'+word+'');
out += '.';
if (word === "Color"){
out += link("ns-color.html#"+member.toLowerCase(), "", "Named color "+word+"."+member+".", ''+esc(member)+'');
} else {
const key=word+"."+member, m=NSMETHODS[key];
if (m){
out += link(m.id+".html", m.id, TIPS[key]||key, ''+esc(member)+'');
if (src[nextNonSpace(k)]==="(") pending = {page:m.id, params:new Set(m.params||[])};
} else out += ''+esc(member)+'';
}
i=k; continue;
}
const ns = nextNonSpace(j);
const callish = src[ns] === "(";
const labelish = src[ns] === ":";
const top = stack.length ? stack[stack.length-1] : null;
if (KEYWORDS[word]){
out += link(KEYWORDS[word]+".html", KEYWORDS[word], TIPS[word], ''+word+'');
} else if (BUILTINS[word] && callish){
const b=BUILTINS[word];
out += link(b.id+".html", b.id, TIPS[word], ''+word+'');
pending = {page:b.id, params:new Set(b.params||[])};
} else if (labelish && top && top.params.has(word)){
out += link(top.page+".html#param-"+word, "", "parameter: "+word, ''+word+'');
} else if (TYPES[word]){
out += link(TYPES[word]+".html", TYPES[word], TIPS[word]||("The "+word+" type."), ''+word+'');
} else if (PHASES[word]){
out += link(PHASES[word]+".html", PHASES[word], TIPS[word]||("The "+word+" phase."), ''+word+'');
} else if (callish){
out += ''+esc(word)+'';
} else {
out += esc(word);
}
i=j; continue;
}
if (c === "("){ stack.push(pending); pending=null; out+='('; i++; continue; }
if (c === ")"){ stack.pop(); out+=')'; i++; continue; }
if (/[{}\[\]=<>+\-*\/%,.:;!&|~]/.test(c)){ out+=''+esc(c)+''; i++; continue; }
out += esc(c); i++;
}
return out;
}
function highlightAll(){
document.querySelectorAll('pre[data-lang="ludic"]').forEach(pre => { pre.innerHTML = highlight(pre.textContent); });
}
/* ---- tooltip cards: click a token to open; click the card to open the ---
---- page in a new tab; click outside (or Escape) to close ------------- */
let cardEl = null, cardAnchor = null;
function ensureCard(){
if (cardEl) return cardEl;
cardEl = document.createElement("div"); cardEl.className = "hovercard"; cardEl.hidden = true;
cardEl.addEventListener("click", () => {
const h = cardEl.dataset.href; if (h) window.open(h, "_blank", "noopener");
});
document.body.appendChild(cardEl); return cardEl;
}
function positionCard(a){
const el = cardEl, r = a.getBoundingClientRect();
const cw = el.offsetWidth, ch = el.offsetHeight;
let left = r.left, top = r.bottom + 8;
if (left + cw > window.innerWidth - 12) left = window.innerWidth - cw - 12;
if (left < 12) left = 12;
if (top + ch > window.innerHeight - 12) top = r.top - ch - 8;
el.style.left = Math.max(12,left) + "px"; el.style.top = Math.max(12,top) + "px";
}
function showCard(a){
const id = a.getAttribute("data-id"); if (!id) return;
const c = CARDS[id]; if (!c) return;
const el = ensureCard();
el.innerHTML = ''
+ (c.kind||"").replace("namespace-method","method") + ''+esc(c.name||"")+'
'
+ (c.sig ? ''+esc(c.sig)+'' : "")
+ ''+esc(c.tip||"")+'
'
+ '';
el.dataset.href = a.getAttribute("href") || "";
el.hidden = false; cardAnchor = a; positionCard(a);
}
function hideCard(){ if (cardEl){ cardEl.hidden = true; cardAnchor = null; } }
function installCards(){
document.addEventListener("click", e => {
const a = e.target.closest && e.target.closest("a.tok[data-id]");
if (a){ e.preventDefault(); showCard(a); return; } // token -> open card
if (cardEl && !cardEl.hidden && !(e.target.closest && e.target.closest(".hovercard"))) hideCard(); // outside -> close
});
document.addEventListener("keydown", e => { if (e.key === "Escape") hideCard(); });
window.addEventListener("resize", hideCard);
window.addEventListener("scroll", () => {
if (cardEl && !cardEl.hidden && cardAnchor){
const r = cardAnchor.getBoundingClientRect();
if (r.bottom < 0 || r.top > window.innerHeight) hideCard(); else positionCard(cardAnchor);
}
}, {passive:true});
}
/* ---- flash the scrolled-to target ------------------------------------- */
function flash(el){ if (!el) return; el.classList.remove("flash"); void el.offsetWidth; el.classList.add("flash"); }
function flashTarget(){
const go = () => {
// Only a deep link gets a flash. The old fallback flashed the page title
// on every plain visit, which points at nothing the reader was looking for.
const h = location.hash ? decodeURIComponent(location.hash.slice(1)) : "";
if (h) flash(document.getElementById(h));
};
if (document.readyState !== "loading") go(); else document.addEventListener("DOMContentLoaded", go);
window.addEventListener("hashchange", () => { const el = document.getElementById(decodeURIComponent(location.hash.slice(1))); flash(el); });
}
/* ---- fuzzy search on the API index ------------------------------------ */
function subseq(q, s){ let i=0; for (let k=0;k {
const q = box.value.trim().toLowerCase();
let shown = 0;
items.forEach(it => {
const name = (it.getAttribute("data-name")||"").toLowerCase();
const tip = (it.getAttribute("data-tip")||"").toLowerCase();
const hit = !q || name.includes(q) || tip.includes(q) || subseq(q, name);
it.style.display = hit ? "" : "none"; if (hit) shown++;
});
secs.forEach(sec => { const any = [...sec.querySelectorAll(".idx-item")].some(i=>i.style.display!=="none"); sec.style.display = any ? "" : "none"; });
if (none) none.hidden = shown !== 0;
};
box.addEventListener("input", run);
box.addEventListener("keydown", e => { if (e.key === "Enter"){ const first = items.find(i=>i.style.display!=="none"); if (first) location.href = first.getAttribute("href"); } });
}
/* ---- mobile nav toggle (auto-wired on every page) ------------------- */
function initNav(){
document.querySelectorAll(".nav-toggle").forEach(btn => {
btn.addEventListener("click", () => {
const h = btn.closest("header.nav"); if (!h) return;
const open = h.classList.toggle("open");
btn.setAttribute("aria-expanded", open ? "true" : "false");
});
});
document.querySelectorAll("header.nav .nav-links a").forEach(a => {
a.addEventListener("click", () => {
const h = a.closest("header.nav");
if (h){ h.classList.remove("open"); const b = h.querySelector(".nav-toggle"); if (b) b.setAttribute("aria-expanded","false"); }
});
});
}
if (document.readyState !== "loading") initNav(); else document.addEventListener("DOMContentLoaded", initNav);
global.Ludic = { highlight, highlightAll, installCards, flashTarget, installSearch, initNav, SYMBOLS: S };
})(window);