panchang-ts 0.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,3465 @@
1
+ 'use strict';
2
+
3
+ // src/types/errors.ts
4
+ var PanchangError = class _PanchangError extends Error {
5
+ constructor(message, code) {
6
+ super(message);
7
+ this.name = "PanchangError";
8
+ this.code = code;
9
+ Object.setPrototypeOf(this, _PanchangError.prototype);
10
+ }
11
+ };
12
+
13
+ // src/utils/validation.ts
14
+ function validateLocation(location) {
15
+ if (typeof location.latitude !== "number" || location.latitude < -90 || location.latitude > 90) {
16
+ throw new PanchangError(
17
+ `Latitude must be a number between -90 and 90, got ${location.latitude}`,
18
+ "INVALID_LATITUDE"
19
+ );
20
+ }
21
+ if (typeof location.longitude !== "number" || location.longitude < -180 || location.longitude > 180) {
22
+ throw new PanchangError(
23
+ `Longitude must be a number between -180 and 180, got ${location.longitude}`,
24
+ "INVALID_LONGITUDE"
25
+ );
26
+ }
27
+ if (location.elevation !== void 0 && (typeof location.elevation !== "number" || location.elevation < -500)) {
28
+ throw new PanchangError(
29
+ `Elevation must be >= -500 meters, got ${location.elevation}`,
30
+ "INVALID_ELEVATION"
31
+ );
32
+ }
33
+ }
34
+ function validateDate(date) {
35
+ if (!(date instanceof Date) || isNaN(date.getTime())) {
36
+ throw new PanchangError(`Invalid Date: ${String(date)}`, "INVALID_DATE");
37
+ }
38
+ const year = date.getFullYear();
39
+ if (year < 1900 || year > 2100) {
40
+ throw new PanchangError(
41
+ `Date must be between 1900 and 2100 for astronomical accuracy, got year ${year}`,
42
+ "INVALID_DATE"
43
+ );
44
+ }
45
+ }
46
+
47
+ // node_modules/astronomy-engine/esm/astronomy.js
48
+ var C_AUDAY = 173.1446326846693;
49
+ var KM_PER_AU = 14959787069098932e-8;
50
+ var DEG2RAD = 0.017453292519943295;
51
+ var HOUR2RAD = 0.26179938779914946;
52
+ var RAD2DEG = 57.29577951308232;
53
+ var RAD2HOUR = 3.819718634205488;
54
+ var DAYS_PER_TROPICAL_YEAR = 365.24217;
55
+ var J2000 = /* @__PURE__ */ new Date("2000-01-01T12:00:00Z");
56
+ var PI2 = 2 * Math.PI;
57
+ var ARC = 3600 * (180 / Math.PI);
58
+ var ASEC2RAD = 484813681109536e-20;
59
+ var ASEC180 = 180 * 60 * 60;
60
+ var ASEC360 = 2 * ASEC180;
61
+ var ANGVEL = 7292115e-11;
62
+ var SECONDS_PER_DAY = 24 * 3600;
63
+ var SOLAR_DAYS_PER_SIDEREAL_DAY = 0.9972695717592592;
64
+ var SUN_RADIUS_KM = 695700;
65
+ var SUN_RADIUS_AU = SUN_RADIUS_KM / KM_PER_AU;
66
+ var EARTH_FLATTENING = 0.996647180302104;
67
+ var EARTH_FLATTENING_SQUARED = EARTH_FLATTENING * EARTH_FLATTENING;
68
+ var EARTH_EQUATORIAL_RADIUS_KM = 6378.1366;
69
+ var EARTH_EQUATORIAL_RADIUS_AU = EARTH_EQUATORIAL_RADIUS_KM / KM_PER_AU;
70
+ var MOON_EQUATORIAL_RADIUS_KM = 1738.1;
71
+ var MOON_EQUATORIAL_RADIUS_AU = MOON_EQUATORIAL_RADIUS_KM / KM_PER_AU;
72
+ var REFRACTION_NEAR_HORIZON = 34 / 60;
73
+ var EARTH_MOON_MASS_RATIO = 81.30056;
74
+ var SUN_GM = 2959122082855911e-19;
75
+ var JUPITER_GM = 2825345909524226e-22;
76
+ var SATURN_GM = 8459715185680659e-23;
77
+ var URANUS_GM = 1292024916781969e-23;
78
+ var NEPTUNE_GM = 1524358900784276e-23;
79
+ function VerifyNumber(x) {
80
+ if (!Number.isFinite(x)) {
81
+ console.trace();
82
+ throw `Value is not a finite number: ${x}`;
83
+ }
84
+ return x;
85
+ }
86
+ function Frac(x) {
87
+ return x - Math.floor(x);
88
+ }
89
+ var Body;
90
+ (function(Body2) {
91
+ Body2["Sun"] = "Sun";
92
+ Body2["Moon"] = "Moon";
93
+ Body2["Mercury"] = "Mercury";
94
+ Body2["Venus"] = "Venus";
95
+ Body2["Earth"] = "Earth";
96
+ Body2["Mars"] = "Mars";
97
+ Body2["Jupiter"] = "Jupiter";
98
+ Body2["Saturn"] = "Saturn";
99
+ Body2["Uranus"] = "Uranus";
100
+ Body2["Neptune"] = "Neptune";
101
+ Body2["Pluto"] = "Pluto";
102
+ Body2["SSB"] = "SSB";
103
+ Body2["EMB"] = "EMB";
104
+ Body2["Star1"] = "Star1";
105
+ Body2["Star2"] = "Star2";
106
+ Body2["Star3"] = "Star3";
107
+ Body2["Star4"] = "Star4";
108
+ Body2["Star5"] = "Star5";
109
+ Body2["Star6"] = "Star6";
110
+ Body2["Star7"] = "Star7";
111
+ Body2["Star8"] = "Star8";
112
+ })(Body || (Body = {}));
113
+ var StarList = [
114
+ Body.Star1,
115
+ Body.Star2,
116
+ Body.Star3,
117
+ Body.Star4,
118
+ Body.Star5,
119
+ Body.Star6,
120
+ Body.Star7,
121
+ Body.Star8
122
+ ];
123
+ var StarTable = [
124
+ { ra: 0, dec: 0, dist: 0 },
125
+ { ra: 0, dec: 0, dist: 0 },
126
+ { ra: 0, dec: 0, dist: 0 },
127
+ { ra: 0, dec: 0, dist: 0 },
128
+ { ra: 0, dec: 0, dist: 0 },
129
+ { ra: 0, dec: 0, dist: 0 },
130
+ { ra: 0, dec: 0, dist: 0 },
131
+ { ra: 0, dec: 0, dist: 0 }
132
+ ];
133
+ function GetStar(body) {
134
+ const index = StarList.indexOf(body);
135
+ return index >= 0 ? StarTable[index] : null;
136
+ }
137
+ function UserDefinedStar(body) {
138
+ const star = GetStar(body);
139
+ return star && star.dist > 0 ? star : null;
140
+ }
141
+ var PrecessDirection;
142
+ (function(PrecessDirection2) {
143
+ PrecessDirection2[PrecessDirection2["From2000"] = 0] = "From2000";
144
+ PrecessDirection2[PrecessDirection2["Into2000"] = 1] = "Into2000";
145
+ })(PrecessDirection || (PrecessDirection = {}));
146
+ var vsop = {
147
+ Mercury: [
148
+ [
149
+ [
150
+ [4.40250710144, 0, 0],
151
+ [0.40989414977, 1.48302034195, 26087.9031415742],
152
+ [0.050462942, 4.47785489551, 52175.8062831484],
153
+ [0.00855346844, 1.16520322459, 78263.70942472259],
154
+ [0.00165590362, 4.11969163423, 104351.61256629678],
155
+ [34561897e-11, 0.77930768443, 130439.51570787099],
156
+ [7583476e-11, 3.71348404924, 156527.41884944518]
157
+ ],
158
+ [
159
+ [26087.90313685529, 0, 0],
160
+ [0.01131199811, 6.21874197797, 26087.9031415742],
161
+ [0.00292242298, 3.04449355541, 52175.8062831484],
162
+ [75775081e-11, 6.08568821653, 78263.70942472259],
163
+ [19676525e-11, 2.80965111777, 104351.61256629678]
164
+ ]
165
+ ],
166
+ [
167
+ [
168
+ [0.11737528961, 1.98357498767, 26087.9031415742],
169
+ [0.02388076996, 5.03738959686, 52175.8062831484],
170
+ [0.01222839532, 3.14159265359, 0],
171
+ [0.0054325181, 1.79644363964, 78263.70942472259],
172
+ [0.0012977877, 4.83232503958, 104351.61256629678],
173
+ [31866927e-11, 1.58088495658, 130439.51570787099],
174
+ [7963301e-11, 4.60972126127, 156527.41884944518]
175
+ ],
176
+ [
177
+ [0.00274646065, 3.95008450011, 26087.9031415742],
178
+ [99737713e-11, 3.14159265359, 0]
179
+ ]
180
+ ],
181
+ [
182
+ [
183
+ [0.39528271651, 0, 0],
184
+ [0.07834131818, 6.19233722598, 26087.9031415742],
185
+ [0.00795525558, 2.95989690104, 52175.8062831484],
186
+ [0.00121281764, 6.01064153797, 78263.70942472259],
187
+ [21921969e-11, 2.77820093972, 104351.61256629678],
188
+ [4354065e-11, 5.82894543774, 130439.51570787099]
189
+ ],
190
+ [
191
+ [0.0021734774, 4.65617158665, 26087.9031415742],
192
+ [44141826e-11, 1.42385544001, 52175.8062831484]
193
+ ]
194
+ ]
195
+ ],
196
+ Venus: [
197
+ [
198
+ [
199
+ [3.17614666774, 0, 0],
200
+ [0.01353968419, 5.59313319619, 10213.285546211],
201
+ [89891645e-11, 5.30650047764, 20426.571092422],
202
+ [5477194e-11, 4.41630661466, 7860.4193924392],
203
+ [3455741e-11, 2.6996444782, 11790.6290886588],
204
+ [2372061e-11, 2.99377542079, 3930.2096962196],
205
+ [1317168e-11, 5.18668228402, 26.2983197998],
206
+ [1664146e-11, 4.25018630147, 1577.3435424478],
207
+ [1438387e-11, 4.15745084182, 9683.5945811164],
208
+ [1200521e-11, 6.15357116043, 30639.856638633]
209
+ ],
210
+ [
211
+ [10213.28554621638, 0, 0],
212
+ [95617813e-11, 2.4640651111, 10213.285546211],
213
+ [7787201e-11, 0.6247848222, 20426.571092422]
214
+ ]
215
+ ],
216
+ [
217
+ [
218
+ [0.05923638472, 0.26702775812, 10213.285546211],
219
+ [40107978e-11, 1.14737178112, 20426.571092422],
220
+ [32814918e-11, 3.14159265359, 0]
221
+ ],
222
+ [
223
+ [0.00287821243, 1.88964962838, 10213.285546211]
224
+ ]
225
+ ],
226
+ [
227
+ [
228
+ [0.72334820891, 0, 0],
229
+ [0.00489824182, 4.02151831717, 10213.285546211],
230
+ [1658058e-11, 4.90206728031, 20426.571092422],
231
+ [1378043e-11, 1.12846591367, 11790.6290886588],
232
+ [1632096e-11, 2.84548795207, 7860.4193924392],
233
+ [498395e-11, 2.58682193892, 9683.5945811164],
234
+ [221985e-11, 2.01346696541, 19367.1891622328],
235
+ [237454e-11, 2.55136053886, 15720.8387848784]
236
+ ],
237
+ [
238
+ [34551041e-11, 0.89198706276, 10213.285546211]
239
+ ]
240
+ ]
241
+ ],
242
+ Earth: [
243
+ [
244
+ [
245
+ [1.75347045673, 0, 0],
246
+ [0.03341656453, 4.66925680415, 6283.0758499914],
247
+ [34894275e-11, 4.62610242189, 12566.1516999828],
248
+ [3417572e-11, 2.82886579754, 3.523118349],
249
+ [3497056e-11, 2.74411783405, 5753.3848848968],
250
+ [3135899e-11, 3.62767041756, 77713.7714681205],
251
+ [2676218e-11, 4.41808345438, 7860.4193924392],
252
+ [2342691e-11, 6.13516214446, 3930.2096962196],
253
+ [1273165e-11, 2.03709657878, 529.6909650946],
254
+ [1324294e-11, 0.74246341673, 11506.7697697936],
255
+ [901854e-11, 2.04505446477, 26.2983197998],
256
+ [1199167e-11, 1.10962946234, 1577.3435424478],
257
+ [857223e-11, 3.50849152283, 398.1490034082],
258
+ [779786e-11, 1.17882681962, 5223.6939198022],
259
+ [99025e-10, 5.23268072088, 5884.9268465832],
260
+ [753141e-11, 2.53339052847, 5507.5532386674],
261
+ [505267e-11, 4.58292599973, 18849.2275499742],
262
+ [492392e-11, 4.20505711826, 775.522611324],
263
+ [356672e-11, 2.91954114478, 0.0673103028],
264
+ [284125e-11, 1.89869240932, 796.2980068164],
265
+ [242879e-11, 0.34481445893, 5486.777843175],
266
+ [317087e-11, 5.84901948512, 11790.6290886588],
267
+ [271112e-11, 0.31486255375, 10977.078804699],
268
+ [206217e-11, 4.80646631478, 2544.3144198834],
269
+ [205478e-11, 1.86953770281, 5573.1428014331],
270
+ [202318e-11, 2.45767790232, 6069.7767545534],
271
+ [126225e-11, 1.08295459501, 20.7753954924],
272
+ [155516e-11, 0.83306084617, 213.299095438]
273
+ ],
274
+ [
275
+ [6283.0758499914, 0, 0],
276
+ [0.00206058863, 2.67823455808, 6283.0758499914],
277
+ [4303419e-11, 2.63512233481, 12566.1516999828]
278
+ ],
279
+ [
280
+ [8721859e-11, 1.07253635559, 6283.0758499914]
281
+ ]
282
+ ],
283
+ [
284
+ [],
285
+ [
286
+ [0.00227777722, 3.4137662053, 6283.0758499914],
287
+ [3805678e-11, 3.37063423795, 12566.1516999828]
288
+ ]
289
+ ],
290
+ [
291
+ [
292
+ [1.00013988784, 0, 0],
293
+ [0.01670699632, 3.09846350258, 6283.0758499914],
294
+ [13956024e-11, 3.05524609456, 12566.1516999828],
295
+ [308372e-10, 5.19846674381, 77713.7714681205],
296
+ [1628463e-11, 1.17387558054, 5753.3848848968],
297
+ [1575572e-11, 2.84685214877, 7860.4193924392],
298
+ [924799e-11, 5.45292236722, 11506.7697697936],
299
+ [542439e-11, 4.56409151453, 3930.2096962196],
300
+ [47211e-10, 3.66100022149, 5884.9268465832],
301
+ [85831e-11, 1.27079125277, 161000.6857376741],
302
+ [57056e-11, 2.01374292245, 83996.84731811189],
303
+ [55736e-11, 5.2415979917, 71430.69561812909],
304
+ [174844e-11, 3.01193636733, 18849.2275499742],
305
+ [243181e-11, 4.2734953079, 11790.6290886588]
306
+ ],
307
+ [
308
+ [0.00103018607, 1.10748968172, 6283.0758499914],
309
+ [1721238e-11, 1.06442300386, 12566.1516999828]
310
+ ],
311
+ [
312
+ [4359385e-11, 5.78455133808, 6283.0758499914]
313
+ ]
314
+ ]
315
+ ],
316
+ Mars: [
317
+ [
318
+ [
319
+ [6.20347711581, 0, 0],
320
+ [0.18656368093, 5.0503710027, 3340.6124266998],
321
+ [0.01108216816, 5.40099836344, 6681.2248533996],
322
+ [91798406e-11, 5.75478744667, 10021.8372800994],
323
+ [27744987e-11, 5.97049513147, 3.523118349],
324
+ [10610235e-11, 2.93958560338, 2281.2304965106],
325
+ [12315897e-11, 0.84956094002, 2810.9214616052],
326
+ [8926784e-11, 4.15697846427, 0.0172536522],
327
+ [8715691e-11, 6.11005153139, 13362.4497067992],
328
+ [6797556e-11, 0.36462229657, 398.1490034082],
329
+ [7774872e-11, 3.33968761376, 5621.8429232104],
330
+ [3575078e-11, 1.6618650571, 2544.3144198834],
331
+ [4161108e-11, 0.22814971327, 2942.4634232916],
332
+ [3075252e-11, 0.85696614132, 191.4482661116],
333
+ [2628117e-11, 0.64806124465, 3337.0893083508],
334
+ [2937546e-11, 6.07893711402, 0.0673103028],
335
+ [2389414e-11, 5.03896442664, 796.2980068164],
336
+ [2579844e-11, 0.02996736156, 3344.1355450488],
337
+ [1528141e-11, 1.14979301996, 6151.533888305],
338
+ [1798806e-11, 0.65634057445, 529.6909650946],
339
+ [1264357e-11, 3.62275122593, 5092.1519581158],
340
+ [1286228e-11, 3.06796065034, 2146.1654164752],
341
+ [1546404e-11, 2.91579701718, 1751.539531416],
342
+ [1024902e-11, 3.69334099279, 8962.4553499102],
343
+ [891566e-11, 0.18293837498, 16703.062133499],
344
+ [858759e-11, 2.4009381194, 2914.0142358238],
345
+ [832715e-11, 2.46418619474, 3340.5951730476],
346
+ [83272e-10, 4.49495782139, 3340.629680352],
347
+ [712902e-11, 3.66335473479, 1059.3819301892],
348
+ [748723e-11, 3.82248614017, 155.4203994342],
349
+ [723861e-11, 0.67497311481, 3738.761430108],
350
+ [635548e-11, 2.92182225127, 8432.7643848156],
351
+ [655162e-11, 0.48864064125, 3127.3133312618],
352
+ [550474e-11, 3.81001042328, 0.9803210682],
353
+ [55275e-10, 4.47479317037, 1748.016413067],
354
+ [425966e-11, 0.55364317304, 6283.0758499914],
355
+ [415131e-11, 0.49662285038, 213.299095438],
356
+ [472167e-11, 3.62547124025, 1194.4470102246],
357
+ [306551e-11, 0.38052848348, 6684.7479717486],
358
+ [312141e-11, 0.99853944405, 6677.7017350506],
359
+ [293198e-11, 4.22131299634, 20.7753954924],
360
+ [302375e-11, 4.48618007156, 3532.0606928114],
361
+ [274027e-11, 0.54222167059, 3340.545116397],
362
+ [281079e-11, 5.88163521788, 1349.8674096588],
363
+ [231183e-11, 1.28242156993, 3870.3033917944],
364
+ [283602e-11, 5.7688543494, 3149.1641605882],
365
+ [236117e-11, 5.75503217933, 3333.498879699],
366
+ [274033e-11, 0.13372524985, 3340.6797370026],
367
+ [299395e-11, 2.78323740866, 6254.6266625236]
368
+ ],
369
+ [
370
+ [3340.61242700512, 0, 0],
371
+ [0.01457554523, 3.60433733236, 3340.6124266998],
372
+ [0.00168414711, 3.92318567804, 6681.2248533996],
373
+ [20622975e-11, 4.26108844583, 10021.8372800994],
374
+ [3452392e-11, 4.7321039319, 3.523118349],
375
+ [2586332e-11, 4.60670058555, 13362.4497067992],
376
+ [841535e-11, 4.45864030426, 2281.2304965106]
377
+ ],
378
+ [
379
+ [58152577e-11, 2.04961712429, 3340.6124266998],
380
+ [13459579e-11, 2.45738706163, 6681.2248533996]
381
+ ]
382
+ ],
383
+ [
384
+ [
385
+ [0.03197134986, 3.76832042431, 3340.6124266998],
386
+ [0.00298033234, 4.10616996305, 6681.2248533996],
387
+ [0.00289104742, 0, 0],
388
+ [31365539e-11, 4.4465105309, 10021.8372800994],
389
+ [34841e-9, 4.7881254926, 13362.4497067992]
390
+ ],
391
+ [
392
+ [0.00217310991, 6.04472194776, 3340.6124266998],
393
+ [20976948e-11, 3.14159265359, 0],
394
+ [12834709e-11, 1.60810667915, 6681.2248533996]
395
+ ]
396
+ ],
397
+ [
398
+ [
399
+ [1.53033488271, 0, 0],
400
+ [0.1418495316, 3.47971283528, 3340.6124266998],
401
+ [0.00660776362, 3.81783443019, 6681.2248533996],
402
+ [46179117e-11, 4.15595316782, 10021.8372800994],
403
+ [8109733e-11, 5.55958416318, 2810.9214616052],
404
+ [7485318e-11, 1.77239078402, 5621.8429232104],
405
+ [5523191e-11, 1.3643630377, 2281.2304965106],
406
+ [382516e-10, 4.49407183687, 13362.4497067992],
407
+ [2306537e-11, 0.09081579001, 2544.3144198834],
408
+ [1999396e-11, 5.36059617709, 3337.0893083508],
409
+ [2484394e-11, 4.9254563992, 2942.4634232916],
410
+ [1960195e-11, 4.74249437639, 3344.1355450488],
411
+ [1167119e-11, 2.11260868341, 5092.1519581158],
412
+ [1102816e-11, 5.00908403998, 398.1490034082],
413
+ [899066e-11, 4.40791133207, 529.6909650946],
414
+ [992252e-11, 5.83861961952, 6151.533888305],
415
+ [807354e-11, 2.10217065501, 1059.3819301892],
416
+ [797915e-11, 3.44839203899, 796.2980068164],
417
+ [740975e-11, 1.49906336885, 2146.1654164752]
418
+ ],
419
+ [
420
+ [0.01107433345, 2.03250524857, 3340.6124266998],
421
+ [0.00103175887, 2.37071847807, 6681.2248533996],
422
+ [128772e-9, 0, 0],
423
+ [1081588e-10, 2.70888095665, 10021.8372800994]
424
+ ],
425
+ [
426
+ [44242249e-11, 0.47930604954, 3340.6124266998],
427
+ [8138042e-11, 0.86998389204, 6681.2248533996]
428
+ ]
429
+ ]
430
+ ],
431
+ Jupiter: [
432
+ [
433
+ [
434
+ [0.59954691494, 0, 0],
435
+ [0.09695898719, 5.06191793158, 529.6909650946],
436
+ [0.00573610142, 1.44406205629, 7.1135470008],
437
+ [0.00306389205, 5.41734730184, 1059.3819301892],
438
+ [97178296e-11, 4.14264726552, 632.7837393132],
439
+ [72903078e-11, 3.64042916389, 522.5774180938],
440
+ [64263975e-11, 3.41145165351, 103.0927742186],
441
+ [39806064e-11, 2.29376740788, 419.4846438752],
442
+ [38857767e-11, 1.27231755835, 316.3918696566],
443
+ [27964629e-11, 1.7845459182, 536.8045120954],
444
+ [1358973e-10, 5.7748104079, 1589.0728952838],
445
+ [8246349e-11, 3.5822792584, 206.1855484372],
446
+ [8768704e-11, 3.63000308199, 949.1756089698],
447
+ [7368042e-11, 5.0810119427, 735.8765135318],
448
+ [626315e-10, 0.02497628807, 213.299095438],
449
+ [6114062e-11, 4.51319998626, 1162.4747044078],
450
+ [4905396e-11, 1.32084470588, 110.2063212194],
451
+ [5305285e-11, 1.30671216791, 14.2270940016],
452
+ [5305441e-11, 4.18625634012, 1052.2683831884],
453
+ [4647248e-11, 4.69958103684, 3.9321532631],
454
+ [3045023e-11, 4.31676431084, 426.598190876],
455
+ [2609999e-11, 1.56667394063, 846.0828347512],
456
+ [2028191e-11, 1.06376530715, 3.1813937377],
457
+ [1764763e-11, 2.14148655117, 1066.49547719],
458
+ [1722972e-11, 3.88036268267, 1265.5674786264],
459
+ [1920945e-11, 0.97168196472, 639.897286314],
460
+ [1633223e-11, 3.58201833555, 515.463871093],
461
+ [1431999e-11, 4.29685556046, 625.6701923124],
462
+ [973272e-11, 4.09764549134, 95.9792272178]
463
+ ],
464
+ [
465
+ [529.69096508814, 0, 0],
466
+ [0.00489503243, 4.2208293947, 529.6909650946],
467
+ [0.00228917222, 6.02646855621, 7.1135470008],
468
+ [30099479e-11, 4.54540782858, 1059.3819301892],
469
+ [2072092e-10, 5.45943156902, 522.5774180938],
470
+ [12103653e-11, 0.16994816098, 536.8045120954],
471
+ [6067987e-11, 4.42422292017, 103.0927742186],
472
+ [5433968e-11, 3.98480737746, 419.4846438752],
473
+ [4237744e-11, 5.89008707199, 14.2270940016]
474
+ ],
475
+ [
476
+ [47233601e-11, 4.32148536482, 7.1135470008],
477
+ [30649436e-11, 2.929777887, 529.6909650946],
478
+ [14837605e-11, 3.14159265359, 0]
479
+ ]
480
+ ],
481
+ [
482
+ [
483
+ [0.02268615702, 3.55852606721, 529.6909650946],
484
+ [0.00109971634, 3.90809347197, 1059.3819301892],
485
+ [0.00110090358, 0, 0],
486
+ [8101428e-11, 3.60509572885, 522.5774180938],
487
+ [6043996e-11, 4.25883108339, 1589.0728952838],
488
+ [6437782e-11, 0.30627119215, 536.8045120954]
489
+ ],
490
+ [
491
+ [78203446e-11, 1.52377859742, 529.6909650946]
492
+ ]
493
+ ],
494
+ [
495
+ [
496
+ [5.20887429326, 0, 0],
497
+ [0.25209327119, 3.49108639871, 529.6909650946],
498
+ [0.00610599976, 3.84115365948, 1059.3819301892],
499
+ [0.00282029458, 2.57419881293, 632.7837393132],
500
+ [0.00187647346, 2.07590383214, 522.5774180938],
501
+ [86792905e-11, 0.71001145545, 419.4846438752],
502
+ [72062974e-11, 0.21465724607, 536.8045120954],
503
+ [65517248e-11, 5.9799588479, 316.3918696566],
504
+ [29134542e-11, 1.67759379655, 103.0927742186],
505
+ [30135335e-11, 2.16132003734, 949.1756089698],
506
+ [23453271e-11, 3.54023522184, 735.8765135318],
507
+ [22283743e-11, 4.19362594399, 1589.0728952838],
508
+ [23947298e-11, 0.2745803748, 7.1135470008],
509
+ [13032614e-11, 2.96042965363, 1162.4747044078],
510
+ [970336e-10, 1.90669633585, 206.1855484372],
511
+ [12749023e-11, 2.71550286592, 1052.2683831884],
512
+ [7057931e-11, 2.18184839926, 1265.5674786264],
513
+ [6137703e-11, 6.26418240033, 846.0828347512],
514
+ [2616976e-11, 2.00994012876, 1581.959348283]
515
+ ],
516
+ [
517
+ [0.0127180152, 2.64937512894, 529.6909650946],
518
+ [61661816e-11, 3.00076460387, 1059.3819301892],
519
+ [53443713e-11, 3.89717383175, 522.5774180938],
520
+ [31185171e-11, 4.88276958012, 536.8045120954],
521
+ [41390269e-11, 0, 0]
522
+ ]
523
+ ]
524
+ ],
525
+ Saturn: [
526
+ [
527
+ [
528
+ [0.87401354025, 0, 0],
529
+ [0.11107659762, 3.96205090159, 213.299095438],
530
+ [0.01414150957, 4.58581516874, 7.1135470008],
531
+ [0.00398379389, 0.52112032699, 206.1855484372],
532
+ [0.00350769243, 3.30329907896, 426.598190876],
533
+ [0.00206816305, 0.24658372002, 103.0927742186],
534
+ [792713e-9, 3.84007056878, 220.4126424388],
535
+ [23990355e-11, 4.66976924553, 110.2063212194],
536
+ [16573588e-11, 0.43719228296, 419.4846438752],
537
+ [14906995e-11, 5.76903183869, 316.3918696566],
538
+ [1582029e-10, 0.93809155235, 632.7837393132],
539
+ [14609559e-11, 1.56518472, 3.9321532631],
540
+ [13160301e-11, 4.44891291899, 14.2270940016],
541
+ [15053543e-11, 2.71669915667, 639.897286314],
542
+ [13005299e-11, 5.98119023644, 11.0457002639],
543
+ [10725067e-11, 3.12939523827, 202.2533951741],
544
+ [5863206e-11, 0.23656938524, 529.6909650946],
545
+ [5227757e-11, 4.20783365759, 3.1813937377],
546
+ [6126317e-11, 1.76328667907, 277.0349937414],
547
+ [5019687e-11, 3.17787728405, 433.7117378768],
548
+ [459255e-10, 0.61977744975, 199.0720014364],
549
+ [4005867e-11, 2.24479718502, 63.7358983034],
550
+ [2953796e-11, 0.98280366998, 95.9792272178],
551
+ [387367e-10, 3.22283226966, 138.5174968707],
552
+ [2461186e-11, 2.03163875071, 735.8765135318],
553
+ [3269484e-11, 0.77492638211, 949.1756089698],
554
+ [1758145e-11, 3.2658010994, 522.5774180938],
555
+ [1640172e-11, 5.5050445305, 846.0828347512],
556
+ [1391327e-11, 4.02333150505, 323.5054166574],
557
+ [1580648e-11, 4.37265307169, 309.2783226558],
558
+ [1123498e-11, 2.83726798446, 415.5524906121],
559
+ [1017275e-11, 3.71700135395, 227.5261894396],
560
+ [848642e-11, 3.1915017083, 209.3669421749]
561
+ ],
562
+ [
563
+ [213.2990952169, 0, 0],
564
+ [0.01297370862, 1.82834923978, 213.299095438],
565
+ [0.00564345393, 2.88499717272, 7.1135470008],
566
+ [93734369e-11, 1.06311793502, 426.598190876],
567
+ [0.00107674962, 2.27769131009, 206.1855484372],
568
+ [40244455e-11, 2.04108104671, 220.4126424388],
569
+ [19941774e-11, 1.2795439047, 103.0927742186],
570
+ [10511678e-11, 2.7488034213, 14.2270940016],
571
+ [6416106e-11, 0.38238295041, 639.897286314],
572
+ [4848994e-11, 2.43037610229, 419.4846438752],
573
+ [4056892e-11, 2.92133209468, 110.2063212194],
574
+ [3768635e-11, 3.6496533078, 3.9321532631]
575
+ ],
576
+ [
577
+ [0.0011644133, 1.17988132879, 7.1135470008],
578
+ [91841837e-11, 0.0732519584, 213.299095438],
579
+ [36661728e-11, 0, 0],
580
+ [15274496e-11, 4.06493179167, 206.1855484372]
581
+ ]
582
+ ],
583
+ [
584
+ [
585
+ [0.04330678039, 3.60284428399, 213.299095438],
586
+ [0.00240348302, 2.85238489373, 426.598190876],
587
+ [84745939e-11, 0, 0],
588
+ [30863357e-11, 3.48441504555, 220.4126424388],
589
+ [34116062e-11, 0.57297307557, 206.1855484372],
590
+ [1473407e-10, 2.11846596715, 639.897286314],
591
+ [9916667e-11, 5.79003188904, 419.4846438752],
592
+ [6993564e-11, 4.7360468972, 7.1135470008],
593
+ [4807588e-11, 5.43305312061, 316.3918696566]
594
+ ],
595
+ [
596
+ [0.00198927992, 4.93901017903, 213.299095438],
597
+ [36947916e-11, 3.14159265359, 0],
598
+ [17966989e-11, 0.5197943111, 426.598190876]
599
+ ]
600
+ ],
601
+ [
602
+ [
603
+ [9.55758135486, 0, 0],
604
+ [0.52921382865, 2.39226219573, 213.299095438],
605
+ [0.01873679867, 5.2354960466, 206.1855484372],
606
+ [0.01464663929, 1.64763042902, 426.598190876],
607
+ [0.00821891141, 5.93520042303, 316.3918696566],
608
+ [0.00547506923, 5.0153261898, 103.0927742186],
609
+ [0.0037168465, 2.27114821115, 220.4126424388],
610
+ [0.00361778765, 3.13904301847, 7.1135470008],
611
+ [0.00140617506, 5.70406606781, 632.7837393132],
612
+ [0.00108974848, 3.29313390175, 110.2063212194],
613
+ [69006962e-11, 5.94099540992, 419.4846438752],
614
+ [61053367e-11, 0.94037691801, 639.897286314],
615
+ [48913294e-11, 1.55733638681, 202.2533951741],
616
+ [34143772e-11, 0.19519102597, 277.0349937414],
617
+ [32401773e-11, 5.47084567016, 949.1756089698],
618
+ [20936596e-11, 0.46349251129, 735.8765135318],
619
+ [9796004e-11, 5.20477537945, 1265.5674786264],
620
+ [11993338e-11, 5.98050967385, 846.0828347512],
621
+ [208393e-9, 1.52102476129, 433.7117378768],
622
+ [15298404e-11, 3.0594381494, 529.6909650946],
623
+ [6465823e-11, 0.17732249942, 1052.2683831884],
624
+ [11380257e-11, 1.7310542704, 522.5774180938],
625
+ [3419618e-11, 4.94550542171, 1581.959348283]
626
+ ],
627
+ [
628
+ [0.0618298134, 0.2584351148, 213.299095438],
629
+ [0.00506577242, 0.71114625261, 206.1855484372],
630
+ [0.00341394029, 5.79635741658, 426.598190876],
631
+ [0.00188491195, 0.47215589652, 220.4126424388],
632
+ [0.00186261486, 3.14159265359, 0],
633
+ [0.00143891146, 1.40744822888, 7.1135470008]
634
+ ],
635
+ [
636
+ [0.00436902572, 4.78671677509, 213.299095438]
637
+ ]
638
+ ]
639
+ ],
640
+ Uranus: [
641
+ [
642
+ [
643
+ [5.48129294297, 0, 0],
644
+ [0.09260408234, 0.89106421507, 74.7815985673],
645
+ [0.01504247898, 3.6271926092, 1.4844727083],
646
+ [0.00365981674, 1.89962179044, 73.297125859],
647
+ [0.00272328168, 3.35823706307, 149.5631971346],
648
+ [70328461e-11, 5.39254450063, 63.7358983034],
649
+ [68892678e-11, 6.09292483287, 76.2660712756],
650
+ [61998615e-11, 2.26952066061, 2.9689454166],
651
+ [61950719e-11, 2.85098872691, 11.0457002639],
652
+ [2646877e-10, 3.14152083966, 71.8126531507],
653
+ [25710476e-11, 6.11379840493, 454.9093665273],
654
+ [2107885e-10, 4.36059339067, 148.0787244263],
655
+ [17818647e-11, 1.74436930289, 36.6485629295],
656
+ [14613507e-11, 4.73732166022, 3.9321532631],
657
+ [11162509e-11, 5.8268179635, 224.3447957019],
658
+ [1099791e-10, 0.48865004018, 138.5174968707],
659
+ [9527478e-11, 2.95516862826, 35.1640902212],
660
+ [7545601e-11, 5.236265824, 109.9456887885],
661
+ [4220241e-11, 3.23328220918, 70.8494453042],
662
+ [40519e-9, 2.277550173, 151.0476698429],
663
+ [3354596e-11, 1.0654900738, 4.4534181249],
664
+ [2926718e-11, 4.62903718891, 9.5612275556],
665
+ [349034e-10, 5.48306144511, 146.594251718],
666
+ [3144069e-11, 4.75199570434, 77.7505439839],
667
+ [2922333e-11, 5.35235361027, 85.8272988312],
668
+ [2272788e-11, 4.36600400036, 70.3281804424],
669
+ [2051219e-11, 1.51773566586, 0.1118745846],
670
+ [2148602e-11, 0.60745949945, 38.1330356378],
671
+ [1991643e-11, 4.92437588682, 277.0349937414],
672
+ [1376226e-11, 2.04283539351, 65.2203710117],
673
+ [1666902e-11, 3.62744066769, 380.12776796],
674
+ [1284107e-11, 3.11347961505, 202.2533951741],
675
+ [1150429e-11, 0.93343589092, 3.1813937377],
676
+ [1533221e-11, 2.58594681212, 52.6901980395],
677
+ [1281604e-11, 0.54271272721, 222.8603229936],
678
+ [1372139e-11, 4.19641530878, 111.4301614968],
679
+ [1221029e-11, 0.1990065003, 108.4612160802],
680
+ [946181e-11, 1.19253165736, 127.4717966068],
681
+ [1150989e-11, 4.17898916639, 33.6796175129]
682
+ ],
683
+ [
684
+ [74.7815986091, 0, 0],
685
+ [0.00154332863, 5.24158770553, 74.7815985673],
686
+ [24456474e-11, 1.71260334156, 1.4844727083],
687
+ [9258442e-11, 0.4282973235, 11.0457002639],
688
+ [8265977e-11, 1.50218091379, 63.7358983034],
689
+ [915016e-10, 1.41213765216, 149.5631971346]
690
+ ]
691
+ ],
692
+ [
693
+ [
694
+ [0.01346277648, 2.61877810547, 74.7815985673],
695
+ [623414e-9, 5.08111189648, 149.5631971346],
696
+ [61601196e-11, 3.14159265359, 0],
697
+ [9963722e-11, 1.61603805646, 76.2660712756],
698
+ [992616e-10, 0.57630380333, 73.297125859]
699
+ ],
700
+ [
701
+ [34101978e-11, 0.01321929936, 74.7815985673]
702
+ ]
703
+ ],
704
+ [
705
+ [
706
+ [19.21264847206, 0, 0],
707
+ [0.88784984413, 5.60377527014, 74.7815985673],
708
+ [0.03440836062, 0.32836099706, 73.297125859],
709
+ [0.0205565386, 1.7829515933, 149.5631971346],
710
+ [0.0064932241, 4.52247285911, 76.2660712756],
711
+ [0.00602247865, 3.86003823674, 63.7358983034],
712
+ [0.00496404167, 1.40139935333, 454.9093665273],
713
+ [0.00338525369, 1.58002770318, 138.5174968707],
714
+ [0.00243509114, 1.57086606044, 71.8126531507],
715
+ [0.00190522303, 1.99809394714, 1.4844727083],
716
+ [0.00161858838, 2.79137786799, 148.0787244263],
717
+ [0.00143706183, 1.38368544947, 11.0457002639],
718
+ [93192405e-11, 0.17437220467, 36.6485629295],
719
+ [71424548e-11, 4.24509236074, 224.3447957019],
720
+ [89806014e-11, 3.66105364565, 109.9456887885],
721
+ [39009723e-11, 1.66971401684, 70.8494453042],
722
+ [46677296e-11, 1.39976401694, 35.1640902212],
723
+ [39025624e-11, 3.36234773834, 277.0349937414],
724
+ [36755274e-11, 3.88649278513, 146.594251718],
725
+ [30348723e-11, 0.70100838798, 151.0476698429],
726
+ [29156413e-11, 3.180563367, 77.7505439839],
727
+ [22637073e-11, 0.72518687029, 529.6909650946],
728
+ [11959076e-11, 1.7504339214, 984.6003316219],
729
+ [25620756e-11, 5.25656086672, 380.12776796]
730
+ ],
731
+ [
732
+ [0.01479896629, 3.67205697578, 74.7815985673]
733
+ ]
734
+ ]
735
+ ],
736
+ Neptune: [
737
+ [
738
+ [
739
+ [5.31188633046, 0, 0],
740
+ [0.0179847553, 2.9010127389, 38.1330356378],
741
+ [0.01019727652, 0.48580922867, 1.4844727083],
742
+ [0.00124531845, 4.83008090676, 36.6485629295],
743
+ [42064466e-11, 5.41054993053, 2.9689454166],
744
+ [37714584e-11, 6.09221808686, 35.1640902212],
745
+ [33784738e-11, 1.24488874087, 76.2660712756],
746
+ [16482741e-11, 7727998e-11, 491.5579294568],
747
+ [9198584e-11, 4.93747051954, 39.6175083461],
748
+ [899425e-10, 0.27462171806, 175.1660598002]
749
+ ],
750
+ [
751
+ [38.13303563957, 0, 0],
752
+ [16604172e-11, 4.86323329249, 1.4844727083],
753
+ [15744045e-11, 2.27887427527, 38.1330356378]
754
+ ]
755
+ ],
756
+ [
757
+ [
758
+ [0.03088622933, 1.44104372644, 38.1330356378],
759
+ [27780087e-11, 5.91271884599, 76.2660712756],
760
+ [27623609e-11, 0, 0],
761
+ [15355489e-11, 2.52123799551, 36.6485629295],
762
+ [15448133e-11, 3.50877079215, 39.6175083461]
763
+ ]
764
+ ],
765
+ [
766
+ [
767
+ [30.07013205828, 0, 0],
768
+ [0.27062259632, 1.32999459377, 38.1330356378],
769
+ [0.01691764014, 3.25186135653, 36.6485629295],
770
+ [0.00807830553, 5.18592878704, 1.4844727083],
771
+ [0.0053776051, 4.52113935896, 35.1640902212],
772
+ [0.00495725141, 1.5710564165, 491.5579294568],
773
+ [0.00274571975, 1.84552258866, 175.1660598002],
774
+ [1201232e-10, 1.92059384991, 1021.2488945514],
775
+ [0.00121801746, 5.79754470298, 76.2660712756],
776
+ [0.00100896068, 0.3770272493, 73.297125859],
777
+ [0.00135134092, 3.37220609835, 39.6175083461],
778
+ [7571796e-11, 1.07149207335, 388.4651552382]
779
+ ]
780
+ ]
781
+ ]
782
+ };
783
+ function DeltaT_EspenakMeeus(ut) {
784
+ var u, u2, u3, u4, u5, u6, u7;
785
+ const y = 2e3 + (ut - 14) / DAYS_PER_TROPICAL_YEAR;
786
+ if (y < -500) {
787
+ u = (y - 1820) / 100;
788
+ return -20 + 32 * u * u;
789
+ }
790
+ if (y < 500) {
791
+ u = y / 100;
792
+ u2 = u * u;
793
+ u3 = u * u2;
794
+ u4 = u2 * u2;
795
+ u5 = u2 * u3;
796
+ u6 = u3 * u3;
797
+ return 10583.6 - 1014.41 * u + 33.78311 * u2 - 5.952053 * u3 - 0.1798452 * u4 + 0.022174192 * u5 + 0.0090316521 * u6;
798
+ }
799
+ if (y < 1600) {
800
+ u = (y - 1e3) / 100;
801
+ u2 = u * u;
802
+ u3 = u * u2;
803
+ u4 = u2 * u2;
804
+ u5 = u2 * u3;
805
+ u6 = u3 * u3;
806
+ return 1574.2 - 556.01 * u + 71.23472 * u2 + 0.319781 * u3 - 0.8503463 * u4 - 5050998e-9 * u5 + 0.0083572073 * u6;
807
+ }
808
+ if (y < 1700) {
809
+ u = y - 1600;
810
+ u2 = u * u;
811
+ u3 = u * u2;
812
+ return 120 - 0.9808 * u - 0.01532 * u2 + u3 / 7129;
813
+ }
814
+ if (y < 1800) {
815
+ u = y - 1700;
816
+ u2 = u * u;
817
+ u3 = u * u2;
818
+ u4 = u2 * u2;
819
+ return 8.83 + 0.1603 * u - 59285e-7 * u2 + 13336e-8 * u3 - u4 / 1174e3;
820
+ }
821
+ if (y < 1860) {
822
+ u = y - 1800;
823
+ u2 = u * u;
824
+ u3 = u * u2;
825
+ u4 = u2 * u2;
826
+ u5 = u2 * u3;
827
+ u6 = u3 * u3;
828
+ u7 = u3 * u4;
829
+ return 13.72 - 0.332447 * u + 68612e-7 * u2 + 41116e-7 * u3 - 37436e-8 * u4 + 121272e-10 * u5 - 1699e-10 * u6 + 875e-12 * u7;
830
+ }
831
+ if (y < 1900) {
832
+ u = y - 1860;
833
+ u2 = u * u;
834
+ u3 = u * u2;
835
+ u4 = u2 * u2;
836
+ u5 = u2 * u3;
837
+ return 7.62 + 0.5737 * u - 0.251754 * u2 + 0.01680668 * u3 - 4473624e-10 * u4 + u5 / 233174;
838
+ }
839
+ if (y < 1920) {
840
+ u = y - 1900;
841
+ u2 = u * u;
842
+ u3 = u * u2;
843
+ u4 = u2 * u2;
844
+ return -2.79 + 1.494119 * u - 0.0598939 * u2 + 61966e-7 * u3 - 197e-6 * u4;
845
+ }
846
+ if (y < 1941) {
847
+ u = y - 1920;
848
+ u2 = u * u;
849
+ u3 = u * u2;
850
+ return 21.2 + 0.84493 * u - 0.0761 * u2 + 20936e-7 * u3;
851
+ }
852
+ if (y < 1961) {
853
+ u = y - 1950;
854
+ u2 = u * u;
855
+ u3 = u * u2;
856
+ return 29.07 + 0.407 * u - u2 / 233 + u3 / 2547;
857
+ }
858
+ if (y < 1986) {
859
+ u = y - 1975;
860
+ u2 = u * u;
861
+ u3 = u * u2;
862
+ return 45.45 + 1.067 * u - u2 / 260 - u3 / 718;
863
+ }
864
+ if (y < 2005) {
865
+ u = y - 2e3;
866
+ u2 = u * u;
867
+ u3 = u * u2;
868
+ u4 = u2 * u2;
869
+ u5 = u2 * u3;
870
+ return 63.86 + 0.3345 * u - 0.060374 * u2 + 17275e-7 * u3 + 651814e-9 * u4 + 2373599e-11 * u5;
871
+ }
872
+ if (y < 2050) {
873
+ u = y - 2e3;
874
+ return 62.92 + 0.32217 * u + 5589e-6 * u * u;
875
+ }
876
+ if (y < 2150) {
877
+ u = (y - 1820) / 100;
878
+ return -20 + 32 * u * u - 0.5628 * (2150 - y);
879
+ }
880
+ u = (y - 1820) / 100;
881
+ return -20 + 32 * u * u;
882
+ }
883
+ var DeltaT = DeltaT_EspenakMeeus;
884
+ function TerrestrialTime(ut) {
885
+ return ut + DeltaT(ut) / 86400;
886
+ }
887
+ var AstroTime = class _AstroTime {
888
+ /**
889
+ * @param {FlexibleDateTime} date
890
+ * A JavaScript Date object, a numeric UTC value expressed in J2000 days, or another AstroTime object.
891
+ */
892
+ constructor(date) {
893
+ if (date instanceof _AstroTime) {
894
+ this.date = date.date;
895
+ this.ut = date.ut;
896
+ this.tt = date.tt;
897
+ return;
898
+ }
899
+ const MillisPerDay = 1e3 * 3600 * 24;
900
+ if (date instanceof Date && Number.isFinite(date.getTime())) {
901
+ this.date = date;
902
+ this.ut = (date.getTime() - J2000.getTime()) / MillisPerDay;
903
+ this.tt = TerrestrialTime(this.ut);
904
+ return;
905
+ }
906
+ if (Number.isFinite(date)) {
907
+ this.date = new Date(J2000.getTime() + date * MillisPerDay);
908
+ this.ut = date;
909
+ this.tt = TerrestrialTime(this.ut);
910
+ return;
911
+ }
912
+ throw "Argument must be a Date object, an AstroTime object, or a numeric UTC Julian date.";
913
+ }
914
+ /**
915
+ * @brief Creates an `AstroTime` value from a Terrestrial Time (TT) day value.
916
+ *
917
+ * This function can be used in rare cases where a time must be based
918
+ * on Terrestrial Time (TT) rather than Universal Time (UT).
919
+ * Most developers will want to invoke `new AstroTime(ut)` with a universal time
920
+ * instead of this function, because usually time is based on civil time adjusted
921
+ * by leap seconds to match the Earth's rotation, rather than the uniformly
922
+ * flowing TT used to calculate solar system dynamics. In rare cases
923
+ * where the caller already knows TT, this function is provided to create
924
+ * an `AstroTime` value that can be passed to Astronomy Engine functions.
925
+ *
926
+ * @param {number} tt
927
+ * The number of days since the J2000 epoch as expressed in Terrestrial Time.
928
+ *
929
+ * @returns {AstroTime}
930
+ * An `AstroTime` object for the specified terrestrial time.
931
+ */
932
+ static FromTerrestrialTime(tt) {
933
+ let time = new _AstroTime(tt);
934
+ for (; ; ) {
935
+ const err = tt - time.tt;
936
+ if (Math.abs(err) < 1e-12)
937
+ return time;
938
+ time = time.AddDays(err);
939
+ }
940
+ }
941
+ /**
942
+ * Formats an `AstroTime` object as an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
943
+ * date/time string in UTC, to millisecond resolution.
944
+ * Example: `2018-08-17T17:22:04.050Z`
945
+ * @returns {string}
946
+ */
947
+ toString() {
948
+ return this.date.toISOString();
949
+ }
950
+ /**
951
+ * Returns a new `AstroTime` object adjusted by the floating point number of days.
952
+ * Does NOT modify the original `AstroTime` object.
953
+ *
954
+ * @param {number} days
955
+ * The floating point number of days by which to adjust the given date and time.
956
+ * Positive values adjust the date toward the future, and
957
+ * negative values adjust the date toward the past.
958
+ *
959
+ * @returns {AstroTime}
960
+ */
961
+ AddDays(days) {
962
+ return new _AstroTime(this.ut + days);
963
+ }
964
+ };
965
+ function InterpolateTime(time1, time2, fraction) {
966
+ return new AstroTime(time1.ut + fraction * (time2.ut - time1.ut));
967
+ }
968
+ function MakeTime(date) {
969
+ if (date instanceof AstroTime) {
970
+ return date;
971
+ }
972
+ return new AstroTime(date);
973
+ }
974
+ function iau2000b(time) {
975
+ function mod(x) {
976
+ return x % ASEC360 * ASEC2RAD;
977
+ }
978
+ const t = time.tt / 36525;
979
+ const elp = mod(128710479305e-5 + t * 1295965810481e-4);
980
+ const f = mod(335779.526232 + t * 17395272628478e-4);
981
+ const d = mod(107226070369e-5 + t * 1602961601209e-3);
982
+ const om = mod(450160.398036 - t * 69628905431e-4);
983
+ let sarg = Math.sin(om);
984
+ let carg = Math.cos(om);
985
+ let dp = (-172064161 - 174666 * t) * sarg + 33386 * carg;
986
+ let de = (92052331 + 9086 * t) * carg + 15377 * sarg;
987
+ let arg = 2 * (f - d + om);
988
+ sarg = Math.sin(arg);
989
+ carg = Math.cos(arg);
990
+ dp += (-13170906 - 1675 * t) * sarg - 13696 * carg;
991
+ de += (5730336 - 3015 * t) * carg - 4587 * sarg;
992
+ arg = 2 * (f + om);
993
+ sarg = Math.sin(arg);
994
+ carg = Math.cos(arg);
995
+ dp += (-2276413 - 234 * t) * sarg + 2796 * carg;
996
+ de += (978459 - 485 * t) * carg + 1374 * sarg;
997
+ arg = 2 * om;
998
+ sarg = Math.sin(arg);
999
+ carg = Math.cos(arg);
1000
+ dp += (2074554 + 207 * t) * sarg - 698 * carg;
1001
+ de += (-897492 + 470 * t) * carg - 291 * sarg;
1002
+ sarg = Math.sin(elp);
1003
+ carg = Math.cos(elp);
1004
+ dp += (1475877 - 3633 * t) * sarg + 11817 * carg;
1005
+ de += (73871 - 184 * t) * carg - 1924 * sarg;
1006
+ return {
1007
+ dpsi: -135e-6 + dp * 1e-7,
1008
+ deps: 388e-6 + de * 1e-7
1009
+ };
1010
+ }
1011
+ function mean_obliq(time) {
1012
+ var t = time.tt / 36525;
1013
+ var asec = ((((-4.34e-8 * t - 576e-9) * t + 20034e-7) * t - 1831e-7) * t - 46.836769) * t + 84381.406;
1014
+ return asec / 3600;
1015
+ }
1016
+ var cache_e_tilt;
1017
+ function e_tilt(time) {
1018
+ if (!cache_e_tilt || Math.abs(cache_e_tilt.tt - time.tt) > 1e-6) {
1019
+ const nut = iau2000b(time);
1020
+ const mean_ob = mean_obliq(time);
1021
+ const true_ob = mean_ob + nut.deps / 3600;
1022
+ cache_e_tilt = {
1023
+ tt: time.tt,
1024
+ dpsi: nut.dpsi,
1025
+ deps: nut.deps,
1026
+ ee: nut.dpsi * Math.cos(mean_ob * DEG2RAD) / 15,
1027
+ mobl: mean_ob,
1028
+ tobl: true_ob
1029
+ };
1030
+ }
1031
+ return cache_e_tilt;
1032
+ }
1033
+ function obl_ecl2equ_vec(oblDegrees, pos) {
1034
+ const obl = oblDegrees * DEG2RAD;
1035
+ const cos_obl = Math.cos(obl);
1036
+ const sin_obl = Math.sin(obl);
1037
+ return [
1038
+ pos[0],
1039
+ pos[1] * cos_obl - pos[2] * sin_obl,
1040
+ pos[1] * sin_obl + pos[2] * cos_obl
1041
+ ];
1042
+ }
1043
+ function ecl2equ_vec(time, pos) {
1044
+ return obl_ecl2equ_vec(mean_obliq(time), pos);
1045
+ }
1046
+ function CalcMoon(time) {
1047
+ const T = time.tt / 36525;
1048
+ function DeclareArray1(xmin, xmax) {
1049
+ const array = [];
1050
+ let i;
1051
+ for (i = 0; i <= xmax - xmin; ++i) {
1052
+ array.push(0);
1053
+ }
1054
+ return { min: xmin, array };
1055
+ }
1056
+ function DeclareArray2(xmin, xmax, ymin, ymax) {
1057
+ const array = [];
1058
+ for (let i = 0; i <= xmax - xmin; ++i) {
1059
+ array.push(DeclareArray1(ymin, ymax));
1060
+ }
1061
+ return { min: xmin, array };
1062
+ }
1063
+ function ArrayGet2(a, x, y) {
1064
+ const m = a.array[x - a.min];
1065
+ return m.array[y - m.min];
1066
+ }
1067
+ function ArraySet2(a, x, y, v) {
1068
+ const m = a.array[x - a.min];
1069
+ m.array[y - m.min] = v;
1070
+ }
1071
+ let S, MAX, ARG, FAC, I, J, T2, DGAM, DLAM, N, GAM1C, SINPI, L0, L, LS, F, D, DL0, DL, DLS, DF, DD, DS;
1072
+ let coArray = DeclareArray2(-6, 6, 1, 4);
1073
+ let siArray = DeclareArray2(-6, 6, 1, 4);
1074
+ function CO(x, y) {
1075
+ return ArrayGet2(coArray, x, y);
1076
+ }
1077
+ function SI(x, y) {
1078
+ return ArrayGet2(siArray, x, y);
1079
+ }
1080
+ function SetCO(x, y, v) {
1081
+ return ArraySet2(coArray, x, y, v);
1082
+ }
1083
+ function SetSI(x, y, v) {
1084
+ return ArraySet2(siArray, x, y, v);
1085
+ }
1086
+ function AddThe(c1, s1, c2, s2, func) {
1087
+ func(c1 * c2 - s1 * s2, s1 * c2 + c1 * s2);
1088
+ }
1089
+ function Sine(phi) {
1090
+ return Math.sin(PI2 * phi);
1091
+ }
1092
+ T2 = T * T;
1093
+ DLAM = 0;
1094
+ DS = 0;
1095
+ GAM1C = 0;
1096
+ SINPI = 3422.7;
1097
+ var S1 = Sine(0.19833 + 0.05611 * T);
1098
+ var S2 = Sine(0.27869 + 0.04508 * T);
1099
+ var S3 = Sine(0.16827 - 0.36903 * T);
1100
+ var S4 = Sine(0.34734 - 5.37261 * T);
1101
+ var S5 = Sine(0.10498 - 5.37899 * T);
1102
+ var S6 = Sine(0.42681 - 0.41855 * T);
1103
+ var S7 = Sine(0.14943 - 5.37511 * T);
1104
+ DL0 = 0.84 * S1 + 0.31 * S2 + 14.27 * S3 + 7.26 * S4 + 0.28 * S5 + 0.24 * S6;
1105
+ DL = 2.94 * S1 + 0.31 * S2 + 14.27 * S3 + 9.34 * S4 + 1.12 * S5 + 0.83 * S6;
1106
+ DLS = -6.4 * S1 - 1.89 * S6;
1107
+ DF = 0.21 * S1 + 0.31 * S2 + 14.27 * S3 - 88.7 * S4 - 15.3 * S5 + 0.24 * S6 - 1.86 * S7;
1108
+ DD = DL0 - DLS;
1109
+ DGAM = -3332e-9 * Sine(0.59734 - 5.37261 * T) - 539e-9 * Sine(0.35498 - 5.37899 * T) - 64e-9 * Sine(0.39943 - 5.37511 * T);
1110
+ L0 = PI2 * Frac(0.60643382 + 1336.85522467 * T - 313e-8 * T2) + DL0 / ARC;
1111
+ L = PI2 * Frac(0.37489701 + 1325.55240982 * T + 2565e-8 * T2) + DL / ARC;
1112
+ LS = PI2 * Frac(0.99312619 + 99.99735956 * T - 44e-8 * T2) + DLS / ARC;
1113
+ F = PI2 * Frac(0.25909118 + 1342.2278298 * T - 892e-8 * T2) + DF / ARC;
1114
+ D = PI2 * Frac(0.82736186 + 1236.85308708 * T - 397e-8 * T2) + DD / ARC;
1115
+ for (I = 1; I <= 4; ++I) {
1116
+ switch (I) {
1117
+ case 1:
1118
+ ARG = L;
1119
+ MAX = 4;
1120
+ FAC = 1.000002208;
1121
+ break;
1122
+ case 2:
1123
+ ARG = LS;
1124
+ MAX = 3;
1125
+ FAC = 0.997504612 - 2495388e-9 * T;
1126
+ break;
1127
+ case 3:
1128
+ ARG = F;
1129
+ MAX = 4;
1130
+ FAC = 1.000002708 + 139.978 * DGAM;
1131
+ break;
1132
+ case 4:
1133
+ ARG = D;
1134
+ MAX = 6;
1135
+ FAC = 1;
1136
+ break;
1137
+ default:
1138
+ throw `Internal error: I = ${I}`;
1139
+ }
1140
+ SetCO(0, I, 1);
1141
+ SetCO(1, I, Math.cos(ARG) * FAC);
1142
+ SetSI(0, I, 0);
1143
+ SetSI(1, I, Math.sin(ARG) * FAC);
1144
+ for (J = 2; J <= MAX; ++J) {
1145
+ AddThe(CO(J - 1, I), SI(J - 1, I), CO(1, I), SI(1, I), (c, s) => (SetCO(J, I, c), SetSI(J, I, s)));
1146
+ }
1147
+ for (J = 1; J <= MAX; ++J) {
1148
+ SetCO(-J, I, CO(J, I));
1149
+ SetSI(-J, I, -SI(J, I));
1150
+ }
1151
+ }
1152
+ function Term(p, q, r, s) {
1153
+ var result = { x: 1, y: 0 };
1154
+ var I2 = [0, p, q, r, s];
1155
+ for (var k = 1; k <= 4; ++k)
1156
+ if (I2[k] !== 0)
1157
+ AddThe(result.x, result.y, CO(I2[k], k), SI(I2[k], k), (c, s2) => (result.x = c, result.y = s2));
1158
+ return result;
1159
+ }
1160
+ function AddSol(coeffl, coeffs, coeffg, coeffp, p, q, r, s) {
1161
+ var result = Term(p, q, r, s);
1162
+ DLAM += coeffl * result.y;
1163
+ DS += coeffs * result.y;
1164
+ GAM1C += coeffg * result.x;
1165
+ SINPI += coeffp * result.x;
1166
+ }
1167
+ AddSol(13.902, 14.06, -1e-3, 0.2607, 0, 0, 0, 4);
1168
+ AddSol(0.403, -4.01, 0.394, 23e-4, 0, 0, 0, 3);
1169
+ AddSol(2369.912, 2373.36, 0.601, 28.2333, 0, 0, 0, 2);
1170
+ AddSol(-125.154, -112.79, -0.725, -0.9781, 0, 0, 0, 1);
1171
+ AddSol(1.979, 6.98, -0.445, 0.0433, 1, 0, 0, 4);
1172
+ AddSol(191.953, 192.72, 0.029, 3.0861, 1, 0, 0, 2);
1173
+ AddSol(-8.466, -13.51, 0.455, -0.1093, 1, 0, 0, 1);
1174
+ AddSol(22639.5, 22609.07, 0.079, 186.5398, 1, 0, 0, 0);
1175
+ AddSol(18.609, 3.59, -0.094, 0.0118, 1, 0, 0, -1);
1176
+ AddSol(-4586.465, -4578.13, -0.077, 34.3117, 1, 0, 0, -2);
1177
+ AddSol(3.215, 5.44, 0.192, -0.0386, 1, 0, 0, -3);
1178
+ AddSol(-38.428, -38.64, 1e-3, 0.6008, 1, 0, 0, -4);
1179
+ AddSol(-0.393, -1.43, -0.092, 86e-4, 1, 0, 0, -6);
1180
+ AddSol(-0.289, -1.59, 0.123, -53e-4, 0, 1, 0, 4);
1181
+ AddSol(-24.42, -25.1, 0.04, -0.3, 0, 1, 0, 2);
1182
+ AddSol(18.023, 17.93, 7e-3, 0.1494, 0, 1, 0, 1);
1183
+ AddSol(-668.146, -126.98, -1.302, -0.3997, 0, 1, 0, 0);
1184
+ AddSol(0.56, 0.32, -1e-3, -37e-4, 0, 1, 0, -1);
1185
+ AddSol(-165.145, -165.06, 0.054, 1.9178, 0, 1, 0, -2);
1186
+ AddSol(-1.877, -6.46, -0.416, 0.0339, 0, 1, 0, -4);
1187
+ AddSol(0.213, 1.02, -0.074, 54e-4, 2, 0, 0, 4);
1188
+ AddSol(14.387, 14.78, -0.017, 0.2833, 2, 0, 0, 2);
1189
+ AddSol(-0.586, -1.2, 0.054, -0.01, 2, 0, 0, 1);
1190
+ AddSol(769.016, 767.96, 0.107, 10.1657, 2, 0, 0, 0);
1191
+ AddSol(1.75, 2.01, -0.018, 0.0155, 2, 0, 0, -1);
1192
+ AddSol(-211.656, -152.53, 5.679, -0.3039, 2, 0, 0, -2);
1193
+ AddSol(1.225, 0.91, -0.03, -88e-4, 2, 0, 0, -3);
1194
+ AddSol(-30.773, -34.07, -0.308, 0.3722, 2, 0, 0, -4);
1195
+ AddSol(-0.57, -1.4, -0.074, 0.0109, 2, 0, 0, -6);
1196
+ AddSol(-2.921, -11.75, 0.787, -0.0484, 1, 1, 0, 2);
1197
+ AddSol(1.267, 1.52, -0.022, 0.0164, 1, 1, 0, 1);
1198
+ AddSol(-109.673, -115.18, 0.461, -0.949, 1, 1, 0, 0);
1199
+ AddSol(-205.962, -182.36, 2.056, 1.4437, 1, 1, 0, -2);
1200
+ AddSol(0.233, 0.36, 0.012, -25e-4, 1, 1, 0, -3);
1201
+ AddSol(-4.391, -9.66, -0.471, 0.0673, 1, 1, 0, -4);
1202
+ AddSol(0.283, 1.53, -0.111, 6e-3, 1, -1, 0, 4);
1203
+ AddSol(14.577, 31.7, -1.54, 0.2302, 1, -1, 0, 2);
1204
+ AddSol(147.687, 138.76, 0.679, 1.1528, 1, -1, 0, 0);
1205
+ AddSol(-1.089, 0.55, 0.021, 0, 1, -1, 0, -1);
1206
+ AddSol(28.475, 23.59, -0.443, -0.2257, 1, -1, 0, -2);
1207
+ AddSol(-0.276, -0.38, -6e-3, -36e-4, 1, -1, 0, -3);
1208
+ AddSol(0.636, 2.27, 0.146, -0.0102, 1, -1, 0, -4);
1209
+ AddSol(-0.189, -1.68, 0.131, -28e-4, 0, 2, 0, 2);
1210
+ AddSol(-7.486, -0.66, -0.037, -86e-4, 0, 2, 0, 0);
1211
+ AddSol(-8.096, -16.35, -0.74, 0.0918, 0, 2, 0, -2);
1212
+ AddSol(-5.741, -0.04, 0, -9e-4, 0, 0, 2, 2);
1213
+ AddSol(0.255, 0, 0, 0, 0, 0, 2, 1);
1214
+ AddSol(-411.608, -0.2, 0, -0.0124, 0, 0, 2, 0);
1215
+ AddSol(0.584, 0.84, 0, 71e-4, 0, 0, 2, -1);
1216
+ AddSol(-55.173, -52.14, 0, -0.1052, 0, 0, 2, -2);
1217
+ AddSol(0.254, 0.25, 0, -17e-4, 0, 0, 2, -3);
1218
+ AddSol(0.025, -1.67, 0, 31e-4, 0, 0, 2, -4);
1219
+ AddSol(1.06, 2.96, -0.166, 0.0243, 3, 0, 0, 2);
1220
+ AddSol(36.124, 50.64, -1.3, 0.6215, 3, 0, 0, 0);
1221
+ AddSol(-13.193, -16.4, 0.258, -0.1187, 3, 0, 0, -2);
1222
+ AddSol(-1.187, -0.74, 0.042, 74e-4, 3, 0, 0, -4);
1223
+ AddSol(-0.293, -0.31, -2e-3, 46e-4, 3, 0, 0, -6);
1224
+ AddSol(-0.29, -1.45, 0.116, -51e-4, 2, 1, 0, 2);
1225
+ AddSol(-7.649, -10.56, 0.259, -0.1038, 2, 1, 0, 0);
1226
+ AddSol(-8.627, -7.59, 0.078, -0.0192, 2, 1, 0, -2);
1227
+ AddSol(-2.74, -2.54, 0.022, 0.0324, 2, 1, 0, -4);
1228
+ AddSol(1.181, 3.32, -0.212, 0.0213, 2, -1, 0, 2);
1229
+ AddSol(9.703, 11.67, -0.151, 0.1268, 2, -1, 0, 0);
1230
+ AddSol(-0.352, -0.37, 1e-3, -28e-4, 2, -1, 0, -1);
1231
+ AddSol(-2.494, -1.17, -3e-3, -17e-4, 2, -1, 0, -2);
1232
+ AddSol(0.36, 0.2, -0.012, -43e-4, 2, -1, 0, -4);
1233
+ AddSol(-1.167, -1.25, 8e-3, -0.0106, 1, 2, 0, 0);
1234
+ AddSol(-7.412, -6.12, 0.117, 0.0484, 1, 2, 0, -2);
1235
+ AddSol(-0.311, -0.65, -0.032, 44e-4, 1, 2, 0, -4);
1236
+ AddSol(0.757, 1.82, -0.105, 0.0112, 1, -2, 0, 2);
1237
+ AddSol(2.58, 2.32, 0.027, 0.0196, 1, -2, 0, 0);
1238
+ AddSol(2.533, 2.4, -0.014, -0.0212, 1, -2, 0, -2);
1239
+ AddSol(-0.344, -0.57, -0.025, 36e-4, 0, 3, 0, -2);
1240
+ AddSol(-0.992, -0.02, 0, 0, 1, 0, 2, 2);
1241
+ AddSol(-45.099, -0.02, 0, -1e-3, 1, 0, 2, 0);
1242
+ AddSol(-0.179, -9.52, 0, -0.0833, 1, 0, 2, -2);
1243
+ AddSol(-0.301, -0.33, 0, 14e-4, 1, 0, 2, -4);
1244
+ AddSol(-6.382, -3.37, 0, -0.0481, 1, 0, -2, 2);
1245
+ AddSol(39.528, 85.13, 0, -0.7136, 1, 0, -2, 0);
1246
+ AddSol(9.366, 0.71, 0, -0.0112, 1, 0, -2, -2);
1247
+ AddSol(0.202, 0.02, 0, 0, 1, 0, -2, -4);
1248
+ AddSol(0.415, 0.1, 0, 13e-4, 0, 1, 2, 0);
1249
+ AddSol(-2.152, -2.26, 0, -66e-4, 0, 1, 2, -2);
1250
+ AddSol(-1.44, -1.3, 0, 14e-4, 0, 1, -2, 2);
1251
+ AddSol(0.384, -0.04, 0, 0, 0, 1, -2, -2);
1252
+ AddSol(1.938, 3.6, -0.145, 0.0401, 4, 0, 0, 0);
1253
+ AddSol(-0.952, -1.58, 0.052, -0.013, 4, 0, 0, -2);
1254
+ AddSol(-0.551, -0.94, 0.032, -97e-4, 3, 1, 0, 0);
1255
+ AddSol(-0.482, -0.57, 5e-3, -45e-4, 3, 1, 0, -2);
1256
+ AddSol(0.681, 0.96, -0.026, 0.0115, 3, -1, 0, 0);
1257
+ AddSol(-0.297, -0.27, 2e-3, -9e-4, 2, 2, 0, -2);
1258
+ AddSol(0.254, 0.21, -3e-3, 0, 2, -2, 0, -2);
1259
+ AddSol(-0.25, -0.22, 4e-3, 14e-4, 1, 3, 0, -2);
1260
+ AddSol(-3.996, 0, 0, 4e-4, 2, 0, 2, 0);
1261
+ AddSol(0.557, -0.75, 0, -9e-3, 2, 0, 2, -2);
1262
+ AddSol(-0.459, -0.38, 0, -53e-4, 2, 0, -2, 2);
1263
+ AddSol(-1.298, 0.74, 0, 4e-4, 2, 0, -2, 0);
1264
+ AddSol(0.538, 1.14, 0, -0.0141, 2, 0, -2, -2);
1265
+ AddSol(0.263, 0.02, 0, 0, 1, 1, 2, 0);
1266
+ AddSol(0.426, 0.07, 0, -6e-4, 1, 1, -2, -2);
1267
+ AddSol(-0.304, 0.03, 0, 3e-4, 1, -1, 2, 0);
1268
+ AddSol(-0.372, -0.19, 0, -27e-4, 1, -1, -2, 2);
1269
+ AddSol(0.418, 0, 0, 0, 0, 0, 4, 0);
1270
+ AddSol(-0.33, -0.04, 0, 0, 3, 0, 2, 0);
1271
+ function ADDN(coeffn, p, q, r, s) {
1272
+ return coeffn * Term(p, q, r, s).y;
1273
+ }
1274
+ N = 0;
1275
+ N += ADDN(-526.069, 0, 0, 1, -2);
1276
+ N += ADDN(-3.352, 0, 0, 1, -4);
1277
+ N += ADDN(44.297, 1, 0, 1, -2);
1278
+ N += ADDN(-6, 1, 0, 1, -4);
1279
+ N += ADDN(20.599, -1, 0, 1, 0);
1280
+ N += ADDN(-30.598, -1, 0, 1, -2);
1281
+ N += ADDN(-24.649, -2, 0, 1, 0);
1282
+ N += ADDN(-2, -2, 0, 1, -2);
1283
+ N += ADDN(-22.571, 0, 1, 1, -2);
1284
+ N += ADDN(10.985, 0, -1, 1, -2);
1285
+ DLAM += 0.82 * Sine(0.7736 - 62.5512 * T) + 0.31 * Sine(0.0466 - 125.1025 * T) + 0.35 * Sine(0.5785 - 25.1042 * T) + 0.66 * Sine(0.4591 + 1335.8075 * T) + 0.64 * Sine(0.313 - 91.568 * T) + 1.14 * Sine(0.148 + 1331.2898 * T) + 0.21 * Sine(0.5918 + 1056.5859 * T) + 0.44 * Sine(0.5784 + 1322.8595 * T) + 0.24 * Sine(0.2275 - 5.7374 * T) + 0.28 * Sine(0.2965 + 2.6929 * T) + 0.33 * Sine(0.3132 + 6.3368 * T);
1286
+ S = F + DS / ARC;
1287
+ let lat_seconds = (1.000002708 + 139.978 * DGAM) * (18518.511 + 1.189 + GAM1C) * Math.sin(S) - 6.24 * Math.sin(3 * S) + N;
1288
+ return {
1289
+ geo_eclip_lon: PI2 * Frac((L0 + DLAM / ARC) / PI2),
1290
+ geo_eclip_lat: Math.PI / (180 * 3600) * lat_seconds,
1291
+ distance_au: ARC * EARTH_EQUATORIAL_RADIUS_AU / (0.999953253 * SINPI)
1292
+ };
1293
+ }
1294
+ function rotate(rot, vec) {
1295
+ return [
1296
+ rot.rot[0][0] * vec[0] + rot.rot[1][0] * vec[1] + rot.rot[2][0] * vec[2],
1297
+ rot.rot[0][1] * vec[0] + rot.rot[1][1] * vec[1] + rot.rot[2][1] * vec[2],
1298
+ rot.rot[0][2] * vec[0] + rot.rot[1][2] * vec[1] + rot.rot[2][2] * vec[2]
1299
+ ];
1300
+ }
1301
+ function precession(pos, time, dir) {
1302
+ const r = precession_rot(time, dir);
1303
+ return rotate(r, pos);
1304
+ }
1305
+ function precession_rot(time, dir) {
1306
+ const t = time.tt / 36525;
1307
+ let eps0 = 84381.406;
1308
+ let psia = ((((-9.51e-8 * t + 132851e-9) * t - 114045e-8) * t - 1.0790069) * t + 5038.481507) * t;
1309
+ let omegaa = ((((3337e-10 * t - 467e-9) * t - 772503e-8) * t + 0.0512623) * t - 0.025754) * t + eps0;
1310
+ let chia = ((((-56e-9 * t + 170663e-9) * t - 121197e-8) * t - 2.3814292) * t + 10.556403) * t;
1311
+ eps0 *= ASEC2RAD;
1312
+ psia *= ASEC2RAD;
1313
+ omegaa *= ASEC2RAD;
1314
+ chia *= ASEC2RAD;
1315
+ const sa2 = Math.sin(eps0);
1316
+ const ca = Math.cos(eps0);
1317
+ const sb = Math.sin(-psia);
1318
+ const cb = Math.cos(-psia);
1319
+ const sc = Math.sin(-omegaa);
1320
+ const cc = Math.cos(-omegaa);
1321
+ const sd = Math.sin(chia);
1322
+ const cd = Math.cos(chia);
1323
+ const xx = cd * cb - sb * sd * cc;
1324
+ const yx = cd * sb * ca + sd * cc * cb * ca - sa2 * sd * sc;
1325
+ const zx = cd * sb * sa2 + sd * cc * cb * sa2 + ca * sd * sc;
1326
+ const xy = -sd * cb - sb * cd * cc;
1327
+ const yy = -sd * sb * ca + cd * cc * cb * ca - sa2 * cd * sc;
1328
+ const zy = -sd * sb * sa2 + cd * cc * cb * sa2 + ca * cd * sc;
1329
+ const xz = sb * sc;
1330
+ const yz = -sc * cb * ca - sa2 * cc;
1331
+ const zz = -sc * cb * sa2 + cc * ca;
1332
+ if (dir === PrecessDirection.Into2000) {
1333
+ return new RotationMatrix([
1334
+ [xx, yx, zx],
1335
+ [xy, yy, zy],
1336
+ [xz, yz, zz]
1337
+ ]);
1338
+ }
1339
+ if (dir === PrecessDirection.From2000) {
1340
+ return new RotationMatrix([
1341
+ [xx, xy, xz],
1342
+ [yx, yy, yz],
1343
+ [zx, zy, zz]
1344
+ ]);
1345
+ }
1346
+ throw "Invalid precess direction";
1347
+ }
1348
+ function era(time) {
1349
+ const thet1 = 0.779057273264 + 0.00273781191135448 * time.ut;
1350
+ const thet3 = time.ut % 1;
1351
+ let theta = 360 * ((thet1 + thet3) % 1);
1352
+ if (theta < 0) {
1353
+ theta += 360;
1354
+ }
1355
+ return theta;
1356
+ }
1357
+ var sidereal_time_cache;
1358
+ function sidereal_time(time) {
1359
+ if (!sidereal_time_cache || sidereal_time_cache.tt !== time.tt) {
1360
+ const t = time.tt / 36525;
1361
+ let eqeq = 15 * e_tilt(time).ee;
1362
+ const theta = era(time);
1363
+ const st = eqeq + 0.014506 + ((((-3.68e-8 * t - 29956e-9) * t - 44e-8) * t + 1.3915817) * t + 4612.156534) * t;
1364
+ let gst = (st / 3600 + theta) % 360 / 15;
1365
+ if (gst < 0) {
1366
+ gst += 24;
1367
+ }
1368
+ sidereal_time_cache = {
1369
+ tt: time.tt,
1370
+ st: gst
1371
+ };
1372
+ }
1373
+ return sidereal_time_cache.st;
1374
+ }
1375
+ function terra(observer, st) {
1376
+ const phi = observer.latitude * DEG2RAD;
1377
+ const sinphi = Math.sin(phi);
1378
+ const cosphi = Math.cos(phi);
1379
+ const c = 1 / Math.hypot(cosphi, EARTH_FLATTENING * sinphi);
1380
+ const s = EARTH_FLATTENING_SQUARED * c;
1381
+ const ht_km = observer.height / 1e3;
1382
+ const ach = EARTH_EQUATORIAL_RADIUS_KM * c + ht_km;
1383
+ const ash = EARTH_EQUATORIAL_RADIUS_KM * s + ht_km;
1384
+ const stlocl = (15 * st + observer.longitude) * DEG2RAD;
1385
+ const sinst = Math.sin(stlocl);
1386
+ const cosst = Math.cos(stlocl);
1387
+ return {
1388
+ pos: [ach * cosphi * cosst / KM_PER_AU, ach * cosphi * sinst / KM_PER_AU, ash * sinphi / KM_PER_AU],
1389
+ vel: [-ANGVEL * ach * cosphi * sinst * 86400 / KM_PER_AU, ANGVEL * ach * cosphi * cosst * 86400 / KM_PER_AU, 0]
1390
+ };
1391
+ }
1392
+ function nutation(pos, time, dir) {
1393
+ const r = nutation_rot(time, dir);
1394
+ return rotate(r, pos);
1395
+ }
1396
+ function nutation_rot(time, dir) {
1397
+ const tilt = e_tilt(time);
1398
+ const oblm = tilt.mobl * DEG2RAD;
1399
+ const oblt = tilt.tobl * DEG2RAD;
1400
+ const psi = tilt.dpsi * ASEC2RAD;
1401
+ const cobm = Math.cos(oblm);
1402
+ const sobm = Math.sin(oblm);
1403
+ const cobt = Math.cos(oblt);
1404
+ const sobt = Math.sin(oblt);
1405
+ const cpsi = Math.cos(psi);
1406
+ const spsi = Math.sin(psi);
1407
+ const xx = cpsi;
1408
+ const yx = -spsi * cobm;
1409
+ const zx = -spsi * sobm;
1410
+ const xy = spsi * cobt;
1411
+ const yy = cpsi * cobm * cobt + sobm * sobt;
1412
+ const zy = cpsi * sobm * cobt - cobm * sobt;
1413
+ const xz = spsi * sobt;
1414
+ const yz = cpsi * cobm * sobt - sobm * cobt;
1415
+ const zz = cpsi * sobm * sobt + cobm * cobt;
1416
+ if (dir === PrecessDirection.From2000) {
1417
+ return new RotationMatrix([
1418
+ [xx, xy, xz],
1419
+ [yx, yy, yz],
1420
+ [zx, zy, zz]
1421
+ ]);
1422
+ }
1423
+ if (dir === PrecessDirection.Into2000) {
1424
+ return new RotationMatrix([
1425
+ [xx, yx, zx],
1426
+ [xy, yy, zy],
1427
+ [xz, yz, zz]
1428
+ ]);
1429
+ }
1430
+ throw "Invalid precess direction";
1431
+ }
1432
+ function gyration(pos, time, dir) {
1433
+ return dir === PrecessDirection.Into2000 ? precession(nutation(pos, time, dir), time, dir) : nutation(precession(pos, time, dir), time, dir);
1434
+ }
1435
+ function geo_pos(time, observer) {
1436
+ const gast = sidereal_time(time);
1437
+ const pos = terra(observer, gast).pos;
1438
+ return gyration(pos, time, PrecessDirection.Into2000);
1439
+ }
1440
+ var Vector = class {
1441
+ constructor(x, y, z, t) {
1442
+ this.x = x;
1443
+ this.y = y;
1444
+ this.z = z;
1445
+ this.t = t;
1446
+ }
1447
+ /**
1448
+ * Returns the length of the vector in astronomical units (AU).
1449
+ * @returns {number}
1450
+ */
1451
+ Length() {
1452
+ return Math.hypot(this.x, this.y, this.z);
1453
+ }
1454
+ };
1455
+ var StateVector = class {
1456
+ constructor(x, y, z, vx, vy, vz, t) {
1457
+ this.x = x;
1458
+ this.y = y;
1459
+ this.z = z;
1460
+ this.vx = vx;
1461
+ this.vy = vy;
1462
+ this.vz = vz;
1463
+ this.t = t;
1464
+ }
1465
+ };
1466
+ var Spherical = class {
1467
+ constructor(lat, lon, dist) {
1468
+ this.lat = VerifyNumber(lat);
1469
+ this.lon = VerifyNumber(lon);
1470
+ this.dist = VerifyNumber(dist);
1471
+ }
1472
+ };
1473
+ var EquatorialCoordinates = class {
1474
+ constructor(ra, dec, dist, vec) {
1475
+ this.ra = VerifyNumber(ra);
1476
+ this.dec = VerifyNumber(dec);
1477
+ this.dist = VerifyNumber(dist);
1478
+ this.vec = vec;
1479
+ }
1480
+ };
1481
+ var RotationMatrix = class {
1482
+ constructor(rot) {
1483
+ this.rot = rot;
1484
+ }
1485
+ };
1486
+ var HorizontalCoordinates = class {
1487
+ constructor(azimuth, altitude, ra, dec) {
1488
+ this.azimuth = VerifyNumber(azimuth);
1489
+ this.altitude = VerifyNumber(altitude);
1490
+ this.ra = VerifyNumber(ra);
1491
+ this.dec = VerifyNumber(dec);
1492
+ }
1493
+ };
1494
+ var EclipticCoordinates = class {
1495
+ constructor(vec, elat, elon) {
1496
+ this.vec = vec;
1497
+ this.elat = VerifyNumber(elat);
1498
+ this.elon = VerifyNumber(elon);
1499
+ }
1500
+ };
1501
+ function VectorFromArray(av, time) {
1502
+ return new Vector(av[0], av[1], av[2], time);
1503
+ }
1504
+ function vector2radec(pos, time) {
1505
+ const vec = VectorFromArray(pos, time);
1506
+ const xyproj = vec.x * vec.x + vec.y * vec.y;
1507
+ const dist = Math.sqrt(xyproj + vec.z * vec.z);
1508
+ if (xyproj === 0) {
1509
+ if (vec.z === 0)
1510
+ throw "Indeterminate sky coordinates";
1511
+ return new EquatorialCoordinates(0, vec.z < 0 ? -90 : 90, dist, vec);
1512
+ }
1513
+ let ra = RAD2HOUR * Math.atan2(vec.y, vec.x);
1514
+ if (ra < 0)
1515
+ ra += 24;
1516
+ const dec = RAD2DEG * Math.atan2(pos[2], Math.sqrt(xyproj));
1517
+ return new EquatorialCoordinates(ra, dec, dist, vec);
1518
+ }
1519
+ function spin(angle, pos) {
1520
+ const angr = angle * DEG2RAD;
1521
+ const c = Math.cos(angr);
1522
+ const s = Math.sin(angr);
1523
+ return [c * pos[0] + s * pos[1], c * pos[1] - s * pos[0], pos[2]];
1524
+ }
1525
+ function Horizon(date, observer, ra, dec, refraction) {
1526
+ let time = MakeTime(date);
1527
+ VerifyObserver(observer);
1528
+ VerifyNumber(ra);
1529
+ VerifyNumber(dec);
1530
+ const sinlat = Math.sin(observer.latitude * DEG2RAD);
1531
+ const coslat = Math.cos(observer.latitude * DEG2RAD);
1532
+ const sinlon = Math.sin(observer.longitude * DEG2RAD);
1533
+ const coslon = Math.cos(observer.longitude * DEG2RAD);
1534
+ const sindc = Math.sin(dec * DEG2RAD);
1535
+ const cosdc = Math.cos(dec * DEG2RAD);
1536
+ const sinra = Math.sin(ra * HOUR2RAD);
1537
+ const cosra = Math.cos(ra * HOUR2RAD);
1538
+ let uze = [coslat * coslon, coslat * sinlon, sinlat];
1539
+ let une = [-sinlat * coslon, -sinlat * sinlon, coslat];
1540
+ let uwe = [sinlon, -coslon, 0];
1541
+ const spin_angle = -15 * sidereal_time(time);
1542
+ let uz = spin(spin_angle, uze);
1543
+ let un = spin(spin_angle, une);
1544
+ let uw = spin(spin_angle, uwe);
1545
+ let p = [cosdc * cosra, cosdc * sinra, sindc];
1546
+ const pz = p[0] * uz[0] + p[1] * uz[1] + p[2] * uz[2];
1547
+ const pn = p[0] * un[0] + p[1] * un[1] + p[2] * un[2];
1548
+ const pw = p[0] * uw[0] + p[1] * uw[1] + p[2] * uw[2];
1549
+ let proj = Math.hypot(pn, pw);
1550
+ let az;
1551
+ if (proj > 0) {
1552
+ az = -RAD2DEG * Math.atan2(pw, pn);
1553
+ if (az < 0)
1554
+ az += 360;
1555
+ } else {
1556
+ az = 0;
1557
+ }
1558
+ let zd = RAD2DEG * Math.atan2(proj, pz);
1559
+ let out_ra = ra;
1560
+ let out_dec = dec;
1561
+ return new HorizontalCoordinates(az, 90 - zd, out_ra, out_dec);
1562
+ }
1563
+ function VerifyObserver(observer) {
1564
+ if (!(observer instanceof Observer)) {
1565
+ throw `Not an instance of the Observer class: ${observer}`;
1566
+ }
1567
+ VerifyNumber(observer.latitude);
1568
+ VerifyNumber(observer.longitude);
1569
+ VerifyNumber(observer.height);
1570
+ if (observer.latitude < -90 || observer.latitude > 90) {
1571
+ throw `Latitude ${observer.latitude} is out of range. Must be -90..+90.`;
1572
+ }
1573
+ return observer;
1574
+ }
1575
+ var Observer = class {
1576
+ constructor(latitude, longitude, height) {
1577
+ this.latitude = latitude;
1578
+ this.longitude = longitude;
1579
+ this.height = height;
1580
+ VerifyObserver(this);
1581
+ }
1582
+ };
1583
+ function SunPosition(date) {
1584
+ const time = MakeTime(date).AddDays(-1 / C_AUDAY);
1585
+ const earth2000 = CalcVsop(vsop.Earth, time);
1586
+ const sun2000 = [-earth2000.x, -earth2000.y, -earth2000.z];
1587
+ const [gx, gy, gz] = gyration(sun2000, time, PrecessDirection.From2000);
1588
+ const true_obliq = DEG2RAD * e_tilt(time).tobl;
1589
+ const cos_ob = Math.cos(true_obliq);
1590
+ const sin_ob = Math.sin(true_obliq);
1591
+ const vec = new Vector(gx, gy, gz, time);
1592
+ const sun_ecliptic = RotateEquatorialToEcliptic(vec, cos_ob, sin_ob);
1593
+ return sun_ecliptic;
1594
+ }
1595
+ function Equator(body, date, observer, ofdate, aberration) {
1596
+ VerifyObserver(observer);
1597
+ const time = MakeTime(date);
1598
+ const gc_observer = geo_pos(time, observer);
1599
+ const gc = GeoVector(body, time, aberration);
1600
+ const j2000 = [
1601
+ gc.x - gc_observer[0],
1602
+ gc.y - gc_observer[1],
1603
+ gc.z - gc_observer[2]
1604
+ ];
1605
+ const datevect = gyration(j2000, time, PrecessDirection.From2000);
1606
+ return vector2radec(datevect, time);
1607
+ }
1608
+ function RotateEquatorialToEcliptic(equ, cos_ob, sin_ob) {
1609
+ const ex = equ.x;
1610
+ const ey = equ.y * cos_ob + equ.z * sin_ob;
1611
+ const ez = -equ.y * sin_ob + equ.z * cos_ob;
1612
+ const xyproj = Math.hypot(ex, ey);
1613
+ let elon = 0;
1614
+ if (xyproj > 0) {
1615
+ elon = RAD2DEG * Math.atan2(ey, ex);
1616
+ if (elon < 0)
1617
+ elon += 360;
1618
+ }
1619
+ let elat = RAD2DEG * Math.atan2(ez, xyproj);
1620
+ let ecl = new Vector(ex, ey, ez, equ.t);
1621
+ return new EclipticCoordinates(ecl, elat, elon);
1622
+ }
1623
+ function Ecliptic(eqj) {
1624
+ const et = e_tilt(eqj.t);
1625
+ const eqj_pos = [eqj.x, eqj.y, eqj.z];
1626
+ const mean_pos = precession(eqj_pos, eqj.t, PrecessDirection.From2000);
1627
+ const [x, y, z] = nutation(mean_pos, eqj.t, PrecessDirection.From2000);
1628
+ const eqd = new Vector(x, y, z, eqj.t);
1629
+ const tobl = et.tobl * DEG2RAD;
1630
+ return RotateEquatorialToEcliptic(eqd, Math.cos(tobl), Math.sin(tobl));
1631
+ }
1632
+ function GeoMoon(date) {
1633
+ const time = MakeTime(date);
1634
+ const moon = CalcMoon(time);
1635
+ const dist_cos_lat = moon.distance_au * Math.cos(moon.geo_eclip_lat);
1636
+ const gepos = [
1637
+ dist_cos_lat * Math.cos(moon.geo_eclip_lon),
1638
+ dist_cos_lat * Math.sin(moon.geo_eclip_lon),
1639
+ moon.distance_au * Math.sin(moon.geo_eclip_lat)
1640
+ ];
1641
+ const mpos1 = ecl2equ_vec(time, gepos);
1642
+ const mpos2 = precession(mpos1, time, PrecessDirection.Into2000);
1643
+ return new Vector(mpos2[0], mpos2[1], mpos2[2], time);
1644
+ }
1645
+ function GeoMoonState(date) {
1646
+ const time = MakeTime(date);
1647
+ const dt = 1e-5;
1648
+ const t1 = time.AddDays(-dt);
1649
+ const t2 = time.AddDays(+dt);
1650
+ const r1 = GeoMoon(t1);
1651
+ const r2 = GeoMoon(t2);
1652
+ return new StateVector((r1.x + r2.x) / 2, (r1.y + r2.y) / 2, (r1.z + r2.z) / 2, (r2.x - r1.x) / (2 * dt), (r2.y - r1.y) / (2 * dt), (r2.z - r1.z) / (2 * dt), time);
1653
+ }
1654
+ function GeoEmbState(date) {
1655
+ const time = MakeTime(date);
1656
+ const s = GeoMoonState(time);
1657
+ const d = 1 + EARTH_MOON_MASS_RATIO;
1658
+ return new StateVector(s.x / d, s.y / d, s.z / d, s.vx / d, s.vy / d, s.vz / d, time);
1659
+ }
1660
+ function VsopFormula(formula, t, clamp_angle) {
1661
+ let tpower = 1;
1662
+ let coord = 0;
1663
+ for (let series of formula) {
1664
+ let sum = 0;
1665
+ for (let [ampl, phas, freq] of series)
1666
+ sum += ampl * Math.cos(phas + t * freq);
1667
+ let incr = tpower * sum;
1668
+ if (clamp_angle)
1669
+ incr %= PI2;
1670
+ coord += incr;
1671
+ tpower *= t;
1672
+ }
1673
+ return coord;
1674
+ }
1675
+ function VsopDeriv(formula, t) {
1676
+ let tpower = 1;
1677
+ let dpower = 0;
1678
+ let deriv = 0;
1679
+ let s = 0;
1680
+ for (let series of formula) {
1681
+ let sin_sum = 0;
1682
+ let cos_sum = 0;
1683
+ for (let [ampl, phas, freq] of series) {
1684
+ let angle = phas + t * freq;
1685
+ sin_sum += ampl * freq * Math.sin(angle);
1686
+ if (s > 0)
1687
+ cos_sum += ampl * Math.cos(angle);
1688
+ }
1689
+ deriv += s * dpower * cos_sum - tpower * sin_sum;
1690
+ dpower = tpower;
1691
+ tpower *= t;
1692
+ ++s;
1693
+ }
1694
+ return deriv;
1695
+ }
1696
+ var DAYS_PER_MILLENNIUM = 365250;
1697
+ var LON_INDEX = 0;
1698
+ var LAT_INDEX = 1;
1699
+ var RAD_INDEX = 2;
1700
+ function VsopRotate(eclip) {
1701
+ return new TerseVector(eclip[0] + 44036e-11 * eclip[1] - 190919e-12 * eclip[2], -4.79966e-7 * eclip[0] + 0.917482137087 * eclip[1] - 0.397776982902 * eclip[2], 0.397776982902 * eclip[1] + 0.917482137087 * eclip[2]);
1702
+ }
1703
+ function VsopSphereToRect(lon, lat, radius) {
1704
+ const r_coslat = radius * Math.cos(lat);
1705
+ const coslon = Math.cos(lon);
1706
+ const sinlon = Math.sin(lon);
1707
+ return [
1708
+ r_coslat * coslon,
1709
+ r_coslat * sinlon,
1710
+ radius * Math.sin(lat)
1711
+ ];
1712
+ }
1713
+ function CalcVsop(model, time) {
1714
+ const t = time.tt / DAYS_PER_MILLENNIUM;
1715
+ const lon = VsopFormula(model[LON_INDEX], t, true);
1716
+ const lat = VsopFormula(model[LAT_INDEX], t, false);
1717
+ const rad = VsopFormula(model[RAD_INDEX], t, false);
1718
+ const eclip = VsopSphereToRect(lon, lat, rad);
1719
+ return VsopRotate(eclip).ToAstroVector(time);
1720
+ }
1721
+ function CalcVsopPosVel(model, tt) {
1722
+ const t = tt / DAYS_PER_MILLENNIUM;
1723
+ const lon = VsopFormula(model[LON_INDEX], t, true);
1724
+ const lat = VsopFormula(model[LAT_INDEX], t, false);
1725
+ const rad = VsopFormula(model[RAD_INDEX], t, false);
1726
+ const dlon_dt = VsopDeriv(model[LON_INDEX], t);
1727
+ const dlat_dt = VsopDeriv(model[LAT_INDEX], t);
1728
+ const drad_dt = VsopDeriv(model[RAD_INDEX], t);
1729
+ const coslon = Math.cos(lon);
1730
+ const sinlon = Math.sin(lon);
1731
+ const coslat = Math.cos(lat);
1732
+ const sinlat = Math.sin(lat);
1733
+ const vx = +(drad_dt * coslat * coslon) - rad * sinlat * coslon * dlat_dt - rad * coslat * sinlon * dlon_dt;
1734
+ const vy = +(drad_dt * coslat * sinlon) - rad * sinlat * sinlon * dlat_dt + rad * coslat * coslon * dlon_dt;
1735
+ const vz = +(drad_dt * sinlat) + rad * coslat * dlat_dt;
1736
+ const eclip_pos = VsopSphereToRect(lon, lat, rad);
1737
+ const eclip_vel = [
1738
+ vx / DAYS_PER_MILLENNIUM,
1739
+ vy / DAYS_PER_MILLENNIUM,
1740
+ vz / DAYS_PER_MILLENNIUM
1741
+ ];
1742
+ const equ_pos = VsopRotate(eclip_pos);
1743
+ const equ_vel = VsopRotate(eclip_vel);
1744
+ return new body_state_t(tt, equ_pos, equ_vel);
1745
+ }
1746
+ function AdjustBarycenter(ssb, time, body, pmass) {
1747
+ const shift = pmass / (pmass + SUN_GM);
1748
+ const planet = CalcVsop(vsop[body], time);
1749
+ ssb.x += shift * planet.x;
1750
+ ssb.y += shift * planet.y;
1751
+ ssb.z += shift * planet.z;
1752
+ }
1753
+ function CalcSolarSystemBarycenter(time) {
1754
+ const ssb = new Vector(0, 0, 0, time);
1755
+ AdjustBarycenter(ssb, time, Body.Jupiter, JUPITER_GM);
1756
+ AdjustBarycenter(ssb, time, Body.Saturn, SATURN_GM);
1757
+ AdjustBarycenter(ssb, time, Body.Uranus, URANUS_GM);
1758
+ AdjustBarycenter(ssb, time, Body.Neptune, NEPTUNE_GM);
1759
+ return ssb;
1760
+ }
1761
+ var PLUTO_NUM_STATES = 51;
1762
+ var PLUTO_TIME_STEP = 29200;
1763
+ var PLUTO_DT = 146;
1764
+ var PLUTO_NSTEPS = 201;
1765
+ var PlutoStateTable = [
1766
+ [-73e4, [-26.118207232108, -14.376168177825, 3.384402515299], [0.0016339372163656, -0.0027861699588508, -0.0013585880229445]],
1767
+ [-700800, [41.974905202127, -0.448502952929, -12.770351505989], [73458569351457e-17, 0.0022785014891658, 48619778602049e-17]],
1768
+ [-671600, [14.706930780744, 44.269110540027, 9.353698474772], [-0.00210001479998, 22295915939915e-17, 70143443551414e-17]],
1769
+ [-642400, [-29.441003929957, -6.43016153057, 6.858481011305], [84495803960544e-17, -0.0030783914758711, -0.0012106305981192]],
1770
+ [-613200, [39.444396946234, -6.557989760571, -13.913760296463], [0.0011480029005873, 0.0022400006880665, 35168075922288e-17]],
1771
+ [-584e3, [20.2303809507, 43.266966657189, 7.382966091923], [-0.0019754081700585, 53457141292226e-17, 75929169129793e-17]],
1772
+ [-554800, [-30.65832536462, 2.093818874552, 9.880531138071], [61010603013347e-18, -0.0031326500935382, -99346125151067e-17]],
1773
+ [-525600, [35.737703251673, -12.587706024764, -14.677847247563], [0.0015802939375649, 0.0021347678412429, 19074436384343e-17]],
1774
+ [-496400, [25.466295188546, 41.367478338417, 5.216476873382], [-0.0018054401046468, 8328308359951e-16, 80260156912107e-17]],
1775
+ [-467200, [-29.847174904071, 10.636426313081, 12.297904180106], [-63257063052907e-17, -0.0029969577578221, -74476074151596e-17]],
1776
+ [-438e3, [30.774692107687, -18.236637015304, -14.945535879896], [0.0020113162005465, 0.0019353827024189, -20937793168297e-19]],
1777
+ [-408800, [30.243153324028, 38.656267888503, 2.938501750218], [-0.0016052508674468, 0.0011183495337525, 83333973416824e-17]],
1778
+ [-379600, [-27.288984772533, 18.643162147874, 14.023633623329], [-0.0011856388898191, -0.0027170609282181, -49015526126399e-17]],
1779
+ [-350400, [24.519605196774, -23.245756064727, -14.626862367368], [0.0024322321483154, 0.0016062008146048, -23369181613312e-17]],
1780
+ [-321200, [34.505274805875, 35.125338586954, 0.557361475637], [-0.0013824391637782, 0.0013833397561817, 84823598806262e-17]],
1781
+ [-292e3, [-23.275363915119, 25.818514298769, 15.055381588598], [-0.0016062295460975, -0.0023395961498533, -24377362639479e-17]],
1782
+ [-262800, [17.050384798092, -27.180376290126, -13.608963321694], [0.0028175521080578, 0.0011358749093955, -49548725258825e-17]],
1783
+ [-233600, [38.093671910285, 30.880588383337, -1.843688067413], [-0.0011317697153459, 0.0016128814698472, 84177586176055e-17]],
1784
+ [-204400, [-18.197852930878, 31.932869934309, 15.438294826279], [-0.0019117272501813, -0.0019146495909842, -19657304369835e-18]],
1785
+ [-175200, [8.528924039997, -29.618422200048, -11.805400994258], [0.0031034370787005, 5139363329243e-16, -77293066202546e-17]],
1786
+ [-146e3, [40.94685725864, 25.904973592021, -4.256336240499], [-83652705194051e-17, 0.0018129497136404, 8156422827306e-16]],
1787
+ [-116800, [-12.326958895325, 36.881883446292, 15.217158258711], [-0.0021166103705038, -0.001481442003599, 17401209844705e-17]],
1788
+ [-87600, [-0.633258375909, -30.018759794709, -9.17193287495], [0.0032016994581737, -25279858672148e-17, -0.0010411088271861]],
1789
+ [-58400, [42.936048423883, 20.344685584452, -6.588027007912], [-50525450073192e-17, 0.0019910074335507, 77440196540269e-17]],
1790
+ [-29200, [-5.975910552974, 40.61180995846, 14.470131723673], [-0.0022184202156107, -0.0010562361130164, 33652250216211e-17]],
1791
+ [0, [-9.875369580774, -27.978926224737, -5.753711824704], [0.0030287533248818, -0.0011276087003636, -0.0012651326732361]],
1792
+ [29200, [43.958831986165, 14.214147973292, -8.808306227163], [-14717608981871e-17, 0.0021404187242141, 71486567806614e-17]],
1793
+ [58400, [0.67813676352, 43.094461639362, 13.243238780721], [-0.0022358226110718, -63233636090933e-17, 47664798895648e-17]],
1794
+ [87600, [-18.282602096834, -23.30503958666, -1.766620508028], [0.0025567245263557, -0.0019902940754171, -0.0013943491701082]],
1795
+ [116800, [43.873338744526, 7.700705617215, -10.814273666425], [23174803055677e-17, 0.0022402163127924, 62988756452032e-17]],
1796
+ [146e3, [7.392949027906, 44.382678951534, 11.629500214854], [-0.002193281545383, -21751799585364e-17, 59556516201114e-17]],
1797
+ [175200, [-24.981690229261, -16.204012851426, 2.466457544298], [0.001819398914958, -0.0026765419531201, -0.0013848283502247]],
1798
+ [204400, [42.530187039511, 0.845935508021, -12.554907527683], [65059779150669e-17, 0.0022725657282262, 51133743202822e-17]],
1799
+ [233600, [13.999526486822, 44.462363044894, 9.669418486465], [-0.0021079296569252, 17533423831993e-17, 69128485798076e-17]],
1800
+ [262800, [-29.184024803031, -7.371243995762, 6.493275957928], [93581363109681e-17, -0.0030610357109184, -0.0012364201089345]],
1801
+ [292e3, [39.831980671753, -6.078405766765, -13.909815358656], [0.0011117769689167, 0.0022362097830152, 36230548231153e-17]],
1802
+ [321200, [20.294955108476, 43.417190420251, 7.450091985932], [-0.0019742157451535, 53102050468554e-17, 75938408813008e-17]],
1803
+ [350400, [-30.66999230216, 2.318743558955, 9.973480913858], [45605107450676e-18, -0.0031308219926928, -99066533301924e-17]],
1804
+ [379600, [35.626122155983, -12.897647509224, -14.777586508444], [0.0016015684949743, 0.0021171931182284, 18002516202204e-17]],
1805
+ [408800, [26.133186148561, 41.232139187599, 5.00640132622], [-0.0017857704419579, 86046232702817e-17, 80614690298954e-17]],
1806
+ [438e3, [-29.57674022923, 11.863535943587, 12.631323039872], [-72292830060955e-17, -0.0029587820140709, -708242964503e-15]],
1807
+ [467200, [29.910805787391, -19.159019294, -15.013363865194], [0.0020871080437997, 0.0018848372554514, -38528655083926e-18]],
1808
+ [496400, [31.375957451819, 38.050372720763, 2.433138343754], [-0.0015546055556611, 0.0011699815465629, 83565439266001e-17]],
1809
+ [525600, [-26.360071336928, 20.662505904952, 14.414696258958], [-0.0013142373118349, -0.0026236647854842, -42542017598193e-17]],
1810
+ [554800, [22.599441488648, -24.508879898306, -14.484045731468], [0.0025454108304806, 0.0014917058755191, -30243665086079e-17]],
1811
+ [584e3, [35.877864013014, 33.894226366071, -0.224524636277], [-0.0012941245730845, 0.0014560427668319, 84762160640137e-17]],
1812
+ [613200, [-21.538149762417, 28.204068269761, 15.321973799534], [-0.001731211740901, -0.0021939631314577, -1631691327518e-16]],
1813
+ [642400, [13.971521374415, -28.339941764789, -13.083792871886], [0.0029334630526035, 91860931752944e-17, -59939422488627e-17]],
1814
+ [671600, [39.526942044143, 28.93989736011, -2.872799527539], [-0.0010068481658095, 0.001702113288809, 83578230511981e-17]],
1815
+ [700800, [-15.576200701394, 34.399412961275, 15.466033737854], [-0.0020098814612884, -0.0017191109825989, 70414782780416e-18]],
1816
+ [73e4, [4.24325283709, -30.118201690825, -10.707441231349], [0.0031725847067411, 1609846120227e-16, -90672150593868e-17]]
1817
+ ];
1818
+ var TerseVector = class _TerseVector {
1819
+ constructor(x, y, z) {
1820
+ this.x = x;
1821
+ this.y = y;
1822
+ this.z = z;
1823
+ }
1824
+ clone() {
1825
+ return new _TerseVector(this.x, this.y, this.z);
1826
+ }
1827
+ ToAstroVector(t) {
1828
+ return new Vector(this.x, this.y, this.z, t);
1829
+ }
1830
+ static zero() {
1831
+ return new _TerseVector(0, 0, 0);
1832
+ }
1833
+ quadrature() {
1834
+ return this.x * this.x + this.y * this.y + this.z * this.z;
1835
+ }
1836
+ add(other) {
1837
+ return new _TerseVector(this.x + other.x, this.y + other.y, this.z + other.z);
1838
+ }
1839
+ sub(other) {
1840
+ return new _TerseVector(this.x - other.x, this.y - other.y, this.z - other.z);
1841
+ }
1842
+ incr(other) {
1843
+ this.x += other.x;
1844
+ this.y += other.y;
1845
+ this.z += other.z;
1846
+ }
1847
+ decr(other) {
1848
+ this.x -= other.x;
1849
+ this.y -= other.y;
1850
+ this.z -= other.z;
1851
+ }
1852
+ mul(scalar) {
1853
+ return new _TerseVector(scalar * this.x, scalar * this.y, scalar * this.z);
1854
+ }
1855
+ div(scalar) {
1856
+ return new _TerseVector(this.x / scalar, this.y / scalar, this.z / scalar);
1857
+ }
1858
+ mean(other) {
1859
+ return new _TerseVector((this.x + other.x) / 2, (this.y + other.y) / 2, (this.z + other.z) / 2);
1860
+ }
1861
+ neg() {
1862
+ return new _TerseVector(-this.x, -this.y, -this.z);
1863
+ }
1864
+ };
1865
+ var body_state_t = class _body_state_t {
1866
+ constructor(tt, r, v) {
1867
+ this.tt = tt;
1868
+ this.r = r;
1869
+ this.v = v;
1870
+ }
1871
+ clone() {
1872
+ return new _body_state_t(this.tt, this.r, this.v);
1873
+ }
1874
+ sub(other) {
1875
+ return new _body_state_t(this.tt, this.r.sub(other.r), this.v.sub(other.v));
1876
+ }
1877
+ };
1878
+ function BodyStateFromTable(entry) {
1879
+ let [tt, [rx, ry, rz], [vx, vy, vz]] = entry;
1880
+ return new body_state_t(tt, new TerseVector(rx, ry, rz), new TerseVector(vx, vy, vz));
1881
+ }
1882
+ function AdjustBarycenterPosVel(ssb, tt, body, planet_gm) {
1883
+ const shift = planet_gm / (planet_gm + SUN_GM);
1884
+ const planet = CalcVsopPosVel(vsop[body], tt);
1885
+ ssb.r.incr(planet.r.mul(shift));
1886
+ ssb.v.incr(planet.v.mul(shift));
1887
+ return planet;
1888
+ }
1889
+ function AccelerationIncrement(small_pos, gm, major_pos) {
1890
+ const delta = major_pos.sub(small_pos);
1891
+ const r2 = delta.quadrature();
1892
+ return delta.mul(gm / (r2 * Math.sqrt(r2)));
1893
+ }
1894
+ var major_bodies_t = class {
1895
+ constructor(tt) {
1896
+ let ssb = new body_state_t(tt, new TerseVector(0, 0, 0), new TerseVector(0, 0, 0));
1897
+ this.Jupiter = AdjustBarycenterPosVel(ssb, tt, Body.Jupiter, JUPITER_GM);
1898
+ this.Saturn = AdjustBarycenterPosVel(ssb, tt, Body.Saturn, SATURN_GM);
1899
+ this.Uranus = AdjustBarycenterPosVel(ssb, tt, Body.Uranus, URANUS_GM);
1900
+ this.Neptune = AdjustBarycenterPosVel(ssb, tt, Body.Neptune, NEPTUNE_GM);
1901
+ this.Jupiter.r.decr(ssb.r);
1902
+ this.Jupiter.v.decr(ssb.v);
1903
+ this.Saturn.r.decr(ssb.r);
1904
+ this.Saturn.v.decr(ssb.v);
1905
+ this.Uranus.r.decr(ssb.r);
1906
+ this.Uranus.v.decr(ssb.v);
1907
+ this.Neptune.r.decr(ssb.r);
1908
+ this.Neptune.v.decr(ssb.v);
1909
+ this.Sun = new body_state_t(tt, ssb.r.mul(-1), ssb.v.mul(-1));
1910
+ }
1911
+ Acceleration(pos) {
1912
+ let acc = AccelerationIncrement(pos, SUN_GM, this.Sun.r);
1913
+ acc.incr(AccelerationIncrement(pos, JUPITER_GM, this.Jupiter.r));
1914
+ acc.incr(AccelerationIncrement(pos, SATURN_GM, this.Saturn.r));
1915
+ acc.incr(AccelerationIncrement(pos, URANUS_GM, this.Uranus.r));
1916
+ acc.incr(AccelerationIncrement(pos, NEPTUNE_GM, this.Neptune.r));
1917
+ return acc;
1918
+ }
1919
+ };
1920
+ var body_grav_calc_t = class _body_grav_calc_t {
1921
+ constructor(tt, r, v, a) {
1922
+ this.tt = tt;
1923
+ this.r = r;
1924
+ this.v = v;
1925
+ this.a = a;
1926
+ }
1927
+ clone() {
1928
+ return new _body_grav_calc_t(this.tt, this.r.clone(), this.v.clone(), this.a.clone());
1929
+ }
1930
+ };
1931
+ var grav_sim_t = class {
1932
+ constructor(bary, grav) {
1933
+ this.bary = bary;
1934
+ this.grav = grav;
1935
+ }
1936
+ };
1937
+ function UpdatePosition(dt, r, v, a) {
1938
+ return new TerseVector(r.x + dt * (v.x + dt * a.x / 2), r.y + dt * (v.y + dt * a.y / 2), r.z + dt * (v.z + dt * a.z / 2));
1939
+ }
1940
+ function UpdateVelocity(dt, v, a) {
1941
+ return new TerseVector(v.x + dt * a.x, v.y + dt * a.y, v.z + dt * a.z);
1942
+ }
1943
+ function GravSim(tt2, calc1) {
1944
+ const dt = tt2 - calc1.tt;
1945
+ const bary2 = new major_bodies_t(tt2);
1946
+ const approx_pos = UpdatePosition(dt, calc1.r, calc1.v, calc1.a);
1947
+ const mean_acc = bary2.Acceleration(approx_pos).mean(calc1.a);
1948
+ const pos = UpdatePosition(dt, calc1.r, calc1.v, mean_acc);
1949
+ const vel = calc1.v.add(mean_acc.mul(dt));
1950
+ const acc = bary2.Acceleration(pos);
1951
+ const grav = new body_grav_calc_t(tt2, pos, vel, acc);
1952
+ return new grav_sim_t(bary2, grav);
1953
+ }
1954
+ var pluto_cache = [];
1955
+ function ClampIndex(frac, nsteps) {
1956
+ const index = Math.floor(frac);
1957
+ if (index < 0)
1958
+ return 0;
1959
+ if (index >= nsteps)
1960
+ return nsteps - 1;
1961
+ return index;
1962
+ }
1963
+ function GravFromState(entry) {
1964
+ const state = BodyStateFromTable(entry);
1965
+ const bary = new major_bodies_t(state.tt);
1966
+ const r = state.r.add(bary.Sun.r);
1967
+ const v = state.v.add(bary.Sun.v);
1968
+ const a = bary.Acceleration(r);
1969
+ const grav = new body_grav_calc_t(state.tt, r, v, a);
1970
+ return new grav_sim_t(bary, grav);
1971
+ }
1972
+ function GetSegment(cache, tt) {
1973
+ const t0 = PlutoStateTable[0][0];
1974
+ if (tt < t0 || tt > PlutoStateTable[PLUTO_NUM_STATES - 1][0]) {
1975
+ return null;
1976
+ }
1977
+ const seg_index = ClampIndex((tt - t0) / PLUTO_TIME_STEP, PLUTO_NUM_STATES - 1);
1978
+ if (!cache[seg_index]) {
1979
+ const seg = cache[seg_index] = [];
1980
+ seg[0] = GravFromState(PlutoStateTable[seg_index]).grav;
1981
+ seg[PLUTO_NSTEPS - 1] = GravFromState(PlutoStateTable[seg_index + 1]).grav;
1982
+ let i;
1983
+ let step_tt = seg[0].tt;
1984
+ for (i = 1; i < PLUTO_NSTEPS - 1; ++i)
1985
+ seg[i] = GravSim(step_tt += PLUTO_DT, seg[i - 1]).grav;
1986
+ step_tt = seg[PLUTO_NSTEPS - 1].tt;
1987
+ var reverse = [];
1988
+ reverse[PLUTO_NSTEPS - 1] = seg[PLUTO_NSTEPS - 1];
1989
+ for (i = PLUTO_NSTEPS - 2; i > 0; --i)
1990
+ reverse[i] = GravSim(step_tt -= PLUTO_DT, reverse[i + 1]).grav;
1991
+ for (i = PLUTO_NSTEPS - 2; i > 0; --i) {
1992
+ const ramp = i / (PLUTO_NSTEPS - 1);
1993
+ seg[i].r = seg[i].r.mul(1 - ramp).add(reverse[i].r.mul(ramp));
1994
+ seg[i].v = seg[i].v.mul(1 - ramp).add(reverse[i].v.mul(ramp));
1995
+ seg[i].a = seg[i].a.mul(1 - ramp).add(reverse[i].a.mul(ramp));
1996
+ }
1997
+ }
1998
+ return cache[seg_index];
1999
+ }
2000
+ function CalcPlutoOneWay(entry, target_tt, dt) {
2001
+ let sim = GravFromState(entry);
2002
+ const n = Math.ceil((target_tt - sim.grav.tt) / dt);
2003
+ for (let i = 0; i < n; ++i)
2004
+ sim = GravSim(i + 1 === n ? target_tt : sim.grav.tt + dt, sim.grav);
2005
+ return sim;
2006
+ }
2007
+ function CalcPluto(time, helio) {
2008
+ let r, v, bary;
2009
+ const seg = GetSegment(pluto_cache, time.tt);
2010
+ if (!seg) {
2011
+ let sim;
2012
+ if (time.tt < PlutoStateTable[0][0])
2013
+ sim = CalcPlutoOneWay(PlutoStateTable[0], time.tt, -PLUTO_DT);
2014
+ else
2015
+ sim = CalcPlutoOneWay(PlutoStateTable[PLUTO_NUM_STATES - 1], time.tt, +PLUTO_DT);
2016
+ r = sim.grav.r;
2017
+ v = sim.grav.v;
2018
+ bary = sim.bary;
2019
+ } else {
2020
+ const left = ClampIndex((time.tt - seg[0].tt) / PLUTO_DT, PLUTO_NSTEPS - 1);
2021
+ const s1 = seg[left];
2022
+ const s2 = seg[left + 1];
2023
+ const acc = s1.a.mean(s2.a);
2024
+ const ra = UpdatePosition(time.tt - s1.tt, s1.r, s1.v, acc);
2025
+ const va = UpdateVelocity(time.tt - s1.tt, s1.v, acc);
2026
+ const rb = UpdatePosition(time.tt - s2.tt, s2.r, s2.v, acc);
2027
+ const vb = UpdateVelocity(time.tt - s2.tt, s2.v, acc);
2028
+ const ramp = (time.tt - s1.tt) / PLUTO_DT;
2029
+ r = ra.mul(1 - ramp).add(rb.mul(ramp));
2030
+ v = va.mul(1 - ramp).add(vb.mul(ramp));
2031
+ }
2032
+ {
2033
+ if (!bary)
2034
+ bary = new major_bodies_t(time.tt);
2035
+ r = r.sub(bary.Sun.r);
2036
+ v = v.sub(bary.Sun.v);
2037
+ }
2038
+ return new StateVector(r.x, r.y, r.z, v.x, v.y, v.z, time);
2039
+ }
2040
+ function HelioVector(body, date) {
2041
+ var time = MakeTime(date);
2042
+ if (body in vsop)
2043
+ return CalcVsop(vsop[body], time);
2044
+ if (body === Body.Pluto) {
2045
+ const p = CalcPluto(time);
2046
+ return new Vector(p.x, p.y, p.z, time);
2047
+ }
2048
+ if (body === Body.Sun)
2049
+ return new Vector(0, 0, 0, time);
2050
+ if (body === Body.Moon) {
2051
+ var e = CalcVsop(vsop.Earth, time);
2052
+ var m = GeoMoon(time);
2053
+ return new Vector(e.x + m.x, e.y + m.y, e.z + m.z, time);
2054
+ }
2055
+ if (body === Body.EMB) {
2056
+ const e2 = CalcVsop(vsop.Earth, time);
2057
+ const m2 = GeoMoon(time);
2058
+ const denom = 1 + EARTH_MOON_MASS_RATIO;
2059
+ return new Vector(e2.x + m2.x / denom, e2.y + m2.y / denom, e2.z + m2.z / denom, time);
2060
+ }
2061
+ if (body === Body.SSB)
2062
+ return CalcSolarSystemBarycenter(time);
2063
+ const star = UserDefinedStar(body);
2064
+ if (star) {
2065
+ const sphere = new Spherical(star.dec, 15 * star.ra, star.dist);
2066
+ return VectorFromSphere(sphere, time);
2067
+ }
2068
+ throw `HelioVector: Unknown body "${body}"`;
2069
+ }
2070
+ function CorrectLightTravel(func, time) {
2071
+ let ltime = time;
2072
+ let dt = 0;
2073
+ for (let iter = 0; iter < 10; ++iter) {
2074
+ const pos = func(ltime);
2075
+ const lt = pos.Length() / C_AUDAY;
2076
+ if (lt > 1)
2077
+ throw `Object is too distant for light-travel solver.`;
2078
+ const ltime2 = time.AddDays(-lt);
2079
+ dt = Math.abs(ltime2.tt - ltime.tt);
2080
+ if (dt < 1e-9)
2081
+ return pos;
2082
+ ltime = ltime2;
2083
+ }
2084
+ throw `Light-travel time solver did not converge: dt = ${dt}`;
2085
+ }
2086
+ var BodyPosition = class {
2087
+ constructor(observerBody, targetBody, aberration, observerPos) {
2088
+ this.observerBody = observerBody;
2089
+ this.targetBody = targetBody;
2090
+ this.aberration = aberration;
2091
+ this.observerPos = observerPos;
2092
+ }
2093
+ Position(time) {
2094
+ if (this.aberration) {
2095
+ this.observerPos = HelioVector(this.observerBody, time);
2096
+ }
2097
+ const targetPos = HelioVector(this.targetBody, time);
2098
+ return new Vector(targetPos.x - this.observerPos.x, targetPos.y - this.observerPos.y, targetPos.z - this.observerPos.z, time);
2099
+ }
2100
+ };
2101
+ function BackdatePosition(date, observerBody, targetBody, aberration) {
2102
+ const time = MakeTime(date);
2103
+ if (UserDefinedStar(targetBody)) {
2104
+ const tvec = HelioVector(targetBody, time);
2105
+ {
2106
+ const ostate = HelioState(observerBody, time);
2107
+ const rvec = new Vector(tvec.x - ostate.x, tvec.y - ostate.y, tvec.z - ostate.z, time);
2108
+ const s = C_AUDAY / rvec.Length();
2109
+ return new Vector(rvec.x + ostate.vx / s, rvec.y + ostate.vy / s, rvec.z + ostate.vz / s, time);
2110
+ }
2111
+ }
2112
+ let observerPos;
2113
+ {
2114
+ observerPos = new Vector(0, 0, 0, time);
2115
+ }
2116
+ const bpos = new BodyPosition(observerBody, targetBody, aberration, observerPos);
2117
+ return CorrectLightTravel((t) => bpos.Position(t), time);
2118
+ }
2119
+ function GeoVector(body, date, aberration) {
2120
+ const time = MakeTime(date);
2121
+ switch (body) {
2122
+ case Body.Earth:
2123
+ return new Vector(0, 0, 0, time);
2124
+ case Body.Moon:
2125
+ return GeoMoon(time);
2126
+ default:
2127
+ const vec = BackdatePosition(time, Body.Earth, body, aberration);
2128
+ vec.t = time;
2129
+ return vec;
2130
+ }
2131
+ }
2132
+ function ExportState(terse, time) {
2133
+ return new StateVector(terse.r.x, terse.r.y, terse.r.z, terse.v.x, terse.v.y, terse.v.z, time);
2134
+ }
2135
+ function HelioState(body, date) {
2136
+ const time = MakeTime(date);
2137
+ switch (body) {
2138
+ case Body.Sun:
2139
+ return new StateVector(0, 0, 0, 0, 0, 0, time);
2140
+ case Body.SSB:
2141
+ const bary = new major_bodies_t(time.tt);
2142
+ return new StateVector(-bary.Sun.r.x, -bary.Sun.r.y, -bary.Sun.r.z, -bary.Sun.v.x, -bary.Sun.v.y, -bary.Sun.v.z, time);
2143
+ case Body.Mercury:
2144
+ case Body.Venus:
2145
+ case Body.Earth:
2146
+ case Body.Mars:
2147
+ case Body.Jupiter:
2148
+ case Body.Saturn:
2149
+ case Body.Uranus:
2150
+ case Body.Neptune:
2151
+ const planet = CalcVsopPosVel(vsop[body], time.tt);
2152
+ return ExportState(planet, time);
2153
+ case Body.Pluto:
2154
+ return CalcPluto(time);
2155
+ case Body.Moon:
2156
+ case Body.EMB:
2157
+ const earth = CalcVsopPosVel(vsop.Earth, time.tt);
2158
+ const state = body == Body.Moon ? GeoMoonState(time) : GeoEmbState(time);
2159
+ return new StateVector(state.x + earth.r.x, state.y + earth.r.y, state.z + earth.r.z, state.vx + earth.v.x, state.vy + earth.v.y, state.vz + earth.v.z, time);
2160
+ default:
2161
+ if (UserDefinedStar(body)) {
2162
+ const vec = HelioVector(body, time);
2163
+ return new StateVector(vec.x, vec.y, vec.z, 0, 0, 0, time);
2164
+ }
2165
+ throw `HelioState: Unsupported body "${body}"`;
2166
+ }
2167
+ }
2168
+ function QuadInterp(tm, dt, fa, fm, fb) {
2169
+ let Q = (fb + fa) / 2 - fm;
2170
+ let R = (fb - fa) / 2;
2171
+ let S = fm;
2172
+ let x;
2173
+ if (Q == 0) {
2174
+ if (R == 0) {
2175
+ return null;
2176
+ }
2177
+ x = -S / R;
2178
+ if (x < -1 || x > 1)
2179
+ return null;
2180
+ } else {
2181
+ let u = R * R - 4 * Q * S;
2182
+ if (u <= 0)
2183
+ return null;
2184
+ let ru = Math.sqrt(u);
2185
+ let x1 = (-R + ru) / (2 * Q);
2186
+ let x2 = (-R - ru) / (2 * Q);
2187
+ if (-1 <= x1 && x1 <= 1) {
2188
+ if (-1 <= x2 && x2 <= 1)
2189
+ return null;
2190
+ x = x1;
2191
+ } else if (-1 <= x2 && x2 <= 1) {
2192
+ x = x2;
2193
+ } else {
2194
+ return null;
2195
+ }
2196
+ }
2197
+ let t = tm + x * dt;
2198
+ let df_dt = (2 * Q * x + R) / dt;
2199
+ return { t, df_dt };
2200
+ }
2201
+ function Search(f, t1, t2, options) {
2202
+ const dt_tolerance_seconds = VerifyNumber(options && options.dt_tolerance_seconds || 1);
2203
+ const dt_days = Math.abs(dt_tolerance_seconds / SECONDS_PER_DAY);
2204
+ let f1 = options && options.init_f1 || f(t1);
2205
+ let f2 = options && options.init_f2 || f(t2);
2206
+ let fmid = NaN;
2207
+ let iter = 0;
2208
+ let iter_limit = options && options.iter_limit || 20;
2209
+ let calc_fmid = true;
2210
+ while (true) {
2211
+ if (++iter > iter_limit)
2212
+ throw `Excessive iteration in Search()`;
2213
+ let tmid = InterpolateTime(t1, t2, 0.5);
2214
+ let dt = tmid.ut - t1.ut;
2215
+ if (Math.abs(dt) < dt_days) {
2216
+ return tmid;
2217
+ }
2218
+ if (calc_fmid)
2219
+ fmid = f(tmid);
2220
+ else
2221
+ calc_fmid = true;
2222
+ let q = QuadInterp(tmid.ut, t2.ut - tmid.ut, f1, fmid, f2);
2223
+ if (q) {
2224
+ let tq = MakeTime(q.t);
2225
+ let fq = f(tq);
2226
+ if (q.df_dt !== 0) {
2227
+ if (Math.abs(fq / q.df_dt) < dt_days) {
2228
+ return tq;
2229
+ }
2230
+ let dt_guess = 1.2 * Math.abs(fq / q.df_dt);
2231
+ if (dt_guess < dt / 10) {
2232
+ let tleft = tq.AddDays(-dt_guess);
2233
+ let tright = tq.AddDays(+dt_guess);
2234
+ if ((tleft.ut - t1.ut) * (tleft.ut - t2.ut) < 0) {
2235
+ if ((tright.ut - t1.ut) * (tright.ut - t2.ut) < 0) {
2236
+ let fleft = f(tleft);
2237
+ let fright = f(tright);
2238
+ if (fleft < 0 && fright >= 0) {
2239
+ f1 = fleft;
2240
+ f2 = fright;
2241
+ t1 = tleft;
2242
+ t2 = tright;
2243
+ fmid = fq;
2244
+ calc_fmid = false;
2245
+ continue;
2246
+ }
2247
+ }
2248
+ }
2249
+ }
2250
+ }
2251
+ }
2252
+ if (f1 < 0 && fmid >= 0) {
2253
+ t2 = tmid;
2254
+ f2 = fmid;
2255
+ continue;
2256
+ }
2257
+ if (fmid < 0 && f2 >= 0) {
2258
+ t1 = tmid;
2259
+ f1 = fmid;
2260
+ continue;
2261
+ }
2262
+ return null;
2263
+ }
2264
+ }
2265
+ var AtmosphereInfo = class {
2266
+ constructor(pressure, temperature, density) {
2267
+ this.pressure = pressure;
2268
+ this.temperature = temperature;
2269
+ this.density = density;
2270
+ }
2271
+ };
2272
+ function Atmosphere(elevationMeters) {
2273
+ const P0 = 101325;
2274
+ const T0 = 288.15;
2275
+ const T1 = 216.65;
2276
+ if (!Number.isFinite(elevationMeters) || elevationMeters < -500 || elevationMeters > 1e5)
2277
+ throw `Invalid elevation: ${elevationMeters}`;
2278
+ let temperature;
2279
+ let pressure;
2280
+ if (elevationMeters <= 11e3) {
2281
+ temperature = T0 - 65e-4 * elevationMeters;
2282
+ pressure = P0 * Math.pow(T0 / temperature, -5.25577);
2283
+ } else if (elevationMeters <= 2e4) {
2284
+ temperature = T1;
2285
+ pressure = 22632 * Math.exp(-15768832e-11 * (elevationMeters - 11e3));
2286
+ } else {
2287
+ temperature = T1 + 1e-3 * (elevationMeters - 2e4);
2288
+ pressure = 5474.87 * Math.pow(T1 / temperature, 34.16319);
2289
+ }
2290
+ const density = pressure / temperature / (P0 / T0);
2291
+ return new AtmosphereInfo(pressure, temperature, density);
2292
+ }
2293
+ function HorizonDipAngle(observer, metersAboveGround) {
2294
+ const phi = observer.latitude * DEG2RAD;
2295
+ const sinphi = Math.sin(phi);
2296
+ const cosphi = Math.cos(phi);
2297
+ const c = 1 / Math.hypot(cosphi, sinphi * EARTH_FLATTENING);
2298
+ const s = c * (EARTH_FLATTENING * EARTH_FLATTENING);
2299
+ const ht_km = (observer.height - metersAboveGround) / 1e3;
2300
+ const ach = EARTH_EQUATORIAL_RADIUS_KM * c + ht_km;
2301
+ const ash = EARTH_EQUATORIAL_RADIUS_KM * s + ht_km;
2302
+ const radius_m = 1e3 * Math.hypot(ach * cosphi, ash * sinphi);
2303
+ const k = 0.175 * Math.pow(1 - 65e-4 / 283.15 * (observer.height - 2 / 3 * metersAboveGround), 3.256);
2304
+ return RAD2DEG * -(Math.sqrt(2 * (1 - k) * metersAboveGround / radius_m) / (1 - k));
2305
+ }
2306
+ function BodyRadiusAu(body) {
2307
+ switch (body) {
2308
+ case Body.Sun:
2309
+ return SUN_RADIUS_AU;
2310
+ case Body.Moon:
2311
+ return MOON_EQUATORIAL_RADIUS_AU;
2312
+ default:
2313
+ return 0;
2314
+ }
2315
+ }
2316
+ function SearchRiseSet(body, observer, direction, dateStart, limitDays, metersAboveGround = 0) {
2317
+ if (!Number.isFinite(metersAboveGround) || metersAboveGround < 0)
2318
+ throw `Invalid value for metersAboveGround: ${metersAboveGround}`;
2319
+ const body_radius_au = BodyRadiusAu(body);
2320
+ const atmos = Atmosphere(observer.height - metersAboveGround);
2321
+ const dip = HorizonDipAngle(observer, metersAboveGround);
2322
+ const altitude = dip - REFRACTION_NEAR_HORIZON * atmos.density;
2323
+ return InternalSearchAltitude(body, observer, direction, dateStart, limitDays, body_radius_au, altitude);
2324
+ }
2325
+ var AscentInfo = class {
2326
+ constructor(tx, ty, ax, ay) {
2327
+ this.tx = tx;
2328
+ this.ty = ty;
2329
+ this.ax = ax;
2330
+ this.ay = ay;
2331
+ }
2332
+ };
2333
+ function FindAscent(depth, altdiff, max_deriv_alt, t1, t2, a1, a2) {
2334
+ if (a1 < 0 && a2 >= 0) {
2335
+ return new AscentInfo(t1, t2, a1, a2);
2336
+ }
2337
+ if (a1 >= 0 && a2 < 0) {
2338
+ return null;
2339
+ }
2340
+ if (depth > 17) {
2341
+ throw `Excessive recursion in rise/set ascent search.`;
2342
+ }
2343
+ const dt = t2.ut - t1.ut;
2344
+ if (dt * SECONDS_PER_DAY < 1)
2345
+ return null;
2346
+ const da = Math.min(Math.abs(a1), Math.abs(a2));
2347
+ if (da > max_deriv_alt * (dt / 2)) {
2348
+ return null;
2349
+ }
2350
+ const tmid = new AstroTime((t1.ut + t2.ut) / 2);
2351
+ const amid = altdiff(tmid);
2352
+ return FindAscent(1 + depth, altdiff, max_deriv_alt, t1, tmid, a1, amid) || FindAscent(1 + depth, altdiff, max_deriv_alt, tmid, t2, amid, a2);
2353
+ }
2354
+ function MaxAltitudeSlope(body, latitude) {
2355
+ if (latitude < -90 || latitude > 90)
2356
+ throw `Invalid geographic latitude: ${latitude}`;
2357
+ let deriv_ra;
2358
+ let deriv_dec;
2359
+ switch (body) {
2360
+ case Body.Moon:
2361
+ deriv_ra = 4.5;
2362
+ deriv_dec = 8.2;
2363
+ break;
2364
+ case Body.Sun:
2365
+ deriv_ra = 0.8;
2366
+ deriv_dec = 0.5;
2367
+ break;
2368
+ case Body.Mercury:
2369
+ deriv_ra = -1.6;
2370
+ deriv_dec = 1;
2371
+ break;
2372
+ case Body.Venus:
2373
+ deriv_ra = -0.8;
2374
+ deriv_dec = 0.6;
2375
+ break;
2376
+ case Body.Mars:
2377
+ deriv_ra = -0.5;
2378
+ deriv_dec = 0.4;
2379
+ break;
2380
+ case Body.Jupiter:
2381
+ case Body.Saturn:
2382
+ case Body.Uranus:
2383
+ case Body.Neptune:
2384
+ case Body.Pluto:
2385
+ deriv_ra = -0.2;
2386
+ deriv_dec = 0.2;
2387
+ break;
2388
+ case Body.Star1:
2389
+ case Body.Star2:
2390
+ case Body.Star3:
2391
+ case Body.Star4:
2392
+ case Body.Star5:
2393
+ case Body.Star6:
2394
+ case Body.Star7:
2395
+ case Body.Star8:
2396
+ deriv_ra = -8e-3;
2397
+ deriv_dec = 8e-3;
2398
+ break;
2399
+ default:
2400
+ throw `Body not allowed for altitude search: ${body}`;
2401
+ }
2402
+ const latrad = DEG2RAD * latitude;
2403
+ return Math.abs((360 / SOLAR_DAYS_PER_SIDEREAL_DAY - deriv_ra) * Math.cos(latrad)) + Math.abs(deriv_dec * Math.sin(latrad));
2404
+ }
2405
+ function InternalSearchAltitude(body, observer, direction, dateStart, limitDays, bodyRadiusAu, targetAltitude) {
2406
+ VerifyObserver(observer);
2407
+ VerifyNumber(limitDays);
2408
+ VerifyNumber(bodyRadiusAu);
2409
+ VerifyNumber(targetAltitude);
2410
+ if (targetAltitude < -90 || targetAltitude > 90)
2411
+ throw `Invalid target altitude angle: ${targetAltitude}`;
2412
+ const max_deriv_alt = MaxAltitudeSlope(body, observer.latitude);
2413
+ function altdiff(time) {
2414
+ const ofdate = Equator(body, time, observer, true, true);
2415
+ const hor = Horizon(time, observer, ofdate.ra, ofdate.dec);
2416
+ const altitude = hor.altitude + RAD2DEG * Math.asin(bodyRadiusAu / ofdate.dist);
2417
+ return direction * (altitude - targetAltitude);
2418
+ }
2419
+ const startTime = MakeTime(dateStart);
2420
+ let t1 = startTime;
2421
+ let t2 = startTime;
2422
+ let a1 = altdiff(t1);
2423
+ let a2 = a1;
2424
+ for (; ; ) {
2425
+ if (limitDays < 0) {
2426
+ t1 = t2.AddDays(-0.42);
2427
+ a1 = altdiff(t1);
2428
+ } else {
2429
+ t2 = t1.AddDays(0.42);
2430
+ a2 = altdiff(t2);
2431
+ }
2432
+ const ascent = FindAscent(0, altdiff, max_deriv_alt, t1, t2, a1, a2);
2433
+ if (ascent) {
2434
+ const time = Search(altdiff, ascent.tx, ascent.ty, {
2435
+ dt_tolerance_seconds: 0.1,
2436
+ init_f1: ascent.ax,
2437
+ init_f2: ascent.ay
2438
+ });
2439
+ if (time) {
2440
+ if (limitDays < 0) {
2441
+ if (time.ut < startTime.ut + limitDays)
2442
+ return null;
2443
+ } else {
2444
+ if (time.ut > startTime.ut + limitDays)
2445
+ return null;
2446
+ }
2447
+ return time;
2448
+ }
2449
+ throw `Rise/set search failed after finding ascent: t1=${t1}, t2=${t2}, a1=${a1}, a2=${a2}`;
2450
+ }
2451
+ if (limitDays < 0) {
2452
+ if (t1.ut < startTime.ut + limitDays)
2453
+ return null;
2454
+ t2 = t1;
2455
+ a2 = a1;
2456
+ } else {
2457
+ if (t2.ut > startTime.ut + limitDays)
2458
+ return null;
2459
+ t1 = t2;
2460
+ a1 = a2;
2461
+ }
2462
+ }
2463
+ }
2464
+ var ApsisKind;
2465
+ (function(ApsisKind2) {
2466
+ ApsisKind2[ApsisKind2["Pericenter"] = 0] = "Pericenter";
2467
+ ApsisKind2[ApsisKind2["Apocenter"] = 1] = "Apocenter";
2468
+ })(ApsisKind || (ApsisKind = {}));
2469
+ function VectorFromSphere(sphere, time) {
2470
+ time = MakeTime(time);
2471
+ const radlat = sphere.lat * DEG2RAD;
2472
+ const radlon = sphere.lon * DEG2RAD;
2473
+ const rcoslat = sphere.dist * Math.cos(radlat);
2474
+ return new Vector(rcoslat * Math.cos(radlon), rcoslat * Math.sin(radlon), sphere.dist * Math.sin(radlat), time);
2475
+ }
2476
+ var EclipseKind;
2477
+ (function(EclipseKind2) {
2478
+ EclipseKind2["Penumbral"] = "penumbral";
2479
+ EclipseKind2["Partial"] = "partial";
2480
+ EclipseKind2["Annular"] = "annular";
2481
+ EclipseKind2["Total"] = "total";
2482
+ })(EclipseKind || (EclipseKind = {}));
2483
+ var NodeEventKind;
2484
+ (function(NodeEventKind2) {
2485
+ NodeEventKind2[NodeEventKind2["Invalid"] = 0] = "Invalid";
2486
+ NodeEventKind2[NodeEventKind2["Ascending"] = 1] = "Ascending";
2487
+ NodeEventKind2[NodeEventKind2["Descending"] = -1] = "Descending";
2488
+ })(NodeEventKind || (NodeEventKind = {}));
2489
+
2490
+ // src/astronomy/ayanamsa.ts
2491
+ function computeAyanamsa(date, type = "lahiri") {
2492
+ const T = julianCenturiesFromJ2000(date);
2493
+ switch (type) {
2494
+ case "lahiri":
2495
+ return lahiriAyanamsa(T);
2496
+ case "raman":
2497
+ return ramanAyanamsa(T);
2498
+ case "krishnamurti":
2499
+ return kpAyanamsa(T);
2500
+ default:
2501
+ throw new PanchangError(`Unknown ayanamsa type: ${type}`, "INVALID_AYANAMSA");
2502
+ }
2503
+ }
2504
+ function lahiriAyanamsa(T) {
2505
+ const REF_J2000_DEG = 23.853211;
2506
+ const precessionArcsec = 5029.0966 * T + 1.112 * T * T - 6e-6 * T * T * T;
2507
+ return REF_J2000_DEG + precessionArcsec / 3600;
2508
+ }
2509
+ function ramanAyanamsa(T) {
2510
+ const REF_J2000_DEG = 22.460489;
2511
+ const annualRateDeg = 50.3304 / 3600;
2512
+ return REF_J2000_DEG + annualRateDeg * T * 100;
2513
+ }
2514
+ function kpAyanamsa(T) {
2515
+ const REF_J2000_DEG = 23.773606;
2516
+ const precessionArcsec = 5029.0966 * T + 1.112 * T * T - 6e-6 * T * T * T;
2517
+ return REF_J2000_DEG + precessionArcsec / 3600;
2518
+ }
2519
+ function julianCenturiesFromJ2000(date) {
2520
+ const jd = dateToJulianDay(date);
2521
+ return (jd - 2451545) / 36525;
2522
+ }
2523
+ function dateToJulianDay(date) {
2524
+ return date.getTime() / 864e5 + 24405875e-1;
2525
+ }
2526
+
2527
+ // src/utils/angle.ts
2528
+ function normalize360(degrees) {
2529
+ const r = degrees % 360;
2530
+ if (r === 0) return 0;
2531
+ return r < 0 ? r + 360 : r;
2532
+ }
2533
+
2534
+ // src/astronomy/moon.ts
2535
+ function getSiderealMoonLongitude(date, ayanamsaType) {
2536
+ const astroTime = MakeTime(date);
2537
+ const tropicalLon = Ecliptic(GeoMoon(astroTime)).elon;
2538
+ const ayanamsa = computeAyanamsa(date, ayanamsaType);
2539
+ return normalize360(tropicalLon - ayanamsa);
2540
+ }
2541
+
2542
+ // src/astronomy/sun.ts
2543
+ function getSiderealSunLongitude(date, ayanamsaType) {
2544
+ const astroTime = MakeTime(date);
2545
+ const tropicalLon = SunPosition(astroTime).elon;
2546
+ const ayanamsa = computeAyanamsa(date, ayanamsaType);
2547
+ return normalize360(tropicalLon - ayanamsa);
2548
+ }
2549
+
2550
+ // src/astronomy/cache.ts
2551
+ var BUCKET_MS = 6e4;
2552
+ var LongitudeCache = class {
2553
+ constructor(ayanamsaType) {
2554
+ this.moonCache = /* @__PURE__ */ new Map();
2555
+ this.sunCache = /* @__PURE__ */ new Map();
2556
+ this.hits = 0;
2557
+ this.misses = 0;
2558
+ this.ayanamsaType = ayanamsaType;
2559
+ }
2560
+ getMoon(date) {
2561
+ const bucket = Math.floor(date.getTime() / BUCKET_MS);
2562
+ const cached = this.moonCache.get(bucket);
2563
+ if (cached !== void 0) {
2564
+ this.hits++;
2565
+ return cached;
2566
+ }
2567
+ this.misses++;
2568
+ const lon = getSiderealMoonLongitude(date, this.ayanamsaType);
2569
+ this.moonCache.set(bucket, lon);
2570
+ return lon;
2571
+ }
2572
+ getSun(date) {
2573
+ const bucket = Math.floor(date.getTime() / BUCKET_MS);
2574
+ const cached = this.sunCache.get(bucket);
2575
+ if (cached !== void 0) {
2576
+ this.hits++;
2577
+ return cached;
2578
+ }
2579
+ this.misses++;
2580
+ const lon = getSiderealSunLongitude(date, this.ayanamsaType);
2581
+ this.sunCache.set(bucket, lon);
2582
+ return lon;
2583
+ }
2584
+ get size() {
2585
+ return this.moonCache.size + this.sunCache.size;
2586
+ }
2587
+ };
2588
+
2589
+ // src/astronomy/sunrise.ts
2590
+ function computeSunrise(searchFromUtc, location, limitDays = 2) {
2591
+ const observer = new Observer(
2592
+ location.latitude,
2593
+ location.longitude,
2594
+ location.elevation ?? 0
2595
+ );
2596
+ const astroTime = MakeTime(searchFromUtc);
2597
+ const result = SearchRiseSet(Body.Sun, observer, 1, astroTime, limitDays);
2598
+ if (!result) {
2599
+ throw new PanchangError(
2600
+ `No sunrise found within ${limitDays} days for (${location.latitude}\xB0, ${location.longitude}\xB0) near ${searchFromUtc.toISOString()}. This location may be experiencing midnight sun or polar night.`,
2601
+ "NO_SUNRISE"
2602
+ );
2603
+ }
2604
+ return result.date;
2605
+ }
2606
+ function computeSunset(searchFromUtc, location, limitDays = 2) {
2607
+ const observer = new Observer(
2608
+ location.latitude,
2609
+ location.longitude,
2610
+ location.elevation ?? 0
2611
+ );
2612
+ const astroTime = MakeTime(searchFromUtc);
2613
+ const result = SearchRiseSet(Body.Sun, observer, -1, astroTime, limitDays);
2614
+ if (!result) {
2615
+ throw new PanchangError(
2616
+ `No sunset found within ${limitDays} days for (${location.latitude}\xB0, ${location.longitude}\xB0) near ${searchFromUtc.toISOString()}.`,
2617
+ "NO_SUNSET"
2618
+ );
2619
+ }
2620
+ return result.date;
2621
+ }
2622
+
2623
+ // src/utils/search.ts
2624
+ function findTransitionTime(startUtc, maxEndUtc, currentIndex, getIndexAtTime, maxIterations = 15, toleranceMs = 3e4) {
2625
+ let lo = startUtc.getTime();
2626
+ let hi2 = maxEndUtc.getTime();
2627
+ if (getIndexAtTime(new Date(hi2)) === currentIndex) {
2628
+ const extensions = [6, 12, 18, 24];
2629
+ let found = false;
2630
+ for (const ext of extensions) {
2631
+ hi2 = maxEndUtc.getTime() + ext * 36e5;
2632
+ if (getIndexAtTime(new Date(hi2)) !== currentIndex) {
2633
+ found = true;
2634
+ break;
2635
+ }
2636
+ }
2637
+ if (!found) {
2638
+ throw new PanchangError(
2639
+ `Binary search could not find transition for element index ${currentIndex} within 48h+ of ${startUtc.toISOString()}`,
2640
+ "SEARCH_DIVERGED"
2641
+ );
2642
+ }
2643
+ }
2644
+ let iterations = 0;
2645
+ while (hi2 - lo > toleranceMs && iterations < maxIterations) {
2646
+ const mid = lo + (hi2 - lo) / 2;
2647
+ if (getIndexAtTime(new Date(mid)) === currentIndex) {
2648
+ lo = mid;
2649
+ } else {
2650
+ hi2 = mid;
2651
+ }
2652
+ iterations++;
2653
+ }
2654
+ return new Date(hi2);
2655
+ }
2656
+ function findStartTime(fromUtc, currentIndex, totalElements, getIndexAtTime, maxSearchBackHours = 36, maxIterations = 15, toleranceMs = 3e4) {
2657
+ const searchStart = new Date(fromUtc.getTime() - maxSearchBackHours * 36e5);
2658
+ const previousIndex = (currentIndex - 1 + totalElements) % totalElements;
2659
+ if (getIndexAtTime(new Date(searchStart.getTime())) !== previousIndex) {
2660
+ return searchStart;
2661
+ }
2662
+ let lo = searchStart.getTime();
2663
+ let hi2 = fromUtc.getTime();
2664
+ let iterations = 0;
2665
+ while (hi2 - lo > toleranceMs && iterations < maxIterations) {
2666
+ const mid = lo + (hi2 - lo) / 2;
2667
+ if (getIndexAtTime(new Date(mid)) === previousIndex) {
2668
+ lo = mid;
2669
+ } else {
2670
+ hi2 = mid;
2671
+ }
2672
+ iterations++;
2673
+ }
2674
+ return new Date(hi2);
2675
+ }
2676
+ function findDailyElements(sunriseUtc, nextSunriseUtc, elementAtSunrise, getIndexAtTime, computeElementAtTime, totalElements, searchWindowHours, maxIterations, maxPerDay) {
2677
+ const results = [];
2678
+ let cursor = new Date(sunriseUtc.getTime());
2679
+ while (cursor.getTime() < nextSunriseUtc.getTime()) {
2680
+ const element = results.length === 0 ? elementAtSunrise : computeElementAtTime(cursor);
2681
+ const startTime = results.length === 0 ? findStartTime(sunriseUtc, element.index, totalElements, getIndexAtTime) : cursor;
2682
+ const isActiveAtSunrise = results.length === 0;
2683
+ const indexAtNextSunrise = getIndexAtTime(nextSunriseUtc);
2684
+ if (indexAtNextSunrise === element.index) {
2685
+ results.push(Object.assign({}, element, {
2686
+ startTime,
2687
+ endTime: new Date(nextSunriseUtc.getTime()),
2688
+ isActiveAtSunrise
2689
+ }));
2690
+ break;
2691
+ }
2692
+ const searchEnd = new Date(cursor.getTime() + searchWindowHours * 36e5);
2693
+ const rawEnd = findTransitionTime(cursor, searchEnd, element.index, getIndexAtTime, maxIterations);
2694
+ const endTime = rawEnd.getTime() > nextSunriseUtc.getTime() ? new Date(nextSunriseUtc.getTime()) : rawEnd;
2695
+ results.push(Object.assign({}, element, {
2696
+ startTime,
2697
+ endTime,
2698
+ isActiveAtSunrise
2699
+ }));
2700
+ if (rawEnd.getTime() >= nextSunriseUtc.getTime()) break;
2701
+ cursor = new Date(rawEnd.getTime() + 1);
2702
+ if (results.length >= maxPerDay) break;
2703
+ }
2704
+ return results;
2705
+ }
2706
+
2707
+ // src/utils/constants.ts
2708
+ var TITHI_SPAN = 12;
2709
+ var NAKSHATRA_SPAN = 360 / 27;
2710
+ var NAKSHATRA_PADA_SPAN = NAKSHATRA_SPAN / 4;
2711
+ var YOGA_SPAN = 360 / 27;
2712
+ var KARANA_SPAN = 6;
2713
+ var RAHU_KALAM_SLOTS = [7, 1, 6, 4, 5, 3, 2];
2714
+ var YAMAGANDA_SLOTS = [4, 3, 2, 1, 0, 6, 5];
2715
+ var GULIKA_SLOTS = [6, 5, 4, 3, 2, 1, 0];
2716
+ var ENGLISH_DAY_NAMES = [
2717
+ "Sunday",
2718
+ "Monday",
2719
+ "Tuesday",
2720
+ "Wednesday",
2721
+ "Thursday",
2722
+ "Friday",
2723
+ "Saturday"
2724
+ ];
2725
+
2726
+ // src/utils/timezone.ts
2727
+ function resolveUtcOffset(timezone, referenceDate) {
2728
+ if (typeof timezone === "number") {
2729
+ validateOffset(timezone);
2730
+ return timezone;
2731
+ }
2732
+ try {
2733
+ const formatter = new Intl.DateTimeFormat("en-US", {
2734
+ timeZone: timezone,
2735
+ timeZoneName: "shortOffset"
2736
+ });
2737
+ const parts = formatter.formatToParts(referenceDate);
2738
+ const tzPart = parts.find((p) => p.type === "timeZoneName");
2739
+ if (!tzPart) throw new Error("No timeZoneName part found");
2740
+ return parseGmtOffset(tzPart.value);
2741
+ } catch {
2742
+ throw new PanchangError(
2743
+ `Cannot resolve timezone "${timezone}". On React Native (Hermes), pass a numeric UTC offset in minutes instead (e.g. 330 for IST +05:30, -300 for EST -05:00).`,
2744
+ "TIMEZONE_RESOLUTION_FAILED"
2745
+ );
2746
+ }
2747
+ }
2748
+ function getLocalMidnightUtc(date, offsetMinutes) {
2749
+ const y = date.getFullYear();
2750
+ const m = date.getMonth();
2751
+ const d = date.getDate();
2752
+ const midnightUtc = Date.UTC(y, m, d, 0, 0, 0, 0);
2753
+ return new Date(midnightUtc - offsetMinutes * 6e4);
2754
+ }
2755
+ function utcToLocalDisplay(utcDate, offsetMinutes) {
2756
+ return new Date(utcDate.getTime() + offsetMinutes * 6e4);
2757
+ }
2758
+ function parseGmtOffset(gmtString) {
2759
+ if (gmtString === "GMT") return 0;
2760
+ const match = gmtString.match(/GMT([+-])(\d{1,2})(?::(\d{2}))?/);
2761
+ if (!match) return 0;
2762
+ const sign = match[1] === "+" ? 1 : -1;
2763
+ const hours = parseInt(match[2], 10);
2764
+ const mins = parseInt(match[3] ?? "0", 10);
2765
+ return sign * (hours * 60 + mins);
2766
+ }
2767
+ function validateOffset(offset) {
2768
+ if (offset < -720 || offset > 840 || !Number.isInteger(offset)) {
2769
+ throw new PanchangError(
2770
+ `UTC offset must be an integer between -720 and 840, got ${offset}`,
2771
+ "INVALID_TIMEZONE"
2772
+ );
2773
+ }
2774
+ }
2775
+
2776
+ // src/core/tithi.ts
2777
+ function computeTithiFromLongitudes(siderealMoon, siderealSun, name) {
2778
+ const angle = normalize360(siderealMoon - siderealSun);
2779
+ const index = Math.floor(angle / TITHI_SPAN);
2780
+ const elapsed = angle - index * TITHI_SPAN;
2781
+ const completionPercentage = elapsed / TITHI_SPAN * 100;
2782
+ const paksha = index < 15 ? "Shukla" : "Krishna";
2783
+ const number = index < 15 ? index + 1 : index - 14;
2784
+ return {
2785
+ index,
2786
+ name,
2787
+ paksha,
2788
+ number,
2789
+ completionPercentage: Math.round(completionPercentage * 100) / 100,
2790
+ endTime: null
2791
+ };
2792
+ }
2793
+ function getTithiIndexAtTime(date, getCachedMoon, getCachedSun) {
2794
+ const angle = normalize360(getCachedMoon(date) - getCachedSun(date));
2795
+ return Math.floor(angle / TITHI_SPAN);
2796
+ }
2797
+ function getTithiIndexFromLons(siderealMoon, siderealSun) {
2798
+ return Math.floor(normalize360(siderealMoon - siderealSun) / TITHI_SPAN);
2799
+ }
2800
+
2801
+ // src/core/nakshatra.ts
2802
+ function computeNakshatraFromLongitude(siderealMoon, name) {
2803
+ const index = Math.floor(siderealMoon / NAKSHATRA_SPAN);
2804
+ const degreesInNakshatra = siderealMoon - index * NAKSHATRA_SPAN;
2805
+ const pada = Math.min(Math.floor(degreesInNakshatra / NAKSHATRA_PADA_SPAN) + 1, 4);
2806
+ const completionPercentage = degreesInNakshatra / NAKSHATRA_SPAN * 100;
2807
+ return {
2808
+ index,
2809
+ name,
2810
+ pada,
2811
+ degreesInNakshatra: Math.round(degreesInNakshatra * 1e4) / 1e4,
2812
+ completionPercentage: Math.round(completionPercentage * 100) / 100,
2813
+ endTime: null
2814
+ };
2815
+ }
2816
+ function getNakshatraIndexAtTime(date, getCachedMoon) {
2817
+ return Math.floor(getCachedMoon(date) / NAKSHATRA_SPAN);
2818
+ }
2819
+
2820
+ // src/core/yoga.ts
2821
+ function computeYogaFromLongitudes(siderealMoon, siderealSun, name) {
2822
+ const angle = normalize360(siderealSun + siderealMoon);
2823
+ const index = Math.floor(angle / YOGA_SPAN);
2824
+ const elapsed = angle - index * YOGA_SPAN;
2825
+ const completionPercentage = elapsed / YOGA_SPAN * 100;
2826
+ return {
2827
+ index,
2828
+ name,
2829
+ completionPercentage: Math.round(completionPercentage * 100) / 100,
2830
+ endTime: null
2831
+ };
2832
+ }
2833
+ function getYogaIndexAtTime(date, getCachedMoon, getCachedSun) {
2834
+ const angle = normalize360(getCachedSun(date) + getCachedMoon(date));
2835
+ return Math.floor(angle / YOGA_SPAN);
2836
+ }
2837
+ function getYogaIndex(siderealMoon, siderealSun) {
2838
+ return Math.floor(normalize360(siderealSun + siderealMoon) / YOGA_SPAN);
2839
+ }
2840
+
2841
+ // src/core/karana.ts
2842
+ function computeKaranaFromLongitudes(siderealMoon, siderealSun, name) {
2843
+ const angle = normalize360(siderealMoon - siderealSun);
2844
+ const index = Math.floor(angle / KARANA_SPAN);
2845
+ const elapsed = angle - index * KARANA_SPAN;
2846
+ const completionPercentage = elapsed / KARANA_SPAN * 100;
2847
+ return {
2848
+ index,
2849
+ name,
2850
+ type: getKaranaType(index),
2851
+ completionPercentage: Math.round(completionPercentage * 100) / 100,
2852
+ endTime: null
2853
+ };
2854
+ }
2855
+ function getKaranaType(index) {
2856
+ return index === 0 || index >= 57 ? "fixed" : "movable";
2857
+ }
2858
+ function getKaranaIndexAtTime(date, getCachedMoon, getCachedSun) {
2859
+ const angle = normalize360(getCachedMoon(date) - getCachedSun(date));
2860
+ return Math.floor(angle / KARANA_SPAN);
2861
+ }
2862
+ function getKaranaIndex(siderealMoon, siderealSun) {
2863
+ return Math.floor(normalize360(siderealMoon - siderealSun) / KARANA_SPAN);
2864
+ }
2865
+
2866
+ // src/core/vara.ts
2867
+ function computeVara(dateUtc, sunriseUtc, varaNames) {
2868
+ let d = new Date(dateUtc);
2869
+ if (dateUtc.getTime() < sunriseUtc.getTime()) {
2870
+ d = new Date(dateUtc.getTime() - 864e5);
2871
+ }
2872
+ const index = d.getUTCDay();
2873
+ return {
2874
+ index,
2875
+ name: varaNames[index].name,
2876
+ shortName: varaNames[index].short,
2877
+ englishName: ENGLISH_DAY_NAMES[index]
2878
+ };
2879
+ }
2880
+
2881
+ // src/core/inauspicious.ts
2882
+ function computeInauspiciousPeriod(sunrise, sunset, varaIndex, slotTable) {
2883
+ const dayDurationMs = sunset.getTime() - sunrise.getTime();
2884
+ const slotDurationMs = dayDurationMs / 8;
2885
+ const slotIndex = slotTable[varaIndex];
2886
+ const start = new Date(sunrise.getTime() + slotIndex * slotDurationMs);
2887
+ const end = new Date(start.getTime() + slotDurationMs);
2888
+ return { start, end };
2889
+ }
2890
+ function computeRahuKalam(sunrise, sunset, varaIndex) {
2891
+ return computeInauspiciousPeriod(sunrise, sunset, varaIndex, RAHU_KALAM_SLOTS);
2892
+ }
2893
+ function computeGulikaKalam(sunrise, sunset, varaIndex) {
2894
+ return computeInauspiciousPeriod(sunrise, sunset, varaIndex, GULIKA_SLOTS);
2895
+ }
2896
+ function computeYamaganda(sunrise, sunset, varaIndex) {
2897
+ return computeInauspiciousPeriod(sunrise, sunset, varaIndex, YAMAGANDA_SLOTS);
2898
+ }
2899
+
2900
+ // src/core/muhurta.ts
2901
+ function computeAbhijitMuhurta(sunrise, sunset) {
2902
+ const dayDurationMs = sunset.getTime() - sunrise.getTime();
2903
+ const muhurtaDurationMs = dayDurationMs / 15;
2904
+ const start = new Date(sunrise.getTime() + 7 * muhurtaDurationMs);
2905
+ const end = new Date(start.getTime() + muhurtaDurationMs);
2906
+ return { start, end };
2907
+ }
2908
+
2909
+ // src/core/masa.ts
2910
+ var MASA_NAMES_EN = [
2911
+ "Mesha",
2912
+ "Vrishabha",
2913
+ "Mithuna",
2914
+ "Karka",
2915
+ "Simha",
2916
+ "Kanya",
2917
+ "Tula",
2918
+ "Vrischika",
2919
+ "Dhanus",
2920
+ "Makara",
2921
+ "Kumbha",
2922
+ "Meena"
2923
+ ];
2924
+ function computeMasa(siderealSunLon) {
2925
+ const index = Math.floor(siderealSunLon / 30);
2926
+ return {
2927
+ index,
2928
+ name: MASA_NAMES_EN[index]
2929
+ };
2930
+ }
2931
+
2932
+ // src/i18n/en.ts
2933
+ var en = {
2934
+ tithiNames: [
2935
+ "Pratipad",
2936
+ "Dwitiya",
2937
+ "Tritiya",
2938
+ "Chaturthi",
2939
+ "Panchami",
2940
+ "Shashthi",
2941
+ "Saptami",
2942
+ "Ashtami",
2943
+ "Navami",
2944
+ "Dashami",
2945
+ "Ekadashi",
2946
+ "Dwadashi",
2947
+ "Trayodashi",
2948
+ "Chaturdashi"
2949
+ ],
2950
+ nakshatraNames: [
2951
+ "Ashwini",
2952
+ "Bharani",
2953
+ "Krittika",
2954
+ "Rohini",
2955
+ "Mrigashira",
2956
+ "Ardra",
2957
+ "Punarvasu",
2958
+ "Pushya",
2959
+ "Ashlesha",
2960
+ "Magha",
2961
+ "Purva Phalguni",
2962
+ "Uttara Phalguni",
2963
+ "Hasta",
2964
+ "Chitra",
2965
+ "Swati",
2966
+ "Vishakha",
2967
+ "Anuradha",
2968
+ "Jyeshtha",
2969
+ "Mula",
2970
+ "Purva Ashadha",
2971
+ "Uttara Ashadha",
2972
+ "Shravana",
2973
+ "Dhanishta",
2974
+ "Shatabhisha",
2975
+ "Purva Bhadrapada",
2976
+ "Uttara Bhadrapada",
2977
+ "Revati"
2978
+ ],
2979
+ yogaNames: [
2980
+ "Vishkamba",
2981
+ "Priti",
2982
+ "Ayushman",
2983
+ "Saubhagya",
2984
+ "Shobhana",
2985
+ "Atiganda",
2986
+ "Sukarma",
2987
+ "Dhriti",
2988
+ "Shula",
2989
+ "Ganda",
2990
+ "Vriddhi",
2991
+ "Dhruva",
2992
+ "Vyaghata",
2993
+ "Harshana",
2994
+ "Vajra",
2995
+ "Siddhi",
2996
+ "Vyatipata",
2997
+ "Variyan",
2998
+ "Parigha",
2999
+ "Shiva",
3000
+ "Siddha",
3001
+ "Sadhya",
3002
+ "Shubha",
3003
+ "Shukla",
3004
+ "Brahma",
3005
+ "Indra",
3006
+ "Vaidhriti"
3007
+ ],
3008
+ karanaNames: {
3009
+ movable: ["Bava", "Balava", "Kaulava", "Taitila", "Gara", "Vanija", "Vishti"],
3010
+ fixed: ["Kimstughna", "Shakuni", "Chatushpada", "Naga"]
3011
+ },
3012
+ varaNames: [
3013
+ { name: "Ravivara", short: "Ravi" },
3014
+ { name: "Somavara", short: "Soma" },
3015
+ { name: "Mangalavara", short: "Mangal" },
3016
+ { name: "Budhavara", short: "Budh" },
3017
+ { name: "Guruvara", short: "Guru" },
3018
+ { name: "Shukravara", short: "Shukra" },
3019
+ { name: "Shanivara", short: "Shani" }
3020
+ ],
3021
+ pakshaNames: { shukla: "Shukla", krishna: "Krishna" },
3022
+ masaNames: [
3023
+ "Mesha",
3024
+ "Vrishabha",
3025
+ "Mithuna",
3026
+ "Karka",
3027
+ "Simha",
3028
+ "Kanya",
3029
+ "Tula",
3030
+ "Vrischika",
3031
+ "Dhanus",
3032
+ "Makara",
3033
+ "Kumbha",
3034
+ "Meena"
3035
+ ],
3036
+ misc: { purnima: "Purnima", amavasya: "Amavasya" }
3037
+ };
3038
+
3039
+ // src/i18n/sa.ts
3040
+ var sa = {
3041
+ tithiNames: [
3042
+ "\u092A\u094D\u0930\u0924\u093F\u092A\u0926\u093E",
3043
+ "\u0926\u094D\u0935\u093F\u0924\u0940\u092F\u093E",
3044
+ "\u0924\u0943\u0924\u0940\u092F\u093E",
3045
+ "\u091A\u0924\u0941\u0930\u094D\u0925\u0940",
3046
+ "\u092A\u091E\u094D\u091A\u092E\u0940",
3047
+ "\u0937\u0937\u094D\u0920\u0940",
3048
+ "\u0938\u092A\u094D\u0924\u092E\u0940",
3049
+ "\u0905\u0937\u094D\u091F\u092E\u0940",
3050
+ "\u0928\u0935\u092E\u0940",
3051
+ "\u0926\u0936\u092E\u0940",
3052
+ "\u090F\u0915\u093E\u0926\u0936\u0940",
3053
+ "\u0926\u094D\u0935\u093E\u0926\u0936\u0940",
3054
+ "\u0924\u094D\u0930\u092F\u094B\u0926\u0936\u0940",
3055
+ "\u091A\u0924\u0941\u0930\u094D\u0926\u0936\u0940"
3056
+ ],
3057
+ nakshatraNames: [
3058
+ "\u0905\u0936\u094D\u0935\u093F\u0928\u0940",
3059
+ "\u092D\u0930\u0923\u0940",
3060
+ "\u0915\u0943\u0924\u094D\u0924\u093F\u0915\u093E",
3061
+ "\u0930\u094B\u0939\u093F\u0923\u0940",
3062
+ "\u092E\u0943\u0917\u0936\u093F\u0930\u093E",
3063
+ "\u0906\u0930\u094D\u0926\u094D\u0930\u093E",
3064
+ "\u092A\u0941\u0928\u0930\u094D\u0935\u0938\u0941",
3065
+ "\u092A\u0941\u0937\u094D\u092F",
3066
+ "\u0906\u0936\u094D\u0932\u0947\u0937\u093E",
3067
+ "\u092E\u0918\u093E",
3068
+ "\u092A\u0942\u0930\u094D\u0935\u092B\u093E\u0932\u094D\u0917\u0941\u0928\u0940",
3069
+ "\u0909\u0924\u094D\u0924\u0930\u092B\u093E\u0932\u094D\u0917\u0941\u0928\u0940",
3070
+ "\u0939\u0938\u094D\u0924",
3071
+ "\u091A\u093F\u0924\u094D\u0930\u093E",
3072
+ "\u0938\u094D\u0935\u093E\u0924\u0940",
3073
+ "\u0935\u093F\u0936\u093E\u0916\u093E",
3074
+ "\u0905\u0928\u0941\u0930\u093E\u0927\u093E",
3075
+ "\u091C\u094D\u092F\u0947\u0937\u094D\u0920\u093E",
3076
+ "\u092E\u0942\u0932",
3077
+ "\u092A\u0942\u0930\u094D\u0935\u093E\u0937\u093E\u0922\u093E",
3078
+ "\u0909\u0924\u094D\u0924\u0930\u093E\u0937\u093E\u0922\u093E",
3079
+ "\u0936\u094D\u0930\u0935\u0923",
3080
+ "\u0927\u0928\u093F\u0937\u094D\u0920\u093E",
3081
+ "\u0936\u0924\u092D\u093F\u0937\u093E",
3082
+ "\u092A\u0942\u0930\u094D\u0935\u092D\u093E\u0926\u094D\u0930\u092A\u0926\u093E",
3083
+ "\u0909\u0924\u094D\u0924\u0930\u092D\u093E\u0926\u094D\u0930\u092A\u0926\u093E",
3084
+ "\u0930\u0947\u0935\u0924\u0940"
3085
+ ],
3086
+ yogaNames: [
3087
+ "\u0935\u093F\u0937\u094D\u0915\u092E\u094D\u092D",
3088
+ "\u092A\u094D\u0930\u0940\u0924\u093F",
3089
+ "\u0906\u092F\u0941\u0937\u094D\u092E\u093E\u0928\u094D",
3090
+ "\u0938\u094C\u092D\u093E\u0917\u094D\u092F",
3091
+ "\u0936\u094B\u092D\u0928",
3092
+ "\u0905\u0924\u093F\u0917\u0923\u094D\u0921",
3093
+ "\u0938\u0941\u0915\u0930\u094D\u092E\u093E",
3094
+ "\u0927\u0943\u0924\u093F",
3095
+ "\u0936\u0942\u0932",
3096
+ "\u0917\u0923\u094D\u0921",
3097
+ "\u0935\u0943\u0926\u094D\u0927\u093F",
3098
+ "\u0927\u094D\u0930\u0941\u0935",
3099
+ "\u0935\u094D\u092F\u093E\u0918\u093E\u0924",
3100
+ "\u0939\u0930\u094D\u0937\u0923",
3101
+ "\u0935\u091C\u094D\u0930",
3102
+ "\u0938\u093F\u0926\u094D\u0927\u093F",
3103
+ "\u0935\u094D\u092F\u0924\u0940\u092A\u093E\u0924",
3104
+ "\u0935\u0930\u0940\u092F\u093E\u0928\u094D",
3105
+ "\u092A\u0930\u093F\u0918",
3106
+ "\u0936\u093F\u0935",
3107
+ "\u0938\u093F\u0926\u094D\u0927",
3108
+ "\u0938\u093E\u0927\u094D\u092F",
3109
+ "\u0936\u0941\u092D",
3110
+ "\u0936\u0941\u0915\u094D\u0932",
3111
+ "\u092C\u094D\u0930\u0939\u094D\u092E",
3112
+ "\u0907\u0928\u094D\u0926\u094D\u0930",
3113
+ "\u0935\u0948\u0927\u0943\u0924\u093F"
3114
+ ],
3115
+ karanaNames: {
3116
+ movable: ["\u092C\u0935", "\u092C\u093E\u0932\u0935", "\u0915\u094C\u0932\u0935", "\u0924\u0948\u0924\u093F\u0932", "\u0917\u0930", "\u0935\u0923\u093F\u091C", "\u0935\u093F\u0937\u094D\u091F\u093F"],
3117
+ fixed: ["\u0915\u093F\u0902\u0938\u094D\u0924\u0941\u0918\u094D\u0928", "\u0936\u0915\u0941\u0928\u093F", "\u091A\u0924\u0941\u0937\u094D\u092A\u093E\u0926", "\u0928\u093E\u0917"]
3118
+ },
3119
+ varaNames: [
3120
+ { name: "\u0930\u0935\u093F\u0935\u093E\u0930", short: "\u0930\u0935\u093F" },
3121
+ { name: "\u0938\u094B\u092E\u0935\u093E\u0930", short: "\u0938\u094B\u092E" },
3122
+ { name: "\u092E\u0919\u094D\u0917\u0932\u0935\u093E\u0930", short: "\u092E\u0919\u094D\u0917\u0932" },
3123
+ { name: "\u092C\u0941\u0927\u0935\u093E\u0930", short: "\u092C\u0941\u0927" },
3124
+ { name: "\u0917\u0941\u0930\u0941\u0935\u093E\u0930", short: "\u0917\u0941\u0930\u0941" },
3125
+ { name: "\u0936\u0941\u0915\u094D\u0930\u0935\u093E\u0930", short: "\u0936\u0941\u0915\u094D\u0930" },
3126
+ { name: "\u0936\u0928\u093F\u0935\u093E\u0930", short: "\u0936\u0928\u093F" }
3127
+ ],
3128
+ pakshaNames: { shukla: "\u0936\u0941\u0915\u094D\u0932", krishna: "\u0915\u0943\u0937\u094D\u0923" },
3129
+ masaNames: [
3130
+ "\u092E\u0947\u0937",
3131
+ "\u0935\u0943\u0937\u092D",
3132
+ "\u092E\u093F\u0925\u0941\u0928",
3133
+ "\u0915\u0930\u094D\u0915",
3134
+ "\u0938\u093F\u0902\u0939",
3135
+ "\u0915\u0928\u094D\u092F\u093E",
3136
+ "\u0924\u0941\u0932\u093E",
3137
+ "\u0935\u0943\u0936\u094D\u091A\u093F\u0915",
3138
+ "\u0927\u0928\u0941",
3139
+ "\u092E\u0915\u0930",
3140
+ "\u0915\u0941\u092E\u094D\u092D",
3141
+ "\u092E\u0940\u0928"
3142
+ ],
3143
+ misc: { purnima: "\u092A\u0942\u0930\u094D\u0923\u093F\u092E\u093E", amavasya: "\u0905\u092E\u093E\u0935\u093E\u0938\u094D\u092F\u093E" }
3144
+ };
3145
+
3146
+ // src/i18n/hi.ts
3147
+ var hi = { ...sa };
3148
+
3149
+ // src/i18n/resolver.ts
3150
+ var TRANSLATIONS = { en, sa, hi };
3151
+ function getTranslations(lang) {
3152
+ return TRANSLATIONS[lang] ?? en;
3153
+ }
3154
+ function resolveTithiName(index, lang) {
3155
+ const t = getTranslations(lang);
3156
+ if (index === 14) return t.misc.purnima;
3157
+ if (index === 29) return t.misc.amavasya;
3158
+ const paksha = index < 15 ? t.pakshaNames.shukla : t.pakshaNames.krishna;
3159
+ const nameIndex = index < 15 ? index : index - 15;
3160
+ return `${paksha} ${t.tithiNames[nameIndex]}`;
3161
+ }
3162
+ function resolveNakshatraName(index, lang) {
3163
+ return getTranslations(lang).nakshatraNames[index];
3164
+ }
3165
+ function resolveYogaName(index, lang) {
3166
+ return getTranslations(lang).yogaNames[index];
3167
+ }
3168
+ function resolveKaranaName(index, lang) {
3169
+ const t = getTranslations(lang);
3170
+ if (index === 0) return t.karanaNames.fixed[0];
3171
+ if (index >= 57) return t.karanaNames.fixed[index - 56];
3172
+ return t.karanaNames.movable[(index - 1) % 7];
3173
+ }
3174
+
3175
+ // src/core/panchang.ts
3176
+ function getInstantPanchang(date, location, options) {
3177
+ validateDate(date);
3178
+ validateLocation(location);
3179
+ const ayanamsaType = options?.ayanamsa ?? "lahiri";
3180
+ const lang = options?.language ?? "en";
3181
+ const doEndTimes = options?.computeEndTimes !== false;
3182
+ const maxIter = options?.precision === "high" ? 25 : 15;
3183
+ const cache = new LongitudeCache(ayanamsaType);
3184
+ const getMoon = (d) => cache.getMoon(d);
3185
+ const getSun = (d) => cache.getSun(d);
3186
+ const siderealMoon = getMoon(date);
3187
+ const siderealSun = getSun(date);
3188
+ const ayanamsaValue = computeAyanamsa(date, ayanamsaType);
3189
+ const tithi = computeTithiFromLongitudes(
3190
+ siderealMoon,
3191
+ siderealSun,
3192
+ resolveTithiName(getTithiIndexFromLons(siderealMoon, siderealSun), lang)
3193
+ );
3194
+ const nakshatra = computeNakshatraFromLongitude(
3195
+ siderealMoon,
3196
+ resolveNakshatraName(Math.floor(siderealMoon / NAKSHATRA_SPAN), lang)
3197
+ );
3198
+ const yoga = computeYogaFromLongitudes(
3199
+ siderealMoon,
3200
+ siderealSun,
3201
+ resolveYogaName(getYogaIndex(siderealMoon, siderealSun), lang)
3202
+ );
3203
+ const karana = computeKaranaFromLongitudes(
3204
+ siderealMoon,
3205
+ siderealSun,
3206
+ resolveKaranaName(getKaranaIndex(siderealMoon, siderealSun), lang)
3207
+ );
3208
+ const sunriseUtc = computeSunrise(
3209
+ new Date(date.getTime() - 12 * 36e5),
3210
+ location
3211
+ );
3212
+ const vara = computeVara(date, sunriseUtc, getTranslations(lang).varaNames);
3213
+ if (doEndTimes) {
3214
+ tithi.endTime = findTransitionTime(
3215
+ date,
3216
+ new Date(date.getTime() + 36 * 36e5),
3217
+ tithi.index,
3218
+ (d) => getTithiIndexAtTime(d, getMoon, getSun),
3219
+ maxIter
3220
+ );
3221
+ nakshatra.endTime = findTransitionTime(
3222
+ date,
3223
+ new Date(date.getTime() + 36 * 36e5),
3224
+ nakshatra.index,
3225
+ (d) => getNakshatraIndexAtTime(d, getMoon),
3226
+ maxIter
3227
+ );
3228
+ yoga.endTime = findTransitionTime(
3229
+ date,
3230
+ new Date(date.getTime() + 36 * 36e5),
3231
+ yoga.index,
3232
+ (d) => getYogaIndexAtTime(d, getMoon, getSun),
3233
+ maxIter
3234
+ );
3235
+ karana.endTime = findTransitionTime(
3236
+ date,
3237
+ new Date(date.getTime() + 18 * 36e5),
3238
+ karana.index,
3239
+ (d) => getKaranaIndexAtTime(d, getMoon, getSun),
3240
+ maxIter
3241
+ );
3242
+ }
3243
+ return {
3244
+ timestamp: date,
3245
+ location,
3246
+ tithi,
3247
+ nakshatra,
3248
+ yoga,
3249
+ karana,
3250
+ vara,
3251
+ ayanamsa: ayanamsaValue,
3252
+ siderealSun,
3253
+ siderealMoon
3254
+ };
3255
+ }
3256
+ function getDailyPanchang(date, location, options) {
3257
+ validateDate(date);
3258
+ validateLocation(location);
3259
+ const offsetMinutes = resolveUtcOffset(options.timezone, date);
3260
+ const ayanamsaType = options.ayanamsa ?? "lahiri";
3261
+ const lang = options.language ?? "en";
3262
+ const doEndTimes = options.computeEndTimes !== false;
3263
+ const maxIter = options.precision === "high" ? 25 : 15;
3264
+ const cache = new LongitudeCache(ayanamsaType);
3265
+ const getMoon = (d) => cache.getMoon(d);
3266
+ const getSun = (d) => cache.getSun(d);
3267
+ const localMidnightUtc = getLocalMidnightUtc(date, offsetMinutes);
3268
+ const sunriseUtc = computeSunrise(localMidnightUtc, location);
3269
+ const sunsetUtc = computeSunset(sunriseUtc, location);
3270
+ const nextSunriseUtc = computeSunrise(sunsetUtc, location);
3271
+ const siderealMoonAtSunrise = getMoon(sunriseUtc);
3272
+ const siderealSunAtSunrise = getSun(sunriseUtc);
3273
+ const ayanamsaValue = computeAyanamsa(sunriseUtc, ayanamsaType);
3274
+ const tithiAtSunrise = computeTithiFromLongitudes(
3275
+ siderealMoonAtSunrise,
3276
+ siderealSunAtSunrise,
3277
+ resolveTithiName(getTithiIndexFromLons(siderealMoonAtSunrise, siderealSunAtSunrise), lang)
3278
+ );
3279
+ const nakshatraAtSunrise = computeNakshatraFromLongitude(
3280
+ siderealMoonAtSunrise,
3281
+ resolveNakshatraName(Math.floor(siderealMoonAtSunrise / NAKSHATRA_SPAN), lang)
3282
+ );
3283
+ const yogaAtSunrise = computeYogaFromLongitudes(
3284
+ siderealMoonAtSunrise,
3285
+ siderealSunAtSunrise,
3286
+ resolveYogaName(getYogaIndex(siderealMoonAtSunrise, siderealSunAtSunrise), lang)
3287
+ );
3288
+ const karanaAtSunrise = computeKaranaFromLongitudes(
3289
+ siderealMoonAtSunrise,
3290
+ siderealSunAtSunrise,
3291
+ resolveKaranaName(getKaranaIndex(siderealMoonAtSunrise, siderealSunAtSunrise), lang)
3292
+ );
3293
+ const vara = computeVara(sunriseUtc, sunriseUtc, getTranslations(lang).varaNames);
3294
+ const masa = computeMasa(siderealSunAtSunrise);
3295
+ let tithis;
3296
+ let nakshatras;
3297
+ let yogas;
3298
+ let karanas;
3299
+ if (doEndTimes) {
3300
+ tithis = findDailyElements(
3301
+ sunriseUtc,
3302
+ nextSunriseUtc,
3303
+ tithiAtSunrise,
3304
+ (d) => getTithiIndexAtTime(d, getMoon, getSun),
3305
+ (d) => {
3306
+ const moon = getMoon(d), sun = getSun(d);
3307
+ return computeTithiFromLongitudes(moon, sun, resolveTithiName(getTithiIndexFromLons(moon, sun), lang));
3308
+ },
3309
+ 30,
3310
+ 36,
3311
+ maxIter,
3312
+ 2
3313
+ );
3314
+ nakshatras = findDailyElements(
3315
+ sunriseUtc,
3316
+ nextSunriseUtc,
3317
+ nakshatraAtSunrise,
3318
+ (d) => getNakshatraIndexAtTime(d, getMoon),
3319
+ (d) => {
3320
+ const moon = getMoon(d);
3321
+ return computeNakshatraFromLongitude(moon, resolveNakshatraName(Math.floor(moon / NAKSHATRA_SPAN), lang));
3322
+ },
3323
+ 27,
3324
+ 36,
3325
+ maxIter,
3326
+ 2
3327
+ );
3328
+ yogas = findDailyElements(
3329
+ sunriseUtc,
3330
+ nextSunriseUtc,
3331
+ yogaAtSunrise,
3332
+ (d) => getYogaIndexAtTime(d, getMoon, getSun),
3333
+ (d) => {
3334
+ const moon = getMoon(d), sun = getSun(d);
3335
+ return computeYogaFromLongitudes(moon, sun, resolveYogaName(getYogaIndex(moon, sun), lang));
3336
+ },
3337
+ 27,
3338
+ 36,
3339
+ maxIter,
3340
+ 2
3341
+ );
3342
+ karanas = findDailyElements(
3343
+ sunriseUtc,
3344
+ nextSunriseUtc,
3345
+ karanaAtSunrise,
3346
+ (d) => getKaranaIndexAtTime(d, getMoon, getSun),
3347
+ (d) => {
3348
+ const moon = getMoon(d), sun = getSun(d);
3349
+ return computeKaranaFromLongitudes(moon, sun, resolveKaranaName(getKaranaIndex(moon, sun), lang));
3350
+ },
3351
+ 60,
3352
+ 18,
3353
+ maxIter,
3354
+ 4
3355
+ );
3356
+ } else {
3357
+ tithis = [{ ...tithiAtSunrise, startTime: null, isActiveAtSunrise: true }];
3358
+ nakshatras = [{ ...nakshatraAtSunrise, startTime: null, isActiveAtSunrise: true }];
3359
+ yogas = [{ ...yogaAtSunrise, startTime: null, isActiveAtSunrise: true }];
3360
+ karanas = [{ ...karanaAtSunrise, startTime: null, isActiveAtSunrise: true }];
3361
+ }
3362
+ const rahuKalam = computeRahuKalam(sunriseUtc, sunsetUtc, vara.index);
3363
+ const gulikaKalam = computeGulikaKalam(sunriseUtc, sunsetUtc, vara.index);
3364
+ const yamaganda = computeYamaganda(sunriseUtc, sunsetUtc, vara.index);
3365
+ const abhijitMuhurta = computeAbhijitMuhurta(sunriseUtc, sunsetUtc);
3366
+ const toLocal = (d) => utcToLocalDisplay(d, offsetMinutes);
3367
+ const toLocalOrNull = (d) => d ? toLocal(d) : null;
3368
+ const convertTimePeriod = (tp) => ({
3369
+ start: toLocal(tp.start),
3370
+ end: toLocal(tp.end)
3371
+ });
3372
+ const dayDurationMs = sunsetUtc.getTime() - sunriseUtc.getTime();
3373
+ const nightDurationMs = nextSunriseUtc.getTime() - sunsetUtc.getTime();
3374
+ for (const t of tithis) {
3375
+ t.endTime = toLocalOrNull(t.endTime);
3376
+ t.startTime = toLocalOrNull(t.startTime);
3377
+ }
3378
+ for (const n of nakshatras) {
3379
+ n.endTime = toLocalOrNull(n.endTime);
3380
+ n.startTime = toLocalOrNull(n.startTime);
3381
+ }
3382
+ for (const y of yogas) {
3383
+ y.endTime = toLocalOrNull(y.endTime);
3384
+ y.startTime = toLocalOrNull(y.startTime);
3385
+ }
3386
+ for (const k of karanas) {
3387
+ k.endTime = toLocalOrNull(k.endTime);
3388
+ k.startTime = toLocalOrNull(k.startTime);
3389
+ }
3390
+ return {
3391
+ date,
3392
+ location,
3393
+ timezone: offsetMinutes,
3394
+ sunrise: toLocal(sunriseUtc),
3395
+ sunset: toLocal(sunsetUtc),
3396
+ nextSunrise: toLocal(nextSunriseUtc),
3397
+ dayDurationMinutes: Math.round(dayDurationMs / 6e4),
3398
+ nightDurationMinutes: Math.round(nightDurationMs / 6e4),
3399
+ tithis,
3400
+ nakshatras,
3401
+ yogas,
3402
+ karanas,
3403
+ vara,
3404
+ rahuKalam: convertTimePeriod(rahuKalam),
3405
+ gulikaKalam: convertTimePeriod(gulikaKalam),
3406
+ yamaganda: convertTimePeriod(yamaganda),
3407
+ abhijitMuhurta: convertTimePeriod(abhijitMuhurta),
3408
+ ayanamsa: ayanamsaValue,
3409
+ siderealSunAtSunrise,
3410
+ siderealMoonAtSunrise,
3411
+ masa
3412
+ };
3413
+ }
3414
+ /*! Bundled license information:
3415
+
3416
+ astronomy-engine/esm/astronomy.js:
3417
+ (**
3418
+ @preserve
3419
+
3420
+ Astronomy library for JavaScript (browser and Node.js).
3421
+ https://github.com/cosinekitty/astronomy
3422
+
3423
+ MIT License
3424
+
3425
+ Copyright (c) 2019-2023 Don Cross <cosinekitty@gmail.com>
3426
+
3427
+ Permission is hereby granted, free of charge, to any person obtaining a copy
3428
+ of this software and associated documentation files (the "Software"), to deal
3429
+ in the Software without restriction, including without limitation the rights
3430
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3431
+ copies of the Software, and to permit persons to whom the Software is
3432
+ furnished to do so, subject to the following conditions:
3433
+
3434
+ The above copyright notice and this permission notice shall be included in all
3435
+ copies or substantial portions of the Software.
3436
+
3437
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3438
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3439
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3440
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3441
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3442
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3443
+ SOFTWARE.
3444
+ *)
3445
+ (**
3446
+ * @fileoverview Astronomy calculation library for browser scripting and Node.js.
3447
+ * @author Don Cross <cosinekitty@gmail.com>
3448
+ * @license MIT
3449
+ *)
3450
+ */
3451
+
3452
+ exports.PanchangError = PanchangError;
3453
+ exports.computeAbhijitMuhurta = computeAbhijitMuhurta;
3454
+ exports.computeGulikaKalam = computeGulikaKalam;
3455
+ exports.computeRahuKalam = computeRahuKalam;
3456
+ exports.computeYamaganda = computeYamaganda;
3457
+ exports.getAyanamsa = computeAyanamsa;
3458
+ exports.getDailyPanchang = getDailyPanchang;
3459
+ exports.getInstantPanchang = getInstantPanchang;
3460
+ exports.getSiderealMoonLongitude = getSiderealMoonLongitude;
3461
+ exports.getSiderealSunLongitude = getSiderealSunLongitude;
3462
+ exports.getSunrise = computeSunrise;
3463
+ exports.getSunset = computeSunset;
3464
+ //# sourceMappingURL=index.cjs.map
3465
+ //# sourceMappingURL=index.cjs.map