/** * @file * * Pure helpers for screenshot capture: building the CDP device-metrics override * payload, decoding a base64-encoded PNG, and reading a PNG's pixel dimensions * out of its IHDR header. * * Kept separate from the transports (which are integration-only and excluded * from unit tests) so the payload shape and the PNG parsing stay unit-testable — * the transports themselves only talk to CDP / Appium. */ import type { Except } from 'type-fest'; /** * Parameters for capturing a screenshot of a running Obsidian instance. */ export interface CaptureScreenshotParams { /** * The working directory (vault path) identifying which Obsidian window to * capture. * * Mirrors the `cwd` of an evaluation: a desktop instance can hold several * vault windows, and the capture has to be routed to the right one. */ readonly cwd: string; /** * The exact height in pixels the captured image should have. * * Desktop only, and only meaningful together with {@link widthInPixels}: the * viewport is pinned to these metrics for the duration of the capture, so the * resulting PNG is exactly this size whatever size the window happens to be. * Omit both to capture the window at its natural size. * * Ignored by the Appium transport, which can only return the device's native * framebuffer — size a mobile capture by choosing an AVD with the wanted * screen geometry instead. */ readonly heightInPixels?: number; /** * The exact width in pixels the captured image should have. * * See {@link heightInPixels} — the two are set together or not at all. */ readonly widthInPixels?: number; } /** * The pixel dimensions read out of a PNG's IHDR header. */ export interface PngDimensions { /** * The image height in pixels. */ readonly heightInPixels: number; /** * The image width in pixels. */ readonly widthInPixels: number; } /** * Builds the `Emulation.setDeviceMetricsOverride` payload that pins a desktop * capture to an exact pixel size. * * Takes only the size half of {@link CaptureScreenshotParams} — routing the * capture to a window is the transport's job, not the payload's. * * @param params - The requested capture size. * @returns The CDP payload, or `undefined` when no size was requested (capture the window as it is). * @throws Error if exactly one of the two dimensions is given — a half-specified size cannot be honoured. */ export declare function buildDeviceMetricsOverride(params: Except): Record | undefined; /** * Decodes the base64 payload both CDP (`Page.captureScreenshot`) and Appium * (`takeScreenshot`) return into raw PNG bytes. * * @param base64 - The base64-encoded image data. * @returns The decoded bytes. */ export declare function decodeBase64Png(base64: string): Uint8Array; /** * Decides whether the given bytes are a PNG carrying an IHDR chunk. * * Used to fail a capture loudly when a transport hands back something that is * not an image, rather than writing a corrupt file to disk. * * @param bytes - The bytes to check. * @returns `true` when the bytes are a PNG. */ export declare function isPng(bytes: Uint8Array): boolean; /** * Reads a PNG's pixel dimensions from its IHDR header. * * The whole point is verification: a capture that silently comes back at the * wrong size is the failure mode that produces an off-spec screenshot set, so * the size is read back from the bytes rather than assumed from the request. * * @param bytes - The PNG bytes. * @returns The image's width and height in pixels. * @throws Error if the bytes are not a PNG, or are too short to carry an IHDR header. */ export declare function readPngDimensions(bytes: Uint8Array): PngDimensions;