/** * Fuse.js v6.5.3 - Lightweight fuzzy-search (http://fusejs.io) * * Copyright (c) 2021 Kiro Risk (http://kiro.me) * All Rights Reserved. Apache Software License 2.0 * * http://www.apache.org/licenses/LICENSE-2.0 */ function e(e){return Array.isArray?Array.isArray(e):"[object Array]"===o(e)}function t(e){return"string"==typeof e}function n(e){return"number"==typeof e}function i(e){return!0===e||!1===e||function(e){return function(e){return"object"==typeof e}(e)&&null!==e}(e)&&"[object Boolean]"==o(e)}function s(e){return null!=e}function r(e){return!e.trim().length}function o(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}const c=Object.prototype.hasOwnProperty;class h{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach((e=>{let n=a(e);t+=n.weight,this._keys.push(n),this._keyMap[n.id]=n,t+=n.weight})),this._keys.forEach((e=>{e.weight/=t}))}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function a(n){let i=null,s=null,r=null,o=1;if(t(n)||e(n))r=n,i=l(n),s=d(n);else{if(!c.call(n,"name"))throw new Error((e=>`Missing ${e} property in key`)("name"));const e=n.name;if(r=e,c.call(n,"weight")&&(o=n.weight,o<=0))throw new Error((e=>`Property 'weight' in key '${e}' must be a positive integer`)(e));i=l(e),s=d(e)}return{path:i,id:s,weight:o,src:r}}function l(t){return e(t)?t:t.split(".")}function d(t){return e(t)?t.join("."):t}var u={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx{if(s(r))if(o[l]){const d=r[o[l]];if(!s(d))return;if(l===o.length-1&&(t(d)||n(d)||i(d)))c.push(function(e){return null==e?"":function(e){if("string"==typeof e)return e;let t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(e)}(d));else if(e(d)){h=!0;for(let e=0,t=d.length;e{this._keysMap[e.id]=t}))}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,t(this.docs[0])?this.docs.forEach(((e,t)=>{this._addString(e,t)})):this.docs.forEach(((e,t)=>{this._addObject(e,t)})),this.norm.clear())}add(e){const n=this.size();t(e)?this._addString(e,n):this._addObject(e,n)}removeAt(e){this.records.splice(e,1);for(let t=e,n=this.size();t{let h=this.getFn(n,i.path);if(s(h))if(e(h)){let n=[];const i=[{nestedArrIndex:-1,value:h}];for(;i.length;){const{nestedArrIndex:o,value:c}=i.pop();if(s(c))if(t(c)&&!r(c)){let e={v:c,i:o,n:this.norm.get(c)};n.push(e)}else e(c)&&c.forEach(((e,t)=>{i.push({nestedArrIndex:t,value:e})}))}o.$[c]=n}else if(!r(h)){let e={v:h,n:this.norm.get(h)};o.$[c]=e}})),this.records.push(o)}toJSON(){return{keys:this.keys,records:this.records}}}function p(e,t,{getFn:n=u.getFn,fieldNormWeight:i=u.fieldNormWeight}={}){const s=new g({getFn:n,fieldNormWeight:i});return s.setKeys(e.map(a)),s.setSources(t),s.create(),s}function m(e,{errors:t=0,currentLocation:n=0,expectedLocation:i=0,distance:s=u.distance,ignoreLocation:r=u.ignoreLocation}={}){const o=t/e.length;if(r)return o;const c=Math.abs(i-n);return s?o+c/s:c?1:o}function y(e,t,n,{location:i=u.location,distance:s=u.distance,threshold:r=u.threshold,findAllMatches:o=u.findAllMatches,minMatchCharLength:c=u.minMatchCharLength,includeMatches:h=u.includeMatches,ignoreLocation:a=u.ignoreLocation}={}){if(t.length>32)throw new Error(`Pattern length exceeds max of ${32}.`);const l=t.length,d=e.length,f=Math.max(0,Math.min(i,d));let g=r,p=f;const y=c>1||h,M=y?Array(d):[];let x;for(;(x=e.indexOf(t,p))>-1;){let e=m(t,{currentLocation:x,expectedLocation:f,distance:s,ignoreLocation:a});if(g=Math.min(e,g),p=x+l,y){let e=0;for(;e=h;r-=1){let o=r-1,c=n[e.charAt(o)];if(y&&(M[o]=+!!c),x[r]=(x[r+1]<<1|1)&c,i&&(x[r]|=(L[r+1]|L[r])<<1|1|L[r+1]),x[r]&v&&(_=m(t,{errors:i,currentLocation:o,expectedLocation:f,distance:s,ignoreLocation:a}),_<=g)){if(g=_,p=o,p<=f)break;h=Math.max(1,2*f-p)}}if(m(t,{errors:i+1,currentLocation:f,expectedLocation:f,distance:s,ignoreLocation:a})>g)break;L=x}const w={isMatch:p>=0,score:Math.max(.001,_)};if(y){const e=function(e=[],t=u.minMatchCharLength){let n=[],i=-1,s=-1,r=0;for(let o=e.length;r=t&&n.push([i,s]),i=-1)}return e[r-1]&&r-i>=t&&n.push([i,r-1]),n}(M,c);e.length?h&&(w.indices=e):w.isMatch=!1}return w}function M(e){let t={};for(let n=0,i=e.length;n{this.chunks.push({pattern:e,alphabet:M(e),startIndex:t})},l=this.pattern.length;if(l>32){let e=0;const t=l%32,n=l-t;for(;e{const{isMatch:g,score:p,indices:m}=y(e,t,u,{location:i+f,distance:s,threshold:r,findAllMatches:o,minMatchCharLength:c,includeMatches:n,ignoreLocation:h});g&&(d=!0),l+=p,g&&m&&(a=[...a,...m])}));let u={isMatch:d,score:d?l/this.chunks.length:1};return d&&n&&(u.indices=a),u}}const L=[];function _(e,t){for(let n=0,i=L.length;n{if(!s(e.indices)||!e.indices.length)return;const{indices:n,value:i}=e;let r={indices:n,value:i};e.key&&(r.key=e.key.src),e.idx>-1&&(r.refIndex=e.idx),t.matches.push(r)}))}function v(e,t){t.score=e.score}class w{constructor(e,t={},n){if(this.options={...u,...t},this.options.useExtendedSearch)throw new Error("Extended search is not available");this._keyStore=new h(this.options.keys),this.setCollection(e,n)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof g))throw new Error("Incorrect 'index' type");this._myIndex=t||p(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){s(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=(()=>!1)){const t=[];for(let n=0,i=this._docs.length;n{let n=1;e.matches.forEach((({key:e,norm:i,score:s})=>{const r=e?e.weight:null;n*=Math.pow(0===s&&r?Number.EPSILON:s,(r||1)*(t?1:i))})),e.score=n}))}(a,{ignoreFieldNorm:h}),o&&a.sort(c),n(i)&&i>-1&&(a=a.slice(0,i)),function(e,t,{includeMatches:n=u.includeMatches,includeScore:i=u.includeScore}={}){const s=[];return n&&s.push(k),i&&s.push(v),e.map((e=>{const{idx:n}=e,i={item:t[n],refIndex:n};return s.length&&s.forEach((t=>{t(e,i)})),i}))}(a,this._docs,{includeMatches:s,includeScore:r})}_searchStringList(e){const t=_(e,this.options),{records:n}=this._myIndex,i=[];return n.forEach((({v:e,i:n,n:r})=>{if(!s(e))return;const{isMatch:o,score:c,indices:h}=t.searchIn(e);o&&i.push({item:e,idx:n,matches:[{score:c,value:e,norm:r,indices:h}]})})),i}_searchLogical(e){throw new Error("Logical search is not available")}_searchObjectList(e){const t=_(e,this.options),{keys:n,records:i}=this._myIndex,r=[];return i.forEach((({$:e,i:i})=>{if(!s(e))return;let o=[];n.forEach(((n,i)=>{o.push(...this._findMatches({key:n,value:e[i],searcher:t}))})),o.length&&r.push({idx:i,item:e,matches:o})})),r}_findMatches({key:t,value:n,searcher:i}){if(!s(n))return[];let r=[];if(e(n))n.forEach((({v:e,i:n,n:o})=>{if(!s(e))return;const{isMatch:c,score:h,indices:a}=i.searchIn(e);c&&r.push({score:h,key:t,value:e,idx:n,norm:o,indices:a})}));else{const{v:e,n:s}=n,{isMatch:o,score:c,indices:h}=i.searchIn(e);o&&r.push({score:c,key:t,value:e,norm:s,indices:h})}return r}}w.version="6.5.3",w.createIndex=p,w.parseIndex=function(e,{getFn:t=u.getFn,fieldNormWeight:n=u.fieldNormWeight}={}){const{keys:i,records:s}=e,r=new g({getFn:t,fieldNormWeight:n});return r.setKeys(i),r.setIndexRecords(s),r},w.config=u;export{w as default};