mirror of
https://github.com/godotengine/godot-website.git
synced 2026-01-02 17:48:55 +03:00
1 line
15 KiB
JavaScript
1 line
15 KiB
JavaScript
function t(e){return Array.isArray?Array.isArray(e):"[object Array]"===a(e)}const e=1/0;function n(t){return t==null?"":function(t){if("string"==typeof t)return t;let n=t+"";return"0"==n&&1/t==-e?"-0":n}(t)}function s(e){return"string"==typeof e}function i(e){return"number"==typeof e}function r(e){return!0===e||!1===e||function(e){return c(e)&&null!==e}(e)&&"[object Boolean]"==a(e)}function c(e){return"object"==typeof e}function o(e){return e!=null}function h(e){return!e.trim().length}function a(e){return e==null?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}const l=e=>`Missing ${e} property in key`,u=e=>`Property 'weight' in key '${e}' must be a positive integer`,d=Object.prototype.hasOwnProperty;class g{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=f(e);this._keys.push(n),this._keyMap[n.id]=n,t+=n.weight}),this._keys.forEach(e=>{e.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function f(e){let n=null,o=null,i=null,a=1,r=null;if(s(e)||t(e))i=e,n=p(e),o=m(e);else{if(!d.call(e,"name"))throw new Error(l("name"));const t=e.name;if(i=t,d.call(e,"weight")&&(a=e.weight,a<=0))throw new Error(u(t));n=p(t),o=m(t),r=e.getFn}return{path:n,id:o,weight:a,src:i,getFn:r}}function p(e){return t(e)?e:e.split(".")}function m(e){return t(e)?e.join("."):e}var M={isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1,includeMatches:!1,findAllMatches:!1,minMatchCharLength:1,location:0,threshold:.6,distance:100,...{useExtendedSearch:!1,getFn:function(e,a){let c=[],d=!1;const l=(e,a,u)=>{if(o(e))if(a[u]){const h=e[a[u]];if(!o(h))return;if(u===a.length-1&&(s(h)||i(h)||r(h)))c.push(n(h));else if(t(h)){d=!0;for(let e=0,t=h.length;e<t;e+=1)l(h[e],a,u+1)}else a.length&&l(h,a,u+1)}else c.push(e)};return l(e,s(a)?a.split("."):a,0),d?c:c[0]},ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const x=/[^ ]+/g;class y{constructor({getFn:e=M.getFn,fieldNormWeight:t=M.fieldNormWeight}={}){this.norm=function(e=1,t=3){const n=new Map,s=Math.pow(10,t);return{get(t){const o=t.match(x).length;if(n.has(o))return n.get(o);const a=1/Math.pow(o,.5*e),i=parseFloat(Math.round(a*s)/s);return n.set(o,i),i},clear(){n.clear()}}}(t,3),this.getFn=e,this.isCreated=!1,this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((e,t)=>{this._keysMap[e.id]=t})}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,s(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){const t=this.size();s(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,n=this.size();t<n;t+=1)this.records[t].i-=1}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!o(e)||h(e))return;let n={v:e,i:t,n:this.norm.get(e)};this.records.push(n)}_addObject(e,n){let i={i:n,$:{}};this.keys.forEach((n,a)=>{let r=n.getFn?n.getFn(e):this.getFn(e,n.path);if(o(r))if(t(r)){let n=[];const e=[{nestedArrIndex:-1,value:r}];for(;e.length;){const{nestedArrIndex:a,value:i}=e.pop();if(o(i))if(s(i)&&!h(i)){let e={v:i,i:a,n:this.norm.get(i)};n.push(e)}else t(i)&&i.forEach((t,n)=>{e.push({nestedArrIndex:n,value:t})})}i.$[a]=n}else if(s(r)&&!h(r)){let e={v:r,n:this.norm.get(r)};i.$[a]=e}}),this.records.push(i)}toJSON(){return{keys:this.keys,records:this.records}}}function L(e,t,{getFn:n=M.getFn,fieldNormWeight:s=M.fieldNormWeight}={}){const o=new y({getFn:n,fieldNormWeight:s});return o.setKeys(e.map(f)),o.setSources(t),o.create(),o}function k(e,{errors:t=0,currentLocation:n=0,expectedLocation:s=0,distance:o=M.distance,ignoreLocation:i=M.ignoreLocation}={}){const a=t/e.length;if(i)return a;const r=Math.abs(s-n);return o?a+r/o:r?1:a}const _=32;function v(e,t,n,{location:s=M.location,distance:o=M.distance,threshold:i=M.threshold,findAllMatches:a=M.findAllMatches,minMatchCharLength:r=M.minMatchCharLength,includeMatches:c=M.includeMatches,ignoreLocation:l=M.ignoreLocation}={}){if(t.length>_)throw new Error(`Pattern length exceeds max of ${_}.`);const h=t.length,f=e.length,d=Math.max(0,Math.min(s,f));let m=i,u=d;const b=r>1||c,y=b?Array(f):[];let g;for(;(g=e.indexOf(t,u))>-1;){let n=k(t,{currentLocation:g,expectedLocation:d,distance:o,ignoreLocation:l});if(m=Math.min(n,m),u=g+h,b){let e=0;for(;e<h;)y[g+e]=1,e+=1}}u=-1;let v=[],p=1,j=h+f;const O=1<<h-1;for(let i=0;i<h;i+=1){let c=0,s=j;for(;c<s;)k(t,{errors:i,currentLocation:d+s,expectedLocation:d,distance:o,ignoreLocation:l})<=m?c=s:j=s,s=Math.floor((j-c)/2+c);j=s;let _=Math.max(1,d-s+1),g=a?f:Math.min(d+s,f)+h,r=Array(g+2);r[g+1]=(1<<i)-1;for(let s=g;s>=_;s-=1){let a=s-1,c=n[e.charAt(a)];if(b&&(y[a]=+!!c),r[s]=(r[s+1]<<1|1)&c,i&&(r[s]|=(v[s+1]|v[s])<<1|1|v[s+1]),r[s]&O&&(p=k(t,{errors:i,currentLocation:a,expectedLocation:d,distance:o,ignoreLocation:l}),p<=m)){if(m=p,u=a,u<=d)break;_=Math.max(1,2*d-u)}}if(k(t,{errors:i+1,currentLocation:d,expectedLocation:d,distance:o,ignoreLocation:l})>m)break;v=r}const w={isMatch:u>=0,score:Math.max(.001,p)};if(b){const e=function(e=[],t=M.minMatchCharLength){let o=[],n=-1,i=-1,s=0;for(let r=e.length;s<r;s+=1){let a=e[s];a&&-1===n?n=s:a||-1===n||(i=s-1,i-n+1>=t&&o.push([n,i]),n=-1)}return e[s-1]&&s-n>=t&&o.push([n,s-1]),o}(y,r);e.length?c&&(w.indices=e):w.isMatch=!1}return w}function S(e){let t={};for(let n=0,s=e.length;n<s;n+=1){const o=e.charAt(n);t[o]=(t[o]||0)|1<<s-n-1}return t}class C{constructor(e,{location:t=M.location,threshold:n=M.threshold,distance:s=M.distance,includeMatches:o=M.includeMatches,findAllMatches:i=M.findAllMatches,minMatchCharLength:a=M.minMatchCharLength,isCaseSensitive:r=M.isCaseSensitive,ignoreLocation:c=M.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:s,includeMatches:o,findAllMatches:i,minMatchCharLength:a,isCaseSensitive:r,ignoreLocation:c},this.pattern=r?e:e.toLowerCase(),this.chunks=[],!this.pattern.length)return;const d=(e,t)=>{this.chunks.push({pattern:e,alphabet:S(e),startIndex:t})},l=this.pattern.length;if(l>_){{let e=0;const t=l%_,n=l-t;for(;e<n;)d(this.pattern.substr(e,_),e),e+=_;if(t){const e=l-_;d(this.pattern.substr(e),e)}}}else d(this.pattern,0)}searchIn(e){const{isCaseSensitive:a,includeMatches:n}=this.options;if(a||(e=e.toLowerCase()),this.pattern===e){let t={isMatch:!0,score:0};return n&&(t.indices=[[0,e.length-1]]),t}const{location:r,distance:c,threshold:l,findAllMatches:d,minMatchCharLength:u,ignoreLocation:h}=this.options;let s=[],o=0,t=!1;this.chunks.forEach(({pattern:i,alphabet:a,startIndex:m})=>{const{isMatch:f,score:g,indices:p}=v(e,i,a,{location:r+m,distance:c,threshold:l,findAllMatches:d,minMatchCharLength:u,includeMatches:n,ignoreLocation:h});f&&(t=!0),o+=g,f&&p&&(s=[...s,...p])});let i={isMatch:t,score:t?o/this.chunks.length:1};return t&&n&&(i.indices=s),i}}class I{constructor(e){this.pattern=e}static isMultiMatch(e){return w(e,this.multiRegex)}static isSingleMatch(e){return w(e,this.singleRegex)}search(){}}function w(e,t){const n=e.match(t);return n?n[1]:null}class $ extends I{constructor(e,{location:t=M.location,threshold:n=M.threshold,distance:s=M.distance,includeMatches:o=M.includeMatches,findAllMatches:i=M.findAllMatches,minMatchCharLength:a=M.minMatchCharLength,isCaseSensitive:r=M.isCaseSensitive,ignoreLocation:c=M.ignoreLocation}={}){super(e),this._bitapSearch=new C(e,{location:t,threshold:n,distance:s,includeMatches:o,findAllMatches:i,minMatchCharLength:a,isCaseSensitive:r,ignoreLocation:c})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class A extends I{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t,n=0;const s=[],i=this.pattern.length;for(;(t=e.indexOf(this.pattern,n))>-1;)n=t+i,s.push([t,n-1]);const o=!!s.length;return{isMatch:o,score:o?0:1,indices:s}}}const E=[class extends I{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}},A,class extends I{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}},class extends I{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},class extends I{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},class extends I{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}},class extends I{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const t=-1===e.indexOf(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},$],b=E.length,F=/ +(?=(?:[^"]*"[^"]*")*[^"]*$)/,N=new Set([$.type,A.type]);class R{constructor(e,{isCaseSensitive:t=M.isCaseSensitive,includeMatches:n=M.includeMatches,minMatchCharLength:s=M.minMatchCharLength,ignoreLocation:o=M.ignoreLocation,findAllMatches:i=M.findAllMatches,location:a=M.location,threshold:r=M.threshold,distance:c=M.distance}={}){this.query=null,this.options={isCaseSensitive:t,includeMatches:n,minMatchCharLength:s,findAllMatches:i,ignoreLocation:o,location:a,threshold:r,distance:c},this.pattern=t?e:e.toLowerCase(),this.query=function(e,t={}){return e.split("|").map(e=>{let s=e.trim().split(F).filter(e=>e&&!!e.trim()),n=[];for(let o=0,r=s.length;o<r;o+=1){const a=s[o];let i=!1,e=-1;for(;!i&&++e<b;){const s=E[e];let o=s.isMultiMatch(a);o&&(n.push(new s(o,t)),i=!0)}if(!i)for(e=-1;++e<b;){const s=E[e];let o=s.isSingleMatch(a);if(o){n.push(new s(o,t));break}}}return n})}(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){const s=this.query;if(!s)return{isMatch:!1,score:1};const{includeMatches:i,isCaseSensitive:a}=this.options;e=a?e:e.toLowerCase();let n=0,t=[],o=0;for(let a=0,c=s.length;a<c;a+=1){const r=s[a];t.length=0,n=0;for(let s=0,l=r.length;s<l;s+=1){const a=r[s],{isMatch:d,indices:c,score:u}=a.search(e);if(!d){o=0,n=0,t.length=0;break}if(n+=1,o+=u,i){const e=a.constructor.type;N.has(e)?t=[...t,...c]:t.push(c)}}if(n){let e={isMatch:!0,score:o/n};return i&&(e.indices=t),e}}return{isMatch:!1,score:1}}}const O=[];function j(e,t){for(let n=0,o=O.length;n<o;n+=1){let s=O[n];if(s.condition(e,t))return new s(e,t)}return new C(e,t)}const W="$and",z="$or",K="$path",P="$val",q=e=>!!e[W]||!!e[z],J=e=>({[W]:Object.keys(e).map(t=>({[t]:e[t]}))});function V(e,n,{auto:o=!0}={}){const i=e=>{let a=Object.keys(e);const r=(e=>!!e[K])(e);if(!r&&a.length>1&&!q(e))return i(J(e));if((e=>!t(e)&&c(e)&&!q(e))(e)){const t=r?e[K]:a[0],i=r?e[P]:e[t];if(!s(i))throw new Error((e=>`Invalid value for key ${e}`)(t));const c={keyId:m(t),pattern:i};return o&&(c.searcher=j(i,n)),c}let l={children:[],operator:a[0]};return a.forEach(n=>{const s=e[n];t(s)&&s.forEach(e=>{l.children.push(i(e))})}),l};return q(e)||(e=J(e)),i(e)}function B(e,t){const n=e.matches;t.matches=[],o(n)&&n.forEach(e=>{if(!o(e.indices)||!e.indices.length)return;const{indices:s,value:i}=e;let n={indices:s,value:i};e.key&&(n.key=e.key.src),e.idx>-1&&(n.refIndex=e.idx),t.matches.push(n)})}function U(e,t){t.score=e.score}class D{constructor(e,t={},n){this.options={...M,...t},this.options.useExtendedSearch,this._keyStore=new g(this.options.keys),this.setCollection(e,n)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof y))throw new Error("Incorrect 'index' type");this._myIndex=t||L(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){o(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let n=0,s=this._docs.length;n<s;n+=1){const o=this._docs[n];e(o,n)&&(this.removeAt(n),n-=1,s-=1,t.push(o))}return t}removeAt(e){this._docs.splice(e,1),this._myIndex.removeAt(e)}getIndex(){return this._myIndex}search(e,{limit:t=-1}={}){const{includeMatches:o,includeScore:a,shouldSort:r,sortFn:c,ignoreFieldNorm:l}=this.options;let n=s(e)?s(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return function(e,{ignoreFieldNorm:t=M.ignoreFieldNorm}){e.forEach(e=>{let n=1;e.matches.forEach(({key:e,norm:s,score:o})=>{const i=e?e.weight:null;n*=Math.pow(0===o&&i?Number.EPSILON:o,(i||1)*(t?1:s))}),e.score=n})}(n,{ignoreFieldNorm:l}),r&&n.sort(c),i(t)&&t>-1&&(n=n.slice(0,t)),function(e,t,{includeMatches:n=M.includeMatches,includeScore:s=M.includeScore}={}){const o=[];return n&&o.push(B),s&&o.push(U),e.map(e=>{const{idx:n}=e,s={item:t[n],refIndex:n};return o.length&&o.forEach(t=>{t(e,s)}),s})}(n,this._docs,{includeMatches:o,includeScore:a})}_searchStringList(e){const n=j(e,this.options),{records:s}=this._myIndex,t=[];return s.forEach(({v:e,i:s,n:i})=>{if(!o(e))return;const{isMatch:a,score:r,indices:c}=n.searchIn(e);a&&t.push({item:e,idx:s,matches:[{score:r,value:e,norm:i,indices:c}]})}),t}_searchLogical(e){const i=V(e,this.options),n=(e,t,s)=>{if(!e.children){const{keyId:o,searcher:i}=e,n=this._findMatches({key:this._keyStore.get(o),value:this._myIndex.getValueForItemAtKeyId(t,o),searcher:i});return n&&n.length?[{idx:s,item:t,matches:n}]:[]}const o=[];for(let i=0,r=e.children.length;i<r;i+=1){const c=e.children[i],a=n(c,t,s);if(a.length)o.push(...a);else if(e.operator===W)return[]}return o},a=this._myIndex.records,t={},s=[];return a.forEach(({$:e,i:a})=>{if(o(e)){let o=n(i,e,a);o.length&&(t[a]||(t[a]={idx:a,item:e,matches:[]},s.push(t[a])),o.forEach(({matches:e})=>{t[a].matches.push(...e)}))}}),s}_searchObjectList(e){const n=j(e,this.options),{keys:s,records:i}=this._myIndex,t=[];return i.forEach(({$:e,i})=>{if(!o(e))return;let a=[];s.forEach((t,s)=>{a.push(...this._findMatches({key:t,value:e[s],searcher:n}))}),a.length&&t.push({idx:i,item:e,matches:a})}),t}_findMatches({key:e,value:n,searcher:s}){if(!o(n))return[];let i=[];if(t(n))n.forEach(({v:t,i:n,n:a})=>{if(!o(t))return;const{isMatch:r,score:c,indices:l}=s.searchIn(t);r&&i.push({score:c,key:e,value:t,idx:n,norm:a,indices:l})});else{const{v:t,n:o}=n,{isMatch:a,score:r,indices:c}=s.searchIn(t);a&&i.push({score:r,key:e,value:t,norm:o,indices:c})}return i}}D.version="7.0.0",D.createIndex=L,D.parseIndex=function(e,{getFn:t=M.getFn,fieldNormWeight:n=M.fieldNormWeight}={}){const{keys:o,records:i}=e,s=new y({getFn:t,fieldNormWeight:n});return s.setKeys(o),s.setIndexRecords(i),s},D.config=M,function(...e){O.push(...e)}(R);export{D as default} |