hyperscript.org
Version:
a small scripting language for the web
1 lines • 109 kB
JavaScript
!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;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function t(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}function n(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,o(e,t)}function r(e){return r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},r(e)}function o(e,t){return o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},o(e,t)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function a(e,t,n){return a=i()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&o(i,n.prototype),i},a.apply(null,arguments)}function u(e){var t="function"==typeof Map?new Map:void 0;return u=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return a(e,arguments,r(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),o(n,e)},u(e)}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function l(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=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,h=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=l(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),v=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 a(e)||i(e)||"-"===e||"_"===e||":"===e}function n(e){return a(e)||i(e)||"-"===e||"_"===e||":"===e}function r(e){return" "===e||"\t"===e||o(e)}function o(e){return"\r"===e||"\n"===e}function i(e){return e>="0"&&e<="9"}function a(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"}function u(e,t){return"_"===e||"$"===e}function s(e,t,n){o();var r=null;function o(){for(;"WHITESPACE"===f(0,!0).type;)t.push(e.shift())}function i(e,t){y.raiseParseError(e,t)}function a(e){if(m()&&m().op&&m().value===e)return l()}function u(e,t,n,r){if(m()&&m().type&&[e,t,n,r].indexOf(m().type)>=0)return l()}function s(e,t){if(-1===p.indexOf(e))return t=t||"IDENTIFIER",m()&&m().value===e&&m().type===t?l():void 0}function l(){var n=e.shift();return t.push(n),r=n,o(),n}function c(n,r){for(var i=[],a=f(0,!0);!(null!=r&&a.type===r||null!=n&&a.value===n||"EOF"===a.type);){var u=e.shift();t.push(u),i.push(a),a=f(0,!0)}return o(),i}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:"<<<EOF>>>"}}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;r<arguments.length;r++){var o=arguments[r],i=s(o);if(i)return i}},matchAnyOpToken:function(e,t,n){for(var r=0;r<arguments.length;r++){var o=arguments[r],i=a(o);if(i)return i}},matchOpToken:a,requireOpToken:function(e){var t=a(e);if(t)return t;i(this,"Expected '"+e+"' but found '"+m().value+"'")},matchTokenType:u,requireTokenType:function(e,t,n,r){var o=u(e,t,n,r);if(o)return o;i(this,"Expected one of "+JSON.stringify([e,t,n]))},consumeToken:l,peekToken:function(t,n,r){return e[n]&&e[n].value===t&&e[n].type===r},matchToken:s,requireToken:function(e,t){var n=s(e,t);if(n)return n;i(this,"Expected '"+e+"' but found '"+m().value+"'")},list:e,consumed:t,source:n,hasMore:function(){return e.length>0},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 l(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,h=0,v=0,y=1,E="<START>",T=0;function k(){return f&&0===T}for(;h<d.length;)if("-"!==R()||"-"!==A()||!r(F())&&""!==F())if(r(R()))p.push(_());else if(M()||"."!==R()||!a(A())&&"{"!==A())if(M()||"#"!==R()||!a(A())&&"{"!==A())if("["===R()&&"@"===A())p.push(w());else if("@"===R())p.push(q());else if("*"===R()&&a(A()))p.push(S());else if(a(R())||!k()&&u(R()))p.push(L());else if(i(R()))p.push(C());else if(k()||'"'!==R()&&"`"!==R())if(k()||"'"!==R()){if(e[R()])"$"===E&&"{"===R()&&T++,"}"===R()&&T--,p.push(O());else if(k()||"`"===(m=R())||"^"===m)p.push(g("RESERVED",P()));else if(h<d.length)throw Error("Unknown token: "+R()+" ")}else l(p)?p.push(I()):p.push(O());else p.push(I());else p.push(N());else p.push(b());else x();return s(p,[],d);function g(e,t){return{type:e,value:t,start:h,end:h+1,column:v,line:y}}function x(){for(;R()&&!o(R());)P();P()}function b(){var e=g("CLASS_REF"),n=P();if("{"===R()){for(e.template=!0,n+=P();R()&&"}"!==R();)n+=P();if("}"!==R())throw Error("Unterminated class reference");n+=P()}else for(;t(R());)n+=P();return e.value=n,e.end=h,e}function w(){for(var e=g("ATTRIBUTE_REF"),t=P();h<d.length&&"]"!==R();)t+=P();return"]"===R()&&(t+=P()),e.value=t,e.end=h,e}function q(){for(var e=g("ATTRIBUTE_REF"),t=P();n(R());)t+=P();return e.value=t,e.end=h,e}function S(){for(var e=g("STYLE_REF"),t=P();a(R())||"-"===R();)t+=P();return e.value=t,e.end=h,e}function N(){var e=g("ID_REF"),t=P();if("{"===R()){for(e.template=!0,t+=P();R()&&"}"!==R();)t+=P();if("}"!==R())throw Error("Unterminated id reference");P()}else for(;n(R());)t+=P();return e.value=t,e.end=h,e}function L(){for(var e=g("IDENTIFIER"),t=P();a(R())||i(R())||u(R());)t+=P();return"!"===R()&&"beep"===t&&(t+=P()),e.value=t,e.end=h,e}function C(){for(var e=g("NUMBER"),t=P();i(R());)t+=P();for("."===R()&&i(A())&&(t+=P());i(R());)t+=P();return e.value=t,e.end=h,e}function O(){for(var t=(r=void 0,(r=g(void 0,void 0)).op=!0,r),n=P();R()&&e[n+R()];)n+=P();var r;return t.type=e[n],t.value=n,t.end=h,t}function I(){for(var e,t=g("STRING"),n=P(),r="";R()&&R()!==n;)if("\\"===R()){P();var o=P();r+="b"===o?"\b":"f"===o?"\f":"n"===o?"\n":"r"===o?"\r":"t"===o?"\t":"v"===o?"\v":o}else r+=P();if(R()!==n)throw Error("Unterminated string at [Line: "+(e=t).line+", Column: "+e.column+"]");return P(),t.value=r,t.end=h,t.template="`"===n,t}function R(){return d.charAt(h)}function A(){return d.charAt(h+1)}function F(){return d.charAt(h+2)}function P(){return E=R(),h++,v++,E}function M(){return a(E)||i(E)||")"===E||'"'===E||"'"===E||"`"===E||"}"===E||"]"===E}function _(){for(var e=g("WHITESPACE"),t="";R()&&r(R());)o(R())&&(v=0,y++),t+=P();return e.value=t,e.end=h,e}},makeTokensObject:s}}(),y=function(){var e={},t={},n={},r=[],o=[];function i(e,t,n){e.startToken=t,e.sourceFor=n.sourceFor,e.lineFor=n.lineFor,e.programSource=n.source}function a(t,n,r){return void 0===r&&(r=void 0),function(r){var o=e[t];if(o){var a=n.currentToken(),u=o(y,T,n,r);if(u)for(i(u,a,n),u.endToken=u.endToken||n.lastMatch(),r=u.root;null!=r;)i(r,a,n),r=r.root;return u}}(r)}function u(e,t,n,r){var o=a(e,t,r);return o||c(t,n||"Expected "+e),o}function s(e,t){for(var n=0;n<e.length;n++){var r=a(e[n],t);if(r)return r}}function l(t,n){e[t]=n}function c(e,t){t=(t||"Unexpected Token : "+e.currentToken().value)+"\n\n"+function(e){var t=e.currentToken(),n=e.source.split("\n"),r=n[t&&t.line?t.line-1:n.length-1];return r+"\n"+" ".repeat(t&&t.line?t.column:r.length-1)+"^^\n\n"}(e);var n=new Error(t);throw n.tokens=e,n}function f(e){return t[e.value]}function m(e){return n[e.value]}return l("feature",function(e,t,r){if(r.matchOpToken("(")){var o=e.requireElement("feature",r);return r.requireOpToken(")"),o}var i=n[r.currentToken().value];if(i)return i(e,t,r)}),l("command",function(e,n,r){if(r.matchOpToken("(")){var o=e.requireElement("command",r);return r.requireOpToken(")"),o}var i,a=t[r.currentToken().value];return a?i=a(e,n,r):"IDENTIFIER"===r.currentToken().type&&(i=e.parseElement("pseudoCommand",r)),i?e.parseElement("indirectStatement",r,i):i}),l("commandList",function(e,t,n){var r=e.parseElement("command",n);if(r){n.matchToken("then");var o=e.parseElement("commandList",n);return o&&(r.next=o),r}}),l("leaf",function(e,t,n){var o=s(r,n);return null==o?a("symbol",n):o}),l("indirectExpression",function(e,t,n,r){for(var i=0;i<o.length;i++){var a=o[i];r.endToken=n.lastMatch();var u=e.parseElement(a,n,r);if(u)return u}return r}),l("indirectStatement",function(e,t,n,r){if(n.matchToken("unless")){r.endToken=n.lastMatch();var o={type:"unlessStatementModifier",args:[e.requireElement("expression",n)],op:function(e,t){return t?this.next:r},execute:function(e){return t.unifiedExec(this,e)}};return r.parent=o,o}return r}),l("primaryExpression",function(e,t,n){var r=e.parseElement("leaf",n);if(r)return e.parseElement("indirectExpression",n,r);e.raiseParseError(n,"Unexpected value: "+n.currentToken().value)}),{setParent:function e(t,n){"object"==typeof t&&(t.parent=n,"object"==typeof n&&(n.children=n.children||new Set,n.children.add(t)),e(t.next,n))},requireElement:u,parseElement:a,featureStart:m,commandStart:f,commandBoundary:function(e){return!("end"!=e.value&&"then"!=e.value&&"else"!=e.value&&"otherwise"!=e.value&&")"!=e.value&&!f(e)&&!m(e)&&"EOF"!=e.type)},parseAnyOf:s,parseHyperScript:function(e){var t=a("hyperscript",e);if(e.hasMore()&&c(e),t)return t},raiseParseError:c,addGrammarElement:l,addCommand:function(n,r){var o=n+"Command",i=function(e,t,n){var i=r(e,t,n);if(i)return i.type=o,i.execute=function(e){return e.meta.command=i,t.unifiedExec(this,e)},i};e[o]=i,t[n]=i},addFeature:function(t,r){var o=t+"Feature",i=function(e,n,i){var a=r(e,n,i);if(a)return a.isFeature=!0,a.keyword=t,a.type=o,a};e[o]=i,n[t]=i},addLeafExpression:function(e,t){r.push(e),l(e,t)},addIndirectExpression:function(e,t){o.push(e),l(e,t)},parseStringTemplate:function(e){var t=[""];do{if(t.push(e.lastWhitespace()),"$"===e.currentToken().value){e.consumeToken();var n=e.matchOpToken("{");t.push(u("expression",e)),n&&e.requireOpToken("}"),t.push("")}else if("\\"===e.currentToken().value)e.consumeToken(),e.consumeToken();else{var r=e.consumeToken();t[t.length-1]+=r?r.value:""}}while(e.hasMore());return t.push(e.lastWhitespace()),t},ensureTerminated:function(e){for(var t={type:"implicitReturn",op:function(e){return e.meta.returned=!0,e.meta.resolve&&e.meta.resolve(),T.HALT},execute:function(e){}},n=e;n.next;)n=n.next;n.next=t}}}(),E={dynamicResolvers:[function(e,t){if("Fixed"===e)return Number(t).toFixed();if(0===e.indexOf("Fixed:")){var n=e.split(":")[1];return Number(t).toFixed(parseInt(n))}}],String:function(e){return e.toString?e.toString():""+e},Int:function(e){return parseInt(e)},Float:function(e){return parseFloat(e)},Number:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}(function(e){return Number(e)}),Date:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}(function(e){return new Date(e)}),Array:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}(function(e){return Array.from(e)}),JSON:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}(function(e){return JSON.stringify(e)}),Object:function(e){return e instanceof String&&(e=e.toString()),"string"==typeof e?JSON.parse(e):c({},e)}},T=function(){function e(e,t){var n=e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.oMatchesSelector;return n&&n.call(e,t)}function t(e,t,n,r){(n=n||{}).sender=r;var o=function(e,t){var n;return d.Event&&"function"==typeof d.Event?(n=new Event(e,{bubbles:!0,cancelable:!0})).detail=t:(n=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,t),n}(t,n);return e.dispatchEvent(o)}function r(e){return Array.isArray(e)||"undefined"!=typeof NodeList&&(e instanceof NodeList||e instanceof HTMLCollection)}function o(e){return e instanceof h||r(e)}function i(e,t){if(null==e);else if(function(e){return"object"==typeof e&&Symbol.iterator in e&&"function"==typeof e[Symbol.iterator]}(e))for(var n,o=l(e);!(n=o()).done;)t(n.value);else if(r(e))for(var i=0;i<e.length;i++)t(e[i]);else t(e)}function a(e){for(var t=0;t<e.length;t++){var n=e[t];if(n.asyncWrapper&&(e[t]=n.value),Array.isArray(n))for(var r=0;r<n.length;r++){var o=n[r];o.asyncWrapper&&(n[r]=o.value)}}}var s={};function m(e,t){var n=[t],r=!1,o=!1;if(e.args)for(var i=0;i<e.args.length;i++){var u=e.args[i];if(null==u)n.push(null);else if(Array.isArray(u)){for(var s=[],l=0;l<u.length;l++){var c=u[l];(f=c?c.evaluate(t):null)&&(f.then?r=!0:f.asyncWrapper&&(o=!0)),s.push(f)}n.push(s)}else if(u.evaluate){var f;(f=u.evaluate(t))&&(f.then?r=!0:f.asyncWrapper&&(o=!0)),n.push(f)}else n.push(u)}return r?new Promise(function(t,r){n=function(e){for(var t=[],n=0;n<e.length;n++){var r=e[n];Array.isArray(r)?t.push(Promise.all(r)):t.push(r)}return t}(n),Promise.all(n).then(function(n){o&&a(n);try{var i=e.op.apply(e,n);t(i)}catch(e){r(e)}}).catch(function(e){r(e)})}):(o&&a(n),e.op.apply(e,n))}var k=null;function g(){return null==k&&(k=p.config.attributes.replace(/ /g,"").split(",")),k}function x(e){for(var t=0;t<g().length;t++){var n=g()[t];if(e.hasAttribute&&e.hasAttribute(n))return e.getAttribute(n)}return e instanceof HTMLScriptElement&&"text/hyperscript"===e.type?e.innerText:null}var b=new WeakMap;function w(e){var t=b.get(e);return void 0===t&&b.set(e,t={}),t}function q(e,t){e&&(c(t,w(e)),q(e.parentElement,t))}function S(e,t,n,r){var o={meta:{parser:y,lexer:v,runtime:T,owner:e,feature:t,iterators:{}},me:n,event:r,target:r?r.target:null,detail:r?r.detail:null,sender:r&&r.detail?r.detail.sender:null,body:"document"in d?document.body:null};return o.meta.ctx=o,q(e,o),o}function N(e){var t=v.tokenize(e);if(y.commandStart(t.currentToken())){var n=y.requireElement("commandList",t);return t.hasMore()&&y.raiseParseError(t),y.ensureTerminated(n),n}if(y.featureStart(t.currentToken())){var r=y.requireElement("hyperscript",t);return t.hasMore()&&y.raiseParseError(t),r}var o=y.requireElement("expression",t);return t.hasMore()&&y.raiseParseError(t),o}function L(e,n){if(!e.closest||!e.closest(p.config.disableSelector)){var r=O(e);if(!r.initialized){var o=x(e);if(o)try{r.initialized=!0,r.script=o;var i=v.tokenize(o),a=y.parseHyperScript(i);if(!a)return;a.apply(n||e,e),setTimeout(function(){t(n||e,"load",{hyperscript:!0})},1)}catch(t){T.triggerEvent(e,"exception",{error:t}),console.error("hyperscript errors were found on the following element:",e,"\n\n",t.message,t.stack)}}}}var C=new WeakMap;function O(e){var t=C.get(e);return void 0===t&&C.set(e,t={}),t}function I(e){var t=e.meta&&e.meta.owner;if(t){var n=O(t),r="elementScope";return e.meta.feature&&e.meta.feature.behavior&&(r=e.meta.feature.behavior+"Scope"),f(n,r)}return{}}function R(e,t,n){if(null!=e){var r=n(e,t);if(void 0!==r)return r;if(o(e)){for(var i,a=[],u=l(e);!(i=u()).done;){var s=n(i.value,t);s&&a.push(s)}return a}}}return{typeCheck:function(e,t,n){return!(null!=e||!n)||Object.prototype.toString.call(e).slice(8,-1)===t},forEach:i,implicitLoop:function(e,t){if(o(e))for(var n,r=l(e);!(n=r()).done;)t(n.value);else t(e)},shouldAutoIterate:o,triggerEvent:t,matchesSelector:e,getScript:x,processNode:function(t){var n=T.getScriptSelector();e(t,n)&&L(t,t),t instanceof HTMLScriptElement&&"text/hyperscript"===t.type&&L(t,document.body),t.querySelectorAll&&i(t.querySelectorAll(n+", [type='text/hyperscript']"),function(e){L(e,e instanceof HTMLScriptElement&&"text/hyperscript"===e.type?document.body:e)})},evaluate:function(e,t,r){var o=function(e){function t(t){var n;return(n=e.call(this)||this).module=t,n}return n(t,e),t.prototype.toString=function(){return this.module.id},t}(u(EventTarget)),i="document"in d?d.document.body:new o(r&&r.module);t=c(S(i,null,i,null),t||{});var a=N(e);return a.execute?(a.execute(t),t.result):a.apply?(a.apply(i,i,r),w(i)):a.evaluate(t)},evaluateNoPromise:function(e,t){var n=e.evaluate(t);if(n.next)throw new Error(e.sourceFor()+" returned a Promise in a context that they are not allowed.");return n},parse:N,getScriptSelector:function(){return g().map(function(e){return"["+e+"]"}).join(", ")},resolveSymbol:function(e,t,n){if("me"===e||"my"===e||"I"===e)return t.me;if("it"===e||"its"===e)return t.result;if("you"===e||"your"===e||"yourself"===e)return t.beingTold;if("global"===n)return d[e];if("element"===n)return I(t)[e];if("local"===n)return t[e];if(t.meta&&t.meta.context){var r=t.meta.context[e];if(void 0!==r)return r}var o=t[e];return void 0!==o||void 0!==(o=I(t)[e])?o:d[e]},setSymbol:function(e,t,n,r){if("global"===n)d[e]=r;else if("element"===n)(o=I(t))[e]=r;else if("local"===n)t[e]=r;else{var o,i=t[e];void 0!==i?t[e]=r:void 0!==(i=(o=I(t))[e])?o[e]=r:t[e]=r}},makeContext:S,findNext:function e(t,n){if(t)return t.resolveNext?t.resolveNext(n):t.next?t.next:e(t.parent,n)},unifiedEval:m,convertValue:function(e,t){for(var n=E.dynamicResolvers,r=0;r<n.length;r++){var o=(0,n[r])(t,e);if(void 0!==o)return o}if(null==e)return null;var i=E[t];if(i)return i(e);throw"Unknown conversion : "+t},unifiedExec:function e(t,n){for(;;){try{var r=m(t,n)}catch(e){if(n.meta.handlingFinally)console.error(" Exception in finally block: ",e),r=s;else{if(T.registerHyperTrace(n,e),n.meta.errorHandler&&!n.meta.handlingError){n.meta.handlingError=!0,n[n.meta.errorSymbol]=e,t=n.meta.errorHandler;continue}n.meta.currentException=e,r=s}}if(null==r)return void console.error(t," did not return a next element to execute! context: ",n);if(r.then)return void r.then(function(t){e(t,n)}).catch(function(t){e({op:function(){throw t}},n)});if(r===s){if(!n.meta.finallyHandler||n.meta.handlingFinally){if(n.meta.onHalt&&n.meta.onHalt(),n.meta.currentException){if(n.meta.reject)return void n.meta.reject(n.meta.currentException);throw n.meta.currentException}return}n.meta.handlingFinally=!0,t=n.meta.finallyHandler}else t=r}},resolveProperty:function(e,t){return R(e,t,function(e,t){return e[t]})},resolveAttribute:function(e,t){return R(e,t,function(e,t){return e.getAttribute&&e.getAttribute(t)})},resolveStyle:function(e,t){return R(e,t,function(e,t){return e.style&&e.style[t]})},resolveComputedStyle:function(e,t){return R(e,t,function(e,t){return getComputedStyle(e).getPropertyValue(t)})},assignToNamespace:function(e,t,n,r){var o;for(o="undefined"!=typeof document&&e===document.body?d:w(e);t.length>0;){var i=t.shift(),a=o[i];null==a&&(o[i]=a={}),o=a}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<n.length;r++)t=Math.max(t,n[r].meta.feature.displayName.length);for(r=0;r<n.length;r++){var o=n[r];e(" ->",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:w,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=l(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_w9y.min.js",document.baseURI).href:null,HALT:s}}(),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),i=t.parseElement("namedArgumentList",r);if("send"===e&&r.matchToken("to")||"trigger"===e&&r.matchToken("on"))var a=t.requireElement("expression",r);else a=t.requireElement("implicitMeTarget",r);var u={eventName:o,details:i,to:a,args:[a,o,i],op:function(e,t,r,o){return n.nullCheck(t,a),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}};y.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}}),y.addLeafExpression("string",function(e,t,n){var r=n.matchTokenType("STRING");if(r){var o,i=r.value;if(r.template){var a=v.tokenize(i,!0);o=e.parseStringTemplate(a)}else o=[];return{type:"string",token:r,args:o,op:function(e){for(var t="",n=1;n<arguments.length;n++){var r=arguments[n];void 0!==r&&(t+=r)}return t},evaluate:function(e){return 0===o.length?i:t.unifiedEval(this,e)}}}}),y.addGrammarElement("nakedString",function(e,t,n){if(n.hasMore()){var r=n.consumeUntilWhitespace();return n.matchTokenType("WHITESPACE"),{type:"nakedString",tokens:r,evaluate:function(e){return r.map(function(e){return e.value}).join("")}}}}),y.addLeafExpression("number",function(e,t,n){var r=n.matchTokenType("NUMBER");if(r){var o=r,i=parseFloat(r.value);return{type:"number",value:i,numberToken:o,evaluate:function(){return i}}}}),y.addLeafExpression("idRef",function(e,t,n){var r=n.matchTokenType("ID_REF");if(r){if(r.template){var o=r.value.substr(2,r.value.length-2),i=v.tokenize(o);return{type:"idRefTemplate",args:[e.requireElement("expression",i)],op:function(e,n){return t.getRootNode(e.me).getElementById(n)},evaluate:function(e){return t.unifiedEval(this,e)}}}var a=r.value.substr(1);return{type:"idRef",css:r.value,value:a,evaluate:function(e){return t.getRootNode(e.me).getElementById(a)}}}}),y.addLeafExpression("classRef",function(e,t,n){var r=n.matchTokenType("CLASS_REF");if(r){if(r.template){var o=r.value.substr(2,r.value.length-2),i=v.tokenize(o);return{type:"classRefTemplate",args:[e.requireElement("expression",i)],op:function(e,t){return new h("."+t,e.me,!0)},evaluate:function(e){return t.unifiedEval(this,e)}}}var a=r.value;return{type:"classRef",css:a,evaluate:function(e){return new h(a,e.me,!0)}}}});var w=function(e,r){function o(t,n,r){var o;return(o=e.call(this,t,n)||this).templateParts=r,o.elements=r.filter(function(e){return e instanceof Element}),o}return n(o,e),o.prototype[r]=function(){this.elements.forEach(function(e,t){return e.dataset.hsQueryId=t});var t=e.prototype[Symbol.iterator].call(this);return this.elements.forEach(function(e){return e.removeAttribute("data-hs-query-id")}),t},t(o,[{key:"css",get:function(){for(var e,t="",n=0,r=l(this.templateParts);!(e=r()).done;){var o=e.value;o instanceof Element?t+="[data-hs-query-id='"+n+++"']":t+=o}return t}}]),o}(h,Symbol.iterator);y.addLeafExpression("queryRef",function(e,t,n){if(n.matchOpToken("<")){var r=n.consumeUntil("/");n.requireOpToken("/"),n.requireOpToken(">");var o=r.map(function(e){return"STRING"===e.type?'"'+e.value+'"':e.value}).join("");if(o.indexOf("$")>=0)var i=!0,a=v.tokenize(o,!0),u=e.parseStringTemplate(a);return{type:"queryRef",css:o,args:u,op:function(e){return i?new w(o,e.me,[].slice.call(arguments,1)):new h(o,e.me)},evaluate:function(e){return t.unifiedEval(this,e)}}}}),y.addLeafExpression("attributeRef",function(e,t,n){var r=n.matchTokenType("ATTRIBUTE_REF");if(r){var o=r.value;if(0===o.indexOf("["))var i=o.substring(2,o.length-1);else i=o.substring(1);var a="["+i+"]",u=i.split("="),s=u[0],l=u[1];return l&&0===l.indexOf('"')&&(l=l.substring(1,l.length-1)),{type:"attributeRef",name:s,css:a,value:l,op:function(e){var t=e.beingTold||e.me;if(t)return t.getAttribute(s)},evaluate:function(e){return t.unifiedEval(this,e)}}}}),y.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)}}}}),y.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 i="";do{(r=n.matchTokenType("IDENTIFIER")||n.matchOpToken("-"))&&(i+=r.value)}while(r);return{type:"objectKey",key:i,evaluate:function(){return i}}}),y.addLeafExpression("objectLiteral",function(e,t,n){if(n.matchOpToken("{")){var r=[],o=[];if(!n.matchOpToken("}")){do{var i=e.requireElement("objectKey",n);n.requireOpToken(":");var a=e.requireElement("expression",n);o.push(a),r.push(i)}while(n.matchOpToken(","));n.requireOpToken("}")}return{type:"objectLiteral",args:[r,o],op:function(e,t,n){for(var r={},o=0;o<t.length;o++)r[t[o]]=n[o];return r},evaluate:function(e){return t.unifiedEval(this,e)}}}}),y.addGrammarElement("nakedNamedArgumentList",function(e,t,n){var r=[],o=[];if("IDENTIFIER"===n.currentToken().type)do{var i=n.requireTokenType("IDENTIFIER");n.requireOpToken(":");var a=e.requireElement("expression",n);o.push(a),r.push({name:i,value:a})}while(n.matchOpToken(","));return{type:"namedArgumentList",fields:r,args:[o],op:function(e,t){for(var n={_namedArgList_:!0},o=0;o<t.length;o++)n[r[o].name.value]=t[o];return n},evaluate:function(e){return t.unifiedEval(this,e)}}}),y.addGrammarElement("namedArgumentList",function(e,t,n){if(n.matchOpToken("(")){var r=e.requireElement("nakedNamedArgumentList",n);return n.requireOpToken(")"),r}}),y.addGrammarElement("symbol",function(e,t,n){var r="default";n.matchToken("global")?r="global":n.matchToken("element")||n.matchToken("module")?(r="element",n.matchOpToken("'")&&n.requireToken("s")):n.matchToken("local")&&(r="local");var o=n.matchOpToken(":"),i=n.matchTokenType("IDENTIFIER");if(i){var a=i.value;return o&&(a=":"+a),"default"===r&&(0===a.indexOf("$")&&(r="global"),0===a.indexOf(":")&&(r="element")),{type:"symbol",token:i,scope:r,name:a,evaluate:function(e){return t.resolveSymbol(a,e,r)}}}}),y.addGrammarElement("implicitMeTarget",function(e,t,n){return{type:"implicitMeTarget",evaluate:function(e){return e.beingTold||e.me}}}),y.addLeafExpression("boolean",function(e,t,n){var r=n.matchToken("true")||n.matchToken("false");if(r){var o="true"===r.value;return{type:"boolean",evaluate:function(e){return o}}}}),y.addLeafExpression("null",function(e,t,n){if(n.matchToken("null"))return{type:"null",evaluate:function(e){return null}}}),y.addLeafExpression("arrayLiteral",function(e,t,n){if(n.matchOpToken("[")){var r=[];if(!n.matchOpToken("]")){do{var o=e.requireElement("expression",n);r.push(o)}while(n.matchOpToken(","));n.requireOpToken("]")}return{type:"arrayLiteral",values:r,args:[r],op:function(e,t){return t},evaluate:function(e){return t.unifiedEval(this,e)}}}}),y.addLeafExpression("blockLiteral",function(e,t,n){if(n.matchOpToken("\\")){var r=[],o=n.matchTokenType("IDENTIFIER");if(o)for(r.push(o);n.matchOpToken(",");)r.push(n.requireTokenType("IDENTIFIER"));n.requireOpToken("-"),n.requireOpToken(">");var i=e.requireElement("expression",n);return{type:"blockLiteral",args:r,expr:i,evaluate:function(e){return function(){for(var t=0;t<r.length;t++)e[r[t].value]=arguments[t];return i.evaluate(e)}}}}}),y.addIndirectExpression("propertyAccess",function(e,t,n,r){if(n.matchOpToken(".")){var o=n.requireTokenType("IDENTIFIER");return e.parseElement("indirectExpression",n,{type:"propertyAccess",root:r,prop:o,args:[r],op:function(e,n){return t.resolveProperty(n,o.value)},evaluate:function(e){return t.unifiedEval(this,e)}})}}),y.addIndirectExpression("of",function(e,t,n,r){if(n.matchToken("of")){for(var o=e.requireElement("unaryExpression",n),i=null,a=r;a.root;)i=a,a=a.root;"symbol"!==a.type&&"attributeRef"!==a.type&&"styleRef"!==a.type&&"computedStyleRef"!==a.type&&e.raiseParseError(n,"Cannot take a property of a non-symbol: "+a.type);var u="attributeRef"===a.type,s="styleRef"===a.type||"computedStyleRef"===a.type;if(u||s)var l=a;var c=a.name,f={type:"ofExpression",prop:a.token,root:o,attribute:l,expression:r,args:[o],op:function(e,n){return u?t.resolveAttribute(n,c):s?"computedStyleRef"===a.type?t.resolveComputedStyle(n,c):t.resolveStyle(n,c):t.resolveProperty(n,c)},evaluate:function(e){return t.unifiedEval(this,e)}};return"attributeRef"===a.type&&(f.attribute=a),i?(i.root=f,i.args=[f]):r=f,e.parseElement("indirectExpression",n,r)}}),y.addIndirectExpression("possessive",function(e,t,n,r){if(!e.possessivesDisabled){var o=n.matchOpToken("'");if(o||"symbol"===r.type&&("my"===r.name||"its"===r.name||"your"===r.name)&&("IDENTIFIER"===n.currentToken().type||"ATTRIBUTE_REF"===n.currentToken().type||"STYLE_REF"===n.currentToken().type)){o&&n.requireToken("s");var i=e.parseElement("attributeRef",n);if(null==i){var a=e.parseElement("styleRef",n);if(null==a)var u=n.requireTokenType("IDENTIFIER")}return e.parseElement("indirectExpression",n,{type:"possessive",root:r,attribute:i||a,prop:u,args:[r],op:function(e,n){if(i)var r=t.resolveAttribute(n,i.name);else r=a?"computedStyleRef"===a.type?t.resolveComputedStyle(n,a.name):t.resolveStyle(n,a.name):t.resolveProperty(n,u.value);return r},evaluate:function(e){return t.unifiedEval(this,e)}})}}}),y.addIndirectExpression("inExpression",function(e,t,n,r){if(n.matchToken("in")){var o={type:"inExpression",root:r,args:[r,e.requireElement("unaryExpression",n)],op:function(e,n,r){var o=[];if(n.css)t.implicitLoop(r,function(e){for(var t=e.querySelectorAll(n.css),r=0;r<t.length;r++)o.push(t[r])});else if(n instanceof Element){var i=!1;if(t.implicitLoop(r,function(e){e.contains(n)&&(i=!0)}),i)return n}else t.implicitLoop(n,function(e){t.implicitLoop(r,function(t){e===t&&o.push(e)})});return o},evaluate:function(e){return t.unifiedEval(this,e)}};return e.parseElement("indirectExpression",n,o)}}),y.addIndirectExpression("asExpression",function(e,t,n,r){if(n.matchToken("as")){n.matchToken("a")||n.matchToken("an");var o=e.requireElement("dotOrColonPath",n).evaluate();return e.parseElement("indirectExpression",n,{type:"asExpression",root:r,args:[r],op:function(e,n){return t.convertValue(n,o)},evaluate:function(e){return t.unifiedEval(this,e)}})}}),y.addIndirectExpression("functionCall",function(e,t,n,r){if(n.matchOpToken("(")){var o=[];if(!n.matchOpToken(")")){do{o.push(e.requireElement("expression",n))}while(n.matchOpToken(","));n.requireOpToken(")")}if(r.root)var i={type:"functionCall",root:r,argExressions:o,args:[r.root,o],op:function(e,n,o){t.nullCheck(n,r.root);var i=n[r.prop.value];return t.nullCheck(i,r),i.hyperfunc&&o.push(e),i.apply(n,o)},evaluate:function(e){return t.unifiedEval(this,e)}};else i={type:"functionCall",root:r,argExressions:o,args:[r,o],op:function(e,n,o){return t.nullCheck(n,r),n.hyperfunc&&o.push(e),n.apply(null,o)},evaluate:function(e){return t.unifiedEval(this,e)}};return e.parseElement("indirectExpression",n,i)}}),y.addIndirectExpression("attributeRefAccess",function(e,t,n,r){var o=e.parseElement("attributeRef",n);if(o)return{type:"attributeRefAccess",root:r,attribute:o,args:[r],op:function(e,n){return t.resolveAttribute(n,o.name)},evaluate:function(e){return T.unifiedEval(this,e)}}}),y.addIndirectExpression("arrayIndex",function(e,t,n,r){if(n.matchOpToken("[")){var o=!1,i=!1,a=null,u=null;n.matchOpToken("..")?(o=!0,a=e.requireElement("expression",n)):(a=e.requireElement("expression",n),n.matchOpToken("..")&&(i=!0,"R_BRACKET"!==n.currentToken().type&&(u=e.parseElement("expression",n)))),n.requireOpToken("]");var s={type:"arrayIndex",root:r,prop:a,firstIndex:a,secondIndex:u,args:[r,a,u],op:function(e,t,n,r){return null==t?null:o?(n<0&&(n=t.length+n),t.slice(0,n+1)):i?null!=r?(r<0&&(r=t.length+r),t.slice(n,r+1)):t.slice(n):t[n]},evaluate:function(e){return T.unifiedEval(this,e)}};return y.parseElement("indirectExpression",n,s)}});var q=["em","ex","cap","ch","ic","rem","lh","rlh","vw","vh","vi","vb","vmin","vmax","cm","mm","Q","pc","pt","px"];y.addGrammarElement("postfixExpression",function(e,t,n){var r=e.parseElement("primaryExpression",n),o=n.matchAnyToken.apply(n,q)||n.matchOpToken("%");if(o)return{type:"stringPostfix",postfix:o.value,args:[r],op:function(e,t){return""+t+o.value},evaluate:function(e){return t.unifiedEval(this,e)}};var i=null;if(n.matchToken("s")||n.matchToken("seconds")?i=1e3:(n.matchToken("ms")||n.matchToken("milliseconds"))&&(i=1),i)return{type:"timeExpression",time:r,factor:i,args:[r],op:function(e,t){return t*i},evaluate:function(e){return t.unifiedEval(this,e)}};if(n.matchOpToken(":")){var a=n.requireTokenType("IDENTIFIER"),u=!n.matchOpToken("!");return{type:"typeCheck",typeName:a,nullOk:u,args:[r],op:function(e,n){if(t.typeCheck(n,a.value,u))return n;throw new Error("Typecheck failed! Expected: "+a.value)},evaluate:function(e){return t.unifiedEval(this,e)}}}return r}),y.addGrammarElement("logicalNot",function(e,t,n){if(n.matchToken("not")){var r=e.requireElement("unaryExpression",n);return{type:"logicalNot",root:r,args:[r],op:function(e,t){return!t},evaluate:function(e){return t.unifiedEval(this,e)}}}}),y.addGrammarElement("noExpression",function(e,t,n){if(n.matchToken("no")){var r=e.requireElement("unaryExpression",n);return{type:"noExpression",root:r,args:[r],op:function(e,n){return t.isEmpty(n)},evaluate:function(e){return t.unifiedEval(this,e)}}}}),y.addLeafExpression("some",function(e,t,n){if(n.matchToken("some")){var r=e.requireElement("expression",n);return{type:"noExpression",root:r,args:[r],op:function(e,n){return!t.isEmpty(n)},evaluate:function(e){return t.unifiedEval(this,e)}}}}),y.addGrammarElement("negativeNumber",function(e,t,n){if(n.matchOpToken("-")){var r=e.requireElement("unaryExpression",n);return{type:"negativeNumber",root:r,args:[r],op:function(e,t){return-1*t},evaluate:function(e){return t.unifiedEval(this,e)}}}}),y.addGrammarElement("unaryExpression",function(e,t,n){return n.matchToken("the"),e.parseAnyOf(["beepExpression","logicalNot","relativePositionalExpression","positionalExpression","noExpression","negativeNumber","postfixExpression"],n)}),y.addGrammarElement("beepExpression",function(e,t,n){if(n.matchToken("beep!")){var r=e.parseElement("unaryExpression",n);if(r){r.booped=!0;var o=r.evaluate;return r.evaluate=function(e){var n=o.apply(r,arguments),i=e.me;if(t.triggerEvent(i,"hyperscript:beep",{element:i,expression:r,value:n})){var a,u=n;"String"===(a=n?n instanceof h?"ElementCollection":n.constructor?n.constructor.name:"unknown":"object (null)")?u='"'+u+'"':n instanceof h&&(u=Array.from(n)),console.log("///_ BEEP! The expression ("+r.sourceFor().substr(6)+") evaluates to:",u,"of type "+a)}return n},r}}});var S=function(e,t,n,r){var o=[];T.forEach(t,function(t){(t.matches(n)||t===e)&&o.push(t)});for(var i=0;i<o.length-1;i++)if(o[i]===e)return o[i+1];if(r){var a=o[0];if(a&&a.matches(n))return a}};y.addGrammarElement("relativePositionalExpression",function(e,t,n){var r=n.matchAnyToken("next","previous");if(r){if("next"===r.value)var o=!0;var i=e.parseElement("expression",n);if(n.matchToken("from")){n.pushFollow("in");try{var a=e.requireElement("unaryExpression",n)}finally{n.popFollow()}}else a=e.requireElement("implicitMeTarget",n);var u,s=!1;if(n.matchToken("in")){s=!0;var l=e.requireElement("unaryExpression",n)}else u=n.matchToken("within")?e.requireElement("unaryExpression",n):document.body;var c=!1;return n.matchToken("with")&&(n.requireToken("wrapping"),c=!0),{type:"relativePositionalExpression",from:a,forwardSearch:o,inSearch:s,wrapping:c,inElt:l,withinElt:u,operator:r.value,args:[i,a,l,u],op:function(e,t,n,r,i){var a,u,l=t.css;if(null==l)throw"Expected a CSS value";if(s){if(r)return o?S(n,r,l,c):(a=l,u=c,S(n,Array.from(r).reverse(),a,u))}else if(i)return o?function(e,t,n,r){for(var o=t.querySelectorAll(n),i=0;i<o.length;i++){var a=o[i];if(a.compareDocumentPosition(e)===Node.DOCUMENT_POSITION_PRECEDING)return a}if(r)return o[0]}(n,i,l,c):function(e,t,n,r){for(var o=t.querySelectorAll(n),i=o.length-1;i>=0;i--){var a=o[i];if(a.compareDocumentPosition(e)===Node.DOCUMENT_POSITION_FOLLOWING)return a}if(r)return o[o.length-1]}(n,i,l,c)},evaluate:function(e){return t.unifiedEval(this,e)}}}}),y.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),i=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"===i)return t[0];if("last"===i)return t[t.length-1];if("random"===i)return t[Math.floor(Math.random()*t.length)]}},evaluate:function(e){return t.unifiedEval(this,e)}}}}),y.addGrammarElement("mathOperator",function(e,t,n){var r,o=e.parseElement("unaryExpression",n),i=null;for(r=n.matchAnyOpToken("+","-","*","/","%");r;){var a=r.value;(i=i||r).value!==a&&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:a,args:[o,u],op:function(e,t,n){return"+"===a?t+n:"-"===a?t-n:"*"===a?t*n:"/"===a?t/n:"%"===a?t%n:void 0},evaluate:function(e){return t.unifiedEval(this,e)}},r=n.matchAnyOpToken("+","-","*","/","%")}return o}),y.addGrammarElement("mathExpression",function(e,t,n){return e.parseAnyOf(["mathOperator","unaryExpression"],n)}),y.addGrammarElement("comparisonOperator",function(e,t,n){var r=e.parseElement("mathExpression",n),o=n.matchAnyOpToken("<",">","<=",">=","==","===","!=","!=="),i=o?o.value:null,a=!0,u=!1;if(null==i&&(n.matchToken("is")||n.matchToken("am")?n.matchToken("not")?n.matchToken("in")?i="not in":n.matchToken("a")?(i="not a",u=!0):n.matchToken("empty")?(i="not empty",a=!1):i="!=":n.matchToken("in")?i="in":n.matchToken("a")?(i="a",u=!0):n.matchToken("empty")?(i="empty",a=!1):n.matchToken("less")?(n.requireToken("than"),n.matchToken("or")?(n.requireToken("equal"),n.requireToken("to"),i="<="):i="<"):n.matchToken("greater")?(n.requireToken("than"),n.matchToken("or")?(n.requireToken("equal"),n.requireToken("to"),i=">="):i=">"):i="==":n.matchToken("exist")||n.matchToken("exists")?(i="exist",a=!1):n.matchToken("matches")||n.matchToken("match")?i="match":n.matchToken("contains")||n.matchToken("contain")?i="contain":n.matchToken("includes")||n.matchToken("include")?i="include":(n.matchToken("do")||n.matchToken("does"))&&(n.requireToken("not"),n.matchToken("matches")||n.matchToken("match")?i="not match":n.matchToken("contains")||n.matchToken("contain")?i="not contain":n.matchToken("exist")||n.matchToken("exist")?(i="not exist",a=!1):n.matchToken("include")?i="not include":e.raiseParseError(n,"Expected matches or contains"))),i){if(u)var s=n.requireTokenType("IDENTIFIER"),l=!n.matchOpToken("!");else if(a){var c=e.requireElement("mathExpression",n);"match"!==i&&"not match"!==i||(c=c.css?c.css:c)}var f=r;r={type:"comparisonOperator",operator:i,typeName:s,nullOk:l,lhs:r,rhs:c,args:[r,c],op:function(e,n,r){if("=="===i)return n==r;if("!="===i)return n!=r;if("match"===i)return null!=n&&g(f,n,r);if("not match"===i)return null==n||!g(f,n,r);if("in"===i)return null!=r&&k(c,r,n);if("not in"===i)return null==r||!k(c,r,n);if("contain"===i)return null!=n&&k(f,n,r);if("not contain"===i)return null==n||!k(f,n,r);if("include"===i)return null!=n&&k(f,n,r);if("not include"===i)return null==n||!k(f,n,r);if("==="===i)return n===r;if("!=="===i)return n!==r;if("<"===i)return n<r;if(">"===i)return n>r;if("<="===i)return n<=r;if(">="===i)return n>=r;if("empty"===i)return t.isEmpty(n);if("not empty"===i)return!t.isEmpty(n);if("exist"===i)return t.doesExist(n);if("not exist"===i)return!t.doesExist(n);if("a"===i)return t.typeCheck(n,s.value,l);if("not a"===i)return!t.typeCheck(n,s.value,l);throw"Unknown comparison : "+i},evaluate:function(e){return t.unifiedEval(this,e)}}}return r}),y.addGrammarElement("comparisonExpression",function(e,t,n){return e.parseAnyOf(["comparisonOperator","mathExpression"],n)}),y.addGrammarElement("logicalOperator",function(e,t,n){var r,o=e.parseElement("comparisonExpression",n),i=null;r=n.matchToken("and")||n.matchToken("or");for(var a=function(){(i=i||r).value!==r.value&&e.raiseParseError(n,"You must parenthesize logical operations with different operators"),u=e.requireElement("comparisonExpression",n);var a=r.value;o={type:"logicalOperator",operator:a,lhs:o,rhs:u,args:[o,u],op:function(e,t,n){return"and"===a?t&&n:t||n},evaluate:function(e){return t.unifiedEval(this,e)}},r=n.matchToken("and")||n.matchToken("or")};r;){var u;a()}return o}),y.addGrammarElement("logicalExpression",function(e,t,n){return e.parseAnyOf(["logicalOperator","mathExpression"],n)}),y.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)}),y.addGrammarElement("expression",function(e,t,n){return n.matchToken("the"),e.parseElement("asyncExpression",n)}),y.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?(y.raiseParseError(n,"A target expression must be writable. The expression type '"+(r&&r.type)+"' is not."),r):r}),y.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,i=l(r);!(o=i()).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};y.addFeature("on",function(e,t,n){if(n.matchToken("on")){var r=!1;n.matchToken("every")&&(r=!0);var o=[],i=null;do{var a=e.requireElement("eventName",n,"Expected event name").evaluate();i=i?i+" or "+a:"on "+a;var u=N(n),s=null;if(n.matchOpToken("[")&&(s=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 h=!0;n.requireToken("on")}}if("intersection"===a){var v={};if(n.matchToken("with")&&(v.with=e.requireElement("expression",n).evaluate()),n.matchToken("having"))do{n.matchToken("margin")?v.rootMargin=e.requireElement("stringLike",n).evaluate():n.matchToken("threshold")?v.threshold=e.requireElement("expression",n).evaluate():e.raiseParseError(n,"Unknown intersection config specification")}while(n.matchToken("and"))}else if("mutation"===a){var y={};if(n.matchToken("of"))do{if(n.matchToken("anything"))y.attributes=!0,y.subtree=!0,y.characterData=!0,y.childList=!0;else if(n.matchToken("childList"))y.childList=!0;else if(n.matchToken("attributes"))y.attributes=!0,y.attributeOldValue=!0;else if(n.matchToken("subtree"))y.subtree=!0;else if(n.matchToken("characterData"))y.characterData=!0,y.characterDataOldValue=!0;else if("ATTRIBUTE_REF"===n.currentToken().type){var E=n.consumeToken();null==y.attributeFilter&&(y.attributeFilter=[]),0==E.value.indexOf("@")?y.attributeFilter.push(E.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 y.attributes=!0,y.characterData=!0,y.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 w=e.requireElement("expression",n).evaluate({})}o.push({execCount:0,every:r,on:a,args:u,filter:s,from:k,inExpr:x,elsewhere:g,startCount:m,endCount:d,unbounded:h,debounceTime:b,throttleTime:w,mutationSpec:y,intersectionSpec:v,debounced:void 0,lastExec:void 0})}while(n.matchToken("or"));var q=!0;if(!r&&n.matchToken("queue"))if(n.matchToken("all"))q=!1;else if(n.matchToken("first"))var S=!0;else if(n.matchToken("none"))var L=!0;else n.requireToken("last");var C=e.requireElement("commandList",n);if(e.ensureTerminated(C),n.matchToken("catch")){var O=n.requireTokenType("IDENTIFIER").value,I=e.requireElement("commandList",n);e.ensureTerminated(I)}if(n.matchToken("finally")){var R=e.requireElement("commandList",n);e.ensureTerminated(R)}var A={displayName:i,events:o,start:C,every:r,execCount:0,errorHandler:I,errorSymbol:O,execute:function(e){var n=t.getEventQueueFor(e.me,A);if(n.executing&&!1===r){if(L||S&&n.queue.length>0)return;return q&&(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})},C.execute(e)},install:function(e,n){for(var r,o=function(){var n=r.value;a=n.elsewhere?[document]:n.from?n.from.evaluate(t.makeContext(e,A,e,null)):[e],t.implicitLoop(a,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 i=new IntersectionObserver(function(e){for(var t,n=l(e);!(t=n()).done;){var a=t.value,u={observer:i};(u=c(u,a)).intersecting=a.isIntersecting,T.triggerEvent(r,o,u)}},n.intersectionSpec);i.observe(r)}(r.addEventListener||r.on).call(r,o,function i(a){if("undefined"!=typeof Node&&e instanceof Node&&r!==e&&!e.isConnected)r.removeEventListener(o,i);else{var u=t.makeContext(e,A,e,a);if(!n.elsewhere||!e.contains(a.target)){n.from&&(u.result=r);for(var s,c=l(n.args);!(s=c()).done;){var f=s.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