export function single(t,e){if(!t||!e)return null;let l=b(t);if(U(e)||(e=y(e)),(l.t&e.l)!==l.t)return null;let i=l.i||2!==l.u.length?r(l,e):n(l,e);return i&&A(i)}export function go(l,f,u){if(f instanceof h)return((l,f,u)=>{if(u?.key||u?.keys)throw Error("fuzzysort: key/keys must be provided to snapshot(), not go()");if(f.o(),!l)return((t,e)=>{let l=[],i=t.h,n=t.p,r=t.k,f=void 0===r?i.length:n.length;l.total=f;let u=R(e);for(let t=0,e=Math.min(f,u);t{let o=l.h,s=l.p,h=C(f?.threshold??.5),c=R(f),a=f?.scoreFn,p=t.u.length,d=!t.i&&p<=3,y=!t.i&&2===p,b=l.M,g=l.A,k=l.I,m=0,w=0,v=0;for(let e=0;e=c?ut.C().S:-H;if(u&&x)g=i(t,p,l.D,f);else if(y&&x){let e=l.U[f],i=l.U[f+1];g=n(t,p,l.q,e,i,_)}else if(y)g=n(t,p,null,0,0,_);else if(x){let e=l.U[f],i=l.U[f+1];g=r(t,p,!1,!1,!1,!0,l.q,e,i,_)}else g=r(t,p,!1,!1,!1,!0,null,0,0,_);if(null===g)continue;if(k[m++]=f,g===st){v++;continue}let M=g.S;if(a){if(g=A(g,s?.[f]),M=a(g),!M)continue;g.S=M=C(M)}if(M=97&&s<=122)}else l=t(o,f.p,u,f);return f.F(o),f.O(o,l,u),l}catch(t){throw f.R(),t}})(l,f,u);let o=u?.key,s=!o&&u?.keys,c=f[0];if(!o&&!s&&"object"==typeof c&&null!==c&&!U(c))throw Error("fuzzysort: key or keys is required when searching object targets");if(!l)return((t,e)=>{let l=[];l.total=t.length;let i=R(e),n=e?.key,r=!n&&e?.keys;if(r){let e=r.map(q);for(let n of t){for(let t=r.length-1;t>=0;t--){let l=null===e[t]?n[r[t]]:e[t](n);l?(U(l)||(l=y(l)),l.S=-H,l.H.len=0,lt[t]=l):lt[t]=ot}if(l.push(S(lt,r.length,n,-H)),l.length>=i)break}return l}let f=n&&q(n);for(let e of t){let t=n?null===f?e[n]:f(e):e;if(null!=t&&(U(t)||(t=y(t)),n?t=M(t.target,-H,e):(t.S=-H,t.H.len=0),l.push(t),l.length>=i))break}return l})(f,u);let a=b(l);if(s)return t(a,f,u);let p=a.t,d=!a.i&&2===a.u.length,g=C(u?.threshold??.5),k=R(u),m=u?.scoreFn,w=0,v=0,x=o&&q(o);for(let t=0;tt-e);if(!u.length)return n?[r]:r;let o=n?[]:"",s=0,h=0;for(let t=0;t=97&&z<=122,T=h?.scoreFn,j=a&&!T&&(x!==H||v>-H),F=a?c.M:null,O=a?c.A:s.length,E=a?c.I:null,K=0,L=0,N=0;t:for(let e=0;e=0;e--){let t=ut.N();l&&(t=l(t)),t instanceof _&&!t.B&&I(t),i[e]=t}return i.total=t+e,i}function l(t){for(let e=0;e24&&(u*=10*(e.P-24)):u*=1e3,e.S=u-e.V.length+1,e.H[0]=n,e.H.len=1,e}function n(t,e,l=null,i=0,n=0,r=-H){let f=e.V,u=f.length,o=t.u[0],s=t.u[1],h=0;for(;f[h]!==o;)if(++h>=u)return null;let c=h+1;for(;f[c]!==s;)if(++c>=u)return null;if(r!==-H&&T(2,u)<=r)return st;null===l&&(null===(l=e.q)&&(e.q=l=(t=>{let e=[];return g(t,t=>e.push(t)),e})(e)),n=l.length);let a=e.G.indexOf(t.J,h),p=-1!==a,d=F(l,i,n,a),y=p&&d200)break;t++}}if(p&&!y){for(;d24&&(k*=10*(n-i-24)):k*=1e3;let m=(u-2)/2;k-=m,p&&(k/=5),y&&(k/=5),k-=m;let w=p&&c===h+1&&(c+1===u||E(l,i,n,c+1));return e.S=w?k+Math.min(4,-k/2):k,e.H[0]=h,e.H[1]=c,e.H.len=2,e}function r(t,e,l=!1,i=!1,n=!1,f=!0,o=null,h=0,c=0,a=-H){if(!l&&t.i)return((t,e,l)=>{let i=0,n=++nt,f=0,o=null,h=0,c=t.L,a=0,p=!1;for(let t=0;t=0&&e.W[t]===i;t--)e.W[t]=l,V[2*a]=t,V[2*a+1]=i,a++}}if(l){let e=Y[t];e.length=o.H.len;for(let t=0;tf){if(l){let e=0;for(let l=0;l=9&&i<=13;)r++;let f=c[e].J;if(!t.startsWith(f,r))continue;for(let t=n;t=D&&u(o.H,Y[t])}else{for(let t=0;t=b)return null}if(a!==-H&&y>1&&T(y,b)<=a)return st;if(1===y&&!n&&f){let t,l;if(e.X===k)t=e.Y,l=e.Z;else if(null!==e.W){let i=e.W;for(w=0===G[0]?0:i[G[0]-1];w{let l=G[0],i=!1;g(t,n=>{i||e!==t.V[n]||(l=n,i=!0)}),t.X=e,t.Y=l,t.Z=i})(e,k),t=e.Y,l=e.Z;let i=0===t?0:-t*t*.2;return l?e.P>24&&(i*=10*(e.P-24)):i*=1e3,e.S=i-(b-1),e.H[0]=t,e.H.len=1,e}m=0;let v=!1,x=0,_=e.W;null===o&&null===_&&(_=e.W=(t=>{let e=[],l=0;for(g(t,t=>{for(;l=b){if(m<=0||++t>200)break;m--;let e=J[--x];w=o?O(o,h,c,e,b):_[e]}else if(p[m]===d[w]){if(J[x++]=w,++m===y){v=!0;break}w++}else w=o?O(o,h,c,w,b):_[w]}if(S&&!z)if(o)for(let t=h;t{let o=0,s=0;for(let l=1;l24&&(o*=10*(n-24)):o*=1e3;let h=(l-e)/2;o-=h;let c=1+e*e;return r&&(o/=c),f&&(o/=c),o-=h,u?o+Math.min(4,-o/2):o})(A,y,b,v,M,S,z,U);for(let t=0;t-1e3&&l>-H&&(l=Math.max(l,(l+t)/4)),X[e]=Math.max(l,t)}}function u(t,e){let l=t.len;t:for(let i=0;i-1e3&&l>-H&&(l=Math.max(l,(l+e)/4)),e>l&&(l=e)}return l}function s(t,e){for(let l=e-1;l>=0;l--)t.W[V[2*l]]=V[2*l+1]}class h{constructor(t,e){this._=e?.keys?2:e?.key?1:0,this.$=2===this._?e.keys.slice():[e?.key],this.tt=t.slice(),this.et=0,this.lt=!1,this.it=null,this.nt=null,0===t.length?this.o():this.rt()}rt(){null===this.nt&&(this.nt=(t=>{let e;return"function"==typeof requestIdleCallback?(e=requestIdleCallback(t,{timeout:100}),()=>"function"==typeof cancelIdleCallback&&cancelIdleCallback(e)):"function"==typeof setImmediate?(e=setImmediate(t),()=>"function"==typeof clearImmediate&&clearImmediate(e)):(e=setTimeout(t),()=>clearTimeout(e))})(t=>{this.nt=null,this.ft(t)}))}ut(){null!==this.nt&&this.nt(),this.nt=null}ot(){if(this.h)return;let t=2===this._?this.$.length:1,e=this.tt.length*t,l=this.tt.length;this.h=Array(e),this.D=new Uint16Array(26*e),this.U=new Uint32Array(e+1),this.st=[],this.ht=l,this.ct=l+31>>5,this.dt=new Uint32Array(32*this.ct),this.I=new Uint32Array(l),this.yt=0,this.j=0,this.bt=null,this.M=null,this.A=l,this.gt=[],this._&&(this.p=this.tt,this.kt=this.$.map(q)),2===this._&&(this.k=t,this.l=new Int32Array(l))}ft(t){if(this.lt||this.it)return;let e=Date.now()+4,l=()=>t&&!t.didTimeout?t.timeRemaining()>1:Date.now()>>0,i=t>>5,n=1<<(31&t),r=this.ct,f=this.dt;for(;l;)f[(31-Math.clz32(l&-l))*r+i]|=n,l=(l&l-1)>>>0}wt(){let t=this.et++,e=this._,l=this.tt[t],i=2===e?this.k:1,n=0;for(let r=0;r>>0}else if(f+=j(r),f>=l)return f}return e&&(this.M=this.I,this.A=f),f}v(t){this.j=0;let e=this.bt,l=this.yt;this.bt=null;let i=t.t>>>0;if(null!==e&&t.J.startsWith(e)&&l<=this.Mt(i,!1,l))return this.M=this.I,void(this.A=l);this.Mt(i,!0)}F(t){this.yt=this.j,this.j=0,this.bt=t.J||null,this.M=null,this.A=0}m(t,e){let l=this.gt;if(l.length<2||e?.scoreFn||void 0!==e?.threshold)return null;let i=R(e);if(i===H)return null;let n=l[l.length-1],r=t.J;if(n.query===r&&n.limit===i&&n.results)return a(n.results);if(r.length>=n.query.length||!n.query.startsWith(r))return null;let f=l.length-2;for(;f>=0&&l[f].query.length>r.length;)f--;let u=l[f];return u&&u.query===r&&u.limit===i?(l.length=f+1,u.results?(this.R(),a(u.results)):null):null}O(t,e,l){let i=this.gt,n=R(l);if(l?.scoreFn||void 0!==l?.threshold||n===H||e.length>256)return void(i.length=0);let r=t.J,f=i[i.length-1];f&&!r.startsWith(f.query)?i.length=0:f?.query===r&&f.limit===n&&i.pop(),i.push({query:r,limit:n,results:r.length<=32?a(e):null})}R(){this.bt=null,this.yt=this.j=this.A=0,this.M=null}o(){if(this.it)throw this.it;if(!this.lt){this.ut();try{for(this.ot();this.et999)return p(t);let e=N.get(t);return void 0===e&&N.set(t,e=p(t)),e}function b(t){if(t.length>999)return d(t);let e=B.get(t);return void 0===e&&(B.size>=512&&B.clear(),B.set(t,e=d(t))),e}function g(t,e){let l=w(t.target),i=!1,n=!1,r=0;for(let t=0;t=65&&f<=90,o=u||f>=97&&f<=122||f>=48&&f<=57,s=u&&!i||!n||!o;i=u,n=o,s&&(r++,e(t))}t.P=r}function k(t,e,l,i){if(t.target.length>=65535)return;let n=w(t.target),r=t.V,f=26*l,u=!1,o=!1,s=0;for(let t=0;t=65&&l<=90,c=h||l>=97&&l<=122||l>=48&&l<=57,a=h&&!u||!o||!c;if(u=h,o=c,a&&(s++,i.push(t),l=r[t],l>=97&&l<=122)){let i=f+l-97;0===e[i]&&(e[i]=t+1)}}t.P=s}function m(t){let e=rt[t];return void 0!==e?e:t.charCodeAt(0)<128?t:(e=t.normalize("NFKD").replace(/[\u0300-\u036f]/g,""),1===e.length?e:t)}function w(t){return ft?t.replace(/[\s\S]/g,m):/[^\x00-\x7F]|[\\"`]/.test(t)?t.replace(/[^\x00-\x7F]|[\\"`]/g,m):t}function v(t){let e=t.toLowerCase(),l=[],i=0,n=!1;for(let t=0;t=97&&r<=122?r-97:r>=48&&r<=57?26:r<=127?30:31):(n=!0,i|=K)}return{u:l,t:i,i:n,J:e}}class x{get indexes(){return this.H.slice(0,this.H.len).sort((t,e)=>t-e)}set indexes(t){this.H=t}highlight(t,e,l){return highlight(this,t,e,l)}get score(){return z(this.S)}}class _ extends Array{get score(){return z(this.S)}}function M(t,e=-H,l=null,i="",n=null,r=0){let f=new x;return f.target=t,f.obj=l,f.S=e,f.H=[],f.G=i,f.V=n,f.W=null,f.q=null,f.P=0,f.X=f.Y=-1,f.Z=!1,f.l=r,f}function A(t,e=null){let l=new x;return l.target=t.target,l.obj=e,l.S=t.S,l.H=t.H,l}function I(t){let e=-H;for(let l=0;le&&(e=t[l].S);for(let l=0;lt===-H?0:t>1?t:Math.E**(-2*((1-t)**.04307-1)),C=t=>0===t?-H:t>1?t:1-Math.pow(Math.log(t)/-2+1,1/.04307),D=C(.5),U=t=>"object"==typeof t&&"number"==typeof t?.l;function q(t){if("function"==typeof t)return t;let e=Array.isArray(t)?t:"string"==typeof t&&t.includes(".")?t.split("."):null;return null===e?null:l=>{if(e!==t){let e=l[t];if(void 0!==e)return e}for(let t=0;l&&t>>1&1431655765))+(t>>>2&858993459))+(t>>>4)&252645135)>>>24}function F(t,e,l,i){for(;e>1;t[n]{let t=[],e=0;function l(){let l=0,i=t[0];for(let i=1;i>1]=t[l]}for(let e=l-1>>1;l>0&&i.S>1)t[l]=t[e];t[l]=i}return{add(l){let i=e++;for(let e=i-1>>1;i>0&&l.S>1)t[i]=t[e];t[i]=l},N(){if(!e)return;let i=t[0],n=t[--e];return t[e]=void 0,e&&(t[0]=n,l()),i},C:()=>e?t[0]:void 0,T(e){t[0]=e,l()},clear(){t.length=e=0}}})(),ot=p(""),st={};export default{single,go,highlight,score,remap,prepare,snapshot,cleanup};