// Shared DOM construction and small browser helpers. The page builds every // node with these functions; server-derived text is always assigned through // textContent, never innerHTML. export function h(tag, props = {}, ...children) { const node = document.createElement(tag); for (const [key, value] of Object.entries(props)) { if (value == null || value === false) continue; if (key === "class") node.className = value; else if (key === "text") node.textContent = value; else if (key.startsWith("on") && typeof value === "function") { node.addEventListener(key.slice(2).toLowerCase(), value); } else node.setAttribute(key, value === true ? "" : String(value)); } for (const child of children.flat()) { if (child == null || child === false) continue; node.append(child instanceof Node ? child : document.createTextNode(String(child))); } return node; } /** One small live-stream badge (LiveBadge.kt): a dot plus the honest word. */ export function renderLiveBadge(info) { return h( "span", { class: `live-badge live-${info.tone}`, title: info.title ?? "Live run stream" }, h("span", { class: "live-dot", "aria-hidden": "true" }), h("span", { class: "live-word", text: info.label }), ); } /** Whether the Clipboard API can be used for a copy control. */ export function canCopyLink() { return typeof navigator !== "undefined" && Boolean(navigator.clipboard?.writeText); } /** Whether the Web Share API can be used for a share control. */ export function canShare() { return typeof navigator !== "undefined" && typeof navigator.share === "function"; } export async function copyText(text) { if (!text || !canCopyLink()) return; try { await navigator.clipboard.writeText(text); } catch { // Clipboard permission may be denied; the patch is still readable. } } export async function copyArtifactLink(resolved) { if (!resolved || !canCopyLink()) return; try { await navigator.clipboard.writeText(resolved); } catch { // Clipboard permission may be denied; the link is still openable. } } export async function shareArtifact(resolved) { if (!resolved || !canShare()) return; try { await navigator.share({ url: resolved }); } catch { // The share chooser may be dismissed. } } /** A key/value row whose value is monospace (a key, an id) rather than prose. */ export function kvMono(key, value) { return h( "div", { class: "kv-row" }, h("span", { class: "kv-key", text: key }), h("span", { class: "kv-val" }, h("code", { text: value })), ); }