import { RUNTIME_URLS } from "./runtime.ts"; import { artifactChromeStyles, renderArtifactToolbar, type ArtifactPageChrome, } from "./viewer-ui.ts"; /** * html render path (Phase C, Pass 2). * * The authored `index.html` body is served inside a shared page shell that * injects the html runtime from `/runtime` (never vendored per bundle): * - Pico CSS (classless semantic base) — authored markup styles itself. * - Chart.js + a CSP-clean hydration script — charts are authored as a * plus a sibling \n` : ""; // The mermaid bundle is multi-megabyte; only pages that author a //
 diagram pay for it.
  const mermaidRuntime = hasMermaidBlock(html)
    ? `\n\n`
    : "";

  return `




${escapedTitle}





${mermaidRuntime}${liveReload}

${toolbar}
${html}


`;
}

function isFullDocument(html: string): boolean {
  return /]/i.test(html);
}

function hasMermaidBlock(html: string): boolean {
  return /]*\bclass\s*=\s*["'][^"']*\bmermaid\b/i.test(html);
}

function escapeHtml(value: string): string {
  return value
    .replaceAll("&", "&")
    .replaceAll("<", "<")
    .replaceAll(">", ">")
    .replaceAll('"', """);
}