kaabalah 6.14.0 → 6.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +15 -0
  2. package/dist/astrology/index.d.mts +39 -1
  3. package/dist/astrology/index.d.ts +39 -1
  4. package/dist/astrology/index.js +75 -53
  5. package/dist/astrology/index.mjs +3 -1
  6. package/dist/chunk-2IC6H3FI.js +1600 -0
  7. package/dist/chunk-2IC6H3FI.js.map +1 -0
  8. package/dist/{chunk-RAQDVWNK.mjs → chunk-3JMY4U4S.mjs} +546 -3
  9. package/dist/chunk-3JMY4U4S.mjs.map +1 -0
  10. package/dist/chunk-3QN5V3DP.js +4737 -0
  11. package/dist/chunk-3QN5V3DP.js.map +1 -0
  12. package/dist/{chunk-UNXDDLZS.js → chunk-6LZOAU6E.js} +548 -3
  13. package/dist/chunk-6LZOAU6E.js.map +1 -0
  14. package/dist/{chunk-LXJ3THNW.mjs → chunk-7JWBIAUF.mjs} +12 -9
  15. package/dist/chunk-7JWBIAUF.mjs.map +1 -0
  16. package/dist/{chunk-Q7YAKPBH.js → chunk-7OWGGDRF.js} +80 -1015
  17. package/dist/chunk-7OWGGDRF.js.map +1 -0
  18. package/dist/{chunk-2WCC2KCJ.js → chunk-BALOSCWQ.mjs} +22 -3
  19. package/dist/chunk-BALOSCWQ.mjs.map +1 -0
  20. package/dist/{chunk-4PVIDUPI.js → chunk-BKFHIKFY.js} +647 -187
  21. package/dist/chunk-BKFHIKFY.js.map +1 -0
  22. package/dist/{chunk-7C7VO76O.js → chunk-CMXTZKWW.js} +574 -147
  23. package/dist/chunk-CMXTZKWW.js.map +1 -0
  24. package/dist/{chunk-6GDEXIDI.js → chunk-HEZCZXQC.js} +25 -22
  25. package/dist/chunk-HEZCZXQC.js.map +1 -0
  26. package/dist/chunk-ICUDGCYX.js +15 -0
  27. package/dist/chunk-ICUDGCYX.js.map +1 -0
  28. package/dist/chunk-IT7GZ337.mjs +4679 -0
  29. package/dist/chunk-IT7GZ337.mjs.map +1 -0
  30. package/dist/{chunk-NOZKIUGP.mjs → chunk-J5Y325TG.mjs} +80 -1015
  31. package/dist/chunk-J5Y325TG.mjs.map +1 -0
  32. package/dist/chunk-JY4QC6FR.js +2214 -0
  33. package/dist/chunk-JY4QC6FR.js.map +1 -0
  34. package/dist/{chunk-URDMOQRN.mjs → chunk-L5EYUE4B.js} +27 -2
  35. package/dist/chunk-L5EYUE4B.js.map +1 -0
  36. package/dist/{chunk-QQN54SLY.mjs → chunk-LQVHJ3VY.mjs} +454 -32
  37. package/dist/chunk-LQVHJ3VY.mjs.map +1 -0
  38. package/dist/{chunk-WA52P72D.mjs → chunk-MWLSSRHL.mjs} +628 -168
  39. package/dist/chunk-MWLSSRHL.mjs.map +1 -0
  40. package/dist/{chunk-CW6QDSMF.js → chunk-PBBF5DKC.js} +88 -21
  41. package/dist/chunk-PBBF5DKC.js.map +1 -0
  42. package/dist/chunk-RUE6NTVT.mjs +2211 -0
  43. package/dist/chunk-RUE6NTVT.mjs.map +1 -0
  44. package/dist/{chunk-X5HGLMEF.mjs → chunk-UO2RQQZO.mjs} +770 -3
  45. package/dist/chunk-UO2RQQZO.mjs.map +1 -0
  46. package/dist/chunk-W2N7STO3.mjs +13 -0
  47. package/dist/chunk-W2N7STO3.mjs.map +1 -0
  48. package/dist/chunk-WP5MRAYG.mjs +6289 -0
  49. package/dist/chunk-WP5MRAYG.mjs.map +1 -0
  50. package/dist/chunk-WRF3EORB.js +6333 -0
  51. package/dist/chunk-WRF3EORB.js.map +1 -0
  52. package/dist/{chunk-OSMB2MJR.mjs → chunk-Z3JZ5DZN.mjs} +68 -3
  53. package/dist/chunk-Z3JZ5DZN.mjs.map +1 -0
  54. package/dist/cli.js +39837 -28550
  55. package/dist/cli.js.map +1 -1
  56. package/dist/core/index.d.mts +24 -1
  57. package/dist/core/index.d.ts +24 -1
  58. package/dist/core/index.js +67 -53
  59. package/dist/core/index.mjs +4 -2
  60. package/dist/{data-BRi5-xg_.d.ts → data-Dle4z75J.d.ts} +1 -1
  61. package/dist/{data-BoQrkrWX.d.mts → data-DvKCOgjb.d.mts} +1 -1
  62. package/dist/gematria/index.d.mts +153 -1
  63. package/dist/gematria/index.d.ts +153 -1
  64. package/dist/gematria/index.js +15 -5
  65. package/dist/gematria/index.mjs +4 -2
  66. package/dist/iching/index.d.mts +802 -30
  67. package/dist/iching/index.d.ts +802 -30
  68. package/dist/iching/index.js +72 -38
  69. package/dist/iching/index.mjs +5 -3
  70. package/dist/ifa/index.d.mts +44 -1
  71. package/dist/ifa/index.d.ts +44 -1
  72. package/dist/ifa/index.js +11 -2
  73. package/dist/ifa/index.mjs +2 -1
  74. package/dist/index.d.mts +8 -8
  75. package/dist/index.d.ts +8 -8
  76. package/dist/index.js +375 -265
  77. package/dist/index.mjs +12 -10
  78. package/dist/numerology/index.d.mts +872 -1
  79. package/dist/numerology/index.d.ts +872 -1
  80. package/dist/numerology/index.js +28 -18
  81. package/dist/numerology/index.mjs +5 -3
  82. package/dist/semantic/index.d.mts +94 -17
  83. package/dist/semantic/index.d.ts +94 -17
  84. package/dist/semantic/index.js +57 -35
  85. package/dist/semantic/index.mjs +9 -7
  86. package/dist/tarot/index.d.mts +15 -10
  87. package/dist/tarot/index.d.ts +15 -10
  88. package/dist/tarot/index.js +32 -30
  89. package/dist/tarot/index.mjs +5 -3
  90. package/dist/visual/index.js +48 -46
  91. package/dist/visual/index.mjs +5 -3
  92. package/package.json +7 -3
  93. package/dist/chunk-2WCC2KCJ.js.map +0 -1
  94. package/dist/chunk-47BAJUYW.js +0 -830
  95. package/dist/chunk-47BAJUYW.js.map +0 -1
  96. package/dist/chunk-4PVIDUPI.js.map +0 -1
  97. package/dist/chunk-6GDEXIDI.js.map +0 -1
  98. package/dist/chunk-7C7VO76O.js.map +0 -1
  99. package/dist/chunk-CW6QDSMF.js.map +0 -1
  100. package/dist/chunk-LXJ3THNW.mjs.map +0 -1
  101. package/dist/chunk-NOZKIUGP.mjs.map +0 -1
  102. package/dist/chunk-OSMB2MJR.mjs.map +0 -1
  103. package/dist/chunk-OZUEDZ4U.mjs +0 -3699
  104. package/dist/chunk-OZUEDZ4U.mjs.map +0 -1
  105. package/dist/chunk-PEHDLSUH.mjs +0 -2227
  106. package/dist/chunk-PEHDLSUH.mjs.map +0 -1
  107. package/dist/chunk-Q7YAKPBH.js.map +0 -1
  108. package/dist/chunk-QQN54SLY.mjs.map +0 -1
  109. package/dist/chunk-RAQDVWNK.mjs.map +0 -1
  110. package/dist/chunk-SWWLTDR6.js +0 -2280
  111. package/dist/chunk-SWWLTDR6.js.map +0 -1
  112. package/dist/chunk-UNXDDLZS.js.map +0 -1
  113. package/dist/chunk-URDMOQRN.mjs.map +0 -1
  114. package/dist/chunk-WA52P72D.mjs.map +0 -1
  115. package/dist/chunk-X5HGLMEF.mjs.map +0 -1
  116. package/dist/chunk-XWVT3SI7.js +0 -3735
  117. package/dist/chunk-XWVT3SI7.js.map +0 -1
@@ -1,2280 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk4337NVKS_js = require('./chunk-4337NVKS.js');
4
-
5
- // wasm/build/swisseph.node.wasm?url
6
- var swisseph_node_default = "./swisseph.node-GPVFDOB6.wasm?url";
7
-
8
- // wasm/build/swisseph.web.wasm?url
9
- var swisseph_web_default = "./swisseph.web-GPVFDOB6.wasm?url";
10
-
11
- // wasm/src/swisseph.ts
12
- var Planet = /* @__PURE__ */ ((Planet2) => {
13
- Planet2[Planet2["SUN"] = 0] = "SUN";
14
- Planet2[Planet2["MOON"] = 1] = "MOON";
15
- Planet2[Planet2["MERCURY"] = 2] = "MERCURY";
16
- Planet2[Planet2["VENUS"] = 3] = "VENUS";
17
- Planet2[Planet2["MARS"] = 4] = "MARS";
18
- Planet2[Planet2["JUPITER"] = 5] = "JUPITER";
19
- Planet2[Planet2["SATURN"] = 6] = "SATURN";
20
- Planet2[Planet2["URANUS"] = 7] = "URANUS";
21
- Planet2[Planet2["NEPTUNE"] = 8] = "NEPTUNE";
22
- Planet2[Planet2["PLUTO"] = 9] = "PLUTO";
23
- Planet2[Planet2["MEAN_NODE"] = 10] = "MEAN_NODE";
24
- Planet2[Planet2["TRUE_NODE"] = 11] = "TRUE_NODE";
25
- Planet2[Planet2["LILITH_MEAN"] = 12] = "LILITH_MEAN";
26
- Planet2[Planet2["LILITH_TRUE"] = 13] = "LILITH_TRUE";
27
- Planet2[Planet2["CHIRON"] = 15] = "CHIRON";
28
- return Planet2;
29
- })(Planet || {});
30
- var VirtualNodes = /* @__PURE__ */ ((VirtualNodes2) => {
31
- VirtualNodes2["PARS_FORTUNAE"] = "parsFortunae";
32
- return VirtualNodes2;
33
- })(VirtualNodes || {});
34
- var PLANET_AND_NODE_NAMES = {
35
- [0 /* SUN */]: "Sun",
36
- [1 /* MOON */]: "Moon",
37
- [2 /* MERCURY */]: "Mercury",
38
- [3 /* VENUS */]: "Venus",
39
- [4 /* MARS */]: "Mars",
40
- [5 /* JUPITER */]: "Jupiter",
41
- [6 /* SATURN */]: "Saturn",
42
- [7 /* URANUS */]: "Uranus",
43
- [8 /* NEPTUNE */]: "Neptune",
44
- [9 /* PLUTO */]: "Pluto",
45
- [10 /* MEAN_NODE */]: "Mean Node",
46
- [11 /* TRUE_NODE */]: "True Node",
47
- [12 /* LILITH_MEAN */]: "Lilith Mean",
48
- [13 /* LILITH_TRUE */]: "Lilith True",
49
- [15 /* CHIRON */]: "Chiron",
50
- ["parsFortunae" /* PARS_FORTUNAE */]: "Wheel of Fortune"
51
- };
52
- var HouseSystem = /* @__PURE__ */ ((HouseSystem2) => {
53
- HouseSystem2["PLACIDUS"] = "P";
54
- HouseSystem2["KOCH"] = "K";
55
- HouseSystem2["PORPHYRIUS"] = "O";
56
- HouseSystem2["REGIOMONTANUS"] = "R";
57
- HouseSystem2["CAMPANUS"] = "C";
58
- HouseSystem2["EQUAL"] = "E";
59
- HouseSystem2["WHOLE_SIGN"] = "W";
60
- HouseSystem2["MERIDIAN"] = "X";
61
- HouseSystem2["MORINUS"] = "M";
62
- HouseSystem2["KRUSINSKI"] = "U";
63
- HouseSystem2["ALCABITIUS"] = "B";
64
- return HouseSystem2;
65
- })(HouseSystem || {});
66
- var CalcFlag = /* @__PURE__ */ ((CalcFlag2) => {
67
- CalcFlag2[CalcFlag2["JPL_EPH"] = 1] = "JPL_EPH";
68
- CalcFlag2[CalcFlag2["SWISS_EPH"] = 2] = "SWISS_EPH";
69
- CalcFlag2[CalcFlag2["MOSHIER"] = 4] = "MOSHIER";
70
- CalcFlag2[CalcFlag2["HELIOCENTRIC"] = 8] = "HELIOCENTRIC";
71
- CalcFlag2[CalcFlag2["TRUE_POS"] = 16] = "TRUE_POS";
72
- CalcFlag2[CalcFlag2["J2000"] = 32] = "J2000";
73
- CalcFlag2[CalcFlag2["NONUT"] = 64] = "NONUT";
74
- CalcFlag2[CalcFlag2["SPEED3"] = 128] = "SPEED3";
75
- CalcFlag2[CalcFlag2["SPEED"] = 256] = "SPEED";
76
- CalcFlag2[CalcFlag2["EQUATORIAL"] = 2048] = "EQUATORIAL";
77
- CalcFlag2[CalcFlag2["TOPOCTR"] = 32768] = "TOPOCTR";
78
- CalcFlag2[CalcFlag2["SIDEREAL"] = 65536] = "SIDEREAL";
79
- return CalcFlag2;
80
- })(CalcFlag || {});
81
- var RiseTransitFlag = /* @__PURE__ */ ((RiseTransitFlag2) => {
82
- RiseTransitFlag2[RiseTransitFlag2["RISE"] = 1] = "RISE";
83
- RiseTransitFlag2[RiseTransitFlag2["SET"] = 2] = "SET";
84
- RiseTransitFlag2[RiseTransitFlag2["UPPER_MERIDIAN"] = 4] = "UPPER_MERIDIAN";
85
- RiseTransitFlag2[RiseTransitFlag2["LOWER_MERIDIAN"] = 8] = "LOWER_MERIDIAN";
86
- RiseTransitFlag2[RiseTransitFlag2["DISC_CENTER"] = 256] = "DISC_CENTER";
87
- RiseTransitFlag2[RiseTransitFlag2["NO_REFRACTION"] = 512] = "NO_REFRACTION";
88
- return RiseTransitFlag2;
89
- })(RiseTransitFlag || {});
90
- var SE_ECL2HOR = 0;
91
- var SE_EQU2HOR = 1;
92
- var SE_AST_OFFSET = 1e4;
93
- var BODY = {
94
- MEAN_APOGEE: 12,
95
- // Lilith mean
96
- OSC_APOGEE: 13};
97
- var normalizeAngle = (deg) => (deg % 360 + 360) % 360;
98
- var SwissEph = class {
99
- /**
100
- * Constructor that accepts a pre-initialized Swiss Ephemeris module
101
- */
102
- constructor(module) {
103
- this.swe_julday = null;
104
- this.swe_calc_ut = null;
105
- this.swe_houses = null;
106
- this.swe_house_pos = null;
107
- this.swe_set_ephe_path = null;
108
- this.swe_close = null;
109
- this.swe_set_topo = null;
110
- this.swe_set_sid_mode = null;
111
- this.swe_azalt_fn = null;
112
- this.swe_rise_trans_fn = null;
113
- this.module = module;
114
- this.swe_julday = this.module.cwrap("swe_julday", "number", [
115
- "number",
116
- "number",
117
- "number",
118
- "number",
119
- "number"
120
- ]);
121
- this.swe_calc_ut = this.module.cwrap("swe_calc_ut", "number", [
122
- "number",
123
- "number",
124
- "number",
125
- "number",
126
- "number"
127
- ]);
128
- this.swe_houses = this.module.cwrap("swe_houses", "number", [
129
- "number",
130
- "number",
131
- "number",
132
- "number",
133
- "number",
134
- "number"
135
- ]);
136
- this.swe_house_pos = this.module.cwrap(
137
- "swe_house_pos",
138
- "number",
139
- ["number", "number", "number", "string", "number", "number"]
140
- );
141
- this.swe_set_ephe_path = this.module.cwrap(
142
- "swe_set_ephe_path",
143
- null,
144
- ["number"]
145
- );
146
- this.swe_close = this.module.cwrap("swe_close", null, []);
147
- this.swe_set_topo = this.module.cwrap("swe_set_topo", null, [
148
- "number",
149
- "number",
150
- "number"
151
- ]);
152
- this.swe_set_sid_mode = this.module.cwrap(
153
- "swe_set_sid_mode",
154
- null,
155
- ["number", "number", "number"]
156
- );
157
- this.swe_azalt_fn = this.module.cwrap(
158
- "swe_azalt",
159
- null,
160
- ["number", "number", "number", "number", "number", "number", "number"]
161
- );
162
- this.swe_rise_trans_fn = this.module.cwrap(
163
- "swe_rise_trans",
164
- "number",
165
- ["number", "number", "number", "number", "number", "number", "number", "number", "number", "number"]
166
- );
167
- }
168
- checkInitialized() {
169
- if (!this.module) {
170
- throw new Error("Swiss Ephemeris module not available.");
171
- }
172
- }
173
- /**
174
- * Sets the path to the ephemeris data files.
175
- * @param path - The path to the directory containing ephemeris files.
176
- */
177
- setEphemerisPath(path) {
178
- this.checkInitialized();
179
- if (path && this.swe_set_ephe_path) {
180
- const pathPtr = this.module._malloc(path.length + 1);
181
- if (!pathPtr) {
182
- throw new Error("Failed to allocate memory for ephemeris path");
183
- }
184
- this.module.stringToUTF8(path, pathPtr, path.length + 1);
185
- this.swe_set_ephe_path(pathPtr);
186
- this.module._free(pathPtr);
187
- }
188
- }
189
- /**
190
- * Calculate Julian day number for a given date and time
191
- */
192
- getJulianDay(date) {
193
- this.checkInitialized();
194
- if (!this.swe_julday) {
195
- throw new Error("Julian day calculation function not available");
196
- }
197
- const year = date.getUTCFullYear();
198
- const month = date.getUTCMonth() + 1;
199
- const day = date.getUTCDate();
200
- const hour = date.getUTCHours() + date.getUTCMinutes() / 60 + date.getUTCSeconds() / 3600;
201
- return this.swe_julday(year, month, day, hour, 1);
202
- }
203
- /**
204
- * Calculate planet position at a given Julian day
205
- */
206
- calculatePlanetPosition(julday, planet, flags = 2 /* SWISS_EPH */) {
207
- this.checkInitialized();
208
- if (!this.swe_calc_ut || !this.module) {
209
- throw new Error("Planet calculation function not available");
210
- }
211
- const resultPtr = this.module._malloc(6 * 8);
212
- if (!resultPtr) {
213
- throw new Error("Failed to allocate memory for planet position");
214
- }
215
- const ERR_BYTES = 512;
216
- const errPtr = this.module._malloc(ERR_BYTES);
217
- if (!errPtr) {
218
- this.module._free(resultPtr);
219
- throw new Error("Failed to allocate memory for error buffer");
220
- }
221
- this.module.HEAP8.fill(0, errPtr, errPtr + ERR_BYTES);
222
- try {
223
- let ret = this.swe_calc_ut(julday, planet, flags, resultPtr, errPtr);
224
- if (ret < 0) {
225
- const msg = this.module.UTF8ToString(errPtr);
226
- throw new Error(msg && msg.length ? msg : `Swiss Ephemeris calculation failed with error code ${ret}`);
227
- }
228
- const position = {
229
- longitude: this.module.getValue(resultPtr, "double"),
230
- latitude: this.module.getValue(resultPtr + 8, "double"),
231
- distance: this.module.getValue(resultPtr + 16, "double")
232
- };
233
- if (flags & 256 /* SPEED */) {
234
- position.longitudeSpeed = this.module.getValue(resultPtr + 24, "double");
235
- position.latitudeSpeed = this.module.getValue(resultPtr + 32, "double");
236
- position.distanceSpeed = this.module.getValue(resultPtr + 40, "double");
237
- }
238
- return position;
239
- } finally {
240
- this.module._free(errPtr);
241
- this.module._free(resultPtr);
242
- }
243
- }
244
- /**
245
- * Calculate houses for a given date, location, and house system
246
- */
247
- calculateHouses(julday, latitude, longitude, hsys = "P" /* PLACIDUS */) {
248
- this.checkInitialized();
249
- if (!this.swe_houses || !this.module) {
250
- throw new Error("Houses calculation function not available");
251
- }
252
- if (latitude < -90 || latitude > 90) {
253
- throw new Error("Latitude must be between -90 and 90 degrees");
254
- }
255
- if (longitude < -180 || longitude > 180) {
256
- throw new Error("Longitude must be between -180 and 180 degrees");
257
- }
258
- const HOUSES_DOUBLES = 13;
259
- const ASCMC_DOUBLES = 10;
260
- const BYTES_PER_F64 = 8;
261
- const totalBytes = (HOUSES_DOUBLES + ASCMC_DOUBLES) * BYTES_PER_F64;
262
- const memoryPtr = this.module._malloc(totalBytes);
263
- if (!memoryPtr)
264
- throw new Error("Memory allocation failed");
265
- const housesPtr = memoryPtr;
266
- const ascmcPtr = memoryPtr + HOUSES_DOUBLES * BYTES_PER_F64;
267
- try {
268
- const hsysCode = hsys.charCodeAt(0);
269
- const ret = this.swe_houses(
270
- julday,
271
- latitude,
272
- longitude,
273
- hsysCode,
274
- housesPtr,
275
- ascmcPtr
276
- );
277
- if (ret < 0) {
278
- throw new Error(`Houses calculation failed with error code ${ret}`);
279
- }
280
- const houses = new Array(HOUSES_DOUBLES);
281
- for (let i = 0; i < HOUSES_DOUBLES; i++) {
282
- houses[i] = this.module.getValue(
283
- housesPtr + i * BYTES_PER_F64,
284
- "double"
285
- );
286
- }
287
- const ascendant = this.module.getValue(
288
- ascmcPtr + 0 * BYTES_PER_F64,
289
- "double"
290
- );
291
- const mc = this.module.getValue(ascmcPtr + 1 * BYTES_PER_F64, "double");
292
- const armc = this.module.getValue(ascmcPtr + 2 * BYTES_PER_F64, "double");
293
- const vertex = this.module.getValue(
294
- ascmcPtr + 3 * BYTES_PER_F64,
295
- "double"
296
- );
297
- const equasc = this.module.getValue(
298
- ascmcPtr + 4 * BYTES_PER_F64,
299
- "double"
300
- );
301
- const coasc1 = this.module.getValue(
302
- ascmcPtr + 5 * BYTES_PER_F64,
303
- "double"
304
- );
305
- const coasc2 = this.module.getValue(
306
- ascmcPtr + 6 * BYTES_PER_F64,
307
- "double"
308
- );
309
- const polasc = this.module.getValue(
310
- ascmcPtr + 7 * BYTES_PER_F64,
311
- "double"
312
- );
313
- return {
314
- ascendant,
315
- mc,
316
- houses,
317
- ascmc: {
318
- armc,
319
- vertex,
320
- equasc,
321
- coasc1,
322
- coasc2,
323
- polasc
324
- }
325
- };
326
- } finally {
327
- this.module._free(memoryPtr);
328
- }
329
- }
330
- /**
331
- * Clean up and close the Swiss Ephemeris
332
- */
333
- close() {
334
- this.checkInitialized();
335
- if (this.swe_close) {
336
- this.swe_close();
337
- }
338
- }
339
- /**
340
- * Set topocentric observer
341
- */
342
- setTopocentric(longitude, latitude, altitudeMeters = 0) {
343
- this.checkInitialized();
344
- if (!this.swe_set_topo) {
345
- throw new Error("Topocentric calculation function not available");
346
- }
347
- this.swe_set_topo(longitude, latitude, altitudeMeters);
348
- }
349
- /**
350
- * Set sidereal mode
351
- * Ex.: mode=1 (Lahiri). See Swiss Ephemeris mode table.
352
- */
353
- setSiderealMode(mode, t0 = 0, ayan_t0 = 0) {
354
- this.checkInitialized();
355
- this.swe_set_sid_mode?.(mode, t0, ayan_t0);
356
- }
357
- /**
358
- * Asteroid by MPC number
359
- */
360
- calculateAsteroidPosition(julday, mpcNumber, flags = 2 /* SWISS_EPH */) {
361
- return this.calculatePlanetPosition(
362
- julday,
363
- SE_AST_OFFSET + mpcNumber,
364
- flags
365
- );
366
- }
367
- /**
368
- * Lilith mean (12) and true (13)
369
- */
370
- calculateLilith(julday, kind = "mean", flags = 2 /* SWISS_EPH */) {
371
- const id = kind === "mean" ? BODY.MEAN_APOGEE : BODY.OSC_APOGEE;
372
- return this.calculatePlanetPosition(julday, id, flags);
373
- }
374
- /**
375
- * Convert ecliptic (or equatorial) coordinates to horizon coordinates.
376
- * Returns azimuth (0=south, 90=west, 180=north, 270=east) and altitude.
377
- */
378
- azalt(julday, longitude, latitude, altitude, xinLon, xinLat, xinDist, fromEquatorial = false) {
379
- this.checkInitialized();
380
- if (!this.swe_azalt_fn) {
381
- throw new Error("swe_azalt function not available");
382
- }
383
- const BYTES = 8;
384
- const geoPtr = this.module._malloc(3 * BYTES);
385
- const xinPtr = this.module._malloc(3 * BYTES);
386
- const xazPtr = this.module._malloc(3 * BYTES);
387
- if (!geoPtr || !xinPtr || !xazPtr) {
388
- if (geoPtr)
389
- this.module._free(geoPtr);
390
- if (xinPtr)
391
- this.module._free(xinPtr);
392
- if (xazPtr)
393
- this.module._free(xazPtr);
394
- throw new Error("Memory allocation failed for azalt");
395
- }
396
- try {
397
- this.module.setValue(geoPtr, longitude, "double");
398
- this.module.setValue(geoPtr + BYTES, latitude, "double");
399
- this.module.setValue(geoPtr + 2 * BYTES, altitude, "double");
400
- this.module.setValue(xinPtr, xinLon, "double");
401
- this.module.setValue(xinPtr + BYTES, xinLat, "double");
402
- this.module.setValue(xinPtr + 2 * BYTES, xinDist, "double");
403
- this.swe_azalt_fn(
404
- julday,
405
- fromEquatorial ? SE_EQU2HOR : SE_ECL2HOR,
406
- geoPtr,
407
- 0,
408
- // atpress (0 = default 1013.25 mbar)
409
- 0,
410
- // attemp (0 = default 15°C)
411
- xinPtr,
412
- xazPtr
413
- );
414
- return {
415
- azimuth: this.module.getValue(xazPtr, "double"),
416
- trueAltitude: this.module.getValue(xazPtr + BYTES, "double"),
417
- apparentAltitude: this.module.getValue(xazPtr + 2 * BYTES, "double")
418
- };
419
- } finally {
420
- this.module._free(geoPtr);
421
- this.module._free(xinPtr);
422
- this.module._free(xazPtr);
423
- }
424
- }
425
- /**
426
- * Find the next rise, set, or meridian transit of a planet.
427
- * Returns the Julian day of the event.
428
- */
429
- riseTransit(julday, planet, rsmi, longitude, latitude, altitude = 0, flags = 2 /* SWISS_EPH */) {
430
- this.checkInitialized();
431
- if (!this.swe_rise_trans_fn) {
432
- throw new Error("swe_rise_trans function not available");
433
- }
434
- const BYTES = 8;
435
- const geoPtr = this.module._malloc(3 * BYTES);
436
- const tretPtr = this.module._malloc(BYTES);
437
- const ERR_BYTES = 512;
438
- const errPtr = this.module._malloc(ERR_BYTES);
439
- if (!geoPtr || !tretPtr || !errPtr) {
440
- if (geoPtr)
441
- this.module._free(geoPtr);
442
- if (tretPtr)
443
- this.module._free(tretPtr);
444
- if (errPtr)
445
- this.module._free(errPtr);
446
- throw new Error("Memory allocation failed for riseTransit");
447
- }
448
- this.module.HEAP8.fill(0, errPtr, errPtr + ERR_BYTES);
449
- try {
450
- this.module.setValue(geoPtr, longitude, "double");
451
- this.module.setValue(geoPtr + BYTES, latitude, "double");
452
- this.module.setValue(geoPtr + 2 * BYTES, altitude, "double");
453
- const ret = this.swe_rise_trans_fn(
454
- julday,
455
- planet,
456
- 0,
457
- // starname pointer (0 = planet, not fixed star)
458
- flags,
459
- rsmi,
460
- geoPtr,
461
- 0,
462
- // atpress
463
- 0,
464
- // attemp
465
- tretPtr,
466
- errPtr
467
- );
468
- if (ret < 0) {
469
- const msg = this.module.UTF8ToString(errPtr);
470
- throw new Error(msg || `swe_rise_trans failed with code ${ret}`);
471
- }
472
- return this.module.getValue(tretPtr, "double");
473
- } finally {
474
- this.module._free(geoPtr);
475
- this.module._free(tretPtr);
476
- this.module._free(errPtr);
477
- }
478
- }
479
- };
480
- function parsFortunae(asc, sunLon, moonLon, diurnal) {
481
- const val = diurnal ? asc + moonLon - sunLon : asc + sunLon - moonLon;
482
- return normalizeAngle(val);
483
- }
484
-
485
- // src/astrology/swisseph.ts
486
- var swissEph = null;
487
- var DEFAULT_FLAGS = 2 /* SWISS_EPH */ | 256 /* SPEED */;
488
- var REQUIRED_EPHE_FILES = ["seas_18.se1", "semo_18.se1", "sepl_18.se1"];
489
- var NODE_EPHE_MOUNT_POINT = "/ephefs";
490
- var NODE_EPHE_MEMFS_PATH = "/ephemem";
491
- function emitRuntimeNotice(message) {
492
- if (typeof process !== "undefined" && process.stderr && typeof process.stderr.write === "function") {
493
- process.stderr.write(`${message}
494
- `);
495
- return;
496
- }
497
- console.info(message);
498
- }
499
- var SWISS_EPH_RUNTIME_WASM_ENV_KEYS = [
500
- "KAABALAH_SWISSEPH_WASM_PATH",
501
- "KAABALAH_WASM_PATH"
502
- ];
503
- var SWISS_EPH_RUNTIME_EPHE_ENV_KEYS = [
504
- "KAABALAH_SWISSEPH_EPHE_PATH",
505
- "KAABALAH_EPHE_PATH"
506
- ];
507
- function getRuntimeEnv(env) {
508
- if (env) {
509
- return env;
510
- }
511
- if (typeof process !== "undefined" && process.env) {
512
- return process.env;
513
- }
514
- return {};
515
- }
516
- function firstDefinedEnvValue(env, keys) {
517
- for (const key of keys) {
518
- const value = env[key];
519
- if (typeof value === "string" && value.length > 0) {
520
- return value;
521
- }
522
- }
523
- return void 0;
524
- }
525
- function getBundledNodeSwissEphAssets(options) {
526
- if (options.bundledNodeWasmPath && options.bundledNodeEphePath) {
527
- return {
528
- wasmPaths: [options.bundledNodeWasmPath],
529
- ephePaths: [options.bundledNodeEphePath]
530
- };
531
- }
532
- const resolvePath = options.nodePathResolve ?? ((...paths) => chunk4337NVKS_js.__require("path").resolve(...paths));
533
- return {
534
- wasmPaths: [
535
- options.bundledNodeWasmPath,
536
- resolvePath(__dirname, swisseph_node_default),
537
- resolvePath(__dirname, "../../wasm/build/swisseph.node.wasm"),
538
- resolvePath(__dirname, "../wasm/build/swisseph.node.wasm")
539
- ].filter((value) => typeof value === "string"),
540
- ephePaths: [
541
- options.bundledNodeEphePath,
542
- resolvePath(__dirname, "../../ephe"),
543
- resolvePath(__dirname, "../ephe")
544
- ].filter((value) => typeof value === "string")
545
- };
546
- }
547
- function getBundledBrowserSwissEphAssets(options) {
548
- return {
549
- wasmPath: options.bundledBrowserWasmPath ?? swisseph_web_default,
550
- ephePath: options.bundledBrowserEphePath ?? "../ephe"
551
- };
552
- }
553
- function formatCandidatePaths(paths) {
554
- return paths.length > 0 ? paths.join(", ") : "(none)";
555
- }
556
- function resolveBundledRuntimeAssetPath(label, bundledPaths, existsSync) {
557
- for (const bundledPath of bundledPaths) {
558
- if (existsSync(bundledPath)) {
559
- return {
560
- path: bundledPath,
561
- source: "bundled"
562
- };
563
- }
564
- }
565
- throw new Error(
566
- `Unable to resolve Swiss Ephemeris ${label}. Bundled paths checked: ${formatCandidatePaths(
567
- bundledPaths
568
- )}.`
569
- );
570
- }
571
- function resolveRuntimeAssetPath(label, explicitPath, envPath, candidatePaths, bundledPaths, existsSync) {
572
- if (explicitPath) {
573
- if (!existsSync(explicitPath)) {
574
- throw new Error(
575
- `Swiss Ephemeris ${label} override does not exist: "${explicitPath}".`
576
- );
577
- }
578
- return {
579
- path: explicitPath,
580
- source: "explicit"
581
- };
582
- }
583
- if (envPath) {
584
- if (!existsSync(envPath)) {
585
- throw new Error(
586
- `Swiss Ephemeris ${label} from environment does not exist: "${envPath}".`
587
- );
588
- }
589
- return {
590
- path: envPath,
591
- source: "env"
592
- };
593
- }
594
- for (const candidatePath of candidatePaths) {
595
- if (existsSync(candidatePath)) {
596
- return {
597
- path: candidatePath,
598
- source: "candidate"
599
- };
600
- }
601
- }
602
- try {
603
- return resolveBundledRuntimeAssetPath(label, bundledPaths, existsSync);
604
- } catch (error) {
605
- throw new Error(
606
- `Unable to resolve Swiss Ephemeris ${label}. Checked candidate paths: ${formatCandidatePaths(
607
- candidatePaths
608
- )}. ${toError(error).message}`
609
- );
610
- }
611
- }
612
- function resolveSwissEphRuntimeAssetsInternal(options = {}) {
613
- const isBrowser = options.isBrowser ?? typeof window !== "undefined";
614
- if (isBrowser) {
615
- const bundledAssets2 = getBundledBrowserSwissEphAssets(options);
616
- return {
617
- wasmPath: options.wasmPath ?? bundledAssets2.wasmPath,
618
- ephePath: options.ephePath ?? bundledAssets2.ephePath,
619
- wasmPathSource: options.wasmPath ? "explicit" : "bundled",
620
- ephePathSource: options.ephePath ? "explicit" : "bundled"
621
- };
622
- }
623
- const env = getRuntimeEnv(options.env);
624
- const existsSync = options.existsSync ?? ((path) => chunk4337NVKS_js.__require("fs").existsSync(path));
625
- const bundledAssets = getBundledNodeSwissEphAssets(options);
626
- const envWasmPath = firstDefinedEnvValue(env, SWISS_EPH_RUNTIME_WASM_ENV_KEYS);
627
- const envEphePath = firstDefinedEnvValue(env, SWISS_EPH_RUNTIME_EPHE_ENV_KEYS);
628
- const resolvedWasm = resolveRuntimeAssetPath(
629
- "wasmPath",
630
- options.wasmPath,
631
- envWasmPath,
632
- options.wasmPathCandidates ?? [],
633
- bundledAssets.wasmPaths,
634
- existsSync
635
- );
636
- const resolvedEphe = resolveRuntimeAssetPath(
637
- "ephePath",
638
- options.ephePath,
639
- envEphePath,
640
- options.ephePathCandidates ?? [],
641
- bundledAssets.ephePaths,
642
- existsSync
643
- );
644
- return {
645
- wasmPath: resolvedWasm.path,
646
- ephePath: resolvedEphe.path,
647
- wasmPathSource: resolvedWasm.source,
648
- ephePathSource: resolvedEphe.source
649
- };
650
- }
651
- function resolveSwissEphRuntimeAssets(options = {}) {
652
- return resolveSwissEphRuntimeAssetsInternal(options);
653
- }
654
- function normalizeVirtualPath(path) {
655
- if (path === "/") {
656
- return path;
657
- }
658
- return path.replace(/\/+$/, "") || "/";
659
- }
660
- function joinVirtualPath(rootPath, leaf) {
661
- const normalizedRoot = normalizeVirtualPath(rootPath);
662
- return normalizedRoot === "/" ? `/${leaf}` : `${normalizedRoot}/${leaf}`;
663
- }
664
- function ensureVirtualDir(fs, path) {
665
- try {
666
- fs.mkdir(path);
667
- } catch {
668
- }
669
- }
670
- function safeAnalyzePath(fs, path) {
671
- if (!fs.analyzePath) {
672
- return null;
673
- }
674
- try {
675
- return fs.analyzePath(path).exists === true;
676
- } catch {
677
- return false;
678
- }
679
- }
680
- function safeReaddir(fs, path) {
681
- if (!fs.readdir) {
682
- return [];
683
- }
684
- try {
685
- return fs.readdir(path).filter((entry) => entry !== "." && entry !== "..");
686
- } catch {
687
- return [];
688
- }
689
- }
690
- function inspectVirtualEphemerisPath(fs, rootPath, requiredFiles = REQUIRED_EPHE_FILES) {
691
- if (!fs) {
692
- return {
693
- rootExists: null,
694
- visibleEntries: [],
695
- missingFiles: [...requiredFiles]
696
- };
697
- }
698
- const rootExists = safeAnalyzePath(fs, rootPath);
699
- const visibleEntries = safeReaddir(fs, rootPath);
700
- const missingFiles = requiredFiles.filter((file) => {
701
- const filePath = joinVirtualPath(rootPath, file);
702
- return !visibleEntries.includes(file) && safeAnalyzePath(fs, filePath) !== true;
703
- });
704
- return {
705
- rootExists,
706
- visibleEntries,
707
- missingFiles
708
- };
709
- }
710
- function formatVirtualPathCheck(label, path, check) {
711
- if (!check) {
712
- return `${label} "${path}" could not be inspected.`;
713
- }
714
- const exists = check.rootExists == null ? "unknown" : check.rootExists ? "yes" : "no";
715
- const visibleEntries = check.visibleEntries.length > 0 ? check.visibleEntries.join(", ") : "(none)";
716
- const missingFiles = check.missingFiles.length > 0 ? check.missingFiles.join(", ") : "(none)";
717
- return `${label} "${path}" exists: ${exists}; visible entries: ${visibleEntries}; missing required files: ${missingFiles}.`;
718
- }
719
- function normalizeHostFileData(data) {
720
- return data instanceof Uint8Array ? data : new Uint8Array(data);
721
- }
722
- function loadHostEphemerisFiles(ephePath, requiredFiles, nodeFs, pathModule) {
723
- const files = /* @__PURE__ */ new Map();
724
- for (const file of requiredFiles) {
725
- files.set(file, normalizeHostFileData(nodeFs.readFileSync(pathModule.join(ephePath, file))));
726
- }
727
- return files;
728
- }
729
- function writeEphemerisFilesToMemfs(fs, targetPath, files) {
730
- ensureVirtualDir(fs, targetPath);
731
- for (const [fileName, fileData] of files.entries()) {
732
- fs.writeFile(joinVirtualPath(targetPath, fileName), fileData);
733
- }
734
- }
735
- function toError(err) {
736
- return err instanceof Error ? err : new Error(String(err));
737
- }
738
- function buildEphemerisResolutionError(finalEphePath, requiredFiles, details) {
739
- const parts = [
740
- `Unable to resolve Swiss Ephemeris data files. Expected ${requiredFiles.join(", ")} under "${finalEphePath}".`
741
- ];
742
- if (details.mountAttempted) {
743
- parts.push(
744
- `${formatVirtualPathCheck("Mounted ephemeris path", details.mountPoint, details.mountCheck)} The NODEFS mount may have failed silently.`
745
- );
746
- }
747
- if (details.mountError) {
748
- parts.push(`Mounting the ephemeris directory failed: ${details.mountError.message}.`);
749
- }
750
- parts.push(formatVirtualPathCheck("Direct host ephemeris path", finalEphePath, details.hostCheck));
751
- if (details.memfsCheck) {
752
- parts.push(formatVirtualPathCheck("MEMFS ephemeris copy", details.memfsPath, details.memfsCheck));
753
- }
754
- if (details.hostReadError) {
755
- parts.push(`Reading host ephemeris files failed: ${details.hostReadError.message}.`);
756
- }
757
- parts.push(
758
- `Pass an explicit ephePath that contains ${requiredFiles.join(", ")} or ensure the packaged ephemeris directory is readable.`
759
- );
760
- return parts.join(" ");
761
- }
762
- function resolveNodeEphemerisPath(module, finalEphePath, options = {}) {
763
- const fs = module.FS;
764
- const requiredFiles = options.requiredFiles ?? REQUIRED_EPHE_FILES;
765
- const mountPoint = options.mountPoint ?? NODE_EPHE_MOUNT_POINT;
766
- const memfsPath = options.memfsPath ?? NODE_EPHE_MEMFS_PATH;
767
- const nodeFs = options.nodeFs ?? chunk4337NVKS_js.__require("fs");
768
- const pathModule = options.pathModule ?? chunk4337NVKS_js.__require("path");
769
- let mountAttempted = false;
770
- let mountCheck = null;
771
- let mountError = null;
772
- let hostCheck = null;
773
- let memfsCheck = null;
774
- let hostReadError = null;
775
- if (fs?.mount && fs.filesystems?.NODEFS) {
776
- mountAttempted = true;
777
- ensureVirtualDir(fs, mountPoint);
778
- try {
779
- fs.mount(fs.filesystems.NODEFS, { root: finalEphePath }, mountPoint);
780
- mountCheck = inspectVirtualEphemerisPath(fs, mountPoint, requiredFiles);
781
- if (mountCheck.missingFiles.length === 0) {
782
- return { path: mountPoint, strategy: "nodefs-mount" };
783
- }
784
- } catch (mountErr) {
785
- mountError = toError(mountErr);
786
- }
787
- }
788
- hostCheck = inspectVirtualEphemerisPath(fs, finalEphePath, requiredFiles);
789
- if (fs && hostCheck.missingFiles.length === 0) {
790
- return { path: finalEphePath, strategy: "host-path" };
791
- }
792
- let hostFiles = null;
793
- try {
794
- hostFiles = loadHostEphemerisFiles(finalEphePath, requiredFiles, nodeFs, pathModule);
795
- } catch (err) {
796
- hostReadError = toError(err);
797
- }
798
- if (hostFiles && fs?.writeFile) {
799
- writeEphemerisFilesToMemfs(fs, memfsPath, hostFiles);
800
- memfsCheck = inspectVirtualEphemerisPath(fs, memfsPath, requiredFiles);
801
- if (memfsCheck.missingFiles.length === 0) {
802
- return { path: memfsPath, strategy: "memfs-copy" };
803
- }
804
- }
805
- if (hostFiles) {
806
- return { path: finalEphePath, strategy: "host-path" };
807
- }
808
- throw new Error(
809
- buildEphemerisResolutionError(finalEphePath, requiredFiles, {
810
- mountAttempted,
811
- mountPoint,
812
- mountCheck,
813
- mountError,
814
- hostCheck,
815
- memfsPath,
816
- memfsCheck,
817
- hostReadError
818
- })
819
- );
820
- }
821
- async function getSwissEph(options = {}) {
822
- if (swissEph) {
823
- return;
824
- }
825
- try {
826
- const isBrowser = typeof window !== "undefined";
827
- const runtimeAssets = resolveSwissEphRuntimeAssets({
828
- wasmPath: options.wasmPath,
829
- ephePath: options.ephePath
830
- });
831
- const finalWasmPath = runtimeAssets.wasmPath;
832
- const moduleFactory = isBrowser ? (await import('./swisseph.web-XCF4GL2M.js')).default : (await import('./swisseph.node-CGBZTQ5N.js')).default;
833
- const module = await moduleFactory({
834
- locateFile: () => finalWasmPath
835
- });
836
- const instance = new SwissEph(module);
837
- const finalEphePath = runtimeAssets.ephePath;
838
- if (isBrowser) {
839
- const epheFsPath = "/ephe";
840
- try {
841
- module.FS?.mkdir?.(epheFsPath);
842
- } catch {
843
- }
844
- const files = ["seas_18.se1", "semo_18.se1", "sepl_18.se1"];
845
- await Promise.all(
846
- files.map(async (name) => {
847
- const url = `${finalEphePath}/${name}`;
848
- const res = await fetch(url);
849
- if (!res.ok) {
850
- throw new Error(`Failed to fetch ephemeris file: ${url}`);
851
- }
852
- const buf = await res.arrayBuffer();
853
- module.FS?.writeFile?.(
854
- `${epheFsPath}/${name}`,
855
- new Uint8Array(buf)
856
- );
857
- })
858
- );
859
- const browserCheck = inspectVirtualEphemerisPath(module.FS, epheFsPath, REQUIRED_EPHE_FILES);
860
- if (browserCheck.missingFiles.length > 0) {
861
- throw new Error(
862
- `Failed to materialize browser ephemeris files at "${epheFsPath}". Missing: ${browserCheck.missingFiles.join(", ")}.`
863
- );
864
- }
865
- emitRuntimeNotice(`Setting ephemeris path to: ${epheFsPath}`);
866
- instance.setEphemerisPath(epheFsPath);
867
- } else {
868
- const resolution = resolveNodeEphemerisPath(module, finalEphePath);
869
- if (resolution.strategy === "nodefs-mount") {
870
- emitRuntimeNotice(`Setting ephemeris path to: ${resolution.path} (mounted from ${finalEphePath})`);
871
- } else if (resolution.strategy === "memfs-copy") {
872
- emitRuntimeNotice(`Setting ephemeris path to: ${resolution.path} (copied from ${finalEphePath})`);
873
- } else {
874
- emitRuntimeNotice(`Setting ephemeris path to: ${resolution.path}`);
875
- }
876
- instance.setEphemerisPath(resolution.path);
877
- }
878
- swissEph = instance;
879
- } catch (error) {
880
- console.error("Error initializing Swiss Ephemeris:", error);
881
- throw error;
882
- }
883
- }
884
- function calculateSinglePlanetPosition(date, planet) {
885
- checkInitialization();
886
- const julday = swissEph.getJulianDay(date);
887
- return swissEph.calculatePlanetPosition(julday, planet, DEFAULT_FLAGS);
888
- }
889
- function calculateEquatorialPosition(date, planet) {
890
- checkInitialization();
891
- const julday = swissEph.getJulianDay(date);
892
- const pos = swissEph.calculatePlanetPosition(
893
- julday,
894
- planet,
895
- 2 /* SWISS_EPH */ | 2048 /* EQUATORIAL */
896
- );
897
- return {
898
- rightAscension: pos.longitude,
899
- declination: pos.latitude,
900
- distance: pos.distance
901
- };
902
- }
903
- function getJulianDay(date) {
904
- checkInitialization();
905
- return swissEph.getJulianDay(date);
906
- }
907
- async function calculatePlanetaryPositions(date) {
908
- try {
909
- checkInitialization();
910
- const julday = swissEph.getJulianDay(date);
911
- const flags = DEFAULT_FLAGS;
912
- const planets = {
913
- sun: 0 /* SUN */,
914
- moon: 1 /* MOON */,
915
- mercury: 2 /* MERCURY */,
916
- venus: 3 /* VENUS */,
917
- mars: 4 /* MARS */,
918
- jupiter: 5 /* JUPITER */,
919
- saturn: 6 /* SATURN */,
920
- uranus: 7 /* URANUS */,
921
- neptune: 8 /* NEPTUNE */,
922
- pluto: 9 /* PLUTO */,
923
- meanNode: 10 /* MEAN_NODE */,
924
- trueNode: 11 /* TRUE_NODE */,
925
- chiron: 15 /* CHIRON */,
926
- lilithMean: 12 /* LILITH_MEAN */,
927
- lilithTrue: 13 /* LILITH_TRUE */
928
- };
929
- const positions = {};
930
- for (const id of Object.values(planets)) {
931
- try {
932
- positions[id] = swissEph.calculatePlanetPosition(julday, id, flags);
933
- } catch (error) {
934
- throw new Error(
935
- `Failed to calculate position for ${PLANET_AND_NODE_NAMES[id]}: ${error}`
936
- );
937
- }
938
- }
939
- return positions;
940
- } catch (error) {
941
- console.error("Error calculating planetary positions:", error);
942
- throw error;
943
- }
944
- }
945
- async function calculateHouses(date, latitude, longitude, houseSystem, options = {}) {
946
- try {
947
- checkInitialization();
948
- const dateForUt = options.treatAsUTC === true ? date instanceof Date ? date : createUtcDateFromParts(buildLocalParts(date)) : await localToUtcDate(date, latitude, longitude, options);
949
- const julday = swissEph.getJulianDay(dateForUt);
950
- return swissEph.calculateHouses(
951
- julday,
952
- latitude,
953
- longitude,
954
- houseSystem
955
- );
956
- } catch (error) {
957
- console.error("Error calculating houses:", error);
958
- throw error;
959
- }
960
- }
961
- function calcParsFortunae(asc, sunLon, moonLon, isDiurnal) {
962
- return parsFortunae(asc, sunLon, moonLon, isDiurnal);
963
- }
964
- function closeSwissEph() {
965
- if (swissEph) {
966
- try {
967
- swissEph.close();
968
- swissEph = null;
969
- } catch (error) {
970
- console.error("Error closing Swiss Ephemeris:", error);
971
- throw error;
972
- }
973
- }
974
- }
975
- function checkInitialization() {
976
- if (!swissEph) {
977
- throw new Error(
978
- "Swiss Ephemeris not initialized. Call getSwissEph() first."
979
- );
980
- }
981
- }
982
- function buildLocalParts(date) {
983
- if (date instanceof Date) {
984
- return {
985
- year: date.getFullYear(),
986
- month: date.getMonth() + 1,
987
- day: date.getDate(),
988
- hour: date.getHours(),
989
- minute: date.getMinutes(),
990
- second: date.getSeconds()
991
- };
992
- }
993
- return date;
994
- }
995
- function createUtcDateFromParts(parts) {
996
- const { year, month, day, hour = 0, minute = 0, second = 0 } = parts;
997
- return new Date(Date.UTC(year, month - 1, day, hour, minute, second));
998
- }
999
- function getTimeZoneOffsetMs(instant, timeZone) {
1000
- const dtf = new Intl.DateTimeFormat("en-US", {
1001
- timeZone,
1002
- year: "numeric",
1003
- month: "2-digit",
1004
- day: "2-digit",
1005
- hour: "2-digit",
1006
- minute: "2-digit",
1007
- second: "2-digit",
1008
- hour12: false
1009
- });
1010
- const parts = dtf.formatToParts(instant);
1011
- const map = {};
1012
- for (const p of parts) {
1013
- map[p.type] = p.value;
1014
- }
1015
- const asUTC = Date.UTC(
1016
- Number(map.year),
1017
- Number(map.month) - 1,
1018
- Number(map.day),
1019
- Number(map.hour),
1020
- Number(map.minute),
1021
- Number(map.second)
1022
- );
1023
- return asUTC - instant.getTime();
1024
- }
1025
- async function localToUtcDate(local, latitude, longitude, opts = {}) {
1026
- if (opts.treatAsUTC === true) {
1027
- return local instanceof Date ? local : createUtcDateFromParts(buildLocalParts(local));
1028
- }
1029
- const parts = buildLocalParts(local);
1030
- const auto = opts.autoTimeZone !== false;
1031
- if (typeof opts.utcOffsetMinutes === "number" && Number.isFinite(opts.utcOffsetMinutes)) {
1032
- const utcMs = Date.UTC(
1033
- parts.year,
1034
- parts.month - 1,
1035
- parts.day,
1036
- parts.hour ?? 0,
1037
- parts.minute ?? 0,
1038
- parts.second ?? 0
1039
- );
1040
- return new Date(utcMs - opts.utcOffsetMinutes * 6e4);
1041
- }
1042
- if (opts.timeZone) {
1043
- const naiveUtc = createUtcDateFromParts(parts);
1044
- const offsetMs = getTimeZoneOffsetMs(naiveUtc, opts.timeZone);
1045
- return new Date(naiveUtc.getTime() - offsetMs);
1046
- }
1047
- if (opts.resolveTimeZone && typeof latitude === "number" && typeof longitude === "number") {
1048
- const tz = opts.resolveTimeZone(latitude, longitude, parts);
1049
- if (tz) {
1050
- const naiveUtc = createUtcDateFromParts(parts);
1051
- const offsetMs = getTimeZoneOffsetMs(naiveUtc, tz);
1052
- return new Date(naiveUtc.getTime() - offsetMs);
1053
- }
1054
- }
1055
- if (auto && typeof latitude === "number" && typeof longitude === "number") {
1056
- const mod = await import('tz-lookup');
1057
- const lookup = mod.default ?? mod;
1058
- const tz = lookup(latitude, longitude);
1059
- if (tz) {
1060
- const naiveUtc = createUtcDateFromParts(parts);
1061
- const offsetMs = getTimeZoneOffsetMs(naiveUtc, tz);
1062
- return new Date(naiveUtc.getTime() - offsetMs);
1063
- }
1064
- }
1065
- throw new Error(
1066
- "Time zone information is required. Provide 'utcOffsetMinutes', 'timeZone', 'resolveTimeZone', or enable autoTimeZone with latitude/longitude."
1067
- );
1068
- }
1069
- async function toUtcDate(local, latitude, longitude, options = {}) {
1070
- return localToUtcDate(local, latitude, longitude, options);
1071
- }
1072
-
1073
- // src/astrology/astrocartography.ts
1074
- var ASTROCARTOGRAPHY_DEFAULT_PLANETS = [
1075
- 0 /* SUN */,
1076
- 1 /* MOON */,
1077
- 2 /* MERCURY */,
1078
- 3 /* VENUS */,
1079
- 4 /* MARS */,
1080
- 5 /* JUPITER */,
1081
- 6 /* SATURN */,
1082
- 7 /* URANUS */,
1083
- 8 /* NEPTUNE */,
1084
- 9 /* PLUTO */,
1085
- 15 /* CHIRON */,
1086
- 11 /* TRUE_NODE */
1087
- ];
1088
- var DEG = Math.PI / 180;
1089
- function computeGMST(julianDay) {
1090
- return normalizeAngle(
1091
- 280.46061837 + 360.98564736629 * (julianDay - 2451545)
1092
- );
1093
- }
1094
- function computeMCLongitude(gmst, ra) {
1095
- return toGeoLon(normalizeAngle(gmst - ra));
1096
- }
1097
- function computeICLongitude(gmst, ra) {
1098
- return toGeoLon(normalizeAngle(gmst - ra + 180));
1099
- }
1100
- function computeHorizonLongitude(gmst, ra, dec, latitude, angle) {
1101
- const tanPhi = Math.tan(latitude * DEG);
1102
- const tanDelta = Math.tan(dec * DEG);
1103
- const cosH = -(tanPhi * tanDelta);
1104
- if (Math.abs(cosH) > 1)
1105
- return null;
1106
- const H = Math.acos(cosH) / DEG;
1107
- const lon = angle === "AC" ? normalizeAngle(gmst - ra - H) : normalizeAngle(gmst - ra + H);
1108
- return toGeoLon(lon);
1109
- }
1110
- function geographicAngularDifference(a, b) {
1111
- const d = normalizeAngle(a - b);
1112
- return d > 180 ? 360 - d : d;
1113
- }
1114
- function toGeoLon(deg360) {
1115
- const n = normalizeAngle(deg360);
1116
- return n > 180 ? n - 360 : n;
1117
- }
1118
- function computeEquatorialPositions(date, planets = ASTROCARTOGRAPHY_DEFAULT_PLANETS) {
1119
- const result = {};
1120
- for (const p of planets) {
1121
- const name = PLANET_AND_NODE_NAMES[p];
1122
- const eq = calculateEquatorialPosition(date, p);
1123
- result[name] = {
1124
- ra: eq.rightAscension,
1125
- dec: eq.declination,
1126
- planetId: p
1127
- };
1128
- }
1129
- return result;
1130
- }
1131
- function findParansAtLatitude(equatorialPositions, gmst, latitude, paranOrb = 1) {
1132
- const ANGLES = ["MC", "IC", "AC", "DC"];
1133
- const lines = [];
1134
- for (const [name, eq] of Object.entries(equatorialPositions)) {
1135
- for (const angle of ANGLES) {
1136
- let lon;
1137
- if (angle === "MC")
1138
- lon = computeMCLongitude(gmst, eq.ra);
1139
- else if (angle === "IC")
1140
- lon = computeICLongitude(gmst, eq.ra);
1141
- else
1142
- lon = computeHorizonLongitude(gmst, eq.ra, eq.dec, latitude, angle);
1143
- if (lon !== null) {
1144
- lines.push({ planet: name, angle, longitude: lon });
1145
- }
1146
- }
1147
- }
1148
- const parans = [];
1149
- for (let i = 0; i < lines.length; i++) {
1150
- for (let j = i + 1; j < lines.length; j++) {
1151
- const a = lines[i];
1152
- const b = lines[j];
1153
- if (a.planet === b.planet)
1154
- continue;
1155
- if (a.angle === b.angle)
1156
- continue;
1157
- const dist = geographicAngularDifference(a.longitude, b.longitude);
1158
- if (dist <= paranOrb) {
1159
- parans.push({
1160
- latitude,
1161
- planetA: a.planet,
1162
- angleA: a.angle,
1163
- longitudeA: a.longitude,
1164
- planetB: b.planet,
1165
- angleB: b.angle,
1166
- longitudeB: b.longitude
1167
- });
1168
- }
1169
- }
1170
- }
1171
- return parans;
1172
- }
1173
- function queryAstrocartographyLocation(date, options) {
1174
- const {
1175
- latitude,
1176
- longitude,
1177
- orb = 2,
1178
- planets = ASTROCARTOGRAPHY_DEFAULT_PLANETS,
1179
- paranOrb = 1
1180
- } = options;
1181
- const jd = getJulianDay(date);
1182
- const gmst = computeGMST(jd);
1183
- const positions = computeEquatorialPositions(date, planets);
1184
- const lines = [];
1185
- const ANGLES = ["MC", "IC", "AC", "DC"];
1186
- for (const [name, eq] of Object.entries(positions)) {
1187
- for (const angle of ANGLES) {
1188
- let lineLon;
1189
- if (angle === "MC")
1190
- lineLon = computeMCLongitude(gmst, eq.ra);
1191
- else if (angle === "IC")
1192
- lineLon = computeICLongitude(gmst, eq.ra);
1193
- else
1194
- lineLon = computeHorizonLongitude(
1195
- gmst,
1196
- eq.ra,
1197
- eq.dec,
1198
- latitude,
1199
- angle
1200
- );
1201
- if (lineLon === null)
1202
- continue;
1203
- const dist = geographicAngularDifference(longitude, lineLon);
1204
- lines.push({
1205
- planet: name,
1206
- angle,
1207
- distance: Math.round(dist * 1e3) / 1e3,
1208
- active: dist <= orb,
1209
- longitude: Math.round(lineLon * 1e3) / 1e3
1210
- });
1211
- }
1212
- }
1213
- lines.sort((a, b) => a.distance - b.distance);
1214
- const activeLines = lines.filter((l) => l.active);
1215
- const parans = findParansAtLatitude(positions, gmst, latitude, paranOrb);
1216
- return { queryLatitude: latitude, queryLongitude: longitude, orb, lines, activeLines, parans };
1217
- }
1218
- function computeAstrocartographyMap(date, options = {}) {
1219
- const {
1220
- latitudeStep = 1,
1221
- latitudeRange = 66.5,
1222
- planets = ASTROCARTOGRAPHY_DEFAULT_PLANETS
1223
- } = options;
1224
- const jd = getJulianDay(date);
1225
- const gmst = computeGMST(jd);
1226
- const positions = computeEquatorialPositions(date, planets);
1227
- const meridianLines = [];
1228
- const horizonLines = [];
1229
- for (const [name, eq] of Object.entries(positions)) {
1230
- meridianLines.push({
1231
- planet: name,
1232
- angle: "MC",
1233
- longitude: Math.round(computeMCLongitude(gmst, eq.ra) * 1e3) / 1e3
1234
- });
1235
- meridianLines.push({
1236
- planet: name,
1237
- angle: "IC",
1238
- longitude: Math.round(computeICLongitude(gmst, eq.ra) * 1e3) / 1e3
1239
- });
1240
- for (const angle of ["AC", "DC"]) {
1241
- const points = [];
1242
- for (let lat = -latitudeRange; lat <= latitudeRange; lat += latitudeStep) {
1243
- const lon = computeHorizonLongitude(gmst, eq.ra, eq.dec, lat, angle);
1244
- if (lon !== null) {
1245
- points.push({
1246
- latitude: Math.round(lat * 1e3) / 1e3,
1247
- longitude: Math.round(lon * 1e3) / 1e3
1248
- });
1249
- }
1250
- }
1251
- horizonLines.push({ planet: name, angle, points });
1252
- }
1253
- }
1254
- return { meridianLines, horizonLines };
1255
- }
1256
-
1257
- // src/astrology/aspects.ts
1258
- var DEFAULT_ASPECT_SPECS = [
1259
- { name: "conjunction", angle: 0, orb: 8 },
1260
- { name: "duodecile", angle: 30, orb: 2 },
1261
- { name: "octile", angle: 45, orb: 3 },
1262
- { name: "sextile", angle: 60, orb: 5 },
1263
- { name: "square", angle: 90, orb: 6 },
1264
- { name: "trine", angle: 120, orb: 7 },
1265
- { name: "trioctile", angle: 135, orb: 3 },
1266
- { name: "quincunx", angle: 150, orb: 3 },
1267
- { name: "opposition", angle: 180, orb: 8 }
1268
- ];
1269
- function getAspectMatch(lonA, lonB, specs = DEFAULT_ASPECT_SPECS) {
1270
- const a = normalizeAngle(lonA);
1271
- const b = normalizeAngle(lonB);
1272
- const delta = Math.min(
1273
- normalizeAngle(b - a),
1274
- normalizeAngle(a - b)
1275
- );
1276
- for (const spec of specs) {
1277
- const orb = Math.abs(delta - spec.angle);
1278
- if (orb <= spec.orb) {
1279
- return { spec, orb, delta };
1280
- }
1281
- }
1282
- return null;
1283
- }
1284
- function computeAspects(planets, specs = DEFAULT_ASPECT_SPECS) {
1285
- const keys = Object.keys(planets);
1286
- const edges = [];
1287
- for (let i = 0; i < keys.length; i++) {
1288
- for (let j = i + 1; j < keys.length; j++) {
1289
- const a = planets[keys[i]];
1290
- const b = planets[keys[j]];
1291
- const match = getAspectMatch(a.longitude, b.longitude, specs);
1292
- if (match) {
1293
- edges.push({
1294
- planetA: keys[i],
1295
- planetB: keys[j],
1296
- longitudeA: a.longitude,
1297
- longitudeB: b.longitude,
1298
- aspect: match.spec.name,
1299
- aspectAngle: match.spec.angle,
1300
- delta: match.delta,
1301
- orb: match.orb
1302
- });
1303
- }
1304
- }
1305
- }
1306
- return edges;
1307
- }
1308
- function computeSynastryAspects(planetsA, planetsB, specs = DEFAULT_ASPECT_SPECS) {
1309
- const keysA = Object.keys(planetsA);
1310
- const keysB = Object.keys(planetsB);
1311
- const edges = [];
1312
- for (const kA of keysA) {
1313
- for (const kB of keysB) {
1314
- const a = planetsA[kA];
1315
- const b = planetsB[kB];
1316
- const match = getAspectMatch(a.longitude, b.longitude, specs);
1317
- if (match) {
1318
- edges.push({
1319
- planetA: kA,
1320
- planetB: kB,
1321
- longitudeA: a.longitude,
1322
- longitudeB: b.longitude,
1323
- aspect: match.spec.name,
1324
- aspectAngle: match.spec.angle,
1325
- delta: match.delta,
1326
- orb: match.orb
1327
- });
1328
- }
1329
- }
1330
- }
1331
- return edges;
1332
- }
1333
- function shorterArcMidpoint(a, b) {
1334
- let diff = b - a;
1335
- if (diff > 180)
1336
- diff -= 360;
1337
- if (diff < -180)
1338
- diff += 360;
1339
- return normalizeAngle(a + diff / 2);
1340
- }
1341
- function computeMidpoints(planetsA, planetsB) {
1342
- const result = {};
1343
- for (const key of Object.keys(planetsA)) {
1344
- if (!(key in planetsB))
1345
- continue;
1346
- result[key] = shorterArcMidpoint(planetsA[key].longitude, planetsB[key].longitude);
1347
- }
1348
- return result;
1349
- }
1350
- var SLOW_PLANETS = /* @__PURE__ */ new Set([
1351
- "pluto",
1352
- "neptune",
1353
- "uranus",
1354
- "saturn",
1355
- "jupiter",
1356
- "chiron",
1357
- "mean node",
1358
- "true node",
1359
- "lilith true",
1360
- "lilith mean"
1361
- ]);
1362
- function computeTransitAspects(transitPlanets, natalPlanets, specs = DEFAULT_ASPECT_SPECS) {
1363
- const keysT = Object.keys(transitPlanets);
1364
- const keysN = Object.keys(natalPlanets);
1365
- const edges = [];
1366
- for (const kT of keysT) {
1367
- const t = transitPlanets[kT];
1368
- for (const kN of keysN) {
1369
- const n = natalPlanets[kN];
1370
- const match = getAspectMatch(t.longitude, n.longitude, specs);
1371
- if (!match)
1372
- continue;
1373
- const tSpeed = t.longitudeSpeed ?? 0;
1374
- const nSpeed = n.longitudeSpeed ?? 0;
1375
- const dt = 0.01;
1376
- const tLonFuture = t.longitude + tSpeed * dt;
1377
- const nLonFuture = n.longitude + nSpeed * dt;
1378
- const futureMatch = getAspectMatch(tLonFuture, nLonFuture, [match.spec]);
1379
- const applying = futureMatch != null ? futureMatch.orb < match.orb : false;
1380
- edges.push({
1381
- planetA: kT,
1382
- planetB: kN,
1383
- longitudeA: t.longitude,
1384
- longitudeB: n.longitude,
1385
- aspect: match.spec.name,
1386
- aspectAngle: match.spec.angle,
1387
- delta: match.delta,
1388
- orb: match.orb,
1389
- applying,
1390
- retrograde: tSpeed < 0,
1391
- category: SLOW_PLANETS.has(kT) ? "slow" : "fast"
1392
- });
1393
- }
1394
- }
1395
- return edges;
1396
- }
1397
-
1398
- // src/astrology/dignity.ts
1399
- var DOMICILE_RULERS = {
1400
- Aries: "Mars",
1401
- Taurus: "Venus",
1402
- Gemini: "Mercury",
1403
- Cancer: "Moon",
1404
- Leo: "Sun",
1405
- Virgo: "Mercury",
1406
- Libra: "Venus",
1407
- Scorpio: "Mars",
1408
- Sagittarius: "Jupiter",
1409
- Capricorn: "Saturn",
1410
- Aquarius: "Saturn",
1411
- Pisces: "Jupiter"
1412
- };
1413
- var EXALTATIONS = {
1414
- Sun: { sign: "Aries", degree: 19 },
1415
- Moon: { sign: "Taurus", degree: 3 },
1416
- Mercury: { sign: "Virgo", degree: 15 },
1417
- Venus: { sign: "Pisces", degree: 27 },
1418
- Mars: { sign: "Capricorn", degree: 28 },
1419
- Jupiter: { sign: "Cancer", degree: 15 },
1420
- Saturn: { sign: "Libra", degree: 21 }
1421
- };
1422
- function getDomicileRuler(sign) {
1423
- return DOMICILE_RULERS[sign];
1424
- }
1425
- function getExaltation(planet) {
1426
- return EXALTATIONS[planet];
1427
- }
1428
- function getOppositeSign(sign) {
1429
- const idx = SIGNS.indexOf(sign);
1430
- return SIGNS[(idx + 6) % 12];
1431
- }
1432
- function getDetriment(planet) {
1433
- const signs = [];
1434
- for (const [sign, ruler] of Object.entries(DOMICILE_RULERS)) {
1435
- if (ruler === planet) {
1436
- signs.push(getOppositeSign(sign));
1437
- }
1438
- }
1439
- return signs;
1440
- }
1441
- function getFall(planet) {
1442
- return getOppositeSign(EXALTATIONS[planet].sign);
1443
- }
1444
- function getEssentialDignity(planet, sign) {
1445
- const domicile = DOMICILE_RULERS[sign] === planet;
1446
- const exaltation = EXALTATIONS[planet].sign === sign;
1447
- const detrimentSigns = getDetriment(planet);
1448
- const detriment = detrimentSigns.includes(sign);
1449
- const fallSign = getFall(planet);
1450
- const fall = fallSign === sign;
1451
- const domicileRuler = DOMICILE_RULERS[sign];
1452
- const peregrine = !domicile && !exaltation && !detriment && !fall;
1453
- return { domicile, exaltation, detriment, fall, domicileRuler, peregrine };
1454
- }
1455
-
1456
- // src/astrology/decans.ts
1457
- var CHALDEAN_RULERS = [
1458
- "Mars",
1459
- "Sun",
1460
- "Venus",
1461
- "Mercury",
1462
- "Moon",
1463
- "Saturn",
1464
- "Jupiter"
1465
- ];
1466
- var SIGN_SUITS = {
1467
- Aries: "Wands",
1468
- Taurus: "Pentacles",
1469
- Gemini: "Swords",
1470
- Cancer: "Cups",
1471
- Leo: "Wands",
1472
- Virgo: "Pentacles",
1473
- Libra: "Swords",
1474
- Scorpio: "Cups",
1475
- Sagittarius: "Wands",
1476
- Capricorn: "Pentacles",
1477
- Aquarius: "Swords",
1478
- Pisces: "Cups"
1479
- };
1480
- var RANK_NAMES = ["Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"];
1481
- function getDecan(longitude) {
1482
- const L = normalizeAngle(longitude);
1483
- const signIndex = Math.floor(L / 30) % 12;
1484
- const degreeWithinSign = L - signIndex * 30;
1485
- const decanIndex = Math.min(Math.floor(degreeWithinSign / 10), 2);
1486
- const globalDecanIndex = signIndex * 3 + decanIndex;
1487
- const sign = SIGNS[signIndex];
1488
- const ruler = CHALDEAN_RULERS[globalDecanIndex % 7];
1489
- const suit = SIGN_SUITS[sign];
1490
- const rank = RANK_NAMES[globalDecanIndex % 9];
1491
- const tarotCard = `${rank} of ${suit}`;
1492
- return {
1493
- sign,
1494
- decanNumber: decanIndex + 1,
1495
- ruler,
1496
- tarotCard,
1497
- startDegree: signIndex * 30 + decanIndex * 10,
1498
- endDegree: signIndex * 30 + (decanIndex + 1) * 10,
1499
- degreeWithinSign
1500
- };
1501
- }
1502
-
1503
- // src/astrology/dodecatemoria.ts
1504
- function getDodecatemoria(longitude) {
1505
- const L = normalizeAngle(longitude);
1506
- const signIndex = Math.floor(L / 30) % 12;
1507
- const degreeWithinSign = L - signIndex * 30;
1508
- const index = Math.min(Math.floor(degreeWithinSign / 2.5), 11);
1509
- const dodecatemoriaSignIndex = (signIndex + index) % 12;
1510
- return {
1511
- originalSign: SIGNS[signIndex],
1512
- originalDegree: degreeWithinSign,
1513
- dodecatemoriaSign: SIGNS[dodecatemoriaSignIndex],
1514
- dodecatemoriaIndex: index
1515
- };
1516
- }
1517
-
1518
- // src/astrology/profections.ts
1519
- function getAnnualProfection(natalChart, birthDate, targetYear) {
1520
- const year = targetYear ?? (/* @__PURE__ */ new Date()).getFullYear();
1521
- const birthYear = birthDate.getFullYear();
1522
- const age = year - birthYear;
1523
- if (age < 0) {
1524
- throw new Error(`Target year (${year}) is before birth year (${birthYear}).`);
1525
- }
1526
- const house = age % 12 + 1;
1527
- const sign = natalChart.houses.houses[house - 1].sign;
1528
- const ruler = getDomicileRuler(sign);
1529
- return { age, house, sign, ruler, targetYear: year };
1530
- }
1531
- function getMonthlyProfections(natalChart, birthDate, targetYear) {
1532
- const annualProfection = getAnnualProfection(natalChart, birthDate, targetYear);
1533
- const annualSignIndex = SIGNS.indexOf(annualProfection.sign);
1534
- const bdMonth = birthDate.getMonth();
1535
- const bdDay = birthDate.getDate();
1536
- const year = annualProfection.targetYear;
1537
- const months = [];
1538
- for (let i = 0; i < 12; i++) {
1539
- const monthDate = new Date(year, bdMonth + i, bdDay);
1540
- if (monthDate.getDate() !== bdDay) {
1541
- monthDate.setDate(0);
1542
- }
1543
- const signIndex = (annualSignIndex + i) % 12;
1544
- const sign = SIGNS[signIndex];
1545
- months.push({
1546
- month: i + 1,
1547
- startDate: monthDate,
1548
- sign,
1549
- ruler: getDomicileRuler(sign)
1550
- });
1551
- }
1552
- return { annualProfection, months };
1553
- }
1554
-
1555
- // src/astrology/firdaria.ts
1556
- var DAY_SEQUENCE = [
1557
- { planet: "Sun", years: 10 },
1558
- { planet: "Venus", years: 8 },
1559
- { planet: "Mercury", years: 13 },
1560
- { planet: "Moon", years: 9 },
1561
- { planet: "Saturn", years: 11 },
1562
- { planet: "Jupiter", years: 12 },
1563
- { planet: "Mars", years: 7 },
1564
- { planet: "NorthNode", years: 3 },
1565
- { planet: "SouthNode", years: 2 }
1566
- ];
1567
- var NIGHT_SEQUENCE = [
1568
- { planet: "Moon", years: 9 },
1569
- { planet: "Saturn", years: 11 },
1570
- { planet: "Jupiter", years: 12 },
1571
- { planet: "Mars", years: 7 },
1572
- { planet: "NorthNode", years: 3 },
1573
- { planet: "SouthNode", years: 2 },
1574
- { planet: "Sun", years: 10 },
1575
- { planet: "Venus", years: 8 },
1576
- { planet: "Mercury", years: 13 }
1577
- ];
1578
- var CHALDEAN_ORDER = [
1579
- "Saturn",
1580
- "Jupiter",
1581
- "Mars",
1582
- "Sun",
1583
- "Venus",
1584
- "Mercury",
1585
- "Moon"
1586
- ];
1587
- function addYears(date, years) {
1588
- const ms = years * 365.25 * 24 * 60 * 60 * 1e3;
1589
- return new Date(date.getTime() + ms);
1590
- }
1591
- function getSubPeriodStart(planet, options) {
1592
- const mode = options?.nodeSubPeriodStart ?? "jupiter-saturn";
1593
- if (planet === "NorthNode") {
1594
- if (mode === "sun-mars") {
1595
- return CHALDEAN_ORDER.indexOf("Sun");
1596
- }
1597
- return CHALDEAN_ORDER.indexOf("Jupiter");
1598
- }
1599
- if (planet === "SouthNode") {
1600
- if (mode === "sun-mars") {
1601
- return CHALDEAN_ORDER.indexOf("Mars");
1602
- }
1603
- return CHALDEAN_ORDER.indexOf("Saturn");
1604
- }
1605
- return CHALDEAN_ORDER.indexOf(planet);
1606
- }
1607
- function buildSubPeriods(major, majorStart, majorEnd, options) {
1608
- const startIdx = getSubPeriodStart(major.planet, options);
1609
- const totalMs = majorEnd.getTime() - majorStart.getTime();
1610
- const subMs = totalMs / 7;
1611
- const subs = [];
1612
- for (let i = 0; i < 7; i++) {
1613
- const subPlanet = CHALDEAN_ORDER[(startIdx + i) % 7];
1614
- const subStart = new Date(majorStart.getTime() + i * subMs);
1615
- const subEnd = new Date(majorStart.getTime() + (i + 1) * subMs);
1616
- subs.push({ planet: subPlanet, startDate: subStart, endDate: subEnd });
1617
- }
1618
- return subs;
1619
- }
1620
- function getFirdaria(birthDate, isDiurnal, targetDate, options) {
1621
- const target = targetDate ?? /* @__PURE__ */ new Date();
1622
- const sequence = isDiurnal ? DAY_SEQUENCE : NIGHT_SEQUENCE;
1623
- const sect = isDiurnal ? "diurnal" : "nocturnal";
1624
- const allPeriods = [];
1625
- let cursor = new Date(birthDate.getTime());
1626
- let foundCurrent = false;
1627
- for (let cycle = 0; cycle < 3 && !foundCurrent; cycle++) {
1628
- for (const entry of sequence) {
1629
- const start = new Date(cursor.getTime());
1630
- const end = addYears(start, entry.years);
1631
- const subPeriods = buildSubPeriods(entry, start, end, options);
1632
- allPeriods.push({
1633
- planet: entry.planet,
1634
- years: entry.years,
1635
- startDate: start,
1636
- endDate: end,
1637
- subPeriods
1638
- });
1639
- cursor = end;
1640
- if (target.getTime() >= start.getTime() && target.getTime() < end.getTime()) {
1641
- foundCurrent = true;
1642
- }
1643
- }
1644
- }
1645
- const currentMajor = allPeriods.find(
1646
- (p) => target.getTime() >= p.startDate.getTime() && target.getTime() < p.endDate.getTime()
1647
- ) ?? allPeriods[0];
1648
- const currentSub = currentMajor.subPeriods.find(
1649
- (s) => target.getTime() >= s.startDate.getTime() && target.getTime() < s.endDate.getTime()
1650
- ) ?? currentMajor.subPeriods[0];
1651
- return { sect, currentMajor, currentSub, allPeriods };
1652
- }
1653
-
1654
- // src/astrology/index.ts
1655
- function getSect(sunHouse) {
1656
- return sunHouse >= 7 && sunHouse <= 12 ? "diurnal" : "nocturnal";
1657
- }
1658
- function isValidLocalDateTimeParts(date) {
1659
- const hour = date.hour ?? 0;
1660
- const minute = date.minute ?? 0;
1661
- const second = date.second ?? 0;
1662
- if (!Number.isInteger(date.year) || !Number.isInteger(date.month) || !Number.isInteger(date.day) || !Number.isInteger(hour) || !Number.isInteger(minute) || !Number.isInteger(second)) {
1663
- return false;
1664
- }
1665
- if (date.month < 1 || date.month > 12 || date.day < 1 || date.day > 31 || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
1666
- return false;
1667
- }
1668
- const utcDate = new Date(Date.UTC(date.year, date.month - 1, date.day, hour, minute, second));
1669
- return !Number.isNaN(utcDate.getTime()) && utcDate.getUTCFullYear() === date.year && utcDate.getUTCMonth() === date.month - 1 && utcDate.getUTCDate() === date.day && utcDate.getUTCHours() === hour && utcDate.getUTCMinutes() === minute && utcDate.getUTCSeconds() === second;
1670
- }
1671
- function getCivilMonthDay(date) {
1672
- if (date instanceof Date) {
1673
- return {
1674
- monthIndex: date.getMonth(),
1675
- day: date.getDate()
1676
- };
1677
- }
1678
- return {
1679
- monthIndex: date.month - 1,
1680
- day: date.day
1681
- };
1682
- }
1683
- function validateInputs(options) {
1684
- const { date } = options;
1685
- if (date instanceof Date) {
1686
- if (Number.isNaN(date.getTime())) {
1687
- throw new Error("Invalid date provided");
1688
- }
1689
- } else if (!isValidLocalDateTimeParts(date)) {
1690
- throw new Error("Invalid date provided");
1691
- }
1692
- if (typeof options.latitude !== "number" || options.latitude < -90 || options.latitude > 90) {
1693
- throw new Error("Invalid latitude: must be between -90 and 90 degrees");
1694
- }
1695
- if (typeof options.longitude !== "number" || options.longitude < -180 || options.longitude > 180) {
1696
- throw new Error("Invalid longitude: must be between -180 and 180 degrees");
1697
- }
1698
- }
1699
- function hydratePlanet(id, position, houseCusps) {
1700
- return {
1701
- ...position,
1702
- id,
1703
- name: PLANET_AND_NODE_NAMES[id],
1704
- zodiacPosition: getZodiacPosition(position.longitude, houseCusps)
1705
- };
1706
- }
1707
- async function getBirthChart(options) {
1708
- try {
1709
- validateInputs(options);
1710
- const tzOptions = options.timeZoneSettings ?? { autoTimeZone: true };
1711
- const utcDate = await toUtcDate(options.date, options.latitude, options.longitude, tzOptions);
1712
- const planetPositions = await calculatePlanetaryPositions(utcDate);
1713
- if (!planetPositions) {
1714
- throw new Error("Failed to calculate planetary positions");
1715
- }
1716
- const housesPositions = await calculateHouses(
1717
- utcDate,
1718
- options.latitude,
1719
- options.longitude,
1720
- options.houseSystem || "P" /* PLACIDUS */,
1721
- { treatAsUTC: true }
1722
- );
1723
- if (!housesPositions) {
1724
- throw new Error("Failed to calculate houses");
1725
- }
1726
- const houseCusps = housesPositions.houses.slice(1, 13).map(normalizeAngle);
1727
- const planets = {};
1728
- for (const [planetId, position] of Object.entries(planetPositions)) {
1729
- const id = planetId;
1730
- const hydratedPlanet = hydratePlanet(id, position, houseCusps);
1731
- planets[hydratedPlanet.name.toLocaleLowerCase()] = hydratedPlanet;
1732
- }
1733
- const houseCuspsPositions = houseCusps.map(
1734
- (lon) => getZodiacPosition(lon, houseCusps)
1735
- );
1736
- const descendant = normalizeAngle(housesPositions.ascendant + 180);
1737
- const imumCoeli = normalizeAngle(housesPositions.mc + 180);
1738
- const ascendantSign = getZodiacPosition(
1739
- housesPositions.ascendant,
1740
- houseCusps
1741
- );
1742
- const midheavenSign = getZodiacPosition(housesPositions.mc, houseCusps);
1743
- const descendantSign = getZodiacPosition(descendant, houseCusps);
1744
- const imumCoeliSign = getZodiacPosition(imumCoeli, houseCusps);
1745
- const houses = {
1746
- ascendant: ascendantSign,
1747
- mc: midheavenSign,
1748
- dc: descendantSign,
1749
- ic: imumCoeliSign,
1750
- houses: houseCuspsPositions,
1751
- ascmc: {
1752
- armc: housesPositions.ascmc ? getZodiacPosition(housesPositions.ascmc.armc, houseCusps) : void 0,
1753
- vertex: housesPositions.ascmc ? getZodiacPosition(housesPositions.ascmc.vertex, houseCusps) : void 0,
1754
- equasc: housesPositions.ascmc ? getZodiacPosition(housesPositions.ascmc.equasc, houseCusps) : void 0,
1755
- coasc1: housesPositions.ascmc ? getZodiacPosition(housesPositions.ascmc.coasc1, houseCusps) : void 0,
1756
- coasc2: housesPositions.ascmc ? getZodiacPosition(housesPositions.ascmc.coasc2, houseCusps) : void 0,
1757
- polasc: housesPositions.ascmc ? getZodiacPosition(housesPositions.ascmc.polasc, houseCusps) : void 0
1758
- }
1759
- };
1760
- const sect = getSect(planets.sun.zodiacPosition.house);
1761
- const isDiurnal = sect === "diurnal";
1762
- const wheelOfFortuneLongitude = calcParsFortunae(
1763
- houses.ascendant.longitude,
1764
- planets.sun.longitude,
1765
- planets.moon.longitude,
1766
- isDiurnal
1767
- );
1768
- const wheelOfFortune = getZodiacPosition(
1769
- wheelOfFortuneLongitude,
1770
- houseCusps
1771
- );
1772
- const nodes = {
1773
- ["parsFortunae" /* PARS_FORTUNAE */]: {
1774
- ...wheelOfFortune,
1775
- id: "parsFortunae" /* PARS_FORTUNAE */,
1776
- name: PLANET_AND_NODE_NAMES["parsFortunae" /* PARS_FORTUNAE */]
1777
- }
1778
- };
1779
- const aspects = computeAspects(getAspectPoints(planets, houses.ascendant.longitude, houses.mc.longitude));
1780
- return {
1781
- dateUtc: utcDate,
1782
- planets,
1783
- houses,
1784
- nodes,
1785
- aspects,
1786
- sect
1787
- };
1788
- } catch (error) {
1789
- console.error("Error calculating birth chart:", error);
1790
- throw error;
1791
- }
1792
- }
1793
- var SIGNS = [
1794
- "Aries",
1795
- "Taurus",
1796
- "Gemini",
1797
- "Cancer",
1798
- "Leo",
1799
- "Virgo",
1800
- "Libra",
1801
- "Scorpio",
1802
- "Sagittarius",
1803
- "Capricorn",
1804
- "Aquarius",
1805
- "Pisces"
1806
- ];
1807
- function formatDegreeMinutes(decimalDegrees) {
1808
- let deg = Math.floor(decimalDegrees);
1809
- let min = Math.round((decimalDegrees - deg) * 60);
1810
- if (min === 60) {
1811
- min = 0;
1812
- deg += 1;
1813
- }
1814
- return `${deg}\xB0${String(min).padStart(2, "0")}'`;
1815
- }
1816
- function getZodiacPosition(longitude, houseCusps) {
1817
- const L = normalizeAngle(longitude);
1818
- const signIndex = Math.floor(L / 30) % 12;
1819
- const within = L - signIndex * 30;
1820
- const house = findHouseOf(L, houseCusps);
1821
- return {
1822
- sign: SIGNS[signIndex],
1823
- decimalDegrees: within,
1824
- traditionalFormat: formatDegreeMinutes(within),
1825
- decimal: within.toFixed(2) + "\xB0",
1826
- longitude: L,
1827
- house
1828
- };
1829
- }
1830
- function findHouseOf(longitude, housePositions) {
1831
- const L = normalizeAngle(longitude);
1832
- if (!housePositions || housePositions.length === 0) {
1833
- throw new Error("House positions are required");
1834
- }
1835
- const H = housePositions.map((c, i) => ({ i: i + 1, L: normalizeAngle(c) })).sort((a, b) => a.L - b.L);
1836
- for (let k = 0; k < H.length; k++) {
1837
- const cur = H[k], nxt = H[(k + 1) % H.length];
1838
- if (nxt.L < cur.L) {
1839
- if (L >= cur.L || L < nxt.L)
1840
- return cur.i;
1841
- } else {
1842
- if (L >= cur.L && L < nxt.L)
1843
- return cur.i;
1844
- }
1845
- }
1846
- return 1;
1847
- }
1848
- function getAspectPoints(planets, ascLon, mcLon) {
1849
- return { ...planets, ascendant: { longitude: ascLon }, mc: { longitude: mcLon } };
1850
- }
1851
- async function getSynastryChart(options) {
1852
- const [chartA, chartB] = await Promise.all([
1853
- getBirthChart(options.chartA),
1854
- getBirthChart(options.chartB)
1855
- ]);
1856
- const aspects = computeSynastryAspects(
1857
- getAspectPoints(chartA.planets, chartA.houses.ascendant.longitude, chartA.houses.mc.longitude),
1858
- getAspectPoints(chartB.planets, chartB.houses.ascendant.longitude, chartB.houses.mc.longitude),
1859
- options.aspectSpecs
1860
- );
1861
- return { chartA, chartB, aspects };
1862
- }
1863
- async function getCompositeChart(options) {
1864
- const [chartA, chartB] = await Promise.all([
1865
- getBirthChart(options.chartA),
1866
- getBirthChart(options.chartB)
1867
- ]);
1868
- const midpointLongitudes = computeMidpoints(chartA.planets, chartB.planets);
1869
- const cuspsA = chartA.houses.houses.map((h) => h.longitude);
1870
- const cuspsB = chartB.houses.houses.map((h) => h.longitude);
1871
- const compositeCusps = cuspsA.map(
1872
- (a, i) => i < cuspsB.length ? shorterArcMidpoint(a, cuspsB[i]) : a
1873
- );
1874
- const compositePlanets = {};
1875
- for (const [key, lon] of Object.entries(midpointLongitudes)) {
1876
- compositePlanets[key] = {
1877
- name: key,
1878
- longitude: lon,
1879
- zodiacPosition: getZodiacPosition(lon, compositeCusps)
1880
- };
1881
- }
1882
- const compositeHouses = compositeCusps.map(
1883
- (lon) => getZodiacPosition(lon, compositeCusps)
1884
- );
1885
- const aspects = computeAspects(compositePlanets, options.aspectSpecs);
1886
- return {
1887
- chartA,
1888
- chartB,
1889
- compositePlanets,
1890
- compositeHouses,
1891
- aspects
1892
- };
1893
- }
1894
- function getTransitAspectPoints(planets) {
1895
- const points = {};
1896
- for (const [key, p] of Object.entries(planets)) {
1897
- points[key] = { longitude: p.longitude, longitudeSpeed: p.longitudeSpeed };
1898
- }
1899
- return points;
1900
- }
1901
- function getNatalAspectPoints(planets, ascLon, mcLon) {
1902
- const points = {};
1903
- for (const [key, p] of Object.entries(planets)) {
1904
- points[key] = { longitude: p.longitude, longitudeSpeed: 0 };
1905
- }
1906
- points.ascendant = { longitude: ascLon, longitudeSpeed: 0 };
1907
- points.mc = { longitude: mcLon, longitudeSpeed: 0 };
1908
- return points;
1909
- }
1910
- function filterByNames(points, names) {
1911
- if (!names || names.length === 0)
1912
- return points;
1913
- const allowed = new Set(names.map((n) => n.toLowerCase()));
1914
- const result = {};
1915
- for (const [key, val] of Object.entries(points)) {
1916
- if (allowed.has(key))
1917
- result[key] = val;
1918
- }
1919
- return result;
1920
- }
1921
- async function getTransitChart(options) {
1922
- const natalChart = await getBirthChart(options.natal);
1923
- const transitChart = await getBirthChart({
1924
- date: options.transitDate,
1925
- latitude: options.transitLatitude ?? options.natal.latitude,
1926
- longitude: options.transitLongitude ?? options.natal.longitude,
1927
- houseSystem: options.natal.houseSystem,
1928
- timeZoneSettings: options.transitTimeZoneSettings ?? { autoTimeZone: true }
1929
- });
1930
- const natalCusps = natalChart.houses.houses.map((h) => h.longitude);
1931
- const transitPlanets = {};
1932
- for (const [key, planet] of Object.entries(transitChart.planets)) {
1933
- const natalZodiac = getZodiacPosition(planet.longitude, natalCusps);
1934
- transitPlanets[key] = {
1935
- ...planet,
1936
- retrograde: (planet.longitudeSpeed ?? 0) < 0,
1937
- natalHouse: natalZodiac.house,
1938
- zodiacPosition: {
1939
- ...planet.zodiacPosition,
1940
- house: natalZodiac.house
1941
- }
1942
- };
1943
- }
1944
- let tPoints = getTransitAspectPoints(transitChart.planets);
1945
- let nPoints = getNatalAspectPoints(
1946
- natalChart.planets,
1947
- natalChart.houses.ascendant.longitude,
1948
- natalChart.houses.mc.longitude
1949
- );
1950
- tPoints = filterByNames(tPoints, options.transitPlanets);
1951
- nPoints = filterByNames(nPoints, options.natalPlanets);
1952
- let aspects = computeTransitAspects(tPoints, nPoints, options.aspectSpecs);
1953
- if (options.maxOrb != null) {
1954
- aspects = aspects.filter((a) => a.orb <= options.maxOrb);
1955
- }
1956
- if (options.aspectFilter && options.aspectFilter.length > 0) {
1957
- const allowed = new Set(options.aspectFilter);
1958
- aspects = aspects.filter((a) => allowed.has(a.aspect));
1959
- }
1960
- return {
1961
- natalChart,
1962
- transitDateUtc: transitChart.dateUtc,
1963
- transitPlanets,
1964
- aspects
1965
- };
1966
- }
1967
- async function getTransitRange(options) {
1968
- const natalChart = await getBirthChart(options.natal);
1969
- natalChart.houses.houses.map((h) => h.longitude);
1970
- const nPoints = filterByNames(
1971
- getNatalAspectPoints(
1972
- natalChart.planets,
1973
- natalChart.houses.ascendant.longitude,
1974
- natalChart.houses.mc.longitude
1975
- ),
1976
- options.natalPlanets
1977
- );
1978
- const natalKeys = Object.keys(nPoints);
1979
- const rawStep = options.stepDays ?? 1;
1980
- if (rawStep <= 0)
1981
- throw new Error("stepDays must be greater than 0");
1982
- const fromMs = options.from.getTime();
1983
- const toMs = options.to.getTime();
1984
- const specs = options.aspectSpecs;
1985
- const steps = [];
1986
- const transitLat = options.transitLatitude ?? options.natal.latitude;
1987
- const transitLon = options.transitLongitude ?? options.natal.longitude;
1988
- const transitTz = options.transitTimeZoneSettings ?? { autoTimeZone: true };
1989
- const FAST_PLANET_MAX_STEP = 0.25;
1990
- let effectiveStepDays = rawStep;
1991
- const requestedTransitPlanets = options.transitPlanets?.map((n) => n.toLowerCase());
1992
- const hasFastPlanets = requestedTransitPlanets ? requestedTransitPlanets.some((n) => !SLOW_PLANETS.has(n)) : true;
1993
- if (hasFastPlanets && effectiveStepDays > FAST_PLANET_MAX_STEP) {
1994
- effectiveStepDays = FAST_PLANET_MAX_STEP;
1995
- }
1996
- const stepMs = effectiveStepDays * 864e5;
1997
- const scanEndMs = toMs + stepMs;
1998
- for (let ms = fromMs; ms <= scanEndMs; ms += stepMs) {
1999
- const date = new Date(ms);
2000
- const utcDate = await toUtcDate(date, transitLat, transitLon, transitTz ?? { autoTimeZone: true });
2001
- const positions = await calculatePlanetaryPositions(utcDate);
2002
- if (!positions)
2003
- continue;
2004
- const points = {};
2005
- for (const [planetId, pos] of Object.entries(positions)) {
2006
- const id = planetId;
2007
- const name = PLANET_AND_NODE_NAMES[id].toLowerCase();
2008
- points[name] = { longitude: pos.longitude, longitudeSpeed: pos.longitudeSpeed };
2009
- }
2010
- steps.push({ time: ms, positions: filterByNames(points, options.transitPlanets) });
2011
- }
2012
- const perfections = [];
2013
- const transitKeys = steps.length > 0 ? Object.keys(steps[0].positions) : [];
2014
- for (const tKey of transitKeys) {
2015
- for (const nKey of natalKeys) {
2016
- let prevOrb = null;
2017
- let prevDecreasing = false;
2018
- let prevStep = null;
2019
- for (const step of steps) {
2020
- const tPos = step.positions[tKey];
2021
- const nPos = nPoints[nKey];
2022
- if (!tPos || !nPos)
2023
- continue;
2024
- const match = specs ? findClosestAspectOrb(tPos.longitude, nPos.longitude, specs) : findClosestAspectOrb(tPos.longitude, nPos.longitude);
2025
- if (!match) {
2026
- prevOrb = null;
2027
- prevStep = step;
2028
- continue;
2029
- }
2030
- const currentOrb = match.orb;
2031
- if (prevOrb != null && prevStep) {
2032
- const wasDecreasing = prevOrb > currentOrb;
2033
- if (prevDecreasing && !wasDecreasing && currentOrb <= match.spec.orb) {
2034
- const exactResult = await binarySearchPerfection(
2035
- tKey,
2036
- nKey,
2037
- match.spec,
2038
- prevStep.time,
2039
- step.time,
2040
- nPos,
2041
- transitLat,
2042
- transitLon,
2043
- transitTz
2044
- );
2045
- if (exactResult)
2046
- perfections.push(exactResult);
2047
- }
2048
- prevDecreasing = wasDecreasing;
2049
- } else {
2050
- prevDecreasing = false;
2051
- }
2052
- prevOrb = currentOrb;
2053
- prevStep = step;
2054
- }
2055
- }
2056
- }
2057
- let filtered = perfections.filter((p) => {
2058
- const t = p.exactDate.getTime();
2059
- return t >= fromMs && t <= toMs;
2060
- });
2061
- if (options.maxOrb != null) {
2062
- filtered = filtered.filter((p) => p.exactOrb <= options.maxOrb);
2063
- }
2064
- if (options.aspectFilter && options.aspectFilter.length > 0) {
2065
- const allowed = new Set(options.aspectFilter);
2066
- filtered = filtered.filter((p) => allowed.has(p.aspect));
2067
- }
2068
- filtered.sort((a, b) => a.exactDate.getTime() - b.exactDate.getTime());
2069
- return {
2070
- natalChart,
2071
- from: options.from,
2072
- to: options.to,
2073
- perfections: filtered
2074
- };
2075
- }
2076
- function findClosestAspectOrb(lonA, lonB, specs = DEFAULT_ASPECT_SPECS) {
2077
- const a = normalizeAngle(lonA);
2078
- const b = normalizeAngle(lonB);
2079
- const delta = Math.min(normalizeAngle(b - a), normalizeAngle(a - b));
2080
- let best = null;
2081
- for (const spec of specs) {
2082
- const orb = Math.abs(delta - spec.angle);
2083
- if (orb <= spec.orb + 2) {
2084
- if (!best || orb < best.orb) {
2085
- best = { spec, orb, delta };
2086
- }
2087
- }
2088
- }
2089
- return best;
2090
- }
2091
- function computeOrbForAspect(transitLon, natalLon, aspectAngle) {
2092
- const delta = Math.min(
2093
- normalizeAngle(transitLon - natalLon),
2094
- normalizeAngle(natalLon - transitLon)
2095
- );
2096
- return Math.abs(delta - aspectAngle);
2097
- }
2098
- var NAME_TO_PLANET = {};
2099
- for (const [id, name] of Object.entries(PLANET_AND_NODE_NAMES)) {
2100
- const numId = Number(id);
2101
- if (!isNaN(numId))
2102
- NAME_TO_PLANET[name.toLowerCase()] = numId;
2103
- }
2104
- async function getTransitLongitudeAt(ms, transitKey, transitLat, transitLon, transitTz) {
2105
- const date = new Date(ms);
2106
- const utc = await toUtcDate(date, transitLat, transitLon, transitTz);
2107
- const planetId = NAME_TO_PLANET[transitKey];
2108
- if (planetId != null) {
2109
- try {
2110
- return calculateSinglePlanetPosition(utc, planetId);
2111
- } catch {
2112
- return null;
2113
- }
2114
- }
2115
- const positions = await calculatePlanetaryPositions(utc);
2116
- if (!positions)
2117
- return null;
2118
- return findPlanetByName(positions, transitKey) ?? null;
2119
- }
2120
- async function binarySearchPerfection(transitKey, natalKey, spec, startMs, endMs, natalPoint, transitLat, transitLon, transitTz) {
2121
- const tz = transitTz ?? { autoTimeZone: true };
2122
- const maxIterations = 30;
2123
- let lo = startMs;
2124
- let hi = endMs;
2125
- for (let i = 0; i < maxIterations; i++) {
2126
- if (hi - lo < 6e4)
2127
- break;
2128
- const m1 = lo + Math.floor((hi - lo) / 3);
2129
- const m2 = hi - Math.floor((hi - lo) / 3);
2130
- const pos1 = await getTransitLongitudeAt(m1, transitKey, transitLat, transitLon, tz);
2131
- const pos2 = await getTransitLongitudeAt(m2, transitKey, transitLat, transitLon, tz);
2132
- if (!pos1 || !pos2)
2133
- break;
2134
- const orb1 = computeOrbForAspect(pos1.longitude, natalPoint.longitude, spec.angle);
2135
- const orb2 = computeOrbForAspect(pos2.longitude, natalPoint.longitude, spec.angle);
2136
- if (orb1 < orb2) {
2137
- hi = m2;
2138
- } else {
2139
- lo = m1;
2140
- }
2141
- }
2142
- const finalMs = Math.floor((lo + hi) / 2);
2143
- const finalPos = await getTransitLongitudeAt(finalMs, transitKey, transitLat, transitLon, tz);
2144
- if (!finalPos)
2145
- return null;
2146
- const finalOrb = computeOrbForAspect(finalPos.longitude, natalPoint.longitude, spec.angle);
2147
- if (finalOrb > spec.orb)
2148
- return null;
2149
- return {
2150
- transitPlanet: transitKey,
2151
- natalPlanet: natalKey,
2152
- aspect: spec.name,
2153
- exactDate: new Date(finalMs),
2154
- exactOrb: finalOrb,
2155
- retrograde: (finalPos.longitudeSpeed ?? 0) < 0,
2156
- category: SLOW_PLANETS.has(transitKey) ? "slow" : "fast"
2157
- };
2158
- }
2159
- function findPlanetByName(positions, name) {
2160
- for (const [planetId, pos] of Object.entries(positions)) {
2161
- const id = planetId;
2162
- if (PLANET_AND_NODE_NAMES[id].toLowerCase() === name)
2163
- return pos;
2164
- }
2165
- return void 0;
2166
- }
2167
- async function getSunLongitudeAtMs(ms) {
2168
- const positions = await calculatePlanetaryPositions(new Date(ms));
2169
- const sun = findPlanetByName(positions, "sun");
2170
- if (!sun)
2171
- throw new Error("Failed to compute Sun position");
2172
- return sun.longitude;
2173
- }
2174
- function signedAngularDelta(current, target) {
2175
- let d = normalizeAngle(current - target);
2176
- if (d > 180)
2177
- d -= 360;
2178
- return d;
2179
- }
2180
- async function getSolarReturnChart(options) {
2181
- const natalChart = await getBirthChart(options.natal);
2182
- const natalSunLongitude = natalChart.planets.sun.longitude;
2183
- const natalDate = getCivilMonthDay(options.natal.date);
2184
- const approxReturn = new Date(Date.UTC(
2185
- options.year,
2186
- natalDate.monthIndex,
2187
- natalDate.day,
2188
- 12,
2189
- 0,
2190
- 0
2191
- ));
2192
- let lo = approxReturn.getTime() - 2 * 864e5;
2193
- let hi = approxReturn.getTime() + 2 * 864e5;
2194
- for (let i = 0; i < 30; i++) {
2195
- if (hi - lo < 6e4)
2196
- break;
2197
- const mid = Math.floor((lo + hi) / 2);
2198
- const sunLon = await getSunLongitudeAtMs(mid);
2199
- const delta = signedAngularDelta(sunLon, natalSunLongitude);
2200
- if (delta < 0) {
2201
- lo = mid;
2202
- } else {
2203
- hi = mid;
2204
- }
2205
- }
2206
- const exactMs = Math.floor((lo + hi) / 2);
2207
- const exactReturnDate = new Date(exactMs);
2208
- const solarReturnChart = await getBirthChart({
2209
- date: exactReturnDate,
2210
- latitude: options.solarReturnLatitude ?? options.natal.latitude,
2211
- longitude: options.solarReturnLongitude ?? options.natal.longitude,
2212
- houseSystem: options.solarReturnHouseSystem ?? options.natal.houseSystem,
2213
- // Always treatAsUTC: the binary search converged on a UTC millisecond timestamp.
2214
- // Passing a caller timezone here would re-interpret the already-UTC instant as local,
2215
- // shifting planetary positions by hours.
2216
- timeZoneSettings: { treatAsUTC: true }
2217
- });
2218
- return {
2219
- natalChart,
2220
- solarReturnChart,
2221
- exactReturnDate,
2222
- natalSunLongitude,
2223
- year: options.year
2224
- };
2225
- }
2226
-
2227
- exports.ASTROCARTOGRAPHY_DEFAULT_PLANETS = ASTROCARTOGRAPHY_DEFAULT_PLANETS;
2228
- exports.CalcFlag = CalcFlag;
2229
- exports.DEFAULT_ASPECT_SPECS = DEFAULT_ASPECT_SPECS;
2230
- exports.DOMICILE_RULERS = DOMICILE_RULERS;
2231
- exports.EXALTATIONS = EXALTATIONS;
2232
- exports.HouseSystem = HouseSystem;
2233
- exports.PLANET_AND_NODE_NAMES = PLANET_AND_NODE_NAMES;
2234
- exports.Planet = Planet;
2235
- exports.RiseTransitFlag = RiseTransitFlag;
2236
- exports.SIGNS = SIGNS;
2237
- exports.SLOW_PLANETS = SLOW_PLANETS;
2238
- exports.VirtualNodes = VirtualNodes;
2239
- exports.closeSwissEph = closeSwissEph;
2240
- exports.computeAspects = computeAspects;
2241
- exports.computeAstrocartographyMap = computeAstrocartographyMap;
2242
- exports.computeEquatorialPositions = computeEquatorialPositions;
2243
- exports.computeGMST = computeGMST;
2244
- exports.computeHorizonLongitude = computeHorizonLongitude;
2245
- exports.computeICLongitude = computeICLongitude;
2246
- exports.computeMCLongitude = computeMCLongitude;
2247
- exports.computeMidpoints = computeMidpoints;
2248
- exports.computeSynastryAspects = computeSynastryAspects;
2249
- exports.computeTransitAspects = computeTransitAspects;
2250
- exports.findHouseOf = findHouseOf;
2251
- exports.findParansAtLatitude = findParansAtLatitude;
2252
- exports.formatDegreeMinutes = formatDegreeMinutes;
2253
- exports.geographicAngularDifference = geographicAngularDifference;
2254
- exports.getAnnualProfection = getAnnualProfection;
2255
- exports.getAspectMatch = getAspectMatch;
2256
- exports.getBirthChart = getBirthChart;
2257
- exports.getCompositeChart = getCompositeChart;
2258
- exports.getDecan = getDecan;
2259
- exports.getDetriment = getDetriment;
2260
- exports.getDodecatemoria = getDodecatemoria;
2261
- exports.getDomicileRuler = getDomicileRuler;
2262
- exports.getEssentialDignity = getEssentialDignity;
2263
- exports.getExaltation = getExaltation;
2264
- exports.getFall = getFall;
2265
- exports.getFirdaria = getFirdaria;
2266
- exports.getMonthlyProfections = getMonthlyProfections;
2267
- exports.getOppositeSign = getOppositeSign;
2268
- exports.getSect = getSect;
2269
- exports.getSolarReturnChart = getSolarReturnChart;
2270
- exports.getSwissEph = getSwissEph;
2271
- exports.getSynastryChart = getSynastryChart;
2272
- exports.getTransitChart = getTransitChart;
2273
- exports.getTransitRange = getTransitRange;
2274
- exports.getZodiacPosition = getZodiacPosition;
2275
- exports.normalizeAngle = normalizeAngle;
2276
- exports.queryAstrocartographyLocation = queryAstrocartographyLocation;
2277
- exports.resolveSwissEphRuntimeAssets = resolveSwissEphRuntimeAssets;
2278
- exports.shorterArcMidpoint = shorterArcMidpoint;
2279
- //# sourceMappingURL=out.js.map
2280
- //# sourceMappingURL=chunk-SWWLTDR6.js.map