@laot/bridge 1.2.7 → 1.3.1

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