@johnmorrisdotca/chikyu-earth 0.30.0 → 0.32.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 +11 -0
- package/NOTICE.md +4 -0
- package/README.md +73 -1
- package/dist/data-door.d.ts +357 -0
- package/dist/data-door.js +393 -0
- package/dist/door/book.d.ts +118 -0
- package/dist/door/book.js +211 -0
- package/dist/door/elements.d.ts +96 -0
- package/dist/door/elements.js +108 -0
- package/dist/door/host.d.ts +30 -0
- package/dist/door/host.js +44 -0
- package/dist/door/index.d.ts +6 -0
- package/dist/door/index.js +10 -0
- package/dist/door/map.d.ts +165 -0
- package/dist/door/map.js +182 -0
- package/dist/door/own.d.ts +36 -0
- package/dist/door/own.js +75 -0
- package/dist/passes/element.d.ts +18 -0
- package/dist/passes/element.js +67 -5
- package/dist/realistic/body-label.d.ts +113 -0
- package/dist/realistic/body-label.js +171 -0
- package/dist/realistic/earth.d.ts +10 -3
- package/dist/realistic/earth.js +10 -1
- package/dist/realistic/element.d.ts +35 -0
- package/dist/realistic/element.js +107 -5
- 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/realistic/tile-set.d.ts +27 -2
- package/dist/realistic/tile-set.js +155 -49
- package/dist/space/element.d.ts +17 -0
- package/dist/space/element.js +46 -2
- package/dist/space/scene.d.ts +5 -0
- package/dist/space/scene.js +8 -0
- package/package.json +7 -2
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// The sources a view holds: which are in it, which are switched off, the records of the record sources once read, and the credits of what was drawn. An element owns one. Everything here is plain TypeScript with no DOM and no
|
|
2
|
+
// three.js; the elements call it, and a test can too. The tiles themselves are loaded by the realistic Earth's tile set, which asks the book for the source of each layer.
|
|
3
|
+
import { validateSource } from "../data-door.js";
|
|
4
|
+
import { readElementSets } from "./elements.js";
|
|
5
|
+
import { OWN_BY_ID, isOwnSource } from "./own.js";
|
|
6
|
+
const LAYERS = ["day", "night", "clouds", "water", "*"];
|
|
7
|
+
/**
|
|
8
|
+
* Makes the sources of one view.
|
|
9
|
+
*
|
|
10
|
+
* @param options - The kinds the view draws.
|
|
11
|
+
* @returns The book.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { createSourceBook } from "@johnmorrisdotca/chikyu-earth/door";
|
|
16
|
+
*
|
|
17
|
+
* const book = createSourceBook({ kinds: ["tiles"] });
|
|
18
|
+
* console.log(book.active().length);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createSourceBook(options = {}) {
|
|
22
|
+
const kinds = new Set(options.kinds ?? ["tiles", "records"]);
|
|
23
|
+
const list = [];
|
|
24
|
+
const off = new Set();
|
|
25
|
+
const controllers = new Map();
|
|
26
|
+
const reads = new Map();
|
|
27
|
+
const listeners = new Set();
|
|
28
|
+
const reading = new Set();
|
|
29
|
+
let onlyOwn = false;
|
|
30
|
+
let gone = false;
|
|
31
|
+
let version = 0;
|
|
32
|
+
const notify = () => {
|
|
33
|
+
version += 1;
|
|
34
|
+
for (const listener of [...listeners])
|
|
35
|
+
listener();
|
|
36
|
+
};
|
|
37
|
+
const isOwn = (source) => isOwnSource(source);
|
|
38
|
+
const inUse = (source) => !off.has(source.info.id) && !(onlyOwn && !isOwn(source));
|
|
39
|
+
const active = () => list.filter(inUse);
|
|
40
|
+
const controllerOf = (id) => {
|
|
41
|
+
let controller = controllers.get(id);
|
|
42
|
+
if (controller === undefined) {
|
|
43
|
+
controller = new AbortController();
|
|
44
|
+
controllers.set(id, controller);
|
|
45
|
+
}
|
|
46
|
+
return controller;
|
|
47
|
+
};
|
|
48
|
+
/** Aborts a source's reads and loads and frees its records. */
|
|
49
|
+
const release = (id) => {
|
|
50
|
+
controllers.get(id)?.abort();
|
|
51
|
+
controllers.delete(id);
|
|
52
|
+
reads.delete(id);
|
|
53
|
+
};
|
|
54
|
+
/** Starts reading a record source: once, when it is added or switched on. */
|
|
55
|
+
const start = (source) => {
|
|
56
|
+
if (source.kind !== "records" || reads.has(source.info.id) || controllers.has(source.info.id))
|
|
57
|
+
return;
|
|
58
|
+
const controller = controllerOf(source.info.id);
|
|
59
|
+
const done = readElementSets(source, controller.signal).then((read) => {
|
|
60
|
+
reading.delete(done);
|
|
61
|
+
if (controllers.get(source.info.id) !== controller || read.status === "aborted")
|
|
62
|
+
return;
|
|
63
|
+
reads.set(source.info.id, read);
|
|
64
|
+
notify();
|
|
65
|
+
});
|
|
66
|
+
reading.add(done);
|
|
67
|
+
};
|
|
68
|
+
const check = (source) => {
|
|
69
|
+
validateSource(source, list.map((one) => one.info.id));
|
|
70
|
+
const id = source.info.id;
|
|
71
|
+
if (OWN_BY_ID.has(id) && !isOwnSource(source))
|
|
72
|
+
throw new TypeError(`source "${id}": that id is one of the package's own (${[...OWN_BY_ID.keys()].join(", ")}); a source of yours takes an id of its own`);
|
|
73
|
+
if (!kinds.has(source.kind))
|
|
74
|
+
throw new TypeError(`source "${id}": this view takes ${[...kinds].join(" and ")} sources, not ${source.kind} sources`);
|
|
75
|
+
if (source.kind === "tiles") {
|
|
76
|
+
const map = source;
|
|
77
|
+
if (typeof map.layer !== "string" || !LAYERS.includes(map.layer))
|
|
78
|
+
throw new TypeError(`source "${id}": a map source names its layer ("day", "night", "clouds" or "water", or "*" for a folder of them), not ${JSON.stringify(map.layer)}`);
|
|
79
|
+
}
|
|
80
|
+
return source;
|
|
81
|
+
};
|
|
82
|
+
const remove = (id) => {
|
|
83
|
+
const at = list.findIndex((source) => source.info.id === id);
|
|
84
|
+
if (at < 0)
|
|
85
|
+
return false;
|
|
86
|
+
list.splice(at, 1);
|
|
87
|
+
off.delete(id);
|
|
88
|
+
release(id);
|
|
89
|
+
notify();
|
|
90
|
+
return true;
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
get sources() {
|
|
94
|
+
return [...list];
|
|
95
|
+
},
|
|
96
|
+
addSource(source) {
|
|
97
|
+
const one = check(source);
|
|
98
|
+
list.push(one);
|
|
99
|
+
if (inUse(one))
|
|
100
|
+
start(one);
|
|
101
|
+
notify();
|
|
102
|
+
return () => void remove(one.info.id);
|
|
103
|
+
},
|
|
104
|
+
removeSource: remove,
|
|
105
|
+
enableSource(id, on) {
|
|
106
|
+
const source = list.find((one) => one.info.id === id);
|
|
107
|
+
if (source === undefined || off.has(id) === !on)
|
|
108
|
+
return;
|
|
109
|
+
if (on) {
|
|
110
|
+
off.delete(id);
|
|
111
|
+
if (inUse(source))
|
|
112
|
+
start(source);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
off.add(id);
|
|
116
|
+
release(id);
|
|
117
|
+
}
|
|
118
|
+
notify();
|
|
119
|
+
},
|
|
120
|
+
isEnabled: (id) => list.some((source) => source.info.id === id) && !off.has(id),
|
|
121
|
+
ownOnly(on) {
|
|
122
|
+
if (on === onlyOwn)
|
|
123
|
+
return;
|
|
124
|
+
onlyOwn = on;
|
|
125
|
+
for (const source of list) {
|
|
126
|
+
if (isOwn(source) || off.has(source.info.id))
|
|
127
|
+
continue;
|
|
128
|
+
if (on)
|
|
129
|
+
release(source.info.id);
|
|
130
|
+
else
|
|
131
|
+
start(source);
|
|
132
|
+
}
|
|
133
|
+
notify();
|
|
134
|
+
},
|
|
135
|
+
get onlyOwn() {
|
|
136
|
+
return onlyOwn;
|
|
137
|
+
},
|
|
138
|
+
active,
|
|
139
|
+
mapSources: (layer) => active()
|
|
140
|
+
.filter((source) => source.kind === "tiles" && (source.layer === layer || source.layer === "*"))
|
|
141
|
+
.reverse(),
|
|
142
|
+
elementLists: () => active().flatMap((source) => (source.kind === "records" && reads.get(source.info.id)?.status === "ok" ? [{ id: source.info.id, sets: reads.get(source.info.id).records }] : [])),
|
|
143
|
+
isOwn,
|
|
144
|
+
get: (id) => list.find((source) => source.info.id === id),
|
|
145
|
+
signal: (id) => controllerOf(id).signal,
|
|
146
|
+
onChange(listener) {
|
|
147
|
+
listeners.add(listener);
|
|
148
|
+
return () => void listeners.delete(listener);
|
|
149
|
+
},
|
|
150
|
+
stats() {
|
|
151
|
+
const records = {};
|
|
152
|
+
for (const [id, read] of reads)
|
|
153
|
+
records[id] = { status: read.status, kept: read.records.length, skipped: read.skipped };
|
|
154
|
+
return { records };
|
|
155
|
+
},
|
|
156
|
+
get version() {
|
|
157
|
+
return version;
|
|
158
|
+
},
|
|
159
|
+
async ready() {
|
|
160
|
+
await Promise.all([...reading]);
|
|
161
|
+
},
|
|
162
|
+
dispose() {
|
|
163
|
+
if (gone)
|
|
164
|
+
return;
|
|
165
|
+
gone = true;
|
|
166
|
+
for (const source of [...list])
|
|
167
|
+
release(source.info.id);
|
|
168
|
+
for (const id of [...controllers.keys()])
|
|
169
|
+
release(id);
|
|
170
|
+
list.length = 0;
|
|
171
|
+
listeners.clear();
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The credits of a view for the last drawn frame: the package's own first, then the sources a caller added, each with the marks or tiles it gave; a source that gave none is left out.
|
|
177
|
+
*
|
|
178
|
+
* @param own - The package's own credits (`ownCredit`), with how many marks each gave.
|
|
179
|
+
* @param book - The view's sources.
|
|
180
|
+
* @param used - How many marks or tiles each source of the book gave, by id.
|
|
181
|
+
* @returns The credits, own first, in a stable order.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* import { createSourceBook, creditsOf, ownCredit } from "@johnmorrisdotca/chikyu-earth/door";
|
|
186
|
+
*
|
|
187
|
+
* const book = createSourceBook();
|
|
188
|
+
* console.log(creditsOf([ownCredit("chikyu-pictures", 1)], book, new Map()).length);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export function creditsOf(own, book, used) {
|
|
192
|
+
const mine = own.filter((credit) => credit.used > 0);
|
|
193
|
+
const theirs = [];
|
|
194
|
+
const named = new Set(mine.map((credit) => credit.source.id));
|
|
195
|
+
for (const source of book.active()) {
|
|
196
|
+
const count = used.get(source.info.id) ?? 0;
|
|
197
|
+
if (count <= 0)
|
|
198
|
+
continue;
|
|
199
|
+
const credit = { source: source.info, own: book.isOwn(source), used: count };
|
|
200
|
+
if (credit.own) {
|
|
201
|
+
const held = mine.findIndex((one) => one.source.id === credit.source.id);
|
|
202
|
+
if (held >= 0)
|
|
203
|
+
mine[held] = { ...mine[held], used: mine[held].used + count };
|
|
204
|
+
else
|
|
205
|
+
mine.push(credit);
|
|
206
|
+
}
|
|
207
|
+
else if (!named.has(credit.source.id))
|
|
208
|
+
theirs.push(credit);
|
|
209
|
+
}
|
|
210
|
+
return [...mine, ...theirs];
|
|
211
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type RecordSource, type RecordsRead, type SourceInfo } from "../data-door.ts";
|
|
2
|
+
import { type FetchElementsOptions } from "../satellites/source.ts";
|
|
3
|
+
import type { ElementSet } from "../satellites/types.ts";
|
|
4
|
+
/**
|
|
5
|
+
* A source of satellites' orbital elements: a list that fits in memory (at most 200,000 sets), read once when the source is added, each an `ElementSet`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import type { ElementRecordSource } from "@johnmorrisdotca/chikyu-earth/door";
|
|
10
|
+
*
|
|
11
|
+
* const names = (sources: readonly ElementRecordSource[]): string[] => sources.map((source) => source.info.id);
|
|
12
|
+
* console.log(names([]));
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type ElementRecordSource = RecordSource<ElementSet>;
|
|
16
|
+
/** The numbers of an element set that must be finite for it to be drawn. */
|
|
17
|
+
export declare const elementNumbers: (set: ElementSet) => readonly number[];
|
|
18
|
+
/** Whether a record is an element set the passes can work from: a name and an epoch that are text, a mean motion above zero and an orbit that is an ellipse. */
|
|
19
|
+
export declare const isElementSet: (set: unknown) => set is ElementSet;
|
|
20
|
+
/**
|
|
21
|
+
* What `readElementSets` found: the frozen element sets that can be used, and `skipped`, the ones left out for a number that is not finite, a name that is not text or an orbit that is not an ellipse.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import type { ElementSetsRead } from "@johnmorrisdotca/chikyu-earth/door";
|
|
26
|
+
*
|
|
27
|
+
* const say = (read: ElementSetsRead): string => `${read.status}: ${read.records.length} kept, ${read.skipped} skipped`;
|
|
28
|
+
* console.log(typeof say);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export type ElementSetsRead = RecordsRead<ElementSet>;
|
|
32
|
+
/**
|
|
33
|
+
* Reads a source of element sets once: the list is frozen, a set that cannot be used is left out and counted, and a list of more than 200,000 is refused whole. It never throws: a source that fails is a failed read, and one the
|
|
34
|
+
* signal aborted is `aborted`.
|
|
35
|
+
*
|
|
36
|
+
* @param source - The source.
|
|
37
|
+
* @param signal - Aborts the read.
|
|
38
|
+
* @returns The element sets and the count left out.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts no-run
|
|
42
|
+
* import { readElementSets, type ElementRecordSource } from "@johnmorrisdotca/chikyu-earth/door";
|
|
43
|
+
*
|
|
44
|
+
* declare const source: ElementRecordSource;
|
|
45
|
+
* const read = await readElementSets(source, new AbortController().signal);
|
|
46
|
+
* console.log(read.records.length, read.skipped);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function readElementSets(source: ElementRecordSource, signal: AbortSignal): Promise<ElementSetsRead>;
|
|
50
|
+
/**
|
|
51
|
+
* A source of element sets read from an address of your choosing, with whose data it is. The address is read through `fetchElements`, so its politeness rules apply (one request in two hours, a refusal is left alone for an hour,
|
|
52
|
+
* nothing at rest); the sets are read once, when the source is added. The package has no address of its own and never asks one by itself.
|
|
53
|
+
*
|
|
54
|
+
* @param url - The address of OMM JSON, OMM CSV or TLE text.
|
|
55
|
+
* @param info - Who the data is: its id, credit, licence and page.
|
|
56
|
+
* @param options - What `fetchElements` takes.
|
|
57
|
+
* @returns The source, for `addSource` or `sources`.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts no-run
|
|
61
|
+
* import { elementsFrom } from "@johnmorrisdotca/chikyu-earth/door";
|
|
62
|
+
*
|
|
63
|
+
* const mine = elementsFrom("https://example.org/elements/bright.json", {
|
|
64
|
+
* id: "my-elements",
|
|
65
|
+
* name: { en: "My elements", ja: "私の軌道要素" },
|
|
66
|
+
* credit: { en: "Orbit data: my own mirror", ja: "軌道データ:私のミラー" },
|
|
67
|
+
* licence: { name: "CC BY 4.0", url: "https://creativecommons.org/licenses/by/4.0/" },
|
|
68
|
+
* url: "https://example.org/elements/",
|
|
69
|
+
* retrieved: "2026-11-11",
|
|
70
|
+
* });
|
|
71
|
+
* console.log(mine.info.id);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function elementsFrom(url: string, info: SourceInfo, options?: FetchElementsOptions): ElementRecordSource;
|
|
75
|
+
/** A newer epoch wins: the milliseconds of an element set's epoch, or `-Infinity` for one that does not parse. */
|
|
76
|
+
export declare const epochOf: (set: ElementSet) => number;
|
|
77
|
+
/**
|
|
78
|
+
* The element sets of several lists as one, one set for each satellite: where two lists have the same NORAD number the set with the newer epoch wins, and a tie goes to the list that came first.
|
|
79
|
+
*
|
|
80
|
+
* @param lists - Each list's sets, with the id of the source they came from (`null` for sets the page set itself).
|
|
81
|
+
* @returns The sets, each with the id of the source it came from (an `id` of `null` means a set the page set itself, not one from a source).
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { mergeElementSets } from "@johnmorrisdotca/chikyu-earth/door";
|
|
86
|
+
*
|
|
87
|
+
* console.log(mergeElementSets([]).length);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function mergeElementSets(lists: readonly {
|
|
91
|
+
id: string | null;
|
|
92
|
+
sets: readonly ElementSet[];
|
|
93
|
+
}[]): {
|
|
94
|
+
set: ElementSet;
|
|
95
|
+
id: string | null;
|
|
96
|
+
}[];
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// The record sources of the data door: lists of satellites' orbital elements (`ElementSet`s, the OMM "GP" shape CelesTrak and Space-Track serve), for `<chikyu-passes>`. A page that already reads elements from an address
|
|
2
|
+
// (`fetchElements`) hands the result in as a source by `elementsFrom`, which says whose data it is. Pure: no DOM, no three.js, no satellite.js.
|
|
3
|
+
import { loadRecords } from "../data-door.js";
|
|
4
|
+
import { fetchElements } from "../satellites/source.js";
|
|
5
|
+
/** The numbers of an element set that must be finite for it to be drawn. */
|
|
6
|
+
export const elementNumbers = (set) => [
|
|
7
|
+
set.MEAN_MOTION,
|
|
8
|
+
set.ECCENTRICITY,
|
|
9
|
+
set.INCLINATION,
|
|
10
|
+
set.RA_OF_ASC_NODE,
|
|
11
|
+
set.ARG_OF_PERICENTER,
|
|
12
|
+
set.MEAN_ANOMALY,
|
|
13
|
+
set.NORAD_CAT_ID,
|
|
14
|
+
set.BSTAR,
|
|
15
|
+
set.MEAN_MOTION_DOT,
|
|
16
|
+
set.MEAN_MOTION_DDOT,
|
|
17
|
+
Date.parse(/[zZ]|[+-]\d\d:?\d\d$/.test(set.EPOCH) ? set.EPOCH : `${set.EPOCH}Z`),
|
|
18
|
+
];
|
|
19
|
+
/** Whether a record is an element set the passes can work from: a name and an epoch that are text, a mean motion above zero and an orbit that is an ellipse. */
|
|
20
|
+
export const isElementSet = (set) => {
|
|
21
|
+
if (typeof set !== "object" || set === null)
|
|
22
|
+
return false;
|
|
23
|
+
const one = set;
|
|
24
|
+
return typeof one.OBJECT_NAME === "string" && typeof one.EPOCH === "string" && typeof one.MEAN_MOTION === "number" && one.MEAN_MOTION > 0 && typeof one.ECCENTRICITY === "number" && one.ECCENTRICITY >= 0 && one.ECCENTRICITY < 1;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Reads a source of element sets once: the list is frozen, a set that cannot be used is left out and counted, and a list of more than 200,000 is refused whole. It never throws: a source that fails is a failed read, and one the
|
|
28
|
+
* signal aborted is `aborted`.
|
|
29
|
+
*
|
|
30
|
+
* @param source - The source.
|
|
31
|
+
* @param signal - Aborts the read.
|
|
32
|
+
* @returns The element sets and the count left out.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts no-run
|
|
36
|
+
* import { readElementSets, type ElementRecordSource } from "@johnmorrisdotca/chikyu-earth/door";
|
|
37
|
+
*
|
|
38
|
+
* declare const source: ElementRecordSource;
|
|
39
|
+
* const read = await readElementSets(source, new AbortController().signal);
|
|
40
|
+
* console.log(read.records.length, read.skipped);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export async function readElementSets(source, signal) {
|
|
44
|
+
const read = await loadRecords(source, signal, (set) => (isElementSet(set) ? elementNumbers(set) : [Number.NaN]));
|
|
45
|
+
return read;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A source of element sets read from an address of your choosing, with whose data it is. The address is read through `fetchElements`, so its politeness rules apply (one request in two hours, a refusal is left alone for an hour,
|
|
49
|
+
* nothing at rest); the sets are read once, when the source is added. The package has no address of its own and never asks one by itself.
|
|
50
|
+
*
|
|
51
|
+
* @param url - The address of OMM JSON, OMM CSV or TLE text.
|
|
52
|
+
* @param info - Who the data is: its id, credit, licence and page.
|
|
53
|
+
* @param options - What `fetchElements` takes.
|
|
54
|
+
* @returns The source, for `addSource` or `sources`.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts no-run
|
|
58
|
+
* import { elementsFrom } from "@johnmorrisdotca/chikyu-earth/door";
|
|
59
|
+
*
|
|
60
|
+
* const mine = elementsFrom("https://example.org/elements/bright.json", {
|
|
61
|
+
* id: "my-elements",
|
|
62
|
+
* name: { en: "My elements", ja: "私の軌道要素" },
|
|
63
|
+
* credit: { en: "Orbit data: my own mirror", ja: "軌道データ:私のミラー" },
|
|
64
|
+
* licence: { name: "CC BY 4.0", url: "https://creativecommons.org/licenses/by/4.0/" },
|
|
65
|
+
* url: "https://example.org/elements/",
|
|
66
|
+
* retrieved: "2026-11-11",
|
|
67
|
+
* });
|
|
68
|
+
* console.log(mine.info.id);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function elementsFrom(url, info, options = {}) {
|
|
72
|
+
return {
|
|
73
|
+
kind: "records",
|
|
74
|
+
info,
|
|
75
|
+
async records(signal) {
|
|
76
|
+
return (await fetchElements(url, { ...options, signal })).sets;
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** A newer epoch wins: the milliseconds of an element set's epoch, or `-Infinity` for one that does not parse. */
|
|
81
|
+
export const epochOf = (set) => {
|
|
82
|
+
const ms = Date.parse(/[zZ]|[+-]\d\d:?\d\d$/.test(set.EPOCH) ? set.EPOCH : `${set.EPOCH}Z`);
|
|
83
|
+
return Number.isFinite(ms) ? ms : -Infinity;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* The element sets of several lists as one, one set for each satellite: where two lists have the same NORAD number the set with the newer epoch wins, and a tie goes to the list that came first.
|
|
87
|
+
*
|
|
88
|
+
* @param lists - Each list's sets, with the id of the source they came from (`null` for sets the page set itself).
|
|
89
|
+
* @returns The sets, each with the id of the source it came from (an `id` of `null` means a set the page set itself, not one from a source).
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { mergeElementSets } from "@johnmorrisdotca/chikyu-earth/door";
|
|
94
|
+
*
|
|
95
|
+
* console.log(mergeElementSets([]).length);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export function mergeElementSets(lists) {
|
|
99
|
+
const best = new Map();
|
|
100
|
+
for (const list of lists) {
|
|
101
|
+
for (const set of list.sets) {
|
|
102
|
+
const held = best.get(set.NORAD_CAT_ID);
|
|
103
|
+
if (held === undefined || epochOf(set) > epochOf(held.set))
|
|
104
|
+
best.set(set.NORAD_CAT_ID, { set, id: list.id });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return [...best.values()];
|
|
108
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Credit, DataSource } from "../data-door.ts";
|
|
2
|
+
import { type SourceBook, type SourceBookOptions } from "./book.ts";
|
|
3
|
+
/** What an element tells its host about the last drawn frame. */
|
|
4
|
+
export interface DoorFrame {
|
|
5
|
+
/** The package's own credits, with how many marks each gave (`ownCredit`). */
|
|
6
|
+
own(): readonly Credit[];
|
|
7
|
+
/** How many marks or tiles each of the book's sources gave, by id. */
|
|
8
|
+
used(): ReadonlyMap<string, number>;
|
|
9
|
+
}
|
|
10
|
+
export interface DoorHost {
|
|
11
|
+
readonly book: SourceBook;
|
|
12
|
+
/** The sources set by a page, in the order added. */
|
|
13
|
+
sources(): readonly DataSource[];
|
|
14
|
+
/** Replaces every source: all are checked first, and if one is refused nothing changes and the `TypeError` is thrown. */
|
|
15
|
+
setSources(list: readonly unknown[]): void;
|
|
16
|
+
/** The credits of the last drawn frame, the package's own first. */
|
|
17
|
+
credits(): Credit[];
|
|
18
|
+
/** Fires `chikyu-creditschange` when the set of credited sources changed since the last call (not at each draw). */
|
|
19
|
+
announce(): void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Makes the door of one element.
|
|
23
|
+
*
|
|
24
|
+
* @param target - The element: it gets `chikyu-creditschange`.
|
|
25
|
+
* @param frame - What the last drawn frame held.
|
|
26
|
+
* @param options - The kinds of source the element draws.
|
|
27
|
+
* @param redraw - Asked for when a source was added, removed or switched, or its records were read.
|
|
28
|
+
* @returns The host.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createDoorHost(target: EventTarget, frame: DoorFrame, options: SourceBookOptions, redraw: () => void): DoorHost;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createSourceBook, creditsOf } from "./book.js";
|
|
2
|
+
/**
|
|
3
|
+
* Makes the door of one element.
|
|
4
|
+
*
|
|
5
|
+
* @param target - The element: it gets `chikyu-creditschange`.
|
|
6
|
+
* @param frame - What the last drawn frame held.
|
|
7
|
+
* @param options - The kinds of source the element draws.
|
|
8
|
+
* @param redraw - Asked for when a source was added, removed or switched, or its records were read.
|
|
9
|
+
* @returns The host.
|
|
10
|
+
*/
|
|
11
|
+
export function createDoorHost(target, frame, options, redraw) {
|
|
12
|
+
const book = createSourceBook(options);
|
|
13
|
+
let shown = "";
|
|
14
|
+
const credits = () => creditsOf(frame.own(), book, frame.used());
|
|
15
|
+
const announce = () => {
|
|
16
|
+
const now = credits();
|
|
17
|
+
const signature = now.map((credit) => credit.source.id).join(",");
|
|
18
|
+
if (signature === shown)
|
|
19
|
+
return;
|
|
20
|
+
shown = signature;
|
|
21
|
+
target.dispatchEvent(new CustomEvent("chikyu-creditschange", { detail: { credits: now } }));
|
|
22
|
+
};
|
|
23
|
+
book.onChange(() => {
|
|
24
|
+
redraw();
|
|
25
|
+
announce();
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
book,
|
|
29
|
+
sources: () => book.sources,
|
|
30
|
+
setSources(list) {
|
|
31
|
+
const old = [...book.sources];
|
|
32
|
+
const checker = createSourceBook(options);
|
|
33
|
+
for (const one of list)
|
|
34
|
+
checker.addSource(one);
|
|
35
|
+
checker.dispose();
|
|
36
|
+
for (const one of old)
|
|
37
|
+
book.removeSource(one.info.id);
|
|
38
|
+
for (const one of list)
|
|
39
|
+
book.addSource(one);
|
|
40
|
+
},
|
|
41
|
+
credits,
|
|
42
|
+
announce,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createTileStore, creditLine, loadRecords, MAX_IN_FLIGHT, MAX_RECORDS, TILE_BUDGET_BYTES, validateSource } from "../data-door.ts";
|
|
2
|
+
export type { BitmapLike, Credit, DataSource, ImageTile, Licence, MapPlace, RecordsRead, RecordSource, SourceInfo, TileLoader, TileSource, TileStats, TileStore, TileStoreOptions } from "../data-door.ts";
|
|
3
|
+
export { DEFAULT_LEVELS, earthTiles, imageBytes, mapKeys, tileKeyParts, tilePlace, type EarthMapPlace, type EarthMapSource, type EarthTilesOptions, type MapLayer } from "./map.ts";
|
|
4
|
+
export { elementsFrom, mergeElementSets, readElementSets, type ElementRecordSource, type ElementSetsRead } from "./elements.ts";
|
|
5
|
+
export { OWN_SOURCES, ownCredit } from "./own.ts";
|
|
6
|
+
export { createSourceBook, creditsOf, type SourceBook, type SourceBookOptions, type SourceStats } from "./book.ts";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The data door of the Earth (`@johnmorrisdotca/chikyu-earth/door`, MODULES-902): one way to hand the package outside data, and to see whose data is on the screen. A source is a small typed object that carries its own licence and
|
|
2
|
+
// credit. A map source (`EarthMapSource`) is the finer map of the Earth in tiles, and `earthTiles` is the package's own folder of them, which is what the `tiles` attribute means; a record source of orbital elements
|
|
3
|
+
// (`ElementRecordSource`, `elementsFrom`) is what `<chikyu-passes>` works the passes out from. `<chikyu-earth-realistic>` and `<chikyu-passes>` take `sources` and `addSource`, and `credits()` says whose data was in the last drawn frame.
|
|
4
|
+
// The shapes and the four small functions are `../data-door.ts`, the same file in every package of the family (kazoku-ui's templates/data-door.ts). Nothing here is imported by the main entry or the elements' own
|
|
5
|
+
// entries beyond what they use: a page that never uses the door pays nothing. With no outside source every view draws what it always drew. Pure: no DOM, no three.js, no clock.
|
|
6
|
+
export { createTileStore, creditLine, loadRecords, MAX_IN_FLIGHT, MAX_RECORDS, TILE_BUDGET_BYTES, validateSource } from "../data-door.js";
|
|
7
|
+
export { DEFAULT_LEVELS, earthTiles, imageBytes, mapKeys, tileKeyParts, tilePlace } from "./map.js";
|
|
8
|
+
export { elementsFrom, mergeElementSets, readElementSets } from "./elements.js";
|
|
9
|
+
export { OWN_SOURCES, ownCredit } from "./own.js";
|
|
10
|
+
export { createSourceBook, creditsOf } from "./book.js";
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { BitmapLike, ImageTile, MapPlace, TileSource } from "../data-door.ts";
|
|
2
|
+
import { type TileId, type TileLayer } from "../realistic/tiles.ts";
|
|
3
|
+
/**
|
|
4
|
+
* What a map source draws: `day` and `night` are the Earth's pictures, which the realistic Earth lays tiles over; `clouds` and `water` are the door's for the whole-Earth layers they are, which the package does not tile or draw yet.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import type { MapLayer } from "@johnmorrisdotca/chikyu-earth/door";
|
|
9
|
+
*
|
|
10
|
+
* const layers: MapLayer[] = ["day", "night", "clouds", "water"];
|
|
11
|
+
* console.log(layers.join(", "));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type MapLayer = "day" | "night" | "clouds" | "water";
|
|
15
|
+
/**
|
|
16
|
+
* The place a map source is asked about: the family's `MapPlace` in degrees (longitude from `lonMin` to `lonMax`, which may pass 180 and is at most a whole turn, latitude from `latMin` to `latMax`), and the layer it is for.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import type { EarthMapPlace } from "@johnmorrisdotca/chikyu-earth/door";
|
|
21
|
+
*
|
|
22
|
+
* const place: EarthMapPlace = { lonMin: 170, lonMax: 190, latMin: -10, latMax: 10, layer: "day" };
|
|
23
|
+
* console.log(place.layer);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export type EarthMapPlace = MapPlace & {
|
|
27
|
+
layer?: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A source of the Earth's map in tiles for one layer (or every layer of a folder): a `TileSource` of the family's map shape (the place is a `MapPlace`, the detail is the pixels across the whole circumference, a tile is an
|
|
31
|
+
* `ImageTile`) that says which `layer` it is for. A `layer` of `"*"` is every layer of a folder (the place then names the one, in `place.layer`, and the keys start with its name). The keys a source returns end in
|
|
32
|
+
* `level/column/row` on the package's pyramid. `levels` says which levels the source has when that has to be asked (a folder's manifest); left out, levels 3 and 4.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import type { EarthMapSource } from "@johnmorrisdotca/chikyu-earth/door";
|
|
37
|
+
*
|
|
38
|
+
* const layers = (sources: readonly EarthMapSource[]): string[] => sources.map((source) => source.layer);
|
|
39
|
+
* console.log(layers([]));
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export type EarthMapSource = TileSource<EarthMapPlace, number, ImageTile> & {
|
|
43
|
+
layer: MapLayer | "*";
|
|
44
|
+
levels?(layer: string, signal: AbortSignal): TileLayer | undefined | Promise<TileLayer | undefined>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The levels a source has when it does not say: levels 3 and 4 (8192 and 16384 pixels across), the two the package's cutter makes beyond its own 4096 pixel picture.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { DEFAULT_LEVELS } from "@johnmorrisdotca/chikyu-earth/door";
|
|
52
|
+
*
|
|
53
|
+
* console.log(DEFAULT_LEVELS.levels.map((level) => level.width));
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare const DEFAULT_LEVELS: TileLayer;
|
|
57
|
+
/**
|
|
58
|
+
* The level, column and row a tile key ends in, or `undefined` for a key that does not end in three numbers.
|
|
59
|
+
*
|
|
60
|
+
* @param key - The tile's key.
|
|
61
|
+
* @returns Where the tile is in the pyramid, or `undefined` for a key that does not end in three numbers.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { tileKeyParts } from "@johnmorrisdotca/chikyu-earth/door";
|
|
66
|
+
*
|
|
67
|
+
* console.log(tileKeyParts("day/3/12/5"));
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function tileKeyParts(key: string): TileId | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* The place a tile covers, in degrees: what a view asks a source about to get that tile's key.
|
|
73
|
+
*
|
|
74
|
+
* @param tile - A tile of the pyramid.
|
|
75
|
+
* @returns The tile's longitude and latitude bounds.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { tilePlace } from "@johnmorrisdotca/chikyu-earth/door";
|
|
80
|
+
*
|
|
81
|
+
* console.log(tilePlace({ level: 3, col: 0, row: 0 }));
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function tilePlace(tile: TileId): MapPlace;
|
|
85
|
+
/**
|
|
86
|
+
* The keys of the tiles that cover a place at a detail, on the package's pyramid: the level is the lowest whose width is at least `detail` pixels round (or the finest there is), and the tiles are every one the place touches.
|
|
87
|
+
* Pure. A source of your own can build its `need` on it.
|
|
88
|
+
*
|
|
89
|
+
* @param place - The part of the map, in degrees.
|
|
90
|
+
* @param detail - The pixels across the whole circumference wanted.
|
|
91
|
+
* @param layer - The levels the source has; `DEFAULT_LEVELS` where left out.
|
|
92
|
+
* @param prefix - Put before each key (`"day/"`), for a folder of several layers.
|
|
93
|
+
* @returns The keys, `[<prefix>]level/column/row`, row by row; none for a place with no area.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { mapKeys } from "@johnmorrisdotca/chikyu-earth/door";
|
|
98
|
+
*
|
|
99
|
+
* console.log(mapKeys({ lonMin: -10, lonMax: 10, latMin: -5, latMax: 5 }, 8192));
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function mapKeys(place: MapPlace, detail: number, layer?: TileLayer, prefix?: string): string[];
|
|
103
|
+
/**
|
|
104
|
+
* What `earthTiles` takes.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* import type { EarthTilesOptions } from "@johnmorrisdotca/chikyu-earth/door";
|
|
109
|
+
*
|
|
110
|
+
* const options: EarthTilesOptions = { fetch: (url, init) => fetch(url, init) };
|
|
111
|
+
* console.log(typeof options.fetch);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export interface EarthTilesOptions {
|
|
115
|
+
/** The `fetch` to use: the global one where left out. It is called as `fetch(address, { mode: "cors", signal })`. */
|
|
116
|
+
fetch?: (url: string, init?: RequestInit) => Promise<Response>;
|
|
117
|
+
/** Makes a picture of a tile's bytes: `createImageBitmap` where left out. */
|
|
118
|
+
decode?: (blob: Blob) => Promise<BitmapLike>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* What a decoded picture holds in memory, with its mipmaps (4/3 of its bytes): the `bytes` of a map source.
|
|
122
|
+
*
|
|
123
|
+
* @param tile - The tile.
|
|
124
|
+
* @returns Bytes.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { imageBytes } from "@johnmorrisdotca/chikyu-earth/door";
|
|
129
|
+
*
|
|
130
|
+
* console.log(imageBytes({ width: 512, height: 512, image: { width: 512, height: 512 } }));
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function imageBytes(tile: ImageTile): number;
|
|
134
|
+
/**
|
|
135
|
+
* The package's own finer map tiles as a source: a folder with a `manifest.json` and a tile for each layer, level and place at `<layer>/<level>/<column>/<row>.webp` (made by `scripts/make-earth-tiles.py`). This is what the `tiles`
|
|
136
|
+
* attribute of `<chikyu-earth-realistic>` means, and what the Earth is drawn from where no source of yours covers a layer. It is for every layer in the folder (`layer: "*"`); the manifest says which levels each has, and it is read once
|
|
137
|
+
* for the source, only when a view first wants more than the 4096 pixel picture. Its `id` is `chikyu-tiles`, and a view counts it as the package's own data.
|
|
138
|
+
*
|
|
139
|
+
* @param base - The folder's address, with or without the closing slash.
|
|
140
|
+
* @param options - The `fetch` and the decoder to use.
|
|
141
|
+
* @returns The source.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts no-run
|
|
145
|
+
* import { earthTiles } from "@johnmorrisdotca/chikyu-earth/door";
|
|
146
|
+
*
|
|
147
|
+
* const mine = earthTiles("/tiles/");
|
|
148
|
+
* console.log(mine.need({ lonMin: 0, lonMax: 20, latMin: 0, latMax: 10, layer: "day" }, 8192));
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function earthTiles(base: string, options?: EarthTilesOptions): EarthMapSource;
|
|
152
|
+
/**
|
|
153
|
+
* The folder source of an address, the same object each time: what an element makes of its `tiles` attribute, so that two elements on a page with the same folder share one source and its pictures.
|
|
154
|
+
*
|
|
155
|
+
* @param base - The folder's address.
|
|
156
|
+
* @returns The source `earthTiles` makes for it.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts no-run
|
|
160
|
+
* import { folderSource } from "@johnmorrisdotca/chikyu-earth/door";
|
|
161
|
+
*
|
|
162
|
+
* console.log(folderSource("/tiles/") === folderSource("/tiles/"));
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare function folderSource(base: string): EarthMapSource;
|