#![no_std]
extern crate alloc;
use alloc::string::String;
use swisseph_wasm;
use wasm_bindgen::prelude::*;
use serde::{Deserialize, Serialize};
pub(crate) use swisseph_wasm::swe_bindings;
pub mod astronomy;
pub mod vedic;
pub mod geo;
pub mod muhurat;
#[wasm_bindgen]
pub fn get_version() -> String {
String::from(env!("CARGO_PKG_VERSION"))
}
#[wasm_bindgen]
pub fn get_swisseph_version() -> String {
let mut buf = [0i8; 256];
unsafe {
swe_bindings::swe_version(buf.as_mut_ptr());
}
let c_str = unsafe { core::ffi::CStr::from_ptr(buf.as_ptr()) };
String::from(c_str.to_str().unwrap_or("Unknown"))
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[wasm_bindgen]
pub struct Location {
pub latitude: f64,
pub longitude: f64,
pub altitude: f64,
}
#[wasm_bindgen]
impl Location {
#[wasm_bindgen(constructor)]
pub fn new(latitude: f64, longitude: f64, altitude: f64) -> Self {
Self { latitude, longitude, altitude }
}
}
#[wasm_bindgen]
pub fn calculate_sunrise(year: i32, month: u32, day: u32, location: &Location) -> f64 {
geo::sunrise_sunset::calculate_sunrise(year, month, day, location.latitude, location.longitude, location.altitude)
}
#[wasm_bindgen]
pub fn calculate_sunset(year: i32, month: u32, day: u32, location: &Location) -> f64 {
geo::sunrise_sunset::calculate_sunset(year, month, day, location.latitude, location.longitude, location.altitude)
}