function B(t, e) {
  if (t.match(/^[a-z]+:\/\//i))
    return t;
  if (t.match(/^\/\//))
    return window.location.protocol + t;
  if (t.match(/^[a-z]+:/i))
    return t;
  const n = document.implementation.createHTMLDocument(), r = n.createElement("base"), s = n.createElement("a");
  return n.head.appendChild(r), n.body.appendChild(s), e && (r.href = e), s.href = t, s.href;
}
const j = /* @__PURE__ */ (() => {
  let t = 0;
  const e = () => (
    // eslint-disable-next-line no-bitwise
    `0000${(Math.random() * 36 ** 4 << 0).toString(36)}`.slice(-4)
  );
  return () => (t += 1, `u${e()}${t}`);
})();
function m(t) {
  const e = [];
  for (let n = 0, r = t.length; n < r; n++)
    e.push(t[n]);
  return e;
}
let g = null;
function v(t = {}) {
  return g || (t.includeStyleProperties ? (g = t.includeStyleProperties, g) : (g = m(window.getComputedStyle(document.documentElement)), g));
}
function y(t, e) {
  const r = (t.ownerDocument.defaultView || window).getComputedStyle(t).getPropertyValue(e);
  return r ? parseFloat(r.replace("px", "")) : 0;
}
function z(t) {
  const e = y(t, "border-left-width"), n = y(t, "border-right-width");
  return t.clientWidth + e + n;
}
function G(t) {
  const e = y(t, "border-top-width"), n = y(t, "border-bottom-width");
  return t.clientHeight + e + n;
}
function R(t, e = {}) {
  const n = e.width || z(t), r = e.height || G(t);
  return { width: n, height: r };
}
function X() {
  let t, e;
  try {
    e = process;
  } catch {
  }
  const n = e && e.env ? e.env.devicePixelRatio : null;
  return n && (t = parseInt(n, 10), Number.isNaN(t) && (t = 1)), t || window.devicePixelRatio || 1;
}
const u = 16384;
function J(t) {
  (t.width > u || t.height > u) && (t.width > u && t.height > u ? t.width > t.height ? (t.height *= u / t.width, t.width = u) : (t.width *= u / t.height, t.height = u) : t.width > u ? (t.height *= u / t.width, t.width = u) : (t.width *= u / t.height, t.height = u));
}
function K(t, e = {}) {
  return t.toBlob ? new Promise((n) => {
    t.toBlob(n, e.type ? e.type : "image/png", e.quality ? e.quality : 1);
  }) : new Promise((n) => {
    const r = window.atob(t.toDataURL(e.type ? e.type : void 0, e.quality ? e.quality : void 0).split(",")[1]), s = r.length, i = new Uint8Array(s);
    for (let a = 0; a < s; a += 1)
      i[a] = r.charCodeAt(a);
    n(new Blob([i], {
      type: e.type ? e.type : "image/png"
    }));
  });
}
function w(t) {
  return new Promise((e, n) => {
    const r = new Image();
    r.onload = () => {
      r.decode().then(() => {
        requestAnimationFrame(() => e(r));
      });
    }, r.onerror = n, r.crossOrigin = "anonymous", r.decoding = "async", r.src = t;
  });
}
async function Q(t) {
  return Promise.resolve().then(() => new XMLSerializer().serializeToString(t)).then(encodeURIComponent).then((e) => `data:image/svg+xml;charset=utf-8,${e}`);
}
async function Y(t, e, n) {
  const r = "http://www.w3.org/2000/svg", s = document.createElementNS(r, "svg"), i = document.createElementNS(r, "foreignObject");
  return s.setAttribute("width", `${e}`), s.setAttribute("height", `${n}`), s.setAttribute("viewBox", `0 0 ${e} ${n}`), i.setAttribute("width", "100%"), i.setAttribute("height", "100%"), i.setAttribute("x", "0"), i.setAttribute("y", "0"), i.setAttribute("externalResourcesRequired", "true"), s.appendChild(i), i.appendChild(t), Q(s);
}
const l = (t, e) => {
  if (t instanceof e)
    return !0;
  const n = Object.getPrototypeOf(t);
  return n === null ? !1 : n.constructor.name === e.name || l(n, e);
};
function Z(t) {
  const e = t.getPropertyValue("content");
  return `${t.cssText} content: '${e.replace(/'|"/g, "")}';`;
}
function N(t, e) {
  return v(e).map((n) => {
    const r = t.getPropertyValue(n), s = t.getPropertyPriority(n);
    return `${n}: ${r}${s ? " !important" : ""};`;
  }).join(" ");
}
function tt(t, e, n, r) {
  const s = `.${t}:${e}`, i = n.cssText ? Z(n) : N(n, r);
  return document.createTextNode(`${s}{${i}}`);
}
function $(t, e, n, r) {
  const s = window.getComputedStyle(t, n), i = s.getPropertyValue("content");
  if (i === "" || i === "none")
    return;
  const a = j();
  try {
    e.className = `${e.className} ${a}`;
  } catch {
    return;
  }
  const c = document.createElement("style");
  c.appendChild(tt(a, n, s, r)), e.appendChild(c);
}
function et(t, e, n) {
  $(t, e, ":before", n), $(t, e, ":after", n);
}
const T = "application/font-woff", L = "image/jpeg", nt = {
  woff: T,
  woff2: T,
  ttf: "application/font-truetype",
  eot: "application/vnd.ms-fontobject",
  png: "image/png",
  jpg: L,
  jpeg: L,
  gif: "image/gif",
  tiff: "image/tiff",
  svg: "image/svg+xml",
  webp: "image/webp"
};
function rt(t) {
  const e = /\.([^./]*?)$/g.exec(t);
  return e ? e[1] : "";
}
function C(t) {
  const e = rt(t).toLowerCase();
  return nt[e] || "";
}
function it(t) {
  return t.split(/,/)[1];
}
function x(t) {
  return t.search(/^(data:)/) !== -1;
}
function st(t, e) {
  return `data:${e};base64,${t}`;
}
async function U(t, e, n) {
  const r = await fetch(t, e);
  if (r.status === 404)
    throw new Error(`Resource "${r.url}" not found`);
  const s = await r.blob();
  return new Promise((i, a) => {
    const c = new FileReader();
    c.onerror = a, c.onloadend = () => {
      try {
        i(n({ res: r, result: c.result }));
      } catch (o) {
        a(o);
      }
    }, c.readAsDataURL(s);
  });
}
const E = {};
function at(t, e, n) {
  let r = t.replace(/\?.*/, "");
  return n && (r = t), /ttf|otf|eot|woff2?/i.test(r) && (r = r.replace(/.*\//, "")), e ? `[${e}]${r}` : r;
}
async function P(t, e, n) {
  const r = at(t, e, n.includeQueryParams);
  if (E[r] != null)
    return E[r];
  n.cacheBust && (t += (/\?/.test(t) ? "&" : "?") + (/* @__PURE__ */ new Date()).getTime());
  let s;
  try {
    const i = await U(t, n.fetchRequestInit, ({ res: a, result: c }) => (e || (e = a.headers.get("Content-Type") || ""), it(c)));
    s = st(i, e);
  } catch (i) {
    s = n.imagePlaceholder || "";
    let a = `Failed to fetch resource: ${t}`;
    i && (a = typeof i == "string" ? i : i.message), a && console.warn(a);
  }
  return E[r] = s, s;
}
async function ct(t) {
  const e = t.toDataURL();
  return e === "data:," ? t.cloneNode(!1) : w(e);
}
async function ot(t, e) {
  if (t.currentSrc) {
    const i = document.createElement("canvas"), a = i.getContext("2d");
    i.width = t.clientWidth, i.height = t.clientHeight, a == null || a.drawImage(t, 0, 0, i.width, i.height);
    const c = i.toDataURL();
    return w(c);
  }
  const n = t.poster, r = C(n), s = await P(n, r, e);
  return w(s);
}
async function lt(t, e) {
  var n;
  try {
    if (!((n = t == null ? void 0 : t.contentDocument) === null || n === void 0) && n.body)
      return await p(t.contentDocument.body, e, !0);
  } catch {
  }
  return t.cloneNode(!1);
}
async function ut(t, e) {
  return l(t, HTMLCanvasElement) ? ct(t) : l(t, HTMLVideoElement) ? ot(t, e) : l(t, HTMLIFrameElement) ? lt(t, e) : t.cloneNode(k(t));
}
const ft = (t) => t.tagName != null && t.tagName.toUpperCase() === "SLOT", k = (t) => t.tagName != null && t.tagName.toUpperCase() === "SVG";
async function ht(t, e, n) {
  var r, s;
  if (k(e))
    return e;
  let i = [];
  return ft(t) && t.assignedNodes ? i = m(t.assignedNodes()) : l(t, HTMLIFrameElement) && (!((r = t.contentDocument) === null || r === void 0) && r.body) ? i = m(t.contentDocument.body.childNodes) : i = m(((s = t.shadowRoot) !== null && s !== void 0 ? s : t).childNodes), i.length === 0 || l(t, HTMLVideoElement) || await i.reduce((a, c) => a.then(() => p(c, n)).then((o) => {
    o && e.appendChild(o);
  }), Promise.resolve()), e;
}
function mt(t, e, n) {
  const r = e.style;
  if (!r)
    return;
  const s = window.getComputedStyle(t);
  s.cssText ? (r.cssText = s.cssText, r.transformOrigin = s.transformOrigin) : v(n).forEach((i) => {
    let a = s.getPropertyValue(i);
    i === "font-size" && a.endsWith("px") && (a = `${Math.floor(parseFloat(a.substring(0, a.length - 2))) - 0.1}px`), l(t, HTMLIFrameElement) && i === "display" && a === "inline" && (a = "block"), i === "d" && e.getAttribute("d") && (a = `path(${e.getAttribute("d")})`), r.setProperty(i, a, s.getPropertyPriority(i));
  });
}
function gt(t, e) {
  l(t, HTMLTextAreaElement) && (e.innerHTML = t.value), l(t, HTMLInputElement) && e.setAttribute("value", t.value);
}
function dt(t, e) {
  if (l(t, HTMLSelectElement)) {
    const n = e, r = Array.from(n.children).find((s) => t.value === s.getAttribute("value"));
    r && r.setAttribute("selected", "");
  }
}
function yt(t, e, n) {
  return l(e, Element) && (mt(t, e, n), et(t, e, n), gt(t, e), dt(t, e)), e;
}
async function wt(t, e) {
  const n = t.querySelectorAll ? t.querySelectorAll("use") : [];
  if (n.length === 0)
    return t;
  const r = {};
  for (let i = 0; i < n.length; i++) {
    const c = n[i].getAttribute("xlink:href");
    if (c) {
      const o = t.querySelector(c), f = document.querySelector(c);
      !o && f && !r[c] && (r[c] = await p(f, e, !0));
    }
  }
  const s = Object.values(r);
  if (s.length) {
    const i = "http://www.w3.org/1999/xhtml", a = document.createElementNS(i, "svg");
    a.setAttribute("xmlns", i), a.style.position = "absolute", a.style.width = "0", a.style.height = "0", a.style.overflow = "hidden", a.style.display = "none";
    const c = document.createElementNS(i, "defs");
    a.appendChild(c);
    for (let o = 0; o < s.length; o++)
      c.appendChild(s[o]);
    t.appendChild(a);
  }
  return t;
}
async function p(t, e, n) {
  return !n && e.filter && !e.filter(t) ? null : Promise.resolve(t).then((r) => ut(r, e)).then((r) => ht(t, r, e)).then((r) => yt(t, r, e)).then((r) => wt(r, e));
}
const H = /url\((['"]?)([^'"]+?)\1\)/g, pt = /url\([^)]+\)\s*format\((["']?)([^"']+)\1\)/g, bt = /src:\s*(?:url\([^)]+\)\s*format\([^)]+\)[,;]\s*)+/g;
function St(t) {
  const e = t.replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1");
  return new RegExp(`(url\\(['"]?)(${e})(['"]?\\))`, "g");
}
function Et(t) {
  const e = [];
  return t.replace(H, (n, r, s) => (e.push(s), n)), e.filter((n) => !x(n));
}
async function xt(t, e, n, r, s) {
  try {
    const i = n ? B(e, n) : e, a = C(e);
    let c;
    return s || (c = await P(i, a, r)), t.replace(St(e), `$1${c}$3`);
  } catch {
  }
  return t;
}
function Rt(t, { preferredFontFormat: e }) {
  return e ? t.replace(bt, (n) => {
    for (; ; ) {
      const [r, , s] = pt.exec(n) || [];
      if (!s)
        return "";
      if (s === e)
        return `src: ${r};`;
    }
  }) : t;
}
function V(t) {
  return t.search(H) !== -1;
}
async function M(t, e, n) {
  if (!V(t))
    return t;
  const r = Rt(t, n);
  return Et(r).reduce((i, a) => i.then((c) => xt(c, a, e, n)), Promise.resolve(r));
}
async function d(t, e, n) {
  var r;
  const s = (r = e.style) === null || r === void 0 ? void 0 : r.getPropertyValue(t);
  if (s) {
    const i = await M(s, null, n);
    return e.style.setProperty(t, i, e.style.getPropertyPriority(t)), !0;
  }
  return !1;
}
async function Ct(t, e) {
  await d("background", t, e) || await d("background-image", t, e), await d("mask", t, e) || await d("-webkit-mask", t, e) || await d("mask-image", t, e) || await d("-webkit-mask-image", t, e);
}
async function Pt(t, e) {
  const n = l(t, HTMLImageElement);
  if (!(n && !x(t.src)) && !(l(t, SVGImageElement) && !x(t.href.baseVal)))
    return;
  const r = n ? t.src : t.href.baseVal, s = await P(r, C(r), e);
  await new Promise((i, a) => {
    t.onload = i, t.onerror = e.onImageErrorHandler ? (...o) => {
      try {
        i(e.onImageErrorHandler(...o));
      } catch (f) {
        a(f);
      }
    } : a;
    const c = t;
    c.decode && (c.decode = i), c.loading === "lazy" && (c.loading = "eager"), n ? (t.srcset = "", t.src = s) : t.href.baseVal = s;
  });
}
async function $t(t, e) {
  const r = m(t.childNodes).map((s) => O(s, e));
  await Promise.all(r).then(() => t);
}
async function O(t, e) {
  l(t, Element) && (await Ct(t, e), await Pt(t, e), await $t(t, e));
}
function Tt(t, e) {
  const { style: n } = t;
  e.backgroundColor && (n.backgroundColor = e.backgroundColor), e.width && (n.width = `${e.width}px`), e.height && (n.height = `${e.height}px`);
  const r = e.style;
  return r != null && Object.keys(r).forEach((s) => {
    n[s] = r[s];
  }), t;
}
const F = {};
async function I(t) {
  let e = F[t];
  if (e != null)
    return e;
  const r = await (await fetch(t)).text();
  return e = { url: t, cssText: r }, F[t] = e, e;
}
async function A(t, e) {
  let n = t.cssText;
  const r = /url\(["']?([^"')]+)["']?\)/g, i = (n.match(/url\([^)]+\)/g) || []).map(async (a) => {
    let c = a.replace(r, "$1");
    return c.startsWith("https://") || (c = new URL(c, t.url).href), U(c, e.fetchRequestInit, ({ result: o }) => (n = n.replace(a, `url(${o})`), [a, o]));
  });
  return Promise.all(i).then(() => n);
}
function D(t) {
  if (t == null)
    return [];
  const e = [], n = /(\/\*[\s\S]*?\*\/)/gi;
  let r = t.replace(n, "");
  const s = new RegExp("((@.*?keyframes [\\s\\S]*?){([\\s\\S]*?}\\s*?)})", "gi");
  for (; ; ) {
    const o = s.exec(r);
    if (o === null)
      break;
    e.push(o[0]);
  }
  r = r.replace(s, "");
  const i = /@import[\s\S]*?url\([^)]*\)[\s\S]*?;/gi, a = "((\\s*?(?:\\/\\*[\\s\\S]*?\\*\\/)?\\s*?@media[\\s\\S]*?){([\\s\\S]*?)}\\s*?})|(([\\s\\S]*?){([\\s\\S]*?)})", c = new RegExp(a, "gi");
  for (; ; ) {
    let o = i.exec(r);
    if (o === null) {
      if (o = c.exec(r), o === null)
        break;
      i.lastIndex = c.lastIndex;
    } else
      c.lastIndex = i.lastIndex;
    e.push(o[0]);
  }
  return e;
}
async function Lt(t, e) {
  const n = [], r = [];
  return t.forEach((s) => {
    if ("cssRules" in s)
      try {
        m(s.cssRules || []).forEach((i, a) => {
          if (i.type === CSSRule.IMPORT_RULE) {
            let c = a + 1;
            const o = i.href, f = I(o).then((h) => A(h, e)).then((h) => D(h).forEach((S) => {
              try {
                s.insertRule(S, S.startsWith("@import") ? c += 1 : s.cssRules.length);
              } catch (W) {
                console.error("Error inserting rule from remote css", {
                  rule: S,
                  error: W
                });
              }
            })).catch((h) => {
              console.error("Error loading remote css", h.toString());
            });
            r.push(f);
          }
        });
      } catch (i) {
        const a = t.find((c) => c.href == null) || document.styleSheets[0];
        s.href != null && r.push(I(s.href).then((c) => A(c, e)).then((c) => D(c).forEach((o) => {
          a.insertRule(o, a.cssRules.length);
        })).catch((c) => {
          console.error("Error loading remote stylesheet", c);
        })), console.error("Error inlining remote css file", i);
      }
  }), Promise.all(r).then(() => (t.forEach((s) => {
    if ("cssRules" in s)
      try {
        m(s.cssRules || []).forEach((i) => {
          n.push(i);
        });
      } catch (i) {
        console.error(`Error while reading CSS rules from ${s.href}`, i);
      }
  }), n));
}
function Ft(t) {
  return t.filter((e) => e.type === CSSRule.FONT_FACE_RULE).filter((e) => V(e.style.getPropertyValue("src")));
}
async function It(t, e) {
  if (t.ownerDocument == null)
    throw new Error("Provided element is not within a Document");
  const n = m(t.ownerDocument.styleSheets), r = await Lt(n, e);
  return Ft(r);
}
function _(t) {
  return t.trim().replace(/["']/g, "");
}
function At(t) {
  const e = /* @__PURE__ */ new Set();
  function n(r) {
    (r.style.fontFamily || getComputedStyle(r).fontFamily).split(",").forEach((i) => {
      e.add(_(i));
    }), Array.from(r.children).forEach((i) => {
      i instanceof HTMLElement && n(i);
    });
  }
  return n(t), e;
}
async function q(t, e) {
  const n = await It(t, e), r = At(t);
  return (await Promise.all(n.filter((i) => r.has(_(i.style.fontFamily))).map((i) => {
    const a = i.parentStyleSheet ? i.parentStyleSheet.href : null;
    return M(i.cssText, a, e);
  }))).join(`
`);
}
async function Dt(t, e) {
  const n = e.fontEmbedCSS != null ? e.fontEmbedCSS : e.skipFonts ? null : await q(t, e);
  if (n) {
    const r = document.createElement("style"), s = document.createTextNode(n);
    r.appendChild(s), t.firstChild ? t.insertBefore(r, t.firstChild) : t.appendChild(r);
  }
}
async function vt(t, e = {}) {
  const { width: n, height: r } = R(t, e), s = await p(t, e, !0);
  return await Dt(s, e), await O(s, e), Tt(s, e), await Y(s, n, r);
}
async function b(t, e = {}) {
  const { width: n, height: r } = R(t, e), s = await vt(t, e), i = await w(s), a = document.createElement("canvas"), c = a.getContext("2d"), o = e.pixelRatio || X(), f = e.canvasWidth || n, h = e.canvasHeight || r;
  return a.width = f * o, a.height = h * o, e.skipAutoScale || J(a), a.style.width = `${f}`, a.style.height = `${h}`, e.backgroundColor && (c.fillStyle = e.backgroundColor, c.fillRect(0, 0, a.width, a.height)), c.drawImage(i, 0, 0, a.width, a.height), a;
}
async function Ut(t, e = {}) {
  const { width: n, height: r } = R(t, e);
  return (await b(t, e)).getContext("2d").getImageData(0, 0, n, r).data;
}
async function kt(t, e = {}) {
  return (await b(t, e)).toDataURL();
}
async function Ht(t, e = {}) {
  return (await b(t, e)).toDataURL("image/jpeg", e.quality || 1);
}
async function Vt(t, e = {}) {
  const n = await b(t, e);
  return await K(n);
}
async function Mt(t, e = {}) {
  return q(t, e);
}
export {
  Mt as getFontEmbedCSS,
  Vt as toBlob,
  b as toCanvas,
  Ht as toJpeg,
  Ut as toPixelData,
  kt as toPng,
  vt as toSvg
};
//# sourceMappingURL=index-DAIDnjfR.mjs.map
