@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
package/dist/door/map.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { parseManifest, tileColumns, tileRows } from "../realistic/tiles.js";
|
|
2
|
+
import { OWN_BY_ID, madeHere } from "./own.js";
|
|
3
|
+
const RAD = Math.PI / 180;
|
|
4
|
+
const TAU = Math.PI * 2;
|
|
5
|
+
/** A tile's own edge is not the next tile: places are measured to a billionth of a tile. */
|
|
6
|
+
const EDGE = 1e-9;
|
|
7
|
+
/**
|
|
8
|
+
* 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.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { DEFAULT_LEVELS } from "@johnmorrisdotca/chikyu-earth/door";
|
|
13
|
+
*
|
|
14
|
+
* console.log(DEFAULT_LEVELS.levels.map((level) => level.width));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_LEVELS = Object.freeze({ tileSize: 512, levels: Object.freeze([3, 4].map((level) => ({ level, width: 1024 * 2 ** level }))) });
|
|
18
|
+
const KEY_END = /(\d+)\/(\d+)\/(\d+)$/;
|
|
19
|
+
/**
|
|
20
|
+
* The level, column and row a tile key ends in, or `undefined` for a key that does not end in three numbers.
|
|
21
|
+
*
|
|
22
|
+
* @param key - The tile's key.
|
|
23
|
+
* @returns Where the tile is in the pyramid, or `undefined` for a key that does not end in three numbers.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { tileKeyParts } from "@johnmorrisdotca/chikyu-earth/door";
|
|
28
|
+
*
|
|
29
|
+
* console.log(tileKeyParts("day/3/12/5"));
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function tileKeyParts(key) {
|
|
33
|
+
const found = KEY_END.exec(key);
|
|
34
|
+
return found === null ? undefined : { level: Number(found[1]), col: Number(found[2]), row: Number(found[3]) };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The place a tile covers, in degrees: what a view asks a source about to get that tile's key.
|
|
38
|
+
*
|
|
39
|
+
* @param tile - A tile of the pyramid.
|
|
40
|
+
* @returns The tile's longitude and latitude bounds.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { tilePlace } from "@johnmorrisdotca/chikyu-earth/door";
|
|
45
|
+
*
|
|
46
|
+
* console.log(tilePlace({ level: 3, col: 0, row: 0 }));
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function tilePlace(tile) {
|
|
50
|
+
const columns = tileColumns(tile.level);
|
|
51
|
+
const rows = tileRows(tile.level);
|
|
52
|
+
return { lonMin: -180 + (360 * tile.col) / columns, lonMax: -180 + (360 * (tile.col + 1)) / columns, latMax: 90 - (180 * tile.row) / rows, latMin: 90 - (180 * (tile.row + 1)) / rows };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 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.
|
|
56
|
+
* Pure. A source of your own can build its `need` on it.
|
|
57
|
+
*
|
|
58
|
+
* @param place - The part of the map, in degrees.
|
|
59
|
+
* @param detail - The pixels across the whole circumference wanted.
|
|
60
|
+
* @param layer - The levels the source has; `DEFAULT_LEVELS` where left out.
|
|
61
|
+
* @param prefix - Put before each key (`"day/"`), for a folder of several layers.
|
|
62
|
+
* @returns The keys, `[<prefix>]level/column/row`, row by row; none for a place with no area.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { mapKeys } from "@johnmorrisdotca/chikyu-earth/door";
|
|
67
|
+
*
|
|
68
|
+
* console.log(mapKeys({ lonMin: -10, lonMax: 10, latMin: -5, latMax: 5 }, 8192));
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function mapKeys(place, detail, layer = DEFAULT_LEVELS, prefix = "") {
|
|
72
|
+
if (layer.levels.length === 0 || !(place.lonMax > place.lonMin) || !(place.latMax >= place.latMin))
|
|
73
|
+
return [];
|
|
74
|
+
const level = layer.levels.find((one) => one.width >= detail) ?? layer.levels[layer.levels.length - 1];
|
|
75
|
+
const columns = tileColumns(level.level);
|
|
76
|
+
const rows = tileRows(level.level);
|
|
77
|
+
const span = Math.min(TAU, (place.lonMax - place.lonMin) * RAD);
|
|
78
|
+
const first = Math.floor(((place.lonMin * RAD) / TAU + 0.5) * columns + EDGE);
|
|
79
|
+
const count = span >= TAU - 1e-9 ? columns : Math.min(columns, Math.ceil(((place.lonMin * RAD + span) / TAU + 0.5) * columns - EDGE) - first);
|
|
80
|
+
const row0 = Math.max(0, Math.floor((0.5 - (place.latMax * RAD) / Math.PI) * rows + EDGE));
|
|
81
|
+
const row1 = Math.min(rows, Math.max(row0 + 1, Math.ceil((0.5 - (place.latMin * RAD) / Math.PI) * rows - EDGE)));
|
|
82
|
+
const keys = [];
|
|
83
|
+
for (let row = row0; row < row1; row += 1)
|
|
84
|
+
for (let i = 0; i < count; i += 1)
|
|
85
|
+
keys.push(`${prefix}${level.level}/${(((first + i) % columns) + columns) % columns}/${row}`);
|
|
86
|
+
return keys;
|
|
87
|
+
}
|
|
88
|
+
const slash = (base) => (base.endsWith("/") ? base : `${base}/`);
|
|
89
|
+
/**
|
|
90
|
+
* What a decoded picture holds in memory, with its mipmaps (4/3 of its bytes): the `bytes` of a map source.
|
|
91
|
+
*
|
|
92
|
+
* @param tile - The tile.
|
|
93
|
+
* @returns Bytes.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { imageBytes } from "@johnmorrisdotca/chikyu-earth/door";
|
|
98
|
+
*
|
|
99
|
+
* console.log(imageBytes({ width: 512, height: 512, image: { width: 512, height: 512 } }));
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export function imageBytes(tile) {
|
|
103
|
+
return Math.ceil(tile.width * tile.height * 4 * (4 / 3));
|
|
104
|
+
}
|
|
105
|
+
const folders = new Map();
|
|
106
|
+
/**
|
|
107
|
+
* 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`
|
|
108
|
+
* 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
|
|
109
|
+
* 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.
|
|
110
|
+
*
|
|
111
|
+
* @param base - The folder's address, with or without the closing slash.
|
|
112
|
+
* @param options - The `fetch` and the decoder to use.
|
|
113
|
+
* @returns The source.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts no-run
|
|
117
|
+
* import { earthTiles } from "@johnmorrisdotca/chikyu-earth/door";
|
|
118
|
+
*
|
|
119
|
+
* const mine = earthTiles("/tiles/");
|
|
120
|
+
* console.log(mine.need({ lonMin: 0, lonMax: 20, latMin: 0, latMax: 10, layer: "day" }, 8192));
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export function earthTiles(base, options = {}) {
|
|
124
|
+
const folder = slash(base);
|
|
125
|
+
const get = options.fetch ?? ((url, init) => globalThis.fetch(url, init));
|
|
126
|
+
const decode = options.decode ?? ((blob) => createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }));
|
|
127
|
+
let manifest;
|
|
128
|
+
const source = {
|
|
129
|
+
kind: "tiles",
|
|
130
|
+
layer: "*",
|
|
131
|
+
info: OWN_BY_ID.get("chikyu-tiles"),
|
|
132
|
+
need(place, detail) {
|
|
133
|
+
const layer = place.layer;
|
|
134
|
+
if (typeof layer !== "string" || layer === "")
|
|
135
|
+
throw new RangeError("a folder of tiles is asked for a place with its layer");
|
|
136
|
+
return mapKeys(place, detail, DEFAULT_LEVELS, `${layer}/`);
|
|
137
|
+
},
|
|
138
|
+
async levels(layer) {
|
|
139
|
+
// read once: a folder that cannot be read is not asked again by this source, so a view at rest sends nothing
|
|
140
|
+
const asked = (manifest ??= get(`${folder}manifest.json`, { mode: "cors" }).then(async (response) => (response.ok ? parseManifest(await response.json().catch(() => undefined))?.layers : undefined), () => undefined));
|
|
141
|
+
const layers = await asked;
|
|
142
|
+
// an answer that was no folder is not kept: the next view of it (a changed source, a new element) asks again, and a view at rest never does
|
|
143
|
+
if (layers === undefined && manifest === asked)
|
|
144
|
+
manifest = undefined;
|
|
145
|
+
return layers?.[layer];
|
|
146
|
+
},
|
|
147
|
+
async load(key, signal) {
|
|
148
|
+
if (tileKeyParts(key) === undefined)
|
|
149
|
+
throw new RangeError(`"${key}" is not the key of a tile`);
|
|
150
|
+
const response = await get(`${folder}${key}.webp`, { mode: "cors", signal });
|
|
151
|
+
if (!response.ok)
|
|
152
|
+
throw new Error(`The tile ${key} could not be fetched (${response.status})`);
|
|
153
|
+
const image = await decode(await response.blob());
|
|
154
|
+
return { width: image.width > 0 ? image.width : 512, height: image.height > 0 ? image.height : 512, image };
|
|
155
|
+
},
|
|
156
|
+
bytes: (tile) => imageBytes(tile),
|
|
157
|
+
};
|
|
158
|
+
madeHere(source);
|
|
159
|
+
return source;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 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.
|
|
163
|
+
*
|
|
164
|
+
* @param base - The folder's address.
|
|
165
|
+
* @returns The source `earthTiles` makes for it.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts no-run
|
|
169
|
+
* import { folderSource } from "@johnmorrisdotca/chikyu-earth/door";
|
|
170
|
+
*
|
|
171
|
+
* console.log(folderSource("/tiles/") === folderSource("/tiles/"));
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export function folderSource(base) {
|
|
175
|
+
const folder = slash(base);
|
|
176
|
+
let held = folders.get(folder);
|
|
177
|
+
if (held === undefined) {
|
|
178
|
+
held = earthTiles(folder);
|
|
179
|
+
folders.set(folder, held);
|
|
180
|
+
}
|
|
181
|
+
return held;
|
|
182
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Credit, SourceInfo } from "../data-door.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The package's own data, as sources, written from the rows of `NOTICE.md`: `chikyu-pictures` (the whole-Earth pictures of the realistic Earth: day, night, clouds and water) and `chikyu-tiles` (the finer map tiles cut from NASA's bigger maps).
|
|
4
|
+
* A test holds that none is non-commercial or share-alike, so the package can pass all of it on under the MIT licence. A view's credit line is written from these and from the sources a caller handed in.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { OWN_SOURCES } from "@johnmorrisdotca/chikyu-earth/door";
|
|
9
|
+
*
|
|
10
|
+
* console.log(OWN_SOURCES.map((source) => `${source.id}: ${source.licence.name}`));
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const OWN_SOURCES: readonly SourceInfo[];
|
|
14
|
+
/** The rows of `OWN_SOURCES` by id. */
|
|
15
|
+
export declare const OWN_BY_ID: ReadonlyMap<string, SourceInfo>;
|
|
16
|
+
/** Marks a source object as made by this package. */
|
|
17
|
+
export declare function madeHere<T extends object>(source: T): T;
|
|
18
|
+
/** True for a source object this package made (`earthTiles`), false for any other. */
|
|
19
|
+
export declare const isOwnSource: (source: object) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The credit of one of the package's own sources, for a page that draws something itself: the elements credit their own pictures and tiles in `credits()`, and a page that draws the Earth from the package's pictures
|
|
22
|
+
* puts `ownCredit("chikyu-pictures", 1)` in its credit line.
|
|
23
|
+
*
|
|
24
|
+
* @param id - `chikyu-pictures` or `chikyu-tiles`.
|
|
25
|
+
* @param used - How many marks were drawn from it.
|
|
26
|
+
* @returns The credit, marked as the package's own.
|
|
27
|
+
* @throws RangeError for an id that is not one of `OWN_SOURCES`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { creditLine, ownCredit } from "@johnmorrisdotca/chikyu-earth/door";
|
|
32
|
+
*
|
|
33
|
+
* console.log(creditLine([ownCredit("chikyu-tiles", 6)], "en"));
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function ownCredit(id: string, used: number): Credit;
|
package/dist/door/own.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const NOTICE = "https://github.com/johnmorrisdotca/chikyu-earth/blob/main/NOTICE.md";
|
|
2
|
+
function freeze(value) {
|
|
3
|
+
if (typeof value === "object" && value !== null)
|
|
4
|
+
for (const inner of Object.values(value))
|
|
5
|
+
freeze(inner);
|
|
6
|
+
return Object.freeze(value);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The package's own data, as sources, written from the rows of `NOTICE.md`: `chikyu-pictures` (the whole-Earth pictures of the realistic Earth: day, night, clouds and water) and `chikyu-tiles` (the finer map tiles cut from NASA's bigger maps).
|
|
10
|
+
* A test holds that none is non-commercial or share-alike, so the package can pass all of it on under the MIT licence. A view's credit line is written from these and from the sources a caller handed in.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { OWN_SOURCES } from "@johnmorrisdotca/chikyu-earth/door";
|
|
15
|
+
*
|
|
16
|
+
* console.log(OWN_SOURCES.map((source) => `${source.id}: ${source.licence.name}`));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const OWN_SOURCES = freeze([
|
|
20
|
+
{
|
|
21
|
+
id: "chikyu-pictures",
|
|
22
|
+
name: { en: "Earth pictures", ja: "地球の画像" },
|
|
23
|
+
credit: {
|
|
24
|
+
en: "Earth pictures: NASA Earth Observatory (Blue Marble, Reto Stöckli; Black Marble, Suomi NPP VIIRS data)",
|
|
25
|
+
ja: "地球の画像:NASA Earth Observatory(ブルーマーブル、Reto Stöckli/ブラックマーブル、Suomi NPP VIIRSデータ)",
|
|
26
|
+
},
|
|
27
|
+
licence: { name: "Public domain", url: `${NOTICE}#the-realistic-earths-pictures` },
|
|
28
|
+
url: "https://github.com/johnmorrisdotca/chikyu-earth/tree/main/textures",
|
|
29
|
+
retrieved: "2026-11-02",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: "chikyu-tiles",
|
|
33
|
+
name: { en: "Finer map tiles", ja: "細かい地図のタイル" },
|
|
34
|
+
credit: {
|
|
35
|
+
en: "Finer map tiles: NASA Earth Observatory (Blue Marble: Next Generation; Black Marble, Suomi NPP VIIRS data), cut by Chikyu Earth",
|
|
36
|
+
ja: "細かい地図のタイル:NASA Earth Observatory(ブルーマーブル・ネクストジェネレーション/ブラックマーブル、Suomi NPP VIIRSデータ)、Chikyu Earthで切り出したもの",
|
|
37
|
+
},
|
|
38
|
+
licence: { name: "Public domain", url: `${NOTICE}#the-earth-tiles` },
|
|
39
|
+
url: "https://johnmorrisdotca.github.io/chikyu-earth/tiles/",
|
|
40
|
+
retrieved: "2026-11-08",
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
43
|
+
/** The rows of `OWN_SOURCES` by id. */
|
|
44
|
+
export const OWN_BY_ID = new Map(OWN_SOURCES.map((source) => [source.id, source]));
|
|
45
|
+
/** The source objects this package made itself: only these are its own, whatever id a caller's source gives itself. */
|
|
46
|
+
const MADE_HERE = new WeakSet();
|
|
47
|
+
/** Marks a source object as made by this package. */
|
|
48
|
+
export function madeHere(source) {
|
|
49
|
+
MADE_HERE.add(source);
|
|
50
|
+
return source;
|
|
51
|
+
}
|
|
52
|
+
/** True for a source object this package made (`earthTiles`), false for any other. */
|
|
53
|
+
export const isOwnSource = (source) => MADE_HERE.has(source);
|
|
54
|
+
/**
|
|
55
|
+
* The credit of one of the package's own sources, for a page that draws something itself: the elements credit their own pictures and tiles in `credits()`, and a page that draws the Earth from the package's pictures
|
|
56
|
+
* puts `ownCredit("chikyu-pictures", 1)` in its credit line.
|
|
57
|
+
*
|
|
58
|
+
* @param id - `chikyu-pictures` or `chikyu-tiles`.
|
|
59
|
+
* @param used - How many marks were drawn from it.
|
|
60
|
+
* @returns The credit, marked as the package's own.
|
|
61
|
+
* @throws RangeError for an id that is not one of `OWN_SOURCES`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { creditLine, ownCredit } from "@johnmorrisdotca/chikyu-earth/door";
|
|
66
|
+
*
|
|
67
|
+
* console.log(creditLine([ownCredit("chikyu-tiles", 6)], "en"));
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export function ownCredit(id, used) {
|
|
71
|
+
const source = OWN_BY_ID.get(id);
|
|
72
|
+
if (source === undefined)
|
|
73
|
+
throw new RangeError(`"${id}" is not one of the package's own sources`);
|
|
74
|
+
return { source, own: true, used };
|
|
75
|
+
}
|
package/dist/passes/element.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ElementSet } from "../satellites/types.ts";
|
|
2
|
+
import { type Credit, type DataSource } from "../data-door.ts";
|
|
2
3
|
import { type SatellitePass } from "./passes.ts";
|
|
3
4
|
type Lang = "en" | "ja";
|
|
4
5
|
/**
|
|
@@ -26,6 +27,23 @@ export declare class ChikyuPasses extends HTMLElement {
|
|
|
26
27
|
/** The orbit data the passes are worked out from. Setting it works the passes out again. */
|
|
27
28
|
get elements(): readonly ElementSet[];
|
|
28
29
|
set elements(sets: readonly ElementSet[]);
|
|
30
|
+
/**
|
|
31
|
+
* The outside sources of orbital elements (the data door): each carries its own licence and credit (`elementsFrom` makes one of an address), is read once when it is added, and its sets are worked out with the page's own.
|
|
32
|
+
* Assign a list to replace them; a source that is refused throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
33
|
+
*/
|
|
34
|
+
get sources(): readonly DataSource[];
|
|
35
|
+
set sources(list: readonly unknown[]);
|
|
36
|
+
/** Adds a source of orbital elements: checked at once (a `TypeError` for one that is refused). Returns the function that takes it away. */
|
|
37
|
+
addSource(source: unknown): () => void;
|
|
38
|
+
/** Takes a source away by its id. Returns whether there was one. */
|
|
39
|
+
removeSource(id: string): boolean;
|
|
40
|
+
/** Switches a source off (`false`) or on again, and keeps it in the element. The attribute `data="own"` ignores every outside source at once. */
|
|
41
|
+
enableSource(id: string, on: boolean): void;
|
|
42
|
+
/**
|
|
43
|
+
* Whose orbit data is in the list now: each source of the data door that gave a satellite to a pass listed, with how many satellites (`used`). `creditLine(credits, "en" | "ja")` from `@johnmorrisdotca/chikyu-earth/door` writes them
|
|
44
|
+
* as a line with the licences, and the element shows that line under the list (after the text of the `credit` attribute, which stays). `chikyu-creditschange` fires when this set changes, with `detail: { credits }`.
|
|
45
|
+
*/
|
|
46
|
+
credits(): Credit[];
|
|
29
47
|
/** The passes listed now, earliest first. */
|
|
30
48
|
get passes(): readonly SatellitePass[];
|
|
31
49
|
/** The pass pressed, or undefined. */
|
package/dist/passes/element.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// Nothing runs on a timer: it works the passes out when something it shows changes, and reads the clock once, when it first comes into a page (or never, when `from` is given).
|
|
3
3
|
import { adoptStyles } from "../adopt.js";
|
|
4
4
|
import { fetchElements } from "../satellites/source.js";
|
|
5
|
+
import { creditLine } from "../data-door.js";
|
|
6
|
+
import { createDoorHost } from "../door/host.js";
|
|
7
|
+
import { mergeElementSets } from "../door/elements.js";
|
|
5
8
|
import { DEFAULT_DIM_AFTER_DAYS } from "../satellites/limits.js";
|
|
6
9
|
import { findPasses, passPath } from "./passes.js";
|
|
7
10
|
import { skySvg } from "./sky.js";
|
|
@@ -169,8 +172,14 @@ const number = (value, fallback) => (value === null || value.trim() === "" || !N
|
|
|
169
172
|
* ```
|
|
170
173
|
*/
|
|
171
174
|
export class ChikyuPasses extends HTMLElement {
|
|
172
|
-
static observedAttributes = ["latitude", "longitude", "height", "days", "show", "sky", "satellite", "from", "min-altitude", "lang", "time-zone", "utc-offset", "selected", "elements-src", "credit"];
|
|
175
|
+
static observedAttributes = ["latitude", "longitude", "height", "days", "show", "sky", "satellite", "from", "min-altitude", "lang", "time-zone", "utc-offset", "selected", "elements-src", "credit", "data"];
|
|
173
176
|
#sets = [];
|
|
177
|
+
/** The element sets the passes are worked out from: the page's own (`elements`, `elements-src`) and those of the sources of the data door, one set a satellite, the newest epoch winning. */
|
|
178
|
+
#all = [];
|
|
179
|
+
/** Which source each satellite's set came from (`null`: the page's own sets), by NORAD number. */
|
|
180
|
+
#origin = new Map();
|
|
181
|
+
/** The data door: the outside sources of orbital elements, and whose data is on the screen. */
|
|
182
|
+
#door = createDoorHost(this, { own: () => [], used: () => this.#used() }, { kinds: ["records"] }, () => this.#schedule());
|
|
174
183
|
#passes = [];
|
|
175
184
|
#chosen;
|
|
176
185
|
#problem = "";
|
|
@@ -190,6 +199,49 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
190
199
|
this.#problem = "";
|
|
191
200
|
this.#schedule();
|
|
192
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* The outside sources of orbital elements (the data door): each carries its own licence and credit (`elementsFrom` makes one of an address), is read once when it is added, and its sets are worked out with the page's own.
|
|
204
|
+
* Assign a list to replace them; a source that is refused throws a `TypeError` and nothing changes. A property, never an attribute: data is not text.
|
|
205
|
+
*/
|
|
206
|
+
get sources() {
|
|
207
|
+
return this.#door.sources();
|
|
208
|
+
}
|
|
209
|
+
set sources(list) {
|
|
210
|
+
this.#door.setSources(list);
|
|
211
|
+
}
|
|
212
|
+
/** Adds a source of orbital elements: checked at once (a `TypeError` for one that is refused). Returns the function that takes it away. */
|
|
213
|
+
addSource(source) {
|
|
214
|
+
return this.#door.book.addSource(source);
|
|
215
|
+
}
|
|
216
|
+
/** Takes a source away by its id. Returns whether there was one. */
|
|
217
|
+
removeSource(id) {
|
|
218
|
+
return this.#door.book.removeSource(id);
|
|
219
|
+
}
|
|
220
|
+
/** Switches a source off (`false`) or on again, and keeps it in the element. The attribute `data="own"` ignores every outside source at once. */
|
|
221
|
+
enableSource(id, on) {
|
|
222
|
+
this.#door.book.enableSource(id, on);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Whose orbit data is in the list now: each source of the data door that gave a satellite to a pass listed, with how many satellites (`used`). `creditLine(credits, "en" | "ja")` from `@johnmorrisdotca/chikyu-earth/door` writes them
|
|
226
|
+
* as a line with the licences, and the element shows that line under the list (after the text of the `credit` attribute, which stays). `chikyu-creditschange` fires when this set changes, with `detail: { credits }`.
|
|
227
|
+
*/
|
|
228
|
+
credits() {
|
|
229
|
+
return this.#door.credits();
|
|
230
|
+
}
|
|
231
|
+
/** How many satellites of the passes listed came from each source of the door, by id. */
|
|
232
|
+
#used() {
|
|
233
|
+
const seen = new Set();
|
|
234
|
+
const used = new Map();
|
|
235
|
+
for (const pass of this.#passes) {
|
|
236
|
+
if (seen.has(pass.noradId))
|
|
237
|
+
continue;
|
|
238
|
+
seen.add(pass.noradId);
|
|
239
|
+
const id = this.#origin.get(pass.noradId);
|
|
240
|
+
if (id !== null && id !== undefined)
|
|
241
|
+
used.set(id, (used.get(id) ?? 0) + 1);
|
|
242
|
+
}
|
|
243
|
+
return used;
|
|
244
|
+
}
|
|
193
245
|
/** The passes listed now, earliest first. */
|
|
194
246
|
get passes() {
|
|
195
247
|
return this.#passes;
|
|
@@ -216,12 +268,15 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
216
268
|
connectedCallback() {
|
|
217
269
|
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
218
270
|
adoptStyles(root, CSS, this.getAttribute("nonce") ?? "");
|
|
271
|
+
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
219
272
|
this.#load();
|
|
220
273
|
this.#schedule();
|
|
221
274
|
}
|
|
222
275
|
attributeChangedCallback(name) {
|
|
223
276
|
if (!this.isConnected)
|
|
224
277
|
return;
|
|
278
|
+
if (name === "data")
|
|
279
|
+
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
225
280
|
if (name === "elements-src")
|
|
226
281
|
this.#load();
|
|
227
282
|
this.#schedule();
|
|
@@ -326,8 +381,13 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
326
381
|
holder.innerHTML = `<p class="empty" role="status">${escape(say("unreadable", { why: this.#problem }))}</p>`;
|
|
327
382
|
return;
|
|
328
383
|
}
|
|
384
|
+
const lists = this.#door.book.elementLists();
|
|
385
|
+
// with no source the page's own sets are used as they are, every one
|
|
386
|
+
const merged = lists.length === 0 ? this.#sets.map((set) => ({ set, id: null })) : mergeElementSets([{ id: null, sets: this.#sets }, ...lists]);
|
|
387
|
+
this.#all = merged.map((one) => one.set);
|
|
388
|
+
this.#origin = new Map(merged.map((one) => [one.set.NORAD_CAT_ID, one.id]));
|
|
329
389
|
const chosenSet = this.getAttribute("satellite");
|
|
330
|
-
const sets = chosenSet ? this.#
|
|
390
|
+
const sets = chosenSet ? this.#all.filter((one) => String(one.NORAD_CAT_ID) === chosenSet) : this.#all;
|
|
331
391
|
if (this.#waiting && sets.length === 0) {
|
|
332
392
|
holder.innerHTML = `<p class="empty" role="status">${escape(say("waiting"))}</p>`;
|
|
333
393
|
return;
|
|
@@ -363,7 +423,8 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
363
423
|
ages.set(pass.noradId, pass);
|
|
364
424
|
const oldest = Math.max(0, ...[...ages.values()].map((one) => one.elementAgeDays));
|
|
365
425
|
const note = `<p class="note">${escape(f.zone)} ${escape(say("reboost"))}${oldest > DEFAULT_DIM_AFTER_DAYS ? ` ${escape(say("stale"))}${lang === "ja" ? "。" : "."}` : ""}</p>`;
|
|
366
|
-
|
|
426
|
+
// the `credit` attribute stays as the page's own words; the sources of the door add their credit line, with the licences, after it
|
|
427
|
+
const credit = [this.getAttribute("credit") ?? "", creditLine(this.#door.credits(), lang)].filter((part) => part.trim() !== "").join(" ");
|
|
367
428
|
const list = this.#passes.length === 0 ? `<p class="empty" role="status">${escape(say(all ? "noneAll" : "none", { days }))}</p>` : `<ul class="list" aria-label="${escape(say("list"))}">${rows}</ul>`;
|
|
368
429
|
holder.innerHTML = `${note}<div class="layout"><div>${list}</div><div class="detail">${this.#chosen ? this.#detail(this.#chosen, f, say, lang) : ""}</div></div>${credit ? `<p class="credit">${escape(credit)}</p>` : ""}`;
|
|
369
430
|
this.dispatchEvent(new CustomEvent("chikyu-passes", { detail: { passes: this.#passes, ageDays: oldest }, bubbles: true, composed: true }));
|
|
@@ -371,11 +432,12 @@ export class ChikyuPasses extends HTMLElement {
|
|
|
371
432
|
const shown = this.#chosen?.highest.ms;
|
|
372
433
|
if (shown !== this.#announced) {
|
|
373
434
|
this.#announced = shown;
|
|
374
|
-
this.dispatchEvent(new CustomEvent("chikyu-pass-select", { detail: { pass: this.#chosen, set: this.#chosen ? this.#
|
|
435
|
+
this.dispatchEvent(new CustomEvent("chikyu-pass-select", { detail: { pass: this.#chosen, set: this.#chosen ? this.#all.find((one) => one.NORAD_CAT_ID === this.#chosen.noradId) : undefined }, bubbles: true, composed: true }));
|
|
375
436
|
}
|
|
437
|
+
this.#door.announce();
|
|
376
438
|
}
|
|
377
439
|
#detail(pass, f, say, lang) {
|
|
378
|
-
const set = this.#
|
|
440
|
+
const set = this.#all.find((one) => one.NORAD_CAT_ID === pass.noradId);
|
|
379
441
|
const place = { latitude: number(this.getAttribute("latitude"), 0), longitude: number(this.getAttribute("longitude"), 0), heightM: number(this.getAttribute("height"), 0) };
|
|
380
442
|
const short = SHORT[pass.noradId]?.[lang] ?? pass.name;
|
|
381
443
|
const labels = { north: say("skyN"), east: say("skyE"), south: say("skyS"), west: say("skyW"), start: say("skyStart"), highest: say("skyHighest"), end: say("skyEnd"), zenith: say("skyZenith") };
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
* 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
|
+
* 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.
|
|
89
|
+
*
|
|
90
|
+
* @param url - The font file's address, or `undefined` for the default.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts no-run
|
|
94
|
+
* import { setBodyLabelFontUrl } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
95
|
+
*
|
|
96
|
+
* setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function setBodyLabelFontUrl(url: string | undefined): void;
|
|
100
|
+
/**
|
|
101
|
+
* 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
|
|
102
|
+
* 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.
|
|
103
|
+
*
|
|
104
|
+
* @param three - The page's three.js.
|
|
105
|
+
* @param parent - What turns with the Earth.
|
|
106
|
+
* @param state - The settings and the text, which the element changes.
|
|
107
|
+
* @param deps - `invalidate` asks for a draw; `onError` hears of a label that could not be made.
|
|
108
|
+
* @returns The layer.
|
|
109
|
+
*/
|
|
110
|
+
export declare function createBodyLabelLayer(three: ThreeParts, parent: THREE.Object3D, state: BodyLabelState, deps: {
|
|
111
|
+
invalidate: () => void;
|
|
112
|
+
onError?: (error: unknown) => void;
|
|
113
|
+
}): BodyLabelLayer;
|