@hyperfixi/engine 3.3.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.
- package/CHANGELOG.md +921 -0
- package/LICENSE +20 -0
- package/README.md +272 -0
- package/dist/additions.d.ts +30 -0
- package/dist/ast.d.ts +277 -0
- package/dist/commands/animation.d.ts +34 -0
- package/dist/commands/control.d.ts +36 -0
- package/dist/commands/dom-more.d.ts +68 -0
- package/dist/commands/dom.d.ts +50 -0
- package/dist/commands/events.d.ts +25 -0
- package/dist/commands/js.d.ts +22 -0
- package/dist/commands/loops.d.ts +34 -0
- package/dist/commands/misc.d.ts +36 -0
- package/dist/commands/morph.d.ts +18 -0
- package/dist/commands/pick.d.ts +22 -0
- package/dist/commands/platform.d.ts +44 -0
- package/dist/commands/setters.d.ts +38 -0
- package/dist/common.js +3020 -0
- package/dist/common.min.js +17 -0
- package/dist/conversions.d.ts +6 -0
- package/dist/cookies.d.ts +10 -0
- package/dist/core.js +2190 -0
- package/dist/core.min.js +17 -0
- package/dist/engine.d.ts +79 -0
- package/dist/everything.d.ts +2 -0
- package/dist/expressions-extra.d.ts +2 -0
- package/dist/expressions.d.ts +51 -0
- package/dist/features.d.ts +47 -0
- package/dist/full.js +5673 -0
- package/dist/full.min.js +19 -0
- package/dist/hyperfixi-hs.dev.js +5676 -0
- package/dist/hyperfixi-hs.js +19 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +5737 -0
- package/dist/live-templates.d.ts +3 -0
- package/dist/minimal.js +2580 -0
- package/dist/minimal.min.js +17 -0
- package/dist/on.d.ts +39 -0
- package/dist/parser.d.ts +97 -0
- package/dist/reactivity.d.ts +30 -0
- package/dist/runtime.d.ts +160 -0
- package/dist/statements.d.ts +24 -0
- package/dist/templates.d.ts +61 -0
- package/dist/tokenizer.d.ts +25 -0
- package/dist/util.d.ts +34 -0
- package/package.json +60 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";(()=>{var K=e=>typeof e=="object"&&e!==null&&"then"in e&&typeof e.then=="function",T=(e,t)=>K(e)?e.then(t):t(e),I=(e,t)=>e.some(K)?Promise.all(e).then(t):t(e),M=e=>e!=null,H=e=>typeof e=="function",v=(e,t)=>M(e)?e[t]:void 0,ne=(e,t,n)=>{M(e)&&(e[t]=n)},R=e=>e instanceof Element,z=e=>H(v(e,"addEventListener"));var b=e=>e;var B={attributes:"_, script, data-script",defaultTransition:"all 500ms ease-in",disableSelector:"[disable-scripting], [data-disable-scripting]",hideShowStrategies:{},fetchThrowsOn:[/^4/,/^5/]},Se=Object.assign(Object.create(null),{String:e=>String(e),Int:e=>parseInt(String(e)),Float:e=>parseFloat(String(e)),Number:e=>Number(e),Fragment:e=>et(e)}),Ce=[],se={process(e){},enter(e){}},we=new WeakMap,ee=e=>we.get(e),Ye=e=>we.delete(e);function W(e){let t=we.get(e);return t||we.set(e,t={}),t}var x={tracking:!1,readGlobal(e){},readElement(e,t){},readProperty(e,t){},readAttribute(e,t){},readQuery(e){},wroteGlobal(e){},wroteElement(e,t){},wroteProperty(e){},stop(e){}},ge=e=>(x.tracking&&typeof e=="object"&&e!==null&&x.readProperty(e,"__mutation__"),e),Xt={Array:["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"],Set:["add","delete","clear"],Map:["set","delete","clear"]};function Ze(e,t){let n=v(v(e,"constructor"),"name");typeof n=="string"&&Xt[n]?.includes(t)&&x.wroteProperty(e)}var Oe=e=>{if(e instanceof Node){let t=e.getRootNode();if(t instanceof Document||t instanceof ShadowRoot)return t}return document},en=e=>e.replace(/[:&()[\]/]/g,t=>"\\"+t);function Ie(e,t){return x.tracking&&x.readQuery(e),e.querySelectorAll(t)}var j=class{constructor(t,n,r=!1){this.raw=t;this.relativeTo=n;this.escape=r}get css(){return this.escape?en(this.raw):this.raw}get className(){return this.raw.slice(1)}get length(){return this.select().length}contains(t){for(let n of this)if(n.contains(t))return!0;return!1}select(){return Ie(Oe(this.relativeTo),this.css)}[Symbol.iterator](){return this.select()[Symbol.iterator]()}},Ae=e=>e instanceof j||Array.isArray(e)||e instanceof NodeList||e instanceof HTMLCollection||e instanceof FileList;function S(e,t){if(Ae(e))for(let n of e)t(n);else t(e)}var ve=(e,t)=>{if(e==null)return;let n=t(e);if(n!==void 0)return n;if(Ae(e))return Array.from(e,t)},ie=(e,t)=>(x.tracking&&x.readProperty(e,t),ve(e,n=>v(n,t))),ae=(e,t)=>(x.tracking&&x.readAttribute(e,t),ve(e,n=>R(n)?n.getAttribute(t):void 0)),be=(e,t)=>ve(e,n=>v(v(n,"style"),t)),Ee=(e,t)=>ve(e,n=>R(n)?getComputedStyle(n).getPropertyValue(t):void 0),ue=(e,t,n)=>S(e,r=>{R(r)&&(n==null?r.removeAttribute(t):r.setAttribute(t,String(n)))}),xe=(e,t,n)=>S(e,r=>ne(v(r,"style"),t,n)),ke=(e,t,n)=>S(e,r=>{ne(r,t,n),x.wroteProperty(r)});function A(e,t){if(e==null)throw new Error(`'${t}' is null`)}var Fe=e=>e==null||v(e,"length")===0;function Je(e){if(e==null)return!1;if(Ae(e)){for(let t of e)return!0;return!1}return!0}function Ke(e,t,n){if(e==null&&n||Object.prototype.toString.call(e).slice(8,-1)===t)return!0;let r=v(globalThis,t);return H(r)&&e instanceof r}function Xe(e,t){for(let r of Ce){let o=r(t,e);if(o!==void 0)return o}if(e==null)return null;let n=Se[t];if(n)return n(e);throw new Error("Unknown conversion : "+t)}function et(e){let t=document.createDocumentFragment();return e==null?t.append("null"):S(e,n=>{if(n instanceof Node)t.append(n);else{let r=document.createElement("template");r.innerHTML=n===null?"":String(n),t.append(r.content)}}),t}function ce(e,t){S(e,n=>{if(!R(n))return;let r=n.parentElement;n.replaceWith(t instanceof Node?t.cloneNode(!0):et(t)),r&&se.process(r)})}function L(e,t,n={},r){if(!z(e))return!0;n.sender=r;let o=Object.assign(new Event(t,{bubbles:!0,cancelable:!0,composed:!0}),{detail:n});return e.dispatchEvent(o)}var tt=(e,t="elementScope")=>(W(e).scopes??={})[t]??={},tn=Object.create(null,{selection:{get:()=>getSelection()?.toString(),enumerable:!0},clipboard:{get:()=>navigator.clipboard.readText(),set:e=>void navigator.clipboard.writeText(String(e))}});function le(e,t,n,r){let o=v(r,"detail"),i=Object.create(tn);for(let s=R(e)?e:null;s;s=s.parentElement)Object.assign(i,ee(s)?.features);return{meta:{owner:e,feature:t},locals:i,me:n,you:void 0,result:void 0,beingTested:null,event:r,target:v(r,"target")??null,detail:o??null,sender:v(o,"sender")??null,body:typeof document>"u"?null:document.body}}var Re=["meta","it","result","locals","event","target","detail","sender","body"],re=e=>{let t=e.meta.owner,n=e.meta.feature?.behavior;return M(t)?tt(t,n?n+"Scope":void 0):{}};function nt(e,t,n){let r=R(n)?n:R(t.meta.owner)?t.meta.owner:null;for(;r;){let o=ee(r)?.scopes?.elementScope;if(o&&e in o)return{value:o[e],element:r};let i=r.getAttribute("dom-scope");if(i==="isolated")break;let s=i?.match(/^closest\s+(.+)/),u=i?.match(/^parent\s+of\s+(.+)/);s?r=r.parentElement?.closest(s[1])??null:u?r=r.closest(u[1])?.parentElement??null:r=r.parentElement}return{value:void 0,element:null}}function rt(e,t,n,r){if(e==="me"||e==="my"||e==="I")return t.me;if(e==="it"||e==="its")return t.beingTested??t.result;if(e==="result")return t.result;if(e==="you"||e==="your"||e==="yourself")return t.you;let o=t.meta.owner,i=()=>(x.tracking&&x.readGlobal(e),ge(v(globalThis,e)));if(n==="global")return i();if(n==="element")return x.tracking&&x.readElement(e,o),ge(re(t)[e]);if(n==="inherited"){let l=nt(e,t,r);return x.tracking&&x.readElement(e,l.element??(R(r)?r:o)),ge(l.value)}let s=t.meta.context;if(s!=null){let l=v(s,e);if(l!==void 0)return l;let c=v(v(s,"detail"),e);if(c!==void 0)return c}let u=Re.includes(e)?v(t,e):t.locals[e];if(u!==void 0)return u;let a=re(t)[e];return a!==void 0?(x.tracking&&x.readElement(e,o),ge(a)):i()}function ot(e,t,n,r,o){if(n==="global")ne(globalThis,e,r),x.wroteGlobal(e);else if(n==="element")re(t)[e]=r,x.wroteElement(e,t.meta.owner);else if(n==="inherited"){let s=nt(e,t,o).element??(R(o)?o:t.meta.owner);M(s)&&(tt(s)[e]=r),x.wroteElement(e,s)}else!Re.includes(e)&&t.locals[e]!==void 0?t.locals[e]=r:re(t)[e]!==void 0?(re(t)[e]=r,x.wroteElement(e,t.meta.owner)):Re.includes(e)?ne(t,e,r):t.locals[e]=r}function X(e,t,n=0){for(let r=n;r<e.length;r++){let o=e[r].run(t);if(K(o))return o.then(i=>i||X(e,t,r+1));if(o)return o}}function oe(e,t){try{let n=e();return K(n)?n.then(void 0,t):n}catch(n){return t(n)}}function st(e,t,n){let{errorSymbol:r,errorHandler:o,finallyHandler:i}=n,s=()=>oe(()=>T(X(t,e),a=>{let l=v(a,"k");if(l==="break"||l==="continue")throw new Error(`Command \`${l}\` cannot be used outside of a \`repeat\` loop.`);return Qe(a)}),a=>{if(!o||!r)throw a;return e.locals[r]=a,X(o,e)});if(!i)return s();let u=()=>oe(()=>T(X(i,e),()=>{}),a=>console.error(" Exception in finally block: ",a));return oe(()=>T(s(),a=>T(u(),()=>Qe(a))),a=>T(u(),()=>{throw a}))}var Qe=e=>{let t=v(e,"k");if(t==="return")return{k:"return",value:v(e,"value")};if(t==="break"||t==="continue")return{k:t}};function it(e,t,n,r,o){let i=[];S(e,a=>i.push(a));let s=i.map(a=>(n.beingTested=a,t.ev(n)));n.beingTested=null;let u=a=>{n.result=i.filter((l,c)=>((a[c]?r:o)(l),a[c]))};return s.some(K)?Promise.all(s).then(u):u(s)}var at=new Set("+ - * / . .. \\ : % | ! ? # & $ ; , ( ) < > <= >= == === != !== { } [ ] = ~ ^".split(" ")),ut={b:"\b",f:"\f",n:`
|
|
2
|
+
`,r:"\r",t:" ",v:"\v"},$=e=>e>="a"&&e<="z"||e>="A"&&e<="Z",U=e=>e>="0"&&e<="9",Le=e=>e===" "||e===" "||e==="\r"||e===`
|
|
3
|
+
`,qe=e=>$(e)||U(e)||e==="-"||e==="_"||e===":",_e=e=>$(e)||U(e)||e==="_"||e==="$";function fe(e,t=!1){let n=[],r=0,o=0,i=1,s="<START>",u=0,a=()=>e.charAt(r),l=h=>e.charAt(r+h),c=()=>(s=e.charAt(r++),s===`
|
|
4
|
+
`?(i++,o=0):o++,s),d=h=>({type:h,value:"",start:r,end:r+1,line:i,column:o}),m=(h,y)=>(h.value=y,h.end=r,h),f=h=>{let y="";for(;a()&&h(a());)y+=c();return y},p=()=>t&&u===0,g=()=>$(s)||U(s)||")\"'`}]".includes(s),w=(h,y)=>{let P=d(h),F=c();if(a()==="{"){if(P.template=!0,F+=c(),F+=f(Kt=>Kt!=="}"),a()!=="}")throw new Error("Unterminated "+(y?"class":"id")+" reference");let ye=c();y&&(F+=ye)}else if(y)for(;qe(a())||a()==="\\";)a()==="\\"&&c(),F+=c();else F+=f(qe);return m(P,F)},k=()=>{let h=d("STRING"),y=c();h.template=y==="`";let P="";for(;a()&&a()!==y;)if(a()==="\\"){c();let F=c();if(F in ut)P+=ut[F];else if(h.template&&F==="$")P+="\\$";else if(F==="x"){let ye=a()&&l(1)?parseInt(c()+c(),16):NaN;if(Number.isNaN(ye))throw new Error(`Invalid hexadecimal escape at [Line: ${h.line}, Column: ${h.column}]`);P+=String.fromCharCode(ye)}else P+=F}else P+=c();if(a()!==y)throw new Error(`Unterminated string at [Line: ${h.line}, Column: ${h.column}]`);return c(),m(h,P)},q=()=>{let h=d("IDENTIFIER"),y=c()+f(_e);return a()==="!"&&y==="beep"&&(y+=c()),m(h,y)},N=()=>{let h=d("IDENTIFIER"),y=c(),P=y==="\\";for(P&&(y="");(_e(a())||"\\{}".includes(a()||" "))&&!(a()==="$"&&!P);)a()==="\\"?(P=!0,c()):(P=!1,y+=c());return m(h,y)},C=()=>{let h=d("NUMBER"),y=c()+f(U);return a()==="."&&U(l(1))&&(y+=c()),y+=f(U),(a()==="e"||a()==="E")&&(U(l(1))?y+=c():l(1)==="-"&&(y+=c()+c())),m(h,y+f(U))},O=()=>{let h=d("OP");h.op=!0;let y=c();for(;a()&&at.has(y+a());)y+=c();return m(h,y)},_=()=>{let h=d("ATTRIBUTE_REF"),y=c();return y==="["?(y+=f(P=>P!=="]"),a()==="]"&&(y+=c())):(y+=f(qe),a()==="="&&(y+=c(),a()==='"'||a()==="'"?y+=k().value:_e(a())&&(y+=q().value))),m(h,y)},Z=()=>{let h=n.at(-1);return h?h.type==="IDENTIFIER"||h.type==="CLASS_REF"||h.type==="ID_REF"?!1:!(h.op&&(h.value===">"||h.value===")")):!0},J=()=>{let h=a(),y=l(2);return(h==="-"||h==="/")&&l(1)===h&&(Le(y)||y===""||y===h)};for(;r<e.length;){let h=a(),y=l(1);if(J())f(P=>P!=="\r"&&P!==`
|
|
5
|
+
`),c();else if(Le(h))n.push(m(d("WHITESPACE"),f(Le)));else if(!g()&&h==="."&&($(y)||y==="{"||y==="-"))n.push(w("CLASS_REF",!0));else if(!g()&&h==="#"&&($(y)||y==="{"))n.push(w("ID_REF",!1));else if(h==="@"||h==="["&&y==="@")n.push(_());else if(h==="*"&&$(y)){let P=d("STYLE_REF");n.push(m(P,c()+f(F=>$(F)||F==="-")))}else if(p()&&($(h)||h==="\\"))n.push(N());else if(!p()&&($(h)||h==="_"||h==="$"))n.push(q());else if(U(h))n.push(C());else if(!p()&&(h==='"'||h==="`"))n.push(k());else if(!p()&&h==="'")n.push(Z()?k():O());else if(at.has(h))s==="$"&&h==="{"&&u++,h==="}"&&u--,n.push(O());else if(p()||h==="`"){let P=d("RESERVED");n.push(m(P,c()))}else throw new Error("Unknown token: "+h+" ")}return n}function E(e){return e.match("the"),nn(e)}function nn(e){let t=lt(e),n,r=()=>e.match("and")??e.match("or");for(let o=r();o;o=r())n??=o.value,n!==o.value&&e.err("You must parenthesize logical operations with different operators"),t=rn(o.value,t,lt(e));return t}function rn(e,t,n){let r=e==="or";return{type:"logicalOperator",operator:e,left:t,right:n,start:t.start,end:n.end,ev:o=>T(t.ev(o),i=>!!i===r?i:n.ev(o))}}var on={"+":(e,t)=>Array.isArray(e)?e.concat(t):b(e)+b(t),"-":(e,t)=>b(e)-b(t),"*":(e,t)=>b(e)*b(t),"/":(e,t)=>b(e)/b(t),mod:(e,t)=>b(e)%b(t)};function De(e){let t=je(e),n,r=()=>e.matchAnyOp("+","-","*","/")??e.match("mod");for(let o=r();o;o=r()){n??=o.value,n!==o.value&&e.err("You must parenthesize math operations with different operators");let i=t,s=je(e),u=on[o.value];t={type:"mathOperator",operator:o.value,left:i,right:s,start:i.start,end:s.end,ev:l=>I([i.ev(l),s.ev(l)],([c,d])=>u(c,d))}}return t}function je(e){let t=G(e);for(let n=!0;n;){n=!1;for(let r of e.g.collections){let o=r(e,t);if(o){t=o,n=!0;break}}}return t}function G(e){e.match("the");let t=e.pos();if(e.match("not"))return He(e,"logicalNot",t,G(e),n=>!n);if(e.match("no"))return He(e,"noExpression",t,je(e),Fe);for(let n of e.g.unaries){let r=n(e);if(r)return D(e,r)}return an(e)}function He(e,t,n,r,o,i=t!=="negativeNumber"){let s={type:t,root:r,start:n,end:e.endPos(),ev:u=>T(r.ev(u),a=>o(a,u))};return i?D(e,s):s}var sn="em ex cap ch ic rem lh rlh vw vh vi vb vmin vmax cm mm Q pc pt px".split(" ");function an(e){let t=ht(e),n=e.matchAny(...sn)??e.matchOp("%");if(n)return ct(e,"stringPostfixExpression",t,n.value);let r=e.matchAny("s","seconds")?1e3:e.matchAny("ms","milliseconds")?1:0;if(r)return ct(e,"timeExpression",t,r);for(let o of e.g.postfixes){let i=o(e,t);if(i)return i}return t}function ct(e,t,n,r){let o=s=>typeof r=="number"?b(s)*r:`${s}${r}`,i={type:t,root:n,suffix:r,start:n.start,end:e.endPos(),ev:s=>T(n.ev(s),o)};return n.stat&&(i.stat=()=>o(de(n))),i}function ht(e){let t=e.pos();return e.matchOp("-")?He(e,"negativeNumber",t,ht(e),n=>-b(n)):pt(e)}function pt(e){let t=dn(e);return t?D(e,t):e.err("Unexpected value: "+e.cur().value)}function yt(e){return e.match("the"),Ue(e,pt(e))}function Ue(e,t){let n=un(t);return n.put||e.err(`A target expression must be writable. The expression type '${n.type}' is not.`),n}function un(e){let t=e;for(;t.type==="parenthesized"&&"expr"in t&&cn(t.expr);)t=t.expr;return t}var cn=e=>H(v(e,"ev"));function de(e){if(e.stat)return e.stat();throw new Error("This expression cannot be evaluated statically: "+e.type)}function ln(e){let t=e.matchAnyOp("<",">","<=",">=","==","===","!=","!==");if(t)return{operator:t.value,right:!0,isType:!1};let n=(a,l=!0,c=!1)=>({operator:a,right:l,isType:c}),r=()=>e.match("equal")&&e.match("to"),o=(a,l)=>(e.req("than"),e.match("or")?(e.req("equal"),e.req("to"),n(l)):n(a));if(e.match("is")||e.match("am")){let a=!!e.match("not"),l=a?"not ":"";return e.match("in")?n(l+"in"):e.match("a")||e.match("an")?n(l+"a",!1,!0):e.match("empty")?n(l+"empty",!1):e.match("between")?n(l+"between"):!a&&e.match("less")?o("<","<="):!a&&e.match("greater")?o(">",">="):e.match("really")?(r(),n(a?"!==":"===")):e.match("equal")?(e.match("to"),n(a?"!=":"==")):n(a?"is not":"is")}if(e.match("equals"))return n("==");if(e.match("really"))return e.req("equals"),n("===");if(e.matchAny("exist","exists"))return n("exist",!1);let i=!!e.matchAny("do","does");i&&e.req("not");let s=i?"not ":"",u=(a,l)=>e.match(a)??(i&&a!=="match"&&a!=="contain"?void 0:e.match(l));if(u("match","matches"))return n(s+"match");if(u("contain","contains"))return n(s+"contain");if(i&&e.match("exist"))return n("not exist",!1);if(u("include","includes"))return n(s+"include");if(e.match(i?"start":"starts"))return e.req("with"),n(s+"start with");if(e.match(i?"end":"ends"))return e.req("with"),n(s+"end with");if(u("precede","precedes"))return n(s+"precede");if(u("follow","follows"))return n(s+"follow");i&&e.expected("matches","contains","starts with","ends with","precede","follow")}function lt(e){let t=De(e),n=ln(e);if(!n)return t;let{operator:r}=n,o,i=!0,s,u;n.isType?(o=e.reqType("IDENTIFIER").value,i=!e.matchOp("!")):n.right&&(s=De(e),r.endsWith("match")&&(u=s.css));let a;r.endsWith("between")&&(e.req("and"),a=De(e));let l=!1;e.match("ignoring")&&(e.req("case"),l=!0);let c=f=>l&&typeof f=="string"?f.toLowerCase():f,d=s?.type==="symbol"&&"scope"in s&&s.scope==="local"&&s.name!=="undefined"&&s.name!=="null"?s.name:void 0;return{type:"comparisonOperator",operator:r,left:t,right:s,right2:a,typeName:o,ignoringCase:l,start:t.start,end:e.endPos(),ev:f=>I([t.ev(f),u??s?.ev(f),a?.ev(f)],([p,g,w])=>{if(o){let k=Ke(p,o,i);return r==="a"?k:!k}if(d&&g===void 0&&(r==="is"||r==="is not")){let k=!!ie(p,d);return r==="is"?k:!k}return gt(r,c(p),c(g),w)})}}function ft(e,t){let n=v(e,"contains")??v(e,"includes");if(!H(n))throw new Error("The value does not have a contains or includes method on it");return!!Reflect.apply(n,e,[t])}function fn(e,t){let n=v(e,"match")??v(e,"matches");if(!H(n))throw new Error("The value does not have a match or matches method on it");return!!Reflect.apply(n,e,[t])}var dt=(e,t,n)=>e instanceof Node&&t instanceof Node&&(e.compareDocumentPosition(t)&n)!==0;function gt(e,t,n,r){if(e==="not between")return b(t)<b(n)||b(t)>b(r);if(e.startsWith("not "))return!gt(e.slice(4),t,n,r);switch(e){case"is":case"==":return t==n;case"is not":case"!=":return t!=n;case"===":return t===n;case"!==":return t!==n;case"<":return b(t)<b(n);case">":return b(t)>b(n);case"<=":return b(t)<=b(n);case">=":return b(t)>=b(n);case"match":return t!=null&&fn(t,n);case"in":return n!=null&&ft(n,t);case"contain":case"include":return t!=null&&ft(t,n);case"start with":return t!=null&&String(t).startsWith(String(n));case"end with":return t!=null&&String(t).endsWith(String(n));case"between":return b(t)>=b(n)&&b(t)<=b(r);case"precede":return dt(t,n,Node.DOCUMENT_POSITION_FOLLOWING);case"follow":return dt(t,n,Node.DOCUMENT_POSITION_PRECEDING);case"empty":return Fe(t);case"exist":return Je(t)}throw new Error("Unknown comparison : "+e)}function dn(e){let t=e.cur();switch(t.type){case"NUMBER":return e.consume(),Me("number",parseFloat(t.value),t);case"STRING":return pn(e);case"ID_REF":return vn(e);case"CLASS_REF":return Q(e);case"ATTRIBUTE_REF":return V(e);case"STYLE_REF":return Et(e)}if(t.op){if(t.value==="(")return mn(e);if(t.value==="[")return yn(e);if(t.value==="{")return gn(e);if(t.value==="<")return bn(e)}let n=e.match("true")??e.match("false");if(n)return Me("boolean",n.value==="true",n);let r=e.match("null");if(r)return Me("null",null,r);for(let o of e.g.leaves){let i=o(e);if(i)return i}return wn(e)}function Me(e,t,n){return{type:e,value:t,start:n.start,end:n.end,ev:()=>t,stat:()=>t}}function mn(e){let t=e.pos();e.consume();let n=e.withoutFollows(()=>E(e));return e.reqOp(")"),{type:"parenthesized",expr:n,start:t,end:e.endPos(),ev:r=>n.ev(r)}}var hn=(e,t)=>I(e.map(n=>typeof n=="string"?n:n.ev(t)),n=>n.map(r=>r===void 0?"":`${r}`).join(""));function wt(e,t){let n=e.child(fe(t,!0),t),r=[],o="";do{o+=n.lastWs();let i=n.cur();if(i.value==="$"){n.consume();let s=n.matchOp("{");r.push(o,E(n)),o="",s&&n.reqOp("}")}else i.value==="\\"?(n.consume(),n.consume()):n.hasMore()&&(o+=n.consume().value)}while(n.hasMore());return r.push(o+n.lastWs()),r}function pn(e){let t=e.consume(),n=t.value,r={type:"string",value:n,start:t.start,end:t.end,ev:()=>n};if(t.template){let o=r.parts=wt(e,n);r.ev=i=>hn(o,i)}else r.stat=()=>n;return r}function yn(e){let t=e.pos();e.consume();let n=[];if(!e.matchOp("]")){do n.push(E(e));while(e.matchOp(","));e.reqOp("]")}return{type:"arrayLiteral",values:n,start:t,end:e.endPos(),ev:r=>I(n.map(o=>o.ev(r)),o=>o)}}function gn(e){let t=e.pos();e.consume();let n=[],r=[],o=()=>e.cur().op&&e.cur().value==="}";if(!e.matchOp("}")){do{let i=e.matchType("STRING");if(i)n.push(i.value);else if(e.matchOp("["))n.push(E(e)),e.reqOp("]");else{let s="";for(let u=e.matchType("IDENTIFIER")??e.matchOp("-");u;u=e.matchType("IDENTIFIER")??e.matchOp("-"))s+=u.value;n.push(s)}e.reqOp(":"),r.push(E(e))}while(e.matchOp(",")&&!o());e.reqOp("}")}return{type:"objectLiteral",keys:n,values:r,start:t,end:e.endPos(),ev:i=>I([...n.map(s=>typeof s=="string"?s:s.ev(i)),...r.map(s=>s.ev(i))],s=>Object.fromEntries(n.map((u,a)=>[String(s[a]),s[n.length+a]])))}}function vt(e){return e.matchType("STRING")?.value??e.consumeUntil(void 0,"WHITESPACE").map(t=>t.value).join("")}function wn(e){let t=e.pos(),n;e.match("global")?n="global":e.match("element")?(n="element",e.matchOp("'")&&e.req("s")):e.match("dom")?n="inherited":e.match("local")&&(n="local");let r=e.matchOp(":"),o=!r&&e.matchOp("^"),i=e.matchType("IDENTIFIER");if(!i?.value)return;let s=(r?":":o?"^":"")+i.value,a=n??{$:"global",":":"element","^":"inherited"}[s[0]]??"local",l;return a==="inherited"&&e.match("on")&&(l=e.withFollow(["to","into","before","after","then"],()=>E(e))),{type:"symbol",name:s,scope:a,start:t,end:e.endPos(),ev:c=>rt(s,c,a,l?.ev(c)),lhs:()=>{},put:(c,d,m)=>ot(s,c,a,m,l?.ev(c))}}var bt=(e,t)=>{let n=t.value.substring(2);return E(e.child(fe(n),n))};function vn(e){let t=e.consume(),n=(o,i)=>Oe(o.me).getElementById(String(i)),r={type:"idRef",start:t.start,end:t.end,ev:()=>null,lhs:()=>{},put:(o,i,s)=>T(r.ev(o),u=>u&&ce(u,s))};if(t.template){let o=r.expr=bt(e,t);r.ev=i=>T(o.ev(i),s=>n(i,s))}else{let o=r.value=t.value.substring(1);r.css=t.value,r.ev=i=>n(i,o)}return r}function Q(e){let t=e.matchType("CLASS_REF");if(!t)return;let n={type:"classRef",start:t.start,end:t.end,ev:()=>null,lhs:()=>{},put:(r,o,i)=>T(n.ev(r),s=>ce(Array.from(s instanceof j?s:[]),i))};if(t.template){let r=n.expr=bt(e,t);n.ev=o=>T(r.ev(o),i=>new j("."+i,o.me,!0))}else{let r=n.css=t.value;n.className=r.slice(1),n.ev=o=>new j(r,o.me,!0)}return n}var $e=class extends j{constructor(n,r){super("",n);this.parts=r}get css(){let n=0;return this.parts.map(r=>R(r)?`[data-hs-query-id='${n++}']`:`${r??""}`).join("")}select(){let n=this.parts.filter(R);n.forEach((o,i)=>o.setAttribute("data-hs-query-id",String(i)));let r=super.select();return n.forEach(o=>o.removeAttribute("data-hs-query-id")),r}};function bn(e){let t=e.pos();e.consume();let n=e.consumeUntil("/").map(o=>o.type==="STRING"?`"${o.value}"`:o.value).join("");e.reqOp("/"),e.reqOp(">");let r={type:"queryRef",css:n,start:t,end:e.endPos(),ev:o=>new j(n,o.me),lhs:()=>{},put:(o,i,s)=>T(r.ev(o),u=>ce(Array.from(u instanceof j?u:[]),s))};if(/\$[^=]/.test(n)){let o=r.parts=wt(e,n);r.ev=i=>I(o.map(s=>typeof s=="string"?s:s.ev(i)),s=>new $e(i.me,s))}return r}function V(e){let t=e.matchType("ATTRIBUTE_REF");if(!t)return;let n=t.value.startsWith("[")?t.value.slice(2,-1):t.value.slice(1),[r,o]=n.split("="),i=o&&/^["']/.test(o)?o.slice(1,-1):o;return{type:"attributeRef",name:r,value:i,css:`[${n}]`,start:t.start,end:t.end,ev:s=>ae(s.you||s.me,r),lhs:()=>{},put:(s,u,a)=>ue(s.you||s.me,r,a)}}function Et(e){let t=e.matchType("STYLE_REF");if(!t)return;let n=t.value.startsWith("*computed-"),r=t.value.slice(n?10:1);return{type:n?"computedStyleRef":"styleRef",name:r,start:t.start,end:t.end,ev:o=>(n?Ee:be)(o.you||o.me,r),lhs:()=>{},put:(o,i,s)=>xe(o.you||o.me,r,s)}}function xt(e){let t=e.pos();if(!e.matchOp("{"))return;let n=[""],r=[];for(;e.hasMore();){if(e.matchOp("\\"))e.consume();else{if(e.matchOp("}"))break;if(e.match("$")){let o=e.matchOp("{");r.push(E(e)),o&&e.reqOp("}"),n.push("")}else n[n.length-1]+=e.text(e.consume())}n[n.length-1]+=e.lastWs()}return{type:"styleLiteral",parts:n,exprs:r,start:t,end:e.endPos(),ev:o=>I(r.map(i=>i.ev(o)),i=>n.map((s,u)=>s+(u in i?`${i[u]}`:"")).join(""))}}function me(e){let t=e.endPos();return{type:"implicitMeTarget",start:t,end:t,ev:n=>n.you||n.me}}function kt(e){let t=e.matchType("IDENTIFIER");if(!t)return;let n=[t.value],r=e.matchOp(".")??e.matchOp(":");if(r)do n.push(e.reqType("IDENTIFIER","NUMBER").value);while(e.matchOp(r.value));return n.join(r?.value??"")}function Te(e,t="Expected event name"){return e.matchType("STRING")?.value??kt(e)??e.err(t)}function D(e,t){return xn(e,t)??kn(e,t)??Sn(e,t)??Tn(e,t)??Nn(e,t)??Pn(e,t)??Rn(e,t)??On(e,t)??En(e,t)??t}function En(e,t){for(let n of e.g.indirects){let r=n(e,t);if(r)return r}}function xn(e,t){if(!e.matchOp("."))return;let n=e.reqType("IDENTIFIER").value,r=e.text(t),o={type:"propertyAccess",root:t,prop:n,start:t.start,end:e.endPos(),ev:i=>T(o.root.ev(i),s=>ie(s,n)),lhs:i=>o.root.ev(i),put:(i,s,u)=>{A(s,r),ke(s,n,u)},del:(i,s)=>{A(s,r),S(s,u=>{M(u)&&delete u[n],x.wroteProperty(u)})}};return D(e,o)}function kn(e,t){if(!e.match("of"))return;let n=G(e),r,o=t;for(;o.root;)r=o,o=o.root;let s={symbol:"property",attributeRef:"attribute",styleRef:"style",computedStyleRef:"computed"}[o.type],u=o.name;if(!s||u===void 0)return e.err("Cannot take a property of a non-symbol: "+o.type);let a=e.text(n),l={property:ie,attribute:ae,style:be,computed:Ee}[s],c={type:"ofExpression",root:n,name:u,kind:s,start:t.start,end:e.endPos(),ev:d=>T(c.root.ev(d),m=>l(m,u)),lhs:d=>c.root.ev(d),put:(d,m,f)=>{A(m,a),s==="attribute"?ue(m,u,f):s==="property"?ke(m,u,f):xe(m,u,f)},del:(d,m)=>{A(m,a),S(m,f=>{s==="attribute"?R(f)&&f.removeAttribute(u):s==="property"?(M(f)&&delete f[u],x.wroteProperty(f)):f instanceof HTMLElement&&f.style.removeProperty(u)})}};return r?(r.root=c,D(e,t)):D(e,c)}function Tn(e,t){let n=e.matchOp("'"),r=t.type==="symbol"&&["my","its","your"].includes(t.name??"")&&["IDENTIFIER","ATTRIBUTE_REF","STYLE_REF"].includes(e.cur().type);if(!n&&!r)return;n&&e.req("s");let o=V(e)??Et(e),i=o?void 0:e.reqType("IDENTIFIER").value,s=e.text(t),u=l=>i!==void 0?ie(l,i):o?.type==="attributeRef"?ae(l,o.name):o?.type==="computedStyleRef"?Ee(l,o.name):o&&be(l,o.name),a={type:"possessive",root:t,prop:i,attribute:o,start:t.start,end:e.endPos(),ev:l=>T(a.root.ev(l),u),lhs:l=>a.root.ev(l),put:(l,c,d)=>{A(c,s),i!==void 0?ke(c,i,d):o?.type==="attributeRef"?ue(c,o.name,d):o&&xe(c,o.name,d)}};return D(e,a)}function Nn(e,t){if(!e.match("in"))return;let n=G(e),r=(s,u)=>{if(s==null)return[];let a=[],l=v(s,"css");if(typeof l=="string")S(u,c=>R(c)&&a.push(...Ie(c,l)));else if(R(s)){let c=!1;if(S(u,d=>{d instanceof Node&&d.contains(s)&&(c=!0)}),c)return s}else S(s,c=>S(u,d=>c===d&&a.push(c)));return a},o={type:"inExpression",root:t,target:n,start:t.start,end:e.endPos(),ev:s=>I([o.root.ev(s),n.ev(s)],([u,a])=>r(u,a)),lhs:s=>o.ev(s),put:(s,u,a)=>ce(u,a)},i;if(e.peek("where"))for(let s of e.g.collections)i??=s(e,o);return D(e,i??o)}function Pn(e,t){if(!e.match("as"))return;e.match("a")||e.match("an");let n=o=>{let i=kt(e)??e.err("Expected dotOrColonPath"),s={type:"asExpression",root:o,conversion:i,start:o.start,end:e.endPos(),ev:u=>T(s.root.ev(u),a=>Xe(a,i))};return s},r=n(t);for(;e.matchOp("|");)r=n(r);return D(e,r)}function Rn(e,t){if(!e.matchOp("("))return;let n=[];if(!e.matchOp(")")){do n.push(E(e));while(e.matchOp(","));e.reqOp(")")}let r=e.text(t),o=t.root?e.text(t.root):"",i={type:"functionCall",root:t,args:n,start:t.start,end:e.endPos(),ev:s=>{let u=i.root,a=u.prop,l=a===void 0?void 0:u.root;return I([(l??u).ev(s),...n.map(c=>c.ev(s))],([c,...d])=>{if(!l||a===void 0)return mt(c,void 0,d,s,r);A(c,o);let m=mt(v(c,a),c,d,s,r);return Ze(c,a),m})}};return D(e,i)}function mt(e,t,n,r,o){if(!H(e))throw A(e,o),new Error(`'${o}' is not a function`);return v(e,"hyperfunc")&&n.push(r),Reflect.apply(e,t,n)}function Sn(e,t){let n=V(e);return n&&Cn(e,t,n)}function Cn(e,t,n){let r=e.text(t),o={type:"attributeRefAccess",root:t,attribute:n,start:t.start,end:e.endPos(),ev:i=>T(o.root.ev(i),s=>ae(s,n.name)),lhs:i=>o.root.ev(i),put:(i,s,u)=>{A(s,r),ue(s,n.name,u)}};return o}function On(e,t){if(!e.matchOp("["))return;let n=!!e.matchOp(".."),r=E(e),o=!1,i;!n&&e.matchOp("..")&&(o=!0,e.cur().op&&e.cur().value==="]"||(i=E(e))),e.reqOp("]");let s=e.text(t),u=(c,d)=>b(d)<0?b(v(c,"length"))+b(d):b(d),a=(c,d,m)=>{let f=v(c,"slice");return H(f)?Reflect.apply(f,c,[d,m]):void 0},l={type:"arrayIndex",root:t,first:r,second:i,andBefore:n,andAfter:o,start:t.start,end:e.endPos(),ev:c=>I([l.root.ev(c),r.ev(c),i?.ev(c)],([d,m,f])=>d==null?null:n?a(d,0,u(d,m)+1):o?f==null?a(d,b(m)):a(d,b(m),u(d,f)+1):v(d,String(m))),lhs:c=>I([l.root.ev(c),r.ev(c)],d=>d),put:(c,d,m)=>{let[f,p]=Array.isArray(d)?d:[];A(f,s),M(f)&&(f[String(p)]=m)},del:(c,d)=>{if(n||o)throw new Error("Cannot remove a slice - use a single index");let[m,f]=Array.isArray(d)?d:[];A(m,s),Array.isArray(m)?m.splice(u(m,f),1):M(m)&&delete m[String(f)],x.wroteProperty(m)}};return D(e,l)}function Pt(e){let t=Q(e);if(!t)return;let n=[t];for(let r=Q(e);r;r=Q(e))n.push(r);return n}var Ge=(e,t)=>(e??[]).map(n=>T(n.ev(t),r=>String(v(r,"className")))),In=e=>e.split(";").map(t=>t.split(":")[0].trim()).filter(Boolean),We=e=>e instanceof HTMLElement||e instanceof SVGElement?e.style:void 0,Tt=(e,t,n,r,o)=>t?it(e,t,n,i=>R(i)&&r(i),i=>R(i)&&o(i)):S(e,i=>R(i)&&r(i)),he=(e,{name:t,value:n},r)=>r?e.setAttribute(t,String(n)):e.removeAttribute(t),Rt=(e,t,n,r,o,i)=>i?Tt(t,n,r,s=>he(s,i,e),s=>he(s,i,!e)):I(o.map(s=>Tt(t,n,r,u=>u.classList.toggle(String(s),e),u=>u.classList.toggle(String(s),!e))),()=>{});function St(e){let t=Pt(e),n=t?void 0:V(e);return{refs:t,attribute:n,css:t||n?void 0:xt(e)}}function Ct(e){e.commands.add=(t,n,r)=>{let{refs:o,attribute:i,css:s}=St(t),u;!o&&!i&&!s&&(u=t.withFollow(["to"],()=>E(t)),t.cur().value!=="to"&&t.err("Expected either a class reference or attribute expression"));let a=t.match("to")?E(t):me(t),l=t.match("when")?E(t):void 0,c=o||i?l:void 0,d=t.text(a);return{type:"addCommand",classRefs:o,attributeRef:i,css:s,value:u,to:a,when:c,start:r,end:t.endPos(),run:f=>I([a.ev(f),s?.ev(f),u?.ev(f),...Ge(o,f)],([p,g,w,...k])=>{if(A(p,d),u){if(Array.isArray(p))p.push(w);else if(p instanceof Set)p.add(w);else throw p instanceof Map?new Error("Use 'set myMap[key] to value' for Maps"):new Error("Cannot add to "+typeof p);x.wroteProperty(p)}else if(s)S(p,q=>{let N=We(q);N&&(N.cssText+=g)});else return Rt(!0,p,c,f,k,i)})}}}var An=e=>e instanceof Node||e instanceof NodeList||e instanceof HTMLCollection;function Ot(e){e.commands.remove=(t,n,r)=>{let{refs:o,attribute:i,css:s}=St(t),u=o||i||s?void 0:E(t),a=t.match("from")?E(t):u?void 0:me(t),l;t.match("when")&&(u&&t.err("'when' clause is not supported when removing elements"),l=E(t));let c=a?t.text(a):"",d=u?t.text(u):"",m=(p,g,w)=>{if(w==null&&u?.del&&u.lhs&&!An(g)){let k=u;return T(u.lhs(p),q=>k.del?.(p,q))}if(A(g,d),Array.isArray(w)){let k=w.indexOf(g);k>-1&&w.splice(k,1),x.wroteProperty(w)}else w instanceof Set||w instanceof Map?(w.delete(g),x.wroteProperty(w)):S(g,k=>{R(k)&&k.parentElement&&(w==null||w instanceof Node&&w.contains(k))&&k.parentElement.removeChild(k)})};return{type:"removeCommand",classRefs:o,attributeRef:i,css:s,element:u,from:a,when:l,start:r,end:t.endPos(),run:p=>I([a?.ev(p),s?.ev(p),u?.ev(p),...Ge(o,p)],([g,w,k,...q])=>{if(u)return m(p,k,g);if(A(g,c),s){let N=In(String(w));S(g,C=>N.forEach(O=>We(C)?.removeProperty(O)))}else return Rt(!1,g,l,p,q,i)})}}}var Nt=(e,t,n)=>(r,o,i)=>{i?o.style[e]=i:r==="toggle"?o.style[e]=getComputedStyle(o)[e]===t?n:t:o.style[e]=r==="hide"?t:n},It={display(e,t,n){if(!n&&t instanceof HTMLDialogElement){e==="hide"||e==="toggle"&&t.open?t.close():t.open||t.show();return}let r=W(t);n?t.style.display=n:e==="toggle"?It.display(getComputedStyle(t).display==="none"?"show":"hide",t):e==="hide"?(r.originalDisplay??=t.style.display,t.style.display="none"):r.originalDisplay&&r.originalDisplay!=="none"?t.style.display=r.originalDisplay:t.style.removeProperty("display")},visibility:Nt("visibility","hidden","visible"),opacity:Nt("opacity","0","1"),hidden(e,t){(e==="toggle"?!t.hasAttribute("hidden"):e==="hide")?t.setAttribute("hidden",""):t.removeAttribute("hidden")}};function Fn(e,t){let n=t??B.defaultHideShowStrategy??"display";return B.hideShowStrategies[n]??It[n]??e.err("Unknown show/hide strategy : "+n)}function At(e){e.commands.toggle=(t,n,r)=>{t.matchAny("the","my");let o={type:"toggleCommand",start:r,end:r,run:()=>{}},i;if(t.cur().type==="STYLE_REF"){let g=o.styleProp=t.consume().value.slice(1);i=Fn(t,g),o.on=t.match("of")?t.withFollow(["with","between"],()=>E(t)):me(t)}else if(t.match("between")){let g=Q(t);if(g)t.req("and"),o.between=[g,Q(t)??t.err("Expected classRef")];else{let w=V(t)??t.err("Expected either a class reference or attribute expression");t.req("and"),o.between=[w,V(t)??t.err("Expected attributeRef")]}}else if(!(o.classRefs=Pt(t))&&!(o.attributeRef=V(t))){let g=t.g.toggleElement;if(!g)o.target=t.withFollow(["between"],()=>yt(t));else{let w=t.withFollow(["between","as"],()=>G(t));if(!t.peek("between"))return g(t,w,r);o.target=Ue(t,w)}}if(!o.styleProp&&!o.target&&(o.on=t.match("on")?E(t):me(t)),t.match("between")){let g=o.betweenValues=t.withFollow(["and"],()=>{let w=[E(t)];for(;t.matchOp(",");)w.push(E(t));return w});t.req("and"),g.push(E(t))}o.target&&!o.betweenValues&&t.err("toggle <expression> requires 'between' with values"),t.peek("for")&&!t.peek("in",2)?(t.match("for"),o.time=E(t)):t.match("until")&&(o.until=Te(t),t.match("from")&&(o.from=E(t))),o.end=t.endPos();let{on:s,target:u,betweenValues:a,between:l,attributeRef:c,styleProp:d}=o,m=s?t.text(s):"",f=(g,w)=>g[(g.findIndex(k=>k==w)+1)%g.length],p=(g,w,k,q)=>{if(a&&u?.lhs&&u.put){let N=u;return I([u.ev(g),u.lhs(g)],([C,O])=>N.put?.(g,O,f(k,C)))}if(a&&d)return S(w,N=>{let C=We(N);if(!C||!R(N))return;let O=C.getPropertyValue(d)||getComputedStyle(N).getPropertyValue(d);C.setProperty(d,String(f(k,O)))});A(w,m),S(w,N=>{if(R(N))if(i)N instanceof HTMLElement&&i("toggle",N);else if(l){let[C,O]=l;if(C.type==="classRef"&&O.type==="classRef"){let[_,Z]=[String(C.className),String(O.className)],J=N.classList.contains(_);N.classList.toggle(_,!J),N.classList.toggle(Z,J)}else if(C.type==="attributeRef"&&O.type==="attributeRef"){let _=N.getAttribute(C.name)===String(C.value);he(N,_?C:O,!1),he(N,_?O:C,!0)}}else c?he(N,c,!N.hasAttribute(c.name)):q.forEach(C=>N.classList.toggle(String(C)))})};return o.run=g=>I([s?.ev(g),o.time?.ev(g),o.from?.ev(g),I((a??[]).map(w=>w.ev(g)),w=>w),...Ge(o.classRefs,g)],([w,k,q,N,...C])=>{let O=()=>p(g,w,Array.isArray(N)?N:[],C);if(o.time)return new Promise(_=>{O(),setTimeout(()=>{O(),_()},b(k))});if(o.until){let _=o.until,Z=q||g.me;return new Promise(J=>{z(Z)&&Z.addEventListener(_,()=>{O(),J()},{once:!0}),O()})}return T(O(),()=>{})}),o}}var Y=class extends Error{constructor(n,r,o,i){super(n);this.token=r;this.source=o;this.expected=i}written},Ft=()=>({commands:Object.create(null),features:Object.create(null),leaves:[],indirects:[],unaries:[],postfixes:[],collections:[]}),Ne=class e{constructor(t,n,r){this.g=t;this.tokens=n;this.src=r;let o=r.length;this.eof={type:"EOF",value:"<<<EOF>>>",start:o,end:o,line:0,column:0},this.last=this.eof,this.skipWs()}i=0;follows=[];eof;last;child(t,n){return new e(this.g,t,n)}tok(t=0,n=!1){let r=this.i;for(;;){if(!n)for(;this.tokens[r]?.type==="WHITESPACE";)r++;if(t--===0)return this.tokens[r]??this.eof;r++}}cur(){return this.tokens[this.i]??this.eof}hasMore(){return this.i<this.tokens.length}pos(){return this.cur().start}endPos(){return this.last.end}text(t){return this.src.substring(t.start,t.end)}match(t,n="IDENTIFIER"){if(this.follows.includes(t))return;let r=this.cur();if(r.value===t&&r.type===n)return this.consume()}matchOp(t){let n=this.cur();if(n.op&&n.value===t)return this.consume()}matchType(...t){if(t.includes(this.cur().type))return this.consume()}matchAny(...t){for(let n of t){let r=this.match(n);if(r)return r}}matchAnyOp(...t){for(let n of t){let r=this.matchOp(n);if(r)return r}}req(t){return this.match(t)??this.expected(t)}reqOp(t){return this.matchOp(t)??this.expected(t)}reqType(...t){return this.matchType(...t)??this.expected(...t)}peek(t,n=0,r="IDENTIFIER"){let o=this.tok(n);if(o.value===t&&o.type===r)return o}consume(){return this.hasMore()?(this.last=this.tokens[this.i++],this.skipWs(),this.last):this.eof}skipWs(){for(;this.tokens[this.i]?.type==="WHITESPACE";)this.i++}consumeUntil(t,n){let r=[],o=this.cur();for(;(n==null||o.type!==n)&&(t==null||o.value!==t)&&o.type!=="EOF";)r.push(o),this.i++,o=this.cur();return this.skipWs(),r}lastWs(){let t=this.tokens[this.i-1];return t?.type==="WHITESPACE"?t.value:""}pushFollow(...t){return this.follows.push(...t),t.length}popFollow(t=1){this.follows.length-=t}withFollow(t,n){let r=this.pushFollow(...t);try{return n()}finally{this.popFollow(r)}}withoutFollows(t){let n=this.follows;this.follows=[];try{return t()}finally{this.follows=n}}err(t,n){let r=this.cur();throw new Y(t??"Unexpected Token : "+r.value,r,this.src,n)}expected(...t){this.err(t.length===1?`Expected '${t[0]}' but found '${this.cur().value}'`:"Expected one of: "+t.map(n=>`'${n}'`).join(", "),t)}commandStart(t){return t.value in this.g.commands}featureStart(t){return t.value in this.g.features}commandBoundary(t){return["end","then","else","otherwise",")"].includes(t.value)||this.commandStart(t)||this.featureStart(t)||t.type==="EOF"}};function Ve(e){let t=e.source.split(`
|
|
6
|
+
`),n=e.token.line?e.token.line-1:t.length-1,r=t[n]??"",o=e.token.line?e.token.column:Math.max(0,r.length-1),i=String(n+1).length,s=" ".repeat(i+5+o);return` ${n+1} | ${r}
|
|
7
|
+
`+s+"^".repeat(Math.max(1,e.token.value.length))+`
|
|
8
|
+
`+s+e.message+`
|
|
9
|
+
`}function Lt(e){let t=e.pos();if(e.matchOp("(")){let a=Lt(e)??e.err("Expected command");return e.reqOp(")"),a}let n=e.cur(),r=e.g.commands[n.value],o;if(r?o=e.match(n.value)&&r(e,n.value,t):n.type==="IDENTIFIER"&&(o=e.g.pseudo?.(e,t)),!o||!e.match("unless"))return o;let i=o,s=E(e);return{type:"unlessStatementModifier",command:i,condition:s,start:t,end:e.endPos(),run:a=>T(s.ev(a),l=>l?void 0:i.run(a))}}function te(e){let t=[];for(;e.hasMore();){let n=Lt(e);if(!n)break;t.push(n),e.match("then")}return t}function qt(e){let t=e.pos();if(e.matchOp("(")){let o=qt(e);return e.reqOp(")"),o}let n=e.cur(),r=e.g.features[n.value];return!r||!e.match(n.value)?e.err("Expected feature"):r(e,t)}function ze(e){let t=e.pos(),n=[];for(;e.hasMore();){let r=e.cur();if(e.featureStart(r)||r.value==="(")n.push(qt(e)),e.match("end");else{if(r.value==="end")break;e.err()}}return{type:"hyperscript",features:n,start:t,end:e.endPos()}}function _t(e){let t={};return e.match("catch")&&(t.errorSymbol=e.reqType("IDENTIFIER").value,t.errorHandler=te(e)),e.match("finally")&&(t.finallyHandler=te(e)),t}function Dt(e){let t=[],n=e.tok(1).value,r=e.tok(2).value;if(e.cur().value==="("&&(n===")"||r===","||r===")")){e.matchOp("(");do t.push(e.reqType("IDENTIFIER").value);while(e.matchOp(","));e.reqOp(")")}return t}var Ht=Ft();function $t(...e){for(let t of e)t(Ht)}var Ut=e=>new Ne(Ht,fe(e),e);function Ln(e){let t=Ut(e),n=ze(t);return t.hasMore()&&t.err(),n}function Gt(e){let t=Ut(e),n=t.cur(),r=t.commandStart(n)?{kind:"commands",commands:te(t)}:t.featureStart(n)?{kind:"features",program:ze(t)}:{kind:"expression",expression:E(t)};return t.hasMore()&&t.err(),r}function Mt(e,t){let n;try{n=Gt(e)}catch(i){throw i instanceof Y?new Error(i.message+`
|
|
10
|
+
|
|
11
|
+
`+Ve(i)):i}let r=document.body;if(n.kind==="features"){for(let i of n.program.features)i.install(r,r);return}let o=Object.assign(le(r,void 0,r,null),t);return n.kind==="expression"?n.expression.ev(o):T(X(n.commands,o),i=>{let s=v(i,"k")==="return"?v(i,"value"):void 0;return s!==void 0?s:o.result})}var Wt=()=>B.attributes.replaceAll(" ","").split(","),Vt=e=>e instanceof HTMLScriptElement&&e.type==="text/hyperscript";function qn(e){for(let t of Wt())if(e.hasAttribute(t))return e.getAttribute(t);return Vt(e)?e.innerText:null}var _n=e=>{let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n);return t},zt=[];function jt(e){if(e.closest(B.disableSelector))return;let t=qn(e);if(!t)return;let n=_n(t);if(ee(e)?.initialized){if(ee(e)?.scriptHash===n)return se.enter(e);Pe(e)}if(!L(e,"hyperscript:before:init"))return;Object.assign(W(e),{initialized:!0,scriptHash:n});let r=Vt(e)?document.body:e,o=t;try{for(let s of zt)o=s(o,e)??o;let{features:i}=Ln(o);se.enter(e);for(let s of i)s.install(r,e);e.setAttribute("data-hyperscript-powered","true"),L(e,"hyperscript:after:init"),setTimeout(()=>L(r,"load",{hyperscript:!0}),1)}catch(i){if(i instanceof Y){o!==t&&(i.written=t),L(e,"hyperscript:parse-error",{errors:[i]});let s=i.written?`
|
|
12
|
+
rewritten from: ${i.written}
|
|
13
|
+
`:"";console.error("hyperscript: 1 parse error(s) on:",e,`
|
|
14
|
+
|
|
15
|
+
`+Ve(i)+s)}else L(e,"exception",{error:i}),console.error("hyperscript errors were found on the following element:",e,`
|
|
16
|
+
|
|
17
|
+
`,i)}}var Bt=[],Qt=[];function pe(e){if(!(e instanceof Element||e instanceof Document||e instanceof DocumentFragment))return;for(let n of Bt)n(e);let t=Wt().map(n=>`[${n}]`).join(", ")+", [type='text/hyperscript']";e instanceof Element&&e.matches(t)&&jt(e),e.querySelectorAll(t).forEach(jt);for(let n of Qt)n(e)}function Pe(e){let t=ee(e);if(t){L(e,"hyperscript:before:cleanup");for(let{target:n,event:r,handler:o}of t.listeners??[])n.removeEventListener(r,o);for(let n of t.observers??[])n.disconnect();for(let n of t.timers??[])clearTimeout(n);x.stop(e),e.querySelectorAll("[data-hyperscript-powered]").forEach(Pe),L(e,"hyperscript:after:cleanup"),e.removeAttribute("data-hyperscript-powered"),Ye(e)}}se.process=pe;function Dn(e){try{let t=Gt(e);return t.kind==="features"?{...t.program,errors:[]}:{...t.kind==="commands"?t.commands[0]:t.expression,errors:[]}}catch(t){if(t instanceof Y)return{errors:[t]};throw t}}var Yt=Object.assign(Mt,{config:Object.assign(B,{conversions:Object.assign(Se,{dynamicResolvers:Ce})}),use(e){e(Yt)},addBeforeProcessHook:e=>void Bt.push(e),addAfterProcessHook:e=>void Qt.push(e),addSourceTransform:e=>void zt.push(e),evaluate:Mt,parse:Dn,process:pe,processNode:pe,cleanup:Pe,internals:{runtime:{cleanup:Pe,processNode:pe}},version:"3.3.0"});function Zt(){if(Object.assign(globalThis,{_hyperscript:Yt}),typeof document>"u")return;let e=()=>{pe(document.documentElement),document.dispatchEvent(new Event("hyperscript:ready"))};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):setTimeout(e)}function Mn(e,t){if(typeof e!="object"||e===null)return{queue:[],executing:!1};let n=W(e).eventQueues??=new Map,r=n.get(t);return r||n.set(t,r={queue:[],executing:!1}),r}function Be(e,t){let n=Mn(e.me,t);if(n.executing&&!t.every){if(t.queue==="none"||t.queue==="first"&&n.queue.length>0)return;t.queue!=="all"&&(n.queue.length=0),n.queue.push(e);return}n.executing=!0;let r=o=>{n.executing=!1;let i=n.queue.shift();if(i&&setTimeout(()=>Be(i,t),1),o){let{error:s}=o;console.error(v(s,"message")??s),console.error(v(s,"stack")),L(e.me,"exception",{error:s})}};oe(()=>T(st(e,t.body,t),()=>r()),o=>r({error:o}))}function jn(e,t){if(!z(t))return;let n=W(t),r=n.listeners??=[],o=n.observers??=[],i=n.timers??=new Set;for(let s of e.events){let u={execCount:0},a=s.elsewhere?[document]:s.from?s.from.ev(le(t,e,t,null)):[t];S(a,l=>{if(!z(l)){console.warn("'%s' feature ignored because target does not exists:",e.displayName,t);return}let c=s.on;if(s.mutationSpec&&l instanceof Node){c="hyperscript:mutation";let m=new MutationObserver(f=>L(l,c,{mutationList:f,observer:m}));m.observe(l,s.mutationSpec),o.push(m)}if(s.intersectionSpec&&l instanceof Element){c="hyperscript:intersection";let m=new IntersectionObserver(f=>{for(let p of f)L(l,c,{observer:m,entry:p,intersecting:p.isIntersecting,isIntersecting:p.isIntersecting,intersectionRatio:p.intersectionRatio})},s.intersectionSpec);m.observe(l),o.push(m)}if(s.resizeSpec&&l instanceof Element){c="hyperscript:resize";let m=new ResizeObserver(f=>{for(let p of f){let{width:g,height:w}=p.contentRect;L(l,c,{width:g,height:w,contentRect:p.contentRect,entry:p})}});m.observe(l),o.push(m)}let d=m=>{if(t instanceof Node&&l!==t&&!t.isConnected){l.removeEventListener(c,d);return}let f=le(t,e,t,m);if(!(s.elsewhere&&t instanceof Node&&m.target instanceof Node&&t.contains(m.target))){s.from&&(f.result=l);for(let p of s.args){let g=v(m,p);g!==void 0?f.locals[p]=g:f.detail!=null&&(f.locals[p]=v(f.detail,p))}if(s.filter){f.meta.context=m;try{if(!s.filter.ev(f))return}finally{f.meta.context=void 0}}if(s.inExpr?.css){let p=m.target instanceof Element?m.target:null;for(;p&&!p.matches(s.inExpr.css);)p=p.parentElement;if(!p)return;f.result=p}if(u.execCount++,s.startCount){let p=u.execCount;if(s.endCount?p<s.startCount||p>s.endCount:s.unbounded?p<s.startCount:p!==s.startCount)return}if(s.debounceTime){u.debounced&&(clearTimeout(u.debounced),i.delete(u.debounced)),i.add(u.debounced=setTimeout(()=>Be(f,e),s.debounceTime));return}if(s.throttleTime){if(u.lastExec&&Date.now()<u.lastExec+s.throttleTime)return;u.lastExec=Date.now()}Be(f,e)}};l.addEventListener(c,d),r.push({target:l,event:c,handler:d})})}}function Hn(e){if(!e.match("of"))return{attributes:!0,characterData:!0,childList:!0,attributeOldValue:!0,characterDataOldValue:!0};let t={};do if(e.match("anything"))Object.assign(t,{attributes:!0,subtree:!0,characterData:!0,childList:!0});else if(e.match("childList"))t.childList=!0;else if(e.match("attributes"))t.attributes=!0;else if(e.match("subtree"))t.subtree=!0;else if(e.match("characterData"))t.characterData=!0;else if(e.cur().type==="ATTRIBUTE_REF"){let n=e.consume().value;n.startsWith("@")||e.err("Only shorthand attribute references are allowed here"),(t.attributeFilter??=[]).push(n.substring(1))}else e.err("Unknown mutation config specification");while(e.match("or"));return(t.attributes||t.attributeFilter)&&(t.attributeOldValue=!0),t.characterData&&(t.characterDataOldValue=!0),t}function $n(e){let t={};if(e.match("with")){let n=de(E(e));n instanceof Element&&(t.root=n)}if(e.match("having"))do e.match("margin")?t.rootMargin=vt(e):e.match("threshold")?t.threshold=Number(de(E(e))):e.err("Unknown intersection config specification");while(e.match("and"));return t}function Un(e,t){let n=Te(e),r=Dt(e),o;e.matchOp("[")&&(o=E(e),e.reqOp("]"));let i,s,u=!1;t?i=1:e.cur().type==="NUMBER"&&(i=parseInt(e.consume().value),e.match("to")?s=parseInt(e.consume().value):e.match("and")&&(u=!0,e.req("on")));let a={on:n,args:r,filter:o,startCount:i,endCount:s,unbounded:u,elsewhere:!1,resizeSpec:n==="resize"};n==="intersection"?a.intersectionSpec=$n(e):n==="mutation"&&(a.mutationSpec=Hn(e)),e.match("from")&&(e.match("elsewhere")?a.elsewhere=!0:a.from=e.withFollow(["or"],()=>E(e))),!a.from&&!a.elsewhere&&e.match("elsewhere")&&(a.elsewhere=!0),e.match("in")&&(a.inExpr=G(e));let l=()=>(e.req("at"),Number(de(G(e))));return e.match("debounced")?a.debounceTime=l():e.match("throttled")&&(a.throttleTime=l()),a}function Jt(e){e.features.on=(t,n)=>{let r=!!t.match("every"),o=!r&&!!t.match("first"),i=[];do i.push(Un(t,o));while(t.match("or"));let s="last";!r&&t.match("queue")&&(t.match("all")?s="all":t.match("first")?s="first":t.match("none")?s="none":t.req("last"));let u=te(t),a={type:"onFeature",displayName:"on "+i.map(l=>l.on).join(" or "),events:i,body:u,every:r,queue:s,..._t(t),start:n,end:t.endPos(),install:l=>jn(a,l)};return a}}$t(Jt,Ct,Ot,At);Zt();})();
|
package/dist/on.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `on` feature: event handlers.
|
|
3
|
+
*
|
|
4
|
+
* on [every|first] <event>[(args)] [[filter]] [<count> [to <count> | and on]]
|
|
5
|
+
* [from <target> | elsewhere] [in <selector>] [debounced|throttled at <time>]
|
|
6
|
+
* [or <event> …] [queue all|first|last|none]
|
|
7
|
+
* <commands> [catch <name> <commands>] [finally <commands>] [end]
|
|
8
|
+
*
|
|
9
|
+
* Follows upstream `parsetree/features/on.js`. The handler body runs
|
|
10
|
+
* synchronously until a command returns a promise, so `halt the event` takes
|
|
11
|
+
* effect before `dispatchEvent` returns.
|
|
12
|
+
*/
|
|
13
|
+
import type { Cmd, Expr, Feature, Handlers } from './ast';
|
|
14
|
+
import type { Grammar } from './parser';
|
|
15
|
+
export interface EventSpec {
|
|
16
|
+
on: string;
|
|
17
|
+
args: string[];
|
|
18
|
+
filter?: Expr;
|
|
19
|
+
from?: Expr;
|
|
20
|
+
inExpr?: Expr;
|
|
21
|
+
elsewhere: boolean;
|
|
22
|
+
startCount?: number;
|
|
23
|
+
endCount?: number;
|
|
24
|
+
unbounded: boolean;
|
|
25
|
+
debounceTime?: number;
|
|
26
|
+
throttleTime?: number;
|
|
27
|
+
mutationSpec?: MutationObserverInit;
|
|
28
|
+
intersectionSpec?: IntersectionObserverInit;
|
|
29
|
+
resizeSpec: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface OnFeature extends Feature, Handlers {
|
|
32
|
+
type: 'onFeature';
|
|
33
|
+
displayName: string;
|
|
34
|
+
events: EventSpec[];
|
|
35
|
+
body: Cmd[];
|
|
36
|
+
every: boolean;
|
|
37
|
+
queue: 'all' | 'first' | 'last' | 'none';
|
|
38
|
+
}
|
|
39
|
+
export declare function on(g: Grammar): void;
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token stream and grammar registry.
|
|
3
|
+
*
|
|
4
|
+
* `Parser` is the one object every grammar rule receives. It only knows about
|
|
5
|
+
* tokens; the rules themselves live in the registry (`Grammar`), which a bundle
|
|
6
|
+
* fills by registering the commands, features and expression kinds it wants.
|
|
7
|
+
* A rule that is not registered does not exist, so a bundle is a list of imports.
|
|
8
|
+
*
|
|
9
|
+
* Errors throw. A rule either returns its node, returns `undefined` to say
|
|
10
|
+
* "not mine" before consuming anything, or raises a `ParseError`.
|
|
11
|
+
*/
|
|
12
|
+
import type { Cmd, Expr, Feature } from './ast';
|
|
13
|
+
import type { Token } from './tokenizer';
|
|
14
|
+
export declare class ParseError extends Error {
|
|
15
|
+
readonly token: Token;
|
|
16
|
+
readonly source: string;
|
|
17
|
+
readonly expected?: string[] | undefined;
|
|
18
|
+
/** What the author wrote, when a plugin rewrote the script before it was parsed. */
|
|
19
|
+
written?: string;
|
|
20
|
+
constructor(message: string, token: Token, source: string, expected?: string[] | undefined);
|
|
21
|
+
}
|
|
22
|
+
export type CommandRule = (p: Parser, keyword: string, start: number) => Cmd | undefined;
|
|
23
|
+
export type FeatureRule = (p: Parser, start: number) => Feature;
|
|
24
|
+
export type LeafRule = (p: Parser) => Expr | undefined;
|
|
25
|
+
export type ChainRule = (p: Parser, root: Expr) => Expr | undefined;
|
|
26
|
+
export interface Grammar {
|
|
27
|
+
commands: Record<string, CommandRule>;
|
|
28
|
+
features: Record<string, FeatureRule>;
|
|
29
|
+
/** Tried in order; the symbol rule goes last so it does not swallow keywords. */
|
|
30
|
+
leaves: LeafRule[];
|
|
31
|
+
/** `.prop`, `'s prop`, `(args)`, `[i]`, `of`, `in`, `as`, `@attr` after a value. */
|
|
32
|
+
indirects: ChainRule[];
|
|
33
|
+
/** Prefix forms: `not`, `no`, `first`, `next`, … */
|
|
34
|
+
unaries: LeafRule[];
|
|
35
|
+
/** `1s`, `10px`, `x:Type`. */
|
|
36
|
+
postfixes: ChainRule[];
|
|
37
|
+
/** `where`, `sorted by`, `mapped to`, … — looser than the indirects. */
|
|
38
|
+
collections: ChainRule[];
|
|
39
|
+
/** A bare call used as a command: `foo()`, `me.focus()`. */
|
|
40
|
+
pseudo?: (p: Parser, start: number) => Cmd | undefined;
|
|
41
|
+
/** `toggle <element>`, with no `between`: not upstream's (`additions.ts`). */
|
|
42
|
+
toggleElement?: (p: Parser, target: Expr, start: number) => Cmd;
|
|
43
|
+
}
|
|
44
|
+
export declare const createGrammar: () => Grammar;
|
|
45
|
+
export declare class Parser {
|
|
46
|
+
readonly g: Grammar;
|
|
47
|
+
readonly tokens: Token[];
|
|
48
|
+
readonly src: string;
|
|
49
|
+
private i;
|
|
50
|
+
private follows;
|
|
51
|
+
private readonly eof;
|
|
52
|
+
/** The last token consumed by a match. */
|
|
53
|
+
last: Token;
|
|
54
|
+
constructor(g: Grammar, tokens: Token[], src: string);
|
|
55
|
+
child(tokens: Token[], src: string): Parser;
|
|
56
|
+
/** The nth token from here; whitespace is skipped unless `ws`. */
|
|
57
|
+
tok(n?: number, ws?: boolean): Token;
|
|
58
|
+
cur(): Token;
|
|
59
|
+
hasMore(): boolean;
|
|
60
|
+
/** Start offset of the current token — what a rule records as its node's `start`. */
|
|
61
|
+
pos(): number;
|
|
62
|
+
/** End offset of the last consumed token — a node's `end`. */
|
|
63
|
+
endPos(): number;
|
|
64
|
+
text(node: {
|
|
65
|
+
start: number;
|
|
66
|
+
end: number;
|
|
67
|
+
}): string;
|
|
68
|
+
match(value: string, type?: string): Token | undefined;
|
|
69
|
+
matchOp(value: string): Token | undefined;
|
|
70
|
+
matchType(...types: string[]): Token | undefined;
|
|
71
|
+
matchAny(...values: string[]): Token | undefined;
|
|
72
|
+
matchAnyOp(...values: string[]): Token | undefined;
|
|
73
|
+
req(value: string): Token;
|
|
74
|
+
reqOp(value: string): Token;
|
|
75
|
+
reqType(...types: string[]): Token;
|
|
76
|
+
/** Is the nth token from here this identifier (or this `type`)? Consumes nothing. */
|
|
77
|
+
peek(value: string, n?: number, type?: string): Token | undefined;
|
|
78
|
+
consume(): Token;
|
|
79
|
+
private skipWs;
|
|
80
|
+
/** Raw tokens (whitespace included) up to a token with this value or type. */
|
|
81
|
+
consumeUntil(value?: string, type?: string): Token[];
|
|
82
|
+
/** The whitespace just before the current token, if any. */
|
|
83
|
+
lastWs(): string;
|
|
84
|
+
pushFollow(...words: string[]): number;
|
|
85
|
+
popFollow(count?: number): void;
|
|
86
|
+
/** Parse with `words` reserved for the caller, e.g. the `to` of `set x to y`. */
|
|
87
|
+
withFollow<T>(words: string[], f: () => T): T;
|
|
88
|
+
/** Parse with no reserved words — inside parentheses the outer rule's words are free again. */
|
|
89
|
+
withoutFollows<T>(f: () => T): T;
|
|
90
|
+
err(message?: string, expected?: string[]): never;
|
|
91
|
+
expected(...expected: string[]): never;
|
|
92
|
+
commandStart(token: Token): boolean;
|
|
93
|
+
featureStart(token: Token): boolean;
|
|
94
|
+
commandBoundary(token: Token): boolean;
|
|
95
|
+
}
|
|
96
|
+
/** One error, with the offending line and a caret under the token. */
|
|
97
|
+
export declare function formatError(e: ParseError): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reactivity: effects that re-run when what they read changes, and the three
|
|
3
|
+
* features built on them — `when … changes`, `live`, `bind`.
|
|
4
|
+
*
|
|
5
|
+
* While an effect evaluates, the runtime reports every variable, property,
|
|
6
|
+
* attribute and DOM query it reads (through `rx` in `runtime.ts`); those become
|
|
7
|
+
* the effect's dependencies. Writes schedule the dependent effects for the next
|
|
8
|
+
* microtask.
|
|
9
|
+
* Follows upstream `core/runtime/reactivity.js` and `parsetree/features/{when,live,bind}.js`.
|
|
10
|
+
*/
|
|
11
|
+
import type { Cmd, Expr, Feature } from './ast';
|
|
12
|
+
import type { Grammar } from './parser';
|
|
13
|
+
/** Run `handler` with the value of `expression` now, and again whenever that value changes. */
|
|
14
|
+
export declare function createEffect(expression: () => unknown, handler: (value: unknown) => void, element?: Element): () => void;
|
|
15
|
+
export interface WhenFeature extends Feature {
|
|
16
|
+
type: 'whenFeature';
|
|
17
|
+
watched: Expr[];
|
|
18
|
+
body: Cmd[];
|
|
19
|
+
}
|
|
20
|
+
export interface LiveFeature extends Feature {
|
|
21
|
+
type: 'liveFeature';
|
|
22
|
+
body: Cmd[];
|
|
23
|
+
}
|
|
24
|
+
export interface BindFeature extends Feature {
|
|
25
|
+
type: 'bindFeature';
|
|
26
|
+
left: Expr;
|
|
27
|
+
right: Expr;
|
|
28
|
+
}
|
|
29
|
+
/** Registers `when`, `live` and `bind`, and switches dependency tracking on. */
|
|
30
|
+
export declare function reactivity(g: Grammar): void;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime values: contexts, symbol scopes, collections, conversions, events.
|
|
3
|
+
* Nothing here parses; `engine.ts` connects parsing to the DOM.
|
|
4
|
+
*
|
|
5
|
+
* Semantics follow upstream _hyperscript's `core/runtime/runtime.js`.
|
|
6
|
+
*/
|
|
7
|
+
import type { Cmd, Completion, Ctx, Expr, Feature, Handlers, LoopScope, Scope } from './ast';
|
|
8
|
+
import { type MaybeP } from './util';
|
|
9
|
+
export type Conversion = (value: unknown) => unknown;
|
|
10
|
+
export interface Config {
|
|
11
|
+
/** Attributes that hold a script. */
|
|
12
|
+
attributes: string;
|
|
13
|
+
defaultTransition: string;
|
|
14
|
+
disableSelector: string;
|
|
15
|
+
/** Strategy `hide` / `show` / `toggle` use when none is named; `display` if unset. */
|
|
16
|
+
defaultHideShowStrategy?: string;
|
|
17
|
+
/** Extra strategies by name. */
|
|
18
|
+
hideShowStrategies: Record<string, (op: 'hide' | 'show' | 'toggle', elt: HTMLElement, arg?: string) => void>;
|
|
19
|
+
/** `fetch` throws when the response status matches one of these. */
|
|
20
|
+
fetchThrowsOn: RegExp[];
|
|
21
|
+
}
|
|
22
|
+
export declare const config: Config;
|
|
23
|
+
/** `as <Name>` conversions. The everyday ones are built in; `conversions.ts` adds the rest. */
|
|
24
|
+
export declare const conversions: Record<string, Conversion>;
|
|
25
|
+
/** Tried before the table, for parameterised names such as `Fixed:2`. */
|
|
26
|
+
export declare const dynamicResolvers: ((name: string, value: unknown) => unknown)[];
|
|
27
|
+
/** Set by `engine.ts`, so commands can initialise content they insert. */
|
|
28
|
+
export declare const host: {
|
|
29
|
+
process(_node: unknown): void;
|
|
30
|
+
/** A scripted element is being initialised, or was found again. Templates use it. */
|
|
31
|
+
enter(_elt: Element): void;
|
|
32
|
+
};
|
|
33
|
+
export interface EventQueue {
|
|
34
|
+
queue: Ctx[];
|
|
35
|
+
executing: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface ElementData {
|
|
38
|
+
initialized?: boolean;
|
|
39
|
+
scriptHash?: number;
|
|
40
|
+
/** Variable scopes: `elementScope`, plus one per installed behavior. */
|
|
41
|
+
scopes?: Record<string, Record<string, unknown>>;
|
|
42
|
+
/** Functions and namespaces defined by `def` on this element. */
|
|
43
|
+
features?: Record<string, unknown>;
|
|
44
|
+
listeners?: {
|
|
45
|
+
target: EventTarget;
|
|
46
|
+
event: string;
|
|
47
|
+
handler: EventListener;
|
|
48
|
+
}[];
|
|
49
|
+
observers?: {
|
|
50
|
+
disconnect(): void;
|
|
51
|
+
}[];
|
|
52
|
+
timers?: Set<ReturnType<typeof setTimeout>>;
|
|
53
|
+
eventQueues?: Map<object, EventQueue>;
|
|
54
|
+
originalDisplay?: string;
|
|
55
|
+
/** Property values before the first `transition`, for `to initial`. */
|
|
56
|
+
transitionInitials?: Record<number, unknown>;
|
|
57
|
+
/** The loops of the template rendered into this element. */
|
|
58
|
+
loops?: Record<string, LoopScope>;
|
|
59
|
+
}
|
|
60
|
+
export declare const peekData: (elt: object) => ElementData | undefined;
|
|
61
|
+
export declare const dropData: (elt: object) => boolean;
|
|
62
|
+
export declare function dataOf(elt: object): ElementData;
|
|
63
|
+
/**
|
|
64
|
+
* Where reads and writes report to the reactivity module. Every member is a
|
|
65
|
+
* no-op until `reactivity.ts` is registered, so a bundle without `when`, `bind`
|
|
66
|
+
* or `live` pays only for these calls.
|
|
67
|
+
*/
|
|
68
|
+
export declare const rx: {
|
|
69
|
+
/** True while an effect is evaluating: reads are then recorded as its dependencies. */
|
|
70
|
+
tracking: boolean;
|
|
71
|
+
readGlobal(_name: string): void;
|
|
72
|
+
readElement(_name: string, _element: unknown): void;
|
|
73
|
+
readProperty(_object: unknown, _name: string): void;
|
|
74
|
+
readAttribute(_element: unknown, _name: string): void;
|
|
75
|
+
/** A selector was queried under `root`: any DOM change inside it re-runs the reader. */
|
|
76
|
+
readQuery(_root: Node): void;
|
|
77
|
+
wroteGlobal(_name: string): void;
|
|
78
|
+
wroteElement(_name: string, _element: unknown): void;
|
|
79
|
+
/** A property was assigned, or the object was mutated in place. */
|
|
80
|
+
wroteProperty(_object: unknown): void;
|
|
81
|
+
stop(_element: Element): void;
|
|
82
|
+
};
|
|
83
|
+
/** Methods that change their receiver, by constructor name. */
|
|
84
|
+
export declare const mutatingMethods: Record<string, string[]>;
|
|
85
|
+
/** After calling `target.method(…)`: report the change if the method is a mutating one. */
|
|
86
|
+
export declare function maybeNotify(target: unknown, method: string): void;
|
|
87
|
+
export declare const getRootNode: (node: unknown) => Document | ShadowRoot;
|
|
88
|
+
export declare const escapeSelector: (s: string) => string;
|
|
89
|
+
/** `querySelectorAll`, recorded as a dependency of the effect that is evaluating. */
|
|
90
|
+
export declare function query(root: ParentNode & Node, css: string): NodeListOf<Element>;
|
|
91
|
+
/** A live query: re-run each time it is iterated, like upstream's ElementCollection. */
|
|
92
|
+
export declare class ElementCollection implements Iterable<Element> {
|
|
93
|
+
private readonly raw;
|
|
94
|
+
private readonly relativeTo;
|
|
95
|
+
private readonly escape;
|
|
96
|
+
constructor(raw: string, relativeTo: unknown, escape?: boolean);
|
|
97
|
+
get css(): string;
|
|
98
|
+
get className(): string;
|
|
99
|
+
get length(): number;
|
|
100
|
+
contains(node: Node): boolean;
|
|
101
|
+
select(): NodeListOf<Element>;
|
|
102
|
+
[Symbol.iterator](): Iterator<Element>;
|
|
103
|
+
}
|
|
104
|
+
export declare const shouldAutoIterate: (v: unknown) => v is Iterable<unknown>;
|
|
105
|
+
/** Apply to each member of a collection, or to the value itself. */
|
|
106
|
+
export declare function implicitLoop(value: unknown, f: (v: unknown) => void): void;
|
|
107
|
+
export declare function forEach(value: unknown, f: (v: unknown) => void): void;
|
|
108
|
+
export declare const resolveProperty: (root: unknown, prop: string) => unknown;
|
|
109
|
+
export declare const resolveAttribute: (root: unknown, name: string) => unknown;
|
|
110
|
+
export declare const resolveStyle: (root: unknown, prop: string) => unknown;
|
|
111
|
+
export declare const resolveComputedStyle: (root: unknown, prop: string) => unknown;
|
|
112
|
+
export declare const setAttribute: (target: unknown, name: string, value: unknown) => void;
|
|
113
|
+
export declare const setStyle: (target: unknown, prop: string, value: unknown) => void;
|
|
114
|
+
export declare const setProperty: (target: unknown, prop: string, value: unknown) => void;
|
|
115
|
+
export declare function nullCheck(value: unknown, source: string): void;
|
|
116
|
+
export declare const isEmpty: (v: unknown) => boolean;
|
|
117
|
+
export declare function doesExist(v: unknown): boolean;
|
|
118
|
+
export declare function typeCheck(value: unknown, typeName: string, nullOk: boolean): boolean;
|
|
119
|
+
export declare function convert(value: unknown, type: string): unknown;
|
|
120
|
+
/** Turn a value into nodes to insert: nodes are moved, anything else is parsed as HTML. */
|
|
121
|
+
export declare function toFragment(value: unknown): DocumentFragment;
|
|
122
|
+
/** Replace each target element with the value (a node is cloned per target), then initialise it. */
|
|
123
|
+
export declare function replaceInDom(target: unknown, value: unknown): void;
|
|
124
|
+
export declare function triggerEvent(target: unknown, name: string, detail?: Record<string, unknown>, sender?: unknown): boolean;
|
|
125
|
+
/** The scope an element keeps for its own script, or for one installed behavior. */
|
|
126
|
+
export declare const scopeOf: (elt: object, name?: string) => Record<string, unknown>;
|
|
127
|
+
/**
|
|
128
|
+
* Names every script can read without declaring them. Locals inherit from this
|
|
129
|
+
* object, so a context costs nothing extra and a local of the same name wins.
|
|
130
|
+
*/
|
|
131
|
+
export declare const ambient: Record<string, unknown>;
|
|
132
|
+
export declare function makeContext(owner: unknown, feature: Feature | undefined, me: unknown, event: unknown): Ctx;
|
|
133
|
+
/** Define `path.name` globally (for the body or no element) or on an element's own features. */
|
|
134
|
+
export declare function assignToNamespace(elt: unknown, path: string[], name: string, value: unknown): void;
|
|
135
|
+
export declare function resolveSymbol(name: string, ctx: Ctx, scope?: Scope, target?: unknown): unknown;
|
|
136
|
+
export declare function setSymbol(name: string, ctx: Ctx, scope: Scope | undefined, value: unknown, target?: unknown): void;
|
|
137
|
+
/**
|
|
138
|
+
* Run commands in order. Synchronous commands run in this call; the first one
|
|
139
|
+
* that returns a promise makes the rest continue when it settles. A command that
|
|
140
|
+
* returns a signal (`return`, `break`, `continue`) stops the list and hands the
|
|
141
|
+
* signal to whoever called it.
|
|
142
|
+
*/
|
|
143
|
+
export declare function runList(cmds: Cmd[], ctx: Ctx, from?: number): MaybeP<Completion>;
|
|
144
|
+
/** `try { f() } catch (e) { rescue(e) }` for a value that may be a promise. */
|
|
145
|
+
export declare function guard<T>(f: () => MaybeP<T>, rescue: (e: unknown) => MaybeP<T>): MaybeP<T>;
|
|
146
|
+
/**
|
|
147
|
+
* Run the body of a handler or function: the body, its `catch` block on an
|
|
148
|
+
* error, and its `finally` block in every case. An error with no `catch`, or
|
|
149
|
+
* one thrown inside the `catch` block, propagates — thrown if everything so far
|
|
150
|
+
* was synchronous, as a rejection otherwise.
|
|
151
|
+
*/
|
|
152
|
+
export declare function runBlock(ctx: Ctx, body: Cmd[], handlers: Handlers): MaybeP<Completion>;
|
|
153
|
+
/** Narrow what came back from a command list to a completion. */
|
|
154
|
+
export declare const signalOf: (v: unknown) => Completion;
|
|
155
|
+
/**
|
|
156
|
+
* Evaluate a `when` clause once per target with `it` bound to the target, then
|
|
157
|
+
* apply `yes` to the targets that passed and `no` to the rest. The result is the
|
|
158
|
+
* list that passed.
|
|
159
|
+
*/
|
|
160
|
+
export declare function implicitLoopWhen(targets: unknown, when: Expr, ctx: Ctx, yes: (elt: unknown) => void, no: (elt: unknown) => void): MaybeP<void>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Statement grammar: commands, command lists and the top-level program.
|
|
3
|
+
*
|
|
4
|
+
* There is exactly one command-list rule, and it throws on anything it cannot
|
|
5
|
+
* place — a leftover token is a parse error, never a silently dropped word.
|
|
6
|
+
* Follows upstream `core/kernel.js`.
|
|
7
|
+
*/
|
|
8
|
+
import type { Cmd, Expr, Feature, Handlers, Program } from './ast';
|
|
9
|
+
import type { Parser } from './parser';
|
|
10
|
+
export interface UnlessNode extends Cmd {
|
|
11
|
+
type: 'unlessStatementModifier';
|
|
12
|
+
command: Cmd;
|
|
13
|
+
condition: Expr;
|
|
14
|
+
}
|
|
15
|
+
export declare function command(p: Parser): Cmd | undefined;
|
|
16
|
+
/** Commands, optionally separated by `then`, up to the first token that starts none. */
|
|
17
|
+
export declare function commandList(p: Parser): Cmd[];
|
|
18
|
+
export declare function feature(p: Parser): Feature;
|
|
19
|
+
/** The script of one element: features, each optionally closed by `end`. */
|
|
20
|
+
export declare function program(p: Parser): Program;
|
|
21
|
+
/** `catch <name> <commands>` and `finally <commands>` after a handler body. */
|
|
22
|
+
export declare function errorAndFinally(p: Parser): Handlers;
|
|
23
|
+
/** `(a, b)` after an event name: fields to copy from the event into locals. */
|
|
24
|
+
export declare function eventArgs(p: Parser): string[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Templates: `render <template> [with <args>] [here | into <target>]`, the text lines a
|
|
3
|
+
* template is made of, and `escape html <value>`.
|
|
4
|
+
*
|
|
5
|
+
* A template is the text of an element (usually `<script type="text/hyperscript-template">`).
|
|
6
|
+
* It is read line by line: a line that starts with `#` is a command (`#for x in xs`, `#if`,
|
|
7
|
+
* `#else`, `#end`, `#continue`), any other line is text with `${…}` holes. The lines parse
|
|
8
|
+
* into an ordinary command list, so loops and conditionals are the engine's own.
|
|
9
|
+
* Follows upstream `parsetree/commands/template.js` and the `"lines"` mode of its tokenizer.
|
|
10
|
+
*/
|
|
11
|
+
import type { Cmd, Ctx, Expr, LoopScope } from './ast';
|
|
12
|
+
import { type Grammar } from './parser';
|
|
13
|
+
import { type Token } from './tokenizer';
|
|
14
|
+
import { type MaybeP } from './util';
|
|
15
|
+
/**
|
|
16
|
+
* Tokens for a template. Command lines are tokenized as hyperscript; a text line becomes
|
|
17
|
+
* one token carrying the line. Leading whitespace and blank lines are dropped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function templateTokens(source: string): Token[];
|
|
20
|
+
export interface TemplateError {
|
|
21
|
+
line: number;
|
|
22
|
+
message: string;
|
|
23
|
+
/** The `${…}` expression the error is in. */
|
|
24
|
+
expr: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function parseTemplate(g: Grammar, source: string): {
|
|
27
|
+
commands: Cmd[];
|
|
28
|
+
errors: TemplateError[];
|
|
29
|
+
};
|
|
30
|
+
/** One piece of a text line: literal text, or a `${…}` hole. */
|
|
31
|
+
type Part = string | {
|
|
32
|
+
value: Expr;
|
|
33
|
+
condition?: Expr;
|
|
34
|
+
otherwise?: Expr;
|
|
35
|
+
escape: boolean;
|
|
36
|
+
};
|
|
37
|
+
export interface TemplateTextNode extends Cmd {
|
|
38
|
+
type: 'templateText';
|
|
39
|
+
parts: Part[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Run a parsed template against a context, then hand `done` the HTML (markers included)
|
|
43
|
+
* and what each loop iterated over.
|
|
44
|
+
*/
|
|
45
|
+
export declare function runTemplate<R>(commands: Cmd[], ctx: Ctx, done: (html: string, loops: Record<string, LoopScope>) => R): MaybeP<R>;
|
|
46
|
+
export interface RenderNode extends Cmd {
|
|
47
|
+
type: 'renderCommand';
|
|
48
|
+
template: Expr;
|
|
49
|
+
args?: Expr;
|
|
50
|
+
/** `here`: the result becomes the content of `me`. */
|
|
51
|
+
here: boolean;
|
|
52
|
+
/** `into <target>`: the result becomes the content of the target. */
|
|
53
|
+
target?: Expr;
|
|
54
|
+
}
|
|
55
|
+
export interface EscapeNode extends Expr {
|
|
56
|
+
type: 'escapeExpression';
|
|
57
|
+
value: Expr;
|
|
58
|
+
}
|
|
59
|
+
/** Registers `render`, template text lines and `escape html`. */
|
|
60
|
+
export declare function render(g: Grammar): void;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tokenizer. Follows upstream _hyperscript's lexical rules (src/core/tokenizer.js):
|
|
3
|
+
* the same token kinds, the same context rule for `.x` / `#x` (a reference unless
|
|
4
|
+
* the previous character could end a value), and the same string escapes.
|
|
5
|
+
*
|
|
6
|
+
* `template` is the mode used for the inside of a backtick string or a query
|
|
7
|
+
* reference: text is kept verbatim until `$` / `${`, where normal lexing resumes.
|
|
8
|
+
* Upstream's third mode (`"lines"`, for the `render` command) is not here: `templates.ts`
|
|
9
|
+
* splits a template into lines itself and tokenizes the command lines with this function.
|
|
10
|
+
*/
|
|
11
|
+
export interface Token {
|
|
12
|
+
type: string;
|
|
13
|
+
value: string;
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
line: number;
|
|
17
|
+
column: number;
|
|
18
|
+
/** An operator or punctuation token. */
|
|
19
|
+
op?: boolean;
|
|
20
|
+
/** A backtick string, or a `.{…}` / `#{…}` reference. */
|
|
21
|
+
template?: boolean;
|
|
22
|
+
/** The text of a template line (`templates.ts`). */
|
|
23
|
+
content?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function tokenize(src: string, template?: boolean): Token[];
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sync-until-promise plumbing and the few value guards the engine needs.
|
|
3
|
+
*
|
|
4
|
+
* The engine never awaits a value that is not a promise: every evaluation
|
|
5
|
+
* returns its value directly, and only a real thenable makes the rest of the
|
|
6
|
+
* work continue in a `.then`. That is what lets a handler made of synchronous
|
|
7
|
+
* commands finish before `dispatchEvent` returns.
|
|
8
|
+
*/
|
|
9
|
+
export type MaybeP<T> = T | PromiseLike<T>;
|
|
10
|
+
export declare const isP: (v: unknown) => v is PromiseLike<unknown>;
|
|
11
|
+
/** Continue with `f` now, or after `v` resolves if it is a promise. */
|
|
12
|
+
export declare const then1: <R>(v: unknown, f: (v: unknown) => MaybeP<R>) => MaybeP<R>;
|
|
13
|
+
/** Continue with every value resolved; synchronous when none is a promise. */
|
|
14
|
+
export declare const all: <R>(vals: unknown[], f: (vals: unknown[]) => MaybeP<R>) => MaybeP<R>;
|
|
15
|
+
/** Anything but null/undefined can be indexed in JavaScript. */
|
|
16
|
+
export declare const obj: (v: unknown) => v is Record<string, unknown>;
|
|
17
|
+
export declare const fn: (v: unknown) => v is (...args: unknown[]) => unknown;
|
|
18
|
+
export declare const get: (o: unknown, key: string) => unknown;
|
|
19
|
+
export declare const set: (o: unknown, key: string, value: unknown) => void;
|
|
20
|
+
export declare const isEl: (v: unknown) => v is Element;
|
|
21
|
+
/**
|
|
22
|
+
* Can events be heard on it? Asked by shape, as upstream's `on` does, not with
|
|
23
|
+
* `instanceof EventTarget`: an element of another window (an iframe's, or jsdom's beside
|
|
24
|
+
* node's own `EventTarget`) is a target too.
|
|
25
|
+
*/
|
|
26
|
+
export declare const isTarget: (v: unknown) => v is EventTarget;
|
|
27
|
+
export declare const isIterable: (v: unknown) => v is Iterable<unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* The operand of a JavaScript arithmetic or relational operator. The assertion
|
|
30
|
+
* is for the type checker only: at run time the language coerces the value
|
|
31
|
+
* exactly as it does in `a + b` or `a < b` written in JavaScript, which is the
|
|
32
|
+
* semantics hyperscript's operators have.
|
|
33
|
+
*/
|
|
34
|
+
export declare const num: (v: unknown) => number;
|