var ft=Object.defineProperty;var Q=Object.getOwnPropertySymbols;var dt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable;var X=(s,t,e)=>t in s?ft(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,b=(s,t)=>{for(var e in t||(t={}))dt.call(t,e)&&X(s,e,t[e]);if(Q)for(var e of Q(t))gt.call(t,e)&&X(s,e,t[e]);return s};function I(s){return Array.isArray?Array.isArray(s):rt(s)==="[object Array]"}const pt=1/0;function Mt(s){if(typeof s=="string")return s;let t=s+"";return t=="0"&&1/s==-pt?"-0":t}function mt(s){return s==null?"":Mt(s)}function _(s){return typeof s=="string"}function st(s){return typeof s=="number"}function xt(s){return s===!0||s===!1||Et(s)&&rt(s)=="[object Boolean]"}function nt(s){return typeof s=="object"}function Et(s){return nt(s)&&s!==null}function M(s){return s!=null}function K(s){return!s.trim().length}function rt(s){return s==null?s===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(s)}const _t="Incorrect 'index' type",yt=s=>`Invalid value for key ${s}`,It=s=>`Pattern length exceeds max of ${s}.`,St=s=>`Missing ${s} property in key`,At=s=>`Property 'weight' in key '${s}' must be a positive integer`,J=Object.prototype.hasOwnProperty;class wt{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(n=>{let r=it(n);e+=r.weight,this._keys.push(r),this._keyMap[r.id]=r,e+=r.weight}),this._keys.forEach(n=>{n.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function it(s){let t=null,e=null,n=null,r=1,i=null;if(_(s)||I(s))n=s,t=Z(s),e=D(s);else{if(!J.call(s,"name"))throw new Error(St("name"));const c=s.name;if(n=c,J.call(s,"weight")&&(r=s.weight,r<=0))throw new Error(At(c));t=Z(c),e=D(c),i=s.getFn}return{path:t,id:e,weight:r,src:n,getFn:i}}function Z(s){return I(s)?s:s.split(".")}function D(s){return I(s)?s.join("."):s}function Lt(s,t){let e=[],n=!1;const r=(i,c,o)=>{if(M(i))if(!c[o])e.push(i);else{let h=c[o];const a=i[h];if(!M(a))return;if(o===c.length-1&&(_(a)||st(a)||xt(a)))e.push(mt(a));else if(I(a)){n=!0;for(let l=0,f=a.length;ls.score===t.score?s.idx{this._keysMap[e.id]=n})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,_(this.docs[0])?this.docs.forEach((t,e)=>{this._addString(t,e)}):this.docs.forEach((t,e)=>{this._addObject(t,e)}),this.norm.clear())}add(t){const e=this.size();_(t)?this._addString(t,e):this._addObject(t,e)}removeAt(t){this.records.splice(t,1);for(let e=t,n=this.size();e{let c=r.getFn?r.getFn(t):this.getFn(t,r.path);if(M(c)){if(I(c)){let o=[];const h=[{nestedArrIndex:-1,value:c}];for(;h.length;){const{nestedArrIndex:a,value:l}=h.pop();if(M(l))if(_(l)&&!K(l)){let f={v:l,i:a,n:this.norm.get(l)};o.push(f)}else I(l)&&l.forEach((f,d)=>{h.push({nestedArrIndex:d,value:f})})}n.$[i]=o}else if(_(c)&&!K(c)){let o={v:c,n:this.norm.get(c)};n.$[i]=o}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function ct(s,t,{getFn:e=u.getFn,fieldNormWeight:n=u.fieldNormWeight}={}){const r=new Y({getFn:e,fieldNormWeight:n});return r.setKeys(s.map(it)),r.setSources(t),r.create(),r}function Ct(s,{getFn:t=u.getFn,fieldNormWeight:e=u.fieldNormWeight}={}){const{keys:n,records:r}=s,i=new Y({getFn:t,fieldNormWeight:e});return i.setKeys(n),i.setIndexRecords(r),i}function T(s,{errors:t=0,currentLocation:e=0,expectedLocation:n=0,distance:r=u.distance,ignoreLocation:i=u.ignoreLocation}={}){const c=t/s.length;if(i)return c;const o=Math.abs(n-e);return r?c+o/r:o?1:c}function vt(s=[],t=u.minMatchCharLength){let e=[],n=-1,r=-1,i=0;for(let c=s.length;i=t&&e.push([n,r]),n=-1)}return s[i-1]&&i-n>=t&&e.push([n,i-1]),e}const N=32;function Tt(s,t,e,{location:n=u.location,distance:r=u.distance,threshold:i=u.threshold,findAllMatches:c=u.findAllMatches,minMatchCharLength:o=u.minMatchCharLength,includeMatches:h=u.includeMatches,ignoreLocation:a=u.ignoreLocation}={}){if(t.length>N)throw new Error(It(N));const l=t.length,f=s.length,d=Math.max(0,Math.min(n,f));let g=i,p=d;const m=o>1||h,L=m?Array(f):[];let y;for(;(y=s.indexOf(t,p))>-1;){let x=T(t,{currentLocation:y,expectedLocation:d,distance:r,ignoreLocation:a});if(g=Math.min(x,g),p=y+l,m){let S=0;for(;S=G;E-=1){let v=E-1,U=e[s.charAt(v)];if(m&&(L[v]=+!!U),$[E]=($[E+1]<<1|1)&U,x&&($[E]|=(O[E+1]|O[E])<<1|1|O[E+1]),$[E]&ut&&(R=T(t,{errors:x,currentLocation:v,expectedLocation:d,distance:r,ignoreLocation:a}),R<=g)){if(g=R,p=v,p<=d)break;G=Math.max(1,2*d-p)}}if(T(t,{errors:x+1,currentLocation:d,expectedLocation:d,distance:r,ignoreLocation:a})>g)break;O=$}const P={isMatch:p>=0,score:Math.max(.001,R)};if(m){const x=vt(L,o);x.length?h&&(P.indices=x):P.isMatch=!1}return P}function Ft(s){let t={};for(let e=0,n=s.length;e{this.chunks.push({pattern:d,alphabet:Ft(d),startIndex:g})},f=this.pattern.length;if(f>N){let d=0;const g=f%N,p=f-g;for(;d{const{isMatch:y,score:O,indices:R}=Tt(t,p,m,{location:r+L,distance:i,threshold:c,findAllMatches:o,minMatchCharLength:h,includeMatches:n,ignoreLocation:a});y&&(d=!0),f+=O,y&&R&&(l=[...l,...R])});let g={isMatch:d,score:d?f/this.chunks.length:1};return d&&n&&(g.indices=l),g}}class w{constructor(t){this.pattern=t}static isMultiMatch(t){return q(t,this.multiRegex)}static isSingleMatch(t){return q(t,this.singleRegex)}search(){}}function q(s,t){const e=s.match(t);return e?e[1]:null}class Pt extends w{constructor(t){super(t)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(t){const e=t===this.pattern;return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}}class jt extends w{constructor(t){super(t)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(t){const n=t.indexOf(this.pattern)===-1;return{isMatch:n,score:n?0:1,indices:[0,t.length-1]}}}class Kt extends w{constructor(t){super(t)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(t){const e=t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,this.pattern.length-1]}}}class Dt extends w{constructor(t){super(t)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(t){const e=!t.startsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}}class Wt extends w{constructor(t){super(t)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(t){const e=t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[t.length-this.pattern.length,t.length-1]}}}class Bt extends w{constructor(t){super(t)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(t){const e=!t.endsWith(this.pattern);return{isMatch:e,score:e?0:1,indices:[0,t.length-1]}}}class ht extends w{constructor(t,{location:e=u.location,threshold:n=u.threshold,distance:r=u.distance,includeMatches:i=u.includeMatches,findAllMatches:c=u.findAllMatches,minMatchCharLength:o=u.minMatchCharLength,isCaseSensitive:h=u.isCaseSensitive,ignoreLocation:a=u.ignoreLocation}={}){super(t),this._bitapSearch=new ot(t,{location:e,threshold:n,distance:r,includeMatches:i,findAllMatches:c,minMatchCharLength:o,isCaseSensitive:h,ignoreLocation:a})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(t){return this._bitapSearch.searchIn(t)}}class at extends w{constructor(t){super(t)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(t){let e=0,n;const r=[],i=this.pattern.length;for(;(n=t.indexOf(this.pattern,e))>-1;)e=n+i,r.push([n,e-1]);const c=!!r.length;return{isMatch:c,score:c?0:1,indices:r}}}const W=[Pt,at,Kt,Dt,Bt,Wt,jt,ht],tt=W.length,zt=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Ht="|";function Vt(s,t={}){return s.split(Ht).map(e=>{let n=e.trim().split(zt).filter(i=>i&&!!i.trim()),r=[];for(let i=0,c=n.length;i!!(s[F.AND]||s[F.OR]),Qt=s=>!!s[H.PATH],Xt=s=>!I(s)&&nt(s)&&!V(s),et=s=>({[F.AND]:Object.keys(s).map(t=>({[t]:s[t]}))});function lt(s,t,{auto:e=!0}={}){const n=r=>{let i=Object.keys(r);const c=Qt(r);if(!c&&i.length>1&&!V(r))return n(et(r));if(Xt(r)){const h=c?r[H.PATH]:i[0],a=c?r[H.PATTERN]:r[h];if(!_(a))throw new Error(yt(h));const l={keyId:D(h),pattern:a};return e&&(l.searcher=z(a,t)),l}let o={children:[],operator:i[0]};return i.forEach(h=>{const a=r[h];I(a)&&a.forEach(l=>{o.children.push(n(l))})}),o};return V(s)||(s=et(s)),n(s)}function Jt(s,{ignoreFieldNorm:t=u.ignoreFieldNorm}){s.forEach(e=>{let n=1;e.matches.forEach(({key:r,norm:i,score:c})=>{const o=r?r.weight:null;n*=Math.pow(c===0&&o?Number.EPSILON:c,(o||1)*(t?1:i))}),e.score=n})}function Zt(s,t){const e=s.matches;t.matches=[],M(e)&&e.forEach(n=>{if(!M(n.indices)||!n.indices.length)return;const{indices:r,value:i}=n;let c={indices:r,value:i};n.key&&(c.key=n.key.src),n.idx>-1&&(c.refIndex=n.idx),t.matches.push(c)})}function qt(s,t){t.score=s.score}function te(s,t,{includeMatches:e=u.includeMatches,includeScore:n=u.includeScore}={}){const r=[];return e&&r.push(Zt),n&&r.push(qt),s.map(i=>{const{idx:c}=i,o={item:t[c],refIndex:c};return r.length&&r.forEach(h=>{h(i,o)}),o})}class k{constructor(t,e={},n){this.options=b(b({},u),e),this.options.useExtendedSearch,this._keyStore=new wt(this.options.keys),this.setCollection(t,n)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof Y))throw new Error(_t);this._myIndex=e||ct(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(t){M(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=()=>!1){const e=[];for(let n=0,r=this._docs.length;n-1&&(h=h.slice(0,e)),te(h,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(t){const e=z(t,this.options),{records:n}=this._myIndex,r=[];return n.forEach(({v:i,i:c,n:o})=>{if(!M(i))return;const{isMatch:h,score:a,indices:l}=e.searchIn(i);h&&r.push({item:i,idx:c,matches:[{score:a,value:i,norm:o,indices:l}]})}),r}_searchLogical(t){const e=lt(t,this.options),n=(o,h,a)=>{if(!o.children){const{keyId:f,searcher:d}=o,g=this._findMatches({key:this._keyStore.get(f),value:this._myIndex.getValueForItemAtKeyId(h,f),searcher:d});return g&&g.length?[{idx:a,item:h,matches:g}]:[]}const l=[];for(let f=0,d=o.children.length;f{if(M(o)){let a=n(e,o,h);a.length&&(i[h]||(i[h]={idx:h,item:o,matches:[]},c.push(i[h])),a.forEach(({matches:l})=>{i[h].matches.push(...l)}))}}),c}_searchObjectList(t){const e=z(t,this.options),{keys:n,records:r}=this._myIndex,i=[];return r.forEach(({$:c,i:o})=>{if(!M(c))return;let h=[];n.forEach((a,l)=>{h.push(...this._findMatches({key:a,value:c[l],searcher:e}))}),h.length&&i.push({idx:o,item:c,matches:h})}),i}_findMatches({key:t,value:e,searcher:n}){if(!M(e))return[];let r=[];if(I(e))e.forEach(({v:i,i:c,n:o})=>{if(!M(i))return;const{isMatch:h,score:a,indices:l}=n.searchIn(i);h&&r.push({score:a,key:t,value:i,idx:c,norm:o,indices:l})});else{const{v:i,n:c}=e,{isMatch:o,score:h,indices:a}=n.searchIn(i);o&&r.push({score:h,key:t,value:i,norm:c,indices:a})}return r}}k.version="6.6.2";k.createIndex=ct;k.parseIndex=Ct;k.config=u;k.parseQuery=lt;Ut(Gt);export{k as default};