(function(){"use strict";let d=[],i=[],u=0;function h(t){return"^"+t.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase()+"$"}function y(t){const e=t.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase();return{based:e,words:e.split(/\s+/)}}function w(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 k(t){return[...t].sort((e,s)=>s.mtime-e.mtime)}function C(){return new Promise(t=>setTimeout(t,0))}async function F(t,e,s){const c=y(t),n=100,o=1e3,r=[];for(let l=0;l<i.length&&r.length<n;l+=o){if(u!==s)return;const M=Math.min(l+o,i.length);for(let a=l;a<M&&r.length<n;a++){const g=i[a];w(g.haystack,c)&&r.push(g)}if(r.length>0&&u===s){const a=f(r,t,e);postMessage({type:"results",docs:a.map(p),id:s,done:!1})}l+o<i.length&&r.length<n&&await C()}if(u===s){const l=f(r,t,e);postMessage({type:"results",docs:l.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:h(s.name)})),i=k(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}))}})();
