owoify/target/doc/main.js

95 lines
52 KiB
JavaScript
Raw Normal View History

2019-08-01 13:54:11 +00:00
if(!String.prototype.startsWith){String.prototype.startsWith=function(searchString,position){position=position||0;return this.indexOf(searchString,position)===position;};}if(!String.prototype.endsWith){String.prototype.endsWith=function(suffix,length){var l=length||this.length;return this.indexOf(suffix,l-suffix.length)!==-1;};}if(!DOMTokenList.prototype.add){DOMTokenList.prototype.add=function(className){if(className&&!hasClass(this,className)){if(this.className&&this.className.length>0){this.className+=" "+className;}else{this.className=className;}}};}if(!DOMTokenList.prototype.remove){DOMTokenList.prototype.remove=function(className){if(className&&this.className){this.className=(" "+this.className+" ").replace(" "+className+" "," ").trim();}};}(function(){"use strict";var itemTypes=["mod","externcrate","import","struct","enum","fn","type","static","trait","impl","tymethod","method","structfield","variant","macro","primitive","associatedtype","constant","associatedconstant","union","foreigntype","keyword","existential","attr","derive","traitalias"];var search_input=document.getElementsByClassName("search-input")[0];var currentTab=0;var titleBeforeSearch=document.title;function getPageId(){var id=document.location.href.split("#")[1];if(id){return id.split("?")[0].split("&")[0];}return null;}function showSidebar(){var elems=document.getElementsByClassName("sidebar-elems")[0];if(elems){addClass(elems,"show-it");}var sidebar=document.getElementsByClassName("sidebar")[0];if(sidebar){addClass(sidebar,"mobile");var filler=document.getElementById("sidebar-filler");if(!filler){var div=document.createElement("div");div.id="sidebar-filler";sidebar.appendChild(div);}}var themePicker=document.getElementsByClassName("theme-picker");if(themePicker&&themePicker.length>0){themePicker[0].style.display="none";}}function hideSidebar(){var elems=document.getElementsByClassName("sidebar-elems")[0];if(elems){removeClass(elems,"show-it");}var sidebar=document.getElementsByClassName("sidebar")[0];removeClass(sidebar,"mobile");var filler=document.getElementById("sidebar-filler");if(filler){filler.remove();}document.getElementsByTagName("body")[0].style.marginTop="";var themePicker=document.getElementsByClassName("theme-picker");if(themePicker&&themePicker.length>0){themePicker[0].style.display=null;}}var TY_PRIMITIVE=itemTypes.indexOf("primitive");var TY_KEYWORD=itemTypes.indexOf("keyword");onEachLazy(document.getElementsByClassName("js-only"),function(e){removeClass(e,"js-only");});function getQueryStringParams(){var params={};window.location.search.substring(1).split("&").map(function(s){var pair=s.split("=");params[decodeURIComponent(pair[0])]=typeof pair[1]==="undefined"?null:decodeURIComponent(pair[1]);});return params;}function browserSupportsHistoryApi(){return window.history&&typeof window.history.pushState==="function";}var main=document.getElementById("main");function highlightSourceLines(ev){hideSidebar();var elem;var search=document.getElementById("search");var i,from,to,match=window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);if(match){from=parseInt(match[1],10);to=Math.min(50000,parseInt(match[2]||match[1],10));from=Math.min(from,to);elem=document.getElementById(from);if(!elem){return;}if(ev===null){var x=document.getElementById(from);if(x){x.scrollIntoView();}}onEachLazy(document.getElementsByClassName("line-numbers"),function(e){onEachLazy(e.getElementsByTagName("span"),function(i_e){removeClass(i_e,"line-highlighted");});});for(i=from;i<=to;++i){addClass(document.getElementById(i),"line-highlighted");}}else if(ev!==null&&search&&!hasClass(search,"hidden")&&ev.newURL){addClass(search,"hidden");removeClass(main,"hidden");var hash=ev.newURL.slice(ev.newURL.indexOf("#")+1);if(browserSupportsHistoryApi()){history.replaceState(hash,"","?search=#"+hash);}elem=document.getElementById(hash);if(elem){elem.scrollIntoView();}}}function expandSection(id){var elem=document.getElementById(id);if(elem&&isHidden(elem)){var h3=elem.parentNode.previousElementSibling;if(h3&&h3.tagName!=="H3"){h3=h3.previousElementSibling;}if(h3){var collapses=h3.
} else if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) {
// We can check if the type we're looking for is inside the generics!
var olength = obj[GENERICS_DATA].length;
for (x = 0; x < olength; ++x) {
lev_distance = Math.min(levenshtein(obj[GENERICS_DATA][x], val.name),
lev_distance);
}
}
// Now whatever happens, the returned distance is "less good" so we should mark it
// as such, and so we add 1 to the distance to make it "less good".
return lev_distance + 1;
}
function findArg(obj, val, literalSearch) {
var lev_distance = MAX_LEV_DISTANCE + 1;
if (obj && obj.type && obj.type[INPUTS_DATA] &&
obj.type[INPUTS_DATA].length > 0) {
var length = obj.type[INPUTS_DATA].length;
for (var i = 0; i < length; i++) {
var tmp = checkType(obj.type[INPUTS_DATA][i], val, literalSearch);
if (literalSearch === true && tmp === true) {
return true;
}
lev_distance = Math.min(tmp, lev_distance);
if (lev_distance === 0) {
return 0;
}
}
}
return literalSearch === true ? false : lev_distance;
}
function checkReturned(obj, val, literalSearch) {
var lev_distance = MAX_LEV_DISTANCE + 1;
if (obj && obj.type && obj.type.length > OUTPUT_DATA) {
var ret = obj.type[OUTPUT_DATA];
if (!obj.type[OUTPUT_DATA].length) {
ret = [ret];
}
for (var x = 0; x < ret.length; ++x) {
var r = ret[x];
if (typeof r === "string") {
r = [r];
}
var tmp = checkType(r, val, literalSearch);
if (literalSearch === true) {
if (tmp === true) {
return true;
}
continue;
}
lev_distance = Math.min(tmp, lev_distance);
if (lev_distance === 0) {
return 0;
}
}
}
return literalSearch === true ? false : lev_distance;
}
function checkPath(contains, lastElem, ty) {
if (contains.length === 0) {
return 0;
}
var ret_lev = MAX_LEV_DISTANCE + 1;
var path = ty.path.split("::");
if (ty.parent && ty.parent.name) {
path.push(ty.parent.name.toLowerCase());
}
var length = path.length;
var clength = contains.length;
if (clength > length) {
return MAX_LEV_DISTANCE + 1;
}
for (var i = 0; i < length; ++i) {
if (i + clength > length) {
break;
}
var lev_total = 0;
var aborted = false;
for (var x = 0; x < clength; ++x) {
var lev = levenshtein(path[i + x], contains[x]);
if (lev > MAX_LEV_DISTANCE) {
aborted = true;
break;
}
lev_total += lev;
}
if (aborted === false) {
ret_lev = Math.min(ret_lev, Math.round(lev_total /clength));}}return ret_lev;}function typePassesFilter(filter,type){if(filter<0)return true;if(filter===type)return true;var name=itemTypes[type];switch(itemTypes[filter]){case"constant":return(name=="associatedconstant");case"fn":return(name=="method"||name=="tymethod");case"type":return(name=="primitive"||name=="keyword");}return false;}function generateId(ty){if(ty.parent&&ty.parent.name){return itemTypes[ty.ty]+ty.path+ty.parent.name+ty.name;}return itemTypes[ty.ty]+ty.path+ty.name;}var nSearchWords=searchWords.length;var i;var ty;var fullId;var returned;var in_args;if((val.charAt(0)==="\""||val.charAt(0)==="'")&&val.charAt(val.length-1)===val.charAt(0)){val=extractGenerics(val.substr(1,val.length-2));for(i=0;i<nSearchWords;++i){if(filterCrates!==undefined&&searchIndex[i].crate!==filterCrates){continue;}in_args=findArg(searchIndex[i],val,true);returned=checkReturned(searchIndex[i],val,true);ty=searchIndex[i];fullId=generateId(ty);if(searchWords[i]===val.name){if(typePassesFilter(typeFilter,searchIndex[i].ty)&&results[fullId]===undefined){results[fullId]={id:i,index:-1};}}else if((in_args===true||returned===true)&&typePassesFilter(typeFilter,searchIndex[i].ty)){if(in_args===true||returned===true){if(in_args===true){results_in_args[fullId]={id:i,index:-1,dontValidate:true,};}if(returned===true){results_returned[fullId]={id:i,index:-1,dontValidate:true,};}}else{results[fullId]={id:i,index:-1,dontValidate:true,};}}}query.inputs=[val];query.output=val;query.search=val;}else if(val.search("->")>-1){var trimmer=function(s){return s.trim();};var parts=val.split("->").map(trimmer);var input=parts[0];var inputs=input.split(",").map(trimmer).sort();for(i=0;i<inputs.length;++i){inputs[i]=extractGenerics(inputs[i]);}var output=extractGenerics(parts[1]);for(i=0;i<nSearchWords;++i){if(filterCrates!==undefined&&searchIndex[i].crate!==filterCrates){continue;}var type=searchIndex[i].type;ty=searchIndex[i];if(!type){continue;}fullId=generateId(ty);var typeOutput=type.length>OUTPUT_DATA?type[OUTPUT_DATA].name:"";returned=checkReturned(ty,output,true);if(output.name==="*"||returned===true){in_args=false;var is_module=false;if(input==="*"){is_module=true;}else{var allFound=true;for(var it=0;allFound===true&&it<inputs.length;it++){allFound=checkType(type,inputs[it],true);}in_args=allFound;}if(in_args===true){results_in_args[fullId]={id:i,index:-1,dontValidate:true,};}if(returned===true){results_returned[fullId]={id:i,index:-1,dontValidate:true,};}if(is_module===true){results[fullId]={id:i,index:-1,dontValidate:true,};}}}query.inputs=inputs.map(function(input){return input.name;});query.output=output.name;}else{query.inputs=[val];query.output=val;query.search=val;val=val.replace(/\_/g,"");var valGenerics=extractGenerics(val);var paths=valLower.split("::");var j;for(j=0;j<paths.length;++j){if(paths[j]===""){paths.splice(j,1);j-=1;}}val=paths[paths.length-1];var contains=paths.slice(0,paths.length>1?paths.length-1:1);for(j=0;j<nSearchWords;++j){var lev;var lev_distance;ty=searchIndex[j];if(!ty||(filterCrates!==undefined&&ty.crate!==filterCrates)){continue;}var lev_distance;var lev_add=0;if(paths.length>1){lev=checkPath(contains,paths[paths.length-1],ty);if(lev>MAX_LEV_DISTANCE){continue;}else if(lev>0){lev_add=1;}}returned=MAX_LEV_DISTANCE+1;in_args=MAX_LEV_DISTANCE+1;var index=-1;lev=MAX_LEV_DISTANCE+1;fullId=generateId(ty);if(searchWords[j].indexOf(split[i])>-1||searchWords[j].indexOf(val)>-1||searchWords[j].replace(/_/g,"").indexOf(val)>-1){if(typePassesFilter(typeFilter,ty.ty)&&results[fullId]===undefined){index=searchWords[j].replace(/_/g,"").indexOf(val);}}if((lev=levenshtein(searchWords[j],val))<=MAX_LEV_DISTANCE){if(typePassesFilter(typeFilter,ty.ty)===false){lev=MAX_LEV_DISTANCE+1;}else{lev+=1;}}if((in_args=findArg(ty,valGenerics))<=MAX_LEV_DISTANCE){if(typePassesFilter(typeFilter,ty.ty)===false){in_args=MAX_LEV_DISTANCE+1;}}if((returned=checkReturned(ty,valGenerics))<=MAX_LEV_DISTANCE){if(typePassesFilter(typeFilter,ty.ty)===false){returned=MAX_LEV_DISTANCE+1;