@zodiacs/engine 0.1.1-rc.16 → 1.1.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 (80) hide show
  1. package/CHANGELOG.md +1478 -0
  2. package/LICENSING.md +184 -30
  3. package/NOTICE +81 -14
  4. package/README.md +345 -67
  5. package/dist/{api-VOW6Umy5.d.ts → api-ChL1N2Sr.d.ts} +44 -7
  6. package/dist/ayanamsa-ClFzkKmV.d.ts +135 -0
  7. package/dist/calc.d.ts +218 -21
  8. package/dist/calc.js +580 -160
  9. package/dist/chunk-2PZYJQV5.js +83 -0
  10. package/dist/chunk-47ERTK5X.js +27 -0
  11. package/dist/{chunk-O3NJRGJ2.js → chunk-4XOYTBLS.js} +1 -1
  12. package/dist/chunk-767FTO7O.js +48 -0
  13. package/dist/{chunk-N4B5JNMA.js → chunk-7Y2F2IWN.js} +40 -28
  14. package/dist/chunk-B4M2Y7FT.js +96 -0
  15. package/dist/{chunk-KHBLFXFG.js → chunk-B5LKF437.js} +29 -28
  16. package/dist/{chunk-ONBZ4HK7.js → chunk-BHJXUY67.js} +4 -2
  17. package/dist/{chunk-PFGUCNOK.js → chunk-BMDASNPB.js} +6 -6
  18. package/dist/chunk-I3L4POY7.js +18 -0
  19. package/dist/{chunk-I7O5EGFV.js → chunk-LNGURVNH.js} +3 -3
  20. package/dist/{chunk-4NV4ZEFZ.js → chunk-NNOSOOWS.js} +4 -4
  21. package/dist/chunk-OVXQQEXL.js +41 -0
  22. package/dist/{chunk-WOU7JVD3.js → chunk-QLIEEICB.js} +205 -194
  23. package/dist/chunk-RMBWKZI2.js +130 -0
  24. package/dist/{chunk-AECKV73C.js → chunk-TSS2SZWQ.js} +8 -2
  25. package/dist/{chunk-L6ZHWJZ6.js → chunk-TZVPZHZM.js} +51 -29
  26. package/dist/chunk-WBTWY2OB.js +478 -0
  27. package/dist/chunk-Y4E3WJU5.js +87 -0
  28. package/dist/chunk-YPU3MDNI.js +852 -0
  29. package/dist/conventions.d.ts +70 -0
  30. package/dist/conventions.js +26 -0
  31. package/dist/crossings.d.ts +22 -10
  32. package/dist/crossings.js +1 -1
  33. package/dist/de440-pack.d.ts +43 -0
  34. package/dist/de440-pack.js +16 -0
  35. package/dist/de440.d.ts +113 -0
  36. package/dist/de440.js +19 -0
  37. package/dist/deltat.d.ts +28 -3
  38. package/dist/deltat.js +1 -1
  39. package/dist/ephemeris-exTSqBgb.d.ts +60 -0
  40. package/dist/geo.d.ts +46 -13
  41. package/dist/geo.js +4 -2
  42. package/dist/{houses-q1O2GGp4.d.ts → houses-Bh7GCnPi.d.ts} +14 -4
  43. package/dist/houses-extra.d.ts +22 -7
  44. package/dist/houses-extra.js +4 -2
  45. package/dist/index.d.ts +36 -49
  46. package/dist/index.js +54 -34
  47. package/dist/{internal-math-CmJ9xtaW.d.ts → internal-math-CxenuGfm.d.ts} +41 -27
  48. package/dist/internal-math.d.ts +4 -3
  49. package/dist/internal-math.js +14 -12
  50. package/dist/internal.d.ts +16 -7
  51. package/dist/internal.js +27 -6
  52. package/dist/lite-composite.js +114 -0
  53. package/dist/lite-declinations.js +253 -0
  54. package/dist/lite-dignities.js +333 -0
  55. package/dist/lite-sect.js +72 -0
  56. package/dist/lite.d.ts +82 -0
  57. package/dist/lite.js +4 -0
  58. package/dist/receipt.d.ts +3 -268
  59. package/dist/receipt.js +202 -89
  60. package/dist/reference-span-CILpclrz.d.ts +40 -0
  61. package/dist/{rulers-9wljfVaO.d.ts → rulers-CSSWtiWF.d.ts} +7 -2
  62. package/dist/sky.d.ts +26 -10
  63. package/dist/sky.js +23 -14
  64. package/dist/techniques.d.ts +160 -21
  65. package/dist/techniques.js +157 -89
  66. package/dist/time-bands-CZA9AlLg.d.ts +36 -0
  67. package/dist/time-scale-DIFNa0gz.d.ts +47 -0
  68. package/dist/time.d.ts +81 -0
  69. package/dist/time.js +74 -0
  70. package/dist/timing.d.ts +55 -17
  71. package/dist/timing.js +33 -45
  72. package/dist/types-DpPdtXgO.d.ts +335 -0
  73. package/dist/vedic.d.ts +150 -123
  74. package/dist/vedic.js +398 -440
  75. package/dist/window.d.ts +102 -80
  76. package/dist/window.js +108 -51
  77. package/dist/zone-history-BxmDCcTK.d.ts +290 -0
  78. package/package.json +26 -3
  79. package/dist/chunk-2OWGBT3O.js +0 -219
  80. package/dist/types-B4MCoCCS.d.ts +0 -228
@@ -216,8 +216,14 @@ function findLongitudeCrossingsWith(longitudeAt, body, targetLongitude, from, to
216
216
  return result.crossings;
217
217
  }
218
218
  function searchLongitudeCrossingsWith(longitudeAt, body, targetLongitude, from, to, options = {}) {
219
- if (options === null || typeof options !== "object") {
220
- throw new RangeError("Crossing search options must be an object.");
219
+ const prototype = options !== null && typeof options === "object" ? Object.getPrototypeOf(options) : void 0;
220
+ if (prototype !== Object.prototype && prototype !== null) {
221
+ throw new RangeError("Crossing search options must be a plain options object.");
222
+ }
223
+ for (const key of Reflect.ownKeys(options)) {
224
+ if (key !== "stepDays" && key !== "maxSamples") throw new RangeError(`Crossing search options has an unknown option: ${String(key)}.`);
225
+ const slot = Object.getOwnPropertyDescriptor(options, key);
226
+ if (!slot || !("value" in slot) || !slot.enumerable) throw new RangeError("Crossing search options must contain only plain data properties.");
221
227
  }
222
228
  const stepDays = options.stepDays === void 0 ? 5 : options.stepDays;
223
229
  const window = validWindow(targetLongitude, from, to, stepDays);
@@ -1,16 +1,3 @@
1
- import {
2
- dateFrom
3
- } from "./chunk-CPALRSPC.js";
4
- import {
5
- findLongitudeCrossingsWith,
6
- searchLongitudeCrossingsWith
7
- } from "./chunk-AECKV73C.js";
8
- import {
9
- assertDerivedFlags,
10
- snapshotFlags,
11
- timeFlags,
12
- validateBirthSettings
13
- } from "./chunk-PFGUCNOK.js";
14
1
  import {
15
2
  SPEED_STEP_DAYS,
16
3
  bodyLongitude,
@@ -18,26 +5,48 @@ import {
18
5
  computeChart,
19
6
  computeChartDeclinations,
20
7
  computePoints,
21
- longitudeSpeed
22
- } from "./chunk-WOU7JVD3.js";
8
+ deltaTExtrapolated,
9
+ ephemerisAt,
10
+ longitudeSpeed,
11
+ notingFallbacks
12
+ } from "./chunk-QLIEEICB.js";
13
+ import {
14
+ dateFrom
15
+ } from "./chunk-CPALRSPC.js";
16
+ import {
17
+ ASPECT_BODY_SET,
18
+ EPHEMERIS,
19
+ matchAspect
20
+ } from "./chunk-B4M2Y7FT.js";
23
21
  import {
24
22
  TIME_SCALE_NAMES,
25
23
  outsideReferenceSpan,
26
24
  timeBasis
27
- } from "./chunk-KHBLFXFG.js";
25
+ } from "./chunk-B5LKF437.js";
26
+ import {
27
+ findLongitudeCrossingsWith,
28
+ searchLongitudeCrossingsWith
29
+ } from "./chunk-TSS2SZWQ.js";
28
30
  import {
29
31
  POLAR_FALLBACK,
30
32
  isPolarUndefinedHouseSystem
31
- } from "./chunk-4NV4ZEFZ.js";
33
+ } from "./chunk-NNOSOOWS.js";
32
34
  import {
33
- ASPECT_BODIES,
34
- matchAspect,
35
35
  normalizeLongitude,
36
36
  signForLongitude
37
- } from "./chunk-2OWGBT3O.js";
37
+ } from "./chunk-RMBWKZI2.js";
38
+ import {
39
+ assertDerivedFlags,
40
+ snapshotFlags,
41
+ timeFlags,
42
+ validateBirthSettings
43
+ } from "./chunk-BMDASNPB.js";
38
44
 
39
45
  // src/returns.ts
40
46
  var DAY = 864e5;
47
+ function windowEnd(value, end) {
48
+ return dateFrom(value, `Crossing window ${end}`);
49
+ }
41
50
  function validMilliseconds(date, label) {
42
51
  if (!(date instanceof Date)) throw new RangeError(`${label} must be a valid Date.`);
43
52
  const milliseconds = Date.prototype.getTime.call(date);
@@ -45,10 +54,13 @@ function validMilliseconds(date, label) {
45
54
  return milliseconds;
46
55
  }
47
56
  function findLongitudeCrossings(body, targetLongitude, from, to, stepDays = 5) {
48
- return findLongitudeCrossingsWith(bodyLongitude, body, targetLongitude, from, to, stepDays);
57
+ return findLongitudeCrossingsWith(bodyLongitude, body, targetLongitude, windowEnd(from, "start"), windowEnd(to, "end"), stepDays);
49
58
  }
50
59
  function searchLongitudeCrossings(body, targetLongitude, from, to, options) {
51
- return searchLongitudeCrossingsWith(bodyLongitude, body, targetLongitude, from, to, options);
60
+ const { value, fallbacks } = notingFallbacks(
61
+ () => searchLongitudeCrossingsWith(bodyLongitude, body, targetLongitude, windowEnd(from, "start"), windowEnd(to, "end"), options)
62
+ );
63
+ return value.status === "complete" ? { ...value, flags: fallbacks } : value;
52
64
  }
53
65
  function groupIntoSeasons(crossings, gapDays = 400) {
54
66
  if (!Number.isFinite(gapDays) || gapDays <= 0) {
@@ -92,8 +104,8 @@ function computeSaturnReturns(birthUtc) {
92
104
 
93
105
  // src/synastry.ts
94
106
  function findInterAspects(first, second) {
95
- const aBodies = first.filter((body) => ASPECT_BODIES.has(body.body));
96
- const bBodies = second.filter((body) => ASPECT_BODIES.has(body.body));
107
+ const aBodies = first.filter((body) => ASPECT_BODY_SET.has(body.body));
108
+ const bBodies = second.filter((body) => ASPECT_BODY_SET.has(body.body));
97
109
  const aspects = [];
98
110
  for (const a of aBodies) {
99
111
  for (const b of bBodies) {
@@ -119,7 +131,7 @@ function elementBalance(bodies) {
119
131
  water: 0
120
132
  };
121
133
  for (const body of bodies) {
122
- if (!ASPECT_BODIES.has(body.body)) continue;
134
+ if (!ASPECT_BODY_SET.has(body.body)) continue;
123
135
  balance[signForLongitude(body.lon).element] += 1;
124
136
  }
125
137
  return balance;
@@ -131,7 +143,7 @@ function modalityBalance(bodies) {
131
143
  mutable: 0
132
144
  };
133
145
  for (const body of bodies) {
134
- if (!ASPECT_BODIES.has(body.body)) continue;
146
+ if (!ASPECT_BODY_SET.has(body.body)) continue;
135
147
  balance[signForLongitude(body.lon).modality] += 1;
136
148
  }
137
149
  return balance;
@@ -196,6 +208,11 @@ function resolvedChart(source) {
196
208
  expected.push("polar-fallback");
197
209
  }
198
210
  if (outsideReferenceSpan(input.utc)) expected.push("outside-reference-span");
211
+ if (resultFlags.values.length > expected.length && deltaTExtrapolated(timeBasis(+input.utc, input.timeScale, input.deltaT), hasHouses))
212
+ expected.push("delta-t-extrapolated");
213
+ if (source.ephemeris === void 0 || source.ephemeris?.name === "astronomy-engine") {
214
+ for (const reason of ["de440-unavailable", "outside-de440-span"]) if (resultFlags.values.includes(reason)) expected.push(reason);
215
+ }
199
216
  assertDerivedFlags(inputFlags?.values ?? [], expected);
200
217
  if (resultFlags.values.length !== expected.length || !expected.every((flag) => resultFlags.values.includes(flag))) {
201
218
  throw new RangeError("chart flags must agree with its input and supplied house result.");
@@ -243,7 +260,7 @@ function validateBirth(birth) {
243
260
  if (scale !== void 0 && !TIME_SCALE_NAMES.includes(scale)) {
244
261
  throw new RangeError('timeScale must be "utc", "ut1" or "tt".');
245
262
  }
246
- const possible = [];
263
+ const possible = ["delta-t-extrapolated", "de440-unavailable", "outside-de440-span"];
247
264
  if (settings.timeKnown === false) possible.push("no-time");
248
265
  else if (settings.houseSystem !== void 0 && isPolarUndefinedHouseSystem(settings.houseSystem) && settings.latitude !== void 0) {
249
266
  possible.push("polar-fallback");
@@ -308,12 +325,15 @@ function phaseName(angle) {
308
325
  function moonPhase(date) {
309
326
  const at = dateFrom(date, "date");
310
327
  const angle = normalizeLongitude(bodyLongitude("Moon", at) - bodyLongitude("Sun", at));
328
+ const { ephemeris, fallback } = ephemerisAt(at.getTime());
311
329
  return {
312
330
  at,
313
331
  angle,
314
332
  illumination: (1 - Math.cos(angle * Math.PI / 180)) / 2,
315
333
  name: phaseName(angle),
316
- waxing: angle < 180
334
+ waxing: angle < 180,
335
+ ephemeris: ephemeris.name,
336
+ ...fallback !== null && { fallback }
317
337
  };
318
338
  }
319
339
  function utcOf(input) {
@@ -331,7 +351,9 @@ function saturnReturn(birth) {
331
351
  validated.flags?.values.includes("polar-fallback") ? computedBirth(validated).input : validated.input
332
352
  );
333
353
  } else utc = dateFrom(birth, "birth");
334
- return computeSaturnReturns(utc);
354
+ const { value, fallbacks } = notingFallbacks(() => computeSaturnReturns(utc));
355
+ const ephemeris = fallbacks.length > 0 ? EPHEMERIS.name : ephemerisAt(utc.getTime()).ephemeris.name;
356
+ return { ...value, ephemeris, flags: fallbacks };
335
357
  }
336
358
 
337
359
  export {
@@ -0,0 +1,478 @@
1
+ import {
2
+ readOptions
3
+ } from "./chunk-47ERTK5X.js";
4
+ import {
5
+ onChartClock,
6
+ refuseUnderSource
7
+ } from "./chunk-QLIEEICB.js";
8
+ import {
9
+ dateFrom
10
+ } from "./chunk-CPALRSPC.js";
11
+ import {
12
+ eclipticFrame,
13
+ meanEcliptic
14
+ } from "./chunk-2PZYJQV5.js";
15
+ import {
16
+ REFERENCE_SPAN,
17
+ TIME_SCALE_NAMES,
18
+ outsideReferenceSpan,
19
+ timeBasis
20
+ } from "./chunk-B5LKF437.js";
21
+
22
+ // src/vedic/ayanamsa.ts
23
+ import { BaryState, Body, HelioVector } from "astronomy-engine";
24
+ var DEG = Math.PI / 180;
25
+ var ARCSEC = DEG / 3600;
26
+ var MAS = ARCSEC / 1e3;
27
+ var J2000 = 2451545;
28
+ var DAY_MS = 864e5;
29
+ var UNIX_JD = 24405875e-1;
30
+ var JULIAN_YEAR = 365.25;
31
+ var AU_KM = 1495978707e-1;
32
+ var C_AU_PER_DAY = 299792.458 * 86400 / AU_KM;
33
+ var SUN_SCHWARZSCHILD_AU = 197412574336e-19;
34
+ var SPAN_FROM_JD = UNIX_JD + Date.parse(REFERENCE_SPAN.from) / DAY_MS;
35
+ var SPAN_TO_JD = UNIX_JD + Date.parse(REFERENCE_SPAN.to) / DAY_MS;
36
+ var DEFINITIONS = /* @__PURE__ */ new WeakSet();
37
+ function registered(definition) {
38
+ const frozen = Object.freeze(definition);
39
+ DEFINITIONS.add(frozen);
40
+ return frozen;
41
+ }
42
+ var HIPPARCOS_EPOCH = 24483490625e-4;
43
+ var HIP2007 = "Hipparcos 2007 (I/311)";
44
+ function star(name, ra, dec, pmRa, pmDec, parallax, radialVelocity, epochTT = HIPPARCOS_EPOCH) {
45
+ return Object.freeze({ name, ra, dec, epochTT, pmRa, pmDec, parallax, radialVelocity });
46
+ }
47
+ var AYANAMSAS = Object.freeze({
48
+ lahiri: registered({
49
+ kind: "epoch",
50
+ name: "lahiri",
51
+ label: "Lahiri (Chitrapaksha)",
52
+ // True 23°15′00.658″ less the IAU 1980 nutation in longitude at that instant, +16.768927″.
53
+ epochTT: 24355535e-1,
54
+ value: 23 + 15 / 60 + (0.658 - 16.768927) / 3600,
55
+ model: "iau1976",
56
+ source: "Indian Astronomical Ephemeris: 23\xB015\u203200.658\u2033 true at 1956-03-21 0h TT (1989, p. 556)"
57
+ }),
58
+ "fagan-bradley": registered({
59
+ kind: "epoch",
60
+ name: "fagan-bradley",
61
+ label: "Fagan\u2013Bradley",
62
+ epochTT: 243328242345905e-8,
63
+ value: 24 + 2 / 60 + 31.36 / 3600,
64
+ model: "newcomb",
65
+ source: "Synetic vernal point 335\xB057\u203228.64\u2033 at B1950.0 (Astro*Index)"
66
+ }),
67
+ krishnamurti: registered({
68
+ kind: "epoch",
69
+ name: "krishnamurti",
70
+ label: "Krishnamurti (KP)",
71
+ epochTT: 24150205e-1,
72
+ value: 22.363889,
73
+ model: "newcomb",
74
+ source: "22\xB021\u203250\u2033 at 1900-01-01, fitted to KP Reader 1's table (Hand, Dawson)"
75
+ }),
76
+ raman: registered({
77
+ kind: "linear",
78
+ name: "raman",
79
+ label: "Raman",
80
+ epochTT: J2000 + (397 - 2e3) * JULIAN_YEAR,
81
+ value: 0,
82
+ rate: 50 + 1 / 3,
83
+ source: "B. V. Raman, A Manual of Hindu Astrology (1935) \xA749"
84
+ }),
85
+ yukteswar: registered({
86
+ kind: "linear",
87
+ name: "yukteswar",
88
+ label: "Sri Yukteswar",
89
+ epochTT: 24129081244e-4,
90
+ value: 20 + 54 / 60 + 36 / 3600,
91
+ rate: 54,
92
+ source: "Sri Yukteswar, The Holy Science (1894), Introduction"
93
+ }),
94
+ "true-chitra": registered({
95
+ kind: "star",
96
+ name: "true-chitra",
97
+ label: "True Chitra (Spica at 180\xB0)",
98
+ longitude: 180,
99
+ star: star("Spica (\u03B1 Vir, HIP 65474)", 201.29835228, -11.16124494, -42.35, -30.67, 13.06, -3.31),
100
+ source: `Surya Siddhanta VIII; ${HIP2007}`
101
+ }),
102
+ "true-revati": registered({
103
+ kind: "star",
104
+ name: "true-revati",
105
+ label: "True Revati (\u03B6 Psc at 359\xB050\u2032)",
106
+ longitude: 359 + 50 / 60,
107
+ star: star("Revati (\u03B6 Psc A, HIP 5737)", 18.43250842, 7.57548938, 145, -55.69, 18.76, 15),
108
+ source: `Surya Siddhanta VIII; ${HIP2007}`
109
+ }),
110
+ "true-pushya": registered({
111
+ kind: "star",
112
+ name: "true-pushya",
113
+ label: "True Pushya (\u03B4 Cnc at 106\xB0)",
114
+ longitude: 106,
115
+ star: star("Pushya (\u03B4 Cnc, HIP 42911)", 131.17129191, 18.15486373, -17.67, -229.26, 24.98, 17.14),
116
+ source: `P. V. R. Narasimha Rao (2013); ${HIP2007}`
117
+ }),
118
+ "galactic-center": registered({
119
+ kind: "star",
120
+ name: "galactic-center",
121
+ label: "Galactic Center at 0\xB0 Sagittarius",
122
+ longitude: 240,
123
+ star: star("Sgr A*", 266.416816625, -(29 + 28.1699 / 3600), -3.151, -5.547, 0, 0, J2000),
124
+ source: "Sgr A*: SIMBAD ICRS position; Reid & Brunthaler 2004"
125
+ })
126
+ });
127
+ function requireFinite(value, low, high, label) {
128
+ if (typeof value !== "number" || !Number.isFinite(value) || value < low || value > high) {
129
+ throw new RangeError(`${label} must be a finite number in [${low}, ${high}].`);
130
+ }
131
+ return value;
132
+ }
133
+ var EPOCH_JD_LIMIT = 1e8;
134
+ function isUserAyanamsaName(name) {
135
+ return typeof name === "string" && /^[a-z][a-z0-9-]{0,63}$/.test(name) && !Object.hasOwn(AYANAMSAS, name);
136
+ }
137
+ function userAyanamsa(input) {
138
+ if (!input || typeof input !== "object") throw new RangeError("userAyanamsa needs an input object.");
139
+ const read = readOptions(input, ["name", "epoch", "value", "rate", "model"], "userAyanamsa input");
140
+ const name = read.name ?? "user";
141
+ if (!isUserAyanamsaName(name)) {
142
+ throw new RangeError("Ayanamsa name must be a new lowercase identifier of at most 64 characters.");
143
+ }
144
+ const epoch = read.epoch;
145
+ let epochTT;
146
+ if (typeof epoch === "number") {
147
+ throw new RangeError("epoch must be { julianDateTT }, a Date or an ISO 8601 string: a bare number could be a Julian date or epoch milliseconds.");
148
+ } else if (epoch && typeof epoch === "object" && !(epoch instanceof Date)) {
149
+ const julian = readOptions(epoch, ["julianDateTT"], "epoch");
150
+ epochTT = requireFinite(julian.julianDateTT, UNIX_JD - EPOCH_JD_LIMIT, UNIX_JD + EPOCH_JD_LIMIT, "epoch.julianDateTT");
151
+ } else {
152
+ const at = dateFrom(epoch, "epoch");
153
+ epochTT = J2000 + timeBasis(at.getTime(), "utc").ttDays;
154
+ }
155
+ const value = requireFinite(read.value, -360, 360, "value");
156
+ const common = { name, label: `user: ${name}`, source: "caller-defined", epochTT, value };
157
+ if (read.rate !== void 0) {
158
+ if (read.model !== void 0) throw new RangeError("Give either a rate or a precession model, not both.");
159
+ return registered({ kind: "linear", ...common, rate: requireFinite(read.rate, -3600, 3600, "rate") });
160
+ }
161
+ const model = read.model ?? "engine";
162
+ if (model !== "engine" && model !== "newcomb" && model !== "iau1976") {
163
+ throw new RangeError("model must be engine, newcomb or iau1976.");
164
+ }
165
+ return registered({ kind: "epoch", ...common, model });
166
+ }
167
+ function definitionOf(definition) {
168
+ if (typeof definition === "string") {
169
+ if (!Object.hasOwn(AYANAMSAS, definition)) throw new RangeError(`Unknown ayanamsa: ${definition}.`);
170
+ return AYANAMSAS[definition];
171
+ }
172
+ if (!definition || typeof definition !== "object" || !DEFINITIONS.has(definition)) {
173
+ throw new RangeError("An ayanamsa must be a built-in name, an AYANAMSAS entry or a userAyanamsa result.");
174
+ }
175
+ return definition;
176
+ }
177
+ function longitudeIn(frame, x, y, z) {
178
+ const [ex, ey] = meanEcliptic(frame, x, y, z);
179
+ return Math.atan2(ey, ex);
180
+ }
181
+ function olderModelLongitude(model, jd) {
182
+ let zeta, z, theta, eps;
183
+ if (model === "newcomb") {
184
+ const B1850 = 239675820358095e-8;
185
+ const CENTURY = 36524.2198781;
186
+ const t = (J2000 - B1850) / CENTURY;
187
+ const h = (jd - J2000) / CENTURY;
188
+ const sum = (4607.1096 + t * (2.7944 + 118e-6 * t) + (1.3972 + 118e-6 * t + 0.03632 * h) * h) * h;
189
+ const diff = (0.79236 + 656e-6 * t + 328e-6 * h) * h * h;
190
+ zeta = (sum - diff) / 2;
191
+ z = (sum + diff) / 2;
192
+ theta = (2005.1125 - t * (0.85294 + 365e-6 * t) + (-0.42647 - 365e-6 * t - 0.041802 * h) * h) * h;
193
+ const e = (jd - B1850) / CENTURY;
194
+ eps = 84451.68 + e * (-46.837 + e * (-8752e-6 + 183e-5 * e));
195
+ } else {
196
+ const t = (jd - J2000) / 36525;
197
+ zeta = t * (2306.2181 + t * (0.30188 + 0.017998 * t));
198
+ z = t * (2306.2181 + t * (1.09468 + 0.018203 * t));
199
+ theta = t * (2004.3109 + t * (-0.42665 - 0.041833 * t));
200
+ eps = 84381.448 + t * (-46.815 + t * (-59e-5 + 1813e-6 * t));
201
+ }
202
+ [zeta, z, theta, eps] = [zeta * ARCSEC, z * ARCSEC, theta * ARCSEC, eps * ARCSEC];
203
+ const x = Math.cos(z) * Math.cos(zeta) * Math.cos(theta) - Math.sin(z) * Math.sin(zeta);
204
+ const y = Math.sin(z) * Math.cos(zeta) * Math.cos(theta) + Math.cos(z) * Math.sin(zeta);
205
+ const w = Math.cos(zeta) * Math.sin(theta);
206
+ return Math.atan2(Math.cos(eps) * y + Math.sin(eps) * w, x);
207
+ }
208
+ var FRAMES = /* @__PURE__ */ new WeakMap();
209
+ function epochFrame(definition) {
210
+ let epoch = FRAMES.get(definition);
211
+ if (epoch === void 0) {
212
+ const frame = eclipticFrame(definition.epochTT - J2000);
213
+ const correction = definition.model === "engine" ? 0 : longitudeIn(frame, 1, 0, 0) - olderModelLongitude(definition.model, definition.epochTT);
214
+ epoch = Object.freeze({ frame, correction });
215
+ FRAMES.set(definition, epoch);
216
+ }
217
+ return epoch;
218
+ }
219
+ var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
220
+ var scale = (a, k) => [a[0] * k, a[1] * k, a[2] * k];
221
+ var unit = (a) => scale(a, 1 / Math.sqrt(dot(a, a)));
222
+ function bias(v) {
223
+ const [xi, eta, alpha] = [-16.617 * MAS, -6.8192 * MAS, -14.6 * MAS];
224
+ const x1 = v[0] + alpha * v[1];
225
+ const y1 = v[1] - alpha * v[0];
226
+ const x2 = x1 - xi * v[2];
227
+ const z2 = v[2] + xi * x1;
228
+ return [x2, y1 - eta * z2, z2 + eta * y1];
229
+ }
230
+ function apparentStar(s, time) {
231
+ refuseUnderSource("A star-anchored ayanamsa");
232
+ const ra = s.ra * DEG;
233
+ const dec = s.dec * DEG;
234
+ const p0 = bias([Math.cos(dec) * Math.cos(ra), Math.cos(dec) * Math.sin(ra), Math.sin(dec)]);
235
+ const east = bias([-Math.sin(ra), Math.cos(ra), 0]);
236
+ const north = bias([-Math.sin(dec) * Math.cos(ra), -Math.sin(dec) * Math.sin(ra), Math.cos(dec)]);
237
+ const days = time.tt + J2000 - s.epochTT;
238
+ const pm = (k2) => k2 * MAS / JULIAN_YEAR;
239
+ const bary = BaryState(Body.Earth, time);
240
+ let q;
241
+ if (s.parallax > 0) {
242
+ const d = 1 / (s.parallax * MAS);
243
+ const rv = s.radialVelocity * 86400 / AU_KM;
244
+ q = [0, 1, 2].map((i) => d * p0[i] + days * (d * (pm(s.pmRa) * east[i] + pm(s.pmDec) * north[i]) + rv * p0[i]));
245
+ q = [q[0] - bary.x, q[1] - bary.y, q[2] - bary.z];
246
+ } else {
247
+ q = [0, 1, 2].map((i) => p0[i] + days * (pm(s.pmRa) * east[i] + pm(s.pmDec) * north[i]));
248
+ }
249
+ let p = unit(q);
250
+ const helio = HelioVector(Body.Earth, time);
251
+ const em = Math.hypot(helio.x, helio.y, helio.z);
252
+ const e = [helio.x / em, helio.y / em, helio.z / em];
253
+ const pe = dot(p, e);
254
+ const elongation = Math.acos(Math.min(1, Math.max(-1, -pe))) / DEG;
255
+ const w = SUN_SCHWARZSCHILD_AU / em / Math.max(1 + pe, 1e-6 / Math.max(em * em, 1));
256
+ p = unit([p[0] + w * (e[0] - pe * p[0]), p[1] + w * (e[1] - pe * p[1]), p[2] + w * (e[2] - pe * p[2])]);
257
+ const v = [bary.vx / C_AU_PER_DAY, bary.vy / C_AU_PER_DAY, bary.vz / C_AU_PER_DAY];
258
+ const root = Math.sqrt(1 - dot(v, v));
259
+ const k = 1 + dot(p, v) / (1 + root);
260
+ return { direction: unit([p[0] * root + k * v[0], p[1] * root + k * v[1], p[2] * root + k * v[2]]), elongation };
261
+ }
262
+ function meanAyanamsa(definition, time, frame) {
263
+ switch (definition.kind) {
264
+ case "epoch": {
265
+ const { frame: at, correction } = frame;
266
+ const [x, y, z] = eclipticFrame(time.tt).rows;
267
+ return { value: definition.value + (correction - longitudeIn(at, x, y, z)) / DEG, elongation: null };
268
+ }
269
+ case "linear": {
270
+ const perDay = definition.rate / JULIAN_YEAR / 3600;
271
+ const atJ2000 = definition.value - perDay * (definition.epochTT - J2000);
272
+ return { value: atJ2000 - 360 * Math.round(atJ2000 / 360) + perDay * time.tt, elongation: null };
273
+ }
274
+ case "star": {
275
+ const { direction: [x, y, z], elongation } = apparentStar(definition.star, time);
276
+ return { value: longitudeIn(eclipticFrame(time.tt), x, y, z) / DEG - definition.longitude, elongation };
277
+ }
278
+ }
279
+ }
280
+ function wrap(value) {
281
+ const r = value % 360;
282
+ return r > 180 ? r - 360 : r <= -180 ? r + 360 : r;
283
+ }
284
+ function ayanamsaAt(definition, time) {
285
+ const frame = definition.kind === "epoch" ? epochFrame(definition) : void 0;
286
+ const { value, elongation } = meanAyanamsa(definition, time, frame);
287
+ const mean = wrap(value);
288
+ const nutation = eclipticFrame(time.tt).tilt.dpsi / 3600;
289
+ return { mean, nutation, true: wrap(mean + nutation), elongation };
290
+ }
291
+ function outsideSpanEpoch(definition) {
292
+ return definition.kind === "epoch" && !(definition.epochTT >= SPAN_FROM_JD && definition.epochTT < SPAN_TO_JD);
293
+ }
294
+ var VALUES = /* @__PURE__ */ new WeakMap();
295
+ function isAyanamsaValue(value) {
296
+ return typeof value === "object" && value !== null && VALUES.has(value);
297
+ }
298
+ function utcInstantOf(value) {
299
+ const ms = VALUES.get(value);
300
+ if (ms === void 0) throw new RangeError("ayanamsa must be a value returned by ayanamsa().");
301
+ return new Date(Math.round(ms)).toISOString();
302
+ }
303
+ function ayanamsa(definition, at, options) {
304
+ const resolved = definitionOf(definition);
305
+ const date = dateFrom(at, "at");
306
+ const read = readOptions(options, ["deltaT", "timeScale"], "ayanamsa options");
307
+ const pin = read.deltaT;
308
+ if (pin !== void 0) requireFinite(pin, -1e10, 1e10, "deltaT");
309
+ const scale2 = read.timeScale;
310
+ if (scale2 !== void 0 && !TIME_SCALE_NAMES.includes(scale2)) {
311
+ throw new RangeError('timeScale must be "utc", "ut1" or "tt".');
312
+ }
313
+ if (resolved.kind === "epoch") epochFrame(resolved);
314
+ const outside = outsideReferenceSpan(date) || outsideSpanEpoch(resolved);
315
+ return onChartClock(date.getTime(), scale2 ?? "utc", pin, (time, basis) => {
316
+ const { mean, nutation, true: trueValue } = ayanamsaAt(resolved, time);
317
+ const { ut1MinusUtc, leapSeconds } = basis.timeScale;
318
+ const value = Object.freeze({
319
+ ayanamsa: resolved.name,
320
+ utc: date.toISOString(),
321
+ timeScale: Object.freeze({
322
+ ...basis.timeScale,
323
+ ut1MinusUtc: ut1MinusUtc && Object.freeze({ ...ut1MinusUtc }),
324
+ leapSeconds: leapSeconds && Object.freeze({ ...leapSeconds })
325
+ }),
326
+ julianDateTT: time.tt + J2000,
327
+ deltaT: Object.freeze({ ...basis.deltaT }),
328
+ mean,
329
+ nutation,
330
+ true: trueValue,
331
+ flags: Object.freeze(outside ? ["outside-reference-span"] : [])
332
+ });
333
+ VALUES.set(value, basis.utcMs);
334
+ return value;
335
+ });
336
+ }
337
+
338
+ // src/vedic/grid.ts
339
+ var TICKS_PER_DEGREE = 7560;
340
+ var SIGN_TICKS = 226800;
341
+ var NAKSHATRA_TICKS = 100800;
342
+ var PADA_TICKS = 25200;
343
+ var YEAR_TICKS = 840;
344
+ var SPLIT = 134217729;
345
+ function productError(a, b, p) {
346
+ let t = SPLIT * a;
347
+ const ah = t - (t - a);
348
+ const al = a - ah;
349
+ t = SPLIT * b;
350
+ const bh = t - (t - b);
351
+ const bl = b - bh;
352
+ return ah * bh - p + ah * bl + al * bh + al * bl;
353
+ }
354
+ function ticksOf(lon) {
355
+ const p = lon * TICKS_PER_DEGREE;
356
+ const f = Math.floor(p);
357
+ return f === p && productError(lon, TICKS_PER_DEGREE, p) < 0 ? f - 1 : f;
358
+ }
359
+
360
+ // src/vedic/sidereal.ts
361
+ var SIDEREAL = /* @__PURE__ */ new WeakSet();
362
+ function make(value) {
363
+ const frozen = Object.freeze(value);
364
+ SIDEREAL.add(frozen);
365
+ return frozen;
366
+ }
367
+ function requireSidereal(value) {
368
+ if (typeof value !== "object" || value === null || !SIDEREAL.has(value)) {
369
+ throw new RangeError("Expected a SiderealLongitude from siderealLongitude or declareSiderealLongitude.");
370
+ }
371
+ return value;
372
+ }
373
+ function wrap360(value) {
374
+ if (value >= 0 && value < 360) return value;
375
+ let r = value % 360;
376
+ if (r < 0) r += 360;
377
+ return r === 360 || r === 0 ? 0 : r;
378
+ }
379
+ function finiteLongitude(value, label) {
380
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new RangeError(`${label} must be a finite number.`);
381
+ return wrap360(value);
382
+ }
383
+ function siderealLongitude(tropicalLongitude, ayanamsa2) {
384
+ if (!isAyanamsaValue(ayanamsa2)) throw new RangeError("ayanamsa must be a value returned by ayanamsa().");
385
+ const tropical = finiteLongitude(tropicalLongitude, "tropicalLongitude");
386
+ return make({
387
+ frame: "sidereal",
388
+ lon: wrap360(tropical - ayanamsa2.true),
389
+ ayanamsa: ayanamsa2.ayanamsa,
390
+ trueAyanamsa: ayanamsa2.true,
391
+ tropical,
392
+ utc: utcInstantOf(ayanamsa2)
393
+ });
394
+ }
395
+ function declareSiderealLongitude(longitude, declaration) {
396
+ const read = readOptions(declaration, ["ayanamsa", "at"], "declaration");
397
+ const label = read.ayanamsa;
398
+ if (typeof label !== "string" || !label || label.length > 80 || label.trim() !== label || /[\u0000-\u001f\u007f]/.test(label)) {
399
+ throw new RangeError("declaration.ayanamsa must be a nonempty trimmed label of at most 80 characters.");
400
+ }
401
+ const at = read.at;
402
+ return make({
403
+ frame: "sidereal",
404
+ lon: finiteLongitude(longitude, "longitude"),
405
+ ayanamsa: label,
406
+ trueAyanamsa: null,
407
+ tropical: null,
408
+ utc: at === void 0 ? null : dateFrom(at, "declaration.at").toISOString()
409
+ });
410
+ }
411
+ function wholeSignCusps(ascendant) {
412
+ const first = Math.floor(ticksOf(ascendant) / SIGN_TICKS);
413
+ return Array.from({ length: 12 }, (_, k) => (first + k) % 12 * 30);
414
+ }
415
+ function siderealChartOf(chart, definition) {
416
+ const input = chart.input;
417
+ const value = ayanamsa(definition, input.utc, {
418
+ ...input.deltaT === void 0 ? {} : { deltaT: input.deltaT },
419
+ ...input.timeScale === void 0 ? {} : { timeScale: input.timeScale }
420
+ });
421
+ const of = (lon) => siderealLongitude(lon, value);
422
+ const bodies = chart.bodies.map((row) => {
423
+ const sidereal = of(row.lon);
424
+ SIDEREAL.delete(sidereal);
425
+ return make({ ...sidereal, body: row.body });
426
+ });
427
+ const ascendant = chart.angles ? of(chart.angles.asc) : null;
428
+ const houseSystem = chart.houses ? chart.houses.system : null;
429
+ let cusps = null;
430
+ if (chart.houses && houseSystem === "whole" && ascendant) {
431
+ cusps = wholeSignCusps(ascendant.lon).map(
432
+ (lon) => make({
433
+ frame: "sidereal",
434
+ lon,
435
+ ayanamsa: value.ayanamsa,
436
+ trueAyanamsa: value.true,
437
+ tropical: wrap360(lon + value.true),
438
+ utc: utcInstantOf(value)
439
+ })
440
+ );
441
+ } else if (chart.houses) {
442
+ cusps = chart.houses.cusps.map(of);
443
+ }
444
+ const flags = [...chart.flags];
445
+ for (const flag of value.flags) if (!flags.includes(flag)) flags.push(flag);
446
+ return Object.freeze({
447
+ ayanamsa: value.ayanamsa,
448
+ ayanamsaValue: value,
449
+ bodies: Object.freeze(bodies),
450
+ ascendant,
451
+ midheaven: chart.angles ? of(chart.angles.mc) : null,
452
+ houseSystem,
453
+ cusps: cusps && Object.freeze(cusps),
454
+ flags: Object.freeze(flags)
455
+ });
456
+ }
457
+
458
+ export {
459
+ AYANAMSAS,
460
+ isUserAyanamsaName,
461
+ userAyanamsa,
462
+ definitionOf,
463
+ ayanamsaAt,
464
+ outsideSpanEpoch,
465
+ ayanamsa,
466
+ TICKS_PER_DEGREE,
467
+ SIGN_TICKS,
468
+ NAKSHATRA_TICKS,
469
+ PADA_TICKS,
470
+ YEAR_TICKS,
471
+ ticksOf,
472
+ requireSidereal,
473
+ wrap360,
474
+ siderealLongitude,
475
+ declareSiderealLongitude,
476
+ wholeSignCusps,
477
+ siderealChartOf
478
+ };