@laot/bridge 1.0.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ltbridge.js CHANGED
@@ -1,69 +1,69 @@
1
1
  #!/usr/bin/env node
2
- var re=(k,u)=>()=>(u||k((u={exports:{}}).exports,u),u.exports);var we=re((ft,pn)=>{pn.exports={name:"@laot/bridge",version:"1.0.8",description:"LTBridge CLI for fetching and bundling FiveM modules.",license:"MIT",repository:{type:"git",url:"https://github.com/laot7490/ltbridge.git"},author:"laot",keywords:["fivem","lua","bridge","module-manager","bundler","cli","gta5","redm","laot","ltbridge"],main:"dist/ltbridge.js",scripts:{build:"node scripts/compiler.js && esbuild bin/ltbridge.js --bundle --minify --platform=node --target=node18 --packages=external --outfile=dist/ltbridge.js",zip:"node scripts/zip-dist.js",prepublishOnly:"npm run build && npm run zip"},bin:{ltbridge:"./dist/ltbridge.js"},files:["dist","LICENSE","README.md"],dependencies:{chokidar:"^5.0.0",commander:"^11.0.0","fs-extra":"^11.1.1",prompts:"^2.4.2"},devDependencies:{esbuild:"^0.25.0"}}});var De=re((dt,Oe)=>{var hn=/__LT_VERSION\s*=\s*'[^']*'/g,mn=/__LT_DISABLE_DEBUG\s*=\s*(true|false)/g;function kn(k,{version:u,disableDebug:d}={}){if(!k)return k;let n=k;return u&&(n=n.replace(hn,`__LT_VERSION = '${u}'`)),d!==void 0&&(n=n.replace(mn,`__LT_DISABLE_DEBUG = ${d?"true":"false"}`)),n}Oe.exports={applyBuildConstants:kn}});var ue=re((Tt,Ue)=>{var qe=require("fs"),gn=require("path"),Fe=null;function Ae(){if(Fe)return Fe;let k=gn.join(__dirname,"..","dist","modules.dat");return qe.existsSync(k)||(console.log("\x1B[31m\u2716 LTBridge is not compiled. Please run 'npm run build' first.\x1B[0m"),process.exit(1)),Fe=JSON.parse(qe.readFileSync(k,"utf8")),Fe}function Ln(){return Ae().registry}function Sn(k){return Ae().modules[k]}Ue.exports={getModuleRegistry:Ln,getDatabase:Ae,getModuleData:Sn}});var Ie=re((mt,Ke)=>{var pt=require("fs"),ht=require("path"),{getModuleRegistry:bn,getModuleData:We}=ue();function yn(k,u){let d=bn(),n=Object.keys(d),i=new Set,l=new Set,e=[],t={};function c(o,g){let L=We(o);if(!L)return[];if(L.meta&&Array.isArray(L.meta.dependencies))return L.meta.dependencies;let a=new Set,p="";["shared","client","server"].forEach(F=>{L[F]&&L[F].code&&(p+=L[F].code+`
3
- `)});let m=/(?:^|[^a-zA-Z0-9_.:"'\]])(LT\.[a-zA-Z0-9_.]+|[a-zA-Z0-9_]+)/g,S;for(;(S=m.exec(p))!==null;){let F=S[1];F.startsWith("LT.")&&(F=F.substring(3));let $=F.split("."),G="";for(let A of $){G=G?G+"."+A:A;let R="@"+G.replace(/\./g,"/"),N=G.replace(/\./g,"/");if(n.includes(R)&&R!==o?a.add(R):n.includes(N)&&N!==o?a.add(N):n.includes(G)&&G!==o&&a.add(G),g&&g[G]){let V=g[G];if(V.length===1)V[0]!==o&&a.add(V[0]);else if(G.includes(".")){let j=G.split(".")[0].toLowerCase(),D=V.find(X=>X.toLowerCase().includes(j));D&&D!==o&&a.add(D)}else{let D=V.find(X=>{let Y=We(X);if(!Y)return!1;let ee=!1;return["shared","client","server"].forEach(te=>{Y[te]&&Y[te].stubs&&Y[te].stubs.some(z=>z.metadata&&z.metadata.global)&&(ee=!0)}),ee})||V[0];D!==o&&a.add(D)}}}}let w=d[o];if(w){let $=w.replace(/\\/g,"/").split("/");for(;$.length>1;){$.pop();let G=$[$.length-1],A=G,R="@"+G;o!==A&&n.includes(A)&&a.add(A),o!==R&&n.includes(R)&&a.add(R)}}return Array.from(a)}function s(o){if(i.has(o))return;if(l.has(o)){console.log(`
4
- \x1B[33m! Circular dependency detected involving '${o}'.\x1B[0m`);return}if(l.add(o),!d[o]){console.log(`\x1B[31m\u2716 Trying to resolve '${o}' but it does not exist in LTBridge.\x1B[0m`),l.delete(o);return}let g=c(o,u);t[o]=g;for(let L of g)s(L);l.delete(o),i.add(o),e.push(o)}for(let o of k)s(o);return{sequence:e,graph:t}}Ke.exports={resolveDependencies:yn}});var Xe=re((kt,Ge)=>{var ge=console.log,J=function(k,u){if(!k)throw u};function _n(k,u){if(!k)return 0;var d=k.toString().split(".");return d.length>1?parseInt(d[0],u)+parseInt(d[1],u)/Math.pow(u,d[1].length):parseInt(d[0],u)}var En=[" ",`
5
- `," ","\r"],Cn={r:"\r",n:`
6
- `,t:" ",'"':'"',"'":"'","\\":"\\"},ze=new Proxy(Cn,{get(k,u){return _n(u)}}),wn=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","_","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],Pe=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","_","a","b","c","d","e","f","g","t","u","v","w","h","i","j","k","l","m","n","o","p","q","r","s","x","y","z"],he=["0","1","2","3","4","5","6","7","8","9"],Fn=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","A","B","C","D","E","F"],Gn=["+","-","*",")",";","/","^","%","#",",","{","}",":","[","]","(",".","`"],Bn=["~","=",">","<"],xn=["+","-","*","/","^","..","%","//"],$n=["+=","-=","*=","/=","^=","..=","%=","//="],Ze=["and","break","do","else","elseif","end","false","for","function","goto","if","in","local","nil","not","or","repeat","return","then","true","until","while","continue"],me=["continue","goto"],Rn=["else","elseif","until","end"],An=["-","not","#","~"],Je=["+","-","*","/","%","^","#","//","&","|","~","<<",">>","..",".",":",">","<","<=",">=","~=","==","+=","-=","*=","/=","%=","^=","..=","//=","and","or"],In=11,Me={"^":[13,12],"%":[10,10],"//":[10,10],"/":[10,10],"*":[10,10],"+":[9,9],"-":[9,9],"..":[8,7],">>":[7,7],"<<":[7,7],"&":[6,6],"~":[5,5],"|":[4,4],"==":[3,3],"~=":[3,3],">=":[3,3],"<=":[3,3],">":[3,3],"<":[3,3],"+=":[3,3],"-=":[3,3],"*=":[3,3],"/=":[3,3],"^=":[3,3],"%=":[3,3],"..=":[3,3],"//=":[3,3],and:[2,2],or:[1,1]};function Mn(k){let u=0,d=k.length,n=[];function i(a){return a=a||0,u<=d?k.substr(u+a,1):""}function l(){if(u<=d){let a=k.substr(u,1);return u++,a}else return""}function e(a){let p=0,m=1,S=1;for(;p<=u;)k.substr(p,1)==`
7
- `?(m++,S=1):S++;let w;for(w=0;w<n.length;w++){let F=n[w];ge(`${F.Type}<${F.Source}>`)}throw`file<${m}:${S}>: ${a}`}function t(a){for(;;){let p=l();if(p=="")e("Unfinished long string.");else if(p=="]"){let m=!0,S;for(S=1;S<=a;S++)if(i()=="=")u++;else{m=!1;break}if(m&&l()=="]")return}}}function c(){let a=u;for(;i()=="=";)u++;if(i()=="[")return u++,u-a-1;u=a}let s=0,o=0,g=0;function L(a){g++;let p=k.substr(o,u-o),m=null;a=="Number"&&(p=p.replace(/[\_]+/g,""),p.substr(0,2).toLowerCase()=="0x"?(m="hex",parseInt(p,16)<999999999999&&(p=parseInt(p,16))):p.substr(0,2).toLowerCase()=="0b"&&(m="bin",parseInt(p.substr(2),2)<999999999999&&(p=parseInt(p.substr(2),2))));let S={Type:a,LeadingWhite:k.substr(s,o-s),Source:p};return m!==null&&(S.NType=m),n.push(S),s=u,o=u,S}for(;;){for(s=u;;){let p=i();if(p=="")break;if(p=="-")if(i(1)=="-")if(u+=2,i()=="["){u++;let m=c();if(m!=null)t(m),s=u;else for(;;){let S=l();if(S==""||S==`
8
- `)break}}else for(;;){let m=l();if(m==""||m==`
9
- `)break}else break;else if(En.includes(p))u++;else break}o=u;let a=l();if(a==""){L("Eof");break}else if(a=="'"||a=='"'){for(;;){let p=l();if(p=="\\"){let m=l();if(ze[m]==null)throw`Invalid Escape Sequence \`${m}\`.`}else{if(p==a)break;if(p=="")throw"Unfinished string!"}}L("String")}else if(a=="`"){for(;;){let p=l();if(p=="\\"){let m=l();if(ze[m]==null)throw`Invalid Escape Sequence \`${m}\`.`}else{if(p==a)break;if(p=="")throw"Unfinished string!"}}L("Hash")}else if(wn.includes(a)){for(;Pe.includes(i());)u++;Ze.includes(k.substr(o,u-o))?L("Keyword"):L("Ident")}else if(he.includes(a)||a=="."&&he.includes(i())){if(a=="0"&&i().toLowerCase()=="x")for(u++;Fn.includes(i())||i()==="_";)u++;else if(a=="0"&&i().toLowerCase()=="b")for(u++;i()==="0"||i()==="1"||i()==="_";)u++;else{for(;he.includes(i())||i()==="_";)u++;if(i()==".")for(u++;he.includes(i());)u++;if(i()=="e"||i()=="E")for(u++,(i()=="-"||i()=="+")&&u++;he.includes(i());)u++}L("Number")}else if(a=="["){let p=c();p!=null?(t(p),L("String")):L("Symbol")}else if(a==".")i()=="."&&(l(),(i()=="."||i()=="=")&&l()),L("Symbol");else if(a+i()=="//")l(),i()=="="&&l(),L("Symbol");else if(a+i()=="::")l(),L("Symbol");else if(Je.includes(a+i()))l(),L("Symbol");else if(Bn.includes(a))i()=="="&&u++,L("Symbol");else if(xn.includes(a)&&i()=="=")l(),L("Symbol");else if(Gn.includes(a))L("Symbol");else throw`Bad symbol \`${a}\` in source. ${u}`}return n}function Pn(k){let u=Mn(k),d=0;function n(){let r=u[d];return d<u.length&&d++,r}function i(r){return r=d+(r||0),u[r]||u[u.length-1]}function l(r){let h=1,T=0,f=0;for(;;){let b=u[f],_;b==r?_=b.LeadingWhite:_=b.LeadingWhite+b.Source;let y;for(y=0;y<=_.length;y++)_.substr(y,1)==`
10
- `?(h++,T=0):T++;if(b==r)break;f++}return`${h}:${T+1}`}function e(){let r=i();return`<${r.Type} \`${r.Source}\`> at: ${l(r)}`}function t(){let r=i();return r.Type=="Eof"||r.Type=="Keyword"&&Rn.includes(r.Source)}function c(){return An.includes(i().Source)||!1}function s(){return Je.includes(i().Source)||!1}function o(r,h){let T=i();if(T.Type==r&&(h==null||T.Source==h))return n();if(T.Type=="Keyword"&&r=="Ident"&&me.includes(T.Source)&&(h==null||T.Source==h))return n();{let f;for(f=-3;f<=3;f++)ge(`Tokens[${f}] = \`${i(f).Source}\``);throw h?`${l(T)}: \`${h}\` expected.`:`${l(T)}: ${r} expected.`}}function g(r){let h=r.GetFirstToken,T=r.GetLastToken,f=r;return r.GetFirstToken=function(){let b=h(f);return J(b),b},r.GetLastToken=function(){let b=T(f);return J(b),b},r}let L,a;function p(r,h){let T=[a(r,h)],f=[];for(;i().Source==",";)f.push(n()),T.push(a(r,h));return[T,f]}function m(r,h){let T=i();if(T.Source=="("){let f=n(),b=a(r,h),_=o("Symbol",")"),y;return y=g({Type:"ParenExpr",Expression:b,Token_OpenParen:f,Token_CloseParen:_,GetFirstToken:()=>y.Token_OpenParen,GetLastToken:()=>y.Token_CloseParen}),y}else if(T.Type=="Ident"||T.Type=="Keyword"&&me.includes(T.Source)){let f;return f=g({Type:"VariableExpr",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),r[f.Token.Source]!=null&&r[f.Token.Source]?.Tokens?.push!=null?(r[f.Token.Source].Tokens.push(f.Token),r[f.Token.Source].UseCountIncrease()):h[f.Token.Source]!=null&&h[f.Token.Source]?.Tokens?.push!=null&&(h[f.Token.Source].Tokens.push(f.Token),h[f.Token.Source].UseCountIncrease()),f}else throw ge(e()),`${l(T)}: Unexpected symbol. ${T.Type} ${T.Source}`}function S(r,h){let T=o("Symbol","{"),f=[],b=[];for(;i().Source!="}";){let E,B;if(i().Source=="["){let C=n(),M=a(r,h),P=o("Symbol","]"),x=o("Symbol","="),Z=a(r,h);E=M.Token&&M.Token.Source,B=Z,f.push({EntryType:"Index",Index:M,Value:Z,Token_OpenBracket:C,Token_CloseBracket:P,Token_Equals:x})}else if((i().Type=="Ident"||i().Type=="Keyword"&&me.includes(i().Source))&&i(1).Source=="="){let C=n(),M=n(),P=a(r,h);E=C,B=P,f.push({EntryType:"Field",Field:C,Value:P,Token_Equals:M})}else{let C=a(r,h);f.push({EntryType:"Value",Value:C})}if(i().Source==","||i().Source==";")b.push(n());else break}let _=o("Symbol","}"),y;return y=g({Type:"TableLiteral",EntryList:f,Token_SeperatorList:b,Token_OpenBrace:T,Token_CloseBrace:_,GetFirstToken:()=>y.Token_OpenBrace,GetLastToken:()=>y.Token_CloseBrace}),y}function w(r,h){let T=[],f=[];if(i().Type=="Ident"||i().Type=="Keyword"&&me.includes(i().Source)){let b=n();if(h&&i().Source=="<"&&i(2).Source==">"){let _=i(1).Source;b.Attribute={LeadingWhite:i().LeadingWhite,Source:`<${_}>`},n(),n(),n()}T.push(b)}else if(i().Source=="..."&&r)return[T,f,n()];for(;i().Source==",";){if(f.push(n()),i().Source=="..."&&r)return[T,f,n()];{let b=o("Ident");if(h&&i().Source=="<"&&i(2).Source==">"){let _=i(1).Source;b.Attribute={LeadingWhite:i().LeadingWhite,Source:`<${_}>`},n(),n(),n()}T.push(b)}}return[T,f]}function F(r,h,T){let f=L(h,T),b=i();if(b.Type=="Keyword"&&b.Source==r)return n(),[f,b];throw ge(b.Type,b.Source),`${l(b)}: ${r} expected.`}function $(r,h,T,f){let b=n(),_,y;if(!r){_=[],y=[];let I=o("Ident");for(_.push(I);i().Source==".";)y.push(n()),_.push(o("Ident"));i().Source==":"&&(y.push(n()),_.push(o("Ident")))}let E=o("Symbol","("),[B,C,M]=w(!0),P=o("Symbol",")"),[x,Z]=F("end",h,T),oe;return oe=g({Type:r==!0?"FunctionLiteral":"FunctionStat",NameChain:_,ArgList:B,Body:x,Token_Function:b,Token_NameChainSeperator:y,Token_OpenParen:E,Token_Varg:M,Token_ArgCommaList:C,Token_CloseParen:P,Token_End:Z,GetFirstToken:()=>oe.Token_Function,GetLastToken:()=>oe.Token_End}),oe}function G(r,h){let T=i();if(T.Source=="("){let f=n(),b=[],_=[];for(;i().Source!=")"&&(b.push(a(r,h)),i().Source==",");)_.push(n());let y=o("Symbol",")"),E;return E=g({CallType:"ArgCall",ArgList:b,Token_CommaList:_,Token_OpenParen:f,Token_CloseParen:y,GetFirstToken:()=>E.Token_OpenParen,GetLastToken:()=>E.Token_CloseParen}),E}else if(T.Source=="{"){let f;return f=g({CallType:"TableCall",TableExpr:a(r,h),GetFirstToken:()=>f.TableExpr.GetFirstToken(),GetLastToken:()=>f.TableExpr.GetLastToken()}),f}else if(T.Type=="String"){let f;return f=g({CallType:"StringCall",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else throw"Function arguments expected."}function A(r,h){let T=m(r,h);for(J(T,"nil prefixexpr");;){let f=i();if(f.Source=="."){let b=n(),_=o("Ident"),y;y=g({Type:"FieldExpr",Base:T,Field:_,Token_Dot:b,GetFirstToken:()=>y.Base.GetFirstToken(),GetLastToken:()=>y.Field}),T=y}else if(f.Source==":"){let b=n(),_=o("Ident"),y=G(r,h),E;E=g({Type:"MethodExpr",Base:T,Method:_,FunctionArguments:y,Token_Colon:b,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.FunctionArguments.GetLastToken()}),T=E}else if(f.Source=="["){let b=n(),_=a(r,h),y=o("Symbol","]"),E;E=g({Type:"IndexExpr",Base:T,Index:_,Token_OpenBracket:b,Token_CloseBracket:y,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.Token_CloseBracket}),T=E}else if(f.Source=="{"||f.Source=="("||f.Type=="String"){let b;b=g({Type:"CallExpr",Base:T,FunctionArguments:G(r,h),GetFirstToken:()=>b.Base.GetFirstToken(),GetLastToken:()=>b.FunctionArguments.GetLastToken()}),T=b}else if($n.includes(f.Source)){let b=n(),_=a(r,h),y;y=g({Type:"CompoundStat",Base:T,Token_Compound:b,Rhs:_,Lhs:T,GetFirstToken:()=>y.Base.GetFirstToken(),GetLastToken:()=>y.Rhs.GetLastToken()}),T=y}else return T}}function R(r,h){let T=i();if(T.Type=="Number"){let f;return f=g({Type:"NumberLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Type=="String"){let f;return f=g({Type:"StringLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Type=="Hash"){let f;return f=g({Type:"HashLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Source=="nil"){let f;return f=g({Type:"NilLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Source=="true"||T.Source=="false"){let f;return f=g({Type:"BooleanLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else if(T.Source=="..."){let f;return f=g({Type:"VargLiteral",Token:n(),GetFirstToken:()=>f.Token,GetLastToken:()=>f.Token}),f}else return T.Source=="{"?S(r,h):T.Source=="function"?$(!0,r,h):T.Source=="if"?j(!0,r,h):A(r,h)}function N(r,h,T){let f;if(c()){let b=n(),_=N(In,h,T),y;y=g({Type:"UnopExpr",Token_Op:b,Rhs:_,GetFirstToken:()=>y.Token_Op,GetLastToken:()=>y.Rhs.GetLastToken()}),f=y}else f=R(h,T),J(f,"nil sipleexpr");for(;s()&&Me[i().Source]!=null&&Me[i().Source][0]>r;){let b=n(),_=N(Me[b.Source][1],h,T);J(_,"RhsNeeded");let y;y=g({Type:"BinopExpr",Lhs:f,Rhs:_,Token_Op:b,GetFirstToken:()=>y.Lhs.GetFirstToken(),GetLastToken:()=>y.Rhs.GetLastToken()}),f=y}return f}a=(r,h)=>N(0,r,h);function V(r,h){let T=A(r,h);if(T.Type=="MethodExpr"||T.Type=="CallExpr"){let f;return f=g({Type:"CallExprStat",Expression:T,GetFirstToken:()=>f.Expression.GetFirstToken(),GetLastToken:()=>f.Expression.GetLastToken()}),f}else{if(T.Type=="CompoundStat")return T;{let f=[T],b=[];for(T.IsStat=!0;i().Source==",";){b.push(n());let C=A(r,h);if(C.Type=="MethodExpr"||C.Type=="CallExpr")throw"Bad left hand side of asignment";C.IsStat=!0,f.push(C)}let _=o("Symbol","="),y=[a(r,h)],E=[];for(;i().Source==",";)E.push(n()),y.push(a(r,h));let B;return B=g({Type:"AssignmentStat",Rhs:y,Lhs:f,Token_Equals:_,Token_LhsSeperatorList:b,Token_RhsSeperatorList:E,GetFirstToken:()=>B.Lhs[0].GetFirstToken(),GetLastToken:()=>B.Rhs[B.Rhs.length-1].GetLastToken()}),B}}}function j(r,h,T){let f=n(),b=a(h,T),_=o("Keyword","then"),y=r?a(h,T):L(h,T),E=[];for(;i().Source=="elseif"||i().Source=="else";){let M=n(),P,x;M.Source=="elseif"&&(P=a(h,T),x=o("Keyword","then"));let Z=r?a(h,T):L(h,T);if(E.push({Condition:P,Body:Z,ClauseType:M.Source,Token:M,Token_Then:x}),M.Source=="else")break}let B=r?null:o("Keyword","end"),C;return C=g({Type:r?"IfExpr":"IfStat",Condition:b,Body:y,ElseClauseList:E,Token_If:f,Token_Then:_,Token_End:B,GetFirstToken:()=>C.Token_If,GetLastToken:()=>C.Token_End}),C}function D(r,h){let T=n(),[f,b]=F("end",r,h),_;return _=g({Type:"DoStat",Body:f,Token_Do:T,Token_End:b,GetFirstToken:()=>_.Token_Do,GetLastToken:()=>_.Token_End}),_}function X(r,h){let T=n(),f=a(r,h),b=o("Keyword","do"),[_,y]=F("end",r,h),E;return E=g({Type:"WhileStat",Condition:f,Body:_,Token_While:T,Token_Do:b,Token_End:y,GetFirstToken:()=>E.Token_While,GetLastToken:()=>E.Token_End}),E}function Y(r,h){let T=n(),[f,b]=w(),_=[];if(i().Source=="="){let y=n(),[E,B]=p(r,h);if(E.length<2||E.length>3)throw"Expected 2 or 3 values for range bounds";let C=o("Keyword","do"),[M,P]=F("end",r,h),x;return x=g({Type:"NumericForStat",VarList:f,RangeList:E,Body:M,Token_For:T,Token_VarCommaList:b,Token_Equals:y,Token_RangeCommaList:B,Token_Do:C,Token_End:P,GetFirstToken:()=>x.Token_For,GetLastToken:()=>x.Token_End}),x}else if(i().Source=="in"){let y=n(),[E,B]=p(r,h),C=o("Keyword","do"),[M,P]=F("end",r,h),x;return x=g({Type:"GenericForStat",VarList:f,GeneratorList:E,Body:M,Token_For:T,Token_VarCommaList:b,Token_In:y,Token_GeneratorCommaList:B,Token_Do:C,Token_End:P,GetFirstToken:()=>x.Token_For,GetLastToken:()=>x.Token_End}),x}}function ee(r,h){let T=n(),[f,b]=F("until",r),_=a(r,h),y;return y=g({Type:"RepeatStat",Body:f,Condition:_,Token_Repeat:T,Token_Until:b,GetFirstToken:()=>y.Token_Repeat,GetLastToken:()=>y.Condition.GetLastToken()}),y}function te(r,h){let T=n();if(i().Source=="function"){let f=$(!1,r,h,!0);if(f.NameChain.length>1)throw l(f.Token_NameChainSeperator[0])+": `(` expected.";let b;return b=g({Type:"LocalFunctionStat",FunctionStat:f,Token_Local:T,GetFirstToken:()=>b.Token_Local,GetLastToken:()=>b.FunctionStat.GetLastToken()}),b}else if(i().Type=="Ident"||i().Type=="Keyword"&&me.includes(i().Source)){let[f,b]=w(!1,!0),_=[],y=[],E;if(i().Source=="="){E=n();let[C,M]=p(r,h);_=C,y=M}let B;return B=g({Type:"LocalVarStat",VarList:f,ExprList:_,Token_Local:T,Token_Equals:E,Token_VarCommaList:b,Token_ExprCommaList:y,GetFirstToken:()=>B.Token_Local,GetLastToken:function(){return B.ExprList.length>0?B.ExprList[B.ExprList.length-1].GetLastToken():B.VarList[B.VarList.length-1]}}),B}else throw"`function` or ident expected"}function z(r,h){let T=n(),f,b;t()||i().Source==";"?(f=[],b=[]):[f,b]=p(r,h);let _;return _={Type:"ReturnStat",ExprList:f,Token_Return:T,Token_CommaList:b,GetFirstToken:()=>_.Token_Return,GetLastToken:function(){return _.ExprList.length>0?_.ExprList[_.ExprList.length-1].GetLastToken():_.Token_Return}},_}function ce(){let r=n(),h;return h={Type:"BreakStat",Token_Break:r,GetFirstToken:()=>h.Token_Break,GetLastToken:()=>h.Token_Break},h}function _e(r,h){if(i(1).Source=="(")return[!1,V(r,h)];let T=n(),f;return f={Type:"ContinueStat",Token_Continue:T,GetFirstToken:()=>f.Token_Continue,GetLastToken:()=>f.Token_Continue},[!0,f]}function H(){let r=n(),h;i().Type=="Keyword"?h=o("Keyword"):h=o("Ident");let T;return T={Type:"GotoStat",Token_Goto:r,Token_Label:h,GetFirstToken:()=>T.Token_Goto,GetLastToken:()=>T.Token_Label},T}function Re(){let r=n(),h;i().Type=="Keyword"?h=o("Keyword"):h=o("Ident");let T=o("Symbol","::"),f;return f={Type:"LabelStat",Token_ColonsLeft:r,Token_Label:h,Token_ColonsRight:T,GetFirstToken:()=>f.Token_ColonsLeft,GetLastToken:()=>f.Token_ColonsRight},f}function Ee(r,h){let T=i();return T.Source=="if"?[!1,j(!1,r,h)]:T.Source=="while"?[!1,X(r,h)]:T.Source=="do"?[!1,D(r,h)]:T.Source=="for"?[!1,Y(r,h)]:T.Source=="repeat"?[!1,ee(r,h)]:T.Source=="function"?[!1,$(!1,r,h)]:T.Source=="local"?[!1,te(r,h)]:T.Source=="return"?[!0,z(r,h)]:T.Source=="break"?[!0,ce(r,h)]:T.Source=="continue"?_e(r,h):T.Source=="goto"?[!1,H()]:T.Source=="::"?[!1,Re()]:[!1,V(r,h)]}let Te=1;return L=function(r,h){let T=[],f=[],b=!1,_={},y={};if(h!=null)for(let[P,x]of Object.entries(h))y[P]=x;if(r!=null)for(let[P,x]of Object.entries(r))y[P]=x;let E,B=0;for(;!b&&!t();){E&&E==i()&&ge(`INFINITE LOOP POSSIBLE ON STATEMENT ${E.Source} :`,E),E=i();let[P,x]=Ee(_,y);if(x)switch(T.push(x),x.Type){case"LocalVarStat":x.VarList.forEach(I=>{I.UseCount=0,I.Number=B++,_[I.Source]=I;let ie=[];function U(){I.UseCount++,ie.forEach(q=>{q.UseCount=I.UseCount})}I.Tokens={},I.Tokens.push=q=>{q.UseCountIncrease=U,q.UseCount=I.UseCount,q.Tokens=I.Tokens,ie.push(q)},I.Tokens.get=()=>ie,I.UseCountIncrease=U});break;case"LocalFunctionStat":let oe=x.FunctionStat.NameChain;if(oe.length===1){let U=function(){I.UseCount++,ie.forEach(q=>{q.UseCount=I.UseCount})};var M=U;let I=oe[0];I.UseCount=0,I.Number=B++,_[I.Source]=I;let ie=[];I.Tokens={},I.Tokens.push=q=>{q.UseCountIncrease=U,q.UseCount=I.UseCount,q.Tokens=I.Tokens,ie.push(q)},I.Tokens.get=()=>ie,I.UseCountIncrease=U}break;default:break}let Z=i();Z.Type=="Symbol"&&Z.Source==";"&&(f[T.length-1]=n())}let C;return C={Type:"StatList",StatementList:T,SemicolonList:f,GetFirstToken:function(){if(C.StatementList.length!=0)return C.StatementList[0]?.GetFirstToken()},GetLastToken:function(){if(C.StatementList.length!=0)return C.SemicolonList[C.StatementList.length-1]?C.SemicolonList[C.StatementList.length-1]:C.StatementList[C.StatementList.length-1].GetLastToken()}},C},L([],[])}function ke(k,u){let d={BinopExpr:!0,UnopExpr:!0,NumberLiteral:!0,StringLiteral:!0,NilLiteral:!0,BooleanLiteral:!0,VargLiteral:!0,HashLiteral:!0,FieldExpr:!0,IndexExpr:!0,MethodExpr:!0,CallExpr:!0,FunctionLiteral:!0,VariableExpr:!0,ParenExpr:!0,TableLiteral:!0},n={StatList:!0,BreakStat:!0,ContinueStat:!0,LabelStat:!0,GotoStat:!0,ReturnStat:!0,LocalVarStat:!0,LocalFunctionStat:!0,FunctionStat:!0,RepeatStat:!0,GenericForStat:!0,NumericForStat:!0,WhileStat:!0,DoStat:!0,IfStat:!0,CallExprStat:!0,AssignmentStat:!0,CompoundStat:!0};for(var[i,l]of Object.entries(u))if(!(i==="VisitStat"||i==="VisitExpr")&&!n[i]&&!d[i])throw`Invalid visitor target: \`${i}\``;function e(o){if(o!=null){let g=u[o.Type];if(typeof g=="function")return g(o);if(g&&g.Pre)return g.Pre(o)}}function t(o){let g=u[o.Type];if(g&&typeof g=="object"&&g.Post)return g.Post(o)}let c,s;c=function(o){if(!e(o)){if(o.Type=="BinopExpr")c(o.Lhs),c(o.Rhs);else if(o.Type=="UnopExpr")c(o.Rhs);else if(!(o.Type=="NumberLiteral"||o.Type=="StringLiteral"||o.Type=="NilLiteral"||o.Type=="BooleanLiteral"||o.Type=="VargLiteral"||o.Type=="HashLiteral")){if(o.Type=="FieldExpr")c(o.Base);else if(o.Type=="IndexExpr")c(o.Base),c(o.Index);else if(o.Type=="MethodExpr"||o.Type=="CallExpr")c(o.Base),o.FunctionArguments.CallType=="ArgCall"?o.FunctionArguments.ArgList.forEach((g,L)=>{c(g)}):o.FunctionArguments.CallType=="TableCall"&&c(o.FunctionArguments.TableExpr);else if(o.Type=="FunctionLiteral")s(o.Body);else if(o.Type!="VariableExpr")if(o.Type=="ParenExpr")c(o.Expression);else if(o.Type=="TableLiteral")o.EntryList.forEach((g,L)=>{if(g.EntryType=="Field")c(g.Value);else if(g.EntryType=="Index")c(g.Index),c(g.Value);else if(g.EntryType=="Value")c(g.Value);else throw"unreachable"});else if(o.Type=="CompoundStat")c(o.Lhs),c(o.Rhs);else if(o.Type=="IfExpr")c(o.Condition),c(o.Body),o.ElseClauseList.forEach(g=>{g.Condition!=null&&c(g.Condition),c(g.Body)});else throw`unreachable, type: ${o.Type}: ${o}`}t(o)}},s=function(o){if(!e(o)){if(o.Type=="StatList")o.StatementList.forEach((g,L)=>{if(g!=null){if(g===null||g.Type===null)return;g.Remove=()=>{o.StatementList[L]=null},s(g)}});else if(o.Type!="BreakStat"){if(o.Type!="ContinueStat"){if(o.Type!="GotoStat"){if(o.Type!="LabelStat")if(o.Type=="ReturnStat")o.ExprList.forEach((g,L)=>{c(g)});else if(o.Type=="LocalVarStat")o.Token_Equals&&o.ExprList.forEach((g,L)=>{c(g)});else if(o.Type=="LocalFunctionStat")s(o.FunctionStat.Body);else if(o.Type=="FunctionStat")s(o.Body);else if(o.Type=="RepeatStat")s(o.Body),c(o.Condition);else if(o.Type=="GenericForStat")o.GeneratorList.forEach((g,L)=>{c(g)}),s(o.Body);else if(o.Type=="NumericForStat")o.RangeList.forEach((g,L)=>{c(g)}),s(o.Body);else if(o.Type=="WhileStat")c(o.Condition),s(o.Body);else if(o.Type=="DoStat")s(o.Body);else if(o.Type=="IfStat")c(o.Condition),s(o.Body),o.ElseClauseList.forEach(g=>{g.Condition!=null&&c(g.Condition),s(g.Body)});else if(o.Type=="CallExprStat")c(o.Expression);else if(o.Type=="CompoundStat")c(o.Lhs),c(o.Rhs);else if(o.Type=="AssignmentStat")o.Lhs.forEach(g=>{c(g)}),o.Rhs.forEach(g=>{c(g)});else throw"Unreachable code. Got "+o.Type}}}t(o)}},u.VisitStat=s,u.VisitExpr=c,n[k.Type]?s(k):c(k)}function Nn(k){let u=[],d,n=0;function i(){return n++,n}function l(){d={ParentScope:d,ChildScopeList:[],VariableList:[],BeginLocation:i(),Depth:null,GetVar:null},d.ParentScope?(d.Depth=d.ParentScope.Depth+1,d.ParentScope.ChildScopeList.push(d)):d.Depth=1;let a=d;d.GetVar=function(p){for(let m of a.VariableList)if(m.Name==p)return m;if(a.ParentScope)return a.ParentScope.GetVar(p);for(let m of u)if(m.Name==p)return m}}function e(){let a=d;return a.EndLocation=i(),a.VariableList.forEach(p=>{p.ScopeEndLocation=a.EndLocation}),d=a.ParentScope,a}l();function t(a,p,m){J(m,"Missing localInfo"),J(a,"Missing local var name");let S={Type:"Local",Name:a,RenameList:[p],AssignedTo:!1,Info:m,Scope:d,BeginLocation:i(),EndLocation:i(),ReferenceLocationList:[i()]};return S.Rename=function(w){S.Name=w,S.RenameList.forEach(F=>{F(w)})},d.VariableList.push(S),S}function c(a){for(let m of u)if(m.Name==a)return m;let p={Type:"Global",Name:a,RenameList:[],AssignedTo:!1,Scope:null,BeginLocation:i(),EndLocation:i(),ReferenceLocationList:[]};return p.Rename=function(m){p.Name=m,p.RenameList.forEach(S=>{S(m)})},u.push(p),p}function s(a,p){J(a,"Missing var name");let m=c(a);return m.RenameList.push(p),m}function o(a,p){let m;for(m=a.VariableList.length-1;m>=0;m--)if(a.VariableList[m].Name==p)return a.VariableList[m];if(a.ParentScope){let S=o(a.ParentScope,p);if(S)return S}}function g(a,p){J(a,"Missing var name");let m=o(d,a);m?m.RenameList.push(p):m=s(a,p);let S=i();return m.EndLocation=S,m.ReferenceLocationList.push(m.EndLocation),m}let L={};return L.FunctionLiteral={Pre:function(a){l(),a.ArgList.forEach((p,m)=>{let S=t(p.Source,function(w,F){F||(p.Source=w)},{Type:"Argument",Index:m});p.var=S})},Post:function(a){e()}},L.VariableExpr=function(a){a.Variable=g(a.Token.Source,function(p,m=!1){m&&a.IsStat||(a.Token.Source=p)})},L.StatList={Pre:function(a){l()},Post:function(a){a.SkipPop||e()}},L.LocalVarStat={Post:function(a){a.VarList.forEach((p,m)=>{t(p.Source,function(S){a.VarList[m].Source=S},{Type:"Local",Expr:a.ExprList})})}},L.LocalFunctionStat={Pre:function(a){t(a.FunctionStat.NameChain[0].Source,function(p){a.FunctionStat.NameChain[0].Source=p},{Type:"LocalFunction"}),l(),a.FunctionStat.ArgList.forEach((p,m)=>{t(p.Source,function(S){p.Source=S},{Type:"Argument",Index:m})})},Post:function(){e()}},L.FunctionStat={Pre:function(a){let p=a.NameChain,m;p.length==1?o(d,p[0].Source)?m=g(p[0].Source,function(S){p[0].Source=S}):m=s(p[0].Source,function(S){p[0].Source=S}):m=g(p[0].Source,function(S){p[0].Source=S}),m.AssignedTo=!0,l(),a.ArgList.forEach((S,w)=>{t(S.Source,function(F){S.Source=F},{Type:"Argument",Index:w})})},Post:function(){e()}},L.GenericForStat={Pre:function(a){return a.GeneratorList.forEach(p=>{ke(p,L)}),l(),a.VarList.forEach((p,m)=>{t(p.Source,function(S){p.Source=S},{Type:"ForRange",Index:m})}),ke(a.Body,L),e(),!0}},L.NumericForStat={Pre:function(a){return a.RangeList.forEach(p=>{ke(p,L)}),l(),a.VarList.forEach((p,m)=>{t(p.Source,function(S){p.Source=S},{Type:"ForRange",Index:m})}),ke(a.Body,L),e(),!0}},L.RepeatStat={Pre:function(a){a.Body.SkipPop=!0},Post:function(a){e()}},L.AssignmentStat={Post:function(a){a.Lhs.forEach(p=>{p.Variable!=null&&(p.Variable.AssignedTo=!0)})}},ke(k,L),[u,e()]}function Vn(k){let u,d,n="",i=e=>typeof e?.LeadingWhite!="string"?" ":e.LeadingWhite;function l(e){if(e.LeadingWhite==null||e.Source==null)throw`Bad token: tk=${e} | lwhite=${e.LeadingWhite} | source=${e.Source}`;n=`${n}${e.LeadingWhite}${e.Source}`}return d=function(e){if(e.Type=="BinopExpr")d(e.Lhs),l(e.Token_Op),d(e.Rhs);else if(e.Type=="UnopExpr")l(e.Token_Op),d(e.Rhs);else if(e.Type=="NumberLiteral"||e.Type=="StringLiteral"||e.Type=="NilLiteral"||e.Type=="BooleanLiteral"||e.Type=="VargLiteral"||e.Type=="HashLiteral")l(e.Token);else if(e.Type=="FieldExpr")d(e.Base),l(e.Token_Dot),l(e.Field);else if(e.Type=="IndexExpr")d(e.Base),l(e.Token_OpenBracket),d(e.Index),l(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")d(e.Base),e.Type=="MethodExpr"&&(l(e.Token_Colon),l(e.Method)),e.FunctionArguments.CallType=="StringCall"?l(e.FunctionArguments.Token):e.FunctionArguments.CallType=="ArgCall"?(l(e.FunctionArguments.Token_OpenParen),e.FunctionArguments.ArgList.forEach((t,c)=>{d(t);let s=e.FunctionArguments.Token_CommaList[c];s!=null&&l(s)}),l(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&d(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")l(e.Token_Function),l(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{l(t);let s=e.Token_ArgCommaList[c];s!=null&&l(s)}),e.Token_Varg!=null&&l(e.Token_Varg),l(e.Token_CloseParen),u(e.Body),l(e.Token_End);else if(e.Type=="VariableExpr")l(e.Token);else if(e.Type=="ParenExpr")l(e.Token_OpenParen),d(e.Expression),l(e.Token_CloseParen);else if(e.Type=="TableLiteral")l(e.Token_OpenBrace),e.EntryList.forEach((t,c)=>{if(t.EntryType=="Field")l(t.Field),l(t.Token_Equals),d(t.Value);else if(t.EntryType=="Index")l(t.Token_OpenBracket),d(t.Index),l(t.Token_CloseBracket),l(t.Token_Equals),d(t.Value);else if(t.EntryType=="Value")d(t.Value);else throw"unreachable";let s=e.Token_SeperatorList[c];s!=null&&l(s)}),l(e.Token_CloseBrace);else if(e.Type=="CompoundStat")u(e);else if(e.Type=="IfExpr")l(e.Token_If),d(e.Condition),l(e.Token_Then),d(e.Body),e.ElseClauseList.forEach(t=>{l(t.Token),t.Condition!=null&&(d(t.Condition),l(t.Token_Then)),d(t.Body)});else throw`unreachable, type: ${e.Type}: ${e}`},u=function(e){if(e==null)throw`STAT IS NIL! ${e}`;if(!(e.Type==="StatList"&&e.StatementList.length===0)){if(e.WrapInDo){let t=i(e.GetFirstToken());e.GetFirstToken().LeadingWhite="",n+=`${t}do `}e.Type=="StatList"?e.StatementList.forEach((t,c)=>{t===null||t.Type===null||(t.Remove=()=>{e.StatementList[c]=null},u(t),e.SemicolonList[c]&&l(e.SemicolonList[c]))}):e.Type=="BreakStat"?l(e.Token_Break):e.Type=="ContinueStat"?l(e.Token_Continue):e.Type=="GotoStat"?(l(e.Token_Goto),l(e.Token_Label)):e.Type=="LabelStat"?(l(e.Token_ColonsLeft),l(e.Token_Label),l(e.Token_ColonsRight)):e.Type=="ReturnStat"?(l(e.Token_Return),e.ExprList.forEach((t,c)=>{d(t),e.Token_CommaList[c]&&l(e.Token_CommaList[c])})):e.Type=="LocalVarStat"?(l(e.Token_Local),e.VarList.forEach((t,c)=>{l(t),t.Attribute!=null&&l(t.Attribute);let s=e.Token_VarCommaList[c];s!=null&&l(s)}),e.Token_Equals!=null&&(l(e.Token_Equals),e.ExprList.forEach((t,c)=>{d(t);let s=e.Token_ExprCommaList[c];s!=null&&l(s)}))):e.Type=="LocalFunctionStat"?(l(e.Token_Local),l(e.FunctionStat.Token_Function),l(e.FunctionStat.NameChain[0]),l(e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((t,c)=>{l(t);let s=e.FunctionStat.Token_ArgCommaList[c];s!=null&&l(s)}),e.FunctionStat.Token_Varg&&l(e.FunctionStat.Token_Varg),l(e.FunctionStat.Token_CloseParen),u(e.FunctionStat.Body),l(e.FunctionStat.Token_End)):e.Type=="FunctionStat"?(l(e.Token_Function),e.NameChain.forEach((t,c)=>{l(t);let s=e.Token_NameChainSeperator[c];s!=null&&l(s)}),l(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{l(t);let s=e.Token_ArgCommaList[c];s!=null&&l(s)}),e.Token_Varg&&l(e.Token_Varg),l(e.Token_CloseParen),u(e.Body),l(e.Token_End)):e.Type=="RepeatStat"?(l(e.Token_Repeat),u(e.Body),l(e.Token_Until),d(e.Condition)):e.Type=="GenericForStat"?(l(e.Token_For),e.VarList.forEach((t,c)=>{l(t);let s=e.Token_VarCommaList[c];s!=null&&l(s)}),l(e.Token_In),e.GeneratorList.forEach((t,c)=>{d(t);let s=e.Token_GeneratorCommaList[c];s!=null&&l(s)}),l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="NumericForStat"?(l(e.Token_For),e.VarList.forEach((t,c)=>{l(t);let s=e.Token_VarCommaList[c];s!=null&&l(s)}),l(e.Token_Equals),e.RangeList.forEach((t,c)=>{d(t);let s=e.Token_RangeCommaList[c];s!=null&&l(s)}),l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="WhileStat"?(l(e.Token_While),d(e.Condition),l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="DoStat"?(l(e.Token_Do),u(e.Body),l(e.Token_End)):e.Type=="IfStat"?(l(e.Token_If),d(e.Condition),l(e.Token_Then),u(e.Body),e.ElseClauseList.forEach(t=>{l(t.Token),t.Condition!=null&&(d(t.Condition),l(t.Token_Then)),u(t.Body)}),l(e.Token_End)):e.Type=="CallExprStat"?d(e.Expression):e.Type=="CompoundStat"?(d(e.Lhs),l(e.Token_Compound),d(e.Rhs),e.Type="CompoundStat"):e.Type=="AssignmentStat"?(e.Lhs.forEach((t,c)=>{d(t);let s=e.Token_LhsSeperatorList[c];s!=null&&l(s)}),l(e.Token_Equals),e.Rhs.forEach((t,c)=>{d(t);let s=e.Token_RhsSeperatorList[c];s!=null&&l(s)})):J(!1,"unreachable"),e.WrapInDo&&(n+=" end ")}},u(k),n}function vn(k){let u,d;function n(e){e&&(e.LeadingWhite="")}function i(e,t,c=!1){n(t);let s=(typeof e.Source=="string"?e.Source:e.Source.toString()).substr(e.Source.length-1,1),o=(typeof t.Source=="string"?t.Source:t.Source.toString()).substr(0,1);s=="-"&&o=="-"||Pe.includes(s)&&Pe.includes(o)||c&&s==")"&&o=="("?t.LeadingWhite=c?";":" ":t.LeadingWhite=""}function l(e,t,c){u(t),n(c);let s=t.GetFirstToken(),o=t.GetLastToken();s!=null?(i(e,s),i(o,c)):i(e,c)}d=function(e){if(e.Type==="BinopExpr")d(e.Lhs),d(e.Rhs),e.Lhs.Type=="NumberLiteral"&&e.Token_Op.Source==".."?e.Token_Op.LeadingWhite=" ":(n(e.Token_Op),i(e.Lhs.GetLastToken(),e.Token_Op)),i(e.Token_Op,e.Rhs.GetFirstToken());else if(e.Type==="UnopExpr")n(e.Token_Op),d(e.Rhs),i(e.Token_Op,e.Rhs.GetFirstToken());else if(e.Type==="NumberLiteral"||e.Type==="StringLiteral"||e.Type==="NilLiteral"||e.Type==="BooleanLiteral"||e.Type==="VargLiteral"||e.Type==="HashLiteral")n(e.Token);else if(e.Type=="FieldExpr")d(e.Base),n(e.Token_Dot),n(e.Field);else if(e.Type=="IndexExpr")d(e.Base),n(e.Token_OpenBracket),d(e.Index),n(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")d(e.Base),e.Type=="MethodExpr"&&(n(e.Token_Colon),n(e.Method)),e.FunctionArguments.CallType=="StringCall"?n(e.FunctionArguments.Token):e.FunctionArguments.CallType=="ArgCall"?(n(e.FunctionArguments.Token_OpenParen),e.FunctionArguments.ArgList.forEach((t,c)=>{d(t);let s=e.FunctionArguments.Token_CommaList[c];s!=null&&n(s)}),n(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&d(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")n(e.Token_Function),n(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{n(t);let s=e.Token_ArgCommaList[c];s!=null&&n(s)}),e.Token_Varg!=null&&n(e.Token_Varg),n(e.Token_CloseParen),l(e.Token_CloseParen,e.Body,e.Token_End);else if(e.Type=="VariableExpr")n(e.Token);else if(e.Type=="ParenExpr")n(e.Token_OpenParen),d(e.Expression),n(e.Token_CloseParen);else if(e.Type=="IfExpr"){n(e.Token_If),d(e.Condition),i(e.Token_If,e.Condition.GetFirstToken()),i(e.Condition.GetLastToken(),e.Token_Then);let t=e.Token_Then,c=e.Body;e.ElseClauseList.forEach((s,o)=>{i(t,c.GetFirstToken()),i(c.GetLastToken(),s.Token),t=s.Token,s.Condition!=null&&(d(s.Condition),i(s.Token,s.Condition.GetFirstToken()),i(s.Condition.GetLastToken(),s.Token_Then),t=s.Token_Then),d(s.Body),c=s.Body}),i(t,c.GetFirstToken())}else if(e.Type=="TableLiteral")n(e.Token_OpenBrace),e.EntryList.forEach((t,c)=>{t.EntryType=="Field"?(n(t.Field),n(t.Token_Equals),d(t.Value)):t.EntryType=="Index"?(n(t.Token_OpenBracket),d(t.Index),n(t.Token_CloseBracket),n(t.Token_Equals),d(t.Value)):t.EntryType=="Value"?d(t.Value):J(!1,"unreachable");let s=e.Token_SeperatorList[c];s!=null&&n(s)}),e.Token_SeperatorList[e.EntryList.length-1]=null,n(e.Token_CloseBrace);else throw`unreachable, type: ${e.Type}:${e} ${console.trace()}`},u=function(e){if(e.Type=="StatList"){let t;for(t=0;t<=e.StatementList.length;t++){let c=e.StatementList[t];if(c==null)continue;u(c),n(c.GetFirstToken());let s=e.StatementList[t-1];if(s!=null){let o={")":["(","["],"]":["(","["]};if(e.SemicolonList[t-1]){let g=s.GetLastToken().Source,L=c.GetFirstToken().Source;(o[g]===null||o[g]===void 0||!o[g].includes(L))&&(e.SemicolonList[t-1]=null)}e.SemicolonList[t-1]||i(s.GetLastToken(),c.GetFirstToken(),!0)}}e.SemicolonList[e.StatementList.length-1]=null,e.StatementList.length>0&&n(e.StatementList[0].GetFirstToken())}else if(e.Type=="BreakStat")n(e.Token_Break);else if(e.Type=="ContinueStat")n(e.Token_Continue);else if(e.Type=="GotoStat")n(e.Token_Goto),i(e.Token_Goto,e.Token_Label);else if(e.Type=="LabelStat")n(e.Token_ColonsLeft),n(e.Token_Label),n(e.Token_ColonsRight);else if(e.Type=="ReturnStat")n(e.Token_Return),e.ExprList.forEach((t,c)=>{d(t),e.Token_CommaList[c]!=null&&n(e.Token_CommaList[c])}),e.ExprList.length>0&&i(e.Token_Return,e.ExprList[0].GetFirstToken());else if(e.Type=="LocalVarStat"){n(e.Token_Local);let t=!1;e.VarList.forEach((c,s)=>{s==0?i(e.Token_Local,c):n(c),c.Attribute&&(n(c.Attribute),s+1==e.VarList.length&&(t=!0));let o=e.Token_VarCommaList[s];o!=null&&n(o)}),e.Token_Equals!=null&&(t||n(e.Token_Equals),e.ExprList.forEach((c,s)=>{d(c);let o=e.Token_ExprCommaList[s];o!=null&&n(o)}))}else if(e.Type=="LocalFunctionStat")n(e.Token_Local),i(e.Token_Local,e.FunctionStat.Token_Function),i(e.FunctionStat.Token_Function,e.FunctionStat.NameChain[0]),i(e.FunctionStat.NameChain[0],e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((t,c)=>{n(t);let s=e.FunctionStat.Token_ArgCommaList[c];s!=null&&n(s)}),e.FunctionStat.Token_Varg&&n(e.FunctionStat.Token_Varg),n(e.FunctionStat.Token_CloseParen),l(e.FunctionStat.Token_CloseParen,e.FunctionStat.Body,e.FunctionStat.Token_End);else if(e.Type=="FunctionStat")n(e.Token_Function),e.NameChain.forEach((t,c)=>{c==0?i(e.Token_Function,t):n(t);let s=e.Token_NameChainSeperator[c];s!=null&&n(s)}),n(e.Token_OpenParen),e.ArgList.forEach((t,c)=>{n(t);let s=e.Token_ArgCommaList[c];s!=null&&n(s)}),e.Token_Varg&&n(e.Token_Varg),n(e.Token_CloseParen),l(e.Token_CloseParen,e.Body,e.Token_End);else if(e.Type=="RepeatStat")n(e.Token_Repeat),l(e.Token_Repeat,e.Body,e.Token_Until),d(e.Condition),i(e.Token_Until,e.Condition.GetFirstToken());else if(e.Type=="GenericForStat")n(e.Token_For),e.VarList.forEach((t,c)=>{c==0?i(e.Token_For,t):n(t);let s=e.Token_VarCommaList[c];s!=null&&n(s)}),i(e.VarList[e.VarList.length-1],e.Token_In),e.GeneratorList.forEach((t,c)=>{d(t),c==0&&i(e.Token_In,t.GetFirstToken());let s=e.Token_GeneratorCommaList[c];s!=null&&n(s)}),i(e.GeneratorList[e.GeneratorList.length-1].GetLastToken(),e.Token_Do),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="NumericForStat")n(e.Token_For),e.VarList.forEach((t,c)=>{c==0?i(e.Token_For,t):n(t);let s=e.Token_VarCommaList[c];s!=null&&n(s)}),i(e.VarList[e.VarList.length-1],e.Token_Equals),e.RangeList.forEach((t,c)=>{d(t),c==0&&i(e.Token_Equals,t.GetFirstToken());let s=e.Token_RangeCommaList[c];s!=null&&n(s)}),i(e.RangeList[e.RangeList.length-1].GetLastToken(),e.Token_Do),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="WhileStat")n(e.Token_While),d(e.Condition),n(e.Token_Do),i(e.Token_While,e.Condition.GetFirstToken()),i(e.Condition.GetLastToken(),e.Token_Do),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="DoStat")n(e.Token_Do),n(e.Token_End),l(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="IfStat"){n(e.Token_If),d(e.Condition),i(e.Token_If,e.Condition.GetFirstToken()),i(e.Condition.GetLastToken(),e.Token_Then);let t=e.Token_Then,c=e.Body;e.ElseClauseList.forEach((s,o)=>{l(t,c,s.Token),t=s.Token,s.Condition!=null&&(d(s.Condition),i(s.Token,s.Condition.GetFirstToken()),i(s.Condition.GetLastToken(),s.Token_Then),t=s.Token_Then),u(s.Body),c=s.Body}),l(t,c,e.Token_End)}else if(e.Type=="CallExprStat")d(e.Expression);else if(e.Type=="CompoundStat")d(e.Lhs),n(e.Token_Compound),d(e.Rhs),i(e.Lhs.GetLastToken(),e.Token_Compound),i(e.Token_Compound,e.Rhs.GetFirstToken());else if(e.Type=="AssignmentStat")e.Lhs.forEach((t,c)=>{d(t);let s=e.Token_LhsSeperatorList[c];s!=null&&n(s)}),n(e.Token_Equals),e.Rhs.forEach((t,c)=>{d(t);let s=e.Token_RhsSeperatorList[c];s!=null&&n(s)});else return d(e)},u(k)}var se=[],v;for(v=97;v<=122;v++)se.push(String.fromCharCode(v));for(v=65;v<=90;v++)se.push(String.fromCharCode(v));for(v=48;v<=57;v++)se.push(String.fromCharCode(v));se.push("_");var Le=[];for(v=97;v<=122;v++)Le.push(String.fromCharCode(v));for(v=65;v<=90;v++)Le.push(String.fromCharCode(v));function He(k){let u="",d=k%Le.length;for(k=(k-d)/Le.length,u=`${u}${Le[d]}`;k>0;){let n=k%se.length;k=(k-n)/se.length,u=`${u}${se[n]}`}return u}function jn(k,u,d){let n=[];for(var[i,l]of Object.entries(Ze))n[i]=!0;let e=[],t=[];k.forEach(L=>{L.AssignedTo&&d?e.push(L):n[L.Name]=!0});function c(L){L.VariableList.forEach(a=>{e.push(a),t.push(a)}),L.ChildScopeList.forEach(a=>{c(a)})}c(u),e.forEach(L=>{L.UsedNameArray=[]}),e.sort((L,a)=>L-a);let s=0,o=[];function g(L){let a=o[L];if(a==null){for(a=He(s),s++;n[a];)a=He(s),s++;o[L]=a}return a}e.forEach((L,a)=>{L.Renamed=!0;let p=0;for(;L.UsedNameArray[p];)p++;L.Rename(g(p)),L.Scope?e.forEach(m=>{m.Renamed||(!m.Scope||m.Scope.Depth<L.Scope.Depth?m.ReferenceLocationList.some(S=>S>=L.BeginLocation&&S<=L.ScopeEndLocation?(m.UsedNameArray[p]=!0,!0):!1):m.Scope.Depth>L.Scope.Depth?L.ReferenceLocationList.some(S=>S>=m.BeginLocation&&S<=m.ScopeEndLocation?(m.UsedNameArray[p]=!0,!0):!1):L.BeginLocation<m.EndLocation&&L.EndLocation>m.BeginLocation&&(m.UsedNameArray[p]=!0))}):e.forEach(m=>{if(!m.Renamed)if(m.Type=="Global")m.UsedNameArray[p]=!0;else if(m.Type=="Local")L.ReferenceLocationList.some(S=>S>=m.BeginLocation&&S<=m.ScopeEndLocation?(m.UsedNameArray[p]=!0,!0):!1);else throw"Unreachable"})})}var Qe={};Qe.Minify=function(k,u){let d=Pn(k),[n,i]=Nn(d);u.RenameVariables==!0&&jn(n,i,u.RenameGlobals),u.SolveMath==!0&&SolveMath(d),vn(d);let l=Vn(d);return l=`${l}`,l};try{Ge!=null&&Ge.exports!=null&&(Ge.exports.Minify=Qe.Minify)}catch{}});var en=re((gt,Ye)=>{var Ne=require("fs-extra"),On=require("path");function Dn(k,u,d,n,i=!1){let l=["fxmanifest.lua","__resource.lua"],e=null;for(let m of l){let S=On.join(k,m);if(Ne.existsSync(S)){e=S;break}}if(!e){console.log("\x1B[33m! No fxmanifest.lua or __resource.lua found. Skipping manifest injection.\x1B[0m");return}let t=Ne.readFileSync(e,"utf8"),c=!1,s=(m,S)=>{let w=m.replace("_scripts","_script").replace("files","file"),F=m,$=new RegExp(`^\\s*${F}\\s*\\{`,"m"),G=t.match($);if(G){let N=G.index,V=t.indexOf("}",N),j=V!==-1?t.substring(N,V):t.substring(N);if(j.includes(`'ltbridge/modules/${S}'`)||j.includes(`"ltbridge/modules/${S}"`))return;let D=`${G[0]}
11
- 'ltbridge/modules/${S}',`;t=t.replace(G[0],D),c=!0;return}let A=new RegExp(`^\\s*${w}\\s+(['"].+?['"])`,"m"),R=t.match(A);if(R){if(R[0].includes(`'ltbridge/modules/${S}'`)||R[0].includes(`"ltbridge/modules/${S}"`))return;let N=R[1],V=`${F} {
12
- 'ltbridge/modules/${S}',
13
- ${N}
14
- }`;t=t.replace(R[0],V),c=!0;return}t+=`
2
+ var H=(d,s)=>()=>(s||d((s={exports:{}}).exports,s),s.exports);var Fe=H((jt,xn)=>{xn.exports={name:"@laot/bridge",version:"1.1.0",description:"LTBridge CLI for fetching and bundling FiveM modules.",license:"MIT",repository:{type:"git",url:"https://github.com/laot7490/ltbridge.git"},author:"laot",keywords:["fivem","lua","bridge","module-manager","bundler","cli","gta5","redm","laot","ltbridge"],main:"dist/ltbridge.js",scripts:{build:"node scripts/compiler.js && esbuild bin/ltbridge.js --bundle --minify --platform=node --target=node18 --packages=external --outfile=dist/ltbridge.js",zip:"node scripts/zip-dist.js",prepublishOnly:"npm run build && npm run zip"},bin:{ltbridge:"./dist/ltbridge.js"},files:["dist","LICENSE","README.md"],dependencies:{chokidar:"^5.0.0",commander:"^11.0.0","fs-extra":"^11.1.1",prompts:"^2.4.2"},devDependencies:{esbuild:"^0.25.0"}}});var Ke=H((Dt,Ue)=>{var Bn=/__LT_VERSION\s*=\s*'[^']*'/g,Gn=/__LT_DISABLE_DEBUG\s*=\s*(true|false)/g;function $n(d,{version:s,disableDebug:u}={}){if(!d)return d;let n=d;return s&&(n=n.replace(Bn,`__LT_VERSION = '${s}'`)),u!==void 0&&(n=n.replace(Gn,`__LT_DISABLE_DEBUG = ${u?"true":"false"}`)),n}Ue.exports={applyBuildConstants:$n}});var oe=H((qt,He)=>{var ze=require("fs"),Rn=require("path"),we=null;function Ae(){if(we)return we;let d=Rn.join(__dirname,"..","dist","modules.dat");return ze.existsSync(d)||(console.log("\x1B[31m\u2716 LTBridge is not compiled. Please run 'npm run build' first.\x1B[0m"),process.exit(1)),we=JSON.parse(ze.readFileSync(d,"utf8")),we}function An(){return Ae().registry}function In(d){return Ae().modules[d]}He.exports={getModuleRegistry:An,getDatabase:Ae,getModuleData:In}});var Ie=H((Wt,Ze)=>{var{getModuleData:Pn}=oe();function Je(d){let s=Pn(d);if(!s)return!1;for(let u of["shared","client","server"])if(s[u]&&s[u].stubs&&s[u].stubs.some(n=>n.metadata&&n.metadata.global))return!0;return!1}function Mn(d,s){if(!s||s.length===0)return null;if(s.length===1)return s[0];if(d.includes(".")){let n=d.split(".")[0].toLowerCase(),t=s.find(i=>i.toLowerCase().includes(n));if(t)return t}return s.find(n=>Je(n))||s[0]}Ze.exports={pickExportModule:Mn,moduleHasGlobalStub:Je}});var xe=H((Ut,Qe)=>{var{getModuleRegistry:Nn,getModuleData:Vn}=oe(),{pickExportModule:vn}=Ie();function On(d,s){let u=Nn(),n=Object.keys(u),t=new Set,i=new Set,e=[],o={};function c(l,m){let h=Vn(l);if(!h)return[];if(h.meta&&Array.isArray(h.meta.dependencies))return h.meta.dependencies;let f=new Set,p="";["shared","client","server"].forEach(x=>{h[x]&&h[x].code&&(p+=h[x].code+`
3
+ `)});let g=/(?:^|[^a-zA-Z0-9_.:"'\]])(LT\.[a-zA-Z0-9_.]+)/g,_;for(;(_=g.exec(p))!==null;){let $=_[1].substring(3).split("."),I="";for(let q of $){I=I?I+"."+q:q;let v="@"+I.replace(/\./g,"/"),O=I.replace(/\./g,"/");if(n.includes(v)&&v!==l?f.add(v):n.includes(O)&&O!==l?f.add(O):n.includes(I)&&I!==l&&f.add(I),m&&m[I]){let K=vn(I,m[I]);K&&K!==l&&f.add(K)}}}let w=u[l];if(w){let $=w.replace(/\\/g,"/").split("/");for(;$.length>1;){$.pop();let I=$[$.length-1],q=I,v="@"+I;l!==q&&n.includes(q)&&f.add(q),l!==v&&n.includes(v)&&f.add(v)}}return Array.from(f)}function a(l){if(t.has(l))return;if(i.has(l)){console.log(`
4
+ \x1B[33m! Circular dependency detected involving '${l}'.\x1B[0m`);return}if(i.add(l),!u[l]){console.log(`\x1B[31m\u2716 Trying to resolve '${l}' but it does not exist in LTBridge.\x1B[0m`),i.delete(l);return}let m=c(l,s);o[l]=m;for(let h of m)a(h);i.delete(l),t.add(l),e.push(l)}for(let l of d)a(l);return{sequence:e,graph:o}}Qe.exports={resolveDependencies:On}});var on=H((Kt,Be)=>{var ke=console.log,U=function(d,s){if(!d)throw s};function jn(d,s){if(!d)return 0;var u=d.toString().split(".");return u.length>1?parseInt(u[0],s)+parseInt(u[1],s)/Math.pow(s,u[1].length):parseInt(u[0],s)}var Dn=[" ",`
5
+ `," ","\r"],qn={r:"\r",n:`
6
+ `,t:" ",'"':'"',"'":"'","\\":"\\"},Xe=new Proxy(qn,{get(d,s){return jn(s)}}),Wn=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","_","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],Me=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","_","a","b","c","d","e","f","g","t","u","v","w","h","i","j","k","l","m","n","o","p","q","r","s","x","y","z"],pe=["0","1","2","3","4","5","6","7","8","9"],Un=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","A","B","C","D","E","F"],Kn=["+","-","*",")",";","/","^","%","#",",","{","}",":","[","]","(",".","`"],zn=["~","=",">","<"],Hn=["+","-","*","/","^","..","%","//"],Jn=["+=","-=","*=","/=","^=","..=","%=","//="],en=["and","break","do","else","elseif","end","false","for","function","goto","if","in","local","nil","not","or","repeat","return","then","true","until","while","continue"],he=["continue","goto"],Zn=["else","elseif","until","end"],Qn=["-","not","#","~"],nn=["+","-","*","/","%","^","#","//","&","|","~","<<",">>","..",".",":",">","<","<=",">=","~=","==","+=","-=","*=","/=","%=","^=","..=","//=","and","or"],Xn=11,Pe={"^":[13,12],"%":[10,10],"//":[10,10],"/":[10,10],"*":[10,10],"+":[9,9],"-":[9,9],"..":[8,7],">>":[7,7],"<<":[7,7],"&":[6,6],"~":[5,5],"|":[4,4],"==":[3,3],"~=":[3,3],">=":[3,3],"<=":[3,3],">":[3,3],"<":[3,3],"+=":[3,3],"-=":[3,3],"*=":[3,3],"/=":[3,3],"^=":[3,3],"%=":[3,3],"..=":[3,3],"//=":[3,3],and:[2,2],or:[1,1]};function Yn(d){let s=0,u=d.length,n=[];function t(f){return f=f||0,s<=u?d.substr(s+f,1):""}function i(){if(s<=u){let f=d.substr(s,1);return s++,f}else return""}function e(f){let p=0,g=1,_=1;for(;p<=s;)d.substr(p,1)==`
7
+ `?(g++,_=1):_++;let w;for(w=0;w<n.length;w++){let x=n[w];ke(`${x.Type}<${x.Source}>`)}throw`file<${g}:${_}>: ${f}`}function o(f){for(;;){let p=i();if(p=="")e("Unfinished long string.");else if(p=="]"){let g=!0,_;for(_=1;_<=f;_++)if(t()=="=")s++;else{g=!1;break}if(g&&i()=="]")return}}}function c(){let f=s;for(;t()=="=";)s++;if(t()=="[")return s++,s-f-1;s=f}let a=0,l=0,m=0;function h(f){m++;let p=d.substr(l,s-l),g=null;f=="Number"&&(p=p.replace(/[\_]+/g,""),p.substr(0,2).toLowerCase()=="0x"?(g="hex",parseInt(p,16)<999999999999&&(p=parseInt(p,16))):p.substr(0,2).toLowerCase()=="0b"&&(g="bin",parseInt(p.substr(2),2)<999999999999&&(p=parseInt(p.substr(2),2))));let _={Type:f,LeadingWhite:d.substr(a,l-a),Source:p};return g!==null&&(_.NType=g),n.push(_),a=s,l=s,_}for(;;){for(a=s;;){let p=t();if(p=="")break;if(p=="-")if(t(1)=="-")if(s+=2,t()=="["){s++;let g=c();if(g!=null)o(g),a=s;else for(;;){let _=i();if(_==""||_==`
8
+ `)break}}else for(;;){let g=i();if(g==""||g==`
9
+ `)break}else break;else if(Dn.includes(p))s++;else break}l=s;let f=i();if(f==""){h("Eof");break}else if(f=="'"||f=='"'){for(;;){let p=i();if(p=="\\"){let g=i();if(Xe[g]==null)throw`Invalid Escape Sequence \`${g}\`.`}else{if(p==f)break;if(p=="")throw"Unfinished string!"}}h("String")}else if(f=="`"){for(;;){let p=i();if(p=="\\"){let g=i();if(Xe[g]==null)throw`Invalid Escape Sequence \`${g}\`.`}else{if(p==f)break;if(p=="")throw"Unfinished string!"}}h("Hash")}else if(Wn.includes(f)){for(;Me.includes(t());)s++;en.includes(d.substr(l,s-l))?h("Keyword"):h("Ident")}else if(pe.includes(f)||f=="."&&pe.includes(t())){if(f=="0"&&t().toLowerCase()=="x")for(s++;Un.includes(t())||t()==="_";)s++;else if(f=="0"&&t().toLowerCase()=="b")for(s++;t()==="0"||t()==="1"||t()==="_";)s++;else{for(;pe.includes(t())||t()==="_";)s++;if(t()==".")for(s++;pe.includes(t());)s++;if(t()=="e"||t()=="E")for(s++,(t()=="-"||t()=="+")&&s++;pe.includes(t());)s++}h("Number")}else if(f=="["){let p=c();p!=null?(o(p),h("String")):h("Symbol")}else if(f==".")t()=="."&&(i(),(t()=="."||t()=="=")&&i()),h("Symbol");else if(f+t()=="//")i(),t()=="="&&i(),h("Symbol");else if(f+t()=="::")i(),h("Symbol");else if(nn.includes(f+t()))i(),h("Symbol");else if(zn.includes(f))t()=="="&&s++,h("Symbol");else if(Hn.includes(f)&&t()=="=")i(),h("Symbol");else if(Kn.includes(f))h("Symbol");else throw`Bad symbol \`${f}\` in source. ${s}`}return n}function et(d){let s=Yn(d),u=0;function n(){let k=s[u];return u<s.length&&u++,k}function t(k){return k=u+(k||0),s[k]||s[s.length-1]}function i(k){let L=1,r=0,T=0;for(;;){let S=s[T],b;S==k?b=S.LeadingWhite:b=S.LeadingWhite+S.Source;let y;for(y=0;y<=b.length;y++)b.substr(y,1)==`
10
+ `?(L++,r=0):r++;if(S==k)break;T++}return`${L}:${r+1}`}function e(){let k=t();return`<${k.Type} \`${k.Source}\`> at: ${i(k)}`}function o(){let k=t();return k.Type=="Eof"||k.Type=="Keyword"&&Zn.includes(k.Source)}function c(){return Qn.includes(t().Source)||!1}function a(){return nn.includes(t().Source)||!1}function l(k,L){let r=t();if(r.Type==k&&(L==null||r.Source==L))return n();if(r.Type=="Keyword"&&k=="Ident"&&he.includes(r.Source)&&(L==null||r.Source==L))return n();{let T;for(T=-3;T<=3;T++)ke(`Tokens[${T}] = \`${t(T).Source}\``);throw L?`${i(r)}: \`${L}\` expected.`:`${i(r)}: ${k} expected.`}}function m(k){let L=k.GetFirstToken,r=k.GetLastToken,T=k;return k.GetFirstToken=function(){let S=L(T);return U(S),S},k.GetLastToken=function(){let S=r(T);return U(S),S},k}let h,f;function p(k,L){let r=[f(k,L)],T=[];for(;t().Source==",";)T.push(n()),r.push(f(k,L));return[r,T]}function g(k,L){let r=t();if(r.Source=="("){let T=n(),S=f(k,L),b=l("Symbol",")"),y;return y=m({Type:"ParenExpr",Expression:S,Token_OpenParen:T,Token_CloseParen:b,GetFirstToken:()=>y.Token_OpenParen,GetLastToken:()=>y.Token_CloseParen}),y}else if(r.Type=="Ident"||r.Type=="Keyword"&&he.includes(r.Source)){let T;return T=m({Type:"VariableExpr",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),k[T.Token.Source]!=null&&k[T.Token.Source]?.Tokens?.push!=null?(k[T.Token.Source].Tokens.push(T.Token),k[T.Token.Source].UseCountIncrease()):L[T.Token.Source]!=null&&L[T.Token.Source]?.Tokens?.push!=null&&(L[T.Token.Source].Tokens.push(T.Token),L[T.Token.Source].UseCountIncrease()),T}else throw ke(e()),`${i(r)}: Unexpected symbol. ${r.Type} ${r.Source}`}function _(k,L){let r=l("Symbol","{"),T=[],S=[];for(;t().Source!="}";){let E,C;if(t().Source=="["){let F=n(),R=f(k,L),G=l("Symbol","]"),B=l("Symbol","="),j=f(k,L);E=R.Token&&R.Token.Source,C=j,T.push({EntryType:"Index",Index:R,Value:j,Token_OpenBracket:F,Token_CloseBracket:G,Token_Equals:B})}else if((t().Type=="Ident"||t().Type=="Keyword"&&he.includes(t().Source))&&t(1).Source=="="){let F=n(),R=n(),G=f(k,L);E=F,C=G,T.push({EntryType:"Field",Field:F,Value:G,Token_Equals:R})}else{let F=f(k,L);T.push({EntryType:"Value",Value:F})}if(t().Source==","||t().Source==";")S.push(n());else break}let b=l("Symbol","}"),y;return y=m({Type:"TableLiteral",EntryList:T,Token_SeperatorList:S,Token_OpenBrace:r,Token_CloseBrace:b,GetFirstToken:()=>y.Token_OpenBrace,GetLastToken:()=>y.Token_CloseBrace}),y}function w(k,L){let r=[],T=[];if(t().Type=="Ident"||t().Type=="Keyword"&&he.includes(t().Source)){let S=n();if(L&&t().Source=="<"&&t(2).Source==">"){let b=t(1).Source;S.Attribute={LeadingWhite:t().LeadingWhite,Source:`<${b}>`},n(),n(),n()}r.push(S)}else if(t().Source=="..."&&k)return[r,T,n()];for(;t().Source==",";){if(T.push(n()),t().Source=="..."&&k)return[r,T,n()];{let S=l("Ident");if(L&&t().Source=="<"&&t(2).Source==">"){let b=t(1).Source;S.Attribute={LeadingWhite:t().LeadingWhite,Source:`<${b}>`},n(),n(),n()}r.push(S)}}return[r,T]}function x(k,L,r){let T=h(L,r),S=t();if(S.Type=="Keyword"&&S.Source==k)return n(),[T,S];throw ke(S.Type,S.Source),`${i(S)}: ${k} expected.`}function $(k,L,r,T){let S=n(),b,y;if(!k){b=[],y=[];let A=l("Ident");for(b.push(A);t().Source==".";)y.push(n()),b.push(l("Ident"));t().Source==":"&&(y.push(n()),b.push(l("Ident")))}let E=l("Symbol","("),[C,F,R]=w(!0),G=l("Symbol",")"),[B,j]=x("end",L,r),V;return V=m({Type:k==!0?"FunctionLiteral":"FunctionStat",NameChain:b,ArgList:C,Body:B,Token_Function:S,Token_NameChainSeperator:y,Token_OpenParen:E,Token_Varg:R,Token_ArgCommaList:F,Token_CloseParen:G,Token_End:j,GetFirstToken:()=>V.Token_Function,GetLastToken:()=>V.Token_End}),V}function I(k,L){let r=t();if(r.Source=="("){let T=n(),S=[],b=[];for(;t().Source!=")"&&(S.push(f(k,L)),t().Source==",");)b.push(n());let y=l("Symbol",")"),E;return E=m({CallType:"ArgCall",ArgList:S,Token_CommaList:b,Token_OpenParen:T,Token_CloseParen:y,GetFirstToken:()=>E.Token_OpenParen,GetLastToken:()=>E.Token_CloseParen}),E}else if(r.Source=="{"){let T;return T=m({CallType:"TableCall",TableExpr:f(k,L),GetFirstToken:()=>T.TableExpr.GetFirstToken(),GetLastToken:()=>T.TableExpr.GetLastToken()}),T}else if(r.Type=="String"){let T;return T=m({CallType:"StringCall",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else throw"Function arguments expected."}function q(k,L){let r=g(k,L);for(U(r,"nil prefixexpr");;){let T=t();if(T.Source=="."){let S=n(),b=l("Ident"),y;y=m({Type:"FieldExpr",Base:r,Field:b,Token_Dot:S,GetFirstToken:()=>y.Base.GetFirstToken(),GetLastToken:()=>y.Field}),r=y}else if(T.Source==":"){let S=n(),b=l("Ident"),y=I(k,L),E;E=m({Type:"MethodExpr",Base:r,Method:b,FunctionArguments:y,Token_Colon:S,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.FunctionArguments.GetLastToken()}),r=E}else if(T.Source=="["){let S=n(),b=f(k,L),y=l("Symbol","]"),E;E=m({Type:"IndexExpr",Base:r,Index:b,Token_OpenBracket:S,Token_CloseBracket:y,GetFirstToken:()=>E.Base.GetFirstToken(),GetLastToken:()=>E.Token_CloseBracket}),r=E}else if(T.Source=="{"||T.Source=="("||T.Type=="String"){let S;S=m({Type:"CallExpr",Base:r,FunctionArguments:I(k,L),GetFirstToken:()=>S.Base.GetFirstToken(),GetLastToken:()=>S.FunctionArguments.GetLastToken()}),r=S}else if(Jn.includes(T.Source)){let S=n(),b=f(k,L),y;y=m({Type:"CompoundStat",Base:r,Token_Compound:S,Rhs:b,Lhs:r,GetFirstToken:()=>y.Base.GetFirstToken(),GetLastToken:()=>y.Rhs.GetLastToken()}),r=y}else return r}}function v(k,L){let r=t();if(r.Type=="Number"){let T;return T=m({Type:"NumberLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(r.Type=="String"){let T;return T=m({Type:"StringLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(r.Type=="Hash"){let T;return T=m({Type:"HashLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(r.Source=="nil"){let T;return T=m({Type:"NilLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(r.Source=="true"||r.Source=="false"){let T;return T=m({Type:"BooleanLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else if(r.Source=="..."){let T;return T=m({Type:"VargLiteral",Token:n(),GetFirstToken:()=>T.Token,GetLastToken:()=>T.Token}),T}else return r.Source=="{"?_(k,L):r.Source=="function"?$(!0,k,L):r.Source=="if"?be(!0,k,L):q(k,L)}function O(k,L,r){let T;if(c()){let S=n(),b=O(Xn,L,r),y;y=m({Type:"UnopExpr",Token_Op:S,Rhs:b,GetFirstToken:()=>y.Token_Op,GetLastToken:()=>y.Rhs.GetLastToken()}),T=y}else T=v(L,r),U(T,"nil sipleexpr");for(;a()&&Pe[t().Source]!=null&&Pe[t().Source][0]>k;){let S=n(),b=O(Pe[S.Source][1],L,r);U(b,"RhsNeeded");let y;y=m({Type:"BinopExpr",Lhs:T,Rhs:b,Token_Op:S,GetFirstToken:()=>y.Lhs.GetFirstToken(),GetLastToken:()=>y.Rhs.GetLastToken()}),T=y}return T}f=(k,L)=>O(0,k,L);function K(k,L){let r=q(k,L);if(r.Type=="MethodExpr"||r.Type=="CallExpr"){let T;return T=m({Type:"CallExprStat",Expression:r,GetFirstToken:()=>T.Expression.GetFirstToken(),GetLastToken:()=>T.Expression.GetLastToken()}),T}else{if(r.Type=="CompoundStat")return r;{let T=[r],S=[];for(r.IsStat=!0;t().Source==",";){S.push(n());let F=q(k,L);if(F.Type=="MethodExpr"||F.Type=="CallExpr")throw"Bad left hand side of asignment";F.IsStat=!0,T.push(F)}let b=l("Symbol","="),y=[f(k,L)],E=[];for(;t().Source==",";)E.push(n()),y.push(f(k,L));let C;return C=m({Type:"AssignmentStat",Rhs:y,Lhs:T,Token_Equals:b,Token_LhsSeperatorList:S,Token_RhsSeperatorList:E,GetFirstToken:()=>C.Lhs[0].GetFirstToken(),GetLastToken:()=>C.Rhs[C.Rhs.length-1].GetLastToken()}),C}}}function be(k,L,r){let T=n(),S=f(L,r),b=l("Keyword","then"),y=k?f(L,r):h(L,r),E=[];for(;t().Source=="elseif"||t().Source=="else";){let R=n(),G,B;R.Source=="elseif"&&(G=f(L,r),B=l("Keyword","then"));let j=k?f(L,r):h(L,r);if(E.push({Condition:G,Body:j,ClauseType:R.Source,Token:R,Token_Then:B}),R.Source=="else")break}let C=k?null:l("Keyword","end"),F;return F=m({Type:k?"IfExpr":"IfStat",Condition:S,Body:y,ElseClauseList:E,Token_If:T,Token_Then:b,Token_End:C,GetFirstToken:()=>F.Token_If,GetLastToken:()=>F.Token_End}),F}function se(k,L){let r=n(),[T,S]=x("end",k,L),b;return b=m({Type:"DoStat",Body:T,Token_Do:r,Token_End:S,GetFirstToken:()=>b.Token_Do,GetLastToken:()=>b.Token_End}),b}function Q(k,L){let r=n(),T=f(k,L),S=l("Keyword","do"),[b,y]=x("end",k,L),E;return E=m({Type:"WhileStat",Condition:T,Body:b,Token_While:r,Token_Do:S,Token_End:y,GetFirstToken:()=>E.Token_While,GetLastToken:()=>E.Token_End}),E}function ae(k,L){let r=n(),[T,S]=w(),b=[];if(t().Source=="="){let y=n(),[E,C]=p(k,L);if(E.length<2||E.length>3)throw"Expected 2 or 3 values for range bounds";let F=l("Keyword","do"),[R,G]=x("end",k,L),B;return B=m({Type:"NumericForStat",VarList:T,RangeList:E,Body:R,Token_For:r,Token_VarCommaList:S,Token_Equals:y,Token_RangeCommaList:C,Token_Do:F,Token_End:G,GetFirstToken:()=>B.Token_For,GetLastToken:()=>B.Token_End}),B}else if(t().Source=="in"){let y=n(),[E,C]=p(k,L),F=l("Keyword","do"),[R,G]=x("end",k,L),B;return B=m({Type:"GenericForStat",VarList:T,GeneratorList:E,Body:R,Token_For:r,Token_VarCommaList:S,Token_In:y,Token_GeneratorCommaList:C,Token_Do:F,Token_End:G,GetFirstToken:()=>B.Token_For,GetLastToken:()=>B.Token_End}),B}}function fe(k,L){let r=n(),[T,S]=x("until",k),b=f(k,L),y;return y=m({Type:"RepeatStat",Body:T,Condition:b,Token_Repeat:r,Token_Until:S,GetFirstToken:()=>y.Token_Repeat,GetLastToken:()=>y.Condition.GetLastToken()}),y}function ie(k,L){let r=n();if(t().Source=="function"){let T=$(!1,k,L,!0);if(T.NameChain.length>1)throw i(T.Token_NameChainSeperator[0])+": `(` expected.";let S;return S=m({Type:"LocalFunctionStat",FunctionStat:T,Token_Local:r,GetFirstToken:()=>S.Token_Local,GetLastToken:()=>S.FunctionStat.GetLastToken()}),S}else if(t().Type=="Ident"||t().Type=="Keyword"&&he.includes(t().Source)){let[T,S]=w(!1,!0),b=[],y=[],E;if(t().Source=="="){E=n();let[F,R]=p(k,L);b=F,y=R}let C;return C=m({Type:"LocalVarStat",VarList:T,ExprList:b,Token_Local:r,Token_Equals:E,Token_VarCommaList:S,Token_ExprCommaList:y,GetFirstToken:()=>C.Token_Local,GetLastToken:function(){return C.ExprList.length>0?C.ExprList[C.ExprList.length-1].GetLastToken():C.VarList[C.VarList.length-1]}}),C}else throw"`function` or ident expected"}function de(k,L){let r=n(),T,S;o()||t().Source==";"?(T=[],S=[]):[T,S]=p(k,L);let b;return b={Type:"ReturnStat",ExprList:T,Token_Return:r,Token_CommaList:S,GetFirstToken:()=>b.Token_Return,GetLastToken:function(){return b.ExprList.length>0?b.ExprList[b.ExprList.length-1].GetLastToken():b.Token_Return}},b}function ee(){let k=n(),L;return L={Type:"BreakStat",Token_Break:k,GetFirstToken:()=>L.Token_Break,GetLastToken:()=>L.Token_Break},L}function ue(k,L){if(t(1).Source=="(")return[!1,K(k,L)];let r=n(),T;return T={Type:"ContinueStat",Token_Continue:r,GetFirstToken:()=>T.Token_Continue,GetLastToken:()=>T.Token_Continue},[!0,T]}function ye(){let k=n(),L;t().Type=="Keyword"?L=l("Keyword"):L=l("Ident");let r;return r={Type:"GotoStat",Token_Goto:k,Token_Label:L,GetFirstToken:()=>r.Token_Goto,GetLastToken:()=>r.Token_Label},r}function _e(){let k=n(),L;t().Type=="Keyword"?L=l("Keyword"):L=l("Ident");let r=l("Symbol","::"),T;return T={Type:"LabelStat",Token_ColonsLeft:k,Token_Label:L,Token_ColonsRight:r,GetFirstToken:()=>T.Token_ColonsLeft,GetLastToken:()=>T.Token_ColonsRight},T}function z(k,L){let r=t();return r.Source=="if"?[!1,be(!1,k,L)]:r.Source=="while"?[!1,Q(k,L)]:r.Source=="do"?[!1,se(k,L)]:r.Source=="for"?[!1,ae(k,L)]:r.Source=="repeat"?[!1,fe(k,L)]:r.Source=="function"?[!1,$(!1,k,L)]:r.Source=="local"?[!1,ie(k,L)]:r.Source=="return"?[!0,de(k,L)]:r.Source=="break"?[!0,ee(k,L)]:r.Source=="continue"?ue(k,L):r.Source=="goto"?[!1,ye()]:r.Source=="::"?[!1,_e()]:[!1,K(k,L)]}let We=1;return h=function(k,L){let r=[],T=[],S=!1,b={},y={};if(L!=null)for(let[G,B]of Object.entries(L))y[G]=B;if(k!=null)for(let[G,B]of Object.entries(k))y[G]=B;let E,C=0;for(;!S&&!o();){E&&E==t()&&ke(`INFINITE LOOP POSSIBLE ON STATEMENT ${E.Source} :`,E),E=t();let[G,B]=z(b,y);if(B)switch(r.push(B),B.Type){case"LocalVarStat":B.VarList.forEach(A=>{A.UseCount=0,A.Number=C++,b[A.Source]=A;let X=[];function ne(){A.UseCount++,X.forEach(D=>{D.UseCount=A.UseCount})}A.Tokens={},A.Tokens.push=D=>{D.UseCountIncrease=ne,D.UseCount=A.UseCount,D.Tokens=A.Tokens,X.push(D)},A.Tokens.get=()=>X,A.UseCountIncrease=ne});break;case"LocalFunctionStat":let V=B.FunctionStat.NameChain;if(V.length===1){let ne=function(){A.UseCount++,X.forEach(D=>{D.UseCount=A.UseCount})};var R=ne;let A=V[0];A.UseCount=0,A.Number=C++,b[A.Source]=A;let X=[];A.Tokens={},A.Tokens.push=D=>{D.UseCountIncrease=ne,D.UseCount=A.UseCount,D.Tokens=A.Tokens,X.push(D)},A.Tokens.get=()=>X,A.UseCountIncrease=ne}break;default:break}let j=t();j.Type=="Symbol"&&j.Source==";"&&(T[r.length-1]=n())}let F;return F={Type:"StatList",StatementList:r,SemicolonList:T,GetFirstToken:function(){if(F.StatementList.length!=0)return F.StatementList[0]?.GetFirstToken()},GetLastToken:function(){if(F.StatementList.length!=0)return F.SemicolonList[F.StatementList.length-1]?F.SemicolonList[F.StatementList.length-1]:F.StatementList[F.StatementList.length-1].GetLastToken()}},F},h([],[])}function me(d,s){let u={BinopExpr:!0,UnopExpr:!0,NumberLiteral:!0,StringLiteral:!0,NilLiteral:!0,BooleanLiteral:!0,VargLiteral:!0,HashLiteral:!0,FieldExpr:!0,IndexExpr:!0,MethodExpr:!0,CallExpr:!0,FunctionLiteral:!0,VariableExpr:!0,ParenExpr:!0,TableLiteral:!0},n={StatList:!0,BreakStat:!0,ContinueStat:!0,LabelStat:!0,GotoStat:!0,ReturnStat:!0,LocalVarStat:!0,LocalFunctionStat:!0,FunctionStat:!0,RepeatStat:!0,GenericForStat:!0,NumericForStat:!0,WhileStat:!0,DoStat:!0,IfStat:!0,CallExprStat:!0,AssignmentStat:!0,CompoundStat:!0};for(var[t,i]of Object.entries(s))if(!(t==="VisitStat"||t==="VisitExpr")&&!n[t]&&!u[t])throw`Invalid visitor target: \`${t}\``;function e(l){if(l!=null){let m=s[l.Type];if(typeof m=="function")return m(l);if(m&&m.Pre)return m.Pre(l)}}function o(l){let m=s[l.Type];if(m&&typeof m=="object"&&m.Post)return m.Post(l)}let c,a;c=function(l){if(!e(l)){if(l.Type=="BinopExpr")c(l.Lhs),c(l.Rhs);else if(l.Type=="UnopExpr")c(l.Rhs);else if(!(l.Type=="NumberLiteral"||l.Type=="StringLiteral"||l.Type=="NilLiteral"||l.Type=="BooleanLiteral"||l.Type=="VargLiteral"||l.Type=="HashLiteral")){if(l.Type=="FieldExpr")c(l.Base);else if(l.Type=="IndexExpr")c(l.Base),c(l.Index);else if(l.Type=="MethodExpr"||l.Type=="CallExpr")c(l.Base),l.FunctionArguments.CallType=="ArgCall"?l.FunctionArguments.ArgList.forEach((m,h)=>{c(m)}):l.FunctionArguments.CallType=="TableCall"&&c(l.FunctionArguments.TableExpr);else if(l.Type=="FunctionLiteral")a(l.Body);else if(l.Type!="VariableExpr")if(l.Type=="ParenExpr")c(l.Expression);else if(l.Type=="TableLiteral")l.EntryList.forEach((m,h)=>{if(m.EntryType=="Field")c(m.Value);else if(m.EntryType=="Index")c(m.Index),c(m.Value);else if(m.EntryType=="Value")c(m.Value);else throw"unreachable"});else if(l.Type=="CompoundStat")c(l.Lhs),c(l.Rhs);else if(l.Type=="IfExpr")c(l.Condition),c(l.Body),l.ElseClauseList.forEach(m=>{m.Condition!=null&&c(m.Condition),c(m.Body)});else throw`unreachable, type: ${l.Type}: ${l}`}o(l)}},a=function(l){if(!e(l)){if(l.Type=="StatList")l.StatementList.forEach((m,h)=>{if(m!=null){if(m===null||m.Type===null)return;m.Remove=()=>{l.StatementList[h]=null},a(m)}});else if(l.Type!="BreakStat"){if(l.Type!="ContinueStat"){if(l.Type!="GotoStat"){if(l.Type!="LabelStat")if(l.Type=="ReturnStat")l.ExprList.forEach((m,h)=>{c(m)});else if(l.Type=="LocalVarStat")l.Token_Equals&&l.ExprList.forEach((m,h)=>{c(m)});else if(l.Type=="LocalFunctionStat")a(l.FunctionStat.Body);else if(l.Type=="FunctionStat")a(l.Body);else if(l.Type=="RepeatStat")a(l.Body),c(l.Condition);else if(l.Type=="GenericForStat")l.GeneratorList.forEach((m,h)=>{c(m)}),a(l.Body);else if(l.Type=="NumericForStat")l.RangeList.forEach((m,h)=>{c(m)}),a(l.Body);else if(l.Type=="WhileStat")c(l.Condition),a(l.Body);else if(l.Type=="DoStat")a(l.Body);else if(l.Type=="IfStat")c(l.Condition),a(l.Body),l.ElseClauseList.forEach(m=>{m.Condition!=null&&c(m.Condition),a(m.Body)});else if(l.Type=="CallExprStat")c(l.Expression);else if(l.Type=="CompoundStat")c(l.Lhs),c(l.Rhs);else if(l.Type=="AssignmentStat")l.Lhs.forEach(m=>{c(m)}),l.Rhs.forEach(m=>{c(m)});else throw"Unreachable code. Got "+l.Type}}}o(l)}},s.VisitStat=a,s.VisitExpr=c,n[d.Type]?a(d):c(d)}function nt(d){let s=[],u,n=0;function t(){return n++,n}function i(){u={ParentScope:u,ChildScopeList:[],VariableList:[],BeginLocation:t(),Depth:null,GetVar:null},u.ParentScope?(u.Depth=u.ParentScope.Depth+1,u.ParentScope.ChildScopeList.push(u)):u.Depth=1;let f=u;u.GetVar=function(p){for(let g of f.VariableList)if(g.Name==p)return g;if(f.ParentScope)return f.ParentScope.GetVar(p);for(let g of s)if(g.Name==p)return g}}function e(){let f=u;return f.EndLocation=t(),f.VariableList.forEach(p=>{p.ScopeEndLocation=f.EndLocation}),u=f.ParentScope,f}i();function o(f,p,g){U(g,"Missing localInfo"),U(f,"Missing local var name");let _={Type:"Local",Name:f,RenameList:[p],AssignedTo:!1,Info:g,Scope:u,BeginLocation:t(),EndLocation:t(),ReferenceLocationList:[t()]};return _.Rename=function(w){_.Name=w,_.RenameList.forEach(x=>{x(w)})},u.VariableList.push(_),_}function c(f){for(let g of s)if(g.Name==f)return g;let p={Type:"Global",Name:f,RenameList:[],AssignedTo:!1,Scope:null,BeginLocation:t(),EndLocation:t(),ReferenceLocationList:[]};return p.Rename=function(g){p.Name=g,p.RenameList.forEach(_=>{_(g)})},s.push(p),p}function a(f,p){U(f,"Missing var name");let g=c(f);return g.RenameList.push(p),g}function l(f,p){let g;for(g=f.VariableList.length-1;g>=0;g--)if(f.VariableList[g].Name==p)return f.VariableList[g];if(f.ParentScope){let _=l(f.ParentScope,p);if(_)return _}}function m(f,p){U(f,"Missing var name");let g=l(u,f);g?g.RenameList.push(p):g=a(f,p);let _=t();return g.EndLocation=_,g.ReferenceLocationList.push(g.EndLocation),g}let h={};return h.FunctionLiteral={Pre:function(f){i(),f.ArgList.forEach((p,g)=>{let _=o(p.Source,function(w,x){x||(p.Source=w)},{Type:"Argument",Index:g});p.var=_})},Post:function(f){e()}},h.VariableExpr=function(f){f.Variable=m(f.Token.Source,function(p,g=!1){g&&f.IsStat||(f.Token.Source=p)})},h.StatList={Pre:function(f){i()},Post:function(f){f.SkipPop||e()}},h.LocalVarStat={Post:function(f){f.VarList.forEach((p,g)=>{o(p.Source,function(_){f.VarList[g].Source=_},{Type:"Local",Expr:f.ExprList})})}},h.LocalFunctionStat={Pre:function(f){o(f.FunctionStat.NameChain[0].Source,function(p){f.FunctionStat.NameChain[0].Source=p},{Type:"LocalFunction"}),i(),f.FunctionStat.ArgList.forEach((p,g)=>{o(p.Source,function(_){p.Source=_},{Type:"Argument",Index:g})})},Post:function(){e()}},h.FunctionStat={Pre:function(f){let p=f.NameChain,g;p.length==1?l(u,p[0].Source)?g=m(p[0].Source,function(_){p[0].Source=_}):g=a(p[0].Source,function(_){p[0].Source=_}):g=m(p[0].Source,function(_){p[0].Source=_}),g.AssignedTo=!0,i(),f.ArgList.forEach((_,w)=>{o(_.Source,function(x){_.Source=x},{Type:"Argument",Index:w})})},Post:function(){e()}},h.GenericForStat={Pre:function(f){return f.GeneratorList.forEach(p=>{me(p,h)}),i(),f.VarList.forEach((p,g)=>{o(p.Source,function(_){p.Source=_},{Type:"ForRange",Index:g})}),me(f.Body,h),e(),!0}},h.NumericForStat={Pre:function(f){return f.RangeList.forEach(p=>{me(p,h)}),i(),f.VarList.forEach((p,g)=>{o(p.Source,function(_){p.Source=_},{Type:"ForRange",Index:g})}),me(f.Body,h),e(),!0}},h.RepeatStat={Pre:function(f){f.Body.SkipPop=!0},Post:function(f){e()}},h.AssignmentStat={Post:function(f){f.Lhs.forEach(p=>{p.Variable!=null&&(p.Variable.AssignedTo=!0)})}},me(d,h),[s,e()]}function tt(d){let s,u,n="",t=e=>typeof e?.LeadingWhite!="string"?" ":e.LeadingWhite;function i(e){if(e.LeadingWhite==null||e.Source==null)throw`Bad token: tk=${e} | lwhite=${e.LeadingWhite} | source=${e.Source}`;n=`${n}${e.LeadingWhite}${e.Source}`}return u=function(e){if(e.Type=="BinopExpr")u(e.Lhs),i(e.Token_Op),u(e.Rhs);else if(e.Type=="UnopExpr")i(e.Token_Op),u(e.Rhs);else if(e.Type=="NumberLiteral"||e.Type=="StringLiteral"||e.Type=="NilLiteral"||e.Type=="BooleanLiteral"||e.Type=="VargLiteral"||e.Type=="HashLiteral")i(e.Token);else if(e.Type=="FieldExpr")u(e.Base),i(e.Token_Dot),i(e.Field);else if(e.Type=="IndexExpr")u(e.Base),i(e.Token_OpenBracket),u(e.Index),i(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")u(e.Base),e.Type=="MethodExpr"&&(i(e.Token_Colon),i(e.Method)),e.FunctionArguments.CallType=="StringCall"?i(e.FunctionArguments.Token):e.FunctionArguments.CallType=="ArgCall"?(i(e.FunctionArguments.Token_OpenParen),e.FunctionArguments.ArgList.forEach((o,c)=>{u(o);let a=e.FunctionArguments.Token_CommaList[c];a!=null&&i(a)}),i(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&u(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")i(e.Token_Function),i(e.Token_OpenParen),e.ArgList.forEach((o,c)=>{i(o);let a=e.Token_ArgCommaList[c];a!=null&&i(a)}),e.Token_Varg!=null&&i(e.Token_Varg),i(e.Token_CloseParen),s(e.Body),i(e.Token_End);else if(e.Type=="VariableExpr")i(e.Token);else if(e.Type=="ParenExpr")i(e.Token_OpenParen),u(e.Expression),i(e.Token_CloseParen);else if(e.Type=="TableLiteral")i(e.Token_OpenBrace),e.EntryList.forEach((o,c)=>{if(o.EntryType=="Field")i(o.Field),i(o.Token_Equals),u(o.Value);else if(o.EntryType=="Index")i(o.Token_OpenBracket),u(o.Index),i(o.Token_CloseBracket),i(o.Token_Equals),u(o.Value);else if(o.EntryType=="Value")u(o.Value);else throw"unreachable";let a=e.Token_SeperatorList[c];a!=null&&i(a)}),i(e.Token_CloseBrace);else if(e.Type=="CompoundStat")s(e);else if(e.Type=="IfExpr")i(e.Token_If),u(e.Condition),i(e.Token_Then),u(e.Body),e.ElseClauseList.forEach(o=>{i(o.Token),o.Condition!=null&&(u(o.Condition),i(o.Token_Then)),u(o.Body)});else throw`unreachable, type: ${e.Type}: ${e}`},s=function(e){if(e==null)throw`STAT IS NIL! ${e}`;if(!(e.Type==="StatList"&&e.StatementList.length===0)){if(e.WrapInDo){let o=t(e.GetFirstToken());e.GetFirstToken().LeadingWhite="",n+=`${o}do `}e.Type=="StatList"?e.StatementList.forEach((o,c)=>{o===null||o.Type===null||(o.Remove=()=>{e.StatementList[c]=null},s(o),e.SemicolonList[c]&&i(e.SemicolonList[c]))}):e.Type=="BreakStat"?i(e.Token_Break):e.Type=="ContinueStat"?i(e.Token_Continue):e.Type=="GotoStat"?(i(e.Token_Goto),i(e.Token_Label)):e.Type=="LabelStat"?(i(e.Token_ColonsLeft),i(e.Token_Label),i(e.Token_ColonsRight)):e.Type=="ReturnStat"?(i(e.Token_Return),e.ExprList.forEach((o,c)=>{u(o),e.Token_CommaList[c]&&i(e.Token_CommaList[c])})):e.Type=="LocalVarStat"?(i(e.Token_Local),e.VarList.forEach((o,c)=>{i(o),o.Attribute!=null&&i(o.Attribute);let a=e.Token_VarCommaList[c];a!=null&&i(a)}),e.Token_Equals!=null&&(i(e.Token_Equals),e.ExprList.forEach((o,c)=>{u(o);let a=e.Token_ExprCommaList[c];a!=null&&i(a)}))):e.Type=="LocalFunctionStat"?(i(e.Token_Local),i(e.FunctionStat.Token_Function),i(e.FunctionStat.NameChain[0]),i(e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((o,c)=>{i(o);let a=e.FunctionStat.Token_ArgCommaList[c];a!=null&&i(a)}),e.FunctionStat.Token_Varg&&i(e.FunctionStat.Token_Varg),i(e.FunctionStat.Token_CloseParen),s(e.FunctionStat.Body),i(e.FunctionStat.Token_End)):e.Type=="FunctionStat"?(i(e.Token_Function),e.NameChain.forEach((o,c)=>{i(o);let a=e.Token_NameChainSeperator[c];a!=null&&i(a)}),i(e.Token_OpenParen),e.ArgList.forEach((o,c)=>{i(o);let a=e.Token_ArgCommaList[c];a!=null&&i(a)}),e.Token_Varg&&i(e.Token_Varg),i(e.Token_CloseParen),s(e.Body),i(e.Token_End)):e.Type=="RepeatStat"?(i(e.Token_Repeat),s(e.Body),i(e.Token_Until),u(e.Condition)):e.Type=="GenericForStat"?(i(e.Token_For),e.VarList.forEach((o,c)=>{i(o);let a=e.Token_VarCommaList[c];a!=null&&i(a)}),i(e.Token_In),e.GeneratorList.forEach((o,c)=>{u(o);let a=e.Token_GeneratorCommaList[c];a!=null&&i(a)}),i(e.Token_Do),s(e.Body),i(e.Token_End)):e.Type=="NumericForStat"?(i(e.Token_For),e.VarList.forEach((o,c)=>{i(o);let a=e.Token_VarCommaList[c];a!=null&&i(a)}),i(e.Token_Equals),e.RangeList.forEach((o,c)=>{u(o);let a=e.Token_RangeCommaList[c];a!=null&&i(a)}),i(e.Token_Do),s(e.Body),i(e.Token_End)):e.Type=="WhileStat"?(i(e.Token_While),u(e.Condition),i(e.Token_Do),s(e.Body),i(e.Token_End)):e.Type=="DoStat"?(i(e.Token_Do),s(e.Body),i(e.Token_End)):e.Type=="IfStat"?(i(e.Token_If),u(e.Condition),i(e.Token_Then),s(e.Body),e.ElseClauseList.forEach(o=>{i(o.Token),o.Condition!=null&&(u(o.Condition),i(o.Token_Then)),s(o.Body)}),i(e.Token_End)):e.Type=="CallExprStat"?u(e.Expression):e.Type=="CompoundStat"?(u(e.Lhs),i(e.Token_Compound),u(e.Rhs),e.Type="CompoundStat"):e.Type=="AssignmentStat"?(e.Lhs.forEach((o,c)=>{u(o);let a=e.Token_LhsSeperatorList[c];a!=null&&i(a)}),i(e.Token_Equals),e.Rhs.forEach((o,c)=>{u(o);let a=e.Token_RhsSeperatorList[c];a!=null&&i(a)})):U(!1,"unreachable"),e.WrapInDo&&(n+=" end ")}},s(d),n}function ot(d){let s,u;function n(e){e&&(e.LeadingWhite="")}function t(e,o,c=!1){n(o);let a=(typeof e.Source=="string"?e.Source:e.Source.toString()).substr(e.Source.length-1,1),l=(typeof o.Source=="string"?o.Source:o.Source.toString()).substr(0,1);a=="-"&&l=="-"||Me.includes(a)&&Me.includes(l)||c&&a==")"&&l=="("?o.LeadingWhite=c?";":" ":o.LeadingWhite=""}function i(e,o,c){s(o),n(c);let a=o.GetFirstToken(),l=o.GetLastToken();a!=null?(t(e,a),t(l,c)):t(e,c)}u=function(e){if(e.Type==="BinopExpr")u(e.Lhs),u(e.Rhs),e.Lhs.Type=="NumberLiteral"&&e.Token_Op.Source==".."?e.Token_Op.LeadingWhite=" ":(n(e.Token_Op),t(e.Lhs.GetLastToken(),e.Token_Op)),t(e.Token_Op,e.Rhs.GetFirstToken());else if(e.Type==="UnopExpr")n(e.Token_Op),u(e.Rhs),t(e.Token_Op,e.Rhs.GetFirstToken());else if(e.Type==="NumberLiteral"||e.Type==="StringLiteral"||e.Type==="NilLiteral"||e.Type==="BooleanLiteral"||e.Type==="VargLiteral"||e.Type==="HashLiteral")n(e.Token);else if(e.Type=="FieldExpr")u(e.Base),n(e.Token_Dot),n(e.Field);else if(e.Type=="IndexExpr")u(e.Base),n(e.Token_OpenBracket),u(e.Index),n(e.Token_CloseBracket);else if(e.Type=="MethodExpr"||e.Type=="CallExpr")u(e.Base),e.Type=="MethodExpr"&&(n(e.Token_Colon),n(e.Method)),e.FunctionArguments.CallType=="StringCall"?n(e.FunctionArguments.Token):e.FunctionArguments.CallType=="ArgCall"?(n(e.FunctionArguments.Token_OpenParen),e.FunctionArguments.ArgList.forEach((o,c)=>{u(o);let a=e.FunctionArguments.Token_CommaList[c];a!=null&&n(a)}),n(e.FunctionArguments.Token_CloseParen)):e.FunctionArguments.CallType=="TableCall"&&u(e.FunctionArguments.TableExpr);else if(e.Type=="FunctionLiteral")n(e.Token_Function),n(e.Token_OpenParen),e.ArgList.forEach((o,c)=>{n(o);let a=e.Token_ArgCommaList[c];a!=null&&n(a)}),e.Token_Varg!=null&&n(e.Token_Varg),n(e.Token_CloseParen),i(e.Token_CloseParen,e.Body,e.Token_End);else if(e.Type=="VariableExpr")n(e.Token);else if(e.Type=="ParenExpr")n(e.Token_OpenParen),u(e.Expression),n(e.Token_CloseParen);else if(e.Type=="IfExpr"){n(e.Token_If),u(e.Condition),t(e.Token_If,e.Condition.GetFirstToken()),t(e.Condition.GetLastToken(),e.Token_Then);let o=e.Token_Then,c=e.Body;e.ElseClauseList.forEach((a,l)=>{t(o,c.GetFirstToken()),t(c.GetLastToken(),a.Token),o=a.Token,a.Condition!=null&&(u(a.Condition),t(a.Token,a.Condition.GetFirstToken()),t(a.Condition.GetLastToken(),a.Token_Then),o=a.Token_Then),u(a.Body),c=a.Body}),t(o,c.GetFirstToken())}else if(e.Type=="TableLiteral")n(e.Token_OpenBrace),e.EntryList.forEach((o,c)=>{o.EntryType=="Field"?(n(o.Field),n(o.Token_Equals),u(o.Value)):o.EntryType=="Index"?(n(o.Token_OpenBracket),u(o.Index),n(o.Token_CloseBracket),n(o.Token_Equals),u(o.Value)):o.EntryType=="Value"?u(o.Value):U(!1,"unreachable");let a=e.Token_SeperatorList[c];a!=null&&n(a)}),e.Token_SeperatorList[e.EntryList.length-1]=null,n(e.Token_CloseBrace);else throw`unreachable, type: ${e.Type}:${e} ${console.trace()}`},s=function(e){if(e.Type=="StatList"){let o;for(o=0;o<=e.StatementList.length;o++){let c=e.StatementList[o];if(c==null)continue;s(c),n(c.GetFirstToken());let a=e.StatementList[o-1];if(a!=null){let l={")":["(","["],"]":["(","["]};if(e.SemicolonList[o-1]){let m=a.GetLastToken().Source,h=c.GetFirstToken().Source;(l[m]===null||l[m]===void 0||!l[m].includes(h))&&(e.SemicolonList[o-1]=null)}e.SemicolonList[o-1]||t(a.GetLastToken(),c.GetFirstToken(),!0)}}e.SemicolonList[e.StatementList.length-1]=null,e.StatementList.length>0&&n(e.StatementList[0].GetFirstToken())}else if(e.Type=="BreakStat")n(e.Token_Break);else if(e.Type=="ContinueStat")n(e.Token_Continue);else if(e.Type=="GotoStat")n(e.Token_Goto),t(e.Token_Goto,e.Token_Label);else if(e.Type=="LabelStat")n(e.Token_ColonsLeft),n(e.Token_Label),n(e.Token_ColonsRight);else if(e.Type=="ReturnStat")n(e.Token_Return),e.ExprList.forEach((o,c)=>{u(o),e.Token_CommaList[c]!=null&&n(e.Token_CommaList[c])}),e.ExprList.length>0&&t(e.Token_Return,e.ExprList[0].GetFirstToken());else if(e.Type=="LocalVarStat"){n(e.Token_Local);let o=!1;e.VarList.forEach((c,a)=>{a==0?t(e.Token_Local,c):n(c),c.Attribute&&(n(c.Attribute),a+1==e.VarList.length&&(o=!0));let l=e.Token_VarCommaList[a];l!=null&&n(l)}),e.Token_Equals!=null&&(o||n(e.Token_Equals),e.ExprList.forEach((c,a)=>{u(c);let l=e.Token_ExprCommaList[a];l!=null&&n(l)}))}else if(e.Type=="LocalFunctionStat")n(e.Token_Local),t(e.Token_Local,e.FunctionStat.Token_Function),t(e.FunctionStat.Token_Function,e.FunctionStat.NameChain[0]),t(e.FunctionStat.NameChain[0],e.FunctionStat.Token_OpenParen),e.FunctionStat.ArgList.forEach((o,c)=>{n(o);let a=e.FunctionStat.Token_ArgCommaList[c];a!=null&&n(a)}),e.FunctionStat.Token_Varg&&n(e.FunctionStat.Token_Varg),n(e.FunctionStat.Token_CloseParen),i(e.FunctionStat.Token_CloseParen,e.FunctionStat.Body,e.FunctionStat.Token_End);else if(e.Type=="FunctionStat")n(e.Token_Function),e.NameChain.forEach((o,c)=>{c==0?t(e.Token_Function,o):n(o);let a=e.Token_NameChainSeperator[c];a!=null&&n(a)}),n(e.Token_OpenParen),e.ArgList.forEach((o,c)=>{n(o);let a=e.Token_ArgCommaList[c];a!=null&&n(a)}),e.Token_Varg&&n(e.Token_Varg),n(e.Token_CloseParen),i(e.Token_CloseParen,e.Body,e.Token_End);else if(e.Type=="RepeatStat")n(e.Token_Repeat),i(e.Token_Repeat,e.Body,e.Token_Until),u(e.Condition),t(e.Token_Until,e.Condition.GetFirstToken());else if(e.Type=="GenericForStat")n(e.Token_For),e.VarList.forEach((o,c)=>{c==0?t(e.Token_For,o):n(o);let a=e.Token_VarCommaList[c];a!=null&&n(a)}),t(e.VarList[e.VarList.length-1],e.Token_In),e.GeneratorList.forEach((o,c)=>{u(o),c==0&&t(e.Token_In,o.GetFirstToken());let a=e.Token_GeneratorCommaList[c];a!=null&&n(a)}),t(e.GeneratorList[e.GeneratorList.length-1].GetLastToken(),e.Token_Do),i(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="NumericForStat")n(e.Token_For),e.VarList.forEach((o,c)=>{c==0?t(e.Token_For,o):n(o);let a=e.Token_VarCommaList[c];a!=null&&n(a)}),t(e.VarList[e.VarList.length-1],e.Token_Equals),e.RangeList.forEach((o,c)=>{u(o),c==0&&t(e.Token_Equals,o.GetFirstToken());let a=e.Token_RangeCommaList[c];a!=null&&n(a)}),t(e.RangeList[e.RangeList.length-1].GetLastToken(),e.Token_Do),i(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="WhileStat")n(e.Token_While),u(e.Condition),n(e.Token_Do),t(e.Token_While,e.Condition.GetFirstToken()),t(e.Condition.GetLastToken(),e.Token_Do),i(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="DoStat")n(e.Token_Do),n(e.Token_End),i(e.Token_Do,e.Body,e.Token_End);else if(e.Type=="IfStat"){n(e.Token_If),u(e.Condition),t(e.Token_If,e.Condition.GetFirstToken()),t(e.Condition.GetLastToken(),e.Token_Then);let o=e.Token_Then,c=e.Body;e.ElseClauseList.forEach((a,l)=>{i(o,c,a.Token),o=a.Token,a.Condition!=null&&(u(a.Condition),t(a.Token,a.Condition.GetFirstToken()),t(a.Condition.GetLastToken(),a.Token_Then),o=a.Token_Then),s(a.Body),c=a.Body}),i(o,c,e.Token_End)}else if(e.Type=="CallExprStat")u(e.Expression);else if(e.Type=="CompoundStat")u(e.Lhs),n(e.Token_Compound),u(e.Rhs),t(e.Lhs.GetLastToken(),e.Token_Compound),t(e.Token_Compound,e.Rhs.GetFirstToken());else if(e.Type=="AssignmentStat")e.Lhs.forEach((o,c)=>{u(o);let a=e.Token_LhsSeperatorList[c];a!=null&&n(a)}),n(e.Token_Equals),e.Rhs.forEach((o,c)=>{u(o);let a=e.Token_RhsSeperatorList[c];a!=null&&n(a)});else return u(e)},s(d)}var re=[],P;for(P=97;P<=122;P++)re.push(String.fromCharCode(P));for(P=65;P<=90;P++)re.push(String.fromCharCode(P));for(P=48;P<=57;P++)re.push(String.fromCharCode(P));re.push("_");var ge=[];for(P=97;P<=122;P++)ge.push(String.fromCharCode(P));for(P=65;P<=90;P++)ge.push(String.fromCharCode(P));function Ye(d){let s="",u=d%ge.length;for(d=(d-u)/ge.length,s=`${s}${ge[u]}`;d>0;){let n=d%re.length;d=(d-n)/re.length,s=`${s}${re[n]}`}return s}function it(d,s,u){let n=[];for(var[t,i]of Object.entries(en))n[t]=!0;let e=[],o=[];d.forEach(h=>{h.AssignedTo&&u?e.push(h):n[h.Name]=!0});function c(h){h.VariableList.forEach(f=>{e.push(f),o.push(f)}),h.ChildScopeList.forEach(f=>{c(f)})}c(s),e.forEach(h=>{h.UsedNameArray=[]}),e.sort((h,f)=>h-f);let a=0,l=[];function m(h){let f=l[h];if(f==null){for(f=Ye(a),a++;n[f];)f=Ye(a),a++;l[h]=f}return f}e.forEach((h,f)=>{h.Renamed=!0;let p=0;for(;h.UsedNameArray[p];)p++;h.Rename(m(p)),h.Scope?e.forEach(g=>{g.Renamed||(!g.Scope||g.Scope.Depth<h.Scope.Depth?g.ReferenceLocationList.some(_=>_>=h.BeginLocation&&_<=h.ScopeEndLocation?(g.UsedNameArray[p]=!0,!0):!1):g.Scope.Depth>h.Scope.Depth?h.ReferenceLocationList.some(_=>_>=g.BeginLocation&&_<=g.ScopeEndLocation?(g.UsedNameArray[p]=!0,!0):!1):h.BeginLocation<g.EndLocation&&h.EndLocation>g.BeginLocation&&(g.UsedNameArray[p]=!0))}):e.forEach(g=>{if(!g.Renamed)if(g.Type=="Global")g.UsedNameArray[p]=!0;else if(g.Type=="Local")h.ReferenceLocationList.some(_=>_>=g.BeginLocation&&_<=g.ScopeEndLocation?(g.UsedNameArray[p]=!0,!0):!1);else throw"Unreachable"})})}var tn={};tn.Minify=function(d,s){let u=et(d),[n,t]=nt(u);s.RenameVariables==!0&&it(n,t,s.RenameGlobals),s.SolveMath==!0&&SolveMath(u),ot(u);let i=tt(u);return i=`${i}`,i};try{Be!=null&&Be.exports!=null&&(Be.exports.Minify=tn.Minify)}catch{}});var an=H((zt,sn)=>{var Ne=require("fs-extra"),rt=require("path");function ln(d,s){let u=0,n=s,t=d.length,i=!1,e="";for(;n<t;){let o=d[n];if(i){if(o==="\\"){n+=2;continue}o===e&&(i=!1)}else{if(o==='"'||o==="'"){i=!0,e=o,n++;continue}if(o==="{")u++;else if(o==="}"&&(u--,u===0))return n}n++}return-1}function rn(d,s){let u=new RegExp(`^\\s*${s}\\s*\\{`,"m"),n=d.match(u);if(!n)return null;let t=n.index,i=d.indexOf("{",t);if(i===-1)return null;let e=ln(d,i);return e===-1?null:{header:n[0],blockStart:t,blockEnd:e,blockContent:d.substring(t,e+1)}}function lt(d,s,u,n,t=!1){let i=["fxmanifest.lua","__resource.lua"],e=null;for(let g of i){let _=rt.join(d,g);if(Ne.existsSync(_)){e=_;break}}if(!e){console.log("\x1B[33m! No fxmanifest.lua or __resource.lua found. Skipping manifest injection.\x1B[0m");return}let o=Ne.readFileSync(e,"utf8"),c=!1,a=(g,_)=>{let w=g.replace("_scripts","_script").replace("files","file"),x=g,$=`'ltbridge/modules/${_}'`,I=rn(o,x);if(I){if(I.blockContent.includes($))return;let O=o.indexOf("{",I.blockStart);o=o.substring(0,O+1)+`
11
+ ${$},`+o.substring(O+1),c=!0;return}let q=new RegExp(`^\\s*${w}\\s+(['"].+?['"])`,"m"),v=o.match(q);if(v){if(v[0].includes($))return;let O=v[1],K=`${x} {
12
+ ${$},
13
+ ${O}
14
+ }`;o=o.replace(v[0],K),c=!0;return}o+=`
15
15
 
16
- ${F} {
17
- 'ltbridge/modules/${S}'
18
- }`,c=!0},o=m=>{let S=m.replace(/[*.]/g,"\\$&"),w=new RegExp(`\\s*['"]ltbridge\\/modules\\/${S}['"],?`,"g");w.test(t)&&(t=t.replace(w,""),c=!0)},g="shared.lua",L="client.lua",a="server.lua";n?s("shared_scripts",g):o(g),u?s("client_scripts",L):o(L),d?s("server_scripts",a):o(a),(()=>{if(t.includes("'ltbridge/**/*.lua'")||t.includes('"ltbridge/**/*.lua"'))return;let m=new RegExp("^\\s*escrow_ignore\\s*\\{","m"),S=t.match(m);if(S){t=t.replace(S[0],`${S[0]}
19
- 'ltbridge/**/*.lua',`),c=!0;return}let w=new RegExp(`^\\s*escrow_ignore\\s+(['"].+?['"])`,"m"),F=t.match(w);if(F){let G=`escrow_ignore {
16
+ ${x} {
17
+ ${$}
18
+ }`,c=!0},l=g=>{let _=g.replace(/[*.]/g,"\\$&"),w=new RegExp(`\\s*['"]ltbridge\\/modules\\/${_}['"],?`,"g");w.test(o)&&(o=o.replace(w,""),c=!0)},m="shared.lua",h="client.lua",f="server.lua";n?a("shared_scripts",m):l(m),s?a("client_scripts",h):l(h),u?a("server_scripts",f):l(f),(()=>{if(o.includes("'ltbridge/**/*.lua'")||o.includes('"ltbridge/**/*.lua"'))return;let g=rn(o,"escrow_ignore");if(g){let x=o.indexOf("{",g.blockStart);o=o.substring(0,x+1)+`
19
+ 'ltbridge/**/*.lua',`+o.substring(x+1),c=!0;return}let _=/^(\s*)escrow_ignore\s+(['"].+?['"])/m,w=o.match(_);if(w){let $=`escrow_ignore {
20
20
  'ltbridge/**/*.lua',
21
- ${F[1]}
22
- }`;t=t.replace(F[0],G),c=!0;return}t+=`
21
+ ${w[2]}
22
+ }`;o=o.replace(w[0],$),c=!0;return}o+=`
23
23
 
24
24
  escrow_ignore {
25
25
  'ltbridge/**/*.lua'
26
- }`,c=!0})(),i&&(n||u)?s("files","imports/**/*.lua"):(o("imports/**/*.lua"),o("modules/**/*.lua")),c&&(Ne.writeFileSync(e,t),console.log("\x1B[32m\u2713 Updated manifest.\x1B[0m"))}Ye.exports={injectManifest:Dn}});var rn=re((Lt,on)=>{var W=require("fs-extra"),K=require("path"),{applyBuildConstants:qn}=De(),Be=null;function nn(){if(Be)return Be;let{getDatabase:k}=ue();return Be=k().exportMap,Be}function tn(k){let{getDatabase:u}=ue(),d=u(),n=[],i=new Set;for(let[s,o]of Object.entries(d.modules)){o.ns&&i.add(`LT.${o.ns} = LT.${o.ns} or {}`);let g=L=>{if(L&&L.stubs)for(let a of L.stubs)a.stubCode&&!a.metadata.internal&&n.push(a.stubCode)};g(o.shared),g(o.client),g(o.server)}let l=K.join(k,"ltbridge");W.ensureDirSync(l);let e=`--- @meta
26
+ }`,c=!0})(),t&&(n||s)?a("files","imports/**/*.lua"):(l("imports/**/*.lua"),l("modules/**/*.lua")),c&&(Ne.writeFileSync(e,o),console.log("\x1B[32m\u2713 Updated manifest.\x1B[0m"))}sn.exports={injectManifest:lt,findBlockEnd:ln}});var ve=H((Ht,dn)=>{var W=require("fs-extra"),J=require("path"),{applyBuildConstants:st}=Ke(),Ge=null;function un(){if(Ge)return Ge;let{getDatabase:d}=oe();return Ge=d().exportMap,Ge}function cn(d){let{getDatabase:s}=oe(),u=s(),n=[],t=new Set;for(let[a,l]of Object.entries(u.modules)){l.ns&&t.add(`LT.${l.ns} = LT.${l.ns} or {}`);let m=h=>{if(h&&h.stubs)for(let f of h.stubs)f.stubCode&&!f.metadata.internal&&n.push(f.stubCode)};m(l.shared),m(l.client),m(l.server)}let i=J.join(d,"ltbridge");W.ensureDirSync(i);let e=`--- @meta
27
27
  --- LT Bridge API Reference
28
28
  --- Auto-generated stub file for IDE intellisense.
29
29
  --- Do NOT include this file in your fxmanifest.
30
30
 
31
- `,t=`LT = LT or {}
32
- `+Array.from(i).sort().join(`
31
+ `,o=`LT = LT or {}
32
+ `+Array.from(t).sort().join(`
33
33
  `)+`
34
34
 
35
- `,c=e+t+n.join(`
35
+ `,c=e+o+n.join(`
36
36
 
37
37
  `)+`
38
- `;W.writeFileSync(K.join(l,"api.lua"),c)}function Un(k,u,d={}){let{version:n}=we();if(u.version!==n){console.log(`\x1B[36m\u2139 LTBridge version updated (${u.version||"unknown"} -> ${n}). Regenerating API stubs...\x1B[0m`),tn(k),u.version=n;let r=K.join(k,"ltbridge","ltbridge.config.json");W.writeFileSync(r,JSON.stringify(u,null,2))}let i=Date.now(),l=u.modules||[],e=u.minify!==!1,t=u.buildAsBundle!==!0,c=[],{resolveDependencies:s}=Ie();l.length>0&&(c=s(l,nn()).sequence),c=["__init__",...c.filter(r=>r!=="__init__")];let{getModuleData:o}=ue(),g=!1,L=!1,a=!1,p={},m={},S=[],w=r=>{let h=o(r);if(!h)return;let T=h.ns,f=E=>{let B=h[E];if(B){if(B.stubs)for(let x of B.stubs)p[x.funcName]=T,m[x.funcName]=x.metadata;let C=B.code,M=`
39
- -- Module: ${r} (${E}.lua)
40
- `,P=C;return e||(P=C.split(`
41
- `).map(x=>x.trim().length>0&&!t?" "+x:x).join(`
42
- `)),t?`${P}
43
- `:M+`do
44
- ${P}
38
+ `;W.writeFileSync(J.join(i,"api.lua"),c)}function at(d,s,u={}){let{version:n}=Fe(),t=u.skipApi===!0;if(s.version!==n){t?console.log(`\x1B[36m\u2139 LTBridge version updated (${s.version||"unknown"} -> ${n}). Run 'ltbridge api' to refresh API stubs.\x1B[0m`):(console.log(`\x1B[36m\u2139 LTBridge version updated (${s.version||"unknown"} -> ${n}). Regenerating API stubs...\x1B[0m`),cn(d)),s.version=n;let r=J.join(d,"ltbridge","ltbridge.config.json");W.writeFileSync(r,JSON.stringify(s,null,2))}let i=Date.now(),e=s.modules||[],o=s.minify!==!1,c=s.buildAsBundle!==!0,a=[],{resolveDependencies:l}=xe();e.length>0&&(a=l(e,un()).sequence),a=["__init__",...a.filter(r=>r!=="__init__")];let{getModuleData:m}=oe(),h=!1,f=!1,p=!1,g={},_={},w=[],x=r=>{let T=m(r);if(!T)return;let S=T.ns,b=F=>{let R=T[F];if(R){if(R.stubs)for(let V of R.stubs)g[V.funcName]=S,_[V.funcName]=V.metadata;let G=R.code,B=`
39
+ -- Module: ${r} (${F}.lua)
40
+ `,j=G;return o||(j=G.split(`
41
+ `).map(V=>V.trim().length>0&&!c?" "+V:V).join(`
42
+ `)),c?`${j}
43
+ `:B+`do
44
+ ${j}
45
45
  end
46
- `}return null},b=f("shared"),_=f("client"),y=f("server");(b||_||y)&&(S.push({modName:r,ns:T,shared:b||"",client:_||"",server:y||""}),b&&(a=!0),_&&(g=!0),y&&(L=!0))};d.details&&(console.log(`
47
- \x1B[1m\x1B[35m\u{1F4E6} Bundling Sequence (${c.length} modules):\x1B[0m`),c.forEach((r,h)=>console.log(` \x1B[90m${(h+1).toString().padStart(2,"0")}.\x1B[0m ${r}`)),console.log(""));for(let r of c)w(r);let F=Xe(),$=(r,h)=>{if(!e)return r;try{return F.Minify(r,{RenameVariables:!0,RenameGlobals:!1,SolveMath:!1})}catch(T){return console.log(`\x1B[33m! Minification failed for ${h}. Emitting unminified code. Error: ${T.message}\x1B[0m`),r}},G=["LT","QBCore","ESX","QBX","exports"],A=new Set,R=r=>{let h=/^([a-zA-Z_][a-zA-Z0-9_]*)\s*=/gm,T;for(;(T=h.exec(r))!==null;){let f=T[1];G.includes(f)||A.add(f)}},N=u.debug===!1||u.debug===void 0;for(let r of S)r.shared&&(r.shared=qn(r.shared,{version:n,disableDebug:N}));if(e)for(let r of S)r.shared&&R(r.shared),r.client&&R(r.client),r.server&&R(r.server);let V=require("crypto"),j=r=>V.createHash("md5").update(r).digest("hex").substring(0,5),D={},X=new Set;for(let r of A){let h=j(r),T=0;for(;X.has(h);)T++,h=j(r+T);X.add(h),D[r]="__"+h}let Y=r=>{if(!r)return r;let h=Object.keys(D);if(h.length===0)return r;let T=h.sort((b,_)=>_.length-b.length).map(b=>b.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),f=new RegExp(`\\[\\[[\\s\\S]*?\\]\\]|'(?:[^'\\\\]|\\\\.)*'|"(?:[^"\\\\]|\\\\.)*"|\\b(${T.join("|")})\\b`,"g");return r.replace(f,(b,_)=>_&&D[_]?D[_]:b)};if(e)for(let r of S)r.shared=Y(r.shared),r.client=Y(r.client),r.server=Y(r.server);let ee={shared:new Set,client:new Set,server:new Set},te=(r,h)=>{if(!r)return r;let T=Object.keys(p).sort((y,E)=>E.length-y.length);if(T.length===0)return r;let f=r,b=new Set,_="";for(let y of T){let E=p[y],B=E?`LT.${E}.`:"LT.",C=m[y]||{};if(e&&C.internal){if(!D[y]){let pe=j(y),Ce=0;for(;X.has(pe);)Ce++,pe=j(y+Ce);X.add(pe),D[y]="__"+pe}let U=D[y],q=new RegExp(`(^|[^a-zA-Z0-9_.:"'])(${y})(\\s*[=().,\\[\\]])`,"g");f=f.replace(q,`$1${U}$3`);continue}let M=`${B}${y}`,P=!!E;if(C.export){if(M=`${B}${C.export}`,C.global){let U=C.global===!0?C.export:C.global;_+=`LT.${U} = ${M}
48
- `}}else C.global&&(M=`LT.${C.global===!0?y:C.global}`,P=!1);let x=new RegExp(`\\b${y}\\b`).test(r);if(P&&x&&(h?h.add(`LT.${E} = LT.${E} or {}`):b.add(`LT.${E} = LT.${E} or {}`)),C.alias&&x&&C.alias.forEach(U=>{_+=`${B}${U} = ${M}
49
- `}),!x)continue;let Z=new RegExp(`(^[ \\t]*function\\s+)${y}(\\s*\\()`,"gm");f=f.replace(Z,`$1${M}$2`);let oe=B.replace(/\./g,"\\."),I=new RegExp(`\\b${oe}(${y})(\\s*\\()`,"g");f=f.replace(I,"$1$2");let ie=new RegExp(`(^|[^a-zA-Z0-9_.:"'])(${y})(\\s*\\()`,"g");f=f.replace(ie,(U,q,pe,Ce)=>q.trim().endsWith("function")?U:`${q}${M}${Ce}`)}return h?f+(_.length>0?`
46
+ `}return null},y=b("shared"),E=b("client"),C=b("server");(y||E||C)&&(w.push({modName:r,ns:S,shared:y||"",client:E||"",server:C||""}),y&&(p=!0),E&&(h=!0),C&&(f=!0))};u.details&&(console.log(`
47
+ \x1B[1m\x1B[35m\u{1F4E6} Bundling Sequence (${a.length} modules):\x1B[0m`),a.forEach((r,T)=>console.log(` \x1B[90m${(T+1).toString().padStart(2,"0")}.\x1B[0m ${r}`)),console.log(""));for(let r of a)x(r);let $=on(),I=(r,T)=>{if(!o)return r;try{return $.Minify(r,{RenameVariables:!0,RenameGlobals:!1,SolveMath:!1})}catch(S){return console.log(`\x1B[33m! Minification failed for ${T}. Emitting unminified code. Error: ${S.message}\x1B[0m`),r}},q=["LT","QBCore","ESX","QBX","exports"],v=new Set,O=r=>{let T=/^([a-zA-Z_][a-zA-Z0-9_]*)\s*=/gm,S;for(;(S=T.exec(r))!==null;){let b=S[1];q.includes(b)||v.add(b)}},K=s.debug===!1||s.debug===void 0;for(let r of w)r.shared&&(r.shared=st(r.shared,{version:n,disableDebug:K}));if(o)for(let r of w)r.shared&&O(r.shared),r.client&&O(r.client),r.server&&O(r.server);let be=require("crypto"),se=r=>be.createHash("md5").update(r).digest("hex").substring(0,5),Q={},ae=new Set;for(let r of v){let T=se(r),S=0;for(;ae.has(T);)S++,T=se(r+S);ae.add(T),Q[r]="__"+T}let fe=r=>{if(!r)return r;let T=Object.keys(Q);if(T.length===0)return r;let S=T.sort((y,E)=>E.length-y.length).map(y=>y.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),b=new RegExp(`\\[\\[[\\s\\S]*?\\]\\]|'(?:[^'\\\\]|\\\\.)*'|"(?:[^"\\\\]|\\\\.)*"|\\b(${S.join("|")})\\b`,"g");return r.replace(b,(y,E)=>E&&Q[E]?Q[E]:y)};if(o)for(let r of w)r.shared=fe(r.shared),r.client=fe(r.client),r.server=fe(r.server);let ie={shared:new Set,client:new Set,server:new Set},de=(r,T)=>{if(!r)return r;let S=Object.keys(g).sort((C,F)=>F.length-C.length);if(S.length===0)return r;let b=r,y=new Set,E="";for(let C of S){let F=g[C],R=F?`LT.${F}.`:"LT.",G=_[C]||{};if(o&&G.internal){if(!Q[C]){let Te=se(C),Ce=0;for(;ae.has(Te);)Ce++,Te=se(C+Ce);ae.add(Te),Q[C]="__"+Te}let te=Q[C],Ee=new RegExp(`(^|[^a-zA-Z0-9_.:"'])(${C})(\\s*[=().,\\[\\]])`,"g");b=b.replace(Ee,`$1${te}$3`);continue}let B=`${R}${C}`,j=!!F;if(G.export){if(B=`${R}${G.export}`,G.global){let te=G.global===!0?G.export:G.global;E+=`LT.${te} = ${B}
48
+ `}}else G.global&&(B=`LT.${G.global===!0?C:G.global}`,j=!1);let V=new RegExp(`\\b${C}\\b`).test(r);if(j&&V&&(T?T.add(`LT.${F} = LT.${F} or {}`):y.add(`LT.${F} = LT.${F} or {}`)),G.alias&&V&&G.alias.forEach(te=>{E+=`${R}${te} = ${B}
49
+ `}),!V)continue;let A=new RegExp(`(^[ \\t]*function\\s+)${C}(\\s*\\()`,"gm");b=b.replace(A,`$1${B}$2`);let X=R.replace(/\./g,"\\."),ne=new RegExp(`\\b${X}(${C})(\\s*\\()`,"g");b=b.replace(ne,"$1$2");let D=new RegExp(`(^|[^a-zA-Z0-9_.:"'])(${C})(\\s*\\()`,"g");b=b.replace(D,(te,Ee,Te,Ce)=>Ee.trim().endsWith("function")?te:`${Ee}${B}${Ce}`)}return T?b+(E.length>0?`
50
50
  -- Exports
51
- ${_}`:""):`LT = LT or {}
52
- `+Array.from(b).join(`
53
- `)+(b.size>0?`
51
+ ${E}`:""):`LT = LT or {}
52
+ `+Array.from(y).join(`
53
+ `)+(y.size>0?`
54
54
 
55
55
  `:`
56
- `)+f+(_.length>0?`
56
+ `)+b+(E.length>0?`
57
57
  -- Exports
58
- ${_}`:"")},z={shared:"",client:"",server:""},ce=[];for(let r of S)r.shared=te(r.shared,t?null:ee.shared),r.client=te(r.client,t?null:ee.client),r.server=te(r.server,t?null:ee.server),t?(r.shared&&ce.push({path:Ve(r.modName,"shared"),content:$(r.shared,`${r.modName} shared.lua`),type:"shared",ns:r.ns}),r.client&&ce.push({path:Ve(r.modName,"client"),content:$(r.client,`${r.modName} client.lua`),type:"client",ns:r.ns}),r.server&&ce.push({path:Ve(r.modName,"server"),content:$(r.server,`${r.modName} server.lua`),type:"server",ns:r.ns})):(r.shared&&(z.shared+=$(r.shared,`${r.modName} shared.lua`)+`
59
- `),r.client&&(z.client+=$(r.client,`${r.modName} client.lua`)+`
60
- `),r.server&&(z.server+=$(r.server,`${r.modName} server.lua`)+`
61
- `));let _e=K.join(k,"ltbridge"),H=K.join(_e,"modules");W.ensureDirSync(H),W.emptyDirSync(H);let Re=`=== LTBridge Auto-Generated Modules ===
58
+ ${E}`:"")},ee={shared:"",client:"",server:""},ue=[];for(let r of w)r.shared=de(r.shared,c?null:ie.shared),r.client=de(r.client,c?null:ie.client),r.server=de(r.server,c?null:ie.server),c?(r.shared&&ue.push({path:Ve(r.modName,"shared"),content:I(r.shared,`${r.modName} shared.lua`),type:"shared",ns:r.ns}),r.client&&ue.push({path:Ve(r.modName,"client"),content:I(r.client,`${r.modName} client.lua`),type:"client",ns:r.ns}),r.server&&ue.push({path:Ve(r.modName,"server"),content:I(r.server,`${r.modName} server.lua`),type:"server",ns:r.ns})):(r.shared&&(ee.shared+=I(r.shared,`${r.modName} shared.lua`)+`
59
+ `),r.client&&(ee.client+=I(r.client,`${r.modName} client.lua`)+`
60
+ `),r.server&&(ee.server+=I(r.server,`${r.modName} server.lua`)+`
61
+ `));let ye=J.join(d,"ltbridge"),_e=new Set,z=(r,T)=>{let S=r.replace(/\\/g,"/"),b=J.join(ye,S);W.ensureDirSync(J.dirname(b)),W.writeFileSync(b,T),_e.add(S)},We=`=== LTBridge Auto-Generated Modules ===
62
62
  These files were automatically generated and/or minified by LTBridge.
63
63
  Repository: https://github.com/laot7490/ltbridge
64
64
  Last Build Time: ${new Date().toLocaleString()}
65
65
  LTBridge Version: ${n}
66
- `;W.writeFileSync(K.join(_e,"README.txt"),Re);let{injectManifest:Ee}=en(),Te=r=>`--[[
66
+ `;z("README.txt",We);let{injectManifest:k}=an(),L=r=>`--[[
67
67
  * @license LT Bridge
68
68
  * ${r.toLowerCase()}.lua
69
69
  *
@@ -73,10 +73,10 @@ LTBridge Version: ${n}
73
73
  * LICENSE file in the root directory of this source tree.
74
74
  ]]
75
75
 
76
- `;if(t){let r={shared:[],client:[],server:[]};for(let T of ce){let f=K.join(H,T.path);W.ensureDirSync(K.dirname(f)),W.writeFileSync(f,Te(T.type)+`--- @diagnostic disable
77
- `+T.content);let b=T.path.replace(/\\/g,"/").replace(/^imports\//,"");r[T.type].push(` "${b}"`)}let h=(T,f)=>f.length===0?"":`-- LTBridge Auto-Generated ${T} Loader
76
+ `;if(c){let r={shared:[],client:[],server:[]};for(let S of ue){let b="modules/"+S.path.replace(/\\/g,"/");z(b,L(S.type)+`--- @diagnostic disable
77
+ `+S.content);let y=S.path.replace(/\\/g,"/").replace(/^imports\//,"");r[S.type].push(` "${y}"`)}let T=(S,b)=>b.length===0?"":`-- LTBridge Auto-Generated ${S} Loader
78
78
  local loadSequence = {
79
- ${f.join(`,
79
+ ${b.join(`,
80
80
  `)}
81
81
  }
82
82
  for _, modPathSuffix in ipairs(loadSequence) do
@@ -93,28 +93,29 @@ for _, modPathSuffix in ipairs(loadSequence) do
93
93
  print("^6[LTBridge ${n}] ^1ERROR: Module file not found: " .. modPathSuffix .. "^7")
94
94
  end
95
95
  end
96
- `;a&&W.writeFileSync(K.join(H,"shared.lua"),h("Shared",r.shared)),g&&W.writeFileSync(K.join(H,"client.lua"),h("Client",r.client)),L&&W.writeFileSync(K.join(H,"server.lua"),h("Server",r.server)),Ee(k,g,L,a,!0)}else{let r=h=>`LT = LT or {}
97
- `+Array.from(ee[h]).join(`
98
- `)+(ee[h].size>0?`
96
+ `;p&&z("modules/shared.lua",T("Shared",r.shared)),h&&z("modules/client.lua",T("Client",r.client)),f&&z("modules/server.lua",T("Server",r.server)),k(d,h,f,p,!0)}else{let r=T=>`LT = LT or {}
97
+ `+Array.from(ie[T]).join(`
98
+ `)+(ie[T].size>0?`
99
99
 
100
100
  `:`
101
- `);a&&W.writeFileSync(K.join(H,"shared.lua"),Te("Shared")+`--- @diagnostic disable
102
- `+r("shared")+z.shared),g&&W.writeFileSync(K.join(H,"client.lua"),Te("Client")+`--- @diagnostic disable
103
- `+r("client")+z.client),L&&W.writeFileSync(K.join(H,"server.lua"),Te("Server")+`--- @diagnostic disable
104
- `+r("server")+z.server),Ee(k,g,L,a,!1)}console.log(`\x1B[32m\u2713\x1B[0m ${c.length} modules bundled in ${Date.now()-i}ms`)}function Ve(k,u){let d=k.split("/"),n="uncategorized",i=k;return k==="__init__"?(n="Core",i="init"):d.length>1?(n=d.slice(0,-1).join("/").replace(/^@/,""),i=d[d.length-1]):k.startsWith("@")?(n=k.replace(/^@/,""),i="init"):i=k.replace(/^@/,""),i==="init"?`imports/${n}/${u}.lua`:`imports/${n}/${i}/${u}.lua`}on.exports={rebuildBundle:Un,generateFullApi:tn,getModuleExportMap:nn}});var dn=re((St,fn)=>{var O=require("fs-extra"),ne=require("path"),{version:xe}=we(),{rebuildBundle:de,generateFullApi:ln,getModuleExportMap:Se}=rn(),{resolveDependencies:je}=Ie(),{getModuleRegistry:ae,getModuleData:$e}=ue(),ve=require("prompts"),le=ne.join("ltbridge","ltbridge.config.json");async function Wn(k,u={}){let d=ne.join(k,le);if(O.existsSync(d)&&!(await ve({type:"confirm",name:"value",message:"LTBridge is already initialized. Do you want to overwrite the configuration?",initial:!1})).value){console.log("\x1B[33m! Initialization cancelled.\x1B[0m");return}console.log(`
105
- \x1B[36m\u26A1 ltbridge v${xe}\x1B[0m \x1B[32mInitializing project...\x1B[0m
106
- `);let i=u.minify!==!1,l=u.debug===!0,e=!1;if(!process.argv.includes("--no-minify")&&!process.argv.includes("--debug")){let s=await ve([{type:"select",name:"buildMode",message:"Build Output Mode:",choices:[{title:"Individual (Separate files per module)",value:!1},{title:"Bundle (Combine all into 3 files)",value:!0}],initial:0},{type:"select",name:"minify",message:"Bundled code minification:",choices:[{title:"Enabled (Compact production code)",value:!0},{title:"Disabled (Readable development code)",value:!1}],initial:0},{type:"select",name:"debug",message:"Runtime debug mode:",choices:[{title:"Disabled (Recommended for production)",value:!1},{title:"Enabled (Detailed logs and helper outputs)",value:!0}],initial:0}]);s.buildMode!==void 0&&(e=s.buildMode),s.minify!==void 0&&(i=s.minify),s.debug!==void 0&&(l=s.debug)}let c={version:xe,buildAsBundle:e,debug:l,minify:i,modules:[]};O.ensureDirSync(ne.dirname(d)),O.writeFileSync(d,JSON.stringify(c,null,2)),console.log(`
107
- \x1B[32m\u2713 Created configuration: ${le}\x1B[0m`),console.log(`\x1B[90m\u2139 Build Mode: ${e?"bundle":"individual"}\x1B[0m`),console.log(`\x1B[90m\u2139 Minify: ${i?"enabled":"disabled"}\x1B[0m`),console.log(`\x1B[90m\u2139 Debug: ${l?"enabled":"disabled"}\x1B[0m
108
- `),ln(k)}function be(k){let u=ne.join(k,le);return O.existsSync(u)||(console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m"),process.exit(1)),JSON.parse(O.readFileSync(u,"utf-8"))}function ye(k,u){let d=ne.join(k,le);O.writeFileSync(d,JSON.stringify(u,null,2))}function sn(k,u){if(!k.endsWith("*")){let i=an(k,u);return i?[i]:[]}let d=k.replace(/\\/g,"/").replace(/^@/,"").replace(/\*$/,"").toLowerCase(),n=[];for(let i of Object.keys(u)){if(i==="__init__")continue;if(i.replace(/^@/,"").toLowerCase().startsWith(d)){let e=!1,t=$e(i);t&&t.meta&&(e=t.meta.internal===!0),e||n.push(i)}}return n}function an(k,u){if(u[k])return k;let d=k.replace(/\\/g,"/").replace(/^@/,"").toLowerCase(),n=[];for(let e of Object.keys(u)){if(e.replace(/^@/,"").toLowerCase()===d)return e;let c=e.split("/"),s=c[c.length-1].toLowerCase();(s===d||s===d.replace(/^@/,""))&&n.push(e)}if(n.length===1)return n[0];n.length>1&&(console.log(`\x1B[31m\u2716 Ambiguous module name '${k}'.\x1B[0m`),console.log("\x1B[90m\u2139 Did you mean one of these?\x1B[0m"),n.forEach(e=>console.log(` - ${e.replace(/^@/,"")}`)),process.exit(1));let i=Se(),l=k.replace(/^LT\./,"");if(i[l]){let e=i[l];if(e.length===1)return e[0];console.log(`\x1B[31m\u2716 Ambiguous export name '${k}' provided by multiple modules.\x1B[0m`),console.log("\x1B[90m\u2139 Please use the full module path to add it:\x1B[0m"),e.forEach(t=>console.log(` - ltbridge add ${t.replace(/^@/,"")}`)),process.exit(1)}return null}function Kn(k,u){let d=be(k),n=ae(),i=sn(u,n);i.length===0&&(console.log(`\x1B[31m\u2716 No modules found matching '${u}'.\x1B[0m`),process.exit(1));let l=0,e=!1;for(let t of i){if(t==="__init__")continue;let c=!1,s=$e(t);if(s&&s.meta&&(c=s.meta.internal===!0),c){u.endsWith("*")||(console.log(`\x1B[31m\u2716 Cannot manually add internal ghost module '${t}'.\x1B[0m`),console.log("\x1B[90m\u2139 Ghost modules are active and managed purely as auto-dependencies behind the scenes.\x1B[0m"),e=!0);continue}if(d.modules.includes(t)){u.endsWith("*")||console.log(`\x1B[90m\u2139 Module '${t}' is already added.\x1B[0m`);continue}d.modules.push(t),console.log(`\x1B[32m\u2713 Added module '${t}'.\x1B[0m`),l++}l>0?(ye(k,d),de(k,d,{skipApi:!0})):u.endsWith("*")&&console.log("\x1B[90m\u2139 All matching modules are already added.\x1B[0m")}function zn(k,u){let d=be(k),n=ae(),i=sn(u,n);i.length===0&&(console.log(`\x1B[31m\u2716 No modules found matching '${u}'.\x1B[0m`),process.exit(1));let l=0;for(let e of i){if(!d.modules.includes(e)){u.endsWith("*")||console.log(`\x1B[90m\u2139 Module '${e}' is not currently added.\x1B[0m`);continue}d.modules=d.modules.filter(t=>t!==e),console.log(`\x1B[33m- Removed module '${e}'.\x1B[0m`),l++}l>0?(ye(k,d),de(k,d,{skipApi:!0})):u.endsWith("*")&&console.log("\x1B[90m\u2139 No matching modules were currently added.\x1B[0m")}function Hn(k,u={}){let d=be(k);console.log(`
109
- \x1B[36m\u26A1 ltbridge v${xe}\x1B[0m \x1B[32mbuilding for production...\x1B[0m`),de(k,d,u)}function cn(k){let u=new Set;function d(n){if(!O.existsSync(n))return;let i=O.readdirSync(n);for(let l of i){if(l==="ltbridge"||l==="node_modules"||l===".git")continue;let e=ne.join(n,l);if(O.statSync(e).isDirectory())d(e);else if(l.endsWith(".lua")){let c=O.readFileSync(e,"utf8"),s=/LT\.([a-zA-Z0-9_.]+)/g,o;for(;(o=s.exec(c))!==null;){let g=o[1];u.add(g);let L=g.split("."),a="";for(let p of L)a=a?a+"."+p:p,u.add(a)}}}}return d(k),u}function un(k){let u=ae(),d=Object.keys(u),n=Se(),i=new Set;for(let l of k){let e="@"+l.replace(/\./g,"/");if(d.includes(e)){i.add(e);continue}if(n[l]){let t=n[l];if(t.length===1)i.add(t[0]);else if(l.includes(".")){let c=l.split(".")[0].toLowerCase(),s=t.find(o=>o.toLowerCase().includes(c));s&&i.add(s)}else{let c=require("fs"),s=require("path"),o=t.find(g=>{let L=u[g];if(!L)return!1;let a=s.join(L,"server.lua");return c.existsSync(a)&&c.readFileSync(a,"utf8").includes("@ltbridge global")});i.add(o||t[0])}}}return i}function Zn(k){let u=be(k);console.log("\x1B[90m\u2139 Scanning project for unused LT modules...\x1B[0m");let d=cn(k),n=un(d),i=[],l=[];for(let e of u.modules)n.has(e)?i.push(e):l.push(e);l.length>0?(console.log(`\x1B[32m\u2713 Pruned ${l.length} unused modules: ${l.join(", ")}\x1B[0m`),u.modules=i,ye(k,u)):console.log("\x1B[90m\u2139 No unused modules found. Everything is tightly integrated!\x1B[0m"),de(k,u,{skipApi:!0})}var fe=null;function Jn(k,u={}){let d=ae(),n=Object.keys(d),i="",l=ne.join(k,le);O.existsSync(l)&&(i=O.readFileSync(l,"utf-8"));function e(s=!1){let o=be(k),g=cn(k),L=un(g),a=!1,p=new Set(o.modules),m=[];for(let w of L)p.has(w)||(p.add(w),m.push(w),a=!0);let S=[];for(let w of o.modules)L.has(w)||(p.delete(w),S.push(w),a=!0);(a||s)&&(a&&(o.modules=Array.from(p)),i=JSON.stringify(o,null,2),a&&ye(k,o),de(k,o,{skipApi:!0,...u}))}console.log(`
110
- \x1B[36m\u26A1 ltbridge v${xe}\x1B[0m \x1B[32mwatching for changes...\x1B[0m`),e(!0),require("chokidar").watch(k,{ignored:[/(^|[\/\\])\../,/node_modules/,/ltbridge[\/\\]modules[\/\\]imports/,/ltbridge[\/\\]api\.lua/,/ltbridge[\/\\]shared\.lua/,/ltbridge[\/\\]client\.lua/,/ltbridge[\/\\]server\.lua/],persistent:!0,ignoreInitial:!0}).on("all",(s,o)=>{if(!o)return;let g=o.replace(/\\/g,"/");if(g.endsWith("ltbridge/ltbridge.config.json")||g.endsWith("ltbridge.config.json"))try{let L=O.readFileSync(l,"utf-8");if(L===i)return;i=L,fe&&clearTimeout(fe),fe=setTimeout(()=>{e(!0)},300);return}catch{return}g.includes("ltbridge/")&&!g.endsWith("ltbridge.config.json")||(fe&&clearTimeout(fe),fe=setTimeout(()=>{try{e()}catch(L){console.log(`\x1B[31m\u2716 Watcher error: ${L.message}\x1B[0m`)}},300))})}function Qn(k){let u=ae(),d=Object.keys(u).filter(a=>{if(a==="__init__")return!1;let p=$e(a);return!(p&&p.meta&&p.meta.internal===!0)}),n=null,i=ne.join(k,le);if(O.existsSync(i))try{n=JSON.parse(O.readFileSync(i,"utf-8"))}catch{}let l=n?new Set(n.modules):new Set,e=new Set,t={};if(n&&n.modules){let{graph:a}=je(n.modules,Se());for(let[p,m]of Object.entries(a))for(let S of m)e.add(S),t[S]||(t[S]=[]),t[S].includes(p)||t[S].push(p)}let c=new Set(d),s=new Set([...l].filter(a=>c.has(a))),o=new Set([...e].filter(a=>c.has(a)&&!s.has(a))),g=s.size+o.size;if(console.log(`
111
- \x1B[1m\x1B[36m\u2139 LTBridge Modules List (${s.size} manual + ${o.size} auto = ${g} active / ${d.length} total)\x1B[0m
112
- `),d.length===0){console.log(" No modules found in the repository.");return}let L={};for(let a of d){let p=u[a],m=[];if(p){let F=p.split("/");for(let $=0;$<F.length-1;$++){let G=F[$];(G.startsWith("@")||G.startsWith("#"))&&(G=G.substring(1)),m.push(G)}}let S=m.length>0?m.join(" / "):"Uncategorized",w=a.split("/").pop();L[S]||(L[S]=[]),L[S].push({mod:a,name:w})}for(let a of Object.keys(L).sort()){console.log(`
113
- \x1B[1m\x1B[35m\u{1F4C1} ${a}\x1B[0m`);let p=L[a],S="@"+a.split(" / ").pop(),F=(p.length>1?p.filter($=>$.mod!==S):p).sort(($,G)=>$.name.localeCompare(G.name));for(let{mod:$,name:G}of F){let A=l.has($),R=e.has($),N=" ",V="\x1B[90m";A?(N="\u2714",V="\x1B[32m"):R&&(N="\u2699",V="\x1B[33m"),process.stdout.write(` ${V}${N} ${G.padEnd(30)}\x1B[0m`),R&&!A?process.stdout.write(" \x1B[90m\u2699 Auto-Dependency\x1B[0m"):R&&A&&process.stdout.write(" \x1B[90m(Also a Dependency)\x1B[0m"),process.stdout.write(`
101
+ `);p&&z("modules/shared.lua",L("Shared")+`--- @diagnostic disable
102
+ `+r("shared")+ee.shared),h&&z("modules/client.lua",L("Client")+`--- @diagnostic disable
103
+ `+r("client")+ee.client),f&&z("modules/server.lua",L("Server")+`--- @diagnostic disable
104
+ `+r("server")+ee.server),k(d,h,f,p,!1)}ut(ye,_e),console.log(`\x1B[32m\u2713\x1B[0m ${a.length} modules bundled in ${Date.now()-i}ms`)}function ut(d,s){let u=J.join(d,"modules");W.existsSync(u)&&fn(u,d,s);let n=J.join(d,"README.txt");W.existsSync(n)&&!s.has("README.txt")&&W.removeSync(n)}function fn(d,s,u){for(let n of W.readdirSync(d)){let t=J.join(d,n),i=J.relative(s,t).replace(/\\/g,"/");W.statSync(t).isDirectory()?(fn(t,s,u),W.existsSync(t)&&W.readdirSync(t).length===0&&W.removeSync(t)):u.has(i)||W.removeSync(t)}}function Ve(d,s){let u=d.split("/"),n="uncategorized",t=d;return d==="__init__"?(n="Core",t="init"):u.length>1?(n=u.slice(0,-1).join("/").replace(/^@/,""),t=u[u.length-1]):d.startsWith("@")?(n=d.replace(/^@/,""),t="init"):t=d.replace(/^@/,""),t==="init"?`imports/${n}/${s}.lua`:`imports/${n}/${t}/${s}.lua`}dn.exports={rebuildBundle:at,generateFullApi:cn,getModuleExportMap:un}});var pn=H((Jt,Tn)=>{var{getModuleRegistry:ct,getModuleData:ft}=oe(),{resolveDependencies:dt}=xe(),{getModuleExportMap:Tt}=ve();function pt(){let d=ct();return Object.keys(d).filter(s=>{if(s==="__init__")return!1;let u=ft(s);return!(u&&u.meta&&u.meta.internal===!0)})}function ht(d,s){let u={};for(let n of d){let t=s[n],i=[];if(t){let c=t.split("/");for(let a=0;a<c.length-1;a++){let l=c[a];(l.startsWith("@")||l.startsWith("#"))&&(l=l.substring(1)),i.push(l)}}let e=i.length>0?i.join(" / "):"Uncategorized",o=n.split("/").pop();u[e]||(u[e]=[]),u[e].push({mod:n,name:o})}return u}function mt(d){let s=new Set;if(d&&d.length>0){let{graph:u}=dt(d,Tt());for(let n of Object.values(u))for(let t of n)s.add(t)}return s}function kt(d,s){let n="@"+s.split(" / ").pop();return(d.length>1?d.filter(i=>i.mod!==n):d).sort((i,e)=>i.name.localeCompare(e.name))}Tn.exports={getVisibleModules:pt,buildModuleGroups:ht,getDependencySets:mt,getFilteredSortedMods:kt}});var wn=H((Zt,Fn)=>{var N=require("fs-extra"),M=require("path"),{version:Re}=Fe(),{rebuildBundle:le,generateFullApi:mn,getModuleExportMap:qe}=ve(),{resolveDependencies:gt}=xe(),{getModuleRegistry:ce,getModuleData:kn}=oe(),{pickExportModule:Lt}=Ie(),{getVisibleModules:gn,buildModuleGroups:Ln,getDependencySets:Sn,getFilteredSortedMods:bn}=pn(),De=require("prompts"),Y=M.join("ltbridge","ltbridge.config.json");async function St(d,s={}){let u=M.join(d,Y);if(N.existsSync(u)&&!(await De({type:"confirm",name:"value",message:"LTBridge is already initialized. Do you want to overwrite the configuration?",initial:!1})).value){console.log("\x1B[33m! Initialization cancelled.\x1B[0m");return}console.log(`
105
+ \x1B[36m\u26A1 ltbridge v${Re}\x1B[0m \x1B[32mInitializing project...\x1B[0m
106
+ `);let t=s.minify!==!1,i=s.debug===!0,e=!1;if(!process.argv.includes("--no-minify")&&!process.argv.includes("--debug")){let a=await De([{type:"select",name:"buildMode",message:"Build Output Mode:",choices:[{title:"Individual (Separate files per module)",value:!1},{title:"Bundle (Combine all into 3 files)",value:!0}],initial:0},{type:"select",name:"minify",message:"Bundled code minification:",choices:[{title:"Enabled (Compact production code)",value:!0},{title:"Disabled (Readable development code)",value:!1}],initial:0},{type:"select",name:"debug",message:"Runtime debug mode:",choices:[{title:"Disabled (Recommended for production)",value:!1},{title:"Enabled (Detailed logs and helper outputs)",value:!0}],initial:0}]);a.buildMode!==void 0&&(e=a.buildMode),a.minify!==void 0&&(t=a.minify),a.debug!==void 0&&(i=a.debug)}let c={version:Re,buildAsBundle:e,debug:i,minify:t,modules:[]};N.ensureDirSync(M.dirname(u)),N.writeFileSync(u,JSON.stringify(c,null,2)),console.log(`
107
+ \x1B[32m\u2713 Created configuration: ${Y}\x1B[0m`),console.log(`\x1B[90m\u2139 Build Mode: ${e?"bundle":"individual"}\x1B[0m`),console.log(`\x1B[90m\u2139 Minify: ${t?"enabled":"disabled"}\x1B[0m`),console.log(`\x1B[90m\u2139 Debug: ${i?"enabled":"disabled"}\x1B[0m
108
+ `),mn(d),s.noBuild!==!0&&le(d,c)}function Le(d){let s=M.join(d,Y);return N.existsSync(s)||(console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m"),process.exit(1)),JSON.parse(N.readFileSync(s,"utf-8"))}function Se(d,s){let u=M.join(d,Y);N.writeFileSync(u,JSON.stringify(s,null,2))}function yn(d,s){if(!d.endsWith("*")){let t=_n(d,s);return t?[t]:[]}let u=d.replace(/\\/g,"/").replace(/^@/,"").replace(/\*$/,"").toLowerCase(),n=[];for(let t of Object.keys(s)){if(t==="__init__")continue;if(t.replace(/^@/,"").toLowerCase().startsWith(u)){let e=!1,o=kn(t);o&&o.meta&&(e=o.meta.internal===!0),e||n.push(t)}}return n}function _n(d,s){if(s[d])return d;let u=d.replace(/\\/g,"/").replace(/^@/,"").toLowerCase(),n=[];for(let e of Object.keys(s)){if(e.replace(/^@/,"").toLowerCase()===u)return e;let c=e.split("/"),a=c[c.length-1].toLowerCase();(a===u||a===u.replace(/^@/,""))&&n.push(e)}if(n.length===1)return n[0];n.length>1&&(console.log(`\x1B[31m\u2716 Ambiguous module name '${d}'.\x1B[0m`),console.log("\x1B[90m\u2139 Did you mean one of these?\x1B[0m"),n.forEach(e=>console.log(` - ${e.replace(/^@/,"")}`)),process.exit(1));let t=qe(),i=d.replace(/^LT\./,"");if(t[i]){let e=t[i];if(e.length===1)return e[0];console.log(`\x1B[31m\u2716 Ambiguous export name '${d}' provided by multiple modules.\x1B[0m`),console.log("\x1B[90m\u2139 Please use the full module path to add it:\x1B[0m"),e.forEach(o=>console.log(` - ltbridge add ${o.replace(/^@/,"")}`)),process.exit(1)}return null}function bt(d,s){let u=Le(d),n=ce(),t=yn(s,n);t.length===0&&(console.log(`\x1B[31m\u2716 No modules found matching '${s}'.\x1B[0m`),process.exit(1));let i=0,e=!1;for(let o of t){if(o==="__init__")continue;let c=!1,a=kn(o);if(a&&a.meta&&(c=a.meta.internal===!0),c){s.endsWith("*")||(console.log(`\x1B[31m\u2716 Cannot manually add internal ghost module '${o}'.\x1B[0m`),console.log("\x1B[90m\u2139 Ghost modules are active and managed purely as auto-dependencies behind the scenes.\x1B[0m"),e=!0);continue}if(u.modules.includes(o)){s.endsWith("*")||console.log(`\x1B[90m\u2139 Module '${o}' is already added.\x1B[0m`);continue}u.modules.push(o),console.log(`\x1B[32m\u2713 Added module '${o}'.\x1B[0m`),i++}i>0?(Se(d,u),le(d,u,{skipApi:!0})):s.endsWith("*")?(e&&(console.log(`\x1B[31m\u2716 No addable modules matched '${s}' (internal-only modules are auto-managed).\x1B[0m`),process.exit(1)),console.log("\x1B[90m\u2139 All matching modules are already added.\x1B[0m")):e&&process.exit(1)}function yt(d,s){let u=Le(d),n=ce(),t=yn(s,n);t.length===0&&(console.log(`\x1B[31m\u2716 No modules found matching '${s}'.\x1B[0m`),process.exit(1));let i=0;for(let e of t){if(!u.modules.includes(e)){s.endsWith("*")||console.log(`\x1B[90m\u2139 Module '${e}' is not currently added.\x1B[0m`);continue}u.modules=u.modules.filter(o=>o!==e),console.log(`\x1B[33m- Removed module '${e}'.\x1B[0m`),i++}i>0?(Se(d,u),le(d,u,{skipApi:!0})):s.endsWith("*")&&console.log("\x1B[90m\u2139 No matching modules were currently added.\x1B[0m")}function _t(d,s={}){let u=Le(d);console.log(`
109
+ \x1B[36m\u26A1 ltbridge v${Re}\x1B[0m \x1B[32mbuilding for production...\x1B[0m`),le(d,u,s)}function En(d){let s=new Set;function u(n){if(!N.existsSync(n))return;let t=N.readdirSync(n);for(let i of t){if(i==="ltbridge"||i==="node_modules"||i===".git")continue;let e=M.join(n,i);if(N.statSync(e).isDirectory())u(e);else if(i.endsWith(".lua")){let c=N.readFileSync(e,"utf8"),a=/LT\.([a-zA-Z0-9_.]+)/g,l;for(;(l=a.exec(c))!==null;){let m=l[1];s.add(m);let h=m.split("."),f="";for(let p of h)f=f?f+"."+p:p,s.add(f)}}}}return u(d),s}function Cn(d){let s=ce(),u=Object.keys(s),n=qe(),t=new Set;for(let i of d){let e="@"+i.replace(/\./g,"/");if(u.includes(e)){t.add(e);continue}if(n[i]){let o=Lt(i,n[i]);o&&t.add(o)}}return t}function Et(d){let s=Le(d);console.log("\x1B[90m\u2139 Scanning project for unused LT modules...\x1B[0m");let u=En(d),n=Cn(u),t=[],i=[];for(let e of s.modules)n.has(e)?t.push(e):i.push(e);i.length>0?(console.log(`\x1B[32m\u2713 Pruned ${i.length} unused modules: ${i.join(", ")}\x1B[0m`),s.modules=t,Se(d,s)):console.log("\x1B[90m\u2139 No unused modules found. Everything is tightly integrated!\x1B[0m"),le(d,s,{skipApi:!0})}var Oe=null,$e=!1,je=!1;function hn(d,s){if(!s)return!0;let u=M.resolve(d),n=M.resolve(M.isAbsolute(s)?s:M.join(u,s)),t=M.relative(u,n).replace(/\\/g,"/");if(t===""||t===".")return!1;if(t.startsWith("..")||t.includes("node_modules")||t==="ltbridge/modules"||t.startsWith("ltbridge/modules/")||t==="ltbridge/api.lua"||t==="fxmanifest.lua"||t==="__resource.lua")return!0;if(t.endsWith("ltbridge.config.json"))return!1;let i;try{i=N.statSync(n)}catch{return!0}return i.isDirectory()?!1:!t.endsWith(".lua")}function Ct(d,s={}){let u="",n=M.join(d,Y);N.existsSync(n)&&(u=N.readFileSync(n,"utf-8"));function t(c=!1){if($e){je=!0;return}let a=Le(d),l=En(d),m=Cn(l),h=!1,f=new Set(a.modules);for(let p of m)f.has(p)||(f.add(p),h=!0);for(let p of a.modules)m.has(p)||(f.delete(p),h=!0);if(!(!h&&!c)){$e=!0;try{h&&(a.modules=Array.from(f)),u=JSON.stringify(a,null,2),h&&Se(d,a),le(d,a,{skipApi:!0,...s})}finally{$e=!1,je&&(je=!1,i())}}}function i(){Oe&&clearTimeout(Oe),Oe=setTimeout(()=>{try{t(!0)}catch(c){console.log(`\x1B[31m\u2716 Watcher error: ${c.message}\x1B[0m`)}},400)}console.log(`
110
+ \x1B[36m\u26A1 ltbridge v${Re}\x1B[0m \x1B[32mwatching for changes...\x1B[0m`),t(!0);let o=require("chokidar").watch(d,{ignored:c=>hn(d,c),persistent:!0,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:150,pollInterval:50}});o.on("ready",()=>{console.log(`\x1B[90m\u2139 Watching Lua files in ${M.resolve(d)} (Ctrl+C to stop)\x1B[0m
111
+ `)}),o.on("error",c=>{console.log(`\x1B[31m\u2716 Watcher error: ${c.message}\x1B[0m`)}),o.on("all",(c,a)=>{if($e||!a||hn(d,a)||c!=="change"&&c!=="add")return;let l=M.isAbsolute(a)?a:M.join(d,a),m=M.relative(d,l).replace(/\\/g,"/");if(m.endsWith("ltbridge.config.json")||m===M.basename(Y).replace(/\\/g,"/"))try{if(N.readFileSync(n,"utf-8")===u)return}catch{return}i()})}function Ft(d){let s=ce(),u=gn(),n=null,t=M.join(d,Y);if(N.existsSync(t))try{n=JSON.parse(N.readFileSync(t,"utf-8"))}catch{}let i=n?new Set(n.modules):new Set,e=Sn(n?n.modules:[]),o=new Set(u),c=new Set([...i].filter(h=>o.has(h))),a=new Set([...e].filter(h=>o.has(h)&&!c.has(h))),l=c.size+a.size;if(console.log(`
112
+ \x1B[1m\x1B[36m\u2139 LTBridge Modules List (${c.size} manual + ${a.size} auto = ${l} active / ${u.length} total)\x1B[0m
113
+ `),u.length===0){console.log(" No modules found in the repository.");return}let m=Ln(u,s);for(let h of Object.keys(m).sort()){console.log(`
114
+ \x1B[1m\x1B[35m\u{1F4C1} ${h}\x1B[0m`);let f=bn(m[h],h);for(let{mod:p,name:g}of f){let _=i.has(p),w=e.has(p),x=" ",$="\x1B[90m";_?(x="\u2714",$="\x1B[32m"):w&&(x="\u2699",$="\x1B[33m"),process.stdout.write(` ${$}${x} ${g.padEnd(30)}\x1B[0m`),w&&!_?process.stdout.write(" \x1B[90m\u2699 Auto-Dependency\x1B[0m"):w&&_&&process.stdout.write(" \x1B[90m(Also a Dependency)\x1B[0m"),process.stdout.write(`
114
115
  `)}}console.log(`
115
116
  \x1B[90m(\u2714 = Installed | \u2699 = Auto Dependency)\x1B[0m
116
- `)}async function Xn(k){let u=ae(),d=Object.keys(u).filter(m=>{if(m==="__init__")return!1;let S=$e(m);return!(S&&S.meta&&S.meta.internal===!0)}),n=null,i=ne.join(k,le);if(O.existsSync(i))try{n=JSON.parse(O.readFileSync(i,"utf-8"))}catch{}if(!n){console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m");return}let l=new Set(n.modules||[]),{graph:e}=je(n.modules||[],Se()),t=new Set,c={};for(let[m,S]of Object.entries(e))for(let w of S)t.add(w),c[w]||(c[w]=[]),c[w].includes(m)||c[w].push(m);let s={};for(let m of d){let S=u[m],w=[];if(S){let G=S.split("/");for(let A=0;A<G.length-1;A++){let R=G[A];(R.startsWith("@")||R.startsWith("#"))&&(R=R.substring(1)),w.push(R)}}let F=w.length>0?w.join(" / "):"Uncategorized",$=m.split("/").pop();s[F]||(s[F]=[]),s[F].push({mod:m,name:$})}let o=[];for(let m of Object.keys(s).sort()){o.push({title:`\x1B[1m\x1B[36m--- ${m.toUpperCase()} ---\x1B[0m`,value:`__group_${m}__`,disabled:!0});let S=s[m],F="@"+m.split(" / ").pop(),G=(S.length>1?S.filter(A=>A.mod!==F):S).sort((A,R)=>A.name.localeCompare(R.name));for(let{mod:A,name:R}of G){let N=l.has(A),V=t.has(A),j=R;V&&!N?j=`${j} \x1B[90m(\u2699 Auto-Dependency [INCLUDED])\x1B[0m`:V&&N&&(j=`${j} \x1B[90m(Also a Dependency)\x1B[0m`),o.push({title:j,value:A,selected:N,disabled:V&&!N})}}let g=await ve({type:"multiselect",name:"selectedModules",message:"Select LTBridge modules",choices:o,instructions:!1,hint:"- [Space] select. [Return] submit",min:0});if(!g.selectedModules){console.log("\x1B[90m\u2139 Module selection cancelled.\x1B[0m");return}let L=g.selectedModules.filter(m=>!m.startsWith("__group_")),a=L.filter(m=>!l.has(m)),p=Array.from(l).filter(m=>!L.includes(m));if(a.length===0&&p.length===0){console.log("\x1B[90m\u2139 No changes made to module selection.\x1B[0m");return}a.length>0&&console.log(`\x1B[32m\u2713 Adding: ${a.join(", ")}\x1B[0m`),p.length>0&&console.log(`\x1B[33m- Removing: ${p.join(", ")}\x1B[0m`),n.modules=L,ye(k,n),de(k,n,{skipApi:!0})}function Yn(k,u){let d=ae(),n=an(u,d);n||(console.log(`\x1B[31m\u2716 Module '${u}' does not exist in the repository.\x1B[0m`),process.exit(1));let i=ne.join(k,le);if(!O.existsSync(i)){console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m");return}let l={modules:[]};try{l=JSON.parse(O.readFileSync(i,"utf-8"))}catch{}let e=new Set(l.modules||[]),{graph:t}=je(l.modules||[],Se()),c={};for(let[L,a]of Object.entries(t))for(let p of a)c[p]||(c[p]=[]),c[p].includes(L)||c[p].push(L);let s=e.has(n),o=c[n]||[],g=o.length>0;if(console.log(`
117
- \x1B[1m\x1B[36m\u2139 Why is '${n}' included in your project?\x1B[0m`),!s&&!g){console.log(` \x1B[90m\u25CB This module is NOT currently included in your project build.\x1B[0m
118
- `);return}if(s&&console.log(" \x1B[32m\u2714 You explicitly added it to your ltbridge.config.json\x1B[0m"),g){console.log(" \x1B[33m\u2699 It is automatically included as a dependency for the following modules:\x1B[0m");for(let L of o)console.log(` - ${L}`)}console.log("")}fn.exports={initProject:Wn,addModule:Kn,removeModule:zn,refreshModules:Hn,pruneModules:Zn,watchProject:Jn,generateFullApi:ln,listModules:Qn,interactiveSelect:Xn,explainModule:Yn}});var{program:Q}=require("commander"),{version:et}=we(),{initProject:nt,addModule:tt,removeModule:ot,refreshModules:it,pruneModules:rt,watchProject:lt,generateFullApi:Tn,listModules:st,interactiveSelect:at,explainModule:ct}=dn();Q.name("ltbridge").description("LT Bridge CLI tool for managing Lua modules and intellisense stubs").version(et);Q.command("init").description("Initialize LTBridge in the current directory and generate Master API stubs").option("--no-minify","Disable minification").option("--debug","Enable debug mode").action(async k=>{let u=process.cwd();await nt(u,k)});Q.command("build").alias("refresh").alias("install").alias("sync").description("Resolve dependencies, rebuild bundles, and regenerate API stubs").option("-w, --watch","Watch project mode for continuous bundling").option("-d, --details","Show detailed bundling sequence").action(k=>{let u=process.cwd();k.watch?lt(u,k):it(u,k)});Q.command("api").description("Regenerate the API stubs for IDE intellisense (Internal use for developers)").action(()=>{let k=process.cwd();console.log(`
119
- \x1B[36m\u26A1 ltbridge\x1B[0m \x1B[32mRegenerating API stubs...\x1B[0m`),Tn(k),console.log(`\x1B[32m\u2713 API reference successfully updated.\x1B[0m
120
- `)});Q.command("add <name>").description("Add a module to your project").action(k=>{tt(process.cwd(),k)});Q.command("remove <name>").description("Remove a module from your project").action(k=>{ot(process.cwd(),k)});Q.command("why <name>").alias("explain").description("Explain why a module is included in your project (dependency graph)").action(k=>{ct(process.cwd(),k)});Q.command("list").description("List installed and available modules").action(()=>{st(process.cwd())});Q.command("prune").description("Prune unused modules from your project bundles").action(()=>{rt(process.cwd())});Q.command("api").description("Standalone: Regenerate the Comprehensive Master API stubs").action(()=>{Tn(process.cwd())});process.argv.length<=2?at(process.cwd()):Q.parse(process.argv);
117
+ `)}async function wt(d){let s=ce(),u=gn(),n=null,t=M.join(d,Y);if(N.existsSync(t))try{n=JSON.parse(N.readFileSync(t,"utf-8"))}catch{}if(!n){console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m");return}let i=new Set(n.modules||[]),e=Sn(n.modules||[]),o=Ln(u,s),c=[];for(let f of Object.keys(o).sort()){c.push({title:`\x1B[1m\x1B[36m--- ${f.toUpperCase()} ---\x1B[0m`,value:`__group_${f}__`,disabled:!0});let p=bn(o[f],f);for(let{mod:g,name:_}of p){let w=i.has(g),x=e.has(g),$=_;x&&!w?$=`${$} \x1B[90m(\u2699 Auto-Dependency [INCLUDED])\x1B[0m`:x&&w&&($=`${$} \x1B[90m(Also a Dependency)\x1B[0m`),c.push({title:$,value:g,selected:w,disabled:x&&!w})}}let a=await De({type:"multiselect",name:"selectedModules",message:"Select LTBridge modules",choices:c,instructions:!1,hint:"- [Space] select. [Return] submit",min:0});if(!a.selectedModules){console.log("\x1B[90m\u2139 Module selection cancelled.\x1B[0m");return}let l=a.selectedModules.filter(f=>!f.startsWith("__group_")),m=l.filter(f=>!i.has(f)),h=Array.from(i).filter(f=>!l.includes(f));if(m.length===0&&h.length===0){console.log("\x1B[90m\u2139 No changes made to module selection.\x1B[0m");return}m.length>0&&console.log(`\x1B[32m\u2713 Adding: ${m.join(", ")}\x1B[0m`),h.length>0&&console.log(`\x1B[33m- Removing: ${h.join(", ")}\x1B[0m`),n.modules=l,Se(d,n),le(d,n,{skipApi:!0})}function xt(d,s){let u=ce(),n=_n(s,u);n||(console.log(`\x1B[31m\u2716 Module '${s}' does not exist in the repository.\x1B[0m`),process.exit(1));let t=M.join(d,Y);if(!N.existsSync(t)){console.log("\x1B[31m\u2716 Not an LTBridge initialized directory. Run 'ltbridge init' first.\x1B[0m");return}let i={modules:[]};try{i=JSON.parse(N.readFileSync(t,"utf-8"))}catch{}let e=new Set(i.modules||[]),{graph:o}=gt(i.modules||[],qe()),c={};for(let[h,f]of Object.entries(o))for(let p of f)c[p]||(c[p]=[]),c[p].includes(h)||c[p].push(h);let a=e.has(n),l=c[n]||[],m=l.length>0;if(console.log(`
118
+ \x1B[1m\x1B[36m\u2139 Why is '${n}' included in your project?\x1B[0m`),!a&&!m){console.log(` \x1B[90m\u25CB This module is NOT currently included in your project build.\x1B[0m
119
+ `);return}if(a&&console.log(" \x1B[32m\u2714 You explicitly added it to your ltbridge.config.json\x1B[0m"),m){console.log(" \x1B[33m\u2699 It is automatically included as a dependency for the following modules:\x1B[0m");for(let h of l)console.log(` - ${h}`)}console.log("")}Fn.exports={initProject:St,addModule:bt,removeModule:yt,refreshModules:_t,pruneModules:Et,watchProject:Ct,generateFullApi:mn,listModules:Ft,interactiveSelect:wt,explainModule:xt}});var{program:Z}=require("commander"),{version:Bt}=Fe(),{initProject:Gt,addModule:$t,removeModule:Rt,refreshModules:At,pruneModules:It,watchProject:Pt,generateFullApi:Mt,listModules:Nt,interactiveSelect:Vt,explainModule:vt}=wn();Z.name("ltbridge").description("LT Bridge CLI tool for managing Lua modules and intellisense stubs").version(Bt);Z.command("init").description("Initialize LTBridge in the current directory and generate Master API stubs").option("--no-minify","Disable minification").option("--debug","Enable debug mode").option("--no-build","Skip initial bundle after init (api stubs still generated)").action(async d=>{let s=process.cwd();await Gt(s,d)});Z.command("build").alias("refresh").alias("install").alias("sync").description("Resolve dependencies, rebuild bundles, and regenerate API stubs").option("-w, --watch","Watch project mode for continuous bundling").option("-d, --details","Show detailed bundling sequence").action(d=>{let s=process.cwd();d.watch?Pt(s,d):At(s,d)});Z.command("api").description("Regenerate the API stubs for IDE intellisense (Internal use for developers)").action(()=>{let d=process.cwd();console.log(`
120
+ \x1B[36m\u26A1 ltbridge\x1B[0m \x1B[32mRegenerating API stubs...\x1B[0m`),Mt(d),console.log(`\x1B[32m\u2713 API reference successfully updated.\x1B[0m
121
+ `)});Z.command("add <name>").description("Add a module to your project").action(d=>{$t(process.cwd(),d)});Z.command("remove <name>").description("Remove a module from your project").action(d=>{Rt(process.cwd(),d)});Z.command("why <name>").alias("explain").description("Explain why a module is included in your project (dependency graph)").action(d=>{vt(process.cwd(),d)});Z.command("list").description("List installed and available modules").action(()=>{Nt(process.cwd())});Z.command("prune").description("Prune unused modules from your project bundles").action(()=>{It(process.cwd())});process.argv.length<=2?Vt(process.cwd()):Z.parse(process.argv);