import { type Credit, type DataSource } from "../data-door.ts"; import type { EarthMapSource, MapLayer } from "./map.ts"; import type { ElementSet } from "../satellites/types.ts"; /** * Options of a view's source book. * * @example * ```ts * import type { SourceBookOptions } from "@johnmorrisdotca/chikyu-earth/door"; * * const options: SourceBookOptions = { kinds: ["tiles"] }; * console.log(options.kinds); * ``` */ export interface SourceBookOptions { /** The kinds of source this view can draw: `tiles` (a map of the Earth) and `records` (satellites' orbital elements). Both where left out. */ kinds?: readonly ("tiles" | "records")[]; } /** * What a view's sources have done: for each record source how many records it holds and how many were left out. * * @example * ```ts * import type { SourceStats } from "@johnmorrisdotca/chikyu-earth/door"; * * const kept = (stats: SourceStats): number => Object.keys(stats.records).length; * console.log(typeof kept); * ``` */ export interface SourceStats { records: Record; } /** * A view's sources, as `` and `` keep them: `addSource`, `removeSource`, `enableSource` and `ownOnly` are the element's methods of the same names. * * @example * ```ts * import { createSourceBook } from "@johnmorrisdotca/chikyu-earth/door"; * * const book = createSourceBook(); * console.log(book.sources.length, book.active().length); * ``` */ export interface SourceBook { /** The sources now in the view, in the order added (the package's own folder of tiles is not among them unless a page added it). */ readonly sources: readonly DataSource[]; /** Adds a source. It throws a `TypeError` at once for a source `validateSource` refuses, an id already in the view, a kind this view cannot draw, or a map source with no layer. Returns the function that removes it. */ addSource(source: unknown): () => void; /** Removes a source by id: aborts its reads, frees its records. Returns whether there was one. */ removeSource(id: string): boolean; /** Switches a source off (`false`) or on: off aborts its read and frees its records, and the source stays in the view. */ enableSource(id: string, on: boolean): void; /** True while a source is in the view and switched on. */ isEnabled(id: string): boolean; /** `true` ignores every source that is not the package's own, at once (the attribute `data="own"`). */ ownOnly(on: boolean): void; readonly onlyOwn: boolean; /** The sources in use: in the view, switched on, and not ignored by `ownOnly`. */ active(): readonly DataSource[]; /** The map sources in use for a layer, the last one added first (it is the one the layer is drawn from). */ mapSources(layer: MapLayer): readonly EarthMapSource[]; /** The element sets of every record source in use, read so far, with the id of the source each came from, in the order added. */ elementLists(): readonly { id: string; sets: readonly ElementSet[]; }[]; /** True for a source the package made itself. */ isOwn(source: DataSource): boolean; /** The source of this id, if it is in the view. */ get(id: string): DataSource | undefined; /** The signal of a source: it aborts when the source is removed, switched off or ignored, so what a view started for it stops. */ signal(id: string): AbortSignal; /** Calls `listener` when something changed that a view may want to draw again for: a source added, removed or switched, records read. Returns the function that stops it. */ onChange(listener: () => void): () => void; stats(): SourceStats; /** A number that changes whenever the sources in use change (a source read, switched, added or removed), so a view looks again only then. */ readonly version: number; /** Resolves when every record source has been read. */ ready(): Promise; /** Frees everything: aborts every read and signal, frees every record. The book is not used again. */ dispose(): void; } /** * Makes the sources of one view. * * @param options - The kinds the view draws. * @returns The book. * * @example * ```ts * import { createSourceBook } from "@johnmorrisdotca/chikyu-earth/door"; * * const book = createSourceBook({ kinds: ["tiles"] }); * console.log(book.active().length); * ``` */ export declare function createSourceBook(options?: SourceBookOptions): SourceBook; /** * The credits of a view for the last drawn frame: the package's own first, then the sources a caller added, each with the marks or tiles it gave; a source that gave none is left out. * * @param own - The package's own credits (`ownCredit`), with how many marks each gave. * @param book - The view's sources. * @param used - How many marks or tiles each source of the book gave, by id. * @returns The credits, own first, in a stable order. * * @example * ```ts * import { createSourceBook, creditsOf, ownCredit } from "@johnmorrisdotca/chikyu-earth/door"; * * const book = createSourceBook(); * console.log(creditsOf([ownCredit("chikyu-pictures", 1)], book, new Map()).length); * ``` */ export declare function creditsOf(own: readonly Credit[], book: SourceBook, used: ReadonlyMap): Credit[];