// src/worker/index.ts
import path from "node:path";
import { fileURLToPath } from "node:url";

// dataurl:/home/runner/work/pdf-parse/pdf-parse/node_modules/pdfjs-dist/legacy/build/pdf.worker.min.mjs
var pdf_worker_min_default = "data:text/javascript;base64,[encoded data, 1465556 characters]";

// src/worker/canvas.ts
import { Canvas, createCanvas, DOMMatrix, ImageData, Path2D } from "@napi-rs/canvas";
global.DOMMatrix = DOMMatrix;
global.Path2D = Path2D;
global.ImageData = ImageData;
var CanvasFactory = class {
  create(width, height) {
    if (width <= 0 || height <= 0) {
      throw new Error("Invalid canvas size");
    }
    const canvas = createCanvas(width, height);
    const context = canvas.getContext("2d");
    return { canvas, context };
  }
  reset(canvasAndContext, width, height) {
    if (!canvasAndContext.canvas) {
      throw new Error("Canvas is not specified");
    }
    if (width <= 0 || height <= 0) {
      throw new Error("Invalid canvas size");
    }
    canvasAndContext.canvas.width = width;
    canvasAndContext.canvas.height = height;
  }
  destroy(canvasAndContext) {
    if (!canvasAndContext.canvas) {
      throw new Error("Canvas is not specified");
    }
    canvasAndContext.canvas.width = 0;
    canvasAndContext.canvas.height = 0;
    canvasAndContext.canvas = null;
    canvasAndContext.context = null;
  }
};

// src/worker/index.ts
var runtimeDirname;
if (typeof __dirname !== "undefined") {
  runtimeDirname = __dirname;
} else {
  const __filename = fileURLToPath(import.meta.url);
  runtimeDirname = path.dirname(__filename);
}
(async () => {
  try {
    await import("pdfjs-dist/legacy/build/pdf.worker.mjs");
  } catch (err) {
    console.error("pdf.worker load error!..\n", err);
  }
})();
function getData() {
  return pdf_worker_min_default;
}
function getPath() {
  return path.resolve(runtimeDirname, "../pdf.worker.mjs");
}
export {
  CanvasFactory,
  getData,
  getPath
};
