// @bun
var{defineProperty:QW,getOwnPropertyNames:nW,getOwnPropertyDescriptor:rW}=Object,tW=Object.prototype.hasOwnProperty;function eW(W){return this[W]}var aJ=(W)=>{var $=(wW??=new WeakMap).get(W),J;if($)return $;if($=QW({},"__esModule",{value:!0}),W&&typeof W==="object"||typeof W==="function"){for(var Z of nW(W))if(!tW.call($,Z))QW($,Z,{get:eW.bind(W,Z),enumerable:!(J=rW(W,Z))||J.enumerable})}return wW.set(W,$),$},wW;var WJ=(W)=>W;function JJ(W,$){this[W]=WJ.bind(null,$)}var sJ=(W,$)=>{for(var J in $)QW(W,J,{get:$[J],enumerable:!0,configurable:!0,set:JJ.bind($,J)})};var E=(W,$)=>()=>(W&&($=W(W=0)),$);var a=import.meta.require;function rJ(W){p={...p,...W}}function tJ(){p={...IW}}function eJ(){return{...p}}function QJ(W){let $="",J=null,Z=!1;for(let Q=0;Q<W.length;Q++){let Y=W[Q];if(Z){Z=!1;continue}if(Y==="\\"&&J){Z=!0;continue}if(J){if(J==="`"&&Y==="$"&&Q+1<W.length&&W[Q+1]==="{"){let U=1;Q+=2;while(Q<W.length&&U>0){if(W[Q]==="{")U++;else if(W[Q]==="}")U--;if(U>0)$+=W[Q],Q++}continue}if(Y===J)J=null;continue}if(Y==='"'||Y==="'"||Y==="`"){J=Y;continue}$+=Y}return $}function XJ(W,$){let J=/[$A-Z_a-z][$\w]*/g,Z;while((Z=J.exec(W))!==null){let Q=Z[0],Y=W[Z.index-1];if(ZJ.has(Q))throw Error(`Potentially unsafe expression (matched /\\b${Q}\\b/; identifier ${Q}): ${$}`);if(Y==="."&&NW.has(Q))throw Error(`Potentially unsafe expression (matched /.${Q}/; property ${Q}): ${$}`)}}function YJ(W){let $=/\[\s*(['"])(.*?)\1\s*\]/g,J;while((J=$.exec(W))!==null){let Z=J[2];if(!NW.has(Z))continue;let Q=W.slice(0,J.index).match(/\S(?=\s*$)/)?.[0],Y=W.slice(J.index+J[0].length).match(/^\s*(\S)/)?.[1];if(!((Q==="{"||Q===",")&&Y===":"))throw Error(`Potentially unsafe expression (bracket key ${J[2]}): ${W}`)}}function UW(W){let $=W.trim(),J=QJ($);XJ(J,$),YJ($);for(let Z of YW)if(Z.test(J))throw Error(`Potentially unsafe expression (matched /${Z.source}/): ${$}`);if(!p.allowBracketNotation&&$J.test($))throw Error(`Bracket notation with strings not allowed: ${$}. Enable with configureSafeEvaluator({ allowBracketNotation: true })`);return $}function MW(W){let $={};$.Math=Math,$.JSON=JSON,$.Date=Date,$.String=String,$.Number=Number,$.Boolean=Boolean,$.Array=Array,$.parseInt=Number.parseInt,$.parseFloat=Number.parseFloat,$.isNaN=Number.isNaN,$.isFinite=Number.isFinite,$.encodeURIComponent=encodeURIComponent,$.decodeURIComponent=decodeURIComponent;for(let[J,Z]of Object.entries(W)){if(J.startsWith("__")||YW.some((Q)=>Q.test(J)))continue;if(Z&&typeof Z==="object"&&!Array.isArray(Z))$[J]=XW(Z);else $[J]=Z}return $}function XW(W,$=0){if($>=p.maxSanitizeDepth)return"[Object too deep]";if(W===null||typeof W!=="object")return W;if(Array.isArray(W))return W.map((Z)=>XW(Z,$+1));if(W instanceof Date||W instanceof RegExp||W instanceof Map||W instanceof Set||W instanceof Error)return W;let J={};for(let[Z,Q]of Object.entries(W)){if(Z.startsWith("__")||Z==="constructor"||Z==="prototype")continue;if(Q&&typeof Q==="object")J[Z]=XW(Q,$+1);else J[Z]=Q}return J}function P(W,$){try{let J=MW($),Z=Object.keys(J),Q=Object.values(J);return d(W,Z)(...Q)}catch{return}}function c(W){try{return UW(W),!0}catch{return!1}}function WZ(W){try{return UW(W),null}catch($){return $ instanceof Error?$.message:String($)}}function JZ(W,$){try{let J=P(W,$);return Boolean(J)}catch{return!1}}function ZZ(W,$){try{let J=P(W,$);if(Array.isArray(J))return J;if(J&&typeof J==="object"&&"length"in J){let Z=J.length;if(typeof Z==="number"&&Number.isFinite(Z)&&Z>=0&&Number.isInteger(Z))return Array.from(J)}return[]}catch{return[]}}function $Z(W,$){try{let J=P(W,$);if(J&&typeof J==="object"&&!Array.isArray(J))return J;return{}}catch{return{}}}function d(W,$){let J=UW(W),Z=/^[A-Za-z_$][\w$]*$/,Q=[],Y=[];for(let X=0;X<$.length;X++){let F=$[X];if(!Z.test(F))continue;if(UJ.has(F))continue;Q.push(X),Y.push(F)}let U=Function(...Y,`
    'use strict';
    try {
      return ${J};
    }
catch (e) {
      if (e instanceof ReferenceError || e instanceof TypeError) {
        return undefined;
      }
      throw e;
    }
  `);if(Y.length===$.length)return U;return(...X)=>{let F=Array(Q.length);for(let q=0;q<Q.length;q++)F[q]=X[Q[q]];return U(...F)}}function QZ(W,$){try{if(typeof W!=="string")return;if(W.length>AW)throw Error(`safeEvaluateCode: input exceeds ${AW} chars`);for(let U of YW)if(U.test(W))throw Error("Potentially unsafe code detected");let J=MW($),Z=Object.keys(J),Q=Object.values(J);return Function(...Z,`
      'use strict';
      ${W}
    `)(...Q)}catch{return}}function qJ(W){let $=W.trim(),J=[/\beval\s*\(/i,/\bFunction\s*\(/i,/\bimport\s*\(/i,/\brequire\s*\(/i,/\bprocess\b/i,/\b__proto__\b/i,/\bconstructor\s*[.(]/i,/\bglobalThis\b/i,/\bwindow\b/i,/\bdocument\b/i,/\bfetch\s*\(/i,/\bBun\b/i,/\bDeno\b/i,/\bconsole\b/i,/\bthis\b/i,/\bReflect\b/i,/\bProxy\b/i,/\bprototype\b/i,/\.(bind|call|apply)\s*\(/i];for(let Z of J)if(Z.test($))return!1;return!0}function XZ(W,$,J,Z,Q=1000){if(!qJ($))throw Error(`Unsafe expression in @${W}: ${$}`);let Y=J.replace(/`/g,"\\`").replace(/\$\{/g,"\\${").replace(/\{\{([^}]+)\}\}/g,(U,X)=>{return`\${${X}}`});if(W==="for")return Function(...Z,`
      'use strict';
      let result = '';
      for (${$}) {
        result += \`${Y}\`;
      }
      return result;
    // eslint-disable-next-line pickier/no-unused-vars
    `);else return Function(...Z,`
      'use strict';
      let result = '';
      let __safeCounter = 0;
      const __maxIterations = ${Q};
      while (${$} && __safeCounter < __maxIterations) {
        __safeCounter++;
        result += \`${Y}\`;
      }
      // Surface the truncation both inline (for end users) and via
      // console.warn (for developers running \`stx dev\`). A silent cut-off
      // made pages render half a list with no breadcrumb.
      if (__safeCounter >= __maxIterations) {
        result += '<!-- [Loop Error]: Maximum iterations exceeded -->';
        if (typeof console !== 'undefined' && typeof console.warn === 'function') {
          console.warn('[stx] @while loop hit max iterations (' + __maxIterations + '); template output was truncated. Raise via createSafeForLoop(..., maxIterations) if intentional.');
        }
      }
      return result;
    // eslint-disable-next-line pickier/no-unused-vars
    `)}var IW,p,YW,ZJ,NW,$J,UJ,AW=65536;var qW=E(()=>{IW={maxSanitizeDepth:10,allowBracketNotation:!1},p={...IW};YW=[/\b(eval|Function|setTimeout|setInterval|setImmediate)\b/,/\b(process|require|import|exports|module)\b/,/\b(window|document|global|globalThis)\b/,/\b(constructor|prototype|__proto__)\b/,/\b(Reflect|Proxy)\b/,/\bSymbol\b/,/\b(WeakMap|WeakSet|WeakRef|FinalizationRegistry)\b/,/\b(Generator|AsyncGenerator)\b/,/__\w+__/,/\.(bind|call|apply)\s*\(/,/\bnew\s+/,/\bdelete\s+/,/\bthis\b/],ZJ=new Set(["eval","Function","setTimeout","setInterval","setImmediate","process","require","import","exports","module","window","document","global","globalThis","constructor","prototype","Reflect","Proxy","Symbol","WeakMap","WeakSet","WeakRef","FinalizationRegistry","Generator","AsyncGenerator","delete","this"]),NW=new Set(["__proto__","constructor","prototype"]),$J=/[\w)\]]\s*\[\s*['"]/;UJ=new Set(["break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","if","import","in","instanceof","new","null","return","super","switch","this","throw","true","try","typeof","var","void","while","with","yield","let","static","implements","interface","package","private","protected","public","arguments","eval","await"])});function HJ(W){RW=W}function VJ(){return RW}function KJ(W){n={...n,...W}}function _J(){n={}}function DW(W,$={}){let J=n[W]||FJ[W]||{message:`Unknown error (code: ${W})`},Z=J.message,Q=J.help;for(let[Y,U]of Object.entries($)){let X=`{{${Y}}}`;if(Z=Z.replace(new RegExp(X,"g"),U),Q)Q=Q.replace(new RegExp(X,"g"),U)}return{message:Z,help:Q}}function OJ(W,$={}){let{message:J,help:Z}=DW(W,$);return Z?`${J}
  Help: ${Z}`:J}function FW(W){for(let[$,J]of Object.entries(k))if(J===W)return $;return}var FJ,n,RW="en",k;var r=E(()=>{FJ={1001:{message:"Unclosed directive: {{directive}}",help:"Make sure to close the directive with the appropriate end tag"},1002:{message:"Unclosed expression at position {{position}}",help:"Check for missing closing braces }}"},1003:{message:"Invalid directive syntax: {{directive}}",help:"Review the directive documentation for correct syntax"},1004:{message:"Malformed expression: {{expression}}",help:"Check for syntax errors in your expression"},1005:{message:"Unexpected token: {{token}}",help:"Remove or fix the unexpected token"},1101:{message:"Undefined variable: {{variable}}",help:"Make sure the variable is defined in the template context"},1102:{message:"Type error: {{details}}",help:"Check that you are using the correct types"},1103:{message:"Evaluation error: {{details}}",help:"Review the expression for errors"},1104:{message:"Infinite loop detected in {{location}}",help:"Check your loop conditions"},1105:{message:"Circular reference detected: {{path}}",help:"Remove the circular dependency"},1201:{message:"Unsafe expression blocked: {{expression}}",help:"This expression contains potentially dangerous code"},1202:{message:"Path traversal attempt blocked: {{path}}",help:"Use only relative paths within allowed directories"},1203:{message:"Potential XSS attempt blocked",help:"Sanitize user input before rendering"},1204:{message:"Code injection attempt blocked: {{code}}",help:"Avoid executing dynamic code"},1205:{message:"Prohibited DOM API usage: {{api}}",help:"Use STX.useRefs(), STX.useRef(), STX.el() and other STX helpers instead of direct DOM manipulation"},1301:{message:"File not found: {{path}}",help:"Check that the file exists and the path is correct"},1302:{message:"Error reading file: {{path}}",help:"Check file permissions and encoding"},1303:{message:"Invalid file path: {{path}}",help:"Use a valid file path"},1304:{message:"Permission denied: {{path}}",help:"Check file permissions"},1401:{message:"Invalid configuration: {{details}}",help:"Review your stx.config.ts file"},1402:{message:"Missing required configuration: {{key}}",help:"Add the required configuration option"},1403:{message:"Deprecated configuration: {{key}}",help:"Update to the new configuration format"},1501:{message:"Component not found: {{name}}",help:"Check that the component exists in your components directory"},1502:{message:"Invalid props for component {{name}}: {{details}}",help:"Check the component prop requirements"},1503:{message:"Error rendering component {{name}}: {{details}}",help:"Check the component template for errors"},1601:{message:"Filter not found: {{filter}}",help:"Register the filter or check the filter name"},1602:{message:"Invalid arguments for filter {{filter}}: {{details}}",help:"Check the filter documentation for correct arguments"},1603:{message:"Expression evaluation timed out",help:"Simplify the expression or increase the timeout"}},n={};k={UNCLOSED_DIRECTIVE:1001,UNCLOSED_EXPRESSION:1002,INVALID_DIRECTIVE_SYNTAX:1003,MALFORMED_EXPRESSION:1004,UNEXPECTED_TOKEN:1005,UNDEFINED_VARIABLE:1101,TYPE_ERROR:1102,EVALUATION_ERROR:1103,INFINITE_LOOP:1104,CIRCULAR_REFERENCE:1105,UNSAFE_EXPRESSION:1201,PATH_TRAVERSAL:1202,XSS_ATTEMPT:1203,CODE_INJECTION:1204,DOM_API_VIOLATION:1205,FILE_NOT_FOUND:1301,FILE_READ_ERROR:1302,INVALID_FILE_PATH:1303,PERMISSION_DENIED:1304,INVALID_CONFIG:1401,MISSING_REQUIRED_CONFIG:1402,DEPRECATED_CONFIG:1403,COMPONENT_NOT_FOUND:1501,INVALID_PROPS:1502,COMPONENT_RENDER_ERROR:1503,FILTER_NOT_FOUND:1601,INVALID_FILTER_ARGS:1602,EXPRESSION_TIMEOUT:1603}});function GJ(){return!1}function s(){return!GJ()||process.env.STX_DEBUG==="true"}function qZ(){return!1}import jJ from"path";function BJ(W){i={...i,...W}}function t(){return{...i}}function zJ(){i={...LW}}function e(W){if(!i.showRelativePaths||!W)return W;let $=i.baseDir||process.cwd();try{let J=jJ.relative($,W);return J.startsWith("..")?W:J}catch{return W}}var LW,i,l,TW,bW,yW,kW,EW;var WW=E(()=>{r();LW={showRelativePaths:!1,enableAutoRecovery:s(),logRecoveryWarnings:!0},i={...LW};l=class l extends Error{code;filePath;line;column;context;numericCode;constructor(W,$,J,Z,Q,Y,U){super(W);this.code=$;this.filePath=J;this.line=Z;this.column=Q;this.context=Y;if(this.name="StxError",this.numericCode=U||k.EVALUATION_ERROR,this.filePath)this.filePath=e(this.filePath)}};TW=class TW extends l{constructor(W,$,J,Z,Q,Y){super(W,"stx_SYNTAX_ERROR",$,J,Z,Q,Y||k.INVALID_DIRECTIVE_SYNTAX);this.name="StxSyntaxError"}};bW=class bW extends l{constructor(W,$,J,Z,Q,Y){super(W,"stx_RUNTIME_ERROR",$,J,Z,Q,Y||k.EVALUATION_ERROR);this.name="StxRuntimeError"}};yW=class yW extends l{constructor(W,$,J,Z,Q,Y){super(W,"stx_SECURITY_ERROR",$,J,Z,Q,Y||k.UNSAFE_EXPRESSION);this.name="StxSecurityError"}};kW=class kW extends l{constructor(W,$,J,Z,Q,Y){super(W,"stx_FILE_ERROR",$,J,Z,Q,Y||k.FILE_NOT_FOUND);this.name="StxFileError"}};EW=class EW extends l{isFatal=!0;constructor(W,$,J,Z,Q,Y){super(W,"stx_VALIDATION_ERROR",$,J,Z,Q,Y||k.DOM_API_VIOLATION);this.name="StxValidationError"}}});function VW(W){let{type:$,message:J,code:Z,filePath:Q,line:Y,column:U,template:X,offset:F,snippet:q,suggestion:H,format:V="text"}=W,K=Y,B=U;if(!K&&X&&F!==void 0){let z=CW(X,F);K=z.line,B=z.column}let _=Q?e(Q):void 0,O=Z?FW(Z):void 0,j={type:$,code:Z,codeName:O,message:J,filePath:_,line:K,column:B,snippet:q,suggestion:H,timestamp:new Date().toISOString()},G;switch(V){case"html":G=AJ(j);break;case"json":G=JSON.stringify(j,null,2);break;case"console":G=IJ(j,X,F);break;case"text":default:G=wJ(j,X,F);break}return{formatted:G,data:j}}function wJ(W,$,J){let Z=[],Q=W.code?` [${W.codeName||W.code}]`:"";if(Z.push(`[${W.type} Error${Q}]`),W.filePath){let Y=W.filePath;if(W.line){if(Y+=`:${W.line}`,W.column)Y+=`:${W.column}`}Z.push(`at ${Y}`)}if(Z.push(`
${W.message}`),$&&W.line){let Y=NJ($,W.line,2);if(Y)Z.push(`
${Y}`)}if(W.snippet)Z.push(`
Snippet: ${W.snippet}`);if(W.suggestion)Z.push(`
Suggestion: ${W.suggestion}`);return Z.join(" ")}function AJ(W){let $=W.code?` [${W.code}]`:"",J=W.filePath?` in ${W.filePath}${W.line?`:${W.line}`:""}`:"",Z=`<!-- [${W.type} Error${$}]${J}: ${SW(W.message)}`;if(W.suggestion)Z+=` | Suggestion: ${SW(W.suggestion)}`;return Z+=" -->",Z}function IJ(W,$,J){let q=[],H=W.code?` [${W.codeName||W.code}]`:"";if(q.push(`\x1B[1m${"\x1B[31m"}\u2501\u2501\u2501 ${W.type} Error${H} \u2501\u2501\u2501${"\x1B[0m"}`),W.filePath){let V=`\x1B[36m${W.filePath}\x1B[0m`;if(W.line){if(V+=`\x1B[90m:${W.line}\x1B[0m`,W.column)V+=`\x1B[90m:${W.column}\x1B[0m`}q.push(`
\x1B[90mat\x1B[0m ${V}`)}if(q.push(`

${W.message}`),$&&W.line){let V=MJ($,W.line,2);if(V)q.push(`

\x1B[90mContext:\x1B[0m
${V}`)}if(W.suggestion)q.push(`

\x1B[33mSuggestion:\x1B[0m ${W.suggestion}`);return q.push(`
${"\x1B[31m"}\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501${"\x1B[0m"}`),q.join("")}function NJ(W,$,J){let Z=W.split(`
`),Q=Math.max(0,$-J-1),Y=Math.min(Z.length-1,$+J-1),U=[];for(let X=Q;X<=Y;X++){let F=(X+1).toString().padStart(4),q=X===$-1?">":" ";U.push(`${q}${F} | ${Z[X]}`)}return U.join(`
`)}function MJ(W,$,J){let Z=W.split(`
`),Q=Math.max(0,$-J-1),Y=Math.min(Z.length-1,$+J-1),U="\x1B[90m",X="\x1B[31m",F="\x1B[0m",q=[];for(let H=Q;H<=Y;H++){let V=(H+1).toString().padStart(4),K=H===$-1,B=K?"\x1B[31m>\x1B[0m":" ",_=K?`\x1B[31m${Z[H]}\x1B[0m`:`\x1B[90m${Z[H]}\x1B[0m`;q.push(`${B}\x1B[90m${V}\x1B[0m | ${_}`)}return q.join(`
`)}function SW(W){return W.replace(/--/g,"- -").replace(/>/g,"&gt;")}function CW(W,$){let Z=W.substring(0,$).split(`
`);return{line:Z.length,column:Z[Z.length-1].length}}function o(W,$,J){return VW({type:W,message:$,code:J,format:"html"}).formatted}function RJ(W,$,J,Z,Q){return VW({type:W,message:$,code:Q,filePath:J,line:Z,format:"console"}).formatted}function DJ(W,$,J){let Z=J.template.split(`
`),Q=CW(J.template,J.offset),Y=`[${W} Error at line ${Q.line} in ${J.filePath}]: ${$}

`,U=Math.max(0,Q.line-3),X=Math.min(Z.length-1,Q.line+2);Y+=`Context:
`;for(let F=U;F<=X;F++){let q=F+1,H=Z[F]||"",V=F===Q.line-1?">":" ";Y+=`${V} ${q.toString().padStart(3)}: ${H}
`}if(Q.line-1<Z.length){let F=" ".repeat(Q.column+5);Y+=`${F}^
`}return Y}function LJ(W,$,J){try{return W()}catch(Z){if(J&&Z instanceof Error)J(Z);return $}}async function TJ(W,$,J){try{return await W()}catch(Z){if(J&&Z instanceof Error)J(Z);return $}}var vW=E(()=>{r();WW()});class KW{errors=[];maxErrors;enableFileLogging;logFilePath;logFormat;maxFileSize;maxLogFiles;minLevel;writeQueue=Promise.resolve();constructor(W={}){this.maxErrors=W.maxErrors??1000,this.enableFileLogging=W.enableFileLogging??!1,this.logFilePath=W.logFilePath??".stx/errors.log",this.logFormat=W.logFormat??"json",this.maxFileSize=W.maxFileSize??10485760,this.maxLogFiles=W.maxLogFiles??5,this.minLevel=W.minLevel??"all"}configure(W){if(W.maxErrors!==void 0)this.maxErrors=W.maxErrors;if(W.enableFileLogging!==void 0)this.enableFileLogging=W.enableFileLogging;if(W.logFilePath!==void 0)this.logFilePath=W.logFilePath;if(W.logFormat!==void 0)this.logFormat=W.logFormat;if(W.maxFileSize!==void 0)this.maxFileSize=W.maxFileSize;if(W.maxLogFiles!==void 0)this.maxLogFiles=W.maxLogFiles;if(W.minLevel!==void 0)this.minLevel=W.minLevel}log(W,$,J="error"){let Z={timestamp:new Date,error:W,context:$,level:J};if(this.errors.push(Z),this.errors.length>this.maxErrors)this.errors=this.errors.slice(-this.maxErrors);if(this.enableFileLogging&&this.shouldLog(J))this.writeToFile(Z)}shouldLog(W){if(this.minLevel==="all")return!0;if(this.minLevel==="warning")return W==="error"||W==="warning";if(this.minLevel==="error")return W==="error";return!0}formatEntry(W){if(this.logFormat==="json")return JSON.stringify({timestamp:W.timestamp.toISOString(),level:W.level||"error",type:W.error.constructor.name,message:W.error.message,stack:W.error.stack,context:W.context});let $=[`[${W.timestamp.toISOString()}] [${(W.level||"error").toUpperCase()}] ${W.error.constructor.name}: ${W.error.message}`];if(W.error.stack)$.push(`  Stack: ${W.error.stack.split(`
`).slice(1).join(`
  `)}`);if(W.context)$.push(`  Context: ${JSON.stringify(W.context)}`);return $.join(`
`)}writeToFile(W){this.writeQueue=this.writeQueue.then(async()=>{try{let $=await import("fs"),Z=(await import("path")).dirname(this.logFilePath);if(!$.existsSync(Z))$.mkdirSync(Z,{recursive:!0});await this.rotateIfNeeded($);let Q=`${this.formatEntry(W)}
`;$.appendFileSync(this.logFilePath,Q,"utf-8")}catch($){if(process.env.STX_DEBUG==="true")console.error("Failed to write to error log:",$)}})}async rotateIfNeeded(W){try{if(!W.existsSync(this.logFilePath))return;if(W.statSync(this.logFilePath).size<this.maxFileSize)return;for(let J=this.maxLogFiles-1;J>=1;J--){let Z=`${this.logFilePath}.${J}`,Q=`${this.logFilePath}.${J+1}`;if(W.existsSync(Z))if(J>=this.maxLogFiles-1)W.unlinkSync(Z);else W.renameSync(Z,Q)}if(this.maxLogFiles<=1)W.writeFileSync(this.logFilePath,"");else W.renameSync(this.logFilePath,`${this.logFilePath}.1`)}catch($){if(process.env.STX_DEBUG==="true")console.error("Failed to rotate error logs:",$)}}getRecentErrors(W=10){return this.errors.slice(-W)}getErrorsByType(W){return this.errors.filter(($)=>$.error.constructor.name===W)}getErrorsByLevel(W){return this.errors.filter(($)=>$.level===W)}clear(){this.errors.length=0}async clearLogFile(){try{let W=await import("fs");if(W.existsSync(this.logFilePath))W.writeFileSync(this.logFilePath,"","utf-8")}catch(W){if(process.env.STX_DEBUG==="true")console.error("Failed to clear error log:",W)}}getStats(){let W={},$={error:0,warning:0,info:0};for(let J of this.errors){let Z=J.error.constructor.name;W[Z]=(W[Z]||0)+1;let Q=J.level||"error";$[Q]=($[Q]||0)+1}return{total:this.errors.length,byType:W,byLevel:$}}async exportToFile(W,$="json"){let J=await import("fs"),Q=(await import("path")).dirname(W);if(!J.existsSync(Q))J.mkdirSync(Q,{recursive:!0});if($==="json"){let Y=this.errors.map((U)=>({timestamp:U.timestamp.toISOString(),level:U.level||"error",type:U.error.constructor.name,message:U.error.message,stack:U.error.stack,context:U.context}));J.writeFileSync(W,JSON.stringify(Y,null,2),"utf-8")}else{let Y=this.errors.map((U)=>this.formatEntry(U));J.writeFileSync(W,Y.join(`

`),"utf-8")}}async flush(){await this.writeQueue}}var bJ,yJ,kJ;var gW=E(()=>{WW();bJ={isEnabled(){return t().enableAutoRecovery},fixCommonSyntaxErrors(W){let $=t();if(!$.enableAutoRecovery)return{fixed:W,fixes:[]};let J=W,Z=[],Q=(J.match(/\{\{/g)||[]).length,Y=(J.match(/\}\}/g)||[]).length;if(Q>Y){let X=Q-Y;J+="}}".repeat(X),Z.push(`Added ${X} missing closing braces '}}'`)}let U=["if","foreach","for","switch","section"];for(let X of U){let F=(J.match(new RegExp(`@${X}\\b`,"g"))||[]).length,q=(J.match(new RegExp(`@end${X}\\b`,"g"))||[]).length;if(F>q){let H=F-q;for(let V=0;V<H;V++)J+=`
@end${X}`;Z.push(`Added ${H} missing @end${X}`)}}if(Z.length>0&&$.logRecoveryWarnings)console.warn("[stx] Auto-recovery applied fixes:"),Z.forEach((X)=>console.warn(`  - ${X}`)),console.warn("  Consider fixing these issues in your template.");return{fixed:J,fixes:Z}},createFallbackContent(W,$){if(s())return`<!-- ${W} failed: ${$.message} -->`;return"<!-- stx rendering error -->"}};yJ=new KW,kJ={isDevelopment(){return s()},logDetailedError(W,$){if(!this.isDevelopment())return;if(console.error("=== stx Detailed Error ==="),console.error("Error:",W.message),console.error("Stack:",W.stack),$)console.error("Context:",$);console.error("========================")},createErrorReport(W,$){let J=["=== stx Error Report ===",`Time: ${new Date().toISOString()}`,`Error: ${W.message}`,`Type: ${W.constructor.name}`,`Stack: ${W.stack}`];if($)J.push(`Context: ${JSON.stringify($,null,2)}`);return J.push("========================"),J.join(`
`)}}});import _W from"path";function EJ(W){let $={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return W.replace(/[&<>"']/g,(J)=>$[J]||J)}function JW(W,$={}){let{allowHtml:J=!1,maxLength:Z=1e4,allowSpecialChars:Q=!0,customSanitizer:Y}=$,U=[],X=W,F=!1;if(Y){let H=Y(X);if(H!==X)X=H,F=!0}if(X.includes("\x00"))X=X.replace(/\0/g,""),F=!0,U.push("Null bytes removed from parameter");if(X.length>Z)X=X.substring(0,Z),F=!0,U.push(`Parameter truncated to ${Z} characters`);if(!J&&/<[^>]+>/.test(X))X=EJ(X),F=!0,U.push("HTML content was escaped");let q=[{pattern:/javascript:/gi,replacement:"",name:"javascript: URI"},{pattern:/vbscript:/gi,replacement:"",name:"vbscript: URI"},{pattern:/data:text\/html/gi,replacement:"",name:"data:text/html URI"}];for(let{pattern:H,replacement:V,name:K}of q)if(H.test(X))X=X.replace(H,V),F=!0,U.push(`Removed ${K} from parameter`);if(!Q){let H=X;if(X=X.split("").filter((V)=>{let K=V.charCodeAt(0);return K>=32&&K!==127}).join(""),X!==H)F=!0,U.push("Control characters removed")}return{value:X,modified:F,warnings:U}}function SJ(W,$){let J=W.replace(/\0/g,"");J=J.replace(/\\/g,"/"),J=J.replace(/^[a-z][a-z0-9+.-]*:/i,"");while(J.includes("../")||J.includes("./"))J=J.replace(/\.\.\//g,"").replace(/\.\//g,"");if(!OW.isValidFilePath(J,$))return null;return J}function CJ(W){let $=[],J=W.trim(),Z=J!==W,Q=[{pattern:/\beval\s*\(/gi,name:"eval()"},{pattern:/\bFunction\s*\(/gi,name:"Function()"},{pattern:/\bsetTimeout\s*\(/gi,name:"setTimeout()"},{pattern:/\bsetInterval\s*\(/gi,name:"setInterval()"},{pattern:/\bimport\s*\(/gi,name:"dynamic import()"},{pattern:/\brequire\s*\(/gi,name:"require()"},{pattern:/\b__proto__\b/gi,name:"__proto__"},{pattern:/\bconstructor\b/gi,name:"constructor"},{pattern:/\bprototype\b/gi,name:"prototype"}];for(let{pattern:Y,name:U}of Q)if(Y.test(J))$.push(`Potentially dangerous pattern detected: ${U}`);if(J.includes("\x00"))J=J.replace(/\0/g,""),Z=!0,$.push("Null bytes removed from expression");return{value:J,modified:Z,warnings:$}}function vJ(W,$={}){return W.map((J)=>JW(J,$))}function PW(W){let $={};for(let[J,Z]of Object.entries(W)){if(!OW.isValidVariableName(J))continue;if(typeof Z==="string"){let Q=JW(Z);$[J]=Q.value}else if(Array.isArray(Z))$[J]=Z.map((Q)=>typeof Q==="string"?JW(Q).value:Q);else if(typeof Z==="object"&&Z!==null)$[J]=PW(Z);else $[J]=Z}return $}var OW;var fW=E(()=>{OW={isValidFilePath(W,$){let J=W.replace(/\\/g,"/");if(J.includes("\x00"))return!1;if(J.includes("../")||J.includes("..\\")||J===".."||J.startsWith("../")||J.endsWith("/..")||J.includes("/..\\")||J.includes("\\../"))return!1;if(/^[a-z][a-z0-9+.-]*:/i.test(J))return!1;if(J.startsWith("/")){if(["/etc/","/root/","/var/","/usr/","/bin/","/sbin/","/proc/","/sys/","/dev/","/boot/","/home/","/private/","/Library/","/System/"].some((Y)=>J===Y.slice(0,-1)||J.startsWith(Y)))return!1}if(/^[a-z]:/i.test(J)){if(["Windows/","Windows\\","System32/","System32\\","Program Files/","Program Files\\"].some((Y)=>J.includes(Y)))return!1}if($){let Q=_W.resolve($,W),Y=_W.resolve($);if(!Q.startsWith(Y+_W.sep)&&Q!==Y)return!1}return!0},isValidVariableName(W){return/^[a-z_$]\w*$/i.test(W)},isValidDirectiveName(W){return/^[a-z][\w-]*$/i.test(W)},isSafeContent(W){return![/<script[^>]*>[\s\S]*?<\/script>/i,/javascript:/i,/data:text\/html/i,/vbscript:/i,/on\w+\s*=/i].some((J)=>J.test(W))}}});var xW=E(()=>{r();vW();gW();fW();WW()});var mW=E(()=>{xW()});function m(W,$){try{let J=W.trim();if(c(J))return d(J,Object.keys($))(...Object.values($));else return P(J,$)}catch{return!1}}var hW=E(()=>{qW()});class ZW{source;pos=0;line=1;column=0;tokens=[];constructor(W){this.source=W}tokenize(){this.tokens=[],this.pos=0,this.line=1,this.column=0;while(this.pos<this.source.length){let W=this.nextToken();if(W)this.tokens.push(W)}return this.tokens.push({type:"EOF",value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),this.tokens}nextToken(){if(this.pos>=this.source.length)return null;let W=this.pos,$=this.line,J=this.column,Z=this.source[this.pos];if(/\s/.test(Z))return this.readWhitespace(W,$,J);if(Z==="/"&&this.peek(1)==="/")return this.readLineComment(W,$,J);if(Z==="/"&&this.peek(1)==="*")return this.readBlockComment(W,$,J);if(Z==='"'||Z==="'")return this.readString(Z,W,$,J);if(Z==="`")return this.readTemplateString(W,$,J);if(/\d/.test(Z)||Z==="."&&/\d/.test(this.peek(1)||""))return this.readNumber(W,$,J);if(/[a-z_$]/i.test(Z))return this.readIdentifier(W,$,J);if(Z==="{"){if(this.peek(1)==="{"&&this.peek(2)==="{")return this.advance(3),{type:"RAW_START",value:"{{{",start:W,end:this.pos,line:$,column:J};if(this.peek(1)==="{")return this.advance(2),{type:"EXPRESSION_START",value:"{{",start:W,end:this.pos,line:$,column:J};if(this.peek(1)==="!"&&this.peek(2)==="!")return this.advance(3),{type:"RAW_START",value:"{!!",start:W,end:this.pos,line:$,column:J}}if(Z==="}"){if(this.peek(1)==="}"&&this.peek(2)==="}")return this.advance(3),{type:"RAW_END",value:"}}}",start:W,end:this.pos,line:$,column:J};if(this.peek(1)==="}")return this.advance(2),{type:"EXPRESSION_END",value:"}}",start:W,end:this.pos,line:$,column:J}}if(Z==="!"&&this.peek(1)==="!"&&this.peek(2)==="}")return this.advance(3),{type:"RAW_END",value:"!!}",start:W,end:this.pos,line:$,column:J};if(Z==="@"&&/[a-z]/i.test(this.peek(1)||""))return this.readDirective(W,$,J);let Q=["===","!==","==","!=","<=",">=","&&","||","??","++","--","+=","-=","*=","/=","%=","**","=>","?.","...","<<",">>",">>>","&=","|=","^="];for(let Y of Q)if(this.source.slice(this.pos,this.pos+Y.length)===Y)return this.advance(Y.length),{type:"OPERATOR",value:Y,start:W,end:this.pos,line:$,column:J};if(/[+\-*/%<>=!&|^~?:]/.test(Z))return this.advance(),{type:"OPERATOR",value:Z,start:W,end:this.pos,line:$,column:J};if(/[()[\]{},;.]/.test(Z))return this.advance(),{type:"PUNCTUATION",value:Z,start:W,end:this.pos,line:$,column:J};return this.advance(),{type:"PUNCTUATION",value:Z,start:W,end:this.pos,line:$,column:J}}readWhitespace(W,$,J){while(this.pos<this.source.length&&/\s/.test(this.source[this.pos]))this.advance();return{type:"WHITESPACE",value:this.source.slice(W,this.pos),start:W,end:this.pos,line:$,column:J}}readLineComment(W,$,J){this.advance(2);while(this.pos<this.source.length&&this.source[this.pos]!==`
`)this.advance();return{type:"COMMENT",value:this.source.slice(W,this.pos),start:W,end:this.pos,line:$,column:J}}readBlockComment(W,$,J){this.advance(2);while(this.pos<this.source.length-1){if(this.source[this.pos]==="*"&&this.source[this.pos+1]==="/"){this.advance(2);break}this.advance()}return{type:"COMMENT",value:this.source.slice(W,this.pos),start:W,end:this.pos,line:$,column:J}}readString(W,$,J,Z){this.advance();while(this.pos<this.source.length){let Q=this.source[this.pos];if(Q==="\\"){this.advance(2);continue}if(Q===W){this.advance();break}this.advance()}return{type:"STRING",value:this.source.slice($,this.pos),start:$,end:this.pos,line:J,column:Z}}readTemplateString(W,$,J){this.advance();let Z=0,Q=256;while(this.pos<this.source.length){let Y=this.source[this.pos];if(Y==="\\"){this.advance(2);continue}if(Y==="$"&&this.peek(1)==="{"){if(Z>=Q){this.pos=this.source.length;break}this.advance(2),Z++;continue}if(Y==="{"&&Z>0){Z++,this.advance();continue}if(Y==="}"&&Z>0){Z--,this.advance();continue}if(Y==="`"&&Z===0){this.advance();break}this.advance()}return{type:"TEMPLATE_STRING",value:this.source.slice(W,this.pos),start:W,end:this.pos,line:$,column:J}}readNumber(W,$,J){if(this.source[this.pos]==="0"){let Z=this.peek(1)?.toLowerCase();if(Z==="x"||Z==="o"||Z==="b"){this.advance(2);while(this.pos<this.source.length&&/[\da-f_]/i.test(this.source[this.pos]))this.advance();return{type:"NUMBER",value:this.source.slice(W,this.pos),start:W,end:this.pos,line:$,column:J}}}while(this.pos<this.source.length&&/[\d_]/.test(this.source[this.pos]))this.advance();if(this.source[this.pos]==="."&&/\d/.test(this.peek(1)||"")){this.advance();while(this.pos<this.source.length&&/[\d_]/.test(this.source[this.pos]))this.advance()}if(/e/i.test(this.source[this.pos]||"")){if(this.advance(),/[+-]/.test(this.source[this.pos]||""))this.advance();while(this.pos<this.source.length&&/[\d_]/.test(this.source[this.pos]))this.advance()}if(this.source[this.pos]==="n")this.advance();return{type:"NUMBER",value:this.source.slice(W,this.pos),start:W,end:this.pos,line:$,column:J}}readIdentifier(W,$,J){while(this.pos<this.source.length&&/[\w$]/.test(this.source[this.pos]))this.advance();return{type:"IDENTIFIER",value:this.source.slice(W,this.pos),start:W,end:this.pos,line:$,column:J}}readDirective(W,$,J){this.advance();while(this.pos<this.source.length&&/[a-z]/i.test(this.source[this.pos]))this.advance();return{type:"DIRECTIVE",value:this.source.slice(W,this.pos),start:W,end:this.pos,line:$,column:J}}advance(W=1){for(let $=0;$<W&&this.pos<this.source.length;$++){if(this.source[this.pos]===`
`)this.line++,this.column=0;else this.column++;this.pos++}}peek(W){return this.source[this.pos+W]}saveState(){return{pos:this.pos,line:this.line,column:this.column}}restoreState(W){this.pos=W.pos,this.line=W.line,this.column=W.column}}function f(W,$,J,Z=0){let Q=0,Y=Z,U=null,X=0,F=!1;while(Y<W.length){let q=W[Y];if(U&&F){F=!1,Y++;continue}if(U&&q==="\\"){F=!0,Y++;continue}if(F=!1,(q==='"'||q==="'"||q==="`")&&!U){U=q,Y++;continue}if(q===U&&U!=="`"){U=null,Y++;continue}if(U==="`"&&q==="$"&&W[Y+1]==="{"){X++,Y+=2;continue}if(X>0&&q==="}"){X--,Y++;continue}if(q==="`"&&U==="`"&&X===0){U=null,Y++;continue}if(U){Y++;continue}if(q===$)Q++;else if(q===J){if(Q--,Q===0)return Y}Y++}return-1}function dW(W,$){let J=$,Z={paren:0,bracket:0,brace:0},Q=null,Y=0;while(J<W.length){let U=W[J];if((J>0?W[J-1]:"")==="\\"&&Q){J++;continue}if((U==='"'||U==="'")&&!Q){Q=U,J++;continue}if(U===Q&&Q!=="`"){Q=null,J++;continue}if(U==="`"&&!Q){Q="`",J++;continue}if(U==="`"&&Q==="`"&&Y===0){Q=null,J++;continue}if(Q==="`"&&U==="$"&&W[J+1]==="{"){Y++,J+=2;continue}if(Y>0){if(U==="{")Y++;else if(U==="}")Y--;J++;continue}if(Q){J++;continue}if(Z.paren===0&&Z.bracket===0&&Z.brace===0){if(W.slice(J,J+2)==="}}"||W.slice(J,J+3)==="!!}")break;if(U===","||U===";")break}if(U==="(")Z.paren++;else if(U===")"){if(Z.paren--,Z.paren<0)break}else if(U==="[")Z.bracket++;else if(U==="]"){if(Z.bracket--,Z.bracket<0)break}else if(U==="{")Z.brace++;else if(U==="}"){if(Z.brace--,Z.brace<0)break}J++}return{expression:W.slice($,J),endPos:J}}function GW(W){let $=[],J="",Z={paren:0,bracket:0,brace:0},Q=null,Y=0;for(let U=0;U<W.length;U++){let X=W[U];if((U>0?W[U-1]:"")==="\\"&&Q){J+=X;continue}if((X==='"'||X==="'")&&!Q){Q=X,J+=X;continue}if(X===Q&&Q!=="`"){Q=null,J+=X;continue}if(X==="`"&&!Q){Q="`",J+=X;continue}if(X==="`"&&Q==="`"&&Y===0){Q=null,J+=X;continue}if(Q==="`"&&X==="$"&&W[U+1]==="{"){Y++,J+=X+W[U+1],U++;continue}if(Y>0&&X==="{"){Y++,J+=X;continue}if(Y>0&&X==="}"){Y--,J+=X;continue}if(Q){J+=X;continue}if(X==="(")Z.paren++;else if(X===")")Z.paren--;else if(X==="[")Z.bracket++;else if(X==="]")Z.bracket--;else if(X==="{")Z.brace++;else if(X==="}")Z.brace--;if(X==="|"&&W[U+1]!=="|"&&(U===0||W[U-1]!=="|")&&W[U-1]!=="\\"&&Z.paren===0&&Z.bracket===0&&Z.brace===0){$.push(J.trim()),J="";continue}if(X==="|"&&W[U-1]==="\\"&&!Q){J=J.slice(0,-1)+X;continue}J+=X}if(J.trim())$.push(J.trim());return $}function h(W,$){let J=gJ(W,$);return J.ok?{expression:J.expression,endPos:J.endPos}:null}function gJ(W,$){let J=$;while(J<W.length&&/\s/.test(W[J]))J++;if(W[J]!=="(")return{ok:!1,reason:"missing-open-paren",pos:J};let Z=f(W,"(",")",J);if(Z===-1)return{ok:!1,reason:"unclosed-paren",pos:J};return{ok:!0,expression:W.slice(J+1,Z),endPos:Z+1}}function u(W,$,J,Z){let Q=1,Y=Z,U=new RegExp(`@${$}\\s*\\(`,"g"),X=new RegExp(`@${J}(?![a-z])`,"g");while(Y<W.length&&Q>0){U.lastIndex=Y,X.lastIndex=Y;let F=U.exec(W),q=X.exec(W),H=F?F.index:1/0,V=q?q.index:1/0;if(H<V)Q++,Y=H+F[0].length;else if(V<1/0){if(Q--,Q===0)return V;Y=V+q[0].length}else break}return-1}function lW(W,$){let J=W.slice($).match(/^@if\s*/);if(!J)return null;let Z=$+J[0].length,Q=h(W,Z);if(!Q)return null;let Y=Q.endPos,U=u(W,"if","endif",Y);if(U===-1)return null;let X=W.slice(Y,U),F=[],q=0,H="if",V=Q.expression,K=0,B=0;while(q<X.length){let _=X.indexOf("@",q);if(_===-1)break;q=_;let O=X.substring(_);if(/^@if\s*\(/.test(O)){B++,q++;continue}if(/^@endif(?![a-z])/.test(O)){B--,q+=6;continue}if(B===0){let j=O.match(/^@elseif\s*/);if(j){F.push({type:H,condition:V,content:X.substring(K,q),start:Y+K,end:Y+q});let G=q+j[0].length,z=h(X,G);if(!z){q++;continue}H="elseif",V=z.expression,q=z.endPos,K=q;continue}else if(/^@else(?![a-z])/.test(O)){F.push({type:H,condition:V,content:X.substring(K,q),start:Y+K,end:Y+q}),H="else",V=void 0,q+=5,K=q;continue}}q++}return F.push({type:H,condition:V,content:X.slice(K),start:Y+K,end:Y+X.length}),{fullMatch:W.slice($,U+6),branches:F,start:$,end:U+6}}function jW(W){let $=[],J=/@if\s*\(/g,Z=J.exec(W);while(Z!==null){if($.some((U)=>Z.index>U.start&&Z.index<U.end)){Z=J.exec(W);continue}let Y=lW(W,Z.index);if(Y)$.push(Y),J.lastIndex=Y.end;Z=J.exec(W)}return $}function PJ(W,$,J){let Z=[],Q=new RegExp(`@${$}\\s*\\(`,"g"),Y=Q.exec(W);while(Y!==null){if(Z.some((O)=>Y.index>O.start&&Y.index<O.end)){Y=Q.exec(W);continue}let X=Y.index,F=X+Y[0].length-1,q=f(W,"(",")",F);if(q===-1){Y=Q.exec(W);continue}let H=W.slice(F+1,q),V=q+1,K=u(W,$,J,V);if(K===-1){Y=Q.exec(W);continue}let B=W.slice(V,K),_=K+`@${J}`.length;Z.push({fullMatch:W.slice(X,_),name:$,params:H,content:B,start:X,end:_}),Q.lastIndex=_,Y=Q.exec(W)}return Z}function BW(W,$){let J=W.slice($).match(/^@switch\s*/);if(!J)return null;let Z=$+J[0].length,Q=h(W,Z);if(!Q)return null;let Y=Q.endPos,U=u(W,"switch","endswitch",Y);if(U===-1)return null;let X=W.slice(Y,U),F=[],q=0,H=null,V=0;while(q<X.length){let K=X.slice(q),B=K.match(/^@switch\s*\(/),_=K.match(/^@endswitch(?![a-z])/);if(B){if(V++,H)H.content+=B[0];q+=B[0].length;continue}if(_){if(V--,H)H.content+=_[0];q+=_[0].length;continue}if(V>0){if(H)H.content+=X[q];q++;continue}let O=K.match(/^@case\s*/),j=K.match(/^@default(?![a-z])/),G=K.match(/^@break(?![a-z])/);if(O&&K.startsWith("@case")){if(H)F.push(H);let z=q+O[0].length,w=h(X,z);if(!w){q++;continue}H={type:"case",value:w.expression,content:""},q=w.endPos}else if(j&&K.startsWith("@default")){if(H)F.push(H);H={type:"default",content:""},q+=j[0].length}else if(G&&K.startsWith("@break"))q+=G[0].length;else{if(H)H.content+=X[q];q++}}if(H)F.push(H);return{fullMatch:W.slice($,U+10),expression:Q.expression,cases:F,start:$,end:U+10}}var uW=()=>{};function fJ(W){let $=[],J=0;while(J<W.length){let Z=W.indexOf("{{",J),Q=W.indexOf("{!!",J),Y=!1,U;if(Z===-1&&Q===-1)break;else if(Z===-1)U=Q,Y=!0;else if(Q===-1)U=Z,Y=!1;else if(Q<Z)U=Q,Y=!0;else U=Z,Y=!1;if(!Y&&W.slice(U,U+3)==="{{{")Y=!0;let X=Y?W.slice(U,U+3)==="{{{"?"{{{":"{!!":"{{",F=Y?X==="{{{"?"}}}":"!!}":"}}",q=U+X.length,H=xJ(W,q,F);if(H===-1){J=U+1;continue}let V=W.slice(q,H).trim(),K=H+F.length;$.push({fullMatch:W.slice(U,K),expression:V,start:U,end:K,isRaw:Y}),J=K}return $}function xJ(W,$,J){let Z=$,Q=null,Y={paren:0,bracket:0,brace:0},U=0;while(Z<W.length){let X=W[Z];if((Z>0?W[Z-1]:"")==="\\"&&Q){Z++;continue}if((X==='"'||X==="'")&&!Q){Q=X,Z++;continue}if(X===Q&&Q!=="`"){Q=null,Z++;continue}if(X==="`"&&!Q){Q="`",Z++;continue}if(X==="`"&&Q==="`"&&U===0){Q=null,Z++;continue}if(Q==="`"&&X==="$"&&W[Z+1]==="{"){U++,Z+=2;continue}if(U>0){if(X==="{")U++;else if(X==="}")U--;Z++;continue}if(Q){Z++;continue}if(X==="(")Y.paren++;else if(X===")")Y.paren--;else if(X==="[")Y.bracket++;else if(X==="]")Y.bracket--;else if(X==="{")Y.brace++;else if(X==="}")Y.brace--;if(Y.paren===0&&Y.bracket===0&&Y.brace<=0){if(W.slice(Z,Z+J.length)===J)return Z}Z++}return-1}function mJ(W){let $=GW(W);if($.length===0)return{baseExpression:"",filters:[]};let J=$[0],Z=[];for(let Q=1;Q<$.length;Q++){let Y=hJ($[Q]);if(Y)Z.push(Y)}return{baseExpression:J,filters:Z}}function hJ(W){let $=W.trim();if(!$)return null;let J=$.indexOf("(");if(J===-1)return{name:$,args:[]};let Z=$.slice(0,J).trim(),Q=J+1,Y=f($,"(",")",J);if(Y===-1)return{name:Z,args:[]};let U=$.slice(Q,Y),X=iW(U);return{name:Z,args:X}}function iW(W){let $=[],J="",Z={paren:0,bracket:0,brace:0},Q=null,Y=0;for(let U=0;U<W.length;U++){let X=W[U];if((U>0?W[U-1]:"")==="\\"&&Q){J+=X;continue}if((X==='"'||X==="'")&&!Q){Q=X,J+=X;continue}if(X===Q&&Q!=="`"){Q=null,J+=X;continue}if(X==="`"&&!Q){Q="`",J+=X;continue}if(X==="`"&&Q==="`"&&Y===0){Q=null,J+=X;continue}if(Q==="`"&&X==="$"&&W[U+1]==="{"){Y++,J+="${",U++;continue}if(Y>0&&X==="{"){Y++,J+=X;continue}if(Y>0&&X==="}"){Y--,J+=X;continue}if(Q){J+=X;continue}if(X==="(")Z.paren++;else if(X===")")Z.paren--;else if(X==="[")Z.bracket++;else if(X==="]")Z.bracket--;else if(X==="{")Z.brace++;else if(X==="}")Z.brace--;if(X===","&&Z.paren===0&&Z.bracket===0&&Z.brace===0){$.push(J.trim()),J="";continue}J+=X}if(J.trim())$.push(J.trim());return $}function dJ(W,$){let J=$;while(J<W.length&&/\s/.test(W[J]))J++;if(W[J]!=="(")return null;let Z=f(W,"(",")",J);if(Z===-1)return null;return{params:W.slice(J+1,Z),endPos:Z+1}}function lJ(W){let $=[],Z=new ZW(W).tokenize().filter((Y)=>Y.type!=="WHITESPACE"&&Y.type!=="COMMENT"),Q=0;while(Q<Z.length){let Y=Z[Q],U=!1;if(Y.type==="IDENTIFIER"&&Y.value==="export"){if(U=!0,Q++,Q>=Z.length)break}let X=Z[Q];if(X.type==="IDENTIFIER"&&(X.value==="const"||X.value==="let"||X.value==="var")){let F=X.value;if(Q++,Q>=Z.length)break;let q=Z[Q];if(q.type==="IDENTIFIER"){let H=q.value;if(Q++,Q<Z.length&&Z[Q].type==="OPERATOR"&&Z[Q].value==="="){Q++;let V=Q<Z.length?Z[Q].start:W.length,K=pW(Z,Q,W);Q=K.nextIndex,$.push({type:"variable",name:H,value:W.slice(V,K.endPos),exported:U,start:X.start,end:K.endPos})}}else if(q.type==="PUNCTUATION"&&(q.value==="{"||q.value==="[")){let H=q.start,V=q.value==="{"?"}":"]",K=f(W,q.value,V,H);if(K!==-1){let B=W.slice(H,K+1);if(Q=cW(Z,K+1),Q<Z.length&&Z[Q].type==="OPERATOR"&&Z[Q].value==="="){Q++;let _=Q<Z.length?Z[Q].start:W.length,O=pW(Z,Q,W);Q=O.nextIndex;let j=`__stx_destructured_${$.length}`;$.push({type:"variable",name:j,value:`${W.slice(_,O.endPos)}; ${F} ${B} = ${j}`,exported:U,start:X.start,end:O.endPos})}}}}else if(X.type==="IDENTIFIER"&&X.value==="function"){let F=U?Z[Q-1].start:X.start;if(Q++,Q>=Z.length)break;let q=Z[Q];if(q.type==="IDENTIFIER"){let H=q.value;Q++;let V=-1;while(Q<Z.length){if(Z[Q].type==="PUNCTUATION"&&Z[Q].value==="{"){V=Z[Q].start;break}Q++}if(V!==-1){let K=f(W,"{","}",V);if(K!==-1)$.push({type:"function",name:H,value:W.slice(F,K+1).replace(/^export\s+/,""),exported:U,start:F,end:K+1}),Q=cW(Z,K+1)}}}else Q++}return $}function pW(W,$,J){let Z=$,Q={paren:0,bracket:0,brace:0},Y=$<W.length?W[$].start:J.length;while(Z<W.length){let U=W[Z];if(U.type==="PUNCTUATION"){if(U.value==="(")Q.paren++;else if(U.value===")")Q.paren--;else if(U.value==="[")Q.bracket++;else if(U.value==="]")Q.bracket--;else if(U.value==="{")Q.brace++;else if(U.value==="}")Q.brace--;if(U.value===";"&&Q.paren===0&&Q.bracket===0&&Q.brace===0){Y=U.start,Z++;break}}if(U.type==="IDENTIFIER"&&(U.value==="const"||U.value==="let"||U.value==="var"||U.value==="function"||U.value==="export")){if(Q.paren===0&&Q.bracket===0&&Q.brace===0){Y=W[Z-1]?.end??U.start;break}}Y=U.end,Z++}return{nextIndex:Z,endPos:Y}}function cW(W,$){for(let J=0;J<W.length;J++)if(W[J].start>=$)return J;return W.length}var oW=()=>{};var aW=E(()=>{uW();oW()});function uJ(W,$,J){let Z=W,Q=!0;while(Q){Q=!1;let Y=Z.match(/@switch\s*\(/);if(!Y||Y.index===void 0)break;let U=Y.index,X=BW(Z,U);if(!X)break;try{let F;if(c(X.expression))F=d(X.expression,Object.keys($))(...Object.values($));else F=P(X.expression,$);let q="",H=!1;for(let V of X.cases)if(V.type==="default"){if(!H)q=V.content.trim()}else try{let K;if(V.value&&c(V.value))K=d(V.value,Object.keys($))(...Object.values($));else if(V.value)K=P(V.value,$);if(F===K){q=V.content.trim(),H=!0;break}}catch{continue}Z=Z.substring(0,U)+q+Z.substring(X.end),Q=!0}catch(F){let q=F instanceof Error?F.message:String(F),H=o("Switch",`Error evaluating @switch expression: ${q}`,k.EVALUATION_ERROR);Z=Z.substring(0,U)+H+Z.substring(X.end);break}}return Z}function iZ(W,$,J){let Z=W;Z=uJ(Z,$,J);{let Y=!0;while(Y){Y=!1;let U=Z.match(/@unless\s*\(/);if(!U||U.index===void 0)break;let X=U.index,F=h(Z,X+7);if(!F)break;let q=F.endPos,H=u(Z,"unless","endunless",q);if(H===-1){console.warn(`[stx] @unless directive at position ${X} has no matching @endunless \u2014 the block was skipped. Check for typos or missing closers.`);break}let V=Z.slice(q,H),K=F.expression,B=-1;{let O=0,j=/@(?:if|unless)\s*\(/g,G=/@(?:endif|endunless)(?![a-z])/g,z=/@else(?![a-z])/g,w=[],I;while((I=j.exec(V))!==null)w.push({pos:I.index,type:"open"});while((I=G.exec(V))!==null)w.push({pos:I.index,type:"close"});while((I=z.exec(V))!==null)w.push({pos:I.index,type:"else"});w.sort((R,A)=>R.pos-A.pos);for(let R of w)if(R.type==="open")O++;else if(R.type==="close")O--;else if(R.type==="else"&&O===0){B=R.pos;break}}let _;if(B!==-1){let O=V.slice(0,B),j=V.slice(B+5);_=`@if (${K})${j}@else ${O}@endif`}else _=`@if (!(${K}))${V}@endif`;Z=Z.substring(0,X)+_+Z.substring(H+10),Y=!0}}Z=cJ(Z,$,J),Z=iJ(Z,$,J),Z=pJ(Z,$);let Q=()=>{let Y=jW(Z);if(Y.length===0)return!1;for(let U=Y.length-1;U>=0;U--){let X=Y[U];try{let F="",q=!1;for(let H of X.branches){if(q)break;if(H.type==="else")F=H.content,q=!0;else try{let V;if(H.condition&&c(H.condition))V=d(H.condition,Object.keys($))(...Object.values($));else if(H.condition)V=P(H.condition,$);if(V)F=H.content,q=!0}catch(V){F=o(H.type==="if"?"If":"Elseif",`Error in @${H.type}(${H.condition}): ${V instanceof Error?V.message:String(V)}`,k.EVALUATION_ERROR),q=!0}}Z=Z.substring(0,X.start)+F+Z.substring(X.end)}catch(F){let q=F instanceof Error?F.message:String(F),H=o("If",`Error processing @if block: ${q}`,k.EVALUATION_ERROR);Z=Z.substring(0,X.start)+H+Z.substring(X.end)}}return!0};while(Q());return Z}function sW(W){let $=0;while($<W.length&&/\s/.test(W[$]))$++;if(W[$]!=="(")return null;$++;while($<W.length&&/\s/.test(W[$]))$++;let J=W[$];if(J!=="'"&&J!=='"')return null;$++;let Z=[];while($<W.length){let Q=W[$];if(Q==="\\"&&$+1<W.length){Z.push(W[$+1]),$+=2;continue}if(Q===J){$++;break}Z.push(Q),$++}while($<W.length&&/\s/.test(W[$]))$++;if(W[$]!==")")return null;return $++,{value:Z.join(""),consumed:$}}function pJ(W,$){let J=W;function Z(X,F,q,H){let V=1,K=H,B=new RegExp(`@${F}(?:\\s*\\(|\\s|$)`,"g"),_=new RegExp(`@${q}(?![a-z])`,"g");while(K<X.length&&V>0){B.lastIndex=K,_.lastIndex=K;let O=B.exec(X),j=_.exec(X),G=O?O.index:1/0,z=j?j.index:1/0;if(G<z)V++,K=G+O[0].length;else if(z<1/0){if(V--,V===0)return z;K=z+j[0].length}else break}return-1}function Q(X,F,q){let H=0,V=new RegExp(`@${F}(?:\\s*\\(|\\s|$)`,"g"),K=new RegExp(`@${q}(?![a-z])`,"g"),B=/@else(?![a-z])/g,_=[],O;while((O=V.exec(X))!==null)_.push({pos:O.index,type:"open"});while((O=K.exec(X))!==null)_.push({pos:O.index,type:"close"});while((O=B.exec(X))!==null)_.push({pos:O.index,type:"else"});_.sort((j,G)=>j.pos-G.pos);for(let j of _)if(j.type==="open")H++;else if(j.type==="close")H--;else if(j.type==="else"&&H===0)return j.pos;return-1}{let X=!0;while(X){X=!1;let F=J.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!F||F.index===void 0)break;let q=F.index,H,V,K=J.slice(q+5),B=sW(K);if(B)H=B.value,V=q+5+B.consumed;else V=q+5;let _=Z(J,"auth","endauth",V);if(_===-1){console.warn(`[stx] @auth directive at position ${q} has no matching @endauth \u2014 the block was skipped.`);break}let O=J.slice(V,_),j=Q(O,"auth","endauth"),G;if(!$.auth)G=!1;else G=H?m(`auth?.check && auth?.user?.[${H}]`,$):m("auth?.check",$);let z;if(j!==-1){let w=O.slice(0,j),I=O.slice(j+5);z=G?w:I}else z=G?O:"";J=J.substring(0,q)+z+J.substring(_+8),X=!0}}{let X=!0;while(X){X=!1;let F=J.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!F||F.index===void 0)break;let q=F.index,H,V,K=J.slice(q+6),B=sW(K);if(B)H=B.value,V=q+6+B.consumed;else V=q+6;let _=Z(J,"guest","endguest",V);if(_===-1){console.warn(`[stx] @guest directive at position ${q} has no matching @endguest \u2014 the block was skipped.`);break}let O=J.slice(V,_),j=Q(O,"guest","endguest"),G;if(!$.auth)G=!0;else G=H?m(`!auth?.check || !auth?.user?.[${H}]`,$):m("!auth?.check",$);let z;if(j!==-1){let w=O.slice(0,j),I=O.slice(j+5);z=G?w:I}else z=G?O:"";J=J.substring(0,q)+z+J.substring(_+9),X=!0}}function Y(X,F,q){if($.userCan&&typeof $.userCan[X]==="boolean")return $.userCan[X];if($.permissions?.check&&typeof $.permissions.check==="function")try{let H=[X];if(F)H.push(F);if(q){let V=m(q,$);H.push(V)}return $.permissions.check(...H)}catch{return!1}return!1}function U(X){let F=X.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!F)return null;return{ability:F[1],type:F[2],id:F[3]?.trim(),paramsEnd:F[0].length}}for(let X of["can","cannot"]){let F=`end${X}`,q=X==="can"?"elsecan":"elsecannot",H=!0;while(H){H=!1;let V=J.match(new RegExp(`@${X}\\s*\\(`));if(!V||V.index===void 0)break;let K=V.index,B=J.slice(K+`@${X}`.length),_=U(B);if(!_)break;let O=K+`@${X}`.length+_.paramsEnd,j=Z(J,X,F,O);if(j===-1){console.warn(`[stx] @${X} directive at position ${K} has no matching @${F} \u2014 the block was skipped.`);break}let G=J.slice(O,j),z=[],w=0,I=new RegExp(`@${X}\\s*\\(`,"g"),R=new RegExp(`@${F}(?![a-z])`,"g"),A=new RegExp(`@${q}\\s*\\(`,"g"),L=/@else(?![a-z])/g,y=[],T;while((T=I.exec(G))!==null)y.push({pos:T.index,type:"open"});while((T=R.exec(G))!==null)y.push({pos:T.index,type:"close"});while((T=A.exec(G))!==null)y.push({pos:T.index,type:"elseDirective"});while((T=L.exec(G))!==null)y.push({pos:T.index,type:"else"});y.sort((M,b)=>M.pos-b.pos);for(let M of y){if(M.type==="open"){w++;continue}if(M.type==="close"){w--;continue}if(w===0)z.push(M)}let N=[],S=0;for(let M=0;M<z.length;M++){let b=z[M];if(N.push({content:G.slice(S,b.pos),ability:void 0}),b.type==="elseDirective"){let g=G.slice(b.pos+`@${q}`.length),v=U(g);if(v){N[N.length-1]={content:G.slice(S,b.pos)},S=b.pos+`@${q}`.length+v.paramsEnd,N.push({content:"",ability:v.ability,type:v.type,id:v.id}),N.pop();let $W=z[M+1],zW=$W?$W.pos:G.length;N.push({content:G.slice(S,zW),ability:v.ability,type:v.type,id:v.id}),S=zW}}else S=b.pos+5}if(S<G.length){let M=N[N.length-1];if(z.length>0&&z[z.length-1].type==="else")N.push({content:G.slice(S),isFinalElse:!0});else if(N.length===0)N.push({content:G.slice(S)})}let D=Y(_.ability,_.type,_.id),C=X==="can"?D:!D,x="";if(C)x=N[0]?.content||"";else{let M=!1;for(let b=1;b<N.length;b++){let g=N[b];if(g.isFinalElse){x=g.content,M=!0;break}if(g.ability){let v=Y(g.ability,g.type,g.id);if(X==="can"?v:!v){x=g.content,M=!0;break}}}if(!M&&N.length>0){let b=N[N.length-1];if(b.isFinalElse)x=b.content}}J=J.substring(0,K)+x+J.substring(j+`@${F}`.length),H=!0}}return J}function cJ(W,$,J){let Z=W;function Q(Y,U,X,F,q){let H=!0;while(H){H=!1;let V=new RegExp(`@${U}\\s*\\(`),K=Y.match(V);if(!K||K.index===void 0)break;let B=K.index,_=h(Y,B+`@${U}`.length);if(!_)break;let O=_.endPos,j=u(Y,U,X,O);if(j===-1){console.warn(`[stx] @${U} directive at position ${B} has no matching @${X} \u2014 the block was skipped.`);break}let G=Y.slice(O,j),z=_.expression,w=-1,I=0,R=0;while(R<G.length){let A=G.indexOf("@",R);if(A===-1)break;let L=G.substring(A);if(/^@(?:if|unless|isset|empty)\s*\(/.test(L)){I++,R=A+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(L)){I--,R=A+1;continue}if(I===0&&/^@else(?![a-z])/.test(L)){w=A;break}R=A+1}try{let A=F(z.trim()),L;if(w!==-1){let y=G.slice(0,w),T=G.slice(w+5);L=A?y:T}else L=A?G:"";Y=Y.substring(0,B)+L+Y.substring(j+`@${X}`.length),H=!0}catch(A){let L=A instanceof Error?A.message:String(A),y=o(q,`Error processing @${U} directive: ${L}`,k.EVALUATION_ERROR);Y=Y.substring(0,B)+y+Y.substring(j+`@${X}`.length);break}}return Y}return Z=Q(Z,"isset","endisset",(Y)=>{let U=m(Y,$);return U!==void 0&&U!==null},"Isset"),Z=Q(Z,"empty","endempty",(Y)=>{let U=m(Y,$);return U===void 0||U===null||U===""||U===0||U===!1||Array.isArray(U)&&U.length===0||typeof U==="object"&&U!==null&&Object.keys(U).length===0},"Empty"),Z}function iJ(W,$,J){let Z=W,Q="development";function Y(U,X,F,q){let H=new RegExp(`@${X}(?![a-z])`,"g"),V=new RegExp(`@${F}(?![a-z])`,"g"),K=new RegExp(`^@${X}(?![a-z])`),B=new RegExp(`^@${F}(?![a-z])`),_=U,O=!0;while(O){O=!1,H.lastIndex=0;let j=H.exec(_);if(!j)break;let G=j.index,z=G+j[0].length;if(X==="env"){let D=_.substring(z).match(/^\s*\(\s*(['"])([^'"]+)\1\s*\)/);if(!D)break;z+=D[0].length,q=Q===D[2]}let w=1,I=z,R=-1;while(w>0&&I<_.length){H.lastIndex=I,V.lastIndex=I;let D=H.exec(_),C=V.exec(_),x=D?D.index:1/0,M=C?C.index:1/0;if(x<M)w++,I=x+D[0].length;else if(M<1/0){if(w--,w===0){R=M;break}I=M+C[0].length}else break}if(R===-1){console.warn(`[stx] @${X} directive at position ${G} has no matching @${F} \u2014 the block was skipped.`);break}let A=_.substring(z,R),L=-1,y=0,T=0;while(T<A.length){let D=A.indexOf("@",T);if(D===-1)break;let C=A.substring(D);if(K.test(C)){y++,T=D+1;continue}if(B.test(C)){y--,T=D+1;continue}if(y===0&&/^@else(?![a-z])/.test(C)){L=D;break}T=D+1}let N;if(L!==-1){let D=A.slice(0,L),C=A.slice(L+5);N=q?D:C}else N=q?A:"";let S=`@${F}`.length;_=_.substring(0,G)+N+_.substring(R+S),O=!0}return _}return Z=Y(Z,"env","endenv",!1),Z=Y(Z,"production","endproduction",Q==="production"),Z=Y(Z,"development","enddevelopment",Q==="development"),Z=Y(Z,"staging","endstaging",Q==="staging"),Z=Y(Z,"testing","endtesting",Q==="testing"),Z}var oJ=E(()=>{hW();mW();aW();qW()});oJ();export{uJ as processSwitchStatements,cJ as processIssetEmptyDirectives,iJ as processEnvDirective,iZ as processConditionals,pJ as processAuthDirectives};
