@johnmorrisdotca/wakusei-planets 0.20.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 (83) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/NOTICE.md +9 -0
  3. package/README.md +34 -4
  4. package/dist/bodies/earth.js +13 -5
  5. package/dist/calendar.js +7 -6
  6. package/dist/clock.js +5 -6
  7. package/dist/coordinates.d.ts +7 -12
  8. package/dist/coordinates.js +19 -18
  9. package/dist/craft/cassini.d.ts +1 -0
  10. package/dist/craft/cassini.js +1131 -0
  11. package/dist/craft/galileo.d.ts +1 -0
  12. package/dist/craft/galileo.js +224 -0
  13. package/dist/craft/juno.d.ts +1 -0
  14. package/dist/craft/juno.js +640 -0
  15. package/dist/craft/newhorizons.d.ts +1 -0
  16. package/dist/craft/newhorizons.js +18 -0
  17. package/dist/craft/parker.d.ts +1 -0
  18. package/dist/craft/parker.js +221 -0
  19. package/dist/craft/pioneer10.d.ts +1 -0
  20. package/dist/craft/pioneer10.js +24 -0
  21. package/dist/craft/pioneer11.d.ts +1 -0
  22. package/dist/craft/pioneer11.js +34 -0
  23. package/dist/craft/voyager1.d.ts +1 -0
  24. package/dist/craft/voyager1.js +28 -0
  25. package/dist/craft/voyager2.d.ts +1 -0
  26. package/dist/craft/voyager2.js +43 -0
  27. package/dist/craft/webb.d.ts +1 -0
  28. package/dist/craft/webb.js +28 -0
  29. package/dist/data/craft.d.ts +23 -0
  30. package/dist/data/craft.js +53 -0
  31. package/dist/data/stars.d.ts +4 -0
  32. package/dist/data/stars.js +5088 -0
  33. package/dist/element.d.ts +1 -23
  34. package/dist/element.js +74 -110
  35. package/dist/ephemeris.d.ts +20 -0
  36. package/dist/ephemeris.js +51 -20
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/portrait/element.d.ts +1 -0
  40. package/dist/portrait/element.js +27 -39
  41. package/dist/scene/basis.d.ts +3 -0
  42. package/dist/scene/basis.js +4 -0
  43. package/dist/scene/body.d.ts +2 -4
  44. package/dist/scene/body.js +55 -67
  45. package/dist/scene/fallback.d.ts +4 -0
  46. package/dist/scene/fallback.js +5 -0
  47. package/dist/scene/painter.js +10 -23
  48. package/dist/scene/store.d.ts +2 -2
  49. package/dist/scene/textures.d.ts +30 -0
  50. package/dist/scene/textures.js +47 -0
  51. package/dist/sidereal.d.ts +4 -0
  52. package/dist/sidereal.js +15 -9
  53. package/dist/sky/engine.d.ts +6 -15
  54. package/dist/sky/engine.js +9 -38
  55. package/dist/sky/frames.d.ts +3 -0
  56. package/dist/sky/frames.js +26 -0
  57. package/dist/sky/types.d.ts +20 -0
  58. package/dist/sky/types.js +1 -0
  59. package/dist/space/aim.d.ts +18 -0
  60. package/dist/space/aim.js +28 -0
  61. package/dist/space/element.d.ts +212 -0
  62. package/dist/space/element.js +524 -0
  63. package/dist/space/frame.d.ts +152 -0
  64. package/dist/space/frame.js +169 -0
  65. package/dist/space/index.d.ts +4 -0
  66. package/dist/space/index.js +5 -0
  67. package/dist/space/ride.d.ts +89 -0
  68. package/dist/space/ride.js +58 -0
  69. package/dist/space/scale.d.ts +126 -0
  70. package/dist/space/scale.js +139 -0
  71. package/dist/space/scene.d.ts +189 -0
  72. package/dist/space/scene.js +422 -0
  73. package/dist/spacecraft-facts.d.ts +114 -0
  74. package/dist/spacecraft-facts.js +215 -0
  75. package/dist/spacecraft.d.ts +134 -0
  76. package/dist/spacecraft.js +198 -0
  77. package/dist/stars.d.ts +160 -0
  78. package/dist/stars.js +193 -0
  79. package/dist/suncalc.js +4 -10
  80. package/dist/version.d.ts +1 -1
  81. package/dist/version.js +1 -1
  82. package/dist/when.js +6 -11
  83. package/package.json +53 -4
package/dist/element.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { SharedRenderer } from "@johnmorrisdotca/kazoku-ui/renderer";
2
2
  import "./tables/all.ts";
3
3
  import { type BodyId, type Look } from "./facts.ts";
4
+ export { TEXTURE_BASE, TEXTURE_FAR_BASE } from "./scene/textures.ts";
4
5
  import { type ThreeParts } from "./scene/body.ts";
5
6
  import { setThreeLoader } from "./scene/shared.ts";
6
7
  export { setThreeLoader };
@@ -16,29 +17,6 @@ export { setThreeLoader };
16
17
  * ```
17
18
  */
18
19
  export type WakuseiState = "line" | "loading" | "still" | "live" | "lost" | "unavailable";
19
- /**
20
- * 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.
21
- *
22
- * @example
23
- * ```ts no-run
24
- * import { TEXTURE_BASE } from "@johnmorrisdotca/wakusei-planets/element";
25
- *
26
- * console.log(TEXTURE_BASE);
27
- * ```
28
- */
29
- export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.20.0/dist/textures/";
30
- /**
31
- * 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
32
- * never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
33
- *
34
- * @example
35
- * ```ts no-run
36
- * import { TEXTURE_FAR_BASE } from "@johnmorrisdotca/wakusei-planets/element";
37
- *
38
- * console.log(TEXTURE_FAR_BASE);
39
- * ```
40
- */
41
- export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.20.0/textures/";
42
20
  /**
43
21
  * The `<wakusei-body>` custom element: a body of the solar system, drawn in a look.
44
22
  *
package/dist/element.js CHANGED
@@ -4,35 +4,13 @@ import { BODIES, ringReach } from "./facts.js";
4
4
  import { createGate, frameCap } from "./gate.js";
5
5
  import { lineSvg } from "./line.js";
6
6
  import { createLive, defaultTurn, REDUCED_TURN } from "./live.js";
7
- import { VERSION } from "./version.js";
7
+ import { texturePaths } from "./scene/textures.js";
8
+ export { TEXTURE_BASE, TEXTURE_FAR_BASE } from "./scene/textures.js";
8
9
  import { createBodyItem } from "./scene/body.js";
9
10
  import { delegates, onRegister } from "./scene/store.js";
10
11
  import { setThreeLoader, takeRenderer } from "./scene/shared.js";
11
12
  import { turn as turnVec } from "./vec.js";
12
13
  export { setThreeLoader };
13
- /**
14
- * 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.
15
- *
16
- * @example
17
- * ```ts no-run
18
- * import { TEXTURE_BASE } from "@johnmorrisdotca/wakusei-planets/element";
19
- *
20
- * console.log(TEXTURE_BASE);
21
- * ```
22
- */
23
- export const TEXTURE_BASE = `https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@${VERSION}/dist/textures/`;
24
- /**
25
- * 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
26
- * never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
27
- *
28
- * @example
29
- * ```ts no-run
30
- * import { TEXTURE_FAR_BASE } from "@johnmorrisdotca/wakusei-planets/element";
31
- *
32
- * console.log(TEXTURE_FAR_BASE);
33
- * ```
34
- */
35
- export const TEXTURE_FAR_BASE = `https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v${VERSION}/textures/`;
36
14
  const num = (value, fallback) => {
37
15
  if (value === null || value.trim() === "")
38
16
  return fallback;
@@ -48,7 +26,12 @@ const readTime = (value) => {
48
26
  const ms = Date.parse(value);
49
27
  return Number.isFinite(ms) ? ms : undefined;
50
28
  };
51
- /** 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
+ }
52
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. */
53
36
  const ROOM = 2.2;
54
37
  function extentOf(id, options) {
@@ -204,15 +187,8 @@ export class WakuseiBody extends HTMLElement {
204
187
  this.#io?.disconnect();
205
188
  document.removeEventListener("visibilitychange", this.#onHidden);
206
189
  this.#unsub?.();
207
- this.removeEventListener("pointerenter", this.#hover);
208
- this.removeEventListener("focusin", this.#hover);
209
- this.removeEventListener("pointerdown", this.#hover);
210
- this.#view?.dispose();
211
- this.#view = undefined;
212
- this.#viewKey = "";
213
- this.#release?.();
214
- this.#release = undefined;
215
- this.#renderer = undefined;
190
+ this.#applyHover(false);
191
+ this.#disposeView(true);
216
192
  }
217
193
  attributeChangedCallback(name) {
218
194
  if (!this.isConnected)
@@ -278,10 +254,10 @@ export class WakuseiBody extends HTMLElement {
278
254
  rate: Math.max(-1e7, Math.min(1e7, num(this.getAttribute("rate"), 1))),
279
255
  moons,
280
256
  portrait: {
281
- ...(this.hasAttribute("tilt") ? { tilt: num(this.getAttribute("tilt"), 0) } : {}),
282
- ...(this.hasAttribute("pitch") ? { pitch: num(this.getAttribute("pitch"), 0) } : {}),
283
- ...(this.hasAttribute("phase") ? { phase: num(this.getAttribute("phase"), 0) } : {}),
284
- ...(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,
285
261
  },
286
262
  turn: (this.hasAttribute("turn") ? num(this.getAttribute("turn"), 0) : this.getAttribute("live") === "off" ? 0 : defaultTurn(this.body)) * (this.#reduce ? REDUCED_TURN : 1),
287
263
  };
@@ -294,39 +270,40 @@ export class WakuseiBody extends HTMLElement {
294
270
  }
295
271
  // --- the state of the scene --------------------------------------------------------------------------------------------------------------------
296
272
  #sceneOf(frame) {
297
- let { pole, meridian, light } = frame.pose;
273
+ const pose = { pole: frame.pose.pole, meridian: frame.pose.meridian, light: frame.pose.light };
298
274
  const tiltBy = this.#pitchDelta - this.#tilt;
299
275
  if (this.#yaw !== 0)
300
- meridian = turnVec(meridian, pole, this.#yaw);
301
- if (tiltBy !== 0) {
302
- const x = [1, 0, 0];
303
- pole = turnVec(pole, x, tiltBy);
304
- meridian = turnVec(meridian, x, tiltBy);
305
- light = turnVec(light, x, tiltBy);
306
- }
276
+ pose.meridian = turnVec(pose.meridian, pose.pole, this.#yaw);
277
+ if (tiltBy !== 0)
278
+ turnPose(pose, [1, 0, 0], tiltBy);
307
279
  const roll = -this.#roll;
308
- if (roll !== 0) {
309
- const z = [0, 0, 1];
310
- pole = turnVec(pole, z, roll);
311
- meridian = turnVec(meridian, z, roll);
312
- light = turnVec(light, z, roll);
313
- }
280
+ if (roll !== 0)
281
+ turnPose(pose, [0, 0, 1], roll);
314
282
  const r = this.#request();
315
283
  const scaleTo = this.getAttribute("scale-to");
316
284
  const range = this.hasAttribute("range") ? num(this.getAttribute("range"), 0) : undefined;
317
285
  const span = num(this.getAttribute("span-km"), 0);
318
- 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 } : {}) });
319
- const moons = r.moons
320
- ? frame.moons
321
- .filter((m) => m.distance <= extent * 1.05)
322
- .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) {
323
300
  const orbit = this.#orbits.get(m.id);
324
- 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);
325
302
  const rotated = roll === 0 ? tipped : turnVec(tipped, [0, 0, 1], roll);
326
- 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) } : {}) };
327
- })
328
- : undefined;
329
- 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;
330
307
  }
331
308
  #tilted = new Map();
332
309
  #tiltedOrbit(id, orbit, tilt, roll) {
@@ -380,15 +357,12 @@ export class WakuseiBody extends HTMLElement {
380
357
  async #refresh() {
381
358
  if (!this.isConnected)
382
359
  return;
383
- const stage = this.#stage;
384
360
  this.setAttribute("aria-label", this.#label());
385
361
  if (this.hasAttribute("size"))
386
362
  this.style.setProperty("--wakusei-size", `${num(this.getAttribute("size"), 320)}px`);
387
363
  const delegate = this.look === "line" ? delegates.get(this.body) : undefined;
388
- if (delegate !== undefined) {
389
- await this.#delegated(delegate);
364
+ if (delegate !== undefined && (await this.#delegated(delegate)))
390
365
  return;
391
- }
392
366
  if (this.#delegateEl !== undefined) {
393
367
  this.#delegateEl.remove();
394
368
  this.#delegateEl = undefined;
@@ -396,14 +370,8 @@ export class WakuseiBody extends HTMLElement {
396
370
  }
397
371
  const wants3d = this.look !== "line" && this.#state !== "unavailable";
398
372
  if (!wants3d) {
399
- if (this.#view !== undefined) {
400
- this.#view.dispose();
401
- this.#view = undefined;
402
- this.#viewKey = "";
403
- this.#release?.();
404
- this.#release = undefined;
405
- this.#renderer = undefined;
406
- }
373
+ if (this.#view !== undefined)
374
+ this.#disposeView(true);
407
375
  this.#drawLine();
408
376
  if (this.look === "line")
409
377
  this.#set("line");
@@ -413,9 +381,7 @@ export class WakuseiBody extends HTMLElement {
413
381
  if (this.#view !== undefined && this.#viewSig !== sig) {
414
382
  if (this.#view.live)
415
383
  this.#wantLive = true;
416
- this.#view.dispose();
417
- this.#view = undefined;
418
- this.#viewKey = "";
384
+ this.#disposeView();
419
385
  }
420
386
  if (this.#view === undefined || this.#viewKey === "")
421
387
  await this.#ensureView();
@@ -432,20 +398,18 @@ export class WakuseiBody extends HTMLElement {
432
398
  if (this.#wantLive || this.#hasPriority())
433
399
  void this.goLive();
434
400
  }
435
- void stage;
436
401
  }
437
402
  #hasPriority() {
438
403
  const mode = this.getAttribute("live") ?? "always";
439
404
  return mode === "always" && this.#visible;
440
405
  }
441
- #applyHover() {
442
- this.removeEventListener("pointerenter", this.#hover);
443
- this.removeEventListener("focusin", this.#hover);
444
- this.removeEventListener("pointerdown", this.#hover);
445
- if ((this.getAttribute("live") ?? "always") === "hover") {
446
- this.addEventListener("pointerenter", this.#hover);
447
- this.addEventListener("focusin", this.#hover);
448
- 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);
449
413
  }
450
414
  }
451
415
  #label() {
@@ -466,19 +430,29 @@ export class WakuseiBody extends HTMLElement {
466
430
  size,
467
431
  pose: scene.pose,
468
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])) } : {}),
469
- ...(scaleTo !== null || this.hasAttribute("span-km") || this.getAttribute("fit") !== "tight" ? { fill: this.#fill() } : {}),
470
- ...(this.getAttribute("lang") === "ja" ? { lang: "ja" } : {}),
471
- ...(this.getAttribute("labels") === "off" ? { labels: false } : {}),
472
- ...(stroke !== "" ? { stroke } : {}),
473
- ...(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,
474
438
  ...(this.#zoom !== 1 ? { zoom: this.#zoom, panX: scene.panX, panY: scene.panY } : {}),
475
439
  });
476
440
  this.#stage.innerHTML = html;
477
441
  }
478
442
  #key(state) {
479
- const q = (v) => v.map((n) => n.toFixed(2)).join(",");
480
443
  const moons = (state.moons ?? []).map((m) => `${m.id}:${m.x.toFixed(1)},${m.y.toFixed(1)}`).join(";");
481
- 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
+ }
482
456
  }
483
457
  /** The renderer, the view and its first still. */
484
458
  async #ensureView() {
@@ -498,22 +472,12 @@ export class WakuseiBody extends HTMLElement {
498
472
  this.#viewSig = `${this.body}|${this.look}`;
499
473
  this.#stilled = false;
500
474
  this.#stage.innerHTML = "";
501
- const base = () => {
502
- const own = this.getAttribute("texture-base");
503
- return own === null || own === "" ? TEXTURE_BASE : own.endsWith("/") ? own : `${own}/`;
504
- };
505
475
  const item = createBodyItem({
506
476
  id: this.body,
507
477
  look: this.look === "illustrated" ? "realistic" : "painted",
508
478
  key: this.#viewKey,
509
479
  state: () => this.#sceneState ?? state,
510
- textureBase: base,
511
- farBase: () => {
512
- const own = this.getAttribute("texture-far-base");
513
- if (own !== null && own !== "")
514
- return own.endsWith("/") ? own : `${own}/`;
515
- return this.hasAttribute("texture-base") ? base() : TEXTURE_FAR_BASE;
516
- },
480
+ ...texturePaths(this),
517
481
  wantedWidth: (discPx) => discPx * Math.min(2, window.devicePixelRatio || 1) * 1.6,
518
482
  redraw: () => this.#view?.invalidate(),
519
483
  report: (note) => {
@@ -532,17 +496,17 @@ export class WakuseiBody extends HTMLElement {
532
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. */
533
497
  async #delegated(delegate) {
534
498
  if (this.#view !== undefined) {
535
- this.#view.dispose();
536
- this.#view = undefined;
537
- this.#viewKey = "";
499
+ this.#disposeView();
538
500
  }
539
501
  const center = this.hasAttribute("meridian") ? `${num(this.getAttribute("meridian"), 10)},20` : "10,20";
540
502
  const size = Math.round(this.clientWidth || 320);
541
503
  const fill = this.#fill();
542
504
  const key = `line|${center}|${fill}`;
543
505
  if (this.#delegateEl !== undefined && this.#delegateKind === key)
544
- return;
506
+ return true;
545
507
  const el = await delegate.line({ center, size });
508
+ if (el === null)
509
+ return false;
546
510
  this.#delegateEl?.remove();
547
511
  this.#stage.innerHTML = "";
548
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}%`;
@@ -550,6 +514,7 @@ export class WakuseiBody extends HTMLElement {
550
514
  this.#delegateEl = el;
551
515
  this.#delegateKind = key;
552
516
  this.#set("line");
517
+ return true;
553
518
  }
554
519
  /** How much of the picture's width the body's disc takes: 1 alone, less in a scale picture (`scale-to`, `span-km`). */
555
520
  #fill() {
@@ -576,8 +541,7 @@ export class WakuseiBody extends HTMLElement {
576
541
  const key = this.#key(state);
577
542
  if (key === this.#viewKey && this.#view.item !== undefined)
578
543
  return;
579
- this.#view.dispose();
580
- this.#view = undefined;
544
+ this.#disposeView();
581
545
  this.#makeView();
582
546
  }
583
547
  /** Hand the live scene the current state. */
@@ -19,6 +19,26 @@ export declare function kepler(meanAnomaly: number, e: number): number;
19
19
  * ```
20
20
  */
21
21
  export declare function heliocentric(planet: HostId, ms: number): Vec3;
22
+ /**
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`.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { heliocentricModel } from "@johnmorrisdotca/wakusei-planets";
34
+ *
35
+ * console.log(heliocentricModel("pluto", Date.UTC(2026, 0, 1)));
36
+ * ```
37
+ */
38
+ export declare function heliocentricModel(planet: HostId, ms: number): {
39
+ theory: "vsop87b" | "chebyshev" | "osculating-elements" | "approximate-elements";
40
+ worstArcseconds: number | null;
41
+ };
22
42
  /**
23
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.
24
44
  * @param id - A planet or a dwarf planet.
package/dist/ephemeris.js CHANGED
@@ -18,16 +18,17 @@ const DAY = 86_400_000;
18
18
  const AU_KM = 149_597_870.7;
19
19
  /** Light takes this many seconds to cross one astronomical unit. */
20
20
  const LIGHT_SECONDS_PER_AU = 499.004784;
21
- // 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.
22
23
  const ELEMENTS = {
23
- 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],
24
- 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],
25
- earth: [1.00000261, 0.01671123, -0.00001531, 100.46457166, 102.93768193, 0, 0.00000562, -0.00004392, -0.01294668, 35999.37244981, 0.32327364, 0],
26
- 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],
27
- 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],
28
- 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],
29
- 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],
30
- 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],
31
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],
32
33
  };
33
34
  const centuries = (ms) => (ms - J2000) / (DAY * 36525);
@@ -48,7 +49,7 @@ export function kepler(meanAnomaly, e) {
48
49
  }
49
50
  return E;
50
51
  }
51
- const PLUTO_TABLE = { start: PLUTO_START, segment: PLUTO_SEGMENT_MS, worst: 0, segments: PLUTO };
52
+ const PLUTO_TABLE = { start: PLUTO_START, segment: PLUTO_SEGMENT_MS, worst: 0.14637, segments: PLUTO };
52
53
  /** A position from a Chebyshev table, as x, y, z in au, or undefined outside the years it covers. */
53
54
  function fittedPosition(table, terrestrialMs) {
54
55
  const segment = Math.floor((terrestrialMs - table.start) / table.segment);
@@ -68,6 +69,14 @@ function fittedPosition(table, terrestrialMs) {
68
69
  };
69
70
  return [at(coefficients[0]), at(coefficients[1]), at(coefficients[2])];
70
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
+ }
71
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. */
72
81
  const MASS_OVER_SUN = {
73
82
  mercury: 1 / 6023657.33,
@@ -113,18 +122,15 @@ export function heliocentric(planet, ms) {
113
122
  const vsop = VSOP87[planet];
114
123
  if (vsop !== undefined)
115
124
  return vsopPosition(vsop, toTerrestrialTime(ms));
116
- if (planet === "pluto") {
117
- const table = fittedPosition(PLUTO_TABLE, toTerrestrialTime(ms));
118
- if (table !== undefined)
119
- return table;
120
- }
121
- const fitted = tableOf(planet);
122
- if (fitted !== undefined) {
125
+ if (planet === "pluto" || tableOf(planet) !== undefined) {
123
126
  const tt = toTerrestrialTime(ms);
124
- const table = fittedPosition(fitted, tt);
125
- if (table !== undefined) {
127
+ const fitted = fittedTableAt(planet, tt);
128
+ if (fitted !== undefined) {
129
+ const position = fittedPosition(fitted, tt);
130
+ if (fitted === PLUTO_TABLE)
131
+ return position;
126
132
  const sun = barycentreFromSun(tt);
127
- return [table[0] + sun[0], table[1] + sun[1], table[2] + sun[2]];
133
+ return [position[0] + sun[0], position[1] + sun[1], position[2] + sun[2]];
128
134
  }
129
135
  }
130
136
  let a;
@@ -165,6 +171,31 @@ export function heliocentric(planet, ms) {
165
171
  const si = Math.sin(I);
166
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];
167
173
  }
174
+ /**
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`.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * import { heliocentricModel } from "@johnmorrisdotca/wakusei-planets";
186
+ *
187
+ * console.log(heliocentricModel("pluto", Date.UTC(2026, 0, 1)));
188
+ * ```
189
+ */
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 };
198
+ }
168
199
  /**
169
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.
170
201
  * @param id - A planet or a dwarf planet.
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";
@@ -1,6 +1,7 @@
1
1
  import type { SharedRenderer } from "@johnmorrisdotca/kazoku-ui/renderer";
2
2
  import type { ThreeParts } from "../scene/body.ts";
3
3
  import { setThreeLoader } from "../scene/shared.ts";
4
+ import "../element.ts";
4
5
  import { type Guide, type Placed, type Portrait, type Resolved } from "./model.ts";
5
6
  export { setThreeLoader };
6
7
  /**
@@ -1,7 +1,9 @@
1
1
  import { BODIES } from "../facts.js";
2
2
  import { createGate, frameCap } from "../gate.js";
3
3
  import { setThreeLoader, takeRenderer } from "../scene/shared.js";
4
- import { TEXTURE_BASE, TEXTURE_FAR_BASE } from "../element.js";
4
+ // /portrait has always registered the body element as well.
5
+ import "../element.js";
6
+ import { texturePaths } from "../scene/textures.js";
5
7
  import { backgroundCss, drawShapes, lineScene, paintBackground, shapesOf, shapesSvg, starfield } from "./overlay.js";
6
8
  import { decodeScene, defaultPortrait, encodeScene, fromScreen, hitTest, resolve, toScreen } from "./model.js";
7
9
  import { REDUCED_TURN } from "../live.js";
@@ -151,15 +153,8 @@ export class WakuseiPortrait extends HTMLElement {
151
153
  this.#stopTick();
152
154
  this.#io?.disconnect();
153
155
  document.removeEventListener("visibilitychange", this.#onHidden);
154
- this.removeEventListener("pointerenter", this.#hover);
155
- this.removeEventListener("focusin", this.#hover);
156
- this.removeEventListener("pointerdown", this.#hover);
157
- this.#view?.dispose();
158
- this.#view = undefined;
159
- this.#viewKey = "";
160
- this.#release?.();
161
- this.#release = undefined;
162
- this.#renderer = undefined;
156
+ this.#applyHover(false);
157
+ this.#disposeView(true);
163
158
  }
164
159
  attributeChangedCallback(name) {
165
160
  if (!this.isConnected)
@@ -313,14 +308,8 @@ export class WakuseiPortrait extends HTMLElement {
313
308
  this.setAttribute("aria-label", this.#label());
314
309
  const wants3d = p.look !== "line" && this.#state !== "unavailable" && p.items.length > 0;
315
310
  if (!wants3d) {
316
- if (this.#view !== undefined) {
317
- this.#view.dispose();
318
- this.#view = undefined;
319
- this.#viewKey = "";
320
- this.#release?.();
321
- this.#release = undefined;
322
- this.#renderer = undefined;
323
- }
311
+ if (this.#view !== undefined)
312
+ this.#disposeView(true);
324
313
  this.#drawLine();
325
314
  if (p.look === "line" || p.items.length === 0)
326
315
  this.#set("line");
@@ -352,14 +341,13 @@ export class WakuseiPortrait extends HTMLElement {
352
341
  #priority() {
353
342
  return (this.getAttribute("live") ?? "always") === "always" && this.#visible;
354
343
  }
355
- #applyHover() {
356
- this.removeEventListener("pointerenter", this.#hover);
357
- this.removeEventListener("focusin", this.#hover);
358
- this.removeEventListener("pointerdown", this.#hover);
359
- if ((this.getAttribute("live") ?? "always") === "hover") {
360
- this.addEventListener("pointerenter", this.#hover);
361
- this.addEventListener("focusin", this.#hover);
362
- this.addEventListener("pointerdown", this.#hover);
344
+ #applyHover(allow = true) {
345
+ const events = ["pointerenter", "focusin", "pointerdown"];
346
+ for (const name of events)
347
+ this.removeEventListener(name, this.#hover);
348
+ if (allow && (this.getAttribute("live") ?? "always") === "hover") {
349
+ for (const name of events)
350
+ this.addEventListener(name, this.#hover);
363
351
  }
364
352
  }
365
353
  #poses() {
@@ -388,6 +376,17 @@ export class WakuseiPortrait extends HTMLElement {
388
376
  const { width } = this.#size();
389
377
  return `${encodeScene(this.#portrait)}|${width}`;
390
378
  }
379
+ // Replacing a view keeps the renderer lease; leaving 3D gives it back.
380
+ #disposeView(releaseRenderer = false) {
381
+ this.#view?.dispose();
382
+ this.#view = undefined;
383
+ this.#viewKey = "";
384
+ if (releaseRenderer) {
385
+ this.#release?.();
386
+ this.#release = undefined;
387
+ this.#renderer = undefined;
388
+ }
389
+ }
391
390
  async #ensureView() {
392
391
  if (this.#renderer === undefined) {
393
392
  const taken = takeRenderer(this.#onContext);
@@ -401,20 +400,10 @@ export class WakuseiPortrait extends HTMLElement {
401
400
  this.#viewKey = this.#key();
402
401
  this.#stilled = false;
403
402
  this.#stage.innerHTML = "";
404
- const base = () => {
405
- const own = this.getAttribute("texture-base");
406
- return own === null || own === "" ? TEXTURE_BASE : own.endsWith("/") ? own : `${own}/`;
407
- };
408
403
  const item = createPortraitItem({
409
404
  key: this.#viewKey,
410
405
  state: () => this.#draw(),
411
- textureBase: base,
412
- farBase: () => {
413
- const own = this.getAttribute("texture-far-base");
414
- if (own !== null && own !== "")
415
- return own.endsWith("/") ? own : `${own}/`;
416
- return this.hasAttribute("texture-base") ? base() : TEXTURE_FAR_BASE;
417
- },
406
+ ...texturePaths(this),
418
407
  redraw: () => this.#view?.invalidate(),
419
408
  });
420
409
  this.#view = this.#renderer.view(this.#stage, item);
@@ -436,8 +425,7 @@ export class WakuseiPortrait extends HTMLElement {
436
425
  return;
437
426
  if (this.#key() === this.#viewKey)
438
427
  return;
439
- this.#view.dispose();
440
- this.#view = undefined;
428
+ this.#disposeView();
441
429
  this.#makeView();
442
430
  }
443
431
  #sync() {
@@ -0,0 +1,3 @@
1
+ import type { Matrix4 } from "three";
2
+ import type { Vec3 } from "../vec.ts";
3
+ export declare function writeBasis(matrix: Matrix4, x: Vec3, y: Vec3, z: Vec3, sx?: number, sy?: number, sz?: number): Matrix4;
@@ -0,0 +1,4 @@
1
+ // The axes are already numeric triples; do not allocate Vector3 objects every frame.
2
+ export function writeBasis(matrix, x, y, z, sx = 1, sy = 1, sz = 1) {
3
+ return matrix.set(x[0] * sx, y[0] * sy, z[0] * sz, 0, x[1] * sx, y[1] * sy, z[1] * sz, 0, x[2] * sx, y[2] * sy, z[2] * sz, 0, 0, 0, 0, 1);
4
+ }