diff --git a/type.d.ts b/type.d.ts new file mode 100644 index 0000000..58a8275 --- /dev/null +++ b/type.d.ts @@ -0,0 +1,49 @@ +declare module "html2pdf.js" { + interface Html2PdfOptions { + margin?: number | [number, number] | [number, number, number, number]; + filename?: string; + image?: { + type?: "jpeg" | "png" | "webp"; + quality?: number; + }; + enableLinks?: boolean; + html2canvas?: object; + jsPDF?: { + unit?: string; + format?: string | [number, number]; + orientation?: "portrait" | "landscape"; + }; + } + + interface Html2PdfWorker { + from(src: HTMLElement | string | HTMLCanvasElement | HTMLImageElement): this; + to(target: "container" | "canvas" | "img" | "pdf"): this; + toContainer(): this; + toCanvas(): this; + toImg(): this; + toPdf(): this; + output(type?: string, options?: any, src?: "pdf" | "img"): Promise; + outputPdf(type?: string, options?: any): Promise; + outputImg(type?: string, options?: any): Promise; + save(filename?: string): Promise; + set(options: Html2PdfOptions): this; + get(key: string, cbk?: (value: any) => void): Promise; + then(onFulfilled?: (value: any) => T | PromiseLike, onRejected?: (reason: any) => any): Promise; + thenCore(onFulfilled?: (value: any) => T | PromiseLike, onRejected?: (reason: any) => any): Promise; + thenExternal(onFulfilled?: (value: any) => T | PromiseLike, onRejected?: (reason: any) => any): Promise; + catch(onRejected?: (reason: any) => T | PromiseLike): Promise; + catchExternal(onRejected?: (reason: any) => T | PromiseLike): Promise; + error(msg: string): void; + } + + interface Html2PdfStatic { + (): Html2PdfWorker; + new (): Html2PdfWorker; + (element: HTMLElement, options?: Html2PdfOptions): Promise; + new (element: HTMLElement, options?: Html2PdfOptions): Promise; + Worker: new () => Html2PdfWorker; + } + + const html2pdf: Html2PdfStatic; + export default html2pdf; +}