-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake-min.js
1 lines (1 loc) · 4.04 KB
/
flake-min.js
1
function random(e){return Math.floor(Math.random()*e)}function toggle(e){return!e}const getElms=()=>{var e,t=[];for(i=0,e=document.getElementsByTagName("*");i<e.length;i++)t.push(e[i]);return t},elements=getElms(),renderReval=()=>{if(reval.length>0)for(i=0;i<reval.length;i++){let trueTxt=reval[i].oldTxt;for(q=0;q<Object.keys(data).length;q++)trueTxt.includes(Object.keys(data)[q])&&(trueTxt=trueTxt.replace(Object.keys(data)[q],`data[Object.keys(data)[${q}]]`));let pre=trueTxt.split("{"),post=trueTxt.split("}");reval[i].pre=pre[0],reval[i].post=post[post.length-1],trueTxt=pre[pre.length-1].split("}")[0],reval[i].elem.innerHTML=pre[0]+eval(trueTxt)+post[post.length-1]}},parseFors=()=>{let e,t=[];for(i=0;i<elements.length;i++)null!=(e=elements[i].getAttribute("for"))&&t.push({elem:elements[i],attr:e});return t},fors=parseFors(),renderFors=()=>{for(i=0;i<fors.length;i++){fors[i].elem.innerHTML="";let e,t=fors[i].elem.getAttribute("item-class"),n=fors[i].elem.getAttribute("item"),r=fors[i].attr;for(q=0;q<data[r].length;q++)(e=document.createElement(n)).classList=t,e.innerHTML=data[r][q],fors[i].elem.appendChild(e)}},renderIfs=()=>{if(ifs.length>0)for(i=0;i<ifs.length;i++){let trueAttr=ifs[i].attr;for(q=0;q<Object.keys(data).length;q++)trueAttr.includes(Object.keys(data)[q])&&(trueAttr=trueAttr.replace(Object.keys(data)[q],`data[Object.keys(data)[${q}]]`));eval(trueAttr)?ifs[i].elem.style.display="":ifs[i].elem.style.display="none"}},$render=()=>{renderReval(),renderIfs(),renderFors()},parseData=()=>{var e,t,n=!1;for(i=0;i<elements.length;i++)if(null!=(e=elements[i].getAttribute("data")))return n=!0,e=JSON.parse(e);if(!n)return JSON.parse(e='{"undefined":"undefined"}')},data=parseData(),parseScreen=()=>{var e,t=[];for(i=0;i<elements.length;i++)null!=(e=elements[i].getAttribute("computer"))?t.push({elem:elements[i],attr:"computer"}):null!=elements[i].getAttribute("mobile")&&t.push({elem:elements[i],attr:"mobile"});return t},screens=parseScreen(),renderScreens=()=>{for(i=0;i<screens.length;i++)"mobile"==screens[i].attr&&(window.innerWidth<=600?screens[i].elem.style.display="block":screens[i].elem.style.display="none"),"computer"==screens[i].attr&&(window.innerWidth>600?screens[i].elem.style.display="block":screens[i].elem.style.display="none")},parseReval=()=>{var e,t=[];for(i=0;i<elements.length;i++)null!=(e=elements[i].getAttribute("react"))?t.push({elem:elements[i],oldTxt:elements[i].innerHTML,pre:"",post:""}):null!=elements[i].getAttribute("lint")&&t.push({elem:elements[i],oldTxt:elements[i].innerHTML,pre:"",post:""});return t},reval=parseReval(),parseIf=()=>{var e,t=[];for(i=0;i<elements.length;i++)null!=(e=elements[i].getAttribute("if"))&&t.push({elem:elements[i],attr:e,computed:void 0,pre:"",post:""});return t},ifs=parseIf(),exc=()=>{var hasExc;for(i=0;i<elements.length;i++)if(null!=(hasExc=elements[i].getAttribute("exc"))){for(q=0;q<Object.keys(data).length;q++)hasExc.includes(Object.keys(data)[q])&&(hasExc=hasExc.replace(Object.keys(data)[q],`data[Object.keys(data)[${q}]]`));eval(hasExc)}$render()};exc();const allowInclReturn=(e,t)=>{(xhttp=new XMLHttpRequest).onreadystatechange=function(){4==this.readyState&&200==this.status&&(e.innerHTML=this.responseText)},xhttp.open("GET",t,!0),xhttp.send()},parseIncl=()=>{let e;for(i=0;i<elements.length;i++)e=elements[i].getAttribute("incl"),elem=elements[i],null!=e&&allowInclReturn(elem,e)};parseIncl();const parseBind=()=>{let e,t=[];for(i=0;i<elements.length;i++)if(null!=(e=elements[i].getAttribute("bind")))for(q=0;q<Object.keys(data).length;q++)e.includes(Object.keys(data)[q])&&t.push({elem:elements[i],attr:e});return t},bound=parseBind(),renderBinds=()=>{let e;for(i=0;i<bound.length;i++)bound[i].elem.addEventListener("input",function(t){setTimeout(()=>{data[e=bound[i].attr]=bound[i].elem.value,$render()},0)})};renderBinds();const $=change=>{let update=change;for(let i=0;i<Object.keys(data).length;i++)update.includes(Object.keys(data)[i])&&(update=update.replace(Object.keys(data)[i],`data.${Object.keys(data)[i]}`));eval(update),$render()};window.main=function(){requestAnimationFrame(main),renderScreens()},main(),$render();