@stacksjs/stx 0.2.77 → 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.
- package/dist/app-shell.js +1 -1
- package/dist/build-mode-detector.js +1 -1
- package/dist/build-views.js +1 -1
- package/dist/build.js +1 -1
- package/dist/cli.js +2 -2
- package/dist/component-processing.js +1 -1
- package/dist/component-renderer.js +1 -1
- package/dist/components.js +1 -1
- package/dist/conditionals.js +1 -1
- package/dist/dev-server/index.js +1 -1
- package/dist/dev-server/serve-app.js +1 -1
- package/dist/dev-server/serve-file.js +1 -1
- package/dist/dev-server/serve-markdown.js +1 -1
- package/dist/dev-server/serve-multi.js +1 -1
- package/dist/dev-server.js +1 -1
- package/dist/docs.js +1 -1
- package/dist/dynamic-components.js +1 -1
- package/dist/includes.js +1 -1
- package/dist/index.js +1 -1
- package/dist/interactive.js +1 -1
- package/dist/lazy-loader.js +1 -1
- package/dist/loops.js +1 -1
- package/dist/plugin.js +1 -1
- package/dist/process.js +1 -1
- package/dist/production-builder.js +1 -1
- package/dist/production-server.js +1 -1
- package/dist/pwa/index.js +1 -1
- package/dist/pwa/offline.js +1 -1
- package/dist/pwa.js +1 -1
- package/dist/render.js +1 -1
- package/dist/serve.js +1 -1
- package/dist/site-builder/build.js +1 -1
- package/dist/site-builder/index.js +1 -1
- package/dist/ssg.js +1 -1
- package/dist/ssr.js +1 -1
- package/dist/story/cli.js +1 -1
- package/dist/story/commands/dev.js +1 -1
- package/dist/story/commands/index.js +1 -1
- package/dist/story/index.js +1 -1
- package/dist/story/renderer.js +1 -1
- package/dist/story/server.js +1 -1
- package/dist/story/visual-testing.js +1 -1
- package/dist/streaming.js +1 -1
- package/dist/template-compiler.js +1 -1
- package/dist/template-hydrator.js +1 -1
- package/dist/testing.js +1 -1
- package/dist/utils.js +1 -1
- package/dist/web-components.js +1 -1
- package/package.json +5 -5
package/dist/loops.js
CHANGED
|
@@ -34,7 +34,7 @@ ${"\x1B[31m"}\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\
|
|
|
34
34
|
`)}writeToFile($){this.writeQueue=this.writeQueue.then(async()=>{try{let Z=await import("fs"),J=(await import("path")).dirname(this.logFilePath);if(!Z.existsSync(J))Z.mkdirSync(J,{recursive:!0});await this.rotateIfNeeded(Z);let X=`${this.formatEntry($)}
|
|
35
35
|
`;Z.appendFileSync(this.logFilePath,X,"utf-8")}catch(Z){if(process.env.STX_DEBUG==="true")console.error("Failed to write to error log:",Z)}})}async rotateIfNeeded($){try{if(!$.existsSync(this.logFilePath))return;if($.statSync(this.logFilePath).size<this.maxFileSize)return;for(let Y=this.maxLogFiles-1;Y>=1;Y--){let J=`${this.logFilePath}.${Y}`,X=`${this.logFilePath}.${Y+1}`;if($.existsSync(J))if(Y>=this.maxLogFiles-1)$.unlinkSync(J);else $.renameSync(J,X)}if(this.maxLogFiles<=1)$.writeFileSync(this.logFilePath,"");else $.renameSync(this.logFilePath,`${this.logFilePath}.1`)}catch(Z){if(process.env.STX_DEBUG==="true")console.error("Failed to rotate error logs:",Z)}}getRecentErrors($=10){return this.errors.slice(-$)}getErrorsByType($){return this.errors.filter((Z)=>Z.error.constructor.name===$)}getErrorsByLevel($){return this.errors.filter((Z)=>Z.level===$)}clear(){this.errors.length=0}async clearLogFile(){try{let $=await import("fs");if($.existsSync(this.logFilePath))$.writeFileSync(this.logFilePath,"","utf-8")}catch($){if(process.env.STX_DEBUG==="true")console.error("Failed to clear error log:",$)}}getStats(){let $={},Z={error:0,warning:0,info:0};for(let Y of this.errors){let J=Y.error.constructor.name;$[J]=($[J]||0)+1;let X=Y.level||"error";Z[X]=(Z[X]||0)+1}return{total:this.errors.length,byType:$,byLevel:Z}}async exportToFile($,Z="json"){let Y=await import("fs"),X=(await import("path")).dirname($);if(!Y.existsSync(X))Y.mkdirSync(X,{recursive:!0});if(Z==="json"){let G=this.errors.map((Q)=>({timestamp:Q.timestamp.toISOString(),level:Q.level||"error",type:Q.error.constructor.name,message:Q.error.message,stack:Q.error.stack,context:Q.context}));Y.writeFileSync($,JSON.stringify(G,null,2),"utf-8")}else{let G=this.errors.map((Q)=>this.formatEntry(Q));Y.writeFileSync($,G.join(`
|
|
36
36
|
|
|
37
|
-
`),"utf-8")}}async flush(){await this.writeQueue}}var V1;var m5=w(()=>{E0();V1=new O1});var u5=()=>{};var l5=w(()=>{D0();d5();m5();u5();E0()});var $0=w(()=>{l5()});function Z0($,Z,Y,J=0){let X=0,G=J,Q=null,K=0,U=!1;while(G<$.length){let q=$[G];if(Q&&U){U=!1,G++;continue}if(Q&&q==="\\"){U=!0,G++;continue}if(U=!1,(q==='"'||q==="'"||q==="`")&&!Q){Q=q,G++;continue}if(q===Q&&Q!=="`"){Q=null,G++;continue}if(Q==="`"&&q==="$"&&$[G+1]==="{"){K++,G+=2;continue}if(K>0&&q==="}"){K--,G++;continue}if(q==="`"&&Q==="`"&&K===0){Q=null,G++;continue}if(Q){G++;continue}if(q===Z)X++;else if(q===Y){if(X--,X===0)return G}G++}return-1}function K0($,Z){let Y=i3($,Z);return Y.ok?{expression:Y.expression,endPos:Y.endPos}:null}function i3($,Z){let Y=Z;while(Y<$.length&&/\s/.test($[Y]))Y++;if($[Y]!=="(")return{ok:!1,reason:"missing-open-paren",pos:Y};let J=Z0($,"(",")",Y);if(J===-1)return{ok:!1,reason:"unclosed-paren",pos:Y};return{ok:!0,expression:$.slice(Y+1,J),endPos:J+1}}function q0($,Z,Y,J){let X=1,G=J,Q=new RegExp(`@${Z}\\s*\\(`,"g"),K=new RegExp(`@${Y}(?![a-z])`,"g");while(G<$.length&&X>0){Q.lastIndex=G,K.lastIndex=G;let U=Q.exec($),q=K.exec($),z=U?U.index:1/0,W=q?q.index:1/0;if(z<W)X++,G=z+U[0].length;else if(W<1/0){if(X--,X===0)return W;G=W+q[0].length}else break}return-1}function c5($,Z){let Y=$.slice(Z).match(/^@if\s*/);if(!Y)return null;let J=Z+Y[0].length,X=K0($,J);if(!X)return null;let G=X.endPos,Q=q0($,"if","endif",G);if(Q===-1)return null;let K=$.slice(G,Q),U=[],q=0,z="if",W=X.expression,_=0,H=0;while(q<K.length){let B=K.indexOf("@",q);if(B===-1)break;q=B;let j=K.substring(B);if(/^@if\s*\(/.test(j)){H++,q++;continue}if(/^@endif(?![a-z])/.test(j)){H--,q+=6;continue}if(H===0){let O=j.match(/^@elseif\s*/);if(O){U.push({type:z,condition:W,content:K.substring(_,q),start:G+_,end:G+q});let V=q+O[0].length,L=K0(K,V);if(!L){q++;continue}z="elseif",W=L.expression,q=L.endPos,_=q;continue}else if(/^@else(?![a-z])/.test(j)){U.push({type:z,condition:W,content:K.substring(_,q),start:G+_,end:G+q}),z="else",W=void 0,q+=5,_=q;continue}}q++}return U.push({type:z,condition:W,content:K.slice(_),start:G+_,end:G+K.length}),{fullMatch:$.slice(Z,Q+6),branches:U,start:Z,end:Q+6}}function k0($){let Z=[],Y=/@if\s*\(/g,J=Y.exec($);while(J!==null){if(Z.some((Q)=>J.index>Q.start&&J.index<Q.end)){J=Y.exec($);continue}let G=c5($,J.index);if(G)Z.push(G),Y.lastIndex=G.end;J=Y.exec($)}return Z}function b0($,Z,Y){let J=[],X=new RegExp(`@${Z}\\s*\\(`,"g"),G=X.exec($);while(G!==null){if(J.some((j)=>G.index>j.start&&G.index<j.end)){G=X.exec($);continue}let K=G.index,U=K+G[0].length-1,q=Z0($,"(",")",U);if(q===-1){G=X.exec($);continue}let z=$.slice(U+1,q),W=q+1,_=q0($,Z,Y,W);if(_===-1){G=X.exec($);continue}let H=$.slice(W,_),B=_+`@${Y}`.length;J.push({fullMatch:$.slice(K,B),name:Z,params:z,content:H,start:K,end:B}),X.lastIndex=B,G=X.exec($)}return J}function L1($,Z){let Y=$.slice(Z).match(/^@switch\s*/);if(!Y)return null;let J=Z+Y[0].length,X=K0($,J);if(!X)return null;let G=X.endPos,Q=q0($,"switch","endswitch",G);if(Q===-1)return null;let K=$.slice(G,Q),U=[],q=0,z=null,W=0;while(q<K.length){let _=K.slice(q),H=_.match(/^@switch\s*\(/),B=_.match(/^@endswitch(?![a-z])/);if(H){if(W++,z)z.content+=H[0];q+=H[0].length;continue}if(B){if(W--,z)z.content+=B[0];q+=B[0].length;continue}if(W>0){if(z)z.content+=K[q];q++;continue}let j=_.match(/^@case\s*/),O=_.match(/^@default(?![a-z])/),V=_.match(/^@break(?![a-z])/);if(j&&_.startsWith("@case")){if(z)U.push(z);let L=q+j[0].length,F=K0(K,L);if(!F){q++;continue}z={type:"case",value:F.expression,content:""},q=F.endPos}else if(O&&_.startsWith("@default")){if(z)U.push(z);z={type:"default",content:""},q+=O[0].length}else if(V&&_.startsWith("@break"))q+=V[0].length;else{if(z)z.content+=K[q];q++}}if(z)U.push(z);return{fullMatch:$.slice(Z,Q+10),expression:X.expression,cases:U,start:Z,end:Q+10}}var p5=()=>{};var i5=()=>{};var S0=w(()=>{p5();i5()});function r3($,Z,Y){let J=$,X=!0;while(X){X=!1;let G=J.match(/@switch\s*\(/);if(!G||G.index===void 0)break;let Q=G.index,K=L1(J,Q);if(!K)break;try{let U;if(u(K.expression))U=h(K.expression,Object.keys(Z))(...Object.values(Z));else U=g(K.expression,Z);let q="",z=!1;for(let W of K.cases)if(W.type==="default"){if(!z)q=W.content.trim()}else try{let _;if(W.value&&u(W.value))_=h(W.value,Object.keys(Z))(...Object.values(Z));else if(W.value)_=g(W.value,Z);if(U===_){q=W.content.trim(),z=!0;break}}catch{continue}J=J.substring(0,Q)+q+J.substring(K.end),X=!0}catch(U){let q=U instanceof Error?U.message:String(U),z=f("Switch",`Error evaluating @switch expression: ${q}`,x.EVALUATION_ERROR);J=J.substring(0,Q)+z+J.substring(K.end);break}}return J}function F0($,Z,Y){let J=$;J=r3(J,Z,Y);{let G=!0;while(G){G=!1;let Q=J.match(/@unless\s*\(/);if(!Q||Q.index===void 0)break;let K=Q.index,U=K0(J,K+7);if(!U)break;let q=U.endPos,z=q0(J,"unless","endunless",q);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 W=J.slice(q,z),_=U.expression,H=-1;{let j=0,O=/@(?:if|unless)\s*\(/g,V=/@(?:endif|endunless)(?![a-z])/g,L=/@else(?![a-z])/g,F=[],N;while((N=O.exec(W))!==null)F.push({pos:N.index,type:"open"});while((N=V.exec(W))!==null)F.push({pos:N.index,type:"close"});while((N=L.exec(W))!==null)F.push({pos:N.index,type:"else"});F.sort((A,R)=>A.pos-R.pos);for(let A of F)if(A.type==="open")j++;else if(A.type==="close")j--;else if(A.type==="else"&&j===0){H=A.pos;break}}let B;if(H!==-1){let j=W.slice(0,H),O=W.slice(H+5);B=`@if (${_})${O}@else ${j}@endif`}else B=`@if (!(${_}))${W}@endif`;J=J.substring(0,K)+B+J.substring(z+10),G=!0}}J=s5(J,Z,Y),J=r5(J,Z,Y),J=o5(J,Z);let X=()=>{let G=k0(J);if(G.length===0)return!1;for(let Q=G.length-1;Q>=0;Q--){let K=G[Q];try{let U="",q=!1;for(let z of K.branches){if(q)break;if(z.type==="else")U=z.content,q=!0;else try{let W;if(z.condition&&u(z.condition))W=h(z.condition,Object.keys(Z))(...Object.values(Z));else if(z.condition)W=g(z.condition,Z);if(W)U=z.content,q=!0}catch(W){U=f(z.type==="if"?"If":"Elseif",`Error in @${z.type}(${z.condition}): ${W instanceof Error?W.message:String(W)}`,x.EVALUATION_ERROR),q=!0}}J=J.substring(0,K.start)+U+J.substring(K.end)}catch(U){let q=U instanceof Error?U.message:String(U),z=f("If",`Error processing @if block: ${q}`,x.EVALUATION_ERROR);J=J.substring(0,K.start)+z+J.substring(K.end)}}return!0};while(X());return J}function n5($){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 J=[];while(Z<$.length){let X=$[Z];if(X==="\\"&&Z+1<$.length){J.push($[Z+1]),Z+=2;continue}if(X===Y){Z++;break}J.push(X),Z++}while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!==")")return null;return Z++,{value:J.join(""),consumed:Z}}function o5($,Z){let Y=$;function J(K,U,q,z){let W=1,_=z,H=new RegExp(`@${U}(?:\\s*\\(|\\s|$)`,"g"),B=new RegExp(`@${q}(?![a-z])`,"g");while(_<K.length&&W>0){H.lastIndex=_,B.lastIndex=_;let j=H.exec(K),O=B.exec(K),V=j?j.index:1/0,L=O?O.index:1/0;if(V<L)W++,_=V+j[0].length;else if(L<1/0){if(W--,W===0)return L;_=L+O[0].length}else break}return-1}function X(K,U,q){let z=0,W=new RegExp(`@${U}(?:\\s*\\(|\\s|$)`,"g"),_=new RegExp(`@${q}(?![a-z])`,"g"),H=/@else(?![a-z])/g,B=[],j;while((j=W.exec(K))!==null)B.push({pos:j.index,type:"open"});while((j=_.exec(K))!==null)B.push({pos:j.index,type:"close"});while((j=H.exec(K))!==null)B.push({pos:j.index,type:"else"});B.sort((O,V)=>O.pos-V.pos);for(let O of B)if(O.type==="open")z++;else if(O.type==="close")z--;else if(O.type==="else"&&z===0)return O.pos;return-1}{let K=!0;while(K){K=!1;let U=Y.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!U||U.index===void 0)break;let q=U.index,z,W,_=Y.slice(q+5),H=n5(_);if(H)z=H.value,W=q+5+H.consumed;else W=q+5;let B=J(Y,"auth","endauth",W);if(B===-1){console.warn(`[stx] @auth directive at position ${q} has no matching @endauth \u2014 the block was skipped.`);break}let j=Y.slice(W,B),O=X(j,"auth","endauth"),V;if(!Z.auth)V=!1;else V=z?Q0(`auth?.check && auth?.user?.[${z}]`,Z):Q0("auth?.check",Z);let L;if(O!==-1){let F=j.slice(0,O),N=j.slice(O+5);L=V?F:N}else L=V?j:"";Y=Y.substring(0,q)+L+Y.substring(B+8),K=!0}}{let K=!0;while(K){K=!1;let U=Y.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!U||U.index===void 0)break;let q=U.index,z,W,_=Y.slice(q+6),H=n5(_);if(H)z=H.value,W=q+6+H.consumed;else W=q+6;let B=J(Y,"guest","endguest",W);if(B===-1){console.warn(`[stx] @guest directive at position ${q} has no matching @endguest \u2014 the block was skipped.`);break}let j=Y.slice(W,B),O=X(j,"guest","endguest"),V;if(!Z.auth)V=!0;else V=z?Q0(`!auth?.check || !auth?.user?.[${z}]`,Z):Q0("!auth?.check",Z);let L;if(O!==-1){let F=j.slice(0,O),N=j.slice(O+5);L=V?F:N}else L=V?j:"";Y=Y.substring(0,q)+L+Y.substring(B+9),K=!0}}function G(K,U,q){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(U)z.push(U);if(q){let W=Q0(q,Z);z.push(W)}return Z.permissions.check(...z)}catch{return!1}return!1}function Q(K){let U=K.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!U)return null;return{ability:U[1],type:U[2],id:U[3]?.trim(),paramsEnd:U[0].length}}for(let K of["can","cannot"]){let U=`end${K}`,q=K==="can"?"elsecan":"elsecannot",z=!0;while(z){z=!1;let W=Y.match(new RegExp(`@${K}\\s*\\(`));if(!W||W.index===void 0)break;let _=W.index,H=Y.slice(_+`@${K}`.length),B=Q(H);if(!B)break;let j=_+`@${K}`.length+B.paramsEnd,O=J(Y,K,U,j);if(O===-1){console.warn(`[stx] @${K} directive at position ${_} has no matching @${U} \u2014 the block was skipped.`);break}let V=Y.slice(j,O),L=[],F=0,N=new RegExp(`@${K}\\s*\\(`,"g"),A=new RegExp(`@${U}(?![a-z])`,"g"),R=new RegExp(`@${q}\\s*\\(`,"g"),T=/@else(?![a-z])/g,y=[],b;while((b=N.exec(V))!==null)y.push({pos:b.index,type:"open"});while((b=A.exec(V))!==null)y.push({pos:b.index,type:"close"});while((b=R.exec(V))!==null)y.push({pos:b.index,type:"elseDirective"});while((b=T.exec(V))!==null)y.push({pos:b.index,type:"else"});y.sort((D,k)=>D.pos-k.pos);for(let D of y){if(D.type==="open"){F++;continue}if(D.type==="close"){F--;continue}if(F===0)L.push(D)}let E=[],M=0;for(let D=0;D<L.length;D++){let k=L[D];if(E.push({content:V.slice(M,k.pos),ability:void 0}),k.type==="elseDirective"){let v=V.slice(k.pos+`@${q}`.length),m=Q(v);if(m){E[E.length-1]={content:V.slice(M,k.pos)},M=k.pos+`@${q}`.length+m.paramsEnd,E.push({content:"",ability:m.ability,type:m.type,id:m.id}),E.pop();let n=L[D+1],e=n?n.pos:V.length;E.push({content:V.slice(M,e),ability:m.ability,type:m.type,id:m.id}),M=e}}else M=k.pos+5}if(M<V.length){let D=E[E.length-1];if(L.length>0&&L[L.length-1].type==="else")E.push({content:V.slice(M),isFinalElse:!0});else if(E.length===0)E.push({content:V.slice(M)})}let I=G(B.ability,B.type,B.id),C=K==="can"?I:!I,S="";if(C)S=E[0]?.content||"";else{let D=!1;for(let k=1;k<E.length;k++){let v=E[k];if(v.isFinalElse){S=v.content,D=!0;break}if(v.ability){let m=G(v.ability,v.type,v.id);if(K==="can"?m:!m){S=v.content,D=!0;break}}}if(!D&&E.length>0){let k=E[E.length-1];if(k.isFinalElse)S=k.content}}Y=Y.substring(0,_)+S+Y.substring(O+`@${U}`.length),z=!0}}return Y}function s5($,Z,Y){let J=$;function X(G,Q,K,U,q){let z=!0;while(z){z=!1;let W=new RegExp(`@${Q}\\s*\\(`),_=G.match(W);if(!_||_.index===void 0)break;let H=_.index,B=K0(G,H+`@${Q}`.length);if(!B)break;let j=B.endPos,O=q0(G,Q,K,j);if(O===-1){console.warn(`[stx] @${Q} directive at position ${H} has no matching @${K} \u2014 the block was skipped.`);break}let V=G.slice(j,O),L=B.expression,F=-1,N=0,A=0;while(A<V.length){let R=V.indexOf("@",A);if(R===-1)break;let T=V.substring(R);if(/^@(?:if|unless|isset|empty)\s*\(/.test(T)){N++,A=R+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(T)){N--,A=R+1;continue}if(N===0&&/^@else(?![a-z])/.test(T)){F=R;break}A=R+1}try{let R=U(L.trim()),T;if(F!==-1){let y=V.slice(0,F),b=V.slice(F+5);T=R?y:b}else T=R?V:"";G=G.substring(0,H)+T+G.substring(O+`@${K}`.length),z=!0}catch(R){let T=R instanceof Error?R.message:String(R),y=f(q,`Error processing @${Q} directive: ${T}`,x.EVALUATION_ERROR);G=G.substring(0,H)+y+G.substring(O+`@${K}`.length);break}}return G}return J=X(J,"isset","endisset",(G)=>{let Q=Q0(G,Z);return Q!==void 0&&Q!==null},"Isset"),J=X(J,"empty","endempty",(G)=>{let Q=Q0(G,Z);return Q===void 0||Q===null||Q===""||Q===0||Q===!1||Array.isArray(Q)&&Q.length===0||typeof Q==="object"&&Q!==null&&Object.keys(Q).length===0},"Empty"),J}function r5($,Z,Y){let J=$,X="development";function G(Q,K,U,q){let z=new RegExp(`@${K}(?![a-z])`,"g"),W=new RegExp(`@${U}(?![a-z])`,"g"),_=new RegExp(`^@${K}(?![a-z])`),H=new RegExp(`^@${U}(?![a-z])`),B=Q,j=!0;while(j){j=!1,z.lastIndex=0;let O=z.exec(B);if(!O)break;let V=O.index,L=V+O[0].length;if(K==="env"){let I=B.substring(L).match(/^\s*\(\s*(['"])([^'"]+)\1\s*\)/);if(!I)break;L+=I[0].length,q=X===I[2]}let F=1,N=L,A=-1;while(F>0&&N<B.length){z.lastIndex=N,W.lastIndex=N;let I=z.exec(B),C=W.exec(B),S=I?I.index:1/0,D=C?C.index:1/0;if(S<D)F++,N=S+I[0].length;else if(D<1/0){if(F--,F===0){A=D;break}N=D+C[0].length}else break}if(A===-1){console.warn(`[stx] @${K} directive at position ${V} has no matching @${U} \u2014 the block was skipped.`);break}let R=B.substring(L,A),T=-1,y=0,b=0;while(b<R.length){let I=R.indexOf("@",b);if(I===-1)break;let C=R.substring(I);if(_.test(C)){y++,b=I+1;continue}if(H.test(C)){y--,b=I+1;continue}if(y===0&&/^@else(?![a-z])/.test(C)){T=I;break}b=I+1}let E;if(T!==-1){let I=R.slice(0,T),C=R.slice(T+5);E=q?I:C}else E=q?R:"";let M=`@${U}`.length;B=B.substring(0,V)+E+B.substring(A+M),j=!0}return B}return J=G(J,"env","endenv",!1),J=G(J,"production","endproduction",X==="production"),J=G(J,"development","enddevelopment",X==="development"),J=G(J,"staging","endstaging",X==="staging"),J=G(J,"testing","endtesting",X==="testing"),J}var y0=w(()=>{x5();$0();S0();p()});var C0=w(()=>{o()});class w0{cache=new Map;maxSize;constructor($=100){this.maxSize=$}get($){if(!this.cache.has($))return;let Z=this.cache.get($);return this.cache.delete($),this.cache.set($,Z),Z}set($,Z){if(this.cache.has($))this.cache.delete($);else if(this.cache.size>=this.maxSize){let Y=this.cache.keys().next().value;if(Y!==void 0)this.cache.delete(Y)}this.cache.set($,Z)}has($){return this.cache.has($)}delete($){return this.cache.delete($)}clear(){this.cache.clear()}get size(){return this.cache.size}keys(){return this.cache.keys()}values(){return this.cache.values()}}class e5{pool=[];maxPoolSize=10;fnCache=new Map;fnCacheMaxSize=200;getEvaluator($){let Z=Array.from(new Set($)),Y=Z.sort().join(","),J=this.pool.find((K)=>K.context.join(",")===Y);if(J)return J.func;let X=this.fnCache,G=this.fnCacheMaxSize,Q=(...K)=>{return(U)=>{try{let q=`${Y}:${U}`,z=X.get(q);if(!z){if(X.size>=G){let W=X.keys().next().value;if(W)X.delete(W)}z=Function(...Z,`
|
|
37
|
+
`),"utf-8")}}async flush(){await this.writeQueue}}var V1;var m5=w(()=>{E0();V1=new O1});var u5=()=>{};var l5=w(()=>{D0();d5();m5();u5();E0()});var $0=w(()=>{l5()});function Z0($,Z,Y,J=0){let X=0,G=J,Q=null,K=0,U=!1;while(G<$.length){let q=$[G];if(Q&&U){U=!1,G++;continue}if(Q&&q==="\\"){U=!0,G++;continue}if(U=!1,(q==='"'||q==="'"||q==="`")&&!Q){Q=q,G++;continue}if(q===Q&&Q!=="`"){Q=null,G++;continue}if(Q==="`"&&q==="$"&&$[G+1]==="{"){K++,G+=2;continue}if(K>0&&q==="}"){K--,G++;continue}if(q==="`"&&Q==="`"&&K===0){Q=null,G++;continue}if(Q){G++;continue}if(q===Z)X++;else if(q===Y){if(X--,X===0)return G}G++}return-1}function K0($,Z){let Y=i3($,Z);return Y.ok?{expression:Y.expression,endPos:Y.endPos}:null}function i3($,Z){let Y=Z;while(Y<$.length&&/\s/.test($[Y]))Y++;if($[Y]!=="(")return{ok:!1,reason:"missing-open-paren",pos:Y};let J=Z0($,"(",")",Y);if(J===-1)return{ok:!1,reason:"unclosed-paren",pos:Y};return{ok:!0,expression:$.slice(Y+1,J),endPos:J+1}}function q0($,Z,Y,J){let X=1,G=J,Q=new RegExp(`@${Z}\\s*\\(`,"g"),K=new RegExp(`@${Y}(?![a-z])`,"g");while(G<$.length&&X>0){Q.lastIndex=G,K.lastIndex=G;let U=Q.exec($),q=K.exec($),z=U?U.index:1/0,W=q?q.index:1/0;if(z<W)X++,G=z+U[0].length;else if(W<1/0){if(X--,X===0)return W;G=W+q[0].length}else break}return-1}function c5($,Z){let Y=$.slice(Z).match(/^@if\s*/);if(!Y)return null;let J=Z+Y[0].length,X=K0($,J);if(!X)return null;let G=X.endPos,Q=q0($,"if","endif",G);if(Q===-1)return null;let K=$.slice(G,Q),U=[],q=0,z="if",W=X.expression,_=0,H=0;while(q<K.length){let B=K.indexOf("@",q);if(B===-1)break;q=B;let j=K.substring(B);if(/^@if\s*\(/.test(j)){H++,q++;continue}if(/^@endif(?![a-z])/.test(j)){H--,q+=6;continue}if(H===0){let O=j.match(/^@elseif\s*/);if(O){U.push({type:z,condition:W,content:K.substring(_,q),start:G+_,end:G+q});let V=q+O[0].length,L=K0(K,V);if(!L){q++;continue}z="elseif",W=L.expression,q=L.endPos,_=q;continue}else if(/^@else(?![a-z])/.test(j)){U.push({type:z,condition:W,content:K.substring(_,q),start:G+_,end:G+q}),z="else",W=void 0,q+=5,_=q;continue}}q++}return U.push({type:z,condition:W,content:K.slice(_),start:G+_,end:G+K.length}),{fullMatch:$.slice(Z,Q+6),branches:U,start:Z,end:Q+6}}function k0($){let Z=[],Y=/@if\s*\(/g,J=Y.exec($);while(J!==null){if(Z.some((Q)=>J.index>Q.start&&J.index<Q.end)){J=Y.exec($);continue}let G=c5($,J.index);if(G)Z.push(G),Y.lastIndex=G.end;J=Y.exec($)}return Z}function b0($,Z,Y){let J=[],X=new RegExp(`@${Z}\\s*\\(`,"g"),G=X.exec($);while(G!==null){if(J.some((j)=>G.index>j.start&&G.index<j.end)){G=X.exec($);continue}let K=G.index,U=K+G[0].length-1,q=Z0($,"(",")",U);if(q===-1){G=X.exec($);continue}let z=$.slice(U+1,q),W=q+1,_=q0($,Z,Y,W);if(_===-1){G=X.exec($);continue}let H=$.slice(W,_),B=_+`@${Y}`.length;J.push({fullMatch:$.slice(K,B),name:Z,params:z,content:H,start:K,end:B}),X.lastIndex=B,G=X.exec($)}return J}function L1($,Z){let Y=$.slice(Z).match(/^@switch\s*/);if(!Y)return null;let J=Z+Y[0].length,X=K0($,J);if(!X)return null;let G=X.endPos,Q=q0($,"switch","endswitch",G);if(Q===-1)return null;let K=$.slice(G,Q),U=[],q=0,z=null,W=0;while(q<K.length){let _=K.slice(q),H=_.match(/^@switch\s*\(/),B=_.match(/^@endswitch(?![a-z])/);if(H){if(W++,z)z.content+=H[0];q+=H[0].length;continue}if(B){if(W--,z)z.content+=B[0];q+=B[0].length;continue}if(W>0){if(z)z.content+=K[q];q++;continue}let j=_.match(/^@case\s*/),O=_.match(/^@default(?![a-z])/),V=_.match(/^@break(?![a-z])/);if(j&&_.startsWith("@case")){if(z)U.push(z);let L=q+j[0].length,F=K0(K,L);if(!F){q++;continue}z={type:"case",value:F.expression,content:""},q=F.endPos}else if(O&&_.startsWith("@default")){if(z)U.push(z);z={type:"default",content:""},q+=O[0].length}else if(V&&_.startsWith("@break"))q+=V[0].length;else{if(z)z.content+=K[q];q++}}if(z)U.push(z);return{fullMatch:$.slice(Z,Q+10),expression:X.expression,cases:U,start:Z,end:Q+10}}var p5=()=>{};var i5=()=>{};var S0=w(()=>{p5();i5()});function r3($,Z,Y){let J=$,X=!0;while(X){X=!1;let G=J.match(/@switch\s*\(/);if(!G||G.index===void 0)break;let Q=G.index,K=L1(J,Q);if(!K)break;try{let U;if(u(K.expression))U=h(K.expression,Object.keys(Z))(...Object.values(Z));else U=g(K.expression,Z);let q="",z=!1;for(let W of K.cases)if(W.type==="default"){if(!z)q=W.content.trim()}else try{let _;if(W.value&&u(W.value))_=h(W.value,Object.keys(Z))(...Object.values(Z));else if(W.value)_=g(W.value,Z);if(U===_){q=W.content.trim(),z=!0;break}}catch{continue}J=J.substring(0,Q)+q+J.substring(K.end),X=!0}catch(U){let q=U instanceof Error?U.message:String(U),z=f("Switch",`Error evaluating @switch expression: ${q}`,x.EVALUATION_ERROR);J=J.substring(0,Q)+z+J.substring(K.end);break}}return J}function F0($,Z,Y){let J=$;J=r3(J,Z,Y);{let G=!0;while(G){G=!1;let Q=J.match(/@unless\s*\(/);if(!Q||Q.index===void 0)break;let K=Q.index,U=K0(J,K+7);if(!U)break;let q=U.endPos,z=q0(J,"unless","endunless",q);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 W=J.slice(q,z),_=U.expression,H=-1;{let j=0,O=/@(?:if|unless)\s*\(/g,V=/@(?:endif|endunless)(?![a-z])/g,L=/@else(?![a-z])/g,F=[],N;while((N=O.exec(W))!==null)F.push({pos:N.index,type:"open"});while((N=V.exec(W))!==null)F.push({pos:N.index,type:"close"});while((N=L.exec(W))!==null)F.push({pos:N.index,type:"else"});F.sort((A,R)=>A.pos-R.pos);for(let A of F)if(A.type==="open")j++;else if(A.type==="close")j--;else if(A.type==="else"&&j===0){H=A.pos;break}}let B;if(H!==-1){let j=W.slice(0,H),O=W.slice(H+5);B=`@if (${_})${O}@else ${j}@endif`}else B=`@if (!(${_}))${W}@endif`;J=J.substring(0,K)+B+J.substring(z+10),G=!0}}J=s5(J,Z,Y),J=r5(J,Z,Y),J=o5(J,Z);let X=()=>{let G=k0(J);if(G.length===0)return!1;for(let Q=G.length-1;Q>=0;Q--){let K=G[Q];try{let U="",q=!1;for(let z of K.branches){if(q)break;if(z.type==="else")U=z.content,q=!0;else try{let W;if(z.condition&&u(z.condition))W=h(z.condition,Object.keys(Z))(...Object.values(Z));else if(z.condition)W=g(z.condition,Z);if(W)U=z.content,q=!0}catch(W){U=f(z.type==="if"?"If":"Elseif",`Error in @${z.type}(${z.condition}): ${W instanceof Error?W.message:String(W)}`,x.EVALUATION_ERROR),q=!0}}J=J.substring(0,K.start)+U+J.substring(K.end)}catch(U){let q=U instanceof Error?U.message:String(U),z=f("If",`Error processing @if block: ${q}`,x.EVALUATION_ERROR);J=J.substring(0,K.start)+z+J.substring(K.end)}}return!0};while(!0){let G=J;if(!X())break;if(J===G)break}return J}function n5($){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 J=[];while(Z<$.length){let X=$[Z];if(X==="\\"&&Z+1<$.length){J.push($[Z+1]),Z+=2;continue}if(X===Y){Z++;break}J.push(X),Z++}while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!==")")return null;return Z++,{value:J.join(""),consumed:Z}}function o5($,Z){let Y=$;function J(K,U,q,z){let W=1,_=z,H=new RegExp(`@${U}(?:\\s*\\(|\\s|$)`,"g"),B=new RegExp(`@${q}(?![a-z])`,"g");while(_<K.length&&W>0){H.lastIndex=_,B.lastIndex=_;let j=H.exec(K),O=B.exec(K),V=j?j.index:1/0,L=O?O.index:1/0;if(V<L)W++,_=V+j[0].length;else if(L<1/0){if(W--,W===0)return L;_=L+O[0].length}else break}return-1}function X(K,U,q){let z=0,W=new RegExp(`@${U}(?:\\s*\\(|\\s|$)`,"g"),_=new RegExp(`@${q}(?![a-z])`,"g"),H=/@else(?![a-z])/g,B=[],j;while((j=W.exec(K))!==null)B.push({pos:j.index,type:"open"});while((j=_.exec(K))!==null)B.push({pos:j.index,type:"close"});while((j=H.exec(K))!==null)B.push({pos:j.index,type:"else"});B.sort((O,V)=>O.pos-V.pos);for(let O of B)if(O.type==="open")z++;else if(O.type==="close")z--;else if(O.type==="else"&&z===0)return O.pos;return-1}{let K=!0;while(K){K=!1;let U=Y.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!U||U.index===void 0)break;let q=U.index,z,W,_=Y.slice(q+5),H=n5(_);if(H)z=H.value,W=q+5+H.consumed;else W=q+5;let B=J(Y,"auth","endauth",W);if(B===-1){console.warn(`[stx] @auth directive at position ${q} has no matching @endauth \u2014 the block was skipped.`);break}let j=Y.slice(W,B),O=X(j,"auth","endauth"),V;if(!Z.auth)V=!1;else V=z?Q0(`auth?.check && auth?.user?.[${z}]`,Z):Q0("auth?.check",Z);let L;if(O!==-1){let F=j.slice(0,O),N=j.slice(O+5);L=V?F:N}else L=V?j:"";Y=Y.substring(0,q)+L+Y.substring(B+8),K=!0}}{let K=!0;while(K){K=!1;let U=Y.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!U||U.index===void 0)break;let q=U.index,z,W,_=Y.slice(q+6),H=n5(_);if(H)z=H.value,W=q+6+H.consumed;else W=q+6;let B=J(Y,"guest","endguest",W);if(B===-1){console.warn(`[stx] @guest directive at position ${q} has no matching @endguest \u2014 the block was skipped.`);break}let j=Y.slice(W,B),O=X(j,"guest","endguest"),V;if(!Z.auth)V=!0;else V=z?Q0(`!auth?.check || !auth?.user?.[${z}]`,Z):Q0("!auth?.check",Z);let L;if(O!==-1){let F=j.slice(0,O),N=j.slice(O+5);L=V?F:N}else L=V?j:"";Y=Y.substring(0,q)+L+Y.substring(B+9),K=!0}}function G(K,U,q){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(U)z.push(U);if(q){let W=Q0(q,Z);z.push(W)}return Z.permissions.check(...z)}catch{return!1}return!1}function Q(K){let U=K.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!U)return null;return{ability:U[1],type:U[2],id:U[3]?.trim(),paramsEnd:U[0].length}}for(let K of["can","cannot"]){let U=`end${K}`,q=K==="can"?"elsecan":"elsecannot",z=!0;while(z){z=!1;let W=Y.match(new RegExp(`@${K}\\s*\\(`));if(!W||W.index===void 0)break;let _=W.index,H=Y.slice(_+`@${K}`.length),B=Q(H);if(!B)break;let j=_+`@${K}`.length+B.paramsEnd,O=J(Y,K,U,j);if(O===-1){console.warn(`[stx] @${K} directive at position ${_} has no matching @${U} \u2014 the block was skipped.`);break}let V=Y.slice(j,O),L=[],F=0,N=new RegExp(`@${K}\\s*\\(`,"g"),A=new RegExp(`@${U}(?![a-z])`,"g"),R=new RegExp(`@${q}\\s*\\(`,"g"),T=/@else(?![a-z])/g,y=[],b;while((b=N.exec(V))!==null)y.push({pos:b.index,type:"open"});while((b=A.exec(V))!==null)y.push({pos:b.index,type:"close"});while((b=R.exec(V))!==null)y.push({pos:b.index,type:"elseDirective"});while((b=T.exec(V))!==null)y.push({pos:b.index,type:"else"});y.sort((D,k)=>D.pos-k.pos);for(let D of y){if(D.type==="open"){F++;continue}if(D.type==="close"){F--;continue}if(F===0)L.push(D)}let E=[],M=0;for(let D=0;D<L.length;D++){let k=L[D];if(E.push({content:V.slice(M,k.pos),ability:void 0}),k.type==="elseDirective"){let v=V.slice(k.pos+`@${q}`.length),m=Q(v);if(m){E[E.length-1]={content:V.slice(M,k.pos)},M=k.pos+`@${q}`.length+m.paramsEnd,E.push({content:"",ability:m.ability,type:m.type,id:m.id}),E.pop();let n=L[D+1],e=n?n.pos:V.length;E.push({content:V.slice(M,e),ability:m.ability,type:m.type,id:m.id}),M=e}}else M=k.pos+5}if(M<V.length){let D=E[E.length-1];if(L.length>0&&L[L.length-1].type==="else")E.push({content:V.slice(M),isFinalElse:!0});else if(E.length===0)E.push({content:V.slice(M)})}let I=G(B.ability,B.type,B.id),C=K==="can"?I:!I,S="";if(C)S=E[0]?.content||"";else{let D=!1;for(let k=1;k<E.length;k++){let v=E[k];if(v.isFinalElse){S=v.content,D=!0;break}if(v.ability){let m=G(v.ability,v.type,v.id);if(K==="can"?m:!m){S=v.content,D=!0;break}}}if(!D&&E.length>0){let k=E[E.length-1];if(k.isFinalElse)S=k.content}}Y=Y.substring(0,_)+S+Y.substring(O+`@${U}`.length),z=!0}}return Y}function s5($,Z,Y){let J=$;function X(G,Q,K,U,q){let z=!0;while(z){z=!1;let W=new RegExp(`@${Q}\\s*\\(`),_=G.match(W);if(!_||_.index===void 0)break;let H=_.index,B=K0(G,H+`@${Q}`.length);if(!B)break;let j=B.endPos,O=q0(G,Q,K,j);if(O===-1){console.warn(`[stx] @${Q} directive at position ${H} has no matching @${K} \u2014 the block was skipped.`);break}let V=G.slice(j,O),L=B.expression,F=-1,N=0,A=0;while(A<V.length){let R=V.indexOf("@",A);if(R===-1)break;let T=V.substring(R);if(/^@(?:if|unless|isset|empty)\s*\(/.test(T)){N++,A=R+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(T)){N--,A=R+1;continue}if(N===0&&/^@else(?![a-z])/.test(T)){F=R;break}A=R+1}try{let R=U(L.trim()),T;if(F!==-1){let y=V.slice(0,F),b=V.slice(F+5);T=R?y:b}else T=R?V:"";G=G.substring(0,H)+T+G.substring(O+`@${K}`.length),z=!0}catch(R){let T=R instanceof Error?R.message:String(R),y=f(q,`Error processing @${Q} directive: ${T}`,x.EVALUATION_ERROR);G=G.substring(0,H)+y+G.substring(O+`@${K}`.length);break}}return G}return J=X(J,"isset","endisset",(G)=>{let Q=Q0(G,Z);return Q!==void 0&&Q!==null},"Isset"),J=X(J,"empty","endempty",(G)=>{let Q=Q0(G,Z);return Q===void 0||Q===null||Q===""||Q===0||Q===!1||Array.isArray(Q)&&Q.length===0||typeof Q==="object"&&Q!==null&&Object.keys(Q).length===0},"Empty"),J}function r5($,Z,Y){let J=$,X="development";function G(Q,K,U,q){let z=new RegExp(`@${K}(?![a-z])`,"g"),W=new RegExp(`@${U}(?![a-z])`,"g"),_=new RegExp(`^@${K}(?![a-z])`),H=new RegExp(`^@${U}(?![a-z])`),B=Q,j=!0;while(j){j=!1,z.lastIndex=0;let O=z.exec(B);if(!O)break;let V=O.index,L=V+O[0].length;if(K==="env"){let I=B.substring(L).match(/^\s*\(\s*(['"])([^'"]+)\1\s*\)/);if(!I)break;L+=I[0].length,q=X===I[2]}let F=1,N=L,A=-1;while(F>0&&N<B.length){z.lastIndex=N,W.lastIndex=N;let I=z.exec(B),C=W.exec(B),S=I?I.index:1/0,D=C?C.index:1/0;if(S<D)F++,N=S+I[0].length;else if(D<1/0){if(F--,F===0){A=D;break}N=D+C[0].length}else break}if(A===-1){console.warn(`[stx] @${K} directive at position ${V} has no matching @${U} \u2014 the block was skipped.`);break}let R=B.substring(L,A),T=-1,y=0,b=0;while(b<R.length){let I=R.indexOf("@",b);if(I===-1)break;let C=R.substring(I);if(_.test(C)){y++,b=I+1;continue}if(H.test(C)){y--,b=I+1;continue}if(y===0&&/^@else(?![a-z])/.test(C)){T=I;break}b=I+1}let E;if(T!==-1){let I=R.slice(0,T),C=R.slice(T+5);E=q?I:C}else E=q?R:"";let M=`@${U}`.length;B=B.substring(0,V)+E+B.substring(A+M),j=!0}return B}return J=G(J,"env","endenv",!1),J=G(J,"production","endproduction",X==="production"),J=G(J,"development","enddevelopment",X==="development"),J=G(J,"staging","endstaging",X==="staging"),J=G(J,"testing","endtesting",X==="testing"),J}var y0=w(()=>{x5();$0();S0();p()});var C0=w(()=>{o()});class w0{cache=new Map;maxSize;constructor($=100){this.maxSize=$}get($){if(!this.cache.has($))return;let Z=this.cache.get($);return this.cache.delete($),this.cache.set($,Z),Z}set($,Z){if(this.cache.has($))this.cache.delete($);else if(this.cache.size>=this.maxSize){let Y=this.cache.keys().next().value;if(Y!==void 0)this.cache.delete(Y)}this.cache.set($,Z)}has($){return this.cache.has($)}delete($){return this.cache.delete($)}clear(){this.cache.clear()}get size(){return this.cache.size}keys(){return this.cache.keys()}values(){return this.cache.values()}}class e5{pool=[];maxPoolSize=10;fnCache=new Map;fnCacheMaxSize=200;getEvaluator($){let Z=Array.from(new Set($)),Y=Z.sort().join(","),J=this.pool.find((K)=>K.context.join(",")===Y);if(J)return J.func;let X=this.fnCache,G=this.fnCacheMaxSize,Q=(...K)=>{return(U)=>{try{let q=`${Y}:${U}`,z=X.get(q);if(!z){if(X.size>=G){let W=X.keys().next().value;if(W)X.delete(W)}z=Function(...Z,`
|
|
38
38
|
'use strict';
|
|
39
39
|
try {
|
|
40
40
|
return ${U};
|
package/dist/plugin.js
CHANGED
|
@@ -2675,7 +2675,7 @@ window.__stx_reactive = (function() {
|
|
|
2675
2675
|
${EU()}
|
|
2676
2676
|
${X}
|
|
2677
2677
|
</script>`}function tX($,Z,X){if(aX=0,!SU($))return $;let Y=RU($);if(Y.length===0)return $;let Q=kU($,Y),J=DU(Y,Z),G=Q.lastIndexOf("</body>");if(G!==-1)Q=Q.slice(0,G)+J+`
|
|
2678
|
-
`+Q.slice(G);else Q+=J;return Q}function kU($,Z){let X=$;for(let Y of Z){let J=new RegExp(`<[a-z][a-z0-9-]*\\s+[^>]*data-stx-scope="([^"]*)"[^>]*x-data\\s*=\\s*["']${j7(Y.stateExpr)}["']`,"gi").exec(X);if(J)Y.id=J[1],Y.selector=`[data-stx-scope="${Y.id}"]`;else{let K=new RegExp(`<[a-z][a-z0-9-]*\\s+[^>]*x-data\\s*=\\s*["']${j7(Y.stateExpr)}["'][^>]*data-stx-scope="([^"]*)"`,"gi").exec(X);if(K)Y.id=K[1],Y.selector=`[data-stx-scope="${Y.id}"]`;else X=X.replace(new RegExp(`(<[a-z][a-z0-9-]*\\s+)([^>]*)(x-data\\s*=\\s*"${j7(Y.stateExpr)}")([^>]*>)`,"gi"),`$1data-stx-scope="${Y.id}" $2$3$4`),X=X.replace(new RegExp(`(<[a-z][a-z0-9-]*\\s+)([^>]*)(x-data\\s*=\\s*'${j7(Y.stateExpr)}')([^>]*>)`,"gi"),`$1data-stx-scope="${Y.id}" $2$3$4`)}}return X=X.replace(/\s*x-data\s*=\s*"([^"]*)"/g,' data-stx-xdata="$1"'),X=X.replace(/\s*x-data\s*=\s*'([^']*)'/g," data-stx-xdata='$1'"),X=X.replace(/\s*x-init\s*=\s*"[^"]*"/g,""),X=X.replace(/\s*x-init\s*=\s*'[^']*'/g,""),X}function SU($){return/x-data\s*=\s*["']/.test($)}var aX=0,wU=0;var eX=T(()=>{M0()});import CU from"fs";import k6 from"path";import{createHighlighter as bU}from"ts-syntax-highlighter";async function O7($,Z={}){try{if(!await c($))throw Error(`Markdown file not found: ${$}`);let Y=(await CU.promises.stat($)).mtime.getTime();if(Z.cache&&S6.has($)){let _=S6.get($);if(_.updatedAt>=Y)return{content:_.content,data:_.data}}let Q=await Bun.file($).text(),{data:J,content:G}=CZ(Q),K=Z.markdown||W$.markdown||{enabled:!0,syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}},B=v$(G,{gfm:!0});if(K.syntaxHighlighting?.enabled&&K.syntaxHighlighting?.serverSide)B=await PU(B,K.syntaxHighlighting?.defaultTheme||"github-dark",K.syntaxHighlighting?.highlightUnknownLanguages||!1);let U={content:B,data:J||{}};if(Z.cache)S6.set($,{...U,updatedAt:Y});return U}catch(X){if(Z.debug)console.error(`Error reading/parsing markdown file ${$}:`,X);let Y=X instanceof Error?X.message:String(X);return{content:Q0("Markdown File",`Error reading/parsing markdown file: ${Y}`,$,"",0,""),data:{}}}}async function PU($,Z,X){let Y=/<pre><code( class="language-([^"]+)")?>([^<]+)<\/code><\/pre>/g;if(!H7)try{H7=await bU({theme:Z||"github-dark",cache:!0})}catch(K){return console.error("Failed to initialize ts-syntax-highlighter:",K),$}let Q=async(K,W,B,U)=>{let _=U.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'"),z=B||(X?"text":"");if(!z)return K;try{if(!H7.getSupportedLanguages().includes(z))return K;return(await H7.highlight(_,z,{theme:Z})).html}catch(q){console.error(`Error highlighting code block with language ${B}:`,q)}return K},J=$,G=$.matchAll(Y);for(let K of G){let[W,B,U,_]=K,z=await Q(W,B,U,_);J=J.replace(W,z)}return J}async function $Y($,Z,X="",Y={}){return await yU($,/@markdown-file\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\{[^}]*\}))?\)/g,async(G,K,W,B)=>{try{let U=K;if(!k6.isAbsolute(K))U=k6.resolve(k6.dirname(X),K);let _={};if(W)try{try{_=JSON.parse(W)}catch{if(Y.debug)console.warn("Using safer alternative for parsing JS object literal");let O=W.replace(/^\s*\{|\}\s*$/g,"").trim().split(/,(?=\s*\w+\s*:)/);for(let V of O){let N=V.indexOf(":");if(N>0){let A=V.substring(0,N).trim(),w=V.substring(N+1).trim(),R=w.startsWith('"')&&w.endsWith('"'),M=w.startsWith("'")&&w.endsWith("'");if(R||M)w=w.substring(1,w.length-1);_[A]=w}}}}catch(F){if(Y.debug)console.error("Error parsing context in @markdown-file directive:",F)}let{content:z,data:q}=await O7(U,Y),j={...Z,...q,..._},H=z,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 _=U instanceof Error?U.message:String(U);return Q0("Markdown File",`Error including markdown file: ${_}`,X,$,B,G)}})}async function yU($,Z,X){let Y=[],Q;while((Q=Z.exec($))!==null){let K=Q[0],W=Q.index,B=Q;Y.push(X(...B).then((U)=>({match:K,replacement:U,index:W})))}let J=await Promise.all(Y);J.sort((K,W)=>W.index-K.index);let G=$;for(let{match:K,replacement:W}of J)G=G.replace(K,()=>W);return G}var S6,H7=null;var B$=T(()=>{E0();J0();S6=new Map});function q1($,Z){try{let X=$.trim();if(Z0(X))return X0(X,Object.keys(Z))(...Object.values(Z));else return $0(X,Z)}catch{return!1}}var C6=T(()=>{L0()});function C0($,Z,X,Y=0){let Q=0,J=Y,G=null,K=0,W=!1;while(J<$.length){let B=$[J];if(G&&W){W=!1,J++;continue}if(G&&B==="\\"){W=!0,J++;continue}if(W=!1,(B==='"'||B==="'"||B==="`")&&!G){G=B,J++;continue}if(B===G&&G!=="`"){G=null,J++;continue}if(G==="`"&&B==="$"&&$[J+1]==="{"){K++,J+=2;continue}if(K>0&&B==="}"){K--,J++;continue}if(B==="`"&&G==="`"&&K===0){G=null,J++;continue}if(G){J++;continue}if(B===Z)Q++;else if(B===X){if(Q--,Q===0)return J}J++}return-1}function j1($,Z){let X=xU($,Z);return X.ok?{expression:X.expression,endPos:X.endPos}:null}function xU($,Z){let X=Z;while(X<$.length&&/\s/.test($[X]))X++;if($[X]!=="(")return{ok:!1,reason:"missing-open-paren",pos:X};let Y=C0($,"(",")",X);if(Y===-1)return{ok:!1,reason:"unclosed-paren",pos:X};return{ok:!0,expression:$.slice(X+1,Y),endPos:Y+1}}function h1($,Z,X,Y){let Q=1,J=Y,G=new RegExp(`@${Z}\\s*\\(`,"g"),K=new RegExp(`@${X}(?![a-z])`,"g");while(J<$.length&&Q>0){G.lastIndex=J,K.lastIndex=J;let W=G.exec($),B=K.exec($),U=W?W.index:1/0,_=B?B.index:1/0;if(U<_)Q++,J=U+W[0].length;else if(_<1/0){if(Q--,Q===0)return _;J=_+B[0].length}else break}return-1}function ZY($,Z){let X=$.slice(Z).match(/^@if\s*/);if(!X)return null;let Y=Z+X[0].length,Q=j1($,Y);if(!Q)return null;let J=Q.endPos,G=h1($,"if","endif",J);if(G===-1)return null;let K=$.slice(J,G),W=[],B=0,U="if",_=Q.expression,z=0,q=0;while(B<K.length){let j=K.indexOf("@",B);if(j===-1)break;B=j;let H=K.substring(j);if(/^@if\s*\(/.test(H)){q++,B++;continue}if(/^@endif(?![a-z])/.test(H)){q--,B+=6;continue}if(q===0){let L=H.match(/^@elseif\s*/);if(L){W.push({type:U,condition:_,content:K.substring(z,B),start:J+z,end:J+B});let F=B+L[0].length,O=j1(K,F);if(!O){B++;continue}U="elseif",_=O.expression,B=O.endPos,z=B;continue}else if(/^@else(?![a-z])/.test(H)){W.push({type:U,condition:_,content:K.substring(z,B),start:J+z,end:J+B}),U="else",_=void 0,B+=5,z=B;continue}}B++}return W.push({type:U,condition:_,content:K.slice(z),start:J+z,end:J+K.length}),{fullMatch:$.slice(Z,G+6),branches:W,start:Z,end:G+6}}function K5($){let Z=[],X=/@if\s*\(/g,Y=X.exec($);while(Y!==null){if(Z.some((G)=>Y.index>G.start&&Y.index<G.end)){Y=X.exec($);continue}let J=ZY($,Y.index);if(J)Z.push(J),X.lastIndex=J.end;Y=X.exec($)}return Z}function L7($,Z,X){let Y=[],Q=new RegExp(`@${Z}\\s*\\(`,"g"),J=Q.exec($);while(J!==null){if(Y.some((H)=>J.index>H.start&&J.index<H.end)){J=Q.exec($);continue}let K=J.index,W=K+J[0].length-1,B=C0($,"(",")",W);if(B===-1){J=Q.exec($);continue}let U=$.slice(W+1,B),_=B+1,z=h1($,Z,X,_);if(z===-1){J=Q.exec($);continue}let q=$.slice(_,z),j=z+`@${X}`.length;Y.push({fullMatch:$.slice(K,j),name:Z,params:U,content:q,start:K,end:j}),Q.lastIndex=j,J=Q.exec($)}return Y}function b6($,Z){let X=$.slice(Z).match(/^@switch\s*/);if(!X)return null;let Y=Z+X[0].length,Q=j1($,Y);if(!Q)return null;let J=Q.endPos,G=h1($,"switch","endswitch",J);if(G===-1)return null;let K=$.slice(J,G),W=[],B=0,U=null,_=0;while(B<K.length){let z=K.slice(B),q=z.match(/^@switch\s*\(/),j=z.match(/^@endswitch(?![a-z])/);if(q){if(_++,U)U.content+=q[0];B+=q[0].length;continue}if(j){if(_--,U)U.content+=j[0];B+=j[0].length;continue}if(_>0){if(U)U.content+=K[B];B++;continue}let H=z.match(/^@case\s*/),L=z.match(/^@default(?![a-z])/),F=z.match(/^@break(?![a-z])/);if(H&&z.startsWith("@case")){if(U)W.push(U);let O=B+H[0].length,V=j1(K,O);if(!V){B++;continue}U={type:"case",value:V.expression,content:""},B=V.endPos}else if(L&&z.startsWith("@default")){if(U)W.push(U);U={type:"default",content:""},B+=L[0].length}else if(F&&z.startsWith("@break"))B+=F[0].length;else{if(U)U.content+=K[B];B++}}if(U)W.push(U);return{fullMatch:$.slice(Z,G+10),expression:Q.expression,cases:W,start:Z,end:G+10}}var XY=()=>{};var YY=()=>{};var W5=T(()=>{XY();YY()});function hU($,Z,X){let Y=$,Q=!0;while(Q){Q=!1;let J=Y.match(/@switch\s*\(/);if(!J||J.index===void 0)break;let G=J.index,K=b6(Y,G);if(!K)break;try{let W;if(Z0(K.expression))W=X0(K.expression,Object.keys(Z))(...Object.values(Z));else W=$0(K.expression,Z);let B="",U=!1;for(let _ of K.cases)if(_.type==="default"){if(!U)B=_.content.trim()}else try{let z;if(_.value&&Z0(_.value))z=X0(_.value,Object.keys(Z))(...Object.values(Z));else if(_.value)z=$0(_.value,Z);if(W===z){B=_.content.trim(),U=!0;break}}catch{continue}Y=Y.substring(0,G)+B+Y.substring(K.end),Q=!0}catch(W){let B=W instanceof Error?W.message:String(W),U=n("Switch",`Error evaluating @switch expression: ${B}`,i.EVALUATION_ERROR);Y=Y.substring(0,G)+U+Y.substring(K.end);break}}return Y}function d1($,Z,X){let Y=$;Y=hU(Y,Z,X);{let J=!0;while(J){J=!1;let G=Y.match(/@unless\s*\(/);if(!G||G.index===void 0)break;let K=G.index,W=j1(Y,K+7);if(!W)break;let B=W.endPos,U=h1(Y,"unless","endunless",B);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 _=Y.slice(B,U),z=W.expression,q=-1;{let H=0,L=/@(?:if|unless)\s*\(/g,F=/@(?:endif|endunless)(?![a-z])/g,O=/@else(?![a-z])/g,V=[],N;while((N=L.exec(_))!==null)V.push({pos:N.index,type:"open"});while((N=F.exec(_))!==null)V.push({pos:N.index,type:"close"});while((N=O.exec(_))!==null)V.push({pos:N.index,type:"else"});V.sort((A,w)=>A.pos-w.pos);for(let A of V)if(A.type==="open")H++;else if(A.type==="close")H--;else if(A.type==="else"&&H===0){q=A.pos;break}}let j;if(q!==-1){let H=_.slice(0,q),L=_.slice(q+5);j=`@if (${z})${L}@else ${H}@endif`}else j=`@if (!(${z}))${_}@endif`;Y=Y.substring(0,K)+j+Y.substring(U+10),J=!0}}Y=y6(Y,Z,X),Y=x6(Y,Z,X),Y=P6(Y,Z);let Q=()=>{let J=K5(Y);if(J.length===0)return!1;for(let G=J.length-1;G>=0;G--){let K=J[G];try{let W="",B=!1;for(let U of K.branches){if(B)break;if(U.type==="else")W=U.content,B=!0;else try{let _;if(U.condition&&Z0(U.condition))_=X0(U.condition,Object.keys(Z))(...Object.values(Z));else if(U.condition)_=$0(U.condition,Z);if(_)W=U.content,B=!0}catch(_){W=n(U.type==="if"?"If":"Elseif",`Error in @${U.type}(${U.condition}): ${_ instanceof Error?_.message:String(_)}`,i.EVALUATION_ERROR),B=!0}}Y=Y.substring(0,K.start)+W+Y.substring(K.end)}catch(W){let B=W instanceof Error?W.message:String(W),U=n("If",`Error processing @if block: ${B}`,i.EVALUATION_ERROR);Y=Y.substring(0,K.start)+U+Y.substring(K.end)}}return!0};while(Q());return Y}function JY($){let Z=0;while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!=="(")return null;Z++;while(Z<$.length&&/\s/.test($[Z]))Z++;let X=$[Z];if(X!=="'"&&X!=='"')return null;Z++;let Y=[];while(Z<$.length){let Q=$[Z];if(Q==="\\"&&Z+1<$.length){Y.push($[Z+1]),Z+=2;continue}if(Q===X){Z++;break}Y.push(Q),Z++}while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!==")")return null;return Z++,{value:Y.join(""),consumed:Z}}function P6($,Z){let X=$;function Y(K,W,B,U){let _=1,z=U,q=new RegExp(`@${W}(?:\\s*\\(|\\s|$)`,"g"),j=new RegExp(`@${B}(?![a-z])`,"g");while(z<K.length&&_>0){q.lastIndex=z,j.lastIndex=z;let H=q.exec(K),L=j.exec(K),F=H?H.index:1/0,O=L?L.index:1/0;if(F<O)_++,z=F+H[0].length;else if(O<1/0){if(_--,_===0)return O;z=O+L[0].length}else break}return-1}function Q(K,W,B){let U=0,_=new RegExp(`@${W}(?:\\s*\\(|\\s|$)`,"g"),z=new RegExp(`@${B}(?![a-z])`,"g"),q=/@else(?![a-z])/g,j=[],H;while((H=_.exec(K))!==null)j.push({pos:H.index,type:"open"});while((H=z.exec(K))!==null)j.push({pos:H.index,type:"close"});while((H=q.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 W=X.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!W||W.index===void 0)break;let B=W.index,U,_,z=X.slice(B+5),q=JY(z);if(q)U=q.value,_=B+5+q.consumed;else _=B+5;let j=Y(X,"auth","endauth",_);if(j===-1){console.warn(`[stx] @auth directive at position ${B} has no matching @endauth \u2014 the block was skipped.`);break}let H=X.slice(_,j),L=Q(H,"auth","endauth"),F;if(!Z.auth)F=!1;else F=U?q1(`auth?.check && auth?.user?.[${U}]`,Z):q1("auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),N=H.slice(L+5);O=F?V:N}else O=F?H:"";X=X.substring(0,B)+O+X.substring(j+8),K=!0}}{let K=!0;while(K){K=!1;let W=X.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!W||W.index===void 0)break;let B=W.index,U,_,z=X.slice(B+6),q=JY(z);if(q)U=q.value,_=B+6+q.consumed;else _=B+6;let j=Y(X,"guest","endguest",_);if(j===-1){console.warn(`[stx] @guest directive at position ${B} has no matching @endguest \u2014 the block was skipped.`);break}let H=X.slice(_,j),L=Q(H,"guest","endguest"),F;if(!Z.auth)F=!0;else F=U?q1(`!auth?.check || !auth?.user?.[${U}]`,Z):q1("!auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),N=H.slice(L+5);O=F?V:N}else O=F?H:"";X=X.substring(0,B)+O+X.substring(j+9),K=!0}}function J(K,W,B){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(W)U.push(W);if(B){let _=q1(B,Z);U.push(_)}return Z.permissions.check(...U)}catch{return!1}return!1}function G(K){let W=K.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!W)return null;return{ability:W[1],type:W[2],id:W[3]?.trim(),paramsEnd:W[0].length}}for(let K of["can","cannot"]){let W=`end${K}`,B=K==="can"?"elsecan":"elsecannot",U=!0;while(U){U=!1;let _=X.match(new RegExp(`@${K}\\s*\\(`));if(!_||_.index===void 0)break;let z=_.index,q=X.slice(z+`@${K}`.length),j=G(q);if(!j)break;let H=z+`@${K}`.length+j.paramsEnd,L=Y(X,K,W,H);if(L===-1){console.warn(`[stx] @${K} directive at position ${z} has no matching @${W} \u2014 the block was skipped.`);break}let F=X.slice(H,L),O=[],V=0,N=new RegExp(`@${K}\\s*\\(`,"g"),A=new RegExp(`@${W}(?![a-z])`,"g"),w=new RegExp(`@${B}\\s*\\(`,"g"),R=/@else(?![a-z])/g,M=[],I;while((I=N.exec(F))!==null)M.push({pos:I.index,type:"open"});while((I=A.exec(F))!==null)M.push({pos:I.index,type:"close"});while((I=w.exec(F))!==null)M.push({pos:I.index,type:"elseDirective"});while((I=R.exec(F))!==null)M.push({pos:I.index,type:"else"});M.sort((C,y)=>C.pos-y.pos);for(let C of M){if(C.type==="open"){V++;continue}if(C.type==="close"){V--;continue}if(V===0)O.push(C)}let E=[],k=0;for(let C=0;C<O.length;C++){let y=O[C];if(E.push({content:F.slice(k,y.pos),ability:void 0}),y.type==="elseDirective"){let u=F.slice(y.pos+`@${B}`.length),f=G(u);if(f){E[E.length-1]={content:F.slice(k,y.pos)},k=y.pos+`@${B}`.length+f.paramsEnd,E.push({content:"",ability:f.ability,type:f.type,id:f.id}),E.pop();let m=O[C+1],s=m?m.pos:F.length;E.push({content:F.slice(k,s),ability:f.ability,type:f.type,id:f.id}),k=s}}else k=y.pos+5}if(k<F.length){let C=E[E.length-1];if(O.length>0&&O[O.length-1].type==="else")E.push({content:F.slice(k),isFinalElse:!0});else if(E.length===0)E.push({content:F.slice(k)})}let D=J(j.ability,j.type,j.id),P=K==="can"?D:!D,S="";if(P)S=E[0]?.content||"";else{let C=!1;for(let y=1;y<E.length;y++){let u=E[y];if(u.isFinalElse){S=u.content,C=!0;break}if(u.ability){let f=J(u.ability,u.type,u.id);if(K==="can"?f:!f){S=u.content,C=!0;break}}}if(!C&&E.length>0){let y=E[E.length-1];if(y.isFinalElse)S=y.content}}X=X.substring(0,z)+S+X.substring(L+`@${W}`.length),U=!0}}return X}function y6($,Z,X){let Y=$;function Q(J,G,K,W,B){let U=!0;while(U){U=!1;let _=new RegExp(`@${G}\\s*\\(`),z=J.match(_);if(!z||z.index===void 0)break;let q=z.index,j=j1(J,q+`@${G}`.length);if(!j)break;let H=j.endPos,L=h1(J,G,K,H);if(L===-1){console.warn(`[stx] @${G} directive at position ${q} has no matching @${K} \u2014 the block was skipped.`);break}let F=J.slice(H,L),O=j.expression,V=-1,N=0,A=0;while(A<F.length){let w=F.indexOf("@",A);if(w===-1)break;let R=F.substring(w);if(/^@(?:if|unless|isset|empty)\s*\(/.test(R)){N++,A=w+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(R)){N--,A=w+1;continue}if(N===0&&/^@else(?![a-z])/.test(R)){V=w;break}A=w+1}try{let w=W(O.trim()),R;if(V!==-1){let M=F.slice(0,V),I=F.slice(V+5);R=w?M:I}else R=w?F:"";J=J.substring(0,q)+R+J.substring(L+`@${K}`.length),U=!0}catch(w){let R=w instanceof Error?w.message:String(w),M=n(B,`Error processing @${G} directive: ${R}`,i.EVALUATION_ERROR);J=J.substring(0,q)+M+J.substring(L+`@${K}`.length);break}}return J}return Y=Q(Y,"isset","endisset",(J)=>{let G=q1(J,Z);return G!==void 0&&G!==null},"Isset"),Y=Q(Y,"empty","endempty",(J)=>{let G=q1(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"),Y}function x6($,Z,X){let Y=$,Q="development";function J(G,K,W,B){let U=new RegExp(`@${K}(?![a-z])`,"g"),_=new RegExp(`@${W}(?![a-z])`,"g"),z=new RegExp(`^@${K}(?![a-z])`),q=new RegExp(`^@${W}(?![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,B=Q===D[2]}let V=1,N=O,A=-1;while(V>0&&N<j.length){U.lastIndex=N,_.lastIndex=N;let D=U.exec(j),P=_.exec(j),S=D?D.index:1/0,C=P?P.index:1/0;if(S<C)V++,N=S+D[0].length;else if(C<1/0){if(V--,V===0){A=C;break}N=C+P[0].length}else break}if(A===-1){console.warn(`[stx] @${K} directive at position ${F} has no matching @${W} \u2014 the block was skipped.`);break}let w=j.substring(O,A),R=-1,M=0,I=0;while(I<w.length){let D=w.indexOf("@",I);if(D===-1)break;let P=w.substring(D);if(z.test(P)){M++,I=D+1;continue}if(q.test(P)){M--,I=D+1;continue}if(M===0&&/^@else(?![a-z])/.test(P)){R=D;break}I=D+1}let E;if(R!==-1){let D=w.slice(0,R),P=w.slice(R+5);E=B?D:P}else E=B?w:"";let k=`@${W}`.length;j=j.substring(0,F)+E+j.substring(A+k),H=!0}return j}return Y=J(Y,"env","endenv",!1),Y=J(Y,"production","endproduction",Q==="production"),Y=J(Y,"development","enddevelopment",Q==="development"),Y=J(Y,"staging","endstaging",Q==="staging"),Y=J(Y,"testing","endtesting",Q==="testing"),Y}var F7=T(()=>{C6();g0();W5();L0()});function GY($=16){let Z=new Uint8Array($);return crypto.getRandomValues(Z),btoa(String.fromCharCode(...Z))}function V7($,Z){if(!$)return Z?.nonceGenerator?.()??GY();let X=QY.get($);if(!X)X=Z?.nonceGenerator?.()??GY(),QY.set($,X);return X}function dU($,Z){let X=[];for(let[Y,Q]of Object.entries($)){if(Q===void 0||Q===null)continue;if(typeof Q==="boolean"){if(Q)X.push(Y);continue}if(Array.isArray(Q)){let J=[...Q];if(Z&&(Y==="script-src"||Y==="style-src"))J=J.filter((G)=>!G.startsWith("'nonce-")),J.push(`'nonce-${Z}'`);if(J.length>0)X.push(`${Y} ${J.join(" ")}`)}}return X.join("; ")}function KY($,Z){return`<meta http-equiv="Content-Security-Policy" content="${dU($,Z).replace(/&/g,"&").replace(/"/g,""")}">`}function WY($,Z,X){if(!Z.enabled||!Z.addMetaTag)return $;if($.includes('http-equiv="Content-Security-Policy"'))return $;if(!$.includes("<head>")&&!$.includes("<head "))return $;let Y=Z.useNonce?V7(X,Z):void 0,Q=KY(Z.directives,Y);return $.replace(/<head([^>]*)>/,`<head$1>
|
|
2678
|
+
`+Q.slice(G);else Q+=J;return Q}function kU($,Z){let X=$;for(let Y of Z){let J=new RegExp(`<[a-z][a-z0-9-]*\\s+[^>]*data-stx-scope="([^"]*)"[^>]*x-data\\s*=\\s*["']${j7(Y.stateExpr)}["']`,"gi").exec(X);if(J)Y.id=J[1],Y.selector=`[data-stx-scope="${Y.id}"]`;else{let K=new RegExp(`<[a-z][a-z0-9-]*\\s+[^>]*x-data\\s*=\\s*["']${j7(Y.stateExpr)}["'][^>]*data-stx-scope="([^"]*)"`,"gi").exec(X);if(K)Y.id=K[1],Y.selector=`[data-stx-scope="${Y.id}"]`;else X=X.replace(new RegExp(`(<[a-z][a-z0-9-]*\\s+)([^>]*)(x-data\\s*=\\s*"${j7(Y.stateExpr)}")([^>]*>)`,"gi"),`$1data-stx-scope="${Y.id}" $2$3$4`),X=X.replace(new RegExp(`(<[a-z][a-z0-9-]*\\s+)([^>]*)(x-data\\s*=\\s*'${j7(Y.stateExpr)}')([^>]*>)`,"gi"),`$1data-stx-scope="${Y.id}" $2$3$4`)}}return X=X.replace(/\s*x-data\s*=\s*"([^"]*)"/g,' data-stx-xdata="$1"'),X=X.replace(/\s*x-data\s*=\s*'([^']*)'/g," data-stx-xdata='$1'"),X=X.replace(/\s*x-init\s*=\s*"[^"]*"/g,""),X=X.replace(/\s*x-init\s*=\s*'[^']*'/g,""),X}function SU($){return/x-data\s*=\s*["']/.test($)}var aX=0,wU=0;var eX=T(()=>{M0()});import CU from"fs";import k6 from"path";import{createHighlighter as bU}from"ts-syntax-highlighter";async function O7($,Z={}){try{if(!await c($))throw Error(`Markdown file not found: ${$}`);let Y=(await CU.promises.stat($)).mtime.getTime();if(Z.cache&&S6.has($)){let _=S6.get($);if(_.updatedAt>=Y)return{content:_.content,data:_.data}}let Q=await Bun.file($).text(),{data:J,content:G}=CZ(Q),K=Z.markdown||W$.markdown||{enabled:!0,syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}},B=v$(G,{gfm:!0});if(K.syntaxHighlighting?.enabled&&K.syntaxHighlighting?.serverSide)B=await PU(B,K.syntaxHighlighting?.defaultTheme||"github-dark",K.syntaxHighlighting?.highlightUnknownLanguages||!1);let U={content:B,data:J||{}};if(Z.cache)S6.set($,{...U,updatedAt:Y});return U}catch(X){if(Z.debug)console.error(`Error reading/parsing markdown file ${$}:`,X);let Y=X instanceof Error?X.message:String(X);return{content:Q0("Markdown File",`Error reading/parsing markdown file: ${Y}`,$,"",0,""),data:{}}}}async function PU($,Z,X){let Y=/<pre><code( class="language-([^"]+)")?>([^<]+)<\/code><\/pre>/g;if(!H7)try{H7=await bU({theme:Z||"github-dark",cache:!0})}catch(K){return console.error("Failed to initialize ts-syntax-highlighter:",K),$}let Q=async(K,W,B,U)=>{let _=U.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'"),z=B||(X?"text":"");if(!z)return K;try{if(!H7.getSupportedLanguages().includes(z))return K;return(await H7.highlight(_,z,{theme:Z})).html}catch(q){console.error(`Error highlighting code block with language ${B}:`,q)}return K},J=$,G=$.matchAll(Y);for(let K of G){let[W,B,U,_]=K,z=await Q(W,B,U,_);J=J.replace(W,z)}return J}async function $Y($,Z,X="",Y={}){return await yU($,/@markdown-file\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\{[^}]*\}))?\)/g,async(G,K,W,B)=>{try{let U=K;if(!k6.isAbsolute(K))U=k6.resolve(k6.dirname(X),K);let _={};if(W)try{try{_=JSON.parse(W)}catch{if(Y.debug)console.warn("Using safer alternative for parsing JS object literal");let O=W.replace(/^\s*\{|\}\s*$/g,"").trim().split(/,(?=\s*\w+\s*:)/);for(let V of O){let N=V.indexOf(":");if(N>0){let A=V.substring(0,N).trim(),w=V.substring(N+1).trim(),R=w.startsWith('"')&&w.endsWith('"'),M=w.startsWith("'")&&w.endsWith("'");if(R||M)w=w.substring(1,w.length-1);_[A]=w}}}}catch(F){if(Y.debug)console.error("Error parsing context in @markdown-file directive:",F)}let{content:z,data:q}=await O7(U,Y),j={...Z,...q,..._},H=z,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 _=U instanceof Error?U.message:String(U);return Q0("Markdown File",`Error including markdown file: ${_}`,X,$,B,G)}})}async function yU($,Z,X){let Y=[],Q;while((Q=Z.exec($))!==null){let K=Q[0],W=Q.index,B=Q;Y.push(X(...B).then((U)=>({match:K,replacement:U,index:W})))}let J=await Promise.all(Y);J.sort((K,W)=>W.index-K.index);let G=$;for(let{match:K,replacement:W}of J)G=G.replace(K,()=>W);return G}var S6,H7=null;var B$=T(()=>{E0();J0();S6=new Map});function q1($,Z){try{let X=$.trim();if(Z0(X))return X0(X,Object.keys(Z))(...Object.values(Z));else return $0(X,Z)}catch{return!1}}var C6=T(()=>{L0()});function C0($,Z,X,Y=0){let Q=0,J=Y,G=null,K=0,W=!1;while(J<$.length){let B=$[J];if(G&&W){W=!1,J++;continue}if(G&&B==="\\"){W=!0,J++;continue}if(W=!1,(B==='"'||B==="'"||B==="`")&&!G){G=B,J++;continue}if(B===G&&G!=="`"){G=null,J++;continue}if(G==="`"&&B==="$"&&$[J+1]==="{"){K++,J+=2;continue}if(K>0&&B==="}"){K--,J++;continue}if(B==="`"&&G==="`"&&K===0){G=null,J++;continue}if(G){J++;continue}if(B===Z)Q++;else if(B===X){if(Q--,Q===0)return J}J++}return-1}function j1($,Z){let X=xU($,Z);return X.ok?{expression:X.expression,endPos:X.endPos}:null}function xU($,Z){let X=Z;while(X<$.length&&/\s/.test($[X]))X++;if($[X]!=="(")return{ok:!1,reason:"missing-open-paren",pos:X};let Y=C0($,"(",")",X);if(Y===-1)return{ok:!1,reason:"unclosed-paren",pos:X};return{ok:!0,expression:$.slice(X+1,Y),endPos:Y+1}}function h1($,Z,X,Y){let Q=1,J=Y,G=new RegExp(`@${Z}\\s*\\(`,"g"),K=new RegExp(`@${X}(?![a-z])`,"g");while(J<$.length&&Q>0){G.lastIndex=J,K.lastIndex=J;let W=G.exec($),B=K.exec($),U=W?W.index:1/0,_=B?B.index:1/0;if(U<_)Q++,J=U+W[0].length;else if(_<1/0){if(Q--,Q===0)return _;J=_+B[0].length}else break}return-1}function ZY($,Z){let X=$.slice(Z).match(/^@if\s*/);if(!X)return null;let Y=Z+X[0].length,Q=j1($,Y);if(!Q)return null;let J=Q.endPos,G=h1($,"if","endif",J);if(G===-1)return null;let K=$.slice(J,G),W=[],B=0,U="if",_=Q.expression,z=0,q=0;while(B<K.length){let j=K.indexOf("@",B);if(j===-1)break;B=j;let H=K.substring(j);if(/^@if\s*\(/.test(H)){q++,B++;continue}if(/^@endif(?![a-z])/.test(H)){q--,B+=6;continue}if(q===0){let L=H.match(/^@elseif\s*/);if(L){W.push({type:U,condition:_,content:K.substring(z,B),start:J+z,end:J+B});let F=B+L[0].length,O=j1(K,F);if(!O){B++;continue}U="elseif",_=O.expression,B=O.endPos,z=B;continue}else if(/^@else(?![a-z])/.test(H)){W.push({type:U,condition:_,content:K.substring(z,B),start:J+z,end:J+B}),U="else",_=void 0,B+=5,z=B;continue}}B++}return W.push({type:U,condition:_,content:K.slice(z),start:J+z,end:J+K.length}),{fullMatch:$.slice(Z,G+6),branches:W,start:Z,end:G+6}}function K5($){let Z=[],X=/@if\s*\(/g,Y=X.exec($);while(Y!==null){if(Z.some((G)=>Y.index>G.start&&Y.index<G.end)){Y=X.exec($);continue}let J=ZY($,Y.index);if(J)Z.push(J),X.lastIndex=J.end;Y=X.exec($)}return Z}function L7($,Z,X){let Y=[],Q=new RegExp(`@${Z}\\s*\\(`,"g"),J=Q.exec($);while(J!==null){if(Y.some((H)=>J.index>H.start&&J.index<H.end)){J=Q.exec($);continue}let K=J.index,W=K+J[0].length-1,B=C0($,"(",")",W);if(B===-1){J=Q.exec($);continue}let U=$.slice(W+1,B),_=B+1,z=h1($,Z,X,_);if(z===-1){J=Q.exec($);continue}let q=$.slice(_,z),j=z+`@${X}`.length;Y.push({fullMatch:$.slice(K,j),name:Z,params:U,content:q,start:K,end:j}),Q.lastIndex=j,J=Q.exec($)}return Y}function b6($,Z){let X=$.slice(Z).match(/^@switch\s*/);if(!X)return null;let Y=Z+X[0].length,Q=j1($,Y);if(!Q)return null;let J=Q.endPos,G=h1($,"switch","endswitch",J);if(G===-1)return null;let K=$.slice(J,G),W=[],B=0,U=null,_=0;while(B<K.length){let z=K.slice(B),q=z.match(/^@switch\s*\(/),j=z.match(/^@endswitch(?![a-z])/);if(q){if(_++,U)U.content+=q[0];B+=q[0].length;continue}if(j){if(_--,U)U.content+=j[0];B+=j[0].length;continue}if(_>0){if(U)U.content+=K[B];B++;continue}let H=z.match(/^@case\s*/),L=z.match(/^@default(?![a-z])/),F=z.match(/^@break(?![a-z])/);if(H&&z.startsWith("@case")){if(U)W.push(U);let O=B+H[0].length,V=j1(K,O);if(!V){B++;continue}U={type:"case",value:V.expression,content:""},B=V.endPos}else if(L&&z.startsWith("@default")){if(U)W.push(U);U={type:"default",content:""},B+=L[0].length}else if(F&&z.startsWith("@break"))B+=F[0].length;else{if(U)U.content+=K[B];B++}}if(U)W.push(U);return{fullMatch:$.slice(Z,G+10),expression:Q.expression,cases:W,start:Z,end:G+10}}var XY=()=>{};var YY=()=>{};var W5=T(()=>{XY();YY()});function hU($,Z,X){let Y=$,Q=!0;while(Q){Q=!1;let J=Y.match(/@switch\s*\(/);if(!J||J.index===void 0)break;let G=J.index,K=b6(Y,G);if(!K)break;try{let W;if(Z0(K.expression))W=X0(K.expression,Object.keys(Z))(...Object.values(Z));else W=$0(K.expression,Z);let B="",U=!1;for(let _ of K.cases)if(_.type==="default"){if(!U)B=_.content.trim()}else try{let z;if(_.value&&Z0(_.value))z=X0(_.value,Object.keys(Z))(...Object.values(Z));else if(_.value)z=$0(_.value,Z);if(W===z){B=_.content.trim(),U=!0;break}}catch{continue}Y=Y.substring(0,G)+B+Y.substring(K.end),Q=!0}catch(W){let B=W instanceof Error?W.message:String(W),U=n("Switch",`Error evaluating @switch expression: ${B}`,i.EVALUATION_ERROR);Y=Y.substring(0,G)+U+Y.substring(K.end);break}}return Y}function d1($,Z,X){let Y=$;Y=hU(Y,Z,X);{let J=!0;while(J){J=!1;let G=Y.match(/@unless\s*\(/);if(!G||G.index===void 0)break;let K=G.index,W=j1(Y,K+7);if(!W)break;let B=W.endPos,U=h1(Y,"unless","endunless",B);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 _=Y.slice(B,U),z=W.expression,q=-1;{let H=0,L=/@(?:if|unless)\s*\(/g,F=/@(?:endif|endunless)(?![a-z])/g,O=/@else(?![a-z])/g,V=[],N;while((N=L.exec(_))!==null)V.push({pos:N.index,type:"open"});while((N=F.exec(_))!==null)V.push({pos:N.index,type:"close"});while((N=O.exec(_))!==null)V.push({pos:N.index,type:"else"});V.sort((A,w)=>A.pos-w.pos);for(let A of V)if(A.type==="open")H++;else if(A.type==="close")H--;else if(A.type==="else"&&H===0){q=A.pos;break}}let j;if(q!==-1){let H=_.slice(0,q),L=_.slice(q+5);j=`@if (${z})${L}@else ${H}@endif`}else j=`@if (!(${z}))${_}@endif`;Y=Y.substring(0,K)+j+Y.substring(U+10),J=!0}}Y=y6(Y,Z,X),Y=x6(Y,Z,X),Y=P6(Y,Z);let Q=()=>{let J=K5(Y);if(J.length===0)return!1;for(let G=J.length-1;G>=0;G--){let K=J[G];try{let W="",B=!1;for(let U of K.branches){if(B)break;if(U.type==="else")W=U.content,B=!0;else try{let _;if(U.condition&&Z0(U.condition))_=X0(U.condition,Object.keys(Z))(...Object.values(Z));else if(U.condition)_=$0(U.condition,Z);if(_)W=U.content,B=!0}catch(_){W=n(U.type==="if"?"If":"Elseif",`Error in @${U.type}(${U.condition}): ${_ instanceof Error?_.message:String(_)}`,i.EVALUATION_ERROR),B=!0}}Y=Y.substring(0,K.start)+W+Y.substring(K.end)}catch(W){let B=W instanceof Error?W.message:String(W),U=n("If",`Error processing @if block: ${B}`,i.EVALUATION_ERROR);Y=Y.substring(0,K.start)+U+Y.substring(K.end)}}return!0};while(!0){let J=Y;if(!Q())break;if(Y===J)break}return Y}function JY($){let Z=0;while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!=="(")return null;Z++;while(Z<$.length&&/\s/.test($[Z]))Z++;let X=$[Z];if(X!=="'"&&X!=='"')return null;Z++;let Y=[];while(Z<$.length){let Q=$[Z];if(Q==="\\"&&Z+1<$.length){Y.push($[Z+1]),Z+=2;continue}if(Q===X){Z++;break}Y.push(Q),Z++}while(Z<$.length&&/\s/.test($[Z]))Z++;if($[Z]!==")")return null;return Z++,{value:Y.join(""),consumed:Z}}function P6($,Z){let X=$;function Y(K,W,B,U){let _=1,z=U,q=new RegExp(`@${W}(?:\\s*\\(|\\s|$)`,"g"),j=new RegExp(`@${B}(?![a-z])`,"g");while(z<K.length&&_>0){q.lastIndex=z,j.lastIndex=z;let H=q.exec(K),L=j.exec(K),F=H?H.index:1/0,O=L?L.index:1/0;if(F<O)_++,z=F+H[0].length;else if(O<1/0){if(_--,_===0)return O;z=O+L[0].length}else break}return-1}function Q(K,W,B){let U=0,_=new RegExp(`@${W}(?:\\s*\\(|\\s|$)`,"g"),z=new RegExp(`@${B}(?![a-z])`,"g"),q=/@else(?![a-z])/g,j=[],H;while((H=_.exec(K))!==null)j.push({pos:H.index,type:"open"});while((H=z.exec(K))!==null)j.push({pos:H.index,type:"close"});while((H=q.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 W=X.match(/@auth(?:\s*\(|\s|(?=\n))/);if(!W||W.index===void 0)break;let B=W.index,U,_,z=X.slice(B+5),q=JY(z);if(q)U=q.value,_=B+5+q.consumed;else _=B+5;let j=Y(X,"auth","endauth",_);if(j===-1){console.warn(`[stx] @auth directive at position ${B} has no matching @endauth \u2014 the block was skipped.`);break}let H=X.slice(_,j),L=Q(H,"auth","endauth"),F;if(!Z.auth)F=!1;else F=U?q1(`auth?.check && auth?.user?.[${U}]`,Z):q1("auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),N=H.slice(L+5);O=F?V:N}else O=F?H:"";X=X.substring(0,B)+O+X.substring(j+8),K=!0}}{let K=!0;while(K){K=!1;let W=X.match(/@guest(?:\s*\(|\s|(?=\n))/);if(!W||W.index===void 0)break;let B=W.index,U,_,z=X.slice(B+6),q=JY(z);if(q)U=q.value,_=B+6+q.consumed;else _=B+6;let j=Y(X,"guest","endguest",_);if(j===-1){console.warn(`[stx] @guest directive at position ${B} has no matching @endguest \u2014 the block was skipped.`);break}let H=X.slice(_,j),L=Q(H,"guest","endguest"),F;if(!Z.auth)F=!0;else F=U?q1(`!auth?.check || !auth?.user?.[${U}]`,Z):q1("!auth?.check",Z);let O;if(L!==-1){let V=H.slice(0,L),N=H.slice(L+5);O=F?V:N}else O=F?H:"";X=X.substring(0,B)+O+X.substring(j+9),K=!0}}function J(K,W,B){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(W)U.push(W);if(B){let _=q1(B,Z);U.push(_)}return Z.permissions.check(...U)}catch{return!1}return!1}function G(K){let W=K.match(/^\s*\(\s*'([^']*)'(?:,\s*'([^']*)')?(?:,\s*([^)]*))?\)/);if(!W)return null;return{ability:W[1],type:W[2],id:W[3]?.trim(),paramsEnd:W[0].length}}for(let K of["can","cannot"]){let W=`end${K}`,B=K==="can"?"elsecan":"elsecannot",U=!0;while(U){U=!1;let _=X.match(new RegExp(`@${K}\\s*\\(`));if(!_||_.index===void 0)break;let z=_.index,q=X.slice(z+`@${K}`.length),j=G(q);if(!j)break;let H=z+`@${K}`.length+j.paramsEnd,L=Y(X,K,W,H);if(L===-1){console.warn(`[stx] @${K} directive at position ${z} has no matching @${W} \u2014 the block was skipped.`);break}let F=X.slice(H,L),O=[],V=0,N=new RegExp(`@${K}\\s*\\(`,"g"),A=new RegExp(`@${W}(?![a-z])`,"g"),w=new RegExp(`@${B}\\s*\\(`,"g"),R=/@else(?![a-z])/g,M=[],I;while((I=N.exec(F))!==null)M.push({pos:I.index,type:"open"});while((I=A.exec(F))!==null)M.push({pos:I.index,type:"close"});while((I=w.exec(F))!==null)M.push({pos:I.index,type:"elseDirective"});while((I=R.exec(F))!==null)M.push({pos:I.index,type:"else"});M.sort((C,y)=>C.pos-y.pos);for(let C of M){if(C.type==="open"){V++;continue}if(C.type==="close"){V--;continue}if(V===0)O.push(C)}let E=[],k=0;for(let C=0;C<O.length;C++){let y=O[C];if(E.push({content:F.slice(k,y.pos),ability:void 0}),y.type==="elseDirective"){let u=F.slice(y.pos+`@${B}`.length),f=G(u);if(f){E[E.length-1]={content:F.slice(k,y.pos)},k=y.pos+`@${B}`.length+f.paramsEnd,E.push({content:"",ability:f.ability,type:f.type,id:f.id}),E.pop();let m=O[C+1],s=m?m.pos:F.length;E.push({content:F.slice(k,s),ability:f.ability,type:f.type,id:f.id}),k=s}}else k=y.pos+5}if(k<F.length){let C=E[E.length-1];if(O.length>0&&O[O.length-1].type==="else")E.push({content:F.slice(k),isFinalElse:!0});else if(E.length===0)E.push({content:F.slice(k)})}let D=J(j.ability,j.type,j.id),P=K==="can"?D:!D,S="";if(P)S=E[0]?.content||"";else{let C=!1;for(let y=1;y<E.length;y++){let u=E[y];if(u.isFinalElse){S=u.content,C=!0;break}if(u.ability){let f=J(u.ability,u.type,u.id);if(K==="can"?f:!f){S=u.content,C=!0;break}}}if(!C&&E.length>0){let y=E[E.length-1];if(y.isFinalElse)S=y.content}}X=X.substring(0,z)+S+X.substring(L+`@${W}`.length),U=!0}}return X}function y6($,Z,X){let Y=$;function Q(J,G,K,W,B){let U=!0;while(U){U=!1;let _=new RegExp(`@${G}\\s*\\(`),z=J.match(_);if(!z||z.index===void 0)break;let q=z.index,j=j1(J,q+`@${G}`.length);if(!j)break;let H=j.endPos,L=h1(J,G,K,H);if(L===-1){console.warn(`[stx] @${G} directive at position ${q} has no matching @${K} \u2014 the block was skipped.`);break}let F=J.slice(H,L),O=j.expression,V=-1,N=0,A=0;while(A<F.length){let w=F.indexOf("@",A);if(w===-1)break;let R=F.substring(w);if(/^@(?:if|unless|isset|empty)\s*\(/.test(R)){N++,A=w+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(R)){N--,A=w+1;continue}if(N===0&&/^@else(?![a-z])/.test(R)){V=w;break}A=w+1}try{let w=W(O.trim()),R;if(V!==-1){let M=F.slice(0,V),I=F.slice(V+5);R=w?M:I}else R=w?F:"";J=J.substring(0,q)+R+J.substring(L+`@${K}`.length),U=!0}catch(w){let R=w instanceof Error?w.message:String(w),M=n(B,`Error processing @${G} directive: ${R}`,i.EVALUATION_ERROR);J=J.substring(0,q)+M+J.substring(L+`@${K}`.length);break}}return J}return Y=Q(Y,"isset","endisset",(J)=>{let G=q1(J,Z);return G!==void 0&&G!==null},"Isset"),Y=Q(Y,"empty","endempty",(J)=>{let G=q1(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"),Y}function x6($,Z,X){let Y=$,Q="development";function J(G,K,W,B){let U=new RegExp(`@${K}(?![a-z])`,"g"),_=new RegExp(`@${W}(?![a-z])`,"g"),z=new RegExp(`^@${K}(?![a-z])`),q=new RegExp(`^@${W}(?![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,B=Q===D[2]}let V=1,N=O,A=-1;while(V>0&&N<j.length){U.lastIndex=N,_.lastIndex=N;let D=U.exec(j),P=_.exec(j),S=D?D.index:1/0,C=P?P.index:1/0;if(S<C)V++,N=S+D[0].length;else if(C<1/0){if(V--,V===0){A=C;break}N=C+P[0].length}else break}if(A===-1){console.warn(`[stx] @${K} directive at position ${F} has no matching @${W} \u2014 the block was skipped.`);break}let w=j.substring(O,A),R=-1,M=0,I=0;while(I<w.length){let D=w.indexOf("@",I);if(D===-1)break;let P=w.substring(D);if(z.test(P)){M++,I=D+1;continue}if(q.test(P)){M--,I=D+1;continue}if(M===0&&/^@else(?![a-z])/.test(P)){R=D;break}I=D+1}let E;if(R!==-1){let D=w.slice(0,R),P=w.slice(R+5);E=B?D:P}else E=B?w:"";let k=`@${W}`.length;j=j.substring(0,F)+E+j.substring(A+k),H=!0}return j}return Y=J(Y,"env","endenv",!1),Y=J(Y,"production","endproduction",Q==="production"),Y=J(Y,"development","enddevelopment",Q==="development"),Y=J(Y,"staging","endstaging",Q==="staging"),Y=J(Y,"testing","endtesting",Q==="testing"),Y}var F7=T(()=>{C6();g0();W5();L0()});function GY($=16){let Z=new Uint8Array($);return crypto.getRandomValues(Z),btoa(String.fromCharCode(...Z))}function V7($,Z){if(!$)return Z?.nonceGenerator?.()??GY();let X=QY.get($);if(!X)X=Z?.nonceGenerator?.()??GY(),QY.set($,X);return X}function dU($,Z){let X=[];for(let[Y,Q]of Object.entries($)){if(Q===void 0||Q===null)continue;if(typeof Q==="boolean"){if(Q)X.push(Y);continue}if(Array.isArray(Q)){let J=[...Q];if(Z&&(Y==="script-src"||Y==="style-src"))J=J.filter((G)=>!G.startsWith("'nonce-")),J.push(`'nonce-${Z}'`);if(J.length>0)X.push(`${Y} ${J.join(" ")}`)}}return X.join("; ")}function KY($,Z){return`<meta http-equiv="Content-Security-Policy" content="${dU($,Z).replace(/&/g,"&").replace(/"/g,""")}">`}function WY($,Z,X){if(!Z.enabled||!Z.addMetaTag)return $;if($.includes('http-equiv="Content-Security-Policy"'))return $;if(!$.includes("<head>")&&!$.includes("<head "))return $;let Y=Z.useNonce?V7(X,Z):void 0,Q=KY(Z.directives,Y);return $.replace(/<head([^>]*)>/,`<head$1>
|
|
2679
2679
|
${Q}`)}function UY($,Z,X,Y){let Q=$,J=Y.csp;if(Q=Q.replace(/@csp\b/g,()=>{if(!J?.enabled||!J.directives)return"<!-- CSP not configured -->";let G=J.useNonce?V7(Z,J):void 0;return KY(J.directives,G)}),Q=Q.replace(/@cspNonce\b/g,()=>{if(!J?.enabled||!J.useNonce)return"";return V7(Z,J)}),J?.enabled&&J.useNonce)Z.cspNonce=V7(Z,J);return Q}var QY;var v6=T(()=>{QY=new WeakMap});import uU from"crypto";function pU($=mU){let Z=uU.randomBytes(Math.ceil($/2)).toString("hex").slice(0,$);return f6=Z,Z}function cU(){if(!f6)pU();return f6}function lU($=BY){let Z=cU();return`<input type="hidden" name="${$}" value="${Z}">`}function _Y($){return $.replace(/@csrf(?:\((['"])([^'"]*)\1\))?/g,(Z,X,Y)=>{return lU(Y||BY)})}var mU=40,BY="_token",f6=null;var zY=()=>{};async function qY($,Z,X,Y){if(!Y.customDirectives||Y.customDirectives.length===0)return $;let Q=$;for(let J of Y.customDirectives){if(!J.name||typeof J.handler!=="function"){if(Y.debug)console.warn("Invalid custom directive:",J);continue}if(J.hasEndTag)Q=await iU(Q,J,Z,X,Y);else Q=await nU(Q,J,Z,X,Y)}return Q}async function iU($,Z,X,Y,Q){let{name:J,handler:G}=Z,K=`@${J}`,W=`@end${J}`,B=$,U=J$(`${K}(?:\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\))?([\\s\\S]*?)${W}`,"g"),_=[],z=U.exec(B);while(z!==null){let[q,j="",H=""]=z,L=z.index||0;try{let F=j?jY(j):[],O=H.trim(),V=await G(O,F,X,Y);_.push({original:q,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);_.push({original:q,processed:n("CustomDirective",`Error in @${J}${j?`(${j})`:""}: ${O}`,i.EVALUATION_ERROR),startIndex:L})}z=U.exec(B)}for(let q=_.length-1;q>=0;q--){let{original:j,processed:H}=_[q];B=B.replace(j,H)}return B}async function nU($,Z,X,Y,Q){let{name:J,handler:G}=Z,K=$,W=J$(`@${J}\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\)`,"g"),B=[],U=W.exec(K);while(U!==null){let[q,j=""]=U,H=U.index||0;try{let L=jY(j),F=await G("",L,X,Y);B.push({original:q,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);B.push({original:q,processed:n("CustomDirective",`Error in @${J}(${j}): ${F}`,i.EVALUATION_ERROR),startIndex:H})}U=W.exec(K)}let _=J$(`@${J}(?!\\w)(?!\\s*\\()`,"g"),z=_.exec(K);while(z!==null){let[q]=z,j=z.index||0;try{let H=await G("",[],X,Y);B.push({original:q,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);B.push({original:q,processed:n("CustomDirective",`Error in @${J}: ${L}`,i.EVALUATION_ERROR),startIndex:j})}z=_.exec(K)}for(let q=B.length-1;q>=0;q--){let{original:j,processed:H}=B[q];K=K.replace(j,H)}return K}function jY($){if(!$.trim())return[];let Z=[],X="",Y=!1,Q="";for(let J=0;J<$.length;J++){let G=$[J];if((G==='"'||G==="'")&&(J===0||$[J-1]!=="\\"))if(!Y)Y=!0,Q=G;else if(G===Q)Y=!1;else X+=G;else if(G===","&&!Y)Z.push(X.trim()),X="";else X+=G}if(X.trim())Z.push(X.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 g6=T(()=>{g0();P1()});var h6={};t(h6,{useTitle:()=>tU,useSeoMeta:()=>A7,usePageTitle:()=>tU,useHead:()=>m1,resetHead:()=>rU,renderHtmlAttrs:()=>$B,renderHead:()=>eU,renderBodyAttrs:()=>ZB,processTitleDirective:()=>JB,processMetaDirective:()=>QB,processHeadDirective:()=>YB,getPageMeta:()=>HY,getHead:()=>U5,definePageMeta:()=>aU,applyHead:()=>XB});function U5(){return H1}function HY(){return N7}function rU(){H1={},sU.length=0,N7={}}function m1($){H1=oU(H1,$)}function oU($,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 A7($){let Z=[];if($.description)Z.push({name:"description",content:$.description});if($.keywords){let W=Array.isArray($.keywords)?$.keywords.join(", "):$.keywords;Z.push({name:"keywords",content:W})}if($.author)Z.push({name:"author",content:$.author});if($.robots)Z.push({name:"robots",content:$.robots});let X=$.ogTitle??$.title,Y=$.ogDescription??$.description;if(X)Z.push({property:"og:title",content:X});if(Y)Z.push({property:"og:description",content:Y});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 W of $.articleTags)Z.push({property:"article:tag",content:W});let K=[];if($.canonical)K.push({rel:"canonical",href:$.canonical});m1({title:$.title,titleTemplate:$.titleTemplate,meta:Z,link:K})}function aU($){if(N7={...N7,...$},$.title||$.description)A7({title:$.title,description:$.description})}function tU($){let Z=typeof $==="function"?$():$;m1({title:Z})}function eU($=H1){let Z=[];if($.title){let X=$.title;if($.titleTemplate)X=typeof $.titleTemplate==="function"?$.titleTemplate(X):$.titleTemplate.replace("%s",X);Z.push(`<title>${u1(X)}</title>`)}if($.base){let X=Object.entries($.base).map(([Y,Q])=>`${Y}="${u1(Q)}"`).join(" ");Z.push(`<base ${X}>`)}for(let X of $.meta||[]){let Y=Object.entries(X).filter(([Q,J])=>J!==void 0).map(([Q,J])=>{return`${Q==="httpEquiv"?"http-equiv":Q}="${u1(String(J))}"`}).join(" ");Z.push(`<meta ${Y}>`)}for(let X of $.link||[]){let Y=Object.entries(X).filter(([Q,J])=>J!==void 0).map(([Q,J])=>`${Q}="${u1(String(J))}"`).join(" ");Z.push(`<link ${Y}>`)}for(let X of $.script||[]){let{content:Y,...Q}=X,J=Object.entries(Q).filter(([G,K])=>K!==void 0).map(([G,K])=>{if(typeof K==="boolean")return K?G:"";return`${G}="${u1(String(K))}"`}).filter(Boolean).join(" ");if(Y)Z.push(`<script ${J}>${Y}</script>`);else Z.push(`<script ${J}></script>`)}for(let X of $.style||[]){let Y=X.type?` type="${X.type}"`:"";Z.push(`<style${Y}>${X.content}</style>`)}return Z.join(`
|
|
2680
2680
|
`)}function $B($=H1){if(!$.htmlAttrs)return"";return Object.entries($.htmlAttrs).map(([Z,X])=>`${Z}="${u1(X)}"`).join(" ")}function ZB($=H1){if(!$.bodyAttrs)return"";return Object.entries($.bodyAttrs).map(([Z,X])=>`${Z}="${u1(X)}"`).join(" ")}function u1($){return $.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function XB($=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 X=Z.name?`meta[name="${Z.name}"]`:Z.property?`meta[property="${Z.property}"]`:null;if(X){let Y=document.querySelector(X);if(!Y){if(Y=document.createElement("meta"),Z.name)Y.setAttribute("name",Z.name);if(Z.property)Y.setAttribute("property",Z.property);document.head.appendChild(Y)}Y.setAttribute("content",Z.content)}}for(let Z of $.link||[]){let X=`link[rel="${Z.rel}"]${Z.href?`[href="${Z.href}"]`:""}`,Y=document.querySelector(X);if(!Y)Y=document.createElement("link"),document.head.appendChild(Y);for(let[Q,J]of Object.entries(Z))if(J!==void 0)Y.setAttribute(Q,String(J))}if($.htmlAttrs)for(let[Z,X]of Object.entries($.htmlAttrs))document.documentElement.setAttribute(Z,X);if($.bodyAttrs)for(let[Z,X]of Object.entries($.bodyAttrs))document.body.setAttribute(Z,X)}function YB($){let Z="";return{content:$.replace(/@head\s*([\s\S]*?)@endhead/g,(Y,Q)=>{return Z+=Q.trim()+`
|
|
2681
2681
|
`,""}),headContent:Z.trim()}}function JB($,Z){return $.replace(/@title\s*\(\s*(?:(['"`])(.+?)\1|([^)]+))\s*\)/g,(X,Y,Q,J)=>{let G=Y?Q:Z[(J||"").trim()]??J;return m1({title:G}),""})}function QB($,Z){return $.replace(/@meta\s*\(\s*(['"`])(.+?)\1\s*,\s*(?:(['"`])(.+?)\3|([^)]+))\s*\)/g,(X,Y,Q,J,G,K)=>{let W=J?G:K,B=J?W:Z[(W||"").trim()]??W,_=Q.includes(":")?{property:Q,content:B}:{name:Q,content:B};return m1({meta:[_]}),""})}var H1,sU,N7;var p1=T(()=>{H1={},sU=[],N7={}});import GB from"crypto";function A0($){return String($??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function w7($,Z,X,Y){let Q=$||Z;return X?`${Q} ${Y}`:Q}function KB(){return GB.randomUUID()}function R7($,Z){let X=$;return X=X.replace(/@csrf/g,()=>{if(!Z.csrf||typeof Z.csrf!=="object"){let Y=KB();Z.csrf={token:Y}}if(Z.csrf.field)return Z.csrf.field;if(Z.csrf.token)return`<input type="hidden" name="_token" value="${A0(Z.csrf.token)}">`;return'<input type="hidden" name="_token" value="">'}),X=X.replace(/@method\(['"]([^'"]+)['"]\)/g,(Y,Q)=>{let J=Q.toUpperCase();if(Q&&!["GET","POST"].includes(J))return`<input type="hidden" name="_method" value="${A0(J)}">`;return Y}),X}function FY($,Z,X=LY){let Y=$;return Y=Y.replace(/@form\(\s*(?:(?:'([^']+)'|"([^"]+)")\s*)?(?:,\s*(?:'([^']+)'|"([^"]+)")?)?\s*(?:,\s*\{([^}]+)\}\s*)?\)/g,(Q,J,G,K,W,B="")=>{let U=J||G||"POST",_=K||W||"",z=O1(B),q=U.toUpperCase(),j=["GET","POST"].includes(q)?q:"POST",H=`<form method="${A0(j)}" action="${A0(_)}"${z?` ${z}`:""}>`;if(H+=`
|
package/dist/process.js
CHANGED
|
@@ -2509,7 +2509,7 @@ window.__stx_reactive = (function() {
|
|
|
2509
2509
|
${ZK()}
|
|
2510
2510
|
${Y}
|
|
2511
2511
|
</script>`}function g8($,Z,Y){if(f8=0,!JK($))return $;let X=aG($);if(X.length===0)return $;let Q=XK($,X),J=YK(X,Z),G=Q.lastIndexOf("</body>");if(G!==-1)Q=Q.slice(0,G)+J+`
|
|
2512
|
-
`+Q.slice(G);else Q+=J;return Q}function XK($,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*["']${N$(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*["']${N$(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*"${N$(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*'${N$(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 JK($){return/x-data\s*=\s*["']/.test($)}var f8=0,rG=0;var h8=y(()=>{c0()});import QK from"fs";import O7 from"path";import{createHighlighter as GK}from"ts-syntax-highlighter";async function KK($,Z={}){try{if(!await l($))throw Error(`Markdown file not found: ${$}`);let X=(await QK.promises.stat($)).mtime.getTime();if(Z.cache&&L7.has($)){let U=L7.get($);if(U.updatedAt>=X)return{content:U.content,data:U.data}}let Q=await Bun.file($).text(),{data:J,content:G}=Z6(Q),K=Z.markdown||U7.markdown||{enabled:!0,syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}},W=e1(G,{gfm:!0});if(K.syntaxHighlighting?.enabled&&K.syntaxHighlighting?.serverSide)W=await qK(W,K.syntaxHighlighting?.defaultTheme||"github-dark",K.syntaxHighlighting?.highlightUnknownLanguages||!1);let z={content:W,data:J||{}};if(Z.cache)L7.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 qK($,Z,Y){let X=/<pre><code( class="language-([^"]+)")?>([^<]+)<\/code><\/pre>/g;if(!T$)try{T$=await GK({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(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'"),_=W||(Y?"text":"");if(!_)return K;try{if(!T$.getSupportedLanguages().includes(_))return K;return(await T$.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 d8($,Z,Y="",X={}){return await zK($,/@markdown-file\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\{[^}]*\}))?\)/g,async(G,K,q,W)=>{try{let z=K;if(!O7.isAbsolute(K))z=O7.resolve(O7.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 KK(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 zK($,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 L7,T$=null;var m8=y(()=>{O5();H0();L7=new Map});function Y1($,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 u8=y(()=>{L0()});function X1($,Z){let Y=WK($,Z);return Y.ok?{expression:Y.expression,endPos:Y.endPos}:null}function WK($,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 M1($,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 p8($,Z){let Y=$.slice(Z).match(/^@if\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=X1($,X);if(!Q)return null;let J=Q.endPos,G=M1($,"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=X1(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 F5($){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=p8($,X.index);if(J)Z.push(J),Y.lastIndex=J.end;X=Y.exec($)}return Z}function M$($,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,_=M1($,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 F7($,Z){let Y=$.slice(Z).match(/^@switch\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=X1($,X);if(!Q)return null;let J=Q.endPos,G=M1($,"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=X1(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 l8=()=>{};var c8=()=>{};var I$=y(()=>{l8();c8()});function jK($,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=F7(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=r("Switch",`Error evaluating @switch expression: ${W}`,i.EVALUATION_ERROR);X=X.substring(0,G)+z+X.substring(K.end);break}}return X}function I1($,Z,Y){let X=$;X=jK(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=X1(X,K+7);if(!q)break;let W=q.endPos,z=M1(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=w7(X,Z,Y),X=A7(X,Z,Y),X=V7(X,Z);let Q=()=>{let J=F5(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=r(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=r("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 i8($){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 V7($,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=i8(_);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?Y1(`auth?.check && auth?.user?.[${z}]`,Z):Y1("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=i8(_);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?Y1(`!auth?.check || !auth?.user?.[${z}]`,Z):Y1("!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=Y1(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 w7($,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=X1(J,B+`@${G}`.length);if(!j)break;let H=j.endPos,L=M1(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=r(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=Y1(J,Z);return G!==void 0&&G!==null},"Isset"),X=Q(X,"empty","endempty",(J)=>{let G=Y1(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 A7($,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 D$=y(()=>{u8();a0();I$();L0()});function o8($=16){let Z=new Uint8Array($);return crypto.getRandomValues(Z),btoa(String.fromCharCode(...Z))}function E$($,Z){if(!$)return Z?.nonceGenerator?.()??o8();let Y=n8.get($);if(!Y)Y=Z?.nonceGenerator?.()??o8(),n8.set($,Y);return Y}function HK($,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 s8($,Z){return`<meta http-equiv="Content-Security-Policy" content="${HK($,Z).replace(/&/g,"&").replace(/"/g,""")}">`}function r8($,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?E$(Y,Z):void 0,Q=s8(Z.directives,X);return $.replace(/<head([^>]*)>/,`<head$1>
|
|
2512
|
+
`+Q.slice(G);else Q+=J;return Q}function XK($,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*["']${N$(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*["']${N$(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*"${N$(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*'${N$(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 JK($){return/x-data\s*=\s*["']/.test($)}var f8=0,rG=0;var h8=y(()=>{c0()});import QK from"fs";import O7 from"path";import{createHighlighter as GK}from"ts-syntax-highlighter";async function KK($,Z={}){try{if(!await l($))throw Error(`Markdown file not found: ${$}`);let X=(await QK.promises.stat($)).mtime.getTime();if(Z.cache&&L7.has($)){let U=L7.get($);if(U.updatedAt>=X)return{content:U.content,data:U.data}}let Q=await Bun.file($).text(),{data:J,content:G}=Z6(Q),K=Z.markdown||U7.markdown||{enabled:!0,syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}},W=e1(G,{gfm:!0});if(K.syntaxHighlighting?.enabled&&K.syntaxHighlighting?.serverSide)W=await qK(W,K.syntaxHighlighting?.defaultTheme||"github-dark",K.syntaxHighlighting?.highlightUnknownLanguages||!1);let z={content:W,data:J||{}};if(Z.cache)L7.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 qK($,Z,Y){let X=/<pre><code( class="language-([^"]+)")?>([^<]+)<\/code><\/pre>/g;if(!T$)try{T$=await GK({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(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'"),_=W||(Y?"text":"");if(!_)return K;try{if(!T$.getSupportedLanguages().includes(_))return K;return(await T$.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 d8($,Z,Y="",X={}){return await zK($,/@markdown-file\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\{[^}]*\}))?\)/g,async(G,K,q,W)=>{try{let z=K;if(!O7.isAbsolute(K))z=O7.resolve(O7.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 KK(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 zK($,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 L7,T$=null;var m8=y(()=>{O5();H0();L7=new Map});function Y1($,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 u8=y(()=>{L0()});function X1($,Z){let Y=WK($,Z);return Y.ok?{expression:Y.expression,endPos:Y.endPos}:null}function WK($,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 M1($,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 p8($,Z){let Y=$.slice(Z).match(/^@if\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=X1($,X);if(!Q)return null;let J=Q.endPos,G=M1($,"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=X1(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 F5($){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=p8($,X.index);if(J)Z.push(J),Y.lastIndex=J.end;X=Y.exec($)}return Z}function M$($,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,_=M1($,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 F7($,Z){let Y=$.slice(Z).match(/^@switch\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=X1($,X);if(!Q)return null;let J=Q.endPos,G=M1($,"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=X1(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 l8=()=>{};var c8=()=>{};var I$=y(()=>{l8();c8()});function jK($,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=F7(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=r("Switch",`Error evaluating @switch expression: ${W}`,i.EVALUATION_ERROR);X=X.substring(0,G)+z+X.substring(K.end);break}}return X}function I1($,Z,Y){let X=$;X=jK(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=X1(X,K+7);if(!q)break;let W=q.endPos,z=M1(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=w7(X,Z,Y),X=A7(X,Z,Y),X=V7(X,Z);let Q=()=>{let J=F5(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=r(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=r("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 i8($){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 V7($,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=i8(_);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?Y1(`auth?.check && auth?.user?.[${z}]`,Z):Y1("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=i8(_);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?Y1(`!auth?.check || !auth?.user?.[${z}]`,Z):Y1("!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=Y1(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 w7($,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=X1(J,B+`@${G}`.length);if(!j)break;let H=j.endPos,L=M1(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=r(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=Y1(J,Z);return G!==void 0&&G!==null},"Isset"),X=Q(X,"empty","endempty",(J)=>{let G=Y1(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 A7($,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 D$=y(()=>{u8();a0();I$();L0()});function o8($=16){let Z=new Uint8Array($);return crypto.getRandomValues(Z),btoa(String.fromCharCode(...Z))}function E$($,Z){if(!$)return Z?.nonceGenerator?.()??o8();let Y=n8.get($);if(!Y)Y=Z?.nonceGenerator?.()??o8(),n8.set($,Y);return Y}function HK($,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 s8($,Z){return`<meta http-equiv="Content-Security-Policy" content="${HK($,Z).replace(/&/g,"&").replace(/"/g,""")}">`}function r8($,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?E$(Y,Z):void 0,Q=s8(Z.directives,X);return $.replace(/<head([^>]*)>/,`<head$1>
|
|
2513
2513
|
${Q}`)}function a8($,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?E$(Z,J):void 0;return s8(J.directives,G)}),Q=Q.replace(/@cspNonce\b/g,()=>{if(!J?.enabled||!J.useNonce)return"";return E$(Z,J)}),J?.enabled&&J.useNonce)Z.cspNonce=E$(Z,J);return Q}var n8;var t8=y(()=>{n8=new WeakMap});import OK from"crypto";function FK($=LK){let Z=OK.randomBytes(Math.ceil($/2)).toString("hex").slice(0,$);return R7=Z,Z}function VK(){if(!R7)FK();return R7}function wK($=e8){let Z=VK();return`<input type="hidden" name="${$}" value="${Z}">`}function $Z($){return $.replace(/@csrf(?:\((['"])([^'"]*)\1\))?/g,(Z,Y,X)=>{return wK(X||e8)})}var LK=40,e8="_token",R7=null;var ZZ=()=>{};async function YZ($,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 AK(Q,J,Z,Y,X);else Q=await RK(Q,J,Z,Y,X)}return Q}async function AK($,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?XZ(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:r("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 RK($,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=XZ(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:r("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:r("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 XZ($){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 JZ=y(()=>{a0();x1()});import NK from"crypto";function F0($){return String($??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function k$($,Z,Y,X){let Q=$||Z;return Y?`${Q} ${X}`:Q}function TK(){return NK.randomUUID()}function b$($,Z){let Y=$;return Y=Y.replace(/@csrf/g,()=>{if(!Z.csrf||typeof Z.csrf!=="object"){let X=TK();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 KZ($,Z,Y=GZ){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+=`
|
|
2514
2514
|
${b$("@csrf",Z)}`,!["GET","POST"].includes(B))H+=`
|
|
2515
2515
|
${b$(`@method('${B}')`,Z)}`;return H}),X=X.replace(/@endform/g,"</form>"),X=X.replace(/@input\(\s*(?:'([^']+)'|"([^"]+)")\s*(?:,\s*(?:(?:'([^']*)'|"([^"]*)")\s*)?)?(?:,\s*\{([^}]+)\})?\s*\)/g,(Q,J,G,K,q,W="")=>{let z=J||G||"",U=K||q||"",_=J1(W),B=V5(z,Z),j=B!==void 0&&B!==null?B:U||"",H=_.match(/type=['"]([^'"]+)['"]/i),L=H?H[1]:"text",F=w5(z,Z),O=_.match(/class=['"]([^'"]+)['"]/i),V=k$(O?O[1]:"",Y.input,F,Y.inputError),w=_.replace(/class=['"][^'"]+['"]/i,"");return w=w.replace(/type=['"][^'"]+['"]/i,""),`<input type="${F0(L)}" name="${F0(z)}" value="${F0(j)}" class="${V}"${w?` ${w}`:""}>`}),X=X.replace(/@textarea\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)([\s\S]*?)@endtextarea/g,(Q,J,G="",K="")=>{let q=J1(G),W=V5(J,Z)||K.trim(),z=w5(J,Z),U=q.match(/class=['"]([^'"]+)['"]/i),_=k$(U?U[1]:"",Y.input,z,Y.inputError),B=q.replace(/class=['"][^'"]+['"]/i,"");return`<textarea name="${F0(J)}" class="${_}"${B?` ${B}`:""}>${F0(W)}</textarea>`}),X=X.replace(/@select\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)([\s\S]*?)@endselect/g,(Q,J,G="",K)=>{let q=J1(G),W=V5(J,Z),z=w5(J,Z),U=q.match(/class=['"]([^'"]+)['"]/i),_=k$(U?U[1]:"",Y.input,z,Y.inputError),B=q.replace(/class=['"][^'"]+['"]/i,""),j=K;if(W!==void 0)j=K.replace(/(<option[^>]*value=['"]([^'"]+)['"][^>]*>)/gi,(H,L,F)=>{if((Array.isArray(W)?W.some((V)=>String(V)===F):String(W)===F)&&!L.includes("selected"))return L.replace(/(<option)/,"$1 selected");return H});return`<select name="${F0(J)}" class="${_}"${B?` ${B}`:""}>${j}</select>`}),X=X.replace(/@checkbox\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?(?:,\s*\{([^}]+)\})?\)/g,(Q,J,G="1",K="")=>{let q=J1(K),W=V5(J,Z),z=W!==void 0&&(Array.isArray(W)?W.some((j)=>String(j)===G):W===!0||String(W)===G),U=q.match(/class=['"]([^'"]+)['"]/i),_=U?U[1]:Y.checkInput,B=q.replace(/class=['"][^'"]+['"]/i,"");return`<input type="checkbox" name="${F0(J)}" value="${F0(G)}" class="${_}"${z?" checked":""}${B?` ${B}`:""}>`}),X=X.replace(/@radio\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)/g,(Q,J,G,K="")=>{let q=J1(K),W=V5(J,Z),z=W!==void 0&&W===G,U=q.match(/class=['"]([^'"]+)['"]/i),_=U?U[1]:Y.checkInput,B=q.replace(/class=['"][^'"]+['"]/i,"");return`<input type="radio" name="${F0(J)}" value="${F0(G)}" class="${_}"${z?" checked":""}${B?` ${B}`:""}>`}),X=X.replace(/@file\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)/g,(Q,J,G="")=>{let K=J1(G),q=K.match(/accept=['"]([^'"]+)['"]/i),W=q?q[1]:"",z=K.includes("multiple"),U=w5(J,Z),_=K.match(/class=['"]([^'"]+)['"]/i),B=k$(_?_[1]:"",Y.input,U,Y.inputError),j=K.replace(/class=['"][^'"]+['"]/gi,"").replace(/accept=['"][^'"]+['"]/gi,"").replace(/\bmultiple\b/gi,"").trim(),H=[`<input type="file" name="${F0(J)}"`,`class="${B}"`];if(W)H.push(`accept="${F0(W)}"`);if(z)H.push("multiple");if(j)H.push(j);return`${H.join(" ")}>`}),X=X.replace(/@label\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)([\s\S]*?)@endlabel/g,(Q,J,G="",K)=>{let q=J1(G),W=q.match(/class=['"]([^'"]+)['"]/i),z=W?W[1]:Y.label,U=q.replace(/class=['"][^'"]+['"]/i,"");return`<label for="${F0(J)}" class="${z}"${U?` ${U}`:""}>${K}</label>`}),X}function qZ($,Z,Y=GZ){return $.replace(/@error\(['"]([^'"]+)['"]\)([\s\S]*?)@enderror/g,(X,Q,J)=>{try{if(w5(Q,Z))return J.replace(/\{\{([^}]+)\}\}/g,(G,K)=>{try{if(K.trim()==="$message"||K.trim()==="message")return QZ(Q,Z);if(K.trim().includes("errors.first")||K.trim().includes("$errors.first")){if(typeof Z.errors?.first==="function")return Z.errors.first(Q);return QZ(Q,Z)}let q=K.trim();if(Z0(q)){let W=$0(q,Z);return W!==void 0?String(W):q}return q}catch{return K}});return""}catch(G){return console.error("Error processing @error directive:",G),X}})}function w5($,Z){if(!Z.errors)return!1;if(typeof Z.errors.has==="function")return Z.errors.has($);if(typeof Z.errors==="object")return Object.prototype.hasOwnProperty.call(Z.errors,$);return!1}function QZ($,Z){if(!Z.errors)return"";if(typeof Z.errors.get==="function")return Z.errors.get($);if(typeof Z.errors==="object"&&Object.prototype.hasOwnProperty.call(Z.errors,$)){let Y=Z.errors[$];return Array.isArray(Y)?Y[0]:String(Y)}return""}function V5($,Z){let Y;if(Z.old&&typeof Z.old==="function")return Z.old($);if(Z.old&&typeof Z.old==="object")return Z.old[$];if($.endsWith("[]")){let X=$.slice(0,-2);if(Y=Z[X],Y!==void 0)return Y}return Z[$]}function J1($){if(!$.trim())return"";let Z=[],Y=$.trim(),X=/([\w-]+)\s*:\s*(['"]?)([^,'"]*)\2(?:\s*,\s*|\s*$)/g,Q;while((Q=X.exec(Y))!==null){let[,J,,G]=Q;Z.push(`${J}="${G.trim()}"`)}return Z.join(" ")}var GZ;var zZ=y(()=>{L0();GZ={input:"form-control",inputError:"is-invalid",checkInput:"form-check-input",label:"form-label",errorFeedback:"invalid-feedback"}});import M7 from"path";async function MK(){if(A5!==void 0)return A5;try{A5=(await import("@stacksjs/ts-i18n")).loadLocale??null}catch{A5=null}return A5}function IK($,Z=0){if(Z<=0)return!1;return Date.now()-$.loadedAt>Z}async function DK($,Z){if({...E7,...Z.i18n}.cache&&I7[$]){let Q=I7[$],J=Z.i18n?.cacheMaxAge??0;if(!IK(Q,J))return Q.translations}if(R5[$]?.state==="loading")return R5[$].promise;N7[$]="loading";let X=D7($,Z).then((Q)=>{return N7[$]="loaded",delete R5[$],Q}).catch((Q)=>{throw N7[$]="error",R5[$]={promise:X,state:"error",error:Q instanceof Error?Q:Error(String(Q))},Q});return R5[$]={promise:X,state:"loading"},X}async function D7($,Z){let Y={...E7,...Z.i18n},X=M7.isAbsolute(Y.translationsDir)?Y.translationsDir:M7.resolve(Z.root||process.cwd(),Y.translationsDir);try{let Q=await MK(),J=Q?await Q($,{translationsDir:X,defaultLocale:Y.defaultLocale,sources:yK(Y.format)}):await EK($,Y,X);if(J===void 0){if($!==Y.defaultLocale)return D7(Y.defaultLocale,Z);return{}}let G=J;if(Y.cache)I7[$]={translations:G,loadedAt:Date.now(),locale:$};return G}catch(Q){if(Z.debug)console.error(`Error loading translation file for locale "${$}":`,Q);if($!==Y.defaultLocale)return D7(Y.defaultLocale,Z);return{}}}async function EK($,Z,Y){let X=M7.join(Y,`${$}${kK(Z.format)}`);try{let Q=await import(X);return Q.default||Q}catch(Q){try{let J=await Bun.file(X).text();if(Z.format==="yaml"||Z.format==="yml")return bK(J);if(Z.format==="json")return JSON.parse(J);throw Q}catch{return}}}function kK($){switch($){case"yaml":return".yaml";case"yml":return".yml";case"js":return".js";case"ts":return".ts";case"json":default:return".json"}}function bK($){let Z={},Y=$.split(`
|
|
@@ -7718,7 +7718,7 @@ window.__stx_reactive = (function() {
|
|
|
7718
7718
|
${kK()}
|
|
7719
7719
|
${Y}
|
|
7720
7720
|
</script>`}function $Z($,Z,Y){if(e8=0,!yK($))return $;let X=MK($);if(X.length===0)return $;let Q=SK($,X),J=bK(X,Z),G=Q.lastIndexOf("</body>");if(G!==-1)Q=Q.slice(0,G)+J+`
|
|
7721
|
-
`+Q.slice(G);else Q+=J;return Q}function SK($,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*["']${f$(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*["']${f$(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*"${f$(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*'${f$(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 yK($){return/x-data\s*=\s*["']/.test($)}var e8=0,TK=0;var ZZ=b(()=>{i0()});import CK from"fs";import S7 from"path";import{createHighlighter as PK}from"ts-syntax-highlighter";async function vK($,Z={}){try{if(!await l($))throw Error(`Markdown file not found: ${$}`);let X=(await CK.promises.stat($)).mtime.getTime();if(Z.cache&&y7.has($)){let U=y7.get($);if(U.updatedAt>=X)return{content:U.content,data:U.data}}let Q=await Bun.file($).text(),{data:J,content:G}=L6(Q),K=Z.markdown||M7.markdown||{enabled:!0,syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}},W=Q5(G,{gfm:!0});if(K.syntaxHighlighting?.enabled&&K.syntaxHighlighting?.serverSide)W=await xK(W,K.syntaxHighlighting?.defaultTheme||"github-dark",K.syntaxHighlighting?.highlightUnknownLanguages||!1);let z={content:W,data:J||{}};if(Z.cache)y7.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 xK($,Z,Y){let X=/<pre><code( class="language-([^"]+)")?>([^<]+)<\/code><\/pre>/g;if(!g$)try{g$=await PK({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(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'"),B=W||(Y?"text":"");if(!B)return K;try{if(!g$.getSupportedLanguages().includes(B))return K;return(await g$.highlight(U,B,{theme:Z})).html}catch(_){console.error(`Error highlighting code block with language ${W}:`,_)}return K},J=$,G=$.matchAll(X);for(let K of G){let[q,W,z,U]=K,B=await Q(q,W,z,U);J=J.replace(q,B)}return J}async function YZ($,Z,Y="",X={}){return await fK($,/@markdown-file\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\{[^}]*\}))?\)/g,async(G,K,q,W)=>{try{let z=K;if(!S7.isAbsolute(K))z=S7.resolve(S7.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 N=V.substring(0,w).trim(),A=V.substring(w+1).trim(),R=A.startsWith('"')&&A.endsWith('"'),T=A.startsWith("'")&&A.endsWith("'");if(R||T)A=A.substring(1,A.length-1);U[N]=A}}}}catch(F){if(X.debug)console.error("Error parsing context in @markdown-file directive:",F)}let{content:B,data:_}=await vK(z,X),j={...Z,..._,...U},H=B,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 fK($,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 y7,g$=null;var XZ=b(()=>{D1();O0();y7=new Map});function G1($,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 JZ=b(()=>{F0()});function K1($,Z){let Y=gK($,Z);return Y.ok?{expression:Y.expression,endPos:Y.endPos}:null}function gK($,Z){let Y=Z;while(Y<$.length&&/\s/.test($[Y]))Y++;if($[Y]!=="(")return{ok:!1,reason:"missing-open-paren",pos:Y};let X=E0($,"(",")",Y);if(X===-1)return{ok:!1,reason:"unclosed-paren",pos:Y};return{ok:!0,expression:$.slice(Y+1,X),endPos:X+1}}function k1($,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 QZ($,Z){let Y=$.slice(Z).match(/^@if\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=K1($,X);if(!Q)return null;let J=Q.endPos,G=k1($,"if","endif",J);if(G===-1)return null;let K=$.slice(J,G),q=[],W=0,z="if",U=Q.expression,B=0,_=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)){_++,W++;continue}if(/^@endif(?![a-z])/.test(H)){_--,W+=6;continue}if(_===0){let L=H.match(/^@elseif\s*/);if(L){q.push({type:z,condition:U,content:K.substring(B,W),start:J+B,end:J+W});let F=W+L[0].length,O=K1(K,F);if(!O){W++;continue}z="elseif",U=O.expression,W=O.endPos,B=W;continue}else if(/^@else(?![a-z])/.test(H)){q.push({type:z,condition:U,content:K.substring(B,W),start:J+B,end:J+W}),z="else",U=void 0,W+=5,B=W;continue}}W++}return q.push({type:z,condition:U,content:K.slice(B),start:J+B,end:J+K.length}),{fullMatch:$.slice(Z,G+6),branches:q,start:Z,end:G+6}}function R5($){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=QZ($,X.index);if(J)Z.push(J),Y.lastIndex=J.end;X=Y.exec($)}return Z}function h$($,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=E0($,"(",")",q);if(W===-1){J=Q.exec($);continue}let z=$.slice(q+1,W),U=W+1,B=k1($,Z,Y,U);if(B===-1){J=Q.exec($);continue}let _=$.slice(U,B),j=B+`@${Y}`.length;X.push({fullMatch:$.slice(K,j),name:Z,params:z,content:_,start:K,end:j}),Q.lastIndex=j,J=Q.exec($)}return X}function C7($,Z){let Y=$.slice(Z).match(/^@switch\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=K1($,X);if(!Q)return null;let J=Q.endPos,G=k1($,"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 B=K.slice(W),_=B.match(/^@switch\s*\(/),j=B.match(/^@endswitch(?![a-z])/);if(_){if(U++,z)z.content+=_[0];W+=_[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=B.match(/^@case\s*/),L=B.match(/^@default(?![a-z])/),F=B.match(/^@break(?![a-z])/);if(H&&B.startsWith("@case")){if(z)q.push(z);let O=W+H[0].length,V=K1(K,O);if(!V){W++;continue}z={type:"case",value:V.expression,content:""},W=V.endPos}else if(L&&B.startsWith("@default")){if(z)q.push(z);z={type:"default",content:""},W+=L[0].length}else if(F&&B.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 GZ=()=>{};var KZ=()=>{};var d$=b(()=>{GZ();KZ()});function uK($,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=C7(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 B;if(U.value&&Z0(U.value))B=Y0(U.value,Object.keys(Z))(...Object.values(Z));else if(U.value)B=$0(U.value,Z);if(q===B){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=r("Switch",`Error evaluating @switch expression: ${W}`,i.EVALUATION_ERROR);X=X.substring(0,G)+z+X.substring(K.end);break}}return X}function b1($,Z,Y){let X=$;X=uK(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=K1(X,K+7);if(!q)break;let W=q.endPos,z=k1(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),B=q.expression,_=-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((N,A)=>N.pos-A.pos);for(let N of V)if(N.type==="open")H++;else if(N.type==="close")H--;else if(N.type==="else"&&H===0){_=N.pos;break}}let j;if(_!==-1){let H=U.slice(0,_),L=U.slice(_+5);j=`@if (${B})${L}@else ${H}@endif`}else j=`@if (!(${B}))${U}@endif`;X=X.substring(0,K)+j+X.substring(z+10),J=!0}}X=v7(X,Z,Y),X=x7(X,Z,Y),X=P7(X,Z);let Q=()=>{let J=R5(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=r(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=r("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 qZ($){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 P7($,Z){let Y=$;function X(K,q,W,z){let U=1,B=z,_=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),j=new RegExp(`@${W}(?![a-z])`,"g");while(B<K.length&&U>0){_.lastIndex=B,j.lastIndex=B;let H=_.exec(K),L=j.exec(K),F=H?H.index:1/0,O=L?L.index:1/0;if(F<O)U++,B=F+H[0].length;else if(O<1/0){if(U--,U===0)return O;B=O+L[0].length}else break}return-1}function Q(K,q,W){let z=0,U=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),B=new RegExp(`@${W}(?![a-z])`,"g"),_=/@else(?![a-z])/g,j=[],H;while((H=U.exec(K))!==null)j.push({pos:H.index,type:"open"});while((H=B.exec(K))!==null)j.push({pos:H.index,type:"close"});while((H=_.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,B=Y.slice(W+5),_=qZ(B);if(_)z=_.value,U=W+5+_.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?G1(`auth?.check && auth?.user?.[${z}]`,Z):G1("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,B=Y.slice(W+6),_=qZ(B);if(_)z=_.value,U=W+6+_.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?G1(`!auth?.check || !auth?.user?.[${z}]`,Z):G1("!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=G1(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 B=U.index,_=Y.slice(B+`@${K}`.length),j=G(_);if(!j)break;let H=B+`@${K}`.length+j.paramsEnd,L=X(Y,K,q,H);if(L===-1){console.warn(`[stx] @${K} directive at position ${B} 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"),N=new RegExp(`@${q}(?![a-z])`,"g"),A=new RegExp(`@${W}\\s*\\(`,"g"),R=/@else(?![a-z])/g,T=[],M;while((M=w.exec(F))!==null)T.push({pos:M.index,type:"open"});while((M=N.exec(F))!==null)T.push({pos:M.index,type:"close"});while((M=A.exec(F))!==null)T.push({pos:M.index,type:"elseDirective"});while((M=R.exec(F))!==null)T.push({pos:M.index,type:"else"});T.sort((S,P)=>S.pos-P.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 P=O[S];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[S+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 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=J(j.ability,j.type,j.id),C=K==="can"?D:!D,k="";if(C)k=I[0]?.content||"";else{let S=!1;for(let P=1;P<I.length;P++){let d=I[P];if(d.isFinalElse){k=d.content,S=!0;break}if(d.ability){let f=J(d.ability,d.type,d.id);if(K==="can"?f:!f){k=d.content,S=!0;break}}}if(!S&&I.length>0){let P=I[I.length-1];if(P.isFinalElse)k=P.content}}Y=Y.substring(0,B)+k+Y.substring(L+`@${q}`.length),z=!0}}return Y}function v7($,Z,Y){let X=$;function Q(J,G,K,q,W){let z=!0;while(z){z=!1;let U=new RegExp(`@${G}\\s*\\(`),B=J.match(U);if(!B||B.index===void 0)break;let _=B.index,j=K1(J,_+`@${G}`.length);if(!j)break;let H=j.endPos,L=k1(J,G,K,H);if(L===-1){console.warn(`[stx] @${G} directive at position ${_} has no matching @${K} \u2014 the block was skipped.`);break}let F=J.slice(H,L),O=j.expression,V=-1,w=0,N=0;while(N<F.length){let A=F.indexOf("@",N);if(A===-1)break;let R=F.substring(A);if(/^@(?:if|unless|isset|empty)\s*\(/.test(R)){w++,N=A+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(R)){w--,N=A+1;continue}if(w===0&&/^@else(?![a-z])/.test(R)){V=A;break}N=A+1}try{let A=q(O.trim()),R;if(V!==-1){let T=F.slice(0,V),M=F.slice(V+5);R=A?T:M}else R=A?F:"";J=J.substring(0,_)+R+J.substring(L+`@${K}`.length),z=!0}catch(A){let R=A instanceof Error?A.message:String(A),T=r(W,`Error processing @${G} directive: ${R}`,i.EVALUATION_ERROR);J=J.substring(0,_)+T+J.substring(L+`@${K}`.length);break}}return J}return X=Q(X,"isset","endisset",(J)=>{let G=G1(J,Z);return G!==void 0&&G!==null},"Isset"),X=Q(X,"empty","endempty",(J)=>{let G=G1(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 x7($,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"),B=new RegExp(`^@${K}(?![a-z])`),_=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,N=-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,S=C?C.index:1/0;if(k<S)V++,w=k+D[0].length;else if(S<1/0){if(V--,V===0){N=S;break}w=S+C[0].length}else break}if(N===-1){console.warn(`[stx] @${K} directive at position ${F} has no matching @${q} \u2014 the block was skipped.`);break}let A=j.substring(O,N),R=-1,T=0,M=0;while(M<A.length){let D=A.indexOf("@",M);if(D===-1)break;let C=A.substring(D);if(B.test(C)){T++,M=D+1;continue}if(_.test(C)){T--,M=D+1;continue}if(T===0&&/^@else(?![a-z])/.test(C)){R=D;break}M=D+1}let I;if(R!==-1){let D=A.slice(0,R),C=A.slice(R+5);I=W?D:C}else I=W?A:"";let E=`@${q}`.length;j=j.substring(0,F)+I+j.substring(N+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 m$=b(()=>{JZ();e0();d$();F0()});function WZ($=16){let Z=new Uint8Array($);return crypto.getRandomValues(Z),btoa(String.fromCharCode(...Z))}function u$($,Z){if(!$)return Z?.nonceGenerator?.()??WZ();let Y=zZ.get($);if(!Y)Y=Z?.nonceGenerator?.()??WZ(),zZ.set($,Y);return Y}function pK($,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 UZ($,Z){return`<meta http-equiv="Content-Security-Policy" content="${pK($,Z).replace(/&/g,"&").replace(/"/g,""")}">`}function BZ($,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?u$(Y,Z):void 0,Q=UZ(Z.directives,X);return $.replace(/<head([^>]*)>/,`<head$1>
|
|
7721
|
+
`+Q.slice(G);else Q+=J;return Q}function SK($,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*["']${f$(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*["']${f$(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*"${f$(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*'${f$(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 yK($){return/x-data\s*=\s*["']/.test($)}var e8=0,TK=0;var ZZ=b(()=>{i0()});import CK from"fs";import S7 from"path";import{createHighlighter as PK}from"ts-syntax-highlighter";async function vK($,Z={}){try{if(!await l($))throw Error(`Markdown file not found: ${$}`);let X=(await CK.promises.stat($)).mtime.getTime();if(Z.cache&&y7.has($)){let U=y7.get($);if(U.updatedAt>=X)return{content:U.content,data:U.data}}let Q=await Bun.file($).text(),{data:J,content:G}=L6(Q),K=Z.markdown||M7.markdown||{enabled:!0,syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}},W=Q5(G,{gfm:!0});if(K.syntaxHighlighting?.enabled&&K.syntaxHighlighting?.serverSide)W=await xK(W,K.syntaxHighlighting?.defaultTheme||"github-dark",K.syntaxHighlighting?.highlightUnknownLanguages||!1);let z={content:W,data:J||{}};if(Z.cache)y7.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 xK($,Z,Y){let X=/<pre><code( class="language-([^"]+)")?>([^<]+)<\/code><\/pre>/g;if(!g$)try{g$=await PK({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(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'"),B=W||(Y?"text":"");if(!B)return K;try{if(!g$.getSupportedLanguages().includes(B))return K;return(await g$.highlight(U,B,{theme:Z})).html}catch(_){console.error(`Error highlighting code block with language ${W}:`,_)}return K},J=$,G=$.matchAll(X);for(let K of G){let[q,W,z,U]=K,B=await Q(q,W,z,U);J=J.replace(q,B)}return J}async function YZ($,Z,Y="",X={}){return await fK($,/@markdown-file\(\s*['"]([^'"]+)['"]\s*(?:,\s*(\{[^}]*\}))?\)/g,async(G,K,q,W)=>{try{let z=K;if(!S7.isAbsolute(K))z=S7.resolve(S7.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 N=V.substring(0,w).trim(),A=V.substring(w+1).trim(),R=A.startsWith('"')&&A.endsWith('"'),T=A.startsWith("'")&&A.endsWith("'");if(R||T)A=A.substring(1,A.length-1);U[N]=A}}}}catch(F){if(X.debug)console.error("Error parsing context in @markdown-file directive:",F)}let{content:B,data:_}=await vK(z,X),j={...Z,..._,...U},H=B,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 fK($,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 y7,g$=null;var XZ=b(()=>{D1();O0();y7=new Map});function G1($,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 JZ=b(()=>{F0()});function K1($,Z){let Y=gK($,Z);return Y.ok?{expression:Y.expression,endPos:Y.endPos}:null}function gK($,Z){let Y=Z;while(Y<$.length&&/\s/.test($[Y]))Y++;if($[Y]!=="(")return{ok:!1,reason:"missing-open-paren",pos:Y};let X=E0($,"(",")",Y);if(X===-1)return{ok:!1,reason:"unclosed-paren",pos:Y};return{ok:!0,expression:$.slice(Y+1,X),endPos:X+1}}function k1($,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 QZ($,Z){let Y=$.slice(Z).match(/^@if\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=K1($,X);if(!Q)return null;let J=Q.endPos,G=k1($,"if","endif",J);if(G===-1)return null;let K=$.slice(J,G),q=[],W=0,z="if",U=Q.expression,B=0,_=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)){_++,W++;continue}if(/^@endif(?![a-z])/.test(H)){_--,W+=6;continue}if(_===0){let L=H.match(/^@elseif\s*/);if(L){q.push({type:z,condition:U,content:K.substring(B,W),start:J+B,end:J+W});let F=W+L[0].length,O=K1(K,F);if(!O){W++;continue}z="elseif",U=O.expression,W=O.endPos,B=W;continue}else if(/^@else(?![a-z])/.test(H)){q.push({type:z,condition:U,content:K.substring(B,W),start:J+B,end:J+W}),z="else",U=void 0,W+=5,B=W;continue}}W++}return q.push({type:z,condition:U,content:K.slice(B),start:J+B,end:J+K.length}),{fullMatch:$.slice(Z,G+6),branches:q,start:Z,end:G+6}}function R5($){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=QZ($,X.index);if(J)Z.push(J),Y.lastIndex=J.end;X=Y.exec($)}return Z}function h$($,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=E0($,"(",")",q);if(W===-1){J=Q.exec($);continue}let z=$.slice(q+1,W),U=W+1,B=k1($,Z,Y,U);if(B===-1){J=Q.exec($);continue}let _=$.slice(U,B),j=B+`@${Y}`.length;X.push({fullMatch:$.slice(K,j),name:Z,params:z,content:_,start:K,end:j}),Q.lastIndex=j,J=Q.exec($)}return X}function C7($,Z){let Y=$.slice(Z).match(/^@switch\s*/);if(!Y)return null;let X=Z+Y[0].length,Q=K1($,X);if(!Q)return null;let J=Q.endPos,G=k1($,"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 B=K.slice(W),_=B.match(/^@switch\s*\(/),j=B.match(/^@endswitch(?![a-z])/);if(_){if(U++,z)z.content+=_[0];W+=_[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=B.match(/^@case\s*/),L=B.match(/^@default(?![a-z])/),F=B.match(/^@break(?![a-z])/);if(H&&B.startsWith("@case")){if(z)q.push(z);let O=W+H[0].length,V=K1(K,O);if(!V){W++;continue}z={type:"case",value:V.expression,content:""},W=V.endPos}else if(L&&B.startsWith("@default")){if(z)q.push(z);z={type:"default",content:""},W+=L[0].length}else if(F&&B.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 GZ=()=>{};var KZ=()=>{};var d$=b(()=>{GZ();KZ()});function uK($,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=C7(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 B;if(U.value&&Z0(U.value))B=Y0(U.value,Object.keys(Z))(...Object.values(Z));else if(U.value)B=$0(U.value,Z);if(q===B){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=r("Switch",`Error evaluating @switch expression: ${W}`,i.EVALUATION_ERROR);X=X.substring(0,G)+z+X.substring(K.end);break}}return X}function b1($,Z,Y){let X=$;X=uK(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=K1(X,K+7);if(!q)break;let W=q.endPos,z=k1(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),B=q.expression,_=-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((N,A)=>N.pos-A.pos);for(let N of V)if(N.type==="open")H++;else if(N.type==="close")H--;else if(N.type==="else"&&H===0){_=N.pos;break}}let j;if(_!==-1){let H=U.slice(0,_),L=U.slice(_+5);j=`@if (${B})${L}@else ${H}@endif`}else j=`@if (!(${B}))${U}@endif`;X=X.substring(0,K)+j+X.substring(z+10),J=!0}}X=v7(X,Z,Y),X=x7(X,Z,Y),X=P7(X,Z);let Q=()=>{let J=R5(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=r(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=r("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 qZ($){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 P7($,Z){let Y=$;function X(K,q,W,z){let U=1,B=z,_=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),j=new RegExp(`@${W}(?![a-z])`,"g");while(B<K.length&&U>0){_.lastIndex=B,j.lastIndex=B;let H=_.exec(K),L=j.exec(K),F=H?H.index:1/0,O=L?L.index:1/0;if(F<O)U++,B=F+H[0].length;else if(O<1/0){if(U--,U===0)return O;B=O+L[0].length}else break}return-1}function Q(K,q,W){let z=0,U=new RegExp(`@${q}(?:\\s*\\(|\\s|$)`,"g"),B=new RegExp(`@${W}(?![a-z])`,"g"),_=/@else(?![a-z])/g,j=[],H;while((H=U.exec(K))!==null)j.push({pos:H.index,type:"open"});while((H=B.exec(K))!==null)j.push({pos:H.index,type:"close"});while((H=_.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,B=Y.slice(W+5),_=qZ(B);if(_)z=_.value,U=W+5+_.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?G1(`auth?.check && auth?.user?.[${z}]`,Z):G1("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,B=Y.slice(W+6),_=qZ(B);if(_)z=_.value,U=W+6+_.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?G1(`!auth?.check || !auth?.user?.[${z}]`,Z):G1("!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=G1(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 B=U.index,_=Y.slice(B+`@${K}`.length),j=G(_);if(!j)break;let H=B+`@${K}`.length+j.paramsEnd,L=X(Y,K,q,H);if(L===-1){console.warn(`[stx] @${K} directive at position ${B} 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"),N=new RegExp(`@${q}(?![a-z])`,"g"),A=new RegExp(`@${W}\\s*\\(`,"g"),R=/@else(?![a-z])/g,T=[],M;while((M=w.exec(F))!==null)T.push({pos:M.index,type:"open"});while((M=N.exec(F))!==null)T.push({pos:M.index,type:"close"});while((M=A.exec(F))!==null)T.push({pos:M.index,type:"elseDirective"});while((M=R.exec(F))!==null)T.push({pos:M.index,type:"else"});T.sort((S,P)=>S.pos-P.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 P=O[S];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[S+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 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=J(j.ability,j.type,j.id),C=K==="can"?D:!D,k="";if(C)k=I[0]?.content||"";else{let S=!1;for(let P=1;P<I.length;P++){let d=I[P];if(d.isFinalElse){k=d.content,S=!0;break}if(d.ability){let f=J(d.ability,d.type,d.id);if(K==="can"?f:!f){k=d.content,S=!0;break}}}if(!S&&I.length>0){let P=I[I.length-1];if(P.isFinalElse)k=P.content}}Y=Y.substring(0,B)+k+Y.substring(L+`@${q}`.length),z=!0}}return Y}function v7($,Z,Y){let X=$;function Q(J,G,K,q,W){let z=!0;while(z){z=!1;let U=new RegExp(`@${G}\\s*\\(`),B=J.match(U);if(!B||B.index===void 0)break;let _=B.index,j=K1(J,_+`@${G}`.length);if(!j)break;let H=j.endPos,L=k1(J,G,K,H);if(L===-1){console.warn(`[stx] @${G} directive at position ${_} has no matching @${K} \u2014 the block was skipped.`);break}let F=J.slice(H,L),O=j.expression,V=-1,w=0,N=0;while(N<F.length){let A=F.indexOf("@",N);if(A===-1)break;let R=F.substring(A);if(/^@(?:if|unless|isset|empty)\s*\(/.test(R)){w++,N=A+1;continue}if(/^@(?:endif|endunless|endisset|endempty)(?![a-z])/.test(R)){w--,N=A+1;continue}if(w===0&&/^@else(?![a-z])/.test(R)){V=A;break}N=A+1}try{let A=q(O.trim()),R;if(V!==-1){let T=F.slice(0,V),M=F.slice(V+5);R=A?T:M}else R=A?F:"";J=J.substring(0,_)+R+J.substring(L+`@${K}`.length),z=!0}catch(A){let R=A instanceof Error?A.message:String(A),T=r(W,`Error processing @${G} directive: ${R}`,i.EVALUATION_ERROR);J=J.substring(0,_)+T+J.substring(L+`@${K}`.length);break}}return J}return X=Q(X,"isset","endisset",(J)=>{let G=G1(J,Z);return G!==void 0&&G!==null},"Isset"),X=Q(X,"empty","endempty",(J)=>{let G=G1(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 x7($,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"),B=new RegExp(`^@${K}(?![a-z])`),_=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,N=-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,S=C?C.index:1/0;if(k<S)V++,w=k+D[0].length;else if(S<1/0){if(V--,V===0){N=S;break}w=S+C[0].length}else break}if(N===-1){console.warn(`[stx] @${K} directive at position ${F} has no matching @${q} \u2014 the block was skipped.`);break}let A=j.substring(O,N),R=-1,T=0,M=0;while(M<A.length){let D=A.indexOf("@",M);if(D===-1)break;let C=A.substring(D);if(B.test(C)){T++,M=D+1;continue}if(_.test(C)){T--,M=D+1;continue}if(T===0&&/^@else(?![a-z])/.test(C)){R=D;break}M=D+1}let I;if(R!==-1){let D=A.slice(0,R),C=A.slice(R+5);I=W?D:C}else I=W?A:"";let E=`@${q}`.length;j=j.substring(0,F)+I+j.substring(N+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 m$=b(()=>{JZ();e0();d$();F0()});function WZ($=16){let Z=new Uint8Array($);return crypto.getRandomValues(Z),btoa(String.fromCharCode(...Z))}function u$($,Z){if(!$)return Z?.nonceGenerator?.()??WZ();let Y=zZ.get($);if(!Y)Y=Z?.nonceGenerator?.()??WZ(),zZ.set($,Y);return Y}function pK($,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 UZ($,Z){return`<meta http-equiv="Content-Security-Policy" content="${pK($,Z).replace(/&/g,"&").replace(/"/g,""")}">`}function BZ($,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?u$(Y,Z):void 0,Q=UZ(Z.directives,X);return $.replace(/<head([^>]*)>/,`<head$1>
|
|
7722
7722
|
${Q}`)}function _Z($,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?u$(Z,J):void 0;return UZ(J.directives,G)}),Q=Q.replace(/@cspNonce\b/g,()=>{if(!J?.enabled||!J.useNonce)return"";return u$(Z,J)}),J?.enabled&&J.useNonce)Z.cspNonce=u$(Z,J);return Q}var zZ;var jZ=b(()=>{zZ=new WeakMap});import lK from"crypto";function iK($=cK){let Z=lK.randomBytes(Math.ceil($/2)).toString("hex").slice(0,$);return f7=Z,Z}function nK(){if(!f7)iK();return f7}function oK($=HZ){let Z=nK();return`<input type="hidden" name="${$}" value="${Z}">`}function OZ($){return $.replace(/@csrf(?:\((['"])([^'"]*)\1\))?/g,(Z,Y,X)=>{return oK(X||HZ)})}var cK=40,HZ="_token",f7=null;var LZ=()=>{};async function FZ($,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 sK(Q,J,Z,Y,X);else Q=await rK(Q,J,Z,Y,X)}return Q}async function sK($,Z,Y,X,Q){let{name:J,handler:G}=Z,K=`@${J}`,q=`@end${J}`,W=$,z=d1(`${K}(?:\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\))?([\\s\\S]*?)${q}`,"g"),U=[],B=z.exec(W);while(B!==null){let[_,j="",H=""]=B,L=B.index||0;try{let F=j?VZ(j):[],O=H.trim(),V=await G(O,F,Y,X);U.push({original:_,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:_,processed:r("CustomDirective",`Error in @${J}${j?`(${j})`:""}: ${O}`,i.EVALUATION_ERROR),startIndex:L})}B=z.exec(W)}for(let _=U.length-1;_>=0;_--){let{original:j,processed:H}=U[_];W=W.replace(j,H)}return W}async function rK($,Z,Y,X,Q){let{name:J,handler:G}=Z,K=$,q=d1(`@${J}\\s*\\(([^()]*(?:\\([^)]*\\)[^()]*)*)\\)`,"g"),W=[],z=q.exec(K);while(z!==null){let[_,j=""]=z,H=z.index||0;try{let L=VZ(j),F=await G("",L,Y,X);W.push({original:_,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:_,processed:r("CustomDirective",`Error in @${J}(${j}): ${F}`,i.EVALUATION_ERROR),startIndex:H})}z=q.exec(K)}let U=d1(`@${J}(?!\\w)(?!\\s*\\()`,"g"),B=U.exec(K);while(B!==null){let[_]=B,j=B.index||0;try{let H=await G("",[],Y,X);W.push({original:_,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:_,processed:r("CustomDirective",`Error in @${J}: ${L}`,i.EVALUATION_ERROR),startIndex:j})}B=U.exec(K)}for(let _=W.length-1;_>=0;_--){let{original:j,processed:H}=W[_];K=K.replace(j,H)}return K}function VZ($){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 wZ=b(()=>{e0();m1()});import aK from"crypto";function V0($){return String($??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function p$($,Z,Y,X){let Q=$||Z;return Y?`${Q} ${X}`:Q}function tK(){return aK.randomUUID()}function l$($,Z){let Y=$;return Y=Y.replace(/@csrf/g,()=>{if(!Z.csrf||typeof Z.csrf!=="object"){let X=tK();Z.csrf={token:X}}if(Z.csrf.field)return Z.csrf.field;if(Z.csrf.token)return`<input type="hidden" name="_token" value="${V0(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="${V0(J)}">`;return X}),Y}function RZ($,Z,Y=AZ){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||"",B=q1(W),_=z.toUpperCase(),j=["GET","POST"].includes(_)?_:"POST",H=`<form method="${V0(j)}" action="${V0(U)}"${B?` ${B}`:""}>`;if(H+=`
|
|
7723
7723
|
${l$("@csrf",Z)}`,!["GET","POST"].includes(_))H+=`
|
|
7724
7724
|
${l$(`@method('${_}')`,Z)}`;return H}),X=X.replace(/@endform/g,"</form>"),X=X.replace(/@input\(\s*(?:'([^']+)'|"([^"]+)")\s*(?:,\s*(?:(?:'([^']*)'|"([^"]*)")\s*)?)?(?:,\s*\{([^}]+)\})?\s*\)/g,(Q,J,G,K,q,W="")=>{let z=J||G||"",U=K||q||"",B=q1(W),_=T5(z,Z),j=_!==void 0&&_!==null?_:U||"",H=B.match(/type=['"]([^'"]+)['"]/i),L=H?H[1]:"text",F=M5(z,Z),O=B.match(/class=['"]([^'"]+)['"]/i),V=p$(O?O[1]:"",Y.input,F,Y.inputError),w=B.replace(/class=['"][^'"]+['"]/i,"");return w=w.replace(/type=['"][^'"]+['"]/i,""),`<input type="${V0(L)}" name="${V0(z)}" value="${V0(j)}" class="${V}"${w?` ${w}`:""}>`}),X=X.replace(/@textarea\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)([\s\S]*?)@endtextarea/g,(Q,J,G="",K="")=>{let q=q1(G),W=T5(J,Z)||K.trim(),z=M5(J,Z),U=q.match(/class=['"]([^'"]+)['"]/i),B=p$(U?U[1]:"",Y.input,z,Y.inputError),_=q.replace(/class=['"][^'"]+['"]/i,"");return`<textarea name="${V0(J)}" class="${B}"${_?` ${_}`:""}>${V0(W)}</textarea>`}),X=X.replace(/@select\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)([\s\S]*?)@endselect/g,(Q,J,G="",K)=>{let q=q1(G),W=T5(J,Z),z=M5(J,Z),U=q.match(/class=['"]([^'"]+)['"]/i),B=p$(U?U[1]:"",Y.input,z,Y.inputError),_=q.replace(/class=['"][^'"]+['"]/i,""),j=K;if(W!==void 0)j=K.replace(/(<option[^>]*value=['"]([^'"]+)['"][^>]*>)/gi,(H,L,F)=>{if((Array.isArray(W)?W.some((V)=>String(V)===F):String(W)===F)&&!L.includes("selected"))return L.replace(/(<option)/,"$1 selected");return H});return`<select name="${V0(J)}" class="${B}"${_?` ${_}`:""}>${j}</select>`}),X=X.replace(/@checkbox\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?(?:,\s*\{([^}]+)\})?\)/g,(Q,J,G="1",K="")=>{let q=q1(K),W=T5(J,Z),z=W!==void 0&&(Array.isArray(W)?W.some((j)=>String(j)===G):W===!0||String(W)===G),U=q.match(/class=['"]([^'"]+)['"]/i),B=U?U[1]:Y.checkInput,_=q.replace(/class=['"][^'"]+['"]/i,"");return`<input type="checkbox" name="${V0(J)}" value="${V0(G)}" class="${B}"${z?" checked":""}${_?` ${_}`:""}>`}),X=X.replace(/@radio\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)/g,(Q,J,G,K="")=>{let q=q1(K),W=T5(J,Z),z=W!==void 0&&W===G,U=q.match(/class=['"]([^'"]+)['"]/i),B=U?U[1]:Y.checkInput,_=q.replace(/class=['"][^'"]+['"]/i,"");return`<input type="radio" name="${V0(J)}" value="${V0(G)}" class="${B}"${z?" checked":""}${_?` ${_}`:""}>`}),X=X.replace(/@file\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)/g,(Q,J,G="")=>{let K=q1(G),q=K.match(/accept=['"]([^'"]+)['"]/i),W=q?q[1]:"",z=K.includes("multiple"),U=M5(J,Z),B=K.match(/class=['"]([^'"]+)['"]/i),_=p$(B?B[1]:"",Y.input,U,Y.inputError),j=K.replace(/class=['"][^'"]+['"]/gi,"").replace(/accept=['"][^'"]+['"]/gi,"").replace(/\bmultiple\b/gi,"").trim(),H=[`<input type="file" name="${V0(J)}"`,`class="${_}"`];if(W)H.push(`accept="${V0(W)}"`);if(z)H.push("multiple");if(j)H.push(j);return`${H.join(" ")}>`}),X=X.replace(/@label\(\s*['"]([^'"]+)['"]\s*(?:,\s*\{([^}]+)\})?\)([\s\S]*?)@endlabel/g,(Q,J,G="",K)=>{let q=q1(G),W=q.match(/class=['"]([^'"]+)['"]/i),z=W?W[1]:Y.label,U=q.replace(/class=['"][^'"]+['"]/i,"");return`<label for="${V0(J)}" class="${z}"${U?` ${U}`:""}>${K}</label>`}),X}function TZ($,Z,Y=AZ){return $.replace(/@error\(['"]([^'"]+)['"]\)([\s\S]*?)@enderror/g,(X,Q,J)=>{try{if(M5(Q,Z))return J.replace(/\{\{([^}]+)\}\}/g,(G,K)=>{try{if(K.trim()==="$message"||K.trim()==="message")return NZ(Q,Z);if(K.trim().includes("errors.first")||K.trim().includes("$errors.first")){if(typeof Z.errors?.first==="function")return Z.errors.first(Q);return NZ(Q,Z)}let q=K.trim();if(Z0(q)){let W=$0(q,Z);return W!==void 0?String(W):q}return q}catch{return K}});return""}catch(G){return console.error("Error processing @error directive:",G),X}})}function M5($,Z){if(!Z.errors)return!1;if(typeof Z.errors.has==="function")return Z.errors.has($);if(typeof Z.errors==="object")return Object.prototype.hasOwnProperty.call(Z.errors,$);return!1}function NZ($,Z){if(!Z.errors)return"";if(typeof Z.errors.get==="function")return Z.errors.get($);if(typeof Z.errors==="object"&&Object.prototype.hasOwnProperty.call(Z.errors,$)){let Y=Z.errors[$];return Array.isArray(Y)?Y[0]:String(Y)}return""}function T5($,Z){let Y;if(Z.old&&typeof Z.old==="function")return Z.old($);if(Z.old&&typeof Z.old==="object")return Z.old[$];if($.endsWith("[]")){let X=$.slice(0,-2);if(Y=Z[X],Y!==void 0)return Y}return Z[$]}function q1($){if(!$.trim())return"";let Z=[],Y=$.trim(),X=/([\w-]+)\s*:\s*(['"]?)([^,'"]*)\2(?:\s*,\s*|\s*$)/g,Q;while((Q=X.exec(Y))!==null){let[,J,,G]=Q;Z.push(`${J}="${G.trim()}"`)}return Z.join(" ")}var AZ;var MZ=b(()=>{F0();AZ={input:"form-control",inputError:"is-invalid",checkInput:"form-check-input",label:"form-label",errorFeedback:"invalid-feedback"}});import d7 from"path";async function eK(){if(I5!==void 0)return I5;try{I5=(await import("@stacksjs/ts-i18n")).loadLocale??null}catch{I5=null}return I5}function $q($,Z=0){if(Z<=0)return!1;return Date.now()-$.loadedAt>Z}async function Zq($,Z){if({...p7,...Z.i18n}.cache&&m7[$]){let Q=m7[$],J=Z.i18n?.cacheMaxAge??0;if(!$q(Q,J))return Q.translations}if(D5[$]?.state==="loading")return D5[$].promise;g7[$]="loading";let X=u7($,Z).then((Q)=>{return g7[$]="loaded",delete D5[$],Q}).catch((Q)=>{throw g7[$]="error",D5[$]={promise:X,state:"error",error:Q instanceof Error?Q:Error(String(Q))},Q});return D5[$]={promise:X,state:"loading"},X}async function u7($,Z){let Y={...p7,...Z.i18n},X=d7.isAbsolute(Y.translationsDir)?Y.translationsDir:d7.resolve(Z.root||process.cwd(),Y.translationsDir);try{let Q=await eK(),J=Q?await Q($,{translationsDir:X,defaultLocale:Y.defaultLocale,sources:Gq(Y.format)}):await Yq($,Y,X);if(J===void 0){if($!==Y.defaultLocale)return u7(Y.defaultLocale,Z);return{}}let G=J;if(Y.cache)m7[$]={translations:G,loadedAt:Date.now(),locale:$};return G}catch(Q){if(Z.debug)console.error(`Error loading translation file for locale "${$}":`,Q);if($!==Y.defaultLocale)return u7(Y.defaultLocale,Z);return{}}}async function Yq($,Z,Y){let X=d7.join(Y,`${$}${Xq(Z.format)}`);try{let Q=await import(X);return Q.default||Q}catch(Q){try{let J=await Bun.file(X).text();if(Z.format==="yaml"||Z.format==="yml")return Jq(J);if(Z.format==="json")return JSON.parse(J);throw Q}catch{return}}}function Xq($){switch($){case"yaml":return".yaml";case"yml":return".yml";case"js":return".js";case"ts":return".ts";case"json":default:return".json"}}function Jq($){let Z={},Y=$.split(`
|