import { E as p } from "./jspdf.es.min-t_OLULUR.js";
import { d as u } from "./dom-to-png-DtBlqZMR.js";
async function I({ domElement: d, fileName: m, scale: f = 2, options: P = {} }) {
  if (!d) return Promise.reject("No domElement provided");
  const t = {
    width: 595.28,
    height: 841.89
  }, a = await u({ container: d, scale: f });
  return await new Promise((l, w) => {
    const e = new window.Image();
    e.onload = function() {
      const i = e.naturalWidth, r = e.naturalHeight;
      let g = t.width, h = t.width / i * r;
      const o = new p("", "pt", "a4");
      let s = 0, n = r;
      const c = i / t.width * t.height;
      if (n < c)
        o.addImage(
          a,
          "PNG",
          0,
          0,
          g,
          h,
          "",
          "FAST"
        );
      else
        for (; n > 0; )
          o.addImage(
            a,
            "PNG",
            0,
            s,
            g,
            h,
            "",
            "FAST"
          ), n -= c, s -= t.height, n > 0 && o.addPage();
      o.save(`${m}.pdf`), l();
    }, e.onerror = (i) => w("Failed to load image for PDF: " + i), e.src = a;
  });
}
export {
  I as default
};
