-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_bundle_tinysearch.min.js
1 lines (1 loc) · 5.49 KB
/
search_bundle_tinysearch.min.js
1
function closeSearchNow(){const e=document.querySelector("main");e.innerHTML=window.main}function goSearchNow(){const e=document.querySelector("main");window.main||(window.main=e.innerHTML);var t=document.getElementById("suggestions"),n=t.cloneNode(!0),o=(n.id="results",document.createElement("div")),a='<form name="closeSearch"><h2><button type="submit" title="Close Search"><i class="svgs x"></i></button> Results For: '.concat(document.getElementById("searchinput").value,"</h2></form>");return o.innerHTML=a,n.insertBefore(o,n.firstChild),e.innerHTML=n.outerHTML,t.innerHTML="",document.getElementById("searchinput").value="",document.body.contains(document.closeSearch)&&(document.closeSearch.onsubmit=function(){closeSearchNow()}),!1}async function lazyLoad(){var e=document.querySelector("meta[name='base']").getAttribute("content");await init((e="/"==e.slice(-1)?e.slice(0,-1):e)+"/tinysearch_engine_bg.wasm")}var loaded=!(window.onload=function(){document.body.contains(document.goSearch)&&(document.goSearch.onsubmit=function(){return goSearchNow()})});function closeAllLists(e){for(var t=document.getElementById("suggestions");t.firstChild;)t.removeChild(t.firstChild)}function markTerm(e,t){return e.replace(new RegExp("(^|)("+t+")(|$)","ig"),"$1<mark><b>$2</b></mark>$3")}function autocomplete(e){e.addEventListener("input",function(e){var t=this.value;if(closeAllLists(),!t)return!1;for(var n=document.getElementById("suggestions"),o=search(t,99),a=0;a<o.length;a++){var r,c,i,s,u=o[a];(s=document.createElement("DIV")).innerHTML="<a href><span></span><span></span></a>",r=s.querySelector("a"),c=s.querySelector("span:first-child"),i=s.querySelector("span:nth-child(2)"),r.href=u[1]+"?q="+encodeURIComponent(t),c.innerHTML=markTerm(u[0],t),i.innerHTML=markTerm(u[2],t),n.appendChild(s)}})}loaded||(lazyLoad(),loaded=!0,document.body.contains(document.goSearch)&&(document.goSearch.onsubmit=function(){return goSearchNow()}));var searchinput=document.getElementById("searchinput");function suggestionFocus(t){191===t.keyCode&&"INPUT"!==document.activeElement.tagName&&"TEXTAREA"!==document.activeElement.tagName&&(t.preventDefault(),searchinput.focus(),suggestions.classList.remove("d-none")),27===t.keyCode&&(searchinput.blur(),suggestions.classList.add("d-none"),closeAllLists());const n=suggestions.querySelectorAll("a");if(!suggestions.classList.contains("d-none")&&0!==n.length){const a=[...n];var o=a.indexOf(document.activeElement);let e=0;38===t.keyCode?(t.preventDefault(),e=0<o?o-1:0,n[e].focus()):40===t.keyCode&&(t.preventDefault(),e=o+1<a.length?o+1:o,n[e].focus())}}document.addEventListener("keydown",suggestionFocus);let wasm,cachedTextDecoder=(autocomplete(document.getElementById("searchinput")),new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0})),cachegetUint8Memory0=(cachedTextDecoder.decode(),null);function getUint8Memory0(){return cachegetUint8Memory0=null!==cachegetUint8Memory0&&cachegetUint8Memory0.buffer===wasm.memory.buffer?cachegetUint8Memory0:new Uint8Array(wasm.memory.buffer)}function getStringFromWasm0(e,t){return cachedTextDecoder.decode(getUint8Memory0().subarray(e,e+t))}const heap=new Array(32).fill(void 0);heap.push(void 0,null,!0,!1);let heap_next=heap.length;function addHeapObject(e){heap_next===heap.length&&heap.push(heap.length+1);var t=heap_next;return heap_next=heap[t],heap[t]=e,t}let WASM_VECTOR_LEN=0,cachedTextEncoder=new TextEncoder("utf-8");const encodeString="function"==typeof cachedTextEncoder.encodeInto?function(e,t){return cachedTextEncoder.encodeInto(e,t)}:function(e,t){var n=cachedTextEncoder.encode(e);return t.set(n),{read:e.length,written:n.length}};function passStringToWasm0(e,t,n){if(void 0===n){const n=cachedTextEncoder.encode(e),o=t(n.length);return getUint8Memory0().subarray(o,o+n.length).set(n),WASM_VECTOR_LEN=n.length,o}let o=e.length,a=t(o);const r=getUint8Memory0();let c=0;for(;c<o;c++){const t=e.charCodeAt(c);if(127<t)break;r[a+c]=t}if(c!==o){0!==c&&(e=e.slice(c)),a=n(a,o,o=c+3*e.length);const t=getUint8Memory0().subarray(a+c,a+o);c+=encodeString(e,t).written}return WASM_VECTOR_LEN=c,a}function getObject(e){return heap[e]}function dropObject(e){e<36||(heap[e]=heap_next,heap_next=e)}function takeObject(e){var t=getObject(e);return dropObject(e),t}function search(e,t){var e=passStringToWasm0(e,wasm.__wbindgen_malloc,wasm.__wbindgen_realloc),n=WASM_VECTOR_LEN;return takeObject(wasm.search(e,n,t))}async function load(e,t){if("function"==typeof Response&&e instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if("application/wasm"==e.headers.get("Content-Type"))throw t;console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t)}var n=await e.arrayBuffer();return WebAssembly.instantiate(n,t)}return(n=await WebAssembly.instantiate(e,t))instanceof WebAssembly.Instance?{instance:n,module:e}:n}async function init(e){var t=document.querySelector("meta[name='base']").getAttribute("content");"/"==t.slice(-1)&&(t=t.slice(0,-1)),void 0===e&&(e=new URL(t+"/tinysearch_engine_bg.wasm",import.meta.url));const n={wbg:{}};n.wbg.__wbindgen_json_parse=function(e,t){return addHeapObject(JSON.parse(getStringFromWasm0(e,t)))};var{instance:e,module:t}=await load(await(e="string"==typeof e||"function"==typeof Request&&e instanceof Request||"function"==typeof URL&&e instanceof URL?fetch(e):e),n);return wasm=e.exports,init.__wbindgen_wasm_module=t,wasm}export default init;export{search};