@johnmorrisdotca/wakusei-planets 0.19.0 → 0.21.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.
- package/CHANGELOG.md +23 -0
- package/NOTICE.md +14 -3
- package/README.md +39 -6
- package/dist/bodies/earth.js +13 -5
- package/dist/calendar.d.ts +119 -0
- package/dist/calendar.js +155 -0
- package/dist/clock.d.ts +244 -0
- package/dist/clock.js +325 -0
- package/dist/coordinates.d.ts +172 -0
- package/dist/coordinates.js +170 -0
- package/dist/craft/cassini.d.ts +1 -0
- package/dist/craft/cassini.js +1131 -0
- package/dist/craft/galileo.d.ts +1 -0
- package/dist/craft/galileo.js +224 -0
- package/dist/craft/juno.d.ts +1 -0
- package/dist/craft/juno.js +640 -0
- package/dist/craft/newhorizons.d.ts +1 -0
- package/dist/craft/newhorizons.js +18 -0
- package/dist/craft/parker.d.ts +1 -0
- package/dist/craft/parker.js +221 -0
- package/dist/craft/pioneer10.d.ts +1 -0
- package/dist/craft/pioneer10.js +24 -0
- package/dist/craft/pioneer11.d.ts +1 -0
- package/dist/craft/pioneer11.js +34 -0
- package/dist/craft/voyager1.d.ts +1 -0
- package/dist/craft/voyager1.js +28 -0
- package/dist/craft/voyager2.d.ts +1 -0
- package/dist/craft/voyager2.js +43 -0
- package/dist/craft/webb.d.ts +1 -0
- package/dist/craft/webb.js +28 -0
- package/dist/data/craft.d.ts +23 -0
- package/dist/data/craft.js +53 -0
- package/dist/data/lunar.d.ts +4 -0
- package/dist/data/lunar.js +548 -0
- package/dist/data/pluto.d.ts +6 -0
- package/dist/data/pluto.js +29 -0
- package/dist/data/stars.d.ts +4 -0
- package/dist/data/stars.js +5088 -0
- package/dist/data/tables.d.ts +41 -0
- package/dist/data/tables.js +37 -0
- package/dist/data/vsop.d.ts +19 -1
- package/dist/data/vsop.js +25 -8
- package/dist/element.d.ts +2 -23
- package/dist/element.js +75 -110
- package/dist/ephemeris.d.ts +22 -14
- package/dist/ephemeris.js +106 -58
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mars.d.ts +41 -0
- package/dist/mars.js +52 -0
- package/dist/portrait/element.d.ts +1 -0
- package/dist/portrait/element.js +27 -39
- package/dist/scales.d.ts +46 -0
- package/dist/scales.js +75 -0
- package/dist/scene/basis.d.ts +3 -0
- package/dist/scene/basis.js +4 -0
- package/dist/scene/body.d.ts +2 -4
- package/dist/scene/body.js +55 -67
- package/dist/scene/fallback.d.ts +4 -0
- package/dist/scene/fallback.js +5 -0
- package/dist/scene/painter.js +10 -23
- package/dist/scene/store.d.ts +2 -2
- package/dist/scene/textures.d.ts +30 -0
- package/dist/scene/textures.js +47 -0
- package/dist/sidereal.d.ts +70 -0
- package/dist/sidereal.js +94 -0
- package/dist/sky/engine.d.ts +37 -0
- package/dist/sky/engine.js +116 -0
- package/dist/sky/events.d.ts +37 -0
- package/dist/sky/events.js +133 -0
- package/dist/sky/frames.d.ts +3 -0
- package/dist/sky/frames.js +26 -0
- package/dist/sky/types.d.ts +20 -0
- package/dist/sky/types.js +1 -0
- package/dist/space/aim.d.ts +18 -0
- package/dist/space/aim.js +28 -0
- package/dist/space/element.d.ts +212 -0
- package/dist/space/element.js +524 -0
- package/dist/space/frame.d.ts +152 -0
- package/dist/space/frame.js +169 -0
- package/dist/space/index.d.ts +4 -0
- package/dist/space/index.js +5 -0
- package/dist/space/ride.d.ts +89 -0
- package/dist/space/ride.js +58 -0
- package/dist/space/scale.d.ts +126 -0
- package/dist/space/scale.js +139 -0
- package/dist/space/scene.d.ts +189 -0
- package/dist/space/scene.js +422 -0
- package/dist/spacecraft-facts.d.ts +114 -0
- package/dist/spacecraft-facts.js +215 -0
- package/dist/spacecraft.d.ts +134 -0
- package/dist/spacecraft.js +198 -0
- package/dist/stars.d.ts +160 -0
- package/dist/stars.js +193 -0
- package/dist/suncalc-legacy.d.ts +187 -0
- package/dist/suncalc-legacy.js +168 -0
- package/dist/suncalc.d.ts +209 -0
- package/dist/suncalc.js +167 -0
- package/dist/tables/all.d.ts +2 -0
- package/dist/tables/all.js +2 -0
- package/dist/tables/ceres.d.ts +1 -0
- package/dist/tables/ceres.js +57 -0
- package/dist/tables/dwarfs.d.ts +1 -0
- package/dist/tables/dwarfs.js +59 -0
- package/dist/theory.d.ts +20 -0
- package/dist/theory.js +98 -0
- package/dist/time.d.ts +6 -108
- package/dist/time.js +7 -180
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/when.d.ts +16 -0
- package/dist/when.js +13 -0
- package/package.json +95 -4
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// The searches behind the sun and moon times: the day a time belongs to, the instants when a body crosses an altitude or the meridian, found by sampling and bisection on this package's own positions.
|
|
2
|
+
// Shared by `suncalc` and `suncalc/legacy`. Pure: no DOM, no three.js.
|
|
3
|
+
import { horizontalOf, moonEquatorial, sunEquatorial } from "./engine.js";
|
|
4
|
+
const DAY_MS = 86_400_000;
|
|
5
|
+
const MOON_RADIUS_KM = 1737.4;
|
|
6
|
+
const SAMPLE_MS = 6 * 60_000;
|
|
7
|
+
/** A date or milliseconds since 1970 as milliseconds, throwing on anything that is not a moment. */
|
|
8
|
+
export function moment(date, name = "date") {
|
|
9
|
+
const ms = typeof date === "number" ? date : date.getTime();
|
|
10
|
+
if (!Number.isFinite(ms))
|
|
11
|
+
throw new RangeError(`${name} must be a valid Date or a finite number of milliseconds, got ${String(date)}`);
|
|
12
|
+
return ms;
|
|
13
|
+
}
|
|
14
|
+
export function place(latitude, longitude, heightM = 0) {
|
|
15
|
+
if (!Number.isFinite(latitude) || latitude < -90 || latitude > 90)
|
|
16
|
+
throw new RangeError(`lat must be between -90 and 90 degrees, got ${latitude}`);
|
|
17
|
+
if (!Number.isFinite(longitude))
|
|
18
|
+
throw new RangeError(`lng must be a finite number of degrees, got ${longitude}`);
|
|
19
|
+
if (!Number.isFinite(heightM))
|
|
20
|
+
throw new RangeError(`height must be a finite number of metres, got ${heightM}`);
|
|
21
|
+
return { latitude, longitude, heightM };
|
|
22
|
+
}
|
|
23
|
+
/** The window of a day: the local calendar day when a UTC offset is given, otherwise the solar day from one solar midnight to the next that holds the moment. Milliseconds, the end not included. */
|
|
24
|
+
export function dayWindow(ms, observer, utcOffset) {
|
|
25
|
+
if (utcOffset !== undefined) {
|
|
26
|
+
if (!Number.isFinite(utcOffset))
|
|
27
|
+
throw new RangeError(`utcOffset must be a finite number of minutes east of UTC, got ${utcOffset}`);
|
|
28
|
+
const start = Math.floor((ms + utcOffset * 60_000) / DAY_MS) * DAY_MS - utcOffset * 60_000;
|
|
29
|
+
return [start, start + DAY_MS];
|
|
30
|
+
}
|
|
31
|
+
const nadir = nearestHourAngle(ms, observer, 180);
|
|
32
|
+
const previous = nadir <= ms ? nadir : nearestHourAngle(nadir - DAY_MS, observer, 180);
|
|
33
|
+
const next = nearestHourAngle(previous + DAY_MS, observer, 180);
|
|
34
|
+
return [previous, next];
|
|
35
|
+
}
|
|
36
|
+
/** The Sun's hour angle in degrees from -180 to 180 for an observer (positive west, 0 on the meridian). */
|
|
37
|
+
export function sunHourAngle(ms, observer) {
|
|
38
|
+
return horizontalOf(sunEquatorial(ms), ms, observer).hourAngle;
|
|
39
|
+
}
|
|
40
|
+
/** The instant nearest to `ms` when the Sun's hour angle is `target` degrees (0 noon, 180 midnight), by Newton steps on the Sun's turn of about 360 degrees a day. */
|
|
41
|
+
export function nearestHourAngle(ms, observer, target) {
|
|
42
|
+
let t = ms;
|
|
43
|
+
for (let i = 0; i < 8; i += 1) {
|
|
44
|
+
const difference = ((((sunHourAngle(t, observer) - target) % 360) + 540) % 360) - 180;
|
|
45
|
+
t -= (difference / 360) * DAY_MS;
|
|
46
|
+
if (Math.abs(difference) < 1e-6)
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
return t;
|
|
50
|
+
}
|
|
51
|
+
/** The zero crossings of `f` in [start, end), as [instant, true when f goes up], found by sampling every `step` milliseconds and bisecting each bracket to about a tenth of a second. */
|
|
52
|
+
export function crossings(f, start, end, step) {
|
|
53
|
+
const found = [];
|
|
54
|
+
let t0 = start;
|
|
55
|
+
let f0 = f(t0);
|
|
56
|
+
while (t0 < end) {
|
|
57
|
+
const t1 = Math.min(t0 + step, end);
|
|
58
|
+
const f1 = f(t1);
|
|
59
|
+
if ((f0 < 0 && f1 >= 0) || (f0 >= 0 && f1 < 0)) {
|
|
60
|
+
let lo = t0;
|
|
61
|
+
let hi = t1;
|
|
62
|
+
let flo = f0;
|
|
63
|
+
for (let i = 0; i < 26; i += 1) {
|
|
64
|
+
const mid = (lo + hi) / 2;
|
|
65
|
+
const fm = f(mid);
|
|
66
|
+
if ((fm < 0) === (flo < 0)) {
|
|
67
|
+
lo = mid;
|
|
68
|
+
flo = fm;
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
hi = mid;
|
|
72
|
+
}
|
|
73
|
+
const at = (lo + hi) / 2;
|
|
74
|
+
if (at < end)
|
|
75
|
+
found.push([at, f0 < 0]);
|
|
76
|
+
}
|
|
77
|
+
t0 = t1;
|
|
78
|
+
f0 = f1;
|
|
79
|
+
}
|
|
80
|
+
return found;
|
|
81
|
+
}
|
|
82
|
+
/** The height of the horizon below level for an observer `height` metres up, in degrees (the dip, with the refraction along it). */
|
|
83
|
+
export const dip = (heightM) => 0.0347 * Math.sqrt(Math.max(0, heightM));
|
|
84
|
+
/**
|
|
85
|
+
* The Sun's day at a place: `utcOffset` in minutes east of UTC picks the local calendar day holding `ms`, and `undefined` the solar day (one solar midnight to the next).
|
|
86
|
+
* A row at the horizon (between -1 and 0 degrees) is lowered by the dip of the horizon for an observer `heightM` metres up.
|
|
87
|
+
*/
|
|
88
|
+
export function sunDay(ms, observer, utcOffset, rows) {
|
|
89
|
+
const [start, end] = dayWindow(ms, observer, utcOffset);
|
|
90
|
+
const altitude = (t) => horizontalOf(sunEquatorial(t), t, observer).altitude;
|
|
91
|
+
const solarNoon = nearestHourAngle(start + 12 * 3_600_000, observer, 0);
|
|
92
|
+
const noon = solarNoon < start - 1000 ? nearestHourAngle(solarNoon + DAY_MS, observer, 0) : solarNoon;
|
|
93
|
+
// the solar midnight that leads into this day's solar noon, as suncalc does: it can fall a few minutes before a calendar day begins
|
|
94
|
+
const nadir = nearestHourAngle(noon - DAY_MS / 2, observer, 180);
|
|
95
|
+
const cache = new Map();
|
|
96
|
+
const sampled = (t) => {
|
|
97
|
+
let v = cache.get(t);
|
|
98
|
+
if (v === undefined) {
|
|
99
|
+
v = altitude(t);
|
|
100
|
+
cache.set(t, v);
|
|
101
|
+
}
|
|
102
|
+
return v;
|
|
103
|
+
};
|
|
104
|
+
const events = new Map();
|
|
105
|
+
const height = observer.heightM ?? 0;
|
|
106
|
+
for (const [angle, morning, evening] of rows) {
|
|
107
|
+
const level = angle - (angle > -1 && angle < 0 ? dip(height) : 0);
|
|
108
|
+
const found = crossings((t) => sampled(t) - level, start, end, 10 * 60_000);
|
|
109
|
+
events.set(morning, found.find(([, rising]) => rising)?.[0] ?? null);
|
|
110
|
+
events.set(evening, found.find(([, rising]) => !rising)?.[0] ?? null);
|
|
111
|
+
}
|
|
112
|
+
const sunrise = events.get("sunrise");
|
|
113
|
+
const sunset = events.get("sunset");
|
|
114
|
+
const none = sunrise === null && sunset === null;
|
|
115
|
+
const high = none && altitude(noon) > -0.833 - dip(height);
|
|
116
|
+
return { noon, nadir, events, alwaysUp: high, alwaysDown: none && !high };
|
|
117
|
+
}
|
|
118
|
+
/** The Moon between two instants at a place: rise and set (the upper limb at the horizon through 34 arc-minutes of refraction), the upper and lower meridian crossings, and whether it stays up or down. */
|
|
119
|
+
export function moonDay(start, end, observer) {
|
|
120
|
+
// the centre's geometric altitude plus the refraction and the radius of the disc is zero at the rise and the set
|
|
121
|
+
const above = (t) => {
|
|
122
|
+
const h = horizontalOf(moonEquatorial(t), t, observer);
|
|
123
|
+
return h.altitude + 34 / 60 + (Math.asin(MOON_RADIUS_KM / h.distanceKm) * 180) / Math.PI;
|
|
124
|
+
};
|
|
125
|
+
const meridian = (t) => Math.sin((horizontalOf(moonEquatorial(t), t, observer).hourAngle * Math.PI) / 180);
|
|
126
|
+
const edges = crossings(above, start, end, SAMPLE_MS);
|
|
127
|
+
const turns = crossings(meridian, start, end, SAMPLE_MS);
|
|
128
|
+
const rise = edges.find(([, rising]) => rising)?.[0] ?? null;
|
|
129
|
+
const set = edges.find(([, rising]) => !rising)?.[0] ?? null;
|
|
130
|
+
const none = rise === null && set === null;
|
|
131
|
+
const up = none && above(start) > 0;
|
|
132
|
+
return { rise, set, transit: turns.find(([, rising]) => rising)?.[0] ?? null, lowerTransit: turns.find(([, rising]) => !rising)?.[0] ?? null, alwaysUp: up, alwaysDown: none && !up };
|
|
133
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Vec3 as Vec } from "../vec.ts";
|
|
2
|
+
/** A J2000 mean-ecliptic vector turned into the true equator and equinox of date: obliquity of J2000, IAU 1976 precession, then nutation. */
|
|
3
|
+
export declare function eclipticJ2000ToTrueEquatorialOfDate(ecliptic: Vec, T: number): Vec;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const ARCSEC = Math.PI / 648000;
|
|
2
|
+
import { meanObliquityArcseconds, nutation } from "../sidereal.js";
|
|
3
|
+
const OBLIQUITY_J2000 = meanObliquityArcseconds(0) * ARCSEC;
|
|
4
|
+
const matrixTimes = (a, b) => [0, 1, 2].map((i) => [0, 1, 2].map((j) => a[i][0] * b[0][j] + a[i][1] * b[1][j] + a[i][2] * b[2][j]));
|
|
5
|
+
const apply = (matrix, vector) => matrix.map((row) => row[0] * vector[0] + row[1] * vector[1] + row[2] * vector[2]);
|
|
6
|
+
/** The matrix that re-expresses a vector in axes turned by `a` radians about x, y or z (a frame turn, not a vector turn). */
|
|
7
|
+
const frameTurn = (axis, a) => {
|
|
8
|
+
const c = Math.cos(a);
|
|
9
|
+
const s = Math.sin(a);
|
|
10
|
+
if (axis === 1)
|
|
11
|
+
return [[1, 0, 0], [0, c, s], [0, -s, c]];
|
|
12
|
+
if (axis === 2)
|
|
13
|
+
return [[c, 0, -s], [0, 1, 0], [s, 0, c]];
|
|
14
|
+
return [[c, s, 0], [-s, c, 0], [0, 0, 1]];
|
|
15
|
+
};
|
|
16
|
+
/** A J2000 mean-ecliptic vector turned into the true equator and equinox of date: obliquity of J2000, IAU 1976 precession, then nutation. */
|
|
17
|
+
export function eclipticJ2000ToTrueEquatorialOfDate(ecliptic, T) {
|
|
18
|
+
const equatorial = apply(frameTurn(1, -OBLIQUITY_J2000), ecliptic);
|
|
19
|
+
const zeta = (2306.2181 * T + 0.30188 * T * T + 0.017998 * T * T * T) * ARCSEC;
|
|
20
|
+
const z = (2306.2181 * T + 1.09468 * T * T + 0.018203 * T * T * T) * ARCSEC;
|
|
21
|
+
const theta = (2004.3109 * T - 0.42665 * T * T - 0.041833 * T * T * T) * ARCSEC;
|
|
22
|
+
const precession = matrixTimes(frameTurn(3, -z), matrixTimes(frameTurn(2, theta), frameTurn(3, -zeta)));
|
|
23
|
+
const n = nutation(T);
|
|
24
|
+
const nutate = matrixTimes(frameTurn(1, -(n.meanObliquity + n.obliquity)), matrixTimes(frameTurn(3, -n.longitude), frameTurn(1, n.meanObliquity)));
|
|
25
|
+
return apply(nutate, apply(precession, equatorial));
|
|
26
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Geodetic degrees north/east and optional metres above the WGS 84 ellipsoid.
|
|
2
|
+
* Direction-only rotations ignore height. Parallax uses ellipsoidal height.
|
|
3
|
+
* Event dip retains the supplied height as height above the visible horizon;
|
|
4
|
+
* no geoid or terrain correction is inferred from these coordinates.
|
|
5
|
+
*/
|
|
6
|
+
export interface Observer {
|
|
7
|
+
latitude: number;
|
|
8
|
+
longitude: number;
|
|
9
|
+
heightM?: number;
|
|
10
|
+
}
|
|
11
|
+
/** Right ascension [0,360) and declination [-90,90], in degrees; frame belongs to the caller. */
|
|
12
|
+
export interface EquatorialAngles {
|
|
13
|
+
rightAscension: number;
|
|
14
|
+
declination: number;
|
|
15
|
+
}
|
|
16
|
+
/** Azimuth clockwise from north and altitude, both in degrees. */
|
|
17
|
+
export interface HorizontalAngles {
|
|
18
|
+
azimuth: number;
|
|
19
|
+
altitude: number;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Vec3 } from "../vec.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The unit direction, in the scene's axes, of a longitude and latitude on the Earth as the stars see it at `ms`: the camera fixed to the stars looks at the same place on the ground only at that moment, and the Earth turns away under it as time runs.
|
|
4
|
+
*
|
|
5
|
+
* @param lon - Degrees east.
|
|
6
|
+
* @param lat - Degrees north.
|
|
7
|
+
* @param ms - The moment, in milliseconds since the Unix epoch.
|
|
8
|
+
* @returns The direction from the Earth's centre.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { groundDirection } from "@johnmorrisdotca/wakusei-planets/space";
|
|
13
|
+
*
|
|
14
|
+
* const [x, y, z] = groundDirection(0, 90, Date.UTC(2026, 10, 2));
|
|
15
|
+
* console.log(y.toFixed(2));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function groundDirection(lon: number, lat: number, ms: number): Vec3;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Which way the camera sits from the body it looks at: over a place on the Earth's surface as the stars saw it at one moment. Pure.
|
|
2
|
+
import { orientation } from "../scene/orient.js";
|
|
3
|
+
import { cross, RAD } from "../vec.js";
|
|
4
|
+
/**
|
|
5
|
+
* The unit direction, in the scene's axes, of a longitude and latitude on the Earth as the stars see it at `ms`: the camera fixed to the stars looks at the same place on the ground only at that moment, and the Earth turns away under it as time runs.
|
|
6
|
+
*
|
|
7
|
+
* @param lon - Degrees east.
|
|
8
|
+
* @param lat - Degrees north.
|
|
9
|
+
* @param ms - The moment, in milliseconds since the Unix epoch.
|
|
10
|
+
* @returns The direction from the Earth's centre.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { groundDirection } from "@johnmorrisdotca/wakusei-planets/space";
|
|
15
|
+
*
|
|
16
|
+
* const [x, y, z] = groundDirection(0, 90, Date.UTC(2026, 10, 2));
|
|
17
|
+
* console.log(y.toFixed(2));
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function groundDirection(lon, lat, ms) {
|
|
21
|
+
const { pole, meridian } = orientation("earth", ms);
|
|
22
|
+
const east = cross(pole, meridian);
|
|
23
|
+
const c = Math.cos(lat * RAD);
|
|
24
|
+
const along = c * Math.cos(lon * RAD);
|
|
25
|
+
const across = c * Math.sin(lon * RAD);
|
|
26
|
+
const up = Math.sin(lat * RAD);
|
|
27
|
+
return [meridian[0] * along + east[0] * across + pole[0] * up, meridian[1] * along + east[1] * across + pole[1] * up, meridian[2] * along + east[2] * across + pole[2] * up];
|
|
28
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { setThreeLoader } from "../scene/shared.ts";
|
|
2
|
+
import { type SpacePlanet } from "./frame.ts";
|
|
3
|
+
import { type ScaleMode } from "./scale.ts";
|
|
4
|
+
import type { RideLook } from "./ride.ts";
|
|
5
|
+
import { SPACE_BODIES, type RidePoint, type RideState, type RideTarget, type SpaceBody, type SpaceLight } from "./scene.ts";
|
|
6
|
+
export { setThreeLoader, SPACE_BODIES, type RidePoint, type RideTarget, type SpaceBody, type SpaceLight };
|
|
7
|
+
/**
|
|
8
|
+
* What a page can tell a reader about a body now.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts no-run
|
|
12
|
+
* import type { BodyInfo } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
13
|
+
*
|
|
14
|
+
* const info: BodyInfo = { id: "mars", name: "Mars", radiusKm: 3389.5, distanceKm: 225_000_000 };
|
|
15
|
+
* console.log(`${info.name}: ${info.radiusKm} km`);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface BodyInfo {
|
|
19
|
+
id: SpaceBody;
|
|
20
|
+
/** The name shown beside the body. */
|
|
21
|
+
name: string;
|
|
22
|
+
/** Mean radius, kilometres. */
|
|
23
|
+
radiusKm: number;
|
|
24
|
+
/** Distance from the Earth's centre now, kilometres (0 for the Earth). */
|
|
25
|
+
distanceKm: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* What the space view is doing: `loading`, `live`, `unavailable` (no WebGL), `lost` (the GPU took the context; it comes back by itself).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts no-run
|
|
32
|
+
* import type { SpaceState, WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
33
|
+
*
|
|
34
|
+
* const stateOf = (space: WakuseiSpace): SpaceState => space.stats.state;
|
|
35
|
+
* console.log(typeof stateOf);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export type SpaceState = "loading" | "live" | "unavailable" | "lost";
|
|
39
|
+
/**
|
|
40
|
+
* A named distance for `zoomFor`: the Earth, the Moon, the Sun, the inner planets, the whole solar system, or a planet with its nearer moons (`jupiter-moons`).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts no-run
|
|
44
|
+
* import type { SpacePreset, WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
45
|
+
*
|
|
46
|
+
* const zoomTo = (space: WakuseiSpace, preset: SpacePreset): number => space.zoomFor(preset);
|
|
47
|
+
* console.log(typeof zoomTo);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export type SpacePreset = "earth" | "moon" | "sun" | "inner" | "solar-system" | `${Exclude<SpacePlanet, "mercury" | "venus">}-moons`;
|
|
51
|
+
/**
|
|
52
|
+
* How a ride along is done: `view` `from` (the default) puts the camera at the target looking at the body it goes round, `follow` keeps it a distance from the target looking at it (`distanceKm`,
|
|
53
|
+
* 3000 by default, for a point of your own; a body or a moon is kept at the distance the zoom says); `look` `down` (the default) or `horizon` is where a camera at the target points; `around` is the
|
|
54
|
+
* body a point of your own goes round (the Earth by default); `smooth` (the default) glides from the old camera to the new one in about a second and a bit, and jumps instead for a reader who asked for reduced motion.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts no-run
|
|
58
|
+
* import type { RideOptions } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
59
|
+
*
|
|
60
|
+
* const options: RideOptions = { view: "from", look: "horizon", around: "mars" };
|
|
61
|
+
* console.log(options.look);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export interface RideOptions {
|
|
65
|
+
view?: "from" | "follow";
|
|
66
|
+
look?: RideLook;
|
|
67
|
+
distanceKm?: number;
|
|
68
|
+
around?: SpaceBody;
|
|
69
|
+
smooth?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* What the camera is riding along with now: the target, the body it goes round, how (`from` or `follow`), where it looks, and the distance kept for a point.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts no-run
|
|
76
|
+
* import type { Riding } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
77
|
+
*
|
|
78
|
+
* const describe = (ride: Riding | null): string => (ride ? `${ride.view} ${typeof ride.target === "string" ? ride.target : "a point"}` : "not riding");
|
|
79
|
+
* console.log(typeof describe);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export type Riding = RideState;
|
|
83
|
+
/**
|
|
84
|
+
* The `<wakusei-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`
|
|
85
|
+
* (`"lon,lat"`), `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `look` (`realistic` or `painted`),
|
|
86
|
+
* `light` (`sun` or `lit`), `lang` (`en` or `ja`: the names), `labels` and `orbits` (`off` hides them), and `texture-base`, `texture-far-base` and `max-texture`. Positions come from this package's own models. It draws
|
|
87
|
+
* only when something changes, and nothing while it is out of sight.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts no-run
|
|
91
|
+
* import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
92
|
+
*
|
|
93
|
+
* const space = document.createElement("wakusei-space") as WakuseiSpace;
|
|
94
|
+
* space.setAttribute("time", "2026-11-02T12:00Z");
|
|
95
|
+
* space.setAttribute("speed", "0");
|
|
96
|
+
* document.body.append(space);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare class WakuseiSpace extends HTMLElement {
|
|
100
|
+
#private;
|
|
101
|
+
static observedAttributes: string[];
|
|
102
|
+
connectedCallback(): void;
|
|
103
|
+
disconnectedCallback(): void;
|
|
104
|
+
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
|
105
|
+
/** The home place the camera starts above, as longitude and latitude in degrees. */
|
|
106
|
+
get centre(): {
|
|
107
|
+
lon: number;
|
|
108
|
+
lat: number;
|
|
109
|
+
};
|
|
110
|
+
set centre(value: {
|
|
111
|
+
lon: number;
|
|
112
|
+
lat: number;
|
|
113
|
+
});
|
|
114
|
+
/** The moment shown: milliseconds since the epoch, or "now" to follow the clock. Setting it points the camera at the same place on the ground again. */
|
|
115
|
+
get time(): number;
|
|
116
|
+
set time(value: number | Date | "now");
|
|
117
|
+
/** Seconds of game time per second: 1 is real time, 0 holds still, negative runs backwards. */
|
|
118
|
+
get speed(): number;
|
|
119
|
+
set speed(value: number);
|
|
120
|
+
/** `compressed` (the default: every direction real, the distances squeezed) or `true` (real distances and sizes). */
|
|
121
|
+
get scale(): ScaleMode;
|
|
122
|
+
set scale(value: ScaleMode);
|
|
123
|
+
get labels(): boolean;
|
|
124
|
+
set labels(value: boolean);
|
|
125
|
+
get orbits(): boolean;
|
|
126
|
+
set orbits(value: boolean);
|
|
127
|
+
/** How the bodies are drawn: `realistic` (shaded from the body's real colours and features) or `painted` (public-domain surface maps). */
|
|
128
|
+
get look(): "realistic" | "painted";
|
|
129
|
+
set look(value: "realistic" | "painted");
|
|
130
|
+
/** How the Earth is lit: `sun` (true, the default) or `lit` (as if by daylight from the camera's side, so the night side is never a black frame). The Sun, the Moon and the planets keep their true places. */
|
|
131
|
+
get light(): SpaceLight;
|
|
132
|
+
set light(value: SpaceLight);
|
|
133
|
+
/**
|
|
134
|
+
* The shared controls' camera: yaw and tilt turn the view (the Earth's surface moves right for a drag right and up for a drag up), zoom brings the camera in (1 shows the body looked at, less shows the sky round it). Pan is not used. A turn that
|
|
135
|
+
* moves nothing on the screen by half a pixel is kept for the next draw but does not cause one unless `final` is true (the default).
|
|
136
|
+
*
|
|
137
|
+
* @param view - The controls' yaw and tilt in degrees and zoom.
|
|
138
|
+
* @param final - False for the frames of a turn that is still going on (Auto-turn, a drag); true when it has settled.
|
|
139
|
+
*/
|
|
140
|
+
setView(view: {
|
|
141
|
+
yaw: number;
|
|
142
|
+
tilt: number;
|
|
143
|
+
zoom: number;
|
|
144
|
+
}, final?: boolean): void;
|
|
145
|
+
/** The body the camera looks at (`earth`, `sun`, `moon`, `mercury` to `neptune`, `pluto`): at zoom 1 it fills the view; the yaw and tilt turn the camera round it. */
|
|
146
|
+
get body(): SpaceBody;
|
|
147
|
+
set body(name: SpaceBody);
|
|
148
|
+
/** The words shown beside each body, for a page in another language (`{ mars: "火星" }`). A body left out keeps its name in the element's `lang`. */
|
|
149
|
+
get bodyNames(): Partial<Record<SpaceBody, string>>;
|
|
150
|
+
set bodyNames(value: Partial<Record<SpaceBody, string>>);
|
|
151
|
+
/** What a screen reader hears after a body's name: "choose to look at it" by default, or the page's own words. */
|
|
152
|
+
get bodyHint(): string;
|
|
153
|
+
set bodyHint(value: string);
|
|
154
|
+
/** The name, radius and distance from the Earth of a body now, for a page's own caption. */
|
|
155
|
+
bodyInfo(id: SpaceBody): BodyInfo;
|
|
156
|
+
/**
|
|
157
|
+
* Ride along with a body, a moon or a moving point of your own. By default the camera sits at it and looks at the body it goes round, with the way it is going at the top of the picture, at its real place for the moment shown,
|
|
158
|
+
* so the ground slides beneath as it moves along its orbit. A drag looks about from there (a drag right turns the camera to its left and a drag up tips it towards the bottom of its picture, so the ground follows the pointer), the shared
|
|
159
|
+
* controls' zoom narrows the view. A body of the view (`"moon"`, `"mars"`) goes round the Earth; a moon (`"io"`) goes round its planet; a point of your own (`{ at(ms) }`, a satellite, a probe) goes round `around` (the Earth by default) and the
|
|
160
|
+
* element knows nothing of what it is. Another call switches smoothly; `null` stops. The draw rate follows how fast the picture moves, never more than 30 a second (one a second for a reader who asked for reduced motion), and nothing is drawn out of sight.
|
|
161
|
+
*
|
|
162
|
+
* @param target - A body name, a moon name, a point, or `null` to stop.
|
|
163
|
+
* @param options - `view`, `look`, `distanceKm`, `around`, `smooth` (see `RideOptions`).
|
|
164
|
+
*/
|
|
165
|
+
ride(target: RideTarget | null, options?: RideOptions): void;
|
|
166
|
+
/** What the camera is riding along with now, or null. */
|
|
167
|
+
get riding(): Riding | null;
|
|
168
|
+
/** The zoom that shows a part of the sky: the Earth alone, the Moon's orbit, the Sun, the planets out to Mars, all of them, or a planet's nearer moons, at this scale and moment. */
|
|
169
|
+
zoomFor(preset: SpacePreset): number;
|
|
170
|
+
/** What the element is doing, for a page or a test. */
|
|
171
|
+
get stats(): {
|
|
172
|
+
state: SpaceState;
|
|
173
|
+
draws: number;
|
|
174
|
+
contexts: number;
|
|
175
|
+
canvas: {
|
|
176
|
+
width: number;
|
|
177
|
+
height: number;
|
|
178
|
+
pixels: number;
|
|
179
|
+
};
|
|
180
|
+
/** How far the camera is from the body it looks at, in that body's radii. */
|
|
181
|
+
distance: number;
|
|
182
|
+
assets: {
|
|
183
|
+
entries: number;
|
|
184
|
+
refs: number;
|
|
185
|
+
};
|
|
186
|
+
time: number;
|
|
187
|
+
/** How many frames the ephemeris has worked out. */
|
|
188
|
+
lookups: number;
|
|
189
|
+
/** The camera as the last draw left it: its place in Earth radii from the Earth's centre, and its field of view in degrees. */
|
|
190
|
+
camera: {
|
|
191
|
+
position: [number, number, number];
|
|
192
|
+
fov: number;
|
|
193
|
+
};
|
|
194
|
+
/** What the painter has made at the last draw: the bodies with a drawing, the moons shown round a planet that is near, and the moons made and not yet let go. */
|
|
195
|
+
bodies: {
|
|
196
|
+
look: string;
|
|
197
|
+
painted: number;
|
|
198
|
+
moons: number;
|
|
199
|
+
held: number;
|
|
200
|
+
};
|
|
201
|
+
ride: {
|
|
202
|
+
riding: boolean;
|
|
203
|
+
lost: boolean;
|
|
204
|
+
gliding: boolean;
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
declare global {
|
|
209
|
+
interface HTMLElementTagNameMap {
|
|
210
|
+
"wakusei-space": WakuseiSpace;
|
|
211
|
+
}
|
|
212
|
+
}
|