Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fuse.basic.min.mjs « dist « fuse.js@7.0.0 « libs « static - gitlab.com/rmaguiar/hugo-theme-color-your-world.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 07e34d5eab65134a470029aa70bce1cc7455aba5 (plain)
1
2
3
4
5
6
7
8
9
/**
 * Fuse.js v7.0.0 - Lightweight fuzzy-search (http://fusejs.io)
 *
 * Copyright (c) 2023 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 i(t){return"string"==typeof t}function s(t){return"number"==typeof t}function r(t){return!0===t||!1===t||function(t){return function(t){return"object"==typeof t}(t)&&null!==t}(t)&&"[object Boolean]"==h(t)}function o(t){return null!=t}function c(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 u{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,s=null,r=null,o=1,c=null;if(i(e)||t(e))r=e,n=g(e),s=p(e);else{if(!d.call(e,"name"))throw new Error(a("name"));const t=e.name;if(r=t,d.call(e,"weight")&&(o=e.weight,o<=0))throw new Error(l(t));n=g(t),s=p(t),c=e.getFn}return{path:n,id:s,weight:o,src:r,getFn:c}}function g(e){return t(e)?e:e.split(".")}function p(e){return t(e)?e.join("."):e}var m={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(e,c){let h=[],a=!1;const l=(e,c,d)=>{if(o(e))if(c[d]){const u=e[c[d]];if(!o(u))return;if(d===c.length-1&&(i(u)||s(u)||r(u)))h.push(n(u));else if(t(u)){a=!0;for(let t=0,e=u.length;t<e;t+=1)l(u[t],c,d+1)}else c.length&&l(u,c,d+1)}else h.push(e)};return l(e,i(c)?c.split("."):c,0),a?h:h[0]},ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const y=/[^ ]+/g;class M{constructor({getFn:t=m.getFn,fieldNormWeight:e=m.fieldNormWeight}={}){this.norm=function(t=1,e=3){const n=new Map,i=Math.pow(10,e);return{get(e){const s=e.match(y).length;if(n.has(s))return n.get(s);const r=1/Math.pow(s,.5*t),o=parseFloat(Math.round(r*i)/i);return n.set(s,o),o},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,i(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();i(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(!o(t)||c(t))return;let n={v:t,i:e,n:this.norm.get(t)};this.records.push(n)}_addObject(e,n){let s={i:n,$:{}};this.keys.forEach(((n,r)=>{let h=n.getFn?n.getFn(e):this.getFn(e,n.path);if(o(h))if(t(h)){let e=[];const n=[{nestedArrIndex:-1,value:h}];for(;n.length;){const{nestedArrIndex:s,value:r}=n.pop();if(o(r))if(i(r)&&!c(r)){let t={v:r,i:s,n:this.norm.get(r)};e.push(t)}else t(r)&&r.forEach(((t,e)=>{n.push({nestedArrIndex:e,value:t})}))}s.$[r]=e}else if(i(h)&&!c(h)){let t={v:h,n:this.norm.get(h)};s.$[r]=t}})),this.records.push(s)}toJSON(){return{keys:this.keys,records:this.records}}}function x(t,e,{getFn:n=m.getFn,fieldNormWeight:i=m.fieldNormWeight}={}){const s=new M({getFn:n,fieldNormWeight:i});return s.setKeys(t.map(f)),s.setSources(e),s.create(),s}function L(t,{errors:e=0,currentLocation:n=0,expectedLocation:i=0,distance:s=m.distance,ignoreLocation:r=m.ignoreLocation}={}){const o=e/t.length;if(r)return o;const c=Math.abs(i-n);return s?o+c/s:c?1:o}const _=32;function k(t,e,n,{location:i=m.location,distance:s=m.distance,threshold:r=m.threshold,findAllMatches:o=m.findAllMatches,minMatchCharLength:c=m.minMatchCharLength,includeMatches:h=m.includeMatches,ignoreLocation:a=m.ignoreLocation}={}){if(e.length>_)throw new Error(`Pattern length exceeds max of ${_}.`);const l=e.length,d=t.length,u=Math.max(0,Math.min(i,d));let f=r,g=u;const p=c>1||h,y=p?Array(d):[];let M;for(;(M=t.indexOf(e,g))>-1;){let t=L(e,{currentLocation:M,expectedLocation:u,distance:s,ignoreLocation:a});if(f=Math.min(t,f),g=M+l,p){let t=0;for(;t<l;)y[M+t]=1,t+=1}}g=-1;let x=[],k=1,v=l+d;const w=1<<l-1;for(let i=0;i<l;i+=1){let r=0,c=v;for(;r<c;){L(e,{errors:i,currentLocation:u+c,expectedLocation:u,distance:s,ignoreLocation:a})<=f?r=c:v=c,c=Math.floor((v-r)/2+r)}v=c;let h=Math.max(1,u-c+1),m=o?d:Math.min(u+c,d)+l,M=Array(m+2);M[m+1]=(1<<i)-1;for(let r=m;r>=h;r-=1){let o=r-1,c=n[t.charAt(o)];if(p&&(y[o]=+!!c),M[r]=(M[r+1]<<1|1)&c,i&&(M[r]|=(x[r+1]|x[r])<<1|1|x[r+1]),M[r]&w&&(k=L(e,{errors:i,currentLocation:o,expectedLocation:u,distance:s,ignoreLocation:a}),k<=f)){if(f=k,g=o,g<=u)break;h=Math.max(1,2*u-g)}}if(L(e,{errors:i+1,currentLocation:u,expectedLocation:u,distance:s,ignoreLocation:a})>f)break;x=M}const I={isMatch:g>=0,score:Math.max(.001,k)};if(p){const t=function(t=[],e=m.minMatchCharLength){let n=[],i=-1,s=-1,r=0;for(let o=t.length;r<o;r+=1){let o=t[r];o&&-1===i?i=r:o||-1===i||(s=r-1,s-i+1>=e&&n.push([i,s]),i=-1)}return t[r-1]&&r-i>=e&&n.push([i,r-1]),n}(y,c);t.length?h&&(I.indices=t):I.isMatch=!1}return I}function v(t){let e={};for(let n=0,i=t.length;n<i;n+=1){const s=t.charAt(n);e[s]=(e[s]||0)|1<<i-n-1}return e}class w{constructor(t,{location:e=m.location,threshold:n=m.threshold,distance:i=m.distance,includeMatches:s=m.includeMatches,findAllMatches:r=m.findAllMatches,minMatchCharLength:o=m.minMatchCharLength,isCaseSensitive:c=m.isCaseSensitive,ignoreLocation:h=m.ignoreLocation}={}){if(this.options={location:e,threshold:n,distance:i,includeMatches:s,findAllMatches:r,minMatchCharLength:o,isCaseSensitive:c,ignoreLocation:h},this.pattern=c?t:t.toLowerCase(),this.chunks=[],!this.pattern.length)return;const a=(t,e)=>{this.chunks.push({pattern:t,alphabet:v(t),startIndex:e})},l=this.pattern.length;if(l>_){let t=0;const e=l%_,n=l-e;for(;t<n;)a(this.pattern.substr(t,_),t),t+=_;if(e){const t=l-_;a(this.pattern.substr(t),t)}}else a(this.pattern,0)}searchIn(t){const{isCaseSensitive:e,includeMatches:n}=this.options;if(e||(t=t.toLowerCase()),this.pattern===t){let e={isMatch:!0,score:0};return n&&(e.indices=[[0,t.length-1]]),e}const{location:i,distance:s,threshold:r,findAllMatches:o,minMatchCharLength:c,ignoreLocation:h}=this.options;let a=[],l=0,d=!1;this.chunks.forEach((({pattern:e,alphabet:u,startIndex:f})=>{const{isMatch:g,score:p,indices:m}=k(t,e,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 I=[];function S(t,e){for(let n=0,i=I.length;n<i;n+=1){let i=I[n];if(i.condition(t,e))return new i(t,e)}return new w(t,e)}function E(t,e){const n=t.matches;e.matches=[],o(n)&&n.forEach((t=>{if(!o(t.indices)||!t.indices.length)return;const{indices:n,value:i}=t;let s={indices:n,value:i};t.key&&(s.key=t.key.src),t.idx>-1&&(s.refIndex=t.idx),e.matches.push(s)}))}function F(t,e){e.score=t.score}class A{constructor(t,e={},n){if(this.options={...m,...e},this.options.useExtendedSearch)throw new Error("Extended search is not available");this._keyStore=new u(this.options.keys),this.setCollection(t,n)}setCollection(t,e){if(this._docs=t,e&&!(e instanceof M))throw new Error("Incorrect 'index' type");this._myIndex=e||x(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(t){o(t)&&(this._docs.push(t),this._myIndex.add(t))}remove(t=(()=>!1)){const e=[];for(let n=0,i=this._docs.length;n<i;n+=1){const s=this._docs[n];t(s,n)&&(this.removeAt(n),n-=1,i-=1,e.push(s))}return e}removeAt(t){this._docs.splice(t,1),this._myIndex.removeAt(t)}getIndex(){return this._myIndex}search(t,{limit:e=-1}={}){const{includeMatches:n,includeScore:r,shouldSort:o,sortFn:c,ignoreFieldNorm:h}=this.options;let a=i(t)?i(this._docs[0])?this._searchStringList(t):this._searchObjectList(t):this._searchLogical(t);return function(t,{ignoreFieldNorm:e=m.ignoreFieldNorm}){t.forEach((t=>{let n=1;t.matches.forEach((({key:t,norm:i,score:s})=>{const r=t?t.weight:null;n*=Math.pow(0===s&&r?Number.EPSILON:s,(r||1)*(e?1:i))})),t.score=n}))}(a,{ignoreFieldNorm:h}),o&&a.sort(c),s(e)&&e>-1&&(a=a.slice(0,e)),function(t,e,{includeMatches:n=m.includeMatches,includeScore:i=m.includeScore}={}){const s=[];return n&&s.push(E),i&&s.push(F),t.map((t=>{const{idx:n}=t,i={item:e[n],refIndex:n};return s.length&&s.forEach((e=>{e(t,i)})),i}))}(a,this._docs,{includeMatches:n,includeScore:r})}_searchStringList(t){const e=S(t,this.options),{records:n}=this._myIndex,i=[];return n.forEach((({v:t,i:n,n:s})=>{if(!o(t))return;const{isMatch:r,score:c,indices:h}=e.searchIn(t);r&&i.push({item:t,idx:n,matches:[{score:c,value:t,norm:s,indices:h}]})})),i}_searchLogical(t){throw new Error("Logical search is not available")}_searchObjectList(t){const e=S(t,this.options),{keys:n,records:i}=this._myIndex,s=[];return i.forEach((({$:t,i:i})=>{if(!o(t))return;let r=[];n.forEach(((n,i)=>{r.push(...this._findMatches({key:n,value:t[i],searcher:e}))})),r.length&&s.push({idx:i,item:t,matches:r})})),s}_findMatches({key:e,value:n,searcher:i}){if(!o(n))return[];let s=[];if(t(n))n.forEach((({v:t,i:n,n:r})=>{if(!o(t))return;const{isMatch:c,score:h,indices:a}=i.searchIn(t);c&&s.push({score:h,key:e,value:t,idx:n,norm:r,indices:a})}));else{const{v:t,n:r}=n,{isMatch:o,score:c,indices:h}=i.searchIn(t);o&&s.push({score:c,key:e,value:t,norm:r,indices:h})}return s}}A.version="7.0.0",A.createIndex=x,A.parseIndex=function(t,{getFn:e=m.getFn,fieldNormWeight:n=m.fieldNormWeight}={}){const{keys:i,records:s}=t,r=new M({getFn:e,fieldNormWeight:n});return r.setKeys(i),r.setIndexRecords(s),r},A.config=m;export{A as default};