@johnmorrisdotca/wakusei-planets 0.34.0 → 0.35.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 (203) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/NOTICE.md +48 -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/places-67p.d.ts +27 -0
  33. package/dist/data/places-67p.js +2 -0
  34. package/dist/data/places-ariel.d.ts +602 -0
  35. package/dist/data/places-ariel.js +27 -0
  36. package/dist/data/places-bennu.d.ts +25 -0
  37. package/dist/data/places-bennu.js +2 -0
  38. package/dist/data/places-callisto.d.ts +3547 -0
  39. package/dist/data/places-callisto.js +155 -0
  40. package/dist/data/places-ceres.d.ts +3436 -0
  41. package/dist/data/places-ceres.js +150 -0
  42. package/dist/data/places-charon.d.ts +349 -0
  43. package/dist/data/places-charon.js +16 -0
  44. package/dist/data/places-dimorphos.d.ts +23 -0
  45. package/dist/data/places-dimorphos.js +2 -0
  46. package/dist/data/places-dione.d.ts +2258 -0
  47. package/dist/data/places-dione.js +99 -0
  48. package/dist/data/places-enceladus.d.ts +2009 -0
  49. package/dist/data/places-enceladus.js +88 -0
  50. package/dist/data/places-eros.d.ts +26 -0
  51. package/dist/data/places-eros.js +2 -0
  52. package/dist/data/places-europa.d.ts +2977 -0
  53. package/dist/data/places-europa.js +130 -0
  54. package/dist/data/places-ganymede.d.ts +4518 -0
  55. package/dist/data/places-ganymede.js +197 -0
  56. package/dist/data/places-iapetus.d.ts +1616 -0
  57. package/dist/data/places-iapetus.js +71 -0
  58. package/dist/data/places-io.d.ts +6012 -0
  59. package/dist/data/places-io.js +262 -0
  60. package/dist/data/places-jupiter.d.ts +46 -0
  61. package/dist/data/places-jupiter.js +3 -0
  62. package/dist/data/places-mars.d.ts +20701 -0
  63. package/dist/data/places-mars.js +942 -0
  64. package/dist/data/places-mercury.d.ts +9256 -0
  65. package/dist/data/places-mercury.js +403 -0
  66. package/dist/data/places-mimas.d.ts +968 -0
  67. package/dist/data/places-mimas.js +43 -0
  68. package/dist/data/places-miranda.d.ts +419 -0
  69. package/dist/data/places-miranda.js +19 -0
  70. package/dist/data/places-moon.d.ts +18849 -0
  71. package/dist/data/places-moon.js +861 -0
  72. package/dist/data/places-oberon.d.ts +235 -0
  73. package/dist/data/places-oberon.js +11 -0
  74. package/dist/data/places-pluto.d.ts +1687 -0
  75. package/dist/data/places-pluto.js +74 -0
  76. package/dist/data/places-rhea.d.ts +3317 -0
  77. package/dist/data/places-rhea.js +145 -0
  78. package/dist/data/places-ryugu.d.ts +87 -0
  79. package/dist/data/places-ryugu.js +5 -0
  80. package/dist/data/places-saturn.d.ts +25 -0
  81. package/dist/data/places-saturn.js +2 -0
  82. package/dist/data/places-tempel-1.d.ts +25 -0
  83. package/dist/data/places-tempel-1.js +2 -0
  84. package/dist/data/places-tethys.d.ts +1222 -0
  85. package/dist/data/places-tethys.js +54 -0
  86. package/dist/data/places-titan.d.ts +7031 -0
  87. package/dist/data/places-titan.js +306 -0
  88. package/dist/data/places-titania.d.ts +418 -0
  89. package/dist/data/places-titania.js +19 -0
  90. package/dist/data/places-triton.d.ts +1457 -0
  91. package/dist/data/places-triton.js +64 -0
  92. package/dist/data/places-umbriel.d.ts +303 -0
  93. package/dist/data/places-umbriel.js +14 -0
  94. package/dist/data/places-venus.d.ts +9290 -0
  95. package/dist/data/places-venus.js +405 -0
  96. package/dist/data/places-vesta.d.ts +2444 -0
  97. package/dist/data/places-vesta.js +107 -0
  98. package/dist/data/roadster.d.ts +8 -0
  99. package/dist/data/roadster.js +686 -0
  100. package/dist/element.js +17 -3
  101. package/dist/places/67p.d.ts +13 -0
  102. package/dist/places/67p.js +14 -0
  103. package/dist/places/ariel.d.ts +13 -0
  104. package/dist/places/ariel.js +14 -0
  105. package/dist/places/bennu.d.ts +13 -0
  106. package/dist/places/bennu.js +14 -0
  107. package/dist/places/callisto.d.ts +13 -0
  108. package/dist/places/callisto.js +14 -0
  109. package/dist/places/ceres.d.ts +13 -0
  110. package/dist/places/ceres.js +14 -0
  111. package/dist/places/charon.d.ts +13 -0
  112. package/dist/places/charon.js +14 -0
  113. package/dist/places/dimorphos.d.ts +13 -0
  114. package/dist/places/dimorphos.js +14 -0
  115. package/dist/places/dione.d.ts +13 -0
  116. package/dist/places/dione.js +14 -0
  117. package/dist/places/enceladus.d.ts +13 -0
  118. package/dist/places/enceladus.js +14 -0
  119. package/dist/places/eros.d.ts +13 -0
  120. package/dist/places/eros.js +14 -0
  121. package/dist/places/europa.d.ts +13 -0
  122. package/dist/places/europa.js +14 -0
  123. package/dist/places/ganymede.d.ts +13 -0
  124. package/dist/places/ganymede.js +14 -0
  125. package/dist/places/iapetus.d.ts +13 -0
  126. package/dist/places/iapetus.js +14 -0
  127. package/dist/places/io.d.ts +13 -0
  128. package/dist/places/io.js +14 -0
  129. package/dist/places/jupiter.d.ts +13 -0
  130. package/dist/places/jupiter.js +14 -0
  131. package/dist/places/mars.d.ts +12 -0
  132. package/dist/places/mars.js +13 -0
  133. package/dist/places/mercury.d.ts +13 -0
  134. package/dist/places/mercury.js +14 -0
  135. package/dist/places/mimas.d.ts +13 -0
  136. package/dist/places/mimas.js +14 -0
  137. package/dist/places/miranda.d.ts +13 -0
  138. package/dist/places/miranda.js +14 -0
  139. package/dist/places/moon.d.ts +12 -0
  140. package/dist/places/moon.js +13 -0
  141. package/dist/places/oberon.d.ts +13 -0
  142. package/dist/places/oberon.js +14 -0
  143. package/dist/places/pluto.d.ts +13 -0
  144. package/dist/places/pluto.js +14 -0
  145. package/dist/places/rhea.d.ts +13 -0
  146. package/dist/places/rhea.js +14 -0
  147. package/dist/places/ryugu.d.ts +13 -0
  148. package/dist/places/ryugu.js +14 -0
  149. package/dist/places/saturn.d.ts +13 -0
  150. package/dist/places/saturn.js +14 -0
  151. package/dist/places/tempel-1.d.ts +13 -0
  152. package/dist/places/tempel-1.js +14 -0
  153. package/dist/places/tethys.d.ts +13 -0
  154. package/dist/places/tethys.js +14 -0
  155. package/dist/places/titan.d.ts +13 -0
  156. package/dist/places/titan.js +14 -0
  157. package/dist/places/titania.d.ts +13 -0
  158. package/dist/places/titania.js +14 -0
  159. package/dist/places/triton.d.ts +13 -0
  160. package/dist/places/triton.js +14 -0
  161. package/dist/places/umbriel.d.ts +13 -0
  162. package/dist/places/umbriel.js +14 -0
  163. package/dist/places/venus.d.ts +13 -0
  164. package/dist/places/venus.js +14 -0
  165. package/dist/places/vesta.d.ts +13 -0
  166. package/dist/places/vesta.js +14 -0
  167. package/dist/places.d.ts +354 -0
  168. package/dist/places.js +357 -0
  169. package/dist/plan/element.d.ts +52 -0
  170. package/dist/plan/element.js +258 -0
  171. package/dist/plan/index.d.ts +2 -0
  172. package/dist/plan/index.js +2 -0
  173. package/dist/plan/layout.d.ts +230 -0
  174. package/dist/plan/layout.js +229 -0
  175. package/dist/plan/svg.d.ts +125 -0
  176. package/dist/plan/svg.js +185 -0
  177. package/dist/roadster.d.ts +415 -0
  178. package/dist/roadster.js +496 -0
  179. package/dist/scene/body.js +10 -9
  180. package/dist/scene/painter.d.ts +1 -1
  181. package/dist/scene/painter.js +23 -7
  182. package/dist/scene/textures.d.ts +2 -2
  183. package/dist/space/beside.d.ts +4 -1
  184. package/dist/space/beside.js +47 -6
  185. package/dist/space/covered.d.ts +102 -0
  186. package/dist/space/covered.js +98 -0
  187. package/dist/space/element.d.ts +21 -1
  188. package/dist/space/element.js +126 -11
  189. package/dist/space/index.d.ts +1 -0
  190. package/dist/space/index.js +1 -0
  191. package/dist/space/scale.d.ts +2 -1
  192. package/dist/space/scale.js +13 -2
  193. package/dist/space/scene.d.ts +10 -0
  194. package/dist/space/scene.js +45 -22
  195. package/dist/spacecraft-facts.d.ts +4 -4
  196. package/dist/spacecraft-facts.js +158 -3
  197. package/dist/spacecraft.d.ts +69 -2
  198. package/dist/spacecraft.js +45 -2
  199. package/dist/textures/mimas-1024.webp +0 -0
  200. package/dist/textures/mimas-512.webp +0 -0
  201. package/dist/version.d.ts +1 -1
  202. package/dist/version.js +1 -1
  203. package/package.json +203 -1
@@ -0,0 +1,185 @@
1
+ // The plan as an SVG string: orbits as lines, each body a dot, the one marked ringed and named, a line saying which spacing it is. Light and dark come from CSS custom properties with defaults that follow the page's colour scheme.
2
+ // Pure: a plan in, a string out. A dot is `data-id`'d so the element can turn a press into the body's id.
3
+ import { BODIES } from "../facts.js";
4
+ import { LABEL_GAP } from "../space/labels.js";
5
+ import { SPACECRAFT } from "../spacecraft-facts.js";
6
+ /** What each language says. The plan's own words are a handful: the rest are each body's name from the package's facts. */
7
+ const WORDS = {
8
+ en: {
9
+ sun: (marked) => `The solar system from above${marked === undefined ? "" : `, ${marked} marked`}`,
10
+ moons: (planet, marked) => `${planet}'s moons from above its north pole${marked === undefined ? "" : `, ${marked} marked`}`,
11
+ squeezed: (reach) => `Squeezed (log) to ${reach}`,
12
+ true: (reach) => `True scale to ${reach}`,
13
+ au: "au",
14
+ radii: (planet) => `${planet} radii`,
15
+ },
16
+ ja: {
17
+ sun: (marked) => `真上から見た太陽系${marked === undefined ? "" : `(${marked}に印)`}`,
18
+ moons: (planet, marked) => `${planet}の北極の真上から見た衛星${marked === undefined ? "" : `(${marked}に印)`}`,
19
+ squeezed: (reach) => `対数で圧縮、縁は${reach}`,
20
+ true: (reach) => `実際の縮尺、縁は${reach}`,
21
+ au: "au",
22
+ radii: (planet) => `${planet}半径`,
23
+ },
24
+ };
25
+ const nameOf = (id, lang) => {
26
+ const body = BODIES[id];
27
+ if (body !== undefined)
28
+ return body.name[lang];
29
+ const craft = SPACECRAFT[id];
30
+ return craft === undefined ? id : craft.name[lang];
31
+ };
32
+ /**
33
+ * What a body is called on the plan, in a language: its name from the package's facts, or a craft's from `/spacecraft`; any other id is returned as it is.
34
+ *
35
+ * @param id - A body's id.
36
+ * @param lang - `en` or `ja`.
37
+ * @returns The name.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import { planName } from "@johnmorrisdotca/wakusei-planets/plan";
42
+ *
43
+ * console.log(planName("jupiter", "en"), planName("jupiter", "ja"), planName("voyager1", "en"));
44
+ * ```
45
+ */
46
+ export function planName(id, lang = "en") {
47
+ return nameOf(id, lang);
48
+ }
49
+ /** A distance for the scale line: whole, or one decimal below ten, with its unit. */
50
+ const reachOf = (plan, lang) => {
51
+ const words = WORDS[lang];
52
+ const n = plan.extent;
53
+ const text = n >= 100 ? n.toFixed(0) : Number(n.toFixed(n >= 10 ? 0 : 1)).toString();
54
+ return plan.unit === "au" ? `${text} ${words.au}` : `${text} ${words.radii(nameOf(plan.system, lang))}`;
55
+ };
56
+ /**
57
+ * The words a plan says besides names, in a language.
58
+ *
59
+ * @param plan - The plan.
60
+ * @param lang - `en` or `ja`.
61
+ * @returns The label for a screen reader and the scale line.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { planAt, planText } from "@johnmorrisdotca/wakusei-planets/plan";
66
+ *
67
+ * const plan = planAt(Date.UTC(2026, 10, 11), { system: "jupiter", mark: "io", spacing: "true" });
68
+ * console.log(planText(plan, "en"));
69
+ * ```
70
+ */
71
+ export function planText(plan, lang = "en") {
72
+ const words = WORDS[lang];
73
+ const marked = plan.marked === undefined ? undefined : nameOf(plan.marked, lang);
74
+ return {
75
+ label: plan.system === "sun" ? words.sun(marked) : words.moons(nameOf(plan.system, lang), marked),
76
+ scale: words[plan.spacing === "true" ? "true" : "squeezed"](reachOf(plan, lang)),
77
+ };
78
+ }
79
+ /**
80
+ * The type the plan is drawn in, as a CSS `font` value; a page that measures text to fit it (the element does) uses the same string.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { PLAN_FONT } from "@johnmorrisdotca/wakusei-planets/plan";
85
+ *
86
+ * console.log(PLAN_FONT.startsWith("10px"));
87
+ * ```
88
+ */
89
+ export const PLAN_FONT = "10px system-ui,-apple-system,'Segoe UI','Hiragino Sans','Noto Sans JP',sans-serif";
90
+ const STYLE = [
91
+ // The colours: the page may set --wakusei-plan-* itself; the defaults are the family's inks and follow light and dark.
92
+ "svg{display:block;width:100%;height:100%;font:10px/12px system-ui,-apple-system,'Segoe UI','Hiragino Sans','Noto Sans JP',sans-serif;--wp-ink:var(--wakusei-plan-ink,light-dark(#1f2320,#ece8dc));--wp-muted:var(--wakusei-plan-muted,light-dark(#6b6f68,#a09d93));--wp-line:var(--wakusei-plan-line,light-dark(#b9b3a3,#4a4e48));--wp-sun:var(--wakusei-plan-sun,light-dark(#c98f00,#e0b43b));--wp-dot:var(--wakusei-plan-dot,light-dark(#2f5d4a,#8fd1b0));--wp-mark:var(--wakusei-plan-mark,light-dark(#b5452c,#ff8a65))}",
93
+ ".o{fill:none;stroke:var(--wp-line);stroke-width:1}.om{fill:none;stroke:var(--wp-mark);stroke-width:1.5}",
94
+ ".d{fill:var(--wp-dot)}.dm{fill:var(--wp-mark)}.s{fill:var(--wp-sun)}.ring{fill:none;stroke:var(--wp-mark);stroke-width:1.5}",
95
+ ".t{fill:var(--wp-ink);paint-order:stroke;stroke:light-dark(#fbf8f1,#1d201e);stroke-width:3px;stroke-linejoin:round}.tm{font-weight:700;fill:var(--wp-mark)}.sc{fill:var(--wp-muted);font-size:9px}",
96
+ // a dot reached by the keyboard shows a ring, marked or not; the hit area is 24 px across
97
+ ".hit{fill:transparent;cursor:pointer}.fr{display:none;fill:none;stroke:var(--wp-ink);stroke-width:2}g[data-id]:focus-visible .fr{display:inline}g[data-id]:focus{outline:none}g[data-id]:hover .hit+*{opacity:.8}",
98
+ ].join("");
99
+ /** The pixels a dot is drawn with: the Sun and a planet at the middle are larger than a body going round. */
100
+ const radiusOf = (dot, centre) => (centre ? 5 : dot.marked ? 4 : dot.kind === "planet" ? 2.8 : 2.2);
101
+ const RANK = { star: 1, planet: 2, "dwarf-planet": 3, spacecraft: 3, asteroid: 4, centaur: 4, comet: 4, moon: 3 };
102
+ const n2 = (n) => (Math.round(n * 100) / 100).toString();
103
+ /** The width of a name in pixels, at 10 px type: a Japanese character is as wide as it is tall. */
104
+ const widthOf = (text) => [...text].reduce((sum, ch) => sum + (/[\u3000-\u9fff\uff00-\uffef]/.test(ch) ? 10 : 6.1), 0);
105
+ /** The places a name may take beside its dot, in the order tried: right and above, right and below, left and above, left and below. Each is kept inside the picture. */
106
+ function boxesFor(text, width, x, y, size, offset) {
107
+ const height = 12;
108
+ const fit = (left, top) => ({ id: "", x: Math.max(2, Math.min(size - 4 - width, left)), y: Math.max(2, Math.min(size - 18 - height, top)), width, height, rank: 0, size: 0 });
109
+ return [fit(x + offset, y - height - 1), fit(x + offset, y + 1), fit(x - offset - width, y - height - 1), fit(x - offset - width, y + 1)];
110
+ }
111
+ const touches = (a, b) => a.x < b.x + b.width + LABEL_GAP && b.x < a.x + a.width + LABEL_GAP && a.y < b.y + b.height + LABEL_GAP && b.y < a.y + a.height + LABEL_GAP;
112
+ /**
113
+ * The plan as an SVG string, for a square of `size` pixels: the orbit lines, the Sun or planet at the middle, a dot for each body (the marked one larger, ringed and named), the names that do not overlap, and a line at the foot
114
+ * saying how distances are drawn. Each body is a `<g data-id>` with a `role="button"`, so a page can turn a press into the body's id (the target is 24 pixels across, and a dot reached with the keyboard shows a focus ring); the colours are CSS custom properties (`--wakusei-plan-ink`, `-muted`, `-line`, `-sun`, `-dot`, `-mark`)
115
+ * that default to the family's and follow light and dark with the page's `color-scheme`.
116
+ *
117
+ * @param plan - The plan from `planAt`.
118
+ * @param options - The size, the language and whether names show.
119
+ * @returns The SVG text.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * import { planAt, planSvg } from "@johnmorrisdotca/wakusei-planets/plan";
124
+ *
125
+ * const svg = planSvg(planAt(Date.UTC(2026, 10, 11), { mark: "mars" }), { size: 240, lang: "en" });
126
+ * console.log(svg.startsWith("<svg"), svg.includes('data-id="mars"'));
127
+ * ```
128
+ */
129
+ export function planSvg(plan, options = {}) {
130
+ const size = Math.max(120, Math.round(options.size ?? 240));
131
+ const lang = options.lang ?? "en";
132
+ const names = options.names !== false;
133
+ const prefix = options.id ?? "wp";
134
+ const measure = options.measure ?? ((words) => widthOf(words));
135
+ const text = planText(plan, lang);
136
+ // the disc: a 4 px margin above, the scale line below
137
+ const R = (size - 20) / 2;
138
+ const cx = size / 2;
139
+ const cy = 4 + R;
140
+ const at = (x, y) => [cx + x * R, cy - y * R];
141
+ const path = (points) => points.map((p, i) => `${i === 0 ? "M" : "L"}${n2(cx + p[0] * R)} ${n2(cy - p[1] * R)}`).join("") + "Z";
142
+ const clip = `${prefix}-clip`;
143
+ const out = [];
144
+ out.push(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${size} ${size}" width="${size}" height="${size}" role="group" aria-label="${esc(text.label)}"><style>${STYLE}</style>`);
145
+ out.push(`<defs><clipPath id="${clip}"><circle cx="${n2(cx)}" cy="${n2(cy)}" r="${n2(R + 1)}"/></clipPath></defs>`);
146
+ out.push(`<circle cx="${n2(cx)}" cy="${n2(cy)}" r="${n2(R)}" fill="none" stroke="var(--wp-line)" stroke-width="1" stroke-dasharray="2 3"/>`);
147
+ out.push(`<g clip-path="url(#${clip})">`);
148
+ for (const orbit of plan.orbits)
149
+ if (!orbit.marked && orbit.points.length > 1)
150
+ out.push(`<path class="o" d="${path(orbit.points)}"/>`);
151
+ for (const orbit of plan.orbits)
152
+ if (orbit.marked && orbit.points.length > 1)
153
+ out.push(`<path class="om" d="${path(orbit.points)}"/>`);
154
+ out.push("</g>");
155
+ // the middle, then the bodies, the marked one last so it lies on top
156
+ const everyone = [{ dot: plan.centre, centre: true }, ...plan.dots.map((dot) => ({ dot, centre: false }))];
157
+ // names: the surest first (the marked body, then the Sun, planets and the rest), each in the first of four places beside its dot that touches no name already kept; one that fits nowhere is left out
158
+ const kept = [{ id: "\0scale", x: 2, y: size - 14, width: measure(text.scale, false) * 0.9, height: 12, rank: -1, size: 0 }];
159
+ const named = new Map();
160
+ const wanting = everyone.filter(({ dot }) => dot.marked || names).sort((a, b) => (a.dot.marked ? 0 : RANK[a.dot.kind]) - (b.dot.marked ? 0 : RANK[b.dot.kind]));
161
+ for (const { dot, centre } of wanting) {
162
+ const [x, y] = at(dot.x, dot.y);
163
+ const box = boxesFor(nameOf(dot.id, lang), measure(nameOf(dot.id, lang), dot.marked), x, y, size, radiusOf(dot, centre) + 3).find((one) => !kept.some((other) => touches(one, other)));
164
+ if (box !== undefined) {
165
+ kept.push(box);
166
+ named.set(dot.id, box);
167
+ }
168
+ }
169
+ for (const { dot, centre } of everyone) {
170
+ const [x, y] = at(dot.x, dot.y);
171
+ const r = radiusOf(dot, centre);
172
+ const name = nameOf(dot.id, lang);
173
+ const colour = dot.marked ? "dm" : dot.kind === "star" ? "s" : "d";
174
+ const shape = dot.kind === "spacecraft" ? `<rect class="${colour}" x="${n2(x - r)}" y="${n2(y - r)}" width="${n2(2 * r)}" height="${n2(2 * r)}" transform="rotate(45 ${n2(x)} ${n2(y)})"/>` : `<circle class="${colour}" cx="${n2(x)}" cy="${n2(y)}" r="${n2(r)}"/>`;
175
+ const ring = dot.marked ? `<circle class="ring" cx="${n2(x)}" cy="${n2(y)}" r="${n2(r + 4)}"/>` : "";
176
+ const box = named.get(dot.id);
177
+ const label = box !== undefined ? `<text class="t${dot.marked ? " tm" : ""}" x="${n2(box.x)}" y="${n2(box.y + 10)}">${esc(name)}</text>` : "";
178
+ out.push(`<g data-id="${esc(dot.id)}" data-kind="${dot.kind}"${dot.marked ? ' data-marked=""' : ""} role="button" tabindex="0" aria-label="${esc(name)}"><circle class="hit" cx="${n2(x)}" cy="${n2(y)}" r="12"/>${shape}${ring}<circle class="fr" cx="${n2(x)}" cy="${n2(y)}" r="${n2(r + 7)}"/>${label}</g>`);
179
+ }
180
+ out.push(`<text class="sc" x="2" y="${size - 4}">${esc(text.scale)}</text></svg>`);
181
+ return out.join("");
182
+ }
183
+ function esc(text) {
184
+ return text.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
185
+ }
@@ -0,0 +1,415 @@
1
+ import { type Vec3 } from "./vec.ts";
2
+ import { type When } from "./when.ts";
3
+ export type { When } from "./when.ts";
4
+ /**
5
+ * The names of a thing in English and Japanese.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { ROADSTER, type RoadsterName } from "@johnmorrisdotca/wakusei-planets/roadster";
10
+ *
11
+ * const name: RoadsterName = ROADSTER.name;
12
+ * console.log(name.en, name.ja);
13
+ * ```
14
+ */
15
+ export interface RoadsterName {
16
+ /** The name in English. */
17
+ en: string;
18
+ /** The name in Japanese. */
19
+ ja: string;
20
+ }
21
+ /**
22
+ * What is known about the car: its names, launch, Horizons' number and the span of the path.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { ROADSTER } from "@johnmorrisdotca/wakusei-planets/roadster";
27
+ *
28
+ * console.log(ROADSTER.name.en, "and the", ROADSTER.car.en, "were launched", new Date(ROADSTER.launch).toISOString());
29
+ * ```
30
+ */
31
+ export declare const ROADSTER: {
32
+ /** The mannequin at the wheel, in English and Japanese. */
33
+ readonly name: {
34
+ readonly en: "Starman";
35
+ readonly ja: "スターマン";
36
+ };
37
+ /** The car, in English and Japanese. */
38
+ readonly car: {
39
+ readonly en: "Tesla Roadster";
40
+ readonly ja: "テスラ・ロードスター";
41
+ };
42
+ /** The launch, in milliseconds since 1970 (UTC): the first flight of the Falcon Heavy, 2018-02-06 20:45, from launch complex 39A of the Kennedy Space Center. */
43
+ readonly launch: number;
44
+ /** The number JPL Horizons gives the car. */
45
+ readonly horizonsId: "-143205";
46
+ /** The span the path covers, in milliseconds since 1970 (UTC): from about six hours after the launch (where Horizons' record starts) to 2036-01-01. A date outside it throws a `RangeError`. */
47
+ readonly record: {
48
+ readonly start: number;
49
+ readonly end: number;
50
+ };
51
+ };
52
+ /**
53
+ * How far to trust the path, stated: the span it covers, the worst error of the interpolation against Horizons' own record as measured when the table was made, and what the table cannot know.
54
+ * The car's path is a prediction from a fit to 374 telescope observations made in February and March 2018 (Horizons' solution s11), with sunlight's push on the car estimated from them: a date years after the fit drifts from where the car really is, by more the further away it is.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { ROADSTER_ACCURACY } from "@johnmorrisdotca/wakusei-planets/roadster";
59
+ *
60
+ * console.log(`rows ${ROADSTER_ACCURACY.stepDays} days apart, within ${ROADSTER_ACCURACY.interpolationKm} km of Horizons' own path`);
61
+ * ```
62
+ */
63
+ export declare const ROADSTER_ACCURACY: {
64
+ /** The first moment the path covers, in milliseconds since 1970 (UTC). */
65
+ readonly from: number;
66
+ /** The last moment the path covers, in milliseconds since 1970 (UTC). */
67
+ readonly to: number;
68
+ /** The days between rows of the table once the car is ten days out. */
69
+ readonly stepDays: 10;
70
+ /** The worst distance, in kilometres, between the table's interpolation and Horizons' own record of the same path, measured every day of the span, every hour of the first 13 days and every hour round the Mars passes of October 2020 and April 2035. */
71
+ readonly interpolationKm: 755;
72
+ /** In words, what the numbers leave out. */
73
+ readonly note: "Horizons' path was fitted to observations from February and March 2018 and is a prediction after that; sunlight's push is modelled only as one number fitted to those observations, so the real car drifts from the predicted path, and the further from 2018 the more. The interpolation error above is separate and small beside it.";
74
+ };
75
+ /**
76
+ * Where the car is at a moment: x, y, z in kilometres from the Sun, in the J2000 ecliptic frame (the axes of `heliocentric`, which is in astronomical units, and of `spacecraftPosition`).
77
+ * The path is Horizons' prediction from 2018's observations (see `ROADSTER_ACCURACY`). A moment outside `ROADSTER.record` throws a `RangeError`.
78
+ *
79
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
80
+ * @returns The position in kilometres.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { roadsterPosition } from "@johnmorrisdotca/wakusei-planets/roadster";
85
+ *
86
+ * const [x, y, z] = roadsterPosition(new Date("2020-10-07T06:00:00Z"));
87
+ * console.log((Math.hypot(x, y, z) / 149597870.7).toFixed(3), "au from the Sun");
88
+ * ```
89
+ */
90
+ export declare function roadsterPosition(when: When): Vec3;
91
+ /**
92
+ * The same position in astronomical units, the unit `heliocentric` gives the planets in, so the car and a planet subtract directly.
93
+ *
94
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
95
+ * @returns The position in au.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { heliocentric } from "@johnmorrisdotca/wakusei-planets";
100
+ * import { roadsterPositionAu } from "@johnmorrisdotca/wakusei-planets/roadster";
101
+ *
102
+ * const day = Date.UTC(2020, 9, 7);
103
+ * const [c, m] = [roadsterPositionAu(day), heliocentric("mars", day)];
104
+ * console.log(Math.hypot(c[0] - m[0], c[1] - m[1], c[2] - m[2]).toFixed(3), "au from Mars");
105
+ * ```
106
+ */
107
+ export declare function roadsterPositionAu(when: When): Vec3;
108
+ /**
109
+ * The car's velocity relative to the Sun at a moment, in kilometres a second, in the same frame as `roadsterPosition`. It is the slope of the interpolation, within 2.3 metres a second of Horizons' own after the first day (up to 115 metres a second in the first day, while the Earth still bends the path).
110
+ *
111
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
112
+ * @returns The velocity.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * import { roadsterVelocity } from "@johnmorrisdotca/wakusei-planets/roadster";
117
+ *
118
+ * console.log(roadsterVelocity(Date.UTC(2024, 0, 1)).map((v) => v.toFixed(2)));
119
+ * ```
120
+ */
121
+ export declare function roadsterVelocity(when: When): Vec3;
122
+ /**
123
+ * The car's speed relative to the Sun at a moment, in kilometres a second.
124
+ *
125
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
126
+ * @returns The speed.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * import { roadsterSpeed } from "@johnmorrisdotca/wakusei-planets/roadster";
131
+ *
132
+ * console.log(roadsterSpeed(Date.UTC(2026, 10, 11)).toFixed(1), "km/s");
133
+ * ```
134
+ */
135
+ export declare function roadsterSpeed(when: When): number;
136
+ /**
137
+ * The osculating orbit of the car about the Sun at a moment: the ellipse it would follow if only the Sun's pull acted from then on (the real car is pulled by the planets too, so the elements drift).
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * import { roadsterElements, type RoadsterElements } from "@johnmorrisdotca/wakusei-planets/roadster";
142
+ *
143
+ * const orbit: RoadsterElements = roadsterElements(Date.UTC(2026, 10, 11));
144
+ * console.log(orbit.periodDays.toFixed(0), "days");
145
+ * ```
146
+ */
147
+ export interface RoadsterElements {
148
+ /** The semi-major axis in kilometres. */
149
+ semiMajorAxisKm: number;
150
+ /** The semi-major axis in astronomical units. */
151
+ semiMajorAxisAu: number;
152
+ /** The eccentricity: 0 is a circle, a little over a quarter for the car. */
153
+ eccentricity: number;
154
+ /** The inclination to the ecliptic of J2000, in degrees. */
155
+ inclination: number;
156
+ /** The longitude of the ascending node, in degrees (0 up to 360). */
157
+ ascendingNode: number;
158
+ /** The argument of perihelion, in degrees (0 up to 360). */
159
+ argumentOfPerihelion: number;
160
+ /** The mean anomaly, in degrees (0 up to 360): the share of the orbit run since the last perihelion, as an angle that grows evenly. */
161
+ meanAnomaly: number;
162
+ /** The true anomaly, in degrees (0 up to 360): the angle from perihelion to the car, seen from the Sun. */
163
+ trueAnomaly: number;
164
+ /** The period in days, about 557. */
165
+ periodDays: number;
166
+ /** The closest the orbit comes to the Sun, in kilometres. */
167
+ perihelionKm: number;
168
+ /** The closest the orbit comes to the Sun, in astronomical units. */
169
+ perihelionAu: number;
170
+ /** The furthest the orbit goes from the Sun, in kilometres. */
171
+ aphelionKm: number;
172
+ /** The furthest the orbit goes from the Sun, in astronomical units. */
173
+ aphelionAu: number;
174
+ }
175
+ /**
176
+ * The osculating orbital elements about the Sun at a moment, from the state vector (the same numbers Horizons lists as EC, QR, IN, OM, W, A, AD and PR).
177
+ *
178
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
179
+ * @returns The elements.
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * import { roadsterElements } from "@johnmorrisdotca/wakusei-planets/roadster";
184
+ *
185
+ * const orbit = roadsterElements(new Date("2026-11-11T00:00:00Z"));
186
+ * console.log(`perihelion ${orbit.perihelionAu.toFixed(3)} au, aphelion ${orbit.aphelionAu.toFixed(3)} au, period ${orbit.periodDays.toFixed(0)} days`);
187
+ * ```
188
+ */
189
+ export declare function roadsterElements(when: When): RoadsterElements;
190
+ /**
191
+ * The two bodies the car's close approaches are found for.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * import { roadsterApproaches, type RoadsterBody } from "@johnmorrisdotca/wakusei-planets/roadster";
196
+ *
197
+ * const body: RoadsterBody = "earth";
198
+ * console.log(roadsterApproaches(body).length, "close approaches to the", body);
199
+ * ```
200
+ */
201
+ export type RoadsterBody = "earth" | "mars";
202
+ /**
203
+ * One closest approach of the car to a planet: the moment and the distance between the centres.
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * import { roadsterApproaches, type RoadsterApproach } from "@johnmorrisdotca/wakusei-planets/roadster";
208
+ *
209
+ * const mars: RoadsterApproach = roadsterApproaches("mars")[0]!;
210
+ * console.log(new Date(mars.date).toISOString().slice(0, 10), Math.round(mars.distanceKm / 1e6), "million km");
211
+ * ```
212
+ */
213
+ export interface RoadsterApproach {
214
+ /** The moment, in milliseconds since 1970 (UTC). */
215
+ date: number;
216
+ /** The distance between the car and the planet's centre, in kilometres, with no allowance for the light's travel. */
217
+ distanceKm: number;
218
+ }
219
+ /**
220
+ * Every closest approach of the car to the Earth or to Mars inside the span of the path, in date order: a least value of the distance between the centres that is under one astronomical unit (found by scanning every two days and then narrowing each minimum to about a second).
221
+ * The car's launch, before the span, and the end of the span are not counted. The answer is the same every time, so it is worked out once and kept.
222
+ *
223
+ * @param body - `"earth"` or `"mars"`.
224
+ * @returns The approaches.
225
+ *
226
+ * @example
227
+ * ```ts
228
+ * import { roadsterApproaches } from "@johnmorrisdotca/wakusei-planets/roadster";
229
+ *
230
+ * for (const a of roadsterApproaches("mars")) console.log(new Date(a.date).toISOString().slice(0, 10), (a.distanceKm / 149597870.7).toFixed(3), "au");
231
+ * ```
232
+ */
233
+ export declare function roadsterApproaches(body: RoadsterBody): readonly RoadsterApproach[];
234
+ /**
235
+ * A distance in three units and the time a radio signal takes to cross it.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * import { roadsterStats, type RoadsterDistance } from "@johnmorrisdotca/wakusei-planets/roadster";
240
+ *
241
+ * const sun: RoadsterDistance = roadsterStats(Date.UTC(2026, 10, 11)).sun;
242
+ * console.log(sun.km, sun.miles, sun.au, sun.lightSeconds);
243
+ * ```
244
+ */
245
+ export interface RoadsterDistance {
246
+ /** Kilometres. */
247
+ km: number;
248
+ /** International miles. */
249
+ miles: number;
250
+ /** Astronomical units. */
251
+ au: number;
252
+ /** Seconds a radio signal (or light) takes to cross it. */
253
+ lightSeconds: number;
254
+ }
255
+ /**
256
+ * The closest approach before a moment and the next one after it, to one planet; `null` where the span holds none on that side.
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * import { roadsterStats, type RoadsterNeighbours } from "@johnmorrisdotca/wakusei-planets/roadster";
261
+ *
262
+ * const mars: RoadsterNeighbours = roadsterStats(Date.UTC(2026, 10, 11)).approaches.mars;
263
+ * console.log(mars.previous?.date, mars.next?.date);
264
+ * ```
265
+ */
266
+ export interface RoadsterNeighbours {
267
+ /** The latest approach at or before the moment, or `null`. */
268
+ previous: RoadsterApproach | null;
269
+ /** The earliest approach after the moment, or `null`. */
270
+ next: RoadsterApproach | null;
271
+ }
272
+ /**
273
+ * The numbers a page shows about the car at a moment.
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * import { roadsterStats, type RoadsterStats } from "@johnmorrisdotca/wakusei-planets/roadster";
278
+ *
279
+ * const stats: RoadsterStats = roadsterStats(Date.UTC(2026, 10, 11));
280
+ * console.log(stats.daysSinceLaunch.toFixed(0), "days since launch");
281
+ * ```
282
+ */
283
+ export interface RoadsterStats {
284
+ /** The moment, in milliseconds since 1970 (UTC). */
285
+ when: number;
286
+ /** Distance from the Sun's centre. */
287
+ sun: RoadsterDistance;
288
+ /** Distance from the Earth's centre. */
289
+ earth: RoadsterDistance;
290
+ /** Distance from Mars's centre. */
291
+ mars: RoadsterDistance;
292
+ /** Speed in kilometres a second relative to the Sun, the Earth and Mars. */
293
+ speed: {
294
+ sun: number;
295
+ earth: number;
296
+ mars: number;
297
+ };
298
+ /** Days since the launch (a fraction of a day counts). */
299
+ daysSinceLaunch: number;
300
+ /** The orbits of the Sun made since the launch, with the fraction of the one under way. */
301
+ orbits: number;
302
+ /** The orbits completed: `orbits` without its fraction. */
303
+ orbitsCompleted: number;
304
+ /** The period of the osculating orbit now, in days. */
305
+ periodDays: number;
306
+ /** The closest approaches before and after the moment, to the Earth and to Mars, inside the span. */
307
+ approaches: {
308
+ earth: RoadsterNeighbours;
309
+ mars: RoadsterNeighbours;
310
+ };
311
+ }
312
+ /**
313
+ * The car's numbers at a moment: its distance from the Sun, the Earth and Mars in kilometres, miles and astronomical units with the light time, its speed relative to each, the days since launch, the orbits of the Sun made, the period of its orbit now,
314
+ * and the closest approaches to the Earth and Mars before and after the moment inside the span. The Earth and Mars come from the package's own positions (`heliocentric`), with no allowance for the light's travel.
315
+ * A moment outside `ROADSTER.record` throws a `RangeError`.
316
+ *
317
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
318
+ * @returns The numbers.
319
+ *
320
+ * @example
321
+ * ```ts
322
+ * import { roadsterStats } from "@johnmorrisdotca/wakusei-planets/roadster";
323
+ *
324
+ * const stats = roadsterStats(new Date("2026-11-11T12:00:00Z"));
325
+ * console.log(Math.round(stats.earth.km / 1e6), "million km from the Earth,", stats.orbitsCompleted, "orbits of the Sun,", stats.speed.sun.toFixed(1), "km/s");
326
+ * ```
327
+ */
328
+ export declare function roadsterStats(when: When): RoadsterStats;
329
+ /**
330
+ * What kind of moment an event is: `"launch"`, `"earth-approach"`, `"mars-approach"`, `"perihelion"` or `"aphelion"`.
331
+ *
332
+ * @example
333
+ * ```ts
334
+ * import { roadsterEvents, type RoadsterEventKind } from "@johnmorrisdotca/wakusei-planets/roadster";
335
+ *
336
+ * const kind: RoadsterEventKind = "perihelion";
337
+ * console.log(roadsterEvents().filter((e) => e.kind === kind).length, "perihelia");
338
+ * ```
339
+ */
340
+ export type RoadsterEventKind = "launch" | "earth-approach" | "mars-approach" | "perihelion" | "aphelion";
341
+ /**
342
+ * A moment in the car's story that a page can jump to.
343
+ *
344
+ * @example
345
+ * ```ts
346
+ * import { roadsterEvents, type RoadsterEvent } from "@johnmorrisdotca/wakusei-planets/roadster";
347
+ *
348
+ * const first: RoadsterEvent = roadsterEvents()[0]!;
349
+ * console.log(first.kind, new Date(first.date).toISOString(), first.name.en);
350
+ * ```
351
+ */
352
+ export interface RoadsterEvent {
353
+ /** What happened. */
354
+ kind: RoadsterEventKind;
355
+ /** When, in milliseconds since 1970 (UTC). */
356
+ date: number;
357
+ /** The name in English and Japanese. */
358
+ name: RoadsterName;
359
+ /** The distance in kilometres that goes with the moment: from the planet at a close approach, from the Sun at a perihelion or an aphelion. The launch has none. */
360
+ distanceKm?: number;
361
+ }
362
+ /**
363
+ * Every moment of the car's story the table can find, in date order, each with a name in English and Japanese: the launch, each closest approach to the Earth and to Mars, and each perihelion and aphelion passage inside the span.
364
+ * A page can list them and jump to any one. The answer is the same every time, so it is worked out once and kept.
365
+ *
366
+ * @returns The events.
367
+ *
368
+ * @example
369
+ * ```ts
370
+ * import { roadsterEvents } from "@johnmorrisdotca/wakusei-planets/roadster";
371
+ *
372
+ * for (const e of roadsterEvents().slice(0, 5)) console.log(new Date(e.date).toISOString().slice(0, 10), e.name.en);
373
+ * ```
374
+ */
375
+ export declare function roadsterEvents(): readonly RoadsterEvent[];
376
+ /**
377
+ * The car's distances and speed sampled over a stretch of time, for a chart: one entry in each array for each moment in `times`.
378
+ *
379
+ * @example
380
+ * ```ts
381
+ * import { roadsterSeries, type RoadsterSeries } from "@johnmorrisdotca/wakusei-planets/roadster";
382
+ *
383
+ * const series: RoadsterSeries = roadsterSeries(Date.UTC(2020, 0, 1), Date.UTC(2021, 0, 1), 86_400_000);
384
+ * console.log(series.times.length, "days");
385
+ * ```
386
+ */
387
+ export interface RoadsterSeries {
388
+ /** The moments, in milliseconds since 1970 (UTC), from the start to the end at the step (the end is included when the step lands on it). */
389
+ times: number[];
390
+ /** Distance from the Sun, in kilometres. */
391
+ sunKm: number[];
392
+ /** Distance from the Earth, in kilometres. */
393
+ earthKm: number[];
394
+ /** Distance from Mars, in kilometres. */
395
+ marsKm: number[];
396
+ /** Speed relative to the Sun, in kilometres a second. */
397
+ speed: number[];
398
+ }
399
+ /**
400
+ * The car's distance from the Sun, the Earth and Mars, and its speed relative to the Sun, at equal steps from one moment to another, ready to graph. Both ends must be inside `ROADSTER.record`; a step that is not positive, or a series of more than 100,000 moments, throws a `RangeError`.
401
+ *
402
+ * @param from - The first moment: a `Date` or milliseconds since 1970 (UTC).
403
+ * @param to - The last moment, not before the first.
404
+ * @param stepMs - The step in milliseconds.
405
+ * @returns The series.
406
+ *
407
+ * @example
408
+ * ```ts
409
+ * import { roadsterSeries } from "@johnmorrisdotca/wakusei-planets/roadster";
410
+ *
411
+ * const { times, earthKm } = roadsterSeries(new Date("2019-01-01T00:00:00Z"), new Date("2020-01-01T00:00:00Z"), 7 * 86_400_000);
412
+ * console.log(times.length, "weeks; nearest", Math.round(Math.min(...earthKm) / 1e6), "million km from the Earth");
413
+ * ```
414
+ */
415
+ export declare function roadsterSeries(from: When, to: When, stepMs: number): RoadsterSeries;