@zodiacs/engine 0.1.1-rc.15 → 1.0.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 (54) hide show
  1. package/CHANGELOG.md +891 -0
  2. package/LICENSING.md +192 -12
  3. package/NOTICE +96 -2
  4. package/README.md +296 -66
  5. package/dist/{api-CoB_kqE3.d.ts → api-WbxJ4Wj-.d.ts} +15 -10
  6. package/dist/ayanamsa--YQ46fET.d.ts +134 -0
  7. package/dist/calc.d.ts +390 -0
  8. package/dist/calc.js +1039 -0
  9. package/dist/chunk-47ERTK5X.js +27 -0
  10. package/dist/chunk-7TRLIFFI.js +56 -0
  11. package/dist/chunk-A3U2ZS2W.js +29 -0
  12. package/dist/{chunk-KHBLFXFG.js → chunk-B5LKF437.js} +29 -28
  13. package/dist/{chunk-ONBZ4HK7.js → chunk-BHJXUY67.js} +4 -2
  14. package/dist/{chunk-OYGRVGXD.js → chunk-CHSYDKBL.js} +3 -3
  15. package/dist/{chunk-ZHVI3KWJ.js → chunk-DMGHYCDI.js} +4 -4
  16. package/dist/{chunk-CWI4YUDL.js → chunk-FTX3JDJA.js} +21 -18
  17. package/dist/{chunk-MFF3VKO3.js → chunk-OG4OYTJJ.js} +47 -42
  18. package/dist/{chunk-ZZPITHQS.js → chunk-SRXBTP5H.js} +199 -65
  19. package/dist/{chunk-AECKV73C.js → chunk-TSS2SZWQ.js} +8 -2
  20. package/dist/chunk-WS3TDSP3.js +474 -0
  21. package/dist/chunk-YIITY7Q7.js +483 -0
  22. package/dist/crossings.d.ts +8 -7
  23. package/dist/crossings.js +1 -1
  24. package/dist/deltat.d.ts +28 -3
  25. package/dist/deltat.js +1 -1
  26. package/dist/geo.d.ts +33 -12
  27. package/dist/geo.js +17 -458
  28. package/dist/{internal-math-BbktkHCc.d.ts → houses-CFERsAlK.d.ts} +14 -160
  29. package/dist/houses-extra.d.ts +95 -0
  30. package/dist/houses-extra.js +339 -0
  31. package/dist/index.d.ts +34 -48
  32. package/dist/index.js +31 -23
  33. package/dist/internal-math-DJJ8BYex.d.ts +174 -0
  34. package/dist/internal-math.d.ts +3 -2
  35. package/dist/internal-math.js +2 -2
  36. package/dist/internal.d.ts +1 -1
  37. package/dist/internal.js +5 -5
  38. package/dist/receipt.d.ts +2 -243
  39. package/dist/receipt.js +78 -37
  40. package/dist/reference-span-CILpclrz.d.ts +40 -0
  41. package/dist/rulers-Dla6h_Sm.d.ts +15 -0
  42. package/dist/sky.d.ts +173 -0
  43. package/dist/sky.js +379 -0
  44. package/dist/techniques.d.ts +453 -0
  45. package/dist/techniques.js +823 -0
  46. package/dist/timing.d.ts +113 -17
  47. package/dist/timing.js +98 -64
  48. package/dist/{types-BsWaqwU_.d.ts → types-B-yb_tGL.d.ts} +23 -11
  49. package/dist/vedic.d.ts +42 -124
  50. package/dist/vedic.js +44 -458
  51. package/dist/window.d.ts +180 -0
  52. package/dist/window.js +960 -0
  53. package/dist/zone-history-ghdyO0Sc.d.ts +268 -0
  54. package/package.json +25 -3
package/dist/sky.d.ts ADDED
@@ -0,0 +1,173 @@
1
+ import { B as BodyName, D as DateInput } from './types-B-yb_tGL.js';
2
+ import { T as TraditionalPlanet } from './rulers-Dla6h_Sm.js';
3
+ export { C as CHALDEAN_ORDER } from './rulers-Dla6h_Sm.js';
4
+ import './deltat.js';
5
+
6
+ /** A body the sky functions accept: the Sun, the Moon and the planets. */
7
+ type SkyBody = Exclude<BodyName, "North Node" | "South Node">;
8
+ /**
9
+ * A place: geodetic latitude and longitude in degrees (east positive) and
10
+ * height in metres above the WGS84 ellipsoid, on which the sky functions place
11
+ * the observer. `@zodiacs/engine/calc`'s CalcPlace has the same three fields on
12
+ * the IERS 2003 ellipsoid, which its topocentric reduction uses, and accepts
13
+ * heights from −12,000 m: the two ellipsoids' equatorial radii differ by
14
+ * 0.4 m, and a height from −12,000 to −10,000 m is refused here.
15
+ */
16
+ interface Observer {
17
+ latitude: number;
18
+ longitude: number;
19
+ /** Metres above the WGS84 ellipsoid, from −10,000 to 100,000; 0 when absent. */
20
+ height?: number;
21
+ }
22
+ /** The point of the disc that meets the horizon. Planets are always taken at their centre. */
23
+ type Limb = "upper" | "centre" | "lower";
24
+ /** `"standard"`: 34′ of refraction at the horizon. `"none"`: the geometric horizon. */
25
+ type Refraction = "standard" | "none";
26
+ interface SkyOptions {
27
+ /** `"upper"` for the Sun and Moon unless given; the planets accept only `"centre"`. */
28
+ readonly limb?: Limb | undefined;
29
+ /** `"standard"` unless given. */
30
+ readonly refraction?: Refraction | undefined;
31
+ /** Most position evaluations the searches may make: a positive integer or `Infinity` (default). */
32
+ readonly maxSamples?: number | undefined;
33
+ }
34
+ interface SkyDayOptions extends SkyOptions {
35
+ /** The clock that defines the day, minutes east of UTC. Default: the observer's local mean time, longitude × 4. */
36
+ readonly utcOffsetMinutes?: number | undefined;
37
+ }
38
+ type SkyEventKind = "rise" | "set" | "upper-transit" | "lower-transit";
39
+ interface SkyEvent {
40
+ readonly kind: SkyEventKind;
41
+ readonly at: Date;
42
+ /** Geometric (unrefracted) topocentric altitude of the body's centre, degrees. */
43
+ readonly altitude: number;
44
+ /** Topocentric azimuth of the centre, degrees from north through east, in [0, 360). */
45
+ readonly azimuth: number;
46
+ }
47
+ /**
48
+ * `"never-rises"` and `"never-sets"`: the window holds no rise and no set, and
49
+ * the body stayed below (polar night, for the Sun) or above (polar day) the
50
+ * horizon of the conventions throughout. `"outside-reference-span"`: the
51
+ * window reaches outside `REFERENCE_SPAN`.
52
+ */
53
+ type SkyFlag = "never-rises" | "never-sets" | "outside-reference-span";
54
+ interface SkyConventions {
55
+ readonly limb: Limb;
56
+ readonly refraction: Refraction;
57
+ /** The refraction at the horizon, arcminutes: 34 or 0. */
58
+ readonly refractionArcmin: number;
59
+ }
60
+ interface SkyWindow {
61
+ readonly body: SkyBody;
62
+ readonly observer: Readonly<Required<Observer>>;
63
+ readonly from: Date;
64
+ readonly to: Date;
65
+ readonly conventions: SkyConventions;
66
+ readonly flags: readonly SkyFlag[];
67
+ /** Position evaluations the searches made. */
68
+ readonly samples: number;
69
+ }
70
+ /** A search either completes, with every event in the window, or is refused whole. */
71
+ type SkyEvents = (SkyWindow & {
72
+ readonly status: "complete";
73
+ readonly events: readonly SkyEvent[];
74
+ }) | (SkyWindow & {
75
+ readonly status: "refused";
76
+ readonly reason: "sample-budget";
77
+ readonly events: readonly [];
78
+ });
79
+ /** Refraction at the horizon, arcminutes (USNO, Rise, Set, and Twilight Definitions). */
80
+ declare const STANDARD_REFRACTION_ARCMIN = 34;
81
+ /** Radii for the semi-diameter, km: the Sun's (959.64″ at 1 au), the Moon's IAU mean radius. */
82
+ declare const SKY_RADII_KM: Readonly<{
83
+ Sun: 696000;
84
+ Moon: 1737.4;
85
+ }>;
86
+ /**
87
+ * Every rise, set, upper transit and lower transit of `body` in [from, to),
88
+ * for `observer`, in time order.
89
+ *
90
+ * A rise or set is the instant the geometric topocentric altitude of the
91
+ * body's centre equals −(refraction) − (semi-diameter) for the upper limb
92
+ * (+ for the lower, 0 for the centre). A transit is the instant the
93
+ * topocentric hour angle is 0° (upper) or 180° (lower). Throws RangeError for
94
+ * an unknown body, observer field or option, an invalid window, or an instant
95
+ * outside `EPHEMERIS_SPAN`.
96
+ */
97
+ declare function skyEvents(body: SkyBody, observer: Observer, from: DateInput, to: DateInput, options?: SkyOptions): SkyEvents;
98
+ /**
99
+ * The events of one calendar day on a clock `utcOffsetMinutes` east of UTC
100
+ * (by default the observer's local mean time): `skyEvents` over that day.
101
+ */
102
+ declare function skyEventsOn(body: SkyBody, observer: Observer, date: string, options?: SkyDayOptions): SkyEvents;
103
+
104
+ /** The ruler of each weekday, Sunday first (Cassius Dio 37.18–19). */
105
+ declare const PLANETARY_DAY_RULERS: readonly TraditionalPlanet[];
106
+ interface PlanetaryHour {
107
+ /** 1 to 24: hours 1–12 are the day's, 13–24 the night's. */
108
+ readonly number: number;
109
+ readonly period: "day" | "night";
110
+ readonly ruler: TraditionalPlanet;
111
+ readonly start: Date;
112
+ /** Exclusive; the next hour's start. */
113
+ readonly end: Date;
114
+ }
115
+ interface PlanetaryDayBase {
116
+ /** The calendar date whose sunrise begins the day, on the clock of `utcOffsetMinutes`. */
117
+ readonly date: string;
118
+ readonly utcOffsetMinutes: number;
119
+ /** 0 for Sunday to 6 for Saturday. */
120
+ readonly weekday: number;
121
+ /** The weekday's ruler, which rules the first hour. */
122
+ readonly ruler: TraditionalPlanet;
123
+ readonly conventions: SkyConventions;
124
+ readonly flags: readonly SkyFlag[];
125
+ readonly samples: number;
126
+ }
127
+ /**
128
+ * `"complete"`: the Sun rose on the date, set, and rose again, and the 24
129
+ * hours are given. `"no-sunrise"`: the date's 24 hours on the chosen clock
130
+ * hold no sunrise, in polar day or night (`flags` says which) or when the
131
+ * clock's midnight falls next to sunrise. `"no-sunset"`: the Sun rose but did
132
+ * not set within three days of the date's start, as polar day begins.
133
+ * `"no-next-sunrise"`: it rose and set but did not rise again within those
134
+ * three days, as polar night begins. `"refused"`: the sample budget ran out,
135
+ * with `reason: "sample-budget"` as a refused skyEventsOn() gives it.
136
+ */
137
+ type PlanetaryDay = (PlanetaryDayBase & {
138
+ readonly status: "complete";
139
+ readonly sunrise: Date;
140
+ readonly sunset: Date;
141
+ readonly nextSunrise: Date;
142
+ readonly hours: readonly PlanetaryHour[];
143
+ }) | (PlanetaryDayBase & {
144
+ readonly status: "no-sunrise" | "no-sunset" | "no-next-sunrise";
145
+ readonly sunrise: null;
146
+ readonly sunset: null;
147
+ readonly nextSunrise: null;
148
+ readonly hours: readonly [];
149
+ }) | (PlanetaryDayBase & {
150
+ readonly status: "refused";
151
+ readonly reason: "sample-budget";
152
+ readonly sunrise: null;
153
+ readonly sunset: null;
154
+ readonly nextSunrise: null;
155
+ readonly hours: readonly [];
156
+ });
157
+ /**
158
+ * The planetary day that begins at the Sun's first rise on `date` (YYYY-MM-DD
159
+ * on the clock `utcOffsetMinutes` east of UTC, by default the observer's local
160
+ * mean time): the day's ruler, sunrise, sunset, the next sunrise and the 24
161
+ * hours. Rise and set follow the options of `skyEvents` for the Sun.
162
+ */
163
+ declare function planetaryHours(observer: Observer, date: string, options?: SkyDayOptions): PlanetaryDay;
164
+ /**
165
+ * The planetary hour running at `at`, with its day: the day whose sunrise is
166
+ * the last at or before `at`. `hour` is null when that day is not complete.
167
+ */
168
+ declare function planetaryHourAt(observer: Observer, at: DateInput, options?: SkyDayOptions): {
169
+ readonly day: PlanetaryDay;
170
+ readonly hour: PlanetaryHour | null;
171
+ };
172
+
173
+ export { type Limb, type Observer, PLANETARY_DAY_RULERS, type PlanetaryDay, type PlanetaryHour, type Refraction, SKY_RADII_KM, STANDARD_REFRACTION_ARCMIN, type SkyBody, type SkyConventions, type SkyDayOptions, type SkyEvent, type SkyEventKind, type SkyEvents, type SkyFlag, type SkyOptions, TraditionalPlanet, planetaryHourAt, planetaryHours, skyEvents, skyEventsOn };
package/dist/sky.js ADDED
@@ -0,0 +1,379 @@
1
+ import {
2
+ CHALDEAN_ORDER
3
+ } from "./chunk-A3U2ZS2W.js";
4
+ import {
5
+ equatorRows,
6
+ turn
7
+ } from "./chunk-7TRLIFFI.js";
8
+ import {
9
+ dateFrom
10
+ } from "./chunk-CPALRSPC.js";
11
+ import {
12
+ searchLongitudeCrossingsWith
13
+ } from "./chunk-TSS2SZWQ.js";
14
+ import {
15
+ gastHours,
16
+ onChartClock
17
+ } from "./chunk-SRXBTP5H.js";
18
+ import {
19
+ outsideReferenceSpan
20
+ } from "./chunk-B5LKF437.js";
21
+ import "./chunk-BHJXUY67.js";
22
+ import "./chunk-DMGHYCDI.js";
23
+ import "./chunk-OG4OYTJJ.js";
24
+
25
+ // src/sky/riseset.ts
26
+ import { Body, GeoVector } from "astronomy-engine";
27
+
28
+ // src/first-millisecond.ts
29
+ function firstMillisecond(reached, estimate) {
30
+ const start = Math.round(estimate);
31
+ let lo = start - 4;
32
+ let hi = start + 4;
33
+ for (let widen = 4; reached(lo); widen *= 2) {
34
+ if (widen > 1 << 24) throw new RangeError("A crossing could not be bracketed.");
35
+ hi = lo;
36
+ lo -= widen;
37
+ }
38
+ for (let widen = 4; !reached(hi); widen *= 2) {
39
+ if (widen > 1 << 24) throw new RangeError("A crossing could not be bracketed.");
40
+ lo = hi;
41
+ hi += widen;
42
+ }
43
+ while (hi - lo > 1) {
44
+ const middle = Math.floor((lo + hi) / 2);
45
+ if (reached(middle)) hi = middle;
46
+ else lo = middle;
47
+ }
48
+ return hi;
49
+ }
50
+
51
+ // src/sky/riseset.ts
52
+ var RAD = Math.PI / 180;
53
+ var DAY_MS = 864e5;
54
+ var STEP_DAYS = 1 / 24;
55
+ var STANDARD_REFRACTION_ARCMIN = 34;
56
+ var SKY_RADII_KM = /* @__PURE__ */ Object.freeze({ Sun: 696e3, Moon: 1737.4 });
57
+ var KM_PER_AU = 1495978707e-1;
58
+ var WGS84_A = 6378.137;
59
+ var WGS84_F = 1 / 298.257223563;
60
+ var E2 = WGS84_F * (2 - WGS84_F);
61
+ var BODIES = {
62
+ Sun: Body.Sun,
63
+ Moon: Body.Moon,
64
+ Mercury: Body.Mercury,
65
+ Venus: Body.Venus,
66
+ Mars: Body.Mars,
67
+ Jupiter: Body.Jupiter,
68
+ Saturn: Body.Saturn,
69
+ Uranus: Body.Uranus,
70
+ Neptune: Body.Neptune,
71
+ Pluto: Body.Pluto
72
+ };
73
+ function optionsOf(value, allowed, label) {
74
+ const out = {};
75
+ if (value === void 0) return out;
76
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
77
+ throw new RangeError(`${label} must be an options object.`);
78
+ }
79
+ for (const key of Reflect.ownKeys(value)) {
80
+ if (typeof key !== "string" || !allowed.includes(key)) {
81
+ throw new RangeError(`${label} has an unknown key: ${String(key)}.`);
82
+ }
83
+ const slot = Object.getOwnPropertyDescriptor(value, key);
84
+ if (!slot || !("value" in slot)) throw new RangeError(`${label} must contain only data properties.`);
85
+ if (slot.value !== void 0) out[key] = slot.value;
86
+ }
87
+ return out;
88
+ }
89
+ function numberIn(value, low, high, label) {
90
+ if (typeof value !== "number" || !Number.isFinite(value) || value < low || value > high) {
91
+ throw new RangeError(`${label} must be a finite number from ${low} to ${high}.`);
92
+ }
93
+ return value;
94
+ }
95
+ function observerOf(value) {
96
+ const input = optionsOf(value, ["latitude", "longitude", "height"], "observer");
97
+ return Object.freeze({
98
+ latitude: numberIn(input.latitude, -90, 90, "observer.latitude"),
99
+ longitude: numberIn(input.longitude, -180, 180, "observer.longitude"),
100
+ height: input.height === void 0 ? 0 : numberIn(input.height, -1e4, 1e5, "observer.height")
101
+ });
102
+ }
103
+ function bodyOf(value) {
104
+ if (typeof value !== "string" || !Object.prototype.hasOwnProperty.call(BODIES, value)) {
105
+ throw new RangeError(`Unknown body: ${String(value)}. Use the Sun, the Moon or a planet.`);
106
+ }
107
+ return value;
108
+ }
109
+ function budgetOf(value) {
110
+ if (value === void 0 || value === Number.POSITIVE_INFINITY) return Number.POSITIVE_INFINITY;
111
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
112
+ throw new RangeError("maxSamples must be a positive integer or Infinity.");
113
+ }
114
+ return value;
115
+ }
116
+ function conventionsOf(body, input) {
117
+ const disc = body === "Sun" || body === "Moon";
118
+ const limb = input.limb ?? (disc ? "upper" : "centre");
119
+ if (limb !== "upper" && limb !== "centre" && limb !== "lower") {
120
+ throw new RangeError('limb must be "upper", "centre" or "lower".');
121
+ }
122
+ if (!disc && limb !== "centre") throw new RangeError(`${body} is taken at its centre; only limb "centre" applies.`);
123
+ const refraction = input.refraction ?? "standard";
124
+ if (refraction !== "standard" && refraction !== "none") throw new RangeError('refraction must be "standard" or "none".');
125
+ return Object.freeze({ limb, refraction, refractionArcmin: refraction === "standard" ? STANDARD_REFRACTION_ARCMIN : 0 });
126
+ }
127
+ function stateAt(body, site, conventions, ms) {
128
+ return onChartClock(ms, "utc", void 0, (time) => {
129
+ const g = GeoVector(BODIES[body], time, true);
130
+ const [vx, vy, vz] = turn(equatorRows(time.tt, "true"), g.x, g.y, g.z);
131
+ const theta = (gastHours(time) * 15 + site.longitude) * RAD;
132
+ const phi = site.latitude * RAD;
133
+ const sinPhi = Math.sin(phi);
134
+ const cosPhi = Math.cos(phi);
135
+ const n = WGS84_A / Math.sqrt(1 - E2 * sinPhi * sinPhi);
136
+ const h = site.height / 1e3;
137
+ const cosT = Math.cos(theta);
138
+ const sinT = Math.sin(theta);
139
+ const x = vx - (n + h) * cosPhi * cosT / KM_PER_AU;
140
+ const y = vy - (n + h) * cosPhi * sinT / KM_PER_AU;
141
+ const z = vz - (n * (1 - E2) + h) * sinPhi / KM_PER_AU;
142
+ const east = -x * sinT + y * cosT;
143
+ const radial = x * cosT + y * sinT;
144
+ const north = -radial * sinPhi + z * cosPhi;
145
+ const up = radial * cosPhi + z * sinPhi;
146
+ const altitude = Math.atan2(up, Math.hypot(east, north)) / RAD;
147
+ const azimuth = (Math.atan2(east, north) / RAD % 360 + 360) % 360;
148
+ const hourAngle = ((theta - Math.atan2(y, x)) / RAD % 360 + 360) % 360;
149
+ const radius = body === "Sun" || body === "Moon" ? SKY_RADII_KM[body] : 0;
150
+ const semiDiameter = Math.asin(radius / (Math.hypot(x, y, z) * KM_PER_AU)) / RAD;
151
+ const limb = conventions.limb === "upper" ? 1 : conventions.limb === "lower" ? -1 : 0;
152
+ const horizon = -conventions.refractionArcmin / 60 - limb * semiDiameter;
153
+ return { above: altitude - horizon, altitude, azimuth, hourAngle };
154
+ });
155
+ }
156
+ var BudgetSpent = class {
157
+ };
158
+ var HOUR_MS = 36e5;
159
+ var offsetFrom = (target, value) => ((value - target + 540) % 360 + 360) % 360 - 180;
160
+ function searchEvents(body, site, conventions, fromMs, toMs, maxSamples, transits) {
161
+ const cache = /* @__PURE__ */ new Map();
162
+ const state = (ms) => {
163
+ let known = cache.get(ms);
164
+ if (!known) {
165
+ known = stateAt(body, site, conventions, ms);
166
+ cache.set(ms, known);
167
+ }
168
+ return known;
169
+ };
170
+ let budget = maxSamples;
171
+ let samples = 0;
172
+ const events = [];
173
+ const from = new Date(fromMs - HOUR_MS);
174
+ const to = new Date(toMs + HOUR_MS);
175
+ const add = (kind, value, estimate, rising) => {
176
+ const at = firstMillisecond((ms) => {
177
+ if (budget < 1) throw new BudgetSpent();
178
+ budget -= 1;
179
+ samples += 1;
180
+ const v = value(state(ms));
181
+ return rising ? v >= 0 : v <= 0;
182
+ }, estimate);
183
+ if (at < fromMs || at >= toMs) return;
184
+ const found = state(at);
185
+ events.push(Object.freeze({ kind, at: new Date(at), altitude: found.altitude, azimuth: found.azimuth }));
186
+ };
187
+ const run = (value, target) => {
188
+ if (budget < 1) throw new BudgetSpent();
189
+ const result = searchLongitudeCrossingsWith((_, date) => value(state(date.getTime())), body, target, from, to, {
190
+ stepDays: STEP_DAYS,
191
+ maxSamples: budget
192
+ });
193
+ samples += result.samples;
194
+ budget -= result.samples;
195
+ if (result.status !== "complete") throw new BudgetSpent();
196
+ return result.crossings;
197
+ };
198
+ try {
199
+ const above = (found) => found.above;
200
+ for (const crossing of run(above, 0)) {
201
+ add(crossing.retrograde ? "set" : "rise", above, crossing.at.getTime(), !crossing.retrograde);
202
+ }
203
+ if (transits) {
204
+ for (const [target, kind] of [[0, "upper-transit"], [180, "lower-transit"]]) {
205
+ const hour = (found) => offsetFrom(target, found.hourAngle);
206
+ for (const crossing of run((found) => found.hourAngle, target)) add(kind, hour, crossing.at.getTime(), true);
207
+ }
208
+ }
209
+ } catch (error) {
210
+ if (error instanceof BudgetSpent) return { status: "refused", samples, events: [], first: void 0 };
211
+ throw error;
212
+ }
213
+ events.sort((a, b) => a.at.getTime() - b.at.getTime());
214
+ return { status: "complete", samples, events, first: state(fromMs) };
215
+ }
216
+ function windowFlags(events, first, fromMs, toMs) {
217
+ const flags = [];
218
+ if (!events.some((event) => event.kind === "rise" || event.kind === "set")) {
219
+ flags.push(first.above > 0 ? "never-sets" : "never-rises");
220
+ }
221
+ if (outsideReferenceSpan(new Date(fromMs)) || outsideReferenceSpan(new Date(toMs - 1))) {
222
+ flags.push("outside-reference-span");
223
+ }
224
+ return flags;
225
+ }
226
+ function eventsIn(body, site, input, fromMs, toMs) {
227
+ const conventions = conventionsOf(body, input);
228
+ const maxSamples = budgetOf(input.maxSamples);
229
+ if (!(toMs > fromMs)) throw new RangeError("The window must end after it starts.");
230
+ const search = searchEvents(body, site, conventions, fromMs, toMs, maxSamples, true);
231
+ const base = {
232
+ body,
233
+ observer: site,
234
+ from: new Date(fromMs),
235
+ to: new Date(toMs),
236
+ conventions,
237
+ samples: search.samples
238
+ };
239
+ if (search.status === "refused") {
240
+ const flags = outsideReferenceSpan(new Date(fromMs)) || outsideReferenceSpan(new Date(toMs - 1)) ? ["outside-reference-span"] : [];
241
+ return Object.freeze({ ...base, flags: Object.freeze(flags), status: "refused", reason: "sample-budget", events: Object.freeze([]) });
242
+ }
243
+ return Object.freeze({
244
+ ...base,
245
+ flags: Object.freeze(windowFlags(search.events, search.first, fromMs, toMs)),
246
+ status: "complete",
247
+ events: Object.freeze(search.events)
248
+ });
249
+ }
250
+ function skyEvents(body, observer, from, to, options) {
251
+ const name = bodyOf(body);
252
+ const site = observerOf(observer);
253
+ const input = optionsOf(options, ["limb", "refraction", "maxSamples"], "options");
254
+ return eventsIn(name, site, input, dateFrom(from, "from").getTime(), dateFrom(to, "to").getTime());
255
+ }
256
+ function calendarDateMs(value) {
257
+ const match = typeof value === "string" ? /^(\d{4})-(\d{2})-(\d{2})$/u.exec(value) : null;
258
+ if (match) {
259
+ const [year, month, day] = [Number(match[1]), Number(match[2]) - 1, Number(match[3])];
260
+ const date = /* @__PURE__ */ new Date(0);
261
+ date.setUTCFullYear(year, month, day);
262
+ if (date.getUTCFullYear() === year && date.getUTCMonth() === month && date.getUTCDate() === day) return date.getTime();
263
+ }
264
+ throw new RangeError("date must be a calendar date, YYYY-MM-DD.");
265
+ }
266
+ function offsetOf(value, site) {
267
+ return value === void 0 ? site.longitude * 4 : numberIn(value, -1080, 1080, "utcOffsetMinutes");
268
+ }
269
+ function skyEventsOn(body, observer, date, options) {
270
+ const name = bodyOf(body);
271
+ const site = observerOf(observer);
272
+ const input = optionsOf(options, ["limb", "refraction", "maxSamples", "utcOffsetMinutes"], "options");
273
+ const fromMs = calendarDateMs(date) - offsetOf(input.utcOffsetMinutes, site) * 6e4;
274
+ return eventsIn(name, site, input, fromMs, fromMs + DAY_MS);
275
+ }
276
+
277
+ // src/sky/hours.ts
278
+ var PLANETARY_DAY_RULERS = /* @__PURE__ */ Object.freeze([
279
+ "Sun",
280
+ "Moon",
281
+ "Mars",
282
+ "Mercury",
283
+ "Jupiter",
284
+ "Venus",
285
+ "Saturn"
286
+ ]);
287
+ var DAY_MS2 = 864e5;
288
+ var SPAN_DAYS = 3;
289
+ function isoDate(ms) {
290
+ const date = new Date(ms);
291
+ const year = date.getUTCFullYear();
292
+ return `${String(year).padStart(4, "0")}-${String(date.getUTCMonth() + 1).padStart(2, "0")}-${String(date.getUTCDate()).padStart(2, "0")}`;
293
+ }
294
+ function hourRuler(ruler, number) {
295
+ return CHALDEAN_ORDER[(CHALDEAN_ORDER.indexOf(ruler) + number - 1) % 7];
296
+ }
297
+ function dayOf(site, input, midnightMs) {
298
+ const conventions = conventionsOf("Sun", input);
299
+ const offset = offsetOf(input.utcOffsetMinutes, site);
300
+ const startMs = midnightMs - offset * 6e4;
301
+ const weekday = ((Math.floor(midnightMs / DAY_MS2) + 4) % 7 + 7) % 7;
302
+ const ruler = PLANETARY_DAY_RULERS[weekday];
303
+ const search = searchEvents("Sun", site, conventions, startMs, startMs + SPAN_DAYS * DAY_MS2, budgetOf(input.maxSamples), false);
304
+ const base = { date: isoDate(midnightMs), utcOffsetMinutes: offset, weekday, ruler, conventions, samples: search.samples };
305
+ const empty = { sunrise: null, sunset: null, nextSunrise: null, hours: Object.freeze([]) };
306
+ if (search.status === "refused") {
307
+ return Object.freeze({ ...base, flags: Object.freeze([]), status: "refused", reason: "sample-budget", ...empty });
308
+ }
309
+ const rise = search.events.find((event) => event.kind === "rise" && event.at.getTime() < startMs + DAY_MS2);
310
+ const set = rise && search.events.find((event) => event.kind === "set" && event.at > rise.at);
311
+ const next = set && search.events.find((event) => event.kind === "rise" && event.at > set.at);
312
+ if (!rise || !set || !next) {
313
+ const flags2 = [];
314
+ const firstDay = search.events.filter((event) => event.at.getTime() < startMs + DAY_MS2);
315
+ if (firstDay.length === 0) flags2.push(search.first.above > 0 ? "never-sets" : "never-rises");
316
+ const status = !rise ? "no-sunrise" : !set ? "no-sunset" : "no-next-sunrise";
317
+ return Object.freeze({ ...base, flags: Object.freeze(flags2), status, ...empty });
318
+ }
319
+ const hours = [];
320
+ const marks = [rise.at.getTime(), set.at.getTime(), next.at.getTime()];
321
+ for (let number = 1; number <= 24; number += 1) {
322
+ const night = number > 12;
323
+ const from = marks[night ? 1 : 0];
324
+ const length = (marks[night ? 2 : 1] - from) / 12;
325
+ const k = night ? number - 13 : number - 1;
326
+ hours.push(
327
+ Object.freeze({
328
+ number,
329
+ period: night ? "night" : "day",
330
+ ruler: hourRuler(ruler, number),
331
+ start: new Date(k === 0 ? from : Math.round(from + k * length)),
332
+ end: new Date(k === 11 ? marks[night ? 2 : 1] : Math.round(from + (k + 1) * length))
333
+ })
334
+ );
335
+ }
336
+ const flags = outsideReferenceSpan(rise.at) || outsideReferenceSpan(next.at) ? ["outside-reference-span"] : [];
337
+ return Object.freeze({
338
+ ...base,
339
+ flags: Object.freeze(flags),
340
+ status: "complete",
341
+ sunrise: rise.at,
342
+ sunset: set.at,
343
+ nextSunrise: next.at,
344
+ hours: Object.freeze(hours)
345
+ });
346
+ }
347
+ var DAY_KEYS = ["limb", "refraction", "maxSamples", "utcOffsetMinutes"];
348
+ function planetaryHours(observer, date, options) {
349
+ const site = observerOf(observer);
350
+ const input = optionsOf(options, DAY_KEYS, "options");
351
+ return dayOf(site, input, calendarDateMs(date));
352
+ }
353
+ function planetaryHourAt(observer, at, options) {
354
+ const site = observerOf(observer);
355
+ const input = optionsOf(options, DAY_KEYS, "options");
356
+ const ms = dateFrom(at, "at").getTime();
357
+ const offset = offsetOf(input.utcOffsetMinutes, site);
358
+ let midnight = Math.floor((ms + offset * 6e4) / DAY_MS2) * DAY_MS2;
359
+ let day = dayOf(site, input, midnight);
360
+ for (let step = 0; step < 2 && day.status === "complete"; step += 1) {
361
+ const shift = ms < day.sunrise.getTime() ? -1 : ms >= day.nextSunrise.getTime() ? 1 : 0;
362
+ if (shift === 0) break;
363
+ midnight += shift * DAY_MS2;
364
+ day = dayOf(site, input, midnight);
365
+ }
366
+ if (day.status !== "complete") return Object.freeze({ day, hour: null });
367
+ const hour = day.hours.find((candidate) => ms >= candidate.start.getTime() && ms < candidate.end.getTime()) ?? null;
368
+ return Object.freeze({ day, hour });
369
+ }
370
+ export {
371
+ CHALDEAN_ORDER,
372
+ PLANETARY_DAY_RULERS,
373
+ SKY_RADII_KM,
374
+ STANDARD_REFRACTION_ARCMIN,
375
+ planetaryHourAt,
376
+ planetaryHours,
377
+ skyEvents,
378
+ skyEventsOn
379
+ };