diff --git a/dist/jadelet-browser.js b/dist/jadelet-browser.js index 13aa8ec..73d1a8a 100644 --- a/dist/jadelet-browser.js +++ b/dist/jadelet-browser.js @@ -586,7 +586,7 @@ ${input.slice(result.pos)} generate: generate, rules: rules }; -}, {"Template":["S",[["?","__"],["*","Line"]],{"f":"var top = a => a[a.length-1];\nfunction reduceLines(lines) {\n var depth = 0;\n var stack = [[]];\n var firstIndent = 0;\n lines.forEach( ([indent, line]) => {\n if (firstIndent === 0 && indent > depth + 1) {\n firstIndent = indent - 1;\n }\n indent = indent > firstIndent ? indent - firstIndent : indent;\n if (Array.isArray(line)) {\n line[1] = collectAttributes(line[1])\n }\n if (depth+1 === indent) {\n // We're adding to the content of the last element in the current stack\n stack.push(top(top(stack))[2])\n } else if ( indent > depth) {\n throw new Error(\"Indented too far\")\n } else if (indent < depth) {\n stack = stack.slice(0, indent + 1)\n }\n depth = indent\n top(stack).push(line)\n })\n return stack[0]\n}\nfunction collectAttributes(attributesArray) {\n return attributesArray.reduce((o, [key, value]) => {\n if (key === \"id\" || key === \"class\" || key === \"style\") {\n var p = o[key] || (o[key] = [])\n p.push(value)\n } else {\n o[key] = value\n }\n return o\n }, {})\n}\nfunction pretty(lines) {\n return lines.map(line =>\n JSON.stringify(line)\n )\n}\nvar reduced = reduceLines($2);\nif (reduced.length != 1) {\n throw new Error(\"Must have exactly one root node.\");\n}\nreturn reduced[0];"}],"Line":["S",["Indent","LineBody","EOS"],[1,2]],"LineBody":["/",[["S",["Tag",["?","DeprecatedEquals"],"_","RestOfLine"],{"f":"$1[2].push($4)\nreturn $1"}],["S",["Tag",["?","_"]],1],["S",[["L","|"],["?",["L"," "]],"RestOfLine"],{"f":"return $3 + \"\\n\";"}],["S",[["?",["S",["DeprecatedEquals","_"]]],"RestOfLine"],2]]],"RestOfLine":["R","[^\\n\\r]*",{"f":"// TODO: Handle runs of text with bound content inside\nif ($0.slice(0,1) === \"@\") {\n return {\n bind: $0.slice(1)\n }\n} else {\n return $0\n}"}],"DeprecatedEquals":["L","=",{"f":"console.warn(\"'= ' is deprecated, you can remove the '=' without issue.\")"}],"Tag":["/",[["S",["TagName","OptionalIds","OptionalClasses","OptionalAttributes"],{"f":"return [\n $1,\n $2.concat($3, $4),\n [],\n]"}],["S",["Ids","OptionalClasses","OptionalAttributes"],{"f":"return [\n \"div\",\n $1.concat($2, $3),\n [],\n]"}],["S",["Classes","OptionalAttributes"],{"f":"return [\n \"div\",\n $1.concat($2),\n [],\n]"}]]],"OptionalClasses":["/",["Classes",["L","",{"f":"return []"}]]],"Classes":["+","Class"],"Class":["/",[["S",[["L","."],"Identifier"],{"f":"return [\"class\", $2]"}],["S",[["L","."],["!","Identifier"]],{"f":"throw \"Expected a class name\""}],"IdError"]],"OptionalIds":["?","Ids",{"f":"return $1 || []"}],"Ids":["S",["Id"],{"f":"return [ $1 ]"}],"Id":["/",[["S",[["L","#"],"Identifier"],{"f":"return [\"id\", $2]"}],["S",[["L","#"],["!","Identifier"]],{"f":"throw \"Expected an id name\""}]]],"IdError":["L","#",{"f":"throw \"Ids must appear before classes and attributes. Elements can only have one id.\""}],"ClassError":["L",".",{"f":"throw \"Classes cannot appear after attributes.\""}],"TagName":"Identifier","OptionalAttributes":["/",[["S",[["L","("],["?","__"],["+","Attribute"],["L",")"],["?","IdError"],["?","ClassError"]],{"f":"return $3"}],["L","(",{"f":"throw \"Invalid attributes\""}],["L","",{"f":"return []"}]]],"Attribute":["/",[["S",["AtIdentifier",["?","__"]],{"f":"return [$1.bind, $1]"}],["S",["EqBinding",["?","__"]],1],["S",["Identifier",["?","__"]],{"f":"return [$1, \"\"]"}]]],"AtIdentifier":["S",[["L","@"],"Identifier"],{"f":"return {\n bind: $2\n}"}],"EqBinding":["S",["Identifier",["L","="],["/",["AtIdentifier","Value"]]],[1,3]],"Identifier":["R","[a-zA-Z][a-zA-Z0-9-]*"],"Indent":["*",["/",[["L"," "],["L","\\t"]]],{"f":"return $1.length"}],"_":["R","[ \\t]+"],"__":["+",["/",[["R","[ \\t]"],"EOL"]]],"Value":["/",[["S",[["L","\\\""],["*","DoubleStringCharacter"],["L","\\\""]],{"f":"return $2.join(\"\")"}],["S",[["L","'"],["*","SingleStringCharacter"],["L","'"]],{"f":"return $2.join(\"\")"}],"Number"]],"DoubleStringCharacter":["/",[["S",[["!",["/",[["L","\\\""],["L","\\\\"]]]],["R","."]],2],["S",[["L","\\\\"],"EscapeSequence"],2]]],"SingleStringCharacter":["/",[["S",[["!",["/",[["L","'"],["L","\\\\"]]]],["R","."]],2],["S",[["L","\\\\"],"EscapeSequence"],2]]],"EscapeSequence":["/",[["L","'"],["L","\\\""],["L","\\\\"],["R",".",{"f":"return \"\\\\\" + $0"}]]],"Number":["/",[["R","-?[0-9]+\\.[0-9]+"],["R","-?[0-9]+"]]],"EOS":["/",[["S",[["+",["S",[["?","_"],"EOL"]]],"_","EOF"]],["+",["S",[["?","_"],"EOL"]]],"EOF"]],"EOL":["/",[["L","\\r\\n"],["L","\\n"],["L","\\r"]]],"EOF":["!",["R","[\\s\\S]"]]})); +}, {"Template":["S",[["?","__"],["*","Line"]],{"f":"var top = a => a[a.length-1];\nfunction reduceLines(lines) {\n var depth = 0;\n var stack = [[]];\n var firstIndent = 0;\n lines.forEach( ([indent, line]) => {\n if (firstIndent === 0 && indent > depth + 1) {\n firstIndent = indent;\n indent = 1;\n }\n indent = indent > firstIndent ? indent - firstIndent : indent;\n if (Array.isArray(line)) {\n line[1] = collectAttributes(line[1])\n }\n if (depth+1 === indent) {\n // We're adding to the content of the last element in the current stack\n stack.push(top(top(stack))[2])\n } else if ( indent > depth) {\n throw new Error(\"Indented too far\")\n } else if (indent < depth) {\n stack = stack.slice(0, indent + 1)\n }\n depth = indent\n top(stack).push(line)\n })\n return stack[0]\n}\nfunction collectAttributes(attributesArray) {\n return attributesArray.reduce((o, [key, value]) => {\n if (key === \"id\" || key === \"class\" || key === \"style\") {\n var p = o[key] || (o[key] = [])\n p.push(value)\n } else {\n o[key] = value\n }\n return o\n }, {})\n}\nfunction pretty(lines) {\n return lines.map(line =>\n JSON.stringify(line)\n )\n}\nvar reduced = reduceLines($2);\nif (reduced.length != 1) {\n throw new Error(\"Must have exactly one root node.\");\n}\nreturn reduced[0];"}],"Line":["S",["Indent","LineBody","EOS"],[1,2]],"LineBody":["/",[["S",["Tag",["?","DeprecatedEquals"],"_","RestOfLine"],{"f":"$1[2].push($4)\nreturn $1"}],["S",["Tag",["?","_"]],1],["S",[["L","|"],["?",["L"," "]],"RestOfLine"],{"f":"return $3 + \"\\n\";"}],["S",[["?",["S",["DeprecatedEquals","_"]]],"RestOfLine"],2]]],"RestOfLine":["R","[^\\n\\r]*",{"f":"// TODO: Handle runs of text with bound content inside\nif ($0.slice(0,1) === \"@\") {\n return {\n bind: $0.slice(1)\n }\n} else {\n return $0\n}"}],"DeprecatedEquals":["L","=",{"f":"console.warn(\"'= ' is deprecated, you can remove the '=' without issue.\")"}],"Tag":["/",[["S",["TagName","OptionalIds","OptionalClasses","OptionalAttributes"],{"f":"return [\n $1,\n $2.concat($3, $4),\n [],\n]"}],["S",["Ids","OptionalClasses","OptionalAttributes"],{"f":"return [\n \"div\",\n $1.concat($2, $3),\n [],\n]"}],["S",["Classes","OptionalAttributes"],{"f":"return [\n \"div\",\n $1.concat($2),\n [],\n]"}]]],"OptionalClasses":["/",["Classes",["L","",{"f":"return []"}]]],"Classes":["+","Class"],"Class":["/",[["S",[["L","."],"Identifier"],{"f":"return [\"class\", $2]"}],["S",[["L","."],["!","Identifier"]],{"f":"throw \"Expected a class name\""}],"IdError"]],"OptionalIds":["?","Ids",{"f":"return $1 || []"}],"Ids":["S",["Id"],{"f":"return [ $1 ]"}],"Id":["/",[["S",[["L","#"],"Identifier"],{"f":"return [\"id\", $2]"}],["S",[["L","#"],["!","Identifier"]],{"f":"throw \"Expected an id name\""}]]],"IdError":["L","#",{"f":"throw \"Ids must appear before classes and attributes. Elements can only have one id.\""}],"ClassError":["L",".",{"f":"throw \"Classes cannot appear after attributes.\""}],"TagName":["/",[["S",["Identifier"],1],["S",[["L"," "],"Identifier"],2]]],"OptionalAttributes":["/",[["S",[["L","("],["?","__"],["+","Attribute"],["L",")"],["?","IdError"],["?","ClassError"]],{"f":"return $3"}],["L","(",{"f":"throw \"Invalid attributes\""}],["L","",{"f":"return []"}]]],"Attribute":["/",[["S",["AtIdentifier",["?","__"]],{"f":"return [$1.bind, $1]"}],["S",["EqBinding",["?","__"]],1],["S",["Identifier",["?","__"]],{"f":"return [$1, \"\"]"}]]],"AtIdentifier":["S",[["L","@"],"Identifier"],{"f":"return {\n bind: $2\n}"}],"EqBinding":["S",["Identifier",["L","="],["/",["AtIdentifier","Value"]]],[1,3]],"Identifier":["R","[a-zA-Z][a-zA-Z0-9-]*"],"Indent":["*",["/",[["L"," "],["L","\\t"]]],{"f":"return $1.length"}],"_":["R","[ \\t]+"],"__":["+",["/",[["R","[ \\t]"],"EOL"]]],"Value":["/",[["S",[["L","\\\""],["*","DoubleStringCharacter"],["L","\\\""]],{"f":"return $2.join(\"\")"}],["S",[["L","'"],["*","SingleStringCharacter"],["L","'"]],{"f":"return $2.join(\"\")"}],"Number"]],"DoubleStringCharacter":["/",[["S",[["!",["/",[["L","\\\""],["L","\\\\"]]]],["R","."]],2],["S",[["L","\\\\"],"EscapeSequence"],2]]],"SingleStringCharacter":["/",[["S",[["!",["/",[["L","'"],["L","\\\\"]]]],["R","."]],2],["S",[["L","\\\\"],"EscapeSequence"],2]]],"EscapeSequence":["/",[["L","'"],["L","\\\""],["L","\\\\"],["R",".",{"f":"return \"\\\\\" + $0"}]]],"Number":["/",[["R","-?[0-9]+\\.[0-9]+"],["R","-?[0-9]+"]]],"EOS":["/",[["S",[["+",["S",[["?","_"],"EOL"]]],"_","EOF"]],["+",["S",[["?","_"],"EOL"]]],"EOF"]],"EOL":["/",[["L","\\r\\n"],["L","\\n"],["L","\\r"]]],"EOF":["!",["R","[\\s\\S]"]]})); },{}],2:[function(require,module,exports){ // Generated by CoffeeScript 2.5.1 diff --git a/dist/jadelet-browser.min.js b/dist/jadelet-browser.min.js index f9c8854..f36d1b4 100644 --- a/dist/jadelet-browser.min.js +++ b/dist/jadelet-browser.min.js @@ -1,13 +1,13 @@ -!function(n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Jadelet=n()}(function(){return function r(u,i,o){function a(e,n){if(!i[e]){if(!u[e]){var t="function"==typeof require&&require;if(!n&&t)return t(e,!0);if(c)return c(e,!0);throw(t=new Error("Cannot find module '"+e+"'")).code="MODULE_NOT_FOUND",t}t=i[e]={exports:{}},u[e][0].call(t.exports,function(n){return a(u[e][1][n]||n)},t,t.exports,r,u,i,o)}return i[e].exports}for(var c="function"==typeof require&&require,n=0;nf?(i=S(n,e.pos),new Error(`Unconsumed input at ${i} +!function(n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Jadelet=n()}(function(){return function r(i,u,o){function a(e,n){if(!u[e]){if(!i[e]){var t="function"==typeof require&&require;if(!n&&t)return t(e,!0);if(c)return c(e,!0);throw(t=new Error("Cannot find module '"+e+"'")).code="MODULE_NOT_FOUND",t}t=u[e]={exports:{}},i[e][0].call(t.exports,function(n){return a(i[e][1][n]||n)},t,t.exports,r,i,u,o)}return u[e].exports}for(var c="function"==typeof require&&require,n=0;nf?(u=S(n,e.pos),new Error(`Unconsumed input at ${u} ${n.slice(e.pos)} -`)):r.length?(s.lastIndex=f,[u]=n.match(s),u=u.length?l(u):"EOF",new Error(`${t}:${i} Failed to parse +`)):r.length?(s.lastIndex=f,[i]=n.match(s),i=i.length?l(i):"EOF",new Error(`${t}:${u} Failed to parse Expected: \t${r.map(l).join("\n\t")} -Found: ${u}`)):new Error(`Unconsumed input at ${i} +Found: ${i}`)):new Error(`Unconsumed input at ${u} ${n.slice(e.pos)} `)},e=function(n,e={}){var t;if("string"!=typeof n)throw new Error("Input must be a string");return null==e.filename&&(e.filename="[stdin]"),t={input:n,pos:f=c=0},e.tokenize&&v(a,O),t=y(t,Object.values(d)[0]),E(n,t,e)},O=function(n,e,t){return function({value:n}){if(null==n)return n;switch(e){case"S":return{type:t,value:n.filter(function(n){return null!=n}).reduce(function(n,e){return n.concat(e)},[])};case"L":case"R":return{type:t,value:n};case"*":case"+":return{type:e,value:n};case"?":case"/":return n;case"!":case"&":return{type:e+t,value:n}}}},$=function(n,e){n=`(function(create, rules) { create(create, rules); }(${t.toString()}, ${JSON.stringify(n)})); -`;return e?(e={},Function("module",n)(e),e.exports):n},m=function(n){return null==n?"":" -> "+function(){switch(typeof n){case"number":return n;case"string":return JSON.stringify(n);case"object":return Array.isArray(n)?JSON.stringify(n):`\n${n.f.replace(/^|\n/g,"$& ")}`}}()},w=function(n,e=0){var t,r,u;if(!Array.isArray(n))return n;switch(t=n[0],r=n[2],t){case"*":case"+":case"?":return w(n[1],e+1)+t+m(r);case"&":case"!":return t+w(n[1],e+1);case"L":return'"'+n[1]+'"'+m(r);case"R":return"/"+n[1]+"/"+m(r);case"S":return u=n[1].map(function(n){return w(n,e+1)}),e<1?u.join(" ")+m(r):"( "+u.join(" ")+" )";case"/":return u=n[1].map(function(n){return w(n,e&&e+1)}),0!==e||r?"( "+u.join(" / ")+" )"+m(r):u.join("\n ")}},L=function(e){return Object.keys(e).map(function(n){return`${n}\n ${w(e[n])}\n`}).join("\n")};return v(a,n),A.exports={decompile:L,parse:e,generate:$,rules:a}})(t,{Template:["S",[["?","__"],["*","Line"]],{f:'var top = a => a[a.length-1];\nfunction reduceLines(lines) {\n var depth = 0;\n var stack = [[]];\n var firstIndent = 0;\n lines.forEach( ([indent, line]) => {\n if (firstIndent === 0 && indent > depth + 1) {\n firstIndent = indent - 1;\n }\n indent = indent > firstIndent ? indent - firstIndent : indent;\n if (Array.isArray(line)) {\n line[1] = collectAttributes(line[1])\n }\n if (depth+1 === indent) {\n // We\'re adding to the content of the last element in the current stack\n stack.push(top(top(stack))[2])\n } else if ( indent > depth) {\n throw new Error("Indented too far")\n } else if (indent < depth) {\n stack = stack.slice(0, indent + 1)\n }\n depth = indent\n top(stack).push(line)\n })\n return stack[0]\n}\nfunction collectAttributes(attributesArray) {\n return attributesArray.reduce((o, [key, value]) => {\n if (key === "id" || key === "class" || key === "style") {\n var p = o[key] || (o[key] = [])\n p.push(value)\n } else {\n o[key] = value\n }\n return o\n }, {})\n}\nfunction pretty(lines) {\n return lines.map(line =>\n JSON.stringify(line)\n )\n}\nvar reduced = reduceLines($2);\nif (reduced.length != 1) {\n throw new Error("Must have exactly one root node.");\n}\nreturn reduced[0];'}],Line:["S",["Indent","LineBody","EOS"],[1,2]],LineBody:["/",[["S",["Tag",["?","DeprecatedEquals"],"_","RestOfLine"],{f:"$1[2].push($4)\nreturn $1"}],["S",["Tag",["?","_"]],1],["S",[["L","|"],["?",["L"," "]],"RestOfLine"],{f:'return $3 + "\\n";'}],["S",[["?",["S",["DeprecatedEquals","_"]]],"RestOfLine"],2]]],RestOfLine:["R","[^\\n\\r]*",{f:'// TODO: Handle runs of text with bound content inside\nif ($0.slice(0,1) === "@") {\n return {\n bind: $0.slice(1)\n }\n} else {\n return $0\n}'}],DeprecatedEquals:["L","=",{f:"console.warn(\"'= ' is deprecated, you can remove the '=' without issue.\")"}],Tag:["/",[["S",["TagName","OptionalIds","OptionalClasses","OptionalAttributes"],{f:"return [\n $1,\n $2.concat($3, $4),\n [],\n]"}],["S",["Ids","OptionalClasses","OptionalAttributes"],{f:'return [\n "div",\n $1.concat($2, $3),\n [],\n]'}],["S",["Classes","OptionalAttributes"],{f:'return [\n "div",\n $1.concat($2),\n [],\n]'}]]],OptionalClasses:["/",["Classes",["L","",{f:"return []"}]]],Classes:["+","Class"],Class:["/",[["S",[["L","."],"Identifier"],{f:'return ["class", $2]'}],["S",[["L","."],["!","Identifier"]],{f:'throw "Expected a class name"'}],"IdError"]],OptionalIds:["?","Ids",{f:"return $1 || []"}],Ids:["S",["Id"],{f:"return [ $1 ]"}],Id:["/",[["S",[["L","#"],"Identifier"],{f:'return ["id", $2]'}],["S",[["L","#"],["!","Identifier"]],{f:'throw "Expected an id name"'}]]],IdError:["L","#",{f:'throw "Ids must appear before classes and attributes. Elements can only have one id."'}],ClassError:["L",".",{f:'throw "Classes cannot appear after attributes."'}],TagName:"Identifier",OptionalAttributes:["/",[["S",[["L","("],["?","__"],["+","Attribute"],["L",")"],["?","IdError"],["?","ClassError"]],{f:"return $3"}],["L","(",{f:'throw "Invalid attributes"'}],["L","",{f:"return []"}]]],Attribute:["/",[["S",["AtIdentifier",["?","__"]],{f:"return [$1.bind, $1]"}],["S",["EqBinding",["?","__"]],1],["S",["Identifier",["?","__"]],{f:'return [$1, ""]'}]]],AtIdentifier:["S",[["L","@"],"Identifier"],{f:"return {\n bind: $2\n}"}],EqBinding:["S",["Identifier",["L","="],["/",["AtIdentifier","Value"]]],[1,3]],Identifier:["R","[a-zA-Z][a-zA-Z0-9-]*"],Indent:["*",["/",[["L"," "],["L","\\t"]]],{f:"return $1.length"}],_:["R","[ \\t]+"],__:["+",["/",[["R","[ \\t]"],"EOL"]]],Value:["/",[["S",[["L",'\\"'],["*","DoubleStringCharacter"],["L",'\\"']],{f:'return $2.join("")'}],["S",[["L","'"],["*","SingleStringCharacter"],["L","'"]],{f:'return $2.join("")'}],"Number"]],DoubleStringCharacter:["/",[["S",[["!",["/",[["L",'\\"'],["L","\\\\"]]]],["R","."]],2],["S",[["L","\\\\"],"EscapeSequence"],2]]],SingleStringCharacter:["/",[["S",[["!",["/",[["L","'"],["L","\\\\"]]]],["R","."]],2],["S",[["L","\\\\"],"EscapeSequence"],2]]],EscapeSequence:["/",[["L","'"],["L",'\\"'],["L","\\\\"],["R",".",{f:'return "\\\\" + $0'}]]],Number:["/",[["R","-?[0-9]+\\.[0-9]+"],["R","-?[0-9]+"]]],EOS:["/",[["S",[["+",["S",[["?","_"],"EOL"]]],"_","EOF"]],["+",["S",[["?","_"],"EOL"]]],"EOF"]],EOL:["/",[["L","\\r\\n"],["L","\\n"],["L","\\r"]]],EOF:["!",["R","[\\s\\S]"]]})},{}],2:[function(n,e,t){"use strict";var r,o=n("o_0"),u=Array.prototype.forEach,i=new WeakMap,a=new WeakMap,c=function(n){var e=a.get(n)||0;a.set(n,e+1)},p=function(n){var e=a.get(n)||0;0<--e?a.set(n,e):(a.delete(n),s(n))},s=function(e){var n=e.children;null!=n&&u.call(n,s),null!=(n=i.get(e))&&n.forEach(function(n){n(),i.delete(e)})},f=function(n,e){var t;if("function"!=typeof e)throw new Error("whoops");(t=i.get(n))?t.push(e):i.set(n,[e])},l=/^on(touch|animation|transition)(start|iteration|move|end|cancel)$/,d=function(n,e){return n.match(l)||n in e},h=function(t,n,e,r){var u;switch(e){case"id":b(t,n,r,function(n){var e=n.length;e?t.id=n[e-1]:t.removeAttribute("id")});break;case"class":b(t,n,r,function(n){n=n.join(" ");n?t.className=n:t.removeAttribute("class")});break;case"style":b(t,n,r,function(n){t.removeAttribute("style"),n.forEach(function(n){return O(n)?Object.assign(t.style,n):t.setAttribute("style",n)})});break;case"value":y(t,r,n);break;case"checked":r&&O(r)&&(u=r["bind"],t.onchange=function(){"function"==typeof n[u]&&n[u](t.checked)}),v(t,r,n,function(n){t.checked=n});break;default:d(`on${e}`,t)?g(t,e,r.bind,n):v(t,r,n,function(n){null!=n&&!1!==n?t.setAttribute(e,n):t.removeAttribute(e)})}},v=function(n,e,t,r){var u,i;if($(e))return r(e);0!==(i="function"==typeof e?o(function(){r(e.call(t))}):(u=e["bind"],o(function(){r(w(t[u],t))})))._observableDependencies.size&&f(n,i.releaseDependencies)},y=function(e,n,t){var r;n&&"object"==typeof n&&(r=n["bind"],e.oninput=e.onchange=function(){"function"==typeof t[r]&&t[r](e.value)}),v(e,n,t,function(n){e.value!==n&&(e.value=n)})},g=function(n,e,t,r){t=r[t];"function"==typeof t&&n.addEventListener(e,t.bind(r))},b=function(n,e,t,r){v(n,function(){return m(t,e)},e,r)},S=function(f,e,n,t){var l=[],r=0;n.forEach(function(n,a){var c,s;if(l[a]=r,Array.isArray(n))f.appendChild(L(n,e,t)),r++;else if($(n))f.appendChild(document.createTextNode(n)),r++;else{if(!O(n))throw new Error("oof");c=0,v(f,n,e,function(n){var e,t,r,u,i,o;for(s=c,i=l[a],e=f.childNodes[i+c],o=new Array(c),u=0;u "+function(){switch(typeof n){case"number":return n;case"string":return JSON.stringify(n);case"object":return Array.isArray(n)?JSON.stringify(n):`\n${n.f.replace(/^|\n/g,"$& ")}`}}()},w=function(n,e=0){var t,r,i;if(!Array.isArray(n))return n;switch(t=n[0],r=n[2],t){case"*":case"+":case"?":return w(n[1],e+1)+t+m(r);case"&":case"!":return t+w(n[1],e+1);case"L":return'"'+n[1]+'"'+m(r);case"R":return"/"+n[1]+"/"+m(r);case"S":return i=n[1].map(function(n){return w(n,e+1)}),e<1?i.join(" ")+m(r):"( "+i.join(" ")+" )";case"/":return i=n[1].map(function(n){return w(n,e&&e+1)}),0!==e||r?"( "+i.join(" / ")+" )"+m(r):i.join("\n ")}},L=function(e){return Object.keys(e).map(function(n){return`${n}\n ${w(e[n])}\n`}).join("\n")};return v(a,n),A.exports={decompile:L,parse:e,generate:$,rules:a}})(t,{Template:["S",[["?","__"],["*","Line"]],{f:'var top = a => a[a.length-1];\nfunction reduceLines(lines) {\n var depth = 0;\n var stack = [[]];\n var firstIndent = 0;\n lines.forEach( ([indent, line]) => {\n if (firstIndent === 0 && indent > depth + 1) {\n firstIndent = indent;\n indent = 1;\n }\n indent = indent > firstIndent ? indent - firstIndent : indent;\n if (Array.isArray(line)) {\n line[1] = collectAttributes(line[1])\n }\n if (depth+1 === indent) {\n // We\'re adding to the content of the last element in the current stack\n stack.push(top(top(stack))[2])\n } else if ( indent > depth) {\n throw new Error("Indented too far")\n } else if (indent < depth) {\n stack = stack.slice(0, indent + 1)\n }\n depth = indent\n top(stack).push(line)\n })\n return stack[0]\n}\nfunction collectAttributes(attributesArray) {\n return attributesArray.reduce((o, [key, value]) => {\n if (key === "id" || key === "class" || key === "style") {\n var p = o[key] || (o[key] = [])\n p.push(value)\n } else {\n o[key] = value\n }\n return o\n }, {})\n}\nfunction pretty(lines) {\n return lines.map(line =>\n JSON.stringify(line)\n )\n}\nvar reduced = reduceLines($2);\nif (reduced.length != 1) {\n throw new Error("Must have exactly one root node.");\n}\nreturn reduced[0];'}],Line:["S",["Indent","LineBody","EOS"],[1,2]],LineBody:["/",[["S",["Tag",["?","DeprecatedEquals"],"_","RestOfLine"],{f:"$1[2].push($4)\nreturn $1"}],["S",["Tag",["?","_"]],1],["S",[["L","|"],["?",["L"," "]],"RestOfLine"],{f:'return $3 + "\\n";'}],["S",[["?",["S",["DeprecatedEquals","_"]]],"RestOfLine"],2]]],RestOfLine:["R","[^\\n\\r]*",{f:'// TODO: Handle runs of text with bound content inside\nif ($0.slice(0,1) === "@") {\n return {\n bind: $0.slice(1)\n }\n} else {\n return $0\n}'}],DeprecatedEquals:["L","=",{f:"console.warn(\"'= ' is deprecated, you can remove the '=' without issue.\")"}],Tag:["/",[["S",["TagName","OptionalIds","OptionalClasses","OptionalAttributes"],{f:"return [\n $1,\n $2.concat($3, $4),\n [],\n]"}],["S",["Ids","OptionalClasses","OptionalAttributes"],{f:'return [\n "div",\n $1.concat($2, $3),\n [],\n]'}],["S",["Classes","OptionalAttributes"],{f:'return [\n "div",\n $1.concat($2),\n [],\n]'}]]],OptionalClasses:["/",["Classes",["L","",{f:"return []"}]]],Classes:["+","Class"],Class:["/",[["S",[["L","."],"Identifier"],{f:'return ["class", $2]'}],["S",[["L","."],["!","Identifier"]],{f:'throw "Expected a class name"'}],"IdError"]],OptionalIds:["?","Ids",{f:"return $1 || []"}],Ids:["S",["Id"],{f:"return [ $1 ]"}],Id:["/",[["S",[["L","#"],"Identifier"],{f:'return ["id", $2]'}],["S",[["L","#"],["!","Identifier"]],{f:'throw "Expected an id name"'}]]],IdError:["L","#",{f:'throw "Ids must appear before classes and attributes. Elements can only have one id."'}],ClassError:["L",".",{f:'throw "Classes cannot appear after attributes."'}],TagName:["/",[["S",["Identifier"],1],["S",[["L"," "],"Identifier"],2]]],OptionalAttributes:["/",[["S",[["L","("],["?","__"],["+","Attribute"],["L",")"],["?","IdError"],["?","ClassError"]],{f:"return $3"}],["L","(",{f:'throw "Invalid attributes"'}],["L","",{f:"return []"}]]],Attribute:["/",[["S",["AtIdentifier",["?","__"]],{f:"return [$1.bind, $1]"}],["S",["EqBinding",["?","__"]],1],["S",["Identifier",["?","__"]],{f:'return [$1, ""]'}]]],AtIdentifier:["S",[["L","@"],"Identifier"],{f:"return {\n bind: $2\n}"}],EqBinding:["S",["Identifier",["L","="],["/",["AtIdentifier","Value"]]],[1,3]],Identifier:["R","[a-zA-Z][a-zA-Z0-9-]*"],Indent:["*",["/",[["L"," "],["L","\\t"]]],{f:"return $1.length"}],_:["R","[ \\t]+"],__:["+",["/",[["R","[ \\t]"],"EOL"]]],Value:["/",[["S",[["L",'\\"'],["*","DoubleStringCharacter"],["L",'\\"']],{f:'return $2.join("")'}],["S",[["L","'"],["*","SingleStringCharacter"],["L","'"]],{f:'return $2.join("")'}],"Number"]],DoubleStringCharacter:["/",[["S",[["!",["/",[["L",'\\"'],["L","\\\\"]]]],["R","."]],2],["S",[["L","\\\\"],"EscapeSequence"],2]]],SingleStringCharacter:["/",[["S",[["!",["/",[["L","'"],["L","\\\\"]]]],["R","."]],2],["S",[["L","\\\\"],"EscapeSequence"],2]]],EscapeSequence:["/",[["L","'"],["L",'\\"'],["L","\\\\"],["R",".",{f:'return "\\\\" + $0'}]]],Number:["/",[["R","-?[0-9]+\\.[0-9]+"],["R","-?[0-9]+"]]],EOS:["/",[["S",[["+",["S",[["?","_"],"EOL"]]],"_","EOF"]],["+",["S",[["?","_"],"EOL"]]],"EOF"]],EOL:["/",[["L","\\r\\n"],["L","\\n"],["L","\\r"]]],EOF:["!",["R","[\\s\\S]"]]})},{}],2:[function(n,e,t){"use strict";var r,o=n("o_0"),i=Array.prototype.forEach,u=new WeakMap,a=new WeakMap,c=function(n){var e=a.get(n)||0;a.set(n,e+1)},p=function(n){var e=a.get(n)||0;0<--e?a.set(n,e):(a.delete(n),s(n))},s=function(e){var n=e.children;null!=n&&i.call(n,s),null!=(n=u.get(e))&&n.forEach(function(n){n(),u.delete(e)})},f=function(n,e){var t;if("function"!=typeof e)throw new Error("whoops");(t=u.get(n))?t.push(e):u.set(n,[e])},l=/^on(touch|animation|transition)(start|iteration|move|end|cancel)$/,d=function(n,e){return n.match(l)||n in e},h=function(t,n,e,r){var i;switch(e){case"id":b(t,n,r,function(n){var e=n.length;e?t.id=n[e-1]:t.removeAttribute("id")});break;case"class":b(t,n,r,function(n){n=n.join(" ");n?t.className=n:t.removeAttribute("class")});break;case"style":b(t,n,r,function(n){t.removeAttribute("style"),n.forEach(function(n){return O(n)?Object.assign(t.style,n):t.setAttribute("style",n)})});break;case"value":y(t,r,n);break;case"checked":r&&O(r)&&(i=r["bind"],t.onchange=function(){"function"==typeof n[i]&&n[i](t.checked)}),v(t,r,n,function(n){t.checked=n});break;default:d(`on${e}`,t)?g(t,e,r.bind,n):v(t,r,n,function(n){null!=n&&!1!==n?t.setAttribute(e,n):t.removeAttribute(e)})}},v=function(n,e,t,r){var i,u;if($(e))return r(e);0!==(u="function"==typeof e?o(function(){r(e.call(t))}):(i=e["bind"],o(function(){r(w(t[i],t))})))._observableDependencies.size&&f(n,u.releaseDependencies)},y=function(e,n,t){var r;n&&"object"==typeof n&&(r=n["bind"],e.oninput=e.onchange=function(){"function"==typeof t[r]&&t[r](e.value)}),v(e,n,t,function(n){e.value!==n&&(e.value=n)})},g=function(n,e,t,r){t=r[t];"function"==typeof t&&n.addEventListener(e,t.bind(r))},b=function(n,e,t,r){v(n,function(){return m(t,e)},e,r)},S=function(f,e,n,t){var l=[],r=0;n.forEach(function(n,a){var c,s;if(l[a]=r,Array.isArray(n))f.appendChild(L(n,e,t)),r++;else if($(n))f.appendChild(document.createTextNode(n)),r++;else{if(!O(n))throw new Error("oof");c=0,v(f,n,e,function(n){var e,t,r,i,u,o;for(s=c,u=l[a],e=f.childNodes[u+c],o=new Array(c),i=0;i var top = a => a[a.length-1]; - + function reduceLines(lines) { var depth = 0; var stack = [[]]; @@ -9,7 +9,8 @@ Template lines.forEach( ([indent, line]) => { if (firstIndent === 0 && indent > depth + 1) { - firstIndent = indent - 1; + firstIndent = indent; + indent = 1; } indent = indent > firstIndent ? indent - firstIndent : indent; @@ -29,7 +30,7 @@ Template depth = indent top(stack).push(line) }) - + return stack[0] } @@ -115,7 +116,7 @@ Classes Class+ Class - "." Identifier -> + "." Identifier -> return ["class", $2] "." !Identifier -> throw "Expected a class name" @@ -144,7 +145,8 @@ ClassError throw "Classes cannot appear after attributes." TagName - Identifier + Identifier -> 1 + " " Identifier -> 2 OptionalAttributes "(" __? Attribute+ ")" IdError? ClassError? -> @@ -162,7 +164,7 @@ Attribute return [$1, ""] AtIdentifier - "@" Identifier -> + "@" Identifier -> return { bind: $2 }