@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.
Files changed (113) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/NOTICE.md +14 -3
  3. package/README.md +39 -6
  4. package/dist/bodies/earth.js +13 -5
  5. package/dist/calendar.d.ts +119 -0
  6. package/dist/calendar.js +155 -0
  7. package/dist/clock.d.ts +244 -0
  8. package/dist/clock.js +325 -0
  9. package/dist/coordinates.d.ts +172 -0
  10. package/dist/coordinates.js +170 -0
  11. package/dist/craft/cassini.d.ts +1 -0
  12. package/dist/craft/cassini.js +1131 -0
  13. package/dist/craft/galileo.d.ts +1 -0
  14. package/dist/craft/galileo.js +224 -0
  15. package/dist/craft/juno.d.ts +1 -0
  16. package/dist/craft/juno.js +640 -0
  17. package/dist/craft/newhorizons.d.ts +1 -0
  18. package/dist/craft/newhorizons.js +18 -0
  19. package/dist/craft/parker.d.ts +1 -0
  20. package/dist/craft/parker.js +221 -0
  21. package/dist/craft/pioneer10.d.ts +1 -0
  22. package/dist/craft/pioneer10.js +24 -0
  23. package/dist/craft/pioneer11.d.ts +1 -0
  24. package/dist/craft/pioneer11.js +34 -0
  25. package/dist/craft/voyager1.d.ts +1 -0
  26. package/dist/craft/voyager1.js +28 -0
  27. package/dist/craft/voyager2.d.ts +1 -0
  28. package/dist/craft/voyager2.js +43 -0
  29. package/dist/craft/webb.d.ts +1 -0
  30. package/dist/craft/webb.js +28 -0
  31. package/dist/data/craft.d.ts +23 -0
  32. package/dist/data/craft.js +53 -0
  33. package/dist/data/lunar.d.ts +4 -0
  34. package/dist/data/lunar.js +548 -0
  35. package/dist/data/pluto.d.ts +6 -0
  36. package/dist/data/pluto.js +29 -0
  37. package/dist/data/stars.d.ts +4 -0
  38. package/dist/data/stars.js +5088 -0
  39. package/dist/data/tables.d.ts +41 -0
  40. package/dist/data/tables.js +37 -0
  41. package/dist/data/vsop.d.ts +19 -1
  42. package/dist/data/vsop.js +25 -8
  43. package/dist/element.d.ts +2 -23
  44. package/dist/element.js +75 -110
  45. package/dist/ephemeris.d.ts +22 -14
  46. package/dist/ephemeris.js +106 -58
  47. package/dist/index.d.ts +1 -1
  48. package/dist/index.js +1 -1
  49. package/dist/mars.d.ts +41 -0
  50. package/dist/mars.js +52 -0
  51. package/dist/portrait/element.d.ts +1 -0
  52. package/dist/portrait/element.js +27 -39
  53. package/dist/scales.d.ts +46 -0
  54. package/dist/scales.js +75 -0
  55. package/dist/scene/basis.d.ts +3 -0
  56. package/dist/scene/basis.js +4 -0
  57. package/dist/scene/body.d.ts +2 -4
  58. package/dist/scene/body.js +55 -67
  59. package/dist/scene/fallback.d.ts +4 -0
  60. package/dist/scene/fallback.js +5 -0
  61. package/dist/scene/painter.js +10 -23
  62. package/dist/scene/store.d.ts +2 -2
  63. package/dist/scene/textures.d.ts +30 -0
  64. package/dist/scene/textures.js +47 -0
  65. package/dist/sidereal.d.ts +70 -0
  66. package/dist/sidereal.js +94 -0
  67. package/dist/sky/engine.d.ts +37 -0
  68. package/dist/sky/engine.js +116 -0
  69. package/dist/sky/events.d.ts +37 -0
  70. package/dist/sky/events.js +133 -0
  71. package/dist/sky/frames.d.ts +3 -0
  72. package/dist/sky/frames.js +26 -0
  73. package/dist/sky/types.d.ts +20 -0
  74. package/dist/sky/types.js +1 -0
  75. package/dist/space/aim.d.ts +18 -0
  76. package/dist/space/aim.js +28 -0
  77. package/dist/space/element.d.ts +212 -0
  78. package/dist/space/element.js +524 -0
  79. package/dist/space/frame.d.ts +152 -0
  80. package/dist/space/frame.js +169 -0
  81. package/dist/space/index.d.ts +4 -0
  82. package/dist/space/index.js +5 -0
  83. package/dist/space/ride.d.ts +89 -0
  84. package/dist/space/ride.js +58 -0
  85. package/dist/space/scale.d.ts +126 -0
  86. package/dist/space/scale.js +139 -0
  87. package/dist/space/scene.d.ts +189 -0
  88. package/dist/space/scene.js +422 -0
  89. package/dist/spacecraft-facts.d.ts +114 -0
  90. package/dist/spacecraft-facts.js +215 -0
  91. package/dist/spacecraft.d.ts +134 -0
  92. package/dist/spacecraft.js +198 -0
  93. package/dist/stars.d.ts +160 -0
  94. package/dist/stars.js +193 -0
  95. package/dist/suncalc-legacy.d.ts +187 -0
  96. package/dist/suncalc-legacy.js +168 -0
  97. package/dist/suncalc.d.ts +209 -0
  98. package/dist/suncalc.js +167 -0
  99. package/dist/tables/all.d.ts +2 -0
  100. package/dist/tables/all.js +2 -0
  101. package/dist/tables/ceres.d.ts +1 -0
  102. package/dist/tables/ceres.js +57 -0
  103. package/dist/tables/dwarfs.d.ts +1 -0
  104. package/dist/tables/dwarfs.js +59 -0
  105. package/dist/theory.d.ts +20 -0
  106. package/dist/theory.js +98 -0
  107. package/dist/time.d.ts +6 -108
  108. package/dist/time.js +7 -180
  109. package/dist/version.d.ts +1 -1
  110. package/dist/version.js +1 -1
  111. package/dist/when.d.ts +16 -0
  112. package/dist/when.js +13 -0
  113. package/package.json +95 -4
@@ -0,0 +1,168 @@
1
+ // The sun and moon from a place with the conventions of suncalc 1.x, so code written for it changes only its import: angles in radians, the azimuth measured from south toward west, the Sun's altitude
2
+ // without refraction and the Moon's with it, an event that does not happen as an invalid `Date`, the Moon's day running from midnight (local, or UTC) for 24 hours, and a bright-limb angle that is
3
+ // negative while the Moon waxes. The numbers come from the same engine as `suncalc` (VSOP87B and ELP2000-82B, seconds of time). Pure: no DOM, no three.js.
4
+ import { horizontalOf, moonEquatorial, moonPhase, refraction, sunEquatorial } from "./sky/engine.js";
5
+ import { moment, moonDay, place, sunDay } from "./sky/events.js";
6
+ const RAD = Math.PI / 180;
7
+ /** An azimuth in degrees clockwise from north as radians from south toward west (south 0, west a quarter turn). */
8
+ const fromSouth = (azimuth) => (((azimuth - 180 + 540) % 360) - 180) * RAD;
9
+ /**
10
+ * The times suncalc 1 gives, as `[altitude in degrees, morning name, evening name]`.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { times } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
15
+ *
16
+ * console.log(times.length);
17
+ * ```
18
+ */
19
+ export const times = [
20
+ [-0.833, "sunrise", "sunset"],
21
+ [-0.3, "sunriseEnd", "sunsetStart"],
22
+ [-6, "dawn", "dusk"],
23
+ [-12, "nauticalDawn", "nauticalDusk"],
24
+ [-18, "nightEnd", "night"],
25
+ [6, "goldenHourEnd", "goldenHour"],
26
+ ];
27
+ /**
28
+ * Add a time to the ones `getTimes` gives: when the Sun reaches an altitude in degrees.
29
+ *
30
+ * @param angle - The altitude in degrees.
31
+ * @param riseName - The name when the Sun goes up through it.
32
+ * @param setName - The name when the Sun goes down through it.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { addTime, times } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
37
+ *
38
+ * addTime(-4, "morningBlue", "eveningBlue");
39
+ * console.log(times.some((row) => row[1] === "morningBlue"));
40
+ * ```
41
+ */
42
+ export function addTime(angle, riseName, setName) {
43
+ times.push([angle, riseName, setName]);
44
+ }
45
+ /**
46
+ * The Sun's place in the sky, as suncalc 1 gave it: the altitude has no refraction in it.
47
+ *
48
+ * @param date - The moment.
49
+ * @param lat - Degrees north.
50
+ * @param lng - Degrees east.
51
+ * @returns The azimuth in radians from south toward west and the altitude in radians.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { getPosition } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
56
+ *
57
+ * const { altitude } = getPosition(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
58
+ * console.log((altitude * 180 / Math.PI).toFixed(0));
59
+ * ```
60
+ */
61
+ export function getPosition(date, lat, lng) {
62
+ const ms = moment(date);
63
+ const h = horizontalOf(sunEquatorial(ms), ms, place(lat, lng));
64
+ return { azimuth: fromSouth(h.azimuth), altitude: h.altitude * RAD };
65
+ }
66
+ /**
67
+ * The Moon's place in the sky, as suncalc 1 gave it: the altitude includes refraction.
68
+ *
69
+ * @param date - The moment.
70
+ * @param lat - Degrees north.
71
+ * @param lng - Degrees east.
72
+ * @returns The azimuth and altitude in radians, the distance in kilometres and the parallactic angle in radians.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * import { getMoonPosition } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
77
+ *
78
+ * const { distance } = getMoonPosition(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7);
79
+ * console.log(Math.round(distance / 1000));
80
+ * ```
81
+ */
82
+ export function getMoonPosition(date, lat, lng) {
83
+ const ms = moment(date);
84
+ const moon = moonEquatorial(ms);
85
+ const h = horizontalOf(moon, ms, place(lat, lng));
86
+ return { azimuth: fromSouth(h.azimuth), altitude: (h.altitude + refraction(h.altitude)) * RAD, distance: moon.distanceKm, parallacticAngle: h.parallacticAngle * RAD };
87
+ }
88
+ /**
89
+ * The Moon's phase, as suncalc 1 gave it.
90
+ *
91
+ * @param date - The moment; now when left out.
92
+ * @returns The lit fraction, the phase 0 to 1 and the bright limb's angle in radians (negative while waxing).
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import { getMoonIllumination } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
97
+ *
98
+ * const { fraction, angle } = getMoonIllumination(new Date(Date.UTC(2026, 10, 24, 14)));
99
+ * console.log(fraction.toFixed(2), angle < 0);
100
+ * ```
101
+ */
102
+ export function getMoonIllumination(date = new Date()) {
103
+ const p = moonPhase(moment(date));
104
+ // suncalc 1 reckons the angle from the Moon's own side of the Sun, which makes it negative while the Moon waxes
105
+ const wrapped = (((p.angle + 180) % 360) + 360) % 360 - 180;
106
+ return { fraction: p.fraction, phase: p.phase, angle: (p.waxing ? -Math.abs(wrapped) : Math.abs(wrapped)) * RAD };
107
+ }
108
+ /**
109
+ * The Sun's times for the solar day nearest a moment, as suncalc 1 gave them: every time a `Date`, invalid when it does not happen.
110
+ *
111
+ * @param date - Any moment of the day.
112
+ * @param lat - Degrees north.
113
+ * @param lng - Degrees east.
114
+ * @param height - The observer's height in metres (default 0).
115
+ * @returns The times by name.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * import { getTimes } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
120
+ *
121
+ * const t = getTimes(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
122
+ * console.log(t.sunrise!.getTime() < t.sunset!.getTime());
123
+ * ```
124
+ */
125
+ export function getTimes(date, lat, lng, height = 0) {
126
+ const day = sunDay(moment(date), place(lat, lng, height), undefined, times);
127
+ const result = { solarNoon: new Date(day.noon), nadir: new Date(day.nadir) };
128
+ for (const [name, at] of day.events)
129
+ result[name] = new Date(at ?? Number.NaN);
130
+ return result;
131
+ }
132
+ /**
133
+ * The Moon's rise and set over the 24 hours from midnight of the moment's day, in the machine's zone or, with `inUTC`, in UTC.
134
+ *
135
+ * @param date - Any moment of the day.
136
+ * @param lat - Degrees north.
137
+ * @param lng - Degrees east.
138
+ * @param inUTC - Search the UTC day instead of the local one.
139
+ * @returns `rise` and `set` when they happen, and `alwaysUp` or `alwaysDown` when the Moon stays up or down.
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * import { getMoonTimes } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
144
+ *
145
+ * const t = getMoonTimes(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7, true);
146
+ * console.log(t.rise === undefined || t.rise instanceof Date);
147
+ * ```
148
+ */
149
+ export function getMoonTimes(date, lat, lng, inUTC = false) {
150
+ const day = new Date(moment(date));
151
+ if (inUTC)
152
+ day.setUTCHours(0, 0, 0, 0);
153
+ else
154
+ day.setHours(0, 0, 0, 0);
155
+ const start = day.getTime();
156
+ const observer = place(lat, lng);
157
+ const found = moonDay(start, start + 24 * 3_600_000, observer);
158
+ const result = {};
159
+ if (found.rise !== null)
160
+ result.rise = new Date(found.rise);
161
+ if (found.set !== null)
162
+ result.set = new Date(found.set);
163
+ if (found.alwaysUp)
164
+ result.alwaysUp = true;
165
+ if (found.alwaysDown)
166
+ result.alwaysDown = true;
167
+ return result;
168
+ }
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Where a body is in a place's sky: the azimuth in degrees clockwise from north (0 north, 90 east, 180 south, 270 west) and the apparent altitude (refraction included) in degrees.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { getPosition, type Position } from "@johnmorrisdotca/wakusei-planets/suncalc";
7
+ *
8
+ * const p: Position = getPosition(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
9
+ * console.log(p.altitude > 0);
10
+ * ```
11
+ */
12
+ export interface Position {
13
+ azimuth: number;
14
+ altitude: number;
15
+ }
16
+ /**
17
+ * The Moon in a place's sky: the Position, the Moon's distance in kilometres and the parallactic angle in degrees.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { getMoonPosition, type MoonPosition } from "@johnmorrisdotca/wakusei-planets/suncalc";
22
+ *
23
+ * const p: MoonPosition = getMoonPosition(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7);
24
+ * console.log(p.distance > 350000);
25
+ * ```
26
+ */
27
+ export interface MoonPosition extends Position {
28
+ distance: number;
29
+ parallacticAngle: number;
30
+ }
31
+ /**
32
+ * The names of the Sun's times that `getTimes` gives.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { type SunTimeName } from "@johnmorrisdotca/wakusei-planets/suncalc";
37
+ *
38
+ * const name: SunTimeName = "goldenHour";
39
+ * console.log(name);
40
+ * ```
41
+ */
42
+ export type SunTimeName = "sunrise" | "sunset" | "sunriseEnd" | "sunsetStart" | "dawn" | "dusk" | "nauticalDawn" | "nauticalDusk" | "nightEnd" | "night" | "goldenHourEnd" | "goldenHour";
43
+ /**
44
+ * The Sun's times for a day: each a `Date` or `null` when the Sun does not reach that height that day, `solarNoon` and `nadir` always there, and `alwaysUp` or `alwaysDown` when the Sun stays above or below the sunrise height all day.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { getTimes, type SunTimes } from "@johnmorrisdotca/wakusei-planets/suncalc";
49
+ *
50
+ * const t: SunTimes = getTimes(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
51
+ * console.log(t.sunrise instanceof Date, t.solarNoon instanceof Date);
52
+ * ```
53
+ */
54
+ export type SunTimes = Record<SunTimeName, Date | null> & {
55
+ solarNoon: Date;
56
+ nadir: Date;
57
+ alwaysUp?: boolean;
58
+ alwaysDown?: boolean;
59
+ [custom: string]: Date | boolean | null | undefined;
60
+ };
61
+ /**
62
+ * The Moon's illumination: the lit fraction 0 to 1, the phase 0 to 1 (0 new, 0.25 first quarter, 0.5 full, 0.75 last quarter), the position angle of the bright limb in degrees eastward from north, and whether it is waxing.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { getMoonIllumination, type MoonIllumination } from "@johnmorrisdotca/wakusei-planets/suncalc";
67
+ *
68
+ * const m: MoonIllumination = getMoonIllumination(new Date(Date.UTC(2026, 10, 24, 14)));
69
+ * console.log(m.fraction >= 0 && m.fraction <= 1);
70
+ * ```
71
+ */
72
+ export interface MoonIllumination {
73
+ fraction: number;
74
+ phase: number;
75
+ angle: number;
76
+ waxing: boolean;
77
+ }
78
+ /**
79
+ * The Moon's rise, set and transits over a day. An event that does not happen that day is absent; `alwaysUp` or `alwaysDown` is set when the Moon stays above or below the horizon all day.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * import { getMoonTimes, type MoonTimes } from "@johnmorrisdotca/wakusei-planets/suncalc";
84
+ *
85
+ * const t: MoonTimes = getMoonTimes(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7, 540);
86
+ * console.log(t.rise instanceof Date || t.alwaysUp === true || t.alwaysDown === true || t.rise === undefined);
87
+ * ```
88
+ */
89
+ export interface MoonTimes {
90
+ rise?: Date;
91
+ set?: Date;
92
+ transit?: Date;
93
+ lowerTransit?: Date;
94
+ alwaysUp?: boolean;
95
+ alwaysDown?: boolean;
96
+ }
97
+ /**
98
+ * The altitudes of the Sun's times in degrees: the morning name when it rises through the angle, the evening name when it sets through it. The ones at the horizon move with the observer's height.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * import { times } from "@johnmorrisdotca/wakusei-planets/suncalc";
103
+ *
104
+ * console.log(times.map((row) => row[1]).join(", "));
105
+ * ```
106
+ */
107
+ export declare const times: Array<[number, string, string]>;
108
+ /**
109
+ * Add a time to the ones `getTimes` gives: when the Sun reaches an altitude in degrees, going up under the morning name and going down under the evening name.
110
+ *
111
+ * @param angle - The altitude in degrees.
112
+ * @param riseName - The name of the time when the Sun goes up through it.
113
+ * @param setName - The name of the time when the Sun goes down through it.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * import { addTime, times } from "@johnmorrisdotca/wakusei-planets/suncalc";
118
+ *
119
+ * addTime(-4, "morningBlueHourEnd", "blueHour");
120
+ * console.log(times.some((row) => row[2] === "blueHour"));
121
+ * ```
122
+ */
123
+ export declare function addTime(angle: number, riseName: string, setName: string): void;
124
+ /**
125
+ * The Sun's place in the sky from a place on the Earth.
126
+ *
127
+ * @param date - The moment, as a `Date` (or milliseconds since 1970).
128
+ * @param lat - Degrees north, -90 to 90.
129
+ * @param lng - Degrees east (west negative).
130
+ * @returns The azimuth (degrees clockwise from north) and the apparent altitude (degrees).
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * import { getPosition } from "@johnmorrisdotca/wakusei-planets/suncalc";
135
+ *
136
+ * const { azimuth, altitude } = getPosition(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
137
+ * console.log(azimuth.toFixed(0), altitude.toFixed(0));
138
+ * ```
139
+ */
140
+ export declare function getPosition(date: Date | number, lat: number, lng: number): Position;
141
+ /**
142
+ * The Moon's place in the sky from a place on the Earth.
143
+ *
144
+ * @param date - The moment, as a `Date` (or milliseconds since 1970).
145
+ * @param lat - Degrees north, -90 to 90.
146
+ * @param lng - Degrees east (west negative).
147
+ * @returns The azimuth (degrees clockwise from north), apparent altitude (degrees), distance from the Earth's centre (kilometres) and parallactic angle (degrees).
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * import { getMoonPosition } from "@johnmorrisdotca/wakusei-planets/suncalc";
152
+ *
153
+ * const { distance } = getMoonPosition(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7);
154
+ * console.log(Math.round(distance / 1000));
155
+ * ```
156
+ */
157
+ export declare function getMoonPosition(date: Date | number, lat: number, lng: number): MoonPosition;
158
+ /**
159
+ * The Moon's phase.
160
+ *
161
+ * @param date - The moment, as a `Date` (or milliseconds since 1970); now when left out.
162
+ * @returns The lit fraction, the phase, the bright limb's position angle in degrees and whether it is waxing.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * import { getMoonIllumination } from "@johnmorrisdotca/wakusei-planets/suncalc";
167
+ *
168
+ * const { fraction, waxing } = getMoonIllumination(new Date(Date.UTC(2026, 10, 24, 14)));
169
+ * console.log(fraction.toFixed(2), waxing);
170
+ * ```
171
+ */
172
+ export declare function getMoonIllumination(date?: Date | number): MoonIllumination;
173
+ /**
174
+ * The Sun's times for a day at a place.
175
+ *
176
+ * @param date - Any moment of the day, as a `Date` (or milliseconds since 1970).
177
+ * @param lat - Degrees north, -90 to 90.
178
+ * @param lng - Degrees east (west negative).
179
+ * @param height - The observer's height above the horizon in metres (default 0): it lowers the sunrise and sunset altitudes by the dip of the horizon.
180
+ * @param utcOffset - Minutes east of UTC: when given the day is the local calendar day holding `date`; when left out it is the solar day (from one solar midnight to the next) holding `date`.
181
+ * @returns The times as `Date`s, `null` for one that does not happen that day, and `alwaysUp` or `alwaysDown` at the poles.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * import { getTimes } from "@johnmorrisdotca/wakusei-planets/suncalc";
186
+ *
187
+ * const t = getTimes(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1, 0, 60);
188
+ * console.log(t.sunrise!.toISOString().slice(0, 13));
189
+ * ```
190
+ */
191
+ export declare function getTimes(date: Date | number, lat: number, lng: number, height?: number, utcOffset?: number): SunTimes;
192
+ /**
193
+ * The Moon's rise, set and transits over a day at a place.
194
+ *
195
+ * @param date - Any moment of the day, as a `Date` (or milliseconds since 1970).
196
+ * @param lat - Degrees north, -90 to 90.
197
+ * @param lng - Degrees east (west negative).
198
+ * @param utcOffset - Minutes east of UTC: when given the day is the local calendar day holding `date`; when left out it is the solar day holding `date`.
199
+ * @returns `rise`, `set`, `transit` (the Moon highest) and `lowerTransit` (lowest) as `Date`s, each absent on a day without it, with `alwaysUp` or `alwaysDown` when the Moon never crosses the horizon.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * import { getMoonTimes } from "@johnmorrisdotca/wakusei-planets/suncalc";
204
+ *
205
+ * const t = getMoonTimes(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7, 540);
206
+ * console.log(Object.keys(t).length > 0);
207
+ * ```
208
+ */
209
+ export declare function getMoonTimes(date: Date | number, lat: number, lng: number, utcOffset?: number): MoonTimes;
@@ -0,0 +1,167 @@
1
+ // The sun and moon from a place, with the names, arguments and results of suncalc 2 (degrees, azimuth clockwise from north), written from the public methods on this package's own positions:
2
+ // the Sun from VSOP87B, the Moon from ELP2000-82B, with parallax, refraction and the Earth's turn. Its rise and set times are within half a second of JPL Horizons for both,
3
+ // where suncalc 2.1.2 is within 5 to 7 seconds (scripts/compare/rise-set.mjs). Pure: no DOM, no three.js. `import { getTimes } from "@johnmorrisdotca/wakusei-planets/suncalc"` instead of from "suncalc" changes nothing else.
4
+ import { horizontalOf, moonEquatorial, moonPhase, refraction, sunEquatorial } from "./sky/engine.js";
5
+ import { dayWindow, moment, moonDay, place, sunDay } from "./sky/events.js";
6
+ /**
7
+ * The altitudes of the Sun's times in degrees: the morning name when it rises through the angle, the evening name when it sets through it. The ones at the horizon move with the observer's height.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { times } from "@johnmorrisdotca/wakusei-planets/suncalc";
12
+ *
13
+ * console.log(times.map((row) => row[1]).join(", "));
14
+ * ```
15
+ */
16
+ export const times = [
17
+ [-0.833, "sunrise", "sunset"],
18
+ [-0.3, "sunriseEnd", "sunsetStart"],
19
+ [-6, "dawn", "dusk"],
20
+ [-12, "nauticalDawn", "nauticalDusk"],
21
+ [-18, "nightEnd", "night"],
22
+ [6, "goldenHourEnd", "goldenHour"],
23
+ ];
24
+ /**
25
+ * Add a time to the ones `getTimes` gives: when the Sun reaches an altitude in degrees, going up under the morning name and going down under the evening name.
26
+ *
27
+ * @param angle - The altitude in degrees.
28
+ * @param riseName - The name of the time when the Sun goes up through it.
29
+ * @param setName - The name of the time when the Sun goes down through it.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { addTime, times } from "@johnmorrisdotca/wakusei-planets/suncalc";
34
+ *
35
+ * addTime(-4, "morningBlueHourEnd", "blueHour");
36
+ * console.log(times.some((row) => row[2] === "blueHour"));
37
+ * ```
38
+ */
39
+ export function addTime(angle, riseName, setName) {
40
+ times.push([angle, riseName, setName]);
41
+ }
42
+ /**
43
+ * The Sun's place in the sky from a place on the Earth.
44
+ *
45
+ * @param date - The moment, as a `Date` (or milliseconds since 1970).
46
+ * @param lat - Degrees north, -90 to 90.
47
+ * @param lng - Degrees east (west negative).
48
+ * @returns The azimuth (degrees clockwise from north) and the apparent altitude (degrees).
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * import { getPosition } from "@johnmorrisdotca/wakusei-planets/suncalc";
53
+ *
54
+ * const { azimuth, altitude } = getPosition(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
55
+ * console.log(azimuth.toFixed(0), altitude.toFixed(0));
56
+ * ```
57
+ */
58
+ export function getPosition(date, lat, lng) {
59
+ const ms = moment(date);
60
+ const h = horizontalOf(sunEquatorial(ms), ms, place(lat, lng));
61
+ return { azimuth: h.azimuth, altitude: h.altitude + refraction(h.altitude) };
62
+ }
63
+ /**
64
+ * The Moon's place in the sky from a place on the Earth.
65
+ *
66
+ * @param date - The moment, as a `Date` (or milliseconds since 1970).
67
+ * @param lat - Degrees north, -90 to 90.
68
+ * @param lng - Degrees east (west negative).
69
+ * @returns The azimuth (degrees clockwise from north), apparent altitude (degrees), distance from the Earth's centre (kilometres) and parallactic angle (degrees).
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { getMoonPosition } from "@johnmorrisdotca/wakusei-planets/suncalc";
74
+ *
75
+ * const { distance } = getMoonPosition(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7);
76
+ * console.log(Math.round(distance / 1000));
77
+ * ```
78
+ */
79
+ export function getMoonPosition(date, lat, lng) {
80
+ const ms = moment(date);
81
+ const moon = moonEquatorial(ms);
82
+ const h = horizontalOf(moon, ms, place(lat, lng));
83
+ return { azimuth: h.azimuth, altitude: h.altitude + refraction(h.altitude), distance: moon.distanceKm, parallacticAngle: h.parallacticAngle };
84
+ }
85
+ /**
86
+ * The Moon's phase.
87
+ *
88
+ * @param date - The moment, as a `Date` (or milliseconds since 1970); now when left out.
89
+ * @returns The lit fraction, the phase, the bright limb's position angle in degrees and whether it is waxing.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { getMoonIllumination } from "@johnmorrisdotca/wakusei-planets/suncalc";
94
+ *
95
+ * const { fraction, waxing } = getMoonIllumination(new Date(Date.UTC(2026, 10, 24, 14)));
96
+ * console.log(fraction.toFixed(2), waxing);
97
+ * ```
98
+ */
99
+ export function getMoonIllumination(date = new Date()) {
100
+ return moonPhase(moment(date));
101
+ }
102
+ /**
103
+ * The Sun's times for a day at a place.
104
+ *
105
+ * @param date - Any moment of the day, as a `Date` (or milliseconds since 1970).
106
+ * @param lat - Degrees north, -90 to 90.
107
+ * @param lng - Degrees east (west negative).
108
+ * @param height - The observer's height above the horizon in metres (default 0): it lowers the sunrise and sunset altitudes by the dip of the horizon.
109
+ * @param utcOffset - Minutes east of UTC: when given the day is the local calendar day holding `date`; when left out it is the solar day (from one solar midnight to the next) holding `date`.
110
+ * @returns The times as `Date`s, `null` for one that does not happen that day, and `alwaysUp` or `alwaysDown` at the poles.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * import { getTimes } from "@johnmorrisdotca/wakusei-planets/suncalc";
115
+ *
116
+ * const t = getTimes(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1, 0, 60);
117
+ * console.log(t.sunrise!.toISOString().slice(0, 13));
118
+ * ```
119
+ */
120
+ export function getTimes(date, lat, lng, height = 0, utcOffset) {
121
+ const day = sunDay(moment(date), place(lat, lng, height), utcOffset, times);
122
+ const result = { solarNoon: new Date(day.noon), nadir: new Date(day.nadir) };
123
+ for (const [name, at] of day.events)
124
+ result[name] = at === null ? null : new Date(at);
125
+ if (day.alwaysUp)
126
+ result.alwaysUp = true;
127
+ if (day.alwaysDown)
128
+ result.alwaysDown = true;
129
+ return result;
130
+ }
131
+ /**
132
+ * The Moon's rise, set and transits over a day at a place.
133
+ *
134
+ * @param date - Any moment of the day, as a `Date` (or milliseconds since 1970).
135
+ * @param lat - Degrees north, -90 to 90.
136
+ * @param lng - Degrees east (west negative).
137
+ * @param utcOffset - Minutes east of UTC: when given the day is the local calendar day holding `date`; when left out it is the solar day holding `date`.
138
+ * @returns `rise`, `set`, `transit` (the Moon highest) and `lowerTransit` (lowest) as `Date`s, each absent on a day without it, with `alwaysUp` or `alwaysDown` when the Moon never crosses the horizon.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * import { getMoonTimes } from "@johnmorrisdotca/wakusei-planets/suncalc";
143
+ *
144
+ * const t = getMoonTimes(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7, 540);
145
+ * console.log(Object.keys(t).length > 0);
146
+ * ```
147
+ */
148
+ export function getMoonTimes(date, lat, lng, utcOffset) {
149
+ const ms = moment(date);
150
+ const observer = place(lat, lng);
151
+ const [start, end] = dayWindow(ms, observer, utcOffset);
152
+ const day = moonDay(start, end, observer);
153
+ const result = {};
154
+ if (day.rise !== null)
155
+ result.rise = new Date(day.rise);
156
+ if (day.set !== null)
157
+ result.set = new Date(day.set);
158
+ if (day.transit !== null)
159
+ result.transit = new Date(day.transit);
160
+ if (day.lowerTransit !== null)
161
+ result.lowerTransit = new Date(day.lowerTransit);
162
+ if (day.alwaysUp)
163
+ result.alwaysUp = true;
164
+ if (day.alwaysDown)
165
+ result.alwaysDown = true;
166
+ return result;
167
+ }
@@ -0,0 +1,2 @@
1
+ import "./ceres.ts";
2
+ import "./dwarfs.ts";
@@ -0,0 +1,2 @@
1
+ import "./ceres.js";
2
+ import "./dwarfs.js";
@@ -0,0 +1 @@
1
+ export {};