@nrweb/astro-calc
Version:
Comprehensive astrological calculations using Swiss Ephemeris and astronomy-engine for positions, aspects, houses, lots, and scoring metrics
103 lines • 4.27 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadCalendar = loadCalendar;
exports.getRetrogradeInfo = getRetrogradeInfo;
exports.findNextRetrogradeDate = findNextRetrogradeDate;
exports.isRetrograde = isRetrograde;
const Astronomy = __importStar(require("astronomy-engine"));
const constants_1 = require("./constants");
const retrograde_calendar_json_1 = __importDefault(require("./retrograde-calendar.json"));
function loadCalendar() {
return retrograde_calendar_json_1.default || {};
}
function getRetrogradeInfo(time, body) {
if (!constants_1.RETROGRADE_PLANETS.includes(body)) {
return { motion: "direct" };
}
try {
// Check current motion state
const yesterday = new Date(time.getTime() - 24 * 60 * 60 * 1000);
const tomorrow = new Date(time.getTime() + 24 * 60 * 60 * 1000);
const yesterdayLon = Astronomy.Ecliptic(Astronomy.GeoVector(body, yesterday, true)).elon;
const tomorrowLon = Astronomy.Ecliptic(Astronomy.GeoVector(body, tomorrow, true)).elon;
// Calculate motion over 48 hours
let motion = tomorrowLon - yesterdayLon;
// Handle 360-degree wrap
if (motion < -180)
motion += 360;
if (motion > 180)
motion -= 360;
const result = {
motion: motion < 0 ? "retrograde" : "direct",
};
// Find next retrograde
let currentDate = new Date(time);
const endDate = new Date(time.getTime() + 3 * 365 * 24 * 60 * 60 * 1000); // 3 years
let prevLon = Astronomy.Ecliptic(Astronomy.GeoVector(body, currentDate, true)).elon;
while (currentDate < endDate) {
currentDate = new Date(currentDate.getTime() + 24 * 60 * 60 * 1000);
const currentLon = Astronomy.Ecliptic(Astronomy.GeoVector(body, currentDate, true)).elon;
let deltaLon = currentLon - prevLon;
if (deltaLon < -180)
deltaLon += 360;
if (deltaLon > 180)
deltaLon -= 360;
if (deltaLon < 0) {
result.nextRetrograde = new Date(currentDate.getTime() - 24 * 60 * 60 * 1000)
.toISOString()
.split("T")[0];
break;
}
prevLon = currentLon;
}
return result;
}
catch (error) {
console.error(`Error calculating retrograde for ${body}:`, error);
return { motion: "direct" };
}
}
function findNextRetrogradeDate(time, body) {
const info = getRetrogradeInfo(time, body);
return info.nextRetrograde;
}
function isRetrograde(time, body) {
return getRetrogradeInfo(time, body).motion === "retrograde";
}
//# sourceMappingURL=retrograde.js.map