import { n as BaseComponent, t as publicDirURL } from "../../../public_dir-C5bujZKB.js"; import { i as wordWrap, n as htmlEscape, t as colors } from "../../../helpers-B9BQYaS6.js"; const ERROR_ICON_SVG = ``; const HINT_ICON_SVG = ``; const COPY_ICON_SVG = ``; function buildErrorWithStacktrace(error) { const cwd = process.cwd(); const lines = []; lines.push(`${error.name}: ${error.message}`); if (error.hint) lines.push(`Hint: ${error.hint.replace(/(<([^>]+)>)/gi, "")}`); if (error.frames.length > 0) { lines.push(""); lines.push("Stack trace:"); for (const frame of error.frames) { const fileName = frame.fileName?.replace(`${cwd}/`, "") || ""; const func = frame.functionName ? `at ${frame.functionName} ` : "at "; lines.push(` ${func}(${fileName}:${frame.lineNumber}:${frame.columnNumber})`); } } return lines.join("\n"); } function htmlAttributeEscape(value) { return value.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(//g, ">"); } var ErrorInfo = class extends BaseComponent { cssFile = new URL("./error_info/style.css", publicDirURL); scriptFile = new URL("./error_info/script.js", publicDirURL); async toHTML(props) { const stacktraceText = buildErrorWithStacktrace(props.error); return ` ${htmlEscape(props.error.name)} ${htmlEscape(props.title)} ${ERROR_ICON_SVG} ${htmlEscape(props.error.message)} ${COPY_ICON_SVG} ${props.error.hint ? ` ${HINT_ICON_SVG} ${props.error.hint} ` : ""} `; } async toANSI(props) { return `${colors.red(`ℹ ${wordWrap(`${props.error.name}: ${props.error.message}`, { width: process.stdout.columns, indent: " ", newLine: "\n", escape: (value) => value })}`)}${props.error.hint ? `\n\n${colors.blue("◉")} ${colors.dim().italic(wordWrap(props.error.hint.replace(/(<([^>]+)>)/gi, ""), { width: process.stdout.columns, indent: " ", newLine: "\n", escape: (value) => value }))}` : ""}`; } }; export { ErrorInfo };