// @bun
var{defineProperty:F,getOwnPropertyNames:I,getOwnPropertyDescriptor:J}=Object,K=Object.prototype.hasOwnProperty;function L(j){return this[j]}var V=(j)=>{var q=(H??=new WeakMap).get(j),w;if(q)return q;if(q=F({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var y of I(j))if(!K.call(q,y))F(q,y,{get:L.bind(j,y),enumerable:!(w=J(j,y))||w.enumerable})}return H.set(j,q),q},H;var O=(j)=>j;function Q(j,q){this[j]=O.bind(null,q)}var R=(j,q)=>{for(var w in q)F(j,w,{get:q[w],enumerable:!0,configurable:!0,set:Q.bind(q,w)})};var S=(j,q)=>()=>(j&&(q=j(j=0)),q);var M=import.meta.require;var $={};R($,{timingPlugin:()=>Z,pluginManager:()=>U,definePlugin:()=>D,debugPlugin:()=>Y,createVariablesPlugin:()=>_,createFilterPlugin:()=>X,createDirectivePlugin:()=>W,PluginManager:()=>G});function D(j){return j}class G{plugins=new Map;sortedPlugins=[];initialized=!1;async register(j,q){if(this.plugins.has(j.name))throw Error(`Plugin "${j.name}" is already registered`);if(j.dependencies){for(let w of j.dependencies)if(!this.plugins.has(w))throw Error(`Plugin "${j.name}" depends on "${w}" which is not registered`)}if(this.plugins.set(j.name,j),j.onRegister)await j.onRegister(q);this.sortPlugins()}async unregister(j){let q=this.plugins.get(j);if(!q)return!1;for(let[w,y]of this.plugins)if(y.dependencies?.includes(j))throw Error(`Cannot unregister "${j}" because "${w}" depends on it`);if(q.onUnregister)await q.onUnregister();return this.plugins.delete(j),this.sortPlugins(),!0}get(j){return this.plugins.get(j)}has(j){return this.plugins.has(j)}getAll(){return[...this.sortedPlugins]}getAllDirectives(){let j=[];for(let q of this.sortedPlugins)if(q.registerDirectives)j.push(...q.registerDirectives());return j}getAllFilters(){let j={};for(let q of this.sortedPlugins)if(q.registerFilters)Object.assign(j,q.registerFilters());return j}async runBeforeProcess(j){return this.runHooks("beforeProcess",j)}async runAfterParse(j){return this.runHooks("afterParse",j)}async runBeforeDirective(j,q){return this.runDirectiveHooks("beforeDirective",j,q)}async runAfterDirective(j,q){return this.runDirectiveHooks("afterDirective",j,q)}async runBeforeRender(j){return this.runHooks("beforeRender",j)}async runAfterRender(j){return this.runHooks("afterRender",j)}async runOnError(j){for(let q of this.sortedPlugins)if(q.onError)try{let w=await q.onError(j);if(w){if(w.template!==void 0)j.template=w.template;if(w.context)j.context={...j.context,...w.context};if(w.metadata)j.metadata={...j.metadata,...w.metadata};if(w.skip)return j}}catch(w){console.error(`Error in plugin "${q.name}" onError hook:`,w)}return null}sortPlugins(){this.sortedPlugins=Array.from(this.plugins.values()).sort((j,q)=>(j.priority??100)-(q.priority??100))}async runHooks(j,q){let w={...q};for(let y of this.sortedPlugins){let B=y[j];if(B)try{let z=await B(w);if(z){if(z.template!==void 0)w.template=z.template;if(z.context)w.context={...w.context,...z.context};if(z.metadata)w.metadata={...w.metadata,...z.metadata};if(z.skip)break}}catch(z){console.error(`Error in plugin "${y.name}" ${j} hook:`,z)}}return w}async runDirectiveHooks(j,q,w){let y={...w};for(let B of this.sortedPlugins){let z=B[j];if(z)try{let A=await z(q,y);if(A){if(A.template!==void 0)y.template=A.template;if(A.context)y.context={...y.context,...A.context};if(A.metadata)y.metadata={...y.metadata,...A.metadata};if(A.skip)break}}catch(A){console.error(`Error in plugin "${B.name}" ${j} hook:`,A)}}return y}}function W(j,q,w={}){return{name:j,...w,registerDirectives:()=>q}}function X(j,q,w={}){return{name:j,...w,registerFilters:()=>q}}function _(j){return D({name:"stx-variables",version:"1.0.0",description:"Adds predefined variables to template context",beforeProcess(q){return{context:{...q.context,...j}}}})}var U,Y,Z;var E=S(()=>{U=new G;Y=D({name:"stx-debug",version:"1.0.0",description:"Logs all plugin lifecycle events for debugging",priority:0,beforeProcess(j){console.log("[stx-debug] beforeProcess:",j.filePath)},afterParse(j){console.log("[stx-debug] afterParse:",j.template.length,"chars")},beforeDirective(j,q){console.log("[stx-debug] beforeDirective:",j)},afterDirective(j,q){console.log("[stx-debug] afterDirective:",j)},beforeRender(j){console.log("[stx-debug] beforeRender")},afterRender(j){console.log("[stx-debug] afterRender:",j.template.length,"chars")},onError(j){console.error("[stx-debug] onError:",j.error.message,"in phase:",j.phase)}}),Z=D({name:"stx-timing",version:"1.0.0",description:"Measures template processing time",priority:1,beforeProcess(j){j.metadata.startTime=performance.now()},afterRender(j){let q=j.metadata.startTime;if(q){let w=performance.now()-q;console.log(`[stx-timing] Processing took ${w.toFixed(2)}ms`)}}})});E();export{Z as timingPlugin,U as pluginManager,D as definePlugin,Y as debugPlugin,_ as createVariablesPlugin,X as createFilterPlugin,W as createDirectivePlugin,G as PluginManager};
