@stacksjs/stx 0.2.685 → 0.2.687

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/{chunk-2ajbhefk.js → chunk-078as147.js} +1 -1
  2. package/dist/{chunk-jrche9k7.js → chunk-1b526cba.js} +1 -1
  3. package/dist/{chunk-718rkxa7.js → chunk-1zjn5p5c.js} +1 -1
  4. package/dist/chunk-2s1c7g5r.js +2 -0
  5. package/dist/{chunk-eykbcntx.js → chunk-3svg41sb.js} +1 -1
  6. package/dist/{chunk-qjmvcqfh.js → chunk-3vjzezn1.js} +1 -1
  7. package/dist/{chunk-6qn368e7.js → chunk-3zcc0w5e.js} +2 -2
  8. package/dist/{chunk-qgs69nds.js → chunk-52g5q984.js} +1 -1
  9. package/dist/chunk-5j1bb675.js +2 -0
  10. package/dist/chunk-5m6ja6mx.js +2 -0
  11. package/dist/chunk-5rn0k6kq.js +2 -0
  12. package/dist/{chunk-r8cn9qhr.js → chunk-68wa4bf0.js} +1 -1
  13. package/dist/{chunk-7st0prz9.js → chunk-71sawjg8.js} +2 -2
  14. package/dist/chunk-7z5sp09n.js +2 -0
  15. package/dist/{chunk-fbdmsw5j.js → chunk-95yt1gxa.js} +1 -1
  16. package/dist/{chunk-zhcb33s1.js → chunk-9h46mvew.js} +1 -1
  17. package/dist/{chunk-zf6kmw9q.js → chunk-9m1agnnx.js} +1 -1
  18. package/dist/{chunk-km6ggz8n.js → chunk-9s8471tv.js} +1 -1
  19. package/dist/{chunk-9xp9hs7t.js → chunk-agx8pbg4.js} +1 -1
  20. package/dist/chunk-aprvds2c.js +2 -0
  21. package/dist/{chunk-gn98ha90.js → chunk-ay9bwfbj.js} +1 -1
  22. package/dist/{chunk-w6frg42f.js → chunk-b2cfg8d1.js} +1 -1
  23. package/dist/{chunk-d0g4zndy.js → chunk-bkk6xq8p.js} +1 -1
  24. package/dist/{chunk-xpch3mq8.js → chunk-bm6yhhew.js} +1 -1
  25. package/dist/{chunk-7grjwpdq.js → chunk-bzzye361.js} +1 -1
  26. package/dist/chunk-c0fkhe6t.js +2 -0
  27. package/dist/{chunk-bnggav14.js → chunk-cz0p258g.js} +1 -1
  28. package/dist/{chunk-dpghx4z6.js → chunk-d26nb6zy.js} +1 -1
  29. package/dist/{chunk-qz314za9.js → chunk-dztv0p4y.js} +1 -1
  30. package/dist/chunk-e25r7baw.js +2 -0
  31. package/dist/{chunk-8x34g2ad.js → chunk-f178pm4d.js} +1 -1
  32. package/dist/{chunk-4ht54p3j.js → chunk-fbj9b0p6.js} +4 -4
  33. package/dist/{chunk-w3q5czk5.js → chunk-ff7pvv0p.js} +2 -2
  34. package/dist/{chunk-ppxfsqwh.js → chunk-fvxvd48v.js} +1 -1
  35. package/dist/{chunk-6nhsvb9x.js → chunk-g3jg4mcw.js} +1 -1
  36. package/dist/chunk-gcy2prwj.js +2 -0
  37. package/dist/chunk-gpk0ew71.js +2 -0
  38. package/dist/{chunk-4rj9746b.js → chunk-h1bnge85.js} +1 -1
  39. package/dist/{chunk-kgcwx6nt.js → chunk-haq3cg76.js} +1 -1
  40. package/dist/{chunk-9wd31tc6.js → chunk-hr3m2h4n.js} +1 -1
  41. package/dist/{chunk-wt6f9pk9.js → chunk-hx787tfa.js} +1 -1
  42. package/dist/{chunk-5t9ndqfm.js → chunk-jgxzbthg.js} +1 -1
  43. package/dist/{chunk-mxbp4vyy.js → chunk-jhr08gjs.js} +2 -2
  44. package/dist/chunk-jk16vj3c.js +2 -0
  45. package/dist/{chunk-6e60jp4a.js → chunk-kq1hmpgb.js} +1 -1
  46. package/dist/chunk-kz9xs9gn.js +2 -0
  47. package/dist/chunk-m5y0tgax.js +2 -0
  48. package/dist/{chunk-nqvex98n.js → chunk-m62xkpek.js} +3 -3
  49. package/dist/{chunk-gwqw8r2e.js → chunk-mf7r2gd0.js} +1 -1
  50. package/dist/chunk-mpgf9zbd.js +2 -0
  51. package/dist/{chunk-4r8c96a0.js → chunk-mpvekbzr.js} +5 -5
  52. package/dist/{chunk-49c5v5fh.js → chunk-n93krbsx.js} +1 -1
  53. package/dist/{chunk-4k3jx9mm.js → chunk-nm7b8cmr.js} +6 -6
  54. package/dist/{chunk-t3e5tv4h.js → chunk-pe9ry4mj.js} +6 -6
  55. package/dist/{chunk-mf8yzpyy.js → chunk-pfc2h65d.js} +1 -1
  56. package/dist/{chunk-jsac71cy.js → chunk-q0v0cs2j.js} +1 -1
  57. package/dist/chunk-qk34p70z.js +2 -0
  58. package/dist/{chunk-bxr4c8rg.js → chunk-qkr7epna.js} +1 -1
  59. package/dist/{chunk-fb84n8kz.js → chunk-qy26afdn.js} +2 -2
  60. package/dist/{chunk-3tp7r57c.js → chunk-r0ys9aqa.js} +1 -1
  61. package/dist/{chunk-cnvwrv5a.js → chunk-r16cej66.js} +1 -1
  62. package/dist/{chunk-9wa3t87n.js → chunk-r21m7gsd.js} +1 -1
  63. package/dist/{chunk-nsvnxkyb.js → chunk-rtfyx54t.js} +2 -2
  64. package/dist/{chunk-px7ryjd9.js → chunk-t2twa7wy.js} +1 -1
  65. package/dist/{chunk-f5s2h2y8.js → chunk-trzanjcp.js} +1 -1
  66. package/dist/{chunk-gccwjjzw.js → chunk-vnnwp1cg.js} +1 -1
  67. package/dist/{chunk-244tyyhx.js → chunk-xszbpnaa.js} +1 -1
  68. package/dist/{chunk-yhba2f9d.js → chunk-xzffh9aj.js} +1 -1
  69. package/dist/{chunk-6zzg889q.js → chunk-y8f59j6z.js} +1 -1
  70. package/dist/{chunk-gkmh0xys.js → chunk-ydad3kq5.js} +1 -1
  71. package/dist/{chunk-r7csb300.js → chunk-ygb33q5w.js} +1 -1
  72. package/dist/chunk-yxg5na8z.js +2 -0
  73. package/dist/{chunk-01bd9hrj.js → chunk-z6enp6s3.js} +1 -1
  74. package/dist/{chunk-e5kz0y03.js → chunk-zff3cb1e.js} +4 -4
  75. package/dist/cli.js +7 -7
  76. package/dist/craft-entry.js +1 -1
  77. package/dist/craft.js +1 -1
  78. package/dist/env.d.ts +1 -1
  79. package/dist/env.js +2 -2
  80. package/dist/native/runtime/native-host.js +4 -0
  81. package/dist/process.js +2 -2
  82. package/dist/pwa.js +2 -2
  83. package/dist/ssg.js +5 -5
  84. package/dist/types/config-types.d.ts +1 -0
  85. package/package.json +5 -5
  86. package/dist/chunk-42c308vk.js +0 -2
  87. package/dist/chunk-8y7tpjfs.js +0 -2
  88. package/dist/chunk-bhm9sdnv.js +0 -2
  89. package/dist/chunk-bpk0qy53.js +0 -2
  90. package/dist/chunk-cxvka6g3.js +0 -2
  91. package/dist/chunk-fzfa35ft.js +0 -2
  92. package/dist/chunk-kxqvfdm9.js +0 -2
  93. package/dist/chunk-m1cwgzqy.js +0 -2
  94. package/dist/chunk-mn9xw0fe.js +0 -2
  95. package/dist/chunk-sy19th0w.js +0 -2
  96. package/dist/chunk-t8djd28a.js +0 -2
  97. package/dist/chunk-tfhhxpda.js +0 -2
  98. package/dist/chunk-v3mmxk1y.js +0 -2
  99. package/dist/chunk-x519ewtq.js +0 -2
  100. package/dist/chunk-xe40yhcw.js +0 -2
  101. package/dist/chunk-xs8228sa.js +0 -2
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{se,ue,un,At,Pt,g,n,pe,d}from"./chunk-t3e5tv4h.js";import{gt,$e,oa,Lr,to,no,o}from"./chunk-4k3jx9mm.js";import{ie,fr,xe,D,bn}from"./chunk-3tp7r57c.js";import{vt,tr,ns,rs,ss,wt,xt,St,kt,_t,Ct,Ye}from"./chunk-kypwg2ws.js";import{Jr,i,R}from"./chunk-mxbp4vyy.js";import{ut,Ri,ke,O,Ai,Hs,Pr,Ve,Pi,_e}from"./chunk-nsvnxkyb.js";import{Zn,Qn}from"./chunk-fbdmsw5j.js";import{kn}from"./chunk-px7ryjd9.js";import{e,nn,Kn,h}from"./chunk-fb84n8kz.js";import{Ke}from"./chunk-e5kz0y03.js";import{Te}from"./chunk-374nhgyf.js";import{q,he,ye}from"./chunk-4ht54p3j.js";import{c}from"./chunk-xvs84gas.js";import{W}from"./chunk-2ajbhefk.js";async function Fn(t){try{let r=await Bun.file(t).text(),s=zn(r),p=Nn(r,t),a=Un(r,s),l=Wn(r,s);return{file:t,metrics:s,issues:p,suggestions:a,performance:l}}catch(r){throw Error(`Failed to analyze template ${t}: ${r instanceof Error?r.message:String(r)}`)}}function zn(t){let r=t.split(`
2
+ import{se,ue,un,At,Pt,g,n,pe,d}from"./chunk-pe9ry4mj.js";import{gt,$e,oa,Lr,to,no,o}from"./chunk-nm7b8cmr.js";import{ie,fr,xe,D,bn}from"./chunk-r0ys9aqa.js";import{vt,tr,ns,rs,ss,wt,xt,St,kt,_t,Ct,Ye}from"./chunk-kypwg2ws.js";import{Jr,i,R}from"./chunk-jhr08gjs.js";import{ut,Ri,ke,O,Ai,Hs,Pr,Ve,Pi,_e}from"./chunk-rtfyx54t.js";import{Zn,Qn}from"./chunk-95yt1gxa.js";import{kn}from"./chunk-t2twa7wy.js";import{e,nn,Kn,h}from"./chunk-qy26afdn.js";import{Ke}from"./chunk-zff3cb1e.js";import{Te}from"./chunk-374nhgyf.js";import{q,he,ye}from"./chunk-fbj9b0p6.js";import{c}from"./chunk-xvs84gas.js";import{W}from"./chunk-078as147.js";async function Fn(t){try{let r=await Bun.file(t).text(),s=zn(r),p=Nn(r,t),a=Un(r,s),l=Wn(r,s);return{file:t,metrics:s,issues:p,suggestions:a,performance:l}}catch(r){throw Error(`Failed to analyze template ${t}: ${r instanceof Error?r.message:String(r)}`)}}function zn(t){let r=t.split(`
3
3
  `),s=t.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),a=(s?s[1]:"").split(`
4
4
  `).length,l={conditionals:(t.match(/@(if|unless|elseif|else|endif|endunless)\b/g)||[]).length,loops:(t.match(/@(foreach|for|endforeach|endfor|while|endwhile)\b/g)||[]).length,includes:(t.match(/@(include|component|extends|section|yield)\b/g)||[]).length,custom:0,total:0};l.total=l.conditionals+l.loops+l.includes+l.custom;let f=(t.match(/\{\{[\s\S]*?\}\}/g)||[]).length,u=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,y=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,m=f+u+y,b=(t.match(/<[A-Z][^>]*>/g)||[]).length,w=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,C=0;for(let T of r)if(/@(?:if|unless|foreach|for|while|section)\b/.test(T)&&!/@end/.test(T)&&!/@else/.test(T))C++,S=Math.max(S,C);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(T))C--;let v=S>=4?3:0,x=Math.min(10,Math.ceil(l.total*0.5+m*0.1+b*0.3+(a>10?a*0.05:0)+v));return{lines:r.length,characters:t.length,directives:l,expressions:m,components:b,layouts:w,scriptLines:a,complexity:x}}function Nn(t,r){let s=[],p=Kt(t,"if","endif");if(p>0)s.push({type:"error",category:"syntax",message:`Found ${p} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let a=Kt(t,"foreach","endforeach");if(a>0)s.push({type:"error",category:"syntax",message:`Found ${a} unmatched @foreach directive(s)`,suggestion:"Ensure every @foreach has a corresponding @endforeach"});let l=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(l&&l.length>0)s.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let f=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(f>0)s.push({type:"warning",category:"security",message:`Found ${f} raw output expression(s) {!! !!}`,suggestion:"Ensure raw outputs are properly sanitized to prevent XSS"});let u=t.match(/<img[^>]*>/g);if(u){let b=u.filter((w)=>!w.includes("alt="));if(b.length>0)s.push({type:"warning",category:"accessibility",message:`Found ${b.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let y=t.split(`
5
5
  `).filter((b)=>b.length>120);if(y.length>0)s.push({type:"info",category:"maintainability",message:`Found ${y.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let m=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(m>3)s.push({type:"info",category:"maintainability",message:`Found ${m} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return s}function Un(t,r){let s=[];if(r.complexity>7)s.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(r.complexity>5&&r.directives.total>8)s.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(r.lines>100&&r.components===0)s.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(r.expressions>20)s.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let p=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(p&&p.length>0)s.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(r.directives.total===0&&r.expressions<5)s.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(r.scriptLines>50)s.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return s}function Wn(t,r){let s=1;if(s+=r.directives.conditionals*0.1,s+=r.directives.loops*0.5,s+=r.directives.includes*2,s+=r.expressions*0.05,s+=r.components*1,r.scriptLines>10)s+=r.scriptLines*0.1;let p;if(r.expressions===0&&r.directives.total===0)p="high";else if(r.expressions<5&&r.directives.total<3)p="medium";else p="low";let a=[];if(s>10)a.push("Consider optimizing template complexity");if(p==="low"&&r.directives.total>5)a.push("Reduce dynamic content for better caching");if(r.components===0&&r.lines>40)a.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(s*100)/100,complexityScore:r.complexity,cacheability:p,recommendations:a}}function Kt(t,r,s){let p=t.replace(/<!--[\s\S]*?-->/g,""),a=(p.match(new RegExp(`@${r}\\b`,"g"))||[]).length,l=(p.match(new RegExp(`@${s}\\b`,"g"))||[]).length;return Math.abs(a-l)}async function yi(t=["**/*.stx"],r){let s=[],p=[];for(let l of t){let f=await Array.fromAsync(new Bun.Glob(l).scan({cwd:r||process.cwd(),onlyFiles:!0,absolute:!0}));p.push(...f.filter((u)=>u.endsWith(".stx")))}for(let l of p)try{let f=await Fn(l);s.push(f)}catch(f){console.warn(`Failed to analyze ${l}:`,f)}let a=Vn(s);return{results:s,summary:a}}function Vn(t){let r=t.length,s=t.reduce((m,b)=>m+b.metrics.lines,0),p=r>0?t.reduce((m,b)=>m+b.metrics.complexity,0)/r:0,a=t.reduce((m,b)=>m+b.issues.length,0),l={};t.forEach((m)=>{m.issues.forEach((b)=>{l[b.category]=(l[b.category]||0)+1})});let f=r>0?t.reduce((m,b)=>m+b.performance.estimatedRenderTime,0)/r:0,u=Math.max(1,Math.min(10,Math.round(10-f/2-p/2))),y=[];if(p>6)y.push("Project has high average complexity. Consider refactoring complex templates.");if(a>r*2)y.push("High number of issues detected. Run detailed analysis on individual files.");if(l.security>0)y.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:r,totalLines:s,avgComplexity:Math.round(p*100)/100,totalIssues:a,issuesByCategory:l,performanceScore:u,recommendations:y}}import{mkdir as qn,readFile as Xn,readdir as Gn,stat as Xt,writeFile as Jn}from"fs/promises";import Re from"path";function en(t){if(t==="connectedCallback")return`method "${t}" is reserved; define "onConnect" instead, which the element calls once it is connected, rendered and bound`;if(t==="disconnectedCallback")return`method "${t}" is reserved; define "onDisconnect" instead, which the element calls as it leaves the DOM, before it releases its own listeners`;return`method "${t}" is reserved`}var tn=new Set(["constructor","connectedCallback","disconnectedCallback","attributeChangedCallback","adoptedCallback"]);function Yn(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((r)=>r.charAt(0).toUpperCase()+r.slice(1)).join("")}function jt(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function er(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function nr(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function rr(t){let r=[];async function s(p){let a=await Gn(p,{withFileTypes:!0});a.sort((l,f)=>l.name.localeCompare(f.name));for(let l of a){let f=Re.join(p,l.name);if(l.isDirectory()){if(!l.name.startsWith(".")&&l.name!=="node_modules")await s(f)}else if(l.isFile()&&l.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(l.name))r.push(f)}}return await s(t),r}function or(t,r){let s=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!s)return{};let p=s[1].trim();if(!p)return{};try{return JSON.parse(p)}catch(a){throw Error(`${r}: <script component> must contain JSON metadata (${a.message})`)}}function sr(t,r){let s={},p=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let a of p){if(!/\bclient\b/i.test(a[1])||/\bcomponent\b|\bstx:component\b/i.test(a[1]))continue;let l;try{l=new Bun.Transpiler({loader:"ts"}).transformSync(a[2])}catch(y){throw Error(`${r}: failed to transpile <script client> (${y.message})`)}let f=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,u;while(u=f.exec(l)){let y=u[1];if(tn.has(y))throw Error(`${r}: client ${en(y)}`);let m=f.lastIndex,b=1,w="",S=!1,C=m;for(;C<l.length&&b>0;C++){let x=l[C];if(S){S=!1;continue}if(w){if(x==="\\")S=!0;else if(x===w)w="";continue}if(x==='"'||x==="'"||x==="`")w=x;else if(x==="{")b++;else if(x==="}")b--}if(b!==0)throw Error(`${r}: unterminated client function "${y}"`);let v=u[0].includes("async")?"async ":"";s[y]=`${v}${y}(${u[2]}) {${l.slice(m,C-1)}}`,f.lastIndex=C}}return s}function ir(t){let r=t.match(/<template\b(?![^>]*\bshadowrootmode\b)[^>]*>([\s\S]*?)<\/template>/i);return(r?r[1]:t).replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").trim()}function Gt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((r)=>r[1].trim()).filter(Boolean).join(`
@@ -876,7 +876,7 @@ else {
876
876
  };
877
877
  })();
878
878
  </script>
879
- `}function Ne(t,r,s={}){let p=zr(r,s),a=t.lastIndexOf("</body>");if(a!==-1)return t.slice(0,a)+p+t.slice(a);if(t.includes("</html>"))return t.replace("</html>",`${p}</html>`);return t+p}function yt(t){let r=t.toLowerCase();return r.endsWith(".css")||r.endsWith(".scss")||r.endsWith(".sass")||r.endsWith(".less")}function bt(t){let r=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((p)=>r.endsWith(p))}function Tt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((s)=>s.test(t))}var tt=null;function $t(t){if(!tt)tt=new on(t);return tt}function st(){if(tt)tt.stop(),tt=null}import Rt from"path";var nt={name:"bun-plugin-stx",async setup(t){let s={...await i(),...t.config?.stx},p=new Set,a=s.webComponents?.enabled?`./${Rt.relative(Rt.dirname(t.config?.outdir||"dist"),s.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(s.webComponents?.enabled)try{let f=await Jr(s,p);if(l.push(...f),s.debug&&f.length>0)console.log(`Successfully built ${f.length} web components`)}catch(f){console.error("Failed to build web components:",f)}t.onLoad({filter:/\.stx$/},async({path:f})=>{try{let u=new Set;if(s.cache&&s.cachePath){let x=await Zn(f,s);if(x){if(s.debug)console.log(`Using cached version of ${f}`);return{contents:x,loader:"html"}}}let y=await xe(()=>Bun.file(f).text(),"",(x)=>{throw new fr(`Failed to read stx file: ${f}`,f,void 0,void 0,`File read error: ${x.message}`)});if(!y)throw new fr(`stx file is empty: ${f}`,f);let{scriptContent:m,templateContent:b,allScripts:w}=se.time("script-extraction",()=>{let x=y,T=ue(y);if(T)x=T.content.trim();let k=y.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],I="",A=[];for(let E of k){let _=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",j=E.match(/<script\b([^>]*)>/i),K=j?j[1]:"";if(/\bserver\b/i.test(K))I=_;else A.push(E)}let M=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:I,templateContent:M,allScripts:A}}),S={__filename:f,__dirname:Rt.dirname(f),__stx:{webComponentsPath:a,builtComponents:l}};await xe(()=>g(m,S,f),void 0,(x)=>{let T=new ie(`Script execution failed in ${f}: ${x.message}`,f,void 0,void 0,m.substring(0,100));if(D.log(T,{filePath:f,scriptContent:m}),s.debug)throw T});let v=await se.timeAsync("directive-processing",async()=>await o(b,S,f,s,u));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-qjmvcqfh.js"),T=x(w.join(`
879
+ `}function Ne(t,r,s={}){let p=zr(r,s),a=t.lastIndexOf("</body>");if(a!==-1)return t.slice(0,a)+p+t.slice(a);if(t.includes("</html>"))return t.replace("</html>",`${p}</html>`);return t+p}function yt(t){let r=t.toLowerCase();return r.endsWith(".css")||r.endsWith(".scss")||r.endsWith(".sass")||r.endsWith(".less")}function bt(t){let r=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((p)=>r.endsWith(p))}function Tt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((s)=>s.test(t))}var tt=null;function $t(t){if(!tt)tt=new on(t);return tt}function st(){if(tt)tt.stop(),tt=null}import Rt from"path";var nt={name:"bun-plugin-stx",async setup(t){let s={...await i(),...t.config?.stx},p=new Set,a=s.webComponents?.enabled?`./${Rt.relative(Rt.dirname(t.config?.outdir||"dist"),s.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(s.webComponents?.enabled)try{let f=await Jr(s,p);if(l.push(...f),s.debug&&f.length>0)console.log(`Successfully built ${f.length} web components`)}catch(f){console.error("Failed to build web components:",f)}t.onLoad({filter:/\.stx$/},async({path:f})=>{try{let u=new Set;if(s.cache&&s.cachePath){let x=await Zn(f,s);if(x){if(s.debug)console.log(`Using cached version of ${f}`);return{contents:x,loader:"html"}}}let y=await xe(()=>Bun.file(f).text(),"",(x)=>{throw new fr(`Failed to read stx file: ${f}`,f,void 0,void 0,`File read error: ${x.message}`)});if(!y)throw new fr(`stx file is empty: ${f}`,f);let{scriptContent:m,templateContent:b,allScripts:w}=se.time("script-extraction",()=>{let x=y,T=ue(y);if(T)x=T.content.trim();let k=y.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],I="",A=[];for(let E of k){let _=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",j=E.match(/<script\b([^>]*)>/i),K=j?j[1]:"";if(/\bserver\b/i.test(K))I=_;else A.push(E)}let M=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:I,templateContent:M,allScripts:A}}),S={__filename:f,__dirname:Rt.dirname(f),__stx:{webComponentsPath:a,builtComponents:l}};await xe(()=>g(m,S,f),void 0,(x)=>{let T=new ie(`Script execution failed in ${f}: ${x.message}`,f,void 0,void 0,m.substring(0,100));if(D.log(T,{filePath:f,scriptContent:m}),s.debug)throw T});let v=await se.timeAsync("directive-processing",async()=>await o(b,S,f,s,u));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-3vjzezn1.js"),T=x(w.join(`
880
880
  `),S),k=v.search(/<\/body>/i);if(k!==-1)v=v.slice(0,k)+T+`
881
881
  `+v.slice(k);else v+=`
882
882
  ${T}`}if(v=await ye(v),u.forEach((x)=>p.add(x)),s.cache&&s.cachePath){if(await Qn(f,v,u,s),s.debug)console.log(`Cached template ${f} with ${u.size} dependencies`)}return{contents:v,loader:"html"}}catch(u){let y=u instanceof Error?u:new ie(`Plugin processing failed: ${String(u)}`,f);if(D.log(y,{filePath:f,buildConfig:t.config}),bn.logDetailedError(y,{filePath:f,plugin:"bun-plugin-stx"}),s.debug)console.error("stx Plugin Error:",y);let m=y,b=m.line||null,w=m.context||null;return{contents:s.debug||W()?`<!DOCTYPE html>
@@ -939,7 +939,7 @@ ${T}`}if(v=await ye(v),u.forEach((x)=>p.add(x)),s.cache&&s.cachePath){if(await Q
939
939
  <h1>Something went wrong</h1>
940
940
  <p>An internal error occurred. Please try again later.</p>
941
941
  </body>
942
- </html>`,loader:"html"}}})}};async function Cr(t,r={}){let s=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||s+1,u=ge.resolve(t);if(!Be.existsSync(u))return console.error(`${e.red}Error: File not found: ${e.bright}${u}${e.reset}`),!1;if(u.endsWith(".md"))return Ft(u,r);else if(!u.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${u}${e.reset}. Only .stx and .md files are supported.`),!1;let y=c(process.cwd(),"output");Be.mkdirSync(y,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let m=null,b=async()=>{try{let _={name:"public-assets",setup(we){we.onResolve({filter:/^\/(images|fonts|assets|public)\//},(le)=>({path:le.path,external:!0}))}},j=await Bun.build({entrypoints:[u],outdir:y,plugins:[_,nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!j.success)return console.error(`${e.red}Build failed:${e.reset}`,j.logs),!1;let K=j.outputs.find((we)=>we.path.endsWith(".html"));if(!K)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return m=await Bun.file(K.path).text(),!0}catch(_){return console.error(`${e.red}Error building stx file:${e.reset}`,_),!1}};if(!await b())return!1;let S=ge.dirname(u);await nn(S);let C=s;try{if(C=await We(s),C!==s)console.log(`${e.yellow}Port ${s} is busy, using port ${C} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(a){let _=r.hmrPort||C+1;l=$t({wsPort:_,verbose:!1}),f=l.start(_)}let v={},x=null,T;try{let{loadStxConfig:_}=await import("./chunk-bhm9sdnv.js"),j=await _();if(T=r.stxOptions?.serverApi??j.serverApi,j?.apiRouter)x=j?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(j?.apiRoutes){v=j.apiRoutes;let K=Object.keys(v).length;if(K>0)console.log(`${e.blue}Loaded ${e.bright}${K} API route${K>1?"s":""}${e.reset}`)}if(j?.broadcasting?.enabled)try{let{startBroadcasting:K,loadChannels:Y}=await import("./chunk-9rv27cdd.js"),we=j.broadcasting;await K(we);let le=we.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${le}/ws${e.reset}`);let Pe=ge.join(process.cwd(),"channels.ts");if(Be.existsSync(Pe))try{let ne=await Y(Pe);console.log(`${e.blue}Loaded ${e.bright}${ne} broadcast channel${ne!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ne){console.warn(`${e.yellow}Failed to load channels.ts: ${ne.message}${e.reset}`)}}catch(K){console.warn(`${e.yellow}Broadcasting failed to start: ${K.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:I}=await import("./chunk-zf6kmw9q.js"),A=await k(process.cwd(),T);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${C}/${e.reset}...`),a)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${f}${e.reset}`);let M=Nr({port:C,async fetch(_){return kn(_,await(async()=>{let j=new URL(_.url);if([y,ge.dirname(u),ge.join(process.cwd(),"public")].some((ne)=>I(ge.join(ne,j.pathname),process.cwd(),T)))return new Response("Not Found",{status:404});if(x)try{let ne=await x.handleRequest(_);if(ne.status!==404)return ne}catch{}if(v[j.pathname])try{return await v[j.pathname](_)}catch(ne){return new Response(JSON.stringify({error:ne.message}),{status:500,headers:{"Content-Type":"application/json"}})}let K=await A(_);if(K)return K;if(j.pathname==="/")return(async()=>{let F=await h(m||"");if(a)F=Ne(F,f);if(r.native)if(F.includes("<head>"))F=F.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else if(F.includes("<html"))F=F.replace(/(<html[^>]*>)/,"$1<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>");else F="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+F;if(r.titlebarHidden)if(F.includes("<head>"))F=F.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else if(F.includes("<html"))F=F.replace(/(<html[^>]*>)/,"$1<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>");else F=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${F}`;return F})().then((F)=>new Response(F,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Y=ge.join(y,j.pathname);if(Be.existsSync(Y)&&Be.statSync(Y).isFile()){let ne=Bun.file(Y),F=ge.extname(Y).toLowerCase(),L="text/plain";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}let we=ge.dirname(u),le=ge.join(we,j.pathname);if(Be.existsSync(le)&&Be.statSync(le).isFile()){let ne=Bun.file(le),F=ge.extname(le).toLowerCase(),L="text/plain";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}let Pe=ge.join(process.cwd(),"public",j.pathname);if(Be.existsSync(Pe)&&Be.statSync(Pe).isFile()){let ne=Bun.file(Pe),F=ge.extname(Pe).toLowerCase(),L="application/octet-stream";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}return new Response("Not Found",{status:404})})())},error(_){return new Response(`<pre>${_}
942
+ </html>`,loader:"html"}}})}};async function Cr(t,r={}){let s=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||s+1,u=ge.resolve(t);if(!Be.existsSync(u))return console.error(`${e.red}Error: File not found: ${e.bright}${u}${e.reset}`),!1;if(u.endsWith(".md"))return Ft(u,r);else if(!u.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${u}${e.reset}. Only .stx and .md files are supported.`),!1;let y=c(process.cwd(),"output");Be.mkdirSync(y,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let m=null,b=async()=>{try{let _={name:"public-assets",setup(we){we.onResolve({filter:/^\/(images|fonts|assets|public)\//},(le)=>({path:le.path,external:!0}))}},j=await Bun.build({entrypoints:[u],outdir:y,plugins:[_,nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!j.success)return console.error(`${e.red}Build failed:${e.reset}`,j.logs),!1;let K=j.outputs.find((we)=>we.path.endsWith(".html"));if(!K)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return m=await Bun.file(K.path).text(),!0}catch(_){return console.error(`${e.red}Error building stx file:${e.reset}`,_),!1}};if(!await b())return!1;let S=ge.dirname(u);await nn(S);let C=s;try{if(C=await We(s),C!==s)console.log(`${e.yellow}Port ${s} is busy, using port ${C} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(a){let _=r.hmrPort||C+1;l=$t({wsPort:_,verbose:!1}),f=l.start(_)}let v={},x=null,T;try{let{loadStxConfig:_}=await import("./chunk-m5y0tgax.js"),j=await _();if(T=r.stxOptions?.serverApi??j.serverApi,j?.apiRouter)x=j?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(j?.apiRoutes){v=j.apiRoutes;let K=Object.keys(v).length;if(K>0)console.log(`${e.blue}Loaded ${e.bright}${K} API route${K>1?"s":""}${e.reset}`)}if(j?.broadcasting?.enabled)try{let{startBroadcasting:K,loadChannels:Y}=await import("./chunk-9rv27cdd.js"),we=j.broadcasting;await K(we);let le=we.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${le}/ws${e.reset}`);let Pe=ge.join(process.cwd(),"channels.ts");if(Be.existsSync(Pe))try{let ne=await Y(Pe);console.log(`${e.blue}Loaded ${e.bright}${ne} broadcast channel${ne!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ne){console.warn(`${e.yellow}Failed to load channels.ts: ${ne.message}${e.reset}`)}}catch(K){console.warn(`${e.yellow}Broadcasting failed to start: ${K.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:I}=await import("./chunk-9m1agnnx.js"),A=await k(process.cwd(),T);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${C}/${e.reset}...`),a)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${f}${e.reset}`);let M=Nr({port:C,async fetch(_){return kn(_,await(async()=>{let j=new URL(_.url);if([y,ge.dirname(u),ge.join(process.cwd(),"public")].some((ne)=>I(ge.join(ne,j.pathname),process.cwd(),T)))return new Response("Not Found",{status:404});if(x)try{let ne=await x.handleRequest(_);if(ne.status!==404)return ne}catch{}if(v[j.pathname])try{return await v[j.pathname](_)}catch(ne){return new Response(JSON.stringify({error:ne.message}),{status:500,headers:{"Content-Type":"application/json"}})}let K=await A(_);if(K)return K;if(j.pathname==="/")return(async()=>{let F=await h(m||"");if(a)F=Ne(F,f);if(r.native)if(F.includes("<head>"))F=F.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else if(F.includes("<html"))F=F.replace(/(<html[^>]*>)/,"$1<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>");else F="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+F;if(r.titlebarHidden)if(F.includes("<head>"))F=F.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else if(F.includes("<html"))F=F.replace(/(<html[^>]*>)/,"$1<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>");else F=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${F}`;return F})().then((F)=>new Response(F,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Y=ge.join(y,j.pathname);if(Be.existsSync(Y)&&Be.statSync(Y).isFile()){let ne=Bun.file(Y),F=ge.extname(Y).toLowerCase(),L="text/plain";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}let we=ge.dirname(u),le=ge.join(we,j.pathname);if(Be.existsSync(le)&&Be.statSync(le).isFile()){let ne=Bun.file(le),F=ge.extname(le).toLowerCase(),L="text/plain";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}let Pe=ge.join(process.cwd(),"public",j.pathname);if(Be.existsSync(Pe)&&Be.statSync(Pe).isFile()){let ne=Bun.file(Pe),F=ge.extname(Pe).toLowerCase(),L="application/octet-stream";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}return new Response("Not Found",{status:404})})())},error(_){return new Response(`<pre>${_}
943
943
  ${_.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
944
944
  ${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
945
945
  ${e.bright}\u2192 ${e.cyan}http://localhost:${C}/${e.reset}`),console.log(`
@@ -1426,12 +1426,12 @@ ${v.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),con
1426
1426
  ${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
1427
1427
  ${e.bright}\u2192 ${e.cyan}http://localhost:${b}/${e.reset}`),console.log(`
1428
1428
  ${e.yellow}Routes:${e.reset}`);let S=new Set(u.map((v)=>v.routeTemplate)),C=Object.entries(f).filter(([v])=>!S.has(v)).sort(([v],[x])=>v.localeCompare(x)).map(([v,x])=>({route:v==="/"?"/":v,filePath:Ee.relative(process.cwd(),x.filePath),fileType:x.fileType}));for(let v of u){let x=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");C.push({route:x,filePath:Ee.relative(process.cwd(),v.filePath),fileType:"stx"})}if(C.sort((v,x)=>v.route.localeCompare(x.route)),C.forEach((v,x)=>{let k=x===C.length-1?"\u2514\u2500 ":"\u251C\u2500 ",I=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${k}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${I}`)}),console.log(`
1429
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(w.url.toString(),()=>{if(p)Xe.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Xe.watch(l,{recursive:!0},async(x,T)=>{if(!T)return;if(T.endsWith(".stx")||T.endsWith(".js")||T.endsWith(".ts")||T.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${T}${e.yellow} changed, rebuilding...${e.reset}`),Ke.clear(),pe(),await y()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function an(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Wr}=globalThis.Bun;import me from"fs";import te from"path";async function ln(t){try{return un(await Bun.file(t).text())}catch{return}}function zt(t){let r=Bun.file(t),s=te.extname(t).toLowerCase(),p={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(s)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(r,{headers:{"Content-Type":p[s]||"application/octet-stream",...l}})}async function Tr(t=".",r={}){let s=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||s+1,u=te.resolve(t),{loadStxConfig:y}=await import("./chunk-bhm9sdnv.js"),m=await y(u),{createServerApi:b,isServerApiSource:w}=await import("./chunk-zf6kmw9q.js"),S=r.stxOptions?.serverApi??m.serverApi,C=await b(u,S),v=m.root&&m.root!=="."?te.join(u,m.root):u,x=r.pagesDir||m.pagesDir||"pages",T=te.join(v,x);if(!me.existsSync(T)&&!m._layerPageDirs?.some((P)=>me.existsSync(P)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${T}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=q(v,{pagesDir:x,pagesDirs:m._layerPageDirs?[T,...m._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${T}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let I=m?._pluginPageDirs||[],A=[];for(let{dir:P,prefix:H}of I)if(me.existsSync(P)){let z=q(te.dirname(P),{pagesDir:te.basename(P)});for(let Q of z){let X=H==="/"?Q.pattern:`${H}${Q.pattern==="/"?"":Q.pattern}`;A.push({route:{...Q,pattern:X},prefix:H})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${H}${e.reset}`)}let M=new Map,E=null,_=null;if(r.stxOptions?.shell!==!1){if(_=await Ai(u,r.stxOptions?.shell),_){if(E=await Hs(_,r.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(u,_)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}wt(),await St(u);let j=xt();if(j.length>0)console.log(`${e.blue}Loaded ${e.bright}${j.length}${e.blue} middleware: ${e.dim}${j.join(", ")}${e.reset}`);let K={},Y=null;try{let{loadStxConfig:P}=await import("./chunk-bhm9sdnv.js"),H=await P(u);if(H?.apiRouter)Y=H?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(H?.apiRoutes){K=H.apiRoutes;let z=Object.keys(K).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(H?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:Q}=await import("./chunk-9rv27cdd.js"),X=H.broadcasting;await z(X);let Oe=X.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Oe}/ws${e.reset}`);let Se=te.join(process.cwd(),"channels.ts");if(me.existsSync(Se))try{let N=await Q(Se);console.log(`${e.blue}Loaded ${e.bright}${N} broadcast channel${N!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(N){console.warn(`${e.yellow}Failed to load channels.ts: ${N.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let we=c(u,"output");me.mkdirSync(we,{recursive:!0});let le=new Map,Pe=new Set,ne=async(P)=>{let H=rs(T,P);if(!H)return null;try{let z=await Bun.build({entrypoints:[H],outdir:we,plugins:[nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!z.success)return null;let Q=z.outputs.find((X)=>X.path.endsWith(".html"));if(!Q)return null;return await Bun.file(Q.path).text()}catch{return null}},F=new Map,L=async(P,H)=>{try{let{processDirectives:z,extractVariables:Q,defaultConfig:X,loadStxConfig:Oe,injectRouterScript:Se}=await import("./chunk-bhm9sdnv.js"),{checkCache:N,cacheTemplate:J,readFileCached:V,templateCache:de}=await import("./chunk-bxr4c8rg.js"),G=await Oe(u),Ue=(ae)=>{if(!ae)return ae;if(te.isAbsolute(ae))return ae;return te.resolve(u,ae)},ce={...X,...G,...r.stxOptions,autoShell:!0};if(r.debugDirectives)ce.debug=!0;ce.partialsDir=Ue(ce.partialsDir),ce.componentsDir=Ue(ce.componentsDir),ce.layoutsDir=Ue(ce.layoutsDir),ce.storesDir=Ue(ce.storesDir||"stores"),ce.cachePath=Ue(ce.cachePath)??c(u,"cache");let B=!H&&!r.profile,re=ce.cache!==!1;if(re&&B){let ae=de.get(P.filePath);if(ae)try{if((await me.promises.stat(P.filePath)).mtime.getTime()<=ae.mtime){let He=!0;for(let Ce of ae.dependencies){if(!me.existsSync(Ce)){He=!1;break}if((await me.promises.stat(Ce)).mtime.getTime()>ae.mtime){He=!1;break}}if(He){let Ce=ae.output;if(E)Ce=Ve(Ce,{preserveHead:!0});let ot=F.get(P.filePath);return{route:P,content:Ce,status:ot?.status??await ln(P.filePath),headers:ot?.headers}}}}catch{}let Ie=await N(P.filePath,ce);if(Ie){let je=Ie;if(E)je=Ve(je,{preserveHead:!0});let He=F.get(P.filePath);return{route:P,content:je,status:He?.status??await ln(P.filePath),headers:He?.headers}}}let Z=re?await V(P.filePath):await Bun.file(P.filePath).text(),oe=un(Z),{classifyAllScripts:fe}=await import("./chunk-bhm9sdnv.js"),U=fe(Z),Le=U.server.map((ae)=>ae.content),De=Z;for(let ae of U.server)De=De.replace(ae.fullTag,"");let ee={__filename:P.filePath,__dirname:te.dirname(P.filePath),__stx_options:ce,params:H??{},__stx_runtime_head:{}};for(let ae of Le)try{await Q(ae,ee,P.filePath)}catch(Ie){if(r.stxOptions?.debug)console.error("[stx] variable extraction error",P.filePath,Ie?.message||Ie)}let Ae=new Set,be;if(r.profile){let ae=performance.now();be=await z(De,ee,P.filePath,ce,Ae);let Ie=performance.now()-ae,je=te.relative(u,P.filePath)||P.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else be=await z(De,ee,P.filePath,ce,Ae);if(!E)be=await Se(be,{router:ce.router});{let{interpolateScriptExpressions:ae}=await import("./chunk-qjmvcqfh.js");be=be.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,je,He)=>{if(!/function\s+__stx_setup_/.test(He))return Ie;return`<script${je}>${ae(He,ee)}</script>`})}if(E)be=Ve(be,{preserveHead:!0});if(re&&B)await J(P.filePath,be,Ae,ce);let{extractStreamBoundaries:at}=await import("./chunk-mn9xw0fe.js"),Qe=at(ee),rt=ee.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let ae=ee.streamBoundaries||{},Ie={...ce,autoShell:!1},je=Object.keys(rt).map((Ce)=>({id:Ce,render:async()=>{let ot=typeof ae[Ce]==="function"?await ae[Ce]():void 0;return z(rt[Ce],{...ee,$boundary:ot},P.filePath,Ie,new Set)}})),He=new Set(je.map((Ce)=>Ce.id));Qe=[...(Qe||[]).filter((Ce)=>!He.has(Ce.id)),...je]}if(Qe&&Qe.length>0)Pe.add(P.pattern);else Qe=void 0;let Wt=At(ee),Vt=Pt(ee);if(B)F.set(P.filePath,{status:Wt,headers:Vt});return{route:P,content:be,status:Wt??oe,headers:Vt,boundaries:Qe}}catch(z){return console.error(`${e.red}Error building ${e.bright}${P.pattern}${e.reset}:`,z),null}},Fe=8,ze=async()=>{let P=new Set(le.keys()),H=new Set(M.keys());le.clear(),M.clear();let z=r.prebuild===!1?k.filter((X)=>P.has(X.pattern)):k,Q=r.prebuild===!1?A.filter(({route:X})=>H.has(X.pattern)):A;for(let X=0;X<z.length;X+=Fe){let Oe=z.slice(X,X+Fe),Se=await Promise.all(Oe.map((N)=>L(N)));for(let N of Se)if(N)le.set(N.route.pattern,N)}for(let X=0;X<Q.length;X+=Fe){let Oe=Q.slice(X,X+Fe),Se=await Promise.all(Oe.map(({route:N})=>L(N)));for(let N of Se)if(N)M.set(N.route.pattern,N)}return le.size>0};if(console.log(`${e.blue}${r.prebuild===!1?"Rendering pages on request...":"Building pages..."}${e.reset}`),!(r.prebuild===!1?k.length+A.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await nn(u);let Ge=s;try{if(Ge=await We(s),Ge!==s)console.log(`${e.yellow}Port ${s} is busy, using port ${Ge} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(a){let P=r.hmrPort||Ge+1;l=$t({wsPort:P,verbose:!1}),f=l.start(P)}let Ot=(P,H)=>{let Q=`<script data-stx-route-params>(function(){var p=${JSON.stringify(H).replace(/</g,"\\u003C").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;if(P.includes("</head>"))return P.replace("</head>",`${Q}</head>`);if(P.includes("<body"))return P.replace(/<body([^>]*)>/,`<body$1>${Q}`);return Q+P};console.log(`${e.blue}Starting server...${e.reset}`);let Dt=Wr({port:Ge,hostname:r.hostname,async fetch(P){let H=new URL(P.url),z=r.stxOptions?.offline??m.offline;if(H.pathname===to&&z?.enabled){if(!["GET","HEAD"].includes(P.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});return new Response(P.method==="HEAD"?null:no(z,Lr()),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let Q=m?.publicDir||"public",X=te.join(u,Q,H.pathname),Oe=te.join(u,H.pathname),Se=te.join(we,H.pathname);if([X,Oe,Se].some((B)=>w(B,u,S)))return new Response("Not Found",{status:404});let[N,J,V]=await Promise.all([me.promises.stat(X).catch(()=>null),me.promises.stat(Oe).catch(()=>null),me.promises.stat(Se).catch(()=>null)]);if(N?.isFile()&&!w(X,u,S))return zt(X);if(J?.isFile()&&!w(Oe,u,S))return zt(Oe);if(V?.isFile()&&!w(Se,u,S))return zt(Se);if(H.pathname.startsWith("/_stx/component/")){let B=decodeURIComponent(H.pathname.slice(16));if(B)try{let re=`<${B} />`,Z={...buildConfig,autoShell:!1},oe=await processDirectives(re,{},te.join(u,"components",`${B}.stx`),Z,new Set);return new Response(oe,{headers:{"Content-Type":"text/html"}})}catch(re){return new Response(`<div class="stx-async-error">${re.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(H.pathname==="/_stx/img"){let{handleImageRequest:B}=await import("./chunk-ykjzhfyf.js"),re=await B(P,{publicDir:te.join(u,Q),cacheDir:c(u,"cache","img")});if(re)return re}if(Y)try{let B=await Y.handleRequest(P);if(B.status!==404)return B}catch{}if(K[H.pathname])try{return await K[H.pathname](P)}catch(B){return new Response(JSON.stringify({error:B.message}),{status:500,headers:{"Content-Type":"application/json"}})}let de=await C(P);if(de)return de;let G=tr(H.pathname,k);if(G){let B=le.get(G.route.pattern),re=Pe.has(G.route.pattern);if(!B||G.route.isDynamic&&Object.keys(G.params).length>0||re){let Z=await L(G.route,G.params);if(Z){if(B=Z,!G.route.isDynamic&&!re)le.set(G.route.pattern,Z)}}if(B){let Z=B.status??200,oe=B.headers??{},fe=(G.route.filePath?gt(await Bun.file(G.route.filePath).text().catch(()=>"")):null)??{};if(fe.validate){if(!await fe.validate({params:G.params})){let De=await ne(404);if(De){let ee=De;if(ee=await h(ee,u),a)ee=Ne(ee,f);return new Response(ee,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(fe.middleware){let Le=kt(H.pathname,G.params,fe,H.search),De=_t(Le,null,P,{isServer:!0}),ee=await Ct(fe.middleware,De);if(ee.redirect){let Ae=ee.redirect.path,be=ee.redirect.options.redirectCode||302,at=new Headers(ee.responseHeaders);return at.set("Location",Ae),new Response(null,{status:be,headers:at})}if(ee.abort){let{statusCode:Ae,message:be}=ee.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${Ae}</title></head><body><h1>Error ${Ae}</h1><p>${be}</p></body></html>`,{status:Ae,headers:{"Content-Type":"text/html"}})}if(Object.keys(ee.state).length>0){let Ae=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(ee.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;B.content=B.content.replace("</head>",`${Ae}</head>`)}}let U=B.content;if(E&&Pi(P)){let Le=Ye(U),De=he(U),ee=U.match(/<title[^>]*>([\s\S]*?)<\/title>/i),Ae=ee?Ri(ee[1].trim()):"";if(Object.keys(G.params).length>0)U=Ot(U,G.params);U=await h(U,u);let be=m?.router?.container||"main";return U=_e(U,be),new Response(U,{status:Z,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":De?"true":"false",...Ae&&{"X-STX-Title":encodeURIComponent(Ae)},[oa]:Lr(),...O(),"Cache-Control":ut}})}if(E)U=Pr(E,U);if(Object.keys(G.params).length>0)U=Ot(U,G.params);if(U=await h(U,u),a)U=Ne(U,f);if(r.native)if(U.includes("<head>"))U=U.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else U="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+U;if(r.titlebarHidden)if(U.includes("<head>"))U=U.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else U=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${U}`;if(B.boundaries&&B.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:De}=await import("./chunk-mn9xw0fe.js");return De(Le(U,B.boundaries,{timeoutMs:30000}),{status:Z,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(U,{status:Z,headers:{"Content-Type":"text/html",...O(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...oe}})}}if(A.length>0){let B=A.map((Z)=>Z.route),re=tr(H.pathname,B);if(re){let Z=M.get(re.route.pattern);if(!Z||re.route.isDynamic){let oe=await L(re.route,re.params);if(oe){if(Z=oe,!re.route.isDynamic)M.set(re.route.pattern,oe)}}if(Z){let oe=Z.content;if(E)oe=Pr(E,oe);if(Object.keys(re.params).length>0)oe=Ot(oe,re.params);if(oe=await h(oe,u),a)oe=Ne(oe,f);return new Response(oe,{status:Z.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:Z}of I)if(Z!=="/"&&H.pathname.startsWith(Z)){let oe=M.get(Z)||M.get(Z+"/");if(!oe){let fe=A.find(({route:U})=>U.pattern===Z||U.pattern===`${Z}/`);if(fe){let U=await L(fe.route);if(U)oe=U,M.set(fe.route.pattern,U)}}if(oe){let fe=oe.content;if(E)fe=Pr(E,fe);if(fe=await h(fe,u),a)fe=Ne(fe,f);return new Response(fe,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(vt(H.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Ue=le.get("/");if(Ue){let B=Ue.content;if(B=await h(B,u),a)B=Ne(B,f);if(r.native)if(B.includes("<head>"))B=B.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else B="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+B;return new Response(B,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let ce=await ne(404);if(ce){let B=ce;if(B=await h(B,u),a)B=Ne(B,f);return new Response(B,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(P){let H=await ne(500);if(H)return new Response(H,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${P}
1429
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(w.url.toString(),()=>{if(p)Xe.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Xe.watch(l,{recursive:!0},async(x,T)=>{if(!T)return;if(T.endsWith(".stx")||T.endsWith(".js")||T.endsWith(".ts")||T.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${T}${e.yellow} changed, rebuilding...${e.reset}`),Ke.clear(),pe(),await y()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function an(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Wr}=globalThis.Bun;import me from"fs";import te from"path";async function ln(t){try{return un(await Bun.file(t).text())}catch{return}}function zt(t){let r=Bun.file(t),s=te.extname(t).toLowerCase(),p={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(s)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(r,{headers:{"Content-Type":p[s]||"application/octet-stream",...l}})}async function Tr(t=".",r={}){let s=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||s+1,u=te.resolve(t),{loadStxConfig:y}=await import("./chunk-m5y0tgax.js"),m=await y(u),{createServerApi:b,isServerApiSource:w}=await import("./chunk-9m1agnnx.js"),S=r.stxOptions?.serverApi??m.serverApi,C=await b(u,S),v=m.root&&m.root!=="."?te.join(u,m.root):u,x=r.pagesDir||m.pagesDir||"pages",T=te.join(v,x);if(!me.existsSync(T)&&!m._layerPageDirs?.some((P)=>me.existsSync(P)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${T}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=q(v,{pagesDir:x,pagesDirs:m._layerPageDirs?[T,...m._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${T}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let I=m?._pluginPageDirs||[],A=[];for(let{dir:P,prefix:H}of I)if(me.existsSync(P)){let z=q(te.dirname(P),{pagesDir:te.basename(P)});for(let Q of z){let X=H==="/"?Q.pattern:`${H}${Q.pattern==="/"?"":Q.pattern}`;A.push({route:{...Q,pattern:X},prefix:H})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${H}${e.reset}`)}let M=new Map,E=null,_=null;if(r.stxOptions?.shell!==!1){if(_=await Ai(u,r.stxOptions?.shell),_){if(E=await Hs(_,r.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(u,_)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}wt(),await St(u);let j=xt();if(j.length>0)console.log(`${e.blue}Loaded ${e.bright}${j.length}${e.blue} middleware: ${e.dim}${j.join(", ")}${e.reset}`);let K={},Y=null;try{let{loadStxConfig:P}=await import("./chunk-m5y0tgax.js"),H=await P(u);if(H?.apiRouter)Y=H?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(H?.apiRoutes){K=H.apiRoutes;let z=Object.keys(K).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(H?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:Q}=await import("./chunk-9rv27cdd.js"),X=H.broadcasting;await z(X);let Oe=X.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Oe}/ws${e.reset}`);let Se=te.join(process.cwd(),"channels.ts");if(me.existsSync(Se))try{let N=await Q(Se);console.log(`${e.blue}Loaded ${e.bright}${N} broadcast channel${N!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(N){console.warn(`${e.yellow}Failed to load channels.ts: ${N.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let we=c(u,"output");me.mkdirSync(we,{recursive:!0});let le=new Map,Pe=new Set,ne=async(P)=>{let H=rs(T,P);if(!H)return null;try{let z=await Bun.build({entrypoints:[H],outdir:we,plugins:[nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!z.success)return null;let Q=z.outputs.find((X)=>X.path.endsWith(".html"));if(!Q)return null;return await Bun.file(Q.path).text()}catch{return null}},F=new Map,L=async(P,H)=>{try{let{processDirectives:z,extractVariables:Q,defaultConfig:X,loadStxConfig:Oe,injectRouterScript:Se}=await import("./chunk-m5y0tgax.js"),{checkCache:N,cacheTemplate:J,readFileCached:V,templateCache:de}=await import("./chunk-qkr7epna.js"),G=await Oe(u),Ue=(ae)=>{if(!ae)return ae;if(te.isAbsolute(ae))return ae;return te.resolve(u,ae)},ce={...X,...G,...r.stxOptions,autoShell:!0};if(r.debugDirectives)ce.debug=!0;ce.partialsDir=Ue(ce.partialsDir),ce.componentsDir=Ue(ce.componentsDir),ce.layoutsDir=Ue(ce.layoutsDir),ce.storesDir=Ue(ce.storesDir||"stores"),ce.cachePath=Ue(ce.cachePath)??c(u,"cache");let B=!H&&!r.profile,re=ce.cache!==!1;if(re&&B){let ae=de.get(P.filePath);if(ae)try{if((await me.promises.stat(P.filePath)).mtime.getTime()<=ae.mtime){let He=!0;for(let Ce of ae.dependencies){if(!me.existsSync(Ce)){He=!1;break}if((await me.promises.stat(Ce)).mtime.getTime()>ae.mtime){He=!1;break}}if(He){let Ce=ae.output;if(E)Ce=Ve(Ce,{preserveHead:!0});let ot=F.get(P.filePath);return{route:P,content:Ce,status:ot?.status??await ln(P.filePath),headers:ot?.headers}}}}catch{}let Ie=await N(P.filePath,ce);if(Ie){let je=Ie;if(E)je=Ve(je,{preserveHead:!0});let He=F.get(P.filePath);return{route:P,content:je,status:He?.status??await ln(P.filePath),headers:He?.headers}}}let Z=re?await V(P.filePath):await Bun.file(P.filePath).text(),oe=un(Z),{classifyAllScripts:fe}=await import("./chunk-m5y0tgax.js"),U=fe(Z),Le=U.server.map((ae)=>ae.content),De=Z;for(let ae of U.server)De=De.replace(ae.fullTag,"");let ee={__filename:P.filePath,__dirname:te.dirname(P.filePath),__stx_options:ce,params:H??{},__stx_runtime_head:{}};for(let ae of Le)try{await Q(ae,ee,P.filePath)}catch(Ie){if(r.stxOptions?.debug)console.error("[stx] variable extraction error",P.filePath,Ie?.message||Ie)}let Ae=new Set,be;if(r.profile){let ae=performance.now();be=await z(De,ee,P.filePath,ce,Ae);let Ie=performance.now()-ae,je=te.relative(u,P.filePath)||P.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else be=await z(De,ee,P.filePath,ce,Ae);if(!E)be=await Se(be,{router:ce.router});{let{interpolateScriptExpressions:ae}=await import("./chunk-3vjzezn1.js");be=be.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,je,He)=>{if(!/function\s+__stx_setup_/.test(He))return Ie;return`<script${je}>${ae(He,ee)}</script>`})}if(E)be=Ve(be,{preserveHead:!0});if(re&&B)await J(P.filePath,be,Ae,ce);let{extractStreamBoundaries:at}=await import("./chunk-qk34p70z.js"),Qe=at(ee),rt=ee.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let ae=ee.streamBoundaries||{},Ie={...ce,autoShell:!1},je=Object.keys(rt).map((Ce)=>({id:Ce,render:async()=>{let ot=typeof ae[Ce]==="function"?await ae[Ce]():void 0;return z(rt[Ce],{...ee,$boundary:ot},P.filePath,Ie,new Set)}})),He=new Set(je.map((Ce)=>Ce.id));Qe=[...(Qe||[]).filter((Ce)=>!He.has(Ce.id)),...je]}if(Qe&&Qe.length>0)Pe.add(P.pattern);else Qe=void 0;let Wt=At(ee),Vt=Pt(ee);if(B)F.set(P.filePath,{status:Wt,headers:Vt});return{route:P,content:be,status:Wt??oe,headers:Vt,boundaries:Qe}}catch(z){return console.error(`${e.red}Error building ${e.bright}${P.pattern}${e.reset}:`,z),null}},Fe=8,ze=async()=>{let P=new Set(le.keys()),H=new Set(M.keys());le.clear(),M.clear();let z=r.prebuild===!1?k.filter((X)=>P.has(X.pattern)):k,Q=r.prebuild===!1?A.filter(({route:X})=>H.has(X.pattern)):A;for(let X=0;X<z.length;X+=Fe){let Oe=z.slice(X,X+Fe),Se=await Promise.all(Oe.map((N)=>L(N)));for(let N of Se)if(N)le.set(N.route.pattern,N)}for(let X=0;X<Q.length;X+=Fe){let Oe=Q.slice(X,X+Fe),Se=await Promise.all(Oe.map(({route:N})=>L(N)));for(let N of Se)if(N)M.set(N.route.pattern,N)}return le.size>0};if(console.log(`${e.blue}${r.prebuild===!1?"Rendering pages on request...":"Building pages..."}${e.reset}`),!(r.prebuild===!1?k.length+A.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await nn(u);let Ge=s;try{if(Ge=await We(s),Ge!==s)console.log(`${e.yellow}Port ${s} is busy, using port ${Ge} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(a){let P=r.hmrPort||Ge+1;l=$t({wsPort:P,verbose:!1}),f=l.start(P)}let Ot=(P,H)=>{let Q=`<script data-stx-route-params>(function(){var p=${JSON.stringify(H).replace(/</g,"\\u003C").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;if(P.includes("</head>"))return P.replace("</head>",`${Q}</head>`);if(P.includes("<body"))return P.replace(/<body([^>]*)>/,`<body$1>${Q}`);return Q+P};console.log(`${e.blue}Starting server...${e.reset}`);let Dt=Wr({port:Ge,hostname:r.hostname,async fetch(P){let H=new URL(P.url),z=r.stxOptions?.offline??m.offline;if(H.pathname===to&&z?.enabled){if(!["GET","HEAD"].includes(P.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});return new Response(P.method==="HEAD"?null:no(z,Lr()),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let Q=m?.publicDir||"public",X=te.join(u,Q,H.pathname),Oe=te.join(u,H.pathname),Se=te.join(we,H.pathname);if([X,Oe,Se].some((B)=>w(B,u,S)))return new Response("Not Found",{status:404});let[N,J,V]=await Promise.all([me.promises.stat(X).catch(()=>null),me.promises.stat(Oe).catch(()=>null),me.promises.stat(Se).catch(()=>null)]);if(N?.isFile()&&!w(X,u,S))return zt(X);if(J?.isFile()&&!w(Oe,u,S))return zt(Oe);if(V?.isFile()&&!w(Se,u,S))return zt(Se);if(H.pathname.startsWith("/_stx/component/")){let B=decodeURIComponent(H.pathname.slice(16));if(B)try{let re=`<${B} />`,Z={...buildConfig,autoShell:!1},oe=await processDirectives(re,{},te.join(u,"components",`${B}.stx`),Z,new Set);return new Response(oe,{headers:{"Content-Type":"text/html"}})}catch(re){return new Response(`<div class="stx-async-error">${re.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(H.pathname==="/_stx/img"){let{handleImageRequest:B}=await import("./chunk-ykjzhfyf.js"),re=await B(P,{publicDir:te.join(u,Q),cacheDir:c(u,"cache","img")});if(re)return re}if(Y)try{let B=await Y.handleRequest(P);if(B.status!==404)return B}catch{}if(K[H.pathname])try{return await K[H.pathname](P)}catch(B){return new Response(JSON.stringify({error:B.message}),{status:500,headers:{"Content-Type":"application/json"}})}let de=await C(P);if(de)return de;let G=tr(H.pathname,k);if(G){let B=le.get(G.route.pattern),re=Pe.has(G.route.pattern);if(!B||G.route.isDynamic&&Object.keys(G.params).length>0||re){let Z=await L(G.route,G.params);if(Z){if(B=Z,!G.route.isDynamic&&!re)le.set(G.route.pattern,Z)}}if(B){let Z=B.status??200,oe=B.headers??{},fe=(G.route.filePath?gt(await Bun.file(G.route.filePath).text().catch(()=>"")):null)??{};if(fe.validate){if(!await fe.validate({params:G.params})){let De=await ne(404);if(De){let ee=De;if(ee=await h(ee,u),a)ee=Ne(ee,f);return new Response(ee,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(fe.middleware){let Le=kt(H.pathname,G.params,fe,H.search),De=_t(Le,null,P,{isServer:!0}),ee=await Ct(fe.middleware,De);if(ee.redirect){let Ae=ee.redirect.path,be=ee.redirect.options.redirectCode||302,at=new Headers(ee.responseHeaders);return at.set("Location",Ae),new Response(null,{status:be,headers:at})}if(ee.abort){let{statusCode:Ae,message:be}=ee.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${Ae}</title></head><body><h1>Error ${Ae}</h1><p>${be}</p></body></html>`,{status:Ae,headers:{"Content-Type":"text/html"}})}if(Object.keys(ee.state).length>0){let Ae=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(ee.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;B.content=B.content.replace("</head>",`${Ae}</head>`)}}let U=B.content;if(E&&Pi(P)){let Le=Ye(U),De=he(U),ee=U.match(/<title[^>]*>([\s\S]*?)<\/title>/i),Ae=ee?Ri(ee[1].trim()):"";if(Object.keys(G.params).length>0)U=Ot(U,G.params);U=await h(U,u);let be=m?.router?.container||"main";return U=_e(U,be),new Response(U,{status:Z,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":De?"true":"false",...Ae&&{"X-STX-Title":encodeURIComponent(Ae)},[oa]:Lr(),...O(),"Cache-Control":ut}})}if(E)U=Pr(E,U);if(Object.keys(G.params).length>0)U=Ot(U,G.params);if(U=await h(U,u),a)U=Ne(U,f);if(r.native)if(U.includes("<head>"))U=U.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else U="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+U;if(r.titlebarHidden)if(U.includes("<head>"))U=U.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else U=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${U}`;if(B.boundaries&&B.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:De}=await import("./chunk-qk34p70z.js");return De(Le(U,B.boundaries,{timeoutMs:30000}),{status:Z,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(U,{status:Z,headers:{"Content-Type":"text/html",...O(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...oe}})}}if(A.length>0){let B=A.map((Z)=>Z.route),re=tr(H.pathname,B);if(re){let Z=M.get(re.route.pattern);if(!Z||re.route.isDynamic){let oe=await L(re.route,re.params);if(oe){if(Z=oe,!re.route.isDynamic)M.set(re.route.pattern,oe)}}if(Z){let oe=Z.content;if(E)oe=Pr(E,oe);if(Object.keys(re.params).length>0)oe=Ot(oe,re.params);if(oe=await h(oe,u),a)oe=Ne(oe,f);return new Response(oe,{status:Z.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:Z}of I)if(Z!=="/"&&H.pathname.startsWith(Z)){let oe=M.get(Z)||M.get(Z+"/");if(!oe){let fe=A.find(({route:U})=>U.pattern===Z||U.pattern===`${Z}/`);if(fe){let U=await L(fe.route);if(U)oe=U,M.set(fe.route.pattern,U)}}if(oe){let fe=oe.content;if(E)fe=Pr(E,fe);if(fe=await h(fe,u),a)fe=Ne(fe,f);return new Response(fe,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(vt(H.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Ue=le.get("/");if(Ue){let B=Ue.content;if(B=await h(B,u),a)B=Ne(B,f);if(r.native)if(B.includes("<head>"))B=B.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else B="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+B;return new Response(B,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let ce=await ne(404);if(ce){let B=ce;if(B=await h(B,u),a)B=Ne(B,f);return new Response(B,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(P){let H=await ne(500);if(H)return new Response(H,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${P}
1430
1430
  ${P.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});if(console.clear(),console.log(`
1431
1431
  ${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
1432
1432
  ${e.bright}\u2192 ${e.cyan}http://localhost:${Ge}/${e.reset}`),a)console.log(`${e.dim} HMR: ws://localhost:${f}${e.reset}`);console.log(`
1433
1433
  ${e.yellow}Routes:${e.reset}`);let Mt=[...ss(k,u)];for(let{route:P}of A)Mt.push(`${P.pattern}`);if(Mt.forEach((P,H)=>{let Q=H===Mt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${Q}${e.reset}${P}`)}),console.log(`
1434
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(Dt.url.toString(),()=>{if(l)st();Dt.stop()}),r.native){let P,H=te.join(T,"index.stx");if(me.existsSync(H)){let Q=await Bun.file(H).text();P=ht(Q)}let z=m?.app?.window??{};await Ze(Ge,{title:m?.app?.head?.title||te.basename(u)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??r.titlebarHidden===!0,nativeSidebar:!!P,sidebarConfig:P})}if(p){console.log(`${e.blue}Watching for changes...${e.reset}`);let P=(N)=>N.startsWith("public/")||N.startsWith("public\\"),H=(N)=>{let J=N.toLowerCase();return J.endsWith(".stx")||J.endsWith(".html")||J.endsWith(".md")},z=new Map,Q=()=>{let N=new Set([u,...m._layerGraph?.layers.map((J)=>J.root)??[],...m._layerGraph?.configDependencies.map((J)=>te.dirname(J))??[]].filter((J)=>me.existsSync(J)).map((J)=>me.realpathSync(J)));for(let J of m._layerGraph?.layers??[])for(let V of Object.values(J.resources)){if(!me.existsSync(V))continue;let de=me.realpathSync(V);if(![...N].some((G)=>de===G||de.startsWith(`${G}${te.sep}`)))N.add(de)}for(let[J,V]of z)if(!N.has(J))V.close(),z.delete(J);for(let J of N)if(!z.has(J)&&me.existsSync(J))z.set(J,me.watch(J,{recursive:!0},(V,de)=>{Oe(J,V,de).catch((G)=>console.error("[stx] Layer rebuild failed:",G))}))},X=Promise.resolve(),Oe=(N,J,V)=>(X=X.catch(()=>{}).then(()=>Se(N,J,V)),X),Se=async(N,J,V)=>{if(!V||Tt(V))return;if(bt(V)){if(m._layerGraph){let de=await y(u);Object.assign(m,de),k.splice(0,k.length,...q(v,{pagesDir:x,pagesDirs:de._layerPageDirs?[T,...de._layerPageDirs.slice(1)]:void 0})),Q()}if(P(V)){if(console.log(`${e.cyan}${V} changed${e.reset}`),a&&l)l.reload(V)}else if(H(V)){console.log(`${e.yellow}${V} changed, rebuilding...${e.reset}`),Ke.clear(),pe();try{let{invalidateFileCache:de,templateCache:G}=await import("./chunk-bxr4c8rg.js");de(te.resolve(N,V)),G.delete(te.resolve(N,V))}catch{}if(_&&V){if(te.resolve(N,V)===_||te.basename(_)===V){let G=await Hs(_,r.stxOptions||{});if(G)E=G}}if(await ze(),await Kn(u),a&&l)l.reload(V)}else{console.log(`${e.yellow}${V} changed, rebuilding...${e.reset}`),Ke.clear(),pe();try{let{invalidateFileCache:de,templateCache:G}=await import("./chunk-bxr4c8rg.js");de(te.resolve(N,V)),G.delete(te.resolve(N,V))}catch{}if(await ze(),a&&l)l.reload(V)}}else if(yt(V)){if(console.log(`${e.cyan}CSS ${V} changed${e.reset}`),a&&l)l.updateCss(V)}};Q(),process.on("SIGINT",()=>{for(let N of z.values())N.close();if(l)st();Dt.stop(),process.exit(0)})}return!0}import Nt from"fs";import it from"path";async function Vr(t){try{let s=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!s)return[];let p=s[1],a=[],l=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,f;while((f=l.exec(p))!==null){let u=f[1],y=f[2]||f[3]||f[4];if(!y)continue;let m={name:y},b=u.match(/@type\s+\{([^}]+)\}/i);if(b)m.type=b[1].trim();if(u.match(/@required/i))m.required=!0;let S=u.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)m.default=S[1].trim();let C=u.split(`
1434
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(Dt.url.toString(),()=>{if(l)st();Dt.stop()}),r.native){let P,H=te.join(T,"index.stx");if(me.existsSync(H)){let Q=await Bun.file(H).text();P=ht(Q)}let z=m?.app?.window??{};await Ze(Ge,{title:m?.app?.head?.title||te.basename(u)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??r.titlebarHidden===!0,nativeSidebar:!!P,sidebarConfig:P})}if(p){console.log(`${e.blue}Watching for changes...${e.reset}`);let P=(N)=>N.startsWith("public/")||N.startsWith("public\\"),H=(N)=>{let J=N.toLowerCase();return J.endsWith(".stx")||J.endsWith(".html")||J.endsWith(".md")},z=new Map,Q=()=>{let N=new Set([u,...m._layerGraph?.layers.map((J)=>J.root)??[],...m._layerGraph?.configDependencies.map((J)=>te.dirname(J))??[]].filter((J)=>me.existsSync(J)).map((J)=>me.realpathSync(J)));for(let J of m._layerGraph?.layers??[])for(let V of Object.values(J.resources)){if(!me.existsSync(V))continue;let de=me.realpathSync(V);if(![...N].some((G)=>de===G||de.startsWith(`${G}${te.sep}`)))N.add(de)}for(let[J,V]of z)if(!N.has(J))V.close(),z.delete(J);for(let J of N)if(!z.has(J)&&me.existsSync(J))z.set(J,me.watch(J,{recursive:!0},(V,de)=>{Oe(J,V,de).catch((G)=>console.error("[stx] Layer rebuild failed:",G))}))},X=Promise.resolve(),Oe=(N,J,V)=>(X=X.catch(()=>{}).then(()=>Se(N,J,V)),X),Se=async(N,J,V)=>{if(!V||Tt(V))return;if(bt(V)){if(m._layerGraph){let de=await y(u);Object.assign(m,de),k.splice(0,k.length,...q(v,{pagesDir:x,pagesDirs:de._layerPageDirs?[T,...de._layerPageDirs.slice(1)]:void 0})),Q()}if(P(V)){if(console.log(`${e.cyan}${V} changed${e.reset}`),a&&l)l.reload(V)}else if(H(V)){console.log(`${e.yellow}${V} changed, rebuilding...${e.reset}`),Ke.clear(),pe();try{let{invalidateFileCache:de,templateCache:G}=await import("./chunk-qkr7epna.js");de(te.resolve(N,V)),G.delete(te.resolve(N,V))}catch{}if(_&&V){if(te.resolve(N,V)===_||te.basename(_)===V){let G=await Hs(_,r.stxOptions||{});if(G)E=G}}if(await ze(),await Kn(u),a&&l)l.reload(V)}else{console.log(`${e.yellow}${V} changed, rebuilding...${e.reset}`),Ke.clear(),pe();try{let{invalidateFileCache:de,templateCache:G}=await import("./chunk-qkr7epna.js");de(te.resolve(N,V)),G.delete(te.resolve(N,V))}catch{}if(await ze(),a&&l)l.reload(V)}}else if(yt(V)){if(console.log(`${e.cyan}CSS ${V} changed${e.reset}`),a&&l)l.updateCss(V)}};Q(),process.on("SIGINT",()=>{for(let N of z.values())N.close();if(l)st();Dt.stop(),process.exit(0)})}return!0}import Nt from"fs";import it from"path";async function Vr(t){try{let s=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!s)return[];let p=s[1],a=[],l=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,f;while((f=l.exec(p))!==null){let u=f[1],y=f[2]||f[3]||f[4];if(!y)continue;let m={name:y},b=u.match(/@type\s+\{([^}]+)\}/i);if(b)m.type=b[1].trim();if(u.match(/@required/i))m.required=!0;let S=u.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)m.default=S[1].trim();let C=u.split(`
1435
1435
  `).map((v)=>v.trim().replace(/^\*\s*/,"")).filter((v)=>!v.startsWith("@")&&v.length>0);m.description=C.join(" ").trim(),a.push(m)}if(a.length===0){let u=p.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(u){let m=u[1].split(",").map((b)=>b.trim()).filter(Boolean);for(let b of m){let[w]=b.split(":").map((S)=>S.trim());if(w)a.push({name:w})}}}return a}catch(r){return console.error(`Error extracting props from ${t}:`,r),[]}}async function qr(t){try{let r=await Bun.file(t).text(),s=r.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||r.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(s)return s[1].split(`
1436
1436
  `).map((p)=>p.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Kr(t,r=!1,s){let p=it.basename(t,".stx"),a=await Vr(t),l=await qr(t),f="";if(r&&s)f=`<${s}></${s}>`;else{let u=a.map((y)=>{if(y.type==="boolean")return`:${y.name}="true"`;return`${y.name}="value"`}).join(`
1437
1437
  `);f=`<${p}
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Bt}from"./chunk-6e60jp4a.js";function Rs(e){let n=e.pwa;if(!n?.enabled)return"";let r=n.manifest,t=n.icons?.outputDir?`/${n.icons.outputDir}`:"/pwa-icons",o=Bt(e),i=`
2
+ import{Bt}from"./chunk-kq1hmpgb.js";function Rs(e){let n=e.pwa;if(!n?.enabled)return"";let r=n.manifest,t=n.icons?.outputDir?`/${n.icons.outputDir}`:"/pwa-icons",o=Bt(e),i=`
3
3
  <!-- stx PWA Meta Tags -->
4
4
  <link rel="manifest" href="/manifest.json">
5
5
  <meta name="theme-color" content="${a(r?.themeColor||"#000000")}">
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Ro,Aa,s,Tt,se,k,Pe,cn,Ie,de,G,cr,ln,ms,za,dn,dr,ys,bs,Ha,Do,Va,Ua,Wa,qa,Ne,De,vs,je,n,gn,m,d,V,Y,we,x,_}from"./chunk-t3e5tv4h.js";import{l,p,E,t,ie,U,a,xe,qo,D,bn,Ko,Lt,Go,oc,mr,ic,rt,ac,hr,cc,vn,Xo,lc,yr,vr,Se,Jo}from"./chunk-3tp7r57c.js";import{Nt}from"./chunk-t6m5d64b.js";import{hn}from"./chunk-8x34g2ad.js";import{h}from"./chunk-fb84n8kz.js";import{rr,os}from"./chunk-kypwg2ws.js";import{ga,ma,er,Je,ha,R}from"./chunk-mxbp4vyy.js";import{wo,xo,So,ko}from"./chunk-r7csb300.js";import{la,Vr}from"./chunk-4rj9746b.js";import{Br,Fr,zr}from"./chunk-e5kz0y03.js";import{Ur,po,fo,Wr,qr,go}from"./chunk-7st0prz9.js";import{jr,Gn}from"./chunk-qgs69nds.js";import{ro}from"./chunk-9bgb9n12.js";import{re,ao,co,lo}from"./chunk-wt6f9pk9.js";import{Jn,he,da,Yn,pa}from"./chunk-4ht54p3j.js";import{K,Ge}from"./chunk-yft8yn6y.js";import{ya,ba}from"./chunk-9wd31tc6.js";import{C,wn,Yo}from"./chunk-2ajbhefk.js";import gs from"fs";import ce from"path";function lt(){return`
2
+ import{Ro,Aa,s,Tt,se,k,Pe,cn,Ie,de,G,cr,ln,ms,za,dn,dr,ys,bs,Ha,Do,Va,Ua,Wa,qa,Ne,De,vs,je,n,gn,m,d,V,Y,we,x,_}from"./chunk-pe9ry4mj.js";import{l,p,E,t,ie,U,a,xe,qo,D,bn,Ko,Lt,Go,oc,mr,ic,rt,ac,hr,cc,vn,Xo,lc,yr,vr,Se,Jo}from"./chunk-r0ys9aqa.js";import{Nt}from"./chunk-t6m5d64b.js";import{hn}from"./chunk-f178pm4d.js";import{h}from"./chunk-qy26afdn.js";import{rr,os}from"./chunk-kypwg2ws.js";import{ga,ma,er,Je,ha,R}from"./chunk-jhr08gjs.js";import{wo,xo,So,ko}from"./chunk-ygb33q5w.js";import{la,Vr}from"./chunk-h1bnge85.js";import{Br,Fr,zr}from"./chunk-zff3cb1e.js";import{Ur,po,fo,Wr,qr,go}from"./chunk-71sawjg8.js";import{jr,Gn}from"./chunk-52g5q984.js";import{ro}from"./chunk-9bgb9n12.js";import{re,ao,co,lo}from"./chunk-hx787tfa.js";import{Jn,he,da,Yn,pa}from"./chunk-fbj9b0p6.js";import{K,Ge}from"./chunk-yft8yn6y.js";import{ya,ba}from"./chunk-hr3m2h4n.js";import{C,wn,Yo}from"./chunk-078as147.js";import gs from"fs";import ce from"path";function lt(){return`
3
3
  // STX Lifecycle Runtime
4
4
  (function() {
5
5
  if (typeof window === 'undefined') return;
@@ -1558,13 +1558,13 @@ ${I}
1558
1558
  </style>`;c=c.replace(S,P),v.lastIndex=0}catch(I){}}}return c}import it from"path";var ds=/(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+)(['"])(\.\.?\/[^'"]*)\2/g,ps=/(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi;function fs(i,e){if(!e||!i.includes("/"))return i;let u=it.dirname(e);return i.replace(ds,(c,g,r,f)=>{let v=it.resolve(u,f);return`${g}${r}${v.split(it.sep).join("/")}${r}`})}function un(i,e){if(!e||!i.includes("<script"))return i;return i.replace(ps,(u,c,g,r)=>`${c}${fs(g,e)}${r}`)}var Te="<!--PARENT_CONTENT_PLACEHOLDER-->";function pn(i){return i.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Sn(i,e){let u=i.length,c=e,g=!0,r=[],f=(v)=>v+9<=u&&i[v]==="<"&&i[v+1]==="/"&&(i[v+2]==="s"||i[v+2]==="S")&&(i[v+3]==="c"||i[v+3]==="C")&&(i[v+4]==="r"||i[v+4]==="R")&&(i[v+5]==="i"||i[v+5]==="I")&&(i[v+6]==="p"||i[v+6]==="P")&&(i[v+7]==="t"||i[v+7]==="T")&&(i[v+8]===">"||/\s/.test(i[v+8]));while(c<u){let v=i[c];if(f(c))return c;if(v==="/"&&i[c+1]==="/"){if(c=i.indexOf(`
1559
1559
  `,c+2),c===-1)return-1;c+=1,g=!0;continue}if(v==="/"&&i[c+1]==="*"){let y=i.indexOf("*/",c+2);if(y===-1)return-1;c=y+2,g=!0;continue}if(v==="/"&&g){let y=c+1,S=!1;while(y<u){let b=i[y];if(b==="\\"){y+=2;continue}if(b==="[")S=!0;else if(b==="]")S=!1;else if(b==="/"&&!S){y++;break}else if(b===`
1560
1560
  `){y=-1;break}y++}if(y===-1){c++,g=!1;continue}while(y<u&&/[a-z]/.test(i[y]))y++;c=y,g=!1;continue}if(v==="'"||v==='"'){let y=v;c++;while(c<u){if(i[c]==="\\"){c+=2;continue}if(i[c]===y){c++;break}if(i[c]===`
1561
- `)break;c++}g=!1;continue}if(v==="`"){c++;while(c<u){if(i[c]==="\\"){c+=2;continue}if(i[c]==="`"){c++;break}if(i[c]==="$"&&i[c+1]==="{"){r.push(!0),c+=2,g=!0;break}c++}if(r.length===0)g=!1;continue}if(v==="}"&&r.length>0){r.pop(),c++;while(c<u){if(i[c]==="\\"){c+=2;continue}if(i[c]==="`"){c++,g=!1;break}if(i[c]==="$"&&i[c+1]==="{"){r.push(!0),c+=2,g=!0;break}c++}continue}if(/\s/.test(v));else if(/[)\].\w$]/.test(v))g=!1;else g=!0;c++}return-1}function $n(i,e){let u=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),c=new RegExp(`<script\\b(?=[^>]*\\b${u}(?:\\s|=|/?>))[^>]*>`,"i").exec(i);if(!c)return null;let g=c.index+c[0].length,r=i.indexOf("</script>",g);if(r===-1)return null;let f=i.indexOf(">",r);if(f===-1)return null;return{start:c.index,end:f+1}}var hs=4096;async function fn(i,e,u){if(u.buildMode!=="serve"||e.length<hs)return null;let{registerServeModuleBundle:c}=await import("./chunk-bxr4c8rg.js");return`<script ${i} src="${c(e)}"></script>`}async function Un(i,e,u){try{let{registeredModuleIdsIn:c,buildModuleRegistryScript:g}=await s("stx/client-module-registry",()=>import("./chunk-7grjwpdq.js")),r=[],f=await g(c(...i),{minify:Yo(e.buildMode),collectInputs:r});for(let v of r)u?.add(v);if(!f)return null;if(e.buildMode==="serve"){let{registerServeModuleBundle:v}=await import("./chunk-bxr4c8rg.js");return`<script data-stx-scoped data-stx-run="always" data-stx-modules src="${v(f)}"></script>`}return`<script data-stx-scoped data-stx-run="always" data-stx-modules>${f.replace(/<\/script/gi,"<\\/script")}</script>`}catch{return null}}function ws(i,e=""){let u=$n(i,"data-stx-runtime");if(!u)return i;let c=Jn(i);if(c===-1||c===u.start){if(!e)return i;return i.slice(0,u.end)+e+i.slice(u.end)}if(c<u.start)return i.slice(0,c)+i.slice(u.start,u.end)+e+`
1561
+ `)break;c++}g=!1;continue}if(v==="`"){c++;while(c<u){if(i[c]==="\\"){c+=2;continue}if(i[c]==="`"){c++;break}if(i[c]==="$"&&i[c+1]==="{"){r.push(!0),c+=2,g=!0;break}c++}if(r.length===0)g=!1;continue}if(v==="}"&&r.length>0){r.pop(),c++;while(c<u){if(i[c]==="\\"){c+=2;continue}if(i[c]==="`"){c++,g=!1;break}if(i[c]==="$"&&i[c+1]==="{"){r.push(!0),c+=2,g=!0;break}c++}continue}if(/\s/.test(v));else if(/[)\].\w$]/.test(v))g=!1;else g=!0;c++}return-1}function $n(i,e){let u=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),c=new RegExp(`<script\\b(?=[^>]*\\b${u}(?:\\s|=|/?>))[^>]*>`,"i").exec(i);if(!c)return null;let g=c.index+c[0].length,r=i.indexOf("</script>",g);if(r===-1)return null;let f=i.indexOf(">",r);if(f===-1)return null;return{start:c.index,end:f+1}}var hs=4096;async function fn(i,e,u){if(u.buildMode!=="serve"||e.length<hs)return null;let{registerServeModuleBundle:c}=await import("./chunk-qkr7epna.js");return`<script ${i} src="${c(e)}"></script>`}async function Un(i,e,u){try{let{registeredModuleIdsIn:c,buildModuleRegistryScript:g}=await s("stx/client-module-registry",()=>import("./chunk-bzzye361.js")),r=[],f=await g(c(...i),{minify:Yo(e.buildMode,e.minifyClient),collectInputs:r});for(let v of r)u?.add(v);if(!f)return null;if(e.buildMode==="serve"){let{registerServeModuleBundle:v}=await import("./chunk-qkr7epna.js");return`<script data-stx-scoped data-stx-run="always" data-stx-modules src="${v(f)}"></script>`}return`<script data-stx-scoped data-stx-run="always" data-stx-modules>${f.replace(/<\/script/gi,"<\\/script")}</script>`}catch{return null}}function ws(i,e=""){let u=$n(i,"data-stx-runtime");if(!u)return i;let c=Jn(i);if(c===-1||c===u.start){if(!e)return i;return i.slice(0,u.end)+e+i.slice(u.end)}if(c<u.start)return i.slice(0,c)+i.slice(u.start,u.end)+e+`
1562
1562
  `+i.slice(c,u.start)+i.slice(u.end);let g=i.slice(u.start,u.end),r=i.slice(0,u.start)+i.slice(u.end),f=Jn(r);if(f===-1)return g+e+`
1563
1563
  `+r;return r.slice(0,f)+g+e+`
1564
1564
  `+r.slice(f)}function xs(i){let e=/\x00STX_ESC_MUSTACHE_OPEN\x00([\s\S]*?)\x00STX_ESC_MUSTACHE_CLOSE\x00/g;return i.replace(e,(u,c,g)=>{let r=i.slice(0,g);return r.lastIndexOf("<")>r.lastIndexOf(">")?`{{${c}}}`:`{<!--stx-literal-->{${c}}}`})}async function o(i,e,u,c,g){if(c.ssr===!1&&!c.autoShell&&c.buildMode==="spa")return i;if(e.__stx_signals_gate===void 0)e.__stx_signals_gate=we(i,u);let r=!e.__stxProcessingDepth;dn(e);for(let f of c._layerGraph?.configDependencies??[])g.add(f);if(r&&c.runtimeConfig)await hn(e,u,c.runtimeConfig);if(r)Wa(e),e.__stx_scope_seq??={n:0,key:vs(String(e.__filename??u))},e.__stx_head_injections=Go(),e.__stx_seo_staged=!1;if(!e.__stxProcessingDepth)e.__stxProcessingDepth=0;if(e.__stxProcessingDepth++,!e.__onceStore)e.__onceStore=new Set;if((c.debug||!C()&&!wn())&&u&&u.endsWith(".stx"))ro(i,u);try{return await se.timeAsync("template-processing",async()=>{let f=await ks(i,e,u,c,g);if(r)f=Do(f);if(r&&c.autoShell&&c.buildMode!=="compile"){let v=Se(c.app?.head,{known:vr,source:"app.head"}),S=(e.__stx_runtime_head||null)??Jo(),b=(e.__stx_head_raw||"").trim(),w,T=b.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(T)w=T[1].trim(),b=b.replace(T[0],"").trim();let A=e.__sections?.title,O=A?x(A,e,u):void 0,M=S.title||w||O,I=!S.title&&(!!w||!!O),P=S.meta||[],N=new Set(P.map((W)=>rt(W)).filter(Boolean)),F={...v,...M&&{title:M},meta:[...(v.meta||[]).filter((W)=>!N.has(rt(W))),...P],link:[...v.link||[],...S.link||[]],script:[...v.script||[],...S.script||[]],headRaw:[v.headRaw,b].filter(Boolean).join(`
1565
1565
  `),...S.htmlAttrs&&{htmlAttrs:ac(v.htmlAttrs,S.htmlAttrs)},...S.bodyAttrs&&{bodyAttrs:{...v.bodyAttrs||{},...S.bodyAttrs}}},z=Xo(f);if(f=yr(f,F,{...I&&{titleIsHtml:!0},...c.app?.colorMode&&{colorMode:c.app.colorMode}},z),z)f=lc(f,v),f=hr(f,F.htmlAttrs);let L=f.match(/<!-- stx-layout: ([^ ]+) -->/);if(L&&f.includes("<head")){let W=L[1],X=os(W);f=f.replace(/<head\b[^>]*>/i,(Q)=>`${Q}
1566
1566
  <meta name="stx-layout" content="${pn(W)}">
1567
- <meta name="stx-layout-group" content="${pn(X)}">`)}let j=f.match(/function (__stx_setup_\w+)\(/),H=j?K(f):null;if(j&&H&&!/\bdata-stx=/.test(H.tag)){f=Ge(f,(X,Q)=>`<body${Q} data-stx="${j[1]}">`);let W=new RegExp(`(<(?!body)[a-zA-Z][^>]*) data-stx="${j[1]}"`,"i");f=f.replace(W,"$1")}}if(r){let v=e.__stx_head_injections??Go(),y=cc(f);if(y!==null)v.beforeClose.push(y);let S=tn(f);if(S!==null)v.afterOpen.push(S);if(c.offline?.enabled&&!f.includes("data-stx-offline"))v.beforeClose.push(nn);f=oc(f,v);let b=c.app?.colorMode;if(b)f=mr(f,b)}if(r)if($n(f,"data-stx-runtime")){let y=null,S=null,b=null,w=null,T=null;try{let{getStoreScript:O}=await s("stx/store-loader",()=>import("./chunk-42c308vk.js")),M=c.storesDir,I=await O(M);if(I)b=`<script data-stx-stores>${I}</script>`,S=await fn("data-stx-stores",I,c)??b}catch{}y=await Un([f,b],c,g);try{let{getFrameworkComposableScript:O}=await s("stx/framework-composables",()=>import("./chunk-f5s2h2y8.js"));T=await O(f)}catch{}try{let{getComposableScript:O}=await s("stx/composable-loader",()=>import("./chunk-kxqvfdm9.js")),M=c.composablesDir,I=[y,b,T].filter((N)=>N!==null),P=await O(c._layerComposableDirs??M,f,I);if(P)w=await fn('data-stx-scoped data-stx-run="always" data-stx-composables',P,c)??`<script data-stx-scoped data-stx-run="always" data-stx-composables>${P}</script>`}catch{}let A=[y,S,w,T].filter((O)=>O!==null).map((O)=>`
1567
+ <meta name="stx-layout-group" content="${pn(X)}">`)}let j=f.match(/function (__stx_setup_\w+)\(/),H=j?K(f):null;if(j&&H&&!/\bdata-stx=/.test(H.tag)){f=Ge(f,(X,Q)=>`<body${Q} data-stx="${j[1]}">`);let W=new RegExp(`(<(?!body)[a-zA-Z][^>]*) data-stx="${j[1]}"`,"i");f=f.replace(W,"$1")}}if(r){let v=e.__stx_head_injections??Go(),y=cc(f);if(y!==null)v.beforeClose.push(y);let S=tn(f);if(S!==null)v.afterOpen.push(S);if(c.offline?.enabled&&!f.includes("data-stx-offline"))v.beforeClose.push(nn);f=oc(f,v);let b=c.app?.colorMode;if(b)f=mr(f,b)}if(r)if($n(f,"data-stx-runtime")){let y=null,S=null,b=null,w=null,T=null;try{let{getStoreScript:O}=await s("stx/store-loader",()=>import("./chunk-jk16vj3c.js")),M=c.storesDir,I=await O(M);if(I)b=`<script data-stx-stores>${I}</script>`,S=await fn("data-stx-stores",I,c)??b}catch{}y=await Un([f,b],c,g);try{let{getFrameworkComposableScript:O}=await s("stx/framework-composables",()=>import("./chunk-trzanjcp.js"));T=await O(f)}catch{}try{let{getComposableScript:O}=await s("stx/composable-loader",()=>import("./chunk-yxg5na8z.js")),M=c.composablesDir,I=[y,b,T].filter((N)=>N!==null),P=await O(c._layerComposableDirs??M,f,I);if(P)w=await fn('data-stx-scoped data-stx-run="always" data-stx-composables',P,c)??`<script data-stx-scoped data-stx-run="always" data-stx-composables>${P}</script>`}catch{}let A=[y,S,w,T].filter((O)=>O!==null).map((O)=>`
1568
1568
  ${O}`).join("");f=ws(f,A)}else{let y=await Un([f],c,g);if(y){let S=f.search(/<script\b[^>]*>(?:(?!<\/script>)[\s\S])*?__stxModules\[/i);if(S!==-1)f=f.slice(0,S)+y+`
1569
1569
  `+f.slice(S)}}if(r)f=ic(f);if(r&&e.__stx_inject_css!==!1)f=await h(f,void 0,c.buildMode==="serve",!0);else if(r)f=ln(f);if(f=f.replace(/\x00STX_ESCAPED_AT\x00/g,"@"),f=xs(f),r&&e.__stx_runtime_config)f=Nt(f,e.__stx_runtime_config);if(r&&!e.__stx_defer_server_data){let v=dr(e);if(v){let y=/<head\b[^>]*>/i.exec(f),S=y?y.index+y[0].length:0;f=f.slice(0,S)+v+f.slice(S)}}return f})}catch(f){if(f instanceof U)throw f;let v=f instanceof Error?f.message:String(f),y=new ie(`Template processing failed: ${v}`,u,void 0,void 0,i.substring(0,200)+(i.length>200?"...":""));if(D.log(y,{filePath:u,context:e}),bn.logDetailedError(y,{filePath:u,template:i.substring(0,500)}),C()&&!c.debug)console.error(`[stx] ${ce.relative(process.cwd(),u)||u}: ${y.message}`);if(c.debug)throw y;return qo.createFallbackContent("Template Processing",y)}}async function ks(i,e,u,c,g){let r=process.cwd(),f={...c,partialsDir:c.partialsDir&&!ce.isAbsolute(c.partialsDir)?ce.resolve(r,c.partialsDir):c.partialsDir,componentsDir:c.componentsDir&&!ce.isAbsolute(c.componentsDir)?ce.resolve(r,c.componentsDir):c.componentsDir,layoutsDir:c.layoutsDir&&!ce.isAbsolute(c.layoutsDir)?ce.resolve(r,c.layoutsDir):c.layoutsDir},v=f,y=i;await Es(u,e),$s(e,v),y=await xe(()=>zt(y,e,u,v),y,(L)=>{D.log(L,{filePath:u,phase:"pre-processing-middleware"},"warning"),console.warn(`[stx] pre-processing middleware failed for ${u}: ${L.message}`)}),y=y.replace(/\{\{--[\s\S]*?--\}\}/g,"");let S=de(y,Ie,(L,j)=>`\x00STX_HTML_COMMENT_${j}\x00`);y=S.output;let b=S.tokens,w=(L)=>b.length===0?L:L.replace(/\x00STX_HTML_COMMENT_(\d+)\x00/g,(j,H)=>b[Number(H)]??""),T="\x00STX_ESCAPED_AT\x00",A="\x00STX_ESC_MUSTACHE_OPEN\x00",O="\x00STX_ESC_MUSTACHE_CLOSE\x00";y=y.replace(/@@/g,T),y=y.replace(/@\{\{([\s\S]*?)\}\}/g,(L,j)=>`${A}${j}${O}`),y=Jt(y),y=await an(y,u,g);let M={};y=Fr(y,M);let I={...e.__sections||{}},P="",N=mt(gt(i)),F=/@nolayout\b/.test(y)||N===!1;if(/@nolayout\b/.test(y))y=y.replace(/@nolayout\b\s*/g,"");let z=y.match(/@(?:layout|extends)\(\s*['"]([^'"]+)['"]\s*\)/);if(z)P=z[1],y=y.replace(/@(?:layout|extends)\(\s*['"]([^'"]+)['"]\s*\)/g,"");else if(typeof N==="string"){if(P=N,!/@section\s*\(/.test(y))y=`@section('content')
1570
1570
  ${y.trim()}
@@ -1573,7 +1573,7 @@ ${y.trim()}
1573
1573
  @endsection`}}if(P&&y.includes("<script")){let L=G(y),j=L.scripts.map((H)=>mn(H,u)??H);y=cr(L.output,j)}if(y=y.replace(/@section\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*\)/g,(L,j,H)=>(I[j]=H,"")),y=y.replace(/@section\(\s*['"]([^'"]+)['"]\s*,\s*([^)]+?)\s*\)/g,(L,j,H)=>{if(/^(['"]).*\1$/.test(H.trim()))return L;try{let W=l(H.trim(),e);if(W===void 0)return L;let Q=(e.__stx_inline_section_values??=[]).push(W)-1;return I[j]=`{{ __stx_inline_section_values[${Q}] }}`,""}catch{return L}}),y=y.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@endsection|@show)/g,(L,j,H)=>{if(H.includes("@parent"))I[j]=H.replace("@parent",Te);else I[j]=H.trim();return""}),e.__sections=I,y=y.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"](?:,\s*['"]([^'"]+)['"])?\)/g,(L,j,H)=>I[j]||H||""),!("slot"in e)||e.slot===void 0)y=y.replace(/\{\{\s*slot\s*\}\}/g,()=>I.content||"");if(y=zr(y,M),P){let L=[],j=G(y),H=de(j.output,cn,(W,X)=>`\x00STX_ORPHAN_STYLE_${X}\x00`);if(y=H.output.replace(/\x00STX_(SCRIPT|ORPHAN_STYLE)_(\d+)\x00/g,(W,X,Q)=>{let ee=X==="SCRIPT"?mn(j.scripts[Number(Q)],u):H.tokens[Number(Q)];if(ee)L.push(ee);return""}),L.length>0){let W=L.join(`
1574
1574
  `);I.content=I.content?`${I.content}
1575
1575
  ${W}`:W,e.__sections=I}}if(P)try{let L;if(ce.isAbsolute(P))L=P,g.add(P);else L=await xe(()=>gn(P,u,f,g),null,()=>{throw new ie(`Failed to resolve layout path: ${P}`,u,void 0,void 0,`Layout referenced from ${u}`)});if(!L){let ee=(oe)=>{if(!oe)return[];try{let ae=ce.isAbsolute(oe)?oe:ce.resolve(process.cwd(),oe);return gs.readdirSync(ae).filter((le)=>le.endsWith(".stx")).map((le)=>le.replace(/\.stx$/,""))}catch{return[]}},te=[...ee(f.layoutsDir),...ee(f.fallbackLayoutsDir)].filter((oe,ae,le)=>le.indexOf(oe)===ae).sort(),ue=`Layout not found: ${P} (referenced from ${u})`+(te.length>0?`. Available layouts: ${te.join(", ")}`:f.layoutsDir?`. No .stx layouts found in ${f.layoutsDir}`:"");if(D.log(Error(ue),{layoutPath:P,filePath:u,available:te},"error"),console.error(`[stx] ${ue}`),f.debug)throw new ie(ue,u);return y}let j=await xe(()=>Bun.file(L).text(),"",()=>{throw new ie(`Failed to read layout file: ${L}`,u,void 0,void 0,"Layout content could not be loaded")});j=un(j,L);let H=j.match(/@(?:layout|extends)\(\s*['"]([^'"]+)['"]\s*\)/);if(H){if(f.debug)console.log(`Found nested layout: ${H[1]} in ${L}`);let ee={},te=j.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@show|@endsection)/g,(ae,le,be)=>(ee[le]=be.trim(),""));for(let[ae,le]of Object.entries(ee))if(I[ae]&&I[ae].includes(Te)){let be=I[ae].indexOf(Te);I[ae]=I[ae].slice(0,be)+le+I[ae].slice(be+Te.length)}else if(!I[ae])I[ae]=le;let ue={...e,__sections:I},oe=`@layout('${H[1]}')${te}`;return await o(oe,ue,L,f,g)}let W=j.replace(/\{\{--[\s\S]*?--\}\}/g,""),X=Fr(W,M),Q={};return X=X.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@show|@endsection)/g,(ee,te,ue)=>(Q[te]=ue.trim(),`@slot('${te}')`)),X=X.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(ee,te,ue)=>{if(I[te]){let oe=I[te];if(oe.includes(Te)){let ae=Q[te]||"",le=oe.indexOf(Te);oe=oe.slice(0,le)+ae+oe.slice(le+Te.length)}return oe}return ue||""}),X=Ss(X,I),X=X.replace(/\{\{\s*slot\s*\}\}/g,()=>I.content||""),X=zr(X,M),e.__originalFilePath=u,y=await kn(X,e,L,f,g),y=`<!-- stx-layout: ${P} -->
1576
- ${y}`,w(y)}catch(L){if(L instanceof U)throw L;throw new ie(`Error processing layout ${P}: ${L instanceof Error?L.message:String(L)}`,u)}return w(await kn(y,e,u,f,g))}function Ss(i,e){return i.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(u,c,g)=>{let r=e[c];if(r!==void 0){if(!new RegExp(`@(?:yield|slot)\\(\\s*['"]${c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}['"]`).test(r))return r}return g||""})}function $s(i,e){if(i.__stx_sfc_mode=!0,i.__stx_options=e,e.buildMode)i.__stx_buildMode=e.buildMode;let u=e.envPrefix||"STX_PUBLIC_",c={};for(let[g,r]of Object.entries(process.env))if(g.startsWith(u)&&r!==void 0)c[g]=r;i.$env=c}async function Es(i,e){await xe(()=>Kt(i,e),void 0,(u)=>{D.log(u,{filePath:i,phase:"view-composer"},"warning"),console.warn(`[stx] view composer failed for ${i}: ${u.message}`)})}var ot="data-stx-source";function mn(i,e){if(!i)return i;let u=/^<script\b([^>]*)>/i.exec(i);if(!u||!/\bserver\b/.test(u[1])||u[1].includes(ot))return i;return`<script ${ot}="${encodeURIComponent(e)}"${i.slice(7)}`}function _s(i){let e=new RegExp(`${ot}="([^"]*)"`).exec(i);return e?decodeURIComponent(e[1]):void 0}function yn(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function xn(i,e,u){return`<div data-stx-server-script-error role="alert" style="padding:12px 14px;border:1px solid #f0b4b4;border-left-width:4px;background:#fff5f5;color:#7a1f1f;font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace"><strong style="display:block;margin-bottom:4px">stx: a &lt;script server&gt; ${e==="module-resolution"?"imports a module that does not resolve":e==="syntax"?"does not parse":"names something that does not exist"}, so this component rendered nothing.</strong><span style="display:block;opacity:.85">${yn(i)}</span><span style="display:block;margin-top:4px">${yn(u)}</span></div>`}async function Ts(i,e,u,c){let{scanScriptTags:g}=await s("stx/signal-processing",()=>import("./chunk-9xp9hs7t.js")),r=[],f=!C()&&!wn();for(let y of g(i)){let S=y.attrs;if(!/\bserver\b/.test(S))continue;let b=y.start+y.fullMatch.indexOf(">")+1,w=Sn(i,b);if(w===-1)continue;let T=i.slice(b,w);if(!T.trim())continue;let A=_s(S)??u,O={index:y.start,length:w+9-y.start};try{let{extractVariables:M}=await s("stx/variable-extractor",()=>import("./chunk-xpch3mq8.js"));await M(T,e,A,{preserveExisting:!0,onFailure:(I)=>{if(I.kind==="unknown")return;if(c?.onServerScriptError?.({sourcePath:A,kind:I.kind,message:I.message}),!f)return;r.push({...O,markup:xn(A,I.kind,I.message)})}})}catch(M){let I=M instanceof Error?M:Error(String(M));if(D.log(I,{filePath:A,phase:"server-script-extraction"},"warning"),console.warn(`[stx] server <script> extraction failed in ${A}: ${I.message}`),f)r.push({...O,markup:xn(A,"unknown",I.message)})}}if(r.length===0)return i;let v=i;for(let y of r.sort((S,b)=>b.index-S.index))v=v.slice(0,y.index)+y.markup+v.slice(y.index+y.length);return v}async function Cs(i,e,u){try{let{interpolateScriptsInTemplate:c}=await s("stx/expressions",()=>import("./chunk-qjmvcqfh.js"));return c(i,e,{skipServer:!0})}catch(c){let g=c instanceof Error?c:Error(String(c));return D.log(g,{filePath:u,phase:"script-expression-interpolation"},"warning"),console.warn(`[stx] script expression interpolation failed in ${u}: ${g.message}`),i}}async function kn(i,e,u,c,g){let r=i,f=c;if(r=await Ts(r,e,u,c),r=await Bt(r,e,u),r=await Ft(r,e,u),r=await Cs(r,e,u),r=await At(r,e,u,f),we(r))r=po(r,e),r=qr(r,e),r=Wr(r,e);r=fo(r);let{processStreamDirectives:v}=await s("stx/streaming",()=>import("./chunk-mn9xw0fe.js"));r=v(r,e),r=Gn(r,e,u,f,!0),r=await en(r,e,u,f,g),r=await Vr(r,e,u,f,g),r=ga(r,e,u,f);let{processDeferDirectives:y}=await s("stx/defer",()=>import("./chunk-c9jnkbdb.js"));r=y(r,e,u);let{processTeleportDirectives:S}=await s("stx/teleport",()=>import("./chunk-kerxevf9.js"));r=S(r,e,u);let{processTransitionDirectives:b,processTransitionAttributes:w}=await s("stx/transitions",()=>import("./chunk-sqvdrk81.js"));r=b(r,e,u),r=w(r);let{processErrorBoundaryDirectives:T,stripRenderFailedMarkers:A}=await s("stx/error-boundaries",()=>import("./chunk-h85hrwkq.js"));r=T(r,e,u),r=A(r);let{processSuspenseDirectives:O}=await s("stx/suspense",()=>import("./chunk-8j0zcyd7.js"));r=O(r,e,u);let{processAsyncDirectives:M}=await s("stx/async-components",()=>import("./chunk-sncp7jhv.js"));r=M(r,e,u);let{processKeepAliveDirectives:I}=await s("stx/keep-alive",()=>import("./chunk-myc60z74.js"));r=I(r,e,u);let{processVirtualListDirectives:P,processVirtualGridDirectives:N,processInfiniteListDirectives:F}=await s("stx/virtual-scrolling",()=>import("./chunk-a1r3jbt4.js"));r=P(r,e,u),r=N(r,e,u),r=F(r,e,u);let{processPartialHydrationDirectives:z,processStaticDirectives:L}=await s("stx/partial-hydration",()=>import("./chunk-7jxj6cv1.js"));r=z(r,e,u),r=L(r);let{processComputedDirectives:j,processWatchDirectives:H}=await s("stx/computed",()=>import("./chunk-1xdzcy9d.js"));r=j(r,e,u),r=H(r,e,u);let{processFormValidationDirectives:W}=await s("stx/forms-validation",()=>import("./chunk-ppxfsqwh.js"));r=W(r,e,u);let{processHeadDirective:X,processTitleDirective:Q,processMetaDirective:ee,resetHead:te}=await s("stx/head",()=>import("./chunk-gccwjjzw.js"));if(!e.__stx_head_preset&&!e.__stx_runtime_head)te();let ue=X(r);if(r=ue.content,ue.headContent)e.__stx_head_raw=`${e.__stx_head_raw||""}${ue.headContent}
1576
+ ${y}`,w(y)}catch(L){if(L instanceof U)throw L;throw new ie(`Error processing layout ${P}: ${L instanceof Error?L.message:String(L)}`,u)}return w(await kn(y,e,u,f,g))}function Ss(i,e){return i.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(u,c,g)=>{let r=e[c];if(r!==void 0){if(!new RegExp(`@(?:yield|slot)\\(\\s*['"]${c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}['"]`).test(r))return r}return g||""})}function $s(i,e){if(i.__stx_sfc_mode=!0,i.__stx_options=e,e.buildMode)i.__stx_buildMode=e.buildMode;let u=e.envPrefix||"STX_PUBLIC_",c={};for(let[g,r]of Object.entries(process.env))if(g.startsWith(u)&&r!==void 0)c[g]=r;i.$env=c}async function Es(i,e){await xe(()=>Kt(i,e),void 0,(u)=>{D.log(u,{filePath:i,phase:"view-composer"},"warning"),console.warn(`[stx] view composer failed for ${i}: ${u.message}`)})}var ot="data-stx-source";function mn(i,e){if(!i)return i;let u=/^<script\b([^>]*)>/i.exec(i);if(!u||!/\bserver\b/.test(u[1])||u[1].includes(ot))return i;return`<script ${ot}="${encodeURIComponent(e)}"${i.slice(7)}`}function _s(i){let e=new RegExp(`${ot}="([^"]*)"`).exec(i);return e?decodeURIComponent(e[1]):void 0}function yn(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function xn(i,e,u){return`<div data-stx-server-script-error role="alert" style="padding:12px 14px;border:1px solid #f0b4b4;border-left-width:4px;background:#fff5f5;color:#7a1f1f;font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace"><strong style="display:block;margin-bottom:4px">stx: a &lt;script server&gt; ${e==="module-resolution"?"imports a module that does not resolve":e==="syntax"?"does not parse":"names something that does not exist"}, so this component rendered nothing.</strong><span style="display:block;opacity:.85">${yn(i)}</span><span style="display:block;margin-top:4px">${yn(u)}</span></div>`}async function Ts(i,e,u,c){let{scanScriptTags:g}=await s("stx/signal-processing",()=>import("./chunk-agx8pbg4.js")),r=[],f=!C()&&!wn();for(let y of g(i)){let S=y.attrs;if(!/\bserver\b/.test(S))continue;let b=y.start+y.fullMatch.indexOf(">")+1,w=Sn(i,b);if(w===-1)continue;let T=i.slice(b,w);if(!T.trim())continue;let A=_s(S)??u,O={index:y.start,length:w+9-y.start};try{let{extractVariables:M}=await s("stx/variable-extractor",()=>import("./chunk-bm6yhhew.js"));await M(T,e,A,{preserveExisting:!0,onFailure:(I)=>{if(I.kind==="unknown")return;if(c?.onServerScriptError?.({sourcePath:A,kind:I.kind,message:I.message}),!f)return;r.push({...O,markup:xn(A,I.kind,I.message)})}})}catch(M){let I=M instanceof Error?M:Error(String(M));if(D.log(I,{filePath:A,phase:"server-script-extraction"},"warning"),console.warn(`[stx] server <script> extraction failed in ${A}: ${I.message}`),f)r.push({...O,markup:xn(A,"unknown",I.message)})}}if(r.length===0)return i;let v=i;for(let y of r.sort((S,b)=>b.index-S.index))v=v.slice(0,y.index)+y.markup+v.slice(y.index+y.length);return v}async function Cs(i,e,u){try{let{interpolateScriptsInTemplate:c}=await s("stx/expressions",()=>import("./chunk-3vjzezn1.js"));return c(i,e,{skipServer:!0})}catch(c){let g=c instanceof Error?c:Error(String(c));return D.log(g,{filePath:u,phase:"script-expression-interpolation"},"warning"),console.warn(`[stx] script expression interpolation failed in ${u}: ${g.message}`),i}}async function kn(i,e,u,c,g){let r=i,f=c;if(r=await Ts(r,e,u,c),r=await Bt(r,e,u),r=await Ft(r,e,u),r=await Cs(r,e,u),r=await At(r,e,u,f),we(r))r=po(r,e),r=qr(r,e),r=Wr(r,e);r=fo(r);let{processStreamDirectives:v}=await s("stx/streaming",()=>import("./chunk-qk34p70z.js"));r=v(r,e),r=Gn(r,e,u,f,!0),r=await en(r,e,u,f,g),r=await Vr(r,e,u,f,g),r=ga(r,e,u,f);let{processDeferDirectives:y}=await s("stx/defer",()=>import("./chunk-c9jnkbdb.js"));r=y(r,e,u);let{processTeleportDirectives:S}=await s("stx/teleport",()=>import("./chunk-kerxevf9.js"));r=S(r,e,u);let{processTransitionDirectives:b,processTransitionAttributes:w}=await s("stx/transitions",()=>import("./chunk-sqvdrk81.js"));r=b(r,e,u),r=w(r);let{processErrorBoundaryDirectives:T,stripRenderFailedMarkers:A}=await s("stx/error-boundaries",()=>import("./chunk-h85hrwkq.js"));r=T(r,e,u),r=A(r);let{processSuspenseDirectives:O}=await s("stx/suspense",()=>import("./chunk-8j0zcyd7.js"));r=O(r,e,u);let{processAsyncDirectives:M}=await s("stx/async-components",()=>import("./chunk-sncp7jhv.js"));r=M(r,e,u);let{processKeepAliveDirectives:I}=await s("stx/keep-alive",()=>import("./chunk-myc60z74.js"));r=I(r,e,u);let{processVirtualListDirectives:P,processVirtualGridDirectives:N,processInfiniteListDirectives:F}=await s("stx/virtual-scrolling",()=>import("./chunk-a1r3jbt4.js"));r=P(r,e,u),r=N(r,e,u),r=F(r,e,u);let{processPartialHydrationDirectives:z,processStaticDirectives:L}=await s("stx/partial-hydration",()=>import("./chunk-7jxj6cv1.js"));r=z(r,e,u),r=L(r);let{processComputedDirectives:j,processWatchDirectives:H}=await s("stx/computed",()=>import("./chunk-1xdzcy9d.js"));r=j(r,e,u),r=H(r,e,u);let{processFormValidationDirectives:W}=await s("stx/forms-validation",()=>import("./chunk-fvxvd48v.js"));r=W(r,e,u);let{processHeadDirective:X,processTitleDirective:Q,processMetaDirective:ee,resetHead:te}=await s("stx/head",()=>import("./chunk-vnnwp1cg.js"));if(!e.__stx_head_preset&&!e.__stx_runtime_head)te();let ue=X(r);if(r=ue.content,ue.headContent)e.__stx_head_raw=`${e.__stx_head_raw||""}${ue.headContent}
1577
1577
  `;if(r=Q(r,e),r=ee(r,e,u),r=Xt(r),r=ao(r,e),r=Ct(r),r=Ut(r),r=await Br(r,e,u,f,g),r=await Vr(r,e,u,f,g),e.__stxProcessingDepth===1)r=qa(r,e);if(r=r.replace(/@push\s*\(\s*['"][^'"]+['"]\s*\)[\s\S]*?@endpush/g,""),r=Do(r),r=re(r,e,u),r=jr(r),r=za(r,e,{filePath:u,buildMode:f.buildMode}),r=co(r,e),r=lo(r,e),r=ze(r,e),r=jt(r,e),r=Ht(r,e),r=await bt(r,e,u,f),r=await ha(r,e,u),r=await ya(r,e,u,f),r=ba(r,e,u,f),r=wo(r,e,u,f),r=xo(r,e,u),r=So(r,e,u,f),r=Et(r,e,u,f),r=ys(r,e),r=bs(r),r=Ha(r),!f.skipEventDirectives)r=Aa(r,e,u);if(r=vt(r,e,u),f.debug){let B=/\bx-data\s*=/.test(r),q=Ur(i);if(B&&q)console.warn(`[stx] ${u}: Template mixes Alpine-style (x-data) and signals (state/derived/effect) reactivity.
1578
1578
  Both work on the same page, but they manage separate scopes.
1579
1579
  Prefer signals (state/derived/effect) for new components.`)}r=la(r,e),r=await x(r,e,u),r=Va(r),r=Ua(r),r=pt(r);let{processXElementDirectives:oe}=await s("stx/x-element",()=>import("./chunk-zhxdpzga.js"));r=oe(r);let ae=e.__originalFilePath||u,le=Ne(e);if(r=await go(r,f,ae,le),r=It(r,e),r=await Wt(r,e,u,f),f.media?.image?.autoSiblings){let B=f.publicDir||"public",{rewriteImagesWithSiblings:q}=await s("stx/image-optimization/auto-sibling",()=>import("./chunk-01ks1244.js"));r=await q(r,{publicDir:B})}if(f.seo?.enabled)r=ko(r,e,f);let be=(B,q,J=!0)=>{if(!q)return B;let me=q.match(/<title\b[^>]*>[\s\S]*?<\/title>/i),ne=/<head\b[^>]*>[\s\S]*?(?:<\/head\s*>|<body\b|$)/i.exec(B),fe=ne?/<title\b[^>]*>[\s\S]*?<\/title>/i.exec(ne[0]):null;if(me&&ne&&fe){if(J){let Ce=ne.index+fe.index;B=B.slice(0,Ce)+me[0]+B.slice(Ce+fe[0].length)}if(q=q.replace(me[0],"").trim(),!q)return B}if(/<\/head>/i.test(B))return B.replace(/<\/head>/i,`${q}
@@ -1581,12 +1581,12 @@ ${y}`,w(y)}catch(L){if(L instanceof U)throw L;throw new ie(`Error processing lay
1581
1581
  ${q}`);if(/<html\b[^>]*>/i.test(B))return B.replace(/(<html\b[^>]*>)/i,`$1
1582
1582
  <head>
1583
1583
  ${q}
1584
- </head>`);return B},{renderHead:En,getHead:_n}=await s("stx/head",()=>import("./chunk-gccwjjzw.js")),Oe=e.__stx_runtime_head??_n();if(Oe.title||Oe.meta?.length||Oe.link?.length){let B=En(Oe);if(B)r=be(r,B)}if(ue.headContent)r=be(r,ue.headContent,!Oe.title);if(f.csp?.enabled&&f.csp.addMetaTag)r=St(r,f.csp,e);if(f.analytics?.enabled)r=ft(r,f);if(f.heatmap?.enabled)r=ma(r,f);if(f.pwa?.enabled&&f.pwa.autoInject!==!1){let{injectPwaTags:B}=await s("stx/pwa/inject",()=>import("./chunk-8y7tpjfs.js"));r=B(r,f)}let Tn=/<script\b(?![^>]*\bserver\b)[^>]*>[\s\S]*?<\/script>/i.test(r),Cn=/\bSTX\.\w+/.test(r),An=/window\.STX\s*=/.test(r);if(Tn&&Cn&&!An){let q=`<script data-stx-scoped data-stx-run="once">
1584
+ </head>`);return B},{renderHead:En,getHead:_n}=await s("stx/head",()=>import("./chunk-vnnwp1cg.js")),Oe=e.__stx_runtime_head??_n();if(Oe.title||Oe.meta?.length||Oe.link?.length){let B=En(Oe);if(B)r=be(r,B)}if(ue.headContent)r=be(r,ue.headContent,!Oe.title);if(f.csp?.enabled&&f.csp.addMetaTag)r=St(r,f.csp,e);if(f.analytics?.enabled)r=ft(r,f);if(f.heatmap?.enabled)r=ma(r,f);if(f.pwa?.enabled&&f.pwa.autoInject!==!1){let{injectPwaTags:B}=await s("stx/pwa/inject",()=>import("./chunk-c0fkhe6t.js"));r=B(r,f)}let Tn=/<script\b(?![^>]*\bserver\b)[^>]*>[\s\S]*?<\/script>/i.test(r),Cn=/\bSTX\.\w+/.test(r),An=/window\.STX\s*=/.test(r);if(Tn&&Cn&&!An){let q=`<script data-stx-scoped data-stx-run="once">
1585
1585
  ${lt()}
1586
1586
  </script>`;if(r.includes("</head>")){let J=r.indexOf("</head>"),ne=r.slice(0,J).indexOf("<script");if(ne!==-1){let fe=r.slice(0,ne),Ce=r.slice(ne);r=fe+q+`
1587
1587
  `+Ce}else r=r.replace("</head>",`${q}
1588
1588
  </head>`)}else if(r.includes("<body"))r=r.replace(/<body([^>]*)>/,`<body$1>
1589
1589
  ${q}`);else r=q+`
1590
- `+r}{let{scanScriptTags:B}=await s("stx/signal-processing",()=>import("./chunk-9xp9hs7t.js")),q=[];for(let J of B(r)){if(!/\bserver\b/i.test(J.attrs))continue;let me=J.start+J.fullMatch.indexOf(">")+1,ne=Sn(r,me);if(ne===-1)continue;let fe=ne+9;while(fe<r.length&&/\s/.test(r[fe]))fe++;q.push({start:J.start,end:fe})}if(q.length>0){let J=Array(q.length+1),me=0;for(let ne=0;ne<q.length;ne++){let{start:fe,end:Ce}=q[ne];J[ne]=r.slice(me,fe),me=Ce}J[q.length]=r.slice(me),r=J.join("")}}let at=ms(r,u);if(at.hasScoped)r=at.html;let Rn=e.__stx_event_bindings||[],Xe=!1,ct=[],Mn=/\s:[a-z][\w.-]*\s*=/.test(r),{scanScriptTags:Dn}=await s("stx/signal-processing",()=>import("./chunk-9xp9hs7t.js"));for(let B of Dn(r,{skipAttrs:/\bserver\b|\bsrc\s*=|\bdata-stx-scoped\b|\bdata-stx-router\b|\btype\s*=\s*["'](?!(?:text\/javascript|application\/javascript|module)["'])[^"']*["']/}))ct.push({match:B.fullMatch,attrs:B.attrs,content:B.body});for(let{match:B,attrs:q,content:J}of ct){Xe=!0;let me=J;Pe(J,u,c.strict,e.__originalFilePath);let ne=await De(J,{eventBindings:Rn,attrs:q,hasColonDirectives:Mn,templateContent:i,filePath:u,projectRoot:process.cwd(),production:Yo(c.buildMode),serverData:le});r=r.replace(B,()=>ne)}if(Xe)e.__stx_event_bindings=[];if(!Xe&&e.__stxProcessingDepth===1){let B=e.__stx_event_bindings||[];if(B.length>0){let q=Ro(B);if(q){let J=r.lastIndexOf("</body>");r=J===-1?r+q:r.slice(0,J)+q+`
1590
+ `+r}{let{scanScriptTags:B}=await s("stx/signal-processing",()=>import("./chunk-agx8pbg4.js")),q=[];for(let J of B(r)){if(!/\bserver\b/i.test(J.attrs))continue;let me=J.start+J.fullMatch.indexOf(">")+1,ne=Sn(r,me);if(ne===-1)continue;let fe=ne+9;while(fe<r.length&&/\s/.test(r[fe]))fe++;q.push({start:J.start,end:fe})}if(q.length>0){let J=Array(q.length+1),me=0;for(let ne=0;ne<q.length;ne++){let{start:fe,end:Ce}=q[ne];J[ne]=r.slice(me,fe),me=Ce}J[q.length]=r.slice(me),r=J.join("")}}let at=ms(r,u);if(at.hasScoped)r=at.html;let Rn=e.__stx_event_bindings||[],Xe=!1,ct=[],Mn=/\s:[a-z][\w.-]*\s*=/.test(r),{scanScriptTags:Dn}=await s("stx/signal-processing",()=>import("./chunk-agx8pbg4.js"));for(let B of Dn(r,{skipAttrs:/\bserver\b|\bsrc\s*=|\bdata-stx-scoped\b|\bdata-stx-router\b|\btype\s*=\s*["'](?!(?:text\/javascript|application\/javascript|module)["'])[^"']*["']/}))ct.push({match:B.fullMatch,attrs:B.attrs,content:B.body});for(let{match:B,attrs:q,content:J}of ct){Xe=!0;let me=J;Pe(J,u,c.strict,e.__originalFilePath);let ne=await De(J,{eventBindings:Rn,attrs:q,hasColonDirectives:Mn,templateContent:i,filePath:u,projectRoot:process.cwd(),production:Yo(c.buildMode,c.minifyClient),serverData:le});r=r.replace(B,()=>ne)}if(Xe)e.__stx_event_bindings=[];if(!Xe&&e.__stxProcessingDepth===1){let B=e.__stx_event_bindings||[];if(B.length>0){let q=Ro(B);if(q){let J=r.lastIndexOf("</body>");r=J===-1?r+q:r.slice(0,J)+q+`
1591
1591
  `+r.slice(J)}e.__stx_event_bindings=[]}}if(!he(r)&&da(r))r=await Yn(r,f);if(r=pa(r),f.csp?.enabled&&f.csp.useNonce&&typeof e.cspNonce==="string")r=$t(r,e.cspNonce);return r}
1592
1592
  export{gt,$e,oa,Lr,to,no,Un,o};