import { Page } from 'playwright'; import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter'; import { JobStatus } from './job-status.js'; export interface Viewport { width: number; height: number; } export interface ScreenshotOptions { /** * The name of a storage bucket to save screenshots into. * * If no storage bucket is passed in, the project's default bucket is used. */ storage?: string; /** * An optional subdirectory inside the storage bucket to use when saving the screenshots. * * @defaultValue {'screenshots'} * @type {string} */ directory: string; /** * An array of strings specifying viewport sizes for the screen captures. Values can be: * * - Specific dimensions in the format 'WIDTHxHEIGHT' or 'WIDTH,HEIGHT' * - The name of a preset stored in `ScreenshotTool.ViewportPresets` * - The keyword 'all', which expands to *all* stored presets. * * @defaultValue {['hd']} * @type {string[]} */ viewports: string[]; /** * An orientation to use when capturing the screen. If no value is passed in, the viewport's * inherent orientation is used. If `both` is used, a screenshot is captured for * each orientation */ orientation?: 'portrait' | 'landscape' | 'both'; /** * CSS selectors used crop the captured image. * * If DOM elements matching the selectors in question can be found on the page, they * will be scrolled into view and the resulting capture will be cropped to the * dimensions of the DOM element. * * Honestly, haven't tested what happens if multiple selectors are matched on one page. * * @type {string[]} */ selectors: string[]; /** * Capture the full length of the page, even if it scrolls beyond the viewport boundaries. * * @defaultValue: false * @type {boolean} */ fullPage: boolean; /** * File format for the screen capture. * * @defaultValue {'jpeg'} * @type {('jpeg' | 'png')} */ type: 'jpeg' | 'png'; /** * Maximium number of images to capture when multiple elements match the given selector. * * @defaultValue Infinity * @type {Number} */ limit: number; } type ScreenshotEventMap = Record & { progress: [status: JobStatus, message?: string]; end: [status: JobStatus]; }; type ScreenshotEventType = keyof ScreenshotEventMap; type ScreenshotEventParams = ScreenshotEventMap[T]; type ScreenshotEventListener = (...args: ScreenshotEventParams) => unknown; export declare class ScreenshotTool { options: Partial; static ViewportPresets: Record; protected events: AsyncEventEmitter; status: JobStatus; on(event: T, listener: ScreenshotEventListener): this; off(event: T, listener: ScreenshotEventListener): this; protected defaults: ScreenshotOptions; constructor(options?: Partial); capture(page: Page): Promise; protected presetsToViewports(input: string | string[]): Record; protected isPortrait(input: Viewport): boolean; protected rotateViewport(input: Viewport): Viewport; protected forcePortrait(input: Viewport): Viewport; protected forceLandscape(input: Viewport): Viewport; protected getFilename(url: string, viewport: string, selector?: string, fullPage?: boolean): string; protected expandViewports(names?: string | string[], orientation?: string): Record; } export {}; //# sourceMappingURL=screenshot.d.ts.map