/** The tiers of detail, from the most to the least. */ export type QualityTier = "high" | "medium" | "low"; /** What a view is asked for: one tier, or `auto`, which chooses by the frames the view makes. */ export type Quality = "auto" | QualityTier; /** The tiers, highest first: a step down is one place later in this list. */ export declare const QUALITY_TIERS: readonly QualityTier[]; /** The values a page can ask for: `auto` and the tiers. */ export declare const QUALITIES: readonly Quality[]; /** What a tier draws. */ export interface TierProfile { tier: QualityTier; /** The most buildings of a district's context that stand up as blocks in the 3D view (the tallest and widest first); the rest are the floor's flat footprints, which every tier draws. */ blocks: number; /** The share of the context's trees that are drawn, 0 to 1. */ trees: number; /** A venue whose longest side is under this share of the plan's longest side is drawn as its footprint standing up to its height, one block, in place of its stands and roof; 0 draws every venue in full. */ proxy: number; /** The small parts of a venue (benches, glass, posts, goals, the fascia and its fittings) are left out, and the crowd in its stands is drawn as blocks of colour. */ simple: boolean; /** The share of the crowd outside that is drawn, 0 to 1 (0 hides it), and the width of its canvas as a share of the usual. */ outside: { people: number; width: number; }; /** The pixel ratio the layers are rastered at, at most: on a phone or a tablet, and elsewhere. `Infinity` leaves the device's own. */ ratio: { handheld: number; other: number; }; } /** The profile of each tier. `high` leaves everything as it always was (the cap on a handheld's pixel ratio is the mode `auto`'s and is made in `rasterOf`). */ export declare const TIER_PROFILES: Record; /** Whether a value is one of the qualities. */ export declare const isQuality: (value: unknown) => value is Quality; /** A quality from whatever a page or an address gave: the same if it is one, else `fallback`. */ export declare const qualityOf: (value: unknown, fallback?: Quality) => Quality; /** The tier a view with no frames to go by is drawn at: the tier asked for, and `high` for `auto` (a page made on a server, a first draw). */ export declare const tierOf: (quality: Quality | undefined) => QualityTier; /** The tier one step lower or higher than `tier`, or the same at the end. */ export declare const lower: (tier: QualityTier) => QualityTier; export declare const higher: (tier: QualityTier) => QualityTier; /** What decides whether the device is a phone or a tablet: it has a coarse pointer, or its screen is small. It is asked of the page's own window, never of the browser's name. */ export declare function handheld(win: { matchMedia?: (query: string) => { matches: boolean; }; screen?: { width: number; height: number; }; innerWidth?: number; } | null | undefined): boolean; /** * The share of its size a layer is made at, from the device's pixel ratio `dpr`: a layer is made `share` times as wide and as high in CSS pixels and turned back to its size by its matrix, so that it holds `share` squared as many device * pixels, as far as the engine keeps a layer's pixels to its own box (the layers of a district at a ratio of 3 are hundreds of megabytes, which a phone's browser does not always keep). An engine that draws a layer again at the scale its matrix has * (Chromium does) makes the same pixels from it, so there it changes nothing, and the sizes this package reports are the boxes times the ratio squared, not what an engine allocates. 1 when the ratio is within the cap. The mode `auto` caps a handheld * at 2 even at `high`; a tier asked for by name is exactly that tier's, and `high` asked for by name is the device's own ratio, as it always was. */ export declare function rasterOf(quality: Quality, tier: QualityTier, dpr: number, isHandheld: boolean): number; /** * The most device pixels one layer may hold in a tier: a flat floor of a building is a layer as big as the building's box (the Kodokan's fourteen plates are 47 megabytes each at a ratio of 3), so a layer past the budget is made smaller * still (see `rasterOf`). `Infinity` at `high`, by name or in `auto`. */ export declare function layerBudget(tier: QualityTier, isHandheld: boolean): number; /** * The shares a layer is made at, from the smallest to a whole: the share a view needs (`viewShare`) is rounded up to one of these, so that a zoom draws the layers again at most three times from the whole view to the nearest and not at every step. */ export declare const SHARE_LEVELS: readonly number[]; /** How much finer than the screen shows it a layer is made: the perspective makes what is near the eye larger than the scale of the fit says, by a tenth at most with the lens of a district. */ export declare const VIEW_MARGIN = 1.25; /** * The share of its size a layer needs to be as fine as the screen shows it, whatever the device's pixel ratio: a layer holds `share` device pixels for each pixel of the scene (times the ratio) and the screen shows `scale * zoom` * of them (times the ratio too, and a little more near the eye), so a share of `scale * zoom * VIEW_MARGIN` is as sharp as the view and no layer needs more. `scale` is the scale that fits the scene in its container (`viewScale`), `zoom` the * view's. Rounded up to one of `SHARE_LEVELS`, so a view that is drawn at 0.15 of the scene's size, as a district on a phone is, has layers a quarter as wide and as high, a sixteenth of the pixels. 1 when the view is at least as large as the scene. */ export declare function viewShare(scale: number, zoom: number): number; /** * The least share the floor is made at, under what the view needs: the floor is one layer, and it holds the thinnest lines of the view (the north arrow, the scale, the grid, the streets and their edges), which a browser draws as a staircase * when the layer is made much coarser than it shows (Chromium does; measured on the demo at a ratio of 3). One layer at 0.6 of its size is 24 megabytes on a phone at a ratio of 3, against 67 whole. */ export declare const FLOOR_SHARE = 0.6; /** * The share of its size each layer is made at, from the sizes the layers would have at full size (their boxes in CSS pixels), the share every layer is made at (`rasterOf`), the device's pixel ratio and the layer budget: a layer is * made at the smaller of the share and the one that holds `budget` device pixels, and never at more than `ceiling` (what the view needs, `viewShare`), never under a fifth. The floor comes first, then the planes, as `layoutOf` takes them; its * ceiling is at least `floorMin`. */ export declare function rasterShares(sizes: readonly (readonly [number, number])[], share: number, dpr: number, budget: number, ceiling?: number, floorMin?: number): number[]; /** How the governor judges the frames. Times are in milliseconds. */ export interface GovernorTuning { /** The frames in a window it keeps (the oldest are dropped past twice this), and the fewest it judges: a window is also at least `settleMs` long, so a view at 60 frames a second judges 42 frames and one at 6 frames a second judges 8. */ frames: number; minFrames: number; settleMs: number; /** The first frames after the view is mounted are slow whatever it holds (scripts are still compiling, the page is still being laid out): they are not judged. */ warmMs: number; /** The mean interval between frames above which the view is over budget (21 is below 48 frames a second: a view that misses a refresh in three does not hold 60; it widens on a display that refreshes slower than 60 Hz), and the mean at or under which it is steady (18.5 holds 60 frames a second). */ budgetMs: number; steadyMs: number; /** How long the view must stay steady before it tries the tier above, and the most that wait grows to after steps that were taken back. */ upAfterMs: number; maxUpAfterMs: number; /** Frames are ignored for this long after a step, while the view is drawn again. */ quietMs: number; /** A gap longer than this between two frames is a pause (a hidden page, a stopped turn), not a slow frame. */ pauseMs: number; } export declare const GOVERNOR_TUNING: GovernorTuning; /** What the governor does with a frame. */ export interface Governor { /** The tier now. */ readonly tier: QualityTier; /** Give it the time since the last frame and the time now; it gives the new tier when it steps, else `undefined`. */ frame(interval: number, now: number): QualityTier | undefined; /** The interval of the display, in milliseconds, as the page measured it with nothing else going on (16.7 for 60 Hz, 33.3 for a phone in a power-saving mode): a display that refreshes slower than 60 Hz is not taken for a view that is too slow. 16.7 until told. */ display(interval: number): void; /** Forget the frames so far (the turn stopped, the page was hidden). */ pause(): void; /** Put it on a tier without a step (a page chose one). */ set(tier: QualityTier, now?: number): void; /** How long it now waits, steady, before it tries a tier up. */ readonly wait: number; } /** * The governor of a view that turns. It keeps a window of frame intervals; when their mean is over budget it steps one tier down, and when the mean has been steady for `wait` it tries one tier up. A try that goes over budget * is taken back, and every step down within thirty seconds of a step up doubles the wait (up to `maxUpAfterMs`), so a device on the edge between two tiers settles on the lower one and stays there. A step up that holds (steady * for `settleMs` after it) leaves the wait as it was. */ export declare function createGovernor(start: QualityTier, tuning?: Partial): Governor;