/** * Looking at a page from the Studio: * where it is -- its path and scroll, so a new build opens at the same place * -- and what is on it, so the assistant can check its own change * (`read_page`). * * Plain DOM and in `shared` for the reason `elementPicker.ts` is: the canvas * bridge (`@valbuild/next`, `@valbuild/tanstack`) runs it inside the * proposal's page, which is another origin than the tab and the only place * the page can be read. Only what is returned here crosses the frame * (`valCanvasProtocol.ts`). */ import type { ModuleFilePath } from "@valbuild/core"; import type { PageLogCounts } from "./pageLog.js"; /** Where the page is: what a new build is opened at. */ export type PageLocation = { /** Its path and query, without the canvas's own parameter. */ path: string; scrollX: number; scrollY: number; }; /** A box on the page, in CSS pixels from the top of the document. */ export type PageBox = { x: number; y: number; width: number; height: number; }; /** One thing a reader would notice on the page, in document order. */ export type PageOutlineItem = { kind: "heading" | "text" | "link" | "button" | "image" | "input" | "section"; tag: string; /** How to find it again: `read_page` with this `selector`. */ selector: string; /** The words in it, shortened. Absent for an image or an empty element. */ text?: string; /** `h1` is 1. */ level?: number; href?: string; alt?: string; src?: string; box: PageBox; }; /** One element in detail: what `read_page` answers for a `selector`. */ export type PageElementDetail = { selector: string; tag: string; text: string; box: PageBox; /** How many lines its text wraps to, when it can be told. */ lines?: number; /** The computed styles a change to a design is usually about. */ styles: Record; /** Its children, one level down. */ children: Array<{ tag: string; selector: string; text?: string; box: PageBox; }>; }; export type PageSnapshot = { /** The page's own address. */ url: string; title: string; viewport: { width: number; height: number; scrollY: number; /** How tall the whole page is. */ pageHeight: number; }; outline: PageOutlineItem[]; /** Cut short at `maxItems`: narrow with a `selector`. */ truncated?: true; /** The element asked for by `selector`. */ element?: PageElementDetail; /** The `selector` matched nothing. */ notFound?: string; /** * What the page logged as going wrong since it last navigated * (`pageLog.ts`): added by the bridge, so the assistant notices without * asking. Absent from a bridge of a release before it. */ log?: PageLogCounts; /** * The Val modules the page read: what its server read for this request * (`ready`'s `holds`), added by the Studio. A module the page read only in * the browser, after it loaded, is not in it. */ modules?: ModuleFilePath[]; }; /** Where `win` is now. */ export declare function pageLocationOf(win: Window): PageLocation; /** * Report where the page is as it moves: on scroll, a little after it settles, * and when it navigates -- which a client-side router does without an event, * so the address is also looked at now and then. Returns the way to stop. */ export declare function watchPageLocation(win: Window, onChange: (location: PageLocation) => void, options?: { settleMs?: number; pollMs?: number; }): () => void; /** * Scroll to where the last build was, once the page is tall enough to: a page * that is still loading its content is shorter than it will be, so this tries * again each frame for a while rather than stopping at the bottom of half a * page. Returns the way to stop trying. */ export declare function restoreScroll(win: Window, x: number, y: number, options?: { withinMs?: number; }): () => void; /** * What is on the page, as a reader would take it in: headings, text, links, * buttons, images and inputs, in order, each with where it is. With a * `selector`, that element in detail -- its computed styles, how many lines * its text wraps to, and its children. * * `root` is what selectors are written from: the body, as `describeElement` * writes them for a picked element. */ export declare function readPageSnapshot(doc: Document, options?: { selector?: string; maxItems?: number; }): PageSnapshot; /** * The element a selector names, written as `describeElement` writes them -- * from the body down, or from an element with an id -- or any selector a * person would write. */ export declare function findBySelector(root: Element, selector: string): Element | null;