'use client';

// src/lib/browser-pdfjs.ts
var workerSrc;
function setPdfWorkerSrc(src) {
  workerSrc = src;
}
var pdfjsPromise;
async function getPdfjs() {
  if (!pdfjsPromise) {
    pdfjsPromise = import("pdfjs-dist").then((pdfjsLib) => {
      if (workerSrc) {
        pdfjsLib.GlobalWorkerOptions.workerSrc = workerSrc;
      }
      return pdfjsLib;
    });
  }
  return pdfjsPromise;
}
async function loadPdfDocument(url) {
  const pdfjsLib = await getPdfjs();
  return pdfjsLib.getDocument({ url }).promise;
}
async function renderPdfPageToDataUrl(page, scale = 1) {
  const viewport = page.getViewport({ scale });
  const canvas = document.createElement("canvas");
  canvas.width = viewport.width;
  canvas.height = viewport.height;
  await page.render({ canvas, viewport }).promise;
  return {
    dataUrl: canvas.toDataURL("image/png"),
    width: viewport.width,
    height: viewport.height
  };
}

// src/lib/anchor-rect.ts
function toViewportAnchorRect(origin, x, y, width, height) {
  const left = origin.left + x;
  const top = origin.top + y;
  return { x: left, y: top, width, height, top, right: left + width, bottom: top + height, left };
}

export {
  setPdfWorkerSrc,
  loadPdfDocument,
  renderPdfPageToDataUrl,
  toViewportAnchorRect
};
//# sourceMappingURL=chunk-VXASXU4K.js.map