@johnmorrisdotca/wakusei-planets 0.67.0 → 0.69.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 (256) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/NOTICE.md +10 -0
  3. package/README.md +3 -3
  4. package/dist/data/moon-catalogue.d.ts +1 -1
  5. package/dist/data/moon-catalogue.js +1 -1
  6. package/dist/data/places-added.d.ts +2 -0
  7. package/dist/data/places-added.js +2 -0
  8. package/dist/data/places-aliases.d.ts +1 -0
  9. package/dist/data/places-aliases.js +14 -0
  10. package/dist/data/places-planned.js +1 -1
  11. package/dist/data/places-search-67p.d.ts +1 -0
  12. package/dist/data/places-search-67p.js +3 -0
  13. package/dist/data/places-search-amalthea.d.ts +1 -0
  14. package/dist/data/places-search-amalthea.js +3 -0
  15. package/dist/data/places-search-ariel.d.ts +1 -0
  16. package/dist/data/places-search-ariel.js +3 -0
  17. package/dist/data/places-search-bennu.d.ts +1 -0
  18. package/dist/data/places-search-bennu.js +3 -0
  19. package/dist/data/places-search-bodies.d.ts +25 -0
  20. package/dist/data/places-search-bodies.js +125 -0
  21. package/dist/data/places-search-callisto.d.ts +1 -0
  22. package/dist/data/places-search-callisto.js +3 -0
  23. package/dist/data/places-search-ceres.d.ts +1 -0
  24. package/dist/data/places-search-ceres.js +3 -0
  25. package/dist/data/places-search-charon.d.ts +1 -0
  26. package/dist/data/places-search-charon.js +3 -0
  27. package/dist/data/places-search-dactyl.d.ts +1 -0
  28. package/dist/data/places-search-dactyl.js +3 -0
  29. package/dist/data/places-search-deimos.d.ts +1 -0
  30. package/dist/data/places-search-deimos.js +3 -0
  31. package/dist/data/places-search-didymos.d.ts +1 -0
  32. package/dist/data/places-search-didymos.js +3 -0
  33. package/dist/data/places-search-dimorphos.d.ts +1 -0
  34. package/dist/data/places-search-dimorphos.js +3 -0
  35. package/dist/data/places-search-dinkinesh.d.ts +1 -0
  36. package/dist/data/places-search-dinkinesh.js +3 -0
  37. package/dist/data/places-search-dione.d.ts +1 -0
  38. package/dist/data/places-search-dione.js +3 -0
  39. package/dist/data/places-search-donaldjohanson.d.ts +1 -0
  40. package/dist/data/places-search-donaldjohanson.js +3 -0
  41. package/dist/data/places-search-enceladus.d.ts +1 -0
  42. package/dist/data/places-search-enceladus.js +3 -0
  43. package/dist/data/places-search-epimetheus.d.ts +1 -0
  44. package/dist/data/places-search-epimetheus.js +3 -0
  45. package/dist/data/places-search-eros.d.ts +1 -0
  46. package/dist/data/places-search-eros.js +3 -0
  47. package/dist/data/places-search-europa.d.ts +1 -0
  48. package/dist/data/places-search-europa.js +3 -0
  49. package/dist/data/places-search-ganymede.d.ts +1 -0
  50. package/dist/data/places-search-ganymede.js +3 -0
  51. package/dist/data/places-search-gaspra.d.ts +1 -0
  52. package/dist/data/places-search-gaspra.js +3 -0
  53. package/dist/data/places-search-hyperion.d.ts +1 -0
  54. package/dist/data/places-search-hyperion.js +3 -0
  55. package/dist/data/places-search-iapetus.d.ts +1 -0
  56. package/dist/data/places-search-iapetus.js +3 -0
  57. package/dist/data/places-search-ida.d.ts +1 -0
  58. package/dist/data/places-search-ida.js +3 -0
  59. package/dist/data/places-search-io.d.ts +1 -0
  60. package/dist/data/places-search-io.js +3 -0
  61. package/dist/data/places-search-itokawa.d.ts +1 -0
  62. package/dist/data/places-search-itokawa.js +3 -0
  63. package/dist/data/places-search-janus.d.ts +1 -0
  64. package/dist/data/places-search-janus.js +3 -0
  65. package/dist/data/places-search-jupiter.d.ts +1 -0
  66. package/dist/data/places-search-jupiter.js +3 -0
  67. package/dist/data/places-search-lutetia.d.ts +1 -0
  68. package/dist/data/places-search-lutetia.js +3 -0
  69. package/dist/data/places-search-mars.d.ts +1 -0
  70. package/dist/data/places-search-mars.js +3 -0
  71. package/dist/data/places-search-mathilde.d.ts +1 -0
  72. package/dist/data/places-search-mathilde.js +3 -0
  73. package/dist/data/places-search-mercury.d.ts +1 -0
  74. package/dist/data/places-search-mercury.js +3 -0
  75. package/dist/data/places-search-mimas.d.ts +1 -0
  76. package/dist/data/places-search-mimas.js +3 -0
  77. package/dist/data/places-search-miranda.d.ts +1 -0
  78. package/dist/data/places-search-miranda.js +3 -0
  79. package/dist/data/places-search-moon-satellites.d.ts +1 -0
  80. package/dist/data/places-search-moon-satellites.js +3 -0
  81. package/dist/data/places-search-moon.d.ts +1 -0
  82. package/dist/data/places-search-moon.js +3 -0
  83. package/dist/data/places-search-oberon.d.ts +1 -0
  84. package/dist/data/places-search-oberon.js +3 -0
  85. package/dist/data/places-search-phobos.d.ts +1 -0
  86. package/dist/data/places-search-phobos.js +3 -0
  87. package/dist/data/places-search-phoebe.d.ts +1 -0
  88. package/dist/data/places-search-phoebe.js +3 -0
  89. package/dist/data/places-search-pluto.d.ts +1 -0
  90. package/dist/data/places-search-pluto.js +3 -0
  91. package/dist/data/places-search-proteus.d.ts +1 -0
  92. package/dist/data/places-search-proteus.js +3 -0
  93. package/dist/data/places-search-rhea.d.ts +1 -0
  94. package/dist/data/places-search-rhea.js +3 -0
  95. package/dist/data/places-search-ryugu.d.ts +1 -0
  96. package/dist/data/places-search-ryugu.js +3 -0
  97. package/dist/data/places-search-saturn.d.ts +1 -0
  98. package/dist/data/places-search-saturn.js +3 -0
  99. package/dist/data/places-search-steins.d.ts +1 -0
  100. package/dist/data/places-search-steins.js +3 -0
  101. package/dist/data/places-search-tempel-1.d.ts +1 -0
  102. package/dist/data/places-search-tempel-1.js +3 -0
  103. package/dist/data/places-search-tethys.d.ts +1 -0
  104. package/dist/data/places-search-tethys.js +3 -0
  105. package/dist/data/places-search-thebe.d.ts +1 -0
  106. package/dist/data/places-search-thebe.js +3 -0
  107. package/dist/data/places-search-titan.d.ts +1 -0
  108. package/dist/data/places-search-titan.js +3 -0
  109. package/dist/data/places-search-titania.d.ts +1 -0
  110. package/dist/data/places-search-titania.js +3 -0
  111. package/dist/data/places-search-triton.d.ts +1 -0
  112. package/dist/data/places-search-triton.js +3 -0
  113. package/dist/data/places-search-types.d.ts +1 -0
  114. package/dist/data/places-search-types.js +59 -0
  115. package/dist/data/places-search-umbriel.d.ts +1 -0
  116. package/dist/data/places-search-umbriel.js +3 -0
  117. package/dist/data/places-search-venus.d.ts +1 -0
  118. package/dist/data/places-search-venus.js +3 -0
  119. package/dist/data/places-search-vesta.d.ts +1 -0
  120. package/dist/data/places-search-vesta.js +3 -0
  121. package/dist/earth-places.d.ts +17 -1
  122. package/dist/earth-places.js +18 -0
  123. package/dist/fact-sheets.d.ts +1 -1
  124. package/dist/fact-sheets.js +1 -1
  125. package/dist/flat/words.js +2 -0
  126. package/dist/moon-catalogue.d.ts +190 -0
  127. package/dist/moon-catalogue.js +189 -3
  128. package/dist/place-marks.js +1 -1
  129. package/dist/place-search.d.ts +179 -0
  130. package/dist/place-search.js +223 -0
  131. package/dist/places/moon.js +4 -1
  132. package/dist/places/search/67p.d.ts +12 -0
  133. package/dist/places/search/67p.js +14 -0
  134. package/dist/places/search/amalthea.d.ts +12 -0
  135. package/dist/places/search/amalthea.js +14 -0
  136. package/dist/places/search/ariel.d.ts +12 -0
  137. package/dist/places/search/ariel.js +14 -0
  138. package/dist/places/search/bennu.d.ts +12 -0
  139. package/dist/places/search/bennu.js +14 -0
  140. package/dist/places/search/callisto.d.ts +12 -0
  141. package/dist/places/search/callisto.js +14 -0
  142. package/dist/places/search/ceres.d.ts +12 -0
  143. package/dist/places/search/ceres.js +14 -0
  144. package/dist/places/search/charon.d.ts +12 -0
  145. package/dist/places/search/charon.js +14 -0
  146. package/dist/places/search/dactyl.d.ts +12 -0
  147. package/dist/places/search/dactyl.js +14 -0
  148. package/dist/places/search/deimos.d.ts +12 -0
  149. package/dist/places/search/deimos.js +14 -0
  150. package/dist/places/search/didymos.d.ts +12 -0
  151. package/dist/places/search/didymos.js +14 -0
  152. package/dist/places/search/dimorphos.d.ts +12 -0
  153. package/dist/places/search/dimorphos.js +14 -0
  154. package/dist/places/search/dinkinesh.d.ts +12 -0
  155. package/dist/places/search/dinkinesh.js +14 -0
  156. package/dist/places/search/dione.d.ts +12 -0
  157. package/dist/places/search/dione.js +14 -0
  158. package/dist/places/search/donaldjohanson.d.ts +12 -0
  159. package/dist/places/search/donaldjohanson.js +14 -0
  160. package/dist/places/search/enceladus.d.ts +12 -0
  161. package/dist/places/search/enceladus.js +14 -0
  162. package/dist/places/search/epimetheus.d.ts +12 -0
  163. package/dist/places/search/epimetheus.js +14 -0
  164. package/dist/places/search/eros.d.ts +12 -0
  165. package/dist/places/search/eros.js +14 -0
  166. package/dist/places/search/europa.d.ts +12 -0
  167. package/dist/places/search/europa.js +14 -0
  168. package/dist/places/search/ganymede.d.ts +12 -0
  169. package/dist/places/search/ganymede.js +14 -0
  170. package/dist/places/search/gaspra.d.ts +12 -0
  171. package/dist/places/search/gaspra.js +14 -0
  172. package/dist/places/search/hyperion.d.ts +12 -0
  173. package/dist/places/search/hyperion.js +14 -0
  174. package/dist/places/search/iapetus.d.ts +12 -0
  175. package/dist/places/search/iapetus.js +14 -0
  176. package/dist/places/search/ida.d.ts +12 -0
  177. package/dist/places/search/ida.js +14 -0
  178. package/dist/places/search/io.d.ts +12 -0
  179. package/dist/places/search/io.js +14 -0
  180. package/dist/places/search/itokawa.d.ts +12 -0
  181. package/dist/places/search/itokawa.js +14 -0
  182. package/dist/places/search/janus.d.ts +12 -0
  183. package/dist/places/search/janus.js +14 -0
  184. package/dist/places/search/jupiter.d.ts +12 -0
  185. package/dist/places/search/jupiter.js +14 -0
  186. package/dist/places/search/lutetia.d.ts +12 -0
  187. package/dist/places/search/lutetia.js +14 -0
  188. package/dist/places/search/mars.d.ts +12 -0
  189. package/dist/places/search/mars.js +14 -0
  190. package/dist/places/search/mathilde.d.ts +12 -0
  191. package/dist/places/search/mathilde.js +14 -0
  192. package/dist/places/search/mercury.d.ts +12 -0
  193. package/dist/places/search/mercury.js +14 -0
  194. package/dist/places/search/mimas.d.ts +12 -0
  195. package/dist/places/search/mimas.js +14 -0
  196. package/dist/places/search/miranda.d.ts +12 -0
  197. package/dist/places/search/miranda.js +14 -0
  198. package/dist/places/search/moon-satellites.d.ts +12 -0
  199. package/dist/places/search/moon-satellites.js +14 -0
  200. package/dist/places/search/moon.d.ts +12 -0
  201. package/dist/places/search/moon.js +14 -0
  202. package/dist/places/search/oberon.d.ts +12 -0
  203. package/dist/places/search/oberon.js +14 -0
  204. package/dist/places/search/phobos.d.ts +12 -0
  205. package/dist/places/search/phobos.js +14 -0
  206. package/dist/places/search/phoebe.d.ts +12 -0
  207. package/dist/places/search/phoebe.js +14 -0
  208. package/dist/places/search/pluto.d.ts +12 -0
  209. package/dist/places/search/pluto.js +14 -0
  210. package/dist/places/search/proteus.d.ts +12 -0
  211. package/dist/places/search/proteus.js +14 -0
  212. package/dist/places/search/rhea.d.ts +12 -0
  213. package/dist/places/search/rhea.js +14 -0
  214. package/dist/places/search/ryugu.d.ts +12 -0
  215. package/dist/places/search/ryugu.js +14 -0
  216. package/dist/places/search/saturn.d.ts +12 -0
  217. package/dist/places/search/saturn.js +14 -0
  218. package/dist/places/search/steins.d.ts +12 -0
  219. package/dist/places/search/steins.js +14 -0
  220. package/dist/places/search/tempel-1.d.ts +12 -0
  221. package/dist/places/search/tempel-1.js +14 -0
  222. package/dist/places/search/tethys.d.ts +12 -0
  223. package/dist/places/search/tethys.js +14 -0
  224. package/dist/places/search/thebe.d.ts +12 -0
  225. package/dist/places/search/thebe.js +14 -0
  226. package/dist/places/search/titan.d.ts +12 -0
  227. package/dist/places/search/titan.js +14 -0
  228. package/dist/places/search/titania.d.ts +12 -0
  229. package/dist/places/search/titania.js +14 -0
  230. package/dist/places/search/triton.d.ts +12 -0
  231. package/dist/places/search/triton.js +14 -0
  232. package/dist/places/search/umbriel.d.ts +12 -0
  233. package/dist/places/search/umbriel.js +14 -0
  234. package/dist/places/search/venus.d.ts +12 -0
  235. package/dist/places/search/venus.js +14 -0
  236. package/dist/places/search/vesta.d.ts +12 -0
  237. package/dist/places/search/vesta.js +14 -0
  238. package/dist/places/search.d.ts +42 -0
  239. package/dist/places/search.js +77 -0
  240. package/dist/places.d.ts +4 -3
  241. package/dist/scene/body-places.d.ts +98 -0
  242. package/dist/scene/body-places.js +113 -0
  243. package/dist/scene/earth-places.d.ts +6 -1
  244. package/dist/scene/earth-places.js +55 -2
  245. package/dist/scene/place-layer.js +1 -0
  246. package/dist/space/all-moons.d.ts +81 -10
  247. package/dist/space/all-moons.js +132 -27
  248. package/dist/space/element.d.ts +56 -5
  249. package/dist/space/element.js +240 -24
  250. package/dist/space/moon-settings.d.ts +25 -0
  251. package/dist/space/moon-settings.js +43 -0
  252. package/dist/space/orbit-rules.d.ts +25 -0
  253. package/dist/space/orbit-rules.js +36 -0
  254. package/dist/space/scene.d.ts +14 -3
  255. package/dist/space/scene.js +48 -17
  256. package/package.json +271 -1
@@ -263,11 +263,10 @@ function ratesOf(orbit) {
263
263
  const dn = orbit.nodeYears ? (-Math.sign(ci) * 360) / (orbit.nodeYears * YEAR_DAYS) : 0;
264
264
  return [360 / orbit.periodDays - dw - dn, dw, dn];
265
265
  }
266
- /** A place on an ellipse of semi-major axis `a` (km) and eccentricity `e`, inclination `i`, node and argument of periapsis `w` (degrees), at mean anomaly `meanAnomaly` (radians), in the frame of the pole (the J2000 ecliptic for `null`). */
267
- function placed(a, e, i, nodeDeg, wDeg, meanAnomaly, pole) {
266
+ /** A place on an ellipse of semi-major axis `a` (km) and eccentricity `e`, inclination `i`, node and argument of periapsis `w` (degrees), at eccentric anomaly `E` (radians), in the frame of the pole (the J2000 ecliptic for `null`). */
267
+ function placedAt(a, e, i, nodeDeg, wDeg, E, pole) {
268
268
  const w = wDeg * RAD;
269
269
  const node = nodeDeg * RAD;
270
- const E = kepler(meanAnomaly, e);
271
270
  const x = a * (Math.cos(E) - e);
272
271
  const y = a * Math.sqrt(1 - e * e) * Math.sin(E);
273
272
  const [cw, sw, cn, sn, ci, si] = [Math.cos(w), Math.sin(w), Math.cos(node), Math.sin(node), Math.cos(i * RAD), Math.sin(i * RAD)];
@@ -277,6 +276,10 @@ function placed(a, e, i, nodeDeg, wDeg, meanAnomaly, pole) {
277
276
  const [bx, by, bz] = basisOf(pole);
278
277
  return [px * bx[0] + py * by[0] + pz * bz[0], px * bx[1] + py * by[1] + pz * bz[1], px * bx[2] + py * by[2] + pz * bz[2]];
279
278
  }
279
+ /** The same at mean anomaly `meanAnomaly` (radians), solved by Kepler's equation. */
280
+ function placed(a, e, i, nodeDeg, wDeg, meanAnomaly, pole) {
281
+ return placedAt(a, e, i, nodeDeg, wDeg, kepler(meanAnomaly, e), pole);
282
+ }
280
283
  /**
281
284
  * Where a moon is at a moment, from its planet's centre, in kilometres, in the J2000 ecliptic frame (the axes of `moonVector`): its mean orbit, turned for the precession of its periapsis and node, solved by Kepler's
282
285
  * equation. How close that is to the moon's real place near 2026 is the moon's `accuracy` and `grade`; decades away it drifts much further (`accuracy.farDegrees`). A moon the package draws in full is placed far better
@@ -312,3 +315,186 @@ export function catalogueMoonPosition(moon, when) {
312
315
  const dt = jd - orbit.epochJd;
313
316
  return placed(orbit.a, orbit.e, orbit.i, orbit.node + dn * dt, orbit.w + dw * dt, (orbit.m + n * dt) * RAD, orbit.frame === "ecliptic" ? null : (orbit.pole ?? null));
314
317
  }
318
+ /**
319
+ * The orbit a moon follows at a moment, as a closed line from its planet's centre, in kilometres, in the same frame as `catalogueMoonPosition`: the one that function places the moon on (its osculating orbit within
320
+ * `MOON_OSCULATING_DAYS` of `MOON_OSCULATING_EPOCH_JD`, else its mean orbit turned for the precession of its periapsis and node), sampled evenly in eccentric anomaly so a long ellipse keeps its sharp end. The line
321
+ * closes: its last point is its first. It is the shape at that moment; an irregular moon's orbit turns over years, so draw it again after a month or two of game time, not every frame.
322
+ *
323
+ * @param moon - A moon of the catalogue, or its id, name, designation or code.
324
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
325
+ * @param points - How many points round the orbit, 8 to 720 (default 72). The line has one more, the first again.
326
+ * @returns The points, or `undefined` for a moon with no orbit.
327
+ *
328
+ * @example
329
+ * ```ts
330
+ * import { catalogueMoonOrbit } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
331
+ *
332
+ * const ring = catalogueMoonOrbit("Carme", new Date("2026-11-18T00:00:00Z"), 48)!;
333
+ * console.log(ring.length, "points, the first", ring[0]!.map((v) => Math.round(v / 1e6)).join(", "), "million km from Jupiter");
334
+ * ```
335
+ */
336
+ export function catalogueMoonOrbit(moon, when, points = 72) {
337
+ const m = typeof moon === "object" ? moon : findCatalogueMoon(moon);
338
+ if (m === undefined)
339
+ throw new RangeError(`unknown moon ${JSON.stringify(moon)}; look one up with findCatalogueMoon`);
340
+ const orbit = m.orbit;
341
+ if (orbit === null)
342
+ return undefined;
343
+ const count = Math.min(720, Math.max(8, Math.round(points)));
344
+ const jd = toTerrestrialTime(moment(when)) / DAY_MS + UNIX_JD;
345
+ const osc = m.osculating;
346
+ let shape;
347
+ if (osc !== null && Math.abs(jd - osc.epochJd) <= MOON_OSCULATING_DAYS)
348
+ shape = [osc.a, osc.e, osc.i, osc.node, osc.w, null];
349
+ else {
350
+ const [, dw, dn] = ratesOf(orbit);
351
+ const dt = jd - orbit.epochJd;
352
+ shape = [orbit.a, orbit.e, orbit.i, orbit.node + dn * dt, orbit.w + dw * dt, orbit.frame === "ecliptic" ? null : (orbit.pole ?? null)];
353
+ }
354
+ const out = [];
355
+ for (let k = 0; k < count; k += 1)
356
+ out.push(placedAt(shape[0], shape[1], shape[2], shape[3], shape[4], (k / count) * 2 * Math.PI, shape[5]));
357
+ out.push(out[0]);
358
+ return out;
359
+ }
360
+ /** The families of each host, in the order a list shows them, with the group each takes in, its names and the colour its orbits are drawn in by group. */
361
+ const FAMILY_TABLE = {
362
+ galilean: { names: { en: "Galilean moons", ja: "ガリレオ衛星" }, color: "#f2c14e" },
363
+ inner: { names: { en: "Inner and major moons", ja: "内側の衛星と大きな衛星" }, color: "#9bd1ff" },
364
+ himalia: { names: { en: "Himalia group", ja: "ヒマリア群" }, color: "#5fd38d" },
365
+ ananke: { names: { en: "Ananke group", ja: "アナンケ群" }, color: "#ff9f6b" },
366
+ carme: { names: { en: "Carme group", ja: "カルメ群" }, color: "#e0568a" },
367
+ pasiphae: { names: { en: "Pasiphae group", ja: "パシファエ群" }, color: "#b07cff" },
368
+ other: { names: { en: "Other irregular moons", ja: "その他の不規則衛星" }, color: "#c9cdd4" },
369
+ inuit: { names: { en: "Inuit group", ja: "イヌイット群" }, color: "#5fd38d" },
370
+ gallic: { names: { en: "Gallic group", ja: "ガリア群" }, color: "#5aa9ff" },
371
+ norse: { names: { en: "Norse group", ja: "北欧群" }, color: "#e0568a" },
372
+ irregular: { names: { en: "Irregular moons", ja: "不規則衛星" }, color: "#ff9f6b" },
373
+ moons: { names: { en: "Moons", ja: "衛星" }, color: "#c9cdd4" },
374
+ };
375
+ const FAMILIES_OF = {
376
+ jupiter: ["galilean", "inner", "himalia", "ananke", "carme", "pasiphae", "other"],
377
+ saturn: ["inner", "inuit", "gallic", "norse"],
378
+ uranus: ["inner", "irregular"],
379
+ neptune: ["inner", "irregular"],
380
+ };
381
+ /** The family a moon is in. */
382
+ function familyOf(moon) {
383
+ const group = moon.group;
384
+ if (moon.host === "jupiter") {
385
+ if (group === "major")
386
+ return "galilean";
387
+ if (group === "inner" || group === "regular")
388
+ return "inner";
389
+ if (group === "himalia" || group === "ananke" || group === "carme" || group === "pasiphae")
390
+ return group;
391
+ return "other";
392
+ }
393
+ if (moon.host === "saturn")
394
+ return group === "inuit" || group === "gallic" || group === "norse" ? group : "inner";
395
+ if (moon.host === "uranus" || moon.host === "neptune")
396
+ return group === "prograde" || group === "retrograde" ? "irregular" : "inner";
397
+ return "moons";
398
+ }
399
+ /**
400
+ * A planet's moons sorted into families for a list or a tab: Jupiter (Galilean, inner, Himalia, Ananke, Carme, Pasiphae, other irregular moons), Saturn (inner and major, Inuit, Gallic, Norse), Uranus and Neptune (inner
401
+ * and major, irregular), and one family `moons` for a host with too few to divide. Every moon of the host is in exactly one family. A size is the catalogue's `radiusKm`; `estimate` is true where it is derived
402
+ * (see `radiusFrom`), and a family says how many of its sizes are estimates, so a page can mark them.
403
+ *
404
+ * @param host - The planet or dwarf planet: "saturn".
405
+ * @returns The families, in the order a list shows them; an empty list for a host with no moon in the catalogue.
406
+ *
407
+ * @example
408
+ * ```ts
409
+ * import { moonFamilies } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
410
+ *
411
+ * for (const family of moonFamilies("jupiter")) console.log(family.names.en, family.count, family.sized, "with a size,", family.estimated, "of them estimated");
412
+ * ```
413
+ */
414
+ export function moonFamilies(host) {
415
+ const own = catalogueMoonsOf(host);
416
+ if (own.length === 0)
417
+ return [];
418
+ return (FAMILIES_OF[host] ?? ["moons"]).map((id) => {
419
+ const moons = own
420
+ .filter((m) => familyOf(m) === id)
421
+ .map((m) => ({ id: m.id, label: m.label, ja: m.ja, radiusKm: m.radiusKm, estimate: m.radiusFrom === "derived", retrograde: m.retrograde, moon: m }));
422
+ const sized = moons.filter((m) => m.radiusKm !== null);
423
+ const largest = sized.reduce((best, m) => (best === undefined || m.radiusKm > best.radiusKm ? m : best), undefined);
424
+ const smallest = sized.reduce((best, m) => (best === undefined || m.radiusKm < best.radiusKm ? m : best), undefined);
425
+ const ways = new Set(moons.filter((m) => m.retrograde !== null).map((m) => (m.retrograde ? "retrograde" : "prograde")));
426
+ return {
427
+ id,
428
+ host,
429
+ names: FAMILY_TABLE[id].names,
430
+ color: FAMILY_TABLE[id].color,
431
+ count: moons.length,
432
+ named: moons.filter((m) => m.moon.named).length,
433
+ sized: sized.length,
434
+ estimated: sized.filter((m) => m.estimate).length,
435
+ largestKm: largest?.radiusKm ?? null,
436
+ largestIsEstimate: largest?.estimate ?? false,
437
+ smallestKm: smallest?.radiusKm ?? null,
438
+ smallestIsEstimate: smallest?.estimate ?? false,
439
+ direction: ways.size === 0 ? null : ways.size === 2 ? "mixed" : ways.has("retrograde") ? "retrograde" : "prograde",
440
+ moons,
441
+ };
442
+ });
443
+ }
444
+ const DIRECTION_KEY = {
445
+ prograde: { names: { en: "Prograde (with the planet's turn)", ja: "順行(惑星の自転と同じ向き)" }, color: "#5aa9ff" },
446
+ retrograde: { names: { en: "Retrograde (against it)", ja: "逆行(惑星の自転と逆向き)" }, color: "#ff6b6b" },
447
+ };
448
+ /**
449
+ * The colour an orbit is drawn in, `#rrggbb`: by `group` the moon's family colour, by `direction` blue for prograde and red for retrograde. A moon with no orbit has none to draw; it gets the neutral grey.
450
+ *
451
+ * @param moon - A moon of the catalogue.
452
+ * @param by - What the colour says.
453
+ * @returns `#rrggbb`.
454
+ *
455
+ * @example
456
+ * ```ts
457
+ * import { findCatalogueMoon, moonOrbitColor } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
458
+ *
459
+ * console.log(moonOrbitColor(findCatalogueMoon("Carme")!, "direction"));
460
+ * ```
461
+ */
462
+ export function moonOrbitColor(moon, by) {
463
+ if (by === "direction")
464
+ return moon.retrograde === null ? "#c9cdd4" : DIRECTION_KEY[moon.retrograde ? "retrograde" : "prograde"].color;
465
+ return FAMILY_TABLE[familyOf(moon)].color;
466
+ }
467
+ /**
468
+ * The key to the colours of the orbits drawn for some hosts, as data: one entry per colour in use, with its names (English and Japanese), its `#rrggbb` and how many moons wear it. A page draws it beside the view
469
+ * (the element's `moonKey` gives the key of what it is drawing).
470
+ *
471
+ * @param by - Coloured by `group` (the families) or `direction`.
472
+ * @param hosts - The planets or dwarf planets drawn; every host by default.
473
+ * @returns The entries, in the order the families are listed (prograde, then retrograde).
474
+ *
475
+ * @example
476
+ * ```ts
477
+ * import { moonOrbitKey } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
478
+ *
479
+ * for (const entry of moonOrbitKey("group", ["saturn"])) console.log(entry.color, entry.names.en, entry.count);
480
+ * ```
481
+ */
482
+ export function moonOrbitKey(by, hosts) {
483
+ const moons = MOON_CATALOGUE.filter((m) => m.orbit !== null && (hosts === undefined || hosts.includes(m.host)));
484
+ if (by === "direction") {
485
+ return ["prograde", "retrograde"]
486
+ .map((id) => ({ id, names: DIRECTION_KEY[id].names, color: DIRECTION_KEY[id].color, count: moons.filter((m) => m.retrograde === (id === "retrograde")).length }))
487
+ .filter((entry) => entry.count > 0);
488
+ }
489
+ const out = [];
490
+ for (const m of moons) {
491
+ const id = familyOf(m);
492
+ const seen = out.find((entry) => entry.id === id);
493
+ if (seen === undefined)
494
+ out.push({ id, names: FAMILY_TABLE[id].names, color: FAMILY_TABLE[id].color, count: 1 });
495
+ else
496
+ seen.count += 1;
497
+ }
498
+ const order = Object.keys(FAMILY_TABLE);
499
+ return out.sort((x, y) => order.indexOf(x.id) - order.indexOf(y.id));
500
+ }
@@ -25,7 +25,7 @@ export const PLACE_LAYERS = ["landing", "crash", "planned", "feature"];
25
25
  * ```
26
26
  */
27
27
  export function layerOf(kind) {
28
- return kind === "crewed" || kind === "landing" || kind === "rover" ? "landing" : kind === "crash" || kind === "impact" || kind === "entry" ? "crash" : kind === "planned" ? "planned" : "feature";
28
+ return kind === "crewed" || kind === "landing" || kind === "rover" || kind === "hardware" ? "landing" : kind === "crash" || kind === "impact" || kind === "entry" ? "crash" : kind === "planned" ? "planned" : "feature";
29
29
  }
30
30
  /**
31
31
  * The layers an attribute asks for: a list of layer names with spaces or commas between (`"landing crash"`), `all` (or an empty value) for every layer, and `none` or `off` for none. Unknown words are left out.
@@ -0,0 +1,179 @@
1
+ import type { PlaceOnBody } from "./scene/body-places.ts";
2
+ import type { Place, PlaceKind } from "./places.ts";
3
+ /**
4
+ * One row of a body's search list: the compact record of a point of interest, enough to find it, show it, favourite it and go to it. A favourite stores `id`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { loadPlaceSearch } from "@johnmorrisdotca/wakusei-planets/places/search";
9
+ * import type { PlaceHit } from "@johnmorrisdotca/wakusei-planets/places/search";
10
+ *
11
+ * const hits = await loadPlaceSearch("mars");
12
+ * const olympus: PlaceHit = hits.find((hit) => hit.id === "mars/olympus-mons")!;
13
+ * console.log(olympus.name.ja, olympus.typeWord.en, olympus.diameterKm, olympus.source.ref);
14
+ * ```
15
+ */
16
+ export interface PlaceHit {
17
+ /** `<body>/<slug>`, the id the full lists (`/places/<body>`) use for the same place, and the id a favourite keeps. It is stable: an id of 0.66.0 is still in the lists, or is an alias (`resolvePlaceId`). */
18
+ id: string;
19
+ /** The body: `moon`, `mars`, `ceres`, `phobos`. The Moon's lettered craters are in the body `moon` too. */
20
+ body: string;
21
+ kind: PlaceKind;
22
+ /** The name in English and Japanese (a feature's Japanese name is the package's name for it where it has one, else its IAU name, which is Latin or the name's own spelling). */
23
+ name: {
24
+ en: string;
25
+ ja: string;
26
+ };
27
+ /** A plain word for what it is: the feature's type (`crater`, `plain`, `satellite crater`) or the kind of site (`rover`, `crash site`). */
28
+ typeWord: {
29
+ en: string;
30
+ ja: string;
31
+ };
32
+ /** The Gazetteer's name for a feature's type (`Crater, craters`), for a feature. */
33
+ type?: string;
34
+ /** Planetocentric latitude and east longitude from -180 to 180, in degrees. */
35
+ lat: number;
36
+ lon: number;
37
+ /** A feature's size in kilometres (the diameter, or the length of a line); 0 where the Gazetteer gives none. Always 0 for a site. */
38
+ diameterKm: number;
39
+ /** For a site: when it got there (ISO, UTC), to the minute where the source gives one. */
40
+ date?: string;
41
+ /** True where the source gives a site's position to a degree or less, or says it is an estimate. */
42
+ approximate?: true;
43
+ /** Where the row comes from: the source's id (as in `PLACES_CREDITS`), the date its file was read, and for a feature the Gazetteer's feature id (`placeHitUrl` makes its page). */
44
+ source: {
45
+ id: Place["source"]["id"];
46
+ read: string;
47
+ ref?: number;
48
+ };
49
+ }
50
+ /**
51
+ * The ids of the sources in the order the tables number them: the same ones as `PLACES_CREDITS`, in another order.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { SEARCH_SOURCE_IDS } from "@johnmorrisdotca/wakusei-planets/places/search";
56
+ *
57
+ * console.log(SEARCH_SOURCE_IDS.length, "sources, the first is", SEARCH_SOURCE_IDS[0]);
58
+ * ```
59
+ */
60
+ export declare const SEARCH_SOURCE_IDS: readonly Place["source"]["id"][];
61
+ /**
62
+ * A plain word for each kind of place, in English and Japanese, as a search result shows it for a site.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { PLACE_KIND_WORDS } from "@johnmorrisdotca/wakusei-planets/places/search";
67
+ *
68
+ * console.log(PLACE_KIND_WORDS.hardware.en, PLACE_KIND_WORDS.hardware.ja);
69
+ * ```
70
+ */
71
+ export declare const PLACE_KIND_WORDS: Readonly<Record<PlaceKind, {
72
+ en: string;
73
+ ja: string;
74
+ }>>;
75
+ /**
76
+ * Reads a body's table into its list. The table is one string: the date its Gazetteer file was read, then one line for each place, with the columns id, kind, name, Japanese name, type, latitude, longitude, size, source and date, flags.
77
+ * A feature's Gazetteer id is written as the step from the feature before it. Used by the entry points of `/places/search/<body>`.
78
+ *
79
+ * @param body - The body the table is of.
80
+ * @param text - The table.
81
+ * @returns The list: the sites by date, then the features in the order of their Gazetteer ids.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import { readPlaceHits } from "@johnmorrisdotca/wakusei-planets/places/search";
86
+ *
87
+ * const hits = readPlaceHits("moon", "2026-11-18\n\tf\tTycho\tティコ\t6\t-43.31\t-11.36\t85\t6163");
88
+ * console.log(hits[0]?.id, hits[0]?.name.ja, hits[0]?.source.ref);
89
+ * ```
90
+ */
91
+ export declare function readPlaceHits(body: string, text: string): PlaceHit[];
92
+ /**
93
+ * An id as the lists now have it: an id of an earlier release whose place was renamed (or held twice) turned into its current id, any other id as it is. A page that saved favourites with 0.66.0's ids calls this before it looks one up.
94
+ *
95
+ * @param id - A place id.
96
+ * @returns The current id.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { resolvePlaceId } from "@johnmorrisdotca/wakusei-planets/places/search";
101
+ *
102
+ * console.log(resolvePlaceId("mercury/kunisada-2"), resolvePlaceId("moon/tycho"));
103
+ * ```
104
+ */
105
+ export declare function resolvePlaceId(id: string): string;
106
+ /**
107
+ * The page a hit comes from: a Gazetteer feature's page on the USGS site, or `undefined` for a site (its source is named in `PLACES_CREDITS`).
108
+ *
109
+ * @param hit - A row of a search list.
110
+ * @returns The address, or `undefined` for a site.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * import { loadPlaceSearch, placeHitUrl } from "@johnmorrisdotca/wakusei-planets/places/search";
115
+ *
116
+ * const tycho = (await loadPlaceSearch("moon")).find((hit) => hit.id === "moon/tycho")!;
117
+ * console.log(placeHitUrl(tycho));
118
+ * ```
119
+ */
120
+ export declare function placeHitUrl(hit: PlaceHit): string | undefined;
121
+ /**
122
+ * A hit as a `Place`, for the parts of the package that take one (`goToPlace` with a list of your own, `placeMarks`, `findPlace`). A feature's `approved` date and the origin of its name are not in a search list, so `approved` is empty and there is no `origin`:
123
+ * the Gazetteer's page (`placeHitUrl`) has them.
124
+ *
125
+ * @param hit - A row of a search list.
126
+ * @returns The place.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * import { hitToPlace, loadPlaceSearch } from "@johnmorrisdotca/wakusei-planets/places/search";
131
+ *
132
+ * const place = hitToPlace((await loadPlaceSearch("mars")).find((hit) => hit.id === "mars/olympus-mons")!);
133
+ * console.log(place.kind, place.feature?.diameterKm, place.lat);
134
+ * ```
135
+ */
136
+ export declare function hitToPlace(hit: PlaceHit): Place;
137
+ /**
138
+ * The places of a list that match what a reader typed, best first. A match is on the English name, the Japanese name or the id's name, ignoring case and accents: the whole name first, then a name that starts with the text, then a word that does, then any
139
+ * name that holds it. Within a kind of match the visited sites come before the features, and a larger feature before a smaller one.
140
+ *
141
+ * @param hits - One or more lists (`loadPlaceSearch`); the lists of several bodies make a search of all of them.
142
+ * @param query - What the reader typed. Empty text matches nothing.
143
+ * @param options - `limit` (default 20), and `kinds` to keep only some kinds of place.
144
+ * @returns The matching places.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * import { loadPlaceSearch, searchPlaces } from "@johnmorrisdotca/wakusei-planets/places/search";
149
+ *
150
+ * const moon = await loadPlaceSearch("moon");
151
+ * console.log(searchPlaces(moon, "apollo 11", { limit: 3 }).map((hit) => hit.name.en).join("; "));
152
+ * console.log(searchPlaces(moon, "静かの海")[0]?.name.en);
153
+ * ```
154
+ */
155
+ export declare function searchPlaces(hits: readonly PlaceHit[], query: string, options?: {
156
+ limit?: number;
157
+ kinds?: readonly PlaceKind[];
158
+ }): PlaceHit[];
159
+ /**
160
+ * A hit as a place for `<wakusei-space>`'s `bodyPlaces`: a beam on the ground of the hit's body at its latitude and longitude, named in English or Japanese, the id the hit has (a favourite's id, so a press says which one it was).
161
+ *
162
+ * @param hit - A row of a search list.
163
+ * @param options - `lang` for the label (`en` by default), `kind` (`favourite` by default, or `here`), `color` (a CSS colour for this place alone) and `label` (your own text, or `false` for none).
164
+ * @returns The place to draw.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * import { hitToBodyPlace, loadPlaceSearch } from "@johnmorrisdotca/wakusei-planets/places/search";
169
+ *
170
+ * const olympus = (await loadPlaceSearch("mars")).find((hit) => hit.id === "mars/olympus-mons")!;
171
+ * console.log(hitToBodyPlace(olympus, { lang: "ja", color: "#ff8844" }));
172
+ * ```
173
+ */
174
+ export declare function hitToBodyPlace(hit: PlaceHit, options?: {
175
+ lang?: "en" | "ja";
176
+ kind?: "here" | "favourite";
177
+ color?: string;
178
+ label?: string | false;
179
+ }): PlaceOnBody;
@@ -0,0 +1,223 @@
1
+ // The search lists of every point of interest on every body: the record a search returns (`PlaceHit`), how a list is read from its table, the matching, the ids and the page a hit comes from. Pure: no DOM, no clock reads.
2
+ // The lists themselves are the entry points `/places/search/<body>`, loaded one at a time by `loadPlaceSearch` from `/places/search`, so a page pays only for the body it searches.
3
+ import { PLACE_ID_ALIASES } from "./data/places-aliases.js";
4
+ import { SEARCH_TYPES } from "./data/places-search-types.js";
5
+ /**
6
+ * The ids of the sources in the order the tables number them: the same ones as `PLACES_CREDITS`, in another order.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { SEARCH_SOURCE_IDS } from "@johnmorrisdotca/wakusei-planets/places/search";
11
+ *
12
+ * console.log(SEARCH_SOURCE_IDS.length, "sources, the first is", SEARCH_SOURCE_IDS[0]);
13
+ * ```
14
+ */
15
+ export const SEARCH_SOURCE_IDS = ["iau-gazetteer", "gcat-landercat", "nssdca", "pds-ode", "nasa-mars24", "agency", "nasa-ntrs", "pds-atmospheres", "paper", "announcement"];
16
+ /**
17
+ * A plain word for each kind of place, in English and Japanese, as a search result shows it for a site.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { PLACE_KIND_WORDS } from "@johnmorrisdotca/wakusei-planets/places/search";
22
+ *
23
+ * console.log(PLACE_KIND_WORDS.hardware.en, PLACE_KIND_WORDS.hardware.ja);
24
+ * ```
25
+ */
26
+ export const PLACE_KIND_WORDS = {
27
+ crewed: { en: "crewed landing", ja: "有人着陸" },
28
+ landing: { en: "lander", ja: "着陸機" },
29
+ rover: { en: "rover", ja: "探査車" },
30
+ crash: { en: "crash site", ja: "墜落地点" },
31
+ impact: { en: "impact site", ja: "衝突地点" },
32
+ entry: { en: "lost in the atmosphere", ja: "大気圏で消失" },
33
+ planned: { en: "planned landing", ja: "着陸予定" },
34
+ feature: { en: "feature", ja: "地形" },
35
+ hardware: { en: "hardware", ja: "機器・部品" },
36
+ };
37
+ const KINDS = { c: "crewed", l: "landing", r: "rover", x: "crash", i: "impact", e: "entry", p: "planned", f: "feature", h: "hardware" };
38
+ /**
39
+ * Reads a body's table into its list. The table is one string: the date its Gazetteer file was read, then one line for each place, with the columns id, kind, name, Japanese name, type, latitude, longitude, size, source and date, flags.
40
+ * A feature's Gazetteer id is written as the step from the feature before it. Used by the entry points of `/places/search/<body>`.
41
+ *
42
+ * @param body - The body the table is of.
43
+ * @param text - The table.
44
+ * @returns The list: the sites by date, then the features in the order of their Gazetteer ids.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { readPlaceHits } from "@johnmorrisdotca/wakusei-planets/places/search";
49
+ *
50
+ * const hits = readPlaceHits("moon", "2026-11-18\n\tf\tTycho\tティコ\t6\t-43.31\t-11.36\t85\t6163");
51
+ * console.log(hits[0]?.id, hits[0]?.name.ja, hits[0]?.source.ref);
52
+ * ```
53
+ */
54
+ export function readPlaceHits(body, text) {
55
+ const lines = text.split("\n");
56
+ const read = lines[0] ?? "";
57
+ const hits = [];
58
+ let feature = 0;
59
+ for (let i = 1; i < lines.length; i++) {
60
+ const c = lines[i].split("\t");
61
+ const kind = KINDS[c[1]];
62
+ const en = c[2];
63
+ const type = c[4] === "" || c[4] === undefined ? undefined : SEARCH_TYPES[Number(c[4])];
64
+ const ref = c[8];
65
+ const at = ref.indexOf("@");
66
+ const hit = {
67
+ id: c[0] === "" ? `${body}/${slugOf(en)}` : c[0],
68
+ body: (c[0] === "" ? body : c[0].split("/")[0]),
69
+ kind,
70
+ name: { en, ja: c[3] === "" ? en : c[3] },
71
+ typeWord: type === undefined ? PLACE_KIND_WORDS[kind] : { en: type[1], ja: type[2] },
72
+ lat: Number(c[5]),
73
+ lon: Number(c[6]),
74
+ diameterKm: c[7] === "" || c[7] === undefined ? 0 : Number(c[7]),
75
+ source: at < 0 ? { id: "iau-gazetteer", read, ref: (feature += Number(ref)) } : { id: SEARCH_SOURCE_IDS[Number(ref.slice(0, at))], read: ref.slice(at + 1) },
76
+ };
77
+ if (type !== undefined)
78
+ hit.type = type[0];
79
+ if (c[9] !== "" && c[9] !== undefined)
80
+ hit.date = c[9];
81
+ if (c[10] === "a")
82
+ hit.approximate = true;
83
+ hits.push(hit);
84
+ }
85
+ return hits;
86
+ }
87
+ /** The slug of a name: accents taken off, lower case, anything else but letters and digits a hyphen. */
88
+ function slugOf(name) {
89
+ return name.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
90
+ }
91
+ /**
92
+ * An id as the lists now have it: an id of an earlier release whose place was renamed (or held twice) turned into its current id, any other id as it is. A page that saved favourites with 0.66.0's ids calls this before it looks one up.
93
+ *
94
+ * @param id - A place id.
95
+ * @returns The current id.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { resolvePlaceId } from "@johnmorrisdotca/wakusei-planets/places/search";
100
+ *
101
+ * console.log(resolvePlaceId("mercury/kunisada-2"), resolvePlaceId("moon/tycho"));
102
+ * ```
103
+ */
104
+ export function resolvePlaceId(id) {
105
+ return Object.hasOwn(PLACE_ID_ALIASES, id) ? PLACE_ID_ALIASES[id] : id;
106
+ }
107
+ /**
108
+ * The page a hit comes from: a Gazetteer feature's page on the USGS site, or `undefined` for a site (its source is named in `PLACES_CREDITS`).
109
+ *
110
+ * @param hit - A row of a search list.
111
+ * @returns The address, or `undefined` for a site.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * import { loadPlaceSearch, placeHitUrl } from "@johnmorrisdotca/wakusei-planets/places/search";
116
+ *
117
+ * const tycho = (await loadPlaceSearch("moon")).find((hit) => hit.id === "moon/tycho")!;
118
+ * console.log(placeHitUrl(tycho));
119
+ * ```
120
+ */
121
+ export function placeHitUrl(hit) {
122
+ return hit.source.id === "iau-gazetteer" && hit.source.ref !== undefined ? `https://planetarynames.wr.usgs.gov/Feature/${hit.source.ref}` : undefined;
123
+ }
124
+ /**
125
+ * A hit as a `Place`, for the parts of the package that take one (`goToPlace` with a list of your own, `placeMarks`, `findPlace`). A feature's `approved` date and the origin of its name are not in a search list, so `approved` is empty and there is no `origin`:
126
+ * the Gazetteer's page (`placeHitUrl`) has them.
127
+ *
128
+ * @param hit - A row of a search list.
129
+ * @returns The place.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * import { hitToPlace, loadPlaceSearch } from "@johnmorrisdotca/wakusei-planets/places/search";
134
+ *
135
+ * const place = hitToPlace((await loadPlaceSearch("mars")).find((hit) => hit.id === "mars/olympus-mons")!);
136
+ * console.log(place.kind, place.feature?.diameterKm, place.lat);
137
+ * ```
138
+ */
139
+ export function hitToPlace(hit) {
140
+ const place = { id: hit.id, kind: hit.kind, name: hit.name, lat: hit.lat, lon: hit.lon, source: { id: hit.source.id, read: hit.source.read } };
141
+ if (hit.kind === "feature" && hit.type !== undefined)
142
+ place.feature = { type: hit.type, typeWord: hit.typeWord, diameterKm: hit.diameterKm, approved: "" };
143
+ if (hit.date !== undefined)
144
+ place.date = hit.date;
145
+ if (hit.approximate === true)
146
+ place.approximate = true;
147
+ if (hit.source.ref !== undefined)
148
+ place.source.url = placeHitUrl(hit);
149
+ return place;
150
+ }
151
+ const FOLDED = new WeakMap();
152
+ /** Lower case with the accents off, so "Bartók" is found by "bartok" and "ÅNGSTRÖM" by "angstrom". */
153
+ function fold(text) {
154
+ return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
155
+ }
156
+ const KIND_ORDER = { crewed: 0, landing: 1, rover: 2, crash: 3, impact: 4, entry: 5, planned: 6, hardware: 7, feature: 8 };
157
+ /**
158
+ * The places of a list that match what a reader typed, best first. A match is on the English name, the Japanese name or the id's name, ignoring case and accents: the whole name first, then a name that starts with the text, then a word that does, then any
159
+ * name that holds it. Within a kind of match the visited sites come before the features, and a larger feature before a smaller one.
160
+ *
161
+ * @param hits - One or more lists (`loadPlaceSearch`); the lists of several bodies make a search of all of them.
162
+ * @param query - What the reader typed. Empty text matches nothing.
163
+ * @param options - `limit` (default 20), and `kinds` to keep only some kinds of place.
164
+ * @returns The matching places.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * import { loadPlaceSearch, searchPlaces } from "@johnmorrisdotca/wakusei-planets/places/search";
169
+ *
170
+ * const moon = await loadPlaceSearch("moon");
171
+ * console.log(searchPlaces(moon, "apollo 11", { limit: 3 }).map((hit) => hit.name.en).join("; "));
172
+ * console.log(searchPlaces(moon, "静かの海")[0]?.name.en);
173
+ * ```
174
+ */
175
+ export function searchPlaces(hits, query, options = {}) {
176
+ const wanted = fold(query.trim());
177
+ if (wanted === "")
178
+ return [];
179
+ const out = [];
180
+ for (const hit of hits) {
181
+ if (options.kinds !== undefined && !options.kinds.includes(hit.kind))
182
+ continue;
183
+ let names = FOLDED.get(hit);
184
+ if (names === undefined)
185
+ FOLDED.set(hit, (names = [fold(hit.name.en), fold(hit.name.ja)]));
186
+ let score = 9;
187
+ for (const name of names) {
188
+ const at = name.indexOf(wanted);
189
+ if (at < 0)
190
+ continue;
191
+ score = Math.min(score, name === wanted ? 0 : at === 0 ? 1 : /[\s\-'(]/.test(name[at - 1]) ? 2 : 3);
192
+ }
193
+ if (score < 9)
194
+ out.push({ hit, score });
195
+ }
196
+ out.sort((a, b) => a.score - b.score || KIND_ORDER[a.hit.kind] - KIND_ORDER[b.hit.kind] || b.hit.diameterKm - a.hit.diameterKm || (a.hit.name.en < b.hit.name.en ? -1 : a.hit.name.en > b.hit.name.en ? 1 : 0));
197
+ return out.slice(0, options.limit ?? 20).map((entry) => entry.hit);
198
+ }
199
+ /**
200
+ * A hit as a place for `<wakusei-space>`'s `bodyPlaces`: a beam on the ground of the hit's body at its latitude and longitude, named in English or Japanese, the id the hit has (a favourite's id, so a press says which one it was).
201
+ *
202
+ * @param hit - A row of a search list.
203
+ * @param options - `lang` for the label (`en` by default), `kind` (`favourite` by default, or `here`), `color` (a CSS colour for this place alone) and `label` (your own text, or `false` for none).
204
+ * @returns The place to draw.
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * import { hitToBodyPlace, loadPlaceSearch } from "@johnmorrisdotca/wakusei-planets/places/search";
209
+ *
210
+ * const olympus = (await loadPlaceSearch("mars")).find((hit) => hit.id === "mars/olympus-mons")!;
211
+ * console.log(hitToBodyPlace(olympus, { lang: "ja", color: "#ff8844" }));
212
+ * ```
213
+ */
214
+ export function hitToBodyPlace(hit, options = {}) {
215
+ const place = { body: hit.body, id: hit.id, lon: hit.lon, lat: hit.lat };
216
+ if (options.label !== false)
217
+ place.label = options.label ?? hit.name[options.lang ?? "en"];
218
+ if (options.kind !== undefined)
219
+ place.kind = options.kind;
220
+ if (options.color !== undefined)
221
+ place.color = options.color;
222
+ return place;
223
+ }
@@ -1,7 +1,10 @@
1
1
  // The places on the Moon: landing, rover, crash and impact sites, and the named features, as one list. See `/places` for the record's shape and the lookups.
2
2
  import { PLACES_MOON as DATA } from "../data/places-moon.js";
3
+ import { ADDED_MOON } from "../data/places-added.js";
3
4
  import { PLANNED_MOON } from "../data/places-planned.js";
4
5
  const ALL = DATA;
6
+ // The sites by date; the rovers added in 0.67 take their place among them (a stable sort leaves the others as they were)
7
+ const SITES = [...ALL.filter((place) => place.kind !== "feature"), ...ADDED_MOON].sort((a, b) => ((a.date ?? "") < (b.date ?? "") ? -1 : (a.date ?? "") > (b.date ?? "") ? 1 : 0));
5
8
  /**
6
9
  * Every place on the Moon the package knows: the sites first, by date, then the planned landings, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
7
10
  *
@@ -12,4 +15,4 @@ const ALL = DATA;
12
15
  * console.log(PLACES_MOON.length, "places;", PLACES_MOON.filter((place) => place.kind === "landing").length, "landings");
13
16
  * ```
14
17
  */
15
- export const PLACES_MOON = [...ALL.filter((place) => place.kind !== "feature"), ...PLANNED_MOON, ...ALL.filter((place) => place.kind === "feature")];
18
+ export const PLACES_MOON = [...SITES, ...PLANNED_MOON, ...ALL.filter((place) => place.kind === "feature")];
@@ -0,0 +1,12 @@
1
+ import { type PlaceHit } from "../../place-search.ts";
2
+ /**
3
+ * The search list of comet 67P: 1 rows (0 named features, the rest sites), the sites first by date, then the features in the order of their Gazetteer ids. Read from a compact table when the entry is first imported.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { PLACE_HITS_67P } from "@johnmorrisdotca/wakusei-planets/places/search/67p";
8
+ *
9
+ * console.log(PLACE_HITS_67P.length, "rows;", PLACE_HITS_67P[0]?.name.en);
10
+ * ```
11
+ */
12
+ export declare const PLACE_HITS_67P: readonly PlaceHit[];