@xnoxs/flux-lang 4.0.8 → 4.0.9

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/dist/flux.min.js CHANGED
@@ -1,26 +1,25 @@
1
1
  /*!
2
- * flux-lang v4.0.8
2
+ * flux-lang v4.0.9
3
3
  * Flux — A modern language that transpiles to JavaScript. Python-clean syntax, TypeScript-level safety, Rust-inspired pattern matching.
4
4
  * (c) 2026 Flux Lang Contributors
5
5
  * Released under the MIT License
6
6
  */
7
- "use strict";var _=(n,t)=>()=>{try{return t||n((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}};var J=_((xs,Ct)=>{"use strict";var o={NUMBER:"NUMBER",STRING:"STRING",BOOL:"BOOL",NULL:"NULL",IDENT:"IDENT",VAR:"VAR",VAL:"VAL",FN:"FN",RETURN:"RETURN",DECLARE:"DECLARE",IF:"IF",ELSE:"ELSE",FOR:"FOR",IN:"IN",WHILE:"WHILE",BREAK:"BREAK",CONTINUE:"CONTINUE",DO:"DO",CLASS:"CLASS",EXTENDS:"EXTENDS",SELF:"SELF",NEW:"NEW",INTERFACE:"INTERFACE",IMPLEMENTS:"IMPLEMENTS",PRIVATE:"PRIVATE",PUBLIC:"PUBLIC",PROTECTED:"PROTECTED",READONLY:"READONLY",STATIC:"STATIC",ABSTRACT:"ABSTRACT",OVERRIDE:"OVERRIDE",MATCH:"MATCH",WHEN:"WHEN",IMPORT:"IMPORT",EXPORT:"EXPORT",FROM:"FROM",AS:"AS",DEFAULT:"DEFAULT",AND:"AND",OR:"OR",NOT:"NOT",ASYNC:"ASYNC",AWAIT:"AWAIT",TRY:"TRY",CATCH:"CATCH",FINALLY:"FINALLY",THROW:"THROW",TYPEOF:"TYPEOF",INSTANCEOF:"INSTANCEOF",TYPE:"TYPE",ENUM:"ENUM",SATISFIES:"SATISFIES",IS:"IS",CONST:"CONST",PLUS:"PLUS",MINUS:"MINUS",STAR:"STAR",SLASH:"SLASH",PERCENT:"PERCENT",REGEX:"REGEX",STARSTAR:"STARSTAR",EQ:"EQ",EQEQ:"EQEQ",NEQ:"NEQ",EQEQEQ:"EQEQEQ",NEQEQ:"NEQEQ",LT:"LT",LTE:"LTE",GT:"GT",GTE:"GTE",PLUSEQ:"PLUSEQ",MINUSEQ:"MINUSEQ",STAREQ:"STAREQ",SLASHEQ:"SLASHEQ",PERCENTEQ:"PERCENTEQ",PLUSPLUS:"PLUSPLUS",MINUSMINUS:"MINUSMINUS",AMPERSAND:"AMPERSAND",ANDAND:"ANDAND",PIPEB:"PIPEB",OROR:"OROR",CARET:"CARET",TILDE:"TILDE",LSHIFT:"LSHIFT",RSHIFT:"RSHIFT",ARROW:"ARROW",FATARROW:"FATARROW",PIPE:"PIPE",DOTDOT:"DOTDOT",DOTDOTDOT:"DOTDOTDOT",WILDCARD:"WILDCARD",NULLISH:"NULLISH",QUESTIONDOT:"QUESTIONDOT",BANG:"BANG",AT:"AT",LPAREN:"LPAREN",RPAREN:"RPAREN",LBRACKET:"LBRACKET",RBRACKET:"RBRACKET",LBRACE:"LBRACE",RBRACE:"RBRACE",COMMA:"COMMA",DOT:"DOT",COLON:"COLON",QUESTION:"QUESTION",NEWLINE:"NEWLINE",INDENT:"INDENT",DEDENT:"DEDENT",EOF:"EOF"},Lt={var:o.VAR,val:o.VAL,fn:o.FN,return:o.RETURN,declare:o.DECLARE,if:o.IF,else:o.ELSE,for:o.FOR,in:o.IN,while:o.WHILE,break:o.BREAK,continue:o.CONTINUE,do:o.DO,class:o.CLASS,extends:o.EXTENDS,self:o.SELF,new:o.NEW,interface:o.INTERFACE,implements:o.IMPLEMENTS,private:o.PRIVATE,public:o.PUBLIC,protected:o.PROTECTED,readonly:o.READONLY,static:o.STATIC,abstract:o.ABSTRACT,override:o.OVERRIDE,match:o.MATCH,when:o.WHEN,import:o.IMPORT,export:o.EXPORT,from:o.FROM,as:o.AS,default:o.DEFAULT,and:o.AND,or:o.OR,not:o.NOT,async:o.ASYNC,await:o.AWAIT,try:o.TRY,catch:o.CATCH,finally:o.FINALLY,throw:o.THROW,typeof:o.TYPEOF,instanceof:o.INSTANCEOF,type:o.TYPE,enum:o.ENUM,satisfies:o.SATISFIES,is:o.IS,const:o.CONST,true:"__TRUE__",false:"__FALSE__",null:"__NULL__"},kt=class extends Error{constructor(t,e,s){super(t),this.name="LexerError",this.line=e,this.col=s}},Et=class{constructor(t){this.src=t.replace(/\r\n/g,`
7
+ "use strict";var S=(a,t)=>()=>{try{return t||a((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}};var B=S((Ze,V)=>{"use strict";var p={NUMBER:"NUMBER",STRING:"STRING",BOOL:"BOOL",NULL:"NULL",IDENT:"IDENT",VAR:"VAR",VAL:"VAL",FN:"FN",RETURN:"RETURN",IF:"IF",ELSE:"ELSE",FOR:"FOR",IN:"IN",WHILE:"WHILE",BREAK:"BREAK",CONTINUE:"CONTINUE",DO:"DO",CLASS:"CLASS",EXTENDS:"EXTENDS",SELF:"SELF",NEW:"NEW",INTERFACE:"INTERFACE",IMPLEMENTS:"IMPLEMENTS",PRIVATE:"PRIVATE",PUBLIC:"PUBLIC",PROTECTED:"PROTECTED",READONLY:"READONLY",STATIC:"STATIC",ABSTRACT:"ABSTRACT",OVERRIDE:"OVERRIDE",MATCH:"MATCH",WHEN:"WHEN",IMPORT:"IMPORT",EXPORT:"EXPORT",FROM:"FROM",AS:"AS",DEFAULT:"DEFAULT",AND:"AND",OR:"OR",NOT:"NOT",ASYNC:"ASYNC",AWAIT:"AWAIT",TRY:"TRY",CATCH:"CATCH",FINALLY:"FINALLY",THROW:"THROW",TYPEOF:"TYPEOF",INSTANCEOF:"INSTANCEOF",TYPE:"TYPE",ENUM:"ENUM",SATISFIES:"SATISFIES",IS:"IS",CONST:"CONST",PLUS:"PLUS",MINUS:"MINUS",STAR:"STAR",SLASH:"SLASH",PERCENT:"PERCENT",REGEX:"REGEX",STARSTAR:"STARSTAR",EQ:"EQ",EQEQ:"EQEQ",NEQ:"NEQ",EQEQEQ:"EQEQEQ",NEQEQ:"NEQEQ",LT:"LT",LTE:"LTE",GT:"GT",GTE:"GTE",PLUSEQ:"PLUSEQ",MINUSEQ:"MINUSEQ",STAREQ:"STAREQ",SLASHEQ:"SLASHEQ",PERCENTEQ:"PERCENTEQ",PLUSPLUS:"PLUSPLUS",MINUSMINUS:"MINUSMINUS",AMPERSAND:"AMPERSAND",ANDAND:"ANDAND",PIPEB:"PIPEB",OROR:"OROR",CARET:"CARET",TILDE:"TILDE",LSHIFT:"LSHIFT",RSHIFT:"RSHIFT",ARROW:"ARROW",FATARROW:"FATARROW",PIPE:"PIPE",DOTDOT:"DOTDOT",DOTDOTDOT:"DOTDOTDOT",WILDCARD:"WILDCARD",NULLISH:"NULLISH",QUESTIONDOT:"QUESTIONDOT",BANG:"BANG",AT:"AT",LPAREN:"LPAREN",RPAREN:"RPAREN",LBRACKET:"LBRACKET",RBRACKET:"RBRACKET",LBRACE:"LBRACE",RBRACE:"RBRACE",COMMA:"COMMA",DOT:"DOT",COLON:"COLON",QUESTION:"QUESTION",NEWLINE:"NEWLINE",INDENT:"INDENT",DEDENT:"DEDENT",EOF:"EOF"};V.exports.T=p;var Xt=p;V.exports.TokenType=Xt;var Nt={var:"VAR",val:"VAL",fn:"FN",return:"RETURN",declare:"DECLARE",if:"IF",else:"ELSE",for:"FOR",in:"IN",while:"WHILE",break:"BREAK",continue:"CONTINUE",do:"DO",class:"CLASS",extends:"EXTENDS",self:"SELF",new:"NEW",interface:"INTERFACE",implements:"IMPLEMENTS",private:"PRIVATE",public:"PUBLIC",protected:"PROTECTED",readonly:"READONLY",static:"STATIC",abstract:"ABSTRACT",override:"OVERRIDE",match:"MATCH",when:"WHEN",import:"IMPORT",export:"EXPORT",from:"FROM",as:"AS",default:"DEFAULT",and:"AND",or:"OR",not:"NOT",async:"ASYNC",await:"AWAIT",try:"TRY",catch:"CATCH",finally:"FINALLY",throw:"THROW",typeof:"TYPEOF",instanceof:"INSTANCEOF",type:"TYPE",enum:"ENUM",satisfies:"SATISFIES",is:"IS",const:"CONST",true:"__TRUE__",false:"__FALSE__",null:"__NULL__"},J=class{constructor(t,e,s,i,n,h,l){this.src=t,this.pos=e,this.line=s,this.col=i,this.tokens=n,this.indentStack=h,this.nestDepth=l}err(t){throw new Error(`[Lexer ${this.line}:${this.col}] ${t}`)}ch(t=0){return this.src[this.pos+t]??""}adv(){let t=this.src[this.pos];return this.pos=this.pos+1,t==`
8
+ `?(this.line=this.line+1,this.col=1):this.col=this.col+1,t}tok(t,e,s,i){let n=e??t,h=s??this.line,l=i??this.col;this.tokens.push({type:t,value:n,line:h,col:l})}applyIndent(t){if(this.nestDepth>0)return;let e=this.indentStack[this.indentStack.length-1];if(t>e)this.indentStack.push(t),this.tok(p.INDENT,t,this.line,1);else if(t<e){for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>t;)this.indentStack.pop(),this.tok(p.DEDENT,null,this.line,1);this.indentStack[this.indentStack.length-1]!=t&&this.err(`Inconsistent indentation (${t} spaces)`)}}scanBacktick(t,e){this.adv();let s="";for(;this.pos<this.src.length&&this.ch()!="`";)if(this.ch()=="\\"){this.adv();let c=this.adv();c=="n"?s+=`
9
+ `:c=="t"?s+=" ":c=="`"?s+="`":c=="\\"?s+="\\":s+="\\"+c}else s+=this.adv();this.ch()!="`"&&this.err("Unterminated backtick string"),this.adv();let n=s.split(`
10
+ `).map(c=>c.trimEnd());for(;n.length&&!n[0].trim();)n.shift();for(;n.length&&!n[n.length-1].trim();)n.pop();let h=999999;for(let c of n)if(c.trim()){let u=c.match(/^(\s*)/)[1].length;u<h&&(h=u)}h==999999&&(h=0);let l=n.map(c=>c.slice(h));this.tok(p.STRING,l.join(`
11
+ `),t,e)}scanStr(t,e){this.adv();let s=[],i="";for(;this.pos<this.src.length&&this.ch()!='"';)if(this.ch()=="\\"){this.adv();let n=this.adv();n=="n"?i+=`
12
+ `:n=="t"?i+=" ":n=='"'?i+='"':n=="'"?i+="'":n=="\\"?i+="\\":n=="{"?i+="{":n=="}"?i+="}":i+="\\"+n}else if(this.ch()=="{"){s.push({type:"text",value:i}),i="",this.adv();let n=1,h="";for(;this.pos<this.src.length;){let l=this.ch();if(l=="{"&&(n=n+1),l=="}"&&(n=n-1,n==0))break;l=="\\"&&(this.src[this.pos+1]=='"'||this.src[this.pos+1]=="'")?(this.adv(),h+=this.adv()):h+=this.adv()}this.ch()!="}"&&this.err("Unclosed string interpolation"),this.adv(),s.push({type:"expr",value:h.trim()})}else i+=this.adv();this.ch()!='"'&&this.err("Unterminated string"),this.adv(),s.push({type:"text",value:i}),s.some(n=>n.type=="expr")?this.tok(p.STRING,{template:!0,parts:s},t,e):this.tok(p.STRING,s.map(n=>n.value).join(""),t,e)}scanRegexBody(t,e){let s="",i=!1;for(;this.pos<this.src.length;){let h=this.ch();if(h==`
13
+ `&&this.err("Unterminated regex literal"),h=="\\"){s+=this.adv(),this.pos<this.src.length&&(s+=this.adv());continue}if(h=="["){i=!0,s+=this.adv();continue}if(h=="]"){i=!1,s+=this.adv();continue}if(h=="/"&&!i)break;s+=this.adv()}this.ch()!="/"&&this.err("Unterminated regex literal"),this.adv();let n="";for(;/[gimsuy]/.test(this.ch());)n+=this.adv();this.tok(p.REGEX,{pattern:s,flags:n},t,e)}scanBlockComment(){for(this.adv(),this.adv();this.pos<this.src.length;){if(this.ch()=="*"&&this.ch(1)=="/"){this.adv(),this.adv();return}this.adv()}this.err("Unterminated block comment")}tokenize(){let t=!0;for(;this.pos<this.src.length;){if(t){t=!1;let h=0;for(;this.ch()==" "||this.ch()==" ";)this.ch()==" "?h=h+4:h=h+1,this.adv();if(this.ch()==`
14
+ `||!this.ch()){this.ch()==`
15
+ `&&(this.adv(),t=!0);continue}if(this.ch()=="/"&&this.ch(1)=="/"){for(;this.pos<this.src.length&&this.ch()!=`
16
+ `;)this.adv();this.ch()==`
17
+ `&&(this.adv(),t=!0);continue}if(this.ch()=="/"&&this.ch(1)=="*"){this.scanBlockComment();continue}if(this.ch()=="|"&&this.ch(1)==">"||this.ch()=="."||this.ch()=="?"&&this.ch(1)=="."){let c=this.tokens[this.tokens.length-1];c&&c.type==p.NEWLINE&&this.tokens.pop()}else this.applyIndent(h)}let s=this.line,i=this.col,n=this.ch();if(n==`
18
+ `){if(this.adv(),t=!0,this.nestDepth==0){let h=this.tokens[this.tokens.length-1];h&&h.type!=p.NEWLINE&&h.type!=p.INDENT&&h.type!=p.DEDENT&&this.tok(p.NEWLINE,null,s,i)}continue}if(n==" "||n==" "){this.adv();continue}if(n=="/"&&this.ch(1)=="/"){for(;this.pos<this.src.length&&this.ch()!=`
19
+ `;)this.adv();continue}if(n=="/"&&this.ch(1)=="*"){this.scanBlockComment();continue}if(n>="0"&&n<="9"){if(n=="0"&&(this.ch(1)=="x"||this.ch(1)=="X")){this.adv(),this.adv();let l="";for(;/[0-9a-fA-F_]/.test(this.ch());){let c=this.adv();c!="_"&&(l+=c)}this.tok(p.NUMBER,parseInt(l.length>0?l:"0",16),s,i);continue}if(n=="0"&&(this.ch(1)=="b"||this.ch(1)=="B")){this.adv(),this.adv();let l="";for(;/[01_]/.test(this.ch());){let c=this.adv();c!="_"&&(l+=c)}this.tok(p.NUMBER,parseInt(l.length>0?l:"0",2),s,i);continue}let h="";for(;this.pos<this.src.length&&!(this.ch()=="."&&this.ch(1)==".");)if(this.ch()>="0"&&this.ch()<="9"||this.ch()==".")h+=this.adv();else if(this.ch()=="_")this.adv();else if((this.ch()=="e"||this.ch()=="E")&&h.length>0){for(h+=this.adv(),(this.ch()=="+"||this.ch()=="-")&&(h+=this.adv());this.ch()>="0"&&this.ch()<="9";)h+=this.adv();break}else break;this.tok(p.NUMBER,parseFloat(h),s,i);continue}if(n=='"'){this.scanStr(s,i);continue}if(n=="`"){this.scanBacktick(s,i);continue}if(n=="'"){this.adv();let h="";for(;this.pos<this.src.length&&this.ch()!="'";)if(this.ch()=="\\"){this.adv();let l=this.adv();l=="n"?h+=`
20
+ `:l=="t"?h+=" ":l=="r"?h+="\r":l=="'"?h+="'":l=="\\"?h+="\\":h+="\\"+l}else h+=this.adv();this.ch()!="'"&&this.err("Unterminated string"),this.adv(),this.tok(p.STRING,h,s,i);continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||n=="_"){let h="";for(;/[a-zA-Z0-9_]/.test(this.ch());)h+=this.adv();if(h=="_"&&!/[a-zA-Z0-9_]/.test(this.ch())){this.tok(p.WILDCARD,"_",s,i);continue}let l=Object.prototype.hasOwnProperty.call(Nt,h)?Nt[h]:void 0;l=="__TRUE__"?this.tok(p.BOOL,!0,s,i):l=="__FALSE__"?this.tok(p.BOOL,!1,s,i):l=="__NULL__"?this.tok(p.NULL,null,s,i):l!=null?this.tok(l,h,s,i):this.tok(p.IDENT,h,s,i);continue}if(this.adv(),n=="+")this.ch()=="+"?(this.adv(),this.tok(p.PLUSPLUS,"++",s,i)):this.ch()=="="?(this.adv(),this.tok(p.PLUSEQ,"+=",s,i)):this.tok(p.PLUS,"+",s,i);else if(n=="-")this.ch()=="-"?(this.adv(),this.tok(p.MINUSMINUS,"--",s,i)):this.ch()==">"?(this.adv(),this.tok(p.ARROW,"->",s,i)):this.ch()=="="?(this.adv(),this.tok(p.MINUSEQ,"-=",s,i)):this.tok(p.MINUS,"-",s,i);else if(n=="*")this.ch()=="*"?(this.adv(),this.tok(p.STARSTAR,"**",s,i)):this.ch()=="="?(this.adv(),this.tok(p.STAREQ,"*=",s,i)):this.tok(p.STAR,"*",s,i);else if(n=="/")if(this.ch()=="=")this.adv(),this.tok(p.SLASHEQ,"/=",s,i);else{let h=this.tokens[this.tokens.length-1];h!=null&&(h.type==p.IDENT||h.type==p.NUMBER||h.type==p.STRING||h.type==p.BOOL||h.type==p.NULL||h.type==p.REGEX||h.type==p.RPAREN||h.type==p.RBRACKET||h.type==p.PLUSPLUS||h.type==p.MINUSMINUS||h.type==p.BANG)?this.tok(p.SLASH,"/",s,i):this.scanRegexBody(s,i)}else n=="%"?this.ch()=="="?(this.adv(),this.tok(p.PERCENTEQ,"%=",s,i)):this.tok(p.PERCENT,"%",s,i):n=="="?this.ch()=="="&&this.src[this.pos+1]=="="?(this.adv(),this.adv(),this.tok(p.EQEQEQ,"===",s,i)):this.ch()=="="?(this.adv(),this.tok(p.EQEQ,"==",s,i)):this.ch()==">"?(this.adv(),this.tok(p.FATARROW,"=>",s,i)):this.tok(p.EQ,"=",s,i):n=="!"?this.ch()=="="&&this.src[this.pos+1]=="="?(this.adv(),this.adv(),this.tok(p.NEQEQ,"!==",s,i)):this.ch()=="="?(this.adv(),this.tok(p.NEQ,"!=",s,i)):this.tok(p.BANG,"!",s,i):n=="<"?this.ch()=="<"?(this.adv(),this.tok(p.LSHIFT,"<<",s,i)):this.ch()=="="?(this.adv(),this.tok(p.LTE,"<=",s,i)):this.tok(p.LT,"<",s,i):n==">"?this.ch()==">"?(this.adv(),this.tok(p.RSHIFT,">>",s,i)):this.ch()=="="?(this.adv(),this.tok(p.GTE,">=",s,i)):this.tok(p.GT,">",s,i):n=="."?this.ch()=="."&&this.src[this.pos+1]=="."?(this.adv(),this.adv(),this.tok(p.DOTDOTDOT,"...",s,i)):this.ch()=="."?(this.adv(),this.tok(p.DOTDOT,"..",s,i)):this.tok(p.DOT,".",s,i):n=="?"?this.ch()=="."?(this.adv(),this.tok(p.QUESTIONDOT,"?.",s,i)):this.ch()=="?"?(this.adv(),this.tok(p.NULLISH,"??",s,i)):this.tok(p.QUESTION,"?",s,i):n=="|"?this.ch()==">"?(this.adv(),this.tok(p.PIPE,"|>",s,i)):this.ch()=="|"?(this.adv(),this.tok(p.OROR,"||",s,i)):this.tok(p.PIPEB,"|",s,i):n=="&"?this.ch()=="&"?(this.adv(),this.tok(p.ANDAND,"&&",s,i)):this.tok(p.AMPERSAND,"&",s,i):n=="^"?this.tok(p.CARET,"^",s,i):n=="~"?this.tok(p.TILDE,"~",s,i):n=="@"?this.tok(p.AT,"@",s,i):n=="("?(this.nestDepth=this.nestDepth+1,this.tok(p.LPAREN,"(",s,i)):n==")"?(this.nestDepth=this.nestDepth-1,this.tok(p.RPAREN,")",s,i)):n=="["?(this.nestDepth=this.nestDepth+1,this.tok(p.LBRACKET,"[",s,i)):n=="]"?(this.nestDepth=this.nestDepth-1,this.tok(p.RBRACKET,"]",s,i)):n=="{"?(this.nestDepth=this.nestDepth+1,this.tok(p.LBRACE,"{",s,i)):n=="}"?(this.nestDepth=this.nestDepth-1,this.tok(p.RBRACE,"}",s,i)):n==","?this.tok(p.COMMA,",",s,i):n==":"?this.tok(p.COLON,":",s,i):n!=";"&&this.err(`Unknown character: '${n}'`)}for(;this.indentStack.length>1;)this.indentStack.pop(),this.tok(p.DEDENT,null,this.line,1);let e=this.tokens[this.tokens.length-1];return e&&e.type!=p.NEWLINE&&e.type!=p.DEDENT&&this.tok(p.NEWLINE,null,this.line,this.col),this.tok(p.EOF,null,this.line,this.col),this.tokens}};V.exports.Lexer=J;function Zt(a){let t=a.replace(/\r\n/g,`
8
21
  `).replace(/\r/g,`
9
- `),this.pos=0,this.line=1,this.col=1,this.tokens=[],this.indentStack=[0],this.nestDepth=0}err(t){throw new kt(t,this.line,this.col)}ch(t=0){return this.src[this.pos+t]||""}adv(){let t=this.src[this.pos++];return t===`
10
- `?(this.line++,this.col=1):this.col++,t}tok(t,e,s,r){this.tokens.push({type:t,value:e!==void 0?e:t,line:s||this.line,col:r||this.col})}applyIndent(t){if(this.nestDepth>0)return;let e=this.indentStack[this.indentStack.length-1];if(t>e)this.indentStack.push(t),this.tok(o.INDENT,t,this.line,1);else if(t<e){for(;this.indentStack.length>1&&this.indentStack[this.indentStack.length-1]>t;)this.indentStack.pop(),this.tok(o.DEDENT,null,this.line,1);this.indentStack[this.indentStack.length-1]!==t&&this.err(`Inconsistent indentation (${t} spaces)`)}}scanBacktick(t,e){this.adv();let s="";for(;this.pos<this.src.length&&this.ch()!=="`";)if(this.ch()==="\\"){this.adv();let l=this.adv();s+={n:`
11
- `,t:" ","`":"`","\\":"\\"}[l]||"\\"+l}else s+=this.adv();this.ch()!=="`"&&this.err("Unterminated backtick string"),this.adv();let a=s.split(`
12
- `).map(l=>l.trimEnd());for(;a.length&&!a[0].trim();)a.shift();for(;a.length&&!a[a.length-1].trim();)a.pop();let c=a.filter(l=>l.trim()).reduce((l,p)=>{let m=p.match(/^(\s*)/)[1].length;return Math.min(l,m)},1/0),h=a.map(l=>l.slice(c===1/0?0:c));this.tok(o.STRING,h.join(`
13
- `),t,e)}scanStr(t,e){this.adv();let s=[],r="";for(;this.pos<this.src.length&&this.ch()!=='"';)if(this.ch()==="\\"){this.adv();let a=this.adv();if(a==="u"){let c=this.src.slice(this.pos,this.pos+4);this.pos+=4,r+=String.fromCharCode(parseInt(c,16))}else if(a==="x"){let c=this.src.slice(this.pos,this.pos+2);this.pos+=2,r+=String.fromCharCode(parseInt(c,16))}else r+={n:`
14
- `,t:" ",r:"\r",'"':'"',"'":"'","\\":"\\","{":"{","}":"}"}[a]||"\\"+a}else if(this.ch()==="{"){s.push({type:"text",value:r}),r="",this.adv();let a=1,c="";for(;this.pos<this.src.length&&(this.ch()==="{"&&a++,!(this.ch()==="}"&&(a--,a===0)));)this.ch()==="\\"&&(this.src[this.pos+1]==='"'||this.src[this.pos+1]==="'")?(this.adv(),c+=this.adv()):c+=this.adv();this.ch()!=="}"&&this.err("Unclosed string interpolation"),this.adv(),s.push({type:"expr",value:c.trim()})}else r+=this.adv();this.ch()!=='"'&&this.err("Unterminated string"),this.adv(),s.push({type:"text",value:r}),s.some(a=>a.type==="expr")?this.tok(o.STRING,{template:!0,parts:s},t,e):this.tok(o.STRING,s.map(a=>a.value).join(""),t,e)}scanRegexBody(t,e){let s="",r=!1;for(;this.pos<this.src.length;){let c=this.ch();if(c===`
15
- `&&this.err("Unterminated regex literal"),c==="\\"){s+=this.adv(),this.pos<this.src.length&&(s+=this.adv());continue}if(c==="["){r=!0,s+=this.adv();continue}if(c==="]"){r=!1,s+=this.adv();continue}if(c==="/"&&!r)break;s+=this.adv()}this.ch()!=="/"&&this.err("Unterminated regex literal"),this.adv();let a="";for(;/[gimsuy]/.test(this.ch());)a+=this.adv();this.tok(o.REGEX,{pattern:s,flags:a},t,e)}scanBlockComment(){for(this.adv(),this.adv();this.pos<this.src.length;){if(this.ch()==="*"&&this.ch(1)==="/"){this.adv(),this.adv();return}this.adv()}this.err("Unterminated block comment")}tokenize(){let t=!0;for(;this.pos<this.src.length;){if(t){t=!1;let c=0;for(;this.ch()===" "||this.ch()===" ";)c+=this.ch()===" "?4:1,this.adv();if(this.ch()===`
16
- `||!this.ch()){this.ch()===`
17
- `&&(this.adv(),t=!0);continue}if(this.ch()==="/"&&this.ch(1)==="/"){for(;this.pos<this.src.length&&this.ch()!==`
18
- `;)this.adv();this.ch()===`
19
- `&&(this.adv(),t=!0);continue}if(this.ch()==="/"&&this.ch(1)==="*"){this.scanBlockComment();continue}if(this.ch()==="|"&&this.ch(1)===">"||this.ch()==="."||this.ch()==="?"&&this.ch(1)==="."){let l=this.tokens[this.tokens.length-1];l&&l.type===o.NEWLINE&&this.tokens.pop()}else this.applyIndent(c)}let s=this.line,r=this.col,a=this.ch();if(a===`
20
- `){if(this.adv(),t=!0,this.nestDepth===0){let c=this.tokens[this.tokens.length-1];c&&c.type!==o.NEWLINE&&c.type!==o.INDENT&&c.type!==o.DEDENT&&this.tok(o.NEWLINE,null,s,r)}continue}if(a===" "||a===" "){this.adv();continue}if(a==="/"&&this.ch(1)==="/"){for(;this.pos<this.src.length&&this.ch()!==`
21
- `;)this.adv();continue}if(a==="/"&&this.ch(1)==="*"){this.scanBlockComment();continue}if(a>="0"&&a<="9"){if(a==="0"&&(this.ch(1)==="x"||this.ch(1)==="X")){this.adv(),this.adv();let h="";for(;/[0-9a-fA-F_]/.test(this.ch());){let l=this.adv();l!=="_"&&(h+=l)}this.tok(o.NUMBER,parseInt(h||"0",16),s,r);continue}if(a==="0"&&(this.ch(1)==="b"||this.ch(1)==="B")){this.adv(),this.adv();let h="";for(;/[01_]/.test(this.ch());){let l=this.adv();l!=="_"&&(h+=l)}this.tok(o.NUMBER,parseInt(h||"0",2),s,r);continue}let c="";for(;this.pos<this.src.length&&!(this.ch()==="."&&this.ch(1)===".");)if(this.ch()>="0"&&this.ch()<="9"||this.ch()===".")c+=this.adv();else if(this.ch()==="_")this.adv();else if((this.ch()==="e"||this.ch()==="E")&&c.length>0){for(c+=this.adv(),(this.ch()==="+"||this.ch()==="-")&&(c+=this.adv());this.ch()>="0"&&this.ch()<="9";)c+=this.adv();break}else break;this.tok(o.NUMBER,parseFloat(c),s,r);continue}if(a==='"'){this.scanStr(s,r);continue}if(a==="`"){this.scanBacktick(s,r);continue}if(a==="'"){this.adv();let c="";for(;this.pos<this.src.length&&this.ch()!=="'";)if(this.ch()==="\\"){this.adv();let h=this.adv();if(h==="u"){let l=this.src.slice(this.pos,this.pos+4);this.pos+=4,c+=String.fromCharCode(parseInt(l,16))}else if(h==="x"){let l=this.src.slice(this.pos,this.pos+2);this.pos+=2,c+=String.fromCharCode(parseInt(l,16))}else c+={n:`
22
- `,t:" ",r:"\r","'":"'","\\":"\\"}[h]||"\\"+h}else c+=this.adv();this.ch()!=="'"&&this.err("Unterminated string"),this.adv(),this.tok(o.STRING,c,s,r);continue}if(a>="a"&&a<="z"||a>="A"&&a<="Z"||a==="_"){let c="";for(;/[a-zA-Z0-9_]/.test(this.ch());)c+=this.adv();if(c==="_"&&!/[a-zA-Z0-9_]/.test(this.ch())){this.tok(o.WILDCARD,"_",s,r);continue}let h=Object.prototype.hasOwnProperty.call(Lt,c)?Lt[c]:void 0;h==="__TRUE__"?this.tok(o.BOOL,!0,s,r):h==="__FALSE__"?this.tok(o.BOOL,!1,s,r):h==="__NULL__"?this.tok(o.NULL,null,s,r):h?this.tok(h,c,s,r):this.tok(o.IDENT,c,s,r);continue}switch(this.adv(),a){case"+":this.ch()==="+"?(this.adv(),this.tok(o.PLUSPLUS,"++",s,r)):this.ch()==="="?(this.adv(),this.tok(o.PLUSEQ,"+=",s,r)):this.tok(o.PLUS,"+",s,r);break;case"-":this.ch()==="-"?(this.adv(),this.tok(o.MINUSMINUS,"--",s,r)):this.ch()===">"?(this.adv(),this.tok(o.ARROW,"->",s,r)):this.ch()==="="?(this.adv(),this.tok(o.MINUSEQ,"-=",s,r)):this.tok(o.MINUS,"-",s,r);break;case"*":this.ch()==="*"?(this.adv(),this.tok(o.STARSTAR,"**",s,r)):this.ch()==="="?(this.adv(),this.tok(o.STAREQ,"*=",s,r)):this.tok(o.STAR,"*",s,r);break;case"/":if(this.ch()==="=")this.adv(),this.tok(o.SLASHEQ,"/=",s,r);else{let c=this.tokens[this.tokens.length-1];c&&(c.type===o.IDENT||c.type===o.NUMBER||c.type===o.STRING||c.type===o.BOOL||c.type===o.NULL||c.type===o.REGEX||c.type===o.RPAREN||c.type===o.RBRACKET||c.type===o.PLUSPLUS||c.type===o.MINUSMINUS||c.type===o.BANG)?this.tok(o.SLASH,"/",s,r):this.scanRegexBody(s,r)}break;case"%":this.ch()==="="?(this.adv(),this.tok(o.PERCENTEQ,"%=",s,r)):this.tok(o.PERCENT,"%",s,r);break;case"=":this.ch()==="="&&this.ch(1)==="="?(this.adv(),this.adv(),this.tok(o.EQEQEQ,"===",s,r)):this.ch()==="="?(this.adv(),this.tok(o.EQEQ,"==",s,r)):this.ch()===">"?(this.adv(),this.tok(o.FATARROW,"=>",s,r)):this.tok(o.EQ,"=",s,r);break;case"!":this.ch()==="="&&this.ch(1)==="="?(this.adv(),this.adv(),this.tok(o.NEQEQ,"!==",s,r)):this.ch()==="="?(this.adv(),this.tok(o.NEQ,"!=",s,r)):this.tok(o.BANG,"!",s,r);break;case"<":this.ch()==="<"?(this.adv(),this.tok(o.LSHIFT,"<<",s,r)):this.ch()==="="?(this.adv(),this.tok(o.LTE,"<=",s,r)):this.tok(o.LT,"<",s,r);break;case">":this.ch()===">"?(this.adv(),this.tok(o.RSHIFT,">>",s,r)):this.ch()==="="?(this.adv(),this.tok(o.GTE,">=",s,r)):this.tok(o.GT,">",s,r);break;case".":this.ch()==="."&&this.ch(1)==="."?(this.adv(),this.adv(),this.tok(o.DOTDOTDOT,"...",s,r)):this.ch()==="."?(this.adv(),this.tok(o.DOTDOT,"..",s,r)):this.tok(o.DOT,".",s,r);break;case"?":this.ch()==="."?(this.adv(),this.tok(o.QUESTIONDOT,"?.",s,r)):this.ch()==="?"?(this.adv(),this.tok(o.NULLISH,"??",s,r)):this.tok(o.QUESTION,"?",s,r);break;case"|":this.ch()===">"?(this.adv(),this.tok(o.PIPE,"|>",s,r)):this.ch()==="|"?(this.adv(),this.tok(o.OROR,"||",s,r)):this.tok(o.PIPEB,"|",s,r);break;case"&":this.ch()==="&"?(this.adv(),this.tok(o.ANDAND,"&&",s,r)):this.tok(o.AMPERSAND,"&",s,r);break;case"^":this.tok(o.CARET,"^",s,r);break;case"~":this.tok(o.TILDE,"~",s,r);break;case"@":this.tok(o.AT,"@",s,r);break;case";":break;case"(":this.nestDepth++,this.tok(o.LPAREN,"(",s,r);break;case")":this.nestDepth--,this.tok(o.RPAREN,")",s,r);break;case"[":this.nestDepth++,this.tok(o.LBRACKET,"[",s,r);break;case"]":this.nestDepth--,this.tok(o.RBRACKET,"]",s,r);break;case"{":this.nestDepth++,this.tok(o.LBRACE,"{",s,r);break;case"}":this.nestDepth--,this.tok(o.RBRACE,"}",s,r);break;case",":this.tok(o.COMMA,",",s,r);break;case":":this.tok(o.COLON,":",s,r);break;default:this.err(`Unknown character: '${a}'`)}}for(;this.indentStack.length>1;)this.indentStack.pop(),this.tok(o.DEDENT,null,this.line,1);let e=this.tokens[this.tokens.length-1];return e&&e.type!==o.NEWLINE&&e.type!==o.DEDENT&&this.tok(o.NEWLINE,null,this.line,this.col),this.tok(o.EOF,null,this.line,this.col),this.tokens}};Ct.exports={Lexer:Et,T:o,TokenType:o}});var et=_((bs,jt)=>{"use strict";var{T:i}=J(),Ft={COLON:'":"',COMMA:'","',DOT:'"."',LPAREN:'"("',RPAREN:'")"',LBRACKET:'"["',RBRACKET:'"]"',LBRACE:'"{"',RBRACE:'"}"',ARROW:'"->"',FATARROW:'"=>"',EQ:'"="',EQEQ:'"=="',NEQ:'"!="',PLUS:'"+"',MINUS:'"-"',STAR:'"*"',SLASH:'"/"',PERCENT:'"%"',STARSTAR:'"**"',LT:'"<"',GT:'">"',LTE:'"<="',GTE:'">="',PIPE:'"|>"',PIPEB:'"|"',DOTDOT:'".."',DOTDOTDOT:'"..."',QUESTION:'"?"',BANG:'"!"',NEWLINE:"end of line",INDENT:"indented block",DEDENT:"end of block",EOF:"end of file",IDENT:"identifier",NUMBER:"number",STRING:"string",BOOL:"true/false",NULL:"null",FN:'"fn"',VAL:'"val"',VAR:'"var"',IF:'"if"',ELSE:'"else"',FOR:'"for"',WHILE:'"while"',IN:'"in"',RETURN:'"return"',CLASS:'"class"',NEW:'"new"',SELF:'"self"',IMPORT:'"import"',FROM:'"from"',EXPORT:'"export"',MATCH:'"match"',WHEN:'"when"',AND:'"and"',OR:'"or"',NOT:'"not"',ASYNC:'"async"',AWAIT:'"await"',TRY:'"try"',CATCH:'"catch"',FINALLY:'"finally"',THROW:'"throw"'};function Bt(n,t){return Ft[n]?Ft[n]:t!=null&&t!==n?`"${t}"`:`"${n.toLowerCase()}"`}var z=class extends Error{constructor(t,e){super(t),this.name="ParseError",this.tok=e,this.line=e?e.line:null,this.col=e?e.col:null}},Ne=["val","var","fn","return","if","else","for","in","while","do","break","continue","match","when","class","extends","self","new","interface","implements","import","export","from","as","default","and","or","not","async","await","try","catch","finally","throw","type","enum","static","abstract","override","readonly","private","public","protected","true","false","null"],Pt={function:{fix:"fn",note:'Flux uses "fn" instead of "function"'},func:{fix:"fn",note:'Flux uses "fn" for functions'},def:{fix:"fn",note:'Flux uses "fn" for functions (not "def" like Python)'},const:{fix:"val",note:'Flux uses "val" for immutable bindings (not "const")'},let:{fix:"var",note:'Flux uses "var" for mutable bindings (not "let")'},elif:{fix:"else if",note:'Flux uses "else if" (not "elif" like Python)'},elsif:{fix:"else if",note:'Flux uses "else if" (not "elsif")'},elseif:{fix:"else if",note:'Flux uses "else if" as two separate keywords'},switch:{fix:"match",note:'Flux uses "match/when" instead of "switch/case"'},case:{fix:"when",note:'Flux uses "when" inside a "match" block'},foreach:{fix:"for ... in",note:'Flux uses "for item in collection:" syntax'},forEach:{fix:"for ... in",note:'Flux uses "for item in collection:" syntax'},lambda:{fix:"fn",note:'Flux uses "fn" or the "->" arrow for inline functions'},struct:{fix:"class",note:'Flux uses "class" for data types (no structs)'},interface:null,print:null,Fn:{fix:"fn",note:"Flux keywords are lowercase"},FN:{fix:"fn",note:"Flux keywords are lowercase"},Val:{fix:"val",note:"Flux keywords are lowercase"},Var:{fix:"var",note:"Flux keywords are lowercase"},If:{fix:"if",note:"Flux keywords are lowercase"},Else:{fix:"else",note:"Flux keywords are lowercase"},For:{fix:"for",note:"Flux keywords are lowercase"},While:{fix:"while",note:"Flux keywords are lowercase"},Return:{fix:"return",note:"Flux keywords are lowercase"},Class:{fix:"class",note:"Flux keywords are lowercase"},Import:{fix:"import",note:"Flux keywords are lowercase"},Export:{fix:"export",note:"Flux keywords are lowercase"},New:{fix:"new",note:"Flux keywords are lowercase"},True:{fix:"true",note:"Flux keywords are lowercase"},False:{fix:"false",note:"Flux keywords are lowercase"},Null:{fix:"null",note:"Flux keywords are lowercase"},Async:{fix:"async",note:"Flux keywords are lowercase"},Await:{fix:"await",note:"Flux keywords are lowercase"},Match:{fix:"match",note:"Flux keywords are lowercase"},Try:{fix:"try",note:"Flux keywords are lowercase"},Catch:{fix:"catch",note:"Flux keywords are lowercase"}};function we(n,t,e=2){if(Math.abs(n.length-t.length)>e)return e+1;let s=n.length,r=t.length,a=new Uint8Array(r+1),c=new Uint8Array(r+1);for(let h=0;h<=r;h++)a[h]=h;for(let h=1;h<=s;h++){c[0]=h;let l=h;for(let p=1;p<=r;p++){let m=n[h-1]===t[p-1]?0:1;c[p]=Math.min(c[p-1]+1,a[p]+1,a[p-1]+m),c[p]<l&&(l=c[p])}if(l>e)return e+1;c.copyWithin(0,0,r+1),a.set(c)}return a[r]}function Mt(n){if(!n||n.length<2)return null;if(Object.prototype.hasOwnProperty.call(Pt,n)){let s=Pt[n];return s?`Did you mean "${s.fix}"? ${s.note}`:null}let t=3,e=null;for(let s of Ne){if(Math.abs(n.length-s.length)>2)continue;let r=we(n.toLowerCase(),s,2);r<t&&(t=r,e=s)}return e&&t<=2&&n!==e?`Did you mean "${e}"?`:null}var dt=class{constructor(t){this.tokens=t,this.pos=0}peek(t=0){return this.tokens[this.pos+t]||{type:i.EOF,value:null,line:0,col:0}}check(t){return this.peek().type===t}at(...t){return t.includes(this.peek().type)}eat(t){let e=this.peek();if(e.type!==t){let s=Bt(t,null),r=Bt(e.type,e.value),a=new z(`Expected ${s} but got ${r}`,e);if(e.type===i.IDENT){let c=Mt(e.value);c&&(a.hint=c)}throw a}return this.pos++,e}maybe(t){return this.check(t)?(this.pos++,!0):!1}skip(){return this.tokens[this.pos++]}skipNewlines(){for(;this.check(i.NEWLINE);)this.pos++}err(t){throw new z(t,this.peek())}parseBlock(){if(this.eat(i.COLON),this.check(i.NEWLINE)){this.pos++,this.eat(i.INDENT);let e=this.parseStmtList(()=>this.check(i.DEDENT)||this.check(i.EOF));return this.maybe(i.DEDENT),e}return[this.parseOneStmt()]}parseIndentedBlock(){this.eat(i.NEWLINE),this.eat(i.INDENT);let t=this.parseStmtList(()=>this.check(i.DEDENT)||this.check(i.EOF));return this.maybe(i.DEDENT),t}parse(){return this.skipNewlines(),{type:"Program",body:this.parseStmtList(()=>this.check(i.EOF))}}parseStmtList(t){let e=[];for(;!t()&&(this.skipNewlines(),!t());)e.push(this.parseOneStmt());return e}parseDecorators(){let t=[];for(;this.check(i.AT);){let e=this.skip(),s=this.eat(i.IDENT).value,r=[];if(this.check(i.LPAREN)){for(this.pos++;!this.check(i.RPAREN)&&!this.check(i.EOF)&&(r.push(this.parseExpr()),!!this.maybe(i.COMMA)););this.eat(i.RPAREN)}t.push({name:s,args:r,loc:e}),this.skipNewlines()}return t}parseOneStmt(){let t=this.check(i.AT)?this.parseDecorators():[],e=this.peek();switch(e.type){case i.VAR:case i.VAL:return this.parseVarDecl();case i.FN:{let s=this.parseFnDecl();return t.length&&(s.decorators=t),s}case i.ASYNC:{let s=this.parseAsyncFn();return t.length&&(s.decorators=t),s}case i.CLASS:{let s=this.parseClassDecl();return t.length&&(s.decorators=t),s}case i.DECLARE:return this.parseDeclareDecl();case i.IF:return this.parseIf();case i.FOR:return this.parseFor();case i.WHILE:return this.parseWhile();case i.DO:return this.parseDoWhile();case i.MATCH:return this.parseMatch();case i.RETURN:return this.parseReturn();case i.BREAK:{this.skip();let s=!this.check(i.NEWLINE)&&!this.check(i.EOF)&&this.check(i.IDENT)?this.skip().value:null;return this.skipNewlines(),{type:"BreakStmt",label:s,loc:e}}case i.CONTINUE:{this.skip();let s=!this.check(i.NEWLINE)&&!this.check(i.EOF)&&this.check(i.IDENT)?this.skip().value:null;return this.skipNewlines(),{type:"ContinueStmt",label:s,loc:e}}case i.IMPORT:return this.parseImport();case i.EXPORT:return this.parseExport();case i.TRY:return this.parseTryCatch();case i.THROW:return this.parseThrow();case i.TYPE:return this.parseTypeDecl();case i.INTERFACE:return this.parseInterfaceDecl();case i.ENUM:return this.parseEnumDecl();default:{let s={[i.CONST]:{msg:'"const" is not a Flux keyword',hint:'Did you mean "val"? Flux uses "val" for immutable bindings (not "const")'},[i.TYPEOF]:{msg:'"typeof" is an expression, not a statement'},[i.INSTANCEOF]:{msg:'"instanceof" is an expression, not a statement'},[i.SATISFIES]:{msg:'"satisfies" is a type expression, not a statement'}};if(Object.prototype.hasOwnProperty.call(s,e.type)){let r=s[e.type],a=new z(r.msg,e);throw r.hint&&(a.hint=r.hint),a}if(e.type===i.IDENT&&this.peek(1).type===i.COLON){let r=this.peek(2).type;if(r===i.FOR||r===i.WHILE){let a=this.skip().value;this.pos++;let c=this.parseOneStmt();return{type:"LabeledStmt",label:a,body:c,loc:e}}}if(e.type===i.IDENT){let r=this.peek(1).type;if(!(r===i.DOT||r===i.LPAREN||r===i.LBRACKET||r===i.EQ||r===i.PLUSEQ||r===i.MINUSEQ||r===i.STAREQ||r===i.SLASHEQ||r===i.PERCENTEQ||r===i.ARROW||r===i.FATARROW||r===i.QUESTION||r===i.EQEQ||r===i.NEQ||r===i.AND||r===i.OR||r===i.PIPE)){let c=Mt(e.value);if(c){let h=new z(`Unexpected identifier "${e.value}"`,e);throw h.hint=c,h}}}return this.parseExprStmt()}}}parseVarDecl(){let t=this.peek().type===i.VAR?"var":"val",e=this.skip();if(this.check(i.LBRACE)){let c=this.parseObjectDestructurePattern();this.eat(i.EQ);let h=this.parseExpr();return this.skipNewlines(),{type:"DestructureDecl",kind:t,patternType:"object",pattern:c,init:h,loc:e}}if(this.check(i.LBRACKET)){let c=this.parseArrayDestructurePattern();this.eat(i.EQ);let h=this.parseExpr();return this.skipNewlines(),{type:"DestructureDecl",kind:t,patternType:"array",pattern:c,init:h,loc:e}}let s=this.eat(i.IDENT).value,r=null;this.maybe(i.COLON)&&(r=this.parseTypeAnn());let a=null;return this.maybe(i.EQ)&&(a=this.parseExpr()),this.skipNewlines(),{type:"VarDecl",kind:t,name:s,typeAnn:r,init:a,loc:e}}parseObjectDestructurePattern(){this.eat(i.LBRACE);let t=[];for(;!this.check(i.RBRACE)&&!this.check(i.EOF);){let e=!1;this.check(i.DOTDOTDOT)&&(this.pos++,e=!0);let s=this.eat(i.IDENT).value;if(e){t.push({key:s,alias:s,rest:!0});break}let r=s;this.maybe(i.COLON)&&(r=this.eat(i.IDENT).value);let a=null;if(this.maybe(i.EQ)&&(a=this.parseExpr()),t.push({key:s,alias:r,defaultVal:a,rest:!1}),!this.maybe(i.COMMA))break}return this.eat(i.RBRACE),t}parseArrayDestructurePattern(){this.eat(i.LBRACKET);let t=[];for(;!this.check(i.RBRACKET)&&!this.check(i.EOF);){if(this.check(i.COMMA)){t.push(null),this.pos++;continue}let e=!1;this.check(i.DOTDOTDOT)&&(this.pos++,e=!0);let s=this.eat(i.IDENT).value,r=null;if(this.maybe(i.EQ)&&(r=this.parseExpr()),t.push({name:s,defaultVal:r,rest:e}),e||!this.maybe(i.COMMA))break}return this.eat(i.RBRACKET),t}parseTypeAnn(){let t=this._parseIntersectionType();for(;this.check(i.PIPEB);)this.pos++,t+=" | "+this._parseIntersectionType();return t}_parseIntersectionType(){let t=this._parseSingleType();for(;this.check(i.AMPERSAND);)this.pos++,t+=" & "+this._parseSingleType();return t}_parseSingleType(){let t=this.peek();if(t.type===i.LBRACKET){this.pos++;let s=[];for(;!this.check(i.RBRACKET)&&!this.check(i.EOF)&&(s.push(this.parseTypeAnn()),!!this.maybe(i.COMMA)););return this.eat(i.RBRACKET),"["+s.join(", ")+"]"}if(t.type===i.LBRACE){this.pos++;let s=[];for(;!this.check(i.RBRACE)&&!this.check(i.EOF);){let r=!1;if(this.check(i.READONLY)&&(this.pos++,r=!0),this.check(i.LBRACKET)){this.pos++;let a=this.eat(i.IDENT).value;this.eat(i.COLON);let c=this.parseTypeAnn();this.eat(i.RBRACKET),this.eat(i.COLON);let h=this.parseTypeAnn();s.push(`[${a}: ${c}]: ${h}`)}else{let a=this.at(i.IDENT,i.STRING)?this.skip().value:this.eat(i.IDENT).value,c=!1;this.check(i.QUESTION)&&(this.pos++,c=!0),this.eat(i.COLON);let h=this.parseTypeAnn(),l=r?"readonly ":"";s.push(`${l}${a}${c?"?":""}: ${h}`)}this.maybe(i.COMMA)}return this.eat(i.RBRACE),"{ "+s.join(", ")+" }"}if(t.type===i.LPAREN){this.pos++;let s=this.parseTypeAnn();return this.eat(i.RPAREN),"("+s+")"}if(t.type===i.IDENT&&t.value==="keyof")return this.pos++,"keyof "+this._parseSingleType();if(t.type===i.TYPEOF)return this.pos++,"typeof "+this.eat(i.IDENT).value;if(t.type===i.READONLY)return this.pos++,"readonly "+this._parseSingleType();if(t.type===i.IDENT&&t.value==="infer")return this.pos++,"infer "+this.eat(i.IDENT).value;if(t.type===i.FN){this.pos++;let s=[];if(this.check(i.LPAREN)){for(this.pos++;!this.check(i.RPAREN)&&!this.check(i.EOF);){let a;if(this.check(i.IDENT)&&this.peek(1).type===i.COLON?(this.pos+=2,a=this.parseTypeAnn()):a=this.parseTypeAnn(),s.push(a),!this.maybe(i.COMMA))break}this.eat(i.RPAREN)}let r="Void";return this.check(i.ARROW)&&(this.pos++,r=this.parseTypeAnn()),`fn(${s.join(", ")}) -> ${r}`}let e;if(t.type===i.IDENT||t.type===i.CONST||t.type===i.TYPE?e=this.skip().value:e=this.eat(i.IDENT).value,this.check(i.EXTENDS)){this.pos++;let s=this._parseSingleType();this.eat(i.QUESTION);let r=this.parseTypeAnn();this.eat(i.COLON);let a=this.parseTypeAnn();return`${e} extends ${s} ? ${r} : ${a}`}if(this.check(i.LT)){this.pos++;let s=[this._parseGenericArg()];for(;this.maybe(i.COMMA);)s.push(this._parseGenericArg());this.eat(i.GT),e+="<"+s.join(", ")+">"}for(;this.check(i.LBRACKET)&&this.peek(1).type===i.RBRACKET;)this.pos+=2,e+="[]";return this.check(i.QUESTION)&&this.peek(1).type!==i.DOT&&(this.pos++,e+="?"),e}_parseGenericArg(){return this.parseTypeAnn()}_isTypeAnnBeforeColon(){let t=s=>this.tokens[this.pos+s]||{type:i.EOF},e=0;if(t(e).type===i.LBRACKET||t(e).type===i.LBRACE||t(e).type===i.LPAREN){let s=0,r=new Set([i.LBRACKET,i.LBRACE,i.LPAREN,i.LT]),a=new Set([i.RBRACKET,i.RBRACE,i.RPAREN,i.GT]);for(;t(e).type!==i.EOF&&(r.has(t(e).type)&&s++,a.has(t(e).type)&&s--,e++,s!==0););for(t(e).type===i.QUESTION&&e++;t(e).type===i.PIPEB||t(e).type===i.AMPERSAND;){if(e++,t(e).type!==i.IDENT)return!1;e++}return t(e).type===i.COLON}if((t(e).type===i.TYPEOF||t(e).type===i.READONLY||t(e).type===i.IDENT&&(t(e).value==="keyof"||t(e).value==="readonly"))&&e++,t(e).type!==i.IDENT)return!1;if(e++,t(e).type===i.LT){e++;let s=1;for(;t(e).type!==i.EOF&&s>0;)t(e).type===i.LT&&s++,t(e).type===i.GT&&s--,e++}for(;t(e).type===i.LBRACKET&&t(e+1).type===i.RBRACKET;)e+=2;for(t(e).type===i.QUESTION&&e++;t(e).type===i.PIPEB;){if(e++,t(e).type!==i.IDENT)return!1;if(e++,t(e).type===i.LT){e++;let s=1;for(;t(e).type!==i.EOF&&s>0;)t(e).type===i.LT&&s++,t(e).type===i.GT&&s--,e++}for(;t(e).type===i.LBRACKET&&t(e+1).type===i.RBRACKET;)e+=2;t(e).type===i.QUESTION&&e++}return t(e).type===i.COLON}parseTypeDecl(){let t=this.eat(i.TYPE),e=this.eat(i.IDENT).value,s=[];if(this.check(i.LT)){for(this.pos++;!this.check(i.GT)&&!this.check(i.EOF)&&(s.push(this.eat(i.IDENT).value),!!this.maybe(i.COMMA)););this.eat(i.GT)}this.eat(i.EQ);let r=[];for(;;){let a=this.eat(i.IDENT).value,c=[],h={};if(this.check(i.LPAREN)){for(this.eat(i.LPAREN);!this.check(i.RPAREN)&&!this.check(i.EOF);){let l=this.peek(),p;if(l.type===i.IDENT||l.type in i?p=this.skip().value:this.err(`Expected field name, got '${l.type}'`),this.maybe(i.COLON)&&(h[p]=this.parseTypeAnn()),c.push(p),!this.maybe(i.COMMA))break}this.eat(i.RPAREN)}if(r.push({name:a,fields:c,fieldTypes:h}),!this.check(i.PIPEB))break;this.pos++}return this.skipNewlines(),{type:"TypeDecl",name:e,variants:r,loc:t}}_isColonReturnType(){let t=this.pos;try{return this.pos++,this.at(i.IDENT,i.LBRACKET,i.LBRACE,i.LPAREN,i.FN,i.READONLY,i.TYPEOF)?(this.parseTypeAnn(),this.check(i.NEWLINE)||this.check(i.EOF)):!1}catch{return!1}finally{this.pos=t}}parseFnDecl(t=!1){let e=this.eat(i.FN),s=new Set([i.NEW,i.DELETE,i.FROM,i.AS,i.DEFAULT,i.IS,i.IN,i.TYPE]),r=this.check(i.IDENT)||s.has(this.peek().type)?this.skip().value:null,a=this.parseParamList(),c=null;if(this.check(i.ARROW))if(this.pos++,this._isTypeAnnBeforeColon()){c=this.parseTypeAnn();let h=this.parseBlock();return{type:"FnDecl",name:r,params:a,retType:c,body:h,inline:!1,async:t,loc:e}}else{let h=this.parseExpr();return this.skipNewlines(),{type:"FnDecl",name:r,params:a,retType:null,body:h,inline:!0,async:t,loc:e}}if(this.check(i.COLON)){if(this._isColonReturnType()){if(this.pos++,c=this.parseTypeAnn(),this.check(i.NEWLINE)&&this.pos++,this.check(i.INDENT)){this.pos++;let p=this.parseStmtList(()=>this.check(i.DEDENT)||this.check(i.EOF));return this.maybe(i.DEDENT),{type:"FnDecl",name:r,params:a,retType:c,body:p,inline:!1,async:t,loc:e}}let l=this.parseOneStmt();return{type:"FnDecl",name:r,params:a,retType:c,body:[l],inline:!1,async:t,loc:e}}let h=this.parseBlock();return{type:"FnDecl",name:r,params:a,retType:null,body:h,inline:!1,async:t,loc:e}}this.err("Expected -> or : after function signature")}parseDeclareDecl(){let t=this.eat(i.DECLARE),e=this.peek();if(e.type===i.FN||e.type===i.ASYNC){let s=e.type===i.ASYNC;this.skip(),s&&this.eat(i.FN);let r=new Set([i.NEW,i.DELETE,i.FROM,i.AS,i.DEFAULT,i.IS,i.IN,i.TYPE]),a=this.check(i.IDENT)||r.has(this.peek().type)?this.skip().value:null,c=this.parseParamList(),h=null;return this.check(i.ARROW)?(this.pos++,h=this.parseTypeAnn()):this.check(i.COLON)&&(this.pos++,h=this.parseTypeAnn()),this.skipNewlines(),{type:"DeclareDecl",decl:{type:"FnDecl",name:a,params:c,retType:h,body:[],inline:!1,async:s,loc:e},loc:t}}if(e.type===i.VAL||e.type===i.VAR){let s=e.type===i.VAR?"var":"val";this.skip();let r=this.eat(i.IDENT).value,a=null;return this.maybe(i.COLON)&&(a=this.parseTypeAnn()),this.skipNewlines(),{type:"DeclareDecl",decl:{type:"VarDecl",kind:s,name:r,typeAnn:a,init:null,loc:e},loc:t}}if(e.type===i.CLASS){this.skip();let s=this.eat(i.IDENT).value;return this.skipNewlines(),{type:"DeclareDecl",decl:{type:"ClassDecl",name:s,fields:[],methods:[],loc:e},loc:t}}this.err("Expected fn, async fn, val, var, or class after declare")}parseAsyncFn(){return this.eat(i.ASYNC),this.check(i.FN)||this.err("Expected fn after async"),this.parseFnDecl(!0)}parseParamList(){this.eat(i.LPAREN);let t=[];for(;!this.check(i.RPAREN)&&!this.check(i.EOF);){let e=!1;this.check(i.DOTDOTDOT)&&(this.pos++,e=!0);let s=this.eat(i.IDENT).value,r=!1,a=null;!e&&this.check(i.QUESTION)&&(this.pos++,r=!0),!e&&this.maybe(i.COLON)&&(a=this.parseTypeAnn());let c=null;if(!e&&this.maybe(i.EQ)&&(c=this.parseExpr()),t.push({name:s,typeAnn:a,optional:r,defaultVal:c,rest:e}),e||!this.maybe(i.COMMA))break}return this.eat(i.RPAREN),t}parseAccessModifiers(){let t=new Set,e=new Set([i.PRIVATE,i.PUBLIC,i.PROTECTED,i.READONLY,i.STATIC,i.ABSTRACT,i.OVERRIDE]);for(;e.has(this.peek().type);)t.add(this.skip().value);return t}parseClassDecl(){let t=this.eat(i.CLASS),e=this.eat(i.IDENT).value,s=null,r=[],a=[];if(this.check(i.LT)){for(this.pos++,a.push(this.eat(i.IDENT).value);this.maybe(i.COMMA);)a.push(this.eat(i.IDENT).value);this.eat(i.GT)}if(this.maybe(i.EXTENDS)&&(s=this.eat(i.IDENT).value),this.maybe(i.IMPLEMENTS))for(r.push(this.eat(i.IDENT).value);this.maybe(i.COMMA);)r.push(this.eat(i.IDENT).value);this.eat(i.COLON),this.check(i.NEWLINE)&&(this.pos++,this.eat(i.INDENT));let c=[],h=[];for(;!this.check(i.DEDENT)&&!this.check(i.EOF)&&(this.skipNewlines(),!(this.check(i.DEDENT)||this.check(i.EOF)));){let l=this.parseAccessModifiers(),p=this.check(i.IDENT)&&(this.peek().value==="get"||this.peek().value==="set")&&(this.peek(1).type===i.IDENT||this.peek(1).type===i.FN),m=this.check(i.FN)&&this.peek(1).type===i.IDENT&&(this.peek(1).value==="get"||this.peek(1).value==="set")&&this.peek(2).type===i.IDENT;if(p&&this.peek(1).type!==i.FN){let y=this.peek(),u=this.skip().value,d=this.eat(i.IDENT).value,g=this.parseParamList(),f=null;this.check(i.ARROW)?(this.pos++,this._isTypeAnnBeforeColon()&&(f=this.parseTypeAnn())):this.check(i.COLON)&&this._isColonReturnType()&&(this.pos++,f=this.parseTypeAnn());let T=this.parseBlock(),b={type:"FnDecl",name:d,params:g,retType:f,body:T,inline:!1,async:!1,modifiers:l,getset:u,loc:y};h.push(b)}else if(this.check(i.FN)){let y=this.parseFnDecl();y.modifiers=l,h.push(y)}else if(this.check(i.ASYNC)){let y=this.parseAsyncFn();y.modifiers=l,h.push(y)}else if(this.check(i.STATIC)&&(this.peek(1).type===i.FN||this.peek(1).type===i.ASYNC)){this.skip();let y=this.check(i.ASYNC)?this.parseAsyncFn():this.parseFnDecl();y.modifiers=l,y.modifiers.add("static"),h.push(y)}else if(this.check(i.VAR)||this.check(i.VAL)){let y=this.skip().type===i.VAR?"var":"val",u=this.eat(i.IDENT).value,d=!1,g=null;this.check(i.QUESTION)&&(this.pos++,d=!0),this.check(i.COLON)&&(this.pos++,g=this.parseTypeAnn());let f=null;this.check(i.EQ)&&(this.pos++,f=this.parseExpr()),this.skipNewlines(),c.push({name:u,typeAnn:g,optional:d,modifiers:l,init:f,fieldKind:y})}else if(this.check(i.IDENT)){let y=this.eat(i.IDENT).value,u=!1;this.check(i.QUESTION)&&(this.pos++,u=!0),this.eat(i.COLON);let d=this.parseTypeAnn();this.skipNewlines(),c.push({name:y,typeAnn:d,optional:u,modifiers:l,init:null})}else this.skip()}return this.maybe(i.DEDENT),{type:"ClassDecl",name:e,typeParams:a,superClass:s,interfaces:r,fields:c,methods:h,loc:t}}parseInterfaceDecl(){let t=this.eat(i.INTERFACE),e=this.eat(i.IDENT).value,s=[];if(this.check(i.LT)){for(this.pos++,s.push(this.eat(i.IDENT).value);this.maybe(i.COMMA);)s.push(this.eat(i.IDENT).value);this.eat(i.GT)}let r=[];if(this.maybe(i.EXTENDS))for(r.push(this.eat(i.IDENT).value);this.maybe(i.COMMA);)r.push(this.eat(i.IDENT).value);this.eat(i.COLON),this.check(i.NEWLINE)&&(this.pos++,this.eat(i.INDENT));let a=[];for(;!this.check(i.DEDENT)&&!this.check(i.EOF)&&(this.skipNewlines(),!(this.check(i.DEDENT)||this.check(i.EOF)));){let c=this.parseAccessModifiers();if(this.check(i.ASYNC)){this.pos++,this.eat(i.FN);let h=this.eat(i.IDENT).value,l=this.parseParamList(),p=null;this.maybe(i.ARROW)&&(p=this.parseTypeAnn()),this.skipNewlines(),a.push({kind:"method",name:h,params:l,retType:p,modifiers:c,isAsync:!0})}else if(this.check(i.FN)){this.eat(i.FN);let h=this.eat(i.IDENT).value,l=this.parseParamList(),p=null;this.maybe(i.ARROW)&&(p=this.parseTypeAnn()),this.skipNewlines(),a.push({kind:"method",name:h,params:l,retType:p,modifiers:c,isAsync:!1})}else if(this.check(i.IDENT)){let h=this.eat(i.IDENT).value,l=!1;this.check(i.QUESTION)&&(this.pos++,l=!0),this.eat(i.COLON);let p=this.parseTypeAnn();this.skipNewlines(),a.push({kind:"field",name:h,typeAnn:p,optional:l,modifiers:c})}else this.skip()}return this.maybe(i.DEDENT),{type:"InterfaceDecl",name:e,typeParams:s,superInterfaces:r,members:a,loc:t}}parseEnumDecl(){let t=this.eat(i.ENUM),e=this.eat(i.IDENT).value;this.eat(i.COLON),this.check(i.NEWLINE)&&(this.pos++,this.eat(i.INDENT));let s=[],r=0;for(;!this.check(i.DEDENT)&&!this.check(i.EOF)&&(this.skipNewlines(),!(this.check(i.DEDENT)||this.check(i.EOF)));){let a=this.eat(i.IDENT).value,c=null;this.maybe(i.EQ)?(c=this.parseExpr(),c.type==="NumberLit"&&(r=c.value)):c={type:"NumberLit",value:r},r++,this.skipNewlines(),s.push({name:a,value:c})}return this.maybe(i.DEDENT),{type:"EnumDecl",name:e,members:s,loc:t}}parseIf(){let t=this.eat(i.IF),e=this.parseExpr(),s=this.parseBlock(),r=[],a=null;for(this.skipNewlines();this.check(i.ELSE);)if(this.pos++,this.check(i.IF)){this.pos++;let c=this.parseExpr(),h=this.parseBlock();r.push({cond:c,body:h}),this.skipNewlines()}else{a=this.parseBlock();break}return{type:"IfStmt",cond:e,then:s,elseifs:r,else_:a,loc:t}}parseFor(){let t=this.eat(i.FOR),e=!1;this.check(i.AWAIT)&&(this.pos++,e=!0);let s,r=null;if(this.check(i.LBRACKET)){this.pos++;let h=[];for(;!this.check(i.RBRACKET)&&!this.check(i.EOF);){if(this.check(i.DOTDOTDOT)){this.pos++,h.push({rest:!0,name:this.eat(i.IDENT).value});break}if(h.push({name:this.eat(i.IDENT).value}),!this.maybe(i.COMMA))break}this.eat(i.RBRACKET),s="__item__",r={type:"array",names:h}}else s=this.eat(i.IDENT).value;this.check(i.IN)?this.pos++:this.check(i.IDENT)&&this.peek().value==="of"?(this.pos++,e=e):this.eat(i.IN);let a=this.parseExpr(),c=this.parseBlock();return{type:"ForInStmt",var:s,varPattern:r,iter:a,body:c,isAwait:e,loc:t}}parseWhile(){let t=this.eat(i.WHILE),e=this.parseExpr(),s=this.parseBlock();return{type:"WhileStmt",cond:e,body:s,loc:t}}parseDoWhile(){let t=this.eat(i.DO),e=this.parseBlock();this.skipNewlines(),this.eat(i.WHILE);let s=this.parseExpr();return this.skipNewlines(),{type:"DoWhileStmt",body:e,cond:s,loc:t}}parseMatch(){let t=this.eat(i.MATCH),e=this.parseExpr();this.eat(i.COLON),this.check(i.NEWLINE)&&this.pos++,this.eat(i.INDENT);let s=[];for(;!this.check(i.DEDENT)&&!this.check(i.EOF)&&(this.skipNewlines(),!(this.check(i.DEDENT)||this.check(i.EOF)));){this.eat(i.WHEN);let r=this.parsePattern(),a=null;if(this.check(i.IF)&&(this.pos++,a=this.parseExpr()),this.check(i.ARROW)){this.pos++;let c=this.parseExpr();this.skipNewlines(),s.push({pattern:r,guard:a,body:[{type:"ExprStmt",expr:c}],inline:!0})}else if(this.check(i.COLON)){let c=this.peek(1).type!==i.NEWLINE,h=this.parseBlock();s.push({pattern:r,guard:a,body:h,inline:c&&h.length===1&&h[0].type==="ExprStmt"})}}return this.maybe(i.DEDENT),{type:"MatchStmt",subject:e,arms:s,loc:t}}parsePattern(){if(this.check(i.WILDCARD))return this.skip(),{type:"WildcardPat"};if(this.check(i.IDENT)&&this.peek(1).type===i.LPAREN){let e=this.eat(i.IDENT).value;this.eat(i.LPAREN);let s=[];for(;!this.check(i.RPAREN)&&!this.check(i.EOF)&&(this.check(i.WILDCARD)?(s.push("_"),this.pos++):s.push(this.eat(i.IDENT).value),!!this.maybe(i.COMMA)););return this.eat(i.RPAREN),{type:"VariantPat",variant:e,bindings:s}}let t=this.parsePrimary();for(;this.check(i.DOT);){this.pos++;let e=this.skip().value;t={type:"MemberExpr",obj:t,prop:e}}if(this.check(i.DOTDOT)){this.pos++;let e=this.parsePrimary();return{type:"RangePat",start:t,end:e}}return{type:"LiteralPat",value:t}}parseReturn(){let t=this.eat(i.RETURN),e=null;return this.at(i.NEWLINE,i.EOF,i.DEDENT)||(e=this.parseExpr()),this.skipNewlines(),{type:"ReturnStmt",value:e,loc:t}}parseTryCatch(){let t=this.eat(i.TRY),e=this.parseBlock(),s=null,r=null,a=null;return this.skipNewlines(),this.check(i.CATCH)&&(this.pos++,this.check(i.LPAREN)&&(this.pos++,s=this.eat(i.IDENT).value,this.maybe(i.COLON)&&this.parseTypeAnn(),this.eat(i.RPAREN)),r=this.parseBlock(),this.skipNewlines()),this.check(i.FINALLY)&&(this.pos++,a=this.parseBlock()),{type:"TryCatchStmt",tryBody:e,catchParam:s,catchBody:r,finallyBody:a,loc:t}}parseThrow(){let t=this.eat(i.THROW),e=this.parseExpr();return this.skipNewlines(),{type:"ThrowStmt",value:e,loc:t}}parseImport(){if(this.eat(i.IMPORT),this.check(i.STAR)){this.pos++,this.eat(i.AS);let s=this.eat(i.IDENT).value;this.eat(i.FROM);let r=this.eat(i.STRING).value;return this.skipNewlines(),{type:"ImportDecl",names:[],defaultName:null,namespaceName:s,source:r}}if(this.check(i.IDENT)){let s=this.eat(i.IDENT).value;this.eat(i.FROM);let r=this.eat(i.STRING).value;return this.skipNewlines(),{type:"ImportDecl",names:[],defaultName:s,source:r}}let t=[];if(this.maybe(i.LBRACE)){for(;!this.check(i.RBRACE)&&!this.check(i.EOF);){let s=this.eat(i.IDENT).value,r=s;if(this.check(i.AS)&&(this.pos++,r=this.eat(i.IDENT).value),t.push({name:s,alias:r}),!this.maybe(i.COMMA))break}this.eat(i.RBRACE)}this.eat(i.FROM);let e=this.eat(i.STRING).value;return this.skipNewlines(),{type:"ImportDecl",names:t,defaultName:null,source:e}}parseExport(){if(this.eat(i.EXPORT),this.check(i.DEFAULT)&&(this.peek(1).type===i.FN||this.peek(1).type===i.ASYNC))return this.pos++,{type:"ExportDecl",isDefault:!0,decl:this.check(i.ASYNC)?(this.pos++,this.parseFnDecl(!0)):this.parseFnDecl()};if(this.check(i.DEFAULT)){this.pos++;let e=this.parseExpr();return this.skipNewlines(),{type:"ExportDecl",isDefault:!0,decl:e}}return this.check(i.ASYNC)?(this.pos++,this.check(i.FN)||this.err("Expected fn after async"),{type:"ExportDecl",isDefault:!1,decl:this.parseFnDecl(!0)}):{type:"ExportDecl",isDefault:!1,decl:this.parseOneStmt()}}parseExprStmt(){let t=this.parseExpr();return this.skipNewlines(),{type:"ExprStmt",expr:t}}parseExpr(){return this.parsePipe()}parsePipe(){let t=this.parseAssign();for(;;)if(this.check(i.PIPE)){this.pos++;let e=this.parseAssign();t={type:"PipeExpr",left:t,right:e}}else if(this.check(i.NEWLINE)){let e=1;for(;this.peek(e).type===i.NEWLINE;)e++;if(this.peek(e).type===i.PIPE){for(;this.check(i.NEWLINE);)this.pos++;this.pos++;let s=this.parseAssign();t={type:"PipeExpr",left:t,right:s}}else break}else break;return t}parseAssign(){let t=this.parseTernary(),s={[i.EQ]:"=",[i.PLUSEQ]:"+=",[i.MINUSEQ]:"-=",[i.STAREQ]:"*=",[i.SLASHEQ]:"/=",[i.PERCENTEQ]:"%="}[this.peek().type];return s?(this.pos++,{type:"AssignExpr",target:t,op:s,value:this.parseAssign()}):t}parseTernary(){let t=this.parseNullish();if(this.maybe(i.QUESTION)){let e=this.parseNullish();this.eat(i.COLON);let s=this.parseTernary();return{type:"TernaryExpr",cond:t,then:e,else_:s}}return t}parseNullish(){let t=this.parseOr();for(;this.check(i.NULLISH);){this.pos++;let e=this.parseOr();t={type:"BinaryExpr",op:"??",left:t,right:e}}return t}parseOr(){let t=this.parseAnd();for(;this.check(i.OR)||this.check(i.OROR);){this.pos++;let e=this.parseAnd();t={type:"BinaryExpr",op:"||",left:t,right:e}}return t}parseAnd(){let t=this.parseBitOr();for(;this.check(i.AND)||this.check(i.ANDAND);){this.pos++;let e=this.parseBitOr();t={type:"BinaryExpr",op:"&&",left:t,right:e}}return t}parseBitOr(){let t=this.parseBitXor();for(;this.check(i.PIPEB);){this.pos++;let e=this.parseBitXor();t={type:"BinaryExpr",op:"|",left:t,right:e}}return t}parseBitXor(){let t=this.parseBitAnd();for(;this.check(i.CARET);){this.pos++;let e=this.parseBitAnd();t={type:"BinaryExpr",op:"^",left:t,right:e}}return t}parseBitAnd(){let t=this.parseEq();for(;this.check(i.AMPERSAND);){this.pos++;let e=this.parseEq();t={type:"BinaryExpr",op:"&",left:t,right:e}}return t}parseEq(){let t=this.parseRel();for(;this.at(i.EQEQ,i.NEQ,i.EQEQEQ,i.NEQEQ);){let e=this.skip().value,s=this.parseRel();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseRel(){let t=this.parseShift();for(;this.at(i.LT,i.LTE,i.GT,i.GTE)||this.check(i.IN);){let e=this.skip().value,s=this.parseShift();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseShift(){let t=this.parseRange();for(;this.at(i.LSHIFT,i.RSHIFT);){let e=this.skip().value,s=this.parseRange();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseRange(){let t=this.parseAdd();if(this.check(i.DOTDOT)){this.pos++;let e=this.parseAdd();return{type:"RangeExpr",start:t,end:e}}return t}parseAdd(){let t=this.parseMul();for(;this.at(i.PLUS,i.MINUS);){let e=this.skip().value,s=this.parseMul();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseMul(){let t=this.parsePow();for(;this.at(i.STAR,i.SLASH,i.PERCENT);){let e=this.skip().value,s=this.parsePow();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parsePow(){let t=this.parseUnary();return this.check(i.STARSTAR)?(this.pos++,{type:"BinaryExpr",op:"**",left:t,right:this.parsePow()}):t}parseUnary(){return this.check(i.MINUS)?(this.pos++,{type:"UnaryExpr",op:"-",operand:this.parseUnary()}):this.check(i.NOT)?(this.pos++,{type:"UnaryExpr",op:"!",operand:this.parseUnary()}):this.check(i.BANG)?(this.pos++,{type:"UnaryExpr",op:"!",operand:this.parseUnary()}):this.check(i.TILDE)?(this.pos++,{type:"UnaryExpr",op:"~",operand:this.parseUnary()}):this.check(i.PLUSPLUS)?(this.pos++,{type:"UpdateExpr",op:"++",prefix:!0,operand:this.parseUnary()}):this.check(i.MINUSMINUS)?(this.pos++,{type:"UpdateExpr",op:"--",prefix:!0,operand:this.parseUnary()}):this.check(i.AWAIT)?(this.pos++,{type:"AwaitExpr",operand:this.parseUnary()}):this.check(i.TYPEOF)?(this.pos++,{type:"TypeofExpr",operand:this.parseUnary()}):this.check(i.IDENT)&&this.tokens[this.pos].value==="delete"?(this.pos++,{type:"UnaryExpr",op:"delete ",operand:this.parseUnary()}):this.parseLambdaOrPostfix()}parseLambdaOrPostfix(){let t=this.pos;if(this.check(i.IDENT)||this.check(i.WILDCARD)){let e=this.skip().value??"_";if(this.check(i.ARROW)){if(this.pos++,this.check(i.NEWLINE)){let r=this.parseIndentedBlock();return{type:"LambdaExpr",params:[{name:e}],body:r,block:!0}}let s=this.parseExpr();return{type:"LambdaExpr",params:[{name:e}],body:s}}this.pos=t}return this.parsePostfix()}parsePostfix(){let t=this.parsePrimary();t:for(;;)if(this.check(i.PLUSPLUS))this.pos++,t={type:"UpdateExpr",op:"++",prefix:!1,operand:t};else if(this.check(i.MINUSMINUS))this.pos++,t={type:"UpdateExpr",op:"--",prefix:!1,operand:t};else if(this.check(i.DOT)){this.pos++;let e=this.peek();e.type!==i.IDENT&&!(e.type in i)&&this.err(`Expected property name, got '${e.type}'`);let s=this.skip().value;t={type:"MemberExpr",obj:t,prop:s}}else if(this.check(i.QUESTIONDOT))if(this.pos++,this.check(i.LPAREN)){let e=this.parseArgList();t={type:"OptCallExpr",callee:t,args:e}}else if(this.check(i.LBRACKET)){this.pos++;let e=this.parseExpr();this.eat(i.RBRACKET),t={type:"OptIndexExpr",obj:t,idx:e}}else{let e=this.peek();e.type!==i.IDENT&&!(e.type in i)&&this.err(`Expected property name, got '${e.type}'`);let s=this.skip().value;t={type:"OptMemberExpr",obj:t,prop:s}}else if(this.check(i.INSTANCEOF)){this.pos++;let e=this.eat(i.IDENT).value;t={type:"BinaryExpr",op:"instanceof",left:t,right:{type:"Identifier",name:e}}}else if(this.check(i.AS))if(this.pos++,this.check(i.CONST))this.pos++,t={type:"AsConstExpr",expr:t};else{let e=this.parseTypeAnn();t={type:"CastExpr",expr:t,castType:e}}else if(this.check(i.SATISFIES)){this.pos++;let e=this.parseTypeAnn();t={type:"SatisfiesExpr",expr:t,satType:e}}else if(this.check(i.IS)){this.pos++;let e=this.parseTypeAnn();t={type:"IsExpr",expr:t,isType:e}}else if(this.check(i.BANG))this.pos++,t={type:"NonNullExpr",expr:t};else if(this.check(i.LBRACKET)){this.pos++;let e=this.parseExpr();this.eat(i.RBRACKET),t={type:"IndexExpr",obj:t,idx:e}}else if(this.check(i.LPAREN)){let e=this.parseArgList();if(this.check(i.ARROW)){this.pos++;let s=this.parseExpr();return{type:"LambdaExpr",params:e.map(a=>({name:a.type==="Identifier"?a.name:"_"})),body:s}}t={type:"CallExpr",callee:t,args:e}}else break t;return t}parseArgList(){this.eat(i.LPAREN);let t=[];for(;!this.check(i.RPAREN)&&!this.check(i.EOF)&&(this.check(i.DOTDOTDOT)?(this.pos++,t.push({type:"SpreadExpr",expr:this.parseExpr()})):t.push(this.parseExpr()),!!this.maybe(i.COMMA)););return this.eat(i.RPAREN),t}parsePrimary(){let t=this.peek();switch(t.type){case i.NUMBER:return this.pos++,{type:"NumberLit",value:t.value,loc:t};case i.BOOL:return this.pos++,{type:"BoolLit",value:t.value,loc:t};case i.NULL:return this.pos++,{type:"NullLit",loc:t};case i.SELF:return this.pos++,{type:"SelfExpr",loc:t};case i.WILDCARD:return this.pos++,{type:"Identifier",name:"_",loc:t};case i.IDENT:return this.pos++,{type:"Identifier",name:t.value,loc:t};case i.STRING:return this.pos++,t.value&&t.value.template?{type:"TemplateLit",parts:t.value.parts,loc:t}:{type:"StringLit",value:t.value,loc:t};case i.REGEX:return this.pos++,{type:"RegexLit",value:t.value,loc:t};case i.NEW:{this.pos++;let e=this.eat(i.IDENT).value,s=this.parseArgList();return{type:"NewExpr",callee:e,args:s}}case i.FN:{this.pos++;let e=this.parseParamList();if(this.check(i.ARROW)){if(this.pos++,this._isTypeAnnBeforeColon()){let r=this.parseTypeAnn(),a=this.parseBlock();return{type:"FnDecl",name:null,params:e,retType:r,body:a,inline:!1,async:!1,loc:t}}let s=this.parseExpr();return{type:"FnDecl",name:null,params:e,retType:null,body:s,inline:!0,async:!1,loc:t}}if(this.check(i.COLON)){let s=this.parseBlock();return{type:"FnDecl",name:null,params:e,retType:null,body:s,inline:!1,async:!1,loc:t}}this.err("Expected -> or : after anonymous fn")}case i.MATCH:return this.parseMatch();case i.LPAREN:{if(this.pos++,this.check(i.RPAREN)){if(this.pos++,this.check(i.ARROW)){if(this.pos++,this.check(i.NEWLINE)){let a=this.parseIndentedBlock();return{type:"LambdaExpr",params:[],body:a,block:!0}}let r=this.parseExpr();return{type:"LambdaExpr",params:[],body:r}}return{type:"NullLit"}}let e=this.parseExpr();if(this.check(i.RPAREN)){if(this.pos++,this.check(i.ARROW)){if(this.pos++,this.check(i.NEWLINE)){let c=this.parseIndentedBlock();return{type:"LambdaExpr",params:[{name:e.type==="Identifier"?e.name:"_"}],body:c,block:!0}}let r=this.parseExpr();return{type:"LambdaExpr",params:[{name:e.type==="Identifier"?e.name:"_"}],body:r}}return e}let s=[e];for(;this.maybe(i.COMMA);)s.push(this.parseExpr());if(this.eat(i.RPAREN),this.check(i.ARROW)){this.pos++;let r=s.map(c=>({name:c.type==="Identifier"?c.name:"_"}));if(this.check(i.NEWLINE)){let c=this.parseIndentedBlock();return{type:"LambdaExpr",params:r,body:c,block:!0}}let a=this.parseExpr();return{type:"LambdaExpr",params:r,body:a}}return s.length>1&&this.err(`Unexpected comma in expression \u2014 did you mean a lambda? Write (${s.map((r,a)=>"p"+a).join(", ")}) -> expr`),s[0]}case i.LBRACKET:{this.pos++;let e=[];for(;!this.check(i.RBRACKET)&&!this.check(i.EOF)&&(this.check(i.DOTDOTDOT)?(this.pos++,e.push({type:"SpreadExpr",expr:this.parseExpr()})):e.push(this.parseExpr()),!!this.maybe(i.COMMA)););return this.eat(i.RBRACKET),{type:"ArrayExpr",items:e}}case i.LBRACE:{this.pos++;let e=[];for(;!this.check(i.RBRACE)&&!this.check(i.EOF);){if(this.check(i.DOTDOTDOT)){if(this.pos++,e.push({spread:!0,value:this.parseExpr()}),!this.maybe(i.COMMA))break;continue}if(this.check(i.LBRACKET)){this.pos++;let r=this.parseExpr();this.eat(i.RBRACKET),this.eat(i.COLON);let a=this.parseExpr();if(e.push({computed:!0,keyExpr:r,value:a}),!this.maybe(i.COMMA))break;continue}let s=this.check(i.STRING)?this.eat(i.STRING).value:this.check(i.IDENT)?this.eat(i.IDENT).value:this.skip().value;if(!this.check(i.COLON))e.push({key:s,value:{type:"Identifier",name:s}});else{this.eat(i.COLON);let r=this.parseExpr();e.push({key:s,value:r})}if(!this.maybe(i.COMMA))break}return this.eat(i.RBRACE),{type:"ObjectExpr",pairs:e}}default:this.err(`Unexpected token: ${t.type} (${JSON.stringify(t.value)})`)}}};jt.exports={Parser:dt,ParseError:z}});var xt=_((Ns,Wt)=>{"use strict";function Se(n){let t=n.lastIndexOf(":");if(t<1)return null;let e=n.slice(t+1).trim();return e.length>0&&/[.<>^,dbeEfFgGoOxXs%bcn]/.test(e)&&/^([.<>^0\-+ #,]*[0-9]*\.?[0-9]*[dbeEfFgGoOxXs%bcn]?[,]?)$/.test(e)?{expr:n.slice(0,t).trim(),fmt:e}:null}var Ae=`
23
- function _fmt(v, s) {
22
+ `);return new J(t,0,1,1,[],[0],0)}V.exports.lexerize=Zt});var Q=S((ts,pt)=>{"use strict";var{T:r}=B();function St(a,t){let e=(t==null?void 0:t.line)??"?",s=(t==null?void 0:t.col)??"?",i=new Error(`[Parser ${e}:${s}] ${a}`);return i.name="ParseError",i.tok=t,i}var K=class{constructor(t,e){this.tokens=t,this.pos=e}peek(t=0){return this.tokens[this.pos+t]??{type:"EOF",value:null,line:0,col:0}}check(t){return this.peek().type==t}at(t,e=null,s=null,i=null,n=null,h=null){let l=this.peek().type;return l==t||e!=null&&l==e||s!=null&&l==s||i!=null&&l==i||n!=null&&l==n||h!=null&&l==h}eat(t){let e=this.peek();if(e.type!=t)throw St(`Expected '${t}', got '${e.type}' (${JSON.stringify(e.value)})`,e);return this.pos=this.pos+1,e}maybe(t){return this.check(t)?(this.pos=this.pos+1,!0):!1}skip(){let t=this.tokens[this.pos];return this.pos=this.pos+1,t}skipNewlines(){for(;this.check(r.NEWLINE);)this.pos=this.pos+1}err(t){throw St(t,this.peek())}parseBlock(){if(this.eat(r.COLON),this.check(r.NEWLINE)){this.pos=this.pos+1,this.eat(r.INDENT);let e=this.parseStmtList();return this.maybe(r.DEDENT),e}return[this.parseOneStmt()]}parseStmtList(){let t=[];for(;!this.check(r.DEDENT)&&!this.check(r.EOF)&&(this.skipNewlines(),!(this.check(r.DEDENT)||this.check(r.EOF)));)t.push(this.parseOneStmt());return t}parse(){this.skipNewlines();let t=[];for(;!this.check(r.EOF)&&(this.skipNewlines(),!this.check(r.EOF));)t.push(this.parseOneStmt());return{type:"Program",body:t}}parseOneStmt(){let t=this.peek();return t.type==r.VAR||t.type==r.VAL?this.parseVarDecl():t.type==r.FN?this.parseFnDecl(!1):t.type==r.ASYNC?this.parseAsyncFn():t.type==r.CLASS?this.parseClassDecl():t.type==r.DECLARE?this.parseDeclareDecl():t.type==r.IF?this.parseIf():t.type==r.FOR?this.parseFor():t.type==r.WHILE?this.parseWhile():t.type==r.DO?this.parseDoWhile():t.type==r.MATCH?this.parseMatch():t.type==r.RETURN?this.parseReturn():t.type==r.BREAK?(this.skip(),this.skipNewlines(),{type:"BreakStmt",loc:t}):t.type==r.CONTINUE?(this.skip(),this.skipNewlines(),{type:"ContinueStmt",loc:t}):t.type==r.IMPORT?this.parseImport():t.type==r.EXPORT?this.parseExport():t.type==r.TRY?this.parseTryCatch():t.type==r.THROW?this.parseThrow():t.type==r.TYPE?this.parseTypeDecl():t.type==r.INTERFACE?this.parseInterfaceDecl():t.type==r.ENUM?this.parseEnumDecl():this.parseExprStmt()}parseVarDecl(){let t=this.peek().type==r.VAR?"var":"val",e=this.skip();if(this.check(r.LBRACE)){let h=this.parseObjectDestructurePattern();this.eat(r.EQ);let l=this.parseExpr();return this.skipNewlines(),{type:"DestructureDecl",kind:t,patternType:"object",pattern:h,init:l,loc:e}}if(this.check(r.LBRACKET)){let h=this.parseArrayDestructurePattern();this.eat(r.EQ);let l=this.parseExpr();return this.skipNewlines(),{type:"DestructureDecl",kind:t,patternType:"array",pattern:h,init:l,loc:e}}let s=this.eat(r.IDENT).value,i=null;this.maybe(r.COLON)&&(i=this.parseTypeAnn());let n=null;return this.maybe(r.EQ)&&(n=this.parseExpr()),this.skipNewlines(),{type:"VarDecl",kind:t,name:s,typeAnn:i,init:n,loc:e}}parseObjectDestructurePattern(){this.eat(r.LBRACE);let t=[];for(;!this.check(r.RBRACE)&&!this.check(r.EOF);){let e=!1;this.check(r.DOTDOTDOT)&&(this.pos=this.pos+1,e=!0);let s=this.eat(r.IDENT).value;if(e){t.push({key:s,alias:s,rest:!0});break}let i=s;this.maybe(r.COLON)&&(i=this.eat(r.IDENT).value);let n=null;if(this.maybe(r.EQ)&&(n=this.parseExpr()),t.push({key:s,alias:i,defaultVal:n,rest:!1}),!this.maybe(r.COMMA))break}return this.eat(r.RBRACE),t}parseArrayDestructurePattern(){this.eat(r.LBRACKET);let t=[];for(;!this.check(r.RBRACKET)&&!this.check(r.EOF);){if(this.check(r.COMMA)){t.push(null),this.pos=this.pos+1;continue}let e=!1;this.check(r.DOTDOTDOT)&&(this.pos=this.pos+1,e=!0);let s=this.eat(r.IDENT).value,i=null;if(this.maybe(r.EQ)&&(i=this.parseExpr()),t.push({name:s,defaultVal:i,rest:e}),e||!this.maybe(r.COMMA))break}return this.eat(r.RBRACKET),t}parseTypeAnn(){let t=this.parseIntersectionType();for(;this.check(r.PIPEB);)this.pos=this.pos+1,t=t+" | "+this.parseIntersectionType();return t}parseIntersectionType(){let t=this.parseSingleType();for(;this.check(r.AMPERSAND);)this.pos=this.pos+1,t=t+" & "+this.parseSingleType();return t}parseSingleType(){let t=this.peek();if(t.type==r.LBRACKET){this.pos=this.pos+1;let s=[];for(;!this.check(r.RBRACKET)&&!this.check(r.EOF)&&(s.push(this.parseTypeAnn()),!!this.maybe(r.COMMA)););return this.eat(r.RBRACKET),"["+s.join(", ")+"]"}if(t.type==r.LBRACE){this.pos=this.pos+1;let s=[];for(;!this.check(r.RBRACE)&&!this.check(r.EOF);){if(this.check(r.LBRACKET)){this.pos=this.pos+1;let i=this.eat(r.IDENT).value;this.eat(r.COLON);let n=this.parseTypeAnn();this.eat(r.RBRACKET),this.eat(r.COLON);let h=this.parseTypeAnn();s.push(`[${i}: ${n}]: ${h}`)}else{let i=this.at(r.IDENT,r.STRING)?this.skip().value:this.eat(r.IDENT).value,n=!1;this.check(r.QUESTION)&&(this.pos=this.pos+1,n=!0),this.eat(r.COLON);let h=this.parseTypeAnn(),l=n?"?":"";s.push(`${i}${l}: ${h}`)}this.maybe(r.COMMA)}return this.eat(r.RBRACE),"{ "+s.join(", ")+" }"}if(t.type==r.LPAREN){this.pos=this.pos+1;let s=this.parseTypeAnn();return this.eat(r.RPAREN),"("+s+")"}if(t.type==r.IDENT&&t.value=="keyof")return this.pos=this.pos+1,"keyof "+this.parseSingleType();if(t.type==r.TYPEOF)return this.pos=this.pos+1,"typeof "+this.eat(r.IDENT).value;if(t.type==r.READONLY)return this.pos=this.pos+1,"readonly "+this.parseSingleType();if(t.type==r.IDENT&&t.value=="infer")return this.pos=this.pos+1,"infer "+this.eat(r.IDENT).value;if(t.type==r.FN){this.pos=this.pos+1;let s=[];if(this.check(r.LPAREN)){for(this.pos=this.pos+1;!this.check(r.RPAREN)&&!this.check(r.EOF);){let n="";if(this.check(r.IDENT)&&this.peek(1).type==r.COLON?(this.pos=this.pos+2,n=this.parseTypeAnn()):n=this.parseTypeAnn(),s.push(n),!this.maybe(r.COMMA))break}this.eat(r.RPAREN)}let i="Void";return this.check(r.ARROW)&&(this.pos=this.pos+1,i=this.parseTypeAnn()),"fn("+s.join(", ")+") -> "+i}let e="";if(t.type==r.IDENT||t.type==r.CONST||t.type==r.TYPE?e=this.skip().value:e=this.eat(r.IDENT).value,this.check(r.EXTENDS)){this.pos=this.pos+1;let s=this.parseSingleType();this.eat(r.QUESTION);let i=this.parseTypeAnn();this.eat(r.COLON);let n=this.parseTypeAnn();return`${e} extends ${s} ? ${i} : ${n}`}if(this.check(r.LT)){this.pos=this.pos+1;let s=[this.parseTypeAnn()];for(;this.maybe(r.COMMA);)s.push(this.parseTypeAnn());this.eat(r.GT),e=e+"<"+s.join(", ")+">"}for(;this.check(r.LBRACKET)&&this.peek(1).type==r.RBRACKET;)this.pos=this.pos+2,e=e+"[]";return this.check(r.QUESTION)&&this.peek(1).type!=r.DOT&&(this.pos=this.pos+1,e=e+"?"),e}isTypeAnnBeforeColon(){var e;let t=this.pos;try{let s=this.peek();if(s.type==r.LBRACKET||s.type==r.LBRACE||s.type==r.LPAREN){let n=0,h=0;for(;this.tokens[this.pos+h]&&this.tokens[this.pos+h].type!=r.EOF;){let c=this.tokens[this.pos+h].type;if((c==r.LBRACKET||c==r.LBRACE||c==r.LPAREN||c==r.LT)&&(n=n+1),(c==r.RBRACKET||c==r.RBRACE||c==r.RPAREN||c==r.GT)&&(n=n-1),h=h+1,n==0)break}this.tokens[this.pos+h]&&this.tokens[this.pos+h].type==r.QUESTION&&(h=h+1);let l=(e=this.tokens[this.pos+h])==null?void 0:e.type;return this.pos=t,l==r.COLON}if(s.type!=r.IDENT&&s.type!=r.TYPEOF&&s.type!=r.READONLY&&s.type!=r.FN)return this.pos=t,!1;this.parseTypeAnn();let i=this.check(r.NEWLINE)||this.check(r.EOF);return this.pos=t,i}catch{return this.pos=t,!1}}isColonReturnType(){let t=this.pos;try{if(this.pos=this.pos+1,!this.at(r.IDENT,r.LBRACKET,r.LBRACE,r.LPAREN,r.FN,r.READONLY,r.TYPEOF))return this.pos=t,!1;this.parseTypeAnn();let e=this.check(r.NEWLINE)||this.check(r.EOF);return this.pos=t,e}catch{return this.pos=t,!1}}parseTypeDecl(){let t=this.eat(r.TYPE),e=this.eat(r.IDENT).value,s=[];if(this.check(r.LT)){for(this.pos=this.pos+1;!this.check(r.GT)&&!this.check(r.EOF)&&(s.push(this.eat(r.IDENT).value),!!this.maybe(r.COMMA)););this.eat(r.GT)}this.eat(r.EQ);let i=[],n=!0;for(;n;){let h=this.eat(r.IDENT).value,l=[],c={};if(this.check(r.LPAREN)){for(this.eat(r.LPAREN);!this.check(r.RPAREN)&&!this.check(r.EOF);){let o=this.peek(),u="";if(o.type==r.IDENT?u=this.skip().value:u=this.skip().value,this.maybe(r.COLON)&&(c[u]=this.parseTypeAnn()),l.push(u),!this.maybe(r.COMMA))break}this.eat(r.RPAREN)}i.push({name:h,fields:l,fieldTypes:c}),this.check(r.PIPEB)?this.pos=this.pos+1:n=!1}return this.skipNewlines(),{type:"TypeDecl",name:e,variants:i,loc:t}}parseInterfaceDecl(){let t=this.eat(r.INTERFACE),e=this.eat(r.IDENT).value,s=[];if(this.check(r.LT)){for(this.pos=this.pos+1;!this.check(r.GT)&&!this.check(r.EOF)&&(s.push(this.eat(r.IDENT).value),!!this.maybe(r.COMMA)););this.eat(r.GT)}let i=[];if(this.maybe(r.EXTENDS))for(i.push(this.eat(r.IDENT).value);this.maybe(r.COMMA);)i.push(this.eat(r.IDENT).value);this.eat(r.COLON),this.check(r.NEWLINE)&&(this.pos=this.pos+1),this.eat(r.INDENT);let n=[];for(;!this.check(r.DEDENT)&&!this.check(r.EOF)&&(this.skipNewlines(),!(this.check(r.DEDENT)||this.check(r.EOF)));){let h=this.parseAccessModifiers();if(this.check(r.FN)){this.eat(r.FN);let l=this.eat(r.IDENT).value,c=this.parseParamList(),o=null;this.maybe(r.ARROW)&&(o=this.parseTypeAnn()),this.skipNewlines(),n.push({kind:"method",name:l,params:c,retType:o,modifiers:h,isAsync:!1})}else if(this.check(r.IDENT)){let l=this.eat(r.IDENT).value,c=!1;this.check(r.QUESTION)&&(this.pos=this.pos+1,c=!0),this.eat(r.COLON);let o=this.parseTypeAnn();this.skipNewlines(),n.push({kind:"field",name:l,typeAnn:o,optional:c,modifiers:h})}else this.skip()}return this.maybe(r.DEDENT),{type:"InterfaceDecl",name:e,typeParams:s,superInterfaces:i,members:n,loc:t}}parseEnumDecl(){let t=this.eat(r.ENUM),e=this.eat(r.IDENT).value;this.eat(r.COLON),this.check(r.NEWLINE)&&(this.pos=this.pos+1,this.eat(r.INDENT));let s=[],i=0;for(;!this.check(r.DEDENT)&&!this.check(r.EOF)&&(this.skipNewlines(),!(this.check(r.DEDENT)||this.check(r.EOF)));){let n=this.eat(r.IDENT).value,h={type:"NumberLit",value:i};if(this.maybe(r.EQ)){let l=this.parseExpr();h=l,l.type=="NumberLit"&&(i=l.value)}else h={type:"NumberLit",value:i};i=i+1,this.skipNewlines(),s.push({name:n,value:h})}return this.maybe(r.DEDENT),{type:"EnumDecl",name:e,members:s,loc:t}}parseIf(){let t=this.eat(r.IF),e=this.parseExpr(),s=this.parseBlock(),i=[],n=null;for(this.skipNewlines();this.check(r.ELSE);)if(this.pos=this.pos+1,this.check(r.IF)){this.pos=this.pos+1;let h=this.parseExpr(),l=this.parseBlock();i.push({cond:h,body:l}),this.skipNewlines()}else{n=this.parseBlock();break}return{type:"IfStmt",cond:e,then:s,elseifs:i,else_:n,loc:t}}parseFor(){let t=this.eat(r.FOR),e=!1;this.check(r.AWAIT)&&(this.pos=this.pos+1,e=!0);let s=this.eat(r.IDENT).value;this.eat(r.IN);let i=this.parseExpr(),n=this.parseBlock();return{type:"ForInStmt",var:s,iter:i,body:n,isAwait:e,loc:t}}parseWhile(){let t=this.eat(r.WHILE),e=this.parseExpr(),s=this.parseBlock();return{type:"WhileStmt",cond:e,body:s,loc:t}}parseDoWhile(){let t=this.eat(r.DO),e=this.parseBlock();this.skipNewlines(),this.eat(r.WHILE);let s=this.parseExpr();return this.skipNewlines(),{type:"DoWhileStmt",body:e,cond:s,loc:t}}parseMatch(){let t=this.eat(r.MATCH),e=this.parseExpr();this.eat(r.COLON),this.check(r.NEWLINE)&&(this.pos=this.pos+1),this.eat(r.INDENT);let s=[];for(;!this.check(r.DEDENT)&&!this.check(r.EOF)&&(this.skipNewlines(),!(this.check(r.DEDENT)||this.check(r.EOF)));){this.eat(r.WHEN);let i=this.parsePattern(),n=null;if(this.check(r.IF)&&(this.pos=this.pos+1,n=this.parseExpr()),this.check(r.ARROW)){this.pos=this.pos+1;let h=this.parseExpr();this.skipNewlines(),s.push({pattern:i,guard:n,body:[{type:"ExprStmt",expr:h}],inline:!0})}else if(this.check(r.COLON)){let h=this.peek(1).type!=r.NEWLINE,l=this.parseBlock(),c=h&&l.length==1&&l[0].type=="ExprStmt";s.push({pattern:i,guard:n,body:l,inline:c})}}return this.maybe(r.DEDENT),{type:"MatchStmt",subject:e,arms:s,loc:t}}parsePattern(){if(this.check(r.WILDCARD))return this.skip(),{type:"WildcardPat"};if(this.check(r.IDENT)&&this.peek(1).type==r.LPAREN){let e=this.eat(r.IDENT).value;this.eat(r.LPAREN);let s=[];for(;!this.check(r.RPAREN)&&!this.check(r.EOF)&&(this.check(r.WILDCARD)?(s.push("_"),this.pos=this.pos+1):s.push(this.eat(r.IDENT).value),!!this.maybe(r.COMMA)););return this.eat(r.RPAREN),{type:"VariantPat",variant:e,bindings:s}}let t=this.parsePrimary();for(;this.check(r.DOT);){this.pos=this.pos+1;let e=this.skip().value;t={type:"MemberExpr",obj:t,prop:e}}if(this.check(r.DOTDOT)){this.pos=this.pos+1;let e=this.parsePrimary();return{type:"RangePat",start:t,end:e}}return{type:"LiteralPat",value:t}}parseReturn(){let t=this.eat(r.RETURN),e=null;return this.at(r.NEWLINE,r.EOF,r.DEDENT)||(e=this.parseExpr()),this.skipNewlines(),{type:"ReturnStmt",value:e,loc:t}}parseTryCatch(){let t=this.eat(r.TRY),e=this.parseBlock(),s=null,i=null,n=null;return this.skipNewlines(),this.check(r.CATCH)&&(this.pos=this.pos+1,this.check(r.LPAREN)&&(this.pos=this.pos+1,s=this.eat(r.IDENT).value,this.maybe(r.COLON)&&this.parseTypeAnn(),this.eat(r.RPAREN)),i=this.parseBlock(),this.skipNewlines()),this.check(r.FINALLY)&&(this.pos=this.pos+1,n=this.parseBlock()),{type:"TryCatchStmt",tryBody:e,catchParam:s,catchBody:i,finallyBody:n,loc:t}}parseThrow(){let t=this.eat(r.THROW),e=this.parseExpr();return this.skipNewlines(),{type:"ThrowStmt",value:e,loc:t}}parseImport(){if(this.eat(r.IMPORT),this.check(r.STAR)){this.pos=this.pos+1,this.eat(r.AS);let s=this.eat(r.IDENT).value;this.eat(r.FROM);let i=this.eat(r.STRING).value;return this.skipNewlines(),{type:"ImportDecl",names:[],defaultName:null,namespaceName:s,source:i}}if(this.check(r.IDENT)){let s=this.eat(r.IDENT).value;this.eat(r.FROM);let i=this.eat(r.STRING).value;return this.skipNewlines(),{type:"ImportDecl",names:[],defaultName:s,source:i}}let t=[];if(this.maybe(r.LBRACE)){for(;!this.check(r.RBRACE)&&!this.check(r.EOF);){let s=this.eat(r.IDENT).value,i=s;if(this.check(r.AS)&&(this.pos=this.pos+1,i=this.eat(r.IDENT).value),t.push({name:s,alias:i}),!this.maybe(r.COMMA))break}this.eat(r.RBRACE)}this.eat(r.FROM);let e=this.eat(r.STRING).value;return this.skipNewlines(),{type:"ImportDecl",names:t,defaultName:null,source:e}}parseExport(){if(this.eat(r.EXPORT),this.check(r.DEFAULT)){if(this.pos=this.pos+1,this.check(r.ASYNC))return this.pos=this.pos+1,{type:"ExportDecl",isDefault:!0,decl:this.parseFnDecl(!0)};if(this.check(r.FN))return{type:"ExportDecl",isDefault:!0,decl:this.parseFnDecl(!1)};let e=this.parseExpr();return this.skipNewlines(),{type:"ExportDecl",isDefault:!0,decl:e}}return this.check(r.ASYNC)?(this.pos=this.pos+1,this.check(r.FN)||this.err("Expected fn after async"),{type:"ExportDecl",isDefault:!1,decl:this.parseFnDecl(!0)}):{type:"ExportDecl",isDefault:!1,decl:this.parseOneStmt()}}parseFnDecl(t=!1){let e=this.eat(r.FN),s=null;(this.check(r.IDENT)||this.check(r.NEW)||this.check(r.FROM)||this.check(r.AS)||this.check(r.DEFAULT)||this.check(r.IS)||this.check(r.IN)||this.check(r.TYPE))&&(s=this.skip().value);let i=this.parseParamList(),n=null;if(this.check(r.ARROW)){if(this.pos=this.pos+1,this.isTypeAnnBeforeColon()){n=this.parseTypeAnn();let l=this.parseBlock();return{type:"FnDecl",name:s,params:i,retType:n,body:l,inline:!1,async:t,loc:e}}let h=this.parseExpr();return this.skipNewlines(),{type:"FnDecl",name:s,params:i,retType:null,body:h,inline:!0,async:t,loc:e}}if(this.check(r.COLON)){if(this.isColonReturnType()){if(this.pos=this.pos+1,n=this.parseTypeAnn(),this.check(r.NEWLINE)&&(this.pos=this.pos+1),this.check(r.INDENT)){this.pos=this.pos+1;let c=this.parseStmtList();return this.maybe(r.DEDENT),{type:"FnDecl",name:s,params:i,retType:n,body:c,inline:!1,async:t,loc:e}}let l=this.parseOneStmt();return{type:"FnDecl",name:s,params:i,retType:n,body:[l],inline:!1,async:t,loc:e}}let h=this.parseBlock();return{type:"FnDecl",name:s,params:i,retType:null,body:h,inline:!1,async:t,loc:e}}this.err("Expected -> or : after function signature")}parseAsyncFn(){return this.eat(r.ASYNC),this.check(r.FN)||this.err("Expected fn after async"),this.parseFnDecl(!0)}parseDeclareDecl(){let t=this.eat(r.DECLARE),e=this.peek();if(e.type==r.FN||e.type==r.ASYNC){let s=e.type==r.ASYNC;this.skip(),s&&this.eat(r.FN);let i=this.check(r.IDENT)?this.skip().value:null,n=this.parseParamList(),h=null;return this.check(r.ARROW)?(this.pos=this.pos+1,h=this.parseTypeAnn()):this.check(r.COLON)&&(this.pos=this.pos+1,h=this.parseTypeAnn()),this.skipNewlines(),{type:"DeclareDecl",decl:{type:"FnDecl",name:i,params:n,retType:h,body:[],inline:!1,async:s,loc:e},loc:t}}if(e.type==r.VAL||e.type==r.VAR){let s=e.type==r.VAR?"var":"val";this.skip();let i=this.eat(r.IDENT).value,n=null;return this.maybe(r.COLON)&&(n=this.parseTypeAnn()),this.skipNewlines(),{type:"DeclareDecl",decl:{type:"VarDecl",kind:s,name:i,typeAnn:n,init:null,loc:e},loc:t}}if(e.type==r.CLASS){this.skip();let s=this.eat(r.IDENT).value;return this.skipNewlines(),{type:"DeclareDecl",decl:{type:"ClassDecl",name:s,fields:[],methods:[],loc:e},loc:t}}this.err("Expected fn, async fn, val, var, or class after declare")}parseParamList(){this.eat(r.LPAREN);let t=[];for(;!this.check(r.RPAREN)&&!this.check(r.EOF);){let e=!1;this.check(r.DOTDOTDOT)&&(this.pos=this.pos+1,e=!0);let s=this.eat(r.IDENT).value,i=!1,n=null;!e&&this.check(r.QUESTION)&&(this.pos=this.pos+1,i=!0),!e&&this.maybe(r.COLON)&&(n=this.parseTypeAnn());let h=null;if(!e&&this.maybe(r.EQ)&&(h=this.parseExpr()),t.push({name:s,typeAnn:n,optional:i,defaultVal:h,rest:e}),e||!this.maybe(r.COMMA))break}return this.eat(r.RPAREN),t}parseAccessModifiers(){let t=new Set([]),e=!0;for(;e;){let s=this.peek().type;s==r.PRIVATE||s==r.PUBLIC||s==r.PROTECTED||s==r.READONLY||s==r.STATIC||s==r.ABSTRACT||s==r.OVERRIDE?t.add(this.skip().value):e=!1}return t}parseClassDecl(){let t=this.eat(r.CLASS),e=this.eat(r.IDENT).value,s=null,i=[],n=[];if(this.check(r.LT)){for(this.pos=this.pos+1,n.push(this.eat(r.IDENT).value);this.maybe(r.COMMA);)n.push(this.eat(r.IDENT).value);this.eat(r.GT)}if(this.maybe(r.EXTENDS)&&(s=this.eat(r.IDENT).value),this.maybe(r.IMPLEMENTS))for(i.push(this.eat(r.IDENT).value);this.maybe(r.COMMA);)i.push(this.eat(r.IDENT).value);this.eat(r.COLON),this.check(r.NEWLINE)&&(this.pos=this.pos+1,this.eat(r.INDENT));let h=[],l=[];for(;!this.check(r.DEDENT)&&!this.check(r.EOF)&&(this.skipNewlines(),!(this.check(r.DEDENT)||this.check(r.EOF)));){let c=this.parseAccessModifiers();if(this.check(r.FN)){let o=this.parseFnDecl(!1);o.modifiers=c,l.push(o)}else if(this.check(r.ASYNC)){let o=this.parseAsyncFn();o.modifiers=c,l.push(o)}else if(this.check(r.STATIC)&&this.peek(1).type==r.FN){this.skip();let o=this.parseFnDecl(!1);o.modifiers=c,o.modifiers.add("static"),l.push(o)}else if(this.check(r.IDENT)){let o=this.eat(r.IDENT).value,u=!1;this.check(r.QUESTION)&&(this.pos=this.pos+1,u=!0),this.eat(r.COLON);let y=this.parseTypeAnn();this.skipNewlines(),h.push({name:o,typeAnn:y,optional:u,modifiers:c})}else this.skip()}return this.maybe(r.DEDENT),{type:"ClassDecl",name:e,typeParams:n,superClass:s,interfaces:i,fields:h,methods:l,loc:t}}parseExprStmt(){let t=this.parseExpr();return this.skipNewlines(),{type:"ExprStmt",expr:t}}parseExpr(){return this.parsePipe()}parsePipe(){let t=this.parseAssign(),e=!0;for(;e;)if(this.check(r.PIPE)){this.pos=this.pos+1;let s=this.parseAssign();t={type:"PipeExpr",left:t,right:s}}else if(this.check(r.NEWLINE)){let s=1;for(;this.peek(s).type==r.NEWLINE;)s=s+1;if(this.peek(s).type==r.PIPE){for(;this.check(r.NEWLINE);)this.pos=this.pos+1;this.pos=this.pos+1;let i=this.parseAssign();t={type:"PipeExpr",left:t,right:i}}else e=!1}else e=!1;return t}parseAssign(){let t=this.parseTernary(),e=this.peek().type,s="";return e==r.EQ?s="=":e==r.PLUSEQ?s="+=":e==r.MINUSEQ?s="-=":e==r.STAREQ?s="*=":e==r.SLASHEQ?s="/=":e==r.PERCENTEQ&&(s="%="),s?(this.pos=this.pos+1,{type:"AssignExpr",target:t,op:s,value:this.parseAssign()}):t}parseTernary(){let t=this.parseNullish();if(this.maybe(r.QUESTION)){let e=this.parseNullish();this.eat(r.COLON);let s=this.parseTernary();return{type:"TernaryExpr",cond:t,then:e,else_:s}}return t}parseNullish(){let t=this.parseOr();for(;this.check(r.NULLISH);){this.pos=this.pos+1;let e=this.parseOr();t={type:"BinaryExpr",op:"??",left:t,right:e}}return t}parseOr(){let t=this.parseAnd();for(;this.check(r.OR)||this.check(r.OROR);){this.pos=this.pos+1;let e=this.parseAnd();t={type:"BinaryExpr",op:"||",left:t,right:e}}return t}parseAnd(){let t=this.parseBitOr();for(;this.check(r.AND)||this.check(r.ANDAND);){this.pos=this.pos+1;let e=this.parseBitOr();t={type:"BinaryExpr",op:"&&",left:t,right:e}}return t}parseBitOr(){let t=this.parseBitXor();for(;this.check(r.PIPEB);){this.pos=this.pos+1;let e=this.parseBitXor();t={type:"BinaryExpr",op:"|",left:t,right:e}}return t}parseBitXor(){let t=this.parseBitAnd();for(;this.check(r.CARET);){this.pos=this.pos+1;let e=this.parseBitAnd();t={type:"BinaryExpr",op:"^",left:t,right:e}}return t}parseBitAnd(){let t=this.parseEq();for(;this.check(r.AMPERSAND);){this.pos=this.pos+1;let e=this.parseEq();t={type:"BinaryExpr",op:"&",left:t,right:e}}return t}parseEq(){let t=this.parseRel();for(;this.at(r.EQEQ,r.NEQ,r.EQEQEQ,r.NEQEQ);){let e=this.skip().value,s=this.parseRel();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseRel(){let t=this.parseShift();for(;this.at(r.LT,r.LTE,r.GT,r.GTE)||this.check(r.IN);){let e=this.skip().value,s=this.parseShift();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseShift(){let t=this.parseRange();for(;this.at(r.LSHIFT,r.RSHIFT);){let e=this.skip().value,s=this.parseRange();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseRange(){let t=this.parseAdd();if(this.check(r.DOTDOT)){this.pos=this.pos+1;let e=this.parseAdd();return{type:"RangeExpr",start:t,end:e}}return t}parseAdd(){let t=this.parseMul();for(;this.at(r.PLUS,r.MINUS);){let e=this.skip().value,s=this.parseMul();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parseMul(){let t=this.parsePow();for(;this.at(r.STAR,r.SLASH,r.PERCENT);){let e=this.skip().value,s=this.parsePow();t={type:"BinaryExpr",op:e,left:t,right:s}}return t}parsePow(){let t=this.parseUnary();return this.check(r.STARSTAR)?(this.pos=this.pos+1,{type:"BinaryExpr",op:"**",left:t,right:this.parsePow()}):t}parseUnary(){return this.check(r.MINUS)?(this.pos=this.pos+1,{type:"UnaryExpr",op:"-",operand:this.parseUnary()}):this.check(r.NOT)?(this.pos=this.pos+1,{type:"UnaryExpr",op:"!",operand:this.parseUnary()}):this.check(r.BANG)?(this.pos=this.pos+1,{type:"UnaryExpr",op:"!",operand:this.parseUnary()}):this.check(r.TILDE)?(this.pos=this.pos+1,{type:"UnaryExpr",op:"~",operand:this.parseUnary()}):this.check(r.PLUSPLUS)?(this.pos=this.pos+1,{type:"UpdateExpr",op:"++",prefix:!0,operand:this.parseUnary()}):this.check(r.MINUSMINUS)?(this.pos=this.pos+1,{type:"UpdateExpr",op:"--",prefix:!0,operand:this.parseUnary()}):this.check(r.AWAIT)?(this.pos=this.pos+1,{type:"AwaitExpr",operand:this.parseUnary()}):this.check(r.TYPEOF)?(this.pos=this.pos+1,{type:"TypeofExpr",operand:this.parseUnary()}):this.parseLambdaOrPostfix()}parseLambdaOrPostfix(){let t=this.pos;if(this.check(r.IDENT)||this.check(r.WILDCARD)){let e=this.skip().value??"_";if(this.check(r.ARROW)){this.pos=this.pos+1;let s=this.parseExpr();return{type:"LambdaExpr",params:[{name:e}],body:s}}this.pos=t}return this.parsePostfix()}parsePostfix(){let t=this.parsePrimary(),e=!0;for(;e;)if(this.check(r.PLUSPLUS))this.pos=this.pos+1,t={type:"UpdateExpr",op:"++",prefix:!1,operand:t};else if(this.check(r.MINUSMINUS))this.pos=this.pos+1,t={type:"UpdateExpr",op:"--",prefix:!1,operand:t};else if(this.check(r.DOT)){this.pos=this.pos+1;let s=this.peek(),i=this.skip().value;t={type:"MemberExpr",obj:t,prop:i}}else if(this.check(r.QUESTIONDOT))if(this.pos=this.pos+1,this.check(r.LPAREN)){let s=this.parseArgList();t={type:"OptCallExpr",callee:t,args:s}}else if(this.check(r.LBRACKET)){this.pos=this.pos+1;let s=this.parseExpr();this.eat(r.RBRACKET),t={type:"OptIndexExpr",obj:t,idx:s}}else{let s=this.skip().value;t={type:"OptMemberExpr",obj:t,prop:s}}else if(this.check(r.INSTANCEOF)){this.pos=this.pos+1;let s=this.eat(r.IDENT).value;t={type:"BinaryExpr",op:"instanceof",left:t,right:{type:"Identifier",name:s}}}else if(this.check(r.AS))if(this.pos=this.pos+1,this.check(r.CONST))this.pos=this.pos+1,t={type:"AsConstExpr",expr:t};else{let s=this.parseTypeAnn();t={type:"CastExpr",expr:t,castType:s}}else if(this.check(r.SATISFIES)){this.pos=this.pos+1;let s=this.parseTypeAnn();t={type:"SatisfiesExpr",expr:t,satType:s}}else if(this.check(r.IS)){this.pos=this.pos+1;let s=this.parseTypeAnn();t={type:"IsExpr",expr:t,isType:s}}else if(this.check(r.BANG))this.pos=this.pos+1,t={type:"NonNullExpr",expr:t};else if(this.check(r.LBRACKET)){this.pos=this.pos+1;let s=this.parseExpr();this.eat(r.RBRACKET),t={type:"IndexExpr",obj:t,idx:s}}else if(this.check(r.LPAREN)){let s=this.parseArgList();if(this.check(r.ARROW)){this.pos=this.pos+1;let i=this.parseExpr();return{type:"LambdaExpr",params:s.map(h=>{h.type=="Identifier"&&h.name}),body:i}}t={type:"CallExpr",callee:t,args:s}}else e=!1;return t}parseArgList(){this.eat(r.LPAREN);let t=[];for(;!this.check(r.RPAREN)&&!this.check(r.EOF)&&(this.check(r.DOTDOTDOT)?(this.pos=this.pos+1,t.push({type:"SpreadExpr",expr:this.parseExpr()})):t.push(this.parseExpr()),!!this.maybe(r.COMMA)););return this.eat(r.RPAREN),t}parsePrimary(){let t=this.peek();if(t.type==r.NUMBER)return this.pos=this.pos+1,{type:"NumberLit",value:t.value,loc:t};if(t.type==r.BOOL)return this.pos=this.pos+1,{type:"BoolLit",value:t.value,loc:t};if(t.type==r.NULL)return this.pos=this.pos+1,{type:"NullLit",loc:t};if(t.type==r.SELF)return this.pos=this.pos+1,{type:"SelfExpr",loc:t};if(t.type==r.WILDCARD)return this.pos=this.pos+1,{type:"Identifier",name:"_",loc:t};if(t.type==r.IDENT)return this.pos=this.pos+1,{type:"Identifier",name:t.value,loc:t};if(t.type==r.STRING)return this.pos=this.pos+1,t.value&&t.value.template?{type:"TemplateLit",parts:t.value.parts,loc:t}:{type:"StringLit",value:t.value,loc:t};if(t.type==r.REGEX)return this.pos=this.pos+1,{type:"RegexLit",value:t.value,loc:t};if(t.type==r.NEW){this.pos=this.pos+1;let e=this.eat(r.IDENT).value,s=this.parseArgList();return{type:"NewExpr",callee:e,args:s}}if(t.type==r.MATCH)return this.parseMatch();if(t.type==r.FN){this.pos=this.pos+1;let e=this.parseParamList();if(this.check(r.ARROW)){if(this.pos=this.pos+1,this.isTypeAnnBeforeColon()){let i=this.parseTypeAnn(),n=this.parseBlock();return{type:"FnDecl",name:null,params:e,retType:i,body:n,inline:!1,async:!1,loc:t}}let s=this.parseExpr();return{type:"FnDecl",name:null,params:e,retType:null,body:s,inline:!0,async:!1,loc:t}}if(this.check(r.COLON)){let s=this.parseBlock();return{type:"FnDecl",name:null,params:e,retType:null,body:s,inline:!1,async:!1,loc:t}}this.err("Expected -> or : after anonymous fn")}if(t.type==r.LPAREN){if(this.pos=this.pos+1,this.check(r.RPAREN)){if(this.pos=this.pos+1,this.check(r.ARROW)){this.pos=this.pos+1;let i=this.parseExpr();return{type:"LambdaExpr",params:[],body:i}}return{type:"NullLit"}}let e=this.parseExpr();if(this.check(r.RPAREN)){if(this.pos=this.pos+1,this.check(r.ARROW)){this.pos=this.pos+1;let i=this.parseExpr();return{type:"LambdaExpr",params:[{name:e.type=="Identifier"?e.name:"_"}],body:i}}return e}let s=[e];for(;this.maybe(r.COMMA);)s.push(this.parseExpr());if(this.eat(r.RPAREN),this.check(r.ARROW)){this.pos=this.pos+1;let i=this.parseExpr();return{type:"LambdaExpr",params:s.map(h=>{h.type=="Identifier"&&h.name}),body:i}}return s[0]}if(t.type==r.LBRACKET){this.pos=this.pos+1;let e=[];for(;!this.check(r.RBRACKET)&&!this.check(r.EOF)&&(this.check(r.DOTDOTDOT)?(this.pos=this.pos+1,e.push({type:"SpreadExpr",expr:this.parseExpr()})):e.push(this.parseExpr()),!!this.maybe(r.COMMA)););return this.eat(r.RBRACKET),{type:"ArrayExpr",items:e}}if(t.type==r.LBRACE){this.pos=this.pos+1;let e=[];for(;!this.check(r.RBRACE)&&!this.check(r.EOF);){if(this.check(r.DOTDOTDOT)){if(this.pos=this.pos+1,e.push({spread:!0,value:this.parseExpr()}),!this.maybe(r.COMMA))break;continue}let s=this.check(r.STRING)?this.eat(r.STRING).value:this.check(r.IDENT)?this.skip().value:this.skip().value;if(!this.check(r.COLON))e.push({key:s,value:{type:"Identifier",name:s}});else{this.eat(r.COLON);let i=this.parseExpr();e.push({key:s,value:i})}if(!this.maybe(r.COMMA))break}return this.eat(r.RBRACE),{type:"ObjectExpr",pairs:e}}this.err(`Unexpected token: ${t.type} (${JSON.stringify(t.value)})`)}};pt.exports.Parser=K;function te(a){return new K(a,0)}pt.exports.makeParser=te});var mt=S((rs,ft)=>{"use strict";var{Lexer:es,lexerize:ee,T:ss}=B(),{Parser:is,makeParser:se}=Q();function ie(a){let t=a.lastIndexOf(":");if(t<1)return null;let e=a.slice(t+1).trim();return e.length>0&&/[.<>^,dbeEfFgGoOxXs%bcn]/.test(e)&&/^([.<>^0\-+ #,]*[0-9]*\.?[0-9]*[dbeEfFgGoOxXs%bcn]?[,]?)$/.test(e)?{expr:a.slice(0,t).trim(),fmt:e}:null}var re=`function _fmt(v, s) {
24
23
  if (s === ',') return (+v).toLocaleString();
25
24
  if (s === '%') return ((+v)*100).toFixed(0)+'%';
26
25
  var m = s.match(/^([0-9,]*)?\\.([0-9]+)([fdgGeEb%x])$/);
@@ -34,368 +33,123 @@ function _fmt(v, s) {
34
33
  }
35
34
  var m2 = s.match(/^([0-9]*)d$/); if (m2) return Math.round(+v).toString();
36
35
  return String(v);
37
- }`,st=class extends Error{constructor(t,e){super(`${t}${e?` [${e.type}]`:""}`),this.name="CodeGenError"}};function ve(n){let t={};for(let e of n.body){let s=e.type==="ExportDecl"?e.decl:e;s.type==="ClassDecl"&&(t[s.name]={fields:s.fields,superClass:s.superClass})}return t}function gt(n,t,e=new Set){return!n||!t[n]||e.has(n)?[]:(e.add(n),[...gt(t[n].superClass,t,e),...t[n].fields])}var Tt=class{constructor(t={}){this.ind=t.indent||" ",this.level=0,this.lines=[],this.clsReg={},this.smBuilder=t.smBuilder||null,this._needsFmt=!1,this._loopDepth=0}i(){return this.ind.repeat(this.level)}emit(t){this.lines.push(this.i()+t)}emitRaw(t){this.lines.push(t)}blank(){this.lines.push("")}in(){this.level++}out(){this.level=Math.max(0,this.level-1)}_map(t){if(!this.smBuilder||!t)return;let e=this.lines.length,s=this.ind.repeat(this.level).length,r=(t.line||1)-1,a=(t.col||1)-1;this.smBuilder.addMapping(e,s,r,a)}generate(t){this.clsReg=ve(t),this.lines=[],this.level=0,this._needsFmt=!1,this.emit("// Generated by Flux Transpiler v3.2.0"),this.emit('"use strict";'),this.blank();for(let e of t.body)this.genStmt(e);return this._needsFmt&&this.lines.splice(2,0,Ae),{code:this.lines.join(`
38
- `),smBuilder:this.smBuilder}}genStmt(t){switch(this._map(t.loc),t.type){case"VarDecl":return this.genVar(t);case"DestructureDecl":return this.genDestructure(t);case"FnDecl":return this.genFn(t);case"ClassDecl":return this.genClass(t);case"IfStmt":return this.genIf(t);case"ForInStmt":return this.genFor(t);case"WhileStmt":return this.genWhile(t);case"MatchStmt":return this.genMatch(t);case"ReturnStmt":return this.genReturn(t);case"TryCatchStmt":return this.genTryCatch(t);case"ThrowStmt":return this.genThrow(t);case"DoWhileStmt":return this.genDoWhile(t);case"BreakStmt":return this.emit(t.label?`break ${t.label};`:"break;");case"ContinueStmt":return this.emit(t.label?`continue ${t.label};`:"continue;");case"LabeledStmt":return this.genLabeled(t);case"ImportDecl":return this.genImport(t);case"ExportDecl":return this.genExport(t);case"TypeDecl":return this.genTypeDecl(t);case"InterfaceDecl":return this.genInterfaceDecl(t);case"EnumDecl":return this.genEnumDecl(t);case"DeclareDecl":return;case"ExprStmt":return this.emit(this.genExpr(t.expr)+";");default:throw new st(`Unknown statement: ${t.type}`,t)}}genVar(t){let e=t.kind==="val"?"const":"let",s=t.init?` = ${this.genExpr(t.init)}`:"";this.emit(`${e} ${t.name}${s};`)}genDestructure(t){let e=t.kind==="val"?"const":"let",s=this.genExpr(t.init);if(t.patternType==="object"){let r=t.pattern.map(a=>{if(a.rest)return`...${a.key}`;let c=a.alias!==a.key?`${a.key}: ${a.alias}`:a.key;return a.defaultVal&&(c+=` = ${this.genExpr(a.defaultVal)}`),c}).join(", ");this.emit(`${e} { ${r} } = ${s};`)}else{let r=t.pattern.map(a=>{if(!a)return"";if(a.rest)return`...${a.name}`;let c=a.name;return a.defaultVal&&(c+=` = ${this.genExpr(a.defaultVal)}`),c}).join(", ");this.emit(`${e} [${r}] = ${s};`)}}genFn(t,e=""){let s=t.async?"async ":"",r=t.name||"",a=t.params.map(c=>c.rest?`...${c.name}`:c.defaultVal?`${c.name} = ${this.genExpr(c.defaultVal)}`:c.name).join(", ");if(t.inline)this.emit(`${e}${s}function ${r}(${a}) { return ${this.genExpr(t.body)}; }`);else{this.emit(`${e}${s}function ${r}(${a}) {`),this.in();for(let c of t.body)this.genStmt(c);this.out(),this.emit("}")}if(t.name&&t.decorators&&t.decorators.length>0)for(let c=t.decorators.length-1;c>=0;c--){let h=t.decorators[c],l=h.args.length>0?`(${h.args.map(p=>this.genExpr(p)).join(", ")})(${t.name})`:`(${t.name})`;this.emit(`${t.name} = ${h.name}${l};`)}}genClass(t){let e=t.superClass?` extends ${t.superClass}`:"";this.emit(`class ${t.name}${e} {`),this.in();let s=u=>u.modifiers&&u.modifiers.has("private"),r=u=>s(u)?`#${u.name}`:u.name,a=u=>s(u)?`this.#${u.name}`:`this.${u.name}`,c=t.fields.filter(s);for(let u of c)this.emit(`#${u.name};`);c.length>0&&this.blank();let h=gt(t.name,this.clsReg),l=h.filter(u=>u.init==null&&!s(u)),p=h.filter(u=>u.init!=null),m=t.fields.filter(u=>u.init!=null);if(l.length>0||p.length>0||c.length>0){let u=l.map(d=>d.name).join(", ");if(this.emit(`constructor(${u}) {`),this.in(),t.superClass&&this.clsReg[t.superClass]){let g=gt(t.superClass,this.clsReg).filter(f=>f.init==null);g.length>0&&this.emit(`super(${g.map(f=>f.name).join(", ")});`)}for(let d of t.fields.filter(g=>g.init==null&&!s(g)))this.emit(`${a(d)} = ${d.name};`);for(let d of m)this.emit(`${a(d)} = ${this.genExpr(d.init)};`);this.out(),this.emit("}"),this.blank()}for(let u of t.methods){let d=u.async?"async ":"",g=u.modifiers&&u.modifiers.has("static")?"static ":"",f=u.getset?`${u.getset} `:"",T=u.params.map(b=>b.rest?`...${b.name}`:b.defaultVal?`${b.name} = ${this.genExpr(b.defaultVal)}`:b.name).join(", ");if(u.inline)this.emit(`${g}${d}${f}${u.name}(${T}) { return ${this.genExpr(u.body)}; }`);else{this.emit(`${g}${d}${f}${u.name}(${T}) {`),this.in();for(let b of u.body)this.genStmt(b);this.out(),this.emit("}")}this.blank()}if(this.out(),this.emit("}"),t.decorators&&t.decorators.length>0)for(let u=t.decorators.length-1;u>=0;u--){let d=t.decorators[u],g=d.args.length>0?`(${d.args.map(f=>this.genExpr(f)).join(", ")})(${t.name})`:`(${t.name})`;this.emit(`${t.name} = ${d.name}${g};`)}this.blank()}genIf(t){this.emit(`if (${this.genExpr(t.cond)}) {`),this.in(),t.then.forEach(e=>this.genStmt(e)),this.out(),this.emit("}");for(let e of t.elseifs)this.emitRaw(this.i()+`else if (${this.genExpr(e.cond)}) {`),this.in(),e.body.forEach(s=>this.genStmt(s)),this.out(),this.emit("}");t.else_&&(this.emitRaw(this.i()+"else {"),this.in(),t.else_.forEach(e=>this.genStmt(e)),this.out(),this.emit("}"))}genFor(t){let e=t.iter,s=t.label?`${t.label}: `:"";if(e.type==="RangeExpr"){let r=this.genExpr(e.start),a=this.genExpr(e.end);this.emit(`${s}for (let ${t.var} = ${r}; ${t.var} < ${a}; ${t.var}++) {`)}else t.isAwait?this.emit(`${s}for await (const ${t.var} of ${this.genExpr(e)}) {`):this.emit(`${s}for (const ${t.var} of ${this.genExpr(e)}) {`);if(this._loopDepth++,this.in(),t.varPattern){let r=t.varPattern;if(r.type==="array"){let a=r.names.map(c=>c.rest?`...${c.name}`:c.name).join(", ");this.emit(`const [${a}] = ${t.var};`)}}t.body.forEach(r=>this.genStmt(r)),this.out(),this._loopDepth--,this.emit("}")}genLabeled(t){t.body.label=t.label,this.genStmt(t.body)}genWhile(t){let e=t.label?`${t.label}: `:"";this.emit(`${e}while (${this.genExpr(t.cond)}) {`),this._loopDepth++,this.in(),t.body.forEach(s=>this.genStmt(s)),this.out(),this._loopDepth--,this.emit("}")}genMatch(t){let e=this.genExpr(t.subject),s=t.arms,r=!1;s.forEach((a,c)=>{let h=a.pattern,l=null,p=[];if(h.type==="WildcardPat")l=null;else if(h.type==="RangePat"){let m=this.genExpr(h.start),y=this.genExpr(h.end);l=`${e} >= ${m} && ${e} <= ${y}`}else if(h.type==="VariantPat")l=`${e}?.__type === "${h.variant}"`,p=h.bindings.map((m,y)=>`const ${m} = ${e}.__args[${y}];`);else{let m=this.genExpr(h.value);h.value.type==="Identifier"&&/^[A-Z]/.test(h.value.name)?l=`(${e} === ${m} || ${e}?.__type === "${h.value.name}")`:l=`${e} === ${m}`}if(a.guard){let m=this.genExpr(a.guard);if(p.length>0){let y=`(function(){ ${p.map(u=>u.replace("const ","var ")).join(" ")} return (${m}); }())`;l=l?`(${l}) && ${y}`:y}else l=l?`(${l}) && (${m})`:m}!r&&l?(this.emit(`if (${l}) {`),r=!0):!r&&!l?(this.emit("if (true) {"),r=!0):r&&l?this.emitRaw(this.i()+`else if (${l}) {`):this.emitRaw(this.i()+"else {"),this.in();for(let m of p)this.emit(m);if(a.inline){let m=this.genExpr(a.body[0].expr);this._loopDepth>0?this.emit(`${m};`):this.emit(`return ${m};`)}else a.body.forEach(m=>this.genStmt(m));this.out(),this.emit("}")})}genInterfaceDecl(t){this.blank(),this.emit(`// interface ${t.name}`),this.blank()}genEnumDecl(t){this.blank();let e=t.members.map(s=>{let r=this.genExpr(s.value);return`${s.name}: ${r}`}).join(", ");this.emit(`const ${t.name} = Object.freeze({ ${e} });`),this.blank()}genTypeDecl(t){this.blank(),this.emit(`// ADT type: ${t.name}`);for(let e of t.variants)if(e.fields.length===0)this.emit(`const ${e.name} = Object.freeze({ __type: "${e.name}", __args: [] });`);else{let s=e.fields.join(", "),r=`[${e.fields.join(", ")}]`,a=e.fields.map(c=>`${c}: ${c}`).join(", ");this.emit(`function ${e.name}(${s}) { return Object.freeze({ __type: "${e.name}", __args: ${r}, ${a} }); }`)}this.blank()}genReturn(t){t.value?this.emit(`return ${this.genExpr(t.value)};`):this.emit("return;")}genTryCatch(t){if(this.emit("try {"),this.in(),t.tryBody.forEach(e=>this.genStmt(e)),this.out(),this.emit("}"),t.catchBody){let e=t.catchParam?`(${t.catchParam})`:"(_err)";this.emitRaw(this.i()+`catch ${e} {`),this.in(),t.catchBody.forEach(s=>this.genStmt(s)),this.out(),this.emit("}")}t.finallyBody&&(this.emitRaw(this.i()+"finally {"),this.in(),t.finallyBody.forEach(e=>this.genStmt(e)),this.out(),this.emit("}"))}genThrow(t){this.emit(`throw ${this.genExpr(t.value)};`)}genDoWhile(t){this.emit("do {"),this.in();for(let e of t.body)this.genStmt(e);this.out(),this.emit(`} while (${this.genExpr(t.cond)});`)}genImport(t){let e=typeof t.source=="string"?t.source:String(t.source);if(t.namespaceName)this.emit(`const ${t.namespaceName} = require("${e}");`);else if(t.defaultName)this.emit(`const ${t.defaultName} = require("${e}");`);else if(t.names.length){let s=t.names.map(r=>typeof r=="string"?r:r.name!==r.alias?`${r.name}: ${r.alias}`:r.name).join(", ");this.emit(`const { ${s} } = require("${e}");`)}}genExport(t){if(t.isDefault){this.emit(`module.exports = ${this.genExpr(t.decl)};`);return}let e=t.decl;switch(e.type){case"FnDecl":{let s=e.async?"async ":"",r=e.params.map(a=>a.rest?`...${a.name}`:a.defaultVal?`${a.name} = ${this.genExpr(a.defaultVal)}`:a.name).join(", ");e.inline?this.emit(`${s}function ${e.name}(${r}) { return ${this.genExpr(e.body)}; }`):(this.emit(`${s}function ${e.name}(${r}) {`),this.in(),e.body.forEach(a=>this.genStmt(a)),this.out(),this.emit("}")),this.emit(`module.exports.${e.name} = ${e.name};`);break}case"ClassDecl":this.genClass(e),this.emit(`module.exports.${e.name} = ${e.name};`);break;case"TypeDecl":this.genTypeDecl(e);for(let s of e.variants)this.emit(`module.exports.${s.name} = ${s.name};`);break;case"InterfaceDecl":this.genInterfaceDecl(e);break;case"EnumDecl":this.genEnumDecl(e),this.emit(`module.exports.${e.name} = ${e.name};`);break;case"VarDecl":{let s=e.kind==="val"?"const":"let";this.emit(`${s} ${e.name} = ${this.genExpr(e.init)};`),this.emit(`module.exports.${e.name} = ${e.name};`);break}default:this.genStmt(e)}}genExpr(t){if(!t)return"undefined";switch(t.type){case"NumberLit":return String(t.value);case"BoolLit":return String(t.value);case"NullLit":return"null";case"SelfExpr":return"this";case"Identifier":return t.name==="print"?"console.log":t.name;case"StringLit":return JSON.stringify(t.value);case"RegexLit":return`/${t.value.pattern}/${t.value.flags}`;case"TemplateLit":return this.genTemplate(t.parts);case"BinaryExpr":return`(${this.genExpr(t.left)} ${t.op} ${this.genExpr(t.right)})`;case"UnaryExpr":return`${t.op}${this.genExpr(t.operand)}`;case"UpdateExpr":return t.prefix?`${t.op}${this.genExpr(t.operand)}`:`${this.genExpr(t.operand)}${t.op}`;case"TernaryExpr":return`(${this.genExpr(t.cond)} ? ${this.genExpr(t.then)} : ${this.genExpr(t.else_)})`;case"AssignExpr":return`${this.genExpr(t.target)} ${t.op} ${this.genExpr(t.value)}`;case"AwaitExpr":return`await ${this.genExpr(t.operand)}`;case"TypeofExpr":return`typeof ${this.genExpr(t.operand)}`;case"SpreadExpr":return`...${this.genExpr(t.expr)}`;case"CallExpr":{let e=this.genExpr(t.callee),s=t.args.map(r=>this.genExpr(r)).join(", ");return`${e}(${s})`}case"MemberExpr":{let e=this.genExpr(t.obj);return`${t.obj.type==="NumberLit"?`(${e})`:e}.${t.prop}`}case"OptMemberExpr":return`${this.genExpr(t.obj)}?.${t.prop}`;case"OptIndexExpr":return`${this.genExpr(t.obj)}?.[${this.genExpr(t.idx)}]`;case"OptCallExpr":{let e=t.args.map(s=>this.genExpr(s)).join(", ");return`${this.genExpr(t.callee)}?.(${e})`}case"IndexExpr":return`${this.genExpr(t.obj)}[${this.genExpr(t.idx)}]`;case"NewExpr":{let e=t.args.map(s=>this.genExpr(s)).join(", ");return`new ${t.callee}(${e})`}case"LambdaExpr":{let e=t.params.map(s=>s.rest?`...${s.name}`:s.name).join(", ");if(t.block){let s=this.lines.length,r=this.level;this.emit(`(${e}) => {`),this.in();for(let c of t.body)this.genStmt(c);this.out(),this.emit("}");let a=this.lines.splice(s).map(c=>c.trimStart()).join(" ");return this.level=r,a}return`(${e}) => ${this.genExpr(t.body)}`}case"FnDecl":{let e=t.async?"async ":"",s=t.params.map(r=>r.rest?`...${r.name}`:r.defaultVal?`${r.name} = ${this.genExpr(r.defaultVal)}`:r.name).join(", ");if(t.inline)return`${e}function(${s}) { return ${this.genExpr(t.body)}; }`;{let r=this.lines.length,a=this.level;this.emit(`${e}function(${s}) {`),this.in();for(let h of t.body)this.genStmt(h);this.out(),this.emit("}");let c=this.lines.splice(r).map(h=>h.trimStart()).join(" ");return this.level=a,c}}case"MatchStmt":{let e=this.lines.length,s=this.level,r=this._loopDepth;this._loopDepth=0,this.emit("(() => {"),this.in(),this.genMatch(t),this.out(),this.emit("})()"),this._loopDepth=r;let a=this.lines.splice(e).map(c=>c.trimStart()).join(" ");return this.level=s,a}case"ArrayExpr":return`[${t.items.map(e=>this.genExpr(e)).join(", ")}]`;case"ObjectExpr":return`{ ${t.pairs.map(s=>{if(s.spread)return`...${this.genExpr(s.value)}`;if(s.computed)return`[${this.genExpr(s.keyExpr)}]: ${this.genExpr(s.value)}`;let r=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(s.key),a=r?s.key:`"${s.key}"`;return r&&s.value&&s.value.type==="Identifier"&&s.value.name===s.key?s.key:`${a}: ${this.genExpr(s.value)}`}).join(", ")} }`;case"RangeExpr":return`Array.from({ length: ${this.genExpr(t.end)} - ${this.genExpr(t.start)} }, (_, i) => i + ${this.genExpr(t.start)})`;case"PipeExpr":return this.genPipe(t);case"CastExpr":return this.genExpr(t.expr);case"AsConstExpr":return`Object.freeze(${this.genExpr(t.expr)})`;case"SatisfiesExpr":return this.genExpr(t.expr);case"IsExpr":return this.genExpr(t.expr);case"NonNullExpr":return this.genExpr(t.expr);default:throw new st(`Unknown expression: ${t.type}`,t)}}genTemplate(t){let{Lexer:e}=J(),{Parser:s}=et(),r="`";for(let a of t)if(a.type==="text")r+=a.value.replace(/`/g,"\\`").replace(/\$/g,"\\$");else{let c=Se(a.value),h=c?c.expr:a.value,l=c?c.fmt:null;try{let p=new e(h).tokenize(),m=new s(p).parseExpr(),y=this.genExpr(m);l?(this._needsFmt=!0,r+=`\${_fmt(${y}, ${JSON.stringify(l)})}`):r+=`\${${y}}`}catch{r+=`\${${a.value}}`}}return r+="`",r}genPipe(t){let e=this.genExpr(t.left),s=t.right;if(s.type==="Identifier")return`${this.genExpr(s)}(${e})`;if(s.type==="CallExpr"){let r=this.genExpr(s.callee),a=s.args.map(c=>this.genExpr(c)).join(", ");return a?`${r}(${e}, ${a})`:`${r}(${e})`}return`(${this.genExpr(s)})(${e})`}};Wt.exports={CodeGenerator:Tt,CodeGenError:st}});var Qt=_((ws,Ut)=>{"use strict";var Re="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function it(n){let t=n<0?-n<<1|1:n<<1,e="";do{let s=t&31;t>>>=5,t>0&&(s|=32),e+=Re[s]}while(t>0);return e}var bt=class{constructor(t,e){this.sourceFile=t,this.sourceContent=e,this.mappings=[]}addMapping(t,e,s,r){for(;this.mappings.length<=t;)this.mappings.push([]);this.mappings[t].push({genCol:e,srcLine:s,srcCol:r})}encodeMappings(){let t=0,e=0;return this.mappings.map(s=>{let r=0;return s.map(a=>{let c=[it(a.genCol-r),it(0),it(a.srcLine-t),it(a.srcCol-e)].join("");return r=a.genCol,t=a.srcLine,e=a.srcCol,c}).join(",")}).join(";")}toJSON(t=""){return{version:3,file:t,sourceRoot:"",sources:[this.sourceFile],sourcesContent:[this.sourceContent],names:[],mappings:this.encodeMappings()}}toString(t=""){return JSON.stringify(this.toJSON(t))}};Ut.exports={SourceMapBuilder:bt,encodeVLQ:it}});var Yt=_((As,Gt)=>{"use strict";var Nt={bg:n=>`background:${n}`,fg:n=>`color:${n}`,color:n=>`color:${n}`,p:n=>`padding:${n}`,px:n=>`paddingLeft:${n},paddingRight:${n}`,py:n=>`paddingTop:${n},paddingBottom:${n}`,pt:n=>`paddingTop:${n}`,pb:n=>`paddingBottom:${n}`,pl:n=>`paddingLeft:${n}`,pr:n=>`paddingRight:${n}`,m:n=>`margin:${n}`,mx:n=>`marginLeft:${n},marginRight:${n}`,my:n=>`marginTop:${n},marginBottom:${n}`,mt:n=>`marginTop:${n}`,mb:n=>`marginBottom:${n}`,ml:n=>`marginLeft:${n}`,mr:n=>`marginRight:${n}`,radius:n=>`borderRadius:${n}`,w:n=>`width:${n}`,h:n=>`height:${n}`,"min-w":n=>`minWidth:${n}`,"max-w":n=>`maxWidth:${n}`,"min-h":n=>`minHeight:${n}`,"max-h":n=>`maxHeight:${n}`,gap:n=>`gap:${n}`,"col-gap":n=>`columnGap:${n}`,"row-gap":n=>`rowGap:${n}`,text:n=>`fontSize:${n}`,font:n=>`fontFamily:${n}`,weight:n=>`fontWeight:${n}`,tracking:n=>`letterSpacing:${n}`,leading:n=>`lineHeight:${n}`,shadow:n=>`boxShadow:${n}`,opacity:n=>`opacity:${n}`,border:n=>`border:${n}`,outline:n=>`outline:${n}`,transition:n=>`transition:${n}`,cursor:n=>`cursor:${n}`,overflow:n=>`overflow:${n}`,z:n=>`zIndex:${n}`,transform:n=>`transform:${n}`,direction:n=>`flexDirection:${n}`,align:n=>`alignItems:${n}`,justify:n=>`justifyContent:${n}`,"align-self":n=>`alignSelf:${n}`,"place-items":n=>`placeItems:${n}`,grow:n=>`flexGrow:${n}`,shrink:n=>`flexShrink:${n}`,basis:n=>`flexBasis:${n}`,cols:n=>`gridTemplateColumns:${n}`,rows:n=>`gridTemplateRows:${n}`,inset:n=>`inset:${n}`,top:n=>`top:${n}`,right:n=>`right:${n}`,bottom:n=>`bottom:${n}`,left:n=>`left:${n}`,"object-fit":n=>`objectFit:${n}`,"line-height":n=>`lineHeight:${n}`,"text-align":n=>`textAlign:${n}`,decoration:n=>`textDecoration:${n}`,clip:n=>`clipPath:${n}`,filter:n=>`filter:${n}`,backdrop:n=>`backdropFilter:${n}`,animation:n=>`animation:${n}`},rt={flex:'display:"flex"',grid:'display:"grid"',block:'display:"block"',"inline-flex":'display:"inline-flex"',"inline-block":'display:"inline-block"',bold:"fontWeight:700",italic:'fontStyle:"italic"',underline:'textDecoration:"underline"',pointer:'cursor:"pointer"',hidden:'display:"none"',relative:'position:"relative"',absolute:'position:"absolute"',fixed:'position:"fixed"',sticky:'position:"sticky"',"flex-col":'flexDirection:"column"',"flex-row":'flexDirection:"row"',"flex-wrap":'flexWrap:"wrap"',"flex-1":"flex:1","w-full":'width:"100%"',"h-full":'height:"100%"',center:'textAlign:"center"',truncate:'overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"',"select-none":'userSelect:"none"',"no-wrap":'whiteSpace:"nowrap"',"no-list":'listStyle:"none"',"no-outline":'outline:"none"',"no-border":'border:"none"',"box-border":'boxSizing:"border-box"'},Ss=new Set([...Object.keys(Nt),...Object.keys(rt)]),ht=class{constructor(t){this.src=t,this.pos=0,this.out=""}transform(){for(;this.pos<this.src.length;)this.scanTop();return this.hasJsx=this.out!==this.src,this.out}scanTop(){let t=this.src[this.pos];if(t==="/"&&this.src[this.pos+1]==="/"){let e=this.src.indexOf(`
39
- `,this.pos);e===-1?(this.out+=this.src.slice(this.pos),this.pos=this.src.length):(this.out+=this.src.slice(this.pos,e+1),this.pos=e+1);return}if(t==="/"&&this.src[this.pos+1]==="*"){let e=this.src.indexOf("*/",this.pos+2);e===-1?(this.out+=this.src.slice(this.pos),this.pos=this.src.length):(this.out+=this.src.slice(this.pos,e+2),this.pos=e+2);return}if(t==='"'){this.passString('"');return}if(t==="'"){this.passString("'");return}if(t==="`"){this.passTemplateLit();return}if(t==="<"&&this.isJsxStart()){let e=this.parseJsxElement();this.out+=e;return}this.out+=t,this.pos++}isJsxStart(){let t=this.src[this.pos+1]||"";if(!(t===">"||t>="a"&&t<="z"||t>="A"&&t<="Z"))return!1;let e=this.pos-1;for(;e>=0&&(this.src[e]===" "||this.src[e]===" ");)e--;if(e<0)return!0;let s=this.src[e];if(`=([{,:>
40
- ?`.includes(s))return!0;if(/[a-z]/.test(s)){let r=e;for(;r>=0&&/[a-z]/.test(this.src[r]);)r--;let a=this.src.slice(r+1,e+1);if(new Set(["return","not","and","or","val","var","await","yield","else","in","throw"]).has(a))return!0}return!1}passString(t){for(this.out+=t,this.pos++;this.pos<this.src.length;){let e=this.src[this.pos];if(e==="\\"){this.out+=e+(this.src[this.pos+1]||""),this.pos+=2;continue}if(e===t){this.out+=e,this.pos++;return}this.out+=e,this.pos++}}passTemplateLit(){for(this.out+="`",this.pos++;this.pos<this.src.length;){let t=this.src[this.pos];if(t==="\\"){this.out+=t+(this.src[this.pos+1]||""),this.pos+=2;continue}if(t==="`"){this.out+=t,this.pos++;return}this.out+=t,this.pos++}}parseJsxElement(){if(this.pos++,this.src[this.pos]===">"){this.pos++;let s=this.parseJsxChildren("");return this.expectClose(""),`_fluxH("",null${s.length?","+s.join(","):""})`}let t=this.readTagName(),e=this.parseJsxAttrs();if(this.src[this.pos]==="/"&&this.src[this.pos+1]===">")return this.pos+=2,`_fluxH("${t}",${e})`;if(this.src[this.pos]===">"){this.pos++;let s=this.parseJsxChildren(t);this.expectClose(t);let r=s.length?","+s.join(","):"";return`_fluxH("${t}",${e}${r})`}return`<${t}`}readTagName(){let t="";for(;this.pos<this.src.length;){let e=this.src[this.pos];if(/[a-zA-Z0-9\-_\.]/.test(e))t+=e,this.pos++;else break}return t}parseJsxAttrs(){this.skipWs();let t=[],e=[],s=null;for(;this.pos<this.src.length;){let r=this.src[this.pos];if(r===">"||r==="/"&&this.src[this.pos+1]===">"||(this.skipWs(),!/[a-zA-Z_\-]/.test(this.src[this.pos])))break;let a="";for(;this.pos<this.src.length&&/[a-zA-Z0-9\-_:]/.test(this.src[this.pos]);)a+=this.src[this.pos++];if(this.skipWs(),this.src[this.pos]!=="="){rt[a]!==void 0?e.push(rt[a]):t.push(`"${a}":true`);continue}this.pos++,this.skipWs();let c=this.src[this.pos],h=null,l=null;if(c==='"'||c==="'"){let p=c;this.pos++;let m="";for(;this.pos<this.src.length&&this.src[this.pos]!==p;)this.src[this.pos]==="\\"?(m+=this.src[this.pos]+this.src[this.pos+1],this.pos+=2):m+=this.src[this.pos++];this.pos++,h=m}else if(c==="{")l=this.readBraced();else{rt[a]!==void 0?e.push(rt[a]):t.push(`"${a}":true`),this.skipWs();continue}if(h!==null&&Nt[a]){let p=Nt[a](JSON.stringify(h));e.push(p)}else l!==null&&a==="style"?s=l:h!==null?t.push(`"${a}":${JSON.stringify(h)}`):t.push(`"${a}":${l}`);this.skipWs()}if(e.length>0||s!==null){let r=e.length>0?`{${e.join(",")}}`:null;s!==null&&r!==null?t.push(`"style":Object.assign(${s},${r})`):s!==null?t.push(`"style":${s}`):t.push(`"style":{${e.join(",")}}`)}return t.length?`{${t.join(",")}}`:"null"}readBraced(){this.pos++;let t=1,e="";for(;this.pos<this.src.length&&t>0;){let s=this.src[this.pos];if(s==="{"&&t++,s==="}"&&(t--,t===0)){this.pos++;break}e+=s,this.pos++}return e.trim()}parseJsxChildren(t){let e=[];for(;this.pos<this.src.length&&!(this.src[this.pos]==="<"&&this.src[this.pos+1]==="/");){if(this.src[this.pos]==="<"){let a=this.src[this.pos+1]||"";if(a>="a"&&a<="z"||a>="A"&&a<="Z"||a===">"){e.push(this.parseJsxElement());continue}}if(this.src[this.pos]==="{"){let a=this.readBraced();a.trim()&&e.push(a);continue}let s="";for(;this.pos<this.src.length;){let a=this.src[this.pos];if(a==="<"||a==="{")break;s+=a,this.pos++}let r=s.replace(/\s+/g," ").trim();r&&e.push(JSON.stringify(r))}return e}expectClose(t){if(this.src[this.pos]==="<"&&this.src[this.pos+1]==="/"){for(this.pos+=2;this.pos<this.src.length&&this.src[this.pos]!==">";)this.pos++;this.src[this.pos]===">"&&this.pos++}}skipWs(){for(;this.pos<this.src.length&&(this.src[this.pos]===" "||this.src[this.pos]===" ");)this.pos++}},Vt=`
41
- function _fluxH(tag,props,...children){
36
+ }`;function ne(a){let t={};for(let e of a.body){let s=e.type=="ExportDecl"?e.decl:e;s.type=="ClassDecl"&&(t[s.name]={fields:s.fields,superClass:s.superClass})}return t}function ut(a,t,e){let s=e??new Set([]);return!a||!t[a]||s.has(a)?[]:(s.add(a),[...ut(t[a].superClass,t,s),...t[a].fields])}var X=class{constructor(t,e,s,i,n,h,l,c,o){this.ind=t,this.level=e,this.lines=s,this.clsReg=i,this.smBuilder=n,this._needsFmt=h,this._loopDepth=l,this._fnDepth=c,this._version=o}i(){let t="",e=this.level;for(;e>0;)t+=this.ind,e=e-1;return t}emit(t){this.lines.push(this.i()+t)}emitRaw(t){this.lines.push(t)}blank(){this.lines.push("")}indIn(){this.level=this.level+1}indOut(){this.level>0&&(this.level=this.level-1)}generate(t){this.clsReg=ne(t),this.lines=[],this.level=0,this._needsFmt=!1,this.emit("// Generated by Flux Transpiler v"+(this._version??"3.5.3")+" (self-hosted)"),this.emit('"use strict";'),this.blank();for(let e of t.body)this.genStmt(e);return this._needsFmt&&this.lines.splice(2,0,re),{code:this.lines.join(`
37
+ `),smBuilder:this.smBuilder}}genStmt(t){if(t.type=="VarDecl")this.genVar(t);else if(t.type=="DestructureDecl")this.genDestructure(t);else if(t.type=="FnDecl")this.genFn(t,"");else if(t.type=="ClassDecl")this.genClass(t);else if(t.type=="IfStmt")this.genIf(t);else if(t.type=="ForInStmt")this.genFor(t);else if(t.type=="WhileStmt")this.genWhile(t);else if(t.type=="MatchStmt")this.genMatch(t);else if(t.type=="ReturnStmt")this.genReturn(t);else if(t.type=="TryCatchStmt")this.genTryCatch(t);else if(t.type=="ThrowStmt")this.genThrow(t);else if(t.type=="DoWhileStmt")this.genDoWhile(t);else if(t.type=="BreakStmt")this.emit("break;");else if(t.type=="ContinueStmt")this.emit("continue;");else if(t.type=="ImportDecl")this.genImport(t);else if(t.type=="ExportDecl")this.genExport(t);else if(t.type=="TypeDecl")this.genTypeDecl(t);else if(t.type=="InterfaceDecl")this.genInterfaceDecl(t);else if(t.type=="EnumDecl")this.genEnumDecl(t);else{if(t.type=="DeclareDecl")return;if(t.type=="ExprStmt")this.emit(this.genExpr(t.expr)+";");else throw new Error(`Unknown statement: ${t.type}`)}}genVar(t){let e=t.kind=="val"?"const":"let",s=t.init?" = "+this.genExpr(t.init):"";this.emit(e+" "+t.name+s+";")}genObjPair(t){if(t.spread)return"..."+this.genExpr(t.value);let e=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(t.key),s=e?t.key:'"'+t.key+'"';return e&&t.value&&t.value.type=="Identifier"&&t.value.name==t.key?t.key:s+": "+this.genExpr(t.value)}genDestructProp(t){if(t.rest)return"..."+t.key;let e=t.alias!=t.key?t.key+": "+t.alias:t.key;return t.defaultVal&&(e=e+" = "+this.genExpr(t.defaultVal)),e}genDestructItem(t){if(!t)return"";if(t.rest)return"..."+t.name;let e=t.name;return t.defaultVal&&(e=e+" = "+this.genExpr(t.defaultVal)),e}genDestructure(t){let e=t.kind=="val"?"const":"let",s=this.genExpr(t.init);if(t.patternType=="object"){let i=t.pattern.map(n=>this.genDestructProp(n)).join(", ");this.emit(e+" { "+i+" } = "+s+";")}else{let i=t.pattern.map(n=>this.genDestructItem(n)).join(", ");this.emit(e+" ["+i+"] = "+s+";")}}genFn(t,e){let s=t.async?"async ":"",i=t.name??"",n=t.params.map(h=>h.rest?"..."+h.name:h.defaultVal?h.name+" = "+this.genExpr(h.defaultVal):h.name).join(", ");if(t.inline)this.emit(e+s+"function "+i+"("+n+") { return "+this.genExpr(t.body)+"; }");else{this.emit(e+s+"function "+i+"("+n+") {"),this.indIn(),this._fnDepth=this._fnDepth+1;for(let h of t.body)this.genStmt(h);this._fnDepth=this._fnDepth-1,this.indOut(),this.emit("}")}}genClass(t){let e=t.superClass?" extends "+t.superClass:"";this.emit("class "+t.name+e+" {"),this.indIn();let s=ut(t.name,this.clsReg,null);if(s.length>0){let i=s.map(n=>n.name).join(", ");if(this.emit("constructor("+i+") {"),this.indIn(),t.superClass&&this.clsReg[t.superClass]){let n=ut(t.superClass,this.clsReg,null);n.length>0&&this.emit("super("+n.map(h=>h.name).join(", ")+");")}for(let n of t.fields)this.emit("this."+n.name+" = "+n.name+";");this.indOut(),this.emit("}"),this.blank()}for(let i of t.methods){let n=i.async?"async ":"",h=i.modifiers&&i.modifiers.has("static")?"static ":"",l=i.params.map(c=>c.rest?"..."+c.name:c.defaultVal?c.name+" = "+this.genExpr(c.defaultVal):c.name).join(", ");if(i.inline)this.emit(h+n+i.name+"("+l+") { return "+this.genExpr(i.body)+"; }");else{this.emit(h+n+i.name+"("+l+") {"),this.indIn(),this._fnDepth=this._fnDepth+1;for(let c of i.body)this.genStmt(c);this._fnDepth=this._fnDepth-1,this.indOut(),this.emit("}")}this.blank()}this.indOut(),this.emit("}"),this.blank()}genIf(t){this.emit("if ("+this.genExpr(t.cond)+") {"),this.indIn();for(let e of t.then)this.genStmt(e);this.indOut(),this.emit("}");for(let e of t.elseifs){this.emitRaw(this.i()+"else if ("+this.genExpr(e.cond)+") {"),this.indIn();for(let s of e.body)this.genStmt(s);this.indOut(),this.emit("}")}if(t.else_){this.emitRaw(this.i()+"else {"),this.indIn();for(let e of t.else_)this.genStmt(e);this.indOut(),this.emit("}")}}genFor(t){let e=t.var,s=t.iter;if(s.type=="RangeExpr"){let i=this.genExpr(s.start),n=this.genExpr(s.end);this.emit("for (let "+e+" = "+i+"; "+e+" < "+n+"; "+e+"++) {")}else t.isAwait?this.emit("for await (const "+e+" of "+this.genExpr(s)+") {"):this.emit("for (const "+e+" of "+this.genExpr(s)+") {");this._loopDepth=this._loopDepth+1,this.indIn();for(let i of t.body)this.genStmt(i);this.indOut(),this._loopDepth=this._loopDepth-1,this.emit("}")}genWhile(t){this.emit("while ("+this.genExpr(t.cond)+") {"),this._loopDepth=this._loopDepth+1,this.indIn();for(let e of t.body)this.genStmt(e);this.indOut(),this._loopDepth=this._loopDepth-1,this.emit("}")}genMatch(t){let e=this.genExpr(t.subject),s=t.arms,i=!1;for(let n of s){let h=n.pattern,l="",c=[];if(h.type=="WildcardPat")l="";else if(h.type=="RangePat"){let o=this.genExpr(h.start),u=this.genExpr(h.end);l=e+" >= "+o+" && "+e+" <= "+u}else if(h.type=="VariantPat"){l=e+'?.__type === "'+h.variant+'"';let o=0;for(let u of h.bindings)c.push("const "+u+" = "+e+".__args["+o+"];"),o=o+1}else{let o=this.genExpr(h.value);h.value.type=="Identifier"&&/^[A-Z]/.test(h.value.name)?l="("+e+" === "+o+" || "+e+'?.__type === "'+h.value.name+'")':l=e+" === "+o}if(n.guard){let o=this.genExpr(n.guard);if(c.length>0){let y="(function(){ "+c.map(g=>g.replace("const ","var ")).join(" ")+" return ("+o+"); }())";l=l?"("+l+") && "+y:y}else l=l?"("+l+") && ("+o+")":o}!i&&l?(this.emit("if ("+l+") {"),i=!0):!i&&!l?(this.emit("if (true) {"),i=!0):i&&l?this.emitRaw(this.i()+"else if ("+l+") {"):this.emitRaw(this.i()+"else {"),this.indIn();for(let o of c)this.emit(o);if(n.inline){let o=this.genExpr(n.body[0].expr);this._loopDepth>0?this.emit(o+";"):this._fnDepth>0?this.emit("return "+o+";"):this.emit(o+";")}else for(let o of n.body)this.genStmt(o);this.indOut(),this.emit("}")}}genInterfaceDecl(t){this.blank(),this.emit("// interface "+t.name),this.blank()}genEnumDecl(t){this.blank();let e=t.members.map(s=>s.name+": "+this.genExpr(s.value)).join(", ");this.emit("const "+t.name+" = Object.freeze({ "+e+" });"),this.blank()}genTypeDecl(t){this.blank(),this.emit("// ADT type: "+t.name);for(let e of t.variants)if(e.fields.length==0)this.emit("const "+e.name+' = Object.freeze({ __type: "'+e.name+'", __args: [] });');else{let s=e.fields.join(", "),i="["+e.fields.join(", ")+"]",n=e.fields.map(h=>h+": "+h).join(", ");this.emit("function "+e.name+"("+s+') { return Object.freeze({ __type: "'+e.name+'", __args: '+i+", "+n+" }); }")}this.blank()}genReturn(t){t.value?this.emit("return "+this.genExpr(t.value)+";"):this.emit("return;")}genTryCatch(t){this.emit("try {"),this.indIn();for(let e of t.tryBody)this.genStmt(e);if(this.indOut(),this.emit("}"),t.catchBody){let e=t.catchParam?"("+t.catchParam+")":"(_err)";this.emitRaw(this.i()+"catch "+e+" {"),this.indIn();for(let s of t.catchBody)this.genStmt(s);this.indOut(),this.emit("}")}if(t.finallyBody){this.emitRaw(this.i()+"finally {"),this.indIn();for(let e of t.finallyBody)this.genStmt(e);this.indOut(),this.emit("}")}}genThrow(t){this.emit("throw "+this.genExpr(t.value)+";")}genDoWhile(t){this.emit("do {"),this.indIn();for(let e of t.body)this.genStmt(e);this.indOut(),this.emit("} while ("+this.genExpr(t.cond)+");")}genImport(t){let e=String(t.source);if(t.namespaceName)this.emit("const "+t.namespaceName+' = require("'+e+'");');else if(t.defaultName)this.emit("const "+t.defaultName+' = require("'+e+'");');else if(t.names.length){let s=t.names.map(i=>typeof i=="string"?i:i.name!=i.alias?i.name+": "+i.alias:i.name).join(", ");this.emit("const { "+s+' } = require("'+e+'");')}}genExport(t){if(t.isDefault){this.emit("module.exports = "+this.genExpr(t.decl)+";");return}let e=t.decl;if(e.type=="FnDecl"){let s=e.async?"async ":"",i=e.params.map(n=>n.rest?"..."+n.name:n.defaultVal?n.name+" = "+this.genExpr(n.defaultVal):n.name).join(", ");if(e.inline)this.emit(s+"function "+e.name+"("+i+") { return "+this.genExpr(e.body)+"; }");else{this.emit(s+"function "+e.name+"("+i+") {"),this.indIn();for(let n of e.body)this.genStmt(n);this.indOut(),this.emit("}")}this.emit("module.exports."+e.name+" = "+e.name+";")}else if(e.type=="ClassDecl")this.genClass(e),this.emit("module.exports."+e.name+" = "+e.name+";");else if(e.type=="TypeDecl"){this.genTypeDecl(e);for(let s of e.variants)this.emit("module.exports."+s.name+" = "+s.name+";")}else if(e.type=="InterfaceDecl")this.genInterfaceDecl(e);else if(e.type=="EnumDecl")this.genEnumDecl(e),this.emit("module.exports."+e.name+" = "+e.name+";");else if(e.type=="VarDecl"){let s=e.kind=="val"?"const":"let";this.emit(s+" "+e.name+" = "+this.genExpr(e.init)+";"),this.emit("module.exports."+e.name+" = "+e.name+";")}else this.genStmt(e)}genExpr(t){if(!t)return"undefined";if(t.type=="NumberLit"||t.type=="BoolLit")return String(t.value);if(t.type=="NullLit")return"null";if(t.type=="SelfExpr")return"this";if(t.type=="Identifier")return t.name=="print"?"console.log":t.name;if(t.type=="StringLit")return JSON.stringify(t.value);if(t.type=="RegexLit")return"/"+t.value.pattern+"/"+t.value.flags;if(t.type=="TemplateLit")return this.genTemplate(t.parts);if(t.type=="BinaryExpr")return"("+this.genExpr(t.left)+" "+t.op+" "+this.genExpr(t.right)+")";if(t.type=="UnaryExpr")return t.op+this.genExpr(t.operand);if(t.type=="UpdateExpr")return t.prefix?t.op+this.genExpr(t.operand):this.genExpr(t.operand)+t.op;if(t.type=="TernaryExpr")return"("+this.genExpr(t.cond)+" ? "+this.genExpr(t.then)+" : "+this.genExpr(t.else_)+")";if(t.type=="AssignExpr")return this.genExpr(t.target)+" "+t.op+" "+this.genExpr(t.value);if(t.type=="AwaitExpr")return"await "+this.genExpr(t.operand);if(t.type=="TypeofExpr")return"typeof "+this.genExpr(t.operand);if(t.type=="SpreadExpr")return"..."+this.genExpr(t.expr);if(t.type=="CallExpr"){let e=this.genExpr(t.callee),s=t.args.map(i=>this.genExpr(i)).join(", ");return e+"("+s+")"}if(t.type=="MemberExpr"){let e=this.genExpr(t.obj);return(t.obj.type=="NumberLit"?"("+e+")":e)+"."+t.prop}if(t.type=="OptMemberExpr")return this.genExpr(t.obj)+"?."+t.prop;if(t.type=="OptIndexExpr")return this.genExpr(t.obj)+"?.["+this.genExpr(t.idx)+"]";if(t.type=="OptCallExpr"){let e=t.args.map(s=>this.genExpr(s)).join(", ");return this.genExpr(t.callee)+"?.("+e+")"}if(t.type=="IndexExpr")return this.genExpr(t.obj)+"["+this.genExpr(t.idx)+"]";if(t.type=="NewExpr"){let e=t.args.map(s=>this.genExpr(s)).join(", ");return"new "+t.callee+"("+e+")"}if(t.type=="LambdaExpr")return"("+t.params.map(s=>s.rest?"..."+s.name:s.name).join(", ")+") => "+this.genExpr(t.body);if(t.type=="FnDecl"){let e=t.async?"async ":"",s=t.params.map(l=>l.rest?"..."+l.name:l.defaultVal?l.name+" = "+this.genExpr(l.defaultVal):l.name).join(", ");if(t.inline)return e+"function("+s+") { return "+this.genExpr(t.body)+"; }";let i=this.lines.length,n=this.level;this.emit(e+"function("+s+") {"),this.indIn();for(let l of t.body)this.genStmt(l);this.indOut(),this.emit("}");let h=this.lines.splice(i).map(l=>l.trimStart()).join(" ");return this.level=n,h}if(t.type=="MatchStmt"){let e=this.lines.length,s=this.level,i=this._loopDepth;this._loopDepth=0,this._fnDepth=this._fnDepth+1,this.emit("(() => {"),this.indIn(),this.genMatch(t),this.indOut(),this.emit("})()"),this._fnDepth=this._fnDepth-1,this._loopDepth=i;let n=this.lines.splice(e).map(h=>h.trimStart()).join(" ");return this.level=s,n}if(t.type=="ArrayExpr")return"["+t.items.map(e=>this.genExpr(e)).join(", ")+"]";if(t.type=="ObjectExpr")return"{ "+t.pairs.map(s=>this.genObjPair(s)).join(", ")+" }";if(t.type=="RangeExpr")return"Array.from({ length: "+this.genExpr(t.end)+" - "+this.genExpr(t.start)+" }, (_, i) => i + "+this.genExpr(t.start)+")";if(t.type=="PipeExpr")return this.genPipe(t);if(t.type=="CastExpr")return this.genExpr(t.expr);if(t.type=="AsConstExpr")return"Object.freeze("+this.genExpr(t.expr)+")";if(t.type=="SatisfiesExpr")return this.genExpr(t.expr);if(t.type=="IsExpr")return this.genExpr(t.expr);if(t.type=="NonNullExpr")return this.genExpr(t.expr);throw new Error(`Unknown expression: ${t.type}`)}genTemplate(t){let e="`";for(let s of t)if(s.type=="text")e+=s.value.replace(/`/g,"\\`").replace(/\$/g,"\\$");else{let i=ie(s.value),n=i?i.expr:s.value,h=i?i.fmt:null;try{let l=ee(n).tokenize(),c=se(l).parseExpr(),o=this.genExpr(c);h?(this._needsFmt=!0,e+="${_fmt("+o+", "+JSON.stringify(h)+")}"):e+="${"+o+"}"}catch{e+="${"+s.value+"}"}}return e+="`",e}genPipe(t){let e=this.genExpr(t.left),s=t.right;if(s.type=="Identifier")return this.genExpr(s)+"("+e+")";if(s.type=="CallExpr"){let i=this.genExpr(s.callee),n=s.args.map(h=>this.genExpr(h)).join(", ");return n?i+"("+e+", "+n+")":i+"("+e+")"}return"("+this.genExpr(s)+")("+e+")"}};ft.exports.CodeGenerator=X;function ae(a){let t=(a==null?void 0:a.indent)??" ",e=(a==null?void 0:a.smBuilder)??null,s=(a==null?void 0:a.version)??"3.5.3";return new X(t,0,[],{},e,!1,0,s)}ft.exports.makeCodeGen=ae});var Ot=S((ns,j)=>{"use strict";var bt={bg:"background",fg:"color",p:"padding",px:"padding-inline",py:"padding-block",pt:"padding-top",pb:"padding-bottom",pl:"padding-left",pr:"padding-right",m:"margin",mx:"margin-inline",my:"margin-block",mt:"margin-top",mb:"margin-bottom",ml:"margin-left",mr:"margin-right",radius:"border-radius",w:"width",h:"height","min-w":"min-width","max-w":"max-width","min-h":"min-height","max-h":"max-height",gap:"gap","col-gap":"column-gap","row-gap":"row-gap",text:"font-size",font:"font-family",weight:"font-weight",tracking:"letter-spacing",leading:"line-height",shadow:"box-shadow",opacity:"opacity",border:"border",outline:"outline",transition:"transition",cursor:"cursor",overflow:"overflow","overflow-x":"overflow-x","overflow-y":"overflow-y",z:"z-index",transform:"transform",content:"content",resize:"resize",appearance:"appearance","object-fit":"object-fit","accent-color":"accent-color",direction:"flex-direction",wrap:"flex-wrap",align:"align-items",justify:"justify-content","align-self":"align-self","justify-self":"justify-self",grow:"flex-grow",shrink:"flex-shrink",basis:"flex-basis",order:"order",cols:"grid-template-columns",rows:"grid-template-rows","col-span":"grid-column","row-span":"grid-row","place-items":"place-items","place-content":"place-content","list-style":"list-style","text-align":"text-align",decoration:"text-decoration","text-transform":"text-transform","white-space":"white-space","word-break":"word-break","user-select":"user-select","pointer-events":"pointer-events","vertical-align":"vertical-align",backdrop:"backdrop-filter",filter:"filter",clip:"clip-path",animation:"animation",position:"position",top:"top",right:"right",bottom:"bottom",left:"left",inset:"inset",color:"color",background:"background"};j.exports.CSS_PROP_MAP=bt;var At={flex:"display: flex",grid:"display: grid",block:"display: block",inline:"display: inline","inline-flex":"display: inline-flex","inline-block":"display: inline-block","inline-grid":"display: inline-grid",bold:"font-weight: 700",italic:"font-style: italic",relative:"position: relative",absolute:"position: absolute",fixed:"position: fixed",sticky:"position: sticky",hidden:"display: none",pointer:"cursor: pointer",underline:"text-decoration: underline","line-through":"text-decoration: line-through",capitalize:"text-transform: capitalize",uppercase:"text-transform: uppercase",lowercase:"text-transform: lowercase",truncate:"overflow: hidden; text-overflow: ellipsis; white-space: nowrap","select-none":"user-select: none","no-wrap":"white-space: nowrap","no-list":"list-style: none","no-outline":"outline: none","no-border":"border: none","no-bg":"background: transparent","no-padding":"padding: 0","no-margin":"margin: 0","no-resize":"resize: none",center:"text-align: center","items-center":"align-items: center","justify-center":"justify-content: center","place-center":"place-items: center","flex-col":"flex-direction: column","flex-row":"flex-direction: row","flex-wrap":"flex-wrap: wrap","flex-1":"flex: 1","w-full":"width: 100%","h-full":"height: 100%","w-screen":"width: 100vw","h-screen":"height: 100vh","box-border":"box-sizing: border-box"};j.exports.CSS_BOOL_MAP=At;function he(a){let t=a.trim();return bt[t]??t}function le(a){let t=a.trim();if(t.length>=2){let e=t[0],s=t[t.length-1];if(e=='"'&&s=='"'||e=="'"&&s=="'")return t.slice(1,-1)}return t}function wt(a,t){let e=a.trim();return!t||e.startsWith("@")||t.startsWith("@keyframes")||t.startsWith("@font-face")?e:e.includes("&")?e.replace(/&/g,t):t+" "+e}var yt=class{constructor(t,e,s,i,n){this.content=t,this.indentLevel=e,this.rules=s,this.atRuleSegs=i,this.selStack=n}curSel(){return this.selStack.length==0?null:this.selStack[this.selStack.length-1]}findOrCreateRule(t){for(let s of this.rules)if(s.sel==t)return s;let e={sel:t,decls:[]};return this.rules.push(e),e}addDecl(t,e){this.findOrCreateRule(t).decls.push(e)}addDeclarationLine(t,e){if(t.includes(";")){let n=t.split(";");for(let h of n){let l=h.trim();l&&this.addDeclarationLine(l,e)}return}let s=At[t];if(s){let n=s.split(";");for(let h of n){let l=h.trim();l&&this.addDecl(e,l)}return}let i=t.indexOf(":");if(i!=-1){let n=he(t.slice(0,i)),h=le(t.slice(i+1));h!=""&&this.addDecl(e,n+": "+h)}}collectBlock(t,e){let s=1,i="",n=e;for(;n<t.length&&s>0;){let h=t[n];n=n+1;for(let l of h)l=="{"?s=s+1:l=="}"&&(s=s-1);if(s>0)i=i+h+`
38
+ `;else{let l=h.lastIndexOf("}");l>0&&(i=i+h.slice(0,l)+`
39
+ `)}}return{inner:i,nextI:n}}parse(){let t=this.content.split(`
40
+ `),e=0;for(;e<t.length;){let s=t[e];e=e+1;let i=s.trim();if(!i||i.startsWith("//"))continue;let n=i.indexOf("{"),h=i.lastIndexOf("}");if(i.startsWith("@keyframes")||i.startsWith("@font-face")){let l=n!=-1?i.slice(0,n).trim():i.trim(),c="";if(n!=-1&&h!=-1&&h>n)c=i.slice(n+1,h);else if(n!=-1){let u=this.collectBlock(t,e);e=u.nextI,c=u.inner}let o=" ".repeat(this.indentLevel??0);this.atRuleSegs.push(o+l+` {
41
+ `+c+o+`}
42
+ `);continue}if(i.startsWith("@media")||i.startsWith("@supports")||i.startsWith("@layer")){let l=n!=-1?i.slice(0,n).trim():i.trim(),c="";if(n!=-1&&h!=-1&&h>n)c=i.slice(n+1,h);else if(n!=-1){let y=this.collectBlock(t,e);e=y.nextI,c=y.inner}let o=Et(c,(this.indentLevel??0)+1),u=" ".repeat(this.indentLevel??0);this.atRuleSegs.push(u+l+` {
43
+ `+o+u+`}
44
+ `);continue}if(n!=-1&&h!=-1&&h>n){let l=i.slice(0,n).trim(),c=i.slice(n+1,h).trim(),o=wt(l,this.curSel());this.findOrCreateRule(o),c&&this.addDeclarationLine(c,o);continue}if(n!=-1){let l=i.slice(0,n).trim(),c=wt(l,this.curSel());this.selStack.push(c),this.findOrCreateRule(c);let o=i.slice(n+1).trim();o&&this.addDeclarationLine(o,c);continue}if(i=="}"||i=="};"){this.selStack.pop();continue}this.selStack.length>0&&this.addDeclarationLine(i,this.curSel())}}emit(){let t="",e=" ".repeat(this.indentLevel??0),s=e+" ";for(let i of this.rules)if(i.decls.length!=0){t=t+e+i.sel+` {
45
+ `;for(let n of i.decls)t=t+s+n+`;
46
+ `;t=t+e+`}
47
+ `}for(let i of this.atRuleSegs)t=t+i;return t}};function Et(a,t){let e=new yt(a,t??0,[],[],[]);return e.parse(),e.emit()}j.exports.parseCssBlockContent=Et;var Z=class{constructor(t,e,s){this.src=t,this.pos=e,this.out=s}transform(){for(;this.pos<this.src.length;)this.scan();return this.out}scan(){let t=this.src[this.pos];if(t=="/"&&this.src[this.pos+1]=="/"){let e=this.src.indexOf(`
48
+ `,this.pos);e==-1?(this.out=this.out+this.src.slice(this.pos),this.pos=this.src.length):(this.out=this.out+this.src.slice(this.pos,e+1),this.pos=e+1);return}if(t=="/"&&this.src[this.pos+1]=="*"){let e=this.src.indexOf("*/",this.pos+2);e==-1?(this.out=this.out+this.src.slice(this.pos),this.pos=this.src.length):(this.out=this.out+this.src.slice(this.pos,e+2),this.pos=e+2);return}if(t=='"'){this.passString('"');return}if(t=="'"){this.passString("'");return}if(t=="`"){this.passTemplate();return}if(t=="c"&&this.src.slice(this.pos,this.pos+3)=="css"){let e=this.pos>0?this.src[this.pos-1]:`
49
+ `,s=this.src[this.pos+3]??"";if(!/[a-zA-Z0-9_]/.test(e)&&!/[a-zA-Z0-9_]/.test(s)){let i=this.pos+3;for(;i<this.src.length&&(this.src[i]==" "||this.src[i]==" "||this.src[i]==`
50
+ `||this.src[i]=="\r");)i=i+1;if(this.src[i]=="{"){i=i+1;let n=1,h=i;for(;i<this.src.length&&n>0;){let y=this.src[i];if(y=='"'||y=="'"||y=="`"){let g=y;for(i=i+1;i<this.src.length&&this.src[i]!=g;)this.src[i]=="\\"&&(i=i+1),i=i+1;i=i+1}else y=="{"?(n=n+1,i=i+1):(y=="}"&&(n=n-1),i=i+1)}let l=this.src.slice(h,i-1),c=Et(l,0),o="`",u=c.replace(/\\/g,"\\\\").replace(new RegExp(o,"g"),"\\"+o);this.out=this.out+o+u+o,this.pos=i;return}}}this.out=this.out+t,this.pos=this.pos+1}passString(t){for(this.out=this.out+t,this.pos=this.pos+1;this.pos<this.src.length;){let e=this.src[this.pos];if(e=="\\"){this.out=this.out+e+(this.src[this.pos+1]??""),this.pos=this.pos+2;continue}if(e==t){this.out=this.out+e,this.pos=this.pos+1;return}this.out=this.out+e,this.pos=this.pos+1}}passTemplate(){for(this.out=this.out+"`",this.pos=this.pos+1;this.pos<this.src.length;){let t=this.src[this.pos];if(t=="\\"){this.out=this.out+t+(this.src[this.pos+1]??""),this.pos=this.pos+2;continue}if(t=="`"){this.out=this.out+t,this.pos=this.pos+1;return}this.out=this.out+t,this.pos=this.pos+1}}};j.exports.CssPreprocessor=Z;function ce(a){return new Z(a,0,"").transform()}j.exports.transformCss=ce});var Mt=S((as,C)=>{"use strict";var Rt={bg:a=>"background:"+a,fg:a=>"color:"+a,color:a=>"color:"+a,p:a=>"padding:"+a,px:a=>"paddingLeft:"+a+",paddingRight:"+a,py:a=>"paddingTop:"+a+",paddingBottom:"+a,pt:a=>"paddingTop:"+a,pb:a=>"paddingBottom:"+a,pl:a=>"paddingLeft:"+a,pr:a=>"paddingRight:"+a,m:a=>"margin:"+a,mx:a=>"marginLeft:"+a+",marginRight:"+a,my:a=>"marginTop:"+a+",marginBottom:"+a,mt:a=>"marginTop:"+a,mb:a=>"marginBottom:"+a,ml:a=>"marginLeft:"+a,mr:a=>"marginRight:"+a,radius:a=>"borderRadius:"+a,w:a=>"width:"+a,h:a=>"height:"+a,"min-w":a=>"minWidth:"+a,"max-w":a=>"maxWidth:"+a,"min-h":a=>"minHeight:"+a,"max-h":a=>"maxHeight:"+a,gap:a=>"gap:"+a,"col-gap":a=>"columnGap:"+a,"row-gap":a=>"rowGap:"+a,text:a=>"fontSize:"+a,font:a=>"fontFamily:"+a,weight:a=>"fontWeight:"+a,tracking:a=>"letterSpacing:"+a,leading:a=>"lineHeight:"+a,shadow:a=>"boxShadow:"+a,opacity:a=>"opacity:"+a,border:a=>"border:"+a,outline:a=>"outline:"+a,transition:a=>"transition:"+a,cursor:a=>"cursor:"+a,overflow:a=>"overflow:"+a,z:a=>"zIndex:"+a,transform:a=>"transform:"+a,direction:a=>"flexDirection:"+a,align:a=>"alignItems:"+a,justify:a=>"justifyContent:"+a,"align-self":a=>"alignSelf:"+a,"place-items":a=>"placeItems:"+a,grow:a=>"flexGrow:"+a,shrink:a=>"flexShrink:"+a,basis:a=>"flexBasis:"+a,cols:a=>"gridTemplateColumns:"+a,rows:a=>"gridTemplateRows:"+a,inset:a=>"inset:"+a,top:a=>"top:"+a,right:a=>"right:"+a,bottom:a=>"bottom:"+a,left:a=>"left:"+a,"object-fit":a=>"objectFit:"+a,"line-height":a=>"lineHeight:"+a,"text-align":a=>"textAlign:"+a,decoration:a=>"textDecoration:"+a,clip:a=>"clipPath:"+a,filter:a=>"filter:"+a,backdrop:a=>"backdropFilter:"+a,animation:a=>"animation:"+a},Dt={flex:'display:"flex"',grid:'display:"grid"',block:'display:"block"',"inline-flex":'display:"inline-flex"',"inline-block":'display:"inline-block"',bold:"fontWeight:700",italic:'fontStyle:"italic"',underline:'textDecoration:"underline"',pointer:'cursor:"pointer"',hidden:'display:"none"',relative:'position:"relative"',absolute:'position:"absolute"',fixed:'position:"fixed"',sticky:'position:"sticky"',"flex-col":'flexDirection:"column"',"flex-row":'flexDirection:"row"',"flex-wrap":'flexWrap:"wrap"',"flex-1":"flex:1","w-full":'width:"100%"',"h-full":'height:"100%"',center:'textAlign:"center"',truncate:'overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"',"select-none":'userSelect:"none"',"no-wrap":'whiteSpace:"nowrap"',"no-list":'listStyle:"none"',"no-outline":'outline:"none"',"no-border":'border:"none"',"box-border":'boxSizing:"border-box"'},vt=`function _fluxH(tag,props,...children){
42
51
  if(tag===""){const f=document.createDocumentFragment();children.flat(Infinity).forEach(c=>{if(c==null)return;f.appendChild(c instanceof Node?c:document.createTextNode(String(c)));});return f;}
43
52
  const el=document.createElement(tag);
44
53
  if(props){for(const[k,v]of Object.entries(props)){if(k==="class"||k==="className"){el.className=v;}else if(k==="style"&&typeof v==="object"){Object.assign(el.style,v);}else if(k.startsWith("on")&&typeof v==="function"){el.addEventListener(k.slice(2).toLowerCase(),v);}else if(typeof v==="boolean"){if(v)el.setAttribute(k,"");}else{el.setAttribute(k,String(v));}}}
45
54
  children.flat(Infinity).forEach(c=>{if(c==null)return;el.appendChild(c instanceof Node?c:document.createTextNode(String(c)));});
46
55
  return el;
47
- }`,Ht='\nfunction _fluxH(tag,props,...children){\n const VOID=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);\n if(tag==="")return children.flat(Infinity).map(c=>c==null?"":String(c)).join("");\n let attrs="";\n if(props){for(const[k,v]of Object.entries(props)){if(k==="class"||k==="className")attrs+=` class="${v}"`;else if(k==="style"&&typeof v==="object")attrs+=` style="${Object.entries(v).map(([p,val])=>p.replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+":"+val).join(";")}"`;else if(typeof v!=="function"&&typeof v!=="boolean")attrs+=` ${k}="${String(v).replace(/"/g,"&quot;")}"`;else if(v===true)attrs+=` ${k}`;}}\n const inner=children.flat(Infinity).map(c=>c==null?"":String(c)).join("");\n if(VOID.has(tag))return`<${tag}${attrs}>`;\n return`<${tag}${attrs}>${inner}</${tag}>`;\n}',zt=`
48
- function _fluxCSS(css){const s=document.createElement("style");s.textContent=css;document.head.appendChild(s);return css;}`,Kt=`
49
- function _fluxCSS(css){return css;}`;function De(n,t={}){let e=t.target||"browser",s=new ht(n),r=s.transform(),a=s.hasJsx||n.includes("_fluxH")||n.includes("_fluxCSS");return{source:r,hasJsx:a,runtimeHelpers:(e==="browser"?Vt:Ht)+(e==="browser"?zt:Kt)}}Gt.exports={transformJsx:De,JsxPreprocessor:ht,FLUX_H_BROWSER:Vt,FLUX_H_SERVER:Ht,FLUX_CSS_BROWSER:zt,FLUX_CSS_SERVER:Kt}});var Jt=_((vs,qt)=>{"use strict";var nt=new Set(["undefined","null","true","false","NaN","Infinity","arguments","this","super","console","document","window","navigator","location","history","screen","Math","JSON","Array","Object","String","Number","Boolean","Symbol","BigInt","Promise","Proxy","Reflect","WeakMap","WeakSet","WeakRef","Map","Set","Date","RegExp","Error","TypeError","RangeError","SyntaxError","URIError","EvalError","ReferenceError","parseInt","parseFloat","isNaN","isFinite","encodeURIComponent","decodeURIComponent","encodeURI","decodeURI","atob","btoa","structuredClone","queueMicrotask","setTimeout","setInterval","clearTimeout","clearInterval","requestAnimationFrame","cancelAnimationFrame","fetch","XMLHttpRequest","WebSocket","EventSource","FormData","Headers","Request","Response","URL","URLSearchParams","Blob","File","FileReader","alert","confirm","prompt","Event","CustomEvent","Node","Element","HTMLElement","DocumentFragment","MutationObserver","IntersectionObserver","ResizeObserver","process","Buffer","require","module","exports","__dirname","__filename","global","globalThis","setImmediate","clearImmediate","queueMicrotask","TextEncoder","TextDecoder","AbortController","AbortSignal","performance","Http","Fs","Path","Url","Crypto","Os","Net","Stream","Events","Util","http","fs","path","url","crypto","os","net","stream","events","util","_fluxH","_fluxCSS","print"]);function lt(n){let t="abcdefghijklmnopqrstuvwxyz",e="";for(n++;n>0;)e=t[(n-1)%26]+e,n=Math.floor((n-1)/26);return"_"+e}var wt=class{constructor(){this.map=new Map,this.counter=0,this.exported=new Set,this.imported=new Set}mangle(t){return this._collectExportedAndImported(t),this._collectDeclarations(t),this._walkProgram(t)}getMap(){return Object.fromEntries(this.map)}_collectExportedAndImported(t){for(let e of t.body){if(e.type==="ExportDecl"){let s=e.decl;s&&s.name&&this.exported.add(s.name),s&&s.type==="DestructureDecl"&&(s.pattern||[]).forEach(r=>r&&this.exported.add(r.alias||r.name||r.key))}e.type==="ImportDecl"&&(e.defaultName&&this.imported.add(e.defaultName),(e.names||[]).forEach(s=>this.imported.add(s)))}}_collectDeclarations(t){this._walkStmts(t.body,{toplevel:!0,collect:!0})}_walkProgram(t){let e=this._walkStmts(t.body,{toplevel:!0});return{...t,body:e}}_walkStmts(t,e={}){return t.map(s=>this._walkStmt(s,e))}_walkStmt(t,e={}){if(!t)return t;switch(t.type){case"VarDecl":return this._walkVarDecl(t,e);case"DestructureDecl":return this._walkDestructure(t,e);case"FnDecl":return this._walkFnDecl(t,e);case"ClassDecl":return this._walkClassDecl(t,e);case"IfStmt":return{...t,cond:this._walkExpr(t.cond),then:this._walkStmts(t.then),elseifs:t.elseifs.map(s=>({cond:this._walkExpr(s.cond),body:this._walkStmts(s.body)})),else_:t.else_?this._walkStmts(t.else_):null};case"ForInStmt":return{...t,var:this._mangleLocal(t.var),iter:this._walkExpr(t.iter),body:this._walkStmts(t.body)};case"WhileStmt":return{...t,cond:this._walkExpr(t.cond),body:this._walkStmts(t.body)};case"DoWhileStmt":return{...t,cond:this._walkExpr(t.cond),body:this._walkStmts(t.body)};case"MatchStmt":return{...t,subject:this._walkExpr(t.subject),arms:t.arms.map(s=>({...s,body:this._walkStmts(s.body)}))};case"ReturnStmt":return{...t,value:this._walkExpr(t.value)};case"ThrowStmt":return{...t,value:this._walkExpr(t.value)};case"TryCatchStmt":return{...t,tryBody:this._walkStmts(t.tryBody),catchParam:t.catchParam?this._mangleLocal(t.catchParam):null,catchBody:t.catchBody?this._walkStmts(t.catchBody):null,finallyBody:t.finallyBody?this._walkStmts(t.finallyBody):null};case"ExportDecl":{let s=t.decl;return{...t,decl:this._walkStmt(s,e)}}case"ImportDecl":return t;case"TypeDecl":return t;case"ExprStmt":return{...t,expr:this._walkExpr(t.expr)};case"BreakStmt":case"ContinueStmt":return t;default:return t}}_walkVarDecl(t,e){return e.collect?(this._registerName(t.name),t):{...t,name:this._mangleName(t.name),init:t.init?this._walkExpr(t.init):null}}_walkDestructure(t,e){if(e.collect)return(t.pattern||[]).forEach(s=>{s&&this._registerName(s.alias||s.name||s.key)}),t;if(t.patternType==="array"){let s=t.pattern.map(r=>r&&(r.rest?{...r,name:this._mangleName(r.name)}:{...r,name:this._mangleName(r.name),defaultVal:r.defaultVal?this._walkExpr(r.defaultVal):null}));return{...t,pattern:s,init:this._walkExpr(t.init)}}else{let s=t.pattern.map(r=>r&&(r.rest?{...r,key:r.key,alias:this._mangleName(r.alias||r.key)}:{...r,alias:this._mangleName(r.alias||r.key),defaultVal:r.defaultVal?this._walkExpr(r.defaultVal):null}));return{...t,pattern:s,init:this._walkExpr(t.init)}}}_walkFnDecl(t,e){if(e.collect&&t.name)return this._registerName(t.name),t;let s=t.name?this._mangleName(t.name):null,r=t.params.map(c=>({...c,name:this._mangleParam(c.name),defaultVal:c.defaultVal?this._walkExpr(c.defaultVal):null})),a=t.inline?this._walkExpr(t.body):this._walkStmts(t.body);return{...t,name:s,params:r,body:a}}_walkClassDecl(t,e){if(e.collect&&t.name)return this._registerName(t.name),t;let s=this._mangleName(t.name),r=t.methods.map(c=>{let h=c.params.map(p=>({...p,name:this._mangleParam(p.name),defaultVal:p.defaultVal?this._walkExpr(p.defaultVal):null})),l=c.inline?this._walkExpr(c.body):this._walkStmts(c.body);return{...c,params:h,body:l}}),a=t.superClass?this._mangleName(t.superClass):null;return{...t,name:s,superClass:a,methods:r}}_walkExpr(t){if(!t)return t;switch(t.type){case"Identifier":return{...t,name:this._mangleName(t.name)};case"NumberLit":case"BoolLit":case"NullLit":case"StringLit":case"SelfExpr":return t;case"TemplateLit":return{...t,parts:t.parts.map(e=>{if(e.type!=="expr")return e;let s=e.value;for(let[r,a]of this.map)s=s.replace(new RegExp(`(?<![\\w$])${r}(?![\\w$])`,"g"),a);return{...e,value:s}})};case"BinaryExpr":return{...t,left:this._walkExpr(t.left),right:this._walkExpr(t.right)};case"UnaryExpr":return{...t,operand:this._walkExpr(t.operand)};case"UpdateExpr":return{...t,operand:this._walkExpr(t.operand)};case"AwaitExpr":return{...t,operand:this._walkExpr(t.operand)};case"TypeofExpr":return{...t,operand:this._walkExpr(t.operand)};case"TernaryExpr":return{...t,cond:this._walkExpr(t.cond),then:this._walkExpr(t.then),else_:this._walkExpr(t.else_)};case"AssignExpr":return{...t,target:this._walkExpr(t.target),value:this._walkExpr(t.value)};case"SpreadExpr":return{...t,expr:this._walkExpr(t.expr)};case"PipeExpr":return{...t,left:this._walkExpr(t.left),right:this._walkExpr(t.right)};case"MemberExpr":return{...t,obj:this._walkExpr(t.obj)};case"OptMemberExpr":return{...t,obj:this._walkExpr(t.obj)};case"IndexExpr":return{...t,obj:this._walkExpr(t.obj),idx:this._walkExpr(t.idx)};case"OptIndexExpr":return{...t,obj:this._walkExpr(t.obj),idx:this._walkExpr(t.idx)};case"CallExpr":return{...t,callee:this._walkExpr(t.callee),args:t.args.map(e=>this._walkExpr(e))};case"OptCallExpr":return{...t,callee:this._walkExpr(t.callee),args:t.args.map(e=>this._walkExpr(e))};case"NewExpr":return{...t,callee:this._mangleName(t.callee),args:t.args.map(e=>this._walkExpr(e))};case"LambdaExpr":return{...t,params:t.params.map(e=>({...e,name:this._mangleParam(e.name)})),body:this._walkExpr(t.body)};case"FnDecl":return this._walkFnDecl(t,{});case"ArrayExpr":return{...t,items:t.items.map(e=>this._walkExpr(e))};case"ObjectExpr":return{...t,pairs:t.pairs.map(e=>({...e,value:this._walkExpr(e.value)}))};case"RangeExpr":return{...t,start:this._walkExpr(t.start),end:this._walkExpr(t.end)};default:return t}}_registerName(t){!t||nt.has(t)||this.exported.has(t)||this.imported.has(t)||this.map.has(t)||this.map.set(t,lt(this.counter++))}_mangleName(t){return!t||nt.has(t)||this.exported.has(t)||this.imported.has(t)?t:this.map.has(t)?this.map.get(t):t}_mangleLocal(t){return!t||nt.has(t)?t:(this.map.has(t)||this.map.set(t,lt(this.counter++)),this.map.get(t))}_mangleParam(t){return!t||nt.has(t)?t:(this.map.has(t)||this.map.set(t,lt(this.counter++)),this.map.get(t))}};qt.exports={Mangler:wt,SAFE:nt,makeName:lt}});var se=_((Rs,ee)=>{"use strict";var te={bg:"background",fg:"color",p:"padding",px:"padding-inline",py:"padding-block",pt:"padding-top",pb:"padding-bottom",pl:"padding-left",pr:"padding-right",m:"margin",mx:"margin-inline",my:"margin-block",mt:"margin-top",mb:"margin-bottom",ml:"margin-left",mr:"margin-right",radius:"border-radius",w:"width",h:"height","min-w":"min-width","max-w":"max-width","min-h":"min-height","max-h":"max-height",gap:"gap","col-gap":"column-gap","row-gap":"row-gap",text:"font-size",font:"font-family",weight:"font-weight",tracking:"letter-spacing",leading:"line-height",shadow:"box-shadow",opacity:"opacity",border:"border",outline:"outline",transition:"transition",cursor:"cursor",overflow:"overflow","overflow-x":"overflow-x","overflow-y":"overflow-y",z:"z-index",transform:"transform",content:"content",resize:"resize",appearance:"appearance","accent-color":"accent-color","object-fit":"object-fit",direction:"flex-direction",wrap:"flex-wrap",align:"align-items",justify:"justify-content","align-self":"align-self","justify-self":"justify-self",grow:"flex-grow",shrink:"flex-shrink",basis:"flex-basis",order:"order",cols:"grid-template-columns",rows:"grid-template-rows","col-span":"grid-column","row-span":"grid-row","place-items":"place-items","place-content":"place-content","list-style":"list-style","text-align":"text-align",decoration:"text-decoration","text-transform":"text-transform","white-space":"white-space","word-break":"word-break","user-select":"user-select","pointer-events":"pointer-events","vertical-align":"vertical-align",backdrop:"backdrop-filter",filter:"filter",clip:"clip-path",animation:"animation",position:"position",top:"top",right:"right",bottom:"bottom",left:"left",inset:"inset",color:"color",background:"background"},at={flex:"display: flex",grid:"display: grid",block:"display: block",inline:"display: inline","inline-flex":"display: inline-flex","inline-block":"display: inline-block","inline-grid":"display: inline-grid",bold:"font-weight: 700",italic:"font-style: italic",relative:"position: relative",absolute:"position: absolute",fixed:"position: fixed",sticky:"position: sticky",hidden:"display: none",pointer:"cursor: pointer",underline:"text-decoration: underline","line-through":"text-decoration: line-through",capitalize:"text-transform: capitalize",uppercase:"text-transform: uppercase",lowercase:"text-transform: lowercase",truncate:"overflow: hidden; text-overflow: ellipsis; white-space: nowrap","select-none":"user-select: none","no-wrap":"white-space: nowrap","no-list":"list-style: none","no-outline":"outline: none","no-border":"border: none","no-bg":"background: transparent","no-padding":"padding: 0","no-margin":"margin: 0","no-resize":"resize: none",center:"text-align: center","items-center":"align-items: center","justify-center":"justify-content: center","place-center":"place-items: center","flex-col":"flex-direction: column","flex-row":"flex-direction: row","flex-wrap":"flex-wrap: wrap","flex-1":"flex: 1","w-full":"width: 100%","h-full":"height: 100%","w-screen":"width: 100vw","h-screen":"height: 100vh","box-border":"box-sizing: border-box"};function St(n){let t=n.trim();return te[t]||t}function At(n){let t=n.trim();return t.length>=2&&(t[0]==='"'&&t[t.length-1]==='"'||t[0]==="'"&&t[t.length-1]==="'")?t.slice(1,-1):t}function Xt(n,t){return n=n.trim(),!t||n.startsWith("@")||t.startsWith("@keyframes")||t.startsWith("@font-face")?n:n.includes("&")?n.replace(/&/g,t):t+" "+n}function Zt(n){let t=[];return n.split(";").forEach(e=>{let s=e.trim();if(!s||s.startsWith("//"))return;if(at[s]){at[s].split(";").forEach(a=>{let c=a.trim();c&&t.push(c)});return}let r=s.indexOf(":");if(r!==-1){let a=St(s.slice(0,r)),c=At(s.slice(r+1));c!==""&&t.push(a+": "+c)}}),t}function Rt(n,t){let e=" ".repeat(t||0),s=e+" ",r=n.split(`
50
- `),a=new Map,c=[],h=[];function l(){return h.length?h[h.length-1]:null}function p(g,f){a.has(g)||a.set(g,[]),a.get(g).push(f)}function m(g,f){if(g.includes(";")){g.split(";").forEach(b=>{let w=b.trim();w&&m(w,f)});return}if(at[g]){at[g].split(";").forEach(b=>{let w=b.trim();w&&p(f,w)});return}let T=g.indexOf(":");if(T!==-1){let b=St(g.slice(0,T)),w=At(g.slice(T+1));w!==""&&p(f,b+": "+w)}}function y(g){let f=1,T="",b=g;for(;b<r.length&&f>0;){let w=r[b++];for(let S of w)S==="{"?f++:S==="}"&&f--;if(f>0)T+=w+`
51
- `;else{let S=w.lastIndexOf("}");S>0&&(T+=w.slice(0,S)+`
52
- `)}}return{inner:T,nextI:b}}let u=0;for(;u<r.length;){let f=r[u++].trim();if(!f||f.startsWith("//"))continue;let T=f.indexOf("{"),b=f.lastIndexOf("}");if(f.startsWith("@keyframes")||f.startsWith("@font-face")){let w=T!==-1?f.slice(0,T).trim():f.trim(),S="";if(T!==-1&&b!==-1&&b>T)S=f.slice(T+1,b);else if(T!==-1){let v=y(u);u=v.nextI,S=v.inner}let A=S.split(`
53
- `).map(v=>{let B=v.trim();if(!B||B==="{"||B==="}")return v;let $=B.indexOf(":");if($!==-1&&!B.slice(0,$).includes("{")){let P=St(B.slice(0,$)),U=At(B.slice($+1));return v.replace(B,P+": "+U)}return v}).join(`
54
- `);c.push(`${e}${w} {
55
- ${A}${e}}
56
- `);continue}if(f.startsWith("@media")||f.startsWith("@supports")||f.startsWith("@layer")){let w=T!==-1?f.slice(0,T).trim():f.trim(),S="";if(T!==-1&&b!==-1&&b>T)S=f.slice(T+1,b);else if(T!==-1){let v=y(u);u=v.nextI,S=v.inner}let A=Rt(S,(t||0)+1);c.push(`${e}${w} {
57
- ${A}${e}}
58
- `);continue}if(T!==-1&&b!==-1&&b>T){let w=f.slice(0,T).trim(),S=f.slice(T+1,b).trim(),A=Xt(w,l());a.has(A)||a.set(A,[]),S&&Zt(S).forEach(v=>p(A,v));continue}if(T!==-1){let w=f.slice(0,T).trim(),S=Xt(w,l());h.push(S),a.has(S)||a.set(S,[]);let A=f.slice(T+1).trim();A&&Zt(A).forEach(v=>p(S,v));continue}if(f==="}"||f==="};"){h.pop();continue}h.length>0&&m(f,l())}let d="";for(let[g,f]of a)if(f.length!==0){d+=`${e}${g} {
59
- `;for(let T of f)d+=`${s}${T};
60
- `;d+=`${e}}
61
- `}for(let g of c)d+=g;return d}var vt=class{constructor(t){this.src=t,this.pos=0,this.out=""}transform(){for(;this.pos<this.src.length;)this.scan();return this.out}scan(){let t=this.src[this.pos];if(t==="/"&&this.src[this.pos+1]==="/"){let e=this.src.indexOf(`
62
- `,this.pos);e===-1?(this.out+=this.src.slice(this.pos),this.pos=this.src.length):(this.out+=this.src.slice(this.pos,e+1),this.pos=e+1);return}if(t==="/"&&this.src[this.pos+1]==="*"){let e=this.src.indexOf("*/",this.pos+2);e===-1?(this.out+=this.src.slice(this.pos),this.pos=this.src.length):(this.out+=this.src.slice(this.pos,e+2),this.pos=e+2);return}if(t==='"'||t==="'"||t==="`"){this.passString(t);return}if(t==="c"&&this.src.slice(this.pos,this.pos+3)==="css"){let e=this.pos>0?this.src[this.pos-1]:`
63
- `,s=this.src[this.pos+3]||"";if(!/[a-zA-Z0-9_]/.test(e)&&!/[a-zA-Z0-9_]/.test(s)){let r=this.pos+3;for(;r<this.src.length&&(this.src[r]===" "||this.src[r]===" "||this.src[r]===`
64
- `||this.src[r]==="\r");)r++;if(this.src[r]==="{"){r++;let a=1,c=r;for(;r<this.src.length&&a>0;){let p=this.src[r];if(p==='"'||p==="'"||p==="`"){let m=p;for(r++;r<this.src.length&&this.src[r]!==m;)this.src[r]==="\\"&&r++,r++;r++}else p==="{"?(a++,r++):(p==="}"&&a--,r++)}let h=this.src.slice(c,r-1),l=Rt(h);this.out+="`"+l.replace(/\\/g,"\\\\").replace(/`/g,"\\`")+"`",this.pos=r;return}}}this.out+=t,this.pos++}passString(t){for(this.out+=t,this.pos++;this.pos<this.src.length;){let e=this.src[this.pos];if(e==="\\"){this.out+=e+(this.src[this.pos+1]||""),this.pos+=2;continue}if(e===t){this.out+=e,this.pos++;return}this.out+=e,this.pos++}}};function Ie(n){return new vt(n).transform()}ee.exports={transformCss:Ie,parseCssBlockContent:Rt,CSS_PROP_MAP:te,CSS_BOOL_MAP:at}});var re=_((Ds,ie)=>{"use strict";var ot=class{constructor(t,e,s=null){this.message=t,this.loc=e,this.hint=s,this.name="CheckError",e&&(this.line=e.line,this.col=e.col)}},D=class{constructor(t=null){this.parent=t,this.vars=new Map}define(t,e,s){this.vars.set(t,{kind:e,loc:s})}lookup(t){let e=this;for(;e;){if(e.vars.has(t))return e.vars.get(t);e=e.parent}return null}isVal(t){let e=this.lookup(t);return e&&e.kind==="val"}},Dt=class{constructor(){this.errors=[],this.warnings=[]}check(t){this.errors=[],this.warnings=[];let e=new D;return this.walkStmts(t.body,e),{errors:this.errors,warnings:this.warnings}}error(t,e,s=null){this.errors.push(new ot(t,e,s))}warn(t,e,s=null){this.warnings.push(new ot(t,e,s))}walkStmts(t,e){for(let s of t)this.walkStmt(s,e)}walkStmt(t,e){if(t)switch(t.type){case"VarDecl":t.init&&this.walkExpr(t.init,e),e.define(t.name,t.kind,t.loc);break;case"DestructureDecl":if(t.init&&this.walkExpr(t.init,e),t.patternType==="object")for(let s of t.pattern)e.define(s.alias,t.kind,t.loc);else for(let s of t.pattern)s&&e.define(s.name,t.kind,t.loc);break;case"FnDecl":{let s=new D(e);for(let r of t.params)s.define(r.name,"val",t.loc);t.name&&e.define(t.name,"val",t.loc),t.inline?this.walkExpr(t.body,s):this.walkStmts(t.body,s);break}case"ClassDecl":{e.define(t.name,"val",t.loc);let s=new D(e);for(let r of t.fields)s.define(r.name,"var",t.loc);for(let r of t.methods)this.walkStmt(r,s);break}case"TypeDecl":for(let s of t.variants)e.define(s.name,"val",t.loc);break;case"InterfaceDecl":e.define(t.name,"val",t.loc);break;case"EnumDecl":e.define(t.name,"val",t.loc);break;case"IfStmt":this.walkExpr(t.cond,e),this.walkStmts(t.then,new D(e));for(let s of t.elseifs)this.walkExpr(s.cond,e),this.walkStmts(s.body,new D(e));t.else_&&this.walkStmts(t.else_,new D(e));break;case"ForInStmt":{this.walkExpr(t.iter,e);let s=new D(e);s.define(t.var,"val",t.loc),this.walkStmts(t.body,s);break}case"WhileStmt":this.walkExpr(t.cond,e),this.walkStmts(t.body,new D(e));break;case"DoWhileStmt":this.walkStmts(t.body,new D(e)),this.walkExpr(t.cond,e);break;case"MatchStmt":this.walkExpr(t.subject,e);for(let s of t.arms){let r=new D(e);if(s.pattern.type==="VariantPat")for(let a of s.pattern.bindings)r.define(a,"val",t.loc);s.guard&&this.walkExpr(s.guard,r),this.walkStmts(s.body,r)}break;case"ReturnStmt":t.value&&this.walkExpr(t.value,e);break;case"ThrowStmt":this.walkExpr(t.value,e);break;case"TryCatchStmt":{if(this.walkStmts(t.tryBody,new D(e)),t.catchBody){let s=new D(e);t.catchParam&&s.define(t.catchParam,"val",t.loc),this.walkStmts(t.catchBody,s)}t.finallyBody&&this.walkStmts(t.finallyBody,new D(e));break}case"ImportDecl":t.defaultName&&e.define(t.defaultName,"val",t.loc),t.namespaceName&&e.define(t.namespaceName,"val",t.loc);for(let s of t.names)e.define(typeof s=="string"?s:s.alias,"val",t.loc);break;case"ExportDecl":this.walkStmt(t.isDefault?{type:"ExprStmt",expr:t.decl}:t.decl,e);break;case"ExprStmt":this.walkExpr(t.expr,e);break;case"BreakStmt":case"ContinueStmt":break;default:}}walkExpr(t,e){if(t)switch(t.type){case"AssignExpr":{let s=t.target;s.type==="Identifier"&&e.isVal(s.name)&&this.error(`Cannot reassign 'val ${s.name}' \u2014 val is immutable`,s.loc,`Use 'var ${s.name}' if you need a mutable variable`),this.walkExpr(t.target,e),this.walkExpr(t.value,e);break}case"UpdateExpr":t.operand.type==="Identifier"&&e.isVal(t.operand.name)&&this.error(`Cannot apply '${t.op}' to 'val ${t.operand.name}' \u2014 val is immutable`,t.operand.loc,`Use 'var ${t.operand.name}' if you need a mutable variable`),this.walkExpr(t.operand,e);break;case"BinaryExpr":case"PipeExpr":this.walkExpr(t.left,e),this.walkExpr(t.right,e);break;case"UnaryExpr":case"AwaitExpr":case"TypeofExpr":this.walkExpr(t.operand,e);break;case"TernaryExpr":this.walkExpr(t.cond,e),this.walkExpr(t.then,e),this.walkExpr(t.else_,e);break;case"CallExpr":case"OptCallExpr":this.walkExpr(t.callee,e);for(let s of t.args)this.walkExpr(s,e);break;case"MemberExpr":case"OptMemberExpr":this.walkExpr(t.obj,e);break;case"IndexExpr":case"OptIndexExpr":this.walkExpr(t.obj,e),this.walkExpr(t.idx,e);break;case"NewExpr":for(let s of t.args)this.walkExpr(s,e);break;case"ArrayExpr":for(let s of t.items)s&&this.walkExpr(s,e);break;case"ObjectExpr":for(let s of t.pairs)s.value&&this.walkExpr(s.value,e);break;case"SpreadExpr":this.walkExpr(t.expr,e);break;case"LambdaExpr":{let s=new D(e);for(let r of t.params)s.define(r.name,"val",null);this.walkExpr(t.body,s);break}case"FnDecl":{let s=new D(e);for(let r of t.params)s.define(r.name,"val",null);t.inline?this.walkExpr(t.body,s):this.walkStmts(t.body,s);break}case"TemplateLit":break;case"CastExpr":case"AsConstExpr":case"SatisfiesExpr":case"IsExpr":case"NonNullExpr":this.walkExpr(t.expr,e);break;case"RangeExpr":this.walkExpr(t.start,e),this.walkExpr(t.end,e);break;case"Identifier":case"NumberLit":case"BoolLit":case"NullLit":case"StringLit":case"SelfExpr":break;default:}}};ie.exports={Checker:Dt}});var oe=_((Is,le)=>{"use strict";var I=Object.freeze({kind:"any"}),k=Object.freeze({kind:"unknown"}),ct=Object.freeze({kind:"never"}),O=Object.freeze({kind:"void"}),V=Object.freeze({kind:"null"}),C=Object.freeze({kind:"primitive",name:"String"}),W=Object.freeze({kind:"primitive",name:"Int"}),G=Object.freeze({kind:"primitive",name:"Float"}),L=Object.freeze({kind:"primitive",name:"Number"}),j=Object.freeze({kind:"primitive",name:"Bool"});function F(...n){let t=[];for(let r of n)r&&r.kind==="union"?t.push(...r.members):r&&t.push(r);let e=new Set,s=t.filter(r=>{let a=N(r);return e.has(a)?!1:(e.add(a),!0)});return s.length===0?ct:s.length===1?s[0]:{kind:"union",members:s}}function ae(...n){let t=[];for(let e of n)e&&e.kind==="intersection"?t.push(...e.members):e&&t.push(e);return t.length===1?t[0]:{kind:"intersection",members:t}}function X(n){return{kind:"generic",name:"Array",args:[n||k]}}function It(n){return{kind:"tuple",types:n||[]}}function ce(n){return F(n,V)}function E(n){return{kind:"named",name:n}}function R(n,t){return{kind:"fn",params:n||[],ret:t||O}}function ut(n){return{kind:"object",shape:n||new Map}}function he(n,t){return{kind:"record",key:n||C,val:t||k}}function Oe(n,t){return{kind:"literal",value:n,prim:t}}function N(n){if(!n)return"unknown";switch(n.kind){case"any":return"Any";case"unknown":return"Unknown";case"never":return"Never";case"void":return"Void";case"null":return"Null";case"primitive":return n.name;case"literal":return JSON.stringify(n.value);case"union":return n.members.map(N).join(" | ");case"intersection":return n.members.map(N).join(" & ");case"tuple":return"["+n.types.map(N).join(", ")+"]";case"object":return"{"+[...(n.shape||new Map).entries()].map(([t,e])=>`${t}: ${N(e)}`).join(", ")+"}";case"record":return`Record<${N(n.key)}, ${N(n.val)}>`;case"generic":return n.name+(n.args&&n.args.length?"<"+n.args.map(N).join(", ")+">":"");case"named":return n.name;case"fn":return`(${(n.params||[]).map(N).join(", ")}) -> ${N(n.ret)}`;case"keyof":return`keyof ${N(n.inner)}`;case"conditional":return`${N(n.check)} extends ${N(n.extends)} ? ${N(n.then)} : ${N(n.else)}`;default:return"unknown"}}function K(n,t){let e=[],s=0,r=0;for(let a=0;a<n.length;a++){let c=n[a];"<([{".includes(c)?s++:">)]}".includes(c)?s--:s===0&&n.slice(a,a+t.length)===t&&(e.push(n.slice(r,a)),r=a+t.length,a+=t.length-1)}return e.push(n.slice(r)),e.filter(a=>a.trim().length>0)}var ne={String:C,string:C,Int:W,int:W,Float:G,float:G,Number:L,number:L,Bool:j,boolean:j,Boolean:j,bool:j,Void:O,void:O,Never:ct,never:ct,Any:I,any:I,Unknown:k,unknown:k,Null:V,null:V,undefined:O,Object:E("Object"),object:E("Object"),Symbol:E("Symbol"),symbol:E("Symbol"),BigInt:E("BigInt"),bigint:E("BigInt")};function x(n){if(!n)return null;n=n.trim(),n.startsWith("(")&&n.endsWith(")")&&(n=n.slice(1,-1).trim());let t=K(n," | ");if(t.length>1)return F(...t.map(x));let e=K(n," & ");if(e.length>1)return ae(...e.map(x));let s=n.match(/^(\w+)\s+extends\s+(.+?)\s*\?\s*(.+?)\s*:\s*(.+)$/);if(s)return{kind:"conditional",check:x(s[1]),extends:x(s[2]),then:x(s[3]),else:x(s[4])};if(n.startsWith("keyof "))return{kind:"keyof",inner:x(n.slice(6))};if(n.startsWith("typeof "))return{kind:"typeof",name:n.slice(7)};if(n.startsWith("readonly "))return x(n.slice(9));if(n.startsWith("infer "))return I;let r=n.match(/^fn\(([^)]*)\)\s*->\s*(.+)$/)||n.match(/^\(([^)]*)\)\s*->\s*(.+)$/);if(r){let c=r[1].trim(),h=r[2].trim(),l=c?K(c,", ").map(p=>{let m=p.indexOf(":");return x(m>=0?p.slice(m+1).trim():p.trim())}):[];return R(l,x(h))}if(n.endsWith("?"))return ce(x(n.slice(0,-1)));if(n.endsWith("[]"))return X(x(n.slice(0,-2)));if(n.startsWith("[")&&n.endsWith("]")){let c=n.slice(1,-1);if(!c.trim())return It([]);let h=K(c,", ");return It(h.map(l=>x(l.replace(/^\.\.\./,"").trim())))}if(n.startsWith("{")&&n.endsWith("}")){let c=n.slice(1,-1).trim(),h=new Map;if(c){let l=K(c,", ");for(let p of l){let m=p.match(/^\[(\w+):\s*\w+\]:\s*(.+)$/);if(m){h.set("[index]",x(m[2]));continue}let y=p.indexOf(":");if(y>=0){let u=p.slice(0,y).trim().replace(/^readonly\s+/,""),d=u.replace(/\?$/,""),g=u.endsWith("?"),f=x(p.slice(y+1).trim());h.set(d,g?F(f,O):f)}}}return ut(h)}let a=n.match(/^(\w+)<(.+)>$/s);if(a){let c=a[1],l=K(a[2],", ").map(p=>x(p.trim()));switch(c){case"Array":case"List":case"ReadonlyArray":return X(l[0]||k);case"NonNullable":return $e(l[0]);case"Partial":return{kind:"utility",util:"Partial",inner:l[0]};case"Required":return{kind:"utility",util:"Required",inner:l[0]};case"Readonly":return l[0];case"Record":return he(l[0]||C,l[1]||k);case"Pick":return{kind:"utility",util:"Pick",inner:l[0],keys:l[1]};case"Omit":return{kind:"utility",util:"Omit",inner:l[0],keys:l[1]};case"Exclude":return{kind:"utility",util:"Exclude",inner:l[0],keys:l[1]};case"Extract":return{kind:"utility",util:"Extract",inner:l[0],keys:l[1]};case"ReturnType":return{kind:"utility",util:"ReturnType",inner:l[0]};case"InstanceType":return{kind:"utility",util:"InstanceType",inner:l[0]};case"Parameters":return{kind:"utility",util:"Parameters",inner:l[0]};case"Awaited":return{kind:"utility",util:"Awaited",inner:l[0]};case"Promise":return{kind:"generic",name:"Promise",args:l};case"Map":return{kind:"generic",name:"Map",args:l};case"Set":return{kind:"generic",name:"Set",args:l};case"WeakMap":return{kind:"generic",name:"WeakMap",args:l};default:return{kind:"generic",name:c,args:l}}}return ne[n]?ne[n]:E(n)}function $e(n){return n?n.kind==="union"?F(...n.members.filter(t=>t.kind!=="null"&&t.kind!=="void")):n.kind==="null"||n.kind==="void"?ct:n:k}function _e(n,t){return M(n,t)}function M(n,t){if(!n||!t||t.kind==="any"||n.kind==="any"||n.kind==="never"||t.kind==="unknown"||n.kind==="void"&&t.kind==="void"||n.kind==="null"&&t.kind==="null"||n.kind==="never"&&t.kind==="never")return!0;if(n.kind==="null"&&t.kind==="union")return t.members.some(e=>e.kind==="null"||e.kind==="any"||e.kind==="void");if(n.kind==="union")return n.members.every(e=>M(e,t));if(t.kind==="union")return t.members.some(e=>M(n,e));if(n.kind==="intersection")return n.members.some(e=>M(e,t));if(t.kind==="intersection")return t.members.every(e=>M(n,e));if(n.kind==="primitive"&&t.kind==="primitive")return!!(n.name===t.name||t.name==="Number"&&["Int","Float","Number"].includes(n.name)||t.name==="Float"&&n.name==="Int"||n.name==="Bool"&&t.name==="Boolean"||n.name==="Boolean"&&t.name==="Bool");if(n.kind==="literal"&&t.kind==="primitive")return{string:"String",number:"Number",boolean:"Bool"}[n.prim]===t.name||n.prim==="number"&&["Int","Float","Number"].includes(t.name);if(n.kind==="named"&&t.kind==="named")return n.name===t.name||t.name==="Object";if(n.kind==="generic"&&t.kind==="generic"){let e=new Set(["Array","List","ReadonlyArray"]);return n.name!==t.name&&!(e.has(n.name)&&e.has(t.name))||n.args.length!==t.args.length?!1:n.args.every((s,r)=>M(s,t.args[r]))}if(n.kind==="tuple"&&t.kind==="tuple")return n.types.length!==t.types.length?!1:n.types.every((e,s)=>M(e,t.types[s]));if(n.kind==="generic"&&n.name==="Array"&&t.kind==="tuple"){let e=n.args[0]||k;return e.kind==="unknown"?!0:t.types.every(s=>M(e,s))}if(n.kind==="object"&&t.kind==="object"){for(let[e,s]of t.shape)if(!n.shape.has(e)||!M(n.shape.get(e),s))return!1;return!0}return n.kind==="object"&&t.kind==="named"?!0:n.kind==="fn"&&t.kind==="fn"?t.ret&&n.ret?M(n.ret,t.ret):!0:(n.kind==="fn"||t.kind==="fn")&&(n.kind==="fn"||t.kind==="fn")?!0:n.kind==="record"&&t.kind==="record"?M(n.val,t.val):n.kind==="generic"&&t.kind==="generic"||t.kind==="utility"||n.kind==="utility"}function pt(n,t){return!n||n.kind==="unknown"?t||k:!t||t.kind==="unknown"||N(n)===N(t)?n:n.kind==="any"||t.kind==="any"?I:F(n,t)}var Ot=class n{constructor(t=null){this.parent=t,this.vars=new Map,this.retType=t?t.retType:null,this.isAsync=t?t.isAsync:!1}set(t,e){this.vars.set(t,e)}has(t){let e=this;for(;e;){if(e.vars.has(t))return!0;e=e.parent}return!1}get(t){let e=this;for(;e;){if(e.vars.has(t))return e.vars.get(t);e=e.parent}return null}child(){return new n(this)}childFn(t,e=!1){let s=new n(this);return s.retType=t,s.isAsync=e,s}narrow(t,e){let s=new n(this);return t&&e&&s.vars.set(t,e),s}},ft=class{constructor(t,e,s=null){this.message=t,this.name="TypeError",this.hint=s,e&&(this.line=e.line,this.col=e.col)}},$t=class{constructor(){this.errors=[],this.warnings=[],this.interfaces=new Map,this.types=new Map,this.classes=new Map,this.enums=new Map,this.typeAliases=new Map}check(t){this.errors=[],this.warnings=[],this.interfaces.clear(),this.types.clear(),this.classes.clear(),this.enums.clear(),this.typeAliases.clear(),this._collectDeclarations(t.body),this._validateImplementations();let e=new Ot;return this._registerBuiltins(e),this._checkStmts(t.body,e),{errors:this.errors,warnings:this.warnings}}_err(t,e,s=null){this.errors.push(new ft(t,e,s))}_warn(t,e,s=null){this.warnings.push(new ft(t,e,s))}_collectDeclarations(t){for(let e of t){let s=e.type==="ExportDecl"?e.decl:e;if(s)switch(s.type){case"InterfaceDecl":this.interfaces.set(s.name,s);break;case"TypeDecl":this.types.set(s.name,s);break;case"ClassDecl":this.classes.set(s.name,s);break;case"EnumDecl":this.enums.set(s.name,s);break}}}_validateImplementations(){for(let[,t]of this.classes)for(let e of t.interfaces||[])this._checkInterfaceImpl(t,e)}_checkInterfaceImpl(t,e){let s=this.interfaces.get(e);if(!s){this._warn(`Class '${t.name}' implements unknown interface '${e}'`,t.loc,`Define 'interface ${e}' before use`);return}for(let r of s.members)if(r.kind==="method")t.methods.find(c=>c.name===r.name)||this._err(`Class '${t.name}' does not implement method '${r.name}()' required by interface '${e}'`,t.loc,`Add 'fn ${r.name}(${r.params.map(c=>c.name+(c.typeAnn?": "+c.typeAnn:"")).join(", ")})' to the class`);else if(r.kind==="field"&&!r.optional){let a=t.fields.find(h=>h.name===r.name),c=t.methods.find(h=>h.name===r.name);!a&&!c&&this._err(`Class '${t.name}' is missing field '${r.name}' required by interface '${e}'`,t.loc,`Add '${r.name}: ${r.typeAnn}' to the class`)}for(let r of s.superInterfaces||[])this._checkInterfaceImpl(t,r)}_isStructurallyCompatible(t,e){let s=this.interfaces.get(e);if(!s){let r=this.classes.get(e);if(!r)return!1;for(let a of r.fields){if(!t.has(a.name)&&!a.optional)return!1;if(a.typeAnn&&t.has(a.name)){let c=x(a.typeAnn),h=t.get(a.name);if(!this._isAssignable(h,c))return!1}}return!0}for(let r of s.members)if(r.kind==="field"&&!r.optional){if(!t.has(r.name))return!1;if(r.typeAnn){let a=x(r.typeAnn),c=t.get(r.name);if(!this._isAssignable(c,a))return!1}}return!0}_isAssignable(t,e){if(!t||!e||e.kind==="any"||t.kind==="any"||t.kind==="never"||e.kind==="unknown")return!0;if(t.kind==="unknown")return!1;if(t.kind==="object"&&e.kind==="named")return this._isStructurallyCompatible(t.shape,e.name);if(t.kind==="object"&&e.kind==="object"){for(let[s,r]of e.shape)if(!t.shape.has(s)||!this._isAssignable(t.shape.get(s),r))return!1;return!0}if(t.kind==="named"&&e.kind==="named"){if(t.name===e.name||e.name==="Object")return!0;let s=this.classes.get(t.name);if(s&&(s.interfaces||[]).includes(e.name)||s&&s.superClass===e.name)return!0;let r=this.interfaces.get(t.name);return!!(r&&(r.superInterfaces||[]).includes(e.name))}if(e.kind==="utility")switch(e.util){case"Partial":return!0;case"Required":return this._isAssignable(t,e.inner);case"NonNullable":return t.kind!=="null"&&t.kind!=="void";default:return!0}return t.kind==="utility"?!0:M(t,e)}_analyzeNarrowingCondition(t,e){if(!t)return null;if(t.type==="BinaryExpr"&&(t.op==="!="||t.op==="!==")&&t.left.type==="Identifier"&&(t.right.type==="NullLit"||t.right.type==="Identifier"&&t.right.name==="undefined")){let s=t.left.name,r=e.get(s);if(r&&r.kind==="union"){let a=F(...r.members.filter(c=>c.kind!=="null"&&c.kind!=="void"));return{varName:s,trueType:a,falseType:F(V,O)}}}if(t.type==="BinaryExpr"&&(t.op==="=="||t.op==="===")&&t.left.type==="Identifier"&&t.right.type==="NullLit"){let s=t.left.name,r=e.get(s);if(r&&r.kind==="union"){let a=F(...r.members.filter(c=>c.kind!=="null"&&c.kind!=="void"));return{varName:s,trueType:V,falseType:a}}}if(t.type==="BinaryExpr"&&(t.op==="==="||t.op==="==")&&t.left.type==="TypeofExpr"&&t.left.operand.type==="Identifier"&&t.right.type==="StringLit"){let s=t.left.operand.name,r=t.right.value,c={string:C,number:L,boolean:j,object:E("Object"),function:R([],I),undefined:O,bigint:E("BigInt"),symbol:E("Symbol")}[r]||k;return{varName:s,trueType:c,falseType:e.get(s)||k}}if(t.type==="BinaryExpr"&&t.op==="instanceof"&&t.left.type==="Identifier"){let s=t.left.name,r=t.right.type==="Identifier"?t.right.name:null;if(r)return{varName:s,trueType:E(r),falseType:e.get(s)||k}}if(t.type==="Identifier"){let s=t.name,r=e.get(s);if(r&&r.kind==="union"){let a=F(...r.members.filter(c=>c.kind!=="null"&&c.kind!=="void"));return{varName:s,trueType:a,falseType:F(V,O)}}}return null}_registerBuiltins(t){t.set("console",E("Console")),t.set("process",E("Process")),t.set("Math",E("Math")),t.set("JSON",E("JSON")),t.set("Date",E("Date")),t.set("Promise",E("Promise")),t.set("Error",E("Error")),t.set("Buffer",E("Buffer")),t.set("RegExp",E("RegExp")),t.set("Map",E("Map")),t.set("Set",E("Set")),t.set("WeakMap",E("WeakMap")),t.set("WeakSet",E("WeakSet")),t.set("Symbol",E("Symbol")),t.set("Proxy",E("Proxy")),t.set("Reflect",E("Reflect")),t.set("setTimeout",R([R([],O),L],O)),t.set("setInterval",R([R([],O),L],O)),t.set("clearTimeout",I),t.set("clearInterval",I),t.set("parseInt",R([C,W],W)),t.set("parseFloat",R([C],G)),t.set("isNaN",R([L],j)),t.set("isFinite",R([L],j)),t.set("require",R([C],I)),t.set("fetch",R([C],I)),t.set("print",R([],O)),t.set("undefined",O),t.set("Infinity",L),t.set("NaN",L),t.set("globalThis",E("Object")),t.set("Object",E("Object")),t.set("Array",E("Array")),t.set("String",E("String")),t.set("Number",E("Number")),t.set("Boolean",E("Boolean")),t.set("Function",E("Function"))}_checkStmts(t,e){for(let s of t)this._checkStmt(s,e)}_checkStmt(t,e){if(t)switch(t.type){case"VarDecl":{let s=t.typeAnn?x(t.typeAnn):null,r=null;t.init&&(r=this._inferType(t.init,e)),s&&r&&r.kind!=="unknown"&&(this._isAssignable(r,s)||this._err(`Type '${N(r)}' is not assignable to '${t.name}: ${N(s)}'`,t.loc,`Change the value to match '${N(s)}' or update the annotation`)),e.set(t.name,s||r||k);break}case"DestructureDecl":{let s=t.init?this._inferType(t.init,e):k;if(t.patternType==="object")for(let r of t.pattern){let a=k;s.kind==="object"&&s.shape.has(r.key)&&(a=s.shape.get(r.key)),e.set(r.alias,a)}else for(let r=0;r<t.pattern.length;r++){let a=t.pattern[r];if(!a)continue;let c=k;s.kind==="tuple"&&s.types[r]?c=s.types[r]:s.kind==="generic"&&s.name==="Array"&&(c=s.args[0]||k),e.set(a.name,c)}break}case"FnDecl":{let s=t.retType?x(t.retType):null,r=t.params.map(c=>c.typeAnn?x(c.typeAnn):k);t.name&&e.set(t.name,R(r,s||k));let a=e.childFn(s,t.async);for(let c=0;c<t.params.length;c++)a.set(t.params[c].name,r[c]);if(t.inline){let c=this._inferType(t.body,a);s&&c&&c.kind!=="unknown"&&(this._isAssignable(c,s)||this._err(`Function '${t.name||"(anon)"}' returns '${N(c)}' but declared '${N(s)}'`,t.loc,"Fix return type or update the annotation"))}else this._checkStmts(t.body,a);break}case"ClassDecl":{e.set(t.name,E(t.name));let s=e.child(),r=new Map;for(let a of t.fields){let c=a.typeAnn?x(a.typeAnn):k;s.set(a.name,c),r.set(a.name,c)}s.set("self",ut(r));for(let a of t.methods)this._checkStmt(a,s);break}case"DeclareDecl":{let s=t.decl;if(s.type==="FnDecl"){let r=s.retType?x(s.retType):null,a=s.params.map(c=>c.typeAnn?x(c.typeAnn):k);s.name&&e.set(s.name,R(a,r||k))}else if(s.type==="VarDecl"){let r=s.typeAnn?x(s.typeAnn):k;e.set(s.name,r)}else s.type==="ClassDecl"&&e.set(s.name,E(s.name));break}case"TypeDecl":for(let s of t.variants)s.fields.length===0?e.set(s.name,E(t.name)):e.set(s.name,R(s.fields.map(()=>I),E(t.name)));break;case"InterfaceDecl":e.set(t.name,E(t.name));break;case"EnumDecl":e.set(t.name,E(t.name));break;case"IfStmt":{this._inferType(t.cond,e);let s=this._analyzeNarrowingCondition(t.cond,e),r=s?e.narrow(s.varName,s.trueType):e.child(),a=s?e.narrow(s.varName,s.falseType):e.child();this._checkStmts(t.then,r);for(let c of t.elseifs)this._inferType(c.cond,e),this._checkStmts(c.body,e.child());t.else_&&this._checkStmts(t.else_,a);break}case"ForInStmt":{let s=this._inferType(t.iter,e),r=e.child();s.kind==="generic"&&s.args.length>0?r.set(t.var,s.args[0]):s.kind==="tuple"&&s.types.length>0?r.set(t.var,F(...s.types)):r.set(t.var,k),this._checkStmts(t.body,r);break}case"WhileStmt":this._inferType(t.cond,e),this._checkStmts(t.body,e.child());break;case"DoWhileStmt":this._checkStmts(t.body,e.child()),this._inferType(t.cond,e);break;case"MatchStmt":this._inferType(t.subject,e);for(let s of t.arms){let r=e.child();if(s.pattern.type==="VariantPat")for(let a of s.pattern.bindings)r.set(a,k);s.guard&&this._inferType(s.guard,r),this._checkStmts(s.body,r)}break;case"ReturnStmt":{let s=e.retType;if(t.value){let r=this._inferType(t.value,e);if(s&&r&&r.kind!=="unknown"&&s.kind!=="unknown"){let a=e.isAsync&&s.kind==="generic"&&s.name==="Promise"?s.args[0]:s;this._isAssignable(r,a)||this._err(`Return type '${N(r)}' is not assignable to declared '${N(a)}'`,t.loc,"Fix return expression or update return type annotation")}}else s&&s.kind!=="void"&&s.kind!=="any"&&s.kind!=="unknown"&&this._warn(`Missing return value \u2014 function declares return type '${N(s)}'`,t.loc);break}case"ThrowStmt":this._inferType(t.value,e);break;case"TryCatchStmt":{if(this._checkStmts(t.tryBody,e.child()),t.catchBody){let s=e.child();t.catchParam&&s.set(t.catchParam,F(E("Error"),k)),this._checkStmts(t.catchBody,s)}t.finallyBody&&this._checkStmts(t.finallyBody,e.child());break}case"ImportDecl":t.defaultName&&e.set(t.defaultName,I),t.namespaceName&&e.set(t.namespaceName,I);for(let s of t.names)e.set(typeof s=="string"?s:s.alias,I);break;case"ExportDecl":this._checkStmt(t.decl,e);break;case"ExprStmt":this._inferType(t.expr,e);break;case"BreakStmt":case"ContinueStmt":break}}_inferType(t,e){if(!t)return O;switch(t.type){case"NumberLit":return Number.isInteger(t.value)?W:G;case"StringLit":case"TemplateLit":return C;case"BoolLit":return j;case"NullLit":return V;case"RegexLit":return I;case"SelfExpr":return e.get("self")||k;case"Identifier":{let s=e.get(t.name);return s||(this.classes.has(t.name)||this.enums.has(t.name)||this.interfaces.has(t.name)?E(t.name):k)}case"ArrayExpr":{if(!t.items||t.items.length===0)return X(k);let s=t.items.filter(r=>r&&r.type!=="SpreadExpr").map(r=>this._inferType(r,e));return X(s.reduce(pt,k))}case"ObjectExpr":{let s=new Map;for(let r of t.pairs||[])r.spread||s.set(String(r.key),this._inferType(r.value,e));return ut(s)}case"NewExpr":for(let s of t.args)this._inferType(s,e);return E(t.callee);case"CallExpr":{let s=this._inferType(t.callee,e);for(let r of t.args)this._inferType(r,e);return s&&s.kind==="fn"?(this._checkCallArgs(t,s,e),s.ret||k):k}case"OptCallExpr":this._inferType(t.callee,e);for(let s of t.args)this._inferType(s,e);return k;case"MemberExpr":case"OptMemberExpr":{let s=this._inferType(t.obj,e);return s.kind==="object"&&s.shape.has(t.prop)?s.shape.get(t.prop):k}case"IndexExpr":case"OptIndexExpr":{let s=this._inferType(t.obj,e);return this._inferType(t.idx,e),s.kind==="generic"&&s.args.length>0?s.args[0]:s.kind==="tuple"?F(...s.types):s.kind==="record"?s.val:k}case"BinaryExpr":{let s=this._inferType(t.left,e),r=this._inferType(t.right,e),a=t.op;if(["+","-","*","/","%","**"].includes(a)){if(s.kind==="primitive"&&s.name==="String"||r.kind==="primitive"&&r.name==="String")return C;if(s.kind==="unknown"||r.kind==="unknown")return k;if(s.kind==="any"||r.kind==="any")return L;if(s.kind==="primitive"&&r.kind==="primitive"){let c=s.name,h=r.name;if(c==="Int"&&h==="Int")return W;if(["Float","Int"].includes(c)&&["Float","Int"].includes(h))return G}return L}return["===","!==","==","!=","<","<=",">",">=","&&","||","instanceof","in"].includes(a)?j:a==="??"?pt(s,r):["&","|","^","<<",">>"].includes(a)?W:k}case"UnaryExpr":{let s=this._inferType(t.operand,e);return t.op==="!"||t.op==="not"?j:t.op==="-"?s.kind==="primitive"&&s.name==="Int"?W:s.kind==="primitive"&&s.name==="Float"?G:L:t.op==="~"?W:s}case"UpdateExpr":return this._inferType(t.operand,e),L;case"TernaryExpr":{let s=this._analyzeNarrowingCondition(t.cond,e),r=s?e.narrow(s.varName,s.trueType):e,a=s?e.narrow(s.varName,s.falseType):e;this._inferType(t.cond,e);let c=this._inferType(t.then,r),h=this._inferType(t.else_,a);return pt(c,h)}case"AssignExpr":{let s=this._inferType(t.value,e),r=this._inferType(t.target,e);return r&&r.kind!=="unknown"&&s&&s.kind!=="unknown"&&(this._isAssignable(s,r)||this._err(`Cannot assign '${N(s)}' to type '${N(r)}'`,t.target.loc||t.loc,"Ensure the value matches the declared type")),s}case"AwaitExpr":{let s=this._inferType(t.operand,e);return s.kind==="generic"&&s.name==="Promise"&&s.args[0]||k}case"TypeofExpr":return this._inferType(t.operand,e),C;case"PipeExpr":return this._inferType(t.left,e),this._inferType(t.right,e);case"SpreadExpr":return this._inferType(t.expr,e),k;case"RangeExpr":return this._inferType(t.start,e),this._inferType(t.end,e),X(W);case"LambdaExpr":{let s=e.child();for(let c of t.params)s.set(c.name,c.typeAnn?x(c.typeAnn):k);let r=this._inferType(t.body,s),a=t.params.map(c=>c.typeAnn?x(c.typeAnn):k);return R(a,r)}case"FnDecl":{let s=t.retType?x(t.retType):null,r=e.childFn(s,t.async);for(let c of t.params||[])r.set(c.name,c.typeAnn?x(c.typeAnn):k);let a=(t.params||[]).map(c=>c.typeAnn?x(c.typeAnn):k);if(t.inline){let c=this._inferType(t.body,r);return R(a,s||c)}return this._checkStmts(t.body,r),R(a,s||k)}case"CastExpr":return this._inferType(t.expr,e),t.castType?x(t.castType):I;case"SatisfiesExpr":case"NonNullExpr":case"AsConstExpr":{let s=this._inferType(t.expr,e);if(t.type==="SatisfiesExpr"&&t.satType){let r=x(t.satType);this._isAssignable(s,r)||this._err(`Type '${N(s)}' does not satisfy '${N(r)}'`,t.loc)}return s}case"IsExpr":return this._inferType(t.expr,e),j;default:return k}}_checkCallArgs(t,e,s){let r=t.args||[],a=e.params||[];for(let c=0;c<r.length;c++){let h=this._inferType(r[c],s),l=a[c]||I;l.kind!=="any"&&h&&h.kind!=="unknown"&&(this._isAssignable(h,l)||this._err(`Argument ${c+1}: '${N(h)}' is not assignable to '${N(l)}'`,t.loc,"Check function signature"))}}};le.exports={FluxTypeChecker:$t,parseAnnotation:x,typeStr:N,isAssignable:_e,mergeTypes:pt,splitAtTopLevel:K,T_ANY:I,T_UNKNOWN:k,T_NEVER:ct,T_VOID:O,T_NULL:V,T_STRING:C,T_INT:W,T_FLOAT:G,T_NUMBER:L,T_BOOL:j,T_UNION:F,T_INTERSECTION:ae,T_ARRAY:X,T_TUPLE:It,T_NULLABLE:ce,T_NAMED:E,T_FN:R,T_OBJECT:ut,T_RECORD:he,T_LITERAL:Oe}});var _t=_((Os,pe)=>{"use strict";var mt=["range","zip","enumerate","flatten","chunk","unique","groupBy","sortBy","map","filter","reduce","forEach","find","findIndex","some","every","join","sort","flat","flatMap","includes","first","last","take","drop","takeWhile","dropWhile","compact","intersection","difference","arrayUnion","unzip","countBy","minBy","maxBy","toPairs","partition","count","head","tail","nth","rotate","sliding","clamp","sum","product","min","max","abs","floor","ceil","round","mean","median","stdDev","lerp","randInt","sample","shuffle","pick","omit","deepEqual","deepClone","mapValues","filterValues","fromEntries","keys","values","entries","merge","invert","defaults","capitalize","camelCase","snakeCase","kebabCase","truncate","pad","padStart","padEnd","trim","trimStart","trimEnd","words","lines","startsWith","endsWith","repeat","replaceAll","reverseStr","isNil","isString","isNumber","isArray","isObject","isFunction","isBool","sleep","retry","memoize","timeout","debounce","throttle","allSettled","pipe","compose","partial","curry","identity","noop","once","flip","complement"];function Le(n){let t=n?new Set(n.filter(s=>mt.includes(s))):new Set(mt);if(t.size===0)return"";let e=["// \u2500\u2500 Flux stdlib \u2500\u2500"];return t.has("map")&&e.push(`
65
- function map(arr, fn) { return arr.map(fn); }`),t.has("filter")&&e.push(`
66
- function filter(arr, fn) { return arr.filter(fn); }`),t.has("reduce")&&e.push(`
67
- function reduce(arr, fn, init) { return arguments.length >= 3 ? arr.reduce(fn, init) : arr.reduce(fn); }`),t.has("forEach")&&e.push(`
68
- function forEach(arr, fn) { arr.forEach(fn); return arr; }`),t.has("find")&&e.push(`
69
- function find(arr, fn) { return arr.find(fn); }`),t.has("findIndex")&&e.push(`
70
- function findIndex(arr, fn) { return arr.findIndex(fn); }`),t.has("some")&&e.push(`
71
- function some(arr, fn) { return arr.some(fn); }`),t.has("every")&&e.push(`
72
- function every(arr, fn) { return arr.every(fn); }`),t.has("join")&&e.push(`
73
- function join(arr, sep) { return arr.join(sep != null ? sep : ','); }`),t.has("sort")&&e.push(`
74
- function sort(arr, fn) { return arr.slice().sort(fn); }`),t.has("flat")&&e.push(`
75
- function flat(arr, depth) { return arr.flat(depth != null ? depth : 1); }`),t.has("flatMap")&&e.push(`
76
- function flatMap(arr, fn) { return arr.flatMap(fn); }`),t.has("includes")&&e.push(`
77
- function includes(arr, val) { return arr.includes(val); }`),t.has("range")&&e.push(`
78
- function range(start, end, step) {
56
+ }`;C.exports.FLUX_H_BROWSER=vt;var It='function _fluxH(tag,props,...children){\n const VOID=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);\n if(tag==="")return children.flat(Infinity).map(c=>c==null?"":String(c)).join("");\n let attrs="";\n if(props){for(const[k,v]of Object.entries(props)){if(k==="class"||k==="className")attrs+=` class="${v}"`;else if(k==="style"&&typeof v==="object")attrs+=` style="${Object.entries(v).map(([p,val])=>p.replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+":"+val).join(";")}"`;else if(typeof v!=="function"&&typeof v!=="boolean")attrs+=` ${k}="${String(v).replace(/"/g,"&quot;")}"`;else if(v===true)attrs+=` ${k}`;}}\n const inner=children.flat(Infinity).map(c=>c==null?"":String(c)).join("");\n if(VOID.has(tag))return`<${tag}${attrs}>`;\n return`<${tag}${attrs}>${inner}</${tag}>`;\n}';C.exports.FLUX_H_SERVER=It;var Lt='function _fluxCSS(css){const s=document.createElement("style");s.textContent=css;document.head.appendChild(s);return css;}';C.exports.FLUX_CSS_BROWSER=Lt;var Ct="function _fluxCSS(css){return css;}";C.exports.FLUX_CSS_SERVER=Ct;var tt=class{constructor(t,e,s,i){this.src=t,this.pos=e,this.out=s,this.hasJsx=i}transform(){for(;this.pos<this.src.length;)this.scanTop();return this.hasJsx=this.out!=this.src,this.out}scanTop(){let t=this.src[this.pos];if(t=="/"&&this.src[this.pos+1]=="/"){let e=this.src.indexOf(`
57
+ `,this.pos);e==-1?(this.out=this.out+this.src.slice(this.pos),this.pos=this.src.length):(this.out=this.out+this.src.slice(this.pos,e+1),this.pos=e+1);return}if(t=="/"&&this.src[this.pos+1]=="*"){let e=this.src.indexOf("*/",this.pos+2);e==-1?(this.out=this.out+this.src.slice(this.pos),this.pos=this.src.length):(this.out=this.out+this.src.slice(this.pos,e+2),this.pos=e+2);return}if(t=='"'){this.passString('"');return}if(t=="'"){this.passString("'");return}if(t=="`"){this.passTemplateLit();return}if(t=="<"&&this.isJsxStart()){let e=this.parseJsxElement();this.out=this.out+e;return}this.out=this.out+t,this.pos=this.pos+1}isJsxStart(){let t=this.src[this.pos+1]??"";if(t!=">"&&!(t>="a"&&t<="z")&&!(t>="A"&&t<="Z"))return!1;let e=this.pos-1;for(;e>=0&&(this.src[e]==" "||this.src[e]==" ");)e=e-1;if(e<0)return!0;let s=this.src[e];if(`=([{,:>
58
+ ?`.includes(s))return!0;if(/[a-z]/.test(s)){let i=e;for(;i>=0&&/[a-z]/.test(this.src[i]);)i=i-1;let n=this.src.slice(i+1,e+1);if(new Set(["return","not","and","or","val","var","await","yield","else","in","throw"]).has(n))return!0}return!1}passString(t){for(this.out=this.out+t,this.pos=this.pos+1;this.pos<this.src.length;){let e=this.src[this.pos];if(e=="\\"){this.out=this.out+e+(this.src[this.pos+1]??""),this.pos=this.pos+2;continue}if(e==t){this.out=this.out+e,this.pos=this.pos+1;return}this.out=this.out+e,this.pos=this.pos+1}}passTemplateLit(){for(this.out=this.out+"`",this.pos=this.pos+1;this.pos<this.src.length;){let t=this.src[this.pos];if(t=="\\"){this.out=this.out+t+(this.src[this.pos+1]??""),this.pos=this.pos+2;continue}if(t=="`"){this.out=this.out+t,this.pos=this.pos+1;return}this.out=this.out+t,this.pos=this.pos+1}}parseJsxElement(){if(this.pos=this.pos+1,this.src[this.pos]==">"){this.pos=this.pos+1;let s=this.parseJsxChildren("");return this.expectClose(""),'_fluxH("",null'+(s.length>0?","+s.join(","):"")+")"}let t=this.readTagName(),e=this.parseJsxAttrs();if(this.src[this.pos]=="/"&&this.src[this.pos+1]==">")return this.pos=this.pos+2,'_fluxH("'+t+'",'+e+")";if(this.src[this.pos]==">"){this.pos=this.pos+1;let s=this.parseJsxChildren(t);this.expectClose(t);let i=s.length>0?","+s.join(","):"";return'_fluxH("'+t+'",'+e+i+")"}return"<"+t}readTagName(){let t="";for(;this.pos<this.src.length;){let e=this.src[this.pos];if(/[a-zA-Z0-9\-_\.]/.test(e))t=t+e,this.pos=this.pos+1;else break}return t}parseJsxAttrs(){this.skipWs();let t=[],e=[],s=null;for(;this.pos<this.src.length;){let i=this.src[this.pos];if(i==">"||i=="/"&&this.src[this.pos+1]==">"||(this.skipWs(),!/[a-zA-Z_\-]/.test(this.src[this.pos]??"")))break;let n="";for(;this.pos<this.src.length&&/[a-zA-Z0-9\-_:]/.test(this.src[this.pos]);)n=n+this.src[this.pos],this.pos=this.pos+1;if(this.skipWs(),this.src[this.pos]!="="){let o=Dt[n];o!=null?e.push(o):t.push('"'+n+'":true');continue}this.pos=this.pos+1,this.skipWs();let h=this.src[this.pos],l="",c="";if(h=='"'||h=="'"){let o=h;this.pos=this.pos+1;let u="";for(;this.pos<this.src.length&&this.src[this.pos]!=o;)this.src[this.pos]=="\\"?(u=u+this.src[this.pos]+this.src[this.pos+1],this.pos=this.pos+2):(u=u+this.src[this.pos],this.pos=this.pos+1);this.pos=this.pos+1,l=u}else if(h=="{")c=this.readBraced();else{let o=Dt[n];o!=null?e.push(o):t.push('"'+n+'":true'),this.skipWs();continue}if(l!=null&&Rt[n]){let o=Rt[n](JSON.stringify(l));e.push(o)}else c!=null&&n=="style"?s=c:l!=null?t.push('"'+n+'":'+JSON.stringify(l)):t.push('"'+n+'":'+c);this.skipWs()}if(e.length>0||s!=null){let i=e.length>0?"{"+e.join(",")+"}":null;s!=null&&i!=null?t.push('"style":Object.assign('+s+","+i+")"):s!=null?t.push('"style":'+s):t.push('"style":{'+e.join(",")+"}")}return t.length>0?"{"+t.join(",")+"}":"null"}readBraced(){this.pos=this.pos+1;let t=1,e="";for(;this.pos<this.src.length&&t>0;){let s=this.src[this.pos];if(s=="{"&&(t=t+1),s=="}"&&(t=t-1,t==0)){this.pos=this.pos+1;break}e=e+s,this.pos=this.pos+1}return e.trim()}parseJsxChildren(t){let e=[];for(;this.pos<this.src.length&&!(this.src[this.pos]=="<"&&this.src[this.pos+1]=="/");){if(this.src[this.pos]=="<"){let n=this.src[this.pos+1]??"";if(n>="a"&&n<="z"||n>="A"&&n<="Z"||n==">"){e.push(this.parseJsxElement());continue}}if(this.src[this.pos]=="{"){let n=this.readBraced();n.trim()&&e.push(n);continue}let s="";for(;this.pos<this.src.length;){let n=this.src[this.pos];if(n=="<"||n=="{")break;s=s+n,this.pos=this.pos+1}let i=s.replace(/\s+/g," ").trim();i&&e.push(JSON.stringify(i))}return e}expectClose(t){if(this.src[this.pos]=="<"&&this.src[this.pos+1]=="/"){for(this.pos=this.pos+2;this.pos<this.src.length&&this.src[this.pos]!=">";)this.pos=this.pos+1;this.src[this.pos]==">"&&(this.pos=this.pos+1)}}skipWs(){for(;this.pos<this.src.length&&(this.src[this.pos]==" "||this.src[this.pos]==" ");)this.pos=this.pos+1}};C.exports.JsxPreprocessor=tt;function oe(a,t){let e=(t??{}).target??"browser",s=new tt(a,0,"",!1),i=s.transform(),n=s.hasJsx||a.includes("_fluxH")||a.includes("_fluxCSS"),h=e=="browser"?vt:It,l=e=="browser"?Lt:Ct;return{source:i,hasJsx:n,runtimeHelpers:h+l}}C.exports.transformJsx=oe});var Pt=S((hs,et)=>{"use strict";var z=class{constructor(t,e,s,i,n,h){this.message=t,this.loc=e,this.hint=s,this.name=i,this.line=n,this.col=h}};et.exports.CheckError=z;var x=class{constructor(t,e){this.parent=t,this.vars=e}define(t,e,s){this.vars.set(t,{kind:e,loc:s})}lookup(t){let e=this;for(;e;){if(e.vars.has(t))return e.vars.get(t);e=e.parent}return null}isVal(t){let e=this.lookup(t);return e&&e.kind=="val"}};et.exports.Scope=x;var kt=class{constructor(t,e){this.errors=t,this.warnings=e}error(t,e,s){let i=new z;i.message=t,i.loc=e,i.hint=s??null,i.name="CheckError",e&&(i.line=e.line,i.col=e.col),this.errors.push(i)}warn(t,e,s){let i=new z;i.message=t,i.loc=e,i.hint=s??null,i.name="CheckError",e&&(i.line=e.line,i.col=e.col),this.warnings.push(i)}check(t){this.errors=[],this.warnings=[];let e=new x(null,new Map);return this.walkStmts(t.body,e),{errors:this.errors,warnings:this.warnings}}walkStmts(t,e){for(let s of t)this.walkStmt(s,e)}walkStmt(t,e){if(t)if(t.type=="VarDecl")t.init&&this.walkExpr(t.init,e),e.define(t.name,t.kind,t.loc);else if(t.type=="DestructureDecl")if(t.init&&this.walkExpr(t.init,e),t.patternType=="object")for(let s of t.pattern)e.define(s.alias,t.kind,t.loc);else for(let s of t.pattern)s&&e.define(s.name,t.kind,t.loc);else if(t.type=="FnDecl"){let s=new x(e,new Map);for(let i of t.params)s.define(i.name,"val",t.loc);t.name&&e.define(t.name,"val",t.loc),t.inline?this.walkExpr(t.body,s):this.walkStmts(t.body,s)}else if(t.type=="ClassDecl"){e.define(t.name,"val",t.loc);let s=new x(e,new Map);for(let i of t.fields)s.define(i.name,"var",t.loc);for(let i of t.methods)this.walkStmt(i,s)}else if(t.type=="TypeDecl")for(let s of t.variants)e.define(s.name,"val",t.loc);else if(t.type=="InterfaceDecl")e.define(t.name,"val",t.loc);else if(t.type=="EnumDecl")e.define(t.name,"val",t.loc);else if(t.type=="IfStmt"){this.walkExpr(t.cond,e),this.walkStmts(t.then,new x(e,new Map));for(let s of t.elseifs)this.walkExpr(s.cond,e),this.walkStmts(s.body,new x(e,new Map));t.else_&&this.walkStmts(t.else_,new x(e,new Map))}else if(t.type=="ForInStmt"){this.walkExpr(t.iter,e);let s=new x(e,new Map);s.define(t.var,"val",t.loc),this.walkStmts(t.body,s)}else if(t.type=="WhileStmt")this.walkExpr(t.cond,e),this.walkStmts(t.body,new x(e,new Map));else if(t.type=="DoWhileStmt")this.walkStmts(t.body,new x(e,new Map)),this.walkExpr(t.cond,e);else if(t.type=="MatchStmt"){this.walkExpr(t.subject,e);for(let s of t.arms){let i=new x(e,new Map);if(s.pattern.type=="VariantPat")for(let n of s.pattern.bindings)i.define(n,"val",t.loc);s.guard&&this.walkExpr(s.guard,i),this.walkStmts(s.body,i)}}else if(t.type=="ReturnStmt")t.value&&this.walkExpr(t.value,e);else if(t.type=="ThrowStmt")this.walkExpr(t.value,e);else if(t.type=="TryCatchStmt"){if(this.walkStmts(t.tryBody,new x(e,new Map)),t.catchBody){let s=new x(e,new Map);t.catchParam&&s.define(t.catchParam,"val",t.loc),this.walkStmts(t.catchBody,s)}t.finallyBody&&this.walkStmts(t.finallyBody,new x(e,new Map))}else if(t.type=="ImportDecl"){t.defaultName&&e.define(t.defaultName,"val",t.loc),t.namespaceName&&e.define(t.namespaceName,"val",t.loc);for(let s of t.names){let i=typeof s=="string"?s:s.alias;e.define(i,"val",t.loc)}}else t.type=="ExportDecl"?t.isDefault?this.walkExpr(t.decl,e):this.walkStmt(t.decl,e):t.type=="ExprStmt"&&this.walkExpr(t.expr,e)}walkExpr(t,e){if(t)if(t.type=="AssignExpr"){let s=t.target;s.type=="Identifier"&&e.isVal(s.name)&&this.error("Cannot reassign 'val "+s.name+"' \u2014 val is immutable",s.loc,"Use 'var "+s.name+"' if you need a mutable variable"),this.walkExpr(t.target,e),this.walkExpr(t.value,e)}else if(t.type=="UpdateExpr")t.operand.type=="Identifier"&&e.isVal(t.operand.name)&&this.error("Cannot apply '"+t.op+"' to 'val "+t.operand.name+"' \u2014 val is immutable",t.operand.loc,"Use 'var "+t.operand.name+"' if you need a mutable variable"),this.walkExpr(t.operand,e);else if(t.type=="BinaryExpr"||t.type=="PipeExpr")this.walkExpr(t.left,e),this.walkExpr(t.right,e);else if(t.type=="UnaryExpr"||t.type=="AwaitExpr"||t.type=="TypeofExpr")this.walkExpr(t.operand,e);else if(t.type=="TernaryExpr")this.walkExpr(t.cond,e),this.walkExpr(t.then,e),this.walkExpr(t.else_,e);else if(t.type=="CallExpr"||t.type=="OptCallExpr"){this.walkExpr(t.callee,e);for(let s of t.args)this.walkExpr(s,e)}else if(t.type=="MemberExpr"||t.type=="OptMemberExpr")this.walkExpr(t.obj,e);else if(t.type=="IndexExpr"||t.type=="OptIndexExpr")this.walkExpr(t.obj,e),this.walkExpr(t.idx,e);else if(t.type=="NewExpr")for(let s of t.args)this.walkExpr(s,e);else if(t.type=="ArrayExpr")for(let s of t.items)s&&this.walkExpr(s,e);else if(t.type=="ObjectExpr")for(let s of t.pairs)s.value&&this.walkExpr(s.value,e);else if(t.type=="SpreadExpr")this.walkExpr(t.expr,e);else if(t.type=="LambdaExpr"){let s=new x(e,new Map);for(let i of t.params)s.define(i.name,"val",null);this.walkExpr(t.body,s)}else if(t.type=="FnDecl"){let s=new x(e,new Map);for(let i of t.params)s.define(i.name,"val",null);t.inline?this.walkExpr(t.body,s):this.walkStmts(t.body,s)}else t.type=="CastExpr"||t.type=="AsConstExpr"||t.type=="SatisfiesExpr"||t.type=="IsExpr"||t.type=="NonNullExpr"?this.walkExpr(t.expr,e):t.type=="RangeExpr"&&(this.walkExpr(t.start,e),this.walkExpr(t.end,e))}};et.exports.Checker=kt});var Wt=S((ls,d)=>{"use strict";var w=Object.freeze({kind:"any"});d.exports.T_ANY=w;var f=Object.freeze({kind:"unknown"});d.exports.T_UNKNOWN=f;var H=Object.freeze({kind:"never"});d.exports.T_NEVER=H;var R=Object.freeze({kind:"void"});d.exports.T_VOID=R;var M=Object.freeze({kind:"null"});d.exports.T_NULL=M;var b=Object.freeze({kind:"primitive",name:"String"});d.exports.T_STRING=b;var U=Object.freeze({kind:"primitive",name:"Int"});d.exports.T_INT=U;var G=Object.freeze({kind:"primitive",name:"Float"});d.exports.T_FLOAT=G;var v=Object.freeze({kind:"primitive",name:"Number"});d.exports.T_NUMBER=v;var O=Object.freeze({kind:"primitive",name:"Bool"});d.exports.T_BOOL=O;function D(...a){let t=[];for(let i of a)if(i&&i.kind=="union")for(let n of i.members)t.push(n);else i&&t.push(i);let e=new Set,s=[];for(let i of t){let n=k(i);e.has(n)||(e.add(n),s.push(i))}return s.length==0?H:s.length==1?s[0]:{kind:"union",members:s}}d.exports.T_UNION=D;function jt(...a){let t=[];for(let e of a)if(e&&e.kind=="intersection")for(let s of e.members)t.push(s);else e&&t.push(e);return t.length==1?t[0]:{kind:"intersection",members:t}}d.exports.T_INTERSECTION=jt;function $(a){return{kind:"generic",name:"Array",args:[a??f]}}d.exports.T_ARRAY=$;function dt(a){return{kind:"tuple",types:a??[]}}d.exports.T_TUPLE=dt;function _t(a){return D(a,M)}d.exports.T_NULLABLE=_t;function m(a){return{kind:"named",name:a}}d.exports.T_NAMED=m;function N(a,t){return{kind:"fn",params:a??[],ret:t??R}}d.exports.T_FN=N;function st(a){return{kind:"object",shape:a??new Map}}d.exports.T_OBJECT=st;function Ut(a,t){return{kind:"record",key:a??b,val:t??f}}d.exports.T_RECORD=Ut;function pe(a,t){return{kind:"literal",value:a,prim:t}}d.exports.T_LITERAL=pe;function k(a){if(!a)return"unknown";if(a.kind=="any")return"Any";if(a.kind=="unknown")return"Unknown";if(a.kind=="never")return"Never";if(a.kind=="void")return"Void";if(a.kind=="null")return"Null";if(a.kind=="primitive")return a.name;if(a.kind=="literal")return JSON.stringify(a.value);if(a.kind=="union")return a.members.map(k).join(" | ");if(a.kind=="intersection")return a.members.map(k).join(" & ");if(a.kind=="tuple")return"["+a.types.map(k).join(", ")+"]";if(a.kind=="object"){let t=[];for(let e of(a.shape??new Map).entries())t.push(e[0]+": "+k(e[1]));return"{"+t.join(", ")+"}"}return a.kind=="record"?"Record<"+k(a.key)+", "+k(a.val)+">":a.kind=="generic"?a.args&&a.args.length>0?a.name+"<"+a.args.map(k).join(", ")+">":a.name:a.kind=="named"?a.name:a.kind=="fn"?"("+(a.params??[]).map(k).join(", ")+") -> "+k(a.ret):a.kind=="keyof"?"keyof "+k(a.inner):a.kind=="conditional"?k(a.check)+" extends "+k(a.extends)+" ? "+k(a.then)+" : "+k(a.else):"unknown"}d.exports.typeStr=k;function _(a,t){let e=[],s=0,i=0,n=0;for(;n<a.length;){let h=a[n];"<([{".includes(h)?s=s+1:">)]}".includes(h)?s=s-1:s==0&&a.slice(n,n+t.length)==t&&(e.push(a.slice(i,n)),i=n+t.length,n=n+t.length-1),n=n+1}return e.push(a.slice(i)),e.filter(h=>h.trim().length>0)}var Ft={String:b,string:b,Int:U,int:U,Float:G,float:G,Number:v,number:v,Bool:O,boolean:O,Boolean:O,bool:O,Void:R,void:R,Never:H,never:H,Any:w,any:w,Unknown:f,unknown:f,Null:M,null:M,undefined:R,Object:m("Object"),object:m("Object"),Symbol:m("Symbol"),symbol:m("Symbol"),BigInt:m("BigInt"),bigint:m("BigInt")};function E(a){if(!a)return null;let t=a.trim();t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1).trim());let e=_(t," | ");if(e.length>1)return D(...e.map(E));let s=_(t," & ");if(s.length>1)return jt(...s.map(E));let i=t.match(/^(\w+)\s+extends\s+(.+?)\s*\?\s*(.+?)\s*:\s*(.+)$/);if(i)return{kind:"conditional",check:E(i[1]),extends:E(i[2]),then:E(i[3]),else:E(i[4])};if(t.startsWith("keyof "))return{kind:"keyof",inner:E(t.slice(6))};if(t.startsWith("typeof "))return{kind:"typeof",name:t.slice(7)};if(t.startsWith("readonly "))return E(t.slice(9));if(t.startsWith("infer "))return w;let n=t.match(/^fn\(([^)]*)\)\s*->\s*(.+)$/)??t.match(/^\(([^)]*)\)\s*->\s*(.+)$/);if(n){let l=n[1].trim(),c=n[2].trim(),o=l?_(l,", ").map(u=>E(u.slice(u.indexOf(":")>=0?u.indexOf(":")+1:0).trim())):[];return N(o,E(c))}if(t.endsWith("?"))return _t(E(t.slice(0,-1)));if(t.endsWith("[]"))return $(E(t.slice(0,-2)));if(t.startsWith("[")&&t.endsWith("]")){let l=t.slice(1,-1);if(!l.trim())return dt([]);let c=_(l,", ");return dt(c.map(o=>E(o.replace(/^\.\.\./,"").trim())))}if(t.startsWith(") and s.endsWith(")){let l=t.slice(1,-1).trim(),c=new Map;if(l){let o=_(l,", ");for(let u of o){let y=u.match(/^\[(\w+):\s*\w+\]:\s*(.+)$/);if(y){c.set("[index]",E(y[2]));continue}let g=u.indexOf(":");if(g>=0){let T=u.slice(0,g).trim().replace(/^readonly\s+/,""),ot=T.replace(/\?$/,""),F=T.endsWith("?"),W=E(u.slice(g+1).trim());c.set(ot,F?D(W,R):W)}}}return st(c)}let h=t.match(/^(\w+)<(.+)>$/s);if(h){let l=h[1],o=_(h[2],", ").map(u=>E(u.trim()));return l=="Array"||l=="List"||l=="ReadonlyArray"?$(o[0]??f):l=="NonNullable"?ue(o[0]):l=="Partial"?{kind:"utility",util:"Partial",inner:o[0]}:l=="Required"?{kind:"utility",util:"Required",inner:o[0]}:l=="Readonly"?o[0]:l=="Record"?Ut(o[0]??b,o[1]??f):l=="Pick"?{kind:"utility",util:"Pick",inner:o[0],keys:o[1]}:l=="Omit"?{kind:"utility",util:"Omit",inner:o[0],keys:o[1]}:l=="Exclude"?{kind:"utility",util:"Exclude",inner:o[0],keys:o[1]}:l=="Extract"?{kind:"utility",util:"Extract",inner:o[0],keys:o[1]}:l=="ReturnType"?{kind:"utility",util:"ReturnType",inner:o[0]}:l=="Parameters"?{kind:"utility",util:"Parameters",inner:o[0]}:l=="Awaited"?{kind:"utility",util:"Awaited",inner:o[0]}:{kind:"generic",name:l,args:o}}return Ft[t]?Ft[t]:m(t)}d.exports.parseAnnotation=E;function ue(a){return a?a.kind=="union"?D(...a.members.filter(t=>t.kind!="null"&&t.kind!="void")):a.kind=="null"||a.kind=="void"?H:a:f}function A(a,t){if(!a||!t||t.kind=="any"||a.kind=="any"||a.kind=="never"||t.kind=="unknown"||a.kind=="void"&&t.kind=="void"||a.kind=="null"&&t.kind=="null")return!0;if(a.kind=="null"&&t.kind=="union")return t.members.some(e=>e.kind=="null"||e.kind=="any"||e.kind=="void");if(a.kind=="union")return a.members.every(e=>A(e,t));if(t.kind=="union")return t.members.some(e=>A(a,e));if(a.kind=="intersection")return a.members.some(e=>A(e,t));if(t.kind=="intersection")return t.members.every(e=>A(a,e));if(a.kind=="primitive"&&t.kind=="primitive")return a.name==t.name||t.name=="Number"&&(a.name=="Int"||a.name=="Float"||a.name=="Number")||t.name=="Float"&&a.name=="Int"||a.name=="Bool"&&t.name=="Boolean"||a.name=="Boolean"&&t.name=="Bool";if(a.kind=="literal"&&t.kind=="primitive")return{string:"String",number:"Number",boolean:"Bool"}[a.prim]==t.name||a.prim=="number"&&(t.name=="Int"||t.name=="Float"||t.name=="Number");if(a.kind=="named"&&t.kind=="named")return a.name==t.name||t.name=="Object";if(a.kind=="generic"&&t.kind=="generic"){let e=new Set(["Array","List","ReadonlyArray"]);return a.name!=t.name&&!(e.has(a.name)&&e.has(t.name))||a.args.length!=t.args.length?!1:a.args.every((s,i)=>A(s,t.args[i]))}if(a.kind=="tuple"&&t.kind=="tuple")return a.types.length!=t.types.length?!1:a.types.every((e,s)=>A(e,t.types[s]));if(a.kind=="generic"&&a.name=="Array"&&t.kind=="tuple"){let e=a.args[0]??f;return e.kind=="unknown"?!0:t.types.every(s=>A(e,s))}if(a.kind=="object"&&t.kind=="object"){for(let e of t.shape.entries()){let s=e[0],i=e[1];if(!a.shape.has(s)||!A(a.shape.get(s),i))return!1}return!0}return a.kind=="object"&&t.kind=="named"?!0:a.kind=="fn"&&t.kind=="fn"?t.ret&&a.ret?A(a.ret,t.ret):!0:a.kind=="record"&&t.kind=="record"?A(a.val,t.val):t.kind=="utility"||a.kind=="utility"}function Bt(a,t){return!a||a.kind=="unknown"?t??f:!t||t.kind=="unknown"||k(a)==k(t)?a:a.kind=="any"||t.kind=="any"?w:D(a,t)}var it=class a{constructor(t,e,s,i){this.parent=t,this.vars=e,this.retType=s,this.isAsync=i}set(t,e){this.vars.set(t,e)}has(t){let e=this;for(;e;){if(e.vars.has(t))return!0;e=e.parent}return!1}get(t){let e=this;for(;e;){if(e.vars.has(t))return e.vars.get(t);e=e.parent}return null}child(){return new a(this,new Map,this.retType,this.isAsync)}childFn(t,e){return new a(this,new Map,t,e??!1)}narrow(t,e){let s=new a(this,new Map,this.retType,this.isAsync);return t&&e&&s.vars.set(t,e),s}};d.exports.TypeEnv=it;var rt=class{constructor(t,e,s,i,n){this.message=t,this.name=e,this.hint=s,this.line=i,this.col=n}},gt=class{constructor(t,e,s,i,n,h){this.errors=t,this.warnings=e,this.interfaces=s,this.types=i,this.classes=n,this.enums=h}_err(t,e,s){let i=new rt;i.message=t,i.name="TypeError",i.hint=s??null,e&&(i.line=e.line,i.col=e.col),this.errors.push(i)}_warn(t,e,s){let i=new rt;i.message=t,i.name="TypeError",i.hint=s??null,e&&(i.line=e.line,i.col=e.col),this.warnings.push(i)}check(t){this.errors=[],this.warnings=[],this.interfaces=new Map,this.types=new Map,this.classes=new Map,this.enums=new Map,this._collectDeclarations(t.body),this._validateImplementations();let e=new it(null,new Map,null,!1);return this._registerBuiltins(e),this._checkStmts(t.body,e),{errors:this.errors,warnings:this.warnings}}_collectDeclarations(t){for(let e of t){let s=e.type=="ExportDecl"?e.decl:e;s&&(s.type=="InterfaceDecl"?this.interfaces.set(s.name,s):s.type=="TypeDecl"?this.types.set(s.name,s):s.type=="ClassDecl"?this.classes.set(s.name,s):s.type=="EnumDecl"&&this.enums.set(s.name,s))}}_validateImplementations(){for(let t of this.classes.entries()){let e=t[1];for(let s of e.interfaces??[])this._checkInterfaceImpl(e,s)}}_checkInterfaceImpl(t,e){let s=this.interfaces.get(e);if(!s){this._warn("Class '"+t.name+"' implements unknown interface '"+e+"'",t.loc,"Define 'interface "+e+"' before use");return}for(let i of s.members)if(i.kind=="method")t.methods.find(h=>h.name==i.name)||this._err("Class '"+t.name+"' does not implement method '"+i.name+"()' required by '"+e+"'",t.loc,"Add 'fn "+i.name+"(...)' to the class");else if(i.kind=="field"&&!i.optional){let n=t.fields.find(l=>l.name==i.name),h=t.methods.find(l=>l.name==i.name);!n&&!h&&this._err("Class '"+t.name+"' is missing field '"+i.name+"' required by '"+e+"'",t.loc,"Add '"+i.name+": "+(i.typeAnn??"Any")+"' to the class")}for(let i of s.superInterfaces??[])this._checkInterfaceImpl(t,i)}_isStructurallyCompatible(t,e){let s=this.interfaces.get(e);if(!s){let i=this.classes.get(e);if(!i)return!1;for(let n of i.fields)if(!t.has(n.name)&&!n.optional)return!1;return!0}for(let i of s.members)if(i.kind=="field"&&!i.optional&&!t.has(i.name))return!1;return!0}_isAssignable(t,e){if(!t||!e||e.kind=="any"||t.kind=="any"||t.kind=="never"||e.kind=="unknown")return!0;if(t.kind=="object"&&e.kind=="named")return this._isStructurallyCompatible(t.shape,e.name);if(t.kind=="named"&&e.kind=="named"){if(t.name==e.name||e.name=="Object")return!0;let s=this.classes.get(t.name);if(s&&(s.interfaces??[]).includes(e.name)||s&&s.superClass==e.name)return!0;let i=this.interfaces.get(t.name);return!!(i&&(i.superInterfaces??[]).includes(e.name))}return e.kind=="utility"?e.util=="Partial"?!0:e.util=="Required"?this._isAssignable(t,e.inner):e.util=="NonNullable"?t.kind!="null"&&t.kind!="void":!0:t.kind=="utility"?!0:A(t,e)}_analyzeNarrowingCondition(t,e){if(!t)return null;if(t.type=="BinaryExpr"&&(t.op=="!="||t.op=="!==")&&t.left.type=="Identifier"&&t.right.type=="NullLit"){let s=t.left.name,i=e.get(s);if(i&&i.kind=="union"){let n=D(...i.members.filter(h=>h.kind!="null"&&h.kind!="void"));return{varName:s,trueType:n,falseType:D(M,R)}}}if(t.type=="BinaryExpr"&&(t.op=="==="||t.op=="==")&&t.left.type=="TypeofExpr"&&t.left.operand.type=="Identifier"&&t.right.type=="StringLit"){let s=t.left.operand.name,n={string:b,number:v,boolean:O,undefined:R}[t.right.value]??f;return{varName:s,trueType:n,falseType:e.get(s)??f}}if(t.type=="BinaryExpr"&&t.op=="instanceof"&&t.left.type=="Identifier"){let s=t.left.name,i=t.right.type=="Identifier"?t.right.name:null;if(i)return{varName:s,trueType:m(i),falseType:e.get(s)??f}}if(t.type=="Identifier"){let s=t.name,i=e.get(s);if(i&&i.kind=="union"){let n=D(...i.members.filter(h=>h.kind!="null"&&h.kind!="void"));return{varName:s,trueType:n,falseType:D(M,R)}}}return null}_registerBuiltins(t){t.set("console",m("Console")),t.set("process",m("Process")),t.set("Math",m("Math")),t.set("JSON",m("JSON")),t.set("Date",m("Date")),t.set("Promise",m("Promise")),t.set("Error",m("Error")),t.set("Buffer",m("Buffer")),t.set("RegExp",m("RegExp")),t.set("Map",m("Map")),t.set("Set",m("Set")),t.set("WeakMap",m("WeakMap")),t.set("WeakSet",m("WeakSet")),t.set("Symbol",m("Symbol")),t.set("Object",m("Object")),t.set("Array",m("Array")),t.set("String",m("String")),t.set("Number",m("Number")),t.set("Boolean",m("Boolean")),t.set("Function",m("Function")),t.set("parseInt",N([b,U],U)),t.set("parseFloat",N([b],G)),t.set("isNaN",N([v],O)),t.set("isFinite",N([v],O)),t.set("require",N([b],w)),t.set("fetch",N([b],w)),t.set("print",N([],R)),t.set("undefined",R),t.set("Infinity",v),t.set("NaN",v),t.set("globalThis",m("Object"))}_inferType(t,e){if(!t)return f;if(t.type=="NumberLit")return String(t.value).includes(".")?G:U;if(t.type=="StringLit")return b;if(t.type=="BoolLit")return O;if(t.type=="NullLit")return M;if(t.type=="Identifier")return e.get(t.name)??f;if(t.type=="ArrayExpr"){if(t.items.length==0)return $(f);let i=t.items.map(n=>n?this._inferType(n,e):f).reduce((n,h)=>Bt(n,h),f);return $(i)}if(t.type=="ObjectExpr"){let s=new Map;for(let i of t.pairs)!i.spread&&i.key&&s.set(i.key,i.value?this._inferType(i.value,e):f);return st(s)}if(t.type=="LambdaExpr"){let s=t.params.map(n=>n.typeAnn?E(n.typeAnn):f),i=t.retType?E(t.retType):f;return N(s,i)}if(t.type=="CallExpr"||t.type=="OptCallExpr"){let s=this._inferType(t.callee,e);return s.kind=="fn"?s.ret??f:f}if(t.type=="MemberExpr"||t.type=="OptMemberExpr")return f;if(t.type=="TernaryExpr"){let s=this._inferType(t.then,e),i=this._inferType(t.else_,e);return Bt(s,i)}return t.type=="BinaryExpr"?t.op=="+"||t.op=="-"||t.op=="*"||t.op=="/"||t.op=="%"?v:t.op=="=="||t.op=="!="||t.op=="==="||t.op=="!=="||t.op=="<"||t.op==">"||t.op=="<="||t.op==">="||t.op=="and"||t.op=="or"||t.op=="&&"||t.op=="||"?O:f:t.type=="AwaitExpr"?this._inferType(t.operand,e):t.type=="NewExpr"?t.callee&&t.callee.type=="Identifier"?m(t.callee.name):f:t.type=="TemplateLit"?b:t.type=="CastExpr"||t.type=="AsConstExpr"?t.typeAnn?E(t.typeAnn):this._inferType(t.expr,e):f}_checkStmts(t,e){for(let s of t)this._checkStmt(s,e)}_checkStmt(t,e){if(t)if(t.type=="VarDecl"){let s=t.typeAnn?E(t.typeAnn):null,i=null;t.init&&(i=this._inferType(t.init,e)),s&&i&&i.kind!="unknown"&&(this._isAssignable(i,s)||this._err("Type '"+k(i)+"' is not assignable to '"+t.name+": "+k(s)+"'",t.loc,"Change the value to match '"+k(s)+"' or update the annotation")),e.set(t.name,s??i??f)}else if(t.type=="DestructureDecl"){let s=t.init?this._inferType(t.init,e):f;if(t.patternType=="object")for(let i of t.pattern){let n=f;s.kind=="object"&&s.shape.has(i.key)&&(n=s.shape.get(i.key)),e.set(i.alias,n)}else{let i=0;for(let n of t.pattern){if(n){let h=f;s.kind=="tuple"&&s.types[i]?h=s.types[i]:s.kind=="generic"&&s.name=="Array"&&(h=s.args[0]??f),e.set(n.name,h)}i=i+1}}}else if(t.type=="FnDecl"){let s=t.retType?E(t.retType):null,i=t.params.map(l=>l.typeAnn?E(l.typeAnn):f);t.name&&e.set(t.name,N(i,s??f));let n=e.childFn(s,t.async),h=0;for(let l of t.params)n.set(l.name,i[h]),h=h+1;if(t.inline){let l=this._inferType(t.body,n);s&&l&&l.kind!="unknown"&&(this._isAssignable(l,s)||this._err("Function '"+(t.name??"(anon)")+"' returns '"+k(l)+"' but declared '"+k(s)+"'",t.loc,"Fix return type or update the annotation"))}else this._checkStmts(t.body,n)}else if(t.type=="ClassDecl"){e.set(t.name,m(t.name));let s=e.child(),i=new Map;for(let n of t.fields){let h=n.typeAnn?E(n.typeAnn):f;s.set(n.name,h),i.set(n.name,h)}s.set("self",st(i));for(let n of t.methods)this._checkStmt(n,s)}else if(t.type=="DeclareDecl"){let s=t.decl;if(s.type=="FnDecl"){let i=s.retType?E(s.retType):null,n=s.params.map(h=>h.typeAnn?E(h.typeAnn):f);s.name&&e.set(s.name,N(n,i??f))}else if(s.type=="VarDecl"){let i=s.typeAnn?E(s.typeAnn):f;e.set(s.name,i)}else s.type=="ClassDecl"&&e.set(s.name,m(s.name))}else if(t.type=="TypeDecl")for(let s of t.variants)s.fields.length==0?e.set(s.name,m(t.name)):e.set(s.name,N(s.fields.map(i=>w),m(t.name)));else if(t.type=="InterfaceDecl")e.set(t.name,m(t.name));else if(t.type=="EnumDecl")e.set(t.name,m(t.name));else if(t.type=="IfStmt"){this._inferType(t.cond,e);let s=this._analyzeNarrowingCondition(t.cond,e),i=s?e.narrow(s.varName,s.trueType):e.child(),n=s?e.narrow(s.varName,s.falseType):e.child();this._checkStmts(t.then,i);for(let h of t.elseifs)this._inferType(h.cond,e),this._checkStmts(h.body,e.child());t.else_&&this._checkStmts(t.else_,n)}else if(t.type=="ForInStmt"){let s=this._inferType(t.iter,e),i=e.child();s.kind=="generic"&&s.name=="Array"?i.set(t.var,s.args[0]??f):s.kind=="tuple"?i.set(t.var,s.types[0]??f):i.set(t.var,f),this._checkStmts(t.body,i)}else if(t.type=="WhileStmt"||t.type=="DoWhileStmt")this._inferType(t.cond,e),this._checkStmts(t.body??[],e.child());else if(t.type=="MatchStmt"){this._inferType(t.subject,e);for(let s of t.arms){let i=e.child();if(s.pattern.type=="VariantPat")for(let n of s.pattern.bindings)i.set(n,f);this._checkStmts(s.body,i)}}else if(t.type=="ReturnStmt"){if(t.value){let s=e.retType,i=this._inferType(t.value,e);s&&i&&i.kind!="unknown"&&(this._isAssignable(i,s)||this._err("Return type '"+k(i)+"' is not assignable to declared '"+k(s)+"'",t.loc,"Fix the return value or update the return type annotation"))}}else if(t.type=="TryCatchStmt"){if(this._checkStmts(t.tryBody,e.child()),t.catchBody){let s=e.child();t.catchParam&&s.set(t.catchParam,w),this._checkStmts(t.catchBody,s)}t.finallyBody&&this._checkStmts(t.finallyBody,e.child())}else if(t.type=="ThrowStmt")t.value&&this._inferType(t.value,e);else if(t.type=="ImportDecl"){t.defaultName&&e.set(t.defaultName,w),t.namespaceName&&e.set(t.namespaceName,w);for(let s of t.names){let i=typeof s=="string"?s:s.alias;e.set(i,w)}}else t.type=="ExportDecl"?t.isDefault?this._inferType(t.decl,e):this._checkStmt(t.decl,e):t.type=="ExprStmt"&&this._inferType(t.expr,e)}};d.exports.FluxTypeChecker=gt});var zt=S((ks,q)=>{"use strict";var{Lexer:cs,lexerize:fe,T:os}=B(),{Parser:ps,makeParser:me}=Q(),{CodeGenerator:us,makeCodeGen:ye}=mt(),{transformCss:Ee}=Ot(),{transformJsx:ke,FLUX_H_BROWSER:fs,FLUX_H_SERVER:ms,FLUX_CSS_BROWSER:ys,FLUX_CSS_SERVER:Es}=Mt(),{Checker:de}=Pt(),{FluxTypeChecker:ge}=Wt(),Te=require("fs"),xe=require("path");function Ne(){try{let a=xe.resolve(__dirname,"../../package.json");return JSON.parse(Te.readFileSync(a,"utf8")).version}catch{return"4.0.1"}}var Vt=Ne();q.exports.FLUX_VERSION=Vt;var Se="self-hosted";q.exports.FLUX_STAGE=Se;function Qt(a,t){let e=t??{},s={success:!1,output:"",ast:null,tokens:null,errors:[],typeErrors:[],typeWarnings:[],stage:""};try{let i=a;if(s.stage="css",e.css!=!1&&(i=Ee(i)),s.stage="jsx",e.jsx){let g=e.jsxTarget??"browser",T=ke(i,{target:g});i=T.source,T.hasJsx&&(e._jsxHelpers=T.runtimeHelpers)}s.stage="lexer";let h=fe(i).tokenize();s.tokens=h,s.stage="parser";let l=me(h).parse();if(s.ast=l,e.check!=!1){s.stage="checker";let T=new de([],[]).check(l);if(T.errors.length>0)return s.errors=T.errors,s.stage=null,s}if(e.typecheck){s.stage="type-checker";let T=new ge([],[],new Map,new Map,new Map,new Map).check(l);if(s.typeErrors=T.errors,s.typeWarnings=T.warnings,e.strict&&T.errors.length>0)return s.errors=T.errors,s.stage=null,s}s.stage="codegen";let c=e.mangle?"":" ",y=ye({indent:c,version:Vt}).generate(l).code;e._jsxHelpers&&(y=e._jsxHelpers+`
59
+ `+y),s.output=y,s.success=!0,s.stage=null}catch(i){s.errors.push({message:i.message,name:i.name,stage:s.stage})}return s}q.exports.transpile=Qt;function we(a,t){return Qt(a,{check:!0,typecheck:(t==null?void 0:t.typecheck)??!1,jsx:(t==null?void 0:t.jsx)??!1,jsxTarget:(t==null?void 0:t.jsxTarget)??"browser",mangle:(t==null?void 0:t.mangle)??!1,strict:(t==null?void 0:t.strict)??!1,...t??{}})}q.exports.transpileFile=we});var Ht=S((ds,Tt)=>{"use strict";function be(a){if((a.match(/:/g)??[]).length>2)return a;let t=a;return t=t.replace(/([^=!<>+\-*\/%])=(?!=|>)/g,"$1 = "),t=t.replace(/\s{2,}=/g," ="),t=t.replace(/([^\s]) +/g,"$1 "),t=t.replace(/,(?!\s)/g,", "),t=t.replace(/\s*->\s*/g," -> "),t=t.replace(/\s*=>\s*/g," => "),t=t.trimEnd(),t}function Ae(a){let t=a.replace(/\r\n/g,`
60
+ `).replace(/\r/g,`
61
+ `).split(`
62
+ `),e=4;for(let u of t){let y=u.match(/^( +)\S/);if(y){let g=y[1].length;g>0&&g<e&&(e=g);break}}e<1&&(e=4);function s(u){let y=u.trimEnd();if(!y)return"";let g=y.match(/^( *)/),T=g?g[1].length:0,ot=Math.round(T/e),F=y.trimStart(),W=be(F);return(F.startsWith("//")||F.startsWith("*"))&&(W=F)," ".repeat(ot)+W}let i=t.map(u=>s(u)),n=[],h=0;for(let u of i)u==""?(h=h+1,h<=1&&n.push("")):(h=0,n.push(u));let l=[],c=0;for(;c<n.length;){l.push(n[c]);let u=(n[c].match(/^( *)/)??["",""])[1].length;if(c>0){let y=(n[c-1].match(/^( *)/)??["",""])[1].length,g=n[c].trimStart();y>=4&&u==0&&g!=""&&l[l.length-2]!=""&&l.splice(l.length-1,0,"")}c=c+1}let o=l;for(;o.length>0&&o[0]=="";)o.shift();for(;o.length>0&&o[o.length-1]=="";)o.pop();return o.push(""),o.join(`
63
+ `)}Tt.exports.format=Ae;function Oe(a,t){let e=a.split(`
64
+ `),s=t.split(`
65
+ `),i=[],n=Math.max(e.length,s.length),h=0;for(;h<n;){let l=e[h],c=s[h];l!=c&&i.push({line:h+1,original:l,formatted:c}),h=h+1}return i}Tt.exports.diff=Oe});var Gt=S((gs,at)=>{"use strict";var nt=["range","zip","enumerate","clamp","sum","product","flatten","chunk","unique","groupBy","sortBy","pick","omit","deepEqual","deepClone","sleep","retry","memoize","pipe","compose","partial","curry","capitalize","camelCase","snakeCase","kebabCase","truncate","pad","randInt","sample","shuffle","mapValues","filterValues","fromEntries","map","filter","reduce","forEach","find","findIndex","some","every","join","sort","flat","flatMap","includes"];at.exports.STDLIB_SYMBOLS=nt;function Re(a){return new RegExp("\\b"+a+"\\s*\\(","g")}function De(a){return nt.filter(t=>Re(t).test(a))}at.exports.detectUsedSymbols=De;function ve(a){let t=new Set(nt);if(a&&(t=new Set(a.filter(s=>nt.includes(s)))),t.size==0)return"";let e=["// \u2500\u2500 Flux stdlib \u2500\u2500"];return t.has("map")&&e.push("function map(arr, fn) { return arr.map(fn); }"),t.has("filter")&&e.push("function filter(arr, fn) { return arr.filter(fn); }"),t.has("reduce")&&e.push("function reduce(arr, fn, init) { return arguments.length >= 3 ? arr.reduce(fn, init) : arr.reduce(fn); }"),t.has("forEach")&&e.push("function forEach(arr, fn) { arr.forEach(fn); return arr; }"),t.has("find")&&e.push("function find(arr, fn) { return arr.find(fn); }"),t.has("findIndex")&&e.push("function findIndex(arr, fn) { return arr.findIndex(fn); }"),t.has("some")&&e.push("function some(arr, fn) { return arr.some(fn); }"),t.has("every")&&e.push("function every(arr, fn) { return arr.every(fn); }"),t.has("join")&&e.push("function join(arr, sep) { return arr.join(sep != null ? sep : ','); }"),t.has("sort")&&e.push("function sort(arr, fn) { return arr.slice().sort(fn); }"),t.has("flat")&&e.push("function flat(arr, depth) { return arr.flat(depth != null ? depth : 1); }"),t.has("flatMap")&&e.push("function flatMap(arr, fn) { return arr.flatMap(fn); }"),t.has("includes")&&e.push("function includes(arr, val) { return arr.includes(val); }"),t.has("range")&&e.push(`function range(start, end, step) {
79
66
  if (arguments.length === 1) { end = start; start = 0; }
80
67
  step = step || (end >= start ? 1 : -1);
81
68
  const out = [];
82
69
  if (step > 0) { for (let i = start; i < end; i += step) out.push(i); }
83
70
  else { for (let i = start; i > end; i += step) out.push(i); }
84
71
  return out;
85
- }`),t.has("zip")&&e.push(`
86
- function zip() {
72
+ }`),t.has("zip")&&e.push(`function zip() {
87
73
  const arrays = Array.from(arguments);
88
74
  const len = Math.min.apply(null, arrays.map(function(a) { return a.length; }));
89
75
  const out = [];
90
76
  for (let i = 0; i < len; i++) out.push(arrays.map(function(a) { return a[i]; }));
91
77
  return out;
92
- }`),t.has("enumerate")&&e.push(`
93
- function enumerate(arr, start) {
78
+ }`),t.has("enumerate")&&e.push(`function enumerate(arr, start) {
94
79
  start = start || 0;
95
80
  return arr.map(function(v, i) { return [i + start, v]; });
96
- }`),t.has("flatten")&&e.push(`
97
- function flatten(arr, depth) {
81
+ }`),t.has("flatten")&&e.push(`function flatten(arr, depth) {
98
82
  return depth == null ? arr.flat(Infinity) : arr.flat(depth);
99
- }`),t.has("chunk")&&e.push(`
100
- function chunk(arr, size) {
83
+ }`),t.has("chunk")&&e.push(`function chunk(arr, size) {
101
84
  const out = [];
102
85
  for (let i = 0; i < arr.length; i += size) out.push(arr.slice(i, i + size));
103
86
  return out;
104
- }`),t.has("unique")&&e.push(`
105
- function unique(arr) {
87
+ }`),t.has("unique")&&e.push(`function unique(arr) {
106
88
  return Array.from(new Set(arr));
107
- }`),t.has("groupBy")&&e.push(`
108
- function groupBy(arr, fn) {
89
+ }`),t.has("groupBy")&&e.push(`function groupBy(arr, fn) {
109
90
  return arr.reduce(function(acc, v) {
110
91
  var k = typeof fn === 'function' ? fn(v) : v[fn];
111
92
  (acc[k] = acc[k] || []).push(v);
112
93
  return acc;
113
94
  }, {});
114
- }`),t.has("sortBy")&&e.push(`
115
- function sortBy(arr, fn) {
95
+ }`),t.has("sortBy")&&e.push(`function sortBy(arr, fn) {
116
96
  return arr.slice().sort(function(a, b) {
117
97
  var ka = typeof fn === 'function' ? fn(a) : a[fn];
118
98
  var kb = typeof fn === 'function' ? fn(b) : b[fn];
119
99
  return ka < kb ? -1 : ka > kb ? 1 : 0;
120
100
  });
121
- }`),(t.has("first")||t.has("head"))&&e.push(`
122
- function first(arr) { return arr[0]; }
123
- function head(arr) { return arr[0]; }`),t.has("last")&&e.push(`
124
- function last(arr) { return arr[arr.length - 1]; }`),t.has("tail")&&e.push(`
125
- function tail(arr) { return arr.slice(1); }`),t.has("nth")&&e.push(`
126
- function nth(arr, n) { return n < 0 ? arr[arr.length + n] : arr[n]; }`),t.has("take")&&e.push(`
127
- function take(arr, n) { return arr.slice(0, n); }`),t.has("drop")&&e.push(`
128
- function drop(arr, n) { return arr.slice(n); }`),t.has("takeWhile")&&e.push(`
129
- function takeWhile(arr, fn) {
130
- var i = 0;
131
- while (i < arr.length && fn(arr[i])) i++;
132
- return arr.slice(0, i);
133
- }`),t.has("dropWhile")&&e.push(`
134
- function dropWhile(arr, fn) {
135
- var i = 0;
136
- while (i < arr.length && fn(arr[i])) i++;
137
- return arr.slice(i);
138
- }`),t.has("compact")&&e.push(`
139
- function compact(arr) {
140
- return arr.filter(function(v) { return v != null && v !== false && v !== 0 && v !== ''; });
141
- }`),t.has("intersection")&&e.push(`
142
- function intersection(a, b) {
143
- var s = new Set(b);
144
- return a.filter(function(v) { return s.has(v); });
145
- }`),t.has("difference")&&e.push(`
146
- function difference(a, b) {
147
- var s = new Set(b);
148
- return a.filter(function(v) { return !s.has(v); });
149
- }`),t.has("arrayUnion")&&e.push(`
150
- function arrayUnion(a, b) {
151
- return Array.from(new Set(a.concat(b)));
152
- }`),t.has("unzip")&&e.push(`
153
- function unzip(pairs) {
154
- var a = [], b = [];
155
- for (var i = 0; i < pairs.length; i++) { a.push(pairs[i][0]); b.push(pairs[i][1]); }
156
- return [a, b];
157
- }`),t.has("countBy")&&e.push(`
158
- function countBy(arr, fn) {
159
- return arr.reduce(function(acc, v) {
160
- var k = typeof fn === 'function' ? fn(v) : v[fn];
161
- acc[k] = (acc[k] || 0) + 1;
162
- return acc;
163
- }, {});
164
- }`),t.has("minBy")&&e.push(`
165
- function minBy(arr, fn) {
166
- if (!arr.length) return undefined;
167
- return arr.reduce(function(best, v) {
168
- return (typeof fn === 'function' ? fn(v) : v[fn]) < (typeof fn === 'function' ? fn(best) : best[fn]) ? v : best;
169
- });
170
- }`),t.has("maxBy")&&e.push(`
171
- function maxBy(arr, fn) {
172
- if (!arr.length) return undefined;
173
- return arr.reduce(function(best, v) {
174
- return (typeof fn === 'function' ? fn(v) : v[fn]) > (typeof fn === 'function' ? fn(best) : best[fn]) ? v : best;
175
- });
176
- }`),t.has("toPairs")&&e.push(`
177
- function toPairs(obj) {
178
- return Object.keys(obj).map(function(k) { return [k, obj[k]]; });
179
- }`),t.has("partition")&&e.push(`
180
- function partition(arr, fn) {
181
- var yes = [], no = [];
182
- arr.forEach(function(v) { (fn(v) ? yes : no).push(v); });
183
- return [yes, no];
184
- }`),t.has("count")&&e.push(`
185
- function count(arr, fn) {
186
- if (typeof fn !== 'function') return arr.length;
187
- return arr.reduce(function(n, v) { return fn(v) ? n + 1 : n; }, 0);
188
- }`),t.has("rotate")&&e.push(`
189
- function rotate(arr, n) {
190
- var len = arr.length;
191
- if (!len) return [];
192
- var k = ((n % len) + len) % len;
193
- return arr.slice(k).concat(arr.slice(0, k));
194
- }`),t.has("sliding")&&e.push(`
195
- function sliding(arr, size, step) {
196
- step = step || 1;
197
- var out = [];
198
- for (var i = 0; i + size <= arr.length; i += step) out.push(arr.slice(i, i + size));
199
- return out;
200
- }`),t.has("clamp")&&e.push(`
201
- function clamp(val, min, max) {
101
+ }`),t.has("clamp")&&e.push(`function clamp(val, min, max) {
202
102
  return Math.min(Math.max(val, min), max);
203
- }`),t.has("sum")&&e.push(`
204
- function sum(arr) {
103
+ }`),t.has("sum")&&e.push(`function sum(arr) {
205
104
  return arr.reduce(function(a, b) { return a + b; }, 0);
206
- }`),t.has("product")&&e.push(`
207
- function product(arr) {
105
+ }`),t.has("product")&&e.push(`function product(arr) {
208
106
  return arr.reduce(function(a, b) { return a * b; }, 1);
209
- }`),t.has("min")&&e.push(`
210
- function min(arr) {
211
- if (arguments.length > 1) return Math.min.apply(null, arguments);
212
- return Math.min.apply(null, arr);
213
- }`),t.has("max")&&e.push(`
214
- function max(arr) {
215
- if (arguments.length > 1) return Math.max.apply(null, arguments);
216
- return Math.max.apply(null, arr);
217
- }`),t.has("abs")&&e.push(`
218
- function abs(n) { return Math.abs(n); }`),t.has("floor")&&e.push(`
219
- function floor(n) { return Math.floor(n); }`),t.has("ceil")&&e.push(`
220
- function ceil(n) { return Math.ceil(n); }`),t.has("round")&&e.push(`
221
- function round(n, decimals) {
222
- if (decimals == null) return Math.round(n);
223
- var f = Math.pow(10, decimals);
224
- return Math.round(n * f) / f;
225
- }`),t.has("mean")&&e.push(`
226
- function mean(arr) {
227
- if (!arr.length) return 0;
228
- return arr.reduce(function(a, b) { return a + b; }, 0) / arr.length;
229
- }`),t.has("median")&&e.push(`
230
- function median(arr) {
231
- if (!arr.length) return 0;
232
- var s = arr.slice().sort(function(a, b) { return a - b; });
233
- var m = Math.floor(s.length / 2);
234
- return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
235
- }`),t.has("stdDev")&&e.push(`
236
- function stdDev(arr) {
237
- if (!arr.length) return 0;
238
- var m = arr.reduce(function(a, b) { return a + b; }, 0) / arr.length;
239
- var variance = arr.reduce(function(acc, v) { return acc + (v - m) * (v - m); }, 0) / arr.length;
240
- return Math.sqrt(variance);
241
- }`),t.has("lerp")&&e.push(`
242
- function lerp(a, b, t) { return a + (b - a) * t; }`),t.has("randInt")&&e.push(`
243
- function randInt(min, max) {
107
+ }`),t.has("randInt")&&e.push(`function randInt(min, max) {
244
108
  return Math.floor(Math.random() * (max - min + 1)) + min;
245
- }`),t.has("sample")&&e.push(`
246
- function sample(arr) {
109
+ }`),t.has("sample")&&e.push(`function sample(arr) {
247
110
  return arr[Math.floor(Math.random() * arr.length)];
248
- }`),t.has("shuffle")&&e.push(`
249
- function shuffle(arr) {
111
+ }`),t.has("shuffle")&&e.push(`function shuffle(arr) {
250
112
  var a = arr.slice();
251
113
  for (var i = a.length - 1; i > 0; i--) {
252
114
  var j = Math.floor(Math.random() * (i + 1));
253
115
  var tmp = a[i]; a[i] = a[j]; a[j] = tmp;
254
116
  }
255
117
  return a;
256
- }`),t.has("pick")&&e.push(`
257
- function pick(obj, keys) {
118
+ }`),t.has("pick")&&e.push(`function pick(obj, keys) {
258
119
  var out = {};
259
120
  keys.forEach(function(k) { if (Object.prototype.hasOwnProperty.call(obj, k)) out[k] = obj[k]; });
260
121
  return out;
261
- }`),t.has("omit")&&e.push(`
262
- function omit(obj, keys) {
122
+ }`),t.has("omit")&&e.push(`function omit(obj, keys) {
263
123
  var ks = new Set(keys);
264
124
  var out = {};
265
125
  Object.keys(obj).forEach(function(k) { if (!ks.has(k)) out[k] = obj[k]; });
266
126
  return out;
267
- }`),t.has("mapValues")&&e.push(`
268
- function mapValues(obj, fn) {
127
+ }`),t.has("mapValues")&&e.push(`function mapValues(obj, fn) {
269
128
  var out = {};
270
129
  Object.keys(obj).forEach(function(k) { out[k] = fn(obj[k], k); });
271
130
  return out;
272
- }`),t.has("filterValues")&&e.push(`
273
- function filterValues(obj, fn) {
131
+ }`),t.has("filterValues")&&e.push(`function filterValues(obj, fn) {
274
132
  var out = {};
275
133
  Object.keys(obj).forEach(function(k) { if (fn(obj[k], k)) out[k] = obj[k]; });
276
134
  return out;
277
- }`),t.has("fromEntries")&&e.push(`
278
- function fromEntries(entries) {
135
+ }`),t.has("fromEntries")&&e.push(`function fromEntries(entries) {
279
136
  return Object.fromEntries(entries);
280
- }`),t.has("keys")&&e.push(`
281
- function keys(obj) { return Object.keys(obj); }`),t.has("values")&&e.push(`
282
- function values(obj) { return Object.values(obj); }`),t.has("entries")&&e.push(`
283
- function entries(obj) { return Object.entries(obj); }`),t.has("merge")&&e.push(`
284
- function merge() {
285
- return Object.assign.apply(Object, [{}].concat(Array.from(arguments)));
286
- }`),t.has("invert")&&e.push(`
287
- function invert(obj) {
288
- var out = {};
289
- Object.keys(obj).forEach(function(k) { out[obj[k]] = k; });
290
- return out;
291
- }`),t.has("defaults")&&e.push(`
292
- function defaults(obj) {
293
- var sources = Array.from(arguments).slice(1);
294
- var out = Object.assign({}, obj);
295
- sources.forEach(function(s) {
296
- Object.keys(s).forEach(function(k) { if (out[k] == null) out[k] = s[k]; });
297
- });
298
- return out;
299
- }`),t.has("deepEqual")&&e.push(`
300
- function deepEqual(a, b) {
137
+ }`),t.has("deepEqual")&&e.push(`function deepEqual(a, b) {
301
138
  return JSON.stringify(a) === JSON.stringify(b);
302
- }`),t.has("deepClone")&&e.push(`
303
- function deepClone(v) {
139
+ }`),t.has("deepClone")&&e.push(`function deepClone(v) {
304
140
  return JSON.parse(JSON.stringify(v));
305
- }`),t.has("capitalize")&&e.push(`
306
- function capitalize(s) {
307
- return s ? s[0].toUpperCase() + s.slice(1) : s;
308
- }`),t.has("camelCase")&&e.push(`
309
- function camelCase(s) {
310
- return s.replace(/[-_\\s]+(.)/g, function(_, c) { return c.toUpperCase(); }).replace(/^./, function(c) { return c.toLowerCase(); });
311
- }`),t.has("snakeCase")&&e.push(`
312
- function snakeCase(s) {
313
- return s.replace(/([A-Z])/g, function(c) { return '_' + c.toLowerCase(); }).replace(/[-\\s]+/g, '_').replace(/^_/, '');
314
- }`),t.has("kebabCase")&&e.push(`
315
- function kebabCase(s) {
316
- return s.replace(/([A-Z])/g, function(c) { return '-' + c.toLowerCase(); }).replace(/[_\\s]+/g, '-').replace(/^-/, '');
317
- }`),t.has("truncate")&&e.push(`
318
- function truncate(s, len, suffix) {
319
- suffix = suffix != null ? suffix : '...';
320
- if (s.length <= len) return s;
321
- var cut = len - suffix.length;
322
- if (cut <= 0) return suffix.slice(0, len);
323
- return s.slice(0, cut) + suffix;
324
- }`),t.has("pad")&&e.push(`
325
- function pad(s, len, char) {
326
- char = char || ' ';
327
- s = String(s);
328
- var total = len - s.length;
329
- if (total <= 0) return s;
330
- var half = Math.floor(total / 2);
331
- return char.repeat(half) + s + char.repeat(total - half);
332
- }`),t.has("padStart")&&e.push(`
333
- function padStart(s, len, char) {
334
- return String(s).padStart(len, char || ' ');
335
- }`),t.has("padEnd")&&e.push(`
336
- function padEnd(s, len, char) {
337
- return String(s).padEnd(len, char || ' ');
338
- }`),t.has("trim")&&e.push(`
339
- function trim(s) { return String(s).trim(); }`),t.has("trimStart")&&e.push(`
340
- function trimStart(s) { return String(s).trimStart(); }`),t.has("trimEnd")&&e.push(`
341
- function trimEnd(s) { return String(s).trimEnd(); }`),t.has("words")&&e.push(`
342
- function words(s) { return String(s).trim().split(/\\s+/); }`),t.has("lines")&&e.push(`
343
- function lines(s) { return String(s).split(/\\r?\\n/); }`),t.has("startsWith")&&e.push(`
344
- function startsWith(s, prefix) { return String(s).startsWith(prefix); }`),t.has("endsWith")&&e.push(`
345
- function endsWith(s, suffix) { return String(s).endsWith(suffix); }`),t.has("repeat")&&e.push(`
346
- function repeat(s, n) { return String(s).repeat(n); }`),t.has("replaceAll")&&e.push(`
347
- function replaceAll(s, search, replacement) {
348
- return String(s).split(search).join(replacement);
349
- }`),t.has("reverseStr")&&e.push(`
350
- function reverseStr(s) { return String(s).split('').reverse().join(''); }`),t.has("isNil")&&e.push(`
351
- function isNil(v) { return v == null; }`),t.has("isString")&&e.push(`
352
- function isString(v) { return typeof v === 'string'; }`),t.has("isNumber")&&e.push(`
353
- function isNumber(v) { return typeof v === 'number' && !isNaN(v); }`),t.has("isArray")&&e.push(`
354
- function isArray(v) { return Array.isArray(v); }`),t.has("isObject")&&e.push(`
355
- function isObject(v) { return v !== null && typeof v === 'object' && !Array.isArray(v); }`),t.has("isFunction")&&e.push(`
356
- function isFunction(v) { return typeof v === 'function'; }`),t.has("isBool")&&e.push(`
357
- function isBool(v) { return typeof v === 'boolean'; }`),t.has("sleep")&&e.push(`
358
- function sleep(ms) {
141
+ }`),t.has("sleep")&&e.push(`function sleep(ms) {
359
142
  return new Promise(function(resolve) { setTimeout(resolve, ms); });
360
- }`),t.has("retry")&&e.push(`
361
- async function retry(fn, attempts, delay) {
143
+ }`),t.has("retry")&&e.push(`async function retry(fn, attempts, delay) {
362
144
  attempts = attempts || 3;
363
145
  delay = delay || 300;
364
146
  for (var i = 0; i < attempts; i++) {
365
147
  try { return await fn(); } catch(e) {
366
148
  if (i === attempts - 1) throw e;
367
- await new Promise(function(r) { setTimeout(r, delay * Math.pow(2, i)); });
149
+ await sleep(delay * Math.pow(2, i));
368
150
  }
369
151
  }
370
- }`),t.has("timeout")&&e.push(`
371
- function timeout(fn, ms) {
372
- return Promise.race([
373
- typeof fn === 'function' ? fn() : fn,
374
- new Promise(function(_, reject) {
375
- setTimeout(function() { reject(new Error('Timeout after ' + ms + 'ms')); }, ms);
376
- })
377
- ]);
378
- }`),t.has("allSettled")&&e.push(`
379
- function allSettled(promises) {
380
- return Promise.allSettled(promises);
381
- }`),t.has("debounce")&&e.push(`
382
- function debounce(fn, ms) {
383
- var timer;
384
- return function() {
385
- clearTimeout(timer);
386
- var args = arguments;
387
- var ctx = this;
388
- timer = setTimeout(function() { fn.apply(ctx, args); }, ms);
389
- };
390
- }`),t.has("throttle")&&e.push(`
391
- function throttle(fn, ms) {
392
- var last = 0;
393
- return function() {
394
- var now = Date.now();
395
- if (now - last >= ms) { last = now; return fn.apply(this, arguments); }
396
- };
397
- }`),t.has("memoize")&&e.push(`
398
- function memoize(fn) {
152
+ }`),t.has("memoize")&&e.push(`function memoize(fn) {
399
153
  var cache = new Map();
400
154
  return function() {
401
155
  var key = JSON.stringify(arguments);
@@ -404,61 +158,46 @@ function memoize(fn) {
404
158
  cache.set(key, result);
405
159
  return result;
406
160
  };
407
- }`),t.has("pipe")&&e.push(`
408
- function pipe() {
161
+ }`),t.has("pipe")&&e.push(`function pipe() {
409
162
  var fns = Array.from(arguments);
410
163
  return function(x) { return fns.reduce(function(v, f) { return f(v); }, x); };
411
- }`),t.has("compose")&&e.push(`
412
- function compose() {
164
+ }`),t.has("compose")&&e.push(`function compose() {
413
165
  var fns = Array.from(arguments);
414
166
  return function(x) { return fns.reduceRight(function(v, f) { return f(v); }, x); };
415
- }`),t.has("partial")&&e.push(`
416
- function partial(fn) {
167
+ }`),t.has("partial")&&e.push(`function partial(fn) {
417
168
  var args = Array.from(arguments).slice(1);
418
169
  return function() { return fn.apply(this, args.concat(Array.from(arguments))); };
419
- }`),t.has("curry")&&e.push(`
420
- function curry(fn) {
170
+ }`),t.has("curry")&&e.push(`function curry(fn) {
421
171
  return function curried() {
422
172
  var args = Array.from(arguments);
423
173
  if (args.length >= fn.length) return fn.apply(this, args);
424
174
  return function() { return curried.apply(this, args.concat(Array.from(arguments))); };
425
175
  };
426
- }`),t.has("identity")&&e.push(`
427
- function identity(v) { return v; }`),t.has("noop")&&e.push(`
428
- function noop() {}`),t.has("once")&&e.push(`
429
- function once(fn) {
430
- var called = false, result;
431
- return function() {
432
- if (!called) { called = true; result = fn.apply(this, arguments); }
433
- return result;
434
- };
435
- }`),t.has("flip")&&e.push(`
436
- function flip(fn) {
437
- return function() {
438
- var args = Array.from(arguments);
439
- return fn.apply(this, [args[1], args[0]].concat(args.slice(2)));
440
- };
441
- }`),t.has("complement")&&e.push(`
442
- function complement(fn) {
443
- return function() { return !fn.apply(this, arguments); };
176
+ }`),t.has("capitalize")&&e.push(`function capitalize(s) {
177
+ return s ? s[0].toUpperCase() + s.slice(1) : s;
178
+ }`),t.has("camelCase")&&e.push(`function camelCase(s) {
179
+ return s.replace(/[-_\\s]+(.)/g, function(_, c) { return c.toUpperCase(); }).replace(/^./, function(c) { return c.toLowerCase(); });
180
+ }`),t.has("snakeCase")&&e.push(`function snakeCase(s) {
181
+ return s.replace(/([A-Z])/g, function(c) { return '_' + c.toLowerCase(); }).replace(/[-\\s]+/g, '_').replace(/^_/, '');
182
+ }`),t.has("kebabCase")&&e.push(`function kebabCase(s) {
183
+ return s.replace(/([A-Z])/g, function(c) { return '-' + c.toLowerCase(); }).replace(/[_\\s]+/g, '-').replace(/^-/, '');
184
+ }`),t.has("truncate")&&e.push(`function truncate(s, len, suffix) {
185
+ suffix = suffix != null ? suffix : '...';
186
+ if (s.length <= len) return s;
187
+ var cut = len - suffix.length;
188
+ if (cut <= 0) return suffix.slice(0, len);
189
+ return s.slice(0, cut) + suffix;
190
+ }`),t.has("pad")&&e.push(`function pad(s, len, char) {
191
+ char = char || ' ';
192
+ s = String(s);
193
+ var total = len - s.length;
194
+ if (total <= 0) return s;
195
+ var half = Math.floor(total / 2);
196
+ return char.repeat(half) + s + char.repeat(total - half);
444
197
  }`),e.push(`// \u2500\u2500 end stdlib \u2500\u2500
445
198
  `),e.join(`
446
- `)}function Ce(n){return mt.filter(t=>new RegExp(`\\b${t}\\s*\\(`,"g").test(n))}pe.exports={buildStdlib:Le,detectUsedSymbols:Ce,STDLIB_SYMBOLS:mt}});var me=_(($s,fe)=>{"use strict";var{Lexer:Fe}=J(),{Parser:Be}=et(),{CodeGenerator:Pe}=xt(),{SourceMapBuilder:ue}=Qt(),{transformJsx:Me}=Yt(),{Mangler:je}=Jt(),{transformCss:We}=se(),{Checker:Ue}=re(),{FluxTypeChecker:Qe}=oe(),{buildStdlib:Ve,detectUsedSymbols:He}=_t();function ze(n,t={}){let e={success:!1,output:"",sourceMap:null,ast:null,tokens:null,errors:[],typeErrors:[],typeWarnings:[],stage:null,nameMap:null};try{e.stage="css";let s=We(n);e.stage="jsx";let r=t.jsxTarget||"browser",a=t.jsx!==!1,c=s,h="";if(a){let A=Me(s,{target:r});c=A.source,h=A.hasJsx?A.runtimeHelpers:""}e.stage="lexer";let l=new Fe(c).tokenize();e.tokens=l,e.stage="parser";let p=new Be(l).parse();if(e.ast=p,t.check){e.stage="checker";let v=new Ue().check(p);if(v.errors.length>0)return e.errors=v.errors,e.stage=null,e;e.typeWarnings=[...e.typeWarnings||[],...v.warnings]}if(t.typecheck!==!1){e.stage="typecheck";let v=new Qe().check(p);e.typeErrors=v.errors,e.typeWarnings=[...e.typeWarnings||[],...v.warnings]}let m=p;if(t.mangle){e.stage="mangler";let A=new je;m=A.mangle(p),e.nameMap=A.getMap()}e.stage="codegen";let y={indent:t.mangle?"":" "};t.sourcemap&&(y.smBuilder=new ue(t.sourceFile||"source.flux",n));let{code:u,smBuilder:d}=new Pe(y).generate(m),g=t.stdlib!==!1,f="";if(g){let A=He(u);A.length>0&&(f=Ve(A)+`
447
- `)}let T=h?`// Flux JSX Runtime
448
- "use strict";
449
- ${h}
450
- `:"",b=h?u.replace(/^\/\/ Generated.*\n"use strict";\n/,""):u,w=T+f+b,S=d||null;if(t.mangle){let A=(T+f).split(`
451
- `).length-1,v=w.split(`
452
- `),B=[];for(let $=0;$<v.length;$++){let P=v[$].trim();if(!P||P.startsWith("//"))continue;let U=null,tt=!1,q=P;for(let Q=0;Q<P.length-1;Q++){let H=P[Q];if(tt){tt=!1;continue}if(H==="\\"){tt=!0;continue}if(!U&&(H==='"'||H==="'"||H==="`")){U=H;continue}if(U&&H===U){U=null;continue}if(!U&&H==="/"&&P[Q+1]==="/"){q=P.slice(0,Q).trimEnd();break}}q&&B.push({origIdx:$,content:q})}if(w=B.map($=>$.content).join(" "),S){let $=new ue(t.sourceFile||"source.flux",n),P=0;for(let{origIdx:U,content:tt}of B){let q=U-A;if(q>=0)for(let Q of S.mappings[q]||[])$.addMapping(0,P+Q.genCol,Q.srcLine,Q.srcCol);P+=tt.length+1}S=$}}if(S){let A=t.outputFile||"output.js",v=A+".map";e.sourceMap=S.toString(A),w=w+`
453
- //# sourceMappingURL=${v}`}e.output=w,e.success=!0,e.stage=null}catch(s){e.errors.push({message:s.message,name:s.name,stage:e.stage,line:s.tok?s.tok.line:s.line||null,col:s.tok?s.tok.col:s.col||null,len:s.tok&&s.tok.value?String(s.tok.value).length:1,hint:s.hint||null})}return e}fe.exports={transpile:ze}});var ke=_((_s,ye)=>{"use strict";function Ke(n){let t=n.replace(/\r\n/g,`
454
- `).replace(/\r/g,`
455
- `).split(`
456
- `),e=4;for(let l of t){let p=l.match(/^( +)\S/);if(p){let m=p[1].length;m>0&&m<e&&(e=m);break}}e<1&&(e=4);let s=t.map(l=>{let p=l.trimEnd();if(!p)return"";let m=p.match(/^( *)/),y=m?m[1].length:0,u=Math.round(y/e),d=p.trimStart(),g=d.startsWith("//")||d.startsWith("*")?d:Ge(d);return" ".repeat(u)+g}),r=[],a=0;for(let l of s)l===""?(a++,a<=1&&r.push("")):(a=0,r.push(l));let c=[];for(let l=0;l<r.length;l++){c.push(r[l]);let p=r[l].trimStart(),m=(r[l+1]||"").trimStart(),y=r[l].match(/^( *)/)[1].length;y<=4&&/^(fn |async fn |class |type )/.test(p)&&m!==""&&/^(fn |async fn |class |type )/.test(m),l>0&&r[l-1].match(/^( *)/)[1].length>=4&&y===0&&p!==""&&c[c.length-2]!==""&&c.splice(c.length-1,0,"")}let h=c;for(;h.length>0&&h[0]==="";)h.shift();for(;h.length>0&&h[h.length-1]==="";)h.pop();return h.push(""),h.join(`
457
- `)}function Ge(n){if((n.match(/:/g)||[]).length>2)return n;let t=n;return t=t.replace(/([^=!<>+\-*/%])=(?!=|>)/g,"$1 = "),t=t.replace(/\s{2,}=/g," ="),t=t.replace(/([^\s]) +/g,"$1 "),t=t.replace(/,(?!\s)/g,", "),t=t.replace(/\s*->\s*/g," -> "),t=t.replace(/\s*=>\s*/g," => "),t=t.trimEnd(),t}function Ye(n,t){let e=n.split(`
458
- `),s=t.split(`
459
- `),r=[],a=Math.max(e.length,s.length);for(let c=0;c<a;c++){let h=e[c],l=s[c];h!==l&&r.push({line:c+1,original:h,formatted:l})}return r}ye.exports={format:Ke,diff:Ye}});var Te=_((Ls,ge)=>{"use strict";var Ee=require("fs"),Y=require("path"),{Lexer:qe}=J(),{Parser:Je}=et(),{CodeGenerator:Xe}=xt(),Z=class extends Error{constructor(t,e){super(e?`[${Y.basename(e)}] ${t}`:t),this.name="BundleError",this.file=e}};function Ze(n,t){let e=[],s=[],r=[],a=Y.dirname(t);for(let c of n.body)if(c.type==="ImportDecl"){let h=c.source;h.endsWith(".flux")||(h+=".flux");let l=Y.resolve(a,h);e.push({names:c.names,source:c.source,absPath:l})}else if(c.type==="ExportDecl"){let h=c.decl;h.type==="FnDecl"&&s.push(h.name),h.type==="ClassDecl"&&s.push(h.name),h.type==="VarDecl"&&s.push(h.name),r.push(h)}else r.push(c);return{cleanAst:{type:"Program",body:r},imports:e,exports:s}}function ts(n){let{code:t}=new Xe({indent:" "}).generate(n),e=t.split(`
460
- `),s=e.findIndex(r=>r.trim()!==""&&!r.includes("Dihasilkan")&&!r.includes('"use strict"'));return e.slice(s).join(`
461
- `)}function de(n){return"_flux_"+Y.basename(n,".flux").replace(/[^a-zA-Z0-9]/g,"_")}var yt=class{constructor(t,e={}){this.entryFile=Y.resolve(t),this.options=e,this.modules=new Map,this.order=[],this.visited=new Set,this.inStack=new Set}bundle(){return this.collect(this.entryFile),this.link()}collect(t){if(this.visited.has(t))return;if(this.inStack.has(t))throw new Z(`Dependensi sirkular terdeteksi: ${t}`,t);if(!Ee.existsSync(t))throw new Z(`File tidak ditemukan: ${t}`,t);this.inStack.add(t);let e=Ee.readFileSync(t,"utf8"),s;try{let h=new qe(e).tokenize();s=new Je(h).parse()}catch(h){throw new Z(`Error saat parsing: ${h.message}`,t)}let{cleanAst:r,imports:a,exports:c}=Ze(s,t);this.modules.set(t,{cleanAst:r,imports:a,exports:c,source:e,absPath:t});for(let h of a)this.collect(h.absPath);this.inStack.delete(t),this.visited.add(t),this.order.push(t)}link(){let t=[];this.options.banner!==!1&&(t.push("// Dihasilkan oleh Flux Bundler"),t.push(`// Entry: ${Y.basename(this.entryFile)}`),t.push(`// Modul: ${this.order.length}`),t.push('"use strict";'),t.push("")),t.push("// flux_modules resolver"),t.push("(function(){var _p=require('path'),_fs=require('fs'),_M=require('module'),_d=_p.join(process.cwd(),'flux_modules','node_modules');if(_fs.existsSync(_d)){var _o=_M._resolveFilename.bind(_M);_M._resolveFilename=function(r,p,m,op){if(!r.startsWith('.')&&!r.startsWith('/')&&!r.startsWith('node:')){var _fp=_p.join(_d,r.split('/')[0]);if(_fs.existsSync(_fp)){try{return _o(_p.join(_d,r),p,m,op);}catch(_e){}}}return _o(r,p,m,op);};}})();"),t.push(""),t.push("(function() {"),t.push("");for(let s of this.order){let{cleanAst:r,imports:a,exports:c}=this.modules.get(s),h=s===this.entryFile,l=de(s),p=Y.relative(process.cwd(),s);t.push(` // ${"\u2500".repeat(60)}`),t.push(` // Modul: ${p}`),t.push(` // ${"\u2500".repeat(60)}`),h||(t.push(` var ${l} = (function() {`),t.push(" var _exports = {};"),t.push(""));for(let y of a){let u=de(y.absPath);if(y.names.length===1)t.push(` var ${y.names[0]} = ${u};`);else for(let d of y.names)t.push(` var ${d} = ${u}._exports ? ${u}._exports.${d} : ${u}.${d};`)}a.length>0&&t.push("");let m=ts(r);if(t.push(m),!h){if(c.length>0){t.push("");for(let y of c)t.push(` _exports.${y} = ${y};`)}t.push(""),t.push(" return _exports;"),t.push(" })()"),t.push(` ${l}._exports = ${l};`)}t.push("")}return t.push("})();"),{code:t.join(`
462
- `),modules:this.order.length}}};function es(n,t={}){let e={success:!1,code:"",modules:0,errors:[]};try{let s=new yt(n,t),{code:r,modules:a}=s.bundle();e.code=r,e.modules=a,e.success=!0}catch(s){e.errors.push({message:s.message,name:s.name,file:s.file||null})}return e}ge.exports={bundle:es,Bundler:yt,BundleError:Z}});var be=_((Cs,xe)=>{"use strict";var ss=require("fs"),is=require("path"),rs=["flux.config.js","flux.config.cjs",".fluxrc.js"];function ns(n){let t=n||process.cwd();for(let e of rs){let s=is.join(t,e);if(ss.existsSync(s)){delete require.cache[require.resolve(s)];try{let r=require(s),a=r&&r.default?r.default:r;return typeof a!="object"||a===null?(process.stderr.write(`[flux] warning: ${e} must export a plain object \u2014 ignoring
463
- `),{}):a}catch(r){return process.stderr.write(`[flux] error loading ${e}: ${r.message}
464
- `),{}}}}return{}}function as(n,t){let e=n||{},s=t||{};return{jsxTarget:s.jsxTarget!==void 0?s.jsxTarget:e.jsxTarget||"browser",outDir:s.outDir!==void 0?s.outDir:e.outDir||null,sourcemap:s.sourcemap!==void 0?s.sourcemap:e.sourcemap||!1,mangle:s.mangle!==void 0?s.mangle:e.mangle!==void 0?e.mangle:!0,ignore:s.ignore!==void 0?s.ignore:e.ignore||[],entry:s.entry!==void 0?s.entry:e.entry||null}}function cs(n){return n}function hs(n,t){if(!t||t.length===0)return!1;let e=r=>r.replace(/\\/g,"/"),s=e(n);for(let r of t){let a=e(r).replace(/\*\*/g,"\0DS\0");if(a=a.replace(/[.+^${}()|[\]\\]/g,"\\$&"),a=a.replace(/\*/g,"[^/]*"),a=a.replace(/\x00DS\x00\//g,"(.+/)?").replace(/\x00DS\x00/g,".*"),new RegExp("(^|/)"+a+"$").test(s))return!0}return!1}xe.exports={loadConfig:ns,mergeConfig:as,defineConfig:cs,matchIgnore:hs}});var{transpile:ls}=me(),{format:os}=ke(),{buildStdlib:ps,detectUsedSymbols:us,STDLIB_SYMBOLS:fs}=_t(),{Lexer:ms}=J(),{Parser:ys}=et(),{bundle:ks}=Te(),{loadConfig:Es,mergeConfig:ds,defineConfig:gs}=be();module.exports={transpile:ls,format:os,buildStdlib:ps,detectUsedSymbols:us,STDLIB_SYMBOLS:fs,Lexer:ms,Parser:ys,bundle:ks,loadConfig:Es,mergeConfig:ds,defineConfig:gs};
199
+ `)}at.exports.buildStdlib=ve});var Jt=S((Ts,lt)=>{"use strict";var $t=require("fs"),I=require("path"),{lexerize:Ie}=B(),{makeParser:Le}=Q(),{makeCodeGen:Ce}=mt();function qt(a){return"_flux_"+I.basename(a,".flux").replace(/[^a-zA-Z0-9]/g,"_")}function Me(a,t){let e=[],s=[],i=[],n=I.dirname(t);for(let h of a.body)if(h.type=="ImportDecl"){let l=h.source;l.endsWith(".flux")||(l=l+".flux");let c=I.resolve(n,l);e.push({names:h.names,source:h.source,absPath:c})}else if(h.type=="ExportDecl"){let l=h.decl;l.type=="FnDecl"&&s.push(l.name),l.type=="ClassDecl"&&s.push(l.name),l.type=="VarDecl"&&s.push(l.name),i.push(l)}else i.push(h);return{cleanAst:{type:"Program",body:i},imports:e,exports:s}}function Pe(a){let s=Ce({indent:" "}).generate(a).code.split(`
200
+ `),i=s.findIndex(n=>n.trim()!=""&&!n.includes("Generated by Flux")&&!n.includes('"use strict"'));return s.slice(i).join(`
201
+ `)}var ht=class{constructor(t,e,s,i,n,h){this.entryFile=t,this.options=e,this.modules=s,this.order=i,this.visited=n,this.inStack=h}bundle(){return this.collect(this.entryFile),this.link()}collect(t){if(this.visited.has(t))return;if(this.inStack.has(t))throw new Error("["+I.basename(t)+"] Circular dependency detected: "+t);if(!$t.existsSync(t))throw new Error("["+I.basename(t)+"] File not found: "+t);this.inStack.add(t);let e=$t.readFileSync(t,"utf8"),s=null;try{let n=Ie(e).tokenize();s=Le(n).parse()}catch(n){throw new Error("["+I.basename(t)+"] Parse error: "+n.message)}let i=Me(s,t);this.modules.set(t,{cleanAst:i.cleanAst,imports:i.imports,exports:i.exports,source:e,absPath:t});for(let n of i.imports)this.collect(n.absPath);this.inStack.delete(t),this.visited.add(t),this.order.push(t)}link(){let t=[];this.options.banner!=!1&&(t.push("// Generated by Flux Bundler (self-hosted)"),t.push("// Entry: "+I.basename(this.entryFile)),t.push("// Modules: "+this.order.length),t.push('"use strict";'),t.push("")),t.push("// flux_modules resolver"),t.push("(function(){var _p=require('path'),_fs=require('fs'),_M=require('module'),_d=_p.join(process.cwd(),'flux_modules','node_modules');if(_fs.existsSync(_d)){var _o=_M._resolveFilename.bind(_M);_M._resolveFilename=function(r,p,m,op){if(!r.startsWith('.')&&!r.startsWith('/')&&!r.startsWith('node:')){var _fp=_p.join(_d,r.split('/')[0]);if(_fs.existsSync(_fp)){try{return _o(_p.join(_d,r),p,m,op);}catch(_e){}}}return _o(r,p,m,op);};}})();"),t.push(""),t.push("(function() {"),t.push("");for(let s of this.order){let i=this.modules.get(s),n=s==this.entryFile,h=qt(s),l=I.relative(process.cwd(),s);t.push(" // "+"\u2500".repeat(60)),t.push(" // Module: "+l),t.push(" // "+"\u2500".repeat(60)),n||(t.push(" var "+h+" = (function() {"),t.push(" var _exports = {};"),t.push(""));for(let o of i.imports){let u=qt(o.absPath);for(let y of o.names){let g=y.alias??y.name,T=y.name;t.push(" var "+g+" = "+u+"._exports ? "+u+"._exports."+T+" : "+u+"."+T+";")}}i.imports.length>0&&t.push("");let c=Pe(i.cleanAst);if(t.push(c),!n){if(i.exports.length>0){t.push("");for(let o of i.exports)t.push(" _exports."+o+" = "+o+";")}t.push(""),t.push(" return _exports;"),t.push(" })()"),t.push(" "+h+"._exports = "+h+";")}t.push("")}return t.push("})();"),{code:t.join(`
202
+ `),modules:this.order.length}}};lt.exports.Bundler=ht;function Yt(a,t){return new ht(I.resolve(a),t??{},new Map,[],new Set,new Set)}lt.exports.makeBundler=Yt;function Fe(a,t){let e={success:!1,code:"",modules:0,errors:[]};try{let i=Yt(a,t).bundle();e.code=i.code,e.modules=i.modules,e.success=!0}catch(s){e.errors.push({message:s.message,name:s.name,file:null})}return e}lt.exports.bundle=Fe});var Kt=S((xs,P)=>{"use strict";var L=require("fs"),Y=require("path"),ct={entry:"src/main.flux",outDir:"dist",sourcemap:!1,mangle:!1,jsx:!1,jsxTarget:"browser",typecheck:!0,strict:!1,watch:!1,ignore:[],selfHosted:!1,registry:"https://registry.flux-lang.dev",pkg:{name:"",version:"1.0.0",description:"",author:"",license:"MIT",deps:{},devDeps:{}}};P.exports.DEFAULT_CONFIG=ct;function Be(a){let t=a??process.cwd(),e=Y.join(t,"flux.json");if(L.existsSync(e))try{let i=L.readFileSync(e,"utf8"),n=JSON.parse(i);return xt(ct,n)}catch(i){throw new Error("Invalid flux.json: "+i.message)}let s=Y.join(t,"flux.config.js");if(L.existsSync(s))try{let i=require(s);return xt(ct,i)}catch(i){throw new Error("Invalid flux.config.js: "+i.message)}return{...ct}}P.exports.loadConfig=Be;function xt(a,t){if(!t)return{...a};let e={...a};for(let s of Object.keys(t)){let i=t[s];i!=null&&i!=null&&(e[s]=i)}return e}P.exports.mergeConfig=xt;function je(a,t){let e=t??process.cwd(),s=Y.join(e,"flux.json"),i=JSON.stringify(a,null,2)+`
203
+ `;L.writeFileSync(s,i,"utf8")}P.exports.writeConfig=je;function _e(a){let t=[];return a.entry&&!a.entry.endsWith(".flux")&&t.push("entry must be a .flux file"),a.jsxTarget&&!["browser","server","react"].includes(a.jsxTarget)&&t.push("jsxTarget must be 'browser', 'server', or 'react'"),{valid:t.length==0,errors:t}}P.exports.validateConfig=_e;function Ue(a){let t=a??process.cwd(),e=Y.join(t,"flux.json"),s=Y.join(t,"package.json");if(L.existsSync(e))try{return JSON.parse(L.readFileSync(e,"utf8"))}catch{return null}if(L.existsSync(s))try{return JSON.parse(L.readFileSync(s,"utf8"))}catch{return null}return null}P.exports.readPackage=Ue});var{transpile:We}=zt(),{format:Ve}=Ht(),{buildStdlib:Qe,detectUsedSymbols:ze,STDLIB_SYMBOLS:He}=Gt(),{Lexer:Ge}=B(),{Parser:$e}=Q(),{bundle:qe}=Jt(),{loadConfig:Ye,mergeConfig:Je,defineConfig:Ke}=Kt();module.exports={transpile:We,format:Ve,buildStdlib:Qe,detectUsedSymbols:ze,STDLIB_SYMBOLS:He,Lexer:Ge,Parser:$e,bundle:qe,loadConfig:Ye,mergeConfig:Je,defineConfig:Ke};