@stacksjs/stx 0.2.78 → 0.2.79

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.
Files changed (49) hide show
  1. package/dist/app-shell.js +1 -1
  2. package/dist/build-mode-detector.js +1 -1
  3. package/dist/build-views.js +1 -1
  4. package/dist/build.js +1 -1
  5. package/dist/cli.js +2 -2
  6. package/dist/component-processing.js +1 -1
  7. package/dist/component-renderer.js +1 -1
  8. package/dist/components.js +1 -1
  9. package/dist/conditionals.js +1 -1
  10. package/dist/dev-server/index.js +1 -1
  11. package/dist/dev-server/serve-app.js +1 -1
  12. package/dist/dev-server/serve-file.js +1 -1
  13. package/dist/dev-server/serve-markdown.js +1 -1
  14. package/dist/dev-server/serve-multi.js +1 -1
  15. package/dist/dev-server.js +1 -1
  16. package/dist/docs.js +1 -1
  17. package/dist/dynamic-components.js +1 -1
  18. package/dist/includes.js +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/interactive.js +1 -1
  21. package/dist/lazy-loader.js +1 -1
  22. package/dist/loops.js +1 -1
  23. package/dist/plugin.js +1 -1
  24. package/dist/process.js +1 -1
  25. package/dist/production-builder.js +1 -1
  26. package/dist/production-server.js +1 -1
  27. package/dist/pwa/index.js +1 -1
  28. package/dist/pwa/offline.js +1 -1
  29. package/dist/pwa.js +1 -1
  30. package/dist/render.js +1 -1
  31. package/dist/serve.js +1 -1
  32. package/dist/site-builder/build.js +1 -1
  33. package/dist/site-builder/index.js +1 -1
  34. package/dist/ssg.js +1 -1
  35. package/dist/ssr.js +1 -1
  36. package/dist/story/cli.js +1 -1
  37. package/dist/story/commands/dev.js +1 -1
  38. package/dist/story/commands/index.js +1 -1
  39. package/dist/story/index.js +1 -1
  40. package/dist/story/renderer.js +1 -1
  41. package/dist/story/server.js +1 -1
  42. package/dist/story/visual-testing.js +1 -1
  43. package/dist/streaming.js +1 -1
  44. package/dist/template-compiler.js +1 -1
  45. package/dist/template-hydrator.js +1 -1
  46. package/dist/testing.js +1 -1
  47. package/dist/utils.js +1 -1
  48. package/dist/web-components.js +1 -1
  49. package/package.json +5 -5
@@ -2435,7 +2435,7 @@ window.__stx_reactive = (function() {
2435
2435
  ${FG()}
2436
2436
  ${Y}
2437
2437
  </script>`}function B8($,Z,Y){if(_8=0,!AG($))return $;let X=jG($);if(X.length===0)return $;let Q=wG($,X),J=VG(X,Z),G=Q.lastIndexOf("</body>");if(G!==-1)Q=Q.slice(0,G)+J+`
2438
- `+Q.slice(G);else Q+=J;return Q}function wG($,Z){let Y=$;for(let X of Z){let J=new RegExp(`<[a-z][a-z0-9-]*\\s+[^>]*data-stx-scope="([^"]*)"[^>]*x-data\\s*=\\s*["']${V$(X.stateExpr)}["']`,"gi").exec(Y);if(J)X.id=J[1],X.selector=`[data-stx-scope="${X.id}"]`;else{let K=new RegExp(`<[a-z][a-z0-9-]*\\s+[^>]*x-data\\s*=\\s*["']${V$(X.stateExpr)}["'][^>]*data-stx-scope="([^"]*)"`,"gi").exec(Y);if(K)X.id=K[1],X.selector=`[data-stx-scope="${X.id}"]`;else Y=Y.replace(new RegExp(`(<[a-z][a-z0-9-]*\\s+)([^>]*)(x-data\\s*=\\s*"${V$(X.stateExpr)}")([^>]*>)`,"gi"),`$1data-stx-scope="${X.id}" $2$3$4`),Y=Y.replace(new RegExp(`(<[a-z][a-z0-9-]*\\s+)([^>]*)(x-data\\s*=\\s*'${V$(X.stateExpr)}')([^>]*>)`,"gi"),`$1data-stx-scope="${X.id}" $2$3$4`)}}return Y=Y.replace(/\s*x-data\s*=\s*"([^"]*)"/g,' data-stx-xdata="$1"'),Y=Y.replace(/\s*x-data\s*=\s*'([^']*)'/g," data-stx-xdata='$1'"),Y=Y.replace(/\s*x-init\s*=\s*"[^"]*"/g,""),Y=Y.replace(/\s*x-init\s*=\s*'[^']*'/g,""),Y}function AG($){return/x-data\s*=\s*["']/.test($)}var _8=0,BG=0;var j8=y(()=>{c0()});import RG from"fs";import q7 from"path";import{createHighlighter as NG}from"ts-syntax-highlighter";async function TG($,Z={}){try{if(!await l($))throw Error(`Markdown file not found: ${$}`);let X=(await RG.promises.stat($)).mtime.getTime();if(Z.cache&&z7.has($)){let U=z7.get($);if(U.updatedAt>=X)return{content:U.content,data:U.data}}let Q=await Bun.file($).text(),{data:J,content:G}=N6(Q),K=Z.markdown||X7.markdown||{enabled:!0,syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}},W=K5(G,{gfm:!0});if(K.syntaxHighlighting?.enabled&&K.syntaxHighlighting?.serverSide)W=await MG(W,K.syntaxHighlighting?.defaultTheme||"github-dark",K.syntaxHighlighting?.highlightUnknownLanguages||!1);let z={content:W,data:J||{}};if(Z.cache)z7.set($,{...z,updatedAt:X});return z}catch(Y){if(Z.debug)console.error(`Error reading/parsing markdown file ${$}:`,Y);let X=Y instanceof Error?Y.message:String(Y);return{content:J0("Markdown File",`Error reading/parsing markdown file: ${X}`,$,"",0,""),data:{}}}}async function MG($,Z,Y){let X=/<pre><code( class="language-([^"]+)")?>([^<]+)<\/code><\/pre>/g;if(!w$)try{w$=await NG({theme:Z||"github-dark",cache:!0})}catch(K){return console.error("Failed to initialize ts-syntax-highlighter:",K),$}let Q=async(K,q,W,z)=>{let U=z.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&#39;/g,"'"),_=W||(Y?"text":"");if(!_)return K;try{if(!w$.getSupportedLanguages().includes(_))return K;return(await w$.highlight(U,_,{theme:Z})).html}catch(B){console.error(`Error highlighting code block with language ${W}:`,B)}return K},J=$,G=$.matchAll(X);for(let K of G){let[q,W,z,U]=K,_=await Q(q,W,z,U);J=J.replace(q,_)}return J}async function H8($,Z,Y="",X={}){return await IG($,/@markdown-file\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\{[^}]*\}))?\)/g,async(G,K,q,W)=>{try{let z=K;if(!q7.isAbsolute(K))z=q7.resolve(q7.dirname(Y),K);let U={};if(q)try{try{U=JSON.parse(q)}catch{if(X.debug)console.warn("Using safer alternative for parsing JS object literal");let O=q.replace(/^\s*\{|\}\s*$/g,"").trim().split(/,(?=\s*\w+\s*:)/);for(let V of O){let w=V.indexOf(":");if(w>0){let A=V.substring(0,w).trim(),R=V.substring(w+1).trim(),N=R.startsWith('"')&&R.endsWith('"'),T=R.startsWith("'")&&R.endsWith("'");if(N||T)R=R.substring(1,R.length-1);U[A]=R}}}}catch(F){if(X.debug)console.error("Error parsing context in @markdown-file directive:",F)}let{content:_,data:B}=await TG(z,X),j={...Z,...B,...U},H=_,L=/\{\{([^}]+)\}\}/g;return H=H.replace(L,(F,O)=>{let V=O.trim();return j[V]!==void 0?String(j[V]):F}),H}catch(z){let U=z instanceof Error?z.message:String(z);return J0("Markdown File",`Error including markdown file: ${U}`,Y,$,W,G)}})}async function IG($,Z,Y){let X=[],Q;while((Q=Z.exec($))!==null){let K=Q[0],q=Q.index,W=Q;X.push(Y(...W).then((z)=>({match:K,replacement:z,index:q})))}let J=await Promise.all(X);J.sort((K,q)=>q.index-K.index);let G=$;for(let{match:K,replacement:q}of J)G=G.replace(K,()=>q);return G}var z7,w$=null;var O8=y(()=>{_5();j0();z7=new Map});function Z1($,Z){try{let Y=$.trim();if(Z0(Y))return Y0(Y,Object.keys(Z))(...Object.values(Z));else return $0(Y,Z)}catch{return!1}}var L8=y(()=>{O0()});function D0($,Z,Y,X=0){let Q=0,J=X,G=null,K=0,q=!1;while(J<$.length){let W=$[J];if(G&&q){q=!1,J++;continue}if(G&&W==="\\"){q=!0,J++;continue}if(q=!1,(W==='"'||W==="'"||W==="`")&&!G){G=W,J++;continue}if(W===G&&G!=="`"){G=null,J++;continue}if(G==="`"&&W==="$"&&$[J+1]==="{"){K++,J+=2;continue}if(K>0&&W==="}"){K--,J++;continue}if(W==="`"&&G==="`"&&K===0){G=null,J++;continue}if(G){J++;continue}if(W===Z)Q++;else if(W===Y){if(Q--,Q===0)return J}J++}return-1}function Y1($,Z){let Y=DG($,Z);return Y.ok?{expression:Y.expression,endPos:Y.endPos}:null}function DG($,Z){let Y=Z;while(Y<$.length&&/\s/.test($[Y]))Y++;if($[Y]!=="(")return{ok:!1,reason:"missing-open-paren",pos:Y};let X=D0($,"(",")",Y);if(X===-1)return{ok:!1,reason:"unclosed-paren",pos:Y};return{ok:!0,expression:$.slice(Y+1,X),endPos:X+1}}function A1($,Z,Y,X){let Q=1,J=X,G=new RegExp(`@${Z}\\s*\\(`,"g"),K=new RegExp(`@${Y}(?![a-z])`,"g");while(J<$.length&&Q>0){G.lastIndex=J,K.lastIndex=J;let q=G.exec($),W=K.exec($),z=q?q.index:1/0,U=W?W.index:1/0;if(z<U)Q++,J=z+q[0].length;else if(U<1/0){if(Q--,Q===0)return U;J=U+W[0].length}else break}return-1}function F8($,Z){let Y=$.slice(Z).match(/^@if\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=Y1($,X);if(!Q)return null;let J=Q.endPos,G=A1($,"if","endif",J);if(G===-1)return null;let K=$.slice(J,G),q=[],W=0,z="if",U=Q.expression,_=0,B=0;while(W<K.length){let j=K.indexOf("@",W);if(j===-1)break;W=j;let H=K.substring(j);if(/^@if\s*\(/.test(H)){B++,W++;continue}if(/^@endif(?![a-z])/.test(H)){B--,W+=6;continue}if(B===0){let L=H.match(/^@elseif\s*/);if(L){q.push({type:z,condition:U,content:K.substring(_,W),start:J+_,end:J+W});let F=W+L[0].length,O=Y1(K,F);if(!O){W++;continue}z="elseif",U=O.expression,W=O.endPos,_=W;continue}else if(/^@else(?![a-z])/.test(H)){q.push({type:z,condition:U,content:K.substring(_,W),start:J+_,end:J+W}),z="else",U=void 0,W+=5,_=W;continue}}W++}return q.push({type:z,condition:U,content:K.slice(_),start:J+_,end:J+K.length}),{fullMatch:$.slice(Z,G+6),branches:q,start:Z,end:G+6}}function j5($){let Z=[],Y=/@if\s*\(/g,X=Y.exec($);while(X!==null){if(Z.some((G)=>X.index>G.start&&X.index<G.end)){X=Y.exec($);continue}let J=F8($,X.index);if(J)Z.push(J),Y.lastIndex=J.end;X=Y.exec($)}return Z}function A$($,Z,Y){let X=[],Q=new RegExp(`@${Z}\\s*\\(`,"g"),J=Q.exec($);while(J!==null){if(X.some((H)=>J.index>H.start&&J.index<H.end)){J=Q.exec($);continue}let K=J.index,q=K+J[0].length-1,W=D0($,"(",")",q);if(W===-1){J=Q.exec($);continue}let z=$.slice(q+1,W),U=W+1,_=A1($,Z,Y,U);if(_===-1){J=Q.exec($);continue}let B=$.slice(U,_),j=_+`@${Y}`.length;X.push({fullMatch:$.slice(K,j),name:Z,params:z,content:B,start:K,end:j}),Q.lastIndex=j,J=Q.exec($)}return X}function W7($,Z){let Y=$.slice(Z).match(/^@switch\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=Y1($,X);if(!Q)return null;let J=Q.endPos,G=A1($,"switch","endswitch",J);if(G===-1)return null;let K=$.slice(J,G),q=[],W=0,z=null,U=0;while(W<K.length){let _=K.slice(W),B=_.match(/^@switch\s*\(/),j=_.match(/^@endswitch(?![a-z])/);if(B){if(U++,z)z.content+=B[0];W+=B[0].length;continue}if(j){if(U--,z)z.content+=j[0];W+=j[0].length;continue}if(U>0){if(z)z.content+=K[W];W++;continue}let H=_.match(/^@case\s*/),L=_.match(/^@default(?![a-z])/),F=_.match(/^@break(?![a-z])/);if(H&&_.startsWith("@case")){if(z)q.push(z);let O=W+H[0].length,V=Y1(K,O);if(!V){W++;continue}z={type:"case",value:V.expression,content:""},W=V.endPos}else if(L&&_.startsWith("@default")){if(z)q.push(z);z={type:"default",content:""},W+=L[0].length}else if(F&&_.startsWith("@break"))W+=F[0].length;else{if(z)z.content+=K[W];W++}}if(z)q.push(z);return{fullMatch:$.slice(Z,G+10),expression:Q.expression,cases:q,start:Z,end:G+10}}var V8=()=>{};var w8=()=>{};var R$=y(()=>{V8();w8()});function SG($,Z,Y){let X=$,Q=!0;while(Q){Q=!1;let J=X.match(/@switch\s*\(/);if(!J||J.index===void 0)break;let G=J.index,K=W7(X,G);if(!K)break;try{let q;if(Z0(K.expression))q=Y0(K.expression,Object.keys(Z))(...Object.values(Z));else q=$0(K.expression,Z);let W="",z=!1;for(let U of K.cases)if(U.type==="default"){if(!z)W=U.content.trim()}else try{let _;if(U.value&&Z0(U.value))_=Y0(U.value,Object.keys(Z))(...Object.values(Z));else if(U.value)_=$0(U.value,Z);if(q===_){W=U.content.trim(),z=!0;break}}catch{continue}X=X.substring(0,G)+W+X.substring(K.end),Q=!0}catch(q){let W=q instanceof Error?q.message:String(q),z=s("Switch",`Error evaluating @switch expression: ${W}`,i.EVALUATION_ERROR);X=X.substring(0,G)+z+X.substring(K.end);break}}return X}function R1($,Z,Y){let X=$;X=SG(X,Z,Y);{let J=!0;while(J){J=!1;let G=X.match(/@unless\s*\(/);if(!G||G.index===void 0)break;let K=G.index,q=Y1(X,K+7);if(!q)break;let W=q.endPos,z=A1(X,"unless","endunless",W);if(z===-1){console.warn(`[stx] @unless directive at position ${K} has no matching @endunless \u2014 the block was skipped. Check for typos or missing closers.`);break}let U=X.slice(W,z),_=q.expression,B=-1;{let H=0,L=/@(?:if|unless)\s*\(/g,F=/@(?:endif|endunless)(?![a-z])/g,O=/@else(?![a-z])/g,V=[],w;while((w=L.exec(U))!==null)V.push({pos:w.index,type:"open"});while((w=F.exec(U))!==null)V.push({pos:w.index,type:"close"});while((w=O.exec(U))!==null)V.push({pos:w.index,type:"else"});V.sort((A,R)=>A.pos-R.pos);for(let A of V)if(A.type==="open")H++;else if(A.type==="close")H--;else if(A.type==="else"&&H===0){B=A.pos;break}}let j;if(B!==-1){let H=U.slice(0,B),L=U.slice(B+5);j=`@if (${_})${L}@else ${H}@endif`}else j=`@if (!(${_}))${U}@endif`;X=X.substring(0,K)+j+X.substring(z+10),J=!0}}X=_7(X,Z,Y),X=B7(X,Z,Y),X=U7(X,Z);let Q=()=>{let J=j5(X);if(J.length===0)return!1;for(let G=J.length-1;G>=0;G--){let K=J[G];try{let q="",W=!1;for(let z of K.branches){if(W)break;if(z.type==="else")q=z.content,W=!0;else try{let U;if(z.condition&&Z0(z.condition))U=Y0(z.condition,Object.keys(Z))(...Object.values(Z));else if(z.condition)U=$0(z.condition,Z);if(U)q=z.content,W=!0}catch(U){q=s(z.type==="if"?"If":"Elseif",`Error in @${z.type}(${z.condition}): ${U instanceof Error?U.message:String(U)}`,i.EVALUATION_ERROR),W=!0}}X=X.substring(0,K.start)+q+X.substring(K.end)}catch(q){let W=q instanceof Error?q.message:String(q),z=s("If",`Error processing @if block: ${W}`,i.EVALUATION_ERROR);X=X.substring(0,K.start)+z+X.substring(K.end)}}return!0};while(Q());return X}function A8($){let Z=0;while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!=="(")return null;Z++;while(Z<$.length&&/\s/.test($[Z]))Z++;let Y=$[Z];if(Y!=="'"&&Y!=='"')return null;Z++;let X=[];while(Z<$.length){let Q=$[Z];if(Q==="\\"&&Z+1<$.length){X.push($[Z+1]),Z+=2;continue}if(Q===Y){Z++;break}X.push(Q),Z++}while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!==")")return null;return Z++,{value:X.join(""),consumed:Z}}function U7($,Z){let Y=$;function X(K,q,W,z){let U=1,_=z,B=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),j=new RegExp(`@${W}(?![a-z])`,"g");while(_<K.length&&U>0){B.lastIndex=_,j.lastIndex=_;let H=B.exec(K),L=j.exec(K),F=H?H.index:1/0,O=L?L.index:1/0;if(F<O)U++,_=F+H[0].length;else if(O<1/0){if(U--,U===0)return O;_=O+L[0].length}else break}return-1}function Q(K,q,W){let z=0,U=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),_=new RegExp(`@${W}(?![a-z])`,"g"),B=/@else(?![a-z])/g,j=[],H;while((H=U.exec(K))!==null)j.push({pos:H.index,type:"open"});while((H=_.exec(K))!==null)j.push({pos:H.index,type:"close"});while((H=B.exec(K))!==null)j.push({pos:H.index,type:"else"});j.sort((L,F)=>L.pos-F.pos);for(let L of j)if(L.type==="open")z++;else if(L.type==="close")z--;else if(L.type==="else"&&z===0)return L.pos;return-1}{let K=!0;while(K){K=!1;let q=Y.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!q||q.index===void 0)break;let W=q.index,z,U,_=Y.slice(W+5),B=A8(_);if(B)z=B.value,U=W+5+B.consumed;else U=W+5;let j=X(Y,"auth","endauth",U);if(j===-1){console.warn(`[stx] @auth directive at position ${W} has no matching @endauth \u2014 the block was skipped.`);break}let H=Y.slice(U,j),L=Q(H,"auth","endauth"),F;if(!Z.auth)F=!1;else F=z?Z1(`auth?.check && auth?.user?.[${z}]`,Z):Z1("auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),w=H.slice(L+5);O=F?V:w}else O=F?H:"";Y=Y.substring(0,W)+O+Y.substring(j+8),K=!0}}{let K=!0;while(K){K=!1;let q=Y.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!q||q.index===void 0)break;let W=q.index,z,U,_=Y.slice(W+6),B=A8(_);if(B)z=B.value,U=W+6+B.consumed;else U=W+6;let j=X(Y,"guest","endguest",U);if(j===-1){console.warn(`[stx] @guest directive at position ${W} has no matching @endguest \u2014 the block was skipped.`);break}let H=Y.slice(U,j),L=Q(H,"guest","endguest"),F;if(!Z.auth)F=!0;else F=z?Z1(`!auth?.check || !auth?.user?.[${z}]`,Z):Z1("!auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),w=H.slice(L+5);O=F?V:w}else O=F?H:"";Y=Y.substring(0,W)+O+Y.substring(j+9),K=!0}}function J(K,q,W){if(Z.userCan&&typeof Z.userCan[K]==="boolean")return Z.userCan[K];if(Z.permissions?.check&&typeof Z.permissions.check==="function")try{let z=[K];if(q)z.push(q);if(W){let U=Z1(W,Z);z.push(U)}return Z.permissions.check(...z)}catch{return!1}return!1}function G(K){let q=K.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!q)return null;return{ability:q[1],type:q[2],id:q[3]?.trim(),paramsEnd:q[0].length}}for(let K of["can","cannot"]){let q=`end${K}`,W=K==="can"?"elsecan":"elsecannot",z=!0;while(z){z=!1;let U=Y.match(new RegExp(`@${K}\\s*\\(`));if(!U||U.index===void 0)break;let _=U.index,B=Y.slice(_+`@${K}`.length),j=G(B);if(!j)break;let H=_+`@${K}`.length+j.paramsEnd,L=X(Y,K,q,H);if(L===-1){console.warn(`[stx] @${K} directive at position ${_} has no matching @${q} \u2014 the block was skipped.`);break}let F=Y.slice(H,L),O=[],V=0,w=new RegExp(`@${K}\\s*\\(`,"g"),A=new RegExp(`@${q}(?![a-z])`,"g"),R=new RegExp(`@${W}\\s*\\(`,"g"),N=/@else(?![a-z])/g,T=[],M;while((M=w.exec(F))!==null)T.push({pos:M.index,type:"open"});while((M=A.exec(F))!==null)T.push({pos:M.index,type:"close"});while((M=R.exec(F))!==null)T.push({pos:M.index,type:"elseDirective"});while((M=N.exec(F))!==null)T.push({pos:M.index,type:"else"});T.sort((b,P)=>b.pos-P.pos);for(let b of T){if(b.type==="open"){V++;continue}if(b.type==="close"){V--;continue}if(V===0)O.push(b)}let I=[],E=0;for(let b=0;b<O.length;b++){let P=O[b];if(I.push({content:F.slice(E,P.pos),ability:void 0}),P.type==="elseDirective"){let d=F.slice(P.pos+`@${W}`.length),f=G(d);if(f){I[I.length-1]={content:F.slice(E,P.pos)},E=P.pos+`@${W}`.length+f.paramsEnd,I.push({content:"",ability:f.ability,type:f.type,id:f.id}),I.pop();let m=O[b+1],n=m?m.pos:F.length;I.push({content:F.slice(E,n),ability:f.ability,type:f.type,id:f.id}),E=n}}else E=P.pos+5}if(E<F.length){let b=I[I.length-1];if(O.length>0&&O[O.length-1].type==="else")I.push({content:F.slice(E),isFinalElse:!0});else if(I.length===0)I.push({content:F.slice(E)})}let D=J(j.ability,j.type,j.id),C=K==="can"?D:!D,k="";if(C)k=I[0]?.content||"";else{let b=!1;for(let P=1;P<I.length;P++){let d=I[P];if(d.isFinalElse){k=d.content,b=!0;break}if(d.ability){let f=J(d.ability,d.type,d.id);if(K==="can"?f:!f){k=d.content,b=!0;break}}}if(!b&&I.length>0){let P=I[I.length-1];if(P.isFinalElse)k=P.content}}Y=Y.substring(0,_)+k+Y.substring(L+`@${q}`.length),z=!0}}return Y}function _7($,Z,Y){let X=$;function Q(J,G,K,q,W){let z=!0;while(z){z=!1;let U=new RegExp(`@${G}\\s*\\(`),_=J.match(U);if(!_||_.index===void 0)break;let B=_.index,j=Y1(J,B+`@${G}`.length);if(!j)break;let H=j.endPos,L=A1(J,G,K,H);if(L===-1){console.warn(`[stx] @${G} directive at position ${B} has no matching @${K} \u2014 the block was skipped.`);break}let F=J.slice(H,L),O=j.expression,V=-1,w=0,A=0;while(A<F.length){let R=F.indexOf("@",A);if(R===-1)break;let N=F.substring(R);if(/^@(?:if|unless|isset|empty)\s*\(/.test(N)){w++,A=R+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(N)){w--,A=R+1;continue}if(w===0&&/^@else(?![a-z])/.test(N)){V=R;break}A=R+1}try{let R=q(O.trim()),N;if(V!==-1){let T=F.slice(0,V),M=F.slice(V+5);N=R?T:M}else N=R?F:"";J=J.substring(0,B)+N+J.substring(L+`@${K}`.length),z=!0}catch(R){let N=R instanceof Error?R.message:String(R),T=s(W,`Error processing @${G} directive: ${N}`,i.EVALUATION_ERROR);J=J.substring(0,B)+T+J.substring(L+`@${K}`.length);break}}return J}return X=Q(X,"isset","endisset",(J)=>{let G=Z1(J,Z);return G!==void 0&&G!==null},"Isset"),X=Q(X,"empty","endempty",(J)=>{let G=Z1(J,Z);return G===void 0||G===null||G===""||G===0||G===!1||Array.isArray(G)&&G.length===0||typeof G==="object"&&G!==null&&Object.keys(G).length===0},"Empty"),X}function B7($,Z,Y){let X=$,Q="development";function J(G,K,q,W){let z=new RegExp(`@${K}(?![a-z])`,"g"),U=new RegExp(`@${q}(?![a-z])`,"g"),_=new RegExp(`^@${K}(?![a-z])`),B=new RegExp(`^@${q}(?![a-z])`),j=G,H=!0;while(H){H=!1,z.lastIndex=0;let L=z.exec(j);if(!L)break;let F=L.index,O=F+L[0].length;if(K==="env"){let D=j.substring(O).match(/^\s*\(\s*(['"])([^'"]+)\1\s*\)/);if(!D)break;O+=D[0].length,W=Q===D[2]}let V=1,w=O,A=-1;while(V>0&&w<j.length){z.lastIndex=w,U.lastIndex=w;let D=z.exec(j),C=U.exec(j),k=D?D.index:1/0,b=C?C.index:1/0;if(k<b)V++,w=k+D[0].length;else if(b<1/0){if(V--,V===0){A=b;break}w=b+C[0].length}else break}if(A===-1){console.warn(`[stx] @${K} directive at position ${F} has no matching @${q} \u2014 the block was skipped.`);break}let R=j.substring(O,A),N=-1,T=0,M=0;while(M<R.length){let D=R.indexOf("@",M);if(D===-1)break;let C=R.substring(D);if(_.test(C)){T++,M=D+1;continue}if(B.test(C)){T--,M=D+1;continue}if(T===0&&/^@else(?![a-z])/.test(C)){N=D;break}M=D+1}let I;if(N!==-1){let D=R.slice(0,N),C=R.slice(N+5);I=W?D:C}else I=W?R:"";let E=`@${q}`.length;j=j.substring(0,F)+I+j.substring(A+E),H=!0}return j}return X=J(X,"env","endenv",!1),X=J(X,"production","endproduction",Q==="production"),X=J(X,"development","enddevelopment",Q==="development"),X=J(X,"staging","endstaging",Q==="staging"),X=J(X,"testing","endtesting",Q==="testing"),X}var N$=y(()=>{L8();a0();R$();O0()});function N8($=16){let Z=new Uint8Array($);return crypto.getRandomValues(Z),btoa(String.fromCharCode(...Z))}function T$($,Z){if(!$)return Z?.nonceGenerator?.()??N8();let Y=R8.get($);if(!Y)Y=Z?.nonceGenerator?.()??N8(),R8.set($,Y);return Y}function yG($,Z){let Y=[];for(let[X,Q]of Object.entries($)){if(Q===void 0||Q===null)continue;if(typeof Q==="boolean"){if(Q)Y.push(X);continue}if(Array.isArray(Q)){let J=[...Q];if(Z&&(X==="script-src"||X==="style-src"))J=J.filter((G)=>!G.startsWith("'nonce-")),J.push(`'nonce-${Z}'`);if(J.length>0)Y.push(`${X} ${J.join(" ")}`)}}return Y.join("; ")}function T8($,Z){return`<meta http-equiv="Content-Security-Policy" content="${yG($,Z).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}">`}function M8($,Z,Y){if(!Z.enabled||!Z.addMetaTag)return $;if($.includes('http-equiv="Content-Security-Policy"'))return $;if(!$.includes("<head>")&&!$.includes("<head "))return $;let X=Z.useNonce?T$(Y,Z):void 0,Q=T8(Z.directives,X);return $.replace(/<head([^>]*)>/,`<head$1>
2438
+ `+Q.slice(G);else Q+=J;return Q}function wG($,Z){let Y=$;for(let X of Z){let J=new RegExp(`<[a-z][a-z0-9-]*\\s+[^>]*data-stx-scope="([^"]*)"[^>]*x-data\\s*=\\s*["']${V$(X.stateExpr)}["']`,"gi").exec(Y);if(J)X.id=J[1],X.selector=`[data-stx-scope="${X.id}"]`;else{let K=new RegExp(`<[a-z][a-z0-9-]*\\s+[^>]*x-data\\s*=\\s*["']${V$(X.stateExpr)}["'][^>]*data-stx-scope="([^"]*)"`,"gi").exec(Y);if(K)X.id=K[1],X.selector=`[data-stx-scope="${X.id}"]`;else Y=Y.replace(new RegExp(`(<[a-z][a-z0-9-]*\\s+)([^>]*)(x-data\\s*=\\s*"${V$(X.stateExpr)}")([^>]*>)`,"gi"),`$1data-stx-scope="${X.id}" $2$3$4`),Y=Y.replace(new RegExp(`(<[a-z][a-z0-9-]*\\s+)([^>]*)(x-data\\s*=\\s*'${V$(X.stateExpr)}')([^>]*>)`,"gi"),`$1data-stx-scope="${X.id}" $2$3$4`)}}return Y=Y.replace(/\s*x-data\s*=\s*"([^"]*)"/g,' data-stx-xdata="$1"'),Y=Y.replace(/\s*x-data\s*=\s*'([^']*)'/g," data-stx-xdata='$1'"),Y=Y.replace(/\s*x-init\s*=\s*"[^"]*"/g,""),Y=Y.replace(/\s*x-init\s*=\s*'[^']*'/g,""),Y}function AG($){return/x-data\s*=\s*["']/.test($)}var _8=0,BG=0;var j8=y(()=>{c0()});import RG from"fs";import q7 from"path";import{createHighlighter as NG}from"ts-syntax-highlighter";async function TG($,Z={}){try{if(!await l($))throw Error(`Markdown file not found: ${$}`);let X=(await RG.promises.stat($)).mtime.getTime();if(Z.cache&&z7.has($)){let U=z7.get($);if(U.updatedAt>=X)return{content:U.content,data:U.data}}let Q=await Bun.file($).text(),{data:J,content:G}=N6(Q),K=Z.markdown||X7.markdown||{enabled:!0,syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}},W=K5(G,{gfm:!0});if(K.syntaxHighlighting?.enabled&&K.syntaxHighlighting?.serverSide)W=await MG(W,K.syntaxHighlighting?.defaultTheme||"github-dark",K.syntaxHighlighting?.highlightUnknownLanguages||!1);let z={content:W,data:J||{}};if(Z.cache)z7.set($,{...z,updatedAt:X});return z}catch(Y){if(Z.debug)console.error(`Error reading/parsing markdown file ${$}:`,Y);let X=Y instanceof Error?Y.message:String(Y);return{content:J0("Markdown File",`Error reading/parsing markdown file: ${X}`,$,"",0,""),data:{}}}}async function MG($,Z,Y){let X=/<pre><code( class="language-([^"]+)")?>([^<]+)<\/code><\/pre>/g;if(!w$)try{w$=await NG({theme:Z||"github-dark",cache:!0})}catch(K){return console.error("Failed to initialize ts-syntax-highlighter:",K),$}let Q=async(K,q,W,z)=>{let U=z.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&#39;/g,"'"),_=W||(Y?"text":"");if(!_)return K;try{if(!w$.getSupportedLanguages().includes(_))return K;return(await w$.highlight(U,_,{theme:Z})).html}catch(B){console.error(`Error highlighting code block with language ${W}:`,B)}return K},J=$,G=$.matchAll(X);for(let K of G){let[q,W,z,U]=K,_=await Q(q,W,z,U);J=J.replace(q,_)}return J}async function H8($,Z,Y="",X={}){return await IG($,/@markdown-file\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\{[^}]*\}))?\)/g,async(G,K,q,W)=>{try{let z=K;if(!q7.isAbsolute(K))z=q7.resolve(q7.dirname(Y),K);let U={};if(q)try{try{U=JSON.parse(q)}catch{if(X.debug)console.warn("Using safer alternative for parsing JS object literal");let O=q.replace(/^\s*\{|\}\s*$/g,"").trim().split(/,(?=\s*\w+\s*:)/);for(let V of O){let w=V.indexOf(":");if(w>0){let A=V.substring(0,w).trim(),R=V.substring(w+1).trim(),N=R.startsWith('"')&&R.endsWith('"'),T=R.startsWith("'")&&R.endsWith("'");if(N||T)R=R.substring(1,R.length-1);U[A]=R}}}}catch(F){if(X.debug)console.error("Error parsing context in @markdown-file directive:",F)}let{content:_,data:B}=await TG(z,X),j={...Z,...B,...U},H=_,L=/\{\{([^}]+)\}\}/g;return H=H.replace(L,(F,O)=>{let V=O.trim();return j[V]!==void 0?String(j[V]):F}),H}catch(z){let U=z instanceof Error?z.message:String(z);return J0("Markdown File",`Error including markdown file: ${U}`,Y,$,W,G)}})}async function IG($,Z,Y){let X=[],Q;while((Q=Z.exec($))!==null){let K=Q[0],q=Q.index,W=Q;X.push(Y(...W).then((z)=>({match:K,replacement:z,index:q})))}let J=await Promise.all(X);J.sort((K,q)=>q.index-K.index);let G=$;for(let{match:K,replacement:q}of J)G=G.replace(K,()=>q);return G}var z7,w$=null;var O8=y(()=>{_5();j0();z7=new Map});function Z1($,Z){try{let Y=$.trim();if(Z0(Y))return Y0(Y,Object.keys(Z))(...Object.values(Z));else return $0(Y,Z)}catch{return!1}}var L8=y(()=>{O0()});function D0($,Z,Y,X=0){let Q=0,J=X,G=null,K=0,q=!1;while(J<$.length){let W=$[J];if(G&&q){q=!1,J++;continue}if(G&&W==="\\"){q=!0,J++;continue}if(q=!1,(W==='"'||W==="'"||W==="`")&&!G){G=W,J++;continue}if(W===G&&G!=="`"){G=null,J++;continue}if(G==="`"&&W==="$"&&$[J+1]==="{"){K++,J+=2;continue}if(K>0&&W==="}"){K--,J++;continue}if(W==="`"&&G==="`"&&K===0){G=null,J++;continue}if(G){J++;continue}if(W===Z)Q++;else if(W===Y){if(Q--,Q===0)return J}J++}return-1}function Y1($,Z){let Y=DG($,Z);return Y.ok?{expression:Y.expression,endPos:Y.endPos}:null}function DG($,Z){let Y=Z;while(Y<$.length&&/\s/.test($[Y]))Y++;if($[Y]!=="(")return{ok:!1,reason:"missing-open-paren",pos:Y};let X=D0($,"(",")",Y);if(X===-1)return{ok:!1,reason:"unclosed-paren",pos:Y};return{ok:!0,expression:$.slice(Y+1,X),endPos:X+1}}function A1($,Z,Y,X){let Q=1,J=X,G=new RegExp(`@${Z}\\s*\\(`,"g"),K=new RegExp(`@${Y}(?![a-z])`,"g");while(J<$.length&&Q>0){G.lastIndex=J,K.lastIndex=J;let q=G.exec($),W=K.exec($),z=q?q.index:1/0,U=W?W.index:1/0;if(z<U)Q++,J=z+q[0].length;else if(U<1/0){if(Q--,Q===0)return U;J=U+W[0].length}else break}return-1}function F8($,Z){let Y=$.slice(Z).match(/^@if\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=Y1($,X);if(!Q)return null;let J=Q.endPos,G=A1($,"if","endif",J);if(G===-1)return null;let K=$.slice(J,G),q=[],W=0,z="if",U=Q.expression,_=0,B=0;while(W<K.length){let j=K.indexOf("@",W);if(j===-1)break;W=j;let H=K.substring(j);if(/^@if\s*\(/.test(H)){B++,W++;continue}if(/^@endif(?![a-z])/.test(H)){B--,W+=6;continue}if(B===0){let L=H.match(/^@elseif\s*/);if(L){q.push({type:z,condition:U,content:K.substring(_,W),start:J+_,end:J+W});let F=W+L[0].length,O=Y1(K,F);if(!O){W++;continue}z="elseif",U=O.expression,W=O.endPos,_=W;continue}else if(/^@else(?![a-z])/.test(H)){q.push({type:z,condition:U,content:K.substring(_,W),start:J+_,end:J+W}),z="else",U=void 0,W+=5,_=W;continue}}W++}return q.push({type:z,condition:U,content:K.slice(_),start:J+_,end:J+K.length}),{fullMatch:$.slice(Z,G+6),branches:q,start:Z,end:G+6}}function j5($){let Z=[],Y=/@if\s*\(/g,X=Y.exec($);while(X!==null){if(Z.some((G)=>X.index>G.start&&X.index<G.end)){X=Y.exec($);continue}let J=F8($,X.index);if(J)Z.push(J),Y.lastIndex=J.end;X=Y.exec($)}return Z}function A$($,Z,Y){let X=[],Q=new RegExp(`@${Z}\\s*\\(`,"g"),J=Q.exec($);while(J!==null){if(X.some((H)=>J.index>H.start&&J.index<H.end)){J=Q.exec($);continue}let K=J.index,q=K+J[0].length-1,W=D0($,"(",")",q);if(W===-1){J=Q.exec($);continue}let z=$.slice(q+1,W),U=W+1,_=A1($,Z,Y,U);if(_===-1){J=Q.exec($);continue}let B=$.slice(U,_),j=_+`@${Y}`.length;X.push({fullMatch:$.slice(K,j),name:Z,params:z,content:B,start:K,end:j}),Q.lastIndex=j,J=Q.exec($)}return X}function W7($,Z){let Y=$.slice(Z).match(/^@switch\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=Y1($,X);if(!Q)return null;let J=Q.endPos,G=A1($,"switch","endswitch",J);if(G===-1)return null;let K=$.slice(J,G),q=[],W=0,z=null,U=0;while(W<K.length){let _=K.slice(W),B=_.match(/^@switch\s*\(/),j=_.match(/^@endswitch(?![a-z])/);if(B){if(U++,z)z.content+=B[0];W+=B[0].length;continue}if(j){if(U--,z)z.content+=j[0];W+=j[0].length;continue}if(U>0){if(z)z.content+=K[W];W++;continue}let H=_.match(/^@case\s*/),L=_.match(/^@default(?![a-z])/),F=_.match(/^@break(?![a-z])/);if(H&&_.startsWith("@case")){if(z)q.push(z);let O=W+H[0].length,V=Y1(K,O);if(!V){W++;continue}z={type:"case",value:V.expression,content:""},W=V.endPos}else if(L&&_.startsWith("@default")){if(z)q.push(z);z={type:"default",content:""},W+=L[0].length}else if(F&&_.startsWith("@break"))W+=F[0].length;else{if(z)z.content+=K[W];W++}}if(z)q.push(z);return{fullMatch:$.slice(Z,G+10),expression:Q.expression,cases:q,start:Z,end:G+10}}var V8=()=>{};var w8=()=>{};var R$=y(()=>{V8();w8()});function SG($,Z,Y){let X=$,Q=!0;while(Q){Q=!1;let J=X.match(/@switch\s*\(/);if(!J||J.index===void 0)break;let G=J.index,K=W7(X,G);if(!K)break;try{let q;if(Z0(K.expression))q=Y0(K.expression,Object.keys(Z))(...Object.values(Z));else q=$0(K.expression,Z);let W="",z=!1;for(let U of K.cases)if(U.type==="default"){if(!z)W=U.content.trim()}else try{let _;if(U.value&&Z0(U.value))_=Y0(U.value,Object.keys(Z))(...Object.values(Z));else if(U.value)_=$0(U.value,Z);if(q===_){W=U.content.trim(),z=!0;break}}catch{continue}X=X.substring(0,G)+W+X.substring(K.end),Q=!0}catch(q){let W=q instanceof Error?q.message:String(q),z=s("Switch",`Error evaluating @switch expression: ${W}`,i.EVALUATION_ERROR);X=X.substring(0,G)+z+X.substring(K.end);break}}return X}function R1($,Z,Y){let X=$;X=SG(X,Z,Y);{let J=!0;while(J){J=!1;let G=X.match(/@unless\s*\(/);if(!G||G.index===void 0)break;let K=G.index,q=Y1(X,K+7);if(!q)break;let W=q.endPos,z=A1(X,"unless","endunless",W);if(z===-1){console.warn(`[stx] @unless directive at position ${K} has no matching @endunless \u2014 the block was skipped. Check for typos or missing closers.`);break}let U=X.slice(W,z),_=q.expression,B=-1;{let H=0,L=/@(?:if|unless)\s*\(/g,F=/@(?:endif|endunless)(?![a-z])/g,O=/@else(?![a-z])/g,V=[],w;while((w=L.exec(U))!==null)V.push({pos:w.index,type:"open"});while((w=F.exec(U))!==null)V.push({pos:w.index,type:"close"});while((w=O.exec(U))!==null)V.push({pos:w.index,type:"else"});V.sort((A,R)=>A.pos-R.pos);for(let A of V)if(A.type==="open")H++;else if(A.type==="close")H--;else if(A.type==="else"&&H===0){B=A.pos;break}}let j;if(B!==-1){let H=U.slice(0,B),L=U.slice(B+5);j=`@if (${_})${L}@else ${H}@endif`}else j=`@if (!(${_}))${U}@endif`;X=X.substring(0,K)+j+X.substring(z+10),J=!0}}X=_7(X,Z,Y),X=B7(X,Z,Y),X=U7(X,Z);let Q=()=>{let J=j5(X);if(J.length===0)return!1;for(let G=J.length-1;G>=0;G--){let K=J[G];try{let q="",W=!1;for(let z of K.branches){if(W)break;if(z.type==="else")q=z.content,W=!0;else try{let U;if(z.condition&&Z0(z.condition))U=Y0(z.condition,Object.keys(Z))(...Object.values(Z));else if(z.condition)U=$0(z.condition,Z);if(U)q=z.content,W=!0}catch(U){q=s(z.type==="if"?"If":"Elseif",`Error in @${z.type}(${z.condition}): ${U instanceof Error?U.message:String(U)}`,i.EVALUATION_ERROR),W=!0}}X=X.substring(0,K.start)+q+X.substring(K.end)}catch(q){let W=q instanceof Error?q.message:String(q),z=s("If",`Error processing @if block: ${W}`,i.EVALUATION_ERROR);X=X.substring(0,K.start)+z+X.substring(K.end)}}return!0};while(!0){let J=X;if(!Q())break;if(X===J)break}return X}function A8($){let Z=0;while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!=="(")return null;Z++;while(Z<$.length&&/\s/.test($[Z]))Z++;let Y=$[Z];if(Y!=="'"&&Y!=='"')return null;Z++;let X=[];while(Z<$.length){let Q=$[Z];if(Q==="\\"&&Z+1<$.length){X.push($[Z+1]),Z+=2;continue}if(Q===Y){Z++;break}X.push(Q),Z++}while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!==")")return null;return Z++,{value:X.join(""),consumed:Z}}function U7($,Z){let Y=$;function X(K,q,W,z){let U=1,_=z,B=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),j=new RegExp(`@${W}(?![a-z])`,"g");while(_<K.length&&U>0){B.lastIndex=_,j.lastIndex=_;let H=B.exec(K),L=j.exec(K),F=H?H.index:1/0,O=L?L.index:1/0;if(F<O)U++,_=F+H[0].length;else if(O<1/0){if(U--,U===0)return O;_=O+L[0].length}else break}return-1}function Q(K,q,W){let z=0,U=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),_=new RegExp(`@${W}(?![a-z])`,"g"),B=/@else(?![a-z])/g,j=[],H;while((H=U.exec(K))!==null)j.push({pos:H.index,type:"open"});while((H=_.exec(K))!==null)j.push({pos:H.index,type:"close"});while((H=B.exec(K))!==null)j.push({pos:H.index,type:"else"});j.sort((L,F)=>L.pos-F.pos);for(let L of j)if(L.type==="open")z++;else if(L.type==="close")z--;else if(L.type==="else"&&z===0)return L.pos;return-1}{let K=!0;while(K){K=!1;let q=Y.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!q||q.index===void 0)break;let W=q.index,z,U,_=Y.slice(W+5),B=A8(_);if(B)z=B.value,U=W+5+B.consumed;else U=W+5;let j=X(Y,"auth","endauth",U);if(j===-1){console.warn(`[stx] @auth directive at position ${W} has no matching @endauth \u2014 the block was skipped.`);break}let H=Y.slice(U,j),L=Q(H,"auth","endauth"),F;if(!Z.auth)F=!1;else F=z?Z1(`auth?.check && auth?.user?.[${z}]`,Z):Z1("auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),w=H.slice(L+5);O=F?V:w}else O=F?H:"";Y=Y.substring(0,W)+O+Y.substring(j+8),K=!0}}{let K=!0;while(K){K=!1;let q=Y.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!q||q.index===void 0)break;let W=q.index,z,U,_=Y.slice(W+6),B=A8(_);if(B)z=B.value,U=W+6+B.consumed;else U=W+6;let j=X(Y,"guest","endguest",U);if(j===-1){console.warn(`[stx] @guest directive at position ${W} has no matching @endguest \u2014 the block was skipped.`);break}let H=Y.slice(U,j),L=Q(H,"guest","endguest"),F;if(!Z.auth)F=!0;else F=z?Z1(`!auth?.check || !auth?.user?.[${z}]`,Z):Z1("!auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),w=H.slice(L+5);O=F?V:w}else O=F?H:"";Y=Y.substring(0,W)+O+Y.substring(j+9),K=!0}}function J(K,q,W){if(Z.userCan&&typeof Z.userCan[K]==="boolean")return Z.userCan[K];if(Z.permissions?.check&&typeof Z.permissions.check==="function")try{let z=[K];if(q)z.push(q);if(W){let U=Z1(W,Z);z.push(U)}return Z.permissions.check(...z)}catch{return!1}return!1}function G(K){let q=K.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!q)return null;return{ability:q[1],type:q[2],id:q[3]?.trim(),paramsEnd:q[0].length}}for(let K of["can","cannot"]){let q=`end${K}`,W=K==="can"?"elsecan":"elsecannot",z=!0;while(z){z=!1;let U=Y.match(new RegExp(`@${K}\\s*\\(`));if(!U||U.index===void 0)break;let _=U.index,B=Y.slice(_+`@${K}`.length),j=G(B);if(!j)break;let H=_+`@${K}`.length+j.paramsEnd,L=X(Y,K,q,H);if(L===-1){console.warn(`[stx] @${K} directive at position ${_} has no matching @${q} \u2014 the block was skipped.`);break}let F=Y.slice(H,L),O=[],V=0,w=new RegExp(`@${K}\\s*\\(`,"g"),A=new RegExp(`@${q}(?![a-z])`,"g"),R=new RegExp(`@${W}\\s*\\(`,"g"),N=/@else(?![a-z])/g,T=[],M;while((M=w.exec(F))!==null)T.push({pos:M.index,type:"open"});while((M=A.exec(F))!==null)T.push({pos:M.index,type:"close"});while((M=R.exec(F))!==null)T.push({pos:M.index,type:"elseDirective"});while((M=N.exec(F))!==null)T.push({pos:M.index,type:"else"});T.sort((b,P)=>b.pos-P.pos);for(let b of T){if(b.type==="open"){V++;continue}if(b.type==="close"){V--;continue}if(V===0)O.push(b)}let I=[],E=0;for(let b=0;b<O.length;b++){let P=O[b];if(I.push({content:F.slice(E,P.pos),ability:void 0}),P.type==="elseDirective"){let d=F.slice(P.pos+`@${W}`.length),f=G(d);if(f){I[I.length-1]={content:F.slice(E,P.pos)},E=P.pos+`@${W}`.length+f.paramsEnd,I.push({content:"",ability:f.ability,type:f.type,id:f.id}),I.pop();let m=O[b+1],n=m?m.pos:F.length;I.push({content:F.slice(E,n),ability:f.ability,type:f.type,id:f.id}),E=n}}else E=P.pos+5}if(E<F.length){let b=I[I.length-1];if(O.length>0&&O[O.length-1].type==="else")I.push({content:F.slice(E),isFinalElse:!0});else if(I.length===0)I.push({content:F.slice(E)})}let D=J(j.ability,j.type,j.id),C=K==="can"?D:!D,k="";if(C)k=I[0]?.content||"";else{let b=!1;for(let P=1;P<I.length;P++){let d=I[P];if(d.isFinalElse){k=d.content,b=!0;break}if(d.ability){let f=J(d.ability,d.type,d.id);if(K==="can"?f:!f){k=d.content,b=!0;break}}}if(!b&&I.length>0){let P=I[I.length-1];if(P.isFinalElse)k=P.content}}Y=Y.substring(0,_)+k+Y.substring(L+`@${q}`.length),z=!0}}return Y}function _7($,Z,Y){let X=$;function Q(J,G,K,q,W){let z=!0;while(z){z=!1;let U=new RegExp(`@${G}\\s*\\(`),_=J.match(U);if(!_||_.index===void 0)break;let B=_.index,j=Y1(J,B+`@${G}`.length);if(!j)break;let H=j.endPos,L=A1(J,G,K,H);if(L===-1){console.warn(`[stx] @${G} directive at position ${B} has no matching @${K} \u2014 the block was skipped.`);break}let F=J.slice(H,L),O=j.expression,V=-1,w=0,A=0;while(A<F.length){let R=F.indexOf("@",A);if(R===-1)break;let N=F.substring(R);if(/^@(?:if|unless|isset|empty)\s*\(/.test(N)){w++,A=R+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(N)){w--,A=R+1;continue}if(w===0&&/^@else(?![a-z])/.test(N)){V=R;break}A=R+1}try{let R=q(O.trim()),N;if(V!==-1){let T=F.slice(0,V),M=F.slice(V+5);N=R?T:M}else N=R?F:"";J=J.substring(0,B)+N+J.substring(L+`@${K}`.length),z=!0}catch(R){let N=R instanceof Error?R.message:String(R),T=s(W,`Error processing @${G} directive: ${N}`,i.EVALUATION_ERROR);J=J.substring(0,B)+T+J.substring(L+`@${K}`.length);break}}return J}return X=Q(X,"isset","endisset",(J)=>{let G=Z1(J,Z);return G!==void 0&&G!==null},"Isset"),X=Q(X,"empty","endempty",(J)=>{let G=Z1(J,Z);return G===void 0||G===null||G===""||G===0||G===!1||Array.isArray(G)&&G.length===0||typeof G==="object"&&G!==null&&Object.keys(G).length===0},"Empty"),X}function B7($,Z,Y){let X=$,Q="development";function J(G,K,q,W){let z=new RegExp(`@${K}(?![a-z])`,"g"),U=new RegExp(`@${q}(?![a-z])`,"g"),_=new RegExp(`^@${K}(?![a-z])`),B=new RegExp(`^@${q}(?![a-z])`),j=G,H=!0;while(H){H=!1,z.lastIndex=0;let L=z.exec(j);if(!L)break;let F=L.index,O=F+L[0].length;if(K==="env"){let D=j.substring(O).match(/^\s*\(\s*(['"])([^'"]+)\1\s*\)/);if(!D)break;O+=D[0].length,W=Q===D[2]}let V=1,w=O,A=-1;while(V>0&&w<j.length){z.lastIndex=w,U.lastIndex=w;let D=z.exec(j),C=U.exec(j),k=D?D.index:1/0,b=C?C.index:1/0;if(k<b)V++,w=k+D[0].length;else if(b<1/0){if(V--,V===0){A=b;break}w=b+C[0].length}else break}if(A===-1){console.warn(`[stx] @${K} directive at position ${F} has no matching @${q} \u2014 the block was skipped.`);break}let R=j.substring(O,A),N=-1,T=0,M=0;while(M<R.length){let D=R.indexOf("@",M);if(D===-1)break;let C=R.substring(D);if(_.test(C)){T++,M=D+1;continue}if(B.test(C)){T--,M=D+1;continue}if(T===0&&/^@else(?![a-z])/.test(C)){N=D;break}M=D+1}let I;if(N!==-1){let D=R.slice(0,N),C=R.slice(N+5);I=W?D:C}else I=W?R:"";let E=`@${q}`.length;j=j.substring(0,F)+I+j.substring(A+E),H=!0}return j}return X=J(X,"env","endenv",!1),X=J(X,"production","endproduction",Q==="production"),X=J(X,"development","enddevelopment",Q==="development"),X=J(X,"staging","endstaging",Q==="staging"),X=J(X,"testing","endtesting",Q==="testing"),X}var N$=y(()=>{L8();a0();R$();O0()});function N8($=16){let Z=new Uint8Array($);return crypto.getRandomValues(Z),btoa(String.fromCharCode(...Z))}function T$($,Z){if(!$)return Z?.nonceGenerator?.()??N8();let Y=R8.get($);if(!Y)Y=Z?.nonceGenerator?.()??N8(),R8.set($,Y);return Y}function yG($,Z){let Y=[];for(let[X,Q]of Object.entries($)){if(Q===void 0||Q===null)continue;if(typeof Q==="boolean"){if(Q)Y.push(X);continue}if(Array.isArray(Q)){let J=[...Q];if(Z&&(X==="script-src"||X==="style-src"))J=J.filter((G)=>!G.startsWith("'nonce-")),J.push(`'nonce-${Z}'`);if(J.length>0)Y.push(`${X} ${J.join(" ")}`)}}return Y.join("; ")}function T8($,Z){return`<meta http-equiv="Content-Security-Policy" content="${yG($,Z).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}">`}function M8($,Z,Y){if(!Z.enabled||!Z.addMetaTag)return $;if($.includes('http-equiv="Content-Security-Policy"'))return $;if(!$.includes("<head>")&&!$.includes("<head "))return $;let X=Z.useNonce?T$(Y,Z):void 0,Q=T8(Z.directives,X);return $.replace(/<head([^>]*)>/,`<head$1>
2439
2439
  ${Q}`)}function I8($,Z,Y,X){let Q=$,J=X.csp;if(Q=Q.replace(/@csp\b/g,()=>{if(!J?.enabled||!J.directives)return"<!-- CSP not configured -->";let G=J.useNonce?T$(Z,J):void 0;return T8(J.directives,G)}),Q=Q.replace(/@cspNonce\b/g,()=>{if(!J?.enabled||!J.useNonce)return"";return T$(Z,J)}),J?.enabled&&J.useNonce)Z.cspNonce=T$(Z,J);return Q}var R8;var D8=y(()=>{R8=new WeakMap});import CG from"crypto";function vG($=PG){let Z=CG.randomBytes(Math.ceil($/2)).toString("hex").slice(0,$);return j7=Z,Z}function xG(){if(!j7)vG();return j7}function fG($=E8){let Z=xG();return`<input type="hidden" name="${$}" value="${Z}">`}function k8($){return $.replace(/@csrf(?:\((['"])([^'"]*)\1\))?/g,(Z,Y,X)=>{return fG(X||E8)})}var PG=40,E8="_token",j7=null;var b8=()=>{};async function S8($,Z,Y,X){if(!X.customDirectives||X.customDirectives.length===0)return $;let Q=$;for(let J of X.customDirectives){if(!J.name||typeof J.handler!=="function"){if(X.debug)console.warn("Invalid custom directive:",J);continue}if(J.hasEndTag)Q=await gG(Q,J,Z,Y,X);else Q=await hG(Q,J,Z,Y,X)}return Q}async function gG($,Z,Y,X,Q){let{name:J,handler:G}=Z,K=`@${J}`,q=`@end${J}`,W=$,z=v1(`${K}(?:\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\))?([\\s\\S]*?)${q}`,"g"),U=[],_=z.exec(W);while(_!==null){let[B,j="",H=""]=_,L=_.index||0;try{let F=j?y8(j):[],O=H.trim(),V=await G(O,F,Y,X);U.push({original:B,processed:V,startIndex:L})}catch(F){let O=F instanceof Error?F.message:String(F);if(Q.debug)console.error(`Error processing custom directive @${J}:`,F);U.push({original:B,processed:s("CustomDirective",`Error in @${J}${j?`(${j})`:""}: ${O}`,i.EVALUATION_ERROR),startIndex:L})}_=z.exec(W)}for(let B=U.length-1;B>=0;B--){let{original:j,processed:H}=U[B];W=W.replace(j,H)}return W}async function hG($,Z,Y,X,Q){let{name:J,handler:G}=Z,K=$,q=v1(`@${J}\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\)`,"g"),W=[],z=q.exec(K);while(z!==null){let[B,j=""]=z,H=z.index||0;try{let L=y8(j),F=await G("",L,Y,X);W.push({original:B,processed:F,startIndex:H})}catch(L){let F=L instanceof Error?L.message:String(L);if(Q.debug)console.error(`Error processing custom directive @${J}:`,L);W.push({original:B,processed:s("CustomDirective",`Error in @${J}(${j}): ${F}`,i.EVALUATION_ERROR),startIndex:H})}z=q.exec(K)}let U=v1(`@${J}(?!\\w)(?!\\s*\\()`,"g"),_=U.exec(K);while(_!==null){let[B]=_,j=_.index||0;try{let H=await G("",[],Y,X);W.push({original:B,processed:H,startIndex:j})}catch(H){let L=H instanceof Error?H.message:String(H);if(Q.debug)console.error(`Error processing custom directive @${J}:`,H);W.push({original:B,processed:s("CustomDirective",`Error in @${J}: ${L}`,i.EVALUATION_ERROR),startIndex:j})}_=U.exec(K)}for(let B=W.length-1;B>=0;B--){let{original:j,processed:H}=W[B];K=K.replace(j,H)}return K}function y8($){if(!$.trim())return[];let Z=[],Y="",X=!1,Q="";for(let J=0;J<$.length;J++){let G=$[J];if((G==='"'||G==="'")&&(J===0||$[J-1]!=="\\"))if(!X)X=!0,Q=G;else if(G===Q)X=!1;else Y+=G;else if(G===","&&!X)Z.push(Y.trim()),Y="";else Y+=G}if(Y.trim())Z.push(Y.trim());return Z.map((J)=>{let G=J.trim();if(G.startsWith('"')&&G.endsWith('"')||G.startsWith("'")&&G.endsWith("'"))return G.substring(1,G.length-1);return G})}var C8=y(()=>{a0();x1()});var H7={};t(H7,{useTitle:()=>cG,useSeoMeta:()=>I$,usePageTitle:()=>cG,useHead:()=>T1,resetHead:()=>uG,renderHtmlAttrs:()=>nG,renderHead:()=>iG,renderBodyAttrs:()=>oG,processTitleDirective:()=>aG,processMetaDirective:()=>tG,processHeadDirective:()=>rG,getPageMeta:()=>mG,getHead:()=>H5,definePageMeta:()=>lG,applyHead:()=>sG});function H5(){return X1}function mG(){return M$}function uG(){X1={},dG.length=0,M$={}}function T1($){X1=pG(X1,$)}function pG($,Z){return{title:Z.title??$.title,titleTemplate:Z.titleTemplate??$.titleTemplate,base:Z.base??$.base,meta:[...$.meta||[],...Z.meta||[]],link:[...$.link||[],...Z.link||[]],script:[...$.script||[],...Z.script||[]],style:[...$.style||[],...Z.style||[]],htmlAttrs:{...$.htmlAttrs,...Z.htmlAttrs},bodyAttrs:{...$.bodyAttrs,...Z.bodyAttrs}}}function I$($){let Z=[];if($.description)Z.push({name:"description",content:$.description});if($.keywords){let q=Array.isArray($.keywords)?$.keywords.join(", "):$.keywords;Z.push({name:"keywords",content:q})}if($.author)Z.push({name:"author",content:$.author});if($.robots)Z.push({name:"robots",content:$.robots});let Y=$.ogTitle??$.title,X=$.ogDescription??$.description;if(Y)Z.push({property:"og:title",content:Y});if(X)Z.push({property:"og:description",content:X});if($.ogImage)Z.push({property:"og:image",content:$.ogImage});if($.ogUrl)Z.push({property:"og:url",content:$.ogUrl});if($.ogType)Z.push({property:"og:type",content:$.ogType});if($.ogSiteName)Z.push({property:"og:site_name",content:$.ogSiteName});if($.ogLocale)Z.push({property:"og:locale",content:$.ogLocale});let Q=$.twitterTitle??$.title,J=$.twitterDescription??$.description,G=$.twitterImage??$.ogImage;if($.twitterCard)Z.push({name:"twitter:card",content:$.twitterCard});if(Q)Z.push({name:"twitter:title",content:Q});if(J)Z.push({name:"twitter:description",content:J});if(G)Z.push({name:"twitter:image",content:G});if($.twitterSite)Z.push({name:"twitter:site",content:$.twitterSite});if($.twitterCreator)Z.push({name:"twitter:creator",content:$.twitterCreator});if($.articleAuthor)Z.push({property:"article:author",content:$.articleAuthor});if($.articlePublishedTime)Z.push({property:"article:published_time",content:$.articlePublishedTime});if($.articleModifiedTime)Z.push({property:"article:modified_time",content:$.articleModifiedTime});if($.articleSection)Z.push({property:"article:section",content:$.articleSection});if($.articleTags)for(let q of $.articleTags)Z.push({property:"article:tag",content:q});let K=[];if($.canonical)K.push({rel:"canonical",href:$.canonical});T1({title:$.title,titleTemplate:$.titleTemplate,meta:Z,link:K})}function lG($){if(M$={...M$,...$},$.title||$.description)I$({title:$.title,description:$.description})}function cG($){let Z=typeof $==="function"?$():$;T1({title:Z})}function iG($=X1){let Z=[];if($.title){let Y=$.title;if($.titleTemplate)Y=typeof $.titleTemplate==="function"?$.titleTemplate(Y):$.titleTemplate.replace("%s",Y);Z.push(`<title>${N1(Y)}</title>`)}if($.base){let Y=Object.entries($.base).map(([X,Q])=>`${X}="${N1(Q)}"`).join(" ");Z.push(`<base ${Y}>`)}for(let Y of $.meta||[]){let X=Object.entries(Y).filter(([Q,J])=>J!==void 0).map(([Q,J])=>{return`${Q==="httpEquiv"?"http-equiv":Q}="${N1(String(J))}"`}).join(" ");Z.push(`<meta ${X}>`)}for(let Y of $.link||[]){let X=Object.entries(Y).filter(([Q,J])=>J!==void 0).map(([Q,J])=>`${Q}="${N1(String(J))}"`).join(" ");Z.push(`<link ${X}>`)}for(let Y of $.script||[]){let{content:X,...Q}=Y,J=Object.entries(Q).filter(([G,K])=>K!==void 0).map(([G,K])=>{if(typeof K==="boolean")return K?G:"";return`${G}="${N1(String(K))}"`}).filter(Boolean).join(" ");if(X)Z.push(`<script ${J}>${X}</script>`);else Z.push(`<script ${J}></script>`)}for(let Y of $.style||[]){let X=Y.type?` type="${Y.type}"`:"";Z.push(`<style${X}>${Y.content}</style>`)}return Z.join(`
2440
2440
  `)}function nG($=X1){if(!$.htmlAttrs)return"";return Object.entries($.htmlAttrs).map(([Z,Y])=>`${Z}="${N1(Y)}"`).join(" ")}function oG($=X1){if(!$.bodyAttrs)return"";return Object.entries($.bodyAttrs).map(([Z,Y])=>`${Z}="${N1(Y)}"`).join(" ")}function N1($){return $.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function sG($=X1){if(typeof document>"u")return;if($.title){let Z=$.title;if($.titleTemplate)Z=typeof $.titleTemplate==="function"?$.titleTemplate(Z):$.titleTemplate.replace("%s",Z);document.title=Z}for(let Z of $.meta||[]){let Y=Z.name?`meta[name="${Z.name}"]`:Z.property?`meta[property="${Z.property}"]`:null;if(Y){let X=document.querySelector(Y);if(!X){if(X=document.createElement("meta"),Z.name)X.setAttribute("name",Z.name);if(Z.property)X.setAttribute("property",Z.property);document.head.appendChild(X)}X.setAttribute("content",Z.content)}}for(let Z of $.link||[]){let Y=`link[rel="${Z.rel}"]${Z.href?`[href="${Z.href}"]`:""}`,X=document.querySelector(Y);if(!X)X=document.createElement("link"),document.head.appendChild(X);for(let[Q,J]of Object.entries(Z))if(J!==void 0)X.setAttribute(Q,String(J))}if($.htmlAttrs)for(let[Z,Y]of Object.entries($.htmlAttrs))document.documentElement.setAttribute(Z,Y);if($.bodyAttrs)for(let[Z,Y]of Object.entries($.bodyAttrs))document.body.setAttribute(Z,Y)}function rG($){let Z="";return{content:$.replace(/@head\s*([\s\S]*?)@endhead/g,(X,Q)=>{return Z+=Q.trim()+`
2441
2441
  `,""}),headContent:Z.trim()}}function aG($,Z){return $.replace(/@title\s*\(\s*(?:(['"`])(.+?)\1|([^)]+))\s*\)/g,(Y,X,Q,J)=>{let G=X?Q:Z[(J||"").trim()]??J;return T1({title:G}),""})}function tG($,Z){return $.replace(/@meta\s*\(\s*(['"`])(.+?)\1\s*,\s*(?:(['"`])(.+?)\3|([^)]+))\s*\)/g,(Y,X,Q,J,G,K)=>{let q=J?G:K,W=J?q:Z[(q||"").trim()]??q,U=Q.includes(":")?{property:Q,content:W}:{name:Q,content:W};return T1({meta:[U]}),""})}var X1,dG,M$;var O5=y(()=>{X1={},dG=[],M$={}});import eG from"crypto";function F0($){return String($??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function D$($,Z,Y,X){let Q=$||Z;return Y?`${Q} ${X}`:Q}function $K(){return eG.randomUUID()}function E$($,Z){let Y=$;return Y=Y.replace(/@csrf/g,()=>{if(!Z.csrf||typeof Z.csrf!=="object"){let X=$K();Z.csrf={token:X}}if(Z.csrf.field)return Z.csrf.field;if(Z.csrf.token)return`<input type="hidden" name="_token" value="${F0(Z.csrf.token)}">`;return'<input type="hidden" name="_token" value="">'}),Y=Y.replace(/@method\(['"]([^'"]+)['"]\)/g,(X,Q)=>{let J=Q.toUpperCase();if(Q&&!["GET","POST"].includes(J))return`<input type="hidden" name="_method" value="${F0(J)}">`;return X}),Y}function x8($,Z,Y=v8){let X=$;return X=X.replace(/@form\(\s*(?:(?:'([^']+)'|"([^"]+)")\s*)?(?:,\s*(?:'([^']+)'|"([^"]+)")?)?\s*(?:,\s*\{([^}]+)\}\s*)?\)/g,(Q,J,G,K,q,W="")=>{let z=J||G||"POST",U=K||q||"",_=J1(W),B=z.toUpperCase(),j=["GET","POST"].includes(B)?B:"POST",H=`<form method="${F0(j)}" action="${F0(U)}"${_?` ${_}`:""}>`;if(H+=`
@@ -3769,7 +3769,7 @@ ${Y}
3769
3769
  </script>`}function mZ($,Z,Y){if(dZ=0,!sq($))return $;let X=uq($);if(X.length===0)return $;let J=oq($,X),Q=nq(X,Z),G=J.lastIndexOf("</body>");if(G!==-1)J=J.slice(0,G)+Q+`
3770
3770
  `+J.slice(G);else J+=Q;return J}function oq($,Z){let Y=$;for(let X of Z){let Q=new RegExp(`<[a-z][a-z0-9-]*\\s+[^>]*data-stx-scope="([^"]*)"[^>]*x-data\\s*=\\s*["']${$4(X.stateExpr)}["']`,"gi").exec(Y);if(Q)X.id=Q[1],X.selector=`[data-stx-scope="${X.id}"]`;else{let K=new RegExp(`<[a-z][a-z0-9-]*\\s+[^>]*x-data\\s*=\\s*["']${$4(X.stateExpr)}["'][^>]*data-stx-scope="([^"]*)"`,"gi").exec(Y);if(K)X.id=K[1],X.selector=`[data-stx-scope="${X.id}"]`;else Y=Y.replace(new RegExp(`(<[a-z][a-z0-9-]*\\s+)([^>]*)(x-data\\s*=\\s*"${$4(X.stateExpr)}")([^>]*>)`,"gi"),`$1data-stx-scope="${X.id}" $2$3$4`),Y=Y.replace(new RegExp(`(<[a-z][a-z0-9-]*\\s+)([^>]*)(x-data\\s*=\\s*'${$4(X.stateExpr)}')([^>]*>)`,"gi"),`$1data-stx-scope="${X.id}" $2$3$4`)}}return Y=Y.replace(/\s*x-data\s*=\s*"([^"]*)"/g,' data-stx-xdata="$1"'),Y=Y.replace(/\s*x-data\s*=\s*'([^']*)'/g," data-stx-xdata='$1'"),Y=Y.replace(/\s*x-init\s*=\s*"[^"]*"/g,""),Y=Y.replace(/\s*x-init\s*=\s*'[^']*'/g,""),Y}function sq($){return/x-data\s*=\s*["']/.test($)}var dZ=0,mq=0;var uZ=P(()=>{a0()});import rq from"fs";import F3 from"path";import{createHighlighter as aq}from"ts-syntax-highlighter";async function tq($,Z={}){try{if(!await p($))throw Error(`Markdown file not found: ${$}`);let X=(await rq.promises.stat($)).mtime.getTime();if(Z.cache&&V3.has($)){let W=V3.get($);if(W.updatedAt>=X)return{content:W.content,data:W.data}}let J=await Bun.file($).text(),{data:Q,content:G}=i9(J),K=Z.markdown||q3.markdown||{enabled:!0,syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}},z=k5(G,{gfm:!0});if(K.syntaxHighlighting?.enabled&&K.syntaxHighlighting?.serverSide)z=await eq(z,K.syntaxHighlighting?.defaultTheme||"github-dark",K.syntaxHighlighting?.highlightUnknownLanguages||!1);let U={content:z,data:Q||{}};if(Z.cache)V3.set($,{...U,updatedAt:X});return U}catch(Y){if(Z.debug)console.error(`Error reading/parsing markdown file ${$}:`,Y);let X=Y instanceof Error?Y.message:String(Y);return{content:J0("Markdown File",`Error reading/parsing markdown file: ${X}`,$,"",0,""),data:{}}}}async function eq($,Z,Y){let X=/<pre><code( class="language-([^"]+)")?>([^<]+)<\/code><\/pre>/g;if(!Z4)try{Z4=await aq({theme:Z||"github-dark",cache:!0})}catch(K){return console.error("Failed to initialize ts-syntax-highlighter:",K),$}let J=async(K,q,z,U)=>{let W=U.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&#39;/g,"'"),_=z||(Y?"text":"");if(!_)return K;try{if(!Z4.getSupportedLanguages().includes(_))return K;return(await Z4.highlight(W,_,{theme:Z})).html}catch(B){console.error(`Error highlighting code block with language ${z}:`,B)}return K},Q=$,G=$.matchAll(X);for(let K of G){let[q,z,U,W]=K,_=await J(q,z,U,W);Q=Q.replace(q,_)}return Q}async function lZ($,Z,Y="",X={}){return await $z($,/@markdown-file\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\{[^}]*\}))?\)/g,async(G,K,q,z)=>{try{let U=K;if(!F3.isAbsolute(K))U=F3.resolve(F3.dirname(Y),K);let W={};if(q)try{try{W=JSON.parse(q)}catch{if(X.debug)console.warn("Using safer alternative for parsing JS object literal");let O=q.replace(/^\s*\{|\}\s*$/g,"").trim().split(/,(?=\s*\w+\s*:)/);for(let V of O){let A=V.indexOf(":");if(A>0){let w=V.substring(0,A).trim(),R=V.substring(A+1).trim(),N=R.startsWith('"')&&R.endsWith('"'),T=R.startsWith("'")&&R.endsWith("'");if(N||T)R=R.substring(1,R.length-1);W[w]=R}}}}catch(F){if(X.debug)console.error("Error parsing context in @markdown-file directive:",F)}let{content:_,data:B}=await tq(U,X),j={...Z,...B,...W},H=_,L=/\{\{([^}]+)\}\}/g;return H=H.replace(L,(F,O)=>{let V=O.trim();return j[V]!==void 0?String(j[V]):F}),H}catch(U){let W=U instanceof Error?U.message:String(U);return J0("Markdown File",`Error including markdown file: ${W}`,Y,$,z,G)}})}async function $z($,Z,Y){let X=[],J;while((J=Z.exec($))!==null){let K=J[0],q=J.index,z=J;X.push(Y(...z).then((U)=>({match:K,replacement:U,index:q})))}let Q=await Promise.all(X);Q.sort((K,q)=>q.index-K.index);let G=$;for(let{match:K,replacement:q}of Q)G=G.replace(K,()=>q);return G}var V3,Z4=null;var cZ=P(()=>{P5();O0();V3=new Map});function B1($,Z){try{let Y=$.trim();if($0(Y))return Z0(Y,Object.keys(Z))(...Object.values(Z));else return e(Y,Z)}catch{return!1}}var pZ=P(()=>{H0()});class Y4{source;pos=0;line=1;column=0;tokens=[];constructor($){this.source=$}tokenize(){this.tokens=[],this.pos=0,this.line=1,this.column=0;while(this.pos<this.source.length){let $=this.nextToken();if($)this.tokens.push($)}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 $=this.pos,Z=this.line,Y=this.column,X=this.source[this.pos];if(/\s/.test(X))return this.readWhitespace($,Z,Y);if(X==="/"&&this.peek(1)==="/")return this.readLineComment($,Z,Y);if(X==="/"&&this.peek(1)==="*")return this.readBlockComment($,Z,Y);if(X==='"'||X==="'")return this.readString(X,$,Z,Y);if(X==="`")return this.readTemplateString($,Z,Y);if(/\d/.test(X)||X==="."&&/\d/.test(this.peek(1)||""))return this.readNumber($,Z,Y);if(/[a-z_$]/i.test(X))return this.readIdentifier($,Z,Y);if(X==="{"){if(this.peek(1)==="{"&&this.peek(2)==="{")return this.advance(3),{type:"RAW_START",value:"{{{",start:$,end:this.pos,line:Z,column:Y};if(this.peek(1)==="{")return this.advance(2),{type:"EXPRESSION_START",value:"{{",start:$,end:this.pos,line:Z,column:Y};if(this.peek(1)==="!"&&this.peek(2)==="!")return this.advance(3),{type:"RAW_START",value:"{!!",start:$,end:this.pos,line:Z,column:Y}}if(X==="}"){if(this.peek(1)==="}"&&this.peek(2)==="}")return this.advance(3),{type:"RAW_END",value:"}}}",start:$,end:this.pos,line:Z,column:Y};if(this.peek(1)==="}")return this.advance(2),{type:"EXPRESSION_END",value:"}}",start:$,end:this.pos,line:Z,column:Y}}if(X==="!"&&this.peek(1)==="!"&&this.peek(2)==="}")return this.advance(3),{type:"RAW_END",value:"!!}",start:$,end:this.pos,line:Z,column:Y};if(X==="@"&&/[a-z]/i.test(this.peek(1)||""))return this.readDirective($,Z,Y);let J=["===","!==","==","!=","<=",">=","&&","||","??","++","--","+=","-=","*=","/=","%=","**","=>","?.","...","<<",">>",">>>","&=","|=","^="];for(let Q of J)if(this.source.slice(this.pos,this.pos+Q.length)===Q)return this.advance(Q.length),{type:"OPERATOR",value:Q,start:$,end:this.pos,line:Z,column:Y};if(/[+\-*/%<>=!&|^~?:]/.test(X))return this.advance(),{type:"OPERATOR",value:X,start:$,end:this.pos,line:Z,column:Y};if(/[()[\]{},;.]/.test(X))return this.advance(),{type:"PUNCTUATION",value:X,start:$,end:this.pos,line:Z,column:Y};return this.advance(),{type:"PUNCTUATION",value:X,start:$,end:this.pos,line:Z,column:Y}}readWhitespace($,Z,Y){while(this.pos<this.source.length&&/\s/.test(this.source[this.pos]))this.advance();return{type:"WHITESPACE",value:this.source.slice($,this.pos),start:$,end:this.pos,line:Z,column:Y}}readLineComment($,Z,Y){this.advance(2);while(this.pos<this.source.length&&this.source[this.pos]!==`
3771
3771
  `)this.advance();return{type:"COMMENT",value:this.source.slice($,this.pos),start:$,end:this.pos,line:Z,column:Y}}readBlockComment($,Z,Y){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($,this.pos),start:$,end:this.pos,line:Z,column:Y}}readString($,Z,Y,X){this.advance();while(this.pos<this.source.length){let J=this.source[this.pos];if(J==="\\"){this.advance(2);continue}if(J===$){this.advance();break}this.advance()}return{type:"STRING",value:this.source.slice(Z,this.pos),start:Z,end:this.pos,line:Y,column:X}}readTemplateString($,Z,Y){this.advance();let X=0,J=256;while(this.pos<this.source.length){let Q=this.source[this.pos];if(Q==="\\"){this.advance(2);continue}if(Q==="$"&&this.peek(1)==="{"){if(X>=J){this.pos=this.source.length;break}this.advance(2),X++;continue}if(Q==="{"&&X>0){X++,this.advance();continue}if(Q==="}"&&X>0){X--,this.advance();continue}if(Q==="`"&&X===0){this.advance();break}this.advance()}return{type:"TEMPLATE_STRING",value:this.source.slice($,this.pos),start:$,end:this.pos,line:Z,column:Y}}readNumber($,Z,Y){if(this.source[this.pos]==="0"){let X=this.peek(1)?.toLowerCase();if(X==="x"||X==="o"||X==="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($,this.pos),start:$,end:this.pos,line:Z,column:Y}}}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($,this.pos),start:$,end:this.pos,line:Z,column:Y}}readIdentifier($,Z,Y){while(this.pos<this.source.length&&/[\w$]/.test(this.source[this.pos]))this.advance();return{type:"IDENTIFIER",value:this.source.slice($,this.pos),start:$,end:this.pos,line:Z,column:Y}}readDirective($,Z,Y){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($,this.pos),start:$,end:this.pos,line:Z,column:Y}}advance($=1){for(let Z=0;Z<$&&this.pos<this.source.length;Z++){if(this.source[this.pos]===`
3772
- `)this.line++,this.column=0;else this.column++;this.pos++}}peek($){return this.source[this.pos+$]}saveState(){return{pos:this.pos,line:this.line,column:this.column}}restoreState($){this.pos=$.pos,this.line=$.line,this.column=$.column}}function F0($,Z,Y,X=0){let J=0,Q=X,G=null,K=0,q=!1;while(Q<$.length){let z=$[Q];if(G&&q){q=!1,Q++;continue}if(G&&z==="\\"){q=!0,Q++;continue}if(q=!1,(z==='"'||z==="'"||z==="`")&&!G){G=z,Q++;continue}if(z===G&&G!=="`"){G=null,Q++;continue}if(G==="`"&&z==="$"&&$[Q+1]==="{"){K++,Q+=2;continue}if(K>0&&z==="}"){K--,Q++;continue}if(z==="`"&&G==="`"&&K===0){G=null,Q++;continue}if(G){Q++;continue}if(z===Z)J++;else if(z===Y){if(J--,J===0)return Q}Q++}return-1}function iZ($,Z){let Y=Z,X={paren:0,bracket:0,brace:0},J=null,Q=0;while(Y<$.length){let G=$[Y];if((Y>0?$[Y-1]:"")==="\\"&&J){Y++;continue}if((G==='"'||G==="'")&&!J){J=G,Y++;continue}if(G===J&&J!=="`"){J=null,Y++;continue}if(G==="`"&&!J){J="`",Y++;continue}if(G==="`"&&J==="`"&&Q===0){J=null,Y++;continue}if(J==="`"&&G==="$"&&$[Y+1]==="{"){Q++,Y+=2;continue}if(Q>0){if(G==="{")Q++;else if(G==="}")Q--;Y++;continue}if(J){Y++;continue}if(X.paren===0&&X.bracket===0&&X.brace===0){if($.slice(Y,Y+2)==="}}"||$.slice(Y,Y+3)==="!!}")break;if(G===","||G===";")break}if(G==="(")X.paren++;else if(G===")"){if(X.paren--,X.paren<0)break}else if(G==="[")X.bracket++;else if(G==="]"){if(X.bracket--,X.bracket<0)break}else if(G==="{")X.brace++;else if(G==="}"){if(X.brace--,X.brace<0)break}Y++}return{expression:$.slice(Z,Y),endPos:Y}}function w3($){let Z=[],Y="",X={paren:0,bracket:0,brace:0},J=null,Q=0;for(let G=0;G<$.length;G++){let K=$[G];if((G>0?$[G-1]:"")==="\\"&&J){Y+=K;continue}if((K==='"'||K==="'")&&!J){J=K,Y+=K;continue}if(K===J&&J!=="`"){J=null,Y+=K;continue}if(K==="`"&&!J){J="`",Y+=K;continue}if(K==="`"&&J==="`"&&Q===0){J=null,Y+=K;continue}if(J==="`"&&K==="$"&&$[G+1]==="{"){Q++,Y+=K+$[G+1],G++;continue}if(Q>0&&K==="{"){Q++,Y+=K;continue}if(Q>0&&K==="}"){Q--,Y+=K;continue}if(J){Y+=K;continue}if(K==="(")X.paren++;else if(K===")")X.paren--;else if(K==="[")X.bracket++;else if(K==="]")X.bracket--;else if(K==="{")X.brace++;else if(K==="}")X.brace--;if(K==="|"&&$[G+1]!=="|"&&(G===0||$[G-1]!=="|")&&$[G-1]!=="\\"&&X.paren===0&&X.bracket===0&&X.brace===0){Z.push(Y.trim()),Y="";continue}if(K==="|"&&$[G-1]==="\\"&&!J){Y=Y.slice(0,-1)+K;continue}Y+=K}if(Y.trim())Z.push(Y.trim());return Z}function j1($,Z){let Y=Zz($,Z);return Y.ok?{expression:Y.expression,endPos:Y.endPos}:null}function Zz($,Z){let Y=Z;while(Y<$.length&&/\s/.test($[Y]))Y++;if($[Y]!=="(")return{ok:!1,reason:"missing-open-paren",pos:Y};let X=F0($,"(",")",Y);if(X===-1)return{ok:!1,reason:"unclosed-paren",pos:Y};return{ok:!0,expression:$.slice(Y+1,X),endPos:X+1}}function P1($,Z,Y,X){let J=1,Q=X,G=new RegExp(`@${Z}\\s*\\(`,"g"),K=new RegExp(`@${Y}(?![a-z])`,"g");while(Q<$.length&&J>0){G.lastIndex=Q,K.lastIndex=Q;let q=G.exec($),z=K.exec($),U=q?q.index:1/0,W=z?z.index:1/0;if(U<W)J++,Q=U+q[0].length;else if(W<1/0){if(J--,J===0)return W;Q=W+z[0].length}else break}return-1}function nZ($,Z){let Y=$.slice(Z).match(/^@if\s*/);if(!Y)return null;let X=Z+Y[0].length,J=j1($,X);if(!J)return null;let Q=J.endPos,G=P1($,"if","endif",Q);if(G===-1)return null;let K=$.slice(Q,G),q=[],z=0,U="if",W=J.expression,_=0,B=0;while(z<K.length){let j=K.indexOf("@",z);if(j===-1)break;z=j;let H=K.substring(j);if(/^@if\s*\(/.test(H)){B++,z++;continue}if(/^@endif(?![a-z])/.test(H)){B--,z+=6;continue}if(B===0){let L=H.match(/^@elseif\s*/);if(L){q.push({type:U,condition:W,content:K.substring(_,z),start:Q+_,end:Q+z});let F=z+L[0].length,O=j1(K,F);if(!O){z++;continue}U="elseif",W=O.expression,z=O.endPos,_=z;continue}else if(/^@else(?![a-z])/.test(H)){q.push({type:U,condition:W,content:K.substring(_,z),start:Q+_,end:Q+z}),U="else",W=void 0,z+=5,_=z;continue}}z++}return q.push({type:U,condition:W,content:K.slice(_),start:Q+_,end:Q+K.length}),{fullMatch:$.slice(Z,G+6),branches:q,start:Z,end:G+6}}function v5($){let Z=[],Y=/@if\s*\(/g,X=Y.exec($);while(X!==null){if(Z.some((G)=>X.index>G.start&&X.index<G.end)){X=Y.exec($);continue}let Q=nZ($,X.index);if(Q)Z.push(Q),Y.lastIndex=Q.end;X=Y.exec($)}return Z}function X4($,Z,Y){let X=[],J=new RegExp(`@${Z}\\s*\\(`,"g"),Q=J.exec($);while(Q!==null){if(X.some((H)=>Q.index>H.start&&Q.index<H.end)){Q=J.exec($);continue}let K=Q.index,q=K+Q[0].length-1,z=F0($,"(",")",q);if(z===-1){Q=J.exec($);continue}let U=$.slice(q+1,z),W=z+1,_=P1($,Z,Y,W);if(_===-1){Q=J.exec($);continue}let B=$.slice(W,_),j=_+`@${Y}`.length;X.push({fullMatch:$.slice(K,j),name:Z,params:U,content:B,start:K,end:j}),J.lastIndex=j,Q=J.exec($)}return X}function A3($,Z){let Y=$.slice(Z).match(/^@switch\s*/);if(!Y)return null;let X=Z+Y[0].length,J=j1($,X);if(!J)return null;let Q=J.endPos,G=P1($,"switch","endswitch",Q);if(G===-1)return null;let K=$.slice(Q,G),q=[],z=0,U=null,W=0;while(z<K.length){let _=K.slice(z),B=_.match(/^@switch\s*\(/),j=_.match(/^@endswitch(?![a-z])/);if(B){if(W++,U)U.content+=B[0];z+=B[0].length;continue}if(j){if(W--,U)U.content+=j[0];z+=j[0].length;continue}if(W>0){if(U)U.content+=K[z];z++;continue}let H=_.match(/^@case\s*/),L=_.match(/^@default(?![a-z])/),F=_.match(/^@break(?![a-z])/);if(H&&_.startsWith("@case")){if(U)q.push(U);let O=z+H[0].length,V=j1(K,O);if(!V){z++;continue}U={type:"case",value:V.expression,content:""},z=V.endPos}else if(L&&_.startsWith("@default")){if(U)q.push(U);U={type:"default",content:""},z+=L[0].length}else if(F&&_.startsWith("@break"))z+=F[0].length;else{if(U)U.content+=K[z];z++}}if(U)q.push(U);return{fullMatch:$.slice(Z,G+10),expression:J.expression,cases:q,start:Z,end:G+10}}var oZ=()=>{};function Yz($){let Z=[],Y=0;while(Y<$.length){let X=$.indexOf("{{",Y),J=$.indexOf("{!!",Y),Q=!1,G;if(X===-1&&J===-1)break;else if(X===-1)G=J,Q=!0;else if(J===-1)G=X,Q=!1;else if(J<X)G=J,Q=!0;else G=X,Q=!1;if(!Q&&$.slice(G,G+3)==="{{{")Q=!0;let K=Q?$.slice(G,G+3)==="{{{"?"{{{":"{!!":"{{",q=Q?K==="{{{"?"}}}":"!!}":"}}",z=G+K.length,U=Xz($,z,q);if(U===-1){Y=G+1;continue}let W=$.slice(z,U).trim(),_=U+q.length;Z.push({fullMatch:$.slice(G,_),expression:W,start:G,end:_,isRaw:Q}),Y=_}return Z}function Xz($,Z,Y){let X=Z,J=null,Q={paren:0,bracket:0,brace:0},G=0;while(X<$.length){let K=$[X];if((X>0?$[X-1]:"")==="\\"&&J){X++;continue}if((K==='"'||K==="'")&&!J){J=K,X++;continue}if(K===J&&J!=="`"){J=null,X++;continue}if(K==="`"&&!J){J="`",X++;continue}if(K==="`"&&J==="`"&&G===0){J=null,X++;continue}if(J==="`"&&K==="$"&&$[X+1]==="{"){G++,X+=2;continue}if(G>0){if(K==="{")G++;else if(K==="}")G--;X++;continue}if(J){X++;continue}if(K==="(")Q.paren++;else if(K===")")Q.paren--;else if(K==="[")Q.bracket++;else if(K==="]")Q.bracket--;else if(K==="{")Q.brace++;else if(K==="}")Q.brace--;if(Q.paren===0&&Q.bracket===0&&Q.brace<=0){if($.slice(X,X+Y.length)===Y)return X}X++}return-1}function Jz($){let Z=w3($);if(Z.length===0)return{baseExpression:"",filters:[]};let Y=Z[0],X=[];for(let J=1;J<Z.length;J++){let Q=Qz(Z[J]);if(Q)X.push(Q)}return{baseExpression:Y,filters:X}}function Qz($){let Z=$.trim();if(!Z)return null;let Y=Z.indexOf("(");if(Y===-1)return{name:Z,args:[]};let X=Z.slice(0,Y).trim(),J=Y+1,Q=F0(Z,"(",")",Y);if(Q===-1)return{name:X,args:[]};let G=Z.slice(J,Q),K=aZ(G);return{name:X,args:K}}function aZ($){let Z=[],Y="",X={paren:0,bracket:0,brace:0},J=null,Q=0;for(let G=0;G<$.length;G++){let K=$[G];if((G>0?$[G-1]:"")==="\\"&&J){Y+=K;continue}if((K==='"'||K==="'")&&!J){J=K,Y+=K;continue}if(K===J&&J!=="`"){J=null,Y+=K;continue}if(K==="`"&&!J){J="`",Y+=K;continue}if(K==="`"&&J==="`"&&Q===0){J=null,Y+=K;continue}if(J==="`"&&K==="$"&&$[G+1]==="{"){Q++,Y+="${",G++;continue}if(Q>0&&K==="{"){Q++,Y+=K;continue}if(Q>0&&K==="}"){Q--,Y+=K;continue}if(J){Y+=K;continue}if(K==="(")X.paren++;else if(K===")")X.paren--;else if(K==="[")X.bracket++;else if(K==="]")X.bracket--;else if(K==="{")X.brace++;else if(K==="}")X.brace--;if(K===","&&X.paren===0&&X.bracket===0&&X.brace===0){Z.push(Y.trim()),Y="";continue}Y+=K}if(Y.trim())Z.push(Y.trim());return Z}function Gz($,Z){let Y=Z;while(Y<$.length&&/\s/.test($[Y]))Y++;if($[Y]!=="(")return null;let X=F0($,"(",")",Y);if(X===-1)return null;return{params:$.slice(Y+1,X),endPos:X+1}}function Kz($){let Z=[],X=new Y4($).tokenize().filter((Q)=>Q.type!=="WHITESPACE"&&Q.type!=="COMMENT"),J=0;while(J<X.length){let Q=X[J],G=!1;if(Q.type==="IDENTIFIER"&&Q.value==="export"){if(G=!0,J++,J>=X.length)break}let K=X[J];if(K.type==="IDENTIFIER"&&(K.value==="const"||K.value==="let"||K.value==="var")){let q=K.value;if(J++,J>=X.length)break;let z=X[J];if(z.type==="IDENTIFIER"){let U=z.value;if(J++,J<X.length&&X[J].type==="OPERATOR"&&X[J].value==="="){J++;let W=J<X.length?X[J].start:$.length,_=sZ(X,J,$);J=_.nextIndex,Z.push({type:"variable",name:U,value:$.slice(W,_.endPos),exported:G,start:K.start,end:_.endPos})}}else if(z.type==="PUNCTUATION"&&(z.value==="{"||z.value==="[")){let U=z.start,W=z.value==="{"?"}":"]",_=F0($,z.value,W,U);if(_!==-1){let B=$.slice(U,_+1);if(J=rZ(X,_+1),J<X.length&&X[J].type==="OPERATOR"&&X[J].value==="="){J++;let j=J<X.length?X[J].start:$.length,H=sZ(X,J,$);J=H.nextIndex;let L=`__stx_destructured_${Z.length}`;Z.push({type:"variable",name:L,value:`${$.slice(j,H.endPos)}; ${q} ${B} = ${L}`,exported:G,start:K.start,end:H.endPos})}}}}else if(K.type==="IDENTIFIER"&&K.value==="function"){let q=G?X[J-1].start:K.start;if(J++,J>=X.length)break;let z=X[J];if(z.type==="IDENTIFIER"){let U=z.value;J++;let W=-1;while(J<X.length){if(X[J].type==="PUNCTUATION"&&X[J].value==="{"){W=X[J].start;break}J++}if(W!==-1){let _=F0($,"{","}",W);if(_!==-1)Z.push({type:"function",name:U,value:$.slice(q,_+1).replace(/^export\s+/,""),exported:G,start:q,end:_+1}),J=rZ(X,_+1)}}}else J++}return Z}function sZ($,Z,Y){let X=Z,J={paren:0,bracket:0,brace:0},Q=Z<$.length?$[Z].start:Y.length;while(X<$.length){let G=$[X];if(G.type==="PUNCTUATION"){if(G.value==="(")J.paren++;else if(G.value===")")J.paren--;else if(G.value==="[")J.bracket++;else if(G.value==="]")J.bracket--;else if(G.value==="{")J.brace++;else if(G.value==="}")J.brace--;if(G.value===";"&&J.paren===0&&J.bracket===0&&J.brace===0){Q=G.start,X++;break}}if(G.type==="IDENTIFIER"&&(G.value==="const"||G.value==="let"||G.value==="var"||G.value==="function"||G.value==="export")){if(J.paren===0&&J.bracket===0&&J.brace===0){Q=$[X-1]?.end??G.start;break}}Q=G.end,X++}return{nextIndex:X,endPos:Q}}function rZ($,Z){for(let Y=0;Y<$.length;Y++)if($[Y].start>=Z)return Y;return $.length}var tZ=()=>{};var J4=P(()=>{oZ();tZ()});function qz($,Z,Y){let X=$,J=!0;while(J){J=!1;let Q=X.match(/@switch\s*\(/);if(!Q||Q.index===void 0)break;let G=Q.index,K=A3(X,G);if(!K)break;try{let q;if($0(K.expression))q=Z0(K.expression,Object.keys(Z))(...Object.values(Z));else q=e(K.expression,Z);let z="",U=!1;for(let W of K.cases)if(W.type==="default"){if(!U)z=W.content.trim()}else try{let _;if(W.value&&$0(W.value))_=Z0(W.value,Object.keys(Z))(...Object.values(Z));else if(W.value)_=e(W.value,Z);if(q===_){z=W.content.trim(),U=!0;break}}catch{continue}X=X.substring(0,G)+z+X.substring(K.end),J=!0}catch(q){let z=q instanceof Error?q.message:String(q),U=o("Switch",`Error evaluating @switch expression: ${z}`,m.EVALUATION_ERROR);X=X.substring(0,G)+U+X.substring(K.end);break}}return X}function C1($,Z,Y){let X=$;X=qz(X,Z,Y);{let Q=!0;while(Q){Q=!1;let G=X.match(/@unless\s*\(/);if(!G||G.index===void 0)break;let K=G.index,q=j1(X,K+7);if(!q)break;let z=q.endPos,U=P1(X,"unless","endunless",z);if(U===-1){console.warn(`[stx] @unless directive at position ${K} has no matching @endunless \u2014 the block was skipped. Check for typos or missing closers.`);break}let W=X.slice(z,U),_=q.expression,B=-1;{let H=0,L=/@(?:if|unless)\s*\(/g,F=/@(?:endif|endunless)(?![a-z])/g,O=/@else(?![a-z])/g,V=[],A;while((A=L.exec(W))!==null)V.push({pos:A.index,type:"open"});while((A=F.exec(W))!==null)V.push({pos:A.index,type:"close"});while((A=O.exec(W))!==null)V.push({pos:A.index,type:"else"});V.sort((w,R)=>w.pos-R.pos);for(let w of V)if(w.type==="open")H++;else if(w.type==="close")H--;else if(w.type==="else"&&H===0){B=w.pos;break}}let j;if(B!==-1){let H=W.slice(0,B),L=W.slice(B+5);j=`@if (${_})${L}@else ${H}@endif`}else j=`@if (!(${_}))${W}@endif`;X=X.substring(0,K)+j+X.substring(U+10),Q=!0}}X=N3(X,Z,Y),X=T3(X,Z,Y),X=R3(X,Z);let J=()=>{let Q=v5(X);if(Q.length===0)return!1;for(let G=Q.length-1;G>=0;G--){let K=Q[G];try{let q="",z=!1;for(let U of K.branches){if(z)break;if(U.type==="else")q=U.content,z=!0;else try{let W;if(U.condition&&$0(U.condition))W=Z0(U.condition,Object.keys(Z))(...Object.values(Z));else if(U.condition)W=e(U.condition,Z);if(W)q=U.content,z=!0}catch(W){q=o(U.type==="if"?"If":"Elseif",`Error in @${U.type}(${U.condition}): ${W instanceof Error?W.message:String(W)}`,m.EVALUATION_ERROR),z=!0}}X=X.substring(0,K.start)+q+X.substring(K.end)}catch(q){let z=q instanceof Error?q.message:String(q),U=o("If",`Error processing @if block: ${z}`,m.EVALUATION_ERROR);X=X.substring(0,K.start)+U+X.substring(K.end)}}return!0};while(J());return X}function eZ($){let Z=0;while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!=="(")return null;Z++;while(Z<$.length&&/\s/.test($[Z]))Z++;let Y=$[Z];if(Y!=="'"&&Y!=='"')return null;Z++;let X=[];while(Z<$.length){let J=$[Z];if(J==="\\"&&Z+1<$.length){X.push($[Z+1]),Z+=2;continue}if(J===Y){Z++;break}X.push(J),Z++}while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!==")")return null;return Z++,{value:X.join(""),consumed:Z}}function R3($,Z){let Y=$;function X(K,q,z,U){let W=1,_=U,B=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),j=new RegExp(`@${z}(?![a-z])`,"g");while(_<K.length&&W>0){B.lastIndex=_,j.lastIndex=_;let H=B.exec(K),L=j.exec(K),F=H?H.index:1/0,O=L?L.index:1/0;if(F<O)W++,_=F+H[0].length;else if(O<1/0){if(W--,W===0)return O;_=O+L[0].length}else break}return-1}function J(K,q,z){let U=0,W=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),_=new RegExp(`@${z}(?![a-z])`,"g"),B=/@else(?![a-z])/g,j=[],H;while((H=W.exec(K))!==null)j.push({pos:H.index,type:"open"});while((H=_.exec(K))!==null)j.push({pos:H.index,type:"close"});while((H=B.exec(K))!==null)j.push({pos:H.index,type:"else"});j.sort((L,F)=>L.pos-F.pos);for(let L of j)if(L.type==="open")U++;else if(L.type==="close")U--;else if(L.type==="else"&&U===0)return L.pos;return-1}{let K=!0;while(K){K=!1;let q=Y.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!q||q.index===void 0)break;let z=q.index,U,W,_=Y.slice(z+5),B=eZ(_);if(B)U=B.value,W=z+5+B.consumed;else W=z+5;let j=X(Y,"auth","endauth",W);if(j===-1){console.warn(`[stx] @auth directive at position ${z} has no matching @endauth \u2014 the block was skipped.`);break}let H=Y.slice(W,j),L=J(H,"auth","endauth"),F;if(!Z.auth)F=!1;else F=U?B1(`auth?.check && auth?.user?.[${U}]`,Z):B1("auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),A=H.slice(L+5);O=F?V:A}else O=F?H:"";Y=Y.substring(0,z)+O+Y.substring(j+8),K=!0}}{let K=!0;while(K){K=!1;let q=Y.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!q||q.index===void 0)break;let z=q.index,U,W,_=Y.slice(z+6),B=eZ(_);if(B)U=B.value,W=z+6+B.consumed;else W=z+6;let j=X(Y,"guest","endguest",W);if(j===-1){console.warn(`[stx] @guest directive at position ${z} has no matching @endguest \u2014 the block was skipped.`);break}let H=Y.slice(W,j),L=J(H,"guest","endguest"),F;if(!Z.auth)F=!0;else F=U?B1(`!auth?.check || !auth?.user?.[${U}]`,Z):B1("!auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),A=H.slice(L+5);O=F?V:A}else O=F?H:"";Y=Y.substring(0,z)+O+Y.substring(j+9),K=!0}}function Q(K,q,z){if(Z.userCan&&typeof Z.userCan[K]==="boolean")return Z.userCan[K];if(Z.permissions?.check&&typeof Z.permissions.check==="function")try{let U=[K];if(q)U.push(q);if(z){let W=B1(z,Z);U.push(W)}return Z.permissions.check(...U)}catch{return!1}return!1}function G(K){let q=K.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!q)return null;return{ability:q[1],type:q[2],id:q[3]?.trim(),paramsEnd:q[0].length}}for(let K of["can","cannot"]){let q=`end${K}`,z=K==="can"?"elsecan":"elsecannot",U=!0;while(U){U=!1;let W=Y.match(new RegExp(`@${K}\\s*\\(`));if(!W||W.index===void 0)break;let _=W.index,B=Y.slice(_+`@${K}`.length),j=G(B);if(!j)break;let H=_+`@${K}`.length+j.paramsEnd,L=X(Y,K,q,H);if(L===-1){console.warn(`[stx] @${K} directive at position ${_} has no matching @${q} \u2014 the block was skipped.`);break}let F=Y.slice(H,L),O=[],V=0,A=new RegExp(`@${K}\\s*\\(`,"g"),w=new RegExp(`@${q}(?![a-z])`,"g"),R=new RegExp(`@${z}\\s*\\(`,"g"),N=/@else(?![a-z])/g,T=[],M;while((M=A.exec(F))!==null)T.push({pos:M.index,type:"open"});while((M=w.exec(F))!==null)T.push({pos:M.index,type:"close"});while((M=R.exec(F))!==null)T.push({pos:M.index,type:"elseDirective"});while((M=N.exec(F))!==null)T.push({pos:M.index,type:"else"});T.sort((S,y)=>S.pos-y.pos);for(let S of T){if(S.type==="open"){V++;continue}if(S.type==="close"){V--;continue}if(V===0)O.push(S)}let I=[],E=0;for(let S=0;S<O.length;S++){let y=O[S];if(I.push({content:F.slice(E,y.pos),ability:void 0}),y.type==="elseDirective"){let d=F.slice(y.pos+`@${z}`.length),f=G(d);if(f){I[I.length-1]={content:F.slice(E,y.pos)},E=y.pos+`@${z}`.length+f.paramsEnd,I.push({content:"",ability:f.ability,type:f.type,id:f.id}),I.pop();let u=O[S+1],s=u?u.pos:F.length;I.push({content:F.slice(E,s),ability:f.ability,type:f.type,id:f.id}),E=s}}else E=y.pos+5}if(E<F.length){let S=I[I.length-1];if(O.length>0&&O[O.length-1].type==="else")I.push({content:F.slice(E),isFinalElse:!0});else if(I.length===0)I.push({content:F.slice(E)})}let D=Q(j.ability,j.type,j.id),k=K==="can"?D:!D,b="";if(k)b=I[0]?.content||"";else{let S=!1;for(let y=1;y<I.length;y++){let d=I[y];if(d.isFinalElse){b=d.content,S=!0;break}if(d.ability){let f=Q(d.ability,d.type,d.id);if(K==="can"?f:!f){b=d.content,S=!0;break}}}if(!S&&I.length>0){let y=I[I.length-1];if(y.isFinalElse)b=y.content}}Y=Y.substring(0,_)+b+Y.substring(L+`@${q}`.length),U=!0}}return Y}function N3($,Z,Y){let X=$;function J(Q,G,K,q,z){let U=!0;while(U){U=!1;let W=new RegExp(`@${G}\\s*\\(`),_=Q.match(W);if(!_||_.index===void 0)break;let B=_.index,j=j1(Q,B+`@${G}`.length);if(!j)break;let H=j.endPos,L=P1(Q,G,K,H);if(L===-1){console.warn(`[stx] @${G} directive at position ${B} has no matching @${K} \u2014 the block was skipped.`);break}let F=Q.slice(H,L),O=j.expression,V=-1,A=0,w=0;while(w<F.length){let R=F.indexOf("@",w);if(R===-1)break;let N=F.substring(R);if(/^@(?:if|unless|isset|empty)\s*\(/.test(N)){A++,w=R+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(N)){A--,w=R+1;continue}if(A===0&&/^@else(?![a-z])/.test(N)){V=R;break}w=R+1}try{let R=q(O.trim()),N;if(V!==-1){let T=F.slice(0,V),M=F.slice(V+5);N=R?T:M}else N=R?F:"";Q=Q.substring(0,B)+N+Q.substring(L+`@${K}`.length),U=!0}catch(R){let N=R instanceof Error?R.message:String(R),T=o(z,`Error processing @${G} directive: ${N}`,m.EVALUATION_ERROR);Q=Q.substring(0,B)+T+Q.substring(L+`@${K}`.length);break}}return Q}return X=J(X,"isset","endisset",(Q)=>{let G=B1(Q,Z);return G!==void 0&&G!==null},"Isset"),X=J(X,"empty","endempty",(Q)=>{let G=B1(Q,Z);return G===void 0||G===null||G===""||G===0||G===!1||Array.isArray(G)&&G.length===0||typeof G==="object"&&G!==null&&Object.keys(G).length===0},"Empty"),X}function T3($,Z,Y){let X=$,J="development";function Q(G,K,q,z){let U=new RegExp(`@${K}(?![a-z])`,"g"),W=new RegExp(`@${q}(?![a-z])`,"g"),_=new RegExp(`^@${K}(?![a-z])`),B=new RegExp(`^@${q}(?![a-z])`),j=G,H=!0;while(H){H=!1,U.lastIndex=0;let L=U.exec(j);if(!L)break;let F=L.index,O=F+L[0].length;if(K==="env"){let D=j.substring(O).match(/^\s*\(\s*(['"])([^'"]+)\1\s*\)/);if(!D)break;O+=D[0].length,z=J===D[2]}let V=1,A=O,w=-1;while(V>0&&A<j.length){U.lastIndex=A,W.lastIndex=A;let D=U.exec(j),k=W.exec(j),b=D?D.index:1/0,S=k?k.index:1/0;if(b<S)V++,A=b+D[0].length;else if(S<1/0){if(V--,V===0){w=S;break}A=S+k[0].length}else break}if(w===-1){console.warn(`[stx] @${K} directive at position ${F} has no matching @${q} \u2014 the block was skipped.`);break}let R=j.substring(O,w),N=-1,T=0,M=0;while(M<R.length){let D=R.indexOf("@",M);if(D===-1)break;let k=R.substring(D);if(_.test(k)){T++,M=D+1;continue}if(B.test(k)){T--,M=D+1;continue}if(T===0&&/^@else(?![a-z])/.test(k)){N=D;break}M=D+1}let I;if(N!==-1){let D=R.slice(0,N),k=R.slice(N+5);I=z?D:k}else I=z?R:"";let E=`@${q}`.length;j=j.substring(0,F)+I+j.substring(w+E),H=!0}return j}return X=Q(X,"env","endenv",!1),X=Q(X,"production","endproduction",J==="production"),X=Q(X,"development","enddevelopment",J==="development"),X=Q(X,"staging","endstaging",J==="staging"),X=Q(X,"testing","endtesting",J==="testing"),X}var Q4=P(()=>{pZ();e0();J4();H0()});function $2($=16){let Z=new Uint8Array($);return crypto.getRandomValues(Z),btoa(String.fromCharCode(...Z))}function v1($,Z){if(!$)return Z?.nonceGenerator?.()??$2();let Y=M3.get($);if(!Y)Y=Z?.nonceGenerator?.()??$2(),M3.set($,Y);return Y}function tV($){M3.delete($)}function Z2($,Z){let Y=[];for(let[X,J]of Object.entries($)){if(J===void 0||J===null)continue;if(typeof J==="boolean"){if(J)Y.push(X);continue}if(Array.isArray(J)){let Q=[...J];if(Z&&(X==="script-src"||X==="style-src"))Q=Q.filter((G)=>!G.startsWith("'nonce-")),Q.push(`'nonce-${Z}'`);if(Q.length>0)Y.push(`${X} ${Q.join(" ")}`)}}return Y.join("; ")}function D3($,Z){return`<meta http-equiv="Content-Security-Policy" content="${Z2($,Z).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}">`}function eV($){return{enabled:!0,directives:{strict:zz,moderate:I3,relaxed:Uz,api:Wz}[$]||I3,useNonce:$==="strict",addMetaTag:!0}}function $w($,Z){let Y={...$};for(let[X,J]of Object.entries(Z)){let Q=X,G=Y[Q];if(J===void 0||J===null)continue;if(typeof J==="boolean")Y[Q]=G||J;else if(Array.isArray(J)){let K=Array.isArray(G)?G:[],q=[...new Set([...K,...J])];Y[Q]=q}}return Y}function Y2($,Z,Y){if(!Z.enabled||!Z.addMetaTag)return $;if($.includes('http-equiv="Content-Security-Policy"'))return $;if(!$.includes("<head>")&&!$.includes("<head "))return $;let X=Z.useNonce?v1(Y,Z):void 0,J=D3(Z.directives,X);return $.replace(/<head([^>]*)>/,`<head$1>
3772
+ `)this.line++,this.column=0;else this.column++;this.pos++}}peek($){return this.source[this.pos+$]}saveState(){return{pos:this.pos,line:this.line,column:this.column}}restoreState($){this.pos=$.pos,this.line=$.line,this.column=$.column}}function F0($,Z,Y,X=0){let J=0,Q=X,G=null,K=0,q=!1;while(Q<$.length){let z=$[Q];if(G&&q){q=!1,Q++;continue}if(G&&z==="\\"){q=!0,Q++;continue}if(q=!1,(z==='"'||z==="'"||z==="`")&&!G){G=z,Q++;continue}if(z===G&&G!=="`"){G=null,Q++;continue}if(G==="`"&&z==="$"&&$[Q+1]==="{"){K++,Q+=2;continue}if(K>0&&z==="}"){K--,Q++;continue}if(z==="`"&&G==="`"&&K===0){G=null,Q++;continue}if(G){Q++;continue}if(z===Z)J++;else if(z===Y){if(J--,J===0)return Q}Q++}return-1}function iZ($,Z){let Y=Z,X={paren:0,bracket:0,brace:0},J=null,Q=0;while(Y<$.length){let G=$[Y];if((Y>0?$[Y-1]:"")==="\\"&&J){Y++;continue}if((G==='"'||G==="'")&&!J){J=G,Y++;continue}if(G===J&&J!=="`"){J=null,Y++;continue}if(G==="`"&&!J){J="`",Y++;continue}if(G==="`"&&J==="`"&&Q===0){J=null,Y++;continue}if(J==="`"&&G==="$"&&$[Y+1]==="{"){Q++,Y+=2;continue}if(Q>0){if(G==="{")Q++;else if(G==="}")Q--;Y++;continue}if(J){Y++;continue}if(X.paren===0&&X.bracket===0&&X.brace===0){if($.slice(Y,Y+2)==="}}"||$.slice(Y,Y+3)==="!!}")break;if(G===","||G===";")break}if(G==="(")X.paren++;else if(G===")"){if(X.paren--,X.paren<0)break}else if(G==="[")X.bracket++;else if(G==="]"){if(X.bracket--,X.bracket<0)break}else if(G==="{")X.brace++;else if(G==="}"){if(X.brace--,X.brace<0)break}Y++}return{expression:$.slice(Z,Y),endPos:Y}}function w3($){let Z=[],Y="",X={paren:0,bracket:0,brace:0},J=null,Q=0;for(let G=0;G<$.length;G++){let K=$[G];if((G>0?$[G-1]:"")==="\\"&&J){Y+=K;continue}if((K==='"'||K==="'")&&!J){J=K,Y+=K;continue}if(K===J&&J!=="`"){J=null,Y+=K;continue}if(K==="`"&&!J){J="`",Y+=K;continue}if(K==="`"&&J==="`"&&Q===0){J=null,Y+=K;continue}if(J==="`"&&K==="$"&&$[G+1]==="{"){Q++,Y+=K+$[G+1],G++;continue}if(Q>0&&K==="{"){Q++,Y+=K;continue}if(Q>0&&K==="}"){Q--,Y+=K;continue}if(J){Y+=K;continue}if(K==="(")X.paren++;else if(K===")")X.paren--;else if(K==="[")X.bracket++;else if(K==="]")X.bracket--;else if(K==="{")X.brace++;else if(K==="}")X.brace--;if(K==="|"&&$[G+1]!=="|"&&(G===0||$[G-1]!=="|")&&$[G-1]!=="\\"&&X.paren===0&&X.bracket===0&&X.brace===0){Z.push(Y.trim()),Y="";continue}if(K==="|"&&$[G-1]==="\\"&&!J){Y=Y.slice(0,-1)+K;continue}Y+=K}if(Y.trim())Z.push(Y.trim());return Z}function j1($,Z){let Y=Zz($,Z);return Y.ok?{expression:Y.expression,endPos:Y.endPos}:null}function Zz($,Z){let Y=Z;while(Y<$.length&&/\s/.test($[Y]))Y++;if($[Y]!=="(")return{ok:!1,reason:"missing-open-paren",pos:Y};let X=F0($,"(",")",Y);if(X===-1)return{ok:!1,reason:"unclosed-paren",pos:Y};return{ok:!0,expression:$.slice(Y+1,X),endPos:X+1}}function P1($,Z,Y,X){let J=1,Q=X,G=new RegExp(`@${Z}\\s*\\(`,"g"),K=new RegExp(`@${Y}(?![a-z])`,"g");while(Q<$.length&&J>0){G.lastIndex=Q,K.lastIndex=Q;let q=G.exec($),z=K.exec($),U=q?q.index:1/0,W=z?z.index:1/0;if(U<W)J++,Q=U+q[0].length;else if(W<1/0){if(J--,J===0)return W;Q=W+z[0].length}else break}return-1}function nZ($,Z){let Y=$.slice(Z).match(/^@if\s*/);if(!Y)return null;let X=Z+Y[0].length,J=j1($,X);if(!J)return null;let Q=J.endPos,G=P1($,"if","endif",Q);if(G===-1)return null;let K=$.slice(Q,G),q=[],z=0,U="if",W=J.expression,_=0,B=0;while(z<K.length){let j=K.indexOf("@",z);if(j===-1)break;z=j;let H=K.substring(j);if(/^@if\s*\(/.test(H)){B++,z++;continue}if(/^@endif(?![a-z])/.test(H)){B--,z+=6;continue}if(B===0){let L=H.match(/^@elseif\s*/);if(L){q.push({type:U,condition:W,content:K.substring(_,z),start:Q+_,end:Q+z});let F=z+L[0].length,O=j1(K,F);if(!O){z++;continue}U="elseif",W=O.expression,z=O.endPos,_=z;continue}else if(/^@else(?![a-z])/.test(H)){q.push({type:U,condition:W,content:K.substring(_,z),start:Q+_,end:Q+z}),U="else",W=void 0,z+=5,_=z;continue}}z++}return q.push({type:U,condition:W,content:K.slice(_),start:Q+_,end:Q+K.length}),{fullMatch:$.slice(Z,G+6),branches:q,start:Z,end:G+6}}function v5($){let Z=[],Y=/@if\s*\(/g,X=Y.exec($);while(X!==null){if(Z.some((G)=>X.index>G.start&&X.index<G.end)){X=Y.exec($);continue}let Q=nZ($,X.index);if(Q)Z.push(Q),Y.lastIndex=Q.end;X=Y.exec($)}return Z}function X4($,Z,Y){let X=[],J=new RegExp(`@${Z}\\s*\\(`,"g"),Q=J.exec($);while(Q!==null){if(X.some((H)=>Q.index>H.start&&Q.index<H.end)){Q=J.exec($);continue}let K=Q.index,q=K+Q[0].length-1,z=F0($,"(",")",q);if(z===-1){Q=J.exec($);continue}let U=$.slice(q+1,z),W=z+1,_=P1($,Z,Y,W);if(_===-1){Q=J.exec($);continue}let B=$.slice(W,_),j=_+`@${Y}`.length;X.push({fullMatch:$.slice(K,j),name:Z,params:U,content:B,start:K,end:j}),J.lastIndex=j,Q=J.exec($)}return X}function A3($,Z){let Y=$.slice(Z).match(/^@switch\s*/);if(!Y)return null;let X=Z+Y[0].length,J=j1($,X);if(!J)return null;let Q=J.endPos,G=P1($,"switch","endswitch",Q);if(G===-1)return null;let K=$.slice(Q,G),q=[],z=0,U=null,W=0;while(z<K.length){let _=K.slice(z),B=_.match(/^@switch\s*\(/),j=_.match(/^@endswitch(?![a-z])/);if(B){if(W++,U)U.content+=B[0];z+=B[0].length;continue}if(j){if(W--,U)U.content+=j[0];z+=j[0].length;continue}if(W>0){if(U)U.content+=K[z];z++;continue}let H=_.match(/^@case\s*/),L=_.match(/^@default(?![a-z])/),F=_.match(/^@break(?![a-z])/);if(H&&_.startsWith("@case")){if(U)q.push(U);let O=z+H[0].length,V=j1(K,O);if(!V){z++;continue}U={type:"case",value:V.expression,content:""},z=V.endPos}else if(L&&_.startsWith("@default")){if(U)q.push(U);U={type:"default",content:""},z+=L[0].length}else if(F&&_.startsWith("@break"))z+=F[0].length;else{if(U)U.content+=K[z];z++}}if(U)q.push(U);return{fullMatch:$.slice(Z,G+10),expression:J.expression,cases:q,start:Z,end:G+10}}var oZ=()=>{};function Yz($){let Z=[],Y=0;while(Y<$.length){let X=$.indexOf("{{",Y),J=$.indexOf("{!!",Y),Q=!1,G;if(X===-1&&J===-1)break;else if(X===-1)G=J,Q=!0;else if(J===-1)G=X,Q=!1;else if(J<X)G=J,Q=!0;else G=X,Q=!1;if(!Q&&$.slice(G,G+3)==="{{{")Q=!0;let K=Q?$.slice(G,G+3)==="{{{"?"{{{":"{!!":"{{",q=Q?K==="{{{"?"}}}":"!!}":"}}",z=G+K.length,U=Xz($,z,q);if(U===-1){Y=G+1;continue}let W=$.slice(z,U).trim(),_=U+q.length;Z.push({fullMatch:$.slice(G,_),expression:W,start:G,end:_,isRaw:Q}),Y=_}return Z}function Xz($,Z,Y){let X=Z,J=null,Q={paren:0,bracket:0,brace:0},G=0;while(X<$.length){let K=$[X];if((X>0?$[X-1]:"")==="\\"&&J){X++;continue}if((K==='"'||K==="'")&&!J){J=K,X++;continue}if(K===J&&J!=="`"){J=null,X++;continue}if(K==="`"&&!J){J="`",X++;continue}if(K==="`"&&J==="`"&&G===0){J=null,X++;continue}if(J==="`"&&K==="$"&&$[X+1]==="{"){G++,X+=2;continue}if(G>0){if(K==="{")G++;else if(K==="}")G--;X++;continue}if(J){X++;continue}if(K==="(")Q.paren++;else if(K===")")Q.paren--;else if(K==="[")Q.bracket++;else if(K==="]")Q.bracket--;else if(K==="{")Q.brace++;else if(K==="}")Q.brace--;if(Q.paren===0&&Q.bracket===0&&Q.brace<=0){if($.slice(X,X+Y.length)===Y)return X}X++}return-1}function Jz($){let Z=w3($);if(Z.length===0)return{baseExpression:"",filters:[]};let Y=Z[0],X=[];for(let J=1;J<Z.length;J++){let Q=Qz(Z[J]);if(Q)X.push(Q)}return{baseExpression:Y,filters:X}}function Qz($){let Z=$.trim();if(!Z)return null;let Y=Z.indexOf("(");if(Y===-1)return{name:Z,args:[]};let X=Z.slice(0,Y).trim(),J=Y+1,Q=F0(Z,"(",")",Y);if(Q===-1)return{name:X,args:[]};let G=Z.slice(J,Q),K=aZ(G);return{name:X,args:K}}function aZ($){let Z=[],Y="",X={paren:0,bracket:0,brace:0},J=null,Q=0;for(let G=0;G<$.length;G++){let K=$[G];if((G>0?$[G-1]:"")==="\\"&&J){Y+=K;continue}if((K==='"'||K==="'")&&!J){J=K,Y+=K;continue}if(K===J&&J!=="`"){J=null,Y+=K;continue}if(K==="`"&&!J){J="`",Y+=K;continue}if(K==="`"&&J==="`"&&Q===0){J=null,Y+=K;continue}if(J==="`"&&K==="$"&&$[G+1]==="{"){Q++,Y+="${",G++;continue}if(Q>0&&K==="{"){Q++,Y+=K;continue}if(Q>0&&K==="}"){Q--,Y+=K;continue}if(J){Y+=K;continue}if(K==="(")X.paren++;else if(K===")")X.paren--;else if(K==="[")X.bracket++;else if(K==="]")X.bracket--;else if(K==="{")X.brace++;else if(K==="}")X.brace--;if(K===","&&X.paren===0&&X.bracket===0&&X.brace===0){Z.push(Y.trim()),Y="";continue}Y+=K}if(Y.trim())Z.push(Y.trim());return Z}function Gz($,Z){let Y=Z;while(Y<$.length&&/\s/.test($[Y]))Y++;if($[Y]!=="(")return null;let X=F0($,"(",")",Y);if(X===-1)return null;return{params:$.slice(Y+1,X),endPos:X+1}}function Kz($){let Z=[],X=new Y4($).tokenize().filter((Q)=>Q.type!=="WHITESPACE"&&Q.type!=="COMMENT"),J=0;while(J<X.length){let Q=X[J],G=!1;if(Q.type==="IDENTIFIER"&&Q.value==="export"){if(G=!0,J++,J>=X.length)break}let K=X[J];if(K.type==="IDENTIFIER"&&(K.value==="const"||K.value==="let"||K.value==="var")){let q=K.value;if(J++,J>=X.length)break;let z=X[J];if(z.type==="IDENTIFIER"){let U=z.value;if(J++,J<X.length&&X[J].type==="OPERATOR"&&X[J].value==="="){J++;let W=J<X.length?X[J].start:$.length,_=sZ(X,J,$);J=_.nextIndex,Z.push({type:"variable",name:U,value:$.slice(W,_.endPos),exported:G,start:K.start,end:_.endPos})}}else if(z.type==="PUNCTUATION"&&(z.value==="{"||z.value==="[")){let U=z.start,W=z.value==="{"?"}":"]",_=F0($,z.value,W,U);if(_!==-1){let B=$.slice(U,_+1);if(J=rZ(X,_+1),J<X.length&&X[J].type==="OPERATOR"&&X[J].value==="="){J++;let j=J<X.length?X[J].start:$.length,H=sZ(X,J,$);J=H.nextIndex;let L=`__stx_destructured_${Z.length}`;Z.push({type:"variable",name:L,value:`${$.slice(j,H.endPos)}; ${q} ${B} = ${L}`,exported:G,start:K.start,end:H.endPos})}}}}else if(K.type==="IDENTIFIER"&&K.value==="function"){let q=G?X[J-1].start:K.start;if(J++,J>=X.length)break;let z=X[J];if(z.type==="IDENTIFIER"){let U=z.value;J++;let W=-1;while(J<X.length){if(X[J].type==="PUNCTUATION"&&X[J].value==="{"){W=X[J].start;break}J++}if(W!==-1){let _=F0($,"{","}",W);if(_!==-1)Z.push({type:"function",name:U,value:$.slice(q,_+1).replace(/^export\s+/,""),exported:G,start:q,end:_+1}),J=rZ(X,_+1)}}}else J++}return Z}function sZ($,Z,Y){let X=Z,J={paren:0,bracket:0,brace:0},Q=Z<$.length?$[Z].start:Y.length;while(X<$.length){let G=$[X];if(G.type==="PUNCTUATION"){if(G.value==="(")J.paren++;else if(G.value===")")J.paren--;else if(G.value==="[")J.bracket++;else if(G.value==="]")J.bracket--;else if(G.value==="{")J.brace++;else if(G.value==="}")J.brace--;if(G.value===";"&&J.paren===0&&J.bracket===0&&J.brace===0){Q=G.start,X++;break}}if(G.type==="IDENTIFIER"&&(G.value==="const"||G.value==="let"||G.value==="var"||G.value==="function"||G.value==="export")){if(J.paren===0&&J.bracket===0&&J.brace===0){Q=$[X-1]?.end??G.start;break}}Q=G.end,X++}return{nextIndex:X,endPos:Q}}function rZ($,Z){for(let Y=0;Y<$.length;Y++)if($[Y].start>=Z)return Y;return $.length}var tZ=()=>{};var J4=P(()=>{oZ();tZ()});function qz($,Z,Y){let X=$,J=!0;while(J){J=!1;let Q=X.match(/@switch\s*\(/);if(!Q||Q.index===void 0)break;let G=Q.index,K=A3(X,G);if(!K)break;try{let q;if($0(K.expression))q=Z0(K.expression,Object.keys(Z))(...Object.values(Z));else q=e(K.expression,Z);let z="",U=!1;for(let W of K.cases)if(W.type==="default"){if(!U)z=W.content.trim()}else try{let _;if(W.value&&$0(W.value))_=Z0(W.value,Object.keys(Z))(...Object.values(Z));else if(W.value)_=e(W.value,Z);if(q===_){z=W.content.trim(),U=!0;break}}catch{continue}X=X.substring(0,G)+z+X.substring(K.end),J=!0}catch(q){let z=q instanceof Error?q.message:String(q),U=o("Switch",`Error evaluating @switch expression: ${z}`,m.EVALUATION_ERROR);X=X.substring(0,G)+U+X.substring(K.end);break}}return X}function C1($,Z,Y){let X=$;X=qz(X,Z,Y);{let Q=!0;while(Q){Q=!1;let G=X.match(/@unless\s*\(/);if(!G||G.index===void 0)break;let K=G.index,q=j1(X,K+7);if(!q)break;let z=q.endPos,U=P1(X,"unless","endunless",z);if(U===-1){console.warn(`[stx] @unless directive at position ${K} has no matching @endunless \u2014 the block was skipped. Check for typos or missing closers.`);break}let W=X.slice(z,U),_=q.expression,B=-1;{let H=0,L=/@(?:if|unless)\s*\(/g,F=/@(?:endif|endunless)(?![a-z])/g,O=/@else(?![a-z])/g,V=[],A;while((A=L.exec(W))!==null)V.push({pos:A.index,type:"open"});while((A=F.exec(W))!==null)V.push({pos:A.index,type:"close"});while((A=O.exec(W))!==null)V.push({pos:A.index,type:"else"});V.sort((w,R)=>w.pos-R.pos);for(let w of V)if(w.type==="open")H++;else if(w.type==="close")H--;else if(w.type==="else"&&H===0){B=w.pos;break}}let j;if(B!==-1){let H=W.slice(0,B),L=W.slice(B+5);j=`@if (${_})${L}@else ${H}@endif`}else j=`@if (!(${_}))${W}@endif`;X=X.substring(0,K)+j+X.substring(U+10),Q=!0}}X=N3(X,Z,Y),X=T3(X,Z,Y),X=R3(X,Z);let J=()=>{let Q=v5(X);if(Q.length===0)return!1;for(let G=Q.length-1;G>=0;G--){let K=Q[G];try{let q="",z=!1;for(let U of K.branches){if(z)break;if(U.type==="else")q=U.content,z=!0;else try{let W;if(U.condition&&$0(U.condition))W=Z0(U.condition,Object.keys(Z))(...Object.values(Z));else if(U.condition)W=e(U.condition,Z);if(W)q=U.content,z=!0}catch(W){q=o(U.type==="if"?"If":"Elseif",`Error in @${U.type}(${U.condition}): ${W instanceof Error?W.message:String(W)}`,m.EVALUATION_ERROR),z=!0}}X=X.substring(0,K.start)+q+X.substring(K.end)}catch(q){let z=q instanceof Error?q.message:String(q),U=o("If",`Error processing @if block: ${z}`,m.EVALUATION_ERROR);X=X.substring(0,K.start)+U+X.substring(K.end)}}return!0};while(!0){let Q=X;if(!J())break;if(X===Q)break}return X}function eZ($){let Z=0;while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!=="(")return null;Z++;while(Z<$.length&&/\s/.test($[Z]))Z++;let Y=$[Z];if(Y!=="'"&&Y!=='"')return null;Z++;let X=[];while(Z<$.length){let J=$[Z];if(J==="\\"&&Z+1<$.length){X.push($[Z+1]),Z+=2;continue}if(J===Y){Z++;break}X.push(J),Z++}while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!==")")return null;return Z++,{value:X.join(""),consumed:Z}}function R3($,Z){let Y=$;function X(K,q,z,U){let W=1,_=U,B=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),j=new RegExp(`@${z}(?![a-z])`,"g");while(_<K.length&&W>0){B.lastIndex=_,j.lastIndex=_;let H=B.exec(K),L=j.exec(K),F=H?H.index:1/0,O=L?L.index:1/0;if(F<O)W++,_=F+H[0].length;else if(O<1/0){if(W--,W===0)return O;_=O+L[0].length}else break}return-1}function J(K,q,z){let U=0,W=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),_=new RegExp(`@${z}(?![a-z])`,"g"),B=/@else(?![a-z])/g,j=[],H;while((H=W.exec(K))!==null)j.push({pos:H.index,type:"open"});while((H=_.exec(K))!==null)j.push({pos:H.index,type:"close"});while((H=B.exec(K))!==null)j.push({pos:H.index,type:"else"});j.sort((L,F)=>L.pos-F.pos);for(let L of j)if(L.type==="open")U++;else if(L.type==="close")U--;else if(L.type==="else"&&U===0)return L.pos;return-1}{let K=!0;while(K){K=!1;let q=Y.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!q||q.index===void 0)break;let z=q.index,U,W,_=Y.slice(z+5),B=eZ(_);if(B)U=B.value,W=z+5+B.consumed;else W=z+5;let j=X(Y,"auth","endauth",W);if(j===-1){console.warn(`[stx] @auth directive at position ${z} has no matching @endauth \u2014 the block was skipped.`);break}let H=Y.slice(W,j),L=J(H,"auth","endauth"),F;if(!Z.auth)F=!1;else F=U?B1(`auth?.check && auth?.user?.[${U}]`,Z):B1("auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),A=H.slice(L+5);O=F?V:A}else O=F?H:"";Y=Y.substring(0,z)+O+Y.substring(j+8),K=!0}}{let K=!0;while(K){K=!1;let q=Y.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!q||q.index===void 0)break;let z=q.index,U,W,_=Y.slice(z+6),B=eZ(_);if(B)U=B.value,W=z+6+B.consumed;else W=z+6;let j=X(Y,"guest","endguest",W);if(j===-1){console.warn(`[stx] @guest directive at position ${z} has no matching @endguest \u2014 the block was skipped.`);break}let H=Y.slice(W,j),L=J(H,"guest","endguest"),F;if(!Z.auth)F=!0;else F=U?B1(`!auth?.check || !auth?.user?.[${U}]`,Z):B1("!auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),A=H.slice(L+5);O=F?V:A}else O=F?H:"";Y=Y.substring(0,z)+O+Y.substring(j+9),K=!0}}function Q(K,q,z){if(Z.userCan&&typeof Z.userCan[K]==="boolean")return Z.userCan[K];if(Z.permissions?.check&&typeof Z.permissions.check==="function")try{let U=[K];if(q)U.push(q);if(z){let W=B1(z,Z);U.push(W)}return Z.permissions.check(...U)}catch{return!1}return!1}function G(K){let q=K.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!q)return null;return{ability:q[1],type:q[2],id:q[3]?.trim(),paramsEnd:q[0].length}}for(let K of["can","cannot"]){let q=`end${K}`,z=K==="can"?"elsecan":"elsecannot",U=!0;while(U){U=!1;let W=Y.match(new RegExp(`@${K}\\s*\\(`));if(!W||W.index===void 0)break;let _=W.index,B=Y.slice(_+`@${K}`.length),j=G(B);if(!j)break;let H=_+`@${K}`.length+j.paramsEnd,L=X(Y,K,q,H);if(L===-1){console.warn(`[stx] @${K} directive at position ${_} has no matching @${q} \u2014 the block was skipped.`);break}let F=Y.slice(H,L),O=[],V=0,A=new RegExp(`@${K}\\s*\\(`,"g"),w=new RegExp(`@${q}(?![a-z])`,"g"),R=new RegExp(`@${z}\\s*\\(`,"g"),N=/@else(?![a-z])/g,T=[],M;while((M=A.exec(F))!==null)T.push({pos:M.index,type:"open"});while((M=w.exec(F))!==null)T.push({pos:M.index,type:"close"});while((M=R.exec(F))!==null)T.push({pos:M.index,type:"elseDirective"});while((M=N.exec(F))!==null)T.push({pos:M.index,type:"else"});T.sort((S,y)=>S.pos-y.pos);for(let S of T){if(S.type==="open"){V++;continue}if(S.type==="close"){V--;continue}if(V===0)O.push(S)}let I=[],E=0;for(let S=0;S<O.length;S++){let y=O[S];if(I.push({content:F.slice(E,y.pos),ability:void 0}),y.type==="elseDirective"){let d=F.slice(y.pos+`@${z}`.length),f=G(d);if(f){I[I.length-1]={content:F.slice(E,y.pos)},E=y.pos+`@${z}`.length+f.paramsEnd,I.push({content:"",ability:f.ability,type:f.type,id:f.id}),I.pop();let u=O[S+1],s=u?u.pos:F.length;I.push({content:F.slice(E,s),ability:f.ability,type:f.type,id:f.id}),E=s}}else E=y.pos+5}if(E<F.length){let S=I[I.length-1];if(O.length>0&&O[O.length-1].type==="else")I.push({content:F.slice(E),isFinalElse:!0});else if(I.length===0)I.push({content:F.slice(E)})}let D=Q(j.ability,j.type,j.id),k=K==="can"?D:!D,b="";if(k)b=I[0]?.content||"";else{let S=!1;for(let y=1;y<I.length;y++){let d=I[y];if(d.isFinalElse){b=d.content,S=!0;break}if(d.ability){let f=Q(d.ability,d.type,d.id);if(K==="can"?f:!f){b=d.content,S=!0;break}}}if(!S&&I.length>0){let y=I[I.length-1];if(y.isFinalElse)b=y.content}}Y=Y.substring(0,_)+b+Y.substring(L+`@${q}`.length),U=!0}}return Y}function N3($,Z,Y){let X=$;function J(Q,G,K,q,z){let U=!0;while(U){U=!1;let W=new RegExp(`@${G}\\s*\\(`),_=Q.match(W);if(!_||_.index===void 0)break;let B=_.index,j=j1(Q,B+`@${G}`.length);if(!j)break;let H=j.endPos,L=P1(Q,G,K,H);if(L===-1){console.warn(`[stx] @${G} directive at position ${B} has no matching @${K} \u2014 the block was skipped.`);break}let F=Q.slice(H,L),O=j.expression,V=-1,A=0,w=0;while(w<F.length){let R=F.indexOf("@",w);if(R===-1)break;let N=F.substring(R);if(/^@(?:if|unless|isset|empty)\s*\(/.test(N)){A++,w=R+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(N)){A--,w=R+1;continue}if(A===0&&/^@else(?![a-z])/.test(N)){V=R;break}w=R+1}try{let R=q(O.trim()),N;if(V!==-1){let T=F.slice(0,V),M=F.slice(V+5);N=R?T:M}else N=R?F:"";Q=Q.substring(0,B)+N+Q.substring(L+`@${K}`.length),U=!0}catch(R){let N=R instanceof Error?R.message:String(R),T=o(z,`Error processing @${G} directive: ${N}`,m.EVALUATION_ERROR);Q=Q.substring(0,B)+T+Q.substring(L+`@${K}`.length);break}}return Q}return X=J(X,"isset","endisset",(Q)=>{let G=B1(Q,Z);return G!==void 0&&G!==null},"Isset"),X=J(X,"empty","endempty",(Q)=>{let G=B1(Q,Z);return G===void 0||G===null||G===""||G===0||G===!1||Array.isArray(G)&&G.length===0||typeof G==="object"&&G!==null&&Object.keys(G).length===0},"Empty"),X}function T3($,Z,Y){let X=$,J="development";function Q(G,K,q,z){let U=new RegExp(`@${K}(?![a-z])`,"g"),W=new RegExp(`@${q}(?![a-z])`,"g"),_=new RegExp(`^@${K}(?![a-z])`),B=new RegExp(`^@${q}(?![a-z])`),j=G,H=!0;while(H){H=!1,U.lastIndex=0;let L=U.exec(j);if(!L)break;let F=L.index,O=F+L[0].length;if(K==="env"){let D=j.substring(O).match(/^\s*\(\s*(['"])([^'"]+)\1\s*\)/);if(!D)break;O+=D[0].length,z=J===D[2]}let V=1,A=O,w=-1;while(V>0&&A<j.length){U.lastIndex=A,W.lastIndex=A;let D=U.exec(j),k=W.exec(j),b=D?D.index:1/0,S=k?k.index:1/0;if(b<S)V++,A=b+D[0].length;else if(S<1/0){if(V--,V===0){w=S;break}A=S+k[0].length}else break}if(w===-1){console.warn(`[stx] @${K} directive at position ${F} has no matching @${q} \u2014 the block was skipped.`);break}let R=j.substring(O,w),N=-1,T=0,M=0;while(M<R.length){let D=R.indexOf("@",M);if(D===-1)break;let k=R.substring(D);if(_.test(k)){T++,M=D+1;continue}if(B.test(k)){T--,M=D+1;continue}if(T===0&&/^@else(?![a-z])/.test(k)){N=D;break}M=D+1}let I;if(N!==-1){let D=R.slice(0,N),k=R.slice(N+5);I=z?D:k}else I=z?R:"";let E=`@${q}`.length;j=j.substring(0,F)+I+j.substring(w+E),H=!0}return j}return X=Q(X,"env","endenv",!1),X=Q(X,"production","endproduction",J==="production"),X=Q(X,"development","enddevelopment",J==="development"),X=Q(X,"staging","endstaging",J==="staging"),X=Q(X,"testing","endtesting",J==="testing"),X}var Q4=P(()=>{pZ();e0();J4();H0()});function $2($=16){let Z=new Uint8Array($);return crypto.getRandomValues(Z),btoa(String.fromCharCode(...Z))}function v1($,Z){if(!$)return Z?.nonceGenerator?.()??$2();let Y=M3.get($);if(!Y)Y=Z?.nonceGenerator?.()??$2(),M3.set($,Y);return Y}function tV($){M3.delete($)}function Z2($,Z){let Y=[];for(let[X,J]of Object.entries($)){if(J===void 0||J===null)continue;if(typeof J==="boolean"){if(J)Y.push(X);continue}if(Array.isArray(J)){let Q=[...J];if(Z&&(X==="script-src"||X==="style-src"))Q=Q.filter((G)=>!G.startsWith("'nonce-")),Q.push(`'nonce-${Z}'`);if(Q.length>0)Y.push(`${X} ${Q.join(" ")}`)}}return Y.join("; ")}function D3($,Z){return`<meta http-equiv="Content-Security-Policy" content="${Z2($,Z).replace(/&/g,"&amp;").replace(/"/g,"&quot;")}">`}function eV($){return{enabled:!0,directives:{strict:zz,moderate:I3,relaxed:Uz,api:Wz}[$]||I3,useNonce:$==="strict",addMetaTag:!0}}function $w($,Z){let Y={...$};for(let[X,J]of Object.entries(Z)){let Q=X,G=Y[Q];if(J===void 0||J===null)continue;if(typeof J==="boolean")Y[Q]=G||J;else if(Array.isArray(J)){let K=Array.isArray(G)?G:[],q=[...new Set([...K,...J])];Y[Q]=q}}return Y}function Y2($,Z,Y){if(!Z.enabled||!Z.addMetaTag)return $;if($.includes('http-equiv="Content-Security-Policy"'))return $;if(!$.includes("<head>")&&!$.includes("<head "))return $;let X=Z.useNonce?v1(Y,Z):void 0,J=D3(Z.directives,X);return $.replace(/<head([^>]*)>/,`<head$1>
3773
3773
  ${J}`)}function Zw($,Z){let Y=$;return Y=Y.replace(/<script(?![^>]*\ssrc=)([^>]*)>/gi,(X,J)=>{if(J.includes("nonce="))return X;return`<script nonce="${Z}"${J}>`}),Y=Y.replace(/<style([^>]*)>/gi,(X,J)=>{if(J.includes("nonce="))return X;return`<style nonce="${Z}"${J}>`}),Y}function X2($,Z,Y,X){let J=$,Q=X.csp;if(J=J.replace(/@csp\b/g,()=>{if(!Q?.enabled||!Q.directives)return"<!-- CSP not configured -->";let G=Q.useNonce?v1(Z,Q):void 0;return D3(Q.directives,G)}),J=J.replace(/@cspNonce\b/g,()=>{if(!Q?.enabled||!Q.useNonce)return"";return v1(Z,Q)}),Q?.enabled&&Q.useNonce)Z.cspNonce=v1(Z,Q);return J}function Yw(){return[_z,Bz]}function Xw($){let Z=[];if($["script-src"]?.includes("'unsafe-inline'"))Z.push("CSP: Using unsafe-inline in script-src significantly reduces XSS protection");if($["script-src"]?.includes("'unsafe-eval'"))Z.push("CSP: Using unsafe-eval in script-src allows eval() and related functions");if(!$["default-src"])Z.push("CSP: No default-src specified. Recommend adding default-src as a fallback");if($["default-src"]?.includes("*"))Z.push("CSP: Using * in default-src provides minimal protection");if(!$["object-src"]&&!$["default-src"]?.includes("'none'"))Z.push("CSP: Consider adding object-src: none to block plugins");if(!$["base-uri"])Z.push("CSP: Consider adding base-uri to prevent base tag injection attacks");for(let[Y,X]of Object.entries($))if(Array.isArray(X)&&X.includes("http:"))Z.push(`CSP: Using http: in ${Y} allows insecure resources`);return Z}function jz($=!1){return $?"Content-Security-Policy-Report-Only":"Content-Security-Policy"}function Jw($,Z){if(!$.enabled)return{};let Y=$.useNonce?v1(Z,$):void 0,X=Z2($.directives,Y);return{[jz($.reportOnly)]:X}}var M3,zz,I3,Uz,Wz,_z,Bz,Qw;var J2=P(()=>{M3=new WeakMap;zz={"default-src":["'self'"],"script-src":["'self'","'strict-dynamic'"],"style-src":["'self'"],"img-src":["'self'","data:","https:"],"font-src":["'self'","https:","data:"],"connect-src":["'self'"],"media-src":["'self'"],"object-src":["'none'"],"frame-src":["'none'"],"base-uri":["'self'"],"form-action":["'self'"],"frame-ancestors":["'self'"],"upgrade-insecure-requests":!0},I3={"default-src":["'self'"],"script-src":["'self'"],"style-src":["'self'","'unsafe-inline'"],"img-src":["'self'","data:","https:"],"font-src":["'self'","https:","data:"],"connect-src":["'self'","https:"],"media-src":["'self'"],"object-src":["'none'"],"frame-src":["'self'"],"base-uri":["'self'"],"form-action":["'self'"],"upgrade-insecure-requests":!0},Uz={"default-src":["'self'"],"script-src":["'self'","'unsafe-inline'"],"style-src":["'self'","'unsafe-inline'"],"img-src":["'self'","data:","https:","http:"],"font-src":["'self'","https:","http:","data:"],"connect-src":["'self'","https:","http:","ws:","wss:"],"media-src":["'self'","https:","http:"],"object-src":["'none'"],"frame-src":["'self'","https:"],"base-uri":["'self'"]},Wz={"default-src":["'none'"],"frame-ancestors":["'none'"]};_z={name:"csp",handler:($,Z,Y,X)=>{let Q=Y.__stx_options?.csp;if(!Q?.enabled||!Q.directives)return"<!-- CSP not configured -->";let G=Q.useNonce?v1(Y,Q):void 0;return D3(Q.directives,G)},hasEndTag:!1,description:"Insert Content-Security-Policy meta tag"},Bz={name:"cspNonce",handler:($,Z,Y,X)=>{let Q=Y.__stx_options?.csp;if(!Q?.enabled||!Q.useNonce)return"";return v1(Y,Q)},hasEndTag:!1,description:"Output the current CSP nonce value"};Qw={enabled:!1,reportOnly:!1,directives:I3,useNonce:!1,addMetaTag:!0}});import{Buffer as Q2}from"buffer";import G2 from"crypto";function Oz($=Hz){let Z=G2.randomBytes(Math.ceil($/2)).toString("hex").slice(0,$);return q5=Z,Z}function Lz(){if(!q5)Oz();return q5}function zw(){q5=null}function Uw($){q5=$}function Fz($=K2){let Z=Lz();return`<input type="hidden" name="${$}" value="${Z}">`}function q2($){return $.replace(/@csrf(?:\((['"])([^'"]*)\1\))?/g,(Z,Y,X)=>{return Fz(X||K2)})}function Ww($,Z){let Y=Z??q5;if(!Y)return!1;let X=Q2.from($),J=Q2.from(Y);if(X.length!==J.length)return!1;return G2.timingSafeEqual(X,J)}var Hz=40,K2="_token",q5=null;var z2=()=>{};async function U2($,Z,Y,X){if(!X.customDirectives||X.customDirectives.length===0)return $;let J=$;for(let Q of X.customDirectives){if(!Q.name||typeof Q.handler!=="function"){if(X.debug)console.warn("Invalid custom directive:",Q);continue}if(Q.hasEndTag)J=await Vz(J,Q,Z,Y,X);else J=await wz(J,Q,Z,Y,X)}return J}async function Vz($,Z,Y,X,J){let{name:Q,handler:G}=Z,K=`@${Q}`,q=`@end${Q}`,z=$,U=I1(`${K}(?:\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\))?([\\s\\S]*?)${q}`,"g"),W=[],_=U.exec(z);while(_!==null){let[B,j="",H=""]=_,L=_.index||0;try{let F=j?W2(j):[],O=H.trim(),V=await G(O,F,Y,X);W.push({original:B,processed:V,startIndex:L})}catch(F){let O=F instanceof Error?F.message:String(F);if(J.debug)console.error(`Error processing custom directive @${Q}:`,F);W.push({original:B,processed:o("CustomDirective",`Error in @${Q}${j?`(${j})`:""}: ${O}`,m.EVALUATION_ERROR),startIndex:L})}_=U.exec(z)}for(let B=W.length-1;B>=0;B--){let{original:j,processed:H}=W[B];z=z.replace(j,H)}return z}async function wz($,Z,Y,X,J){let{name:Q,handler:G}=Z,K=$,q=I1(`@${Q}\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\)`,"g"),z=[],U=q.exec(K);while(U!==null){let[B,j=""]=U,H=U.index||0;try{let L=W2(j),F=await G("",L,Y,X);z.push({original:B,processed:F,startIndex:H})}catch(L){let F=L instanceof Error?L.message:String(L);if(J.debug)console.error(`Error processing custom directive @${Q}:`,L);z.push({original:B,processed:o("CustomDirective",`Error in @${Q}(${j}): ${F}`,m.EVALUATION_ERROR),startIndex:H})}U=q.exec(K)}let W=I1(`@${Q}(?!\\w)(?!\\s*\\()`,"g"),_=W.exec(K);while(_!==null){let[B]=_,j=_.index||0;try{let H=await G("",[],Y,X);z.push({original:B,processed:H,startIndex:j})}catch(H){let L=H instanceof Error?H.message:String(H);if(J.debug)console.error(`Error processing custom directive @${Q}:`,H);z.push({original:B,processed:o("CustomDirective",`Error in @${Q}: ${L}`,m.EVALUATION_ERROR),startIndex:j})}_=W.exec(K)}for(let B=z.length-1;B>=0;B--){let{original:j,processed:H}=z[B];K=K.replace(j,H)}return K}function W2($){if(!$.trim())return[];let Z=[],Y="",X=!1,J="";for(let Q=0;Q<$.length;Q++){let G=$[Q];if((G==='"'||G==="'")&&(Q===0||$[Q-1]!=="\\"))if(!X)X=!0,J=G;else if(G===J)X=!1;else Y+=G;else if(G===","&&!X)Z.push(Y.trim()),Y="";else Y+=G}if(Y.trim())Z.push(Y.trim());return Z.map((Q)=>{let G=Q.trim();if(G.startsWith('"')&&G.endsWith('"')||G.startsWith("'")&&G.endsWith("'"))return G.substring(1,G.length-1);return G})}var _2=P(()=>{e0();a1()});var E3={};i(E3,{useTitle:()=>Iz,useSeoMeta:()=>K4,usePageTitle:()=>Iz,useHead:()=>f1,resetHead:()=>Nz,renderHtmlAttrs:()=>Ez,renderHead:()=>Dz,renderBodyAttrs:()=>kz,processTitleDirective:()=>yz,processMetaDirective:()=>Pz,processHeadDirective:()=>Sz,getPageMeta:()=>Rz,getHead:()=>x5,definePageMeta:()=>Mz,applyHead:()=>bz});function x5(){return H1}function Rz(){return G4}function Nz(){H1={},Az.length=0,G4={}}function f1($){H1=Tz(H1,$)}function Tz($,Z){return{title:Z.title??$.title,titleTemplate:Z.titleTemplate??$.titleTemplate,base:Z.base??$.base,meta:[...$.meta||[],...Z.meta||[]],link:[...$.link||[],...Z.link||[]],script:[...$.script||[],...Z.script||[]],style:[...$.style||[],...Z.style||[]],htmlAttrs:{...$.htmlAttrs,...Z.htmlAttrs},bodyAttrs:{...$.bodyAttrs,...Z.bodyAttrs}}}function K4($){let Z=[];if($.description)Z.push({name:"description",content:$.description});if($.keywords){let q=Array.isArray($.keywords)?$.keywords.join(", "):$.keywords;Z.push({name:"keywords",content:q})}if($.author)Z.push({name:"author",content:$.author});if($.robots)Z.push({name:"robots",content:$.robots});let Y=$.ogTitle??$.title,X=$.ogDescription??$.description;if(Y)Z.push({property:"og:title",content:Y});if(X)Z.push({property:"og:description",content:X});if($.ogImage)Z.push({property:"og:image",content:$.ogImage});if($.ogUrl)Z.push({property:"og:url",content:$.ogUrl});if($.ogType)Z.push({property:"og:type",content:$.ogType});if($.ogSiteName)Z.push({property:"og:site_name",content:$.ogSiteName});if($.ogLocale)Z.push({property:"og:locale",content:$.ogLocale});let J=$.twitterTitle??$.title,Q=$.twitterDescription??$.description,G=$.twitterImage??$.ogImage;if($.twitterCard)Z.push({name:"twitter:card",content:$.twitterCard});if(J)Z.push({name:"twitter:title",content:J});if(Q)Z.push({name:"twitter:description",content:Q});if(G)Z.push({name:"twitter:image",content:G});if($.twitterSite)Z.push({name:"twitter:site",content:$.twitterSite});if($.twitterCreator)Z.push({name:"twitter:creator",content:$.twitterCreator});if($.articleAuthor)Z.push({property:"article:author",content:$.articleAuthor});if($.articlePublishedTime)Z.push({property:"article:published_time",content:$.articlePublishedTime});if($.articleModifiedTime)Z.push({property:"article:modified_time",content:$.articleModifiedTime});if($.articleSection)Z.push({property:"article:section",content:$.articleSection});if($.articleTags)for(let q of $.articleTags)Z.push({property:"article:tag",content:q});let K=[];if($.canonical)K.push({rel:"canonical",href:$.canonical});f1({title:$.title,titleTemplate:$.titleTemplate,meta:Z,link:K})}function Mz($){if(G4={...G4,...$},$.title||$.description)K4({title:$.title,description:$.description})}function Iz($){let Z=typeof $==="function"?$():$;f1({title:Z})}function Dz($=H1){let Z=[];if($.title){let Y=$.title;if($.titleTemplate)Y=typeof $.titleTemplate==="function"?$.titleTemplate(Y):$.titleTemplate.replace("%s",Y);Z.push(`<title>${x1(Y)}</title>`)}if($.base){let Y=Object.entries($.base).map(([X,J])=>`${X}="${x1(J)}"`).join(" ");Z.push(`<base ${Y}>`)}for(let Y of $.meta||[]){let X=Object.entries(Y).filter(([J,Q])=>Q!==void 0).map(([J,Q])=>{return`${J==="httpEquiv"?"http-equiv":J}="${x1(String(Q))}"`}).join(" ");Z.push(`<meta ${X}>`)}for(let Y of $.link||[]){let X=Object.entries(Y).filter(([J,Q])=>Q!==void 0).map(([J,Q])=>`${J}="${x1(String(Q))}"`).join(" ");Z.push(`<link ${X}>`)}for(let Y of $.script||[]){let{content:X,...J}=Y,Q=Object.entries(J).filter(([G,K])=>K!==void 0).map(([G,K])=>{if(typeof K==="boolean")return K?G:"";return`${G}="${x1(String(K))}"`}).filter(Boolean).join(" ");if(X)Z.push(`<script ${Q}>${X}</script>`);else Z.push(`<script ${Q}></script>`)}for(let Y of $.style||[]){let X=Y.type?` type="${Y.type}"`:"";Z.push(`<style${X}>${Y.content}</style>`)}return Z.join(`
3774
3774
  `)}function Ez($=H1){if(!$.htmlAttrs)return"";return Object.entries($.htmlAttrs).map(([Z,Y])=>`${Z}="${x1(Y)}"`).join(" ")}function kz($=H1){if(!$.bodyAttrs)return"";return Object.entries($.bodyAttrs).map(([Z,Y])=>`${Z}="${x1(Y)}"`).join(" ")}function x1($){return $.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function bz($=H1){if(typeof document>"u")return;if($.title){let Z=$.title;if($.titleTemplate)Z=typeof $.titleTemplate==="function"?$.titleTemplate(Z):$.titleTemplate.replace("%s",Z);document.title=Z}for(let Z of $.meta||[]){let Y=Z.name?`meta[name="${Z.name}"]`:Z.property?`meta[property="${Z.property}"]`:null;if(Y){let X=document.querySelector(Y);if(!X){if(X=document.createElement("meta"),Z.name)X.setAttribute("name",Z.name);if(Z.property)X.setAttribute("property",Z.property);document.head.appendChild(X)}X.setAttribute("content",Z.content)}}for(let Z of $.link||[]){let Y=`link[rel="${Z.rel}"]${Z.href?`[href="${Z.href}"]`:""}`,X=document.querySelector(Y);if(!X)X=document.createElement("link"),document.head.appendChild(X);for(let[J,Q]of Object.entries(Z))if(Q!==void 0)X.setAttribute(J,String(Q))}if($.htmlAttrs)for(let[Z,Y]of Object.entries($.htmlAttrs))document.documentElement.setAttribute(Z,Y);if($.bodyAttrs)for(let[Z,Y]of Object.entries($.bodyAttrs))document.body.setAttribute(Z,Y)}function Sz($){let Z="";return{content:$.replace(/@head\s*([\s\S]*?)@endhead/g,(X,J)=>{return Z+=J.trim()+`
3775
3775
  `,""}),headContent:Z.trim()}}function yz($,Z){return $.replace(/@title\s*\(\s*(?:(['"`])(.+?)\1|([^)]+))\s*\)/g,(Y,X,J,Q)=>{let G=X?J:Z[(Q||"").trim()]??Q;return f1({title:G}),""})}function Pz($,Z){return $.replace(/@meta\s*\(\s*(['"`])(.+?)\1\s*,\s*(?:(['"`])(.+?)\3|([^)]+))\s*\)/g,(Y,X,J,Q,G,K)=>{let q=Q?G:K,z=Q?q:Z[(q||"").trim()]??q,W=J.includes(":")?{property:J,content:z}:{name:J,content:z};return f1({meta:[W]}),""})}var H1,Az,G4;var f5=P(()=>{H1={},Az=[],G4={}});import Cz from"crypto";function w0($){return String($??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function vz($){return{...k3,...$.forms?.classes}}function q4($,Z,Y,X){let J=$||Z;return Y?`${J} ${X}`:J}function xz(){return Cz.randomUUID()}function Fw($,Z,Y,X){let J=vz(X),Q=$;return Q=gz(Q,Z),Q=d5(Q,Z),Q=b3(Q,Z,J),Q=S3(Q,Z,J),Q}function d5($,Z){let Y=$;return Y=Y.replace(/@csrf/g,()=>{if(!Z.csrf||typeof Z.csrf!=="object"){let X=xz();Z.csrf={token:X}}if(Z.csrf.field)return Z.csrf.field;if(Z.csrf.token)return`<input type="hidden" name="_token" value="${w0(Z.csrf.token)}">`;return'<input type="hidden" name="_token" value="">'}),Y=Y.replace(/@method\(['"]([^'"]+)['"]\)/g,(X,J)=>{let Q=J.toUpperCase();if(J&&!["GET","POST"].includes(Q))return`<input type="hidden" name="_method" value="${w0(Q)}">`;return X}),Y}function b3($,Z,Y=k3){let X=$;return X=X.replace(/@form\(\s*(?:(?:'([^']+)'|"([^"]+)")\s*)?(?:,\s*(?:'([^']+)'|"([^"]+)")?)?\s*(?:,\s*\{([^}]+)\}\s*)?\)/g,(J,Q,G,K,q,z="")=>{let U=Q||G||"POST",W=K||q||"",_=O1(z),B=U.toUpperCase(),j=["GET","POST"].includes(B)?B:"POST",H=`<form method="${w0(j)}" action="${w0(W)}"${_?` ${_}`:""}>`;if(H+=`
@@ -76,4 +76,4 @@ ${"\x1B[31m"}\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\
76
76
  @end${X}`;$.push(`Added ${H} missing @end${X}`)}}if($.length>0&&W.logRecoveryWarnings)console.warn("[stx] Auto-recovery applied fixes:"),$.forEach((X)=>console.warn(` - ${X}`)),console.warn(" Consider fixing these issues in your template.");return{fixed:Z,fixes:$}},createFallbackContent(J,W){if(s())return`<!-- ${J} failed: ${W.message} -->`;return"<!-- stx rendering error -->"}};kZ=new _J,EZ={isDevelopment(){return s()},logDetailedError(J,W){if(!this.isDevelopment())return;if(console.error("=== stx Detailed Error ==="),console.error("Error:",J.message),console.error("Stack:",J.stack),W)console.error("Context:",W);console.error("========================")},createErrorReport(J,W){let Z=["=== stx Error Report ===",`Time: ${new Date().toISOString()}`,`Error: ${J.message}`,`Type: ${J.constructor.name}`,`Stack: ${J.stack}`];if(W)Z.push(`Context: ${JSON.stringify(W,null,2)}`);return Z.push("========================"),Z.join(`
77
77
  `)}}});import KJ from"path";function SZ(J){let W={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return J.replace(/[&<>"']/g,(Z)=>W[Z]||Z)}function ZJ(J,W={}){let{allowHtml:Z=!1,maxLength:$=1e4,allowSpecialChars:Q=!0,customSanitizer:Y}=W,U=[],X=J,V=!1;if(Y){let H=Y(X);if(H!==X)X=H,V=!0}if(X.includes("\x00"))X=X.replace(/\0/g,""),V=!0,U.push("Null bytes removed from parameter");if(X.length>$)X=X.substring(0,$),V=!0,U.push(`Parameter truncated to ${$} characters`);if(!Z&&/<[^>]+>/.test(X))X=SZ(X),V=!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:F,name:_}of q)if(H.test(X))X=X.replace(H,F),V=!0,U.push(`Removed ${_} from parameter`);if(!Q){let H=X;if(X=X.split("").filter((F)=>{let _=F.charCodeAt(0);return _>=32&&_!==127}).join(""),X!==H)V=!0,U.push("Control characters removed")}return{value:X,modified:V,warnings:U}}function CZ(J,W){let Z=J.replace(/\0/g,"");Z=Z.replace(/\\/g,"/"),Z=Z.replace(/^[a-z][a-z0-9+.-]*:/i,"");while(Z.includes("../")||Z.includes("./"))Z=Z.replace(/\.\.\//g,"").replace(/\.\//g,"");if(!OJ.isValidFilePath(Z,W))return null;return Z}function vZ(J){let W=[],Z=J.trim(),$=Z!==J,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(Z))W.push(`Potentially dangerous pattern detected: ${U}`);if(Z.includes("\x00"))Z=Z.replace(/\0/g,""),$=!0,W.push("Null bytes removed from expression");return{value:Z,modified:$,warnings:W}}function gZ(J,W={}){return J.map((Z)=>ZJ(Z,W))}function xJ(J){let W={};for(let[Z,$]of Object.entries(J)){if(!OJ.isValidVariableName(Z))continue;if(typeof $==="string"){let Q=ZJ($);W[Z]=Q.value}else if(Array.isArray($))W[Z]=$.map((Q)=>typeof Q==="string"?ZJ(Q).value:Q);else if(typeof $==="object"&&$!==null)W[Z]=xJ($);else W[Z]=$}return W}var OJ;var mJ=E(()=>{OJ={isValidFilePath(J,W){let Z=J.replace(/\\/g,"/");if(Z.includes("\x00"))return!1;if(Z.includes("../")||Z.includes("..\\")||Z===".."||Z.startsWith("../")||Z.endsWith("/..")||Z.includes("/..\\")||Z.includes("\\../"))return!1;if(/^[a-z][a-z0-9+.-]*:/i.test(Z))return!1;if(Z.startsWith("/")){if(["/etc/","/root/","/var/","/usr/","/bin/","/sbin/","/proc/","/sys/","/dev/","/boot/","/home/","/private/","/Library/","/System/"].some((Y)=>Z===Y.slice(0,-1)||Z.startsWith(Y)))return!1}if(/^[a-z]:/i.test(Z)){if(["Windows/","Windows\\","System32/","System32\\","Program Files/","Program Files\\"].some((Y)=>Z.includes(Y)))return!1}if(W){let Q=KJ.resolve(W,J),Y=KJ.resolve(W);if(!Q.startsWith(Y+KJ.sep)&&Q!==Y)return!1}return!0},isValidVariableName(J){return/^[a-z_$]\w*$/i.test(J)},isValidDirectiveName(J){return/^[a-z][\w-]*$/i.test(J)},isSafeContent(J){return![/<script[^>]*>[\s\S]*?<\/script>/i,/javascript:/i,/data:text\/html/i,/vbscript:/i,/on\w+\s*=/i].some((Z)=>Z.test(J))}}});var hJ=E(()=>{r();PJ();fJ();mJ();JJ()});var dJ=E(()=>{hJ()});function m(J,W){try{let Z=J.trim();if(c(Z))return d(Z,Object.keys(W))(...Object.values(W));else return P(Z,W)}catch{return!1}}var lJ=E(()=>{qJ()});class $J{source;pos=0;line=1;column=0;tokens=[];constructor(J){this.source=J}tokenize(){this.tokens=[],this.pos=0,this.line=1,this.column=0;while(this.pos<this.source.length){let J=this.nextToken();if(J)this.tokens.push(J)}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 J=this.pos,W=this.line,Z=this.column,$=this.source[this.pos];if(/\s/.test($))return this.readWhitespace(J,W,Z);if($==="/"&&this.peek(1)==="/")return this.readLineComment(J,W,Z);if($==="/"&&this.peek(1)==="*")return this.readBlockComment(J,W,Z);if($==='"'||$==="'")return this.readString($,J,W,Z);if($==="`")return this.readTemplateString(J,W,Z);if(/\d/.test($)||$==="."&&/\d/.test(this.peek(1)||""))return this.readNumber(J,W,Z);if(/[a-z_$]/i.test($))return this.readIdentifier(J,W,Z);if($==="{"){if(this.peek(1)==="{"&&this.peek(2)==="{")return this.advance(3),{type:"RAW_START",value:"{{{",start:J,end:this.pos,line:W,column:Z};if(this.peek(1)==="{")return this.advance(2),{type:"EXPRESSION_START",value:"{{",start:J,end:this.pos,line:W,column:Z};if(this.peek(1)==="!"&&this.peek(2)==="!")return this.advance(3),{type:"RAW_START",value:"{!!",start:J,end:this.pos,line:W,column:Z}}if($==="}"){if(this.peek(1)==="}"&&this.peek(2)==="}")return this.advance(3),{type:"RAW_END",value:"}}}",start:J,end:this.pos,line:W,column:Z};if(this.peek(1)==="}")return this.advance(2),{type:"EXPRESSION_END",value:"}}",start:J,end:this.pos,line:W,column:Z}}if($==="!"&&this.peek(1)==="!"&&this.peek(2)==="}")return this.advance(3),{type:"RAW_END",value:"!!}",start:J,end:this.pos,line:W,column:Z};if($==="@"&&/[a-z]/i.test(this.peek(1)||""))return this.readDirective(J,W,Z);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:J,end:this.pos,line:W,column:Z};if(/[+\-*/%<>=!&|^~?:]/.test($))return this.advance(),{type:"OPERATOR",value:$,start:J,end:this.pos,line:W,column:Z};if(/[()[\]{},;.]/.test($))return this.advance(),{type:"PUNCTUATION",value:$,start:J,end:this.pos,line:W,column:Z};return this.advance(),{type:"PUNCTUATION",value:$,start:J,end:this.pos,line:W,column:Z}}readWhitespace(J,W,Z){while(this.pos<this.source.length&&/\s/.test(this.source[this.pos]))this.advance();return{type:"WHITESPACE",value:this.source.slice(J,this.pos),start:J,end:this.pos,line:W,column:Z}}readLineComment(J,W,Z){this.advance(2);while(this.pos<this.source.length&&this.source[this.pos]!==`
78
78
  `)this.advance();return{type:"COMMENT",value:this.source.slice(J,this.pos),start:J,end:this.pos,line:W,column:Z}}readBlockComment(J,W,Z){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(J,this.pos),start:J,end:this.pos,line:W,column:Z}}readString(J,W,Z,$){this.advance();while(this.pos<this.source.length){let Q=this.source[this.pos];if(Q==="\\"){this.advance(2);continue}if(Q===J){this.advance();break}this.advance()}return{type:"STRING",value:this.source.slice(W,this.pos),start:W,end:this.pos,line:Z,column:$}}readTemplateString(J,W,Z){this.advance();let $=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($>=Q){this.pos=this.source.length;break}this.advance(2),$++;continue}if(Y==="{"&&$>0){$++,this.advance();continue}if(Y==="}"&&$>0){$--,this.advance();continue}if(Y==="`"&&$===0){this.advance();break}this.advance()}return{type:"TEMPLATE_STRING",value:this.source.slice(J,this.pos),start:J,end:this.pos,line:W,column:Z}}readNumber(J,W,Z){if(this.source[this.pos]==="0"){let $=this.peek(1)?.toLowerCase();if($==="x"||$==="o"||$==="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(J,this.pos),start:J,end:this.pos,line:W,column:Z}}}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(J,this.pos),start:J,end:this.pos,line:W,column:Z}}readIdentifier(J,W,Z){while(this.pos<this.source.length&&/[\w$]/.test(this.source[this.pos]))this.advance();return{type:"IDENTIFIER",value:this.source.slice(J,this.pos),start:J,end:this.pos,line:W,column:Z}}readDirective(J,W,Z){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(J,this.pos),start:J,end:this.pos,line:W,column:Z}}advance(J=1){for(let W=0;W<J&&this.pos<this.source.length;W++){if(this.source[this.pos]===`
79
- `)this.line++,this.column=0;else this.column++;this.pos++}}peek(J){return this.source[this.pos+J]}saveState(){return{pos:this.pos,line:this.line,column:this.column}}restoreState(J){this.pos=J.pos,this.line=J.line,this.column=J.column}}function f(J,W,Z,$=0){let Q=0,Y=$,U=null,X=0,V=!1;while(Y<J.length){let q=J[Y];if(U&&V){V=!1,Y++;continue}if(U&&q==="\\"){V=!0,Y++;continue}if(V=!1,(q==='"'||q==="'"||q==="`")&&!U){U=q,Y++;continue}if(q===U&&U!=="`"){U=null,Y++;continue}if(U==="`"&&q==="$"&&J[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===W)Q++;else if(q===Z){if(Q--,Q===0)return Y}Y++}return-1}function uJ(J,W){let Z=W,$={paren:0,bracket:0,brace:0},Q=null,Y=0;while(Z<J.length){let U=J[Z];if((Z>0?J[Z-1]:"")==="\\"&&Q){Z++;continue}if((U==='"'||U==="'")&&!Q){Q=U,Z++;continue}if(U===Q&&Q!=="`"){Q=null,Z++;continue}if(U==="`"&&!Q){Q="`",Z++;continue}if(U==="`"&&Q==="`"&&Y===0){Q=null,Z++;continue}if(Q==="`"&&U==="$"&&J[Z+1]==="{"){Y++,Z+=2;continue}if(Y>0){if(U==="{")Y++;else if(U==="}")Y--;Z++;continue}if(Q){Z++;continue}if($.paren===0&&$.bracket===0&&$.brace===0){if(J.slice(Z,Z+2)==="}}"||J.slice(Z,Z+3)==="!!}")break;if(U===","||U===";")break}if(U==="(")$.paren++;else if(U===")"){if($.paren--,$.paren<0)break}else if(U==="[")$.bracket++;else if(U==="]"){if($.bracket--,$.bracket<0)break}else if(U==="{")$.brace++;else if(U==="}"){if($.brace--,$.brace<0)break}Z++}return{expression:J.slice(W,Z),endPos:Z}}function GJ(J){let W=[],Z="",$={paren:0,bracket:0,brace:0},Q=null,Y=0;for(let U=0;U<J.length;U++){let X=J[U];if((U>0?J[U-1]:"")==="\\"&&Q){Z+=X;continue}if((X==='"'||X==="'")&&!Q){Q=X,Z+=X;continue}if(X===Q&&Q!=="`"){Q=null,Z+=X;continue}if(X==="`"&&!Q){Q="`",Z+=X;continue}if(X==="`"&&Q==="`"&&Y===0){Q=null,Z+=X;continue}if(Q==="`"&&X==="$"&&J[U+1]==="{"){Y++,Z+=X+J[U+1],U++;continue}if(Y>0&&X==="{"){Y++,Z+=X;continue}if(Y>0&&X==="}"){Y--,Z+=X;continue}if(Q){Z+=X;continue}if(X==="(")$.paren++;else if(X===")")$.paren--;else if(X==="[")$.bracket++;else if(X==="]")$.bracket--;else if(X==="{")$.brace++;else if(X==="}")$.brace--;if(X==="|"&&J[U+1]!=="|"&&(U===0||J[U-1]!=="|")&&J[U-1]!=="\\"&&$.paren===0&&$.bracket===0&&$.brace===0){W.push(Z.trim()),Z="";continue}if(X==="|"&&J[U-1]==="\\"&&!Q){Z=Z.slice(0,-1)+X;continue}Z+=X}if(Z.trim())W.push(Z.trim());return W}function h(J,W){let Z=PZ(J,W);return Z.ok?{expression:Z.expression,endPos:Z.endPos}:null}function PZ(J,W){let Z=W;while(Z<J.length&&/\s/.test(J[Z]))Z++;if(J[Z]!=="(")return{ok:!1,reason:"missing-open-paren",pos:Z};let $=f(J,"(",")",Z);if($===-1)return{ok:!1,reason:"unclosed-paren",pos:Z};return{ok:!0,expression:J.slice(Z+1,$),endPos:$+1}}function u(J,W,Z,$){let Q=1,Y=$,U=new RegExp(`@${W}\\s*\\(`,"g"),X=new RegExp(`@${Z}(?![a-z])`,"g");while(Y<J.length&&Q>0){U.lastIndex=Y,X.lastIndex=Y;let V=U.exec(J),q=X.exec(J),H=V?V.index:1/0,F=q?q.index:1/0;if(H<F)Q++,Y=H+V[0].length;else if(F<1/0){if(Q--,Q===0)return F;Y=F+q[0].length}else break}return-1}function pJ(J,W){let Z=J.slice(W).match(/^@if\s*/);if(!Z)return null;let $=W+Z[0].length,Q=h(J,$);if(!Q)return null;let Y=Q.endPos,U=u(J,"if","endif",Y);if(U===-1)return null;let X=J.slice(Y,U),V=[],q=0,H="if",F=Q.expression,_=0,B=0;while(q<X.length){let K=X.indexOf("@",q);if(K===-1)break;q=K;let O=X.substring(K);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){V.push({type:H,condition:F,content:X.substring(_,q),start:Y+_,end:Y+q});let G=q+j[0].length,z=h(X,G);if(!z){q++;continue}H="elseif",F=z.expression,q=z.endPos,_=q;continue}else if(/^@else(?![a-z])/.test(O)){V.push({type:H,condition:F,content:X.substring(_,q),start:Y+_,end:Y+q}),H="else",F=void 0,q+=5,_=q;continue}}q++}return V.push({type:H,condition:F,content:X.slice(_),start:Y+_,end:Y+X.length}),{fullMatch:J.slice(W,U+6),branches:V,start:W,end:U+6}}function jJ(J){let W=[],Z=/@if\s*\(/g,$=Z.exec(J);while($!==null){if(W.some((U)=>$.index>U.start&&$.index<U.end)){$=Z.exec(J);continue}let Y=pJ(J,$.index);if(Y)W.push(Y),Z.lastIndex=Y.end;$=Z.exec(J)}return W}function fZ(J,W,Z){let $=[],Q=new RegExp(`@${W}\\s*\\(`,"g"),Y=Q.exec(J);while(Y!==null){if($.some((O)=>Y.index>O.start&&Y.index<O.end)){Y=Q.exec(J);continue}let X=Y.index,V=X+Y[0].length-1,q=f(J,"(",")",V);if(q===-1){Y=Q.exec(J);continue}let H=J.slice(V+1,q),F=q+1,_=u(J,W,Z,F);if(_===-1){Y=Q.exec(J);continue}let B=J.slice(F,_),K=_+`@${Z}`.length;$.push({fullMatch:J.slice(X,K),name:W,params:H,content:B,start:X,end:K}),Q.lastIndex=K,Y=Q.exec(J)}return $}function BJ(J,W){let Z=J.slice(W).match(/^@switch\s*/);if(!Z)return null;let $=W+Z[0].length,Q=h(J,$);if(!Q)return null;let Y=Q.endPos,U=u(J,"switch","endswitch",Y);if(U===-1)return null;let X=J.slice(Y,U),V=[],q=0,H=null,F=0;while(q<X.length){let _=X.slice(q),B=_.match(/^@switch\s*\(/),K=_.match(/^@endswitch(?![a-z])/);if(B){if(F++,H)H.content+=B[0];q+=B[0].length;continue}if(K){if(F--,H)H.content+=K[0];q+=K[0].length;continue}if(F>0){if(H)H.content+=X[q];q++;continue}let O=_.match(/^@case\s*/),j=_.match(/^@default(?![a-z])/),G=_.match(/^@break(?![a-z])/);if(O&&_.startsWith("@case")){if(H)V.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&&_.startsWith("@default")){if(H)V.push(H);H={type:"default",content:""},q+=j[0].length}else if(G&&_.startsWith("@break"))q+=G[0].length;else{if(H)H.content+=X[q];q++}}if(H)V.push(H);return{fullMatch:J.slice(W,U+10),expression:Q.expression,cases:V,start:W,end:U+10}}var cJ=()=>{};function xZ(J){let W=[],Z=0;while(Z<J.length){let $=J.indexOf("{{",Z),Q=J.indexOf("{!!",Z),Y=!1,U;if($===-1&&Q===-1)break;else if($===-1)U=Q,Y=!0;else if(Q===-1)U=$,Y=!1;else if(Q<$)U=Q,Y=!0;else U=$,Y=!1;if(!Y&&J.slice(U,U+3)==="{{{")Y=!0;let X=Y?J.slice(U,U+3)==="{{{"?"{{{":"{!!":"{{",V=Y?X==="{{{"?"}}}":"!!}":"}}",q=U+X.length,H=mZ(J,q,V);if(H===-1){Z=U+1;continue}let F=J.slice(q,H).trim(),_=H+V.length;W.push({fullMatch:J.slice(U,_),expression:F,start:U,end:_,isRaw:Y}),Z=_}return W}function mZ(J,W,Z){let $=W,Q=null,Y={paren:0,bracket:0,brace:0},U=0;while($<J.length){let X=J[$];if(($>0?J[$-1]:"")==="\\"&&Q){$++;continue}if((X==='"'||X==="'")&&!Q){Q=X,$++;continue}if(X===Q&&Q!=="`"){Q=null,$++;continue}if(X==="`"&&!Q){Q="`",$++;continue}if(X==="`"&&Q==="`"&&U===0){Q=null,$++;continue}if(Q==="`"&&X==="$"&&J[$+1]==="{"){U++,$+=2;continue}if(U>0){if(X==="{")U++;else if(X==="}")U--;$++;continue}if(Q){$++;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(J.slice($,$+Z.length)===Z)return $}$++}return-1}function hZ(J){let W=GJ(J);if(W.length===0)return{baseExpression:"",filters:[]};let Z=W[0],$=[];for(let Q=1;Q<W.length;Q++){let Y=dZ(W[Q]);if(Y)$.push(Y)}return{baseExpression:Z,filters:$}}function dZ(J){let W=J.trim();if(!W)return null;let Z=W.indexOf("(");if(Z===-1)return{name:W,args:[]};let $=W.slice(0,Z).trim(),Q=Z+1,Y=f(W,"(",")",Z);if(Y===-1)return{name:$,args:[]};let U=W.slice(Q,Y),X=aJ(U);return{name:$,args:X}}function aJ(J){let W=[],Z="",$={paren:0,bracket:0,brace:0},Q=null,Y=0;for(let U=0;U<J.length;U++){let X=J[U];if((U>0?J[U-1]:"")==="\\"&&Q){Z+=X;continue}if((X==='"'||X==="'")&&!Q){Q=X,Z+=X;continue}if(X===Q&&Q!=="`"){Q=null,Z+=X;continue}if(X==="`"&&!Q){Q="`",Z+=X;continue}if(X==="`"&&Q==="`"&&Y===0){Q=null,Z+=X;continue}if(Q==="`"&&X==="$"&&J[U+1]==="{"){Y++,Z+="${",U++;continue}if(Y>0&&X==="{"){Y++,Z+=X;continue}if(Y>0&&X==="}"){Y--,Z+=X;continue}if(Q){Z+=X;continue}if(X==="(")$.paren++;else if(X===")")$.paren--;else if(X==="[")$.bracket++;else if(X==="]")$.bracket--;else if(X==="{")$.brace++;else if(X==="}")$.brace--;if(X===","&&$.paren===0&&$.bracket===0&&$.brace===0){W.push(Z.trim()),Z="";continue}Z+=X}if(Z.trim())W.push(Z.trim());return W}function lZ(J,W){let Z=W;while(Z<J.length&&/\s/.test(J[Z]))Z++;if(J[Z]!=="(")return null;let $=f(J,"(",")",Z);if($===-1)return null;return{params:J.slice(Z+1,$),endPos:$+1}}function uZ(J){let W=[],$=new $J(J).tokenize().filter((Y)=>Y.type!=="WHITESPACE"&&Y.type!=="COMMENT"),Q=0;while(Q<$.length){let Y=$[Q],U=!1;if(Y.type==="IDENTIFIER"&&Y.value==="export"){if(U=!0,Q++,Q>=$.length)break}let X=$[Q];if(X.type==="IDENTIFIER"&&(X.value==="const"||X.value==="let"||X.value==="var")){let V=X.value;if(Q++,Q>=$.length)break;let q=$[Q];if(q.type==="IDENTIFIER"){let H=q.value;if(Q++,Q<$.length&&$[Q].type==="OPERATOR"&&$[Q].value==="="){Q++;let F=Q<$.length?$[Q].start:J.length,_=iJ($,Q,J);Q=_.nextIndex,W.push({type:"variable",name:H,value:J.slice(F,_.endPos),exported:U,start:X.start,end:_.endPos})}}else if(q.type==="PUNCTUATION"&&(q.value==="{"||q.value==="[")){let H=q.start,F=q.value==="{"?"}":"]",_=f(J,q.value,F,H);if(_!==-1){let B=J.slice(H,_+1);if(Q=oJ($,_+1),Q<$.length&&$[Q].type==="OPERATOR"&&$[Q].value==="="){Q++;let K=Q<$.length?$[Q].start:J.length,O=iJ($,Q,J);Q=O.nextIndex;let j=`__stx_destructured_${W.length}`;W.push({type:"variable",name:j,value:`${J.slice(K,O.endPos)}; ${V} ${B} = ${j}`,exported:U,start:X.start,end:O.endPos})}}}}else if(X.type==="IDENTIFIER"&&X.value==="function"){let V=U?$[Q-1].start:X.start;if(Q++,Q>=$.length)break;let q=$[Q];if(q.type==="IDENTIFIER"){let H=q.value;Q++;let F=-1;while(Q<$.length){if($[Q].type==="PUNCTUATION"&&$[Q].value==="{"){F=$[Q].start;break}Q++}if(F!==-1){let _=f(J,"{","}",F);if(_!==-1)W.push({type:"function",name:H,value:J.slice(V,_+1).replace(/^export\s+/,""),exported:U,start:V,end:_+1}),Q=oJ($,_+1)}}}else Q++}return W}function iJ(J,W,Z){let $=W,Q={paren:0,bracket:0,brace:0},Y=W<J.length?J[W].start:Z.length;while($<J.length){let U=J[$];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,$++;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=J[$-1]?.end??U.start;break}}Y=U.end,$++}return{nextIndex:$,endPos:Y}}function oJ(J,W){for(let Z=0;Z<J.length;Z++)if(J[Z].start>=W)return Z;return J.length}var sJ=()=>{};var nJ=E(()=>{cJ();sJ()});function pZ(J,W,Z){let $=J,Q=!0;while(Q){Q=!1;let Y=$.match(/@switch\s*\(/);if(!Y||Y.index===void 0)break;let U=Y.index,X=BJ($,U);if(!X)break;try{let V;if(c(X.expression))V=d(X.expression,Object.keys(W))(...Object.values(W));else V=P(X.expression,W);let q="",H=!1;for(let F of X.cases)if(F.type==="default"){if(!H)q=F.content.trim()}else try{let _;if(F.value&&c(F.value))_=d(F.value,Object.keys(W))(...Object.values(W));else if(F.value)_=P(F.value,W);if(V===_){q=F.content.trim(),H=!0;break}}catch{continue}$=$.substring(0,U)+q+$.substring(X.end),Q=!0}catch(V){let q=V instanceof Error?V.message:String(V),H=o("Switch",`Error evaluating @switch expression: ${q}`,k.EVALUATION_ERROR);$=$.substring(0,U)+H+$.substring(X.end);break}}return $}function o0(J,W,Z){let $=J;$=pZ($,W,Z);{let Y=!0;while(Y){Y=!1;let U=$.match(/@unless\s*\(/);if(!U||U.index===void 0)break;let X=U.index,V=h($,X+7);if(!V)break;let q=V.endPos,H=u($,"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 F=$.slice(q,H),_=V.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(F))!==null)w.push({pos:I.index,type:"open"});while((I=G.exec(F))!==null)w.push({pos:I.index,type:"close"});while((I=z.exec(F))!==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 K;if(B!==-1){let O=F.slice(0,B),j=F.slice(B+5);K=`@if (${_})${j}@else ${O}@endif`}else K=`@if (!(${_}))${F}@endif`;$=$.substring(0,X)+K+$.substring(H+10),Y=!0}}$=iZ($,W,Z),$=oZ($,W,Z),$=cZ($,W);let Q=()=>{let Y=jJ($);if(Y.length===0)return!1;for(let U=Y.length-1;U>=0;U--){let X=Y[U];try{let V="",q=!1;for(let H of X.branches){if(q)break;if(H.type==="else")V=H.content,q=!0;else try{let F;if(H.condition&&c(H.condition))F=d(H.condition,Object.keys(W))(...Object.values(W));else if(H.condition)F=P(H.condition,W);if(F)V=H.content,q=!0}catch(F){V=o(H.type==="if"?"If":"Elseif",`Error in @${H.type}(${H.condition}): ${F instanceof Error?F.message:String(F)}`,k.EVALUATION_ERROR),q=!0}}$=$.substring(0,X.start)+V+$.substring(X.end)}catch(V){let q=V instanceof Error?V.message:String(V),H=o("If",`Error processing @if block: ${q}`,k.EVALUATION_ERROR);$=$.substring(0,X.start)+H+$.substring(X.end)}}return!0};while(Q());return $}function rJ(J){let W=0;while(W<J.length&&/\s/.test(J[W]))W++;if(J[W]!=="(")return null;W++;while(W<J.length&&/\s/.test(J[W]))W++;let Z=J[W];if(Z!=="'"&&Z!=='"')return null;W++;let $=[];while(W<J.length){let Q=J[W];if(Q==="\\"&&W+1<J.length){$.push(J[W+1]),W+=2;continue}if(Q===Z){W++;break}$.push(Q),W++}while(W<J.length&&/\s/.test(J[W]))W++;if(J[W]!==")")return null;return W++,{value:$.join(""),consumed:W}}function cZ(J,W){let Z=J;function $(X,V,q,H){let F=1,_=H,B=new RegExp(`@${V}(?:\\s*\\(|\\s|$)`,"g"),K=new RegExp(`@${q}(?![a-z])`,"g");while(_<X.length&&F>0){B.lastIndex=_,K.lastIndex=_;let O=B.exec(X),j=K.exec(X),G=O?O.index:1/0,z=j?j.index:1/0;if(G<z)F++,_=G+O[0].length;else if(z<1/0){if(F--,F===0)return z;_=z+j[0].length}else break}return-1}function Q(X,V,q){let H=0,F=new RegExp(`@${V}(?:\\s*\\(|\\s|$)`,"g"),_=new RegExp(`@${q}(?![a-z])`,"g"),B=/@else(?![a-z])/g,K=[],O;while((O=F.exec(X))!==null)K.push({pos:O.index,type:"open"});while((O=_.exec(X))!==null)K.push({pos:O.index,type:"close"});while((O=B.exec(X))!==null)K.push({pos:O.index,type:"else"});K.sort((j,G)=>j.pos-G.pos);for(let j of K)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 V=Z.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!V||V.index===void 0)break;let q=V.index,H,F,_=Z.slice(q+5),B=rJ(_);if(B)H=B.value,F=q+5+B.consumed;else F=q+5;let K=$(Z,"auth","endauth",F);if(K===-1){console.warn(`[stx] @auth directive at position ${q} has no matching @endauth \u2014 the block was skipped.`);break}let O=Z.slice(F,K),j=Q(O,"auth","endauth"),G;if(!W.auth)G=!1;else G=H?m(`auth?.check && auth?.user?.[${H}]`,W):m("auth?.check",W);let z;if(j!==-1){let w=O.slice(0,j),I=O.slice(j+5);z=G?w:I}else z=G?O:"";Z=Z.substring(0,q)+z+Z.substring(K+8),X=!0}}{let X=!0;while(X){X=!1;let V=Z.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!V||V.index===void 0)break;let q=V.index,H,F,_=Z.slice(q+6),B=rJ(_);if(B)H=B.value,F=q+6+B.consumed;else F=q+6;let K=$(Z,"guest","endguest",F);if(K===-1){console.warn(`[stx] @guest directive at position ${q} has no matching @endguest \u2014 the block was skipped.`);break}let O=Z.slice(F,K),j=Q(O,"guest","endguest"),G;if(!W.auth)G=!0;else G=H?m(`!auth?.check || !auth?.user?.[${H}]`,W):m("!auth?.check",W);let z;if(j!==-1){let w=O.slice(0,j),I=O.slice(j+5);z=G?w:I}else z=G?O:"";Z=Z.substring(0,q)+z+Z.substring(K+9),X=!0}}function Y(X,V,q){if(W.userCan&&typeof W.userCan[X]==="boolean")return W.userCan[X];if(W.permissions?.check&&typeof W.permissions.check==="function")try{let H=[X];if(V)H.push(V);if(q){let F=m(q,W);H.push(F)}return W.permissions.check(...H)}catch{return!1}return!1}function U(X){let V=X.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!V)return null;return{ability:V[1],type:V[2],id:V[3]?.trim(),paramsEnd:V[0].length}}for(let X of["can","cannot"]){let V=`end${X}`,q=X==="can"?"elsecan":"elsecannot",H=!0;while(H){H=!1;let F=Z.match(new RegExp(`@${X}\\s*\\(`));if(!F||F.index===void 0)break;let _=F.index,B=Z.slice(_+`@${X}`.length),K=U(B);if(!K)break;let O=_+`@${X}`.length+K.paramsEnd,j=$(Z,X,V,O);if(j===-1){console.warn(`[stx] @${X} directive at position ${_} has no matching @${V} \u2014 the block was skipped.`);break}let G=Z.slice(O,j),z=[],w=0,I=new RegExp(`@${X}\\s*\\(`,"g"),R=new RegExp(`@${V}(?![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 WJ=z[M+1],zJ=WJ?WJ.pos:G.length;N.push({content:G.slice(S,zJ),ability:v.ability,type:v.type,id:v.id}),S=zJ}}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(K.ability,K.type,K.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}}Z=Z.substring(0,_)+x+Z.substring(j+`@${V}`.length),H=!0}}return Z}function iZ(J,W,Z){let $=J;function Q(Y,U,X,V,q){let H=!0;while(H){H=!1;let F=new RegExp(`@${U}\\s*\\(`),_=Y.match(F);if(!_||_.index===void 0)break;let B=_.index,K=h(Y,B+`@${U}`.length);if(!K)break;let O=K.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=K.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=V(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 $=Q($,"isset","endisset",(Y)=>{let U=m(Y,W);return U!==void 0&&U!==null},"Isset"),$=Q($,"empty","endempty",(Y)=>{let U=m(Y,W);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"),$}function oZ(J,W,Z){let $=J,Q="development";function Y(U,X,V,q){let H=new RegExp(`@${X}(?![a-z])`,"g"),F=new RegExp(`@${V}(?![a-z])`,"g"),_=new RegExp(`^@${X}(?![a-z])`),B=new RegExp(`^@${V}(?![a-z])`),K=U,O=!0;while(O){O=!1,H.lastIndex=0;let j=H.exec(K);if(!j)break;let G=j.index,z=G+j[0].length;if(X==="env"){let D=K.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<K.length){H.lastIndex=I,F.lastIndex=I;let D=H.exec(K),C=F.exec(K),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 @${V} \u2014 the block was skipped.`);break}let A=K.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(_.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=`@${V}`.length;K=K.substring(0,G)+N+K.substring(R+S),O=!0}return K}return $=Y($,"env","endenv",!1),$=Y($,"production","endproduction",Q==="production"),$=Y($,"development","enddevelopment",Q==="development"),$=Y($,"staging","endstaging",Q==="staging"),$=Y($,"testing","endtesting",Q==="testing"),$}var aZ=E(()=>{lJ();dJ();nJ();qJ()});aZ();export{pZ as processSwitchStatements,iZ as processIssetEmptyDirectives,oZ as processEnvDirective,o0 as processConditionals,cZ as processAuthDirectives};
79
+ `)this.line++,this.column=0;else this.column++;this.pos++}}peek(J){return this.source[this.pos+J]}saveState(){return{pos:this.pos,line:this.line,column:this.column}}restoreState(J){this.pos=J.pos,this.line=J.line,this.column=J.column}}function f(J,W,Z,$=0){let Q=0,Y=$,U=null,X=0,V=!1;while(Y<J.length){let q=J[Y];if(U&&V){V=!1,Y++;continue}if(U&&q==="\\"){V=!0,Y++;continue}if(V=!1,(q==='"'||q==="'"||q==="`")&&!U){U=q,Y++;continue}if(q===U&&U!=="`"){U=null,Y++;continue}if(U==="`"&&q==="$"&&J[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===W)Q++;else if(q===Z){if(Q--,Q===0)return Y}Y++}return-1}function uJ(J,W){let Z=W,$={paren:0,bracket:0,brace:0},Q=null,Y=0;while(Z<J.length){let U=J[Z];if((Z>0?J[Z-1]:"")==="\\"&&Q){Z++;continue}if((U==='"'||U==="'")&&!Q){Q=U,Z++;continue}if(U===Q&&Q!=="`"){Q=null,Z++;continue}if(U==="`"&&!Q){Q="`",Z++;continue}if(U==="`"&&Q==="`"&&Y===0){Q=null,Z++;continue}if(Q==="`"&&U==="$"&&J[Z+1]==="{"){Y++,Z+=2;continue}if(Y>0){if(U==="{")Y++;else if(U==="}")Y--;Z++;continue}if(Q){Z++;continue}if($.paren===0&&$.bracket===0&&$.brace===0){if(J.slice(Z,Z+2)==="}}"||J.slice(Z,Z+3)==="!!}")break;if(U===","||U===";")break}if(U==="(")$.paren++;else if(U===")"){if($.paren--,$.paren<0)break}else if(U==="[")$.bracket++;else if(U==="]"){if($.bracket--,$.bracket<0)break}else if(U==="{")$.brace++;else if(U==="}"){if($.brace--,$.brace<0)break}Z++}return{expression:J.slice(W,Z),endPos:Z}}function GJ(J){let W=[],Z="",$={paren:0,bracket:0,brace:0},Q=null,Y=0;for(let U=0;U<J.length;U++){let X=J[U];if((U>0?J[U-1]:"")==="\\"&&Q){Z+=X;continue}if((X==='"'||X==="'")&&!Q){Q=X,Z+=X;continue}if(X===Q&&Q!=="`"){Q=null,Z+=X;continue}if(X==="`"&&!Q){Q="`",Z+=X;continue}if(X==="`"&&Q==="`"&&Y===0){Q=null,Z+=X;continue}if(Q==="`"&&X==="$"&&J[U+1]==="{"){Y++,Z+=X+J[U+1],U++;continue}if(Y>0&&X==="{"){Y++,Z+=X;continue}if(Y>0&&X==="}"){Y--,Z+=X;continue}if(Q){Z+=X;continue}if(X==="(")$.paren++;else if(X===")")$.paren--;else if(X==="[")$.bracket++;else if(X==="]")$.bracket--;else if(X==="{")$.brace++;else if(X==="}")$.brace--;if(X==="|"&&J[U+1]!=="|"&&(U===0||J[U-1]!=="|")&&J[U-1]!=="\\"&&$.paren===0&&$.bracket===0&&$.brace===0){W.push(Z.trim()),Z="";continue}if(X==="|"&&J[U-1]==="\\"&&!Q){Z=Z.slice(0,-1)+X;continue}Z+=X}if(Z.trim())W.push(Z.trim());return W}function h(J,W){let Z=PZ(J,W);return Z.ok?{expression:Z.expression,endPos:Z.endPos}:null}function PZ(J,W){let Z=W;while(Z<J.length&&/\s/.test(J[Z]))Z++;if(J[Z]!=="(")return{ok:!1,reason:"missing-open-paren",pos:Z};let $=f(J,"(",")",Z);if($===-1)return{ok:!1,reason:"unclosed-paren",pos:Z};return{ok:!0,expression:J.slice(Z+1,$),endPos:$+1}}function u(J,W,Z,$){let Q=1,Y=$,U=new RegExp(`@${W}\\s*\\(`,"g"),X=new RegExp(`@${Z}(?![a-z])`,"g");while(Y<J.length&&Q>0){U.lastIndex=Y,X.lastIndex=Y;let V=U.exec(J),q=X.exec(J),H=V?V.index:1/0,F=q?q.index:1/0;if(H<F)Q++,Y=H+V[0].length;else if(F<1/0){if(Q--,Q===0)return F;Y=F+q[0].length}else break}return-1}function pJ(J,W){let Z=J.slice(W).match(/^@if\s*/);if(!Z)return null;let $=W+Z[0].length,Q=h(J,$);if(!Q)return null;let Y=Q.endPos,U=u(J,"if","endif",Y);if(U===-1)return null;let X=J.slice(Y,U),V=[],q=0,H="if",F=Q.expression,_=0,B=0;while(q<X.length){let K=X.indexOf("@",q);if(K===-1)break;q=K;let O=X.substring(K);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){V.push({type:H,condition:F,content:X.substring(_,q),start:Y+_,end:Y+q});let G=q+j[0].length,z=h(X,G);if(!z){q++;continue}H="elseif",F=z.expression,q=z.endPos,_=q;continue}else if(/^@else(?![a-z])/.test(O)){V.push({type:H,condition:F,content:X.substring(_,q),start:Y+_,end:Y+q}),H="else",F=void 0,q+=5,_=q;continue}}q++}return V.push({type:H,condition:F,content:X.slice(_),start:Y+_,end:Y+X.length}),{fullMatch:J.slice(W,U+6),branches:V,start:W,end:U+6}}function jJ(J){let W=[],Z=/@if\s*\(/g,$=Z.exec(J);while($!==null){if(W.some((U)=>$.index>U.start&&$.index<U.end)){$=Z.exec(J);continue}let Y=pJ(J,$.index);if(Y)W.push(Y),Z.lastIndex=Y.end;$=Z.exec(J)}return W}function fZ(J,W,Z){let $=[],Q=new RegExp(`@${W}\\s*\\(`,"g"),Y=Q.exec(J);while(Y!==null){if($.some((O)=>Y.index>O.start&&Y.index<O.end)){Y=Q.exec(J);continue}let X=Y.index,V=X+Y[0].length-1,q=f(J,"(",")",V);if(q===-1){Y=Q.exec(J);continue}let H=J.slice(V+1,q),F=q+1,_=u(J,W,Z,F);if(_===-1){Y=Q.exec(J);continue}let B=J.slice(F,_),K=_+`@${Z}`.length;$.push({fullMatch:J.slice(X,K),name:W,params:H,content:B,start:X,end:K}),Q.lastIndex=K,Y=Q.exec(J)}return $}function BJ(J,W){let Z=J.slice(W).match(/^@switch\s*/);if(!Z)return null;let $=W+Z[0].length,Q=h(J,$);if(!Q)return null;let Y=Q.endPos,U=u(J,"switch","endswitch",Y);if(U===-1)return null;let X=J.slice(Y,U),V=[],q=0,H=null,F=0;while(q<X.length){let _=X.slice(q),B=_.match(/^@switch\s*\(/),K=_.match(/^@endswitch(?![a-z])/);if(B){if(F++,H)H.content+=B[0];q+=B[0].length;continue}if(K){if(F--,H)H.content+=K[0];q+=K[0].length;continue}if(F>0){if(H)H.content+=X[q];q++;continue}let O=_.match(/^@case\s*/),j=_.match(/^@default(?![a-z])/),G=_.match(/^@break(?![a-z])/);if(O&&_.startsWith("@case")){if(H)V.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&&_.startsWith("@default")){if(H)V.push(H);H={type:"default",content:""},q+=j[0].length}else if(G&&_.startsWith("@break"))q+=G[0].length;else{if(H)H.content+=X[q];q++}}if(H)V.push(H);return{fullMatch:J.slice(W,U+10),expression:Q.expression,cases:V,start:W,end:U+10}}var cJ=()=>{};function xZ(J){let W=[],Z=0;while(Z<J.length){let $=J.indexOf("{{",Z),Q=J.indexOf("{!!",Z),Y=!1,U;if($===-1&&Q===-1)break;else if($===-1)U=Q,Y=!0;else if(Q===-1)U=$,Y=!1;else if(Q<$)U=Q,Y=!0;else U=$,Y=!1;if(!Y&&J.slice(U,U+3)==="{{{")Y=!0;let X=Y?J.slice(U,U+3)==="{{{"?"{{{":"{!!":"{{",V=Y?X==="{{{"?"}}}":"!!}":"}}",q=U+X.length,H=mZ(J,q,V);if(H===-1){Z=U+1;continue}let F=J.slice(q,H).trim(),_=H+V.length;W.push({fullMatch:J.slice(U,_),expression:F,start:U,end:_,isRaw:Y}),Z=_}return W}function mZ(J,W,Z){let $=W,Q=null,Y={paren:0,bracket:0,brace:0},U=0;while($<J.length){let X=J[$];if(($>0?J[$-1]:"")==="\\"&&Q){$++;continue}if((X==='"'||X==="'")&&!Q){Q=X,$++;continue}if(X===Q&&Q!=="`"){Q=null,$++;continue}if(X==="`"&&!Q){Q="`",$++;continue}if(X==="`"&&Q==="`"&&U===0){Q=null,$++;continue}if(Q==="`"&&X==="$"&&J[$+1]==="{"){U++,$+=2;continue}if(U>0){if(X==="{")U++;else if(X==="}")U--;$++;continue}if(Q){$++;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(J.slice($,$+Z.length)===Z)return $}$++}return-1}function hZ(J){let W=GJ(J);if(W.length===0)return{baseExpression:"",filters:[]};let Z=W[0],$=[];for(let Q=1;Q<W.length;Q++){let Y=dZ(W[Q]);if(Y)$.push(Y)}return{baseExpression:Z,filters:$}}function dZ(J){let W=J.trim();if(!W)return null;let Z=W.indexOf("(");if(Z===-1)return{name:W,args:[]};let $=W.slice(0,Z).trim(),Q=Z+1,Y=f(W,"(",")",Z);if(Y===-1)return{name:$,args:[]};let U=W.slice(Q,Y),X=aJ(U);return{name:$,args:X}}function aJ(J){let W=[],Z="",$={paren:0,bracket:0,brace:0},Q=null,Y=0;for(let U=0;U<J.length;U++){let X=J[U];if((U>0?J[U-1]:"")==="\\"&&Q){Z+=X;continue}if((X==='"'||X==="'")&&!Q){Q=X,Z+=X;continue}if(X===Q&&Q!=="`"){Q=null,Z+=X;continue}if(X==="`"&&!Q){Q="`",Z+=X;continue}if(X==="`"&&Q==="`"&&Y===0){Q=null,Z+=X;continue}if(Q==="`"&&X==="$"&&J[U+1]==="{"){Y++,Z+="${",U++;continue}if(Y>0&&X==="{"){Y++,Z+=X;continue}if(Y>0&&X==="}"){Y--,Z+=X;continue}if(Q){Z+=X;continue}if(X==="(")$.paren++;else if(X===")")$.paren--;else if(X==="[")$.bracket++;else if(X==="]")$.bracket--;else if(X==="{")$.brace++;else if(X==="}")$.brace--;if(X===","&&$.paren===0&&$.bracket===0&&$.brace===0){W.push(Z.trim()),Z="";continue}Z+=X}if(Z.trim())W.push(Z.trim());return W}function lZ(J,W){let Z=W;while(Z<J.length&&/\s/.test(J[Z]))Z++;if(J[Z]!=="(")return null;let $=f(J,"(",")",Z);if($===-1)return null;return{params:J.slice(Z+1,$),endPos:$+1}}function uZ(J){let W=[],$=new $J(J).tokenize().filter((Y)=>Y.type!=="WHITESPACE"&&Y.type!=="COMMENT"),Q=0;while(Q<$.length){let Y=$[Q],U=!1;if(Y.type==="IDENTIFIER"&&Y.value==="export"){if(U=!0,Q++,Q>=$.length)break}let X=$[Q];if(X.type==="IDENTIFIER"&&(X.value==="const"||X.value==="let"||X.value==="var")){let V=X.value;if(Q++,Q>=$.length)break;let q=$[Q];if(q.type==="IDENTIFIER"){let H=q.value;if(Q++,Q<$.length&&$[Q].type==="OPERATOR"&&$[Q].value==="="){Q++;let F=Q<$.length?$[Q].start:J.length,_=iJ($,Q,J);Q=_.nextIndex,W.push({type:"variable",name:H,value:J.slice(F,_.endPos),exported:U,start:X.start,end:_.endPos})}}else if(q.type==="PUNCTUATION"&&(q.value==="{"||q.value==="[")){let H=q.start,F=q.value==="{"?"}":"]",_=f(J,q.value,F,H);if(_!==-1){let B=J.slice(H,_+1);if(Q=oJ($,_+1),Q<$.length&&$[Q].type==="OPERATOR"&&$[Q].value==="="){Q++;let K=Q<$.length?$[Q].start:J.length,O=iJ($,Q,J);Q=O.nextIndex;let j=`__stx_destructured_${W.length}`;W.push({type:"variable",name:j,value:`${J.slice(K,O.endPos)}; ${V} ${B} = ${j}`,exported:U,start:X.start,end:O.endPos})}}}}else if(X.type==="IDENTIFIER"&&X.value==="function"){let V=U?$[Q-1].start:X.start;if(Q++,Q>=$.length)break;let q=$[Q];if(q.type==="IDENTIFIER"){let H=q.value;Q++;let F=-1;while(Q<$.length){if($[Q].type==="PUNCTUATION"&&$[Q].value==="{"){F=$[Q].start;break}Q++}if(F!==-1){let _=f(J,"{","}",F);if(_!==-1)W.push({type:"function",name:H,value:J.slice(V,_+1).replace(/^export\s+/,""),exported:U,start:V,end:_+1}),Q=oJ($,_+1)}}}else Q++}return W}function iJ(J,W,Z){let $=W,Q={paren:0,bracket:0,brace:0},Y=W<J.length?J[W].start:Z.length;while($<J.length){let U=J[$];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,$++;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=J[$-1]?.end??U.start;break}}Y=U.end,$++}return{nextIndex:$,endPos:Y}}function oJ(J,W){for(let Z=0;Z<J.length;Z++)if(J[Z].start>=W)return Z;return J.length}var sJ=()=>{};var nJ=E(()=>{cJ();sJ()});function pZ(J,W,Z){let $=J,Q=!0;while(Q){Q=!1;let Y=$.match(/@switch\s*\(/);if(!Y||Y.index===void 0)break;let U=Y.index,X=BJ($,U);if(!X)break;try{let V;if(c(X.expression))V=d(X.expression,Object.keys(W))(...Object.values(W));else V=P(X.expression,W);let q="",H=!1;for(let F of X.cases)if(F.type==="default"){if(!H)q=F.content.trim()}else try{let _;if(F.value&&c(F.value))_=d(F.value,Object.keys(W))(...Object.values(W));else if(F.value)_=P(F.value,W);if(V===_){q=F.content.trim(),H=!0;break}}catch{continue}$=$.substring(0,U)+q+$.substring(X.end),Q=!0}catch(V){let q=V instanceof Error?V.message:String(V),H=o("Switch",`Error evaluating @switch expression: ${q}`,k.EVALUATION_ERROR);$=$.substring(0,U)+H+$.substring(X.end);break}}return $}function o0(J,W,Z){let $=J;$=pZ($,W,Z);{let Y=!0;while(Y){Y=!1;let U=$.match(/@unless\s*\(/);if(!U||U.index===void 0)break;let X=U.index,V=h($,X+7);if(!V)break;let q=V.endPos,H=u($,"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 F=$.slice(q,H),_=V.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(F))!==null)w.push({pos:I.index,type:"open"});while((I=G.exec(F))!==null)w.push({pos:I.index,type:"close"});while((I=z.exec(F))!==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 K;if(B!==-1){let O=F.slice(0,B),j=F.slice(B+5);K=`@if (${_})${j}@else ${O}@endif`}else K=`@if (!(${_}))${F}@endif`;$=$.substring(0,X)+K+$.substring(H+10),Y=!0}}$=iZ($,W,Z),$=oZ($,W,Z),$=cZ($,W);let Q=()=>{let Y=jJ($);if(Y.length===0)return!1;for(let U=Y.length-1;U>=0;U--){let X=Y[U];try{let V="",q=!1;for(let H of X.branches){if(q)break;if(H.type==="else")V=H.content,q=!0;else try{let F;if(H.condition&&c(H.condition))F=d(H.condition,Object.keys(W))(...Object.values(W));else if(H.condition)F=P(H.condition,W);if(F)V=H.content,q=!0}catch(F){V=o(H.type==="if"?"If":"Elseif",`Error in @${H.type}(${H.condition}): ${F instanceof Error?F.message:String(F)}`,k.EVALUATION_ERROR),q=!0}}$=$.substring(0,X.start)+V+$.substring(X.end)}catch(V){let q=V instanceof Error?V.message:String(V),H=o("If",`Error processing @if block: ${q}`,k.EVALUATION_ERROR);$=$.substring(0,X.start)+H+$.substring(X.end)}}return!0};while(!0){let Y=$;if(!Q())break;if($===Y)break}return $}function rJ(J){let W=0;while(W<J.length&&/\s/.test(J[W]))W++;if(J[W]!=="(")return null;W++;while(W<J.length&&/\s/.test(J[W]))W++;let Z=J[W];if(Z!=="'"&&Z!=='"')return null;W++;let $=[];while(W<J.length){let Q=J[W];if(Q==="\\"&&W+1<J.length){$.push(J[W+1]),W+=2;continue}if(Q===Z){W++;break}$.push(Q),W++}while(W<J.length&&/\s/.test(J[W]))W++;if(J[W]!==")")return null;return W++,{value:$.join(""),consumed:W}}function cZ(J,W){let Z=J;function $(X,V,q,H){let F=1,_=H,B=new RegExp(`@${V}(?:\\s*\\(|\\s|$)`,"g"),K=new RegExp(`@${q}(?![a-z])`,"g");while(_<X.length&&F>0){B.lastIndex=_,K.lastIndex=_;let O=B.exec(X),j=K.exec(X),G=O?O.index:1/0,z=j?j.index:1/0;if(G<z)F++,_=G+O[0].length;else if(z<1/0){if(F--,F===0)return z;_=z+j[0].length}else break}return-1}function Q(X,V,q){let H=0,F=new RegExp(`@${V}(?:\\s*\\(|\\s|$)`,"g"),_=new RegExp(`@${q}(?![a-z])`,"g"),B=/@else(?![a-z])/g,K=[],O;while((O=F.exec(X))!==null)K.push({pos:O.index,type:"open"});while((O=_.exec(X))!==null)K.push({pos:O.index,type:"close"});while((O=B.exec(X))!==null)K.push({pos:O.index,type:"else"});K.sort((j,G)=>j.pos-G.pos);for(let j of K)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 V=Z.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!V||V.index===void 0)break;let q=V.index,H,F,_=Z.slice(q+5),B=rJ(_);if(B)H=B.value,F=q+5+B.consumed;else F=q+5;let K=$(Z,"auth","endauth",F);if(K===-1){console.warn(`[stx] @auth directive at position ${q} has no matching @endauth \u2014 the block was skipped.`);break}let O=Z.slice(F,K),j=Q(O,"auth","endauth"),G;if(!W.auth)G=!1;else G=H?m(`auth?.check && auth?.user?.[${H}]`,W):m("auth?.check",W);let z;if(j!==-1){let w=O.slice(0,j),I=O.slice(j+5);z=G?w:I}else z=G?O:"";Z=Z.substring(0,q)+z+Z.substring(K+8),X=!0}}{let X=!0;while(X){X=!1;let V=Z.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!V||V.index===void 0)break;let q=V.index,H,F,_=Z.slice(q+6),B=rJ(_);if(B)H=B.value,F=q+6+B.consumed;else F=q+6;let K=$(Z,"guest","endguest",F);if(K===-1){console.warn(`[stx] @guest directive at position ${q} has no matching @endguest \u2014 the block was skipped.`);break}let O=Z.slice(F,K),j=Q(O,"guest","endguest"),G;if(!W.auth)G=!0;else G=H?m(`!auth?.check || !auth?.user?.[${H}]`,W):m("!auth?.check",W);let z;if(j!==-1){let w=O.slice(0,j),I=O.slice(j+5);z=G?w:I}else z=G?O:"";Z=Z.substring(0,q)+z+Z.substring(K+9),X=!0}}function Y(X,V,q){if(W.userCan&&typeof W.userCan[X]==="boolean")return W.userCan[X];if(W.permissions?.check&&typeof W.permissions.check==="function")try{let H=[X];if(V)H.push(V);if(q){let F=m(q,W);H.push(F)}return W.permissions.check(...H)}catch{return!1}return!1}function U(X){let V=X.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!V)return null;return{ability:V[1],type:V[2],id:V[3]?.trim(),paramsEnd:V[0].length}}for(let X of["can","cannot"]){let V=`end${X}`,q=X==="can"?"elsecan":"elsecannot",H=!0;while(H){H=!1;let F=Z.match(new RegExp(`@${X}\\s*\\(`));if(!F||F.index===void 0)break;let _=F.index,B=Z.slice(_+`@${X}`.length),K=U(B);if(!K)break;let O=_+`@${X}`.length+K.paramsEnd,j=$(Z,X,V,O);if(j===-1){console.warn(`[stx] @${X} directive at position ${_} has no matching @${V} \u2014 the block was skipped.`);break}let G=Z.slice(O,j),z=[],w=0,I=new RegExp(`@${X}\\s*\\(`,"g"),R=new RegExp(`@${V}(?![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 WJ=z[M+1],zJ=WJ?WJ.pos:G.length;N.push({content:G.slice(S,zJ),ability:v.ability,type:v.type,id:v.id}),S=zJ}}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(K.ability,K.type,K.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}}Z=Z.substring(0,_)+x+Z.substring(j+`@${V}`.length),H=!0}}return Z}function iZ(J,W,Z){let $=J;function Q(Y,U,X,V,q){let H=!0;while(H){H=!1;let F=new RegExp(`@${U}\\s*\\(`),_=Y.match(F);if(!_||_.index===void 0)break;let B=_.index,K=h(Y,B+`@${U}`.length);if(!K)break;let O=K.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=K.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=V(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 $=Q($,"isset","endisset",(Y)=>{let U=m(Y,W);return U!==void 0&&U!==null},"Isset"),$=Q($,"empty","endempty",(Y)=>{let U=m(Y,W);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"),$}function oZ(J,W,Z){let $=J,Q="development";function Y(U,X,V,q){let H=new RegExp(`@${X}(?![a-z])`,"g"),F=new RegExp(`@${V}(?![a-z])`,"g"),_=new RegExp(`^@${X}(?![a-z])`),B=new RegExp(`^@${V}(?![a-z])`),K=U,O=!0;while(O){O=!1,H.lastIndex=0;let j=H.exec(K);if(!j)break;let G=j.index,z=G+j[0].length;if(X==="env"){let D=K.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<K.length){H.lastIndex=I,F.lastIndex=I;let D=H.exec(K),C=F.exec(K),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 @${V} \u2014 the block was skipped.`);break}let A=K.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(_.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=`@${V}`.length;K=K.substring(0,G)+N+K.substring(R+S),O=!0}return K}return $=Y($,"env","endenv",!1),$=Y($,"production","endproduction",Q==="production"),$=Y($,"development","enddevelopment",Q==="development"),$=Y($,"staging","endstaging",Q==="staging"),$=Y($,"testing","endtesting",Q==="testing"),$}var aZ=E(()=>{lJ();dJ();nJ();qJ()});aZ();export{pZ as processSwitchStatements,iZ as processIssetEmptyDirectives,oZ as processEnvDirective,o0 as processConditionals,cZ as processAuthDirectives};