/*! Fiesta 1.0.0 | MPL-2.0 | https://fiesta.rastrillo.org */ (function () { "use strict"; const fold = (s) => String(s || "").normalize("NFD").replace(/\p{M}/gu, "").replace(/[\u2018\u2019]/g, "'").toLowerCase().trim(); const plain = (t) => t.replace(/^\+/, ""); const folded = (o) => { if (o.folded) return o.folded; const name = fold(o.name); const terms = (o.terms || []).map(fold).filter(Boolean); return { name, text: fold(o.text), terms, bareName: name.replace(/\s*\([^()]*\)$/, ""), words: name.split(/[\s\-’'(),.]+/).filter(Boolean), plainTerms: terms.map(plain), }; }; const ranked = (o, q) => { if (!q) return 0; const bare = q.replace(/^\+/, ""); const f = folded(o); const name = f.name; const terms = f.terms; const plains = f.plainTerms; if (name === q || f.bareName === q || terms.includes(q) || (bare && plains.includes(bare))) return 0; if (name.startsWith(q)) return 1; if (f.words.some((w) => w.startsWith(q))) return 2; if (bare && plains.some((t) => t.startsWith(bare))) return 2; if (f.text.includes(q)) return 3; return -1; }; const rank = (o, query) => ranked(o, fold(query)); const order = (opts, query) => { const q = fold(query); return opts .map((o, i) => ({ o, i, r: ranked(o, q) })) .filter((x) => x.r >= 0) .sort((a, b) => a.r - b.r || (a.r === 0 ? (b.o.first ? 1 : 0) - (a.o.first ? 1 : 0) : 0) || a.i - b.i) .map((x) => x.o); }; const settle = (hits, query) => { if (hits.length === 1) return hits[0]; if (!hits.length) return null; const q = fold(query); const bare = q.replace(/^\+/, ""); const r0 = rank(hits[0], query); if (r0 === 0 && /^\d+$/.test(bare) && hits[0].first) return hits[0]; if (bare.length < 3 || /^\d+$/.test(bare)) return null; if (r0 === 0) { const ties = hits.filter((o) => ranked(o, q) === 0); if (ties.length === 1) return hits[0]; return hits[0].first && ties.filter((o) => o.first).length === 1 ? hits[0] : null; } return r0 < rank(hits[1], query) ? hits[0] : null; }; const isPrompt = (value, marked, required, disabled) => marked || (value === "" && (required || !!disabled)); const offered = (value, marked, required, searching, disabled) => value !== "" || (marked ? !searching : !(required || !!disabled)); function fiestaPickLang(tag, registry) { var want = String(tag || "").toLowerCase(); if (!want) return null; var keys = Object.keys(registry || {}), i; for (i = 0; i < keys.length; i++) { if (keys[i].toLowerCase() === want) return keys[i]; } var primary = want.split("-")[0]; for (i = 0; i < keys.length; i++) { if (keys[i].toLowerCase().split("-")[0] === primary) return keys[i]; } return null; } function fiestaWord(el, key, fallback) { var v = el.getAttribute("data-rst-" + key); if (v !== null && v !== "") return v; var registry = (typeof self !== "undefined" && self.fiestaStrings) || {}; var lang = fiestaPickLang(document.documentElement.lang, registry); var table = lang ? registry[lang] : null; return table && table[key] !== undefined && table[key] !== "" ? table[key] : fallback; } if (typeof module !== "undefined" && module && module.exports) { module.exports = { fold: fold, rank: rank, order: order, settle: settle, isPrompt: isPrompt, offered: offered, fiestaPickLang: fiestaPickLang, fiestaWord: fiestaWord }; } if (typeof document === "undefined") return; let told = null; document.addEventListener("rst:select-viewport", (e) => { const d = e.detail; told = d && isFinite(d.top) && isFinite(d.bottom) ? { top: +d.top, bottom: +d.bottom } : null; }); const holds = (cs) => { const d = cs.display, b = d !== "contents", cv = cs.contentVisibility; const o = b && !/^(inline|run-in)( list-item)?$|^(ruby$|table-col|ruby-)/.test(d), c = o && !/^table-(row|head|foot)/.test(d); const w = (cs.willChange || "").toLowerCase().split(/,\s*/).filter((v) => CSS.supports(v, "initial")).map((v) => v.replace(/^-webkit-/, "")); const X = (s, v) => s.split(" ").some((k) => w.includes(k) || (v && !/^(none|)$/.test(cs.getPropertyValue(k)))); const p = c && (/paint|strict|content/.test(cs.contain) || cv === "auto" || cv === "hidden"); const f = p || (c && (/layout/.test(cs.contain) || X("contain content-visibility"))) || (o && (cs.transformStyle === "preserve-3d" || /\d/.test(cs.offsetPosition) || X("transform translate rotate scale perspective offset-path", 1) || X("transform-style offset offset-position"))) || (b && X("filter backdrop-filter -webkit-backdrop-filter", 1)); return { f, a: f || (b && (cs.position !== "static" || X("position"))), p, o, b }; }; const onTop = (a) => [":modal", ":popover-open"].some((q) => { try { return a.matches(q); } catch (e) { return false; } }); const clippers = (list, pos) => { const out = []; for (let a = list; (a = a.assignedSlot || a.parentElement || (a.parentNode && a.parentNode.host)) && a !== document.body; ) { const cs = getComputedStyle(a), h = holds(cs); if (h.b && (pos === "fixed" ? h.f : pos !== "absolute" || h.a)) { if (h.p || (h.o && /auto|scroll|hidden|clip/.test(cs.overflowY))) out.push(a); pos = cs.position; } if (onTop(a)) break; } return out; }; const ACTS = new Set(["ArrowDown", "ArrowUp", "Home", "End", "Enter", "Tab"]); const el = (tag, attr) => { const e = document.createElement(tag); if (attr) e.setAttribute(attr, ""); return e; }; const enhanced = new WeakSet(); function combo(native, resume) { if (enhanced.has(native)) return; enhanced.add(native); native.dataset.rstEnhanced = "true"; const id = native.id || "rst-select-" + Math.random().toString(36).slice(2); const listId = id + "-listbox"; const say = (key, fallback) => fiestaWord(native, "select-" + key, fallback); const manyFmt = say("results", "{n} results"); const oneFmt = say("result-one", "1 result"); const groups = []; const offLimits = (o) => o.disabled || !!(o.parentElement && o.parentElement.tagName === "OPTGROUP" && o.parentElement.disabled); const locked = () => native.matches(":disabled"); const opts = Array.from(native.options).map((o, i) => { const d = o.dataset; const g = o.parentElement.tagName === "OPTGROUP" ? o.parentElement : null; if (g && groups[groups.length - 1] !== g) groups.push(g); return { text: o.text, name: d.rstName || o.text, desc: d.rstDesc || "", short: d.rstShort || "", lead: d.rstLead || "", classes: (d.rstClass || "").split(/\s+/).filter((c) => c && c !== "is-active"), terms: (d.rstTerms || "").split(/\s+/).filter(Boolean), marked: d.rstPrompt !== undefined, prompt: isPrompt(o.value, d.rstPrompt !== undefined, native.required, offLimits(o)), first: d.rstFirst !== undefined, sepBefore: !!(o.previousElementSibling && o.previousElementSibling.tagName === "HR"), disabled: offLimits(o), blank: o.value === "", index: i, group: g, el: o, li: null, }; }); for (const o of opts) o.folded = folded(o); const compact = opts.some((o) => o.short); const wrap = el("div", "rst-combo"); if (compact) wrap.setAttribute("rst-combo-compact", ""); const lead = el("span", "rst-combo-lead"); lead.setAttribute("aria-hidden", "true"); const said = el("span"); said.id = id + "-said"; said.hidden = true; const input = el("input", "rst-input"); input.type = "text"; input.id = id + "-combo"; input.autocomplete = "off"; input.spellcheck = false; input.disabled = native.disabled; input.placeholder = compact && native.getAttribute("aria-label") ? native.getAttribute("aria-label") : say("filter", "Type to filter"); input.setAttribute("role", "combobox"); input.setAttribute("aria-expanded", "false"); input.setAttribute("aria-controls", listId); input.setAttribute("aria-autocomplete", "list"); const described = native.getAttribute("aria-describedby"); if (described) input.setAttribute("aria-describedby", described); if (compact) input.setAttribute("aria-describedby", described ? described + " " + said.id : said.id); const list = el("ul", "rst-combo-list"); list.id = listId; list.hidden = true; list.setAttribute("role", "listbox"); const status = el("p"); status.className = "rst-sr-only"; status.setAttribute("role", "status"); status.setAttribute("aria-live", "polite"); const label = native.id && document.querySelector('label[for="' + CSS.escape(native.id) + '"]'); if (label) { if (!label.id) label.id = id + "-label"; label.htmlFor = input.id; list.setAttribute("aria-labelledby", label.id); } else if (native.getAttribute("aria-label")) { input.setAttribute("aria-label", native.getAttribute("aria-label")); list.setAttribute("aria-label", native.getAttribute("aria-label")); } const boxes = new Map(); for (const g of groups) { const box = el("li"); box.setAttribute("role", "group"); box.setAttribute("aria-label", g.label); const rows = el("ul", "rst-combo-rows"); rows.setAttribute("role", "none"); const head = el("li", "rst-select-group"); head.setAttribute("aria-hidden", "true"); head.textContent = g.label; rows.appendChild(head); box.appendChild(rows); boxes.set(g, { box, rows }); } const home = (o) => (o.group ? boxes.get(o.group).rows : list); for (const o of opts) { const li = el("li", "rst-combo-option"); li.id = listId + "-" + o.index; li.setAttribute("role", "option"); li.setAttribute("aria-selected", "false"); if (o.disabled) li.setAttribute("aria-disabled", "true"); if (o.classes.length) li.classList.add(...o.classes); if (o.lead) { const glyph = el("span", "rst-combo-lead"); glyph.setAttribute("aria-hidden", "true"); glyph.textContent = o.lead; li.append(glyph); } if (o.desc) { const name = el("span", "rst-combo-name"); name.textContent = o.name; const desc = el("span", "rst-combo-desc"); desc.textContent = o.desc; li.append(name, desc); } else { li.append(o.text); } o.li = li; if (o.group && !list.contains(boxes.get(o.group).box)) list.appendChild(boxes.get(o.group).box); if (o.sepBefore) { o.sep = el("li", "rst-combo-sep"); o.sep.setAttribute("aria-hidden", "true"); home(o).appendChild(o.sep); } home(o).appendChild(li); } const empty = el("li", "rst-combo-empty"); empty.style.display = "none"; empty.textContent = say("no-matches", "No matches"); list.appendChild(empty); native.parentNode.insertBefore(wrap, native); wrap.append(lead, input, said, list, status); const inputAttr = native.getAttribute("rst-input"); native.removeAttribute("rst-input"); native.classList.add("rst-sr-only"); native.setAttribute("tabindex", "-1"); native.setAttribute("aria-hidden", "true"); let open = false; let active = null; let extras = 0; const selectedEl = () => native.options[native.selectedIndex] || null; const picked = () => opts.find((o) => o.el && o.el === selectedEl()) || null; const currentText = () => { const o = picked(); return o && !o.prompt ? o.short || o.name : ""; }; let showingPick = true; const showText = () => { input.value = currentText(); showingPick = true; }; const query = () => (showingPick ? "" : input.value); let worn = []; const wear = (classes) => { input.classList.remove(...worn); worn = classes; input.classList.add(...worn); }; const showPick = () => { const o = picked(); wear(o && !o.prompt ? o.classes : []); lead.textContent = (o && o.lead) || ""; lead.hidden = !lead.textContent; if (wrap.hasAttribute("rst-combo-has-lead") === lead.hidden) wrap.toggleAttribute("rst-combo-has-lead", !lead.hidden); said.textContent = o && o.short ? [o.name, o.desc].filter(Boolean).join(" ") : ""; }; showText(); showPick(); let steered = false; const settledPick = () => { if (!open || !active || active.run) return null; if (steered) return active.el === selectedEl() ? null : active; if (input.value === currentText()) return null; const pick = settle(lastHits, input.value); return pick && pick === (lastHits.length === 1 ? pick : active) ? pick : null; }; let shown = opts; const isShown = (e) => e.style.display !== "none"; const visible = () => shown.filter((o) => isShown(o.li) && !o.disabled); const firstReal = () => visible().find((o) => !o.run && !o.prompt) || null; const unanswered = () => { const sel = picked(); return !sel || sel.prompt; }; const opening = () => { if (unanswered()) return null; const sel = picked(); return sel && isShown(sel.li) && !sel.disabled ? sel : firstReal(); }; const steps = () => visible().filter((o) => !o.prompt); let layout = 0; let placeDue = false; let scrollTo = null; let scrollTop = false; const onLayout = () => { layout = 0; if (!open) return; if (placeDue) place(); placeDue = false; if (scrollTop) list.scrollTop = 0; else if (scrollTo && isShown(scrollTo.li)) scrollTo.li.scrollIntoView({ block: "nearest" }); scrollTo = null; scrollTop = false; }; const soon = () => { if (!layout) layout = requestAnimationFrame(onLayout); }; let preferred = 0; let gap = 0; let chrome = 0; let scrollers = []; let floors = []; const place = () => { if (!preferred) { if (wrap.hasAttribute("rst-combo-up")) wrap.removeAttribute("rst-combo-up"); list.style.maxBlockSize = ""; const cs = getComputedStyle(list); scrollers = clippers(list, cs.position); preferred = parseFloat(cs.maxBlockSize) || 240; gap = parseFloat(cs.marginTop) || 0; chrome = cs.boxSizing === "border-box" ? 0 : ["paddingTop", "paddingBottom", "borderTopWidth", "borderBottomWidth"].reduce((n, k) => n + (parseFloat(cs[k]) || 0), 0); } const vv = window.visualViewport; let top = vv ? vv.offsetTop : 0; let bottom = vv ? vv.offsetTop + vv.height : window.innerHeight; if (told) { top = Math.max(top, told.top); bottom = Math.min(bottom, told.bottom); } for (const a of scrollers) { const r = a.getBoundingClientRect(); top = Math.max(top, r.top); bottom = Math.min(bottom, r.bottom); } const box = wrap.getBoundingClientRect(); for (const f of floors) { const r = f.getBoundingClientRect(); if (!r.height) continue; if (!f.hasAttribute("data-rst-select-ceiling")) { if (r.top >= box.bottom - 1) bottom = Math.min(bottom, r.top); } else if (r.bottom <= box.top + 1) top = Math.max(top, r.bottom); } const below = bottom - box.bottom - gap; const above = box.top - top - gap; const up = below < preferred + chrome && above > below; const h = Math.floor(Math.max(0, Math.min(preferred + chrome, up ? above : below) - chrome)) + "px"; if (list.style.maxBlockSize !== h) list.style.maxBlockSize = h; if (up !== wrap.hasAttribute("rst-combo-up")) wrap.toggleAttribute("rst-combo-up", up); }; const replace = (e) => { if (!wrap.isConnected) return closeList(false); if (e && e.type === "resize" && e.currentTarget === window) preferred = 0; placeDue = true; soon(); }; const scrolled = (e) => { if (e.target !== list) replace(); }; const setActive = (o, atTop) => { if (active && active !== o) active.li.classList.remove("is-active"); if (o && !o.li.classList.contains("is-active")) o.li.classList.add("is-active"); active = o || null; if (o) { if (input.getAttribute("aria-activedescendant") !== o.li.id) input.setAttribute("aria-activedescendant", o.li.id); scrollTop = !!(atTop && visible()[0] === o); scrollTo = o; soon(); } else if (input.hasAttribute("aria-activedescendant")) { input.removeAttribute("aria-activedescendant"); } }; const markSelected = () => { for (const o of opts) { const v = o.el && o.el === selectedEl() && !o.prompt ? "true" : "false"; if (o.li.getAttribute("aria-selected") !== v) o.li.setAttribute("aria-selected", v); } }; let pending = false; let frame = 0; let lastQuery = null; let lastHits = []; const lifted = new Set(); const anchorAfter = (o) => { const next = opts[o.index + 1]; if (next && !next.run && next.group === o.group) return next.sep || next.li; if (o.group) return null; if (next && !next.run) return next.group ? boxes.get(next.group).box : next.sep || next.li; return empty; }; const show = (e, on) => { if (isShown(e) !== on) e.style.display = on ? "" : "none"; }; const filter = (query) => { pending = false; const own = opts.filter((o) => !o.run); const searching = fold(query) !== ""; const answerable = (o) => !o.blank || offered(o.el.value, o.marked, native.required, searching, o.disabled); const hits = order(own.filter(answerable), query); lastHits = hits.filter((o) => !o.disabled); const hit = new Set(hits); const extra = opts.filter((o) => o.run); shown = searching ? [...hits, ...own.filter((o) => !hit.has(o)), ...extra] : opts; const tail = extra.length ? extra[0].li : null; if (empty.nextSibling !== tail || empty.parentNode !== list) list.insertBefore(empty, tail); if (searching) { const hitRow = new Set(hits.map((o) => o.li)); let ref = list.firstChild; for (const o of hits) { while (ref && ref !== empty && ref !== o.li && !hitRow.has(ref)) ref = ref.nextSibling; if (ref === o.li) { ref = ref.nextSibling; } else { list.insertBefore(o.li, ref); lifted.add(o); } } } else if (lifted.size) { for (const o of [...lifted].sort((a, b) => b.index - a.index)) home(o).insertBefore(o.li, anchorAfter(o)); lifted.clear(); } for (const o of own) { show(o.li, hit.has(o)); if (o.sep) show(o.sep, !searching); } for (const { box } of boxes.values()) show(box, !searching); for (const o of extra) show(o.li, true); const found = hits.filter((o) => !o.disabled).length; show(empty, !found); const text = found === 1 ? oneFmt : manyFmt.replace("{n}", String(found)); if (status.textContent !== text) status.textContent = text; const requeried = query !== lastQuery; if (requeried) steered = false; lastQuery = query; if (!searching && !steered && (requeried || unanswered())) setActive(opening()); else if ((searching && requeried) || !active || !shown.includes(active) || !isShown(active.li) || active.disabled) { setActive(firstReal(), true); } }; const flush = () => { if (pending && open) filter(input.value); }; const onFrame = () => { frame = 0; flush(); }; const searchTyping = () => { if (frame) { pending = true; return; } frame = requestAnimationFrame(onFrame); filter(input.value); }; const openList = (showAll) => { if (open || locked()) return; open = true; list.hidden = false; input.setAttribute("aria-expanded", "true"); floors = [...document.querySelectorAll("[data-rst-select-floor],[data-rst-select-ceiling]")]; preferred = 0; replace(); window.addEventListener("resize", replace); document.addEventListener("rst:select-viewport", replace); document.addEventListener("scroll", scrolled, true); if (window.visualViewport) { window.visualViewport.addEventListener("resize", replace); window.visualViewport.addEventListener("scroll", replace); } if (showAll) filter(""); markSelected(); setActive(opening()); }; const closeList = (revert) => { if (!open) return; open = false; list.hidden = true; window.removeEventListener("resize", replace); document.removeEventListener("rst:select-viewport", replace); document.removeEventListener("scroll", scrolled, true); if (window.visualViewport) { window.visualViewport.removeEventListener("resize", replace); window.visualViewport.removeEventListener("scroll", replace); } input.setAttribute("aria-expanded", "false"); input.removeAttribute("aria-activedescendant"); pending = false; cancelAnimationFrame(frame); frame = 0; lastQuery = null; if (active) active.li.classList.remove("is-active"); if (revert) { showText(); showPick(); } }; const choose = (o) => { if (!o || o.disabled || locked()) return; if (o.run) { o.run(); return; } if (!native.contains(o.el)) { closeList(true); return; } o.el.selected = true; native.dispatchEvent(new Event("change", { bubbles: true })); showText(); showPick(); markSelected(); closeList(false); }; let resuming = false; let pointerFocus = ""; const selectPick = () => { if (document.activeElement === input && showingPick && input.selectionStart === input.selectionEnd) { input.setSelectionRange(0, input.value.length); } }; input.addEventListener("pointerdown", (e) => { pointerFocus = document.activeElement === input ? "" : e.pointerType || "mouse"; }); input.addEventListener("focus", () => { if (resuming) return; if (pointerFocus !== "mouse") input.select(); openList(true); }); input.addEventListener("click", () => { if (pointerFocus) { pointerFocus = ""; selectPick(); requestAnimationFrame(selectPick); } openList(true); }); input.addEventListener("input", () => { showingPick = false; if (!lead.hidden) { lead.hidden = true; wrap.removeAttribute("rst-combo-has-lead"); } if (worn.length) wear([]); openList(false); searchTyping(); }); let tookEnter = false; input.addEventListener("keydown", (e) => { tookEnter = false; if (ACTS.has(e.key)) flush(); switch (e.key) { case "ArrowDown": { e.preventDefault(); if (!open) return openList(true); const v = steps(); steered = true; setActive(v[Math.min(v.indexOf(active) + 1, v.length - 1)] || v[0] || null); break; } case "ArrowUp": { e.preventDefault(); if (!open) return openList(true); const v = steps(); steered = true; setActive((active ? v[Math.max(v.indexOf(active) - 1, 0)] : v[v.length - 1]) || null); break; } case "Home": case "End": if (open) { e.preventDefault(); steered = true; const v = steps(); setActive((e.key === "Home" ? v[0] : v[v.length - 1]) || null); } break; case "Enter": if (open) { e.preventDefault(); tookEnter = true; if (active) choose(active); } break; case "Escape": if (open) { e.preventDefault(); e.stopPropagation(); closeList(true); } break; case "Tab": if (settledPick()) choose(settledPick()); else closeList(true); break; } }); input.addEventListener("keypress", (e) => { if (e.key === "Enter" && tookEnter) e.preventDefault(); tookEnter = false; }); list.addEventListener("mousedown", (e) => { const li = e.target.closest("[rst-combo-option]"); if (!li) return; e.preventDefault(); choose(opts.find((o) => o.li === li)); }); wrap.addEventListener("focusout", (e) => { if (gone) return; if (wrap.contains(e.relatedTarget)) return; flush(); if (settledPick()) choose(settledPick()); else closeList(true); }); let given = []; wrap.rstExtras = (rows) => { given = rows || []; for (let i = opts.length - 1; i >= 0; i--) { if (!opts[i].run) break; opts[i].li.remove(); opts.splice(i, 1); } for (const row of rows || []) { const li = el("li", "rst-combo-option"); li.id = listId + "-extra-" + ++extras; li.setAttribute("role", "option"); li.setAttribute("aria-selected", "false"); const name = el("span", "rst-combo-name"); name.textContent = row.label; li.append(name); if (row.meta) { const meta = el("span", "rst-combo-desc"); meta.textContent = row.meta; li.append(meta); } list.appendChild(li); opts.push({ text: row.label, name: row.label, desc: row.meta || "", short: "", lead: "", terms: [], classes: [], first: false, disabled: false, index: -1, group: null, el: null, li, run: row.run }); } shown = opts; if (open) filter(query()); }; const mine = new AbortController(); const follow = () => { showText(); showPick(); markSelected(); input.setCustomValidity(""); settleValidity(); }; native.addEventListener("change", follow, { signal: mine.signal }); document.addEventListener("reset", (e) => { if (e.target !== native.form) return; setTimeout(() => { if (e.defaultPrevented || gone) return; closeList(false); follow(); }, 0); }, { signal: mine.signal }); const settleValidity = () => { if (!native.validity.valid && native.willValidate) return; input.removeAttribute("aria-invalid"); input.setCustomValidity(""); }; native.addEventListener("invalid", () => input.setAttribute("aria-invalid", "true"), { signal: mine.signal }); const settleRequired = () => { if (native.required) input.setAttribute("aria-required", "true"); else input.removeAttribute("aria-required"); }; settleRequired(); const flips = new MutationObserver(() => { input.disabled = native.disabled; if (native.disabled) closeList(false); settleRequired(); settleValidity(); for (const o of opts) { if (!o.run) o.prompt = isPrompt(o.el.value, o.marked, native.required, offLimits(o.el)); } markSelected(); if (open) { if (showingPick) { showText(); const o = picked(); wear(o && !o.prompt ? o.classes : []); } filter(query()); } else { showText(); showPick(); } }); flips.observe(native, { attributes: true, attributeFilter: ["required", "disabled"] }); let gone = false; const stepAside = () => { gone = true; mine.abort(); flips.disconnect(); options.disconnect(); swapped.disconnect(); closeList(false); cancelAnimationFrame(frame); cancelAnimationFrame(layout); native.classList.remove("rst-sr-only"); native.removeAttribute("tabindex"); native.removeAttribute("aria-hidden"); if (inputAttr !== null) native.setAttribute("rst-input", inputAttr); delete native.dataset.rstEnhanced; enhanced.delete(native); if (label) label.htmlFor = native.id; wrap.remove(); }; const options = new MutationObserver((records) => { if (!records.some((r) => r.target !== native || r.type !== "attributes")) return; if (!native.isConnected || native.parentNode !== wrap.parentNode) { stepAside(); queueMicrotask(() => scan()); return; } flush(); const resume = { focused: document.activeElement === input, open, typed: showingPick ? null : input.value, at: active && active.el, extra: active && active.run ? opts.filter((o) => o.run).indexOf(active) : -1, steered, given, tookEnter, caret: [input.selectionStart, input.selectionEnd, input.selectionDirection], }; stepAside(); combo(native, resume); }); options.observe(native, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ["value", "label", "disabled", "data-rst-prompt"] }); const swapped = new MutationObserver(() => { if (native.isConnected && native.parentNode === wrap.parentNode) return; stepAside(); queueMicrotask(() => scan()); }); if (wrap.parentNode) swapped.observe(wrap.parentNode, { childList: true }); native.addEventListener("focus", () => { input.focus(); if (!native.validity.valid) { input.setCustomValidity(native.validationMessage); input.reportValidity(); } }, { signal: mine.signal }); input.addEventListener("input", () => input.setCustomValidity("")); input.addEventListener("blur", () => { pointerFocus = ""; if (gone) return; input.setCustomValidity(""); settleValidity(); }); if (resume) { resuming = true; if (resume.focused) input.focus(); resuming = false; tookEnter = resume.tookEnter; if (resume.given.length) wrap.rstExtras(resume.given); if (resume.open) { openList(resume.typed === null); if (resume.typed !== null) { input.value = resume.typed; showingPick = false; lead.hidden = true; wrap.removeAttribute("rst-combo-has-lead"); wear([]); filter(resume.typed); } const was = resume.extra >= 0 ? opts.filter((o) => o.run)[resume.extra] : resume.at && opts.find((o) => o.el === resume.at && isShown(o.li) && !o.disabled); if (was) { setActive(was); steered = resume.steered; } } if (resume.focused) input.setSelectionRange(...resume.caret); } return input; } function scan(root) { const within = root && root.querySelectorAll ? root : document; const found = [...within.querySelectorAll("select[data-rst-select]")]; if (within.matches && within.matches("select[data-rst-select]")) found.push(within); found.forEach((s) => { if (s.dataset.rstSelect !== "false" && !s.multiple) combo(s); }); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", () => scan()); } else { scan(); } document.addEventListener("rst:select-scan", (e) => queueMicrotask(() => scan(e.detail && e.detail.root))); })();