9 lines
15 KiB
JavaScript
9 lines
15 KiB
JavaScript
|
|
/**
|
||
|
|
* Fuse.js v6.4.3 - Lightweight fuzzy-search (http://fusejs.io)
|
||
|
|
*
|
||
|
|
* Copyright (c) 2020 Kiro Risk (http://kiro.me)
|
||
|
|
* All Rights Reserved. Apache Software License 2.0
|
||
|
|
*
|
||
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
*/
|
||
|
|
function t(t){return Array.isArray?Array.isArray(t):"[object Array]"===o(t)}function e(t){return"string"==typeof t}function n(t){return"number"==typeof t}function s(t){return!0===t||!1===t||function(t){return r(t)&&null!==t}(t)&&"[object Boolean]"==o(t)}function r(t){return"object"==typeof t}function i(t){return null!=t}function c(t){return!t.trim().length}function o(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const h=Object.prototype.hasOwnProperty;class a{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach(t=>{let n=l(t);e+=n.weight,this._keys.push(n),this._keyMap[n.id]=n,e+=n.weight}),this._keys.forEach(t=>{t.weight/=e})}get(t){return this._keyMap[t]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function l(n){let s=null,r=null,i=null,c=1;if(e(n)||t(n))i=n,s=u(n),r=d(n);else{if(!h.call(n,"name"))throw new Error((t=>`Missing ${t} property in key`)("name"));const t=n.name;if(i=t,h.call(n,"weight")&&(c=n.weight,c<=0))throw new Error((t=>`Property 'weight' in key '${t}' must be a positive integer`)(t));s=u(t),r=d(t)}return{path:s,id:r,weight:c,src:i}}function u(e){return t(e)?e:e.split(".")}function d(e){return t(e)?e.join("."):e}var g={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(t,e)=>t.score===e.score?t.idx<e.idx?-1:1:t.score<e.score?-1:1,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,...{useExtendedSearch:!1,getFn:function(r,c){let o=[],h=!1;const a=(r,c,l)=>{if(i(r))if(c[l]){const u=r[c[l]];if(!i(u))return;if(l===c.length-1&&(e(u)||n(u)||s(u)))o.push(function(t){return null==t?"":function(t){if("string"==typeof t)return t;let e=t+"";return"0"==e&&1/t==-1/0?"-0":e}(t)}(u));else if(t(u)){h=!0;for(let t=0,e=u.length;t<e;t+=1)a(u[t],c,l+1)}else c.length&&a(u,c,l+1)}else o.push(r)};return a(r,e(c)?c.split("."):c,0),h?o:o[0]},ignoreLocation:!1,ignoreFieldNorm:!1}};const f=/[^ ]+/g;class p{constructor({getFn:t=g.getFn}={}){this.norm=function(t=3){const e=new Map;return{get(n){const s=n.match(f).length;if(e.has(s))return e.get(s);const r=parseFloat((1/Math.sqrt(s)).toFixed(t));return e.set(s,r),r},clear(){e.clear()}}}(3),this.getFn=t,this.isCreated=!1,this.setIndexRecords()}setSources(t=[]){this.docs=t}setIndexRecords(t=[]){this.records=t}setKeys(t=[]){this.keys=t,this._keysMap={},t.forEach((t,e)=>{this._keysMap[t.id]=e})}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,e(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 n=this.size();e(t)?this._addString(t,n):this._addObject(t,n)}removeAt(t){this.records.splice(t,1);for(let e=t,n=this.size();e<n;e+=1)this.records[e].i-=1}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_addString(t,e){if(!i(t)||c(t))return;let n={v:t,i:e,n:this.norm.get(t)};this.records.push(n)}_addObject(n,s){let r={i:s,$:{}};this.keys.forEach((s,o)=>{let h=this.getFn(n,s.path);if(i(h))if(t(h)){let n=[];const s=[{nestedArrIndex:-1,value:h}];for(;s.length;){const{nestedArrIndex:r,value:o}=s.pop();if(i(o))if(e(o)&&!c(o)){let t={v:o,i:r,n:this.norm.get(o)};n.push(t)}else t(o)&&o.forEach((t,e)=>{s.push({nestedArrIndex:e,value:t})})}r.$[o]=n}else if(!c(h)){let t={v:h,n:this.norm.get(h)};r.$[o]=t}}),this.records.push(r)}toJSON(){return{keys:this.keys,records:this.records}}}function M(t,e,{getFn:n=g.getFn}={}){const s=new p({getFn:n});return s.setKeys(t.map(l)),s.setSources(e),s.create(),s}function m(t,e){const n=t.matches;e.matches=[],i(n)&&n.forEach(t=>{if(!i(t.indices)||!t.indices.length)return;const{indices:n,value:s}=t;let r={indices:n,value:s};t.key&&(r.key=t.key.src),t.idx>-1&&(r.refIndex=t.idx),e.matches.push(r)})}function x(t,e){e.score=t.score}function y(t,{errors:e=0,currentLocation:n=0,expectedLocation:s=0,distance:r=g.distance,ignoreLocation:i=g.ignoreLocation}={}){const c=e/t.length;if(i)return c;const o=Math.abs(s-n);return r?c+o/r:o?1:c}function L(t,e,n,{location:s=g.location,distance:r=g.distance,
|