const h = async (e, n) => {
  const o = await (await fetch(e)).blob();
  return new File([o], n || w(e), { type: o.type });
}, w = (e) => {
  const t = new URL(e).pathname.split("/").pop() || "image";
  return (t?.includes(".") ? t.split(".").pop() : "") ? t : `${t}.jpg`;
}, g = (e) => new Promise((n, t) => {
  const o = new Image(), s = new FileReader();
  s.onload = (r) => {
    o.onload = () => {
      n(o);
    }, o.onerror = (a) => {
      URL.revokeObjectURL(o.src), o.src = "", t(a);
    }, r.target && r.target.result && (o.src = r.target.result);
  }, s.onerror = t, s.readAsDataURL(e);
}), d = async (e) => {
  const n = await g(e), t = n.width, o = n.height;
  return URL.revokeObjectURL(n.src), n.src = "", { width: t, height: o };
}, p = async (e, n, t) => {
  const o = await g(e), s = document.createElement("canvas"), r = s.getContext("2d");
  if (!r)
    throw new Error("Failed to get canvas context");
  const a = t.width, c = t.height;
  return s.width = a, s.height = c, console.log(n), console.log(t), r.drawImage(
    o,
    t.x,
    t.y,
    a,
    c,
    0,
    0,
    a,
    c
  ), new Promise((l, m) => {
    s.toBlob((i) => {
      if (!i) {
        m(new Error("Failed to convert canvas to blob"));
        return;
      }
      l(new File([i], e.name, { type: "image/jpeg" }));
    }, "image/jpeg");
  });
}, u = (e, n) => e.size < n * 1e3 * 1e3, f = (e, n) => n.includes(e.type);
export {
  u as a,
  f as b,
  p as c,
  h as f,
  d as g
};
