2026-03-07 05:17:50 -08:00
|
|
|
(function () {
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
let config = {};
|
|
|
|
|
let lastNowSkyGeoKey = "";
|
|
|
|
|
let lastNowSkySourceUrl = "";
|
2026-03-08 03:52:25 -07:00
|
|
|
const NOW_SKY_WRAPPER_PATH = "app/stellarium-now-wrapper.html";
|
|
|
|
|
const NOW_SKY_FOV_DEGREES = "220";
|
2026-03-07 05:17:50 -08:00
|
|
|
|
|
|
|
|
function getNowSkyLayerEl() {
|
|
|
|
|
return config.nowSkyLayerEl || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getNowPanelEl() {
|
|
|
|
|
return config.nowPanelEl || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCurrentGeo() {
|
|
|
|
|
return config.getCurrentGeo?.() || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function normalizeGeoForSky(geo) {
|
|
|
|
|
const latitude = Number(geo?.latitude);
|
|
|
|
|
const longitude = Number(geo?.longitude);
|
|
|
|
|
|
|
|
|
|
if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
latitude: Number(latitude.toFixed(4)),
|
|
|
|
|
longitude: Number(longitude.toFixed(4))
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function buildStellariumObserverUrl(geo) {
|
|
|
|
|
const normalizedGeo = normalizeGeoForSky(geo);
|
|
|
|
|
if (!normalizedGeo) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-08 03:52:25 -07:00
|
|
|
const wrapperUrl = new URL(NOW_SKY_WRAPPER_PATH, window.location.href);
|
|
|
|
|
wrapperUrl.searchParams.set("lat", String(normalizedGeo.latitude));
|
|
|
|
|
wrapperUrl.searchParams.set("lng", String(normalizedGeo.longitude));
|
|
|
|
|
wrapperUrl.searchParams.set("elev", "0");
|
|
|
|
|
wrapperUrl.searchParams.set("date", new Date().toISOString());
|
|
|
|
|
wrapperUrl.searchParams.set("az", "0");
|
|
|
|
|
wrapperUrl.searchParams.set("alt", "90");
|
|
|
|
|
wrapperUrl.searchParams.set("fov", NOW_SKY_FOV_DEGREES);
|
2026-03-07 05:17:50 -08:00
|
|
|
|
2026-03-08 03:52:25 -07:00
|
|
|
return wrapperUrl.toString();
|
2026-03-07 05:17:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function syncNowSkyBackground(geo, force = false) {
|
|
|
|
|
const nowSkyLayerEl = getNowSkyLayerEl();
|
|
|
|
|
if (!nowSkyLayerEl || !geo) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const normalizedGeo = normalizeGeoForSky(geo);
|
|
|
|
|
if (!normalizedGeo) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const geoKey = `${normalizedGeo.latitude.toFixed(4)},${normalizedGeo.longitude.toFixed(4)}`;
|
|
|
|
|
const stellariumUrl = buildStellariumObserverUrl(normalizedGeo);
|
|
|
|
|
if (!stellariumUrl) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!force && geoKey === lastNowSkyGeoKey && stellariumUrl === lastNowSkySourceUrl) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stellariumUrl === lastNowSkySourceUrl) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nowSkyLayerEl.src = stellariumUrl;
|
|
|
|
|
lastNowSkyGeoKey = geoKey;
|
|
|
|
|
lastNowSkySourceUrl = stellariumUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function syncNowPanelTheme(referenceDate = new Date()) {
|
|
|
|
|
const nowPanelEl = getNowPanelEl();
|
|
|
|
|
if (!nowPanelEl) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const currentGeo = getCurrentGeo();
|
|
|
|
|
if (!currentGeo || !window.SunCalc) {
|
|
|
|
|
nowPanelEl.classList.remove("is-day");
|
|
|
|
|
nowPanelEl.classList.add("is-night");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sunPosition = window.SunCalc.getPosition(referenceDate, currentGeo.latitude, currentGeo.longitude);
|
|
|
|
|
const sunAltitudeDeg = (sunPosition.altitude * 180) / Math.PI;
|
|
|
|
|
const isDaytime = sunAltitudeDeg >= -4;
|
|
|
|
|
|
|
|
|
|
nowPanelEl.classList.toggle("is-day", isDaytime);
|
|
|
|
|
nowPanelEl.classList.toggle("is-night", !isDaytime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function init(nextConfig = {}) {
|
|
|
|
|
config = {
|
|
|
|
|
...config,
|
|
|
|
|
...nextConfig
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.TarotHomeUi = {
|
|
|
|
|
...(window.TarotHomeUi || {}),
|
|
|
|
|
init,
|
|
|
|
|
syncNowSkyBackground,
|
|
|
|
|
syncNowPanelTheme
|
|
|
|
|
};
|
|
|
|
|
})();
|