@johnmorrisdotca/chikyu-earth 0.31.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/NOTICE.md +10 -1
- package/README.md +32 -2
- package/dist/catalogue/fleets.d.ts +70 -0
- package/dist/catalogue/fleets.js +66 -0
- package/dist/catalogue/index.d.ts +5 -0
- package/dist/catalogue/index.js +7 -0
- package/dist/catalogue/kinds.d.ts +143 -0
- package/dist/catalogue/kinds.js +121 -0
- package/dist/catalogue/omm.d.ts +44 -0
- package/dist/catalogue/omm.js +92 -0
- package/dist/catalogue/orbit.d.ts +95 -0
- package/dist/catalogue/orbit.js +91 -0
- package/dist/catalogue/pack.d.ts +193 -0
- package/dist/catalogue/pack.js +327 -0
- package/dist/data/meteor-iau.d.ts +79 -0
- package/dist/data/meteor-iau.js +77 -0
- package/dist/data/meteor-showers.js +24 -20
- package/dist/data-door.d.ts +2 -0
- package/dist/data-door.js +4 -2
- package/dist/door/index.d.ts +1 -0
- package/dist/door/index.js +1 -0
- package/dist/door/packed.d.ts +64 -0
- package/dist/door/packed.js +91 -0
- package/dist/meteors/index.d.ts +2 -0
- package/dist/meteors/index.js +2 -0
- package/dist/meteors/parents.d.ts +45 -0
- package/dist/meteors/parents.js +67 -0
- package/dist/realistic/body-label.d.ts +126 -0
- package/dist/realistic/body-label.js +187 -0
- package/dist/realistic/earth.d.ts +8 -0
- package/dist/realistic/earth.js +29 -0
- package/dist/realistic/element.d.ts +35 -0
- package/dist/realistic/element.js +78 -2
- package/dist/realistic/index.d.ts +1 -0
- package/dist/realistic/index.js +1 -0
- package/dist/realistic/textures.d.ts +8 -0
- package/dist/satellites/source.d.ts +4 -0
- package/dist/satellites/source.js +2 -2
- package/dist/sky/host.d.ts +55 -0
- package/dist/sky/host.js +382 -0
- package/dist/space/element.d.ts +35 -0
- package/dist/space/element.js +78 -2
- package/dist/space/scene.d.ts +8 -0
- package/dist/space/scene.js +34 -0
- package/package.json +12 -2
|
@@ -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
|
+
}
|
package/dist/meteors/index.d.ts
CHANGED
|
@@ -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";
|
package/dist/meteors/index.js
CHANGED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type * as THREE from "three";
|
|
2
|
+
import type { BodyLabelLook } from "@johnmorrisdotca/kazoku-ui/body-label";
|
|
3
|
+
import type { ThreeParts } from "./textures.ts";
|
|
4
|
+
/**
|
|
5
|
+
* The attributes of the family's body label, in the order a settings panel lists them.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { BODY_LABEL_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
10
|
+
*
|
|
11
|
+
* console.log(BODY_LABEL_ATTRIBUTES.join(", "));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const BODY_LABEL_ATTRIBUTES: readonly ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font"];
|
|
15
|
+
/**
|
|
16
|
+
* The settings of the name on the Earth: the same options the family's label takes, with the text left out (it is the Earth's own name, in the page's language).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import type { BodyLabelSettings } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
21
|
+
*
|
|
22
|
+
* const settings: BodyLabelSettings = { look: "painted", strength: 0.5, repeat: "once", latitude: 0, facing: false };
|
|
23
|
+
* console.log(settings.look);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export interface BodyLabelSettings {
|
|
27
|
+
look: BodyLabelLook;
|
|
28
|
+
/** 0 to 1. */
|
|
29
|
+
strength: number;
|
|
30
|
+
repeat: "once" | "both" | "around";
|
|
31
|
+
/** Degrees, kept within 70 of the equator by the label. */
|
|
32
|
+
latitude: number;
|
|
33
|
+
/** The name keeps facing the reader while the Earth turns under it. */
|
|
34
|
+
facing: boolean;
|
|
35
|
+
/** A CSS font family the page has loaded; Michroma, fetched once, when left out. */
|
|
36
|
+
font?: string;
|
|
37
|
+
/** The family for letters the font has none of (Japanese); the page's sans when left out. */
|
|
38
|
+
fallbackFont?: string;
|
|
39
|
+
}
|
|
40
|
+
/** What an Earth tells its scene about its name: the settings now, or `null` for none, and the text. */
|
|
41
|
+
export interface BodyLabelState {
|
|
42
|
+
settings: BodyLabelSettings | null;
|
|
43
|
+
text: string;
|
|
44
|
+
/** What the layer has done: the label is made and in the globe, and it is showing (not hidden for being small), as of the last draw. */
|
|
45
|
+
drawn: {
|
|
46
|
+
made: boolean;
|
|
47
|
+
showing: boolean;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export declare const newBodyLabelState: () => BodyLabelState;
|
|
51
|
+
/**
|
|
52
|
+
* What the family's attributes mean: `body-label` (`painted`, `etched`, `outline` or `burned`; present with another value, or none, it is `painted`; absent, no label), `body-label-strength` (0 to 1, 0.5), `body-label-repeat` (`once`, `both` or
|
|
53
|
+
* `around`; `once`), `body-label-latitude` (degrees; 0), `body-label-facing` (present: always facing the reader), `body-label-font` and `body-label-fallback-font`.
|
|
54
|
+
*
|
|
55
|
+
* @param get - Reads an attribute by name, `null` for one that is not there.
|
|
56
|
+
* @returns The settings, or `null` for no label.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { readBodyLabel } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
61
|
+
*
|
|
62
|
+
* const attributes: Record<string, string> = { "body-label": "etched", "body-label-strength": "0.8", "body-label-repeat": "both" };
|
|
63
|
+
* console.log(readBodyLabel((name) => attributes[name] ?? null));
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function readBodyLabel(get: (name: string) => string | null): BodyLabelSettings | null;
|
|
67
|
+
/**
|
|
68
|
+
* The name written on the Earth: `EARTH`, or `地球` for a Japanese page.
|
|
69
|
+
*
|
|
70
|
+
* @param language - `en` or `ja`.
|
|
71
|
+
* @returns The text.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { bodyLabelText } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
76
|
+
*
|
|
77
|
+
* console.log(bodyLabelText("en"), bodyLabelText("ja"));
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare const bodyLabelText: (language: "en" | "ja") => string;
|
|
81
|
+
export interface BodyLabelLayer {
|
|
82
|
+
/** Puts the label right for this draw (made, changed or taken away as the settings say) and returns nothing: it asks for a draw of its own when something changed. */
|
|
83
|
+
sync(camera: THREE.Camera, radiusPx: number): void;
|
|
84
|
+
dispose(): void;
|
|
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>;
|
|
99
|
+
/**
|
|
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
|
|
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.
|
|
102
|
+
*
|
|
103
|
+
* @param url - The font file's address, or `undefined` for the default.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts no-run
|
|
107
|
+
* import { setBodyLabelFontUrl } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
108
|
+
*
|
|
109
|
+
* setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function setBodyLabelFontUrl(url: string | undefined): void;
|
|
113
|
+
/**
|
|
114
|
+
* Makes the layer that keeps the Earth's name on its globe, inside `parent` (the group or mesh that turns with the Earth, a radius of 1). The family's body label is loaded only when the settings first ask for it, and its font (Michroma, 64 kB) only
|
|
115
|
+
* when the page has named no font of its own. All three.js parts the label needs must be in `three` (the full three.js has them); without them `onError` is told once and nothing is drawn.
|
|
116
|
+
*
|
|
117
|
+
* @param three - The page's three.js.
|
|
118
|
+
* @param parent - What turns with the Earth.
|
|
119
|
+
* @param state - The settings and the text, which the element changes.
|
|
120
|
+
* @param deps - `invalidate` asks for a draw; `onError` hears of a label that could not be made.
|
|
121
|
+
* @returns The layer.
|
|
122
|
+
*/
|
|
123
|
+
export declare function createBodyLabelLayer(three: ThreeParts, parent: THREE.Object3D, state: BodyLabelState, deps: {
|
|
124
|
+
invalidate: () => void;
|
|
125
|
+
onError?: (error: unknown) => void;
|
|
126
|
+
}): BodyLabelLayer;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attributes of the family's body label, in the order a settings panel lists them.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { BODY_LABEL_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
7
|
+
*
|
|
8
|
+
* console.log(BODY_LABEL_ATTRIBUTES.join(", "));
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export const BODY_LABEL_ATTRIBUTES = ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font"];
|
|
12
|
+
export const newBodyLabelState = () => ({ settings: null, text: "EARTH", drawn: { made: false, showing: false } });
|
|
13
|
+
const LOOKS = ["painted", "etched", "outline", "burned"];
|
|
14
|
+
const REPEATS = ["once", "both", "around"];
|
|
15
|
+
/**
|
|
16
|
+
* What the family's attributes mean: `body-label` (`painted`, `etched`, `outline` or `burned`; present with another value, or none, it is `painted`; absent, no label), `body-label-strength` (0 to 1, 0.5), `body-label-repeat` (`once`, `both` or
|
|
17
|
+
* `around`; `once`), `body-label-latitude` (degrees; 0), `body-label-facing` (present: always facing the reader), `body-label-font` and `body-label-fallback-font`.
|
|
18
|
+
*
|
|
19
|
+
* @param get - Reads an attribute by name, `null` for one that is not there.
|
|
20
|
+
* @returns The settings, or `null` for no label.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { readBodyLabel } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
25
|
+
*
|
|
26
|
+
* const attributes: Record<string, string> = { "body-label": "etched", "body-label-strength": "0.8", "body-label-repeat": "both" };
|
|
27
|
+
* console.log(readBodyLabel((name) => attributes[name] ?? null));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function readBodyLabel(get) {
|
|
31
|
+
const look = get("body-label");
|
|
32
|
+
if (look === null)
|
|
33
|
+
return null;
|
|
34
|
+
const strength = get("body-label-strength");
|
|
35
|
+
const latitude = get("body-label-latitude");
|
|
36
|
+
const repeat = get("body-label-repeat") ?? "once";
|
|
37
|
+
const font = get("body-label-font")?.trim();
|
|
38
|
+
const fallback = get("body-label-fallback-font")?.trim();
|
|
39
|
+
const number = (text, fallbackValue) => (text === null || text.trim() === "" || !Number.isFinite(Number(text)) ? fallbackValue : Number(text));
|
|
40
|
+
return {
|
|
41
|
+
look: (LOOKS.includes(look.trim()) ? look.trim() : "painted"),
|
|
42
|
+
strength: Math.min(1, Math.max(0, number(strength, 0.5))),
|
|
43
|
+
repeat: (REPEATS.includes(repeat) ? repeat : "once"),
|
|
44
|
+
latitude: number(latitude, 0),
|
|
45
|
+
facing: get("body-label-facing") !== null && get("body-label-facing") !== "off",
|
|
46
|
+
...(font ? { font } : {}),
|
|
47
|
+
...(fallback ? { fallbackFont: fallback } : {}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The name written on the Earth: `EARTH`, or `地球` for a Japanese page.
|
|
52
|
+
*
|
|
53
|
+
* @param language - `en` or `ja`.
|
|
54
|
+
* @returns The text.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { bodyLabelText } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
59
|
+
*
|
|
60
|
+
* console.log(bodyLabelText("en"), bodyLabelText("ja"));
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export const bodyLabelText = (language) => (language === "ja" ? "地球" : "EARTH");
|
|
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
|
+
}
|
|
81
|
+
/**
|
|
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
|
|
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.
|
|
84
|
+
*
|
|
85
|
+
* @param url - The font file's address, or `undefined` for the default.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts no-run
|
|
89
|
+
* import { setBodyLabelFontUrl } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
90
|
+
*
|
|
91
|
+
* setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function setBodyLabelFontUrl(url) {
|
|
95
|
+
fontUrl = url;
|
|
96
|
+
}
|
|
97
|
+
const signatureOf = (state) => (state.settings ? JSON.stringify([state.text, state.settings]) : "");
|
|
98
|
+
/**
|
|
99
|
+
* Makes the layer that keeps the Earth's name on its globe, inside `parent` (the group or mesh that turns with the Earth, a radius of 1). The family's body label is loaded only when the settings first ask for it, and its font (Michroma, 64 kB) only
|
|
100
|
+
* when the page has named no font of its own. All three.js parts the label needs must be in `three` (the full three.js has them); without them `onError` is told once and nothing is drawn.
|
|
101
|
+
*
|
|
102
|
+
* @param three - The page's three.js.
|
|
103
|
+
* @param parent - What turns with the Earth.
|
|
104
|
+
* @param state - The settings and the text, which the element changes.
|
|
105
|
+
* @param deps - `invalidate` asks for a draw; `onError` hears of a label that could not be made.
|
|
106
|
+
* @returns The layer.
|
|
107
|
+
*/
|
|
108
|
+
export function createBodyLabelLayer(three, parent, state, deps) {
|
|
109
|
+
let label = null;
|
|
110
|
+
let loading = false;
|
|
111
|
+
let failed = false;
|
|
112
|
+
let signature = "";
|
|
113
|
+
let gone = false;
|
|
114
|
+
const options = () => {
|
|
115
|
+
const s = state.settings;
|
|
116
|
+
return { text: state.text, look: s.look, strength: s.strength, repeat: s.repeat, latitude: s.latitude, facing: s.facing, ...(s.font ? { font: s.font } : {}), ...(s.fallbackFont ? { fallbackFont: s.fallbackFont } : {}) };
|
|
117
|
+
};
|
|
118
|
+
const remove = () => {
|
|
119
|
+
if (!label)
|
|
120
|
+
return;
|
|
121
|
+
parent.remove(label.object);
|
|
122
|
+
label.dispose();
|
|
123
|
+
label = null;
|
|
124
|
+
signature = "";
|
|
125
|
+
state.drawn = { made: false, showing: false };
|
|
126
|
+
};
|
|
127
|
+
const make = () => {
|
|
128
|
+
loading = true;
|
|
129
|
+
void import("@johnmorrisdotca/kazoku-ui/body-label")
|
|
130
|
+
.then(async (module) => {
|
|
131
|
+
const parts = three;
|
|
132
|
+
for (const name of ["CanvasTexture", "SphereGeometry", "MeshLambertMaterial", "SRGBColorSpace", "NormalBlending", "AdditiveBlending"])
|
|
133
|
+
if (parts[name] === undefined)
|
|
134
|
+
throw new Error(`the three.js handed over has no ${name}, which the name on the Earth needs`);
|
|
135
|
+
if (!state.settings?.font)
|
|
136
|
+
await module.loadBodyLabelFont(fontUrl);
|
|
137
|
+
if (gone || !state.settings) {
|
|
138
|
+
loading = false;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const made = module.createBodyLabel(three, options());
|
|
142
|
+
parent.add(made.object);
|
|
143
|
+
label = made;
|
|
144
|
+
state.drawn.made = true;
|
|
145
|
+
signature = signatureOf(state);
|
|
146
|
+
loading = false;
|
|
147
|
+
void made.ready.then(() => {
|
|
148
|
+
if (!gone)
|
|
149
|
+
deps.invalidate();
|
|
150
|
+
});
|
|
151
|
+
deps.invalidate();
|
|
152
|
+
})
|
|
153
|
+
.catch((error) => {
|
|
154
|
+
loading = false;
|
|
155
|
+
failed = true;
|
|
156
|
+
deps.onError?.(error);
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
sync(camera, radiusPx) {
|
|
161
|
+
if (gone)
|
|
162
|
+
return;
|
|
163
|
+
if (!state.settings) {
|
|
164
|
+
remove();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (!label) {
|
|
168
|
+
if (!loading && !failed)
|
|
169
|
+
make();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const now = signatureOf(state);
|
|
173
|
+
if (now !== signature) {
|
|
174
|
+
signature = now;
|
|
175
|
+
label.set(options());
|
|
176
|
+
deps.invalidate();
|
|
177
|
+
}
|
|
178
|
+
if (label.update(camera, radiusPx))
|
|
179
|
+
deps.invalidate();
|
|
180
|
+
state.drawn.showing = label.object.visible;
|
|
181
|
+
},
|
|
182
|
+
dispose() {
|
|
183
|
+
gone = true;
|
|
184
|
+
remove();
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
@@ -7,6 +7,8 @@ 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";
|
|
11
|
+
import { type BodyLabelState } from "./body-label.ts";
|
|
10
12
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
11
13
|
export type { ThreeParts };
|
|
12
14
|
type Three = ThreeParts;
|
|
@@ -85,6 +87,8 @@ export interface EarthModel {
|
|
|
85
87
|
ratio(): number;
|
|
86
88
|
/** Meteors seen from space (src/meteors/layer.ts): off unless the element switches them on. */
|
|
87
89
|
meteors: MeteorState;
|
|
90
|
+
/** The name written on the Earth (src/realistic/body-label.ts): off unless the element sets it. */
|
|
91
|
+
bodyLabel: BodyLabelState;
|
|
88
92
|
}
|
|
89
93
|
export interface EarthDeps {
|
|
90
94
|
assets: AssetCache;
|
|
@@ -103,6 +107,10 @@ export interface EarthDeps {
|
|
|
103
107
|
air?: () => "full" | "light";
|
|
104
108
|
/** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
|
|
105
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;
|
|
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). */
|
|
113
|
+
onLabelError?: (error: unknown) => void;
|
|
106
114
|
/** Told after the tiles were put right for a draw: what the draw shows from each source is known now. */
|
|
107
115
|
onTiled?: () => void;
|
|
108
116
|
/** Told at the start of every draw, before anything is read for it. */
|