import { openBlock as f, createElementBlock as p } from "vue";
const _ = {
  __name: "QrLoad",
  emits: ["loaded"],
  setup(w, { emit: d }) {
    async function l(e) {
      const t = await m(e), n = (await import("./jsQR-0211a301.js").then((o) => o.jsQR)).default, a = n(t.data, t.width, t.height);
      console.log(a.data), d("loaded", a == null ? void 0 : a.data);
    }
    async function m(e) {
      var t;
      if (/image.*/.test(e.type)) {
        const n = new FileReader();
        n.readAsDataURL(e);
        const a = await c(n, "load");
        return g((t = a == null ? void 0 : a.target) == null ? void 0 : t.result);
      } else
        console.log("File is not an image");
    }
    async function g(e) {
      if (!e)
        return;
      const t = document.createElement("img");
      return t.src = e, await c(t, "load"), u(t);
    }
    function u(e) {
      const t = e.naturalWidth, n = e.naturalHeight;
      return h(e, t, n);
    }
    function h(e, t, n) {
      const a = document.createElement("canvas"), o = a.getContext("2d");
      a.width = 1920, a.height = 1080;
      const i = Math.min(
        1,
        a.width / t,
        a.height / n
      ), s = i * t, r = i * n;
      return o.drawImage(e, 0, 0, s, r), o.getImageData(0, 0, s, r);
    }
    function c(e, t, n) {
      let a, o;
      const i = new Promise((s, r) => {
        a = s, o = r;
      });
      return e.addEventListener(t, a), e.addEventListener(n, o), i.finally(() => {
        e.removeEventListener(t, a), e.removeEventListener(n, o);
      }), i;
    }
    return (e, t) => (f(), p("input", {
      id: "qr-input",
      type: "file",
      accept: "image/*",
      onChange: t[0] || (t[0] = (n) => l(n.target.files[0]))
    }, null, 32));
  }
};
export {
  _ as default
};
//# sourceMappingURL=QrLoad-eb469a15.js.map
