mirror of
https://github.com/welpo/tabi.git
synced 2026-03-10 01:57:20 +01:00
Add `!event.isComposing` guards to the arrow-key and Enter handlers in the search modal. This prevents keydown events fired during IME composition (e.g. Japanese input) from being intercepted: - Arrow keys no longer move result selection while choosing candidates - Enter no longer navigates to a result while confirming a character Closes #626
1 line
No EOL
24 KiB
JavaScript
1 line
No EOL
24 KiB
JavaScript
!function(){function g(e){var t=new g.Index;return t.pipeline.add(g.trimmer,g.stopWordFilter,g.stemmer),e&&e.call(t,t),t}var t,e,n;g.version="0.9.5",(lunr=g).utils={},g.utils.warn=(t=this,function(e){t.console&&console.warn&&console.warn(e)}),g.utils.toString=function(e){return null==e?"":e.toString()},g.EventEmitter=function(){this.events={}},g.EventEmitter.prototype.addListener=function(){var e=Array.prototype.slice.call(arguments);let t=e.pop();if("function"!=typeof t)throw new TypeError("last argument must be a function");e.forEach(function(e){this.hasHandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},g.EventEmitter.prototype.removeListener=function(e,t){this.hasHandler(e)&&-1!==(t=this.events[e].indexOf(t))&&(this.events[e].splice(t,1),0===this.events[e].length)&&delete this.events[e]},g.EventEmitter.prototype.emit=function(e){if(this.hasHandler(e)){let t=Array.prototype.slice.call(arguments,1);this.events[e].forEach(function(e){e.apply(void 0,t)},this)}},g.EventEmitter.prototype.hasHandler=function(e){return e in this.events},g.tokenizer=function(n){if(!arguments.length||null==n)return[];if(Array.isArray(n)){let e=n.filter(function(e){return null!=e}),t=(e=e.map(function(e){return g.utils.toString(e).toLowerCase()}),[]);return e.forEach(function(e){e=e.split(g.tokenizer.seperator);t=t.concat(e)},this),t}return n.toString().trim().toLowerCase().split(g.tokenizer.seperator)},g.tokenizer.defaultSeperator=/[\s-]+/,g.tokenizer.seperator=g.tokenizer.defaultSeperator,g.tokenizer.setSeperator=function(e){null!=e&&"object"==typeof e&&(g.tokenizer.seperator=e)},g.tokenizer.resetSeperator=function(){g.tokenizer.seperator=g.tokenizer.defaultSeperator},g.tokenizer.getSeperator=function(){return g.tokenizer.seperator},g.Pipeline=function(){this._queue=[]},g.Pipeline.registeredFunctions={},g.Pipeline.registerFunction=function(e,t){t in g.Pipeline.registeredFunctions&&g.utils.warn("Overwriting existing registered function: "+t),e.label=t,g.Pipeline.registeredFunctions[t]=e},g.Pipeline.getRegisteredFunction=function(e){return e in g.Pipeline.registeredFunctions!=!0?null:g.Pipeline.registeredFunctions[e]},g.Pipeline.warnIfFunctionNotRegistered=function(e){e.label&&e.label in this.registeredFunctions||g.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},g.Pipeline.load=function(e){let n=new g.Pipeline;return e.forEach(function(e){var t=g.Pipeline.getRegisteredFunction(e);if(!t)throw new Error("Cannot load un-registered function: "+e);n.add(t)}),n},g.Pipeline.prototype.add=function(){Array.prototype.slice.call(arguments).forEach(function(e){g.Pipeline.warnIfFunctionNotRegistered(e),this._queue.push(e)},this)},g.Pipeline.prototype.after=function(e,t){g.Pipeline.warnIfFunctionNotRegistered(t);e=this._queue.indexOf(e);if(-1===e)throw new Error("Cannot find existingFn");this._queue.splice(e+1,0,t)},g.Pipeline.prototype.before=function(e,t){g.Pipeline.warnIfFunctionNotRegistered(t);e=this._queue.indexOf(e);if(-1===e)throw new Error("Cannot find existingFn");this._queue.splice(e,0,t)},g.Pipeline.prototype.remove=function(e){e=this._queue.indexOf(e);-1!==e&&this._queue.splice(e,1)},g.Pipeline.prototype.run=function(o){var e=[],t=o.length,i=this._queue.length;for(let n=0;n<t;n++){let t=o[n];for(let e=0;e<i&&null!=(t=this._queue[e](t,n,o));e++);null!=t&&e.push(t)}return e},g.Pipeline.prototype.reset=function(){this._queue=[]},g.Pipeline.prototype.get=function(){return this._queue},g.Pipeline.prototype.toJSON=function(){return this._queue.map(function(e){return g.Pipeline.warnIfFunctionNotRegistered(e),e.label})},g.Index=function(){this._fields=[],this._ref="id",this.pipeline=new g.Pipeline,this.documentStore=new g.DocumentStore,this.index={},this.eventEmitter=new g.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},g.Index.prototype.on=function(){var e=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,e)},g.Index.prototype.off=function(e,t){return this.eventEmitter.removeListener(e,t)},g.Index.load=function(e){e.version!==g.version&&g.utils.warn("version mismatch: current "+g.version+" importing "+e.version);var t,n=new this;for(t in n._fields=e.fields,n._ref=e.ref,n.documentStore=g.DocumentStore.load(e.documentStore),n.pipeline=g.Pipeline.load(e.pipeline),n.index={},e.index)n.index[t]=g.InvertedIndex.load(e.index[t]);return n},g.Index.prototype.addField=function(e){return this._fields.push(e),this.index[e]=new g.InvertedIndex,this},g.Index.prototype.setRef=function(e){return this._ref=e,this},g.Index.prototype.saveDocument=function(e){return this.documentStore=new g.DocumentStore(e),this},g.Index.prototype.addDoc=function(s,e){if(s){e=void 0===e||e;let r=s[this._ref];this.documentStore.addDoc(r,s),this._fields.forEach(function(e){var t,n=this.pipeline.run(g.tokenizer(s[e]));this.documentStore.addFieldLength(r,e,n.length);let o={};for(t in n.forEach(function(e){e in o?o[e]+=1:o[e]=1},this),o){var i=o[t],i=Math.sqrt(i);this.index[e].addToken(t,{ref:r,tf:i})}},this),e&&this.eventEmitter.emit("add",s,this)}},g.Index.prototype.removeDocByRef=function(e,t){e&&!1!==this.documentStore.isDocStored()&&this.documentStore.hasDoc(e)&&(e=this.documentStore.getDoc(e),this.removeDoc(e,!1))},g.Index.prototype.removeDoc=function(e,t){if(e){t=void 0===t||t;let n=e[this._ref];this.documentStore.hasDoc(n)&&(this.documentStore.removeDoc(n),this._fields.forEach(function(t){this.pipeline.run(g.tokenizer(e[t])).forEach(function(e){this.index[t].removeToken(e,n)},this)},this),t)&&this.eventEmitter.emit("remove",e,this)}},g.Index.prototype.updateDoc=function(e,t){t=void 0===t||t;this.removeDocByRef(e[this._ref],!1),this.addDoc(e,!1),t&&this.eventEmitter.emit("update",e,this)},g.Index.prototype.idf=function(e,t){var n="@"+t+"/"+e;return Object.prototype.hasOwnProperty.call(this._idfCache,n)?this._idfCache[n]:(t=this.index[t].getDocFreq(e),e=1+Math.log(this.documentStore.length/(t+1)),this._idfCache[n]=e)},g.Index.prototype.getFields=function(){return this._fields.slice()},g.Index.prototype.search=function(t,e){if(!t)return[];t="string"==typeof t?{any:t}:JSON.parse(JSON.stringify(t));let n=null;null!=e&&(n=JSON.stringify(e));var o=new g.Configuration(n,this.getFields()).get(),i={},r=Object.keys(t);for(let e=0;e<r.length;e++){var s=r[e];i[s]=this.pipeline.run(g.tokenizer(t[s]))}var l,u={};for(l in o){var a=i[l]||i.any;if(a){var c=this.fieldSearch(a,l,o),d=o[l].boost;for(f in c)c[f]=c[f]*d;for(f in c)f in u?u[f]+=c[f]:u[f]=c[f]}}var h,f,p=[];for(f in u)h={ref:f,score:u[f]},this.documentStore.hasDoc(f)&&(h.doc=this.documentStore.getDoc(f)),p.push(h);return p.sort(function(e,t){return t.score-e.score}),p},g.Index.prototype.fieldSearch=function(e,a,t){let c=t[a].bool,n=t[a].expand;t=t[a].boost;let d=null,h={};if(0!==t)return e.forEach(function(l){let e=[l],u=(!0===n&&(e=this.index[a].expandToken(l)),{});e.forEach(function(n){let e=this.index[a].getDocs(n);var o=this.idf(n,a);if(d&&"AND"===c){var i,t={};for(i in d)i in e&&(t[i]=e[i]);e=t}for(i in n===l&&this.fieldSearchStats(h,n,e),e){var r=this.index[a].getTermFrequency(n,i),s=this.documentStore.getFieldLength(i,a);let e=1,t=(0!==s&&(e=1/Math.sqrt(s)),1);n!==l&&(t=.15*(1-(n.length-l.length)/n.length));s=r*o*e*t;i in u?u[i]+=s:u[i]=s}},this),d=this.mergeScores(d,u,c)},this),d=this.coordNorm(d,h,e.length)},g.Index.prototype.mergeScores=function(e,t,n){if(!e)return t;if("AND"===n){var o={};for(i in t)i in e&&(o[i]=e[i]+t[i]);return o}for(var i in t)i in e?e[i]+=t[i]:e[i]=t[i];return e},g.Index.prototype.fieldSearchStats=function(e,t,n){for(var o in n)o in e?e[o].push(t):e[o]=[t]},g.Index.prototype.coordNorm=function(e,t,n){for(var o in e){var i;o in t&&(i=t[o].length,e[o]=e[o]*i/n)}return e},g.Index.prototype.toJSON=function(){let t={};return this._fields.forEach(function(e){t[e]=this.index[e].toJSON()},this),{version:g.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),index:t,pipeline:this.pipeline.toJSON()}},g.Index.prototype.use=function(e){var t=Array.prototype.slice.call(arguments,1);t.unshift(this),e.apply(this,t)},g.DocumentStore=function(e){this._save=null==e||e,this.docs={},this.docInfo={},this.length=0},g.DocumentStore.load=function(e){var t=new this;return t.length=e.length,t.docs=e.docs,t.docInfo=e.docInfo,t._save=e.save,t},g.DocumentStore.prototype.isDocStored=function(){return this._save},g.DocumentStore.prototype.addDoc=function(e,t){this.hasDoc(e)||this.length++,!0===this._save?this.docs[e]=(e=>{if(null===e||"object"!=typeof e)return e;var t,n=e.constructor();for(t in e)e.hasOwnProperty(t)&&(n[t]=e[t]);return n})(t):this.docs[e]=null},g.DocumentStore.prototype.getDoc=function(e){return!1===this.hasDoc(e)?null:this.docs[e]},g.DocumentStore.prototype.hasDoc=function(e){return e in this.docs},g.DocumentStore.prototype.removeDoc=function(e){this.hasDoc(e)&&(delete this.docs[e],delete this.docInfo[e],this.length--)},g.DocumentStore.prototype.addFieldLength=function(e,t,n){null!=e&&0!=this.hasDoc(e)&&(this.docInfo[e]||(this.docInfo[e]={}),this.docInfo[e][t]=n)},g.DocumentStore.prototype.updateFieldLength=function(e,t,n){null!=e&&0!=this.hasDoc(e)&&this.addFieldLength(e,t,n)},g.DocumentStore.prototype.getFieldLength=function(e,t){return null!=e&&e in this.docs&&t in this.docInfo[e]?this.docInfo[e][t]:0},g.DocumentStore.prototype.toJSON=function(){return{docs:this.docs,docInfo:this.docInfo,length:this.length,save:this._save}},g.stemmer=(()=>{let a={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},c={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""};var e="[aeiouy]",t="[^aeiou][^aeiouy]*";let d=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*"),h=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*"),f=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$"),p=new RegExp("^([^aeiou][^aeiouy]*)?[aeiouy]"),g=/^(.+?)(ss|i)es$/,m=/^(.+?)([^s])s$/,y=/^(.+?)eed$/,v=/^(.+?)(ed|ing)$/,w=/.$/,S=/(at|bl|iz)$/,b=new RegExp("([^aeiouylsz])\\1$"),x=new RegExp("^"+t+e+"[^aeiouwxy]$"),E=/^(.+?[^aeiou])y$/,I=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,k=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,_=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,D=/^(.+?)(s|t)(ion)$/,F=/^(.+?)e$/,A=/ll$/,C=new RegExp("^"+t+e+"[^aeiouwxy]$");return function(e){let t,n,o,i,r,s,l;var u;return e.length<3||("y"==(o=e.substr(0,1))&&(e=o.toUpperCase()+e.substr(1)),i=g,r=m,i.test(e)?e=e.replace(i,"$1$2"):r.test(e)&&(e=e.replace(r,"$1$2")),i=y,r=v,i.test(e)?(u=i.exec(e),(i=d).test(u[1])&&(i=w,e=e.replace(i,""))):r.test(e)&&(u=r.exec(e),t=u[1],(r=p).test(t))&&(e=t,r=S,s=b,l=x,r.test(e)?e+="e":s.test(e)?(i=w,e=e.replace(i,"")):l.test(e)&&(e+="e")),(i=E).test(e)&&(u=i.exec(e),e=(t=u[1])+"i"),(i=I).test(e)&&(u=i.exec(e),t=u[1],n=u[2],(i=d).test(t))&&(e=t+a[n]),(i=k).test(e)&&(u=i.exec(e),t=u[1],n=u[2],(i=d).test(t))&&(e=t+c[n]),i=_,r=D,i.test(e)?(u=i.exec(e),t=u[1],(i=h).test(t)&&(e=t)):r.test(e)&&(u=r.exec(e),t=u[1]+u[2],(r=h).test(t))&&(e=t),(i=F).test(e)&&(u=i.exec(e),t=u[1],i=h,r=f,s=C,i.test(t)||r.test(t)&&!s.test(t))&&(e=t),i=A,r=h,i.test(e)&&r.test(e)&&(i=w,e=e.replace(i,"")),"y"==o&&(e=o.toLowerCase()+e.substr(1))),e}})(),g.Pipeline.registerFunction(g.stemmer,"stemmer"),g.stopWordFilter=function(e){if(e&&!0!==g.stopWordFilter.stopWords[e])return e},g.clearStopWords=function(){g.stopWordFilter.stopWords={}},g.addStopWords=function(e){null!=e&&!1!==Array.isArray(e)&&e.forEach(function(e){g.stopWordFilter.stopWords[e]=!0},this)},g.resetStopWords=function(){g.stopWordFilter.stopWords=g.defaultStopWords},g.defaultStopWords={"":!0,a:!0,able:!0,about:!0,across:!0,after:!0,all:!0,almost:!0,also:!0,am:!0,among:!0,an:!0,and:!0,any:!0,are:!0,as:!0,at:!0,be:!0,because:!0,been:!0,but:!0,by:!0,can:!0,cannot:!0,could:!0,dear:!0,did:!0,do:!0,does:!0,either:!0,else:!0,ever:!0,every:!0,for:!0,from:!0,get:!0,got:!0,had:!0,has:!0,have:!0,he:!0,her:!0,hers:!0,him:!0,his:!0,how:!0,however:!0,i:!0,if:!0,in:!0,into:!0,is:!0,it:!0,its:!0,just:!0,least:!0,let:!0,like:!0,likely:!0,may:!0,me:!0,might:!0,most:!0,must:!0,my:!0,neither:!0,no:!0,nor:!0,not:!0,of:!0,off:!0,often:!0,on:!0,only:!0,or:!0,other:!0,our:!0,own:!0,rather:!0,said:!0,say:!0,says:!0,she:!0,should:!0,since:!0,so:!0,some:!0,than:!0,that:!0,the:!0,their:!0,them:!0,then:!0,there:!0,these:!0,they:!0,this:!0,tis:!0,to:!0,too:!0,twas:!0,us:!0,wants:!0,was:!0,we:!0,were:!0,what:!0,when:!0,where:!0,which:!0,while:!0,who:!0,whom:!0,why:!0,will:!0,with:!0,would:!0,yet:!0,you:!0,your:!0},g.stopWordFilter.stopWords=g.defaultStopWords,g.Pipeline.registerFunction(g.stopWordFilter,"stopWordFilter"),g.trimmer=function(e){if(null==e)throw new Error("token should not be undefined");return e.replace(/^\W+/,"").replace(/\W+$/,"")},g.Pipeline.registerFunction(g.trimmer,"trimmer"),g.InvertedIndex=function(){this.root={docs:{},df:0}},g.InvertedIndex.load=function(e){var t=new this;return t.root=e.root,t},g.InvertedIndex.prototype.addToken=function(e,t,n){n=n||this.root;let o=0;for(;o<=e.length-1;){var i=e[o];i in n||(n[i]={docs:{},df:0}),o+=1,n=n[i]}var r=t.ref;n.docs[r]?n.docs[r]={tf:t.tf}:(n.docs[r]={tf:t.tf},n.df+=1)},g.InvertedIndex.prototype.hasToken=function(t){if(!t)return!1;let n=this.root;for(let e=0;e<t.length;e++){if(!n[t[e]])return!1;n=n[t[e]]}return!0},g.InvertedIndex.prototype.getNode=function(t){if(!t)return null;let n=this.root;for(let e=0;e<t.length;e++){if(!n[t[e]])return null;n=n[t[e]]}return n},g.InvertedIndex.prototype.getDocs=function(e){e=this.getNode(e);return null==e?{}:e.docs},g.InvertedIndex.prototype.getTermFrequency=function(e,t){e=this.getNode(e);return null!=e&&t in e.docs?e.docs[t].tf:0},g.InvertedIndex.prototype.getDocFreq=function(e){e=this.getNode(e);return null==e?0:e.df},g.InvertedIndex.prototype.removeToken=function(e,t){e&&null!=(e=this.getNode(e))&&t in e.docs&&(delete e.docs[t],--e.df)},g.InvertedIndex.prototype.expandToken=function(e,t,n){if(null==e||""==e)return[];t=t||[];if(null!=n||null!=(n=this.getNode(e)))for(var o in 0<n.df&&t.push(e),n)"docs"!==o&&"df"!==o&&this.expandToken(e+o,t,n[o]);return t},g.InvertedIndex.prototype.toJSON=function(){return{root:this.root}},g.Configuration=function(e,t){var n,e=e||"";if(null==t)throw new Error("fields should not be null");this.config={};try{n=JSON.parse(e),this.buildUserConfig(n,t)}catch(e){g.utils.warn("user configuration parse failed, will use default configuration"),this.buildDefaultConfig(t)}},g.Configuration.prototype.buildDefaultConfig=function(e){this.reset(),e.forEach(function(e){this.config[e]={boost:1,bool:"OR",expand:!1}},this)},g.Configuration.prototype.buildUserConfig=function(t,e){let n="OR",o=!1;if(this.reset(),"bool"in t&&(n=t.bool||n),"expand"in t&&(o=t.expand||o),"fields"in t)for(var i in t.fields)if(-1<e.indexOf(i)){var r=t.fields[i];let e=o;null!=r.expand&&(e=r.expand),this.config[i]={boost:r.boost||0===r.boost?r.boost:1,bool:r.bool||n,expand:e}}else g.utils.warn("field name in user configuration not found in index instance fields");else this.addAllFields2UserConfig(n,o,e)},g.Configuration.prototype.addAllFields2UserConfig=function(t,n,e){e.forEach(function(e){this.config[e]={boost:1,bool:t,expand:n}},this)},g.Configuration.prototype.get=function(){return this.config},g.Configuration.prototype.reset=function(){this.config={}},lunr.SortedSet=function(){this.length=0,this.elements=[]},lunr.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},lunr.SortedSet.prototype.add=function(){let e,t;for(e=0;e<arguments.length;e++)t=arguments[e],~this.indexOf(t)||this.elements.splice(this.locationFor(t),0,t);this.length=this.elements.length},lunr.SortedSet.prototype.toArray=function(){return this.elements.slice()},lunr.SortedSet.prototype.map=function(e,t){return this.elements.map(e,t)},lunr.SortedSet.prototype.forEach=function(e,t){return this.elements.forEach(e,t)},lunr.SortedSet.prototype.indexOf=function(e){let t=0,n=this.elements.length,o=n-t,i=t+Math.floor(o/2),r=this.elements[i];for(;1<o;){if(r===e)return i;r<e&&(t=i),r>e&&(n=i),o=n-t,i=t+Math.floor(o/2),r=this.elements[i]}return r===e?i:-1},lunr.SortedSet.prototype.locationFor=function(e){let t=0,n=this.elements.length,o=n-t,i=t+Math.floor(o/2),r=this.elements[i];for(;1<o;)r<e&&(t=i),r>e&&(n=i),o=n-t,i=t+Math.floor(o/2),r=this.elements[i];return r>e?i:r<e?i+1:void 0},lunr.SortedSet.prototype.intersect=function(e){var t=new lunr.SortedSet;let n=0,o=0;for(var i=this.length,r=e.length,s=this.elements,l=e.elements;!(n>i-1||o>r-1);)s[n]===l[o]?(t.add(s[n]),n++,o++):s[n]<l[o]?n++:s[n]>l[o]&&o++;return t},lunr.SortedSet.prototype.clone=function(){var e=new lunr.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},lunr.SortedSet.prototype.union=function(e){let t,n,o;n=this.length>=e.length?(t=this,e):(t=e,this),o=t.clone();for(let e=0,t=n.toArray();e<t.length;e++)o.add(t[e]);return o},lunr.SortedSet.prototype.toJSON=function(){return this.toArray()},e=this,n=function(){return g},"function"==typeof define&&define.amd?define(n):"object"==typeof exports?module.exports=g:e.elasticlunr=g}(),window.onload=function(){if(document.body.contains(document.getElementById("searchModal"))){let o=document.documentElement.lang,u=document.getElementById("searchInput"),l=document.getElementById("searchModal"),t=document.getElementById("search-button"),a=document.getElementById("clear-search"),i=document.getElementById("results-container"),c=document.getElementById("results");let r={zero_results:document.getElementById("zero_results"),one_results:document.getElementById("one_results"),two_results:document.getElementById("two_results"),few_results:document.getElementById("few_results"),many_results:document.getElementById("many_results")};{var s=t;var h=["title","aria-label"];let n=window.navigator.userAgent.toLowerCase().includes("mac")?"Cmd + K":"Ctrl + K";h.forEach(e=>{let t=s.getAttribute(e);t&&(t=t.replace("$SHORTCUT",n),s.setAttribute(e,t))})}t.addEventListener("keydown",function(e){"Enter"!==e.key&&" "!==e.key||t.click()});let e,d=(l.addEventListener("click",m),l.addEventListener("touchend",m,{passive:!0}),document.addEventListener("keydown",function(e){"Escape"===e.key&&p()}),a.addEventListener("click",function(){n(),u.focus()}),a.addEventListener("keydown",function(e){"Enter"!==e.key&&" "!==e.key||(n(),u.focus(),e.preventDefault())}),t.addEventListener("mouseover",y),t.addEventListener("click",f),t.addEventListener("touchstart",f,{passive:!0}),null);function f(){e=document.activeElement,y(),l.style.display="block",u.focus()}function p(){l.style.display="none",n(),e&&document.body.contains(e)&&e.focus()}function g(e){var t;"true"!==e.getAttribute("aria-selected")&&([t=null]=[e],c.querySelectorAll("#results > div").forEach(e=>{e!==t&&e.setAttribute("aria-selected","false")}),e.setAttribute("aria-selected","true")),u.setAttribute("aria-activedescendant",e.id)}function n(){u.value="",c.innerHTML="",i.style.display="none",u.removeAttribute("aria-activedescendant"),a.style.display="none"}function m(e){e.target===l&&p(),e.stopPropagation()}function y(){if(!d)if(window.searchIndex)d=Promise.resolve(elasticlunr.Index.load(window.searchIndex));else{var t=document.documentElement.getAttribute("lang").substring(0,2);let e=document.querySelector("meta[name='base']").getAttribute("content");e.endsWith("/")&&(e=e.slice(0,-1)),d=fetch(e+"/search_index."+t+".json").then(e=>e.json()).then(e=>elasticlunr.Index.load(e))}}function S(e){return e=parseInt(e,16).toString(2),[0,1,2,3,4][Math.ceil(e.length/8)]}function v(e,t){var n=t.map(function(e){return elasticlunr.stemmer(e.toLowerCase())});let o=0;var i,r,s=[];for(i of e.toLowerCase().split(". ")){let t=!0;for(r of i.split(/[\s\n]/)){if(0<r.length){let e=t?8:2;for(var l of n)elasticlunr.stemmer(r).startsWith(l)&&(e=40);s.push([r,e,o]),t=!1}o+=r.length+1}o+=1}if(0===s.length)return 150<e.length?e.substring(0,150)+"…":e;var u=[];let a=0;for(var c=0;c<Math.min(s.length,30);c++)a+=s[c][1];u.push(a);for(c=1;c<=s.length-30;c++)a=(a-=s[c-1][1])+s[c+30-1][1],u.push(a);let d=0,h=0;for(c=u.length-1;0<=c;c--)h<u[c]&&(h=u[c],d=c);var f=[];let p=((e,t,n)=>{let o=0,i=t-1;for(;0<=i&&o<n;){if(" "===e[i]&&"."!==e[i-1])o++;else if("."===e[i]&&" "===e[i+1])break;i--}return o===n?i+1:t})(e,s[d][2],4);for(var g=/^[\x00-\xff]+$/,c=d;c<d+30&&c<s.length;c++){var m,y=s[c],v=(p<y[2]&&(f.push(e.substring(p,y[2])),p=y[2]),40===y[1]&&f.push("<b>"),y[2]+y[0].length);!g.test(y[0])&&12<=y[0].length?(m=((t,n)=>{let o="",i=!1,r=0,s=0,l=0;for(let e=0;e<t.length;e++){var u=t.codePointAt(e).toString(16);if(i=4<u.length&&++e+1<t.length?"200d"===t.codePointAt(e+1).toString(16):i){if(r+=S(u),e==t.length-1){if(!((s+=r)<=n))break;o+=t.substr(l,e-l+1)}}else if(0!=r){if(!((s=(s+=r)+S(u))<=n))break;o+=t.substr(l,e-l+1),l=e+1,r=0}else{if(!((s+=S(u))<=n))break;u.length<=4?o+=t[e]:o+=t[e-1]+t[e],l=e+1}}return o})(e.substring(y[2],v),12),f.push(m)):f.push(e.substring(y[2],v)),40===y[1]&&f.push("</b>"),p=v}f.push("…");t=f.join("");let w=t;return w=150<t.replace(/<[^>]+>/g,"").length?t.substring(0,150)+"…":w}function w(){g(this)}u.addEventListener("input",async function(){var e=this.value;let s=e.trim();var t,n=await d,e=(c.innerHTML="",a.style.display=0<e.length?"block":"none",i.style.display=0<s.length?"block":"none",n.search(s,{bool:"OR",fields:{title:{boost:3},body:{boost:2},description:{boost:1},path:{boost:1}}}));n=e.length,t=((e,t)=>{let n="";var o;return n=0===e?"zero_results":1===e?"one_results":"ar"===t?(o=e%100,2===e?"two_results":3<=o&&o<=10?"few_results":"many_results"):["uk","be","bs","hr","ru","sr"].includes(t)?(o=e%100,1==(t=e%10)&&11!=o?"one_results":2<=t&&t<=4&&!(12<=o&&o<=14)?"few_results":"many_results"):"many_results"})(n,o),Object.values(r).forEach(e=>{e&&(e.style.display="none")}),(t=r[t])&&(t.style.display="inline",t.textContent=t.textContent.replace("$NUMBER",n.toString()));let l=0;e.forEach(function(t){if(t.doc.title||t.doc.path||t.doc.id){var n=document.createElement("div"),o=(n.setAttribute("role","option"),n.id="result-"+l++,n.innerHTML="<a href><span></span><span></span></a>",n.querySelector("a")),i=n.querySelector("span:first-child"),r=n.querySelector("span:nth-child(2)"),i=(i.textContent=t.doc.title||t.doc.path||t.doc.id,t.doc.body?v(t.doc.body,s.split(/\s+/)):t.doc.description||"");r.innerHTML=i;let e=t.ref;t.doc.body&&(r=encodeURIComponent(s),e+="#:~:text="+r),o.href=e,c.appendChild(n)}}),u.setAttribute("aria-expanded",0<l?"true":"false"),c.firstChild&&g(c.firstChild),c.addEventListener("mouseover",function(e){e.target.closest('div[role="option"]')&&g(e.target.closest('div[role="option"]'))}),c.addEventListener("click",function(e){var t,n,o=e.target.closest("a");o&&(o=o.getAttribute("href"),t=window.location.href,(n=e=>e.split("#")[0].replace(/\/$/,""))(o)!==n(t)||e.ctrlKey||e.metaKey||p())}),document.querySelectorAll("#results > div").forEach(e=>{e.removeEventListener("touchstart",w),e.addEventListener("touchstart",w,{passive:!0})})},!0),document.addEventListener("keydown",function(t){var e=navigator.userAgent.toLowerCase().includes("mac")?t.metaKey:t.ctrlKey;if("k"===t.key&&e)t.preventDefault(),("block"===l.style.display?p:f)();else{e=document.activeElement;if("Tab"!==t.key||e!==u&&e!==a){var n=c.querySelectorAll("#results > div");if(0!==n.length){var o,i,r=Array.from(n),n=c.querySelector('[aria-selected="true"]'),s=r.indexOf(n);if(["ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(t.key)&&!t.isComposing){t.preventDefault();let e=s;switch(t.key){case"ArrowUp":e=Math.max(s-1,0);break;case"ArrowDown":e=Math.min(s+1,r.length-1);break;case"Home":e=0;break;case"End":e=r.length-1;break;case"PageUp":e=Math.max(s-3,0);break;case"PageDown":e=Math.min(s+3,r.length-1)}e!==s&&(o=e,g((i=r)[o]),i[o].scrollIntoView({block:"nearest",inline:"start"}))}"Enter"===t.key&&n&&!t.isComposing&&(t.preventDefault(),t.stopImmediatePropagation(),(i=n.querySelector("a"))&&(window.location.href=i.getAttribute("href")),p())}}else t.preventDefault(),(e===u?a:u).focus()}})}}; |