import { PDFWorkerMessage } from "./worker" import { PDFWorker } from "../dist/cache/worker" const scriptUrlFromFunction = (fn: Function) => { const blob = new Blob(["(" + fn.toString() + ")()"], { type: "application/javascript" }) return URL.createObjectURL(blob) } export class PDFWorkerHelper extends Worker { constructor() { const url = scriptUrlFromFunction(PDFWorker) super(url) } generatePDF(imgURLs: string[], imgType: "svg" | "png", width: number, height: number): Promise { const msg: PDFWorkerMessage = [ imgURLs, imgType, width, height, ] this.postMessage(msg) return new Promise((resolve) => { this.addEventListener("message", (e) => { resolve(e.data) }) }) } }