/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * A Schematic kind read by area (#1393, `Schematic Builder Spec.md` §10.4, * D25, D41): its viewport's window read from an area index alone, a cell at a * time, as the Plan's events are read (`plan/root/cells.ts`, #1039). * * # The window * * The canvas writes where its viewport rests — its box, its zoom and the tier * its items draw at — to a store of its own ({@link createViewportStore}), * rendering nothing for it. A kind's window is that viewport padded by the * largest card's half size at the zoom ({@link windowOf}), so a card whose * centre lies just outside still draws. Drawn as its rows, it holds while the * viewport stays inside the box its searches reach — the window grown by its * margin — and is at least half its size, so a pan or a zoom inside the * margin reads nothing. Drawn as its density, it holds only at the zoom it * was made for, so one view draws one raster by whatever route it was * reached, and only while the viewport still holds more rows than a window * draws ({@link windowHolds}). * * # What it reads * * e3-ui's planner names the area index a window reads and its leading values * (`schematicWindowPlan`, SC34); each of the window's searches is a cell * (`areaCells`). Every cell not yet found goes in one request, counted before * an entry is read, and the rows the viewport holds are counted from those * counts (D25, {@link cellsInView}): each cell's rows held evenly over its * part of the drawing's extent, the viewport's share of them. While they * number at most `SCHEMATIC_WINDOW_ROWS`, and the window's cells hold at most * `SCHEMATIC_WINDOW_READ_ROWS`, the entries of the cells not held go in one * read of their runs, each cell's kept at the revision it was read at while * the window wants it — so a window into new cells searches and reads only * those. A narrowing the index doesn't lead is asked of the window's rows, and * of the far ends read beside them, in one `within` (D28), each row's answer * kept for its revision and narrowing; under `narrowed="dim"` every row is * read, and `within` says which match. * * Past `SCHEMATIC_WINDOW_ROWS` in view, the density (D25): one request finds * the bounds of the raster's cells — the level whose cells are about a * sixty-fourth of the window's reach — and of the coarser levels' cells, by * their exact keys (`schematicRaster`). The density's own count of the * viewport ({@link densityInView}), finer than the cells', decides at last: * once it counts no more than `SCHEMATIC_WINDOW_ROWS` there, the rows are read * after all, so the footer, which says that count, never says one the rows * would draw at. A window whose cells hold more than * `SCHEMATIC_WINDOW_READ_ROWS` draws its density whatever its view holds. The * coarser levels' rows, boxes larger than half a raster cell, are read as rows * while they number no more than a window draws, in one read of their runs; * past that they are spread over the raster cells their cells cover * (`schematicDensityCells`), and no row is read. No search of the density is * kept as a cell: the source's cells are the window's alone. * * Beside its window, a kind's overview — its whole drawing's density, which * the minimap draws — is counted over the drawing's extent in one request, once * a revision and a narrowing ({@link SchematicAreaReader.overview}); and under * `fit`, the box its narrowing's rows stand in, from the same counts of its * narrowing alone ({@link SchematicAreaReader.fitBox}): what the camera flies * to as the narrowing changes, wherever the window is (§10.3). * * Its items' details are read at every tier — a dot draws its item's status * too (D45) — by the runs its window's rows were read by: the window's cells, * or at density the coarser levels' runs, every cell not held in one request * of the details' record, the server reading each entry's key from the area * index, none sent (`recordSliceCellJoins`); each cell's kept at the kind's * revision and the details' while the window wants it, so a pan reads only the * cells it adds, and a commit to the details reads them again. The far ends of * the links and nets that touch the window are read by key, a request a kind, * through the kind's own paged read — whether or not its source joins its rows. * * Each row is held by its key's text, as a reference names it (#1549): a * String key as itself, any other as East prints it. A text is read back at * the record's key type where the record is read by key — a far end — or a * row is asked of its narrowing. * * # What it keeps * * Each kind's state across reads (`Slot`): its window, its plan and its cells, * what each was read from — and every result the same object while what it * was read from is, so a read that lands elsewhere, or a viewport resting * inside the window, plans nothing, asks nothing, makes nothing and hands the * frame nothing new. * * What a kind's `rowsOf` — or its details' — made of each row is kept by the * row's key while the row reads again as it was, as many as a window reads, * and made a budget a read (`made-rows.ts`): a window over rows another * window made — a zoom into finer cells, which searches anew, or a pan back — * makes only the rows it adds, the rows it made before the same objects, * which the drawing keeps; and a window of thousands of rows new to it is * made over several reads, a frame drawing between (#1393). * * # What it says while it reads * * While a kind's window is read, the reader says what the read waits on — its * rows, or its density's counts ({@link SchematicAreaReader.waiting}), what * the footer's loading line names — and the window it reads * ({@link SchematicAreaReader.wanted}), each read saying the window it was * read for: the canvas washes what of the window the drawing does not cover * yet ({@link unreadArea}, #1398, CL2). * * @packageDocumentation */ import { type ValueTypeOf } from "@elaraai/east"; import { type SeekRangeType } from "@elaraai/east-ui"; import { type AreaCell, type RecordSliceBindType, type RecordSliceCell } from "@elaraai/east-ui/internal"; import { type SchematicAreaIndexes, type SchematicDensityCell, type SchematicWindowPlan } from "@elaraai/e3-ui/internal"; import { type LodTier, type WorldBox } from "./canvas/model.js"; import type { SchematicValue } from "./data.js"; import { type KindKeys } from "../shared/schedule/kind-keys.js"; import { type StoredRows } from "./made-rows.js"; /** An item kind or a zone kind: what reads by area. */ export type SchematicAreaKind = SchematicValue["items"][number] | SchematicValue["zones"][number]; /** A kind's source of the slice. */ type Part = ValueTypeOf; /** A kind's details, closed. */ type Details = Extract["value"]; /** One search's bounds, decoded. */ type Range = ValueTypeOf; /** A read still in flight. */ export declare const READING = "reading"; /** A read still in flight. */ export type Reading = typeof READING; /** Where the canvas's viewport rests (#1393): what a kind read by area reads its window around. */ export interface SchematicViewport { /** Its box, in world units. */ readonly box: WorldBox; /** Its pixels per world unit. */ readonly ppu: number; /** The tier its items draw at: their cards' details are read at card and label zoom. */ readonly lod: LodTier; } /** Where the canvas's viewport rests, as the canvas reports it to the reader: a store of one viewport. */ export interface SchematicViewportStore { /** The viewport last reported; `undefined` before any is. */ get(): SchematicViewport | undefined; /** Reports where the viewport rests: one the store holds already moves nothing. */ set(viewport: SchematicViewport): void; /** Listens for a viewport that moves; returns the unsubscribe. */ subscribe(listener: () => void): () => void; } /** * A store of where the canvas's viewport rests (#1393): the canvas writes it * as its camera comes to rest, and the reader, a component of its own, reads * it — the canvas renders nothing for it, as the Plan's span store does. * * @returns The store */ export declare function createViewportStore(): SchematicViewportStore; /** * How far past the viewport a card or a labelled pin whose centre lies outside still draws, in screen pixels: half the * widest one ({@link SCHEMATIC_CARD_MAX_PX}), each shorter than it is wide. A card drawn at its item's own width spans * that box, which the area index files its row by (SC34), and reaches past it by less. */ export declare const SCHEMATIC_CARD_REACH_PX: number; /** A kind's window (§10.4): the viewport padded by the largest card's half size, the box its searches reach, and its zoom. */ export interface SchematicWindow { /** The viewport padded by the largest card's half size at its zoom: what its searches are planned over. */ readonly box: WorldBox; /** The box its searches hold: the padded viewport grown by an eighth of its larger side on each side (`areaCells`' margin). */ readonly reach: WorldBox; /** The zoom it was made for, in px per world unit: drawn as its density, it holds only at it. */ readonly ppu: number; } /** * A viewport's window (§10.4): the viewport padded by the largest card's half * size at its zoom — a dot's at dot zoom — the box its searches reach, and * the zoom. * * @param viewport - Where the viewport rests * @returns Its window */ export declare function windowOf(viewport: SchematicViewport): SchematicWindow; /** A window drawn as its density, as whether it holds weighs it: the density, and whether its cells hold more rows than a window reads. */ export interface SchematicWindowDensity { /** The density it draws. */ readonly density: SchematicDensity; /** Whether its cells hold more than `SCHEMATIC_WINDOW_READ_ROWS`: then it draws its density whatever its view holds. */ readonly capped: boolean; } /** * Whether a window holds for a viewport (§10.4, D25). Drawn as its rows, it * holds while the viewport's padded box lies inside the window's reach and is * at least half its size, so a pan or a zoom inside the margin reads nothing, * and a zoom in by more than half plans the window again at its finer cells. * Drawn as its density, it holds only at the zoom it was made for — so a view * draws one raster by whatever route it was reached, Fit's button or the * wheel — while the viewport's padded box lies inside its reach, which its * raster covers, and while the density counts more rows in the viewport than * a window draws or its cells hold more than a window reads: past that, the * viewport's own window is planned, which reads the rows. * * @param window - The window read * @param viewport - Where the viewport rests now * @param drawn - Its density, while it is drawn as its density; `undefined` while it is drawn as its rows, or not yet read * @param extent - The drawing's extent, in world units: where a density's rows lie * @returns Whether the window still holds */ export declare function windowHolds(window: SchematicWindow, viewport: SchematicViewport, drawn: SchematicWindowDensity | undefined, extent: WorldBox): boolean; /** A kind's rows read by area: each row's decoded value, by its key's text ({@link kindKeys}, #1549). */ export type SchematicAreaRows = ReadonlyMap; /** A density raster, as the canvas draws it (D25): its cells holding rows, each its corner and how many. */ export interface SchematicDensity { /** Its cells' side, in world units. */ readonly side: number; /** Its cells that hold rows: each its left edge, its top and how many rows it holds. */ readonly cells: readonly SchematicDensityCell[]; /** The most rows a cell holds: what the raster's shading is scaled to. */ readonly most: number; /** The box its cells cover, in world units: its window's reach. */ readonly box: WorldBox; /** Whether the coarser levels' rows are spread over its cells, each cell's count then holding a share of theirs. */ readonly spread: boolean; /** Whether a narrowing the index doesn't lead is left out of it, which the footer says. */ readonly unnarrowed: boolean; } /** How many rows a density shades in a box (#1393): what the footer says of a kind drawn as its density. */ export interface SchematicDensityInView { /** * How many: every row of each cell inside the box, and the box's share of each cell it cuts — the cell's rows held * evenly over its part in the drawing's extent — whole below a hundred and to two significant figures above, where it * is not exact. */ readonly rows: number; /** Whether that is exact: every cell the box meets lies inside it, the density covers the box, and no coarser level's rows are spread. */ readonly exact: boolean; } /** * How many rows a density shades in a box (#1393, D25) — the viewport's, where * it rests: what the footer says of a kind drawn as its density. A cell's rows * lie in its part of the drawing's extent, as Issues holds every item to the * extent, so a cell reaching past the extent's edge lies in the box while its * part in the extent does: the view Fit leaves, the extent edge to edge, counts * every row exactly whatever cell the extent's edge cuts. A cell wholly outside * the extent holds rows only where they stand outside it, and is taken whole. A * cell the box cuts gives the box its share of the cell's rows, as the density * holds a coarser cell's rows evenly over the cells it covers; a count that * takes a share is an estimate, said to two significant figures. * * @param density - The kind's density * @param box - The box, in world units * @param extent - The drawing's extent, in world units * @returns How many rows it shades in the box, and whether that is exact */ export declare function densityInView(density: SchematicDensity, box: WorldBox, extent: WorldBox): SchematicDensityInView; /** * How many rows a window's cells hold in a box, by their counts (#1393, D25) — * the viewport's, where it rests: what the density switch weighs before a row * or a raster is read. Each cell's rows are held evenly over its part of the * drawing's extent, as a density's cell's are ({@link densityInView}), the * box giving its share of them; a coarser level's cell by its exact key the * same, its rows' centres anywhere in it. * * @param cells - The window's cells, as `areaCells` plans them * @param counts - How many entries each holds, in their order * @param box - The box, in world units * @param extent - The drawing's extent, in world units * @returns How many rows they hold in the box: an estimate, unrounded * @throws {Error} When the counts are not one a cell */ export declare function cellsInView(cells: readonly AreaCell[], counts: readonly bigint[], box: WorldBox, extent: WorldBox): number; /** * What of a box another leaves (#1398): up to four boxes, disjoint — the * strips above and below the other, then those beside it, between them. The * box whole where the two do not overlap; none where the other covers it. * * @param a - The box * @param b - What is taken from it; `undefined`, nothing * @returns What of `a` lies outside `b` */ export declare function boxMinus(a: WorldBox, b: WorldBox | undefined): WorldBox[]; /** * The area a drawing's reads in flight have not drawn yet (#1398, CL2): each * kind's window being read, less the reach of the window its drawing holds — * what the canvas washes, as boxes disjoint from one another, so where two * kinds' unread areas meet it washes once. * * @param parts - Each kind read by area whose window is read: the reach it reads, and the reach its drawing holds — `undefined` for none yet * @returns The unread area, as disjoint boxes */ export declare function unreadArea(parts: readonly { readonly want: WorldBox; readonly have: WorldBox | undefined; }[]): WorldBox[]; /** A kind's window as it was read, before its narrowing is asked of it (#1393). */ export interface SchematicWindowRead { /** The plan it was read by. */ readonly plan: SchematicWindowPlan; /** The revision it was read at. */ readonly revision: string; /** Its rows, by key: the window's — or, at density, the coarser levels' — the narrowing not yet asked of them. */ readonly rows: SchematicAreaRows; /** Its density, past the rows a window draws; `undefined` while it draws items. */ readonly density: SchematicDensity | undefined; /** Where its rows were read from in its index, which its details are read by (D45): its cells, or at density the coarser levels' runs. */ readonly at: { readonly cells: readonly RecordSliceCell[]; } | { readonly runs: readonly Range[]; }; /** What its rows were read from: the same parts, the same rows. */ readonly from: readonly unknown[]; /** The window it was read for: the drawing it makes covers that window's reach. */ readonly window: SchematicWindow; } /** A kind's rows read by area, the narrowing asked of them (#1393). */ export interface SchematicAreaRead { /** The rows it draws, by key: within its narrowing — every one read under `narrowed="dim"`. */ readonly rows: SchematicAreaRows; /** * The rows its narrowing holds, while one narrows it: under `narrowed="dim"` those `within` answered for, else every * row it draws; `undefined` while nothing narrows it. */ readonly matched: ReadonlySet | undefined; /** What its rows were read from: the same parts, the same rows. */ readonly from: readonly unknown[]; } /** What a kind's window's read waits on: its rows — its cells' counts and entries, the coarser levels' — or its density's counts. */ export type SchematicWindowWait = "rows" | "counts"; /** * The reader's state across reads (see the module docs): each kind's window, * the cells it read at their revision, the narrowing's answers, the density it * drew and the rows it made — every part beside what it was read from. */ export declare class SchematicAreaReader { private readonly slots; /** What each kind's `rowsOf` — and its details' — has made of its rows, a budget a read (`made-rows.ts`). */ private readonly making; /** Begins a read: it makes rows for a budget's time, and leaves the rest to the next read ({@link unmade}). */ begin(): void; /** Whether the last read left rows to make: its reader reads again a task later, so a frame draws between. */ get unmade(): boolean; /** A kind's state, made empty on first use. */ private slotOf; /** * The rows a kind's window holds at a revision, as the frame is handed them: * the same object while they and the revision hold. * * @param slot - The kind's slot * @param revision - The revision they were read at * @param rows - The rows, by key * @returns What the window holds */ held(slot: string, revision: string, rows: ReadonlyMap): { readonly revision: string; readonly rows: ReadonlyMap; }; /** * A kind's window as it is read (see the module docs): its rows while the * viewport holds no more than a window draws, else its density — the same * object while its plan and its revision hold. * * @param kind - The kind * @param part - Its source of the slice * @param areas - Its area indexes * @param viewport - Where the viewport rests * @param dim - Whether every row is read, the narrowing drawn as context (`narrowed="dim"`) * @param extent - The drawing's extent, in world units: where a cell's rows lie, as the viewport's count weighs them * @returns What the window holds; {@link READING} while a search or a read is in flight */ window(kind: SchematicAreaKind, part: Part, areas: SchematicAreaIndexes, viewport: SchematicViewport, dim: boolean, extent: WorldBox): SchematicWindowRead | Reading; /** * The window a kind reads now (#1398): its viewport's, or the one it holds while it holds — what the canvas washes * the part of its drawing does not cover, while its read is in flight. * * @param slot - The kind's slot * @returns The window; `undefined` before the kind has planned one */ wanted(slot: string): SchematicWindow | undefined; /** * What a kind's window's read waits on, while it is in flight (#1398, CL3): its rows — `Loading racks in view` — or * its density's counts — `Loading counts`. * * @param slot - The kind's slot * @returns What it waits on; `undefined` while its read has landed */ waiting(slot: string): SchematicWindowWait | undefined; /** * The window a kind reads for a viewport: the one it holds while it holds as it was drawn ({@link windowHolds}) — * as its rows until its read lands — else the viewport's own. */ private windowFor; /** A window's plan and its cells, planned again only when the source, the narrowing or the window moves. */ private plannedOf; /** How many entries a window's cells hold, each cell's and all of them: found in one request, once a revision. */ private foundOf; /** A window's rows, by their keys' text: its cells' entries, those of the cells not held read in one read of their runs. */ private rows; /** * The cells' entries a kind's window holds, at the record's revision through * an index: those of the wanted cells it doesn't hold read in one read of * their runs, and every cell no longer wanted let go. * * @returns Each wanted cell's entries, in order; {@link READING} while the read is in flight */ private entriesOf; /** * A window's density raster (D25): the bounds of the raster's cells over * the window's reach and of the coarser levels' cells, in one request, and * the density they draw — the coarser levels' rows spread over the raster * while they number more than a window draws. */ private rasterOf; /** A window drawn as its density (D25): the coarser levels' rows read in one read of their runs while they are few. */ private density; /** A window's density raster and its searches, planned again only with the window's plan. */ private rasteredOf; /** A raster's searches' bounds: found in one request, once a revision, and kept as no cell. */ private boundsOf; /** * The coarser levels' rows: the runs holding any, ascending, read in one read — once for the bounds they were found * by — and those runs, which their details are read by. */ private coarseOf; /** A raster's density, as the canvas draws it: the one it last drew while its cells read again as they were, over the same box. */ private densityOf; /** * A kind's overview (#1393): its whole drawing's density, which the * minimap draws, where its window holds only what the view is near — the * area index's counts over the drawing's extent at the level whose cells * are about a sixty-fourth of it, through the index its narrowing reads a * window through, each combination of its leading values added cell by * cell and the coarser levels' rows spread over them: one request of * counted ranges, no row read, read once a revision and a narrowing, the * last one standing until the next lands. * * @param kind - The kind * @param part - Its source of the slice * @param areas - Its area indexes * @param extent - The drawing's extent, in world units * @param dim - Whether every row is drawn, the narrowing as context (`narrowed="dim"`) * @returns The density; {@link READING} while its counts are in flight */ overview(kind: SchematicAreaKind, part: Part, areas: SchematicAreaIndexes, extent: WorldBox, dim: boolean): SchematicDensity | Reading; /** * The box a kind's narrowing's rows stand in (#1393, §10.3), as its area * index's counts over the drawing's extent answer it: the cells of its * narrowing's raster — planned as the overview's is, its narrowing's * choices whatever `narrowed` draws — and of the coarser levels that hold * a row, each cell's part of the extent, in one request of counted ranges, * no row read; what the camera flies * to under `fit`, never what the window draws. A choice the index doesn't * lead isn't counted in it: the box is then that of the choices it leads, * which hold the narrowing's rows among others. Read once a revision and a * narrowing; while a new one's counts are in flight, none stands in. * * @param kind - The kind * @param part - Its source of the slice * @param areas - Its area indexes * @param extent - The drawing's extent, in world units * @returns The box; `null` where the narrowing holds no row; {@link READING} while its counts are in flight */ fitBox(kind: SchematicAreaKind, part: Part, areas: SchematicAreaIndexes, extent: WorldBox): WorldBox | null | Reading; /** * The rows of some of a kind's keys its window doesn't hold — the far ends * of the links and nets that touch it — read by key through the kind's own * paged read, in one request: the same rows while that read's answer is. * * @param slot - The kind's slot * @param paged - The `id` of its paged read; `undefined` for a kind with none * @param keys - The kind's keys: each text read back at the record's key type for the read, and each row read by its key's text (#1549) * @param texts - The keys' text, as the links and nets name them, in order * @returns Each row the record holds, by its key's text; {@link READING} while the read is in flight * @throws {Error} When the kind has no paged read, or it is bound on no page this runtime serves */ farEnds(slot: string, paged: string | undefined, keys: KindKeys, texts: readonly string[]): SchematicAreaRows | Reading; /** * A kind's rows read by area, its narrowing asked of them (D28): those it * holds drawn — every one under `dim`, those it holds the matches — each * row's answer kept at its revision and narrowing, so a pan asks only of * the rows it adds; every row asked in one request. The same object while * what it was read from is. * * @param kind - The kind * @param part - Its source of the slice * @param read - Its window, as it was read * @param far - Its far ends, read by key * @param dim - Whether the narrowing is drawn as context * @returns The rows it draws, and under `dim` the matches; {@link READING} while the narrowing's answer is in flight */ narrowed(kind: SchematicAreaKind, part: Part, read: SchematicWindowRead, far: SchematicAreaRows, dim: boolean): SchematicAreaRead | Reading; /** A kind's rows, its narrowing asked of them (see {@link SchematicAreaReader.narrowed}). */ private narrow; /** * Which of some rows a narrowing holds: each answer kept at its revision and narrowing, by its row's key's text, the * rows not yet answered asked in one request — each by its key read back at the record's key type (#1549). */ private answersOf; /** * A kind's rows made its stored rows (#1393), through its `rowsOf`: each * one's roles beside its bytes — made again only when what they were read * from moved, and then only the rows it has not made already, over as * many reads as its budget takes. * * @param kind - The kind * @param read - Its rows, the narrowing asked of them * @returns Its stored rows, by key; {@link READING} while rows are left to make */ rowsOf(kind: K, read: SchematicAreaRead): ReturnType | Reading; /** * The details of the items a kind's window holds, made their stored rows * (§12, D45): read by the runs its rows were read by — its cells, or at * density the coarser levels' runs — every cell not held in one request of * the details' record, the server reading each entry's key from the area * index, none sent; each cell's kept at the kind's revision and the * details' while the window wants it, so a pan reads only the cells it * adds and a commit to the details reads them again. Read at every tier: a * dot draws its item's status too. A far end, drawn off the window, has * none read. * * @param slot - The kind's slot * @param details - Its details * @param part - Its source of the slice: the area index its window was read through * @param read - Its window, as it was read * @param keys - The kind's keys, which its details are keyed as: each details row by its key's text (#1549) * @returns Their details' rows, by key; `undefined` for details read whole or by no paged read; {@link READING} while the read is in flight, or rows are left to make * @throws {Error} When the details' paged read is bound on no page this runtime serves */ detailsOf(slot: string, details: Details, part: Part, read: SchematicWindowRead, keys: KindKeys): StoredRows | Reading | undefined; /** * A window's details' rows (see {@link SchematicAreaReader.detailsOf}): its * cells' — those not held read in one request, and every cell no longer * wanted let go — or the coarser levels' runs', read once for the runs. * * @returns Each cell's rows of the details, in the window's order, or the runs'; {@link READING} while the read is in flight */ private joinedOf; } export {}; //# sourceMappingURL=area.d.ts.map