@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,2 @@
1
+ export { planAt, planRadius, planSunExtent, PLAN_AU_KM, PLAN_SYSTEMS, type Plan, type PlanDot, type PlanExtra, type PlanKind, type PlanOptions, type PlanOrbit, type PlanSpacing, type PlanSystem } from "./layout.ts";
2
+ export { PLAN_FONT, planName, planSvg, planText, type PlanDrawOptions, type PlanLang, type PlanMeasure, type PlanText } from "./svg.ts";
@@ -0,0 +1,2 @@
1
+ export { planAt, planRadius, planSunExtent, PLAN_AU_KM, PLAN_SYSTEMS } from "./layout.js";
2
+ export { PLAN_FONT, planName, planSvg, planText } from "./svg.js";
@@ -0,0 +1,230 @@
1
+ import { MOONS_OF } from "../facts.ts";
2
+ import { type Vec3 } from "../vec.ts";
3
+ /**
4
+ * Which plan to draw: `"sun"` for the solar system from above, or a planet or dwarf planet that has moons (`earth`, `mars`, `jupiter`, `saturn`, `uranus`, `neptune`, `pluto`, `orcus`, `haumea`, `eris`) for its moons from above its north pole.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import type { PlanSystem } from "@johnmorrisdotca/wakusei-planets/plan";
9
+ *
10
+ * const system: PlanSystem = "jupiter";
11
+ * console.log(system);
12
+ * ```
13
+ */
14
+ export type PlanSystem = "sun" | keyof typeof MOONS_OF;
15
+ /**
16
+ * Every system a plan can show: the Sun first, then each planet or dwarf planet that has moons, nearest the Sun first.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { PLAN_SYSTEMS } from "@johnmorrisdotca/wakusei-planets/plan";
21
+ *
22
+ * console.log(PLAN_SYSTEMS.join(", "));
23
+ * ```
24
+ */
25
+ export declare const PLAN_SYSTEMS: readonly PlanSystem[];
26
+ /**
27
+ * How distances are drawn: `squeezed` (the default) puts a body at the logarithm of its distance, so Mercury and Neptune both show in a small picture, and `true` puts it at its real distance in proportion, which crowds the inner bodies near the middle.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import type { PlanSpacing } from "@johnmorrisdotca/wakusei-planets/plan";
32
+ *
33
+ * const spacing: PlanSpacing = "squeezed";
34
+ * console.log(spacing);
35
+ * ```
36
+ */
37
+ export type PlanSpacing = "squeezed" | "true";
38
+ /**
39
+ * What a dot is: the Sun (`star`), a `planet`, a `dwarf-planet`, a `moon`, an `asteroid`, a `centaur`, a `comet`, or a `spacecraft` handed in with `extras`.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import type { PlanKind } from "@johnmorrisdotca/wakusei-planets/plan";
44
+ *
45
+ * const kind: PlanKind = "comet";
46
+ * console.log(kind);
47
+ * ```
48
+ */
49
+ export type PlanKind = "star" | "planet" | "dwarf-planet" | "moon" | "asteroid" | "centaur" | "comet" | "spacecraft";
50
+ /**
51
+ * One body on the plan: where it is in the unit disc (x to the right, y up, the edge at 1), its real distance from the middle, and whether it is the one marked.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { planAt, type PlanDot } from "@johnmorrisdotca/wakusei-planets/plan";
56
+ *
57
+ * const earth: PlanDot = planAt(Date.UTC(2026, 10, 11)).dots.find((dot) => dot.id === "earth")!;
58
+ * console.log(earth.distance.toFixed(2), "au", earth.kind);
59
+ * ```
60
+ */
61
+ export interface PlanDot {
62
+ id: string;
63
+ kind: PlanKind;
64
+ /** Across the unit disc, to the right. */
65
+ x: number;
66
+ /** Up the unit disc. */
67
+ y: number;
68
+ /** The distance from the middle in astronomical units (the solar system) or the planet's radii (a moon system). */
69
+ distance: number;
70
+ /** The one the plan is about. */
71
+ marked: boolean;
72
+ /** Further out than the edge of the plan: the dot is held on the edge. */
73
+ beyond: boolean;
74
+ }
75
+ /**
76
+ * The path of one body round the middle, as points in the unit disc. Points beyond the edge are kept, so a long orbit is cut by the edge and not squashed into it.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { planAt, type PlanOrbit } from "@johnmorrisdotca/wakusei-planets/plan";
81
+ *
82
+ * const orbit: PlanOrbit = planAt(Date.UTC(2026, 10, 11)).orbits[0]!;
83
+ * console.log(orbit.id, orbit.points.length);
84
+ * ```
85
+ */
86
+ export interface PlanOrbit {
87
+ id: string;
88
+ /** The orbit of the body the plan is about. */
89
+ marked: boolean;
90
+ points: readonly (readonly [number, number])[];
91
+ }
92
+ /**
93
+ * A plan: what to draw for a moment, in the unit disc. `unit` says what `extent` and each dot's `distance` count.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * import { planAt, type Plan } from "@johnmorrisdotca/wakusei-planets/plan";
98
+ *
99
+ * const plan: Plan = planAt(Date.UTC(2026, 10, 11), { system: "jupiter", mark: "io" });
100
+ * console.log(plan.unit, plan.extent.toFixed(1), plan.dots.length);
101
+ * ```
102
+ */
103
+ export interface Plan {
104
+ system: PlanSystem;
105
+ /** The moment, in milliseconds since 1970 (UTC). */
106
+ time: number;
107
+ spacing: PlanSpacing;
108
+ /** `au` for the solar system, `radii` (the planet's equatorial radii) for a moon system. */
109
+ unit: "au" | "radii";
110
+ /** The distance at the edge of the plan, in `unit`. */
111
+ extent: number;
112
+ /** The distance squeezed spacing treats as near the middle; with `extent` it fixes the logarithm. */
113
+ inner: number;
114
+ /** The Sun, or the planet the moons go round, at the middle. */
115
+ centre: PlanDot;
116
+ /** The bodies round the middle. */
117
+ dots: PlanDot[];
118
+ /** The path of each body round the middle. */
119
+ orbits: PlanOrbit[];
120
+ /** The id of the body marked, or `undefined`. */
121
+ marked: string | undefined;
122
+ }
123
+ /**
124
+ * A body the package has no position for, handed in by the page: a craft from `/spacecraft`, say.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * import type { PlanExtra } from "@johnmorrisdotca/wakusei-planets/plan";
129
+ *
130
+ * const probe: PlanExtra = { id: "voyager1", au: [-40, -120, 90], kind: "spacecraft" };
131
+ * console.log(probe.id);
132
+ * ```
133
+ */
134
+ export interface PlanExtra {
135
+ id: string;
136
+ /** Its place from the Sun in the J2000 ecliptic frame, in astronomical units (kilometres over 149,597,870.7). Only the solar-system plan draws it. */
137
+ au: Vec3;
138
+ /** Default `spacecraft`. */
139
+ kind?: PlanKind;
140
+ }
141
+ /**
142
+ * What `planAt` is asked: the system, the body to mark, the spacing, and any extra bodies.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * import type { PlanOptions } from "@johnmorrisdotca/wakusei-planets/plan";
147
+ *
148
+ * const options: PlanOptions = { system: "saturn", mark: "titan", spacing: "squeezed" };
149
+ * console.log(options.mark);
150
+ * ```
151
+ */
152
+ export interface PlanOptions {
153
+ /** Default `sun`. */
154
+ system?: PlanSystem;
155
+ /** The body the plan is about. In the solar system a moon marks its planet; in a moon system a moon of another planet marks nothing. */
156
+ mark?: string;
157
+ /** Default `squeezed`. */
158
+ spacing?: PlanSpacing;
159
+ /** Bodies of your own, such as a craft's place. */
160
+ extras?: readonly PlanExtra[];
161
+ }
162
+ /**
163
+ * Where a distance goes on the plan, 0 at the middle and 1 at the edge. Squeezed is `ln(1 + d / inner) / ln(1 + extent / inner)`, which spreads the inner bodies a good deal and the outer ones a little; true is `d / extent`.
164
+ *
165
+ * @param distance - The distance from the middle, in the plan's unit.
166
+ * @param extent - The distance at the edge.
167
+ * @param spacing - `squeezed` or `true`.
168
+ * @param inner - The distance squeezed spacing treats as near the middle.
169
+ * @returns The place on the radius: 0 to 1 within the edge, more beyond it.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * import { planRadius } from "@johnmorrisdotca/wakusei-planets/plan";
174
+ *
175
+ * console.log(planRadius(1, 50, "squeezed", 0.1).toFixed(2), planRadius(1, 50, "true", 0.1).toFixed(2));
176
+ * ```
177
+ */
178
+ export declare function planRadius(distance: number, extent: number, spacing: PlanSpacing, inner: number): number;
179
+ /**
180
+ * The reach of the solar-system plan that holds a farthest body: the smallest of 50, 100, 200, 500, 1,000 and 2,000 au that is at least `farthest` (2,000 beyond that).
181
+ *
182
+ * @param farthest - The distance of the farthest dot, in au.
183
+ * @returns The distance at the edge, in au.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * import { planSunExtent } from "@johnmorrisdotca/wakusei-planets/plan";
188
+ *
189
+ * console.log(planSunExtent(30), planSunExtent(83), planSunExtent(170));
190
+ * ```
191
+ */
192
+ export declare function planSunExtent(farthest: number): number;
193
+ /**
194
+ * The plan for a moment: the solar system seen from above the ecliptic's north pole (x toward the March equinox, planets going anticlockwise), or one planet's moons seen from above its north pole. Every position is the package's own (VSOP87B,
195
+ * the fitted tables, the moon theories) for `time`, with no allowance for light's travel. The orbit lines are cut once a year in the solar system and once a week for moons, which is finer than a pixel; the dots are exact.
196
+ *
197
+ * The solar-system plan holds the eight planets and Pluto, and the body marked if it is a dwarf planet or a minor body (and any `extras`), and stands at the smallest of 50, 100, 200, 500, 1,000 and 2,000 au that holds them all.
198
+ * A moon system holds every moon of the planet and stands a little past the furthest of them. A moon system is seen from above the planet's IAU north pole, so a planet that spins backward about it (Uranus) has its moons go clockwise.
199
+ * Pluto comes from its fitted table. The other dwarf planets and the minor bodies come from the osculating elements of one epoch, unless you have imported `@johnmorrisdotca/wakusei-planets/tables` (or `/tables/ceres`, `/tables/dwarfs`, `/tables/minor`), which fit them to Horizons; `<wakusei-plan>` imports the one it needs when such a body is marked.
200
+ * `mark` is read in lower case. A `system` that is not in `PLAN_SYSTEMS` throws a `RangeError` that lists them.
201
+ *
202
+ * @param time - The moment, in milliseconds since 1970 (UTC).
203
+ * @param options - The system, the body to mark, the spacing and any extras.
204
+ * @returns The plan.
205
+ * @throws RangeError when `options.system` is not one of `PLAN_SYSTEMS`.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * import { planAt } from "@johnmorrisdotca/wakusei-planets/plan";
210
+ *
211
+ * const sky = planAt(Date.UTC(2026, 10, 11), { mark: "mars" });
212
+ * const mars = sky.dots.find((dot) => dot.id === "mars")!;
213
+ * console.log(sky.extent, mars.marked, mars.distance.toFixed(2), "au");
214
+ *
215
+ * const jupiter = planAt(Date.UTC(2026, 10, 11), { system: "jupiter", mark: "io" });
216
+ * console.log(jupiter.dots.map((dot) => dot.id).join(", "));
217
+ * ```
218
+ */
219
+ export declare function planAt(time: number, options?: PlanOptions): Plan;
220
+ /**
221
+ * Kilometres in an astronomical unit, for turning a craft's place from `/spacecraft` (kilometres) into the astronomical units `PlanExtra` takes.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * import { PLAN_AU_KM } from "@johnmorrisdotca/wakusei-planets/plan";
226
+ *
227
+ * console.log((PLAN_AU_KM / 1e6).toFixed(1), "million km");
228
+ * ```
229
+ */
230
+ export declare const PLAN_AU_KM = 149597870.7;
@@ -0,0 +1,229 @@
1
+ // The plan: where the bodies are on a top-down map, from the package's own positions. Two systems: the solar system seen from above the ecliptic's north pole, and one planet's moons seen from above that planet's north pole.
2
+ // Distances are squeezed (a logarithm, so the inner planets and the outer ones both show in a few hundred pixels) or true. Pure: numbers in, numbers out; no DOM, no clock.
3
+ import { ORBITS } from "../data/orbits.js";
4
+ import { heliocentric, heliocentricModel, moonVector } from "../ephemeris.js";
5
+ import { BODIES, MOONS_OF, PLANET_IDS } from "../facts.js";
6
+ import { planetOrbit, SPACE_DWARFS, SPACE_MINORS } from "../space/frame.js";
7
+ import { cross, dot, fromRaDec, toEcliptic } from "../vec.js";
8
+ const DAY = 86_400_000;
9
+ const AU_KM = 149_597_870.7;
10
+ /**
11
+ * Every system a plan can show: the Sun first, then each planet or dwarf planet that has moons, nearest the Sun first.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { PLAN_SYSTEMS } from "@johnmorrisdotca/wakusei-planets/plan";
16
+ *
17
+ * console.log(PLAN_SYSTEMS.join(", "));
18
+ * ```
19
+ */
20
+ export const PLAN_SYSTEMS = ["sun", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto", "orcus", "haumea", "eris"];
21
+ /** The reaches the solar-system plan steps through, in au: the plan is the smallest of them that holds every dot, so a mark that goes further out redraws the scale in whole steps and the planets keep their places in between. */
22
+ const SUN_EXTENTS = [50, 100, 200, 500, 1000, 2000];
23
+ /** The distance, in au, squeezed spacing treats as close to the Sun: Mercury is then about a quarter of the way out and Neptune nine tenths. */
24
+ const SUN_INNER = 0.1;
25
+ /** A moon system's inner scale, in the planet's radii. */
26
+ const MOON_INNER = 1;
27
+ /** A moon system's edge is this far past its furthest moon at its furthest. */
28
+ const MOON_MARGIN = 1.08;
29
+ /** The points of each orbit line. */
30
+ const ORBIT_POINTS = 96;
31
+ /** How long an orbit line stands before it is cut again: a planet's path changes less than a pixel in a year, a moon's in a week. */
32
+ const SUN_BUCKET = 365.25 * DAY;
33
+ const MOON_BUCKET = 7 * DAY;
34
+ /**
35
+ * Where a distance goes on the plan, 0 at the middle and 1 at the edge. Squeezed is `ln(1 + d / inner) / ln(1 + extent / inner)`, which spreads the inner bodies a good deal and the outer ones a little; true is `d / extent`.
36
+ *
37
+ * @param distance - The distance from the middle, in the plan's unit.
38
+ * @param extent - The distance at the edge.
39
+ * @param spacing - `squeezed` or `true`.
40
+ * @param inner - The distance squeezed spacing treats as near the middle.
41
+ * @returns The place on the radius: 0 to 1 within the edge, more beyond it.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import { planRadius } from "@johnmorrisdotca/wakusei-planets/plan";
46
+ *
47
+ * console.log(planRadius(1, 50, "squeezed", 0.1).toFixed(2), planRadius(1, 50, "true", 0.1).toFixed(2));
48
+ * ```
49
+ */
50
+ export function planRadius(distance, extent, spacing, inner) {
51
+ const d = Math.max(0, distance);
52
+ return spacing === "true" ? d / extent : Math.log1p(d / inner) / Math.log1p(extent / inner);
53
+ }
54
+ /**
55
+ * The reach of the solar-system plan that holds a farthest body: the smallest of 50, 100, 200, 500, 1,000 and 2,000 au that is at least `farthest` (2,000 beyond that).
56
+ *
57
+ * @param farthest - The distance of the farthest dot, in au.
58
+ * @returns The distance at the edge, in au.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { planSunExtent } from "@johnmorrisdotca/wakusei-planets/plan";
63
+ *
64
+ * console.log(planSunExtent(30), planSunExtent(83), planSunExtent(170));
65
+ * ```
66
+ */
67
+ export function planSunExtent(farthest) {
68
+ return SUN_EXTENTS.find((step) => step >= farthest) ?? SUN_EXTENTS[SUN_EXTENTS.length - 1];
69
+ }
70
+ const orbitCache = new Map();
71
+ const remember = (key, make) => {
72
+ let found = orbitCache.get(key);
73
+ if (found === undefined) {
74
+ if (orbitCache.size > 400)
75
+ orbitCache.clear();
76
+ found = make();
77
+ orbitCache.set(key, found);
78
+ }
79
+ return found;
80
+ };
81
+ const SUN_BODIES = [...PLANET_IDS];
82
+ /** A body in the solar-system plan: a planet, a dwarf planet or a minor body, or a moon's planet. */
83
+ const sunBodyOf = (id) => {
84
+ if (id === "sun")
85
+ return "sun";
86
+ const facts = BODIES[id];
87
+ if (facts === undefined)
88
+ return undefined;
89
+ if (facts.kind === "moon")
90
+ return facts.parent ?? "earth";
91
+ return facts.kind === "star" ? "sun" : id;
92
+ };
93
+ /** A heliocentric orbit, as points in the ecliptic plane in au: a trip round the Sun from the start of the year or so the moment is in. */
94
+ function sunOrbit(id, time) {
95
+ const bucket = Math.floor(time / SUN_BUCKET);
96
+ // the theory is in the key: a table imported after the first draw gives a better line than the elements it replaces
97
+ return remember(`${id}|${bucket}|${heliocentricModel(id, time).theory}`, () => planetOrbit(id, bucket * SUN_BUCKET, ORBIT_POINTS).map((p) => {
98
+ // planetOrbit answers in the scene's axes (J2000 equatorial with y north and z toward the viewer): back to equatorial, then to the ecliptic
99
+ const ecliptic = toEcliptic([p[0], -p[2], p[1]]);
100
+ return [ecliptic[0], ecliptic[1]];
101
+ }));
102
+ }
103
+ /** The axes of a planet's north pole as seen in the J2000 ecliptic: x along its equator, y a quarter turn on, z up its pole. */
104
+ function poleBasis(host) {
105
+ const { ra, dec } = BODIES[host].pole;
106
+ const z = toEcliptic(fromRaDec(ra, dec));
107
+ const x = toEcliptic(fromRaDec(ra + 90, 0));
108
+ return { x, y: cross(z, x), z };
109
+ }
110
+ /** A moon's place from its planet, in the planet's radii, in the view from above its north pole. */
111
+ function overPole(host, id, time) {
112
+ const basis = poleBasis(host);
113
+ const v = moonVector(id, time);
114
+ const radius = BODIES[host].radiusKm;
115
+ return [dot(v, basis.x) / radius, dot(v, basis.y) / radius];
116
+ }
117
+ /** One moon's orbit round its planet in the planet's radii, one trip from the week the moment is in. */
118
+ function moonOrbit(host, id, time) {
119
+ const bucket = Math.floor(time / MOON_BUCKET);
120
+ return remember(`${host}:${id}|${bucket}`, () => {
121
+ const rate = ORBITS[id]?.sid;
122
+ if (rate === undefined || rate === 0)
123
+ return [];
124
+ const start = bucket * MOON_BUCKET;
125
+ const period = (360 / Math.abs(rate)) * DAY;
126
+ const points = [];
127
+ for (let k = 0; k <= ORBIT_POINTS; k += 1)
128
+ points.push(overPole(host, id, start + (k / ORBIT_POINTS) * period));
129
+ return points;
130
+ });
131
+ }
132
+ /** The farthest a moon goes from its planet, in the planet's radii. */
133
+ function reachOf(host, id) {
134
+ const radius = BODIES[host].radiusKm;
135
+ if (id === "moon")
136
+ return (405_500 / radius);
137
+ const orbit = ORBITS[id];
138
+ return orbit === undefined ? 0 : (orbit.a * (1 + orbit.e)) / radius;
139
+ }
140
+ const squeeze = (point, extent, spacing, inner) => {
141
+ const d = Math.hypot(point[0], point[1]);
142
+ if (d === 0)
143
+ return [0, 0];
144
+ const k = planRadius(d, extent, spacing, inner) / d;
145
+ return [point[0] * k, point[1] * k];
146
+ };
147
+ const place = (id, kind, point, extent, spacing, inner, marked) => {
148
+ const distance = Math.hypot(point[0], point[1]);
149
+ const at = squeeze(point, extent, spacing, inner);
150
+ const r = Math.hypot(at[0], at[1]);
151
+ const beyond = r > 1;
152
+ return { id, kind, x: beyond ? at[0] / r : at[0], y: beyond ? at[1] / r : at[1], distance, marked, beyond };
153
+ };
154
+ /**
155
+ * The plan for a moment: the solar system seen from above the ecliptic's north pole (x toward the March equinox, planets going anticlockwise), or one planet's moons seen from above its north pole. Every position is the package's own (VSOP87B,
156
+ * the fitted tables, the moon theories) for `time`, with no allowance for light's travel. The orbit lines are cut once a year in the solar system and once a week for moons, which is finer than a pixel; the dots are exact.
157
+ *
158
+ * The solar-system plan holds the eight planets and Pluto, and the body marked if it is a dwarf planet or a minor body (and any `extras`), and stands at the smallest of 50, 100, 200, 500, 1,000 and 2,000 au that holds them all.
159
+ * A moon system holds every moon of the planet and stands a little past the furthest of them. A moon system is seen from above the planet's IAU north pole, so a planet that spins backward about it (Uranus) has its moons go clockwise.
160
+ * Pluto comes from its fitted table. The other dwarf planets and the minor bodies come from the osculating elements of one epoch, unless you have imported `@johnmorrisdotca/wakusei-planets/tables` (or `/tables/ceres`, `/tables/dwarfs`, `/tables/minor`), which fit them to Horizons; `<wakusei-plan>` imports the one it needs when such a body is marked.
161
+ * `mark` is read in lower case. A `system` that is not in `PLAN_SYSTEMS` throws a `RangeError` that lists them.
162
+ *
163
+ * @param time - The moment, in milliseconds since 1970 (UTC).
164
+ * @param options - The system, the body to mark, the spacing and any extras.
165
+ * @returns The plan.
166
+ * @throws RangeError when `options.system` is not one of `PLAN_SYSTEMS`.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * import { planAt } from "@johnmorrisdotca/wakusei-planets/plan";
171
+ *
172
+ * const sky = planAt(Date.UTC(2026, 10, 11), { mark: "mars" });
173
+ * const mars = sky.dots.find((dot) => dot.id === "mars")!;
174
+ * console.log(sky.extent, mars.marked, mars.distance.toFixed(2), "au");
175
+ *
176
+ * const jupiter = planAt(Date.UTC(2026, 10, 11), { system: "jupiter", mark: "io" });
177
+ * console.log(jupiter.dots.map((dot) => dot.id).join(", "));
178
+ * ```
179
+ */
180
+ export function planAt(time, options = {}) {
181
+ const system = options.system ?? "sun";
182
+ if (!PLAN_SYSTEMS.includes(system))
183
+ throw new RangeError(`unknown plan system ${JSON.stringify(system)}; expected one of ${PLAN_SYSTEMS.join(", ")}`);
184
+ if (options.mark !== undefined)
185
+ options = { ...options, mark: options.mark.trim().toLowerCase() };
186
+ const spacing = options.spacing === "true" ? "true" : "squeezed";
187
+ return system === "sun" ? sunPlan(time, options, spacing) : moonPlan(time, system, options, spacing);
188
+ }
189
+ function sunPlan(time, options, spacing) {
190
+ const wanted = options.mark === undefined ? undefined : sunBodyOf(options.mark) ?? ((options.extras ?? []).some((one) => one.id === options.mark) ? options.mark : undefined);
191
+ const ids = [...SUN_BODIES];
192
+ if (wanted !== undefined && wanted !== "sun" && !ids.includes(wanted) && (SPACE_DWARFS.includes(wanted) || SPACE_MINORS.includes(wanted)))
193
+ ids.push(wanted);
194
+ const raw = [];
195
+ for (const id of ids) {
196
+ const v = heliocentric(id, time);
197
+ raw.push({ id, kind: BODIES[id].kind, point: [v[0], v[1]] });
198
+ }
199
+ for (const extra of options.extras ?? [])
200
+ raw.push({ id: extra.id, kind: extra.kind ?? "spacecraft", point: [extra.au[0], extra.au[1]] });
201
+ // the plan is a view from above, so a body's distance is its distance in the ecliptic plane: its height does not push the edge out
202
+ const farthest = Math.max(...raw.map((one) => Math.hypot(one.point[0], one.point[1])));
203
+ const extent = planSunExtent(farthest);
204
+ const dots = raw.map((one) => place(one.id, one.kind, one.point, extent, spacing, SUN_INNER, one.id === wanted));
205
+ const orbits = ids
206
+ .map((id) => ({ id, marked: id === wanted, points: sunOrbit(id, time).map((p) => squeeze(p, extent, spacing, SUN_INNER)) }));
207
+ const centre = { id: "sun", kind: "star", x: 0, y: 0, distance: 0, marked: wanted === "sun", beyond: false };
208
+ return { system: "sun", time, spacing, unit: "au", extent, inner: SUN_INNER, centre, dots: dots.sort((a, b) => Number(a.marked) - Number(b.marked)), orbits: orbits.sort((a, b) => Number(a.marked) - Number(b.marked)), marked: wanted };
209
+ }
210
+ function moonPlan(time, host, options, spacing) {
211
+ const moons = MOONS_OF[host];
212
+ const wanted = options.mark !== undefined && (options.mark === host || moons.includes(options.mark)) ? options.mark : undefined;
213
+ const extent = Math.max(...moons.map((id) => reachOf(host, id))) * MOON_MARGIN;
214
+ const dots = moons.map((id) => place(id, "moon", overPole(host, id, time), extent, spacing, MOON_INNER, id === wanted));
215
+ const orbits = moons.map((id) => ({ id, marked: id === wanted, points: moonOrbit(host, id, time).map((p) => squeeze(p, extent, spacing, MOON_INNER)) }));
216
+ const centre = { id: host, kind: BODIES[host].kind, x: 0, y: 0, distance: 0, marked: wanted === host, beyond: false };
217
+ return { system: host, time, spacing, unit: "radii", extent, inner: MOON_INNER, centre, dots: dots.sort((a, b) => Number(a.marked) - Number(b.marked)), orbits: orbits.sort((a, b) => Number(a.marked) - Number(b.marked)), marked: wanted };
218
+ }
219
+ /**
220
+ * Kilometres in an astronomical unit, for turning a craft's place from `/spacecraft` (kilometres) into the astronomical units `PlanExtra` takes.
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * import { PLAN_AU_KM } from "@johnmorrisdotca/wakusei-planets/plan";
225
+ *
226
+ * console.log((PLAN_AU_KM / 1e6).toFixed(1), "million km");
227
+ * ```
228
+ */
229
+ export const PLAN_AU_KM = AU_KM;
@@ -0,0 +1,125 @@
1
+ import type { Plan } from "./layout.ts";
2
+ /**
3
+ * A language the plan's words can be in: `en` or `ja`.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import type { PlanLang } from "@johnmorrisdotca/wakusei-planets/plan";
8
+ *
9
+ * const lang: PlanLang = "ja";
10
+ * console.log(lang);
11
+ * ```
12
+ */
13
+ export type PlanLang = "en" | "ja";
14
+ /**
15
+ * The words a plan says besides names: its label for a screen reader and the line saying how distances are drawn.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import type { PlanText } from "@johnmorrisdotca/wakusei-planets/plan";
20
+ *
21
+ * const text: PlanText = { label: "The solar system from above", scale: "Squeezed (log) to 50 au" };
22
+ * console.log(text.scale);
23
+ * ```
24
+ */
25
+ export interface PlanText {
26
+ /** What the picture is, for a screen reader: "The solar system from above, Mars marked". */
27
+ label: string;
28
+ /** How distances are drawn and how far the edge is: "Squeezed (log) to 50 au". */
29
+ scale: string;
30
+ }
31
+ /**
32
+ * 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.
33
+ *
34
+ * @param id - A body's id.
35
+ * @param lang - `en` or `ja`.
36
+ * @returns The name.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { planName } from "@johnmorrisdotca/wakusei-planets/plan";
41
+ *
42
+ * console.log(planName("jupiter", "en"), planName("jupiter", "ja"), planName("voyager1", "en"));
43
+ * ```
44
+ */
45
+ export declare function planName(id: string, lang?: PlanLang): string;
46
+ /**
47
+ * The words a plan says besides names, in a language.
48
+ *
49
+ * @param plan - The plan.
50
+ * @param lang - `en` or `ja`.
51
+ * @returns The label for a screen reader and the scale line.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { planAt, planText } from "@johnmorrisdotca/wakusei-planets/plan";
56
+ *
57
+ * const plan = planAt(Date.UTC(2026, 10, 11), { system: "jupiter", mark: "io", spacing: "true" });
58
+ * console.log(planText(plan, "en"));
59
+ * ```
60
+ */
61
+ export declare function planText(plan: Plan, lang?: PlanLang): PlanText;
62
+ /**
63
+ * How a plan is drawn: the picture's side in pixels, the language of the names, whether names show, and a prefix for the ids inside the SVG (two plans on one page need two).
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import type { PlanDrawOptions } from "@johnmorrisdotca/wakusei-planets/plan";
68
+ *
69
+ * const options: PlanDrawOptions = { size: 240, lang: "en", names: true };
70
+ * console.log(options.size);
71
+ * ```
72
+ */
73
+ export interface PlanDrawOptions {
74
+ /** The picture's side in CSS pixels. Default 240. */
75
+ size?: number;
76
+ /** Default `en`. */
77
+ lang?: PlanLang;
78
+ /** Whether names are written beside the dots (the marked body's is always written). Default true. */
79
+ names?: boolean;
80
+ /** Prefixes the ids inside the SVG. Default `wp`. */
81
+ id?: string;
82
+ /** Measures text in the type the plan is drawn in (the element does, so a machine whose fallback font is wider or taller than the one assumed still gets names that do not overlap). Default: an estimate by character. */
83
+ measure?: PlanMeasure;
84
+ }
85
+ /**
86
+ * 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.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import { PLAN_FONT } from "@johnmorrisdotca/wakusei-planets/plan";
91
+ *
92
+ * console.log(PLAN_FONT.startsWith("10px"));
93
+ * ```
94
+ */
95
+ export declare const PLAN_FONT = "10px system-ui,-apple-system,'Segoe UI','Hiragino Sans','Noto Sans JP',sans-serif";
96
+ /**
97
+ * How wide a piece of text is in the type it is drawn in, in pixels: `bold` for the marked body's name.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * import type { PlanMeasure } from "@johnmorrisdotca/wakusei-planets/plan";
102
+ *
103
+ * const sixPixelsALetter: PlanMeasure = (text) => text.length * 6;
104
+ * console.log(sixPixelsALetter("Mars", false));
105
+ * ```
106
+ */
107
+ export type PlanMeasure = (text: string, bold: boolean) => number;
108
+ /**
109
+ * 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
110
+ * 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`)
111
+ * that default to the family's and follow light and dark with the page's `color-scheme`.
112
+ *
113
+ * @param plan - The plan from `planAt`.
114
+ * @param options - The size, the language and whether names show.
115
+ * @returns The SVG text.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * import { planAt, planSvg } from "@johnmorrisdotca/wakusei-planets/plan";
120
+ *
121
+ * const svg = planSvg(planAt(Date.UTC(2026, 10, 11), { mark: "mars" }), { size: 240, lang: "en" });
122
+ * console.log(svg.startsWith("<svg"), svg.includes('data-id="mars"'));
123
+ * ```
124
+ */
125
+ export declare function planSvg(plan: Plan, options?: PlanDrawOptions): string;