import { defineComponent as _, defineAsyncComponent as I, ref as p, shallowRef as m, computed as B, watch as R, onMounted as E, onBeforeUnmount as P, createElementBlock as g, openBlock as d, createElementVNode as i, renderSlot as h, createBlock as L, createCommentVNode as w, createVNode as N, normalizeClass as S, unref as V, Transition as F, withCtx as T } from "vue";
const $ = { class: "leading-none" }, q = { class: "relative h-full w-full bg-white leading-none" }, z = ["width", "height"], A = {
  key: 0,
  class: "absolute inset-0 flex items-center bg-black/5"
}, U = /* @__PURE__ */ _({
  __name: "vPdfPageRenderer",
  props: {
    pageInfo: {},
    pdf: {},
    textLayer: { type: Boolean, default: !1 },
    render: { type: Boolean, default: !1 },
    onRender: { type: Function, default: () => {
    } },
    onError: {}
  },
  setup(y, { expose: b }) {
    const x = I(() => import("./nUErmb8O.js")), a = y, t = p(!1), l = p(), c = m(), n = m(), o = B(
      () => {
        var e;
        return (e = l.value) == null ? void 0 : e.getContext("2d", {
          alpha: !1,
          willReadFrequently: !0
        });
      }
    ), u = async () => {
      var e, r;
      if (!t.value && l.value && o.value) {
        t.value = !0;
        const { viewport: f, page: k } = a.pageInfo, { promise: C } = a.pdf, v = await C;
        try {
          n.value = await v.getPage(k);
          const s = {
            canvasContext: o.value,
            viewport: f
          };
          c.value = n.value.render(s), await c.value.promise, l.value && o.value && a.onRender({
            canvas: l.value,
            context: o.value,
            viewport: f,
            doc: v
          });
        } catch (s) {
          (e = a.onError) == null || e.call(a, s), s.name != "RenderingCancelledException";
        } finally {
          t.value = !1, (r = n.value) == null || r.cleanup(!0);
        }
      }
    };
    return R(
      () => a.render,
      async (e) => {
        e && !n.value && await u();
      }
    ), E(async () => {
      a.render && await u();
    }), P(async () => {
      var e;
      t.value && c.value.cancel(), (e = n.value) == null || e.cleanup();
    }), b({
      context: o,
      canvas: l
    }), (e, r) => (d(), g("div", $, [
      i("div", q, [
        h(e.$slots, "prepend"),
        i("canvas", {
          ref_key: "canva",
          ref: l,
          class: S(["box-border h-full w-full border border-gray-400 bg-white outline-none", {
            hidden: t.value
          }]),
          width: e.pageInfo.viewport.width,
          height: e.pageInfo.viewport.height
        }, null, 10, z),
        e.textLayer && n.value ? (d(), L(V(x), {
          key: 0,
          page: n.value,
          pageInfo: e.pageInfo
        }, null, 8, ["page", "pageInfo"])) : w("", !0),
        N(F, {
          "enter-from-class": "opacity-0 blur-sm",
          "leave-to-class": "opacity-0 blur-sm",
          "enter-active-class": "transition",
          "leave-active-class": "transition"
        }, {
          default: T(() => [
            t.value ? (d(), g("div", A, r[0] || (r[0] = [
              i("div", { class: "mx-auto" }, [
                i("span", {
                  class: "realtive block h-[1em] w-[1em] animate-mltShdSpin overflow-hidden rounded-full -indent-[9999em] text-sm leading-none text-black",
                  style: { transform: "translateZ(0)" }
                })
              ], -1)
            ]))) : w("", !0)
          ]),
          _: 1
        }),
        h(e.$slots, "append")
      ])
    ]));
  }
});
export {
  U as default
};
//# sourceMappingURL=CNx3-bqR.js.map
