9 lines
18 KiB
JavaScript
Raw 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]"===h(t)}const e=1/0;function n(t){return null==t?"":function(t){if("string"==typeof t)return t;let n=t+"";return"0"==n&&1/t==-e?"-0":n}(t)}function s(t){return"string"==typeof t}function i(t){return"number"==typeof t}function r(t){return!0===t||!1===t||function(t){return u(t)&&null!==t}(t)&&"[object Boolean]"==h(t)}function u(t){return"object"==typeof t}function c(t){return null!=t}function o(t){return!t.trim().length}function h(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const a=t=>`Missing ${t} property in key`,l=t=>`Property 'weight' in key '${t}' must be a positive integer`,d=Object.prototype.hasOwnProperty;class g{constructor(t){this._keys=[],this._keyMap={};let e=0;t.forEach((t=>{let n=f(t);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 f(e){let n=null,i=null,r=null,u=1,c=null;if(s(e)||t(e))r=e,n=A(e),i=p(e);else{if(!d.call(e,"name"))throw new Error(a("name"));const t=e.name;if(r=t,d.call(e,"weight")&&(u=e.weight,u<=0))throw new Error(l(t));n=A(t),i=p(t),c=e.getFn}return{path:n,id:i,weight:u,src:r,getFn:c}}function A(e){return t(e)?e:e.split(".")}function p(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,u){let o=[],h=!1;const a=(e,u,l)=>{if(c(e))if(u[l]){const d=e[u[l]];if(!c(d))return;if(l===u.length-1&&(s(d)||i(d)||r(d)))o.push(n(d));else if(t(d)){h=!0;for(let t=0,e=d.length;t<e;t+=1)a(d[t],u,l+1)}else u.length&&a(d,u,l+1)}else o.push(e)};return a(e,s(u)?u.split("."):u,0),h?o:o[0]},ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const m=/[^ ]+/g;class F{constructor({getFn:t=C.getFn,fieldNormWeight:e=C.fieldNormWeight}={}){this.norm=function(t=1,e=3){const n=new Map,s=Math.pow(10,e);return{get(e){const i=e.match(m).length;if(n.has(i))return n.get(i);const r=1/Math.pow(i,.5*t),u=parseFloat(Math.round(r*s)/s);return n.set(i,u),u},clear(){n.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,s(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();s(t)?this._addString(t,e):this._addObject(t,e)}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(!c(t)||o(t))return;let n={v:t,i:e,n:this.norm.get(t)};this.records.push(n)}_addObject(e,n){let i={i:n,$:{}};this.keys.forEach(((n,r)=>{let u=n.getFn?n.getFn(e):this.getFn(e,n.path);if(c(u))if(t(u)){let e=[];const n=[{nestedArrIndex:-1,value:u}];for(;n.length;){const{nestedArrIndex:i,value:r}=n.pop();if(c(r))if(s(r)&&!o(r)){let t={v:r,i:i,n:this.norm.get(r)};e.push(t)}else t(r)&&r.forEach(((t,e)=>{n.push({nestedArrIndex:e,value:t})}))}i.$[r]=e}else if(s(u)&&!o(u)){let t={v:u,n:this.norm.get(u)};i.$[r]=t}})),this.records.push(i)}toJSON(){return{keys:this.keys,records:this.records}}}function M(t,e,{getFn:n=C.getFn,fieldNormWeight:s=C.fieldNormWeight}={}){const i=new F({getFn:n,fieldNormWeight:s});return i.setKeys(t.map(f)),i.setSources(e),i.create(),i}function E(t,{errors:e=0,currentLocation:n=0,expectedLocation:s=0,distance:i=C.distance,ignoreLocation:r=C.ignoreLocation}={}){const u=e/t.length;if(r)return u;const c=Math.abs(s-n);return i?u+c/i:c?1:u}const D=32;function B(t,e,n,{location:s=C.location,distance:i=C.distance,threshold:r=C.threshold,fin