(function(){"use strict";let d=[],i=[],u=0;function y(t){return"^"+t.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase()+"$"}function w(t){const e=t.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase();return{based:e,words:e.split(/\s+/)}}function C(t,e){const{based:s,words:c}=e;return t.includes(s)||c&&c.every(n=>t.includes(n))}const m=new Intl.Collator("en",{sensitivity:"base",numeric:!0,usage:"search"});function R(t){return[...t].sort((e,s)=>s.mtime-e.mtime)}function k(){return new Promise(t=>setTimeout(t,0))}async function F(t,e,s){const c=w(t),n=100,o=500,l=[];let g=0;for(let r=0;r<i.length&&l.length<n;r+=o){if(u!==s)return;const M=Math.min(r+o,i.length);for(let a=r;a<M&&l.length<n;a++){const h=i[a];C(h.haystack,c)&&l.push(h)}if(l.length>g&&u===s){g=l.length;const a=f(l,t,e);postMessage({type:"results",docs:a.map(p),id:s,done:!1})}r+o<i.length&&l.length<n&&await k()}if(u===s){const r=f(l,t,e);postMessage({type:"results",docs:r.map(p),id:s,done:!0})}}function f(t,e,s){const c=s+"/";return[...t].sort((n,o)=>(o.loc===s)-(n.loc===s)||(o.loc.slice(0,c.length)===c)-(n.loc.slice(0,c.length)===c)||m.compare(n.loc,o.loc)||(n.dir===!1)-(o.dir===!1)||o.name.includes(e)-n.name.includes(e)||m.compare(n.name,o.name))}function p(t){const{haystack:e,...s}=t;return s}self.onmessage=async t=>{const e=t.data;e.type==="update"?(d=e.documents.map(s=>({...s,haystack:y(s.name)})),i=R(d)):e.type==="search"&&(u=e.id,e.query?await F(e.query,e.loc,e.id):postMessage({type:"results",docs:[],id:e.id,done:!0}))}})();
