@johnmorrisdotca/wakusei-planets 0.31.0 → 0.33.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 (73) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/NOTICE.md +16 -1
  3. package/README.md +60 -5
  4. package/dist/bodies/all.d.ts +1 -0
  5. package/dist/bodies/all.js +1 -0
  6. package/dist/bodies/minor.d.ts +1 -0
  7. package/dist/bodies/minor.js +16 -0
  8. package/dist/data/minor.d.ts +3 -0
  9. package/dist/data/minor.js +7 -0
  10. package/dist/data/tables.d.ts +4 -2
  11. package/dist/data/tables.js +1 -1
  12. package/dist/data-door.d.ts +357 -0
  13. package/dist/data-door.js +393 -0
  14. package/dist/door/book.d.ts +133 -0
  15. package/dist/door/book.js +256 -0
  16. package/dist/door/host.d.ts +30 -0
  17. package/dist/door/host.js +44 -0
  18. package/dist/door/index.d.ts +6 -0
  19. package/dist/door/index.js +10 -0
  20. package/dist/door/map.d.ts +152 -0
  21. package/dist/door/map.js +162 -0
  22. package/dist/door/own.d.ts +36 -0
  23. package/dist/door/own.js +86 -0
  24. package/dist/door/points.d.ts +61 -0
  25. package/dist/door/points.js +175 -0
  26. package/dist/door/small-bodies.d.ts +157 -0
  27. package/dist/door/small-bodies.js +148 -0
  28. package/dist/element.d.ts +21 -0
  29. package/dist/element.js +85 -6
  30. package/dist/embed.d.ts +1 -1
  31. package/dist/embed.js +3 -3
  32. package/dist/ephemeris.d.ts +7 -7
  33. package/dist/ephemeris.js +36 -13
  34. package/dist/facts.d.ts +28 -4
  35. package/dist/facts.js +24 -2
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.js +1 -1
  38. package/dist/nearest.js +6 -4
  39. package/dist/scene/body.d.ts +4 -1
  40. package/dist/scene/body.js +2 -1
  41. package/dist/scene/detail.d.ts +29 -12
  42. package/dist/scene/detail.js +217 -135
  43. package/dist/scene/painter.d.ts +3 -0
  44. package/dist/scene/painter.js +7 -4
  45. package/dist/scene/textures.d.ts +9 -2
  46. package/dist/scene/textures.js +17 -0
  47. package/dist/space/arrows.d.ts +29 -3
  48. package/dist/space/arrows.js +38 -6
  49. package/dist/space/bodies.d.ts +6 -6
  50. package/dist/space/bodies.js +6 -6
  51. package/dist/space/element.d.ts +28 -0
  52. package/dist/space/element.js +74 -6
  53. package/dist/space/frame.d.ts +28 -3
  54. package/dist/space/frame.js +40 -4
  55. package/dist/space/index.d.ts +2 -2
  56. package/dist/space/index.js +2 -2
  57. package/dist/space/scale.d.ts +4 -4
  58. package/dist/space/scale.js +8 -2
  59. package/dist/space/scene.d.ts +12 -2
  60. package/dist/space/scene.js +43 -14
  61. package/dist/stops.d.ts +1 -1
  62. package/dist/stops.js +4 -1
  63. package/dist/tables/all.d.ts +1 -0
  64. package/dist/tables/all.js +1 -0
  65. package/dist/tables/lazy.d.ts +5 -0
  66. package/dist/tables/lazy.js +12 -0
  67. package/dist/tables/minor.d.ts +1 -0
  68. package/dist/tables/minor.js +317 -0
  69. package/dist/textures/vesta-1024.webp +0 -0
  70. package/dist/textures/vesta-512.webp +0 -0
  71. package/dist/version.d.ts +1 -1
  72. package/dist/version.js +1 -1
  73. package/package.json +17 -2
package/dist/element.d.ts CHANGED
@@ -3,6 +3,8 @@ import "./tables/ceres.ts";
3
3
  import "./tables/dwarfs.ts";
4
4
  import { type BodyId, type Look } from "./facts.ts";
5
5
  import { type StarLook, type StarNumbers } from "./star.ts";
6
+ import type { Credit, DataSource } from "./data-door.ts";
7
+ import { type DoorHost } from "./door/host.ts";
6
8
  export { TEXTURE_BASE, TEXTURE_FAR_BASE, TILES_BASE } from "./scene/textures.ts";
7
9
  import type { DetailStats } from "./scene/detail.ts";
8
10
  import { type ThreeParts } from "./scene/body.ts";
@@ -49,6 +51,25 @@ export type WakuseiState = "line" | "loading" | "still" | "live" | "lost" | "una
49
51
  export declare class WakuseiBody extends HTMLElement {
50
52
  #private;
51
53
  static observedAttributes: string[];
54
+ /**
55
+ * The outside sources of map for this body (the data door): each carries its own licence and credit, and a map source for the body takes the place of the folder of tiles. Assign a list to replace them; a source that
56
+ * `validateSource` refuses, or that is not a map source, throws a `TypeError` and changes nothing. A property, not an attribute: data is not text.
57
+ */
58
+ get sources(): readonly DataSource[];
59
+ set sources(list: readonly DataSource[]);
60
+ /** Adds one source (checked at once: a `TypeError` for an empty credit, no licence, a clashing id or a source that is not a map source). Returns the function that removes it. */
61
+ addSource(source: DataSource): () => void;
62
+ /** Removes a source by id: its loads are aborted and its tiles freed, and its credit goes. Returns whether there was one. */
63
+ removeSource(id: string): boolean;
64
+ /** Switches a source off (`false`) or on, for a layers panel. Off aborts its loads, frees its tiles and drops its credit. */
65
+ enableSource(id: string, on: boolean): void;
66
+ /**
67
+ * The sources whose data is in the last drawn frame, the package's own first: the surface picture, the finer map tiles when a window of them is on the body, and each source of yours that gave tiles. `creditLine(credits, "en" | "ja")`
68
+ * from `@johnmorrisdotca/wakusei-planets/door` writes them as a line with the licences. `wakusei-creditschange` fires when this set changes (not at each frame) with `detail: { credits }`.
69
+ */
70
+ credits(): Credit[];
71
+ /** What the sources have done: tile loads started, failed and refused, and the bytes held. */
72
+ get sourceStats(): ReturnType<DoorHost["book"]["stats"]>;
52
73
  /** The moment the dated picture shows, in milliseconds since 1970, or `undefined` for a portrait with no date. */
53
74
  get time(): number | undefined;
54
75
  /** The radius of the body's disc on the screen in CSS pixels, at the picture's own size: what `grab-radius` on the shared view controls wants for a drag that keeps the touched point under the pointer. */
package/dist/element.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
2
2
  import "./tables/ceres.js";
3
3
  import "./tables/dwarfs.js";
4
- import { loadMoonTheory } from "./tables/lazy.js";
4
+ import { loadMinorTables, loadMoonTheory } from "./tables/lazy.js";
5
5
  import { orbitPath } from "./ephemeris.js";
6
- import { BODIES } from "./facts.js";
6
+ import { BODIES, MINOR_IDS } from "./facts.js";
7
7
  import { extentOf, ROOM } from "./scene/extent.js";
8
8
  import { createGate, frameCap } from "./gate.js";
9
9
  import { lineSvg } from "./line.js";
@@ -11,7 +11,9 @@ import { starLook } from "./star.js";
11
11
  import { starLineSvg } from "./star-line.js";
12
12
  import { detailOf, lookOf, starLookOf } from "./scene/look.js";
13
13
  import { createLive, defaultTurn, REDUCED_TURN } from "./live.js";
14
- import { texturePaths, tilesBase } from "./scene/textures.js";
14
+ import { mapSourceFor, texturePaths, tilesBase } from "./scene/textures.js";
15
+ import { createDoorHost } from "./door/host.js";
16
+ import { ownCredit } from "./door/own.js";
15
17
  export { TEXTURE_BASE, TEXTURE_FAR_BASE, TILES_BASE } from "./scene/textures.js";
16
18
  import { mapWidthOf, ringWidthOf, zoomLimit } from "./scene/reach.js";
17
19
  import { createBodyItem } from "./scene/body.js";
@@ -92,7 +94,7 @@ const TEMPLATE = `<style>
92
94
  * ```
93
95
  */
94
96
  export class WakuseiBody extends HTMLElement {
95
- 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", "lang", "labels"];
97
+ 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"];
96
98
  #stage;
97
99
  #state = "line";
98
100
  #renderer;
@@ -133,6 +135,28 @@ export class WakuseiBody extends HTMLElement {
133
135
  #limitKey = "";
134
136
  #tileLevels;
135
137
  #tiles;
138
+ #door = createDoorHost(this, {
139
+ own: () => {
140
+ // the body's own pictures and, where a window of the package's own tiles is on it, those
141
+ const own = [];
142
+ if (this.look !== "line" && this.#view !== undefined && this.#textureWidth > 0)
143
+ own.push(ownCredit("wakusei-pictures", 1));
144
+ const shown = this.#view?.scene?.detail;
145
+ if (shown?.source !== undefined && this.#door.book.get(shown.source.id) === undefined)
146
+ own.push(ownCredit(shown.source.id, shown.used));
147
+ return own;
148
+ },
149
+ used: () => {
150
+ const shown = this.#view?.scene?.detail;
151
+ return shown?.source === undefined ? new Map() : new Map([[shown.source.id, shown.used]]);
152
+ },
153
+ }, { kinds: ["tiles"] },
154
+ // a source added, removed or switched, or a tile arrived: look at the view again (the window is chosen at a sync), then draw
155
+ () => {
156
+ if (this.#view?.live === true)
157
+ this.#sync();
158
+ this.#view?.invalidate();
159
+ });
136
160
  #hover = () => void this.goLive();
137
161
  #onContext = (state) => {
138
162
  if (state === "unavailable")
@@ -149,6 +173,39 @@ export class WakuseiBody extends HTMLElement {
149
173
  this.#resume();
150
174
  this.#syncClock();
151
175
  };
176
+ /**
177
+ * The outside sources of map for this body (the data door): each carries its own licence and credit, and a map source for the body takes the place of the folder of tiles. Assign a list to replace them; a source that
178
+ * `validateSource` refuses, or that is not a map source, throws a `TypeError` and changes nothing. A property, not an attribute: data is not text.
179
+ */
180
+ get sources() {
181
+ return this.#door.sources();
182
+ }
183
+ set sources(list) {
184
+ this.#door.setSources(list);
185
+ }
186
+ /** Adds one source (checked at once: a `TypeError` for an empty credit, no licence, a clashing id or a source that is not a map source). Returns the function that removes it. */
187
+ addSource(source) {
188
+ return this.#door.book.addSource(source);
189
+ }
190
+ /** Removes a source by id: its loads are aborted and its tiles freed, and its credit goes. Returns whether there was one. */
191
+ removeSource(id) {
192
+ return this.#door.book.removeSource(id);
193
+ }
194
+ /** Switches a source off (`false`) or on, for a layers panel. Off aborts its loads, frees its tiles and drops its credit. */
195
+ enableSource(id, on) {
196
+ this.#door.book.enableSource(id, on);
197
+ }
198
+ /**
199
+ * The sources whose data is in the last drawn frame, the package's own first: the surface picture, the finer map tiles when a window of them is on the body, and each source of yours that gave tiles. `creditLine(credits, "en" | "ja")`
200
+ * from `@johnmorrisdotca/wakusei-planets/door` writes them as a line with the licences. `wakusei-creditschange` fires when this set changes (not at each frame) with `detail: { credits }`.
201
+ */
202
+ credits() {
203
+ return this.#door.credits();
204
+ }
205
+ /** What the sources have done: tile loads started, failed and refused, and the bytes held. */
206
+ get sourceStats() {
207
+ return this.#door.book.stats();
208
+ }
152
209
  /** The moment the dated picture shows, in milliseconds since 1970, or `undefined` for a portrait with no date. */
153
210
  get time() {
154
211
  const r = this.#request();
@@ -197,6 +254,7 @@ export class WakuseiBody extends HTMLElement {
197
254
  root.innerHTML = TEMPLATE;
198
255
  this.#stage = root.getElementById("stage");
199
256
  this.#startedAt = performance.now();
257
+ this.#door.book.ownOnly(this.getAttribute("data") === "own");
200
258
  this.#reduce = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
201
259
  this.#clockFromAttributes();
202
260
  if (!this.hasAttribute("role"))
@@ -254,6 +312,8 @@ export class WakuseiBody extends HTMLElement {
254
312
  this.#clockFromAttributes();
255
313
  this.#syncClock(true);
256
314
  }
315
+ if (name === "data")
316
+ this.#door.book.ownOnly(this.getAttribute("data") === "own");
257
317
  if (name === "live")
258
318
  this.#applyHover();
259
319
  if (name === "live" || name === "look" || name === "body")
@@ -546,6 +606,15 @@ export class WakuseiBody extends HTMLElement {
546
606
  const request = this.#request();
547
607
  if (request.moons)
548
608
  this.#wantTheory(request.id);
609
+ // a minor body with a date is placed from its fitted table, fetched the first time one is asked for
610
+ if (request.start !== undefined && MINOR_IDS.includes(request.id)) {
611
+ void loadMinorTables().then((loaded) => {
612
+ if (!loaded)
613
+ return;
614
+ this.#live = createLive();
615
+ this.#queue(true);
616
+ });
617
+ }
549
618
  const frame = this.#live.at(request, performance.now());
550
619
  if (frame.anchors !== this.#lastAnchors) {
551
620
  this.#lastAnchors = frame.anchors;
@@ -705,7 +774,8 @@ export class WakuseiBody extends HTMLElement {
705
774
  ...texturePaths(this),
706
775
  wantedWidth: (discPx) => discPx * Math.min(2, window.devicePixelRatio || 1) * 1.6,
707
776
  tiles: {
708
- base: () => tilesBase(this),
777
+ source: (body) => mapSourceFor(this.#door.book, tilesBase(this), body),
778
+ book: this.#door.book,
709
779
  ratio: () => window.devicePixelRatio || 1,
710
780
  allowed: () => (navigator.deviceMemory ?? 8) > 2,
711
781
  onLevels: (levels) => {
@@ -713,9 +783,16 @@ export class WakuseiBody extends HTMLElement {
713
783
  this.#refreshLimits();
714
784
  },
715
785
  },
716
- redraw: () => this.#view?.invalidate(),
786
+ redraw: () => {
787
+ // the tile levels were read, or a window is ready: look at the view again (the window is chosen at a sync), then draw
788
+ if (this.#view?.live === true)
789
+ this.#sync();
790
+ this.#view?.invalidate();
791
+ this.#door.announce();
792
+ },
717
793
  report: (note) => {
718
794
  this.#textureWidth = note.width;
795
+ this.#door.announce();
719
796
  if (note.failed === true)
720
797
  this.setAttribute("data-fallback", "shader");
721
798
  else
@@ -787,6 +864,7 @@ export class WakuseiBody extends HTMLElement {
787
864
  this.#sceneState = state;
788
865
  scene.apply(state);
789
866
  this.#textureWidth = scene.textureWidth;
867
+ this.#door.announce();
790
868
  }
791
869
  // --- moving ---------------------------------------------------------------------------------------------------------------------------------------
792
870
  #frame() {
@@ -822,6 +900,7 @@ export class WakuseiBody extends HTMLElement {
822
900
  this.#state = state;
823
901
  this.setAttribute("data-state", state);
824
902
  this.dispatchEvent(new CustomEvent("wakusei-state", { detail: { state } }));
903
+ this.#door.announce();
825
904
  if (state === "unavailable")
826
905
  this.#drawLine();
827
906
  }
package/dist/embed.d.ts CHANGED
@@ -68,7 +68,7 @@ export interface EmbedSettings {
68
68
  /** The package's address on the CDN, with its version. */
69
69
  cdn?: string;
70
70
  }
71
- /** The entry point that holds a body's shaded and painted look: the body's own, `dwarfs` for the dwarf planets besides Pluto, `moons-<planet>` for a moon and `moons-dwarf` for a moon of a dwarf planet. */
71
+ /** The entry point that holds a body's shaded and painted look: the body's own, `dwarfs` for the dwarf planets besides Pluto, `minor` for Vesta, Pallas, Chiron, Pholus and Halley, `moons-<planet>` for a moon and `moons-dwarf` for a moon of a dwarf planet. */
72
72
  export declare function entryOf(id: BodyId): string;
73
73
  /**
74
74
  * The text that puts a body in a page, for one way of making the page. Each way is built, parsed or run by the package's tests: the plain HTML one with a script tag from jsDelivr, an ES module, a React component,
package/dist/embed.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // The text to put a body in a page, for each way a page is made: a script tag from a CDN, an ES module, React, Vue, Angular, Svelte, or an iframe of `embed.html`. The demo's "Put it in your page"
2
2
  // section shows these as the reader changes a choice, and the tests build or parse every one. Pure: no DOM.
3
3
  import { embedSnippet } from "@johnmorrisdotca/kazoku-ui/embed-panel";
4
- import { BODIES, DWARF_IDS } from "./facts.js";
4
+ import { BODIES, DWARF_IDS, MINOR_IDS } from "./facts.js";
5
5
  import { decodeScene } from "./portrait/model.js";
6
6
  import { VERSION } from "./version.js";
7
7
  /**
@@ -18,11 +18,11 @@ export const EMBED_KINDS = ["html", "module", "react", "vue", "angular", "svelte
18
18
  const SITE = "https://johnmorrisdotca.github.io/wakusei-planets/";
19
19
  const CDN = `https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@${VERSION}`;
20
20
  const PACKAGE = "@johnmorrisdotca/wakusei-planets";
21
- /** The entry point that holds a body's shaded and painted look: the body's own, `dwarfs` for the dwarf planets besides Pluto, `moons-<planet>` for a moon and `moons-dwarf` for a moon of a dwarf planet. */
21
+ /** The entry point that holds a body's shaded and painted look: the body's own, `dwarfs` for the dwarf planets besides Pluto, `minor` for Vesta, Pallas, Chiron, Pholus and Halley, `moons-<planet>` for a moon and `moons-dwarf` for a moon of a dwarf planet. */
22
22
  export function entryOf(id) {
23
23
  const parent = BODIES[id].parent;
24
24
  if (parent === undefined)
25
- return DWARF_IDS.includes(id) ? "dwarfs" : id;
25
+ return DWARF_IDS.includes(id) ? "dwarfs" : MINOR_IDS.includes(id) ? "minor" : id;
26
26
  return DWARF_IDS.includes(parent) ? "moons-dwarf" : `moons-${parent}`;
27
27
  }
28
28
  /** A star's numbers as the attributes that carry them, in the order they are written: the same names are the iframe's address keys. */
@@ -1,12 +1,12 @@
1
1
  import { moonGeocentric } from "./theory.ts";
2
2
  export { moonGeocentric };
3
- import { type BodyId, type HostId, type MoonId } from "./facts.ts";
3
+ import { type BodyId, type HostId, type MinorId, type MoonId } from "./facts.ts";
4
4
  import { type Vec3 } from "./vec.ts";
5
5
  /** Solve Kepler's equation for the eccentric anomaly, all in radians. */
6
6
  export declare function kepler(meanAnomaly: number, e: number): number;
7
7
  /**
8
8
  * A planet's or dwarf planet's position in the Sun's frame (J2000 ecliptic, astronomical units) at a time: Mercury to Neptune from the VSOP87B series, and Pluto and the other dwarf planets from tables fitted to Horizons (each within a few arc-seconds or better, see the accuracy guide; outside a table's years a dwarf planet falls back to the osculating elements of one epoch from JPL's Small-Body Database).
9
- * @param planet - The planet's or dwarf planet's name.
9
+ * @param planet - The planet's, dwarf planet's or minor body's name.
10
10
  * @param ms - The instant, in milliseconds since 1970 (UTC).
11
11
  * @returns The position as x, y, z in au.
12
12
  *
@@ -18,7 +18,7 @@ export declare function kepler(meanAnomaly: number, e: number): number;
18
18
  * console.log(Math.hypot(x, y, z).toFixed(3));
19
19
  * ```
20
20
  */
21
- export declare function heliocentric(planet: HostId, ms: number): Vec3;
21
+ export declare function heliocentric(planet: HostId | MinorId, ms: number): Vec3;
22
22
  /**
23
23
  * The theory that `heliocentric(planet, ms)` answers with, given the tables loaded now: VSOP87B for Mercury to Neptune, a fitted Chebyshev table where one covers the moment, else
24
24
  * osculating elements (a dwarf planet) or JPL's approximate elements (Pluto outside its table). `worstArcseconds` is the fitted table's measured worst on samples held back from
@@ -35,13 +35,13 @@ export declare function heliocentric(planet: HostId, ms: number): Vec3;
35
35
  * console.log(heliocentricModel("pluto", Date.UTC(2026, 0, 1)));
36
36
  * ```
37
37
  */
38
- export declare function heliocentricModel(planet: HostId, ms: number): {
38
+ export declare function heliocentricModel(planet: HostId | MinorId, ms: number): {
39
39
  theory: "vsop87b" | "chebyshev" | "osculating-elements" | "approximate-elements";
40
40
  worstArcseconds: number | null;
41
41
  };
42
42
  /**
43
- * Mean distance from the Sun, in astronomical units: a planet's semi-major axis at J2000, or a dwarf planet's semi-major axis at the epoch of its elements.
44
- * @param id - A planet or a dwarf planet.
43
+ * Mean distance from the Sun, in astronomical units: a planet's semi-major axis at J2000, or a dwarf planet's or minor body's semi-major axis at the epoch of its elements.
44
+ * @param id - A planet, a dwarf planet or a minor body.
45
45
  * @returns The semi-major axis in au.
46
46
  *
47
47
  * @example
@@ -51,7 +51,7 @@ export declare function heliocentricModel(planet: HostId, ms: number): {
51
51
  * console.log(meanSunAu("earth").toFixed(3));
52
52
  * ```
53
53
  */
54
- export declare function meanSunAu(id: HostId): number;
54
+ export declare function meanSunAu(id: HostId | MinorId): number;
55
55
  /** The north pole of a body as a J2000 ecliptic unit vector. */
56
56
  export declare function poleOf(id: BodyId): Vec3;
57
57
  /** The prime meridian's direction (J2000 ecliptic unit vector) when it has turned to `w` degrees. */
package/dist/ephemeris.js CHANGED
@@ -5,6 +5,7 @@
5
5
  import { ORBITS } from "./data/orbits.js";
6
6
  import { moonTheoryOf, planetSeriesOf } from "./data/theories.js";
7
7
  import { DWARF_ELEMENTS } from "./data/dwarf.js";
8
+ import { MINOR_ELEMENTS } from "./data/minor.js";
8
9
  import { tableOf } from "./data/tables.js";
9
10
  import { PLUTO, PLUTO_SEGMENT_MS, PLUTO_START } from "./data/pluto.js";
10
11
  import { VSOP87 } from "./data/vsop.js";
@@ -41,7 +42,8 @@ export function kepler(meanAnomaly, e) {
41
42
  m -= 2 * Math.PI;
42
43
  if (m < -Math.PI)
43
44
  m += 2 * Math.PI;
44
- let E = e < 0.8 ? m : Math.PI;
45
+ // from the mean anomaly itself for a gentle orbit, and for a long one from a place on the same side of the orbit (Newton's method started at pi goes astray for a negative mean anomaly, which put Sedna's far side in the wrong places)
46
+ let E = e < 0.8 ? m : m + 0.85 * e * Math.sign(Math.sin(m) || 1);
45
47
  for (let i = 0; i < 12; i += 1) {
46
48
  const d = (E - e * Math.sin(E) - m) / (1 - e * Math.cos(E));
47
49
  E -= d;
@@ -51,13 +53,34 @@ export function kepler(meanAnomaly, e) {
51
53
  return E;
52
54
  }
53
55
  const PLUTO_TABLE = { start: PLUTO_START, segment: PLUTO_SEGMENT_MS, worst: 0.14637, segments: PLUTO };
56
+ /** Which segment of a table holds a moment, where it starts (milliseconds from the table's start) and how long it is; `undefined` outside the table. A table with `edges` has segments of unequal length, found by bisection. */
57
+ function segmentAt(table, terrestrialMs) {
58
+ const since = terrestrialMs - table.start;
59
+ const edges = table.edges;
60
+ if (edges === undefined) {
61
+ const index = Math.floor(since / table.segment);
62
+ return table.segments[index] === undefined ? undefined : { index, from: index * table.segment, length: table.segment };
63
+ }
64
+ if (!(since >= edges[0]) || since >= edges[edges.length - 1])
65
+ return undefined;
66
+ let lo = 0;
67
+ let hi = edges.length - 2;
68
+ while (lo < hi) {
69
+ const mid = (lo + hi + 1) >> 1;
70
+ if (edges[mid] <= since)
71
+ lo = mid;
72
+ else
73
+ hi = mid - 1;
74
+ }
75
+ return { index: lo, from: edges[lo], length: edges[lo + 1] - edges[lo] };
76
+ }
54
77
  /** A position from a Chebyshev table, as x, y, z in au, or undefined outside the years it covers. */
55
78
  function fittedPosition(table, terrestrialMs) {
56
- const segment = Math.floor((terrestrialMs - table.start) / table.segment);
57
- const coefficients = table.segments[segment];
58
- if (coefficients === undefined)
79
+ const found = segmentAt(table, terrestrialMs);
80
+ if (found === undefined)
59
81
  return undefined;
60
- const x = (2 * (terrestrialMs - table.start - segment * table.segment)) / table.segment - 1;
82
+ const coefficients = table.segments[found.index];
83
+ const x = (2 * (terrestrialMs - table.start - found.from)) / found.length - 1;
61
84
  const at = (axis) => {
62
85
  let b1 = 0;
63
86
  let b2 = 0;
@@ -72,7 +95,7 @@ function fittedPosition(table, terrestrialMs) {
72
95
  }
73
96
  /** Same table priority and TT segment coverage for positions and model information. */
74
97
  function fittedTableAt(planet, tt) {
75
- const covers = (table) => table.segments[Math.floor((tt - table.start) / table.segment)] !== undefined;
98
+ const covers = (table) => segmentAt(table, tt) !== undefined;
76
99
  if (planet === "pluto" && covers(PLUTO_TABLE))
77
100
  return PLUTO_TABLE;
78
101
  const registered = tableOf(planet);
@@ -107,7 +130,7 @@ function barycentreFromSun(terrestrialMs) {
107
130
  }
108
131
  /**
109
132
  * A planet's or dwarf planet's position in the Sun's frame (J2000 ecliptic, astronomical units) at a time: Mercury to Neptune from the VSOP87B series, and Pluto and the other dwarf planets from tables fitted to Horizons (each within a few arc-seconds or better, see the accuracy guide; outside a table's years a dwarf planet falls back to the osculating elements of one epoch from JPL's Small-Body Database).
110
- * @param planet - The planet's or dwarf planet's name.
133
+ * @param planet - The planet's, dwarf planet's or minor body's name.
111
134
  * @param ms - The instant, in milliseconds since 1970 (UTC).
112
135
  * @returns The position as x, y, z in au.
113
136
  *
@@ -140,9 +163,9 @@ export function heliocentric(planet, ms) {
140
163
  let node;
141
164
  let w;
142
165
  let E;
143
- const dwarf = DWARF_ELEMENTS[planet];
166
+ const dwarf = DWARF_ELEMENTS[planet] ?? MINOR_ELEMENTS[planet];
144
167
  if (dwarf !== undefined) {
145
- // a dwarf planet: the osculating elements of one epoch, run as a plain ellipse (good for years either side of it)
168
+ // a dwarf planet or a minor body: the osculating elements of one epoch, run as a plain ellipse (good for years either side of it)
146
169
  a = dwarf.a;
147
170
  e = dwarf.e;
148
171
  I = dwarf.i * RAD;
@@ -195,11 +218,11 @@ export function heliocentricModel(planet, ms) {
195
218
  const table = fittedTableAt(planet, tt);
196
219
  return table !== undefined
197
220
  ? { theory: "chebyshev", worstArcseconds: table.worst }
198
- : { theory: planet in DWARF_ELEMENTS ? "osculating-elements" : "approximate-elements", worstArcseconds: null };
221
+ : { theory: planet in DWARF_ELEMENTS || planet in MINOR_ELEMENTS ? "osculating-elements" : "approximate-elements", worstArcseconds: null };
199
222
  }
200
223
  /**
201
- * Mean distance from the Sun, in astronomical units: a planet's semi-major axis at J2000, or a dwarf planet's semi-major axis at the epoch of its elements.
202
- * @param id - A planet or a dwarf planet.
224
+ * Mean distance from the Sun, in astronomical units: a planet's semi-major axis at J2000, or a dwarf planet's or minor body's semi-major axis at the epoch of its elements.
225
+ * @param id - A planet, a dwarf planet or a minor body.
203
226
  * @returns The semi-major axis in au.
204
227
  *
205
228
  * @example
@@ -210,7 +233,7 @@ export function heliocentricModel(planet, ms) {
210
233
  * ```
211
234
  */
212
235
  export function meanSunAu(id) {
213
- const dwarf = DWARF_ELEMENTS[id];
236
+ const dwarf = DWARF_ELEMENTS[id] ?? MINOR_ELEMENTS[id];
214
237
  return dwarf !== undefined ? dwarf.a : ELEMENTS[id][0];
215
238
  }
216
239
  /** The north pole of a body as a J2000 ecliptic unit vector. */
package/dist/facts.d.ts CHANGED
@@ -20,6 +20,17 @@ export declare const PLANET_IDS: readonly ["mercury", "venus", "earth", "mars",
20
20
  * ```
21
21
  */
22
22
  export declare const DWARF_IDS: readonly ["ceres", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris", "sedna"];
23
+ /**
24
+ * The minor bodies beyond the dwarf planets that the package knows by name: the asteroids Vesta and Pallas, the centaurs Chiron and Pholus and Halley's comet, nearest the Sun first by the size of their orbits (Halley's, a long ellipse, last).
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { MINOR_IDS } from "@johnmorrisdotca/wakusei-planets";
29
+ *
30
+ * console.log(MINOR_IDS.join(", "));
31
+ * ```
32
+ */
33
+ export declare const MINOR_IDS: readonly ["vesta", "pallas", "chiron", "pholus", "halley"];
23
34
  /**
24
35
  * The moons the package draws, by planet or dwarf planet.
25
36
  *
@@ -66,6 +77,18 @@ export type PlanetId = (typeof PLANET_IDS)[number];
66
77
  * ```
67
78
  */
68
79
  export type DwarfId = (typeof DWARF_IDS)[number];
80
+ /**
81
+ * The name of a minor body: `vesta`, `pallas`, `chiron`, `pholus` or `halley`.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import { MINOR_IDS, type MinorId } from "@johnmorrisdotca/wakusei-planets";
86
+ *
87
+ * const id: MinorId = MINOR_IDS[4];
88
+ * console.log(id);
89
+ * ```
90
+ */
91
+ export type MinorId = (typeof MINOR_IDS)[number];
69
92
  /**
70
93
  * A body a moon can go round: a planet, Pluto or another dwarf planet.
71
94
  *
@@ -91,7 +114,7 @@ export type HostId = PlanetId | DwarfId;
91
114
  */
92
115
  export type MoonId = (typeof MOONS_OF)[keyof typeof MOONS_OF][number];
93
116
  /**
94
- * The name of a body: `sun`, a planet, a dwarf planet or a moon.
117
+ * The name of a body: `sun`, a planet, a dwarf planet, a minor body or a moon.
95
118
  *
96
119
  * @example
97
120
  * ```ts
@@ -101,7 +124,7 @@ export type MoonId = (typeof MOONS_OF)[keyof typeof MOONS_OF][number];
101
124
  * console.log(lineSvg(id, { size: 64 }).length > 100);
102
125
  * ```
103
126
  */
104
- export type BodyId = "sun" | PlanetId | DwarfId | MoonId;
127
+ export type BodyId = "sun" | PlanetId | DwarfId | MinorId | MoonId;
105
128
  /**
106
129
  * How a body is drawn: `line` (an outline drawing), `realistic` and `painted` (a real surface map; `painted` is the same maps), or `illustrated` (shaded from the numbers, not a default).
107
130
  *
@@ -176,7 +199,8 @@ export type Feature = {
176
199
  */
177
200
  export interface BodyFacts {
178
201
  id: BodyId;
179
- kind: "star" | "planet" | "dwarf-planet" | "moon";
202
+ /** What it is: a star, a planet, a dwarf planet, a moon, or one of the minor bodies: an `asteroid`, a `centaur` (between Jupiter and Neptune) or a `comet`. */
203
+ kind: "star" | "planet" | "dwarf-planet" | "moon" | "asteroid" | "centaur" | "comet";
180
204
  /** The planet or dwarf planet a moon goes round. */
181
205
  parent?: HostId;
182
206
  name: {
@@ -224,7 +248,7 @@ export interface BodyFacts {
224
248
  */
225
249
  export declare const BODIES: Readonly<Record<BodyId, BodyFacts>>;
226
250
  /**
227
- * Every body's name: the Sun, the planets outward, the dwarf planets, then the moons of each.
251
+ * Every body's name: the Sun, the planets outward, the dwarf planets, the minor bodies, then the moons of each.
228
252
  *
229
253
  * @example
230
254
  * ```ts
package/dist/facts.js CHANGED
@@ -22,6 +22,17 @@ export const PLANET_IDS = ["mercury", "venus", "earth", "mars", "jupiter", "satu
22
22
  * ```
23
23
  */
24
24
  export const DWARF_IDS = ["ceres", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris", "sedna"];
25
+ /**
26
+ * The minor bodies beyond the dwarf planets that the package knows by name: the asteroids Vesta and Pallas, the centaurs Chiron and Pholus and Halley's comet, nearest the Sun first by the size of their orbits (Halley's, a long ellipse, last).
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { MINOR_IDS } from "@johnmorrisdotca/wakusei-planets";
31
+ *
32
+ * console.log(MINOR_IDS.join(", "));
33
+ * ```
34
+ */
35
+ export const MINOR_IDS = ["vesta", "pallas", "chiron", "pholus", "halley"];
25
36
  /**
26
37
  * The moons the package draws, by planet or dwarf planet.
27
38
  *
@@ -172,6 +183,17 @@ export const BODIES = {
172
183
  gonggong: f("gonggong", "dwarf-planet", "Gonggong", "ゴンゴン", 615, 0, 0, 255.383, 36.831, 0, 385.7, 22.4, "#9c4f3b", { features: dots([[-50, 10, 9], [60, -25, 8], [140, 30, 7]]) }),
173
184
  eris: f("eris", "dwarf-planet", "Eris", "エリス", 1163, 0, 78.22, 36.17, 44.51, 0, 22.805163, 378.8616, "#e8e4dc", { features: [{ kind: "band", lat: 0 }, ...dots([[-30, 30, 8], [80, -20, 9]])] }),
174
185
  sedna: f("sedna", "dwarf-planet", "Sedna", "セドナ", 453, 0, 0, 297.062, 74.71, 0, 840.95, 10.273, "#9a3f2b", { features: dots([[-40, 20, 9], [70, -30, 8], [150, 10, 7]]) }),
186
+ // The minor bodies. Vesta: Park et al. 2025 (Nature Astronomy, JPL SBDB), pole and rotation from the same; Pallas: Marsset et al. 2020 (shape), Carry et al. 2010 (pole, rotation); Chiron and Pholus: JPL SBDB (diameters
187
+ // from occultation and thermal measurements) with the pole estimated along the orbit's; Halley: Keller et al. 1987 (the nucleus), the pole estimated along the orbit's and no spin drawn. See NOTICE.md.
188
+ vesta: f("vesta", "asteroid", "Vesta", "ベスタ", 261.385, 0, 27.4, 309.0611, 42.2324, 285.39, 1617.33312922, 5.3421276322, "#aaa397", {
189
+ axesKm: [284.62, 277.24, 226.33],
190
+ showLon: 301,
191
+ features: [{ kind: "circle", lon: 301, lat: -75, radius: 50 }, { kind: "band", lat: -10 }, { kind: "band", lat: -22 }, ...dots([[60, 25, 9], [140, 5, 7], [-100, 30, 8], [-40, -20, 6]])],
192
+ }),
193
+ pallas: f("pallas", "asteroid", "Pallas", "パラス", 256.5, 0, 83.6, 33, -3, 0, 1105.8, 7.8132214, "#85878a", { axesKm: [284, 266, 224], features: dots([[-60, 20, 12], [50, -25, 10], [130, 30, 9], [-130, -30, 8], [10, 55, 7]]) }),
194
+ chiron: f("chiron", "centaur", "Chiron", "ケイロン", 83, 0, 0, 258.793, 72.317, 0, 1460, 5.918, "#8d8e90", { features: dots([[-50, 20, 14], [70, -25, 12], [150, 30, 10], [-120, -35, 9]]) }),
195
+ pholus: f("pholus", "centaur", "Pholus", "ポルス", 95, 0, 0, 334.495, 66.246, 0, 865.73, 9.98, "#8e4b36", { features: dots([[-60, 15, 14], [40, -30, 12], [130, 25, 10], [-130, -20, 9]]) }),
196
+ halley: f("halley", "comet", "Halley", "ハレー彗星", 5.5, 0, 0, 41.795, -69.39, 0, 0, 0, "#44403d", { axesKm: [7.45, 4.1, 4.1], features: [...dots([[-40, 20, 16], [60, -15, 12], [130, 30, 10]]), { kind: "line", points: [[-120, -5], [-80, 8], [-30, -4], [20, 10], [80, 0]] }] }),
175
197
  moon: f("moon", "moon", "Moon", "月", 1737.4, 0.0012, 6.68, 269.9949, 66.5392, 38.3213, 13.17635815, 655.728, "#b8b5ae", {
176
198
  parent: "earth",
177
199
  synchronous: true,
@@ -216,7 +238,7 @@ export const BODIES = {
216
238
  dysnomia: f("dysnomia", "moon", "Dysnomia", "ディスノミア", 308, 0, 0, 36.17, 44.51, 0, 22.805163, 378.8616, "#5a5856", { parent: "eris", synchronous: true, features: dots([[-60, 20, 10], [50, -25, 9], [140, 30, 8]]) }),
217
239
  };
218
240
  /**
219
- * Every body's name: the Sun, the planets outward, the dwarf planets, then the moons of each.
241
+ * Every body's name: the Sun, the planets outward, the dwarf planets, the minor bodies, then the moons of each.
220
242
  *
221
243
  * @example
222
244
  * ```ts
@@ -225,7 +247,7 @@ export const BODIES = {
225
247
  * console.log(BODY_IDS.length, BODY_IDS[0]);
226
248
  * ```
227
249
  */
228
- export const BODY_IDS = ["sun", ...PLANET_IDS, ...DWARF_IDS, ...Object.values(MOONS_OF).flat()];
250
+ export const BODY_IDS = ["sun", ...PLANET_IDS, ...DWARF_IDS, ...MINOR_IDS, ...Object.values(MOONS_OF).flat()];
229
251
  /** A body's polar radius as a fraction of its equatorial radius. */
230
252
  export const polarRatio = (facts) => 1 - facts.flattening;
231
253
  /**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { BODIES, BODY_IDS, DWARF_IDS, MOONS_OF, PLANET_IDS, ringReach, type BodyFacts, type BodyId, type DwarfId, type Feature, type HostId, type Look, type MoonId, type PlanetId, type RingBand } from "./facts.ts";
1
+ export { BODIES, BODY_IDS, DWARF_IDS, MINOR_IDS, MOONS_OF, PLANET_IDS, ringReach, type BodyFacts, type BodyId, type DwarfId, type Feature, type HostId, type Look, type MinorId, type MoonId, type PlanetId, type RingBand } from "./facts.ts";
2
2
  export { apparent, heliocentric, heliocentricModel, meanSunAu, moonGeocentric, orbitPath, system, type Apparent, type MoonPlace, type Pose, type System } from "./ephemeris.ts";
3
3
  export { JOURNEY_STOPS, journeyStop, stopPlaceAu, type JourneyStop } from "./stops.ts";
4
4
  export { drawnTilt, portrait, type PortraitOptions } from "./pose.ts";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { BODIES, BODY_IDS, DWARF_IDS, MOONS_OF, PLANET_IDS, ringReach } from "./facts.js";
1
+ export { BODIES, BODY_IDS, DWARF_IDS, MINOR_IDS, MOONS_OF, PLANET_IDS, ringReach } from "./facts.js";
2
2
  export { apparent, heliocentric, heliocentricModel, meanSunAu, moonGeocentric, orbitPath, system } from "./ephemeris.js";
3
3
  export { JOURNEY_STOPS, journeyStop, stopPlaceAu } from "./stops.js";
4
4
  export { drawnTilt, portrait } from "./pose.js";
package/dist/nearest.js CHANGED
@@ -1,4 +1,4 @@
1
- // Which bodies are nearest to a body on a date, and when two bodies come closest over a span: for the Sun, the planets, the dwarf planets and the moons, by the angle between them in the sky of an observer
1
+ // Which bodies are nearest to a body on a date, and when two bodies come closest over a span: for the Sun, the planets, the dwarf planets, the minor bodies and the moons, by the angle between them in the sky of an observer
2
2
  // or by the distance between them in space. The positions are this package's own (heliocentric, ephemeris.ts): a sky angle is astrometric (the Earth's or the observer's place at the date, the body's place when
3
3
  // its light left, no aberration or light bending), a distance is the geometry at one instant. Each result carries the accuracy the theories are held to (docs/guides/accuracy.md). Pure: no DOM, no three.js.
4
4
  import { heliocentric, heliocentricModel, meanSunAu, moonVector } from "./ephemeris.js";
@@ -14,12 +14,14 @@ const AU_KM = 149_597_870.7;
14
14
  const LIGHT_SECONDS_PER_AU = 499.004784;
15
15
  const DAY_MS = 86_400_000;
16
16
  const ARCSECONDS_PER_RADIAN = 206_264.806;
17
- const KINDS = ["star", "planet", "dwarf-planet", "moon"];
17
+ const KINDS = ["star", "planet", "dwarf-planet", "moon", "asteroid", "centaur", "comet"];
18
18
  /** The worst direction error from the Sun in arc-seconds over 60 dates from 1800 to 2200, as the accuracy guide holds each planet to. */
19
19
  const PLANET_ARCSECONDS = { mercury: 4.5, venus: 2.6, earth: 4, mars: 6, jupiter: 3.6, saturn: 5.7, uranus: 5, neptune: 3.4, pluto: 0.2 };
20
20
  /** The same for a dwarf planet inside its fitted table's years. */
21
21
  const DWARF_ARCSECONDS = { ceres: 0.3, orcus: 0.1, haumea: 0.1, quaoar: 0.15, makemake: 0.15, gonggong: 0.1, eris: 0.1, sedna: 0.1 };
22
- /** A dwarf planet outside its table's years runs on the osculating elements of one epoch, and Pluto outside 1800 to 2200 on JPL's approximate elements. */
22
+ /** The same for a minor body inside its fitted table's years: the worst of the held-back samples of each fit (scripts/make-minor-data.py), rounded up. */
23
+ const MINOR_ARCSECONDS = { vesta: 1, pallas: 1, chiron: 0.6, pholus: 0.7, halley: 1 };
24
+ /** A dwarf planet or minor body outside its table's years runs on the osculating elements of one epoch, and Pluto outside 1800 to 2200 on JPL's approximate elements. */
23
25
  const OSCULATING_ARCSECONDS = 3600;
24
26
  const APPROXIMATE_ARCSECONDS = 120;
25
27
  /** The worst direction error from the planet in degrees over 60 dates, for the Moon and each moon; a moon the accuracy guide does not measure is given 5 degrees. */
@@ -104,7 +106,7 @@ function separation(by, a, b) {
104
106
  }
105
107
  function hostErrorKm(host, ms) {
106
108
  const model = heliocentricModel(host, ms);
107
- const arcseconds = model.theory === "vsop87b" ? PLANET_ARCSECONDS[host] : model.theory === "chebyshev" ? (PLANET_ARCSECONDS[host] ?? DWARF_ARCSECONDS[host]) : model.theory === "osculating-elements" ? OSCULATING_ARCSECONDS : APPROXIMATE_ARCSECONDS;
109
+ const arcseconds = model.theory === "vsop87b" ? PLANET_ARCSECONDS[host] : model.theory === "chebyshev" ? (PLANET_ARCSECONDS[host] ?? DWARF_ARCSECONDS[host] ?? MINOR_ARCSECONDS[host]) : model.theory === "osculating-elements" ? OSCULATING_ARCSECONDS : APPROXIMATE_ARCSECONDS;
108
110
  return length(heliocentric(host, ms)) * AU_KM * Math.tan(arcseconds / ARCSECONDS_PER_RADIAN);
109
111
  }
110
112
  /** The independent parts of how far a body's place may be off, kilometres: the planet it goes round (which its moons share) and its own part. */
@@ -3,6 +3,8 @@ import type * as THREE from "three";
3
3
  import type { Pose } from "../ephemeris.ts";
4
4
  import { type BodyFacts, type BodyId } from "../facts.ts";
5
5
  import { type BodyLook } from "./look.ts";
6
+ import type { SourceBook } from "../door/book.ts";
7
+ import type { BodyMapSource } from "../door/map.ts";
6
8
  import { type DetailStats } from "./detail.ts";
7
9
  import type { TileLevel } from "./tiles.ts";
8
10
  export { fallbackLook } from "./fallback.ts";
@@ -70,7 +72,8 @@ export interface BodyItemOptions {
70
72
  }): void;
71
73
  /** Finer map tiles for a close zoom (see `scene/detail.ts`): where they are (`undefined` for none), the pixel ratio, whether this device may use them, and what to do when the tile set's levels for the body are known. */
72
74
  tiles?: {
73
- base(): string | undefined;
75
+ source(body: string): BodyMapSource | undefined;
76
+ book: SourceBook;
74
77
  ratio(): number;
75
78
  allowed(): boolean;
76
79
  onLevels?(levels: readonly TileLevel[] | undefined): void;
@@ -205,7 +205,8 @@ export function createBodyItem(options) {
205
205
  const detail = windowUniforms === undefined || options.tiles === undefined
206
206
  ? undefined
207
207
  : createDetail(T, {
208
- base: () => options.tiles.base(),
208
+ source: () => options.tiles.source(look.painted.map),
209
+ book: options.tiles.book,
209
210
  body: look.painted.map,
210
211
  ratio: () => options.tiles.ratio(),
211
212
  allowed: () => options.tiles.allowed(),