@johnmorrisdotca/chikyu-earth 0.32.0 → 0.33.1

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 (45) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/NOTICE.md +10 -1
  3. package/README.md +13 -2
  4. package/dist/catalogue/fleets.d.ts +70 -0
  5. package/dist/catalogue/fleets.js +66 -0
  6. package/dist/catalogue/index.d.ts +5 -0
  7. package/dist/catalogue/index.js +7 -0
  8. package/dist/catalogue/kinds.d.ts +143 -0
  9. package/dist/catalogue/kinds.js +121 -0
  10. package/dist/catalogue/omm.d.ts +44 -0
  11. package/dist/catalogue/omm.js +92 -0
  12. package/dist/catalogue/orbit.d.ts +95 -0
  13. package/dist/catalogue/orbit.js +91 -0
  14. package/dist/catalogue/pack.d.ts +193 -0
  15. package/dist/catalogue/pack.js +327 -0
  16. package/dist/data/meteor-iau.d.ts +79 -0
  17. package/dist/data/meteor-iau.js +77 -0
  18. package/dist/data/meteor-showers.js +24 -20
  19. package/dist/data-door.d.ts +2 -0
  20. package/dist/data-door.js +4 -2
  21. package/dist/door/index.d.ts +1 -0
  22. package/dist/door/index.js +1 -0
  23. package/dist/door/packed.d.ts +64 -0
  24. package/dist/door/packed.js +91 -0
  25. package/dist/meteors/index.d.ts +2 -0
  26. package/dist/meteors/index.js +2 -0
  27. package/dist/meteors/parents.d.ts +45 -0
  28. package/dist/meteors/parents.js +67 -0
  29. package/dist/realistic/body-label.d.ts +13 -0
  30. package/dist/realistic/body-label.js +16 -0
  31. package/dist/realistic/earth.d.ts +3 -0
  32. package/dist/realistic/earth.js +21 -0
  33. package/dist/realistic/element.d.ts +18 -0
  34. package/dist/realistic/element.js +36 -4
  35. package/dist/realistic/index.d.ts +1 -1
  36. package/dist/realistic/index.js +1 -1
  37. package/dist/satellites/source.d.ts +4 -0
  38. package/dist/satellites/source.js +2 -2
  39. package/dist/sky/host.d.ts +55 -0
  40. package/dist/sky/host.js +382 -0
  41. package/dist/space/element.d.ts +18 -0
  42. package/dist/space/element.js +36 -4
  43. package/dist/space/scene.d.ts +3 -0
  44. package/dist/space/scene.js +26 -0
  45. package/package.json +11 -1
@@ -0,0 +1,64 @@
1
+ import { type PackedCatalogue } from "../catalogue/pack.ts";
2
+ import type { ElementRecordSource } from "./elements.ts";
3
+ import type { SourceInfo } from "../data-door.ts";
4
+ /**
5
+ * What `packedElementsFrom` can be told. Every one has a safe default.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import type { PackedElementsOptions } from "@johnmorrisdotca/chikyu-earth/door";
10
+ *
11
+ * const options: PackedElementsOptions = { maxBytes: 30_000_000 };
12
+ * console.log(options.maxBytes);
13
+ * ```
14
+ */
15
+ export interface PackedElementsOptions {
16
+ /** The most bytes of answer read (64 MB by default, the most a packed file may unpack to). */
17
+ maxBytes?: number;
18
+ /** The fetch function (the browser's by default). */
19
+ fetch?: typeof fetch;
20
+ }
21
+ /**
22
+ * A source of element sets read from a packed catalogue file (`packCatalogue`, gzipped or not) at an address you choose: up to 200,000 objects, six-digit catalogue numbers included. The file is asked for once, when the source is added,
23
+ * and nowhere else: no cookies and no referrer are sent, only `https` (or `http` on `localhost`) is used, a redirect or any answer but 200 is a failed read, and an answer over `maxBytes` is refused. Nothing is kept between page loads and
24
+ * nothing is asked on a timer. The package has no address of its own; a site that hosts these files says whose data they are in `info`.
25
+ *
26
+ * @param url - The address of a packed file.
27
+ * @param info - Who the data is: its id, credit, licence and page.
28
+ * @param options - See `PackedElementsOptions`.
29
+ * @returns The source, for `addSource` or `sources`.
30
+ *
31
+ * @example
32
+ * ```ts no-run
33
+ * import { packedElementsFrom } from "@johnmorrisdotca/chikyu-earth/door";
34
+ *
35
+ * const debris = packedElementsFrom("https://example.org/catalogue/debris.pack.gz", {
36
+ * id: "catalogue-debris",
37
+ * name: { en: "Debris in Earth orbit", ja: "地球周回軌道のデブリ" },
38
+ * credit: { en: "Data from Space-Track.org (USSPACECOM)", ja: "データ:Space-Track.org(USSPACECOM)" },
39
+ * licence: { name: "Space-Track basic SSA data, with citation", url: "https://www.space-track.org/documentation" },
40
+ * url: "https://www.space-track.org",
41
+ * retrieved: "2026-11-11",
42
+ * });
43
+ * console.log(debris.info.id);
44
+ * ```
45
+ */
46
+ export declare function packedElementsFrom(url: string, info: SourceInfo, options?: PackedElementsOptions): ElementRecordSource;
47
+ /**
48
+ * Ask an address for a packed catalogue file once and read it. This is what `packedElementsFrom` does; use it when a page wants the whole record (kind, owner, launch) and not just the element sets.
49
+ *
50
+ * @param url - The address of a packed file.
51
+ * @param options - See `PackedElementsOptions`, and a signal that stops the read.
52
+ * @returns The file, by column.
53
+ *
54
+ * @example
55
+ * ```ts no-run
56
+ * import { readPackedFrom } from "@johnmorrisdotca/chikyu-earth/door";
57
+ *
58
+ * const file = await readPackedFrom("https://example.org/catalogue/rocket-bodies.pack.gz");
59
+ * console.log(file.count, file.meta["retrieved"], file.kindAt(0));
60
+ * ```
61
+ */
62
+ export declare function readPackedFrom(url: string, options?: PackedElementsOptions & {
63
+ signal?: AbortSignal;
64
+ }): Promise<PackedCatalogue>;
@@ -0,0 +1,91 @@
1
+ // A record source for a packed catalogue file (`../catalogue/pack.ts`): up to 200,000 objects read once from an address of the page author's choosing. Pure: no DOM, no three.js, no satellite.js.
2
+ import { ElementSourceError } from "../satellites/source.js";
3
+ import { MAX_PACKED_BYTES, PackError, unpackAny } from "../catalogue/pack.js";
4
+ /**
5
+ * A source of element sets read from a packed catalogue file (`packCatalogue`, gzipped or not) at an address you choose: up to 200,000 objects, six-digit catalogue numbers included. The file is asked for once, when the source is added,
6
+ * and nowhere else: no cookies and no referrer are sent, only `https` (or `http` on `localhost`) is used, a redirect or any answer but 200 is a failed read, and an answer over `maxBytes` is refused. Nothing is kept between page loads and
7
+ * nothing is asked on a timer. The package has no address of its own; a site that hosts these files says whose data they are in `info`.
8
+ *
9
+ * @param url - The address of a packed file.
10
+ * @param info - Who the data is: its id, credit, licence and page.
11
+ * @param options - See `PackedElementsOptions`.
12
+ * @returns The source, for `addSource` or `sources`.
13
+ *
14
+ * @example
15
+ * ```ts no-run
16
+ * import { packedElementsFrom } from "@johnmorrisdotca/chikyu-earth/door";
17
+ *
18
+ * const debris = packedElementsFrom("https://example.org/catalogue/debris.pack.gz", {
19
+ * id: "catalogue-debris",
20
+ * name: { en: "Debris in Earth orbit", ja: "地球周回軌道のデブリ" },
21
+ * credit: { en: "Data from Space-Track.org (USSPACECOM)", ja: "データ:Space-Track.org(USSPACECOM)" },
22
+ * licence: { name: "Space-Track basic SSA data, with citation", url: "https://www.space-track.org/documentation" },
23
+ * url: "https://www.space-track.org",
24
+ * retrieved: "2026-11-11",
25
+ * });
26
+ * console.log(debris.info.id);
27
+ * ```
28
+ */
29
+ export function packedElementsFrom(url, info, options = {}) {
30
+ return {
31
+ kind: "records",
32
+ info,
33
+ async records(signal) {
34
+ return (await readPackedFrom(url, { ...options, signal })).sets();
35
+ },
36
+ };
37
+ }
38
+ /**
39
+ * Ask an address for a packed catalogue file once and read it. This is what `packedElementsFrom` does; use it when a page wants the whole record (kind, owner, launch) and not just the element sets.
40
+ *
41
+ * @param url - The address of a packed file.
42
+ * @param options - See `PackedElementsOptions`, and a signal that stops the read.
43
+ * @returns The file, by column.
44
+ *
45
+ * @example
46
+ * ```ts no-run
47
+ * import { readPackedFrom } from "@johnmorrisdotca/chikyu-earth/door";
48
+ *
49
+ * const file = await readPackedFrom("https://example.org/catalogue/rocket-bodies.pack.gz");
50
+ * console.log(file.count, file.meta["retrieved"], file.kindAt(0));
51
+ * ```
52
+ */
53
+ export async function readPackedFrom(url, options = {}) {
54
+ let address;
55
+ try {
56
+ address = new URL(url);
57
+ }
58
+ catch {
59
+ throw new ElementSourceError("that is not an address");
60
+ }
61
+ const local = address.hostname === "localhost" || address.hostname === "127.0.0.1" || address.hostname === "[::1]";
62
+ if (address.protocol !== "https:" && !(address.protocol === "http:" && local))
63
+ throw new ElementSourceError("only https addresses are used (http only on localhost)");
64
+ const maxBytes = options.maxBytes ?? MAX_PACKED_BYTES;
65
+ const ask = options.fetch ?? globalThis.fetch;
66
+ let response;
67
+ try {
68
+ response = await ask(address.href, { method: "GET", credentials: "omit", referrerPolicy: "no-referrer", redirect: "error", signal: options.signal ?? null });
69
+ }
70
+ catch (error) {
71
+ if (options.signal?.aborted)
72
+ throw error;
73
+ throw new ElementSourceError(`the source could not be reached: ${error instanceof Error ? error.message : "no answer"}`);
74
+ }
75
+ if (response.status !== 200)
76
+ throw new ElementSourceError(`the source answered ${response.status}`, { status: response.status });
77
+ const length = Number(response.headers.get("content-length"));
78
+ if (Number.isFinite(length) && length > maxBytes)
79
+ throw new ElementSourceError("the answer is bigger than the limit");
80
+ const bytes = new Uint8Array(await response.arrayBuffer());
81
+ if (bytes.length > maxBytes)
82
+ throw new ElementSourceError("the answer is bigger than the limit");
83
+ try {
84
+ return await unpackAny(bytes);
85
+ }
86
+ catch (error) {
87
+ if (error instanceof PackError)
88
+ throw new ElementSourceError(`the file could not be read: ${error.message}`);
89
+ throw error;
90
+ }
91
+ }
@@ -2,3 +2,5 @@ export { METEOR_SHOWERS, type MeteorShower } from "../data/meteor-showers.ts";
2
2
  export { METEOR_HEIGHT_KM, SPORADIC_HOURLY_RATE, activeShowers, apexPoint, darkness, hourlyRateAt, meteorSky, placeVector, pointBeneath, showerRate, solarLongitude, type MeteorSky } from "./rate.ts";
3
3
  export { METEORS_PER_SECOND_MAX, METEOR_SLOTS, streakPath, streaksPerSecond } from "./layer.ts";
4
4
  export { METEOR_STRENGTH_DEFAULT, readMeteorStrength } from "./strength.ts";
5
+ export { IAU_MDC, METEOR_LINKS, type ParentBody, type ShowerLink } from "../data/meteor-iau.ts";
6
+ export { parentBodyOf, showerSource, showersOfParent } from "./parents.ts";
@@ -5,3 +5,5 @@ export { METEOR_SHOWERS } from "../data/meteor-showers.js";
5
5
  export { METEOR_HEIGHT_KM, SPORADIC_HOURLY_RATE, activeShowers, apexPoint, darkness, hourlyRateAt, meteorSky, placeVector, pointBeneath, showerRate, solarLongitude } from "./rate.js";
6
6
  export { METEORS_PER_SECOND_MAX, METEOR_SLOTS, streakPath, streaksPerSecond } from "./layer.js";
7
7
  export { METEOR_STRENGTH_DEFAULT, readMeteorStrength } from "./strength.js";
8
+ export { IAU_MDC, METEOR_LINKS } from "../data/meteor-iau.js";
9
+ export { parentBodyOf, showerSource, showersOfParent } from "./parents.js";
@@ -0,0 +1,45 @@
1
+ import { type ParentBody, type ShowerLink } from "../data/meteor-iau.ts";
2
+ import { type MeteorShower } from "../data/meteor-showers.ts";
3
+ /**
4
+ * The parent body of a shower, found by the shower's IAU code, as the IAU Meteor Data Center's origin column names it.
5
+ *
6
+ * @param code - The IAU's three-letter code (`PER`).
7
+ * @returns The comet or asteroid, or `null` when the shower has none named (or the code is not in the table).
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { parentBodyOf } from "@johnmorrisdotca/chikyu-earth/meteors";
12
+ *
13
+ * console.log(parentBodyOf("PER")?.designation, parentBodyOf("GEM")?.kind, parentBodyOf("COM"));
14
+ * ```
15
+ */
16
+ export declare function parentBodyOf(code: string): ParentBody | null;
17
+ /**
18
+ * The showers that come from one parent body, found by its designation (the whole designation, or just its number or name: `2P` and `Encke` both find `2P/Encke`).
19
+ *
20
+ * @param designation - A designation: `1P/Halley`, `1P`, `Halley`, `(3200) Phaethon`.
21
+ * @returns The showers, in the table's order (empty when none comes from it).
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { showersOfParent } from "@johnmorrisdotca/chikyu-earth/meteors";
26
+ *
27
+ * console.log(showersOfParent("1P/Halley").map((shower) => shower.code), showersOfParent("2P").map((shower) => shower.name));
28
+ * ```
29
+ */
30
+ export declare function showersOfParent(designation: string): MeteorShower[];
31
+ /**
32
+ * Where a row's figures come from, in a sentence: the International Meteor Organization's table for the dates, the radiant, the speed and the rate, the IAU Meteor Data Center for the name, the parent body and the check, and
33
+ * which of the radiant and speed were replaced by the IAU's.
34
+ *
35
+ * @param link - A shower's link (`METEOR_LINKS`).
36
+ * @returns The sentence, in English.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * import { METEOR_LINKS, showerSource } from "@johnmorrisdotca/chikyu-earth/meteors";
41
+ *
42
+ * console.log(showerSource(METEOR_LINKS.find((link) => link.code === "LYR")!));
43
+ * ```
44
+ */
45
+ export declare function showerSource(link: ShowerLink): string;
@@ -0,0 +1,67 @@
1
+ // The showers' parent bodies by IAU code and designation, and where each row's figures come from. Pure: no DOM, no dependency.
2
+ import { METEOR_LINKS } from "../data/meteor-iau.js";
3
+ import { METEOR_SHOWERS } from "../data/meteor-showers.js";
4
+ /**
5
+ * The parent body of a shower, found by the shower's IAU code, as the IAU Meteor Data Center's origin column names it.
6
+ *
7
+ * @param code - The IAU's three-letter code (`PER`).
8
+ * @returns The comet or asteroid, or `null` when the shower has none named (or the code is not in the table).
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { parentBodyOf } from "@johnmorrisdotca/chikyu-earth/meteors";
13
+ *
14
+ * console.log(parentBodyOf("PER")?.designation, parentBodyOf("GEM")?.kind, parentBodyOf("COM"));
15
+ * ```
16
+ */
17
+ export function parentBodyOf(code) {
18
+ return METEOR_LINKS.find((link) => link.code === code)?.parent ?? null;
19
+ }
20
+ /**
21
+ * The showers that come from one parent body, found by its designation (the whole designation, or just its number or name: `2P` and `Encke` both find `2P/Encke`).
22
+ *
23
+ * @param designation - A designation: `1P/Halley`, `1P`, `Halley`, `(3200) Phaethon`.
24
+ * @returns The showers, in the table's order (empty when none comes from it).
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { showersOfParent } from "@johnmorrisdotca/chikyu-earth/meteors";
29
+ *
30
+ * console.log(showersOfParent("1P/Halley").map((shower) => shower.code), showersOfParent("2P").map((shower) => shower.name));
31
+ * ```
32
+ */
33
+ export function showersOfParent(designation) {
34
+ const wanted = designation.trim().toLowerCase();
35
+ if (wanted === "")
36
+ return [];
37
+ const matches = (full) => {
38
+ const whole = full.toLowerCase();
39
+ return whole === wanted || whole.split("/")[0] === wanted || whole.split("/")[1]?.split(" ")[0] === wanted || whole.replace(/^\(\d+\) /, "") === wanted || whole.endsWith(` ${wanted}`);
40
+ };
41
+ const codes = new Set(METEOR_LINKS.filter((link) => link.parent && matches(link.parent.designation)).map((link) => link.code));
42
+ return METEOR_SHOWERS.filter((shower) => codes.has(shower.code));
43
+ }
44
+ /**
45
+ * Where a row's figures come from, in a sentence: the International Meteor Organization's table for the dates, the radiant, the speed and the rate, the IAU Meteor Data Center for the name, the parent body and the check, and
46
+ * which of the radiant and speed were replaced by the IAU's.
47
+ *
48
+ * @param link - A shower's link (`METEOR_LINKS`).
49
+ * @returns The sentence, in English.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { METEOR_LINKS, showerSource } from "@johnmorrisdotca/chikyu-earth/meteors";
54
+ *
55
+ * console.log(showerSource(METEOR_LINKS.find((link) => link.code === "LYR")!));
56
+ * ```
57
+ */
58
+ export function showerSource(link) {
59
+ const parts = ["dates and rate: IMO 2026 Meteor Shower Calendar, Table 5 (the IAU MDC lists no maximum date and no rate)"];
60
+ const replaced = ["radiant", "speed"].filter((field) => link.from[field] === "mdc");
61
+ if (link.checked)
62
+ parts.push(`${replaced.length ? `${replaced.join(" and ")} from` : "radiant and speed agree with"} IAU MDC solution ${link.checked.adNo} of ${link.iauName} (IAU ${link.iau}, ${link.checked.meteors} meteors)${replaced.length ? "; the IMO table's was further off" : ""}`);
63
+ else
64
+ parts.push(`radiant and speed: IMO table, kept (${link.status === "working" ? "on the IAU MDC's working list only" : "no IAU MDC solution of 100 meteors or more near the maximum"})`);
65
+ parts.push(link.parent ? `parent body: ${link.parent.kind} ${link.parent.designation}, IAU MDC origin column` : "parent body: none named by the IAU MDC");
66
+ return parts.join("; ");
67
+ }
@@ -83,6 +83,19 @@ export interface BodyLabelLayer {
83
83
  sync(camera: THREE.Camera, radiusPx: number): void;
84
84
  dispose(): void;
85
85
  }
86
+ /**
87
+ * Loads Michroma, the family's font for a name written on a body or a sky, from where `setBodyLabelFontUrl` says (beside kazoku-ui's label by default). Once: asking again does nothing.
88
+ *
89
+ * @returns A promise that settles when the font is in.
90
+ *
91
+ * @example
92
+ * ```ts no-run
93
+ * import { loadMichroma } from "@johnmorrisdotca/chikyu-earth/realistic";
94
+ *
95
+ * await loadMichroma();
96
+ * ```
97
+ */
98
+ export declare function loadMichroma(): Promise<void>;
86
99
  /**
87
100
  * Where Michroma, the family's font for the name, is fetched from. Left alone it is the file beside the label's own module (`fonts/Michroma-Regular.ttf` in kazoku-ui's `body-label`), which is right where the package is used as it is shipped, or through a
88
101
  * bundler that keeps assets beside the code (Vite does); a bundler or a site that moves the module copies the file and says where with this. A page that names its own font (`body-label-font`) never fetches it.
@@ -62,6 +62,22 @@ export function readBodyLabel(get) {
62
62
  */
63
63
  export const bodyLabelText = (language) => (language === "ja" ? "地球" : "EARTH");
64
64
  let fontUrl;
65
+ /**
66
+ * Loads Michroma, the family's font for a name written on a body or a sky, from where `setBodyLabelFontUrl` says (beside kazoku-ui's label by default). Once: asking again does nothing.
67
+ *
68
+ * @returns A promise that settles when the font is in.
69
+ *
70
+ * @example
71
+ * ```ts no-run
72
+ * import { loadMichroma } from "@johnmorrisdotca/chikyu-earth/realistic";
73
+ *
74
+ * await loadMichroma();
75
+ * ```
76
+ */
77
+ export async function loadMichroma() {
78
+ const module = await import("@johnmorrisdotca/kazoku-ui/body-label");
79
+ await module.loadBodyLabelFont(fontUrl);
80
+ }
65
81
  /**
66
82
  * Where Michroma, the family's font for the name, is fetched from. Left alone it is the file beside the label's own module (`fonts/Michroma-Regular.ttf` in kazoku-ui's `body-label`), which is right where the package is used as it is shipped, or through a
67
83
  * bundler that keeps assets beside the code (Vite does); a bundler or a site that moves the module copies the file and says where with this. A page that names its own font (`body-label-font`) never fetches it.
@@ -7,6 +7,7 @@ import { type SatelliteState } from "../space/satellite-layer.ts";
7
7
  import type { Layer } from "./tiers.ts";
8
8
  import { type ThreeParts } from "./textures.ts";
9
9
  import { type TileSet, type TileSources } from "./tile-set.ts";
10
+ import type { SkyFrame } from "../sky/host.ts";
10
11
  import { type BodyLabelState } from "./body-label.ts";
11
12
  import { type MeteorState } from "../meteors/layer.ts";
12
13
  export type { ThreeParts };
@@ -106,6 +107,8 @@ export interface EarthDeps {
106
107
  air?: () => "full" | "light";
107
108
  /** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
108
109
  onSatellitesError?: (error: unknown) => void;
110
+ /** Where the sky falls on the screen at this draw, for the names of the stars and the constellation lines laid over it: the directions seen along the picture's own axes. */
111
+ onSky?: (frame: SkyFrame) => void;
109
112
  /** The name written on the Earth could not be made (the three.js handed over lacks a part, or the label could not be loaded). */
110
113
  onLabelError?: (error: unknown) => void;
111
114
  /** Told after the tiles were put right for a draw: what the draw shows from each source is known now. */
@@ -234,6 +234,27 @@ export function createEarthItem(model, deps) {
234
234
  if (model.bodyLabel.settings && !nameOn)
235
235
  nameOn = createBodyLabelLayer(three, turned, model.bodyLabel, { invalidate: deps.invalidate, ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
236
236
  nameOn?.sync(camera, radius);
237
+ if (deps.onSky) {
238
+ // the sky as the picture's own axes see it: a direction in space, turned as the satellites are into the picture's axes, falls where its sideways and upward parts say, in front when it points towards the viewer
239
+ spun.updateWorldMatrix(true, false);
240
+ const sky = new three.Vector3();
241
+ const scale = Math.min(size.width, size.height) / 2;
242
+ const cx = size.width / 2 + view.panX;
243
+ const cy = size.height / 2 + view.panY;
244
+ deps.onSky({
245
+ width: size.width,
246
+ height: size.height,
247
+ discs: [{ x: cx, y: cy, radius }],
248
+ project(rightAscension, declination, out) {
249
+ const r = rightAscension * RAD;
250
+ const d = declination * RAD;
251
+ sky.set(Math.cos(d) * Math.cos(r), Math.sin(d), -Math.cos(d) * Math.sin(r)).transformDirection(spun.matrixWorld);
252
+ out.x = cx + scale * sky.x;
253
+ out.y = cy - scale * sky.y;
254
+ return sky.z > 0;
255
+ },
256
+ });
257
+ }
237
258
  deps.onPose?.({ lon: look.lon, lat: look.lat, radius, cx: size.width / 2 + view.panX, cy: size.height / 2 + view.panY, width: size.width, height: size.height });
238
259
  if (model.meteors.on && !meteors)
239
260
  meteors = createMeteorLayer(three, turned, model.meteors);
@@ -5,6 +5,7 @@ import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/type
5
5
  import { type SatelliteStyle } from "../space/satellite-layer.ts";
6
6
  import type { Credit, DataSource } from "../data-door.ts";
7
7
  import { type BodyLabelSettings } from "./body-label.ts";
8
+ import type { LabelStyle } from "@johnmorrisdotca/hoshi-stars/sky-labels";
8
9
  import { setSharedRenderer, setThreeLoader } from "./shared.ts";
9
10
  export { setSharedRenderer, setThreeLoader };
10
11
  export type { CameraMode };
@@ -133,6 +134,13 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
133
134
  */
134
135
  get bodyLabel(): BodyLabelSettings | null;
135
136
  set bodyLabel(value: Partial<BodyLabelSettings> | null);
137
+ /**
138
+ * The names of the brightest stars and the constellations as faint lines, laid over the sky the page draws (hoshi-stars' `sky-labels`, an optional peer loaded only when one of these is set). The plain attributes are hoshi's: `star-names` (a count of the brightest stars in view and not covered by the
139
+ * Earth, the Moon or the Sun; bare is 10), `star-names-magnitude` (only stars at least that bright) and `constellation-lines` (the 88 figures as lines at this strength, 0 to 1; bare is 0.16): none of them, and nothing is loaded. The figure under the pointer or touched is at full strength and shows its name. Names are in the
140
+ * page's language and never overlap. Nothing is redrawn at rest. `chikyu-sky-unavailable` is sent when hoshi-stars is not there. The property is the look of the names, a partial hoshi-stars `LabelStyle` (font, size, case, ring, leader and the rest).
141
+ */
142
+ get skyStyle(): Partial<LabelStyle>;
143
+ set skyStyle(value: Partial<LabelStyle>);
136
144
  /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
137
145
  get controller(): ViewController | undefined;
138
146
  /**
@@ -220,6 +228,16 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
220
228
  made: boolean;
221
229
  showing: boolean;
222
230
  };
231
+ /** The names of the stars and the constellation lines: whether one is asked for, whether hoshi-stars is loaded, the names and figures laid out at the last draw, the figure picked, how many times the layer was drawn and the language its names were last laid out in. */
232
+ sky: {
233
+ on: boolean;
234
+ loaded: boolean;
235
+ names: number;
236
+ figures: number;
237
+ picked: string | null;
238
+ renders: number;
239
+ lang: string;
240
+ };
223
241
  };
224
242
  /**
225
243
  * Apply a shared view controller's camera (yaw, tilt, zoom, pan). A change under half a pixel is not drawn, a settled change always is,
@@ -13,12 +13,13 @@ import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/
13
13
  import { createDoorHost } from "../door/host.js";
14
14
  import { folderSource } from "../door/map.js";
15
15
  import { ownCredit } from "../door/own.js";
16
- import { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel } from "./body-label.js";
16
+ import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "./body-label.js";
17
+ import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
17
18
  import { createGate, frameCap } from "./gate.js";
18
19
  import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
19
20
  export { setSharedRenderer, setThreeLoader };
20
21
  import { MAX_TEXTURE, TIERS } from "./tiers.js";
21
- const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + METEOR_NOTE_STYLE + NOTES_STYLE;
22
+ const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + SKY_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
22
23
  const RAD = Math.PI / 180;
23
24
  /** The Sun and the clouds are re-placed this often at real time: 15 degrees an hour is 0.25 degree a minute. */
24
25
  const LIVE_TICK_MS = 60_000;
@@ -129,7 +130,7 @@ export const readTime = (value) => {
129
130
  * ```
130
131
  */
131
132
  export class ChikyuEarthRealistic extends HTMLElement {
132
- static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, "air-thickness", "air-label", "lang"];
133
+ static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, "air-thickness", "air-label", "lang"];
133
134
  #model = newModel();
134
135
  #mode = "now";
135
136
  #view;
@@ -159,6 +160,9 @@ export class ChikyuEarthRealistic extends HTMLElement {
159
160
  /** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
160
161
  #played = false;
161
162
  #note;
163
+ /** The names of the stars and the constellation lines (`star-names`, `constellation-lines`), and the look of the names. */
164
+ #sky;
165
+ #skyStyle = {};
162
166
  #airNote;
163
167
  #onContext = (state) => {
164
168
  if (state === "unavailable")
@@ -193,6 +197,14 @@ export class ChikyuEarthRealistic extends HTMLElement {
193
197
  this.#overlay = root.getElementById("overlay");
194
198
  this.#note = root.getElementById("meteor-note");
195
199
  this.#airNote = root.getElementById("air-note");
200
+ this.#sky = createSkyHost({
201
+ root,
202
+ attribute: (name) => this.getAttribute(name),
203
+ language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
204
+ onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-sky-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
205
+ loadFont: loadMichroma,
206
+ });
207
+ this.#sky.setStyle(this.#skyStyle);
196
208
  this.#played = false;
197
209
  this.#model.meteors.on = this.#meteorsAsked();
198
210
  this.#model.meteors.strength = readMeteorStrength(this.getAttribute("meteors-strength"));
@@ -232,6 +244,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
232
244
  invalidate: () => this.#gate?.soon(),
233
245
  onDraw: () => this.#gate?.drawn(),
234
246
  onTiled: () => this.#door.announce(),
247
+ onSky: (sky) => this.#sky?.frame(sky),
235
248
  onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
236
249
  onPose: (pose) => {
237
250
  if (this.#hands)
@@ -288,6 +301,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
288
301
  this.#view = undefined;
289
302
  this.#taken?.release();
290
303
  this.#taken = undefined;
304
+ this.#sky?.dispose();
305
+ this.#sky = undefined;
291
306
  }
292
307
  attributeChangedCallback(name, _old, value) {
293
308
  if (name === "center")
@@ -326,11 +341,15 @@ export class ChikyuEarthRealistic extends HTMLElement {
326
341
  }
327
342
  else if (name === "meteors-label" || name === "lang") {
328
343
  this.#meteorNote();
329
- if (name === "lang")
344
+ if (name === "lang") {
330
345
  this.#applyBodyLabel();
346
+ this.#sky?.refresh();
347
+ }
331
348
  }
332
349
  else if (BODY_LABEL_ATTRIBUTES.includes(name))
333
350
  this.#applyBodyLabel();
351
+ else if (SKY_ATTRIBUTES.includes(name))
352
+ this.#sky?.refresh();
334
353
  if (name === "air-thickness" || name === "air-label" || name === "lang")
335
354
  setAirNote(this.#airNote, this, this.#model.airThickness);
336
355
  }
@@ -409,6 +428,18 @@ export class ChikyuEarthRealistic extends HTMLElement {
409
428
  if (value.fallbackFont)
410
429
  this.setAttribute("body-label-fallback-font", value.fallbackFont);
411
430
  }
431
+ /**
432
+ * The names of the brightest stars and the constellations as faint lines, laid over the sky the page draws (hoshi-stars' `sky-labels`, an optional peer loaded only when one of these is set). The plain attributes are hoshi's: `star-names` (a count of the brightest stars in view and not covered by the
433
+ * Earth, the Moon or the Sun; bare is 10), `star-names-magnitude` (only stars at least that bright) and `constellation-lines` (the 88 figures as lines at this strength, 0 to 1; bare is 0.16): none of them, and nothing is loaded. The figure under the pointer or touched is at full strength and shows its name. Names are in the
434
+ * page's language and never overlap. Nothing is redrawn at rest. `chikyu-sky-unavailable` is sent when hoshi-stars is not there. The property is the look of the names, a partial hoshi-stars `LabelStyle` (font, size, case, ring, leader and the rest).
435
+ */
436
+ get skyStyle() {
437
+ return { ...this.#skyStyle };
438
+ }
439
+ set skyStyle(value) {
440
+ this.#skyStyle = { ...value };
441
+ this.#sky?.setStyle(this.#skyStyle);
442
+ }
412
443
  /** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
413
444
  #applyBodyLabel() {
414
445
  this.#model.bodyLabel.settings = readBodyLabel((name) => this.getAttribute(name));
@@ -594,6 +625,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
594
625
  assets: { entries: stats?.assets.entries ?? 0, refs: stats?.assets.refs ?? 0 },
595
626
  meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
596
627
  bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
628
+ sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, renders: 0, lang: "" },
597
629
  };
598
630
  }
599
631
  /**
@@ -5,6 +5,6 @@ export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre, type CameraMode, ty
5
5
  export type { ThreeParts } from "./earth.ts";
6
6
  export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type VisibleTile } from "./tiles.ts";
7
7
  export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.ts";
8
- export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, setBodyLabelFontUrl, type BodyLabelSettings } from "./body-label.ts";
8
+ export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, loadMichroma, setBodyLabelFontUrl, type BodyLabelSettings } from "./body-label.ts";
9
9
  export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness, type AirSamples } from "./air.ts";
10
10
  export { AIR_NOTE } from "./air-note.ts";
@@ -6,6 +6,6 @@ export { createGate, frameCap } from "./gate.js";
6
6
  export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre } from "./earth.js";
7
7
  export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView } from "./tiles.js";
8
8
  export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.js";
9
- export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, setBodyLabelFontUrl } from "./body-label.js";
9
+ export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, loadMichroma, setBodyLabelFontUrl } from "./body-label.js";
10
10
  export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness } from "./air.js";
11
11
  export { AIR_NOTE } from "./air-note.js";
@@ -30,6 +30,10 @@ export interface ParsedElements {
30
30
  reason: string;
31
31
  }[];
32
32
  }
33
+ /** A record with the fields of an OMM, from text or numbers, or the reason it is not one. */
34
+ export declare function toElementSet(record: Record<string, unknown>): ElementSet | string;
35
+ /** The cells of one CSV line (a cell may be in double quotes, with `""` for a quote). */
36
+ export declare function cellsOf(line: string): string[];
33
37
  /**
34
38
  * Read element sets from text: OMM as JSON (an array or a single object), OMM as CSV (a header row, then one satellite a row) or TLE (two lines, or three with the name first). The format is found from the text.
35
39
  * An element set that is missing a number, has a wrong TLE checksum or is not a possible orbit is left out, with the reason, in `skipped`. It throws if the text is none of the three.
@@ -1,7 +1,7 @@
1
1
  const NUMBERS = ["MEAN_MOTION", "ECCENTRICITY", "INCLINATION", "RA_OF_ASC_NODE", "ARG_OF_PERICENTER", "MEAN_ANOMALY", "NORAD_CAT_ID", "BSTAR", "MEAN_MOTION_DOT", "MEAN_MOTION_DDOT"];
2
2
  const OPTIONAL_NUMBERS = ["EPHEMERIS_TYPE", "ELEMENT_SET_NO", "REV_AT_EPOCH"];
3
3
  /** A record with the fields of an OMM, from text or numbers, or the reason it is not one. */
4
- function toElementSet(record) {
4
+ export function toElementSet(record) {
5
5
  const out = {};
6
6
  const name = typeof record["OBJECT_NAME"] === "string" ? record["OBJECT_NAME"].trim() : "";
7
7
  out["OBJECT_NAME"] = name || `NORAD ${String(record["NORAD_CAT_ID"] ?? "?")}`;
@@ -47,7 +47,7 @@ function fromRecords(records, format) {
47
47
  return { format, sets, skipped };
48
48
  }
49
49
  /** The cells of one CSV line (a cell may be in double quotes, with `""` for a quote). */
50
- function cellsOf(line) {
50
+ export function cellsOf(line) {
51
51
  const cells = [];
52
52
  let at = 0;
53
53
  while (at <= line.length) {
@@ -0,0 +1,55 @@
1
+ import type { LabelStyle, ScreenPoint } from "@johnmorrisdotca/hoshi-stars/sky-labels";
2
+ /** The styles of the layer, for an element to add to its own (`#sk-canvas`, `#sk-names` and the labels in its shadow root). */
3
+ export declare const SKY_STYLE: string;
4
+ /** What an element tells the layer at each draw: where a direction in the sky falls on the screen, the size of the box, and the bodies that cover the sky (round, in pixels). */
5
+ export interface SkyFrame {
6
+ /** Writes where the direction (right ascension and declination, degrees) falls on the screen in CSS pixels and answers whether it is in front of the camera. */
7
+ project(rightAscension: number, declination: number, out: ScreenPoint): boolean;
8
+ width: number;
9
+ height: number;
10
+ /** Bodies in front of the sky, each a disc on the screen: the Earth, the Moon, the Sun. */
11
+ discs: readonly {
12
+ x: number;
13
+ y: number;
14
+ radius: number;
15
+ }[];
16
+ }
17
+ export interface SkyHost {
18
+ /** Tells where the sky falls in the picture just drawn, or `null` when there is no picture. */
19
+ frame(frame: SkyFrame | null): void;
20
+ /** What the settings are now (`star-names`, `star-names-magnitude`, `constellation-lines`, the language): read again after any of them changed. */
21
+ refresh(): void;
22
+ /** The look of the names, as a partial hoshi-stars `LabelStyle` (the property `skyStyle`). */
23
+ setStyle(style: Partial<LabelStyle>): void;
24
+ readonly stats: {
25
+ on: boolean;
26
+ loaded: boolean;
27
+ names: number;
28
+ figures: number;
29
+ picked: string | null;
30
+ renders: number;
31
+ lang: string;
32
+ };
33
+ dispose(): void;
34
+ }
35
+ export interface SkyHostOptions {
36
+ /** Reads one of the element's attributes. */
37
+ attribute(name: string): string | null;
38
+ /** The page's language, `en` or `ja`. */
39
+ language(): "en" | "ja";
40
+ /** The shadow root and its host. */
41
+ root: ShadowRoot;
42
+ /** Told when the layer could not be made (hoshi-stars is not installed, or its font did not load). */
43
+ onError(error: unknown): void;
44
+ /** Loads Michroma for the names, when the page has named no font of its own: kazoku-ui's `loadBodyLabelFont`. */
45
+ loadFont(): Promise<unknown>;
46
+ }
47
+ /** The attributes this layer reads. */
48
+ export declare const SKY_ATTRIBUTES: readonly ["star-names", "star-names-magnitude", "constellation-lines"];
49
+ /**
50
+ * Makes the layer of one element, inside its shadow root. Nothing of hoshi-stars is loaded, and nothing is added to the root, until one of the three attributes is there.
51
+ *
52
+ * @param options - The attribute reader, the language and the shadow root.
53
+ * @returns The host.
54
+ */
55
+ export declare function createSkyHost(options: SkyHostOptions): SkyHost;