const K = 3;
function E(A, a) {
  let h = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1;
  const t = document.createElement("canvas"), r = t.getContext("2d"), s = A * h, m = a * h;
  return t.setAttribute("width", `${s}px`), t.setAttribute("height", `${m}px`), r.save(), [r, t, s, m];
}
function O() {
  function A(a, h, t, r, s, m, L, T) {
    const [o, N, l, d] = E(r, s, t);
    if (a instanceof HTMLImageElement)
      o.drawImage(a, 0, 0, l, d);
    else {
      const {
        color: e,
        fontSize: n,
        fontStyle: f,
        fontWeight: c,
        fontFamily: $,
        textAlign: k
      } = m, Y = Number(n) * t;
      o.font = `${f} normal ${c} ${Y}px/${s}px ${$}`, o.fillStyle = e, o.textAlign = k, o.textBaseline = "top";
      const w = Array.isArray(a) ? a : [a];
      w == null || w.forEach((z, q) => {
        o.fillText(z ?? "", l / 2, q * (Y + 3 * t));
      });
    }
    const i = Math.PI / 180 * Number(h), F = Math.max(r, s), [H, P, x] = E(F, F, t);
    H.translate(x / 2, x / 2), H.rotate(i), l > 0 && d > 0 && H.drawImage(N, -l / 2, -d / 2);
    function R(e, n) {
      const f = e * Math.cos(i) - n * Math.sin(i), c = e * Math.sin(i) + n * Math.cos(i);
      return [f, c];
    }
    let p = 0, I = 0, M = 0, S = 0;
    const v = l / 2, C = d / 2;
    [[0 - v, 0 - C], [0 + v, 0 - C], [0 + v, 0 + C], [0 - v, 0 + C]].forEach((e) => {
      let [n, f] = e;
      const [c, $] = R(n, f);
      p = Math.min(p, c), I = Math.max(I, c), M = Math.min(M, $), S = Math.max(S, $);
    });
    const B = p + x / 2, D = M + x / 2, g = I - p, u = S - M, W = L * t, b = T * t, G = (g + W) * 2, X = u + b, [U, j] = E(G, X);
    function y() {
      let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
      U.drawImage(P, B, D, g, u, e, n, g, u);
    }
    return y(), y(g + W, -u / 2 - b / 2), y(g + W, +u / 2 + b / 2), [j.toDataURL(), G / t, X / t];
  }
  return A;
}
export {
  K as FontGap,
  O as default
};
