import { o as T, r as W } from "./rolldown-runtime.js";
import { i as D, t as O } from "./vendor/react.js";
import { t as A } from "./dist.js";
import { t as R } from "./utils.js";
var b = /* @__PURE__ */ T(D(), 1), I = {
  cellWidth: 10,
  cellHeight: 20,
  strokeColor: "currentColor",
  textColor: "currentColor",
  backgroundColor: "transparent",
  borderRadius: 2,
  fontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',
  fontSize: 14
}, $ = {
  horizontal: [
    "─",
    "━",
    "═",
    "-"
  ],
  vertical: [
    "│",
    "┃",
    "║",
    "|"
  ],
  corners: {
    topLeft: [
      "┌",
      "┏",
      "╔",
      "+"
    ],
    topRight: [
      "┐",
      "┓",
      "╗",
      "+"
    ],
    bottomLeft: [
      "└",
      "┗",
      "╚",
      "+"
    ],
    bottomRight: [
      "┘",
      "┛",
      "╝",
      "+"
    ]
  },
  tees: {
    left: [
      "├",
      "┣",
      "╠"
    ],
    right: [
      "┤",
      "┫",
      "╣"
    ],
    top: [
      "┬",
      "┳",
      "╦"
    ],
    bottom: [
      "┴",
      "┻",
      "╩"
    ]
  },
  cross: [
    "┼",
    "╋",
    "╬",
    "+"
  ],
  arrows: {
    up: [
      "▲",
      "△",
      "^"
    ],
    down: [
      "▼",
      "▽",
      "v",
      "V"
    ],
    left: [
      "◀",
      "◁",
      "<"
    ],
    right: [
      "▶",
      "▷",
      ">"
    ]
  }
};
function z(r) {
  return $.horizontal.includes(r) || $.vertical.includes(r) || Object.values($.corners).some((i) => i.includes(r)) || Object.values($.tees).some((i) => i.includes(r)) || $.cross.includes(r) || Object.values($.arrows).some((i) => i.includes(r));
}
function N(r) {
  return $.horizontal.includes(r) ? "horizontal" : $.vertical.includes(r) ? "vertical" : Object.values($.corners).some((i) => i.includes(r)) ? "corner" : Object.values($.tees).some((i) => i.includes(r)) ? "tee" : $.cross.includes(r) ? "cross" : Object.values($.arrows).some((i) => i.includes(r)) ? "arrow" : "text";
}
function V(r) {
  for (const [i, e] of Object.entries($.corners)) if (e.includes(r)) return i;
  return null;
}
function F(r) {
  for (const [i, e] of Object.entries($.tees)) if (e.includes(r)) return i;
  return null;
}
function Q(r) {
  for (const [i, e] of Object.entries($.arrows)) if (e.includes(r)) return i;
  return null;
}
function L(r, i = {}) {
  const e = {
    ...I,
    ...i
  }, d = r.split(`
`), f = Math.max(...d.map((a) => a.length)), k = d.length, g = f * e.cellWidth, m = k * e.cellHeight, l = [], v = [], x = /* @__PURE__ */ new Set(), w = [];
  for (let a = 0; a < d.length; a++) {
    const p = d[a] || "";
    let u = "", h = -1;
    for (let c = 0; c <= p.length; c++) {
      const n = p[c] || "";
      if (n && !z(n) && n !== " " && n !== "")
        h === -1 && (h = c), u += n;
      else {
        if (u.length > 0) {
          w.push({
            row: a,
            col: h,
            text: u
          });
          for (let t = h; t < h + u.length; t++) x.add(`${a},${t}`);
        }
        u = "", h = -1;
      }
    }
  }
  for (let a = 0; a < d.length; a++) {
    const p = d[a] || "";
    for (let u = 0; u < p.length; u++) {
      const h = p[u];
      if (!h || x.has(`${a},${u}`)) continue;
      const c = u * e.cellWidth, n = a * e.cellHeight, t = c + e.cellWidth / 2, o = n + e.cellHeight / 2;
      switch (N(h)) {
        case "horizontal":
          l.push(`<line x1="${c}" y1="${o}" x2="${c + e.cellWidth}" y2="${o}" stroke="${e.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
          break;
        case "vertical":
          l.push(`<line x1="${t}" y1="${n}" x2="${t}" y2="${n + e.cellHeight}" stroke="${e.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
          break;
        case "corner": {
          const C = V(h), s = e.borderRadius;
          switch (C) {
            case "topLeft":
              l.push(`<path d="M ${t} ${n + e.cellHeight} L ${t} ${o + s} Q ${t} ${o} ${t + s} ${o} L ${c + e.cellWidth} ${o}" fill="none" stroke="${e.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
              break;
            case "topRight":
              l.push(`<path d="M ${c} ${o} L ${t - s} ${o} Q ${t} ${o} ${t} ${o + s} L ${t} ${n + e.cellHeight}" fill="none" stroke="${e.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
              break;
            case "bottomLeft":
              l.push(`<path d="M ${t} ${n} L ${t} ${o - s} Q ${t} ${o} ${t + s} ${o} L ${c + e.cellWidth} ${o}" fill="none" stroke="${e.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
              break;
            case "bottomRight":
              l.push(`<path d="M ${c} ${o} L ${t - s} ${o} Q ${t} ${o} ${t} ${o - s} L ${t} ${n}" fill="none" stroke="${e.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
              break;
          }
          break;
        }
        case "tee":
          switch (F(h)) {
            case "left":
              l.push(`<line x1="${t}" y1="${n}" x2="${t}" y2="${n + e.cellHeight}" stroke="${e.strokeColor}" stroke-width="1.5"/>`), l.push(`<line x1="${t}" y1="${o}" x2="${c + e.cellWidth}" y2="${o}" stroke="${e.strokeColor}" stroke-width="1.5"/>`);
              break;
            case "right":
              l.push(`<line x1="${t}" y1="${n}" x2="${t}" y2="${n + e.cellHeight}" stroke="${e.strokeColor}" stroke-width="1.5"/>`), l.push(`<line x1="${c}" y1="${o}" x2="${t}" y2="${o}" stroke="${e.strokeColor}" stroke-width="1.5"/>`);
              break;
            case "top":
              l.push(`<line x1="${c}" y1="${o}" x2="${c + e.cellWidth}" y2="${o}" stroke="${e.strokeColor}" stroke-width="1.5"/>`), l.push(`<line x1="${t}" y1="${o}" x2="${t}" y2="${n + e.cellHeight}" stroke="${e.strokeColor}" stroke-width="1.5"/>`);
              break;
            case "bottom":
              l.push(`<line x1="${c}" y1="${o}" x2="${c + e.cellWidth}" y2="${o}" stroke="${e.strokeColor}" stroke-width="1.5"/>`), l.push(`<line x1="${t}" y1="${n}" x2="${t}" y2="${o}" stroke="${e.strokeColor}" stroke-width="1.5"/>`);
              break;
          }
          break;
        case "cross":
          l.push(`<line x1="${c}" y1="${o}" x2="${c + e.cellWidth}" y2="${o}" stroke="${e.strokeColor}" stroke-width="1.5"/>`), l.push(`<line x1="${t}" y1="${n}" x2="${t}" y2="${n + e.cellHeight}" stroke="${e.strokeColor}" stroke-width="1.5"/>`);
          break;
        case "arrow": {
          const C = Q(h), s = Math.min(e.cellWidth, e.cellHeight) * 0.4;
          switch (C) {
            case "up":
              l.push(`<polygon points="${t},${o - s} ${t - s},${o + s / 2} ${t + s},${o + s / 2}" fill="${e.strokeColor}"/>`);
              break;
            case "down":
              l.push(`<polygon points="${t},${o + s} ${t - s},${o - s / 2} ${t + s},${o - s / 2}" fill="${e.strokeColor}"/>`);
              break;
            case "left":
              l.push(`<polygon points="${t - s},${o} ${t + s / 2},${o - s} ${t + s / 2},${o + s}" fill="${e.strokeColor}"/>`);
              break;
            case "right":
              l.push(`<polygon points="${t + s},${o} ${t - s / 2},${o - s} ${t - s / 2},${o + s}" fill="${e.strokeColor}"/>`);
              break;
          }
          break;
        }
      }
    }
  }
  for (const a of w) {
    const p = a.col * e.cellWidth, u = a.row * e.cellHeight + e.cellHeight * 0.7;
    v.push(`<text x="${p}" y="${u}" font-family="${e.fontFamily}" font-size="${e.fontSize}" fill="${e.textColor}">${q(a.text)}</text>`);
  }
  return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${g} ${m}" width="${g}" height="${m}" style="max-width: 100%; height: auto;">
  ${e.backgroundColor !== "transparent" ? `<rect width="100%" height="100%" fill="${e.backgroundColor}"/>` : ""}
  <g class="ascii-lines">
    ${l.join(`
    `)}
  </g>
  <g class="ascii-text">
    ${v.join(`
    `)}
  </g>
</svg>`;
}
function q(r) {
  return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
function _(r, i) {
  try {
    return L(r, i);
  } catch (e) {
    return console.warn("ASCII to SVG conversion failed:", e), null;
  }
}
var y = O(), j = A("relative overflow-hidden rounded-xl border border-border bg-muted", {
  variants: { scaleMode: {
    fit: "w-full [&_svg]:w-full [&_svg]:h-auto",
    scroll: "overflow-x-auto",
    responsive: "w-full [&_svg]:w-full [&_svg]:h-auto [&_svg]:max-h-[500px]"
  } },
  defaultVariants: { scaleMode: "responsive" }
}), B = A("text-xs text-muted-foreground text-center py-2 border-t border-border"), S = b.forwardRef(({ content: r, mode: i = "svg", scaleMode: e, caption: d, className: f, ariaLabel: k }, g) => {
  const [m, l] = b.useState(null), [v, x] = b.useState(i);
  b.useEffect(() => {
    if (i === "monospace") {
      x("monospace");
      return;
    }
    const a = _(r, {
      strokeColor: "var(--border)",
      textColor: "var(--foreground)",
      backgroundColor: "transparent"
    });
    a ? (l(a), x("svg")) : x("monospace");
  }, [r, i]);
  const w = k || `ASCII diagram with ${r.split(`
`).length} lines`;
  return /* @__PURE__ */ (0, y.jsxs)("div", {
    ref: g,
    "data-slot": "ai-ascii-diagram",
    className: R(j({ scaleMode: e }), f),
    role: "img",
    "aria-label": w,
    children: [v === "svg" && m ? /* @__PURE__ */ (0, y.jsx)("div", {
      className: "p-4 [&_svg]:text-foreground",
      "aria-hidden": "true",
      dangerouslySetInnerHTML: { __html: m }
    }) : /* @__PURE__ */ (0, y.jsx)("pre", {
      className: "p-4 font-mono text-sm text-foreground whitespace-pre overflow-x-auto leading-relaxed",
      children: r
    }), d && /* @__PURE__ */ (0, y.jsx)("div", {
      className: B(),
      children: d
    })]
  });
});
S.displayName = "AIAsciiDiagram";
function H(r) {
  return (r.match(/[┌┐└┘├┤┬┴┼─│═║╔╗╚╝╠╣╦╩╬]/g) || []).length < 5 ? !1 : /[┌╔].*[┐╗]/s.test(r) || /[└╚].*[┘╝]/s.test(r);
}
function M(r) {
  const i = r.split(`
`);
  if (i.length < 3) return !1;
  const e = /\+[-=]+\+/, d = /\|.*\|/;
  let f = 0, k = 0;
  for (const g of i)
    e.test(g) && f++, d.test(g) && k++;
  return f >= 2 && k >= 1;
}
function E(r) {
  return H(r) || M(r);
}
var J = /* @__PURE__ */ W({
  AIAsciiDiagram: () => S,
  asciiDiagramVariants: () => j,
  asciiToSvg: () => L,
  default: () => S,
  isAsciiDiagram: () => E,
  looksLikeAsciiDiagram: () => H,
  looksLikeSimpleAscii: () => M,
  tryAsciiToSvg: () => _
});
export {
  S as n,
  J as t
};

//# sourceMappingURL=AIAsciiDiagram.js.map