UNPKG

@cappa/core

Version:

Core Playwright screenshot functionality for Cappa

127 lines (126 loc) 3.7 kB
import { Browser, BrowserContext, Locator, Page } from "playwright-core"; import { ConsolaInstance } from "consola"; //#region src/screenshot.d.ts declare class ScreenshotTool { browserType: string; headless: boolean; viewport: { width: number; height: number; }; outputDir: string; fullPage: boolean; browser: Browser | null; context: BrowserContext | null; page: Page | null; constructor(options: { browserType?: string; headless?: boolean; viewport?: { width: number; height: number; }; outputDir?: string; fullPage?: boolean; }); init(): Promise<void>; close(): Promise<void>; goTo(page: Page, url: string): Promise<void>; getFilePath(filename: string): string; takeScreenshot(page: Page, filename: string, options?: { fullPage?: boolean; waitForSelector?: string; waitForTimeout?: number; mask?: Locator[]; omitBackground?: boolean; }): Promise<string>; takeElementScreenshot(page: Page, selector: string, options?: { filename?: string; fullPage?: boolean; }): Promise<string>; batchScreenshots(urls: string[], options?: {}): Promise<{ url: string; success: boolean; filepath: string; error?: string; }[]>; takeResponsiveScreenshots(url: string, viewports?: { width: number; height: number; name: string; }[], options?: { fullPage?: boolean; }): Promise<{ viewport: string; success: boolean; filepath: string; error?: string; }[]>; } //#endregion //#region src/plugin.d.ts /** * Plugin function type definition */ type PluginFunction = (screenshotTool: ScreenshotTool, logger: ConsolaInstance) => Promise<any[]>; /** * Plugin definition interface */ type PluginDef = { name: string; description: string; version: string; execute: PluginFunction; validateOptions?: (options: any) => boolean; }; /** * Plugin function type definition */ type Plugin<Config = any> = (config?: Config) => PluginDef; //#endregion //#region src/types.d.ts type PossiblePromise<T> = Promise<T> | T; /** * Config used in `cappa.config.ts` * * @example * import { defineConfig } from '@cappa/core' * export default defineConfig({ * ... * }) */ type UserConfig = { /** * The project root directory, which can be either an absolute path or a path relative to the location of your `cappa.config.ts` file. * @default process.cwd() */ root?: string; outputDir?: string; /** * An array of Cappa plugins used for generation. Each plugin may have additional configurable options (defined within the plugin itself). If a plugin relies on another plugin, an error will occur if the required dependency is missing. Refer to "pre" for more details. */ plugins?: Array<Plugin | PluginDef>; }; type ScreenshotOptions = { fullPage?: boolean; waitForSelector?: string; waitForTimeout?: number; delay?: number; skip?: boolean; mask?: string[]; omitBackground?: boolean; }; interface Exposed { emitCapture(opt: ScreenshotOptions): void; getBaseScreenshotOptions(): ScreenshotOptions; waitBrowserMetricsStable(): Promise<void>; } //#endregion //#region src/config.d.ts /** * Type helper to make it easier to use vite.config.ts accepts a direct UserConfig object, or a function that returns it. The function receives a ConfigEnv object. */ declare function defineConfig(options: PossiblePromise<UserConfig | Array<UserConfig>> | (() => PossiblePromise<UserConfig | Array<UserConfig>>)): typeof options; //#endregion export { type Exposed, type Plugin, type PluginDef, type PluginFunction, type ScreenshotOptions, ScreenshotTool, type UserConfig, defineConfig }; //# sourceMappingURL=index.d.mts.map