import { n as BaseComponent, t as publicDirURL } from "../../../public_dir-C5bujZKB.js"; import { n as htmlEscape, t as colors } from "../../../helpers-B9BQYaS6.js"; import { dump, themes } from "@poppinss/dumper/html"; import { dump as dump$1 } from "@poppinss/dumper/console"; const CHEVIRON = ` `; const EDITORS = { textmate: "txmt://open?url=file://%f&line=%l", macvim: "mvim://open?url=file://%f&line=%l", emacs: "emacs://open?url=file://%f&line=%l", sublime: "subl://open?url=file://%f&line=%l", phpstorm: "phpstorm://open?file=%f&line=%l", atom: "atom://core/open/file?filename=%f&line=%l", vscode: "vscode://file/%f:%l" }; var ErrorStack = class extends BaseComponent { cssFile = new URL("./error_stack/style.css", publicDirURL); scriptFile = new URL("./error_stack/script.js", publicDirURL); #getRelativeFileName(filePath) { return filePath.replace(`${process.cwd()}/`, ""); } #getFirstExpandedFrameIndex(frames) { let expandAtIndex = frames.findIndex((frame) => frame.type === "app"); if (expandAtIndex === -1) expandAtIndex = frames.findIndex((frame) => frame.type === "module"); return expandAtIndex; } #getEditorLink(ide, frame) { const editorURL = EDITORS[ide] || ide; if (!editorURL || frame.type === "native") return { text: this.#getRelativeFileName(frame.fileName) }; return { href: editorURL.replace("%f", frame.fileName).replace("%l", String(frame.lineNumber)), text: this.#getRelativeFileName(frame.fileName) }; } #renderFrameLocation(frame, ide) { const { text, href } = this.#getEditorLink(ide, frame); const fileName = ` ${htmlEscape(text)} `; const functionName = frame.functionName ? `in ${htmlEscape(frame.functionName)} ` : ""; const loc = `at line ${frame.lineNumber}:${frame.columnNumber}`; if (frame.type !== "native" && frame.source) return ``; return `
${fileName} ${functionName} ${loc}
`; } async #renderStackFrame(frame, index, expandAtIndex, props) { const label = frame.type === "app" ? "In App" : ""; const expandedClass = expandAtIndex === index ? " expanded" : ""; const toggleButton = frame.type !== "native" && frame.source ? `` : ""; return `
  • ${this.#renderFrameLocation(frame, props.ide)}
    ${label} ${toggleButton}
    ${await props.sourceCodeRenderer(props.error, frame)}
  • `; } async #printStackFrame(frame, index, expandAtIndex, props) { const loc = `${this.#getRelativeFileName(frame.fileName)}:${frame.lineNumber}:${frame.columnNumber}`; if (index === expandAtIndex) { const functionName = frame.functionName ? `at ${frame.functionName} ` : ""; const codeSnippet = await props.sourceCodeRenderer(props.error, frame); return ` ⁃ ${functionName}${colors.yellow(`(${loc})`)}${codeSnippet}`; } if (frame.type === "native") { const functionName = frame.functionName ? `at ${colors.italic(frame.functionName)} ` : ""; return colors.dim(` ⁃ ${functionName}(${colors.italic(loc)})`); } return ` ⁃ ${frame.functionName ? `at ${frame.functionName} ` : ""}${colors.yellow(`(${loc})`)}`; } async toHTML(props) { return `

    Stack Trace

      ${(await Promise.all(props.error.frames.map((frame, index) => { return this.#renderStackFrame(frame, index, this.#getFirstExpandedFrameIndex(props.error.frames), props); }))).join("\n")}
    ${dump(props.error.raw, { styles: themes.cssVariables, expand: true, cspNonce: props.cspNonce, inspectObjectPrototype: false, inspectStaticMembers: false, inspectArrayPrototype: false })}
    `; } async toANSI(props) { const displayRaw = process.env.YOUCH_RAW; if (displayRaw) { const depth = Number.isNaN(Number(displayRaw)) ? 2 : Number(displayRaw); return `\n\n${colors.red("[RAW]")}\n${dump$1(props.error.raw, { depth, inspectObjectPrototype: false, inspectStaticMembers: false, inspectArrayPrototype: false })}`; } const frames = await Promise.all(props.error.frames.map((frame, index) => { return this.#printStackFrame(frame, index, this.#getFirstExpandedFrameIndex(props.error.frames), props); })); if (frames.length) return `\n\n${frames.join("\n")}`; return ""; } }; export { ErrorStack };