@johnmorrisdotca/wakusei-planets 0.17.2 → 0.20.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 (53) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/NOTICE.md +8 -4
  3. package/README.md +9 -5
  4. package/dist/calendar.d.ts +119 -0
  5. package/dist/calendar.js +154 -0
  6. package/dist/clock.d.ts +244 -0
  7. package/dist/clock.js +326 -0
  8. package/dist/coordinates.d.ts +177 -0
  9. package/dist/coordinates.js +169 -0
  10. package/dist/data/lunar.d.ts +4 -0
  11. package/dist/data/lunar.js +548 -0
  12. package/dist/data/orbits.d.ts +5 -1
  13. package/dist/data/orbits.js +26 -26
  14. package/dist/data/pluto.d.ts +6 -0
  15. package/dist/data/pluto.js +29 -0
  16. package/dist/data/tables.d.ts +41 -0
  17. package/dist/data/tables.js +37 -0
  18. package/dist/data/vsop.d.ts +21 -0
  19. package/dist/data/vsop.js +27 -0
  20. package/dist/element.d.ts +5 -3
  21. package/dist/element.js +22 -9
  22. package/dist/ephemeris.d.ts +4 -16
  23. package/dist/ephemeris.js +76 -33
  24. package/dist/live.js +1 -1
  25. package/dist/mars.d.ts +41 -0
  26. package/dist/mars.js +52 -0
  27. package/dist/scales.d.ts +46 -0
  28. package/dist/scales.js +75 -0
  29. package/dist/sidereal.d.ts +66 -0
  30. package/dist/sidereal.js +88 -0
  31. package/dist/sky/engine.d.ts +46 -0
  32. package/dist/sky/engine.js +145 -0
  33. package/dist/sky/events.d.ts +37 -0
  34. package/dist/sky/events.js +133 -0
  35. package/dist/suncalc-legacy.d.ts +187 -0
  36. package/dist/suncalc-legacy.js +168 -0
  37. package/dist/suncalc.d.ts +209 -0
  38. package/dist/suncalc.js +173 -0
  39. package/dist/tables/all.d.ts +2 -0
  40. package/dist/tables/all.js +2 -0
  41. package/dist/tables/ceres.d.ts +1 -0
  42. package/dist/tables/ceres.js +57 -0
  43. package/dist/tables/dwarfs.d.ts +1 -0
  44. package/dist/tables/dwarfs.js +59 -0
  45. package/dist/theory.d.ts +20 -0
  46. package/dist/theory.js +98 -0
  47. package/dist/time.d.ts +6 -0
  48. package/dist/time.js +7 -0
  49. package/dist/version.d.ts +1 -1
  50. package/dist/version.js +1 -1
  51. package/dist/when.d.ts +16 -0
  52. package/dist/when.js +18 -0
  53. package/package.json +71 -5
package/dist/theory.js ADDED
@@ -0,0 +1,98 @@
1
+ // The two theories the rest is built on, kept apart so that the sun and moon times import them and nothing else: the planets' VSOP87B series (Bretagnon and Francou, IMCCE, data/vsop.ts) and the Moon's
2
+ // ELP2000-82B (Chapront-Touze and Chapront, IMCCE, data/lunar.ts), both in terrestrial time. Pure: no DOM, no three.js.
3
+ import { LUNAR_MAIN, LUNAR_PERIODIC } from "./data/lunar.js";
4
+ import { VSOP_EARTH } from "./data/vsop.js";
5
+ import { toTerrestrialTime } from "./clock.js";
6
+ /** Milliseconds since 1970 at J2000.0 (2000-01-01 12:00 TT, taken as UTC). */
7
+ const J2000 = Date.UTC(2000, 0, 1, 12);
8
+ const DAY = 86_400_000;
9
+ const centuries = (ms) => (ms - J2000) / (DAY * 36525);
10
+ /** A planet from its VSOP87B series: longitude, latitude and radius at a moment in terrestrial time, as x, y, z in the J2000 ecliptic. */
11
+ export function vsopPosition(series, terrestrialMs) {
12
+ const t = (terrestrialMs - J2000) / (365_250 * DAY);
13
+ const spherical = [0, 0, 0];
14
+ for (let k = 0; k < 3; k += 1) {
15
+ let sum = 0;
16
+ let power = 1;
17
+ for (const terms of series[k]) {
18
+ let s = 0;
19
+ for (const [amplitude, phase, frequency] of terms)
20
+ s += amplitude * Math.cos(phase + frequency * t);
21
+ sum += power * s;
22
+ power *= t;
23
+ }
24
+ spherical[k] = sum;
25
+ }
26
+ const [longitude, latitude, radius] = spherical;
27
+ const cosLatitude = Math.cos(latitude);
28
+ return [radius * cosLatitude * Math.cos(longitude), radius * cosLatitude * Math.sin(longitude), radius * Math.sin(latitude)];
29
+ }
30
+ /** The Earth's heliocentric place (J2000 ecliptic, au) at a UTC instant: the VSOP87B series run in terrestrial time. */
31
+ export function earthPosition(ms) {
32
+ return vsopPosition(VSOP_EARTH, toTerrestrialTime(ms));
33
+ }
34
+ const ARCSEC = Math.PI / 648000;
35
+ const dms = (d, m, sec) => ((d + m / 60 + sec / 3600) * Math.PI) / 180;
36
+ // The mean arguments of ELP2000-82B (Chapront-Touze and Chapront), each as a polynomial in Julian centuries of terrestrial time from J2000, in radians:
37
+ // the Moon's mean longitude, its node and its perigee, the Earth–Moon barycentre's mean longitude and the Sun's perigee, then the planets' mean longitudes.
38
+ const LUNAR_W1 = [dms(218, 18, 59.95571), 1732559343.73604 * ARCSEC, -5.8883 * ARCSEC, 0.6604e-2 * ARCSEC, -0.3169e-4 * ARCSEC];
39
+ const LUNAR_W2 = [dms(83, 21, 11.67475), 14643420.2632 * ARCSEC, -38.2776 * ARCSEC, -0.45047e-1 * ARCSEC, 0.21301e-3 * ARCSEC];
40
+ const LUNAR_W3 = [dms(125, 2, 40.39816), -6967919.3622 * ARCSEC, 6.3622 * ARCSEC, 0.7625e-2 * ARCSEC, -0.3586e-4 * ARCSEC];
41
+ const LUNAR_EARTH = [dms(100, 27, 59.22059), 129597742.2758 * ARCSEC, -0.0202 * ARCSEC, 0.9e-5 * ARCSEC, 0.15e-6 * ARCSEC];
42
+ const LUNAR_PERIGEE = [dms(102, 56, 14.42753), 1161.2283 * ARCSEC, 0.5327 * ARCSEC, -0.138e-3 * ARCSEC, 0];
43
+ /** Delaunay's arguments D, l', l and F as polynomials: by power of time, then by argument. */
44
+ const LUNAR_DELAUNAY = LUNAR_W1.map((w1, k) => [w1 - LUNAR_EARTH[k] + (k === 0 ? Math.PI : 0), LUNAR_EARTH[k] - LUNAR_PERIGEE[k], w1 - LUNAR_W2[k], w1 - LUNAR_W3[k]]);
45
+ const LUNAR_ZETA = [LUNAR_W1[0], LUNAR_W1[1] + 5029.0966 * ARCSEC];
46
+ const LUNAR_PLANET_0 = [dms(252, 15, 3.25986), dms(181, 58, 47.28305), LUNAR_EARTH[0], dms(355, 25, 59.78866), dms(34, 21, 5.34212), dms(50, 4, 38.89694), dms(314, 3, 18.01841), dms(304, 20, 55.19575)];
47
+ const LUNAR_PLANET_1 = [538101628.68898, 210664136.43355, 129597742.2758, 68905077.59284, 10925660.42861, 4399609.65932, 1542481.19393, 786550.32074].map((rate) => rate * ARCSEC);
48
+ /** The ratio of the Moon's mean distance in the fitted theory to the one the series are written for. */
49
+ const LUNAR_DISTANCE_SCALE = 384747.9806448954 / 384747.9806743165;
50
+ /**
51
+ * The Moon's position from the Earth's centre (J2000 mean ecliptic and equinox, kilometres), from the lunar solution ELP2000-82B (Chapront-Touze and Chapront, IMCCE) cut to its 540 largest terms and run in terrestrial time: within a few arc-seconds of Horizons from 1800 to 2200.
52
+ * @param ms - The instant, in milliseconds since 1970 (UTC).
53
+ * @returns The position as x, y, z in kilometres.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { moonGeocentric } from "@johnmorrisdotca/wakusei-planets";
58
+ *
59
+ * const [x, y, z] = moonGeocentric(Date.UTC(2026, 10, 2));
60
+ * console.log(Math.round(Math.hypot(x, y, z)) > 350000);
61
+ * ```
62
+ */
63
+ export function moonGeocentric(ms) {
64
+ const T = centuries(toTerrestrialTime(ms));
65
+ const poly = (c) => c[0] + T * (c[1] + T * (c[2] + T * (c[3] + T * c[4])));
66
+ // the arguments D, l', l, F for the main problem (to the fourth power of time), and for the perturbations (to the first) with zeta and the planets
67
+ const full = [0, 1, 2, 3].map((i) => LUNAR_DELAUNAY[0][i] + T * (LUNAR_DELAUNAY[1][i] + T * (LUNAR_DELAUNAY[2][i] + T * (LUNAR_DELAUNAY[3][i] + T * LUNAR_DELAUNAY[4][i]))));
68
+ const slow = [...[0, 1, 2, 3].map((i) => LUNAR_DELAUNAY[0][i] + T * LUNAR_DELAUNAY[1][i]), LUNAR_ZETA[0] + T * LUNAR_ZETA[1], ...LUNAR_PLANET_0.map((p, i) => p + T * LUNAR_PLANET_1[i])];
69
+ const sums = [0, 0, 0];
70
+ for (const term of LUNAR_MAIN) {
71
+ const c = term[0];
72
+ sums[c] = sums[c] + term[1] * Math.sin(term[2] * full[0] + term[3] * full[1] + term[4] * full[2] + term[5] * full[3] + (c === 2 ? Math.PI / 2 : 0));
73
+ }
74
+ for (const term of LUNAR_PERIODIC) {
75
+ const c = term[0];
76
+ let y = (term[3] * Math.PI) / 180;
77
+ for (let j = 0; j < 13; j += 1)
78
+ y += term[4 + j] * slow[j];
79
+ const power = term[1];
80
+ sums[c] = sums[c] + term[2] * (power === 0 ? 1 : power === 1 ? T : T * T) * Math.sin(y);
81
+ }
82
+ const lon = sums[0] * ARCSEC + poly(LUNAR_W1);
83
+ const lat = sums[1] * ARCSEC;
84
+ const dist = sums[2] * LUNAR_DISTANCE_SCALE;
85
+ const x1 = dist * Math.cos(lat) * Math.cos(lon);
86
+ const x2 = dist * Math.cos(lat) * Math.sin(lon);
87
+ const x3 = dist * Math.sin(lat);
88
+ // the plane of the mean ecliptic of date to J2000, by the series' own precession matrix
89
+ let pw = T * (0.10180391e-4 + T * (0.47020439e-6 + T * (-0.5417367e-9 + T * (-0.2507948e-11 + T * 0.463486e-14))));
90
+ let qw = T * (-0.113469002e-3 + T * (0.12372674e-6 + T * (0.1265417e-8 + T * (-0.1371808e-11 + T * -0.320334e-14))));
91
+ const ra = 2 * Math.sqrt(1 - pw * pw - qw * qw);
92
+ const pwqw = 2 * pw * qw;
93
+ const pw2 = 1 - 2 * pw * pw;
94
+ const qw2 = 1 - 2 * qw * qw;
95
+ pw *= ra;
96
+ qw *= ra;
97
+ return [pw2 * x1 + pwqw * x2 + pw * x3, pwqw * x1 + qw2 * x2 - qw * x3, -pw * x1 + qw * x2 + (pw2 + qw2 - 1) * x3];
98
+ }
package/dist/time.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { B1950_JD, J2000_JD, J2000_MS, UNIX_EPOCH_JULIAN_DATE, deltaT, fromJulianDate, fromJulianDayAndMilliseconds, julian, julianCenturies, julianMillennia, modifiedJulianDate, taiMinusUtc, toDate, toJulianDate, toJulianDay, toMillisecondsInJulianDay, toTerrestrialTime, ttMinusUtc, } from "./clock.ts";
2
+ export { dayOfWeek, dayOfYear, daysInMonth, fromCalendar, isLeapYear, toCalendar, type Calendar, type CivilTime } from "./calendar.ts";
3
+ export { convertTimeScale, tdbMinusTt, type TimeScale } from "./scales.ts";
4
+ export { equationOfTheEquinoxes, greenwichApparentSiderealTime, greenwichMeanSiderealTime, localSiderealTime } from "./sidereal.ts";
5
+ export { coordinatedMarsTime, marsLocalMeanSolarTime, marsSolDate } from "./mars.ts";
6
+ export type { When } from "./when.ts";
package/dist/time.js ADDED
@@ -0,0 +1,7 @@
1
+ // Time for the sky, one public entry: Julian dates (and the `julian` package's functions under the same names), calendars, time scales, sidereal time and Mars time.
2
+ // Pure: no DOM, no three.js, nothing to install. The parts are in clock.ts, calendar.ts, scales.ts, sidereal.ts and mars.ts.
3
+ export { B1950_JD, J2000_JD, J2000_MS, UNIX_EPOCH_JULIAN_DATE, deltaT, fromJulianDate, fromJulianDayAndMilliseconds, julian, julianCenturies, julianMillennia, modifiedJulianDate, taiMinusUtc, toDate, toJulianDate, toJulianDay, toMillisecondsInJulianDay, toTerrestrialTime, ttMinusUtc, } from "./clock.js";
4
+ export { dayOfWeek, dayOfYear, daysInMonth, fromCalendar, isLeapYear, toCalendar } from "./calendar.js";
5
+ export { convertTimeScale, tdbMinusTt } from "./scales.js";
6
+ export { equationOfTheEquinoxes, greenwichApparentSiderealTime, greenwichMeanSiderealTime, localSiderealTime } from "./sidereal.js";
7
+ export { coordinatedMarsTime, marsLocalMeanSolarTime, marsSolDate } from "./mars.js";
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.17.2";
1
+ export declare const VERSION = "0.20.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.17.2";
1
+ export const VERSION = "0.20.0";
package/dist/when.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A moment: a `Date` or a number of milliseconds since 1970 (UTC, as JavaScript counts).
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { toJulianDate, type When } from "@johnmorrisdotca/wakusei-planets/time";
7
+ *
8
+ * const when: When = new Date(Date.UTC(2000, 0, 1, 12));
9
+ * console.log(toJulianDate(when) === toJulianDate(when.getTime()));
10
+ * ```
11
+ */
12
+ export type When = Date | number;
13
+ /**
14
+ * A moment as milliseconds since 1970. A `Date` is never changed. An invalid `Date`, a number that is not finite or anything else throws, naming the argument and the value.
15
+ */
16
+ export declare function moment(when: When, name?: string): number;
package/dist/when.js ADDED
@@ -0,0 +1,18 @@
1
+ // A moment as the sky functions take it: a `Date` or milliseconds since 1970, which is UTC as JavaScript counts it (leap seconds are not counted). Pure: no DOM, no three.js.
2
+ /**
3
+ * A moment as milliseconds since 1970. A `Date` is never changed. An invalid `Date`, a number that is not finite or anything else throws, naming the argument and the value.
4
+ */
5
+ export function moment(when, name = "when") {
6
+ if (typeof when === "number") {
7
+ if (Number.isFinite(when))
8
+ return when;
9
+ }
10
+ else if (typeof when?.getTime === "function") {
11
+ const ms = when.getTime();
12
+ if (Number.isFinite(ms))
13
+ return ms;
14
+ }
15
+ else
16
+ throw new TypeError(`${name} must be a Date or a number of milliseconds since 1970, got ${typeof when}`);
17
+ throw new RangeError(`${name} must be a valid Date or a finite number of milliseconds since 1970, got ${String(when)}`);
18
+ }
package/package.json CHANGED
@@ -1,25 +1,50 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.17.2",
3
+ "version": "0.20.0",
4
4
  "description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
5
5
  "keywords": [
6
6
  "planets",
7
+ "planet",
7
8
  "solar-system",
8
9
  "sun",
9
10
  "moon",
10
11
  "moons",
12
+ "mercury",
13
+ "venus",
14
+ "earth",
15
+ "mars",
11
16
  "jupiter",
12
17
  "saturn",
13
- "mars",
18
+ "uranus",
19
+ "neptune",
20
+ "pluto",
21
+ "dwarf-planets",
14
22
  "astronomy",
15
23
  "ephemeris",
24
+ "heliocentric",
25
+ "orbit",
26
+ "orbits",
27
+ "rotation",
28
+ "celestial",
29
+ "space",
30
+ "nasa",
31
+ "jpl",
16
32
  "web-component",
17
33
  "custom-element",
18
34
  "svg",
19
35
  "three",
20
36
  "webgl",
37
+ "3d",
21
38
  "line-drawing",
22
- "typescript"
39
+ "typescript",
40
+ "javascript",
41
+ "browser",
42
+ "julian-date",
43
+ "julian-day",
44
+ "epoch",
45
+ "time-scales",
46
+ "leap-seconds",
47
+ "sidereal-time"
23
48
  ],
24
49
  "homepage": "https://johnmorrisdotca.github.io/wakusei-planets/",
25
50
  "repository": {
@@ -36,9 +61,11 @@
36
61
  "./dist/element.js",
37
62
  "./dist/portrait/element.js",
38
63
  "./dist/bodies/*.js",
64
+ "./dist/tables/*.js",
39
65
  "./src/element.ts",
40
66
  "./src/portrait/element.ts",
41
- "./src/bodies/*.ts"
67
+ "./src/bodies/*.ts",
68
+ "./src/tables/*.ts"
42
69
  ],
43
70
  "main": "./dist/index.js",
44
71
  "module": "./dist/index.js",
@@ -59,6 +86,36 @@
59
86
  "import": "./dist/portrait/element.js",
60
87
  "default": "./dist/portrait/element.js"
61
88
  },
89
+ "./time": {
90
+ "types": "./dist/time.d.ts",
91
+ "import": "./dist/time.js",
92
+ "default": "./dist/time.js"
93
+ },
94
+ "./suncalc": {
95
+ "types": "./dist/suncalc.d.ts",
96
+ "import": "./dist/suncalc.js",
97
+ "default": "./dist/suncalc.js"
98
+ },
99
+ "./suncalc/legacy": {
100
+ "types": "./dist/suncalc-legacy.d.ts",
101
+ "import": "./dist/suncalc-legacy.js",
102
+ "default": "./dist/suncalc-legacy.js"
103
+ },
104
+ "./tables": {
105
+ "types": "./dist/tables/all.d.ts",
106
+ "import": "./dist/tables/all.js",
107
+ "default": "./dist/tables/all.js"
108
+ },
109
+ "./tables/ceres": {
110
+ "types": "./dist/tables/ceres.d.ts",
111
+ "import": "./dist/tables/ceres.js",
112
+ "default": "./dist/tables/ceres.js"
113
+ },
114
+ "./tables/dwarfs": {
115
+ "types": "./dist/tables/dwarfs.d.ts",
116
+ "import": "./dist/tables/dwarfs.js",
117
+ "default": "./dist/tables/dwarfs.js"
118
+ },
62
119
  "./look": {
63
120
  "types": "./dist/scene/look.d.ts",
64
121
  "import": "./dist/scene/look.js",
@@ -169,6 +226,11 @@
169
226
  "types": "./dist/bodies/earth.d.ts",
170
227
  "import": "./dist/bodies/earth.js",
171
228
  "default": "./dist/bodies/earth.js"
229
+ },
230
+ "./coordinates": {
231
+ "types": "./dist/coordinates.d.ts",
232
+ "import": "./dist/coordinates.js",
233
+ "default": "./dist/coordinates.js"
172
234
  }
173
235
  },
174
236
  "files": [
@@ -194,6 +256,7 @@
194
256
  "site": "pnpm build && node scripts/site.ts",
195
257
  "dev": "pnpm site && node scripts/dev.ts",
196
258
  "test:demo": "pnpm site && node scripts/docs-site.mjs build && playwright test --project=chromium-desk --project=chromium-phone --project=webkit-desk --project=webkit-phone",
259
+ "test:demo:one": "pnpm site && node scripts/docs-site.mjs build && playwright test",
197
260
  "test:freeze": "pnpm site && playwright test --project=freeze",
198
261
  "test:soak": "pnpm site && playwright test --project=soak",
199
262
  "screenshots": "pnpm site && node scripts/screenshots.ts",
@@ -221,11 +284,14 @@
221
284
  "astronomy-engine": "2.1.19",
222
285
  "esbuild": "^0.25.12",
223
286
  "eslint": "^9.0.0",
287
+ "julian": "0.2.0",
224
288
  "marked": "^18.1.2",
225
289
  "pagefind": "^1.6.0",
226
290
  "react": "^19.3.1",
227
291
  "react-dom": "^19.3.1",
228
292
  "rxjs": "^7.8.2",
293
+ "suncalc": "2.1.2",
294
+ "suncalc1": "npm:suncalc@1.9.0",
229
295
  "svelte": "^5.57.3",
230
296
  "three": "0.186.1",
231
297
  "typescript": "^5.9.0",
@@ -240,7 +306,7 @@
240
306
  },
241
307
  "packageManager": "pnpm@10.28.0",
242
308
  "dependencies": {
243
- "@johnmorrisdotca/kazoku-ui": "^0.15.1"
309
+ "@johnmorrisdotca/kazoku-ui": "^0.19.0"
244
310
  },
245
311
  "peerDependencies": {
246
312
  "@johnmorrisdotca/chikyu-earth": ">=0.10.0",