//#region src/components/organisms/ai/AIAsciiDiagram/ascii-to-svg.ts
var DEFAULT_OPTIONS = {
	cellWidth: 10,
	cellHeight: 20,
	strokeColor: "currentColor",
	textColor: "currentColor",
	backgroundColor: "transparent",
	borderRadius: 2,
	fontFamily: "ui-monospace, SFMono-Regular, \"SF Mono\", Menlo, monospace",
	fontSize: 14
};
var BOX_CHARS = {
	horizontal: [
		"─",
		"━",
		"═",
		"-"
	],
	vertical: [
		"│",
		"┃",
		"║",
		"|"
	],
	corners: {
		topLeft: [
			"┌",
			"┏",
			"╔",
			"+"
		],
		topRight: [
			"┐",
			"┓",
			"╗",
			"+"
		],
		bottomLeft: [
			"└",
			"┗",
			"╚",
			"+"
		],
		bottomRight: [
			"┘",
			"┛",
			"╝",
			"+"
		]
	},
	tees: {
		left: [
			"├",
			"┣",
			"╠"
		],
		right: [
			"┤",
			"┫",
			"╣"
		],
		top: [
			"┬",
			"┳",
			"╦"
		],
		bottom: [
			"┴",
			"┻",
			"╩"
		]
	},
	cross: [
		"┼",
		"╋",
		"╬",
		"+"
	],
	arrows: {
		up: [
			"▲",
			"△",
			"^"
		],
		down: [
			"▼",
			"▽",
			"v",
			"V"
		],
		left: [
			"◀",
			"◁",
			"<"
		],
		right: [
			"▶",
			"▷",
			">"
		]
	}
};
function isBoxDrawingChar(char) {
	return BOX_CHARS.horizontal.includes(char) || BOX_CHARS.vertical.includes(char) || Object.values(BOX_CHARS.corners).some((arr) => arr.includes(char)) || Object.values(BOX_CHARS.tees).some((arr) => arr.includes(char)) || BOX_CHARS.cross.includes(char) || Object.values(BOX_CHARS.arrows).some((arr) => arr.includes(char));
}
function getCharType(char) {
	if (BOX_CHARS.horizontal.includes(char)) return "horizontal";
	if (BOX_CHARS.vertical.includes(char)) return "vertical";
	if (Object.values(BOX_CHARS.corners).some((arr) => arr.includes(char))) return "corner";
	if (Object.values(BOX_CHARS.tees).some((arr) => arr.includes(char))) return "tee";
	if (BOX_CHARS.cross.includes(char)) return "cross";
	if (Object.values(BOX_CHARS.arrows).some((arr) => arr.includes(char))) return "arrow";
	return "text";
}
function getCornerType(char) {
	for (const [type, chars] of Object.entries(BOX_CHARS.corners)) if (chars.includes(char)) return type;
	return null;
}
function getTeeType(char) {
	for (const [type, chars] of Object.entries(BOX_CHARS.tees)) if (chars.includes(char)) return type;
	return null;
}
function getArrowType(char) {
	for (const [type, chars] of Object.entries(BOX_CHARS.arrows)) if (chars.includes(char)) return type;
	return null;
}
/**
* Convert ASCII content to SVG string
*/
function asciiToSvg(content, options = {}) {
	const opts = {
		...DEFAULT_OPTIONS,
		...options
	};
	const lines = content.split("\n");
	const maxWidth = Math.max(...lines.map((l) => l.length));
	const height = lines.length;
	const svgWidth = maxWidth * opts.cellWidth;
	const svgHeight = height * opts.cellHeight;
	const paths = [];
	const texts = [];
	const processed = /* @__PURE__ */ new Set();
	const textRuns = [];
	for (let row = 0; row < lines.length; row++) {
		const line = lines[row] || "";
		let currentText = "";
		let textStart = -1;
		for (let col = 0; col <= line.length; col++) {
			const char = line[col] || "";
			if (char && !isBoxDrawingChar(char) && char !== " " && char !== "") {
				if (textStart === -1) textStart = col;
				currentText += char;
			} else {
				if (currentText.length > 0) {
					textRuns.push({
						row,
						col: textStart,
						text: currentText
					});
					for (let i = textStart; i < textStart + currentText.length; i++) processed.add(`${row},${i}`);
				}
				currentText = "";
				textStart = -1;
			}
		}
	}
	for (let row = 0; row < lines.length; row++) {
		const line = lines[row] || "";
		for (let col = 0; col < line.length; col++) {
			const char = line[col];
			if (!char || processed.has(`${row},${col}`)) continue;
			const x = col * opts.cellWidth;
			const y = row * opts.cellHeight;
			const cx = x + opts.cellWidth / 2;
			const cy = y + opts.cellHeight / 2;
			switch (getCharType(char)) {
				case "horizontal":
					paths.push(`<line x1="${x}" y1="${cy}" x2="${x + opts.cellWidth}" y2="${cy}" stroke="${opts.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
					break;
				case "vertical":
					paths.push(`<line x1="${cx}" y1="${y}" x2="${cx}" y2="${y + opts.cellHeight}" stroke="${opts.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
					break;
				case "corner": {
					const cornerType = getCornerType(char);
					const r = opts.borderRadius;
					switch (cornerType) {
						case "topLeft":
							paths.push(`<path d="M ${cx} ${y + opts.cellHeight} L ${cx} ${cy + r} Q ${cx} ${cy} ${cx + r} ${cy} L ${x + opts.cellWidth} ${cy}" fill="none" stroke="${opts.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
							break;
						case "topRight":
							paths.push(`<path d="M ${x} ${cy} L ${cx - r} ${cy} Q ${cx} ${cy} ${cx} ${cy + r} L ${cx} ${y + opts.cellHeight}" fill="none" stroke="${opts.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
							break;
						case "bottomLeft":
							paths.push(`<path d="M ${cx} ${y} L ${cx} ${cy - r} Q ${cx} ${cy} ${cx + r} ${cy} L ${x + opts.cellWidth} ${cy}" fill="none" stroke="${opts.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
							break;
						case "bottomRight":
							paths.push(`<path d="M ${x} ${cy} L ${cx - r} ${cy} Q ${cx} ${cy} ${cx} ${cy - r} L ${cx} ${y}" fill="none" stroke="${opts.strokeColor}" stroke-width="1.5" stroke-linecap="round"/>`);
							break;
					}
					break;
				}
				case "tee":
					switch (getTeeType(char)) {
						case "left":
							paths.push(`<line x1="${cx}" y1="${y}" x2="${cx}" y2="${y + opts.cellHeight}" stroke="${opts.strokeColor}" stroke-width="1.5"/>`);
							paths.push(`<line x1="${cx}" y1="${cy}" x2="${x + opts.cellWidth}" y2="${cy}" stroke="${opts.strokeColor}" stroke-width="1.5"/>`);
							break;
						case "right":
							paths.push(`<line x1="${cx}" y1="${y}" x2="${cx}" y2="${y + opts.cellHeight}" stroke="${opts.strokeColor}" stroke-width="1.5"/>`);
							paths.push(`<line x1="${x}" y1="${cy}" x2="${cx}" y2="${cy}" stroke="${opts.strokeColor}" stroke-width="1.5"/>`);
							break;
						case "top":
							paths.push(`<line x1="${x}" y1="${cy}" x2="${x + opts.cellWidth}" y2="${cy}" stroke="${opts.strokeColor}" stroke-width="1.5"/>`);
							paths.push(`<line x1="${cx}" y1="${cy}" x2="${cx}" y2="${y + opts.cellHeight}" stroke="${opts.strokeColor}" stroke-width="1.5"/>`);
							break;
						case "bottom":
							paths.push(`<line x1="${x}" y1="${cy}" x2="${x + opts.cellWidth}" y2="${cy}" stroke="${opts.strokeColor}" stroke-width="1.5"/>`);
							paths.push(`<line x1="${cx}" y1="${y}" x2="${cx}" y2="${cy}" stroke="${opts.strokeColor}" stroke-width="1.5"/>`);
							break;
					}
					break;
				case "cross":
					paths.push(`<line x1="${x}" y1="${cy}" x2="${x + opts.cellWidth}" y2="${cy}" stroke="${opts.strokeColor}" stroke-width="1.5"/>`);
					paths.push(`<line x1="${cx}" y1="${y}" x2="${cx}" y2="${y + opts.cellHeight}" stroke="${opts.strokeColor}" stroke-width="1.5"/>`);
					break;
				case "arrow": {
					const arrowType = getArrowType(char);
					const arrowSize = Math.min(opts.cellWidth, opts.cellHeight) * .4;
					switch (arrowType) {
						case "up":
							paths.push(`<polygon points="${cx},${cy - arrowSize} ${cx - arrowSize},${cy + arrowSize / 2} ${cx + arrowSize},${cy + arrowSize / 2}" fill="${opts.strokeColor}"/>`);
							break;
						case "down":
							paths.push(`<polygon points="${cx},${cy + arrowSize} ${cx - arrowSize},${cy - arrowSize / 2} ${cx + arrowSize},${cy - arrowSize / 2}" fill="${opts.strokeColor}"/>`);
							break;
						case "left":
							paths.push(`<polygon points="${cx - arrowSize},${cy} ${cx + arrowSize / 2},${cy - arrowSize} ${cx + arrowSize / 2},${cy + arrowSize}" fill="${opts.strokeColor}"/>`);
							break;
						case "right":
							paths.push(`<polygon points="${cx + arrowSize},${cy} ${cx - arrowSize / 2},${cy - arrowSize} ${cx - arrowSize / 2},${cy + arrowSize}" fill="${opts.strokeColor}"/>`);
							break;
					}
					break;
				}
			}
		}
	}
	for (const run of textRuns) {
		const x = run.col * opts.cellWidth;
		const y = run.row * opts.cellHeight + opts.cellHeight * .7;
		texts.push(`<text x="${x}" y="${y}" font-family="${opts.fontFamily}" font-size="${opts.fontSize}" fill="${opts.textColor}">${escapeXml(run.text)}</text>`);
	}
	return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${svgWidth} ${svgHeight}" width="${svgWidth}" height="${svgHeight}" style="max-width: 100%; height: auto;">
  ${opts.backgroundColor !== "transparent" ? `<rect width="100%" height="100%" fill="${opts.backgroundColor}"/>` : ""}
  <g class="ascii-lines">
    ${paths.join("\n    ")}
  </g>
  <g class="ascii-text">
    ${texts.join("\n    ")}
  </g>
</svg>`;
}
/**
* Escape special XML characters
*/
function escapeXml(text) {
	return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
}
/**
* Try to convert ASCII to SVG, return null on failure
*/
function tryAsciiToSvg(content, options) {
	try {
		return asciiToSvg(content, options);
	} catch (error) {
		console.warn("ASCII to SVG conversion failed:", error);
		return null;
	}
}
//#endregion
export { asciiToSvg, tryAsciiToSvg };

//# sourceMappingURL=index408.js.map