@tempo-kit/plugin-celestial 0.0.0-stage → 2.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +110 -0
- package/LICENSE +21 -0
- package/README.md +209 -2
- package/dist/astro.d.ts +37 -0
- package/dist/index.d.ts +145 -0
- package/dist/index.global.min.js +1 -0
- package/dist/index.js +823 -0
- package/dist/install.d.ts +2 -0
- package/dist/install.global.min.js +1 -0
- package/dist/install.js +826 -0
- package/dist/lunar.d.ts +143 -0
- package/dist/solar.d.ts +244 -0
- package/dist/tidal.d.ts +90 -0
- package/dist/util.d.ts +74 -0
- package/package.json +70 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,823 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key2 of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key2) && key2 !== except)
|
|
13
|
+
__defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
import {
|
|
21
|
+
LUNAR_PHASE_KEYS as LUNAR_PHASE_KEYS2,
|
|
22
|
+
SOLAR_PHASE_STATES as SOLAR_PHASE_STATES2,
|
|
23
|
+
SOLAR_PHASE_NAMES as SOLAR_PHASE_NAMES2,
|
|
24
|
+
TIDAL_PHASE_STATES as TIDAL_PHASE_STATES2,
|
|
25
|
+
HALF_DAY_MS as HALF_DAY_MS2,
|
|
26
|
+
DAY_MS as DAY_MS2,
|
|
27
|
+
getEclipse as getEclipse3,
|
|
28
|
+
getSolarPosition as getSolarPosition2
|
|
29
|
+
} from "tempo-fns";
|
|
30
|
+
|
|
31
|
+
// auto-inject-version:tempo-kit/plugin/sdk
|
|
32
|
+
var sdk_exports = {};
|
|
33
|
+
__export(sdk_exports, {
|
|
34
|
+
definePlugin: () => definePlugin,
|
|
35
|
+
defineTerm: () => defineTerm
|
|
36
|
+
});
|
|
37
|
+
__reExport(sdk_exports, sdk_star);
|
|
38
|
+
import * as sdk_star from "tempo-kit/plugin/sdk";
|
|
39
|
+
import { definePlugin as originalPlugin, defineTerm as originalTerm } from "tempo-kit/plugin/sdk";
|
|
40
|
+
var definePlugin = (config) => originalPlugin({ ...config, version: "2.0.0-rc.0" });
|
|
41
|
+
var defineTerm = (config) => originalTerm({ ...config, version: "2.0.0-rc.0" });
|
|
42
|
+
|
|
43
|
+
// src/lunar.ts
|
|
44
|
+
import {
|
|
45
|
+
getLunarPhaseRange,
|
|
46
|
+
getMoonriseMoonset,
|
|
47
|
+
getLunarPosition,
|
|
48
|
+
getLunarDistance,
|
|
49
|
+
getCrescentTilt,
|
|
50
|
+
getEclipse,
|
|
51
|
+
LUNAR_PHASE_KEYS
|
|
52
|
+
} from "tempo-fns";
|
|
53
|
+
import { Tempo as Tempo2 } from "tempo-kit";
|
|
54
|
+
|
|
55
|
+
// src/util.ts
|
|
56
|
+
import { Tempo } from "tempo-kit";
|
|
57
|
+
import { getLunarPhase } from "tempo-fns";
|
|
58
|
+
import { isNumber, isReference, isArray } from "tempo-kit/library";
|
|
59
|
+
var LUNAR_PHASE_CACHE = new sdk_exports.WeakCache();
|
|
60
|
+
function isValidGeo(geo) {
|
|
61
|
+
if (!isReference(geo) || isArray(geo)) return false;
|
|
62
|
+
const lat = geo.latitude ?? geo.lat;
|
|
63
|
+
const lng = geo.longitude ?? geo.lng ?? geo.long;
|
|
64
|
+
const isLatValid = isNumber(lat) && lat >= -90 && lat <= 90;
|
|
65
|
+
const isLngValid = isNumber(lng) && lng >= -180 && lng <= 180;
|
|
66
|
+
return isLatValid && isLngValid;
|
|
67
|
+
}
|
|
68
|
+
function getCelestialCoordinates(t, anchor) {
|
|
69
|
+
const target = anchor ?? t;
|
|
70
|
+
const refTempo = target instanceof Tempo ? target : new Tempo(isNumber(target) ? new Date(target) : target, t?.config);
|
|
71
|
+
const geo = refTempo.geo ?? refTempo.config?.geo ?? anchor?.geo ?? t?.geo ?? null;
|
|
72
|
+
const hasGeo = isValidGeo(geo);
|
|
73
|
+
const latVal = hasGeo ? geo.latitude ?? geo.lat : void 0;
|
|
74
|
+
const lngVal = hasGeo ? geo.longitude ?? geo.lng ?? geo.long : void 0;
|
|
75
|
+
const elevation = hasGeo ? geo?.elevation ?? refTempo.config?.geo?.elevation : void 0;
|
|
76
|
+
const timeZone = refTempo.tz ?? anchor?.tz ?? t?.tz ?? "UTC";
|
|
77
|
+
const sphere = refTempo.sphere ?? anchor?.sphere ?? t?.sphere;
|
|
78
|
+
if (!hasGeo)
|
|
79
|
+
(0, sdk_exports.logWarn)("CelestialPlugin: Valid 'geo' coordinates (latitude: -90..90, longitude: -180..180) were not provided; geo-dependent properties evaluate to null.", refTempo.config);
|
|
80
|
+
return { refTempo, lat: latVal, lng: lngVal, elevation, hasGeo, geo, timeZone, ...sphere ? { sphere } : {} };
|
|
81
|
+
}
|
|
82
|
+
function toDateTimeFields(t) {
|
|
83
|
+
const dt = t.toDateTime();
|
|
84
|
+
return {
|
|
85
|
+
year: dt.year,
|
|
86
|
+
month: dt.month,
|
|
87
|
+
day: dt.day,
|
|
88
|
+
hour: dt.hour,
|
|
89
|
+
minute: dt.minute,
|
|
90
|
+
second: dt.second,
|
|
91
|
+
millisecond: dt.millisecond,
|
|
92
|
+
microsecond: dt.microsecond,
|
|
93
|
+
nanosecond: dt.nanosecond
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function toTempoOrNull(ms, timeZone, sphere) {
|
|
97
|
+
return isNumber(ms) ? new Tempo(ms, { timeZone, timeStamp: "ms", ...sphere ? { sphere } : {} }) : null;
|
|
98
|
+
}
|
|
99
|
+
function getLunarDetails(t, coords) {
|
|
100
|
+
const { refTempo, sphere } = coords ?? getCelestialCoordinates(t);
|
|
101
|
+
const cacheKey = `${refTempo.epoch.ms}:${sphere ?? ""}`;
|
|
102
|
+
let res = LUNAR_PHASE_CACHE.get(cacheKey);
|
|
103
|
+
if (!res) {
|
|
104
|
+
res = getLunarPhase(refTempo.epoch.ms, { sphere });
|
|
105
|
+
LUNAR_PHASE_CACHE.set(cacheKey, res);
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
key: res.key,
|
|
109
|
+
phase: res.phase,
|
|
110
|
+
index: res.index,
|
|
111
|
+
illumination: Math.round(res.illumination * 1e4) / 1e4,
|
|
112
|
+
ageDays: Math.round(res.ageDays * 100) / 100,
|
|
113
|
+
isWaxing: res.isWaxing,
|
|
114
|
+
...sphere && res.emoji !== void 0 ? { emoji: res.emoji } : {},
|
|
115
|
+
phases: res.phases,
|
|
116
|
+
keys: res.phases
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function createCelestialTermHandlers(getScopeRange) {
|
|
120
|
+
return {
|
|
121
|
+
resolve(anchor) {
|
|
122
|
+
return [getScopeRange(this, anchor)];
|
|
123
|
+
},
|
|
124
|
+
define(keyOnly, anchor) {
|
|
125
|
+
const scopeObj = getScopeRange(this, anchor);
|
|
126
|
+
return keyOnly === true || keyOnly === void 0 ? scopeObj.key : scopeObj;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/lunar.ts
|
|
132
|
+
var SYNODIC_MONTH_MS = 29.530588 * 86400 * 1e3;
|
|
133
|
+
var LUNAR_PHASE_RANGE_CACHE = new sdk_exports.WeakCache();
|
|
134
|
+
var MOON_EVENTS_CACHE = new sdk_exports.WeakCache();
|
|
135
|
+
var LUNAR_POSITION_CACHE = new sdk_exports.WeakCache();
|
|
136
|
+
function cachedLunarPhaseRange(epochMs, sphere) {
|
|
137
|
+
const key2 = `${epochMs}:${sphere ?? ""}`;
|
|
138
|
+
let res = LUNAR_PHASE_RANGE_CACHE.get(key2);
|
|
139
|
+
if (!res) {
|
|
140
|
+
res = getLunarPhaseRange(epochMs, { sphere });
|
|
141
|
+
LUNAR_PHASE_RANGE_CACHE.set(key2, res);
|
|
142
|
+
}
|
|
143
|
+
return res;
|
|
144
|
+
}
|
|
145
|
+
function cachedMoonEvents(epochMs, lat, lng) {
|
|
146
|
+
const key2 = `${epochMs}:${lat}:${lng}`;
|
|
147
|
+
let res = MOON_EVENTS_CACHE.get(key2);
|
|
148
|
+
if (!res) {
|
|
149
|
+
res = getMoonriseMoonset(epochMs, lat, lng);
|
|
150
|
+
MOON_EVENTS_CACHE.set(key2, res);
|
|
151
|
+
}
|
|
152
|
+
return res;
|
|
153
|
+
}
|
|
154
|
+
function cachedLunarPosition(epochMs, lat, lng) {
|
|
155
|
+
const key2 = `${epochMs}:${lat}:${lng}`;
|
|
156
|
+
let res = LUNAR_POSITION_CACHE.get(key2);
|
|
157
|
+
if (!res) {
|
|
158
|
+
res = getLunarPosition(epochMs, lat, lng);
|
|
159
|
+
LUNAR_POSITION_CACHE.set(key2, res);
|
|
160
|
+
}
|
|
161
|
+
return res;
|
|
162
|
+
}
|
|
163
|
+
function getLunarScopeRange(t, anchor) {
|
|
164
|
+
const coords = getCelestialCoordinates(t, anchor);
|
|
165
|
+
const { refTempo, lat, lng, hasGeo, geo, timeZone, sphere } = coords;
|
|
166
|
+
const lunarDetails = getLunarDetails(t, coords);
|
|
167
|
+
const moonEvents = hasGeo ? cachedMoonEvents(refTempo.epoch.ms, lat, lng) : null;
|
|
168
|
+
const moonrise = moonEvents ? toTempoOrNull(moonEvents.moonriseMs, timeZone, sphere) : null;
|
|
169
|
+
const moonset = moonEvents ? toTempoOrNull(moonEvents.moonsetMs, timeZone, sphere) : null;
|
|
170
|
+
const position = hasGeo ? cachedLunarPosition(refTempo.epoch.ms, lat, lng) : null;
|
|
171
|
+
const distance = hasGeo ? getLunarDistance(refTempo.epoch.ms) : null;
|
|
172
|
+
const crescentTilt = hasGeo ? getCrescentTilt(refTempo.epoch.ms, lat, lng) : null;
|
|
173
|
+
const eclipseRes = hasGeo ? getEclipse(refTempo.epoch.ms, lat, lng) : null;
|
|
174
|
+
const transit = position?.transitMs ? toTempoOrNull(position.transitMs, timeZone, sphere) : null;
|
|
175
|
+
const nadir = position?.antiTransitMs ? toTempoOrNull(position.antiTransitMs, timeZone, sphere) : null;
|
|
176
|
+
const altitude = position ? position.altitude : null;
|
|
177
|
+
const azimuth = position ? position.azimuth : null;
|
|
178
|
+
const zenith = position ? position.zenith : null;
|
|
179
|
+
const isAboveHorizon = position ? position.isAboveHorizon : null;
|
|
180
|
+
const crescentTiltDeg = crescentTilt ? crescentTilt.crescentTiltDeg : null;
|
|
181
|
+
const distanceKm = distance ? distance.distanceKm : null;
|
|
182
|
+
const angularDiameterArcmin = distance ? distance.angularDiameterArcmin : null;
|
|
183
|
+
const isSupermoon = distance ? distance.isSupermoon : null;
|
|
184
|
+
const isMicromoon = distance ? distance.isMicromoon : null;
|
|
185
|
+
const eclipse = eclipseRes ? eclipseRes.type : null;
|
|
186
|
+
const obscuration = eclipseRes ? eclipseRes.obscuration : null;
|
|
187
|
+
const { startMs, endMs } = cachedLunarPhaseRange(refTempo.epoch.ms, sphere);
|
|
188
|
+
const start = new Tempo2(startMs, { timeZone, timeStamp: "ms", ...sphere ? { sphere } : {} });
|
|
189
|
+
const end = new Tempo2(endMs, { timeZone, timeStamp: "ms", ...sphere ? { sphere } : {} });
|
|
190
|
+
return {
|
|
191
|
+
...lunarDetails,
|
|
192
|
+
group: "lunar",
|
|
193
|
+
geo: hasGeo ? geo : null,
|
|
194
|
+
...toDateTimeFields(start),
|
|
195
|
+
moonrise,
|
|
196
|
+
moonset,
|
|
197
|
+
transit,
|
|
198
|
+
nadir,
|
|
199
|
+
altitude,
|
|
200
|
+
azimuth,
|
|
201
|
+
zenith,
|
|
202
|
+
isAboveHorizon,
|
|
203
|
+
crescentTiltDeg,
|
|
204
|
+
distanceKm,
|
|
205
|
+
angularDiameterArcmin,
|
|
206
|
+
isSupermoon,
|
|
207
|
+
isMicromoon,
|
|
208
|
+
eclipse,
|
|
209
|
+
obscuration,
|
|
210
|
+
start,
|
|
211
|
+
end
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
var LunarTerm = defineTerm({
|
|
215
|
+
key: "moon",
|
|
216
|
+
aliases: ["lunar"],
|
|
217
|
+
scope: "lunar",
|
|
218
|
+
description: "Lunar phase cycle and range resolution",
|
|
219
|
+
phases: LUNAR_PHASE_KEYS,
|
|
220
|
+
keys: LUNAR_PHASE_KEYS,
|
|
221
|
+
...createCelestialTermHandlers(getLunarScopeRange),
|
|
222
|
+
[sdk_exports.TermHook.bound](boundary, _unit, tempo) {
|
|
223
|
+
const scope2 = getLunarScopeRange(tempo);
|
|
224
|
+
if (boundary === "start") return scope2.start;
|
|
225
|
+
if (boundary === "end") return scope2.end.sub({ nanoseconds: 1 });
|
|
226
|
+
if (boundary === "mid") {
|
|
227
|
+
const midMs = Math.round((scope2.start.epoch.ms + scope2.end.epoch.ms) / 2);
|
|
228
|
+
return new Tempo2(midMs, { timeZone: scope2.start.tz, timeStamp: "ms", ...scope2.start.sphere ? { sphere: scope2.start.sphere } : {} });
|
|
229
|
+
}
|
|
230
|
+
return void 0;
|
|
231
|
+
},
|
|
232
|
+
[sdk_exports.TermHook.step](_unit, count, tempo) {
|
|
233
|
+
const targetMs = Math.round(tempo.epoch.ms + count * SYNODIC_MONTH_MS);
|
|
234
|
+
return new Tempo2(targetMs, { timeZone: tempo.tz, timeStamp: "ms", ...tempo.sphere ? { sphere: tempo.sphere } : {} });
|
|
235
|
+
},
|
|
236
|
+
[sdk_exports.TermHook.diff](other, _unit, tempo) {
|
|
237
|
+
return Math.round((other.epoch.ms - tempo.epoch.ms) / SYNODIC_MONTH_MS);
|
|
238
|
+
},
|
|
239
|
+
[sdk_exports.TermHook.format](token, tempo) {
|
|
240
|
+
const t = token.toLowerCase();
|
|
241
|
+
if (t === "#moon" || t === "#lunar" || t.startsWith("#moon.") || t.startsWith("#lunar.")) {
|
|
242
|
+
const scope2 = getLunarScopeRange(tempo);
|
|
243
|
+
if (t === "#moon.emoji" || t === "#lunar.emoji") return scope2.emoji ?? "";
|
|
244
|
+
if (t === "#moon.phase" || t === "#lunar.phase") return scope2.phase;
|
|
245
|
+
if (t === "#moon.key" || t === "#lunar.key") return scope2.key;
|
|
246
|
+
if (t === "#moon.illumination" || t === "#lunar.illumination") return `${Math.round(scope2.illumination * 100)}%`;
|
|
247
|
+
if (t === "#moon.age" || t === "#lunar.age") return `${scope2.ageDays}d`;
|
|
248
|
+
if (t === "#moon" || t === "#lunar") return scope2.emoji ? `${scope2.emoji} ${scope2.phase}` : scope2.phase;
|
|
249
|
+
}
|
|
250
|
+
return void 0;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// src/solar.ts
|
|
255
|
+
import {
|
|
256
|
+
getSunriseSunset,
|
|
257
|
+
getSolarPosition,
|
|
258
|
+
getEclipse as getEclipse2,
|
|
259
|
+
SOLAR_PHASE_STATES,
|
|
260
|
+
SOLAR_PHASE_NAMES,
|
|
261
|
+
HALF_DAY_MS,
|
|
262
|
+
DAY_MS
|
|
263
|
+
} from "tempo-fns";
|
|
264
|
+
import { Tempo as Tempo3 } from "tempo-kit";
|
|
265
|
+
import { isNull, isNumber as isNumber2 } from "tempo-kit/library";
|
|
266
|
+
var SUNRISE_SUNSET_CACHE = new sdk_exports.WeakCache();
|
|
267
|
+
var SOLAR_POSITION_CACHE = new sdk_exports.WeakCache();
|
|
268
|
+
function cachedSunriseSunset(epochMs, options) {
|
|
269
|
+
const key2 = `${epochMs}:${options.latitude}:${options.longitude}:${options.elevation ?? 0}`;
|
|
270
|
+
let res = SUNRISE_SUNSET_CACHE.get(key2);
|
|
271
|
+
if (!res) {
|
|
272
|
+
res = getSunriseSunset(epochMs, options);
|
|
273
|
+
SUNRISE_SUNSET_CACHE.set(key2, res);
|
|
274
|
+
}
|
|
275
|
+
return res;
|
|
276
|
+
}
|
|
277
|
+
function cachedSolarPosition(epochMs, options) {
|
|
278
|
+
const key2 = `${epochMs}:${options.latitude}:${options.longitude}:${options.elevation ?? 0}`;
|
|
279
|
+
let res = SOLAR_POSITION_CACHE.get(key2);
|
|
280
|
+
if (!res) {
|
|
281
|
+
res = getSolarPosition(epochMs, options);
|
|
282
|
+
SOLAR_POSITION_CACHE.set(key2, res);
|
|
283
|
+
}
|
|
284
|
+
return res;
|
|
285
|
+
}
|
|
286
|
+
function getSolarScopeRange(t, anchor) {
|
|
287
|
+
const { refTempo, lat, lng, hasGeo, geo, timeZone } = getCelestialCoordinates(t, anchor);
|
|
288
|
+
if (!hasGeo) {
|
|
289
|
+
return {
|
|
290
|
+
key: null,
|
|
291
|
+
phase: null,
|
|
292
|
+
phases: SOLAR_PHASE_STATES,
|
|
293
|
+
keys: SOLAR_PHASE_STATES,
|
|
294
|
+
index: null,
|
|
295
|
+
group: "solar",
|
|
296
|
+
geo: null,
|
|
297
|
+
...toDateTimeFields(refTempo),
|
|
298
|
+
elevation: null,
|
|
299
|
+
sunrise: null,
|
|
300
|
+
sunset: null,
|
|
301
|
+
noon: null,
|
|
302
|
+
nadir: null,
|
|
303
|
+
solarTime: null,
|
|
304
|
+
altitude: null,
|
|
305
|
+
azimuth: null,
|
|
306
|
+
zenith: null,
|
|
307
|
+
isGoldenHour: null,
|
|
308
|
+
isBlueHour: null,
|
|
309
|
+
shadowRatio: null,
|
|
310
|
+
isMidnightSun: null,
|
|
311
|
+
isPolarNight: null,
|
|
312
|
+
daylightDurationMs: null,
|
|
313
|
+
isDaylight: null,
|
|
314
|
+
civil: { sunrise: null, sunset: null },
|
|
315
|
+
nautical: { sunrise: null, sunset: null },
|
|
316
|
+
astronomical: { sunrise: null, sunset: null },
|
|
317
|
+
eclipse: null,
|
|
318
|
+
obscuration: null,
|
|
319
|
+
start: refTempo,
|
|
320
|
+
end: refTempo
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
const elevation = isNumber2(geo?.elevation) ? geo.elevation : isNumber2(t.config?.geo?.elevation) ? (t.config?.geo).elevation : void 0;
|
|
324
|
+
const epochMs = refTempo.epoch.ms;
|
|
325
|
+
const res = cachedSunriseSunset(epochMs, {
|
|
326
|
+
latitude: lat,
|
|
327
|
+
longitude: lng,
|
|
328
|
+
...elevation !== void 0 ? { elevation } : {}
|
|
329
|
+
});
|
|
330
|
+
const position = cachedSolarPosition(epochMs, {
|
|
331
|
+
latitude: lat,
|
|
332
|
+
longitude: lng,
|
|
333
|
+
...elevation !== void 0 ? { elevation } : {}
|
|
334
|
+
});
|
|
335
|
+
const sunrise = toTempoOrNull(res.sunriseMs, timeZone);
|
|
336
|
+
const sunset = toTempoOrNull(res.sunsetMs, timeZone);
|
|
337
|
+
const solarNoon = toTempoOrNull(res.solarNoonMs, timeZone);
|
|
338
|
+
const solarNadir = toTempoOrNull(res.solarNadirMs, timeZone);
|
|
339
|
+
const localSolarDayStartMs = Date.UTC(
|
|
340
|
+
new Date(epochMs + lng * 24e4).getUTCFullYear(),
|
|
341
|
+
new Date(epochMs + lng * 24e4).getUTCMonth(),
|
|
342
|
+
new Date(epochMs + lng * 24e4).getUTCDate()
|
|
343
|
+
);
|
|
344
|
+
const solarTimeMs = Math.round(epochMs + (localSolarDayStartMs + HALF_DAY_MS - res.solarNoonMs));
|
|
345
|
+
const solarTime = toTempoOrNull(solarTimeMs, "UTC");
|
|
346
|
+
const civilSunrise = toTempoOrNull(res.civil.sunriseMs, timeZone);
|
|
347
|
+
const civilSunset = toTempoOrNull(res.civil.sunsetMs, timeZone);
|
|
348
|
+
const nauticalSunrise = toTempoOrNull(res.nautical.sunriseMs, timeZone);
|
|
349
|
+
const nauticalSunset = toTempoOrNull(res.nautical.sunsetMs, timeZone);
|
|
350
|
+
const astroSunrise = toTempoOrNull(res.astronomical.sunriseMs, timeZone);
|
|
351
|
+
const astroSunset = toTempoOrNull(res.astronomical.sunsetMs, timeZone);
|
|
352
|
+
const eclipseRes = getEclipse2(epochMs, lat, lng);
|
|
353
|
+
const eclipse = eclipseRes.type && eclipseRes.type.endsWith("-solar") ? eclipseRes.type : null;
|
|
354
|
+
const obscuration = eclipseRes.type && eclipseRes.type.endsWith("-solar") ? eclipseRes.obscuration : 0;
|
|
355
|
+
let start;
|
|
356
|
+
let end;
|
|
357
|
+
if (res.isMidnightSun || res.isPolarNight || !sunrise || !sunset) {
|
|
358
|
+
start = new Tempo3(res.solarNoonMs - HALF_DAY_MS, { timeZone, timeStamp: "ms" });
|
|
359
|
+
end = new Tempo3(res.solarNoonMs + HALF_DAY_MS, { timeZone, timeStamp: "ms" });
|
|
360
|
+
} else if (res.solarPhaseState === "daylight") {
|
|
361
|
+
start = sunrise;
|
|
362
|
+
end = sunset;
|
|
363
|
+
} else if (res.solarPhaseState === "civil-twilight") {
|
|
364
|
+
if (civilSunrise && epochMs < res.sunriseMs) {
|
|
365
|
+
start = civilSunrise;
|
|
366
|
+
end = sunrise;
|
|
367
|
+
} else {
|
|
368
|
+
start = sunset;
|
|
369
|
+
end = civilSunset ?? sunset;
|
|
370
|
+
}
|
|
371
|
+
} else if (res.solarPhaseState === "nautical-twilight") {
|
|
372
|
+
if (nauticalSunrise && civilSunrise && epochMs < res.civil.sunriseMs) {
|
|
373
|
+
start = nauticalSunrise;
|
|
374
|
+
end = civilSunrise;
|
|
375
|
+
} else {
|
|
376
|
+
start = civilSunset ?? sunset;
|
|
377
|
+
end = nauticalSunset ?? sunset;
|
|
378
|
+
}
|
|
379
|
+
} else if (res.solarPhaseState === "astronomical-twilight") {
|
|
380
|
+
if (astroSunrise && nauticalSunrise && epochMs < res.nautical.sunriseMs) {
|
|
381
|
+
start = astroSunrise;
|
|
382
|
+
end = nauticalSunrise;
|
|
383
|
+
} else {
|
|
384
|
+
start = nauticalSunset ?? sunset;
|
|
385
|
+
end = astroSunset ?? sunset;
|
|
386
|
+
}
|
|
387
|
+
} else {
|
|
388
|
+
start = sunset;
|
|
389
|
+
end = new Tempo3(res.sunriseMs + DAY_MS, { timeZone, timeStamp: "ms" });
|
|
390
|
+
}
|
|
391
|
+
return {
|
|
392
|
+
key: res.solarPhaseState,
|
|
393
|
+
phase: SOLAR_PHASE_NAMES[res.solarPhaseState],
|
|
394
|
+
phases: SOLAR_PHASE_STATES,
|
|
395
|
+
keys: SOLAR_PHASE_STATES,
|
|
396
|
+
index: res.index,
|
|
397
|
+
group: "solar",
|
|
398
|
+
geo,
|
|
399
|
+
elevation: isNumber2(geo?.elevation) ? geo.elevation : isNumber2(t.config?.geo?.elevation) ? (t.config?.geo).elevation : null,
|
|
400
|
+
...toDateTimeFields(start),
|
|
401
|
+
sunrise,
|
|
402
|
+
sunset,
|
|
403
|
+
noon: solarNoon,
|
|
404
|
+
nadir: solarNadir,
|
|
405
|
+
solarTime,
|
|
406
|
+
altitude: position.altitude,
|
|
407
|
+
azimuth: position.azimuth,
|
|
408
|
+
zenith: position.zenith,
|
|
409
|
+
isGoldenHour: position.isGoldenHour,
|
|
410
|
+
isBlueHour: position.isBlueHour,
|
|
411
|
+
shadowRatio: position.shadowRatio,
|
|
412
|
+
isMidnightSun: res.isMidnightSun,
|
|
413
|
+
isPolarNight: res.isPolarNight,
|
|
414
|
+
daylightDurationMs: res.daylightDurationMs,
|
|
415
|
+
isDaylight: res.isDaylight,
|
|
416
|
+
civil: { sunrise: civilSunrise, sunset: civilSunset },
|
|
417
|
+
nautical: { sunrise: nauticalSunrise, sunset: nauticalSunset },
|
|
418
|
+
astronomical: { sunrise: astroSunrise, sunset: astroSunset },
|
|
419
|
+
eclipse,
|
|
420
|
+
obscuration,
|
|
421
|
+
start,
|
|
422
|
+
end
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
var SolarTerm = defineTerm({
|
|
426
|
+
key: "sun",
|
|
427
|
+
aliases: ["solar"],
|
|
428
|
+
scope: "solar",
|
|
429
|
+
description: "Local solar day cycle and twilight range resolution",
|
|
430
|
+
phases: SOLAR_PHASE_STATES,
|
|
431
|
+
keys: SOLAR_PHASE_STATES,
|
|
432
|
+
...createCelestialTermHandlers(getSolarScopeRange),
|
|
433
|
+
[sdk_exports.TermHook.bound](boundary, _unit, tempo) {
|
|
434
|
+
const scope2 = getSolarScopeRange(tempo);
|
|
435
|
+
if (boundary === "start") return scope2.sunrise ?? scope2.start;
|
|
436
|
+
if (boundary === "end") return scope2.sunset ?? scope2.end;
|
|
437
|
+
if (boundary === "mid") return scope2.noon ?? tempo.set({ hour: 12, minute: 0, second: 0, millisecond: 0 });
|
|
438
|
+
return void 0;
|
|
439
|
+
},
|
|
440
|
+
[sdk_exports.TermHook.parse](input, context) {
|
|
441
|
+
const lower = input.toLowerCase();
|
|
442
|
+
if (lower.startsWith("#sun.") || lower.startsWith("#solar.")) {
|
|
443
|
+
const parts = lower.split(".");
|
|
444
|
+
if (parts.length !== 2) return void 0;
|
|
445
|
+
const sub = parts[1];
|
|
446
|
+
const anchor = context?.anchor;
|
|
447
|
+
const geo = context?.geo ?? context?.config?.geo;
|
|
448
|
+
const target = anchor ? anchor.geo ? anchor : geo ? new Tempo3(anchor, { ...anchor.config, geo }) : anchor : new Tempo3(void 0, { ...context?.config ?? {}, ...geo ? { geo } : {} });
|
|
449
|
+
const coords = getCelestialCoordinates(target, anchor);
|
|
450
|
+
if (!coords.hasGeo) return void 0;
|
|
451
|
+
const scope2 = getSolarScopeRange(coords.refTempo, anchor);
|
|
452
|
+
if (sub === "sunrise") return scope2.sunrise ?? void 0;
|
|
453
|
+
if (sub === "sunset") return scope2.sunset ?? void 0;
|
|
454
|
+
if (sub === "noon") return scope2.noon ?? void 0;
|
|
455
|
+
if (sub === "nadir") return scope2.nadir ?? void 0;
|
|
456
|
+
if (sub === "dawn") return scope2.civil.sunrise ?? void 0;
|
|
457
|
+
if (sub === "dusk") return scope2.civil.sunset ?? void 0;
|
|
458
|
+
if (sub === "start") return scope2.sunrise ?? scope2.start;
|
|
459
|
+
if (sub === "end") return scope2.sunset ?? scope2.end;
|
|
460
|
+
if (sub === "mid") return scope2.noon ?? void 0;
|
|
461
|
+
}
|
|
462
|
+
return void 0;
|
|
463
|
+
},
|
|
464
|
+
[sdk_exports.TermHook.format](token, tempo) {
|
|
465
|
+
const t = token.toLowerCase();
|
|
466
|
+
if (t === "#sun" || t === "#solar" || t.startsWith("#sun.") || t.startsWith("#solar.")) {
|
|
467
|
+
const scope2 = getSolarScopeRange(tempo);
|
|
468
|
+
if (t === "#solar.phase" || t === "#sun.phase" || t === "#sun" || t === "#solar") return scope2.phase ?? "";
|
|
469
|
+
if (t === "#solar.key" || t === "#sun.key") return scope2.key ?? "";
|
|
470
|
+
if (t === "#solar.altitude" || t === "#sun.altitude") {
|
|
471
|
+
return !isNull(scope2.altitude) ? `${Math.round(scope2.altitude * 10) / 10}\xB0` : "";
|
|
472
|
+
}
|
|
473
|
+
if (t === "#solar.elevation" || t === "#sun.elevation") {
|
|
474
|
+
return !isNull(scope2.elevation) ? `${scope2.elevation}m` : "";
|
|
475
|
+
}
|
|
476
|
+
if (t === "#solar.azimuth" || t === "#sun.azimuth") return !isNull(scope2.azimuth) ? `${Math.round(scope2.azimuth * 10) / 10}\xB0` : "";
|
|
477
|
+
if (t === "#solar.zenith" || t === "#sun.zenith") return !isNull(scope2.zenith) ? `${Math.round(scope2.zenith * 10) / 10}\xB0` : "";
|
|
478
|
+
}
|
|
479
|
+
return void 0;
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
// src/tidal.ts
|
|
484
|
+
import { getTidalState, TIDAL_PHASE_STATES } from "tempo-fns";
|
|
485
|
+
import { Tempo as Tempo4 } from "tempo-kit";
|
|
486
|
+
import { isNumber as isNumber3 } from "tempo-kit/library";
|
|
487
|
+
var TIDAL_STATE_CACHE = new sdk_exports.WeakCache();
|
|
488
|
+
function cachedTidalState(epochMs, options) {
|
|
489
|
+
const key2 = typeof options === "number" ? `${epochMs}:${options}` : `${epochMs}:${options.latitude}:${options.longitude}:${options.lunitidalIntervalMin ?? 0}:${options.regime ?? ""}`;
|
|
490
|
+
let res = TIDAL_STATE_CACHE.get(key2);
|
|
491
|
+
if (!res) {
|
|
492
|
+
res = getTidalState(epochMs, options);
|
|
493
|
+
TIDAL_STATE_CACHE.set(key2, res);
|
|
494
|
+
}
|
|
495
|
+
return res;
|
|
496
|
+
}
|
|
497
|
+
function getTidalScopeRange(t, anchor) {
|
|
498
|
+
const { refTempo, lat, lng, hasGeo, geo, timeZone } = getCelestialCoordinates(t, anchor);
|
|
499
|
+
const lunitidalIntervalMin = isNumber3(geo?.lunitidalIntervalMin) ? geo.lunitidalIntervalMin : isNumber3(t.config?.geo?.lunitidalIntervalMin) ? (t.config?.geo).lunitidalIntervalMin : void 0;
|
|
500
|
+
const regime = geo?.regime ?? t.config?.geo?.regime;
|
|
501
|
+
const res = cachedTidalState(refTempo.epoch.ms, hasGeo ? {
|
|
502
|
+
latitude: lat,
|
|
503
|
+
longitude: lng,
|
|
504
|
+
...lunitidalIntervalMin !== void 0 ? { lunitidalIntervalMin } : {},
|
|
505
|
+
...regime ? { regime } : {}
|
|
506
|
+
} : 0);
|
|
507
|
+
const nextHighTide = res.nextHighTideMs ? toTempoOrNull(res.nextHighTideMs, timeZone) : null;
|
|
508
|
+
const nextLowTide = res.nextLowTideMs ? toTempoOrNull(res.nextLowTideMs, timeZone) : null;
|
|
509
|
+
return {
|
|
510
|
+
key: res.state,
|
|
511
|
+
state: res.state,
|
|
512
|
+
group: "tide",
|
|
513
|
+
alignmentDeg: res.alignmentDeg,
|
|
514
|
+
isSpringTide: res.isSpringTide,
|
|
515
|
+
isNeapTide: res.isNeapTide,
|
|
516
|
+
isKingTide: hasGeo ? res.isKingTide : null,
|
|
517
|
+
perigeeFactor: res.perigeeFactor,
|
|
518
|
+
lunarTideMinute: hasGeo ? res.lunarTideMinute : null,
|
|
519
|
+
nextHighTide,
|
|
520
|
+
nextLowTide,
|
|
521
|
+
lunitidalIntervalMin: res.lunitidalIntervalMin ?? null,
|
|
522
|
+
regime: res.regime ?? null,
|
|
523
|
+
states: TIDAL_PHASE_STATES,
|
|
524
|
+
phases: TIDAL_PHASE_STATES,
|
|
525
|
+
keys: TIDAL_PHASE_STATES,
|
|
526
|
+
geo,
|
|
527
|
+
...toDateTimeFields(refTempo),
|
|
528
|
+
start: refTempo,
|
|
529
|
+
end: refTempo.add({ minutes: 745 })
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
var TidalTerm = defineTerm({
|
|
533
|
+
key: "tide",
|
|
534
|
+
aliases: ["tides", "tidal"],
|
|
535
|
+
scope: "tides",
|
|
536
|
+
description: "Astronomical tidal state, alignment, and perigee factor",
|
|
537
|
+
phases: TIDAL_PHASE_STATES,
|
|
538
|
+
states: TIDAL_PHASE_STATES,
|
|
539
|
+
keys: TIDAL_PHASE_STATES,
|
|
540
|
+
...createCelestialTermHandlers(getTidalScopeRange),
|
|
541
|
+
[sdk_exports.TermHook.step](_unit, count, tempo) {
|
|
542
|
+
return tempo.add({ minutes: count * 745 });
|
|
543
|
+
},
|
|
544
|
+
[sdk_exports.TermHook.bound](boundary, _unit, tempo) {
|
|
545
|
+
const scope2 = getTidalScopeRange(tempo);
|
|
546
|
+
const high = scope2.nextHighTide ?? scope2.start;
|
|
547
|
+
let low = scope2.nextLowTide;
|
|
548
|
+
if (!low) {
|
|
549
|
+
low = high.add({ minutes: 372.5 });
|
|
550
|
+
} else if (low.epoch.ms <= high.epoch.ms) {
|
|
551
|
+
low = low.add({ minutes: 745 });
|
|
552
|
+
}
|
|
553
|
+
if (boundary === "start") return high;
|
|
554
|
+
if (boundary === "end") return low;
|
|
555
|
+
if (boundary === "mid") {
|
|
556
|
+
const midMs = Math.round((high.epoch.ms + low.epoch.ms) / 2);
|
|
557
|
+
return new Tempo4(midMs, { timeZone: high.tz, timeStamp: "ms" });
|
|
558
|
+
}
|
|
559
|
+
return void 0;
|
|
560
|
+
},
|
|
561
|
+
[sdk_exports.TermHook.diff](other, _unit, tempo) {
|
|
562
|
+
return Math.round((other.epoch.ms - tempo.epoch.ms) / (745 * 60 * 1e3));
|
|
563
|
+
},
|
|
564
|
+
[sdk_exports.TermHook.format](token, tempo) {
|
|
565
|
+
const t = token.toLowerCase();
|
|
566
|
+
if (t === "#tide" || t === "#tides" || t.startsWith("#tide.") || t.startsWith("#tides.")) {
|
|
567
|
+
const scope2 = getTidalScopeRange(tempo);
|
|
568
|
+
if (t === "#tide.state" || t === "#tides.state" || t === "#tide" || t === "#tides") return scope2.state;
|
|
569
|
+
if (t === "#tide.alignment" || t === "#tides.alignment") return `${scope2.alignmentDeg}\xB0`;
|
|
570
|
+
}
|
|
571
|
+
return void 0;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
// src/astro.ts
|
|
576
|
+
import { Tempo as Tempo5 } from "tempo-kit";
|
|
577
|
+
import { getSolarEvents as getSolarEventsFn } from "tempo-fns";
|
|
578
|
+
var ASTRO = sdk_exports.Enum.from({ Vernal: "vernal", Summer: "summer", Autumnal: "autumnal", Winter: "winter" });
|
|
579
|
+
var ASTRO_KEYS = Object.freeze(["Vernal", "Summer", "Autumnal", "Winter"]);
|
|
580
|
+
var { COMPASS } = sdk_exports.enums;
|
|
581
|
+
var key = "astro";
|
|
582
|
+
var scope = "astronomy";
|
|
583
|
+
var SOLAR_EVENTS_CACHE = new sdk_exports.WeakCache();
|
|
584
|
+
function getSolarEvents(year) {
|
|
585
|
+
const cached = SOLAR_EVENTS_CACHE.get(year);
|
|
586
|
+
if (cached) return cached;
|
|
587
|
+
const events = getSolarEventsFn(year);
|
|
588
|
+
SOLAR_EVENTS_CACHE.set(year, events);
|
|
589
|
+
return events;
|
|
590
|
+
}
|
|
591
|
+
function calculateAstroMoment(year, quarter, timeZone) {
|
|
592
|
+
const events = getSolarEvents(year);
|
|
593
|
+
let keyName = "Vernal";
|
|
594
|
+
if (quarter === ASTRO.Summer) keyName = "Summer";
|
|
595
|
+
else if (quarter === ASTRO.Autumnal) keyName = "Autumnal";
|
|
596
|
+
else if (quarter === ASTRO.Winter) keyName = "Winter";
|
|
597
|
+
const match = events.find((e) => e.key === keyName);
|
|
598
|
+
const epochMs = match ? match.epochMs : Date.now();
|
|
599
|
+
return new Tempo5(epochMs, { timeZone, timeStamp: "ms" });
|
|
600
|
+
}
|
|
601
|
+
function toAnchorTempo(anchor, fallback) {
|
|
602
|
+
if (anchor instanceof Tempo5) {
|
|
603
|
+
return anchor.isValid ? anchor : fallback instanceof Tempo5 ? fallback : new Tempo5(fallback);
|
|
604
|
+
}
|
|
605
|
+
if (anchor !== void 0 && anchor !== null) {
|
|
606
|
+
if ((0, sdk_exports.isNumber)(anchor)) {
|
|
607
|
+
const inst = new fallback.constructor(new Date(anchor), fallback.config);
|
|
608
|
+
if (inst.isValid) return inst;
|
|
609
|
+
}
|
|
610
|
+
try {
|
|
611
|
+
const inst = new fallback.constructor(anchor, fallback.config);
|
|
612
|
+
if (inst.isValid) return inst;
|
|
613
|
+
} catch {
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return fallback instanceof Tempo5 ? fallback : new Tempo5(fallback);
|
|
617
|
+
}
|
|
618
|
+
function resolve(t, anchor) {
|
|
619
|
+
const anchorTempo = toAnchorTempo(anchor, t);
|
|
620
|
+
const sphere = (0, sdk_exports.resolveTermSphere)(anchorTempo.sphere ?? t.sphere, "AstroTerm", t.config);
|
|
621
|
+
if (!sphere || sphere === "equator") {
|
|
622
|
+
if (sphere === "equator")
|
|
623
|
+
(0, sdk_exports.logWarn)(`[tempo] AstroTerm requires an explicit hemisphere of 'north' or 'south' (received: "equator").`, t.config);
|
|
624
|
+
return [];
|
|
625
|
+
}
|
|
626
|
+
const isSouth = sphere === "south";
|
|
627
|
+
const compassSphere = isSouth ? COMPASS.South : COMPASS.North;
|
|
628
|
+
const year = anchorTempo.yy;
|
|
629
|
+
const timeZone = anchorTempo.tz ?? t.tz ?? "UTC";
|
|
630
|
+
const list = [];
|
|
631
|
+
const labels = isSouth ? { vernal: "Autumnal", summer: "Winter", autumnal: "Vernal", winter: "Summer" } : { vernal: "Vernal", summer: "Summer", autumnal: "Autumnal", winter: "Winter" };
|
|
632
|
+
const seasons = isSouth ? { vernal: "Autumn", summer: "Winter", autumnal: "Spring", winter: "Summer" } : { vernal: "Spring", summer: "Summer", autumnal: "Autumn", winter: "Winter" };
|
|
633
|
+
for (const y of [year - 1, year, year + 1]) {
|
|
634
|
+
const m = (y2, t2) => {
|
|
635
|
+
const moment = calculateAstroMoment(y2, t2, timeZone);
|
|
636
|
+
const dt = moment.toDateTime();
|
|
637
|
+
return {
|
|
638
|
+
year: dt.year,
|
|
639
|
+
month: dt.month,
|
|
640
|
+
day: dt.day,
|
|
641
|
+
hour: dt.hour,
|
|
642
|
+
minute: dt.minute,
|
|
643
|
+
second: dt.second,
|
|
644
|
+
millisecond: dt.millisecond,
|
|
645
|
+
microsecond: dt.microsecond,
|
|
646
|
+
nanosecond: dt.nanosecond
|
|
647
|
+
};
|
|
648
|
+
};
|
|
649
|
+
list.push({ key: labels.vernal, season: seasons.vernal, sphere: compassSphere, ...m(y, ASTRO.Vernal), event: "Equinox", group: "astronomy" });
|
|
650
|
+
list.push({ key: labels.summer, season: seasons.summer, sphere: compassSphere, ...m(y, ASTRO.Summer), event: "Solstice", group: "astronomy" });
|
|
651
|
+
list.push({ key: labels.autumnal, season: seasons.autumnal, sphere: compassSphere, ...m(y, ASTRO.Autumnal), event: "Equinox", group: "astronomy" });
|
|
652
|
+
list.push({ key: labels.winter, season: seasons.winter, sphere: compassSphere, ...m(y, ASTRO.Winter), event: "Solstice", group: "astronomy" });
|
|
653
|
+
}
|
|
654
|
+
return list;
|
|
655
|
+
}
|
|
656
|
+
function resolveFiltered(t, anchor, eventFilter) {
|
|
657
|
+
const list = resolve(t, anchor);
|
|
658
|
+
if (!eventFilter) return list;
|
|
659
|
+
return list.filter((item) => item.event === eventFilter);
|
|
660
|
+
}
|
|
661
|
+
function resolveDateBoundaryFiltered(t, anchor, eventFilter) {
|
|
662
|
+
const list = resolveFiltered(t, anchor, eventFilter);
|
|
663
|
+
return list.map((item) => ({ ...item, hour: 0, minute: 0, second: 0, millisecond: 0, microsecond: 0, nanosecond: 0 }));
|
|
664
|
+
}
|
|
665
|
+
var AstroTerm = defineTerm({
|
|
666
|
+
key,
|
|
667
|
+
aliases: ["equinox", "solstice"],
|
|
668
|
+
scope,
|
|
669
|
+
description: "Astronomical seasons and events",
|
|
670
|
+
keys: ASTRO_KEYS,
|
|
671
|
+
resolve(anchor, alias) {
|
|
672
|
+
const filterType = alias === "equinox" ? "Equinox" : alias === "solstice" ? "Solstice" : void 0;
|
|
673
|
+
return resolveFiltered(this, anchor, filterType);
|
|
674
|
+
},
|
|
675
|
+
define(keyOnly, anchor, alias) {
|
|
676
|
+
const filterType = alias === "equinox" ? "Equinox" : alias === "solstice" ? "Solstice" : void 0;
|
|
677
|
+
const anchorTempo = toAnchorTempo(anchor, this);
|
|
678
|
+
const strictList = resolveFiltered(this, anchorTempo, filterType);
|
|
679
|
+
const dateBoundaryList = resolveDateBoundaryFiltered(this, anchorTempo, filterType);
|
|
680
|
+
const zdt = anchorTempo.toDateTime();
|
|
681
|
+
if (keyOnly === true || keyOnly === void 0) {
|
|
682
|
+
const result = (0, sdk_exports.getTermRange)(this, dateBoundaryList, true, anchorTempo);
|
|
683
|
+
return result;
|
|
684
|
+
}
|
|
685
|
+
const scoped = (0, sdk_exports.getTermRange)(this, strictList, false, anchorTempo);
|
|
686
|
+
if (!scoped) return scoped;
|
|
687
|
+
const dateScoped = (0, sdk_exports.getTermRange)(this, dateBoundaryList, false, anchorTempo);
|
|
688
|
+
if (!dateScoped) return scoped;
|
|
689
|
+
const dateStart = dateScoped.span?.start?.toDateTime?.().withCalendar("iso8601");
|
|
690
|
+
const strictBoundary = dateStart ? strictList.find(
|
|
691
|
+
(item) => item.key === dateScoped.key && item.year === dateStart.year && item.month === dateStart.month && item.day === dateStart.day
|
|
692
|
+
) : void 0;
|
|
693
|
+
if (!strictBoundary) {
|
|
694
|
+
return {
|
|
695
|
+
...dateScoped,
|
|
696
|
+
strict: scoped.key,
|
|
697
|
+
keys: ASTRO_KEYS
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
const boundaryAnchor = zdt.with({
|
|
701
|
+
year: strictBoundary.year,
|
|
702
|
+
month: strictBoundary.month,
|
|
703
|
+
day: strictBoundary.day,
|
|
704
|
+
hour: strictBoundary.hour ?? 0,
|
|
705
|
+
minute: strictBoundary.minute ?? 0,
|
|
706
|
+
second: strictBoundary.second ?? 0,
|
|
707
|
+
millisecond: strictBoundary.millisecond ?? 0,
|
|
708
|
+
microsecond: strictBoundary.microsecond ?? 0,
|
|
709
|
+
nanosecond: strictBoundary.nanosecond ?? 0
|
|
710
|
+
}).add({ minutes: 1 });
|
|
711
|
+
const keyedScope = (0, sdk_exports.getTermRange)(this, strictList, false, boundaryAnchor);
|
|
712
|
+
if (!keyedScope) {
|
|
713
|
+
return {
|
|
714
|
+
...dateScoped,
|
|
715
|
+
strict: scoped.key,
|
|
716
|
+
keys: ASTRO_KEYS
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
return {
|
|
720
|
+
...keyedScope,
|
|
721
|
+
span: (0, sdk_exports.defineSpan)(this, keyedScope.span.start, keyedScope.span.end, zdt),
|
|
722
|
+
strict: scoped.key,
|
|
723
|
+
keys: ASTRO_KEYS
|
|
724
|
+
};
|
|
725
|
+
},
|
|
726
|
+
[sdk_exports.TermHook.ordinal](groups, anchor) {
|
|
727
|
+
const ord = groups.ord?.toLowerCase();
|
|
728
|
+
const termLower = (groups.term || "").toLowerCase();
|
|
729
|
+
const year = anchor?.yy ?? new Tempo5().yy;
|
|
730
|
+
const events = getSolarEvents(year);
|
|
731
|
+
const filterType = termLower.includes("equinox") ? "Equinox" : termLower.includes("solstice") ? "Solstice" : void 0;
|
|
732
|
+
const matching = filterType ? events.filter((e) => e.event === filterType) : [...events];
|
|
733
|
+
matching.sort((a, b) => a.epochMs - b.epochMs);
|
|
734
|
+
const ordMap = Tempo5.enums.ORDINAL;
|
|
735
|
+
const rawVal = groups.value ?? ordMap?.[ord];
|
|
736
|
+
const val = (0, sdk_exports.isNumber)(rawVal) ? rawVal : ord === "last" ? -1 : parseInt(rawVal ?? ord, 10) || ordMap?.[ord];
|
|
737
|
+
if (!val) return void 0;
|
|
738
|
+
const index = val < 0 ? matching.length + val + 1 : val;
|
|
739
|
+
if (index < 1 || index > matching.length) return void 0;
|
|
740
|
+
const target = matching[index - 1];
|
|
741
|
+
return new Tempo5(target.epochMs, { timeZone: anchor?.tz ?? "UTC", timeStamp: "ms", ...anchor?.sphere ? { sphere: anchor.sphere } : {} });
|
|
742
|
+
},
|
|
743
|
+
[sdk_exports.TermHook.parse](input, context) {
|
|
744
|
+
const lower = input.toLowerCase();
|
|
745
|
+
if (lower.startsWith("#astro.") || lower.startsWith("#equinox.") || lower.startsWith("#solstice.")) {
|
|
746
|
+
const parts = lower.slice(1).split(".");
|
|
747
|
+
if (parts.length !== 2) return void 0;
|
|
748
|
+
const [prefix, sub] = parts;
|
|
749
|
+
const isEquinox = sub === "vernal" || sub === "spring" || sub === "autumnal" || sub === "autumn";
|
|
750
|
+
const isSolstice = sub === "summer" || sub === "winter";
|
|
751
|
+
if (prefix === "equinox" && !isEquinox) return void 0;
|
|
752
|
+
if (prefix === "solstice" && !isSolstice) return void 0;
|
|
753
|
+
const year = context?.anchor?.yy ?? context?.anchor?.year ?? new Tempo5().yy;
|
|
754
|
+
const timeZone = context?.anchor?.tz ?? "UTC";
|
|
755
|
+
const sphere = (0, sdk_exports.resolveTermSphere)(context?.anchor?.sphere ?? context?.config?.sphere, "AstroTerm", context?.config);
|
|
756
|
+
if (!sphere || sphere === "equator") return void 0;
|
|
757
|
+
const isSouth = sphere === "south";
|
|
758
|
+
let quarter;
|
|
759
|
+
if (isEquinox) {
|
|
760
|
+
if (sub === "vernal" || sub === "spring") quarter = isSouth ? ASTRO.Autumnal : ASTRO.Vernal;
|
|
761
|
+
else quarter = isSouth ? ASTRO.Vernal : ASTRO.Autumnal;
|
|
762
|
+
} else if (isSolstice) {
|
|
763
|
+
if (sub === "summer") quarter = isSouth ? ASTRO.Winter : ASTRO.Summer;
|
|
764
|
+
else quarter = isSouth ? ASTRO.Summer : ASTRO.Winter;
|
|
765
|
+
}
|
|
766
|
+
if (quarter) {
|
|
767
|
+
const moment = calculateAstroMoment(year, quarter, timeZone);
|
|
768
|
+
return new Tempo5(moment.epoch.ms, { timeZone, timeStamp: "ms", sphere });
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
return void 0;
|
|
772
|
+
},
|
|
773
|
+
[sdk_exports.TermHook.bound](boundary, _unit, tempo) {
|
|
774
|
+
const target = tempo instanceof Tempo5 ? tempo : new Tempo5(tempo);
|
|
775
|
+
const scope2 = AstroTerm.define.call(target, false);
|
|
776
|
+
const start = scope2?.span?.start;
|
|
777
|
+
const end = scope2?.span?.end;
|
|
778
|
+
if (start && end) {
|
|
779
|
+
if (boundary === "start") return start;
|
|
780
|
+
if (boundary === "end") return end.sub({ nanoseconds: 1 });
|
|
781
|
+
if (boundary === "mid") {
|
|
782
|
+
const midMs = Math.round((start.epoch.ms + end.epoch.ms) / 2);
|
|
783
|
+
return new Tempo5(midMs, { timeZone: start.tz, timeStamp: "ms", ...target.sphere ? { sphere: target.sphere } : {} });
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
return void 0;
|
|
787
|
+
},
|
|
788
|
+
[sdk_exports.TermHook.format](token, tempo) {
|
|
789
|
+
const t = token.toLowerCase();
|
|
790
|
+
if (t === "#astro" || t === "#astronomy" || t === "#equinox" || t === "#solstice" || t === "#astro.season" || t === "#astro.event" || t === "#astro.key") {
|
|
791
|
+
const alias = t === "#equinox" ? "equinox" : t === "#solstice" ? "solstice" : void 0;
|
|
792
|
+
const scope2 = AstroTerm.define.call(tempo, false, void 0, alias);
|
|
793
|
+
if (scope2) {
|
|
794
|
+
if (t === "#astro.season") return scope2.season;
|
|
795
|
+
if (t === "#astro.event") return scope2.event;
|
|
796
|
+
if (t === "#astro.key") return scope2.key;
|
|
797
|
+
return `${scope2.key} ${scope2.event}`;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return void 0;
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
|
|
804
|
+
// src/index.ts
|
|
805
|
+
var CelestialPlugin = [SolarTerm, LunarTerm, TidalTerm, AstroTerm];
|
|
806
|
+
var index_default = CelestialPlugin;
|
|
807
|
+
export {
|
|
808
|
+
ASTRO_KEYS,
|
|
809
|
+
AstroTerm,
|
|
810
|
+
CelestialPlugin,
|
|
811
|
+
DAY_MS2 as DAY_MS,
|
|
812
|
+
HALF_DAY_MS2 as HALF_DAY_MS,
|
|
813
|
+
LUNAR_PHASE_KEYS2 as LUNAR_PHASE_KEYS,
|
|
814
|
+
LunarTerm,
|
|
815
|
+
SOLAR_PHASE_NAMES2 as SOLAR_PHASE_NAMES,
|
|
816
|
+
SOLAR_PHASE_STATES2 as SOLAR_PHASE_STATES,
|
|
817
|
+
SolarTerm,
|
|
818
|
+
TIDAL_PHASE_STATES2 as TIDAL_PHASE_STATES,
|
|
819
|
+
TidalTerm,
|
|
820
|
+
index_default as default,
|
|
821
|
+
getEclipse3 as getEclipse,
|
|
822
|
+
getSolarPosition2 as getSolarPosition
|
|
823
|
+
};
|