@stacksjs/stx 0.2.636 → 0.2.637

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 (113) hide show
  1. package/dist/chunk-0tbsqnq3.js +2 -0
  2. package/dist/{chunk-mek121wh.js → chunk-1qt006mx.js} +46 -32
  3. package/dist/{chunk-104xw4ps.js → chunk-1t0m4pwg.js} +2 -2
  4. package/dist/chunk-2t5qqn27.js +2 -0
  5. package/dist/chunk-2xzttttk.js +2 -0
  6. package/dist/{chunk-c06b0akz.js → chunk-47shfmkf.js} +1 -1
  7. package/dist/chunk-499wgv9j.js +2 -0
  8. package/dist/{chunk-vvseb46a.js → chunk-4dpq1bnh.js} +1 -1
  9. package/dist/{chunk-cwvd8dc3.js → chunk-4w5rkk9d.js} +1 -1
  10. package/dist/{chunk-5pyv9gjh.js → chunk-55pjhpdq.js} +1 -1
  11. package/dist/chunk-5jk2nqk5.js +2 -0
  12. package/dist/{chunk-1s02ff6n.js → chunk-5kbkx0np.js} +2 -2
  13. package/dist/{chunk-mwqas1qk.js → chunk-5wyp57g3.js} +1 -1
  14. package/dist/{chunk-bx3ar1wz.js → chunk-639ngkgb.js} +1 -1
  15. package/dist/{chunk-gcj5jfbv.js → chunk-6mnwvn9v.js} +2 -2
  16. package/dist/{chunk-s15nte19.js → chunk-6tp66rf3.js} +1 -1
  17. package/dist/{chunk-arrvcn7c.js → chunk-6vmvra0f.js} +1 -1
  18. package/dist/{chunk-4a4zc8yd.js → chunk-6vtq0atz.js} +1 -1
  19. package/dist/{chunk-26g3m2mg.js → chunk-6w3nph4g.js} +2 -2
  20. package/dist/{chunk-7p8kyf4z.js → chunk-70et0fbw.js} +2 -2
  21. package/dist/chunk-72sev9mm.js +2 -0
  22. package/dist/chunk-8s1dkcwk.js +2 -0
  23. package/dist/chunk-8xqh5kjp.js +2 -0
  24. package/dist/{chunk-2kppq4pg.js → chunk-8xx631c2.js} +3 -3
  25. package/dist/{chunk-zsq0754x.js → chunk-972hgzxv.js} +8 -8
  26. package/dist/{chunk-0j9f54wv.js → chunk-9939fjh4.js} +2 -2
  27. package/dist/{chunk-mcs3wbs4.js → chunk-9f79c8pv.js} +22 -22
  28. package/dist/{chunk-215fsx0k.js → chunk-9gvq1spk.js} +1 -1
  29. package/dist/{chunk-4p4qp5ka.js → chunk-9jetjy0s.js} +1 -1
  30. package/dist/chunk-9nvrkpee.js +2 -0
  31. package/dist/{chunk-1071avjd.js → chunk-9xaztqhw.js} +1 -1
  32. package/dist/chunk-adxq3fkh.js +2 -0
  33. package/dist/{chunk-69n2ty1n.js → chunk-b56p8vqw.js} +3 -3
  34. package/dist/chunk-byrmpd9m.js +2 -0
  35. package/dist/{chunk-jdx4za9p.js → chunk-cq331w4g.js} +1 -1
  36. package/dist/{chunk-xgd6xgvz.js → chunk-dcwhp21g.js} +17 -17
  37. package/dist/{chunk-kztnn301.js → chunk-degxqdbb.js} +1 -1
  38. package/dist/chunk-dmmpezc0.js +2 -0
  39. package/dist/{chunk-dtg82vm2.js → chunk-dyg6sadv.js} +1 -1
  40. package/dist/chunk-evwbat9f.js +2 -0
  41. package/dist/{chunk-krchxt50.js → chunk-f2pk3qgg.js} +1 -1
  42. package/dist/{chunk-nxn7gnpq.js → chunk-f9wse4zx.js} +1 -1
  43. package/dist/chunk-g67016zr.js +2 -0
  44. package/dist/{chunk-mn97jhaq.js → chunk-g6s0xdgb.js} +3 -3
  45. package/dist/{chunk-7ftn9ber.js → chunk-gmxrckgj.js} +3 -3
  46. package/dist/{chunk-fk79x8ns.js → chunk-gsp3627d.js} +2 -2
  47. package/dist/chunk-h4fteh7w.js +2 -0
  48. package/dist/chunk-hf340t26.js +2 -0
  49. package/dist/{chunk-26gr5d4w.js → chunk-j00v4m56.js} +8 -8
  50. package/dist/{chunk-g1mp4e7h.js → chunk-j6fxzkn5.js} +1 -1
  51. package/dist/chunk-ky043mkv.js +2 -0
  52. package/dist/{chunk-0bptz1km.js → chunk-m690cqee.js} +251 -251
  53. package/dist/{chunk-hjtym7d9.js → chunk-m92q2jyt.js} +5 -5
  54. package/dist/{chunk-eeqw8jkw.js → chunk-mmt0mv1z.js} +5 -5
  55. package/dist/{chunk-xekmvpha.js → chunk-mqmxhggf.js} +1 -1
  56. package/dist/{chunk-51ea655x.js → chunk-myayey15.js} +1 -1
  57. package/dist/{chunk-z5ewms99.js → chunk-n7jc6gn3.js} +1 -1
  58. package/dist/chunk-nf8r47j1.js +2 -0
  59. package/dist/chunk-nfhd1gct.js +2 -0
  60. package/dist/{chunk-7jp0w5j8.js → chunk-nh812wcz.js} +1 -1
  61. package/dist/{chunk-e2p8ytdd.js → chunk-nkgzwyad.js} +1 -1
  62. package/dist/{chunk-phqtp1b4.js → chunk-nn1mncgw.js} +1 -1
  63. package/dist/chunk-ns4pc13z.js +2 -0
  64. package/dist/{chunk-b2v6v7w8.js → chunk-phdfw45x.js} +1 -1
  65. package/dist/{chunk-xdqwq7a6.js → chunk-pmyqj6yq.js} +1 -1
  66. package/dist/chunk-pnjwynpc.js +2 -0
  67. package/dist/{chunk-kmzc09w6.js → chunk-pv6yw985.js} +4 -4
  68. package/dist/{chunk-tw10tgz8.js → chunk-qmh6f1bt.js} +7 -7
  69. package/dist/{chunk-95ygdn0n.js → chunk-r00nn2qs.js} +1 -1
  70. package/dist/{chunk-k5pm9bex.js → chunk-re2mry1d.js} +1 -1
  71. package/dist/{chunk-9hqjezhx.js → chunk-s775b8ra.js} +2 -2
  72. package/dist/{chunk-z8ftsz64.js → chunk-vd63xejx.js} +1 -1
  73. package/dist/{chunk-77pj0xem.js → chunk-vq4sh8aq.js} +1 -1
  74. package/dist/{chunk-ryj2m6fk.js → chunk-xqr58cxk.js} +1 -1
  75. package/dist/{chunk-jtvrfwd8.js → chunk-y19k3vt3.js} +1 -1
  76. package/dist/chunk-y6z9qwtn.js +2 -0
  77. package/dist/chunk-ypgsyh5k.js +2 -0
  78. package/dist/{chunk-tvs9a3vk.js → chunk-z5wnd2qa.js} +1 -1
  79. package/dist/{chunk-k4xytaq3.js → chunk-zt7b6vwa.js} +4 -4
  80. package/dist/cli.js +11 -11
  81. package/dist/craft-bridge.js +4 -1
  82. package/dist/craft-entry.js +1 -1
  83. package/dist/craft.js +1 -1
  84. package/dist/native-backend.d.ts +11 -0
  85. package/dist/native-backend.js +65 -0
  86. package/dist/native-build.d.ts +1 -0
  87. package/dist/native-build.js +45 -4
  88. package/dist/pwa.js +1 -1
  89. package/dist/ssg.js +2 -2
  90. package/package.json +5 -5
  91. package/dist/chunk-1ejpz9gv.js +0 -2
  92. package/dist/chunk-2yvdnffe.js +0 -2
  93. package/dist/chunk-6g4kd71m.js +0 -2
  94. package/dist/chunk-6pewcgfq.js +0 -2
  95. package/dist/chunk-6vjg5xf3.js +0 -2
  96. package/dist/chunk-6vqk6yfm.js +0 -2
  97. package/dist/chunk-7z6ryf20.js +0 -2
  98. package/dist/chunk-8scndwf6.js +0 -2
  99. package/dist/chunk-e21q08vs.js +0 -2
  100. package/dist/chunk-ffjvqjyh.js +0 -2
  101. package/dist/chunk-ft6gfbr5.js +0 -2
  102. package/dist/chunk-h0d5vg33.js +0 -2
  103. package/dist/chunk-jp3vgscy.js +0 -2
  104. package/dist/chunk-ms4121x1.js +0 -2
  105. package/dist/chunk-n708h31w.js +0 -2
  106. package/dist/chunk-pwn2keqq.js +0 -2
  107. package/dist/chunk-r0s7vdha.js +0 -2
  108. package/dist/chunk-rwjr5bmd.js +0 -2
  109. package/dist/chunk-spz80xnc.js +0 -2
  110. package/dist/chunk-vj5fghnv.js +0 -2
  111. package/dist/chunk-wywkr0rt.js +0 -2
  112. package/dist/chunk-xj5rk4pj.js +0 -2
  113. package/dist/chunk-y1j13dha.js +0 -2
@@ -1,11 +1,11 @@
1
1
  // @bun
2
- import{J,b,xn,Sn,e,Bt,_n,f,Ye,Ft,Ze,Qe,oe,j,ye,Q,u,Re,Li,Fs,n,r,ie,br,o,P,be}from"./chunk-0bptz1km.js";import{W,jn,ae,O,Wt}from"./chunk-hjtym7d9.js";import{pt,Vn,Ir,Or,Nr,ft,gt,mt,ht,yt,bt,Ne}from"./chunk-fk79x8ns.js";import{ze,Io,ce,T,Oo,Gr,Zn,ke,No,le}from"./chunk-k4xytaq3.js";import{Kt}from"./chunk-5pyv9gjh.js";import{fe}from"./chunk-bsts9pr5.js";import{a}from"./chunk-8cqx63aw.js";import{D}from"./chunk-7mkw98cr.js";async function Wn(t){try{let s=await Bun.file(t).text(),i=Xn(s),d=Jn(s,t),c=Yn(s,i),l=Qn(s,i);return{file:t,metrics:i,issues:d,suggestions:c,performance:l}}catch(s){throw Error(`Failed to analyze template ${t}: ${s instanceof Error?s.message:String(s)}`)}}function Xn(t){let s=t.split(`
2
+ import{J,b,xn,Sn,e,Bt,_n,f,Ye,Ft,Ze,Qe,oe,j,ye,Q,u,Ae,Li,Fs,n,r,ie,br,o,P,be}from"./chunk-m690cqee.js";import{q,jn,ae,O,Wt}from"./chunk-m92q2jyt.js";import{pt,Vn,Ir,Or,Nr,ft,gt,mt,ht,yt,bt,De}from"./chunk-gsp3627d.js";import{He,Io,ce,T,Oo,Gr,Zn,ke,No,le}from"./chunk-zt7b6vwa.js";import{Kt}from"./chunk-55pjhpdq.js";import{fe}from"./chunk-bsts9pr5.js";import{a}from"./chunk-8cqx63aw.js";import{D}from"./chunk-7mkw98cr.js";async function Wn(t){try{let s=await Bun.file(t).text(),i=Xn(s),d=Jn(s,t),c=Yn(s,i),l=Qn(s,i);return{file:t,metrics:i,issues:d,suggestions:c,performance:l}}catch(s){throw Error(`Failed to analyze template ${t}: ${s instanceof Error?s.message:String(s)}`)}}function Xn(t){let s=t.split(`
3
3
  `),i=t.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),c=(i?i[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,p=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,h=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,g=m+p+h,y=(t.match(/<[A-Z][^>]*>/g)||[]).length,w=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,R=0;for(let C of s)if(/@(?:if|unless|foreach|for|while|section)\b/.test(C)&&!/@end/.test(C)&&!/@else/.test(C))R++,S=Math.max(S,R);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(C))R--;let v=S>=4?3:0,x=Math.min(10,Math.ceil(l.total*0.5+g*0.1+y*0.3+(c>10?c*0.05:0)+v));return{lines:s.length,characters:t.length,directives:l,expressions:g,components:y,layouts:w,scriptLines:c,complexity:x}}function Jn(t,s){let i=[],d=Jt(t,"if","endif");if(d>0)i.push({type:"error",category:"syntax",message:`Found ${d} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let c=Jt(t,"foreach","endforeach");if(c>0)i.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)i.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)i.push({type:"warning",category:"security",message:`Found ${m} raw output expression(s) {!! !!}`,suggestion:"Ensure raw outputs are properly sanitized to prevent XSS"});let p=t.match(/<img[^>]*>/g);if(p){let y=p.filter((w)=>!w.includes("alt="));if(y.length>0)i.push({type:"warning",category:"accessibility",message:`Found ${y.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let h=t.split(`
5
- `).filter((y)=>y.length>120);if(h.length>0)i.push({type:"info",category:"maintainability",message:`Found ${h.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)i.push({type:"info",category:"maintainability",message:`Found ${g} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return i}function Yn(t,s){let i=[];if(s.complexity>7)i.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)i.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(s.lines>100&&s.components===0)i.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(s.expressions>20)i.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let d=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(d&&d.length>0)i.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)i.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(s.scriptLines>50)i.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return i}function Qn(t,s){let i=1;if(i+=s.directives.conditionals*0.1,i+=s.directives.loops*0.5,i+=s.directives.includes*2,i+=s.expressions*0.05,i+=s.components*1,s.scriptLines>10)i+=s.scriptLines*0.1;let d;if(s.expressions===0&&s.directives.total===0)d="high";else if(s.expressions<5&&s.directives.total<3)d="medium";else d="low";let c=[];if(i>10)c.push("Consider optimizing template complexity");if(d==="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(i*100)/100,complexityScore:s.complexity,cacheability:d,recommendations:c}}function Jt(t,s,i){let d=t.replace(/<!--[\s\S]*?-->/g,""),c=(d.match(new RegExp(`@${s}\\b`,"g"))||[]).length,l=(d.match(new RegExp(`@${i}\\b`,"g"))||[]).length;return Math.abs(c-l)}async function vo(t=["**/*.stx"],s){let i=[],d=[];for(let l of t){let m=await Array.fromAsync(new Bun.Glob(l).scan({cwd:s||process.cwd(),onlyFiles:!0,absolute:!0}));d.push(...m.filter((p)=>p.endsWith(".stx")))}for(let l of d)try{let m=await Wn(l);i.push(m)}catch(m){console.warn(`Failed to analyze ${l}:`,m)}let c=er(i);return{results:i,summary:c}}function er(t){let s=t.length,i=t.reduce((g,y)=>g+y.metrics.lines,0),d=s>0?t.reduce((g,y)=>g+y.metrics.complexity,0)/s:0,c=t.reduce((g,y)=>g+y.issues.length,0),l={};t.forEach((g)=>{g.issues.forEach((y)=>{l[y.category]=(l[y.category]||0)+1})});let m=s>0?t.reduce((g,y)=>g+y.performance.estimatedRenderTime,0)/s:0,p=Math.max(1,Math.min(10,Math.round(10-m/2-d/2))),h=[];if(d>6)h.push("Project has high average complexity. Consider refactoring complex templates.");if(c>s*2)h.push("High number of issues detected. Run detailed analysis on individual files.");if(l.security>0)h.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:s,totalLines:i,avgComplexity:Math.round(d*100)/100,totalIssues:c,issuesByCategory:l,performanceScore:p,recommendations:h}}import{mkdir as tr,readFile as nr,readdir as rr,stat as Yt,writeFile as or}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 on=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 It(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function ir(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function ar(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function cr(t){let s=[];async function i(d){let c=await rr(d,{withFileTypes:!0});c.sort((l,m)=>l.name.localeCompare(m.name));for(let l of c){let m=Ee.join(d,l.name);if(l.isDirectory()){if(!l.name.startsWith(".")&&l.name!=="node_modules")await i(m)}else if(l.isFile()&&l.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(l.name))s.push(m)}}return await i(t),s}function lr(t,s){let i=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!i)return{};let d=i[1].trim();if(!d)return{};try{return JSON.parse(d)}catch(c){throw Error(`${s}: <script component> must contain JSON metadata (${c.message})`)}}function dr(t,s){let i={},d=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let c of d){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(h){throw Error(`${s}: failed to transpile <script client> (${h.message})`)}let m=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,p;while(p=m.exec(l)){let h=p[1];if(on.has(h))throw Error(`${s}: client ${rn(h)}`);let g=m.lastIndex,y=1,w="",S=!1,R=g;for(;R<l.length&&y>0;R++){let x=l[R];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==="{")y++;else if(x==="}")y--}if(y!==0)throw Error(`${s}: unterminated client function "${h}"`);let v=p[0].includes("async")?"async ":"";i[h]=`${v}${h}(${p[2]}) {${l.slice(g,R-1)}}`,m.lastIndex=R}}return i}function pr(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 Qt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((s)=>s[1].trim()).filter(Boolean).join(`
5
+ `).filter((y)=>y.length>120);if(h.length>0)i.push({type:"info",category:"maintainability",message:`Found ${h.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)i.push({type:"info",category:"maintainability",message:`Found ${g} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return i}function Yn(t,s){let i=[];if(s.complexity>7)i.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)i.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(s.lines>100&&s.components===0)i.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(s.expressions>20)i.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let d=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(d&&d.length>0)i.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)i.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(s.scriptLines>50)i.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return i}function Qn(t,s){let i=1;if(i+=s.directives.conditionals*0.1,i+=s.directives.loops*0.5,i+=s.directives.includes*2,i+=s.expressions*0.05,i+=s.components*1,s.scriptLines>10)i+=s.scriptLines*0.1;let d;if(s.expressions===0&&s.directives.total===0)d="high";else if(s.expressions<5&&s.directives.total<3)d="medium";else d="low";let c=[];if(i>10)c.push("Consider optimizing template complexity");if(d==="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(i*100)/100,complexityScore:s.complexity,cacheability:d,recommendations:c}}function Jt(t,s,i){let d=t.replace(/<!--[\s\S]*?-->/g,""),c=(d.match(new RegExp(`@${s}\\b`,"g"))||[]).length,l=(d.match(new RegExp(`@${i}\\b`,"g"))||[]).length;return Math.abs(c-l)}async function vo(t=["**/*.stx"],s){let i=[],d=[];for(let l of t){let m=await Array.fromAsync(new Bun.Glob(l).scan({cwd:s||process.cwd(),onlyFiles:!0,absolute:!0}));d.push(...m.filter((p)=>p.endsWith(".stx")))}for(let l of d)try{let m=await Wn(l);i.push(m)}catch(m){console.warn(`Failed to analyze ${l}:`,m)}let c=er(i);return{results:i,summary:c}}function er(t){let s=t.length,i=t.reduce((g,y)=>g+y.metrics.lines,0),d=s>0?t.reduce((g,y)=>g+y.metrics.complexity,0)/s:0,c=t.reduce((g,y)=>g+y.issues.length,0),l={};t.forEach((g)=>{g.issues.forEach((y)=>{l[y.category]=(l[y.category]||0)+1})});let m=s>0?t.reduce((g,y)=>g+y.performance.estimatedRenderTime,0)/s:0,p=Math.max(1,Math.min(10,Math.round(10-m/2-d/2))),h=[];if(d>6)h.push("Project has high average complexity. Consider refactoring complex templates.");if(c>s*2)h.push("High number of issues detected. Run detailed analysis on individual files.");if(l.security>0)h.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:s,totalLines:i,avgComplexity:Math.round(d*100)/100,totalIssues:c,issuesByCategory:l,performanceScore:p,recommendations:h}}import{mkdir as tr,readFile as nr,readdir as rr,stat as Yt,writeFile as or}from"fs/promises";import Re 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 on=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 It(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function ir(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function ar(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function cr(t){let s=[];async function i(d){let c=await rr(d,{withFileTypes:!0});c.sort((l,m)=>l.name.localeCompare(m.name));for(let l of c){let m=Re.join(d,l.name);if(l.isDirectory()){if(!l.name.startsWith(".")&&l.name!=="node_modules")await i(m)}else if(l.isFile()&&l.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(l.name))s.push(m)}}return await i(t),s}function lr(t,s){let i=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!i)return{};let d=i[1].trim();if(!d)return{};try{return JSON.parse(d)}catch(c){throw Error(`${s}: <script component> must contain JSON metadata (${c.message})`)}}function dr(t,s){let i={},d=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let c of d){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(h){throw Error(`${s}: failed to transpile <script client> (${h.message})`)}let m=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,p;while(p=m.exec(l)){let h=p[1];if(on.has(h))throw Error(`${s}: client ${rn(h)}`);let g=m.lastIndex,y=1,w="",S=!1,R=g;for(;R<l.length&&y>0;R++){let x=l[R];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==="{")y++;else if(x==="}")y--}if(y!==0)throw Error(`${s}: unterminated client function "${h}"`);let v=p[0].includes("async")?"async ":"";i[h]=`${v}${h}(${p[2]}) {${l.slice(g,R-1)}}`,m.lastIndex=R}}return i}function pr(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 Qt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((s)=>s[1].trim()).filter(Boolean).join(`
6
6
 
7
7
  `)}function ur(t){if(!t)return null;let s=t.replace(/\s*\|\s*(?:undefined|null)\b/g,"").trim();if(/^string$/.test(s))return"string";if(/^number$/.test(s))return"number";if(/^boolean$/.test(s))return"boolean";if(/^(?:'[^']*'|"[^"]*")(?:\s*\|\s*(?:'[^']*'|"[^"]*"))*$/.test(s))return"string";return"object"}function fr(t){if(t===void 0)return"object";if(t==="true"||t==="false")return"boolean";if(/^-?\d+(?:\.\d+)?$/.test(t))return"number";if(/^['"`]/.test(t))return"string";return"object"}function mr(t){if(t==="true")return!0;if(t==="false")return!1;if(/^-?\d+(?:\.\d+)?$/.test(t))return Number(t);if(/^['"`]/.test(t))return t.slice(1,-1);try{return JSON.parse(t)}catch{return}}function gr(t){let s=[],i=0,d=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),c=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,l,m=(h)=>{if(d[h]!=="(")return null;let g=0,y="";for(let w=h;w<d.length;w++){let S=d[w];if(y!==""){if(S==="\\")w++;else if(S===y)y="";continue}if(S==="'"||S==='"'||S==="`"){y=S;continue}if(S==="(")g++;else if(S===")"){if(g--,g===0)return{expression:d.slice(h+1,w),end:w+1}}}return null},p=(h)=>{if(h==="")return;let g=0,y=/\{!!\s*([\s\S]*?)\s*!!\}|\{\{\s*([\s\S]*?)\s*\}\}/g,w;while(w=y.exec(h)){if(w.index>g)s.push(`out += ${JSON.stringify(h.slice(g,w.index))};`);s.push(w[1]!==void 0?`out += __raw(${w[1]});`:`out += __escape(${w[2]});`),g=w.index+w[0].length}if(g<h.length)s.push(`out += ${JSON.stringify(h.slice(g))};`)};while(l=c.exec(d)){p(d.slice(i,l.index)),i=l.index+l[0].length;let g=l[1]==="if"||l[1]==="elseif"||l[1]==="foreach"?m(i):null;if(g)i=g.end,c.lastIndex=g.end;let y=g?.expression;switch(l[1]){case"if":s.push(`if (${y}) {`);break;case"elseif":s.push(`} else if (${y}) {`);break;case"else":s.push("} else {");break;case"endif":case"endforeach":s.push("}");break;case"foreach":{let w=/^([\s\S]+?)\s+as\s+(?:([A-Za-z_$][\w$]*)\s*=>\s*)?([A-Za-z_$][\w$]*)$/.exec((y||"").trim());if(!w){s.push(`out += ${JSON.stringify(l[0]+(g?`(${y})`:""))};`);break}let[,S,R,v]=w;s.push(R?`for (const [${R}, ${v}] of __entries(${S})) {`:`for (const ${v} of __values(${S})) {`);break}}}return p(d.slice(i)),s.join(`
8
- `)}function ut(t,s,i,d){if(t[s]!==i)return-1;let c=0,l=null;for(let m=s;m<t.length;m++){let p=t[m];if(l){if(p==="\\"){m++;continue}if(p===l)l=null;continue}if(p==="'"||p==='"'||p==="`"){l=p;continue}if(p===i)c++;else if(p===d){if(d===">"&&t[m-1]==="=")continue;if(c--,c===0)return m+1}}return-1}function _t(t,s,i){let d=i?"([{<":"([{",c=i?")]}>":")]}",l=[],m=0,p=null,h="";for(let g=0;g<t.length;g++){let y=t[g];if(p){if(h+=y,y==="\\"){h+=t[++g]??"";continue}if(y===p)p=null;continue}if(y==="'"||y==='"'||y==="`"){p=y,h+=y;continue}if(d.includes(y))m++;else if(c.includes(y))m--;if(m===0&&s.includes(y)){l.push(h),h="";continue}h+=y}return l.push(h),l.map((g)=>g.trim()).filter(Boolean)}function hr(t){let s=0,i=null;for(let d=0;d<t.length;d++){let c=t[d];if(i){if(c==="\\"){d++;continue}if(c===i)i=null;continue}if(c==="'"||c==='"'||c==="`"){i=c;continue}if("([{".includes(c))s++;else if(")]}".includes(c))s--;if(s!==0||c!=="=")continue;let l=t[d-1];if(t[d+1]==="="||l==="="||l==="!"||l==="<"||l===">")continue;return d}return-1}function Zt(t){switch(t.trim()){case"String":return"string";case"Number":return"number";case"Boolean":return"boolean";case"Array":return"unknown[]";case"Object":return"Record<string, unknown>";default:return}}function yr(t){let s=/\bdefineProps\b/.exec(t);if(!s)return null;let i=/(?:^|[\s;{}()])(const|let|var)\s+/g,d=-1;for(let k=i.exec(t);k&&k.index<s.index;k=i.exec(t))d=k.index+k[0].indexOf(k[1]);if(d===-1)return null;let c={},l={},m=[],p=d+(/^(?:const|let|var)\s+/.exec(t.slice(d))?.[0].length??0),h=()=>{while(p<t.length&&/\s/.test(t[p]))p++},g;if(t[p]==="{"){let k=ut(t,p,"{","}");if(k===-1)return null;g=t.slice(p,k),p=k}else{let k=/^[A-Za-z_$][\w$]*/.exec(t.slice(p));if(!k)return null;g=k[0],p+=k[0].length}if(h(),t[p]!=="=")return null;p++,h();let y=/^withDefaults\s*\(\s*/.exec(t.slice(p)),w=Boolean(y);if(y)p+=y[0].length;let S=/^defineProps\b/.exec(t.slice(p));if(!S)return null;p+=S[0].length;let R="";if(h(),t[p]==="<"){let k=ut(t,p,"<",">");if(k===-1)return null;R=t.slice(p+1,k-1).trim(),p=k}if(h(),t[p]!=="(")return null;let v=ut(t,p,"(",")");if(v===-1)return null;let x=t.slice(p+1,v-1).trim();if(p=v,w){if(h(),t[p]===",")p++,h();if(t[p]==="{"){let k=ut(t,p,"{","}");if(k===-1)return null;for(let[B,_]of Lt(t.slice(p,k)))l[B]=_;p=k}if(h(),t[p]===",")p++,h();if(t[p]===")")p++}if(t[p]===";")p++;let C=/^[A-Za-z_$][\w$]*$/.test(R)?R:void 0;if(R.startsWith("{"))for(let k of _t(R.replace(/^\{/,"").replace(/\}$/,""),",;",!0)){let B=/^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(k);if(B)c[B[1]]=B[2].trim()}if(x.startsWith("{"))for(let[k,B]of Lt(x)){if(m.push(k),!B.startsWith("{")){let _=Zt(B);if(_)c[k]=_;continue}for(let[_,I]of Lt(B))if(_==="default")l[k]=I;else if(_==="type"){let E=Zt(I);if(E)c[k]=E}}else if(x.startsWith("["))for(let k of _t(x.slice(1,-1),",",!1))m.push(k.replace(/^['"`]/,"").replace(/['"`]$/,""));if(g.startsWith("{")){m.length=0;for(let k of _t(g.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let B=hr(k),I=(B===-1?k:k.slice(0,B)).split(":")[0].trim().replace(/^\.\.\./,"");if(!I)continue;if(m.push(I),B!==-1)l[I]=k.slice(B+1).trim()}}else if(m.length===0)m.push(...Object.keys(c));return{text:t.slice(d,p),propNames:m,defaults:l,declared:c,typeName:C}}function Lt(t){let s=t.trim().replace(/^\{/,"").replace(/\}$/,""),i=[],d=0;while(d<s.length){let c=/\s*([A-Za-z_$][\w$]*)\s*:/y;c.lastIndex=d;let l=c.exec(s);if(!l)break;d=c.lastIndex;let m=0,p="",h=d;while(d<s.length){let y=s[d];if(p){if(y==="\\")d++;else if(y===p)p=""}else if(y==="'"||y==='"'||y==="`")p=y;else if(y==="{"||y==="["||y==="(")m++;else if(y==="}"||y==="]"||y===")")m--;else if(y===","&&m===0)break;d++}let g=s.slice(h,d).trim();if(g)i.push([l[1],g]);d++}return i}function xr(t,s,i){let c=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].find((S)=>!/\bcomponent\b|\bstx:component\b|\bclient\b/i.test(S[1]));if(!c)return{imports:[],body:"",propNames:[],defaults:{},declared:{}};let l=c[2],m=[],p=[],h={},g={};l=l.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm,(S)=>{if(/from\s*['"]stx['"]/.test(S))return"";return m.push(S.trim().replace(/(from\s*['"])(\.[^'"]*)(['"])/,(R,v,x,C)=>{let k=Ee.resolve(Ee.dirname(s),x),B=Ee.relative(i,k);return`${v}${B.startsWith(".")?B:`./${B}`}${C}`})),""});let y=yr(l);if(y)p.push(...y.propNames),Object.assign(h,y.defaults),Object.assign(g,y.declared),l=l.replace(y.text,"");let w={};for(let S of l.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)){let R=[];for(let v of S[2].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))g[v[1]]=v[2].trim(),R.push(v[1]);w[S[1]]=R}if(y&&y.propNames.length===0&&y.typeName){for(let S of w[y.typeName]??[])if(!p.includes(S))p.push(S)}return l=l.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g,""),{imports:m,body:l.trim(),propNames:p,defaults:h,declared:g}}function vr(t){let s=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(d,c,l,m,p)=>{let h=c.toLowerCase();s.add(h);let g=(l||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${h}="${p}"${g?` data-stx-mod-${h}="${g}"`:""}`}),eventTypes:[...s].sort()}}function wr(t){let s=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(d,c,l,m)=>{let p=s.length;return s.push({id:p,name:c,expression:m}),` data-stx-bind-${p}=""`}),bindings:s}}function Sr(t){let s=new Set;for(let i of t.matchAll(/<slot\b([^>]*)>/gi))s.add(i[1].match(/\bname\s*=\s*["']([^"']+)["']/i)?.[1]||"");return[...s].map((i)=>({name:i}))}function kr(t){return[...new Set([...t.matchAll(/(--[a-z0-9_-]+)\s*:/gi)].map((s)=>s[1]))].sort().map((s)=>({name:s}))}function en(t,s){if(!s||!new Set(["string","number","boolean","object","array"]).has(s.type))throw Error(`Property "${t}" must declare one of: string, number, boolean, object, array`);return{...s,reflect:s.reflect??s.attribute!==!1}}async function Tr(t,s,i){let d=Ee.isAbsolute(s.file)?s.file:Ee.resolve(t,s.file),c=await nr(d,"utf8"),l=lr(c,d),m=Ee.basename(d,".stx"),p=s.name||l.name||sr(m),h=`${It(i.prefix||"stx")}-${It(m)}`,g=s.tag||l.tag||h;if(!p||!/^[A-Za-z_$][\w$]*$/.test(p))throw Error(`${d}: invalid component class name "${p}"`);if(!ir(g))throw Error(`${d}: invalid custom-element tag "${g}"; tags must be lowercase and contain a hyphen`);let y=s.properties||l.properties||l.props||{},w=Object.fromEntries(Object.entries(y).map(([_,I])=>[_,en(_,I)])),S=vr(pr(c)),R=wr(S.template),v=xr(c,d,Ee.resolve(i.outputDir)),x=gr(R.template);for(let _ of v.propNames){if(w[_])continue;let I=v.defaults[_];w[_]=en(_,{type:ur(v.declared[_])??fr(I),...I===void 0?{}:{default:mr(I)}})}let C=l.methods||{},k=s.methods||{},B=dr(c,d);return{file:Ee.relative(t,d),sourcePath:d,name:p,tag:g,description:s.description||l.description||"",template:R.template,styles:Qt(c),shadowMode:ar(s.shadowDOM??l.shadowDOM??i.shadowDOM),progressive:s.progressive??l.progressive??i.progressive??!0,properties:w,events:s.events||l.events||{},methods:{...C,...k,...B},eventTypes:S.eventTypes,bindings:R.bindings,slots:Sr(R.template),cssProperties:kr(Qt(c)),scope:v,render:x}}function $r(){let t=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),s=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}");return`const HTMLElementBase = globalThis.HTMLElement || class {};
8
+ `)}function ut(t,s,i,d){if(t[s]!==i)return-1;let c=0,l=null;for(let m=s;m<t.length;m++){let p=t[m];if(l){if(p==="\\"){m++;continue}if(p===l)l=null;continue}if(p==="'"||p==='"'||p==="`"){l=p;continue}if(p===i)c++;else if(p===d){if(d===">"&&t[m-1]==="=")continue;if(c--,c===0)return m+1}}return-1}function _t(t,s,i){let d=i?"([{<":"([{",c=i?")]}>":")]}",l=[],m=0,p=null,h="";for(let g=0;g<t.length;g++){let y=t[g];if(p){if(h+=y,y==="\\"){h+=t[++g]??"";continue}if(y===p)p=null;continue}if(y==="'"||y==='"'||y==="`"){p=y,h+=y;continue}if(d.includes(y))m++;else if(c.includes(y))m--;if(m===0&&s.includes(y)){l.push(h),h="";continue}h+=y}return l.push(h),l.map((g)=>g.trim()).filter(Boolean)}function hr(t){let s=0,i=null;for(let d=0;d<t.length;d++){let c=t[d];if(i){if(c==="\\"){d++;continue}if(c===i)i=null;continue}if(c==="'"||c==='"'||c==="`"){i=c;continue}if("([{".includes(c))s++;else if(")]}".includes(c))s--;if(s!==0||c!=="=")continue;let l=t[d-1];if(t[d+1]==="="||l==="="||l==="!"||l==="<"||l===">")continue;return d}return-1}function Zt(t){switch(t.trim()){case"String":return"string";case"Number":return"number";case"Boolean":return"boolean";case"Array":return"unknown[]";case"Object":return"Record<string, unknown>";default:return}}function yr(t){let s=/\bdefineProps\b/.exec(t);if(!s)return null;let i=/(?:^|[\s;{}()])(const|let|var)\s+/g,d=-1;for(let k=i.exec(t);k&&k.index<s.index;k=i.exec(t))d=k.index+k[0].indexOf(k[1]);if(d===-1)return null;let c={},l={},m=[],p=d+(/^(?:const|let|var)\s+/.exec(t.slice(d))?.[0].length??0),h=()=>{while(p<t.length&&/\s/.test(t[p]))p++},g;if(t[p]==="{"){let k=ut(t,p,"{","}");if(k===-1)return null;g=t.slice(p,k),p=k}else{let k=/^[A-Za-z_$][\w$]*/.exec(t.slice(p));if(!k)return null;g=k[0],p+=k[0].length}if(h(),t[p]!=="=")return null;p++,h();let y=/^withDefaults\s*\(\s*/.exec(t.slice(p)),w=Boolean(y);if(y)p+=y[0].length;let S=/^defineProps\b/.exec(t.slice(p));if(!S)return null;p+=S[0].length;let R="";if(h(),t[p]==="<"){let k=ut(t,p,"<",">");if(k===-1)return null;R=t.slice(p+1,k-1).trim(),p=k}if(h(),t[p]!=="(")return null;let v=ut(t,p,"(",")");if(v===-1)return null;let x=t.slice(p+1,v-1).trim();if(p=v,w){if(h(),t[p]===",")p++,h();if(t[p]==="{"){let k=ut(t,p,"{","}");if(k===-1)return null;for(let[B,_]of Lt(t.slice(p,k)))l[B]=_;p=k}if(h(),t[p]===",")p++,h();if(t[p]===")")p++}if(t[p]===";")p++;let C=/^[A-Za-z_$][\w$]*$/.test(R)?R:void 0;if(R.startsWith("{"))for(let k of _t(R.replace(/^\{/,"").replace(/\}$/,""),",;",!0)){let B=/^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(k);if(B)c[B[1]]=B[2].trim()}if(x.startsWith("{"))for(let[k,B]of Lt(x)){if(m.push(k),!B.startsWith("{")){let _=Zt(B);if(_)c[k]=_;continue}for(let[_,I]of Lt(B))if(_==="default")l[k]=I;else if(_==="type"){let E=Zt(I);if(E)c[k]=E}}else if(x.startsWith("["))for(let k of _t(x.slice(1,-1),",",!1))m.push(k.replace(/^['"`]/,"").replace(/['"`]$/,""));if(g.startsWith("{")){m.length=0;for(let k of _t(g.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let B=hr(k),I=(B===-1?k:k.slice(0,B)).split(":")[0].trim().replace(/^\.\.\./,"");if(!I)continue;if(m.push(I),B!==-1)l[I]=k.slice(B+1).trim()}}else if(m.length===0)m.push(...Object.keys(c));return{text:t.slice(d,p),propNames:m,defaults:l,declared:c,typeName:C}}function Lt(t){let s=t.trim().replace(/^\{/,"").replace(/\}$/,""),i=[],d=0;while(d<s.length){let c=/\s*([A-Za-z_$][\w$]*)\s*:/y;c.lastIndex=d;let l=c.exec(s);if(!l)break;d=c.lastIndex;let m=0,p="",h=d;while(d<s.length){let y=s[d];if(p){if(y==="\\")d++;else if(y===p)p=""}else if(y==="'"||y==='"'||y==="`")p=y;else if(y==="{"||y==="["||y==="(")m++;else if(y==="}"||y==="]"||y===")")m--;else if(y===","&&m===0)break;d++}let g=s.slice(h,d).trim();if(g)i.push([l[1],g]);d++}return i}function xr(t,s,i){let c=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].find((S)=>!/\bcomponent\b|\bstx:component\b|\bclient\b/i.test(S[1]));if(!c)return{imports:[],body:"",propNames:[],defaults:{},declared:{}};let l=c[2],m=[],p=[],h={},g={};l=l.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm,(S)=>{if(/from\s*['"]stx['"]/.test(S))return"";return m.push(S.trim().replace(/(from\s*['"])(\.[^'"]*)(['"])/,(R,v,x,C)=>{let k=Re.resolve(Re.dirname(s),x),B=Re.relative(i,k);return`${v}${B.startsWith(".")?B:`./${B}`}${C}`})),""});let y=yr(l);if(y)p.push(...y.propNames),Object.assign(h,y.defaults),Object.assign(g,y.declared),l=l.replace(y.text,"");let w={};for(let S of l.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)){let R=[];for(let v of S[2].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))g[v[1]]=v[2].trim(),R.push(v[1]);w[S[1]]=R}if(y&&y.propNames.length===0&&y.typeName){for(let S of w[y.typeName]??[])if(!p.includes(S))p.push(S)}return l=l.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g,""),{imports:m,body:l.trim(),propNames:p,defaults:h,declared:g}}function vr(t){let s=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(d,c,l,m,p)=>{let h=c.toLowerCase();s.add(h);let g=(l||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${h}="${p}"${g?` data-stx-mod-${h}="${g}"`:""}`}),eventTypes:[...s].sort()}}function wr(t){let s=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(d,c,l,m)=>{let p=s.length;return s.push({id:p,name:c,expression:m}),` data-stx-bind-${p}=""`}),bindings:s}}function Sr(t){let s=new Set;for(let i of t.matchAll(/<slot\b([^>]*)>/gi))s.add(i[1].match(/\bname\s*=\s*["']([^"']+)["']/i)?.[1]||"");return[...s].map((i)=>({name:i}))}function kr(t){return[...new Set([...t.matchAll(/(--[a-z0-9_-]+)\s*:/gi)].map((s)=>s[1]))].sort().map((s)=>({name:s}))}function en(t,s){if(!s||!new Set(["string","number","boolean","object","array"]).has(s.type))throw Error(`Property "${t}" must declare one of: string, number, boolean, object, array`);return{...s,reflect:s.reflect??s.attribute!==!1}}async function Tr(t,s,i){let d=Re.isAbsolute(s.file)?s.file:Re.resolve(t,s.file),c=await nr(d,"utf8"),l=lr(c,d),m=Re.basename(d,".stx"),p=s.name||l.name||sr(m),h=`${It(i.prefix||"stx")}-${It(m)}`,g=s.tag||l.tag||h;if(!p||!/^[A-Za-z_$][\w$]*$/.test(p))throw Error(`${d}: invalid component class name "${p}"`);if(!ir(g))throw Error(`${d}: invalid custom-element tag "${g}"; tags must be lowercase and contain a hyphen`);let y=s.properties||l.properties||l.props||{},w=Object.fromEntries(Object.entries(y).map(([_,I])=>[_,en(_,I)])),S=vr(pr(c)),R=wr(S.template),v=xr(c,d,Re.resolve(i.outputDir)),x=gr(R.template);for(let _ of v.propNames){if(w[_])continue;let I=v.defaults[_];w[_]=en(_,{type:ur(v.declared[_])??fr(I),...I===void 0?{}:{default:mr(I)}})}let C=l.methods||{},k=s.methods||{},B=dr(c,d);return{file:Re.relative(t,d),sourcePath:d,name:p,tag:g,description:s.description||l.description||"",template:R.template,styles:Qt(c),shadowMode:ar(s.shadowDOM??l.shadowDOM??i.shadowDOM),progressive:s.progressive??l.progressive??i.progressive??!0,properties:w,events:s.events||l.events||{},methods:{...C,...k,...B},eventTypes:S.eventTypes,bindings:R.bindings,slots:Sr(R.template),cssProperties:kr(Qt(c)),scope:v,render:x}}function $r(){let t=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),s=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}");return`const HTMLElementBase = globalThis.HTMLElement || class {};
9
9
 
10
10
  const escapeHTML = (value) => String(value ?? '')
11
11
  .replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;')
@@ -410,7 +410,7 @@ export function renderComponent(tag, props = {}, slots = {}) {
410
410
  }
411
411
 
412
412
  ${l}
413
- `}async function wo(t){let s=Ee.resolve(t.inputDir),i=Ee.resolve(t.outputDir);if(!(await Yt(s).catch(()=>null))?.isDirectory())throw Error(`Component-library input directory does not exist: ${s}`);let c=t.components?.length?t.components:(await cr(s)).map((x)=>({file:x}));if(!c.length)throw Error(`No .stx components found in ${s}`);let l=await Promise.all(c.map((x)=>Tr(s,x,t)));l.sort((x,C)=>x.tag.localeCompare(C.tag));let m=l.filter((x,C)=>l.findIndex((k)=>k.tag===x.tag)!==C);if(m.length)throw Error(`Duplicate custom-element tag: ${m[0].tag}`);let p=l.filter((x,C)=>l.findIndex((k)=>k.name===x.name)!==C);if(p.length)throw Error(`Duplicate component class name: ${p[0].name}`);await tr(i,{recursive:!0});let h=[],g=async(x,C)=>{let k=Ee.join(i,x);return await or(k,C.endsWith(`
413
+ `}async function wo(t){let s=Re.resolve(t.inputDir),i=Re.resolve(t.outputDir);if(!(await Yt(s).catch(()=>null))?.isDirectory())throw Error(`Component-library input directory does not exist: ${s}`);let c=t.components?.length?t.components:(await cr(s)).map((x)=>({file:x}));if(!c.length)throw Error(`No .stx components found in ${s}`);let l=await Promise.all(c.map((x)=>Tr(s,x,t)));l.sort((x,C)=>x.tag.localeCompare(C.tag));let m=l.filter((x,C)=>l.findIndex((k)=>k.tag===x.tag)!==C);if(m.length)throw Error(`Duplicate custom-element tag: ${m[0].tag}`);let p=l.filter((x,C)=>l.findIndex((k)=>k.name===x.name)!==C);if(p.length)throw Error(`Duplicate component class name: ${p[0].name}`);await tr(i,{recursive:!0});let h=[],g=async(x,C)=>{let k=Re.join(i,x);return await or(k,C.endsWith(`
414
414
  `)?C:`${C}
415
415
  `,"utf8"),h.push(k),k};await g("runtime.js",$r());for(let x of l){if(await g(`${x.tag}.js`,Cr(x)),t.declarations!==!1)await g(`${x.tag}.d.ts`,Rr(x));if(t.css!==!1&&x.styles){let C=x.shadowMode?x.styles:tn(x);await g(`${x.tag}.css`,t.minify?nn(C):C)}}let y=l.map((x)=>`export { ${x.name}, default as ${x.name}Element } from './${x.tag}.js';`).join(`
416
416
  `);if(await g("index.js",y),await g("ssr.js",Ar(l)),t.declarations!==!1)await g("index.d.ts",l.map((x)=>`export * from './${x.tag}.js'`).join(`
@@ -420,11 +420,11 @@ export declare function renderComponent(tag: string, props?: Record<string, unkn
420
420
  ${l.map((x)=>`import type { ${x.name}Props } from './${x.tag}.js'`).join(`
421
421
  `)}`);let w;if(t.manifest!==!1)w=await g("custom-elements.json",JSON.stringify(Pr(l),null,2));let S;if(t.css!==!1){let x=l.filter((C)=>!C.shadowMode&&C.styles).map(tn).join(`
422
422
 
423
- `);if(x)S=await g("bundle.css",t.minify?nn(x):x)}let R;if(t.bundle!==!1){R=Ee.join(i,"bundle.js");let x;try{x=await Bun.build({entrypoints:[Ee.join(i,"index.js")],outdir:i,naming:"bundle.js",target:"browser",format:"esm",minify:t.minify??!0,sourcemap:t.sourcemap||"none"})}catch(C){let k=C instanceof AggregateError?C.errors:[C],B=k.map((_)=>String(_).trim()).filter(Boolean).join(`
423
+ `);if(x)S=await g("bundle.css",t.minify?nn(x):x)}let R;if(t.bundle!==!1){R=Re.join(i,"bundle.js");let x;try{x=await Bun.build({entrypoints:[Re.join(i,"index.js")],outdir:i,naming:"bundle.js",target:"browser",format:"esm",minify:t.minify??!0,sourcemap:t.sourcemap||"none"})}catch(C){let k=C instanceof AggregateError?C.errors:[C],B=k.map((_)=>String(_).trim()).filter(Boolean).join(`
424
424
  `);throw AggregateError(k,`Failed to bundle component library${B?`
425
425
  ${B}`:""}`)}if(!x.success){let C=x.logs.map((k)=>String(k).trim()).filter(Boolean).join(`
426
426
  `);throw AggregateError(x.logs,`Failed to bundle component library${C?`
427
- ${C}`:""}`)}if(h.push(R),t.sourcemap==="external")h.push(`${R}.map`)}let v=await Promise.all(h.map(async(x)=>(await Yt(x)).size));return{components:l.map((x)=>({name:x.name,tag:x.tag,source:x.sourcePath,module:Ee.join(i,`${x.tag}.js`)})),files:h,manifest:w,bundle:R,cssBundle:S,totalBytes:v.reduce((x,C)=>x+C,0)}}var{serve:Vr}=globalThis.Bun;import Ht from"fs";import ot from"path";function vt(){return`
427
+ ${C}`:""}`)}if(h.push(R),t.sourcemap==="external")h.push(`${R}.map`)}let v=await Promise.all(h.map(async(x)=>(await Yt(x)).size));return{components:l.map((x)=>({name:x.name,tag:x.tag,source:x.sourcePath,module:Re.join(i,`${x.tag}.js`)})),files:h,manifest:w,bundle:R,cssBundle:S,totalBytes:v.reduce((x,C)=>x+C,0)}}var{serve:Vr}=globalThis.Bun;import Ht from"fs";import ot from"path";function vt(){return`
428
428
  /* Theme selector for code blocks */
429
429
  .theme-selector {
430
430
  margin: 1rem 0;
@@ -504,7 +504,7 @@ else {
504
504
  <span class="frontmatter-label">${s}:</span>
505
505
  <span>${Array.isArray(i)?i.join(", "):String(i)}</span>
506
506
  </div>`).join("")}
507
- </div>`}import sn from"net";async function Dr(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"0.0.0.0")})}async function Mr(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"::")})}async function _r(t){if(!await Dr(t))return!1;return await Mr(t)}async function Xe(t,s=20){t=Number(t);for(let i=0;i<s;i++){let d=t+i;if(await _r(d))return d}throw Error(`Could not find an available port between ${t} and ${t+s-1}`)}var Lr={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function jr(){try{let t=await import("./chunk-51ea655x.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function rt(t,s={}){let i={...Lr,...s},d=await jr();if(!d)return console.log(`${e.yellow}\u26A0${e.reset} Native window requested, but @stacksjs/desktop is not available.`),console.log(" Install & build the desktop package to enable --native."),!1;try{let c=await d.openDevWindow(t,{title:i.title,width:i.width,height:i.height,darkMode:i.darkMode,hotReload:i.hotReload,titlebarHidden:i.titlebarHidden,nativeSidebar:i.nativeSidebar,sidebarWidth:i.sidebarWidth,sidebarConfig:i.sidebarConfig});if(c&&i.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return c}catch(c){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,c),!1}}function Tt(t){if(t.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let c=t.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(c){let l=c[1];try{let m=`
507
+ </div>`}import sn from"net";async function Dr(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"0.0.0.0")})}async function Mr(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"::")})}async function _r(t){if(!await Dr(t))return!1;return await Mr(t)}async function Xe(t,s=20){t=Number(t);for(let i=0;i<s;i++){let d=t+i;if(await _r(d))return d}throw Error(`Could not find an available port between ${t} and ${t+s-1}`)}var Lr={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function jr(){try{let t=await import("./chunk-myayey15.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function rt(t,s={}){let i={...Lr,...s},d=await jr();if(!d)return console.log(`${e.yellow}\u26A0${e.reset} Native window requested, but @stacksjs/desktop is not available.`),console.log(" Install & build the desktop package to enable --native."),!1;try{let c=await d.openDevWindow(t,{title:i.title,width:i.width,height:i.height,darkMode:i.darkMode,hotReload:i.hotReload,titlebarHidden:i.titlebarHidden,nativeSidebar:i.nativeSidebar,sidebarWidth:i.sidebarWidth,sidebarConfig:i.sidebarConfig});if(c&&i.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return c}catch(c){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,c),!1}}function Tt(t){if(t.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let c=t.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(c){let l=c[1];try{let m=`
508
508
  ${l}
509
509
  return typeof sidebarConfig !== 'undefined' ? sidebarConfig : null;
510
510
  `,h=Function(m)();if(h)return h}catch(m){console.warn("Invalid sidebarConfig:",m)}}return{sections:[]}}let i=t.match(/@nativeSidebar\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(i)try{return JSON.parse(i[1])}catch{console.warn("Invalid @nativeSidebar configuration")}let d=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(d)try{let c=d[1].match(/(?:export\s+(?:default\s+)?|const\s+\w+\s*=\s*)(\{[\s\S]*\})/m);if(c)return Function(`return ${c[1]}`)()}catch(c){console.warn("Invalid native-sidebar script configuration:",c)}return}function jt(){console.log(`
@@ -677,7 +677,7 @@ ${w.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),con
677
677
  ${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(`
678
678
  ${e.bright}\u2192 ${e.cyan}http://localhost:${h}/${e.reset}`),console.log(`
679
679
  ${e.yellow}Routes:${e.reset}`);let y=ot.relative(process.cwd(),c);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${y}${e.reset}`),console.log(`
680
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(g.url.toString(),()=>{if(d)Ht.watch(ot.dirname(c),{recursive:!0}).close();g.stop()}),s.native)await rt(h,{title:ot.basename(c,".md")});if(d){let w=ot.dirname(c);console.log(`${e.blue}Watching ${e.bright}${w}${e.reset} for changes...`);let S=Ht.watch(w,{recursive:!0},async(R,v)=>{if(v&&v.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${v}${e.yellow} changed, reprocessing...${e.reset}`),await m()});process.on("SIGINT",()=>{S.close(),g.stop(),process.exit(0)})}return!0}function qr(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Xr}=globalThis.Bun;import je from"fs";import ve from"path";class an{clients=new Set;server=null;options;constructor(t={}){this.options={wsPort:t.wsPort??3001,showOverlay:t.showOverlay??!0,reconnectInterval:t.reconnectInterval??1000,maxReconnectAttempts:t.maxReconnectAttempts??10,verbose:t.verbose??!1}}start(t){let s=t??this.options.wsPort,i=20;for(let d=0;d<i;d++)try{if(this.server=Bun.serve({port:s,fetch(c,l){if(l.upgrade(c,{data:{}}))return;return new Response("stx Hot Reload Server",{headers:{"Content-Type":"text/plain"}})},websocket:{open:(c)=>{if(this.clients.add(c),this.options.verbose)console.log(`[HMR] Client connected (${this.clients.size} total)`);c.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close:(c)=>{if(this.clients.delete(c),this.options.verbose)console.log(`[HMR] Client disconnected (${this.clients.size} total)`)},message:(c,l)=>{let m=typeof l==="string"?l:l.toString();if(m==="ping")return;try{let p=JSON.parse(m);if(p.type==="console"&&Array.isArray(p.args)){let h=p.args.join(" "),y={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[p.level]??"\x1B[36m";console.log(`${y}[browser]${p.level!=="log"?` ${p.level}`:""}\x1B[0m ${h}`)}}catch{}}}}),this.options.verbose)console.log(`[HMR] WebSocket server started on port ${s}`);return s}catch(c){if(c?.code==="EADDRINUSE"){s++;continue}throw c}throw Error(`Could not find an available port after ${i} attempts starting from ${t??this.options.wsPort}`)}stop(){for(let t of this.clients)try{t.close()}catch{}if(this.clients.clear(),this.server)this.server.stop(),this.server=null;if(this.options.verbose)console.log("[HMR] Server stopped")}broadcast(t){let s=JSON.stringify(t),i=0;for(let d of this.clients)try{if(d.readyState===1)d.send(s),i++}catch{this.clients.delete(d)}if(this.options.verbose&&i>0)console.log(`[HMR] Broadcast ${t.type} to ${i} client(s)`)}reload(t){if(this.options.verbose)console.log(`[HMR] Sending reload to ${this.clients.size} client(s) for: ${t||"all"}`);this.broadcast({type:"reload",path:t,timestamp:Date.now()})}updateCss(t,s){this.broadcast({type:"css-update",path:t,content:s,timestamp:Date.now()})}error(t){this.broadcast({type:"error",content:t,timestamp:Date.now()})}get clientCount(){return this.clients.size}get port(){return this.options.wsPort}}function Kr(t,s={}){let{showOverlay:i=!0,reconnectInterval:d=1000,maxReconnectAttempts:c=10}=s;return`
680
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(g.url.toString(),()=>{if(d)Ht.watch(ot.dirname(c),{recursive:!0}).close();g.stop()}),s.native)await rt(h,{title:ot.basename(c,".md")});if(d){let w=ot.dirname(c);console.log(`${e.blue}Watching ${e.bright}${w}${e.reset} for changes...`);let S=Ht.watch(w,{recursive:!0},async(R,v)=>{if(v&&v.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${v}${e.yellow} changed, reprocessing...${e.reset}`),await m()});process.on("SIGINT",()=>{S.close(),g.stop(),process.exit(0)})}return!0}function qr(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Xr}=globalThis.Bun;import Be from"fs";import ve from"path";class an{clients=new Set;server=null;options;constructor(t={}){this.options={wsPort:t.wsPort??3001,showOverlay:t.showOverlay??!0,reconnectInterval:t.reconnectInterval??1000,maxReconnectAttempts:t.maxReconnectAttempts??10,verbose:t.verbose??!1}}start(t){let s=t??this.options.wsPort,i=20;for(let d=0;d<i;d++)try{if(this.server=Bun.serve({port:s,fetch(c,l){if(l.upgrade(c,{data:{}}))return;return new Response("stx Hot Reload Server",{headers:{"Content-Type":"text/plain"}})},websocket:{open:(c)=>{if(this.clients.add(c),this.options.verbose)console.log(`[HMR] Client connected (${this.clients.size} total)`);c.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close:(c)=>{if(this.clients.delete(c),this.options.verbose)console.log(`[HMR] Client disconnected (${this.clients.size} total)`)},message:(c,l)=>{let m=typeof l==="string"?l:l.toString();if(m==="ping")return;try{let p=JSON.parse(m);if(p.type==="console"&&Array.isArray(p.args)){let h=p.args.join(" "),y={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[p.level]??"\x1B[36m";console.log(`${y}[browser]${p.level!=="log"?` ${p.level}`:""}\x1B[0m ${h}`)}}catch{}}}}),this.options.verbose)console.log(`[HMR] WebSocket server started on port ${s}`);return s}catch(c){if(c?.code==="EADDRINUSE"){s++;continue}throw c}throw Error(`Could not find an available port after ${i} attempts starting from ${t??this.options.wsPort}`)}stop(){for(let t of this.clients)try{t.close()}catch{}if(this.clients.clear(),this.server)this.server.stop(),this.server=null;if(this.options.verbose)console.log("[HMR] Server stopped")}broadcast(t){let s=JSON.stringify(t),i=0;for(let d of this.clients)try{if(d.readyState===1)d.send(s),i++}catch{this.clients.delete(d)}if(this.options.verbose&&i>0)console.log(`[HMR] Broadcast ${t.type} to ${i} client(s)`)}reload(t){if(this.options.verbose)console.log(`[HMR] Sending reload to ${this.clients.size} client(s) for: ${t||"all"}`);this.broadcast({type:"reload",path:t,timestamp:Date.now()})}updateCss(t,s){this.broadcast({type:"css-update",path:t,content:s,timestamp:Date.now()})}error(t){this.broadcast({type:"error",content:t,timestamp:Date.now()})}get clientCount(){return this.clients.size}get port(){return this.options.wsPort}}function Kr(t,s={}){let{showOverlay:i=!0,reconnectInterval:d=1000,maxReconnectAttempts:c=10}=s;return`
681
681
  <script>
682
682
  (function() {
683
683
  // stx Hot Reload Client
@@ -876,10 +876,10 @@ else {
876
876
  };
877
877
  })();
878
878
  </script>
879
- `}function Ve(t,s,i={}){let d=Kr(s,i),c=t.lastIndexOf("</body>");if(c!==-1)return t.slice(0,c)+d+t.slice(c);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function $t(t){let s=t.toLowerCase();return s.endsWith(".css")||s.endsWith(".scss")||s.endsWith(".sass")||s.endsWith(".less")}function Ct(t){let s=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>s.endsWith(d))}function Rt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((i)=>i.test(t))}var st=null;function Et(t){if(!st)st=new an(t);return st}function lt(){if(st)st.stop(),st=null}import Pt from"path";var it={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},d=new Set,c=i.webComponents?.enabled?`./${Pt.relative(Pt.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let m=await br(i,d);if(l.push(...m),i.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 p=new Set;if(i.cache&&i.cachePath){let x=await xn(m,i);if(x){if(i.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let h=await ae(()=>Bun.file(m).text(),"",(x)=>{throw new jn(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!h)throw new jn(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:y,allScripts:w}=J.time("script-extraction",()=>{let x=h,C=oe(h);if(C)x=C.content.trim();let k=h.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],B="",_=[];for(let E of k){let L=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",F=E.match(/<script\b([^>]*)>/i),K=F?F[1]:"";if(/\bserver\b/i.test(K))B=L;else _.push(E)}let I=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:B,templateContent:I,allScripts:_}}),S={__filename:m,__dirname:Pt.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await ae(()=>u(g,S,m),void 0,(x)=>{let C=new W(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(O.log(C,{filePath:m,scriptContent:g}),i.debug)throw C});let v=await J.timeAsync("directive-processing",async()=>await n(y,S,m,i,p));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-xj5rk4pj.js"),C=x(w.join(`
879
+ `}function Ve(t,s,i={}){let d=Kr(s,i),c=t.lastIndexOf("</body>");if(c!==-1)return t.slice(0,c)+d+t.slice(c);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function $t(t){let s=t.toLowerCase();return s.endsWith(".css")||s.endsWith(".scss")||s.endsWith(".sass")||s.endsWith(".less")}function Ct(t){let s=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>s.endsWith(d))}function Rt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((i)=>i.test(t))}var st=null;function Et(t){if(!st)st=new an(t);return st}function lt(){if(st)st.stop(),st=null}import Pt from"path";var it={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},d=new Set,c=i.webComponents?.enabled?`./${Pt.relative(Pt.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let m=await br(i,d);if(l.push(...m),i.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 p=new Set;if(i.cache&&i.cachePath){let x=await xn(m,i);if(x){if(i.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let h=await ae(()=>Bun.file(m).text(),"",(x)=>{throw new jn(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!h)throw new jn(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:y,allScripts:w}=J.time("script-extraction",()=>{let x=h,C=oe(h);if(C)x=C.content.trim();let k=h.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],B="",_=[];for(let E of k){let L=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",F=E.match(/<script\b([^>]*)>/i),K=F?F[1]:"";if(/\bserver\b/i.test(K))B=L;else _.push(E)}let I=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:B,templateContent:I,allScripts:_}}),S={__filename:m,__dirname:Pt.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await ae(()=>u(g,S,m),void 0,(x)=>{let C=new q(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(O.log(C,{filePath:m,scriptContent:g}),i.debug)throw C});let v=await J.timeAsync("directive-processing",async()=>await n(y,S,m,i,p));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-adxq3fkh.js"),C=x(w.join(`
880
880
  `),S),k=v.search(/<\/body>/i);if(k!==-1)v=v.slice(0,k)+C+`
881
881
  `+v.slice(k);else v+=`
882
- ${C}`}if(v=await Q(v),p.forEach((x)=>d.add(x)),i.cache&&i.cachePath){if(await Sn(m,v,p,i),i.debug)console.log(`Cached template ${m} with ${p.size} dependencies`)}return{contents:v,loader:"html"}}catch(p){let h=p instanceof Error?p:new W(`Plugin processing failed: ${String(p)}`,m);if(O.log(h,{filePath:m,buildConfig:t.config}),Wt.logDetailedError(h,{filePath:m,plugin:"bun-plugin-stx"}),i.debug)console.error("stx Plugin Error:",h);let g=h,y=g.line||null,w=g.context||null;return{contents:i.debug||D()?`<!DOCTYPE html>
882
+ ${C}`}if(v=await Q(v),p.forEach((x)=>d.add(x)),i.cache&&i.cachePath){if(await Sn(m,v,p,i),i.debug)console.log(`Cached template ${m} with ${p.size} dependencies`)}return{contents:v,loader:"html"}}catch(p){let h=p instanceof Error?p:new q(`Plugin processing failed: ${String(p)}`,m);if(O.log(h,{filePath:m,buildConfig:t.config}),Wt.logDetailedError(h,{filePath:m,plugin:"bun-plugin-stx"}),i.debug)console.error("stx Plugin Error:",h);let g=h,y=g.line||null,w=g.context||null;return{contents:i.debug||D()?`<!DOCTYPE html>
883
883
  <html lang="en">
884
884
  <head>
885
885
  <meta charset="UTF-8">
@@ -939,12 +939,12 @@ ${C}`}if(v=await Q(v),p.forEach((x)=>d.add(x)),i.cache&&i.cachePath){if(await Sn
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 qn(t,s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=ve.resolve(t);if(!je.existsSync(p))return console.error(`${e.red}Error: File not found: ${e.bright}${p}${e.reset}`),!1;if(p.endsWith(".md"))return zt(p,s);else if(!p.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${p}${e.reset}. Only .stx and .md files are supported.`),!1;let h=a(process.cwd(),"output");je.mkdirSync(h,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,y=async()=>{try{let L={name:"public-assets",setup(Te){Te.onResolve({filter:/^\/(images|fonts|assets|public)\//},(me)=>({path:me.path,external:!0}))}},F=await Bun.build({entrypoints:[p],outdir:h,plugins:[L,it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!F.success)return console.error(`${e.red}Build failed:${e.reset}`,F.logs),!1;let K=F.outputs.find((Te)=>Te.path.endsWith(".html"));if(!K)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(K.path).text(),!0}catch(L){return console.error(`${e.red}Error building stx file:${e.reset}`,L),!1}};if(!await y())return!1;let S=ve.dirname(p);await Bt(S);let R=i;try{if(R=await Xe(i),R!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${R} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let L=s.hmrPort||R+1;l=Et({wsPort:L,verbose:!1}),m=l.start(L)}let v={},x=null,C;try{let{loadStxConfig:L}=await import("./chunk-6vjg5xf3.js"),F=await L();if(C=s.stxOptions?.serverApi??F.serverApi,F?.apiRouter)x=F?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(F?.apiRoutes){v=F.apiRoutes;let K=Object.keys(v).length;if(K>0)console.log(`${e.blue}Loaded ${e.bright}${K} API route${K>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:K,loadChannels:Z}=await import("./chunk-b2teprjf.js"),Te=F.broadcasting;await K(Te);let me=Te.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${me}/ws${e.reset}`);let Oe=ve.join(process.cwd(),"channels.ts");if(je.existsSync(Oe))try{let ne=await Z(Oe);console.log(`${e.blue}Loaded ${e.bright}${ne} broadcast channel${ne!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ne){console.warn(`${e.yellow}Failed to load channels.ts: ${ne.message}${e.reset}`)}}catch(K){console.warn(`${e.yellow}Broadcasting failed to start: ${K.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:B}=await import("./chunk-2yvdnffe.js"),_=await k(process.cwd(),C);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${R}/${e.reset}...`),c)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${m}${e.reset}`);let I=Xr({port:R,async fetch(L){return Kt(L,await(async()=>{let F=new URL(L.url);if([h,ve.dirname(p),ve.join(process.cwd(),"public")].some((ne)=>B(ve.join(ne,F.pathname),process.cwd(),C)))return new Response("Not Found",{status:404});if(x)try{let ne=await x.handleRequest(L);if(ne.status!==404)return ne}catch{}if(v[F.pathname])try{return await v[F.pathname](L)}catch(ne){return new Response(JSON.stringify({error:ne.message}),{status:500,headers:{"Content-Type":"application/json"}})}let K=await _(L);if(K)return K;if(F.pathname==="/")return(async()=>{let U=await f(g||"");if(c)U=Ve(U,m);if(s.native)if(U.includes("<head>"))U=U.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else if(U.includes("<html"))U=U.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 U="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+U;if(s.titlebarHidden)if(U.includes("<head>"))U=U.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else if(U.includes("<html"))U=U.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 U=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${U}`;return U})().then((U)=>new Response(U,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Z=ve.join(h,F.pathname);if(je.existsSync(Z)&&je.statSync(Z).isFile()){let ne=Bun.file(Z),U=ve.extname(Z).toLowerCase(),H="text/plain";if(U===".ts"||U===".tsx"){let He=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=He.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":H="text/html";break;case".css":H="text/css";break;case".js":H="text/javascript";break;case".json":H="application/json";break;case".png":H="image/png";break;case".jpg":case".jpeg":H="image/jpeg";break;case".gif":H="image/gif";break;case".woff":H="font/woff";break;case".woff2":H="font/woff2";break;case".ttf":H="font/ttf";break;case".otf":H="font/otf";break;case".eot":H="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":H}})}let Te=ve.dirname(p),me=ve.join(Te,F.pathname);if(je.existsSync(me)&&je.statSync(me).isFile()){let ne=Bun.file(me),U=ve.extname(me).toLowerCase(),H="text/plain";if(U===".ts"||U===".tsx"){let He=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=He.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":H="text/html";break;case".css":H="text/css";break;case".js":H="text/javascript";break;case".json":H="application/json";break;case".png":H="image/png";break;case".jpg":case".jpeg":H="image/jpeg";break;case".gif":H="image/gif";break;case".svg":H="image/svg+xml";break;case".ico":H="image/x-icon";break;case".woff":H="font/woff";break;case".woff2":H="font/woff2";break;case".ttf":H="font/ttf";break;case".otf":H="font/otf";break;case".eot":H="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":H}})}let Oe=ve.join(process.cwd(),"public",F.pathname);if(je.existsSync(Oe)&&je.statSync(Oe).isFile()){let ne=Bun.file(Oe),U=ve.extname(Oe).toLowerCase(),H="application/octet-stream";if(U===".ts"||U===".tsx"){let He=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=He.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":H="text/html";break;case".css":H="text/css";break;case".js":H="text/javascript";break;case".json":H="application/json";break;case".png":H="image/png";break;case".jpg":case".jpeg":H="image/jpeg";break;case".gif":H="image/gif";break;case".svg":H="image/svg+xml";break;case".ico":H="image/x-icon";break;case".woff":H="font/woff";break;case".woff2":H="font/woff2";break;case".ttf":H="font/ttf";break;case".otf":H="font/otf";break;case".eot":H="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":H}})}return new Response("Not Found",{status:404})})())},error(L){return new Response(`<pre>${L}
942
+ </html>`,loader:"html"}}})}};async function qn(t,s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=ve.resolve(t);if(!Be.existsSync(p))return console.error(`${e.red}Error: File not found: ${e.bright}${p}${e.reset}`),!1;if(p.endsWith(".md"))return zt(p,s);else if(!p.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${p}${e.reset}. Only .stx and .md files are supported.`),!1;let h=a(process.cwd(),"output");Be.mkdirSync(h,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,y=async()=>{try{let L={name:"public-assets",setup(Te){Te.onResolve({filter:/^\/(images|fonts|assets|public)\//},(me)=>({path:me.path,external:!0}))}},F=await Bun.build({entrypoints:[p],outdir:h,plugins:[L,it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!F.success)return console.error(`${e.red}Build failed:${e.reset}`,F.logs),!1;let K=F.outputs.find((Te)=>Te.path.endsWith(".html"));if(!K)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(K.path).text(),!0}catch(L){return console.error(`${e.red}Error building stx file:${e.reset}`,L),!1}};if(!await y())return!1;let S=ve.dirname(p);await Bt(S);let R=i;try{if(R=await Xe(i),R!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${R} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let L=s.hmrPort||R+1;l=Et({wsPort:L,verbose:!1}),m=l.start(L)}let v={},x=null,C;try{let{loadStxConfig:L}=await import("./chunk-2t5qqn27.js"),F=await L();if(C=s.stxOptions?.serverApi??F.serverApi,F?.apiRouter)x=F?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(F?.apiRoutes){v=F.apiRoutes;let K=Object.keys(v).length;if(K>0)console.log(`${e.blue}Loaded ${e.bright}${K} API route${K>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:K,loadChannels:Z}=await import("./chunk-b2teprjf.js"),Te=F.broadcasting;await K(Te);let me=Te.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${me}/ws${e.reset}`);let Pe=ve.join(process.cwd(),"channels.ts");if(Be.existsSync(Pe))try{let ne=await Z(Pe);console.log(`${e.blue}Loaded ${e.bright}${ne} broadcast channel${ne!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ne){console.warn(`${e.yellow}Failed to load channels.ts: ${ne.message}${e.reset}`)}}catch(K){console.warn(`${e.yellow}Broadcasting failed to start: ${K.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:B}=await import("./chunk-ypgsyh5k.js"),_=await k(process.cwd(),C);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${R}/${e.reset}...`),c)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${m}${e.reset}`);let I=Xr({port:R,async fetch(L){return Kt(L,await(async()=>{let F=new URL(L.url);if([h,ve.dirname(p),ve.join(process.cwd(),"public")].some((ne)=>B(ve.join(ne,F.pathname),process.cwd(),C)))return new Response("Not Found",{status:404});if(x)try{let ne=await x.handleRequest(L);if(ne.status!==404)return ne}catch{}if(v[F.pathname])try{return await v[F.pathname](L)}catch(ne){return new Response(JSON.stringify({error:ne.message}),{status:500,headers:{"Content-Type":"application/json"}})}let K=await _(L);if(K)return K;if(F.pathname==="/")return(async()=>{let U=await f(g||"");if(c)U=Ve(U,m);if(s.native)if(U.includes("<head>"))U=U.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else if(U.includes("<html"))U=U.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 U="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+U;if(s.titlebarHidden)if(U.includes("<head>"))U=U.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else if(U.includes("<html"))U=U.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 U=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${U}`;return U})().then((U)=>new Response(U,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Z=ve.join(h,F.pathname);if(Be.existsSync(Z)&&Be.statSync(Z).isFile()){let ne=Bun.file(Z),U=ve.extname(Z).toLowerCase(),H="text/plain";if(U===".ts"||U===".tsx"){let Fe=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=Fe.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":H="text/html";break;case".css":H="text/css";break;case".js":H="text/javascript";break;case".json":H="application/json";break;case".png":H="image/png";break;case".jpg":case".jpeg":H="image/jpeg";break;case".gif":H="image/gif";break;case".woff":H="font/woff";break;case".woff2":H="font/woff2";break;case".ttf":H="font/ttf";break;case".otf":H="font/otf";break;case".eot":H="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":H}})}let Te=ve.dirname(p),me=ve.join(Te,F.pathname);if(Be.existsSync(me)&&Be.statSync(me).isFile()){let ne=Bun.file(me),U=ve.extname(me).toLowerCase(),H="text/plain";if(U===".ts"||U===".tsx"){let Fe=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=Fe.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":H="text/html";break;case".css":H="text/css";break;case".js":H="text/javascript";break;case".json":H="application/json";break;case".png":H="image/png";break;case".jpg":case".jpeg":H="image/jpeg";break;case".gif":H="image/gif";break;case".svg":H="image/svg+xml";break;case".ico":H="image/x-icon";break;case".woff":H="font/woff";break;case".woff2":H="font/woff2";break;case".ttf":H="font/ttf";break;case".otf":H="font/otf";break;case".eot":H="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":H}})}let Pe=ve.join(process.cwd(),"public",F.pathname);if(Be.existsSync(Pe)&&Be.statSync(Pe).isFile()){let ne=Bun.file(Pe),U=ve.extname(Pe).toLowerCase(),H="application/octet-stream";if(U===".ts"||U===".tsx"){let Fe=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=Fe.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":H="text/html";break;case".css":H="text/css";break;case".js":H="text/javascript";break;case".json":H="application/json";break;case".png":H="image/png";break;case".jpg":case".jpeg":H="image/jpeg";break;case".gif":H="image/gif";break;case".svg":H="image/svg+xml";break;case".ico":H="image/x-icon";break;case".woff":H="font/woff";break;case".woff2":H="font/woff2";break;case".ttf":H="font/ttf";break;case".otf":H="font/otf";break;case".eot":H="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":H}})}return new Response("Not Found",{status:404})})())},error(L){return new Response(`<pre>${L}
943
943
  ${L.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:${R}/${e.reset}`),console.log(`
946
946
  ${e.yellow}Routes:${e.reset}`);let E=ve.relative(process.cwd(),p);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${E}${e.reset}`),console.log(`
947
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(I.url.toString(),()=>{if(d)je.watch(ve.dirname(p),{recursive:!0}).close();I.stop()}),s.native){let L=await Bun.file(p).text(),F=Tt(L);await rt(R,{title:ve.basename(p,".stx"),titlebarHidden:s.titlebarHidden===!0,nativeSidebar:!!F,sidebarConfig:F})}if(d){let L=ve.dirname(p);console.log(`${e.blue}Watching ${e.bright}${L}${e.reset} for changes...`);let F=je.watch(L,{recursive:!0},async(K,Z)=>{if(!Z||Rt(Z))return;if(Ct(Z)){console.log(`${e.yellow}File ${e.bright}${Z}${e.yellow} changed, rebuilding...${e.reset}`),Re.clear(),ie();let Te=await y();if(await _n(S),c&&l)if(Te)l.reload(Z);else l.error("Build failed - check console for details")}else if($t(Z)){if(console.log(`${e.cyan}CSS ${e.bright}${Z}${e.cyan} changed${e.reset}`),c&&l)l.updateCss(Z)}});process.on("SIGINT",()=>{if(F.close(),l)lt();I.stop(),process.exit(0)})}return!0}var{serve:Jr}=globalThis.Bun;import Je from"fs";import Pe from"path";var cn=`
947
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(I.url.toString(),()=>{if(d)Be.watch(ve.dirname(p),{recursive:!0}).close();I.stop()}),s.native){let L=await Bun.file(p).text(),F=Tt(L);await rt(R,{title:ve.basename(p,".stx"),titlebarHidden:s.titlebarHidden===!0,nativeSidebar:!!F,sidebarConfig:F})}if(d){let L=ve.dirname(p);console.log(`${e.blue}Watching ${e.bright}${L}${e.reset} for changes...`);let F=Be.watch(L,{recursive:!0},async(K,Z)=>{if(!Z||Rt(Z))return;if(Ct(Z)){console.log(`${e.yellow}File ${e.bright}${Z}${e.yellow} changed, rebuilding...${e.reset}`),Ae.clear(),ie();let Te=await y();if(await _n(S),c&&l)if(Te)l.reload(Z);else l.error("Build failed - check console for details")}else if($t(Z)){if(console.log(`${e.cyan}CSS ${e.bright}${Z}${e.cyan} changed${e.reset}`),c&&l)l.updateCss(Z)}});process.on("SIGINT",()=>{if(F.close(),l)lt();I.stop(),process.exit(0)})}return!0}var{serve:Jr}=globalThis.Bun;import Je from"fs";import Ee from"path";var cn=`
948
948
  <script data-stx-helpers>
949
949
  (function() {
950
950
  'use strict'
@@ -1255,14 +1255,14 @@ else {
1255
1255
 
1256
1256
  })()
1257
1257
  </script>
1258
- `;function dn(t){if(t.length===0)return"";if(t.length===1)return t[0];let s=t.map((d)=>d.split(Pe.sep)),i=[];for(let d=0;d<s[0].length;d++){let c=s[0][d];if(s.every((l)=>l[d]===c))i.push(c);else break}return i.join(Pe.sep)}async function Gn(t,s={}){let i=s.port||3000,d=s.watch!==!1;for(let v of t){let x=Pe.resolve(v);if(!Je.existsSync(x))return console.error(`${e.red}Error: File not found: ${e.bright}${x}${e.reset}`),!1;if(!x.endsWith(".stx")&&!x.endsWith(".md"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${x}${e.reset}. Only .stx and .md files are supported.`),!1}let c=a(process.cwd(),"output");Je.mkdirSync(c,{recursive:!0});let l=dn(t.map((v)=>Pe.dirname(Pe.resolve(v))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let m={},p=[],h=async()=>{try{for(let v of t){let x=Pe.resolve(v);if(x.endsWith(".md"))try{let{content:k,data:B}=await be(x,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),_=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,I=_?.defaultTheme||"github-dark",E=["github-dark"],L=_?.additionalThemes||[],K=[...new Set([...E,...L])].map((Oe)=>`<option value="${Oe}"${Oe===I?" selected":""}>${Oe}</option>`).join(`
1258
+ `;function dn(t){if(t.length===0)return"";if(t.length===1)return t[0];let s=t.map((d)=>d.split(Ee.sep)),i=[];for(let d=0;d<s[0].length;d++){let c=s[0][d];if(s.every((l)=>l[d]===c))i.push(c);else break}return i.join(Ee.sep)}async function Gn(t,s={}){let i=s.port||3000,d=s.watch!==!1;for(let v of t){let x=Ee.resolve(v);if(!Je.existsSync(x))return console.error(`${e.red}Error: File not found: ${e.bright}${x}${e.reset}`),!1;if(!x.endsWith(".stx")&&!x.endsWith(".md"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${x}${e.reset}. Only .stx and .md files are supported.`),!1}let c=a(process.cwd(),"output");Je.mkdirSync(c,{recursive:!0});let l=dn(t.map((v)=>Ee.dirname(Ee.resolve(v))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let m={},p=[],h=async()=>{try{for(let v of t){let x=Ee.resolve(v);if(x.endsWith(".md"))try{let{content:k,data:B}=await be(x,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),_=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,I=_?.defaultTheme||"github-dark",E=["github-dark"],L=_?.additionalThemes||[],K=[...new Set([...E,...L])].map((Pe)=>`<option value="${Pe}"${Pe===I?" selected":""}>${Pe}</option>`).join(`
1259
1259
  `),Z=`
1260
1260
  <!DOCTYPE html>
1261
1261
  <html lang="en">
1262
1262
  <head>
1263
1263
  <meta charset="UTF-8">
1264
1264
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
1265
- <title>${ln(B.title||Pe.basename(x))}</title>
1265
+ <title>${ln(B.title||Ee.basename(x))}</title>
1266
1266
  <!-- Syntax highlighting styles -->
1267
1267
  <style id="syntax-theme">
1268
1268
  :root {
@@ -1418,20 +1418,20 @@ else {
1418
1418
  </script>
1419
1419
  </body>
1420
1420
  </html>
1421
- `,me=`/${Pe.relative(l,x).replace(/\.md$/,"")}`;if(me.endsWith("/index"))me=me.slice(0,-6)||"/";m[me||"/"]={filePath:x,content:Z,fileType:"md"}}catch(k){console.error(`${e.red}Error processing Markdown file ${e.bright}${v}${e.reset}:`,k);continue}else{let k={name:"public-assets",setup(E){E.onResolve({filter:/^\/(images|fonts|assets|public)\//},(L)=>({path:L.path,external:!0}))}},B;try{let E=await Bun.build({entrypoints:[x],outdir:c,plugins:[k,it],define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!E.success){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:`,fe(E.logs,x));continue}let L=E.outputs.find((F)=>F.path.endsWith(".html"));if(!L){console.error(`${e.red}No HTML output found for ${e.bright}${v}${e.reset}`);continue}B=await Bun.file(L.path).text()}catch(E){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:
1422
- ${fe(E,x)}`);continue}let I=`/${Pe.relative(l,x).replace(/\.stx$/,"")}`;if(I.endsWith("/index"))I=I.slice(0,-6)||"/";if(I.includes("[")){let{regex:E,params:L}=Ir(I,{page:!0});p.push({pattern:E,paramNames:L,filePath:x,routeTemplate:I,fileType:"stx"}),m[I]={filePath:x,content:B,fileType:"stx"}}else m[I||"/"]={filePath:x,content:B,fileType:"stx"}}}if(Object.keys(m).length===0)return console.error(`${e.red}No files were successfully processed${e.reset}`),!1;return!0}catch(v){return console.error(`${e.red}Error processing files:${e.reset}`,fe(v)),!1}};if(!await h())return!1;let y=i;try{if(y=await Xe(i),y!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${y} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${y}/${e.reset}...`);let w=Jr({port:y,async fetch(v){let x=new URL(v.url),C=Pe.join(process.cwd(),"public",x.pathname);if(Je.existsSync(C)&&Je.statSync(C).isFile()){let _=Bun.file(C),I=Pe.extname(C).toLowerCase(),E="application/octet-stream";if(I===".ts"||I===".tsx"){let L=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),F=await _.text(),K=L.transformSync(F);return new Response(K,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(I){case".html":E="text/html";break;case".css":E="text/css";break;case".js":E="text/javascript";break;case".json":E="application/json";break;case".png":E="image/png";break;case".jpg":case".jpeg":E="image/jpeg";break;case".gif":E="image/gif";break;case".svg":E="image/svg+xml";break;case".ico":E="image/x-icon";break;case".woff":E="font/woff";break;case".woff2":E="font/woff2";break;case".ttf":E="font/ttf";break;case".otf":E="font/otf";break;case".eot":E="application/vnd.ms-fontobject";break}return new Response(_,{headers:{"Content-Type":E}})}let k=m[x.pathname];if(!k&&!x.pathname.endsWith("/"))k=m[`${x.pathname}/`];if(!k)for(let _ of p){let I=x.pathname.match(_.pattern);if(I){let E=m[_.routeTemplate];if(E){let L={};for(let Z=0;Z<_.paramNames.length;Z++)L[_.paramNames[Z]]=decodeURIComponent(I[Z+1]);let F=E.content,K=`<script>window.__routeParams = ${JSON.stringify(L)};</script>`;if(F.includes("</head>"))F=F.replace("</head>",`${K}
1421
+ `,me=`/${Ee.relative(l,x).replace(/\.md$/,"")}`;if(me.endsWith("/index"))me=me.slice(0,-6)||"/";m[me||"/"]={filePath:x,content:Z,fileType:"md"}}catch(k){console.error(`${e.red}Error processing Markdown file ${e.bright}${v}${e.reset}:`,k);continue}else{let k={name:"public-assets",setup(E){E.onResolve({filter:/^\/(images|fonts|assets|public)\//},(L)=>({path:L.path,external:!0}))}},B;try{let E=await Bun.build({entrypoints:[x],outdir:c,plugins:[k,it],define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!E.success){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:`,fe(E.logs,x));continue}let L=E.outputs.find((F)=>F.path.endsWith(".html"));if(!L){console.error(`${e.red}No HTML output found for ${e.bright}${v}${e.reset}`);continue}B=await Bun.file(L.path).text()}catch(E){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:
1422
+ ${fe(E,x)}`);continue}let I=`/${Ee.relative(l,x).replace(/\.stx$/,"")}`;if(I.endsWith("/index"))I=I.slice(0,-6)||"/";if(I.includes("[")){let{regex:E,params:L}=Ir(I,{page:!0});p.push({pattern:E,paramNames:L,filePath:x,routeTemplate:I,fileType:"stx"}),m[I]={filePath:x,content:B,fileType:"stx"}}else m[I||"/"]={filePath:x,content:B,fileType:"stx"}}}if(Object.keys(m).length===0)return console.error(`${e.red}No files were successfully processed${e.reset}`),!1;return!0}catch(v){return console.error(`${e.red}Error processing files:${e.reset}`,fe(v)),!1}};if(!await h())return!1;let y=i;try{if(y=await Xe(i),y!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${y} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${y}/${e.reset}...`);let w=Jr({port:y,async fetch(v){let x=new URL(v.url),C=Ee.join(process.cwd(),"public",x.pathname);if(Je.existsSync(C)&&Je.statSync(C).isFile()){let _=Bun.file(C),I=Ee.extname(C).toLowerCase(),E="application/octet-stream";if(I===".ts"||I===".tsx"){let L=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),F=await _.text(),K=L.transformSync(F);return new Response(K,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(I){case".html":E="text/html";break;case".css":E="text/css";break;case".js":E="text/javascript";break;case".json":E="application/json";break;case".png":E="image/png";break;case".jpg":case".jpeg":E="image/jpeg";break;case".gif":E="image/gif";break;case".svg":E="image/svg+xml";break;case".ico":E="image/x-icon";break;case".woff":E="font/woff";break;case".woff2":E="font/woff2";break;case".ttf":E="font/ttf";break;case".otf":E="font/otf";break;case".eot":E="application/vnd.ms-fontobject";break}return new Response(_,{headers:{"Content-Type":E}})}let k=m[x.pathname];if(!k&&!x.pathname.endsWith("/"))k=m[`${x.pathname}/`];if(!k)for(let _ of p){let I=x.pathname.match(_.pattern);if(I){let E=m[_.routeTemplate];if(E){let L={};for(let Z=0;Z<_.paramNames.length;Z++)L[_.paramNames[Z]]=decodeURIComponent(I[Z+1]);let F=E.content,K=`<script>window.__routeParams = ${JSON.stringify(L)};</script>`;if(F.includes("</head>"))F=F.replace("</head>",`${K}
1423
1423
  </head>`);else F=K+F;k={...E,content:F}}break}}if(k)return f(k.content).then((_)=>{if(_.includes("</head>"))_=_.replace("</head>",`${cn}
1424
- </head>`);return new Response(_,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let B=Pe.join(c,x.pathname);if(Je.existsSync(B)&&Je.statSync(B).isFile()){let _=Bun.file(B),I=Pe.extname(B).toLowerCase(),E="text/plain";if(I===".ts"||I===".tsx"){let L=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),F=await _.text(),K=L.transformSync(F);return new Response(K,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(I){case".html":E="text/html";break;case".css":E="text/css";break;case".js":E="text/javascript";break;case".json":E="application/json";break;case".png":E="image/png";break;case".jpg":case".jpeg":E="image/jpeg";break;case".gif":E="image/gif";break;case".svg":E="image/svg+xml";break;case".ico":E="image/x-icon";break;case".woff":E="font/woff";break;case".woff2":E="font/woff2";break;case".ttf":E="font/ttf";break;case".otf":E="font/otf";break;case".eot":E="application/vnd.ms-fontobject";break}return new Response(_,{headers:{"Content-Type":E}})}if(x.pathname!=="/"&&m["/"]){let _=ce(v);return f(m["/"].content).then((I)=>{if(_){let E=I.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(E){let L=I.match(/<title[^>]*>([\s\S]*?)<\/title>/i),F=L?L[1]:"",K=`<!DOCTYPE html><html><head><title>${ln(F)}</title></head><body><main>${E[1]}</main></body></html>`;return new Response(K,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...T(),"Cache-Control":ze,Pragma:"no-cache",Expires:"0"}})}}return new Response(I,{headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})})}return new Response("Not Found",{status:404})},error(v){return new Response(`<pre>${v}
1424
+ </head>`);return new Response(_,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let B=Ee.join(c,x.pathname);if(Je.existsSync(B)&&Je.statSync(B).isFile()){let _=Bun.file(B),I=Ee.extname(B).toLowerCase(),E="text/plain";if(I===".ts"||I===".tsx"){let L=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),F=await _.text(),K=L.transformSync(F);return new Response(K,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(I){case".html":E="text/html";break;case".css":E="text/css";break;case".js":E="text/javascript";break;case".json":E="application/json";break;case".png":E="image/png";break;case".jpg":case".jpeg":E="image/jpeg";break;case".gif":E="image/gif";break;case".svg":E="image/svg+xml";break;case".ico":E="image/x-icon";break;case".woff":E="font/woff";break;case".woff2":E="font/woff2";break;case".ttf":E="font/ttf";break;case".otf":E="font/otf";break;case".eot":E="application/vnd.ms-fontobject";break}return new Response(_,{headers:{"Content-Type":E}})}if(x.pathname!=="/"&&m["/"]){let _=ce(v);return f(m["/"].content).then((I)=>{if(_){let E=I.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(E){let L=I.match(/<title[^>]*>([\s\S]*?)<\/title>/i),F=L?L[1]:"",K=`<!DOCTYPE html><html><head><title>${ln(F)}</title></head><body><main>${E[1]}</main></body></html>`;return new Response(K,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...T(),"Cache-Control":He,Pragma:"no-cache",Expires:"0"}})}}return new Response(I,{headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})})}return new Response("Not Found",{status:404})},error(v){return new Response(`<pre>${v}
1425
1425
  ${v.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
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:${y}/${e.reset}`),console.log(`
1428
- ${e.yellow}Routes:${e.reset}`);let S=new Set(p.map((v)=>v.routeTemplate)),R=Object.entries(m).filter(([v])=>!S.has(v)).sort(([v],[x])=>v.localeCompare(x)).map(([v,x])=>({route:v==="/"?"/":v,filePath:Pe.relative(process.cwd(),x.filePath),fileType:x.fileType}));for(let v of p){let x=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");R.push({route:x,filePath:Pe.relative(process.cwd(),v.filePath),fileType:"stx"})}if(R.sort((v,x)=>v.route.localeCompare(x.route)),R.forEach((v,x)=>{let k=x===R.length-1?"\u2514\u2500 ":"\u251C\u2500 ",B=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${k}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${B}`)}),console.log(`
1429
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(w.url.toString(),()=>{if(d)Je.watch(l,{recursive:!0}).close();w.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Je.watch(l,{recursive:!0},async(x,C)=>{if(!C)return;if(C.endsWith(".stx")||C.endsWith(".js")||C.endsWith(".ts")||C.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${C}${e.yellow} changed, rebuilding...${e.reset}`),Re.clear(),ie(),await h()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function ln(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Yr}=globalThis.Bun;import he from"fs";import te from"path";async function pn(t){try{return Ft(await Bun.file(t).text())}catch{return}}function Nt(t){let s=Bun.file(t),i=te.extname(t).toLowerCase(),d={".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(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":d[i]||"application/octet-stream",...l}})}async function Kn(t=".",s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=te.resolve(t),{loadStxConfig:h}=await import("./chunk-6vjg5xf3.js"),g=await h(p),{createServerApi:y,isServerApiSource:w}=await import("./chunk-2yvdnffe.js"),S=s.stxOptions?.serverApi??g.serverApi,R=await y(p,S),v=g.root&&g.root!=="."?te.join(p,g.root):p,x=s.pagesDir||g.pagesDir||"pages",C=te.join(v,x);if(!he.existsSync(C)&&!g._layerPageDirs?.some((A)=>he.existsSync(A)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${C}${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=j(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[C,...g._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${C}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let B=g?._pluginPageDirs||[],_=[];for(let{dir:A,prefix:z}of B)if(he.existsSync(A)){let N=j(te.dirname(A),{pagesDir:te.basename(A)});for(let V of N){let xe=z==="/"?V.pattern:`${z}${V.pattern==="/"?"":V.pattern}`;_.push({route:{...V,pattern:xe},prefix:z})}if(N.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${N.length}${e.blue} routes at ${e.cyan}${z}${e.reset}`)}let I=new Map,E=null,L=null;if(s.stxOptions?.shell!==!1){if(L=await Oo(p,s.stxOptions?.shell),L){if(E=await Gr(L,s.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(p,L)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}ft(),await mt(p);let F=gt();if(F.length>0)console.log(`${e.blue}Loaded ${e.bright}${F.length}${e.blue} middleware: ${e.dim}${F.join(", ")}${e.reset}`);let K={},Z=null;try{let{loadStxConfig:A}=await import("./chunk-6vjg5xf3.js"),z=await A(p);if(z?.apiRouter)Z=z?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(z?.apiRoutes){K=z.apiRoutes;let N=Object.keys(K).length;if(N>0)console.log(`${e.blue}Loaded ${e.bright}${N} API route${N>1?"s":""}${e.reset}`)}if(z?.broadcasting?.enabled)try{let{startBroadcasting:N,loadChannels:V}=await import("./chunk-b2teprjf.js"),xe=z.broadcasting;await N(xe);let Be=xe.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Be}/ws${e.reset}`);let qe=te.join(process.cwd(),"channels.ts");if(he.existsSync(qe))try{let ee=await V(qe);console.log(`${e.blue}Loaded ${e.bright}${ee} broadcast channel${ee!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ee){console.warn(`${e.yellow}Failed to load channels.ts: ${ee.message}${e.reset}`)}}catch(N){console.warn(`${e.yellow}Broadcasting failed to start: ${N.message}${e.reset}`)}}catch{}let Te=a(p,"output");he.mkdirSync(Te,{recursive:!0});let me=new Map,Oe=new Set,ne=async(A)=>{let z=Or(C,A);if(!z)return null;try{let N=await Bun.build({entrypoints:[z],outdir:Te,plugins:[it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!N.success)return null;let V=N.outputs.find((xe)=>xe.path.endsWith(".html"));if(!V)return null;return await Bun.file(V.path).text()}catch{return null}},U=new Map,H=async(A,z)=>{try{let{processDirectives:N,extractVariables:V,defaultConfig:xe,loadStxConfig:Be,injectRouterScript:qe}=await import("./chunk-6vjg5xf3.js"),{checkCache:ee,cacheTemplate:Y,readFileCached:q,templateCache:X}=await import("./chunk-4a4zc8yd.js"),we=await Be(p),Ke=(re)=>{if(!re)return re;if(te.isAbsolute(re))return re;return te.resolve(p,re)},M={...xe,...we,...s.stxOptions,autoShell:!0};if(s.debugDirectives)M.debug=!0;M.partialsDir=Ke(M.partialsDir),M.componentsDir=Ke(M.componentsDir),M.layoutsDir=Ke(M.layoutsDir),M.storesDir=Ke(M.storesDir||"stores"),M.cachePath=Ke(M.cachePath)??a(p,"cache");let ge=!z&&!s.profile,se=M.cache!==!1;if(se&&ge){let re=X.get(A.filePath);if(re)try{if((await he.promises.stat(A.filePath)).mtime.getTime()<=re.mtime){let Ie=!0;for(let Ce of re.dependencies){if(!he.existsSync(Ce)){Ie=!1;break}if((await he.promises.stat(Ce)).mtime.getTime()>re.mtime){Ie=!1;break}}if(Ie){let Ce=re.output;if(E)Ce=ke(Ce,{preserveHead:!0});let ct=U.get(A.filePath);return{route:A,content:Ce,status:ct?.status??await pn(A.filePath),headers:ct?.headers}}}}catch{}let _e=await ee(A.filePath,M);if(_e){let Le=_e;if(E)Le=ke(Le,{preserveHead:!0});let Ie=U.get(A.filePath);return{route:A,content:Le,status:Ie?.status??await pn(A.filePath),headers:Ie?.headers}}}let ue=se?await q(A.filePath):await Bun.file(A.filePath).text(),$e=Ft(ue),{classifyAllScripts:G}=await import("./chunk-6vjg5xf3.js"),Me=G(ue),Fe=Me.server.map((re)=>re.content),de=ue;for(let re of Me.server)de=de.replace(re.fullTag,"");let pe={__filename:A.filePath,__dirname:te.dirname(A.filePath),__stx_options:M,params:z??{},__stx_runtime_head:{}};for(let re of Fe)try{await V(re,pe,A.filePath)}catch(_e){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",A.filePath,_e?.message||_e)}let We=new Set,Ae;if(s.profile){let re=performance.now();Ae=await N(de,pe,A.filePath,M,We);let _e=performance.now()-re,Le=te.relative(p,A.filePath)||A.filePath;console.log(`[stx:profile] ${Le} \u2192 ${_e.toFixed(2)}ms`)}else Ae=await N(de,pe,A.filePath,M,We);if(!E)Ae=await qe(Ae,{router:M.router});{let{interpolateScriptExpressions:re}=await import("./chunk-xj5rk4pj.js");Ae=Ae.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(_e,Le,Ie)=>{if(!/function\s+__stx_setup_/.test(Ie))return _e;return`<script${Le}>${re(Ie,pe)}</script>`})}if(E)Ae=ke(Ae,{preserveHead:!0});if(se&&ge)await Y(A.filePath,Ae,We,M);let{extractStreamBoundaries:Nn}=await import("./chunk-z5ewms99.js"),nt=Nn(pe),at=pe.__streamTemplates;if(at&&typeof at==="object"&&Object.keys(at).length>0){let re=pe.streamBoundaries||{},_e={...M,autoShell:!1},Le=Object.keys(at).map((Ce)=>({id:Ce,render:async()=>{let ct=typeof re[Ce]==="function"?await re[Ce]():void 0;return N(at[Ce],{...pe,$boundary:ct},A.filePath,_e,new Set)}})),Ie=new Set(Le.map((Ce)=>Ce.id));nt=[...(nt||[]).filter((Ce)=>!Ie.has(Ce.id)),...Le]}if(nt&&nt.length>0)Oe.add(A.pattern);else nt=void 0;let qt=Ze(pe),Xt=Qe(pe);if(ge)U.set(A.filePath,{status:qt,headers:Xt});return{route:A,content:Ae,status:qt??$e,headers:Xt,boundaries:nt}}catch(N){return console.error(`${e.red}Error building ${e.bright}${A.pattern}${e.reset}:`,N),null}},He=8,Ue=async()=>{me.clear(),I.clear();for(let A=0;A<k.length;A+=He){let z=k.slice(A,A+He),N=await Promise.all(z.map((V)=>H(V)));for(let V of N)if(V)me.set(V.route.pattern,V)}for(let A=0;A<_.length;A+=He){let z=_.slice(A,A+He),N=await Promise.all(z.map(({route:V})=>H(V)));for(let V of N)if(V)I.set(V.route.pattern,V)}return me.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await Ue())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Bt(p);let et=i;try{if(et=await Xe(i),et!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${et} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let A=s.hmrPort||et+1;l=Et({wsPort:A,verbose:!1}),m=l.start(A)}let At=(A,z)=>{let V=`<script data-stx-route-params>(function(){var p=${JSON.stringify(z).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 Dt=Yr({port:et,async fetch(A){let z=new URL(A.url),N=g?.publicDir||"public",V=te.join(p,N,z.pathname),xe=te.join(p,z.pathname),Be=te.join(Te,z.pathname);if([V,xe,Be].some((M)=>w(M,p,S)))return new Response("Not Found",{status:404});let[qe,ee,Y]=await Promise.all([he.promises.stat(V).catch(()=>null),he.promises.stat(xe).catch(()=>null),he.promises.stat(Be).catch(()=>null)]);if(qe?.isFile()&&!w(V,p,S))return Nt(V);if(ee?.isFile()&&!w(xe,p,S))return Nt(xe);if(Y?.isFile()&&!w(Be,p,S))return Nt(Be);if(z.pathname.startsWith("/_stx/component/")){let M=decodeURIComponent(z.pathname.slice(16));if(M)try{let ge=`<${M} />`,se={...buildConfig,autoShell:!1},ue=await processDirectives(ge,{},te.join(p,"components",`${M}.stx`),se,new Set);return new Response(ue,{headers:{"Content-Type":"text/html"}})}catch(ge){return new Response(`<div class="stx-async-error">${ge.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(z.pathname==="/_stx/img"){let{handleImageRequest:M}=await import("./chunk-y1j13dha.js"),ge=await M(A,{publicDir:te.join(p,N),cacheDir:a(p,"cache","img")});if(ge)return ge}if(Z)try{let M=await Z.handleRequest(A);if(M.status!==404)return M}catch{}if(K[z.pathname])try{return await K[z.pathname](A)}catch(M){return new Response(JSON.stringify({error:M.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await R(A);if(q)return q;let X=Vn(z.pathname,k);if(X){let M=me.get(X.route.pattern),ge=Oe.has(X.route.pattern);if(X.route.isDynamic&&Object.keys(X.params).length>0||ge){let se=await H(X.route,X.params);if(se)M=se}if(M){let se=M.status??200,ue=M.headers??{},$e=(X.route.filePath?Ye(await Bun.file(X.route.filePath).text().catch(()=>"")):null)??{};if($e.validate){if(!await $e.validate({params:X.params})){let Fe=await ne(404);if(Fe){let de=Fe;if(de=await f(de,p),c)de=Ve(de,m);return new Response(de,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if($e.middleware){let Me=ht(z.pathname,X.params,$e,z.search),Fe=yt(Me,null,A,{isServer:!0}),de=await bt($e.middleware,Fe);if(de.redirect){let pe=de.redirect.path,We=de.redirect.options.redirectCode||302,Ae=new Headers(de.responseHeaders);return Ae.set("Location",pe),new Response(null,{status:We,headers:Ae})}if(de.abort){let{statusCode:pe,message:We}=de.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${pe}</title></head><body><h1>Error ${pe}</h1><p>${We}</p></body></html>`,{status:pe,headers:{"Content-Type":"text/html"}})}if(Object.keys(de.state).length>0){let pe=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(de.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;M.content=M.content.replace("</head>",`${pe}</head>`)}}let G=M.content;if(E&&No(A)){let Me=Ne(G),Fe=ye(G),de=G.match(/<title[^>]*>([\s\S]*?)<\/title>/i),pe=de?Io(de[1].trim()):"";if(Object.keys(X.params).length>0)G=At(G,X.params);G=await f(G,p);let We=g?.router?.container||"main";return G=le(G,We),new Response(G,{status:se,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Me.layout,"X-STX-Layout-Group":Me.group,"X-STX-Runtime":Fe?"true":"false",...pe&&{"X-STX-Title":encodeURIComponent(pe)},[Li]:Fs(),...T(),"Cache-Control":ze}})}if(E)G=Zn(E,G);if(Object.keys(X.params).length>0)G=At(G,X.params);if(G=await f(G,p),c)G=Ve(G,m);if(s.native)if(G.includes("<head>"))G=G.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 G="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+G;if(s.titlebarHidden)if(G.includes("<head>"))G=G.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 G=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${G}`;if(M.boundaries&&M.boundaries.length>0){let{renderStreamingPage:Me,streamToResponse:Fe}=await import("./chunk-z5ewms99.js");return Fe(Me(G,M.boundaries,{timeoutMs:30000}),{status:se,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(G,{status:se,headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ue}})}}if(_.length>0){let M=_.map((se)=>se.route),ge=Vn(z.pathname,M);if(ge){let se=I.get(ge.route.pattern);if(se){let ue=se.content;if(E)ue=Zn(E,ue);if(Object.keys(ge.params).length>0)ue=At(ue,ge.params);if(ue=await f(ue,p),c)ue=Ve(ue,m);return new Response(ue,{status:se.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:se}of B)if(se!=="/"&&z.pathname.startsWith(se)){let ue=I.get(se)||I.get(se+"/");if(ue){let $e=ue.content;if(E)$e=Zn(E,$e);if($e=await f($e,p),c)$e=Ve($e,m);return new Response($e,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(pt(z.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let we=me.get("/");if(we){let M=we.content;if(M=await f(M,p),c)M=Ve(M,m);if(s.native)if(M.includes("<head>"))M=M.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 M="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+M;return new Response(M,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Ke=await ne(404);if(Ke){let M=Ke;if(M=await f(M,p),c)M=Ve(M,m);return new Response(M,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(A){let z=await ne(500);if(z)return new Response(z,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${A}
1428
+ ${e.yellow}Routes:${e.reset}`);let S=new Set(p.map((v)=>v.routeTemplate)),R=Object.entries(m).filter(([v])=>!S.has(v)).sort(([v],[x])=>v.localeCompare(x)).map(([v,x])=>({route:v==="/"?"/":v,filePath:Ee.relative(process.cwd(),x.filePath),fileType:x.fileType}));for(let v of p){let x=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");R.push({route:x,filePath:Ee.relative(process.cwd(),v.filePath),fileType:"stx"})}if(R.sort((v,x)=>v.route.localeCompare(x.route)),R.forEach((v,x)=>{let k=x===R.length-1?"\u2514\u2500 ":"\u251C\u2500 ",B=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${k}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${B}`)}),console.log(`
1429
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(w.url.toString(),()=>{if(d)Je.watch(l,{recursive:!0}).close();w.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Je.watch(l,{recursive:!0},async(x,C)=>{if(!C)return;if(C.endsWith(".stx")||C.endsWith(".js")||C.endsWith(".ts")||C.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${C}${e.yellow} changed, rebuilding...${e.reset}`),Ae.clear(),ie(),await h()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function ln(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Yr}=globalThis.Bun;import he from"fs";import te from"path";async function pn(t){try{return Ft(await Bun.file(t).text())}catch{return}}function Nt(t){let s=Bun.file(t),i=te.extname(t).toLowerCase(),d={".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(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":d[i]||"application/octet-stream",...l}})}async function Kn(t=".",s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=te.resolve(t),{loadStxConfig:h}=await import("./chunk-2t5qqn27.js"),g=await h(p),{createServerApi:y,isServerApiSource:w}=await import("./chunk-ypgsyh5k.js"),S=s.stxOptions?.serverApi??g.serverApi,R=await y(p,S),v=g.root&&g.root!=="."?te.join(p,g.root):p,x=s.pagesDir||g.pagesDir||"pages",C=te.join(v,x);if(!he.existsSync(C)&&!g._layerPageDirs?.some((A)=>he.existsSync(A)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${C}${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=j(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[C,...g._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${C}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let B=g?._pluginPageDirs||[],_=[];for(let{dir:A,prefix:z}of B)if(he.existsSync(A)){let N=j(te.dirname(A),{pagesDir:te.basename(A)});for(let W of N){let xe=z==="/"?W.pattern:`${z}${W.pattern==="/"?"":W.pattern}`;_.push({route:{...W,pattern:xe},prefix:z})}if(N.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${N.length}${e.blue} routes at ${e.cyan}${z}${e.reset}`)}let I=new Map,E=null,L=null;if(s.stxOptions?.shell!==!1){if(L=await Oo(p,s.stxOptions?.shell),L){if(E=await Gr(L,s.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(p,L)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}ft(),await mt(p);let F=gt();if(F.length>0)console.log(`${e.blue}Loaded ${e.bright}${F.length}${e.blue} middleware: ${e.dim}${F.join(", ")}${e.reset}`);let K={},Z=null;try{let{loadStxConfig:A}=await import("./chunk-2t5qqn27.js"),z=await A(p);if(z?.apiRouter)Z=z?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(z?.apiRoutes){K=z.apiRoutes;let N=Object.keys(K).length;if(N>0)console.log(`${e.blue}Loaded ${e.bright}${N} API route${N>1?"s":""}${e.reset}`)}if(z?.broadcasting?.enabled)try{let{startBroadcasting:N,loadChannels:W}=await import("./chunk-b2teprjf.js"),xe=z.broadcasting;await N(xe);let ze=xe.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${ze}/ws${e.reset}`);let qe=te.join(process.cwd(),"channels.ts");if(he.existsSync(qe))try{let ee=await W(qe);console.log(`${e.blue}Loaded ${e.bright}${ee} broadcast channel${ee!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ee){console.warn(`${e.yellow}Failed to load channels.ts: ${ee.message}${e.reset}`)}}catch(N){console.warn(`${e.yellow}Broadcasting failed to start: ${N.message}${e.reset}`)}}catch{}let Te=a(p,"output");he.mkdirSync(Te,{recursive:!0});let me=new Map,Pe=new Set,ne=async(A)=>{let z=Or(C,A);if(!z)return null;try{let N=await Bun.build({entrypoints:[z],outdir:Te,plugins:[it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!N.success)return null;let W=N.outputs.find((xe)=>xe.path.endsWith(".html"));if(!W)return null;return await Bun.file(W.path).text()}catch{return null}},U=new Map,H=async(A,z)=>{try{let{processDirectives:N,extractVariables:W,defaultConfig:xe,loadStxConfig:ze,injectRouterScript:qe}=await import("./chunk-2t5qqn27.js"),{checkCache:ee,cacheTemplate:Y,readFileCached:V,templateCache:X}=await import("./chunk-6vtq0atz.js"),we=await ze(p),Ke=(re)=>{if(!re)return re;if(te.isAbsolute(re))return re;return te.resolve(p,re)},M={...xe,...we,...s.stxOptions,autoShell:!0};if(s.debugDirectives)M.debug=!0;M.partialsDir=Ke(M.partialsDir),M.componentsDir=Ke(M.componentsDir),M.layoutsDir=Ke(M.layoutsDir),M.storesDir=Ke(M.storesDir||"stores"),M.cachePath=Ke(M.cachePath)??a(p,"cache");let ge=!z&&!s.profile,se=M.cache!==!1;if(se&&ge){let re=X.get(A.filePath);if(re)try{if((await he.promises.stat(A.filePath)).mtime.getTime()<=re.mtime){let je=!0;for(let Ce of re.dependencies){if(!he.existsSync(Ce)){je=!1;break}if((await he.promises.stat(Ce)).mtime.getTime()>re.mtime){je=!1;break}}if(je){let Ce=re.output;if(E)Ce=ke(Ce,{preserveHead:!0});let ct=U.get(A.filePath);return{route:A,content:Ce,status:ct?.status??await pn(A.filePath),headers:ct?.headers}}}}catch{}let Le=await ee(A.filePath,M);if(Le){let Ie=Le;if(E)Ie=ke(Ie,{preserveHead:!0});let je=U.get(A.filePath);return{route:A,content:Ie,status:je?.status??await pn(A.filePath),headers:je?.headers}}}let ue=se?await V(A.filePath):await Bun.file(A.filePath).text(),$e=Ft(ue),{classifyAllScripts:G}=await import("./chunk-2t5qqn27.js"),_e=G(ue),Ne=_e.server.map((re)=>re.content),de=ue;for(let re of _e.server)de=de.replace(re.fullTag,"");let pe={__filename:A.filePath,__dirname:te.dirname(A.filePath),__stx_options:M,params:z??{},__stx_runtime_head:{}};for(let re of Ne)try{await W(re,pe,A.filePath)}catch(Le){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",A.filePath,Le?.message||Le)}let We=new Set,Oe;if(s.profile){let re=performance.now();Oe=await N(de,pe,A.filePath,M,We);let Le=performance.now()-re,Ie=te.relative(p,A.filePath)||A.filePath;console.log(`[stx:profile] ${Ie} \u2192 ${Le.toFixed(2)}ms`)}else Oe=await N(de,pe,A.filePath,M,We);if(!E)Oe=await qe(Oe,{router:M.router});{let{interpolateScriptExpressions:re}=await import("./chunk-adxq3fkh.js");Oe=Oe.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Le,Ie,je)=>{if(!/function\s+__stx_setup_/.test(je))return Le;return`<script${Ie}>${re(je,pe)}</script>`})}if(E)Oe=ke(Oe,{preserveHead:!0});if(se&&ge)await Y(A.filePath,Oe,We,M);let{extractStreamBoundaries:Nn}=await import("./chunk-n7jc6gn3.js"),nt=Nn(pe),at=pe.__streamTemplates;if(at&&typeof at==="object"&&Object.keys(at).length>0){let re=pe.streamBoundaries||{},Le={...M,autoShell:!1},Ie=Object.keys(at).map((Ce)=>({id:Ce,render:async()=>{let ct=typeof re[Ce]==="function"?await re[Ce]():void 0;return N(at[Ce],{...pe,$boundary:ct},A.filePath,Le,new Set)}})),je=new Set(Ie.map((Ce)=>Ce.id));nt=[...(nt||[]).filter((Ce)=>!je.has(Ce.id)),...Ie]}if(nt&&nt.length>0)Pe.add(A.pattern);else nt=void 0;let qt=Ze(pe),Xt=Qe(pe);if(ge)U.set(A.filePath,{status:qt,headers:Xt});return{route:A,content:Oe,status:qt??$e,headers:Xt,boundaries:nt}}catch(N){return console.error(`${e.red}Error building ${e.bright}${A.pattern}${e.reset}:`,N),null}},Fe=8,Ue=async()=>{me.clear(),I.clear();for(let A=0;A<k.length;A+=Fe){let z=k.slice(A,A+Fe),N=await Promise.all(z.map((W)=>H(W)));for(let W of N)if(W)me.set(W.route.pattern,W)}for(let A=0;A<_.length;A+=Fe){let z=_.slice(A,A+Fe),N=await Promise.all(z.map(({route:W})=>H(W)));for(let W of N)if(W)I.set(W.route.pattern,W)}return me.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await Ue())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Bt(p);let et=i;try{if(et=await Xe(i),et!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${et} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let A=s.hmrPort||et+1;l=Et({wsPort:A,verbose:!1}),m=l.start(A)}let At=(A,z)=>{let W=`<script data-stx-route-params>(function(){var p=${JSON.stringify(z).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>",`${W}</head>`);if(A.includes("<body"))return A.replace(/<body([^>]*)>/,`<body$1>${W}`);return W+A};console.log(`${e.blue}Starting server...${e.reset}`);let Dt=Yr({port:et,async fetch(A){let z=new URL(A.url),N=g?.publicDir||"public",W=te.join(p,N,z.pathname),xe=te.join(p,z.pathname),ze=te.join(Te,z.pathname);if([W,xe,ze].some((M)=>w(M,p,S)))return new Response("Not Found",{status:404});let[qe,ee,Y]=await Promise.all([he.promises.stat(W).catch(()=>null),he.promises.stat(xe).catch(()=>null),he.promises.stat(ze).catch(()=>null)]);if(qe?.isFile()&&!w(W,p,S))return Nt(W);if(ee?.isFile()&&!w(xe,p,S))return Nt(xe);if(Y?.isFile()&&!w(ze,p,S))return Nt(ze);if(z.pathname.startsWith("/_stx/component/")){let M=decodeURIComponent(z.pathname.slice(16));if(M)try{let ge=`<${M} />`,se={...buildConfig,autoShell:!1},ue=await processDirectives(ge,{},te.join(p,"components",`${M}.stx`),se,new Set);return new Response(ue,{headers:{"Content-Type":"text/html"}})}catch(ge){return new Response(`<div class="stx-async-error">${ge.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(z.pathname==="/_stx/img"){let{handleImageRequest:M}=await import("./chunk-ns4pc13z.js"),ge=await M(A,{publicDir:te.join(p,N),cacheDir:a(p,"cache","img")});if(ge)return ge}if(Z)try{let M=await Z.handleRequest(A);if(M.status!==404)return M}catch{}if(K[z.pathname])try{return await K[z.pathname](A)}catch(M){return new Response(JSON.stringify({error:M.message}),{status:500,headers:{"Content-Type":"application/json"}})}let V=await R(A);if(V)return V;let X=Vn(z.pathname,k);if(X){let M=me.get(X.route.pattern),ge=Pe.has(X.route.pattern);if(X.route.isDynamic&&Object.keys(X.params).length>0||ge){let se=await H(X.route,X.params);if(se)M=se}if(M){let se=M.status??200,ue=M.headers??{},$e=(X.route.filePath?Ye(await Bun.file(X.route.filePath).text().catch(()=>"")):null)??{};if($e.validate){if(!await $e.validate({params:X.params})){let Ne=await ne(404);if(Ne){let de=Ne;if(de=await f(de,p),c)de=Ve(de,m);return new Response(de,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if($e.middleware){let _e=ht(z.pathname,X.params,$e,z.search),Ne=yt(_e,null,A,{isServer:!0}),de=await bt($e.middleware,Ne);if(de.redirect){let pe=de.redirect.path,We=de.redirect.options.redirectCode||302,Oe=new Headers(de.responseHeaders);return Oe.set("Location",pe),new Response(null,{status:We,headers:Oe})}if(de.abort){let{statusCode:pe,message:We}=de.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${pe}</title></head><body><h1>Error ${pe}</h1><p>${We}</p></body></html>`,{status:pe,headers:{"Content-Type":"text/html"}})}if(Object.keys(de.state).length>0){let pe=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(de.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;M.content=M.content.replace("</head>",`${pe}</head>`)}}let G=M.content;if(E&&No(A)){let _e=De(G),Ne=ye(G),de=G.match(/<title[^>]*>([\s\S]*?)<\/title>/i),pe=de?Io(de[1].trim()):"";if(Object.keys(X.params).length>0)G=At(G,X.params);G=await f(G,p);let We=g?.router?.container||"main";return G=le(G,We),new Response(G,{status:se,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":_e.layout,"X-STX-Layout-Group":_e.group,"X-STX-Runtime":Ne?"true":"false",...pe&&{"X-STX-Title":encodeURIComponent(pe)},[Li]:Fs(),...T(),"Cache-Control":He}})}if(E)G=Zn(E,G);if(Object.keys(X.params).length>0)G=At(G,X.params);if(G=await f(G,p),c)G=Ve(G,m);if(s.native)if(G.includes("<head>"))G=G.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 G="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+G;if(s.titlebarHidden)if(G.includes("<head>"))G=G.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 G=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${G}`;if(M.boundaries&&M.boundaries.length>0){let{renderStreamingPage:_e,streamToResponse:Ne}=await import("./chunk-n7jc6gn3.js");return Ne(_e(G,M.boundaries,{timeoutMs:30000}),{status:se,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(G,{status:se,headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ue}})}}if(_.length>0){let M=_.map((se)=>se.route),ge=Vn(z.pathname,M);if(ge){let se=I.get(ge.route.pattern);if(se){let ue=se.content;if(E)ue=Zn(E,ue);if(Object.keys(ge.params).length>0)ue=At(ue,ge.params);if(ue=await f(ue,p),c)ue=Ve(ue,m);return new Response(ue,{status:se.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:se}of B)if(se!=="/"&&z.pathname.startsWith(se)){let ue=I.get(se)||I.get(se+"/");if(ue){let $e=ue.content;if(E)$e=Zn(E,$e);if($e=await f($e,p),c)$e=Ve($e,m);return new Response($e,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(pt(z.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let we=me.get("/");if(we){let M=we.content;if(M=await f(M,p),c)M=Ve(M,m);if(s.native)if(M.includes("<head>"))M=M.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 M="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+M;return new Response(M,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Ke=await ne(404);if(Ke){let M=Ke;if(M=await f(M,p),c)M=Ve(M,m);return new Response(M,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(A){let z=await ne(500);if(z)return new Response(z,{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:${et}/${e.reset}`),c)console.log(`${e.dim} HMR: ws://localhost:${m}${e.reset}`);console.log(`
1433
- ${e.yellow}Routes:${e.reset}`);let Mt=[...Nr(k,p)];for(let{route:A}of _)Mt.push(`${A.pattern}`);if(Mt.forEach((A,z)=>{let V=z===Mt.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`),Ge(Dt.url.toString(),()=>{if(l)lt();Dt.stop()}),s.native){let A,z=te.join(C,"index.stx");if(he.existsSync(z)){let V=await Bun.file(z).text();A=Tt(V)}let N=g?.app?.window??{};await rt(et,{title:g?.app?.head?.title||te.basename(p)||"stx App",width:N.width,height:N.height,darkMode:N.darkMode,hotReload:N.hotReload,titlebarHidden:N.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!A,sidebarConfig:A})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let A=(ee)=>ee.startsWith("public/")||ee.startsWith("public\\"),z=(ee)=>{let Y=ee.toLowerCase();return Y.endsWith(".stx")||Y.endsWith(".html")||Y.endsWith(".md")},N=new Map,V=()=>{let ee=new Set([p,...g._layerGraph?.layers.map((Y)=>Y.root)??[],...g._layerGraph?.configDependencies.map((Y)=>te.dirname(Y))??[]].filter((Y)=>he.existsSync(Y)).map((Y)=>he.realpathSync(Y)));for(let Y of g._layerGraph?.layers??[])for(let q of Object.values(Y.resources)){if(!he.existsSync(q))continue;let X=he.realpathSync(q);if(![...ee].some((we)=>X===we||X.startsWith(`${we}${te.sep}`)))ee.add(X)}for(let[Y,q]of N)if(!ee.has(Y))q.close(),N.delete(Y);for(let Y of ee)if(!N.has(Y)&&he.existsSync(Y))N.set(Y,he.watch(Y,{recursive:!0},(q,X)=>{Be(Y,q,X).catch((we)=>console.error("[stx] Layer rebuild failed:",we))}))},xe=Promise.resolve(),Be=(ee,Y,q)=>(xe=xe.catch(()=>{}).then(()=>qe(ee,Y,q)),xe),qe=async(ee,Y,q)=>{if(!q||Rt(q))return;if(Ct(q)){if(g._layerGraph){let X=await h(p);Object.assign(g,X),k.splice(0,k.length,...j(v,{pagesDir:x,pagesDirs:X._layerPageDirs?[C,...X._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(z(q)){console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),Re.clear(),ie();try{let{invalidateFileCache:X,templateCache:we}=await import("./chunk-4a4zc8yd.js");X(te.resolve(ee,q)),we.delete(te.resolve(ee,q))}catch{}if(L&&q){if(te.resolve(ee,q)===L||te.basename(L)===q){let we=await Gr(L,s.stxOptions||{});if(we)E=we}}if(await Ue(),await _n(p),c&&l)l.reload(q)}else{console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),Re.clear(),ie();try{let{invalidateFileCache:X,templateCache:we}=await import("./chunk-4a4zc8yd.js");X(te.resolve(ee,q)),we.delete(te.resolve(ee,q))}catch{}if(await Ue(),c&&l)l.reload(q)}}else if($t(q)){if(console.log(`${e.cyan}CSS ${q} changed${e.reset}`),c&&l)l.updateCss(q)}};V(),process.on("SIGINT",()=>{for(let ee of N.values())ee.close();if(l)lt();Dt.stop(),process.exit(0)})}return!0}import Ut from"fs";import dt from"path";async function Qr(t){try{let i=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!i)return[];let d=i[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(d))!==null){let p=m[1],h=m[2]||m[3]||m[4];if(!h)continue;let g={name:h},y=p.match(/@type\s+\{([^}]+)\}/i);if(y)g.type=y[1].trim();if(p.match(/@required/i))g.required=!0;let S=p.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)g.default=S[1].trim();let R=p.split(`
1433
+ ${e.yellow}Routes:${e.reset}`);let Mt=[...Nr(k,p)];for(let{route:A}of _)Mt.push(`${A.pattern}`);if(Mt.forEach((A,z)=>{let W=z===Mt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${W}${e.reset}${A}`)}),console.log(`
1434
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(Dt.url.toString(),()=>{if(l)lt();Dt.stop()}),s.native){let A,z=te.join(C,"index.stx");if(he.existsSync(z)){let W=await Bun.file(z).text();A=Tt(W)}let N=g?.app?.window??{};await rt(et,{title:g?.app?.head?.title||te.basename(p)||"stx App",width:N.width,height:N.height,darkMode:N.darkMode,hotReload:N.hotReload,titlebarHidden:N.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!A,sidebarConfig:A})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let A=(ee)=>ee.startsWith("public/")||ee.startsWith("public\\"),z=(ee)=>{let Y=ee.toLowerCase();return Y.endsWith(".stx")||Y.endsWith(".html")||Y.endsWith(".md")},N=new Map,W=()=>{let ee=new Set([p,...g._layerGraph?.layers.map((Y)=>Y.root)??[],...g._layerGraph?.configDependencies.map((Y)=>te.dirname(Y))??[]].filter((Y)=>he.existsSync(Y)).map((Y)=>he.realpathSync(Y)));for(let Y of g._layerGraph?.layers??[])for(let V of Object.values(Y.resources)){if(!he.existsSync(V))continue;let X=he.realpathSync(V);if(![...ee].some((we)=>X===we||X.startsWith(`${we}${te.sep}`)))ee.add(X)}for(let[Y,V]of N)if(!ee.has(Y))V.close(),N.delete(Y);for(let Y of ee)if(!N.has(Y)&&he.existsSync(Y))N.set(Y,he.watch(Y,{recursive:!0},(V,X)=>{ze(Y,V,X).catch((we)=>console.error("[stx] Layer rebuild failed:",we))}))},xe=Promise.resolve(),ze=(ee,Y,V)=>(xe=xe.catch(()=>{}).then(()=>qe(ee,Y,V)),xe),qe=async(ee,Y,V)=>{if(!V||Rt(V))return;if(Ct(V)){if(g._layerGraph){let X=await h(p);Object.assign(g,X),k.splice(0,k.length,...j(v,{pagesDir:x,pagesDirs:X._layerPageDirs?[C,...X._layerPageDirs.slice(1)]:void 0})),W()}if(A(V)){if(console.log(`${e.cyan}${V} changed${e.reset}`),c&&l)l.reload(V)}else if(z(V)){console.log(`${e.yellow}${V} changed, rebuilding...${e.reset}`),Ae.clear(),ie();try{let{invalidateFileCache:X,templateCache:we}=await import("./chunk-6vtq0atz.js");X(te.resolve(ee,V)),we.delete(te.resolve(ee,V))}catch{}if(L&&V){if(te.resolve(ee,V)===L||te.basename(L)===V){let we=await Gr(L,s.stxOptions||{});if(we)E=we}}if(await Ue(),await _n(p),c&&l)l.reload(V)}else{console.log(`${e.yellow}${V} changed, rebuilding...${e.reset}`),Ae.clear(),ie();try{let{invalidateFileCache:X,templateCache:we}=await import("./chunk-6vtq0atz.js");X(te.resolve(ee,V)),we.delete(te.resolve(ee,V))}catch{}if(await Ue(),c&&l)l.reload(V)}}else if($t(V)){if(console.log(`${e.cyan}CSS ${V} changed${e.reset}`),c&&l)l.updateCss(V)}};W(),process.on("SIGINT",()=>{for(let ee of N.values())ee.close();if(l)lt();Dt.stop(),process.exit(0)})}return!0}import Ut from"fs";import dt from"path";async function Qr(t){try{let i=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!i)return[];let d=i[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(d))!==null){let p=m[1],h=m[2]||m[3]||m[4];if(!h)continue;let g={name:h},y=p.match(/@type\s+\{([^}]+)\}/i);if(y)g.type=y[1].trim();if(p.match(/@required/i))g.required=!0;let S=p.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)g.default=S[1].trim();let R=p.split(`
1435
1435
  `).map((v)=>v.trim().replace(/^\*\s*/,"")).filter((v)=>!v.startsWith("@")&&v.length>0);g.description=R.join(" ").trim(),c.push(g)}if(c.length===0){let p=d.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(p){let g=p[1].split(",").map((y)=>y.trim()).filter(Boolean);for(let y of g){let[w]=y.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 Zr(t){try{let s=await Bun.file(t).text(),i=s.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||s.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(i)return i[1].split(`
1436
1436
  `).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function eo(t,s=!1,i){let d=dt.basename(t,".stx"),c=await Qr(t),l=await Zr(t),m="";if(s&&i)m=`<${i}></${i}>`;else{let p=c.map((h)=>{if(h.type==="boolean")return`:${h.name}="true"`;return`${h.name}="value"`}).join(`
1437
1437
  `);m=`<${d}
@@ -2029,5 +2029,5 @@ const features = [
2029
2029
  })();
2030
2030
  </script>
2031
2031
  </body>
2032
- </html>`}var Co="f9c3713";function ha(t){return t}function ya(t){return t}function bo(t,s){let i=[],d=`${s}=`;for(let c=0;c<t.length;c++){let l=t[c];if(l.startsWith(d)){let m=l.slice(d.length);if(m)i.push(m);continue}if(l===s){let m=t[c+1];if(m!==void 0&&!m.startsWith("-"))i.push(m),c++}}return i}import De from"fs";import Se from"path";function Rn(t){try{return De.statSync(t).mtimeMs}catch{return null}}function Ot(t,s){let i=Math.max(0,Math.round((s-t)/1000));if(i<60)return`${i}s ago`;if(i<3600)return`${Math.round(i/60)}m ago`;return`${Math.round(i/3600)}h ago`}function Ai(t,s){try{return globalThis.Bun?.resolveSync(t,s)??null}catch{return null}}function En(t,s="stx"){let i=Se.resolve(t);for(let d=0;d<10;d++){let c=Se.join(i,"pantry","@stacksjs",s);if(De.existsSync(c))return c;let l=Se.dirname(i);if(l===i)break;i=l}return null}var Pn=["@stacksjs/stx","bun-plugin-stx"];function Di(t){try{let s=De.readFileSync(Se.join(t,"package.json"),"utf8"),i=JSON.parse(s)?.version;return typeof i==="string"?i:null}catch{return null}}function Mi(t,s=6){let i=Se.resolve(t),d=[],c=new Set;function l(p,h){if(h>s)return;let g;try{g=De.realpathSync(p)}catch{return}if(c.has(g))return;c.add(g);for(let w of Pn){let S=Se.join(p,w),R=Di(S);if(R!==null)d.push({name:w,version:R,dir:Se.relative(i,S)||S,nested:h>0})}let y;try{y=De.readdirSync(p,{withFileTypes:!0})}catch{return}for(let w of y){if(!w.isDirectory()&&!w.isSymbolicLink())continue;if(w.name===".bin"||w.name===".cache")continue;let S=Se.join(p,w.name);if(w.name.startsWith("@")){let v;try{v=De.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let x of v){let C=Se.join(S,x.name,"node_modules");if(De.existsSync(C))l(C,h+1)}continue}let R=Se.join(S,"node_modules");if(De.existsSync(R))l(R,h+1)}}let m=Se.join(i,"node_modules");if(De.existsSync(m))l(m,0);return d}function _i(t){let s=[];for(let i of Pn){let d=t.filter((m)=>m.name===i);if(d.length<=1)continue;let c=[...new Set(d.map((m)=>m.version))],l=d.map((m)=>`${m.version} at ${m.dir}`).join("; ");if(c.length===1){s.push({name:`${i} copies`,status:"info",detail:`${d.length} copies, all ${c[0]} \u2014 duplicated but in agreement`});continue}s.push({name:`${i} copies disagree`,status:"error",detail:`${c.length} versions installed, so which one runs depends on who imports it: ${l}`,fix:`remove the nested copies, or add an overrides entry pinning ${i}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${i}/package.json' -exec grep -H '"version"' {} +`})}return s}async function Fr(t={}){let s=t.cwd?Se.resolve(t.cwd):process.cwd(),i=t.resolve??Ai,d=Date.now(),c=[],l=i("@stacksjs/stx",s);c.push(l?{name:"@stacksjs/stx resolves to",status:"ok",detail:l}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let m=i("bun-plugin-stx",s);if(m)c.push({name:"bun-plugin-stx resolves to",status:"ok",detail:m});for(let h of _i(Mi(s)))c.push(h);let p=En(s,"stx");if(!p)c.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let h=Se.join(p,"src/signals.ts"),g=[Se.join(p,"dist/index.js"),Se.join(p,"dist/signals.js")].find((v)=>De.existsSync(v))||null,y=Rn(h),w=g?Rn(g):null;if(y==null)c.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${p} but no src/signals.ts to compare`});else if(w==null)c.push({name:"pantry dist freshness",status:"error",detail:"pantry has src but no built dist \u2014 the dev server will resolve nothing (or a stale copy elsewhere)",fix:`cd ${p} && bun build.ts`});else if(w<y){let v=Math.round((y-w)/1000);c.push({name:"pantry dist freshness",status:"error",detail:`dist (${Ot(w,d)}) is OLDER than src/signals.ts (${Ot(y,d)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${p} && bun build.ts`})}else c.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Ot(y,d)}, dist ${Ot(w,d)})`});let S=Se.join(s,"node_modules/@stacksjs/stx"),R=null;try{R=De.lstatSync(S)}catch{R=null}if(!R)c.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(R.isSymbolicLink()){let v=null;try{v=De.realpathSync(S)}catch{}let x=(()=>{try{return De.realpathSync(p)}catch{return p}})();c.push(v===x?{name:"node_modules \u2192 pantry",status:"ok",detail:"symlinked to pantry"}:{name:"node_modules \u2192 pantry",status:"warn",detail:`symlinked to ${v||"(dangling)"}, not pantry`})}else c.push({name:"node_modules \u2192 pantry",status:"warn",detail:"is a real directory, NOT symlinked to pantry \u2014 edits to pantry src/dist won't be resolved",fix:"rm -rf node_modules/@stacksjs/stx && ln -s ../../pantry/@stacksjs/stx node_modules/@stacksjs/stx"})}if(c.push({name:"dev runtime cache",status:"info",detail:"cleared automatically on source edits by the dev watcher (clearDevCaches, #1745 item C)"}),t.generateRuntime)try{let g=t.generateRuntime().length;c.push(g>1000?{name:"signals runtime",status:"ok",detail:`generated ${g.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${g} chars \u2014 suspiciously short`})}catch(h){c.push({name:"signals runtime",status:"error",detail:`failed to generate: ${h.message}`})}return{checks:c,ok:!c.some((h)=>h.status==="error")}}function zr(t){let s={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},i=["stx runtime resolution:"];for(let d of t.checks)if(i.push(` ${s[d.status]} ${d.name}: ${d.detail}`),d.fix)i.push(` \u2192 ${d.fix}`);return i.push(""),i.push(t.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),i.join(`
2032
+ </html>`}var Co="f9c3713";function ha(t){return t}function ya(t){return t}function bo(t,s){let i=[],d=`${s}=`;for(let c=0;c<t.length;c++){let l=t[c];if(l.startsWith(d)){let m=l.slice(d.length);if(m)i.push(m);continue}if(l===s){let m=t[c+1];if(m!==void 0&&!m.startsWith("-"))i.push(m),c++}}return i}import Me from"fs";import Se from"path";function Rn(t){try{return Me.statSync(t).mtimeMs}catch{return null}}function Ot(t,s){let i=Math.max(0,Math.round((s-t)/1000));if(i<60)return`${i}s ago`;if(i<3600)return`${Math.round(i/60)}m ago`;return`${Math.round(i/3600)}h ago`}function Ai(t,s){try{return globalThis.Bun?.resolveSync(t,s)??null}catch{return null}}function En(t,s="stx"){let i=Se.resolve(t);for(let d=0;d<10;d++){let c=Se.join(i,"pantry","@stacksjs",s);if(Me.existsSync(c))return c;let l=Se.dirname(i);if(l===i)break;i=l}return null}var Pn=["@stacksjs/stx","bun-plugin-stx"];function Di(t){try{let s=Me.readFileSync(Se.join(t,"package.json"),"utf8"),i=JSON.parse(s)?.version;return typeof i==="string"?i:null}catch{return null}}function Mi(t,s=6){let i=Se.resolve(t),d=[],c=new Set;function l(p,h){if(h>s)return;let g;try{g=Me.realpathSync(p)}catch{return}if(c.has(g))return;c.add(g);for(let w of Pn){let S=Se.join(p,w),R=Di(S);if(R!==null)d.push({name:w,version:R,dir:Se.relative(i,S)||S,nested:h>0})}let y;try{y=Me.readdirSync(p,{withFileTypes:!0})}catch{return}for(let w of y){if(!w.isDirectory()&&!w.isSymbolicLink())continue;if(w.name===".bin"||w.name===".cache")continue;let S=Se.join(p,w.name);if(w.name.startsWith("@")){let v;try{v=Me.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let x of v){let C=Se.join(S,x.name,"node_modules");if(Me.existsSync(C))l(C,h+1)}continue}let R=Se.join(S,"node_modules");if(Me.existsSync(R))l(R,h+1)}}let m=Se.join(i,"node_modules");if(Me.existsSync(m))l(m,0);return d}function _i(t){let s=[];for(let i of Pn){let d=t.filter((m)=>m.name===i);if(d.length<=1)continue;let c=[...new Set(d.map((m)=>m.version))],l=d.map((m)=>`${m.version} at ${m.dir}`).join("; ");if(c.length===1){s.push({name:`${i} copies`,status:"info",detail:`${d.length} copies, all ${c[0]} \u2014 duplicated but in agreement`});continue}s.push({name:`${i} copies disagree`,status:"error",detail:`${c.length} versions installed, so which one runs depends on who imports it: ${l}`,fix:`remove the nested copies, or add an overrides entry pinning ${i}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${i}/package.json' -exec grep -H '"version"' {} +`})}return s}async function Fr(t={}){let s=t.cwd?Se.resolve(t.cwd):process.cwd(),i=t.resolve??Ai,d=Date.now(),c=[],l=i("@stacksjs/stx",s);c.push(l?{name:"@stacksjs/stx resolves to",status:"ok",detail:l}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let m=i("bun-plugin-stx",s);if(m)c.push({name:"bun-plugin-stx resolves to",status:"ok",detail:m});for(let h of _i(Mi(s)))c.push(h);let p=En(s,"stx");if(!p)c.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let h=Se.join(p,"src/signals.ts"),g=[Se.join(p,"dist/index.js"),Se.join(p,"dist/signals.js")].find((v)=>Me.existsSync(v))||null,y=Rn(h),w=g?Rn(g):null;if(y==null)c.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${p} but no src/signals.ts to compare`});else if(w==null)c.push({name:"pantry dist freshness",status:"error",detail:"pantry has src but no built dist \u2014 the dev server will resolve nothing (or a stale copy elsewhere)",fix:`cd ${p} && bun build.ts`});else if(w<y){let v=Math.round((y-w)/1000);c.push({name:"pantry dist freshness",status:"error",detail:`dist (${Ot(w,d)}) is OLDER than src/signals.ts (${Ot(y,d)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${p} && bun build.ts`})}else c.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Ot(y,d)}, dist ${Ot(w,d)})`});let S=Se.join(s,"node_modules/@stacksjs/stx"),R=null;try{R=Me.lstatSync(S)}catch{R=null}if(!R)c.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(R.isSymbolicLink()){let v=null;try{v=Me.realpathSync(S)}catch{}let x=(()=>{try{return Me.realpathSync(p)}catch{return p}})();c.push(v===x?{name:"node_modules \u2192 pantry",status:"ok",detail:"symlinked to pantry"}:{name:"node_modules \u2192 pantry",status:"warn",detail:`symlinked to ${v||"(dangling)"}, not pantry`})}else c.push({name:"node_modules \u2192 pantry",status:"warn",detail:"is a real directory, NOT symlinked to pantry \u2014 edits to pantry src/dist won't be resolved",fix:"rm -rf node_modules/@stacksjs/stx && ln -s ../../pantry/@stacksjs/stx node_modules/@stacksjs/stx"})}if(c.push({name:"dev runtime cache",status:"info",detail:"cleared automatically on source edits by the dev watcher (clearDevCaches, #1745 item C)"}),t.generateRuntime)try{let g=t.generateRuntime().length;c.push(g>1000?{name:"signals runtime",status:"ok",detail:`generated ${g.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${g} chars \u2014 suspiciously short`})}catch(h){c.push({name:"signals runtime",status:"error",detail:`failed to generate: ${h.message}`})}return{checks:c,ok:!c.some((h)=>h.status==="error")}}function zr(t){let s={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},i=["stx runtime resolution:"];for(let d of t.checks)if(i.push(` ${s[d.status]} ${d.name}: ${d.detail}`),d.fix)i.push(` \u2192 ${d.fix}`);return i.push(""),i.push(t.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),i.join(`
2033
2033
  `)}export{bo,vo,wo,xo,Br,So,ko,Co,ha,ya,Fr,zr,qn,Gn,Kn};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{bn,fe}from"./chunk-bsts9pr5.js";import{M,m,vn,ar,w,Ke,o,P}from"./chunk-0bptz1km.js";import{bs}from"./chunk-26g3m2mg.js";import{s,Ae}from"./chunk-7p8kyf4z.js";import{a}from"./chunk-8cqx63aw.js";import d from"path";import b from"fs";import{AsyncLocalStorage as gt}from"async_hooks";var ht=11;function X(t,e,n){return/^(?:(?:stx|ui)\.config\.[cm]?[jt]s|runtime-config-(?:server|loader)\.[cm]?[jt]s)$/.test(d.basename(t))||bs(t,e,n)}var ot=2;function bc(t){let e=process.env.STX_BUNDLE_CACHE_DIR?.trim();return e?d.resolve(e):a(t,"bundle-cache")}function nt(t,e){let n=t;for(let i of xt(e))if(i!==d.sep)n=n.split(i).join("\x00root");return n}var st=new Map;function xt(t){let e=d.resolve(t),n=st.get(e);if(!n){let i=e;try{i=b.realpathSync(e)}catch{}n=[...new Set([e,i])].sort((u,g)=>g.length-u.length),st.set(e,n)}return n}function yt(t,e){try{let n=b.statSync(t),i=d.resolve(e),u=t.startsWith(`${i}${d.sep}`);return{path:u?d.relative(i,t):t,...u?{inRoot:!0}:{},mtimeMs:n.mtimeMs,size:n.size,hash:Bun.hash(b.readFileSync(t)).toString(36)}}catch{return null}}function at(t,e){return t.inRoot?d.join(d.resolve(e),t.path):t.path}function bt(t,e){for(let n of t){let i=at(n,e);try{let u=b.statSync(i);if(u.size!==n.size)return!1;if(u.mtimeMs!==n.mtimeMs&&Bun.hash(b.readFileSync(i)).toString(36)!==n.hash)return!1}catch{return!1}}return!0}var ct=new Map,wt=100;function vc(t=process.env){let e=Number(t.STX_BUNDLE_CACHE_LIMIT);return Number.isFinite(e)&&e>=1?Math.floor(e):2000}var G=new Map;async function St(t){let e=G.get(t)??0;if(e>0&&e<wt){G.set(t,e+1);return}G.set(t,1);try{let n=(await b.promises.readdir(t)).filter((l)=>l.endsWith(".js")),i=vc();if(n.length<=i)return;let g=(await Promise.all(n.map(async(l)=>{try{return{name:l,at:(await b.promises.stat(d.join(t,l))).mtimeMs}}catch{return null}}))).filter((l)=>l!==null);g.sort((l,S)=>S.at-l.at);for(let l of g.slice(i)){let S=l.name.slice(0,-3);await b.promises.rm(d.join(t,`${S}.js`),{force:!0}),await b.promises.rm(d.join(t,`${S}.deps.json`),{force:!0})}C("pruned bundle cache to",i,"entries")}catch{}}function pe(t){return ct.get(t)??[]}function q(t,e){if(t)ct.set(t,e)}function wc(t=process.env){return t.STX_DEBUG==="true"||t.STX_DEBUG==="1"}function C(...t){if(wc())console.log("[stx:bundler]",...t)}var Y=[];function di(t,e,n){Y.push({filePath:t||"<inline>",message:e,details:n})}function $t(){return Y.slice()}function Rt(){Y.length=0}var Z;function Qu(t){Z=t}function pi(){if(Z)return Z;try{let t=P.strict;return typeof t==="object"&&t!==null?t.bundlerFallback??"warn":"warn"}catch{return"warn"}}var Q=[/^stx$/,/^@stacksjs\/stx$/,/^@stores$/,/^stx\/stores$/,/^@composables$/];function At(t){let e=/^[ \t]*import[ \t]+(?!type(?:[ \t]|{))[\s\S]*?\s+from\s+['"]([^'"]+)['"][ \t]*;?/gm,n;while((n=e.exec(t))!==null){let u=n[1];if(!Q.some((l)=>l.test(u)))return C("detected user import:",u),!0}let i=/^[ \t]*import[ \t]*['"]([^'"]+)['"]/gm;while((n=i.exec(t))!==null){let u=n[1];if(/\.css(?:\?.*)?$/.test(u))continue;if(!Q.some((l)=>l.test(u)))return C("detected side-effect import:",u),!0}return!1}var yn="stx-module:",vt=/\.(?:[cm]?[jt]sx?|json)$/i;function xc(t,e){return d.relative(t,e).split(d.sep).join("/")}function Sc(t,e){if(e.size===0)return t;return t.replace(/^([ \t]*import(?:(?:\s+|(?=[{*]))[^;"']*?\s*from\s*|\s*))(["'])([^"']+)\2/gm,(n,i,u,g)=>{let l=e.get(g);return l&&!g.startsWith(yn)?`${i}${u}${l}${u}`:n})}function kc(t,e){let n=0,i=(g)=>{let l=`__stxMod${n++}`,S=JSON.stringify(g);return e.push(`var ${l} = globalThis.__stxModules && globalThis.__stxModules[${S}];`,`if (${l} === undefined) throw new Error("[stx] module " + ${JSON.stringify(S)} + " is not registered on this page (#1957)");`),l},u=(g,l)=>{for(let S of g.split(",")){let F=S.trim();if(!F)continue;let j=F.match(/^("(?:[^"\\]|\\.)*"|[\w$]+)(?:\s+as\s+([\w$]+))?$/);if(!j)continue;let p=j[1].startsWith('"')?JSON.parse(j[1]):j[1],r=j[2]??p;e.push(`var ${r} = ${l}[${JSON.stringify(p)}];`)}};return t=t.replace(/^[ \t]*import(?:\s+|(?=[{*]))([^;"']+?)\s*from\s*["'](stx-module:[^"']+)["'];?[ \t]*$/gm,(g,l,S)=>{let F=S.slice(yn.length),j=i(F),p=l.trim(),r=p.match(/^([\w$]+)\s*(?:,\s*|$)/);if(r&&!p.startsWith("{")&&!p.startsWith("*"))e.push(`var ${r[1]} = ${j}.default;`),p=p.slice(r[0].length).trim();let c=p.match(/^\*\s*as\s+([\w$]+)$/);if(c)e.push(`var ${c[1]} = ${j};`);else if(p.startsWith("{"))u(p.replace(/^\{|\}$/g,""),j);return""}),t=t.replace(/^[ \t]*import\s*["'](stx-module:[^"']+)["'];?[ \t]*$/gm,(g,l)=>(i(l.slice(yn.length)),"")),t}function rt(t){let e=[t,`${t}.ts`,`${t}.tsx`,`${t}.js`,`${t}.mjs`,`${t}.jsx`,d.join(t,"index.ts"),d.join(t,"index.tsx"),d.join(t,"index.js"),d.join(t,"index.mjs")];for(let n of e)try{if(b.existsSync(n)&&b.statSync(n,{throwIfNoEntry:!1})?.isFile())return n}catch{}return}var K=new gt;function gs(t,e){let n=new Bun.CryptoHasher("md5");for(let[i,u]of[...t].sort(([g],[l])=>g<l?-1:g>l?1:0))n.update(`${i}\x00${u}\x00`);return K.run({modules:t,key:n.digest("hex").slice(0,12)},e)}function Pt(){return K.getStore()?.key??""}function Bt(t,e,n,i,u,g=new Map,l,S){let F=(p,r,c)=>{if(X(r,t,l))return null;if(!u||p!==n||!vt.test(r))return null;try{if(!b.statSync(r,{throwIfNoEntry:!1})?.isFile())return null}catch{return null}i.add(r);let x=`${yn}${xc(process.cwd(),r)}`;return g.set(c,x),{path:x,external:!0}},j=(p,r)=>{let c=p===n?e:d.dirname(p),x=d.resolve(c,r);return rt(x)??x};return{name:"stx-client-bundle",setup(p){if(p.onResolve({filter:/^(stx|@stacksjs\/stx)$/},(r)=>({path:r.path,external:!0})),p.onResolve({filter:/^(@stores|@composables|stx\/stores)$/},(r)=>({path:r.path,external:!0})),p.onResolve({filter:/^\//},(r)=>{let c=rt(r.path);if(c){let x=F(r.importer,c,r.path);if(x)return x;if(c!==n)i.add(c);return{path:c}}return{path:r.path,external:!0}}),p.onResolve({filter:/^\.\.?\//},(r)=>{let c=j(r.importer,r.path),x=F(r.importer,c,r.path);if(x)return x;return i.add(c),{path:c}}),p.onResolve({filter:/^[@~]\//},(r)=>{let c=d.resolve(t,r.path.slice(2)),x=[c,`${c}.ts`,`${c}.tsx`,`${c}.js`,`${c}.mjs`,`${c}.jsx`,d.join(c,"index.ts"),d.join(c,"index.tsx"),d.join(c,"index.js"),d.join(c,"index.mjs")];for(let I of x)if(b.existsSync(I)&&b.statSync(I,{throwIfNoEntry:!1})?.isFile()){let E=F(r.importer,I,r.path);if(E)return E;return C(`resolved ${r.path[0]}/ import:`,r.path,"\u2192",I),i.add(I),{path:I}}return console.warn(`[stx:bundler] could not resolve ${r.path[0]}/ import:`,r.path),{path:c}}),u)p.onResolve({filter:/^(?!node:|bun:)(?:@[\w.-]+\/)?[\w.-]/},(r)=>{if(r.importer!==n)return;let c=`${yn}npm:${r.path}`;return g.set(r.path,c),{path:c,external:!0}});p.onLoad({filter:/\.(?:[cm]?[jt]sx?|json)$/},(r)=>{if(X(r.path,t,l))throw Error(`Server-only API source cannot be imported by a client script: ${r.path}`);let c=d.extname(r.path).toLowerCase(),x=c===".json"?"json":c===".tsx"?"tsx":c===".jsx"?"jsx":c===".ts"||c===".mts"||c===".cts"?"ts":"js";if(r.path!==n)i.add(r.path);let I=S?.get(r.path);if(I!==void 0)return{contents:I,loader:"js"};return{contents:b.readFileSync(r.path,"utf8"),loader:x}})}}}var H=new Map,k=m(64),it=Symbol.for("stx.client-bundle-build-queue");function Cc(t){let e=globalThis,i=(e[it]??Promise.resolve()).then(t,t);return e[it]=i.then(()=>{return},()=>{return}),i}async function It(t,e,n={}){let i=n.projectRoot||process.cwd(),u=(await o(i)).serverApi,g=n.minify??!1,l=n.externalizeUserModules??!0,S=n.expose?.length?[...new Set(n.expose)].sort():void 0,F=n.cacheDir||bc(i),j=K.getStore(),p=new Bun.CryptoHasher("md5");p.update(`${ht}\x00${Ke()}\x00${JSON.stringify(u??!1)}\x00${l?"registry":"inline"}\x00${S?S.join(","):"*"}\x00${g?"minified":"readable"}\x00${j?.key??""}\x00${nt(t,i)}\x00${nt(e,i)}`);let r=p.digest("hex").slice(0,12),c=d.join(F,`${r}.js`),x=k.get(c);if(x){if(ar(x.files)&&x.files.every((R)=>!X(R.path,i,u))){C("memo hit:",r);let R=x.files.map((A)=>A.path);return q(e,R),n.collectInputs?.push(...R),x.code}k.delete(c),C("memo invalidated by dep change:",r)}let I=d.join(F,`${r}.deps.json`),E=Bun.file(c);if(await E.exists()){let R=Bun.file(I),A=!1,O=null;if(await R.exists())try{let D=JSON.parse(await R.text());if(D.metadataVersion===ot&&Array.isArray(D.files)&&bt(D.files,i))O=vn(D.files.map((h)=>at(h,i))),A=O.length===D.files.length&&!O.some((h)=>X(h.path,i,u))}catch{A=!1}if(A){if(C("cache hit:",r),O)q(e,O.map((T)=>T.path)),n.collectInputs?.push(...O.map((T)=>T.path));let D=await E.text(),h=new Date;if(b.promises.utimes(c,h,h).catch(()=>{}),O)k.set(c,{code:D,files:O});return D}C("cache invalidated by dep change:",r)}let z=H.get(r);if(z){let R=await z;if(n.collectInputs)n.collectInputs.push(...(k.get(c)?.files??[]).map((A)=>A.path));return R}let V=Cc(()=>Et(t,e,{projectRoot:i,minify:g,cacheDir:F,hash:r,cachePath:c,depsPath:I,collectInputs:n.collectInputs,externalizeUserModules:l,serverApi:u,expose:S,throwOnFailure:n.throwOnFailure,substitutes:j?.modules}));H.set(r,V);try{return await V}finally{H.delete(r)}}var jt=0;function _c(t){return`${t}-${process.pid}-${++jt}`}async function Et(t,e,n){let{projectRoot:i,minify:u,cacheDir:g,hash:l,cachePath:S,depsPath:F,externalizeUserModules:j}=n,p=a(i,"bundle-tmp"),r=_c(l),c=d.join(p,`${r}.ts`),x=d.join(p,"out",r);b.mkdirSync(p,{recursive:!0}),b.mkdirSync(x,{recursive:!0});let I=d.dirname(e),E=new Set,z=/^[ \t]*(export\s+)?(?:const|let|var)\s+(?:\{([^}]+)\}|(\w+))/gm,V=/^[ \t]*(export\s+)?(?:async\s+)?function\s+(\w+)/gm,R=s(t),{depths:A,balanced:O}=Ae(R),D=(B)=>!O||A[B]===0,h;while((h=z.exec(R))!==null){if(h[1])continue;if(!D(h.index))continue;if(h[2])h[2].split(",").forEach((B)=>{let f=_t(B);if(f)E.add(f)});else if(h[3])E.add(h[3])}while((h=V.exec(R))!==null){if(h[1])continue;if(!D(h.index))continue;E.add(h[2])}let T=/^[ \t]*import[ \t]+(?!type\b)(?:(\w+)\s*(?:,\s*)?)?(?:\*\s+as\s+(\w+)|\{([^}]+)\})?\s+from\b/gm;while((h=T.exec(R))!==null){if(!D(h.index))continue;let B=/^\s*['"]([^'"]+)['"]/.exec(t.slice(h.index+h[0].length))?.[1];if(B&&Q.some((f)=>f.test(B)))continue;if(h[1])E.add(h[1]);if(h[2])E.add(h[2]);for(let f of(h[3]??"").split(",")){let v=f.trim();if(!v||/^type\s/.test(v))continue;let L=/\bas\s+(\w+)\s*$/.exec(v)?.[1]??/^\w+$/.exec(v)?.[0];if(L)E.add(L)}}for(let B of R.matchAll(/\bexport\s*\{([^}]+)\}/g))for(let f of B[1].split(",")){let v=/\bas\s+(\w+)\s*$/.exec(f)?.[1]??/^\s*(\w+)\s*$/.exec(f)?.[1];if(v)E.delete(v)}let lt=E.size>0?`
2
+ import{bn,fe}from"./chunk-bsts9pr5.js";import{M,m,vn,ar,w,Ke,o,P}from"./chunk-m690cqee.js";import{bs}from"./chunk-6w3nph4g.js";import{s,Pe}from"./chunk-70et0fbw.js";import{a}from"./chunk-8cqx63aw.js";import d from"path";import b from"fs";import{AsyncLocalStorage as gt}from"async_hooks";var ht=11;function X(t,e,n){return/^(?:(?:stx|ui)\.config\.[cm]?[jt]s|runtime-config-(?:server|loader)\.[cm]?[jt]s)$/.test(d.basename(t))||bs(t,e,n)}var ot=2;function bc(t){let e=process.env.STX_BUNDLE_CACHE_DIR?.trim();return e?d.resolve(e):a(t,"bundle-cache")}function nt(t,e){let n=t;for(let i of xt(e))if(i!==d.sep)n=n.split(i).join("\x00root");return n}var st=new Map;function xt(t){let e=d.resolve(t),n=st.get(e);if(!n){let i=e;try{i=b.realpathSync(e)}catch{}n=[...new Set([e,i])].sort((u,g)=>g.length-u.length),st.set(e,n)}return n}function yt(t,e){try{let n=b.statSync(t),i=d.resolve(e),u=t.startsWith(`${i}${d.sep}`);return{path:u?d.relative(i,t):t,...u?{inRoot:!0}:{},mtimeMs:n.mtimeMs,size:n.size,hash:Bun.hash(b.readFileSync(t)).toString(36)}}catch{return null}}function at(t,e){return t.inRoot?d.join(d.resolve(e),t.path):t.path}function bt(t,e){for(let n of t){let i=at(n,e);try{let u=b.statSync(i);if(u.size!==n.size)return!1;if(u.mtimeMs!==n.mtimeMs&&Bun.hash(b.readFileSync(i)).toString(36)!==n.hash)return!1}catch{return!1}}return!0}var ct=new Map,wt=100;function vc(t=process.env){let e=Number(t.STX_BUNDLE_CACHE_LIMIT);return Number.isFinite(e)&&e>=1?Math.floor(e):2000}var G=new Map;async function St(t){let e=G.get(t)??0;if(e>0&&e<wt){G.set(t,e+1);return}G.set(t,1);try{let n=(await b.promises.readdir(t)).filter((l)=>l.endsWith(".js")),i=vc();if(n.length<=i)return;let g=(await Promise.all(n.map(async(l)=>{try{return{name:l,at:(await b.promises.stat(d.join(t,l))).mtimeMs}}catch{return null}}))).filter((l)=>l!==null);g.sort((l,S)=>S.at-l.at);for(let l of g.slice(i)){let S=l.name.slice(0,-3);await b.promises.rm(d.join(t,`${S}.js`),{force:!0}),await b.promises.rm(d.join(t,`${S}.deps.json`),{force:!0})}C("pruned bundle cache to",i,"entries")}catch{}}function pe(t){return ct.get(t)??[]}function q(t,e){if(t)ct.set(t,e)}function wc(t=process.env){return t.STX_DEBUG==="true"||t.STX_DEBUG==="1"}function C(...t){if(wc())console.log("[stx:bundler]",...t)}var Y=[];function di(t,e,n){Y.push({filePath:t||"<inline>",message:e,details:n})}function $t(){return Y.slice()}function Rt(){Y.length=0}var Z;function Qu(t){Z=t}function pi(){if(Z)return Z;try{let t=P.strict;return typeof t==="object"&&t!==null?t.bundlerFallback??"warn":"warn"}catch{return"warn"}}var Q=[/^stx$/,/^@stacksjs\/stx$/,/^@stores$/,/^stx\/stores$/,/^@composables$/];function At(t){let e=/^[ \t]*import[ \t]+(?!type(?:[ \t]|{))[\s\S]*?\s+from\s+['"]([^'"]+)['"][ \t]*;?/gm,n;while((n=e.exec(t))!==null){let u=n[1];if(!Q.some((l)=>l.test(u)))return C("detected user import:",u),!0}let i=/^[ \t]*import[ \t]*['"]([^'"]+)['"]/gm;while((n=i.exec(t))!==null){let u=n[1];if(/\.css(?:\?.*)?$/.test(u))continue;if(!Q.some((l)=>l.test(u)))return C("detected side-effect import:",u),!0}return!1}var yn="stx-module:",vt=/\.(?:[cm]?[jt]sx?|json)$/i;function xc(t,e){return d.relative(t,e).split(d.sep).join("/")}function Sc(t,e){if(e.size===0)return t;return t.replace(/^([ \t]*import(?:(?:\s+|(?=[{*]))[^;"']*?\s*from\s*|\s*))(["'])([^"']+)\2/gm,(n,i,u,g)=>{let l=e.get(g);return l&&!g.startsWith(yn)?`${i}${u}${l}${u}`:n})}function kc(t,e){let n=0,i=(g)=>{let l=`__stxMod${n++}`,S=JSON.stringify(g);return e.push(`var ${l} = globalThis.__stxModules && globalThis.__stxModules[${S}];`,`if (${l} === undefined) throw new Error("[stx] module " + ${JSON.stringify(S)} + " is not registered on this page (#1957)");`),l},u=(g,l)=>{for(let S of g.split(",")){let F=S.trim();if(!F)continue;let j=F.match(/^("(?:[^"\\]|\\.)*"|[\w$]+)(?:\s+as\s+([\w$]+))?$/);if(!j)continue;let p=j[1].startsWith('"')?JSON.parse(j[1]):j[1],r=j[2]??p;e.push(`var ${r} = ${l}[${JSON.stringify(p)}];`)}};return t=t.replace(/^[ \t]*import(?:\s+|(?=[{*]))([^;"']+?)\s*from\s*["'](stx-module:[^"']+)["'];?[ \t]*$/gm,(g,l,S)=>{let F=S.slice(yn.length),j=i(F),p=l.trim(),r=p.match(/^([\w$]+)\s*(?:,\s*|$)/);if(r&&!p.startsWith("{")&&!p.startsWith("*"))e.push(`var ${r[1]} = ${j}.default;`),p=p.slice(r[0].length).trim();let c=p.match(/^\*\s*as\s+([\w$]+)$/);if(c)e.push(`var ${c[1]} = ${j};`);else if(p.startsWith("{"))u(p.replace(/^\{|\}$/g,""),j);return""}),t=t.replace(/^[ \t]*import\s*["'](stx-module:[^"']+)["'];?[ \t]*$/gm,(g,l)=>(i(l.slice(yn.length)),"")),t}function rt(t){let e=[t,`${t}.ts`,`${t}.tsx`,`${t}.js`,`${t}.mjs`,`${t}.jsx`,d.join(t,"index.ts"),d.join(t,"index.tsx"),d.join(t,"index.js"),d.join(t,"index.mjs")];for(let n of e)try{if(b.existsSync(n)&&b.statSync(n,{throwIfNoEntry:!1})?.isFile())return n}catch{}return}var K=new gt;function gs(t,e){let n=new Bun.CryptoHasher("md5");for(let[i,u]of[...t].sort(([g],[l])=>g<l?-1:g>l?1:0))n.update(`${i}\x00${u}\x00`);return K.run({modules:t,key:n.digest("hex").slice(0,12)},e)}function Pt(){return K.getStore()?.key??""}function Bt(t,e,n,i,u,g=new Map,l,S){let F=(p,r,c)=>{if(X(r,t,l))return null;if(!u||p!==n||!vt.test(r))return null;try{if(!b.statSync(r,{throwIfNoEntry:!1})?.isFile())return null}catch{return null}i.add(r);let x=`${yn}${xc(process.cwd(),r)}`;return g.set(c,x),{path:x,external:!0}},j=(p,r)=>{let c=p===n?e:d.dirname(p),x=d.resolve(c,r);return rt(x)??x};return{name:"stx-client-bundle",setup(p){if(p.onResolve({filter:/^(stx|@stacksjs\/stx)$/},(r)=>({path:r.path,external:!0})),p.onResolve({filter:/^(@stores|@composables|stx\/stores)$/},(r)=>({path:r.path,external:!0})),p.onResolve({filter:/^\//},(r)=>{let c=rt(r.path);if(c){let x=F(r.importer,c,r.path);if(x)return x;if(c!==n)i.add(c);return{path:c}}return{path:r.path,external:!0}}),p.onResolve({filter:/^\.\.?\//},(r)=>{let c=j(r.importer,r.path),x=F(r.importer,c,r.path);if(x)return x;return i.add(c),{path:c}}),p.onResolve({filter:/^[@~]\//},(r)=>{let c=d.resolve(t,r.path.slice(2)),x=[c,`${c}.ts`,`${c}.tsx`,`${c}.js`,`${c}.mjs`,`${c}.jsx`,d.join(c,"index.ts"),d.join(c,"index.tsx"),d.join(c,"index.js"),d.join(c,"index.mjs")];for(let I of x)if(b.existsSync(I)&&b.statSync(I,{throwIfNoEntry:!1})?.isFile()){let E=F(r.importer,I,r.path);if(E)return E;return C(`resolved ${r.path[0]}/ import:`,r.path,"\u2192",I),i.add(I),{path:I}}return console.warn(`[stx:bundler] could not resolve ${r.path[0]}/ import:`,r.path),{path:c}}),u)p.onResolve({filter:/^(?!node:|bun:)(?:@[\w.-]+\/)?[\w.-]/},(r)=>{if(r.importer!==n)return;let c=`${yn}npm:${r.path}`;return g.set(r.path,c),{path:c,external:!0}});p.onLoad({filter:/\.(?:[cm]?[jt]sx?|json)$/},(r)=>{if(X(r.path,t,l))throw Error(`Server-only API source cannot be imported by a client script: ${r.path}`);let c=d.extname(r.path).toLowerCase(),x=c===".json"?"json":c===".tsx"?"tsx":c===".jsx"?"jsx":c===".ts"||c===".mts"||c===".cts"?"ts":"js";if(r.path!==n)i.add(r.path);let I=S?.get(r.path);if(I!==void 0)return{contents:I,loader:"js"};return{contents:b.readFileSync(r.path,"utf8"),loader:x}})}}}var H=new Map,k=m(64),it=Symbol.for("stx.client-bundle-build-queue");function Cc(t){let e=globalThis,i=(e[it]??Promise.resolve()).then(t,t);return e[it]=i.then(()=>{return},()=>{return}),i}async function It(t,e,n={}){let i=n.projectRoot||process.cwd(),u=(await o(i)).serverApi,g=n.minify??!1,l=n.externalizeUserModules??!0,S=n.expose?.length?[...new Set(n.expose)].sort():void 0,F=n.cacheDir||bc(i),j=K.getStore(),p=new Bun.CryptoHasher("md5");p.update(`${ht}\x00${Ke()}\x00${JSON.stringify(u??!1)}\x00${l?"registry":"inline"}\x00${S?S.join(","):"*"}\x00${g?"minified":"readable"}\x00${j?.key??""}\x00${nt(t,i)}\x00${nt(e,i)}`);let r=p.digest("hex").slice(0,12),c=d.join(F,`${r}.js`),x=k.get(c);if(x){if(ar(x.files)&&x.files.every((R)=>!X(R.path,i,u))){C("memo hit:",r);let R=x.files.map((A)=>A.path);return q(e,R),n.collectInputs?.push(...R),x.code}k.delete(c),C("memo invalidated by dep change:",r)}let I=d.join(F,`${r}.deps.json`),E=Bun.file(c);if(await E.exists()){let R=Bun.file(I),A=!1,O=null;if(await R.exists())try{let D=JSON.parse(await R.text());if(D.metadataVersion===ot&&Array.isArray(D.files)&&bt(D.files,i))O=vn(D.files.map((h)=>at(h,i))),A=O.length===D.files.length&&!O.some((h)=>X(h.path,i,u))}catch{A=!1}if(A){if(C("cache hit:",r),O)q(e,O.map((T)=>T.path)),n.collectInputs?.push(...O.map((T)=>T.path));let D=await E.text(),h=new Date;if(b.promises.utimes(c,h,h).catch(()=>{}),O)k.set(c,{code:D,files:O});return D}C("cache invalidated by dep change:",r)}let z=H.get(r);if(z){let R=await z;if(n.collectInputs)n.collectInputs.push(...(k.get(c)?.files??[]).map((A)=>A.path));return R}let V=Cc(()=>Et(t,e,{projectRoot:i,minify:g,cacheDir:F,hash:r,cachePath:c,depsPath:I,collectInputs:n.collectInputs,externalizeUserModules:l,serverApi:u,expose:S,throwOnFailure:n.throwOnFailure,substitutes:j?.modules}));H.set(r,V);try{return await V}finally{H.delete(r)}}var jt=0;function _c(t){return`${t}-${process.pid}-${++jt}`}async function Et(t,e,n){let{projectRoot:i,minify:u,cacheDir:g,hash:l,cachePath:S,depsPath:F,externalizeUserModules:j}=n,p=a(i,"bundle-tmp"),r=_c(l),c=d.join(p,`${r}.ts`),x=d.join(p,"out",r);b.mkdirSync(p,{recursive:!0}),b.mkdirSync(x,{recursive:!0});let I=d.dirname(e),E=new Set,z=/^[ \t]*(export\s+)?(?:const|let|var)\s+(?:\{([^}]+)\}|(\w+))/gm,V=/^[ \t]*(export\s+)?(?:async\s+)?function\s+(\w+)/gm,R=s(t),{depths:A,balanced:O}=Pe(R),D=(B)=>!O||A[B]===0,h;while((h=z.exec(R))!==null){if(h[1])continue;if(!D(h.index))continue;if(h[2])h[2].split(",").forEach((B)=>{let f=_t(B);if(f)E.add(f)});else if(h[3])E.add(h[3])}while((h=V.exec(R))!==null){if(h[1])continue;if(!D(h.index))continue;E.add(h[2])}let T=/^[ \t]*import[ \t]+(?!type\b)(?:(\w+)\s*(?:,\s*)?)?(?:\*\s+as\s+(\w+)|\{([^}]+)\})?\s+from\b/gm;while((h=T.exec(R))!==null){if(!D(h.index))continue;let B=/^\s*['"]([^'"]+)['"]/.exec(t.slice(h.index+h[0].length))?.[1];if(B&&Q.some((f)=>f.test(B)))continue;if(h[1])E.add(h[1]);if(h[2])E.add(h[2]);for(let f of(h[3]??"").split(",")){let v=f.trim();if(!v||/^type\s/.test(v))continue;let L=/\bas\s+(\w+)\s*$/.exec(v)?.[1]??/^\w+$/.exec(v)?.[0];if(L)E.add(L)}}for(let B of R.matchAll(/\bexport\s*\{([^}]+)\}/g))for(let f of B[1].split(",")){let v=/\bas\s+(\w+)\s*$/.exec(f)?.[1]??/^\s*(\w+)\s*$/.exec(f)?.[1];if(v)E.delete(v)}let lt=E.size>0?`
3
3
  export { ${[...E].join(", ")} }`:"";await Bun.write(c,t+lt),C("bundling:",l,"from:",d.basename(e));let tt=new Set,et=new Map;try{let B=await Bun.build({entrypoints:[c],outdir:x,target:"browser",format:"esm",minify:u?{whitespace:!1,identifiers:!0,syntax:!0}:!1,plugins:[Bt(i,I,c,tt,j,et,n.serverApi,n.substitutes)],define:{"process.env.NODE_ENV":u?'"production"':'"development"',...w()},root:i});if(!B.success){let _=B.logs.filter((N)=>N.level==="error").map((N)=>N.message).join(", ")||`Unable to bundle ${d.basename(e)}`,U=bn(B.logs,e||void 0);if(console.warn("[stx:bundler] build failed:",_),di(e||"",_,U),n.throwOnFailure||pi()==="error")throw Error(_);return t}let f="";for(let y of B.outputs){f=await y.text();break}let v=[];for(let y of f.matchAll(/^\s*export\s*\{([^}]*)\}\s*;?\s*$/gm))for(let _ of y[1].split(",")){let U=_.trim().match(/^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/);if(U){v.push([U[2],U[1]]);continue}let N=_.trim();if(/^[A-Za-z_$][\w$]*$/.test(N))v.push([N,N])}if(n.expose){let y=new Set(n.expose);for(let _=v.length-1;_>=0;_--)if(!y.has(v[_][0]))v.splice(_,1)}let L=[];f=kc(Sc(f,et),L);let ut=f.match(/^\s*import(?:\s+|(?=["'{*]))[^;]+;?\s*$/gm)||[];if(f=f.replace(/^\s*import(?:\s+|(?=["'{*]))[^;]+;?\s*$/gm,"").replace(/^\s*export\s*\{[^}]*\}\s*;?\s*$/gm,"").replace(/^\s*export\s+default\s+.*$/gm,"").trim(),u&&f)try{f=new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(f)}catch{}let J=`__stxBundle_${l}`,dt=new Set(M(t,!0).split(",").map((y)=>y.trim())),pt=v.map(([y,_])=>`get ${JSON.stringify(y)}() { return ${_} }${dt.has(y)?`, set ${JSON.stringify(y)}(__stxValue_${_}) { ${_} = __stxValue_${_} }`:""}`).join(", "),ft=v.map(([y])=>`var ${y} = undefined;`).join(`
4
4
  `),mt=v.map(([y])=>`${y} = ${J}[${JSON.stringify(y)}];`).join(`
5
5
  `);if(f=`${ut.join(`
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{bc,vc,pe,wc,di,$t,Rt,Qu,pi,At,yn,xc,Sc,kc,gs,Pt,Cc,It,_c}from"./chunk-215fsx0k.js";import"./chunk-26g3m2mg.js";import"./chunk-bsts9pr5.js";import"./chunk-0bptz1km.js";import"./chunk-95ygdn0n.js";import"./chunk-y255yybn.js";import"./chunk-1m5cjrpw.js";import"./chunk-jdx4za9p.js";import"./chunk-a0ygyftk.js";import"./chunk-arrvcn7c.js";import"./chunk-tw10tgz8.js";import"./chunk-hjtym7d9.js";import"./chunk-ahyq08mp.js";import"./chunk-g1ae3haw.js";import"./chunk-fk79x8ns.js";import"./chunk-pvfx0dgz.js";export{yn as MODULE_SPECIFIER_PREFIX,bc as bundleCacheDir,vc as bundleCacheEntryLimit,It as bundleClientScript,Rt as clearBundleFailures,pe as clientBundleDependencies,$t as getBundleFailures,At as hasUserImports,Pt as moduleSubstitutionKey,Sc as normalizeRegistrySpecifiers,Cc as queueClientBundleBuild,di as recordBundleFailure,xc as registryIdForPath,pi as resolveBundlerFallback,kc as rewriteRegistryImports,Qu as setBundlerFallbackMode,wc as shouldLogBundlerDiagnostics,_c as tempBuildName,gs as withModuleSubstitutes};
2
+ import{bc,vc,pe,wc,di,$t,Rt,Qu,pi,At,yn,xc,Sc,kc,gs,Pt,Cc,It,_c}from"./chunk-9gvq1spk.js";import"./chunk-6w3nph4g.js";import"./chunk-bsts9pr5.js";import"./chunk-m690cqee.js";import"./chunk-r00nn2qs.js";import"./chunk-y255yybn.js";import"./chunk-1m5cjrpw.js";import"./chunk-cq331w4g.js";import"./chunk-a0ygyftk.js";import"./chunk-6vmvra0f.js";import"./chunk-qmh6f1bt.js";import"./chunk-m92q2jyt.js";import"./chunk-ahyq08mp.js";import"./chunk-g1ae3haw.js";import"./chunk-gsp3627d.js";import"./chunk-pvfx0dgz.js";export{yn as MODULE_SPECIFIER_PREFIX,bc as bundleCacheDir,vc as bundleCacheEntryLimit,It as bundleClientScript,Rt as clearBundleFailures,pe as clientBundleDependencies,$t as getBundleFailures,At as hasUserImports,Pt as moduleSubstitutionKey,Sc as normalizeRegistrySpecifiers,Cc as queueClientBundleBuild,di as recordBundleFailure,xc as registryIdForPath,pi as resolveBundlerFallback,kc as rewriteRegistryImports,Qu as setBundlerFallbackMode,wc as shouldLogBundlerDiagnostics,_c as tempBuildName,gs as withModuleSubstitutes};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{We,un,Ru}from"./chunk-dcwhp21g.js";import{X,dn,Au,pn,as,tr,nr,Pu,Iu,Ou,fn,gn,cs,rr,Nu}from"./chunk-5kbkx0np.js";import"./chunk-g1ae3haw.js";export{as as batch,Ru as default,dn as derived,pn as effect,We as generateSignalsRuntime,un as generateSignalsRuntimeDev,gn as isDerived,fn as isSignal,Au as memo,nr as onDestroy,tr as onMount,rr as peek,Ou as pendingLifecycleCounts,Iu as runDestroyCallbacks,Pu as runMountCallbacks,X as state,cs as untrack,Nu as useOptimistic};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{ba,To,va,wa,$o,xa,Sa,ka,Ca,Ro,_a,Tl}from"./chunk-0j9f54wv.js";import{Bo,Pa}from"./chunk-bx3ar1wz.js";import{F,z,H,Zt,te,ue,Qn,He,Ct,Qt,en,tn,V,nn,rn,er}from"./chunk-9hqjezhx.js";import{cc}from"./chunk-b4j5bpec.js";import"./chunk-7ftn9ber.js";export{z as DEFAULT_FORMATS,H as DEFAULT_QUALITY,F as DEFAULT_WIDTHS,er as ImageProcessingError,wa as clearImageCache,$o as createImageDirective,Pa as createImageHandler,Sa as createImagePlugin,Tl as defaultImageConfig,rn as formatSize,Ro as generateImageManifest,Ct as generateSizes,He as generateSrcSet,Qt as getFallbackVariant,Qn as getImageMetadata,V as getMimeType,nn as getTotalSize,en as groupVariantsByFormat,Bo as handleImageRequest,xa as imageDirective,te as isImageBackendAvailable,tn as isImageFile,Zt as isSharpAvailable,Ca as optimizeDirectory,ka as optimizeImage,To as parseImageComponent,ue as processImage,va as processImageComponents,ba as renderImageComponent,cc as rewriteImagesWithSiblings,_a as writeImageManifest};
2
+ import{ba,To,va,wa,$o,xa,Sa,ka,Ca,Ro,_a,Tl}from"./chunk-9939fjh4.js";import{Bo,Pa}from"./chunk-639ngkgb.js";import{F,z,H,Zt,te,ue,Qn,Ve,Ct,Qt,en,tn,V,nn,rn,er}from"./chunk-s775b8ra.js";import{cc}from"./chunk-b4j5bpec.js";import"./chunk-gmxrckgj.js";export{z as DEFAULT_FORMATS,H as DEFAULT_QUALITY,F as DEFAULT_WIDTHS,er as ImageProcessingError,wa as clearImageCache,$o as createImageDirective,Pa as createImageHandler,Sa as createImagePlugin,Tl as defaultImageConfig,rn as formatSize,Ro as generateImageManifest,Ct as generateSizes,Ve as generateSrcSet,Qt as getFallbackVariant,Qn as getImageMetadata,V as getMimeType,nn as getTotalSize,en as groupVariantsByFormat,Bo as handleImageRequest,xa as imageDirective,te as isImageBackendAvailable,tn as isImageFile,Zt as isSharpAvailable,Ca as optimizeDirectory,ka as optimizeImage,To as parseImageComponent,ue as processImage,va as processImageComponents,ba as renderImageComponent,cc as rewriteImagesWithSiblings,_a as writeImageManifest};