@stacksjs/stx 0.2.414 → 0.2.415

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 (58) hide show
  1. package/dist/builtins/image-delivery.js +19 -11
  2. package/dist/{chunk-3c74vag1.js → chunk-0pnj3zt2.js} +1 -1
  3. package/dist/{chunk-6sgswrqw.js → chunk-0zaess6f.js} +2 -2
  4. package/dist/{chunk-2mkcjw08.js → chunk-18vmfkcc.js} +1 -1
  5. package/dist/{chunk-hkxsewzk.js → chunk-1zs30k3y.js} +1 -1
  6. package/dist/{chunk-10957mcb.js → chunk-393341w7.js} +1 -1
  7. package/dist/{chunk-69mc2np8.js → chunk-3efw27as.js} +111 -111
  8. package/dist/{chunk-mepdnezf.js → chunk-42wbs8vq.js} +1 -1
  9. package/dist/{chunk-q4c06e8x.js → chunk-8eqrwj1k.js} +1 -1
  10. package/dist/{chunk-yvx1ap9b.js → chunk-96k8s808.js} +1 -1
  11. package/dist/{chunk-2gr351s0.js → chunk-9amp82bx.js} +1 -1
  12. package/dist/{chunk-e57rhf65.js → chunk-9p9qkbtg.js} +1 -1
  13. package/dist/{chunk-dvgv8nry.js → chunk-amtr3rmf.js} +1 -1
  14. package/dist/{chunk-z6d0jmjb.js → chunk-atws6p5s.js} +1 -1
  15. package/dist/{chunk-h0atqq82.js → chunk-b98be3yp.js} +1 -1
  16. package/dist/{chunk-2v8wztd5.js → chunk-dd8cja4h.js} +1 -1
  17. package/dist/{chunk-v091jft4.js → chunk-e9hs7kk6.js} +1 -1
  18. package/dist/{chunk-b52s5z0c.js → chunk-f1sxycmv.js} +1 -1
  19. package/dist/chunk-fbcv4fes.js +2 -0
  20. package/dist/{chunk-afhxw2t8.js → chunk-fpfzm238.js} +1 -1
  21. package/dist/{chunk-x72tv2cg.js → chunk-g03s93qr.js} +1 -1
  22. package/dist/{chunk-v4vaqxrf.js → chunk-g186znp9.js} +1 -1
  23. package/dist/{chunk-bmt7w2pk.js → chunk-gc1drn2p.js} +1 -1
  24. package/dist/{chunk-s2x4wcrz.js → chunk-gea5hf0v.js} +1 -1
  25. package/dist/chunk-gqv3ta5d.js +2 -0
  26. package/dist/{chunk-btmhj5t7.js → chunk-h6kp2m9r.js} +1 -1
  27. package/dist/{chunk-xtdw3692.js → chunk-hepd9qgx.js} +1 -1
  28. package/dist/{chunk-qz519eyp.js → chunk-hhnw2sn3.js} +1 -1
  29. package/dist/{chunk-4jjme6a5.js → chunk-hk1mj4tz.js} +1 -1
  30. package/dist/{chunk-sd47dzs0.js → chunk-hkrmcbwy.js} +1 -1
  31. package/dist/{chunk-pj1wg7jg.js → chunk-hn9pkyv8.js} +1 -1
  32. package/dist/{chunk-syaw6b75.js → chunk-hpgr4qgp.js} +1 -1
  33. package/dist/{chunk-d44b9ktb.js → chunk-jnkrn913.js} +1 -1
  34. package/dist/{chunk-dx7n22ed.js → chunk-jp10q90g.js} +1 -1
  35. package/dist/{chunk-866n724v.js → chunk-nc8my58s.js} +1 -1
  36. package/dist/{chunk-apg16xcn.js → chunk-nppdrf0x.js} +1 -1
  37. package/dist/{chunk-x5bpeb4a.js → chunk-pazfr1a1.js} +1 -1
  38. package/dist/{chunk-se7mwqd1.js → chunk-pdb5fw3r.js} +1 -1
  39. package/dist/{chunk-g578mcb0.js → chunk-qghxz7jm.js} +1 -1
  40. package/dist/{chunk-pqxzp1bb.js → chunk-re8b5r9x.js} +1 -1
  41. package/dist/{chunk-5g3y8kym.js → chunk-t5pvq5mx.js} +1 -1
  42. package/dist/{chunk-qet5gc6s.js → chunk-tafqyf2g.js} +5 -5
  43. package/dist/{chunk-daz5aqcf.js → chunk-v91p6ekp.js} +1 -1
  44. package/dist/{chunk-f6az0xj5.js → chunk-w72qx0eb.js} +1 -1
  45. package/dist/{chunk-scezfp0w.js → chunk-wfy1zq53.js} +2 -2
  46. package/dist/{chunk-ynvdvbat.js → chunk-wzx0164n.js} +2 -2
  47. package/dist/{chunk-rs4v4fha.js → chunk-xtvf6n6f.js} +1 -1
  48. package/dist/{chunk-gw07qmjk.js → chunk-xwzvfqcb.js} +1 -1
  49. package/dist/{chunk-1chw8xsw.js → chunk-z23kaxq6.js} +1 -1
  50. package/dist/{chunk-mhq0pjws.js → chunk-z8xn5ta3.js} +1 -1
  51. package/dist/cli.js +7 -7
  52. package/dist/craft-entry.js +1 -1
  53. package/dist/craft.js +1 -1
  54. package/dist/pwa.js +1 -1
  55. package/dist/ssg.js +2 -2
  56. package/package.json +5 -5
  57. package/dist/chunk-48bwk47q.js +0 -2
  58. package/dist/chunk-6y8hnymb.js +0 -2
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{h,je,wt,Be,Fe,ee,M,le,X,d,ve,Ji,ds,r,n,K,Kn,i,T,ue}from"./chunk-69mc2np8.js";import{J,fn,re,_,At}from"./chunk-z0g9jvv0.js";import{H,e,Tt,ln,f}from"./chunk-h0atqq82.js";import{yn,ar,cr,lr,Qe,et,tt,nt,rt,st,Ce}from"./chunk-czxt605c.js";import{Pe,ni,se,C,ri,Sr,En,me,si,ie}from"./chunk-scezfp0w.js";import{Zt,Qt}from"./chunk-pqxzp1bb.js";import{Ot}from"./chunk-x72tv2cg.js";import{Me}from"./chunk-mepdnezf.js";import{o}from"./chunk-fzapbw9p.js";import{O}from"./chunk-px7fvbj6.js";async function Xn(t){try{let s=await Bun.file(t).text(),a=Gn(s),p=Jn(s,t),c=Yn(s,a),l=Qn(s,a);return{file:t,metrics:a,issues:p,suggestions:c,performance:l}}catch(s){throw Error(`Failed to analyze template ${t}: ${s instanceof Error?s.message:String(s)}`)}}function Gn(t){let s=t.split(`
2
+ import{h,je,wt,Be,Fe,ee,M,le,X,d,ve,Ji,ds,r,n,K,Kn,i,T,ue}from"./chunk-3efw27as.js";import{J,fn,re,_,At}from"./chunk-z0g9jvv0.js";import{H,e,Tt,ln,f}from"./chunk-b98be3yp.js";import{yn,ar,cr,lr,Qe,et,tt,nt,rt,st,Ce}from"./chunk-czxt605c.js";import{Pe,ni,se,C,ri,Sr,En,me,si,ie}from"./chunk-wfy1zq53.js";import{Zt,Qt}from"./chunk-re8b5r9x.js";import{Ot}from"./chunk-g03s93qr.js";import{Me}from"./chunk-42wbs8vq.js";import{o}from"./chunk-fzapbw9p.js";import{O}from"./chunk-px7fvbj6.js";async function Xn(t){try{let s=await Bun.file(t).text(),a=Gn(s),p=Jn(s,t),c=Yn(s,a),l=Qn(s,a);return{file:t,metrics:a,issues:p,suggestions:c,performance:l}}catch(s){throw Error(`Failed to analyze template ${t}: ${s instanceof Error?s.message:String(s)}`)}}function Gn(t){let s=t.split(`
3
3
  `),a=t.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),c=(a?a[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 m=(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,g=m+u+y,b=(t.match(/<[A-Z][^>]*>/g)||[]).length,w=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,E=0;for(let R of s)if(/@(?:if|unless|foreach|for|while|section)\b/.test(R)&&!/@end/.test(R)&&!/@else/.test(R))E++,S=Math.max(S,E);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(R))E--;let v=S>=4?3:0,x=Math.min(10,Math.ceil(l.total*0.5+g*0.1+b*0.3+(c>10?c*0.05:0)+v));return{lines:s.length,characters:t.length,directives:l,expressions:g,components:b,layouts:w,scriptLines:c,complexity:x}}function Jn(t,s){let a=[],p=Xt(t,"if","endif");if(p>0)a.push({type:"error",category:"syntax",message:`Found ${p} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let c=Xt(t,"foreach","endforeach");if(c>0)a.push({type:"error",category:"syntax",message:`Found ${c} 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)a.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let m=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(m>0)a.push({type:"warning",category:"security",message:`Found ${m} 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)a.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)a.push({type:"info",category:"maintainability",message:`Found ${y.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let g=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(g>3)a.push({type:"info",category:"maintainability",message:`Found ${g} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return a}function Yn(t,s){let a=[];if(s.complexity>7)a.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(s.complexity>5&&s.directives.total>8)a.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(s.lines>100&&s.components===0)a.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(s.expressions>20)a.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)a.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(s.directives.total===0&&s.expressions<5)a.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(s.scriptLines>50)a.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return a}function Qn(t,s){let a=1;if(a+=s.directives.conditionals*0.1,a+=s.directives.loops*0.5,a+=s.directives.includes*2,a+=s.expressions*0.05,a+=s.components*1,s.scriptLines>10)a+=s.scriptLines*0.1;let p;if(s.expressions===0&&s.directives.total===0)p="high";else if(s.expressions<5&&s.directives.total<3)p="medium";else p="low";let c=[];if(a>10)c.push("Consider optimizing template complexity");if(p==="low"&&s.directives.total>5)c.push("Reduce dynamic content for better caching");if(s.components===0&&s.lines>40)c.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(a*100)/100,complexityScore:s.complexity,cacheability:p,recommendations:c}}function Xt(t,s,a){let p=t.replace(/<!--[\s\S]*?-->/g,""),c=(p.match(new RegExp(`@${s}\\b`,"g"))||[]).length,l=(p.match(new RegExp(`@${a}\\b`,"g"))||[]).length;return Math.abs(c-l)}async function Hs(t=["**/*.stx"],s){let a=[],p=[];for(let l of t){let m=await Array.fromAsync(new Bun.Glob(l).scan({cwd:s||process.cwd(),onlyFiles:!0,absolute:!0}));p.push(...m.filter((u)=>u.endsWith(".stx")))}for(let l of p)try{let m=await Xn(l);a.push(m)}catch(m){console.warn(`Failed to analyze ${l}:`,m)}let c=Zn(a);return{results:a,summary:c}}function Zn(t){let s=t.length,a=t.reduce((g,b)=>g+b.metrics.lines,0),p=s>0?t.reduce((g,b)=>g+b.metrics.complexity,0)/s:0,c=t.reduce((g,b)=>g+b.issues.length,0),l={};t.forEach((g)=>{g.issues.forEach((b)=>{l[b.category]=(l[b.category]||0)+1})});let m=s>0?t.reduce((g,b)=>g+b.performance.estimatedRenderTime,0)/s:0,u=Math.max(1,Math.min(10,Math.round(10-m/2-p/2))),y=[];if(p>6)y.push("Project has high average complexity. Consider refactoring complex templates.");if(c>s*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:s,totalLines:a,avgComplexity:Math.round(p*100)/100,totalIssues:c,issuesByCategory:l,performanceScore:u,recommendations:y}}import{mkdir as er,readFile as tr,readdir as nr,stat as Gt,writeFile as rr}from"fs/promises";import Ee from"path";function rn(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 sn=new Set(["constructor","connectedCallback","disconnectedCallback","attributeChangedCallback","adoptedCallback"]);function sr(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((s)=>s.charAt(0).toUpperCase()+s.slice(1)).join("")}function Bt(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function or(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function ir(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function dr(t){let s=[];async function a(p){let c=await nr(p,{withFileTypes:!0});c.sort((l,m)=>l.name.localeCompare(m.name));for(let l of c){let m=Ee.join(p,l.name);if(l.isDirectory()){if(!l.name.startsWith(".")&&l.name!=="node_modules")await a(m)}else if(l.isFile()&&l.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(l.name))s.push(m)}}return await a(t),s}function pr(t,s){let a=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!a)return{};let p=a[1].trim();if(!p)return{};try{return JSON.parse(p)}catch(c){throw Error(`${s}: <script component> must contain JSON metadata (${c.message})`)}}function ur(t,s){let a={},p=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let c of p){if(!/\bclient\b/i.test(c[1])||/\bcomponent\b|\bstx:component\b/i.test(c[1]))continue;let l;try{l=new Bun.Transpiler({loader:"ts"}).transformSync(c[2])}catch(y){throw Error(`${s}: failed to transpile <script client> (${y.message})`)}let m=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,u;while(u=m.exec(l)){let y=u[1];if(sn.has(y))throw Error(`${s}: client ${rn(y)}`);let g=m.lastIndex,b=1,w="",S=!1,E=g;for(;E<l.length&&b>0;E++){let x=l[E];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(`${s}: unterminated client function "${y}"`);let v=u[0].includes("async")?"async ":"";a[y]=`${v}${y}(${u[2]}) {${l.slice(g,E-1)}}`,m.lastIndex=E}}return a}function fr(t){let s=t.match(/<template\b(?![^>]*\bshadowrootmode\b)[^>]*>([\s\S]*?)<\/template>/i);return(s?s[1]:t).replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").trim()}function Jt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((s)=>s[1].trim()).filter(Boolean).join(`
@@ -876,7 +876,7 @@ else {
876
876
  };
877
877
  })();
878
878
  </script>
879
- `}function Xe(t,s,a={}){let p=qr(s,a),c=t.lastIndexOf("</body>");if(c!==-1)return t.slice(0,c)+p+t.slice(c);if(t.includes("</html>"))return t.replace("</html>",`${p}</html>`);return t+p}function Ct(t){let s=t.toLowerCase();return s.endsWith(".css")||s.endsWith(".scss")||s.endsWith(".sass")||s.endsWith(".less")}function Rt(t){let s=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((p)=>s.endsWith(p))}function Et(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((a)=>a.test(t))}var pt=null;function Pt(t){if(!pt)pt=new an(t);return pt}function gt(){if(pt)pt.stop(),pt=null}import Dt from"path";var ut={name:"bun-plugin-stx",async setup(t){let a={...await i(),...t.config?.stx},p=new Set,c=a.webComponents?.enabled?`./${Dt.relative(Dt.dirname(t.config?.outdir||"dist"),a.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(a.webComponents?.enabled)try{let m=await Kn(a,p);if(l.push(...m),a.debug&&m.length>0)console.log(`Successfully built ${m.length} web components`)}catch(m){console.error("Failed to build web components:",m)}t.onLoad({filter:/\.stx$/},async({path:m})=>{try{let u=new Set;if(a.cache&&a.cachePath){let x=await Zt(m,a);if(x){if(a.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let y=await re(()=>Bun.file(m).text(),"",(x)=>{throw new fn(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!y)throw new fn(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:b,allScripts:w}=H.time("script-extraction",()=>{let x=y,R=ee(y);if(R)x=R.content.trim();let k=y.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],F="",L=[];for(let P of k){let I=P.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",z=P.match(/<script\b([^>]*)>/i),G=z?z[1]:"";if(/\bserver\b/i.test(G))F=I;else L.push(P)}let j=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:F,templateContent:j,allScripts:L}}),S={__filename:m,__dirname:Dt.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await re(()=>d(g,S,m),void 0,(x)=>{let R=new J(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(_.log(R,{filePath:m,scriptContent:g}),a.debug)throw R});let v=await H.timeAsync("directive-processing",async()=>await r(b,S,m,a,u));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-mhq0pjws.js"),R=x(w.join(`
879
+ `}function Xe(t,s,a={}){let p=qr(s,a),c=t.lastIndexOf("</body>");if(c!==-1)return t.slice(0,c)+p+t.slice(c);if(t.includes("</html>"))return t.replace("</html>",`${p}</html>`);return t+p}function Ct(t){let s=t.toLowerCase();return s.endsWith(".css")||s.endsWith(".scss")||s.endsWith(".sass")||s.endsWith(".less")}function Rt(t){let s=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((p)=>s.endsWith(p))}function Et(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((a)=>a.test(t))}var pt=null;function Pt(t){if(!pt)pt=new an(t);return pt}function gt(){if(pt)pt.stop(),pt=null}import Dt from"path";var ut={name:"bun-plugin-stx",async setup(t){let a={...await i(),...t.config?.stx},p=new Set,c=a.webComponents?.enabled?`./${Dt.relative(Dt.dirname(t.config?.outdir||"dist"),a.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(a.webComponents?.enabled)try{let m=await Kn(a,p);if(l.push(...m),a.debug&&m.length>0)console.log(`Successfully built ${m.length} web components`)}catch(m){console.error("Failed to build web components:",m)}t.onLoad({filter:/\.stx$/},async({path:m})=>{try{let u=new Set;if(a.cache&&a.cachePath){let x=await Zt(m,a);if(x){if(a.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let y=await re(()=>Bun.file(m).text(),"",(x)=>{throw new fn(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!y)throw new fn(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:b,allScripts:w}=H.time("script-extraction",()=>{let x=y,R=ee(y);if(R)x=R.content.trim();let k=y.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],F="",L=[];for(let P of k){let I=P.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",z=P.match(/<script\b([^>]*)>/i),G=z?z[1]:"";if(/\bserver\b/i.test(G))F=I;else L.push(P)}let j=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:F,templateContent:j,allScripts:L}}),S={__filename:m,__dirname:Dt.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await re(()=>d(g,S,m),void 0,(x)=>{let R=new J(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(_.log(R,{filePath:m,scriptContent:g}),a.debug)throw R});let v=await H.timeAsync("directive-processing",async()=>await r(b,S,m,a,u));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-z8xn5ta3.js"),R=x(w.join(`
880
880
  `),S),k=v.search(/<\/body>/i);if(k!==-1)v=v.slice(0,k)+R+`
881
881
  `+v.slice(k);else v+=`
882
882
  ${R}`}if(v=await X(v),u.forEach((x)=>p.add(x)),a.cache&&a.cachePath){if(await Qt(m,v,u,a),a.debug)console.log(`Cached template ${m} with ${u.size} dependencies`)}return{contents:v,loader:"html"}}catch(u){let y=u instanceof Error?u:new J(`Plugin processing failed: ${String(u)}`,m);if(_.log(y,{filePath:m,buildConfig:t.config}),At.logDetailedError(y,{filePath:m,plugin:"bun-plugin-stx"}),a.debug)console.error("stx Plugin Error:",y);let g=y,b=g.line||null,w=g.context||null;return{contents:a.debug||O()?`<!DOCTYPE html>
@@ -939,7 +939,7 @@ ${R}`}if(v=await X(v),u.forEach((x)=>p.add(x)),a.cache&&a.cachePath){if(await Qt
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 wn(t,s={}){let a=s.port||3000,p=s.watch!==!1,c=s.hotReload!==!1&&p,l=null,m=s.hmrPort||a+1,u=we.resolve(t);if(!Ne.existsSync(u))return console.error(`${e.red}Error: File not found: ${e.bright}${u}${e.reset}`),!1;if(u.endsWith(".md"))return Nt(u,s);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=o(process.cwd(),"output");Ne.mkdirSync(y,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,b=async()=>{try{let I={name:"public-assets",setup(Te){Te.onResolve({filter:/^\/(images|fonts|assets|public)\//},(he)=>({path:he.path,external:!0}))}},z=await Bun.build({entrypoints:[u],outdir:y,plugins:[I,ut],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!z.success)return console.error(`${e.red}Build failed:${e.reset}`,z.logs),!1;let G=z.outputs.find((Te)=>Te.path.endsWith(".html"));if(!G)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(G.path).text(),!0}catch(I){return console.error(`${e.red}Error building stx file:${e.reset}`,I),!1}};if(!await b())return!1;let S=we.dirname(u);await Tt(S);let E=a;try{if(E=await Ye(a),E!==a)console.log(`${e.yellow}Port ${a} is busy, using port ${E} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let I=s.hmrPort||E+1;l=Pt({wsPort:I,verbose:!1}),m=l.start(I)}let v={},x=null,R;try{let{loadStxConfig:I}=await import("./chunk-48bwk47q.js"),z=await I();if(R=s.stxOptions?.serverApi??z.serverApi,z?.apiRouter)x=z?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(z?.apiRoutes){v=z.apiRoutes;let G=Object.keys(v).length;if(G>0)console.log(`${e.blue}Loaded ${e.bright}${G} API route${G>1?"s":""}${e.reset}`)}if(z?.broadcasting?.enabled)try{let{startBroadcasting:G,loadChannels:te}=await import("./chunk-dgdm3hy3.js"),Te=z.broadcasting;await G(Te);let he=Te.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${he}/ws${e.reset}`);let Oe=we.join(process.cwd(),"channels.ts");if(Ne.existsSync(Oe))try{let ae=await te(Oe);console.log(`${e.blue}Loaded ${e.bright}${ae} broadcast channel${ae!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ae){console.warn(`${e.yellow}Failed to load channels.ts: ${ae.message}${e.reset}`)}}catch(G){console.warn(`${e.yellow}Broadcasting failed to start: ${G.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:F}=await import("./chunk-5g3y8kym.js"),L=await k(process.cwd(),R);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${E}/${e.reset}...`),c)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${m}${e.reset}`);let j=Kr({port:E,async fetch(I){return Ot(I,await(async()=>{let z=new URL(I.url);if([y,we.dirname(u),we.join(process.cwd(),"public")].some((ae)=>F(we.join(ae,z.pathname),process.cwd(),R)))return new Response("Not Found",{status:404});if(x)try{let ae=await x.handleRequest(I);if(ae.status!==404)return ae}catch{}if(v[z.pathname])try{return await v[z.pathname](I)}catch(ae){return new Response(JSON.stringify({error:ae.message}),{status:500,headers:{"Content-Type":"application/json"}})}let G=await L(I);if(G)return G;if(z.pathname==="/")return(async()=>{let W=await f(g||"");if(c)W=Xe(W,m);if(s.native)if(W.includes("<head>"))W=W.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(W.includes("<html"))W=W.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 W="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+W;if(s.titlebarHidden)if(W.includes("<head>"))W=W.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(W.includes("<html"))W=W.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 W=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${W}`;return W})().then((W)=>new Response(W,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let te=we.join(y,z.pathname);if(Ne.existsSync(te)&&Ne.statSync(te).isFile()){let ae=Bun.file(te),W=we.extname(te).toLowerCase(),B="text/plain";if(W===".ts"||W===".tsx"){let Ue=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),qe=await ae.text(),at=Ue.transformSync(qe);return new Response(at,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":B="text/html";break;case".css":B="text/css";break;case".js":B="text/javascript";break;case".json":B="application/json";break;case".png":B="image/png";break;case".jpg":case".jpeg":B="image/jpeg";break;case".gif":B="image/gif";break;case".woff":B="font/woff";break;case".woff2":B="font/woff2";break;case".ttf":B="font/ttf";break;case".otf":B="font/otf";break;case".eot":B="application/vnd.ms-fontobject";break}return new Response(ae,{headers:{"Content-Type":B}})}let Te=we.dirname(u),he=we.join(Te,z.pathname);if(Ne.existsSync(he)&&Ne.statSync(he).isFile()){let ae=Bun.file(he),W=we.extname(he).toLowerCase(),B="text/plain";if(W===".ts"||W===".tsx"){let Ue=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),qe=await ae.text(),at=Ue.transformSync(qe);return new Response(at,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":B="text/html";break;case".css":B="text/css";break;case".js":B="text/javascript";break;case".json":B="application/json";break;case".png":B="image/png";break;case".jpg":case".jpeg":B="image/jpeg";break;case".gif":B="image/gif";break;case".svg":B="image/svg+xml";break;case".ico":B="image/x-icon";break;case".woff":B="font/woff";break;case".woff2":B="font/woff2";break;case".ttf":B="font/ttf";break;case".otf":B="font/otf";break;case".eot":B="application/vnd.ms-fontobject";break}return new Response(ae,{headers:{"Content-Type":B}})}let Oe=we.join(process.cwd(),"public",z.pathname);if(Ne.existsSync(Oe)&&Ne.statSync(Oe).isFile()){let ae=Bun.file(Oe),W=we.extname(Oe).toLowerCase(),B="application/octet-stream";if(W===".ts"||W===".tsx"){let Ue=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),qe=await ae.text(),at=Ue.transformSync(qe);return new Response(at,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":B="text/html";break;case".css":B="text/css";break;case".js":B="text/javascript";break;case".json":B="application/json";break;case".png":B="image/png";break;case".jpg":case".jpeg":B="image/jpeg";break;case".gif":B="image/gif";break;case".svg":B="image/svg+xml";break;case".ico":B="image/x-icon";break;case".woff":B="font/woff";break;case".woff2":B="font/woff2";break;case".ttf":B="font/ttf";break;case".otf":B="font/otf";break;case".eot":B="application/vnd.ms-fontobject";break}return new Response(ae,{headers:{"Content-Type":B}})}return new Response("Not Found",{status:404})})())},error(I){return new Response(`<pre>${I}
942
+ </html>`,loader:"html"}}})}};async function wn(t,s={}){let a=s.port||3000,p=s.watch!==!1,c=s.hotReload!==!1&&p,l=null,m=s.hmrPort||a+1,u=we.resolve(t);if(!Ne.existsSync(u))return console.error(`${e.red}Error: File not found: ${e.bright}${u}${e.reset}`),!1;if(u.endsWith(".md"))return Nt(u,s);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=o(process.cwd(),"output");Ne.mkdirSync(y,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,b=async()=>{try{let I={name:"public-assets",setup(Te){Te.onResolve({filter:/^\/(images|fonts|assets|public)\//},(he)=>({path:he.path,external:!0}))}},z=await Bun.build({entrypoints:[u],outdir:y,plugins:[I,ut],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!z.success)return console.error(`${e.red}Build failed:${e.reset}`,z.logs),!1;let G=z.outputs.find((Te)=>Te.path.endsWith(".html"));if(!G)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(G.path).text(),!0}catch(I){return console.error(`${e.red}Error building stx file:${e.reset}`,I),!1}};if(!await b())return!1;let S=we.dirname(u);await Tt(S);let E=a;try{if(E=await Ye(a),E!==a)console.log(`${e.yellow}Port ${a} is busy, using port ${E} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let I=s.hmrPort||E+1;l=Pt({wsPort:I,verbose:!1}),m=l.start(I)}let v={},x=null,R;try{let{loadStxConfig:I}=await import("./chunk-fbcv4fes.js"),z=await I();if(R=s.stxOptions?.serverApi??z.serverApi,z?.apiRouter)x=z?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(z?.apiRoutes){v=z.apiRoutes;let G=Object.keys(v).length;if(G>0)console.log(`${e.blue}Loaded ${e.bright}${G} API route${G>1?"s":""}${e.reset}`)}if(z?.broadcasting?.enabled)try{let{startBroadcasting:G,loadChannels:te}=await import("./chunk-dgdm3hy3.js"),Te=z.broadcasting;await G(Te);let he=Te.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${he}/ws${e.reset}`);let Oe=we.join(process.cwd(),"channels.ts");if(Ne.existsSync(Oe))try{let ae=await te(Oe);console.log(`${e.blue}Loaded ${e.bright}${ae} broadcast channel${ae!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ae){console.warn(`${e.yellow}Failed to load channels.ts: ${ae.message}${e.reset}`)}}catch(G){console.warn(`${e.yellow}Broadcasting failed to start: ${G.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:F}=await import("./chunk-t5pvq5mx.js"),L=await k(process.cwd(),R);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${E}/${e.reset}...`),c)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${m}${e.reset}`);let j=Kr({port:E,async fetch(I){return Ot(I,await(async()=>{let z=new URL(I.url);if([y,we.dirname(u),we.join(process.cwd(),"public")].some((ae)=>F(we.join(ae,z.pathname),process.cwd(),R)))return new Response("Not Found",{status:404});if(x)try{let ae=await x.handleRequest(I);if(ae.status!==404)return ae}catch{}if(v[z.pathname])try{return await v[z.pathname](I)}catch(ae){return new Response(JSON.stringify({error:ae.message}),{status:500,headers:{"Content-Type":"application/json"}})}let G=await L(I);if(G)return G;if(z.pathname==="/")return(async()=>{let W=await f(g||"");if(c)W=Xe(W,m);if(s.native)if(W.includes("<head>"))W=W.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(W.includes("<html"))W=W.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 W="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+W;if(s.titlebarHidden)if(W.includes("<head>"))W=W.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(W.includes("<html"))W=W.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 W=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${W}`;return W})().then((W)=>new Response(W,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let te=we.join(y,z.pathname);if(Ne.existsSync(te)&&Ne.statSync(te).isFile()){let ae=Bun.file(te),W=we.extname(te).toLowerCase(),B="text/plain";if(W===".ts"||W===".tsx"){let Ue=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),qe=await ae.text(),at=Ue.transformSync(qe);return new Response(at,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":B="text/html";break;case".css":B="text/css";break;case".js":B="text/javascript";break;case".json":B="application/json";break;case".png":B="image/png";break;case".jpg":case".jpeg":B="image/jpeg";break;case".gif":B="image/gif";break;case".woff":B="font/woff";break;case".woff2":B="font/woff2";break;case".ttf":B="font/ttf";break;case".otf":B="font/otf";break;case".eot":B="application/vnd.ms-fontobject";break}return new Response(ae,{headers:{"Content-Type":B}})}let Te=we.dirname(u),he=we.join(Te,z.pathname);if(Ne.existsSync(he)&&Ne.statSync(he).isFile()){let ae=Bun.file(he),W=we.extname(he).toLowerCase(),B="text/plain";if(W===".ts"||W===".tsx"){let Ue=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),qe=await ae.text(),at=Ue.transformSync(qe);return new Response(at,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":B="text/html";break;case".css":B="text/css";break;case".js":B="text/javascript";break;case".json":B="application/json";break;case".png":B="image/png";break;case".jpg":case".jpeg":B="image/jpeg";break;case".gif":B="image/gif";break;case".svg":B="image/svg+xml";break;case".ico":B="image/x-icon";break;case".woff":B="font/woff";break;case".woff2":B="font/woff2";break;case".ttf":B="font/ttf";break;case".otf":B="font/otf";break;case".eot":B="application/vnd.ms-fontobject";break}return new Response(ae,{headers:{"Content-Type":B}})}let Oe=we.join(process.cwd(),"public",z.pathname);if(Ne.existsSync(Oe)&&Ne.statSync(Oe).isFile()){let ae=Bun.file(Oe),W=we.extname(Oe).toLowerCase(),B="application/octet-stream";if(W===".ts"||W===".tsx"){let Ue=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),qe=await ae.text(),at=Ue.transformSync(qe);return new Response(at,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":B="text/html";break;case".css":B="text/css";break;case".js":B="text/javascript";break;case".json":B="application/json";break;case".png":B="image/png";break;case".jpg":case".jpeg":B="image/jpeg";break;case".gif":B="image/gif";break;case".svg":B="image/svg+xml";break;case".ico":B="image/x-icon";break;case".woff":B="font/woff";break;case".woff2":B="font/woff2";break;case".ttf":B="font/ttf";break;case".otf":B="font/otf";break;case".eot":B="application/vnd.ms-fontobject";break}return new Response(ae,{headers:{"Content-Type":B}})}return new Response("Not Found",{status:404})})())},error(I){return new Response(`<pre>${I}
943
943
  ${I.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:${E}/${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)),E=Object.entries(m).filter(([v])=>!S.has(v)).sort(([v],[x])=>v.localeCompare(x)).map(([v,x])=>({route:v==="/"?"/":v,filePath:Ae.relative(process.cwd(),x.filePath),fileType:x.fileType}));for(let v of u){let x=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");E.push({route:x,filePath:Ae.relative(process.cwd(),v.filePath),fileType:"stx"})}if(E.sort((v,x)=>v.route.localeCompare(x.route)),E.forEach((v,x)=>{let k=x===E.length-1?"\u2514\u2500 ":"\u251C\u2500 ",F=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${k}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${F}`)}),console.log(`
1429
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ze(w.url.toString(),()=>{if(p)ot.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=ot.watch(l,{recursive:!0},async(x,R)=>{if(!R)return;if(R.endsWith(".stx")||R.endsWith(".js")||R.endsWith(".ts")||R.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${R}${e.yellow} changed, rebuilding...${e.reset}`),ve.clear(),K(),await y()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function dn(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Gr}=globalThis.Bun;import be from"fs";import oe from"path";async function un(t){try{return wt(await Bun.file(t).text())}catch{return}}function Ut(t){let s=Bun.file(t),a=oe.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(a)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":p[a]||"application/octet-stream",...l}})}async function Sn(t=".",s={}){let a=s.port||3000,p=s.watch!==!1,c=s.hotReload!==!1&&p,l=null,m=s.hmrPort||a+1,u=oe.resolve(t),{loadStxConfig:y}=await import("./chunk-48bwk47q.js"),g=await y(u),{createServerApi:b,isServerApiSource:w}=await import("./chunk-5g3y8kym.js"),S=s.stxOptions?.serverApi??g.serverApi,E=await b(u,S),v=g.root&&g.root!=="."?oe.join(u,g.root):u,x=s.pagesDir||g.pagesDir||"pages",R=oe.join(v,x);if(!be.existsSync(R)&&!g._layerPageDirs?.some((A)=>be.existsSync(A)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${R}${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=M(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[R,...g._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${R}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let F=g?._pluginPageDirs||[],L=[];for(let{dir:A,prefix:N}of F)if(be.existsSync(A)){let U=M(oe.dirname(A),{pagesDir:oe.basename(A)});for(let V of U){let xe=N==="/"?V.pattern:`${N}${V.pattern==="/"?"":V.pattern}`;L.push({route:{...V,pattern:xe},prefix:N})}if(U.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${U.length}${e.blue} routes at ${e.cyan}${N}${e.reset}`)}let j=new Map,P=null,I=null;if(s.stxOptions?.shell!==!1){if(I=await ri(u,s.stxOptions?.shell),I){if(P=await Sr(I,s.stxOptions||{}),P)console.log(`${e.blue}Using app shell: ${e.bright}${oe.relative(u,I)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}Qe(),await tt(u);let z=et();if(z.length>0)console.log(`${e.blue}Loaded ${e.bright}${z.length}${e.blue} middleware: ${e.dim}${z.join(", ")}${e.reset}`);let G={},te=null;try{let{loadStxConfig:A}=await import("./chunk-48bwk47q.js"),N=await A(u);if(N?.apiRouter)te=N?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(N?.apiRoutes){G=N.apiRoutes;let U=Object.keys(G).length;if(U>0)console.log(`${e.blue}Loaded ${e.bright}${U} API route${U>1?"s":""}${e.reset}`)}if(N?.broadcasting?.enabled)try{let{startBroadcasting:U,loadChannels:V}=await import("./chunk-dgdm3hy3.js"),xe=N.broadcasting;await U(xe);let We=xe.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${We}/ws${e.reset}`);let Ge=oe.join(process.cwd(),"channels.ts");if(be.existsSync(Ge))try{let ne=await V(Ge);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(U){console.warn(`${e.yellow}Broadcasting failed to start: ${U.message}${e.reset}`)}}catch{}let Te=o(u,"output");be.mkdirSync(Te,{recursive:!0});let he=new Map,Oe=new Set,ae=async(A)=>{let N=cr(R,A);if(!N)return null;try{let U=await Bun.build({entrypoints:[N],outdir:Te,plugins:[ut],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!U.success)return null;let V=U.outputs.find((xe)=>xe.path.endsWith(".html"));if(!V)return null;return await Bun.file(V.path).text()}catch{return null}},W=new Map,B=async(A,N)=>{try{let{processDirectives:U,extractVariables:V,defaultConfig:xe,loadStxConfig:We,injectRouterScript:Ge}=await import("./chunk-48bwk47q.js"),{checkCache:ne,cacheTemplate:Z,readFileCached:q,templateCache:Y}=await import("./chunk-s2x4wcrz.js"),Se=await We(u),Je=(ce)=>{if(!ce)return ce;if(oe.isAbsolute(ce))return ce;return oe.resolve(u,ce)},D={...xe,...Se,...s.stxOptions,autoShell:!0};if(s.debugDirectives)D.debug=!0;D.partialsDir=Je(D.partialsDir),D.componentsDir=Je(D.componentsDir),D.layoutsDir=Je(D.layoutsDir),D.storesDir=Je(D.storesDir||"stores"),D.cachePath=Je(D.cachePath)??o(u,"cache");let ye=!N&&!s.profile,de=D.cache!==!1;if(de&&ye){let ce=Y.get(A.filePath);if(ce)try{if((await be.promises.stat(A.filePath)).mtime.getTime()<=ce.mtime){let ze=!0;for(let Re of ce.dependencies){if(!be.existsSync(Re)){ze=!1;break}if((await be.promises.stat(Re)).mtime.getTime()>ce.mtime){ze=!1;break}}if(ze){let Re=ce.output;if(P)Re=me(Re,{preserveHead:!0});let mt=W.get(A.filePath);return{route:A,content:Re,status:mt?.status??await un(A.filePath),headers:mt?.headers}}}}catch{}let Ie=await ne(A.filePath,D);if(Ie){let He=Ie;if(P)He=me(He,{preserveHead:!0});let ze=W.get(A.filePath);return{route:A,content:He,status:ze?.status??await un(A.filePath),headers:ze?.headers}}}let ge=de?await q(A.filePath):await Bun.file(A.filePath).text(),$e=wt(ge),{classifyAllScripts:Q}=await import("./chunk-48bwk47q.js"),Le=Q(ge),Ve=Le.server.map((ce)=>ce.content),pe=ge;for(let ce of Le.server)pe=pe.replace(ce.fullTag,"");let fe={__filename:A.filePath,__dirname:oe.dirname(A.filePath),__stx_options:D,params:N??{},__stx_runtime_head:{}};for(let ce of Ve)try{await V(ce,fe,A.filePath)}catch(Ie){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",A.filePath,Ie?.message||Ie)}let Ke=new Set,De;if(s.profile){let ce=performance.now();De=await U(pe,fe,A.filePath,D,Ke);let Ie=performance.now()-ce,He=oe.relative(u,A.filePath)||A.filePath;console.log(`[stx:profile] ${He} \u2192 ${Ie.toFixed(2)}ms`)}else De=await U(pe,fe,A.filePath,D,Ke);if(!P)De=await Ge(De,{router:D.router});{let{interpolateScriptExpressions:ce}=await import("./chunk-mhq0pjws.js");De=De.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,He,ze)=>{if(!/function\s+__stx_setup_/.test(ze))return Ie;return`<script${He}>${ce(ze,fe)}</script>`})}if(P)De=me(De,{preserveHead:!0});if(de&&ye)await Z(A.filePath,De,Ke,D);let{extractStreamBoundaries:Vn}=await import("./chunk-bmt7w2pk.js"),ct=Vn(fe),ft=fe.__streamTemplates;if(ft&&typeof ft==="object"&&Object.keys(ft).length>0){let ce=fe.streamBoundaries||{},Ie={...D,autoShell:!1},He=Object.keys(ft).map((Re)=>({id:Re,render:async()=>{let mt=typeof ce[Re]==="function"?await ce[Re]():void 0;return U(ft[Re],{...fe,$boundary:mt},A.filePath,Ie,new Set)}})),ze=new Set(He.map((Re)=>Re.id));ct=[...(ct||[]).filter((Re)=>!ze.has(Re.id)),...He]}if(ct&&ct.length>0)Oe.add(A.pattern);else ct=void 0;let qt=Be(fe),Kt=Fe(fe);if(ye)W.set(A.filePath,{status:qt,headers:Kt});return{route:A,content:De,status:qt??$e,headers:Kt,boundaries:ct}}catch(U){return console.error(`${e.red}Error building ${e.bright}${A.pattern}${e.reset}:`,U),null}},Ue=8,qe=async()=>{he.clear(),j.clear();for(let A=0;A<k.length;A+=Ue){let N=k.slice(A,A+Ue),U=await Promise.all(N.map((V)=>B(V)));for(let V of U)if(V)he.set(V.route.pattern,V)}for(let A=0;A<L.length;A+=Ue){let N=L.slice(A,A+Ue),U=await Promise.all(N.map(({route:V})=>B(V)));for(let V of U)if(V)j.set(V.route.pattern,V)}return he.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await qe())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Tt(u);let it=a;try{if(it=await Ye(a),it!==a)console.log(`${e.yellow}Port ${a} is busy, using port ${it} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let A=s.hmrPort||it+1;l=Pt({wsPort:A,verbose:!1}),m=l.start(A)}let _t=(A,N)=>{let V=`<script data-stx-route-params>(function(){var p=${JSON.stringify(N).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(A.includes("</head>"))return A.replace("</head>",`${V}</head>`);if(A.includes("<body"))return A.replace(/<body([^>]*)>/,`<body$1>${V}`);return V+A};console.log(`${e.blue}Starting server...${e.reset}`);let Lt=Gr({port:it,async fetch(A){let N=new URL(A.url),U=g?.publicDir||"public",V=oe.join(u,U,N.pathname),xe=oe.join(u,N.pathname),We=oe.join(Te,N.pathname);if([V,xe,We].some((D)=>w(D,u,S)))return new Response("Not Found",{status:404});let[Ge,ne,Z]=await Promise.all([be.promises.stat(V).catch(()=>null),be.promises.stat(xe).catch(()=>null),be.promises.stat(We).catch(()=>null)]);if(Ge?.isFile()&&!w(V,u,S))return Ut(V);if(ne?.isFile()&&!w(xe,u,S))return Ut(xe);if(Z?.isFile()&&!w(We,u,S))return Ut(We);if(N.pathname.startsWith("/_stx/component/")){let D=decodeURIComponent(N.pathname.slice(16));if(D)try{let ye=`<${D} />`,de={...buildConfig,autoShell:!1},ge=await processDirectives(ye,{},oe.join(u,"components",`${D}.stx`),de,new Set);return new Response(ge,{headers:{"Content-Type":"text/html"}})}catch(ye){return new Response(`<div class="stx-async-error">${ye.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(N.pathname==="/_stx/img"){let{handleImageRequest:D}=await import("./chunk-q6vrb2pe.js"),ye=await D(A,{publicDir:oe.join(u,U),cacheDir:o(u,"cache","img")});if(ye)return ye}if(te)try{let D=await te.handleRequest(A);if(D.status!==404)return D}catch{}if(G[N.pathname])try{return await G[N.pathname](A)}catch(D){return new Response(JSON.stringify({error:D.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await E(A);if(q)return q;let Y=yn(N.pathname,k);if(Y){let D=he.get(Y.route.pattern),ye=Oe.has(Y.route.pattern);if(Y.route.isDynamic&&Object.keys(Y.params).length>0||ye){let de=await B(Y.route,Y.params);if(de)D=de}if(D){let de=D.status??200,ge=D.headers??{},$e=(Y.route.filePath?je(await Bun.file(Y.route.filePath).text().catch(()=>"")):null)??{};if($e.validate){if(!await $e.validate({params:Y.params})){let Ve=await ae(404);if(Ve){let pe=Ve;if(pe=await f(pe,u),c)pe=Xe(pe,m);return new Response(pe,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if($e.middleware){let Le=nt(N.pathname,Y.params,$e,N.search),Ve=rt(Le,null,A,{isServer:!0}),pe=await st($e.middleware,Ve);if(pe.redirect){let fe=pe.redirect.path,Ke=pe.redirect.options.redirectCode||302,De=new Headers(pe.responseHeaders);return De.set("Location",fe),new Response(null,{status:Ke,headers:De})}if(pe.abort){let{statusCode:fe,message:Ke}=pe.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${fe}</title></head><body><h1>Error ${fe}</h1><p>${Ke}</p></body></html>`,{status:fe,headers:{"Content-Type":"text/html"}})}if(Object.keys(pe.state).length>0){let fe=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(pe.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;D.content=D.content.replace("</head>",`${fe}</head>`)}}let Q=D.content;if(P&&si(A)){let Le=Ce(Q),Ve=le(Q),pe=Q.match(/<title[^>]*>([\s\S]*?)<\/title>/i),fe=pe?ni(pe[1].trim()):"";if(Object.keys(Y.params).length>0)Q=_t(Q,Y.params);Q=await f(Q,u);let Ke=g?.router?.container||"main";return Q=ie(Q,Ke),new Response(Q,{status:de,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":Ve?"true":"false",...fe&&{"X-STX-Title":encodeURIComponent(fe)},[Ji]:ds(),...C(),"Cache-Control":Pe}})}if(P)Q=En(P,Q);if(Object.keys(Y.params).length>0)Q=_t(Q,Y.params);if(Q=await f(Q,u),c)Q=Xe(Q,m);if(s.native)if(Q.includes("<head>"))Q=Q.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 Q="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+Q;if(s.titlebarHidden)if(Q.includes("<head>"))Q=Q.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 Q=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${Q}`;if(D.boundaries&&D.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:Ve}=await import("./chunk-bmt7w2pk.js");return Ve(Le(Q,D.boundaries,{timeoutMs:30000}),{status:de,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(Q,{status:de,headers:{"Content-Type":"text/html",...C(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ge}})}}if(L.length>0){let D=L.map((de)=>de.route),ye=yn(N.pathname,D);if(ye){let de=j.get(ye.route.pattern);if(de){let ge=de.content;if(P)ge=En(P,ge);if(Object.keys(ye.params).length>0)ge=_t(ge,ye.params);if(ge=await f(ge,u),c)ge=Xe(ge,m);return new Response(ge,{status:de.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:de}of F)if(de!=="/"&&N.pathname.startsWith(de)){let ge=j.get(de)||j.get(de+"/");if(ge){let $e=ge.content;if(P)$e=En(P,$e);if($e=await f($e,u),c)$e=Xe($e,m);return new Response($e,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}let Se=he.get("/");if(Se){let D=Se.content;if(D=await f(D,u),c)D=Xe(D,m);if(s.native)if(D.includes("<head>"))D=D.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 D="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+D;return new Response(D,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Je=await ae(404);if(Je){let D=Je;if(D=await f(D,u),c)D=Xe(D,m);return new Response(D,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(A){let N=await ae(500);if(N)return new Response(N,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${A}
1429
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ze(w.url.toString(),()=>{if(p)ot.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=ot.watch(l,{recursive:!0},async(x,R)=>{if(!R)return;if(R.endsWith(".stx")||R.endsWith(".js")||R.endsWith(".ts")||R.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${R}${e.yellow} changed, rebuilding...${e.reset}`),ve.clear(),K(),await y()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function dn(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Gr}=globalThis.Bun;import be from"fs";import oe from"path";async function un(t){try{return wt(await Bun.file(t).text())}catch{return}}function Ut(t){let s=Bun.file(t),a=oe.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(a)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":p[a]||"application/octet-stream",...l}})}async function Sn(t=".",s={}){let a=s.port||3000,p=s.watch!==!1,c=s.hotReload!==!1&&p,l=null,m=s.hmrPort||a+1,u=oe.resolve(t),{loadStxConfig:y}=await import("./chunk-fbcv4fes.js"),g=await y(u),{createServerApi:b,isServerApiSource:w}=await import("./chunk-t5pvq5mx.js"),S=s.stxOptions?.serverApi??g.serverApi,E=await b(u,S),v=g.root&&g.root!=="."?oe.join(u,g.root):u,x=s.pagesDir||g.pagesDir||"pages",R=oe.join(v,x);if(!be.existsSync(R)&&!g._layerPageDirs?.some((A)=>be.existsSync(A)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${R}${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=M(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[R,...g._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${R}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let F=g?._pluginPageDirs||[],L=[];for(let{dir:A,prefix:N}of F)if(be.existsSync(A)){let U=M(oe.dirname(A),{pagesDir:oe.basename(A)});for(let V of U){let xe=N==="/"?V.pattern:`${N}${V.pattern==="/"?"":V.pattern}`;L.push({route:{...V,pattern:xe},prefix:N})}if(U.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${U.length}${e.blue} routes at ${e.cyan}${N}${e.reset}`)}let j=new Map,P=null,I=null;if(s.stxOptions?.shell!==!1){if(I=await ri(u,s.stxOptions?.shell),I){if(P=await Sr(I,s.stxOptions||{}),P)console.log(`${e.blue}Using app shell: ${e.bright}${oe.relative(u,I)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}Qe(),await tt(u);let z=et();if(z.length>0)console.log(`${e.blue}Loaded ${e.bright}${z.length}${e.blue} middleware: ${e.dim}${z.join(", ")}${e.reset}`);let G={},te=null;try{let{loadStxConfig:A}=await import("./chunk-fbcv4fes.js"),N=await A(u);if(N?.apiRouter)te=N?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(N?.apiRoutes){G=N.apiRoutes;let U=Object.keys(G).length;if(U>0)console.log(`${e.blue}Loaded ${e.bright}${U} API route${U>1?"s":""}${e.reset}`)}if(N?.broadcasting?.enabled)try{let{startBroadcasting:U,loadChannels:V}=await import("./chunk-dgdm3hy3.js"),xe=N.broadcasting;await U(xe);let We=xe.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${We}/ws${e.reset}`);let Ge=oe.join(process.cwd(),"channels.ts");if(be.existsSync(Ge))try{let ne=await V(Ge);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(U){console.warn(`${e.yellow}Broadcasting failed to start: ${U.message}${e.reset}`)}}catch{}let Te=o(u,"output");be.mkdirSync(Te,{recursive:!0});let he=new Map,Oe=new Set,ae=async(A)=>{let N=cr(R,A);if(!N)return null;try{let U=await Bun.build({entrypoints:[N],outdir:Te,plugins:[ut],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!U.success)return null;let V=U.outputs.find((xe)=>xe.path.endsWith(".html"));if(!V)return null;return await Bun.file(V.path).text()}catch{return null}},W=new Map,B=async(A,N)=>{try{let{processDirectives:U,extractVariables:V,defaultConfig:xe,loadStxConfig:We,injectRouterScript:Ge}=await import("./chunk-fbcv4fes.js"),{checkCache:ne,cacheTemplate:Z,readFileCached:q,templateCache:Y}=await import("./chunk-gea5hf0v.js"),Se=await We(u),Je=(ce)=>{if(!ce)return ce;if(oe.isAbsolute(ce))return ce;return oe.resolve(u,ce)},D={...xe,...Se,...s.stxOptions,autoShell:!0};if(s.debugDirectives)D.debug=!0;D.partialsDir=Je(D.partialsDir),D.componentsDir=Je(D.componentsDir),D.layoutsDir=Je(D.layoutsDir),D.storesDir=Je(D.storesDir||"stores"),D.cachePath=Je(D.cachePath)??o(u,"cache");let ye=!N&&!s.profile,de=D.cache!==!1;if(de&&ye){let ce=Y.get(A.filePath);if(ce)try{if((await be.promises.stat(A.filePath)).mtime.getTime()<=ce.mtime){let ze=!0;for(let Re of ce.dependencies){if(!be.existsSync(Re)){ze=!1;break}if((await be.promises.stat(Re)).mtime.getTime()>ce.mtime){ze=!1;break}}if(ze){let Re=ce.output;if(P)Re=me(Re,{preserveHead:!0});let mt=W.get(A.filePath);return{route:A,content:Re,status:mt?.status??await un(A.filePath),headers:mt?.headers}}}}catch{}let Ie=await ne(A.filePath,D);if(Ie){let He=Ie;if(P)He=me(He,{preserveHead:!0});let ze=W.get(A.filePath);return{route:A,content:He,status:ze?.status??await un(A.filePath),headers:ze?.headers}}}let ge=de?await q(A.filePath):await Bun.file(A.filePath).text(),$e=wt(ge),{classifyAllScripts:Q}=await import("./chunk-fbcv4fes.js"),Le=Q(ge),Ve=Le.server.map((ce)=>ce.content),pe=ge;for(let ce of Le.server)pe=pe.replace(ce.fullTag,"");let fe={__filename:A.filePath,__dirname:oe.dirname(A.filePath),__stx_options:D,params:N??{},__stx_runtime_head:{}};for(let ce of Ve)try{await V(ce,fe,A.filePath)}catch(Ie){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",A.filePath,Ie?.message||Ie)}let Ke=new Set,De;if(s.profile){let ce=performance.now();De=await U(pe,fe,A.filePath,D,Ke);let Ie=performance.now()-ce,He=oe.relative(u,A.filePath)||A.filePath;console.log(`[stx:profile] ${He} \u2192 ${Ie.toFixed(2)}ms`)}else De=await U(pe,fe,A.filePath,D,Ke);if(!P)De=await Ge(De,{router:D.router});{let{interpolateScriptExpressions:ce}=await import("./chunk-z8xn5ta3.js");De=De.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,He,ze)=>{if(!/function\s+__stx_setup_/.test(ze))return Ie;return`<script${He}>${ce(ze,fe)}</script>`})}if(P)De=me(De,{preserveHead:!0});if(de&&ye)await Z(A.filePath,De,Ke,D);let{extractStreamBoundaries:Vn}=await import("./chunk-gc1drn2p.js"),ct=Vn(fe),ft=fe.__streamTemplates;if(ft&&typeof ft==="object"&&Object.keys(ft).length>0){let ce=fe.streamBoundaries||{},Ie={...D,autoShell:!1},He=Object.keys(ft).map((Re)=>({id:Re,render:async()=>{let mt=typeof ce[Re]==="function"?await ce[Re]():void 0;return U(ft[Re],{...fe,$boundary:mt},A.filePath,Ie,new Set)}})),ze=new Set(He.map((Re)=>Re.id));ct=[...(ct||[]).filter((Re)=>!ze.has(Re.id)),...He]}if(ct&&ct.length>0)Oe.add(A.pattern);else ct=void 0;let qt=Be(fe),Kt=Fe(fe);if(ye)W.set(A.filePath,{status:qt,headers:Kt});return{route:A,content:De,status:qt??$e,headers:Kt,boundaries:ct}}catch(U){return console.error(`${e.red}Error building ${e.bright}${A.pattern}${e.reset}:`,U),null}},Ue=8,qe=async()=>{he.clear(),j.clear();for(let A=0;A<k.length;A+=Ue){let N=k.slice(A,A+Ue),U=await Promise.all(N.map((V)=>B(V)));for(let V of U)if(V)he.set(V.route.pattern,V)}for(let A=0;A<L.length;A+=Ue){let N=L.slice(A,A+Ue),U=await Promise.all(N.map(({route:V})=>B(V)));for(let V of U)if(V)j.set(V.route.pattern,V)}return he.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await qe())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Tt(u);let it=a;try{if(it=await Ye(a),it!==a)console.log(`${e.yellow}Port ${a} is busy, using port ${it} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let A=s.hmrPort||it+1;l=Pt({wsPort:A,verbose:!1}),m=l.start(A)}let _t=(A,N)=>{let V=`<script data-stx-route-params>(function(){var p=${JSON.stringify(N).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(A.includes("</head>"))return A.replace("</head>",`${V}</head>`);if(A.includes("<body"))return A.replace(/<body([^>]*)>/,`<body$1>${V}`);return V+A};console.log(`${e.blue}Starting server...${e.reset}`);let Lt=Gr({port:it,async fetch(A){let N=new URL(A.url),U=g?.publicDir||"public",V=oe.join(u,U,N.pathname),xe=oe.join(u,N.pathname),We=oe.join(Te,N.pathname);if([V,xe,We].some((D)=>w(D,u,S)))return new Response("Not Found",{status:404});let[Ge,ne,Z]=await Promise.all([be.promises.stat(V).catch(()=>null),be.promises.stat(xe).catch(()=>null),be.promises.stat(We).catch(()=>null)]);if(Ge?.isFile()&&!w(V,u,S))return Ut(V);if(ne?.isFile()&&!w(xe,u,S))return Ut(xe);if(Z?.isFile()&&!w(We,u,S))return Ut(We);if(N.pathname.startsWith("/_stx/component/")){let D=decodeURIComponent(N.pathname.slice(16));if(D)try{let ye=`<${D} />`,de={...buildConfig,autoShell:!1},ge=await processDirectives(ye,{},oe.join(u,"components",`${D}.stx`),de,new Set);return new Response(ge,{headers:{"Content-Type":"text/html"}})}catch(ye){return new Response(`<div class="stx-async-error">${ye.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(N.pathname==="/_stx/img"){let{handleImageRequest:D}=await import("./chunk-q6vrb2pe.js"),ye=await D(A,{publicDir:oe.join(u,U),cacheDir:o(u,"cache","img")});if(ye)return ye}if(te)try{let D=await te.handleRequest(A);if(D.status!==404)return D}catch{}if(G[N.pathname])try{return await G[N.pathname](A)}catch(D){return new Response(JSON.stringify({error:D.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await E(A);if(q)return q;let Y=yn(N.pathname,k);if(Y){let D=he.get(Y.route.pattern),ye=Oe.has(Y.route.pattern);if(Y.route.isDynamic&&Object.keys(Y.params).length>0||ye){let de=await B(Y.route,Y.params);if(de)D=de}if(D){let de=D.status??200,ge=D.headers??{},$e=(Y.route.filePath?je(await Bun.file(Y.route.filePath).text().catch(()=>"")):null)??{};if($e.validate){if(!await $e.validate({params:Y.params})){let Ve=await ae(404);if(Ve){let pe=Ve;if(pe=await f(pe,u),c)pe=Xe(pe,m);return new Response(pe,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if($e.middleware){let Le=nt(N.pathname,Y.params,$e,N.search),Ve=rt(Le,null,A,{isServer:!0}),pe=await st($e.middleware,Ve);if(pe.redirect){let fe=pe.redirect.path,Ke=pe.redirect.options.redirectCode||302,De=new Headers(pe.responseHeaders);return De.set("Location",fe),new Response(null,{status:Ke,headers:De})}if(pe.abort){let{statusCode:fe,message:Ke}=pe.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${fe}</title></head><body><h1>Error ${fe}</h1><p>${Ke}</p></body></html>`,{status:fe,headers:{"Content-Type":"text/html"}})}if(Object.keys(pe.state).length>0){let fe=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(pe.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;D.content=D.content.replace("</head>",`${fe}</head>`)}}let Q=D.content;if(P&&si(A)){let Le=Ce(Q),Ve=le(Q),pe=Q.match(/<title[^>]*>([\s\S]*?)<\/title>/i),fe=pe?ni(pe[1].trim()):"";if(Object.keys(Y.params).length>0)Q=_t(Q,Y.params);Q=await f(Q,u);let Ke=g?.router?.container||"main";return Q=ie(Q,Ke),new Response(Q,{status:de,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":Ve?"true":"false",...fe&&{"X-STX-Title":encodeURIComponent(fe)},[Ji]:ds(),...C(),"Cache-Control":Pe}})}if(P)Q=En(P,Q);if(Object.keys(Y.params).length>0)Q=_t(Q,Y.params);if(Q=await f(Q,u),c)Q=Xe(Q,m);if(s.native)if(Q.includes("<head>"))Q=Q.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 Q="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+Q;if(s.titlebarHidden)if(Q.includes("<head>"))Q=Q.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 Q=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${Q}`;if(D.boundaries&&D.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:Ve}=await import("./chunk-gc1drn2p.js");return Ve(Le(Q,D.boundaries,{timeoutMs:30000}),{status:de,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(Q,{status:de,headers:{"Content-Type":"text/html",...C(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ge}})}}if(L.length>0){let D=L.map((de)=>de.route),ye=yn(N.pathname,D);if(ye){let de=j.get(ye.route.pattern);if(de){let ge=de.content;if(P)ge=En(P,ge);if(Object.keys(ye.params).length>0)ge=_t(ge,ye.params);if(ge=await f(ge,u),c)ge=Xe(ge,m);return new Response(ge,{status:de.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:de}of F)if(de!=="/"&&N.pathname.startsWith(de)){let ge=j.get(de)||j.get(de+"/");if(ge){let $e=ge.content;if(P)$e=En(P,$e);if($e=await f($e,u),c)$e=Xe($e,m);return new Response($e,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}let Se=he.get("/");if(Se){let D=Se.content;if(D=await f(D,u),c)D=Xe(D,m);if(s.native)if(D.includes("<head>"))D=D.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 D="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+D;return new Response(D,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Je=await ae(404);if(Je){let D=Je;if(D=await f(D,u),c)D=Xe(D,m);return new Response(D,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(A){let N=await ae(500);if(N)return new Response(N,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${A}
1430
1430
  ${A.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:${it}/${e.reset}`),c)console.log(`${e.dim} HMR: ws://localhost:${m}${e.reset}`);console.log(`
1433
1433
  ${e.yellow}Routes:${e.reset}`);let It=[...lr(k,u)];for(let{route:A}of L)It.push(`${A.pattern}`);if(It.forEach((A,N)=>{let V=N===It.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${V}${e.reset}${A}`)}),console.log(`
1434
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ze(Lt.url.toString(),()=>{if(l)gt();Lt.stop()}),s.native){let A,N=oe.join(R,"index.stx");if(be.existsSync(N)){let V=await Bun.file(N).text();A=$t(V)}let U=g?.app?.window??{};await lt(it,{title:g?.app?.head?.title||oe.basename(u)||"stx App",width:U.width,height:U.height,darkMode:U.darkMode,hotReload:U.hotReload,titlebarHidden:U.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!A,sidebarConfig:A})}if(p){console.log(`${e.blue}Watching for changes...${e.reset}`);let A=(ne)=>ne.startsWith("public/")||ne.startsWith("public\\"),N=(ne)=>{let Z=ne.toLowerCase();return Z.endsWith(".stx")||Z.endsWith(".html")||Z.endsWith(".md")},U=new Map,V=()=>{let ne=new Set([u,...g._layerGraph?.layers.map((Z)=>Z.root)??[],...g._layerGraph?.configDependencies.map((Z)=>oe.dirname(Z))??[]].filter((Z)=>be.existsSync(Z)).map((Z)=>be.realpathSync(Z)));for(let Z of g._layerGraph?.layers??[])for(let q of Object.values(Z.resources)){if(!be.existsSync(q))continue;let Y=be.realpathSync(q);if(![...ne].some((Se)=>Y===Se||Y.startsWith(`${Se}${oe.sep}`)))ne.add(Y)}for(let[Z,q]of U)if(!ne.has(Z))q.close(),U.delete(Z);for(let Z of ne)if(!U.has(Z)&&be.existsSync(Z))U.set(Z,be.watch(Z,{recursive:!0},(q,Y)=>{We(Z,q,Y).catch((Se)=>console.error("[stx] Layer rebuild failed:",Se))}))},xe=Promise.resolve(),We=(ne,Z,q)=>(xe=xe.catch(()=>{}).then(()=>Ge(ne,Z,q)),xe),Ge=async(ne,Z,q)=>{if(!q||Et(q))return;if(Rt(q)){if(g._layerGraph){let Y=await y(u);Object.assign(g,Y),k.splice(0,k.length,...M(v,{pagesDir:x,pagesDirs:Y._layerPageDirs?[R,...Y._layerPageDirs.slice(1)]:void 0})),V()}if(A(q)){if(console.log(`${e.cyan}${q} changed${e.reset}`),c&&l)l.reload(q)}else if(N(q)){console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),ve.clear(),K();try{let{invalidateFileCache:Y,templateCache:Se}=await import("./chunk-s2x4wcrz.js");Y(oe.resolve(ne,q)),Se.delete(oe.resolve(ne,q))}catch{}if(I&&q){if(oe.resolve(ne,q)===I||oe.basename(I)===q){let Se=await Sr(I,s.stxOptions||{});if(Se)P=Se}}if(await qe(),await ln(u),c&&l)l.reload(q)}else{console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),ve.clear(),K();try{let{invalidateFileCache:Y,templateCache:Se}=await import("./chunk-s2x4wcrz.js");Y(oe.resolve(ne,q)),Se.delete(oe.resolve(ne,q))}catch{}if(await qe(),c&&l)l.reload(q)}}else if(Ct(q)){if(console.log(`${e.cyan}CSS ${q} changed${e.reset}`),c&&l)l.updateCss(q)}};V(),process.on("SIGINT",()=>{for(let ne of U.values())ne.close();if(l)gt();Lt.stop(),process.exit(0)})}return!0}import Wt from"fs";import ht from"path";async function Jr(t){try{let a=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!a)return[];let p=a[1],c=[],l=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,m;while((m=l.exec(p))!==null){let u=m[1],y=m[2]||m[3]||m[4];if(!y)continue;let g={name:y},b=u.match(/@type\s+\{([^}]+)\}/i);if(b)g.type=b[1].trim();if(u.match(/@required/i))g.required=!0;let S=u.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)g.default=S[1].trim();let E=u.split(`
1434
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ze(Lt.url.toString(),()=>{if(l)gt();Lt.stop()}),s.native){let A,N=oe.join(R,"index.stx");if(be.existsSync(N)){let V=await Bun.file(N).text();A=$t(V)}let U=g?.app?.window??{};await lt(it,{title:g?.app?.head?.title||oe.basename(u)||"stx App",width:U.width,height:U.height,darkMode:U.darkMode,hotReload:U.hotReload,titlebarHidden:U.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!A,sidebarConfig:A})}if(p){console.log(`${e.blue}Watching for changes...${e.reset}`);let A=(ne)=>ne.startsWith("public/")||ne.startsWith("public\\"),N=(ne)=>{let Z=ne.toLowerCase();return Z.endsWith(".stx")||Z.endsWith(".html")||Z.endsWith(".md")},U=new Map,V=()=>{let ne=new Set([u,...g._layerGraph?.layers.map((Z)=>Z.root)??[],...g._layerGraph?.configDependencies.map((Z)=>oe.dirname(Z))??[]].filter((Z)=>be.existsSync(Z)).map((Z)=>be.realpathSync(Z)));for(let Z of g._layerGraph?.layers??[])for(let q of Object.values(Z.resources)){if(!be.existsSync(q))continue;let Y=be.realpathSync(q);if(![...ne].some((Se)=>Y===Se||Y.startsWith(`${Se}${oe.sep}`)))ne.add(Y)}for(let[Z,q]of U)if(!ne.has(Z))q.close(),U.delete(Z);for(let Z of ne)if(!U.has(Z)&&be.existsSync(Z))U.set(Z,be.watch(Z,{recursive:!0},(q,Y)=>{We(Z,q,Y).catch((Se)=>console.error("[stx] Layer rebuild failed:",Se))}))},xe=Promise.resolve(),We=(ne,Z,q)=>(xe=xe.catch(()=>{}).then(()=>Ge(ne,Z,q)),xe),Ge=async(ne,Z,q)=>{if(!q||Et(q))return;if(Rt(q)){if(g._layerGraph){let Y=await y(u);Object.assign(g,Y),k.splice(0,k.length,...M(v,{pagesDir:x,pagesDirs:Y._layerPageDirs?[R,...Y._layerPageDirs.slice(1)]:void 0})),V()}if(A(q)){if(console.log(`${e.cyan}${q} changed${e.reset}`),c&&l)l.reload(q)}else if(N(q)){console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),ve.clear(),K();try{let{invalidateFileCache:Y,templateCache:Se}=await import("./chunk-gea5hf0v.js");Y(oe.resolve(ne,q)),Se.delete(oe.resolve(ne,q))}catch{}if(I&&q){if(oe.resolve(ne,q)===I||oe.basename(I)===q){let Se=await Sr(I,s.stxOptions||{});if(Se)P=Se}}if(await qe(),await ln(u),c&&l)l.reload(q)}else{console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),ve.clear(),K();try{let{invalidateFileCache:Y,templateCache:Se}=await import("./chunk-gea5hf0v.js");Y(oe.resolve(ne,q)),Se.delete(oe.resolve(ne,q))}catch{}if(await qe(),c&&l)l.reload(q)}}else if(Ct(q)){if(console.log(`${e.cyan}CSS ${q} changed${e.reset}`),c&&l)l.updateCss(q)}};V(),process.on("SIGINT",()=>{for(let ne of U.values())ne.close();if(l)gt();Lt.stop(),process.exit(0)})}return!0}import Wt from"fs";import ht from"path";async function Jr(t){try{let a=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!a)return[];let p=a[1],c=[],l=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,m;while((m=l.exec(p))!==null){let u=m[1],y=m[2]||m[3]||m[4];if(!y)continue;let g={name:y},b=u.match(/@type\s+\{([^}]+)\}/i);if(b)g.type=b[1].trim();if(u.match(/@required/i))g.required=!0;let S=u.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)g.default=S[1].trim();let E=u.split(`
1435
1435
  `).map((v)=>v.trim().replace(/^\*\s*/,"")).filter((v)=>!v.startsWith("@")&&v.length>0);g.description=E.join(" ").trim(),c.push(g)}if(c.length===0){let u=p.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(u){let g=u[1].split(",").map((b)=>b.trim()).filter(Boolean);for(let b of g){let[w]=b.split(":").map((S)=>S.trim());if(w)c.push({name:w})}}}return c}catch(s){return console.error(`Error extracting props from ${t}:`,s),[]}}async function Yr(t){try{let s=await Bun.file(t).text(),a=s.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||s.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(a)return a[1].split(`
1436
1436
  `).map((p)=>p.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Qr(t,s=!1,a){let p=ht.basename(t,".stx"),c=await Jr(t),l=await Yr(t),m="";if(s&&a)m=`<${a}></${a}>`;else{let u=c.map((y)=>{if(y.type==="boolean")return`:${y.name}="true"`;return`${y.name}="value"`}).join(`
1437
1437
  `);m=`<${p}
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{q,r}from"./chunk-69mc2np8.js";import p from"fs";import g from"path";import*as y from"readline";var e={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m"},u={help:{description:"Show available commands",usage:"help [command]",handler:async(t,o)=>{if(t[0]&&u[t[0]]){let n=u[t[0]];console.log(`
2
+ import{q,r}from"./chunk-3efw27as.js";import p from"fs";import g from"path";import*as y from"readline";var e={reset:"\x1B[0m",bold:"\x1B[1m",dim:"\x1B[2m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m"},u={help:{description:"Show available commands",usage:"help [command]",handler:async(t,o)=>{if(t[0]&&u[t[0]]){let n=u[t[0]];console.log(`
3
3
  ${e.bold}${t[0]}${e.reset} - ${n.description}`),console.log(` Usage: ${e.cyan}${n.usage}${e.reset}
4
4
  `)}else{console.log(`
5
5
  ${e.bold}Available Commands:${e.reset}
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{xt,sc,ic,oc,ac,cc,d,lc,os,uc,qi,Xi}from"./chunk-69mc2np8.js";import"./chunk-752hw7cd.js";import"./chunk-shr559s7.js";import"./chunk-ak1cgcah.js";import"./chunk-2gr351s0.js";import"./chunk-h0atqq82.js";import"./chunk-ngc2wke4.js";import"./chunk-xfp7k0v8.js";import"./chunk-m4sk62wb.js";import"./chunk-z0g9jvv0.js";import"./chunk-8nhshfz6.js";import"./chunk-7gkv67ky.js";import"./chunk-ce1sejr3.js";import"./chunk-czxt605c.js";export{xt as STX_ENGINE_BINDING_NAMES,os as convertToCommonJS,qi as extractScriptFromTemplate,d as extractVariables,Xi as hasVariables,lc as isCompleteImport,cc as isMissingBindingFailure,oc as isModuleResolutionFailure,ac as isSyntaxFailure,uc as splitDeclaration,sc as stripTypeScript,ic as withoutStxReferrer};
2
+ import{xt,sc,ic,oc,ac,cc,d,lc,os,uc,qi,Xi}from"./chunk-3efw27as.js";import"./chunk-752hw7cd.js";import"./chunk-shr559s7.js";import"./chunk-ak1cgcah.js";import"./chunk-9amp82bx.js";import"./chunk-b98be3yp.js";import"./chunk-ngc2wke4.js";import"./chunk-xfp7k0v8.js";import"./chunk-m4sk62wb.js";import"./chunk-z0g9jvv0.js";import"./chunk-8nhshfz6.js";import"./chunk-7gkv67ky.js";import"./chunk-ce1sejr3.js";import"./chunk-czxt605c.js";export{xt as STX_ENGINE_BINDING_NAMES,os as convertToCommonJS,qi as extractScriptFromTemplate,d as extractVariables,Xi as hasVariables,lc as isCompleteImport,cc as isMissingBindingFailure,oc as isModuleResolutionFailure,ac as isSyntaxFailure,uc as splitDeclaration,sc as stripTypeScript,ic as withoutStxReferrer};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Fi,Jr,vt,b,Be,Fe,zn,d,on}from"./chunk-69mc2np8.js";import{G,xe}from"./chunk-h0atqq82.js";import{O}from"./chunk-px7fvbj6.js";var D=/\b(?:state|derived|effect|batch|ref|reactive|computed|watch|watchEffect)\s*(?:<[^>]*>)?\s*\(/;function F(t,n,e){let r={fullTag:e,content:n,attrs:t};if(/\bserver\b/.test(t))return{...r,type:"server"};if(/\bdata-stx-scoped\b/.test(t))return{...r,type:"client"};if(D.test(n))return{...r,type:"signals"};if(/\bclient\b/.test(t)||/\btype\s*=\s*["']module["']/.test(t)||/\bsrc\s*=/.test(t))return{...r,type:"client"};return{...r,type:"server"}}var H=/^<script\b([^>]*)>([\s\S]*)<\/script\s*>$/i;function ti(t){let n=[],e=[],r=[],o=0;while(o<t.length){let s=t.indexOf("<",o);if(s===-1)break;let a=xe(t,s);if(a>s){o=a;continue}let i=G(t,s);if(i>s){let c=t.slice(s,i),u=H.exec(c);if(u){let l=F(u[1],u[2],c);switch(l.type){case"signals":n.push(l);break;case"client":e.push(l);break;case"server":r.push(l);break}}o=i;continue}o=s+(t.startsWith("<!--",s)?4:1)}return{signals:n,client:e,server:r}}var L=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function V(t){let n=[],e=/<!--[\s\S]*?(?:-->|$)|<(script|style|textarea|title|template)\b[^>]*>[\s\S]*?<\/\1\s*>/gi,r;while((r=e.exec(t))!==null)n.push({start:r.index,end:r.index+r[0].length});return n}function P(t,n){return n.some((e)=>t>=e.start&&t<e.end)}function B(t){let n=(t||"").trim();if(!n)return null;if(/[\s>+~,:]/.test(n))return null;let e={},r=n,o=r.match(/^[a-z][\w-]*/i);if(o)e.tag=o[0].toLowerCase(),r=r.slice(o[0].length);while(r.length>0){let s=r.match(/^\[([\w-]+)(?:=(["']?)([^\]"']*)\2)?\]/);if(s){if(e.attr=s[1],s[3]!==void 0&&s[3]!=="")e.attrValue=s[3];r=r.slice(s[0].length);continue}let a=r.match(/^#([\w-]+)/);if(a){e.id=a[1],r=r.slice(a[0].length);continue}let i=r.match(/^\.([\w-]+)/);if(i){e.className=i[1],r=r.slice(i[0].length);continue}return null}if(!e.tag&&!e.attr&&!e.id&&!e.className)return null;return e}function q(t,n){if(n.attr){if(!(n.attrValue===void 0?new RegExp(`\\b${n.attr}(?=[\\s=>/]|$)`,"i"):new RegExp(`\\b${n.attr}\\s*=\\s*(["'])\\s*${n.attrValue}\\s*\\1`,"i")).test(t))return!1}if(n.id){if(!new RegExp(`\\bid\\s*=\\s*(["'])\\s*${n.id}\\s*\\1`,"i").test(t))return!1}if(n.className){let e=t.match(/\bclass\s*=\s*(["'])([\s\S]*?)\1/i);if(!e)return!1;if(!e[2].split(/\s+/).includes(n.className))return!1}return!0}function T(t,n="main"){let e=B(n);if(!e)return null;let r=/<([a-z][\w-]*)\b([^>]*)>/gi,o=V(t),s;while((s=r.exec(t))!==null){if(P(s.index,o))continue;let a=s[1].toLowerCase(),i=s[2]||"";if(i.trimEnd().endsWith("/")||L.has(a))continue;if(e.tag&&e.tag!==a)continue;if(!q(i,e))continue;let c=s[0],u=s.index+c.length,l=new RegExp(`<(/?)${a}\\b([^>]*)>`,"gi");l.lastIndex=u;let f=1,p;while((p=l.exec(t))!==null){if(P(p.index,o))continue;let h=p[1]==="/";if(!h&&(p[2]||"").trimEnd().endsWith("/"))continue;if(f+=h?-1:1,f===0)return{openTag:c,openIndex:s.index,start:u,end:p.index,tagName:a}}return null}return null}var Pe="private, no-store";function ni(t){return t.replace(/&#(\d+);/g,(n,e)=>M(Number(e),n)).replace(/&#x([0-9a-f]+);/gi,(n,e)=>M(Number.parseInt(e,16),n)).replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&")}function M(t,n){if(!Number.isInteger(t)||t<0||t>1114111)return n;try{return String.fromCodePoint(t)}catch{return n}}function se(t){return t.headers.get("X-STX-Router")==="true"}function z(t,n){if(!t)return n;return t.split(",").some((r)=>r.trim().toLowerCase()===n.toLowerCase())?t:`${t}, ${n}`}function C(t){return{Vary:z(t,"X-STX-Router")}}import E from"path";var U="stx-page-head:",W=/<!--stx-page-head:([A-Za-z0-9+/=]+)-->\n?/,v={dev:null,prod:null};function X(){let t=O()?"dev":"prod",n=v[t];if(n!==null)return n;try{let e=import.meta.require("./chunk-jk4njz0w.js"),r=t==="dev"&&typeof e.getRouterScriptDev==="function"?e.getRouterScriptDev:e.getRouterScript;v[t]=`<script>${r()}</script>`}catch{v[t]=""}return v[t]}async function ri(t,n){if(n===!1)return null;if(n&&typeof n==="string"){let r=E.resolve(t,n);if(await Bun.file(r).exists())return r;return null}let e=E.join(t,"app.stx");if(await Bun.file(e).exists())return e;return null}async function Sr(t,n){try{let e=await Bun.file(t).text(),r=e,o=e.match(/<template\b[^>]*>([\s\S]*?)<\/template>/i);if(o)r=o[1].trim();let s=ti(e),a=[...s.client.map((m)=>m.fullTag),...s.signals.map((m)=>m.fullTag)],i=[],c=/<style\b[^>]*>([\s\S]*?)<\/style>/gi,u;while((u=c.exec(e))!==null)i.push(u[0]);let l=r;for(let m of s.server)l=l.replace(m.fullTag,"");for(let m of s.client)l=l.replace(m.fullTag,"");l=l.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"");let f="<!--__STX_PAGE_SLOT__-->";if(l=l.replace(/<slot\s*\/>/gi,f).replace(/<slot\s*>\s*<\/slot>/gi,f),!l.includes(f))return console.warn(`[stx] Shell ${t} has no <slot /> \u2014 pages won't be injected`),null;let{processDirectives:p,extractVariables:h,defaultConfig:x,loadStxConfig:y}=await import("./chunk-48bwk47q.js"),R=await y(),g={__filename:t,__dirname:E.dirname(t)};for(let m of a){let A=m.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(A&&!m.includes("client")&&!m.includes('type="module"'))await h(A[1],g,t)}let S=await p(l,g,t,{...x,...R,...n},new Set),w=S.indexOf(f);if(w===-1)return console.warn("[stx] Shell slot placeholder lost during processing"),null;return{beforeSlot:S.substring(0,w),afterSlot:S.substring(w+f.length),filePath:t,shellScripts:a,shellStyles:i}}catch(e){return console.error(`[stx] Error processing shell ${t}:`,e),null}}function En(t,n,e){let r,o="",s=n.match(W);if(s){n=n.replace(s[0],"");try{let l=Buffer.from(s[1],"base64").toString("utf8"),f=l.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(f)r=f[1].trim();o=l.replace(/<title[^>]*>[\s\S]*?<\/title>/i,"").trim()}catch{}}let a=e||r||"stx App",i=X(),c="<script>window.__stxRouterConfig={container:'[data-stx-content]'};</script>";return`<!DOCTYPE html>
2
+ import{Fi,Jr,vt,b,Be,Fe,zn,d,on}from"./chunk-3efw27as.js";import{G,xe}from"./chunk-b98be3yp.js";import{O}from"./chunk-px7fvbj6.js";var D=/\b(?:state|derived|effect|batch|ref|reactive|computed|watch|watchEffect)\s*(?:<[^>]*>)?\s*\(/;function F(t,n,e){let r={fullTag:e,content:n,attrs:t};if(/\bserver\b/.test(t))return{...r,type:"server"};if(/\bdata-stx-scoped\b/.test(t))return{...r,type:"client"};if(D.test(n))return{...r,type:"signals"};if(/\bclient\b/.test(t)||/\btype\s*=\s*["']module["']/.test(t)||/\bsrc\s*=/.test(t))return{...r,type:"client"};return{...r,type:"server"}}var H=/^<script\b([^>]*)>([\s\S]*)<\/script\s*>$/i;function ti(t){let n=[],e=[],r=[],o=0;while(o<t.length){let s=t.indexOf("<",o);if(s===-1)break;let a=xe(t,s);if(a>s){o=a;continue}let i=G(t,s);if(i>s){let c=t.slice(s,i),u=H.exec(c);if(u){let l=F(u[1],u[2],c);switch(l.type){case"signals":n.push(l);break;case"client":e.push(l);break;case"server":r.push(l);break}}o=i;continue}o=s+(t.startsWith("<!--",s)?4:1)}return{signals:n,client:e,server:r}}var L=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function V(t){let n=[],e=/<!--[\s\S]*?(?:-->|$)|<(script|style|textarea|title|template)\b[^>]*>[\s\S]*?<\/\1\s*>/gi,r;while((r=e.exec(t))!==null)n.push({start:r.index,end:r.index+r[0].length});return n}function P(t,n){return n.some((e)=>t>=e.start&&t<e.end)}function B(t){let n=(t||"").trim();if(!n)return null;if(/[\s>+~,:]/.test(n))return null;let e={},r=n,o=r.match(/^[a-z][\w-]*/i);if(o)e.tag=o[0].toLowerCase(),r=r.slice(o[0].length);while(r.length>0){let s=r.match(/^\[([\w-]+)(?:=(["']?)([^\]"']*)\2)?\]/);if(s){if(e.attr=s[1],s[3]!==void 0&&s[3]!=="")e.attrValue=s[3];r=r.slice(s[0].length);continue}let a=r.match(/^#([\w-]+)/);if(a){e.id=a[1],r=r.slice(a[0].length);continue}let i=r.match(/^\.([\w-]+)/);if(i){e.className=i[1],r=r.slice(i[0].length);continue}return null}if(!e.tag&&!e.attr&&!e.id&&!e.className)return null;return e}function q(t,n){if(n.attr){if(!(n.attrValue===void 0?new RegExp(`\\b${n.attr}(?=[\\s=>/]|$)`,"i"):new RegExp(`\\b${n.attr}\\s*=\\s*(["'])\\s*${n.attrValue}\\s*\\1`,"i")).test(t))return!1}if(n.id){if(!new RegExp(`\\bid\\s*=\\s*(["'])\\s*${n.id}\\s*\\1`,"i").test(t))return!1}if(n.className){let e=t.match(/\bclass\s*=\s*(["'])([\s\S]*?)\1/i);if(!e)return!1;if(!e[2].split(/\s+/).includes(n.className))return!1}return!0}function T(t,n="main"){let e=B(n);if(!e)return null;let r=/<([a-z][\w-]*)\b([^>]*)>/gi,o=V(t),s;while((s=r.exec(t))!==null){if(P(s.index,o))continue;let a=s[1].toLowerCase(),i=s[2]||"";if(i.trimEnd().endsWith("/")||L.has(a))continue;if(e.tag&&e.tag!==a)continue;if(!q(i,e))continue;let c=s[0],u=s.index+c.length,l=new RegExp(`<(/?)${a}\\b([^>]*)>`,"gi");l.lastIndex=u;let f=1,p;while((p=l.exec(t))!==null){if(P(p.index,o))continue;let h=p[1]==="/";if(!h&&(p[2]||"").trimEnd().endsWith("/"))continue;if(f+=h?-1:1,f===0)return{openTag:c,openIndex:s.index,start:u,end:p.index,tagName:a}}return null}return null}var Pe="private, no-store";function ni(t){return t.replace(/&#(\d+);/g,(n,e)=>M(Number(e),n)).replace(/&#x([0-9a-f]+);/gi,(n,e)=>M(Number.parseInt(e,16),n)).replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&amp;/g,"&")}function M(t,n){if(!Number.isInteger(t)||t<0||t>1114111)return n;try{return String.fromCodePoint(t)}catch{return n}}function se(t){return t.headers.get("X-STX-Router")==="true"}function z(t,n){if(!t)return n;return t.split(",").some((r)=>r.trim().toLowerCase()===n.toLowerCase())?t:`${t}, ${n}`}function C(t){return{Vary:z(t,"X-STX-Router")}}import E from"path";var U="stx-page-head:",W=/<!--stx-page-head:([A-Za-z0-9+/=]+)-->\n?/,v={dev:null,prod:null};function X(){let t=O()?"dev":"prod",n=v[t];if(n!==null)return n;try{let e=import.meta.require("./chunk-jk4njz0w.js"),r=t==="dev"&&typeof e.getRouterScriptDev==="function"?e.getRouterScriptDev:e.getRouterScript;v[t]=`<script>${r()}</script>`}catch{v[t]=""}return v[t]}async function ri(t,n){if(n===!1)return null;if(n&&typeof n==="string"){let r=E.resolve(t,n);if(await Bun.file(r).exists())return r;return null}let e=E.join(t,"app.stx");if(await Bun.file(e).exists())return e;return null}async function Sr(t,n){try{let e=await Bun.file(t).text(),r=e,o=e.match(/<template\b[^>]*>([\s\S]*?)<\/template>/i);if(o)r=o[1].trim();let s=ti(e),a=[...s.client.map((m)=>m.fullTag),...s.signals.map((m)=>m.fullTag)],i=[],c=/<style\b[^>]*>([\s\S]*?)<\/style>/gi,u;while((u=c.exec(e))!==null)i.push(u[0]);let l=r;for(let m of s.server)l=l.replace(m.fullTag,"");for(let m of s.client)l=l.replace(m.fullTag,"");l=l.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"");let f="<!--__STX_PAGE_SLOT__-->";if(l=l.replace(/<slot\s*\/>/gi,f).replace(/<slot\s*>\s*<\/slot>/gi,f),!l.includes(f))return console.warn(`[stx] Shell ${t} has no <slot /> \u2014 pages won't be injected`),null;let{processDirectives:p,extractVariables:h,defaultConfig:x,loadStxConfig:y}=await import("./chunk-fbcv4fes.js"),R=await y(),g={__filename:t,__dirname:E.dirname(t)};for(let m of a){let A=m.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(A&&!m.includes("client")&&!m.includes('type="module"'))await h(A[1],g,t)}let S=await p(l,g,t,{...x,...R,...n},new Set),w=S.indexOf(f);if(w===-1)return console.warn("[stx] Shell slot placeholder lost during processing"),null;return{beforeSlot:S.substring(0,w),afterSlot:S.substring(w+f.length),filePath:t,shellScripts:a,shellStyles:i}}catch(e){return console.error(`[stx] Error processing shell ${t}:`,e),null}}function En(t,n,e){let r,o="",s=n.match(W);if(s){n=n.replace(s[0],"");try{let l=Buffer.from(s[1],"base64").toString("utf8"),f=l.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(f)r=f[1].trim();o=l.replace(/<title[^>]*>[\s\S]*?<\/title>/i,"").trim()}catch{}}let a=e||r||"stx App",i=X(),c="<script>window.__stxRouterConfig={container:'[data-stx-content]'};</script>";return`<!DOCTYPE html>
3
3
  <html lang="en">
4
4
  <head>
5
5
  <meta charset="UTF-8">
@@ -26,5 +26,5 @@ ${i}
26
26
  `));if(o.length>0)x.push(o.join(`
27
27
  `));if(f.length>0)x.push(f.join(`
28
28
  `));return x.push(l),x.join(`
29
- `)}import _ from"fs";import I from"path";function ii(t,n,e){return{version:1,buildTime:new Date().toISOString(),routes:t,assets:n,outputDir:e}}function oi(t,n){let e=I.join(n,"manifest.json");_.writeFileSync(e,JSON.stringify(t,null,2))}function ai(t){let n=I.join(t,"manifest.json");if(!_.existsSync(n))return null;try{let e=_.readFileSync(n,"utf-8"),r=JSON.parse(e);if(r.version!==1)return console.warn(`[stx] Manifest version mismatch: expected 1, got ${r.version}`),null;return r}catch(e){return console.warn("[stx] Failed to load manifest:",e),null}}function k(t,n,e={}){let r=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`;if(e.maxAge!==void 0)r+=`; Max-Age=${e.maxAge}`;if(e.expires)r+=`; Expires=${e.expires.toUTCString()}`;if(e.path)r+=`; Path=${e.path}`;if(e.domain)r+=`; Domain=${e.domain}`;if(e.secure)r+="; Secure";if(e.httpOnly)r+="; HttpOnly";if(e.sameSite)r+=`; SameSite=${e.sameSite}`;return r}async function K(t){let n=t.headers.get("content-type")||"",e={},r=(o,s)=>{let a=e[o];if(a===void 0)e[o]=s;else if(Array.isArray(a))a.push(s);else e[o]=[a,s]};if(n.includes("multipart/form-data")){let o=await t.formData();for(let[s,a]of o.entries())if(typeof a==="string")r(s,a);return e}if(n.includes("application/x-www-form-urlencoded")){for(let[o,s]of new URLSearchParams(await t.text()).entries())r(o,s);return e}return e}function kr(t){if(!t)return!1;let n=t.toUpperCase();return n!=="GET"&&n!=="HEAD"}async function j(t,n={}){let e=n.request,r=n.method??e?.method;if(!e||!kr(r))return{ran:!1};if(typeof t.action!=="function")return{ran:!1};let o={};try{o=await K(e)}catch{}let s=await t.action({request:e,form:o,params:n.params??{},query:t.query??{},cookies:n.cookies??{}});if(s&&typeof s==="object"){let a=s,i=Y(a.cookies),c=a.redirect;if(typeof c==="string"&&c)return{redirect:c,ran:!0,...i.length>0?{cookies:i}:{}};let{cookies:u,redirect:l,...f}=a;if(Object.assign(t,f),i.length>0)return{ran:!0,cookies:i}}return{ran:!0}}function Y(t){if(!t||typeof t!=="object"||Array.isArray(t))return[];let n=[];for(let[e,r]of Object.entries(t)){if(!e)continue;if(typeof r==="string"){n.push(k(e,r));continue}if(r&&typeof r==="object"){let o=r;if(typeof o.value!=="string")continue;n.push(k(e,o.value,o))}}return n}function ci(t,n=[],e){let r=new Headers({Location:t,"Cache-Control":"no-store"});for(let o of n)r.append("Set-Cookie",o);for(let[o,s]of Object.entries(e??{}))if(o.toLowerCase()!=="location")r.set(o,s);return new Response(null,{status:303,headers:r})}async function Mt(t,n={}){let{html:e,context:r,redirect:o,cookies:s}=await Z(t,n),a=Be(r),i=Fe(r);if(o)return{html:e,redirect:o,cookies:s,status:a,headers:i};let{extractStreamBoundaries:c}=await import("./chunk-bmt7w2pk.js"),u=c(r),l=t.streamTemplates;if(l&&Object.keys(l).length>0){let{processDirectives:f}=await import("./chunk-se7mwqd1.js"),{defaultConfig:p}=await import("./chunk-syaw6b75.js"),h=r.streamBoundaries||{},x={...p,autoShell:!1},y=Object.keys(l).map((g)=>({id:g,render:async()=>{let S=typeof h[g]==="function"?await h[g]():void 0;return f(l[g],{...r,$boundary:S},t.sourceFile,x,new Set)}})),R=new Set(y.map((g)=>g.id));u=[...(u||[]).filter((g)=>!R.has(g.id)),...y]}return{html:e,boundaries:u&&u.length>0?u:void 0,cookies:s,status:a,headers:i}}async function Z(t,n){let e={__filename:t.sourceFile,__dirname:t.sourceFile.replace(/[/\\][^/\\]+$/,""),...n};if(!t.hasServerScripts&&!Jr(t.html))return{html:t.html,context:e};for(let a of t.serverScriptContent)try{await d(a,e,t.sourceFile)}catch(i){if(n.__stx_strict_hydration)throw i;console.warn(`[stx] Server script error in ${t.sourceFile}:`,i)}let r=await j(e,{request:n.request,method:n.method,params:n.params??{},cookies:n.cookies??{}}),o=(a)=>{let i=a.replace(/<script\b[^>]*\bdata-stx-server-data\b[^>]*>[\s\S]*?<\/script>/gi,""),c=zn(e);if(!c)return i;let u=i.indexOf("</head>");return u<0?c+i:i.slice(0,u)+c+i.slice(u)};if(r.redirect)return{html:t.html,context:e,redirect:r.redirect,cookies:r.cookies};if(!Jr(t.html))return{html:o(t.html),context:e,cookies:r.cookies};let s=new Map;for(let[a,i]of Object.entries(t.placeholders))if(i.expression)try{let c=b(i.expression,e);if(i.type==="raw")s.set(a,c!==void 0&&c!==null?String(c):"");else s.set(a,c!==void 0&&c!==null?vt(String(c)):"")}catch(c){if(n.__stx_strict_hydration)throw c;s.set(a,"")}return{html:o(Fi(t.html,s)),context:e,cookies:r.cookies}}
29
+ `)}import _ from"fs";import I from"path";function ii(t,n,e){return{version:1,buildTime:new Date().toISOString(),routes:t,assets:n,outputDir:e}}function oi(t,n){let e=I.join(n,"manifest.json");_.writeFileSync(e,JSON.stringify(t,null,2))}function ai(t){let n=I.join(t,"manifest.json");if(!_.existsSync(n))return null;try{let e=_.readFileSync(n,"utf-8"),r=JSON.parse(e);if(r.version!==1)return console.warn(`[stx] Manifest version mismatch: expected 1, got ${r.version}`),null;return r}catch(e){return console.warn("[stx] Failed to load manifest:",e),null}}function k(t,n,e={}){let r=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`;if(e.maxAge!==void 0)r+=`; Max-Age=${e.maxAge}`;if(e.expires)r+=`; Expires=${e.expires.toUTCString()}`;if(e.path)r+=`; Path=${e.path}`;if(e.domain)r+=`; Domain=${e.domain}`;if(e.secure)r+="; Secure";if(e.httpOnly)r+="; HttpOnly";if(e.sameSite)r+=`; SameSite=${e.sameSite}`;return r}async function K(t){let n=t.headers.get("content-type")||"",e={},r=(o,s)=>{let a=e[o];if(a===void 0)e[o]=s;else if(Array.isArray(a))a.push(s);else e[o]=[a,s]};if(n.includes("multipart/form-data")){let o=await t.formData();for(let[s,a]of o.entries())if(typeof a==="string")r(s,a);return e}if(n.includes("application/x-www-form-urlencoded")){for(let[o,s]of new URLSearchParams(await t.text()).entries())r(o,s);return e}return e}function kr(t){if(!t)return!1;let n=t.toUpperCase();return n!=="GET"&&n!=="HEAD"}async function j(t,n={}){let e=n.request,r=n.method??e?.method;if(!e||!kr(r))return{ran:!1};if(typeof t.action!=="function")return{ran:!1};let o={};try{o=await K(e)}catch{}let s=await t.action({request:e,form:o,params:n.params??{},query:t.query??{},cookies:n.cookies??{}});if(s&&typeof s==="object"){let a=s,i=Y(a.cookies),c=a.redirect;if(typeof c==="string"&&c)return{redirect:c,ran:!0,...i.length>0?{cookies:i}:{}};let{cookies:u,redirect:l,...f}=a;if(Object.assign(t,f),i.length>0)return{ran:!0,cookies:i}}return{ran:!0}}function Y(t){if(!t||typeof t!=="object"||Array.isArray(t))return[];let n=[];for(let[e,r]of Object.entries(t)){if(!e)continue;if(typeof r==="string"){n.push(k(e,r));continue}if(r&&typeof r==="object"){let o=r;if(typeof o.value!=="string")continue;n.push(k(e,o.value,o))}}return n}function ci(t,n=[],e){let r=new Headers({Location:t,"Cache-Control":"no-store"});for(let o of n)r.append("Set-Cookie",o);for(let[o,s]of Object.entries(e??{}))if(o.toLowerCase()!=="location")r.set(o,s);return new Response(null,{status:303,headers:r})}async function Mt(t,n={}){let{html:e,context:r,redirect:o,cookies:s}=await Z(t,n),a=Be(r),i=Fe(r);if(o)return{html:e,redirect:o,cookies:s,status:a,headers:i};let{extractStreamBoundaries:c}=await import("./chunk-gc1drn2p.js"),u=c(r),l=t.streamTemplates;if(l&&Object.keys(l).length>0){let{processDirectives:f}=await import("./chunk-pdb5fw3r.js"),{defaultConfig:p}=await import("./chunk-hpgr4qgp.js"),h=r.streamBoundaries||{},x={...p,autoShell:!1},y=Object.keys(l).map((g)=>({id:g,render:async()=>{let S=typeof h[g]==="function"?await h[g]():void 0;return f(l[g],{...r,$boundary:S},t.sourceFile,x,new Set)}})),R=new Set(y.map((g)=>g.id));u=[...(u||[]).filter((g)=>!R.has(g.id)),...y]}return{html:e,boundaries:u&&u.length>0?u:void 0,cookies:s,status:a,headers:i}}async function Z(t,n){let e={__filename:t.sourceFile,__dirname:t.sourceFile.replace(/[/\\][^/\\]+$/,""),...n};if(!t.hasServerScripts&&!Jr(t.html))return{html:t.html,context:e};for(let a of t.serverScriptContent)try{await d(a,e,t.sourceFile)}catch(i){if(n.__stx_strict_hydration)throw i;console.warn(`[stx] Server script error in ${t.sourceFile}:`,i)}let r=await j(e,{request:n.request,method:n.method,params:n.params??{},cookies:n.cookies??{}}),o=(a)=>{let i=a.replace(/<script\b[^>]*\bdata-stx-server-data\b[^>]*>[\s\S]*?<\/script>/gi,""),c=zn(e);if(!c)return i;let u=i.indexOf("</head>");return u<0?c+i:i.slice(0,u)+c+i.slice(u)};if(r.redirect)return{html:t.html,context:e,redirect:r.redirect,cookies:r.cookies};if(!Jr(t.html))return{html:o(t.html),context:e,cookies:r.cookies};let s=new Map;for(let[a,i]of Object.entries(t.placeholders))if(i.expression)try{let c=b(i.expression,e);if(i.type==="raw")s.set(a,c!==void 0&&c!==null?String(c):"");else s.set(a,c!==void 0&&c!==null?vt(String(c)):"")}catch(c){if(n.__stx_strict_hydration)throw c;s.set(a,"")}return{html:o(Fi(t.html,s)),context:e,cookies:r.cookies}}
30
30
  export{ti,Pe,ni,se,C,ri,Sr,En,me,si,ie,ii,oi,ai,kr,ci,Mt};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Nn,Ne,Le,ye,zi,Bn,ee,X,sn,d,r,A}from"./chunk-69mc2np8.js";function h(o){return o.endsWith(".md")||o.endsWith(".markdown")}function _(o){let e=[];m(/<pre\b[^>]*>[\s\S]*?<\/pre>/gi);let n=[...e];m(/<code\b[^>]*>[\s\S]*?<\/code>/gi,n);function m(s,p){let u;while((u=s.exec(o))!==null){let t=u.index,i=t+u[0].length;if(p?.some((l)=>t>=l.start&&i<=l.end))continue;e.push({start:t,end:i})}}if(e.length===0)return o;e.sort((s,p)=>s.start-p.start);let a="",c=0;for(let s of e){if(s.start<c)continue;a+=o.slice(c,s.start),a+=`@raw${o.slice(s.start,s.end)}@endraw`,c=s.end}return a+=o.slice(c),a}async function b(o,e={}){let{data:n,content:m}=Nn(o),c=await(e.renderer??((s)=>Ne(s)))(m);return{html:_(c),frontmatter:n??{}}}import{dirname as C,resolve as R}from"path";function k(o){let e=o,n=ee(o);if(n)e=n.content.trim();let m=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,a=[],c=[],s=[],p=(i)=>/\b(?:state|derived|effect|batch)\s*(?:<[^<>()]*>)?\s*\(/.test(i),u;while((u=m.exec(o))!==null){let i=u[1],l=u[2],f=u[0],g=i.includes("server");if(p(l))s.push(f);else if(g)c.push(l);else a.push(f)}let t=e;{let i=/<script\b(?![^>]*\b(?:client|type\s*=\s*["']module["']|src\s*=))[^>]*>/gi,l,f=[];while((l=i.exec(t))!==null){let g=l.index+l[0].length,x=t.indexOf("</script>",g);if(x===-1)continue;f.push({start:l.index,end:x+9}),i.lastIndex=x+9}for(let g=f.length-1;g>=0;g--)t=t.substring(0,f[g].start)+t.substring(f[g].end)}for(let i of a)t=t.replace(i,"");return{templateContent:t,serverScripts:c,clientScripts:a,signalsScripts:s}}function v(o,e){return`<!DOCTYPE html>
2
+ import{Nn,Ne,Le,ye,zi,Bn,ee,X,sn,d,r,A}from"./chunk-3efw27as.js";function h(o){return o.endsWith(".md")||o.endsWith(".markdown")}function _(o){let e=[];m(/<pre\b[^>]*>[\s\S]*?<\/pre>/gi);let n=[...e];m(/<code\b[^>]*>[\s\S]*?<\/code>/gi,n);function m(s,p){let u;while((u=s.exec(o))!==null){let t=u.index,i=t+u[0].length;if(p?.some((l)=>t>=l.start&&i<=l.end))continue;e.push({start:t,end:i})}}if(e.length===0)return o;e.sort((s,p)=>s.start-p.start);let a="",c=0;for(let s of e){if(s.start<c)continue;a+=o.slice(c,s.start),a+=`@raw${o.slice(s.start,s.end)}@endraw`,c=s.end}return a+=o.slice(c),a}async function b(o,e={}){let{data:n,content:m}=Nn(o),c=await(e.renderer??((s)=>Ne(s)))(m);return{html:_(c),frontmatter:n??{}}}import{dirname as C,resolve as R}from"path";function k(o){let e=o,n=ee(o);if(n)e=n.content.trim();let m=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,a=[],c=[],s=[],p=(i)=>/\b(?:state|derived|effect|batch)\s*(?:<[^<>()]*>)?\s*\(/.test(i),u;while((u=m.exec(o))!==null){let i=u[1],l=u[2],f=u[0],g=i.includes("server");if(p(l))s.push(f);else if(g)c.push(l);else a.push(f)}let t=e;{let i=/<script\b(?![^>]*\b(?:client|type\s*=\s*["']module["']|src\s*=))[^>]*>/gi,l,f=[];while((l=i.exec(t))!==null){let g=l.index+l[0].length,x=t.indexOf("</script>",g);if(x===-1)continue;f.push({start:l.index,end:x+9}),i.lastIndex=x+9}for(let g=f.length-1;g>=0;g--)t=t.substring(0,f[g].start)+t.substring(f[g].end)}for(let i of a)t=t.replace(i,"");return{templateContent:t,serverScripts:c,clientScripts:a,signalsScripts:s}}function v(o,e){return`<!DOCTYPE html>
3
3
  <html lang="en">
4
4
  <head>
5
5
  <meta charset="UTF-8">
@@ -14,5 +14,5 @@ ${c.join(`
14
14
  `)}`}else{if(n.processClientScripts!==!1&&c.length>0){let i=p.__stx_event_bindings||[],l=Le(p),g=(await Promise.all(c.map(async(w)=>{let y=w.match(/<script\b[^>]*>([\s\S]*?)<\/script>/);if(!y)return w;return await ye(y[1],{eventBindings:i,templateContent:t,serverData:l,filePath:e})}))).join(`
15
15
  `);if(t.match(/(<\/body>)/i))t=t.replace(/(<\/body>)/i,`${g}
16
16
  $1`);else t+=`
17
- ${g}`}t=await X(t)}if(n.wrapInDocument){if(!t.trim().toLowerCase().startsWith("<!doctype")&&!t.trim().toLowerCase().startsWith("<html"))t=v(t,n.title)}if(n.injectCSS)try{let{injectCss:i}=await import("./chunk-1chw8xsw.js");t=await i(t)}catch{}return t}
17
+ ${g}`}t=await X(t)}if(n.wrapInDocument){if(!t.trim().toLowerCase().startsWith("<!doctype")&&!t.trim().toLowerCase().startsWith("<html"))t=v(t,n.title)}if(n.injectCSS)try{let{injectCss:i}=await import("./chunk-z23kaxq6.js");t=await i(t)}catch{}return t}
18
18
  export{$i};
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{$e}from"./chunk-czxt605c.js";import{Rn,Kt}from"./chunk-765e1s44.js";import{f}from"./chunk-h0atqq82.js";import{ji,Bi,wt,M,Hn,Vn,Un,r,te,A,i}from"./chunk-69mc2np8.js";import{S}from"./chunk-ngc2wke4.js";import{xs}from"./chunk-2gr351s0.js";import{mo}from"./chunk-ak1cgcah.js";import{me,ie,ii,oi,Mt}from"./chunk-scezfp0w.js";import{yt,Ur}from"./chunk-xtdw3692.js";import{Nt}from"./chunk-9g27ybyr.js";import{dt,en,tn}from"./chunk-020xyn9q.js";import m from"fs";import c from"path";import{createHash as Y}from"crypto";function J(o){return Y("sha256").update(o).digest("hex").slice(0,8)}function U(o=!1){let l=o?Kt():Rn(),a=J(l);return{content:l,filename:`runtime.${a}.js`,hash:a}}function V(){let o=$e(),l=J(o);return{content:o,filename:`router.${l}.js`,hash:l}}import q from"path";import{createHash as ee}from"crypto";function re(o={}){let l=new Set;return{context:new Proxy(o,{get(s,e){if(e in s)return s[e];if(typeof e==="string"&&!e.startsWith("__"))l.add(e);return},has(s,e){if(e in s)return!0;if(typeof e==="string"&&!e.startsWith("__"))l.add(e);return!1}}),accessedKeys:l}}async function X(o,l,a={}){let s=q.resolve(o),e=await Bun.file(s).text(),_=ee("sha256").update(e).digest("hex").slice(0,16);ji();let R={};try{R=await i(a.configDir)}catch{}let y=[],d=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,g;while((g=d.exec(e))!==null){let v=g[1];if(/\bserver\b/.test(v))y.push(g[2])}let u=new Set(y.flatMap((v)=>te(v))),{context:w}=re({__filename:s,__dirname:q.dirname(s),__stx_serverDeclared:u}),C=new Set,P={...A,...R,...a,buildMode:"compile",strict:!1},b=await r(e,w,s,P,C),T=me(b),B=Bi();return{route:l,sourceFile:o,html:b,fragment:T,placeholders:B,hasServerScripts:y.length>0,serverScriptContent:y,dependencies:Array.from(C),contentHash:_,status:wt(e),streamTemplates:w.__streamTemplates}}var se=new Set([".DS_Store","Thumbs.db","desktop.ini",".gitkeep",".gitignore"]);function Z(o,l){let a=0,s=0;if(!m.existsSync(o))return{copied:a,bytes:s};m.mkdirSync(l,{recursive:!0});function e(_,R){let y=m.readdirSync(_,{withFileTypes:!0});for(let d of y){if(se.has(d.name))continue;let g=c.join(_,d.name),u=c.join(R,d.name);if(d.isDirectory())m.mkdirSync(u,{recursive:!0}),e(g,u);else if(d.isFile()){if(m.existsSync(u))continue;m.copyFileSync(g,u),a++,s+=m.statSync(u).size}}}return e(o,l),{copied:a,bytes:s}}async function Jc(o={}){let l=Date.now(),a=c.resolve(o.root||process.cwd()),s=c.resolve(a,o.outputDir||".output");console.log("[stx build] Starting production build...");let e=await i(a),_=c.resolve(a,o.componentsDir??e.componentsDir??"components"),R=c.resolve(a,o.partialsDir??e.partialsDir??"partials"),y=c.resolve(a,o.layoutsDir??e.layoutsDir??"layouts"),d=o.publicDir??e.publicDir??"public",g=e.app?.head||{},u=e.app?.colorMode,w=e.router?.container||"main",C=o.routeRules??e.routeRules??{},P=Nt(C),b=o.serverApi??e.serverApi,T=typeof b==="object"?b:{};if(b)yt(a,T);if(e.runtimeConfig)S(e.runtimeConfig,{});if(m.existsSync(s))m.rmSync(s,{recursive:!0});let B=[c.join(s,"public","__stx"),c.join(s,"public","assets"),c.join(s,"server","pages"),c.join(s,"server","fragments")];for(let n of B)m.mkdirSync(n,{recursive:!0});console.log("[stx build] Discovering routes...");let v=M(a,{pagesDirs:e._layerPageDirs}),Q=["components","layouts","partials"],O=v.filter((n)=>!Q.some((h)=>n.pattern.startsWith(`/${h}/`)||n.pattern===`/${h}`));console.log(`[stx build] Found ${O.length} page routes (${v.length-O.length} non-page files excluded)`),console.log("[stx build] Generating shared assets...");let D=U(o.debug),x=V();await Bun.write(c.join(s,"public","__stx",D.filename),D.content),await Bun.write(c.join(s,"public","__stx",x.filename),x.content),console.log(`[stx build] Runtime: ${D.filename} (${(D.content.length/1024).toFixed(1)}KB)`),console.log(`[stx build] Router: ${x.filename} (${(x.content.length/1024).toFixed(1)}KB)`),console.log("[stx build] Compiling templates...");let k=[],F=[];for(let n of O){let h=P(n.pattern),E=h.rendering==="prerender";if(E&&(n.pattern.includes(":")||n.pattern.includes("[")))throw Error(`Cannot prerender parameter route ${n.pattern}; use dynamic rendering (explicit path enumeration is not supported here)`);try{let t=await X(n.filePath,n.pattern,{configDir:a,componentsDir:_,partialsDir:R,layoutsDir:y,debug:o.debug});if(k.push(t),t.html=t.html.replace(/runtime\.__STX_HASH__\.js/g,D.filename).replace(/router\.__STX_HASH__\.js/g,x.filename),t.html=Un(t.html,g,{bodyScripts:[`<script src="/__stx/${x.filename}"></script>`],...u&&{colorMode:u}}),u)t.html=Hn(t.html,u);if(g.htmlAttrs)t.html=Vn(t.html,g.htmlAttrs);if(!/<body[^>]*\bdata-stx=/.test(t.html)){let p=t.html.match(/<(?!body\b)[a-zA-Z][a-zA-Z0-9-]*\b[^>]*?\s(data-stx="[^"]+")[^>]*>/);if(p&&p[1]){let z=p[1];t.html=t.html.replace(" "+z,""),t.html=t.html.replace(/<body([^>]*)>/,`<body$1 ${z}>`)}}if(t.html=t.html.replace(/<style data-css="generated">[\s\S]*?<\/style>\s*/g,""),t.html=await f(t.html),E){let p=await Mt(t,{params:{},request:new Request(`http://stx.build${n.pattern}`),method:"GET",__stx_strict_hydration:!0});if(p.redirect||p.cookies?.length||p.boundaries?.length||p.headers&&Object.keys(p.headers).length)throw Error(`Prerendered route ${n.pattern} cannot set response headers/cookies, redirect or stream`);t.html=p.html,t.status=p.status??t.status,t.hasServerScripts=!1,t.serverScriptContent=[],t.placeholders={}}t.fragment=ie(t.html,w);let G=n.pattern==="/"?"index":n.pattern.slice(1).replace(/\//g,"-").replace(/[[\]]/g,"_"),I=c.join("server","pages",`${G}.compiled.json`),W=c.join("server","fragments",`${G}.html`);await Bun.write(c.join(s,I),JSON.stringify(t,null,2)),await Bun.write(c.join(s,W),t.fragment),F.push({pattern:n.pattern,compiledPath:I,fragmentPath:W,isDynamic:t.hasServerScripts,hasParams:n.pattern.includes(":")||n.pattern.includes("["),prerendered:E}),console.log(`[stx build] \u2713 ${n.pattern}`)}catch(t){if(Object.keys(h).length)throw t;console.error(`[stx build] \u2717 ${n.pattern}:`,t instanceof Error?t.message:t)}}let H=c.resolve(a,d);if(m.existsSync(H)){let{copied:n,bytes:h}=Z(H,c.join(s,"public"));if(n>0)console.log(`[stx build] Copied ${n} public asset${n===1?"":"s"} (${(h/1024).toFixed(1)}KB) from ${d}/`)}let N=tn(a);if(N){let{copied:n,bytes:h}=Z(N,c.join(s,"public",en));if(n>0)console.log(`[stx build] Copied ${n} asset${n===1?"":"s"} (${(h/1024).toFixed(1)}KB) from ${dt}/`)}let K={runtime:D.filename,router:x.filename},j=ii(F,K,s);if(j.routeRules=C,j.routerContainer=w,b)j.apiRoutes=await Ur(a,s,T);if(e.runtimeConfig)await Bun.write(c.join(s,"server/runtime-config.json"),JSON.stringify(e.runtimeConfig)),await xs(a,e.runtimeConfig);if(e._layerGraph)await Bun.write(c.join(s,"server/layers.json"),JSON.stringify(mo(e._layerGraph),null,2));oi(j,s);let L=Date.now()-l;return console.log(`
2
+ import{$e}from"./chunk-czxt605c.js";import{Rn,Kt}from"./chunk-765e1s44.js";import{f}from"./chunk-b98be3yp.js";import{ji,Bi,wt,M,Hn,Vn,Un,r,te,A,i}from"./chunk-3efw27as.js";import{S}from"./chunk-ngc2wke4.js";import{xs}from"./chunk-9amp82bx.js";import{mo}from"./chunk-ak1cgcah.js";import{me,ie,ii,oi,Mt}from"./chunk-wfy1zq53.js";import{yt,Ur}from"./chunk-hepd9qgx.js";import{Nt}from"./chunk-9g27ybyr.js";import{dt,en,tn}from"./chunk-020xyn9q.js";import m from"fs";import c from"path";import{createHash as Y}from"crypto";function J(o){return Y("sha256").update(o).digest("hex").slice(0,8)}function U(o=!1){let l=o?Kt():Rn(),a=J(l);return{content:l,filename:`runtime.${a}.js`,hash:a}}function V(){let o=$e(),l=J(o);return{content:o,filename:`router.${l}.js`,hash:l}}import q from"path";import{createHash as ee}from"crypto";function re(o={}){let l=new Set;return{context:new Proxy(o,{get(s,e){if(e in s)return s[e];if(typeof e==="string"&&!e.startsWith("__"))l.add(e);return},has(s,e){if(e in s)return!0;if(typeof e==="string"&&!e.startsWith("__"))l.add(e);return!1}}),accessedKeys:l}}async function X(o,l,a={}){let s=q.resolve(o),e=await Bun.file(s).text(),_=ee("sha256").update(e).digest("hex").slice(0,16);ji();let R={};try{R=await i(a.configDir)}catch{}let y=[],d=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,g;while((g=d.exec(e))!==null){let v=g[1];if(/\bserver\b/.test(v))y.push(g[2])}let u=new Set(y.flatMap((v)=>te(v))),{context:w}=re({__filename:s,__dirname:q.dirname(s),__stx_serverDeclared:u}),C=new Set,P={...A,...R,...a,buildMode:"compile",strict:!1},b=await r(e,w,s,P,C),T=me(b),B=Bi();return{route:l,sourceFile:o,html:b,fragment:T,placeholders:B,hasServerScripts:y.length>0,serverScriptContent:y,dependencies:Array.from(C),contentHash:_,status:wt(e),streamTemplates:w.__streamTemplates}}var se=new Set([".DS_Store","Thumbs.db","desktop.ini",".gitkeep",".gitignore"]);function Z(o,l){let a=0,s=0;if(!m.existsSync(o))return{copied:a,bytes:s};m.mkdirSync(l,{recursive:!0});function e(_,R){let y=m.readdirSync(_,{withFileTypes:!0});for(let d of y){if(se.has(d.name))continue;let g=c.join(_,d.name),u=c.join(R,d.name);if(d.isDirectory())m.mkdirSync(u,{recursive:!0}),e(g,u);else if(d.isFile()){if(m.existsSync(u))continue;m.copyFileSync(g,u),a++,s+=m.statSync(u).size}}}return e(o,l),{copied:a,bytes:s}}async function Jc(o={}){let l=Date.now(),a=c.resolve(o.root||process.cwd()),s=c.resolve(a,o.outputDir||".output");console.log("[stx build] Starting production build...");let e=await i(a),_=c.resolve(a,o.componentsDir??e.componentsDir??"components"),R=c.resolve(a,o.partialsDir??e.partialsDir??"partials"),y=c.resolve(a,o.layoutsDir??e.layoutsDir??"layouts"),d=o.publicDir??e.publicDir??"public",g=e.app?.head||{},u=e.app?.colorMode,w=e.router?.container||"main",C=o.routeRules??e.routeRules??{},P=Nt(C),b=o.serverApi??e.serverApi,T=typeof b==="object"?b:{};if(b)yt(a,T);if(e.runtimeConfig)S(e.runtimeConfig,{});if(m.existsSync(s))m.rmSync(s,{recursive:!0});let B=[c.join(s,"public","__stx"),c.join(s,"public","assets"),c.join(s,"server","pages"),c.join(s,"server","fragments")];for(let n of B)m.mkdirSync(n,{recursive:!0});console.log("[stx build] Discovering routes...");let v=M(a,{pagesDirs:e._layerPageDirs}),Q=["components","layouts","partials"],O=v.filter((n)=>!Q.some((h)=>n.pattern.startsWith(`/${h}/`)||n.pattern===`/${h}`));console.log(`[stx build] Found ${O.length} page routes (${v.length-O.length} non-page files excluded)`),console.log("[stx build] Generating shared assets...");let D=U(o.debug),x=V();await Bun.write(c.join(s,"public","__stx",D.filename),D.content),await Bun.write(c.join(s,"public","__stx",x.filename),x.content),console.log(`[stx build] Runtime: ${D.filename} (${(D.content.length/1024).toFixed(1)}KB)`),console.log(`[stx build] Router: ${x.filename} (${(x.content.length/1024).toFixed(1)}KB)`),console.log("[stx build] Compiling templates...");let k=[],F=[];for(let n of O){let h=P(n.pattern),E=h.rendering==="prerender";if(E&&(n.pattern.includes(":")||n.pattern.includes("[")))throw Error(`Cannot prerender parameter route ${n.pattern}; use dynamic rendering (explicit path enumeration is not supported here)`);try{let t=await X(n.filePath,n.pattern,{configDir:a,componentsDir:_,partialsDir:R,layoutsDir:y,debug:o.debug});if(k.push(t),t.html=t.html.replace(/runtime\.__STX_HASH__\.js/g,D.filename).replace(/router\.__STX_HASH__\.js/g,x.filename),t.html=Un(t.html,g,{bodyScripts:[`<script src="/__stx/${x.filename}"></script>`],...u&&{colorMode:u}}),u)t.html=Hn(t.html,u);if(g.htmlAttrs)t.html=Vn(t.html,g.htmlAttrs);if(!/<body[^>]*\bdata-stx=/.test(t.html)){let p=t.html.match(/<(?!body\b)[a-zA-Z][a-zA-Z0-9-]*\b[^>]*?\s(data-stx="[^"]+")[^>]*>/);if(p&&p[1]){let z=p[1];t.html=t.html.replace(" "+z,""),t.html=t.html.replace(/<body([^>]*)>/,`<body$1 ${z}>`)}}if(t.html=t.html.replace(/<style data-css="generated">[\s\S]*?<\/style>\s*/g,""),t.html=await f(t.html),E){let p=await Mt(t,{params:{},request:new Request(`http://stx.build${n.pattern}`),method:"GET",__stx_strict_hydration:!0});if(p.redirect||p.cookies?.length||p.boundaries?.length||p.headers&&Object.keys(p.headers).length)throw Error(`Prerendered route ${n.pattern} cannot set response headers/cookies, redirect or stream`);t.html=p.html,t.status=p.status??t.status,t.hasServerScripts=!1,t.serverScriptContent=[],t.placeholders={}}t.fragment=ie(t.html,w);let G=n.pattern==="/"?"index":n.pattern.slice(1).replace(/\//g,"-").replace(/[[\]]/g,"_"),I=c.join("server","pages",`${G}.compiled.json`),W=c.join("server","fragments",`${G}.html`);await Bun.write(c.join(s,I),JSON.stringify(t,null,2)),await Bun.write(c.join(s,W),t.fragment),F.push({pattern:n.pattern,compiledPath:I,fragmentPath:W,isDynamic:t.hasServerScripts,hasParams:n.pattern.includes(":")||n.pattern.includes("["),prerendered:E}),console.log(`[stx build] \u2713 ${n.pattern}`)}catch(t){if(Object.keys(h).length)throw t;console.error(`[stx build] \u2717 ${n.pattern}:`,t instanceof Error?t.message:t)}}let H=c.resolve(a,d);if(m.existsSync(H)){let{copied:n,bytes:h}=Z(H,c.join(s,"public"));if(n>0)console.log(`[stx build] Copied ${n} public asset${n===1?"":"s"} (${(h/1024).toFixed(1)}KB) from ${d}/`)}let N=tn(a);if(N){let{copied:n,bytes:h}=Z(N,c.join(s,"public",en));if(n>0)console.log(`[stx build] Copied ${n} asset${n===1?"":"s"} (${(h/1024).toFixed(1)}KB) from ${dt}/`)}let K={runtime:D.filename,router:x.filename},j=ii(F,K,s);if(j.routeRules=C,j.routerContainer=w,b)j.apiRoutes=await Ur(a,s,T);if(e.runtimeConfig)await Bun.write(c.join(s,"server/runtime-config.json"),JSON.stringify(e.runtimeConfig)),await xs(a,e.runtimeConfig);if(e._layerGraph)await Bun.write(c.join(s,"server/layers.json"),JSON.stringify(mo(e._layerGraph),null,2));oi(j,s);let L=Date.now()-l;return console.log(`
3
3
  [stx build] Done in ${L}ms \u2014 ${k.length} pages compiled`),{pageCount:k.length,assets:K,outputDir:s,duration:L}}
4
4
  export{Jc};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Mu,ec,ns,rs,Hi,Vi,ss,is,tc,nc,Ui,Wi,rc,ze}from"./chunk-69mc2np8.js";import"./chunk-752hw7cd.js";import"./chunk-shr559s7.js";import"./chunk-ak1cgcah.js";import"./chunk-2gr351s0.js";import"./chunk-h0atqq82.js";import"./chunk-ngc2wke4.js";import"./chunk-xfp7k0v8.js";import"./chunk-m4sk62wb.js";import"./chunk-z0g9jvv0.js";import"./chunk-8nhshfz6.js";import"./chunk-7gkv67ky.js";import"./chunk-ce1sejr3.js";import"./chunk-czxt605c.js";export{Mu as clearScriptScanCache,ss as convertServerLoopAttributesToDirectives,Hi as convertSignalDirectivesToAttributes,is as convertSignalLoopsToAttributes,nc as extractExports,Wi as findMarkupIndexOutsideScripts,rs as hasSignalsSyntax,ns as parseLoopExpression,Vi as preEvalLiteralReactiveIfs,tc as processScriptSetup,Ui as processSignals,rc as rewriteStxImportSpecifiers,ec as scanScriptTags,ze as stripStxRuntimeImports};
2
+ import{Mu,ec,ns,rs,Hi,Vi,ss,is,tc,nc,Ui,Wi,rc,ze}from"./chunk-3efw27as.js";import"./chunk-752hw7cd.js";import"./chunk-shr559s7.js";import"./chunk-ak1cgcah.js";import"./chunk-9amp82bx.js";import"./chunk-b98be3yp.js";import"./chunk-ngc2wke4.js";import"./chunk-xfp7k0v8.js";import"./chunk-m4sk62wb.js";import"./chunk-z0g9jvv0.js";import"./chunk-8nhshfz6.js";import"./chunk-7gkv67ky.js";import"./chunk-ce1sejr3.js";import"./chunk-czxt605c.js";export{Mu as clearScriptScanCache,ss as convertServerLoopAttributesToDirectives,Hi as convertSignalDirectivesToAttributes,is as convertSignalLoopsToAttributes,nc as extractExports,Wi as findMarkupIndexOutsideScripts,rs as hasSignalsSyntax,ns as parseLoopExpression,Vi as preEvalLiteralReactiveIfs,tc as processScriptSetup,Ui as processSignals,rc as rewriteStxImportSpecifiers,ec as scanScriptTags,ze as stripStxRuntimeImports};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{zu,vo,Hu,wo,Cc,$c,Tt,ln,Vu,Ec,Tc,f}from"./chunk-h0atqq82.js";export{Tt as buildCss,Ec as extractClassNames,$c as fingerprintConfig,Tc as generateCss,Vu as getCachedCSS,zu as getCssServeAsset,f as injectCss,vo as loadCssEngine,wo as loadCssEngineConfig,ln as rebuildCss,Hu as resetCssCache,Cc as resolveUserCssConfig};
2
+ import{zu,vo,Hu,wo,Cc,$c,Tt,ln,Vu,Ec,Tc,f}from"./chunk-b98be3yp.js";export{Tt as buildCss,Ec as extractClassNames,$c as fingerprintConfig,Tc as generateCss,Vu as getCachedCSS,zu as getCssServeAsset,f as injectCss,vo as loadCssEngine,wo as loadCssEngineConfig,ln as rebuildCss,Hu as resetCssCache,Cc as resolveUserCssConfig};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Ln,Xa,_u,Ka,Ru,Ga,jn,h,vt,be,Ja,Yr,Ya,Au,q,Za,Pu,b,Iu}from"./chunk-69mc2np8.js";import"./chunk-752hw7cd.js";import"./chunk-shr559s7.js";import"./chunk-ak1cgcah.js";import"./chunk-2gr351s0.js";import"./chunk-h0atqq82.js";import"./chunk-ngc2wke4.js";import"./chunk-xfp7k0v8.js";import"./chunk-m4sk62wb.js";import"./chunk-z0g9jvv0.js";import"./chunk-8nhshfz6.js";import"./chunk-7gkv67ky.js";import"./chunk-ce1sejr3.js";import"./chunk-czxt605c.js";export{Za as applyFilters,Ru as clearCustomFilters,Ja as clientLoopScopes,Ln as defaultFilters,h as escapeHtml,vt as escapeHtmlValue,b as evaluateExpression,Ga as findMustacheEnd,Ka as getAllFilters,Ya as interpolateScriptAttributes,Yr as interpolateScriptExpressions,Au as interpolateScriptsInTemplate,q as processExpressions,Xa as registerFilter,_u as registerFilters,jn as replaceInterpolations,Pu as resetRejectedExpressionWarnings,Iu as unescapeHtml,be as usesSignalsInScript};
2
+ import{Ln,Xa,_u,Ka,Ru,Ga,jn,h,vt,be,Ja,Yr,Ya,Au,q,Za,Pu,b,Iu}from"./chunk-3efw27as.js";import"./chunk-752hw7cd.js";import"./chunk-shr559s7.js";import"./chunk-ak1cgcah.js";import"./chunk-9amp82bx.js";import"./chunk-b98be3yp.js";import"./chunk-ngc2wke4.js";import"./chunk-xfp7k0v8.js";import"./chunk-m4sk62wb.js";import"./chunk-z0g9jvv0.js";import"./chunk-8nhshfz6.js";import"./chunk-7gkv67ky.js";import"./chunk-ce1sejr3.js";import"./chunk-czxt605c.js";export{Za as applyFilters,Ru as clearCustomFilters,Ja as clientLoopScopes,Ln as defaultFilters,h as escapeHtml,vt as escapeHtmlValue,b as evaluateExpression,Ga as findMustacheEnd,Ka as getAllFilters,Ya as interpolateScriptAttributes,Yr as interpolateScriptExpressions,Au as interpolateScriptsInTemplate,q as processExpressions,Xa as registerFilter,_u as registerFilters,jn as replaceInterpolations,Pu as resetRejectedExpressionWarnings,Iu as unescapeHtml,be as usesSignalsInScript};