@johnmorrisdotca/wakusei-planets 0.35.0 → 0.37.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 (49) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/NOTICE.md +31 -1
  3. package/README.md +5 -4
  4. package/dist/data/moon-catalogue.d.ts +31 -0
  5. package/dist/data/moon-catalogue.js +471 -0
  6. package/dist/data/orbiters.d.ts +368 -0
  7. package/dist/data/orbiters.js +370 -0
  8. package/dist/data/places-planned.d.ts +3 -0
  9. package/dist/data/places-planned.js +51 -0
  10. package/dist/element.d.ts +28 -0
  11. package/dist/element.js +172 -1
  12. package/dist/moon-catalogue.d.ts +296 -0
  13. package/dist/moon-catalogue.js +234 -0
  14. package/dist/orbiter-facts.d.ts +480 -0
  15. package/dist/orbiter-facts.js +189 -0
  16. package/dist/orbiters.d.ts +256 -0
  17. package/dist/orbiters.js +275 -0
  18. package/dist/place-marks.d.ts +182 -0
  19. package/dist/place-marks.js +194 -0
  20. package/dist/places/mars.d.ts +1 -1
  21. package/dist/places/mars.js +4 -2
  22. package/dist/places/moon.d.ts +1 -1
  23. package/dist/places/moon.js +4 -2
  24. package/dist/places.d.ts +4 -2
  25. package/dist/places.js +2 -0
  26. package/dist/scene/place-layer.d.ts +68 -0
  27. package/dist/scene/place-layer.js +213 -0
  28. package/dist/scene/textures.d.ts +2 -2
  29. package/dist/space/all-moons.d.ts +30 -0
  30. package/dist/space/all-moons.js +61 -0
  31. package/dist/space/bodies.d.ts +18 -0
  32. package/dist/space/bodies.js +18 -0
  33. package/dist/space/element.d.ts +182 -6
  34. package/dist/space/element.js +763 -26
  35. package/dist/space/frame.d.ts +14 -0
  36. package/dist/space/frame.js +16 -0
  37. package/dist/space/index.d.ts +5 -2
  38. package/dist/space/index.js +5 -2
  39. package/dist/space/regions.d.ts +111 -0
  40. package/dist/space/regions.js +84 -0
  41. package/dist/space/scene.d.ts +131 -8
  42. package/dist/space/scene.js +312 -15
  43. package/dist/space/sight.d.ts +106 -0
  44. package/dist/space/sight.js +84 -0
  45. package/dist/space/travel.d.ts +256 -0
  46. package/dist/space/travel.js +597 -0
  47. package/dist/version.d.ts +1 -1
  48. package/dist/version.js +1 -1
  49. package/package.json +13 -2
@@ -1,6 +1,6 @@
1
1
  import type { Place } from "../places.ts";
2
2
  /**
3
- * Every place on the Moon the package knows: the sites first, by date, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
3
+ * 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).
4
4
  *
5
5
  * @example
6
6
  * ```ts
@@ -1,7 +1,9 @@
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 { PLANNED_MOON } from "../data/places-planned.js";
4
+ const ALL = DATA;
3
5
  /**
4
- * Every place on the Moon the package knows: the sites first, by date, then the named features by size. A place's `kind` says what it is (`placesOfKind` from `/places` picks by it).
6
+ * 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).
5
7
  *
6
8
  * @example
7
9
  * ```ts
@@ -10,4 +12,4 @@ import { PLACES_MOON as DATA } from "../data/places-moon.js";
10
12
  * console.log(PLACES_MOON.length, "places;", PLACES_MOON.filter((place) => place.kind === "landing").length, "landings");
11
13
  * ```
12
14
  */
13
- export const PLACES_MOON = DATA;
15
+ export const PLACES_MOON = [...ALL.filter((place) => place.kind !== "feature"), ...PLANNED_MOON, ...ALL.filter((place) => place.kind === "feature")];
package/dist/places.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type BodyId } from "./facts.ts";
2
2
  import { type When } from "./when.ts";
3
3
  export type { When } from "./when.ts";
4
+ export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, readPlaceLayers, surfacePoint, turnToPlace, type PlaceLayer, type PlaceMark, type SurfaceView } from "./place-marks.ts";
4
5
  /**
5
6
  * What a place is: a `crewed` landing (an Apollo lunar module), a `landing` (a lander that worked after touchdown), a `rover` that drove there, a `crash` (a craft that hit the surface and was lost, by accident or at the end of its mission), an
6
7
  * `impact` (a craft sent to hit it on purpose), an `entry` (a probe or orbiter lost in the atmosphere of Venus, Jupiter or Saturn: no surface was reached or none is there), a `planned` landing (announced, not flown) or a named `feature` of the surface.
@@ -72,15 +73,16 @@ export interface Place {
72
73
  diameterKm: number;
73
74
  approved: string;
74
75
  };
75
- /** For a planned landing: the announced date, its state, and the date the announcement was read. */
76
+ /** For a planned landing: the announced date (a year, or a year and month, as the page gives it), whether that date is the `launch` or the `landing`, its state (`slipped` where the agency's own pages have moved it later), and the date the announcement was read. */
76
77
  planned?: {
77
78
  date: string;
79
+ dateOf: "launch" | "landing";
78
80
  status: "announced" | "slipped" | "cancelled";
79
81
  read: string;
80
82
  };
81
83
  /** Where the record comes from, and the date that source's file was read. */
82
84
  source: {
83
- id: "iau-gazetteer" | "gcat-landercat" | "nssdca" | "pds-ode" | "nasa-mars24" | "agency" | "nasa-ntrs" | "pds-atmospheres" | "paper";
85
+ id: "iau-gazetteer" | "gcat-landercat" | "nssdca" | "pds-ode" | "nasa-mars24" | "agency" | "nasa-ntrs" | "pds-atmospheres" | "paper" | "announcement";
84
86
  read: string;
85
87
  latitude?: "planetocentric" | "converted" | "not stated";
86
88
  /** The page or paper a position was typed from, where it is not one of the tables above. */
package/dist/places.js CHANGED
@@ -5,6 +5,7 @@ import { apparent } from "./ephemeris.js";
5
5
  import { BODIES } from "./facts.js";
6
6
  import { cross, dot } from "./vec.js";
7
7
  import { moment } from "./when.js";
8
+ export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, readPlaceLayers, surfacePoint, turnToPlace } from "./place-marks.js";
8
9
  /**
9
10
  * The credit a page that shows places owes each source, one row for every `source.id` the tables use: the line to print, the licence or terms it rests on and the address. The lander catalogue's is a condition of its licence (CC BY 4.0: "data from GCAT (J. McDowell,
10
11
  * planet4589.org/space/gcat)"); the others are US government works, credited as their owners ask, and the papers' coordinates are facts (each record's `source.url` names the paper).
@@ -25,6 +26,7 @@ export const PLACES_CREDITS = [
25
26
  { id: "agency", line: "NASA mission and Photojournal pages (the address is in each record's source.url)", licence: "US government work", url: "https://www.nasa.gov/nasa-brand-center/images-and-media/" },
26
27
  { id: "nasa-ntrs", line: "Basilevsky and Weitz 1992, The geology of the Venera/Vega landing sites, NASA Technical Reports Server", licence: "public use permitted (NTRS)", url: "https://ntrs.nasa.gov/citations/19930005108" },
27
28
  { id: "pds-atmospheres", line: "NASA Planetary Data System, Planetary Atmospheres Node, Pioneer Venus summary", licence: "US government work", url: "https://pds-atmospheres.nmsu.edu/data_and_services/atmospheres_data/PIONEER_Venus/venus_cp.html" },
29
+ { id: "announcement", line: "the agency's or operator's own announcement of a planned landing (the address is in each record's source.url; the position is the IAU Gazetteer's centre of the named site)", licence: "facts (a date and a site's name) typed by hand; no text copied", url: "https://planetarynames.wr.usgs.gov/" },
28
30
  { id: "paper", line: "the published paper named in the record's source.url (Daly et al. 2023; Nagdimunov et al. 2014; Hoang et al. 2020)", licence: "coordinates (facts) typed from the papers, none of whose text, figures or tables is copied; Daly et al. 2023 is CC BY 4.0, credited", url: "https://doi.org/10.1038/s41586-023-05810-5" },
29
31
  ];
30
32
  /**
@@ -0,0 +1,68 @@
1
+ import type { Place, PlaceBody } from "../places.ts";
2
+ import type { PlaceLayer, PlaceMark } from "../place-marks.ts";
3
+ /**
4
+ * The short line under a place's name: what it is and when (a site's year, a planned landing's announced year, a feature's kind and size), in English or Japanese.
5
+ *
6
+ * @param place - The place.
7
+ * @param lang - `en` or `ja`.
8
+ * @returns The line.
9
+ *
10
+ * @example
11
+ * ```ts no-run
12
+ * import { placeLine } from "@johnmorrisdotca/wakusei-planets/element";
13
+ *
14
+ * console.log(placeLine({ id: "moon/x", kind: "crewed", name: { en: "X", ja: "X" }, lat: 0, lon: 0, date: "1969-07-20T20:17Z", source: { id: "nssdca", read: "2026-11-11" } }, "en"));
15
+ * ```
16
+ */
17
+ export declare function placeLine(place: Place, lang: "en" | "ja"): string;
18
+ type PlacesLoader = (body: PlaceBody) => Promise<readonly Place[]>;
19
+ /**
20
+ * Give the views the lists of places, for the marks of the `places` attribute: `loadPlaces` from `/places`, which fetches each body's table as a chunk of its own the first time it is asked for, or a function of your own
21
+ * that returns a body's list. The views hold no table themselves, so a page that never marks a place never carries one; until this is called a view marks nothing. Views already on the page lay their marks at once.
22
+ *
23
+ * @param load - A body's list of places, for a body of `PLACE_BODIES`.
24
+ *
25
+ * @example
26
+ * ```ts no-run
27
+ * import { setPlacesLoader } from "@johnmorrisdotca/wakusei-planets/element";
28
+ * import { loadPlaces } from "@johnmorrisdotca/wakusei-planets/places";
29
+ *
30
+ * setPlacesLoader(loadPlaces);
31
+ * document.querySelector("wakusei-body")!.setAttribute("places", "landing crash");
32
+ * ```
33
+ */
34
+ export declare function setPlacesLoader(load: PlacesLoader): void;
35
+ /** The loader `setPlacesLoader` was given, if any. */
36
+ export declare const placesLoader: () => PlacesLoader | undefined;
37
+ /** Hear `setPlacesLoader`; returns the call that stops it. */
38
+ export declare function onPlacesLoader(heard: () => void): () => void;
39
+ /** The marks over one view. */
40
+ export interface PlaceLayerView {
41
+ /** Lay these marks, moving the ones already there, adding the new and taking away the rest. */
42
+ set(marks: readonly PlaceMark[]): void;
43
+ /** Take every mark away. */
44
+ clear(): void;
45
+ /** The marks laid now: the place's id, its layer and where it is, in CSS pixels. */
46
+ readonly shown: readonly {
47
+ id: string;
48
+ layer: PlaceLayer;
49
+ x: number;
50
+ y: number;
51
+ }[];
52
+ dispose(): void;
53
+ }
54
+ /**
55
+ * Make the layer of marks inside a view's shadow root, above its picture. `pick` is called for a click or Enter on a mark, with the place and where its mark is.
56
+ *
57
+ * @param root - The view's shadow root.
58
+ * @param options - `lang` reads the view's language at the time a tip is shown; `pick` hears a chosen place.
59
+ * @returns The layer.
60
+ */
61
+ export declare function createPlaceLayer(root: ShadowRoot, options: {
62
+ lang(): "en" | "ja";
63
+ pick(place: Place, at: {
64
+ x: number;
65
+ y: number;
66
+ }): void;
67
+ }): PlaceLayerView;
68
+ export {};
@@ -0,0 +1,213 @@
1
+ const STYLE = `.wk-places{position:absolute;inset:0;pointer-events:none;overflow:hidden}
2
+ .wk-place{position:absolute;left:0;top:0;width:20px;height:20px;margin:-10px 0 0 -10px;padding:0;border:0;background:none;cursor:pointer;pointer-events:auto;will-change:transform;-webkit-tap-highlight-color:transparent}
3
+ .wk-place::before{content:"";position:absolute;left:50%;top:50%;width:6px;height:6px;margin:-3px 0 0 -3px;border-radius:50%;box-sizing:border-box;background:var(--wakusei-place-landing,#fff);box-shadow:0 0 0 1px rgba(0,0,0,.55);opacity:.85}
4
+ .wk-place[data-layer=crash]::before{background:var(--wakusei-place-crash,#ffa070)}
5
+ .wk-place[data-layer=planned]::before{background:none;border:1.5px solid var(--wakusei-place-planned,#8fd3ff);width:8px;height:8px;margin:-4px 0 0 -4px;box-shadow:0 0 2px rgba(0,0,0,.8)}
6
+ .wk-place[data-layer=feature]::before{width:4px;height:4px;margin:-2px 0 0 -2px;background:var(--wakusei-place-feature,rgba(255,255,255,.6));box-shadow:0 0 0 1px rgba(0,0,0,.35);opacity:.75}
7
+ .wk-place:hover::before,.wk-place:focus-visible::before{opacity:1;transform:scale(1.4)}
8
+ .wk-place:focus-visible{outline:2px solid #6cd0ff;outline-offset:-3px;border-radius:50%}
9
+ .wk-place-tip{position:absolute;left:0;top:0;max-width:min(260px,80%);padding:3px 7px;border-radius:5px;background:rgba(10,14,22,.86);color:#fff;font:12px/1.35 var(--wakusei-place-font,system-ui,-apple-system,sans-serif);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;pointer-events:none;visibility:hidden}
10
+ .wk-place-tip small{display:block;font-size:11px;opacity:.8}
11
+ .wk-place-tip[data-on]{visibility:visible}`;
12
+ const KIND_WORD = {
13
+ crewed: { en: "crewed landing", ja: "有人着陸" },
14
+ landing: { en: "lander", ja: "着陸機" },
15
+ rover: { en: "rover", ja: "探査車" },
16
+ crash: { en: "crash site", ja: "墜落地点" },
17
+ impact: { en: "impact site", ja: "衝突地点" },
18
+ entry: { en: "lost in the atmosphere", ja: "大気圏で消失" },
19
+ planned: { en: "planned landing", ja: "着陸予定" },
20
+ feature: { en: "feature", ja: "地形" },
21
+ };
22
+ /**
23
+ * The short line under a place's name: what it is and when (a site's year, a planned landing's announced year, a feature's kind and size), in English or Japanese.
24
+ *
25
+ * @param place - The place.
26
+ * @param lang - `en` or `ja`.
27
+ * @returns The line.
28
+ *
29
+ * @example
30
+ * ```ts no-run
31
+ * import { placeLine } from "@johnmorrisdotca/wakusei-planets/element";
32
+ *
33
+ * console.log(placeLine({ id: "moon/x", kind: "crewed", name: { en: "X", ja: "X" }, lat: 0, lon: 0, date: "1969-07-20T20:17Z", source: { id: "nssdca", read: "2026-11-11" } }, "en"));
34
+ * ```
35
+ */
36
+ export function placeLine(place, lang) {
37
+ const ja = lang === "ja";
38
+ if (place.kind === "feature") {
39
+ const word = place.feature?.typeWord[lang] ?? KIND_WORD.feature[lang];
40
+ const km = place.feature?.diameterKm ?? 0;
41
+ return km > 0 ? `${word}${ja ? "、" : ", "}${Math.round(km).toLocaleString(ja ? "ja-JP" : "en")} km` : word;
42
+ }
43
+ const word = KIND_WORD[place.kind][lang];
44
+ if (place.kind === "planned" && place.planned !== undefined) {
45
+ const { date, dateOf } = place.planned;
46
+ const year = date.slice(0, 4);
47
+ return ja ? `${word} (${dateOf === "launch" ? `${year}年打ち上げ` : `${year}年`})` : `${word}, ${dateOf === "launch" ? `launch ${year}` : year}`;
48
+ }
49
+ const year = place.date?.slice(0, 4);
50
+ return year === undefined ? word : ja ? `${word}、${year}年` : `${word}, ${year}`;
51
+ }
52
+ // on globalThis, so the separate copies a CDN can load share the one loader
53
+ const SLOT = Symbol.for("@johnmorrisdotca/wakusei-planets/places-loader");
54
+ const slot = (globalThis[SLOT] ??= { heard: new Set() });
55
+ /**
56
+ * Give the views the lists of places, for the marks of the `places` attribute: `loadPlaces` from `/places`, which fetches each body's table as a chunk of its own the first time it is asked for, or a function of your own
57
+ * that returns a body's list. The views hold no table themselves, so a page that never marks a place never carries one; until this is called a view marks nothing. Views already on the page lay their marks at once.
58
+ *
59
+ * @param load - A body's list of places, for a body of `PLACE_BODIES`.
60
+ *
61
+ * @example
62
+ * ```ts no-run
63
+ * import { setPlacesLoader } from "@johnmorrisdotca/wakusei-planets/element";
64
+ * import { loadPlaces } from "@johnmorrisdotca/wakusei-planets/places";
65
+ *
66
+ * setPlacesLoader(loadPlaces);
67
+ * document.querySelector("wakusei-body")!.setAttribute("places", "landing crash");
68
+ * ```
69
+ */
70
+ export function setPlacesLoader(load) {
71
+ slot.load = load;
72
+ for (const heard of slot.heard)
73
+ heard();
74
+ }
75
+ /** The loader `setPlacesLoader` was given, if any. */
76
+ export const placesLoader = () => slot.load;
77
+ /** Hear `setPlacesLoader`; returns the call that stops it. */
78
+ export function onPlacesLoader(heard) {
79
+ slot.heard.add(heard);
80
+ return () => slot.heard.delete(heard);
81
+ }
82
+ /**
83
+ * Make the layer of marks inside a view's shadow root, above its picture. `pick` is called for a click or Enter on a mark, with the place and where its mark is.
84
+ *
85
+ * @param root - The view's shadow root.
86
+ * @param options - `lang` reads the view's language at the time a tip is shown; `pick` hears a chosen place.
87
+ * @returns The layer.
88
+ */
89
+ export function createPlaceLayer(root, options) {
90
+ const style = document.createElement("style");
91
+ style.textContent = STYLE;
92
+ const box = document.createElement("div");
93
+ box.className = "wk-places";
94
+ box.setAttribute("part", "places");
95
+ const tip = document.createElement("div");
96
+ tip.className = "wk-place-tip";
97
+ tip.setAttribute("part", "place-tip");
98
+ tip.setAttribute("aria-hidden", "true");
99
+ box.append(tip);
100
+ root.append(style, box);
101
+ const held = new Map();
102
+ let shown = [];
103
+ let tipFor = null;
104
+ const showTip = (id) => {
105
+ const entry = held.get(id);
106
+ if (entry === undefined)
107
+ return;
108
+ const lang = options.lang();
109
+ const name = document.createElement("span");
110
+ name.textContent = entry.mark.place.name[lang];
111
+ const line = document.createElement("small");
112
+ line.textContent = placeLine(entry.mark.place, lang);
113
+ tip.replaceChildren(name, line);
114
+ tip.setAttribute("data-on", "");
115
+ tipFor = id;
116
+ placeTip();
117
+ };
118
+ // above the mark, inside the view: measured in the page's own font once its text is in
119
+ const placeTip = () => {
120
+ const entry = tipFor === null ? undefined : held.get(tipFor);
121
+ if (entry === undefined)
122
+ return;
123
+ const w = tip.offsetWidth;
124
+ const h = tip.offsetHeight;
125
+ const width = box.clientWidth;
126
+ const x = Math.max(2, Math.min(width - w - 2, entry.x - w / 2));
127
+ const y = entry.y - h - 10 >= 2 ? entry.y - h - 10 : entry.y + 12;
128
+ tip.style.transform = `translate(${x.toFixed(1)}px,${y.toFixed(1)}px)`;
129
+ };
130
+ const hideTip = (id) => {
131
+ if (id !== undefined && tipFor !== id)
132
+ return;
133
+ tip.removeAttribute("data-on");
134
+ tipFor = null;
135
+ };
136
+ const make = (mark) => {
137
+ const button = document.createElement("button");
138
+ button.type = "button";
139
+ button.className = "wk-place";
140
+ button.setAttribute("part", "place");
141
+ const id = mark.place.id;
142
+ button.dataset.place = id;
143
+ button.addEventListener("pointerenter", () => showTip(id));
144
+ button.addEventListener("pointerleave", () => hideTip(id));
145
+ button.addEventListener("focus", () => showTip(id));
146
+ button.addEventListener("blur", () => hideTip(id));
147
+ // a press on a mark is the mark's, not the start of a drag or a pick of the body under it; a touch shows the name as well
148
+ button.addEventListener("pointerdown", (event) => {
149
+ event.stopPropagation();
150
+ if (event.pointerType !== "mouse")
151
+ showTip(id);
152
+ });
153
+ button.addEventListener("click", (event) => {
154
+ event.stopPropagation();
155
+ const entry = held.get(id);
156
+ if (entry !== undefined)
157
+ options.pick(entry.mark.place, { x: entry.x, y: entry.y });
158
+ });
159
+ return button;
160
+ };
161
+ return {
162
+ set(marks) {
163
+ const lang = options.lang();
164
+ const next = new Set();
165
+ for (const mark of marks) {
166
+ const id = mark.place.id;
167
+ next.add(id);
168
+ let entry = held.get(id);
169
+ if (entry === undefined) {
170
+ const button = make(mark);
171
+ entry = { button, mark, x: Number.NaN, y: Number.NaN, lang: "" };
172
+ held.set(id, entry);
173
+ box.insertBefore(button, tip);
174
+ }
175
+ entry.mark = mark;
176
+ if (entry.lang !== lang) {
177
+ entry.lang = lang;
178
+ entry.button.dataset.layer = mark.layer;
179
+ entry.button.setAttribute("aria-label", `${mark.place.name[lang]}, ${placeLine(mark.place, lang)}`);
180
+ }
181
+ if (!(Math.abs(entry.x - mark.x) < 0.25 && Math.abs(entry.y - mark.y) < 0.25)) {
182
+ entry.x = mark.x;
183
+ entry.y = mark.y;
184
+ entry.button.style.transform = `translate(${mark.x.toFixed(1)}px,${mark.y.toFixed(1)}px)`;
185
+ }
186
+ }
187
+ for (const [id, entry] of held) {
188
+ if (next.has(id))
189
+ continue;
190
+ entry.button.remove();
191
+ held.delete(id);
192
+ hideTip(id);
193
+ }
194
+ shown = marks.map((mark) => ({ id: mark.place.id, layer: mark.layer, x: mark.x, y: mark.y }));
195
+ placeTip();
196
+ },
197
+ clear() {
198
+ for (const entry of held.values())
199
+ entry.button.remove();
200
+ held.clear();
201
+ shown = [];
202
+ hideTip();
203
+ },
204
+ get shown() {
205
+ return shown;
206
+ },
207
+ dispose() {
208
+ this.clear();
209
+ box.remove();
210
+ style.remove();
211
+ },
212
+ };
213
+ }
@@ -11,7 +11,7 @@ import { type BodyMapSource } from "../door/map.ts";
11
11
  * console.log(TEXTURE_BASE);
12
12
  * ```
13
13
  */
14
- export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.35.0/dist/textures/";
14
+ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.37.0/dist/textures/";
15
15
  /**
16
16
  * Where the sharpest surface pictures are: the files of this exact version in the repository, on jsDelivr's GitHub address. The npm package holds only the two smaller widths, so a page that
17
17
  * never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
@@ -23,7 +23,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
23
23
  * console.log(TEXTURE_FAR_BASE);
24
24
  * ```
25
25
  */
26
- export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.35.0/textures/";
26
+ export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.37.0/textures/";
27
27
  /**
28
28
  * Where the finer map tiles are by default: the demo site's `tiles/` folder (GitHub Pages sends `access-control-allow-origin: *`). The tiles are made by `scripts/make-body-tiles.py` and are in no package and no repository:
29
29
  * a page that serves its own gives the folder in the `tiles` attribute, and `tiles="off"` turns them off. A page that sets `texture-base` (it serves its own pictures) has none unless it says where they are.
@@ -0,0 +1,30 @@
1
+ import type * as THREE from "three";
2
+ import { type Vec3 } from "../vec.ts";
3
+ import type { SpaceDwarf, SpacePlanet } from "./frame.ts";
4
+ import { type ScaleMode } from "./scale.ts";
5
+ /** The parts of three.js the dots use, over and above the ones every body needs. */
6
+ export type DotsThree = Pick<typeof THREE, "BufferAttribute" | "BufferGeometry" | "Points" | "PointsMaterial">;
7
+ /** One moon to draw as a dot: its planet, and where it is from the planet's centre in kilometres, in the J2000 ecliptic frame (what `catalogueMoonPosition` gives). */
8
+ export interface MoonDot {
9
+ host: SpacePlanet | SpaceDwarf;
10
+ km: Vec3;
11
+ }
12
+ /** The dots of the view. */
13
+ export interface MoonDots {
14
+ object: THREE.Points;
15
+ /** Places the dots: `at(host)` is where the host is drawn and `radius(host)` its drawn radius, in the view's units. Returns how many are drawn. */
16
+ update(dots: readonly MoonDot[], mode: ScaleMode, at: (host: SpacePlanet | SpaceDwarf) => Vec3, radius: (host: SpacePlanet | SpaceDwarf) => number, ratio: number): number;
17
+ dispose(): void;
18
+ }
19
+ /** The most dots drawn: more than every known moon, with room for the years of finds to come. */
20
+ export declare const MAX_MOON_DOTS = 1024;
21
+ /**
22
+ * Where the view draws a moon of the catalogue: its place from the planet in the planet's radii, turned into the scene's axes and drawn nearer in a compressed view (the same mapping as the drawn moons).
23
+ *
24
+ * @param mode - The scale of the view.
25
+ * @param dot - The moon's host and its place in kilometres.
26
+ * @returns The offset from the planet's centre, in the planet's radii, in the scene's axes.
27
+ */
28
+ export declare function moonDotOffset(mode: ScaleMode, dot: MoonDot): Vec3;
29
+ /** The dots, in one `Points` draw that is hidden until it has something to show. */
30
+ export declare function createMoonDots(T: DotsThree): MoonDots;
@@ -0,0 +1,61 @@
1
+ import { BODIES } from "../facts.js";
2
+ import { OBLIQUITY, RAD } from "../vec.js";
3
+ import { moonDistance } from "./scale.js";
4
+ /** The most dots drawn: more than every known moon, with room for the years of finds to come. */
5
+ export const MAX_MOON_DOTS = 1024;
6
+ /** A dot's size, in CSS pixels across. */
7
+ const DOT_PX = 3;
8
+ const C = Math.cos(OBLIQUITY * RAD);
9
+ const S = Math.sin(OBLIQUITY * RAD);
10
+ /** An ecliptic J2000 vector in the scene's axes (equatorial, y to the celestial north pole), as `moonOffset` turns a moon's. */
11
+ const toScene = (v) => [v[0], v[1] * S + v[2] * C, -(v[1] * C - v[2] * S)];
12
+ /**
13
+ * Where the view draws a moon of the catalogue: its place from the planet in the planet's radii, turned into the scene's axes and drawn nearer in a compressed view (the same mapping as the drawn moons).
14
+ *
15
+ * @param mode - The scale of the view.
16
+ * @param dot - The moon's host and its place in kilometres.
17
+ * @returns The offset from the planet's centre, in the planet's radii, in the scene's axes.
18
+ */
19
+ export function moonDotOffset(mode, dot) {
20
+ const r = BODIES[dot.host].radiusKm;
21
+ const v = toScene([dot.km[0] / r, dot.km[1] / r, dot.km[2] / r]);
22
+ const d = Math.hypot(v[0], v[1], v[2]);
23
+ const k = d === 0 ? 1 : moonDistance(mode, dot.host, d) / d;
24
+ return [v[0] * k, v[1] * k, v[2] * k];
25
+ }
26
+ /** The dots, in one `Points` draw that is hidden until it has something to show. */
27
+ export function createMoonDots(T) {
28
+ const positions = new Float32Array(MAX_MOON_DOTS * 3);
29
+ const geometry = new T.BufferGeometry();
30
+ const attribute = new T.BufferAttribute(positions, 3);
31
+ geometry.setAttribute("position", attribute);
32
+ geometry.setDrawRange(0, 0);
33
+ const material = new T.PointsMaterial({ color: 0xc9cdd4, size: DOT_PX, sizeAttenuation: false, transparent: true, opacity: 0.85, depthWrite: false });
34
+ const object = new T.Points(geometry, material);
35
+ object.frustumCulled = false;
36
+ object.visible = false;
37
+ return {
38
+ object,
39
+ update(dots, mode, at, radius, ratio) {
40
+ const count = Math.min(MAX_MOON_DOTS, dots.length);
41
+ for (let k = 0; k < count; k += 1) {
42
+ const dot = dots[k];
43
+ const o = moonDotOffset(mode, dot);
44
+ const c = at(dot.host);
45
+ const r = radius(dot.host);
46
+ positions[k * 3] = c[0] + o[0] * r;
47
+ positions[k * 3 + 1] = c[1] + o[1] * r;
48
+ positions[k * 3 + 2] = c[2] + o[2] * r;
49
+ }
50
+ attribute.needsUpdate = true;
51
+ geometry.setDrawRange(0, count);
52
+ material.size = DOT_PX * ratio;
53
+ object.visible = count > 0;
54
+ return count;
55
+ },
56
+ dispose() {
57
+ geometry.dispose();
58
+ material.dispose();
59
+ },
60
+ };
61
+ }
@@ -81,3 +81,21 @@ export declare function findBody(text: string): BodyId | undefined;
81
81
  * ```
82
82
  */
83
83
  export declare function hopFrom(id: BodyId, step: 1 | -1, can?: (id: BodyId) => boolean): BodyId;
84
+ /**
85
+ * The system a body belongs to: the body a moon goes round (or the body itself), and that body's moons, nearest first. The Sun's system is the Sun alone, and a body with no moons is a system of one.
86
+ *
87
+ * @param id - A body's name.
88
+ * @returns `host`, the middle of the system, and `moons`, the moons that go round it.
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * import { systemOf } from "@johnmorrisdotca/wakusei-planets/space";
93
+ *
94
+ * const { host, moons } = systemOf("titan");
95
+ * console.log(host, moons.join(", "));
96
+ * ```
97
+ */
98
+ export declare function systemOf(id: BodyId): {
99
+ host: BodyId;
100
+ moons: BodyId[];
101
+ };
@@ -91,3 +91,21 @@ export function hopFrom(id, step, can = () => true) {
91
91
  }
92
92
  return id;
93
93
  }
94
+ /**
95
+ * The system a body belongs to: the body a moon goes round (or the body itself), and that body's moons, nearest first. The Sun's system is the Sun alone, and a body with no moons is a system of one.
96
+ *
97
+ * @param id - A body's name.
98
+ * @returns `host`, the middle of the system, and `moons`, the moons that go round it.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * import { systemOf } from "@johnmorrisdotca/wakusei-planets/space";
103
+ *
104
+ * const { host, moons } = systemOf("titan");
105
+ * console.log(host, moons.join(", "));
106
+ * ```
107
+ */
108
+ export function systemOf(id) {
109
+ const host = hostOf(id) ?? id;
110
+ return { host, moons: [...(MOONS_OF[host] ?? [])] };
111
+ }