@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/calc.js ADDED
@@ -0,0 +1,1039 @@
1
+ import {
2
+ eclipticRows,
3
+ equatorRows
4
+ } from "./chunk-7TRLIFFI.js";
5
+ import {
6
+ AYANAMSAS,
7
+ ayanamsaAt,
8
+ isUserAyanamsaName,
9
+ outsideSpanEpoch,
10
+ siderealChartOf,
11
+ userAyanamsa,
12
+ wholeSignCusps,
13
+ wrap360
14
+ } from "./chunk-WS3TDSP3.js";
15
+ import "./chunk-47ERTK5X.js";
16
+ import {
17
+ dateFrom
18
+ } from "./chunk-CPALRSPC.js";
19
+ import {
20
+ searchLongitudeCrossingsWith
21
+ } from "./chunk-TSS2SZWQ.js";
22
+ import {
23
+ assertDerivedFlags,
24
+ snapshotFlags,
25
+ timeFlags,
26
+ validateBirthSettings
27
+ } from "./chunk-PFGUCNOK.js";
28
+ import {
29
+ bodyLongitude,
30
+ computeChart,
31
+ eclipticFrame,
32
+ eclipticOfDate,
33
+ gastHours,
34
+ meanApogee,
35
+ meanEcliptic,
36
+ meanNodeLongitude,
37
+ onChartClock,
38
+ tilt
39
+ } from "./chunk-SRXBTP5H.js";
40
+ import {
41
+ EPHEMERIS_SPAN,
42
+ REFERENCE_SPAN,
43
+ TIME_SCALE_NAMES,
44
+ elapsedDays,
45
+ timeBasis
46
+ } from "./chunk-B5LKF437.js";
47
+ import "./chunk-BHJXUY67.js";
48
+ import {
49
+ computeAngles,
50
+ computeHouses,
51
+ eastPointOf,
52
+ isPolarUndefinedHouseSystem,
53
+ ramcOf,
54
+ vertexOf
55
+ } from "./chunk-DMGHYCDI.js";
56
+ import {
57
+ ENGINE_VERSION,
58
+ EPHEMERIS,
59
+ normalizeLongitude
60
+ } from "./chunk-OG4OYTJJ.js";
61
+
62
+ // src/calc.ts
63
+ import { AstroTime, GeoMoonState } from "astronomy-engine";
64
+
65
+ // src/calc-bounds.ts
66
+ var MEASURED_BASIS = "largest difference from JPL Horizons (DE441) over 32 instants from JD 2379457.498125 to 2520522.646618 (TT), in all eight frames; docs/evidence/calc-api/rc16";
67
+ var BARYCENTRIC_APPARENT = {
68
+ "Earth": [3, 14e-6, 0.18],
69
+ "Jupiter": [13, 4e-5, 0.025],
70
+ "Mars": [4.4, 21e-6, 0.08],
71
+ "Mercury": [23, 77e-6, 5.4],
72
+ "Moon": [3, 14e-6, 0.18],
73
+ "Neptune": [21, 44e-6, 63e-4],
74
+ "Pluto": [25, 61e-6, 14e-4],
75
+ "Saturn": [19, 65e-6, 0.023],
76
+ "Uranus": [19, 43e-6, 86e-4],
77
+ "Venus": [7.4, 15e-6, 0.22]
78
+ };
79
+ var HELIOCENTRIC_APPARENT = {
80
+ "Earth": [3, 15e-6, 0.18],
81
+ "Jupiter": [13, 4e-5, 0.025],
82
+ "Mars": [4.3, 23e-6, 0.079],
83
+ "Mercury": [23, 87e-6, 5.4],
84
+ "Moon": [3, 15e-6, 0.18],
85
+ "Neptune": [21, 44e-6, 63e-4],
86
+ "Pluto": [25, 6e-5, 17e-4],
87
+ "Saturn": [18, 65e-6, 0.023],
88
+ "Uranus": [19, 42e-6, 91e-4],
89
+ "Venus": [6.6, 12e-6, 0.21]
90
+ };
91
+ var MEASURED = {
92
+ "barycentric/apparent": BARYCENTRIC_APPARENT,
93
+ "barycentric/astrometric": BARYCENTRIC_APPARENT,
94
+ "barycentric/geometric": {
95
+ "Earth": [3, 14e-6, 0.18],
96
+ "Jupiter": [13, 4e-5, 0.025],
97
+ "Mars": [4.4, 21e-6, 0.08],
98
+ "Mercury": [23, 77e-6, 5.4],
99
+ "Moon": [3, 14e-6, 0.18],
100
+ "Neptune": [21, 44e-6, 63e-4],
101
+ "Pluto": [25, 61e-6, 18e-4],
102
+ "Saturn": [19, 65e-6, 0.023],
103
+ "Uranus": [19, 43e-6, 86e-4],
104
+ "Venus": [7.4, 15e-6, 0.22]
105
+ },
106
+ "geocentric/apparent": {
107
+ "Black Moon Lilith": [23e-4, null, 32e-4],
108
+ "Jupiter": [13, 47e-6, 0.061],
109
+ "Mars": [6.6, 58e-6, 0.45],
110
+ "Mean Node": [23e-4, null, 81e-5],
111
+ "Mean South Node": [23e-4, null, 81e-5],
112
+ "Mercury": [9.3, 36e-6, 2.2],
113
+ "Moon": [8.3, 14e-5, 1.1],
114
+ "Neptune": [21, 42e-6, 0.013],
115
+ "North Node": [16, null, null],
116
+ "Pluto": [25, 63e-6, 0.014],
117
+ "Saturn": [18, 68e-6, 0.03],
118
+ "South Node": [16, null, null],
119
+ "Sun": [3, 15e-6, 0.18],
120
+ "Uranus": [20, 42e-6, 0.02],
121
+ "Venus": [11, 32e-6, 0.64]
122
+ },
123
+ "geocentric/astrometric": {
124
+ "Jupiter": [13, 47e-6, 0.061],
125
+ "Mars": [6.6, 58e-6, 0.45],
126
+ "Mercury": [9.3, 36e-6, 2.2],
127
+ "Moon": [7.6, 36e-6, 1.1],
128
+ "Neptune": [21, 42e-6, 0.013],
129
+ "Pluto": [25, 63e-6, 0.014],
130
+ "Saturn": [18, 68e-6, 0.03],
131
+ "Sun": [3, 15e-6, 0.18],
132
+ "Uranus": [20, 42e-6, 0.02],
133
+ "Venus": [11, 32e-6, 0.64]
134
+ },
135
+ "geocentric/geometric": {
136
+ "Jupiter": [13, 47e-6, 0.061],
137
+ "Mars": [6.6, 58e-6, 0.45],
138
+ "Mercury": [9.3, 36e-6, 2.2],
139
+ "Moon": [7.6, 36e-6, 0.97],
140
+ "Neptune": [21, 42e-6, 0.013],
141
+ "Pluto": [25, 63e-6, 0.014],
142
+ "Saturn": [18, 68e-6, 0.03],
143
+ "Sun": [3, 15e-6, 0.18],
144
+ "Uranus": [20, 42e-6, 0.02],
145
+ "Venus": [11, 32e-6, 0.64]
146
+ },
147
+ "heliocentric/apparent": HELIOCENTRIC_APPARENT,
148
+ "heliocentric/astrometric": HELIOCENTRIC_APPARENT,
149
+ "heliocentric/geometric": {
150
+ "Earth": [3, 15e-6, 0.18],
151
+ "Jupiter": [13, 4e-5, 0.025],
152
+ "Mars": [4.3, 23e-6, 0.079],
153
+ "Mercury": [23, 87e-6, 5.4],
154
+ "Moon": [3, 15e-6, 0.18],
155
+ "Neptune": [21, 44e-6, 62e-4],
156
+ "Pluto": [25, 6e-5, 2e-3],
157
+ "Saturn": [18, 65e-6, 0.023],
158
+ "Uranus": [19, 42e-6, 9e-3],
159
+ "Venus": [6.6, 12e-6, 0.21]
160
+ },
161
+ "topocentric/apparent": {
162
+ "Mars": [6.6, 58e-6, 0.46],
163
+ "Moon": [7.8, 36e-6, 1.4],
164
+ "Sun": [3, 15e-6, 0.19]
165
+ },
166
+ "topocentric/astrometric": {
167
+ "Mars": [6.6, 58e-6, 0.45],
168
+ "Moon": [7.8, 36e-6, 1.4],
169
+ "Sun": [3, 15e-6, 0.18]
170
+ },
171
+ "topocentric/geometric": {
172
+ "Mars": [6.6, 58e-6, 0.45],
173
+ "Moon": [7.8, 36e-6, 1.5],
174
+ "Sun": [3, 15e-6, 0.18]
175
+ }
176
+ };
177
+
178
+ // src/calc-frames.ts
179
+ var CALC_FRAMES = [
180
+ "ecliptic-true-of-date",
181
+ "ecliptic-mean-of-date",
182
+ "ecliptic-j2000",
183
+ "ecliptic-icrs",
184
+ "equatorial-true-of-date",
185
+ "equatorial-mean-of-date",
186
+ "equatorial-j2000",
187
+ "equatorial-icrs"
188
+ ];
189
+ var DEG = Math.PI / 180;
190
+ var RAD = 180 / Math.PI;
191
+ var ARCSEC = DEG / 3600;
192
+ var at = (m, i) => m[i];
193
+ function apply(m, [x, y, z]) {
194
+ return [m[0] * x + m[1] * y + m[2] * z, m[3] * x + m[4] * y + m[5] * z, m[6] * x + m[7] * y + m[8] * z];
195
+ }
196
+ function product(a, b) {
197
+ const c = (row, column) => at(a, 3 * row) * at(b, column) + at(a, 3 * row + 1) * at(b, 3 + column) + at(a, 3 * row + 2) * at(b, 6 + column);
198
+ return [c(0, 0), c(0, 1), c(0, 2), c(1, 0), c(1, 1), c(1, 2), c(2, 0), c(2, 1), c(2, 2)];
199
+ }
200
+ function transpose(m) {
201
+ return [m[0], m[3], m[6], m[1], m[4], m[7], m[2], m[5], m[8]];
202
+ }
203
+ function r1(angle) {
204
+ const c = Math.cos(angle);
205
+ const s = Math.sin(angle);
206
+ return [1, 0, 0, 0, c, s, 0, -s, c];
207
+ }
208
+ function r2(angle) {
209
+ const c = Math.cos(angle);
210
+ const s = Math.sin(angle);
211
+ return [c, 0, -s, 0, 1, 0, s, 0, c];
212
+ }
213
+ function r3(angle) {
214
+ const c = Math.cos(angle);
215
+ const s = Math.sin(angle);
216
+ return [c, s, 0, -s, c, 0, 0, 0, 1];
217
+ }
218
+ var IDENTITY = [1, 0, 0, 0, 1, 0, 0, 0, 1];
219
+ var ECLIPTIC_J2000 = r1(84381.406 * ARCSEC);
220
+ var BIAS = product(
221
+ r1(68192e-7 * ARCSEC),
222
+ product(r2(-0.041775 * ARCSEC * Math.sin(84381.448 * ARCSEC)), r3(-0.0146 * ARCSEC))
223
+ );
224
+ var J2000_TO_ICRS = transpose(BIAS);
225
+ function frameMatrix(frame, time) {
226
+ switch (frame) {
227
+ case "ecliptic-true-of-date":
228
+ return eclipticRows(time.tt, "true");
229
+ case "equatorial-true-of-date":
230
+ return equatorRows(time.tt, "true");
231
+ case "ecliptic-mean-of-date":
232
+ return eclipticRows(time.tt, "mean");
233
+ case "equatorial-mean-of-date":
234
+ return equatorRows(time.tt, "mean");
235
+ case "ecliptic-j2000":
236
+ return ECLIPTIC_J2000;
237
+ case "equatorial-j2000":
238
+ return IDENTITY;
239
+ case "ecliptic-icrs":
240
+ return product(ECLIPTIC_J2000, J2000_TO_ICRS);
241
+ case "equatorial-icrs":
242
+ return J2000_TO_ICRS;
243
+ }
244
+ }
245
+ function inertial(frame) {
246
+ return frame.endsWith("j2000") || frame.endsWith("icrs");
247
+ }
248
+ function toSpherical([x, y, z]) {
249
+ return { lon: normalizeLongitude(Math.atan2(y, x) * RAD), lat: Math.asin(z / Math.hypot(x, y, z)) * RAD };
250
+ }
251
+ function fromSpherical(lon, lat, distance) {
252
+ const cosLat = Math.cos(lat * DEG);
253
+ return [
254
+ distance * cosLat * Math.cos(lon * DEG),
255
+ distance * cosLat * Math.sin(lon * DEG),
256
+ distance * Math.sin(lat * DEG)
257
+ ];
258
+ }
259
+ function sphericalRates([x, y, z], [vx, vy, vz]) {
260
+ const plane = x * x + y * y;
261
+ const square = plane + z * z;
262
+ return {
263
+ lon: (x * vy - y * vx) / plane * RAD,
264
+ lat: (vz * plane - z * (x * vx + y * vy)) / (square * Math.sqrt(plane)) * RAD,
265
+ dist: (x * vx + y * vy + z * vz) / Math.sqrt(square)
266
+ };
267
+ }
268
+
269
+ // src/calc-reduce.ts
270
+ import {
271
+ BaryState,
272
+ Body,
273
+ CorrectLightTravel,
274
+ DEG2RAD,
275
+ GeoMoon,
276
+ GeoVector,
277
+ HelioState,
278
+ HelioVector,
279
+ KM_PER_AU,
280
+ Vector
281
+ } from "astronomy-engine";
282
+ var ZERO = [0, 0, 0];
283
+ var vec = ({ x, y, z }) => [x, y, z];
284
+ var add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
285
+ var sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
286
+ var length = ([x, y, z]) => Math.hypot(x, y, z);
287
+ var EARTH_FLATTENING = 0.996647180302104;
288
+ var EARTH_FLATTENING_SQUARED = EARTH_FLATTENING * EARTH_FLATTENING;
289
+ var EARTH_EQUATORIAL_RADIUS_KM = 6378.1366;
290
+ var ANGVEL = 7292115e-11;
291
+ function terra(site, st) {
292
+ const phi = site.latitude * DEG2RAD;
293
+ const sinphi = Math.sin(phi);
294
+ const cosphi = Math.cos(phi);
295
+ const c = 1 / Math.hypot(cosphi, EARTH_FLATTENING * sinphi);
296
+ const s = EARTH_FLATTENING_SQUARED * c;
297
+ const heightKm = site.height / 1e3;
298
+ const ach = EARTH_EQUATORIAL_RADIUS_KM * c + heightKm;
299
+ const ash = EARTH_EQUATORIAL_RADIUS_KM * s + heightKm;
300
+ const stlocl = (15 * st + site.longitude) * DEG2RAD;
301
+ const sinst = Math.sin(stlocl);
302
+ const cosst = Math.cos(stlocl);
303
+ return {
304
+ pos: [ach * cosphi * cosst / KM_PER_AU, ach * cosphi * sinst / KM_PER_AU, ash * sinphi / KM_PER_AU],
305
+ vel: [-ANGVEL * ach * cosphi * sinst * 86400 / KM_PER_AU, ANGVEL * ach * cosphi * cosst * 86400 / KM_PER_AU, 0]
306
+ };
307
+ }
308
+ function observerState(site, time) {
309
+ const { pos, vel } = terra(site, gastHours(time));
310
+ const back = transpose(equatorRows(time.tt, "true"));
311
+ return { r: apply(back, pos), v: apply(back, vel) };
312
+ }
313
+ function observerAt(center, time) {
314
+ return center.kind === "topocentric" ? observerState(center.site, time).r : ZERO;
315
+ }
316
+ function fromGeocentre(body, time) {
317
+ return body === Body.Moon ? vec(GeoMoon(time)) : sub(vec(HelioVector(body, time)), vec(HelioVector(Body.Earth, time)));
318
+ }
319
+ function retarded(at2, time) {
320
+ const found = CorrectLightTravel((t) => {
321
+ const [x, y, z] = at2(t);
322
+ return new Vector(x, y, z, t);
323
+ }, time);
324
+ return { v: vec(found), left: found.t };
325
+ }
326
+ var BARYCENTRE_ERROR = { au: 14e-6, auPerDay: 12e-8 };
327
+ function sunMotion(left, time) {
328
+ return sub(vec(BaryState(Body.Sun, left)), vec(BaryState(Body.Sun, time)));
329
+ }
330
+ function locate(body, center, correction, time) {
331
+ const found = (v2, dist = length(v2)) => ({ v: v2, dist });
332
+ if (center.kind === "barycentric") {
333
+ const bary = (t) => vec(BaryState(body, t));
334
+ return found(correction === "geometric" ? bary(time) : retarded(bary, time).v);
335
+ }
336
+ if (center.kind === "heliocentric") {
337
+ const helio = (t) => vec(HelioVector(body, t));
338
+ if (correction === "geometric") return found(helio(time));
339
+ const { v: v2, left: left2 } = retarded(helio, time);
340
+ const astrometric2 = add(v2, sunMotion(left2, time));
341
+ return correction === "apparent" ? found(v2, length(astrometric2)) : found(astrometric2);
342
+ }
343
+ const place = observerAt(center, time);
344
+ if (correction === "geometric") return found(sub(fromGeocentre(body, time), place));
345
+ if (correction === "apparent" && body === Body.Moon && center.kind === "geocentric") {
346
+ return found(vec(GeoMoon(time)));
347
+ }
348
+ const from = add(vec(HelioVector(Body.Earth, time)), place);
349
+ const { v, left } = retarded((t) => sub(vec(HelioVector(body, t)), from), time);
350
+ const astrometric = add(v, sunMotion(left, time));
351
+ if (correction === "astrometric") return found(astrometric);
352
+ const apparent = center.kind === "geocentric" ? vec(GeoVector(body, time, true)) : retarded((t) => sub(fromGeocentre(body, t), observerAt(center, t)), time).v;
353
+ return found(apparent, length(astrometric));
354
+ }
355
+ function geometricState(body, center, time) {
356
+ if (body === Body.Moon) return null;
357
+ const split = (s) => ({ r: vec(s), v: [s.vx, s.vy, s.vz] });
358
+ if (center.kind === "barycentric") return split(BaryState(body, time));
359
+ const target = split(HelioState(body, time));
360
+ if (center.kind === "heliocentric") return target;
361
+ const earth = split(HelioState(Body.Earth, time));
362
+ const r = sub(target.r, earth.r);
363
+ const v = sub(target.v, earth.v);
364
+ if (center.kind === "geocentric") return { r, v };
365
+ const site = observerState(center.site, time);
366
+ return { r: sub(r, site.r), v: sub(v, site.v) };
367
+ }
368
+
369
+ // src/calc-ayanamsa.ts
370
+ var NEAR_SUN_DEGREES = 2;
371
+ var AT_SUN_DEGREES = 0.3;
372
+ var AYANAMSA_BOUNDS = {
373
+ /**
374
+ * Epoch and linear definitions, built-in and callers': values from −359.9° to 359.9°, an epoch definition's
375
+ * epoch anywhere in the span, a linear one's anywhere a Date reaches, rates to ±3,600″ a year; 134,833 comparisons.
376
+ * A linear one's rate rounds by up to 1.5 units of 2⁻⁴⁴° in 0.002 day; calc's speeds add their own (docs/calc.md).
377
+ */
378
+ epochOrLinear: { position: 46e-8, rate: 16e-8 },
379
+ /**
380
+ * Callers' epoch definitions on the engine's precession (IAU 2006) whose epoch is outside the span but inside
381
+ * EPHEMERIS_SPAN, beyond which calc refuses them: the engine's precession and ERFA's part the further the
382
+ * epoch is from J2000.0, most at the span's ends; 21,658 comparisons (docs/evidence/calc-epochs-2026-10-06).
383
+ */
384
+ epochOutsideSpan: { position: 37e-4, rate: 13e-8 },
385
+ /**
386
+ * The same on Newcomb's or IAU 1976's precession, whose zodiac is held where that model puts it at J2000.0, so
387
+ * that most of the precession's difference from ERFA's cancels; 43,316 comparisons.
388
+ */
389
+ olderEpochOutsideSpan: { position: 18e-6, rate: 12e-8 },
390
+ /** Star definitions, the star 2° or more from the Sun: 306,850 comparisons. */
391
+ star: { position: 13e-4, rate: 39e-5 },
392
+ /** Star definitions, the star 0.3° to 2° from the Sun: 238,364 comparisons. */
393
+ starNearSun: { position: 48e-4, rate: 0.026 },
394
+ /** Star definitions, the star within 0.3° of the Sun, on or near its disc: 1,653,932 comparisons. */
395
+ starAtSun: { position: 0.058, rate: 27 }
396
+ };
397
+ var AYANAMSA_BASIS = "largest difference of the mean ayanamsa from ERFA's construction of the same definition; docs/evidence/calc-sidereal-2026-10-05";
398
+ var AYANAMSA_EPOCH_BASIS = "largest difference of the mean ayanamsa from ERFA's construction of the same definition, for epochs from 0001 to 3998 outside 1800 to 2200; docs/evidence/calc-epochs-2026-10-06";
399
+ function ayanamsaBand(definition, elongation) {
400
+ if (definition.kind === "epoch" && outsideSpanEpoch(definition)) {
401
+ return definition.model === "engine" ? "epochOutsideSpan" : "olderEpochOutsideSpan";
402
+ }
403
+ if (definition.kind !== "star") return "epochOrLinear";
404
+ if (elongation === null || elongation < AT_SUN_DEGREES) return "starAtSun";
405
+ return elongation < NEAR_SUN_DEGREES ? "starNearSun" : "star";
406
+ }
407
+ function ayanamsaBound(definition, elongation) {
408
+ const band = ayanamsaBand(definition, elongation);
409
+ const outside = band === "epochOutsideSpan" || band === "olderEpochOutsideSpan";
410
+ return { ...AYANAMSA_BOUNDS[band], basis: outside ? AYANAMSA_EPOCH_BASIS : AYANAMSA_BASIS };
411
+ }
412
+ function addBounds(a, b) {
413
+ return Math.ceil(Number(((a + b) * 1e9).toPrecision(15))) / 1e9;
414
+ }
415
+
416
+ // src/calc.ts
417
+ var PLANETS = ["Sun", "Moon", "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"];
418
+ var POINTS = ["North Node", "South Node", "Mean Node", "Mean South Node", "Black Moon Lilith"];
419
+ var CALC_BODIES = Object.freeze([...PLANETS, ...POINTS]);
420
+ var CHART_BODIES = CALC_BODIES.filter((body) => body !== "Earth" && !/^Mean|Lilith/.test(body));
421
+ var CALC_FRAMES2 = Object.freeze([...CALC_FRAMES]);
422
+ var CALC_AYANAMSAS = Object.freeze(Object.keys(AYANAMSAS));
423
+ var CALC_RECEIPT_SCHEMA = "zodiacs.calc-receipt.v1";
424
+ var CALC_SPAN = REFERENCE_SPAN;
425
+ var DEG2 = Math.PI / 180;
426
+ var RAD2 = 180 / Math.PI;
427
+ var DAY_MS = 864e5;
428
+ var J2000_JD = 2451545;
429
+ var J2000_MS = Date.UTC(2e3, 0, 1, 12);
430
+ var SPAN_DAYS = [CALC_SPAN.from, CALC_SPAN.to].map((iso) => (Date.parse(iso) - J2000_MS) / DAY_MS);
431
+ var STEP_DAYS = 1e-3;
432
+ var NODE_STEP_DAYS = 0.25;
433
+ function fields(value, label, keys) {
434
+ if (value === null || typeof value !== "object" || Array.isArray(value) || value instanceof Date) {
435
+ throw new RangeError(`${label} must be an object.`);
436
+ }
437
+ if (Object.keys(value).some((key) => !keys.includes(key))) {
438
+ throw new RangeError(`${label} takes only ${keys.join(", ")}.`);
439
+ }
440
+ return value;
441
+ }
442
+ function oneOf(value, options, label, fallback) {
443
+ if (value === void 0 && fallback !== void 0) return fallback;
444
+ if (typeof value !== "string" || !options.includes(value)) {
445
+ throw new RangeError(`${label} must be one of ${options.join(", ")}.`);
446
+ }
447
+ return value;
448
+ }
449
+ function within(value, label, low, high) {
450
+ if (typeof value !== "number" || !Number.isFinite(value) || value < low || value > high) {
451
+ throw new RangeError(`${label} must be a number from ${low} to ${high}.`);
452
+ }
453
+ return value;
454
+ }
455
+ function yesNo(value, label, fallback) {
456
+ if (value === void 0) return fallback;
457
+ if (typeof value !== "boolean") throw new RangeError(`${label} must be true or false.`);
458
+ return value;
459
+ }
460
+ function readTime(value, label) {
461
+ const iso = (text) => {
462
+ try {
463
+ return dateFrom(text, label);
464
+ } catch {
465
+ throw new RangeError(`${label} must be a valid Date, or an ISO 8601 date or date-time with a UTC offset.`);
466
+ }
467
+ };
468
+ if (typeof value === "string" || value instanceof Date) {
469
+ const date = iso(value);
470
+ const record = { iso: typeof value === "string" ? value : date.toISOString() };
471
+ return { record, ms: date.getTime(), scale: "utc", pin: void 0, civil: true };
472
+ }
473
+ if (typeof value === "number") throw new RangeError(`${label} must be an ISO string, a Date or { jd, scale }.`);
474
+ const time = fields(value, label, ["iso", "jd", "scale", "deltaT"]);
475
+ const pin = time.deltaT === void 0 ? void 0 : within(time.deltaT, `${label}.deltaT`, -1e10, 1e10);
476
+ const pinned = pin === void 0 ? {} : { deltaT: pin };
477
+ if (time.iso === void 0 === (time.jd === void 0)) throw new RangeError(`${label} takes iso, or jd and scale.`);
478
+ if (time.iso !== void 0) {
479
+ if (typeof time.iso !== "string" || time.scale !== void 0) throw new RangeError(`${label}.iso must be an ISO string, without a scale.`);
480
+ return { record: { iso: time.iso, ...pinned }, ms: iso(time.iso).getTime(), scale: "utc", pin, civil: true };
481
+ }
482
+ const jd = time.jd;
483
+ if (typeof jd !== "number" || !Number.isFinite(jd)) throw new RangeError(`${label}.jd must be a finite Julian date.`);
484
+ if (typeof time.scale === "string" && TIME_SCALE_NAMES.includes(time.scale.toLowerCase()) && !TIME_SCALE_NAMES.includes(time.scale)) {
485
+ throw new RangeError(`${label}.scale must be one of ${TIME_SCALE_NAMES.join(", ")}: lowercase since 1.0.0.`);
486
+ }
487
+ const scale = oneOf(time.scale, TIME_SCALE_NAMES, `${label}.scale`);
488
+ return { record: { jd, scale, ...pinned }, ms: J2000_MS + (jd - J2000_JD) * DAY_MS, scale, pin, civil: false };
489
+ }
490
+ function readPlace(value, label, withHeight = false) {
491
+ const place = fields(value, label, withHeight ? ["latitude", "longitude", "height"] : ["latitude", "longitude"]);
492
+ return {
493
+ latitude: within(place.latitude, `${label}.latitude`, -90, 90),
494
+ longitude: within(place.longitude, `${label}.longitude`, -180, 180),
495
+ height: place.height === void 0 ? 0 : within(place.height, `${label}.height`, -12e3, 1e5)
496
+ };
497
+ }
498
+ function refuse(reason, detail) {
499
+ return { status: "refused", reason, detail };
500
+ }
501
+ var outOfRange = () => ({
502
+ status: "refused",
503
+ reason: "out-of-range",
504
+ detail: `The instant's UT1 or TT is outside ${CALC_SPAN.from} to ${CALC_SPAN.to}, where the engine's positions have been compared with an independent ephemeris.`,
505
+ span: CALC_SPAN
506
+ });
507
+ var TROPICAL = { record: "tropical", definition: null, ids: ["zodiac:tropical"] };
508
+ var UNIX_JD = 24405875e-1;
509
+ function epochTT(epoch, label) {
510
+ const record = epoch.record;
511
+ const message = `${label} must be an instant in the range of a Date.`;
512
+ let jd;
513
+ if ("jd" in record && record.scale === "tt") {
514
+ jd = record.jd;
515
+ } else {
516
+ if (!(Math.abs(epoch.ms) <= 864e13)) throw new RangeError(message);
517
+ jd = J2000_JD + timeBasis(epoch.ms, epoch.scale, epoch.pin).ttDays;
518
+ }
519
+ if (!(Math.abs(jd - UNIX_JD) <= 1e8)) throw new RangeError(message);
520
+ return jd;
521
+ }
522
+ function readZodiac(value) {
523
+ if (value === void 0 || value === "tropical") return TROPICAL;
524
+ const sidereal = fields(value, "zodiac", ["sidereal"]).sidereal;
525
+ if (sidereal === void 0 || typeof sidereal === "string") {
526
+ const name = oneOf(sidereal, CALC_AYANAMSAS, "zodiac.sidereal");
527
+ return { record: { sidereal: name }, definition: AYANAMSAS[name], ids: ["zodiac:sidereal", `ayanamsa:${name}`] };
528
+ }
529
+ const label = "zodiac.sidereal";
530
+ const given = fields(sidereal, label, ["name", "epoch", "value", "rate", "model"]);
531
+ if (given.name !== void 0 && !isUserAyanamsaName(given.name)) {
532
+ throw new RangeError(`${label}.name must be a lowercase identifier of at most 64 characters that is not a built-in name.`);
533
+ }
534
+ const epoch = readTime(given.epoch, `${label}.epoch`);
535
+ const value_ = within(given.value, `${label}.value`, -360, 360);
536
+ if (given.rate !== void 0 && given.model !== void 0) throw new RangeError(`${label} takes a rate or a model, not both.`);
537
+ const rate = given.rate === void 0 ? void 0 : within(given.rate, `${label}.rate`, -3600, 3600);
538
+ const model = given.model === void 0 ? void 0 : oneOf(given.model, ["engine", "newcomb", "iau1976"], `${label}.model`);
539
+ const definition = userAyanamsa({
540
+ ...given.name === void 0 ? {} : { name: given.name },
541
+ epoch: { julianDateTT: epochTT(epoch, `${label}.epoch`) },
542
+ value: value_,
543
+ ...rate === void 0 ? {} : { rate },
544
+ ...model === void 0 ? {} : { model }
545
+ });
546
+ const user = rate === void 0 ? { name: definition.name, epoch: epoch.record, value: value_, model: model ?? "engine" } : { name: definition.name, epoch: epoch.record, value: value_, rate };
547
+ return { record: { sidereal: user }, definition, ids: ["zodiac:sidereal", `ayanamsa:user-${definition.kind}`] };
548
+ }
549
+ var insideEphemerisSpan = (definition) => definition.kind !== "epoch" || definition.epochTT - J2000_JD >= EPHEMERIS_SPAN.daysFromJ2000.from && definition.epochTT - J2000_JD <= EPHEMERIS_SPAN.daysFromJ2000.to;
550
+ function epochRefusal(zodiac) {
551
+ return zodiac.definition && !insideEphemerisSpan(zodiac.definition) ? {
552
+ status: "refused",
553
+ reason: "epoch-out-of-range",
554
+ detail: `The ayanamsa's epoch is outside ${EPHEMERIS_SPAN.fromTT} to ${EPHEMERIS_SPAN.toTT} TT (EPHEMERIS_SPAN), where the precession that carries it has been compared with ERFA's.`,
555
+ epochSpan: EPHEMERIS_SPAN
556
+ } : null;
557
+ }
558
+ var siderealFrame = (frame) => frame === "ecliptic-true-of-date" || frame === "ecliptic-mean-of-date";
559
+ function frameRefusal(zodiac, frame) {
560
+ return zodiac.definition && !siderealFrame(frame) ? refuse(
561
+ "unsupported-combination",
562
+ `The sidereal zodiac is counted along the ecliptic of date; frame ${frame} is not offered with it, only ecliptic-true-of-date and ecliptic-mean-of-date.`
563
+ ) : null;
564
+ }
565
+ function ayanamsaValue(definition, value, subtracted, k) {
566
+ return {
567
+ name: definition.name,
568
+ mean: value.mean * k,
569
+ nutation: value.nutation * k,
570
+ true: value.true * k,
571
+ subtracted,
572
+ bound: { value: ayanamsaBound(definition, value.elongation).position, unit: "arcsec", label: "measured", basis: ayanamsaBound(definition, value.elongation).basis }
573
+ };
574
+ }
575
+ function withAyanamsa(b, add2) {
576
+ if (add2 === null || b.value === null) return b;
577
+ return { ...b, value: addBounds(b.value, add2.value), basis: `${b.basis}; plus the ayanamsa's, ${add2.value} ${b.unit}: ${add2.basis}` };
578
+ }
579
+ function resolve(time) {
580
+ const inside = (days2, margin = 0) => days2 >= SPAN_DAYS[0] - margin && days2 < SPAN_DAYS[1] + margin;
581
+ const days = (time.ms - J2000_MS) / DAY_MS;
582
+ const shift = (time.pin ?? 0) / 86400;
583
+ if (!(inside(days, 2) && inside(days + (time.scale === "tt" ? -shift : shift), 2))) return null;
584
+ const basis = timeBasis(time.ms, time.scale, time.pin);
585
+ return inside(basis.ut1Days) && inside(basis.ttDays) ? basis : null;
586
+ }
587
+ function inSpan(time, run) {
588
+ const basis = resolve(time);
589
+ return basis === null ? outOfRange() : run(basis);
590
+ }
591
+ function onInput(time, ms, evaluate) {
592
+ return onChartClock(ms, time.scale, time.pin, evaluate);
593
+ }
594
+ function instant(basis) {
595
+ return {
596
+ utc: new Date(Math.round(basis.utcMs)).toISOString(),
597
+ jdUt1: J2000_JD + basis.ut1Days,
598
+ jdTt: J2000_JD + basis.ttDays,
599
+ deltaT: basis.deltaT,
600
+ timeScale: basis.timeScale
601
+ };
602
+ }
603
+ var TIME_BASIS_ID = "time:tt-from-leap-seconds-and-ut1-from-iers-1972-to-table-end;delta-t-model-otherwise";
604
+ function receipt(request, instants, ids, pin) {
605
+ return {
606
+ schema: CALC_RECEIPT_SCHEMA,
607
+ request,
608
+ instants,
609
+ conventions: [
610
+ ...ids,
611
+ `ephemeris:astronomy-engine@${EPHEMERIS.version}`,
612
+ pin === void 0 ? "deltat:time-basis" : "deltat:pinned",
613
+ TIME_BASIS_ID
614
+ ],
615
+ engine: { name: "@zodiacs/engine", version: ENGINE_VERSION, ephemeris: { ...EPHEMERIS } }
616
+ };
617
+ }
618
+ var isPoint = (body) => POINTS.includes(body);
619
+ var isTrueNode = (body) => body === "North Node" || body === "South Node";
620
+ function trueNode(at2) {
621
+ const s = GeoMoonState(at2);
622
+ const frame = eclipticFrame(at2.tt);
623
+ const [x, y] = meanEcliptic(
624
+ frame,
625
+ s.y * s.vz - s.z * s.vy,
626
+ s.z * s.vx - s.x * s.vz,
627
+ s.x * s.vy - s.y * s.vx
628
+ );
629
+ return normalizeLongitude(Math.atan2(x, -y) * RAD2 + frame.tilt.dpsi / 3600);
630
+ }
631
+ function pointAt(body, at2) {
632
+ const row = (raw2, lon, lat = 0) => ({ lon, lat, dist: null, xyz: null, raw: raw2 });
633
+ if (isTrueNode(body)) {
634
+ const raw2 = trueNode(at2);
635
+ return row(raw2, body === "North Node" ? raw2 : normalizeLongitude(raw2 + 180));
636
+ }
637
+ const centuries = at2.tt / 36525;
638
+ const nutation = tilt(at2.tt).dpsi / 3600;
639
+ if (body === "Black Moon Lilith") {
640
+ const apogee = meanApogee(centuries, nutation);
641
+ return row(apogee.lon, normalizeLongitude(apogee.lon), apogee.lat);
642
+ }
643
+ const raw = meanNodeLongitude(centuries, nutation);
644
+ return row(raw, normalizeLongitude(body === "Mean Node" ? raw : raw + 180));
645
+ }
646
+ function evaluator(body, frame, center, correction) {
647
+ if (isPoint(body)) {
648
+ return (at2) => {
649
+ const point = pointAt(body, at2);
650
+ if (frame === "ecliptic-true-of-date") return point;
651
+ const eqj = apply(transpose(frameMatrix("ecliptic-true-of-date", at2)), fromSpherical(point.lon, point.lat, 1));
652
+ const { lon, lat } = toSpherical(apply(frameMatrix(frame, at2), eqj));
653
+ return { lon, lat, dist: null, xyz: null, raw: lon };
654
+ };
655
+ }
656
+ const target = body;
657
+ return (at2) => {
658
+ const { v, dist } = locate(target, center, correction, at2);
659
+ const turned = apply(frameMatrix(frame, at2), v);
660
+ const { lon, lat } = frame === "ecliptic-true-of-date" ? eclipticOfDate(v[0], v[1], v[2], at2.tt) : toSpherical(turned);
661
+ const k = dist / length(turned);
662
+ return { lon, lat, dist, xyz: [turned[0] * k, turned[1] * k, turned[2] * k], raw: lon };
663
+ };
664
+ }
665
+ function turnedBack([x, y, z], angle) {
666
+ const c = Math.cos(angle * DEG2);
667
+ const s = Math.sin(angle * DEG2);
668
+ return [x * c + y * s, y * c - x * s, z];
669
+ }
670
+ function siderealOf(evaluate, definition, frame) {
671
+ const trueOfDate = frame === "ecliptic-true-of-date";
672
+ return (at2) => {
673
+ const row = evaluate(at2);
674
+ const value = ayanamsaAt(definition, at2);
675
+ const subtracted = trueOfDate ? value.true : value.mean;
676
+ return {
677
+ lon: wrap360(wrap360(row.lon) - subtracted),
678
+ lat: row.lat,
679
+ dist: row.dist,
680
+ xyz: row.xyz && turnedBack(row.xyz, subtracted),
681
+ raw: row.raw - subtracted,
682
+ ayanamsa: value
683
+ };
684
+ };
685
+ }
686
+ function positionIds(body, frame, kind, correction, zodiac) {
687
+ const ids = [...zodiac.ids, `frame:${frame}`, `center:${kind}`];
688
+ if (isPoint(body)) {
689
+ ids.push("correction:not-applicable", body.endsWith("Lilith") ? "lilith:mean" : body.startsWith("Mean") ? "node:mean" : "node:true-osculating");
690
+ } else {
691
+ ids.push(`correction:${correction}`);
692
+ if (body === "Moon" && kind === "geocentric" && correction !== "astrometric") ids.push("moon:series-at-instant");
693
+ else if (correction !== "geometric") {
694
+ ids.push("light-time:newtonian", "deflection:none");
695
+ if (correction === "apparent" && kind !== "barycentric") ids.push("aberration:backdated-observer");
696
+ }
697
+ }
698
+ if (isPoint(body) || !inertial(frame)) ids.push("precession:iau2006");
699
+ if (frame.includes("true")) ids.push("nutation:iau2000b");
700
+ if (isPoint(body) || frame.startsWith("ecliptic")) ids.push("obliquity:iau2006");
701
+ if (frame.endsWith("icrs")) ids.push("frame-bias:iau2000");
702
+ if (kind === "barycentric") ids.push("barycentre:sun-and-giant-planets");
703
+ if (kind === "topocentric") ids.push("observer:iers2003-ellipsoid;no-polar-motion");
704
+ return ids;
705
+ }
706
+ function bound(value, unit, estimated) {
707
+ return value === void 0 || value === null ? { value: null, unit, label: "estimated", basis: "not compared with an independent ephemeris" } : { value, unit, label: estimated === null ? "measured" : "estimated", basis: estimated ?? MEASURED_BASIS };
708
+ }
709
+ function up2(x) {
710
+ const unit = 10 ** (Math.floor(Math.log10(x)) - 1);
711
+ return Number((Math.ceil(x / unit) * unit).toPrecision(2));
712
+ }
713
+ function barycentricSun(r, v) {
714
+ const { au: e, auPerDay: ev } = BARYCENTRE_ERROR;
715
+ const rate = v === null ? null : ev / r + (v + ev) * e * (1 / r ** 2 + 1 / (r * (r - e)));
716
+ return [up2(Math.asin(e / r) * RAD2 * 3600), up2(e / (r - e)), rate === null ? null : up2(rate * RAD2 * 3600)];
717
+ }
718
+ function calc(request) {
719
+ const asked = fields(request, "calc request", ["body", "time", "frame", "center", "zodiac", "flags"]);
720
+ const body = oneOf(asked.body, CALC_BODIES, "body");
721
+ const time = readTime(asked.time, "time");
722
+ const frame = oneOf(asked.frame, CALC_FRAMES2, "frame", "ecliptic-true-of-date");
723
+ let center;
724
+ let centerRecord;
725
+ if (asked.center === void 0 || typeof asked.center === "string") {
726
+ const kind2 = oneOf(asked.center, ["geocentric", "heliocentric", "barycentric"], "center", "geocentric");
727
+ center = { kind: kind2 };
728
+ centerRecord = kind2;
729
+ } else {
730
+ const site = readPlace(fields(asked.center, "center", ["topocentric"]).topocentric, "center.topocentric", true);
731
+ center = { kind: "topocentric", site };
732
+ centerRecord = { topocentric: site };
733
+ }
734
+ const given = asked.flags === void 0 ? {} : fields(asked.flags, "flags", ["correction", "speeds", "cartesian", "units", "deflection"]);
735
+ const flags = {
736
+ correction: oneOf(given.correction, ["apparent", "astrometric", "geometric"], "flags.correction", "apparent"),
737
+ speeds: yesNo(given.speeds, "flags.speeds", true),
738
+ cartesian: yesNo(given.cartesian, "flags.cartesian", false),
739
+ units: oneOf(given.units, ["degrees", "radians"], "flags.units", "degrees"),
740
+ deflection: yesNo(given.deflection, "flags.deflection", false)
741
+ };
742
+ const zodiac = readZodiac(asked.zodiac);
743
+ const point = isPoint(body);
744
+ const kind = center.kind;
745
+ const refusal = (flags.deflection ? refuse("not-in-this-version", "Gravitational light deflection is not modelled in this version.") : point && kind !== "geocentric" ? refuse("unsupported-combination", `${body} is a point of the Moon's geocentric orbit; only the geocentric center is offered.`) : point && flags.cartesian ? refuse("unsupported-combination", `${body} has no distance, so no cartesian position.`) : body === "Sun" && kind === "heliocentric" ? refuse("unsupported-combination", "The Sun is the heliocentric origin.") : body === "Earth" && (kind === "geocentric" || kind === "topocentric") ? refuse("unsupported-combination", "The Earth is offered heliocentric or barycentric only.") : frameRefusal(zodiac, frame)) ?? epochRefusal(zodiac);
746
+ if (refusal) return refusal;
747
+ const correction = flags.correction;
748
+ const definition = zodiac.definition;
749
+ return inSpan(time, (basis) => {
750
+ const tropical = evaluator(body, frame, center, correction);
751
+ const evaluate = definition === null ? tropical : siderealOf(tropical, definition, frame);
752
+ const now = onInput(time, time.ms, evaluate);
753
+ const step = isTrueNode(body) ? NODE_STEP_DAYS : STEP_DAYS;
754
+ const analytic = flags.speeds && correction === "geometric" && inertial(frame) && !point && body !== "Moon";
755
+ let speeds = null;
756
+ let velocity = null;
757
+ if (analytic) {
758
+ const { state, turn } = onInput(time, time.ms, (at2) => ({
759
+ state: geometricState(body, center, at2),
760
+ turn: frameMatrix(frame, at2)
761
+ }));
762
+ velocity = apply(turn, state.v);
763
+ speeds = sphericalRates(apply(turn, state.r), velocity);
764
+ } else if (flags.speeds) {
765
+ const shift = (days) => {
766
+ const ms = time.ms + days * DAY_MS;
767
+ return onInput(time, ms, (at2, sampled) => ({ row: evaluate(at2), basis: sampled }));
768
+ };
769
+ const before = shift(-step);
770
+ const after = shift(step);
771
+ const elapsed = elapsedDays(before.basis, after.basis, 2 * step);
772
+ const rate = (a2, b2) => (a2 - b2) / elapsed;
773
+ let turn = after.row.raw - before.row.raw;
774
+ if (turn > 180) turn -= 360;
775
+ if (turn < -180) turn += 360;
776
+ speeds = {
777
+ lon: turn / elapsed,
778
+ lat: rate(after.row.lat, before.row.lat),
779
+ dist: now.dist === null ? null : rate(after.row.dist, before.row.dist)
780
+ };
781
+ const [a, b] = [after.row.xyz, before.row.xyz];
782
+ if (a && b) velocity = [rate(a[0], b[0]), rate(a[1], b[1]), rate(a[2], b[2])];
783
+ }
784
+ const method = !flags.speeds ? null : analytic ? "analytic" : "central-difference";
785
+ const k = flags.units === "radians" ? DEG2 : 1;
786
+ let row = MEASURED[`${kind}/${point ? "apparent" : correction}`]?.[body];
787
+ let estimated = null;
788
+ if (!row && kind === "topocentric") {
789
+ row = MEASURED[`geocentric/${correction}`]?.[body];
790
+ estimated = "the geocentric bound for this correction; topocentric positions were compared only for the Sun, the Moon and Mars";
791
+ } else if (kind === "barycentric" && body === "Sun") {
792
+ row = barycentricSun(now.dist, velocity && length(velocity));
793
+ estimated = `the largest angle, relative distance and rate of direction that the error of astronomy-engine's barycentre, ${BARYCENTRE_ERROR.au.toExponential()} au and ${BARYCENTRE_ERROR.auPerDay.toExponential()} au/day from 1800 to 2200, allows at this distance and speed; docs/evidence/calc-api`;
794
+ }
795
+ const ids = positionIds(body, frame, kind, correction, zodiac);
796
+ if (method) ids.push(method === "analytic" ? "speed:analytic" : `speed:central-difference-${step}d`);
797
+ const sidereal = definition === null ? null : now.ayanamsa;
798
+ const added = sidereal && ayanamsaBound(definition, sidereal.elongation);
799
+ return {
800
+ status: "ok",
801
+ body,
802
+ frame,
803
+ lon: now.lon * k,
804
+ lat: now.lat * k,
805
+ dist: now.dist,
806
+ speeds: speeds && { lon: speeds.lon * k, lat: speeds.lat * k, dist: speeds.dist },
807
+ cartesian: flags.cartesian && now.xyz ? { x: now.xyz[0], y: now.xyz[1], z: now.xyz[2], vx: velocity?.[0] ?? null, vy: velocity?.[1] ?? null, vz: velocity?.[2] ?? null } : null,
808
+ ayanamsa: sidereal && ayanamsaValue(definition, sidereal, frame === "ecliptic-true-of-date" ? "true" : "mean", k),
809
+ bounds: {
810
+ position: withAyanamsa(bound(row?.[0], "arcsec", estimated), added && { value: added.position, basis: added.basis }),
811
+ distance: point ? null : bound(row?.[1], "relative", estimated),
812
+ speed: method && {
813
+ ...withAyanamsa(bound(row?.[2], "arcsec/day", estimated), added && { value: added.rate, basis: added.basis }),
814
+ method,
815
+ stepDays: analytic ? null : step
816
+ }
817
+ },
818
+ receipt: receipt(
819
+ { body, time: time.record, frame, center: centerRecord, zodiac: zodiac.record, flags },
820
+ [instant(basis)],
821
+ ids,
822
+ time.pin
823
+ )
824
+ };
825
+ });
826
+ }
827
+ function houses(request) {
828
+ const asked = fields(request, "houses request", ["time", "place", "houseSystem", "zodiac"]);
829
+ const time = readTime(asked.time, "time");
830
+ const { latitude, longitude } = readPlace(asked.place, "place");
831
+ const system = validateBirthSettings({ houseSystem: asked.houseSystem }).houseSystem ?? "whole";
832
+ const zodiac = readZodiac(asked.zodiac);
833
+ const refusal = epochRefusal(zodiac);
834
+ if (refusal) return refusal;
835
+ const definition = zodiac.definition;
836
+ return inSpan(time, (used) => {
837
+ const { input, value } = onInput(time, time.ms, (at2) => ({
838
+ input: { gastHours: gastHours(at2), latitude, longitude, obliquity: tilt(at2.tt).tobl },
839
+ value: definition && ayanamsaAt(definition, at2)
840
+ }));
841
+ const tropical = computeAngles(input);
842
+ const { houses: computed, fellBack } = computeHouses(system, input, tropical);
843
+ const zodiacal = value === null ? (lon) => lon : (lon) => wrap360(wrap360(lon) - value.true);
844
+ const angles = value === null ? tropical : { asc: zodiacal(tropical.asc), mc: zodiacal(tropical.mc), dsc: zodiacal(tropical.dsc), ic: zodiacal(tropical.ic) };
845
+ const cusps = value === null ? computed.cusps : computed.system === "whole" ? wholeSignCusps(angles.asc) : computed.cusps.map(zodiacal);
846
+ const bounded = definition && value && ayanamsaBound(definition, value.elongation);
847
+ const added = bounded && { value: bounded.position, basis: bounded.basis };
848
+ const basis = (what) => `largest difference over the conformance suite's L2 ${what}, whose arbiter is ERFA with each system's definition`;
849
+ return {
850
+ status: "ok",
851
+ requested: system,
852
+ system: computed.system,
853
+ cusps,
854
+ angles,
855
+ // Normalized once more, as chartPoints() reports them.
856
+ vertex: zodiacal(normalizeLongitude(vertexOf(input, tropical))),
857
+ eastPoint: zodiacal(normalizeLongitude(eastPointOf(input))),
858
+ armc: ramcOf(input),
859
+ obliquity: input.obliquity,
860
+ flags: fellBack ? ["polar-fallback"] : [],
861
+ ayanamsa: value && ayanamsaValue(definition, value, "true", 1),
862
+ bounds: {
863
+ angles: withAyanamsa(
864
+ { value: 0.02, unit: "arcsec", label: "measured", basis: basis("vectors of the ascendant, midheaven, Vertex and East Point") },
865
+ added
866
+ ),
867
+ cusps: withAyanamsa({ value: 0.08, unit: "arcsec", label: "measured", basis: basis("cusp vectors, thirteen systems") }, added)
868
+ },
869
+ receipt: receipt(
870
+ { time: time.record, place: { latitude, longitude }, houseSystem: system, zodiac: zodiac.record },
871
+ [instant(used)],
872
+ [
873
+ ...zodiac.ids,
874
+ `house:${system}`,
875
+ ...fellBack ? ["polar-fallback:whole"] : [],
876
+ "angles:gast-and-true-obliquity",
877
+ "sidereal-time:gast-iau2006-era",
878
+ "nutation:iau2000b",
879
+ "obliquity:iau2006"
880
+ ],
881
+ time.pin
882
+ )
883
+ };
884
+ });
885
+ }
886
+ function events(request) {
887
+ const asked = fields(request, "events request", ["kind", "body", "longitude", "from", "to", "zodiac", "stepDays", "maxSamples"]);
888
+ const kind = oneOf(asked.kind, ["longitude-crossing"], "kind");
889
+ const body = oneOf(asked.body, CALC_BODIES, "body");
890
+ const longitude = within(asked.longitude, "longitude", -Number.MAX_VALUE, Number.MAX_VALUE);
891
+ const from = readTime(asked.from, "from");
892
+ const to = readTime(asked.to, "to");
893
+ const stepDays = asked.stepDays === void 0 ? 5 : asked.stepDays;
894
+ const budget = asked.maxSamples === Infinity ? void 0 : asked.maxSamples;
895
+ const limit = budget === void 0 ? {} : { maxSamples: budget };
896
+ const zodiac = readZodiac(asked.zodiac);
897
+ const refusal = (!CHART_BODIES.includes(body) ? refuse("unsupported-combination", `Crossings are searched for the bodies positions() gives; ${body} is not one.`) : from.pin !== void 0 || to.pin !== void 0 ? refuse("unsupported-combination", "Crossing searches run on the engine's \u0394T model; a pinned \u0394T is not offered.") : null) ?? epochRefusal(zodiac);
898
+ if (refusal) return refusal;
899
+ const definition = zodiac.definition;
900
+ const longitudeAt = definition === null ? bodyLongitude : (b, date) => {
901
+ const tropical = bodyLongitude(b, date);
902
+ return wrap360(wrap360(tropical) - onChartClock(date.getTime(), "utc", void 0, (at2) => ayanamsaAt(definition, at2).true));
903
+ };
904
+ const start = resolve(from);
905
+ const end = resolve(to);
906
+ if (start === null || end === null) return outOfRange();
907
+ {
908
+ const dated = (basis) => new Date(Math.round(basis.utcMs));
909
+ const found = searchLongitudeCrossingsWith(
910
+ longitudeAt,
911
+ body,
912
+ longitude,
913
+ dated(start),
914
+ dated(end),
915
+ { stepDays, ...limit }
916
+ );
917
+ if (found.status === "refused") {
918
+ const { samples, maxSamples } = found;
919
+ return { status: "refused", reason: "sample-budget", detail: `The search needs more than ${maxSamples} evaluations.`, samples, maxSamples };
920
+ }
921
+ return {
922
+ status: "ok",
923
+ kind,
924
+ events: found.crossings.map(({ at: at2, retrograde }) => {
925
+ const { ut1Days, ttDays } = timeBasis(at2.getTime(), "utc");
926
+ return { at: at2.toISOString(), jdUt1: J2000_JD + ut1Days, jdTt: J2000_JD + ttDays, retrograde };
927
+ }),
928
+ samples: found.samples,
929
+ bounds: {
930
+ timing: {
931
+ value: stepDays * 86400 / 2 ** 24,
932
+ unit: "s",
933
+ label: "estimated",
934
+ basis: "the bisection bracket, step / 2^24, on the engine's own longitudes; the ephemeris's error over the body's speed adds to it" + (definition === null ? "" : ", and in the sidereal zodiac the ayanamsa's")
935
+ }
936
+ },
937
+ receipt: receipt(
938
+ { kind, body, longitude, from: from.record, to: to.record, zodiac: zodiac.record, stepDays, ...limit },
939
+ [instant(start), instant(end)],
940
+ [...positionIds(body, "ecliptic-true-of-date", "geocentric", "apparent", zodiac), "search:scan-and-bisect"]
941
+ )
942
+ };
943
+ }
944
+ }
945
+ function siderealOfChart(computed, definition) {
946
+ const sidereal = siderealChartOf(computed, definition);
947
+ const value = sidereal.ayanamsaValue;
948
+ const { elongation } = ayanamsaAt(definition, AstroTime.FromTerrestrialTime(value.julianDateTT - J2000_JD));
949
+ return {
950
+ ayanamsa: ayanamsaValue(definition, { mean: value.mean, nutation: value.nutation, true: value.true, elongation }, "true", 1),
951
+ bodies: sidereal.bodies.map(({ body, lon }) => ({ body, lon })),
952
+ ascendant: sidereal.ascendant === null ? null : sidereal.ascendant.lon,
953
+ midheaven: sidereal.midheaven === null ? null : sidereal.midheaven.lon,
954
+ houseSystem: sidereal.houseSystem,
955
+ cusps: sidereal.cusps === null ? null : sidereal.cusps.map((cusp) => cusp.lon)
956
+ };
957
+ }
958
+ function chart(request) {
959
+ const asked = fields(request, "chart request", ["time", "place", "houseSystem", "timeKnown", "timeFlags", "zodiac"]);
960
+ const time = readTime(asked.time, "time");
961
+ const site = asked.place === void 0 ? null : readPlace(asked.place, "place");
962
+ const place = site === null ? null : { latitude: site.latitude, longitude: site.longitude };
963
+ const settings = validateBirthSettings({ houseSystem: asked.houseSystem, timeKnown: asked.timeKnown });
964
+ const supplied = asked.timeFlags === void 0 ? void 0 : snapshotFlags(asked.timeFlags).values;
965
+ const zodiac = readZodiac(asked.zodiac);
966
+ const refusal = epochRefusal(zodiac);
967
+ if (refusal) return refusal;
968
+ const whole = { ...time, ms: Math.round(time.ms) };
969
+ return inSpan(whole, (basis) => {
970
+ const utc = new Date(whole.ms);
971
+ const houseSystem = settings.houseSystem ?? "whole";
972
+ const timeKnown = settings.timeKnown ?? true;
973
+ const possible = !timeKnown ? ["no-time"] : settings.houseSystem && isPolarUndefinedHouseSystem(houseSystem) && place ? ["polar-fallback"] : [];
974
+ assertDerivedFlags(supplied ?? [], possible);
975
+ const input = {
976
+ utc,
977
+ houseSystem,
978
+ timeKnown,
979
+ ...place,
980
+ ...supplied && { flags: timeFlags(supplied) },
981
+ ...whole.pin === void 0 ? {} : { deltaT: whole.pin },
982
+ ...whole.scale === "utc" ? {} : { timeScale: whole.scale }
983
+ };
984
+ const used = instant(basis);
985
+ const computed = computeChart(input);
986
+ assertDerivedFlags(supplied ?? [], computed.flags);
987
+ return {
988
+ status: "ok",
989
+ chart: computed,
990
+ sidereal: zodiac.definition && siderealOfChart(computed, zodiac.definition),
991
+ receipt: receipt(
992
+ {
993
+ time: time.record,
994
+ ...place && { place },
995
+ houseSystem,
996
+ timeKnown,
997
+ ...supplied && { timeFlags: supplied },
998
+ zodiac: zodiac.record
999
+ },
1000
+ [used],
1001
+ [
1002
+ ...zodiac.ids,
1003
+ "frame:ecliptic-true-of-date",
1004
+ "center:geocentric",
1005
+ "correction:apparent",
1006
+ "light-time:newtonian",
1007
+ "deflection:none",
1008
+ "aberration:backdated-observer",
1009
+ "moon:series-at-instant",
1010
+ "node:true-osculating",
1011
+ "precession:iau2006",
1012
+ "nutation:iau2000b",
1013
+ "obliquity:iau2006",
1014
+ ...computed.houses === null ? [] : [
1015
+ `house:${houseSystem}`,
1016
+ ...computed.houses.system === houseSystem ? [] : ["polar-fallback:whole"],
1017
+ "angles:gast-and-true-obliquity",
1018
+ "sidereal-time:gast-iau2006-era"
1019
+ ],
1020
+ "aspects:major",
1021
+ `speed:central-difference-${STEP_DAYS}d`,
1022
+ `speed:central-difference-${NODE_STEP_DAYS}d`
1023
+ ],
1024
+ time.pin
1025
+ )
1026
+ };
1027
+ });
1028
+ }
1029
+ export {
1030
+ CALC_AYANAMSAS,
1031
+ CALC_BODIES,
1032
+ CALC_FRAMES2 as CALC_FRAMES,
1033
+ CALC_RECEIPT_SCHEMA,
1034
+ CALC_SPAN,
1035
+ calc,
1036
+ chart,
1037
+ events,
1038
+ houses
1039
+ };