import { n as pdf2size$1, r as pdf2img$1, t as img2pdf } from "./img2pdf-Ca1yX5Sv.js";
import * as pdfjsLib from "pdfjs-dist/legacy/build/pdf.mjs";
//#region src/pdfjs-worker.js?worker&url
var pdfjs_worker_default = "" + new URL("assets/pdfjs-worker-DNts7nT2.js", import.meta.url).href;
//#endregion
//#region src/index.browser.ts
var clonePdfData = (pdf) => pdf instanceof Uint8Array ? new Uint8Array(pdf) : new Uint8Array(pdf);
var loadingTaskMap = /* @__PURE__ */ new WeakMap();
var getDocument = async (pdf) => {
	if (typeof Worker !== "undefined" && pdfjsLib.GlobalWorkerOptions.workerSrc !== "" + new URL("assets/pdfjs-worker-DNts7nT2.js", import.meta.url).href) pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjs_worker_default;
	const loadingTask = pdfjsLib.getDocument({ data: clonePdfData(pdf) });
	const document = await loadingTask.promise;
	loadingTaskMap.set(document, { destroy: () => loadingTask.destroy() });
	return document;
};
var destroyDocument = async (document) => {
	const loadingTask = loadingTaskMap.get(document);
	loadingTaskMap.delete(document);
	await loadingTask?.destroy();
};
function dataURLToArrayBuffer(dataURL) {
	const base64String = dataURL.split(",")[1];
	const byteString = atob(base64String);
	const arrayBuffer = new ArrayBuffer(byteString.length);
	const uintArray = new Uint8Array(arrayBuffer);
	for (let i = 0; i < byteString.length; i++) uintArray[i] = byteString.charCodeAt(i);
	return arrayBuffer;
}
var pdf2img = async (pdf, options = {}) => pdf2img$1(pdf, options, {
	getDocument,
	destroyDocument,
	createCanvas: (width, height) => {
		const canvas = document.createElement("canvas");
		canvas.width = width;
		canvas.height = height;
		return canvas;
	},
	canvasToArrayBuffer: (canvas, imageType) => {
		return dataURLToArrayBuffer(canvas.toDataURL(`image/${imageType}`));
	}
});
var pdf2size = async (pdf, options = {}) => pdf2size$1(pdf, options, {
	getDocument,
	destroyDocument
});
//#endregion
export { img2pdf, pdf2img, pdf2size };

//# sourceMappingURL=index.js.map