";
document.body.append(lb);
lb.addEventListener("click", () => lb.close());
$$("article figure img").forEach((img) => img.addEventListener("click", () => {
const big = $("img", lb);
big.src = img.currentSrc || img.src;
big.alt = img.alt;
$("p", lb).textContent = img.alt;
lb.showModal();
}));
// search
const pal = $("#pal");
const input = $("input", pal);
const list = $("ul", pal);
let index = null;
let sel = 0;
let hits = [];
const load = async () => {
if (index) return index;
try { index = await (await fetch(`${base}search-${lang}.json`)).json(); } catch { index = []; }
return index;
};
const esc = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
const norm = (s) => s.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/ß/g, "ss");
const rx = (t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const hi = (s, ts) => {
let o = esc(s);
for (const t of ts) o = o.replace(new RegExp(`(${rx(esc(t))})`, "ig"), "$1");
return o;
};
const run = async () => {
const idx = await load();
const ts = norm(input.value.trim()).split(/\s+/).filter(Boolean);
if (!ts.length) { hits = []; list.innerHTML = `
${esc(T.hint || "")}
`; return; }
hits = idx.map((e) => {
const ht = norm(e.h), pt = norm(e.p), xt = norm(e.x);
let s = 0;
for (const t of ts) {
let k = 0;
if (ht.includes(t)) k += ht.startsWith(t) ? 12 : 8;
if (pt.includes(t)) k += 4;
if (xt.includes(t)) k += 2;
if (!k) return null;
s += k;
}
if (e.l === 1) s += 3;
if (e.u.startsWith(`${lang}/changelog`)) s -= 6;
return { e, s };
}).filter(Boolean).sort((a, b) => b.s - a.s).slice(0, 30);
sel = 0;
list.innerHTML = hits.length
? hits.map((h, i) => {
const at = norm(h.e.x);
const p = ts.map((t) => at.indexOf(t)).find((n) => n >= 0) ?? 0;
const from = Math.max(0, p - 40);
const snip = (from ? h.e.x.slice(h.e.x.indexOf(" ", from) + 1 || from) : h.e.x).slice(0, 120);
return `