9 lines
12 KiB
JavaScript
Raw Permalink Normal View History

2025-09-05 14:59:21 +08:00
/**
* Fuse.js v7.1.0 - Lightweight fuzzy-search (http://fusejs.io)
*
* Copyright (c) 2025 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]"===c(t)}const e=1/0;function u(t){return null==t?"":function(t){if("string"==typeof t)return t;let u=t+"";return"0"==u&&1/t==-e?"-0":u}(t)}function n(t){return"string"==typeof t}function i(t){return"number"==typeof t}function s(t){return!0===t||!1===t||function(t){return function(t){return"object"==typeof t}(t)&&null!==t}(t)&&"[object Boolean]"==c(t)}function r(t){return null!=t}function o(t){return!t.trim().length}function c(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const h=t=>`Missing ${t} property in key`,a=t=>`Property 'weight' in key '${t}' must be a positive integer`,l=Object.prototype.hasOwnProperty;class d{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach((t=>{let u=A(t);this._keys.push(u),this._keyMap[u.id]=u,e+=u.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 A(e){let u=null,i=null,s=null,r=1,o=null;if(n(e)||t(e))s=e,u=f(e),i=g(e);else{if(!l.call(e,"name"))throw new Error(h("name"));const t=e.name;if(s=t,l.call(e,"weight")&&(r=e.weight,r<=0))throw new Error(a(t));u=f(t),i=g(t),o=e.getFn}return{path:u,id:i,weight:r,src:s,getFn:o}}function f(e){return t(e)?e:e.split(".")}function g(e){return t(e)?e.join("."):e}var C={isCaseSensitive:!1,ignoreDiacritics:!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(e,o){let c=[],h=!1;const a=(e,o,l)=>{if(r(e))if(o[l]){const d=e[o[l]];if(!r(d))return;if(l===o.length-1&&(n(d)||i(d)||s(d)))c.push(u(d));else if(t(d)){h=!0;for(let t=0,e=d.length;t<e;t+=1)a(d[t],o,l+1)}else o.length&&a(d,o,l+1)}else c.push(e)};return a(e,n(o)?o.split("."):o,0),h?c:c[0]},ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const F=/[^ ]+/g;class p{constructor({getFn:t=C.getFn,fieldNormWeight:e=C.fieldNormWeight}={}){this.norm=function(t=1,e=3){const u=new Map,n=Math.pow(10,e);return{get(e){const i=e.match(F).length;if(u.has(i))return u.get(i);const s=1/Math.pow(i,.5*t),r=parseFloat(Math.round(s*n)/n);return u.set(i,r),r},clear(){u.clear()}}}(e,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,n(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();n(t)?this._addString(t,e):this._addObject(t,e)}removeAt(t){this.records.splice(t,1);for(let e=t,u=this.size();e<u;e+=1)this.records[e].i-=1}getValueForItemAtKeyId(t,e){return t[this._keysMap[e]]}size(){return this.records.length}_addString(t,e){if(!r(t)||o(t))return;let u={v:t,i:e,n:this.norm.get(t)};this.records.push(u)}_addObject(e,u){let i={i:u,$:{}};this.keys.forEach(((u,s)=>{let c=u.getFn?u.getFn(e):this.getFn(e,u.path);if(r(c))if(t(c)){let e=[];const u=[{nestedArrIndex:-1,value:c}];for(;u.length;){const{nestedArrIndex:i,value:s}=u.pop();if(r(s))if(n(s)&&!o(s)){let t={v:s,i:i,n:this.norm.get(s)};e.push(t)}else t(s)&&s.forEach(((t,e)=>{u.push({nestedArrIndex:e,value:t})}))}i.$[s]=e}else if(n(c)&&!o(c)){let t={v:c,n:this.norm.get(c)};i.$[s]=t}})),this.records.push(i)}toJSON(){return{keys:this.keys,records:this.records}}}function E(t,e,{getFn:u=C.getFn,fieldNormWeight:n=C.fieldNormWeight}={}){const i=new p({getFn:u,fieldNormWeight:n});return i.setKeys(t.map(A)),i.setSources(e),i.create(),i}function B(t,{errors:e=0,currentLocation:u=0,expectedLocation:n=0,distance:i=C.distance,ignoreLocation:s=C.ignoreLocation}={}){const r=e/t.length;if(s)return r;const o=Math.abs(n-u);return i?r+o/i:o?1:r}const D=32;function m(t,e,u,{location:n=C.location,distance:i=C.distance,threshold:s=C.threshold,findAl