import { jsx as j } from "react/jsx-runtime";
import { useRef as B, useEffect as O } from "react";
const D = {
  default: ["#5470c6", "#91cc75", "#fac858", "#ee6666", "#73c0de", "#3ba272", "#fc8452", "#9a60b4", "#ea7ccc", "#48b8d0"],
  blue: ["#1890ff", "#096dd9", "#0050b3", "#003a8c", "#002766", "#40a9ff", "#69c0ff", "#91d5ff", "#bae7ff", "#d6e4ff"],
  green: ["#52c41a", "#389e0d", "#237804", "#135200", "#092b00", "#73d13d", "#95de64", "#b7eb8f", "#d9f7be", "#f6ffed"],
  warm: ["#ff4d4f", "#ff7a45", "#ffa940", "#ffc53d", "#ffec3d", "#fa541c", "#fa8c16", "#faad14", "#fadb14", "#ffec3d"],
  cool: ["#13c2c2", "#08979c", "#006d75", "#00474f", "#002329", "#36cfc9", "#5cdbd3", "#87e8de", "#b5f5ec", "#e6fffb"],
  rainbow: ["#f5222d", "#fa541c", "#fa8c16", "#faad14", "#fadb14", "#a0d911", "#52c41a", "#13c2c2", "#1890ff", "#2f54eb", "#722ed1", "#eb2f96"]
}, P = (s, r, e, i, h) => {
  const p = e / 2, v = i / 2, c = s - p, a = r - v;
  switch (h) {
    case "circle":
      const M = Math.min(e, i) / 2 - 20;
      return c * c + a * a <= M * M;
    case "diamond":
      return Math.abs(c) / (e / 2 - 20) + Math.abs(a) / (i / 2 - 20) <= 1;
    case "triangle":
      const u = i / 2 - 20, g = e / 2 - 20;
      return a >= -u / 3 && a <= u * 2 / 3 && Math.abs(c) <= g * (1 - (a + u / 3) / u);
    case "rect":
    default:
      return Math.abs(c) <= e / 2 - 20 && Math.abs(a) <= i / 2 - 20;
  }
};
function G({ data: s, width: r, height: e, config: i = {} }) {
  const h = B(null), {
    shape: p = "circle",
    colorScheme: v = "default",
    minFontSize: c = 12,
    maxFontSize: a = 48,
    fontFamily: M = "Arial, sans-serif",
    fontWeight: u = "bold",
    rotation: g = !1,
    rotationRange: S = [-90, 90],
    gridSize: f = 8
  } = i;
  return O(() => {
    const W = h.current;
    if (!W || !s || s.length === 0) return;
    const n = W.getContext("2d");
    if (!n) return;
    n.clearRect(0, 0, r, e);
    const E = Math.max(...s.map((t) => t.value)), A = Math.min(...s.map((t) => t.value)), C = D[v] || D.default, F = [], H = (t, b, y, R) => {
      for (const m of F)
        if (!(t + y < m.x - f || t > m.x + m.width + f || b + R < m.y - f || b > m.y + m.height + f))
          return !0;
      return !1;
    };
    [...s].sort((t, b) => b.value - t.value).forEach((t, b) => {
      const y = Math.max(c, Math.min(
        a,
        c + (t.value - A) / (E - A || 1) * (a - c)
      )), R = g ? S[0] + Math.random() * (S[1] - S[0]) : 0;
      n.font = `${u} ${y}px ${M}`;
      const x = n.measureText(t.name).width, o = y;
      let X = !1, z = 0;
      const I = 200;
      for (; !X && z < I; ) {
        const Y = z * 0.3, $ = 5 + z * 3, T = r / 2, V = e / 2;
        let l = T + $ * Math.cos(Y), d = V + $ * Math.sin(Y);
        P(l, d, r, e, p) && (l = l - x / 2, d = d + o / 2, l = Math.max(5, Math.min(r - x - 5, l)), d = Math.max(o + 5, Math.min(e - 5, d)), H(l, d - o, x, o) || (n.save(), n.translate(l + x / 2, d - o / 2), n.rotate(R * Math.PI / 180), n.fillStyle = C[b % C.length], n.fillText(t.name, -x / 2, o / 2), n.restore(), F.push({
          x: l - f,
          y: d - o - f,
          width: x + f * 2,
          height: o + f * 2
        }), X = !0)), z++;
      }
    });
  }, [s, r, e, p, v, c, a, M, u, g, S, f]), /* @__PURE__ */ j(
    "canvas",
    {
      ref: h,
      width: r,
      height: e,
      style: { width: "100%", height: "100%" }
    }
  );
}
export {
  G as default
};
//# sourceMappingURL=WordCloudChart-Nk3RzAK1.mjs.map
