Files
Snap.Hutao.Docs/assets/search.esm-2c3fba7d.js

8 lines
2.8 KiB
JavaScript

/*!
* Handles finding a text string anywhere in the slides and showing the next occurrence to the user
* by navigatating to that slide and highlighting it.
*
* @author Jon Snyder <snyder.jon@gmail.com>, February 2013
*/const B=()=>{let c,t,n,i,r,y,a;function g(){t=document.createElement("div"),t.classList.add("searchbox"),t.style.position="absolute",t.style.top="10px",t.style.right="10px",t.style.zIndex=10,t.innerHTML=`<input type="search" class="searchinput" placeholder="Search..." style="vertical-align: top;"/>
</span>`,n=t.querySelector(".searchinput"),n.style.width="240px",n.style.fontSize="14px",n.style.padding="4px 6px",n.style.color="#000",n.style.background="#fff",n.style.borderRadius="2px",n.style.border="0",n.style.outline="0",n.style.boxShadow="0 2px 18px rgba(0, 0, 0, 0.2)",n.style["-webkit-appearance"]="none",c.getRevealElement().appendChild(t),n.addEventListener("keyup",function(d){switch(d.keyCode){case 13:d.preventDefault(),function(){if(y){var o=n.value;o===""?(a&&a.remove(),i=null):(a=new R("slidecontent"),i=a.apply(o),r=0)}i&&(i.length&&i.length<=r&&(r=0),i.length>r&&(c.slide(i[r].h,i[r].v),r++))}(),y=!1;break;default:y=!0}},!1),C()}function w(){t||g(),t.style.display="inline",n.focus(),n.select()}function C(){t||g(),t.style.display="none",a&&a.remove()}function R(d,o){var k=document.getElementById(d)||document.body,v=o||"EM",L=new RegExp("^(?:"+v+"|SCRIPT|FORM)$"),E=["#ff6","#a0ffff","#9f9","#f99","#f6f"],x=[],T=0,u="",h=[];this.setRegex=function(e){e=e.replace(/^[^\w]+|[^\w]+$/g,"").replace(/[^\w'-]+/g,"|"),u=new RegExp("("+e+")","i")},this.getRegex=function(){return u.toString().replace(/^\/\\b\(|\)\\b\/i$/g,"").replace(/\|/g," ")},this.hiliteWords=function(e){if(e!=null&&e&&u&&!L.test(e.nodeName)){if(e.hasChildNodes())for(var l=0;l<e.childNodes.length;l++)this.hiliteWords(e.childNodes[l]);var N,s;if(e.nodeType==3&&(N=e.nodeValue)&&(s=u.exec(N))){for(var f=e;f!=null&&f.nodeName!="SECTION";)f=f.parentNode;var m=c.getIndices(f),I=h.length,S=!1;for(l=0;l<I;l++)h[l].h===m.h&&h[l].v===m.v&&(S=!0);S||h.push(m),x[s[0].toLowerCase()]||(x[s[0].toLowerCase()]=E[T++%E.length]);var p=document.createElement(v);p.appendChild(document.createTextNode(s[0])),p.style.backgroundColor=x[s[0].toLowerCase()],p.style.fontStyle="inherit",p.style.color="#000";var b=e.splitText(s.index);b.nodeValue=b.nodeValue.substring(s[0].length),e.parentNode.insertBefore(p,b)}}},this.remove=function(){for(var e,l=document.getElementsByTagName(v);l.length&&(e=l[0]);)e.parentNode.replaceChild(e.firstChild,e)},this.apply=function(e){if(e!=null&&e)return this.remove(),this.setRegex(e),this.hiliteWords(k),h}}return{id:"search",init:d=>{c=d,c.registerKeyboardShortcut("CTRL + Shift + F","Search"),document.addEventListener("keydown",function(o){o.key=="F"&&(o.ctrlKey||o.metaKey)&&(o.preventDefault(),t||g(),t.style.display!=="inline"?w():C())},!1)},open:w}};export{B as default};