summitjs 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(){'use strict';var L,G=[],de=0,ne=new Set;function j(n,e={}){let t=mn(n,e);return e.lazy||t(),t}function mn(n,e){let t=function(){if(!t.active)return n();if(!G.includes(t)){_e(t);try{return G.push(t),L=t,n()}finally{G.pop(),L=G[G.length-1];}}};return t.deps=[],t.active=true,t.scheduler=e.scheduler,t.onStop=e.onStop,t.raw=n,t}function _e(n){let{deps:e}=n;for(let t of e)t.delete(n);e.length=0;}function me(n){n.active&&(_e(n),n.onStop?.(),n.active=false);}function O(n){L&&(n.has(L)||(n.add(L),L.deps.push(n)));}function C(n){let e=[...n];for(let t of e)if(t!==L){if(de>0){ne.add(t);continue}Je(t);}}function Je(n){n.scheduler?n.scheduler():n();}function he(n){de++;try{return n()}finally{--de===0&&hn();}}function hn(){if(ne.size===0)return;let n=[...ne];ne.clear();for(let e of n)e.active&&Je(e);}function ve(n){let e=n,t=new Set,r=function(){return O(t),e};return r.set=s=>{let i=typeof s=="function"?s(e):s;Object.is(i,e)||(e=i,C(t));},r.peek=()=>e,r}function q(n){let e,t=true,r=new Set,s=j(n,{lazy:true,scheduler:()=>{t||(t=true,C(r));}}),i=function(){return t&&(e=s(),t=false),O(r),e};return i.peek=()=>(t&&(e=s(),t=false),e),i}var be=Symbol("summit.raw"),ye=Symbol("summit.iterate"),xe=new WeakMap,Ye=new WeakMap;function vn(n,e){let t=xe.get(n);t||xe.set(n,t=new Map);let r=t.get(e);return r||t.set(e,r=new Set),r}function ge(n,e){O(vn(n,e));}function _(n,e){let t=xe.get(n);if(!t)return;let r=t.get(e);r&&C(r);}function Ze(n){return n!==null&&typeof n=="object"}function yn(n){let e=Object.getPrototypeOf(n);return e===Object.prototype||e===null}function Xe(n){return Ze(n)&&(Array.isArray(n)||yn(n))}var gn={get(n,e,t){if(e===be)return n;let r=Reflect.get(n,e,t);return typeof e=="symbol"?r:(ge(n,e),Xe(r)?w(r):r)},set(n,e,t,r){let s=Ze(t)?we(t):t,i=Array.isArray(n),o=i?Number(e)<n.length:Object.prototype.hasOwnProperty.call(n,e),a=n[e],c=Reflect.set(n,e,s,r);return o?Object.is(a,s)||_(n,e):(_(n,e),_(n,i?"length":ye)),c},has(n,e){return ge(n,e),Reflect.has(n,e)},deleteProperty(n,e){let t=Object.prototype.hasOwnProperty.call(n,e),r=Reflect.deleteProperty(n,e);return t&&r&&(_(n,e),_(n,ye)),r},ownKeys(n){return ge(n,Array.isArray(n)?"length":ye),Reflect.ownKeys(n)}};function w(n){if(!Xe(n)||n[be])return n;let e=Ye.get(n);if(e)return e;let t=new Proxy(n,gn);return Ye.set(n,t),t}function we(n){let e=n&&n[be];return e?we(e):n}var Ee=new Set,ke=false,Pe=null,Qe=Promise.resolve();function Se(n){Ee.add(n),ke||(ke=true,Pe=Qe.then(xn));}function xn(){let n=[...Ee];Ee.clear(),ke=false,Pe=null;for(let e of n)e();}function J(n){let e=Pe??Qe;return n?e.then(()=>{n();}):e.then(()=>{})}function T(n){let e;return e=j(n,{lazy:true,scheduler:()=>Se(e)}),e(),()=>me(e)}var Ae=new Map,Te=new Map,Ve=new Map,Re=w({}),et=new Map,De=100;function h(n,e,t=De){Ae.set(n,{handler:e,priority:t});}function re(n){return Ae.get(n)}function tt(){return [...Ae.keys()]}function y(n,e){Te.set(n,e);}function se(n){return Te.get(n)}function nt(){return [...Te.keys()]}function rt(n,e){Ve.set(n,e);}function Me(n){return Ve.get(n)}function Le(n,e){Re[n]=e;}function je(n){return Re[n]}function st(){return Re}function it(n,e){et.set(n,e);}function ot(n){return et.get(n)}function Y(n){let e=w(n),t=Object.getOwnPropertyDescriptors(n);for(let r of Object.keys(t)){let s=t[r];if(typeof s.get=="function"){let i=s.get,o=s.set,a=q(()=>i.call(e));Object.defineProperty(n,r,{get:()=>a(),set:o?c=>o.call(e,c):void 0,enumerable:s.enumerable,configurable:true});}else typeof s.value=="function"&&(n[r]=s.value.bind(e));}return e}var bn=new Set(["return","typeof","void","in","instanceof","new","of","delete","do","else"]);function wn(n){if(!n)return true;switch(n.type){case "num":case "str":case "tmpl":case "regex":return false;case "ident":return bn.has(n.value);case "punc":return n.value!==")"&&n.value!=="]";default:return true}}var En=["...","===","!==","**=","&&=","||=","??=","==","!=","<=",">=","&&","||","??","?.","=>","++","--","+=","-=","*=","/=","%=","**","(",")","[","]","{","}",".",",",";",":","?","+","-","*","/","%","<",">","=","!"],I=class extends Error{};function kn(n){return /[A-Za-z_$]/.test(n)}function Pn(n){return /[A-Za-z0-9_$]/.test(n)}function Z(n){return n>="0"&&n<="9"}function at(n){let e=[],t=0,r=n.length;for(;t<r;){let s=n[t];if(s===" "||s===" "||s===`
1
+ (function(){'use strict';var L,G=[],de=0,ne=new Set;function j(n,e={}){let t=mn(n,e);return e.lazy||t(),t}function mn(n,e){let t=function(){if(!t.active)return n();if(!G.includes(t)){_e(t);try{return G.push(t),L=t,n()}finally{G.pop(),L=G[G.length-1];}}};return t.deps=[],t.active=true,t.scheduler=e.scheduler,t.onStop=e.onStop,t.raw=n,t}function _e(n){let{deps:e}=n;for(let t of e)t.delete(n);e.length=0;}function me(n){n.active&&(_e(n),n.onStop?.(),n.active=false);}function O(n){L&&(n.has(L)||(n.add(L),L.deps.push(n)));}function C(n){if(n.size===0)return;let e=[...n];for(let t of e)if(t!==L){if(de>0){ne.add(t);continue}Je(t);}}function Je(n){n.scheduler?n.scheduler():n();}function he(n){de++;try{return n()}finally{--de===0&&hn();}}function hn(){if(ne.size===0)return;let n=ne;ne=new Set;for(let e of n)e.active&&Je(e);}function ve(n){let e=n,t=new Set,r=function(){return O(t),e};return r.set=s=>{let i=typeof s=="function"?s(e):s;Object.is(i,e)||(e=i,C(t));},r.peek=()=>e,r}function q(n){let e,t=true,r=new Set,s=j(n,{lazy:true,scheduler:()=>{t||(t=true,C(r));}}),i=function(){return t&&(e=s(),t=false),O(r),e};return i.peek=()=>(t&&(e=s(),t=false),e),i}var be=Symbol("summit.raw"),ye=Symbol("summit.iterate"),xe=new WeakMap,Ye=new WeakMap;function vn(n,e){let t=xe.get(n);t||xe.set(n,t=new Map);let r=t.get(e);return r||t.set(e,r=new Set),r}function ge(n,e){O(vn(n,e));}function _(n,e){let t=xe.get(n);if(!t)return;let r=t.get(e);r&&C(r);}function Ze(n){return n!==null&&typeof n=="object"}function yn(n){let e=Object.getPrototypeOf(n);return e===Object.prototype||e===null}function Xe(n){return Ze(n)&&(Array.isArray(n)||yn(n))}var gn={get(n,e,t){if(e===be)return n;let r=Reflect.get(n,e,t);return typeof e=="symbol"?r:(ge(n,e),Xe(r)?w(r):r)},set(n,e,t,r){let s=Ze(t)?we(t):t,i=Array.isArray(n),o=i?Number(e)<n.length:Object.prototype.hasOwnProperty.call(n,e),a=n[e],c=Reflect.set(n,e,s,r);return o?Object.is(a,s)||_(n,e):(_(n,e),_(n,i?"length":ye)),c},has(n,e){return ge(n,e),Reflect.has(n,e)},deleteProperty(n,e){let t=Object.prototype.hasOwnProperty.call(n,e),r=Reflect.deleteProperty(n,e);return t&&r&&(_(n,e),_(n,ye)),r},ownKeys(n){return ge(n,Array.isArray(n)?"length":ye),Reflect.ownKeys(n)}};function w(n){if(!Xe(n)||n[be])return n;let e=Ye.get(n);if(e)return e;let t=new Proxy(n,gn);return Ye.set(n,t),t}function we(n){let e=n&&n[be];return e?we(e):n}var Ee=new Set,ke=false,Pe=null,Qe=Promise.resolve();function Se(n){Ee.add(n),ke||(ke=true,Pe=Qe.then(xn));}function xn(){let n=Ee;Ee=new Set,ke=false,Pe=null;for(let e of n)e();}function J(n){let e=Pe??Qe;return n?e.then(()=>{n();}):e.then(()=>{})}function T(n){let e;return e=j(n,{lazy:true,scheduler:()=>Se(e)}),e(),()=>me(e)}var Ae=new Map,Te=new Map,Ve=new Map,Re=w({}),et=new Map,De=100;function h(n,e,t=De){Ae.set(n,{handler:e,priority:t});}function re(n){return Ae.get(n)}function tt(){return [...Ae.keys()]}function y(n,e){Te.set(n,e);}function se(n){return Te.get(n)}function nt(){return [...Te.keys()]}function rt(n,e){Ve.set(n,e);}function Me(n){return Ve.get(n)}function Le(n,e){Re[n]=e;}function je(n){return Re[n]}function st(){return Re}function it(n,e){et.set(n,e);}function ot(n){return et.get(n)}function Y(n){let e=w(n),t=Object.getOwnPropertyDescriptors(n);for(let r of Object.keys(t)){let s=t[r];if(typeof s.get=="function"){let i=s.get,o=s.set,a=q(()=>i.call(e));Object.defineProperty(n,r,{get:()=>a(),set:o?c=>o.call(e,c):void 0,enumerable:s.enumerable,configurable:true});}else typeof s.value=="function"&&(n[r]=s.value.bind(e));}return e}var bn=new Set(["return","typeof","void","in","instanceof","new","of","delete","do","else"]);function wn(n){if(!n)return true;switch(n.type){case "num":case "str":case "tmpl":case "regex":return false;case "ident":return bn.has(n.value);case "punc":return n.value!==")"&&n.value!=="]";default:return true}}var En=["...","===","!==","**=","&&=","||=","??=","==","!=","<=",">=","&&","||","??","?.","=>","++","--","+=","-=","*=","/=","%=","**","(",")","[","]","{","}",".",",",";",":","?","+","-","*","/","%","<",">","=","!"],I=class extends Error{};function kn(n){return /[A-Za-z_$]/.test(n)}function Pn(n){return /[A-Za-z0-9_$]/.test(n)}function Z(n){return n>="0"&&n<="9"}function at(n){let e=[],t=0,r=n.length;for(;t<r;){let s=n[t];if(s===" "||s===" "||s===`
2
2
  `||s==="\r"){t++;continue}if(Z(s)||s==="."&&Z(n[t+1]??"")){let o=t;if(s==="0"&&(n[t+1]==="x"||n[t+1]==="X"))for(t+=2;t<r&&/[0-9a-fA-F]/.test(n[t]);)t++;else {for(;t<r&&Z(n[t]);)t++;if(n[t]===".")for(t++;t<r&&Z(n[t]);)t++;if(n[t]==="e"||n[t]==="E")for(t++,(n[t]==="+"||n[t]==="-")&&t++;t<r&&Z(n[t]);)t++;}e.push({type:"num",value:n.slice(o,t),start:o,end:t});continue}if(s==='"'||s==="'"){let o=t,a=s;t++;let c="";for(;t<r&&n[t]!==a;)n[t]==="\\"?(c+=Sn(n,t),t+=2):(c+=n[t],t++);if(t>=r)throw new I(`Unterminated string in expression: ${n}`);t++,e.push({type:"str",value:c,start:o,end:t});continue}if(s==="`"){let o=t;t++;let a="",c=0;for(;t<r;){let u=n[t];if(u==="\\"){a+=n[t]+(n[t+1]??""),t+=2;continue}if(u==="`"&&c===0)break;if(u==="$"&&n[t+1]==="{"){c++,a+="${",t+=2;continue}if(u==="}"&&c>0){c--,a+="}",t++;continue}a+=u,t++;}if(t>=r)throw new I(`Unterminated template literal: ${n}`);t++,e.push({type:"tmpl",value:a,raw:a,start:o,end:t});continue}if(kn(s)){let o=t;for(t++;t<r&&Pn(n[t]);)t++;e.push({type:"ident",value:n.slice(o,t),start:o,end:t});continue}if(s==="/"&&wn(e[e.length-1])){let o=t;t++;let a="",c=false;for(;t<r;){let f=n[t];if(f==="\\"){a+=f+(n[t+1]??""),t+=2;continue}if(f===`
3
3
  `)throw new I(`Unterminated regex in expression: ${n}`);if(f==="[")c=true;else if(f==="]")c=false;else if(f==="/"&&!c)break;a+=f,t++;}if(n[t]!=="/")throw new I(`Unterminated regex in expression: ${n}`);t++;let u="";for(;t<r&&/[a-z]/i.test(n[t]);)u+=n[t],t++;e.push({type:"regex",value:a,flags:u,start:o,end:t});continue}let i=false;for(let o of En)if(n.startsWith(o,t)){e.push({type:"punc",value:o,start:t,end:t+o.length}),t+=o.length,i=true;break}if(!i)throw new I(`Unexpected character '${s}' in expression: ${n}`)}return e.push({type:"eof",value:"",start:r,end:r}),e}function Sn(n,e){let t=n[e+1];switch(t){case "n":return `
4
4
  `;case "t":return " ";case "r":return "\r";case "b":return "\b";case "f":return "\f";case "v":return "\v";case "0":return "\0";case "\\":return "\\";case "'":return "'";case '"':return '"';case "`":return "`";default:return t??""}}var A=class extends Error{},An=new Set(["true","false","null","undefined","this","typeof","void","in","instanceof","if","else","return","let","const","var","for","of","while","break","continue"]),Tn={"??":1,"||":2,"&&":3,"==":7,"!=":7,"===":7,"!==":7,"<":8,">":8,"<=":8,">=":8,in:8,instanceof:8,"+":10,"-":10,"*":11,"/":11,"%":11,"**":12},Rn=new Set(["=","+=","-=","*=","/=","%=","**=","&&=","||=","??="]),Oe=class{constructor(e){this.pos=0;this.tokens=at(e);}peek(e=0){return this.tokens[this.pos+e]??this.tokens[this.tokens.length-1]}next(){return this.tokens[this.pos++]??this.tokens[this.tokens.length-1]}isPunc(e,t=0){let r=this.peek(t);return r.type==="punc"&&r.value===e}isKeyword(e,t=0){let r=this.peek(t);return r.type==="ident"&&r.value===e}eatPunc(e){if(!this.isPunc(e))throw new A(`Expected '${e}' but found '${this.peek().value||"end of input"}'`);this.pos++;}atEnd(){return this.peek().type==="eof"}parseProgram(){let e=[];for(;!this.atEnd();){if(this.isPunc(";")){this.pos++;continue}e.push(this.parseStatement());}return {type:"Program",body:e}}parseExpressionProgram(){let e=this.parseExpression();if(!this.atEnd())throw new A(`Unexpected trailing input '${this.peek().value}'`);return {type:"Program",body:[{type:"ExpressionStatement",expression:e}]}}parseStatement(){if(this.isPunc("{"))return this.parseBlock();if(this.isKeyword("if"))return this.parseIf();if(this.isKeyword("return"))return this.parseReturn();if(this.isKeyword("let")||this.isKeyword("const")||this.isKeyword("var")){let t=this.parseVarDecl();return this.consumeSemi(),t}if(this.isKeyword("for"))return this.parseFor();if(this.isKeyword("while"))return this.parseWhile();if(this.isKeyword("break"))return this.pos++,this.consumeSemi(),{type:"BreakStatement"};if(this.isKeyword("continue"))return this.pos++,this.consumeSemi(),{type:"ContinueStatement"};let e=this.parseExpression();return this.consumeSemi(),{type:"ExpressionStatement",expression:e}}consumeSemi(){this.isPunc(";")&&this.pos++;}parseBlock(){this.eatPunc("{");let e=[];for(;!this.isPunc("}")&&!this.atEnd();){if(this.isPunc(";")){this.pos++;continue}e.push(this.parseStatement());}return this.eatPunc("}"),{type:"BlockStatement",body:e}}parseIf(){this.pos++,this.eatPunc("(");let e=this.parseExpression();this.eatPunc(")");let t=this.parseStatement(),r=null;return this.isKeyword("else")&&(this.pos++,r=this.parseStatement()),{type:"IfStatement",test:e,consequent:t,alternate:r}}parseReturn(){this.pos++;let e=null;return !this.isPunc(";")&&!this.isPunc("}")&&!this.atEnd()&&(e=this.parseExpression()),this.consumeSemi(),{type:"ReturnStatement",argument:e}}parseVarDecl(){let e=this.next().value,t=[];do{let r=this.parsePattern(),s=null;this.isPunc("=")&&(this.pos++,s=this.parseAssignment()),t.push({id:r,init:s});}while(this.isPunc(",")&&(this.pos++,true));return {type:"VariableDeclaration",kind:e,declarations:t}}parseFor(){this.pos++,this.eatPunc("(");let e=null;if(this.isKeyword("let")||this.isKeyword("const")||this.isKeyword("var")){let i=this.next().value,o=this.parsePattern();if(this.isKeyword("of")){this.pos++;let u=this.parseExpression();this.eatPunc(")");let f=this.parseStatement();return {type:"ForOfStatement",left:{type:"VariableDeclaration",kind:i,declarations:[{id:o,init:null}]},right:u,body:f}}let a=null;this.isPunc("=")&&(this.pos++,a=this.parseAssignment());let c=[{id:o,init:a}];for(;this.isPunc(",");){this.pos++;let u=this.parsePattern(),f=null;this.isPunc("=")&&(this.pos++,f=this.parseAssignment()),c.push({id:u,init:f});}e={type:"VariableDeclaration",kind:i,declarations:c};}else this.isPunc(";")||(e=this.parseExpression());this.eatPunc(";");let t=this.isPunc(";")?null:this.parseExpression();this.eatPunc(";");let r=this.isPunc(")")?null:this.parseExpression();this.eatPunc(")");let s=this.parseStatement();return {type:"ForStatement",init:e,test:t,update:r,body:s}}parseWhile(){this.pos++,this.eatPunc("(");let e=this.parseExpression();this.eatPunc(")");let t=this.parseStatement();return {type:"WhileStatement",test:e,body:t}}parseExpression(){return this.parseAssignment()}parseAssignment(){if(this.isArrowAhead())return this.parseArrow();let e=this.parseConditional(),t=this.peek();if(t.type==="punc"&&Rn.has(t.value)){this.pos++;let r=this.parseAssignment();return {type:"AssignmentExpression",operator:t.value,left:e,right:r}}return e}parseConditional(){let e=this.parseBinary(1);if(this.isPunc("?")){this.pos++;let t=this.parseAssignment();this.eatPunc(":");let r=this.parseAssignment();return {type:"ConditionalExpression",test:e,consequent:t,alternate:r}}return e}parseBinary(e){let t=this.parseUnary();for(;;){let r=this.peek(),s=r.type==="punc"||r.type==="ident"&&(r.value==="in"||r.value==="instanceof")?r.value:null;if(s===null)break;let i=Tn[s];if(i===void 0||i<e)break;this.pos++;let o=s==="**",a=this.parseBinary(o?i:i+1);s==="&&"||s==="||"||s==="??"?t={type:"LogicalExpression",operator:s,left:t,right:a}:t={type:"BinaryExpression",operator:s,left:t,right:a};}return t}parseUnary(){let e=this.peek();return e.type==="punc"&&(e.value==="!"||e.value==="-"||e.value==="+")?(this.pos++,{type:"UnaryExpression",operator:e.value,argument:this.parseUnary()}):e.type==="ident"&&(e.value==="typeof"||e.value==="void")?(this.pos++,{type:"UnaryExpression",operator:e.value,argument:this.parseUnary()}):e.type==="punc"&&(e.value==="++"||e.value==="--")?(this.pos++,{type:"UpdateExpression",operator:e.value,prefix:true,argument:this.parseUnary()}):this.parsePostfix()}parsePostfix(){let e=this.parseCallMember(),t=this.peek();return t.type==="punc"&&(t.value==="++"||t.value==="--")&&(this.pos++,e={type:"UpdateExpression",operator:t.value,prefix:false,argument:e}),e}parseNewExpr(){this.pos++;let e=this.parsePrimary();for(;;)if(this.isPunc(".")){this.pos++;let r=this.next();e={type:"MemberExpression",object:e,property:{type:"Identifier",name:r.value},computed:false,optional:false};}else if(this.isPunc("[")){this.pos++;let r=this.parseExpression();this.eatPunc("]"),e={type:"MemberExpression",object:e,property:r,computed:true,optional:false};}else break;let t=this.isPunc("(")?this.parseArguments():[];return {type:"NewExpression",callee:e,arguments:t}}parseCallMember(){let e=this.isKeyword("new")?this.parseNewExpr():this.parsePrimary();for(;;)if(this.isPunc(".")){this.pos++;let t=this.next();e={type:"MemberExpression",object:e,property:{type:"Identifier",name:t.value},computed:false,optional:false};}else if(this.isPunc("?."))if(this.pos++,this.isPunc("("))e={type:"CallExpression",callee:e,arguments:this.parseArguments(),optional:true};else if(this.isPunc("[")){this.pos++;let t=this.parseExpression();this.eatPunc("]"),e={type:"MemberExpression",object:e,property:t,computed:true,optional:true};}else {let t=this.next();e={type:"MemberExpression",object:e,property:{type:"Identifier",name:t.value},computed:false,optional:true};}else if(this.isPunc("[")){this.pos++;let t=this.parseExpression();this.eatPunc("]"),e={type:"MemberExpression",object:e,property:t,computed:true,optional:false};}else if(this.isPunc("("))e={type:"CallExpression",callee:e,arguments:this.parseArguments(),optional:false};else break;return e}parseArguments(){this.eatPunc("(");let e=[];for(;!this.isPunc(")")&&!this.atEnd()&&(this.isPunc("...")?(this.pos++,e.push({type:"SpreadElement",argument:this.parseAssignment()})):e.push(this.parseAssignment()),this.isPunc(","));)this.pos++;return this.eatPunc(")"),e}parsePrimary(){let e=this.peek();if(e.type==="num")return this.pos++,{type:"NumberLiteral",value:e.value.startsWith("0x")||e.value.startsWith("0X")?parseInt(e.value,16):Number(e.value)};if(e.type==="str")return this.pos++,{type:"StringLiteral",value:e.value};if(e.type==="tmpl")return this.pos++,this.parseTemplate(e.raw??"");if(e.type==="regex")return this.pos++,{type:"RegexLiteral",pattern:e.value,flags:e.flags??""};if(e.type==="ident")return e.value==="true"||e.value==="false"?(this.pos++,{type:"BooleanLiteral",value:e.value==="true"}):e.value==="null"?(this.pos++,{type:"NullLiteral"}):e.value==="undefined"?(this.pos++,{type:"UndefinedLiteral"}):e.value==="this"?(this.pos++,{type:"ThisExpression"}):(this.pos++,{type:"Identifier",name:e.value});if(this.isPunc("(")){this.pos++;let t=this.parseAssignment();if(this.isPunc(",")){let r=[t];for(;this.isPunc(",");)this.pos++,r.push(this.parseAssignment());return this.eatPunc(")"),{type:"SequenceExpression",expressions:r}}return this.eatPunc(")"),t}if(this.isPunc("["))return this.parseArray();if(this.isPunc("{"))return this.parseObject();throw new A(`Unexpected token '${e.value||"end of input"}' in expression`)}parseArray(){this.eatPunc("[");let e=[];for(;!this.isPunc("]")&&!this.atEnd();){if(this.isPunc(",")){e.push(null),this.pos++;continue}if(this.isPunc("...")?(this.pos++,e.push({type:"SpreadElement",argument:this.parseAssignment()})):e.push(this.parseAssignment()),this.isPunc(","))this.pos++;else break}return this.eatPunc("]"),{type:"ArrayExpression",elements:e}}parseObject(){this.eatPunc("{");let e=[];for(;!this.isPunc("}")&&!this.atEnd()&&(this.isPunc("...")?(this.pos++,e.push({type:"SpreadElement",argument:this.parseAssignment()})):e.push(this.parseObjectProperty()),this.isPunc(","));)this.pos++;return this.eatPunc("}"),{type:"ObjectExpression",properties:e}}parseObjectProperty(){if(this.isKeyword("async")&&this.peek(1).type==="ident")throw new A("async methods are not supported in Summit expressions. Use a regular method that returns a Promise and chain .then().");if((this.isKeyword("get")||this.isKeyword("set"))&&!this.isPunc(":",1)&&!this.isPunc(",",1)&&!this.isPunc("(",1)&&!this.isPunc("}",1)){let s=this.next().value,{key:i,computed:o}=this.parsePropertyKey(),a=this.parseMethodTail();return {key:i,computed:o,value:a,kind:s,shorthand:false}}let{key:e,computed:t,keyName:r}=this.parsePropertyKey();if(this.isPunc("(")){let s=this.parseMethodTail();return {key:e,computed:t,value:s,kind:"method",shorthand:false}}if(this.isPunc(":")){this.pos++;let s=this.parseAssignment();return {key:e,computed:t,value:s,kind:"init",shorthand:false}}if(r!==null&&!t)return {key:e,computed:t,value:{type:"Identifier",name:r},kind:"init",shorthand:true};throw new A(`Invalid object property near '${this.peek().value}'`)}parsePropertyKey(){if(this.isPunc("[")){this.pos++;let t=this.parseAssignment();return this.eatPunc("]"),{key:t,computed:true,keyName:null}}let e=this.next();if(e.type==="str")return {key:{type:"StringLiteral",value:e.value},computed:false,keyName:e.value};if(e.type==="num")return {key:{type:"StringLiteral",value:String(Number(e.value))},computed:false,keyName:null};if(e.type==="ident")return {key:{type:"StringLiteral",value:e.value},computed:false,keyName:e.value};throw new A(`Invalid property key '${e.value}'`)}parseMethodTail(){let e=this.parseParamList(),t=this.parseBlock();return {type:"ArrowFunction",params:e,body:t,expression:false}}isArrowAhead(){let e=this.peek();if(e.type==="ident"&&!An.has(e.value)&&this.isPunc("=>",1))return true;if(this.isPunc("(")){let t=0,r=this.pos;for(;r<this.tokens.length;r++){let i=this.tokens[r];if(i.type==="punc"&&i.value==="(")t++;else if(i.type==="punc"&&i.value===")"){if(t--,t===0)break}else if(i.type==="eof")return false}let s=this.tokens[r+1];return !!s&&s.type==="punc"&&s.value==="=>"}return false}parseArrow(){let e;if(this.peek().type==="ident"?e=[{type:"Identifier",name:this.next().value}]:e=this.parseParamList(),this.eatPunc("=>"),this.isPunc("{")){let r=this.parseBlock();return {type:"ArrowFunction",params:e,body:r,expression:false}}let t=this.parseAssignment();return {type:"ArrowFunction",params:e,body:t,expression:true}}parseParamList(){this.eatPunc("(");let e=[];for(;!this.isPunc(")")&&!this.atEnd()&&(e.push(this.parsePattern()),this.isPunc(","));)this.pos++;return this.eatPunc(")"),e}parsePattern(){let e;if(this.isPunc("..."))return this.pos++,{type:"RestElement",argument:this.parsePattern()};if(this.isPunc("{"))e=this.parseObjectPattern();else if(this.isPunc("["))e=this.parseArrayPattern();else {let t=this.next();if(t.type!=="ident")throw new A(`Invalid binding target '${t.value}'`);e={type:"Identifier",name:t.value};}if(this.isPunc("=")){this.pos++;let t=this.parseAssignment();return {type:"AssignmentPattern",left:e,right:t}}return e}parseObjectPattern(){this.eatPunc("{");let e=[],t=null;for(;!this.isPunc("}")&&!this.atEnd();){if(this.isPunc("...")){this.pos++,t={type:"Identifier",name:this.next().value};break}let{key:r,computed:s,keyName:i}=this.parsePropertyKey(),o;if(this.isPunc(":")?(this.pos++,o=this.parsePattern()):(o={type:"Identifier",name:i??""},this.isPunc("=")&&(this.pos++,o={type:"AssignmentPattern",left:o,right:this.parseAssignment()})),e.push({key:r,value:o,computed:s}),this.isPunc(","))this.pos++;else break}return this.eatPunc("}"),{type:"ObjectPattern",properties:e,rest:t}}parseArrayPattern(){this.eatPunc("[");let e=[],t=null;for(;!this.isPunc("]")&&!this.atEnd();){if(this.isPunc(",")){e.push(null),this.pos++;continue}if(this.isPunc("...")){this.pos++,t=this.parsePattern();break}if(e.push(this.parsePattern()),this.isPunc(","))this.pos++;else break}return this.eatPunc("]"),{type:"ArrayPattern",elements:e,rest:t}}parseTemplate(e){let t=[],r=[],s="",i=0;for(;i<e.length;)if(e[i]==="$"&&e[i+1]==="{"){t.push(s),s="",i+=2;let o=1,a="";for(;i<e.length&&o>0;){let u=e[i];if(u==="{")o++;else if(u==="}"&&(o--,o===0))break;a+=u,i++;}i++;let c=X(a,"expression").body[0];r.push(c&&c.type==="ExpressionStatement"?c.expression:{type:"UndefinedLiteral"});}else s+=e[i],i++;return t.push(s),{type:"TemplateLiteral",quasis:t,expressions:r}}},ct=new Map;function X(n,e){let t=e+"\0"+n,r=ct.get(t);if(r)return r;let s=new Oe(n),i=e==="expression"?s.parseExpressionProgram():s.parseProgram();return ct.set(t,i),i}var Q=class{constructor(e){this.value=e;}},F=class{},B=class{},E=class{constructor(e){this.parent=e;this.vars=new Map;}declare(e,t,r){this.vars.set(e,{value:t,constant:r});}find(e){let t=this;for(;t;){if(t.vars.has(e))return t;t=t.parent;}return null}has(e){return this.find(e)!==null}get(e){return this.find(e)?.vars.get(e)?.value}set(e,t){let r=this.find(e);if(!r)return false;let s=r.vars.get(e);if(s.constant)throw new TypeError(`Assignment to constant '${e}'`);return s.value=t,true}},lt=new Set(["Math","JSON","Date","Object","Array","Number","String","Boolean","parseInt","parseFloat","isNaN","isFinite","RegExp","Map","Set","WeakMap","WeakSet","Promise","Intl","console","window","document","location","navigator","history","localStorage","sessionStorage","setTimeout","clearTimeout","setInterval","clearInterval","requestAnimationFrame","cancelAnimationFrame","fetch","AbortController","Headers","Request","Response","alert","confirm","prompt","structuredClone","URL","URLSearchParams","encodeURIComponent","decodeURIComponent","NaN","Infinity"]);function Ce(n){for(let e of n)lt.add(e);}function ut(n,e){if(n!=null)return n[e]}var U=class{constructor(e){this.root=e;}run(e,t){let r=new E(null),s;try{for(let i of e.body)i.type==="ExpressionStatement"?s=this.evalExpr(i.expression,r,t):this.execStmt(i,r,t);}catch(i){if(i instanceof Q)return i.value;throw i}return s}execBlock(e,t,r){for(let s of e)this.execStmt(s,t,r);}execStmt(e,t,r){switch(e.type){case "ExpressionStatement":this.evalExpr(e.expression,t,r);return;case "BlockStatement":this.execBlock(e.body,new E(t),r);return;case "IfStatement":this.evalExpr(e.test,t,r)?this.execStmt(e.consequent,t,r):e.alternate&&this.execStmt(e.alternate,t,r);return;case "ReturnStatement":throw new Q(e.argument?this.evalExpr(e.argument,t,r):void 0);case "VariableDeclaration":for(let s of e.declarations){let i=s.init?this.evalExpr(s.init,t,r):void 0;this.bindPattern(s.id,i,t,e.kind==="const");}return;case "WhileStatement":for(;this.evalExpr(e.test,t,r);)try{this.execStmt(e.body,new E(t),r);}catch(s){if(s instanceof F)break;if(s instanceof B)continue;throw s}return;case "ForOfStatement":{let s=this.evalExpr(e.right,t,r);for(let i of s??[]){let o=new E(t);e.left.type==="VariableDeclaration"?this.bindPattern(e.left.declarations[0].id,i,o,e.left.kind==="const"):this.assignPattern(e.left,i,o,r);try{this.execStmt(e.body,o,r);}catch(a){if(a instanceof F)break;if(a instanceof B)continue;throw a}}return}case "ForStatement":{let s=new E(t);for(e.init&&(e.init.type==="VariableDeclaration"?this.execStmt(e.init,s,r):this.evalExpr(e.init,s,r));!e.test||this.evalExpr(e.test,s,r);){try{this.execStmt(e.body,new E(s),r);}catch(i){if(i instanceof F)break;if(!(i instanceof B))throw i}e.update&&this.evalExpr(e.update,s,r);}return}case "BreakStatement":throw new F;case "ContinueStatement":throw new B}}evalExpr(e,t,r){switch(e.type){case "NumberLiteral":case "StringLiteral":case "BooleanLiteral":return e.value;case "NullLiteral":return null;case "UndefinedLiteral":return;case "RegexLiteral":return new RegExp(e.pattern,e.flags);case "ThisExpression":return r;case "Identifier":return this.resolve(e.name,t);case "TemplateLiteral":{let s=e.quasis[0]??"";for(let i=0;i<e.expressions.length;i++)s+=String(this.evalExpr(e.expressions[i],t,r)??""),s+=e.quasis[i+1]??"";return s}case "ArrayExpression":{let s=[];for(let i of e.elements)i===null?s.push(void 0):i.type==="SpreadElement"?s.push(...this.evalExpr(i.argument,t,r)):s.push(this.evalExpr(i,t,r));return s}case "ObjectExpression":return this.evalObject(e,t,r);case "UnaryExpression":{let s=this.evalExpr(e.argument,t,r);switch(e.operator){case "!":return !s;case "-":return -s;case "+":return +s;case "typeof":return typeof s;case "void":return}return}case "UpdateExpression":{let s=Number(this.evalTarget(e.argument,t,r)),i=e.operator==="++"?s+1:s-1;return this.assign(e.argument,i,t,r),e.prefix?i:s}case "BinaryExpression":return this.evalBinary(e.operator,this.evalExpr(e.left,t,r),this.evalExpr(e.right,t,r));case "LogicalExpression":{let s=this.evalExpr(e.left,t,r);return e.operator==="&&"?s&&this.evalExpr(e.right,t,r):e.operator==="||"?s||this.evalExpr(e.right,t,r):s??this.evalExpr(e.right,t,r)}case "ConditionalExpression":return this.evalExpr(e.test,t,r)?this.evalExpr(e.consequent,t,r):this.evalExpr(e.alternate,t,r);case "AssignmentExpression":return this.evalAssignment(e,t,r);case "MemberExpression":{let s=this.evalExpr(e.object,t,r);if(e.optional&&s==null)return;let i=e.computed?this.evalExpr(e.property,t,r):e.property.name;return ut(s,i)}case "CallExpression":return this.evalCall(e,t,r);case "NewExpression":{let s=this.evalExpr(e.callee,t,r),i=this.evalArguments(e.arguments,t,r);if(typeof s!="function")throw new TypeError("Expression value is not a constructor");return Reflect.construct(s,i)}case "ArrowFunction":return this.makeFunction(e,t,r,false);case "SequenceExpression":{let s;for(let i of e.expressions)s=this.evalExpr(i,t,r);return s}case "SpreadElement":return this.evalExpr(e.argument,t,r)}}evalObject(e,t,r){let s={};for(let i of e.properties){if(i.type==="SpreadElement"){Object.assign(s,this.evalExpr(i.argument,t,r));continue}let o=i,a=o.computed?String(this.evalExpr(o.key,t,r)):o.key.value;if(o.kind==="get"){let c=this.makeFunction(o.value,t,r,true);Object.defineProperty(s,a,{get:c,enumerable:true,configurable:true});}else if(o.kind==="set"){let c=this.makeFunction(o.value,t,r,true);Object.defineProperty(s,a,{set:c,enumerable:true,configurable:true});}else o.kind==="method"?s[a]=this.makeFunction(o.value,t,r,true):s[a]=this.evalExpr(o.value,t,r);}return s}evalCall(e,t,r){let s,i;if(e.callee.type==="MemberExpression"){let a=e.callee,c=this.evalExpr(a.object,t,r);if(a.optional&&c==null)return;i=c;let u=a.computed?this.evalExpr(a.property,t,r):a.property.name;s=ut(c,u);}else s=this.evalExpr(e.callee,t,r);if(e.optional&&s==null)return;let o=this.evalArguments(e.arguments,t,r);if(typeof s!="function"){if(s==null)return;throw new TypeError("Expression value is not a function")}return s.apply(i,o)}evalArguments(e,t,r){let s=[];for(let i of e)i.type==="SpreadElement"?s.push(...this.evalExpr(i.argument,t,r)):s.push(this.evalExpr(i,t,r));return s}evalBinary(e,t,r){switch(e){case "+":return t+r;case "-":return t-r;case "*":return t*r;case "/":return t/r;case "%":return t%r;case "**":return t**r;case "==":return t==r;case "!=":return t!=r;case "===":return t===r;case "!==":return t!==r;case "<":return t<r;case ">":return t>r;case "<=":return t<=r;case ">=":return t>=r;case "in":return t in r;case "instanceof":return t instanceof r}}evalAssignment(e,t,r){let s=e.operator;if(s==="="){let a=this.evalExpr(e.right,t,r);return this.assign(e.left,a,t,r),a}let i=this.evalTarget(e.left,t,r),o;if(s==="&&="){if(!i)return i;o=this.evalExpr(e.right,t,r);}else if(s==="||="){if(i)return i;o=this.evalExpr(e.right,t,r);}else if(s==="??="){if(i!=null)return i;o=this.evalExpr(e.right,t,r);}else {let a=this.evalExpr(e.right,t,r);o=this.evalBinary(s.slice(0,-1),i,a);}return this.assign(e.left,o,t,r),o}evalTarget(e,t,r){return this.evalExpr(e,t,r)}assign(e,t,r,s){if(e.type==="Identifier"){r.set(e.name,t)||this.root.set(e.name,t);return}if(e.type==="MemberExpression"){let i=this.evalExpr(e.object,r,s);if(i==null)throw new TypeError("Cannot assign to a property of null or undefined");let o=e.computed?this.evalExpr(e.property,r,s):e.property.name;i[o]=t;return}throw new TypeError("Invalid assignment target")}resolve(e,t){if(t.has(e))return t.get(e);if(this.root.has(e))return this.root.get(e);if(lt.has(e))return globalThis[e]}makeFunction(e,t,r,s){let i=this;return function(...o){let a=new E(t);i.bindParams(e.params,o,a);let c=s?this:r;if(e.expression)return i.evalExpr(e.body,a,c);try{i.execBlock(e.body.body,new E(a),c);}catch(u){if(u instanceof Q)return u.value;throw u}}}bindParams(e,t,r){for(let s=0;s<e.length;s++){let i=e[s];if(i.type==="RestElement"){this.bindPattern(i.argument,t.slice(s),r,false);break}this.bindPattern(i,t[s],r,false);}}bindPattern(e,t,r,s){switch(e.type){case "Identifier":r.declare(e.name,t,s);return;case "AssignmentPattern":this.bindPattern(e.left,t===void 0?this.evalExpr(e.right,r,void 0):t,r,s);return;case "RestElement":this.bindPattern(e.argument,t,r,s);return;case "ObjectPattern":{let i=t??{},o=new Set;for(let a of e.properties){let c=a.computed?String(this.evalExpr(a.key,r,void 0)):a.key.value;o.add(c),this.bindPattern(a.value,i[c],r,s);}if(e.rest){let a={};for(let c of Object.keys(i))o.has(c)||(a[c]=i[c]);r.declare(e.rest.name,a,s);}return}case "ArrayPattern":{let i=t??[];for(let o=0;o<e.elements.length;o++){let a=e.elements[o];a&&this.bindPattern(a,i[o],r,s);}e.rest&&this.bindPattern(e.rest,i.slice(e.elements.length),r,s);return}}}assignPattern(e,t,r,s){if(e.type==="Identifier"){r.set(e.name,t)||this.root.set(e.name,t);return}this.bindPattern(e,t,r,false);}};function ie(n,e,t){let r=X(n,"expression");return new U(e).run(r,t)}function Ie(n,e,t){let r=X(n,"program");return new U(e).run(r,t)}function pt(n){let e=X(n,"expression");return (t,r)=>new U(t).run(e,r)}var Dn="https://velofy.github.io/summit";function Mn(n,e){let t=n.length,r=e.length;if(!t)return r;if(!r)return t;let s=Array.from({length:r+1},(i,o)=>o);for(let i=1;i<=t;i++){let o=[i];for(let a=1;a<=r;a++){let c=n[i-1]===e[a-1]?0:1;o[a]=Math.min(s[a]+1,o[a-1]+1,s[a-1]+c);}s=o;}return s[r]}function dt(n,e){let t=null,r=1/0;for(let i of e){let o=Mn(n,i);o<r&&(r=o,t=i);}let s=n.length<=4?1:2;return t!==null&&r<=s?t:null}function Ln(n){let e=n.tagName.toLowerCase(),t=n.id?`#${n.id}`:"",r=n.classList.length?"."+Array.from(n.classList).slice(0,2).join("."):"";return `<${e}${t}${r}>`}function oe(n,e,t){let r=[`[summit] ${n}: ${e}`];return t.hint&&r.push(` ${t.hint}`),t.expression&&r.push(` expression: ${t.expression.trim()}`),t.el&&r.push(` element: ${Ln(t.el)}`),r.push(` docs: ${Dn}/${t.doc?t.doc+"/":""}`),r.join(`