pastel.codes/obsidian/lib/scripts/minisearch.js

1 line
29 KiB
JavaScript
Raw Permalink Normal View History

2024-04-29 14:52:09 +01:00
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).MiniSearch=e()}(this,(function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},t.apply(this,arguments)};function e(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function r(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)u.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return u}"function"==typeof SuppressedError&&SuppressedError;var n,i="KEYS",o="VALUES",u="",a=function(){function t(t,e){var r=t._tree,n=Array.from(r.keys());this.set=t,this._type=e,this._path=n.length>0?[{node:r,keys:n}]:[]}return t.prototype.next=function(){var t=this.dive();return this.backtrack(),t},t.prototype.dive=function(){if(0===this._path.length)return{done:!0,value:void 0};var t=s(this._path),e=t.node,r=t.keys;if(s(r)===u)return{done:!1,value:this.result()};var n=e.get(s(r));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()},t.prototype.backtrack=function(){if(0!==this._path.length){var t=s(this._path).keys;t.pop(),t.length>0||(this._path.pop(),this.backtrack())}},t.prototype.key=function(){return this.set._prefix+this._path.map((function(t){var e=t.keys;return s(e)})).filter((function(t){return t!==u})).join("")},t.prototype.value=function(){return s(this._path).node.get(u)},t.prototype.result=function(){switch(this._type){case o:return this.value();case i:return this.key();default:return[this.key(),this.value()]}},t.prototype[Symbol.iterator]=function(){return this},t}(),s=function(t){return t[t.length-1]},l=function(t,r,n,i,o,a,s,c){var h,d,f=a*s;try{t:for(var y=e(t.keys()),v=y.next();!v.done;v=y.next()){var p=v.value;if(p===u){var m=o[f-1];m<=n&&i.set(c,[t.get(p),m])}else{for(var _=a,g=0;g<p.length;++g,++_){for(var F=p[g],x=s*_,w=x-s,b=o[x],A=Math.max(0,_-n-1),C=Math.min(s-1,_+n),E=A;E<C;++E){var z=F!==r[E],S=o[w+E]+ +z,D=o[w+E+1]+1,I=o[x+E]+1,k=o[x+E+1]=Math.min(S,D,I);k<b&&(b=k)}if(b>n)continue t}l(t.get(p),r,n,i,o,_,s,c+p)}}}catch(t){h={error:t}}finally{try{v&&!v.done&&(d=y.return)&&d.call(y)}finally{if(h)throw h.error}}},c=function(){function t(t,e){void 0===t&&(t=new Map),void 0===e&&(e=""),this._size=void 0,this._tree=t,this._prefix=e}return t.prototype.atPrefix=function(n){var i,o;if(!n.startsWith(this._prefix))throw new Error("Mismatched prefix");var a=r(h(this._tree,n.slice(this._prefix.length)),2),s=a[0],l=a[1];if(void 0===s){var c=r(m(l),2),d=c[0],f=c[1];try{for(var y=e(d.keys()),v=y.next();!v.done;v=y.next()){var p=v.value;if(p!==u&&p.startsWith(f)){var _=new Map;return _.set(p.slice(f.length),d.get(p)),new t(_,n)}}}catch(t){i={error:t}}finally{try{v&&!v.done&&(o=y.return)&&o.call(y)}finally{if(i)throw i.error}}}return new t(s,n)},t.prototype.clear=function(){this._size=void 0,this._tree.clear()},t.prototype.delete=function(t){return this._size=void 0,y(this._tree,t)},t.prototype.entries=function(){return new a(this,"ENTRIES")},t.prototype.forEach=function(t){var n,i;try{for(var o=e(this),u=o.next();!u.done;u=o.next()){var a=r(u.value,2);t(a[0],a[1],this)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},t.prototype.fuzzyGet=function(t,e){return function(t,e,r){var n=new Map;if(void 0===e)return n;for(var i=e.length+1,o=i+r,u=new Uint8Array(o*i).fill(r+1),a=0;a<i;++a)u[a]=a;for(var s=1;s<o;++s)u[s*i]=s;return l(t,e,r,n,u,1,i,""),n}(this._tree,t,e)},t.prototype.get=function(t){var e=d(this._tree,t);return void 0!==e?e.get(u):v