@johnmorrisdotca/wakusei-planets 0.19.0 → 0.21.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 +23 -0
- package/NOTICE.md +14 -3
- package/README.md +39 -6
- package/dist/bodies/earth.js +13 -5
- package/dist/calendar.d.ts +119 -0
- package/dist/calendar.js +155 -0
- package/dist/clock.d.ts +244 -0
- package/dist/clock.js +325 -0
- package/dist/coordinates.d.ts +172 -0
- package/dist/coordinates.js +170 -0
- package/dist/craft/cassini.d.ts +1 -0
- package/dist/craft/cassini.js +1131 -0
- package/dist/craft/galileo.d.ts +1 -0
- package/dist/craft/galileo.js +224 -0
- package/dist/craft/juno.d.ts +1 -0
- package/dist/craft/juno.js +640 -0
- package/dist/craft/newhorizons.d.ts +1 -0
- package/dist/craft/newhorizons.js +18 -0
- package/dist/craft/parker.d.ts +1 -0
- package/dist/craft/parker.js +221 -0
- package/dist/craft/pioneer10.d.ts +1 -0
- package/dist/craft/pioneer10.js +24 -0
- package/dist/craft/pioneer11.d.ts +1 -0
- package/dist/craft/pioneer11.js +34 -0
- package/dist/craft/voyager1.d.ts +1 -0
- package/dist/craft/voyager1.js +28 -0
- package/dist/craft/voyager2.d.ts +1 -0
- package/dist/craft/voyager2.js +43 -0
- package/dist/craft/webb.d.ts +1 -0
- package/dist/craft/webb.js +28 -0
- package/dist/data/craft.d.ts +23 -0
- package/dist/data/craft.js +53 -0
- package/dist/data/lunar.d.ts +4 -0
- package/dist/data/lunar.js +548 -0
- package/dist/data/pluto.d.ts +6 -0
- package/dist/data/pluto.js +29 -0
- package/dist/data/stars.d.ts +4 -0
- package/dist/data/stars.js +5088 -0
- package/dist/data/tables.d.ts +41 -0
- package/dist/data/tables.js +37 -0
- package/dist/data/vsop.d.ts +19 -1
- package/dist/data/vsop.js +25 -8
- package/dist/element.d.ts +2 -23
- package/dist/element.js +75 -110
- package/dist/ephemeris.d.ts +22 -14
- package/dist/ephemeris.js +106 -58
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mars.d.ts +41 -0
- package/dist/mars.js +52 -0
- package/dist/portrait/element.d.ts +1 -0
- package/dist/portrait/element.js +27 -39
- package/dist/scales.d.ts +46 -0
- package/dist/scales.js +75 -0
- package/dist/scene/basis.d.ts +3 -0
- package/dist/scene/basis.js +4 -0
- package/dist/scene/body.d.ts +2 -4
- package/dist/scene/body.js +55 -67
- package/dist/scene/fallback.d.ts +4 -0
- package/dist/scene/fallback.js +5 -0
- package/dist/scene/painter.js +10 -23
- package/dist/scene/store.d.ts +2 -2
- package/dist/scene/textures.d.ts +30 -0
- package/dist/scene/textures.js +47 -0
- package/dist/sidereal.d.ts +70 -0
- package/dist/sidereal.js +94 -0
- package/dist/sky/engine.d.ts +37 -0
- package/dist/sky/engine.js +116 -0
- package/dist/sky/events.d.ts +37 -0
- package/dist/sky/events.js +133 -0
- package/dist/sky/frames.d.ts +3 -0
- package/dist/sky/frames.js +26 -0
- package/dist/sky/types.d.ts +20 -0
- package/dist/sky/types.js +1 -0
- package/dist/space/aim.d.ts +18 -0
- package/dist/space/aim.js +28 -0
- package/dist/space/element.d.ts +212 -0
- package/dist/space/element.js +524 -0
- package/dist/space/frame.d.ts +152 -0
- package/dist/space/frame.js +169 -0
- package/dist/space/index.d.ts +4 -0
- package/dist/space/index.js +5 -0
- package/dist/space/ride.d.ts +89 -0
- package/dist/space/ride.js +58 -0
- package/dist/space/scale.d.ts +126 -0
- package/dist/space/scale.js +139 -0
- package/dist/space/scene.d.ts +189 -0
- package/dist/space/scene.js +422 -0
- package/dist/spacecraft-facts.d.ts +114 -0
- package/dist/spacecraft-facts.js +215 -0
- package/dist/spacecraft.d.ts +134 -0
- package/dist/spacecraft.js +198 -0
- package/dist/stars.d.ts +160 -0
- package/dist/stars.js +193 -0
- package/dist/suncalc-legacy.d.ts +187 -0
- package/dist/suncalc-legacy.js +168 -0
- package/dist/suncalc.d.ts +209 -0
- package/dist/suncalc.js +167 -0
- package/dist/tables/all.d.ts +2 -0
- package/dist/tables/all.js +2 -0
- package/dist/tables/ceres.d.ts +1 -0
- package/dist/tables/ceres.js +57 -0
- package/dist/tables/dwarfs.d.ts +1 -0
- package/dist/tables/dwarfs.js +59 -0
- package/dist/theory.d.ts +20 -0
- package/dist/theory.js +98 -0
- package/dist/time.d.ts +6 -108
- package/dist/time.js +7 -180
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/when.d.ts +16 -0
- package/dist/when.js +13 -0
- package/package.json +95 -4
package/dist/stars.d.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { type When } from "./when.ts";
|
|
2
|
+
/**
|
|
3
|
+
* One star, as the Yale Bright Star Catalogue gives it. Positions are J2000 (equator and equinox of 2000, the FK5 frame, which is the ICRS to a fraction of an arc-second).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { starByName, type Star } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
8
|
+
*
|
|
9
|
+
* const sirius: Star = starByName("Sirius")!;
|
|
10
|
+
* console.log(sirius.designation, sirius.magnitude);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface Star {
|
|
14
|
+
/** The Bright Star Catalogue (Harvard Revised) number: stable, and the key for `starByHr`. */
|
|
15
|
+
hr: number;
|
|
16
|
+
/** The common name where the star has one (the IAU Working Group on Star Names' spelling), else `undefined`. */
|
|
17
|
+
name: string | undefined;
|
|
18
|
+
/** The Bayer letter and constellation (`α CMa`), else the Flamsteed number and constellation (`9 CMa`), else `undefined`. */
|
|
19
|
+
designation: string | undefined;
|
|
20
|
+
/** The IAU three-letter constellation abbreviation (`CMa`) where the star has a Bayer or Flamsteed name, else `undefined`. */
|
|
21
|
+
constellation: string | undefined;
|
|
22
|
+
/** Right ascension in degrees at J2000, 0 up to 360. The catalogue gives it to a tenth of a second of time (1.5 arc-seconds at the equator). */
|
|
23
|
+
rightAscension: number;
|
|
24
|
+
/** Declination in degrees at J2000, -90 to 90. The catalogue gives it to an arc-second. */
|
|
25
|
+
declination: number;
|
|
26
|
+
/** Visual magnitude: smaller is brighter, and Sirius is -1.46. */
|
|
27
|
+
magnitude: number;
|
|
28
|
+
/** The colour index B-V in magnitudes, or `undefined` where the catalogue has none. Hot blue stars are about -0.3, the Sun 0.65, cool red stars above 1.5. */
|
|
29
|
+
colourIndex: number | undefined;
|
|
30
|
+
/** The spectral class and subclass (`A1`, `K1`), or an empty string where the catalogue gives none we read. */
|
|
31
|
+
spectralClass: string;
|
|
32
|
+
/** Proper motion in right ascension, in milliarcseconds a year, already multiplied by cos(declination) (a true angle on the sky). */
|
|
33
|
+
properMotionRaMas: number;
|
|
34
|
+
/** Proper motion in declination, in milliarcseconds a year. */
|
|
35
|
+
properMotionDecMas: number;
|
|
36
|
+
/** The annual parallax in milliarcseconds; 0 where the catalogue has none (the distance is then unknown). */
|
|
37
|
+
parallaxMas: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The stars to a magnitude, brightest first. The catalogue stops at magnitude 6.0, so the default is all 5,080.
|
|
41
|
+
*
|
|
42
|
+
* @param options - `magnitude`: the faintest to include (a star of exactly that magnitude is in). Brighter limits give shorter lists: 1.5 is 15 stars, 4 is 518, 5 is 1,630.
|
|
43
|
+
* @returns A fresh array of the shared, frozen stars.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { stars } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
48
|
+
*
|
|
49
|
+
* console.log(stars().length, stars({ magnitude: 2 }).map((s) => s.name ?? s.designation).slice(0, 3));
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function stars(options?: {
|
|
53
|
+
magnitude?: number;
|
|
54
|
+
}): Star[];
|
|
55
|
+
/**
|
|
56
|
+
* A star by its Bright Star Catalogue number.
|
|
57
|
+
*
|
|
58
|
+
* @param hr - The HR number (Sirius is 2491).
|
|
59
|
+
* @returns The star, or `undefined` if that number is not in this table (the table holds the stars to magnitude 6.0 only).
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { starByHr } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
64
|
+
*
|
|
65
|
+
* console.log(starByHr(2491)?.name);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function starByHr(hr: number): Star | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* A star by its common name (`Sirius`) or its designation (`α CMa`, `9 CMa`), ignoring case.
|
|
71
|
+
*
|
|
72
|
+
* @param text - The name or designation.
|
|
73
|
+
* @returns The star, or `undefined`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { starByName } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
78
|
+
*
|
|
79
|
+
* console.log(starByName("betelgeuse")?.designation, starByName("α Lyr")?.name);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function starByName(text: string): Star | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Where a star is at a moment: its J2000 position carried forward (or back) by its proper motion in a straight line. The frame stays J2000, so precession to the date is not applied: use
|
|
85
|
+
* the result with J2000 coordinates, or convert it to the date with `/coordinates`. A straight line is good to a fraction of an arc-second for centuries for nearly every star here; it is
|
|
86
|
+
* not good for the few with large motion over millennia.
|
|
87
|
+
*
|
|
88
|
+
* @param star - A star.
|
|
89
|
+
* @param when - The moment as a `Date` or milliseconds since 1970 (UTC); J2000 when left out.
|
|
90
|
+
* @returns Right ascension and declination in degrees, J2000 frame, at that moment.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { starByName, starPosition } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
95
|
+
*
|
|
96
|
+
* const now = starPosition(starByName("Arcturus")!, Date.UTC(2026, 10, 7));
|
|
97
|
+
* console.log(now.declination.toFixed(3));
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function starPosition(star: Star, when?: When): {
|
|
101
|
+
rightAscension: number;
|
|
102
|
+
declination: number;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* A star's distance from its parallax, in light-years.
|
|
106
|
+
*
|
|
107
|
+
* @param star - A star.
|
|
108
|
+
* @returns Light-years, or `undefined` where the catalogue has no parallax (or a non-positive one).
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { starByName, starDistanceLightYears } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
113
|
+
*
|
|
114
|
+
* console.log(starDistanceLightYears(starByName("Sirius")!)?.toFixed(1));
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function starDistanceLightYears(star: Star): number | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* The surface temperature a colour index implies, in kelvin, by Ballesteros's relation between B-V and a black body. It is an estimate to a few hundred kelvin for most stars, and it runs cool for the hottest (about 16,600 K at -0.3).
|
|
120
|
+
*
|
|
121
|
+
* @param colourIndex - B-V in magnitudes.
|
|
122
|
+
* @returns Kelvin.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { starTemperatureK } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
127
|
+
*
|
|
128
|
+
* console.log(Math.round(starTemperatureK(0.65)));
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export declare function starTemperatureK(colourIndex: number): number;
|
|
132
|
+
/**
|
|
133
|
+
* The colour of a black body at a temperature, as a `#rrggbb` string, for drawing a star. It is the colour a camera would show, not a measurement, and it uses an approximation of the
|
|
134
|
+
* black-body locus (good to a few percent between 1,000 and 40,000 K).
|
|
135
|
+
*
|
|
136
|
+
* @param kelvin - Temperature in kelvin.
|
|
137
|
+
* @returns A colour like `#a4bdff`.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* import { blackBodyColour } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
142
|
+
*
|
|
143
|
+
* console.log(blackBodyColour(10000), blackBodyColour(3500));
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export declare function blackBodyColour(kelvin: number): string;
|
|
147
|
+
/**
|
|
148
|
+
* The colour to draw a star: from its B-V index, or a plain white where the catalogue has none.
|
|
149
|
+
*
|
|
150
|
+
* @param star - A star.
|
|
151
|
+
* @returns A `#rrggbb` string.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { starByName, starColour } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
156
|
+
*
|
|
157
|
+
* console.log(starColour(starByName("Betelgeuse")!), starColour(starByName("Rigel")!));
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function starColour(star: Star): string;
|
package/dist/stars.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// The stars you can see without a telescope: the 5,080 of the Yale Bright Star Catalogue to visual magnitude 6.0, with their names, positions, proper motion, brightness and colour.
|
|
2
|
+
// An opt-in entry point (`@johnmorrisdotca/wakusei-planets/stars`): the table is about 100 kB gzipped and nothing else imports it. Pure: no DOM, no three.js, no state beyond the parsed table.
|
|
3
|
+
import { J2000_MS } from "./clock.js";
|
|
4
|
+
import { STAR_NAMES, STAR_ROWS } from "./data/stars.js";
|
|
5
|
+
import { moment } from "./when.js";
|
|
6
|
+
const stored = [];
|
|
7
|
+
const byHr = new Map();
|
|
8
|
+
const byText = new Map();
|
|
9
|
+
function load() {
|
|
10
|
+
if (stored.length > 0)
|
|
11
|
+
return;
|
|
12
|
+
for (const row of STAR_ROWS.split("\n")) {
|
|
13
|
+
const p = row.split("|");
|
|
14
|
+
const hr = Number(p[0]);
|
|
15
|
+
const letter = p[1];
|
|
16
|
+
const flamsteed = p[2];
|
|
17
|
+
const constellation = p[3];
|
|
18
|
+
const designation = constellation === "" ? undefined : `${letter !== "" ? letter : flamsteed} ${constellation}`;
|
|
19
|
+
const star = Object.freeze({
|
|
20
|
+
hr,
|
|
21
|
+
name: STAR_NAMES[hr],
|
|
22
|
+
designation: letter === "" && flamsteed === "" ? undefined : designation,
|
|
23
|
+
constellation: constellation === "" ? undefined : constellation,
|
|
24
|
+
rightAscension: (Number(p[4]) / 2400),
|
|
25
|
+
declination: Number(p[5]) / 3600,
|
|
26
|
+
magnitude: Number(p[8]) / 100,
|
|
27
|
+
colourIndex: p[9] === "" ? undefined : Number(p[9]) / 100,
|
|
28
|
+
spectralClass: p[10],
|
|
29
|
+
properMotionRaMas: Number(p[6]),
|
|
30
|
+
properMotionDecMas: Number(p[7]),
|
|
31
|
+
parallaxMas: Number(p[11]),
|
|
32
|
+
});
|
|
33
|
+
stored.push(star);
|
|
34
|
+
byHr.set(hr, star);
|
|
35
|
+
for (const text of [star.name, star.designation])
|
|
36
|
+
if (text !== undefined)
|
|
37
|
+
byText.set(text.toLowerCase(), star);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The stars to a magnitude, brightest first. The catalogue stops at magnitude 6.0, so the default is all 5,080.
|
|
42
|
+
*
|
|
43
|
+
* @param options - `magnitude`: the faintest to include (a star of exactly that magnitude is in). Brighter limits give shorter lists: 1.5 is 15 stars, 4 is 518, 5 is 1,630.
|
|
44
|
+
* @returns A fresh array of the shared, frozen stars.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { stars } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
49
|
+
*
|
|
50
|
+
* console.log(stars().length, stars({ magnitude: 2 }).map((s) => s.name ?? s.designation).slice(0, 3));
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function stars(options = {}) {
|
|
54
|
+
load();
|
|
55
|
+
const limit = options.magnitude ?? Number.POSITIVE_INFINITY;
|
|
56
|
+
if (typeof limit !== "number" || Number.isNaN(limit))
|
|
57
|
+
throw new TypeError(`magnitude must be a number, got ${String(limit)}`);
|
|
58
|
+
return stored.filter((star) => star.magnitude <= limit);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A star by its Bright Star Catalogue number.
|
|
62
|
+
*
|
|
63
|
+
* @param hr - The HR number (Sirius is 2491).
|
|
64
|
+
* @returns The star, or `undefined` if that number is not in this table (the table holds the stars to magnitude 6.0 only).
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { starByHr } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
69
|
+
*
|
|
70
|
+
* console.log(starByHr(2491)?.name);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function starByHr(hr) {
|
|
74
|
+
load();
|
|
75
|
+
return byHr.get(hr);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A star by its common name (`Sirius`) or its designation (`α CMa`, `9 CMa`), ignoring case.
|
|
79
|
+
*
|
|
80
|
+
* @param text - The name or designation.
|
|
81
|
+
* @returns The star, or `undefined`.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { starByName } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
86
|
+
*
|
|
87
|
+
* console.log(starByName("betelgeuse")?.designation, starByName("α Lyr")?.name);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function starByName(text) {
|
|
91
|
+
load();
|
|
92
|
+
return byText.get(text.trim().toLowerCase());
|
|
93
|
+
}
|
|
94
|
+
const JULIAN_YEAR_MS = 365.25 * 86_400_000;
|
|
95
|
+
/**
|
|
96
|
+
* Where a star is at a moment: its J2000 position carried forward (or back) by its proper motion in a straight line. The frame stays J2000, so precession to the date is not applied: use
|
|
97
|
+
* the result with J2000 coordinates, or convert it to the date with `/coordinates`. A straight line is good to a fraction of an arc-second for centuries for nearly every star here; it is
|
|
98
|
+
* not good for the few with large motion over millennia.
|
|
99
|
+
*
|
|
100
|
+
* @param star - A star.
|
|
101
|
+
* @param when - The moment as a `Date` or milliseconds since 1970 (UTC); J2000 when left out.
|
|
102
|
+
* @returns Right ascension and declination in degrees, J2000 frame, at that moment.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* import { starByName, starPosition } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
107
|
+
*
|
|
108
|
+
* const now = starPosition(starByName("Arcturus")!, Date.UTC(2026, 10, 7));
|
|
109
|
+
* console.log(now.declination.toFixed(3));
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export function starPosition(star, when) {
|
|
113
|
+
const years = (moment(when ?? J2000_MS) - J2000_MS) / JULIAN_YEAR_MS;
|
|
114
|
+
const declination = star.declination + (star.properMotionDecMas * years) / 3_600_000;
|
|
115
|
+
const cosine = Math.cos((star.declination * Math.PI) / 180);
|
|
116
|
+
// The motion is a true angle on the sky: it stretches by 1 / cos(declination) in right ascension. At the poles the division is kept finite.
|
|
117
|
+
const rightAscension = star.rightAscension + (star.properMotionRaMas * years) / 3_600_000 / Math.max(Math.abs(cosine), 1e-6);
|
|
118
|
+
return { rightAscension: ((rightAscension % 360) + 360) % 360, declination: Math.max(-90, Math.min(90, declination)) };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A star's distance from its parallax, in light-years.
|
|
122
|
+
*
|
|
123
|
+
* @param star - A star.
|
|
124
|
+
* @returns Light-years, or `undefined` where the catalogue has no parallax (or a non-positive one).
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { starByName, starDistanceLightYears } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
129
|
+
*
|
|
130
|
+
* console.log(starDistanceLightYears(starByName("Sirius")!)?.toFixed(1));
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export function starDistanceLightYears(star) {
|
|
134
|
+
return star.parallaxMas > 0 ? 3261.563777 / star.parallaxMas : undefined;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The surface temperature a colour index implies, in kelvin, by Ballesteros's relation between B-V and a black body. It is an estimate to a few hundred kelvin for most stars, and it runs cool for the hottest (about 16,600 K at -0.3).
|
|
138
|
+
*
|
|
139
|
+
* @param colourIndex - B-V in magnitudes.
|
|
140
|
+
* @returns Kelvin.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* import { starTemperatureK } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
145
|
+
*
|
|
146
|
+
* console.log(Math.round(starTemperatureK(0.65)));
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export function starTemperatureK(colourIndex) {
|
|
150
|
+
if (!Number.isFinite(colourIndex))
|
|
151
|
+
throw new RangeError(`colourIndex must be a finite number, got ${colourIndex}`);
|
|
152
|
+
return 4600 * (1 / (0.92 * colourIndex + 1.7) + 1 / (0.92 * colourIndex + 0.62));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The colour of a black body at a temperature, as a `#rrggbb` string, for drawing a star. It is the colour a camera would show, not a measurement, and it uses an approximation of the
|
|
156
|
+
* black-body locus (good to a few percent between 1,000 and 40,000 K).
|
|
157
|
+
*
|
|
158
|
+
* @param kelvin - Temperature in kelvin.
|
|
159
|
+
* @returns A colour like `#a4bdff`.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { blackBodyColour } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
164
|
+
*
|
|
165
|
+
* console.log(blackBodyColour(10000), blackBodyColour(3500));
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export function blackBodyColour(kelvin) {
|
|
169
|
+
if (!Number.isFinite(kelvin) || kelvin <= 0)
|
|
170
|
+
throw new RangeError(`kelvin must be a positive number, got ${kelvin}`);
|
|
171
|
+
const t = Math.min(40_000, Math.max(1_000, kelvin)) / 100;
|
|
172
|
+
const red = t <= 66 ? 255 : 329.698727446 * (t - 60) ** -0.1332047592;
|
|
173
|
+
const green = t <= 66 ? 99.4708025861 * Math.log(t) - 161.1195681661 : 288.1221695283 * (t - 60) ** -0.0755148492;
|
|
174
|
+
const blue = t >= 66 ? 255 : t <= 19 ? 0 : 138.5177312231 * Math.log(t - 10) - 305.0447927307;
|
|
175
|
+
const byte = (v) => Math.round(Math.min(255, Math.max(0, v))).toString(16).padStart(2, "0");
|
|
176
|
+
return `#${byte(red)}${byte(green)}${byte(blue)}`;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The colour to draw a star: from its B-V index, or a plain white where the catalogue has none.
|
|
180
|
+
*
|
|
181
|
+
* @param star - A star.
|
|
182
|
+
* @returns A `#rrggbb` string.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* import { starByName, starColour } from "@johnmorrisdotca/wakusei-planets/stars";
|
|
187
|
+
*
|
|
188
|
+
* console.log(starColour(starByName("Betelgeuse")!), starColour(starByName("Rigel")!));
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export function starColour(star) {
|
|
192
|
+
return star.colourIndex === undefined ? "#ffffff" : blackBodyColour(starTemperatureK(star.colourIndex));
|
|
193
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a body is: the azimuth in radians from south toward west (0 south, a quarter turn west) and the altitude in radians.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { getPosition, type LegacyPosition } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
7
|
+
*
|
|
8
|
+
* const p: LegacyPosition = getPosition(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
|
|
9
|
+
* console.log(p.altitude > 0);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export interface LegacyPosition {
|
|
13
|
+
azimuth: number;
|
|
14
|
+
altitude: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The Moon in a place's sky: the LegacyPosition, the distance in kilometres and the parallactic angle in radians.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { getMoonPosition, type LegacyMoonPosition } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
22
|
+
*
|
|
23
|
+
* const p: LegacyMoonPosition = getMoonPosition(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7);
|
|
24
|
+
* console.log(p.distance > 350000);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export interface LegacyMoonPosition extends LegacyPosition {
|
|
28
|
+
distance: number;
|
|
29
|
+
parallacticAngle: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The Moon's illumination in suncalc 1's terms: the lit fraction, the phase 0 to 1, and the bright limb's angle in radians, negative while the Moon waxes and positive while it wanes.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { getMoonIllumination, type LegacyMoonIllumination } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
37
|
+
*
|
|
38
|
+
* const m: LegacyMoonIllumination = getMoonIllumination(new Date(Date.UTC(2026, 10, 24, 14)));
|
|
39
|
+
* console.log(m.fraction >= 0 && m.fraction <= 1);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export interface LegacyMoonIllumination {
|
|
43
|
+
fraction: number;
|
|
44
|
+
phase: number;
|
|
45
|
+
angle: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The Sun's times with every one a `Date`: an invalid `Date` (`NaN`) when the Sun does not reach that height that day.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { getTimes, type LegacySunTimes } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
53
|
+
*
|
|
54
|
+
* const t: LegacySunTimes = getTimes(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
|
|
55
|
+
* console.log(Object.keys(t).length);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export type LegacySunTimes = Record<string, Date>;
|
|
59
|
+
/**
|
|
60
|
+
* The Moon's rise and set; `alwaysUp` or `alwaysDown` is `true` when the Moon never rises or sets in the day.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { getMoonTimes, type LegacyMoonTimes } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
65
|
+
*
|
|
66
|
+
* const t: LegacyMoonTimes = getMoonTimes(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7, true);
|
|
67
|
+
* console.log(t.rise === undefined || t.rise instanceof Date);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export interface LegacyMoonTimes {
|
|
71
|
+
rise?: Date;
|
|
72
|
+
set?: Date;
|
|
73
|
+
alwaysUp?: boolean;
|
|
74
|
+
alwaysDown?: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The times suncalc 1 gives, as `[altitude in degrees, morning name, evening name]`.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { times } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
82
|
+
*
|
|
83
|
+
* console.log(times.length);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare const times: Array<[number, string, string]>;
|
|
87
|
+
/**
|
|
88
|
+
* Add a time to the ones `getTimes` gives: when the Sun reaches an altitude in degrees.
|
|
89
|
+
*
|
|
90
|
+
* @param angle - The altitude in degrees.
|
|
91
|
+
* @param riseName - The name when the Sun goes up through it.
|
|
92
|
+
* @param setName - The name when the Sun goes down through it.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { addTime, times } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
97
|
+
*
|
|
98
|
+
* addTime(-4, "morningBlue", "eveningBlue");
|
|
99
|
+
* console.log(times.some((row) => row[1] === "morningBlue"));
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function addTime(angle: number, riseName: string, setName: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* The Sun's place in the sky, as suncalc 1 gave it: the altitude has no refraction in it.
|
|
105
|
+
*
|
|
106
|
+
* @param date - The moment.
|
|
107
|
+
* @param lat - Degrees north.
|
|
108
|
+
* @param lng - Degrees east.
|
|
109
|
+
* @returns The azimuth in radians from south toward west and the altitude in radians.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { getPosition } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
114
|
+
*
|
|
115
|
+
* const { altitude } = getPosition(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
|
|
116
|
+
* console.log((altitude * 180 / Math.PI).toFixed(0));
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function getPosition(date: Date | number, lat: number, lng: number): LegacyPosition;
|
|
120
|
+
/**
|
|
121
|
+
* The Moon's place in the sky, as suncalc 1 gave it: the altitude includes refraction.
|
|
122
|
+
*
|
|
123
|
+
* @param date - The moment.
|
|
124
|
+
* @param lat - Degrees north.
|
|
125
|
+
* @param lng - Degrees east.
|
|
126
|
+
* @returns The azimuth and altitude in radians, the distance in kilometres and the parallactic angle in radians.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* import { getMoonPosition } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
131
|
+
*
|
|
132
|
+
* const { distance } = getMoonPosition(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7);
|
|
133
|
+
* console.log(Math.round(distance / 1000));
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export declare function getMoonPosition(date: Date | number, lat: number, lng: number): LegacyMoonPosition;
|
|
137
|
+
/**
|
|
138
|
+
* The Moon's phase, as suncalc 1 gave it.
|
|
139
|
+
*
|
|
140
|
+
* @param date - The moment; now when left out.
|
|
141
|
+
* @returns The lit fraction, the phase 0 to 1 and the bright limb's angle in radians (negative while waxing).
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { getMoonIllumination } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
146
|
+
*
|
|
147
|
+
* const { fraction, angle } = getMoonIllumination(new Date(Date.UTC(2026, 10, 24, 14)));
|
|
148
|
+
* console.log(fraction.toFixed(2), angle < 0);
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function getMoonIllumination(date?: Date | number): LegacyMoonIllumination;
|
|
152
|
+
/**
|
|
153
|
+
* The Sun's times for the solar day nearest a moment, as suncalc 1 gave them: every time a `Date`, invalid when it does not happen.
|
|
154
|
+
*
|
|
155
|
+
* @param date - Any moment of the day.
|
|
156
|
+
* @param lat - Degrees north.
|
|
157
|
+
* @param lng - Degrees east.
|
|
158
|
+
* @param height - The observer's height in metres (default 0).
|
|
159
|
+
* @returns The times by name.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { getTimes } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
164
|
+
*
|
|
165
|
+
* const t = getTimes(new Date(Date.UTC(2026, 5, 21, 12)), 51.5, -0.1);
|
|
166
|
+
* console.log(t.sunrise!.getTime() < t.sunset!.getTime());
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function getTimes(date: Date | number, lat: number, lng: number, height?: number): LegacySunTimes;
|
|
170
|
+
/**
|
|
171
|
+
* The Moon's rise and set over the 24 hours from midnight of the moment's day, in the machine's zone or, with `inUTC`, in UTC.
|
|
172
|
+
*
|
|
173
|
+
* @param date - Any moment of the day.
|
|
174
|
+
* @param lat - Degrees north.
|
|
175
|
+
* @param lng - Degrees east.
|
|
176
|
+
* @param inUTC - Search the UTC day instead of the local one.
|
|
177
|
+
* @returns `rise` and `set` when they happen, and `alwaysUp` or `alwaysDown` when the Moon stays up or down.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* import { getMoonTimes } from "@johnmorrisdotca/wakusei-planets/suncalc/legacy";
|
|
182
|
+
*
|
|
183
|
+
* const t = getMoonTimes(new Date(Date.UTC(2026, 10, 7, 12)), 35.7, 139.7, true);
|
|
184
|
+
* console.log(t.rise === undefined || t.rise instanceof Date);
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export declare function getMoonTimes(date: Date | number, lat: number, lng: number, inUTC?: boolean): LegacyMoonTimes;
|