document.addEventListener("DOMContentLoaded",function(){if(/iPad|iPhone|Macintosh/.test(navigator.userAgent)){const e=document.querySelectorAll(".search-wrapper kbd");e.forEach(e=>{e.innerHTML='<span class="hx-text-xs">⌘</span>K'})}}),function(){const h="/en.search-data.json",u=document.querySelectorAll(".search-input");for(const e of u)e.addEventListener("focus",o),e.addEventListener("keyup",p),e.addEventListener("keydown",n),e.addEventListener("input",m);const d=document.querySelectorAll(".search-wrapper kbd");function a(e){d.forEach(t=>{t.style.opacity=e})}function m(e){const t=e.target.value.length>0?0:100;a(t)}function e(){const e=Array.from(document.querySelectorAll(".search-wrapper")).filter(e=>e.clientHeight>0);return e.length===1?{wrapper:e[0],inputElement:e[0].querySelector(".search-input"),resultsElement:e[0].querySelector(".search-results")}:0[0]}const l=["input","select","button","textarea"];document.addEventListener("keydown",function(t){const{inputElement:n}=e();if(!n)return;const s=document.activeElement,o=s&&s.tagName;if(n===s||!o||l.includes(o)||s&&s.isContentEditable)return;t.key==="/"||t.key==="k"&&(t.metaKey||t.ctrlKey)?(t.preventDefault(),n.focus()):t.key==="Escape"&&n.value&&n.blur()}),document.addEventListener("mousedown",function(n){const{inputElement:o,resultsElement:s}=e();if(!o||!s)return;n.target!==o&&n.target!==s&&!s.contains(n.target)&&(a(100),t())});function r(){const{resultsElement:n}=e();if(!n)return{result:0[0],index:-1};const t=n.querySelector(".active");if(!t)return{result:0[0],index:-1};const s=parseInt(t.dataset.index,10);return{result:t,index:s}}function s(t){const{resultsElement:s}=e();if(!s)return;const{result:o}=r();o&&o.classList.remove("active");const n=s.querySelector(`[data-index="${t}"]`);n&&(n.classList.add("active"),n.focus())}function c(){const{resultsElement:t}=e();return t?t.dataset.count:0}function i(){const{inputElement:n}=e();if(!n)return;t(),n.value="",n.blur()}function t(){const{resultsElement:t}=e();if(!t)return;t.classList.add("hx-hidden")}function n(n){const{inputElement:o}=e();if(!o)return;const d=c(),{result:l,index:a}=r();switch(n.key){case"ArrowUp":n.preventDefault(),a>0&&s(a-1);break;case"ArrowDown":n.preventDefault(),a+1<d&&s(a+1);break;case"Enter":n.preventDefault(),l&&l.click(),i();case"Escape":n.preventDefault(),t(),o.value="",o.dispatchEvent(new Event("input")),o.blur();break}}function o(e){e.target.removeEventListener("focus",o),window.pageIndex&&window.sectionIndex||f()}async function f(){const n="forward",o=()=>{const e=document.documentElement.lang||"en";return e.startsWith("zh")||e.startsWith("ja")||e.startsWith("ko")},i=e=>e.replace(/[\x00-\x7F]/g,"").split(""),a=e=>(""+e).toLocaleLowerCase().split(/[\p{Z}\p{S}\p{P}\p{C}]+/u),s=o()?i:a;window.pageIndex=new FlexSearch.Document({tokenize:n,encode:s,cache:100,document:{id:"id",store:["title","crumb"],index:"content"}}),window.sectionIndex=new FlexSearch.Document({tokenize:n,encode:s,cache:100,document:{id:"id",store:["title","content","url","display","crumb"],index:"content",tag:"pageId"}});const r=await fetch(h),e=await r.json();let t=0;for(const n in e){let a="";++t;const i=n.split("/").filter(e=>e!=""&&!e.startsWith("#"));let s="",o="/";for(let t=0;t<i.length;t++){const r=i[t];o+=r+"/";const c=e[o];if(!c){console.warn("Excluded page",o,"- will not be included for search result breadcrumb for",n);continue}let a=e[o].title;a=="_index"&&(a=r.split("-").map(e=>e).join(" ")),s+=a,t<i.length-1&&(s+=" > ")}for(const c in e[n].data){const[l,u]=c.split("#"),o=n.trimEnd("/")+(l?"#"+l:""),i=u||e[n].title,d=e[n].data[c]||"",r=d.split(`
`).filter(Boolean);sectionIndex.add({id:o,url:o,title:i,crumb:s,pageId:`page_${t}`,content:i,...r[0]&&{display:r[0]}});for(let e=0;e<r.length;e++)sectionIndex.add({id:`${o}_${e}`,url:o,title:i,crumb:s,pageId:`page_${t}`,content:r[e]});a+=` ${i} ${d}`}window.pageIndex.add({id:t,title:e[n].title,crumb:s,content:a})}}function p(n){const i=n.target.value;if(!n.target.value){t();return}const{resultsElement:o}=e();for(;o.firstChild;)o.removeChild(o.firstChild);o.classList.remove("hx-hidden");const a=window.pageIndex.search(i,5,{enrich:!0,suggest:!0})[0]?.result||[],r=[],s={};for(let e=0;e<a.length;e++){const t=a[e];s[e]=0;const n=window.sectionIndex.search(i,5,{enrich:!0,suggest:!0,tag:`page_${t.id}`})[0]?.result||[];let o=!0;const c={};for(let i=0;i<n.length;i++){const{doc:a}=n[i],u=a.display!==0[0];u&&s[e]++;const{url:l,title:h}=a,d=a.display||a.content;if(c[l+"@"+d])continue;c[l+"@"+d]=!0,r.push({_page_rk:e,_section_rk:i,route:l,prefix:o?t.doc.crumb:0[0],children:{title:h,content:d}}),o=!1}}const c=r.sort((e,t)=>e._page_rk===t._page_rk?e._section_rk-t._section_rk:s[e._page_rk]!==s[t._page_rk]?s[t._page_rk]-s[e._page_rk]:e._page_rk-t._page_rk).map(e=>({id:`${e._page_rk}_${e._section_rk}`,route:e.route,prefix:e.prefix,children:e.children}));g(c,i)}function g(t,s){const{resultsElement:o}=e();if(!o)return;if(!t.length){o.innerHTML=`<span class="no-result">No results found.</span>`;return}function r(e,t){const n=t.replace(/[-\\^$*+?.()|[\]{}]/g,"\\$&"),s=new RegExp(n,"gi");return e.replace(s,e=>`<span class="match">${e}</span>`)}function c(e){const t=document.createElement("div");return t.innerHTML=e.trim(),t.firstChild}function l(e){const t=e.target.closest("a");if(t){const e=o.querySelector("a.active");e&&e.classList.remove("active"),t.classList.add("active")}}const a=document.createDocumentFragment();for(let o=0;o<t.length;o++){const e=t[o];e.prefix&&a.appendChild(c(`
          <div class="prefix">${e.prefix}</div>`));let d=c(`
        <li>
          <a data-index="${o}" href="${e.route}" class=${o===0?"active":""}>
            <div class="title">`+r(e.children.title,s)+`</div>`+(e.children.content?`<div class="excerpt">`+r(e.children.content,s)+`</div>`:"")+`
          </a>
        </li>`);d.addEventListener("mousemove",l),d.addEventListener("keydown",n),d.querySelector("a").addEventListener("click",i),a.appendChild(d)}o.appendChild(a),o.dataset.count=t.length}}()