@johnmorrisdotca/wakusei-planets 0.34.0 → 0.36.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 (215) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/NOTICE.md +64 -0
  3. package/README.md +21 -3
  4. package/dist/approaches.d.ts +276 -0
  5. package/dist/approaches.js +255 -0
  6. package/dist/asteroids.d.ts +397 -0
  7. package/dist/asteroids.js +338 -0
  8. package/dist/comets.d.ts +316 -0
  9. package/dist/comets.js +404 -0
  10. package/dist/craft/bepicolombo.d.ts +1 -0
  11. package/dist/craft/bepicolombo.js +923 -0
  12. package/dist/craft/europaclipper.d.ts +1 -0
  13. package/dist/craft/europaclipper.js +342 -0
  14. package/dist/craft/hayabusa2.d.ts +1 -0
  15. package/dist/craft/hayabusa2.js +73 -0
  16. package/dist/craft/juice.d.ts +1 -0
  17. package/dist/craft/juice.js +40 -0
  18. package/dist/craft/lucy.d.ts +1 -0
  19. package/dist/craft/lucy.js +42 -0
  20. package/dist/craft/osirisapex.d.ts +1 -0
  21. package/dist/craft/osirisapex.js +69 -0
  22. package/dist/craft/psyche.d.ts +1 -0
  23. package/dist/craft/psyche.js +30 -0
  24. package/dist/craft/solarorbiter.d.ts +1 -0
  25. package/dist/craft/solarorbiter.js +94 -0
  26. package/dist/data/approaches.d.ts +17 -0
  27. package/dist/data/approaches.js +4192 -0
  28. package/dist/data/asteroids.d.ts +3 -0
  29. package/dist/data/asteroids.js +107 -0
  30. package/dist/data/comets.d.ts +2 -0
  31. package/dist/data/comets.js +36 -0
  32. package/dist/data/orbiters.d.ts +368 -0
  33. package/dist/data/orbiters.js +370 -0
  34. package/dist/data/places-67p.d.ts +27 -0
  35. package/dist/data/places-67p.js +2 -0
  36. package/dist/data/places-ariel.d.ts +602 -0
  37. package/dist/data/places-ariel.js +27 -0
  38. package/dist/data/places-bennu.d.ts +25 -0
  39. package/dist/data/places-bennu.js +2 -0
  40. package/dist/data/places-callisto.d.ts +3547 -0
  41. package/dist/data/places-callisto.js +155 -0
  42. package/dist/data/places-ceres.d.ts +3436 -0
  43. package/dist/data/places-ceres.js +150 -0
  44. package/dist/data/places-charon.d.ts +349 -0
  45. package/dist/data/places-charon.js +16 -0
  46. package/dist/data/places-dimorphos.d.ts +23 -0
  47. package/dist/data/places-dimorphos.js +2 -0
  48. package/dist/data/places-dione.d.ts +2258 -0
  49. package/dist/data/places-dione.js +99 -0
  50. package/dist/data/places-enceladus.d.ts +2009 -0
  51. package/dist/data/places-enceladus.js +88 -0
  52. package/dist/data/places-eros.d.ts +26 -0
  53. package/dist/data/places-eros.js +2 -0
  54. package/dist/data/places-europa.d.ts +2977 -0
  55. package/dist/data/places-europa.js +130 -0
  56. package/dist/data/places-ganymede.d.ts +4518 -0
  57. package/dist/data/places-ganymede.js +197 -0
  58. package/dist/data/places-iapetus.d.ts +1616 -0
  59. package/dist/data/places-iapetus.js +71 -0
  60. package/dist/data/places-io.d.ts +6012 -0
  61. package/dist/data/places-io.js +262 -0
  62. package/dist/data/places-jupiter.d.ts +46 -0
  63. package/dist/data/places-jupiter.js +3 -0
  64. package/dist/data/places-mars.d.ts +20701 -0
  65. package/dist/data/places-mars.js +942 -0
  66. package/dist/data/places-mercury.d.ts +9256 -0
  67. package/dist/data/places-mercury.js +403 -0
  68. package/dist/data/places-mimas.d.ts +968 -0
  69. package/dist/data/places-mimas.js +43 -0
  70. package/dist/data/places-miranda.d.ts +419 -0
  71. package/dist/data/places-miranda.js +19 -0
  72. package/dist/data/places-moon.d.ts +18849 -0
  73. package/dist/data/places-moon.js +861 -0
  74. package/dist/data/places-oberon.d.ts +235 -0
  75. package/dist/data/places-oberon.js +11 -0
  76. package/dist/data/places-pluto.d.ts +1687 -0
  77. package/dist/data/places-pluto.js +74 -0
  78. package/dist/data/places-rhea.d.ts +3317 -0
  79. package/dist/data/places-rhea.js +145 -0
  80. package/dist/data/places-ryugu.d.ts +87 -0
  81. package/dist/data/places-ryugu.js +5 -0
  82. package/dist/data/places-saturn.d.ts +25 -0
  83. package/dist/data/places-saturn.js +2 -0
  84. package/dist/data/places-tempel-1.d.ts +25 -0
  85. package/dist/data/places-tempel-1.js +2 -0
  86. package/dist/data/places-tethys.d.ts +1222 -0
  87. package/dist/data/places-tethys.js +54 -0
  88. package/dist/data/places-titan.d.ts +7031 -0
  89. package/dist/data/places-titan.js +306 -0
  90. package/dist/data/places-titania.d.ts +418 -0
  91. package/dist/data/places-titania.js +19 -0
  92. package/dist/data/places-triton.d.ts +1457 -0
  93. package/dist/data/places-triton.js +64 -0
  94. package/dist/data/places-umbriel.d.ts +303 -0
  95. package/dist/data/places-umbriel.js +14 -0
  96. package/dist/data/places-venus.d.ts +9290 -0
  97. package/dist/data/places-venus.js +405 -0
  98. package/dist/data/places-vesta.d.ts +2444 -0
  99. package/dist/data/places-vesta.js +107 -0
  100. package/dist/data/roadster.d.ts +8 -0
  101. package/dist/data/roadster.js +686 -0
  102. package/dist/element.js +17 -3
  103. package/dist/orbiter-facts.d.ts +480 -0
  104. package/dist/orbiter-facts.js +189 -0
  105. package/dist/orbiters.d.ts +256 -0
  106. package/dist/orbiters.js +275 -0
  107. package/dist/places/67p.d.ts +13 -0
  108. package/dist/places/67p.js +14 -0
  109. package/dist/places/ariel.d.ts +13 -0
  110. package/dist/places/ariel.js +14 -0
  111. package/dist/places/bennu.d.ts +13 -0
  112. package/dist/places/bennu.js +14 -0
  113. package/dist/places/callisto.d.ts +13 -0
  114. package/dist/places/callisto.js +14 -0
  115. package/dist/places/ceres.d.ts +13 -0
  116. package/dist/places/ceres.js +14 -0
  117. package/dist/places/charon.d.ts +13 -0
  118. package/dist/places/charon.js +14 -0
  119. package/dist/places/dimorphos.d.ts +13 -0
  120. package/dist/places/dimorphos.js +14 -0
  121. package/dist/places/dione.d.ts +13 -0
  122. package/dist/places/dione.js +14 -0
  123. package/dist/places/enceladus.d.ts +13 -0
  124. package/dist/places/enceladus.js +14 -0
  125. package/dist/places/eros.d.ts +13 -0
  126. package/dist/places/eros.js +14 -0
  127. package/dist/places/europa.d.ts +13 -0
  128. package/dist/places/europa.js +14 -0
  129. package/dist/places/ganymede.d.ts +13 -0
  130. package/dist/places/ganymede.js +14 -0
  131. package/dist/places/iapetus.d.ts +13 -0
  132. package/dist/places/iapetus.js +14 -0
  133. package/dist/places/io.d.ts +13 -0
  134. package/dist/places/io.js +14 -0
  135. package/dist/places/jupiter.d.ts +13 -0
  136. package/dist/places/jupiter.js +14 -0
  137. package/dist/places/mars.d.ts +12 -0
  138. package/dist/places/mars.js +13 -0
  139. package/dist/places/mercury.d.ts +13 -0
  140. package/dist/places/mercury.js +14 -0
  141. package/dist/places/mimas.d.ts +13 -0
  142. package/dist/places/mimas.js +14 -0
  143. package/dist/places/miranda.d.ts +13 -0
  144. package/dist/places/miranda.js +14 -0
  145. package/dist/places/moon.d.ts +12 -0
  146. package/dist/places/moon.js +13 -0
  147. package/dist/places/oberon.d.ts +13 -0
  148. package/dist/places/oberon.js +14 -0
  149. package/dist/places/pluto.d.ts +13 -0
  150. package/dist/places/pluto.js +14 -0
  151. package/dist/places/rhea.d.ts +13 -0
  152. package/dist/places/rhea.js +14 -0
  153. package/dist/places/ryugu.d.ts +13 -0
  154. package/dist/places/ryugu.js +14 -0
  155. package/dist/places/saturn.d.ts +13 -0
  156. package/dist/places/saturn.js +14 -0
  157. package/dist/places/tempel-1.d.ts +13 -0
  158. package/dist/places/tempel-1.js +14 -0
  159. package/dist/places/tethys.d.ts +13 -0
  160. package/dist/places/tethys.js +14 -0
  161. package/dist/places/titan.d.ts +13 -0
  162. package/dist/places/titan.js +14 -0
  163. package/dist/places/titania.d.ts +13 -0
  164. package/dist/places/titania.js +14 -0
  165. package/dist/places/triton.d.ts +13 -0
  166. package/dist/places/triton.js +14 -0
  167. package/dist/places/umbriel.d.ts +13 -0
  168. package/dist/places/umbriel.js +14 -0
  169. package/dist/places/venus.d.ts +13 -0
  170. package/dist/places/venus.js +14 -0
  171. package/dist/places/vesta.d.ts +13 -0
  172. package/dist/places/vesta.js +14 -0
  173. package/dist/places.d.ts +354 -0
  174. package/dist/places.js +357 -0
  175. package/dist/plan/element.d.ts +52 -0
  176. package/dist/plan/element.js +258 -0
  177. package/dist/plan/index.d.ts +2 -0
  178. package/dist/plan/index.js +2 -0
  179. package/dist/plan/layout.d.ts +230 -0
  180. package/dist/plan/layout.js +229 -0
  181. package/dist/plan/svg.d.ts +125 -0
  182. package/dist/plan/svg.js +185 -0
  183. package/dist/roadster.d.ts +415 -0
  184. package/dist/roadster.js +496 -0
  185. package/dist/scene/body.js +10 -9
  186. package/dist/scene/painter.d.ts +1 -1
  187. package/dist/scene/painter.js +23 -7
  188. package/dist/scene/textures.d.ts +2 -2
  189. package/dist/space/beside.d.ts +4 -1
  190. package/dist/space/beside.js +47 -6
  191. package/dist/space/covered.d.ts +102 -0
  192. package/dist/space/covered.js +98 -0
  193. package/dist/space/element.d.ts +101 -5
  194. package/dist/space/element.js +474 -30
  195. package/dist/space/frame.d.ts +14 -0
  196. package/dist/space/frame.js +16 -0
  197. package/dist/space/index.d.ts +4 -1
  198. package/dist/space/index.js +4 -1
  199. package/dist/space/regions.d.ts +111 -0
  200. package/dist/space/regions.js +84 -0
  201. package/dist/space/scale.d.ts +2 -1
  202. package/dist/space/scale.js +13 -2
  203. package/dist/space/scene.d.ts +109 -8
  204. package/dist/space/scene.js +313 -37
  205. package/dist/space/travel.d.ts +256 -0
  206. package/dist/space/travel.js +597 -0
  207. package/dist/spacecraft-facts.d.ts +4 -4
  208. package/dist/spacecraft-facts.js +158 -3
  209. package/dist/spacecraft.d.ts +69 -2
  210. package/dist/spacecraft.js +45 -2
  211. package/dist/textures/mimas-1024.webp +0 -0
  212. package/dist/textures/mimas-512.webp +0 -0
  213. package/dist/version.d.ts +1 -1
  214. package/dist/version.js +1 -1
  215. package/package.json +208 -1
package/dist/places.js ADDED
@@ -0,0 +1,357 @@
1
+ // Places on a body: the record a page marks on the Moon, Mars or any of 31 other bodies (a landing, a rover, a crash, impact or atmospheric-entry site, a named feature), the lookups over a body's list, and the helpers a page needs
2
+ // beside them: the sub-solar point, the terminator and the local solar time at a place, at any moment, from the package's own ephemeris and the IAU poles. Pure: no DOM, no clock reads. The lists
3
+ // themselves are the entry points `/places/<body>`, so a page pays only for the body it shows.
4
+ import { apparent } from "./ephemeris.js";
5
+ import { BODIES } from "./facts.js";
6
+ import { cross, dot } from "./vec.js";
7
+ import { moment } from "./when.js";
8
+ /**
9
+ * The credit a page that shows places owes each source, one row for every `source.id` the tables use: the line to print, the licence or terms it rests on and the address. The lander catalogue's is a condition of its licence (CC BY 4.0: "data from GCAT (J. McDowell,
10
+ * planet4589.org/space/gcat)"); the others are US government works, credited as their owners ask, and the papers' coordinates are facts (each record's `source.url` names the paper).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { PLACES_CREDITS } from "@johnmorrisdotca/wakusei-planets/places";
15
+ *
16
+ * console.log(PLACES_CREDITS.map((credit) => credit.line).join("; "));
17
+ * ```
18
+ */
19
+ export const PLACES_CREDITS = [
20
+ { id: "gcat-landercat", line: "data from GCAT (J. McDowell, planet4589.org/space/gcat)", licence: "CC BY 4.0", url: "https://planet4589.org/space/gcat/" },
21
+ { id: "iau-gazetteer", line: "IAU Gazetteer of Planetary Nomenclature, U.S. Geological Survey", licence: "US public domain", url: "https://planetarynames.wr.usgs.gov/" },
22
+ { id: "nssdca", line: "NASA NSSDCA", licence: "US government work (NASA content is generally not subject to copyright in the United States)", url: "https://nssdc.gsfc.nasa.gov/" },
23
+ { id: "pds-ode", line: "NASA Planetary Data System, Mars Orbital Data Explorer", licence: "US government work", url: "https://ode.rsl.wustl.edu/mars/" },
24
+ { id: "nasa-mars24", line: "NASA Goddard Institute for Space Studies, Mars24 Sunclock", licence: "US government work", url: "https://www.giss.nasa.gov/tools/mars24/" },
25
+ { id: "agency", line: "NASA mission and Photojournal pages (the address is in each record's source.url)", licence: "US government work", url: "https://www.nasa.gov/nasa-brand-center/images-and-media/" },
26
+ { id: "nasa-ntrs", line: "Basilevsky and Weitz 1992, The geology of the Venera/Vega landing sites, NASA Technical Reports Server", licence: "public use permitted (NTRS)", url: "https://ntrs.nasa.gov/citations/19930005108" },
27
+ { id: "pds-atmospheres", line: "NASA Planetary Data System, Planetary Atmospheres Node, Pioneer Venus summary", licence: "US government work", url: "https://pds-atmospheres.nmsu.edu/data_and_services/atmospheres_data/PIONEER_Venus/venus_cp.html" },
28
+ { id: "paper", line: "the published paper named in the record's source.url (Daly et al. 2023; Nagdimunov et al. 2014; Hoang et al. 2020)", licence: "coordinates (facts) typed from the papers, none of whose text, figures or tables is copied; Daly et al. 2023 is CC BY 4.0, credited", url: "https://doi.org/10.1038/s41586-023-05810-5" },
29
+ ];
30
+ /**
31
+ * The bodies that have places, in the order a picker shows them: the Moon and Mars (landings, rovers and named features), Mercury, Venus, the moons of Jupiter, Saturn, Uranus and Neptune that have mapped names, Pluto and Charon, Ceres and Vesta
32
+ * (named features), then the bodies with only sites (Eros, Ryugu, Bennu, Dimorphos, comets Tempel 1 and 67P, Jupiter and Saturn themselves). Each has its own entry point `/places/<body>`.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { PLACE_BODIES } from "@johnmorrisdotca/wakusei-planets/places";
37
+ *
38
+ * console.log(PLACE_BODIES.join(", "));
39
+ * ```
40
+ */
41
+ export const PLACE_BODIES = [
42
+ "moon", "mars", "mercury", "venus", "io", "europa", "ganymede", "callisto", "titan", "enceladus", "mimas", "tethys", "dione", "rhea", "iapetus", "miranda", "ariel", "umbriel", "titania", "oberon", "triton", "pluto", "charon", "ceres", "vesta",
43
+ "eros", "ryugu", "bennu", "dimorphos", "tempel-1", "67p", "jupiter", "saturn",
44
+ ];
45
+ /**
46
+ * The places of one kind, or of several, from a body's list, in the list's order (sites by date, then features by size).
47
+ *
48
+ * @param places - A body's list (`PLACES_MOON`, `PLACES_MARS`).
49
+ * @param kinds - The kinds wanted.
50
+ * @returns Those places.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { PLACES_MARS } from "@johnmorrisdotca/wakusei-planets/places/mars";
55
+ * import { placesOfKind } from "@johnmorrisdotca/wakusei-planets/places";
56
+ *
57
+ * console.log(placesOfKind(PLACES_MARS, "rover").map((place) => place.name.en).join(", "));
58
+ * ```
59
+ */
60
+ export function placesOfKind(places, ...kinds) {
61
+ return places.filter((place) => kinds.includes(place.kind));
62
+ }
63
+ /**
64
+ * A place by its id, or by its name in English or Japanese in any case, or `undefined`.
65
+ *
66
+ * @param places - A body's list.
67
+ * @param text - `moon/apollo-11-lunar-module`, `Apollo 11 lunar module`, `Mare Imbrium`, `嫦娥4号`.
68
+ * @returns The place, or `undefined` when none matches.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { PLACES_MOON } from "@johnmorrisdotca/wakusei-planets/places/moon";
73
+ * import { findPlace } from "@johnmorrisdotca/wakusei-planets/places";
74
+ *
75
+ * console.log(findPlace(PLACES_MOON, "mare imbrium")?.feature?.diameterKm, findPlace(PLACES_MOON, "nowhere"));
76
+ * ```
77
+ */
78
+ export function findPlace(places, text) {
79
+ if (typeof text !== "string")
80
+ return undefined;
81
+ const wanted = text.trim().toLowerCase();
82
+ return places.find((place) => place.id === wanted || place.name.en.toLowerCase() === wanted || place.name.ja === text.trim());
83
+ }
84
+ /**
85
+ * The places within a distance of a point on the body, nearest first.
86
+ *
87
+ * @param places - A body's list.
88
+ * @param lat - Planetocentric latitude in degrees.
89
+ * @param lon - East longitude in degrees.
90
+ * @param withinDeg - How far, as an angle at the body's centre, in degrees.
91
+ * @returns The places with their distance in degrees.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import { PLACES_MOON } from "@johnmorrisdotca/wakusei-planets/places/moon";
96
+ * import { placesNear } from "@johnmorrisdotca/wakusei-planets/places";
97
+ *
98
+ * console.log(placesNear(PLACES_MOON, 0.67, 23.47, 3).map((near) => `${near.place.name.en} ${near.degrees.toFixed(2)}`).slice(0, 3).join("; "));
99
+ * ```
100
+ */
101
+ export function placesNear(places, lat, lon, withinDeg) {
102
+ const out = [];
103
+ for (const place of places) {
104
+ const degrees = angleBetween(lat, lon, place.lat, place.lon);
105
+ if (degrees <= withinDeg)
106
+ out.push({ place, degrees });
107
+ }
108
+ return out.sort((a, b) => a.degrees - b.degrees);
109
+ }
110
+ const RAD = Math.PI / 180;
111
+ /**
112
+ * A body's places, loaded when asked for: the table of `/places/<body>` arrives as a chunk of its own the first time, so a page that never asks for one does not carry it.
113
+ *
114
+ * @param body - One of `PLACE_BODIES`: `moon`, `mars`, `venus`, `titan`, `pluto`, `67p` and the rest.
115
+ * @returns The list: the sites first, by date, then the named features by size. An unknown body is a rejected `RangeError`.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * import { loadPlaces } from "@johnmorrisdotca/wakusei-planets/places";
120
+ *
121
+ * const mars = await loadPlaces("mars");
122
+ * console.log(mars.length, "places on Mars");
123
+ * ```
124
+ */
125
+ export async function loadPlaces(body) {
126
+ switch (body) {
127
+ case "moon": return (await import("./places/moon.js")).PLACES_MOON;
128
+ case "mars": return (await import("./places/mars.js")).PLACES_MARS;
129
+ case "mercury": return (await import("./places/mercury.js")).PLACES_MERCURY;
130
+ case "venus": return (await import("./places/venus.js")).PLACES_VENUS;
131
+ case "io": return (await import("./places/io.js")).PLACES_IO;
132
+ case "europa": return (await import("./places/europa.js")).PLACES_EUROPA;
133
+ case "ganymede": return (await import("./places/ganymede.js")).PLACES_GANYMEDE;
134
+ case "callisto": return (await import("./places/callisto.js")).PLACES_CALLISTO;
135
+ case "titan": return (await import("./places/titan.js")).PLACES_TITAN;
136
+ case "enceladus": return (await import("./places/enceladus.js")).PLACES_ENCELADUS;
137
+ case "mimas": return (await import("./places/mimas.js")).PLACES_MIMAS;
138
+ case "tethys": return (await import("./places/tethys.js")).PLACES_TETHYS;
139
+ case "dione": return (await import("./places/dione.js")).PLACES_DIONE;
140
+ case "rhea": return (await import("./places/rhea.js")).PLACES_RHEA;
141
+ case "iapetus": return (await import("./places/iapetus.js")).PLACES_IAPETUS;
142
+ case "miranda": return (await import("./places/miranda.js")).PLACES_MIRANDA;
143
+ case "ariel": return (await import("./places/ariel.js")).PLACES_ARIEL;
144
+ case "umbriel": return (await import("./places/umbriel.js")).PLACES_UMBRIEL;
145
+ case "titania": return (await import("./places/titania.js")).PLACES_TITANIA;
146
+ case "oberon": return (await import("./places/oberon.js")).PLACES_OBERON;
147
+ case "triton": return (await import("./places/triton.js")).PLACES_TRITON;
148
+ case "pluto": return (await import("./places/pluto.js")).PLACES_PLUTO;
149
+ case "charon": return (await import("./places/charon.js")).PLACES_CHARON;
150
+ case "ceres": return (await import("./places/ceres.js")).PLACES_CERES;
151
+ case "vesta": return (await import("./places/vesta.js")).PLACES_VESTA;
152
+ case "eros": return (await import("./places/eros.js")).PLACES_EROS;
153
+ case "ryugu": return (await import("./places/ryugu.js")).PLACES_RYUGU;
154
+ case "bennu": return (await import("./places/bennu.js")).PLACES_BENNU;
155
+ case "dimorphos": return (await import("./places/dimorphos.js")).PLACES_DIMORPHOS;
156
+ case "tempel-1": return (await import("./places/tempel-1.js")).PLACES_TEMPEL_1;
157
+ case "67p": return (await import("./places/67p.js")).PLACES_67P;
158
+ case "jupiter": return (await import("./places/jupiter.js")).PLACES_JUPITER;
159
+ case "saturn": return (await import("./places/saturn.js")).PLACES_SATURN;
160
+ default: throw new RangeError(`places are held for ${PLACE_BODIES.join(", ")}, not "${String(body)}"`);
161
+ }
162
+ }
163
+ /**
164
+ * The places of a body by kind, from its list (loaded on the first call): `listPlaces("moon", "crewed", "landing")`. With no kind it is every place.
165
+ *
166
+ * @param body - One of `PLACE_BODIES`.
167
+ * @param kinds - The kinds wanted; none for all.
168
+ * @returns The places in the list's order.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * import { listPlaces } from "@johnmorrisdotca/wakusei-planets/places";
173
+ *
174
+ * const rovers = await listPlaces("mars", "rover");
175
+ * console.log(rovers.map((place) => place.name.en).join(", "));
176
+ * ```
177
+ */
178
+ export async function listPlaces(body, ...kinds) {
179
+ const all = await loadPlaces(body);
180
+ return kinds.length === 0 ? [...all] : placesOfKind(all, ...kinds);
181
+ }
182
+ /**
183
+ * The place nearest to a point on the body, by great-circle distance, or `undefined` for an empty list. Give kinds to look only among those (`"feature"` for the named surface, the others for the visited places).
184
+ *
185
+ * @param places - A body's list.
186
+ * @param lat - Planetocentric latitude in degrees.
187
+ * @param lon - East longitude in degrees.
188
+ * @param kinds - The kinds to look among; none for all.
189
+ * @returns The place and its distance in degrees at the body's centre, or `undefined` when no place of those kinds is in the list.
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * import { PLACES_MOON } from "@johnmorrisdotca/wakusei-planets/places/moon";
194
+ * import { nearestPlace } from "@johnmorrisdotca/wakusei-planets/places";
195
+ *
196
+ * const near = nearestPlace(PLACES_MOON, 20, 30.7, "crewed", "landing", "rover");
197
+ * console.log(near?.place.name.en, near?.degrees.toFixed(2));
198
+ * ```
199
+ */
200
+ export function nearestPlace(places, lat, lon, ...kinds) {
201
+ let best;
202
+ for (const place of places) {
203
+ if (kinds.length > 0 && !kinds.includes(place.kind))
204
+ continue;
205
+ const degrees = angleBetween(lat, lon, place.lat, place.lon);
206
+ if (best === undefined || degrees < best.degrees)
207
+ best = { place, degrees };
208
+ }
209
+ return best;
210
+ }
211
+ /**
212
+ * The distance over the surface between two places on a body, in kilometres: the great circle on a sphere of the body's equatorial radius from `BODIES` (1737.4 km for the Moon, 3396.19 km for Mars; flattening is not allowed for, which is 0.6 per cent on Mars and nothing on the Moon). A body the package has no radius for (Eros, Ryugu, Bennu, Dimorphos and the two comets: their shapes are not spheres) is a `RangeError`.
213
+ *
214
+ * @param body - A body of `PLACE_BODIES` that has a radius in `BODIES`.
215
+ * @param a - A place, or a latitude and east longitude.
216
+ * @param b - The other.
217
+ * @returns Kilometres.
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * import { PLACES_MOON } from "@johnmorrisdotca/wakusei-planets/places/moon";
222
+ * import { findPlace, placeDistanceKm } from "@johnmorrisdotca/wakusei-planets/places";
223
+ *
224
+ * const a = findPlace(PLACES_MOON, "Apollo 11 lunar module")!;
225
+ * const b = findPlace(PLACES_MOON, "Apollo 17 lunar module")!;
226
+ * console.log(Math.round(placeDistanceKm("moon", a, b)), "km between Tranquility Base and Taurus-Littrow");
227
+ * ```
228
+ */
229
+ export function placeDistanceKm(body, a, b) {
230
+ if (!PLACE_BODIES.includes(body))
231
+ throw new RangeError(`places are held for ${PLACE_BODIES.join(", ")}, not "${String(body)}"`);
232
+ const facts = BODIES[body];
233
+ if (facts === undefined)
234
+ throw new RangeError(`the package has no radius for ${body}, an irregular body: no distance over a sphere is given`);
235
+ return (angleBetween(a.lat, a.lon, b.lat, b.lon) * RAD * facts.radiusKm);
236
+ }
237
+ /**
238
+ * The great-circle angle between two points on a sphere, in degrees.
239
+ *
240
+ * @param lat1 - The first point's latitude, degrees.
241
+ * @param lon1 - Its longitude.
242
+ * @param lat2 - The second point's latitude.
243
+ * @param lon2 - Its longitude.
244
+ * @returns The angle at the centre, 0 to 180.
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * import { angleBetween } from "@johnmorrisdotca/wakusei-planets/places";
249
+ *
250
+ * console.log(angleBetween(0, 0, 0, 90), angleBetween(90, 0, -90, 0));
251
+ * ```
252
+ */
253
+ export function angleBetween(lat1, lon1, lat2, lon2) {
254
+ for (const value of [lat1, lon1, lat2, lon2])
255
+ if (typeof value !== "number" || !Number.isFinite(value))
256
+ throw new RangeError(`a latitude or longitude must be a finite number of degrees, got ${String(value)}`);
257
+ const a = unitOf(lat1, lon1);
258
+ const b = unitOf(lat2, lon2);
259
+ return Math.acos(Math.max(-1, Math.min(1, dot(a, b)))) / RAD;
260
+ }
261
+ /** A unit vector in the body's frame for a latitude and east longitude: x along the prime meridian, z the pole, y 90 degrees east. */
262
+ const unitOf = (lat, lon) => [Math.cos(lat * RAD) * Math.cos(lon * RAD), Math.cos(lat * RAD) * Math.sin(lon * RAD), Math.sin(lat * RAD)];
263
+ /**
264
+ * The sub-solar point of a body at a moment: the latitude and east longitude where the Sun is overhead, from the package's own ephemeris and the body's IAU pole and prime meridian.
265
+ *
266
+ * @param id - `moon`, `mars` or any body the package has a pole and a Sun direction for.
267
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
268
+ * @returns The point, in degrees.
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * import { subSolarPoint } from "@johnmorrisdotca/wakusei-planets/places";
273
+ *
274
+ * const sun = subSolarPoint("mars", Date.UTC(2026, 10, 11, 12));
275
+ * console.log(sun.lat.toFixed(1), sun.lon.toFixed(1));
276
+ * ```
277
+ */
278
+ export function subSolarPoint(id, when) {
279
+ const ms = moment(when);
280
+ const pose = apparent(id, ms);
281
+ const east = cross(pose.pole, pose.meridian);
282
+ const s = pose.light;
283
+ const lat = Math.asin(Math.max(-1, Math.min(1, dot(s, pose.pole)))) / RAD;
284
+ const lon = Math.atan2(dot(s, east), dot(s, pose.meridian)) / RAD;
285
+ return { lat, lon };
286
+ }
287
+ /**
288
+ * The terminator at a moment: points round the great circle 90 degrees from the sub-solar point, in degrees, for a line on a map or a globe. The first point is at the pole-most place of the circle
289
+ * and they go east from there.
290
+ *
291
+ * @param id - The body.
292
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
293
+ * @param points - How many points (the first is repeated at the end).
294
+ * @returns The points.
295
+ *
296
+ * @example
297
+ * ```ts
298
+ * import { terminator } from "@johnmorrisdotca/wakusei-planets/places";
299
+ *
300
+ * const line = terminator("moon", Date.UTC(2026, 10, 11), 8);
301
+ * console.log(line.length, line.map((p) => p.lat.toFixed(0)).join(" "));
302
+ * ```
303
+ */
304
+ export function terminator(id, when, points = 72) {
305
+ const sun = subSolarPoint(id, when);
306
+ const s = unitOf(sun.lat, sun.lon);
307
+ // two unit vectors at right angles to the Sun's: one towards the pole, one east
308
+ const u = [-Math.sin(sun.lat * RAD) * Math.cos(sun.lon * RAD), -Math.sin(sun.lat * RAD) * Math.sin(sun.lon * RAD), Math.cos(sun.lat * RAD)];
309
+ const v = cross(s, u);
310
+ const out = [];
311
+ for (let k = 0; k <= points; k += 1) {
312
+ const a = (2 * Math.PI * k) / points;
313
+ const p = [u[0] * Math.cos(a) + v[0] * Math.sin(a), u[1] * Math.cos(a) + v[1] * Math.sin(a), u[2] * Math.cos(a) + v[2] * Math.sin(a)];
314
+ out.push({ lat: Math.asin(Math.max(-1, Math.min(1, p[2]))) / RAD, lon: Math.atan2(p[1], p[0]) / RAD });
315
+ }
316
+ return out;
317
+ }
318
+ /**
319
+ * The local solar time at a place at a moment, in hours from 0 to 24: 12 where the Sun is on the meridian (the sub-solar longitude), an hour later for every 15 degrees east of it, as on the Earth.
320
+ *
321
+ * @param id - The body.
322
+ * @param lon - The place's east longitude, degrees.
323
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
324
+ * @returns Hours, 0 to 24, of the body's own solar day.
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * import { localSolarTime, subSolarPoint } from "@johnmorrisdotca/wakusei-planets/places";
329
+ *
330
+ * const when = Date.UTC(2026, 10, 11, 12);
331
+ * console.log(localSolarTime("moon", subSolarPoint("moon", when).lon, when).toFixed(1), "o'clock under the Sun");
332
+ * ```
333
+ */
334
+ export function localSolarTime(id, lon, when) {
335
+ const sun = subSolarPoint(id, when);
336
+ return ((((lon - sun.lon) / 15 + 12) % 24) + 24) % 24;
337
+ }
338
+ /**
339
+ * Whether the Sun is up at a place at a moment (its centre above the horizon of a smooth sphere).
340
+ *
341
+ * @param id - The body.
342
+ * @param lat - The place's latitude.
343
+ * @param lon - Its east longitude.
344
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
345
+ * @returns True in daylight.
346
+ *
347
+ * @example
348
+ * ```ts
349
+ * import { isDaylight } from "@johnmorrisdotca/wakusei-planets/places";
350
+ *
351
+ * console.log(isDaylight("mars", 18.44, 77.45, Date.UTC(2026, 10, 11, 12)));
352
+ * ```
353
+ */
354
+ export function isDaylight(id, lat, lon, when) {
355
+ const sun = subSolarPoint(id, when);
356
+ return angleBetween(lat, lon, sun.lat, sun.lon) < 90;
357
+ }
@@ -0,0 +1,52 @@
1
+ import { type Plan } from "./layout.ts";
2
+ /**
3
+ * What the pick event carries: the body's id and what kind of body it is.
4
+ *
5
+ * @example
6
+ * ```ts no-run
7
+ * import type { PlanPick } from "@johnmorrisdotca/wakusei-planets/plan/element";
8
+ *
9
+ * const describe = (pick: PlanPick): string => `${pick.id} (${pick.kind})`;
10
+ * console.log(describe({ id: "mars", kind: "planet" }));
11
+ * ```
12
+ */
13
+ export interface PlanPick {
14
+ id: string;
15
+ kind: string;
16
+ }
17
+ /**
18
+ * The `<wakusei-plan>` custom element: a small plan seen from above, in SVG, light enough for an inset of 200 to 280 pixels.
19
+ *
20
+ * Attributes: `system` (`sun`, the default, draws the solar system from above the ecliptic's north pole; a planet or dwarf planet with moons, such as `jupiter`, draws its moons from above its north pole), `mark` (the body the plan is about: its
21
+ * id in any case, such as `mars`, `ceres`, `halley`, `io` or a craft such as `voyager1`; in the solar system a moon marks its planet. A craft's path, or the fitted table of a dwarf planet or minor body, is fetched the first time it is marked), `time` (an ISO date or milliseconds since 1970, and a bare number is always milliseconds, so `2026` is two seconds past the start of 1970 and not a year; the moment it is read when left out or `now`, and then it stands still:
22
+ * set `time` again to move it), `spacing` (`squeezed`, the default, puts each body at the logarithm of its distance so inner and outer both show; `true` is to scale), `names` (`off` hides every name but the marked body's), `lang` (`en` or `ja`;
23
+ * the page's `lang` when left out), `size` (pixels across, 240 by default; also `--wakusei-size`) and `theme` (`light` or `dark`; the page's colour scheme when left out). The colours are `--wakusei-plan-bg`, `-ink`, `-muted`, `-line`, `-sun`, `-dot` and `-mark`.
24
+ *
25
+ * It draws only when one of these changes, and not while it is out of sight, and it has no timer: a page that moves time sets `time` as often as it likes. A press or Enter on a dot sends `wakusei-plan-pick` with `detail: { id, kind }`.
26
+ *
27
+ * @example
28
+ * ```ts no-run
29
+ * import type { WakuseiPlan } from "@johnmorrisdotca/wakusei-planets/plan/element";
30
+ *
31
+ * const plan = document.createElement("wakusei-plan") as WakuseiPlan;
32
+ * plan.setAttribute("mark", "mars");
33
+ * plan.setAttribute("time", "2026-11-11T12:00Z");
34
+ * plan.addEventListener("wakusei-plan-pick", (event) => console.log((event as CustomEvent).detail.id));
35
+ * document.body.append(plan);
36
+ * ```
37
+ */
38
+ export declare class WakuseiPlan extends HTMLElement {
39
+ #private;
40
+ static observedAttributes: string[];
41
+ constructor();
42
+ /** How many times it has drawn: it moves only when an input changes, so a test can check that nothing draws while nothing changes. */
43
+ get draws(): number;
44
+ /** The plan last drawn, or `undefined` before the first draw. */
45
+ get plan(): Plan | undefined;
46
+ /** The moment shown: milliseconds since 1970, or `"now"` (the moment it draws). Setting it draws again. */
47
+ get time(): number | "now";
48
+ set time(value: number | "now");
49
+ connectedCallback(): void;
50
+ disconnectedCallback(): void;
51
+ attributeChangedCallback(name: string, old: string | null, value: string | null): void;
52
+ }
@@ -0,0 +1,258 @@
1
+ // <wakusei-plan>: a small top-down plan, in SVG with no WebGL: the solar system from above with one body marked, or one planet's moons from above its north pole with one moon marked. Positions are the package's own for the `time` it is
2
+ // given. It draws when an input changes (the time, the mark, the system, the spacing, the names, the language, its size) and never on a timer, and nothing while it is out of sight. A press on a dot sends `wakusei-plan-pick`.
3
+ import { DWARF_IDS, MINOR_IDS } from "../facts.js";
4
+ import { SPACECRAFT_IDS } from "../spacecraft-facts.js";
5
+ import { PLAN_AU_KM, planAt, PLAN_SYSTEMS } from "./layout.js";
6
+ import { PLAN_FONT, planSvg } from "./svg.js";
7
+ const TEMPLATE = `<style>
8
+ :host { display: block; width: var(--wakusei-size, 240px); max-width: 100%; aspect-ratio: 1; overflow: hidden; contain: layout style; border-radius: var(--wakusei-radius, 10px); background: var(--wakusei-plan-bg, light-dark(#fbf8f1, #1d201e)); }
9
+ :host([hidden]) { display: none; }
10
+ :host([theme="light"]) { color-scheme: light; }
11
+ :host([theme="dark"]) { color-scheme: dark; }
12
+ #plan { width: 100%; height: 100%; }
13
+ </style><div id="plan"></div>`;
14
+ /** Text measured in the type the plan is drawn in, whatever font the machine falls back to: a canvas takes the same font list, character by character. Without a canvas (no DOM), the plan's own estimate. */
15
+ let probe;
16
+ const measure = (() => {
17
+ if (typeof document === "undefined")
18
+ return undefined;
19
+ return (text, bold) => {
20
+ probe ??= document.createElement("canvas").getContext("2d");
21
+ if (probe === null)
22
+ return [...text].length * 6.1;
23
+ probe.font = bold ? `700 ${PLAN_FONT}` : PLAN_FONT;
24
+ return probe.measureText(text).width;
25
+ };
26
+ })();
27
+ const READ_TIME = (value) => {
28
+ if (value === null || value.trim() === "" || value.trim() === "now")
29
+ return "now";
30
+ const text = value.trim();
31
+ const ms = /^-?\d+(\.\d+)?$/.test(text) ? Number(text) : Date.parse(text);
32
+ return Number.isFinite(ms) ? ms : "now";
33
+ };
34
+ const off = (value) => value !== null && ["off", "0", "false", "no"].includes(value.trim().toLowerCase());
35
+ /**
36
+ * The `<wakusei-plan>` custom element: a small plan seen from above, in SVG, light enough for an inset of 200 to 280 pixels.
37
+ *
38
+ * Attributes: `system` (`sun`, the default, draws the solar system from above the ecliptic's north pole; a planet or dwarf planet with moons, such as `jupiter`, draws its moons from above its north pole), `mark` (the body the plan is about: its
39
+ * id in any case, such as `mars`, `ceres`, `halley`, `io` or a craft such as `voyager1`; in the solar system a moon marks its planet. A craft's path, or the fitted table of a dwarf planet or minor body, is fetched the first time it is marked), `time` (an ISO date or milliseconds since 1970, and a bare number is always milliseconds, so `2026` is two seconds past the start of 1970 and not a year; the moment it is read when left out or `now`, and then it stands still:
40
+ * set `time` again to move it), `spacing` (`squeezed`, the default, puts each body at the logarithm of its distance so inner and outer both show; `true` is to scale), `names` (`off` hides every name but the marked body's), `lang` (`en` or `ja`;
41
+ * the page's `lang` when left out), `size` (pixels across, 240 by default; also `--wakusei-size`) and `theme` (`light` or `dark`; the page's colour scheme when left out). The colours are `--wakusei-plan-bg`, `-ink`, `-muted`, `-line`, `-sun`, `-dot` and `-mark`.
42
+ *
43
+ * It draws only when one of these changes, and not while it is out of sight, and it has no timer: a page that moves time sets `time` as often as it likes. A press or Enter on a dot sends `wakusei-plan-pick` with `detail: { id, kind }`.
44
+ *
45
+ * @example
46
+ * ```ts no-run
47
+ * import type { WakuseiPlan } from "@johnmorrisdotca/wakusei-planets/plan/element";
48
+ *
49
+ * const plan = document.createElement("wakusei-plan") as WakuseiPlan;
50
+ * plan.setAttribute("mark", "mars");
51
+ * plan.setAttribute("time", "2026-11-11T12:00Z");
52
+ * plan.addEventListener("wakusei-plan-pick", (event) => console.log((event as CustomEvent).detail.id));
53
+ * document.body.append(plan);
54
+ * ```
55
+ */
56
+ export class WakuseiPlan extends HTMLElement {
57
+ static observedAttributes = ["system", "mark", "time", "spacing", "names", "lang", "size", "theme"];
58
+ #root;
59
+ #box;
60
+ #time = "now";
61
+ #size = 0;
62
+ #draws = 0;
63
+ #plan;
64
+ #queued = false;
65
+ #dirty = true;
66
+ #visible = typeof IntersectionObserver !== "function";
67
+ #resize;
68
+ #io;
69
+ #watch;
70
+ #craft;
71
+ /** The craft whose paths are loaded, and those being fetched: each is fetched once, when it is first marked. */
72
+ #craftLoaded = new Set();
73
+ #craftLoading = new Set();
74
+ /** The fitted tables fetched for a marked dwarf planet or minor body, by entry point. */
75
+ #tablesAsked = new Set();
76
+ constructor() {
77
+ super();
78
+ this.#root = this.attachShadow({ mode: "open" });
79
+ this.#root.innerHTML = TEMPLATE;
80
+ this.#box = this.#root.getElementById("plan");
81
+ this.#box.addEventListener("click", (event) => this.#pick(event.target));
82
+ this.#box.addEventListener("keydown", (event) => {
83
+ if (event.key === "Enter" || event.key === " ") {
84
+ event.preventDefault();
85
+ this.#pick(event.target);
86
+ }
87
+ });
88
+ }
89
+ /** How many times it has drawn: it moves only when an input changes, so a test can check that nothing draws while nothing changes. */
90
+ get draws() {
91
+ return this.#draws;
92
+ }
93
+ /** The plan last drawn, or `undefined` before the first draw. */
94
+ get plan() {
95
+ return this.#plan;
96
+ }
97
+ /** The moment shown: milliseconds since 1970, or `"now"` (the moment it draws). Setting it draws again. */
98
+ get time() {
99
+ return this.#time;
100
+ }
101
+ set time(value) {
102
+ this.#time = value === "now" || !Number.isFinite(value) ? "now" : value;
103
+ this.#queue();
104
+ }
105
+ connectedCallback() {
106
+ if (this.hasAttribute("time"))
107
+ this.#time = READ_TIME(this.getAttribute("time"));
108
+ if (this.hasAttribute("size"))
109
+ this.#applySize();
110
+ if (typeof ResizeObserver === "function") {
111
+ this.#resize = new ResizeObserver((entries) => {
112
+ const width = Math.round(entries[0]?.contentRect.width ?? 0);
113
+ if (width > 0 && width !== this.#size) {
114
+ this.#size = width;
115
+ this.#queue();
116
+ }
117
+ });
118
+ this.#resize.observe(this);
119
+ }
120
+ else
121
+ this.#size = Math.round(this.getBoundingClientRect().width) || 240;
122
+ if (typeof IntersectionObserver === "function") {
123
+ this.#io = new IntersectionObserver((entries) => {
124
+ const seen = entries[entries.length - 1]?.isIntersecting ?? this.#visible;
125
+ if (seen !== this.#visible) {
126
+ this.#visible = seen;
127
+ if (seen)
128
+ this.#queue();
129
+ }
130
+ });
131
+ this.#io.observe(this);
132
+ }
133
+ // the page's language, when this element has none of its own
134
+ this.#watch = new MutationObserver(() => {
135
+ if (!this.hasAttribute("lang"))
136
+ this.#queue();
137
+ });
138
+ this.#watch.observe(document.documentElement, { attributes: true, attributeFilter: ["lang"] });
139
+ // and the nearest ancestor that sets one, which is the language it reads when it has none
140
+ const near = this.parentElement?.closest("[lang]");
141
+ if (near !== null && near !== undefined && near !== document.documentElement)
142
+ this.#watch.observe(near, { attributes: true, attributeFilter: ["lang"] });
143
+ this.#queue();
144
+ }
145
+ disconnectedCallback() {
146
+ this.#resize?.disconnect();
147
+ this.#io?.disconnect();
148
+ this.#watch?.disconnect();
149
+ this.#resize = this.#io = this.#watch = undefined;
150
+ this.#visible = typeof IntersectionObserver !== "function";
151
+ }
152
+ attributeChangedCallback(name, old, value) {
153
+ // writing the value it already has is not a change
154
+ if (old === value)
155
+ return;
156
+ if (name === "time")
157
+ this.#time = READ_TIME(value);
158
+ if (name === "size")
159
+ this.#applySize();
160
+ this.#queue();
161
+ }
162
+ #applySize() {
163
+ const n = Number(this.getAttribute("size"));
164
+ if (Number.isFinite(n) && n >= 120)
165
+ this.style.setProperty("--wakusei-size", `${Math.round(n)}px`);
166
+ else
167
+ this.style.removeProperty("--wakusei-size");
168
+ }
169
+ #lang() {
170
+ const own = this.getAttribute("lang") ?? this.closest("[lang]")?.getAttribute("lang") ?? "en";
171
+ return own.toLowerCase().startsWith("ja") ? "ja" : "en";
172
+ }
173
+ /** Ask for a draw: any number of changes in one go make one. */
174
+ #queue() {
175
+ this.#dirty = true;
176
+ if (this.#queued)
177
+ return;
178
+ this.#queued = true;
179
+ queueMicrotask(() => {
180
+ this.#queued = false;
181
+ this.#draw();
182
+ });
183
+ }
184
+ /** The mark, in lower case. */
185
+ #mark() {
186
+ return this.getAttribute("mark")?.trim().toLowerCase() || undefined;
187
+ }
188
+ /** The craft marked, if the mark is one. */
189
+ #craftMarked() {
190
+ const mark = this.#mark();
191
+ return mark !== undefined && SPACECRAFT_IDS.includes(mark) ? mark : undefined;
192
+ }
193
+ /** The place of the craft marked, once its path has been fetched (each craft's the first time it is marked); until then, nothing. */
194
+ #extras(id, time) {
195
+ if (id === undefined)
196
+ return [];
197
+ if (!this.#craftLoaded.has(id) || this.#craft === undefined) {
198
+ if (!this.#craftLoading.has(id)) {
199
+ this.#craftLoading.add(id);
200
+ void import("../spacecraft.js").then(async (module) => {
201
+ await module.loadSpacecraft(id);
202
+ this.#craft = module;
203
+ this.#craftLoaded.add(id);
204
+ this.#queue();
205
+ }, () => undefined);
206
+ }
207
+ return [];
208
+ }
209
+ try {
210
+ const km = this.#craft.spacecraftPosition(id, time);
211
+ return [{ id, au: [km[0] / PLAN_AU_KM, km[1] / PLAN_AU_KM, km[2] / PLAN_AU_KM] }];
212
+ }
213
+ catch {
214
+ return [];
215
+ }
216
+ }
217
+ /** A marked dwarf planet or minor body is drawn from its fitted table once that has been fetched; until then from the elements of one epoch. */
218
+ #tables(mark) {
219
+ if (mark === undefined)
220
+ return;
221
+ const entry = mark === "ceres" ? "ceres" : DWARF_IDS.includes(mark) ? "dwarfs" : MINOR_IDS.includes(mark) ? "minor" : undefined;
222
+ if (entry === undefined || this.#tablesAsked.has(entry))
223
+ return;
224
+ this.#tablesAsked.add(entry);
225
+ const load = entry === "ceres" ? import("../tables/ceres.js") : entry === "dwarfs" ? import("../tables/dwarfs.js") : import("../tables/minor.js");
226
+ void load.then(() => this.#queue(), () => undefined);
227
+ }
228
+ #draw() {
229
+ if (!this.isConnected || !this.#dirty)
230
+ return;
231
+ if (!this.#visible || this.#size <= 0)
232
+ return;
233
+ this.#dirty = false;
234
+ const time = this.#time === "now" ? Date.now() : this.#time;
235
+ const wanted = this.getAttribute("system") ?? "sun";
236
+ const system = PLAN_SYSTEMS.includes(wanted) ? wanted : "sun";
237
+ const spacing = this.getAttribute("spacing") === "true" ? "true" : "squeezed";
238
+ const craft = this.#craftMarked();
239
+ this.#tables(this.#mark());
240
+ const plan = planAt(time, { system, spacing, mark: this.#mark(), extras: system === "sun" ? this.#extras(craft, time) : [] });
241
+ const held = this.#root.activeElement?.getAttribute("data-id");
242
+ this.#box.innerHTML = planSvg(plan, { size: this.#size, lang: this.#lang(), names: !off(this.getAttribute("names")), ...(measure === undefined ? {} : { measure }) });
243
+ if (held !== null && held !== undefined)
244
+ this.#box.querySelector(`g[data-id="${held}"]`)?.focus();
245
+ this.#plan = plan;
246
+ this.#draws += 1;
247
+ this.setAttribute("data-state", "ready");
248
+ }
249
+ #pick(target) {
250
+ const body = target?.closest?.("g[data-id]");
251
+ const id = body?.getAttribute("data-id");
252
+ if (id === null || id === undefined)
253
+ return;
254
+ this.dispatchEvent(new CustomEvent("wakusei-plan-pick", { detail: { id, kind: body?.getAttribute("data-kind") ?? "" }, bubbles: true, composed: true }));
255
+ }
256
+ }
257
+ if (typeof customElements !== "undefined" && !customElements.get("wakusei-plan"))
258
+ customElements.define("wakusei-plan", WakuseiPlan);