@hyperfixi/core 3.1.1 → 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/README.md +28 -36
- package/dist/ast/command-slots.d.ts +1 -1
- package/dist/ast/nodes.d.ts +2 -0
- package/dist/ast-utils/index.cjs +193 -48
- package/dist/ast-utils/index.mjs +193 -48
- package/dist/ast-utils/interchange/types.d.ts +19 -1
- package/dist/behaviors/index.cjs +19 -0
- package/dist/behaviors/index.mjs +19 -0
- package/dist/bundle-generator/index.cjs +36 -17
- package/dist/bundle-generator/index.mjs +36 -17
- package/dist/bundle-generator/parser-templates.d.ts +1 -1
- package/dist/chunks/bridge-CI9SOl8u.js +2 -0
- package/dist/chunks/browser-modular-7CpI5VF2.js +2 -0
- package/dist/chunks/index-BwXDEK0m.js +2 -0
- package/dist/chunks/index-DQi2o8Lk.js +2 -0
- package/dist/chunks/index-uCOQ8Qn0.js +2 -0
- package/dist/commands/animation/transition.d.ts +12 -6
- package/dist/commands/helpers/loop-executor.d.ts +2 -2
- package/dist/commands/helpers/numeric-target-parser.d.ts +1 -1
- package/dist/commands/helpers/variable-access.d.ts +5 -2
- package/dist/commands/helpers/write-target.d.ts +5 -0
- package/dist/commands/index.cjs +938 -425
- package/dist/commands/index.mjs +938 -425
- package/dist/commands/templates/render.d.ts +4 -4
- package/dist/commands/utility/beep.d.ts +0 -3
- package/dist/expressions/index.cjs +7 -13
- package/dist/expressions/index.mjs +7 -13
- package/dist/htmx/i18n-hooks.d.ts +4 -1
- package/dist/hyperfixi-browser-classic-i18n.js +1 -1
- package/dist/hyperfixi-browser.js +1 -1
- package/dist/hyperfixi-classic-i18n.js +1 -1
- package/dist/hyperfixi-hx-v4.js +1 -1
- package/dist/hyperfixi-hx.js +1 -1
- package/dist/hyperfixi-hybrid-complete.js +1 -1
- package/dist/hyperfixi-hybrid-hx.js +1 -1
- package/dist/hyperfixi-multilingual.js +1 -1
- package/dist/hyperfixi.js +1 -1
- package/dist/hyperfixi.mjs +1 -1
- package/dist/index.cjs +1149 -485
- package/dist/index.min.js +1 -1
- package/dist/index.mjs +1149 -485
- package/dist/lib/swap-executor.d.ts +1 -1
- package/dist/lokascript-browser-classic-i18n.js +1 -1
- package/dist/lokascript-browser.js +1 -1
- package/dist/lokascript-hybrid-complete.js +1 -1
- package/dist/lokascript-hybrid-hx.js +1 -1
- package/dist/lokascript-multilingual.js +1 -1
- package/dist/metadata.cjs +9 -9
- package/dist/metadata.d.ts +1 -1
- package/dist/metadata.mjs +9 -9
- package/dist/parser/command-grammar.d.ts +1 -0
- package/dist/parser/full-parser.cjs +396 -153
- package/dist/parser/full-parser.mjs +396 -153
- package/dist/parser/helpers/parsing-helpers.d.ts +3 -0
- package/dist/parser/hybrid/index.cjs +3 -0
- package/dist/parser/hybrid/index.mjs +3 -0
- package/dist/parser/hybrid/parser-core.cjs +3 -0
- package/dist/parser/hybrid/parser-core.mjs +3 -0
- package/dist/parser/hybrid-parser.cjs +3 -0
- package/dist/parser/hybrid-parser.mjs +3 -0
- package/dist/parser/parser-types.d.ts +2 -0
- package/dist/parser/parser.d.ts +9 -0
- package/dist/parser/pratt-parser.d.ts +2 -0
- package/dist/registry/index.cjs +535 -210
- package/dist/registry/index.mjs +535 -210
- package/dist/utils/beep.d.ts +8 -0
- package/dist/version.d.ts +1 -1
- package/package.json +21 -18
- package/vocab/htmx/ar.js +22 -20
- package/vocab/htmx/bn.js +21 -5
- package/vocab/htmx/de.js +33 -10
- package/vocab/htmx/en.js +4 -1
- package/vocab/htmx/es.js +28 -9
- package/vocab/htmx/fr.js +28 -8
- package/vocab/htmx/he.js +22 -1
- package/vocab/htmx/hi.js +28 -7
- package/vocab/htmx/id.js +29 -10
- package/vocab/htmx/it.js +26 -5
- package/vocab/htmx/ja.js +36 -11
- package/vocab/htmx/ko.js +27 -6
- package/vocab/htmx/ms.js +24 -1
- package/vocab/htmx/pl.js +27 -7
- package/vocab/htmx/pt.js +30 -9
- package/vocab/htmx/qu.js +32 -9
- package/vocab/htmx/ru.js +28 -6
- package/vocab/htmx/sw.js +28 -8
- package/vocab/htmx/th.js +19 -1
- package/vocab/htmx/tl.js +24 -1
- package/vocab/htmx/tr.js +34 -8
- package/vocab/htmx/uk.js +28 -6
- package/vocab/htmx/vi.js +27 -19
- package/vocab/htmx/zh.js +28 -9
- package/dist/chunks/bridge-D7qrHhV0.js +0 -2
- package/dist/chunks/browser-modular-C4LFxfoS.js +0 -2
- package/dist/chunks/index-C7lqD4mo.js +0 -2
- package/dist/chunks/index-CAPhqA6k.js +0 -2
- package/dist/chunks/index-CLdRyZaP.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";const t=new Set(["on","from","to","into","before","after","in","of","at","with","if","else","unless","end","then","and","or","not","repeat","times","for","each","while","until","toggle","add","remove","put","set","get","call","return","append","prepend","log","send","trigger","wait","settle","fetch","as","show","hide","take","increment","decrement","focus","blur","go","transition","over","the","a","an","my","its","me","it","you","first","last","next","previous","closest","parent","true","false","null","undefined","is","matches","contains","includes","exists","has","init","every","by","halt","via","values","default","event"]);function e(e){const s=[];let i=0;for(;e.length>i;){if(/\s/.test(e[i])){i++;continue}if("--"===e.slice(i,i+2)){for(;e.length>i&&"\n"!==e[i];)i++;continue}const r=i;if("<"===e[i]&&/[a-zA-Z]/.test(e[i+1]||"")){for(i++;e.length>i&&">"!==e[i];)i++;">"===e[i]&&i++;const t=e.slice(r,i);if(t.endsWith("/>")||t.endsWith(">")){const e=t.slice(1).replace(/\/?>$/,"");s.push({type:"selector",value:e,pos:r});continue}}if("'s"===e.slice(i,i+2)&&!/[a-zA-Z]/.test(e[i+2]||"")){s.push({type:"operator",value:"'s",pos:r}),i+=2;continue}if('"'===e[i]||"'"===e[i]){const t=e[i++];for(;e.length>i&&e[i]!==t;)"\\"===e[i]&&i++,i++;i++,s.push({type:"string",value:e.slice(r,i),pos:r});continue}if(/\d/.test(e[i])||"-"===e[i]&&/\d/.test(e[i+1]||"")){for("-"===e[i]&&i++;e.length>i&&/[\d.]/.test(e[i]);)i++;"ms"===e.slice(i,i+2)?i+=2:"s"!==e[i]||/[a-zA-Z]/.test(e[i+1]||"")?"px"===e.slice(i,i+2)&&(i+=2):i++,s.push({type:"number",value:e.slice(r,i),pos:r});continue}if(":"===e[i]){for(i++;e.length>i&&/[\w]/.test(e[i]);)i++;s.push({type:"localVar",value:e.slice(r,i),pos:r});continue}if("$"===e[i]){for(i++;e.length>i&&/[\w]/.test(e[i]);)i++;s.push({type:"globalVar",value:e.slice(r,i),pos:r});continue}if("@"===e[i]){for(i++;e.length>i&&/[\w-]/.test(e[i]);)i++;s.push({type:"selector",value:e.slice(r,i),pos:r});continue}if("#"===e[i]||"."===e[i]){if("."===e[i]&&e.slice(i+1).match(/^(once|prevent|stop|debounce|throttle)\b/i)){s.push({type:"symbol",value:".",pos:r}),i++;continue}for(i++;e.length>i&&/[\w-]/.test(e[i]);)i++;s.push({type:"selector",value:e.slice(r,i),pos:r});continue}if("["===e[i]){let t=i+1;for(;e.length>t&&/\s/.test(e[t]);)t++;const n=e[t]||"";if(/['"\d\[\]:\$\-]/.test(n)||""===n){s.push({type:"symbol",value:"[",pos:r}),i++;continue}{i++;let t=1;for(;e.length>i&&t>0;)"["===e[i]&&t++,"]"===e[i]&&t--,i++;s.push({type:"selector",value:e.slice(r,i),pos:r});continue}}if("]"===e[i]){s.push({type:"symbol",value:"]",pos:r}),i++;continue}if("'s"===e.slice(i,i+2)){s.push({type:"operator",value:"'s",pos:r}),i+=2;continue}const n=e.slice(i,i+2);if(["==","!=","<=",">=","&&","||"].includes(n))s.push({type:"operator",value:n,pos:r}),i+=2;else if("*"===e[i]&&/[a-zA-Z]/.test(e[i+1]||"")){for(i++;e.length>i&&/[\w-]/.test(e[i]);)i++;s.push({type:"styleProperty",value:e.slice(r,i),pos:r})}else if("+-*/%<>!".includes(e[i]))s.push({type:"operator",value:e[i],pos:r}),i++;else if("()[]{},.".includes(e[i]))s.push({type:"symbol",value:e[i],pos:r}),i++;else{if(/[a-zA-Z_]/.test(e[i])){for(;e.length>i&&/[\w-]/.test(e[i]);)i++;const n=e.slice(r,i),o=t.has(n.toLowerCase())?"keyword":"identifier";s.push({type:o,value:n,pos:r});continue}i++}}return s.push({type:"eof",value:"",pos:e.length}),s}const s={flip:"toggle",switch:"toggle",display:"show",reveal:"show",conceal:"hide",increase:"increment",decrease:"decrement",fire:"trigger",dispatch:"send",navigate:"go",goto:"go"},i={clicked:"click",pressed:"keydown",changed:"change",submitted:"submit",loaded:"load"};function r(t){const e=t.toLowerCase();return s[e]||e}function n(t){const e=t.toLowerCase();return i[e]||e}class o{constructor(t){this.pos=0,this.cmdMap={toggle:()=>this.parseToggle(),add:()=>this.parseAdd(),remove:()=>this.parseRemove(),put:()=>this.parsePut(),append:()=>this.parseInsertion("append"),prepend:()=>this.parseInsertion("prepend"),set:()=>this.parseSet(),get:()=>this.parseGet(),call:()=>this.parseCall(),log:()=>this.parseLog(),send:()=>this.parseSend("to"),trigger:()=>this.parseSend("on"),wait:()=>this.parseWait(),show:()=>this.parseShow(),hide:()=>this.parseHide(),take:()=>this.parseTake(),empty:()=>this.parseEmpty(),increment:()=>this.parseIncDec("increment"),decrement:()=>this.parseIncDec("decrement"),focus:()=>this.parseFocusBlur("focus"),blur:()=>this.parseFocusBlur("blur"),go:()=>this.parseGo(),return:()=>this.parseReturn(),transition:()=>this.parseTransition(),halt:()=>this.parseHalt(),copy:()=>this.parseCopy(),beep:()=>this.parseBeep(),push:()=>this.parseUrlCommand("push"),replace:()=>this.parseUrlCommand("replace"),morph:()=>this.parseMorph(),js:()=>this.parseJs(),throw:()=>this.parseThrow(),break:()=>this.parseBare("break"),continue:()=>this.parseBare("continue"),exit:()=>this.parseBare("exit")},this.source=t,this.tokens=e(t)}peek(t=0){return this.tokens[Math.min(this.pos+t,this.tokens.length-1)]}advance(){return this.tokens[this.pos++]}match(...t){const e=this.peek();return t.some(t=>e.value.toLowerCase()===t.toLowerCase())}matchType(...t){return t.includes(this.peek().type)}expect(t){if(!this.match(t)&&r(this.peek().value)!==t)throw Error(`Expected '${t}', got '${this.peek().value}'`);return this.advance()}isAtEnd(){return"eof"===this.peek().type}parse(){return this.match("on")?this.parseEventHandler():this.match("init")?(this.advance(),{type:"event",event:"init",modifiers:{},body:this.parseCommandSequence()}):this.match("every")?this.parseEveryHandler():{type:"sequence",commands:this.parseCommandSequence()}}parseEventHandler(){this.expect("on");const t=this.advance().value,e={};let s;for(;"."===this.peek().value;){this.advance();const t=this.advance().value.toLowerCase();if("once"===t)e.once=1;else if("prevent"===t)e.prevent=1;else if("stop"===t)e.stop=1;else if(("debounce"===t||"throttle"===t)&&"("===this.peek().value){this.advance();const s=this.advance().value;this.expect(")"),"debounce"===t?e.debounce=parseInt(s)||100:e.throttle=parseInt(s)||100}}return this.match("from")&&(this.advance(),s=this.parseExpression()),{type:"event",event:n(t),filter:s,modifiers:e,body:this.parseCommandSequence()}}parseEveryHandler(){return this.expect("every"),{type:"event",event:"interval:"+this.advance().value,modifiers:{},body:this.parseCommandSequence()}}parseCommandSequence(){const t=[];for(;!this.isAtEnd()&&!this.match("end","else");){const e=this.parseCommand();e&&t.push(e),this.match("then","and")&&this.advance()}return t}parseCommand(){if(this.match("if","unless"))return this.parseIf();if(this.match("repeat"))return this.parseRepeat();if(this.match("for"))return this.parseFor();if(this.match("while"))return this.parseWhile();if(this.match("fetch"))return this.parseFetchBlock();const t=r(this.peek().value);if(this.cmdMap[t])return this.cmdMap[t]();if(this.match("catch","finally"))throw Error(`'${this.peek().value}' needs the full parser (use hyperfixi.js)`);const e=this.peek();if(!(this.isAtEnd()||"identifier"!==e.type&&"keyword"!==e.type||this.match("then","and","end","else")))throw Error(`'${e.value}' needs the full parser (use hyperfixi.js)`);return this.isAtEnd()||this.match("then","and","end","else")||this.advance(),null}parseIf(){const t=this.match("unless");this.advance();const e=this.parseExpression(),s=this.parseCommandSequence();let i;return this.match("else")&&(this.advance(),i=this.parseCommandSequence()),this.match("end")&&this.advance(),{type:"if",condition:t?{type:"unary",operator:"not",operand:e}:e,body:s,elseBody:i}}parseRepeat(){let t;this.expect("repeat"),this.match("until","while","forever")||(t=this.parseExpression(),this.match("times")&&this.advance());const e=this.parseCommandSequence();return this.match("end")&&this.advance(),{type:"repeat",condition:t,body:e}}parseFor(){this.expect("for"),this.match("each")&&this.advance();const t=this.advance().value;this.expect("in");const e=this.parseExpression(),s=this.parseCommandSequence();return this.match("end")&&this.advance(),{type:"for",condition:{type:"forCondition",variable:t,iterable:e},body:s}}parseWhile(){this.expect("while");const t=this.parseExpression(),e=this.parseCommandSequence();return this.match("end")&&this.advance(),{type:"while",condition:t,body:e}}parseNakedUrl(){const t=this.peek(),e="operator"===t.type&&"/"===t.value,s=("http"===t.value||"https"===t.value)&&"://"===this.source.slice(t.pos+t.value.length,t.pos+t.value.length+3);if(!e&&!s)return null;let i=t.pos;for(;this.source.length>i&&!/\s/.test(this.source[i]);)i++;for(;!this.isAtEnd()&&this.peek().pos<i;)this.advance();return{type:"literal",value:this.source.slice(t.pos,i)}}parseFetchBlock(){this.expect("fetch");const t=this.parseNakedUrl()??this.parseExpression();let e,s,i={type:"literal",value:"text"};this.match("{")&&(this.pos--,e=this.parseExpression());for(let t=0;3>t;t++)if(!this.match("via")||s)if(this.match("as"))this.advance(),(this.match("a")||this.match("an"))&&this.advance(),i=this.parseExpression();else{if(!this.match("with")||e)break;this.advance(),e=this.parseExpression()}else this.advance(),s=this.parseExpression();return this.match("then")&&this.advance(),{type:"fetch",condition:{type:"fetchConfig",url:t,responseType:i,options:e,method:s},body:this.parseCommandSequence()}}parseToggle(){this.expect("toggle");const t=this.parseExpression();let e;return this.match("on")&&(this.advance(),e=this.parseExpression()),{type:"command",name:"toggle",args:[t],target:e}}parseAdd(){this.expect("add");const t=this.parseExpression();let e;return this.match("to")&&(this.advance(),e=this.parseExpression()),{type:"command",name:"add",args:[t],target:e}}parseRemove(){if(this.expect("remove"),this.matchType("selector")&&/^[.@]/.test(this.peek().value)){const t=this.parseExpression();let e;return this.match("from")&&(this.advance(),e=this.parseExpression()),{type:"command",name:"removeClass",args:[t],target:e}}return{type:"command",name:"remove",args:[],target:this.parseExpression()}}parsePut(){this.expect("put");const t=this.parseExpression();let e="into";if(this.match("into","before","after","at")&&(e=this.advance().value,"at"===e)){const t=this.advance().value;this.expect("of"),e=`at ${t} of`}return{type:"command",name:"put",args:[t],target:this.parseExpression(),modifier:e}}parseInsertion(t){this.expect(t);const e=this.parseExpression();let s;return this.match("to")&&(this.advance(),s=this.parseExpression()),{type:"command",name:t,args:[e],target:s}}parseSet(){this.expect("set");const t=this.parseExpression();return this.match("to")?(this.advance(),{type:"command",name:"set",args:[t,this.parseExpression()]}):{type:"command",name:"set",args:[t]}}parseGet(){return this.expect("get"),{type:"command",name:"get",args:[this.parseExpression()]}}parseCall(){return this.expect("call"),{type:"command",name:"call",args:[this.parseExpression()]}}parseLog(){this.expect("log");const t=[];for(;!this.isAtEnd()&&!this.match("then","and","end","else")&&(t.push(this.parseExpression()),this.match(","));)this.advance();return{type:"command",name:"log",args:t}}parseSend(t){this.advance();const e=this.advance();let s,i=e.value,r=e.pos+e.value.length;for(;!this.isAtEnd()&&"localVar"===this.peek().type&&this.peek().pos===r;){const t=this.advance();i+=t.value,r=t.pos+t.value.length}return this.match(t)&&(this.advance(),s=this.parseExpression()),{type:"command",name:"send",args:[{type:"literal",value:i}],target:s}}parseWait(){if(this.expect("wait"),this.match("for")){this.advance();const t=this.advance().value;let e;return this.match("from")&&(this.advance(),e=this.parseExpression()),{type:"command",name:"waitFor",args:[{type:"literal",value:t}],target:e}}return{type:"command",name:"wait",args:[this.parseExpression()]}}parseShow(){let t;this.expect("show");const e={};return this.isAtEnd()||this.match("then","and","end","else","when","where")||(t=this.parseExpression()),!this.isAtEnd()&&this.match("when","where")&&(e[this.advance().value]=this.parseExpression()),{type:"command",name:"show",args:[],target:t,modifiers:e}}parseHide(){let t;this.expect("hide");const e={};return this.isAtEnd()||this.match("then","and","end","else","when","where")||(t=this.parseExpression()),!this.isAtEnd()&&this.match("when","where")&&(e[this.advance().value]=this.parseExpression()),{type:"command",name:"hide",args:[],target:t,modifiers:e}}parseTake(){this.expect("take");const t=this.parseExpression();let e;return this.match("from")&&(this.advance(),e=this.parseExpression()),{type:"command",name:"take",args:[t],target:e}}parseIncDec(t){this.advance();const e=this.parseExpression();let s={type:"literal",value:1};return this.match("by")&&(this.advance(),s=this.parseExpression()),{type:"command",name:t,args:[e,s]}}parseFocusBlur(t){let e;return this.advance(),this.isAtEnd()||this.match("then","and","end","else")||(e=this.parseExpression()),{type:"command",name:t,args:[],target:e}}parseGo(){return this.expect("go"),this.match("to")&&this.advance(),this.match("url")&&this.advance(),{type:"command",name:"go",args:[this.parseExpression()]}}parseReturn(){let t;return this.expect("return"),this.isAtEnd()||this.match("then","and","end","else")||(t=this.parseExpression()),{type:"command",name:"return",args:t?[t]:[]}}parseEmpty(){let t;return this.expect("empty"),this.isAtEnd()||this.match("then","and","end","else")||(t=this.parseExpression()),{type:"command",name:"empty",args:[],target:t}}parseCopy(){return this.expect("copy"),{type:"command",name:"copy",args:[this.parseExpression()]}}parseBeep(){this.advance(),this.match("!")&&this.advance();const t=[];for(;!this.isAtEnd()&&!this.match("then","and","end","else")&&(t.push(this.parseExpression()),this.match(","));)this.advance();return{type:"command",name:"beep",args:t}}parseUrlCommand(t){this.advance(),this.match("url")&&this.advance();const e=this.parseExpression(),s={};return this.match("with")&&(this.advance(),this.match("title")&&(this.advance(),s.title=this.parseExpression())),{type:"command",name:t,args:[e],modifiers:s}}parseMorph(){let t;this.expect("morph"),this.match("over")&&(this.advance(),t="over");const e=this.parseExpression();return this.match("with","to","into")&&this.advance(),{type:"command",name:"morph",args:[this.parseExpression()],target:e,modifier:t}}parseJs(){if(this.advance(),this.match("(")){for(;!this.isAtEnd()&&!this.match(")");)this.advance();this.match(")")&&this.advance()}const t=this.peek().pos;for(;!this.isAtEnd()&&!this.match("end");)this.advance();const e=this.peek().pos;return this.match("end")&&this.advance(),{type:"command",name:"js",args:[{type:"literal",value:this.source.slice(t,e).trim()}]}}parseThrow(){let t;return this.expect("throw"),this.isAtEnd()||this.match("then","and","end","else")||(t=this.parseExpression()),{type:"command",name:"throw",args:t?[t]:[]}}parseBare(t){return this.advance(),{type:"command",name:t,args:[]}}parseHalt(){return this.expect("halt"),this.match("the")&&this.advance(),this.match("event","default")&&this.advance(),{type:"command",name:"halt",args:[]}}parseTransition(){let t;if(this.expect("transition"),this.match("my","its"))t={type:"identifier",value:"my"===this.advance().value?"me":"it"};else if(this.matchType("selector")){const e=this.parseExpression();if("possessive"===e.type)return this.parseTransitionRest(e.object,e.property);t=e}const e=this.peek();let s;return s="styleProperty"===e.type||"identifier"===e.type||"keyword"===e.type?this.advance().value:"opacity",this.parseTransitionRest(t,s)}parseTransitionRest(t,e){let s={type:"literal",value:1};this.match("to")&&(this.advance(),s=this.parseExpression());let i={type:"literal",value:300};return this.match("over")&&(this.advance(),i=this.parseExpression()),{type:"command",name:"transition",args:[{type:"literal",value:e},s,i],target:t}}parseExpression(){return this.parseOr()}parseOr(){let t=this.parseAnd();for(;this.match("or","||");)this.advance(),t={type:"binary",operator:"or",left:t,right:this.parseAnd()};return t}parseAnd(){let t=this.parseEquality();for(;this.match("and","&&")&&!this.isCommandKeyword(this.peek(1));)this.advance(),t={type:"binary",operator:"and",left:t,right:this.parseEquality()};return t}isCommandKeyword(t){return["toggle","add","remove","set","put","log","send","wait","show","hide","increment","decrement","focus","blur","go"].includes(r(t.value))}parseEquality(){let t=this.parseComparison();for(;this.match("==","!=","is","matches","contains","includes","has");){const e=this.advance().value;"is"===e.toLowerCase()&&this.match("not")?(this.advance(),t={type:"binary",operator:"is not",left:t,right:this.parseComparison()}):t={type:"binary",operator:e,left:t,right:this.parseComparison()}}return t}parseComparison(){let t=this.parseAdditive();for(;this.match("<",">","<=",">=");)t={type:"binary",operator:this.advance().value,left:t,right:this.parseAdditive()};return t}parseAdditive(){let t=this.parseMultiplicative();for(;this.match("+","-");)t={type:"binary",operator:this.advance().value,left:t,right:this.parseMultiplicative()};return t}parseMultiplicative(){let t=this.parseUnary();for(;this.match("*","/","%");)t={type:"binary",operator:this.advance().value,left:t,right:this.parseUnary()};return t}parseUnary(){if(this.match("not","!"))return this.advance(),{type:"unary",operator:"not",operand:this.parseUnary()};if(this.match("-")&&"number"===this.peek(1).type){this.advance();const t=this.advance();return{type:"literal",value:-parseFloat(t.value)}}return this.parsePostfix()}parsePostfix(){let t=this.parsePrimary();for(;;)if(this.match("'s"))this.advance(),this.peek(),t={type:"possessive",object:t,property:this.advance().value};else if("styleProperty"===this.peek().type)t={type:"possessive",object:t,property:this.advance().value};else if("."===this.peek().value)this.advance(),t={type:"member",object:t,property:this.advance().value};else if("selector"===this.peek().type&&this.peek().value.startsWith("."))t={type:"member",object:t,property:this.advance().value.slice(1)};else if("("===this.peek().value){this.advance();const e=[];for(;!this.match(")");)e.push(this.parseExpression()),this.match(",")&&this.advance();this.expect(")"),t={type:"call",callee:t,args:e}}else{if("["!==this.peek().value||"selector"===t.type)break;{this.advance();const e=this.parseExpression();this.expect("]"),t={type:"member",object:t,property:e,computed:1}}}return t}parsePrimary(){const t=this.peek();if("("===t.value){this.advance();const t=this.parseExpression();return this.expect(")"),t}if("{"===t.value)return this.parseObjectLiteral();if("["===t.value)return this.parseArrayLiteral();if("number"===t.type){this.advance();const e=t.value;return e.endsWith("ms")?{type:"literal",value:parseInt(e),unit:"ms"}:e.endsWith("s")?{type:"literal",value:1e3*parseFloat(e),unit:"ms"}:{type:"literal",value:parseFloat(e)}}if("string"===t.type)return this.advance(),{type:"literal",value:t.value.slice(1,-1)};if(this.match("true"))return this.advance(),{type:"literal",value:1};if(this.match("false"))return this.advance(),{type:"literal",value:0};if(this.match("null"))return this.advance(),{type:"literal",value:null};if(this.match("undefined"))return this.advance(),{type:"literal",value:void 0};if("localVar"===t.type)return this.advance(),{type:"variable",name:t.value,scope:"local"};if("globalVar"===t.type)return this.advance(),{type:"variable",name:t.value,scope:"global"};if("selector"===t.type)return this.advance(),{type:"selector",value:t.value};if(this.match("my")){this.advance();const t=this.peek();return"identifier"!==t.type&&"keyword"!==t.type||this.isCommandKeyword(t)?{type:"identifier",value:"me"}:{type:"possessive",object:{type:"identifier",value:"me"},property:this.advance().value}}if(this.match("its")){this.advance();const t=this.peek();return"identifier"!==t.type&&"keyword"!==t.type||this.isCommandKeyword(t)?{type:"identifier",value:"it"}:{type:"possessive",object:{type:"identifier",value:"it"},property:this.advance().value}}return this.match("me")?(this.advance(),{type:"identifier",value:"me"}):this.match("it")?(this.advance(),{type:"identifier",value:"it"}):this.match("you")?(this.advance(),{type:"identifier",value:"you"}):this.match("the","a","an")?(this.advance(),this.match("first","last","next","previous","closest","parent")?{type:"positional",position:this.advance().value,target:this.parsePositionalTarget()}:this.parsePrimary()):this.match("first","last","next","previous","closest","parent")?{type:"positional",position:this.advance().value,target:this.parsePositionalTarget()}:this.match("values")?(this.advance(),this.match("of")?(this.advance(),{type:"valuesOf",target:this.parseExpression()}):{type:"identifier",value:t.value}):(this.advance(),{type:"identifier",value:t.value})}parseObjectLiteral(){this.expect("{");const t=[];for(;!this.match("}");){const e=this.advance().value;this.expect(":");const s=this.parseExpression();t.push({key:e,value:s}),this.match(",")&&this.advance()}return this.expect("}"),{type:"object",properties:t}}parseArrayLiteral(){this.expect("[");const t=[];for(;!this.match("]");)t.push(this.parseExpression()),this.match(",")&&this.advance();return this.expect("]"),{type:"array",elements:t}}parsePositionalTarget(){const t=this.peek();return"selector"===t.type?{type:"selector",value:this.advance().value}:"identifier"===t.type||"keyword"===t.type?{type:"identifier",value:this.advance().value}:this.parseExpression()}}var a="moveBefore"in Element.prototype,h=[0,1,0,0,0,0,0,0,0,1,0,1,0],c=new Set,l=new Set,u=new Set,f=new Set,p=new Set,d=new Set;function m(t,e,s={}){"string"==typeof e&&(e=v(e).childNodes),!s.preserveChanges&&x(t)&&w(t),new b(s).morph(t,e)}function y(t,e,s={}){if("string"==typeof e){const t=v(e);if(!t.firstChild||1!==t.childNodes.length||1!==t.firstChild.nodeType)throw Error("[Morphlex] The string was not a valid HTML element.");e=t.firstChild}if(1!==t.nodeType||1!==e.nodeType||t.localName!==e.localName)throw Error("[Morphlex] You can only do an inner morph with matching elements.");x(t)&&w(t),new b(s).visitChildNodes(t,e)}function w(t){for(const e of t.querySelectorAll("input"))(e.name&&e.value!==e.defaultValue||e.checked!==e.defaultChecked)&&e.setAttribute("morphlex-dirty","");for(const e of t.querySelectorAll("option"))e.value&&e.selected!==e.defaultSelected&&e.setAttribute("morphlex-dirty","");for(const e of t.querySelectorAll("textarea"))e.value!==e.defaultValue&&e.setAttribute("morphlex-dirty","")}function v(t){const e=document.createElement("template");return e.innerHTML=t.trim(),e.content}function g(t,e,s){if(e!==s){if(e.parentNode===t){if(e.nextSibling===s)return;if(a)return void t.moveBefore(e,s)}t.insertBefore(e,s)}}class b{#t=new WeakMap;#e=new WeakMap;#s;constructor(t={}){this.#s=t}morph(t,e){x(t)&&this.#i(t),e instanceof NodeList?(this.#r(e),this.#n(t,e)):x(e)&&(this.#o(e),this.#a(t,e))}#n(t,e){const s=e.length;if(0===s)this.#h(t);else if(1===s)this.#a(t,e[0]);else if(s>1){const s=[...e];this.#a(t,s.shift());const i=t.nextSibling,r=t.parentNode||document;for(let t=0;s.length>t;t++){const e=s[t];(this.#s.beforeNodeAdded?.(r,e,i)??1)&&(r.insertBefore(e,i),this.#s.afterNodeAdded?.(e))}}}#a(t,e){t!==e&&(t.isEqualNode(e)||(1===t.nodeType&&1===e.nodeType?t.localName===e.localName?this.#c(t,e):this.#l(t,e):this.#u(t,e)))}#c(t,e){(this.#s.beforeNodeVisited?.(t,e)??1)&&((t.hasAttributes()||e.hasAttributes())&&this.#f(t,e),"textarea"===t.localName&&"textarea"===e.localName?this.#p(t,e):(t.hasChildNodes()||e.hasChildNodes())&&this.visitChildNodes(t,e),this.#s.afterNodeVisited?.(t,e))}#l(t,e){(this.#s.beforeNodeVisited?.(t,e)??1)&&(this.#d(t,e),this.#s.afterNodeVisited?.(t,e))}#u(t,e){(this.#s.beforeNodeVisited?.(t,e)??1)&&(t.nodeType===e.nodeType&&null!==t.nodeValue&&null!==e.nodeValue?t.nodeValue=e.nodeValue:this.#d(t,e),this.#s.afterNodeVisited?.(t,e))}#f(t,e){t.hasAttribute("morphlex-dirty")&&t.removeAttribute("morphlex-dirty");for(const{name:s,value:i}of e.attributes){"value"===s&&k(t)&&t.value!==i&&(this.#s.preserveChanges&&t.value!==t.defaultValue||(t.value=i)),"selected"===s&&E(t)&&!t.selected&&(this.#s.preserveChanges&&t.selected!==t.defaultSelected||(t.selected=1)),"checked"===s&&k(t)&&!t.checked&&(this.#s.preserveChanges&&t.checked!==t.defaultChecked||(t.checked=1));const e=t.getAttribute(s);e!==i&&(this.#s.beforeAttributeUpdated?.(t,s,i)??1)&&(t.setAttribute(s,i),this.#s.afterAttributeUpdated?.(t,s,e))}for(const{name:s,value:i}of t.attributes)e.hasAttribute(s)||("selected"===s&&E(t)&&t.selected&&(this.#s.preserveChanges&&t.selected!==t.defaultSelected||(t.selected=0)),"checked"===s&&k(t)&&t.checked&&(this.#s.preserveChanges&&t.checked!==t.defaultChecked||(t.checked=0)),(this.#s.beforeAttributeUpdated?.(t,s,null)??1)&&(t.removeAttribute(s),this.#s.afterAttributeUpdated?.(t,s,i)))}#p(t,e){const s=e.textContent||"",i=t.value!==t.defaultValue;t.textContent!==s&&(t.textContent=s),this.#s.preserveChanges&&i||(t.value=t.defaultValue)}visitChildNodes(t,e){if(!(this.#s.beforeChildrenVisited?.(t)??1))return;const s=t,i=[...t.childNodes],r=[...e.childNodes];c.clear(),l.clear(),u.clear(),f.clear(),p.clear(),d.clear();const n=[],o=[],a=[],h=[],m=[],y=[];for(let t=0;i.length>t;t++){const e=i[t],s=e.nodeType;h[t]=s,1===s?(y[t]=e.localName,""!==e.id?u.add(t):l.add(t)):3===s&&""===e.textContent?.trim()?d.add(t):c.add(t)}for(let t=0;r.length>t;t++){const e=r[t],s=e.nodeType;if(a[t]=s,1===s)m[t]=e.localName,p.add(t);else{if(3===s&&""===e.textContent?.trim())continue;f.add(t)}}for(const t of p){const e=m[t],s=r[t];for(const r of l)if(e===y[r]&&i[r].isEqualNode(s)){n[t]=r,o[t]=0,l.delete(r),p.delete(t);break}}for(const t of p){const e=r[t],s=e.id,a=this.#t.get(e);if(""!==s||a)t:for(const e of u){const r=i[e];if(m[t]===y[e]){if(""!==s&&s===r.id){n[t]=e,o[t]=1,u.delete(e),p.delete(t);break t}if(a){const s=this.#e.get(r);if(s)for(let i=0;a.length>i;i++)if(s.has(a[i])){n[t]=e,o[t]=1,u.delete(e),p.delete(t);break t}}}}}for(const t of p){const e=r[t],s=e.getAttribute("name"),a=e.getAttribute("href"),h=e.getAttribute("src");for(const e of l){const r=i[e];if(m[t]===y[e]&&(s&&s===r.getAttribute("name")||a&&a===r.getAttribute("href")||h&&h===r.getAttribute("src"))){n[t]=e,o[t]=1,l.delete(e),p.delete(t);break}}}for(const t of p){const e=r[t],s=m[t];for(const r of l)if(s===y[r]){if("input"===s&&i[r].type!==e.type)continue;n[t]=r,o[t]=1,l.delete(r),p.delete(t);break}}for(const t of f){const e=r[t];for(const s of c)if(i[s].isEqualNode(e)){n[t]=s,o[t]=0,c.delete(s),f.delete(t);break}}for(const t of f){const e=a[t];for(const s of c)if(e===h[s]){n[t]=s,o[t]=2,c.delete(s),f.delete(t);break}}for(const t of c)this.#h(i[t]);for(const t of d)this.#h(i[t]);for(const t of l)this.#h(i[t]);for(const t of u)this.#h(i[t]);const w=function(t){const e=t.length;if(0===e)return[];const s=[],i=[],r=Array(e);for(let n=0;e>n;n++){const e=t[n];if(void 0===e)continue;let o=0,a=s.length;for(;a>o;){const t=Math.floor((o+a)/2);e>s[t]?o=t+1:a=t}r[n]=o>0?i[o-1]:-1,o===s.length?(s.push(e),i.push(n)):(s[o]=e,i[o]=n)}const n=[];if(0===i.length)return n;let o=i[i.length-1];for(;void 0!==o&&-1!==o;)n.unshift(o),o=r[o];return n}(n),v=Array(i.length);for(let t=0;w.length>t;t++)v[n[w[t]]]=1;let b=s.firstChild;for(let t=0;r.length>t;t++){const e=r[t],a=n[t];if(void 0!==a){const r=i[a],n=o[t];v[a]||g(s,r,b),0===n||(1===n?this.#c(r,e):this.#a(r,e)),b=r.nextSibling}else(this.#s.beforeNodeAdded?.(s,e,b)??1)&&(s.insertBefore(e,b),this.#s.afterNodeAdded?.(e),b=e.nextSibling)}this.#s.afterChildrenVisited?.(t)}#d(t,e){const s=t.parentNode||document,i=t;(this.#s.beforeNodeRemoved?.(t)??1)&&(this.#s.beforeNodeAdded?.(s,e,i)??1)&&(s.insertBefore(e,i),this.#s.afterNodeAdded?.(e),t.remove(),this.#s.afterNodeRemoved?.(t))}#h(t){(this.#s.beforeNodeRemoved?.(t)??1)&&(t.remove(),this.#s.afterNodeRemoved?.(t))}#r(t){for(const e of t)x(e)&&this.#o(e)}#o(t){const e=this.#t;for(const s of t.querySelectorAll("[id]")){const i=s.id;if(""===i)continue;let r=s;for(;r;){const s=e.get(r);if(s?s.push(i):e.set(r,[i]),r===t)break;r=r.parentElement}}}#i(t){const e=this.#e;for(const s of t.querySelectorAll("[id]")){const i=s.id;if(""===i)continue;let r=s;for(;r;){const s=e.get(r);if(s?s.add(i):e.set(r,new Set([i])),r===t)break;r=r.parentElement}}}}function k(t){return"input"===t.localName}function E(t){return"option"===t.localName}function x(t){return!!h[t.nodeType]}const A=new Map,_=new WeakMap;function M(t){let e=_.get(t);return e||(e=new Map,_.set(t,e)),e}const j=1e3;async function C(t,e){switch(t.type){case"literal":return t.value;case"identifier":return"me"===t.value||"my"===t.value?e.me:"it"===t.value?e.it:"you"===t.value?e.you:"event"===t.value?e.event:"body"===t.value?document.body:"document"===t.value?document:"window"===t.value?window:e.locals.has(t.value)?e.locals.get(t.value):t.value in e.me?e.me[t.value]:t.value in window?window[t.value]:t.value;case"variable":if("local"===t.scope)return M(e.me).get(t.name.slice(1));const s=t.name.slice(1);return A.has(s)?A.get(s):window[t.name];case"selector":const i=document.querySelectorAll(t.value);return 1===i.length?i[0]:Array.from(i);case"binary":return async function(t,e){if("has"===t.operator){const s=await C(t.left,e);return s instanceof Element&&"selector"===t.right.type&&t.right.value.startsWith(".")?s.classList.contains(t.right.value.slice(1)):0}const s=await C(t.left,e),i=await C(t.right,e);switch(t.operator){case"+":return s+i;case"-":return s-i;case"*":return s*i;case"/":return s/i;case"%":return s%i;case"==":case"is":return s==i;case"!=":case"is not":return s!=i;case"<":return i>s;case">":return s>i;case"<=":return i>=s;case">=":return s>=i;case"and":case"&&":return s&&i;case"or":case"||":return s||i;case"has":if(s instanceof Element){const t="string"==typeof i?i:i?.value;if("string"==typeof t&&t.startsWith("."))return s.classList.contains(t.slice(1))}return 0;case"contains":case"includes":return"string"==typeof s||Array.isArray(s)?s.includes(i):s instanceof Element?s.contains(i):0;case"matches":return s instanceof Element?s.matches(i):"string"==typeof s?RegExp(i).test(s):0;default:return}}(t,e);case"unary":const r=await C(t.operand,e);return"not"===t.operator?!r:r;case"possessive":case"member":const n=await C(t.object,e);if(null==n)return;const o=t.computed?await C(t.property,e):t.property;return"values"===o&&n instanceof Element?T(n):n[o];case"call":{let s,i=null;if("member"===t.callee.type||"possessive"===t.callee.type){i=await C(t.callee.object,e);const r=t.callee.computed?await C(t.callee.property,e):t.callee.property;s=i?.[r]}else s=await C(t.callee,e);const r=await Promise.all(t.args.map(t=>C(t,e)));return"function"==typeof s?s.apply(i,r):void 0}case"positional":return function(t,e){const s=t.target;let i=[],r=null;switch(("selector"===s.type||"identifier"===s.type||"htmlSelector"===s.type)&&(r=s.value),r&&(i=Array.from(document.querySelectorAll(r))),t.position){case"first":default:return i[0]||null;case"last":return i[i.length-1]||null;case"next":if(r){let t=e.me.nextElementSibling;for(;t;){if(t.matches(r))return t;t=t.nextElementSibling}return null}return e.me.nextElementSibling;case"previous":if(r){let t=e.me.previousElementSibling;for(;t;){if(t.matches(r))return t;t=t.previousElementSibling}return null}return e.me.previousElementSibling;case"closest":return r?e.me.closest(r):null;case"parent":if(r){let t=e.me.parentElement;for(;t;){if(t.matches(r))return t;t=t.parentElement}return null}return e.me.parentElement}}(t,e);case"object":const a={};for(const s of t.properties)a[s.key]=await C(s.value,e);return a;case"array":return Promise.all(t.elements.map(t=>C(t,e)));case"valuesOf":{const s=await C(t.target,e);return s instanceof Element?T(s):new FormData}default:return}}function T(t){if(t instanceof HTMLFormElement)return new FormData(t);const e=new FormData;return t.querySelectorAll("input, select, textarea").forEach(t=>{const s=t.getAttribute("name");s&&"value"in t&&e.append(s,t.value)}),e}async function F(t,e){const s=async()=>{if(!t.target)return[e.me];const s=await C(t.target,e);return Array.isArray(s)?s:s instanceof Element?[s]:"string"==typeof s?Array.from(document.querySelectorAll(s)):[e.me]},i=t=>{if(!t)return"";if("selector"===t.type)return t.value.startsWith("@")?t.value:t.value.slice(1);if("string"===t.type||"literal"===t.type){const e=t.value;return"string"==typeof e&&e.startsWith(".")?e.slice(1):e+""}return"identifier"===t.type?t.value:""},r=t=>Array.isArray(t)?t.filter(t=>t instanceof Element):t instanceof Element?[t]:"string"==typeof t?Array.from(document.querySelectorAll(t)):[],n=t=>t.startsWith("*"),o=t=>t.substring(1),a=(t,e,s)=>n(e)?(t.style.setProperty(o(e),s+""),1):0,h=(t,e)=>{if(n(e))return getComputedStyle(t).getPropertyValue(o(e))};switch(t.name){case"toggle":{const r=i(t.args[0])||await C(t.args[0],e)+"",n=await s();if(r.startsWith("@")){const t=r.slice(1);for(const e of n)e.hasAttribute(t)?e.removeAttribute(t):e.setAttribute(t,"")}else for(const t of n)t.classList.toggle(r);return e.it=1===n.length?n[0]:n,e.it}case"add":{const r=i(t.args[0])||await C(t.args[0],e)+"",n=await s();if(r.startsWith("@")){const t=r.slice(1);for(const e of n)e.setAttribute(t,"")}else for(const t of n)t.classList.add(r);return e.it=1===n.length?n[0]:n,e.it}case"remove":{const t=await s();for(const e of t)e.remove();return null}case"removeClass":{const r=i(t.args[0])||await C(t.args[0],e)+"",n=await s();if(r.startsWith("@")){const t=r.slice(1);for(const e of n)e.removeAttribute(t)}else for(const t of n)t.classList.remove(r);return n}case"show":{const t=await s();for(const e of t)e.style.display="",e.classList.remove("hidden");return t}case"hide":{const t=await s();for(const e of t)e.style.display="none";return t}case"put":{const i=await C(t.args[0],e),o=t.modifier||"into";if("possessive"===t.target?.type&&n(t.target.property)){const s=r(await C(t.target.object,e));for(const e of s)a(e,t.target.property,i);return e.it=i,i}const h=await s();for(const t of h){const e=i+"";"into"===o?t.innerHTML=e:"before"===o?t.insertAdjacentHTML("beforebegin",e):"after"===o?t.insertAdjacentHTML("afterend",e):"at start of"===o?t.insertAdjacentHTML("afterbegin",e):"at end of"===o&&t.insertAdjacentHTML("beforeend",e)}return e.it=i,i}case"append":{const i=await C(t.args[0],e),r=await s();for(const t of r)t.insertAdjacentHTML("beforeend",i+"");return e.it=i,i}case"prepend":{const i=await C(t.args[0],e),r=await s();for(const t of r)t.insertAdjacentHTML("afterbegin",i+"");return e.it=i,i}case"take":{const r=i(t.args[0]),n=t.target?await s():[e.me.parentElement];for(const t of n)t.querySelectorAll("."+r).forEach(t=>t.classList.remove(r));return e.me.classList.add(r),e.me}case"empty":{const t=await s();for(const e of t)e.innerHTML="";return t}case"set":{const s=t.args[0],i=await C(t.args[1],e);if("variable"===s.type){const t=s.name.slice(1);return("local"===s.scope?M(e.me):A).set(t,i),e.it=i,i}if("possessive"===s.type||"member"===s.type){const t=await C(s.object,e);if(t)return t instanceof Element&&n(s.property)?a(t,s.property,i):t[s.property]=i,e.it=i,i}return e.it=i,i}case"get":{const s=await C(t.args[0],e);return e.it=s,s}case"increment":{const s=t.args[0],i=t.args[1]?await C(t.args[1],e):1;if("variable"===s.type){const t=s.name.slice(1),r="local"===s.scope?M(e.me):A,n=(r.get(t)||0)+i;return r.set(t,n),e.it=n,n}if("possessive"===s.type&&n(s.property)){const t=r(await C(s.object,e));for(const r of t){const t=(parseFloat(h(r,s.property)||"0")||0)+i;a(r,s.property,t),e.it=t}return e.it}const o=r(await C(s,e));for(const t of o){const s=(parseFloat(t.textContent||"0")||0)+i;t.textContent=s+"",e.it=s}return e.it}case"decrement":{const s=t.args[0],i=t.args[1]?await C(t.args[1],e):1;if("variable"===s.type){const t=s.name.slice(1),r="local"===s.scope?M(e.me):A,n=(r.get(t)||0)-i;return r.set(t,n),e.it=n,n}if("possessive"===s.type&&n(s.property)){const t=r(await C(s.object,e));for(const r of t){const t=(parseFloat(h(r,s.property)||"0")||0)-i;a(r,s.property,t),e.it=t}return e.it}const o=r(await C(s,e));for(const t of o){const s=(parseFloat(t.textContent||"0")||0)-i;t.textContent=s+"",e.it=s}return e.it}case"wait":{const s=await C(t.args[0],e),i="number"==typeof s?s:parseInt(s+"");return await new Promise(t=>setTimeout(t,i)),i}case"waitFor":{const i=await C(t.args[0],e),r=(await s())[0]||e.me;return new Promise(t=>{r.addEventListener(i+"",s=>{e.it=s,t(s)},{once:1})})}case"transition":{const i=(await C(t.args[0],e)+"").replace(/^\*/,""),r=await C(t.args[1],e),n=await C(t.args[2],e),o="number"==typeof n?n:(n+"").endsWith("ms")?parseInt(n+""):(n+"").endsWith("s")?1e3*parseFloat(n+""):parseInt(n+"")||300,a=await s(),h=[];for(const t of a){const e=t,s=i.replace(/([A-Z])/g,"-$1").toLowerCase(),n=e.style.transition;e.style.transition=`${s} ${o}ms ease`,e.style.setProperty(s,r+""),h.push(new Promise(t=>{const i=()=>{e.style.transition=n,t()},r=t=>{t.propertyName===s&&(e.removeEventListener("transitionend",r),i())};e.addEventListener("transitionend",r),setTimeout(i,o+50)}))}return await Promise.all(h),e.it=1===a.length?a[0]:a,e.it}case"send":{const i=await C(t.args[0],e),r=await s(),n=new CustomEvent(i+"",{bubbles:1,detail:e.it});for(const t of r)t.dispatchEvent(n);return e.it=n,n}case"log":{const s=await Promise.all(t.args.map(t=>C(t,e)));return console.log(...s),s[0]}case"call":{const s=await C(t.args[0],e);return e.it=s,s}case"copy":{const s=await C(t.args[0],e);let i="";i="string"==typeof s?s:s instanceof Element?s.textContent||"":s+"";try{if(navigator.clipboard)await navigator.clipboard.writeText(i);else{const t=document.createElement("textarea");t.value=i,t.style.cssText="position:fixed;top:0;left:-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}return e.me instanceof Element&&e.me.dispatchEvent(new CustomEvent("copy:success",{bubbles:1,detail:{text:i}})),e.it=i,i}catch(t){throw e.me instanceof Element&&e.me.dispatchEvent(new CustomEvent("copy:error",{bubbles:1,detail:{error:t}})),t}}case"beep":{const s=await Promise.all(t.args.map(t=>C(t,e))),i=s.length>0?s:[e.it];for(const t of i){const e=null===t?"null":void 0===t?"undefined":Array.isArray(t)?`Array[${t.length}]`:t instanceof Element?`Element<${t.tagName.toLowerCase()}>`:typeof t;console.log("[beep]",e+":",t)}return i[0]}case"go":{const s=await C(t.args[0],e),i=(s+"").toLowerCase();return"back"===i?history.back():"forward"===i?history.forward():"bottom"===i?e.me.scrollIntoView({block:"end",behavior:"smooth"}):"top"===i?e.me.scrollIntoView({block:"start",behavior:"smooth"}):window.location.href=s+"",null}case"push":{const s=await C(t.args[0],e)+"";let i="";return t.modifiers?.title&&(i=await C(t.modifiers.title,e)+""),window.history.pushState(null,"",s),i&&(document.title=i),window.dispatchEvent(new CustomEvent("lokascript:pushurl",{detail:{url:s,title:i}})),{url:s,title:i,mode:"push"}}case"replace":{const s=await C(t.args[0],e)+"";let i="";return t.modifiers?.title&&(i=await C(t.modifiers.title,e)+""),window.history.replaceState(null,"",s),i&&(document.title=i),window.dispatchEvent(new CustomEvent("lokascript:replaceurl",{detail:{url:s,title:i}})),{url:s,title:i,mode:"replace"}}case"focus":{const t=await s();for(const e of t)e.focus();return t}case"blur":{const t=await s();for(const e of t)e.blur();return t}case"return":throw{type:"return",value:t.args[0]?await C(t.args[0],e):e.it};case"break":throw{type:"break"};case"continue":throw{type:"continue"};case"halt":{const s=t.args[0];let i=e.event;if("identifier"===s?.type&&"the"===s.name&&"event"===t.args[1]?.name)i=e.event;else if(s){const t=await C(s,e);t?.preventDefault&&(i=t)}if(i&&"function"==typeof i.preventDefault)return i.preventDefault(),i.stopPropagation(),{halted:1,eventHalted:1};const r=Error("HALT_EXECUTION");throw r.isHalt=1,r}case"exit":{const t=Error("EXIT_COMMAND");throw t.isExit=1,t}case"throw":{const s=t.args[0]?await C(t.args[0],e):"Error";throw s instanceof Error?s:Error(s+"")}case"js":{const s=t.args[0];let i="";i="string"===s.type?s.value:"template"===s.type?await C(s,e):await C(s,e)+"";const r={me:e.me,it:e.it,event:e.event,target:e.me,locals:Object.fromEntries(e.locals),globals:Object.fromEntries(A),document:"undefined"!=typeof document?document:void 0,window:"undefined"!=typeof window?window:void 0};try{const t=Function("ctx",`with(ctx) { return (async () => { ${i} })(); }`),s=await t(r);return e.it=s,s}catch(t){throw console.error("[js] Execution error:",t),t}}case"morph":{const i=await s(),r=await C(t.args[0],e)+"",n="over"===t.modifier;for(const t of i)try{if(n)m(t,r);else{const e=document.createElement(t.tagName);e.innerHTML=r,y(t,e)}}catch(e){console.warn("[LokaScript] Morph failed, falling back:",e),n?t.outerHTML=r:t.innerHTML=r}return e.it=1===i.length?i[0]:i,e.it}default:return console.error(`[hyperfixi] Unknown command "${t.name}" \u2014 not in this bundle. Use hyperfixi.js (full bundle).`),null}}async function I(t,e){try{return await P(t,e)}catch(t){if("return"===t?.type)throw t;throw t}}async function O(t,e){switch(t.type){case"if":return await C(t.condition,e)?I(t.body,e):t.elseBody?I(t.elseBody,e):null;case"repeat":{const s=await C(t.condition,e),i="number"==typeof s?s:parseInt(s+"");for(let s=0;i>s&&j>s;s++){e.locals.set("__loop_index__",s),e.locals.set("__loop_count__",s+1);try{await I(t.body,e)}catch(t){if("break"===t?.type)break;if("continue"===t?.type)continue;throw t}}return null}case"for":{const{variable:s,iterable:i}=t.condition,r=await C(i,e),n=Array.isArray(r)?r:r instanceof NodeList?Array.from(r):[r],o=s.startsWith(":")?s.slice(1):s;for(let s=0;n.length>s&&j>s;s++){e.locals.set(o,n[s]),e.locals.set("__loop_index__",s),e.locals.set("__loop_count__",s+1);try{await I(t.body,e)}catch(t){if("break"===t?.type)break;if("continue"===t?.type)continue;throw t}}return null}case"while":{let s=0;for(;await C(t.condition,e)&&j>s;){e.locals.set("__loop_index__",s);try{await I(t.body,e)}catch(t){if("break"===t?.type)break;if("continue"===t?.type){s++;continue}throw t}s++}return null}case"fetch":{const{url:s,responseType:i,options:r,method:n}=t.condition;try{const o=await C(s,e),a={};if(n){const t=await C(n,e);a.method=(t+"").toUpperCase()}if(r){const t=await C(r,e);t instanceof FormData?a.body=t:!t||"object"!=typeof t||t instanceof Element||Object.assign(a,t)}const h=await fetch(o+"",a);if(!h.ok)throw Error("HTTP "+h.status);const c=await C(i,e);let l;if("json"===c)l=await h.json();else if("html"===c){const t=await h.text();l=(new DOMParser).parseFromString(t,"text/html").body.innerHTML}else l=await h.text();e.it=l,e.locals.set("it",l),e.locals.set("result",l),e.locals.set("response",h),await I(t.body,e)}catch(t){if("return"===t?.type)throw t;e.locals.set("error",t),console.error("Fetch error:",t)}return null}default:return null}}async function P(t,e){let s;for(const i of t)"command"===i.type?s=await F(i,e):["if","repeat","for","while","fetch"].includes(i.type)&&(s=await O(i,e));return s}async function S(t,e,s){const i={me:e,event:s,locals:new Map,globals:A};if("sequence"===t.type)try{return await P(t.commands,i)}catch(t){if("return"===t?.type)return t.value;throw t}if("event"===t.type){const s=t,r=s.event;if(r.startsWith("interval:")){const t=r.split(":")[1],i=t.endsWith("ms")?parseInt(t):t.endsWith("s")?1e3*parseFloat(t):parseInt(t);return void setInterval(async()=>{const t={me:e,locals:new Map,globals:A};try{await P(s.body,t)}catch(t){if("return"!==t?.type)throw t}},i)}if("init"===r){try{await P(s.body,i)}catch(t){if("return"!==t?.type)throw t}return}const n=s.filter?await C(s.filter,i):e,o=n instanceof Element?n:e,a=s.modifiers;let h=async t=>{a.prevent&&t.preventDefault(),a.stop&&t.stopPropagation();const i={me:e,event:t,you:t.target instanceof Element?t.target:void 0,locals:new Map,globals:A};try{await P(s.body,i)}catch(t){if("return"===t?.type)return t.value;throw t}};if(a.debounce){let t;const e=h;h=async s=>{clearTimeout(t),t=setTimeout(()=>e(s),a.debounce)}}if(a.throttle){let t=0;const e=h;h=async s=>{const i=Date.now();a.throttle>i-t||(t=i,await e(s))}}return void o.addEventListener(r,h,{once:!!a.once})}return null}const $=t=>new o(t).parse(),H=(L=$,N=S,(t=document)=>{t.querySelectorAll("[_]").forEach(t=>{const e=t.getAttribute("_");if(e)try{N(L(e),t)}catch(t){console.error("HyperFixi Hybrid Complete error:",t,"Code:",e)}})});var L,N;!function(t,e,s="hyperfixi"){"undefined"!=typeof window&&(window[s]=t,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>e()):e())}({version:"1.0.0-hybrid-complete",parse:$,execute:async(t,e)=>S($(t),e||document.body),init:H,process:H,addAliases:function(t){Object.assign(s,t)},addEventAliases:function(t){Object.assign(i,t)},tokenize:e,evaluate:C,commands:["toggle","add","remove","removeClass","show","hide","put","append","prepend","take","empty","set","get","increment","decrement","wait","transition","send","trigger","log","call","copy","beep","go","push","push-url","replace","replace-url","focus","blur","return","break","continue","halt","exit","throw","js","morph"],blocks:["if","else","unless","repeat","for","while","fetch"]},H)}();
|
|
1
|
+
!function(){"use strict";const t=new Set(["on","from","to","into","before","after","in","of","at","with","if","else","unless","end","then","and","or","not","repeat","times","for","each","while","until","toggle","add","remove","put","set","get","call","return","append","prepend","log","send","trigger","wait","settle","fetch","as","show","hide","take","increment","decrement","focus","blur","go","transition","over","the","a","an","my","its","me","it","you","first","last","next","previous","closest","parent","true","false","null","undefined","is","matches","contains","includes","exists","has","init","every","by","halt","via","values","default","event"]);function e(e){const s=[];let i=0;for(;e.length>i;){if(/\s/.test(e[i])){i++;continue}if("--"===e.slice(i,i+2)){for(;e.length>i&&"\n"!==e[i];)i++;continue}const r=i;if("<"===e[i]&&/[a-zA-Z]/.test(e[i+1]||"")){for(i++;e.length>i&&">"!==e[i];)i++;">"===e[i]&&i++;const t=e.slice(r,i);if(t.endsWith("/>")||t.endsWith(">")){const e=t.slice(1).replace(/\/?>$/,"");s.push({type:"selector",value:e,pos:r});continue}}if("'s"===e.slice(i,i+2)&&!/[a-zA-Z]/.test(e[i+2]||"")){s.push({type:"operator",value:"'s",pos:r}),i+=2;continue}if('"'===e[i]||"'"===e[i]){const t=e[i++];for(;e.length>i&&e[i]!==t;)"\\"===e[i]&&i++,i++;i++,s.push({type:"string",value:e.slice(r,i),pos:r});continue}if(/\d/.test(e[i])||"-"===e[i]&&/\d/.test(e[i+1]||"")){for("-"===e[i]&&i++;e.length>i&&/[\d.]/.test(e[i]);)i++;"ms"===e.slice(i,i+2)?i+=2:"s"!==e[i]||/[a-zA-Z]/.test(e[i+1]||"")?"px"===e.slice(i,i+2)&&(i+=2):i++,s.push({type:"number",value:e.slice(r,i),pos:r});continue}if(":"===e[i]){for(i++;e.length>i&&/[\w]/.test(e[i]);)i++;s.push({type:"localVar",value:e.slice(r,i),pos:r});continue}if("$"===e[i]){for(i++;e.length>i&&/[\w]/.test(e[i]);)i++;s.push({type:"globalVar",value:e.slice(r,i),pos:r});continue}if("@"===e[i]){for(i++;e.length>i&&/[\w-]/.test(e[i]);)i++;s.push({type:"selector",value:e.slice(r,i),pos:r});continue}if("#"===e[i]||"."===e[i]){if("."===e[i]&&e.slice(i+1).match(/^(once|prevent|stop|debounce|throttle)\b/i)){s.push({type:"symbol",value:".",pos:r}),i++;continue}for(i++;e.length>i&&/[\w-]/.test(e[i]);)i++;s.push({type:"selector",value:e.slice(r,i),pos:r});continue}if("["===e[i]){let t=i+1;for(;e.length>t&&/\s/.test(e[t]);)t++;const n=e[t]||"";if(/['"\d\[\]:\$\-]/.test(n)||""===n){s.push({type:"symbol",value:"[",pos:r}),i++;continue}{i++;let t=1;for(;e.length>i&&t>0;)"["===e[i]&&t++,"]"===e[i]&&t--,i++;s.push({type:"selector",value:e.slice(r,i),pos:r});continue}}if("]"===e[i]){s.push({type:"symbol",value:"]",pos:r}),i++;continue}if("'s"===e.slice(i,i+2)){s.push({type:"operator",value:"'s",pos:r}),i+=2;continue}const n=e.slice(i,i+2);if(["==","!=","<=",">=","&&","||"].includes(n))s.push({type:"operator",value:n,pos:r}),i+=2;else if("*"===e[i]&&/[a-zA-Z]/.test(e[i+1]||"")){for(i++;e.length>i&&/[\w-]/.test(e[i]);)i++;s.push({type:"styleProperty",value:e.slice(r,i),pos:r})}else if("+-*/%<>!".includes(e[i]))s.push({type:"operator",value:e[i],pos:r}),i++;else if("()[]{},.".includes(e[i]))s.push({type:"symbol",value:e[i],pos:r}),i++;else{if(/[a-zA-Z_]/.test(e[i])){for(;e.length>i&&/[\w-]/.test(e[i]);)i++;const n=e.slice(r,i),o=t.has(n.toLowerCase())?"keyword":"identifier";s.push({type:o,value:n,pos:r});continue}i++}}return s.push({type:"eof",value:"",pos:e.length}),s}const s={flip:"toggle",switch:"toggle",display:"show",reveal:"show",conceal:"hide",increase:"increment",decrease:"decrement",fire:"trigger",dispatch:"send",navigate:"go",goto:"go"},i={clicked:"click",pressed:"keydown",changed:"change",submitted:"submit",loaded:"load"};function r(t){const e=t.toLowerCase();return s[e]||e}function n(t){const e=t.toLowerCase();return i[e]||e}class o{constructor(t){this.pos=0,this.cmdMap={toggle:()=>this.parseToggle(),add:()=>this.parseAdd(),remove:()=>this.parseRemove(),put:()=>this.parsePut(),append:()=>this.parseInsertion("append"),prepend:()=>this.parseInsertion("prepend"),set:()=>this.parseSet(),get:()=>this.parseGet(),call:()=>this.parseCall(),log:()=>this.parseLog(),send:()=>this.parseSend("to"),trigger:()=>this.parseSend("on"),wait:()=>this.parseWait(),show:()=>this.parseShow(),hide:()=>this.parseHide(),take:()=>this.parseTake(),empty:()=>this.parseEmpty(),increment:()=>this.parseIncDec("increment"),decrement:()=>this.parseIncDec("decrement"),focus:()=>this.parseFocusBlur("focus"),blur:()=>this.parseFocusBlur("blur"),go:()=>this.parseGo(),return:()=>this.parseReturn(),transition:()=>this.parseTransition(),halt:()=>this.parseHalt(),copy:()=>this.parseCopy(),beep:()=>this.parseBeep(),push:()=>this.parseUrlCommand("push"),replace:()=>this.parseUrlCommand("replace"),morph:()=>this.parseMorph(),js:()=>this.parseJs(),throw:()=>this.parseThrow(),break:()=>this.parseBare("break"),continue:()=>this.parseBare("continue"),exit:()=>this.parseBare("exit")},this.source=t,this.tokens=e(t)}peek(t=0){return this.tokens[Math.min(this.pos+t,this.tokens.length-1)]}advance(){return this.tokens[this.pos++]}match(...t){const e=this.peek();return t.some(t=>e.value.toLowerCase()===t.toLowerCase())}matchType(...t){return t.includes(this.peek().type)}expect(t){if(!this.match(t)&&r(this.peek().value)!==t)throw Error(`Expected '${t}', got '${this.peek().value}'`);return this.advance()}isAtEnd(){return"eof"===this.peek().type}parse(){return this.match("on")?this.parseEventHandler():this.match("init")?(this.advance(),{type:"event",event:"init",modifiers:{},body:this.parseCommandSequence()}):this.match("every")?this.parseEveryHandler():{type:"sequence",commands:this.parseCommandSequence()}}parseEventHandler(){this.expect("on");const t=this.advance().value,e={};let s;for(;"."===this.peek().value;){this.advance();const t=this.advance().value.toLowerCase();if("once"===t)e.once=1;else if("prevent"===t)e.prevent=1;else if("stop"===t)e.stop=1;else if(("debounce"===t||"throttle"===t)&&"("===this.peek().value){this.advance();const s=this.advance().value;this.expect(")"),"debounce"===t?e.debounce=parseInt(s)||100:e.throttle=parseInt(s)||100}}return this.match("from")&&(this.advance(),s=this.parseExpression()),{type:"event",event:n(t),filter:s,modifiers:e,body:this.parseCommandSequence()}}parseEveryHandler(){return this.expect("every"),{type:"event",event:"interval:"+this.advance().value,modifiers:{},body:this.parseCommandSequence()}}parseCommandSequence(){const t=[];for(;!this.isAtEnd()&&!this.match("end","else");){const e=this.parseCommand();e&&t.push(e),this.match("then","and")&&this.advance()}return t}parseCommand(){if(this.match("if","unless"))return this.parseIf();if(this.match("repeat"))return this.parseRepeat();if(this.match("for"))return this.parseFor();if(this.match("while"))return this.parseWhile();if(this.match("fetch"))return this.parseFetchBlock();const t=r(this.peek().value);if(this.cmdMap[t])return this.cmdMap[t]();if(this.match("catch","finally"))throw Error(`'${this.peek().value}' needs the full parser (use hyperfixi.js)`);const e=this.peek();if(!(this.isAtEnd()||"identifier"!==e.type&&"keyword"!==e.type||this.match("then","and","end","else")))throw Error(`'${e.value}' needs the full parser (use hyperfixi.js)`);return this.isAtEnd()||this.match("then","and","end","else")||this.advance(),null}parseIf(){const t=this.match("unless");this.advance();const e=this.parseExpression(),s=this.parseCommandSequence();let i;return this.match("else")&&(this.advance(),i=this.parseCommandSequence()),this.match("end")&&this.advance(),{type:"if",condition:t?{type:"unary",operator:"not",operand:e}:e,body:s,elseBody:i}}parseRepeat(){let t;this.expect("repeat"),this.match("until","while","forever")||(t=this.parseExpression(),this.match("times")&&this.advance());const e=this.parseCommandSequence();return this.match("end")&&this.advance(),{type:"repeat",condition:t,body:e}}parseFor(){this.expect("for"),this.match("each")&&this.advance();const t=this.advance().value;this.expect("in");const e=this.parseExpression(),s=this.parseCommandSequence();return this.match("end")&&this.advance(),{type:"for",condition:{type:"forCondition",variable:t,iterable:e},body:s}}parseWhile(){this.expect("while");const t=this.parseExpression(),e=this.parseCommandSequence();return this.match("end")&&this.advance(),{type:"while",condition:t,body:e}}parseNakedUrl(){const t=this.peek(),e="operator"===t.type&&"/"===t.value,s=("http"===t.value||"https"===t.value)&&"://"===this.source.slice(t.pos+t.value.length,t.pos+t.value.length+3);if(!e&&!s)return null;let i=t.pos;for(;this.source.length>i&&!/\s/.test(this.source[i]);)i++;for(;!this.isAtEnd()&&this.peek().pos<i;)this.advance();return{type:"literal",value:this.source.slice(t.pos,i)}}parseFetchBlock(){this.expect("fetch");const t=this.parseNakedUrl()??this.parseExpression();let e,s,i={type:"literal",value:"text"};this.match("{")&&(this.pos--,e=this.parseExpression());for(let t=0;3>t;t++)if(!this.match("via")||s)if(this.match("as"))this.advance(),(this.match("a")||this.match("an"))&&this.advance(),i=this.parseExpression();else{if(!this.match("with")||e)break;this.advance(),e=this.parseExpression()}else this.advance(),s=this.parseExpression();return this.match("then")&&this.advance(),{type:"fetch",condition:{type:"fetchConfig",url:t,responseType:i,options:e,method:s},body:this.parseCommandSequence()}}parseToggle(){this.expect("toggle");const t=this.parseExpression();let e;return this.match("on")&&(this.advance(),e=this.parseExpression()),{type:"command",name:"toggle",args:[t],target:e}}parseAdd(){this.expect("add");const t=this.parseExpression();let e;return this.match("to")&&(this.advance(),e=this.parseExpression()),{type:"command",name:"add",args:[t],target:e}}parseRemove(){if(this.expect("remove"),this.matchType("selector")&&/^[.@]/.test(this.peek().value)){const t=this.parseExpression();let e;return this.match("from")&&(this.advance(),e=this.parseExpression()),{type:"command",name:"removeClass",args:[t],target:e}}return{type:"command",name:"remove",args:[],target:this.parseExpression()}}parsePut(){this.expect("put");const t=this.parseExpression();let e="into";if(this.match("into","before","after","at")&&(e=this.advance().value,"at"===e)){const t=this.advance().value;this.expect("of"),e=`at ${t} of`}return{type:"command",name:"put",args:[t],target:this.parseExpression(),modifier:e}}parseInsertion(t){this.expect(t);const e=this.parseExpression();let s;return this.match("to")&&(this.advance(),s=this.parseExpression()),{type:"command",name:t,args:[e],target:s}}parseSet(){this.expect("set");const t=this.parseExpression();return this.match("to")?(this.advance(),{type:"command",name:"set",args:[t,this.parseExpression()]}):{type:"command",name:"set",args:[t]}}parseGet(){return this.expect("get"),{type:"command",name:"get",args:[this.parseExpression()]}}parseCall(){return this.expect("call"),{type:"command",name:"call",args:[this.parseExpression()]}}parseLog(){this.expect("log");const t=[];for(;!this.isAtEnd()&&!this.match("then","and","end","else")&&(t.push(this.parseExpression()),this.match(","));)this.advance();return{type:"command",name:"log",args:t}}parseSend(t){this.advance();const e=this.advance();let s,i=e.value,r=e.pos+e.value.length;for(;!this.isAtEnd()&&"localVar"===this.peek().type&&this.peek().pos===r;){const t=this.advance();i+=t.value,r=t.pos+t.value.length}return this.match(t)&&(this.advance(),s=this.parseExpression()),{type:"command",name:"send",args:[{type:"literal",value:i}],target:s}}parseWait(){if(this.expect("wait"),this.match("for")){this.advance();const t=this.advance().value;let e;return this.match("from")&&(this.advance(),e=this.parseExpression()),{type:"command",name:"waitFor",args:[{type:"literal",value:t}],target:e}}return{type:"command",name:"wait",args:[this.parseExpression()]}}parseShow(){let t;this.expect("show");const e={};return this.isAtEnd()||this.match("then","and","end","else","when","where")||(t=this.parseExpression()),!this.isAtEnd()&&this.match("when","where")&&(e[this.advance().value]=this.parseExpression()),{type:"command",name:"show",args:[],target:t,modifiers:e}}parseHide(){let t;this.expect("hide");const e={};return this.isAtEnd()||this.match("then","and","end","else","when","where")||(t=this.parseExpression()),!this.isAtEnd()&&this.match("when","where")&&(e[this.advance().value]=this.parseExpression()),{type:"command",name:"hide",args:[],target:t,modifiers:e}}parseTake(){this.expect("take");const t=this.parseExpression();let e;return this.match("from")&&(this.advance(),e=this.parseExpression()),{type:"command",name:"take",args:[t],target:e}}parseIncDec(t){this.advance();const e=this.parseExpression();let s={type:"literal",value:1};return this.match("by")&&(this.advance(),s=this.parseExpression()),{type:"command",name:t,args:[e,s]}}parseFocusBlur(t){let e;return this.advance(),this.isAtEnd()||this.match("then","and","end","else")||(e=this.parseExpression()),{type:"command",name:t,args:[],target:e}}parseGo(){return this.expect("go"),this.match("to")&&this.advance(),this.match("url")&&this.advance(),{type:"command",name:"go",args:[this.parseExpression()]}}parseReturn(){let t;return this.expect("return"),this.isAtEnd()||this.match("then","and","end","else")||(t=this.parseExpression()),{type:"command",name:"return",args:t?[t]:[]}}parseEmpty(){let t;return this.expect("empty"),this.isAtEnd()||this.match("then","and","end","else")||(t=this.parseExpression()),{type:"command",name:"empty",args:[],target:t}}parseCopy(){return this.expect("copy"),{type:"command",name:"copy",args:[this.parseExpression()]}}parseBeep(){this.advance(),this.match("!")&&this.advance();const t=[];for(;!this.isAtEnd()&&!this.match("then","and","end","else")&&(t.push(this.parseExpression()),this.match(","));)this.advance();return{type:"command",name:"beep",args:t}}parseUrlCommand(t){this.advance(),this.match("url")&&this.advance();const e=this.parseExpression(),s={};return this.match("with")&&(this.advance(),this.match("title")&&(this.advance(),s.title=this.parseExpression())),{type:"command",name:t,args:[e],modifiers:s}}parseMorph(){let t;this.expect("morph"),this.match("over")&&(this.advance(),t="over");const e=this.parseExpression();return this.match("with","to","into")&&this.advance(),{type:"command",name:"morph",args:[this.parseExpression()],target:e,modifier:t}}parseJs(){if(this.advance(),this.match("(")){for(;!this.isAtEnd()&&!this.match(")");)this.advance();this.match(")")&&this.advance()}const t=this.peek().pos;for(;!this.isAtEnd()&&!this.match("end");)this.advance();const e=this.peek().pos;return this.match("end")&&this.advance(),{type:"command",name:"js",args:[{type:"literal",value:this.source.slice(t,e).trim()}]}}parseThrow(){let t;return this.expect("throw"),this.isAtEnd()||this.match("then","and","end","else")||(t=this.parseExpression()),{type:"command",name:"throw",args:t?[t]:[]}}parseBare(t){return this.advance(),{type:"command",name:t,args:[]}}parseHalt(){return this.expect("halt"),this.match("the")&&this.advance(),this.match("event","default")&&this.advance(),{type:"command",name:"halt",args:[]}}parseTransition(){let t;if(this.expect("transition"),this.match("my","its"))t={type:"identifier",value:"my"===this.advance().value?"me":"it"};else if(this.matchType("selector")){const e=this.parseExpression();if("possessive"===e.type)return this.parseTransitionRest(e.object,e.property);t=e}const e=this.peek();let s;return s="styleProperty"===e.type||"identifier"===e.type||"keyword"===e.type?this.advance().value:"opacity",this.parseTransitionRest(t,s)}parseTransitionRest(t,e){let s={type:"literal",value:1};this.match("to")&&(this.advance(),s=this.parseExpression());let i={type:"literal",value:300};return this.match("over")&&(this.advance(),i=this.parseExpression()),{type:"command",name:"transition",args:[{type:"literal",value:e},s,i],target:t}}parseExpression(){return this.parseOr()}parseOr(){let t=this.parseAnd();for(;this.match("or","||");)this.advance(),t={type:"binary",operator:"or",left:t,right:this.parseAnd()};return t}parseAnd(){let t=this.parseEquality();for(;this.match("and","&&")&&!this.isCommandKeyword(this.peek(1));)this.advance(),t={type:"binary",operator:"and",left:t,right:this.parseEquality()};return t}isCommandKeyword(t){return["toggle","add","remove","set","put","log","send","wait","show","hide","increment","decrement","focus","blur","go"].includes(r(t.value))}parseEquality(){let t=this.parseComparison();for(;this.match("==","!=","is","matches","contains","includes","has");){const e=this.advance().value;"is"===e.toLowerCase()&&this.match("not")?(this.advance(),t={type:"binary",operator:"is not",left:t,right:this.parseComparison()}):t={type:"binary",operator:e,left:t,right:this.parseComparison()}}return t}parseComparison(){let t=this.parseAdditive();for(;this.match("<",">","<=",">=");)t={type:"binary",operator:this.advance().value,left:t,right:this.parseAdditive()};return t}parseAdditive(){let t=this.parseMultiplicative();for(;this.match("+","-");)t={type:"binary",operator:this.advance().value,left:t,right:this.parseMultiplicative()};return t}parseMultiplicative(){let t=this.parseUnary();for(;this.match("*","/","%");)t={type:"binary",operator:this.advance().value,left:t,right:this.parseUnary()};return t}parseUnary(){if(this.match("beep")&&"!"===this.peek(1).value)throw Error("'beep!' needs the full parser (use hyperfixi.js)");if(this.match("not","!"))return this.advance(),{type:"unary",operator:"not",operand:this.parseUnary()};if(this.match("-")&&"number"===this.peek(1).type){this.advance();const t=this.advance();return{type:"literal",value:-parseFloat(t.value)}}return this.parsePostfix()}parsePostfix(){let t=this.parsePrimary();for(;;)if(this.match("'s"))this.advance(),this.peek(),t={type:"possessive",object:t,property:this.advance().value};else if("styleProperty"===this.peek().type)t={type:"possessive",object:t,property:this.advance().value};else if("."===this.peek().value)this.advance(),t={type:"member",object:t,property:this.advance().value};else if("selector"===this.peek().type&&this.peek().value.startsWith("."))t={type:"member",object:t,property:this.advance().value.slice(1)};else if("("===this.peek().value){this.advance();const e=[];for(;!this.match(")");)e.push(this.parseExpression()),this.match(",")&&this.advance();this.expect(")"),t={type:"call",callee:t,args:e}}else{if("["!==this.peek().value||"selector"===t.type)break;{this.advance();const e=this.parseExpression();this.expect("]"),t={type:"member",object:t,property:e,computed:1}}}return t}parsePrimary(){const t=this.peek();if("("===t.value){this.advance();const t=this.parseExpression();return this.expect(")"),t}if("{"===t.value)return this.parseObjectLiteral();if("["===t.value)return this.parseArrayLiteral();if("number"===t.type){this.advance();const e=t.value;return e.endsWith("ms")?{type:"literal",value:parseInt(e),unit:"ms"}:e.endsWith("s")?{type:"literal",value:1e3*parseFloat(e),unit:"ms"}:{type:"literal",value:parseFloat(e)}}if("string"===t.type)return this.advance(),{type:"literal",value:t.value.slice(1,-1)};if(this.match("true"))return this.advance(),{type:"literal",value:1};if(this.match("false"))return this.advance(),{type:"literal",value:0};if(this.match("null"))return this.advance(),{type:"literal",value:null};if(this.match("undefined"))return this.advance(),{type:"literal",value:void 0};if("localVar"===t.type)return this.advance(),{type:"variable",name:t.value,scope:"local"};if("globalVar"===t.type)return this.advance(),{type:"variable",name:t.value,scope:"global"};if("selector"===t.type)return this.advance(),{type:"selector",value:t.value};if(this.match("my")){this.advance();const t=this.peek();return"identifier"!==t.type&&"keyword"!==t.type||this.isCommandKeyword(t)?{type:"identifier",value:"me"}:{type:"possessive",object:{type:"identifier",value:"me"},property:this.advance().value}}if(this.match("its")){this.advance();const t=this.peek();return"identifier"!==t.type&&"keyword"!==t.type||this.isCommandKeyword(t)?{type:"identifier",value:"it"}:{type:"possessive",object:{type:"identifier",value:"it"},property:this.advance().value}}return this.match("me")?(this.advance(),{type:"identifier",value:"me"}):this.match("it")?(this.advance(),{type:"identifier",value:"it"}):this.match("you")?(this.advance(),{type:"identifier",value:"you"}):this.match("the","a","an")?(this.advance(),this.match("first","last","next","previous","closest","parent")?{type:"positional",position:this.advance().value,target:this.parsePositionalTarget()}:this.parsePrimary()):this.match("first","last","next","previous","closest","parent")?{type:"positional",position:this.advance().value,target:this.parsePositionalTarget()}:this.match("values")?(this.advance(),this.match("of")?(this.advance(),{type:"valuesOf",target:this.parseExpression()}):{type:"identifier",value:t.value}):(this.advance(),{type:"identifier",value:t.value})}parseObjectLiteral(){this.expect("{");const t=[];for(;!this.match("}");){const e=this.advance().value;this.expect(":");const s=this.parseExpression();t.push({key:e,value:s}),this.match(",")&&this.advance()}return this.expect("}"),{type:"object",properties:t}}parseArrayLiteral(){this.expect("[");const t=[];for(;!this.match("]");)t.push(this.parseExpression()),this.match(",")&&this.advance();return this.expect("]"),{type:"array",elements:t}}parsePositionalTarget(){const t=this.peek();return"selector"===t.type?{type:"selector",value:this.advance().value}:"identifier"===t.type||"keyword"===t.type?{type:"identifier",value:this.advance().value}:this.parseExpression()}}var a="moveBefore"in Element.prototype,h=[0,1,0,0,0,0,0,0,0,1,0,1,0],c=new Set,l=new Set,u=new Set,f=new Set,p=new Set,d=new Set;function m(t,e,s={}){"string"==typeof e&&(e=v(e).childNodes),!s.preserveChanges&&x(t)&&w(t),new b(s).morph(t,e)}function y(t,e,s={}){if("string"==typeof e){const t=v(e);if(!t.firstChild||1!==t.childNodes.length||1!==t.firstChild.nodeType)throw Error("[Morphlex] The string was not a valid HTML element.");e=t.firstChild}if(1!==t.nodeType||1!==e.nodeType||t.localName!==e.localName)throw Error("[Morphlex] You can only do an inner morph with matching elements.");x(t)&&w(t),new b(s).visitChildNodes(t,e)}function w(t){for(const e of t.querySelectorAll("input"))(e.name&&e.value!==e.defaultValue||e.checked!==e.defaultChecked)&&e.setAttribute("morphlex-dirty","");for(const e of t.querySelectorAll("option"))e.value&&e.selected!==e.defaultSelected&&e.setAttribute("morphlex-dirty","");for(const e of t.querySelectorAll("textarea"))e.value!==e.defaultValue&&e.setAttribute("morphlex-dirty","")}function v(t){const e=document.createElement("template");return e.innerHTML=t.trim(),e.content}function g(t,e,s){if(e!==s){if(e.parentNode===t){if(e.nextSibling===s)return;if(a)return void t.moveBefore(e,s)}t.insertBefore(e,s)}}class b{#t=new WeakMap;#e=new WeakMap;#s;constructor(t={}){this.#s=t}morph(t,e){x(t)&&this.#i(t),e instanceof NodeList?(this.#r(e),this.#n(t,e)):x(e)&&(this.#o(e),this.#a(t,e))}#n(t,e){const s=e.length;if(0===s)this.#h(t);else if(1===s)this.#a(t,e[0]);else if(s>1){const s=[...e];this.#a(t,s.shift());const i=t.nextSibling,r=t.parentNode||document;for(let t=0;s.length>t;t++){const e=s[t];(this.#s.beforeNodeAdded?.(r,e,i)??1)&&(r.insertBefore(e,i),this.#s.afterNodeAdded?.(e))}}}#a(t,e){t!==e&&(t.isEqualNode(e)||(1===t.nodeType&&1===e.nodeType?t.localName===e.localName?this.#c(t,e):this.#l(t,e):this.#u(t,e)))}#c(t,e){(this.#s.beforeNodeVisited?.(t,e)??1)&&((t.hasAttributes()||e.hasAttributes())&&this.#f(t,e),"textarea"===t.localName&&"textarea"===e.localName?this.#p(t,e):(t.hasChildNodes()||e.hasChildNodes())&&this.visitChildNodes(t,e),this.#s.afterNodeVisited?.(t,e))}#l(t,e){(this.#s.beforeNodeVisited?.(t,e)??1)&&(this.#d(t,e),this.#s.afterNodeVisited?.(t,e))}#u(t,e){(this.#s.beforeNodeVisited?.(t,e)??1)&&(t.nodeType===e.nodeType&&null!==t.nodeValue&&null!==e.nodeValue?t.nodeValue=e.nodeValue:this.#d(t,e),this.#s.afterNodeVisited?.(t,e))}#f(t,e){t.hasAttribute("morphlex-dirty")&&t.removeAttribute("morphlex-dirty");for(const{name:s,value:i}of e.attributes){"value"===s&&k(t)&&t.value!==i&&(this.#s.preserveChanges&&t.value!==t.defaultValue||(t.value=i)),"selected"===s&&E(t)&&!t.selected&&(this.#s.preserveChanges&&t.selected!==t.defaultSelected||(t.selected=1)),"checked"===s&&k(t)&&!t.checked&&(this.#s.preserveChanges&&t.checked!==t.defaultChecked||(t.checked=1));const e=t.getAttribute(s);e!==i&&(this.#s.beforeAttributeUpdated?.(t,s,i)??1)&&(t.setAttribute(s,i),this.#s.afterAttributeUpdated?.(t,s,e))}for(const{name:s,value:i}of t.attributes)e.hasAttribute(s)||("selected"===s&&E(t)&&t.selected&&(this.#s.preserveChanges&&t.selected!==t.defaultSelected||(t.selected=0)),"checked"===s&&k(t)&&t.checked&&(this.#s.preserveChanges&&t.checked!==t.defaultChecked||(t.checked=0)),(this.#s.beforeAttributeUpdated?.(t,s,null)??1)&&(t.removeAttribute(s),this.#s.afterAttributeUpdated?.(t,s,i)))}#p(t,e){const s=e.textContent||"",i=t.value!==t.defaultValue;t.textContent!==s&&(t.textContent=s),this.#s.preserveChanges&&i||(t.value=t.defaultValue)}visitChildNodes(t,e){if(!(this.#s.beforeChildrenVisited?.(t)??1))return;const s=t,i=[...t.childNodes],r=[...e.childNodes];c.clear(),l.clear(),u.clear(),f.clear(),p.clear(),d.clear();const n=[],o=[],a=[],h=[],m=[],y=[];for(let t=0;i.length>t;t++){const e=i[t],s=e.nodeType;h[t]=s,1===s?(y[t]=e.localName,""!==e.id?u.add(t):l.add(t)):3===s&&""===e.textContent?.trim()?d.add(t):c.add(t)}for(let t=0;r.length>t;t++){const e=r[t],s=e.nodeType;if(a[t]=s,1===s)m[t]=e.localName,p.add(t);else{if(3===s&&""===e.textContent?.trim())continue;f.add(t)}}for(const t of p){const e=m[t],s=r[t];for(const r of l)if(e===y[r]&&i[r].isEqualNode(s)){n[t]=r,o[t]=0,l.delete(r),p.delete(t);break}}for(const t of p){const e=r[t],s=e.id,a=this.#t.get(e);if(""!==s||a)t:for(const e of u){const r=i[e];if(m[t]===y[e]){if(""!==s&&s===r.id){n[t]=e,o[t]=1,u.delete(e),p.delete(t);break t}if(a){const s=this.#e.get(r);if(s)for(let i=0;a.length>i;i++)if(s.has(a[i])){n[t]=e,o[t]=1,u.delete(e),p.delete(t);break t}}}}}for(const t of p){const e=r[t],s=e.getAttribute("name"),a=e.getAttribute("href"),h=e.getAttribute("src");for(const e of l){const r=i[e];if(m[t]===y[e]&&(s&&s===r.getAttribute("name")||a&&a===r.getAttribute("href")||h&&h===r.getAttribute("src"))){n[t]=e,o[t]=1,l.delete(e),p.delete(t);break}}}for(const t of p){const e=r[t],s=m[t];for(const r of l)if(s===y[r]){if("input"===s&&i[r].type!==e.type)continue;n[t]=r,o[t]=1,l.delete(r),p.delete(t);break}}for(const t of f){const e=r[t];for(const s of c)if(i[s].isEqualNode(e)){n[t]=s,o[t]=0,c.delete(s),f.delete(t);break}}for(const t of f){const e=a[t];for(const s of c)if(e===h[s]){n[t]=s,o[t]=2,c.delete(s),f.delete(t);break}}for(const t of c)this.#h(i[t]);for(const t of d)this.#h(i[t]);for(const t of l)this.#h(i[t]);for(const t of u)this.#h(i[t]);const w=function(t){const e=t.length;if(0===e)return[];const s=[],i=[],r=Array(e);for(let n=0;e>n;n++){const e=t[n];if(void 0===e)continue;let o=0,a=s.length;for(;a>o;){const t=Math.floor((o+a)/2);e>s[t]?o=t+1:a=t}r[n]=o>0?i[o-1]:-1,o===s.length?(s.push(e),i.push(n)):(s[o]=e,i[o]=n)}const n=[];if(0===i.length)return n;let o=i[i.length-1];for(;void 0!==o&&-1!==o;)n.unshift(o),o=r[o];return n}(n),v=Array(i.length);for(let t=0;w.length>t;t++)v[n[w[t]]]=1;let b=s.firstChild;for(let t=0;r.length>t;t++){const e=r[t],a=n[t];if(void 0!==a){const r=i[a],n=o[t];v[a]||g(s,r,b),0===n||(1===n?this.#c(r,e):this.#a(r,e)),b=r.nextSibling}else(this.#s.beforeNodeAdded?.(s,e,b)??1)&&(s.insertBefore(e,b),this.#s.afterNodeAdded?.(e),b=e.nextSibling)}this.#s.afterChildrenVisited?.(t)}#d(t,e){const s=t.parentNode||document,i=t;(this.#s.beforeNodeRemoved?.(t)??1)&&(this.#s.beforeNodeAdded?.(s,e,i)??1)&&(s.insertBefore(e,i),this.#s.afterNodeAdded?.(e),t.remove(),this.#s.afterNodeRemoved?.(t))}#h(t){(this.#s.beforeNodeRemoved?.(t)??1)&&(t.remove(),this.#s.afterNodeRemoved?.(t))}#r(t){for(const e of t)x(e)&&this.#o(e)}#o(t){const e=this.#t;for(const s of t.querySelectorAll("[id]")){const i=s.id;if(""===i)continue;let r=s;for(;r;){const s=e.get(r);if(s?s.push(i):e.set(r,[i]),r===t)break;r=r.parentElement}}}#i(t){const e=this.#e;for(const s of t.querySelectorAll("[id]")){const i=s.id;if(""===i)continue;let r=s;for(;r;){const s=e.get(r);if(s?s.add(i):e.set(r,new Set([i])),r===t)break;r=r.parentElement}}}}function k(t){return"input"===t.localName}function E(t){return"option"===t.localName}function x(t){return!!h[t.nodeType]}const A=new Map,_=new WeakMap;function j(t){let e=_.get(t);return e||(e=new Map,_.set(t,e)),e}const M=1e3;async function C(t,e){switch(t.type){case"literal":return t.value;case"identifier":return"me"===t.value||"my"===t.value?e.me:"it"===t.value?e.it:"you"===t.value?e.you:"event"===t.value?e.event:"body"===t.value?document.body:"document"===t.value?document:"window"===t.value?window:e.locals.has(t.value)?e.locals.get(t.value):t.value in e.me?e.me[t.value]:t.value in window?window[t.value]:t.value;case"variable":if("local"===t.scope)return j(e.me).get(t.name.slice(1));const s=t.name.slice(1);return A.has(s)?A.get(s):window[t.name];case"selector":const i=document.querySelectorAll(t.value);return 1===i.length?i[0]:Array.from(i);case"binary":return async function(t,e){if("has"===t.operator){const s=await C(t.left,e);return s instanceof Element&&"selector"===t.right.type&&t.right.value.startsWith(".")?s.classList.contains(t.right.value.slice(1)):0}const s=await C(t.left,e),i=await C(t.right,e);switch(t.operator){case"+":return s+i;case"-":return s-i;case"*":return s*i;case"/":return s/i;case"%":return s%i;case"==":case"is":return s==i;case"!=":case"is not":return s!=i;case"<":return i>s;case">":return s>i;case"<=":return i>=s;case">=":return s>=i;case"and":case"&&":return s&&i;case"or":case"||":return s||i;case"has":if(s instanceof Element){const t="string"==typeof i?i:i?.value;if("string"==typeof t&&t.startsWith("."))return s.classList.contains(t.slice(1))}return 0;case"contains":case"includes":return"string"==typeof s||Array.isArray(s)?s.includes(i):s instanceof Element?s.contains(i):0;case"matches":return s instanceof Element?s.matches(i):"string"==typeof s?RegExp(i).test(s):0;default:return}}(t,e);case"unary":const r=await C(t.operand,e);return"not"===t.operator?!r:r;case"possessive":case"member":const n=await C(t.object,e);if(null==n)return;const o=t.computed?await C(t.property,e):t.property;return"values"===o&&n instanceof Element?T(n):n[o];case"call":{let s,i=null;if("member"===t.callee.type||"possessive"===t.callee.type){i=await C(t.callee.object,e);const r=t.callee.computed?await C(t.callee.property,e):t.callee.property;s=i?.[r]}else s=await C(t.callee,e);const r=await Promise.all(t.args.map(t=>C(t,e)));return"function"==typeof s?s.apply(i,r):void 0}case"positional":return function(t,e){const s=t.target;let i=[],r=null;switch(("selector"===s.type||"identifier"===s.type||"htmlSelector"===s.type)&&(r=s.value),r&&(i=Array.from(document.querySelectorAll(r))),t.position){case"first":default:return i[0]||null;case"last":return i[i.length-1]||null;case"next":if(r){let t=e.me.nextElementSibling;for(;t;){if(t.matches(r))return t;t=t.nextElementSibling}return null}return e.me.nextElementSibling;case"previous":if(r){let t=e.me.previousElementSibling;for(;t;){if(t.matches(r))return t;t=t.previousElementSibling}return null}return e.me.previousElementSibling;case"closest":return r?e.me.closest(r):null;case"parent":if(r){let t=e.me.parentElement;for(;t;){if(t.matches(r))return t;t=t.parentElement}return null}return e.me.parentElement}}(t,e);case"object":const a={};for(const s of t.properties)a[s.key]=await C(s.value,e);return a;case"array":return Promise.all(t.elements.map(t=>C(t,e)));case"valuesOf":{const s=await C(t.target,e);return s instanceof Element?T(s):new FormData}default:return}}function T(t){if(t instanceof HTMLFormElement)return new FormData(t);const e=new FormData;return t.querySelectorAll("input, select, textarea").forEach(t=>{const s=t.getAttribute("name");s&&"value"in t&&e.append(s,t.value)}),e}async function F(t,e){const s=async()=>{if(!t.target)return[e.me];const s=await C(t.target,e);return Array.isArray(s)?s:s instanceof Element?[s]:"string"==typeof s?Array.from(document.querySelectorAll(s)):[e.me]},i=t=>{if(!t)return"";if("selector"===t.type)return t.value.startsWith("@")?t.value:t.value.slice(1);if("string"===t.type||"literal"===t.type){const e=t.value;return"string"==typeof e&&e.startsWith(".")?e.slice(1):e+""}return"identifier"===t.type?t.value:""},r=t=>Array.isArray(t)?t.filter(t=>t instanceof Element):t instanceof Element?[t]:"string"==typeof t?Array.from(document.querySelectorAll(t)):[],n=t=>t.startsWith("*"),o=t=>t.substring(1),a=(t,e,s)=>n(e)?(t.style.setProperty(o(e),s+""),1):0,h=(t,e)=>{if(n(e))return getComputedStyle(t).getPropertyValue(o(e))};switch(t.name){case"toggle":{const r=i(t.args[0])||await C(t.args[0],e)+"",n=await s();if(r.startsWith("@")){const t=r.slice(1);for(const e of n)e.hasAttribute(t)?e.removeAttribute(t):e.setAttribute(t,"")}else for(const t of n)t.classList.toggle(r);return e.it=1===n.length?n[0]:n,e.it}case"add":{const r=i(t.args[0])||await C(t.args[0],e)+"",n=await s();if(r.startsWith("@")){const t=r.slice(1);for(const e of n)e.setAttribute(t,"")}else for(const t of n)t.classList.add(r);return e.it=1===n.length?n[0]:n,e.it}case"remove":{const t=await s();for(const e of t)e.remove();return null}case"removeClass":{const r=i(t.args[0])||await C(t.args[0],e)+"",n=await s();if(r.startsWith("@")){const t=r.slice(1);for(const e of n)e.removeAttribute(t)}else for(const t of n)t.classList.remove(r);return n}case"show":{const t=await s();for(const e of t)e.style.display="",e.classList.remove("hidden");return t}case"hide":{const t=await s();for(const e of t)e.style.display="none";return t}case"put":{const i=await C(t.args[0],e),o=t.modifier||"into";if("possessive"===t.target?.type&&n(t.target.property)){const s=r(await C(t.target.object,e));for(const e of s)a(e,t.target.property,i);return e.it=i,i}const h=await s();for(const t of h){const e=i+"";"into"===o?t.innerHTML=e:"before"===o?t.insertAdjacentHTML("beforebegin",e):"after"===o?t.insertAdjacentHTML("afterend",e):"at start of"===o?t.insertAdjacentHTML("afterbegin",e):"at end of"===o&&t.insertAdjacentHTML("beforeend",e)}return e.it=i,i}case"append":{const i=await C(t.args[0],e),r=await s();for(const t of r)t.insertAdjacentHTML("beforeend",i+"");return e.it=i,i}case"prepend":{const i=await C(t.args[0],e),r=await s();for(const t of r)t.insertAdjacentHTML("afterbegin",i+"");return e.it=i,i}case"take":{const r=i(t.args[0]),n=t.target?await s():[e.me.parentElement];for(const t of n)t.querySelectorAll("."+r).forEach(t=>t.classList.remove(r));return e.me.classList.add(r),e.me}case"empty":{const t=await s();for(const e of t)e.innerHTML="";return t}case"set":{const s=t.args[0],i=await C(t.args[1],e);if("variable"===s.type){const t=s.name.slice(1);return("local"===s.scope?j(e.me):A).set(t,i),e.it=i,i}if("possessive"===s.type||"member"===s.type){const t=await C(s.object,e);if(t)return t instanceof Element&&n(s.property)?a(t,s.property,i):t[s.property]=i,e.it=i,i}return e.it=i,i}case"get":{const s=await C(t.args[0],e);return e.it=s,s}case"increment":{const s=t.args[0],i=t.args[1]?await C(t.args[1],e):1;if("variable"===s.type){const t=s.name.slice(1),r="local"===s.scope?j(e.me):A,n=(r.get(t)||0)+i;return r.set(t,n),e.it=n,n}if("possessive"===s.type){const t=n(s.property),o=r(await C(s.object,e));for(const r of o){const n=t?h(r,s.property):Reflect.get(r,s.property),o=(parseFloat(n||"0")||0)+i;t?a(r,s.property,o):Reflect.set(r,s.property,o),e.it=o}return e.it}const o=r(await C(s,e));for(const t of o){const s=(parseFloat(t.textContent||"0")||0)+i;t.textContent=s+"",e.it=s}return e.it}case"decrement":{const s=t.args[0],i=t.args[1]?await C(t.args[1],e):1;if("variable"===s.type){const t=s.name.slice(1),r="local"===s.scope?j(e.me):A,n=(r.get(t)||0)-i;return r.set(t,n),e.it=n,n}if("possessive"===s.type){const t=n(s.property),o=r(await C(s.object,e));for(const r of o){const n=t?h(r,s.property):Reflect.get(r,s.property),o=(parseFloat(n||"0")||0)-i;t?a(r,s.property,o):Reflect.set(r,s.property,o),e.it=o}return e.it}const o=r(await C(s,e));for(const t of o){const s=(parseFloat(t.textContent||"0")||0)-i;t.textContent=s+"",e.it=s}return e.it}case"wait":{const s=await C(t.args[0],e),i="number"==typeof s?s:parseInt(s+"");return await new Promise(t=>setTimeout(t,i)),i}case"waitFor":{const i=await C(t.args[0],e),r=(await s())[0]||e.me;return new Promise(t=>{r.addEventListener(i+"",s=>{e.it=s,t(s)},{once:1})})}case"transition":{const i=(await C(t.args[0],e)+"").replace(/^\*/,""),r=await C(t.args[1],e),n=await C(t.args[2],e),o="number"==typeof n?n:(n+"").endsWith("ms")?parseInt(n+""):(n+"").endsWith("s")?1e3*parseFloat(n+""):parseInt(n+"")||300,a=await s(),h=[];for(const t of a){const e=t,s=i.replace(/([A-Z])/g,"-$1").toLowerCase(),n=e.style.transition;e.style.transition=`${s} ${o}ms ease`,e.style.setProperty(s,r+""),h.push(new Promise(t=>{const i=()=>{e.style.transition=n,t()},r=t=>{t.propertyName===s&&(e.removeEventListener("transitionend",r),i())};e.addEventListener("transitionend",r),setTimeout(i,o+50)}))}return await Promise.all(h),e.it=1===a.length?a[0]:a,e.it}case"send":{const i=await C(t.args[0],e),r=await s(),n=new CustomEvent(i+"",{bubbles:1,detail:e.it});for(const t of r)t.dispatchEvent(n);return e.it=n,n}case"log":{const s=await Promise.all(t.args.map(t=>C(t,e)));return console.log(...s),s[0]}case"call":{const s=await C(t.args[0],e);return e.it=s,s}case"copy":{const s=await C(t.args[0],e);let i="";i="string"==typeof s?s:s instanceof Element?s.textContent||"":s+"";try{if(navigator.clipboard)await navigator.clipboard.writeText(i);else{const t=document.createElement("textarea");t.value=i,t.style.cssText="position:fixed;top:0;left:-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}return e.me instanceof Element&&e.me.dispatchEvent(new CustomEvent("copy:success",{bubbles:1,detail:{text:i}})),e.it=i,i}catch(t){throw e.me instanceof Element&&e.me.dispatchEvent(new CustomEvent("copy:error",{bubbles:1,detail:{error:t}})),t}}case"beep":{const s=await Promise.all(t.args.map(t=>C(t,e))),i=s.length>0?s:[e.it];for(const t of i){const e=null===t?"null":void 0===t?"undefined":Array.isArray(t)?`Array[${t.length}]`:t instanceof Element?`Element<${t.tagName.toLowerCase()}>`:typeof t;console.log("[beep]",e+":",t)}return i[0]}case"go":{const s=await C(t.args[0],e),i=(s+"").toLowerCase();return"back"===i?history.back():"forward"===i?history.forward():"bottom"===i?e.me.scrollIntoView({block:"end",behavior:"smooth"}):"top"===i?e.me.scrollIntoView({block:"start",behavior:"smooth"}):window.location.href=s+"",null}case"push":{const s=await C(t.args[0],e)+"";let i="";return t.modifiers?.title&&(i=await C(t.modifiers.title,e)+""),window.history.pushState(null,"",s),i&&(document.title=i),window.dispatchEvent(new CustomEvent("lokascript:pushurl",{detail:{url:s,title:i}})),{url:s,title:i,mode:"push"}}case"replace":{const s=await C(t.args[0],e)+"";let i="";return t.modifiers?.title&&(i=await C(t.modifiers.title,e)+""),window.history.replaceState(null,"",s),i&&(document.title=i),window.dispatchEvent(new CustomEvent("lokascript:replaceurl",{detail:{url:s,title:i}})),{url:s,title:i,mode:"replace"}}case"focus":{const t=await s();for(const e of t)e.focus();return t}case"blur":{const t=await s();for(const e of t)e.blur();return t}case"return":throw{type:"return",value:t.args[0]?await C(t.args[0],e):e.it};case"break":throw{type:"break"};case"continue":throw{type:"continue"};case"halt":{const s=t.args[0];let i=e.event;if("identifier"===s?.type&&"the"===s.name&&"event"===t.args[1]?.name)i=e.event;else if(s){const t=await C(s,e);t?.preventDefault&&(i=t)}if(i&&"function"==typeof i.preventDefault)return i.preventDefault(),i.stopPropagation(),{halted:1,eventHalted:1};const r=Error("HALT_EXECUTION");throw r.isHalt=1,r}case"exit":{const t=Error("EXIT_COMMAND");throw t.isExit=1,t}case"throw":{const s=t.args[0]?await C(t.args[0],e):"Error";throw s instanceof Error?s:Error(s+"")}case"js":{const s=t.args[0];let i="";i="string"===s.type?s.value:"template"===s.type?await C(s,e):await C(s,e)+"";const r={me:e.me,it:e.it,event:e.event,target:e.me,locals:Object.fromEntries(e.locals),globals:Object.fromEntries(A),document:"undefined"!=typeof document?document:void 0,window:"undefined"!=typeof window?window:void 0};try{const t=Function("ctx",`with(ctx) { return (async () => { ${i} })(); }`),s=await t(r);return e.it=s,s}catch(t){throw console.error("[js] Execution error:",t),t}}case"morph":{const i=await s(),r=await C(t.args[0],e)+"",n="over"===t.modifier;for(const t of i)try{if(n)m(t,r);else{const e=document.createElement("template");e.innerHTML=r;const s=e.content.firstElementChild;if(s&&!s.nextElementSibling&&s.tagName===t.tagName)m(t,s);else{const e=document.createElement(t.tagName);e.innerHTML=r,y(t,e)}}}catch(e){console.warn("[LokaScript] Morph failed, falling back:",e),n?t.outerHTML=r:t.innerHTML=r}return e.it=1===i.length?i[0]:i,e.it}default:return console.error(`[hyperfixi] Unknown command "${t.name}" \u2014 not in this bundle. Use hyperfixi.js (full bundle).`),null}}async function I(t,e){try{return await P(t,e)}catch(t){if("return"===t?.type)throw t;throw t}}async function O(t,e){switch(t.type){case"if":return await C(t.condition,e)?I(t.body,e):t.elseBody?I(t.elseBody,e):null;case"repeat":{const s=await C(t.condition,e),i=Number(s)||0;for(let s=0;i>s&&M>s;s++){e.locals.set("__loop_index__",s),e.locals.set("__loop_count__",s+1);try{await I(t.body,e)}catch(t){if("break"===t?.type)break;if("continue"===t?.type)continue;throw t}}return null}case"for":{const{variable:s,iterable:i}=t.condition,r=await C(i,e),n=Array.isArray(r)?r:r instanceof NodeList?Array.from(r):[r],o=s.startsWith(":")?s.slice(1):s;for(let s=0;n.length>s&&M>s;s++){e.locals.set(o,n[s]),e.locals.set("__loop_index__",s),e.locals.set("__loop_count__",s+1);try{await I(t.body,e)}catch(t){if("break"===t?.type)break;if("continue"===t?.type)continue;throw t}}return null}case"while":{let s=0;for(;await C(t.condition,e)&&M>s;){e.locals.set("__loop_index__",s);try{await I(t.body,e)}catch(t){if("break"===t?.type)break;if("continue"===t?.type){s++;continue}throw t}s++}return null}case"fetch":{const{url:s,responseType:i,options:r,method:n}=t.condition;try{const o=await C(s,e),a={};if(n){const t=await C(n,e);a.method=(t+"").toUpperCase()}if(r){const t=await C(r,e);t instanceof FormData?a.body=t:!t||"object"!=typeof t||t instanceof Element||Object.assign(a,t)}const h=await fetch(o+"",a);if(!h.ok)throw Error("HTTP "+h.status);const c=await C(i,e);let l;if("json"===c)l=await h.json();else if("html"===c){const t=await h.text();l=(new DOMParser).parseFromString(t,"text/html").body.innerHTML}else l=await h.text();e.it=l,e.locals.set("it",l),e.locals.set("result",l),e.locals.set("response",h),await I(t.body,e)}catch(t){if("return"===t?.type)throw t;e.locals.set("error",t),console.error("Fetch error:",t)}return null}default:return null}}async function P(t,e){let s;for(const i of t)"command"===i.type?s=await F(i,e):["if","repeat","for","while","fetch"].includes(i.type)&&(s=await O(i,e));return s}async function S(t,e,s){const i={me:e,event:s,locals:new Map,globals:A};if("sequence"===t.type)try{return await P(t.commands,i)}catch(t){if("return"===t?.type)return t.value;throw t}if("event"===t.type){const s=t,r=s.event;if(r.startsWith("interval:")){const t=r.split(":")[1],i=t.endsWith("ms")?parseInt(t):t.endsWith("s")?1e3*parseFloat(t):parseInt(t);return void setInterval(async()=>{const t={me:e,locals:new Map,globals:A};try{await P(s.body,t)}catch(t){if("return"!==t?.type)throw t}},i)}if("init"===r){try{await P(s.body,i)}catch(t){if("return"!==t?.type)throw t}return}const n=s.filter?await C(s.filter,i):e,o=n instanceof Element?n:e,a=s.modifiers;let h=async t=>{a.prevent&&t.preventDefault(),a.stop&&t.stopPropagation();const i={me:e,event:t,you:t.target instanceof Element?t.target:void 0,locals:new Map,globals:A};try{await P(s.body,i)}catch(t){if("return"===t?.type)return t.value;throw t}};if(a.debounce){let t;const e=h;h=async s=>{clearTimeout(t),t=setTimeout(()=>e(s),a.debounce)}}if(a.throttle){let t=0;const e=h;h=async s=>{const i=Date.now();a.throttle>i-t||(t=i,await e(s))}}return void o.addEventListener(r,h,{once:!!a.once})}return null}const $=t=>new o(t).parse(),H=(N=$,L=S,(t=document)=>{t.querySelectorAll("[_]").forEach(t=>{const e=t.getAttribute("_");if(e)try{L(N(e),t)}catch(t){console.error("HyperFixi Hybrid Complete error:",t,"Code:",e)}})});var N,L;!function(t,e,s="hyperfixi"){"undefined"!=typeof window&&(window[s]=t,"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>e()):e())}({version:"1.0.0-hybrid-complete",parse:$,execute:async(t,e)=>S($(t),e||document.body),init:H,process:H,addAliases:function(t){Object.assign(s,t)},addEventAliases:function(t){Object.assign(i,t)},tokenize:e,evaluate:C,commands:["toggle","add","remove","removeClass","show","hide","put","append","prepend","take","empty","set","get","increment","decrement","wait","transition","send","trigger","log","call","copy","beep","go","push","push-url","replace","replace-url","focus","blur","return","break","continue","halt","exit","throw","js","morph"],blocks:["if","else","unless","repeat","for","while","fetch"]},H)}();
|