interface Options { /** * Width in pixels to be applied to node before rendering. */ width?: number; /** * Height in pixels to be applied to node before rendering. */ height?: number; /** * A number between `0` and `1` indicating image quality (e.g. 0.92 => 92%) of the JPEG image. */ quality?: number; /** * A string indicating the image format. The default type is image/png; that type is also used if the given type isn't supported. */ type?: string; /** * The pixel ratio of captured image. * * DPI = 96 * scale * * default: 1 */ scale?: number; /** * A string value for the background color, any valid CSS color value. */ backgroundColor?: string | null; /** * An object whose properties to be copied to node's style before rendering. */ style?: Partial | null; /** * A function taking DOM node as argument. Should return `true` if passed * node should be included in the output. Excluding node means excluding * it's children as well. */ filter?: ((el: Node) => boolean) | null; /** * Maximum canvas size (pixels). * * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas#maximum_canvas_size */ maximumCanvasSize?: number; /** * Load media timeout and fetch remote asset timeout (millisecond). * * default: 30000 */ timeout?: number; /** * Embed assets progress. */ progress?: ((current: number, total: number) => void) | null; /** * Enable debug mode to view the execution time log. */ debug?: boolean; /** * Custom implementation to get image data for a custom URL. * This can be helpful for Capacitor or Cordova when using * native fetch to bypass CORS issues. * * If returns a string, will completely bypass any `Options.fetch` * settings with your custom implementation. * * If returns false, will fall back to normal fetch implementation * * @param url * @returns A data URL for the image */ fetchFn?: ((url: string) => Promise) | null; /** * The options of fetch resources. */ fetch?: { /** * The second parameter of `window.fetch` RequestInit * * default: { * cache: 'force-cache', * } */ requestInit?: RequestInit; /** * Set to `true` to append the current time as a query string to URL * requests to enable cache busting. * * default: false */ bypassingCache?: boolean | RegExp; /** * A data URL for a placeholder image that will be used when fetching * an image fails. Defaults to an empty string and will render empty * areas for failed images. * * default: data:image/png;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 */ placeholderImage?: string | ((cloned: HTMLImageElement | SVGImageElement) => string | Promise); }; /** * The options of fonts download and embed. */ font?: false | { /** * Font minify */ minify?: (font: ArrayBuffer, subset: string) => ArrayBuffer; /** * The preferred font format. If specified all other font formats are ignored. */ preferredFormat?: 'woff' | 'woff2' | 'truetype' | 'opentype' | 'embedded-opentype' | 'svg' | string; /** * A CSS string to specify for font embeds. If specified only this CSS will * be present in the resulting image. */ cssText?: string; }; /** * All enabled features * * default: true */ features?: boolean | { /** * Copy scrollbar css styles * * default: true */ copyScrollbar?: boolean; /** * Remove abnormal attributes to cloned node (for normalize XML) * * default: true */ removeAbnormalAttributes?: boolean; /** * Remove control characters (for normalize XML) * * default: true */ removeControlCharacter?: boolean; /** * Fix svg+xml image decode (for Safari、Firefox) * * default: true */ fixSvgXmlDecode?: boolean; /** * Render scrolled children with scrolled content * * default: false */ restoreScrollPosition?: boolean; }; /** * Canvas `drawImage` interval * is used to fix errors in decoding images in Safari、Firefox * * default: 100 */ drawImageInterval?: number; /** * Web Worker script url */ workerUrl?: string | null; /** * Web Worker number */ workerNumber?: number; /** * Triggered after each node is cloned */ onCloneEachNode?: ((cloned: Node) => void | Promise) | null; /** * Triggered after a node is cloned */ onCloneNode?: ((cloned: Node) => void | Promise) | null; /** * Triggered after a node is embed */ onEmbedNode?: ((cloned: Node) => void | Promise) | null; /** * Triggered after a ForeignObjectSvg is created */ onCreateForeignObjectSvg?: ((svg: SVGSVGElement) => void | Promise) | null; /** * An array of style property names. * Can be used to manually specify which style properties are * included when cloning nodes. * This can be useful for performance-critical scenarios. */ includeStyleProperties?: string[] | null; } interface Request { type: 'image' | 'text'; resolve?: (response: string) => void; reject?: (error: Error) => void; response: Promise; } interface InternalContext { /** * FLAG */ __CONTEXT__: true; /** * Logger */ log: { time: (label: string) => void; timeEnd: (label: string) => void; warn: (...args: any[]) => void; }; /** * Node */ node: T; /** * Owner document */ ownerDocument?: Document; /** * Owner window */ ownerWindow?: Window; /** * DPI * * scale === 1 ? null : 96 * scale */ dpi: number | null; /** * The `style` element under the root `svg` element */ svgStyleElement?: HTMLStyleElement; /** * The `defs` element under the root `svg` element */ svgDefsElement?: SVGDefsElement; /** * The `svgStyleElement` class styles * * Map */ svgStyles: Map; /** * The map of default `getComputedStyle` for all tagnames */ defaultComputedStyles: Map>; /** * The IFrame sandbox used to get the `defaultComputedStyles` */ sandbox?: HTMLIFrameElement; /** * Web Workers */ workers: Worker[]; /** * The map of `font-family` values for all cloend elements */ fontFamilies: Map>; /** * Map */ fontCssTexts: Map; /** * `headers.accept` to use when `window.fetch` fetches images */ acceptOfImage: string; /** * All requests for `fetch` */ requests: Map; /** * Canvas multiple draw image fix svg+xml image decoding in Safari and Firefox */ drawImageCount: number; /** * Wait for all tasks embedded in */ tasks: Promise[]; /** * Automatically destroy context */ autoDestruct: boolean; /** * Is enable * * @param key */ isEnable: (key: string) => boolean; /** * [cloning phase] To get the node style set by the user */ currentNodeStyle?: Map; currentParentNodeStyle?: Map; /** * [cloning phase] shadowDOM root list */ shadowRoots: ShadowRoot[]; } type Context = InternalContext & Required; declare function domToBlob(node: T, options?: Options): Promise; declare function domToBlob(context: Context): Promise; declare function domToCanvas(node: T, options?: Options): Promise; declare function domToCanvas(context: Context): Promise; declare function domToDataUrl(node: T, options?: Options): Promise; declare function domToDataUrl(context: Context): Promise; declare function domToForeignObjectSvg(node: T, options?: Options): Promise; declare function domToForeignObjectSvg(context: Context): Promise; declare function domToImage(node: T, options?: Options): Promise; declare function domToImage(context: Context): Promise; declare function domToJpeg(node: T, options?: Options): Promise; declare function domToJpeg(context: Context): Promise; declare function domToPixel(node: T, options?: Options): Promise; declare function domToPixel(context: Context): Promise; declare function domToPng(node: T, options?: Options): Promise; declare function domToPng(context: Context): Promise; declare function domToSvg(node: T, options?: Options): Promise; declare function domToSvg(context: Context): Promise; declare function domToWebp(node: T, options?: Options): Promise; declare function domToWebp(context: Context): Promise; declare function createContext(node: T, options?: Options & { autoDestruct?: boolean; }): Promise>; declare function destroyContext(context: Context): void; type Media = HTMLVideoElement | HTMLImageElement | SVGImageElement; interface LoadMediaOptions { ownerDocument?: Document; timeout?: number; onError?: (error: Error) => void; onWarn?: (...args: any[]) => void; } declare function loadMedia(media: T, options?: LoadMediaOptions): Promise; declare function loadMedia(media: string, options?: LoadMediaOptions): Promise; declare function waitUntilLoad(node: Node, options?: LoadMediaOptions): Promise; export { type Context, type Options, createContext, destroyContext, domToBlob, domToCanvas, domToDataUrl, domToForeignObjectSvg, domToImage, domToJpeg, domToPixel, domToPng, domToSvg, domToWebp, loadMedia, waitUntilLoad };