!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self)._hyperscript=t()}(this,function(){function e(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}function f(e,t){var n=e[t];if(n)return n;var r={};return e[t]=r,r}function m(e,t){return new(e.bind.apply(e,[e].concat(t)))}var p,d=globalThis,v=function(e){function n(e,t,n){this._css=e,this.relativeToElement=t,this.escape=n}var r=n.prototype;return r.contains=function(e){for(var t,n=s(this);!(t=n()).done;)if(t.value.contains(e))return!0;return!1},r[e]=function(){return this.selectMatches()[Symbol.iterator]()},r.selectMatches=function(){return T.getRootNode(this.relativeToElement).querySelectorAll(this.css)},t(n,[{key:"css",get:function(){return this.escape?T.escapeSelector(this._css):this._css}},{key:"className",get:function(){return this._css.substr(1)}},{key:"id",get:function(){return this.className()}},{key:"length",get:function(){return this.selectMatches().length}}]),n}(Symbol.iterator),h=function(){var e={"+":"PLUS","-":"MINUS","*":"MULTIPLY","/":"DIVIDE",".":"PERIOD","..":"ELLIPSIS","\\":"BACKSLASH",":":"COLON","%":"PERCENT","|":"PIPE","!":"EXCLAMATION","?":"QUESTION","#":"POUND","&":"AMPERSAND",$:"DOLLAR",";":"SEMI",",":"COMMA","(":"L_PAREN",")":"R_PAREN","<":"L_ANG",">":"R_ANG","<=":"LTE_ANG",">=":"GTE_ANG","==":"EQ","===":"EQQ","!=":"NEQ","!==":"NEQQ","{":"L_BRACE","}":"R_BRACE","[":"L_BRACKET","]":"R_BRACKET","=":"EQUALS"};function t(e){return i(e)||a(e)||"-"===e||"_"===e||":"===e}function n(e){return i(e)||a(e)||"-"===e||"_"===e||":"===e}function r(e){return" "===e||"\t"===e||o(e)}function o(e){return"\r"===e||"\n"===e}function a(e){return e>="0"&&e<="9"}function i(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"}function u(e,t){return"_"===e||"$"===e}function l(e,t,n){o();var r=null;function o(){for(;"WHITESPACE"===f(0,!0).type;)t.push(e.shift())}function a(e,t){E.raiseParseError(e,t)}function i(e){if(m()&&m().op&&m().value===e)return s()}function u(e,t,n,r){if(m()&&m().type&&[e,t,n,r].indexOf(m().type)>=0)return s()}function l(e,t){if(-1===p.indexOf(e))return t=t||"IDENTIFIER",m()&&m().value===e&&m().type===t?s():void 0}function s(){var n=e.shift();return t.push(n),r=n,o(),n}function c(n,r){for(var a=[],i=f(0,!0);!(null!=r&&i.type===r||null!=n&&i.value===n||"EOF"===i.type);){var u=e.shift();t.push(u),a.push(i),i=f(0,!0)}return o(),a}function f(t,n){var r,o=0;do{if(!n)for(;e[o]&&"WHITESPACE"===e[o].type;)o++;r=e[o],t--,o++}while(t>-1);return r||{type:"EOF",value:"<<>>"}}function m(){return f(0)}var p=[];return{pushFollow:function(e){p.push(e)},popFollow:function(){p.pop()},clearFollow:function(){var e=p;return p=[],e},restoreFollow:function(e){p=e},matchAnyToken:function(e,t,n){for(var r=0;r0},currentToken:m,lastMatch:function(){return r},token:f,consumeUntil:c,consumeUntilWhitespace:function(){return c(null,"WHITESPACE")},lastWhitespace:function(){return t[t.length-1]&&"WHITESPACE"===t[t.length-1].type?t[t.length-1].value:""},sourceFor:function(){return n.substring(this.startToken.start,this.endToken.end)},lineFor:function(){return n.split("\n")[this.startToken.line-1]}}}function s(e){if(e.length>0){var t=e[e.length-1];if("IDENTIFIER"===t.type||"CLASS_REF"===t.type||"ID_REF"===t.type)return!1;if(t.op&&(">"===t.value||")"===t.value))return!1}return!0}return{tokenize:function(c,f){var m,p=[],d=c,v=0,h=0,E=1,y="",T=0;function k(){return f&&0===T}for(;v0;){var a=t.shift(),i=o[a];null==i&&(o[a]=i={}),o=i}o[n]=r},registerHyperTrace:function(e,t){for(var n=[],r=null;null!=e;)n.push(e),r=e,e=e.meta.caller;null==r.meta.traceMap&&(r.meta.traceMap=new Map),r.meta.traceMap.get(t)||r.meta.traceMap.set(t,{trace:n,print:function(e){(e=e||console.error)("hypertrace /// ");for(var t=0,r=0;r",o.meta.feature.displayName.padEnd(t+2),"-",o.meta.owner)}}})},getHyperTrace:function(e,t){for(var n=e;n.meta.caller;)n=n.meta.caller;if(n.meta.traceMap)return n.meta.traceMap.get(t,[])},getInternalData:O,getHyperscriptFeatures:q,escapeSelector:function(e){return e.replace(/:/g,function(e){return"\\"+e})},nullCheck:function(e,t){if(null==e)throw new Error("'"+t.sourceFor()+"' is null")},isEmpty:function(e){return null==e||0===e.length},doesExist:function(e){if(null==e)return!1;if(o(e))for(var t=s(e);!t().done;)return!0;return!1},getRootNode:function(e){if(e&&e instanceof Node){var t=e.getRootNode();if(t instanceof Document||t instanceof ShadowRoot)return t}return document},getEventQueueFor:function(e,t){var n=O(e),r=n.eventQueues;null==r&&(r=new Map,n.eventQueues=r);var o=r.get(t);return null==o&&r.set(t,o={queue:[],executing:!1}),o},hyperscriptUrl:"document"in d?"undefined"==typeof document&&"undefined"==typeof location?new(require("url").URL)("file:"+__filename).href:"undefined"==typeof document?location.href:document.currentScript&&document.currentScript.src||new URL("_hyperscript_web.min.js",document.baseURI).href:null,HALT:l}}(),k=function(e,t,n){if(t.contains)return t.contains(n);if(t.includes)return t.includes(n);throw Error("The value of "+e.sourceFor()+" does not have a contains or includes method on it")},g=function(e,t,n){if(t.match)return!!t.match(n);if(t.matches)return t.matches(n);throw Error("The value of "+e.sourceFor()+" does not have a match or matches method on it")},x=function(e,t,n,r){var o=t.requireElement("eventName",r),a=t.parseElement("namedArgumentList",r);if("send"===e&&r.matchToken("to")||"trigger"===e&&r.matchToken("on"))var i=t.requireElement("expression",r);else i=t.requireElement("implicitMeTarget",r);var u={eventName:o,details:a,to:i,args:[i,o,a],op:function(e,t,r,o){return n.nullCheck(t,i),n.forEach(t,function(t){n.triggerEvent(t,r,o,e.me)}),n.findNext(u,e)}};return u},b=function(e,t){var n,r="text";return e.matchToken("a")||e.matchToken("an"),e.matchToken("json")||e.matchToken("Object")?r="json":e.matchToken("response")?r="response":e.matchToken("html")?r="html":e.matchToken("text")||(n=t.requireElement("dotOrColonPath",e).evaluate()),{type:r,conversion:n}};E.addLeafExpression("parenthesized",function(e,t,n){if(n.matchOpToken("(")){var r=n.clearFollow();try{var o=e.requireElement("expression",n)}finally{n.restoreFollow(r)}return n.requireOpToken(")"),o}}),E.addLeafExpression("string",function(e,t,n){var r=n.matchTokenType("STRING");if(r){var o,a=r.value;if(r.template){var i=h.tokenize(a,!0);o=e.parseStringTemplate(i)}else o=[];return{type:"string",token:r,args:o,op:function(e){for(var t="",n=1;n");var o=r.map(function(e){return"STRING"===e.type?'"'+e.value+'"':e.value}).join("");if(o.indexOf("$")>=0)var a=!0,i=h.tokenize(o,!0),u=e.parseStringTemplate(i);return{type:"queryRef",css:o,args:u,op:function(e){return a?new q(o,e.me,[].slice.call(arguments,1)):new v(o,e.me)},evaluate:function(e){return t.unifiedEval(this,e)}}}}),E.addLeafExpression("attributeRef",function(e,t,n){var r=n.matchTokenType("ATTRIBUTE_REF");if(r){var o=r.value;if(0===o.indexOf("["))var a=o.substring(2,o.length-1);else a=o.substring(1);var i="["+a+"]",u=a.split("="),l=u[0],s=u[1];return s&&0===s.indexOf('"')&&(s=s.substring(1,s.length-1)),{type:"attributeRef",name:l,css:i,value:s,op:function(e){var t=e.beingTold||e.me;if(t)return t.getAttribute(l)},evaluate:function(e){return t.unifiedEval(this,e)}}}}),E.addLeafExpression("styleRef",function(e,t,n){var r=n.matchTokenType("STYLE_REF");if(r){var o=r.value.substr(1);return o.startsWith("computed-")?{type:"computedStyleRef",name:o=o.substr("computed-".length),op:function(e){var n=e.beingTold||e.me;if(n)return t.resolveComputedStyle(n,o)},evaluate:function(e){return t.unifiedEval(this,e)}}:{type:"styleRef",name:o,op:function(e){var n=e.beingTold||e.me;if(n)return t.resolveStyle(n,o)},evaluate:function(e){return t.unifiedEval(this,e)}}}}),E.addGrammarElement("objectKey",function(e,t,n){var r;if(r=n.matchTokenType("STRING"))return{type:"objectKey",key:r.value,evaluate:function(){return r.value}};if(n.matchOpToken("[")){var o=e.parseElement("expression",n);return n.requireOpToken("]"),{type:"objectKey",expr:o,args:[o],op:function(e,t){return t},evaluate:function(e){return t.unifiedEval(this,e)}}}var a="";do{(r=n.matchTokenType("IDENTIFIER")||n.matchOpToken("-"))&&(a+=r.value)}while(r);return{type:"objectKey",key:a,evaluate:function(){return a}}}),E.addLeafExpression("objectLiteral",function(e,t,n){if(n.matchOpToken("{")){var r=[],o=[];if(!n.matchOpToken("}")){do{var a=e.requireElement("objectKey",n);n.requireOpToken(":");var i=e.requireElement("expression",n);o.push(i),r.push(a)}while(n.matchOpToken(","));n.requireOpToken("}")}return{type:"objectLiteral",args:[r,o],op:function(e,t,n){for(var r={},o=0;o");var a=e.requireElement("expression",n);return{type:"blockLiteral",args:r,expr:a,evaluate:function(e){return function(){for(var t=0;t=0;a--){var i=o[a];if(i.compareDocumentPosition(e)===Node.DOCUMENT_POSITION_FOLLOWING)return i}if(r)return o[o.length-1]}(n,a,s,c)},evaluate:function(e){return t.unifiedEval(this,e)}}}}),E.addGrammarElement("positionalExpression",function(e,t,n){var r=n.matchAnyToken("first","last","random");if(r){n.matchAnyToken("in","from","of");var o=e.requireElement("unaryExpression",n),a=r.value;return{type:"positionalExpression",rhs:o,operator:r.value,args:[o],op:function(e,t){if(t&&!Array.isArray(t)&&(t=t.children?t.children:Array.from(t)),t){if("first"===a)return t[0];if("last"===a)return t[t.length-1];if("random"===a)return t[Math.floor(Math.random()*t.length)]}},evaluate:function(e){return t.unifiedEval(this,e)}}}}),E.addGrammarElement("mathOperator",function(e,t,n){var r,o=e.parseElement("unaryExpression",n),a=null;for(r=n.matchAnyOpToken("+","-","*","/","%");r;){var i=r.value;(a=a||r).value!==i&&e.raiseParseError(n,"You must parenthesize math operations with different operators");var u=e.parseElement("unaryExpression",n);o={type:"mathOperator",lhs:o,rhs:u,operator:i,args:[o,u],op:function(e,t,n){return"+"===i?t+n:"-"===i?t-n:"*"===i?t*n:"/"===i?t/n:"%"===i?t%n:void 0},evaluate:function(e){return t.unifiedEval(this,e)}},r=n.matchAnyOpToken("+","-","*","/","%")}return o}),E.addGrammarElement("mathExpression",function(e,t,n){return e.parseAnyOf(["mathOperator","unaryExpression"],n)}),E.addGrammarElement("comparisonOperator",function(e,t,n){var r=e.parseElement("mathExpression",n),o=n.matchAnyOpToken("<",">","<=",">=","==","===","!=","!=="),a=o?o.value:null,i=!0,u=!1;if(null==a&&(n.matchToken("is")||n.matchToken("am")?n.matchToken("not")?n.matchToken("in")?a="not in":n.matchToken("a")?(a="not a",u=!0):n.matchToken("empty")?(a="not empty",i=!1):a="!=":n.matchToken("in")?a="in":n.matchToken("a")?(a="a",u=!0):n.matchToken("empty")?(a="empty",i=!1):n.matchToken("less")?(n.requireToken("than"),n.matchToken("or")?(n.requireToken("equal"),n.requireToken("to"),a="<="):a="<"):n.matchToken("greater")?(n.requireToken("than"),n.matchToken("or")?(n.requireToken("equal"),n.requireToken("to"),a=">="):a=">"):a="==":n.matchToken("exist")||n.matchToken("exists")?(a="exist",i=!1):n.matchToken("matches")||n.matchToken("match")?a="match":n.matchToken("contains")||n.matchToken("contain")?a="contain":n.matchToken("includes")||n.matchToken("include")?a="include":(n.matchToken("do")||n.matchToken("does"))&&(n.requireToken("not"),n.matchToken("matches")||n.matchToken("match")?a="not match":n.matchToken("contains")||n.matchToken("contain")?a="not contain":n.matchToken("exist")||n.matchToken("exist")?(a="not exist",i=!1):n.matchToken("include")?a="not include":e.raiseParseError(n,"Expected matches or contains"))),a){if(u)var l=n.requireTokenType("IDENTIFIER"),s=!n.matchOpToken("!");else if(i){var c=e.requireElement("mathExpression",n);"match"!==a&&"not match"!==a||(c=c.css?c.css:c)}var f=r;r={type:"comparisonOperator",operator:a,typeName:l,nullOk:s,lhs:r,rhs:c,args:[r,c],op:function(e,n,r){if("=="===a)return n==r;if("!="===a)return n!=r;if("match"===a)return null!=n&&g(f,n,r);if("not match"===a)return null==n||!g(f,n,r);if("in"===a)return null!=r&&k(c,r,n);if("not in"===a)return null==r||!k(c,r,n);if("contain"===a)return null!=n&&k(f,n,r);if("not contain"===a)return null==n||!k(f,n,r);if("include"===a)return null!=n&&k(f,n,r);if("not include"===a)return null==n||!k(f,n,r);if("==="===a)return n===r;if("!=="===a)return n!==r;if("<"===a)return n"===a)return n>r;if("<="===a)return n<=r;if(">="===a)return n>=r;if("empty"===a)return t.isEmpty(n);if("not empty"===a)return!t.isEmpty(n);if("exist"===a)return t.doesExist(n);if("not exist"===a)return!t.doesExist(n);if("a"===a)return t.typeCheck(n,l.value,s);if("not a"===a)return!t.typeCheck(n,l.value,s);throw"Unknown comparison : "+a},evaluate:function(e){return t.unifiedEval(this,e)}}}return r}),E.addGrammarElement("comparisonExpression",function(e,t,n){return e.parseAnyOf(["comparisonOperator","mathExpression"],n)}),E.addGrammarElement("logicalOperator",function(e,t,n){var r,o=e.parseElement("comparisonExpression",n),a=null;r=n.matchToken("and")||n.matchToken("or");for(var i=function(){(a=a||r).value!==r.value&&e.raiseParseError(n,"You must parenthesize logical operations with different operators"),u=e.requireElement("comparisonExpression",n);var i=r.value;o={type:"logicalOperator",operator:i,lhs:o,rhs:u,args:[o,u],op:function(e,t,n){return"and"===i?t&&n:t||n},evaluate:function(e){return t.unifiedEval(this,e)}},r=n.matchToken("and")||n.matchToken("or")};r;){var u;i()}return o}),E.addGrammarElement("logicalExpression",function(e,t,n){return e.parseAnyOf(["logicalOperator","mathExpression"],n)}),E.addGrammarElement("asyncExpression",function(e,t,n){return n.matchToken("async")?{type:"asyncExpression",value:e.requireElement("logicalExpression",n),evaluate:function(e){return{asyncWrapper:!0,value:this.value.evaluate(e)}}}:e.parseElement("logicalExpression",n)}),E.addGrammarElement("expression",function(e,t,n){return n.matchToken("the"),e.parseElement("asyncExpression",n)}),E.addGrammarElement("assignableExpression",function(e,t,n){n.matchToken("the");var r=e.parseElement("primaryExpression",n);return!r||"symbol"!==r.type&&"ofExpression"!==r.type&&"propertyAccess"!==r.type&&"attributeRefAccess"!==r.type&&"attributeRef"!==r.type&&"styleRef"!==r.type&&"arrayIndex"!==r.type&&"possessive"!==r.type?(E.raiseParseError(n,"A target expression must be writable. The expression type '"+(r&&r.type)+"' is not."),r):r}),E.addGrammarElement("hyperscript",function(e,t,n){var r=[];if(n.hasMore())for(;e.featureStart(n.currentToken())||"("===n.currentToken().value;){var o=e.requireElement("feature",n);r.push(o),n.matchToken("end")}return{type:"hyperscript",features:r,apply:function(e,t,n){for(var o,a=s(r);!(o=a()).done;)o.value.install(e,t,n)}}});var N=function(e){var t=[];if("("===e.token(0).value&&(")"===e.token(1).value||","===e.token(2).value||")"===e.token(2).value)){e.matchOpToken("(");do{t.push(e.requireTokenType("IDENTIFIER"))}while(e.matchOpToken(","));e.requireOpToken(")")}return t};E.addFeature("on",function(e,t,n){if(n.matchToken("on")){var r=!1;n.matchToken("every")&&(r=!0);var o=[],a=null;do{var i=e.requireElement("eventName",n,"Expected event name").evaluate();a=a?a+" or "+i:"on "+i;var u=N(n),l=null;if(n.matchOpToken("[")&&(l=e.requireElement("expression",n),n.requireOpToken("]")),"NUMBER"===n.currentToken().type){var f=n.consumeToken(),m=parseInt(f.value);if(n.matchToken("to"))var p=n.consumeToken(),d=parseInt(p.value);else if(n.matchToken("and")){var v=!0;n.requireToken("on")}}if("intersection"===i){var h={};if(n.matchToken("with")&&(h.with=e.requireElement("expression",n).evaluate()),n.matchToken("having"))do{n.matchToken("margin")?h.rootMargin=e.requireElement("stringLike",n).evaluate():n.matchToken("threshold")?h.threshold=e.requireElement("expression",n).evaluate():e.raiseParseError(n,"Unknown intersection config specification")}while(n.matchToken("and"))}else if("mutation"===i){var E={};if(n.matchToken("of"))do{if(n.matchToken("anything"))E.attributes=!0,E.subtree=!0,E.characterData=!0,E.childList=!0;else if(n.matchToken("childList"))E.childList=!0;else if(n.matchToken("attributes"))E.attributes=!0,E.attributeOldValue=!0;else if(n.matchToken("subtree"))E.subtree=!0;else if(n.matchToken("characterData"))E.characterData=!0,E.characterDataOldValue=!0;else if("ATTRIBUTE_REF"===n.currentToken().type){var y=n.consumeToken();null==E.attributeFilter&&(E.attributeFilter=[]),0==y.value.indexOf("@")?E.attributeFilter.push(y.value.substring(1)):e.raiseParseError(n,"Only shorthand attribute references are allowed here")}else e.raiseParseError(n,"Unknown mutation config specification")}while(n.matchToken("or"));else E.attributes=!0,E.characterData=!0,E.childList=!0}var k=null,g=!1;if(n.matchToken("from")&&(n.matchToken("elsewhere")?g=!0:(k=e.parseElement("expression",n))||e.raiseParseError(n,'Expected either target value or "elsewhere".')),null===k&&!1===g&&n.matchToken("elsewhere")&&(g=!0),n.matchToken("in"))var x=e.parseElement("unaryExpression",n);if(n.matchToken("debounced")){n.requireToken("at");var b=e.requireElement("expression",n).evaluate({})}else if(n.matchToken("throttled")){n.requireToken("at");var q=e.requireElement("expression",n).evaluate({})}o.push({execCount:0,every:r,on:i,args:u,filter:l,from:k,inExpr:x,elsewhere:g,startCount:m,endCount:d,unbounded:v,debounceTime:b,throttleTime:q,mutationSpec:E,intersectionSpec:h,debounced:void 0,lastExec:void 0})}while(n.matchToken("or"));var w=!0;if(!r&&n.matchToken("queue"))if(n.matchToken("all"))w=!1;else if(n.matchToken("first"))var S=!0;else if(n.matchToken("none"))var I=!0;else n.requireToken("last");var R=e.requireElement("commandList",n);if(e.ensureTerminated(R),n.matchToken("catch")){var O=n.requireTokenType("IDENTIFIER").value,L=e.requireElement("commandList",n);e.ensureTerminated(L)}if(n.matchToken("finally")){var C=e.requireElement("commandList",n);e.ensureTerminated(C)}var A={displayName:a,events:o,start:R,every:r,execCount:0,errorHandler:L,errorSymbol:O,execute:function(e){var n=t.getEventQueueFor(e.me,A);if(n.executing&&!1===r){if(I||S&&n.queue.length>0)return;return w&&(n.queue.length=0),void n.queue.push(e)}A.execCount++,n.executing=!0,e.meta.onHalt=function(){n.executing=!1;var e=n.queue.shift();e&&setTimeout(function(){A.execute(e)},1)},e.meta.reject=function(n){console.error(n.message?n.message:n);var r=t.getHyperTrace(e,n);r&&r.print(),t.triggerEvent(e.me,"exception",{error:n})},R.execute(e)},install:function(e,n){for(var r,o=function(){var n=r.value;i=n.elsewhere?[document]:n.from?n.from.evaluate(t.makeContext(e,A,e,null)):[e],t.implicitLoop(i,function(r){var o=n.on;if(n.mutationSpec&&(o="hyperscript:mutation",new MutationObserver(function(e,t){A.executing||T.triggerEvent(r,o,{mutationList:e,observer:t})}).observe(r,n.mutationSpec)),n.intersectionSpec){o="hyperscript:insersection";var a=new IntersectionObserver(function(e){for(var t,n=s(e);!(t=n()).done;){var i=t.value,u={observer:a};(u=c(u,i)).intersecting=i.isIntersecting,T.triggerEvent(r,o,u)}},n.intersectionSpec);a.observe(r)}(r.addEventListener||r.on).call(r,o,function a(i){if("undefined"!=typeof Node&&e instanceof Node&&r!==e&&!e.isConnected)r.removeEventListener(o,a);else{var u=t.makeContext(e,A,e,i);if(!n.elsewhere||!e.contains(i.target)){n.from&&(u.result=r);for(var l,c=s(n.args);!(l=c()).done;){var f=l.value,m=u.event[f.value];void 0!==m?u[f.value]=m:"detail"in u.event&&(u[f.value]=u.event.detail[f.value])}if(u.meta.errorHandler=L,u.meta.errorSymbol=O,u.meta.finallyHandler=C,n.filter){var p=u.meta.context;u.meta.context=u.event;try{if(!n.filter.evaluate(u))return}finally{u.meta.context=p}}if(n.inExpr)for(var d=i.target;;){if(d.matches&&d.matches(n.inExpr.css)){u.result=d;break}if(null==(d=d.parentElement))return}if(n.execCount++,n.startCount)if(n.endCount){if(n.execCountn.endCount)return}else if(n.unbounded){if(n.execCount