UNPKG

printd

Version:

Print HTML elements in modern browsers.

70 lines (69 loc) 2.64 kB
export declare function createStyle(doc: Document, cssText: string): HTMLStyleElement; export declare function createLinkStyle(doc: Document, url: string): HTMLLinkElement; export declare function createIFrame(parent: HTMLElement): HTMLIFrameElement; export interface PrintdOptions { /** Parent element where the printable element will be appended. */ parent?: HTMLElement; /** Specifies a custom document head elements */ headElements?: HTMLElement[]; /** Specifies a custom document body elements */ bodyElements?: HTMLElement[]; [key: string]: HTMLElement | HTMLElement[] | undefined; } export interface PrintdCallbackArgs { /** Iframe reference */ iframe: HTMLIFrameElement; /** HTMLElement copy reference */ element?: HTMLElement; /** Function to launch the print dialog after content was loaded */ launchPrint: Function; } export declare type PrintdCallback = (args: PrintdCallbackArgs) => void; /** Printd class that prints HTML elements in a blank document */ export default class Printd { private readonly opts; private readonly iframe; private isLoading; private hasEvents; private callback?; private onbeforeprint?; private onafterprint?; private elCopy?; constructor(options?: PrintdOptions); /** Gets current Iframe reference */ getIFrame(): HTMLIFrameElement; /** * Print an HTMLElement * * @param el HTMLElement * @param styles Optional styles (css texts or urls) that will add to iframe document.head * @param scripts Optional scripts (script texts or urls) that will add to iframe document.body * @param callback Optional callback that will be triggered when content is ready to print */ print(el: HTMLElement, styles?: string[], scripts?: string[], callback?: PrintdCallback): void; /** * Print an URL * * @param url URL to print * @param callback Optional callback that will be triggered when content is ready to print */ printURL(url: string, callback?: PrintdCallback): void; /** * Add a browser `beforeprint` print event listener providing a custom callback. * * Note that it only works when printing custom HTML elements. * */ onBeforePrint(callback: (event: Event) => void): void; /** * Add a browser `afterprint` print event listener providing a custom callback. * * Note that it only works when printing custom HTML elements. * */ onAfterPrint(callback: (event: Event) => void): void; private launchPrint; private addEvents; private onLoad; } export { Printd };