diff options
| -rw-r--r-- | COPY-TO-ROOT-SASS/abridge.scss | 1 | ||||
| -rw-r--r-- | sass/_functions.scss | 12 | ||||
| -rw-r--r-- | sass/abridge.scss | 38 | ||||
| -rw-r--r-- | static/js/abridge.min.js | 2 | ||||
| -rw-r--r-- | static/js/codecopy.js | 100 | ||||
| -rw-r--r-- | static/js/elasticlunr.js | 691 |
6 files changed, 67 insertions, 777 deletions
diff --git a/COPY-TO-ROOT-SASS/abridge.scss b/COPY-TO-ROOT-SASS/abridge.scss index b442102..0fd51e9 100644 --- a/COPY-TO-ROOT-SASS/abridge.scss +++ b/COPY-TO-ROOT-SASS/abridge.scss @@ -50,6 +50,7 @@ //$icon-angr: true,//pagination, goto next page //$icon-angrr: true,//pagination, goto last page //$icon-angu: true,//back to top button, appears after scrolling down. + //$icon-copy: true,//copy to clipboard, for code blocks. //$icon-ffolder: false, //$icon-folder: false,// categories folder diff --git a/sass/_functions.scss b/sass/_functions.scss index 13fd8be..2f4029a 100644 --- a/sass/_functions.scss +++ b/sass/_functions.scss @@ -61,6 +61,15 @@ } } +/** + * SVG Icons + * https://github.com/feathericons/feather + * https://github.com/tabler/tabler-icons/find/master + * + * https://yqnn.github.io/svg-path-editor/ + * https://jakearchibald.github.io/svgomg/ + * https://codepen.io/yoksel/pen/MWKeKK + */ @function icon($icon-name,$stroke,$stroke-width:1,$fill:'none',$ic) { $sc:"%23888";//stroke color @if $ic { @@ -115,6 +124,9 @@ angr: "%3Csvg xmlns='http://www.w3.org/2000/svg' stroke='#{map-get($p, s)}' stroke-width='#{map-get($p, sw)}' fill='#{map-get($p, f)}' viewBox='0 0 24 24'%3E%3Cpath d='m8 4 8 8-8 8'/%3E%3C/svg%3E", angrr: "%3Csvg xmlns='http://www.w3.org/2000/svg' stroke='#{map-get($p, s)}' stroke-width='#{map-get($p, sw)}' fill='#{map-get($p, f)}' viewBox='0 0 24 24'%3E%3Cpath d='m4 4 8 8-8 8m9-16 8 8-8 8'/%3E%3C/svg%3E", angu: "%3Csvg xmlns='http://www.w3.org/2000/svg' stroke='#{map-get($p, s)}' stroke-width='#{map-get($p, sw)}' fill='#{map-get($p, f)}' viewBox='0 0 24 24'%3E%3Cpath d='m4 16 8-8 8 8'/%3E%3C/svg%3E", + copy: "%3Csvg xmlns='http://www.w3.org/2000/svg' stroke='#{map-get($p, s)}' stroke-width='#{map-get($p, sw)}' fill='#{map-get($p, f)}' viewBox='0 0 24 24'%3E%3Cpath d='M11 1a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1ZM7 9H3a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1v-4'/%3E%3C/svg%3E", + copy-yes: "%3Csvg xmlns='http://www.w3.org/2000/svg' stroke='#{map-get($p, s)}' stroke-width='#{map-get($p, sw)}' fill='#{map-get($p, f)}' viewBox='0 0 24 24'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E", + copy-err: "%3Csvg xmlns='http://www.w3.org/2000/svg' stroke='#{map-get($p, s)}' stroke-width='#{map-get($p, sw)}' fill='#{map-get($p, f)}' viewBox='0 0 24 24'%3E%3Cpath d='M1 12a1 1 0 0 0 22 0 1 1 0 0 0-22 0m11-7v9m0 5v-2'/%3E%3C/svg%3E", search: "%3Csvg xmlns='http://www.w3.org/2000/svg' stroke='#{map-get($p, s)}' stroke-width='#{map-get($p, sw)}' fill='#{map-get($p, f)}' viewBox='0 0 24 24'%3E%3Ccircle cx='9.5' cy='9.5' r='8'/%3E%3Cpath d='m23 23-9-9'/%3E%3C/svg%3E" ); $icon: map-get($icons, $icon-name); diff --git a/sass/abridge.scss b/sass/abridge.scss index f5e623e..b50d2b6 100644 --- a/sass/abridge.scss +++ b/sass/abridge.scss @@ -58,6 +58,7 @@ $icon-angl: true !default;//pagination, goto previous page $icon-angr: true !default;//pagination, goto next page $icon-angrr: true !default;//pagination, goto last page $icon-angu: true !default;//back to top button, appears after scrolling down. +$icon-copy: true !default;//copy to clipboard, for code blocks. $icon-ffolder: false !default; $icon-folder: false !default;// categories folder @@ -859,6 +860,8 @@ $syntax: true !default;//syntax highlighting for code blocks padding: .3rem .2rem; } pre { + position: relative; + padding: 2rem .5rem .3rem; display: block; overflow-x: auto; -ms-overflow-style: scrollbar; @@ -1158,27 +1161,29 @@ $syntax: true !default;//syntax highlighting for code blocks .rpad {padding-right: .2rem} .si {font-size: 1.5em} pre code[data-lang]::before { + content: attr(data-lang); + padding: .3rem; + display: block; + background-color: var(--c3); color: var(--h1); + width: 100%; + position: absolute; + top: 0; + left: 0; + padding-left: 1rem; text-transform: uppercase; - content: ' [' attr(data-lang) '] ' "\a\a"; - } - // code copy wrapper - .ccw { - position: relative; - } - .ccw:hover { - .cc { - opacity: 1; - } } // code copy button .cc { - opacity: 0; + cursor: pointer; z-index: 9; position: absolute; - right: 9px; - top: 9px; - font-size: .8rem; + top: .3rem; + right: .5rem; + } + .cc:hover { + background: var(--a3); + opacity: 1; } // Table Override, this is used for Zola's linenos and hl_lines code { @@ -1246,6 +1251,11 @@ $syntax: true !default;//syntax highlighting for code blocks @if $icon-angr {.angr { -webkit-mask: functions.icon(angr, "%23000", 3, "none", $ic) ; background: var(--f2) }}//angle right @if $icon-angrr {.angrr { -webkit-mask: functions.icon(angrr, "%23000", 3, "none", $ic) ; background: var(--f2) }}//angle right right @if $icon-angu {.angu { -webkit-mask: functions.icon(angu, "%23000", 3, "none", $ic) ; background: var(--f2) }}//angle up + @if $icon-copy {//copy icons for code blocks + .copy { -webkit-mask: functions.icon(copy, "%23000", 2, "none", $ic) ; background: var(--f2) } + .copy.yes { -webkit-mask: functions.icon(copy-yes, "%23000", 2, "none", $ic) ; background: var(--f2) } + .copy.err { -webkit-mask: functions.icon(copy-err, "%23000", 2, "none", $ic) ; background: var(--f2) } + } @if $icon-search {.search { -webkit-mask: functions.icon(search, "%23000", 3, "none", $ic) ; background: var(--f2) }}//search @if $icon-bitbucket {.bitbucket { background-image: functions.icon(bitbucket, "%2328f", 2, "none", $ic) }} @if $icon-buymeacoffee {.buymeacoffee { background-image: functions.icon(buymeacoffee, "%23777", 1, "%23fd0", $ic) }} diff --git a/static/js/abridge.min.js b/static/js/abridge.min.js index c438a71..4cfe749 100644 --- a/static/js/abridge.min.js +++ b/static/js/abridge.min.js @@ -1 +1 @@ -const items=document.querySelectorAll(".preStyle");items.forEach(e=>{e.rel="stylesheet"}),document.getElementById("mode")&&document.getElementById("mode").addEventListener("click",()=>{document.documentElement.classList.toggle("light"),localStorage.setItem("theme",document.documentElement.classList.contains("light")?"light":"dark")}),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 a,c,e,t,d,h,f,p,m,v,y,S,x,w,b,E,I,C,D,F,k,L,N,_,n;g.version="0.9.5",((lunr=g).utils={}).warn=(n=this,function(e){n.console&&console.warn&&console.warn(e)}),g.utils.toString=function(e){return null==e?"":e.toString()},(g.EventEmitter=function(){this.events={}}).prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),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){var t;this.hasHandler(e)&&(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(e){var t,n;return arguments.length&&null!=e?Array.isArray(e)?(t=(t=e.filter(function(e){return null!=e})).map(function(e){return g.utils.toString(e).toLowerCase()}),n=[],t.forEach(function(e){e=e.split(g.tokenizer.seperator),n=n.concat(e)},this),n):e.toString().trim().toLowerCase().split(g.tokenizer.seperator):[]}).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=[]}).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!=1?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){var 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){if(g.Pipeline.warnIfFunctionNotRegistered(t),-1===(e=this._queue.indexOf(e)))throw new Error("Cannot find existingFn");this._queue.splice(e+1,0,t)},g.Pipeline.prototype.before=function(e,t){if(g.Pipeline.warnIfFunctionNotRegistered(t),-1===(e=this._queue.indexOf(e)))throw new Error("Cannot find existingFn");this._queue.splice(e,0,t)},g.Pipeline.prototype.remove=function(e){-1!==(e=this._queue.indexOf(e))&&this._queue.splice(e,1)},g.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,o=this._queue.length,i=0;i<n;i++){for(var r=e[i],s=0;s<o&&null!=(r=this._queue[s](r,i,e));s++);null!=r&&t.push(r)}return t},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))}).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(r,e){var s;r&&(e=void 0===e||e,s=r[this._ref],this.documentStore.addDoc(s,r),this._fields.forEach(function(e){var t,n=this.pipeline.run(g.tokenizer(r[e])),o=(this.documentStore.addFieldLength(s,e,n.length),{});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:s,tf:i})}},this),e)&&this.eventEmitter.emit("add",r,this)},g.Index.prototype.removeDocByRef=function(e){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){var n;e&&(t=void 0===t||t,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(e,t){if(!e)return[];e="string"==typeof e?{any:e}:JSON.parse(JSON.stringify(e));var n=null;null!=t&&(n=JSON.stringify(t));for(var o=new g.Configuration(n,this.getFields()).get(),i={},r=Object.keys(e),s=0;s<r.length;s++){var u=r[s];i[u]=this.pipeline.run(g.tokenizer(e[u]))}var l,a={};for(l in o){var c=i[l]||i.any;if(c){var d=this.fieldSearch(c,l,o),h=o[l].boost;for(p in d)d[p]=d[p]*h;for(p in d)p in a?a[p]+=d[p]:a[p]=d[p]}}var f,p,m=[];for(p in a)f={ref:p,score:a[p]},this.documentStore.hasDoc(p)&&(f.doc=this.documentStore.getDoc(p)),m.push(f);return m.sort(function(e,t){return t.score-e.score}),m},g.Index.prototype.fieldSearch=function(e,a,t){var c=t[a].bool,n=t[a].expand,t=t[a].boost,d=null,h={};return 0!==t?(e.forEach(function(u){var e=[u],l=(1==n&&(e=this.index[a].expandToken(u)),{});e.forEach(function(e){var t=this.index[a].getDocs(e),n=this.idf(e,a);if(d&&"AND"==c){var o,i={};for(o in d)o in t&&(i[o]=t[o]);t=i}for(o in e==u&&this.fieldSearchStats(h,e,t),t){var r=this.index[a].getTermFrequency(e,o),s=this.documentStore.getFieldLength(o,a),r=r*n*(0!=s?1/Math.sqrt(s):1)*(e!=u?.15*(1-(e.length-u.length)/e.length):1);o in l?l[o]+=r:l[o]=r}},this),d=this.mergeScores(d,l,c)},this),d=this.coordNorm(d,h,e.length)):void 0},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(){var 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}).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++,this.docs[e]=!0===this._save?function(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):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}},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:""},e="[aeiouy]",t="[^aeiou][^aeiouy]*",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]"),m=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,y=/^(.+?)eed$/,S=/^(.+?)(ed|ing)$/,x=/.$/,w=/(at|bl|iz)$/,b=new RegExp("([^aeiouylsz])\\1$"),E=new RegExp("^"+t+e+"[^aeiouwxy]$"),I=/^(.+?[^aeiou])y$/,C=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,D=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,F=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,k=/^(.+?)(s|t)(ion)$/,L=/^(.+?)e$/,N=/ll$/,_=new RegExp("^"+t+e+"[^aeiouwxy]$"),g.Pipeline.registerFunction(g.stemmer=function(e){var t,n,o,i,r,s,u,l;return e.length<3||("y"==(n=e.substr(0,1))&&(e=n.toUpperCase()+e.substr(1)),u=v,(r=m).test(e)?e=e.replace(r,"$1$2"):u.test(e)&&(e=e.replace(u,"$1$2")),u=S,(r=y).test(e)?(l=r.exec(e),(r=d).test(l[1])&&(e=e.replace(r=x,""))):u.test(e)&&(s=(l=u.exec(e))[1],(u=p).test(s))&&(e=s,o=b,i=E,(u=w).test(e)?e+="e":o.test(e)?e=e.replace(r=x,""):i.test(e)&&(e+="e")),(r=I).test(e)&&(e=(s=(l=r.exec(e))[1])+"i"),(r=C).test(e)&&(s=(l=r.exec(e))[1],t=l[2],(r=d).test(s))&&(e=s+a[t]),(r=D).test(e)&&(s=(l=r.exec(e))[1],t=l[2],(r=d).test(s))&&(e=s+c[t]),u=k,(r=F).test(e)?(s=(l=r.exec(e))[1],(r=h).test(s)&&(e=s)):u.test(e)&&(s=(l=u.exec(e))[1]+l[2],(u=h).test(s))&&(e=s),(r=L).test(e)&&(s=(l=r.exec(e))[1],u=f,o=_,(r=h).test(s)||u.test(s)&&!o.test(s))&&(e=s),u=h,(r=N).test(e)&&u.test(e)&&(e=e.replace(r=x,"")),"y"==n&&(e=n.toLowerCase()+e.substr(1))),e},"stemmer"),g.stopWordFilter=function(e){return e&&!0!==g.stopWordFilter.stopWords[e]?e:void 0},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.stopWordFilter.stopWords=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.Pipeline.registerFunction(g.stopWordFilter,"stopWordFilter"),g.Pipeline.registerFunction(g.trimmer=function(e){if(null==e)throw new Error("token should not be undefined");return e.replace(/^\W+/,"").replace(/\W+$/,"")},"trimmer"),(g.InvertedIndex=function(){this.root={docs:{},df:0}}).load=function(e){var t=new this;return t.root=e.root,t},g.InvertedIndex.prototype.addToken=function(e,t,n){for(var n=n||this.root,o=0;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(e){if(!e)return!1;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return!1;t=t[e[n]]}return!0},g.InvertedIndex.prototype.getNode=function(e){if(!e)return null;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return null;t=t[e[n]]}return t},g.InvertedIndex.prototype.getDocs=function(e){return null==(e=this.getNode(e))?{}:e.docs},g.InvertedIndex.prototype.getTermFrequency=function(e,t){return null!=(e=this.getNode(e))&&t in e.docs?e.docs[t].tf:0},g.InvertedIndex.prototype.getDocFreq=function(e){return null==(e=this.getNode(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[];if(t=t||[],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)}}).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(e,t){var n,o,i="OR",r=!1;if(this.reset(),"bool"in e&&(i=e.bool||i),"expand"in e&&(r=e.expand||r),"fields"in e)for(var s in e.fields)-1<t.indexOf(s)?(o=r,null!=(n=e.fields[s]).expand&&(o=n.expand),this.config[s]={boost:n.boost||0===n.boost?n.boost:1,bool:n.bool||i,expand:o}):g.utils.warn("field name in user configuration not found in index instance fields");else this.addAllFields2UserConfig(i,r,t)},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(){for(var e,t=0;t<arguments.length;t++)~this.indexOf(e=arguments[t])||this.elements.splice(this.locationFor(e),0,e);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){for(var t=0,n=this.elements.length,o=n-t,i=t+Math.floor(o/2),r=this.elements[i];1<o;){if(r===e)return i;o=(n=e<r?i:n)-(t=r<e?i:t),i=t+Math.floor(o/2),r=this.elements[i]}return r===e?i:-1},lunr.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,o=n-t,i=t+Math.floor(o/2),r=this.elements[i];1<o;)o=(n=e<r?i:n)-(t=r<e?i:t),i=t+Math.floor(o/2),r=this.elements[i];return e<r?i:r<e?i+1:void 0},lunr.SortedSet.prototype.intersect=function(e){for(var t=new lunr.SortedSet,n=0,o=0,i=this.length,r=e.length,s=this.elements,u=e.elements;!(i-1<n||r-1<o);)s[n]!==u[o]?s[n]<u[o]?n++:s[n]>u[o]&&o++:(t.add(s[n]),n++,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){for(var t,e=this.length>=e.length?(t=this,e):(t=e,this),n=t.clone(),o=0,i=e.toArray();o<i.length;o++)n.add(i[o]);return n},lunr.SortedSet.prototype.toJSON=function(){return this.toArray()},"function"==typeof define&&define.amd?define(function(){return g}):"object"==typeof exports?module.exports=g:this.elasticlunr=g}(),window.onload=function(){function w(e){return e=parseInt(e,16).toString(2),[0,1,2,3,4][Math.ceil(e.length/8)]}var s,r,u,l,c;document.body.contains(document.goSearch)&&(document.goSearch.onsubmit=function(){return goSearchNow()},s=document.getElementById("suggestions"),r=document.getElementById("searchinput"),document.addEventListener("keydown",function(t){if(191===t.keyCode&&"INPUT"!==document.activeElement.tagName&&"TEXTAREA"!==document.activeElement.tagName&&(t.preventDefault(),r.focus(),s.classList.remove("d-none")),27===t.keyCode){r.blur(),s.classList.add("d-none");for(var e=document.getElementById("suggestions");e.firstChild;)e.removeChild(e.firstChild)}var n=s.querySelectorAll("a");if(!s.classList.contains("d-none")&&0!==n.length){var o=[...n],i=o.indexOf(document.activeElement);let e=0;38===t.keyCode?(t.preventDefault(),n[e=0<i?i-1:0].focus()):40===t.keyCode&&(t.preventDefault(),n[e=i+1<o.length?i+1:i].focus())}}),document.addEventListener("click",function(e){s.contains(e.target)||s.classList.add("d-none")}),l=document.documentElement.getAttribute("lang").substring(0,2),"/"==(c=document.querySelector("meta[name='base']").getAttribute("content")).slice(-1)&&(c=c.slice(0,-1)),r.addEventListener("input",async function(){var n,e=this.value.trim(),o=(await(u=void 0===u?fetch(c+"/search_index."+l+".json").then(async function(e){return elasticlunr.Index.load(await e.json())}):u)).search(e,{bool:"OR",fields:{title:{boost:2},body:{boost:1}}}),i=s.childNodes,r=o.length,x=e.split(/\s+/);for(s.classList.remove("d-none"),o.forEach(function(e){""!==e.doc.body&&((n=document.createElement("div")).innerHTML="<a href><span></span><span></span></a>",a=n.querySelector("a"),t=n.querySelector("span:first-child"),d=n.querySelector("span:nth-child(2)"),a.href=e.ref,t.textContent=e.doc.title,d.innerHTML=function(e){var t=x.map(function(e){return elasticlunr.stemmer(e.toLowerCase())}),n=!1,o=0,i=[],r=e.toLowerCase().split(". ");for(f in r){var s,u=r[f].split(/[\s\n]/),l=8;for(s in u){if(0<(g=u[s]).length){for(var a in t)elasticlunr.stemmer(g).startsWith(t[a])&&(l=40,n=!0);i.push([g,l,o]),l=2}o=o+g.length+1}o+=1}if(0===i.length)return void 0!==e.length&&300<e.length?e.substring(0,300)+"...":e;for(var c=[],d=Math.min(i.length,30),h=0,f=0;f<d;f++)h+=i[f][1];for(c.push(h),f=0;f<i.length-d;f++)h=(h-=i[f][1])+i[f+d][1],c.push(h);var p=0;if(n)for(var m=0,f=c.length-1;0<=f;f--)m<c[f]&&(m=c[f],p=f);for(var g,v,y=[],S=i[p][2],f=p;f<p+d;f++)S<(g=i[f])[2]&&(y.push(e.substring(S,g[2])),S=g[2]),40===g[1]&&y.push("<b>"),S=g[2]+g[0].length,40!==g[1]&&12<=g[0].length&&!/^[\x00-\xff]+$/.test(g[0])?(v=function(e){for(var t="",n=!1,o=0,i=0,r=0,s=0;s<e.length;s++){var u=e.codePointAt(s).toString(16);if(n=4<u.length&&++s+1<e.length?"200d"==e.codePointAt(s+1).toString(16):n){if(o+=w(u),s==e.length-1){if(!((i+=o)<=12))break;t+=e.substr(r,s-r+1)}}else if(0!=o){if(!((i=(i+=o)+w(u))<=12))break;t+=e.substr(r,s-r+1),r=s+1,o=0}else{if(!((i+=w(u))<=12))break;u.length<=4?t+=e[s]:t+=e[s-1]+e[s],r=s+1}}return t}(e.substring(g[2],S)),y.push(v)):y.push(e.substring(g[2],S)),40===g[1]&&y.push("</b>");return y.push("…"),y.join("")}(e.doc.body),s.appendChild(n))});i.length>r;)s.removeChild(i[0])},!0),s.addEventListener("click",function(){for(;s.lastChild;)s.removeChild(s.lastChild);return!1},!0),document.goSearch.onsubmit=function(){var e=document.querySelector("main"),t=(window.main||(window.main=e.innerHTML),document.getElementById("suggestions")),n=t.cloneNode(!0),o=(n.id="results",document.createElement("div")),i='<form name="closeSearch"><h2><button type="submit" title="Close Search"><i class="svgs x"></i></button> Results For: '.concat(document.getElementById("searchinput").value,"</h2></form>");return o.innerHTML=i,n.insertBefore(o,n.firstChild),e.innerHTML=n.outerHTML,t.innerHTML="",document.getElementById("searchinput").value="",document.body.contains(document.closeSearch)&&(document.closeSearch.onsubmit=function(){document.querySelector("main").innerHTML=window.main}),!1})},function(){for(var e=document.getElementsByClassName("m-protected"),t=0;t<e.length;t++){var n=e[t].getAttribute("href"),n=atob(n.substring(1));e[t].href="mailto:"+n}}(),function(){function t(e){const t=document.createElement("button");t.className="cc ",t.type="button",t.innerHTML="Copy",t.addEventListener("click",()=>async function(e,t){var n=t.querySelectorAll("table")["length"];let o="";0<n?t.querySelectorAll(":last-child > tr > td:last-child").forEach(e=>{o+=e.innerText}):o=t.querySelector(":last-child > code").innerText;try{"granted"==(result=await navigator.permissions.query({name:"clipboard-write"})).state||"prompt"==result.state?await navigator.clipboard.writeText(o):i(o,t)}catch(e){i(o,t)}finally{e.innerHTML="Copied",setTimeout(function(){e.innerHTML="Copy"},2e3)}}(t,e));var n=document.createElement("div");n.className="ccw",n.appendChild(t),e.parentNode.insertBefore(n,e),n.appendChild(e)}function i(e,t){var n=document.createElement("textArea"),e=(n.contentEditable="true",n.readOnly="false",n.className="copyable-text-area",n.value=e,t.insertBefore(n,t.firstChild),document.createRange()),o=(e.selectNodeContents(n),window.getSelection());o.removeAllRanges(),o.addRange(e),n.setSelectionRange(0,999999),document.execCommand("copy"),t.removeChild(n)}document.querySelectorAll("pre").forEach(e=>t(e))}();
\ No newline at end of file +const items=document.querySelectorAll(".preStyle"),changeIcon=(items.forEach(e=>{e.rel="stylesheet"}),document.getElementById("mode")&&document.getElementById("mode").addEventListener("click",()=>{document.documentElement.classList.toggle("light"),localStorage.setItem("theme",document.documentElement.classList.contains("light")?"light":"dark")}),!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 a,c,e,t,d,h,f,p,m,v,y,S,x,b,w,I,E,C,D,F,k,L,_,N,n;g.version="0.9.5",((lunr=g).utils={}).warn=(n=this,function(e){n.console&&console.warn&&console.warn(e)}),g.utils.toString=function(e){return null==e?"":e.toString()},(g.EventEmitter=function(){this.events={}}).prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),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){var t;this.hasHandler(e)&&(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(e){var t,n;return arguments.length&&null!=e?Array.isArray(e)?(t=(t=e.filter(function(e){return null!=e})).map(function(e){return g.utils.toString(e).toLowerCase()}),n=[],t.forEach(function(e){e=e.split(g.tokenizer.seperator),n=n.concat(e)},this),n):e.toString().trim().toLowerCase().split(g.tokenizer.seperator):[]}).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=[]}).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!=1?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){var 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){if(g.Pipeline.warnIfFunctionNotRegistered(t),-1===(e=this._queue.indexOf(e)))throw new Error("Cannot find existingFn");this._queue.splice(e+1,0,t)},g.Pipeline.prototype.before=function(e,t){if(g.Pipeline.warnIfFunctionNotRegistered(t),-1===(e=this._queue.indexOf(e)))throw new Error("Cannot find existingFn");this._queue.splice(e,0,t)},g.Pipeline.prototype.remove=function(e){-1!==(e=this._queue.indexOf(e))&&this._queue.splice(e,1)},g.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,o=this._queue.length,i=0;i<n;i++){for(var r=e[i],s=0;s<o&&null!=(r=this._queue[s](r,i,e));s++);null!=r&&t.push(r)}return t},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))}).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(r,e){var s;r&&(e=void 0===e||e,s=r[this._ref],this.documentStore.addDoc(s,r),this._fields.forEach(function(e){var t,n=this.pipeline.run(g.tokenizer(r[e])),o=(this.documentStore.addFieldLength(s,e,n.length),{});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:s,tf:i})}},this),e)&&this.eventEmitter.emit("add",r,this)},g.Index.prototype.removeDocByRef=function(e){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){var n;e&&(t=void 0===t||t,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(e,t){if(!e)return[];e="string"==typeof e?{any:e}:JSON.parse(JSON.stringify(e));var n=null;null!=t&&(n=JSON.stringify(t));for(var o=new g.Configuration(n,this.getFields()).get(),i={},r=Object.keys(e),s=0;s<r.length;s++){var u=r[s];i[u]=this.pipeline.run(g.tokenizer(e[u]))}var l,a={};for(l in o){var c=i[l]||i.any;if(c){var d=this.fieldSearch(c,l,o),h=o[l].boost;for(p in d)d[p]=d[p]*h;for(p in d)p in a?a[p]+=d[p]:a[p]=d[p]}}var f,p,m=[];for(p in a)f={ref:p,score:a[p]},this.documentStore.hasDoc(p)&&(f.doc=this.documentStore.getDoc(p)),m.push(f);return m.sort(function(e,t){return t.score-e.score}),m},g.Index.prototype.fieldSearch=function(e,a,t){var c=t[a].bool,n=t[a].expand,t=t[a].boost,d=null,h={};return 0!==t?(e.forEach(function(u){var e=[u],l=(1==n&&(e=this.index[a].expandToken(u)),{});e.forEach(function(e){var t=this.index[a].getDocs(e),n=this.idf(e,a);if(d&&"AND"==c){var o,i={};for(o in d)o in t&&(i[o]=t[o]);t=i}for(o in e==u&&this.fieldSearchStats(h,e,t),t){var r=this.index[a].getTermFrequency(e,o),s=this.documentStore.getFieldLength(o,a),r=r*n*(0!=s?1/Math.sqrt(s):1)*(e!=u?.15*(1-(e.length-u.length)/e.length):1);o in l?l[o]+=r:l[o]=r}},this),d=this.mergeScores(d,l,c)},this),d=this.coordNorm(d,h,e.length)):void 0},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(){var 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}).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++,this.docs[e]=!0===this._save?function(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):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}},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:""},e="[aeiouy]",t="[^aeiou][^aeiouy]*",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]"),m=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,y=/^(.+?)eed$/,S=/^(.+?)(ed|ing)$/,x=/.$/,b=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),I=new RegExp("^"+t+e+"[^aeiouwxy]$"),E=/^(.+?[^aeiou])y$/,C=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,D=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,F=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,k=/^(.+?)(s|t)(ion)$/,L=/^(.+?)e$/,_=/ll$/,N=new RegExp("^"+t+e+"[^aeiouwxy]$"),g.Pipeline.registerFunction(g.stemmer=function(e){var t,n,o,i,r,s,u,l;return e.length<3||("y"==(n=e.substr(0,1))&&(e=n.toUpperCase()+e.substr(1)),u=v,(r=m).test(e)?e=e.replace(r,"$1$2"):u.test(e)&&(e=e.replace(u,"$1$2")),u=S,(r=y).test(e)?(l=r.exec(e),(r=d).test(l[1])&&(e=e.replace(r=x,""))):u.test(e)&&(s=(l=u.exec(e))[1],(u=p).test(s))&&(e=s,o=w,i=I,(u=b).test(e)?e+="e":o.test(e)?e=e.replace(r=x,""):i.test(e)&&(e+="e")),(r=E).test(e)&&(e=(s=(l=r.exec(e))[1])+"i"),(r=C).test(e)&&(s=(l=r.exec(e))[1],t=l[2],(r=d).test(s))&&(e=s+a[t]),(r=D).test(e)&&(s=(l=r.exec(e))[1],t=l[2],(r=d).test(s))&&(e=s+c[t]),u=k,(r=F).test(e)?(s=(l=r.exec(e))[1],(r=h).test(s)&&(e=s)):u.test(e)&&(s=(l=u.exec(e))[1]+l[2],(u=h).test(s))&&(e=s),(r=L).test(e)&&(s=(l=r.exec(e))[1],u=f,o=N,(r=h).test(s)||u.test(s)&&!o.test(s))&&(e=s),u=h,(r=_).test(e)&&u.test(e)&&(e=e.replace(r=x,"")),"y"==n&&(e=n.toLowerCase()+e.substr(1))),e},"stemmer"),g.stopWordFilter=function(e){return e&&!0!==g.stopWordFilter.stopWords[e]?e:void 0},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.stopWordFilter.stopWords=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.Pipeline.registerFunction(g.stopWordFilter,"stopWordFilter"),g.Pipeline.registerFunction(g.trimmer=function(e){if(null==e)throw new Error("token should not be undefined");return e.replace(/^\W+/,"").replace(/\W+$/,"")},"trimmer"),(g.InvertedIndex=function(){this.root={docs:{},df:0}}).load=function(e){var t=new this;return t.root=e.root,t},g.InvertedIndex.prototype.addToken=function(e,t,n){for(var n=n||this.root,o=0;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(e){if(!e)return!1;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return!1;t=t[e[n]]}return!0},g.InvertedIndex.prototype.getNode=function(e){if(!e)return null;for(var t=this.root,n=0;n<e.length;n++){if(!t[e[n]])return null;t=t[e[n]]}return t},g.InvertedIndex.prototype.getDocs=function(e){return null==(e=this.getNode(e))?{}:e.docs},g.InvertedIndex.prototype.getTermFrequency=function(e,t){return null!=(e=this.getNode(e))&&t in e.docs?e.docs[t].tf:0},g.InvertedIndex.prototype.getDocFreq=function(e){return null==(e=this.getNode(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[];if(t=t||[],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)}}).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(e,t){var n,o,i="OR",r=!1;if(this.reset(),"bool"in e&&(i=e.bool||i),"expand"in e&&(r=e.expand||r),"fields"in e)for(var s in e.fields)-1<t.indexOf(s)?(o=r,null!=(n=e.fields[s]).expand&&(o=n.expand),this.config[s]={boost:n.boost||0===n.boost?n.boost:1,bool:n.bool||i,expand:o}):g.utils.warn("field name in user configuration not found in index instance fields");else this.addAllFields2UserConfig(i,r,t)},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(){for(var e,t=0;t<arguments.length;t++)~this.indexOf(e=arguments[t])||this.elements.splice(this.locationFor(e),0,e);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){for(var t=0,n=this.elements.length,o=n-t,i=t+Math.floor(o/2),r=this.elements[i];1<o;){if(r===e)return i;o=(n=e<r?i:n)-(t=r<e?i:t),i=t+Math.floor(o/2),r=this.elements[i]}return r===e?i:-1},lunr.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,o=n-t,i=t+Math.floor(o/2),r=this.elements[i];1<o;)o=(n=e<r?i:n)-(t=r<e?i:t),i=t+Math.floor(o/2),r=this.elements[i];return e<r?i:r<e?i+1:void 0},lunr.SortedSet.prototype.intersect=function(e){for(var t=new lunr.SortedSet,n=0,o=0,i=this.length,r=e.length,s=this.elements,u=e.elements;!(i-1<n||r-1<o);)s[n]!==u[o]?s[n]<u[o]?n++:s[n]>u[o]&&o++:(t.add(s[n]),n++,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){for(var t,e=this.length>=e.length?(t=this,e):(t=e,this),n=t.clone(),o=0,i=e.toArray();o<i.length;o++)n.add(i[o]);return n},lunr.SortedSet.prototype.toJSON=function(){return this.toArray()},"function"==typeof define&&define.amd?define(function(){return g}):"object"==typeof exports?module.exports=g:this.elasticlunr=g}(),window.onload=function(){function b(e){return e=parseInt(e,16).toString(2),[0,1,2,3,4][Math.ceil(e.length/8)]}var s,r,u,l,c;document.body.contains(document.goSearch)&&(document.goSearch.onsubmit=function(){return goSearchNow()},s=document.getElementById("suggestions"),r=document.getElementById("searchinput"),document.addEventListener("keydown",function(t){if(191===t.keyCode&&"INPUT"!==document.activeElement.tagName&&"TEXTAREA"!==document.activeElement.tagName&&(t.preventDefault(),r.focus(),s.classList.remove("d-none")),27===t.keyCode){r.blur(),s.classList.add("d-none");for(var e=document.getElementById("suggestions");e.firstChild;)e.removeChild(e.firstChild)}var n=s.querySelectorAll("a");if(!s.classList.contains("d-none")&&0!==n.length){var o=[...n],i=o.indexOf(document.activeElement);let e=0;38===t.keyCode?(t.preventDefault(),n[e=0<i?i-1:0].focus()):40===t.keyCode&&(t.preventDefault(),n[e=i+1<o.length?i+1:i].focus())}}),document.addEventListener("click",function(e){s.contains(e.target)||s.classList.add("d-none")}),l=document.documentElement.getAttribute("lang").substring(0,2),"/"==(c=document.querySelector("meta[name='base']").getAttribute("content")).slice(-1)&&(c=c.slice(0,-1)),r.addEventListener("input",async function(){var n,e=this.value.trim(),o=(await(u=void 0===u?fetch(c+"/search_index."+l+".json").then(async function(e){return elasticlunr.Index.load(await e.json())}):u)).search(e,{bool:"OR",fields:{title:{boost:2},body:{boost:1}}}),i=s.childNodes,r=o.length,x=e.split(/\s+/);for(s.classList.remove("d-none"),o.forEach(function(e){""!==e.doc.body&&((n=document.createElement("div")).innerHTML="<a href><span></span><span></span></a>",a=n.querySelector("a"),t=n.querySelector("span:first-child"),d=n.querySelector("span:nth-child(2)"),a.href=e.ref,t.textContent=e.doc.title,d.innerHTML=function(e){var t=x.map(function(e){return elasticlunr.stemmer(e.toLowerCase())}),n=!1,o=0,i=[],r=e.toLowerCase().split(". ");for(f in r){var s,u=r[f].split(/[\s\n]/),l=8;for(s in u){if(0<(g=u[s]).length){for(var a in t)elasticlunr.stemmer(g).startsWith(t[a])&&(l=40,n=!0);i.push([g,l,o]),l=2}o=o+g.length+1}o+=1}if(0===i.length)return void 0!==e.length&&300<e.length?e.substring(0,300)+"...":e;for(var c=[],d=Math.min(i.length,30),h=0,f=0;f<d;f++)h+=i[f][1];for(c.push(h),f=0;f<i.length-d;f++)h=(h-=i[f][1])+i[f+d][1],c.push(h);var p=0;if(n)for(var m=0,f=c.length-1;0<=f;f--)m<c[f]&&(m=c[f],p=f);for(var g,v,y=[],S=i[p][2],f=p;f<p+d;f++)S<(g=i[f])[2]&&(y.push(e.substring(S,g[2])),S=g[2]),40===g[1]&&y.push("<b>"),S=g[2]+g[0].length,40!==g[1]&&12<=g[0].length&&!/^[\x00-\xff]+$/.test(g[0])?(v=function(e){for(var t="",n=!1,o=0,i=0,r=0,s=0;s<e.length;s++){var u=e.codePointAt(s).toString(16);if(n=4<u.length&&++s+1<e.length?"200d"==e.codePointAt(s+1).toString(16):n){if(o+=b(u),s==e.length-1){if(!((i+=o)<=12))break;t+=e.substr(r,s-r+1)}}else if(0!=o){if(!((i=(i+=o)+b(u))<=12))break;t+=e.substr(r,s-r+1),r=s+1,o=0}else{if(!((i+=b(u))<=12))break;u.length<=4?t+=e[s]:t+=e[s-1]+e[s],r=s+1}}return t}(e.substring(g[2],S)),y.push(v)):y.push(e.substring(g[2],S)),40===g[1]&&y.push("</b>");return y.push("…"),y.join("")}(e.doc.body),s.appendChild(n))});i.length>r;)s.removeChild(i[0])},!0),s.addEventListener("click",function(){for(;s.lastChild;)s.removeChild(s.lastChild);return!1},!0),document.goSearch.onsubmit=function(){var e=document.querySelector("main"),t=(window.main||(window.main=e.innerHTML),document.getElementById("suggestions")),n=t.cloneNode(!0),o=(n.id="results",document.createElement("div")),i='<form name="closeSearch"><h2><button type="submit" title="Close Search"><i class="svgs x"></i></button> Results For: '.concat(document.getElementById("searchinput").value,"</h2></form>");return o.innerHTML=i,n.insertBefore(o,n.firstChild),e.innerHTML=n.outerHTML,t.innerHTML="",document.getElementById("searchinput").value="",document.body.contains(document.closeSearch)&&(document.closeSearch.onsubmit=function(){document.querySelector("main").innerHTML=window.main}),!1})},!function(){for(var e=document.getElementsByClassName("m-protected"),t=0;t<e.length;t++){var n=e[t].getAttribute("href"),n=atob(n.substring(1));e[t].href="mailto:"+n}}(),(e,t)=>{e.classList.add(t),setTimeout(()=>e.classList.remove(t),2500)}),copyCodeAndChangeIcon=async(t,e)=>{e=(e.querySelector("table")?getTableCode:getNonTableCode)(e);try{await navigator.clipboard.writeText(e),changeIcon(t,"yes")}catch(e){changeIcon(t,"err")}},getNonTableCode=e=>[...e.querySelectorAll("code")].map(e=>e.textContent).join(""),getTableCode=e=>[...e.querySelectorAll("tr")].map(e=>e.querySelector("td:last-child")?.innerText??"").join("");document.querySelectorAll("pre").forEach(e=>{const t=document.createElement("div");t.className="cc svgs svgh copy",t.innerHTML=" ",e.prepend(t),t.addEventListener("click",()=>copyCodeAndChangeIcon(t,e))});
\ No newline at end of file diff --git a/static/js/codecopy.js b/static/js/codecopy.js index c1f3a75..9e00c79 100644 --- a/static/js/codecopy.js +++ b/static/js/codecopy.js @@ -1,76 +1,34 @@ -// https://aaronluna.dev/blog/add-copy-button-to-code-blocks-hugo-chroma/ -// Further modified for Zola by Jieiku: https://github.com/Jieiku -(function() { - // create copy button - function ccb(highlightDiv) { - const button = document.createElement("button"); - button.className = "cc "; - button.type = "button"; - button.innerHTML = "Copy"; - button.addEventListener("click", () => - ccc(button, highlightDiv) - ); +const changeIcon = (copyDiv, className) => { + copyDiv.classList.add(className); + setTimeout(() => copyDiv.classList.remove(className), 2500); +}; - // addCopyButtonToDom - const wrapper = document.createElement("div"); - wrapper.className = "ccw"; - wrapper.appendChild(button); - highlightDiv.parentNode.insertBefore(wrapper, highlightDiv); - wrapper.appendChild(highlightDiv); - } - - // copy code clipboard - async function ccc(button, highlightDiv) { - //look for table, if so do it different - const { length } = highlightDiv.querySelectorAll("table"); - let codeToCopy = ""; - if (length > 0) { - const items = highlightDiv.querySelectorAll(":last-child > tr > td:last-child"); - items.forEach(item => { - codeToCopy = codeToCopy + item.innerText; - //console.log(codeToCopy); - }); - } else { - codeToCopy = highlightDiv.querySelector(":last-child > code").innerText; - } +const copyCodeAndChangeIcon = async (copyDiv, block) => { + const code = block.querySelector('table') ? getTableCode(block) : getNonTableCode(block); try { - result = await navigator.permissions.query({ name: "clipboard-write" }); - if (result.state == "granted" || result.state == "prompt") { - await navigator.clipboard.writeText(codeToCopy); - } else { - cce(codeToCopy, highlightDiv);//copyCodeBlockExecCommand - } - } catch (_) { - cce(codeToCopy, highlightDiv);//copyCodeBlockExecCommand - } finally { - //codeWasCopied - //button.blur(); - button.innerHTML = "Copied"; - setTimeout(function () { - button.innerHTML = "Copy"; - }, 2000); + await navigator.clipboard.writeText(code); + changeIcon(copyDiv, "yes"); + } catch (error) { + changeIcon(copyDiv, "err"); } - } +}; + +const getNonTableCode = (block) => { + return [...block.querySelectorAll('code')] + .map(code => code.textContent) + .join(''); +}; - //copyCodeBlockExecCommand - function cce(codeToCopy, highlightDiv) { - const textArea = document.createElement("textArea"); - textArea.contentEditable = "true"; - textArea.readOnly = "false"; - textArea.className = "copyable-text-area"; - textArea.value = codeToCopy; - highlightDiv.insertBefore(textArea, highlightDiv.firstChild); - const range = document.createRange(); - range.selectNodeContents(textArea); - const sel = window.getSelection(); - sel.removeAllRanges(); - sel.addRange(range); - textArea.setSelectionRange(0, 999999); - document.execCommand("copy"); - highlightDiv.removeChild(textArea); - } +const getTableCode = (block) => { + return [...block.querySelectorAll('tr')] + .map(row => row.querySelector('td:last-child')?.innerText ?? '') + .join(''); +}; - document - .querySelectorAll("pre") - .forEach((highlightDiv) => ccb(highlightDiv)); -})();
\ No newline at end of file +document.querySelectorAll("pre").forEach((block) => { + const copyDiv = document.createElement("div"); + copyDiv.className = "cc svgs svgh copy"; + copyDiv.innerHTML = " "; + block.prepend(copyDiv); + copyDiv.addEventListener("click", () => copyCodeAndChangeIcon(copyDiv, block));; +}); diff --git a/static/js/elasticlunr.js b/static/js/elasticlunr.js deleted file mode 100644 index d96ce65..0000000 --- a/static/js/elasticlunr.js +++ /dev/null @@ -1,691 +0,0 @@ -/** - * elasticlunr - http://weixsong.github.io - * Lightweight full-text search engine in Javascript for browser search and offline search. - 0.9.6 - * - * Copyright (C) 2017 Oliver Nightingale - * Copyright (C) 2017 Wei Song - * MIT Licensed - * @license - */ -! function() { - function e(e) { - if (null === e || "object" != typeof e) return e; - var t = e.constructor(); - for (var n in e) e.hasOwnProperty(n) && (t[n] = e[n]); - return t - } - var t = function(e) { - var n = new t.Index; - return n.pipeline.add(t.trimmer, t.stopWordFilter, t.stemmer), e && e.call(n, n), n - }; - t.version = "0.9.5", lunr = t, t.utils = {}, t.utils.warn = function(e) { - return function(t) { - e.console && console.warn && console.warn(t) - } - }(this), t.utils.toString = function(e) { - return void 0 === e || null === e ? "" : e.toString() - }, t.EventEmitter = function() { - this.events = {} - }, t.EventEmitter.prototype.addListener = function() { - var e = Array.prototype.slice.call(arguments), - t = e.pop(), - n = e; - if ("function" != typeof t) throw new TypeError("last argument must be a function"); - n.forEach(function(e) { - this.hasHandler(e) || (this.events[e] = []), this.events[e].push(t) - }, this) - }, t.EventEmitter.prototype.removeListener = function(e, t) { - if (this.hasHandler(e)) { - var n = this.events[e].indexOf(t); - 1 !== n && (this.events[e].splice(n, 1), 0 == this.events[e].length && delete this.events[e]) - } - }, t.EventEmitter.prototype.emit = function(e) { - if (this.hasHandler(e)) { - var t = Array.prototype.slice.call(arguments, 1); - this.events[e].forEach(function(e) { - e.apply(void 0, t) - }, this) - } - }, t.EventEmitter.prototype.hasHandler = function(e) { - return e in this.events - }, t.tokenizer = function(e) { - if (!arguments.length || null === e || void 0 === e) return []; - if (Array.isArray(e)) { - var n = e.filter(function(e) { - return null === e || void 0 === e ? !1 : !0 - }); - n = n.map(function(e) { - return t.utils.toString(e).toLowerCase() - }); - var i = []; - return n.forEach(function(e) { - var n = e.split(t.tokenizer.seperator); - i = i.concat(n) - }, this), i - } - return e.toString().trim().toLowerCase().split(t.tokenizer.seperator) - }, t.tokenizer.defaultSeperator = /[\s\-]+/, t.tokenizer.seperator = t.tokenizer.defaultSeperator, t.tokenizer.setSeperator = function(e) { - null !== e && void 0 !== e && "object" == typeof e && (t.tokenizer.seperator = e) - }, t.tokenizer.resetSeperator = function() { - t.tokenizer.seperator = t.tokenizer.defaultSeperator - }, t.tokenizer.getSeperator = function() { - return t.tokenizer.seperator - }, t.Pipeline = function() { - this._queue = [] - }, t.Pipeline.registeredFunctions = {}, t.Pipeline.registerFunction = function(e, n) { - n in t.Pipeline.registeredFunctions && t.utils.warn("Overwriting existing registered function: " + n), e.label = n, t.Pipeline.registeredFunctions[n] = e - }, t.Pipeline.getRegisteredFunction = function(e) { - return e in t.Pipeline.registeredFunctions != !0 ? null : t.Pipeline.registeredFunctions[e] - }, t.Pipeline.warnIfFunctionNotRegistered = function(e) { - var n = e.label && e.label in this.registeredFunctions; - n || t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n", e) - }, t.Pipeline.load = function(e) { - var n = new t.Pipeline; - return e.forEach(function(e) { - var i = t.Pipeline.getRegisteredFunction(e); - if (!i) throw new Error("Cannot load un-registered function: " + e); - n.add(i) - }), n - }, t.Pipeline.prototype.add = function() { - var e = Array.prototype.slice.call(arguments); - e.forEach(function(e) { - t.Pipeline.warnIfFunctionNotRegistered(e), this._queue.push(e) - }, this) - }, t.Pipeline.prototype.after = function(e, n) { - t.Pipeline.warnIfFunctionNotRegistered(n); - var i = this._queue.indexOf(e); - if (-1 === i) throw new Error("Cannot find existingFn"); - this._queue.splice(i + 1, 0, n) - }, t.Pipeline.prototype.before = function(e, n) { - t.Pipeline.warnIfFunctionNotRegistered(n); - var i = this._queue.indexOf(e); - if (-1 === i) throw new Error("Cannot find existingFn"); - this._queue.splice(i, 0, n) - }, t.Pipeline.prototype.remove = function(e) { - var t = this._queue.indexOf(e); - 1 !== t && this._queue.splice(t, 1) - }, t.Pipeline.prototype.run = function(e) { - for (var t = [], n = e.length, i = this._queue.length, o = 0; n > o; o++) { - for (var r = e[o], s = 0; i > s && (r = this._queue[s](r, o, e), void 0 !== r && null !== r); s++); - void 0 !== r && null !== r && t.push(r) - } - return t - }, t.Pipeline.prototype.reset = function() { - this._queue = [] - }, t.Pipeline.prototype.get = function() { - return this._queue - }, t.Pipeline.prototype.toJSON = function() { - return this._queue.map(function(e) { - return t.Pipeline.warnIfFunctionNotRegistered(e), e.label - }) - }, t.Index = function() { - this._fields = [], this._ref = "id", this.pipeline = new t.Pipeline, this.documentStore = new t.DocumentStore, this.index = {}, this.eventEmitter = new t.EventEmitter, this._idfCache = {}, this.on("add", "remove", "update", function() { - this._idfCache = {} - }.bind(this)) - }, t.Index.prototype.on = function() { - var e = Array.prototype.slice.call(arguments); - return this.eventEmitter.addListener.apply(this.eventEmitter, e) - }, t.Index.prototype.off = function(e, t) { - return this.eventEmitter.removeListener(e, t) - }, t.Index.load = function(e) { - e.version !== t.version && t.utils.warn("version mismatch: current " + t.version + " importing " + e.version); - var n = new this; - n._fields = e.fields, n._ref = e.ref, n.documentStore = t.DocumentStore.load(e.documentStore), n.pipeline = t.Pipeline.load(e.pipeline), n.index = {}; - for (var i in e.index) n.index[i] = t.InvertedIndex.load(e.index[i]); - return n - }, t.Index.prototype.addField = function(e) { - return this._fields.push(e), this.index[e] = new t.InvertedIndex, this - }, t.Index.prototype.setRef = function(e) { - return this._ref = e, this - }, t.Index.prototype.saveDocument = function(e) { - return this.documentStore = new t.DocumentStore(e), this - }, t.Index.prototype.addDoc = function(e, n) { - if (e) { - var n = void 0 === n ? !0 : n, - i = e[this._ref]; - this.documentStore.addDoc(i, e), this._fields.forEach(function(n) { - var o = this.pipeline.run(t.tokenizer(e[n])); - this.documentStore.addFieldLength(i, n, o.length); - var r = {}; - o.forEach(function(e) { - e in r ? r[e] += 1 : r[e] = 1 - }, this); - for (var s in r) { - var u = r[s]; - u = Math.sqrt(u), this.index[n].addToken(s, { - ref: i, - tf: u - }) - } - }, this), n && this.eventEmitter.emit("add", e, this) - } - }, t.Index.prototype.removeDocByRef = function(e) { - if (e && this.documentStore.isDocStored() !== !1 && this.documentStore.hasDoc(e)) { - var t = this.documentStore.getDoc(e); - this.removeDoc(t, !1) - } - }, t.Index.prototype.removeDoc = function(e, n) { - if (e) { - var n = void 0 === n ? !0 : n, - i = e[this._ref]; - this.documentStore.hasDoc(i) && (this.documentStore.removeDoc(i), this._fields.forEach(function(n) { - var o = this.pipeline.run(t.tokenizer(e[n])); - o.forEach(function(e) { - this.index[n].removeToken(e, i) - }, this) - }, this), n && this.eventEmitter.emit("remove", e, this)) - } - }, t.Index.prototype.updateDoc = function(e, t) { - var t = void 0 === t ? !0 : t; - this.removeDocByRef(e[this._ref], !1), this.addDoc(e, !1), t && this.eventEmitter.emit("update", e, this) - }, t.Index.prototype.idf = function(e, t) { - var n = "@" + t + "/" + e; - if (Object.prototype.hasOwnProperty.call(this._idfCache, n)) return this._idfCache[n]; - var i = this.index[t].getDocFreq(e), - o = 1 + Math.log(this.documentStore.length / (i + 1)); - return this._idfCache[n] = o, o - }, t.Index.prototype.getFields = function() { - return this._fields.slice() - }, t.Index.prototype.search = function(e, n) { - if (!e) return []; - e = "string" == typeof e ? { - any: e - } : JSON.parse(JSON.stringify(e)); - var i = null; - null != n && (i = JSON.stringify(n)); - for (var o = new t.Configuration(i, this.getFields()).get(), r = {}, s = Object.keys(e), u = 0; u < s.length; u++) { - var a = s[u]; - r[a] = this.pipeline.run(t.tokenizer(e[a])) - } - var l = {}; - for (var c in o) { - var d = r[c] || r.any; - if (d) { - var f = this.fieldSearch(d, c, o), - h = o[c].boost; - for (var p in f) f[p] = f[p] * h; - for (var p in f) p in l ? l[p] += f[p] : l[p] = f[p] - } - } - var v, g = []; - for (var p in l) v = { - ref: p, - score: l[p] - }, this.documentStore.hasDoc(p) && (v.doc = this.documentStore.getDoc(p)), g.push(v); - return g.sort(function(e, t) { - return t.score - e.score - }), g - }, t.Index.prototype.fieldSearch = function(e, t, n) { - var i = n[t].bool, - o = n[t].expand, - r = n[t].boost, - s = null, - u = {}; - return 0 !== r ? (e.forEach(function(e) { - var n = [e]; - 1 == o && (n = this.index[t].expandToken(e)); - var r = {}; - n.forEach(function(n) { - var o = this.index[t].getDocs(n), - a = this.idf(n, t); - if (s && "AND" == i) { - var l = {}; - for (var c in s) c in o && (l[c] = o[c]); - o = l - } - n == e && this.fieldSearchStats(u, n, o); - for (var c in o) { - var d = this.index[t].getTermFrequency(n, c), - f = this.documentStore.getFieldLength(c, t), - h = 1; - 0 != f && (h = 1 / Math.sqrt(f)); - var p = 1; - n != e && (p = .15 * (1 - (n.length - e.length) / n.length)); - var v = d * a * h * p; - c in r ? r[c] += v : r[c] = v - } - }, this), s = this.mergeScores(s, r, i) - }, this), s = this.coordNorm(s, u, e.length)) : void 0 - }, t.Index.prototype.mergeScores = function(e, t, n) { - if (!e) return t; - if ("AND" == n) { - var i = {}; - for (var o in t) o in e && (i[o] = e[o] + t[o]); - return i - } - for (var o in t) o in e ? e[o] += t[o] : e[o] = t[o]; - return e - }, t.Index.prototype.fieldSearchStats = function(e, t, n) { - for (var i in n) i in e ? e[i].push(t) : e[i] = [t] - }, t.Index.prototype.coordNorm = function(e, t, n) { - for (var i in e) - if (i in t) { - var o = t[i].length; - e[i] = e[i] * o / n - } - return e - }, t.Index.prototype.toJSON = function() { - var e = {}; - return this._fields.forEach(function(t) { - e[t] = this.index[t].toJSON() - }, this), { - version: t.version, - fields: this._fields, - ref: this._ref, - documentStore: this.documentStore.toJSON(), - index: e, - pipeline: this.pipeline.toJSON() - } - }, t.Index.prototype.use = function(e) { - var t = Array.prototype.slice.call(arguments, 1); - t.unshift(this), e.apply(this, t) - }, t.DocumentStore = function(e) { - this._save = null === e || void 0 === e ? !0 : e, this.docs = {}, this.docInfo = {}, this.length = 0 - }, t.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 - }, t.DocumentStore.prototype.isDocStored = function() { - return this._save - }, t.DocumentStore.prototype.addDoc = function(t, n) { - this.hasDoc(t) || this.length++, this.docs[t] = this._save === !0 ? e(n) : null - }, t.DocumentStore.prototype.getDoc = function(e) { - return this.hasDoc(e) === !1 ? null : this.docs[e] - }, t.DocumentStore.prototype.hasDoc = function(e) { - return e in this.docs - }, t.DocumentStore.prototype.removeDoc = function(e) { - this.hasDoc(e) && (delete this.docs[e], delete this.docInfo[e], this.length--) - }, t.DocumentStore.prototype.addFieldLength = function(e, t, n) { - null !== e && void 0 !== e && 0 != this.hasDoc(e) && (this.docInfo[e] || (this.docInfo[e] = {}), this.docInfo[e][t] = n) - }, t.DocumentStore.prototype.updateFieldLength = function(e, t, n) { - null !== e && void 0 !== e && 0 != this.hasDoc(e) && this.addFieldLength(e, t, n) - }, t.DocumentStore.prototype.getFieldLength = function(e, t) { - return null === e || void 0 === e ? 0 : e in this.docs && t in this.docInfo[e] ? this.docInfo[e][t] : 0 - }, t.DocumentStore.prototype.toJSON = function() { - return { - docs: this.docs, - docInfo: this.docInfo, - length: this.length, - save: this._save - } - }, t.stemmer = function() { - var e = { - 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" - }, - t = { - icate: "ic", - ative: "", - alize: "al", - iciti: "ic", - ical: "ic", - ful: "", - ness: "" - }, - n = "[^aeiou]", - i = "[aeiouy]", - o = n + "[^aeiouy]*", - r = i + "[aeiou]*", - s = "^(" + o + ")?" + r + o, - u = "^(" + o + ")?" + r + o + "(" + r + ")?$", - a = "^(" + o + ")?" + r + o + r + o, - l = "^(" + o + ")?" + i, - c = new RegExp(s), - d = new RegExp(a), - f = new RegExp(u), - h = new RegExp(l), - p = /^(.+?)(ss|i)es$/, - v = /^(.+?)([^s])s$/, - g = /^(.+?)eed$/, - m = /^(.+?)(ed|ing)$/, - y = /.$/, - S = /(at|bl|iz)$/, - x = new RegExp("([^aeiouylsz])\\1$"), - w = new RegExp("^" + o + i + "[^aeiouwxy]$"), - I = /^(.+?[^aeiou])y$/, - b = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/, - E = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/, - D = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/, - F = /^(.+?)(s|t)(ion)$/, - _ = /^(.+?)e$/, - P = /ll$/, - k = new RegExp("^" + o + i + "[^aeiouwxy]$"), - z = function(n) { - var i, o, r, s, u, a, l; - if (n.length < 3) return n; - if (r = n.substr(0, 1), "y" == r && (n = r.toUpperCase() + n.substr(1)), s = p, u = v, s.test(n) ? n = n.replace(s, "$1$2") : u.test(n) && (n = n.replace(u, "$1$2")), s = g, u = m, s.test(n)) { - var z = s.exec(n); - s = c, s.test(z[1]) && (s = y, n = n.replace(s, "")) - } else if (u.test(n)) { - var z = u.exec(n); - i = z[1], u = h, u.test(i) && (n = i, u = S, a = x, l = w, u.test(n) ? n += "e" : a.test(n) ? (s = y, n = n.replace(s, "")) : l.test(n) && (n += "e")) - } - if (s = I, s.test(n)) { - var z = s.exec(n); - i = z[1], n = i + "i" - } - if (s = b, s.test(n)) { - var z = s.exec(n); - i = z[1], o = z[2], s = c, s.test(i) && (n = i + e[o]) - } - if (s = E, s.test(n)) { - var z = s.exec(n); - i = z[1], o = z[2], s = c, s.test(i) && (n = i + t[o]) - } - if (s = D, u = F, s.test(n)) { - var z = s.exec(n); - i = z[1], s = d, s.test(i) && (n = i) - } else if (u.test(n)) { - var z = u.exec(n); - i = z[1] + z[2], u = d, u.test(i) && (n = i) - } - if (s = _, s.test(n)) { - var z = s.exec(n); - i = z[1], s = d, u = f, a = k, (s.test(i) || u.test(i) && !a.test(i)) && (n = i) - } - return s = P, u = d, s.test(n) && u.test(n) && (s = y, n = n.replace(s, "")), "y" == r && (n = r.toLowerCase() + n.substr(1)), n - }; - return z - }(), t.Pipeline.registerFunction(t.stemmer, "stemmer"), t.stopWordFilter = function(e) { - return e && t.stopWordFilter.stopWords[e] !== !0 ? e : void 0 - }, t.clearStopWords = function() { - t.stopWordFilter.stopWords = {} - }, t.addStopWords = function(e) { - null != e && Array.isArray(e) !== !1 && e.forEach(function(e) { - t.stopWordFilter.stopWords[e] = !0 - }, this) - }, t.resetStopWords = function() { - t.stopWordFilter.stopWords = t.defaultStopWords - }, t.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 - }, t.stopWordFilter.stopWords = t.defaultStopWords, t.Pipeline.registerFunction(t.stopWordFilter, "stopWordFilter"), t.trimmer = function(e) { - if (null === e || void 0 === e) throw new Error("token should not be undefined"); - return e.replace(/^\W+/, "").replace(/\W+$/, "") - }, t.Pipeline.registerFunction(t.trimmer, "trimmer"), t.InvertedIndex = function() { - this.root = { - docs: {}, - df: 0 - } - }, t.InvertedIndex.load = function(e) { - var t = new this; - return t.root = e.root, t - }, t.InvertedIndex.prototype.addToken = function(e, t, n) { - for (var n = n || this.root, i = 0; i <= e.length - 1;) { - var o = e[i]; - o in n || (n[o] = { - docs: {}, - df: 0 - }), i += 1, n = n[o] - } - var r = t.ref; - n.docs[r] ? n.docs[r] = { - tf: t.tf - } : (n.docs[r] = { - tf: t.tf - }, n.df += 1) - }, t.InvertedIndex.prototype.hasToken = function(e) { - if (!e) return !1; - for (var t = this.root, n = 0; n < e.length; n++) { - if (!t[e[n]]) return !1; - t = t[e[n]] - } - return !0 - }, t.InvertedIndex.prototype.getNode = function(e) { - if (!e) return null; - for (var t = this.root, n = 0; n < e.length; n++) { - if (!t[e[n]]) return null; - t = t[e[n]] - } - return t - }, t.InvertedIndex.prototype.getDocs = function(e) { - var t = this.getNode(e); - return null == t ? {} : t.docs - }, t.InvertedIndex.prototype.getTermFrequency = function(e, t) { - var n = this.getNode(e); - return null == n ? 0 : t in n.docs ? n.docs[t].tf : 0 - }, t.InvertedIndex.prototype.getDocFreq = function(e) { - var t = this.getNode(e); - return null == t ? 0 : t.df - }, t.InvertedIndex.prototype.removeToken = function(e, t) { - if (e) { - var n = this.getNode(e); - null != n && t in n.docs && (delete n.docs[t], n.df -= 1) - } - }, t.InvertedIndex.prototype.expandToken = function(e, t, n) { - if (null == e || "" == e) return []; - var t = t || []; - if (void 0 == n && (n = this.getNode(e), null == n)) return t; - n.df > 0 && t.push(e); - for (var i in n) "docs" !== i && "df" !== i && this.expandToken(e + i, t, n[i]); - return t - }, t.InvertedIndex.prototype.toJSON = function() { - return { - root: this.root - } - }, t.Configuration = function(e, n) { - var e = e || ""; - if (void 0 == n || null == n) throw new Error("fields should not be null"); - this.config = {}; - var i; - try { - i = JSON.parse(e), this.buildUserConfig(i, n) - } catch (o) { - t.utils.warn("user configuration parse failed, will use default configuration"), this.buildDefaultConfig(n) - } - }, t.Configuration.prototype.buildDefaultConfig = function(e) { - this.reset(), e.forEach(function(e) { - this.config[e] = { - boost: 1, - bool: "OR", - expand: !1 - } - }, this) - }, t.Configuration.prototype.buildUserConfig = function(e, n) { - var i = "OR", - o = !1; - if (this.reset(), "bool" in e && (i = e.bool || i), "expand" in e && (o = e.expand || o), "fields" in e) - for (var r in e.fields) - if (n.indexOf(r) > -1) { - var s = e.fields[r], - u = o; - void 0 != s.expand && (u = s.expand), this.config[r] = { - boost: s.boost || 0 === s.boost ? s.boost : 1, - bool: s.bool || i, - expand: u - } - } else t.utils.warn("field name in user configuration not found in index instance fields"); - else this.addAllFields2UserConfig(i, o, n) - }, t.Configuration.prototype.addAllFields2UserConfig = function(e, t, n) { - n.forEach(function(n) { - this.config[n] = { - boost: 1, - bool: e, - expand: t - } - }, this) - }, t.Configuration.prototype.get = function() { - return this.config - }, t.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() { - var 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) { - for (var t = 0, n = this.elements.length, i = n - t, o = t + Math.floor(i / 2), r = this.elements[o]; i > 1;) { - if (r === e) return o; - e > r && (t = o), r > e && (n = o), i = n - t, o = t + Math.floor(i / 2), r = this.elements[o] - } - return r === e ? o : -1 - }, lunr.SortedSet.prototype.locationFor = function(e) { - for (var t = 0, n = this.elements.length, i = n - t, o = t + Math.floor(i / 2), r = this.elements[o]; i > 1;) e > r && (t = o), r > e && (n = o), i = n - t, o = t + Math.floor(i / 2), r = this.elements[o]; - return r > e ? o : e > r ? o + 1 : void 0 - }, lunr.SortedSet.prototype.intersect = function(e) { - for (var t = new lunr.SortedSet, n = 0, i = 0, o = this.length, r = e.length, s = this.elements, u = e.elements;;) { - if (n > o - 1 || i > r - 1) break; - s[n] !== u[i] ? s[n] < u[i] ? n++ : s[n] > u[i] && i++ : (t.add(s[n]), n++, i++) - } - 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) { - var t, n, i; - this.length >= e.length ? (t = this, n = e) : (t = e, n = this), i = t.clone(); - for (var o = 0, r = n.toArray(); o < r.length; o++) i.add(r[o]); - return i - }, lunr.SortedSet.prototype.toJSON = function() { - return this.toArray() - }, - function(e, t) { - "function" == typeof define && define.amd ? define(t) : "object" == typeof exports ? module.exports = t() : e.elasticlunr = t() - }(this, function() { - return t - }) -}(); |
