@johnmorrisdotca/chikyu-earth 0.29.0 → 0.31.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 +8 -0
- package/NOTICE.md +4 -0
- package/README.md +55 -2
- 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/meteors/index.d.ts +1 -0
- package/dist/meteors/index.js +1 -0
- package/dist/meteors/layer.d.ts +6 -2
- package/dist/meteors/layer.js +26 -9
- package/dist/meteors/strength.d.ts +26 -0
- package/dist/meteors/strength.js +35 -0
- package/dist/passes/element.d.ts +18 -0
- package/dist/passes/element.js +67 -5
- package/dist/realistic/earth.d.ts +5 -3
- package/dist/realistic/earth.js +2 -1
- package/dist/realistic/element.d.ts +27 -0
- package/dist/realistic/element.js +81 -5
- package/dist/realistic/tile-set.d.ts +27 -2
- package/dist/realistic/tile-set.js +155 -49
- package/dist/space/element.d.ts +8 -0
- package/dist/space/element.js +19 -2
- package/package.json +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.31.0 - 2026-11-11
|
|
6
|
+
|
|
7
|
+
- **The data door: sources of your own map and orbit data, with their licence and credit** (MODULES-902, step 3 of MODULES-831). New entry point `@johnmorrisdotca/chikyu-earth/door`: `EarthMapSource` (the Earth's map in tiles for the `day` or `night` layer; the family's `TileSource` of `MapPlace`, `ImageTile`), `earthTiles(base)` (the package's own folder of tiles as a source: what the `tiles` attribute now means), `mapKeys`, `tilePlace`, `tileKeyParts`, `ElementRecordSource` and `elementsFrom(url, info)` (orbit data through `fetchElements`), `createSourceBook`, `OWN_SOURCES` (`chikyu-pictures` and `chikyu-tiles`, written from `NOTICE.md`), `ownCredit`, and the family's `creditLine`, `validateSource`, `loadRecords`, `createTileStore` from `src/data-door.ts`, kazoku-ui's template copied unchanged (a test holds its hash). `<chikyu-earth-realistic>` takes `sources`, `addSource`, `removeSource`, `enableSource`, `data="own"` and `credits()`; `<chikyu-passes>` takes the same for orbit data (the newest epoch of a satellite wins), and its `credit` attribute stays and is followed by the line `credits()` writes, with the licences. `chikyu-creditschange` tells a page when the set of credited sources changes (not at each frame). Off (`remove()`, `enableSource(id, false)`, `data="own"`) aborts a source's loads, frees its tiles and drops its credit. A source is refused at once for an empty credit, no licence, a clashing id (or an id of the package's own) or a layer the Earth does not know; a tile that throws, is not a picture or has a size that is not a number is counted in `stats.tiles.failed` and never drawn. The tiles of a view share one budget, `TILE_BUDGET` (72 MB, the 48 tiles it has always held), and a tile that does not fit is refused and counted (`stats.tiles.refused`). With no source every picture is the same one. Every old attribute and function stays. One change: a tile that could not be fetched is no longer asked for again after 30 seconds; it is asked for again after the view has moved away from it and back, so a view at rest sends nothing. `stats.tiles` gains `heldBytes`, `refused` and `used`. New guide: Outside data, the data door (English and Japanese). The demo's Earth page shows the credit line under the view and reads `?data=own`.
|
|
8
|
+
|
|
9
|
+
## 0.30.0 - 2026-11-11
|
|
10
|
+
|
|
11
|
+
- **A strength setting for the meteors** (MODULES-906). `meteors-strength` (the property `meteorsStrength`) on `<chikyu-earth-realistic>` and `<chikyu-space>` is a number from 0 to 1 that scales how bright each streak is and how many are drawn, so a page can show them subtly. It is 1, the look they have always had, when the page says nothing; a number outside the range is brought to its nearest end and one that is not a number is 1. At 0 no streak is drawn, and the line under the picture, the survey of the sky and `chikyu-meteors` are as they were. Nothing that is real changes at any strength: the hourly rates and the showers' `zhr` are the same, and the line still says the streaks are an illustration. `stats.meteors` gains `strength` (and its `perSecond` is the streaks a second drawn, so it follows the strength). New in `@johnmorrisdotca/chikyu-earth/meteors`: `readMeteorStrength`, `METEOR_STRENGTH_DEFAULT`, and `streaksPerSecond(rate, strength)`. The demo has a Subtle, Medium and Full choice beside the Meteors button (`meteors-strength` in the address). The guide, in English and Japanese, has a section on it.
|
|
12
|
+
|
|
5
13
|
## 0.29.0 - 2026-11-11
|
|
6
14
|
|
|
7
15
|
- **The air is drawn 3 times its real thickness unless a page says otherwise, so the ring can be seen** (MODULES-904). At whole-Earth zoom the true 100 km shell is a line a pixel or two wide, and on a phone thinner than the old painted glow. `air-thickness` (and the property `airThickness`) on `<chikyu-earth-realistic>` and `<chikyu-space>` takes a number from 1 (the true thickness) to 5, and 3 when left out; the shell and the heights over which the air thins grow by it and the air is the same amount, so the physics and the colours do not change. While it is above 1 the element says so in a line under the picture, "The air is drawn 3 times its real thickness so it can be seen." (and in Japanese), which `air-label="off"` takes away. New exports `AIR_THICKNESS_DEFAULT`, `AIR_THICKNESS_MAX`, `readAirThickness`, `airTop` and `AIR_NOTE`. The demo has a True air thickness button on the realistic and space looks and on the full-screen page (`air-thickness=1` in the address). The cost is the same: a draw is the same program with one more uniform. Tests: `test/air.test.ts`, `e2e/air-visible.gl.ts`.
|
package/NOTICE.md
CHANGED
|
@@ -77,6 +77,10 @@ The same build may take a group's element sets from **Space-Track.org** (https:/
|
|
|
77
77
|
|
|
78
78
|
Not from any list, and said so where it is used (`src/meteors/rate.ts`, `src/meteors/layer.ts`, the guide): the sporadic background of 8 meteors an hour, its lean towards the morning side, each shower's curve between its first day, its maximum and its last day, and how many streaks are drawn. The Sun's longitude is Meeus's low-precision formula (as under "Sun position").
|
|
79
79
|
|
|
80
|
+
## The data door
|
|
81
|
+
|
|
82
|
+
`src/data-door.ts` is kazoku-ui's `templates/data-door.ts`, copied unchanged (the same file in every package of the family; MIT, by John Morris). `src/door/own.ts` writes the package's own data as the door's sources from the rows above: `chikyu-pictures` (the whole-Earth pictures, "The realistic Earth's pictures") and `chikyu-tiles` (the finer map tiles, "The Earth tiles"), both NASA Earth Observatory images under the NASA terms quoted there, so "Public domain" with credit; a test holds that neither is non-commercial or share-alike. Any other source is a caller's: it brings its own licence and credit, and the door prints both (and "non-commercial" or "share-alike" where it says so); the package bundles none and ships no data through the door.
|
|
83
|
+
|
|
80
84
|
## Satellite passes
|
|
81
85
|
|
|
82
86
|
`src/passes/` (the `/passes` entry and `<chikyu-passes>`) works out passes with SGP4 by **satellite.js** (see Satellites above), this package's own Sun position (see Sun position above) and a cylinder of the Earth's shadow; the code is this package's own and MIT. The brightness is a model of this package's own: the phase function of a diffuse (Lambertian) sphere, a textbook result, with the standard magnitude (brightness from 1000 km with half of the satellite lit, the convention satellite observers use) worked out from the Sun's apparent magnitude of -26.74 (the IAU's 2015 nominal solar values), an assumed albedo of 0.2 and a rough average cross-section for each of the ISS (2,000 square metres), Tianhe (200) and the Hubble Space Telescope (70). The cross-sections are this package's own rough estimates, made from the sizes the space agencies publish (for the ISS, NASA's "Space Station Facts and Figures" page, read 2026-11-09: solar array length 73 m, wingspan 109 m, truss 94 m); they are not measurements, and no observer's table of standard magnitudes is used or kept.
|
package/README.md
CHANGED
|
@@ -189,7 +189,7 @@ computed in the browser by astronomy-engine (MIT), nothing is fetched. [docs/spa
|
|
|
189
189
|
|
|
190
190
|
## Meteors
|
|
191
191
|
|
|
192
|
-
`<chikyu-earth-realistic meteors>` and `<chikyu-space meteors>` draw meteors as they look from space: short streaks 80 to 120 km up, only on the dark side and in twilight, more of them under an active shower's radiant, and only while the clock runs. Each streak's place and moment are drawn at random, and the element says so under the picture; how many there are, where they fall, their height and the showers' dates are real. The showers are the International Meteor Organization's working list for 2026 (37 of them), in an entry point of its own with the rate functions, which needs no browser: [guide](docs/guides/meteors.md).
|
|
192
|
+
`<chikyu-earth-realistic meteors>` and `<chikyu-space meteors>` draw meteors as they look from space: short streaks 80 to 120 km up, only on the dark side and in twilight, more of them under an active shower's radiant, and only while the clock runs. Each streak's place and moment are drawn at random, and the element says so under the picture; how many there are, where they fall, their height and the showers' dates are real. `meteors-strength` (0 to 1, the property `meteorsStrength`; 1 when you say nothing) makes them subtler: fewer streaks and fainter ones, none at 0, with every real figure unchanged. The showers are the International Meteor Organization's working list for 2026 (37 of them), in an entry point of its own with the rate functions, which needs no browser: [guide](docs/guides/meteors.md).
|
|
193
193
|
|
|
194
194
|
```js
|
|
195
195
|
import { activeShowers } from "@johnmorrisdotca/chikyu-earth/meteors";
|
|
@@ -198,6 +198,57 @@ import { activeShowers } from "@johnmorrisdotca/chikyu-earth/meteors";
|
|
|
198
198
|
for (const { shower, zhr } of activeShowers(Date.UTC(2026, 11, 14, 8))) console.log(`${shower.name}: ${zhr.toFixed(1)} an hour`);
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
+
## Outside data: the data door
|
|
202
|
+
|
|
203
|
+
The package draws; you bring the data. `@johnmorrisdotca/chikyu-earth/door` takes a finer map of the Earth, or a list of satellites' orbit data, as a **source**: a small object that carries its own licence and credit, so the screen can always say whose data it shows. With no source nothing changes: the Earth is drawn from the package's own pictures and tiles (`OWN_SOURCES`, written from `NOTICE.md`, never non-commercial or share-alike). A source of yours may be either, and the credit line prints that beside the licence.
|
|
204
|
+
|
|
205
|
+
```js
|
|
206
|
+
import { createSourceBook, creditLine, mapKeys, mergeElementSets, ownCredit } from "@johnmorrisdotca/chikyu-earth/door";
|
|
207
|
+
|
|
208
|
+
// A map of your own: here a day picture with no pictures behind it, only the keys it would answer. A real one fetches tiles, and says whose they are and under what licence.
|
|
209
|
+
const info = (id, name) => ({
|
|
210
|
+
id,
|
|
211
|
+
name: { en: name, ja: "私のデータ" },
|
|
212
|
+
credit: { en: `${name}, A. Person (2026)`, ja: `私のデータ(A. Person、2026年)` },
|
|
213
|
+
licence: { name: "CC BY-NC 4.0", url: "https://creativecommons.org/licenses/by-nc/4.0/", nonCommercial: true },
|
|
214
|
+
url: "https://example.org/mine",
|
|
215
|
+
retrieved: "2026-11-11",
|
|
216
|
+
});
|
|
217
|
+
const myMap = {
|
|
218
|
+
kind: "tiles",
|
|
219
|
+
layer: "day",
|
|
220
|
+
info: info("my-map", "My map"),
|
|
221
|
+
need: (place, detail) => mapKeys(place, detail, undefined, "mine/"),
|
|
222
|
+
load: async () => ({ width: 512, height: 512, image: { width: 512, height: 512 } }),
|
|
223
|
+
bytes: (tile) => tile.width * tile.height * 4,
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// An element keeps a book like this one: `earth.addSource(myMap)` is `book.addSource(myMap)`, and `passes.addSource(mine)` is the same for orbit data.
|
|
227
|
+
const book = createSourceBook();
|
|
228
|
+
book.addSource(myMap);
|
|
229
|
+
const mine = {
|
|
230
|
+
kind: "records",
|
|
231
|
+
info: info("my-orbits", "My orbits"),
|
|
232
|
+
records: () => [
|
|
233
|
+
{ OBJECT_NAME: "ISS (ZARYA)", EPOCH: "2026-11-10T00:00:00", MEAN_MOTION: 15.49, ECCENTRICITY: 0.0007, INCLINATION: 51.6, RA_OF_ASC_NODE: 335.9, ARG_OF_PERICENTER: 339.3, MEAN_ANOMALY: 20.6, NORAD_CAT_ID: 25544, BSTAR: 0.0001, MEAN_MOTION_DOT: 0.0001, MEAN_MOTION_DDOT: 0 },
|
|
234
|
+
{ OBJECT_NAME: "Broken", EPOCH: "2026-11-10T00:00:00", MEAN_MOTION: Number.NaN, ECCENTRICITY: 0, INCLINATION: 0, RA_OF_ASC_NODE: 0, ARG_OF_PERICENTER: 0, MEAN_ANOMALY: 0, NORAD_CAT_ID: 1, BSTAR: 0, MEAN_MOTION_DOT: 0, MEAN_MOTION_DDOT: 0 },
|
|
235
|
+
],
|
|
236
|
+
};
|
|
237
|
+
book.addSource(mine);
|
|
238
|
+
await book.ready();
|
|
239
|
+
const sets = mergeElementSets(book.elementLists());
|
|
240
|
+
console.log(`${sets.length} element set kept, ${book.stats().records["my-orbits"].skipped} left out: ${sets[0].set.OBJECT_NAME}`);
|
|
241
|
+
console.log(`the day map answers ${book.mapSources("day")[0].need({ lonMin: -10, lonMax: 10, latMin: -5, latMax: 5 }, 8192).join(", ")}`);
|
|
242
|
+
const credits = [ownCredit("chikyu-pictures", 1), { source: myMap.info, own: false, used: 6 }];
|
|
243
|
+
console.log(creditLine(credits, "en"));
|
|
244
|
+
console.log(creditLine(credits, "ja"));
|
|
245
|
+
|
|
246
|
+
book.enableSource("my-map", false);
|
|
247
|
+
console.log(`${book.mapSources("day").length} day maps with the source off`);
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
`<chikyu-earth-realistic>` takes map sources and `<chikyu-passes>` takes orbit data: `sources`, `addSource(source)` (checked at once, returns the way to take it away), `removeSource(id)`, `enableSource(id, on)`, `data="own"` to ignore every outside source, and `credits()` with `chikyu-creditschange` to say whose data was in the last drawn frame. `earthTiles(base)` is the package's own folder of tiles as a source (what `tiles="..."` means), and `elementsFrom(url, info)` makes a source of an address you chose, read politely. The tiles of a view share one 72 MB budget, six loads at a time, and nothing is sent at rest. Every old attribute and function stays: [guide](docs/guides/data-door.md).
|
|
251
|
+
|
|
201
252
|
## Satellites
|
|
202
253
|
|
|
203
254
|
The ISS, a space station or thousands of Starlink satellites at the places SGP4 puts them for the date and time shown, on `<chikyu-space>`: a group is one draw call however many it holds, press one to get its name, height and speed, and its orbit is drawn. Chikyu fetches nothing: your page passes in orbital elements (CelesTrak's JSON, within its usage policy), and satellite.js (MIT, an optional peer) does the maths about once a second, with every frame between interpolated. `fetchElements(url)` reads OMM JSON, CSV or TLE from an address you choose, politely (https, not again within two hours, stop on any answer that is not 200). A satellite whose elements are more than 14 days from the time shown is drawn dimmer, and one more than 30 days away is left out. A group is hidden while the clock runs faster than 60 times real time. A small catalogue (`SATELLITE_GROUPS`, `CATALOGUE`, `findInCatalogue`) names fourteen groups (stations, weather, GPS, Galileo, OneWeb and more) and about forty satellites worth following, with no elements in it. The guide has the rules for getting elements and the budget, each line tested: [satellites guide](docs/guides/satellites.md), [docs/satellites.md](docs/satellites.md).
|
|
@@ -440,6 +491,7 @@ The reference is a site, made from the source's own doc comments: every export h
|
|
|
440
491
|
| `.../space`, `.../space/element` | The Sun, the Moon and the planets; `astronomy-engine` and `three`. |
|
|
441
492
|
| `.../satellites` | SGP4 for a group of satellites; `satellite.js`. |
|
|
442
493
|
| `.../meteors` | The year's meteor showers, and when and where their meteors fall. No DOM, no dependency. |
|
|
494
|
+
| `.../door` | The data door: sources of your own maps and orbit data with their licence and credit, `creditLine`, the package's own sources. No DOM, no dependency. |
|
|
443
495
|
| `.../passes`, `.../passes/element` | Passes of a satellite over a place, the sky dome, `<chikyu-passes>`; `satellite.js`. |
|
|
444
496
|
|
|
445
497
|
## Guides
|
|
@@ -461,6 +513,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
|
|
|
461
513
|
| [Ride along](docs/guides/ride-along.md) | A camera on a moving body |
|
|
462
514
|
| [The date follows the clock, and Play](docs/guides/time-and-play.md) | The `chikyu-timechange` event, a `speed` for the space view and the realistic Earth, Play, Pause and Back |
|
|
463
515
|
| [Meteors seen from space](docs/guides/meteors.md) | Streaks over the night side, the shower table, what is real and what is illustration |
|
|
516
|
+
| [Outside data, the data door](docs/guides/data-door.md) | Hand the package your own maps of the Earth or orbit data with their licence and credit, switch them off, and show whose data is on the screen |
|
|
464
517
|
| [Zoom, pan and turn](docs/guides/zoom-and-pan.md) | The hands every view carries, each zoom range and why |
|
|
465
518
|
| [Printable sheets](docs/guides/printable-sheets.md) | The globe, a world map, my country, day and night and the seasons to print and colour |
|
|
466
519
|
| [Why two packages](docs/guides/two-packages.md) | This package and wakusei-planets: which to install, alone and together |
|
|
@@ -489,7 +542,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
|
|
|
489
542
|
|
|
490
543
|
## How to cite
|
|
491
544
|
|
|
492
|
-
> Morris, J. (2026). *Chikyu Earth* (version 0.
|
|
545
|
+
> Morris, J. (2026). *Chikyu Earth* (version 0.31.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
|
|
493
546
|
|
|
494
547
|
GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
|
|
495
548
|
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A licence: its name and a link are always shown beside the credit. *
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts no-check
|
|
5
|
+
* import type { Licence } from "./data-door.ts";
|
|
6
|
+
*
|
|
7
|
+
* const licence: Licence = { name: "CC BY 4.0", url: "https://creativecommons.org/licenses/by/4.0/", spdx: "CC-BY-4.0" };
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export interface Licence {
|
|
11
|
+
name: string;
|
|
12
|
+
url: string;
|
|
13
|
+
/** An SPDX identifier, when there is one. */
|
|
14
|
+
spdx?: string;
|
|
15
|
+
nonCommercial?: boolean;
|
|
16
|
+
shareAlike?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* What a source says about itself. *
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts no-check
|
|
22
|
+
* import type { SourceInfo } from "./data-door.ts";
|
|
23
|
+
*
|
|
24
|
+
* const info: SourceInfo = {
|
|
25
|
+
* id: "my-catalogue",
|
|
26
|
+
* name: { en: "My catalogue", ja: "私のカタログ" },
|
|
27
|
+
* credit: { en: "My catalogue, A. Person (2026)", ja: "私のカタログ(A. Person、2026年)" },
|
|
28
|
+
* licence: { name: "CC BY 4.0", url: "https://creativecommons.org/licenses/by/4.0/" },
|
|
29
|
+
* url: "https://example.org/my-catalogue",
|
|
30
|
+
* retrieved: "2026-11-10",
|
|
31
|
+
* };
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export interface SourceInfo {
|
|
35
|
+
/** Unique in a view: lower-case letters, digits and hyphens ("ucac4", "my-catalogue"). */
|
|
36
|
+
id: string;
|
|
37
|
+
name: {
|
|
38
|
+
en: string;
|
|
39
|
+
ja: string;
|
|
40
|
+
};
|
|
41
|
+
/** The line shown on screen. Never empty, in both languages. */
|
|
42
|
+
credit: {
|
|
43
|
+
en: string;
|
|
44
|
+
ja: string;
|
|
45
|
+
};
|
|
46
|
+
/** The licence: its name and link are always shown with the credit. */
|
|
47
|
+
licence: Licence;
|
|
48
|
+
/** The source's own page. */
|
|
49
|
+
url: string;
|
|
50
|
+
/** The day it was retrieved, yyyy-mm-dd, as NOTICE.md writes it. */
|
|
51
|
+
retrieved: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The most records a record source may hold. Bigger data must be tiles. *
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts no-check
|
|
57
|
+
* import { MAX_RECORDS } from "./data-door.ts";
|
|
58
|
+
*
|
|
59
|
+
* console.log(MAX_RECORDS); // 200000
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const MAX_RECORDS = 200000;
|
|
63
|
+
/**
|
|
64
|
+
* The default budget for decoded tiles in a view, all sources together: 48 MB (a picture counts with its mipmaps, 4/3 of its bytes). *
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts no-check
|
|
67
|
+
* import { TILE_BUDGET_BYTES } from "./data-door.ts";
|
|
68
|
+
*
|
|
69
|
+
* console.log(TILE_BUDGET_BYTES / 1024 / 1024); // 48
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const TILE_BUDGET_BYTES: number;
|
|
73
|
+
/**
|
|
74
|
+
* The most loads in flight at once for one source. *
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts no-check
|
|
77
|
+
* import { MAX_IN_FLIGHT } from "./data-door.ts";
|
|
78
|
+
*
|
|
79
|
+
* console.log(MAX_IN_FLIGHT); // 6
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare const MAX_IN_FLIGHT = 6;
|
|
83
|
+
/**
|
|
84
|
+
* A list that fits in memory (at most `MAX_RECORDS` records; bigger data must be tiles). It is read once, when the source is added. *
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts no-check
|
|
87
|
+
* import type { RecordSource } from "./data-door.ts";
|
|
88
|
+
*
|
|
89
|
+
* declare const info: import("./data-door.ts").SourceInfo;
|
|
90
|
+
* const source: RecordSource<{ id: string }> = { kind: "records", info, records: () => [{ id: "a" }] };
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export interface RecordSource<R> {
|
|
94
|
+
kind: "records";
|
|
95
|
+
info: SourceInfo;
|
|
96
|
+
records(signal: AbortSignal): R[] | Promise<R[]>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Data cut by place and by detail. `Place` and `Detail` are the package's own types. *
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts no-check
|
|
102
|
+
* import type { TileSource } from "./data-door.ts";
|
|
103
|
+
*
|
|
104
|
+
* declare const info: import("./data-door.ts").SourceInfo;
|
|
105
|
+
* const source: TileSource<string, number, Uint8Array> = {
|
|
106
|
+
* kind: "tiles",
|
|
107
|
+
* info,
|
|
108
|
+
* need: (place, detail) => [`${place}/${detail}`],
|
|
109
|
+
* load: async () => new Uint8Array(16),
|
|
110
|
+
* bytes: (tile) => tile.byteLength,
|
|
111
|
+
* };
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export interface TileSource<Place, Detail, Tile> {
|
|
115
|
+
kind: "tiles";
|
|
116
|
+
info: SourceInfo;
|
|
117
|
+
/** The keys of the tiles a place needs at a detail. Pure: no fetching. */
|
|
118
|
+
need(place: Place, detail: Detail): readonly string[];
|
|
119
|
+
/** Loads one tile. The source may use the network or not; it must stop when the signal aborts. */
|
|
120
|
+
load(key: string, signal: AbortSignal): Promise<Tile>;
|
|
121
|
+
/** The tile's size in memory, in bytes, for the budget. */
|
|
122
|
+
bytes(tile: Tile): number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Either kind of source. *
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts no-check
|
|
128
|
+
* import type { DataSource } from "./data-door.ts";
|
|
129
|
+
*
|
|
130
|
+
* const kinds = (sources: DataSource[]): string[] => sources.map((source) => source.kind);
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export type DataSource = RecordSource<unknown> | TileSource<unknown, unknown, unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* A piece of a map, in degrees: longitude and latitude (right ascension and declination for the sky). One shape in every package. *
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts no-check
|
|
138
|
+
* import type { MapPlace } from "./data-door.ts";
|
|
139
|
+
*
|
|
140
|
+
* const wholeSky: MapPlace = { lonMin: 0, lonMax: 360, latMin: -90, latMax: 90 };
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export interface MapPlace {
|
|
144
|
+
lonMin: number;
|
|
145
|
+
lonMax: number;
|
|
146
|
+
latMin: number;
|
|
147
|
+
latMax: number;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* What a picture needs of its bitmap: an `ImageBitmap` fits. *
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts no-check
|
|
153
|
+
* import type { BitmapLike } from "./data-door.ts";
|
|
154
|
+
*
|
|
155
|
+
* const size = (bitmap: BitmapLike): number => bitmap.width * bitmap.height;
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export interface BitmapLike {
|
|
159
|
+
readonly width: number;
|
|
160
|
+
readonly height: number;
|
|
161
|
+
close?(): void;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* A map tile: its size in pixels and its picture. A map source's detail is the pixels across the whole circumference (not a level number, because the packages number their pyramids differently),
|
|
165
|
+
* and each source maps a width to its own nearest level.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts no-check
|
|
169
|
+
* import type { ImageTile } from "./data-door.ts";
|
|
170
|
+
*
|
|
171
|
+
* const tile: ImageTile = { width: 512, height: 256, image: await createImageBitmap(blob) };
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export interface ImageTile {
|
|
175
|
+
width: number;
|
|
176
|
+
height: number;
|
|
177
|
+
image: BitmapLike;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* One source's part in the last drawn frame. *
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts no-check
|
|
183
|
+
* import type { Credit } from "./data-door.ts";
|
|
184
|
+
*
|
|
185
|
+
* declare const info: import("./data-door.ts").SourceInfo;
|
|
186
|
+
* const credit: Credit = { source: info, own: false, used: 12 };
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
export interface Credit {
|
|
190
|
+
source: SourceInfo;
|
|
191
|
+
/** True for the package's own (bundled) data. */
|
|
192
|
+
own: boolean;
|
|
193
|
+
/** The marks or tiles drawn from it. */
|
|
194
|
+
used: number;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Refuses a source that cannot be shown honestly: it throws a `TypeError` at once, when a source is added, not at the first draw. An empty credit (either language), a licence with no name or no
|
|
198
|
+
* link, a bad or already used id, a missing name, page or day, or a missing function is refused.
|
|
199
|
+
* @param source What the caller handed in.
|
|
200
|
+
* @param taken The ids already in the view, so that a clash is refused.
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts no-check
|
|
203
|
+
* import { validateSource } from "./data-door.ts";
|
|
204
|
+
*
|
|
205
|
+
* validateSource(mySource, view.sources.map((one) => one.info.id)); // throws TypeError: source "mine": the credit is empty (en)
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare function validateSource(source: unknown, taken?: Iterable<string>): asserts source is DataSource;
|
|
209
|
+
/**
|
|
210
|
+
* The credit line for what a view drew: each source's credit with its licence name, and "non-commercial" or "share-alike" whenever the source says so, so a page cannot hide the terms of the data it
|
|
211
|
+
* uses. The package's own sources come first, then the rest, each group in the order given; a source listed twice is written once. English: joined with semicolons, ending in a full stop. Japanese: the
|
|
212
|
+
* licence in full-width parentheses, joined with /, no full stop. An empty list is an empty string.
|
|
213
|
+
* @param credits What the view drew, from its `credits()`.
|
|
214
|
+
* @param language `"en"` or `"ja"`.
|
|
215
|
+
* @returns The line, or an empty string for no credits.
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts no-check
|
|
218
|
+
* import { creditLine } from "./data-door.ts";
|
|
219
|
+
*
|
|
220
|
+
* creditLine(view.credits(), "en"); // "Yale Bright Star Catalogue (Public domain); UCAC4 (CC0 1.0)."
|
|
221
|
+
* creditLine(view.credits(), "ja"); // "イェール輝星カタログ(パブリックドメイン)/UCAC4(CC0 1.0)"
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
export declare function creditLine(credits: readonly Credit[], language: "en" | "ja"): string;
|
|
225
|
+
/**
|
|
226
|
+
* What `loadRecords` found. `skipped` counts the records dropped for a non-finite number; a failed read has no records and says why.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts no-check
|
|
230
|
+
* import type { RecordsRead } from "./data-door.ts";
|
|
231
|
+
*
|
|
232
|
+
* const say = (read: RecordsRead<unknown>): string => `${read.status}: ${read.records.length} kept, ${read.skipped} skipped`;
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
export interface RecordsRead<R> {
|
|
236
|
+
status: "ok" | "failed" | "aborted";
|
|
237
|
+
/** Frozen. Empty unless the read succeeded. */
|
|
238
|
+
records: readonly R[];
|
|
239
|
+
skipped: number;
|
|
240
|
+
/** Why a read failed. */
|
|
241
|
+
reason?: string;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Reads a record source once, when it is added: the list is frozen, a record with a non-finite number (a `NaN` or an infinity in any number `finite` names) is skipped and counted, and a list over
|
|
245
|
+
* `MAX_RECORDS` is refused whole (bigger data must be tiles). It never throws: a source that throws or rejects is a failed read, and a read the signal aborted is `aborted`.
|
|
246
|
+
* @param source The record source.
|
|
247
|
+
* @param signal Aborts the read (the source is removed or switched off).
|
|
248
|
+
* @param finite The numbers of one record that must be finite, if any: `(star) => [star.ra, star.dec, star.mag]`.
|
|
249
|
+
* @returns What was found: the status, the frozen records, how many were skipped and, for a failed read, why.
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts no-check
|
|
252
|
+
* import { loadRecords } from "./data-door.ts";
|
|
253
|
+
*
|
|
254
|
+
* const read = await loadRecords(source, controller.signal, (star) => [star.ra, star.dec]); // read.records is frozen; read.skipped counts the NaNs
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
export declare function loadRecords<R>(source: RecordSource<R>, signal: AbortSignal, finite?: (record: R) => readonly number[]): Promise<RecordsRead<R>>;
|
|
258
|
+
/**
|
|
259
|
+
* The part of a tile source the store uses.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts no-check
|
|
263
|
+
* import type { TileLoader } from "./data-door.ts";
|
|
264
|
+
*
|
|
265
|
+
* const loader: TileLoader<Uint8Array> = { info, load: async () => new Uint8Array(8), bytes: (tile) => tile.byteLength };
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
export type TileLoader<Tile> = Pick<TileSource<unknown, unknown, Tile>, "info" | "load" | "bytes">;
|
|
269
|
+
/**
|
|
270
|
+
* Options for `createTileStore`.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts no-check
|
|
274
|
+
* import type { TileStoreOptions } from "./data-door.ts";
|
|
275
|
+
*
|
|
276
|
+
* const options: TileStoreOptions = { budgetBytes: 24 * 1024 * 1024, maxTiles: 256, onChange: () => draw() };
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
export interface TileStoreOptions {
|
|
280
|
+
/** The bytes of decoded tiles held, all sources together. Default `TILE_BUDGET_BYTES`. */
|
|
281
|
+
budgetBytes?: number;
|
|
282
|
+
/** The most loads in flight for one source. Default `MAX_IN_FLIGHT`. */
|
|
283
|
+
maxInFlight?: number;
|
|
284
|
+
/** The most tiles held, all sources together, as well as the byte budget. Default: no limit. */
|
|
285
|
+
maxTiles?: number;
|
|
286
|
+
/** Called when a tile has arrived, failed or been refused, so the view can redraw. */
|
|
287
|
+
onChange?: () => void;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* What a tile store has done.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts no-check
|
|
294
|
+
* import type { TileStats } from "./data-door.ts";
|
|
295
|
+
*
|
|
296
|
+
* const full = (stats: TileStats): boolean => stats.refused > 0;
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
export interface TileStats {
|
|
300
|
+
/** Tiles held, and their bytes: `heldBytes` is never over the budget. */
|
|
301
|
+
held: number;
|
|
302
|
+
heldBytes: number;
|
|
303
|
+
/** Loads running now, and loads waiting for a free place. */
|
|
304
|
+
inFlight: number;
|
|
305
|
+
queued: number;
|
|
306
|
+
/** Loads started since the store was made: the number a test reads to prove nothing is sent at rest. */
|
|
307
|
+
requested: number;
|
|
308
|
+
/** Tiles that failed to load, came back empty, or reported a size that is not a number. They are never held or drawn. */
|
|
309
|
+
failed: number;
|
|
310
|
+
/** Tiles that arrived and did not fit, because every tile held was needed by the view. They are not held; the view draws what it holds. */
|
|
311
|
+
refused: number;
|
|
312
|
+
/** Tiles let go to make room. */
|
|
313
|
+
evicted: number;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* A tile store: tiles by source and key, under one byte budget.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```ts no-check
|
|
320
|
+
* import type { TileStore } from "./data-door.ts";
|
|
321
|
+
*
|
|
322
|
+
* const held = (store: TileStore<Uint8Array>): number => store.stats().held;
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
export interface TileStore<Tile> {
|
|
326
|
+
/**
|
|
327
|
+
* Tells the store which tiles `source` needs now, and returns the ones it holds. When the keys are the same as the last call it does nothing, so a view that asks again at rest sends nothing;
|
|
328
|
+
* when they changed, the missing ones load (a tile that failed is tried again only now), the loads of tiles no longer needed are aborted, and the held ones are marked used.
|
|
329
|
+
* `again: true` is for a caller that means "try what is missing once more" with the same keys: it starts the missing tiles that are not already loading or waiting, and nothing else changes.
|
|
330
|
+
*/
|
|
331
|
+
want(source: TileLoader<Tile>, keys: readonly string[], again?: boolean): ReadonlyMap<string, Tile>;
|
|
332
|
+
/** One held tile, or `undefined`. */
|
|
333
|
+
get(sourceId: string, key: string): Tile | undefined;
|
|
334
|
+
/** Forgets a source: aborts its loads, frees its tiles. The source is switched off. */
|
|
335
|
+
drop(sourceId: string): void;
|
|
336
|
+
stats(): TileStats;
|
|
337
|
+
/** Resolves when no load is running or waiting. */
|
|
338
|
+
idle(): Promise<void>;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* A tile store for a view: loads the tiles of every source by key and keeps them under one budget of bytes (default 48 MB, all sources together).
|
|
342
|
+
* - At most `maxInFlight` loads (6) run at once for a source, and a load starts only because the keys changed: at rest the store sends nothing, and a tile that failed waits for the next change.
|
|
343
|
+
* - The least recently used tile goes first when room is needed, and never a tile the view needs now. If a new tile does not fit even so, it is refused and counted: the held bytes never pass the budget (nor the count, if `maxTiles` is set).
|
|
344
|
+
* - A tile that throws, comes back empty or reports a size that is not a finite number is counted in `failed` and never held, so it is never drawn.
|
|
345
|
+
* - `drop(sourceId)` aborts the source's loads and frees its tiles.
|
|
346
|
+
* @param options Budget, loads in flight, and a callback for a redraw.
|
|
347
|
+
* @returns The store.
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts no-check
|
|
350
|
+
* import { createTileStore } from "./data-door.ts";
|
|
351
|
+
*
|
|
352
|
+
* const store = createTileStore<Tile>({ onChange: draw });
|
|
353
|
+
* const held = store.want(source, source.need(place, detail)); // draws what is held now; the rest arrives through onChange
|
|
354
|
+
* store.drop(source.info.id); // the layer is switched off
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
export declare function createTileStore<Tile>(options?: TileStoreOptions): TileStore<Tile>;
|