UNPKG

webserverai

Version:

WebServerAI is an advanced project using AI to revolutionize web development. It empowers users to create visually stunning websites tailored to their needs without extensive coding knowledge. This innovative tool streamlines the design process, offering

6 lines 2.78 kB
/* @Author XHiddenProjects @Version 1.1.2 @Updated 06/19/24 */ const SHIFT=!0,CTRL=!0,ALT=!0,NO_SHIFT=!1,NO_CTRL=!1,NO_ALT=!1;var kL=[],IFs="",tar=0;class shortcutJS{constructor(){this.keyBind={},this.r=!0}createListener(obj=window){kL=Object.entries(this.keyBind);for(let i=0;i<kL.length;i++)obj.addEventListener("keydown",(function(event,tar=i){let ifs="";if("string"==typeof kL[tar][0]&&(ifs+='event.key==="'+kL[tar][0]+'"'),"number"==typeof kL[tar][0]&&(ifs+="event.keyCode==="+kL[tar][0]),kL[tar][1].shift?ifs+="&&event.shiftKey":ifs+="&&!event.shiftKey",kL[tar][1].ctrl?ifs+="&&event.ctrlKey":ifs+="&&!event.ctrlKey",kL[tar][1].alt?ifs+="&&event.altKey":ifs+="&&!event.altKey",eval(ifs))return event.preventDefault(),kL[tar][1].func(),!1;ifs=""}))}bind(e,t,r=NO_SHIFT||[NO_SHIFT],s=CTRL||[CTRL],n=ALT||[ALT]){if("function"!=typeof t&&!Array.isArray(t))return console.error(t+" must be a function|array"),!1;if("string"==typeof e)return e=e.substr(0,15),this.keyBind[e]={shift:r,ctrl:s,alt:n,func:t},!0;if(Array.isArray(e)){for(let i=0;i<e.length;i++){if(e[i]=e[i].substr(0,15),"function"!=typeof t[i])return console.error(t[i]+" must be a function"),!1;if("string"!=typeof e[i]&&"number"!=typeof e[i])return console.error(e[i]+" must be a function"),!1;this.keyBind[e[i]]={shift:r[i],ctrl:s[i],alt:n[i],func:t[i]}}return!0}console.error(e+" must be a string|array"),this.r=!1,this.keyBind={}}unbind(e){return this.keyBind[e]?delete this.keyBind[e]:(console.error(e+" doesn`t have a set value"),!1)}update(e,t){return this.keyBind[t]=this.keyBind[e],delete this.keyBind[e]}setDesc(e,t=""){if(!this.keyBind[e])return console.error(e+" doesn`t have a set value"),!1;this.keyBind[e].desc=t}remDesc(e){return this.keyBind[e].desc?delete this.keyBind[e].desc:(console.error(e+" doesn`t have a set description"),!1)}strip(e){let t="";for(let r=0;r<e.split("").length;r++)r<=15&&(t+=e.split("")[r]);return t}get(){return this.keyBind}showList(e,t=""){let r=document.querySelector(e);if(!(r&&"ol"===r.tagName.toLowerCase()||"ul"===r.tagName.toLowerCase()))return console.error(e+" does not exists or element is not OL/UL!"),!1;{r.classList.add("scList");let e=document.createElement("style");e.innerHTML=".scList .cmd{float:right;font-weight:bold;font-style:italic;color:#7a7878;}",document.head.appendChild(e);let s=Object.entries(this.keyBind);for(let e=0;e<s.length;e++){let n=document.createElement("li");Array.isArray(t)?n.classList.add(t[e]):""!==t?n.classList.add(t):n.className="",n.innerHTML+='<span class="desc">'+(s[e][1].desc?s[e][1].desc:"")+"</span> ",n.innerHTML+='<span class="cmd">'+(s[e][1].alt?"ALT+":"")+(s[e][1].ctrl?"CTRL+":"")+(s[e][1].shift?"Shift+":"")+s[e][0]+"</span>",r.appendChild(n)}}}}export{shortcutJS,SHIFT,CTRL,ALT,NO_SHIFT,NO_CTRL,NO_ALT};