|
@@ -0,0 +1,69 @@
|
|
|
+let input = document.getElementById("input");
|
|
|
+let output = document.getElementById("output");
|
|
|
+input.addEventListener("keyup",() => { convert(input.value) });
|
|
|
+
|
|
|
+document.addEventListener("keydown", (e) => {
|
|
|
+ if(e.ctrlKey && e.key == 's'){
|
|
|
+ convert(input.value);
|
|
|
+ download(output.innerHTML,"out.nc","text/plain");
|
|
|
+ e.preventDefault();
|
|
|
+ }
|
|
|
+ else if(e.ctrlKey && e.key == 'q'){
|
|
|
+ download(input.value,"in.jsnc","text/plain");
|
|
|
+ e.preventDefault();
|
|
|
+ }
|
|
|
+ //else if(e.key == "Tab"){
|
|
|
+ // let cp = input.selectionStart;
|
|
|
+ // input.value = input.value.substring(0,cp) + " " + input.value.substring(cp);
|
|
|
+ // input.selectionStart = cp + 2;
|
|
|
+ // input.selectionEnd = cp + 2;
|
|
|
+ // e.preventDefault();
|
|
|
+ //}
|
|
|
+});
|
|
|
+
|
|
|
+//(([GMFSXYZIJKF]((-?[0-9]+(\.[0-9]+)?)|(\$\{[^\}]+\})|(\$[a-zA-Z0-9]+))) ?)+/g
|
|
|
+const prepro = {
|
|
|
+ //reComment: {
|
|
|
+ // regex: /^([^\n;]*)(;[^;\n]*)$/gm,
|
|
|
+ // replace: "$1;gcode.push('$2');"
|
|
|
+ //},
|
|
|
+ bareInterpolables:{
|
|
|
+ regex: /\$([a-zA-Z0-9_]+)/g,
|
|
|
+ replace: "$${$1}"
|
|
|
+ },
|
|
|
+ push:{
|
|
|
+ regex: /(([GMFSXYZIJKF]((-?[0-9]+(\.[0-9]+)?)|(\$\{[^\}]+\}))) ?)+/g,
|
|
|
+ replace: "gcode.push(`$&`);"
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function convert(data){
|
|
|
+ for(let pname in prepro){
|
|
|
+ let pass = prepro[pname];
|
|
|
+ data = data.replace(pass.regex, pass.replace);
|
|
|
+ }
|
|
|
+
|
|
|
+ gcode = [];
|
|
|
+ eval(data);
|
|
|
+ let o = gcode.join("\n");
|
|
|
+ output.innerHTML = o;
|
|
|
+}
|
|
|
+
|
|
|
+// Function to download data to a file
|
|
|
+function download(data, filename, type) {
|
|
|
+ var file = new Blob([data], {type: type});
|
|
|
+ if (window.navigator.msSaveOrOpenBlob) // IE10+
|
|
|
+ window.navigator.msSaveOrOpenBlob(file, filename);
|
|
|
+ else { // Others
|
|
|
+ var a = document.createElement("a"),
|
|
|
+ url = URL.createObjectURL(file);
|
|
|
+ a.href = url;
|
|
|
+ a.download = filename;
|
|
|
+ document.body.appendChild(a);
|
|
|
+ a.click();
|
|
|
+ setTimeout(function() {
|
|
|
+ document.body.removeChild(a);
|
|
|
+ window.URL.revokeObjectURL(url);
|
|
|
+ }, 0);
|
|
|
+ }
|
|
|
+}
|