@imggion/html2realpdf 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -1
- package/dist/image.d.ts +83 -0
- package/dist/image.js +169 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/libhtml2realpdf.wasm +0 -0
- package/dist/node-source.d.ts +16 -0
- package/dist/node-source.js +155 -0
- package/dist/node-source.js.map +1 -0
- package/dist/node.d.ts +78 -0
- package/dist/node.js +105 -0
- package/dist/node.js.map +1 -0
- package/dist/renderer.d.ts +64 -1
- package/dist/renderer.js +164 -41
- package/dist/renderer.js.map +1 -1
- package/dist/snapshot.d.ts +6 -0
- package/dist/snapshot.js +51 -0
- package/dist/snapshot.js.map +1 -1
- package/dist/types.d.ts +42 -1
- package/dist/types.js.map +1 -1
- package/dist/wasm.d.ts +39 -9
- package/dist/wasm.js +77 -28
- package/dist/wasm.js.map +1 -1
- package/dist/worker.js +9 -0
- package/dist/worker.js.map +1 -1
- package/package.json +11 -2
- package/skills/html2realpdf/SKILL.md +74 -3
package/dist/renderer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAA2E,MAAM,eAAe,CAAC;AAExH,OAAO,EAAE,gBAAgB,EAAkB,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAyB,MAAM,WAAW,CAAC;AAQhF,sEAAsE;AACtE,MAAM,i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IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpH,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,WAAW,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,WAAW,CAAC,MAAmB;IACtC,OAAO,MAAM,CAAC,MAAM,IAAI,IAAI,YAAY,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;AACtF,CAAC","sourcesContent":["/**\n * Renderer factories, execution backends, and per-render pipeline ownership.\n *\n * @packageDocumentation\n */\n\nimport { UnsupportedEnvironmentError, WasmRenderError } from \"./errors.js\";\nimport { normalizePage, type NormalizedPage } from \"./page.js\";\nimport { PdfDocument } from \"./pdf-document.js\";\nimport { snapshotSource, type SnapshotOptions, type SnapshotPageMarginBox, type SnapshotPageRule } from \"./snapshot.js\";\nimport type { CssProfile, FontRegistration, HtmlSource, PageBreakRules, PdfMetadata, RendererInit, RenderOptions } from \"./types.js\";\nimport { preparePdfExtras, type PdfExtras } from \"./attachments.js\";\nimport { WASM_TRAP_STATUS, WasmBridge, type WasmRenderResult } from \"./wasm.js\";\n\n/** Common ownership boundary for main-thread and Worker WASM contexts. */\ninterface Backend {\n render(html: string, page: NormalizedPage, metadata?: PdfMetadata, cssProfile?: CssProfile, marginBoxes?: readonly SnapshotPageMarginBox[], pageRules?: readonly SnapshotPageRule[], signal?: AbortSignal, extras?: PdfExtras): Promise<WasmRenderResult>;\n dispose(): void;\n}\n\n/** Executes the synchronous bridge on the caller's browser thread. */\nclass MainThreadBackend implements Backend {\n constructor(private readonly bridge: WasmBridge) {}\n\n render(html: string, page: NormalizedPage, metadata?: PdfMetadata, cssProfile?: CssProfile, marginBoxes?: readonly SnapshotPageMarginBox[], pageRules?: readonly SnapshotPageRule[], signal?: AbortSignal, extras?: PdfExtras): Promise<WasmRenderResult> {\n if (signal?.aborted) return Promise.reject(abortReason(signal));\n return Promise.resolve(this.bridge.render(html, page, metadata, cssProfile, marginBoxes, pageRules, extras));\n }\n\n dispose(): void {\n this.bridge.dispose();\n }\n}\n\n/** Caller state retained while a Worker render is in flight. */\ninterface PendingRender {\n resolve: (result: WasmRenderResult) => void;\n reject: (error: unknown) => void;\n removeAbort?: () => void;\n}\n\n/** Owns a module Worker and routes concurrent results by request identifier. */\nclass WorkerBackend implements Backend {\n private readonly worker: Worker;\n private readonly pending = new Map<number, PendingRender>();\n private readonly ready: Promise<void>;\n private nextId = 1;\n private disposed = false;\n private failure: unknown;\n\n constructor(wasmUrl: string, fonts: readonly FontRegistration[]) {\n this.worker = new Worker(new URL(\"./worker.js\", import.meta.url), { type: \"module\", name: \"html2realpdf\" });\n this.ready = new Promise<void>((resolve, reject) => {\n const onError = (event: ErrorEvent) => {\n this.worker.removeEventListener(\"message\", onMessage);\n reject(new WasmRenderError(event.message || \"PDF Worker initialization failed\", -20));\n };\n const onMessage = (event: MessageEvent) => {\n if (event.data?.type === \"ready\") {\n this.worker.removeEventListener(\"message\", onMessage);\n this.worker.removeEventListener(\"error\", onError);\n resolve();\n } else if (event.data?.type === \"init-error\") {\n this.worker.removeEventListener(\"message\", onMessage);\n this.worker.removeEventListener(\"error\", onError);\n reject(new WasmRenderError(event.data.error, -20));\n }\n };\n this.worker.addEventListener(\"message\", onMessage);\n this.worker.addEventListener(\"error\", onError, { once: true });\n });\n this.worker.addEventListener(\"message\", (event) => this.handleMessage(event));\n this.worker.addEventListener(\"error\", (event) => {\n this.stop(new WasmRenderError(event.message || \"PDF Worker failed\", WASM_TRAP_STATUS));\n });\n this.worker.postMessage({ type: \"init\", wasmUrl, fonts });\n }\n\n async render(html: string, page: NormalizedPage, metadata?: PdfMetadata, cssProfile?: CssProfile, marginBoxes?: readonly SnapshotPageMarginBox[], pageRules?: readonly SnapshotPageRule[], signal?: AbortSignal, extras?: PdfExtras): Promise<WasmRenderResult> {\n if (this.disposed) throw this.failure;\n if (signal?.aborted) throw abortReason(signal);\n await this.ready;\n if (this.disposed) throw this.failure;\n if (signal?.aborted) throw abortReason(signal);\n\n const id = this.nextId++;\n return new Promise<WasmRenderResult>((resolve, reject) => {\n const pending: PendingRender = { resolve, reject };\n if (signal) {\n const onAbort = () => {\n this.pending.delete(id);\n reject(abortReason(signal));\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n pending.removeAbort = () => signal.removeEventListener(\"abort\", onAbort);\n }\n this.pending.set(id, pending);\n try {\n this.worker.postMessage({ type: \"render\", id, html, page, metadata, cssProfile, marginBoxes, pageRules, extras },\n extras?.attachments?.map((attachment) => attachment.data.buffer) ?? []);\n } catch (error) {\n this.pending.delete(id);\n pending.removeAbort?.();\n reject(error);\n }\n });\n }\n\n dispose(): void {\n this.stop(new Error(\"Renderer was disposed\"));\n }\n\n private stop(error: unknown): void {\n if (this.disposed) return;\n this.disposed = true;\n this.failure = error;\n this.worker.terminate();\n for (const pending of this.pending.values()) {\n pending.removeAbort?.();\n pending.reject(error);\n }\n this.pending.clear();\n }\n\n private handleMessage(event: MessageEvent): void {\n const message = event.data;\n if (message?.type !== \"render-result\" && message?.type !== \"render-error\") return;\n // Even an aborted request can report a trap that invalidates other work.\n if (message.type === \"render-error\" && message.status === WASM_TRAP_STATUS) {\n this.stop(new WasmRenderError(message.error, WASM_TRAP_STATUS));\n return;\n }\n const pending = this.pending.get(message.id);\n if (!pending) return;\n this.pending.delete(message.id);\n pending.removeAbort?.();\n\n if (message.type === \"render-error\") {\n pending.reject(new WasmRenderError(message.error, -21));\n } else {\n pending.resolve({\n bytes: new Uint8Array(message.bytes),\n pageCount: message.pageCount,\n diagnostics: Array.isArray(message.diagnostics) ? message.diagnostics : [],\n });\n }\n }\n}\n\n/**\n * Reusable renderer backed by one Worker or main-thread WASM context.\n *\n * @remarks\n * Create instances with `createRenderer`. Fonts and execution mode belong to\n * the renderer lifetime; each returned `PdfDocument` has its own shorter\n * lifetime. Call `dispose` when the renderer is no longer needed. Input-limit\n * errors leave it reusable; an unexpected WASM trap disposes it permanently.\n */\nexport class Html2RealPdf {\n private disposed = false;\n\n private constructor(private readonly backend: Backend) {}\n\n /** @internal */\n static create(backend: Backend): Html2RealPdf {\n return new Html2RealPdf(backend);\n }\n\n /**\n * Snapshots browser state and renders one PDF.\n *\n * @throws {@link InvalidSourceError} when a ref is null or the source shape is invalid.\n * @throws {@link UnsupportedCssError} when strict CSS or fallback policy rejects input.\n * @throws {@link ResourceLoadError} when required resources cannot be materialized.\n * @throws {@link WasmRenderError} when native limits reject input or WASM fails.\n */\n async render(source: HtmlSource, options: RenderOptions = {}): Promise<PdfDocument> {\n if (this.disposed) throw new Error(\"Renderer has been disposed\");\n if (options.signal?.aborted) throw abortReason(options.signal);\n const extras = preparePdfExtras(options);\n options.onProgress?.({ phase: \"snapshot\", completed: 0, total: 1 });\n const snapshotOptions: SnapshotOptions = {\n resourcePolicy: options.resourcePolicy ?? \"error\",\n cssProfile: options.cssProfile ?? \"document\",\n // Preserve the historical browser snapshot behavior unless callers\n // explicitly request print media. The web-profile example in the public\n // API opts into print rather than silently changing existing documents.\n mediaType: options.mediaType ?? \"screen\",\n unsupportedCss: options.unsupportedCss ?? (options.cssProfile === \"strict\" || options.strict ? \"error\" : \"warn\"),\n // Raster fallback is deliberately opt-in. A caller must acknowledge the\n // loss of native PDF primitives for the affected subtree explicitly.\n fallback: options.fallback ?? \"error\",\n };\n if (options.baseUrl !== undefined) snapshotOptions.baseUrl = options.baseUrl;\n if (options.resourceResolver !== undefined) snapshotOptions.resourceResolver = options.resourceResolver;\n if (options.strict !== undefined) snapshotOptions.strict = options.strict;\n if (options.enableLinks !== undefined) snapshotOptions.enableLinks = options.enableLinks;\n if (options.layoutContext !== undefined) snapshotOptions.layoutContext = options.layoutContext;\n if (options.viewport !== undefined) snapshotOptions.viewport = options.viewport;\n if (options.includeShadowDom !== undefined) snapshotOptions.includeShadowDom = options.includeShadowDom;\n if (options.canvasToSvg !== undefined) snapshotOptions.canvasToSvg = options.canvasToSvg;\n if (options.canvasFallback !== undefined) snapshotOptions.canvasFallback = options.canvasFallback;\n const snapshot = await snapshotSource(source, snapshotOptions);\n if (options.signal?.aborted) throw abortReason(options.signal);\n options.onProgress?.({ phase: \"snapshot\", completed: 1, total: 1 });\n\n options.onProgress?.({ phase: \"wasm\", completed: 0, total: 1 });\n const page = options.page !== undefined ? normalizePage(options.page) : snapshot.page ?? normalizePage();\n let rendered: WasmRenderResult;\n try {\n rendered = await this.backend.render(\n applyPageBreakRules(snapshot.html, options.pageBreak),\n page,\n options.metadata,\n options.cssProfile ?? \"document\",\n snapshot.pageMarginBoxes,\n options.page === undefined ? snapshot.pageRules : undefined,\n options.signal,\n extras,\n );\n } catch (error) {\n if (error instanceof WasmRenderError && error.status === WASM_TRAP_STATUS) this.dispose();\n throw error;\n }\n options.onProgress?.({ phase: \"wasm\", completed: 1, total: 1 });\n options.onProgress?.({ phase: \"complete\", completed: 1, total: 1 });\n return PdfDocument.create(rendered.bytes, rendered.pageCount, [...snapshot.diagnostics, ...rendered.diagnostics]);\n }\n\n /** Terminates the owned backend and rejects future renders. */\n dispose(): void {\n if (this.disposed) return;\n this.disposed = true;\n this.backend.dispose();\n }\n}\n\n/**\n * Creates a reusable renderer with explicit backend and font ownership.\n *\n * @example\n * ```ts\n * const renderer = await createRenderer({ fonts });\n * try {\n * const pdf = await renderer.render(element);\n * try { pdf.download(\"report.pdf\"); } finally { pdf.dispose(); }\n * } finally {\n * renderer.dispose();\n * }\n * ```\n *\n * @throws {@link UnsupportedEnvironmentError} outside a browser or when the\n * requested execution backend is unavailable.\n */\nexport async function createRenderer(init: RendererInit = {}): Promise<Html2RealPdf> {\n if (typeof window === \"undefined\") throw new UnsupportedEnvironmentError();\n if (init.execution !== \"main\" && typeof Worker === \"undefined\") {\n throw new UnsupportedEnvironmentError(\"html2realpdf Worker execution is unavailable; use execution: 'main' as a fallback\");\n }\n const wasmUrl = new URL(init.wasmUrl ?? new URL(\"./libhtml2realpdf.wasm\", import.meta.url), window.location.href).href;\n const backend: Backend = init.execution === \"main\"\n ? new MainThreadBackend(await WasmBridge.create(wasmUrl, init.fonts ?? []))\n : new WorkerBackend(wasmUrl, init.fonts ?? []);\n return Html2RealPdf.create(backend);\n}\n\nlet defaultRenderer: Promise<Html2RealPdf> | undefined;\n\n/**\n * Renders with a lazily created package-default Worker renderer.\n *\n * @remarks\n * The default renderer is cached for the application lifetime and cannot be\n * configured with custom fonts. Use `createRenderer` when deterministic\n * backend disposal or renderer-level configuration is required. The returned\n * document must still be disposed by the caller. After an unexpected WASM trap,\n * the failed render is rejected and the next call creates a fresh renderer;\n * the failed document is never retried automatically.\n *\n * @example\n * ```ts\n * const pdf = await renderPdf(document.querySelector(\"#invoice\")!);\n * try { pdf.download(\"invoice.pdf\"); } finally { pdf.dispose(); }\n * ```\n */\nexport async function renderPdf(source: HtmlSource, options: RenderOptions = {}): Promise<PdfDocument> {\n defaultRenderer ??= createRenderer().catch((error: unknown) => {\n defaultRenderer = undefined;\n throw error;\n });\n const current = defaultRenderer;\n try {\n return await (await current).render(source, options);\n } catch (error) {\n if (error instanceof WasmRenderError && error.status === WASM_TRAP_STATUS && defaultRenderer === current) {\n defaultRenderer = undefined;\n }\n throw error;\n }\n}\n\nfunction applyPageBreakRules(html: string, rules?: PageBreakRules): string {\n if (!rules) return html;\n const declarations: string[] = [];\n // DOM snapshots carry computed break properties as inline declarations.\n // Option-driven rules therefore need author importance to override the\n // snapshot's inline `auto` value while still yielding to inline !important.\n appendSelectorRule(declarations, rules.before, \"break-before:page!important\");\n appendSelectorRule(declarations, rules.after, \"break-after:page!important\");\n appendSelectorRule(declarations, rules.avoid, \"break-inside:avoid!important\");\n if (rules.legacy) declarations.push(\".html2pdf__page-break{break-before:page!important}\");\n if (rules.avoidAll) declarations.push(\"body *{break-inside:avoid!important}\");\n return declarations.length === 0 ? html : `<style data-html2realpdf-pagebreak>${declarations.join(\"\")}</style>${html}`;\n}\n\nfunction appendSelectorRule(output: string[], input: string | readonly string[] | undefined, declaration: string): void {\n const selectors = typeof input === \"string\" ? [input] : input ?? [];\n const safe = selectors.map((selector) => selector.trim()).filter((selector) => selector && !/[{};]/.test(selector));\n if (safe.length > 0) output.push(`${safe.join(\",\")}{${declaration}}`);\n}\n\nfunction abortReason(signal: AbortSignal): unknown {\n return signal.reason ?? new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,aAAa,EAA+B,MAAM,YAAY,CAAC;AACpH,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAgG,MAAM,eAAe,CAAC;AAE7I,OAAO,EAAE,gBAAgB,EAAkB,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAA+C,MAAM,WAAW,CAAC;AAatG,MAAM,kBAAkB,GAAsB,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAS1E,8DAA8D;AAC9D,MAAM,OAAO,iBAAiB;IACC,MAAM;IAAnC,YAA6B,MAAkB;sBAAlB,MAAM;IAAe,CAAC;IAEnD,MAAM,CAAC,IAAY,EAAE,IAAoB,EAAE,QAAsB,EAAE,UAAuB,EAAE,WAA8C,EAAE,SAAuC,EAAE,MAAoB,EAAE,MAAkB;QAC3N,IAAI,MAAM,EAAE,OAAO;YAAE,OAAO,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;QAChE,OAAO,OA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AW,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,WAAW,CAAC,MAAmB;IACtC,OAAO,MAAM,CAAC,MAAM,IAAI,IAAI,YAAY,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;AACtF,CAAC","sourcesContent":["/**\n * Renderer factories, execution backends, and per-render pipeline ownership.\n *\n * @packageDocumentation\n */\n\nimport { UnsupportedEnvironmentError, WasmRenderError } from \"./errors.js\";\nimport { DEFAULT_IMAGE_WIDTH, normalizeImageOptions, RenderedImage, type NormalizedImageOptions } from \"./image.js\";\nimport { normalizePage, type NormalizedPage } from \"./page.js\";\nimport { PdfDocument } from \"./pdf-document.js\";\nimport { snapshotSource, type SnapshotOptions, type SnapshotPageMarginBox, type SnapshotPageRule, type SnapshotResult } from \"./snapshot.js\";\nimport type { CssProfile, Diagnostic, FontRegistration, HtmlSource, ImageRenderOptions, PageBreakRules, PdfMetadata, RendererInit, RenderOptions } from \"./types.js\";\nimport { preparePdfExtras, type PdfExtras } from \"./attachments.js\";\nimport { WASM_TRAP_STATUS, WasmBridge, type WasmImageResult, type WasmRenderResult } from \"./wasm.js\";\n\n/**\n * Turns a public source into the HTML the core renders. Not part of the\n * public API: the browser snapshots live DOM state; Node prepares strings\n * (see `node-source.ts`) and checks core diagnostics against the caller's\n * policies after the render.\n */\nexport interface SourcePreparation {\n prepare(source: HtmlSource, options: SnapshotOptions): Promise<SnapshotResult>;\n check?(diagnostics: readonly Diagnostic[], options: SnapshotOptions): void;\n}\n\nconst browserPreparation: SourcePreparation = { prepare: snapshotSource };\n\n/** Common ownership boundary for main-thread and Worker WASM contexts. */\nexport interface Backend {\n render(html: string, page: NormalizedPage, metadata?: PdfMetadata, cssProfile?: CssProfile, marginBoxes?: readonly SnapshotPageMarginBox[], pageRules?: readonly SnapshotPageRule[], signal?: AbortSignal, extras?: PdfExtras): Promise<WasmRenderResult>;\n renderImage(html: string, image: NormalizedImageOptions, cssProfile: CssProfile, signal?: AbortSignal): Promise<WasmImageResult>;\n dispose(): void;\n}\n\n/** Executes the synchronous bridge on the caller's thread. */\nexport class MainThreadBackend implements Backend {\n constructor(private readonly bridge: WasmBridge) {}\n\n render(html: string, page: NormalizedPage, metadata?: PdfMetadata, cssProfile?: CssProfile, marginBoxes?: readonly SnapshotPageMarginBox[], pageRules?: readonly SnapshotPageRule[], signal?: AbortSignal, extras?: PdfExtras): Promise<WasmRenderResult> {\n if (signal?.aborted) return Promise.reject(abortReason(signal));\n return Promise.resolve(this.bridge.render(html, page, metadata, cssProfile, marginBoxes, pageRules, extras));\n }\n\n renderImage(html: string, image: NormalizedImageOptions, cssProfile: CssProfile, signal?: AbortSignal): Promise<WasmImageResult> {\n if (signal?.aborted) return Promise.reject(abortReason(signal));\n return Promise.resolve(this.bridge.renderImage(html, image, cssProfile));\n }\n\n dispose(): void {\n this.bridge.dispose();\n }\n}\n\n/** Raw Worker result fields shared by PDF and image renders. */\ninterface WorkerResultMessage {\n bytes: ArrayBuffer | Uint8Array;\n pageCount?: number;\n width?: number;\n height?: number;\n diagnostics?: unknown;\n}\n\n/** Caller state retained while a Worker render is in flight. */\ninterface PendingRender {\n resolve: (result: WorkerResultMessage) => void;\n reject: (error: unknown) => void;\n removeAbort?: () => void;\n}\n\n/** Owns a module Worker and routes concurrent results by request identifier. */\nclass WorkerBackend implements Backend {\n private readonly worker: Worker;\n private readonly pending = new Map<number, PendingRender>();\n private readonly ready: Promise<void>;\n private nextId = 1;\n private disposed = false;\n private failure: unknown;\n\n constructor(wasmUrl: string, fonts: readonly FontRegistration[]) {\n this.worker = new Worker(new URL(\"./worker.js\", import.meta.url), { type: \"module\", name: \"html2realpdf\" });\n this.ready = new Promise<void>((resolve, reject) => {\n const onError = (event: ErrorEvent) => {\n this.worker.removeEventListener(\"message\", onMessage);\n reject(new WasmRenderError(event.message || \"PDF Worker initialization failed\", -20));\n };\n const onMessage = (event: MessageEvent) => {\n if (event.data?.type === \"ready\") {\n this.worker.removeEventListener(\"message\", onMessage);\n this.worker.removeEventListener(\"error\", onError);\n resolve();\n } else if (event.data?.type === \"init-error\") {\n this.worker.removeEventListener(\"message\", onMessage);\n this.worker.removeEventListener(\"error\", onError);\n reject(new WasmRenderError(event.data.error, -20));\n }\n };\n this.worker.addEventListener(\"message\", onMessage);\n this.worker.addEventListener(\"error\", onError, { once: true });\n });\n this.worker.addEventListener(\"message\", (event) => this.handleMessage(event));\n this.worker.addEventListener(\"error\", (event) => {\n this.stop(new WasmRenderError(event.message || \"PDF Worker failed\", WASM_TRAP_STATUS));\n });\n this.worker.postMessage({ type: \"init\", wasmUrl, fonts });\n }\n\n async render(html: string, page: NormalizedPage, metadata?: PdfMetadata, cssProfile?: CssProfile, marginBoxes?: readonly SnapshotPageMarginBox[], pageRules?: readonly SnapshotPageRule[], signal?: AbortSignal, extras?: PdfExtras): Promise<WasmRenderResult> {\n const result = await this.request(\n { type: \"render\", html, page, metadata, cssProfile, marginBoxes, pageRules, extras },\n extras?.attachments?.map((attachment) => attachment.data.buffer) ?? [],\n signal,\n );\n return {\n bytes: new Uint8Array(result.bytes),\n pageCount: result.pageCount ?? 0,\n diagnostics: Array.isArray(result.diagnostics) ? result.diagnostics : [],\n };\n }\n\n async renderImage(html: string, image: NormalizedImageOptions, cssProfile: CssProfile, signal?: AbortSignal): Promise<WasmImageResult> {\n const result = await this.request({ type: \"render-image\", html, image, cssProfile }, [], signal);\n return {\n bytes: new Uint8Array(result.bytes),\n width: result.width ?? 0,\n height: result.height ?? 0,\n diagnostics: Array.isArray(result.diagnostics) ? result.diagnostics : [],\n };\n }\n\n /** Posts one request after initialization and resolves its raw result. */\n private async request(message: Record<string, unknown>, transfer: Transferable[], signal?: AbortSignal): Promise<WorkerResultMessage> {\n if (this.disposed) throw this.failure;\n if (signal?.aborted) throw abortReason(signal);\n await this.ready;\n if (this.disposed) throw this.failure;\n if (signal?.aborted) throw abortReason(signal);\n\n const id = this.nextId++;\n return new Promise<WorkerResultMessage>((resolve, reject) => {\n const pending: PendingRender = { resolve, reject };\n if (signal) {\n const onAbort = () => {\n this.pending.delete(id);\n reject(abortReason(signal));\n };\n signal.addEventListener(\"abort\", onAbort, { once: true });\n pending.removeAbort = () => signal.removeEventListener(\"abort\", onAbort);\n }\n this.pending.set(id, pending);\n try {\n this.worker.postMessage({ ...message, id }, transfer);\n } catch (error) {\n this.pending.delete(id);\n pending.removeAbort?.();\n reject(error);\n }\n });\n }\n\n dispose(): void {\n this.stop(new Error(\"Renderer was disposed\"));\n }\n\n private stop(error: unknown): void {\n if (this.disposed) return;\n this.disposed = true;\n this.failure = error;\n this.worker.terminate();\n for (const pending of this.pending.values()) {\n pending.removeAbort?.();\n pending.reject(error);\n }\n this.pending.clear();\n }\n\n private handleMessage(event: MessageEvent): void {\n const message = event.data;\n if (message?.type !== \"render-result\" && message?.type !== \"render-error\") return;\n // Even an aborted request can report a trap that invalidates other work.\n if (message.type === \"render-error\" && message.status === WASM_TRAP_STATUS) {\n this.stop(new WasmRenderError(message.error, WASM_TRAP_STATUS));\n return;\n }\n const pending = this.pending.get(message.id);\n if (!pending) return;\n this.pending.delete(message.id);\n pending.removeAbort?.();\n\n if (message.type === \"render-error\") {\n // Input-limit and option statuses stay distinguishable from Worker failures.\n pending.reject(new WasmRenderError(message.error, typeof message.status === \"number\" && message.status < 0 ? message.status : -21));\n } else {\n pending.resolve(message);\n }\n }\n}\n\n/**\n * Reusable renderer backed by one Worker or main-thread WASM context.\n *\n * @remarks\n * Create instances with `createRenderer`. Fonts and execution mode belong to\n * the renderer lifetime; each returned `PdfDocument` has its own shorter\n * lifetime. Call `dispose` when the renderer is no longer needed. Input-limit\n * errors leave it reusable; an unexpected WASM trap disposes it permanently.\n */\nexport class Html2RealPdf {\n private disposed = false;\n\n private constructor(private readonly backend: Backend, private readonly preparation: SourcePreparation) {}\n\n /** @internal */\n static create(backend: Backend, preparation: SourcePreparation = browserPreparation): Html2RealPdf {\n return new Html2RealPdf(backend, preparation);\n }\n\n /**\n * Snapshots browser state and renders one PDF.\n *\n * @throws {@link InvalidSourceError} when a ref is null or the source shape is invalid.\n * @throws {@link UnsupportedCssError} when strict CSS or fallback policy rejects input.\n * @throws {@link ResourceLoadError} when required resources cannot be materialized.\n * @throws {@link WasmRenderError} when native limits reject input or WASM fails.\n */\n async render(source: HtmlSource, options: RenderOptions = {}): Promise<PdfDocument> {\n if (this.disposed) throw new Error(\"Renderer has been disposed\");\n if (options.signal?.aborted) throw abortReason(options.signal);\n const extras = preparePdfExtras(options);\n options.onProgress?.({ phase: \"snapshot\", completed: 0, total: 1 });\n const snapshotOptions = snapshotOptionsFor(options, options.cssProfile ?? \"document\");\n if (options.enableLinks !== undefined) snapshotOptions.enableLinks = options.enableLinks;\n const snapshot = await this.preparation.prepare(source, snapshotOptions);\n if (options.signal?.aborted) throw abortReason(options.signal);\n options.onProgress?.({ phase: \"snapshot\", completed: 1, total: 1 });\n\n options.onProgress?.({ phase: \"wasm\", completed: 0, total: 1 });\n const page = options.page !== undefined ? normalizePage(options.page) : snapshot.page ?? normalizePage();\n let rendered: WasmRenderResult;\n try {\n rendered = await this.backend.render(\n applyPageBreakRules(snapshot.html, options.pageBreak),\n page,\n options.metadata,\n options.cssProfile ?? \"document\",\n snapshot.pageMarginBoxes,\n options.page === undefined ? snapshot.pageRules : undefined,\n options.signal,\n extras,\n );\n } catch (error) {\n if (error instanceof WasmRenderError && error.status === WASM_TRAP_STATUS) this.dispose();\n throw error;\n }\n this.preparation.check?.(rendered.diagnostics, snapshotOptions);\n options.onProgress?.({ phase: \"wasm\", completed: 1, total: 1 });\n options.onProgress?.({ phase: \"complete\", completed: 1, total: 1 });\n return PdfDocument.create(rendered.bytes, rendered.pageCount, [...snapshot.diagnostics, ...rendered.diagnostics]);\n }\n\n /**\n * Snapshots browser state and renders one auto-height image.\n *\n * @remarks\n * Accepts the same sources and snapshot/resource options as `render`. The\n * image is `width` CSS pixels wide (multiplied by `scale`) and exactly as\n * tall as the laid-out content. Option errors are thrown before any\n * snapshot work begins.\n *\n * @throws {RangeError} when `quality`, `scale`, `width`, `format`, or `chromaSubsampling` is invalid.\n * @throws {@link InvalidSourceError} when a ref is null or the source shape is invalid.\n * @throws {@link UnsupportedCssError} when strict CSS or fallback policy rejects input.\n * @throws {@link ResourceLoadError} when required resources cannot be materialized.\n * @throws {@link WasmRenderError} when native limits reject input or WASM fails.\n */\n async renderImage(source: HtmlSource, options: ImageRenderOptions = {}): Promise<RenderedImage> {\n if (this.disposed) throw new Error(\"Renderer has been disposed\");\n if (options.signal?.aborted) throw abortReason(options.signal);\n const normalized = normalizeImageOptions(options, defaultImageWidth(source, options));\n const cssProfile = options.cssProfile ?? \"web\";\n options.onProgress?.({ phase: \"snapshot\", completed: 0, total: 1 });\n const snapshotOptions = snapshotOptionsFor(options, cssProfile);\n // Images have no annotations, and the raster backend reads PNG pixels.\n snapshotOptions.enableLinks = false;\n snapshotOptions.imageTarget = true;\n const snapshot = await this.preparation.prepare(source, snapshotOptions);\n if (options.signal?.aborted) throw abortReason(options.signal);\n options.onProgress?.({ phase: \"snapshot\", completed: 1, total: 1 });\n\n options.onProgress?.({ phase: \"wasm\", completed: 0, total: 1 });\n let rendered: WasmImageResult;\n try {\n rendered = await this.backend.renderImage(snapshot.html, normalized.options, cssProfile, options.signal);\n } catch (error) {\n if (error instanceof WasmRenderError && error.status === WASM_TRAP_STATUS) this.dispose();\n throw error;\n }\n this.preparation.check?.(rendered.diagnostics, snapshotOptions);\n options.onProgress?.({ phase: \"wasm\", completed: 1, total: 1 });\n options.onProgress?.({ phase: \"complete\", completed: 1, total: 1 });\n return RenderedImage.create(rendered.bytes, rendered.width, rendered.height, [\n ...normalized.diagnostics,\n ...snapshot.diagnostics,\n ...rendered.diagnostics,\n ]);\n }\n\n /** Terminates the owned backend and rejects future renders. */\n dispose(): void {\n if (this.disposed) return;\n this.disposed = true;\n this.backend.dispose();\n }\n}\n\n/**\n * Creates a reusable renderer with explicit backend and font ownership.\n *\n * @example\n * ```ts\n * const renderer = await createRenderer({ fonts });\n * try {\n * const pdf = await renderer.render(element);\n * try { pdf.download(\"report.pdf\"); } finally { pdf.dispose(); }\n * } finally {\n * renderer.dispose();\n * }\n * ```\n *\n * @throws {@link UnsupportedEnvironmentError} outside a browser or when the\n * requested execution backend is unavailable.\n */\nexport async function createRenderer(init: RendererInit = {}): Promise<Html2RealPdf> {\n if (typeof window === \"undefined\") throw new UnsupportedEnvironmentError();\n if (init.execution !== \"main\" && typeof Worker === \"undefined\") {\n throw new UnsupportedEnvironmentError(\"html2realpdf Worker execution is unavailable; use execution: 'main' as a fallback\");\n }\n const wasmUrl = new URL(init.wasmUrl ?? new URL(\"./libhtml2realpdf.wasm\", import.meta.url), window.location.href).href;\n const backend: Backend = init.execution === \"main\"\n ? new MainThreadBackend(await WasmBridge.create(wasmUrl, init.fonts ?? []))\n : new WorkerBackend(wasmUrl, init.fonts ?? []);\n return Html2RealPdf.create(backend);\n}\n\nlet defaultRenderer: Promise<Html2RealPdf> | undefined;\n\n/**\n * Renders with a lazily created package-default Worker renderer.\n *\n * @remarks\n * The default renderer is cached for the application lifetime and cannot be\n * configured with custom fonts. Use `createRenderer` when deterministic\n * backend disposal or renderer-level configuration is required. The returned\n * document must still be disposed by the caller. After an unexpected WASM trap,\n * the failed render is rejected and the next call creates a fresh renderer;\n * the failed document is never retried automatically.\n *\n * @example\n * ```ts\n * const pdf = await renderPdf(document.querySelector(\"#invoice\")!);\n * try { pdf.download(\"invoice.pdf\"); } finally { pdf.dispose(); }\n * ```\n */\nexport async function renderPdf(source: HtmlSource, options: RenderOptions = {}): Promise<PdfDocument> {\n defaultRenderer ??= createRenderer().catch((error: unknown) => {\n defaultRenderer = undefined;\n throw error;\n });\n const current = defaultRenderer;\n try {\n return await (await current).render(source, options);\n } catch (error) {\n if (error instanceof WasmRenderError && error.status === WASM_TRAP_STATUS && defaultRenderer === current) {\n defaultRenderer = undefined;\n }\n throw error;\n }\n}\n\n/**\n * Renders one image with the lazily created package-default Worker renderer.\n *\n * @remarks\n * Shares the default renderer, its caching, and its trap recovery with\n * `renderPdf`. Dispose the returned image when its object URLs are no\n * longer needed.\n *\n * @example\n * ```ts\n * const image = await renderImage(chartRef, { width: 800, scale: 2, quality: 0.8 });\n * try { image.download(\"chart.jpg\"); } finally { image.dispose(); }\n * ```\n */\nexport async function renderImage(source: HtmlSource, options: ImageRenderOptions = {}): Promise<RenderedImage> {\n defaultRenderer ??= createRenderer().catch((error: unknown) => {\n defaultRenderer = undefined;\n throw error;\n });\n const current = defaultRenderer;\n try {\n return await (await current).renderImage(source, options);\n } catch (error) {\n if (error instanceof WasmRenderError && error.status === WASM_TRAP_STATUS && defaultRenderer === current) {\n defaultRenderer = undefined;\n }\n throw error;\n }\n}\n\n/** Builds snapshot policy shared by PDF and image renders. */\nexport function snapshotOptionsFor(options: RenderOptions | ImageRenderOptions, cssProfile: CssProfile): SnapshotOptions {\n const snapshotOptions: SnapshotOptions = {\n resourcePolicy: options.resourcePolicy ?? \"error\",\n cssProfile,\n // Preserve the historical browser snapshot behavior unless callers\n // explicitly request print media. The web-profile example in the public\n // API opts into print rather than silently changing existing documents.\n mediaType: options.mediaType ?? \"screen\",\n unsupportedCss: options.unsupportedCss ?? (cssProfile === \"strict\" || options.strict ? \"error\" : \"warn\"),\n // Raster fallback is deliberately opt-in. A caller must acknowledge the\n // loss of native PDF primitives for the affected subtree explicitly.\n fallback: options.fallback ?? \"error\",\n };\n if (options.baseUrl !== undefined) snapshotOptions.baseUrl = options.baseUrl;\n if (options.resourceResolver !== undefined) snapshotOptions.resourceResolver = options.resourceResolver;\n if (options.strict !== undefined) snapshotOptions.strict = options.strict;\n if (options.layoutContext !== undefined) snapshotOptions.layoutContext = options.layoutContext;\n if (options.viewport !== undefined) snapshotOptions.viewport = options.viewport;\n if (options.includeShadowDom !== undefined) snapshotOptions.includeShadowDom = options.includeShadowDom;\n if (options.canvasToSvg !== undefined) snapshotOptions.canvasToSvg = options.canvasToSvg;\n if (options.canvasFallback !== undefined) snapshotOptions.canvasFallback = options.canvasFallback;\n return snapshotOptions;\n}\n\n/**\n * Element and ref sources default to their rendered width so the image\n * matches what is on screen; strings use the viewport or 800 CSS pixels.\n */\nfunction defaultImageWidth(source: HtmlSource, options: ImageRenderOptions): number {\n if (typeof source === \"string\") return Math.min(options.viewport?.width ?? DEFAULT_IMAGE_WIDTH, 4096);\n const element = \"current\" in source ? source.current : source;\n if (!element || typeof element.getBoundingClientRect !== \"function\") return DEFAULT_IMAGE_WIDTH;\n const width = Math.ceil(element.getBoundingClientRect().width);\n return width >= 1 ? Math.min(width, 4096) : DEFAULT_IMAGE_WIDTH;\n}\n\nfunction applyPageBreakRules(html: string, rules?: PageBreakRules): string {\n if (!rules) return html;\n const declarations: string[] = [];\n // DOM snapshots carry computed break properties as inline declarations.\n // Option-driven rules therefore need author importance to override the\n // snapshot's inline `auto` value while still yielding to inline !important.\n appendSelectorRule(declarations, rules.before, \"break-before:page!important\");\n appendSelectorRule(declarations, rules.after, \"break-after:page!important\");\n appendSelectorRule(declarations, rules.avoid, \"break-inside:avoid!important\");\n if (rules.legacy) declarations.push(\".html2pdf__page-break{break-before:page!important}\");\n if (rules.avoidAll) declarations.push(\"body *{break-inside:avoid!important}\");\n return declarations.length === 0 ? html : `<style data-html2realpdf-pagebreak>${declarations.join(\"\")}</style>${html}`;\n}\n\nfunction appendSelectorRule(output: string[], input: string | readonly string[] | undefined, declaration: string): void {\n const selectors = typeof input === \"string\" ? [input] : input ?? [];\n const safe = selectors.map((selector) => selector.trim()).filter((selector) => selector && !/[{};]/.test(selector));\n if (safe.length > 0) output.push(`${safe.join(\",\")}{${declaration}}`);\n}\n\nfunction abortReason(signal: AbortSignal): unknown {\n return signal.reason ?? new DOMException(\"The operation was aborted\", \"AbortError\");\n}\n"]}
|
package/dist/snapshot.d.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface SnapshotOptions {
|
|
|
22
22
|
canvasFallback?: CanvasFallbackPolicy;
|
|
23
23
|
includeShadowDom?: boolean;
|
|
24
24
|
enableLinks?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Prepares the snapshot for raster output: the root loses its outer
|
|
27
|
+
* margin so the image starts at its border box, and JPEG resources become
|
|
28
|
+
* PNG because the native raster backend decodes PNG only.
|
|
29
|
+
*/
|
|
30
|
+
imageTarget?: boolean;
|
|
25
31
|
}
|
|
26
32
|
/** Self-contained HTML plus browser-derived paged-media state and diagnostics. */
|
|
27
33
|
export interface SnapshotResult {
|
package/dist/snapshot.js
CHANGED
|
@@ -1322,6 +1322,8 @@ async function snapshotElement(element, options, canvasOrigins) {
|
|
|
1322
1322
|
const materializedInlineSvgs = await materializeInlineSvgs(clone, options, diagnostics);
|
|
1323
1323
|
await materializeBackgroundImages(clone, options, diagnostics);
|
|
1324
1324
|
await materializeImages(clone, options, diagnostics, materializedInlineSvgs);
|
|
1325
|
+
if (options.imageTarget)
|
|
1326
|
+
await prepareImageTarget(clone, options, diagnostics);
|
|
1325
1327
|
const pageStyle = readDefaultPageStyle(element.ownerDocument, options, diagnostics);
|
|
1326
1328
|
return {
|
|
1327
1329
|
clone,
|
|
@@ -2901,6 +2903,55 @@ async function materializeSvgResourceBlob(blob, options, diagnostics, target, sn
|
|
|
2901
2903
|
});
|
|
2902
2904
|
return rasterizeBlobToPng(normalizedBlob);
|
|
2903
2905
|
}
|
|
2906
|
+
/**
|
|
2907
|
+
* Adapts a materialized snapshot for raster output. JPEG images and
|
|
2908
|
+
* backgrounds are re-encoded losslessly as PNG through a canvas so the
|
|
2909
|
+
* native raster backend, which decodes PNG only, can paint them.
|
|
2910
|
+
*/
|
|
2911
|
+
async function prepareImageTarget(root, options, diagnostics) {
|
|
2912
|
+
if (root instanceof HTMLElement || root instanceof SVGElement)
|
|
2913
|
+
root.style.setProperty("margin", "0px");
|
|
2914
|
+
const jpeg = /^data:image\/(?:jpeg|jpg);/i;
|
|
2915
|
+
const toPng = async (source) => rasterizeBlobToPng(await (await fetch(source)).blob());
|
|
2916
|
+
const images = [...root.querySelectorAll("img")];
|
|
2917
|
+
if (root.localName === "img")
|
|
2918
|
+
images.unshift(root);
|
|
2919
|
+
for (const image of images) {
|
|
2920
|
+
const source = image.getAttribute("src") ?? "";
|
|
2921
|
+
if (!jpeg.test(source))
|
|
2922
|
+
continue;
|
|
2923
|
+
try {
|
|
2924
|
+
image.setAttribute("src", await toPng(source));
|
|
2925
|
+
}
|
|
2926
|
+
catch (error) {
|
|
2927
|
+
if (options.resourcePolicy === "error")
|
|
2928
|
+
throw new ResourceLoadError("JPEG image", { cause: error });
|
|
2929
|
+
image.remove();
|
|
2930
|
+
diagnostics.push({ code: "RESOURCE_OMITTED", severity: "warning", message: "JPEG image could not be converted for raster output", phase: "snapshot" });
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
const styled = [...root.querySelectorAll("[style]")];
|
|
2934
|
+
if (root.hasAttribute("style"))
|
|
2935
|
+
styled.unshift(root);
|
|
2936
|
+
for (const element of styled) {
|
|
2937
|
+
const style = element.style;
|
|
2938
|
+
const backgroundImage = style?.getPropertyValue("background-image");
|
|
2939
|
+
if (!backgroundImage || !/data:image\/(?:jpeg|jpg);/i.test(backgroundImage))
|
|
2940
|
+
continue;
|
|
2941
|
+
let converted = backgroundImage;
|
|
2942
|
+
for (const match of backgroundImage.matchAll(/url\(\s*"?(data:image\/(?:jpeg|jpg);[^")]*)"?\s*\)/gi)) {
|
|
2943
|
+
try {
|
|
2944
|
+
converted = converted.replace(match[1], await toPng(match[1]));
|
|
2945
|
+
}
|
|
2946
|
+
catch (error) {
|
|
2947
|
+
if (options.resourcePolicy === "error")
|
|
2948
|
+
throw new ResourceLoadError("JPEG background", { cause: error });
|
|
2949
|
+
converted = converted.replace(match[0], "none");
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
style.setProperty("background-image", converted);
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2904
2955
|
/** Resolves each authored background URL without disturbing native gradients. */
|
|
2905
2956
|
async function materializeBackgroundImages(root, options, diagnostics) {
|
|
2906
2957
|
const elements = [...root.querySelectorAll("[style]")];
|