@johnmorrisdotca/wakusei-planets 0.19.0 → 0.21.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 (113) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/NOTICE.md +14 -3
  3. package/README.md +39 -6
  4. package/dist/bodies/earth.js +13 -5
  5. package/dist/calendar.d.ts +119 -0
  6. package/dist/calendar.js +155 -0
  7. package/dist/clock.d.ts +244 -0
  8. package/dist/clock.js +325 -0
  9. package/dist/coordinates.d.ts +172 -0
  10. package/dist/coordinates.js +170 -0
  11. package/dist/craft/cassini.d.ts +1 -0
  12. package/dist/craft/cassini.js +1131 -0
  13. package/dist/craft/galileo.d.ts +1 -0
  14. package/dist/craft/galileo.js +224 -0
  15. package/dist/craft/juno.d.ts +1 -0
  16. package/dist/craft/juno.js +640 -0
  17. package/dist/craft/newhorizons.d.ts +1 -0
  18. package/dist/craft/newhorizons.js +18 -0
  19. package/dist/craft/parker.d.ts +1 -0
  20. package/dist/craft/parker.js +221 -0
  21. package/dist/craft/pioneer10.d.ts +1 -0
  22. package/dist/craft/pioneer10.js +24 -0
  23. package/dist/craft/pioneer11.d.ts +1 -0
  24. package/dist/craft/pioneer11.js +34 -0
  25. package/dist/craft/voyager1.d.ts +1 -0
  26. package/dist/craft/voyager1.js +28 -0
  27. package/dist/craft/voyager2.d.ts +1 -0
  28. package/dist/craft/voyager2.js +43 -0
  29. package/dist/craft/webb.d.ts +1 -0
  30. package/dist/craft/webb.js +28 -0
  31. package/dist/data/craft.d.ts +23 -0
  32. package/dist/data/craft.js +53 -0
  33. package/dist/data/lunar.d.ts +4 -0
  34. package/dist/data/lunar.js +548 -0
  35. package/dist/data/pluto.d.ts +6 -0
  36. package/dist/data/pluto.js +29 -0
  37. package/dist/data/stars.d.ts +4 -0
  38. package/dist/data/stars.js +5088 -0
  39. package/dist/data/tables.d.ts +41 -0
  40. package/dist/data/tables.js +37 -0
  41. package/dist/data/vsop.d.ts +19 -1
  42. package/dist/data/vsop.js +25 -8
  43. package/dist/element.d.ts +2 -23
  44. package/dist/element.js +75 -110
  45. package/dist/ephemeris.d.ts +22 -14
  46. package/dist/ephemeris.js +106 -58
  47. package/dist/index.d.ts +1 -1
  48. package/dist/index.js +1 -1
  49. package/dist/mars.d.ts +41 -0
  50. package/dist/mars.js +52 -0
  51. package/dist/portrait/element.d.ts +1 -0
  52. package/dist/portrait/element.js +27 -39
  53. package/dist/scales.d.ts +46 -0
  54. package/dist/scales.js +75 -0
  55. package/dist/scene/basis.d.ts +3 -0
  56. package/dist/scene/basis.js +4 -0
  57. package/dist/scene/body.d.ts +2 -4
  58. package/dist/scene/body.js +55 -67
  59. package/dist/scene/fallback.d.ts +4 -0
  60. package/dist/scene/fallback.js +5 -0
  61. package/dist/scene/painter.js +10 -23
  62. package/dist/scene/store.d.ts +2 -2
  63. package/dist/scene/textures.d.ts +30 -0
  64. package/dist/scene/textures.js +47 -0
  65. package/dist/sidereal.d.ts +70 -0
  66. package/dist/sidereal.js +94 -0
  67. package/dist/sky/engine.d.ts +37 -0
  68. package/dist/sky/engine.js +116 -0
  69. package/dist/sky/events.d.ts +37 -0
  70. package/dist/sky/events.js +133 -0
  71. package/dist/sky/frames.d.ts +3 -0
  72. package/dist/sky/frames.js +26 -0
  73. package/dist/sky/types.d.ts +20 -0
  74. package/dist/sky/types.js +1 -0
  75. package/dist/space/aim.d.ts +18 -0
  76. package/dist/space/aim.js +28 -0
  77. package/dist/space/element.d.ts +212 -0
  78. package/dist/space/element.js +524 -0
  79. package/dist/space/frame.d.ts +152 -0
  80. package/dist/space/frame.js +169 -0
  81. package/dist/space/index.d.ts +4 -0
  82. package/dist/space/index.js +5 -0
  83. package/dist/space/ride.d.ts +89 -0
  84. package/dist/space/ride.js +58 -0
  85. package/dist/space/scale.d.ts +126 -0
  86. package/dist/space/scale.js +139 -0
  87. package/dist/space/scene.d.ts +189 -0
  88. package/dist/space/scene.js +422 -0
  89. package/dist/spacecraft-facts.d.ts +114 -0
  90. package/dist/spacecraft-facts.js +215 -0
  91. package/dist/spacecraft.d.ts +134 -0
  92. package/dist/spacecraft.js +198 -0
  93. package/dist/stars.d.ts +160 -0
  94. package/dist/stars.js +193 -0
  95. package/dist/suncalc-legacy.d.ts +187 -0
  96. package/dist/suncalc-legacy.js +168 -0
  97. package/dist/suncalc.d.ts +209 -0
  98. package/dist/suncalc.js +167 -0
  99. package/dist/tables/all.d.ts +2 -0
  100. package/dist/tables/all.js +2 -0
  101. package/dist/tables/ceres.d.ts +1 -0
  102. package/dist/tables/ceres.js +57 -0
  103. package/dist/tables/dwarfs.d.ts +1 -0
  104. package/dist/tables/dwarfs.js +59 -0
  105. package/dist/theory.d.ts +20 -0
  106. package/dist/theory.js +98 -0
  107. package/dist/time.d.ts +6 -108
  108. package/dist/time.js +7 -180
  109. package/dist/version.d.ts +1 -1
  110. package/dist/version.js +1 -1
  111. package/dist/when.d.ts +16 -0
  112. package/dist/when.js +13 -0
  113. package/package.json +95 -4
package/dist/element.js CHANGED
@@ -1,37 +1,16 @@
1
+ import "./tables/all.js";
1
2
  import { orbitPath, nearMoons } from "./ephemeris.js";
2
3
  import { BODIES, ringReach } from "./facts.js";
3
4
  import { createGate, frameCap } from "./gate.js";
4
5
  import { lineSvg } from "./line.js";
5
6
  import { createLive, defaultTurn, REDUCED_TURN } from "./live.js";
6
- import { VERSION } from "./version.js";
7
+ import { texturePaths } from "./scene/textures.js";
8
+ export { TEXTURE_BASE, TEXTURE_FAR_BASE } from "./scene/textures.js";
7
9
  import { createBodyItem } from "./scene/body.js";
8
10
  import { delegates, onRegister } from "./scene/store.js";
9
11
  import { setThreeLoader, takeRenderer } from "./scene/shared.js";
10
12
  import { turn as turnVec } from "./vec.js";
11
13
  export { setThreeLoader };
12
- /**
13
- * The default home of the surface pictures: the files of this exact version on jsDelivr. Set `texture-base` on an element to serve them yourself.
14
- *
15
- * @example
16
- * ```ts no-run
17
- * import { TEXTURE_BASE } from "@johnmorrisdotca/wakusei-planets/element";
18
- *
19
- * console.log(TEXTURE_BASE);
20
- * ```
21
- */
22
- export const TEXTURE_BASE = `https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@${VERSION}/dist/textures/`;
23
- /**
24
- * 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
25
- * never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
26
- *
27
- * @example
28
- * ```ts no-run
29
- * import { TEXTURE_FAR_BASE } from "@johnmorrisdotca/wakusei-planets/element";
30
- *
31
- * console.log(TEXTURE_FAR_BASE);
32
- * ```
33
- */
34
- export const TEXTURE_FAR_BASE = `https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v${VERSION}/textures/`;
35
14
  const num = (value, fallback) => {
36
15
  if (value === null || value.trim() === "")
37
16
  return fallback;
@@ -47,7 +26,12 @@ const readTime = (value) => {
47
26
  const ms = Date.parse(value);
48
27
  return Number.isFinite(ms) ? ms : undefined;
49
28
  };
50
- /** The half-width of the picture, in body radii, for a body alone, with a scale to another body, or with its moons. */
29
+ const vectorKey = (v) => `${v[0].toFixed(2)},${v[1].toFixed(2)},${v[2].toFixed(2)}`;
30
+ function turnPose(pose, axis, degrees) {
31
+ pose.pole = turnVec(pose.pole, axis, degrees);
32
+ pose.meridian = turnVec(pose.meridian, axis, degrees);
33
+ pose.light = turnVec(pose.light, axis, degrees);
34
+ }
51
35
  /** The half-width of a body's picture, in its radii, when it has no scale of its own: the globe takes a little under half the height, so its rings, glow and haze have room round it. */
52
36
  const ROOM = 2.2;
53
37
  function extentOf(id, options) {
@@ -203,15 +187,8 @@ export class WakuseiBody extends HTMLElement {
203
187
  this.#io?.disconnect();
204
188
  document.removeEventListener("visibilitychange", this.#onHidden);
205
189
  this.#unsub?.();
206
- this.removeEventListener("pointerenter", this.#hover);
207
- this.removeEventListener("focusin", this.#hover);
208
- this.removeEventListener("pointerdown", this.#hover);
209
- this.#view?.dispose();
210
- this.#view = undefined;
211
- this.#viewKey = "";
212
- this.#release?.();
213
- this.#release = undefined;
214
- this.#renderer = undefined;
190
+ this.#applyHover(false);
191
+ this.#disposeView(true);
215
192
  }
216
193
  attributeChangedCallback(name) {
217
194
  if (!this.isConnected)
@@ -277,10 +254,10 @@ export class WakuseiBody extends HTMLElement {
277
254
  rate: Math.max(-1e7, Math.min(1e7, num(this.getAttribute("rate"), 1))),
278
255
  moons,
279
256
  portrait: {
280
- ...(this.hasAttribute("tilt") ? { tilt: num(this.getAttribute("tilt"), 0) } : {}),
281
- ...(this.hasAttribute("pitch") ? { pitch: num(this.getAttribute("pitch"), 0) } : {}),
282
- ...(this.hasAttribute("phase") ? { phase: num(this.getAttribute("phase"), 0) } : {}),
283
- ...(this.hasAttribute("meridian") ? { spin: num(this.getAttribute("meridian"), 0) } : {}),
257
+ tilt: this.hasAttribute("tilt") ? num(this.getAttribute("tilt"), 0) : undefined,
258
+ pitch: this.hasAttribute("pitch") ? num(this.getAttribute("pitch"), 0) : undefined,
259
+ phase: this.hasAttribute("phase") ? num(this.getAttribute("phase"), 0) : undefined,
260
+ spin: this.hasAttribute("meridian") ? num(this.getAttribute("meridian"), 0) : undefined,
284
261
  },
285
262
  turn: (this.hasAttribute("turn") ? num(this.getAttribute("turn"), 0) : this.getAttribute("live") === "off" ? 0 : defaultTurn(this.body)) * (this.#reduce ? REDUCED_TURN : 1),
286
263
  };
@@ -293,39 +270,40 @@ export class WakuseiBody extends HTMLElement {
293
270
  }
294
271
  // --- the state of the scene --------------------------------------------------------------------------------------------------------------------
295
272
  #sceneOf(frame) {
296
- let { pole, meridian, light } = frame.pose;
273
+ const pose = { pole: frame.pose.pole, meridian: frame.pose.meridian, light: frame.pose.light };
297
274
  const tiltBy = this.#pitchDelta - this.#tilt;
298
275
  if (this.#yaw !== 0)
299
- meridian = turnVec(meridian, pole, this.#yaw);
300
- if (tiltBy !== 0) {
301
- const x = [1, 0, 0];
302
- pole = turnVec(pole, x, tiltBy);
303
- meridian = turnVec(meridian, x, tiltBy);
304
- light = turnVec(light, x, tiltBy);
305
- }
276
+ pose.meridian = turnVec(pose.meridian, pose.pole, this.#yaw);
277
+ if (tiltBy !== 0)
278
+ turnPose(pose, [1, 0, 0], tiltBy);
306
279
  const roll = -this.#roll;
307
- if (roll !== 0) {
308
- const z = [0, 0, 1];
309
- pole = turnVec(pole, z, roll);
310
- meridian = turnVec(meridian, z, roll);
311
- light = turnVec(light, z, roll);
312
- }
280
+ if (roll !== 0)
281
+ turnPose(pose, [0, 0, 1], roll);
313
282
  const r = this.#request();
314
283
  const scaleTo = this.getAttribute("scale-to");
315
284
  const range = this.hasAttribute("range") ? num(this.getAttribute("range"), 0) : undefined;
316
285
  const span = num(this.getAttribute("span-km"), 0);
317
- const extent = extentOf(this.body, { ...(this.getAttribute("fit") === "tight" ? { tight: true } : {}), ...(span > 0 ? { spanKm: span } : {}), ...(scaleTo !== null && scaleTo in BODIES ? { scaleTo } : {}), moons: r.moons, ...(range !== undefined && range > 0 ? { range } : {}) });
318
- const moons = r.moons
319
- ? frame.moons
320
- .filter((m) => m.distance <= extent * 1.05)
321
- .map((m) => {
286
+ const extent = extentOf(this.body, {
287
+ tight: this.getAttribute("fit") === "tight",
288
+ spanKm: span > 0 ? span : undefined,
289
+ scaleTo: scaleTo !== null && scaleTo in BODIES ? scaleTo : undefined,
290
+ moons: r.moons,
291
+ range: range !== undefined && range > 0 ? range : undefined,
292
+ });
293
+ const moons = r.moons ? this.#moonsOf(frame, extent, tiltBy, roll) : undefined;
294
+ return { pose, extent, sky: frame.time !== undefined, zoom: this.#zoom, panX: clampPan(this.#panX, extent, this.#zoom), panY: clampPan(this.#panY, extent, this.#zoom), moons };
295
+ }
296
+ #moonsOf(frame, extent, tilt, roll) {
297
+ const moons = [];
298
+ for (const m of frame.moons) {
299
+ if (m.distance <= extent * 1.05) {
322
300
  const orbit = this.#orbits.get(m.id);
323
- const tipped = tiltBy === 0 ? [m.x, m.y, m.z] : turnVec([m.x, m.y, m.z], [1, 0, 0], tiltBy);
301
+ const tipped = tilt === 0 ? [m.x, m.y, m.z] : turnVec([m.x, m.y, m.z], [1, 0, 0], tilt);
324
302
  const rotated = roll === 0 ? tipped : turnVec(tipped, [0, 0, 1], roll);
325
- return { id: m.id, x: rotated[0], y: rotated[1], z: rotated[2], ...(orbit !== undefined ? { orbit: tiltBy === 0 && roll === 0 ? orbit : this.#tiltedOrbit(m.id, orbit, tiltBy, roll) } : {}) };
326
- })
327
- : undefined;
328
- return { pose: { pole, meridian, light }, extent, sky: frame.time !== undefined, zoom: this.#zoom, panX: clampPan(this.#panX, extent, this.#zoom), panY: clampPan(this.#panY, extent, this.#zoom), ...(moons !== undefined ? { moons } : {}) };
303
+ moons.push({ id: m.id, x: rotated[0], y: rotated[1], z: rotated[2], orbit: orbit === undefined || (tilt === 0 && roll === 0) ? orbit : this.#tiltedOrbit(m.id, orbit, tilt, roll) });
304
+ }
305
+ }
306
+ return moons;
329
307
  }
330
308
  #tilted = new Map();
331
309
  #tiltedOrbit(id, orbit, tilt, roll) {
@@ -379,15 +357,12 @@ export class WakuseiBody extends HTMLElement {
379
357
  async #refresh() {
380
358
  if (!this.isConnected)
381
359
  return;
382
- const stage = this.#stage;
383
360
  this.setAttribute("aria-label", this.#label());
384
361
  if (this.hasAttribute("size"))
385
362
  this.style.setProperty("--wakusei-size", `${num(this.getAttribute("size"), 320)}px`);
386
363
  const delegate = this.look === "line" ? delegates.get(this.body) : undefined;
387
- if (delegate !== undefined) {
388
- await this.#delegated(delegate);
364
+ if (delegate !== undefined && (await this.#delegated(delegate)))
389
365
  return;
390
- }
391
366
  if (this.#delegateEl !== undefined) {
392
367
  this.#delegateEl.remove();
393
368
  this.#delegateEl = undefined;
@@ -395,14 +370,8 @@ export class WakuseiBody extends HTMLElement {
395
370
  }
396
371
  const wants3d = this.look !== "line" && this.#state !== "unavailable";
397
372
  if (!wants3d) {
398
- if (this.#view !== undefined) {
399
- this.#view.dispose();
400
- this.#view = undefined;
401
- this.#viewKey = "";
402
- this.#release?.();
403
- this.#release = undefined;
404
- this.#renderer = undefined;
405
- }
373
+ if (this.#view !== undefined)
374
+ this.#disposeView(true);
406
375
  this.#drawLine();
407
376
  if (this.look === "line")
408
377
  this.#set("line");
@@ -412,9 +381,7 @@ export class WakuseiBody extends HTMLElement {
412
381
  if (this.#view !== undefined && this.#viewSig !== sig) {
413
382
  if (this.#view.live)
414
383
  this.#wantLive = true;
415
- this.#view.dispose();
416
- this.#view = undefined;
417
- this.#viewKey = "";
384
+ this.#disposeView();
418
385
  }
419
386
  if (this.#view === undefined || this.#viewKey === "")
420
387
  await this.#ensureView();
@@ -431,20 +398,18 @@ export class WakuseiBody extends HTMLElement {
431
398
  if (this.#wantLive || this.#hasPriority())
432
399
  void this.goLive();
433
400
  }
434
- void stage;
435
401
  }
436
402
  #hasPriority() {
437
403
  const mode = this.getAttribute("live") ?? "always";
438
404
  return mode === "always" && this.#visible;
439
405
  }
440
- #applyHover() {
441
- this.removeEventListener("pointerenter", this.#hover);
442
- this.removeEventListener("focusin", this.#hover);
443
- this.removeEventListener("pointerdown", this.#hover);
444
- if ((this.getAttribute("live") ?? "always") === "hover") {
445
- this.addEventListener("pointerenter", this.#hover);
446
- this.addEventListener("focusin", this.#hover);
447
- this.addEventListener("pointerdown", this.#hover);
406
+ #applyHover(allow = true) {
407
+ const events = ["pointerenter", "focusin", "pointerdown"];
408
+ for (const name of events)
409
+ this.removeEventListener(name, this.#hover);
410
+ if (allow && (this.getAttribute("live") ?? "always") === "hover") {
411
+ for (const name of events)
412
+ this.addEventListener(name, this.#hover);
448
413
  }
449
414
  }
450
415
  #label() {
@@ -465,19 +430,29 @@ export class WakuseiBody extends HTMLElement {
465
430
  size,
466
431
  pose: scene.pose,
467
432
  ...(r.moons ? { moons: true, ...(frame.time !== undefined ? { time: frame.time } : {}), range: scene.extent, moonsAt: (scene.moons ?? []).map((m) => ({ id: m.id, x: m.x, y: m.y, z: m.z, distance: Math.hypot(m.x, m.y, m.z) })), orbits: new Map((scene.moons ?? []).filter((m) => m.orbit !== undefined).map((m) => [m.id, m.orbit])) } : {}),
468
- ...(scaleTo !== null || this.hasAttribute("span-km") || this.getAttribute("fit") !== "tight" ? { fill: this.#fill() } : {}),
469
- ...(this.getAttribute("lang") === "ja" ? { lang: "ja" } : {}),
470
- ...(this.getAttribute("labels") === "off" ? { labels: false } : {}),
471
- ...(stroke !== "" ? { stroke } : {}),
472
- ...(paper !== "" ? { paper } : {}),
433
+ fill: scaleTo !== null || this.hasAttribute("span-km") || this.getAttribute("fit") !== "tight" ? this.#fill() : undefined,
434
+ lang: this.getAttribute("lang") === "ja" ? "ja" : undefined,
435
+ labels: this.getAttribute("labels") === "off" ? false : undefined,
436
+ stroke: stroke || undefined,
437
+ paper: paper || undefined,
473
438
  ...(this.#zoom !== 1 ? { zoom: this.#zoom, panX: scene.panX, panY: scene.panY } : {}),
474
439
  });
475
440
  this.#stage.innerHTML = html;
476
441
  }
477
442
  #key(state) {
478
- const q = (v) => v.map((n) => n.toFixed(2)).join(",");
479
443
  const moons = (state.moons ?? []).map((m) => `${m.id}:${m.x.toFixed(1)},${m.y.toFixed(1)}`).join(";");
480
- return `${this.body}|${this.look}|${q(state.pose.pole)}|${q(state.pose.meridian)}|${q(state.pose.light)}|${state.extent.toFixed(2)}|${state.zoom.toFixed(2)}|${state.panX.toFixed(2)},${state.panY.toFixed(2)}|${moons}`;
444
+ return `${this.body}|${this.look}|${vectorKey(state.pose.pole)}|${vectorKey(state.pose.meridian)}|${vectorKey(state.pose.light)}|${state.extent.toFixed(2)}|${state.zoom.toFixed(2)}|${state.panX.toFixed(2)},${state.panY.toFixed(2)}|${moons}`;
445
+ }
446
+ // Replacing a view keeps the renderer lease; leaving 3D gives it back.
447
+ #disposeView(releaseRenderer = false) {
448
+ this.#view?.dispose();
449
+ this.#view = undefined;
450
+ this.#viewKey = "";
451
+ if (releaseRenderer) {
452
+ this.#release?.();
453
+ this.#release = undefined;
454
+ this.#renderer = undefined;
455
+ }
481
456
  }
482
457
  /** The renderer, the view and its first still. */
483
458
  async #ensureView() {
@@ -497,22 +472,12 @@ export class WakuseiBody extends HTMLElement {
497
472
  this.#viewSig = `${this.body}|${this.look}`;
498
473
  this.#stilled = false;
499
474
  this.#stage.innerHTML = "";
500
- const base = () => {
501
- const own = this.getAttribute("texture-base");
502
- return own === null || own === "" ? TEXTURE_BASE : own.endsWith("/") ? own : `${own}/`;
503
- };
504
475
  const item = createBodyItem({
505
476
  id: this.body,
506
477
  look: this.look === "illustrated" ? "realistic" : "painted",
507
478
  key: this.#viewKey,
508
479
  state: () => this.#sceneState ?? state,
509
- textureBase: base,
510
- farBase: () => {
511
- const own = this.getAttribute("texture-far-base");
512
- if (own !== null && own !== "")
513
- return own.endsWith("/") ? own : `${own}/`;
514
- return this.hasAttribute("texture-base") ? base() : TEXTURE_FAR_BASE;
515
- },
480
+ ...texturePaths(this),
516
481
  wantedWidth: (discPx) => discPx * Math.min(2, window.devicePixelRatio || 1) * 1.6,
517
482
  redraw: () => this.#view?.invalidate(),
518
483
  report: (note) => {
@@ -531,17 +496,17 @@ export class WakuseiBody extends HTMLElement {
531
496
  /** A body whose line look another package draws (the Earth's globe with its countries). It is drawn at the body's size in a scale picture, never larger than the picture. */
532
497
  async #delegated(delegate) {
533
498
  if (this.#view !== undefined) {
534
- this.#view.dispose();
535
- this.#view = undefined;
536
- this.#viewKey = "";
499
+ this.#disposeView();
537
500
  }
538
501
  const center = this.hasAttribute("meridian") ? `${num(this.getAttribute("meridian"), 10)},20` : "10,20";
539
502
  const size = Math.round(this.clientWidth || 320);
540
503
  const fill = this.#fill();
541
504
  const key = `line|${center}|${fill}`;
542
505
  if (this.#delegateEl !== undefined && this.#delegateKind === key)
543
- return;
506
+ return true;
544
507
  const el = await delegate.line({ center, size });
508
+ if (el === null)
509
+ return false;
545
510
  this.#delegateEl?.remove();
546
511
  this.#stage.innerHTML = "";
547
512
  el.style.cssText = `display:block;width:${fill * 100}%;height:${fill * 100}%;aspect-ratio:1;position:absolute;left:${(1 - fill) * 50}%;top:${(1 - fill) * 50}%`;
@@ -549,6 +514,7 @@ export class WakuseiBody extends HTMLElement {
549
514
  this.#delegateEl = el;
550
515
  this.#delegateKind = key;
551
516
  this.#set("line");
517
+ return true;
552
518
  }
553
519
  /** How much of the picture's width the body's disc takes: 1 alone, less in a scale picture (`scale-to`, `span-km`). */
554
520
  #fill() {
@@ -575,8 +541,7 @@ export class WakuseiBody extends HTMLElement {
575
541
  const key = this.#key(state);
576
542
  if (key === this.#viewKey && this.#view.item !== undefined)
577
543
  return;
578
- this.#view.dispose();
579
- this.#view = undefined;
544
+ this.#disposeView();
580
545
  this.#makeView();
581
546
  }
582
547
  /** Hand the live scene the current state. */
@@ -1,9 +1,11 @@
1
+ import { moonGeocentric } from "./theory.ts";
2
+ export { moonGeocentric };
1
3
  import { type BodyId, type HostId, type MoonId } from "./facts.ts";
2
4
  import { type Vec3 } from "./vec.ts";
3
5
  /** Solve Kepler's equation for the eccentric anomaly, all in radians. */
4
6
  export declare function kepler(meanAnomaly: number, e: number): number;
5
7
  /**
6
- * 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 (within a few arc-seconds, see the accuracy guide), Pluto from JPL's approximate elements, a dwarf planet from the osculating elements of one epoch (JPL's Small-Body Database).
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).
7
9
  * @param planet - The planet's or dwarf planet's name.
8
10
  * @param ms - The instant, in milliseconds since 1970 (UTC).
9
11
  * @returns The position as x, y, z in au.
@@ -18,32 +20,38 @@ export declare function kepler(meanAnomaly: number, e: number): number;
18
20
  */
19
21
  export declare function heliocentric(planet: HostId, ms: number): Vec3;
20
22
  /**
21
- * 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.
22
- * @param id - A planet or a dwarf planet.
23
- * @returns The semi-major axis in au.
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
+ * 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
25
+ * the fit, not a bound for every date; `null` where no such measurement exists. Ask again after importing a table or for another moment.
26
+ *
27
+ * @param planet - A planet or dwarf planet.
28
+ * @param ms - The moment in milliseconds since 1970 (UTC).
29
+ * @returns The theory's name and its measured worst error in arc-seconds, or `null`.
24
30
  *
25
31
  * @example
26
32
  * ```ts
27
- * import { meanSunAu } from "@johnmorrisdotca/wakusei-planets";
33
+ * import { heliocentricModel } from "@johnmorrisdotca/wakusei-planets";
28
34
  *
29
- * console.log(meanSunAu("earth").toFixed(3));
35
+ * console.log(heliocentricModel("pluto", Date.UTC(2026, 0, 1)));
30
36
  * ```
31
37
  */
32
- export declare function meanSunAu(id: HostId): number;
38
+ export declare function heliocentricModel(planet: HostId, ms: number): {
39
+ theory: "vsop87b" | "chebyshev" | "osculating-elements" | "approximate-elements";
40
+ worstArcseconds: number | null;
41
+ };
33
42
  /**
34
- * The Moon's position from the Earth's centre (J2000 ecliptic, kilometres), from the largest terms of Meeus's lunar series.
35
- * @param ms - The instant, in milliseconds since 1970.
36
- * @returns The position as x, y, z in kilometres.
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.
45
+ * @returns The semi-major axis in au.
37
46
  *
38
47
  * @example
39
48
  * ```ts
40
- * import { moonGeocentric } from "@johnmorrisdotca/wakusei-planets";
49
+ * import { meanSunAu } from "@johnmorrisdotca/wakusei-planets";
41
50
  *
42
- * const [x, y, z] = moonGeocentric(Date.UTC(2026, 10, 2));
43
- * console.log(Math.round(Math.hypot(x, y, z)) > 350000);
51
+ * console.log(meanSunAu("earth").toFixed(3));
44
52
  * ```
45
53
  */
46
- export declare function moonGeocentric(ms: number): Vec3;
54
+ export declare function meanSunAu(id: HostId): number;
47
55
  /** The north pole of a body as a J2000 ecliptic unit vector. */
48
56
  export declare function poleOf(id: BodyId): Vec3;
49
57
  /** The prime meridian's direction (J2000 ecliptic unit vector) when it has turned to `w` degrees. */
package/dist/ephemeris.js CHANGED
@@ -1,11 +1,15 @@
1
1
  // Where the planets and their moons are at a date and time, and how a body looks from the Earth then: its pole, the face that turns toward us, where the Sun is.
2
- // Planets Mercury to Neptune: the VSOP87B series of Bretagnon and Francou, truncated (data/vsop.ts), in terrestrial time (time.ts). Pluto: JPL's "Keplerian Elements for Approximate Positions of the Major Planets",
3
- // Table 1 (1800 to 2050, https://ssd.jpl.nasa.gov/planets/approx_pos.html). The Moon: the largest terms of Meeus, "Astronomical Algorithms", chapter 47. Other moons: fitted to JPL Horizons (data/orbits.ts).
2
+ // Planets Mercury to Neptune: the VSOP87B series of Bretagnon and Francou, truncated (data/vsop.ts), in terrestrial time (time.ts). Pluto: a Chebyshev table fitted to JPL Horizons for 1800 to 2200 (data/pluto.ts),
3
+ // and outside those years JPL's "Keplerian Elements for Approximate Positions of the Major Planets", Table 1 (https://ssd.jpl.nasa.gov/planets/approx_pos.html). The Moon: the lunar solution ELP2000-82B (Chapront-Touze and Chapront, IMCCE) cut to its largest terms (data/lunar.ts). Other moons: fitted to JPL Horizons (data/orbits.ts).
4
4
  // Light travel time is allowed for, so a turning planet shows the face it really showed when the light left. Pure: no DOM, no three.js.
5
5
  import { ORBITS } from "./data/orbits.js";
6
6
  import { DWARF_ELEMENTS } from "./data/dwarf.js";
7
+ import { tableOf } from "./data/tables.js";
8
+ import { PLUTO, PLUTO_SEGMENT_MS, PLUTO_START } from "./data/pluto.js";
7
9
  import { VSOP87 } from "./data/vsop.js";
8
- import { toTerrestrialTime } from "./time.js";
10
+ import { moonGeocentric, vsopPosition } from "./theory.js";
11
+ export { moonGeocentric };
12
+ import { toTerrestrialTime } from "./clock.js";
9
13
  import { BODIES, MOONS_OF } from "./facts.js";
10
14
  import { add, cross, DEG, dot, fromRaDec, length, OBLIQUITY, RAD, scale, sub, toEcliptic, unit, wrap360 } from "./vec.js";
11
15
  /** Milliseconds since 1970 at J2000.0 (2000-01-01 12:00 TT, taken as UTC). */
@@ -14,16 +18,17 @@ const DAY = 86_400_000;
14
18
  const AU_KM = 149_597_870.7;
15
19
  /** Light takes this many seconds to cross one astronomical unit. */
16
20
  const LIGHT_SECONDS_PER_AU = 499.004784;
17
- // a (au), e, I, L, long.peri, long.node (degrees), then their rates per Julian century.
21
+ // Semi-major axes for meanSunAu. Only Pluto needs the remaining elements and rates:
22
+ // Mercury to Neptune always use VSOP87B before reaching the approximate fallback.
18
23
  const ELEMENTS = {
19
- mercury: [0.38709927, 0.20563593, 7.00497902, 252.2503235, 77.45779628, 48.33076593, 0.00000037, 0.00001906, -0.00594749, 149472.67411175, 0.16047689, -0.12534081],
20
- venus: [0.72333566, 0.00677672, 3.39467605, 181.9790995, 131.60246718, 76.67984255, 0.0000039, -0.00004107, -0.0007889, 58517.81538729, 0.00268329, -0.27769418],
21
- earth: [1.00000261, 0.01671123, -0.00001531, 100.46457166, 102.93768193, 0, 0.00000562, -0.00004392, -0.01294668, 35999.37244981, 0.32327364, 0],
22
- mars: [1.52371034, 0.0933941, 1.84969142, -4.55343205, -23.94362959, 49.55953891, 0.00001847, 0.00007882, -0.00813131, 19140.30268499, 0.44441088, -0.29257343],
23
- jupiter: [5.202887, 0.04838624, 1.30439695, 34.39644051, 14.72847983, 100.47390909, -0.00011607, -0.00013253, -0.00183714, 3034.74612775, 0.21252668, 0.20469106],
24
- saturn: [9.53667594, 0.05386179, 2.48599187, 49.95424423, 92.59887831, 113.66242448, -0.0012506, -0.00050991, 0.00193609, 1222.49362201, -0.41897216, -0.28867794],
25
- uranus: [19.18916464, 0.04725744, 0.77263783, 313.23810451, 170.9542763, 74.01692503, -0.00196176, -0.00004397, -0.00242939, 428.48202785, 0.40805281, 0.04240589],
26
- neptune: [30.06992276, 0.00859048, 1.77004347, -55.12002969, 44.96476227, 131.78422574, 0.00026291, 0.00005105, 0.00035372, 218.45945325, -0.32241464, -0.00508664],
24
+ mercury: [0.38709927],
25
+ venus: [0.72333566],
26
+ earth: [1.00000261],
27
+ mars: [1.52371034],
28
+ jupiter: [5.202887],
29
+ saturn: [9.53667594],
30
+ uranus: [19.18916464],
31
+ neptune: [30.06992276],
27
32
  pluto: [39.48211675, 0.2488273, 17.14001206, 238.92903833, 224.06891629, 110.30393684, -0.00031596, 0.0000517, 0.00004818, 145.20780515, -0.04062942, -0.01183482],
28
33
  };
29
34
  const centuries = (ms) => (ms - J2000) / (DAY * 36525);
@@ -44,28 +49,63 @@ export function kepler(meanAnomaly, e) {
44
49
  }
45
50
  return E;
46
51
  }
47
- /** A planet from its VSOP87B series: longitude, latitude and radius at a moment in terrestrial time, as x, y, z in the J2000 ecliptic. */
48
- function vsopPosition(series, terrestrialMs) {
49
- const t = (terrestrialMs - J2000) / (365_250 * DAY);
50
- const spherical = [0, 0, 0];
51
- for (let k = 0; k < 3; k += 1) {
52
- let sum = 0;
53
- let power = 1;
54
- for (const terms of series[k]) {
55
- let s = 0;
56
- for (const [amplitude, phase, frequency] of terms)
57
- s += amplitude * Math.cos(phase + frequency * t);
58
- sum += power * s;
59
- power *= t;
52
+ const PLUTO_TABLE = { start: PLUTO_START, segment: PLUTO_SEGMENT_MS, worst: 0.14637, segments: PLUTO };
53
+ /** A position from a Chebyshev table, as x, y, z in au, or undefined outside the years it covers. */
54
+ function fittedPosition(table, terrestrialMs) {
55
+ const segment = Math.floor((terrestrialMs - table.start) / table.segment);
56
+ const coefficients = table.segments[segment];
57
+ if (coefficients === undefined)
58
+ return undefined;
59
+ const x = (2 * (terrestrialMs - table.start - segment * table.segment)) / table.segment - 1;
60
+ const at = (axis) => {
61
+ let b1 = 0;
62
+ let b2 = 0;
63
+ for (let k = axis.length - 1; k >= 1; k -= 1) {
64
+ const b0 = 2 * x * b1 - b2 + axis[k];
65
+ b2 = b1;
66
+ b1 = b0;
60
67
  }
61
- spherical[k] = sum;
68
+ return x * b1 - b2 + axis[0];
69
+ };
70
+ return [at(coefficients[0]), at(coefficients[1]), at(coefficients[2])];
71
+ }
72
+ /** Same table priority and TT segment coverage for positions and model information. */
73
+ function fittedTableAt(planet, tt) {
74
+ const covers = (table) => table.segments[Math.floor((tt - table.start) / table.segment)] !== undefined;
75
+ if (planet === "pluto" && covers(PLUTO_TABLE))
76
+ return PLUTO_TABLE;
77
+ const registered = tableOf(planet);
78
+ return registered !== undefined && covers(registered) ? registered : undefined;
79
+ }
80
+ /** Each planet's mass as a fraction of the Sun's (IAU 2012 and JPL DE440 values; the Earth with its Moon), to find the Sun's place among the planets. */
81
+ const MASS_OVER_SUN = {
82
+ mercury: 1 / 6023657.33,
83
+ venus: 1 / 408523.72,
84
+ earth: 1 / 328900.56,
85
+ mars: 1 / 3098703.59,
86
+ jupiter: 1 / 1047.3486,
87
+ saturn: 1 / 3497.9018,
88
+ uranus: 1 / 22902.98,
89
+ neptune: 1 / 19412.26,
90
+ };
91
+ /** The barycentre of the solar system seen from the Sun (J2000 ecliptic, au): the planets' mass-weighted places, which move the Sun about a million kilometres in twelve years. */
92
+ function barycentreFromSun(terrestrialMs) {
93
+ let x = 0;
94
+ let y = 0;
95
+ let z = 0;
96
+ let total = 1;
97
+ for (const id of Object.keys(MASS_OVER_SUN)) {
98
+ const m = MASS_OVER_SUN[id];
99
+ const p = vsopPosition(VSOP87[id], terrestrialMs);
100
+ x += m * p[0];
101
+ y += m * p[1];
102
+ z += m * p[2];
103
+ total += m;
62
104
  }
63
- const [longitude, latitude, radius] = spherical;
64
- const cosLatitude = Math.cos(latitude);
65
- return [radius * cosLatitude * Math.cos(longitude), radius * cosLatitude * Math.sin(longitude), radius * Math.sin(latitude)];
105
+ return [x / total, y / total, z / total];
66
106
  }
67
107
  /**
68
- * 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 (within a few arc-seconds, see the accuracy guide), Pluto from JPL's approximate elements, a dwarf planet from the osculating elements of one epoch (JPL's Small-Body Database).
108
+ * 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).
69
109
  * @param planet - The planet's or dwarf planet's name.
70
110
  * @param ms - The instant, in milliseconds since 1970 (UTC).
71
111
  * @returns The position as x, y, z in au.
@@ -82,6 +122,17 @@ export function heliocentric(planet, ms) {
82
122
  const vsop = VSOP87[planet];
83
123
  if (vsop !== undefined)
84
124
  return vsopPosition(vsop, toTerrestrialTime(ms));
125
+ if (planet === "pluto" || tableOf(planet) !== undefined) {
126
+ const tt = toTerrestrialTime(ms);
127
+ const fitted = fittedTableAt(planet, tt);
128
+ if (fitted !== undefined) {
129
+ const position = fittedPosition(fitted, tt);
130
+ if (fitted === PLUTO_TABLE)
131
+ return position;
132
+ const sun = barycentreFromSun(tt);
133
+ return [position[0] + sun[0], position[1] + sun[1], position[2] + sun[2]];
134
+ }
135
+ }
85
136
  let a;
86
137
  let e;
87
138
  let I;
@@ -121,48 +172,45 @@ export function heliocentric(planet, ms) {
121
172
  return [(cw * cn - sw * sn * ci) * x + (-sw * cn - cw * sn * ci) * y, (cw * sn + sw * cn * ci) * x + (-sw * sn + cw * cn * ci) * y, sw * si * x + cw * si * y];
122
173
  }
123
174
  /**
124
- * 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.
125
- * @param id - A planet or a dwarf planet.
126
- * @returns The semi-major axis in au.
175
+ * 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
176
+ * 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
177
+ * the fit, not a bound for every date; `null` where no such measurement exists. Ask again after importing a table or for another moment.
178
+ *
179
+ * @param planet - A planet or dwarf planet.
180
+ * @param ms - The moment in milliseconds since 1970 (UTC).
181
+ * @returns The theory's name and its measured worst error in arc-seconds, or `null`.
127
182
  *
128
183
  * @example
129
184
  * ```ts
130
- * import { meanSunAu } from "@johnmorrisdotca/wakusei-planets";
185
+ * import { heliocentricModel } from "@johnmorrisdotca/wakusei-planets";
131
186
  *
132
- * console.log(meanSunAu("earth").toFixed(3));
187
+ * console.log(heliocentricModel("pluto", Date.UTC(2026, 0, 1)));
133
188
  * ```
134
189
  */
135
- export function meanSunAu(id) {
136
- const dwarf = DWARF_ELEMENTS[id];
137
- return dwarf !== undefined ? dwarf.a : ELEMENTS[id][0];
190
+ export function heliocentricModel(planet, ms) {
191
+ const tt = toTerrestrialTime(ms);
192
+ if (VSOP87[planet] !== undefined)
193
+ return { theory: "vsop87b", worstArcseconds: null };
194
+ const table = fittedTableAt(planet, tt);
195
+ return table !== undefined
196
+ ? { theory: "chebyshev", worstArcseconds: table.worst }
197
+ : { theory: planet in DWARF_ELEMENTS ? "osculating-elements" : "approximate-elements", worstArcseconds: null };
138
198
  }
139
199
  /**
140
- * The Moon's position from the Earth's centre (J2000 ecliptic, kilometres), from the largest terms of Meeus's lunar series.
141
- * @param ms - The instant, in milliseconds since 1970.
142
- * @returns The position as x, y, z in kilometres.
200
+ * 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.
201
+ * @param id - A planet or a dwarf planet.
202
+ * @returns The semi-major axis in au.
143
203
  *
144
204
  * @example
145
205
  * ```ts
146
- * import { moonGeocentric } from "@johnmorrisdotca/wakusei-planets";
206
+ * import { meanSunAu } from "@johnmorrisdotca/wakusei-planets";
147
207
  *
148
- * const [x, y, z] = moonGeocentric(Date.UTC(2026, 10, 2));
149
- * console.log(Math.round(Math.hypot(x, y, z)) > 350000);
208
+ * console.log(meanSunAu("earth").toFixed(3));
150
209
  * ```
151
210
  */
152
- export function moonGeocentric(ms) {
153
- const T = centuries(ms);
154
- const Lm = 218.3164477 + 481267.88123421 * T;
155
- const D = (297.8501921 + 445267.1114034 * T) * RAD;
156
- const M = (357.5291092 + 35999.0502909 * T) * RAD;
157
- const Mp = (134.9633964 + 477198.8675055 * T) * RAD;
158
- const F = (93.272095 + 483202.0175233 * T) * RAD;
159
- const lon = Lm + 6.289 * Math.sin(Mp) + 1.274 * Math.sin(2 * D - Mp) + 0.658 * Math.sin(2 * D) + 0.214 * Math.sin(2 * Mp) - 0.186 * Math.sin(M) - 0.114 * Math.sin(2 * F) - 0.059 * Math.sin(2 * D - 2 * Mp) - 0.057 * Math.sin(2 * D - M - Mp) + 0.053 * Math.sin(2 * D + Mp) + 0.046 * Math.sin(2 * D - M) + 0.041 * Math.sin(Mp - M);
160
- const lat = 5.128 * Math.sin(F) + 0.2806 * Math.sin(Mp + F) + 0.2777 * Math.sin(Mp - F) + 0.1732 * Math.sin(2 * D - F);
161
- const dist = 385000.56 - 20905.355 * Math.cos(Mp) - 3699.111 * Math.cos(2 * D - Mp) - 2955.968 * Math.cos(2 * D) - 569.925 * Math.cos(2 * Mp) + 48.888 * Math.cos(M) - 3.149 * Math.cos(2 * F);
162
- // The longitude is of the date; take off the precession since J2000 (about 1.4 degrees a century) to put it in the J2000 frame.
163
- const lam = (lon - 1.3969713 * T) * RAD;
164
- const bet = lat * RAD;
165
- return [dist * Math.cos(bet) * Math.cos(lam), dist * Math.cos(bet) * Math.sin(lam), dist * Math.sin(bet)];
211
+ export function meanSunAu(id) {
212
+ const dwarf = DWARF_ELEMENTS[id];
213
+ return dwarf !== undefined ? dwarf.a : ELEMENTS[id][0];
166
214
  }
167
215
  /** The north pole of a body as a J2000 ecliptic unit vector. */
168
216
  export function poleOf(id) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
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";
2
- export { apparent, heliocentric, meanSunAu, moonGeocentric, orbitPath, system, type Apparent, type MoonPlace, type Pose, type System } from "./ephemeris.ts";
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";
5
5
  export { lineSvg, mix, type LineOptions } from "./line.ts";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { BODIES, BODY_IDS, DWARF_IDS, MOONS_OF, PLANET_IDS, ringReach } from "./facts.js";
2
- export { apparent, heliocentric, meanSunAu, moonGeocentric, orbitPath, system } from "./ephemeris.js";
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";
5
5
  export { lineSvg, mix } from "./line.js";