// @bun
var{defineProperty:x,getOwnPropertyNames:BF,getOwnPropertyDescriptor:QF}=Object,WF=Object.prototype.hasOwnProperty;function qF(F){return this[F]}var rF=(F)=>{var U=(p??=new WeakMap).get(F),O;if(U)return U;if(U=x({},"__esModule",{value:!0}),F&&typeof F==="object"||typeof F==="function"){for(var j of BF(F))if(!WF.call(U,j))x(U,j,{get:qF.bind(F,j),enumerable:!(O=QF(F,j))||O.enumerable})}return p.set(F,U),U},p;var GF=(F)=>F;function TF(F,U){this[F]=GF.bind(null,U)}var aF=(F,U)=>{for(var O in U)x(F,O,{get:U[O],enumerable:!0,configurable:!0,set:TF.bind(U,O)})};var A=(F,U)=>()=>(F&&(U=F(F=0)),U);var M=import.meta.require;class XF{cache=new Map;maxSize;constructor(F=100){this.maxSize=F}get(F){if(!this.cache.has(F))return;let U=this.cache.get(F);return this.cache.delete(F),this.cache.set(F,U),U}set(F,U){if(this.cache.has(F))this.cache.delete(F);else if(this.cache.size>=this.maxSize){let O=this.cache.keys().next().value;if(O!==void 0)this.cache.delete(O)}this.cache.set(F,U)}has(F){return this.cache.has(F)}delete(F){return this.cache.delete(F)}clear(){this.cache.clear()}get size(){return this.cache.size}keys(){return this.cache.keys()}values(){return this.cache.values()}}function w(F,U){if(U?.includes("g"))return new RegExp(F,U);let O=`${F}:${U||""}`;if(!D.has(O)){if(D.size>=IF){let j=D.keys().next().value;if(j)D.delete(j)}D.set(O,new RegExp(F,U))}return D.get(O)}function eF(){D.clear()}class _F{cache=new Map;maxSize;ttl;constructor(F=1000,U=300000){this.maxSize=F,this.ttl=U}get(F){let U=this.cache.get(F);if(!U)return null;if(Date.now()-U.timestamp>this.ttl)return this.cache.delete(F),null;return U.result}set(F,U,O=new Set){if(this.cache.size>=this.maxSize){let j=this.cache.keys().next().value;if(j)this.cache.delete(j)}this.cache.set(F,{result:U,timestamp:Date.now(),dependencies:O})}invalidateDependency(F){let U=0;for(let[O,j]of this.cache.entries())if(j.dependencies.has(F))this.cache.delete(O),U++;return U}clear(){this.cache.clear()}getStats(){return{size:this.cache.size,maxSize:this.maxSize}}}function FO(F,U){let O;return(...j)=>{if(O)clearTimeout(O);O=setTimeout(()=>{F(...j)},U)}}function OO(F,U){let O=0,j;return(...J)=>{let N=Date.now();if(N-O>=U)O=N,j=F(...J);return j}}function UO(F,U=100){let O=new Map;return(...j)=>{let J;try{J=JSON.stringify(j)}catch{return F(...j)}if(O.has(J))return O.get(J);if(O.size>=U){let Y=O.keys().next().value;if(Y)O.delete(Y)}let N=F(...j);return O.set(J,N),N}}function jO(F,U,O,j){if(typeof U==="string"){let J=w(U,j);if(typeof O==="string"&&j?.includes("i")){let N=O;return F.replace(J,(Y)=>{if(Y===Y.toUpperCase()&&Y!==Y.toLowerCase())return N.toUpperCase();else if(Y[0]===Y[0].toUpperCase()&&Y[0]!==Y[0].toLowerCase())return N[0].toUpperCase()+N.slice(1).toLowerCase();else return N.toLowerCase()})}return F.replace(J,O)}return F.replace(U,O)}class m{pool=[];maxPoolSize=10;fnCache=new Map;fnCacheMaxSize=200;getEvaluator(F){let U=Array.from(new Set(F)),O=U.sort().join(","),j=this.pool.find(($)=>$.context.join(",")===O);if(j)return j.func;let J=this.fnCache,N=this.fnCacheMaxSize,Y=(...$)=>{return(Z)=>{try{let V=`${O}:${Z}`,B=J.get(V);if(!B){if(J.size>=N){let Q=J.keys().next().value;if(Q)J.delete(Q)}B=Function(...U,`
              'use strict';
              try {
                return ${Z};
              }
catch (e) {
                if (e instanceof ReferenceError || e instanceof TypeError) {
                  return undefined;
                }
                throw e;
              }
            `),J.set(V,B)}return B(...$)}catch{return}}};if(this.pool.length<this.maxPoolSize)this.pool.push({func:Y,context:U.slice()});return Y}clear(){this.pool.length=0,this.fnCache.clear()}}class c{metrics=new Map;budgets=new Map;violations=[];maxViolations=100;violationHandlers=[];enabled=!0;setEnabled(F){this.enabled=F}isEnabled(){return this.enabled}setBudget(F,U){this.budgets.set(F,{warnThreshold:0.8,action:"warn",...U})}setBudgets(F){for(let[U,O]of Object.entries(F))this.setBudget(U,O)}removeBudget(F){this.budgets.delete(F)}getBudgets(){let F={};for(let[U,O]of this.budgets.entries())F[U]=O;return F}onViolation(F){this.violationHandlers.push(F)}offViolation(F){let U=this.violationHandlers.indexOf(F);if(U!==-1)this.violationHandlers.splice(U,1)}time(F,U){if(!this.enabled)return U();let O=performance.now(),j=U(),J=performance.now()-O;return this.recordTime(F,J),this.checkBudget(F,J),j}async timeAsync(F,U){if(!this.enabled)return U();let O=performance.now(),j=await U(),J=performance.now()-O;return this.recordTime(F,J),this.checkBudget(F,J),j}checkBudget(F,U){let O=this.budgets.get(F);if(!O)return;let j=U/O.maxTime*100,J=O.warnThreshold!==void 0?U>=O.maxTime*O.warnThreshold&&U<O.maxTime:!1,N=U>=O.maxTime;if(!J&&!N)return;let Y={label:F,actualTime:U,budgetTime:O.maxTime,exceedancePercent:j,timestamp:new Date,isWarning:J};this.violations.push(Y);while(this.violations.length>this.maxViolations)this.violations.shift();for(let Z of this.violationHandlers)try{Z(Y)}catch{}let $=J?`[Performance Warning] "${F}" took ${U.toFixed(2)}ms (${j.toFixed(1)}% of ${O.maxTime}ms budget)`:`[Performance Budget Exceeded] "${F}" took ${U.toFixed(2)}ms (exceeded ${O.maxTime}ms budget by ${(j-100).toFixed(1)}%)`;switch(O.action){case"log":console.log($);break;case"warn":console.warn($);break;case"error":console.error($);break;case"throw":if(N)throw Error($);else console.warn($);break}}recordTime(F,U){let O=this.metrics.get(F);if(O)O.count++,O.totalTime+=U,O.maxTime=Math.max(O.maxTime,U),O.minTime=Math.min(O.minTime,U);else this.metrics.set(F,{count:1,totalTime:U,maxTime:U,minTime:U})}getStats(F){if(F){let O=this.metrics.get(F);if(!O)return{};let j=this.budgets.get(F);return{count:O.count,avgTime:O.totalTime/O.count,totalTime:O.totalTime,maxTime:O.maxTime,minTime:O.minTime,budget:j?.maxTime,budgetUtilization:j?O.totalTime/O.count/j.maxTime*100:void 0}}let U={};for(let[O,j]of this.metrics.entries()){let J=this.budgets.get(O);U[O]={count:j.count,avgTime:j.totalTime/j.count,totalTime:j.totalTime,maxTime:j.maxTime,minTime:j.minTime,budget:J?.maxTime,budgetUtilization:J?j.totalTime/j.count/J.maxTime*100:void 0}}return U}getViolations(F){if(F)return this.violations.filter((U)=>U.label===F);return[...this.violations]}getViolationStats(){let F={},U=0,O=0;for(let j of this.violations)if(F[j.label]=(F[j.label]||0)+1,j.isWarning)U++;else O++;return{total:this.violations.length,byLabel:F,warnings:U,errors:O}}clear(){this.metrics.clear()}clearViolations(){this.violations.length=0}clearBudgets(){this.budgets.clear()}reset(){this.clear(),this.clearViolations(),this.clearBudgets(),this.violationHandlers.length=0}}function d(){if(!z)z=new c;return z}function YO(F=d()){F.setBudgets(AF)}function $O(){z=null}var D,IF=500,JO,AF,z=null,NO;var s=A(()=>{D=new Map;JO=new m;AF={processDirectives:{maxTime:500,warnThreshold:0.8,action:"warn"},processTemplate:{maxTime:200,warnThreshold:0.8,action:"warn"},processIncludes:{maxTime:100,warnThreshold:0.8,action:"warn"},processLoops:{maxTime:50,warnThreshold:0.8,action:"warn"},processConditionals:{maxTime:50,warnThreshold:0.8,action:"warn"},processExpressions:{maxTime:100,warnThreshold:0.8,action:"warn"},renderComponent:{maxTime:150,warnThreshold:0.8,action:"warn"},buildWebComponents:{maxTime:1000,warnThreshold:0.8,action:"warn"}};NO=new Proxy({},{get(F,U){return d()[U]}})});function RF(F){l=F}function HF(){return l}function KF(F){S={...S,...F}}function MF(){S={}}function o(F,U={}){let O=S[F]||DF[F]||{message:`Unknown error (code: ${F})`},j=O.message,J=O.help;for(let[N,Y]of Object.entries(U)){let $=`{{${N}}}`;if(j=j.replace(new RegExp($,"g"),Y),J)J=J.replace(new RegExp($,"g"),Y)}return{message:j,help:J}}function wF(F,U={}){let{message:O,help:j}=o(F,U);return j?`${O}
  Help: ${j}`:O}function y(F){for(let[U,O]of Object.entries(_))if(O===F)return U;return}var DF,S,l="en",_;var k=A(()=>{DF={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"}},S={};_={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 LF(){return!1}function E(){return!LF()||process.env.STX_DEBUG==="true"}function BO(){return!1}import zF from"path";function SF(F){K={...K,...F}}function C(){return{...K}}function kF(){K={...i}}function b(F){if(!K.showRelativePaths||!F)return F;let U=K.baseDir||process.cwd();try{let O=zF.relative(U,F);return O.startsWith("..")?F:O}catch{return F}}var i,K,R,n,r,a,t,e;var P=A(()=>{k();i={showRelativePaths:!1,enableAutoRecovery:E(),logRecoveryWarnings:!0},K={...i};R=class R extends Error{code;filePath;line;column;context;numericCode;constructor(F,U,O,j,J,N,Y){super(F);this.code=U;this.filePath=O;this.line=j;this.column=J;this.context=N;if(this.name="StxError",this.numericCode=Y||_.EVALUATION_ERROR,this.filePath)this.filePath=b(this.filePath)}};n=class n extends R{constructor(F,U,O,j,J,N){super(F,"stx_SYNTAX_ERROR",U,O,j,J,N||_.INVALID_DIRECTIVE_SYNTAX);this.name="StxSyntaxError"}};r=class r extends R{constructor(F,U,O,j,J,N){super(F,"stx_RUNTIME_ERROR",U,O,j,J,N||_.EVALUATION_ERROR);this.name="StxRuntimeError"}};a=class a extends R{constructor(F,U,O,j,J,N){super(F,"stx_SECURITY_ERROR",U,O,j,J,N||_.UNSAFE_EXPRESSION);this.name="StxSecurityError"}};t=class t extends R{constructor(F,U,O,j,J,N){super(F,"stx_FILE_ERROR",U,O,j,J,N||_.FILE_NOT_FOUND);this.name="StxFileError"}};e=class e extends R{isFatal=!0;constructor(F,U,O,j,J,N){super(F,"stx_VALIDATION_ERROR",U,O,j,J,N||_.DOM_API_VIOLATION);this.name="StxValidationError"}}});function g(F){let{type:U,message:O,code:j,filePath:J,line:N,column:Y,template:$,offset:Z,snippet:V,suggestion:B,format:Q="text"}=F,W=N,q=Y;if(!W&&$&&Z!==void 0){let H=OF($,Z);W=H.line,q=H.column}let G=J?b(J):void 0,T=j?y(j):void 0,X={type:U,code:j,codeName:T,message:O,filePath:G,line:W,column:q,snippet:V,suggestion:B,timestamp:new Date().toISOString()},I;switch(Q){case"html":I=bF(X);break;case"json":I=JSON.stringify(X,null,2);break;case"console":I=PF(X,$,Z);break;case"text":default:I=CF(X,$,Z);break}return{formatted:I,data:X}}function CF(F,U,O){let j=[],J=F.code?` [${F.codeName||F.code}]`:"";if(j.push(`[${F.type} Error${J}]`),F.filePath){let N=F.filePath;if(F.line){if(N+=`:${F.line}`,F.column)N+=`:${F.column}`}j.push(`at ${N}`)}if(j.push(`
${F.message}`),U&&F.line){let N=vF(U,F.line,2);if(N)j.push(`
${N}`)}if(F.snippet)j.push(`
Snippet: ${F.snippet}`);if(F.suggestion)j.push(`
Suggestion: ${F.suggestion}`);return j.join(" ")}function bF(F){let U=F.code?` [${F.code}]`:"",O=F.filePath?` in ${F.filePath}${F.line?`:${F.line}`:""}`:"",j=`<!-- [${F.type} Error${U}]${O}: ${FF(F.message)}`;if(F.suggestion)j+=` | Suggestion: ${FF(F.suggestion)}`;return j+=" -->",j}function PF(F,U,O){let V=[],B=F.code?` [${F.codeName||F.code}]`:"";if(V.push(`\x1B[1m${"\x1B[31m"}\u2501\u2501\u2501 ${F.type} Error${B} \u2501\u2501\u2501${"\x1B[0m"}`),F.filePath){let Q=`\x1B[36m${F.filePath}\x1B[0m`;if(F.line){if(Q+=`\x1B[90m:${F.line}\x1B[0m`,F.column)Q+=`\x1B[90m:${F.column}\x1B[0m`}V.push(`
\x1B[90mat\x1B[0m ${Q}`)}if(V.push(`

${F.message}`),U&&F.line){let Q=xF(U,F.line,2);if(Q)V.push(`

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

\x1B[33mSuggestion:\x1B[0m ${F.suggestion}`);return V.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"}`),V.join("")}function vF(F,U,O){let j=F.split(`
`),J=Math.max(0,U-O-1),N=Math.min(j.length-1,U+O-1),Y=[];for(let $=J;$<=N;$++){let Z=($+1).toString().padStart(4),V=$===U-1?">":" ";Y.push(`${V}${Z} | ${j[$]}`)}return Y.join(`
`)}function xF(F,U,O){let j=F.split(`
`),J=Math.max(0,U-O-1),N=Math.min(j.length-1,U+O-1),Y="\x1B[90m",$="\x1B[31m",Z="\x1B[0m",V=[];for(let B=J;B<=N;B++){let Q=(B+1).toString().padStart(4),W=B===U-1,q=W?"\x1B[31m>\x1B[0m":" ",G=W?`\x1B[31m${j[B]}\x1B[0m`:`\x1B[90m${j[B]}\x1B[0m`;V.push(`${q}\x1B[90m${Q}\x1B[0m | ${G}`)}return V.join(`
`)}function FF(F){return F.replace(/--/g,"- -").replace(/>/g,"&gt;")}function OF(F,U){let j=F.substring(0,U).split(`
`);return{line:j.length,column:j[j.length-1].length}}function L(F,U,O){return g({type:F,message:U,code:O,format:"html"}).formatted}function yF(F,U,O,j,J){return g({type:F,message:U,code:J,filePath:O,line:j,format:"console"}).formatted}function gF(F,U,O){let j=O.template.split(`
`),J=OF(O.template,O.offset),N=`[${F} Error at line ${J.line} in ${O.filePath}]: ${U}

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

`),"utf-8")}}async flush(){await this.writeQueue}}var uF,pF,mF;var jF=A(()=>{P();uF={isEnabled(){return C().enableAutoRecovery},fixCommonSyntaxErrors(F){let U=C();if(!U.enableAutoRecovery)return{fixed:F,fixes:[]};let O=F,j=[],J=(O.match(/\{\{/g)||[]).length,N=(O.match(/\}\}/g)||[]).length;if(J>N){let $=J-N;O+="}}".repeat($),j.push(`Added ${$} missing closing braces '}}'`)}let Y=["if","foreach","for","switch","section"];for(let $ of Y){let Z=(O.match(new RegExp(`@${$}\\b`,"g"))||[]).length,V=(O.match(new RegExp(`@end${$}\\b`,"g"))||[]).length;if(Z>V){let B=Z-V;for(let Q=0;Q<B;Q++)O+=`
@end${$}`;j.push(`Added ${B} missing @end${$}`)}}if(j.length>0&&U.logRecoveryWarnings)console.warn("[stx] Auto-recovery applied fixes:"),j.forEach(($)=>console.warn(`  - ${$}`)),console.warn("  Consider fixing these issues in your template.");return{fixed:O,fixes:j}},createFallbackContent(F,U){if(E())return`<!-- ${F} failed: ${U.message} -->`;return"<!-- stx rendering error -->"}};pF=new h,mF={isDevelopment(){return E()},logDetailedError(F,U){if(!this.isDevelopment())return;if(console.error("=== stx Detailed Error ==="),console.error("Error:",F.message),console.error("Stack:",F.stack),U)console.error("Context:",U);console.error("========================")},createErrorReport(F,U){let O=["=== stx Error Report ===",`Time: ${new Date().toISOString()}`,`Error: ${F.message}`,`Type: ${F.constructor.name}`,`Stack: ${F.stack}`];if(U)O.push(`Context: ${JSON.stringify(U,null,2)}`);return O.push("========================"),O.join(`
`)}}});import f from"path";function cF(F){let U={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return F.replace(/[&<>"']/g,(O)=>U[O]||O)}function v(F,U={}){let{allowHtml:O=!1,maxLength:j=1e4,allowSpecialChars:J=!0,customSanitizer:N}=U,Y=[],$=F,Z=!1;if(N){let B=N($);if(B!==$)$=B,Z=!0}if($.includes("\x00"))$=$.replace(/\0/g,""),Z=!0,Y.push("Null bytes removed from parameter");if($.length>j)$=$.substring(0,j),Z=!0,Y.push(`Parameter truncated to ${j} characters`);if(!O&&/<[^>]+>/.test($))$=cF($),Z=!0,Y.push("HTML content was escaped");let V=[{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:B,replacement:Q,name:W}of V)if(B.test($))$=$.replace(B,Q),Z=!0,Y.push(`Removed ${W} from parameter`);if(!J){let B=$;if($=$.split("").filter((Q)=>{let W=Q.charCodeAt(0);return W>=32&&W!==127}).join(""),$!==B)Z=!0,Y.push("Control characters removed")}return{value:$,modified:Z,warnings:Y}}function dF(F,U){let O=F.replace(/\0/g,"");O=O.replace(/\\/g,"/"),O=O.replace(/^[a-z][a-z0-9+.-]*:/i,"");while(O.includes("../")||O.includes("./"))O=O.replace(/\.\.\//g,"").replace(/\.\//g,"");if(!u.isValidFilePath(O,U))return null;return O}function sF(F){let U=[],O=F.trim(),j=O!==F,J=[{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:N,name:Y}of J)if(N.test(O))U.push(`Potentially dangerous pattern detected: ${Y}`);if(O.includes("\x00"))O=O.replace(/\0/g,""),j=!0,U.push("Null bytes removed from expression");return{value:O,modified:j,warnings:U}}function lF(F,U={}){return F.map((O)=>v(O,U))}function JF(F){let U={};for(let[O,j]of Object.entries(F)){if(!u.isValidVariableName(O))continue;if(typeof j==="string"){let J=v(j);U[O]=J.value}else if(Array.isArray(j))U[O]=j.map((J)=>typeof J==="string"?v(J).value:J);else if(typeof j==="object"&&j!==null)U[O]=JF(j);else U[O]=j}return U}var u;var NF=A(()=>{u={isValidFilePath(F,U){let O=F.replace(/\\/g,"/");if(O.includes("\x00"))return!1;if(O.includes("../")||O.includes("..\\")||O===".."||O.startsWith("../")||O.endsWith("/..")||O.includes("/..\\")||O.includes("\\../"))return!1;if(/^[a-z][a-z0-9+.-]*:/i.test(O))return!1;if(O.startsWith("/")){if(["/etc/","/root/","/var/","/usr/","/bin/","/sbin/","/proc/","/sys/","/dev/","/boot/","/home/","/private/","/Library/","/System/"].some((N)=>O===N.slice(0,-1)||O.startsWith(N)))return!1}if(/^[a-z]:/i.test(O)){if(["Windows/","Windows\\","System32/","System32\\","Program Files/","Program Files\\"].some((N)=>O.includes(N)))return!1}if(U){let J=f.resolve(U,F),N=f.resolve(U);if(!J.startsWith(N+f.sep)&&J!==N)return!1}return!0},isValidVariableName(F){return/^[a-z_$]\w*$/i.test(F)},isValidDirectiveName(F){return/^[a-z][\w-]*$/i.test(F)},isSafeContent(F){return![/<script[^>]*>[\s\S]*?<\/script>/i,/javascript:/i,/data:text\/html/i,/vbscript:/i,/on\w+\s*=/i].some((O)=>O.test(F))}}});var YF=A(()=>{k();UF();jF();NF();P()});var $F=A(()=>{YF()});async function vO(F,U,O,j){if(!j.customDirectives||j.customDirectives.length===0)return F;let J=F;for(let N of j.customDirectives){if(!N.name||typeof N.handler!=="function"){if(j.debug)console.warn("Invalid custom directive:",N);continue}if(N.hasEndTag)J=await oF(J,N,U,O,j);else J=await iF(J,N,U,O,j)}return J}async function oF(F,U,O,j,J){let{name:N,handler:Y}=U,$=`@${N}`,Z=`@end${N}`,V=F,B=w(`${$}(?:\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\))?([\\s\\S]*?)${Z}`,"g"),Q=[],W=B.exec(V);while(W!==null){let[q,G="",T=""]=W,X=W.index||0;try{let I=G?ZF(G):[],H=T.trim(),VF=await Y(H,I,O,j);Q.push({original:q,processed:VF,startIndex:X})}catch(I){let H=I instanceof Error?I.message:String(I);if(J.debug)console.error(`Error processing custom directive @${N}:`,I);Q.push({original:q,processed:L("CustomDirective",`Error in @${N}${G?`(${G})`:""}: ${H}`,_.EVALUATION_ERROR),startIndex:X})}W=B.exec(V)}for(let q=Q.length-1;q>=0;q--){let{original:G,processed:T}=Q[q];V=V.replace(G,T)}return V}async function iF(F,U,O,j,J){let{name:N,handler:Y}=U,$=F,Z=w(`@${N}\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\)`,"g"),V=[],B=Z.exec($);while(B!==null){let[q,G=""]=B,T=B.index||0;try{let X=ZF(G),I=await Y("",X,O,j);V.push({original:q,processed:I,startIndex:T})}catch(X){let I=X instanceof Error?X.message:String(X);if(J.debug)console.error(`Error processing custom directive @${N}:`,X);V.push({original:q,processed:L("CustomDirective",`Error in @${N}(${G}): ${I}`,_.EVALUATION_ERROR),startIndex:T})}B=Z.exec($)}let Q=w(`@${N}(?!\\w)(?!\\s*\\()`,"g"),W=Q.exec($);while(W!==null){let[q]=W,G=W.index||0;try{let T=await Y("",[],O,j);V.push({original:q,processed:T,startIndex:G})}catch(T){let X=T instanceof Error?T.message:String(T);if(J.debug)console.error(`Error processing custom directive @${N}:`,T);V.push({original:q,processed:L("CustomDirective",`Error in @${N}: ${X}`,_.EVALUATION_ERROR),startIndex:G})}W=Q.exec($)}for(let q=V.length-1;q>=0;q--){let{original:G,processed:T}=V[q];$=$.replace(G,T)}return $}function ZF(F){if(!F.trim())return[];let U=[],O="",j=!1,J="";for(let N=0;N<F.length;N++){let Y=F[N];if((Y==='"'||Y==="'")&&(N===0||F[N-1]!=="\\"))if(!j)j=!0,J=Y;else if(Y===J)j=!1;else O+=Y;else if(Y===","&&!j)U.push(O.trim()),O="";else O+=Y}if(O.trim())U.push(O.trim());return U.map((N)=>{let Y=N.trim();if(Y.startsWith('"')&&Y.endsWith('"')||Y.startsWith("'")&&Y.endsWith("'"))return Y.substring(1,Y.length-1);return Y})}var nF=A(()=>{$F();s()});nF();export{vO as processCustomDirectives};
