From 5a89e51bc1e4fc9a36c17a43a60edfeae960c0cb Mon Sep 17 00:00:00 2001 From: Graham Trott Date: Fri, 26 Jun 2020 11:34:26 +0100 Subject: [PATCH] Lint --- dist/easycoder-min.js | 156 ++++++++++++++++++++-------------------- dist/easycoder.js | 124 ++++++++++++++++---------------- js/easycoder/Browser.js | 124 ++++++++++++++++---------------- 3 files changed, 206 insertions(+), 198 deletions(-) diff --git a/dist/easycoder-min.js b/dist/easycoder-min.js index 104dedd..7c2ebf5 100644 --- a/dist/easycoder-min.js +++ b/dist/easycoder-min.js @@ -89,7 +89,7 @@ d){a.next();var f=EasyCoder_Core.isNegate(a);switch(a.getToken()){case "numeric" type:"less",value1:c,value2:g,negate:f}}break;default:var k=a.getValue();return{domain:"core",type:"is",value1:c,value2:k,negate:f}}}else if(c)return{domain:"core",type:"boolean",value:c}}catch(l){return a.warning("Can't get a value"),0}return null},test:function(a,b){switch(b.type){case "boolean":return a.getValue(b.value);case "numeric":var c=a.getValue(b.value1);c=" "===c||isNaN(c);return b.negate?c:!c;case "even":return 0===a.getValue(b.value1)%2;case "odd":return 1===a.getValue(b.value1)%2;case "is":return c= a.compare(a,b.value1,b.value2),b.negate?0!==c:0===c;case "greater":return c=a.compare(a,b.value1,b.value2),b.negate?0>=c:0c;case "not":return!a.getValue(b.value);case "moduleRunning":return c=a.getSymbolRecord(b.name),EasyCoder.scripts.hasOwnProperty(c.program)?(c=EasyCoder.scripts[c.program],b.sense?c.running:!c.running):!b.sense;case "includes":return c=a.getValue(b.value1),b=a.getValue(b.value2),c.includes(b)}return!1}}},EasyCoder_Browser= {name:"EasyCoder_Browser",A:{compile:function(a){a.compileVariable("browser","a",!1,"dom");return!0},run:function(a){return a[a.pc].pc+1}},Alert:{compile:function(a){var b=a.getLino(),c=a.getNextValue();a.addCommand({domain:"browser",keyword:"alert",lino:b,value:c});return!0},run:function(a){var b=a[a.pc];a=a.getFormattedValue(b.value);alert(a);return b.pc+1}},Attach:{compile:function(a){var b=a.getLino();a.next();if(a.isSymbol()){var c=a.getSymbolRecord(),d=c.keyword;switch(d){case "a":case "blockquote":case "button":case "canvas":case "div":case "fieldset":case "file":case "form":case "h1":case "h2":case "h3":case "h4":case "h5":case "h6":case "image":case "img":case "input":case "label":case "legend":case "li":case "option":case "p":case "pre":case "select":case "span":case "table":case "td":case "text":case "textarea":case "tr":case "ul":a.next(); -if(a.tokenIs("to")){if(a.nextTokenIs("body"))if("div"===d)cssId="body",a.next();else throw Error("Body variable must be a div");else cssId=a.getValue();var e=0;a.tokenIs("or")&&(a.next(),e=a.getPc()+1,a.completeHandler());a.addCommand({domain:"browser",keyword:"attach",lino:b,type:d,symbol:c.name,cssId:cssId,onError:e});return!0}break;default:return a.addWarning("type '"+c.keyword+"' not recognized in browser 'attach'"),!1}}a.addWarning("Unrecognised syntax in 'attach'");return!1},run:function(a){var b= +if(a.tokenIs("to")){if(a.nextTokenIs("body"))if("div"===d){var e="body";a.next()}else throw Error("Body variable must be a div");else e=a.getValue();var f=0;a.tokenIs("or")&&(a.next(),f=a.getPc()+1,a.completeHandler());a.addCommand({domain:"browser",keyword:"attach",lino:b,type:d,symbol:c.name,cssId:e,onError:f});return!0}break;default:return a.addWarning("type '"+c.keyword+"' not recognized in browser 'attach'"),!1}}a.addWarning("Unrecognised syntax in 'attach'");return!1},run:function(a){var b= a[a.pc],c=null,d=null;"body"===b.cssId?d=document.body:(c=a.value.evaluate(a,b.cssId).content,d=document.getElementById(c));if(!d)return b.onError?a.run(b.onError):a.runtimeError(b.lino,"No such element: '"+c+"'"),0;var e=a.getSymbolRecord(b.symbol);e.element[e.index]=d;e.value[e.index]={type:"constant",numeric:!1,content:c};"popup"===b.type&&(a.popups.push(d.id),window.onclick=function(b){a.popups.includes(b.target.id)&&(b.target.style.display="none")});return b.pc+1}},Audioclip:{compile:function(a){a.compileVariable("browser", "audioclip");return!0},run:function(a){return a[a.pc].pc+1}},BLOCKQUOTE:{compile:function(a){a.compileVariable("browser","blockquote",!1,"dom");return!0},run:function(a){return a[a.pc].pc+1}},BUTTON:{compile:function(a){a.compileVariable("browser","button",!1,"dom");return!0},run:function(a){return a[a.pc].pc+1}},CANVAS:{compile:function(a){a.compileVariable("browser","canvas",!1,"dom");return!0},run:function(a){return a[a.pc].pc+1}},Click:{compile:function(a){var b=a.getLino();if(a.nextIsSymbol()){var c= a.getSymbolRecord();if("select"===c.keyword)return a.next(),a.addCommand({domain:"browser",keyword:"click",lino:b,target:c.name}),!0}return!1},run:function(a){var b=a[a.pc];a=a.getSymbolRecord(b.target);a.element[a.index].dispatchEvent(new Event("click"));return b.pc+1}},Clear:{compile:function(a){var b=a.getLino();if(a.nextTokenIs("body"))return a.next(),a.addCommand({domain:"browser",keyword:"clear",lino:b,name:null}),!0;if(a.isSymbol()){var c=a.getSymbolRecord();if("dom"===c.extra)return a.next(), @@ -103,80 +103,80 @@ return!1},run:function(a){var b=a[a.pc];a=a.getSymbolRecord(b.symbol);document.g a[a.pc];a=a.getSymbolRecord(b.symbol);document.getElementById(a.value[a.index].content).disabled=!1;return b.pc+1}},FIELDSET:{compile:function(a){a.compileVariable("browser","fieldset",!1,"dom");return!0},run:function(a){return a[a.pc].pc+1}},FILE:{compile:function(a){a.compileVariable("browser","file",!1,"dom");return!0},run:function(a){return a[a.pc].pc+1}},Focus:{compile:function(a){var b=a.getLino();if(a.nextIsSymbol()){var c=a.getToken();a.next();a.addCommand({domain:"browser",keyword:"focus", lino:b,symbol:c});return!0}a.addWarning("Unrecognised syntax in 'focus'");return!1},run:function(a){var b=a[a.pc];a=a.getSymbolRecord(b.symbol);a.element[a.index].focus();return b.pc+1}},FORM:{compile:function(a){a.compileVariable("browser","form",!1,"dom");return!0},run:function(a){return a[a.pc].pc+1}},Get:{compile:function(a){var b=a.getLino();if(a.nextIsSymbol()){var c=a.getToken(),d=a.getSymbolRecord();if(a.nextTokenIs("from")){if(a.nextTokenIs("storage"))return a.nextTokenIs("as")?(d=a.getNextValue(), a.addCommand({domain:"browser",keyword:"get",action:"getStorage",lino:b,target:c,key:d})):a.addCommand({domain:"browser",keyword:"get",action:"listStorage",lino:b,target:c}),!0;if(a.isSymbol()){var e=a.getSymbolRecord();if("select"===e.keyword){if("option"===d.keyword)return a.next(),a.addCommand({domain:"browser",keyword:"get",action:"getOption",lino:b,target:c,select:e.name}),!0;throw Error("Invalid variable type");}if("form"!==e.keyword)throw Error("Invalid variable type");a.next();a.addCommand({domain:"browser", -keyword:"get",action:"getForm",lino:b,target:c,form:e.name});return!0}a.getSymbolRecord(c)}}a.addWarning("Unrecognised syntax in 'get'");return!1},run:function(a){var b=a[a.pc],c=a.getSymbolRecord(b.target);switch(b.action){case "getForm":a=a.getSymbolRecord(b.form);a=document.getElementById(a.value[a.index].content);var d=new FormData(a);a={};d=$jscomp.makeIterator(d);for(var e=d.next();!e.done;e=d.next())e=e.value,a[e[0]]=e[1].replace(/\r/g,"").replace(/\n/g,"%0a");c.value[c.index]={type:"constant", -numeric:!1,content:JSON.stringify(a)};break;case "listStorage":a=[];d=0;for(e=window.localStorage.length;db&&a.onSwipeRight&&a.run(a.onSwipeRight)))},!1);break;case "pick":d=a.getSymbolRecord(b.symbol);document.pickRecord=d;d.element.forEach(function(c,d){document.pickIndex=d;c.pickIndex=d;c.mouseDownPc=b.pc+2;"ontouchstart"in c?(c.addEventListener("touchstart",function(b){var c= -b.targetTouches[0].target;document.pickX=b.touches[0].clientX;document.pickY=b.touches[0].clientY;c.blur();setTimeout(function(){document.pickRecord.index=c.pickIndex;a.run(c.mouseDownPc)},1)},!1),c.addEventListener("touchmove",function(b){document.dragX=b.touches[0].clientX;document.dragY=b.touches[0].clientY;setTimeout(function(){a.run(document.mouseMovePc)},1);return!1},!1),c.addEventListener("touchend",function(){setTimeout(function(){a.run(document.mouseUpPc)},1);return!1})):c.onmousedown=function(b){b= -b?b:window.event;b.stopPropagation();if(0
',b.style.display="none";a.tracing=!0}a.stop= -!1}return a.pc+1}},UL:{compile:function(a){a.compileVariable("browser","ul",!1,"dom");return!0},run:function(a){return a[a.pc].pc+1}},Upload:{compile:function(a){var b=a.getLino();if(a.nextIsSymbol()){var c=a.getToken();if(a.nextTokenIs("to")){var d=a.getNextValue();if(a.tokenIs("with")&&a.nextIsSymbol()){var e=a.getToken();if(a.nextTokenIs("and")&&a.nextIsSymbol()){var f=a.getToken();a.next();a.addCommand({domain:"browser",keyword:"upload",lino:b,file:c,path:d,progress:e,status:f});return!0}}}}return!1}, -run:function(a){var b=a[a.pc],c=a.getSymbolRecord(b.file),d=a.getValue(b.path),e=a.getSymbolRecord(b.progress),f=a.getSymbolRecord(b.status),h=e.element[e.index],g=f.element[f.index],k=function(a){g&&(g.innerHTML=a)};if(e=c.element[c.index].files[0])c=new FormData,c.append("source",e),c.append("path",d),e=new XMLHttpRequest,e.upload.addEventListener("progress",function(a){a=Math.round(a.loaded/a.total*100);h&&(h.value=a);k(Math.round(a)+"%...")},!1),e.addEventListener("load",function(a){a=a.target.responseText; -h&&(h.value=0);k("");a&&console.log(a)},!1),e.addEventListener("error",function(){k("Upload failed");console.log("Upload failed")},!1),e.addEventListener("abort",function(){k("Upload aborted");console.log("Upload aborted")},!1),e.onreadystatechange=function(){if(4===this.readyState){var b=a.ajaxCommand,c=this.status;switch(c){case 200:a.run(b.pc+1);break;case 0:break;default:try{a.runtimeError(b.lino,"Error "+c)}catch(p){a.reportError(p,a)}}}},e.onerror=function(c){b.onError?(a.errorMessage=this.responseText, -a.run(b.onError)):a.runtimeError(b.lino,this.responseText)},a.ajaxCommand=b,(f=document.getElementById("easycoder-rest"))||a.runtimeError(b.lino,"No REST server defined"),d=d.startsWith("http")?d:window.location.origin+"/"+f.innerText+"/"+d,e.open("POST",d),e.send(c);return 0}},getHandler:function(a){switch(a){case "a":return EasyCoder_Browser.A;case "alert":return EasyCoder_Browser.Alert;case "attach":return EasyCoder_Browser.Attach;case "audioclip":return EasyCoder_Browser.Audioclip;case "blockquote":return EasyCoder_Browser.BLOCKQUOTE; -case "button":return EasyCoder_Browser.BUTTON;case "canvas":return EasyCoder_Browser.CANVAS;case "clear":return EasyCoder_Browser.Clear;case "click":return EasyCoder_Browser.Click;case "convert":return EasyCoder_Browser.Convert;case "copy":return EasyCoder_Browser.Copy;case "create":return EasyCoder_Browser.Create;case "disable":return EasyCoder_Browser.Disable;case "div":return EasyCoder_Browser.DIV;case "enable":return EasyCoder_Browser.Enable;case "fieldset":return EasyCoder_Browser.FIELDSET;case "file":return EasyCoder_Browser.FILE; -case "focus":return EasyCoder_Browser.Focus;case "form":return EasyCoder_Browser.FORM;case "fullscreen":return EasyCoder_Browser.FullScreen;case "get":return EasyCoder_Browser.Get;case "h1":return EasyCoder_Browser.H1;case "h2":return EasyCoder_Browser.H2;case "h3":return EasyCoder_Browser.H3;case "h4":return EasyCoder_Browser.H4;case "h5":return EasyCoder_Browser.H5;case "h6":return EasyCoder_Browser.H6;case "highlight":return EasyCoder_Browser.Highlight;case "history":return EasyCoder_Browser.History; -case "hr":return EasyCoder_Browser.HR;case "image":return EasyCoder_Browser.IMAGE;case "img":return EasyCoder_Browser.IMG;case "input":return EasyCoder_Browser.INPUT;case "label":return EasyCoder_Browser.LABEL;case "legend":return EasyCoder_Browser.LEGEND;case "li":return EasyCoder_Browser.LI;case "location":return EasyCoder_Browser.Location;case "mail":return EasyCoder_Browser.Mail;case "on":return EasyCoder_Browser.On;case "option":return EasyCoder_Browser.OPTION;case "p":return EasyCoder_Browser.P; -case "play":return EasyCoder_Browser.Play;case "pre":return EasyCoder_Browser.PRE;case "progress":return EasyCoder_Browser.PROGRESS;case "put":return EasyCoder_Browser.Put;case "remove":return EasyCoder_Browser.Remove;case "request":return EasyCoder_Browser.Request;case "select":return EasyCoder_Browser.SELECT;case "scroll":return EasyCoder_Browser.Scroll;case "section":return EasyCoder_Browser.SECTION;case "set":return EasyCoder_Browser.Set;case "span":return EasyCoder_Browser.SPAN;case "table":return EasyCoder_Browser.TABLE; -case "tr":return EasyCoder_Browser.TR;case "td":return EasyCoder_Browser.TD;case "textarea":return EasyCoder_Browser.TEXTAREA;case "trace":return EasyCoder_Browser.Trace;case "ul":return EasyCoder_Browser.UL;case "upload":return EasyCoder_Browser.Upload;default:return null}},run:function(a){var b=a[a.pc],c=EasyCoder_Browser.getHandler(b.keyword);c||a.runtimeError(b.lino,"Unknown keyword '"+b.keyword+"' in 'browser' package");return c.run(a)},value:{compile:function(a){if(a.isSymbol()){var b=a.getSymbolRecord(); -if(a.nextTokenIs("exists"))return"dom"===b.extra?(a.next(),{domain:"browser",type:"exists",value:b.name}):null;switch(b.keyword){case "file":case "input":case "select":case "textarea":return{domain:"browser",type:b.keyword,value:b.name}}return null}a.tokenIs("the")&&a.next();var c=!1;a.tokenIs("offset")&&(c=!0,a.next());b=a.getToken();switch(b){case "mobile":case "portrait":case "landscape":case "br":case "location":case "key":case "hostname":return a.next(),{domain:"browser",type:b};case "content":case "text":if(a.nextTokenIs("of")){if(a.nextIsSymbol())return b= -a.getSymbolRecord(),a.next(),{domain:"browser",type:"contentOf",symbol:b.name};throw Error("'"+a.getToken()+"' is not a symbol");}break;case "selected":b=a.nextToken();if(["index","item"].includes(b)&&["in","of"].includes(a.nextToken())&&a.nextIsSymbol()&&(c=a.getSymbolRecord(),["ul","ol","select"].includes(c.keyword)))return a.next(),{domain:"browser",type:"selected",symbol:c.name,arg:b};break;case "color":return a.next(),a=a.getValue(),{domain:"browser",type:b,value:a};case "attribute":c=a.getNextValue(); -if(a.tokenIs("of")&&(a.next(),a.isSymbol()&&(b=a.getSymbolRecord(),"dom"===b.extra)))return a.next(),{domain:"browser",type:"attributeOf",attribute:c,symbol:b.name};break;case "style":c=a.getNextValue();if(a.tokenIs("of")&&a.nextIsSymbol()){var d=a.getSymbolRecord();if("dom"===d.extra)return a.next(),{domain:"browser",type:b,style:c,target:d.name}}break;case "confirm":return b=a.getNextValue(),{domain:"browser",type:"confirm",text:b};case "prompt":return b=a.getNextValue(),c=null,a.tokenIs("with")&& -(c=a.getNextValue()),{domain:"browser",type:"prompt",text:b,pre:c};case "screen":c=a.nextToken();if(["width","height"].includes(c))return a.next(),{domain:"browser",type:b,attribute:c};break;case "top":case "bottom":case "left":case "right":case "width":case "height":return EasyCoder_Browser.value.getCoord(a,b,c);case "scroll":if(a.nextTokenIs("position"))return a.next(),{domain:"browser",type:"scrollPosition"};break;case "document":if(a.nextTokenIs("path"))return a.next(),{domain:"browser",type:"docPath"}; -break;case "storage":if(a.nextTokenIs("keys"))return a.next(),{domain:"browser",type:"storageKeys"};break;case "parent":switch(a.nextToken()){case "name":return a.next(),{domain:"browser",type:"varName"};case "index":return a.next(),{domain:"browser",type:"varIndex"}}break;case "history":if(a.nextTokenIs("state"))return a.next(),{domain:"browser",type:"historyState"};break;case "pick":case "drag":if(a.nextTokenIs("position"))return a.next(),{domain:"browser",type:b+"Position"};case "click":if(b=a.nextToken(), -["left","top"].includes(b))return a.next(),{domain:"browser",type:"click",which:b}}return null},getCoord:function(a,b,c){if(a.nextTokenIs("of")){a.nextTokenIs("the")&&a.nextToken();var d=a.getToken();if(["window","viewport"].includes(d))return a.next(),{domain:"browser",type:b,symbol:d,offset:c};if(a.isSymbol()&&(d=a.getSymbolRecord(),"dom"===d.extra))return a.next(),{domain:"browser",type:b,symbol:d.name,offset:c}}return null},get:function(a,b){switch(b.type){case "file":case "input":case "select":case "textarea":var c= -a.getSymbolRecord(b.value);var d=c.element[c.index];return{type:"constant",numeric:!1,content:d.value};case "exists":return c=a.getSymbolRecord(b.value),{domain:"browser",type:"boolean",content:"undefined"!==typeof c.element[c.index]};case "mobile":return{domain:"browser",type:"boolean",content:"undefined"!==typeof window.orientation||-1!==navigator.userAgent.indexOf("IEMobile")};case "portrait":return{domain:"browser",type:"boolean",content:document.documentElement.clientWidth=document.documentElement.clientHeight};case "br":return{type:"constant",numeric:!1,content:decodeURIComponent("%3Cbr%20%2F%3E")};case "attributeOf":return c=a.getSymbolRecord(b.symbol),b=a.getValue(b.attribute),d=c.element[c.index],0===b.indexOf("data-")?a.getSimpleValue(d.dataset[b.substr(5)]):a.getSimpleValue(d[b]);case "style":return c=a.getSymbolRecord(b.target),b=a.getValue(b.style),d=c.element[c.index], -a.getSimpleValue(d.style[b]);case "confirm":return{type:"boolean",content:window.confirm(a.getValue(b.text))};case "prompt":return d=a.getValue(b.text),b=a.getValue(b.pre),{type:"constant",numeric:!1,content:b?window.prompt(d,b):window.prompt(d)};case "contentOf":c=a.getSymbolRecord(b.symbol);d=c.element[c.index];if(null===d||"undefined"===typeof d)return a.runtimeError(a[a.pc].lino,"Variable '"+c.name+"' is not attached to a DOM element."),null;switch(c.keyword){case "input":case "textarea":b=d.value; -break;case "pre":b=d.innerHTML;break;default:b=d.innerHTML.split("\n").join("")}return{type:"constant",numeric:!1,content:b};case "selected":return c=a.getSymbolRecord(b.symbol),d=c.element[c.index],a=d.selectedIndex,d=0<=a?d.options[a].text:"",b="index"===b.arg?a:d,{type:"constant",numeric:!1,content:b};case "top":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenY};c=a.getSymbolRecord(b.symbol);a=c.element[c.index];b=Math.round(b.offset?a.offsetTop:a.getBoundingClientRect().top); -return{type:"constant",numeric:!0,content:b};case "bottom":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenY+window.innerHeight};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().bottom);return{type:"constant",numeric:!0,content:b};case "left":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenLeft};c=a.getSymbolRecord(b.symbol);a=c.element[c.index];b=Math.round(b.offset?a.offsetLeft:a.getBoundingClientRect().left); -return{type:"constant",numeric:!0,content:b};case "right":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenX+window.innerWidth};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().right);return{type:"constant",numeric:!0,content:b};case "width":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.innerWidth};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().width);return{type:"constant", -numeric:!0,content:b};case "height":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.innerHeight};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().height);return{type:"constant",numeric:!0,content:b};case "color":return{type:"constant",numeric:!1,content:"#"+a.value.evaluate(a,b.value).content.toString(16).padStart(6,"0")};case "docPath":return{type:"constant",numeric:!1,content:a.docPath};case "storageKeys":return{type:"constant",numeric:!1, -content:JSON.stringify(Object.keys(localStorage))};case "location":return{type:"constant",numeric:!1,content:window.location.href};case "historyState":return{type:"constant",numeric:!1,content:window.history.state};case "scrollPosition":return{type:"constant",numeric:!0,content:scrollPosition};case "varName":return{type:"constant",numeric:!1,content:a.varName};case "varIndex":return{type:"constant",numeric:!0,content:a.varIndex};case "key":return{type:"constant",numeric:!1,content:a.key};case "hostname":return{type:"constant", -numeric:!1,content:location.hostname};case "screen":return{type:"constant",numeric:!0,content:screen[b.attribute]};case "pickPosition":return{type:"constant",numeric:!1,content:JSON.stringify({x:document.pickX,y:document.pickY})};case "dragPosition":return{type:"constant",numeric:!1,content:JSON.stringify({x:document.dragX,y:document.dragY})};case "click":a=EasyCoder_Browser.clickData;if("undefined"===typeof a)return 0;d=a.target.getBoundingClientRect();return{type:"constant",numeric:!0,content:"left"=== -b.which?a.clientX-Math.round(d.left):a.clientY-Math.round(d.top)}}}},condition:{compile:function(a){if(a.tokenIs("confirm"))return{domain:"browser",type:"confirm",value:a.getNextValue()};if(a.tokenIs("element")&&a.nextIsSymbol()){var b=a.getSymbolRecord();if("dom"===b.extra){var c=a.nextToken();if("has"===c){if(a.nextTokenIs("the")&&a.next(),a.tokenIs("focus"))return a.next(),{domain:"browser",type:"focus",element:b.name}}else if("contains"===c)return a=a.getNextValue(),{domain:"browser",type:"contains", -element:b.name,position:a}}}return null},test:function(a,b){switch(b.type){case "confirm":return confirm(a.getValue(b.value));case "focus":var c=a.getSymbolRecord(b.element);return c.element[c.index]===document.activeElement;case "contains":c=a.getSymbolRecord(b.element);var d=c.element[c.index].getBoundingClientRect();c=Math.round(d.left);var e=Math.round(d.right),f=Math.round(d.top);d=Math.round(d.bottom);b=JSON.parse(a.getValue(b.position));a=b.x;b=b.y;return a>=c&&a<=e&&b>=f&&b<=d?!0:!1}}},setStyles:function(a, -b){a=document.getElementById(a);b=b.split(";");b=$jscomp.makeIterator(b);for(var c=b.next();!c.done;c=b.next())c=c.value.split(":"),a.setAttribute(c[0],c[1])}},scrollPosition=0;window.addEventListener("scroll",function(){scrollPosition=this.scrollY});window.onpopstate=function(a){window.EasyCoder.timestamp=Date.now();(a=JSON.parse(a.state))&&a.script&&((a=window.EasyCoder.scripts[a.script])?a.onBrowserBack&&a.run(a.onBrowserBack):console.log("No script property in window state object"))}; +keyword:"get",action:"getForm",lino:b,target:c,form:e.name});return!0}}}a.addWarning("Unrecognised syntax in 'get'");return!1},run:function(a){var b=a[a.pc],c=a.getSymbolRecord(b.target);switch(b.action){case "getForm":a=a.getSymbolRecord(b.form);a=document.getElementById(a.value[a.index].content);var d=new FormData(a);a={};d=$jscomp.makeIterator(d);for(var e=d.next();!e.done;e=d.next())e=e.value,a[e[0]]=e[1].replace(/\r/g,"").replace(/\n/g,"%0a");c.value[c.index]={type:"constant",numeric:!1,content:JSON.stringify(a)}; +break;case "listStorage":a=[];d=0;for(e=window.localStorage.length;db&&a.onSwipeRight&&a.run(a.onSwipeRight)))},!1);break;case "pick":d=a.getSymbolRecord(b.symbol);document.pickRecord=d;d.element.forEach(function(c,d){document.pickIndex=d;c.pickIndex=d;c.mouseDownPc=b.pc+2;"ontouchstart"in c?(c.addEventListener("touchstart",function(b){var c=b.targetTouches[0].target;document.pickX=b.touches[0].clientX;document.pickY=b.touches[0].clientY;c.blur();setTimeout(function(){document.pickRecord.index= +c.pickIndex;a.run(c.mouseDownPc)},1)},!1),c.addEventListener("touchmove",function(b){document.dragX=b.touches[0].clientX;document.dragY=b.touches[0].clientY;setTimeout(function(){a.run(document.mouseMovePc)},1);return!1},!1),c.addEventListener("touchend",function(){setTimeout(function(){a.run(document.mouseUpPc)},1);return!1})):c.onmousedown=function(b){b=b?b:window.event;b.stopPropagation();if(0
',b.style.display="none";a.tracing=!0}a.stop=!1}return a.pc+1}},UL:{compile:function(a){a.compileVariable("browser","ul",!1,"dom");return!0},run:function(a){return a[a.pc].pc+ +1}},Upload:{compile:function(a){var b=a.getLino();if(a.nextIsSymbol()){var c=a.getToken();if(a.nextTokenIs("to")){var d=a.getNextValue();if(a.tokenIs("with")&&a.nextIsSymbol()){var e=a.getToken();if(a.nextTokenIs("and")&&a.nextIsSymbol()){var f=a.getToken();a.next();a.addCommand({domain:"browser",keyword:"upload",lino:b,file:c,path:d,progress:e,status:f});return!0}}}}return!1},run:function(a){var b=a[a.pc],c=a.getSymbolRecord(b.file),d=a.getValue(b.path),e=a.getSymbolRecord(b.progress),f=a.getSymbolRecord(b.status), +h=e.element[e.index],g=f.element[f.index],k=function(a){g&&(g.innerHTML=a)};if(e=c.element[c.index].files[0])c=new FormData,c.append("source",e),c.append("path",d),e=new XMLHttpRequest,e.upload.addEventListener("progress",function(a){a=Math.round(a.loaded/a.total*100);h&&(h.value=a);k(Math.round(a)+"%...")},!1),e.addEventListener("load",function(a){a=a.target.responseText;h&&(h.value=0);k("");a&&console.log(a)},!1),e.addEventListener("error",function(){k("Upload failed");console.log("Upload failed")}, +!1),e.addEventListener("abort",function(){k("Upload aborted");console.log("Upload aborted")},!1),e.onreadystatechange=function(){if(4===this.readyState){var b=a.ajaxCommand,c=this.status;switch(c){case 200:a.run(b.pc+1);break;case 0:break;default:try{a.runtimeError(b.lino,"Error "+c)}catch(p){a.reportError(p,a)}}}},e.onerror=function(){b.onError?(a.errorMessage=this.responseText,a.run(b.onError)):a.runtimeError(b.lino,this.responseText)},a.ajaxCommand=b,(f=document.getElementById("easycoder-rest"))|| +a.runtimeError(b.lino,"No REST server defined"),d=d.startsWith("http")?d:window.location.origin+"/"+f.innerText+"/"+d,e.open("POST",d),e.send(c);return 0}},getHandler:function(a){switch(a){case "a":return EasyCoder_Browser.A;case "alert":return EasyCoder_Browser.Alert;case "attach":return EasyCoder_Browser.Attach;case "audioclip":return EasyCoder_Browser.Audioclip;case "blockquote":return EasyCoder_Browser.BLOCKQUOTE;case "button":return EasyCoder_Browser.BUTTON;case "canvas":return EasyCoder_Browser.CANVAS; +case "clear":return EasyCoder_Browser.Clear;case "click":return EasyCoder_Browser.Click;case "convert":return EasyCoder_Browser.Convert;case "copy":return EasyCoder_Browser.Copy;case "create":return EasyCoder_Browser.Create;case "disable":return EasyCoder_Browser.Disable;case "div":return EasyCoder_Browser.DIV;case "enable":return EasyCoder_Browser.Enable;case "fieldset":return EasyCoder_Browser.FIELDSET;case "file":return EasyCoder_Browser.FILE;case "focus":return EasyCoder_Browser.Focus;case "form":return EasyCoder_Browser.FORM; +case "fullscreen":return EasyCoder_Browser.FullScreen;case "get":return EasyCoder_Browser.Get;case "h1":return EasyCoder_Browser.H1;case "h2":return EasyCoder_Browser.H2;case "h3":return EasyCoder_Browser.H3;case "h4":return EasyCoder_Browser.H4;case "h5":return EasyCoder_Browser.H5;case "h6":return EasyCoder_Browser.H6;case "highlight":return EasyCoder_Browser.Highlight;case "history":return EasyCoder_Browser.History;case "hr":return EasyCoder_Browser.HR;case "image":return EasyCoder_Browser.IMAGE; +case "img":return EasyCoder_Browser.IMG;case "input":return EasyCoder_Browser.INPUT;case "label":return EasyCoder_Browser.LABEL;case "legend":return EasyCoder_Browser.LEGEND;case "li":return EasyCoder_Browser.LI;case "location":return EasyCoder_Browser.Location;case "mail":return EasyCoder_Browser.Mail;case "on":return EasyCoder_Browser.On;case "option":return EasyCoder_Browser.OPTION;case "p":return EasyCoder_Browser.P;case "play":return EasyCoder_Browser.Play;case "pre":return EasyCoder_Browser.PRE; +case "progress":return EasyCoder_Browser.PROGRESS;case "put":return EasyCoder_Browser.Put;case "remove":return EasyCoder_Browser.Remove;case "request":return EasyCoder_Browser.Request;case "select":return EasyCoder_Browser.SELECT;case "scroll":return EasyCoder_Browser.Scroll;case "section":return EasyCoder_Browser.SECTION;case "set":return EasyCoder_Browser.Set;case "span":return EasyCoder_Browser.SPAN;case "table":return EasyCoder_Browser.TABLE;case "tr":return EasyCoder_Browser.TR;case "td":return EasyCoder_Browser.TD; +case "textarea":return EasyCoder_Browser.TEXTAREA;case "trace":return EasyCoder_Browser.Trace;case "ul":return EasyCoder_Browser.UL;case "upload":return EasyCoder_Browser.Upload;default:return null}},run:function(a){var b=a[a.pc],c=EasyCoder_Browser.getHandler(b.keyword);c||a.runtimeError(b.lino,"Unknown keyword '"+b.keyword+"' in 'browser' package");return c.run(a)},value:{compile:function(a){if(a.isSymbol()){var b=a.getSymbolRecord();if(a.nextTokenIs("exists"))return"dom"===b.extra?(a.next(),{domain:"browser", +type:"exists",value:b.name}):null;switch(b.keyword){case "file":case "input":case "select":case "textarea":return{domain:"browser",type:b.keyword,value:b.name}}return null}a.tokenIs("the")&&a.next();var c=!1;a.tokenIs("offset")&&(c=!0,a.next());b=a.getToken();switch(b){case "mobile":case "portrait":case "landscape":case "br":case "location":case "key":case "hostname":return a.next(),{domain:"browser",type:b};case "content":case "text":if(a.nextTokenIs("of")){if(a.nextIsSymbol())return b=a.getSymbolRecord(), +a.next(),{domain:"browser",type:"contentOf",symbol:b.name};throw Error("'"+a.getToken()+"' is not a symbol");}break;case "selected":b=a.nextToken();if(["index","item"].includes(b)&&["in","of"].includes(a.nextToken())&&a.nextIsSymbol()&&(c=a.getSymbolRecord(),["ul","ol","select"].includes(c.keyword)))return a.next(),{domain:"browser",type:"selected",symbol:c.name,arg:b};break;case "color":return a.next(),a=a.getValue(),{domain:"browser",type:b,value:a};case "attribute":c=a.getNextValue();if(a.tokenIs("of")&& +(a.next(),a.isSymbol()&&(b=a.getSymbolRecord(),"dom"===b.extra)))return a.next(),{domain:"browser",type:"attributeOf",attribute:c,symbol:b.name};break;case "style":c=a.getNextValue();if(a.tokenIs("of")&&a.nextIsSymbol()){var d=a.getSymbolRecord();if("dom"===d.extra)return a.next(),{domain:"browser",type:b,style:c,target:d.name}}break;case "confirm":return b=a.getNextValue(),{domain:"browser",type:"confirm",text:b};case "prompt":return b=a.getNextValue(),c=null,a.tokenIs("with")&&(c=a.getNextValue()), +{domain:"browser",type:"prompt",text:b,pre:c};case "screen":c=a.nextToken();if(["width","height"].includes(c))return a.next(),{domain:"browser",type:b,attribute:c};break;case "top":case "bottom":case "left":case "right":case "width":case "height":return EasyCoder_Browser.value.getCoord(a,b,c);case "scroll":if(a.nextTokenIs("position"))return a.next(),{domain:"browser",type:"scrollPosition"};break;case "document":if(a.nextTokenIs("path"))return a.next(),{domain:"browser",type:"docPath"};break;case "storage":if(a.nextTokenIs("keys"))return a.next(), +{domain:"browser",type:"storageKeys"};break;case "parent":switch(a.nextToken()){case "name":return a.next(),{domain:"browser",type:"varName"};case "index":return a.next(),{domain:"browser",type:"varIndex"}}break;case "history":if(a.nextTokenIs("state"))return a.next(),{domain:"browser",type:"historyState"};break;case "pick":case "drag":if(a.nextTokenIs("position"))return a.next(),{domain:"browser",type:b+"Position"};break;case "click":if(b=a.nextToken(),["left","top"].includes(b))return a.next(), +{domain:"browser",type:"click",which:b}}return null},getCoord:function(a,b,c){if(a.nextTokenIs("of")){a.nextTokenIs("the")&&a.nextToken();var d=a.getToken();if(["window","viewport"].includes(d))return a.next(),{domain:"browser",type:b,symbol:d,offset:c};if(a.isSymbol()&&(d=a.getSymbolRecord(),"dom"===d.extra))return a.next(),{domain:"browser",type:b,symbol:d.name,offset:c}}return null},get:function(a,b){switch(b.type){case "file":case "input":case "select":case "textarea":var c=a.getSymbolRecord(b.value); +var d=c.element[c.index];return d?{type:"constant",numeric:!1,content:d.value}:(a.runtimeError(a[a.pc].lino,"Variable '"+c.name+"' is not attached to a DOM element."),null);case "exists":return c=a.getSymbolRecord(b.value),{domain:"browser",type:"boolean",content:"undefined"!==typeof c.element[c.index]};case "mobile":return{domain:"browser",type:"boolean",content:"undefined"!==typeof window.orientation||-1!==navigator.userAgent.indexOf("IEMobile")};case "portrait":return{domain:"browser",type:"boolean", +content:document.documentElement.clientWidth=document.documentElement.clientHeight};case "br":return{type:"constant",numeric:!1,content:decodeURIComponent("%3Cbr%20%2F%3E")};case "attributeOf":return c=a.getSymbolRecord(b.symbol),b=a.getValue(b.attribute),d=c.element[c.index],0===b.indexOf("data-")?a.getSimpleValue(d.dataset[b.substr(5)]):a.getSimpleValue(d[b]); +case "style":return c=a.getSymbolRecord(b.target),b=a.getValue(b.style),d=c.element[c.index],a.getSimpleValue(d.style[b]);case "confirm":return{type:"boolean",content:window.confirm(a.getValue(b.text))};case "prompt":return d=a.getValue(b.text),b=a.getValue(b.pre),{type:"constant",numeric:!1,content:b?window.prompt(d,b):window.prompt(d)};case "contentOf":c=a.getSymbolRecord(b.symbol);d=c.element[c.index];if(null===d||"undefined"===typeof d)return a.runtimeError(a[a.pc].lino,"Variable '"+c.name+"' is not attached to a DOM element."), +null;switch(c.keyword){case "input":case "textarea":b=d.value;break;case "pre":b=d.innerHTML;break;default:b=d.innerHTML.split("\n").join("")}return{type:"constant",numeric:!1,content:b};case "selected":return c=a.getSymbolRecord(b.symbol),d=c.element[c.index],a=d.selectedIndex,d=0<=a?d.options[a].text:"",b="index"===b.arg?a:d,{type:"constant",numeric:!1,content:b};case "top":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenY};c=a.getSymbolRecord(b.symbol);a=c.element[c.index]; +b=Math.round(b.offset?a.offsetTop:a.getBoundingClientRect().top);return{type:"constant",numeric:!0,content:b};case "bottom":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenY+window.innerHeight};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().bottom);return{type:"constant",numeric:!0,content:b};case "left":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenLeft};c=a.getSymbolRecord(b.symbol);a=c.element[c.index]; +b=Math.round(b.offset?a.offsetLeft:a.getBoundingClientRect().left);return{type:"constant",numeric:!0,content:b};case "right":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.screenX+window.innerWidth};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().right);return{type:"constant",numeric:!0,content:b};case "width":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.innerWidth};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().width); +return{type:"constant",numeric:!0,content:b};case "height":if("window"==b.symbol)return{type:"constant",numeric:!0,content:window.innerHeight};c=a.getSymbolRecord(b.symbol);b=Math.round(c.element[c.index].getBoundingClientRect().height);return{type:"constant",numeric:!0,content:b};case "color":return{type:"constant",numeric:!1,content:"#"+a.value.evaluate(a,b.value).content.toString(16).padStart(6,"0")};case "docPath":return{type:"constant",numeric:!1,content:a.docPath};case "storageKeys":return{type:"constant", +numeric:!1,content:JSON.stringify(Object.keys(localStorage))};case "location":return{type:"constant",numeric:!1,content:window.location.href};case "historyState":return{type:"constant",numeric:!1,content:window.history.state};case "scrollPosition":return{type:"constant",numeric:!0,content:scrollPosition};case "varName":return{type:"constant",numeric:!1,content:a.varName};case "varIndex":return{type:"constant",numeric:!0,content:a.varIndex};case "key":return{type:"constant",numeric:!1,content:a.key}; +case "hostname":return{type:"constant",numeric:!1,content:location.hostname};case "screen":return{type:"constant",numeric:!0,content:screen[b.attribute]};case "pickPosition":return{type:"constant",numeric:!1,content:JSON.stringify({x:document.pickX,y:document.pickY})};case "dragPosition":return{type:"constant",numeric:!1,content:JSON.stringify({x:document.dragX,y:document.dragY})};case "click":a=EasyCoder_Browser.clickData;if("undefined"===typeof a)return 0;d=a.target.getBoundingClientRect();return{type:"constant", +numeric:!0,content:"left"===b.which?a.clientX-Math.round(d.left):a.clientY-Math.round(d.top)}}}},condition:{compile:function(a){if(a.tokenIs("confirm"))return{domain:"browser",type:"confirm",value:a.getNextValue()};if(a.tokenIs("element")&&a.nextIsSymbol()){var b=a.getSymbolRecord();if("dom"===b.extra){var c=a.nextToken();if("has"===c){if(a.nextTokenIs("the")&&a.next(),a.tokenIs("focus"))return a.next(),{domain:"browser",type:"focus",element:b.name}}else if("contains"===c)return a=a.getNextValue(), +{domain:"browser",type:"contains",element:b.name,position:a}}}return null},test:function(a,b){switch(b.type){case "confirm":return confirm(a.getValue(b.value));case "focus":var c=a.getSymbolRecord(b.element);return c.element[c.index]===document.activeElement;case "contains":c=a.getSymbolRecord(b.element);var d=c.element[c.index].getBoundingClientRect();c=Math.round(d.left);var e=Math.round(d.right),f=Math.round(d.top);d=Math.round(d.bottom);b=JSON.parse(a.getValue(b.position));a=b.x;b=b.y;return a>= +c&&a<=e&&b>=f&&b<=d?!0:!1}}},setStyles:function(a,b){a=document.getElementById(a);b=b.split(";");b=$jscomp.makeIterator(b);for(var c=b.next();!c.done;c=b.next())c=c.value.split(":"),a.setAttribute(c[0],c[1])}},scrollPosition=0;window.addEventListener("scroll",function(){scrollPosition=this.scrollY});window.onpopstate=function(a){window.EasyCoder.timestamp=Date.now();(a=JSON.parse(a.state))&&a.script&&((a=window.EasyCoder.scripts[a.script])?a.onBrowserBack&&a.run(a.onBrowserBack):console.log("No script property in window state object"))}; var EasyCoder_Json={name:"EasyCoder_JSON",Json:{compile:function(a){var b=a.getLino(),c=a.nextToken();switch(c){case "set":a.next();if(a.isSymbol())if(c=a.getSymbolRecord(),"variable"===c.keyword){if(a.nextTokenIs("to")){var d=a.nextToken();if('["array","object"]'.includes(d))return a.next(),a.addCommand({domain:"json",keyword:"json",lino:b,request:"setVariable",target:c.name,type:d}),!0}}else if("select"===c.keyword&&a.nextTokenIs("from")&&(a.next(),a.isSymbol()&&(d=a.getSymbolRecord(),"variable"=== d.keyword))){var e=null;a.nextTokenIs("as")&&(e=a.getNextValue());a.addCommand({domain:"json",keyword:"json",lino:b,request:"setList",target:c.name,source:d.name,display:e});return!0}break;case "sort":case "shuffle":case "format":if(a.nextIsSymbol()&&(d=a.getSymbolRecord(),"variable"===d.keyword))return a.next(),a.addCommand({domain:"json",keyword:"json",lino:b,request:c,target:d.name}),!0;break;case "parse":if(a.nextTokenIs("url")&&(d=a.getNextValue(),a.tokenIs("as")&&a.nextIsSymbol()&&(e=a.getSymbolRecord(), "variable"===e.keyword)))return a.next(),a.addCommand({domain:"json",keyword:"json",lino:b,request:c,source:d,target:e.name}),!0;break;case "delete":d=a.nextToken();if(["property","element"].includes(d)&&(e=a.getNextValue(),["from","of"].includes(a.getToken())&&a.nextIsSymbol())){var f=a.getSymbolRecord();if("variable"===f.keyword)return a.next(),a.addCommand({domain:"json",keyword:"json",lino:b,request:c,what:d,value:e,target:f.name}),!0}break;case "rename":d=a.getNextValue();if(a.tokenIs("to")&& @@ -204,9 +204,9 @@ var c=EasyCoder_Value.doValue(a,b);if(c)return c;a.runtimeError(a[a.pc].lino,"Ca b){if(a)switch(b){case "ec":return a.replace(/%0a/g,"\n").replace(/%0d/g,"\r").replace(/~dq~/g,'"').replace(/~sq~/g,"'").replace(/~bs~/g,"\\");case "url":return decodeURIComponent(a).replace(/\+/g," ")}return a}},EasyCoder_Run={name:"EasyCoder_Run",run:function(a,b){var c=[],d=function(a){var b=9999;a.forEach(function(a){a=a.line;for(var c=0;c')}l+="
"}g.innerHTML=k+" "+l;g.style.display="block";b.$jscomp$loop$prop$run$135=document.getElementById("easycoder-run-button");b.$jscomp$loop$prop$step$136=document.getElementById("easycoder-step-button"); -b.$jscomp$loop$prop$run$135.onclick=function(b){return function(){b.$jscomp$loop$prop$run$135.blur();a.tracing=!1;document.getElementById("easycoder-tracer-content").style.display="none";try{EasyCoder_Run.run(a,a.resume)}catch(q){var c="Error in run handler: "+q.message;console.log(c);alert(c)}}}(b);b.$jscomp$loop$prop$step$136.onclick=function(b){return function(){console.log("step");b.$jscomp$loop$prop$step$136.blur();a.tracing=!0;document.getElementById("easycoder-tracer-content").style.display= -"block";try{a.run(a.resume)}catch(q){var c="Error in step handler: "+q.message;console.log(c);alert(c)}}}(b)}a.resume=a.pc;a.pc=0}break}b={$jscomp$loop$prop$run$135:b.$jscomp$loop$prop$run$135,$jscomp$loop$prop$step$136:b.$jscomp$loop$prop$step$136}}},exit:function(a){a.onExit&&a.run(a.onExit);var b=a.parent,c=a.afterExit;delete EasyCoder.scripts[a.script];a.module&&delete a.module.program;Object.keys(a).forEach(function(b){delete a[b]});b&&c&&EasyCoder.scripts[b].run(c)}},EasyCoder_Compiler={name:"EasyCoder_Compiler", +k+(b+": undefined");switch(a.tracer.alignment){case "horizontal":c')}l+="
"}g.innerHTML=k+" "+l;g.style.display="block";b.$jscomp$loop$prop$run$134=document.getElementById("easycoder-run-button");b.$jscomp$loop$prop$step$135=document.getElementById("easycoder-step-button"); +b.$jscomp$loop$prop$run$134.onclick=function(b){return function(){b.$jscomp$loop$prop$run$134.blur();a.tracing=!1;document.getElementById("easycoder-tracer-content").style.display="none";try{EasyCoder_Run.run(a,a.resume)}catch(q){var c="Error in run handler: "+q.message;console.log(c);alert(c)}}}(b);b.$jscomp$loop$prop$step$135.onclick=function(b){return function(){console.log("step");b.$jscomp$loop$prop$step$135.blur();a.tracing=!0;document.getElementById("easycoder-tracer-content").style.display= +"block";try{a.run(a.resume)}catch(q){var c="Error in step handler: "+q.message;console.log(c);alert(c)}}}(b)}a.resume=a.pc;a.pc=0}break}b={$jscomp$loop$prop$run$134:b.$jscomp$loop$prop$run$134,$jscomp$loop$prop$step$135:b.$jscomp$loop$prop$step$135}}},exit:function(a){a.onExit&&a.run(a.onExit);var b=a.parent,c=a.afterExit;delete EasyCoder.scripts[a.script];a.module&&delete a.module.program;Object.keys(a).forEach(function(b){delete a[b]});b&&c&&EasyCoder.scripts[b].run(c)}},EasyCoder_Compiler={name:"EasyCoder_Compiler", getTokens:function(){return this.tokens},addWarning:function(a){this.warnings.push(a)},warning:function(a){this.addWarning(a)},unrecognisedSymbol:function(a){this.addWarning("Unrecognised symbol '"+a+"'")},getWarnings:function(){return this.warnings},getIndex:function(){return this.index},next:function(a){this.index+=void 0===a?1:a},peek:function(){return this.tokens[this.index+1].token},more:function(){return this.index=this.tokens.length? null:this.tokens[this.index]?this.tokens[this.index].token:null},nextToken:function(){this.next();return this.getToken()},tokenIs:function(a){return this.index>=this.tokens.length?!1:a===this.tokens[this.index].token},nextTokenIs:function(a){this.next();return this.tokenIs(a)},skip:function(a){if(this.index>=this.tokens.length)return null;this.next();this.tokenIs(a)&&this.next()},prev:function(){this.index--},getLino:function(){return this.index>=this.tokens.length?0:this.tokens[this.index].lino}, getTarget:function(a){a=void 0===a?this.index:a;return this.tokens[a].token},getTargetPc:function(a){a=void 0===a?this.index:a;return this.symbols[this.getTarget(a)].pc},getCommandAt:function(a){return this.program[a]},isSymbol:function(a){a=void 0===a?!1:a;if(this.getTarget()in this.symbols)return!0;if(a)throw Error("Unknown symbol: '"+this.getTarget()+"'");return!1},nextIsSymbol:function(a){a=void 0===a?!1:a;this.next();return this.isSymbol(a)},getSymbol:function(a){if(this.isSymbol(void 0===a? diff --git a/dist/easycoder.js b/dist/easycoder.js index 92077b9..334e620 100644 --- a/dist/easycoder.js +++ b/dist/easycoder.js @@ -3153,7 +3153,7 @@ const EasyCoder_Browser = { case `ul`: compiler.next(); if (compiler.tokenIs(`to`)) { - let cssID = null; + let cssId = null; if (compiler.nextTokenIs(`body`)) { if (type=== `div`) { cssId = `body`; @@ -3301,7 +3301,7 @@ const EasyCoder_Browser = { const command = program[program.pc]; const targetRecord = program.getSymbolRecord(command.target); const element = targetRecord.element[targetRecord.index]; - element.dispatchEvent(new Event('click')); + element.dispatchEvent(new Event(`click`)); return command.pc + 1; } }, @@ -3429,8 +3429,8 @@ const EasyCoder_Browser = { const element = targetRecord.element[targetRecord.index]; element.select(); element.setSelectionRange(0, 99999); // For mobile devices - document.execCommand("copy"); - return command.pc + 1; + document.execCommand(`copy`); + return command.pc + 1; } }, @@ -3769,9 +3769,6 @@ const EasyCoder_Browser = { }); return true; } - else { - let targetRecord = compiler.getSymbolRecord(target); - } } } compiler.addWarning(`Unrecognised syntax in 'get'`); @@ -4551,7 +4548,7 @@ const EasyCoder_Browser = { break; case `windowResize`: program.onWindowResize = command.pc + 2; - window.addEventListener('resize', function() { + window.addEventListener(`resize`, function() { program.run(program.onWindowResize); }); break; @@ -5353,28 +5350,28 @@ const EasyCoder_Browser = { } break; case `setAttributes`: - symbol = program.getSymbolRecord(command.symbolName); - target = symbol.element[symbol.index]; - if (!target) { - targetId = program.getValue(symbol.value[symbol.index]); - target = document.getElementById(targetId); - } - for (let n = target.attributes.length - 1; n >= 0; n--) { - target.removeAttribute(target.attributes[n].name); + symbol = program.getSymbolRecord(command.symbolName); + target = symbol.element[symbol.index]; + if (!target) { + targetId = program.getValue(symbol.value[symbol.index]); + target = document.getElementById(targetId); + } + for (let n = target.attributes.length - 1; n >= 0; n--) { + target.removeAttribute(target.attributes[n].name); + } + let attributes = program.getValue(command.attributes); + let list = attributes.split(` `); + for (let n = 0; n < list.length; n++) { + let attribute = list[n]; + let p = attribute.indexOf(`=`); + if (p > 0) { + target.setAttribute(attribute.substr(0, p), attribute.substr(p + 1)); } - let attributes = program.getValue(command.attributes); - let list = attributes.split(" "); - for (let n = 0; n < list.length; n++) { - let attribute = list[n]; - let p = attribute.indexOf(`=`); - if (p > 0) { - target.setAttribute(attribute.substr(0, p), attribute.substr(p + 1)); - } - else { - target.setAttribute(attribute, attribute); - } + else { + target.setAttribute(attribute, attribute); } - break; + } + break; case `setStyle`: case `setStyles`: symbol = program.getSymbolRecord(command.symbolName); @@ -5406,7 +5403,7 @@ const EasyCoder_Browser = { case `setHeadStyle`: const headStyleName = program.getValue(command.styleName); const headStyleValue = program.getValue(command.styleValue); - var style = document.createElement('style'); + var style = document.createElement(`style`); style.innerHTML = `${headStyleName} ${headStyleValue}`; for (let i = 0; i < document.head.childNodes.length; i++) { let node = document.head.childNodes[i]; @@ -5423,13 +5420,13 @@ const EasyCoder_Browser = { case `setBodyStyle`: const bodyStyleValue = program.getValue(command.styleValue); switch (command.styleName.content) { - case `background`: - document.body.style.background = bodyStyleValue; - break; - default: - program.runtimeError(command.lino, - `Unsupported body attribute '${command.styleName.content}'`); - return 0; + case `background`: + document.body.style.background = bodyStyleValue; + break; + default: + program.runtimeError(command.lino, + `Unsupported body attribute '${command.styleName.content}'`); + return 0; } break; case `setTitle`: @@ -5699,7 +5696,7 @@ const EasyCoder_Browser = { } } }; - ajax.onerror = function (data) { + ajax.onerror = function () { if (command.onError) { program.errorMessage = this.responseText; program.run(command.onError); @@ -5926,26 +5923,26 @@ const EasyCoder_Browser = { } throw new Error(`'${compiler.getToken()}' is not a symbol`); } - return null; + break; case `selected`: - let arg = compiler.nextToken(); - if ([`index`, `item`].includes(arg)) { - if ([`in`, `of`].includes(compiler.nextToken())) { - if (compiler.nextIsSymbol()) { - const symbol = compiler.getSymbolRecord(); - if ([`ul`, `ol`, `select`].includes(symbol.keyword)) { - compiler.next(); - return { - domain: `browser`, - type: `selected`, - symbol: symbol.name, - arg - }; - } + let arg = compiler.nextToken(); + if ([`index`, `item`].includes(arg)) { + if ([`in`, `of`].includes(compiler.nextToken())) { + if (compiler.nextIsSymbol()) { + const symbol = compiler.getSymbolRecord(); + if ([`ul`, `ol`, `select`].includes(symbol.keyword)) { + compiler.next(); + return { + domain: `browser`, + type: `selected`, + symbol: symbol.name, + arg + }; } } } - return null; + } + break; case `color`: compiler.next(); const value = compiler.getValue(); @@ -5971,7 +5968,7 @@ const EasyCoder_Browser = { } } } - return null; + break; case `style`: const style = compiler.getNextValue(); if (compiler.tokenIs(`of`)) { @@ -5988,7 +5985,7 @@ const EasyCoder_Browser = { } } } - return null; + break; case `confirm`: text = compiler.getNextValue(); return { @@ -6034,7 +6031,7 @@ const EasyCoder_Browser = { type: `scrollPosition` }; } - return null; + break; case `document`: if (compiler.nextTokenIs(`path`)) { compiler.next(); @@ -6043,7 +6040,7 @@ const EasyCoder_Browser = { type: `docPath` }; } - return null; + break; case `storage`: if (compiler.nextTokenIs(`keys`)) { compiler.next(); @@ -6052,7 +6049,7 @@ const EasyCoder_Browser = { type: `storageKeys` }; } - return null; + break; case `parent`: switch (compiler.nextToken()) { case `name`: @@ -6068,7 +6065,7 @@ const EasyCoder_Browser = { type: `varIndex` }; } - return null; + break; case `history`: if (compiler.nextTokenIs(`state`)) { compiler.next(); @@ -6077,7 +6074,7 @@ const EasyCoder_Browser = { type: `historyState` }; } - return null; + break; case `pick`: case `drag`: if (compiler.nextTokenIs(`position`)) { @@ -6087,6 +6084,7 @@ const EasyCoder_Browser = { type: `${type}Position` }; } + break; case `click`: const which = compiler.nextToken(); if ([`left`, `top`].includes(which)) { @@ -6097,6 +6095,7 @@ const EasyCoder_Browser = { which }; } + break; } return null; }, @@ -6145,6 +6144,11 @@ const EasyCoder_Browser = { case `textarea`: symbolRecord = program.getSymbolRecord(value.value); target = symbolRecord.element[symbolRecord.index]; + if (!target) { + program.runtimeError(program[program.pc].lino, + `Variable '${symbolRecord.name}' is not attached to a DOM element.`); + return null; + } return { type: `constant`, numeric: false, diff --git a/js/easycoder/Browser.js b/js/easycoder/Browser.js index 3c6f013..a597e56 100644 --- a/js/easycoder/Browser.js +++ b/js/easycoder/Browser.js @@ -79,7 +79,7 @@ const EasyCoder_Browser = { case `ul`: compiler.next(); if (compiler.tokenIs(`to`)) { - let cssID = null; + let cssId = null; if (compiler.nextTokenIs(`body`)) { if (type=== `div`) { cssId = `body`; @@ -227,7 +227,7 @@ const EasyCoder_Browser = { const command = program[program.pc]; const targetRecord = program.getSymbolRecord(command.target); const element = targetRecord.element[targetRecord.index]; - element.dispatchEvent(new Event('click')); + element.dispatchEvent(new Event(`click`)); return command.pc + 1; } }, @@ -355,8 +355,8 @@ const EasyCoder_Browser = { const element = targetRecord.element[targetRecord.index]; element.select(); element.setSelectionRange(0, 99999); // For mobile devices - document.execCommand("copy"); - return command.pc + 1; + document.execCommand(`copy`); + return command.pc + 1; } }, @@ -695,9 +695,6 @@ const EasyCoder_Browser = { }); return true; } - else { - let targetRecord = compiler.getSymbolRecord(target); - } } } compiler.addWarning(`Unrecognised syntax in 'get'`); @@ -1477,7 +1474,7 @@ const EasyCoder_Browser = { break; case `windowResize`: program.onWindowResize = command.pc + 2; - window.addEventListener('resize', function() { + window.addEventListener(`resize`, function() { program.run(program.onWindowResize); }); break; @@ -2279,28 +2276,28 @@ const EasyCoder_Browser = { } break; case `setAttributes`: - symbol = program.getSymbolRecord(command.symbolName); - target = symbol.element[symbol.index]; - if (!target) { - targetId = program.getValue(symbol.value[symbol.index]); - target = document.getElementById(targetId); - } - for (let n = target.attributes.length - 1; n >= 0; n--) { - target.removeAttribute(target.attributes[n].name); + symbol = program.getSymbolRecord(command.symbolName); + target = symbol.element[symbol.index]; + if (!target) { + targetId = program.getValue(symbol.value[symbol.index]); + target = document.getElementById(targetId); + } + for (let n = target.attributes.length - 1; n >= 0; n--) { + target.removeAttribute(target.attributes[n].name); + } + let attributes = program.getValue(command.attributes); + let list = attributes.split(` `); + for (let n = 0; n < list.length; n++) { + let attribute = list[n]; + let p = attribute.indexOf(`=`); + if (p > 0) { + target.setAttribute(attribute.substr(0, p), attribute.substr(p + 1)); } - let attributes = program.getValue(command.attributes); - let list = attributes.split(" "); - for (let n = 0; n < list.length; n++) { - let attribute = list[n]; - let p = attribute.indexOf(`=`); - if (p > 0) { - target.setAttribute(attribute.substr(0, p), attribute.substr(p + 1)); - } - else { - target.setAttribute(attribute, attribute); - } + else { + target.setAttribute(attribute, attribute); } - break; + } + break; case `setStyle`: case `setStyles`: symbol = program.getSymbolRecord(command.symbolName); @@ -2332,7 +2329,7 @@ const EasyCoder_Browser = { case `setHeadStyle`: const headStyleName = program.getValue(command.styleName); const headStyleValue = program.getValue(command.styleValue); - var style = document.createElement('style'); + var style = document.createElement(`style`); style.innerHTML = `${headStyleName} ${headStyleValue}`; for (let i = 0; i < document.head.childNodes.length; i++) { let node = document.head.childNodes[i]; @@ -2349,13 +2346,13 @@ const EasyCoder_Browser = { case `setBodyStyle`: const bodyStyleValue = program.getValue(command.styleValue); switch (command.styleName.content) { - case `background`: - document.body.style.background = bodyStyleValue; - break; - default: - program.runtimeError(command.lino, - `Unsupported body attribute '${command.styleName.content}'`); - return 0; + case `background`: + document.body.style.background = bodyStyleValue; + break; + default: + program.runtimeError(command.lino, + `Unsupported body attribute '${command.styleName.content}'`); + return 0; } break; case `setTitle`: @@ -2625,7 +2622,7 @@ const EasyCoder_Browser = { } } }; - ajax.onerror = function (data) { + ajax.onerror = function () { if (command.onError) { program.errorMessage = this.responseText; program.run(command.onError); @@ -2852,26 +2849,26 @@ const EasyCoder_Browser = { } throw new Error(`'${compiler.getToken()}' is not a symbol`); } - return null; + break; case `selected`: - let arg = compiler.nextToken(); - if ([`index`, `item`].includes(arg)) { - if ([`in`, `of`].includes(compiler.nextToken())) { - if (compiler.nextIsSymbol()) { - const symbol = compiler.getSymbolRecord(); - if ([`ul`, `ol`, `select`].includes(symbol.keyword)) { - compiler.next(); - return { - domain: `browser`, - type: `selected`, - symbol: symbol.name, - arg - }; - } + let arg = compiler.nextToken(); + if ([`index`, `item`].includes(arg)) { + if ([`in`, `of`].includes(compiler.nextToken())) { + if (compiler.nextIsSymbol()) { + const symbol = compiler.getSymbolRecord(); + if ([`ul`, `ol`, `select`].includes(symbol.keyword)) { + compiler.next(); + return { + domain: `browser`, + type: `selected`, + symbol: symbol.name, + arg + }; } } } - return null; + } + break; case `color`: compiler.next(); const value = compiler.getValue(); @@ -2897,7 +2894,7 @@ const EasyCoder_Browser = { } } } - return null; + break; case `style`: const style = compiler.getNextValue(); if (compiler.tokenIs(`of`)) { @@ -2914,7 +2911,7 @@ const EasyCoder_Browser = { } } } - return null; + break; case `confirm`: text = compiler.getNextValue(); return { @@ -2960,7 +2957,7 @@ const EasyCoder_Browser = { type: `scrollPosition` }; } - return null; + break; case `document`: if (compiler.nextTokenIs(`path`)) { compiler.next(); @@ -2969,7 +2966,7 @@ const EasyCoder_Browser = { type: `docPath` }; } - return null; + break; case `storage`: if (compiler.nextTokenIs(`keys`)) { compiler.next(); @@ -2978,7 +2975,7 @@ const EasyCoder_Browser = { type: `storageKeys` }; } - return null; + break; case `parent`: switch (compiler.nextToken()) { case `name`: @@ -2994,7 +2991,7 @@ const EasyCoder_Browser = { type: `varIndex` }; } - return null; + break; case `history`: if (compiler.nextTokenIs(`state`)) { compiler.next(); @@ -3003,7 +3000,7 @@ const EasyCoder_Browser = { type: `historyState` }; } - return null; + break; case `pick`: case `drag`: if (compiler.nextTokenIs(`position`)) { @@ -3013,6 +3010,7 @@ const EasyCoder_Browser = { type: `${type}Position` }; } + break; case `click`: const which = compiler.nextToken(); if ([`left`, `top`].includes(which)) { @@ -3023,6 +3021,7 @@ const EasyCoder_Browser = { which }; } + break; } return null; }, @@ -3071,6 +3070,11 @@ const EasyCoder_Browser = { case `textarea`: symbolRecord = program.getSymbolRecord(value.value); target = symbolRecord.element[symbolRecord.index]; + if (!target) { + program.runtimeError(program[program.pc].lino, + `Variable '${symbolRecord.name}' is not attached to a DOM element.`); + return null; + } return { type: `constant`, numeric: false,