@johnmorrisdotca/wakusei-planets 0.31.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 CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.32.0] - 2026-11-10
6
+
7
+ - **The data door: `@johnmorrisdotca/wakusei-planets/door`** (MODULES-831, step 2; the shapes are kazoku-ui's `templates/data-door.ts`, copied unchanged to `src/data-door.ts`). One way to hand the package outside data and to say whose data is on the screen. `BodyMapSource` is a `TileSource` for the colour or the height of a body's map (the family's `MapPlace` and `ImageTile`; the keys end in `level/column/row` on the package's 512 pixel pyramid, and `mapKeys` names them), and `tilesSource(base)` is the package's own folder of tiles as a source, which is what the `tiles` attribute means; the attribute stays. `SmallBody` (name, `a`, `e`, `i`, `node`, `peri`, `M0`, `epoch`, `H`) and `SmallBodySource` are a record source of small bodies, read once, at most 200,000, with the records that cannot be drawn left out and counted; `smallBodyAt` says where one is on a date. `<wakusei-body>` and `<wakusei-space>` take `sources`, `addSource` (checked at once, returns its `remove()`), `removeSource`, `enableSource` and `data="own"`, and have `credits()` and the event `wakusei-creditschange`; `creditLine` writes the credit line with the licence beside each source, "non-commercial" or "share-alike" included, in English and Japanese. Off aborts a source's loads, frees its tiles and records, and drops its credit. The tiles of every body in a view share one 48 MB budget (`TILE_BUDGET_BYTES`), six loads at a time per source, and nothing is sent at rest. `OWN_SOURCES` (the pictures, the tiles and the orbit series) and `ownCredit` write the package's own credits from `NOTICE.md`, and a test holds that none is non-commercial or share-alike. A window of tiles that could not be made is no longer tried again after 30 seconds: it is tried again when the view changes. Every attribute and function is as it was; `createPainter` takes an optional `book`.
5
8
  ## [0.31.0] - 2026-11-10
6
9
 
7
10
  - **The body looked at is shown whole with a margin, no orbit line crosses it, and the demo opens moving** (machine1's review of the first hand-in). Zoom 1 now frames the body about 80% of the view's shorter side across (`FIT_DISTANCE` 4.1, it was 3.4 and the disc nearly touched the edges; Saturn is framed with its rings at 2.3 radii), so the zoom ceiling is 3.6 (the camera is as near as before). Close to a body (its disc 30 CSS pixels or more across its radius) only the orbit lines of its own system are drawn and the part of them within about twelve radii fades out, so no line is ever seen across the disc (`stats.orbits.hidden`). The demo's space page opens playing, from now, an hour a second, when its address names no date, speed or play and the reader has not asked for reduced motion; with reduced motion it opens still with Play ready. On the full-screen page the scale line sits at the bottom right and overlaps nothing. Browser tests: the disc is 72% to 88% of the shorter side, centred, at 1440x900, 390x844 and 2400x700 in the panel and full screen; the picture of the disc is the same with the lines on and off; the picture changes within two seconds with nothing touched.
package/NOTICE.md CHANGED
@@ -132,6 +132,11 @@ Not tiled, because no finer public-domain map was found that this package can us
132
132
 
133
133
  The generic detail of a close zoom (docs/guides/close-zoom.md) is noise made in the shader. It is no data and takes nothing from any source.
134
134
 
135
+ ## The data door
136
+
137
+ - **The package's own credits (`OWN_SOURCES` in `@johnmorrisdotca/wakusei-planets/door`, MODULES-831, written 2026-11-10)**: three rows, written from the entries of this file and read nowhere else. `wakusei-pictures` is the surface pictures (Surface pictures above: NASA, USGS and JPL maps that are public domain, and Solar System Scope's and Nestaeric's maps, CC BY 4.0; its licence name is the stricter, "CC BY 4.0", read 2026-11-02). `wakusei-tiles` is the finer map tiles (Finer map tiles above: public domain, read 2026-11-09). `wakusei-orbits` is the series and tables the positions come from (The numbers above: IMCCE's VSOP87B and ELP2000-82B, which "carry no licence text" and are published for use with the credit, and JPL Horizons, NASA/JPL-Caltech, read 2026-11-07; its licence name says "Published for use with credit"). A test holds that none of the three is marked non-commercial or share-alike.
138
+ - **Data a caller hands in is not part of this package.** A source passed to `addSource` or `sources` carries its own credit and licence, and the credit line prints them (with "non-commercial" or "share-alike" where the source says so). This package bundles no such data and takes none as a dependency. The small-body source is a list of orbital elements a caller supplies; this package holds no catalogue of them.
139
+
135
140
  ## Orbiter's MIT notice
136
141
 
137
142
  The TASS1.7 table above was read from Orbiter (https://github.com/orbitersim/orbiter), whose licence is:
package/README.md CHANGED
@@ -19,7 +19,7 @@ Wakusei Planets runs in the browser of a phone, a tablet or a computer: nothing
19
19
 
20
20
  <p align="center"><img alt="The demo on a desk: Saturn in the painted look, turning in the big view, with the page's links to the portrait builder, the colouring sheets, the space view, the star page and the size line-up above it, and the choice of body and its moons below" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-desk.webp" width="620"> <img alt="The same page on a phone: the same links in rows, and Saturn in the painted look below them" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-phone.webp" width="200"></p>
21
21
 
22
- <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.31.0/docs/images/lineup-desk.png" width="640"></p>
22
+ <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.32.0/docs/images/lineup-desk.png" width="640"></p>
23
23
 
24
24
  ## Who it is for
25
25
 
@@ -313,13 +313,66 @@ A body that turns by itself and a moving sky, in HTML:
313
313
  <wakusei-body body="venus" look="realistic" time="2026-11-02T12:00:00Z" turn="12" live="hover"></wakusei-body>
314
314
  ```
315
315
 
316
+ ## Outside data
317
+
318
+ The package draws; you bring the data. `@johnmorrisdotca/wakusei-planets/door` takes a finer map of a body, or a list of small bodies, as a **source**: a small object that carries its own licence and credit, so the page can always say whose data is on the screen. Without a source the package draws exactly what it did before, from its own pictures, tiles and series. A source of yours may be non-commercial or share-alike; the credit line says so beside the licence, and the package never bundles one.
319
+
320
+ ```js
321
+ import { createSourceBook, creditLine, smallBodyAt } from "@johnmorrisdotca/wakusei-planets/door";
322
+
323
+ // A source of your own: here two small bodies held in memory (the second has a number that is not one, so it is left out). A real one would read a catalogue, and says whose it is and under what licence.
324
+ const mine = {
325
+ kind: "records",
326
+ info: {
327
+ id: "my-rocks",
328
+ name: { en: "My rocks", ja: "私の小天体" },
329
+ credit: { en: "My rocks, A. Person (2026)", ja: "私の小天体(A. Person、2026年)" },
330
+ licence: { name: "CC BY-NC 4.0", url: "https://creativecommons.org/licenses/by-nc/4.0/", nonCommercial: true },
331
+ url: "https://example.org/my-rocks",
332
+ retrieved: "2026-11-10",
333
+ },
334
+ records: () => [
335
+ { name: "Ceres", a: 2.7656, e: 0.0795, i: 10.588, node: 80.25, peri: 73.3, M0: 291.4, epoch: 2461000.5, H: 3.34 },
336
+ { name: "Broken", a: Number.NaN, e: 0.1, i: 5, node: 0, peri: 0, M0: 0, epoch: 2461000.5, H: 12 },
337
+ ],
338
+ };
339
+
340
+ // An element keeps a book like this one: `space.addSource(mine)` is `book.addSource(mine)`.
341
+ const book = createSourceBook();
342
+ book.addSource(mine);
343
+ await book.ready();
344
+ const [ceres] = book.smallBodies();
345
+ const [x, y, z] = smallBodyAt(ceres, 2461000.5);
346
+ console.log(`${book.smallBodies().length} small body, ${book.stats().records["my-rocks"].skipped} left out: ${ceres.name} is ${Math.hypot(x, y, z).toFixed(2)} au from the Sun`);
347
+ const credits = [{ source: mine.info, own: false, used: book.smallBodies().length }];
348
+ console.log(creditLine(credits, "en"));
349
+ console.log(creditLine(credits, "ja"));
350
+
351
+ book.enableSource("my-rocks", false);
352
+ console.log(`${book.smallBodies().length} small bodies with the source off`);
353
+ ```
354
+
355
+ `<wakusei-space>` draws small bodies as points in one instanced draw, and `<wakusei-body>` and `<wakusei-space>` both take a map of a body to lay over its own picture. Both have `sources` and `addSource(source)`, which checks the source at once and returns the way to remove it, `removeSource(id)`, `enableSource(id, false)` and the attribute `data="own"` to switch outside sources off (their loads abort and their tiles are freed), and `credits()` with the event `wakusei-creditschange` for the credit line.
356
+
357
+ ```js no-run
358
+ import { creditLine, tilesSource } from "@johnmorrisdotca/wakusei-planets/door";
359
+ import "@johnmorrisdotca/wakusei-planets/space/element";
360
+
361
+ const space = document.querySelector("wakusei-space");
362
+ space.addSource(mine); // the source above: its points are in the next frame
363
+ space.addSource(tilesSource("/my-tiles/")); // what tiles="/my-tiles/" means
364
+ space.addEventListener("wakusei-creditschange", () => console.log(creditLine(space.credits(), "en")));
365
+ ```
366
+
367
+ The tiles of every body share one 48 MB budget, six loads at a time for a source, and nothing is sent at rest. `OWN_SOURCES` and `ownCredit` give the package's own credits, `mapKeys` helps a source of your own name the tiles of a place, and `readSmallBodies` and `smallBodyAt` read a list of small bodies and say where one is on a date. The [guide](docs/guides/data-door.md) has the shapes and the rules.
368
+
316
369
  ## The code builder
317
370
 
318
371
  [The code builder](https://johnmorrisdotca.github.io/wakusei-planets/builder.html) is one screen: choose which planet's system, the body, the look, the size, the sky and the turning, then pick how your page is made and copy the code. It is the family's embed panel with those choices inside it, built from `embedCode`, so it writes what the package writes. [Put it in your page](docs/guides/put-it-in-your-page.md) is its guide.
319
372
 
320
373
  ## The portrait builder
321
374
 
322
- <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.31.0/docs/images/portrait-family.png" width="640"></p>
375
+ <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.32.0/docs/images/portrait-family.png" width="640"></p>
323
376
 
324
377
  [The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
325
378
 
@@ -409,6 +462,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
409
462
  | [The size line-up](docs/guides/size-lineup.md) | The Sun and the largest stars at true relative size, with each radius, its error and its paper, where the papers disagree, every way to put it in a page |
410
463
  | [Zoom and pan](docs/guides/zoom-and-pan.md) | Every view zooms and moves by itself: the range of each and why it ends there, the bar, the embed page |
411
464
  | [Close zoom and map tiles](docs/guides/close-zoom.md) | How far each body zooms and why, the finer map tiles for a close zoom (made from public-domain maps, served beside the demo, never in the package), the generic detail, what it costs |
465
+ | [Outside data, the data door](docs/guides/data-door.md) | Hand the package your own maps of a body or small bodies with their licence and credit, switch them off, and show whose data is on the screen |
412
466
  | [Riding along](docs/guides/ride-along.md) | The camera on a moon, a planet or any moving point, looking at what it goes round |
413
467
  | [Accuracy](docs/guides/accuracy.md) | How far each body is from JPL Horizons |
414
468
  | [In your own three.js scene](docs/guides/in-your-own-scene.md) | `painter.make` |
@@ -453,7 +507,7 @@ BODIES.pluto.kind; // "dwarf-planet"
453
507
 
454
508
  If this package helps a paper, a talk or a class, please cite it as software. GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA; in plain text:
455
509
 
456
- > Morris, J. (2026). *Wakusei Planets* (version 0.31.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
510
+ > Morris, J. (2026). *Wakusei Planets* (version 0.32.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
457
511
 
458
512
  Cite the version you used (`npm ls @johnmorrisdotca/wakusei-planets`), and cite the sources of the numbers you use as well: [NOTICE.md](NOTICE.md) names each one, with the paper or the page it was read from (the IAU working group's report for sizes and poles, VSOP87B, ELP2000-82B, L1.2 and TASS1.7 for positions, and NASA's JPL Horizons for the fits and the spacecraft).
459
513
 
@@ -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>;