(function () {
"use strict";
let MANIFEST = null;
const PAGE_CACHE = {};
const UNFURL_CACHE = {};
function esc(s) {
return String(s)
.replace(/&/g, "&")
.replace(//g, ">");
}
function flattenTree(node, depth, acc) {
acc.push({ node: node, depth: depth });
(node.children || []).forEach((c) => flattenTree(c, depth + 1, acc));
return acc;
}
function findNode(node, slug) {
if (node.slug === slug) return node;
for (const c of node.children || []) {
const hit = findNode(c, slug);
if (hit) return hit;
}
return null;
}
/* -------------------- minimal markdown -------------------- */
function inline(text) {
let t = esc(text);
t = t.replace(/`([^`]+)`/g, (_, c) => `${c}`);
t = t.replace(/\*\*([^*]+)\*\*/g, (_, c) => `${c}`);
t = t.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_, txt, url) => {
const safe = esc(url);
const attrs = /^https?:/.test(url) ? ' target="_blank" rel="noopener"' : "";
return `${txt}`;
});
t = t.replace(/(^|[\s(])(https?:\/\/[^\s<)]+)/g, (m, pre, url) => {
return `${pre}${url}`;
});
return t;
}
const URL_ONLY = /^(https?:\/\/[^\s]+)$/;
function renderMarkdown(md, container) {
const lines = md.replace(//g, "").split("\n");
let i = 0;
let para = [];
function flushPara() {
if (!para.length) return;
const joined = para.join(" ").trim();
para = [];
if (!joined) return;
if (URL_ONLY.test(joined) || IMG_PATH.test(joined)) {
container.appendChild(unfurl(joined));
return;
}
const p = document.createElement("p");
p.innerHTML = inline(joined);
container.appendChild(p);
}
while (i < lines.length) {
const line = lines[i];
const trimmed = line.trim();
if (trimmed === "") {
flushPara();
i++;
continue;
}
const fence = trimmed.match(/^(`{3,}|~{3,})(.*)$/);
if (fence) {
flushPara();
const marker = fence[1][0];
const closeRe = new RegExp("^" + marker + "{" + fence[1].length + ",}\\s*$");
const info = fence[2].trim();
const buf = [];
i++;
while (i < lines.length && !closeRe.test(lines[i].trim())) {
buf.push(lines[i]);
i++;
}
i++;
const lang = (info.split(/\s+/)[0] || "").toLowerCase();
const tm = info.match(/title=(\S+)/);
container.appendChild(
renderCode(buf.join("\n"), lang, tm ? tm[1] : null)
);
continue;
}
if (trimmed === "---") {
flushPara();
container.appendChild(document.createElement("hr"));
i++;
continue;
}
const h = trimmed.match(/^(#{1,4})\s+(.*)$/);
if (h) {
flushPara();
const el = document.createElement("h" + h[1].length);
el.innerHTML = inline(h[2]);
container.appendChild(el);
i++;
continue;
}
if (
trimmed.startsWith("|") &&
i + 1 < lines.length &&
/^\|?[\s:|-]*-{2,}[\s:|-]*\|?$/.test(lines[i + 1].trim())
) {
flushPara();
const rows = [];
while (i < lines.length && lines[i].trim().startsWith("|")) {
rows.push(parseRow(lines[i].trim()));
i++;
}
renderTable(rows, container);
continue;
}
if (trimmed.startsWith("> ")) {
flushPara();
const bq = document.createElement("blockquote");
bq.innerHTML = inline(trimmed.slice(2));
container.appendChild(bq);
i++;
continue;
}
if (/^`[^`]+`$/.test(trimmed)) {
flushPara();
const el = document.createElement("div");
el.className = "ts";
el.textContent = trimmed.replace(/`/g, "");
container.appendChild(el);
i++;
continue;
}
if (trimmed.startsWith("- ")) {
flushPara();
const items = [];
while (i < lines.length && lines[i].trim().startsWith("- ")) {
items.push(lines[i].trim().slice(2).trim());
i++;
}
renderList(items, container);
continue;
}
para.push(trimmed);
i++;
}
flushPara();
}
function parseRow(line) {
let s = line.trim();
if (s.startsWith("|")) s = s.slice(1);
if (s.endsWith("|")) s = s.slice(0, -1);
return s.split(/(? c.replace(/\\\|/g, "|").trim());
}
const TRUTHY = ["x", "✓", "✔", "yes", "done", "true", "[x]"];
const CHIP_COLORS = [
["#e7f0ff", "#2158d0"],
["#fde8ec", "#c62a4b"],
["#e6f7ee", "#1a8a55"],
["#fdf0e0", "#b26a12"],
["#efe9ff", "#5b3bd6"],
["#e6f6f8", "#127b88"],
];
function chipColor(name) {
let h = 0;
for (let i = 0; i < name.length; i++) h = (h * 31 + name.charCodeAt(i)) >>> 0;
return CHIP_COLORS[h % CHIP_COLORS.length];
}
const STATUS_MAP = {
"": ["Planned", "gray"],
planned: ["Planned", "gray"],
todo: ["Planned", "gray"],
"to do": ["Planned", "gray"],
backlog: ["Planned", "gray"],
"in progress": ["In progress", "amber"],
"in-progress": ["In progress", "amber"],
wip: ["In progress", "amber"],
running: ["In progress", "amber"],
active: ["In progress", "amber"],
done: ["Done", "green"],
complete: ["Done", "green"],
completed: ["Done", "green"],
blocked: ["Blocked", "red"],
failed: ["Failed", "red"],
abandoned: ["Abandoned", "gray"],
};
function statusBadge(val) {
const [label, tone] = STATUS_MAP[val.toLowerCase()] || [val || "—", "gray"];
return `${esc(label)}`;
}
function renderTable(rows, container) {
if (rows.length < 2) return;
const header = rows[0];
const body = rows.slice(2);
const roles = header.map((h) => {
const t = h.toLowerCase();
if (t.includes("status") || t.includes("state")) return "status";
if (t.includes("progress") || t.includes("complete") || t.includes("done"))
return "check";
if (t === "who" || t.includes("assign") || t.includes("owner")) return "who";
return "text";
});
const table = document.createElement("table");
table.className = "board";
const thead = document.createElement("thead");
const htr = document.createElement("tr");
header.forEach((h, c) => {
const th = document.createElement("th");
th.textContent = h;
if (roles[c] === "check") th.className = "col-check";
htr.appendChild(th);
});
thead.appendChild(htr);
table.appendChild(thead);
const tbody = document.createElement("tbody");
body.forEach((cells) => {
const nonEmpty = cells.filter((x) => x !== "").length;
if (nonEmpty === 1 && cells[0]) {
const tr = document.createElement("tr");
tr.className = "section-row";
const td = document.createElement("td");
td.colSpan = header.length;
td.innerHTML = inline(cells[0]);
tr.appendChild(td);
tbody.appendChild(tr);
return;
}
const tr = document.createElement("tr");
header.forEach((_, c) => {
const td = document.createElement("td");
const val = (cells[c] || "").trim();
if (roles[c] === "status") {
td.className = "col-status";
td.innerHTML = statusBadge(val);
} else if (roles[c] === "check") {
td.className = "col-check";
const on = TRUTHY.indexOf(val.toLowerCase()) !== -1;
td.innerHTML = `${on ? "✓" : ""}`;
} else if (roles[c] === "who") {
if (!val || /^to assign$/i.test(val)) {
td.innerHTML = `${esc(val || "—")}`;
} else {
const [bg, fg] = chipColor(val);
td.innerHTML = `${esc(val)}`;
}
} else {
td.innerHTML = inline(val);
}
tr.appendChild(td);
});
const link = tr.querySelector('a[href^="#/"]');
if (link) {
tr.classList.add("linked-row");
tr.addEventListener("click", (e) => {
if (e.target.tagName !== "A") location.hash = link.getAttribute("href");
});
}
tbody.appendChild(tr);
});
table.appendChild(tbody);
const wrap = document.createElement("div");
wrap.className = "board-wrap";
wrap.appendChild(table);
container.appendChild(wrap);
}
const HL_RULES = {
python: [
["comment", /#[^\n]*/],
["string", /'''[\s\S]*?'''|"""[\s\S]*?"""|'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"/],
[
"keyword",
/\b(?:def|class|return|if|elif|else|for|while|import|from|as|with|try|except|finally|raise|in|not|and|or|is|None|True|False|lambda|yield|global|nonlocal|assert|pass|break|continue|async|await|print)\b/,
],
["number", /\b\d[\d_.eE+-]*\b/],
],
bash: [
["comment", /#[^\n]*/],
["string", /'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"/],
["keyword", /\b(?:if|then|else|fi|for|in|do|done|while|case|esac|function|export|source|echo|cd|return|local)\b/],
["number", /(?<=\s)-{1,2}[a-zA-Z][\w-]*/],
],
json: [
["string", /"(?:\\.|[^"\\])*"/],
["keyword", /\b(?:true|false|null)\b/],
["number", /-?\b\d[\d.eE+-]*\b/],
],
yaml: [
["comment", /#[^\n]*/],
["string", /'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"/],
["keyword", /\b(?:true|false|null|yes|no)\b/],
["number", /-?\b\d[\d.eE+-]*\b/],
],
};
HL_RULES.javascript = HL_RULES.python;
HL_RULES.typescript = HL_RULES.python;
HL_RULES.sql = [
["comment", /--[^\n]*/],
["string", /'(?:\\.|[^'\\])*'/],
[
"keyword",
/\b(?:SELECT|FROM|WHERE|JOIN|LEFT|RIGHT|INNER|OUTER|ON|GROUP|BY|ORDER|LIMIT|INSERT|INTO|VALUES|UPDATE|SET|DELETE|CREATE|TABLE|AS|AND|OR|NOT|NULL|COUNT|DISTINCT|IN)\b/i,
],
["number", /\b\d[\d.]*\b/],
];
function highlightCode(code, lang) {
const rules = HL_RULES[lang];
if (!rules) return esc(code);
const combined = new RegExp(rules.map((r) => "(" + r[1].source + ")").join("|"), "g");
let out = "";
let last = 0;
let m;
while ((m = combined.exec(code))) {
if (m[0] === "") {
combined.lastIndex++;
continue;
}
out += esc(code.slice(last, m.index));
let gi = 1;
while (gi < m.length && m[gi] === undefined) gi++;
out += `${esc(m[0])}`;
last = m.index + m[0].length;
}
out += esc(code.slice(last));
return out;
}
function renderCode(code, lang, title) {
const pre = document.createElement("pre");
pre.className = "hl";
const c = document.createElement("code");
c.innerHTML = highlightCode(code, lang);
pre.appendChild(c);
if (!title) return pre;
const det = document.createElement("details");
det.className = "code-accordion";
const sum = document.createElement("summary");
sum.innerHTML = `</> ${esc(title)}`;
det.appendChild(sum);
det.appendChild(pre);
return det;
}
const IMG_PATH = /^[^\s]+\.(png|jpe?g|gif|svg|webp)$/i;
function renderList(items, container) {
let ul = null;
items.forEach((item) => {
if (URL_ONLY.test(item) || IMG_PATH.test(item)) {
ul = null;
container.appendChild(unfurl(item));
} else if (item.indexOf("📦 Artifact") !== -1) {
ul = null;
const div = document.createElement("div");
div.className = "artifact-chip";
div.innerHTML = inline(item);
container.appendChild(div);
} else {
if (!ul) {
ul = document.createElement("ul");
container.appendChild(ul);
}
const li = document.createElement("li");
li.innerHTML = inline(item);
ul.appendChild(li);
}
});
}
/* -------------------- unfurl providers -------------------- */
function card(url, kind, icon, title, desc, chips) {
const a = document.createElement("a");
a.className = "unfurl";
a.href = url;
a.target = "_blank";
a.rel = "noopener";
const chipHtml = (chips || [])
.filter(Boolean)
.map((c) => `${esc(c)}`)
.join("");
a.innerHTML =
`