import { PipeupDocument } from "../document"; import { type OpStore } from "../storage/store"; import { type Keep } from "./addons"; import { type Prefs } from "./app"; import type { LookChoice } from "./context"; import { type CopyAs } from "../export/format"; import { type SlideHook } from "./here"; import { type AgentComments } from "../export/agent"; import type { Appearance } from "./legible"; import type { FieldHost } from "./field"; export interface MountOptions { /** The area people can comment on. Default: document.body. */ root?: Element; /** The reviewer's name. Without one they show as their animal until they add a name. */ name?: string; /** Where comments are kept. Default: this browser's IndexedDB. */ store?: OpStore; /** A deck's own slide functions (1-based); they replace Pipeup's following of the deck. */ slides?: SlideHook; /** The document identity, as `data-pipeup-doc` would give it (for hosts that write their own ``). */ doc?: string; /** "column" or "bubbles", as `data-pipeup-layout`. */ layout?: string; /** "light" or "dark", as `data-pipeup-theme`. */ theme?: string; /** "comment-mode": selecting words offers a comment only in comment mode, as `data-pipeup-select`. */ select?: string; /** "off": the page has its own way to start commenting, so Pipeup's control is hidden, as `data-pipeup-control`. */ control?: string; /** Where the reviewer's choices (look, Hide comments) are kept, read as Pipeup starts. Default: localStorage. */ prefs?: Prefs; /** * "host": whatever adds Pipeup shows its threads (the browser extension's side panel). Pipeup opens none on the page, * and says when one is opened there ("open"); new comments are still written on the page. */ ui?: string; /** More page settings, as `data-pipeup-…` attributes would give them (for hosts that can't write the page's own). */ settings?: Record; /** Where add-ons keep their choices (`host.keep`). Default: none; each add-on keeps them in the page's own storage. */ keep?: Keep; /** Pipeup's UI in a closed shadow root, out of the page's scripts' reach (for hosts apart from the page). */ closed?: boolean; /** A host's own stand-in for Pipeup's text fields, where the page can't hear what is typed (the browser extension). */ field?: FieldHost; } /** What the page's code hears: comment mode and the reviewer's name ("" until they give one). */ export interface PipeupState { commentMode: boolean; name: string; } /** Why Pipeup didn't start: `code` for the page's code, the message for people. */ export type MountErrorCode = "another-copy" | "failed"; export interface MountError extends Error { code: MountErrorCode; } export interface PipeupInstance { readonly document: PipeupDocument; /** The page's comments, for an agent: open threads, or every thread with `all`. */ comments(options?: { all?: boolean; edition?: boolean; }): AgentComments; /** How Pipeup looks and why (for `pipeup check` and agents): its look, who chose it, and what the page's styles do to it. */ appearance(): Appearance; flush(): Promise; unmount(): void; /** Comment mode is on. */ readonly commentMode: boolean; /** Turns comment mode on or off; resolves once it has changed. */ setCommentMode(on: boolean): Promise; /** The reviewer's name, or "" while they show as their animal. */ readonly name: string; /** Sets the reviewer's name, kept as if they had typed it. */ setName(name: string): Promise; /** Opens Pipeup's menu (for a page with its own control: copying and sending comments live there). */ openMenu(): Promise; /** Opens All comments. */ openAllComments(): Promise; /** Calls `fn` whenever comment mode or the name changes, however it changed; returns a function that stops it. */ on(event: "change", fn: (state: PipeupState) => void): () => void; /** With `ui: "host"`: a thread was opened on the page (its highlight clicked, or just written). */ on(event: "open", fn: (id: string) => void): () => void; /** The open comments (`all`: and resolved ones), as Copy comments makes them: Markdown for AI, or plain text. */ commentsAs(as: CopyAs, options?: { all?: boolean; }): string; /** The reviewer's look: "auto" follows the author, then the page. Kept like their other choices. */ readonly look: LookChoice; setLook(look: LookChoice): Promise; /** Hide comments is on. */ readonly hidden: boolean; setHidden(on: boolean): Promise; /** Goes to a thread's place on the page: scrolls it into view and marks it; with Pipeup's own panel, opens it. */ openThread(id: string): Promise; /** Opens the comment box on an element or on words (a Range), as choosing it in comment mode does. */ startComment(target: Element | Range): Promise; } /** Adds Pipeup to the page. Calling it again returns the same instance. */ export declare function mount(options?: MountOptions): Promise; /** The page's comments for an agent that is looking at the page: waits for Pipeup to start, then reads them. */ export declare function comments(options?: { all?: boolean; edition?: boolean; }): Promise; /** * The script line alone is enough: every page mounts itself, unless data-pipeup-auto="off" (on or a loading * line). A page without data-pipeup-doc is known by its address. */ export declare function autoMount(): void;