@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.
Files changed (113) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/NOTICE.md +14 -3
  3. package/README.md +39 -6
  4. package/dist/bodies/earth.js +13 -5
  5. package/dist/calendar.d.ts +119 -0
  6. package/dist/calendar.js +155 -0
  7. package/dist/clock.d.ts +244 -0
  8. package/dist/clock.js +325 -0
  9. package/dist/coordinates.d.ts +172 -0
  10. package/dist/coordinates.js +170 -0
  11. package/dist/craft/cassini.d.ts +1 -0
  12. package/dist/craft/cassini.js +1131 -0
  13. package/dist/craft/galileo.d.ts +1 -0
  14. package/dist/craft/galileo.js +224 -0
  15. package/dist/craft/juno.d.ts +1 -0
  16. package/dist/craft/juno.js +640 -0
  17. package/dist/craft/newhorizons.d.ts +1 -0
  18. package/dist/craft/newhorizons.js +18 -0
  19. package/dist/craft/parker.d.ts +1 -0
  20. package/dist/craft/parker.js +221 -0
  21. package/dist/craft/pioneer10.d.ts +1 -0
  22. package/dist/craft/pioneer10.js +24 -0
  23. package/dist/craft/pioneer11.d.ts +1 -0
  24. package/dist/craft/pioneer11.js +34 -0
  25. package/dist/craft/voyager1.d.ts +1 -0
  26. package/dist/craft/voyager1.js +28 -0
  27. package/dist/craft/voyager2.d.ts +1 -0
  28. package/dist/craft/voyager2.js +43 -0
  29. package/dist/craft/webb.d.ts +1 -0
  30. package/dist/craft/webb.js +28 -0
  31. package/dist/data/craft.d.ts +23 -0
  32. package/dist/data/craft.js +53 -0
  33. package/dist/data/lunar.d.ts +4 -0
  34. package/dist/data/lunar.js +548 -0
  35. package/dist/data/pluto.d.ts +6 -0
  36. package/dist/data/pluto.js +29 -0
  37. package/dist/data/stars.d.ts +4 -0
  38. package/dist/data/stars.js +5088 -0
  39. package/dist/data/tables.d.ts +41 -0
  40. package/dist/data/tables.js +37 -0
  41. package/dist/data/vsop.d.ts +19 -1
  42. package/dist/data/vsop.js +25 -8
  43. package/dist/element.d.ts +2 -23
  44. package/dist/element.js +75 -110
  45. package/dist/ephemeris.d.ts +22 -14
  46. package/dist/ephemeris.js +106 -58
  47. package/dist/index.d.ts +1 -1
  48. package/dist/index.js +1 -1
  49. package/dist/mars.d.ts +41 -0
  50. package/dist/mars.js +52 -0
  51. package/dist/portrait/element.d.ts +1 -0
  52. package/dist/portrait/element.js +27 -39
  53. package/dist/scales.d.ts +46 -0
  54. package/dist/scales.js +75 -0
  55. package/dist/scene/basis.d.ts +3 -0
  56. package/dist/scene/basis.js +4 -0
  57. package/dist/scene/body.d.ts +2 -4
  58. package/dist/scene/body.js +55 -67
  59. package/dist/scene/fallback.d.ts +4 -0
  60. package/dist/scene/fallback.js +5 -0
  61. package/dist/scene/painter.js +10 -23
  62. package/dist/scene/store.d.ts +2 -2
  63. package/dist/scene/textures.d.ts +30 -0
  64. package/dist/scene/textures.js +47 -0
  65. package/dist/sidereal.d.ts +70 -0
  66. package/dist/sidereal.js +94 -0
  67. package/dist/sky/engine.d.ts +37 -0
  68. package/dist/sky/engine.js +116 -0
  69. package/dist/sky/events.d.ts +37 -0
  70. package/dist/sky/events.js +133 -0
  71. package/dist/sky/frames.d.ts +3 -0
  72. package/dist/sky/frames.js +26 -0
  73. package/dist/sky/types.d.ts +20 -0
  74. package/dist/sky/types.js +1 -0
  75. package/dist/space/aim.d.ts +18 -0
  76. package/dist/space/aim.js +28 -0
  77. package/dist/space/element.d.ts +212 -0
  78. package/dist/space/element.js +524 -0
  79. package/dist/space/frame.d.ts +152 -0
  80. package/dist/space/frame.js +169 -0
  81. package/dist/space/index.d.ts +4 -0
  82. package/dist/space/index.js +5 -0
  83. package/dist/space/ride.d.ts +89 -0
  84. package/dist/space/ride.js +58 -0
  85. package/dist/space/scale.d.ts +126 -0
  86. package/dist/space/scale.js +139 -0
  87. package/dist/space/scene.d.ts +189 -0
  88. package/dist/space/scene.js +422 -0
  89. package/dist/spacecraft-facts.d.ts +114 -0
  90. package/dist/spacecraft-facts.js +215 -0
  91. package/dist/spacecraft.d.ts +134 -0
  92. package/dist/spacecraft.js +198 -0
  93. package/dist/stars.d.ts +160 -0
  94. package/dist/stars.js +193 -0
  95. package/dist/suncalc-legacy.d.ts +187 -0
  96. package/dist/suncalc-legacy.js +168 -0
  97. package/dist/suncalc.d.ts +209 -0
  98. package/dist/suncalc.js +167 -0
  99. package/dist/tables/all.d.ts +2 -0
  100. package/dist/tables/all.js +2 -0
  101. package/dist/tables/ceres.d.ts +1 -0
  102. package/dist/tables/ceres.js +57 -0
  103. package/dist/tables/dwarfs.d.ts +1 -0
  104. package/dist/tables/dwarfs.js +59 -0
  105. package/dist/theory.d.ts +20 -0
  106. package/dist/theory.js +98 -0
  107. package/dist/time.d.ts +6 -108
  108. package/dist/time.js +7 -180
  109. package/dist/version.d.ts +1 -1
  110. package/dist/version.js +1 -1
  111. package/dist/when.d.ts +16 -0
  112. package/dist/when.js +13 -0
  113. package/package.json +95 -4
package/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.21.0] - 2026-11-08
6
+
7
+ - **`/spacecraft`: famous spacecraft, where they are and their whole voyage** (MODULES-622). Ten craft: Voyager 1 and 2, New Horizons, Pioneer 10 and 11, Cassini, Galileo, Juno, Parker Solar Probe and the James Webb Space Telescope. Each path is a Chebyshev table fitted to JPL Horizons over the whole of Horizons' own record of the craft (`scripts/make-spacecraft-data.py`, `src/craft/<craft>.ts`; segments from seconds near a planet to years in cruise, limit 1,000 km near a planet and a millionth of the distance from the Sun elsewhere, measured worst 570 to 840 km for the orbiters, Parker and Webb, 7,000 to 26,000 km in deep cruise), loaded on demand (`loadSpacecraft`; 2 to 5 kB gzipped each, Galileo 25, Parker 27, Juno 77, Cassini 127). `spacecraftPosition` (km from the Sun, J2000 ecliptic), `spacecraftVelocity`, `spacecraftSpeed`, `spacecraftSunDistance`, `spacecraftEarthDistance`, `spacecraftLightTime` and `spacecraftErrorKm`, with `SPACECRAFT`: names in English and Japanese, launch, agency, status, NASA's page, Horizons' record and its `joins` (where Horizons' own record steps, up to 459,000 km for Pioneer 11), and the voyage's events (launch, 33 flybys and orbit insertions, end) from NASA's mission pages. Every flyby is tested against the closest approach of the fitted path to the body. Where a NASA page and the path disagree the path's date is kept (listed in the guide). Pure, no DOM, no three.js. EN/JA guide `docs/guides/spacecraft.md`.
8
+ - **To scale treats every body the same** (MODULES-621). The Earth was measured against the Sun because a body was never measured against itself, so it showed as a dot with a magnified picture beside it, like a moon. A body measured against itself is now the reference, drawn full size like the planets beside it, and the caption mentions a magnified picture only when there is one (English and Japanese).
9
+ - **Pinch is tested** (MODULES-527): two fingers zoom the demo's view, and on the portrait page a pinch on a body sizes it while a pinch elsewhere zooms; the portrait help says so in both languages.
10
+ - **Why two packages** (MODULES-520): a guide in English and Japanese on this package and chikyu-earth: the rule (the Earth in detail there, every other body and the solar system here, the dependency one way), a table of what lives where, and how each works alone and together; a short README section.
11
+ - **`/earth` builds without chikyu-earth** (MODULES-612). It imported the optional peer `@johnmorrisdotca/chikyu-earth` itself, so a project without it failed to build with esbuild and webpack, and with Vite the line Earth stayed blank in the browser. Now `/earth` never imports it: the Earth's line look is this package's own outline, and chikyu-earth's globe with the countries when the page imports `@johnmorrisdotca/chikyu-earth/element` (add that one line if you relied on `/earth` loading it). A usage check builds `/earth` with chikyu-earth absent and draws it.
12
+ - **`<wakusei-space>` and `/space`: the Earth, the Moon, the Sun and the planets in their places** (MODULES-518, taken over from chikyu-earth's space view). One WebGL context through the shared renderer, a compressed scale and a true one, time forwards and backwards, a zoom from the Earth to the whole solar system, the Moon's phase and the Earth's day side from the real Sun, a body to look at, the planets' orbits, and the nearer moons round a planet; positions are this package's own VSOP87B, Pluto and ELP2000 models (the Sun and the Moon within a hundredth of a degree and the planets within a few hundredths of astronomy-engine, the test oracle). The pure maths (`frameAt`, `createTrack`, `placeSun`, `placeAround`, `radiusIn`, `groundDirection`) is in `/space`. A day a second draws 29 frames a second and looks the sky up twice a second.
13
+ - **Riding along, for any body** (MODULES-518). `space.ride(target)` puts the camera at the Moon, a planet, a moon of a planet (`io` over Jupiter) or any moving point of your own (`{ at(ms) }`: position and velocity from the centre of the body it goes round) and looks at that body, straight down or at the horizon; a drag looks about, a switch glides, a point that cannot be placed is reported once, and it draws only as often as the picture moves a pixel. `ridePose` (in `/space`) takes the radius of the body it goes round, so it is not tied to the Earth; it knows no satellites, so chikyu-earth can ride one through it.
14
+ - **Rise and set times measured against JPL Horizons** (MODULES-561). Six places from the equator to 70 degrees north, seven days from 2000 to 2040, the same definition for every package: this package is within 0.4 s for the Sun and the Moon, astronomy-engine 0.5 s and 1.4 s, suncalc 2.1.2 5.3 s and 7.1 s. The `/suncalc` guide's table now says so, and the source no longer claims suncalc is a minute or two off. `pnpm test` holds this package to 1 s; `scripts/compare/rise-set.mjs` measures all three.
15
+ - **The scientific core and the drawing code are cleaned up** (MODULES-562; no position, time or picture changes). One mean obliquity, one Greenwich mean sidereal angle and one J2000-ecliptic-to-true-equator-of-date rotation (`src/sky/frames.ts`) shared by `/coordinates`, `/time` and the sky engine; one `Observer` and one set of angle types (`src/sky/types.ts`); offsets validated once; the shaded looks share the texture paths, picture loading, matrix writes and the fallback look. Height in an observer is documented as above the WGS 84 ellipsoid. New `heliocentricModel(planet, ms)`: the theory that answers `heliocentric` for that body and moment with the tables loaded now, and the fitted table's measured worst error.
16
+ - **`/stars`: the stars you can see without a telescope** (MODULES-571, part of MODULES-539). The 5,080 stars to visual magnitude 6.0 of the Yale Bright Star Catalogue (Hoffleit and Warren 1991, credited in NOTICE.md), brightest first, with IAU names for 111 of them: `stars`, `starByHr`, `starByName`, `starPosition` (proper motion, straight line, J2000 frame), `starDistanceLightYears`, `starTemperatureK`, `blackBodyColour` and `starColour`. A separate entry point of about 100 kB gzipped that nothing else imports. Positions are tested against published values to the catalogue's 0.1 second of time and 1 arc-second, the counts by magnitude, proper motion over a century and the colour of the hot and cool ends. The data comes from Yale rather than Hipparcos because ESA's catalogues are non-commercial (CC BY-NC) and could not be passed on under the MIT licence. EN/JA guide `docs/guides/stars.md`.
17
+
18
+ ## [0.20.0] - 2026-11-07
19
+
20
+ - **`/time` is the whole clock** (MODULES-538). The `julian` package's functions under the same names (`julian`, `toDate`, `toJulianDay`, `toMillisecondsInJulianDay`, `fromJulianDayAndMilliseconds`; julian truncates toward zero before 31 December 1969 and gives a day one too high, these floor); `julianCenturies`, `julianMillennia` and the epochs (`J2000_JD`, `J2000_MS`, `B1950_JD`); the Gregorian and Julian calendars (`toCalendar`, `fromCalendar`, `dayOfWeek`, `dayOfYear`, `daysInMonth`, `isLeapYear`, the switch of 1582, astronomical years, the whole range of a Date); time scales UTC, UT1, TAI, GPS, TT and TDB (`convertTimeScale`, `taiMinusUtc`, `deltaT`, `tdbMinusTt`) with the leap seconds from 1972; sidereal time (`greenwichMeanSiderealTime`, `greenwichApparentSiderealTime`, `localSiderealTime`, `equationOfTheEquinoxes`); and Mars time (`marsSolDate`, `coordinatedMarsTime`, `marsLocalMeanSolarTime`). Every function takes a `Date` or milliseconds, never changes a `Date` and throws on an invalid one. About 3 kB gzipped, no dependencies. Tests: Meeus's worked examples (chapters 7 and 12), the julian package and astronomy-engine as dev-only oracles, round trips over the years -5000 to 5000 and the ends of a Date, every pair of time scales from 1800 to 2200. EN/JA guide `docs/guides/time.md`.
21
+ - Add a reproducible, development-only accuracy comparison against JPL Horizons for wakusei, Astronomy Engine, Python solarsystem and SunCalc 2.1.2, with EN/JA tables, pinned dependencies, source provenance and frozen regression limits (MODULES-556). Astronomy Engine wins Earth and the four Galilean moons on the shared modern grid; no blanket superiority is claimed.
22
+ - **`/suncalc`: the Sun and Moon from a place, a drop-in for suncalc 2** (MODULES-535). `getPosition`, `getTimes`, `addTime`, `times`, `getMoonPosition`, `getMoonIllumination` and `getMoonTimes` with suncalc 2's names, arguments and results (degrees, azimuth from north, `utcOffset`, observer height, Moon transits), on this package's own VSOP87B Sun and ELP2000-82B Moon with precession, nutation, aberration, parallax and refraction. Sunrise and sunset are within 7 seconds of astronomy-engine and moonrise within 1 (suncalc is 13 and 5); the tests compare against suncalc 2.1.2, suncalc 1.9.0 and astronomy-engine as dev-only oracles. `/suncalc/legacy` has suncalc 1's conventions (radians, azimuth from south, invalid dates, `inUTC`) so only the import changes. Both are 10 kB gzipped: the Earth's VSOP87B series now has its own export (`VSOP_EARTH`) so a page needs one planet, and the two theories moved to `src/theory.ts`. EN/JA guide. Planets' rise and set, eclipses and suncalc3's extras are not here yet (MODULES-537).
23
+ - **The Moon is ELP2000-82B, within 2 arc-seconds of Horizons** (MODULES-528). The Moon was the largest terms of a short series and 0.21 degrees (760 arc-seconds) from Horizons; it is now the lunar solution ELP2000-82B (Chapront-Touzé and Chapront, IMCCE) cut to its 540 largest terms (of 37,872), in terrestrial time, with the constants fitted to JPL's DE200 folded in (`scripts/make-lunar-data.py`, `src/data/lunar.ts`; the core entry point grows from 39.3 to 44.7 kB gzipped). The worst of seven dates from 1900 to 2100 is 1.8 arc-seconds and the distance is within 0.8 km; the limit in `test/accuracy.test.ts` falls from 0.3 degrees to 0.0008. The phase, rise and set of the Moon follow from the better position.
24
+ - **The dwarf planets are fitted to Horizons** (MODULES-554, 557). Ceres was 9 degrees from Horizons in 1900 and 2 degrees in 2000, and Orcus, Haumea, Quaoar, Makemake, Gonggong, Eris and Sedna a few arc-minutes, because each was one ellipse of one epoch. Each is now a Chebyshev table from the solar system's barycentre (`scripts/make-dwarf-data.py`), with the Sun's twelve-year swing about the barycentre added back from the planets' masses; all eight are within 0.2 arc-seconds of Horizons on dates off the fit's grid (Ceres 1900 to 2100, the others 1800 to 2200). `test/accuracy.test.ts` holds each to a limit, `test/pluto.test.ts` checks the segment edges, and the tables load on demand (MODULES-557): `@johnmorrisdotca/wakusei-planets/tables/dwarfs` (about 5 kB gzipped), `/tables/ceres` (about 14 kB) and `/tables` for both register themselves, the web component imports them, and `heliocentric` without them still answers with the old elements, so the core entry point stays at 39.0 kB gzipped.
25
+ - **Pluto is fitted to Horizons** (MODULES-528). VSOP87 has no Pluto, and JPL's approximate elements were 39 arc-seconds from Horizons; a table of 20 Chebyshev segments of 20 years (1800 to 2200, `scripts/make-pluto-data.py`, `src/data/pluto.ts`) is 0.05 arc-seconds on the five reference dates and 0.15 at worst on samples held back from the fit. Pluto is no longer the loosest planet; Saturn and Uranus (3.7 and 3.8) are. The segments are fitted on their own, so the position can step by up to 0.15 arc-seconds where one ends (tested). The elements still answer outside 1800 to 2200. The remaining error is the Sun's yearly wobble about the system's centre of mass, 0.016 arc-seconds at Pluto's distance, which a polynomial of this size cannot follow. The core entry point grows from 35.1 to 39.0 kB gzipped.
26
+ - Add the pure `/coordinates` sub-path: spherical/Cartesian AU coordinates, mean ecliptic/equatorial rotations at J2000 or of date, and equatorial-of-date to horizontal directions. Explicit origins, frames and epochs, degree angles, EN/JA guides, Meeus known-answer tests and a 4 KiB gzip budget (MODULES-555).
27
+
5
28
  ## 0.19.0 - 2026-11-07
6
29
 
7
30
  The planets and the moons are where they are, and every body is checked against JPL Horizons (MODULES-528, 525, 522). 0.18.0 was never published: what it holds, the view gestures, is below and is in this release.
package/NOTICE.md CHANGED
@@ -9,22 +9,33 @@ No picture is used by the line and shaded looks: they are drawn from numbers.
9
9
  - **Sizes, flattening, axial tilt, poles and rotation**: the IAU Working Group on Cartographic Coordinates and Rotational Elements, B. A. Archinal et al. (2018), "Report of the IAU Working Group on Cartographic Coordinates and Rotational Elements: 2015", Celestial Mechanics and Dynamical Astronomy 130:22, and NASA's planetary and satellite fact sheets (https://nssdc.gsfc.nasa.gov/planetary/factsheet/, read 2026-11-02). Facts are not copyrightable; the values were typed from these sources.
10
10
  - **Mercury to Neptune**: the VSOP87B series, P. Bretagnon and G. Francou (1988), "Planetary theories in rectangular and spherical variables: VSOP87 solutions", Astronomy and Astrophysics 202, 309, from the files of IMCCE, Observatoire de Paris (https://ftp.imcce.fr/pub/ephem/planets/vsop87/, read 2026-11-07), cut to 991 of 35,080 terms into `src/data/vsop.ts` by `scripts/make-vsop-data.py`. The files state their precision and ask to be cited; they carry no licence text, and the numbers are a published scientific table.
11
11
  - **Time scales**: the leap seconds are IERS Bulletin C; delta T before 1972 is the polynomials of F. Espenak and J. Meeus (NASA, https://eclipse.gsfc.nasa.gov/SEhelp/deltatpoly2004.html), in `src/time.ts`.
12
- - **Pluto's position**: JPL Solar System Dynamics, "Keplerian Elements for Approximate Positions of the Major Planets", Table 1, 1800 AD to 2050 AD (https://ssd.jpl.nasa.gov/planets/approx_pos.html, read 2026-11-02; Pluto from the same page's earlier edition). NASA/JPL content is not subject to copyright in the United States; credit: NASA/JPL-Caltech.
12
+ - **Calendars, sidereal time and Mars time (`/time`)**: written here from J. Meeus, "Astronomical Algorithms" (2nd edition, chapters 7 and 12: the Julian day and the sidereal time), the Richards day-number algorithm for the calendars, M. Allison and M. McEwen, "A post-Pathfinder evaluation of aerocentric solar coordinates with improved timing recipes for Mars seasonal/diurnal climate studies", Planetary and Space Science 48, 215 (2000), and Meeus's two-term formula for TDB minus TT. The names of the Julian-date functions follow the `julian` package (MIT, Stepan Stolyarov), whose code is not used; `julian` 0.2.0 and astronomy-engine are development-time comparisons in `test/calendar.test.ts` only and are not shipped.
13
+ - **Pluto's position**: a Chebyshev table (`src/data/pluto.ts`, made by `scripts/make-pluto-data.py`) fitted to JPL Horizons (https://ssd.jpl.nasa.gov/api/horizons.api, read 2026-11-07), 1800 to 2200; outside those years, and for its earlier edition, JPL Solar System Dynamics, "Keplerian Elements for Approximate Positions of the Major Planets", Table 1, 1800 AD to 2050 AD (https://ssd.jpl.nasa.gov/planets/approx_pos.html, read 2026-11-02; Pluto from the same page's earlier edition). NASA/JPL content is not subject to copyright in the United States; credit: NASA/JPL-Caltech.
13
14
  - **Moons' orbits**: fitted to the positions and velocities of JPL Horizons (https://ssd.jpl.nasa.gov/api/horizons.api, read 2026-11-07) for 1950 to 2050, by `scripts/make-moon-data.py`, which writes `src/data/orbits.ts`; the Moon's row, and the pole of each moon's reference plane, are from JPL Solar System Dynamics, "Planetary Satellite Mean Elements" (https://ssd.jpl.nasa.gov/sats/elem/, read 2026-11-02). The positions the accuracy test compares with are in `test/data/horizons.json`, fetched by `scripts/fetch-horizons-reference.py`. Credit: NASA/JPL-Caltech; the satellite ephemerides behind Horizons are R. A. Jacobson and colleagues' (the page names each).
14
- - **The Moon's position**: the largest terms of the series in Jean Meeus, "Astronomical Algorithms" (2nd edition), chapter 47, written out here as numbers; the mean arguments are the standard ones.
15
+ - **The Moon's position**: the lunar solution ELP2000-82B, M. Chapront-Touzé and J. Chapront, "The lunar ephemeris ELP 2000", Astron. Astrophys. 124, 50 (1983) and "ELP 2000-85", Astron. Astrophys. 190, 342 (1988), from IMCCE, Observatoire de Paris (https://ftp.imcce.fr/pub/ephem/moon/elp82b/). Its 37,872 terms are cut to the 540 above 0.05 arc-seconds (`scripts/make-lunar-data.py`, `src/data/lunar.ts`) and written out as numbers, with the constants fitted to JPL's DE200 that the notice gives. IMCCE's files carry no licence text; they are published for use with the credit above (the same footing as VSOP87).
16
+ - **Sun and Moon times (`/suncalc`)**: written here from the standard methods: J. Meeus, "Astronomical Algorithms" (2nd edition, chapters 11, 12, 21, 22, 48), the IAU 1976 precession, the IAU 1980 nutation (its largest terms), Saemundsson's refraction formula, and the Naval Observatory's convention for the rise and set of the Moon and Sun. The names, arguments and results follow the public interface of suncalc (BSD-2-Clause, Copyright (c) Volodymyr Agafonkin; https://github.com/mourner/suncalc), whose code is not used. suncalc 1.9.0 and 2.1.2 and astronomy-engine (MIT) are development-time comparisons in `test/suncalc.test.ts` only and are not shipped.
17
+ - **Stars (`/stars`)**: the Yale Bright Star Catalogue, D. Hoffleit and W. H. Warren Jr. (1991), "The Bright Star Catalogue, 5th Revised Edition (Preliminary Version)", Astronomical Data Center (NASA Goddard Space Flight Center) and the Centre de Données astronomiques de Strasbourg, catalogue V/50, as NASA's HEASARC serves it (table bsc5p, https://heasarc.gsfc.nasa.gov/W3Browse/star-catalog/bsc5p.html, file heasarc_bsc5p.tdat.gz, read 2026-11-08; a US government source), the 5,080 stars to visual magnitude 6.0, written out as numbers by `scripts/make-star-data.py` into `src/data/stars.ts`. The catalogue's own documentation calls it public domain and the Astronomical Data Center asks that it and the authors be acknowledged, which this line does; there is no formal licence text, so this footing is informal. The common names are our own list after the IAU Working Group on Star Names (https://www.iau.org/science/scientific_bodies/working_groups/280/); the star colour is Ballesteros's B-V to temperature relation (F. J. Ballesteros 2012, EPL 97, 34008) and a piecewise black-body colour fit. Deliberately NOT used: the Hipparcos, Tycho and Gaia catalogues (ESA, CC BY-NC 3.0 IGO, non-commercial), and HYG, AT-HYG and OpenNGC (CC BY-SA, which would put share-alike terms on this package's data).
15
18
  - **Mass and escape speed** (`JOURNEY_STOPS`): JPL "Planetary Satellite Physical Parameters" (https://ssd.jpl.nasa.gov/sats/phys_par/, read 2026-11-04) for the GM of the Earth, Mars through Pluto and the moons on that page; NASA's Sun, Mercury and Venus fact sheets (https://nssdc.gsfc.nasa.gov/planetary/factsheet/, read 2026-11-04) for those three GM values and the Sun's escape speed; JPL "Planetary Physical Parameters" (https://ssd.jpl.nasa.gov/planets/phys_par.html, read 2026-11-04) for the planets' escape speeds and for the masses of Ceres, Eris, Makemake and Haumea, turned into GM with the CODATA 2018 G that page names. A moon's escape speed is computed from its GM and the radius already in this package. Nereid, Orcus, Quaoar, Gonggong, Sedna, Vanth, Hiʻiaka, Namaka and Dysnomia are left blank: those pages do not print a mass.
16
19
 
17
20
  ## The dwarf planets
18
21
 
19
22
  Ceres, Orcus, Haumea, Quaoar, Makemake, Gonggong, Eris and Sedna (Pluto is with the planets) and the moons Vanth, Hiʻiaka, Namaka and Dysnomia. Values read on 2026-11-03.
20
23
 
21
- - **Where they are**: NASA/JPL Small-Body Database, osculating elements at JD 2461200.5 (https://ssd.jpl.nasa.gov/api/sbdb.api), run as a plain ellipse (`src/data/dwarf.ts`): good for a few years either side of June 2026, and Ceres, pulled by Jupiter, drifts most.
24
+ - **Where they are**: JPL Horizons (https://ssd.jpl.nasa.gov/api/horizons.api), fitted as Chebyshev tables from the solar system's barycentre (`scripts/make-dwarf-data.py`, `src/data/dwarfs.ts`), with the Sun's swing about the barycentre worked out from the planets' masses (IAU 2012 and JPL DE440 mass ratios): Ceres 1900 to 2100, the others 1800 to 2200, each within 0.2 arc-seconds of Horizons. Outside those years, NASA/JPL Small-Body Database osculating elements at JD 2461200.5 (https://ssd.jpl.nasa.gov/api/sbdb.api), run as a plain ellipse (`src/data/dwarf.ts`): good for a few years either side of June 2026.
22
25
  - **Sizes and spin**: Ceres (966.2 x 962.0 x 891.8 km) and its pole: Ermakov et al. 2017 (as listed in Wikipedia's Ceres article); its rotation: JPL SBDB (9.074170 h). Haumea: Ortiz et al. 2017, Nature 550:219 (semi-axes 1161 x 852 x 513 km), rotation 3.915341 h from Santos-Sanz et al. 2017, A&A 604:A95, pole from Kondratyev & Kornoukhov 2018, MNRAS 478:3159 (RA 282.6, Dec -13.0). Eris: radius 1163 km, Sicardy et al. 2011; it keeps one face to Dysnomia, so its rotation is Dysnomia's orbital period, Szakats et al. 2023, A&A 669:L3. Makemake: radius 715 km, Brown 2013; rotation 22.8266 h, Hromakina et al. 2019. Gonggong: radius 615 km and rotation 22.4 h, Kiss et al. 2019, Icarus. Quaoar: 1241.4 x 1093.0 x 1023.0 km and 17.6788 h, Margoti et al. 2026 and Pereira et al. 2023. Sedna: radius 453 km (Lellouch et al. 2013, TNOs are Cool IX, which allows far more) and 10.273 h, Gaudi et al. 2005. Orcus: radius 455 km, Brown & Butler 2018, rotation 13.188 h (JPL SBDB; 7 to 21 h in the literature). Wikipedia's articles on each body were the finding aid; the papers are the sources.
23
26
  - **Moons' orbits**: Dysnomia, Holler et al. 2021, Icarus 355:114130, Table 2 (arXiv 2009.13733). Hiʻiaka and Namaka, Ragozzine & Brown 2009, AJ 137:4766, Table 2 (osculating elements of 2008; the two moons pull on each other, so the position years later is rough). Vanth, Brown et al. 2010, AJ 139:2700, Table 2, solution 1 of two mirror solutions. Radii: Dysnomia 308 km (Brown & Butler 2023), Vanth 221 km (Sickafoose et al. 2018, occultation), Hiʻiaka and Namaka from the Haumea article's listed diameters (370 and 150 km). Weywot, Xiangliu and Makemake's moon S/2015 (136472) 1 are left out: no orbit with a published phase.
24
27
  - **Estimated, not measured** (the pictures say so only here): these bodies' poles are not measured, so each is drawn with its spin axis along its orbit's pole (Quaoar, Makemake, Gonggong, Sedna), along Dysnomia's orbit pole (Eris) or along the far end of Vanth's orbit pole, so that it spins forwards (Orcus). Hiʻiaka's and Namaka's spin is unknown and they are drawn still. Dysnomia and Vanth are assumed to keep one face to their planet. Every drawn feature on the line look of a dwarf planet except Ceres's Occator crater and Haumea's long axis is a generic crater, and so is each shaded (realistic) look: only the colour (from the published colour indices and albedos) and the sizes are from numbers. Ceres, Haumea and Dysnomia's shapes are from the sources above. Only Ceres has a painted look.
25
28
 
26
29
  The tests compare the Galilean moons and four planets with astronomy-engine (MIT, https://github.com/cosinekitty/astronomy), a development dependency that is never shipped.
27
30
 
31
+ ## The spacecraft
32
+
33
+ Voyager 1 and 2, New Horizons, Pioneer 10 and 11, Cassini, Galileo, Juno, Parker Solar Probe and the James Webb Space Telescope. Values read on 2026-11-08. NASA content is not subject to copyright in the United States; credit: NASA/JPL-Caltech. This package is not endorsed by NASA and uses none of its insignia.
34
+
35
+ - **Where they are**: JPL Horizons (https://ssd.jpl.nasa.gov/api/horizons.api, read 2026-11-08), VECTORS, heliocentric, ecliptic and equinox J2000, over the whole of each craft's own record (its start and stop are the ones Horizons gives), fitted as Chebyshev tables by `scripts/make-spacecraft-data.py` (`src/craft/<craft>.ts`). The positions the tests compare with are in `test/data/spacecraft-horizons.json`. Horizons' paths after today are predictions.
36
+ - **Facts and events**: NASA mission pages, read 2026-11-08: Voyager 1 (https://science.nasa.gov/mission/voyager/voyager-1/), Voyager 2 (https://science.nasa.gov/mission/voyager/voyager-2/), New Horizons (https://science.nasa.gov/mission/new-horizons/), Pioneer 10 (https://science.nasa.gov/mission/pioneer-10/), Pioneer 11 (https://science.nasa.gov/mission/pioneer-11/), Cassini (https://science.nasa.gov/mission/cassini/ and its timeline, https://science.nasa.gov/mission/cassini/the-journey/timeline/), Galileo (https://science.nasa.gov/mission/galileo/), Juno (https://science.nasa.gov/mission/juno/ and the NSSDCA record 2011-040A, https://nssdc.gsfc.nasa.gov/nmc/spacecraft/display.action?id=2011-040A), Parker Solar Probe (https://science.nasa.gov/mission/parker-solar-probe/ and the NSSDCA record 2018-065A, https://nssdc.gsfc.nasa.gov/nmc/spacecraft/display.action?id=2018-065A) and the James Webb Space Telescope (https://science.nasa.gov/mission/webb/ and https://science.nasa.gov/mission/webb/launch/). A time is given only where a page gives one. Where a page's date for a flyby disagrees with the closest approach of Horizons' path, the package keeps the date of the path (listed in the guide).
37
+ - **Japanese names** are the usual Japanese spellings of the missions' names.
38
+
28
39
  ## The Earth
29
40
 
30
41
  The Earth's line drawing is chikyu-earth's own globe (MIT, by John Morris; https://github.com/johnmorrisdotca/chikyu-earth), an optional peer dependency: its own NOTICE.md has the terms of its outlines. The Earth's realistic and painted looks are drawn here, like every other body, from NASA's Blue Marble picture (below).
package/README.md CHANGED
@@ -5,6 +5,8 @@
5
5
  <p align="center"><strong>The Sun, the planets and their moons, for the web.</strong><br>
6
6
  A clean line drawing, a shaded realistic drawing, or a painted surface map, with each body's real size, axial tilt and rotation as data, and a planet's moons where they are at any date and time.</p>
7
7
 
8
+ <p align="center">Part of <strong>SpaceProgramX (SPX)</strong>, the space packages: <a href="https://github.com/johnmorrisdotca/wakusei-planets">Wakusei Planets</a> · <a href="https://github.com/johnmorrisdotca/hoshi-stars">Hoshi Stars</a> · <a href="https://github.com/johnmorrisdotca/chikyu-earth">Chikyu Earth</a> · <a href="https://github.com/johnmorrisdotca/uchusen-rockets">Uchusen Rockets</a></p>
9
+
8
10
  <p align="center">
9
11
  <a href="https://github.com/johnmorrisdotca/wakusei-planets/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/johnmorrisdotca/wakusei-planets/actions/workflows/ci.yml/badge.svg"></a>
10
12
  <a href="./LICENSE"><img alt="MIT licence" src="https://img.shields.io/badge/licence-MIT-2f5d4a"></a>
@@ -13,9 +15,9 @@ A clean line drawing, a shaded realistic drawing, or a painted surface map, with
13
15
 
14
16
  <p align="center"><a href="https://johnmorrisdotca.github.io/wakusei-planets/"><strong>Open the demo →</strong></a> · <a href="https://johnmorrisdotca.github.io/wakusei-planets/embed.html">Embed page</a> · <a href="https://johnmorrisdotca.github.io/wakusei-planets/docs/">Docs</a></p>
15
17
 
16
- <p align="center"><img alt="Jupiter and Saturn drawn in the realistic look, and Saturn as a line drawing" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.19.0/docs/images/hero-desk.png" width="640"></p>
18
+ <p align="center"><img alt="Jupiter and Saturn drawn in the realistic look, and Saturn as a line drawing" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.21.0/docs/images/hero-desk.png" width="640"></p>
17
19
 
18
- <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.19.0/docs/images/lineup-desk.png" width="640"></p>
20
+ <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.21.0/docs/images/lineup-desk.png" width="640"></p>
19
21
 
20
22
  ## One minute
21
23
 
@@ -111,6 +113,10 @@ Import the element once in client code, and the entry point of each body you dra
111
113
 
112
114
  Every body has its real size relative to the others (`scale-to="jupiter"`), its axial tilt and its rotation. The Sun, Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune and Pluto are drawn, and so are the eight other dwarf planets (Ceres, Orcus, Haumea, Quaoar, Makemake, Gonggong, Eris and Sedna; Haumea and Quaoar as the long shapes they are, and Ceres with a painted map from Dawn) and 29 moons (the Moon, Phobos and Deimos, the four Galilean moons, Saturn's seven larger moons, Uranus's five, Proteus, Triton and Nereid, Charon, Nix and Hydra, and Vanth, Hiʻiaka, Namaka and Dysnomia, the moons of the dwarf planets whose orbits are published with a date). The Earth is drawn like the rest in the realistic and painted looks (NASA's Blue Marble), and its line look is [chikyu-earth](https://github.com/johnmorrisdotca/chikyu-earth)'s own globe: `import "@johnmorrisdotca/wakusei-planets/earth"` (it needs `@johnmorrisdotca/chikyu-earth` 0.10.0 or later installed). The painted looks cover the Sun, the planets from Mercury to Earth and Pluto, Ceres, the Moon, the four Galilean moons, Saturn's Mimas, Enceladus, Tethys, Dione, Rhea, Titan and Iapetus, Triton and Charon, and Saturn's rings are Cassini's own picture of them.
113
115
 
116
+ ## Two packages: this one and chikyu-earth
117
+
118
+ This package is the Sun, the planets, the dwarf planets and the moons, and where they are. [chikyu-earth](https://github.com/johnmorrisdotca/chikyu-earth) is the Earth in detail: its countries, day and night, places and satellites. Each works alone; install both and the Earth's line look becomes chikyu-earth's globe with the countries. The dependency runs one way: this package may use chikyu-earth, never the reverse. [Why two packages](docs/guides/two-packages.md) has the rule, a table of what lives where and how to use them together.
119
+
114
120
  ## As the Earth sees it
115
121
 
116
122
  Give a body a `time` and it is drawn as the sky shows it then: its pole and rotation, how far the rings are open (Saturn's rings are edge-on in March 2025), the phase of the Moon or Venus, the Sun's direction.
@@ -176,7 +182,7 @@ The pure side has no DOM: `BODIES`, `apparent(id, time)`, `system(planet, time)`
176
182
 
177
183
  ## The data
178
184
 
179
- Sizes, flattening, poles and rotation are the IAU's and NASA's; Mercury to Neptune are VSOP87B, cut down, and Pluto is JPL's approximate elements; the Moon's are Meeus's largest terms; the other moons are fitted to JPL Horizons' positions, and every body is tested against Horizons ([accuracy](docs/guides/accuracy.md)). Nothing is fetched at run time by the line and shaded looks, which use no pictures. See [NOTICE.md](NOTICE.md).
185
+ Sizes, flattening, poles and rotation are the IAU's and NASA's; Mercury to Neptune are VSOP87B, cut down, and Pluto is a table fitted to Horizons; the Moon's are the lunar solution ELP2000-82B cut down; the other moons are fitted to JPL Horizons' positions, and every body is tested against Horizons ([accuracy](docs/guides/accuracy.md)). Nothing is fetched at run time by the line and shaded looks, which use no pictures. See [NOTICE.md](NOTICE.md).
180
186
 
181
187
  ## Examples
182
188
 
@@ -273,7 +279,7 @@ A body that turns by itself and a moving sky, in HTML:
273
279
 
274
280
  ## The portrait builder
275
281
 
276
- <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.19.0/docs/images/portrait-family.png" width="640"></p>
282
+ <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.21.0/docs/images/portrait-family.png" width="640"></p>
277
283
 
278
284
  [The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
279
285
 
@@ -284,6 +290,23 @@ A body that turns by itself and a moving sky, in HTML:
284
290
  <wakusei-portrait scene="look:painted~jupiter_0_0_0.3_0~io_0_0_0.1_0"></wakusei-portrait>
285
291
  ```
286
292
 
293
+ ## The space view
294
+
295
+ [The space view](https://johnmorrisdotca.github.io/wakusei-planets/space.html) puts the Earth, the Moon, the Sun and the planets in their places for any date and time, in one WebGL context: the Moon's phase and the Earth's day side come out of the real Sun's light. Zoom from the Earth out to the whole solar system, in a compressed scale (every direction real, the distances squeezed) or the true one, and run time forwards or backwards. Positions come from this package's own models.
296
+
297
+ ```html
298
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets/space/element/+esm"></script>
299
+
300
+ <wakusei-space time="2026-11-02T14:00Z" speed="0"></wakusei-space>
301
+ ```
302
+
303
+ ```ts
304
+ import { frameAt } from "@johnmorrisdotca/wakusei-planets/space";
305
+
306
+ const frame = frameAt(Date.UTC(2026, 10, 2, 14));
307
+ console.log(Math.hypot(...frame.sun).toFixed(3), "au to the Sun");
308
+ ```
309
+
287
310
  ## API
288
311
 
289
312
  The reference is a site, made from the source's own doc comments: every export has a summary, its parameters, what it returns and an example that runs when the site is built. [Open the reference](https://johnmorrisdotca.github.io/wakusei-planets/docs/).
@@ -293,6 +316,8 @@ The reference is a site, made from the source's own doc comments: every export h
293
316
  | `@johnmorrisdotca/wakusei-planets` | The pure side: `BODIES`, `apparent`, `system`, `orbitPath`, `portrait`, `lineSvg`, `embedCode`. No browser. |
294
317
  | `.../element` | `<wakusei-body>`; three.js is loaded only for a shaded look. |
295
318
  | `.../portrait` | `<wakusei-portrait>`: many bodies in one scene. The scene model (`addBody`, `layoutPortrait`, `encodeScene`, `decodeScene`) is in the main entry. |
319
+ | `.../space` | Where the Sun, the Moon and the planets are for a date, in two scales, and where a camera riding along looks: `frameAt`, `createTrack`, `placeSun`, `placeAround`, `ridePose`. No browser. |
320
+ | `.../space/element` | `<wakusei-space>`: the Earth, the Moon, the Sun and the planets in their places. |
296
321
  | `.../look` | What a body needs to be drawn with three.js. |
297
322
  | `.../painter` | The bodies as objects for a scene of your own. |
298
323
  | `.../all` | Every body's shaded look, at once. |
@@ -318,9 +343,17 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
318
343
  | [Put it in your page](docs/guides/put-it-in-your-page.md) | Set up a body and copy the code |
319
344
  | [The portrait builder](docs/guides/portrait-builder.md) | Many bodies in one picture |
320
345
  | [Looks and bodies](docs/guides/looks-and-bodies.md) | The looks and each body's entry point |
346
+ | [Why two packages](docs/guides/two-packages.md) | This package and chikyu-earth: which to install, alone or together |
321
347
  | [Moons and time](docs/guides/moons-and-time.md) | The sky on a date, time that runs fast |
348
+ | [The space view](docs/guides/space-view.md) | The Earth, Moon, Sun and planets in their places; two scales; time both ways |
349
+ | [Riding along](docs/guides/ride-along.md) | The camera on a moon, a planet or any moving point, looking at what it goes round |
322
350
  | [Accuracy](docs/guides/accuracy.md) | How far each body is from JPL Horizons |
323
351
  | [In your own three.js scene](docs/guides/in-your-own-scene.md) | `painter.make` |
352
+ | [Time](docs/guides/time.md) | Julian dates, calendars, time scales, sidereal time, Mars time |
353
+ | [The stars you can see without a telescope](docs/guides/stars.md) | 5,080 stars with names, positions, proper motion, distance and colour |
354
+ | [Famous spacecraft](docs/guides/spacecraft.md) | Voyager, New Horizons, Pioneer, Cassini, Galileo, Juno, Parker and Webb: where they are and their whole voyage |
355
+ | [The Sun and Moon from a place](docs/guides/suncalc.md) | Position, sunrise and sunset, Moon rise, set and phase; a drop-in for suncalc |
356
+ | [Coordinate conversions](docs/guides/coordinates.md) | Pure spherical, ecliptic, equatorial and horizontal coordinate conversions |
324
357
  | [TypeScript and Node](docs/guides/typescript-and-node.md) | Types and the pure side |
325
358
  | [How it works](docs/guides/how-it-works.md) | Where the numbers come from |
326
359
  | [Architecture](docs/guides/architecture.md) | How the layers fit |
@@ -335,7 +368,7 @@ import { BODIES } from "@johnmorrisdotca/wakusei-planets";
335
368
  BODIES.pluto.kind; // "dwarf-planet"
336
369
  ```
337
370
 
338
- - A fact with no source is left out, never guessed. Moon positions are fitted to JPL Horizons and are within a degree or two on the orbit for almost every moon, about the size of the moon on screen; [accuracy](docs/guides/accuracy.md) has each body's number.
371
+ - A fact with no source is left out, never guessed. The Moon is within 2 arc-seconds of JPL Horizons, and the other moons' positions are fitted to it and are within a degree or two on the orbit for almost every moon, about the size of the moon on screen; [accuracy](docs/guides/accuracy.md) has each body's number.
339
372
  - `realistic` and `painted` are the photo maps (`painted` is the same maps, so an older page still works). `illustrated` is the shaded drawing from the numbers, and it is not a default. Venus, Saturn, Neptune and the Sun use Solar System Scope's maps (CC BY 4.0). Mercury uses the natural grey 8K map (Shady Tex and Solar System Scope, CC BY 4.0). Mars stays on the Viking mosaic, graded toward a butterscotch ochre, with the frost in Hellas toned to the basin and the polar ice left. Jupiter and Uranus use Nestaeric's maps (CC BY 4.0), and Saturn's poles use Nestaeric's caps (CC BY 4.0). The Earth and the Moon stay on their NASA maps until those have been compared. The rest are the public-domain maps in `NOTICE.md`.
340
373
  - A shaded look needs WebGL. Without it the line drawing is drawn.
341
374
  - Jupiter, Saturn, Uranus and Neptune have their rings drawn.
@@ -391,7 +424,7 @@ pnpm test:readme # every ts block of the README, type-checked and run against
391
424
  pnpm test:usage # every way of using it in the README and the guides, built and opened
392
425
  pnpm docs:check # the reference site's checks
393
426
  pnpm test:demo # the demo and the docs site in a real browser
394
- pnpm dev # the demo on http://127.0.0.1:8300/wakusei-planets/
427
+ pnpm dev # the demo on http://127.0.0.1:8225/wakusei-planets/
395
428
  ```
396
429
 
397
430
  The pictures in `docs/images` are made by the package's own script:
@@ -1,15 +1,23 @@
1
1
  import "./earth-look.js";
2
- import { delegates } from "../scene/store.js";
3
- // The Earth's line look is chikyu-earth's own globe with the countries, not a second copy (chikyu-earth is an optional peer, loaded only when that line globe is drawn). The realistic and
4
- // painted looks are drawn here like every other body's (earth-look.ts, which `/all` also loads).
2
+ import { delegates, waiting } from "../scene/store.js";
3
+ // The Earth's line look is chikyu-earth's own globe with the countries when the page has it (`import "@johnmorrisdotca/chikyu-earth/element"`), and this package's own outline when it does not.
4
+ // This entry never imports chikyu-earth itself, so a project without that optional peer still builds. The realistic and painted looks are drawn here like every other body's (earth-look.ts).
5
5
  const CENTRE = "10,20";
6
+ const TAG = "chikyu-earth";
6
7
  delegates.set("earth", {
7
8
  async line({ center, size }) {
8
- await import("@johnmorrisdotca/chikyu-earth/element");
9
- const globe = document.createElement("chikyu-earth");
9
+ if (customElements.get(TAG) === undefined)
10
+ return null;
11
+ const globe = document.createElement(TAG);
10
12
  globe.setAttribute("center", center || CENTRE);
11
13
  globe.setAttribute("look", "line");
12
14
  globe.setAttribute("size", String(size));
13
15
  return globe;
14
16
  },
15
17
  });
18
+ if (typeof customElements !== "undefined" && customElements.get(TAG) === undefined) {
19
+ void customElements.whenDefined(TAG).then(() => {
20
+ for (const wake of waiting)
21
+ wake();
22
+ });
23
+ }
@@ -0,0 +1,119 @@
1
+ import { type When } from "./when.ts";
2
+ /**
3
+ * Which calendar: `gregorian` and `julian` are used for every year (the proleptic calendars), and `auto` follows history: the Julian calendar to 1582-10-04 and the Gregorian from 1582-10-15.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { type Calendar } from "@johnmorrisdotca/wakusei-planets/time";
8
+ *
9
+ * const calendar: Calendar = "auto";
10
+ * console.log(calendar);
11
+ * ```
12
+ */
13
+ export type Calendar = "gregorian" | "julian" | "auto";
14
+ /**
15
+ * A date and time of day. The year is astronomical (1 BCE is 0, 2 BCE is -1), the month is 1 to 12, the day starts at 1.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { toCalendar, type CivilTime } from "@johnmorrisdotca/wakusei-planets/time";
20
+ *
21
+ * const t: CivilTime = toCalendar(Date.UTC(1957, 9, 4, 19, 26, 24));
22
+ * console.log(t.year, t.month, t.day, t.hour);
23
+ * ```
24
+ */
25
+ export interface CivilTime {
26
+ year: number;
27
+ month: number;
28
+ day: number;
29
+ hour: number;
30
+ minute: number;
31
+ second: number;
32
+ millisecond: number;
33
+ }
34
+ /**
35
+ * Whether a year is a leap year.
36
+ * @param year - The astronomical year.
37
+ * @param calendar - `gregorian` (a century is a leap year only if divisible by 400), `julian` (every fourth year), or `auto` (the Julian rule to 1582, the Gregorian after).
38
+ * @returns `true` for a leap year.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { isLeapYear } from "@johnmorrisdotca/wakusei-planets/time";
43
+ *
44
+ * console.log(isLeapYear(1900), isLeapYear(1900, "julian"), isLeapYear(2000));
45
+ * ```
46
+ */
47
+ export declare function isLeapYear(year: number, calendar?: Calendar): boolean;
48
+ /**
49
+ * The number of days in a month; October 1582 has 21 in the `auto` calendar, the ten days of the switch being left out.
50
+ * @param year - The astronomical year.
51
+ * @param month - 1 to 12.
52
+ * @param calendar - `gregorian`, `julian` or `auto`.
53
+ * @returns The days in the month.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { daysInMonth } from "@johnmorrisdotca/wakusei-planets/time";
58
+ *
59
+ * console.log(daysInMonth(2024, 2), daysInMonth(1582, 10));
60
+ * ```
61
+ */
62
+ export declare function daysInMonth(year: number, month: number, calendar?: Calendar): number;
63
+ /**
64
+ * A moment as a date and time of day in UTC, in the Gregorian or the Julian calendar.
65
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
66
+ * @param calendar - `auto` (default: the calendar in use that day), `gregorian` or `julian` for every year.
67
+ * @returns The year (astronomical), month, day, hour, minute, second and millisecond.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * import { toCalendar } from "@johnmorrisdotca/wakusei-planets/time";
72
+ *
73
+ * console.log(toCalendar(Date.UTC(1582, 9, 15)), toCalendar(Date.UTC(1582, 9, 15), "julian").day);
74
+ * ```
75
+ */
76
+ export declare function toCalendar(when: When, calendar?: Calendar): CivilTime;
77
+ /**
78
+ * A date and time of day in UTC as a moment, in milliseconds since 1970. A day that does not exist (31 April, 29 February in a common year, or 5 to 14 October 1582 in the `auto` calendar) throws a `RangeError`.
79
+ * @param civil - The year (astronomical), and the month (1), day (1), hour, minute, second and millisecond (0) when left out.
80
+ * @param calendar - `auto` (default), `gregorian` or `julian`.
81
+ * @returns Milliseconds since 1970.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import { fromCalendar } from "@johnmorrisdotca/wakusei-planets/time";
86
+ *
87
+ * console.log(fromCalendar({ year: 333, month: 1, day: 27, hour: 12 }, "julian"), new Date(fromCalendar({ year: 2000, month: 1, day: 1, hour: 12 })).toISOString());
88
+ * ```
89
+ */
90
+ export declare function fromCalendar(civil: {
91
+ year: number;
92
+ } & Partial<Omit<CivilTime, "year">>, calendar?: Calendar): number;
93
+ /**
94
+ * The day of the week of a moment in UTC: 0 Sunday to 6 Saturday.
95
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
96
+ * @returns 0 to 6.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { dayOfWeek } from "@johnmorrisdotca/wakusei-planets/time";
101
+ *
102
+ * console.log(dayOfWeek(Date.UTC(1954, 5, 30)));
103
+ * ```
104
+ */
105
+ export declare function dayOfWeek(when: When): number;
106
+ /**
107
+ * The day of the year of a moment in UTC: 1 on 1 January.
108
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
109
+ * @param calendar - `auto` (default), `gregorian` or `julian`.
110
+ * @returns 1 to 366.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * import { dayOfYear } from "@johnmorrisdotca/wakusei-planets/time";
115
+ *
116
+ * console.log(dayOfYear(Date.UTC(1978, 10, 14)), dayOfYear(Date.UTC(1988, 3, 22)));
117
+ * ```
118
+ */
119
+ export declare function dayOfYear(when: When, calendar?: Calendar): number;
@@ -0,0 +1,155 @@
1
+ // Calendars: the Gregorian and the Julian, the switch between them in October 1582, years before 1 CE (astronomical numbering, so the year 0 is 1 BCE), days of the week and of the year.
2
+ // Whole days are counted as integers, so a date goes to a moment and back without a digit lost and years from -271821 to 275760 (the range of a JavaScript `Date`) all work. Pure: no DOM, no three.js.
3
+ import { moment } from "./when.js";
4
+ const DAY_MS = 86_400_000;
5
+ /** The Julian day number (the day that begins at midnight) of 1970-01-01. */
6
+ const UNIX_DAY_NUMBER = 2_440_588;
7
+ /** The Julian day number of 1582-10-15, the first day of the Gregorian calendar. */
8
+ const REFORM_DAY_NUMBER = 2_299_161;
9
+ const floorMod = (a, b) => a - b * Math.floor(a / b);
10
+ function wholeNumber(name, value) {
11
+ if (!Number.isInteger(value))
12
+ throw new RangeError(`${name} must be a whole number, got ${value}`);
13
+ }
14
+ function dayNumberOf(year, month, day, gregorian) {
15
+ const a = Math.floor((14 - month) / 12);
16
+ const y = year + 4800 - a;
17
+ const m = month + 12 * a - 3;
18
+ const base = day + Math.floor((153 * m + 2) / 5) + 365 * y + Math.floor(y / 4);
19
+ return gregorian ? base - Math.floor(y / 100) + Math.floor(y / 400) - 32045 : base - 32083;
20
+ }
21
+ function dateOfDayNumber(J, gregorian) {
22
+ const f = gregorian ? J + 1401 + Math.floor((Math.floor((4 * J + 274277) / 146097) * 3) / 4) - 38 : J + 1401;
23
+ const e = 4 * f + 3;
24
+ const g = Math.floor(floorMod(e, 1461) / 4);
25
+ const h = 5 * g + 2;
26
+ const day = Math.floor(floorMod(h, 153) / 5) + 1;
27
+ const month = ((Math.floor(h / 153) + 2) % 12) + 1;
28
+ return { year: Math.floor(e / 1461) - 4716 + Math.floor((14 - month) / 12), month, day };
29
+ }
30
+ /**
31
+ * Whether a year is a leap year.
32
+ * @param year - The astronomical year.
33
+ * @param calendar - `gregorian` (a century is a leap year only if divisible by 400), `julian` (every fourth year), or `auto` (the Julian rule to 1582, the Gregorian after).
34
+ * @returns `true` for a leap year.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { isLeapYear } from "@johnmorrisdotca/wakusei-planets/time";
39
+ *
40
+ * console.log(isLeapYear(1900), isLeapYear(1900, "julian"), isLeapYear(2000));
41
+ * ```
42
+ */
43
+ export function isLeapYear(year, calendar = "auto") {
44
+ wholeNumber("year", year);
45
+ const gregorian = calendar === "gregorian" || (calendar === "auto" && year > 1582);
46
+ return floorMod(year, 4) === 0 && (!gregorian || floorMod(year, 100) !== 0 || floorMod(year, 400) === 0);
47
+ }
48
+ /**
49
+ * The number of days in a month; October 1582 has 21 in the `auto` calendar, the ten days of the switch being left out.
50
+ * @param year - The astronomical year.
51
+ * @param month - 1 to 12.
52
+ * @param calendar - `gregorian`, `julian` or `auto`.
53
+ * @returns The days in the month.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { daysInMonth } from "@johnmorrisdotca/wakusei-planets/time";
58
+ *
59
+ * console.log(daysInMonth(2024, 2), daysInMonth(1582, 10));
60
+ * ```
61
+ */
62
+ export function daysInMonth(year, month, calendar = "auto") {
63
+ if (!Number.isInteger(month) || month < 1 || month > 12)
64
+ throw new RangeError(`month must be a whole number from 1 to 12, got ${month}`);
65
+ if (calendar === "auto" && year === 1582 && month === 10)
66
+ return 21;
67
+ if (month === 2)
68
+ return isLeapYear(year, calendar) ? 29 : 28;
69
+ return [4, 6, 9, 11].includes(month) ? 30 : 31;
70
+ }
71
+ /**
72
+ * A moment as a date and time of day in UTC, in the Gregorian or the Julian calendar.
73
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
74
+ * @param calendar - `auto` (default: the calendar in use that day), `gregorian` or `julian` for every year.
75
+ * @returns The year (astronomical), month, day, hour, minute, second and millisecond.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import { toCalendar } from "@johnmorrisdotca/wakusei-planets/time";
80
+ *
81
+ * console.log(toCalendar(Date.UTC(1582, 9, 15)), toCalendar(Date.UTC(1582, 9, 15), "julian").day);
82
+ * ```
83
+ */
84
+ export function toCalendar(when, calendar = "auto") {
85
+ const ms = Math.floor(moment(when));
86
+ const dayNumber = Math.floor(ms / DAY_MS) + UNIX_DAY_NUMBER;
87
+ const inDay = floorMod(ms, DAY_MS);
88
+ const gregorian = calendar === "gregorian" || (calendar === "auto" && dayNumber >= REFORM_DAY_NUMBER);
89
+ const { year, month, day } = dateOfDayNumber(dayNumber, gregorian);
90
+ return { year, month, day, hour: Math.floor(inDay / 3_600_000), minute: Math.floor((inDay % 3_600_000) / 60_000), second: Math.floor((inDay % 60_000) / 1000), millisecond: inDay % 1000 };
91
+ }
92
+ /**
93
+ * A date and time of day in UTC as a moment, in milliseconds since 1970. A day that does not exist (31 April, 29 February in a common year, or 5 to 14 October 1582 in the `auto` calendar) throws a `RangeError`.
94
+ * @param civil - The year (astronomical), and the month (1), day (1), hour, minute, second and millisecond (0) when left out.
95
+ * @param calendar - `auto` (default), `gregorian` or `julian`.
96
+ * @returns Milliseconds since 1970.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { fromCalendar } from "@johnmorrisdotca/wakusei-planets/time";
101
+ *
102
+ * console.log(fromCalendar({ year: 333, month: 1, day: 27, hour: 12 }, "julian"), new Date(fromCalendar({ year: 2000, month: 1, day: 1, hour: 12 })).toISOString());
103
+ * ```
104
+ */
105
+ export function fromCalendar(civil, calendar = "auto") {
106
+ const { year, month = 1, day = 1, hour = 0, minute = 0, second = 0, millisecond = 0 } = civil;
107
+ for (const [name, value] of Object.entries({ year, month, day, hour, minute, second, millisecond }))
108
+ wholeNumber(name, value);
109
+ if (hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59 || millisecond < 0 || millisecond > 999)
110
+ throw new RangeError(`the time of day ${hour}:${minute}:${second}.${millisecond} does not exist`);
111
+ if (day < 1 || day > daysInMonth(year, month, calendar))
112
+ throw new RangeError(`${year}-${month}-${day} does not exist in the ${calendar} calendar`);
113
+ let gregorian = calendar === "gregorian";
114
+ if (calendar === "auto") {
115
+ if (year === 1582 && month === 10 && day > 4 && day < 15)
116
+ throw new RangeError(`${year}-${month}-${day} does not exist: the calendar skipped 5 to 14 October 1582`);
117
+ gregorian = year > 1582 || (year === 1582 && (month > 10 || (month === 10 && day >= 15)));
118
+ }
119
+ return (dayNumberOf(year, month, day, gregorian) - UNIX_DAY_NUMBER) * DAY_MS + hour * 3_600_000 + minute * 60_000 + second * 1000 + millisecond;
120
+ }
121
+ /**
122
+ * The day of the week of a moment in UTC: 0 Sunday to 6 Saturday.
123
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
124
+ * @returns 0 to 6.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * import { dayOfWeek } from "@johnmorrisdotca/wakusei-planets/time";
129
+ *
130
+ * console.log(dayOfWeek(Date.UTC(1954, 5, 30)));
131
+ * ```
132
+ */
133
+ export function dayOfWeek(when) {
134
+ return floorMod(Math.floor(moment(when) / DAY_MS) + 4, 7);
135
+ }
136
+ /**
137
+ * The day of the year of a moment in UTC: 1 on 1 January.
138
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
139
+ * @param calendar - `auto` (default), `gregorian` or `julian`.
140
+ * @returns 1 to 366.
141
+ *
142
+ * @example
143
+ * ```ts
144
+ * import { dayOfYear } from "@johnmorrisdotca/wakusei-planets/time";
145
+ *
146
+ * console.log(dayOfYear(Date.UTC(1978, 10, 14)), dayOfYear(Date.UTC(1988, 3, 22)));
147
+ * ```
148
+ */
149
+ export function dayOfYear(when, calendar = "auto") {
150
+ const ms = moment(when);
151
+ const { year } = toCalendar(ms, calendar);
152
+ const dayNumber = Math.floor(ms / DAY_MS) + UNIX_DAY_NUMBER;
153
+ const gregorian = calendar === "gregorian" || (calendar === "auto" && year > 1582);
154
+ return dayNumber - dayNumberOf(year, 1, 1, gregorian) + 1;
155
+ }