{"version":3,"file":"host.cjs","names":["PublicRenderToken"],"sources":["../../src/host-contract.ts"],"sourcesContent":["/**\n * @embedpdf/plugin-render/contract/host — the host lens.\n *\n * What view layers need to paint: the conforming render door and its source\n * keys, the resolved paint settings, and a per-view tile surface whose reads\n * are pure. Same runtime token as the public one, typed wider. Never use\n * this from application code.\n */\nimport {\n  createHostToken,\n  type AnnotationAppearanceImage,\n  type AnnotationRef,\n  type EventHook,\n  type OperationOptions,\n  type PageLayerRights,\n  type PageRef,\n  type PageRenderViewport,\n  type PluginErrorInfo,\n} from '@embedpdf/core';\nimport type { Rect } from '@embedpdf/core-geometry';\nimport {\n  RenderToken as PublicRenderToken,\n  type PageImage,\n  type PageLayerOptions,\n  type PictureReport,\n  type RenderCapability,\n} from './contract';\nimport type { PageViewDemand, TilePaintPlan } from './paint-plan';\n\nexport * from './contract';\nexport type { TilePaintPlan, TilePaintSource } from './paint-plan';\n\n/** Layer-facing paint settings (resolved config the view layers need). Reference-stable. */\nexport interface PaintSettings {\n  /** Whether the tile plane is enabled at all (`tiles: false` opts out). */\n  readonly tiles: boolean;\n}\n\nexport interface RenderSourceOptions extends PageLayerOptions {\n  /** Device px per PDF point (the page transform's `renderScale`). A thumbnail ignores it. */\n  scale: number;\n  /**\n   * The page's thumbnail instead: the whole page at the engine's thumbnail\n   * size, which needs only `doc.render.thumbnail` (a thumbnail rail's layer).\n   */\n  thumbnail?: boolean;\n  /**\n   * The view the picture is for (the page context's `view`): the engine ranks\n   * the render by where the page is in that view (`doc.with({ view })`).\n   */\n  view?: string;\n}\n\n/**\n * One view's tile surface. Identity (the view) is bound at creation; every\n * call addresses that view's own state for the given page, so two views\n * showing the same page plan independently — a thumbnail rail's\n * never-engaging demand cannot disturb the main view's tiles.\n *\n * Reads are pure: `setDemand` is the one call that schedules fetches and\n * re-plans; `getPlan` returns the paint plan that demand produced (memoized: the\n * same object until the demand, an epoch, or a tile arrival changes it, so\n * layers subscribe with plain `Object.is`). Handles are reference-stable per\n * view id and reference-counted: every `createViewDemand` pairs with one\n * `destroy`.\n */\nexport interface ViewDemand {\n  /** What this view wants for a page right now. Idempotent; schedules the want set. */\n  setDemand(page: PageRef, demand: PageViewDemand, options?: PageLayerOptions): void;\n  /** The current paint plan for a page under this view's demand. Pure. */\n  getPlan(page: PageRef): TilePaintPlan;\n  /** The image for this plan key had a presentation opportunity. */\n  markPainted(page: PageRef, key: string): void;\n  /** The inverse report: this plan key's element left the DOM. */\n  markUnpainted(page: PageRef, key: string): void;\n  /** This view unmounted its tile plane for the page: abort in-flight tile\n   *  fetches, drop its own bookkeeping (resolved bytes stay cached). */\n  release(page: PageRef): void;\n  /** Release every page of this view and drop the handle's reference. */\n  destroy(): void;\n}\n\n/** Whose pictures: a page's annotations, or its form widgets. */\nexport type AppearanceFamily = 'annotations' | 'widgets';\n\n/** One of an owner's items on a page, at the version of its picture. */\nexport interface AppearanceItem {\n  readonly ref: AnnotationRef;\n  /** Moves when the engine draws the item again (`pictureVersion`): its pictures are fetched again. */\n  readonly version: number;\n}\n\n/** What {@link RenderHostCapability.renderAppearances} takes. */\nexport interface AppearancesOptions extends OperationOptions {\n  readonly family: AppearanceFamily;\n  /** Device px per PDF point, conformed through {@link RenderHostCapability.getAppearanceScale}. */\n  readonly scale: number;\n  /** The owner's items on the page whose pictures it wants, each at its version. */\n  readonly items: readonly AppearanceItem[];\n}\n\n/** The engine's picture of an item in one of its states, and the version of the item it shows. */\nexport interface AppearancePicture extends AnnotationAppearanceImage {\n  readonly version: number;\n}\n\n/** A report a page layer keeps on the page it paints: `close()` it when the layer goes. */\nexport interface OpenPictureReport extends PictureReport {\n  close(): void;\n}\n\nexport interface RenderCompletedEvent {\n  readonly page: PageRef;\n  readonly key: string;\n}\n\nexport interface RenderFailedEvent {\n  readonly page: PageRef;\n  readonly key: string;\n  readonly error: PluginErrorInfo;\n}\n\nexport interface RenderHostCapability extends RenderCapability {\n  /**\n   * The viewer door: render a page at the scale a view shows it, conformed\n   * through the resolved render points (strategy ∧ policy): the exact\n   * demand capped at the pixel budget under `continuous`, the advertised\n   * ladder under a lattice — with same-key asks collapsing in the raster\n   * store. Layers key their fetch on {@link getSourceKey}.\n   */\n  renderSource(page: PageRef, options: RenderSourceOptions & OperationOptions): Promise<PageImage>;\n  /**\n   * The identity of the raster `renderSource` would produce — conformed\n   * width + the parts it draws + epoch (+ format), as one stable string.\n   * Under a lattice it moves only at rung crossings; under exact-mode\n   * `continuous` it tracks the demand and is constant above the budget.\n   */\n  getSourceKey(page: PageRef, options: RenderSourceOptions): string;\n  /** The canonical viewport a desired scale conforms to for this page (always width-kind). */\n  conformViewport(page: PageRef, scale: number): PageRenderViewport;\n  getPaintSettings(): PaintSettings;\n  /**\n   * What the user may read of the parts a picture draws beside the page\n   * content, so a view that leaves one part to a layer of its own can still\n   * ask for the other. The same object until a right changes.\n   */\n  getLayerRights(): PageLayerRights;\n  /** This view's tile surface. Stable per view id; pair with `destroy`. */\n  createViewDemand(viewId: string): ViewDemand;\n  /**\n   * Report on a page's picture in a view: the page is `loading` from now until `shown()`, and\n   * `idle` again once every report on it closed. A page layer opens one when it mounts and\n   * closes it when it unmounts; the box it lends a painter opens one and hands it to `paint`.\n   */\n  reportPicture(view: string, page: PageRef): OpenPictureReport;\n  /**\n   * The engine's pictures of the owner's items on a page (`family`): each\n   * item's look at rest, in every state it stores, each labelled with its\n   * state and tagged with the item's version, so a checkbox switches picture\n   * with no request, and a layer can tell a picture older than its item.\n   * The owner keys the ask on its items' versions: asks for the same page,\n   * family, scale and items share one fetch, and the last few sets of each\n   * page are kept. Rejects `permission-denied` without `doc.annotate.read`\n   * (annotations) or `doc.forms.read` (widgets).\n   */\n  renderAppearances(\n    page: PageRef,\n    options: AppearancesOptions,\n  ): Promise<readonly AppearancePicture[]>;\n  /**\n   * An item's last pictures, every state, kept a while after it left its page:\n   * an undo that brings it back shows them at once. Empty for one never drawn.\n   */\n  getKeptAppearances(family: AppearanceFamily, item: AnnotationRef): readonly AppearancePicture[];\n  /** The appearance scale a render scale conforms to under the deployment's policy. */\n  getAppearanceScale(renderScale: number): number;\n  /** A base raster resolved / failed (the conforming and exact doors alike). */\n  readonly onRenderCompleted: EventHook<RenderCompletedEvent>;\n  readonly onRenderFailed: EventHook<RenderFailedEvent>;\n  /**\n   * The snapshot tool's box on `page`, in page space, for a page layer to\n   * draw: while it is dragged and while it is held. Null on every other page,\n   * and for a drag still too small to be a box. The same object while it\n   * doesn't change.\n   */\n  getSnapshotBox(page: PageRef): Rect | null;\n}\n\nexport const RenderToken = createHostToken<RenderHostCapability>(PublicRenderToken);\n"],"mappings":";;;;;;;;;;;AA4LA,MAAa,eAAA,2BAAA,CAAA,CAAA,gBAAA,CAAoDA,iBAAAA,WAAiB"}