import type { HtmlShellOptions } from "./html.shared"; export type { HtmlShellOptions }; import { cspMeta } from "./security"; export function htmlShell(opts: HtmlShellOptions): string { const { title, description, body, favicon, css, js, nonce, csp, extraScripts, themeCss, depth = 0, headExtra, bodyExtra, absoluteAssets = false, } = opts; const nonceAttr = nonce ? ` nonce="${Bun.escapeHTML(nonce)}"` : ""; const themeStyle = themeCss ? `\n ${Bun.escapeHTML(themeCss)}` : ""; const headInjection = headExtra?.length ? `\n ${headExtra.join("\n ")}` : ""; const bodyInjection = bodyExtra?.length ? `\n ${bodyExtra.join("\n ")}` : ""; const depthPrefix = depth === 0 ? "" : "../".repeat(depth); const assetPrefix = absoluteAssets ? "/assets/" : depthPrefix + "assets/"; const clientScript = js ? `\n \n ` : ""; const resolvePath = (path: string) => absoluteAssets ? path : path.startsWith("/") ? depthPrefix + path.slice(1) : path; // Build SEO meta tags (OG, Twitter, canonical) let seoTags = ""; if (opts.seo) { const s = opts.seo; const e = Bun.escapeHTML; seoTags = `\n \n \n \n \n \n \n `; if (s.image) { seoTags += `\n `; } } return ` ${Bun.escapeHTML(title)} ${favicon ? `` : ""}${themeStyle} ${csp ? `` : ""} ${seoTags} try{if(localStorage.getItem("theme")==="dark")document.documentElement.classList.add("dark")}catch(e){}${headInjection}
${body}
${clientScript}${extraScripts ? `\n ${extraScripts}` : ""}${bodyInjection} `; } export function errorHtml(message: string, stack?: string): string { const msg = Bun.escapeHTML(message || "Unknown error"); const st = Bun.escapeHTML(stack || ""); return ` Server Error

🔥 Server Error

${msg}${st ? `\n\n${st}` : ""}
`; } export function hmrScript(nonce: string): string { return ``; }