import { r as g } from "./number.Dp6Prh44.js";
function m(n, t, e, i) {
  const o = n / t, r = e / i;
  let c = n, a = t;
  return o > r ? c = Math.round(a * r) : a = Math.round(c / r), {
    height: a,
    width: c
  };
}
function p(n, t, e, i, o) {
  const r = new Image();
  return r.src = n, r.crossOrigin = "anonymous", new Promise((c) => {
    r.onload = () => {
      const a = document.createElement("canvas");
      if (t > i || e > o) {
        const h = i / t, l = o / e, u = Math.max(h, l);
        a.width = t * u, a.height = e * u;
      } else
        a.width = t, a.height = e;
      const s = a.getContext("2d");
      s ? (s.drawImage(r, 0, 0, a.width, a.height), c({
        height: a.height,
        url: a.toDataURL("image/jpeg"),
        width: a.width
      })) : c({
        height: e,
        url: n,
        width: t
      });
    }, r.onerror = () => {
      c({
        height: e,
        url: n,
        width: t
      });
    };
  });
}
function R(n, t) {
  const e = new Image();
  return e.src = n.url, e.crossOrigin = "anonymous", new Promise((i) => {
    e.onload = () => {
      const o = document.createElement("canvas");
      o.width = t.width, o.height = t.height;
      const r = o.getContext("2d");
      r ? (r.drawImage(e, -t.x, -t.y, n.width, n.height), i(o.toDataURL("image/jpeg"))) : i(n.url);
    }, e.onerror = () => {
      i(n.url);
    };
  });
}
function S(n, t) {
  const e = new Image();
  return e.src = n.url, e.crossOrigin = "anonymous", new Promise((i) => {
    e.onload = () => {
      const { height: o, width: r } = g(n.width, n.height, t), c = document.createElement("canvas");
      c.width = r, c.height = o;
      const a = c.getContext("2d");
      a ? (a.fillStyle = "white", a.fillRect(0, 0, r, o), a.translate(r / 2, o / 2), a.rotate(t * Math.PI / 180), a.drawImage(
        e,
        -n.width / 2,
        -n.height / 2,
        n.width,
        n.height
      ), a.rotate(-(t * Math.PI) / 180), a.translate(-r / 2, -o / 2), i(c.toDataURL("image/jpeg"))) : i(n.url);
    }, e.onerror = () => {
      i(n.url);
    };
  });
}
function b(n) {
  const t = n.getBoundingClientRect(), e = t.width / t.height, i = n.naturalWidth / n.naturalHeight;
  let o, r;
  return i > e ? (o = t.width, r = t.width / i) : (r = t.height, o = t.height * i), { height: r, width: o };
}
async function d(n) {
  const t = new Image();
  return t.src = n, await t.decode(), [t.naturalWidth, t.naturalHeight];
}
function I(n) {
  const t = n.trim();
  if (!t)
    return !1;
  if (t.startsWith("data:image/") || t.startsWith("blob:"))
    return !0;
  try {
    const e = new URL(t, globalThis.location.href);
    return ["blob:", "data:", "http:", "https:"].includes(e.protocol);
  } catch {
    return !1;
  }
}
async function M(n) {
  try {
    const t = await fetch(n), e = t.headers.get("Content-Type");
    if (!e)
      return null;
    const i = e.split("/")[1], o = await t.blob();
    if (!o)
      return null;
    const r = URL.createObjectURL(o), [c, a] = await d(r);
    return {
      fileExtension: i,
      height: a,
      src: r,
      width: c
    };
  } catch {
    return null;
  }
}
function w(n = /* @__PURE__ */ new Date()) {
  const e = [
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec"
  ][n.getMonth()], i = n.getDate(), o = n.getFullYear();
  let r = n.getHours();
  const a = r < 12 ? "AM" : "PM";
  r = r % 12, r = r === 0 ? 12 : r;
  const s = n.getMinutes().toString().padStart(2, "0"), h = n.getSeconds().toString().padStart(2, "0"), l = n.getMilliseconds().toString().padStart(3, "0");
  return `Screenshot - ${e} ${i} ${o} ${r}-${s}-${h}-${l} ${a}`;
}
function y(n) {
  const t = n.split(".");
  if (t.length <= 1 || n.startsWith(".") && t.length === 2)
    return n.slice(0, 256);
  const e = t.slice(0, -1).join(".").trim();
  return e.length === 0 || e === "image" ? w() : e.slice(0, 256 - t[1].length);
}
export {
  S as a,
  R as b,
  m as c,
  d,
  M as e,
  y as f,
  b as g,
  I as i,
  p as r
};
