binja 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,44 +1,44 @@
1
1
  // @bun
2
- var d=import.meta.require;var b;((I)=>{I.TEXT="TEXT";I.EOF="EOF";I.VARIABLE_START="VARIABLE_START";I.VARIABLE_END="VARIABLE_END";I.BLOCK_START="BLOCK_START";I.BLOCK_END="BLOCK_END";I.COMMENT_START="COMMENT_START";I.COMMENT_END="COMMENT_END";I.NAME="NAME";I.STRING="STRING";I.NUMBER="NUMBER";I.DOT="DOT";I.COMMA="COMMA";I.COLON="COLON";I.PIPE="PIPE";I.LPAREN="LPAREN";I.RPAREN="RPAREN";I.LBRACKET="LBRACKET";I.RBRACKET="RBRACKET";I.LBRACE="LBRACE";I.RBRACE="RBRACE";I.EQ="EQ";I.NE="NE";I.LT="LT";I.GT="GT";I.LE="LE";I.GE="GE";I.ADD="ADD";I.SUB="SUB";I.MUL="MUL";I.DIV="DIV";I.MOD="MOD";I.AND="AND";I.OR="OR";I.NOT="NOT";I.ASSIGN="ASSIGN";I.TILDE="TILDE"})(b||={});var m={and:"AND",or:"OR",not:"NOT",true:"NAME",false:"NAME",True:"NAME",False:"NAME",None:"NAME",none:"NAME",is:"NAME",in:"NAME"};var u={red:"\x1B[31m",yellow:"\x1B[33m",cyan:"\x1B[36m",gray:"\x1B[90m",bold:"\x1B[1m",dim:"\x1B[2m",reset:"\x1B[0m"},zB=process.stdout?.isTTY!==!1;function E(B,K){return zB?`${u[B]}${K}${u.reset}`:K}class r extends Error{line;column;source;templateName;suggestion;availableOptions;constructor(B,K){let A=p("TemplateError",B,K);super(A);this.name="TemplateError",this.line=K.line,this.column=K.column,this.source=K.source,this.templateName=K.templateName,this.suggestion=K.suggestion,this.availableOptions=K.availableOptions}}class P extends Error{line;column;source;templateName;suggestion;constructor(B,K){let A=p("TemplateSyntaxError",B,K);super(A);this.name="TemplateSyntaxError",this.line=K.line,this.column=K.column,this.source=K.source,this.templateName=K.templateName,this.suggestion=K.suggestion}}class y extends Error{line;column;source;templateName;suggestion;availableOptions;constructor(B,K){let A=p("TemplateRuntimeError",B,K);super(A);this.name="TemplateRuntimeError",this.line=K.line,this.column=K.column,this.source=K.source,this.templateName=K.templateName,this.suggestion=K.suggestion,this.availableOptions=K.availableOptions}}function p(B,K,A){let $=[],Q=A.templateName?`${A.templateName}:${A.line}:${A.column}`:`line ${A.line}, column ${A.column}`;if($.push(`${E("red",E("bold",B))}: ${K} at ${E("cyan",Q)}`),A.source)$.push(""),$.push(EB(A.source,A.line,A.column));if(A.suggestion)$.push(""),$.push(`${E("yellow","Did you mean")}: ${E("cyan",A.suggestion)}?`);if(A.availableOptions&&A.availableOptions.length>0){$.push("");let O=A.availableOptions.slice(0,8),U=A.availableOptions.length>8?` ${E("gray",`... and ${A.availableOptions.length-8} more`)}`:"";$.push(`${E("gray","Available")}: ${O.join(", ")}${U}`)}return $.join(`
3
- `)}function EB(B,K,A){let $=B.split(`
4
- `),Q=[],O=Math.max(1,K-2),U=Math.min($.length,K+1),Y=String(U).length;for(let Z=O;Z<=U;Z++){let J=$[Z-1]||"",X=String(Z).padStart(Y," ");if(Z===K){Q.push(`${E("red"," \u2192")} ${E("gray",X)} ${E("dim","\u2502")} ${J}`);let G=" ".repeat(Y+4+Math.max(0,A-1)),R=E("red","^");Q.push(`${G}${R}`)}else Q.push(` ${E("gray",X)} ${E("dim","\u2502")} ${E("gray",J)}`)}return Q.join(`
5
- `)}function l(B,K,A=3){let $=null,Q=A+1,O=B.toLowerCase();for(let U of K){let Y=WB(O,U.toLowerCase());if(Y<Q)Q=Y,$=U}return Q<=A?$:null}function WB(B,K){if(B.length===0)return K.length;if(K.length===0)return B.length;let A=[];for(let $=0;$<=K.length;$++)A[$]=[$];for(let $=0;$<=B.length;$++)A[0][$]=$;for(let $=1;$<=K.length;$++)for(let Q=1;Q<=B.length;Q++)if(K[$-1]===B[Q-1])A[$][Q]=A[$-1][Q-1];else A[$][Q]=Math.min(A[$-1][Q-1]+1,A[$][Q-1]+1,A[$-1][Q]+1);return A[K.length][B.length]}class C{state;variableStart;variableEnd;blockStart;blockEnd;commentStart;commentEnd;constructor(B,K={}){this.state={source:B,pos:0,line:1,column:1,tokens:[]},this.variableStart=K.variableStart??"{{",this.variableEnd=K.variableEnd??"}}",this.blockStart=K.blockStart??"{%",this.blockEnd=K.blockEnd??"%}",this.commentStart=K.commentStart??"{#",this.commentEnd=K.commentEnd??"#}"}tokenize(){while(!this.isAtEnd())this.scanToken();return this.addToken("EOF",""),this.state.tokens}scanToken(){if(this.match(this.variableStart)){this.addToken("VARIABLE_START",this.variableStart),this.scanExpression(this.variableEnd,"VARIABLE_END");return}if(this.match(this.blockStart)){let B=this.peek()==="-";if(B)this.advance();let K=this.state.pos;if(this.skipWhitespace(),this.checkWord("raw")||this.checkWord("verbatim")){let A=this.checkWord("raw")?"raw":"verbatim";this.scanRawBlock(A,B);return}this.state.pos=K,this.addToken("BLOCK_START",this.blockStart+(B?"-":"")),this.scanExpression(this.blockEnd,"BLOCK_END");return}if(this.match(this.commentStart)){this.scanComment();return}this.scanText()}checkWord(B){let K=this.state.pos;for(let $=0;$<B.length;$++)if(this.state.source[K+$]?.toLowerCase()!==B[$])return!1;let A=this.state.source[K+B.length];return!A||!this.isAlphaNumeric(A)}scanRawBlock(B,K){let A=this.state.line,$=this.state.column;for(let U=0;U<B.length;U++)this.advance();if(this.skipWhitespace(),this.peek()==="-")this.advance();if(!this.match(this.blockEnd))throw new P(`Expected '${this.blockEnd}' after '${B}'`,{line:this.state.line,column:this.state.column,source:this.state.source});let Q=`end${B}`,O=this.state.pos;while(!this.isAtEnd()){if(this.check(this.blockStart)){let U=this.state.pos,Y=this.state.line,Z=this.state.column;if(this.match(this.blockStart),this.peek()==="-")this.advance();if(this.skipWhitespace(),this.checkWord(Q)){let J=this.state.source.slice(O,U);if(J.length>0)this.state.tokens.push({type:"TEXT",value:J,line:A,column:$});for(let X=0;X<Q.length;X++)this.advance();if(this.skipWhitespace(),this.peek()==="-")this.advance();if(!this.match(this.blockEnd))throw new P(`Expected '${this.blockEnd}' after '${Q}'`,{line:this.state.line,column:this.state.column,source:this.state.source});return}this.state.pos=U,this.state.line=Y,this.state.column=Z}if(this.peek()===`
6
- `)this.state.line++,this.state.column=0;this.advance()}throw new P(`Unclosed '${B}' block`,{line:A,column:$,source:this.state.source,suggestion:`Add {% end${B} %} to close the block`})}scanText(){let B=this.state.pos,K=this.state.line,A=this.state.column;while(!this.isAtEnd()){if(this.check(this.variableStart)||this.check(this.blockStart)||this.check(this.commentStart))break;if(this.peek()===`
7
- `)this.state.line++,this.state.column=0;this.advance()}if(this.state.pos>B){let $=this.state.source.slice(B,this.state.pos);this.state.tokens.push({type:"TEXT",value:$,line:K,column:A})}}scanExpression(B,K){this.skipWhitespace();while(!this.isAtEnd()){if(this.skipWhitespace(),this.peek()==="-"&&this.check(B,1))this.advance();if(this.match(B)){this.addToken(K,B);return}this.scanExpressionToken()}throw new P("Unclosed template tag",{line:this.state.line,column:this.state.column,source:this.state.source,suggestion:`Add closing delimiter '${B}'`})}scanExpressionToken(){if(this.skipWhitespace(),this.isAtEnd())return;let B=this.peek();if(B==='"'||B==="'"){this.scanString(B);return}if(this.isDigit(B)){this.scanNumber();return}if(this.isAlpha(B)||B==="_"){this.scanIdentifier();return}this.scanOperator()}scanString(B){this.advance();let K=this.state.pos;while(!this.isAtEnd()&&this.peek()!==B){if(this.peek()==="\\"&&this.peekNext()===B)this.advance();if(this.peek()===`
2
+ var s=import.meta.require;var b;((I)=>{I.TEXT="TEXT";I.EOF="EOF";I.VARIABLE_START="VARIABLE_START";I.VARIABLE_END="VARIABLE_END";I.BLOCK_START="BLOCK_START";I.BLOCK_END="BLOCK_END";I.COMMENT_START="COMMENT_START";I.COMMENT_END="COMMENT_END";I.NAME="NAME";I.STRING="STRING";I.NUMBER="NUMBER";I.DOT="DOT";I.COMMA="COMMA";I.COLON="COLON";I.PIPE="PIPE";I.LPAREN="LPAREN";I.RPAREN="RPAREN";I.LBRACKET="LBRACKET";I.RBRACKET="RBRACKET";I.LBRACE="LBRACE";I.RBRACE="RBRACE";I.EQ="EQ";I.NE="NE";I.LT="LT";I.GT="GT";I.LE="LE";I.GE="GE";I.ADD="ADD";I.SUB="SUB";I.MUL="MUL";I.DIV="DIV";I.MOD="MOD";I.AND="AND";I.OR="OR";I.NOT="NOT";I.ASSIGN="ASSIGN";I.TILDE="TILDE"})(b||={});var m={and:"AND",or:"OR",not:"NOT",true:"NAME",false:"NAME",True:"NAME",False:"NAME",None:"NAME",none:"NAME",is:"NAME",in:"NAME"};var u={red:"\x1B[31m",yellow:"\x1B[33m",cyan:"\x1B[36m",gray:"\x1B[90m",bold:"\x1B[1m",dim:"\x1B[2m",reset:"\x1B[0m"},zB=process.stdout?.isTTY!==!1;function E(B,K){return zB?`${u[B]}${K}${u.reset}`:K}class r extends Error{line;column;source;templateName;suggestion;availableOptions;constructor(B,K){let A=p("TemplateError",B,K);super(A);this.name="TemplateError",this.line=K.line,this.column=K.column,this.source=K.source,this.templateName=K.templateName,this.suggestion=K.suggestion,this.availableOptions=K.availableOptions}}class P extends Error{line;column;source;templateName;suggestion;constructor(B,K){let A=p("TemplateSyntaxError",B,K);super(A);this.name="TemplateSyntaxError",this.line=K.line,this.column=K.column,this.source=K.source,this.templateName=K.templateName,this.suggestion=K.suggestion}}class y extends Error{line;column;source;templateName;suggestion;availableOptions;constructor(B,K){let A=p("TemplateRuntimeError",B,K);super(A);this.name="TemplateRuntimeError",this.line=K.line,this.column=K.column,this.source=K.source,this.templateName=K.templateName,this.suggestion=K.suggestion,this.availableOptions=K.availableOptions}}function p(B,K,A){let Q=[],$=A.templateName?`${A.templateName}:${A.line}:${A.column}`:`line ${A.line}, column ${A.column}`;if(Q.push(`${E("red",E("bold",B))}: ${K} at ${E("cyan",$)}`),A.source)Q.push(""),Q.push(EB(A.source,A.line,A.column));if(A.suggestion)Q.push(""),Q.push(`${E("yellow","Did you mean")}: ${E("cyan",A.suggestion)}?`);if(A.availableOptions&&A.availableOptions.length>0){Q.push("");let Z=A.availableOptions.slice(0,8),U=A.availableOptions.length>8?` ${E("gray",`... and ${A.availableOptions.length-8} more`)}`:"";Q.push(`${E("gray","Available")}: ${Z.join(", ")}${U}`)}return Q.join(`
3
+ `)}function EB(B,K,A){let Q=B.split(`
4
+ `),$=[],Z=Math.max(1,K-2),U=Math.min(Q.length,K+1),Y=String(U).length;for(let O=Z;O<=U;O++){let J=Q[O-1]||"",X=String(O).padStart(Y," ");if(O===K){$.push(`${E("red"," \u2192")} ${E("gray",X)} ${E("dim","\u2502")} ${J}`);let G=" ".repeat(Y+4+Math.max(0,A-1)),R=E("red","^");$.push(`${G}${R}`)}else $.push(` ${E("gray",X)} ${E("dim","\u2502")} ${E("gray",J)}`)}return $.join(`
5
+ `)}function n(B,K,A=3){let Q=null,$=A+1,Z=B.toLowerCase();for(let U of K){let Y=WB(Z,U.toLowerCase());if(Y<$)$=Y,Q=U}return $<=A?Q:null}function WB(B,K){if(B.length===0)return K.length;if(K.length===0)return B.length;let A=[];for(let Q=0;Q<=K.length;Q++)A[Q]=[Q];for(let Q=0;Q<=B.length;Q++)A[0][Q]=Q;for(let Q=1;Q<=K.length;Q++)for(let $=1;$<=B.length;$++)if(K[Q-1]===B[$-1])A[Q][$]=A[Q-1][$-1];else A[Q][$]=Math.min(A[Q-1][$-1]+1,A[Q][$-1]+1,A[Q-1][$]+1);return A[K.length][B.length]}class C{state;variableStart;variableEnd;blockStart;blockEnd;commentStart;commentEnd;constructor(B,K={}){this.state={source:B,pos:0,line:1,column:1,tokens:[]},this.variableStart=K.variableStart??"{{",this.variableEnd=K.variableEnd??"}}",this.blockStart=K.blockStart??"{%",this.blockEnd=K.blockEnd??"%}",this.commentStart=K.commentStart??"{#",this.commentEnd=K.commentEnd??"#}"}tokenize(){while(!this.isAtEnd())this.scanToken();return this.addToken("EOF",""),this.state.tokens}scanToken(){if(this.match(this.variableStart)){this.addToken("VARIABLE_START",this.variableStart),this.scanExpression(this.variableEnd,"VARIABLE_END");return}if(this.match(this.blockStart)){let B=this.peek()==="-";if(B)this.advance();let K=this.state.pos;if(this.skipWhitespace(),this.checkWord("raw")||this.checkWord("verbatim")){let A=this.checkWord("raw")?"raw":"verbatim";this.scanRawBlock(A,B);return}this.state.pos=K,this.addToken("BLOCK_START",this.blockStart+(B?"-":"")),this.scanExpression(this.blockEnd,"BLOCK_END");return}if(this.match(this.commentStart)){this.scanComment();return}this.scanText()}checkWord(B){let K=this.state.pos;for(let Q=0;Q<B.length;Q++)if(this.state.source[K+Q]?.toLowerCase()!==B[Q])return!1;let A=this.state.source[K+B.length];return!A||!this.isAlphaNumeric(A)}scanRawBlock(B,K){let A=this.state.line,Q=this.state.column;for(let U=0;U<B.length;U++)this.advance();if(this.skipWhitespace(),this.peek()==="-")this.advance();if(!this.match(this.blockEnd))throw new P(`Expected '${this.blockEnd}' after '${B}'`,{line:this.state.line,column:this.state.column,source:this.state.source});let $=`end${B}`,Z=this.state.pos;while(!this.isAtEnd()){if(this.check(this.blockStart)){let U=this.state.pos,Y=this.state.line,O=this.state.column;if(this.match(this.blockStart),this.peek()==="-")this.advance();if(this.skipWhitespace(),this.checkWord($)){let J=this.state.source.slice(Z,U);if(J.length>0)this.state.tokens.push({type:"TEXT",value:J,line:A,column:Q});for(let X=0;X<$.length;X++)this.advance();if(this.skipWhitespace(),this.peek()==="-")this.advance();if(!this.match(this.blockEnd))throw new P(`Expected '${this.blockEnd}' after '${$}'`,{line:this.state.line,column:this.state.column,source:this.state.source});return}this.state.pos=U,this.state.line=Y,this.state.column=O}if(this.peek()===`
6
+ `)this.state.line++,this.state.column=0;this.advance()}throw new P(`Unclosed '${B}' block`,{line:A,column:Q,source:this.state.source,suggestion:`Add {% end${B} %} to close the block`})}scanText(){let B=this.state.pos,K=this.state.line,A=this.state.column;while(!this.isAtEnd()){if(this.check(this.variableStart)||this.check(this.blockStart)||this.check(this.commentStart))break;if(this.peek()===`
7
+ `)this.state.line++,this.state.column=0;this.advance()}if(this.state.pos>B){let Q=this.state.source.slice(B,this.state.pos);this.state.tokens.push({type:"TEXT",value:Q,line:K,column:A})}}scanExpression(B,K){this.skipWhitespace();while(!this.isAtEnd()){if(this.skipWhitespace(),this.peek()==="-"&&this.check(B,1))this.advance();if(this.match(B)){this.addToken(K,B);return}this.scanExpressionToken()}throw new P("Unclosed template tag",{line:this.state.line,column:this.state.column,source:this.state.source,suggestion:`Add closing delimiter '${B}'`})}scanExpressionToken(){if(this.skipWhitespace(),this.isAtEnd())return;let B=this.peek();if(B==='"'||B==="'"){this.scanString(B);return}if(this.isDigit(B)){this.scanNumber();return}if(this.isAlpha(B)||B==="_"){this.scanIdentifier();return}this.scanOperator()}scanString(B){this.advance();let K=this.state.pos;while(!this.isAtEnd()&&this.peek()!==B){if(this.peek()==="\\"&&this.peekNext()===B)this.advance();if(this.peek()===`
8
8
  `)this.state.line++,this.state.column=0;this.advance()}if(this.isAtEnd())throw new P("Unterminated string literal",{line:this.state.line,column:this.state.column,source:this.state.source,suggestion:`Add closing quote '${B}'`});let A=this.state.source.slice(K,this.state.pos);this.advance(),this.addToken("STRING",A)}scanNumber(){let B=this.state.pos;while(this.isDigit(this.peek()))this.advance();if(this.peek()==="."&&this.isDigit(this.peekNext())){this.advance();while(this.isDigit(this.peek()))this.advance()}let K=this.state.source.slice(B,this.state.pos);this.addToken("NUMBER",K)}scanIdentifier(){let B=this.state.pos;while(this.isAlphaNumeric(this.peek())||this.peek()==="_")this.advance();let K=this.state.source.slice(B,this.state.pos),A=m[K]??"NAME";this.addToken(A,K)}scanOperator(){let B=this.advance();switch(B){case".":this.addToken("DOT",B);break;case",":this.addToken("COMMA",B);break;case":":this.addToken("COLON",B);break;case"|":this.addToken("PIPE",B);break;case"(":this.addToken("LPAREN",B);break;case")":this.addToken("RPAREN",B);break;case"[":this.addToken("LBRACKET",B);break;case"]":this.addToken("RBRACKET",B);break;case"{":this.addToken("LBRACE",B);break;case"}":this.addToken("RBRACE",B);break;case"+":this.addToken("ADD",B);break;case"-":this.addToken("SUB",B);break;case"*":this.addToken("MUL",B);break;case"/":this.addToken("DIV",B);break;case"%":this.addToken("MOD",B);break;case"~":this.addToken("TILDE",B);break;case"=":if(this.match("="))this.addToken("EQ","==");else this.addToken("ASSIGN","=");break;case"!":if(this.match("="))this.addToken("NE","!=");else throw new P("Unexpected character '!'",{line:this.state.line,column:this.state.column-1,source:this.state.source,suggestion:"Use '!=' for not-equal comparison or 'not' for negation"});break;case"<":if(this.match("="))this.addToken("LE","<=");else this.addToken("LT","<");break;case">":if(this.match("="))this.addToken("GE",">=");else this.addToken("GT",">");break;default:if(!this.isWhitespace(B))throw new P(`Unexpected character '${B}'`,{line:this.state.line,column:this.state.column-1,source:this.state.source})}}scanComment(){while(!this.isAtEnd()&&!this.check(this.commentEnd)){if(this.peek()===`
9
- `)this.state.line++,this.state.column=0;this.advance()}if(!this.isAtEnd())this.match(this.commentEnd)}isAtEnd(){return this.state.pos>=this.state.source.length}peek(){if(this.isAtEnd())return"\x00";return this.state.source[this.state.pos]}peekNext(){if(this.state.pos+1>=this.state.source.length)return"\x00";return this.state.source[this.state.pos+1]}advance(){let B=this.state.source[this.state.pos];return this.state.pos++,this.state.column++,B}match(B,K=0){let A=this.state.source,$=this.state.pos+K,Q=B.length;if($+Q>A.length)return!1;for(let O=0;O<Q;O++)if(A[$+O]!==B[O])return!1;if(K===0)this.state.pos+=Q,this.state.column+=Q;return!0}check(B,K=0){let A=this.state.source,$=this.state.pos+K,Q=B.length;if($+Q>A.length)return!1;for(let O=0;O<Q;O++)if(A[$+O]!==B[O])return!1;return!0}skipWhitespace(){while(!this.isAtEnd()&&this.isWhitespace(this.peek())){if(this.peek()===`
9
+ `)this.state.line++,this.state.column=0;this.advance()}if(!this.isAtEnd())this.match(this.commentEnd)}isAtEnd(){return this.state.pos>=this.state.source.length}peek(){if(this.isAtEnd())return"\x00";return this.state.source[this.state.pos]}peekNext(){if(this.state.pos+1>=this.state.source.length)return"\x00";return this.state.source[this.state.pos+1]}advance(){let B=this.state.source[this.state.pos];return this.state.pos++,this.state.column++,B}match(B,K=0){let A=this.state.source,Q=this.state.pos+K,$=B.length;if(Q+$>A.length)return!1;for(let Z=0;Z<$;Z++)if(A[Q+Z]!==B[Z])return!1;if(K===0)this.state.pos+=$,this.state.column+=$;return!0}check(B,K=0){let A=this.state.source,Q=this.state.pos+K,$=B.length;if(Q+$>A.length)return!1;for(let Z=0;Z<$;Z++)if(A[Q+Z]!==B[Z])return!1;return!0}skipWhitespace(){while(!this.isAtEnd()&&this.isWhitespace(this.peek())){if(this.peek()===`
10
10
  `)this.state.line++,this.state.column=0;this.advance()}}isWhitespace(B){return B===" "||B==="\t"||B===`
11
- `||B==="\r"}isDigit(B){let K=B.charCodeAt(0);return K>=48&&K<=57}isAlpha(B){let K=B.charCodeAt(0);return K>=97&&K<=122||K>=65&&K<=90}isAlphaNumeric(B){let K=B.charCodeAt(0);return K>=48&&K<=57||K>=97&&K<=122||K>=65&&K<=90}addToken(B,K){this.state.tokens.push({type:B,value:K,line:this.state.line,column:this.state.column-K.length})}}class N{tokens;current=0;source;constructor(B,K){this.tokens=B,this.source=K}parse(){let B=[];while(!this.isAtEnd()){let K=this.parseStatement();if(K)B.push(K)}return{type:"Template",body:B,line:1,column:1}}parseStatement(){switch(this.peek().type){case"TEXT":return this.parseText();case"VARIABLE_START":return this.parseOutput();case"BLOCK_START":return this.parseBlock();case"EOF":return null;default:return this.advance(),null}}parseText(){let B=this.advance();return{type:"Text",value:B.value,line:B.line,column:B.column}}parseOutput(){let B=this.advance(),K=this.parseExpression();return this.expect("VARIABLE_END"),{type:"Output",expression:K,line:B.line,column:B.column}}parseBlock(){let B=this.advance(),K=this.expect("NAME");switch(K.value){case"if":return this.parseIf(B);case"for":return this.parseFor(B);case"block":return this.parseBlockTag(B);case"extends":return this.parseExtends(B);case"include":return this.parseInclude(B);case"set":return this.parseSet(B);case"with":return this.parseWith(B);case"load":return this.parseLoad(B);case"url":return this.parseUrl(B);case"static":return this.parseStatic(B);case"now":return this.parseNow(B);case"comment":return this.parseComment(B);case"spaceless":case"autoescape":case"verbatim":return this.parseSimpleBlock(B,K.value);case"cycle":return this.parseCycle(B);case"firstof":return this.parseFirstof(B);case"ifchanged":return this.parseIfchanged(B);case"regroup":return this.parseRegroup(B);case"widthratio":return this.parseWidthratio(B);case"lorem":return this.parseLorem(B);case"csrf_token":return this.parseCsrfToken(B);case"debug":return this.parseDebug(B);case"templatetag":return this.parseTemplatetag(B);case"ifequal":return this.parseIfequal(B,!1);case"ifnotequal":return this.parseIfequal(B,!0);default:return this.skipToBlockEnd(),null}}parseIf(B){let K=this.parseExpression();this.expect("BLOCK_END");let A=[],$=[],Q=[];while(!this.isAtEnd()){if(this.checkBlockTag("elif")||this.checkBlockTag("else")||this.checkBlockTag("endif"))break;let O=this.parseStatement();if(O)A.push(O)}while(this.checkBlockTag("elif")){this.advance(),this.advance();let O=this.parseExpression();this.expect("BLOCK_END");let U=[];while(!this.isAtEnd()){if(this.checkBlockTag("elif")||this.checkBlockTag("else")||this.checkBlockTag("endif"))break;let Y=this.parseStatement();if(Y)U.push(Y)}$.push({test:O,body:U})}if(this.checkBlockTag("else")){this.advance(),this.advance(),this.expect("BLOCK_END");while(!this.isAtEnd()){if(this.checkBlockTag("endif"))break;let O=this.parseStatement();if(O)Q.push(O)}}return this.expectBlockTag("endif"),{type:"If",test:K,body:A,elifs:$,else_:Q,line:B.line,column:B.column}}parseFor(B){let K,A=this.expect("NAME").value;if(this.check("COMMA")){let Z=[A];while(this.match("COMMA"))Z.push(this.expect("NAME").value);K=Z}else K=A;let $=this.expect("NAME");if($.value!=="in")throw this.error(`Expected 'in' in for loop, got '${$.value}'`);let Q=this.parseExpression(),O=this.check("NAME")&&this.peek().value==="recursive";if(O)this.advance();this.expect("BLOCK_END");let U=[],Y=[];while(!this.isAtEnd()){if(this.checkBlockTag("empty")||this.checkBlockTag("else")||this.checkBlockTag("endfor"))break;let Z=this.parseStatement();if(Z)U.push(Z)}if(this.checkBlockTag("empty")||this.checkBlockTag("else")){this.advance(),this.advance(),this.expect("BLOCK_END");while(!this.isAtEnd()){if(this.checkBlockTag("endfor"))break;let Z=this.parseStatement();if(Z)Y.push(Z)}}return this.expectBlockTag("endfor"),{type:"For",target:K,iter:Q,body:U,else_:Y,recursive:O,line:B.line,column:B.column}}parseBlockTag(B){let K=this.expect("NAME").value,A=this.check("NAME")&&this.peek().value==="scoped";if(A)this.advance();this.expect("BLOCK_END");let $=[];while(!this.isAtEnd()){if(this.checkBlockTag("endblock"))break;let Q=this.parseStatement();if(Q)$.push(Q)}if(this.advance(),this.advance(),this.check("NAME"))this.advance();return this.expect("BLOCK_END"),{type:"Block",name:K,body:$,scoped:A,line:B.line,column:B.column}}parseExtends(B){let K=this.parseExpression();return this.expect("BLOCK_END"),{type:"Extends",template:K,line:B.line,column:B.column}}parseInclude(B){let K=this.parseExpression(),A=null,$=!1,Q=!1;while(this.check("NAME")){let O=this.peek().value;if(O==="ignore"&&this.peekNext()?.value==="missing")this.advance(),this.advance(),Q=!0;else if(O==="with")this.advance(),A=this.parseKeywordArgs();else if(O==="only")this.advance(),$=!0;else if(O==="without"){if(this.advance(),this.check("NAME")&&this.peek().value==="context")this.advance(),$=!0}else break}return this.expect("BLOCK_END"),{type:"Include",template:K,context:A,only:$,ignoreMissing:Q,line:B.line,column:B.column}}parseSet(B){let K=this.expect("NAME").value;this.expect("ASSIGN");let A=this.parseExpression();return this.expect("BLOCK_END"),{type:"Set",target:K,value:A,line:B.line,column:B.column}}parseWith(B){let K=[];do{let $=this.expect("NAME").value;this.expect("ASSIGN");let Q=this.parseExpression();K.push({target:$,value:Q})}while(this.match("COMMA")||this.check("NAME")&&this.peekNext()?.type==="ASSIGN");this.expect("BLOCK_END");let A=[];while(!this.isAtEnd()){if(this.checkBlockTag("endwith"))break;let $=this.parseStatement();if($)A.push($)}return this.expectBlockTag("endwith"),{type:"With",assignments:K,body:A,line:B.line,column:B.column}}parseLoad(B){let K=[];while(this.check("NAME"))K.push(this.advance().value);return this.expect("BLOCK_END"),{type:"Load",names:K,line:B.line,column:B.column}}parseUrl(B){let K=this.parseExpression(),A=[],$={},Q=null;while(!this.check("BLOCK_END")){if(this.check("NAME")&&this.peek().value==="as"){this.advance(),Q=this.expect("NAME").value;break}if(this.check("NAME")&&this.peekNext()?.type==="ASSIGN"){let O=this.advance().value;this.advance(),$[O]=this.parseExpression()}else A.push(this.parseExpression())}return this.expect("BLOCK_END"),{type:"Url",name:K,args:A,kwargs:$,asVar:Q,line:B.line,column:B.column}}parseStatic(B){let K=this.parseExpression(),A=null;if(this.check("NAME")&&this.peek().value==="as")this.advance(),A=this.expect("NAME").value;return this.expect("BLOCK_END"),{type:"Static",path:K,asVar:A,line:B.line,column:B.column}}parseNow(B){let K=this.parseExpression(),A=null;if(this.check("NAME")&&this.peek().value==="as")this.advance(),A=this.expect("NAME").value;return this.expect("BLOCK_END"),{type:"Now",format:K,asVar:A,line:B.line,column:B.column}}parseComment(B){this.expect("BLOCK_END");while(!this.isAtEnd()){if(this.checkBlockTag("endcomment"))break;this.advance()}return this.expectBlockTag("endcomment"),null}parseSimpleBlock(B,K){this.skipToBlockEnd();let A=`end${K}`;while(!this.isAtEnd()){if(this.checkBlockTag(A))break;this.advance()}if(this.checkBlockTag(A))this.advance(),this.advance(),this.expect("BLOCK_END");return null}parseCycle(B){let K=[],A=null,$=!1;while(!this.check("BLOCK_END")){if(this.check("NAME")&&this.peek().value==="as"){if(this.advance(),A=this.expect("NAME").value,this.check("NAME")&&this.peek().value==="silent")this.advance(),$=!0;break}K.push(this.parseExpression())}return this.expect("BLOCK_END"),{type:"Cycle",values:K,asVar:A,silent:$,line:B.line,column:B.column}}parseFirstof(B){let K=[],A=null,$=null;while(!this.check("BLOCK_END")){if(this.check("NAME")&&this.peek().value==="as"){this.advance(),$=this.expect("NAME").value;break}K.push(this.parseExpression())}if(K.length>0){let Q=K[K.length-1];if(Q.type==="Literal"&&typeof Q.value==="string")A=K.pop()}return this.expect("BLOCK_END"),{type:"Firstof",values:K,fallback:A,asVar:$,line:B.line,column:B.column}}parseIfchanged(B){let K=[];while(!this.check("BLOCK_END"))K.push(this.parseExpression());this.expect("BLOCK_END");let A=[],$=[];while(!this.isAtEnd()){if(this.checkBlockTag("else")||this.checkBlockTag("endifchanged"))break;let Q=this.parseStatement();if(Q)A.push(Q)}if(this.checkBlockTag("else")){this.advance(),this.advance(),this.expect("BLOCK_END");while(!this.isAtEnd()){if(this.checkBlockTag("endifchanged"))break;let Q=this.parseStatement();if(Q)$.push(Q)}}return this.expectBlockTag("endifchanged"),{type:"Ifchanged",values:K,body:A,else_:$,line:B.line,column:B.column}}parseRegroup(B){let K=this.parseExpression();this.expectName("by");let A=this.expect("NAME").value;this.expectName("as");let $=this.expect("NAME").value;return this.expect("BLOCK_END"),{type:"Regroup",target:K,key:A,asVar:$,line:B.line,column:B.column}}parseWidthratio(B){let K=this.parseExpression(),A=this.parseExpression(),$=this.parseExpression(),Q=null;if(this.check("NAME")&&this.peek().value==="as")this.advance(),Q=this.expect("NAME").value;return this.expect("BLOCK_END"),{type:"Widthratio",value:K,maxValue:A,maxWidth:$,asVar:Q,line:B.line,column:B.column}}parseLorem(B){let K=null,A="p",$=!1;if(this.check("NUMBER"))K={type:"Literal",value:parseInt(this.advance().value,10),line:B.line,column:B.column};if(this.check("NAME")){let Q=this.peek().value.toLowerCase();if(Q==="w"||Q==="p"||Q==="b")A=Q,this.advance()}if(this.check("NAME")&&this.peek().value==="random")$=!0,this.advance();return this.expect("BLOCK_END"),{type:"Lorem",count:K,method:A,random:$,line:B.line,column:B.column}}parseCsrfToken(B){return this.expect("BLOCK_END"),{type:"CsrfToken",line:B.line,column:B.column}}parseDebug(B){return this.expect("BLOCK_END"),{type:"Debug",line:B.line,column:B.column}}parseTemplatetag(B){let K=this.expect("NAME").value;return this.expect("BLOCK_END"),{type:"Templatetag",tagType:K,line:B.line,column:B.column}}parseIfequal(B,K){let A=this.parseExpression(),$=this.parseExpression();this.expect("BLOCK_END");let Q={type:"Compare",left:A,ops:[{operator:K?"!=":"==",right:$}],line:B.line,column:B.column},O=[],U=[],Y=K?"endifnotequal":"endifequal";while(!this.isAtEnd()){if(this.checkBlockTag("else")||this.checkBlockTag(Y))break;let Z=this.parseStatement();if(Z)O.push(Z)}if(this.checkBlockTag("else")){this.advance(),this.advance(),this.expect("BLOCK_END");while(!this.isAtEnd()){if(this.checkBlockTag(Y))break;let Z=this.parseStatement();if(Z)U.push(Z)}}return this.expectBlockTag(Y),{type:"If",test:Q,body:O,elifs:[],else_:U,line:B.line,column:B.column}}parseExpression(){return this.parseConditional()}parseConditional(){let B=this.parseOr();if(this.check("NAME")&&this.peek().value==="if"){this.advance();let K=this.parseOr();this.expectName("else");let A=this.parseConditional();B={type:"Conditional",test:K,trueExpr:B,falseExpr:A,line:B.line,column:B.column}}return B}parseOr(){let B=this.parseAnd();while(this.check("OR")||this.check("NAME")&&this.peek().value==="or"){this.advance();let K=this.parseAnd();B={type:"BinaryOp",operator:"or",left:B,right:K,line:B.line,column:B.column}}return B}parseAnd(){let B=this.parseNot();while(this.check("AND")||this.check("NAME")&&this.peek().value==="and"){this.advance();let K=this.parseNot();B={type:"BinaryOp",operator:"and",left:B,right:K,line:B.line,column:B.column}}return B}parseNot(){if(this.check("NOT")||this.check("NAME")&&this.peek().value==="not"){let B=this.advance();return{type:"UnaryOp",operator:"not",operand:this.parseNot(),line:B.line,column:B.column}}return this.parseCompare()}parseCompare(){let B=this.parseAddSub(),K=[];while(!0){let A=null;if(this.match("EQ"))A="==";else if(this.match("NE"))A="!=";else if(this.match("LT"))A="<";else if(this.match("GT"))A=">";else if(this.match("LE"))A="<=";else if(this.match("GE"))A=">=";else if(this.check("NAME")){let Q=this.peek().value;if(Q==="in")this.advance(),A="in";else if(Q==="not"&&this.peekNext()?.value==="in")this.advance(),this.advance(),A="not in";else if(Q==="is"){this.advance();let O=this.check("NOT");if(O)this.advance();let Y=this.expect("NAME").value,Z=[];if(this.match("LPAREN")){while(!this.check("RPAREN"))if(Z.push(this.parseExpression()),!this.check("RPAREN"))this.expect("COMMA");this.expect("RPAREN")}B={type:"TestExpr",node:B,test:Y,args:Z,negated:O,line:B.line,column:B.column};continue}}if(!A)break;let $=this.parseAddSub();K.push({operator:A,right:$})}if(K.length===0)return B;return{type:"Compare",left:B,ops:K,line:B.line,column:B.column}}parseAddSub(){let B=this.parseMulDiv();while(this.check("ADD")||this.check("SUB")||this.check("TILDE")){let K=this.advance(),A=this.parseMulDiv();B={type:"BinaryOp",operator:K.value,left:B,right:A,line:B.line,column:B.column}}return B}parseMulDiv(){let B=this.parseUnary();while(this.check("MUL")||this.check("DIV")||this.check("MOD")){let K=this.advance(),A=this.parseUnary();B={type:"BinaryOp",operator:K.value,left:B,right:A,line:B.line,column:B.column}}return B}parseUnary(){if(this.check("SUB")||this.check("ADD")){let B=this.advance(),K=this.parseUnary();return{type:"UnaryOp",operator:B.value,operand:K,line:B.line,column:B.column}}return this.parseFilter()}parseFilter(){let B=this.parsePostfix();while(this.match("PIPE")){let K=this.expect("NAME").value,A=[],$={};if(this.match("COLON"))if(this.check("SUB")||this.check("ADD")){let Q=this.advance(),O=this.parsePostfix();A.push({type:"UnaryOp",operator:Q.value,operand:O,line:Q.line,column:Q.column})}else A.push(this.parsePostfix());else if(this.match("LPAREN")){while(!this.check("RPAREN")){if(this.check("NAME")&&this.peekNext()?.type==="ASSIGN"){let Q=this.advance().value;this.advance(),$[Q]=this.parseExpression()}else A.push(this.parseExpression());if(!this.check("RPAREN"))this.expect("COMMA")}this.expect("RPAREN")}B={type:"FilterExpr",node:B,filter:K,args:A,kwargs:$,line:B.line,column:B.column}}return B}parsePostfix(){let B=this.parsePrimary();while(!0)if(this.match("DOT")){let K;if(this.check("NUMBER"))K=this.advance().value;else K=this.expect("NAME").value;B={type:"GetAttr",object:B,attribute:K,line:B.line,column:B.column}}else if(this.match("LBRACKET")){let K=this.parseExpression();this.expect("RBRACKET"),B={type:"GetItem",object:B,index:K,line:B.line,column:B.column}}else if(this.match("LPAREN")){let K=[],A={};while(!this.check("RPAREN")){if(this.check("NAME")&&this.peekNext()?.type==="ASSIGN"){let $=this.advance().value;this.advance(),A[$]=this.parseExpression()}else K.push(this.parseExpression());if(!this.check("RPAREN"))this.expect("COMMA")}this.expect("RPAREN"),B={type:"FunctionCall",callee:B,args:K,kwargs:A,line:B.line,column:B.column}}else break;return B}parsePrimary(){let B=this.peek();if(this.match("STRING"))return{type:"Literal",value:B.value,line:B.line,column:B.column};if(this.match("NUMBER"))return{type:"Literal",value:B.value.includes(".")?parseFloat(B.value):parseInt(B.value,10),line:B.line,column:B.column};if(this.check("NAME")){let K=this.advance().value;if(K==="true"||K==="True")return{type:"Literal",value:!0,line:B.line,column:B.column};if(K==="false"||K==="False")return{type:"Literal",value:!1,line:B.line,column:B.column};if(K==="none"||K==="None"||K==="null")return{type:"Literal",value:null,line:B.line,column:B.column};return{type:"Name",name:K,line:B.line,column:B.column}}if(this.match("LPAREN")){let K=this.parseExpression();return this.expect("RPAREN"),K}if(this.match("LBRACKET")){let K=[];while(!this.check("RBRACKET"))if(K.push(this.parseExpression()),!this.check("RBRACKET"))this.expect("COMMA");return this.expect("RBRACKET"),{type:"Array",elements:K,line:B.line,column:B.column}}if(this.match("LBRACE")){let K=[];while(!this.check("RBRACE")){let A=this.parseExpression();this.expect("COLON");let $=this.parseExpression();if(K.push({key:A,value:$}),!this.check("RBRACE"))this.expect("COMMA")}return this.expect("RBRACE"),{type:"Object",pairs:K,line:B.line,column:B.column}}throw this.error(`Unexpected token: ${B.type} (${B.value})`)}parseKeywordArgs(){let B={};while(this.check("NAME")&&this.peekNext()?.type==="ASSIGN"){let K=this.advance().value;this.advance(),B[K]=this.parseExpression()}return B}checkBlockTag(B){if(this.peek().type!=="BLOCK_START")return!1;let K=this.current;this.advance();let A=this.check("NAME")&&this.peek().value===B;return this.current=K,A}expectBlockTag(B){this.advance();let K=this.expect("NAME");if(K.value!==B)throw this.error(`Expected '${B}', got '${K.value}'`);this.expect("BLOCK_END")}expectName(B){let K=this.expect("NAME");if(K.value!==B)throw this.error(`Expected '${B}', got '${K.value}'`)}skipToBlockEnd(){while(!this.isAtEnd()&&!this.check("BLOCK_END"))this.advance();if(this.check("BLOCK_END"))this.advance()}isAtEnd(){return this.peek().type==="EOF"}peek(){return this.tokens[this.current]}peekNext(){if(this.current+1>=this.tokens.length)return null;return this.tokens[this.current+1]}advance(){if(!this.isAtEnd())this.current++;return this.tokens[this.current-1]}check(B){if(this.isAtEnd())return!1;return this.peek().type===B}match(B){if(this.check(B))return this.advance(),!0;return!1}expect(B){if(this.check(B))return this.advance();let K=this.peek();throw this.error(`Expected ${B}, got ${K.type} (${K.value})`)}error(B){let K=this.peek();return new P(B,{line:K.line,column:K.column,source:this.source})}}function PB(B,K,A,$,Q){let O=B.length,U=O-K,Y={_items:B,_idx:K,counter:K+1,counter0:K,first:K===0,last:K===O-1,length:O,index:K+1,index0:K,depth:A,depth0:A-1,revcounter:U,revcounter0:U-1,revindex:U,revindex0:U-1,get previtem(){return this._idx>0?this._items[this._idx-1]:void 0},get nextitem(){return this._idx<this._items.length-1?this._items[this._idx+1]:void 0},cycle(...Z){return Z[this._idx%Z.length]},changed:(Z)=>{let J=Z!==$.value;return $.value=Z,J}};if(Q)Y.parentloop=Q;return Y}class w{scopes=[];parent=null;_forloopStack=[];_lastCycleValue={value:null};_currentForloop=null;_currentScope;constructor(B={},K=null){this.parent=K,this._currentScope={...B},this.scopes.push(this._currentScope)}get(B){if(B==="forloop"||B==="loop")return this._currentForloop;for(let K=this.scopes.length-1;K>=0;K--){let A=this.scopes[K];if(B in A)return A[B]}return this.parent?this.parent.get(B):void 0}set(B,K){this._currentScope[B]=K}has(B){for(let K=this.scopes.length-1;K>=0;K--)if(B in this.scopes[K])return!0;return this.parent?this.parent.has(B):!1}push(B={}){this._currentScope={...B},this.scopes.push(this._currentScope)}pop(){if(this.scopes.length>1)this.scopes.pop(),this._currentScope=this.scopes[this.scopes.length-1]}derived(B={}){return new w(B,this)}pushForLoop(B,K){let A=this._forloopStack.length+1,$=this._forloopStack.length>0?this._forloopStack[this._forloopStack.length-1]:void 0,Q=PB(B,K,A,this._lastCycleValue,$);return this._forloopStack.push(Q),this._currentForloop=Q,Q}popForLoop(){this._forloopStack.pop(),this._currentForloop=this._forloopStack.length>0?this._forloopStack[this._forloopStack.length-1]:null}updateForLoop(B,K){let A=this._currentForloop;if(!A)return;let $=K.length;if(A._idx=B,A._items!==K)A._items=K;A.counter=B+1,A.counter0=B,A.index=B+1,A.index0=B,A.first=B===0,A.last=B===$-1;let Q=$-B;A.revcounter=Q,A.revcounter0=Q-1,A.revindex=Q,A.revindex0=Q-1}toObject(){let B={};if(this.parent)Object.assign(B,this.parent.toObject());for(let K of this.scopes)Object.assign(B,K);return B}}var DB=/\b\w/g,_B=/<[^>]*>/g,LB=/[^\w\s-]/g,jB=/[\s_-]+/g,qB=/^-+|-+$/g,t=/(https?:\/\/[^\s]+)/g,CB=/[a-zA-Z]/g,NB=/\n\n+/,e=/\n/g,BB=/\s+/,SB=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wB=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],VB=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],bB=["January","February","March","April","May","June","July","August","September","October","November","December"],hB=["Jan.","Feb.","March","April","May","June","July","Aug.","Sept.","Oct.","Nov.","Dec."],fB=(B)=>String(B).toUpperCase(),kB=(B)=>String(B).toLowerCase(),yB=(B)=>{let K=String(B);return K.charAt(0).toUpperCase()+K.slice(1).toLowerCase()},TB=(B)=>{let K=String(B);return K.charAt(0).toUpperCase()+K.slice(1)},gB=(B)=>String(B).replace(DB,(K)=>K.toUpperCase()),xB=(B)=>String(B).trim(),mB=(B)=>String(B).replace(_B,""),n=(B)=>{if(B?.__safe__)return B;let K=Bun.escapeHTML(String(B)),A=new String(K);return A.__safe__=!0,A},pB=(B)=>{let K=new String(B);return K.__safe__=!0,K},vB=(B)=>JSON.stringify(String(B)).slice(1,-1),cB=(B)=>{let A=String(B).split(NB),$="";for(let O=0;O<A.length;O++){if(O>0)$+=`
12
- `;$+=`<p>${A[O].replace(e,"<br>")}</p>`}let Q=new String($);return Q.__safe__=!0,Q},iB=(B)=>{let K=String(B).replace(e,"<br>"),A=new String(K);return A.__safe__=!0,A},sB=(B,K=30)=>{let A=String(B);if(A.length<=K)return A;return A.slice(0,K-3)+"..."},dB=(B,K=15)=>{let A=String(B).split(BB);if(A.length<=K)return B;return A.slice(0,K).join(" ")+"..."},uB=(B)=>String(B).split(BB).filter(Boolean).length,rB=(B,K=80)=>{let A=String(B),$=Math.max(0,K-A.length),Q=Math.floor($/2),O=$-Q;return" ".repeat(Q)+A+" ".repeat(O)},lB=(B,K=80)=>String(B).padEnd(K),nB=(B,K=80)=>String(B).padStart(K),oB=(B,K="")=>String(B).split(K).join(""),aB=(B)=>String(B).toLowerCase().replace(LB,"").replace(jB,"-").replace(qB,""),tB=(B)=>Math.abs(Number(B)),eB=(B,K=0)=>Number(Number(B).toFixed(K)),BK=(B)=>parseInt(String(B),10)||0,KK=(B)=>parseFloat(String(B))||0,AK=(B,K=-1)=>{let A=parseFloat(String(B));if(isNaN(A))return"";if(K===-1){let $=A.toFixed(1);return $.endsWith(".0")?Math.round(A).toString():$}return A.toFixed(Math.abs(K))},$K=(B,K)=>{let A=Number(B),$=Number(K);if(!isNaN(A)&&!isNaN($))return A+$;return String(B)+String(K)},QK=(B,K)=>Number(B)%Number(K)===0,OK=(B)=>{let K=Number(B),A=["bytes","KB","MB","GB","TB","PB"],$=0,Q=K;while(Q>=1024&&$<A.length-1)Q/=1024,$++;return`${Q.toFixed(1)} ${A[$]}`},KB=(B)=>{if(B==null)return 0;if(typeof B==="string"||Array.isArray(B))return B.length;if(typeof B==="object"){let K=0;for(let A in B)K++;return K}return 0},ZK=(B,K)=>KB(B)===Number(K),JK=(B)=>{if(Array.isArray(B))return B[0];if(typeof B==="string")return B[0];return B},YK=(B)=>{if(Array.isArray(B))return B[B.length-1];if(typeof B==="string")return B[B.length-1];return B},UK=(B,K="")=>{if(Array.isArray(B))return B.join(K);return String(B)},XK=(B,K)=>{if(!B)return B;let[A,$]=String(K).split(":"),Q=A?parseInt(A,10):0,O=$?parseInt($,10):void 0;if(Array.isArray(B)||typeof B==="string")return B.slice(Q,O);return B},MK=(B)=>{if(Array.isArray(B))return[...B].reverse();if(typeof B==="string")return B.split("").reverse().join("");return B},GK=(B,K=!1)=>{if(!Array.isArray(B))return B;let A=[...B].sort();return K?A.reverse():A},FK=(B)=>{if(!Array.isArray(B))return B;let K=new Set,A=[];for(let $=0;$<B.length;$++){let Q=B[$];if(!K.has(Q))K.add(Q),A.push(Q)}return A},IK=(B)=>{if(Array.isArray(B))return B;return String(B).split("")},AB=(B,K)=>{if(!Array.isArray(B))return B;return[...B].sort((A,$)=>{let Q=K?A[K]:A,O=K?$[K]:$;return Q<O?-1:Q>O?1:0})},RK=(B,K)=>{let A=AB(B,K);return Array.isArray(A)?A.reverse():A},HK=(B,K)=>{if(!Array.isArray(B))return[[B]];let A=[],$=Number(K)||2;for(let Q=0;Q<B.length;Q+=$)A.push(B.slice(Q,Q+$));return A},zK=(B,K)=>{switch(K){case"d":return String(B.getDate()).padStart(2,"0");case"j":return String(B.getDate());case"D":return SB[B.getDay()];case"l":return wB[B.getDay()];case"m":return String(B.getMonth()+1).padStart(2,"0");case"n":return String(B.getMonth()+1);case"M":return VB[B.getMonth()];case"F":return bB[B.getMonth()];case"N":return hB[B.getMonth()];case"y":return String(B.getFullYear()).slice(-2);case"Y":return String(B.getFullYear());case"H":return String(B.getHours()).padStart(2,"0");case"G":return String(B.getHours());case"i":return String(B.getMinutes()).padStart(2,"0");case"s":return String(B.getSeconds()).padStart(2,"0");case"a":return B.getHours()<12?"a.m.":"p.m.";case"A":return B.getHours()<12?"AM":"PM";case"g":return String(B.getHours()%12||12);case"h":return String(B.getHours()%12||12).padStart(2,"0");default:return K}},$B=(B,K="N j, Y")=>{let A=B instanceof Date?B:new Date(B);if(isNaN(A.getTime()))return"";return K.replace(CB,($)=>zK(A,$))},EK=(B,K="H:i")=>$B(B,K),WK=(B,K=new Date)=>{let A=B instanceof Date?B:new Date(B),$=(new Date(K).getTime()-A.getTime())/1000,Q=[[31536000,"year","years"],[2592000,"month","months"],[604800,"week","weeks"],[86400,"day","days"],[3600,"hour","hours"],[60,"minute","minutes"]];for(let[O,U,Y]of Q){let Z=Math.floor($/O);if(Z>=1)return`${Z} ${Z===1?U:Y}`}return"just now"},PK=(B,K=new Date)=>{let $=((B instanceof Date?B:new Date(B)).getTime()-new Date(K).getTime())/1000,Q=[[31536000,"year","years"],[2592000,"month","months"],[604800,"week","weeks"],[86400,"day","days"],[3600,"hour","hours"],[60,"minute","minutes"]];for(let[O,U,Y]of Q){let Z=Math.floor($/O);if(Z>=1)return`${Z} ${Z===1?U:Y}`}return"now"},o=(B,K="")=>{if(B===void 0||B===null||B===""||B===!1)return K;return B};var DK=(B,K="")=>B===null||B===void 0?K:B,_K=(B,K="yes,no,maybe")=>{let[A,$,Q]=K.split(",");if(B===!0)return A;if(B===!1)return $;return Q??$},LK=(B,K="s")=>{let[A,$]=K.includes(",")?K.split(","):["",K];return Number(B)===1?A:$},jK=(B)=>encodeURIComponent(String(B)),qK=(B)=>{let K=String(B).replace(t,'<a href="$1">$1</a>'),A=new String(K);return A.__safe__=!0,A},a=(B,K)=>{try{let A=JSON.stringify(B,null,K),$=new String(A);return $.__safe__=!0,$}catch{return""}},CK=(B)=>{if(Array.isArray(B))return B[Math.floor(Math.random()*B.length)];return B},NK=(B,K,A=null)=>{if(!Array.isArray(B))return[[B]];let $=[],Q=Number(K)||1;for(let O=0;O<B.length;O+=Q){let U=B.slice(O,O+Q);while(A!==null&&U.length<Q)U.push(A);$.push(U)}return $},SK=(B,K)=>{if(!Array.isArray(B))return[];let A={};for(let Q of B){let O=String(K?Q[K]:Q);if(!(O in A))A[O]=[];A[O].push(Q)}let $=[];for(let Q in A)$.push({grouper:Q,list:A[Q]});return $},wK=(B,K=79,A=!0,$=`
13
- `)=>{let Q=String(B);if(Q.length<=K)return Q;let O=Q.split(" "),U=[],Y="";for(let Z of O)if(Y.length+Z.length+1<=K)Y+=(Y?" ":"")+Z;else{if(Y)U.push(Y);if(A&&Z.length>K){let J=Z;while(J.length>K)U.push(J.slice(0,K)),J=J.slice(K);Y=J}else Y=Z}if(Y)U.push(Y);return U.join($)},VK=(B,K=4,A=!1,$=!1)=>{let Q=String(B),O=typeof K==="string"?K:" ".repeat(Number(K)),U=Q.split(`
14
- `),Y="";for(let Z=0;Z<U.length;Z++){if(Z>0)Y+=`
15
- `;let J=U[Z];if(Z===0&&!A)Y+=J;else if(!$&&J.trim()==="")Y+=J;else Y+=O+J}return Y},bK=(B,K,A,$)=>{let Q=String(B),O=String(K),U=String(A);if($===void 0||$<0)return Q.replaceAll(O,U);let Y=Number($);if(Y===0)return Q;let Z="",J=0,X=0;while(J<Q.length&&X<Y){let M=Q.indexOf(O,J);if(M===-1)break;Z+=Q.slice(J,M)+U,J=M+O.length,X++}return Z+=Q.slice(J),Z},hK=(B,...K)=>{let A=String(B);for(let $=0;$<K.length;$++){let Q=String(K[$]);A=A.replace(/%s/,Q);let O=`%${$+1}`;if(A.includes(O))A=A.replaceAll(O,Q)}return A},fK=(B)=>String(B),kK=(B)=>{if(Array.isArray(B))return B;if(typeof B==="string")return B.split("");if(B&&typeof B[Symbol.iterator]==="function")return[...B];if(typeof B==="object"&&B!==null)return Object.values(B);return[B]},yK=(B,K)=>{if(!Array.isArray(B))return[];if(typeof K==="string")return B.map((A)=>A?.[K]);return B},TK=(B,K)=>{if(!Array.isArray(B))return[];if(K===void 0)return B.filter((A)=>!!A);return B.filter((A)=>!!A?.[K])},gK=(B,K)=>{if(!Array.isArray(B))return[];if(K===void 0)return B.filter((A)=>!A);return B.filter((A)=>!A?.[K])},QB=(B,K,A,$)=>{if(!Array.isArray(B))return[];return B.filter((Q)=>{let O=Q?.[K];if(A===void 0)return!!O;if(A==="eq"||A==="equalto")return O===$;if(A==="ne")return O!==$;if(A==="gt")return O>$;if(A==="lt")return O<$;if(A==="ge"||A==="gte")return O>=$;if(A==="le"||A==="lte")return O<=$;if(A==="in")return $?.includes?.(O);if(A==="defined")return O!==void 0;if(A==="undefined")return O===void 0;if(A==="none")return O===null;if(A==="true")return O===!0;if(A==="false")return O===!1;return!!O})},xK=(B,K,A,$)=>{if(!Array.isArray(B))return[];let Q=QB(B,K,A,$);return B.filter((O)=>!Q.includes(O))},mK=(B,K)=>{if(B==null)return;return B[K]},pK=(B,K,A)=>{if(!Array.isArray(B)||B.length===0)return A;if(K){let Q=B[0];for(let O=1;O<B.length;O++)if(B[O][K]>Q[K])Q=B[O];return Q}let $=B[0];for(let Q=1;Q<B.length;Q++)if(B[Q]>$)$=B[Q];return $},vK=(B,K,A)=>{if(!Array.isArray(B)||B.length===0)return A;if(K){let Q=B[0];for(let O=1;O<B.length;O++)if(B[O][K]<Q[K])Q=B[O];return Q}let $=B[0];for(let Q=1;Q<B.length;Q++)if(B[Q]<$)$=B[Q];return $},cK=(B,K,A=0)=>{if(!Array.isArray(B))return A;let $=Number(A);for(let Q=0;Q<B.length;Q++){let O=K?B[Q][K]:B[Q];$+=Number(O)||0}return $},iK=(B)=>{try{let K=JSON.stringify(B,null,2),A=new String(K);return A.__safe__=!0,A}catch{return String(B)}},sK=(B)=>{let K=Bun.escapeHTML(String(B)),A=new String(K);return A.__safe__=!0,A},dK={a:"2",b:"2",c:"2",d:"3",e:"3",f:"3",g:"4",h:"4",i:"4",j:"5",k:"5",l:"5",m:"6",n:"6",o:"6",p:"7",q:"7",r:"7",s:"7",t:"8",u:"8",v:"8",w:"9",x:"9",y:"9",z:"9"},uK=(B)=>{let K=String(B).toLowerCase(),A=K.length,$=Array(A);for(let Q=0;Q<A;Q++)$[Q]=dK[K[Q]]??K[Q];return $.join("")},rK=(B)=>{let K=String(B).split(`
16
- `),A=String(K.length).length,$="";for(let Q=0;Q<K.length;Q++){if(Q>0)$+=`
17
- `;$+=`${String(Q+1).padStart(A," ")}. ${K[Q]}`}return $},lK=(B)=>{if(!Array.isArray(B))return String(B);let K=(Q,O=0)=>{let U=" ".repeat(O),Y="";for(let Z=0;Z<Q.length;Z++){let J=Q[Z];if(Array.isArray(J))Y+=`
11
+ `||B==="\r"}isDigit(B){let K=B.charCodeAt(0);return K>=48&&K<=57}isAlpha(B){let K=B.charCodeAt(0);return K>=97&&K<=122||K>=65&&K<=90}isAlphaNumeric(B){let K=B.charCodeAt(0);return K>=48&&K<=57||K>=97&&K<=122||K>=65&&K<=90}addToken(B,K){this.state.tokens.push({type:B,value:K,line:this.state.line,column:this.state.column-K.length})}}class N{tokens;current=0;source;constructor(B,K){this.tokens=B,this.source=K}parse(){let B=[];while(!this.isAtEnd()){let K=this.parseStatement();if(K)B.push(K)}return{type:"Template",body:B,line:1,column:1}}parseStatement(){switch(this.peek().type){case"TEXT":return this.parseText();case"VARIABLE_START":return this.parseOutput();case"BLOCK_START":return this.parseBlock();case"EOF":return null;default:return this.advance(),null}}parseText(){let B=this.advance();return{type:"Text",value:B.value,line:B.line,column:B.column}}parseOutput(){let B=this.advance(),K=this.parseExpression();return this.expect("VARIABLE_END"),{type:"Output",expression:K,line:B.line,column:B.column}}parseBlock(){let B=this.advance(),K=this.expect("NAME");switch(K.value){case"if":return this.parseIf(B);case"for":return this.parseFor(B);case"block":return this.parseBlockTag(B);case"extends":return this.parseExtends(B);case"include":return this.parseInclude(B);case"set":return this.parseSet(B);case"with":return this.parseWith(B);case"load":return this.parseLoad(B);case"url":return this.parseUrl(B);case"static":return this.parseStatic(B);case"now":return this.parseNow(B);case"comment":return this.parseComment(B);case"spaceless":case"autoescape":case"verbatim":return this.parseSimpleBlock(B,K.value);case"cycle":return this.parseCycle(B);case"firstof":return this.parseFirstof(B);case"ifchanged":return this.parseIfchanged(B);case"regroup":return this.parseRegroup(B);case"widthratio":return this.parseWidthratio(B);case"lorem":return this.parseLorem(B);case"csrf_token":return this.parseCsrfToken(B);case"debug":return this.parseDebug(B);case"templatetag":return this.parseTemplatetag(B);case"ifequal":return this.parseIfequal(B,!1);case"ifnotequal":return this.parseIfequal(B,!0);default:return this.skipToBlockEnd(),null}}parseIf(B){let K=this.parseExpression();this.expect("BLOCK_END");let A=[],Q=[],$=[];while(!this.isAtEnd()){if(this.checkBlockTag("elif")||this.checkBlockTag("else")||this.checkBlockTag("endif"))break;let Z=this.parseStatement();if(Z)A.push(Z)}while(this.checkBlockTag("elif")){this.advance(),this.advance();let Z=this.parseExpression();this.expect("BLOCK_END");let U=[];while(!this.isAtEnd()){if(this.checkBlockTag("elif")||this.checkBlockTag("else")||this.checkBlockTag("endif"))break;let Y=this.parseStatement();if(Y)U.push(Y)}Q.push({test:Z,body:U})}if(this.checkBlockTag("else")){this.advance(),this.advance(),this.expect("BLOCK_END");while(!this.isAtEnd()){if(this.checkBlockTag("endif"))break;let Z=this.parseStatement();if(Z)$.push(Z)}}return this.expectBlockTag("endif"),{type:"If",test:K,body:A,elifs:Q,else_:$,line:B.line,column:B.column}}parseFor(B){let K,A=this.expect("NAME").value;if(this.check("COMMA")){let O=[A];while(this.match("COMMA"))O.push(this.expect("NAME").value);K=O}else K=A;let Q=this.expect("NAME");if(Q.value!=="in")throw this.error(`Expected 'in' in for loop, got '${Q.value}'`);let $=this.parseExpression(),Z=this.check("NAME")&&this.peek().value==="recursive";if(Z)this.advance();this.expect("BLOCK_END");let U=[],Y=[];while(!this.isAtEnd()){if(this.checkBlockTag("empty")||this.checkBlockTag("else")||this.checkBlockTag("endfor"))break;let O=this.parseStatement();if(O)U.push(O)}if(this.checkBlockTag("empty")||this.checkBlockTag("else")){this.advance(),this.advance(),this.expect("BLOCK_END");while(!this.isAtEnd()){if(this.checkBlockTag("endfor"))break;let O=this.parseStatement();if(O)Y.push(O)}}return this.expectBlockTag("endfor"),{type:"For",target:K,iter:$,body:U,else_:Y,recursive:Z,line:B.line,column:B.column}}parseBlockTag(B){let K=this.expect("NAME").value,A=this.check("NAME")&&this.peek().value==="scoped";if(A)this.advance();this.expect("BLOCK_END");let Q=[];while(!this.isAtEnd()){if(this.checkBlockTag("endblock"))break;let $=this.parseStatement();if($)Q.push($)}if(this.advance(),this.advance(),this.check("NAME"))this.advance();return this.expect("BLOCK_END"),{type:"Block",name:K,body:Q,scoped:A,line:B.line,column:B.column}}parseExtends(B){let K=this.parseExpression();return this.expect("BLOCK_END"),{type:"Extends",template:K,line:B.line,column:B.column}}parseInclude(B){let K=this.parseExpression(),A=null,Q=!1,$=!1;while(this.check("NAME")){let Z=this.peek().value;if(Z==="ignore"&&this.peekNext()?.value==="missing")this.advance(),this.advance(),$=!0;else if(Z==="with")this.advance(),A=this.parseKeywordArgs();else if(Z==="only")this.advance(),Q=!0;else if(Z==="without"){if(this.advance(),this.check("NAME")&&this.peek().value==="context")this.advance(),Q=!0}else break}return this.expect("BLOCK_END"),{type:"Include",template:K,context:A,only:Q,ignoreMissing:$,line:B.line,column:B.column}}parseSet(B){let K=this.expect("NAME").value;this.expect("ASSIGN");let A=this.parseExpression();return this.expect("BLOCK_END"),{type:"Set",target:K,value:A,line:B.line,column:B.column}}parseWith(B){let K=[];do{let Q=this.expect("NAME").value;this.expect("ASSIGN");let $=this.parseExpression();K.push({target:Q,value:$})}while(this.match("COMMA")||this.check("NAME")&&this.peekNext()?.type==="ASSIGN");this.expect("BLOCK_END");let A=[];while(!this.isAtEnd()){if(this.checkBlockTag("endwith"))break;let Q=this.parseStatement();if(Q)A.push(Q)}return this.expectBlockTag("endwith"),{type:"With",assignments:K,body:A,line:B.line,column:B.column}}parseLoad(B){let K=[];while(this.check("NAME"))K.push(this.advance().value);return this.expect("BLOCK_END"),{type:"Load",names:K,line:B.line,column:B.column}}parseUrl(B){let K=this.parseExpression(),A=[],Q={},$=null;while(!this.check("BLOCK_END")){if(this.check("NAME")&&this.peek().value==="as"){this.advance(),$=this.expect("NAME").value;break}if(this.check("NAME")&&this.peekNext()?.type==="ASSIGN"){let Z=this.advance().value;this.advance(),Q[Z]=this.parseExpression()}else A.push(this.parseExpression())}return this.expect("BLOCK_END"),{type:"Url",name:K,args:A,kwargs:Q,asVar:$,line:B.line,column:B.column}}parseStatic(B){let K=this.parseExpression(),A=null;if(this.check("NAME")&&this.peek().value==="as")this.advance(),A=this.expect("NAME").value;return this.expect("BLOCK_END"),{type:"Static",path:K,asVar:A,line:B.line,column:B.column}}parseNow(B){let K=this.parseExpression(),A=null;if(this.check("NAME")&&this.peek().value==="as")this.advance(),A=this.expect("NAME").value;return this.expect("BLOCK_END"),{type:"Now",format:K,asVar:A,line:B.line,column:B.column}}parseComment(B){this.expect("BLOCK_END");while(!this.isAtEnd()){if(this.checkBlockTag("endcomment"))break;this.advance()}return this.expectBlockTag("endcomment"),null}parseSimpleBlock(B,K){this.skipToBlockEnd();let A=`end${K}`;while(!this.isAtEnd()){if(this.checkBlockTag(A))break;this.advance()}if(this.checkBlockTag(A))this.advance(),this.advance(),this.expect("BLOCK_END");return null}parseCycle(B){let K=[],A=null,Q=!1;while(!this.check("BLOCK_END")){if(this.check("NAME")&&this.peek().value==="as"){if(this.advance(),A=this.expect("NAME").value,this.check("NAME")&&this.peek().value==="silent")this.advance(),Q=!0;break}K.push(this.parseExpression())}return this.expect("BLOCK_END"),{type:"Cycle",values:K,asVar:A,silent:Q,line:B.line,column:B.column}}parseFirstof(B){let K=[],A=null,Q=null;while(!this.check("BLOCK_END")){if(this.check("NAME")&&this.peek().value==="as"){this.advance(),Q=this.expect("NAME").value;break}K.push(this.parseExpression())}if(K.length>0){let $=K[K.length-1];if($.type==="Literal"&&typeof $.value==="string")A=K.pop()}return this.expect("BLOCK_END"),{type:"Firstof",values:K,fallback:A,asVar:Q,line:B.line,column:B.column}}parseIfchanged(B){let K=[];while(!this.check("BLOCK_END"))K.push(this.parseExpression());this.expect("BLOCK_END");let A=[],Q=[];while(!this.isAtEnd()){if(this.checkBlockTag("else")||this.checkBlockTag("endifchanged"))break;let $=this.parseStatement();if($)A.push($)}if(this.checkBlockTag("else")){this.advance(),this.advance(),this.expect("BLOCK_END");while(!this.isAtEnd()){if(this.checkBlockTag("endifchanged"))break;let $=this.parseStatement();if($)Q.push($)}}return this.expectBlockTag("endifchanged"),{type:"Ifchanged",values:K,body:A,else_:Q,line:B.line,column:B.column}}parseRegroup(B){let K=this.parseExpression();this.expectName("by");let A=this.expect("NAME").value;this.expectName("as");let Q=this.expect("NAME").value;return this.expect("BLOCK_END"),{type:"Regroup",target:K,key:A,asVar:Q,line:B.line,column:B.column}}parseWidthratio(B){let K=this.parseExpression(),A=this.parseExpression(),Q=this.parseExpression(),$=null;if(this.check("NAME")&&this.peek().value==="as")this.advance(),$=this.expect("NAME").value;return this.expect("BLOCK_END"),{type:"Widthratio",value:K,maxValue:A,maxWidth:Q,asVar:$,line:B.line,column:B.column}}parseLorem(B){let K=null,A="p",Q=!1;if(this.check("NUMBER"))K={type:"Literal",value:parseInt(this.advance().value,10),line:B.line,column:B.column};if(this.check("NAME")){let $=this.peek().value.toLowerCase();if($==="w"||$==="p"||$==="b")A=$,this.advance()}if(this.check("NAME")&&this.peek().value==="random")Q=!0,this.advance();return this.expect("BLOCK_END"),{type:"Lorem",count:K,method:A,random:Q,line:B.line,column:B.column}}parseCsrfToken(B){return this.expect("BLOCK_END"),{type:"CsrfToken",line:B.line,column:B.column}}parseDebug(B){return this.expect("BLOCK_END"),{type:"Debug",line:B.line,column:B.column}}parseTemplatetag(B){let K=this.expect("NAME").value;return this.expect("BLOCK_END"),{type:"Templatetag",tagType:K,line:B.line,column:B.column}}parseIfequal(B,K){let A=this.parseExpression(),Q=this.parseExpression();this.expect("BLOCK_END");let $={type:"Compare",left:A,ops:[{operator:K?"!=":"==",right:Q}],line:B.line,column:B.column},Z=[],U=[],Y=K?"endifnotequal":"endifequal";while(!this.isAtEnd()){if(this.checkBlockTag("else")||this.checkBlockTag(Y))break;let O=this.parseStatement();if(O)Z.push(O)}if(this.checkBlockTag("else")){this.advance(),this.advance(),this.expect("BLOCK_END");while(!this.isAtEnd()){if(this.checkBlockTag(Y))break;let O=this.parseStatement();if(O)U.push(O)}}return this.expectBlockTag(Y),{type:"If",test:$,body:Z,elifs:[],else_:U,line:B.line,column:B.column}}parseExpression(){return this.parseConditional()}parseConditional(){let B=this.parseOr();if(this.check("NAME")&&this.peek().value==="if"){this.advance();let K=this.parseOr();this.expectName("else");let A=this.parseConditional();B={type:"Conditional",test:K,trueExpr:B,falseExpr:A,line:B.line,column:B.column}}return B}parseOr(){let B=this.parseAnd();while(this.check("OR")||this.check("NAME")&&this.peek().value==="or"){this.advance();let K=this.parseAnd();B={type:"BinaryOp",operator:"or",left:B,right:K,line:B.line,column:B.column}}return B}parseAnd(){let B=this.parseNot();while(this.check("AND")||this.check("NAME")&&this.peek().value==="and"){this.advance();let K=this.parseNot();B={type:"BinaryOp",operator:"and",left:B,right:K,line:B.line,column:B.column}}return B}parseNot(){if(this.check("NOT")||this.check("NAME")&&this.peek().value==="not"){let B=this.advance();return{type:"UnaryOp",operator:"not",operand:this.parseNot(),line:B.line,column:B.column}}return this.parseCompare()}parseCompare(){let B=this.parseAddSub(),K=[];while(!0){let A=null;if(this.match("EQ"))A="==";else if(this.match("NE"))A="!=";else if(this.match("LT"))A="<";else if(this.match("GT"))A=">";else if(this.match("LE"))A="<=";else if(this.match("GE"))A=">=";else if(this.check("NAME")){let $=this.peek().value;if($==="in")this.advance(),A="in";else if($==="not"&&this.peekNext()?.value==="in")this.advance(),this.advance(),A="not in";else if($==="is"){this.advance();let Z=this.check("NOT");if(Z)this.advance();let Y=this.expect("NAME").value,O=[];if(this.match("LPAREN")){while(!this.check("RPAREN"))if(O.push(this.parseExpression()),!this.check("RPAREN"))this.expect("COMMA");this.expect("RPAREN")}B={type:"TestExpr",node:B,test:Y,args:O,negated:Z,line:B.line,column:B.column};continue}}if(!A)break;let Q=this.parseAddSub();K.push({operator:A,right:Q})}if(K.length===0)return B;return{type:"Compare",left:B,ops:K,line:B.line,column:B.column}}parseAddSub(){let B=this.parseMulDiv();while(this.check("ADD")||this.check("SUB")||this.check("TILDE")){let K=this.advance(),A=this.parseMulDiv();B={type:"BinaryOp",operator:K.value,left:B,right:A,line:B.line,column:B.column}}return B}parseMulDiv(){let B=this.parseUnary();while(this.check("MUL")||this.check("DIV")||this.check("MOD")){let K=this.advance(),A=this.parseUnary();B={type:"BinaryOp",operator:K.value,left:B,right:A,line:B.line,column:B.column}}return B}parseUnary(){if(this.check("SUB")||this.check("ADD")){let B=this.advance(),K=this.parseUnary();return{type:"UnaryOp",operator:B.value,operand:K,line:B.line,column:B.column}}return this.parseFilter()}parseFilter(){let B=this.parsePostfix();while(this.match("PIPE")){let K=this.expect("NAME").value,A=[],Q={};if(this.match("COLON"))if(this.check("SUB")||this.check("ADD")){let $=this.advance(),Z=this.parsePostfix();A.push({type:"UnaryOp",operator:$.value,operand:Z,line:$.line,column:$.column})}else A.push(this.parsePostfix());else if(this.match("LPAREN")){while(!this.check("RPAREN")){if(this.check("NAME")&&this.peekNext()?.type==="ASSIGN"){let $=this.advance().value;this.advance(),Q[$]=this.parseExpression()}else A.push(this.parseExpression());if(!this.check("RPAREN"))this.expect("COMMA")}this.expect("RPAREN")}B={type:"FilterExpr",node:B,filter:K,args:A,kwargs:Q,line:B.line,column:B.column}}return B}parsePostfix(){let B=this.parsePrimary();while(!0)if(this.match("DOT")){let K;if(this.check("NUMBER"))K=this.advance().value;else K=this.expect("NAME").value;B={type:"GetAttr",object:B,attribute:K,line:B.line,column:B.column}}else if(this.match("LBRACKET")){let K=this.parseExpression();this.expect("RBRACKET"),B={type:"GetItem",object:B,index:K,line:B.line,column:B.column}}else if(this.match("LPAREN")){let K=[],A={};while(!this.check("RPAREN")){if(this.check("NAME")&&this.peekNext()?.type==="ASSIGN"){let Q=this.advance().value;this.advance(),A[Q]=this.parseExpression()}else K.push(this.parseExpression());if(!this.check("RPAREN"))this.expect("COMMA")}this.expect("RPAREN"),B={type:"FunctionCall",callee:B,args:K,kwargs:A,line:B.line,column:B.column}}else break;return B}parsePrimary(){let B=this.peek();if(this.match("STRING"))return{type:"Literal",value:B.value,line:B.line,column:B.column};if(this.match("NUMBER"))return{type:"Literal",value:B.value.includes(".")?parseFloat(B.value):parseInt(B.value,10),line:B.line,column:B.column};if(this.check("NAME")){let K=this.advance().value;if(K==="true"||K==="True")return{type:"Literal",value:!0,line:B.line,column:B.column};if(K==="false"||K==="False")return{type:"Literal",value:!1,line:B.line,column:B.column};if(K==="none"||K==="None"||K==="null")return{type:"Literal",value:null,line:B.line,column:B.column};return{type:"Name",name:K,line:B.line,column:B.column}}if(this.match("LPAREN")){let K=this.parseExpression();return this.expect("RPAREN"),K}if(this.match("LBRACKET")){let K=[];while(!this.check("RBRACKET"))if(K.push(this.parseExpression()),!this.check("RBRACKET"))this.expect("COMMA");return this.expect("RBRACKET"),{type:"Array",elements:K,line:B.line,column:B.column}}if(this.match("LBRACE")){let K=[];while(!this.check("RBRACE")){let A=this.parseExpression();this.expect("COLON");let Q=this.parseExpression();if(K.push({key:A,value:Q}),!this.check("RBRACE"))this.expect("COMMA")}return this.expect("RBRACE"),{type:"Object",pairs:K,line:B.line,column:B.column}}throw this.error(`Unexpected token: ${B.type} (${B.value})`)}parseKeywordArgs(){let B={};while(this.check("NAME")&&this.peekNext()?.type==="ASSIGN"){let K=this.advance().value;this.advance(),B[K]=this.parseExpression()}return B}checkBlockTag(B){if(this.peek().type!=="BLOCK_START")return!1;let K=this.current+1;if(K>=this.tokens.length)return!1;let A=this.tokens[K];return A.type==="NAME"&&A.value===B}expectBlockTag(B){this.advance();let K=this.expect("NAME");if(K.value!==B)throw this.error(`Expected '${B}', got '${K.value}'`);this.expect("BLOCK_END")}expectName(B){let K=this.expect("NAME");if(K.value!==B)throw this.error(`Expected '${B}', got '${K.value}'`)}skipToBlockEnd(){while(!this.isAtEnd()&&!this.check("BLOCK_END"))this.advance();if(this.check("BLOCK_END"))this.advance()}isAtEnd(){return this.peek().type==="EOF"}peek(){return this.tokens[this.current]}peekNext(){if(this.current+1>=this.tokens.length)return null;return this.tokens[this.current+1]}advance(){if(!this.isAtEnd())this.current++;return this.tokens[this.current-1]}check(B){if(this.isAtEnd())return!1;return this.peek().type===B}match(B){if(this.check(B))return this.advance(),!0;return!1}expect(B){if(this.check(B))return this.advance();let K=this.peek();throw this.error(`Expected ${B}, got ${K.type} (${K.value})`)}error(B){let K=this.peek();return new P(B,{line:K.line,column:K.column,source:this.source})}}function PB(B,K,A,Q,$){let Z=B.length,U=Z-K,Y={_items:B,_idx:K,counter:K+1,counter0:K,first:K===0,last:K===Z-1,length:Z,index:K+1,index0:K,depth:A,depth0:A-1,revcounter:U,revcounter0:U-1,revindex:U,revindex0:U-1,get previtem(){return this._idx>0?this._items[this._idx-1]:void 0},get nextitem(){return this._idx<this._items.length-1?this._items[this._idx+1]:void 0},cycle(...O){return O[this._idx%O.length]},changed:(O)=>{let J=O!==Q.value;return Q.value=O,J}};if($)Y.parentloop=$;return Y}class w{scopes=[];parent=null;_forloopStack=[];_lastCycleValue={value:null};_currentForloop=null;_currentScope;constructor(B={},K=null){this.parent=K,this._currentScope={...B},this.scopes.push(this._currentScope)}get(B){if(B==="forloop"||B==="loop")return this._currentForloop;for(let K=this.scopes.length-1;K>=0;K--){let A=this.scopes[K];if(B in A)return A[B]}return this.parent?this.parent.get(B):void 0}set(B,K){this._currentScope[B]=K}has(B){for(let K=this.scopes.length-1;K>=0;K--)if(B in this.scopes[K])return!0;return this.parent?this.parent.has(B):!1}push(B={}){this._currentScope={...B},this.scopes.push(this._currentScope)}pop(){if(this.scopes.length>1)this.scopes.pop(),this._currentScope=this.scopes[this.scopes.length-1]}derived(B={}){return new w(B,this)}pushForLoop(B,K){let A=this._forloopStack.length+1,Q=this._forloopStack.length>0?this._forloopStack[this._forloopStack.length-1]:void 0,$=PB(B,K,A,this._lastCycleValue,Q);return this._forloopStack.push($),this._currentForloop=$,$}popForLoop(){this._forloopStack.pop(),this._currentForloop=this._forloopStack.length>0?this._forloopStack[this._forloopStack.length-1]:null}updateForLoop(B,K){let A=this._currentForloop;if(!A)return;let Q=K.length;if(A._idx=B,A._items!==K)A._items=K;A.counter=B+1,A.counter0=B,A.index=B+1,A.index0=B,A.first=B===0,A.last=B===Q-1;let $=Q-B;A.revcounter=$,A.revcounter0=$-1,A.revindex=$,A.revindex0=$-1}toObject(){let B={};if(this.parent)Object.assign(B,this.parent.toObject());for(let K of this.scopes)Object.assign(B,K);return B}}var DB=/\b\w/g,_B=/<[^>]*>/g,LB=/[^\w\s-]/g,jB=/[\s_-]+/g,qB=/^-+|-+$/g,t=/(https?:\/\/[^\s]+)/g,CB=/[a-zA-Z]/g,NB=/\n\n+/,e=/\n/g,BB=/\s+/,SB=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wB=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],VB=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],bB=["January","February","March","April","May","June","July","August","September","October","November","December"],hB=["Jan.","Feb.","March","April","May","June","July","Aug.","Sept.","Oct.","Nov.","Dec."],fB=(B)=>String(B).toUpperCase(),kB=(B)=>String(B).toLowerCase(),yB=(B)=>{let K=String(B);return K.charAt(0).toUpperCase()+K.slice(1).toLowerCase()},TB=(B)=>{let K=String(B);return K.charAt(0).toUpperCase()+K.slice(1)},gB=(B)=>String(B).replace(DB,(K)=>K.toUpperCase()),xB=(B)=>String(B).trim(),mB=(B)=>String(B).replace(_B,""),l=(B)=>{if(B?.__safe__)return B;let K=Bun.escapeHTML(String(B)),A=new String(K);return A.__safe__=!0,A},pB=(B)=>{let K=new String(B);return K.__safe__=!0,K},cB=(B)=>JSON.stringify(String(B)).slice(1,-1),vB=(B)=>{let A=String(B).split(NB),Q="";for(let Z=0;Z<A.length;Z++){if(Z>0)Q+=`
12
+ `;Q+=`<p>${A[Z].replace(e,"<br>")}</p>`}let $=new String(Q);return $.__safe__=!0,$},iB=(B)=>{let K=String(B).replace(e,"<br>"),A=new String(K);return A.__safe__=!0,A},dB=(B,K=30)=>{let A=String(B);if(A.length<=K)return A;return A.slice(0,K-3)+"..."},sB=(B,K=15)=>{let A=String(B).split(BB);if(A.length<=K)return B;return A.slice(0,K).join(" ")+"..."},uB=(B)=>String(B).split(BB).filter(Boolean).length,rB=(B,K=80)=>{let A=String(B),Q=Math.max(0,K-A.length),$=Math.floor(Q/2),Z=Q-$;return" ".repeat($)+A+" ".repeat(Z)},nB=(B,K=80)=>String(B).padEnd(K),lB=(B,K=80)=>String(B).padStart(K),oB=(B,K="")=>String(B).split(K).join(""),aB=(B)=>String(B).toLowerCase().replace(LB,"").replace(jB,"-").replace(qB,""),tB=(B)=>Math.abs(Number(B)),eB=(B,K=0)=>Number(Number(B).toFixed(K)),BK=(B)=>parseInt(String(B),10)||0,KK=(B)=>parseFloat(String(B))||0,AK=(B,K=-1)=>{let A=parseFloat(String(B));if(isNaN(A))return"";if(K===-1){let Q=A.toFixed(1);return Q.endsWith(".0")?Math.round(A).toString():Q}return A.toFixed(Math.abs(K))},$K=(B,K)=>{let A=Number(B),Q=Number(K);if(!isNaN(A)&&!isNaN(Q))return A+Q;return String(B)+String(K)},QK=(B,K)=>Number(B)%Number(K)===0,OK=(B)=>{let K=Number(B),A=["bytes","KB","MB","GB","TB","PB"],Q=0,$=K;while($>=1024&&Q<A.length-1)$/=1024,Q++;return`${$.toFixed(1)} ${A[Q]}`},KB=(B)=>{if(B==null)return 0;if(typeof B==="string"||Array.isArray(B))return B.length;if(typeof B==="object"){let K=0;for(let A in B)K++;return K}return 0},ZK=(B,K)=>KB(B)===Number(K),JK=(B)=>{if(Array.isArray(B))return B[0];if(typeof B==="string")return B[0];return B},YK=(B)=>{if(Array.isArray(B))return B[B.length-1];if(typeof B==="string")return B[B.length-1];return B},UK=(B,K="")=>{if(Array.isArray(B))return B.join(K);return String(B)},XK=(B,K)=>{if(!B)return B;let[A,Q]=String(K).split(":"),$=A?parseInt(A,10):0,Z=Q?parseInt(Q,10):void 0;if(Array.isArray(B)||typeof B==="string")return B.slice($,Z);return B},MK=(B)=>{if(Array.isArray(B))return[...B].reverse();if(typeof B==="string")return B.split("").reverse().join("");return B},GK=(B,K=!1)=>{if(!Array.isArray(B))return B;let A=[...B].sort();return K?A.reverse():A},FK=(B)=>{if(!Array.isArray(B))return B;let K=new Set,A=[];for(let Q=0;Q<B.length;Q++){let $=B[Q];if(!K.has($))K.add($),A.push($)}return A},IK=(B)=>{if(Array.isArray(B))return B;return String(B).split("")},AB=(B,K)=>{if(!Array.isArray(B))return B;return[...B].sort((A,Q)=>{let $=K?A[K]:A,Z=K?Q[K]:Q;return $<Z?-1:$>Z?1:0})},RK=(B,K)=>{let A=AB(B,K);return Array.isArray(A)?A.reverse():A},HK=(B,K)=>{if(!Array.isArray(B))return[[B]];let A=[],Q=Number(K)||2;for(let $=0;$<B.length;$+=Q)A.push(B.slice($,$+Q));return A},zK=(B,K)=>{switch(K){case"d":return String(B.getDate()).padStart(2,"0");case"j":return String(B.getDate());case"D":return SB[B.getDay()];case"l":return wB[B.getDay()];case"m":return String(B.getMonth()+1).padStart(2,"0");case"n":return String(B.getMonth()+1);case"M":return VB[B.getMonth()];case"F":return bB[B.getMonth()];case"N":return hB[B.getMonth()];case"y":return String(B.getFullYear()).slice(-2);case"Y":return String(B.getFullYear());case"H":return String(B.getHours()).padStart(2,"0");case"G":return String(B.getHours());case"i":return String(B.getMinutes()).padStart(2,"0");case"s":return String(B.getSeconds()).padStart(2,"0");case"a":return B.getHours()<12?"a.m.":"p.m.";case"A":return B.getHours()<12?"AM":"PM";case"g":return String(B.getHours()%12||12);case"h":return String(B.getHours()%12||12).padStart(2,"0");default:return K}},$B=(B,K="N j, Y")=>{let A=B instanceof Date?B:new Date(B);if(isNaN(A.getTime()))return"";return K.replace(CB,(Q)=>zK(A,Q))},EK=(B,K="H:i")=>$B(B,K),WK=(B,K=new Date)=>{let A=B instanceof Date?B:new Date(B),Q=(new Date(K).getTime()-A.getTime())/1000,$=[[31536000,"year","years"],[2592000,"month","months"],[604800,"week","weeks"],[86400,"day","days"],[3600,"hour","hours"],[60,"minute","minutes"]];for(let[Z,U,Y]of $){let O=Math.floor(Q/Z);if(O>=1)return`${O} ${O===1?U:Y}`}return"just now"},PK=(B,K=new Date)=>{let Q=((B instanceof Date?B:new Date(B)).getTime()-new Date(K).getTime())/1000,$=[[31536000,"year","years"],[2592000,"month","months"],[604800,"week","weeks"],[86400,"day","days"],[3600,"hour","hours"],[60,"minute","minutes"]];for(let[Z,U,Y]of $){let O=Math.floor(Q/Z);if(O>=1)return`${O} ${O===1?U:Y}`}return"now"},o=(B,K="")=>{if(B===void 0||B===null||B===""||B===!1)return K;return B};var DK=(B,K="")=>B===null||B===void 0?K:B,_K=(B,K="yes,no,maybe")=>{let[A,Q,$]=K.split(",");if(B===!0)return A;if(B===!1)return Q;return $??Q},LK=(B,K="s")=>{let[A,Q]=K.includes(",")?K.split(","):["",K];return Number(B)===1?A:Q},jK=(B)=>encodeURIComponent(String(B)),qK=(B)=>{let K=String(B).replace(t,'<a href="$1">$1</a>'),A=new String(K);return A.__safe__=!0,A},a=(B,K)=>{try{let A=JSON.stringify(B,null,K),Q=new String(A);return Q.__safe__=!0,Q}catch{return""}},CK=(B)=>{if(Array.isArray(B))return B[Math.floor(Math.random()*B.length)];return B},NK=(B,K,A=null)=>{if(!Array.isArray(B))return[[B]];let Q=[],$=Number(K)||1;for(let Z=0;Z<B.length;Z+=$){let U=B.slice(Z,Z+$);while(A!==null&&U.length<$)U.push(A);Q.push(U)}return Q},SK=(B,K)=>{if(!Array.isArray(B))return[];let A={};for(let $ of B){let Z=String(K?$[K]:$);if(!(Z in A))A[Z]=[];A[Z].push($)}let Q=[];for(let $ in A)Q.push({grouper:$,list:A[$]});return Q},wK=(B,K=79,A=!0,Q=`
13
+ `)=>{let $=String(B);if($.length<=K)return $;let Z=$.split(" "),U=[],Y="";for(let O of Z)if(Y.length+O.length+1<=K)Y+=(Y?" ":"")+O;else{if(Y)U.push(Y);if(A&&O.length>K){let J=O;while(J.length>K)U.push(J.slice(0,K)),J=J.slice(K);Y=J}else Y=O}if(Y)U.push(Y);return U.join(Q)},VK=(B,K=4,A=!1,Q=!1)=>{let $=String(B),Z=typeof K==="string"?K:" ".repeat(Number(K)),U=$.split(`
14
+ `),Y="";for(let O=0;O<U.length;O++){if(O>0)Y+=`
15
+ `;let J=U[O];if(O===0&&!A)Y+=J;else if(!Q&&J.trim()==="")Y+=J;else Y+=Z+J}return Y},bK=(B,K,A,Q)=>{let $=String(B),Z=String(K),U=String(A);if(Q===void 0||Q<0)return $.replaceAll(Z,U);let Y=Number(Q);if(Y===0)return $;let O="",J=0,X=0;while(J<$.length&&X<Y){let M=$.indexOf(Z,J);if(M===-1)break;O+=$.slice(J,M)+U,J=M+Z.length,X++}return O+=$.slice(J),O},hK=(B,...K)=>{let A=String(B);for(let Q=0;Q<K.length;Q++){let $=String(K[Q]);A=A.replace(/%s/,$);let Z=`%${Q+1}`;if(A.includes(Z))A=A.replaceAll(Z,$)}return A},fK=(B)=>String(B),kK=(B)=>{if(Array.isArray(B))return B;if(typeof B==="string")return B.split("");if(B&&typeof B[Symbol.iterator]==="function")return[...B];if(typeof B==="object"&&B!==null)return Object.values(B);return[B]},yK=(B,K)=>{if(!Array.isArray(B))return[];if(typeof K==="string")return B.map((A)=>A?.[K]);return B},TK=(B,K)=>{if(!Array.isArray(B))return[];if(K===void 0)return B.filter((A)=>!!A);return B.filter((A)=>!!A?.[K])},gK=(B,K)=>{if(!Array.isArray(B))return[];if(K===void 0)return B.filter((A)=>!A);return B.filter((A)=>!A?.[K])},QB=(B,K,A,Q)=>{if(!Array.isArray(B))return[];return B.filter(($)=>{let Z=$?.[K];if(A===void 0)return!!Z;if(A==="eq"||A==="equalto")return Z===Q;if(A==="ne")return Z!==Q;if(A==="gt")return Z>Q;if(A==="lt")return Z<Q;if(A==="ge"||A==="gte")return Z>=Q;if(A==="le"||A==="lte")return Z<=Q;if(A==="in")return Q?.includes?.(Z);if(A==="defined")return Z!==void 0;if(A==="undefined")return Z===void 0;if(A==="none")return Z===null;if(A==="true")return Z===!0;if(A==="false")return Z===!1;return!!Z})},xK=(B,K,A,Q)=>{if(!Array.isArray(B))return[];let $=QB(B,K,A,Q);return B.filter((Z)=>!$.includes(Z))},mK=(B,K)=>{if(B==null)return;return B[K]},pK=(B,K,A)=>{if(!Array.isArray(B)||B.length===0)return A;if(K){let $=B[0];for(let Z=1;Z<B.length;Z++)if(B[Z][K]>$[K])$=B[Z];return $}let Q=B[0];for(let $=1;$<B.length;$++)if(B[$]>Q)Q=B[$];return Q},cK=(B,K,A)=>{if(!Array.isArray(B)||B.length===0)return A;if(K){let $=B[0];for(let Z=1;Z<B.length;Z++)if(B[Z][K]<$[K])$=B[Z];return $}let Q=B[0];for(let $=1;$<B.length;$++)if(B[$]<Q)Q=B[$];return Q},vK=(B,K,A=0)=>{if(!Array.isArray(B))return A;let Q=Number(A);for(let $=0;$<B.length;$++){let Z=K?B[$][K]:B[$];Q+=Number(Z)||0}return Q},iK=(B)=>{try{let K=JSON.stringify(B,null,2),A=new String(K);return A.__safe__=!0,A}catch{return String(B)}},dK=(B)=>{let K=Bun.escapeHTML(String(B)),A=new String(K);return A.__safe__=!0,A},sK={a:"2",b:"2",c:"2",d:"3",e:"3",f:"3",g:"4",h:"4",i:"4",j:"5",k:"5",l:"5",m:"6",n:"6",o:"6",p:"7",q:"7",r:"7",s:"7",t:"8",u:"8",v:"8",w:"9",x:"9",y:"9",z:"9"},uK=(B)=>{let K=String(B).toLowerCase(),A=K.length,Q=Array(A);for(let $=0;$<A;$++)Q[$]=sK[K[$]]??K[$];return Q.join("")},rK=(B)=>{let K=String(B).split(`
16
+ `),A=String(K.length).length,Q="";for(let $=0;$<K.length;$++){if($>0)Q+=`
17
+ `;Q+=`${String($+1).padStart(A," ")}. ${K[$]}`}return Q},nK=(B)=>{if(!Array.isArray(B))return String(B);let K=($,Z=0)=>{let U=" ".repeat(Z),Y="";for(let O=0;O<$.length;O++){let J=$[O];if(Array.isArray(J))Y+=`
18
18
  ${U}<ul>
19
- ${K(J,O+1)}${U}</ul>
20
- `;else{if(Y+=`${U}<li>${J}`,Z+1<Q.length&&Array.isArray(Q[Z+1]))Y+=`
19
+ ${K(J,Z+1)}${U}</ul>
20
+ `;else{if(Y+=`${U}<li>${J}`,O+1<$.length&&Array.isArray($[O+1]))Y+=`
21
21
  ${U}<ul>
22
- ${K(Q[Z+1],O+1)}${U}</ul>
23
- ${U}`,Z++;Y+=`</li>
24
- `}}return Y},A=K(B),$=new String(A);return $.__safe__=!0,$},nK=(B)=>{let K=String(B).replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,"\\\""),A=new String(K);return A.__safe__=!0,A},oK=(B,K)=>{let A=parseInt(String(B),10);if(isNaN(A))return B;let $=String(Math.abs(A)),Q=Number(K)||1;if(Q<1||Q>$.length)return B;return parseInt($[$.length-Q],10)},aK=(B)=>{return String(B).replace(/ /g,"%20").replace(/"/g,"%22").replace(/</g,"%3C").replace(/>/g,"%3E").replace(/\\/g,"%5C").replace(/\^/g,"%5E").replace(/`/g,"%60").replace(/\{/g,"%7B").replace(/\|/g,"%7C").replace(/\}/g,"%7D")},tK=(B,K)=>{let A=JSON.stringify(B).replace(/</g,"\\u003C").replace(/>/g,"\\u003E").replace(/&/g,"\\u0026"),Q=`<script${K?` id="${String(K)}"`:""} type="application/json">${A}</script>`,O=new String(Q);return O.__safe__=!0,O},eK=(B)=>{if(!Array.isArray(B))return B;return B.map((K)=>{let A=new String(K);return A.__safe__=!0,A})},BA=(B,K)=>{let A=String(K),$=B;if(A==="s")return String($);if(A==="d"||A==="i")return String(parseInt(String($),10)||0);if(A==="f")return String(parseFloat(String($))||0);if(A==="x")return(parseInt(String($),10)||0).toString(16);if(A==="X")return(parseInt(String($),10)||0).toString(16).toUpperCase();if(A==="o")return(parseInt(String($),10)||0).toString(8);if(A==="b")return(parseInt(String($),10)||0).toString(2);if(A==="e")return(parseFloat(String($))||0).toExponential();let Q=A.match(/^\.?(\d+)f$/);if(Q){let U=parseInt(Q[1],10);return(parseFloat(String($))||0).toFixed(U)}let O=A.match(/^(\d+)([sd])$/);if(O){let U=parseInt(O[1],10),Y=O[2];return(Y==="d"?String(parseInt(String($),10)||0):String($)).padStart(U,Y==="d"?"0":" ")}return String($)},KA=(B,K=30)=>{let A=String(B),$=Number(K),Q="",O=0,U=!1,Y=[];for(let J=0;J<A.length&&O<$;J++){let X=A[J];if(X==="<"){U=!0;let M=A.slice(J).match(/^<\/(\w+)/),G=A.slice(J).match(/^<(\w+)/);if(M){let R=M[1].toLowerCase(),F=Y.lastIndexOf(R);if(F!==-1)Y.splice(F,1)}else if(G&&!A.slice(J).match(/^<\w+[^>]*\/>/))Y.push(G[1].toLowerCase())}if(Q+=X,X===">")U=!1;else if(!U)O++}if(O>=$&&A.length>Q.length)Q+="...";for(let J=Y.length-1;J>=0;J--)Q+=`</${Y[J]}>`;let Z=new String(Q);return Z.__safe__=!0,Z},AA=(B,K=15)=>{let A=String(B),$=Number(K),Q="",O=0,U=!1,Y=!1,Z=[];for(let X=0;X<A.length&&O<$;X++){let M=A[X];if(M==="<"){U=!0;let G=A.slice(X).match(/^<\/(\w+)/),R=A.slice(X).match(/^<(\w+)/);if(G){let F=G[1].toLowerCase(),W=Z.lastIndexOf(F);if(W!==-1)Z.splice(W,1)}else if(R&&!A.slice(X).match(/^<\w+[^>]*\/>/))Z.push(R[1].toLowerCase())}if(Q+=M,M===">")U=!1;else if(!U){let G=/\s/.test(M);if(!G&&!Y)Y=!0;else if(G&&Y)Y=!1,O++}}if(Y)O++;if(O>=$)Q=Q.trimEnd()+"...";for(let X=Z.length-1;X>=0;X--)Q+=`</${Z[X]}>`;let J=new String(Q);return J.__safe__=!0,J},$A=(B,K=15)=>{let A=Number(K),$=String(B).replace(t,(O)=>{let U=O.length>A?O.slice(0,A)+"...":O;return`<a href="${O}">${U}</a>`}),Q=new String($);return Q.__safe__=!0,Q},QA=(B)=>{if(B==null||typeof B!=="object")return[];return Object.entries(B)},OA=(B,K=!0)=>{if(B==null||typeof B!=="object")return"";let A=[];for(let[U,Y]of Object.entries(B))if(Y===!0)A.push(U);else if(Y!==!1&&Y!=null){let Z=Bun.escapeHTML(String(Y));A.push(`${U}="${Z}"`)}let $=A.join(" "),Q=K&&$?" "+$:$,O=new String(Q);return O.__safe__=!0,O},h={upper:fB,lower:kB,capitalize:yB,capfirst:TB,title:gB,trim:xB,striptags:mB,escape:n,e:n,safe:pB,escapejs:vB,linebreaks:cB,linebreaksbr:iB,truncatechars:sB,truncatewords:dB,wordcount:uB,center:rB,ljust:lB,rjust:nB,cut:oB,slugify:aB,abs:tB,round:eB,int:BK,float:KK,floatformat:AK,add:$K,divisibleby:QK,filesizeformat:OK,length:KB,length_is:ZK,first:JK,last:YK,join:UK,slice:XK,reverse:MK,sort:GK,unique:FK,make_list:IK,dictsort:AB,dictsortreversed:RK,columns:HK,date:$B,time:EK,timesince:WK,timeuntil:PK,default:o,d:o,default_if_none:DK,yesno:_K,pluralize:LK,urlencode:jK,urlize:qK,json:a,tojson:a,random:CK,batch:NK,groupby:SK,wordwrap:wK,indent:VK,replace:bK,format:hK,string:fK,list:kK,map:yK,select:TK,reject:gK,selectattr:QB,rejectattr:xK,attr:mK,max:pK,min:vK,sum:cK,pprint:iK,forceescape:sK,phone2numeric:uK,linenumbers:rK,unordered_list:lK,addslashes:nK,get_digit:oK,iriencode:aK,json_script:tK,safeseq:eK,stringformat:BA,truncatechars_html:KA,truncatewords_html:AA,urlizetrunc:$A,items:QA,xmlattr:OA};var ZA=(B,K)=>{let A=Number(B),$=Number(K);if($===0)return!1;return A%$===0},JA=(B)=>{let K=Number(B);return Number.isInteger(K)&&K%2===0},YA=(B)=>{let K=Number(B);return Number.isInteger(K)&&K%2!==0},UA=(B)=>{return typeof B==="number"&&!isNaN(B)},XA=(B)=>{return Number.isInteger(B)},MA=(B)=>{return typeof B==="number"&&!Number.isInteger(B)&&!isNaN(B)},ZB=(B,K)=>Number(B)>Number(K),GA=(B,K)=>Number(B)>=Number(K),JB=(B,K)=>Number(B)<Number(K),FA=(B,K)=>Number(B)<=Number(K),IA=ZB,RA=JB,HA=(B)=>{return B!==v},v=(B)=>{return B===v},OB=(B)=>{return B===null},zA=(B)=>{return typeof B==="boolean"},EA=(B)=>{return typeof B==="string"},WA=(B)=>{return B!==null&&typeof B==="object"&&!Array.isArray(B)&&!(B instanceof Date)},PA=(B)=>{if(B==null)return!1;return typeof B==="string"||Array.isArray(B)||typeof B[Symbol.iterator]==="function"},DA=(B)=>{return Array.isArray(B)||typeof B==="string"},_A=(B)=>{return typeof B==="function"},LA=(B)=>{if(typeof B!=="string")return!1;return B===B.toLowerCase()&&B!==B.toUpperCase()},jA=(B)=>{if(typeof B!=="string")return!1;return B===B.toUpperCase()&&B!==B.toLowerCase()},qA=(B)=>{if(B==null)return!0;if(typeof B==="string"||Array.isArray(B))return B.length===0;if(typeof B==="object"){for(let K in B)return!1;return!0}return!1},CA=(B,K)=>{if(Array.isArray(K))return K.includes(B);if(typeof K==="string")return K.includes(String(B));if(typeof K==="object"&&K!==null)return B in K;return!1},YB=(B,K)=>B===K,NA=(B,K)=>B!==K,SA=(B,K)=>B===K,wA=YB,UB=(B)=>{if(B==null)return!1;if(typeof B==="boolean")return B;if(typeof B==="number")return B!==0;if(typeof B==="string")return B.length>0;if(Array.isArray(B))return B.length>0;if(typeof B==="object"){for(let K in B)return!0;return!1}return!0},VA=(B)=>!UB(B),bA=(B)=>B===!0,hA=(B)=>B===!1,f={divisibleby:ZA,even:JA,odd:YA,number:UA,integer:XA,float:MA,gt:ZB,ge:GA,lt:JB,le:FA,greaterthan:IA,lessthan:RA,defined:HA,undefined:v,none:OB,None:OB,boolean:zA,string:EA,mapping:WA,iterable:PA,sequence:DA,callable:_A,lower:LA,upper:jA,empty:qA,in:CA,eq:YB,ne:NA,sameas:SA,equalto:wA,truthy:UB,falsy:VA,true:bA,false:hA};class z{options;filters;tests;blocks=new Map;parentTemplate=null;source;constructor(B={}){if(this.options={autoescape:B.autoescape??!0,filters:B.filters??{},tests:B.tests??{},globals:B.globals??{},urlResolver:B.urlResolver??((K)=>`#${K}`),staticResolver:B.staticResolver??((K)=>`/static/${K}`),templateLoader:B.templateLoader??(async()=>{throw Error("Template loader not configured")}),timezone:B.timezone??void 0},this.filters={...h,...this.options.filters},this.options.timezone){let K=this.options.timezone;this.filters.date=(A,$="N j, Y")=>{let Q=A instanceof Date?A:new Date(A);if(isNaN(Q.getTime()))return"";return this.formatDate(Q,$)},this.filters.time=(A,$="H:i")=>{return this.filters.date(A,$)}}this.tests={...f,...this.options.tests}}async render(B,K={}){let A=new w({...this.options.globals,...K});if(this.blocks.clear(),this.parentTemplate=null,this.templateNeedsAsync(B)){if(await this.collectBlocks(B,A),this.parentTemplate)return this.renderTemplateAsync(this.parentTemplate,A);return this.renderTemplateAsync(B,A)}return this.collectBlocksSync(B),this.renderTemplateSync(B,A)}templateNeedsAsync(B){for(let K of B.body){if(K.type==="Extends"||K.type==="Include")return!0;if(K.type==="If"){let A=K;if(this.nodesNeedAsync(A.body))return!0;for(let $ of A.elifs)if(this.nodesNeedAsync($.body))return!0;if(this.nodesNeedAsync(A.else_))return!0}if(K.type==="For"){let A=K;if(this.nodesNeedAsync(A.body))return!0;if(this.nodesNeedAsync(A.else_))return!0}if(K.type==="Block"){if(this.nodesNeedAsync(K.body))return!0}if(K.type==="With"){if(this.nodesNeedAsync(K.body))return!0}}return!1}nodesNeedAsync(B){for(let K of B){if(K.type==="Extends"||K.type==="Include")return!0;if(K.type==="If"){let A=K;if(this.nodesNeedAsync(A.body))return!0;for(let $ of A.elifs)if(this.nodesNeedAsync($.body))return!0;if(this.nodesNeedAsync(A.else_))return!0}if(K.type==="For"){let A=K;if(this.nodesNeedAsync(A.body))return!0;if(this.nodesNeedAsync(A.else_))return!0}if(K.type==="Block"){if(this.nodesNeedAsync(K.body))return!0}if(K.type==="With"){if(this.nodesNeedAsync(K.body))return!0}}return!1}collectBlocksSync(B){for(let K of B.body)if(K.type==="Block")this.blocks.set(K.name,K)}renderTemplateSync(B,K){let A=[];for(let $ of B.body){let Q=this.renderNodeSync($,K);if(Q!==null)A.push(Q)}return A.join("")}renderNodeSync(B,K){if(B.type==="Text")return B.value;if(B.type==="Output")return this.stringify(this.eval(B.expression,K));switch(B.type){case"If":return this.renderIfSync(B,K);case"For":return this.renderForSync(B,K);case"Block":return this.renderBlockSync(B,K);case"Set":return K.set(B.target,this.eval(B.value,K)),"";case"With":return this.renderWithSync(B,K);case"Url":return this.renderUrlSync(B,K);case"Static":return this.renderStaticSync(B,K);case"Now":return this.renderNowSync(B,K);case"Load":case"Extends":return null;case"Cycle":return this.renderCycleSync(B,K);case"Firstof":return this.renderFirstofSync(B,K);case"Ifchanged":return this.renderIfchangedSync(B,K);case"Regroup":return this.renderRegroupSync(B,K);case"Widthratio":return this.renderWidthratioSync(B,K);case"Lorem":return this.renderLoremSync(B,K);case"CsrfToken":return this.renderCsrfTokenSync();case"Debug":return this.renderDebugSync(K);case"Templatetag":return this.renderTemplatetagSync(B);default:return null}}renderIfSync(B,K){if(this.isTruthy(this.eval(B.test,K)))return this.renderNodesSync(B.body,K);for(let A of B.elifs)if(this.isTruthy(this.eval(A.test,K)))return this.renderNodesSync(A.body,K);return B.else_.length>0?this.renderNodesSync(B.else_,K):""}renderForSync(B,K){let A=this.eval(B.iter,K),$=this.toIterable(A),Q=$.length;if(Q===0)return this.renderNodesSync(B.else_,K);K.push(),K.pushForLoop($,0);let O;if(Array.isArray(B.target)){let U=B.target,Y=U.length;if(Q<50){O="";for(let Z=0;Z<Q;Z++){let J=$[Z];if(Z>0)K.updateForLoop(Z,$);let X;if(Array.isArray(J))X=J;else if(J&&typeof J==="object"&&(("0"in J)||("key"in J)))X=[J[0]??J.key,J[1]??J.value];else X=[J,J];for(let M=0;M<Y;M++)K.set(U[M],X[M]);O+=this.renderNodesSync(B.body,K)}}else{let Z=Array(Q);for(let J=0;J<Q;J++){let X=$[J];if(J>0)K.updateForLoop(J,$);let M;if(Array.isArray(X))M=X;else if(X&&typeof X==="object"&&(("0"in X)||("key"in X)))M=[X[0]??X.key,X[1]??X.value];else M=[X,X];for(let G=0;G<Y;G++)K.set(U[G],M[G]);Z[J]=this.renderNodesSync(B.body,K)}O=Z.join("")}}else{let U=B.target;if(Q<50){O="";for(let Y=0;Y<Q;Y++){if(Y>0)K.updateForLoop(Y,$);K.set(U,$[Y]),O+=this.renderNodesSync(B.body,K)}}else{let Y=Array(Q);for(let Z=0;Z<Q;Z++){if(Z>0)K.updateForLoop(Z,$);K.set(U,$[Z]),Y[Z]=this.renderNodesSync(B.body,K)}O=Y.join("")}}return K.popForLoop(),K.pop(),O}renderBlockSync(B,K){let A=this.blocks.get(B.name)||B;K.push();let $=this.renderNodesSync(B.body,K),Q=new String($);Q.__safe__=!0,K.set("block",{super:Q});let O=this.renderNodesSync(A.body,K);return K.pop(),O}renderWithSync(B,K){K.push();for(let{target:$,value:Q}of B.assignments)K.set($,this.eval(Q,K));let A=this.renderNodesSync(B.body,K);return K.pop(),A}renderUrlSync(B,K){let A=this.eval(B.name,K),$=[];for(let U=0;U<B.args.length;U++)$.push(this.eval(B.args[U],K));let Q=this.evalObjectSync(B.kwargs,K),O=this.options.urlResolver(String(A),$,Q);if(B.asVar)return K.set(B.asVar,O),"";return O}renderStaticSync(B,K){let A=this.eval(B.path,K),$=this.options.staticResolver(String(A));if(B.asVar)return K.set(B.asVar,$),"";return $}renderNowSync(B,K){let A=String(this.eval(B.format,K)),$=this.formatDate(new Date,A);if(B.asVar)return K.set(B.asVar,$),"";return $}cycleState=new Map;renderCycleSync(B,K){let A=`cycle_${B.line}_${B.column}`,$=this.cycleState.get(A)??0,Q=[];for(let U=0;U<B.values.length;U++)Q.push(this.eval(B.values[U],K));let O=Q[$%Q.length];if(this.cycleState.set(A,$+1),B.asVar)return K.set(B.asVar,O),B.silent?"":this.stringify(O);return this.stringify(O)}renderFirstofSync(B,K){for(let $ of B.values){let Q=this.eval($,K);if(this.isTruthy(Q)){if(B.asVar)return K.set(B.asVar,Q),"";return this.stringify(Q)}}let A=B.fallback?this.eval(B.fallback,K):"";if(B.asVar)return K.set(B.asVar,A),"";return this.stringify(A)}ifchangedState=new Map;renderIfchangedSync(B,K){let A=`ifchanged_${B.line}_${B.column}`,$;if(B.values.length>0){let U=[];for(let Y=0;Y<B.values.length;Y++)U.push(this.eval(B.values[Y],K));$=U}else $=this.renderNodesSync(B.body,K);let Q=this.ifchangedState.get(A),O=!this.deepEqual($,Q);if(this.ifchangedState.set(A,$),O){if(B.values.length>0)return this.renderNodesSync(B.body,K);return $}else return this.renderNodesSync(B.else_,K)}renderRegroupSync(B,K){let A=this.toIterable(this.eval(B.target,K)),$=[],Q=Symbol("initial"),O=[];for(let U of A){let Y=U&&typeof U==="object"?U[B.key]:void 0;if(Y!==Q){if(O.length>0)$.push({grouper:Q,list:O});Q=Y,O=[U]}else O.push(U)}if(O.length>0)$.push({grouper:Q,list:O});return K.set(B.asVar,$),""}renderWidthratioSync(B,K){let A=Number(this.eval(B.value,K)),$=Number(this.eval(B.maxValue,K)),Q=Number(this.eval(B.maxWidth,K)),O=$===0?0:Math.round(A/$*Q);if(B.asVar)return K.set(B.asVar,O),"";return String(O)}renderLoremSync(B,K){let A=B.count?Number(this.eval(B.count,K)):1,$=B.method,Q=["lorem","ipsum","dolor","sit","amet","consectetur","adipiscing","elit","sed","do","eiusmod","tempor","incididunt","ut","labore","et","dolore","magna","aliqua","enim","ad","minim","veniam","quis","nostrud","exercitation","ullamco","laboris","nisi","aliquip","ex","ea","commodo","consequat","duis","aute","irure","in","reprehenderit","voluptate","velit","esse","cillum","fugiat","nulla","pariatur","excepteur","sint","occaecat","cupidatat","non","proident","sunt","culpa","qui","officia","deserunt","mollit","anim","id","est","laborum"],O=(U)=>{if(B.random)return Q[Math.floor(Math.random()*Q.length)];return Q[U%Q.length]};if($==="w"){let U=[];for(let Y=0;Y<A;Y++)U.push(O(Y));return U.join(" ")}else if($==="p"||$==="b"){let U=[];for(let Y=0;Y<A;Y++){let Z=3+Y%3,J=[];for(let X=0;X<Z;X++){let M=8+X%7,G=[];for(let R=0;R<M;R++)G.push(O(Y*100+X*20+R));G[0]=G[0].charAt(0).toUpperCase()+G[0].slice(1),J.push(G.join(" ")+".")}U.push(J.join(" "))}if($==="b")return U.join(`
22
+ ${K($[O+1],Z+1)}${U}</ul>
23
+ ${U}`,O++;Y+=`</li>
24
+ `}}return Y},A=K(B),Q=new String(A);return Q.__safe__=!0,Q},lK=(B)=>{let K=String(B).replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(/"/g,"\\\""),A=new String(K);return A.__safe__=!0,A},oK=(B,K)=>{let A=parseInt(String(B),10);if(isNaN(A))return B;let Q=String(Math.abs(A)),$=Number(K)||1;if($<1||$>Q.length)return B;return parseInt(Q[Q.length-$],10)},aK=(B)=>{return String(B).replace(/ /g,"%20").replace(/"/g,"%22").replace(/</g,"%3C").replace(/>/g,"%3E").replace(/\\/g,"%5C").replace(/\^/g,"%5E").replace(/`/g,"%60").replace(/\{/g,"%7B").replace(/\|/g,"%7C").replace(/\}/g,"%7D")},tK=(B,K)=>{let A=JSON.stringify(B).replace(/</g,"\\u003C").replace(/>/g,"\\u003E").replace(/&/g,"\\u0026"),$=`<script${K?` id="${String(K)}"`:""} type="application/json">${A}</script>`,Z=new String($);return Z.__safe__=!0,Z},eK=(B)=>{if(!Array.isArray(B))return B;return B.map((K)=>{let A=new String(K);return A.__safe__=!0,A})},BA=(B,K)=>{let A=String(K),Q=B;if(A==="s")return String(Q);if(A==="d"||A==="i")return String(parseInt(String(Q),10)||0);if(A==="f")return String(parseFloat(String(Q))||0);if(A==="x")return(parseInt(String(Q),10)||0).toString(16);if(A==="X")return(parseInt(String(Q),10)||0).toString(16).toUpperCase();if(A==="o")return(parseInt(String(Q),10)||0).toString(8);if(A==="b")return(parseInt(String(Q),10)||0).toString(2);if(A==="e")return(parseFloat(String(Q))||0).toExponential();let $=A.match(/^\.?(\d+)f$/);if($){let U=parseInt($[1],10);return(parseFloat(String(Q))||0).toFixed(U)}let Z=A.match(/^(\d+)([sd])$/);if(Z){let U=parseInt(Z[1],10),Y=Z[2];return(Y==="d"?String(parseInt(String(Q),10)||0):String(Q)).padStart(U,Y==="d"?"0":" ")}return String(Q)},KA=(B,K=30)=>{let A=String(B),Q=Number(K),$="",Z=0,U=!1,Y=[];for(let J=0;J<A.length&&Z<Q;J++){let X=A[J];if(X==="<"){U=!0;let M=A.slice(J).match(/^<\/(\w+)/),G=A.slice(J).match(/^<(\w+)/);if(M){let R=M[1].toLowerCase(),F=Y.lastIndexOf(R);if(F!==-1)Y.splice(F,1)}else if(G&&!A.slice(J).match(/^<\w+[^>]*\/>/))Y.push(G[1].toLowerCase())}if($+=X,X===">")U=!1;else if(!U)Z++}if(Z>=Q&&A.length>$.length)$+="...";for(let J=Y.length-1;J>=0;J--)$+=`</${Y[J]}>`;let O=new String($);return O.__safe__=!0,O},AA=(B,K=15)=>{let A=String(B),Q=Number(K),$="",Z=0,U=!1,Y=!1,O=[];for(let X=0;X<A.length&&Z<Q;X++){let M=A[X];if(M==="<"){U=!0;let G=A.slice(X).match(/^<\/(\w+)/),R=A.slice(X).match(/^<(\w+)/);if(G){let F=G[1].toLowerCase(),W=O.lastIndexOf(F);if(W!==-1)O.splice(W,1)}else if(R&&!A.slice(X).match(/^<\w+[^>]*\/>/))O.push(R[1].toLowerCase())}if($+=M,M===">")U=!1;else if(!U){let G=/\s/.test(M);if(!G&&!Y)Y=!0;else if(G&&Y)Y=!1,Z++}}if(Y)Z++;if(Z>=Q)$=$.trimEnd()+"...";for(let X=O.length-1;X>=0;X--)$+=`</${O[X]}>`;let J=new String($);return J.__safe__=!0,J},$A=(B,K=15)=>{let A=Number(K),Q=String(B).replace(t,(Z)=>{let U=Z.length>A?Z.slice(0,A)+"...":Z;return`<a href="${Z}">${U}</a>`}),$=new String(Q);return $.__safe__=!0,$},QA=(B)=>{if(B==null||typeof B!=="object")return[];return Object.entries(B)},OA=(B,K=!0)=>{if(B==null||typeof B!=="object")return"";let A=[];for(let[U,Y]of Object.entries(B))if(Y===!0)A.push(U);else if(Y!==!1&&Y!=null){let O=Bun.escapeHTML(String(Y));A.push(`${U}="${O}"`)}let Q=A.join(" "),$=K&&Q?" "+Q:Q,Z=new String($);return Z.__safe__=!0,Z},h={upper:fB,lower:kB,capitalize:yB,capfirst:TB,title:gB,trim:xB,striptags:mB,escape:l,e:l,safe:pB,escapejs:cB,linebreaks:vB,linebreaksbr:iB,truncatechars:dB,truncatewords:sB,wordcount:uB,center:rB,ljust:nB,rjust:lB,cut:oB,slugify:aB,abs:tB,round:eB,int:BK,float:KK,floatformat:AK,add:$K,divisibleby:QK,filesizeformat:OK,length:KB,length_is:ZK,first:JK,last:YK,join:UK,slice:XK,reverse:MK,sort:GK,unique:FK,make_list:IK,dictsort:AB,dictsortreversed:RK,columns:HK,date:$B,time:EK,timesince:WK,timeuntil:PK,default:o,d:o,default_if_none:DK,yesno:_K,pluralize:LK,urlencode:jK,urlize:qK,json:a,tojson:a,random:CK,batch:NK,groupby:SK,wordwrap:wK,indent:VK,replace:bK,format:hK,string:fK,list:kK,map:yK,select:TK,reject:gK,selectattr:QB,rejectattr:xK,attr:mK,max:pK,min:cK,sum:vK,pprint:iK,forceescape:dK,phone2numeric:uK,linenumbers:rK,unordered_list:nK,addslashes:lK,get_digit:oK,iriencode:aK,json_script:tK,safeseq:eK,stringformat:BA,truncatechars_html:KA,truncatewords_html:AA,urlizetrunc:$A,items:QA,xmlattr:OA};var ZA=(B,K)=>{let A=Number(B),Q=Number(K);if(Q===0)return!1;return A%Q===0},JA=(B)=>{let K=Number(B);return Number.isInteger(K)&&K%2===0},YA=(B)=>{let K=Number(B);return Number.isInteger(K)&&K%2!==0},UA=(B)=>{return typeof B==="number"&&!isNaN(B)},XA=(B)=>{return Number.isInteger(B)},MA=(B)=>{return typeof B==="number"&&!Number.isInteger(B)&&!isNaN(B)},ZB=(B,K)=>Number(B)>Number(K),GA=(B,K)=>Number(B)>=Number(K),JB=(B,K)=>Number(B)<Number(K),FA=(B,K)=>Number(B)<=Number(K),IA=ZB,RA=JB,HA=(B)=>{return B!==c},c=(B)=>{return B===c},OB=(B)=>{return B===null},zA=(B)=>{return typeof B==="boolean"},EA=(B)=>{return typeof B==="string"},WA=(B)=>{return B!==null&&typeof B==="object"&&!Array.isArray(B)&&!(B instanceof Date)},PA=(B)=>{if(B==null)return!1;return typeof B==="string"||Array.isArray(B)||typeof B[Symbol.iterator]==="function"},DA=(B)=>{return Array.isArray(B)||typeof B==="string"},_A=(B)=>{return typeof B==="function"},LA=(B)=>{if(typeof B!=="string")return!1;return B===B.toLowerCase()&&B!==B.toUpperCase()},jA=(B)=>{if(typeof B!=="string")return!1;return B===B.toUpperCase()&&B!==B.toLowerCase()},qA=(B)=>{if(B==null)return!0;if(typeof B==="string"||Array.isArray(B))return B.length===0;if(typeof B==="object"){for(let K in B)return!1;return!0}return!1},CA=(B,K)=>{if(Array.isArray(K))return K.includes(B);if(typeof K==="string")return K.includes(String(B));if(typeof K==="object"&&K!==null)return B in K;return!1},YB=(B,K)=>B===K,NA=(B,K)=>B!==K,SA=(B,K)=>B===K,wA=YB,UB=(B)=>{if(B==null)return!1;if(typeof B==="boolean")return B;if(typeof B==="number")return B!==0;if(typeof B==="string")return B.length>0;if(Array.isArray(B))return B.length>0;if(typeof B==="object"){for(let K in B)return!0;return!1}return!0},VA=(B)=>!UB(B),bA=(B)=>B===!0,hA=(B)=>B===!1,f={divisibleby:ZA,even:JA,odd:YA,number:UA,integer:XA,float:MA,gt:ZB,ge:GA,lt:JB,le:FA,greaterthan:IA,lessthan:RA,defined:HA,undefined:c,none:OB,None:OB,boolean:zA,string:EA,mapping:WA,iterable:PA,sequence:DA,callable:_A,lower:LA,upper:jA,empty:qA,in:CA,eq:YB,ne:NA,sameas:SA,equalto:wA,truthy:UB,falsy:VA,true:bA,false:hA};class z{options;filters;tests;blocks=new Map;parentTemplate=null;source;constructor(B={}){if(this.options={autoescape:B.autoescape??!0,filters:B.filters??{},tests:B.tests??{},globals:B.globals??{},urlResolver:B.urlResolver??((K)=>`#${K}`),staticResolver:B.staticResolver??((K)=>`/static/${K}`),templateLoader:B.templateLoader??(async()=>{throw Error("Template loader not configured")}),timezone:B.timezone??void 0},this.filters={...h,...this.options.filters},this.options.timezone){let K=this.options.timezone;this.filters.date=(A,Q="N j, Y")=>{let $=A instanceof Date?A:new Date(A);if(isNaN($.getTime()))return"";return this.formatDate($,Q)},this.filters.time=(A,Q="H:i")=>{return this.filters.date(A,Q)}}this.tests={...f,...this.options.tests}}async render(B,K={}){let A=new w({...this.options.globals,...K});if(this.blocks.clear(),this.parentTemplate=null,this.templateNeedsAsync(B)){if(await this.collectBlocks(B,A),this.parentTemplate)return this.renderTemplateAsync(this.parentTemplate,A);return this.renderTemplateAsync(B,A)}return this.collectBlocksSync(B),this.renderTemplateSync(B,A)}templateNeedsAsync(B){for(let K of B.body){if(K.type==="Extends"||K.type==="Include")return!0;if(K.type==="If"){let A=K;if(this.nodesNeedAsync(A.body))return!0;for(let Q of A.elifs)if(this.nodesNeedAsync(Q.body))return!0;if(this.nodesNeedAsync(A.else_))return!0}if(K.type==="For"){let A=K;if(this.nodesNeedAsync(A.body))return!0;if(this.nodesNeedAsync(A.else_))return!0}if(K.type==="Block"){if(this.nodesNeedAsync(K.body))return!0}if(K.type==="With"){if(this.nodesNeedAsync(K.body))return!0}}return!1}nodesNeedAsync(B){for(let K of B){if(K.type==="Extends"||K.type==="Include")return!0;if(K.type==="If"){let A=K;if(this.nodesNeedAsync(A.body))return!0;for(let Q of A.elifs)if(this.nodesNeedAsync(Q.body))return!0;if(this.nodesNeedAsync(A.else_))return!0}if(K.type==="For"){let A=K;if(this.nodesNeedAsync(A.body))return!0;if(this.nodesNeedAsync(A.else_))return!0}if(K.type==="Block"){if(this.nodesNeedAsync(K.body))return!0}if(K.type==="With"){if(this.nodesNeedAsync(K.body))return!0}}return!1}collectBlocksSync(B){for(let K of B.body)if(K.type==="Block")this.blocks.set(K.name,K)}renderTemplateSync(B,K){let A=[];for(let Q of B.body){let $=this.renderNodeSync(Q,K);if($!==null)A.push($)}return A.join("")}renderNodeSync(B,K){if(B.type==="Text")return B.value;if(B.type==="Output")return this.stringify(this.eval(B.expression,K));switch(B.type){case"If":return this.renderIfSync(B,K);case"For":return this.renderForSync(B,K);case"Block":return this.renderBlockSync(B,K);case"Set":return K.set(B.target,this.eval(B.value,K)),"";case"With":return this.renderWithSync(B,K);case"Url":return this.renderUrlSync(B,K);case"Static":return this.renderStaticSync(B,K);case"Now":return this.renderNowSync(B,K);case"Load":case"Extends":return null;case"Cycle":return this.renderCycleSync(B,K);case"Firstof":return this.renderFirstofSync(B,K);case"Ifchanged":return this.renderIfchangedSync(B,K);case"Regroup":return this.renderRegroupSync(B,K);case"Widthratio":return this.renderWidthratioSync(B,K);case"Lorem":return this.renderLoremSync(B,K);case"CsrfToken":return this.renderCsrfTokenSync();case"Debug":return this.renderDebugSync(K);case"Templatetag":return this.renderTemplatetagSync(B);default:return null}}renderIfSync(B,K){if(this.isTruthy(this.eval(B.test,K)))return this.renderNodesSync(B.body,K);for(let A of B.elifs)if(this.isTruthy(this.eval(A.test,K)))return this.renderNodesSync(A.body,K);return B.else_.length>0?this.renderNodesSync(B.else_,K):""}renderForSync(B,K){let A=this.eval(B.iter,K),Q=this.toIterable(A),$=Q.length;if($===0)return this.renderNodesSync(B.else_,K);K.push(),K.pushForLoop(Q,0);let Z;if(Array.isArray(B.target)){let U=B.target,Y=U.length;if($<25){Z="";for(let O=0;O<$;O++){let J=Q[O];if(O>0)K.updateForLoop(O,Q);let X=Array.isArray(J)?J:[J,J];for(let M=0;M<Y;M++)K.set(U[M],X[M]);Z+=this.renderNodesSync(B.body,K)}}else{let O=Array($);for(let J=0;J<$;J++){let X=Q[J];if(J>0)K.updateForLoop(J,Q);let M=Array.isArray(X)?X:[X,X];for(let G=0;G<Y;G++)K.set(U[G],M[G]);O[J]=this.renderNodesSync(B.body,K)}Z=O.join("")}}else{let U=B.target;if($<25){Z="";for(let Y=0;Y<$;Y++){if(Y>0)K.updateForLoop(Y,Q);K.set(U,Q[Y]),Z+=this.renderNodesSync(B.body,K)}}else{let Y=Array($);for(let O=0;O<$;O++){if(O>0)K.updateForLoop(O,Q);K.set(U,Q[O]),Y[O]=this.renderNodesSync(B.body,K)}Z=Y.join("")}}return K.popForLoop(),K.pop(),Z}renderBlockSync(B,K){let A=this.blocks.get(B.name)||B;K.push();let Q=this.renderNodesSync(B.body,K),$=new String(Q);$.__safe__=!0,K.set("block",{super:$});let Z=this.renderNodesSync(A.body,K);return K.pop(),Z}renderWithSync(B,K){K.push();for(let{target:Q,value:$}of B.assignments)K.set(Q,this.eval($,K));let A=this.renderNodesSync(B.body,K);return K.pop(),A}renderUrlSync(B,K){let A=this.eval(B.name,K),Q=[];for(let U=0;U<B.args.length;U++)Q.push(this.eval(B.args[U],K));let $=this.evalObjectSync(B.kwargs,K),Z=this.options.urlResolver(String(A),Q,$);if(B.asVar)return K.set(B.asVar,Z),"";return Z}renderStaticSync(B,K){let A=this.eval(B.path,K),Q=this.options.staticResolver(String(A));if(B.asVar)return K.set(B.asVar,Q),"";return Q}renderNowSync(B,K){let A=String(this.eval(B.format,K)),Q=this.formatDate(new Date,A);if(B.asVar)return K.set(B.asVar,Q),"";return Q}cycleState=new Map;renderCycleSync(B,K){let A=`cycle_${B.line}_${B.column}`,Q=this.cycleState.get(A)??0,$=[];for(let U=0;U<B.values.length;U++)$.push(this.eval(B.values[U],K));let Z=$[Q%$.length];if(this.cycleState.set(A,Q+1),B.asVar)return K.set(B.asVar,Z),B.silent?"":this.stringify(Z);return this.stringify(Z)}renderFirstofSync(B,K){for(let Q of B.values){let $=this.eval(Q,K);if(this.isTruthy($)){if(B.asVar)return K.set(B.asVar,$),"";return this.stringify($)}}let A=B.fallback?this.eval(B.fallback,K):"";if(B.asVar)return K.set(B.asVar,A),"";return this.stringify(A)}ifchangedState=new Map;renderIfchangedSync(B,K){let A=`ifchanged_${B.line}_${B.column}`,Q;if(B.values.length>0){let U=[];for(let Y=0;Y<B.values.length;Y++)U.push(this.eval(B.values[Y],K));Q=U}else Q=this.renderNodesSync(B.body,K);let $=this.ifchangedState.get(A),Z=!this.deepEqual(Q,$);if(this.ifchangedState.set(A,Q),Z){if(B.values.length>0)return this.renderNodesSync(B.body,K);return Q}else return this.renderNodesSync(B.else_,K)}renderRegroupSync(B,K){let A=this.toIterable(this.eval(B.target,K)),Q=[],$=Symbol("initial"),Z=[];for(let U of A){let Y=U&&typeof U==="object"?U[B.key]:void 0;if(Y!==$){if(Z.length>0)Q.push({grouper:$,list:Z});$=Y,Z=[U]}else Z.push(U)}if(Z.length>0)Q.push({grouper:$,list:Z});return K.set(B.asVar,Q),""}renderWidthratioSync(B,K){let A=Number(this.eval(B.value,K)),Q=Number(this.eval(B.maxValue,K)),$=Number(this.eval(B.maxWidth,K)),Z=Q===0?0:Math.round(A/Q*$);if(B.asVar)return K.set(B.asVar,Z),"";return String(Z)}renderLoremSync(B,K){let A=B.count?Number(this.eval(B.count,K)):1,Q=B.method,$=["lorem","ipsum","dolor","sit","amet","consectetur","adipiscing","elit","sed","do","eiusmod","tempor","incididunt","ut","labore","et","dolore","magna","aliqua","enim","ad","minim","veniam","quis","nostrud","exercitation","ullamco","laboris","nisi","aliquip","ex","ea","commodo","consequat","duis","aute","irure","in","reprehenderit","voluptate","velit","esse","cillum","fugiat","nulla","pariatur","excepteur","sint","occaecat","cupidatat","non","proident","sunt","culpa","qui","officia","deserunt","mollit","anim","id","est","laborum"],Z=(U)=>{if(B.random)return $[Math.floor(Math.random()*$.length)];return $[U%$.length]};if(Q==="w"){let U=[];for(let Y=0;Y<A;Y++)U.push(Z(Y));return U.join(" ")}else if(Q==="p"||Q==="b"){let U=[];for(let Y=0;Y<A;Y++){let O=3+Y%3,J=[];for(let X=0;X<O;X++){let M=8+X%7,G=[];for(let R=0;R<M;R++)G.push(Z(Y*100+X*20+R));G[0]=G[0].charAt(0).toUpperCase()+G[0].slice(1),J.push(G.join(" ")+".")}U.push(J.join(" "))}if(Q==="b")return U.join(`
25
25
 
26
26
  `);return U.map((Y)=>`<p>${Y}</p>`).join(`
27
- `)}return""}renderCsrfTokenSync(){return'<input type="hidden" name="csrfmiddlewaretoken" value="CSRF_TOKEN_PLACEHOLDER">'}renderDebugSync(B){let K=B.toObject?.()||{};return`<pre>${JSON.stringify(K,null,2)}</pre>`}renderTemplatetagSync(B){return{openblock:"{%",closeblock:"%}",openvariable:"{{",closevariable:"}}",openbrace:"{",closebrace:"}",opencomment:"{#",closecomment:"#}"}[B.tagType]||""}getDateInTimezone(B,K){if(!K)return{year:B.getFullYear(),month:B.getMonth(),day:B.getDate(),weekday:B.getDay(),hours:B.getHours(),minutes:B.getMinutes(),seconds:B.getSeconds()};let $=new Intl.DateTimeFormat("en-US",{timeZone:K,year:"numeric",month:"2-digit",day:"2-digit",weekday:"short",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(B),Q=(U)=>$.find((Y)=>Y.type===U)?.value||"",O={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:parseInt(Q("year"),10),month:parseInt(Q("month"),10)-1,day:parseInt(Q("day"),10),weekday:O[Q("weekday")]??0,hours:parseInt(Q("hour"),10),minutes:parseInt(Q("minute"),10),seconds:parseInt(Q("second"),10)}}formatDate(B,K){let A=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],$=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Q=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],O=["January","February","March","April","May","June","July","August","September","October","November","December"],U=this.options.timezone,{year:Y,month:Z,day:J,weekday:X,hours:M,minutes:G,seconds:R}=this.getDateInTimezone(B,U),F="";for(let W=0;W<K.length;W++){let j=K[W];switch(j){case"d":F+=String(J).padStart(2,"0");break;case"j":F+=String(J);break;case"D":F+=A[X];break;case"l":F+=$[X];break;case"m":F+=String(Z+1).padStart(2,"0");break;case"n":F+=String(Z+1);break;case"M":F+=Q[Z];break;case"F":F+=O[Z];break;case"y":F+=String(Y).slice(-2);break;case"Y":F+=String(Y);break;case"H":F+=String(M).padStart(2,"0");break;case"G":F+=String(M);break;case"i":F+=String(G).padStart(2,"0");break;case"s":F+=String(R).padStart(2,"0");break;case"a":F+=M<12?"a.m.":"p.m.";break;case"A":F+=M<12?"AM":"PM";break;case"g":F+=String(M%12||12);break;case"h":F+=String(M%12||12).padStart(2,"0");break;default:F+=j}}return F}renderNodesSync(B,K){let A=B.length;if(A===0)return"";if(A===1)return this.renderNodeSync(B[0],K)??"";if(A===2){let Q=this.renderNodeSync(B[0],K)??"",O=this.renderNodeSync(B[1],K)??"";return Q+O}let $=[];for(let Q=0;Q<A;Q++){let O=this.renderNodeSync(B[Q],K);if(O!==null)$.push(O)}return $.join("")}eval(B,K){if(B.type==="Literal")return B.value;if(B.type==="Name")return K.get(B.name);if(B.type==="GetAttr")return this.evalGetAttr(B,K);switch(B.type){case"GetItem":return this.evalGetItem(B,K);case"FilterExpr":return this.evalFilter(B,K);case"BinaryOp":return this.evalBinaryOp(B,K);case"UnaryOp":return this.evalUnaryOp(B,K);case"Compare":return this.evalCompare(B,K);case"Conditional":return this.evalConditional(B,K);case"Array":{let A=B.elements,$=[];for(let Q=0;Q<A.length;Q++)$.push(this.eval(A[Q],K));return $}case"Object":return this.evalObjectLiteral(B,K);case"FunctionCall":return this.evalFunctionCall(B,K);case"TestExpr":return this.evalTest(B,K);default:return}}evalGetAttr(B,K){let A=this.eval(B.object,K);if(A==null)return;let $=B.attribute,Q=A[$];if(Q===void 0){if(Array.isArray(A)){let O=parseInt($,10);if(!isNaN(O))return A[O]}return}if(typeof Q==="function")return Q.bind(A);return Q}evalGetItem(B,K){let A=this.eval(B.object,K),$=this.eval(B.index,K);if(A==null)return;return A[$]}static TITLE_REGEX=/\b\w/g;static STRIPTAGS_REGEX=/<[^>]*>/g;static SLUGIFY_REGEX1=/[^\w\s-]/g;static SLUGIFY_REGEX2=/[\s_-]+/g;static SLUGIFY_REGEX3=/^-+|-+$/g;static WHITESPACE_REGEX=/\s+/;static URLIZE_REGEX=/(https?:\/\/[^\s]+)/g;static NEWLINE_REGEX=/\n/g;static DOUBLE_NEWLINE_REGEX=/\n\n+/;evalFilter(B,K){let A=this.eval(B.node,K),$=B.filter,Q=B.args.length;if(Q===0)switch($){case"upper":return String(A??"").toUpperCase();case"lower":return String(A??"").toLowerCase();case"trim":return String(A??"").trim();case"capitalize":{let Z=String(A??"");return Z.charAt(0).toUpperCase()+Z.slice(1).toLowerCase()}case"capfirst":{let Z=String(A??"");return Z.charAt(0).toUpperCase()+Z.slice(1)}case"title":return String(A??"").replace(z.TITLE_REGEX,(Z)=>Z.toUpperCase());case"striptags":return String(A??"").replace(z.STRIPTAGS_REGEX,"");case"slugify":return String(A??"").toLowerCase().replace(z.SLUGIFY_REGEX1,"").replace(z.SLUGIFY_REGEX2,"-").replace(z.SLUGIFY_REGEX3,"");case"wordcount":{let Z=String(A??"").trim();return Z?Z.split(z.WHITESPACE_REGEX).length:0}case"escapejs":return JSON.stringify(String(A??"")).slice(1,-1);case"linebreaksbr":{let Z=String(A??"").replace(z.NEWLINE_REGEX,"<br>"),J=new String(Z);return J.__safe__=!0,J}case"linebreaks":{let Z=String(A??"").split(z.DOUBLE_NEWLINE_REGEX),J="";for(let M=0;M<Z.length;M++){if(M>0)J+=`
28
- `;J+=`<p>${Z[M].replace(z.NEWLINE_REGEX,"<br>")}</p>`}let X=new String(J);return X.__safe__=!0,X}case"urlencode":return encodeURIComponent(String(A??""));case"safe":{let Z=new String(A??"");return Z.__safe__=!0,Z}case"escape":case"e":{if(A?.__safe__)return A;let Z=new String(Bun.escapeHTML(String(A??"")));return Z.__safe__=!0,Z}case"forceescape":{let Z=new String(Bun.escapeHTML(String(A??"")));return Z.__safe__=!0,Z}case"int":return parseInt(String(A),10)||0;case"float":return parseFloat(String(A))||0;case"abs":return Math.abs(Number(A)||0);case"filesizeformat":{let Z=Number(A)||0,J=["bytes","KB","MB","GB","TB","PB"],X=0,M=Z;while(M>=1024&&X<J.length-1)M/=1024,X++;return`${M.toFixed(1)} ${J[X]}`}case"length":if(A==null)return 0;if(typeof A==="string"||Array.isArray(A))return A.length;if(typeof A==="object"){let Z=0;for(let J in A)Z++;return Z}return 0;case"first":if(Array.isArray(A))return A[0];if(typeof A==="string")return A[0];return A;case"last":if(Array.isArray(A))return A[A.length-1];if(typeof A==="string")return A[A.length-1];return A;case"reverse":if(Array.isArray(A))return[...A].reverse();if(typeof A==="string")return A.split("").reverse().join("");return A;case"sort":if(Array.isArray(A))return[...A].sort();return A;case"unique":if(Array.isArray(A))return[...new Set(A)];return A;case"list":case"make_list":if(Array.isArray(A))return A;if(typeof A==="string")return A.split("");if(A&&typeof A[Symbol.iterator]==="function")return[...A];if(typeof A==="object"&&A!==null)return Object.values(A);return[A];case"random":if(Array.isArray(A))return A[Math.floor(Math.random()*A.length)];return A;case"items":if(A==null||typeof A!=="object")return[];return Object.entries(A);case"string":return String(A??"");case"json":case"tojson":try{let Z=new String(JSON.stringify(A));return Z.__safe__=!0,Z}catch{return""}case"pprint":try{let Z=new String(JSON.stringify(A,null,2));return Z.__safe__=!0,Z}catch{return String(A)}case"urlize":{let Z=String(A??"").replace(z.URLIZE_REGEX,'<a href="$1">$1</a>'),J=new String(Z);return J.__safe__=!0,J}}if(Q===1){let Z=this.eval(B.args[0],K);switch($){case"default":case"d":if(A===void 0||A===null||A===""||A===!1)return Z;return A;case"default_if_none":return A===null||A===void 0?Z:A;case"truncatechars":{let J=String(A??""),X=Number(Z)||30;if(J.length<=X)return J;return J.slice(0,X-3)+"..."}case"truncatewords":{let J=String(A??"").split(z.WHITESPACE_REGEX),X=Number(Z)||15;if(J.length<=X)return A;return J.slice(0,X).join(" ")+"..."}case"center":{let J=String(A??""),X=Number(Z)||80,M=Math.max(0,X-J.length),G=Math.floor(M/2);return" ".repeat(G)+J+" ".repeat(M-G)}case"ljust":return String(A??"").padEnd(Number(Z)||80);case"rjust":return String(A??"").padStart(Number(Z)||80);case"cut":return String(A??"").split(String(Z)).join("");case"add":{let J=Number(A),X=Number(Z);if(!isNaN(J)&&!isNaN(X))return J+X;return String(A)+String(Z)}case"divisibleby":return Number(A)%Number(Z)===0;case"round":return Number(Number(A).toFixed(Number(Z)||0));case"floatformat":{let J=parseFloat(String(A));if(isNaN(J))return"";let X=Number(Z);if(X===-1){let M=J.toFixed(1);return M.endsWith(".0")?Math.round(J).toString():M}return J.toFixed(Math.abs(X))}case"get_digit":{let J=parseInt(String(A),10);if(isNaN(J))return A;let X=String(Math.abs(J)),M=Number(Z)||1;if(M<1||M>X.length)return A;return parseInt(X[X.length-M],10)}case"join":if(Array.isArray(A))return A.join(String(Z??""));return String(A);case"slice":{if(!A)return A;let[J,X]=String(Z).split(":"),M=J?parseInt(J,10):0,G=X?parseInt(X,10):void 0;if(Array.isArray(A)||typeof A==="string")return A.slice(M,G);return A}case"batch":{if(!Array.isArray(A))return[[A]];let J=Number(Z)||1,X=[];for(let M=0;M<A.length;M+=J)X.push(A.slice(M,M+J));return X}case"columns":{if(!Array.isArray(A))return[[A]];let J=Number(Z)||2,X=[];for(let M=0;M<A.length;M+=J)X.push(A.slice(M,M+J));return X}case"length_is":return(A==null?0:A.length??Object.keys(A).length??0)===Number(Z);case"attr":return A==null?void 0:A[Z];case"dictsort":if(!Array.isArray(A))return A;return[...A].sort((J,X)=>{let M=Z?J[Z]:J,G=Z?X[Z]:X;return M<G?-1:M>G?1:0});case"dictsortreversed":if(!Array.isArray(A))return A;return[...A].sort((J,X)=>{let M=Z?J[Z]:J,G=Z?X[Z]:X;return M>G?-1:M<G?1:0});case"map":if(!Array.isArray(A))return[];if(typeof Z==="string")return A.map((J)=>J?.[Z]);return A;case"select":if(!Array.isArray(A))return[];if(Z===void 0)return A.filter((J)=>!!J);return A.filter((J)=>!!J?.[Z]);case"reject":if(!Array.isArray(A))return[];if(Z===void 0)return A.filter((J)=>!J);return A.filter((J)=>!J?.[Z]);case"groupby":{if(!Array.isArray(A))return[];let J={};for(let M of A){let G=String(Z?M[Z]:M);if(!(G in J))J[G]=[];J[G].push(M)}let X=[];for(let M in J)X.push({grouper:M,list:J[M]});return X}case"date":case"time":{let J=A instanceof Date?A:new Date(A);if(isNaN(J.getTime()))return"";return this.formatDate(J,String(Z||($==="time"?"H:i":"N j, Y")))}case"pluralize":{let J=String(Z??"s"),[X,M]=J.includes(",")?J.split(","):["",J];return Number(A)===1?X:M}case"yesno":{let[J,X,M]=String(Z??"yes,no,maybe").split(",");if(A===!0)return J;if(A===!1)return X;return M??X}case"json":case"tojson":try{let J=new String(JSON.stringify(A,null,Z));return J.__safe__=!0,J}catch{return""}case"urlizetrunc":{let J=Number(Z)||15,X=String(A??"").replace(z.URLIZE_REGEX,(G)=>{let R=G.length>J?G.slice(0,J)+"...":G;return`<a href="${G}">${R}</a>`}),M=new String(X);return M.__safe__=!0,M}case"indent":{let J=String(A??""),X=typeof Z==="string"?Z:" ".repeat(Number(Z)||4),M=J.split(`
27
+ `)}return""}renderCsrfTokenSync(){return'<input type="hidden" name="csrfmiddlewaretoken" value="CSRF_TOKEN_PLACEHOLDER">'}renderDebugSync(B){let K=B.toObject?.()||{};return`<pre>${JSON.stringify(K,null,2)}</pre>`}renderTemplatetagSync(B){return{openblock:"{%",closeblock:"%}",openvariable:"{{",closevariable:"}}",openbrace:"{",closebrace:"}",opencomment:"{#",closecomment:"#}"}[B.tagType]||""}getDateInTimezone(B,K){if(!K)return{year:B.getFullYear(),month:B.getMonth(),day:B.getDate(),weekday:B.getDay(),hours:B.getHours(),minutes:B.getMinutes(),seconds:B.getSeconds()};let Q=new Intl.DateTimeFormat("en-US",{timeZone:K,year:"numeric",month:"2-digit",day:"2-digit",weekday:"short",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(B),$=(U)=>Q.find((Y)=>Y.type===U)?.value||"",Z={Sun:0,Mon:1,Tue:2,Wed:3,Thu:4,Fri:5,Sat:6};return{year:parseInt($("year"),10),month:parseInt($("month"),10)-1,day:parseInt($("day"),10),weekday:Z[$("weekday")]??0,hours:parseInt($("hour"),10),minutes:parseInt($("minute"),10),seconds:parseInt($("second"),10)}}formatDate(B,K){let A=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Q=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],$=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Z=["January","February","March","April","May","June","July","August","September","October","November","December"],U=this.options.timezone,{year:Y,month:O,day:J,weekday:X,hours:M,minutes:G,seconds:R}=this.getDateInTimezone(B,U),F="";for(let W=0;W<K.length;W++){let j=K[W];switch(j){case"d":F+=String(J).padStart(2,"0");break;case"j":F+=String(J);break;case"D":F+=A[X];break;case"l":F+=Q[X];break;case"m":F+=String(O+1).padStart(2,"0");break;case"n":F+=String(O+1);break;case"M":F+=$[O];break;case"F":F+=Z[O];break;case"y":F+=String(Y).slice(-2);break;case"Y":F+=String(Y);break;case"H":F+=String(M).padStart(2,"0");break;case"G":F+=String(M);break;case"i":F+=String(G).padStart(2,"0");break;case"s":F+=String(R).padStart(2,"0");break;case"a":F+=M<12?"a.m.":"p.m.";break;case"A":F+=M<12?"AM":"PM";break;case"g":F+=String(M%12||12);break;case"h":F+=String(M%12||12).padStart(2,"0");break;default:F+=j}}return F}renderNodesSync(B,K){let A=B.length;if(A===0)return"";if(A===1)return this.renderNodeSync(B[0],K)??"";if(A===2){let $=this.renderNodeSync(B[0],K)??"",Z=this.renderNodeSync(B[1],K)??"";return $+Z}let Q=[];for(let $=0;$<A;$++){let Z=this.renderNodeSync(B[$],K);if(Z!==null)Q.push(Z)}return Q.join("")}eval(B,K){if(B.type==="Literal")return B.value;if(B.type==="Name")return K.get(B.name);if(B.type==="GetAttr")return this.evalGetAttr(B,K);switch(B.type){case"GetItem":return this.evalGetItem(B,K);case"FilterExpr":return this.evalFilter(B,K);case"BinaryOp":return this.evalBinaryOp(B,K);case"UnaryOp":return this.evalUnaryOp(B,K);case"Compare":return this.evalCompare(B,K);case"Conditional":return this.evalConditional(B,K);case"Array":{let A=B.elements,Q=[];for(let $=0;$<A.length;$++)Q.push(this.eval(A[$],K));return Q}case"Object":return this.evalObjectLiteral(B,K);case"FunctionCall":return this.evalFunctionCall(B,K);case"TestExpr":return this.evalTest(B,K);default:return}}evalGetAttr(B,K){let A=this.eval(B.object,K);if(A==null)return;let Q=B.attribute,$=A[Q];if($===void 0){if(Array.isArray(A)){let Z=parseInt(Q,10);if(!isNaN(Z))return A[Z]}return}if(typeof $==="function")return $.bind(A);return $}evalGetItem(B,K){let A=this.eval(B.object,K),Q=this.eval(B.index,K);if(A==null)return;return A[Q]}static TITLE_REGEX=/\b\w/g;static STRIPTAGS_REGEX=/<[^>]*>/g;static SLUGIFY_REGEX1=/[^\w\s-]/g;static SLUGIFY_REGEX2=/[\s_-]+/g;static SLUGIFY_REGEX3=/^-+|-+$/g;static WHITESPACE_REGEX=/\s+/;static URLIZE_REGEX=/(https?:\/\/[^\s]+)/g;static NEWLINE_REGEX=/\n/g;static DOUBLE_NEWLINE_REGEX=/\n\n+/;evalFilter(B,K){let A=this.eval(B.node,K),Q=B.filter,$=B.args.length;if($===0)switch(Q){case"upper":return String(A??"").toUpperCase();case"lower":return String(A??"").toLowerCase();case"trim":return String(A??"").trim();case"capitalize":{let O=String(A??"");return O.charAt(0).toUpperCase()+O.slice(1).toLowerCase()}case"capfirst":{let O=String(A??"");return O.charAt(0).toUpperCase()+O.slice(1)}case"title":return String(A??"").replace(z.TITLE_REGEX,(O)=>O.toUpperCase());case"striptags":return String(A??"").replace(z.STRIPTAGS_REGEX,"");case"slugify":return String(A??"").toLowerCase().replace(z.SLUGIFY_REGEX1,"").replace(z.SLUGIFY_REGEX2,"-").replace(z.SLUGIFY_REGEX3,"");case"wordcount":{let O=String(A??"").trim();return O?O.split(z.WHITESPACE_REGEX).length:0}case"escapejs":return JSON.stringify(String(A??"")).slice(1,-1);case"linebreaksbr":{let O=String(A??"").replace(z.NEWLINE_REGEX,"<br>"),J=new String(O);return J.__safe__=!0,J}case"linebreaks":{let O=String(A??"").split(z.DOUBLE_NEWLINE_REGEX),J="";for(let M=0;M<O.length;M++){if(M>0)J+=`
28
+ `;J+=`<p>${O[M].replace(z.NEWLINE_REGEX,"<br>")}</p>`}let X=new String(J);return X.__safe__=!0,X}case"urlencode":return encodeURIComponent(String(A??""));case"safe":{let O=new String(A??"");return O.__safe__=!0,O}case"escape":case"e":{if(A?.__safe__)return A;let O=new String(Bun.escapeHTML(String(A??"")));return O.__safe__=!0,O}case"forceescape":{let O=new String(Bun.escapeHTML(String(A??"")));return O.__safe__=!0,O}case"int":return parseInt(String(A),10)||0;case"float":return parseFloat(String(A))||0;case"abs":return Math.abs(Number(A)||0);case"filesizeformat":{let O=Number(A)||0,J=["bytes","KB","MB","GB","TB","PB"],X=0,M=O;while(M>=1024&&X<J.length-1)M/=1024,X++;return`${M.toFixed(1)} ${J[X]}`}case"length":if(A==null)return 0;if(typeof A==="string"||Array.isArray(A))return A.length;if(typeof A==="object"){let O=0;for(let J in A)O++;return O}return 0;case"first":if(Array.isArray(A))return A[0];if(typeof A==="string")return A[0];return A;case"last":if(Array.isArray(A))return A[A.length-1];if(typeof A==="string")return A[A.length-1];return A;case"reverse":if(Array.isArray(A))return[...A].reverse();if(typeof A==="string")return A.split("").reverse().join("");return A;case"sort":if(Array.isArray(A))return[...A].sort();return A;case"unique":if(Array.isArray(A))return[...new Set(A)];return A;case"list":case"make_list":if(Array.isArray(A))return A;if(typeof A==="string")return A.split("");if(A&&typeof A[Symbol.iterator]==="function")return[...A];if(typeof A==="object"&&A!==null)return Object.values(A);return[A];case"random":if(Array.isArray(A))return A[Math.floor(Math.random()*A.length)];return A;case"items":if(A==null||typeof A!=="object")return[];return Object.entries(A);case"string":return String(A??"");case"json":case"tojson":try{let O=new String(JSON.stringify(A));return O.__safe__=!0,O}catch{return""}case"pprint":try{let O=new String(JSON.stringify(A,null,2));return O.__safe__=!0,O}catch{return String(A)}case"urlize":{let O=String(A??"").replace(z.URLIZE_REGEX,'<a href="$1">$1</a>'),J=new String(O);return J.__safe__=!0,J}}if($===1){let O=this.eval(B.args[0],K);switch(Q){case"default":case"d":if(A===void 0||A===null||A===""||A===!1)return O;return A;case"default_if_none":return A===null||A===void 0?O:A;case"truncatechars":{let J=String(A??""),X=Number(O)||30;if(J.length<=X)return J;return J.slice(0,X-3)+"..."}case"truncatewords":{let J=String(A??"").split(z.WHITESPACE_REGEX),X=Number(O)||15;if(J.length<=X)return A;return J.slice(0,X).join(" ")+"..."}case"center":{let J=String(A??""),X=Number(O)||80,M=Math.max(0,X-J.length),G=Math.floor(M/2);return" ".repeat(G)+J+" ".repeat(M-G)}case"ljust":return String(A??"").padEnd(Number(O)||80);case"rjust":return String(A??"").padStart(Number(O)||80);case"cut":return String(A??"").split(String(O)).join("");case"add":{let J=Number(A),X=Number(O);if(!isNaN(J)&&!isNaN(X))return J+X;return String(A)+String(O)}case"divisibleby":return Number(A)%Number(O)===0;case"round":return Number(Number(A).toFixed(Number(O)||0));case"floatformat":{let J=parseFloat(String(A));if(isNaN(J))return"";let X=Number(O);if(X===-1){let M=J.toFixed(1);return M.endsWith(".0")?Math.round(J).toString():M}return J.toFixed(Math.abs(X))}case"get_digit":{let J=parseInt(String(A),10);if(isNaN(J))return A;let X=String(Math.abs(J)),M=Number(O)||1;if(M<1||M>X.length)return A;return parseInt(X[X.length-M],10)}case"join":if(Array.isArray(A))return A.join(String(O??""));return String(A);case"slice":{if(!A)return A;let[J,X]=String(O).split(":"),M=J?parseInt(J,10):0,G=X?parseInt(X,10):void 0;if(Array.isArray(A)||typeof A==="string")return A.slice(M,G);return A}case"batch":{if(!Array.isArray(A))return[[A]];let J=Number(O)||1,X=[];for(let M=0;M<A.length;M+=J)X.push(A.slice(M,M+J));return X}case"columns":{if(!Array.isArray(A))return[[A]];let J=Number(O)||2,X=[];for(let M=0;M<A.length;M+=J)X.push(A.slice(M,M+J));return X}case"length_is":return(A==null?0:A.length??Object.keys(A).length??0)===Number(O);case"attr":return A==null?void 0:A[O];case"dictsort":if(!Array.isArray(A))return A;return[...A].sort((J,X)=>{let M=O?J[O]:J,G=O?X[O]:X;return M<G?-1:M>G?1:0});case"dictsortreversed":if(!Array.isArray(A))return A;return[...A].sort((J,X)=>{let M=O?J[O]:J,G=O?X[O]:X;return M>G?-1:M<G?1:0});case"map":if(!Array.isArray(A))return[];if(typeof O==="string")return A.map((J)=>J?.[O]);return A;case"select":if(!Array.isArray(A))return[];if(O===void 0)return A.filter((J)=>!!J);return A.filter((J)=>!!J?.[O]);case"reject":if(!Array.isArray(A))return[];if(O===void 0)return A.filter((J)=>!J);return A.filter((J)=>!J?.[O]);case"groupby":{if(!Array.isArray(A))return[];let J={};for(let M of A){let G=String(O?M[O]:M);if(!(G in J))J[G]=[];J[G].push(M)}let X=[];for(let M in J)X.push({grouper:M,list:J[M]});return X}case"date":case"time":{let J=A instanceof Date?A:new Date(A);if(isNaN(J.getTime()))return"";return this.formatDate(J,String(O||(Q==="time"?"H:i":"N j, Y")))}case"pluralize":{let J=String(O??"s"),[X,M]=J.includes(",")?J.split(","):["",J];return Number(A)===1?X:M}case"yesno":{let[J,X,M]=String(O??"yes,no,maybe").split(",");if(A===!0)return J;if(A===!1)return X;return M??X}case"json":case"tojson":try{let J=new String(JSON.stringify(A,null,O));return J.__safe__=!0,J}catch{return""}case"urlizetrunc":{let J=Number(O)||15,X=String(A??"").replace(z.URLIZE_REGEX,(G)=>{let R=G.length>J?G.slice(0,J)+"...":G;return`<a href="${G}">${R}</a>`}),M=new String(X);return M.__safe__=!0,M}case"indent":{let J=String(A??""),X=typeof O==="string"?O:" ".repeat(Number(O)||4),M=J.split(`
29
29
  `),G=M[0];for(let R=1;R<M.length;R++)G+=`
30
- `+(M[R].trim()===""?M[R]:X+M[R]);return G}case"stringformat":{let J=String(Z),X=A;if(J==="s")return String(X);if(J==="d"||J==="i")return String(parseInt(String(X),10)||0);if(J==="f")return String(parseFloat(String(X))||0);if(J==="x")return(parseInt(String(X),10)||0).toString(16);if(J==="X")return(parseInt(String(X),10)||0).toString(16).toUpperCase();if(J==="o")return(parseInt(String(X),10)||0).toString(8);if(J==="b")return(parseInt(String(X),10)||0).toString(2);if(J==="e")return(parseFloat(String(X))||0).toExponential();let M=J.match(/^\.?(\d+)f$/);if(M)return(parseFloat(String(X))||0).toFixed(parseInt(M[1],10));let G=J.match(/^(0?)(\d+)([sd])$/);if(G){let[,R,F,W]=G,j=parseInt(F,10);return(W==="d"?String(parseInt(String(X),10)||0):String(X)).padStart(j,R?"0":" ")}return String(X)}case"json_script":{let J=JSON.stringify(A).replace(/</g,"\\u003C").replace(/>/g,"\\u003E").replace(/&/g,"\\u0026"),M=`<script${Z?` id="${String(Z)}"`:""} type="application/json">${J}</script>`,G=new String(M);return G.__safe__=!0,G}}}if(Q===2){let Z=this.eval(B.args[0],K),J=this.eval(B.args[1],K);switch($){case"replace":return String(A??"").replaceAll(String(Z),String(J));case"batch":{if(!Array.isArray(A))return[[A]];let X=Number(Z)||1,M=J,G=[];for(let R=0;R<A.length;R+=X){let F=A.slice(R,R+X);while(M!==null&&F.length<X)F.push(M);G.push(F)}return G}case"sum":{if(!Array.isArray(A))return Number(J)||0;let X=Number(J)||0;for(let M=0;M<A.length;M++)X+=Number(Z?A[M][Z]:A[M])||0;return X}case"max":{if(!Array.isArray(A)||A.length===0)return J;if(Z){let M=A[0];for(let G=1;G<A.length;G++)if(A[G][Z]>M[Z])M=A[G];return M}let X=A[0];for(let M=1;M<A.length;M++)if(A[M]>X)X=A[M];return X}case"min":{if(!Array.isArray(A)||A.length===0)return J;if(Z){let M=A[0];for(let G=1;G<A.length;G++)if(A[G][Z]<M[Z])M=A[G];return M}let X=A[0];for(let M=1;M<A.length;M++)if(A[M]<X)X=A[M];return X}case"timesince":{let X=A instanceof Date?A:new Date(A),G=((Z instanceof Date?Z:new Date(Z??Date.now())).getTime()-X.getTime())/1000,R=[[31536000,"year","years"],[2592000,"month","months"],[604800,"week","weeks"],[86400,"day","days"],[3600,"hour","hours"],[60,"minute","minutes"]];for(let[F,W,j]of R){let q=Math.floor(G/F);if(q>=1)return`${q} ${q===1?W:j}`}return"just now"}case"timeuntil":{let X=A instanceof Date?A:new Date(A),M=Z instanceof Date?Z:new Date(Z??Date.now()),G=(X.getTime()-M.getTime())/1000,R=[[31536000,"year","years"],[2592000,"month","months"],[604800,"week","weeks"],[86400,"day","days"],[3600,"hour","hours"],[60,"minute","minutes"]];for(let[F,W,j]of R){let q=Math.floor(G/F);if(q>=1)return`${q} ${q===1?W:j}`}return"now"}}}let O=[];for(let Z=0;Z<Q;Z++)O.push(this.eval(B.args[Z],K));let U=this.evalObjectSync(B.kwargs,K),Y=this.filters[$];if(!Y){let Z=Object.keys(this.filters),J=l($,Z);throw new y(`Unknown filter '${$}'`,{line:B.line,column:B.column,source:this.source,suggestion:J||void 0,availableOptions:Z.slice(0,15)})}return Y(A,...O,...Object.values(U))}evalBinaryOp(B,K){let A=this.eval(B.left,K),$=B.operator;if($==="and")return this.isTruthy(A)?this.eval(B.right,K):A;if($==="or")return this.isTruthy(A)?A:this.eval(B.right,K);let Q=this.eval(B.right,K);if($==="%"){if(typeof A==="number"&&typeof Q==="number")return Q===0?NaN:A%Q;let O=Number(Q);return O===0?NaN:Number(A)%O}if($==="+"){if(typeof A==="number"&&typeof Q==="number")return A+Q;return typeof A==="string"||typeof Q==="string"?String(A)+String(Q):Number(A)+Number(Q)}switch($){case"-":return Number(A)-Number(Q);case"*":return Number(A)*Number(Q);case"/":return Number(A)/Number(Q);case"~":return String(A)+String(Q);default:return}}evalUnaryOp(B,K){let A=this.eval(B.operand,K);switch(B.operator){case"not":return!this.isTruthy(A);case"-":return-Number(A);case"+":return+Number(A);default:return A}}evalCompare(B,K){let A=this.eval(B.left,K),$=B.ops;if($.length===1){let{operator:O,right:U}=$[0],Y=this.eval(U,K);if(O==="==")return A===Y;if(O==="!=")return A!==Y;if(O==="<")return A<Y;if(O===">")return A>Y;if(O==="<=")return A<=Y;if(O===">=")return A>=Y;if(O==="in")return this.isIn(A,Y);if(O==="not in")return!this.isIn(A,Y);if(O==="is")return A===Y;if(O==="is not")return A!==Y;return!1}let Q=A;for(let{operator:O,right:U}of $){let Y=this.eval(U,K),Z;switch(O){case"==":Z=Q===Y;break;case"!=":Z=Q!==Y;break;case"<":Z=Q<Y;break;case">":Z=Q>Y;break;case"<=":Z=Q<=Y;break;case">=":Z=Q>=Y;break;case"in":Z=this.isIn(Q,Y);break;case"not in":Z=!this.isIn(Q,Y);break;case"is":Z=Q===Y;break;case"is not":Z=Q!==Y;break;default:Z=!1}if(!Z)return!1;Q=Y}return!0}evalConditional(B,K){return this.isTruthy(this.eval(B.test,K))?this.eval(B.trueExpr,K):this.eval(B.falseExpr,K)}evalObjectLiteral(B,K){let A={};for(let{key:$,value:Q}of B.pairs)A[String(this.eval($,K))]=this.eval(Q,K);return A}evalFunctionCall(B,K){let A=this.eval(B.callee,K),$=[];for(let O=0;O<B.args.length;O++)$.push(this.eval(B.args[O],K));let Q=this.evalObjectSync(B.kwargs,K);return typeof A==="function"?A(...$,Q):void 0}evalTest(B,K){if(B.test==="defined"||B.test==="undefined"){let U=!1;if(B.node.type==="Name")U=K.has(B.node.name);else U=this.eval(B.node,K)!==void 0;let Y=B.test==="defined"?U:!U;return B.negated?!Y:Y}let A=this.eval(B.node,K),$=[];for(let U=0;U<B.args.length;U++)$.push(this.eval(B.args[U],K));let Q=this.tests[B.test];if(!Q)throw Error(`Unknown test: ${B.test}`);let O=Q(A,...$);return B.negated?!O:O}evalObjectSync(B,K){let A={};for(let $ in B)A[$]=this.eval(B[$],K);return A}async collectBlocks(B,K){for(let A of B.body)if(A.type==="Extends"){let $=this.eval(A.template,K);this.parentTemplate=await this.options.templateLoader(String($)),await this.collectBlocks(this.parentTemplate,K)}else if(A.type==="Block")this.blocks.set(A.name,A)}async renderTemplateAsync(B,K){let A=[];for(let $ of B.body){let Q=await this.renderNodeAsync($,K);if(Q!==null)A.push(Q)}return A.join("")}async renderNodeAsync(B,K){switch(B.type){case"Text":return B.value;case"Output":return this.stringify(this.eval(B.expression,K));case"If":return this.renderIfAsync(B,K);case"For":return this.renderForAsync(B,K);case"Block":return this.renderBlockAsync(B,K);case"Extends":return null;case"Include":return this.renderInclude(B,K);case"Set":return K.set(B.target,this.eval(B.value,K)),"";case"With":return this.renderWithAsync(B,K);case"Load":return null;case"Url":return this.renderUrlSync(B,K);case"Static":return this.renderStaticSync(B,K);case"Now":return this.renderNowSync(B,K);case"Cycle":return this.renderCycleSync(B,K);case"Firstof":return this.renderFirstofSync(B,K);case"Ifchanged":return this.renderIfchangedSync(B,K);case"Regroup":return this.renderRegroupSync(B,K);case"Widthratio":return this.renderWidthratioSync(B,K);case"Lorem":return this.renderLoremSync(B,K);case"CsrfToken":return this.renderCsrfTokenSync();case"Debug":return this.renderDebugSync(K);case"Templatetag":return this.renderTemplatetagSync(B);default:return null}}async renderIfAsync(B,K){if(this.isTruthy(this.eval(B.test,K)))return this.renderNodesAsync(B.body,K);for(let A of B.elifs)if(this.isTruthy(this.eval(A.test,K)))return this.renderNodesAsync(A.body,K);return B.else_.length>0?this.renderNodesAsync(B.else_,K):""}async renderForAsync(B,K){let A=this.eval(B.iter,K),$=this.toIterable(A),Q=$.length;if(Q===0)return this.renderNodesAsync(B.else_,K);let O=Array(Q),U=Array.isArray(B.target);K.push(),K.pushForLoop($,0);for(let Y=0;Y<Q;Y++){let Z=$[Y];if(Y>0)K.updateForLoop(Y,$);if(U){let J;if(Array.isArray(Z))J=Z;else if(Z&&typeof Z==="object"&&(("0"in Z)||("key"in Z)))J=[Z[0]??Z.key,Z[1]??Z.value];else J=[Z,Z];let X=B.target;for(let M=0;M<X.length;M++)K.set(X[M],J[M])}else K.set(B.target,Z);O[Y]=await this.renderNodesAsync(B.body,K)}return K.popForLoop(),K.pop(),O.join("")}async renderBlockAsync(B,K){let A=this.blocks.get(B.name)||B;K.push();let $=await this.renderNodesAsync(B.body,K),Q=new String($);Q.__safe__=!0,K.set("block",{super:Q});let O=await this.renderNodesAsync(A.body,K);return K.pop(),O}async renderInclude(B,K){try{let A=this.eval(B.template,K),$=await this.options.templateLoader(String(A)),Q;if(B.only)Q=new w(B.context?this.evalObjectSync(B.context,K):{});else{let O=B.context?this.evalObjectSync(B.context,K):{};Q=K.derived(O)}return this.renderTemplateAsync($,Q)}catch(A){if(B.ignoreMissing)return"";throw A}}async renderWithAsync(B,K){K.push();for(let{target:$,value:Q}of B.assignments)K.set($,this.eval(Q,K));let A=await this.renderNodesAsync(B.body,K);return K.pop(),A}async renderNodesAsync(B,K){let A=[];for(let $ of B){let Q=await this.renderNodeAsync($,K);if(Q!==null)A.push(Q)}return A.join("")}async evaluate(B,K){return this.eval(B,K)}stringify(B){if(B==null)return"";if(typeof B==="string"){if(B.__safe__)return B;return this.options.autoescape?Bun.escapeHTML(B):B}if(typeof B==="boolean")return B?"True":"False";if(typeof B==="number")return String(B);let K=String(B);if(B.__safe__)return K;return this.options.autoescape?Bun.escapeHTML(K):K}isTruthy(B){if(typeof B==="boolean")return B;if(B==null)return!1;if(typeof B==="string")return B.length>0;if(typeof B==="number")return B!==0;if(Array.isArray(B))return B.length>0;if(typeof B==="object"){for(let K in B)return!0;return!1}return!0}deepEqual(B,K){if(B===K)return!0;if(B==null||K==null)return B===K;let A=typeof B;if(A!==typeof K)return!1;if(A!=="object")return!1;if(Array.isArray(B)){if(!Array.isArray(K)||B.length!==K.length)return!1;for(let Q=0;Q<B.length;Q++)if(!this.deepEqual(B[Q],K[Q]))return!1;return!0}return JSON.stringify(B)===JSON.stringify(K)}isIn(B,K){if(Array.isArray(K))return K.includes(B);if(typeof K==="string")return K.includes(String(B));if(typeof K==="object"&&K!==null)return B in K;return!1}toIterable(B){if(Array.isArray(B))return B;if(B==null)return[];if(typeof B==="string")return B.split("");if(typeof B==="object"){if(typeof B[Symbol.iterator]==="function")return Array.from(B);let K=Object.keys(B),A=K.length,$=Array(A);for(let Q=0;Q<A;Q++){let O=K[Q],U=B[O];$[Q]={key:O,value:U,0:O,1:U}}return $}return[B]}addFilter(B,K){this.filters[B]=K}addTest(B,K){this.tests[B]=K}addGlobal(B,K){this.options.globals[B]=K}setSource(B){this.source=B}}function T(B,K={}){return new XB(K).compile(B)}function c(B,K={}){let A=T(B,K),$=Function("__ctx","__helpers",`
30
+ `+(M[R].trim()===""?M[R]:X+M[R]);return G}case"stringformat":{let J=String(O),X=A;if(J==="s")return String(X);if(J==="d"||J==="i")return String(parseInt(String(X),10)||0);if(J==="f")return String(parseFloat(String(X))||0);if(J==="x")return(parseInt(String(X),10)||0).toString(16);if(J==="X")return(parseInt(String(X),10)||0).toString(16).toUpperCase();if(J==="o")return(parseInt(String(X),10)||0).toString(8);if(J==="b")return(parseInt(String(X),10)||0).toString(2);if(J==="e")return(parseFloat(String(X))||0).toExponential();let M=J.match(/^\.?(\d+)f$/);if(M)return(parseFloat(String(X))||0).toFixed(parseInt(M[1],10));let G=J.match(/^(0?)(\d+)([sd])$/);if(G){let[,R,F,W]=G,j=parseInt(F,10);return(W==="d"?String(parseInt(String(X),10)||0):String(X)).padStart(j,R?"0":" ")}return String(X)}case"json_script":{let J=JSON.stringify(A).replace(/</g,"\\u003C").replace(/>/g,"\\u003E").replace(/&/g,"\\u0026"),M=`<script${O?` id="${String(O)}"`:""} type="application/json">${J}</script>`,G=new String(M);return G.__safe__=!0,G}}}if($===2){let O=this.eval(B.args[0],K),J=this.eval(B.args[1],K);switch(Q){case"replace":return String(A??"").replaceAll(String(O),String(J));case"batch":{if(!Array.isArray(A))return[[A]];let X=Number(O)||1,M=J,G=[];for(let R=0;R<A.length;R+=X){let F=A.slice(R,R+X);while(M!==null&&F.length<X)F.push(M);G.push(F)}return G}case"sum":{if(!Array.isArray(A))return Number(J)||0;let X=Number(J)||0;for(let M=0;M<A.length;M++)X+=Number(O?A[M][O]:A[M])||0;return X}case"max":{if(!Array.isArray(A)||A.length===0)return J;if(O){let M=A[0];for(let G=1;G<A.length;G++)if(A[G][O]>M[O])M=A[G];return M}let X=A[0];for(let M=1;M<A.length;M++)if(A[M]>X)X=A[M];return X}case"min":{if(!Array.isArray(A)||A.length===0)return J;if(O){let M=A[0];for(let G=1;G<A.length;G++)if(A[G][O]<M[O])M=A[G];return M}let X=A[0];for(let M=1;M<A.length;M++)if(A[M]<X)X=A[M];return X}case"timesince":{let X=A instanceof Date?A:new Date(A),G=((O instanceof Date?O:new Date(O??Date.now())).getTime()-X.getTime())/1000,R=[[31536000,"year","years"],[2592000,"month","months"],[604800,"week","weeks"],[86400,"day","days"],[3600,"hour","hours"],[60,"minute","minutes"]];for(let[F,W,j]of R){let q=Math.floor(G/F);if(q>=1)return`${q} ${q===1?W:j}`}return"just now"}case"timeuntil":{let X=A instanceof Date?A:new Date(A),M=O instanceof Date?O:new Date(O??Date.now()),G=(X.getTime()-M.getTime())/1000,R=[[31536000,"year","years"],[2592000,"month","months"],[604800,"week","weeks"],[86400,"day","days"],[3600,"hour","hours"],[60,"minute","minutes"]];for(let[F,W,j]of R){let q=Math.floor(G/F);if(q>=1)return`${q} ${q===1?W:j}`}return"now"}}}let Z=[];for(let O=0;O<$;O++)Z.push(this.eval(B.args[O],K));let U=this.evalObjectSync(B.kwargs,K),Y=this.filters[Q];if(!Y){let O=Object.keys(this.filters),J=n(Q,O);throw new y(`Unknown filter '${Q}'`,{line:B.line,column:B.column,source:this.source,suggestion:J||void 0,availableOptions:O.slice(0,15)})}return Y(A,...Z,...Object.values(U))}evalBinaryOp(B,K){let A=this.eval(B.left,K),Q=B.operator;if(Q==="and")return this.isTruthy(A)?this.eval(B.right,K):A;if(Q==="or")return this.isTruthy(A)?A:this.eval(B.right,K);let $=this.eval(B.right,K);if(Q==="%"){if(typeof A==="number"&&typeof $==="number")return $===0?NaN:A%$;let Z=Number($);return Z===0?NaN:Number(A)%Z}if(Q==="+"){if(typeof A==="number"&&typeof $==="number")return A+$;return typeof A==="string"||typeof $==="string"?String(A)+String($):Number(A)+Number($)}switch(Q){case"-":return Number(A)-Number($);case"*":return Number(A)*Number($);case"/":return Number(A)/Number($);case"~":return String(A)+String($);default:return}}evalUnaryOp(B,K){let A=this.eval(B.operand,K);switch(B.operator){case"not":return!this.isTruthy(A);case"-":return-Number(A);case"+":return+Number(A);default:return A}}evalCompare(B,K){let A=this.eval(B.left,K),Q=B.ops;if(Q.length===1){let{operator:Z,right:U}=Q[0],Y=this.eval(U,K);if(Z==="==")return A===Y;if(Z==="!=")return A!==Y;if(Z==="<")return A<Y;if(Z===">")return A>Y;if(Z==="<=")return A<=Y;if(Z===">=")return A>=Y;if(Z==="in")return this.isIn(A,Y);if(Z==="not in")return!this.isIn(A,Y);if(Z==="is")return A===Y;if(Z==="is not")return A!==Y;return!1}let $=A;for(let{operator:Z,right:U}of Q){let Y=this.eval(U,K),O;switch(Z){case"==":O=$===Y;break;case"!=":O=$!==Y;break;case"<":O=$<Y;break;case">":O=$>Y;break;case"<=":O=$<=Y;break;case">=":O=$>=Y;break;case"in":O=this.isIn($,Y);break;case"not in":O=!this.isIn($,Y);break;case"is":O=$===Y;break;case"is not":O=$!==Y;break;default:O=!1}if(!O)return!1;$=Y}return!0}evalConditional(B,K){return this.isTruthy(this.eval(B.test,K))?this.eval(B.trueExpr,K):this.eval(B.falseExpr,K)}evalObjectLiteral(B,K){let A={};for(let{key:Q,value:$}of B.pairs)A[String(this.eval(Q,K))]=this.eval($,K);return A}evalFunctionCall(B,K){let A=this.eval(B.callee,K),Q=[];for(let Z=0;Z<B.args.length;Z++)Q.push(this.eval(B.args[Z],K));let $=this.evalObjectSync(B.kwargs,K);return typeof A==="function"?A(...Q,$):void 0}evalTest(B,K){let{test:A,negated:Q}=B;if(A==="defined"||A==="undefined"){let O=!1;if(B.node.type==="Name")O=K.has(B.node.name);else O=this.eval(B.node,K)!==void 0;let J=A==="defined"?O:!O;return Q?!J:J}let $=this.eval(B.node,K);if(B.args.length===0){let O;switch(A){case"even":{let J=Number($);O=Number.isInteger(J)&&J%2===0;break}case"odd":{let J=Number($);O=Number.isInteger(J)&&J%2!==0;break}case"number":O=typeof $==="number"&&!isNaN($);break;case"integer":O=Number.isInteger($);break;case"float":O=typeof $==="number"&&!Number.isInteger($)&&!isNaN($);break;case"none":case"None":O=$===null;break;case"boolean":O=typeof $==="boolean";break;case"string":O=typeof $==="string";break;case"mapping":O=$!==null&&typeof $==="object"&&!Array.isArray($)&&!($ instanceof Date);break;case"iterable":O=$!=null&&(typeof $==="string"||Array.isArray($)||typeof $[Symbol.iterator]==="function");break;case"sequence":O=Array.isArray($)||typeof $==="string";break;case"callable":O=typeof $==="function";break;case"lower":O=typeof $==="string"&&$===$.toLowerCase()&&$!==$.toUpperCase();break;case"upper":O=typeof $==="string"&&$===$.toUpperCase()&&$!==$.toLowerCase();break;case"empty":if($==null)O=!0;else if(typeof $==="string"||Array.isArray($))O=$.length===0;else if(typeof $==="object"){O=!0;for(let J in $){O=!1;break}}else O=!1;break;case"truthy":if($==null)O=!1;else if(typeof $==="boolean")O=$;else if(typeof $==="number")O=$!==0;else if(typeof $==="string")O=$.length>0;else if(Array.isArray($))O=$.length>0;else if(typeof $==="object"){O=!1;for(let J in $){O=!0;break}}else O=!0;break;case"falsy":if($==null)O=!0;else if(typeof $==="boolean")O=!$;else if(typeof $==="number")O=$===0;else if(typeof $==="string")O=$.length===0;else if(Array.isArray($))O=$.length===0;else if(typeof $==="object"){O=!0;for(let J in $){O=!1;break}}else O=!1;break;case"true":O=$===!0;break;case"false":O=$===!1;break;default:{let J=this.tests[A];if(!J)throw Error(`Unknown test: ${A}`);O=J($)}}return Q?!O:O}if(B.args.length===1){let O=this.eval(B.args[0],K),J;switch(A){case"divisibleby":{let X=Number($),M=Number(O);J=M!==0&&X%M===0;break}case"gt":case"greaterthan":J=Number($)>Number(O);break;case"ge":J=Number($)>=Number(O);break;case"lt":case"lessthan":J=Number($)<Number(O);break;case"le":J=Number($)<=Number(O);break;case"eq":case"equalto":case"sameas":J=$===O;break;case"ne":J=$!==O;break;case"in":if(Array.isArray(O))J=O.includes($);else if(typeof O==="string")J=O.includes(String($));else if(typeof O==="object"&&O!==null)J=$ in O;else J=!1;break;default:{let X=this.tests[A];if(!X)throw Error(`Unknown test: ${A}`);J=X($,O)}}return Q?!J:J}let Z=[];for(let O=0;O<B.args.length;O++)Z.push(this.eval(B.args[O],K));let U=this.tests[A];if(!U)throw Error(`Unknown test: ${A}`);let Y=U($,...Z);return Q?!Y:Y}evalObjectSync(B,K){let A={};for(let Q in B)A[Q]=this.eval(B[Q],K);return A}async collectBlocks(B,K){for(let A of B.body)if(A.type==="Extends"){let Q=this.eval(A.template,K);this.parentTemplate=await this.options.templateLoader(String(Q)),await this.collectBlocks(this.parentTemplate,K)}else if(A.type==="Block")this.blocks.set(A.name,A)}async renderTemplateAsync(B,K){let A=[];for(let Q of B.body){let $=await this.renderNodeAsync(Q,K);if($!==null)A.push($)}return A.join("")}async renderNodeAsync(B,K){switch(B.type){case"Text":return B.value;case"Output":return this.stringify(this.eval(B.expression,K));case"If":return this.renderIfAsync(B,K);case"For":return this.renderForAsync(B,K);case"Block":return this.renderBlockAsync(B,K);case"Extends":return null;case"Include":return this.renderInclude(B,K);case"Set":return K.set(B.target,this.eval(B.value,K)),"";case"With":return this.renderWithAsync(B,K);case"Load":return null;case"Url":return this.renderUrlSync(B,K);case"Static":return this.renderStaticSync(B,K);case"Now":return this.renderNowSync(B,K);case"Cycle":return this.renderCycleSync(B,K);case"Firstof":return this.renderFirstofSync(B,K);case"Ifchanged":return this.renderIfchangedSync(B,K);case"Regroup":return this.renderRegroupSync(B,K);case"Widthratio":return this.renderWidthratioSync(B,K);case"Lorem":return this.renderLoremSync(B,K);case"CsrfToken":return this.renderCsrfTokenSync();case"Debug":return this.renderDebugSync(K);case"Templatetag":return this.renderTemplatetagSync(B);default:return null}}async renderIfAsync(B,K){if(this.isTruthy(this.eval(B.test,K)))return this.renderNodesAsync(B.body,K);for(let A of B.elifs)if(this.isTruthy(this.eval(A.test,K)))return this.renderNodesAsync(A.body,K);return B.else_.length>0?this.renderNodesAsync(B.else_,K):""}async renderForAsync(B,K){let A=this.eval(B.iter,K),Q=this.toIterable(A),$=Q.length;if($===0)return this.renderNodesAsync(B.else_,K);let Z=Array($),U=Array.isArray(B.target);K.push(),K.pushForLoop(Q,0);for(let Y=0;Y<$;Y++){let O=Q[Y];if(Y>0)K.updateForLoop(Y,Q);if(U){let J=Array.isArray(O)?O:[O,O],X=B.target;for(let M=0;M<X.length;M++)K.set(X[M],J[M])}else K.set(B.target,O);Z[Y]=await this.renderNodesAsync(B.body,K)}return K.popForLoop(),K.pop(),Z.join("")}async renderBlockAsync(B,K){let A=this.blocks.get(B.name)||B;K.push();let Q=await this.renderNodesAsync(B.body,K),$=new String(Q);$.__safe__=!0,K.set("block",{super:$});let Z=await this.renderNodesAsync(A.body,K);return K.pop(),Z}async renderInclude(B,K){try{let A=this.eval(B.template,K),Q=await this.options.templateLoader(String(A)),$;if(B.only)$=new w(B.context?this.evalObjectSync(B.context,K):{});else{let Z=B.context?this.evalObjectSync(B.context,K):{};$=K.derived(Z)}return this.renderTemplateAsync(Q,$)}catch(A){if(B.ignoreMissing)return"";throw A}}async renderWithAsync(B,K){K.push();for(let{target:Q,value:$}of B.assignments)K.set(Q,this.eval($,K));let A=await this.renderNodesAsync(B.body,K);return K.pop(),A}async renderNodesAsync(B,K){let A=[];for(let Q of B){let $=await this.renderNodeAsync(Q,K);if($!==null)A.push($)}return A.join("")}async evaluate(B,K){return this.eval(B,K)}stringify(B){if(B==null)return"";if(typeof B==="string"){if(B.__safe__)return B;return this.options.autoescape?Bun.escapeHTML(B):B}if(typeof B==="boolean")return B?"True":"False";if(typeof B==="number")return String(B);let K=String(B);if(B.__safe__)return K;return this.options.autoescape?Bun.escapeHTML(K):K}isTruthy(B){if(typeof B==="boolean")return B;if(B==null)return!1;if(typeof B==="string")return B.length>0;if(typeof B==="number")return B!==0;if(Array.isArray(B))return B.length>0;if(typeof B==="object"){for(let K in B)return!0;return!1}return!0}deepEqual(B,K){if(B===K)return!0;if(B==null||K==null)return B===K;let A=typeof B;if(A!==typeof K)return!1;if(A!=="object")return!1;if(Array.isArray(B)){if(!Array.isArray(K)||B.length!==K.length)return!1;for(let $=0;$<B.length;$++)if(!this.deepEqual(B[$],K[$]))return!1;return!0}return JSON.stringify(B)===JSON.stringify(K)}isIn(B,K){if(Array.isArray(K))return K.includes(B);if(typeof K==="string")return K.includes(String(B));if(typeof K==="object"&&K!==null)return B in K;return!1}toIterable(B){if(Array.isArray(B))return B;if(B==null)return[];if(typeof B==="string")return B.split("");if(typeof B==="object"){if(typeof B[Symbol.iterator]==="function")return Array.from(B);let K=Object.keys(B),A=K.length,Q=Array(A);for(let $=0;$<A;$++){let Z=K[$],U=B[Z],Y=[Z,U];Y.key=Z,Y.value=U,Q[$]=Y}return Q}return[B]}addFilter(B,K){this.filters[B]=K}addTest(B,K){this.tests[B]=K}addGlobal(B,K){this.options.globals[B]=K}setSource(B){this.source=B}}function T(B,K={}){return new XB(K).compile(B)}function v(B,K={}){let A=T(B,K),Q=Function("__ctx","__helpers",`
31
31
  const { escape, isTruthy, toArray, applyFilter, applyTest } = __helpers;
32
32
  ${A}
33
33
  return render(__ctx);
34
- `);return(Q)=>$(Q,fA)}var fA={escape:(B)=>{if(B==null)return"";if(typeof B==="object"&&B.__safe)return String(B.value??"");if(B?.__safe__)return String(B);return Bun.escapeHTML(String(B))},isTruthy:(B)=>{if(B==null)return!1;if(typeof B==="boolean")return B;if(typeof B==="number")return B!==0;if(typeof B==="string")return B.length>0;if(Array.isArray(B))return B.length>0;if(typeof B==="object"){for(let K in B)return!0;return!1}return!0},toArray:(B)=>{if(B==null)return[];if(Array.isArray(B))return B;if(typeof B==="string")return B.split("");if(typeof B==="object"){if(typeof B[Symbol.iterator]==="function")return[...B];return Object.entries(B)}return[]},applyFilter:(B,K,...A)=>{let $=h[B];if(!$)throw Error(`Unknown filter: ${B}`);return $(K,...A)},applyTest:(B,K,...A)=>{let $=f[B];if(!$)throw Error(`Unknown test: ${B}`);return $(K,...A)}};class XB{options;indent=0;varCounter=0;loopStack=[];localVars=[];constructor(B={}){this.options={functionName:B.functionName??"render",inlineHelpers:B.inlineHelpers??!0,minify:B.minify??!1,autoescape:B.autoescape??!0}}pushScope(){this.localVars.push(new Set)}popScope(){this.localVars.pop()}addLocalVar(B){if(this.localVars.length>0)this.localVars[this.localVars.length-1].add(B)}isLocalVar(B){for(let K=this.localVars.length-1;K>=0;K--)if(this.localVars[K].has(B))return!0;return!1}compile(B){let K=this.compileNodes(B.body),A=this.options.minify?"":`
35
- `;return`function ${this.options.functionName}(__ctx) {${A} let __out = '';${A}`+K+` return __out;${A}}`}compileNodes(B){return B.map((K)=>this.compileNode(K)).join("")}compileNode(B){switch(B.type){case"Text":return this.compileText(B);case"Output":return this.compileOutput(B);case"If":return this.compileIf(B);case"For":return this.compileFor(B);case"Set":return this.compileSet(B);case"With":return this.compileWith(B);case"Comment":return"";case"Extends":case"Block":case"Include":throw Error(`AOT compilation does not support '${B.type}' - use Environment.render() for templates with inheritance`);case"Url":case"Static":throw Error(`AOT compilation does not support '${B.type}' tag - use Environment.render() with urlResolver/staticResolver`);default:throw Error(`Unknown node type in AOT compiler: ${B.type}`)}}compileText(B){return` __out += ${JSON.stringify(B.value)};${this.nl()}`}compileOutput(B){let K=this.compileExpr(B.expression);if(this.options.autoescape&&!this.isMarkedSafe(B.expression))return` __out += escape(${K});${this.nl()}`;return` __out += (${K}) ?? '';${this.nl()}`}compileIf(B){let K="",A=this.compileExpr(B.test);K+=` if (isTruthy(${A})) {${this.nl()}`,K+=this.compileNodes(B.body),K+=" }";for(let $ of B.elifs){let Q=this.compileExpr($.test);K+=` else if (isTruthy(${Q})) {${this.nl()}`,K+=this.compileNodes($.body),K+=" }"}if(B.else_.length>0)K+=` else {${this.nl()}`,K+=this.compileNodes(B.else_),K+=" }";return K+=this.nl(),K}compileFor(B){let K=this.genVar("iter"),A=this.genVar("i"),$=this.genVar("len"),Q=this.genVar("loop"),O=Array.isArray(B.target)?B.target[0]:B.target,U=Array.isArray(B.target)&&B.target[1]?B.target[1]:null,Y=this.loopStack.length>0?this.loopStack[this.loopStack.length-1]:null,Z=this.compileExpr(B.iter),J="";if(J+=` const ${K} = toArray(${Z});${this.nl()}`,J+=` const ${$} = ${K}.length;${this.nl()}`,B.else_.length>0)J+=` if (${$} === 0) {${this.nl()}`,J+=this.compileNodes(B.else_),J+=` } else {${this.nl()}`;if(J+=` for (let ${A} = 0; ${A} < ${$}; ${A}++) {${this.nl()}`,U)J+=` const ${O} = ${K}[${A}][0];${this.nl()}`,J+=` const ${U} = ${K}[${A}][1];${this.nl()}`;else J+=` const ${O} = ${K}[${A}];${this.nl()}`;if(J+=` const ${Q} = {${this.nl()}`,J+=` counter: ${A} + 1,${this.nl()}`,J+=` counter0: ${A},${this.nl()}`,J+=` revcounter: ${$} - ${A},${this.nl()}`,J+=` revcounter0: ${$} - ${A} - 1,${this.nl()}`,J+=` first: ${A} === 0,${this.nl()}`,J+=` last: ${A} === ${$} - 1,${this.nl()}`,J+=` length: ${$},${this.nl()}`,J+=` index: ${A} + 1,${this.nl()}`,J+=` index0: ${A},${this.nl()}`,Y)J+=` parentloop: ${Y},${this.nl()}`,J+=` parent: ${Y}${this.nl()}`;else J+=` parentloop: null,${this.nl()}`,J+=` parent: null${this.nl()}`;J+=` };${this.nl()}`,J+=` const forloop = ${Q};${this.nl()}`,J+=` const loop = ${Q};${this.nl()}`,this.loopStack.push(Q);let X=this.compileNodes(B.body);if(J+=X.replace(new RegExp(`__ctx\\.${O}`,"g"),O),this.loopStack.pop(),J+=` }${this.nl()}`,B.else_.length>0)J+=` }${this.nl()}`;return J}compileSet(B){let K=this.compileExpr(B.value);return` const ${B.target} = ${K};${this.nl()}`}compileWith(B){let K=` {${this.nl()}`;this.pushScope();for(let{target:A,value:$}of B.assignments){let Q=this.compileExpr($);K+=` const ${A} = ${Q};${this.nl()}`,this.addLocalVar(A)}return K+=this.compileNodes(B.body),K+=` }${this.nl()}`,this.popScope(),K}compileExpr(B){switch(B.type){case"Name":return this.compileName(B);case"Literal":return this.compileLiteral(B);case"Array":return this.compileArray(B);case"Object":return this.compileObject(B);case"BinaryOp":return this.compileBinaryOp(B);case"UnaryOp":return this.compileUnaryOp(B);case"Compare":return this.compileCompare(B);case"GetAttr":return this.compileGetAttr(B);case"GetItem":return this.compileGetItem(B);case"FilterExpr":return this.compileFilter(B);case"TestExpr":return this.compileTest(B);case"Conditional":return this.compileConditional(B);default:return"undefined"}}compileName(B){if(B.name==="true"||B.name==="True")return"true";if(B.name==="false"||B.name==="False")return"false";if(B.name==="none"||B.name==="None"||B.name==="null")return"null";if(B.name==="forloop"||B.name==="loop")return B.name;if(this.isLocalVar(B.name))return B.name;return`__ctx.${B.name}`}compileLiteral(B){if(typeof B.value==="string")return JSON.stringify(B.value);return String(B.value)}compileArray(B){return`[${B.elements.map((A)=>this.compileExpr(A)).join(", ")}]`}compileObject(B){return`{${B.pairs.map(({key:A,value:$})=>{let Q=this.compileExpr(A),O=this.compileExpr($);return`[${Q}]: ${O}`}).join(", ")}}`}compileBinaryOp(B){let K=this.compileExpr(B.left),A=this.compileExpr(B.right);switch(B.operator){case"and":return`(${K} && ${A})`;case"or":return`(${K} || ${A})`;case"~":return`(String(${K}) + String(${A}))`;case"in":return`(Array.isArray(${A}) ? ${A}.includes(${K}) : String(${A}).includes(String(${K})))`;case"not in":return`!(Array.isArray(${A}) ? ${A}.includes(${K}) : String(${A}).includes(String(${K})))`;default:return`(${K} ${B.operator} ${A})`}}compileUnaryOp(B){let K=this.compileExpr(B.operand);switch(B.operator){case"not":return`!isTruthy(${K})`;case"-":return`-(${K})`;case"+":return`+(${K})`;default:return K}}compileCompare(B){let K=this.compileExpr(B.left);for(let{operator:A,right:$}of B.ops){let Q=this.compileExpr($);switch(A){case"==":case"===":K=`(${K} === ${Q})`;break;case"!=":case"!==":K=`(${K} !== ${Q})`;break;default:K=`(${K} ${A} ${Q})`}}return K}compileGetAttr(B){return`${this.compileExpr(B.object)}?.${B.attribute}`}compileGetItem(B){let K=this.compileExpr(B.object),A=this.compileExpr(B.index);return`${K}?.[${A}]`}compileFilter(B){let K=this.compileExpr(B.node),A=B.args.map(($)=>this.compileExpr($));switch(B.filter){case"upper":return`String(${K}).toUpperCase()`;case"lower":return`String(${K}).toLowerCase()`;case"title":return`String(${K}).replace(/\\b\\w/g, c => c.toUpperCase())`;case"trim":return`String(${K}).trim()`;case"length":return`(${K}?.length ?? Object.keys(${K} ?? {}).length)`;case"first":return`(${K})?.[0]`;case"last":return`(${K})?.[(${K})?.length - 1]`;case"default":return`((${K}) ?? ${A[0]??'""'})`;case"safe":return`{ __safe: true, value: String(${K}) }`;case"escape":case"e":return`escape(${K})`;case"join":return`(${K} ?? []).join(${A[0]??'""'})`;case"abs":return`Math.abs(${K})`;case"round":return A.length?`Number(${K}).toFixed(${A[0]})`:`Math.round(${K})`;case"int":return`parseInt(${K}, 10)`;case"float":return`parseFloat(${K})`;case"floatformat":return`Number(${K}).toFixed(${A[0]??1})`;case"filesizeformat":return`applyFilter('filesizeformat', ${K})`;default:let $=A.length?", "+A.join(", "):"";return`applyFilter('${B.filter}', ${K}${$})`}}compileTest(B){let K=this.compileExpr(B.node),A=B.args.map((Q)=>this.compileExpr(Q)),$=B.negated?"!":"";switch(B.test){case"defined":return`${$}(${K} !== undefined)`;case"undefined":return`${$}(${K} === undefined)`;case"none":return`${$}(${K} === null)`;case"even":return`${$}(${K} % 2 === 0)`;case"odd":return`${$}(${K} % 2 !== 0)`;case"divisibleby":return`${$}(${K} % ${A[0]} === 0)`;case"empty":return`${$}((${K} == null) || (${K}.length === 0) || (Object.keys(${K}).length === 0))`;case"iterable":return`${$}(Array.isArray(${K}) || typeof ${K} === 'string')`;case"number":return`${$}(typeof ${K} === 'number' && !isNaN(${K}))`;case"string":return`${$}(typeof ${K} === 'string')`;default:let Q=A.length?", "+A.join(", "):"";return`${$}applyTest('${B.test}', ${K}${Q})`}}compileConditional(B){let K=this.compileExpr(B.test),A=this.compileExpr(B.trueExpr),$=this.compileExpr(B.falseExpr);return`(isTruthy(${K}) ? ${A} : ${$})`}isMarkedSafe(B){if(B.type==="FilterExpr")return B.filter==="safe";return!1}genVar(B){return`__${B}${this.varCounter++}`}nl(){return this.options.minify?"":`
36
- `}}function g(B,K){return new MB(K).flatten(B)}function x(B){return new GB().check(B)}class MB{loader;maxDepth;blocks=new Map;depth=0;constructor(B){this.loader=B.loader,this.maxDepth=B.maxDepth??10}flatten(B){return this.blocks.clear(),this.depth=0,this.processTemplate(B)}processTemplate(B,K=!0){if(this.depth>this.maxDepth)throw Error(`Maximum template inheritance depth (${this.maxDepth}) exceeded`);this.collectBlocks(B.body,K);let A=this.findExtends(B.body);if(A){let $=this.getStaticTemplateName(A.template),Q=this.loader.load($),O=this.loader.parse(Q);this.depth++;let U=this.processTemplate(O,!1);return this.depth--,{type:"Template",body:this.replaceBlocks(U.body),line:B.line,column:B.column}}return{type:"Template",body:this.processNodes(B.body),line:B.line,column:B.column}}collectBlocks(B,K=!0){for(let A of B){if(A.type==="Block"){let $=A;if(K||!this.blocks.has($.name))this.blocks.set($.name,$)}this.collectBlocksFromNode(A,K)}}collectBlocksFromNode(B,K=!0){switch(B.type){case"If":{let A=B;this.collectBlocks(A.body,K);for(let $ of A.elifs)this.collectBlocks($.body,K);this.collectBlocks(A.else_,K);break}case"For":{let A=B;this.collectBlocks(A.body,K),this.collectBlocks(A.else_,K);break}case"With":{let A=B;this.collectBlocks(A.body,K);break}case"Block":{let A=B;this.collectBlocks(A.body,K);break}}}findExtends(B){for(let K of B)if(K.type==="Extends")return K;return null}processNodes(B){let K=[];for(let A of B){if(A.type==="Extends")continue;if(A.type==="Include"){let Q=A,O=this.inlineInclude(Q);K.push(...O);continue}if(A.type==="Block"){let Q=A,O=this.blocks.get(Q.name);if(O&&O!==Q)K.push(...this.processNodes(O.body));else K.push(...this.processNodes(Q.body));continue}let $=this.processNode(A);if($)K.push($)}return K}processNode(B){switch(B.type){case"If":{let K=B;return{...K,body:this.processNodes(K.body),elifs:K.elifs.map((A)=>({test:A.test,body:this.processNodes(A.body)})),else_:this.processNodes(K.else_)}}case"For":{let K=B;return{...K,body:this.processNodes(K.body),else_:this.processNodes(K.else_)}}case"With":{let K=B;return{...K,body:this.processNodes(K.body)}}default:return B}}replaceBlocks(B){return this.processNodes(B)}inlineInclude(B){let K=this.getStaticTemplateName(B.template);try{let A=this.loader.load(K),$=this.loader.parse(A);this.depth++;let Q=this.processTemplate($);if(this.depth--,B.context&&Object.keys(B.context).length>0)return[{type:"With",assignments:Object.entries(B.context).map(([U,Y])=>({target:U,value:Y})),body:Q.body,line:B.line,column:B.column}];return Q.body}catch(A){if(B.ignoreMissing)return[];throw A}}getStaticTemplateName(B){if(B.type==="Literal"){let K=B;if(typeof K.value==="string")return K.value}throw Error(`AOT compilation requires static template names. Found dynamic expression at line ${B.line}. Use Environment.render() for dynamic template names.`)}}class GB{check(B){return this.checkNodes(B.body)}checkNodes(B){for(let K of B){let A=this.checkNode(K);if(!A.canFlatten)return A}return{canFlatten:!0}}checkNode(B){switch(B.type){case"Extends":{let K=B;if(!this.isStaticName(K.template))return{canFlatten:!1,reason:`Dynamic extends at line ${B.line} - use static string literal`};break}case"Include":{let K=B;if(!this.isStaticName(K.template))return{canFlatten:!1,reason:`Dynamic include at line ${B.line} - use static string literal`};break}case"If":{let K=B,A=this.checkNodes(K.body);if(!A.canFlatten)return A;for(let $ of K.elifs)if(A=this.checkNodes($.body),!A.canFlatten)return A;if(A=this.checkNodes(K.else_),!A.canFlatten)return A;break}case"For":{let K=B,A=this.checkNodes(K.body);if(!A.canFlatten)return A;if(A=this.checkNodes(K.else_),!A.canFlatten)return A;break}case"With":{let K=B,A=this.checkNodes(K.body);if(!A.canFlatten)return A;break}case"Block":{let K=B,A=this.checkNodes(K.body);if(!A.canFlatten)return A;break}}return{canFlatten:!0}}isStaticName(B){return B.type==="Literal"&&typeof B.value==="string"}}class i{data;constructor(){this.data={startTime:performance.now(),templateChain:[],mode:"runtime",isAsync:!1,contextKeys:[],contextSnapshot:{},filtersUsed:new Map,testsUsed:new Map,cacheHits:0,cacheMisses:0,queries:[],queryStats:{count:0,totalDuration:0,slowCount:0,n1Count:0,queryCounts:new Map},warnings:[]}}startLexer(){this.data._lexerStart=performance.now()}endLexer(){if(this.data._lexerStart)this.data.lexerTime=performance.now()-this.data._lexerStart}startParser(){this.data._parserStart=performance.now()}endParser(){if(this.data._parserStart)this.data.parserTime=performance.now()-this.data._parserStart}startRender(){this.data._renderStart=performance.now()}endRender(){if(this.data._renderStart)this.data.renderTime=performance.now()-this.data._renderStart;this.data.endTime=performance.now(),this.data.totalTime=this.data.endTime-this.data.startTime}addTemplate(B,K,A){if(this.data.templateChain.push({name:B,type:K,parent:A}),K==="root")this.data.rootTemplate=B}setMode(B){this.data.mode=B}setAsync(B){this.data.isAsync=B}captureContext(B){this.data.contextKeys=Object.keys(B);for(let[K,A]of Object.entries(B))this.data.contextSnapshot[K]=this.captureValue(A)}captureValue(B,K=0){let A=this.getType(B),$=this.getPreview(B),Q=this.isExpandable(B),O={type:A,preview:$,value:B,expandable:Q};if(Q&&K<3){if(O.children={},Array.isArray(B))B.forEach((U,Y)=>{O.children[String(Y)]=this.captureValue(U,K+1)});else if(typeof B==="object"&&B!==null)for(let[U,Y]of Object.entries(B))O.children[U]=this.captureValue(Y,K+1)}return O}isExpandable(B){if(B===null||B===void 0)return!1;if(Array.isArray(B))return B.length>0;if(typeof B==="object")return Object.keys(B).length>0;return!1}getType(B){if(B===null)return"null";if(B===void 0)return"undefined";if(Array.isArray(B))return`Array(${B.length})`;if(B instanceof Date)return"Date";if(typeof B==="object")return"Object";return typeof B}getPreview(B,K=50){if(B===null)return"null";if(B===void 0)return"undefined";if(typeof B==="string")return B.length>K?`"${B.slice(0,K)}..."`:`"${B}"`;if(typeof B==="number"||typeof B==="boolean")return String(B);if(Array.isArray(B)){if(B.length===0)return"[]";if(B.length<=3)return`[${B.map(($)=>this.getPreview($,15)).join(", ")}]`;return`[${this.getPreview(B[0],15)}, ... +${B.length-1}]`}if(B instanceof Date)return B.toISOString();if(typeof B==="object"){let A=Object.keys(B);if(A.length===0)return"{}";if(A.length<=2)return`{ ${A.join(", ")} }`;return`{ ${A.slice(0,2).join(", ")}, ... +${A.length-2} }`}if(typeof B==="function")return"function()";return String(B)}recordFilter(B){this.data.filtersUsed.set(B,(this.data.filtersUsed.get(B)||0)+1)}recordTest(B){this.data.testsUsed.set(B,(this.data.testsUsed.get(B)||0)+1)}recordCacheHit(){this.data.cacheHits++}recordCacheMiss(){this.data.cacheMisses++}addWarning(B){this.data.warnings.push(B)}recordQuery(B){let K=this.normalizeQuery(B.sql),A=this.data.queryStats.queryCounts.get(K)||0;this.data.queryStats.queryCounts.set(K,A+1);let $=A>=2,Q={...B,timestamp:performance.now(),isN1:$};if(this.data.queries.push(Q),this.data.queryStats.count++,this.data.queryStats.totalDuration+=B.duration,B.duration>100)this.data.queryStats.slowCount++;if($&&A===2)this.data.queryStats.n1Count++,this.addWarning(`N+1 query detected: ${K.slice(0,50)}...`)}normalizeQuery(B){return B.replace(/\s+/g," ").replace(/= \?/g,"= ?").replace(/= \$\d+/g,"= ?").replace(/= '\w+'/g,"= '?'").replace(/= \d+/g,"= ?").replace(/IN \([^)]+\)/gi,"IN (?)").trim()}getQueryStats(){return this.data.queryStats}getData(){return this.data}getSummary(){return{totalTime:this.data.totalTime||0,templateCount:this.data.templateChain.length,filterCount:this.data.filtersUsed.size,mode:this.data.mode}}}var k=null;function D(){return k=new i,k}function _(){if(k){let B=k.getData();return k=null,B}return null}var kA={position:"bottom",height:300,width:400,open:!1,dark:!0};function L(B,K={}){let A={...kA,...K},$=`binja-dbg-${Date.now()}`,Q=A.dark?yA:TA;return`
34
+ `);return($)=>Q($,fA)}var fA={escape:(B)=>{if(B==null)return"";if(typeof B==="object"&&B.__safe)return String(B.value??"");if(B?.__safe__)return String(B);return Bun.escapeHTML(String(B))},isTruthy:(B)=>{if(B==null)return!1;if(typeof B==="boolean")return B;if(typeof B==="number")return B!==0;if(typeof B==="string")return B.length>0;if(Array.isArray(B))return B.length>0;if(typeof B==="object"){for(let K in B)return!0;return!1}return!0},toArray:(B)=>{if(B==null)return[];if(Array.isArray(B))return B;if(typeof B==="string")return B.split("");if(typeof B==="object"){if(typeof B[Symbol.iterator]==="function")return[...B];return Object.entries(B)}return[]},applyFilter:(B,K,...A)=>{let Q=h[B];if(!Q)throw Error(`Unknown filter: ${B}`);return Q(K,...A)},applyTest:(B,K,...A)=>{let Q=f[B];if(!Q)throw Error(`Unknown test: ${B}`);return Q(K,...A)}};class XB{options;indent=0;varCounter=0;loopStack=[];localVars=[];constructor(B={}){this.options={functionName:B.functionName??"render",inlineHelpers:B.inlineHelpers??!0,minify:B.minify??!1,autoescape:B.autoescape??!0}}pushScope(){this.localVars.push(new Set)}popScope(){this.localVars.pop()}addLocalVar(B){if(this.localVars.length>0)this.localVars[this.localVars.length-1].add(B)}isLocalVar(B){for(let K=this.localVars.length-1;K>=0;K--)if(this.localVars[K].has(B))return!0;return!1}compile(B){let K=this.compileNodes(B.body),A=this.options.minify?"":`
35
+ `;return`function ${this.options.functionName}(__ctx) {${A} let __out = '';${A}`+K+` return __out;${A}}`}compileNodes(B){return B.map((K)=>this.compileNode(K)).join("")}compileNode(B){switch(B.type){case"Text":return this.compileText(B);case"Output":return this.compileOutput(B);case"If":return this.compileIf(B);case"For":return this.compileFor(B);case"Set":return this.compileSet(B);case"With":return this.compileWith(B);case"Comment":return"";case"Extends":case"Block":case"Include":throw Error(`AOT compilation does not support '${B.type}' - use Environment.render() for templates with inheritance`);case"Url":case"Static":throw Error(`AOT compilation does not support '${B.type}' tag - use Environment.render() with urlResolver/staticResolver`);default:throw Error(`Unknown node type in AOT compiler: ${B.type}`)}}compileText(B){return` __out += ${JSON.stringify(B.value)};${this.nl()}`}compileOutput(B){let K=this.compileExpr(B.expression);if(this.options.autoescape&&!this.isMarkedSafe(B.expression))return` __out += escape(${K});${this.nl()}`;return` __out += (${K}) ?? '';${this.nl()}`}compileIf(B){let K="",A=this.compileExpr(B.test);K+=` if (isTruthy(${A})) {${this.nl()}`,K+=this.compileNodes(B.body),K+=" }";for(let Q of B.elifs){let $=this.compileExpr(Q.test);K+=` else if (isTruthy(${$})) {${this.nl()}`,K+=this.compileNodes(Q.body),K+=" }"}if(B.else_.length>0)K+=` else {${this.nl()}`,K+=this.compileNodes(B.else_),K+=" }";return K+=this.nl(),K}compileFor(B){let K=this.genVar("iter"),A=this.genVar("i"),Q=this.genVar("len"),$=this.genVar("loop"),Z=Array.isArray(B.target)?B.target[0]:B.target,U=Array.isArray(B.target)&&B.target[1]?B.target[1]:null,Y=this.loopStack.length>0?this.loopStack[this.loopStack.length-1]:null,O=this.compileExpr(B.iter),J="";if(J+=` const ${K} = toArray(${O});${this.nl()}`,J+=` const ${Q} = ${K}.length;${this.nl()}`,B.else_.length>0)J+=` if (${Q} === 0) {${this.nl()}`,J+=this.compileNodes(B.else_),J+=` } else {${this.nl()}`;if(J+=` for (let ${A} = 0; ${A} < ${Q}; ${A}++) {${this.nl()}`,U)J+=` const ${Z} = ${K}[${A}][0];${this.nl()}`,J+=` const ${U} = ${K}[${A}][1];${this.nl()}`;else J+=` const ${Z} = ${K}[${A}];${this.nl()}`;if(J+=` const ${$} = {${this.nl()}`,J+=` counter: ${A} + 1,${this.nl()}`,J+=` counter0: ${A},${this.nl()}`,J+=` revcounter: ${Q} - ${A},${this.nl()}`,J+=` revcounter0: ${Q} - ${A} - 1,${this.nl()}`,J+=` first: ${A} === 0,${this.nl()}`,J+=` last: ${A} === ${Q} - 1,${this.nl()}`,J+=` length: ${Q},${this.nl()}`,J+=` index: ${A} + 1,${this.nl()}`,J+=` index0: ${A},${this.nl()}`,Y)J+=` parentloop: ${Y},${this.nl()}`,J+=` parent: ${Y}${this.nl()}`;else J+=` parentloop: null,${this.nl()}`,J+=` parent: null${this.nl()}`;J+=` };${this.nl()}`,J+=` const forloop = ${$};${this.nl()}`,J+=` const loop = ${$};${this.nl()}`,this.loopStack.push($);let X=this.compileNodes(B.body);if(J+=X.replace(new RegExp(`__ctx\\.${Z}`,"g"),Z),this.loopStack.pop(),J+=` }${this.nl()}`,B.else_.length>0)J+=` }${this.nl()}`;return J}compileSet(B){let K=this.compileExpr(B.value);return` const ${B.target} = ${K};${this.nl()}`}compileWith(B){let K=` {${this.nl()}`;this.pushScope();for(let{target:A,value:Q}of B.assignments){let $=this.compileExpr(Q);K+=` const ${A} = ${$};${this.nl()}`,this.addLocalVar(A)}return K+=this.compileNodes(B.body),K+=` }${this.nl()}`,this.popScope(),K}compileExpr(B){switch(B.type){case"Name":return this.compileName(B);case"Literal":return this.compileLiteral(B);case"Array":return this.compileArray(B);case"Object":return this.compileObject(B);case"BinaryOp":return this.compileBinaryOp(B);case"UnaryOp":return this.compileUnaryOp(B);case"Compare":return this.compileCompare(B);case"GetAttr":return this.compileGetAttr(B);case"GetItem":return this.compileGetItem(B);case"FilterExpr":return this.compileFilter(B);case"TestExpr":return this.compileTest(B);case"Conditional":return this.compileConditional(B);default:return"undefined"}}compileName(B){if(B.name==="true"||B.name==="True")return"true";if(B.name==="false"||B.name==="False")return"false";if(B.name==="none"||B.name==="None"||B.name==="null")return"null";if(B.name==="forloop"||B.name==="loop")return B.name;if(this.isLocalVar(B.name))return B.name;return`__ctx.${B.name}`}compileLiteral(B){if(typeof B.value==="string")return JSON.stringify(B.value);return String(B.value)}compileArray(B){return`[${B.elements.map((A)=>this.compileExpr(A)).join(", ")}]`}compileObject(B){return`{${B.pairs.map(({key:A,value:Q})=>{let $=this.compileExpr(A),Z=this.compileExpr(Q);return`[${$}]: ${Z}`}).join(", ")}}`}compileBinaryOp(B){let K=this.compileExpr(B.left),A=this.compileExpr(B.right);switch(B.operator){case"and":return`(${K} && ${A})`;case"or":return`(${K} || ${A})`;case"~":return`(String(${K}) + String(${A}))`;case"in":return`(Array.isArray(${A}) ? ${A}.includes(${K}) : String(${A}).includes(String(${K})))`;case"not in":return`!(Array.isArray(${A}) ? ${A}.includes(${K}) : String(${A}).includes(String(${K})))`;default:return`(${K} ${B.operator} ${A})`}}compileUnaryOp(B){let K=this.compileExpr(B.operand);switch(B.operator){case"not":return`!isTruthy(${K})`;case"-":return`-(${K})`;case"+":return`+(${K})`;default:return K}}compileCompare(B){let K=this.compileExpr(B.left);for(let{operator:A,right:Q}of B.ops){let $=this.compileExpr(Q);switch(A){case"==":case"===":K=`(${K} === ${$})`;break;case"!=":case"!==":K=`(${K} !== ${$})`;break;default:K=`(${K} ${A} ${$})`}}return K}compileGetAttr(B){return`${this.compileExpr(B.object)}?.${B.attribute}`}compileGetItem(B){let K=this.compileExpr(B.object),A=this.compileExpr(B.index);return`${K}?.[${A}]`}compileFilter(B){let K=this.compileExpr(B.node),A=B.args.map((Q)=>this.compileExpr(Q));switch(B.filter){case"upper":return`String(${K}).toUpperCase()`;case"lower":return`String(${K}).toLowerCase()`;case"title":return`String(${K}).replace(/\\b\\w/g, c => c.toUpperCase())`;case"trim":return`String(${K}).trim()`;case"length":return`(${K}?.length ?? Object.keys(${K} ?? {}).length)`;case"first":return`(${K})?.[0]`;case"last":return`(${K})?.[(${K})?.length - 1]`;case"default":return`((${K}) ?? ${A[0]??'""'})`;case"safe":return`{ __safe: true, value: String(${K}) }`;case"escape":case"e":return`escape(${K})`;case"join":return`(${K} ?? []).join(${A[0]??'""'})`;case"abs":return`Math.abs(${K})`;case"round":return A.length?`Number(${K}).toFixed(${A[0]})`:`Math.round(${K})`;case"int":return`parseInt(${K}, 10)`;case"float":return`parseFloat(${K})`;case"floatformat":return`Number(${K}).toFixed(${A[0]??1})`;case"filesizeformat":return`applyFilter('filesizeformat', ${K})`;default:let Q=A.length?", "+A.join(", "):"";return`applyFilter('${B.filter}', ${K}${Q})`}}compileTest(B){let K=this.compileExpr(B.node),A=B.args.map(($)=>this.compileExpr($)),Q=B.negated?"!":"";switch(B.test){case"defined":return`${Q}(${K} !== undefined)`;case"undefined":return`${Q}(${K} === undefined)`;case"none":return`${Q}(${K} === null)`;case"even":return`${Q}(${K} % 2 === 0)`;case"odd":return`${Q}(${K} % 2 !== 0)`;case"divisibleby":return`${Q}(${K} % ${A[0]} === 0)`;case"empty":return`${Q}((${K} == null) || (${K}.length === 0) || (Object.keys(${K}).length === 0))`;case"iterable":return`${Q}(Array.isArray(${K}) || typeof ${K} === 'string')`;case"number":return`${Q}(typeof ${K} === 'number' && !isNaN(${K}))`;case"string":return`${Q}(typeof ${K} === 'string')`;default:let $=A.length?", "+A.join(", "):"";return`${Q}applyTest('${B.test}', ${K}${$})`}}compileConditional(B){let K=this.compileExpr(B.test),A=this.compileExpr(B.trueExpr),Q=this.compileExpr(B.falseExpr);return`(isTruthy(${K}) ? ${A} : ${Q})`}isMarkedSafe(B){if(B.type==="FilterExpr")return B.filter==="safe";return!1}genVar(B){return`__${B}${this.varCounter++}`}nl(){return this.options.minify?"":`
36
+ `}}function g(B,K){return new MB(K).flatten(B)}function x(B){return new GB().check(B)}class MB{loader;maxDepth;blocks=new Map;depth=0;constructor(B){this.loader=B.loader,this.maxDepth=B.maxDepth??10}flatten(B){return this.blocks.clear(),this.depth=0,this.processTemplate(B)}processTemplate(B,K=!0){if(this.depth>this.maxDepth)throw Error(`Maximum template inheritance depth (${this.maxDepth}) exceeded`);this.collectBlocks(B.body,K);let A=this.findExtends(B.body);if(A){let Q=this.getStaticTemplateName(A.template),$=this.loader.load(Q),Z=this.loader.parse($);this.depth++;let U=this.processTemplate(Z,!1);return this.depth--,{type:"Template",body:this.replaceBlocks(U.body),line:B.line,column:B.column}}return{type:"Template",body:this.processNodes(B.body),line:B.line,column:B.column}}collectBlocks(B,K=!0){for(let A of B){if(A.type==="Block"){let Q=A;if(K||!this.blocks.has(Q.name))this.blocks.set(Q.name,Q)}this.collectBlocksFromNode(A,K)}}collectBlocksFromNode(B,K=!0){switch(B.type){case"If":{let A=B;this.collectBlocks(A.body,K);for(let Q of A.elifs)this.collectBlocks(Q.body,K);this.collectBlocks(A.else_,K);break}case"For":{let A=B;this.collectBlocks(A.body,K),this.collectBlocks(A.else_,K);break}case"With":{let A=B;this.collectBlocks(A.body,K);break}case"Block":{let A=B;this.collectBlocks(A.body,K);break}}}findExtends(B){for(let K of B)if(K.type==="Extends")return K;return null}processNodes(B){let K=[];for(let A of B){if(A.type==="Extends")continue;if(A.type==="Include"){let $=A,Z=this.inlineInclude($);K.push(...Z);continue}if(A.type==="Block"){let $=A,Z=this.blocks.get($.name);if(Z&&Z!==$)K.push(...this.processNodes(Z.body));else K.push(...this.processNodes($.body));continue}let Q=this.processNode(A);if(Q)K.push(Q)}return K}processNode(B){switch(B.type){case"If":{let K=B;return{...K,body:this.processNodes(K.body),elifs:K.elifs.map((A)=>({test:A.test,body:this.processNodes(A.body)})),else_:this.processNodes(K.else_)}}case"For":{let K=B;return{...K,body:this.processNodes(K.body),else_:this.processNodes(K.else_)}}case"With":{let K=B;return{...K,body:this.processNodes(K.body)}}default:return B}}replaceBlocks(B){return this.processNodes(B)}inlineInclude(B){let K=this.getStaticTemplateName(B.template);try{let A=this.loader.load(K),Q=this.loader.parse(A);this.depth++;let $=this.processTemplate(Q);if(this.depth--,B.context&&Object.keys(B.context).length>0)return[{type:"With",assignments:Object.entries(B.context).map(([U,Y])=>({target:U,value:Y})),body:$.body,line:B.line,column:B.column}];return $.body}catch(A){if(B.ignoreMissing)return[];throw A}}getStaticTemplateName(B){if(B.type==="Literal"){let K=B;if(typeof K.value==="string")return K.value}throw Error(`AOT compilation requires static template names. Found dynamic expression at line ${B.line}. Use Environment.render() for dynamic template names.`)}}class GB{check(B){return this.checkNodes(B.body)}checkNodes(B){for(let K of B){let A=this.checkNode(K);if(!A.canFlatten)return A}return{canFlatten:!0}}checkNode(B){switch(B.type){case"Extends":{let K=B;if(!this.isStaticName(K.template))return{canFlatten:!1,reason:`Dynamic extends at line ${B.line} - use static string literal`};break}case"Include":{let K=B;if(!this.isStaticName(K.template))return{canFlatten:!1,reason:`Dynamic include at line ${B.line} - use static string literal`};break}case"If":{let K=B,A=this.checkNodes(K.body);if(!A.canFlatten)return A;for(let Q of K.elifs)if(A=this.checkNodes(Q.body),!A.canFlatten)return A;if(A=this.checkNodes(K.else_),!A.canFlatten)return A;break}case"For":{let K=B,A=this.checkNodes(K.body);if(!A.canFlatten)return A;if(A=this.checkNodes(K.else_),!A.canFlatten)return A;break}case"With":{let K=B,A=this.checkNodes(K.body);if(!A.canFlatten)return A;break}case"Block":{let K=B,A=this.checkNodes(K.body);if(!A.canFlatten)return A;break}}return{canFlatten:!0}}isStaticName(B){return B.type==="Literal"&&typeof B.value==="string"}}class i{data;constructor(){this.data={startTime:performance.now(),templateChain:[],mode:"runtime",isAsync:!1,contextKeys:[],contextSnapshot:{},filtersUsed:new Map,testsUsed:new Map,cacheHits:0,cacheMisses:0,queries:[],queryStats:{count:0,totalDuration:0,slowCount:0,n1Count:0,queryCounts:new Map},warnings:[]}}startLexer(){this.data._lexerStart=performance.now()}endLexer(){if(this.data._lexerStart)this.data.lexerTime=performance.now()-this.data._lexerStart}startParser(){this.data._parserStart=performance.now()}endParser(){if(this.data._parserStart)this.data.parserTime=performance.now()-this.data._parserStart}startRender(){this.data._renderStart=performance.now()}endRender(){if(this.data._renderStart)this.data.renderTime=performance.now()-this.data._renderStart;this.data.endTime=performance.now(),this.data.totalTime=this.data.endTime-this.data.startTime}addTemplate(B,K,A){if(this.data.templateChain.push({name:B,type:K,parent:A}),K==="root")this.data.rootTemplate=B}setMode(B){this.data.mode=B}setAsync(B){this.data.isAsync=B}captureContext(B){this.data.contextKeys=Object.keys(B);for(let[K,A]of Object.entries(B))this.data.contextSnapshot[K]=this.captureValue(A)}captureValue(B,K=0){let A=this.getType(B),Q=this.getPreview(B),$=this.isExpandable(B),Z={type:A,preview:Q,value:B,expandable:$};if($&&K<3){if(Z.children={},Array.isArray(B))B.forEach((U,Y)=>{Z.children[String(Y)]=this.captureValue(U,K+1)});else if(typeof B==="object"&&B!==null)for(let[U,Y]of Object.entries(B))Z.children[U]=this.captureValue(Y,K+1)}return Z}isExpandable(B){if(B===null||B===void 0)return!1;if(Array.isArray(B))return B.length>0;if(typeof B==="object")return Object.keys(B).length>0;return!1}getType(B){if(B===null)return"null";if(B===void 0)return"undefined";if(Array.isArray(B))return`Array(${B.length})`;if(B instanceof Date)return"Date";if(typeof B==="object")return"Object";return typeof B}getPreview(B,K=50){if(B===null)return"null";if(B===void 0)return"undefined";if(typeof B==="string")return B.length>K?`"${B.slice(0,K)}..."`:`"${B}"`;if(typeof B==="number"||typeof B==="boolean")return String(B);if(Array.isArray(B)){if(B.length===0)return"[]";if(B.length<=3)return`[${B.map((Q)=>this.getPreview(Q,15)).join(", ")}]`;return`[${this.getPreview(B[0],15)}, ... +${B.length-1}]`}if(B instanceof Date)return B.toISOString();if(typeof B==="object"){let A=Object.keys(B);if(A.length===0)return"{}";if(A.length<=2)return`{ ${A.join(", ")} }`;return`{ ${A.slice(0,2).join(", ")}, ... +${A.length-2} }`}if(typeof B==="function")return"function()";return String(B)}recordFilter(B){this.data.filtersUsed.set(B,(this.data.filtersUsed.get(B)||0)+1)}recordTest(B){this.data.testsUsed.set(B,(this.data.testsUsed.get(B)||0)+1)}recordCacheHit(){this.data.cacheHits++}recordCacheMiss(){this.data.cacheMisses++}addWarning(B){this.data.warnings.push(B)}recordQuery(B){let K=this.normalizeQuery(B.sql),A=this.data.queryStats.queryCounts.get(K)||0;this.data.queryStats.queryCounts.set(K,A+1);let Q=A>=2,$={...B,timestamp:performance.now(),isN1:Q};if(this.data.queries.push($),this.data.queryStats.count++,this.data.queryStats.totalDuration+=B.duration,B.duration>100)this.data.queryStats.slowCount++;if(Q&&A===2)this.data.queryStats.n1Count++,this.addWarning(`N+1 query detected: ${K.slice(0,50)}...`)}normalizeQuery(B){return B.replace(/\s+/g," ").replace(/= \?/g,"= ?").replace(/= \$\d+/g,"= ?").replace(/= '\w+'/g,"= '?'").replace(/= \d+/g,"= ?").replace(/IN \([^)]+\)/gi,"IN (?)").trim()}getQueryStats(){return this.data.queryStats}getData(){return this.data}getSummary(){return{totalTime:this.data.totalTime||0,templateCount:this.data.templateChain.length,filterCount:this.data.filtersUsed.size,mode:this.data.mode}}}var k=null;function D(){return k=new i,k}function _(){if(k){let B=k.getData();return k=null,B}return null}var kA={position:"bottom",height:300,width:400,open:!1,dark:!0};function L(B,K={}){let A={...kA,...K},Q=`binja-dbg-${Date.now()}`,$=A.dark?yA:TA;return`
37
37
  <!-- Binja Debug Panel -->
38
- <div id="${$}" class="binja-devtools" data-position="${A.position}" data-open="${A.open}">
39
- <style>${gA($,Q,A)}</style>
40
- ${xA($,B,Q,A)}
41
- <script>${rA($,B,A)}</script>
38
+ <div id="${Q}" class="binja-devtools" data-position="${A.position}" data-open="${A.open}">
39
+ <style>${gA(Q,$,A)}</style>
40
+ ${xA(Q,B,$,A)}
41
+ <script>${rA(Q,B,A)}</script>
42
42
  </div>
43
43
  <!-- /Binja Debug Panel -->
44
44
  `}var yA={bg:"#1e1e1e",bgPanel:"#252526",bgHover:"#2a2d2e",bgActive:"#37373d",border:"#3c3c3c",text:"#cccccc",textSecondary:"#969696",textMuted:"#6e6e6e",accent:"#0078d4",accentHover:"#1c86d8",success:"#4ec9b0",warning:"#dcdcaa",error:"#f14c4c",info:"#75beff",string:"#ce9178",number:"#b5cea8",keyword:"#569cd6"},TA={bg:"#f3f3f3",bgPanel:"#ffffff",bgHover:"#e8e8e8",bgActive:"#d4d4d4",border:"#d4d4d4",text:"#1e1e1e",textSecondary:"#616161",textMuted:"#a0a0a0",accent:"#0078d4",accentHover:"#106ebe",success:"#16825d",warning:"#bf8803",error:"#cd3131",info:"#0078d4",string:"#a31515",number:"#098658",keyword:"#0000ff"};function gA(B,K,A){return`
@@ -171,17 +171,17 @@ ${xA($,B,Q,A)}
171
171
  /* Empty State */
172
172
  #${B} .empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); font-size: 12px; }
173
173
  #${B} .empty-state svg { width: 32px; height: 32px; margin-bottom: 8px; opacity: 0.5; }
174
- `}var H={logo:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg>',close:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 6L6 18M6 6l12 12"/></svg>',minimize:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M5 12h14"/></svg>',dock:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 15h18"/></svg>',dockRight:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M15 3v18"/></svg>',popup:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v6h6"/></svg>',arrow:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>',perf:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/></svg>',context:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 16V8a2 2 0 00-1-1.73l-7-4a2 2 0 00-2 0l-7 4A2 2 0 003 8v8a2 2 0 001 1.73l7 4a2 2 0 002 0l7-4A2 2 0 0021 16z"/></svg>',template:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><path d="M14 2v6h6"/></svg>',filter:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"/></svg>',database:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg>',cache:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2a10 10 0 1010 10H12V2z"/><path d="M12 2a10 10 0 00-8.66 15"/></svg>',warning:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>'};function xA(B,K,A,$){let Q=(K.totalTime||0).toFixed(1),O=K.queries?.length||0,U=K.warnings.length>0||K.queryStats?.n1Count>0,Z=[{id:"perf",icon:H.perf,label:"Performance",count:`${Q}ms`},{id:"context",icon:H.context,label:"Context",count:Object.keys(K.contextSnapshot).length||null},{id:"templates",icon:H.template,label:"Templates",count:K.templateChain.length||null},{id:"filters",icon:H.filter,label:"Filters",count:K.filtersUsed.size||null},{id:"queries",icon:H.database,label:"Queries",count:O||null,warn:K.queryStats?.n1Count>0},{id:"cache",icon:H.cache,label:"Cache",count:K.cacheHits+K.cacheMisses||null},{id:"warnings",icon:H.warning,label:"Warnings",count:K.warnings.length||null,warn:U}].map((J,X)=>{let M=J.count!==null?`<span class="count${J.warn?" warn":""}">${J.count}</span>`:"";return`<button class="devtools-tab${X===0?" active":""}" data-tab="${J.id}">${J.icon}${J.label}${M}</button>`}).join("");return`
174
+ `}var H={logo:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg>',close:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 6L6 18M6 6l12 12"/></svg>',minimize:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M5 12h14"/></svg>',dock:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 15h18"/></svg>',dockRight:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M15 3v18"/></svg>',popup:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v6h6"/></svg>',arrow:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 18l6-6-6-6"/></svg>',perf:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/></svg>',context:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 16V8a2 2 0 00-1-1.73l-7-4a2 2 0 00-2 0l-7 4A2 2 0 003 8v8a2 2 0 001 1.73l7 4a2 2 0 002 0l7-4A2 2 0 0021 16z"/></svg>',template:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><path d="M14 2v6h6"/></svg>',filter:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"/></svg>',database:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg>',cache:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2a10 10 0 1010 10H12V2z"/><path d="M12 2a10 10 0 00-8.66 15"/></svg>',warning:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>'};function xA(B,K,A,Q){let $=(K.totalTime||0).toFixed(1),Z=K.queries?.length||0,U=K.warnings.length>0||K.queryStats?.n1Count>0,O=[{id:"perf",icon:H.perf,label:"Performance",count:`${$}ms`},{id:"context",icon:H.context,label:"Context",count:Object.keys(K.contextSnapshot).length||null},{id:"templates",icon:H.template,label:"Templates",count:K.templateChain.length||null},{id:"filters",icon:H.filter,label:"Filters",count:K.filtersUsed.size||null},{id:"queries",icon:H.database,label:"Queries",count:Z||null,warn:K.queryStats?.n1Count>0},{id:"cache",icon:H.cache,label:"Cache",count:K.cacheHits+K.cacheMisses||null},{id:"warnings",icon:H.warning,label:"Warnings",count:K.warnings.length||null,warn:U}].map((J,X)=>{let M=J.count!==null?`<span class="count${J.warn?" warn":""}">${J.count}</span>`:"";return`<button class="devtools-tab${X===0?" active":""}" data-tab="${J.id}">${J.icon}${J.label}${M}</button>`}).join("");return`
175
175
  <button class="devtools-toggle" onclick="document.getElementById('${B}').dataset.open='true'">
176
176
  ${H.logo}
177
177
  <span>Binja</span>
178
- <span class="badge">${Q}ms</span>
178
+ <span class="badge">${$}ms</span>
179
179
  </button>
180
180
 
181
181
  <div class="devtools-panel">
182
182
  <div class="devtools-resize"></div>
183
183
  <div class="devtools-toolbar">
184
- <div class="devtools-tabs">${Z}</div>
184
+ <div class="devtools-tabs">${O}</div>
185
185
  <div class="devtools-actions">
186
186
  <button class="devtools-btn" title="Dock to bottom" data-dock="bottom">${H.dock}</button>
187
187
  <button class="devtools-btn" title="Dock to right" data-dock="right">${H.dockRight}</button>
@@ -192,13 +192,13 @@ ${xA($,B,Q,A)}
192
192
  <div class="devtools-content">
193
193
  ${mA(K)}
194
194
  ${pA(K)}
195
- ${cA(K)}
195
+ ${vA(K)}
196
196
  ${iA(K)}
197
- ${sA(K)}
198
197
  ${dA(K)}
198
+ ${sA(K)}
199
199
  ${uA(K)}
200
200
  </div>
201
- </div>`}function mA(B){let K=B.totalTime||0.01,A=B.lexerTime||0,$=B.parserTime||0,Q=B.renderTime||0,O=B.mode==="aot"?"AOT":"Runtime";return`
201
+ </div>`}function mA(B){let K=B.totalTime||0.01,A=B.lexerTime||0,Q=B.parserTime||0,$=B.renderTime||0,Z=B.mode==="aot"?"AOT":"Runtime";return`
202
202
  <div class="devtools-pane active" data-pane="perf">
203
203
  <div class="perf-grid">
204
204
  <div class="perf-card">
@@ -206,7 +206,7 @@ ${xA($,B,Q,A)}
206
206
  <div class="perf-card-label">Total Time</div>
207
207
  </div>
208
208
  <div class="perf-card">
209
- <div class="perf-card-value" style="color:var(--accent)">${O}</div>
209
+ <div class="perf-card-value" style="color:var(--accent)">${Z}</div>
210
210
  <div class="perf-card-label">Mode</div>
211
211
  </div>
212
212
  <div class="perf-card">
@@ -226,34 +226,34 @@ ${xA($,B,Q,A)}
226
226
  </div>
227
227
  <div class="perf-row">
228
228
  <span class="perf-row-label">Parser</span>
229
- <div class="perf-row-bar"><div class="perf-row-fill parser" style="width:${$/K*100}%"></div></div>
230
- <span class="perf-row-value">${$.toFixed(2)}ms</span>
229
+ <div class="perf-row-bar"><div class="perf-row-fill parser" style="width:${Q/K*100}%"></div></div>
230
+ <span class="perf-row-value">${Q.toFixed(2)}ms</span>
231
231
  </div>
232
232
  <div class="perf-row">
233
233
  <span class="perf-row-label">Render</span>
234
- <div class="perf-row-bar"><div class="perf-row-fill render" style="width:${Q/K*100}%"></div></div>
235
- <span class="perf-row-value">${Q.toFixed(2)}ms</span>
234
+ <div class="perf-row-bar"><div class="perf-row-fill render" style="width:${$/K*100}%"></div></div>
235
+ <span class="perf-row-value">${$.toFixed(2)}ms</span>
236
236
  </div>
237
237
  </div>
238
- </div>`}function pA(B){let K=Object.keys(B.contextSnapshot);if(K.length===0)return`<div class="devtools-pane" data-pane="context"><div class="empty-state">${H.context}<span>No context variables</span></div></div>`;return`<div class="devtools-pane" data-pane="context"><div class="tree">${K.map(($)=>FB($,B.contextSnapshot[$])).join("")}</div></div>`}function FB(B,K){let A=K.expandable&&K.children&&Object.keys(K.children).length>0,$=A?`<span class="tree-arrow">${H.arrow}</span>`:'<span class="tree-arrow" style="visibility:hidden">${icons.arrow}</span>',Q=A?"expandable":"",O=vA(K.type),U="";if(A&&K.children)U=`<div class="tree-children">${Object.entries(K.children).map(([Y,Z])=>FB(Y,Z)).join("")}</div>`;return`
238
+ </div>`}function pA(B){let K=Object.keys(B.contextSnapshot);if(K.length===0)return`<div class="devtools-pane" data-pane="context"><div class="empty-state">${H.context}<span>No context variables</span></div></div>`;return`<div class="devtools-pane" data-pane="context"><div class="tree">${K.map((Q)=>FB(Q,B.contextSnapshot[Q])).join("")}</div></div>`}function FB(B,K){let A=K.expandable&&K.children&&Object.keys(K.children).length>0,Q=A?`<span class="tree-arrow">${H.arrow}</span>`:'<span class="tree-arrow" style="visibility:hidden">${icons.arrow}</span>',$=A?"expandable":"",Z=cA(K.type),U="";if(A&&K.children)U=`<div class="tree-children">${Object.entries(K.children).map(([Y,O])=>FB(Y,O)).join("")}</div>`;return`
239
239
  <div class="tree-item">
240
- <div class="tree-row ${Q}">
241
- ${$}
240
+ <div class="tree-row ${$}">
241
+ ${Q}
242
242
  <span class="tree-key">${S(B)}</span>
243
243
  <span class="tree-colon">:</span>
244
- <span class="tree-value ${O}">${S(K.preview)}</span>
244
+ <span class="tree-value ${Z}">${S(K.preview)}</span>
245
245
  <span class="tree-type">${K.type}</span>
246
246
  </div>
247
247
  ${U}
248
- </div>`}function vA(B){if(B==="string")return"string";if(B==="number"||B==="integer"||B==="float")return"number";if(B==="null"||B==="undefined")return"null";return""}function cA(B){if(B.templateChain.length===0)return`<div class="devtools-pane" data-pane="templates"><div class="empty-state">${H.template}<span>No templates loaded</span></div></div>`;return`<div class="devtools-pane" data-pane="templates"><div class="template-list">${B.templateChain.map((A)=>`
248
+ </div>`}function cA(B){if(B==="string")return"string";if(B==="number"||B==="integer"||B==="float")return"number";if(B==="null"||B==="undefined")return"null";return""}function vA(B){if(B.templateChain.length===0)return`<div class="devtools-pane" data-pane="templates"><div class="empty-state">${H.template}<span>No templates loaded</span></div></div>`;return`<div class="devtools-pane" data-pane="templates"><div class="template-list">${B.templateChain.map((A)=>`
249
249
  <div class="template-item">
250
250
  <span class="template-icon">${H.template}</span>
251
251
  <span class="template-name">${S(A.name)}</span>
252
252
  <span class="template-badge ${A.type}">${A.type}</span>
253
253
  </div>
254
- `).join("")}</div></div>`}function iA(B){let K=Array.from(B.filtersUsed.entries());if(K.length===0)return`<div class="devtools-pane" data-pane="filters"><div class="empty-state">${H.filter}<span>No filters used</span></div></div>`;return`<div class="devtools-pane" data-pane="filters"><div class="filter-grid">${K.map(([$,Q])=>`
255
- <span class="filter-chip">${S($)}<span class="filter-count">\xD7${Q}</span></span>
256
- `).join("")}</div></div>`}function sA(B){if(!B.queries||B.queries.length===0)return`<div class="devtools-pane" data-pane="queries"><div class="empty-state">${H.database}<span>No queries recorded</span></div></div>`;let K=B.queryStats,A=`
254
+ `).join("")}</div></div>`}function iA(B){let K=Array.from(B.filtersUsed.entries());if(K.length===0)return`<div class="devtools-pane" data-pane="filters"><div class="empty-state">${H.filter}<span>No filters used</span></div></div>`;return`<div class="devtools-pane" data-pane="filters"><div class="filter-grid">${K.map(([Q,$])=>`
255
+ <span class="filter-chip">${S(Q)}<span class="filter-count">\xD7${$}</span></span>
256
+ `).join("")}</div></div>`}function dA(B){if(!B.queries||B.queries.length===0)return`<div class="devtools-pane" data-pane="queries"><div class="empty-state">${H.database}<span>No queries recorded</span></div></div>`;let K=B.queryStats,A=`
257
257
  <div class="queries-stats">
258
258
  <div class="queries-stat">
259
259
  <div class="queries-stat-value">${K.count}</div>
@@ -271,16 +271,16 @@ ${xA($,B,Q,A)}
271
271
  <div class="queries-stat-value ${K.n1Count>0?"error":""}">${K.n1Count}</div>
272
272
  <div class="queries-stat-label">N+1</div>
273
273
  </div>
274
- </div>`,$=B.queries.map((Q)=>{let O=Q.duration>100,U=["query-item",Q.isN1?"n1":"",O?"slow":""].filter(Boolean).join(" "),Y=Q.isN1?'<span class="query-badge n1">N+1</span>':"",Z=Q.source?`<span class="query-source">${S(Q.source)}</span>`:"",J=Q.rows!==void 0?`<span class="query-rows">${Q.rows} rows</span>`:"";return`
274
+ </div>`,Q=B.queries.map(($)=>{let Z=$.duration>100,U=["query-item",$.isN1?"n1":"",Z?"slow":""].filter(Boolean).join(" "),Y=$.isN1?'<span class="query-badge n1">N+1</span>':"",O=$.source?`<span class="query-source">${S($.source)}</span>`:"",J=$.rows!==void 0?`<span class="query-rows">${$.rows} rows</span>`:"";return`
275
275
  <div class="${U}">
276
276
  <div class="query-header">
277
- <span class="query-sql" title="${S(Q.sql)}">${S(Q.sql)}</span>
277
+ <span class="query-sql" title="${S($.sql)}">${S($.sql)}</span>
278
278
  <div class="query-meta">
279
- ${Y}${Z}${J}
280
- <span class="query-time ${O?"slow":""}">${Q.duration.toFixed(1)}ms</span>
279
+ ${Y}${O}${J}
280
+ <span class="query-time ${Z?"slow":""}">${$.duration.toFixed(1)}ms</span>
281
281
  </div>
282
282
  </div>
283
- </div>`}).join("");return`<div class="devtools-pane" data-pane="queries">${A}<div class="query-list">${$}</div></div>`}function dA(B){let K=B.cacheHits+B.cacheMisses;if(K===0)return`<div class="devtools-pane" data-pane="cache"><div class="empty-state">${H.cache}<span>No cache activity</span></div></div>`;let A=(B.cacheHits/K*100).toFixed(0);return`
283
+ </div>`}).join("");return`<div class="devtools-pane" data-pane="queries">${A}<div class="query-list">${Q}</div></div>`}function sA(B){let K=B.cacheHits+B.cacheMisses;if(K===0)return`<div class="devtools-pane" data-pane="cache"><div class="empty-state">${H.cache}<span>No cache activity</span></div></div>`;let A=(B.cacheHits/K*100).toFixed(0);return`
284
284
  <div class="devtools-pane" data-pane="cache">
285
285
  <div class="cache-stats">
286
286
  <div class="cache-stat">
@@ -368,5 +368,5 @@ ${xA($,B,Q,A)}
368
368
  document.body.style.cursor = '';
369
369
  });
370
370
  }
371
- })();`}function S(B){return String(B).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}async function IB(B,K,A={},$={}){let Q=D();Q.captureContext(A),Q.addTemplate(K,"root"),Q.setMode("runtime"),Q.startRender();let O=await B.render(K,A);Q.endRender();let U=_();if($.htmlOnly!==!1){if(!(O.includes("<html")||O.includes("<body")||O.includes("<!DOCTYPE")))return O}let Y=L(U,$.panel);if(O.includes("</body>"))return O.replace("</body>",`${Y}</body>`);return O+Y}async function RB(B,K,A={},$={}){let Q=D();Q.captureContext(A),Q.setMode("runtime"),Q.startRender();let O=await B.renderString(K,A);Q.endRender();let U=_();if($.htmlOnly!==!1){if(!(O.includes("<html")||O.includes("<body")))return O}let Y=L(U,$.panel);if(O.includes("</body>"))return O.replace("</body>",`${Y}</body>`);return O+Y}function nA(B,K={}){return{async render(A,$={}){return IB(B,A,$,K)},async renderString(A,$={}){return RB(B,A,$,K)}}}function oA(B,K={}){return{hono(){return async(A,$)=>{if(await $(),!(A.res.headers.get("content-type")||"").includes("text/html"))return;let O=await A.res.text(),U=D();U.captureContext({}),U.setMode("runtime"),U.endRender();let Y=_(),Z=L(Y,K.panel),J=O.includes("</body>")?O.replace("</body>",`${Z}</body>`):O+Z;A.res=new Response(J,{status:A.res.status,headers:A.res.headers})}},express(){return(A,$,Q)=>{let O=$.send.bind($);$.send=(U)=>{if(!($.get("Content-Type")||"").includes("text/html")||typeof U!=="string")return O(U);let Z=D();Z.captureContext({}),Z.setMode("runtime"),Z.endRender();let J=_(),X=L(J,K.panel),M=U.includes("</body>")?U.replace("</body>",`${X}</body>`):U+X;return O(M)},Q()}}}}import*as V from"path";var HB=/<[^>]+>|:[a-zA-Z_]+|\(\?P<[^>]+>\[[^\]]+\]\)/g;class s{options;runtime;templateCache=new Map;routes=new Map;cacheHits=0;cacheMisses=0;constructor(B={}){this.options={templates:B.templates??"./templates",autoescape:B.autoescape??!0,filters:B.filters??{},globals:B.globals??{},urlResolver:B.urlResolver??this.defaultUrlResolver.bind(this),staticResolver:B.staticResolver??this.defaultStaticResolver.bind(this),cache:B.cache??!0,cacheMaxSize:B.cacheMaxSize??100,extensions:B.extensions??[".html",".jinja",".jinja2",""],debug:B.debug??!1,debugOptions:B.debugOptions??{},timezone:B.timezone??void 0},this.runtime=new z({autoescape:this.options.autoescape,filters:this.options.filters,globals:this.options.globals,urlResolver:this.options.urlResolver,staticResolver:this.options.staticResolver,templateLoader:this.loadTemplate.bind(this),timezone:this.options.timezone})}async render(B,K={}){if(this.options.debug)return this.renderWithDebug(B,K);let A=await this.loadTemplate(B);return this.runtime.render(A,K)}async renderString(B,K={}){if(this.options.debug)return this.renderStringWithDebug(B,K);let A=this.compile(B);return this.runtime.render(A,K)}async renderWithDebug(B,K){let A=D();A.captureContext(K),A.addTemplate(B,"root"),A.setMode("runtime"),A.startRender();let $=await this.loadTemplate(B),Q=this.runtime.render($,K);if(Q&&typeof Q.then==="function")Q=await Q;A.endRender();let O=_();return this.injectDebugPanel(String(Q||""),O)}async renderStringWithDebug(B,K){let A=D();A.captureContext(K),A.setMode("runtime"),A.startRender();let $=this.compile(B),Q=this.runtime.render($,K);if(Q&&typeof Q.then==="function")Q=await Q;A.endRender();let O=_();return this.injectDebugPanel(String(Q||""),O)}injectDebugPanel(B,K){if(!B||typeof B!=="string")return B||"";if(!(B.includes("<html")||B.includes("<body")||B.includes("<!DOCTYPE")))return B;let $=L(K,this.options.debugOptions);if(B.includes("</body>"))return B.replace("</body>",`${$}</body>`);return B+$}compile(B){let A=new C(B).tokenize();return new N(A,B).parse()}async loadTemplate(B){if(this.options.cache&&this.templateCache.has(B)){this.cacheHits++;let Q=this.templateCache.get(B);return this.templateCache.delete(B),this.templateCache.set(B,Q),Q}this.cacheMisses++;let K=await this.resolveTemplatePath(B);if(!K)throw Error(`Template not found: ${B}`);let A=await Bun.file(K).text(),$=this.compile(A);if(this.options.cache){while(this.templateCache.size>=this.options.cacheMaxSize){let Q=this.templateCache.keys().next().value;if(Q)this.templateCache.delete(Q)}this.templateCache.set(B,$)}return $}clearCache(){this.templateCache.clear(),this.cacheHits=0,this.cacheMisses=0}cacheSize(){return this.templateCache.size}cacheStats(){let B=this.cacheHits+this.cacheMisses;return{size:this.templateCache.size,maxSize:this.options.cacheMaxSize,hits:this.cacheHits,misses:this.cacheMisses,hitRate:B>0?this.cacheHits/B*100:0}}addFilter(B,K){this.runtime.addFilter(B,K)}addGlobal(B,K){this.runtime.addGlobal(B,K)}addUrl(B,K){this.routes.set(B,K)}addUrls(B){for(let[K,A]of Object.entries(B))this.routes.set(K,A)}async resolveTemplatePath(B){let K=V.resolve(this.options.templates,B);for(let A of this.options.extensions){let $=K+A;if(await Bun.file($).exists())return $}return null}defaultUrlResolver(B,K,A){let $=this.routes.get(B);if(!$)return console.warn(`URL pattern not found: ${B}`),`#${B}`;let Q=$;for(let U in A){let Y=encodeURIComponent(String(A[U]));Q=Q.replaceAll(`:${U}`,Y),Q=Q.replaceAll(`<${U}>`,Y),Q=Q.replaceAll(`(?P<${U}>[^/]+)`,Y)}let O=0;return HB.lastIndex=0,Q=Q.replace(HB,()=>{if(O<K.length)return encodeURIComponent(String(K[O++]));return""}),Q}defaultStaticResolver(B){return`/static/${B}`}}async function Q8(B,K={},A={}){return new s(A).renderString(B,K)}function O8(B,K={}){let $=new s(K).compile(B),Q=new z({autoescape:K.autoescape??!0,filters:K.filters??{},globals:K.globals??{},urlResolver:K.urlResolver,staticResolver:K.staticResolver,templateLoader:async()=>$});return{async render(O={}){return Q.render($,O)}}}function Z8(B,K={}){let $=new C(B).tokenize(),O=new N($,B).parse();return c(O,K)}async function J8(B,K){let A=K.extensions??[".html",".jinja",".jinja2",""],$=V.resolve(K.templates),Q={load(J){let X=V.resolve($,J);for(let M of A){let G=X+M,R=Bun.file(G),F=d("fs");if(F.existsSync(G))return F.readFileSync(G,"utf-8")}throw Error(`Template not found: ${J}`)},parse(J){let M=new C(J).tokenize();return new N(M,J).parse()}},O=Q.load(B),U=Q.parse(O),Y=x(U);if(!Y.canFlatten)throw Error(`Cannot compile template with AOT: ${Y.reason}
372
- Use Environment.render() for dynamic template names.`);let Z=g(U,{loader:Q});return c(Z,K)}async function Y8(B,K){let A=K.extensions??[".html",".jinja",".jinja2",""],$=V.resolve(K.templates),Q=d("fs"),O={load(X){let M=V.resolve($,X);for(let G of A){let R=M+G;if(Q.existsSync(R))return Q.readFileSync(R,"utf-8")}throw Error(`Template not found: ${X}`)},parse(X){let G=new C(X).tokenize();return new N(G,X).parse()}},U=O.load(B),Y=O.parse(U),Z=x(Y);if(!Z.canFlatten)throw Error(`Cannot compile template with AOT: ${Z.reason}`);let J=g(Y,{loader:O});return T(J,K)}function U8(B,K={}){let $=new C(B).tokenize(),O=new N($,B).parse();return T(O,K)}export{IB as renderWithDebug,RB as renderStringWithDebug,Q8 as render,L as generateDebugPanel,g as flattenTemplate,oA as debugMiddleware,nA as createDebugRenderer,Y8 as compileWithInheritanceToCode,J8 as compileWithInheritance,U8 as compileToCode,Z8 as compile,x as canFlatten,f as builtinTests,h as builtinFilters,b as TokenType,P as TemplateSyntaxError,y as TemplateRuntimeError,r as TemplateError,O8 as Template,z as Runtime,N as Parser,C as Lexer,s as Environment,w as Context};
371
+ })();`}function S(B){return String(B).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}async function IB(B,K,A={},Q={}){let $=D();$.captureContext(A),$.addTemplate(K,"root"),$.setMode("runtime"),$.startRender();let Z=await B.render(K,A);$.endRender();let U=_();if(Q.htmlOnly!==!1){if(!(Z.includes("<html")||Z.includes("<body")||Z.includes("<!DOCTYPE")))return Z}let Y=L(U,Q.panel);if(Z.includes("</body>"))return Z.replace("</body>",`${Y}</body>`);return Z+Y}async function RB(B,K,A={},Q={}){let $=D();$.captureContext(A),$.setMode("runtime"),$.startRender();let Z=await B.renderString(K,A);$.endRender();let U=_();if(Q.htmlOnly!==!1){if(!(Z.includes("<html")||Z.includes("<body")))return Z}let Y=L(U,Q.panel);if(Z.includes("</body>"))return Z.replace("</body>",`${Y}</body>`);return Z+Y}function lA(B,K={}){return{async render(A,Q={}){return IB(B,A,Q,K)},async renderString(A,Q={}){return RB(B,A,Q,K)}}}function oA(B,K={}){return{hono(){return async(A,Q)=>{if(await Q(),!(A.res.headers.get("content-type")||"").includes("text/html"))return;let Z=await A.res.text(),U=D();U.captureContext({}),U.setMode("runtime"),U.endRender();let Y=_(),O=L(Y,K.panel),J=Z.includes("</body>")?Z.replace("</body>",`${O}</body>`):Z+O;A.res=new Response(J,{status:A.res.status,headers:A.res.headers})}},express(){return(A,Q,$)=>{let Z=Q.send.bind(Q);Q.send=(U)=>{if(!(Q.get("Content-Type")||"").includes("text/html")||typeof U!=="string")return Z(U);let O=D();O.captureContext({}),O.setMode("runtime"),O.endRender();let J=_(),X=L(J,K.panel),M=U.includes("</body>")?U.replace("</body>",`${X}</body>`):U+X;return Z(M)},$()}}}}import*as V from"path";var HB=/<[^>]+>|:[a-zA-Z_]+|\(\?P<[^>]+>\[[^\]]+\]\)/g;class d{options;runtime;templateCache=new Map;routes=new Map;cacheHits=0;cacheMisses=0;constructor(B={}){this.options={templates:B.templates??"./templates",autoescape:B.autoescape??!0,filters:B.filters??{},globals:B.globals??{},urlResolver:B.urlResolver??this.defaultUrlResolver.bind(this),staticResolver:B.staticResolver??this.defaultStaticResolver.bind(this),cache:B.cache??!0,cacheMaxSize:B.cacheMaxSize??100,extensions:B.extensions??[".html",".jinja",".jinja2",""],debug:B.debug??!1,debugOptions:B.debugOptions??{},timezone:B.timezone??void 0},this.runtime=new z({autoescape:this.options.autoescape,filters:this.options.filters,globals:this.options.globals,urlResolver:this.options.urlResolver,staticResolver:this.options.staticResolver,templateLoader:this.loadTemplate.bind(this),timezone:this.options.timezone})}async render(B,K={}){if(this.options.debug)return this.renderWithDebug(B,K);let A=await this.loadTemplate(B);return this.runtime.render(A,K)}async renderString(B,K={}){if(this.options.debug)return this.renderStringWithDebug(B,K);let A=this.compile(B);return this.runtime.render(A,K)}async renderWithDebug(B,K){let A=D();A.captureContext(K),A.addTemplate(B,"root"),A.setMode("runtime"),A.startRender();let Q=await this.loadTemplate(B),$=this.runtime.render(Q,K);if($&&typeof $.then==="function")$=await $;A.endRender();let Z=_();return this.injectDebugPanel(String($||""),Z)}async renderStringWithDebug(B,K){let A=D();A.captureContext(K),A.setMode("runtime"),A.startRender();let Q=this.compile(B),$=this.runtime.render(Q,K);if($&&typeof $.then==="function")$=await $;A.endRender();let Z=_();return this.injectDebugPanel(String($||""),Z)}injectDebugPanel(B,K){if(!B||typeof B!=="string")return B||"";if(!(B.includes("<html")||B.includes("<body")||B.includes("<!DOCTYPE")))return B;let Q=L(K,this.options.debugOptions);if(B.includes("</body>"))return B.replace("</body>",`${Q}</body>`);return B+Q}compile(B){let A=new C(B).tokenize();return new N(A,B).parse()}async loadTemplate(B){if(this.options.cache&&this.templateCache.has(B)){this.cacheHits++;let $=this.templateCache.get(B);return this.templateCache.delete(B),this.templateCache.set(B,$),$}this.cacheMisses++;let K=await this.resolveTemplatePath(B);if(!K)throw Error(`Template not found: ${B}`);let A=await Bun.file(K).text(),Q=this.compile(A);if(this.options.cache){while(this.templateCache.size>=this.options.cacheMaxSize){let $=this.templateCache.keys().next().value;if($)this.templateCache.delete($)}this.templateCache.set(B,Q)}return Q}clearCache(){this.templateCache.clear(),this.cacheHits=0,this.cacheMisses=0}cacheSize(){return this.templateCache.size}cacheStats(){let B=this.cacheHits+this.cacheMisses;return{size:this.templateCache.size,maxSize:this.options.cacheMaxSize,hits:this.cacheHits,misses:this.cacheMisses,hitRate:B>0?this.cacheHits/B*100:0}}addFilter(B,K){this.runtime.addFilter(B,K)}addGlobal(B,K){this.runtime.addGlobal(B,K)}addUrl(B,K){this.routes.set(B,K)}addUrls(B){for(let[K,A]of Object.entries(B))this.routes.set(K,A)}async resolveTemplatePath(B){let K=V.resolve(this.options.templates,B);for(let A of this.options.extensions){let Q=K+A;if(await Bun.file(Q).exists())return Q}return null}defaultUrlResolver(B,K,A){let Q=this.routes.get(B);if(!Q)return console.warn(`URL pattern not found: ${B}`),`#${B}`;let $=Q;for(let U in A){let Y=encodeURIComponent(String(A[U]));$=$.replaceAll(`:${U}`,Y),$=$.replaceAll(`<${U}>`,Y),$=$.replaceAll(`(?P<${U}>[^/]+)`,Y)}let Z=0;return HB.lastIndex=0,$=$.replace(HB,()=>{if(Z<K.length)return encodeURIComponent(String(K[Z++]));return""}),$}defaultStaticResolver(B){return`/static/${B}`}}async function Q8(B,K={},A={}){return new d(A).renderString(B,K)}function O8(B,K={}){let Q=new d(K).compile(B),$=new z({autoescape:K.autoescape??!0,filters:K.filters??{},globals:K.globals??{},urlResolver:K.urlResolver,staticResolver:K.staticResolver,templateLoader:async()=>Q});return{async render(Z={}){return $.render(Q,Z)}}}function Z8(B,K={}){let Q=new C(B).tokenize(),Z=new N(Q,B).parse();return v(Z,K)}async function J8(B,K){let A=K.extensions??[".html",".jinja",".jinja2",""],Q=V.resolve(K.templates),$={load(J){let X=V.resolve(Q,J);for(let M of A){let G=X+M,R=Bun.file(G),F=s("fs");if(F.existsSync(G))return F.readFileSync(G,"utf-8")}throw Error(`Template not found: ${J}`)},parse(J){let M=new C(J).tokenize();return new N(M,J).parse()}},Z=$.load(B),U=$.parse(Z),Y=x(U);if(!Y.canFlatten)throw Error(`Cannot compile template with AOT: ${Y.reason}
372
+ Use Environment.render() for dynamic template names.`);let O=g(U,{loader:$});return v(O,K)}async function Y8(B,K){let A=K.extensions??[".html",".jinja",".jinja2",""],Q=V.resolve(K.templates),$=s("fs"),Z={load(X){let M=V.resolve(Q,X);for(let G of A){let R=M+G;if($.existsSync(R))return $.readFileSync(R,"utf-8")}throw Error(`Template not found: ${X}`)},parse(X){let G=new C(X).tokenize();return new N(G,X).parse()}},U=Z.load(B),Y=Z.parse(U),O=x(Y);if(!O.canFlatten)throw Error(`Cannot compile template with AOT: ${O.reason}`);let J=g(Y,{loader:Z});return T(J,K)}function U8(B,K={}){let Q=new C(B).tokenize(),Z=new N(Q,B).parse();return T(Z,K)}export{IB as renderWithDebug,RB as renderStringWithDebug,Q8 as render,L as generateDebugPanel,g as flattenTemplate,oA as debugMiddleware,lA as createDebugRenderer,Y8 as compileWithInheritanceToCode,J8 as compileWithInheritance,U8 as compileToCode,Z8 as compile,x as canFlatten,f as builtinTests,h as builtinFilters,b as TokenType,P as TemplateSyntaxError,y as TemplateRuntimeError,r as TemplateError,O8 as Template,z as Runtime,N as Parser,C as Lexer,d as Environment,w as Context};