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";
import { createCanvas } from "@napi-rs/canvas";
import { createRequire } from "node:module";
import { dirname, join } from "node:path";
//#region src/pdfjs.node.ts
var pdfJsDistRoot = dirname(createRequire(import.meta.url).resolve("pdfjs-dist/package.json"));
var getPdfJsWasmUrl = () => join(pdfJsDistRoot, "wasm/");
//#endregion
//#region src/index.node.ts
var clonePdfData = (pdf) => pdf instanceof Uint8Array ? new Uint8Array(pdf) : new Uint8Array(pdf);
var pdfJsWasmUrl = getPdfJsWasmUrl();
var pdf2img = async (pdf, options = {}) => {
	return pdf2img$1(pdf, options, {
		getDocument: (pdf) => pdfjsLib.getDocument({
			data: clonePdfData(pdf),
			wasmUrl: pdfJsWasmUrl
		}).promise,
		createCanvas: (width, height) => createCanvas(width, height),
		canvasToArrayBuffer: (canvas, imageType) => {
			const nodeCanvas = canvas;
			const buffer = imageType === "png" ? nodeCanvas.toBuffer("image/png") : nodeCanvas.toBuffer("image/jpeg");
			const arrayBuffer = new ArrayBuffer(buffer.byteLength);
			new Uint8Array(arrayBuffer).set(buffer);
			return arrayBuffer;
		}
	});
};
var pdf2size = async (pdf, options = {}) => {
	return pdf2size$1(pdf, options, { getDocument: (pdf) => pdfjsLib.getDocument({
		data: clonePdfData(pdf),
		wasmUrl: pdfJsWasmUrl
	}).promise });
};
//#endregion
export { img2pdf, pdf2img, pdf2size };

//# sourceMappingURL=index.node.js.map