From 717a51c6739eb4321f17c4953c134e84b8028fe9 Mon Sep 17 00:00:00 2001 From: Konrad Liebig Date: Fri, 16 Jan 2026 14:42:09 +0100 Subject: [PATCH] Improve types - Removes unnecessary `declare module` to allow aliasing the module. - Exports interfaces - Adds missing `pagebreak` --- type.d.ts | 94 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/type.d.ts b/type.d.ts index 58a82759..8a5f3033 100644 --- a/type.d.ts +++ b/type.d.ts @@ -1,49 +1,55 @@ -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"; - }; - } +export type PageBreakMode = "avoid-all" | "css" | "legacy"; - 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; +export interface Html2PdfOptions { + margin?: number | [number, number] | [number, number, number, number]; + filename?: string; + pagebreak?: { + mode?: PageBreakMode | PageBreakMode[]; + before?: string | string[]; + after?: string | string[]; + avoid?: string | string[]; } + image?: { + type?: "jpeg" | "png" | "webp"; + quality?: number; + }; + enableLinks?: boolean; + html2canvas?: object; + jsPDF?: { + unit?: string; + format?: string | [number, number]; + orientation?: "portrait" | "landscape"; + }; +} - interface Html2PdfStatic { - (): Html2PdfWorker; - new (): Html2PdfWorker; - (element: HTMLElement, options?: Html2PdfOptions): Promise; - new (element: HTMLElement, options?: Html2PdfOptions): Promise; - Worker: new () => Html2PdfWorker; - } +export 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; +} - const html2pdf: Html2PdfStatic; - export default html2pdf; +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;