diff --git a/js/min/script.min.js b/js/min/script.min.js index eccb558..71d97ff 100644 --- a/js/min/script.min.js +++ b/js/min/script.min.js @@ -1 +1 @@ -let setTabSize=t=>{document.querySelectorAll(".textarea div pre code").forEach(e=>{e.style.tabSize=""+(0!=t?t:4),e.style.MozTabSize=""+(0!=t?t:4)}),tabSize=t},tabSize=4,tabRegex=/\t/g;const ThemeArr=["light","dark","funky","twilight","solarized","night","zll"];let TMP_ID=0;function Out(e){document.querySelector("#"+TMP_ID).innerHTML+=e+"
"}window.addEventListener("load",()=>{var c=new LZMA("./js/src/lzma_worker.js");const d={url:document.location},u={parent:document.querySelector(".textarea"),max:4,min:1,label:"Window",current:0,focus:0,visible:0,windows:[],codeWindow:[],windows_value:[],lineActive:[]},m=e=>{var e=e.value.split("\n")[0];return!!e.match(/[\!|\?]/)&&((e=(e=e.split(/[\!|\?]/))[e.length-1].toLowerCase()).includes("--\x3e")?e.replace("--\x3e","").trim():e)},l=e=>{var t=u.windows.indexOf(e),n=u.codeWindow[t],o=e.value.split("\n"),r=m(e);r&&n.setAttribute("class","language-"+r),tabRegex.test(e.value)&&(e.value=e.value.replaceAll(tabRegex," ".repeat(tabSize))),n.innerHTML=e.value.replaceAll(new RegExp("&","g"),"&").replaceAll(new RegExp("<","g"),"<"),Prism.highlightElement(n),document.querySelector(".w-"+t).style.setProperty("--padd",100<=o.length?1e3<=o.length?1e4<=o.length?"55px":"45px":"35px":"25px"),e.parentElement.querySelector(".line-numbers-rows").innerHTML=Array(o.length).fill("").join(""),e===document.activeElement&&a(e)},a=(e,t=-1)=>{var n=e.value.substring(0,e.selectionStart).split("\n").length,o=e.parentElement.querySelector(".line-numbers-rows");n+t{e=e.parentElement.querySelector(".line-numbers-rows");Array.from(e.children).forEach(e=>{e.classList.remove("current")})};function p(){var e;u.parent.classList.remove("odd-3"),u.parent.classList.remove("odd-4"),3==u.visible&&(3==u.current?u.parent.classList.add("odd-3"):(!(e=["none"==u.windows[2].parentElement.style.display,"none"==u.windows[3].parentElement.style.display])[0]&&e[1]&&u.parent.classList.add("odd-3"),u.parent.classList.add("odd-4")))}const h=()=>{if(u.current{var e=o.classList[0].replace("w-","");u.focus=e}),o.addEventListener("dblclick",()=>{if(1document.querySelector(".hidden-tab").classList.remove("demo"),1e3),o.style.display="none",u.visible--,p();let t=document.createElement("a");t.onclick=e=>{o.style.display="block",t.remove(),u.focus=o.classList[0].replace("w-",""),u.visible++,p()};let n;try{n=o.querySelector("pre").classList[0].replace("language-","")}catch(e){n=""}t.innerHTML=`[${0l(i)),i.addEventListener("mouseup",()=>a(i)),("ontouchstart"in window||0a(i)),i.addEventListener("scroll",()=>{n.scrollTo(i.scrollLeft,i.scrollTop),r.scrollTo(i.scrollLeft,i.scrollTop)}),i.addEventListener("keydown",e=>{var t;"Tab"!=e.key&&9!=e.keyCode&&9!=e.which||(e.preventDefault(),t=i.selectionStart,i.value=i.value.substring(0,t)+" ".repeat(tabSize)+i.value.substring(i.selectionEnd),i.selectionStart=i.selectionEnd=t+tabSize,l(i)),"ArrowUp"!=e.key&&38!=e.keyCode&&38!=e.which||a(i,delay=-2),"ArrowDown"!=e.key&&40!=e.keyCode&&40!=e.which||a(i,delay=0),(e.altKey&&"l"==e.key||e.altKey&&76==e.keyCode||e.altKey&&76==e.which)&&(e.preventDefault(),t=i.value.substring(0,i.selectionStart).lastIndexOf("\n")+1,e=i.value.substring(i.selectionEnd).indexOf("\n")+i.selectionEnd,e+=e==i.value.length-1?1:0,i.setSelectionRange(t,e))}),i.addEventListener("keyup",e=>{"Enter"!=e.key&&13!=e.keyCode&&13!=e.which&&"ArrowUp"!=e.key&&38!=e.keyCode&&38!=e.which&&"ArrowDown"!=e.key&&40!=e.keyCode&&40!=e.which&&"ArrowLeft"!=e.key&&37!=e.keyCode&&37!=e.which&&"ArrowRight"!=e.key&&39!=e.keyCode&&39!=e.which||a(i)}),i.addEventListener("focusout",()=>{s(i)}),n.appendChild(t),o.appendChild(r),o.appendChild(i),o.appendChild(n),u.parent.appendChild(o),u.windows.push(i),u.current++,u.visible++,u.parent.classList.remove("odd-3"),u.parent.classList.remove("odd-4"),p(),2!=u.current&&4!=u.current||((e=document.createElement("div")).classList.add("LR"),e.classList.add("LR-1"),o.appendChild(e)),2!=u.current&&3!=u.current&&4!=u.current||((e=document.createElement("div")).classList.add("TB"),e.classList.add("TB-"+(u.current-2)),o.appendChild(e)),u.codeWindow.push(t),o.classList.add("w-"+(u.current-1)),!0}0document.querySelector(".hidden-tab").classList.remove("demo"),1e3))},t=()=>{if(u.current>u.min&&u.visible>u.min){for(;;){if(console.log(u.focus),"none"!=u.windows[u.focus].parentElement.style.display)break;0==u.focus?u.focus=u.current-1:u.focus--}return u.parent.removeChild(u.windows[u.focus].parentElement),u.windows=u.windows.filter((e,t)=>t!=u.focus),u.codeWindow=u.codeWindow.filter((e,t)=>t!=u.focus),u.current--,u.visible--,p(),u.windows.forEach((e,t)=>{e.parentElement.classList.remove(...e.parentElement.classList),e.parentElement.classList.add("w-"+t)}),!0}document.querySelector(".hidden-tab").classList.add("demo"),setTimeout(()=>document.querySelector(".hidden-tab").classList.remove("demo"),1e3)},w=()=>document.querySelector("body > footer").classList.remove("text-offer"),v=e=>{var t;return"touchstart"==e.type||"touchmove"==e.type||"touchend"==e.type||"touchcancel"==e.type?(t=(t=void 0===e.originalEvent?e:e.originalEvent).touches[0]||t.changedTouches[0],x=t.pageX,y=t.pageY):"mousedown"!=e.type&&"mouseup"!=e.type&&"mousemove"!=e.type&&"mouseover"!=e.type&&"mouseout"!=e.type&&"mouseenter"!=e.type&&"mouseleave"!=e.type||(x=e.clientX,y=e.clientY),{x:x,y:y}},g=(t,n,o=!1,r=null)=>{let i="y"===n;var e=v(t);let l,a,s,c=(s=o?(l=r,a=i?.9*window.innerHeight:.5*window.innerWidth,i?.1*window.innerHeight:.1*window.innerWidth):(l=i?terminal.parentElement.parentElement:document.querySelector("#terminal-fast-option"),a=i?.8*window.innerHeight:.5*window.innerWidth,i?.2*window.innerHeight:.1*window.innerWidth),l.getBoundingClientRect()[i?"height":"width"]),d=e[n];e=e=>{["touchstart","touchmove","touchend","touchcancel"].includes(t.type)||e.preventDefault();e=v(e),document.body.classList.add(i?"row-resize":"col-resize"),e=c-(e[n]-d);e>s&&ef(n,o),window.ontouchend=()=>f(n,o)},f=(e,t=!1)=>{e="y"===e;document.body.classList.remove(e?"row-resize":"col-resize"),window.onmousemove=null,window.ontouchmove=null,window.onmouseup=null,window.ontouchend=null,t||localStorage.setItem(e?"terminalHeight":"terminalOptWidth",e?terminal.parentElement.parentElement.getBoundingClientRect().height:document.querySelector("#terminal-fast-option").getBoundingClientRect().width)};let L;const n=()=>{window.addEventListener("keydown",e=>{((e.metaKey||e.ctrlKey||e.altKey)&&"t"==e.key||(e.metaKey||e.ctrlKey||e.altKey)&&84==e.keyCode||(e.metaKey||e.ctrlKey||e.altKey)&&84==e.which)&&(e.preventDefault(),L())});const e=e=>{ThemeArr.includes(e)||(e=ThemeArr[0]),document.body.classList.remove(...ThemeArr),document.body.classList.add(e),localStorage.setItem("theme",e)};document.querySelector(".invert-color").addEventListener("click",()=>{document.body.classList.contains("dark")?e("light"):e("dark")}),0==u.current&&h(),document.querySelector("#add-w").addEventListener("click",h),document.querySelector("#remove-w").addEventListener("click",t),document.querySelectorAll(".generate-url").forEach(e=>{e.addEventListener("click",()=>{const n=e.getAttribute("data-type");u.windows.forEach((e,t)=>u.windows_value[t]=e.value),c.compress(JSON.stringify(u.windows_value),1,(e,t)=>{if(t)alert("Failed to compress data: "+t);else{let t=new FileReader;t.onload=function(){var e=t.result.substr(t.result.indexOf(",")+1),e="https://"+d.url.host+d.url.pathname+"#"+e,e="markdown"===n?"[paste]("+e+")":e;navigator.clipboard.writeText(e),document.querySelector(".nav-text-offer input").value=e,document.querySelector("body > footer").classList.add("text-offer")},t.readAsDataURL(new Blob([new Uint8Array(e)]))}})})}),document.querySelector("a.cancel-url").addEventListener("click",w),document.querySelector("a.copy-url").addEventListener("click",()=>{document.querySelector(".nav-text-offer input").select(),document.execCommand("copy"),w()}),L=(e="toggle")=>{switch(e){case"open":document.querySelector("#terminal").classList.add("open"),n.focus();break;case"close":document.querySelector("#terminal").classList.remove("open");break;case"toggle":document.querySelector("#terminal").classList.toggle("open"),n.focus()}localStorage.setItem("terminal",!!document.querySelector("#terminal").classList.contains("open"))};const o=()=>{a.historyPosition=0;var e=document.createElement("div");e.classList.add("terminal-input"),e.innerHTML=document.querySelector("#terminal-main-input").innerHTML,l.appendChild(e),e.removeChild(e.querySelector("button")),s.exec(r.innerText).then(e=>{var t;a.position=0,r.innerHTML="",(!e[0]||0L("open")),document.querySelector("#close-t").addEventListener("click",()=>L("close")),n.addEventListener("focus",()=>{n.scrollTop=n.scrollHeight,i.classList.add("blink")}),n.addEventListener("blur",()=>i.classList.remove("blink")),n.addEventListener("keydown",e=>{var t;e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),1==e.key.length&&(a.position+=1,r.innerText=r.innerText.slice(0,a.position-1)+e.key+r.innerText.slice(a.position-1))),"ArrowLeft"==e.key&&(a.position-=0=t.length?0:1:a.historyPosition<=0?0:-1,t=t[t.length-a.historyPosition],r.innerText=t||"",a.position=r.innerText.length),"v"==e.key&&(e.ctrlKey||e.metaKey)&&navigator.clipboard.readText().then(e=>{r.innerText=r.innerText.slice(0,a.position-1)+e+r.innerText.slice(a.position-1),a.position+=e.length}),"Backspace"!=e.key&&"Delete"!=e.key||(r.innerText=r.innerText.slice(0,a.position-1)+r.innerText.slice(a.position),a.position-=0==a.position?0:1),"Enter"!=e.key&&"Return"!=e.key&&"NumpadEnter"!=e.key||o()}),document.querySelectorAll(".terminal-option").forEach(n=>{n.addEventListener("click",()=>{return e=n.getAttribute("data-option"),t={add:["window add 1",1],remove:["window remove 1",1],exit:["exit",1],clear:["cls",1],help:["help",1],reset:["config reset",1],import:["config set JSON",0],export:["config get",1]},r.innerHTML=t[e][0],a.position=r.innerText.length,void(t[e][1]&&o());var e,t})}),["mousedown","touchstart"].forEach(e=>{document.querySelector("#scroll-height.terminal").addEventListener(e,e=>g(e,"y")),document.querySelector("#scroll-width.terminal-opt").addEventListener(e,e=>g(e,"x"))}),new Terminal({terminal:{main:n,input:r,output:l,caret:i,toggleFnc:L,config:a},window:{add:h,remove:t,config:u,getLang:m},theme:{list:ThemeArr,set:e}}))};(fn=async()=>{const o=()=>{var e,t;n(),localStorage.getItem("theme")&&document.body.classList.add(localStorage.getItem("theme")),localStorage.getItem("terminalHeight")&&(t=parseFloat(localStorage.getItem("terminalHeight")),e=.8*window.innerHeight,.2*window.innerHeight{h(),u.windows[t].value=e,l(u.windows[t])})}catch(t){alert("Failed to writing data: "+t)}o()})},t.readAsArrayBuffer(e)}else o()})()}); \ No newline at end of file +let setTabSize=t=>{document.querySelectorAll(".textarea div pre code").forEach(e=>{e.style.tabSize=""+(0!=t?t:4),e.style.MozTabSize=""+(0!=t?t:4)}),tabSize=t},tabSize=4,tabRegex=/\t/g;const ThemeArr=["light","dark","funky","twilight","solarized","night","zll"];let TMP_ID=0;function Out(e){document.querySelector("#"+TMP_ID).innerHTML+=e+"
"}window.addEventListener("load",()=>{var c=new LZMA("./js/src/lzma_worker.js");const d={url:document.location},u={parent:document.querySelector(".textarea"),max:4,min:1,label:"Window",current:0,focus:0,visible:0,windows:[],codeWindow:[],windows_value:[],lineActive:[]},m=e=>{var e=e.value.split("\n")[0];return!!e.match(/[\!|\?]/)&&((e=(e=e.split(/[\!|\?]/))[e.length-1].toLowerCase()).includes("--\x3e")?e.replace("--\x3e","").trim():e)},l=e=>{var t=u.windows.indexOf(e),n=u.codeWindow[t],o=e.value.split("\n"),r=m(e);r&&n.setAttribute("class","language-"+r),tabRegex.test(e.value)&&(e.value=e.value.replaceAll(tabRegex," ".repeat(tabSize))),n.innerHTML=e.value.replaceAll(new RegExp("&","g"),"&").replaceAll(new RegExp("<","g"),"<"),Prism.highlightElement(n),document.querySelector(".w-"+t).style.setProperty("--padd",100<=o.length?1e3<=o.length?1e4<=o.length?"55px":"45px":"35px":"25px"),e.parentElement.querySelector(".line-numbers-rows").innerHTML=Array(o.length).fill("").join(""),e===document.activeElement&&a(e)},a=(e,t=-1)=>{var n=e.value.substring(0,e.selectionStart).split("\n").length,o=e.parentElement.querySelector(".line-numbers-rows");n+t{e=e.parentElement.querySelector(".line-numbers-rows");Array.from(e.children).forEach(e=>{e.classList.remove("current")})};function p(){var e;u.parent.classList.remove("odd-3"),u.parent.classList.remove("odd-4"),3==u.visible&&(3==u.current?u.parent.classList.add("odd-3"):(!(e=["none"==u.windows[2].parentElement.style.display,"none"==u.windows[3].parentElement.style.display])[0]&&e[1]&&u.parent.classList.add("odd-3"),u.parent.classList.add("odd-4")))}const h=()=>{if(u.current{var e=o.classList[0].replace("w-","");u.focus=e}),o.addEventListener("dblclick",()=>{if(1document.querySelector(".hidden-tab").classList.remove("demo"),1e3),o.style.display="none",u.visible--,p();let t=document.createElement("a");t.onclick=e=>{o.style.display="block",t.remove(),u.focus=o.classList[0].replace("w-",""),u.visible++,p()};let n;try{n=o.querySelector("pre").classList[0].replace("language-","")}catch(e){n=""}t.innerHTML=`[${0l(i)),i.addEventListener("mouseup",()=>a(i)),("ontouchstart"in window||0a(i)),i.addEventListener("scroll",()=>{r.scrollTo(i.scrollLeft,i.scrollTop),n.scrollTo(i.scrollLeft,i.scrollTop)}),i.addEventListener("keydown",e=>{var t=(e,t)=>{var n=i.selectionStart;i.value=i.value.substring(0,n)+e+i.value.substring(i.selectionEnd),i.selectionStart=i.selectionEnd=n+t,l(i)},n=("Tab"!=e.key&&9!=e.keyCode&&9!=e.which||(e.preventDefault(),t(" ".repeat(tabSize),tabSize)),{"(":")","[":"]","{":"}",'"':'"',"'":"'","`":"`"}),n=(e.key in n&&t(n[e.key],0),r.classList[0].replace("language-","").toUpperCase());"<"!=e.key||"HTML"!=n&&"XML"!=n||t(">",0),"ArrowUp"!=e.key&&38!=e.keyCode&&38!=e.which||a(i,delay=-2),"ArrowDown"!=e.key&&40!=e.keyCode&&40!=e.which||a(i,delay=0),(e.altKey&&"l"==e.key||e.altKey&&76==e.keyCode||e.altKey&&76==e.which)&&(e.preventDefault(),n=i.value.substring(0,i.selectionStart).lastIndexOf("\n")+1,t=i.value.substring(i.selectionEnd).indexOf("\n")+i.selectionEnd,t+=t==i.value.length-1?1:0,i.setSelectionRange(n,t))}),i.addEventListener("keyup",e=>{"Enter"!=e.key&&13!=e.keyCode&&13!=e.which&&"ArrowUp"!=e.key&&38!=e.keyCode&&38!=e.which&&"ArrowDown"!=e.key&&40!=e.keyCode&&40!=e.which&&"ArrowLeft"!=e.key&&37!=e.keyCode&&37!=e.which&&"ArrowRight"!=e.key&&39!=e.keyCode&&39!=e.which||a(i)}),i.addEventListener("focusout",()=>{s(i)}),r.appendChild(t),o.appendChild(n),o.appendChild(i),o.appendChild(r),u.parent.appendChild(o),u.windows.push(i),u.current++,u.visible++,u.parent.classList.remove("odd-3"),u.parent.classList.remove("odd-4"),p(),2!=u.current&&4!=u.current||((e=document.createElement("div")).classList.add("LR"),e.classList.add("LR-1"),o.appendChild(e)),2!=u.current&&3!=u.current&&4!=u.current||((e=document.createElement("div")).classList.add("TB"),e.classList.add("TB-"+(u.current-2)),o.appendChild(e)),u.codeWindow.push(t),o.classList.add("w-"+(u.current-1)),!0}0document.querySelector(".hidden-tab").classList.remove("demo"),1e3))},t=()=>{if(u.current>u.min&&u.visible>u.min){for(;;){if(console.log(u.focus),"none"!=u.windows[u.focus].parentElement.style.display)break;0==u.focus?u.focus=u.current-1:u.focus--}return u.parent.removeChild(u.windows[u.focus].parentElement),u.windows=u.windows.filter((e,t)=>t!=u.focus),u.codeWindow=u.codeWindow.filter((e,t)=>t!=u.focus),u.current--,u.visible--,p(),u.windows.forEach((e,t)=>{e.parentElement.classList.remove(...e.parentElement.classList),e.parentElement.classList.add("w-"+t)}),!0}document.querySelector(".hidden-tab").classList.add("demo"),setTimeout(()=>document.querySelector(".hidden-tab").classList.remove("demo"),1e3)},w=()=>document.querySelector("body > footer").classList.remove("text-offer"),v=e=>{var t;return"touchstart"==e.type||"touchmove"==e.type||"touchend"==e.type||"touchcancel"==e.type?(t=(t=void 0===e.originalEvent?e:e.originalEvent).touches[0]||t.changedTouches[0],x=t.pageX,y=t.pageY):"mousedown"!=e.type&&"mouseup"!=e.type&&"mousemove"!=e.type&&"mouseover"!=e.type&&"mouseout"!=e.type&&"mouseenter"!=e.type&&"mouseleave"!=e.type||(x=e.clientX,y=e.clientY),{x:x,y:y}},g=(t,n,o=!1,r=null)=>{let i="y"===n;var e=v(t);let l,a,s,c=(s=o?(l=r,a=i?.9*window.innerHeight:.5*window.innerWidth,i?.1*window.innerHeight:.1*window.innerWidth):(l=i?terminal.parentElement.parentElement:document.querySelector("#terminal-fast-option"),a=i?.8*window.innerHeight:.5*window.innerWidth,i?.2*window.innerHeight:.1*window.innerWidth),l.getBoundingClientRect()[i?"height":"width"]),d=e[n];e=e=>{["touchstart","touchmove","touchend","touchcancel"].includes(t.type)||e.preventDefault();e=v(e),document.body.classList.add(i?"row-resize":"col-resize"),e=c-(e[n]-d);e>s&&ef(n,o),window.ontouchend=()=>f(n,o)},f=(e,t=!1)=>{e="y"===e;document.body.classList.remove(e?"row-resize":"col-resize"),window.onmousemove=null,window.ontouchmove=null,window.onmouseup=null,window.ontouchend=null,t||localStorage.setItem(e?"terminalHeight":"terminalOptWidth",e?terminal.parentElement.parentElement.getBoundingClientRect().height:document.querySelector("#terminal-fast-option").getBoundingClientRect().width)};let L;const n=()=>{window.addEventListener("keydown",e=>{((e.metaKey||e.ctrlKey||e.altKey)&&"t"==e.key||(e.metaKey||e.ctrlKey||e.altKey)&&84==e.keyCode||(e.metaKey||e.ctrlKey||e.altKey)&&84==e.which)&&(e.preventDefault(),L())});const e=e=>{ThemeArr.includes(e)||(e=ThemeArr[0]),document.body.classList.remove(...ThemeArr),document.body.classList.add(e),localStorage.setItem("theme",e)};document.querySelector(".invert-color").addEventListener("click",()=>{document.body.classList.contains("dark")?e("light"):e("dark")}),0==u.current&&h(),document.querySelector("#add-w").addEventListener("click",h),document.querySelector("#remove-w").addEventListener("click",t),document.querySelectorAll(".generate-url").forEach(e=>{e.addEventListener("click",()=>{const n=e.getAttribute("data-type");u.windows.forEach((e,t)=>u.windows_value[t]=e.value),c.compress(JSON.stringify(u.windows_value),1,(e,t)=>{if(t)alert("Failed to compress data: "+t);else{let t=new FileReader;t.onload=function(){var e=t.result.substr(t.result.indexOf(",")+1),e="https://"+d.url.host+d.url.pathname+"#"+e,e="markdown"===n?"[paste]("+e+")":e;navigator.clipboard.writeText(e),document.querySelector(".nav-text-offer input").value=e,document.querySelector("body > footer").classList.add("text-offer")},t.readAsDataURL(new Blob([new Uint8Array(e)]))}})})}),document.querySelector("a.cancel-url").addEventListener("click",w),document.querySelector("a.copy-url").addEventListener("click",()=>{document.querySelector(".nav-text-offer input").select(),document.execCommand("copy"),w()}),L=(e="toggle")=>{switch(e){case"open":document.querySelector("#terminal").classList.add("open"),n.focus();break;case"close":document.querySelector("#terminal").classList.remove("open");break;case"toggle":document.querySelector("#terminal").classList.toggle("open"),n.focus()}localStorage.setItem("terminal",!!document.querySelector("#terminal").classList.contains("open"))};const o=()=>{a.historyPosition=0;var e=document.createElement("div");e.classList.add("terminal-input"),e.innerHTML=document.querySelector("#terminal-main-input").innerHTML,l.appendChild(e),e.removeChild(e.querySelector("button")),s.exec(r.innerText).then(e=>{var t;a.position=0,r.innerHTML="",(!e[0]||0L("open")),document.querySelector("#close-t").addEventListener("click",()=>L("close")),n.addEventListener("focus",()=>{n.scrollTop=n.scrollHeight,i.classList.add("blink")}),n.addEventListener("blur",()=>i.classList.remove("blink")),n.addEventListener("keydown",e=>{var t;e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),1==e.key.length&&(a.position+=1,r.innerText=r.innerText.slice(0,a.position-1)+e.key+r.innerText.slice(a.position-1))),"ArrowLeft"==e.key&&(a.position-=0=t.length?0:1:a.historyPosition<=0?0:-1,t=t[t.length-a.historyPosition],r.innerText=t||"",a.position=r.innerText.length),"v"==e.key&&(e.ctrlKey||e.metaKey)&&navigator.clipboard.readText().then(e=>{r.innerText=r.innerText.slice(0,a.position-1)+e+r.innerText.slice(a.position-1),a.position+=e.length}),"Backspace"!=e.key&&"Delete"!=e.key||(r.innerText=r.innerText.slice(0,a.position-1)+r.innerText.slice(a.position),a.position-=0==a.position?0:1),"Enter"!=e.key&&"Return"!=e.key&&"NumpadEnter"!=e.key||o()}),document.querySelectorAll(".terminal-option").forEach(n=>{n.addEventListener("click",()=>{return e=n.getAttribute("data-option"),t={add:["window add 1",1],remove:["window remove 1",1],exit:["exit",1],clear:["cls",1],help:["help",1],reset:["config reset",1],import:["config set JSON",0],export:["config get",1]},r.innerHTML=t[e][0],a.position=r.innerText.length,void(t[e][1]&&o());var e,t})}),["mousedown","touchstart"].forEach(e=>{document.querySelector("#scroll-height.terminal").addEventListener(e,e=>g(e,"y")),document.querySelector("#scroll-width.terminal-opt").addEventListener(e,e=>g(e,"x"))}),new Terminal({terminal:{main:n,input:r,output:l,caret:i,toggleFnc:L,config:a},window:{add:h,remove:t,config:u,getLang:m},theme:{list:ThemeArr,set:e}}))};(fn=async()=>{const o=()=>{var e,t;n(),localStorage.getItem("theme")&&document.body.classList.add(localStorage.getItem("theme")),localStorage.getItem("terminalHeight")&&(t=parseFloat(localStorage.getItem("terminalHeight")),e=.8*window.innerHeight,.2*window.innerHeight{h(),u.windows[t].value=e,l(u.windows[t])})}catch(t){alert("Failed to writing data: "+t)}o()})},t.readAsArrayBuffer(e)}else o()})()}); \ No newline at end of file diff --git a/js/src/script.js b/js/src/script.js index f7283ec..4e4d5d2 100644 --- a/js/src/script.js +++ b/js/src/script.js @@ -299,19 +299,40 @@ window.addEventListener('load', () => { // codeWindow.scrollLeft = newWindow.scrollLeft; }); newWindow.addEventListener('keydown', (e) => { - // Write tab on tab press - if(e.key == 'Tab' || e.keyCode == 9 || e.which == 9) { - e.preventDefault(); - + let autoFillFn = (content, offset) => { const start = newWindow.selectionStart; - newWindow.value = newWindow.value.substring(0, start) + " ".repeat(tabSize) + newWindow.value.substring(newWindow.selectionEnd); + newWindow.value = newWindow.value.substring(0, start) + content + newWindow.value.substring(newWindow.selectionEnd); // fix caret position - newWindow.selectionStart = newWindow.selectionEnd = start + tabSize; + newWindow.selectionStart = newWindow.selectionEnd = start + offset; // Update code _update_code(newWindow) + } + // Write tab on tab press + if(e.key == 'Tab' || e.keyCode == 9 || e.which == 9) { + e.preventDefault(); + autoFillFn(" ".repeat(tabSize), tabSize); + } + // Autofill characters + let autoFillDict = { + '(' : ')', + '[' : ']', + '{' : '}', + '"' : '"', + "'" : "'", + '`' : '`', + } + if (e.key in autoFillDict) { + autoFillFn(autoFillDict[e.key], 0); + } + let lang = codeWindow.classList[0].replace('language-', '').toUpperCase(); + + if ( e.key == '<' && (lang == 'HTML' || lang == 'XML')) { + autoFillFn('>', 0); } + + // Update lines number if the user jump lines if(e.key == 'ArrowUp' || e.keyCode == 38 || e.which == 38){ // Overload line numbers fnc