"use strict";(()=>{var vt=Object.create;var K=Object.defineProperty,wt=Object.defineProperties,Tt=Object.getOwnPropertyDescriptor,bt=Object.getOwnPropertyDescriptors,kt=Object.getOwnPropertyNames,J=Object.getOwnPropertySymbols,Mt=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,Et=Object.prototype.propertyIsEnumerable;var V=(t,e,n)=>e in t?K(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,F=(t,e)=>{for(var n in e||(e={}))Y.call(e,n)&&V(t,n,e[n]);if(J)for(var n of J(e))Et.call(e,n)&&V(t,n,e[n]);return t},q=(t,e)=>wt(t,bt(e));var Ft=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}};var Rt=(t,e,n,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of kt(e))!Y.call(t,r)&&r!==n&&K(t,r,{get:()=>e[r],enumerable:!(l=Tt(e,r))||l.enumerable});return t};var St=(t,e,n)=>(n=t!=null?vt(Mt(t)):{},Rt(e||!t||!t.__esModule?K(n,"default",{value:t,enumerable:!0}):n,t));var U=(t,e,n)=>V(t,typeof e!="symbol"?e+"":e,n);var E=(t,e,n)=>new Promise((l,r)=>{var a=i=>{try{s(n.next(i))}catch(u){r(u)}},o=i=>{try{s(n.throw(i))}catch(u){r(u)}},s=i=>i.done?l(i.value):Promise.resolve(i.value).then(a,o);s((n=n.apply(t,e)).next())});var xt=Ft(mt=>{"use strict";function C(t,e,n={}){return{name:t,from:e,meta:n}}function W(t,e){let n=[{value:t,depth:0}];for(let l=0,r=-1,a=0;l>=0;){let{value:o,depth:s}=n[l];if(r<=s&&o.type==="operator"&&o.data.operands.length>0)for(let i=o.data.operands.length;i>0;)n[++l]={value:o.data.operands[--i],depth:s+1};else{let i=e(o,a++,s);if(typeof i<"u")return i;--l}r=s}}var P=class extends Error{constructor(t,e){super(e),this.code=t}};function $(t,e){let n=qt(t);for(let l=0;l{let{matches:l}=n;for(let r=0;r{let r=e.get(n);return typeof r>"u"&&e.set(n,r=t(n,...l)),r}}function D(t,e){return Object.defineProperty(e,"name",{value:t}),e}function tt(t){return E(this,null,function*(){let e=[];if(typeof t.plugins<"u")for(let n=0;n32)throw new RangeError("Bit format exceeds 32 bits");return t}function nt(t,e,n){let l=B(t),r=B(e),a=typeof n<"u"?B(n):32-l-r;return It({d:l,f:r,x:a})}var b=[0];for(let t=0;t<32;t++)b.push(b[t]|1<=n&&t{e+=l*l}),Math.sqrt(e)}function Pt(t,e){t instanceof G?t.data.forEach((n,l)=>{e(n,l)}):t.forEach((n,l)=>{e({start:n,end:n+1,value:1},l)})}var O=class{constructor(t,e=jt(Math.ceil(t/32))){this.size=t,this.data=e}get(t){return this.data[t>>>5]>>>t&1}set(t){this.data[t>>>5]|=1<<(t&31)}forEach(t){let e=this.size&31;for(let n=0;n>>0;for(let n=0;n0;r++){let{value:a,depth:o}=n[--l],s=e(a,r,o);if(typeof s<"u")return s;for(let i=a.children.length;i>0;)n[l++]={value:a.children[--i],depth:o+1}}}function _t(t,e){return E(this,null,function*(){let{fields:n,plugins:l=[]}=e,r=nt(t.length,n.length),a=[];for(let i=0;i"u")continue;let f=i<{var m;return(m=g.onFilterInput)==null?void 0:m.call(g,p,f,r)},d);let c=a[u],h=M();d=Array.isArray(d)?d:[d];for(let p=0;p{let v=c.index.get(m.node);typeof v>"u"&&c.index.set(m.node,v=M());let w=c.terms.length;for(let T=0;T{var u;return(u=i.onFilterStore)==null?void 0:u.call(i,s,e,t)}),s})}function Ht(t,e,n,l={}){let r=[];if(e<0||e>=t.count.fields)return r;let a=t.shards[e],o=new Map,{count:s=1/0,depth:i=1/0}=l;for(let u=0;ui)continue;let p=o.get(d);typeof p>"u"&&o.set(d,p={node:f,children:[]});let g=r;h>0&&(g=o.get(a.terms[c]).children),g.length=t.count.fields)return{documents:l,terms:r};let a=t.shards[n];return e.forEach(o=>{let{occurrences:s}=a.terms[o];for(let i=0;i>>t.space.x>>>t.space.f;l.set(u)}r[n].set(o)}),{documents:l,terms:r}}function Vt(t){let{documents:e,terms:n}=H(t);A(e,1);for(let l=0;lnew O(e.length))}}function Kt(t,e,n){let{compiler:l,fields:r,plugins:a=[]}=n,{input:o,scope:s,abort:i=!1}=z(a,(f,c)=>{var h;return(h=c.onFilterQuery)==null?void 0:h.call(c,f,t,n)},e),u={items:[],query:{select:H(t),values:[]}},d=new Map;if(i===!1){let f=l(n),{select:c,values:h}=f(o,t);typeof s<"u"&&_(c.documents,s);let p=new Map;u.query={select:c,values:h},c.terms.forEach((g,m)=>{g.forEach(y=>{let x=t.shards[m],{occurrences:v}=x.terms[y];for(let w=0;w>>t.space.x,S=T>>>t.space.f;if(!c.documents.get(S))continue;let I=p.get(T);typeof I>"u"&&p.set(T,I=new j(M()));let yt=k&b[t.space.x];I.add(yt,y)}})}),c.documents.forEach(g=>{let m={id:g,matches:[]};u.items.push(m),d.set(g,m)}),p.forEach((g,m)=>{let y=m>>>t.space.f,x=m&b[t.space.f];d.get(y).matches.push({id:m,field:r[x].name,value:{filter:g},score:0})})}return z(a,(f,c)=>{var h;return(h=c.onFilterResult)==null?void 0:h.call(c,f,t,n)},u)}function at(t){let{fields:e}=t;return(n,l)=>{if(Qt(n))return n;let r=[Vt(l)],a=[],o=0;return W(n,({type:s,data:i})=>{switch(s){case"value":let u=e.findIndex(({name:c})=>c===i.field);if(u===-1){r[o++]=H(l);break}let d=i.value;if(typeof d!="object"){let c=new j(M()),h=l.shards[u],p=h.index.get(d);if(typeof p<"u")for(let g=0;gf+1&&o--;){Q(r[f].documents,r[o].documents);for(let c=0;cf+1&&o--;){_(r[f].documents,r[o].documents);for(let c=0;cf+1&&o--;)lt(r[f].documents,r[o].documents)}}}),{select:r[0],values:a}}}function Ut(t){return{name:t.name,data:t.data,onFilterOptions:t.onFilterOptions,onFilterInput:t.onFilterInput,onFilterStore:t.onFilterStore,onFilterQuery:t.onFilterQuery,onFilterResult:t.onFilterResult}}function st(t){return typeof t=="object"&&t!==null&&"type"in t&&"data"in t}function Bt(t){return typeof t=="object"&&t!==null&&"select"in t&&"values"in t}function Nt(t){return t.normalize("NFKD").toLowerCase()}function Wt(t,e){let n=Math.min(t.length,e.length);for(let l=0;l65535)){let a=e(r=t.codePointAt(n),n);if(typeof a<"u")return a}}function it(t,e,n=0,l=t.length){let r=M();return Gt(t,a=>{r.push(a);let o=e(String.fromCodePoint(...r),r.length);if(typeof o<"u")return o},n,l)}function Jt(t,e,n=0,l=t.length){let r=n;for(let a=0;rn&&e(n,n=r);continue;case 62:n=r+1}r>n&&e(n,r)}function ut(t,e,n,l=0){return Jt(t,(r,a)=>e(t,(o,s)=>{l=n({value:t.slice(o,s),index:l,start:o,end:s})},r,a)),l}function Yt(t,e,n,l=0){for(let r=0,a=0;r(o.start+=a,o.end+=a,n(o)),l);return l}function Zt(t){let e=new RegExp(t,"gu");return(n,l,r=0,a=n.length)=>{var i;e.lastIndex=r;let o,s=0;do{o=e.exec(n);let u=(i=o==null?void 0:o.index)!=null?i:a;r"u")continue;let p=f<{var y;return(y=m.onTextInput)==null?void 0:y.call(m,g,p,o)},h),h=Array.isArray(h)?h:[h],Yt(h,n,g=>{let m=z(a,(y,x)=>{var v;return(v=x.onTextTokens)==null?void 0:v.call(x,y)},[g]);for(let y=0;y"u"?s.set(x,[p<{var c;return(c=f.onTextStore)==null?void 0:c.call(f,u,e,t)}),u})}function Xt(t,e,n){let{documents:l,terms:r}=L(t);return n<0||n>=t.count.fields?{documents:l,terms:r}:(e.forEach(a=>{let{occurrences:o}=t.terms[a];for(let s=0;s>>t.space.x;if((i&b[t.space.f])!==n)continue;let u=i>>>t.space.f;l.set(u)}r.set(a)}),{documents:l,terms:r})}function te(t,e){let{documents:n,terms:l}=L(t),r=t.space.f+t.space.x;return e.forEach(a=>{let{occurrences:o}=t.terms[a];for(let s=0;s>>r);l.set(a)}),{documents:n,terms:l}}function L(t){return{documents:new O(t.count.documents),terms:new O(t.terms.length)}}function ee(t,e,n){let{compiler:l,fields:r,plugins:a=[]}=n,{input:o,scope:s,abort:i=!1}=z(a,(f,c)=>{var h;return(h=c.onTextQuery)==null?void 0:h.call(c,f,t,n)},e),u={items:[],query:{select:L(t),values:[]}},d=new Map;if(i===!1){let f=l(n),{select:c,values:h}=f(o,t);typeof s<"u"&&_(c.documents,s);let p=new O(r.length),g=new Map;u.query={select:c,values:h},c.terms.forEach(m=>{A(p,0);for(let x=0;x>>t.space.x,k=w>>>t.space.f;if(!c.documents.get(k))continue;let T=w&b[t.space.f];if(!p.get(T))continue;let S=g.get(w);typeof S>"u"&&g.set(w,S=new j(M()));let I=v&b[t.space.x];S.add(I,m)}}),c.documents.forEach(m=>{let y={id:m,matches:[]};u.items.push(y),d.set(m,y)}),g.forEach((m,y)=>{let x=y>>>t.space.f,v=y&b[t.space.f];d.get(x).matches.push({id:y,field:r[v].name,value:{text:m},score:0})})}return z(a,(f,c)=>{var h;return(h=c.onTextResult)==null?void 0:h.call(c,f,t,n)},u)}function ne(t,e=10){return t.length>1?1+t[t.length-1]-t[0]:e}function re(t,e,n,l=10){let r=[];t.value.text.forEach((s,i)=>{for(let u=0;us.index-i.index);let a=r.slice(0,1),o=0;for(let s=0;sl||u.value===i.value)d=a.map(({index:f})=>f),a=[r[s+1]];else{for(let f=0;fu.index-i.index){let h=a.splice(f+1);d=a.map(({index:p})=>p),a=[...h,r[s+1]]}else d=a.map(({index:h})=>h),a=[r[s+1]];break}}typeof d>"u"&&a.push(r[s+1])}if(typeof d<"u"){let f=n(d,o++);if(typeof f<"u")return f}}if(a.length)return n(a.map(({index:s})=>s),o)}function le(t){let{transform:e,parser:n,fields:l}=t,r=n(t);return(a,o)=>{if(Bt(a))return a;typeof a=="string"&&(a=r(a));let s=[L(o)],i=[],u=0;return W(a,({type:d,data:f})=>{switch(d){case"value":let c=f.value;if(typeof c=="string"){let p=new j(M()),g=o.index.get(e(c));typeof g<"u"&&p.add(g,1),c=p}if(f.field==="*")s[u++]=te(o,c);else{let p=l.findIndex(({name:g})=>g===f.field);s[u++]=Xt(o,c,p)}i.push(q(F({},f),{value:c}));break;case"operator":let h=u-f.operands.length;switch(f.operator){case"or":for(;u>h+1&&u--;)Q(s[h].documents,s[u].documents),Q(s[h].terms,s[u].terms);break;case"and":for(;u>h+1&&u--;)_(s[h].documents,s[u].documents),Q(s[h].terms,s[u].terms);break;case"not":for(ot(s[h].documents),A(s[h].terms,0);u>h+1&&u--;)lt(s[h].documents,s[u].documents)}}}),{select:s[0],values:i}}}function ft(t,e){return W(t,(n,l,r)=>{if(n.type!=="value")return;let a=e(n.data,l,r);if(typeof a<"u")return a})}function ct(t){if(t.length===0)return[];let e=[],n=[];for(let a=0;aa.index-o.index);let l=new Set([n[0].value]),r=n[0].index;for(let a=1;a{t[u].start>r||t[u].end{e.push({start:r,end:a,value:n})})}return new G(ct(e))}function oe(t,e="or",n){let{separator:l}=t;return n!=null||(n=r=>({field:"*",value:r.value})),r=>{let a=[];return ut(r,l,o=>{let s=n(o);typeof s<"u"&&a.push({type:"value",data:s})}),{type:"operator",data:{operator:e,operands:a}}}}function ae(t,e){return E(this,null,function*(){let n=yield tt(e),l=yield zt(n,(a,o)=>{var s;return(s=o.onTextOptions)==null?void 0:s.call(o,a,t)},q(F({},e),{plugins:n})),r=yield $t(t,l);return D("text",a=>{if(a.type!=="text")throw new P("unsupported");return{type:a.type,data:ee(r,a.data,l)}})})}function R(t){return{name:t.name,data:t.data,onTextOptions:t.onTextOptions,onTextInput:t.onTextInput,onTextTokens:t.onTextTokens,onTextStore:t.onTextStore,onTextQuery:t.onTextQuery,onTextResult:t.onTextResult}}function se(t){let{handlers:e}=t,n,l=new Map;return Ut({name:"aggregation",onFilterStore(r,a){for(let o=0;o"u")continue;let i=!0;a.documents.forEach(u=>{i=!1}),i&&A(a.documents,1),r.aggregations.push(s(o,a))}}})}function ie(t={}){let{empty:e=!1,limit:n}=t;return(l,{fields:r})=>{let a=l.space.f+l.space.x;return D("term",({type:o,data:s},{documents:i})=>{if(o!=="term")throw new P("unsupported");let u=r.findIndex(({name:f})=>f===s.field),d=Ht(l,u,f=>{let c=0,{occurrences:h}=f;for(let p=0;p>>a)&&c++;if(!(e===!1&&c===0))return{value:f.value,count:c}},F(F({},n),s.limit));return{type:o,data:{field:s.field,value:d}}})}}function ue(t,e="prefix"){return{type:e,data:t}}function fe(t){return typeof t=="object"&&"type"in t&&typeof t.type=="string"&&"data"in t&&typeof t.data=="string"}function ce(t,e={}){var i;let{prefix:n=2,filter:l=[]}=e,r=t.terms,a=new Map,o=Ot(r.length),s=M();for(let u=0;u{var p;return a.set(c,(p=a.get(c))!=null?p:u),h===n||void 0});let f=u?r[u-1]:"";o[u]=Wt(f,d)}for(let u=0;uu-d),{terms:r,index:a,cover:o,exact:s}}function de(t,e){let n="",l=-1,r=-1;if(it(e,s=>{let i=t.index.get(s);if(typeof i>"u")return!0;n=s,l=i}),l!==-1)for(let s=n.length;ss>l&&so),index:e.index},{prefix:t.prefix,filter:(r=t.filter)==null?void 0:r.map(l)}))},onTextQuery(e,n,l){let{transform:r,parser:a}=l;if(typeof e.input=="string")e.input=a(l)(e.input);else if(!st(e.input))return;ft(e.input,o=>{var i;let s=o.value;if(fe(s))s=r(s.data);else return;o.value=(i=de(this.data,s))!=null?i:s})}})}function pe(t){let e=q(F({},t),{plugins:[]}),n,l,r;return R({name:"filter",onTextOptions(o,s){return E(this,null,function*(){e.plugins=yield tt(t),r=yield _t(s,e)})},onTextQuery(o){typeof o.filter<"u"&&(n=o.filter,l!=null||(l=at(e)),n.input=l(n.input,r),o.scope=n.input.select.documents)},onTextResult(o){if(typeof n<"u"){let s=!0;o.query.select.documents.forEach(u=>{s=!1}),s||(n.scope=o.query.select.documents);let i=Kt(r,n,e);o.aggregations=i.aggregations,n=void 0}}})}function ht(t,e){let n=[],l=t/e>>>0,r=t%e,a=0;if(l)for(let o=0;os);l.sort((o,s)=>t.terms[o].length-t.terms[s].length||t.terms[o].localeCompare(t.terms[s]));let r=0;for(let o=0;or&&(r=t.terms[o].length);let a=[];for(let o=0;o"u"?i[d].set(f,[l[o]]):c.push(l[o])}}return{index:a,terms:t.terms,idxmp:l}}var ye=[["id","di","rr"],["dr","rd"],["dd"]];function pt(t,e,n=2){if(t.lengthn)return;let o,s,i,u=n+1;for(let d of ye[a]){for(i=o=s=0;on)break;switch(d[i-1]){case"d":o++;break;case"i":s++;break;case"r":o++,s++;break}}else o++,s++;i+=l-o+(r-s),i"u")continue;let o=me(e,a,2);for(let s=0;s"u"))for(let c of f){let h=t.terms[c].length,p=n(t.terms[c],e);typeof p<"u"&&l.add(c,(h-p)/h)}}}}if(l.data.length)return l}function we(t={}){return R({name:"fuzzy",onTextStore(e){var n;(n=this.data)!=null||(this.data=xe({terms:e.terms.map(({value:l})=>l)},t))},onTextQuery(e,n,l){let{transform:r,parser:a}=l;if(typeof e.input=="string")e.input=a(l)(e.input);else if(!st(e.input))return;ft(e.input,o=>{var i;let s=o.value;if(typeof s=="string")s=r(s);else return;n.index.get(s)||(o.value=(i=ve(this.data,s))!=null?i:s)})}})}function Te(){return{tables:new Map}}function be(t,e={}){let{count:n}=e;return D("term",l=>{let r=dt(l);return(a,o)=>{let s=[];return a.value.text.forEach((i,u)=>{let d=o[i]>>>10,f=o[i]&b[10];for(let p=0;pi.start-u.start),{ranges:ct(s).slice(0,n)}}})}function ke(t){let e,n;return R({name:"highlight",data:Te(),onTextInput(l,r){let{tables:a}=this.data;a.set(r,n=M())},onTextTokens(l){for(let r=0;r{let s=r.get(o.id);if(o.value.highlight)return;let i=a(o,s);o.value=q(F({},o.value),{highlight:i})})}})}function Me(){return{directives:[]}}function gt(...t){return(e,n)=>{for(let l=0;l{if(l!=="match")throw new P("unsupported");let a=Fe(t),o=gt(...e.map(s=>s(n)));return $(n,({matches:s})=>{s.sort(a)}),(s,i)=>{let u=Math.min(s.matches.length,i.matches.length);for(let d=0,f=0;dl*(r.get(o.field)-r.get(s.field))}function Re(t,e={}){let n=dt(t.query),l=N(re),r=N(ne);return(a,o)=>{let s=l(a,n,f=>f),i=l(o,n,f=>f);if(s.length!==i.length)return i.length-s.length;let u=r(s),d=r(i);return u!==d?u-d:s[0]!==i[0]?s[0]-i[0]:0}}function Se(t){let e=new Map;return R({name:"order",data:Me(),onTextOptions(l,r){return E(this,null,function*(){for(let a=0;a"u")throw new P("unknown");a.push(i(l,s))}l.items.sort(gt(...a))}})}function qe(t){let e=t.handler();return R({name:"pagination",onTextQuery(n){return e.onQuery(n,t)},onTextResult(n){return e.onResult(n,t)}})}function ze(t){let{id:e,size:n=10,from:l=0}=t;if(l-n>=0)return{id:e,size:n,from:l-n}}function Ae(t,e){let{id:n,size:l=10,from:r=0}=t;if(r+l(a,o,s,i)=>{r(a,(u,d)=>{let f=a.slice(u,d);if(!n||!Oe.test(f)){o(u,d);return}let c=0;for(let h of n.segment(f))if(h.isWordLike){let p=u+h.index;o(p,p+h.segment.length),c++}c||o(u,d)},s,i)};return R({name:"segmentation",onTextOptions(r){if(n)return q(F({},r),{separator:l(r.separator)})}})}var Z=null;self.onmessage=t=>E(null,null,function*(){var n;let e=t.data;switch(e.type){case 0:let l=(n=e.data.config.lang)==null?void 0:n.find(je);Z=yield ae(e.data.items,{separator:Zt(e.data.config.separator),transform:N(Nt),parser:a=>oe(a,"and",o=>({field:"*",value:ue(o.value),range:{start:o.start,end:o.end,value:o.index}})),compiler:le,fields:[C("title",a=>a.title,{weight:3}),C("text",a=>a.text),C("path",a=>a.path,{weight:2})],plugins:[...l?[Ce(l)]:[],he(),we(),pe({compiler:at,fields:[C("tags",a=>a.tags)],plugins:[se({handlers:[ie()]})]}),Se({handlers:[a=>Ee({fields:a.fields,comparators:[Re]})],defaults:{order:[{type:"match",data:{field:"*"}}]}}),()=>R({onTextResult(a){a.total=a.items.length}}),qe({handler:Ie,size:10}),ke({handler:a=>be(a)}),()=>R({onTextResult(a){let{query:o}=a,s=o.values.map(({range:i,value:u})=>{var f,c;let d=!1;return u.forEach((h,p)=>{!d&&p<1&&(d=!0)}),d?-1:((f=i==null?void 0:i.end)!=null?f:0)-((c=i==null?void 0:i.start)!=null?c:0)});X(a,i=>{var u;(u=i.value.highlight)==null||u.ranges.forEach(d=>{d.value=s[d.value]})})}})]}),self.postMessage({type:1});break;case 2:let r=Z({type:"text",data:e.data});self.postMessage({type:3,data:r.data});break}})});var Ue=St(xt());})();