@stacksjs/stx 0.2.577 → 0.2.578

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 (209) hide show
  1. package/dist/chunk-0047meje.js +2 -0
  2. package/dist/chunk-00p22wzr.js +3 -0
  3. package/dist/{chunk-z33z3rr4.js → chunk-0k5faspy.js} +6 -6
  4. package/dist/{chunk-wwhxgvr8.js → chunk-0vnngvy1.js} +4 -4
  5. package/dist/{chunk-7a0ewpz0.js → chunk-101ekf6y.js} +2 -2
  6. package/dist/{chunk-t79xnvzr.js → chunk-117xss52.js} +2 -2
  7. package/dist/chunk-1cat8kdj.js +2 -0
  8. package/dist/chunk-1dwnp35v.js +2 -0
  9. package/dist/{chunk-5vw8493b.js → chunk-1r1maqep.js} +3 -3
  10. package/dist/{chunk-zak5xare.js → chunk-1v1mew46.js} +1 -1
  11. package/dist/chunk-2dnr5qfk.js +2 -0
  12. package/dist/{chunk-1swmxkdt.js → chunk-2rx9d75e.js} +2 -2
  13. package/dist/chunk-2v73cjbc.js +2 -0
  14. package/dist/chunk-3akgppsy.js +2 -0
  15. package/dist/{chunk-8efe5vpm.js → chunk-3e3dpp7w.js} +3 -3
  16. package/dist/{chunk-vnsby98n.js → chunk-3qrrv6af.js} +1 -1
  17. package/dist/{chunk-fkbthywg.js → chunk-3wy8q3aq.js} +5 -5
  18. package/dist/chunk-3x6p9me0.js +2 -0
  19. package/dist/{chunk-tybk9hw9.js → chunk-43h8q2cm.js} +9 -9
  20. package/dist/{chunk-pqkb1m5x.js → chunk-4rkvwm6v.js} +5 -5
  21. package/dist/{chunk-bks1fe5e.js → chunk-4srg0qbv.js} +1 -1
  22. package/dist/chunk-4t67wmcg.js +2 -0
  23. package/dist/chunk-51zn42jy.js +2 -0
  24. package/dist/chunk-5702x95v.js +2 -0
  25. package/dist/{chunk-4z21afpp.js → chunk-5db5sxy3.js} +2 -2
  26. package/dist/{chunk-r4w1cye7.js → chunk-5kh5ehfh.js} +2 -2
  27. package/dist/chunk-5pgbsc3a.js +2 -0
  28. package/dist/chunk-60c2bsh9.js +2 -0
  29. package/dist/{chunk-vw1rmevt.js → chunk-620szfcp.js} +3 -3
  30. package/dist/{chunk-6rfm6b1c.js → chunk-6w2yqtrd.js} +2 -2
  31. package/dist/{chunk-37d52q0d.js → chunk-6z3e1tyz.js} +1 -1
  32. package/dist/{chunk-nskvepjv.js → chunk-71sdgv7e.js} +5 -5
  33. package/dist/chunk-79v4d9qh.js +2 -0
  34. package/dist/{chunk-qfb34r6k.js → chunk-7hkc96de.js} +6 -6
  35. package/dist/chunk-7pp2vx1g.js +2 -0
  36. package/dist/chunk-84f9dnq5.js +2 -0
  37. package/dist/chunk-8tq5x4z8.js +2 -0
  38. package/dist/{chunk-gjp2jxrp.js → chunk-8v19753h.js} +1 -1
  39. package/dist/chunk-8zm6tkqb.js +2 -0
  40. package/dist/{chunk-1dg5qxg9.js → chunk-9jh2ake5.js} +5 -5
  41. package/dist/chunk-a1z36dt5.js +2 -0
  42. package/dist/{chunk-7hr63cp5.js → chunk-ah9xyss2.js} +2 -2
  43. package/dist/chunk-atsf1fe0.js +2 -0
  44. package/dist/{chunk-x5xwe5nr.js → chunk-ayy9mmrw.js} +7 -7
  45. package/dist/chunk-b8qd6h1q.js +2 -0
  46. package/dist/{chunk-vde4mtfr.js → chunk-be2ba3hj.js} +2 -2
  47. package/dist/{chunk-pxk0tpw2.js → chunk-bj29pwm0.js} +3 -3
  48. package/dist/{chunk-gpb22a8n.js → chunk-c0h2eqe0.js} +2 -2
  49. package/dist/{chunk-agk478t4.js → chunk-c0s3k64c.js} +2 -2
  50. package/dist/{chunk-bctjmaxg.js → chunk-c1r7zq0q.js} +41 -41
  51. package/dist/{chunk-32gycb72.js → chunk-cb2pyg5t.js} +2 -2
  52. package/dist/chunk-ccxs40xy.js +2 -0
  53. package/dist/{chunk-7j9m4d7x.js → chunk-cdgwkzms.js} +3 -3
  54. package/dist/{chunk-6c2y9h5h.js → chunk-cnknvvwm.js} +1 -1
  55. package/dist/chunk-cp442y7a.js +2 -0
  56. package/dist/chunk-d4en5d3s.js +2 -0
  57. package/dist/chunk-dh80d57p.js +2 -0
  58. package/dist/{chunk-je0cttam.js → chunk-djft0m5h.js} +2 -2
  59. package/dist/chunk-dpn1pmxj.js +2 -0
  60. package/dist/chunk-dtcc09x1.js +2 -0
  61. package/dist/{chunk-sf7z2ar9.js → chunk-dvgvvy5b.js} +3 -3
  62. package/dist/chunk-dyqte1xq.js +2 -0
  63. package/dist/chunk-e4n4v022.js +2 -0
  64. package/dist/chunk-efgk2xv1.js +2 -0
  65. package/dist/{chunk-h1n43e5n.js → chunk-ev5f79mg.js} +5 -5
  66. package/dist/{chunk-1wkpxa58.js → chunk-eww6sdzz.js} +2 -2
  67. package/dist/{chunk-34fajf1n.js → chunk-faghmmrs.js} +139 -139
  68. package/dist/chunk-fj70wq7k.js +2 -0
  69. package/dist/chunk-g2fw68zm.js +2 -0
  70. package/dist/{chunk-szfkkbve.js → chunk-g4crr86j.js} +3 -3
  71. package/dist/{chunk-xh0808cd.js → chunk-h0a2s340.js} +2 -2
  72. package/dist/chunk-hcgm37dy.js +2 -0
  73. package/dist/chunk-hd2bn5q7.js +2 -0
  74. package/dist/{chunk-5dm4k229.js → chunk-hzfhn2vr.js} +2 -2
  75. package/dist/{chunk-6wz6f8d5.js → chunk-j1nqnmcd.js} +4 -4
  76. package/dist/{chunk-1c8sdf9a.js → chunk-jpqkm8tm.js} +2 -2
  77. package/dist/{chunk-550q827h.js → chunk-jtbzmbzz.js} +4 -4
  78. package/dist/chunk-k7jqkt93.js +2 -0
  79. package/dist/{chunk-wvk932dp.js → chunk-k9th7hc4.js} +4 -4
  80. package/dist/chunk-kp0hg06s.js +15 -0
  81. package/dist/{chunk-kskyfss0.js → chunk-ktyctev3.js} +2 -2
  82. package/dist/{chunk-xk2v20xe.js → chunk-m8tm44rq.js} +2 -2
  83. package/dist/chunk-mhjwtkx9.js +2 -0
  84. package/dist/chunk-mqy7g74k.js +2 -0
  85. package/dist/chunk-mxe21m6q.js +2 -0
  86. package/dist/chunk-ne03tfje.js +2 -0
  87. package/dist/{chunk-3gqrv02t.js → chunk-nrfh7gaa.js} +3 -3
  88. package/dist/chunk-p2sns0bn.js +2 -0
  89. package/dist/chunk-pjrh71sn.js +122 -0
  90. package/dist/{chunk-jgrtvs81.js → chunk-pmpb34md.js} +5 -5
  91. package/dist/chunk-q2a58n2a.js +2 -0
  92. package/dist/{chunk-5xwmkxkk.js → chunk-qazn64pm.js} +1 -1
  93. package/dist/{chunk-7bwkeake.js → chunk-qccgncp2.js} +6 -6
  94. package/dist/{chunk-1edvsndv.js → chunk-qdyp2zqf.js} +2 -2
  95. package/dist/chunk-rr8a7d4q.js +11 -0
  96. package/dist/{chunk-mr9c2ej6.js → chunk-s12bnv32.js} +2 -2
  97. package/dist/chunk-s1sycp43.js +2 -0
  98. package/dist/chunk-s932zfjz.js +2 -0
  99. package/dist/chunk-sp46w7z9.js +2 -0
  100. package/dist/{chunk-tasjpnbf.js → chunk-sv5nvfmb.js} +2 -2
  101. package/dist/chunk-sy1bk1ry.js +2 -0
  102. package/dist/chunk-t48ws5j0.js +2 -0
  103. package/dist/{chunk-sn3htx1z.js → chunk-t4g2fptt.js} +6 -6
  104. package/dist/{chunk-d8ek63nc.js → chunk-t8wpzqs4.js} +1 -1
  105. package/dist/{chunk-bpdsdbvg.js → chunk-ta3wn842.js} +2 -2
  106. package/dist/chunk-thbc9gtj.js +2 -0
  107. package/dist/chunk-tn9v10q2.js +2 -0
  108. package/dist/chunk-tpd5nwa3.js +2 -0
  109. package/dist/chunk-tpt4bgs5.js +2 -0
  110. package/dist/{chunk-n829xbbq.js → chunk-tszkg6sj.js} +2 -2
  111. package/dist/chunk-v8p5p2kp.js +2 -0
  112. package/dist/chunk-v9jd283e.js +2 -0
  113. package/dist/{chunk-4xvbc0mb.js → chunk-vpdx7qr3.js} +2 -2
  114. package/dist/chunk-vq0cb1m9.js +2 -0
  115. package/dist/chunk-vx75fb0d.js +33 -0
  116. package/dist/{chunk-pveafhzg.js → chunk-w3rmepwy.js} +2 -2
  117. package/dist/{chunk-xsxh7h8z.js → chunk-wg2w7zmt.js} +2 -2
  118. package/dist/chunk-wgkxgsqx.js +2 -0
  119. package/dist/{chunk-707n4pbz.js → chunk-wwj8zbzc.js} +5 -5
  120. package/dist/{chunk-p3xkj7pm.js → chunk-xpnpg967.js} +2 -2
  121. package/dist/chunk-y1bppxgw.js +2 -0
  122. package/dist/{chunk-1w9ngqpv.js → chunk-y8q1n7hx.js} +10 -10
  123. package/dist/{chunk-vmetcczm.js → chunk-yfq2v7x5.js} +6 -6
  124. package/dist/{chunk-h72befy4.js → chunk-yhpyqsbr.js} +4 -4
  125. package/dist/{chunk-n0kw3q6p.js → chunk-yk3fbzx5.js} +4 -4
  126. package/dist/chunk-yv5rwthv.js +2 -0
  127. package/dist/{chunk-mp99h8wh.js → chunk-yy3ser06.js} +5 -5
  128. package/dist/chunk-yygze2s0.js +2 -0
  129. package/dist/chunk-z1r4tdqy.js +2 -0
  130. package/dist/chunk-z732tf98.js +2 -0
  131. package/dist/{chunk-haeb904b.js → chunk-zk2xk0wd.js} +2 -2
  132. package/dist/chunk-zv288w4e.js +2 -0
  133. package/dist/{chunk-j4zyq2ap.js → chunk-zz02hwec.js} +11 -11
  134. package/dist/cli.js +19 -19
  135. package/dist/client-script-bundler.d.ts +12 -0
  136. package/dist/client-script-bundler.js +19 -5
  137. package/dist/composable-loader.js +2 -2
  138. package/dist/craft-entry.js +2 -2
  139. package/dist/craft.js +2 -2
  140. package/dist/native/compiler/bundle.d.ts +22 -0
  141. package/dist/native/compiler/bundle.js +164 -20
  142. package/dist/pwa.js +3 -3
  143. package/dist/ssg.js +3 -3
  144. package/dist/store-loader.js +7 -7
  145. package/package.json +5 -5
  146. package/dist/chunk-08a98yqt.js +0 -2
  147. package/dist/chunk-0q5s55km.js +0 -2
  148. package/dist/chunk-181m21rg.js +0 -2
  149. package/dist/chunk-194qgkc9.js +0 -2
  150. package/dist/chunk-1nbn56jw.js +0 -2
  151. package/dist/chunk-2ry2pfpe.js +0 -2
  152. package/dist/chunk-3bj1w990.js +0 -2
  153. package/dist/chunk-4a12azrb.js +0 -2
  154. package/dist/chunk-6aq3sm83.js +0 -2
  155. package/dist/chunk-6fpynp8q.js +0 -2
  156. package/dist/chunk-6q3yszw9.js +0 -74
  157. package/dist/chunk-6ryab0yy.js +0 -2
  158. package/dist/chunk-6sasxbv9.js +0 -2
  159. package/dist/chunk-6w9km7qb.js +0 -2
  160. package/dist/chunk-7kh4p06d.js +0 -2
  161. package/dist/chunk-7xrrzqh7.js +0 -2
  162. package/dist/chunk-7y73q42g.js +0 -11
  163. package/dist/chunk-8jaw6exk.js +0 -2
  164. package/dist/chunk-98r9jk2b.js +0 -2
  165. package/dist/chunk-9dgygz8d.js +0 -2
  166. package/dist/chunk-a51f04an.js +0 -2
  167. package/dist/chunk-aa52jhak.js +0 -2
  168. package/dist/chunk-ambynnzb.js +0 -2
  169. package/dist/chunk-ampr3fpv.js +0 -2
  170. package/dist/chunk-asbq9cgs.js +0 -2
  171. package/dist/chunk-bbdg3sqq.js +0 -33
  172. package/dist/chunk-bmtsb5mr.js +0 -2
  173. package/dist/chunk-c8rd3573.js +0 -2
  174. package/dist/chunk-d4b8cgvt.js +0 -2
  175. package/dist/chunk-d7skqhrc.js +0 -2
  176. package/dist/chunk-ensp20xk.js +0 -2
  177. package/dist/chunk-f1zyc84x.js +0 -2
  178. package/dist/chunk-f2y8bwdd.js +0 -2
  179. package/dist/chunk-g9vtny6q.js +0 -2
  180. package/dist/chunk-hcsrj8z6.js +0 -3
  181. package/dist/chunk-hj1bntaa.js +0 -2
  182. package/dist/chunk-hwy3aw5v.js +0 -2
  183. package/dist/chunk-hyafyqy6.js +0 -2
  184. package/dist/chunk-j75hqvgt.js +0 -2
  185. package/dist/chunk-j83ax407.js +0 -2
  186. package/dist/chunk-k3hfwve1.js +0 -2
  187. package/dist/chunk-ktc1ecsm.js +0 -2
  188. package/dist/chunk-mbmbaj0m.js +0 -2
  189. package/dist/chunk-nd3qttxh.js +0 -2
  190. package/dist/chunk-ndc1bmj7.js +0 -2
  191. package/dist/chunk-nn462qm9.js +0 -2
  192. package/dist/chunk-nr07vxm2.js +0 -2
  193. package/dist/chunk-q7a5pwaz.js +0 -2
  194. package/dist/chunk-qx6tr8mr.js +0 -2
  195. package/dist/chunk-r51vyhms.js +0 -2
  196. package/dist/chunk-s68bqf62.js +0 -2
  197. package/dist/chunk-s6sf70ty.js +0 -2
  198. package/dist/chunk-svavrmxb.js +0 -2
  199. package/dist/chunk-sw7mvg9p.js +0 -2
  200. package/dist/chunk-tz40t18m.js +0 -2
  201. package/dist/chunk-v1k0bdsg.js +0 -2
  202. package/dist/chunk-vd10tty0.js +0 -2
  203. package/dist/chunk-vqkzhd19.js +0 -2
  204. package/dist/chunk-w1yft5gg.js +0 -2
  205. package/dist/chunk-w6sa921x.js +0 -2
  206. package/dist/chunk-y120qq1a.js +0 -15
  207. package/dist/chunk-zcw74jmk.js +0 -2
  208. package/dist/chunk-zxvndwaz.js +0 -2
  209. package/dist/chunk-zzr0p4bb.js +0 -2
@@ -1,11 +1,11 @@
1
1
  // @bun
2
- import{G,b,ln,dn,e,Tt,un,f,He,$t,Ue,Ve,te,L,ue,J,d,xe,vi,Cs,n,r,ne,nr,o,P,pe}from"./chunk-34fajf1n.js";import{Y,kn,re,I,Ot}from"./chunk-qfb34r6k.js";import{nt,$n,hr,yr,br,rt,st,ot,it,at,ct,Ee}from"./chunk-h72befy4.js";import{Oe,mo,se,T,ho,Pr,Ln,ye,yo,oe}from"./chunk-pqkb1m5x.js";import{Nt}from"./chunk-je0cttam.js";import{le}from"./chunk-kskyfss0.js";import{a}from"./chunk-hcsrj8z6.js";import{M}from"./chunk-4z21afpp.js";async function Gn(t){try{let s=await Bun.file(t).text(),i=Jn(s),p=Yn(s,t),c=Qn(s,i),l=Zn(s,i);return{file:t,metrics:i,issues:p,suggestions:c,performance:l}}catch(s){throw Error(`Failed to analyze template ${t}: ${s instanceof Error?s.message:String(s)}`)}}function Jn(t){let s=t.split(`
2
+ import{G,b,dn,un,e,$t,pn,f,He,Rt,Ue,Ve,te,L,ue,J,d,xe,Si,Es,n,r,ne,rr,o,P,pe}from"./chunk-faghmmrs.js";import{Y,Cn,re,I,Dt}from"./chunk-7hkc96de.js";import{nt,Rn,yr,br,wr,rt,st,ot,it,at,ct,Ee}from"./chunk-yhpyqsbr.js";import{Oe,yo,se,T,bo,Ir,jn,ye,wo,oe}from"./chunk-4rkvwm6v.js";import{Lt}from"./chunk-djft0m5h.js";import{le}from"./chunk-ktyctev3.js";import{a}from"./chunk-00p22wzr.js";import{M}from"./chunk-5db5sxy3.js";async function Gn(t){try{let s=await Bun.file(t).text(),i=Jn(s),p=Yn(s,t),c=Qn(s,i),l=Zn(s,i);return{file:t,metrics:i,issues:p,suggestions:c,performance:l}}catch(s){throw Error(`Failed to analyze template ${t}: ${s instanceof Error?s.message:String(s)}`)}}function Jn(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,u=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,h=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,g=m+u+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 Yn(t,s){let i=[],p=Jt(t,"if","endif");if(p>0)i.push({type:"error",category:"syntax",message:`Found ${p} 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 u=t.match(/<img[^>]*>/g);if(u){let y=u.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 Qn(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 p=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(p&&p.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 Zn(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 p;if(s.expressions===0&&s.directives.total===0)p="high";else if(s.expressions<5&&s.directives.total<3)p="medium";else p="low";let c=[];if(i>10)c.push("Consider optimizing template complexity");if(p==="low"&&s.directives.total>5)c.push("Reduce dynamic content for better caching");if(s.components===0&&s.lines>40)c.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(i*100)/100,complexityScore:s.complexity,cacheability:p,recommendations:c}}function Jt(t,s,i){let p=t.replace(/<!--[\s\S]*?-->/g,""),c=(p.match(new RegExp(`@${s}\\b`,"g"))||[]).length,l=(p.match(new RegExp(`@${i}\\b`,"g"))||[]).length;return Math.abs(c-l)}async function to(t=["**/*.stx"],s){let i=[],p=[];for(let l of t){let m=await Array.fromAsync(new Bun.Glob(l).scan({cwd:s||process.cwd(),onlyFiles:!0,absolute:!0}));p.push(...m.filter((u)=>u.endsWith(".stx")))}for(let l of p)try{let m=await Gn(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),p=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,u=Math.max(1,Math.min(10,Math.round(10-m/2-p/2))),h=[];if(p>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(p*100)/100,totalIssues:c,issuesByCategory:l,performanceScore:u,recommendations:h}}import{mkdir as tr,readFile as rr,readdir as or,stat as Yt,writeFile as sr}from"fs/promises";import Pe 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 ir(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((s)=>s.charAt(0).toUpperCase()+s.slice(1)).join("")}function Bt(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function ar(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function cr(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function lr(t){let s=[];async function i(p){let c=await or(p,{withFileTypes:!0});c.sort((l,m)=>l.name.localeCompare(m.name));for(let l of c){let m=Pe.join(p,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 dr(t,s){let i=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!i)return{};let p=i[1].trim();if(!p)return{};try{return JSON.parse(p)}catch(c){throw Error(`${s}: <script component> must contain JSON metadata (${c.message})`)}}function pr(t,s){let i={},p=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let c of p){if(!/\bclient\b/i.test(c[1])||/\bcomponent\b|\bstx:component\b/i.test(c[1]))continue;let l;try{l=new Bun.Transpiler({loader:"ts"}).transformSync(c[2])}catch(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,u;while(u=m.exec(l)){let h=u[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=u[0].includes("async")?"async ":"";i[h]=`${v}${h}(${u[2]}) {${l.slice(g,R-1)}}`,m.lastIndex=R}}return i}function ur(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 Qn(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 p=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(p&&p.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 Zn(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 p;if(s.expressions===0&&s.directives.total===0)p="high";else if(s.expressions<5&&s.directives.total<3)p="medium";else p="low";let c=[];if(i>10)c.push("Consider optimizing template complexity");if(p==="low"&&s.directives.total>5)c.push("Reduce dynamic content for better caching");if(s.components===0&&s.lines>40)c.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(i*100)/100,complexityScore:s.complexity,cacheability:p,recommendations:c}}function Jt(t,s,i){let p=t.replace(/<!--[\s\S]*?-->/g,""),c=(p.match(new RegExp(`@${s}\\b`,"g"))||[]).length,l=(p.match(new RegExp(`@${i}\\b`,"g"))||[]).length;return Math.abs(c-l)}async function ro(t=["**/*.stx"],s){let i=[],p=[];for(let l of t){let m=await Array.fromAsync(new Bun.Glob(l).scan({cwd:s||process.cwd(),onlyFiles:!0,absolute:!0}));p.push(...m.filter((u)=>u.endsWith(".stx")))}for(let l of p)try{let m=await Gn(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),p=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,u=Math.max(1,Math.min(10,Math.round(10-m/2-p/2))),h=[];if(p>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(p*100)/100,totalIssues:c,issuesByCategory:l,performanceScore:u,recommendations:h}}import{mkdir as tr,readFile as nr,readdir as or,stat as Yt,writeFile as sr}from"fs/promises";import Pe 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 ir(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((s)=>s.charAt(0).toUpperCase()+s.slice(1)).join("")}function Ft(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function ar(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function cr(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function lr(t){let s=[];async function i(p){let c=await or(p,{withFileTypes:!0});c.sort((l,m)=>l.name.localeCompare(m.name));for(let l of c){let m=Pe.join(p,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 dr(t,s){let i=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!i)return{};let p=i[1].trim();if(!p)return{};try{return JSON.parse(p)}catch(c){throw Error(`${s}: <script component> must contain JSON metadata (${c.message})`)}}function pr(t,s){let i={},p=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let c of p){if(!/\bclient\b/i.test(c[1])||/\bcomponent\b|\bstx:component\b/i.test(c[1]))continue;let l;try{l=new Bun.Transpiler({loader:"ts"}).transformSync(c[2])}catch(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,u;while(u=m.exec(l)){let h=u[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=u[0].includes("async")?"async ":"";i[h]=`${v}${h}(${u[2]}) {${l.slice(g,R-1)}}`,m.lastIndex=R}}return i}function ur(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
- `)}function fr(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 mr(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 gr(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 xr(t){let s=[],i=0,p=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),c=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,l,m=(h)=>{if(p[h]!=="(")return null;let g=0,y="";for(let w=h;w<p.length;w++){let S=p[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:p.slice(h+1,w),end:w+1}}}return null},u=(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(p)){u(p.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 u(p.slice(i)),s.join(`
8
- `)}function bt(t,s,i,p){if(t[s]!==i)return-1;let c=0,l=null;for(let m=s;m<t.length;m++){let u=t[m];if(l){if(u==="\\"){m++;continue}if(u===l)l=null;continue}if(u==="'"||u==='"'||u==="`"){l=u;continue}if(u===i)c++;else if(u===p){if(p===">"&&t[m-1]==="=")continue;if(c--,c===0)return m+1}}return-1}function jt(t,s,i){let p=i?"([{<":"([{",c=i?")]}>":")]}",l=[],m=0,u=null,h="";for(let g=0;g<t.length;g++){let y=t[g];if(u){if(h+=y,y==="\\"){h+=t[++g]??"";continue}if(y===u)u=null;continue}if(y==="'"||y==='"'||y==="`"){u=y,h+=y;continue}if(p.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 vr(t){let s=0,i=null;for(let p=0;p<t.length;p++){let c=t[p];if(i){if(c==="\\"){p++;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[p-1];if(t[p+1]==="="||l==="="||l==="!"||l==="<"||l===">")continue;return p}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 wr(t){let s=/\bdefineProps\b/.exec(t);if(!s)return null;let i=/(?:^|[\s;{}()])(const|let|var)\s+/g,p=-1;for(let k=i.exec(t);k&&k.index<s.index;k=i.exec(t))p=k.index+k[0].indexOf(k[1]);if(p===-1)return null;let c={},l={},m=[],u=p+(/^(?:const|let|var)\s+/.exec(t.slice(p))?.[0].length??0),h=()=>{while(u<t.length&&/\s/.test(t[u]))u++},g;if(t[u]==="{"){let k=bt(t,u,"{","}");if(k===-1)return null;g=t.slice(u,k),u=k}else{let k=/^[A-Za-z_$][\w$]*/.exec(t.slice(u));if(!k)return null;g=k[0],u+=k[0].length}if(h(),t[u]!=="=")return null;u++,h();let y=/^withDefaults\s*\(\s*/.exec(t.slice(u)),w=Boolean(y);if(y)u+=y[0].length;let S=/^defineProps\b/.exec(t.slice(u));if(!S)return null;u+=S[0].length;let R="";if(h(),t[u]==="<"){let k=bt(t,u,"<",">");if(k===-1)return null;R=t.slice(u+1,k-1).trim(),u=k}if(h(),t[u]!=="(")return null;let v=bt(t,u,"(",")");if(v===-1)return null;let x=t.slice(u+1,v-1).trim();if(u=v,w){if(h(),t[u]===",")u++,h();if(t[u]==="{"){let k=bt(t,u,"{","}");if(k===-1)return null;for(let[B,D]of Ht(t.slice(u,k)))l[B]=D;u=k}if(h(),t[u]===",")u++,h();if(t[u]===")")u++}if(t[u]===";")u++;let C=/^[A-Za-z_$][\w$]*$/.test(R)?R:void 0;if(R.startsWith("{"))for(let k of jt(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 Ht(x)){if(m.push(k),!B.startsWith("{")){let D=Zt(B);if(D)c[k]=D;continue}for(let[D,j]of Ht(B))if(D==="default")l[k]=j;else if(D==="type"){let E=Zt(j);if(E)c[k]=E}}else if(x.startsWith("["))for(let k of jt(x.slice(1,-1),",",!1))m.push(k.replace(/^['"`]/,"").replace(/['"`]$/,""));if(g.startsWith("{")){m.length=0;for(let k of jt(g.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let B=vr(k),j=(B===-1?k:k.slice(0,B)).split(":")[0].trim().replace(/^\.\.\./,"");if(!j)continue;if(m.push(j),B!==-1)l[j]=k.slice(B+1).trim()}}else if(m.length===0)m.push(...Object.keys(c));return{text:t.slice(p,u),propNames:m,defaults:l,declared:c,typeName:C}}function Ht(t){let s=t.trim().replace(/^\{/,"").replace(/\}$/,""),i=[],p=0;while(p<s.length){let c=/\s*([A-Za-z_$][\w$]*)\s*:/y;c.lastIndex=p;let l=c.exec(s);if(!l)break;p=c.lastIndex;let m=0,u="",h=p;while(p<s.length){let y=s[p];if(u){if(y==="\\")p++;else if(y===u)u=""}else if(y==="'"||y==='"'||y==="`")u=y;else if(y==="{"||y==="["||y==="(")m++;else if(y==="}"||y==="]"||y===")")m--;else if(y===","&&m===0)break;p++}let g=s.slice(h,p).trim();if(g)i.push([l[1],g]);p++}return i}function Sr(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=[],u=[],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=Pe.resolve(Pe.dirname(s),x),B=Pe.relative(i,k);return`${v}${B.startsWith(".")?B:`./${B}`}${C}`})),""});let y=wr(l);if(y)u.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(!u.includes(S))u.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:u,defaults:h,declared:g}}function Tr(t){let s=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(p,c,l,m,u)=>{let h=c.toLowerCase();s.add(h);let g=(l||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${h}="${u}"${g?` data-stx-mod-${h}="${g}"`:""}`}),eventTypes:[...s].sort()}}function $r(t){let s=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(p,c,l,m)=>{let u=s.length;return s.push({id:u,name:c,expression:m}),` data-stx-bind-${u}=""`}),bindings:s}}function Rr(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 Er(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 Or(t,s,i){let p=Pe.isAbsolute(s.file)?s.file:Pe.resolve(t,s.file),c=await rr(p,"utf8"),l=dr(c,p),m=Pe.basename(p,".stx"),u=s.name||l.name||ir(m),h=`${Bt(i.prefix||"stx")}-${Bt(m)}`,g=s.tag||l.tag||h;if(!u||!/^[A-Za-z_$][\w$]*$/.test(u))throw Error(`${p}: invalid component class name "${u}"`);if(!ar(g))throw Error(`${p}: 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(([D,j])=>[D,en(D,j)])),S=Tr(ur(c)),R=$r(S.template),v=Sr(c,p,Pe.resolve(i.outputDir)),x=xr(R.template);for(let D of v.propNames){if(w[D])continue;let j=v.defaults[D];w[D]=en(D,{type:fr(v.declared[D])??mr(j),...j===void 0?{}:{default:gr(j)}})}let C=l.methods||{},k=s.methods||{},B=pr(c,p);return{file:Pe.relative(t,p),sourcePath:p,name:u,tag:g,description:s.description||l.description||"",template:R.template,styles:Qt(c),shadowMode:cr(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:Rr(R.template),cssProperties:Er(Qt(c)),scope:v,render:x}}function Ar(){let t=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),s=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}");return`const HTMLElementBase = globalThis.HTMLElement || class {};
7
+ `)}function fr(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 mr(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 gr(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 hr(t){let s=[],i=0,p=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),c=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,l,m=(h)=>{if(p[h]!=="(")return null;let g=0,y="";for(let w=h;w<p.length;w++){let S=p[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:p.slice(h+1,w),end:w+1}}}return null},u=(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(p)){u(p.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 u(p.slice(i)),s.join(`
8
+ `)}function bt(t,s,i,p){if(t[s]!==i)return-1;let c=0,l=null;for(let m=s;m<t.length;m++){let u=t[m];if(l){if(u==="\\"){m++;continue}if(u===l)l=null;continue}if(u==="'"||u==='"'||u==="`"){l=u;continue}if(u===i)c++;else if(u===p){if(p===">"&&t[m-1]==="=")continue;if(c--,c===0)return m+1}}return-1}function Ht(t,s,i){let p=i?"([{<":"([{",c=i?")]}>":")]}",l=[],m=0,u=null,h="";for(let g=0;g<t.length;g++){let y=t[g];if(u){if(h+=y,y==="\\"){h+=t[++g]??"";continue}if(y===u)u=null;continue}if(y==="'"||y==='"'||y==="`"){u=y,h+=y;continue}if(p.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 xr(t){let s=0,i=null;for(let p=0;p<t.length;p++){let c=t[p];if(i){if(c==="\\"){p++;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[p-1];if(t[p+1]==="="||l==="="||l==="!"||l==="<"||l===">")continue;return p}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 vr(t){let s=/\bdefineProps\b/.exec(t);if(!s)return null;let i=/(?:^|[\s;{}()])(const|let|var)\s+/g,p=-1;for(let k=i.exec(t);k&&k.index<s.index;k=i.exec(t))p=k.index+k[0].indexOf(k[1]);if(p===-1)return null;let c={},l={},m=[],u=p+(/^(?:const|let|var)\s+/.exec(t.slice(p))?.[0].length??0),h=()=>{while(u<t.length&&/\s/.test(t[u]))u++},g;if(t[u]==="{"){let k=bt(t,u,"{","}");if(k===-1)return null;g=t.slice(u,k),u=k}else{let k=/^[A-Za-z_$][\w$]*/.exec(t.slice(u));if(!k)return null;g=k[0],u+=k[0].length}if(h(),t[u]!=="=")return null;u++,h();let y=/^withDefaults\s*\(\s*/.exec(t.slice(u)),w=Boolean(y);if(y)u+=y[0].length;let S=/^defineProps\b/.exec(t.slice(u));if(!S)return null;u+=S[0].length;let R="";if(h(),t[u]==="<"){let k=bt(t,u,"<",">");if(k===-1)return null;R=t.slice(u+1,k-1).trim(),u=k}if(h(),t[u]!=="(")return null;let v=bt(t,u,"(",")");if(v===-1)return null;let x=t.slice(u+1,v-1).trim();if(u=v,w){if(h(),t[u]===",")u++,h();if(t[u]==="{"){let k=bt(t,u,"{","}");if(k===-1)return null;for(let[B,D]of Bt(t.slice(u,k)))l[B]=D;u=k}if(h(),t[u]===",")u++,h();if(t[u]===")")u++}if(t[u]===";")u++;let C=/^[A-Za-z_$][\w$]*$/.test(R)?R:void 0;if(R.startsWith("{"))for(let k of Ht(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 Bt(x)){if(m.push(k),!B.startsWith("{")){let D=Zt(B);if(D)c[k]=D;continue}for(let[D,j]of Bt(B))if(D==="default")l[k]=j;else if(D==="type"){let E=Zt(j);if(E)c[k]=E}}else if(x.startsWith("["))for(let k of Ht(x.slice(1,-1),",",!1))m.push(k.replace(/^['"`]/,"").replace(/['"`]$/,""));if(g.startsWith("{")){m.length=0;for(let k of Ht(g.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let B=xr(k),j=(B===-1?k:k.slice(0,B)).split(":")[0].trim().replace(/^\.\.\./,"");if(!j)continue;if(m.push(j),B!==-1)l[j]=k.slice(B+1).trim()}}else if(m.length===0)m.push(...Object.keys(c));return{text:t.slice(p,u),propNames:m,defaults:l,declared:c,typeName:C}}function Bt(t){let s=t.trim().replace(/^\{/,"").replace(/\}$/,""),i=[],p=0;while(p<s.length){let c=/\s*([A-Za-z_$][\w$]*)\s*:/y;c.lastIndex=p;let l=c.exec(s);if(!l)break;p=c.lastIndex;let m=0,u="",h=p;while(p<s.length){let y=s[p];if(u){if(y==="\\")p++;else if(y===u)u=""}else if(y==="'"||y==='"'||y==="`")u=y;else if(y==="{"||y==="["||y==="(")m++;else if(y==="}"||y==="]"||y===")")m--;else if(y===","&&m===0)break;p++}let g=s.slice(h,p).trim();if(g)i.push([l[1],g]);p++}return i}function Sr(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=[],u=[],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=Pe.resolve(Pe.dirname(s),x),B=Pe.relative(i,k);return`${v}${B.startsWith(".")?B:`./${B}`}${C}`})),""});let y=vr(l);if(y)u.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(!u.includes(S))u.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:u,defaults:h,declared:g}}function kr(t){let s=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(p,c,l,m,u)=>{let h=c.toLowerCase();s.add(h);let g=(l||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${h}="${u}"${g?` data-stx-mod-${h}="${g}"`:""}`}),eventTypes:[...s].sort()}}function Tr(t){let s=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(p,c,l,m)=>{let u=s.length;return s.push({id:u,name:c,expression:m}),` data-stx-bind-${u}=""`}),bindings:s}}function $r(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 Rr(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 Pr(t,s,i){let p=Pe.isAbsolute(s.file)?s.file:Pe.resolve(t,s.file),c=await nr(p,"utf8"),l=dr(c,p),m=Pe.basename(p,".stx"),u=s.name||l.name||ir(m),h=`${Ft(i.prefix||"stx")}-${Ft(m)}`,g=s.tag||l.tag||h;if(!u||!/^[A-Za-z_$][\w$]*$/.test(u))throw Error(`${p}: invalid component class name "${u}"`);if(!ar(g))throw Error(`${p}: 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(([D,j])=>[D,en(D,j)])),S=kr(ur(c)),R=Tr(S.template),v=Sr(c,p,Pe.resolve(i.outputDir)),x=hr(R.template);for(let D of v.propNames){if(w[D])continue;let j=v.defaults[D];w[D]=en(D,{type:fr(v.declared[D])??mr(j),...j===void 0?{}:{default:gr(j)}})}let C=l.methods||{},k=s.methods||{},B=pr(c,p);return{file:Pe.relative(t,p),sourcePath:p,name:u,tag:g,description:s.description||l.description||"",template:R.template,styles:Qt(c),shadowMode:cr(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:$r(R.template),cssProperties:Rr(Qt(c)),scope:v,render:x}}function Or(){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;')
@@ -303,7 +303,7 @@ export function defineComponent(Component, definition) {
303
303
  }
304
304
  return Component;
305
305
  }
306
- `}function Dr(t){let s=JSON.stringify({tag:t.tag,template:t.template,styles:t.styles,shadowMode:t.shadowMode,progressive:t.progressive,properties:t.properties,eventTypes:t.eventTypes,bindings:t.bindings},null,2),i=Object.entries(t.methods).map(([u,h])=>{if(on.has(u))throw Error(`${t.sourcePath}: ${rn(u)}`);if(/^(?:async\s+)?[A-Za-z_$][\w$]*\s*\(/.test(h.trim()))return` ${h.trim()}`;return` ${u}($event) {
306
+ `}function Ar(t){let s=JSON.stringify({tag:t.tag,template:t.template,styles:t.styles,shadowMode:t.shadowMode,progressive:t.progressive,properties:t.properties,eventTypes:t.eventTypes,bindings:t.bindings},null,2),i=Object.entries(t.methods).map(([u,h])=>{if(on.has(u))throw Error(`${t.sourcePath}: ${rn(u)}`);if(/^(?:async\s+)?[A-Za-z_$][\w$]*\s*\(/.test(h.trim()))return` ${h.trim()}`;return` ${u}($event) {
307
307
  ${h}
308
308
  }`}).join(`
309
309
 
@@ -328,7 +328,7 @@ ${i}${m}
328
328
 
329
329
  defineComponent(${t.name}, ${s});
330
330
  export default ${t.name};
331
- `}function xt(t){switch(t.type){case"boolean":return"boolean";case"number":return"number";case"array":return"unknown[]";case"object":return"Record<string, unknown>";default:return"string"}}function Mr(t){let s=Object.entries(t.properties).map(([l,m])=>` ${l}${m.required?"":"?"}: ${xt(m)}`).join(`
331
+ `}function xt(t){switch(t.type){case"boolean":return"boolean";case"number":return"number";case"array":return"unknown[]";case"object":return"Record<string, unknown>";default:return"string"}}function Dr(t){let s=Object.entries(t.properties).map(([l,m])=>` ${l}${m.required?"":"?"}: ${xt(m)}`).join(`
332
332
  `),i=Object.entries(t.properties).map(([l,m])=>` ${l}: ${xt(m)}`).join(`
333
333
  `),p=Object.entries(t.events).map(([l,m])=>` ${JSON.stringify(l)}: CustomEvent<${m.detailType||"unknown"}>`).join(`
334
334
  `),c=Object.keys(t.methods).map((l)=>` ${l}($event?: Event): unknown`).join(`
@@ -355,7 +355,7 @@ declare global {
355
355
  }
356
356
 
357
357
  export default ${t.name}
358
- `}function Lr(t){return`declare global {
358
+ `}function Mr(t){return`declare global {
359
359
  namespace JSX {
360
360
  interface IntrinsicElements {
361
361
  ${t.map((i)=>{let p=Object.entries(i.properties).map(([l,m])=>` ${JSON.stringify(l)}?: ${xt(m)}`).join(`
@@ -374,7 +374,7 @@ ${c}
374
374
  }
375
375
 
376
376
  export {}
377
- `}function Ir(t){return{schemaVersion:"1.0.0",modules:t.map((s)=>({kind:"javascript-module",path:`./${s.tag}.js`,declarations:[{kind:"class",name:s.name,description:s.description||void 0,customElement:!0,tagName:s.tag,members:Object.entries(s.properties).map(([i,p])=>({kind:"field",name:i,description:p.description,type:{text:xt(p)},default:p.default===void 0?void 0:JSON.stringify(p.default),attribute:p.attribute===!1?void 0:p.attribute||Bt(i),reflects:p.reflect})),events:Object.entries(s.events).map(([i,p])=>({name:i,description:p.description,type:{text:`CustomEvent<${p.detailType||"unknown"}>`}})),slots:s.slots,cssProperties:s.cssProperties}],exports:[{kind:"js",name:s.name,declaration:{name:s.name,module:`./${s.tag}.js`}}]}))}}function tn(t){if(!t.styles)return"";let s=t.styles.replace(/:host\b/g,":scope");if(/\@scope\s*\(/.test(s))return s;return`@scope (${t.tag}) {
377
+ `}function Lr(t){return{schemaVersion:"1.0.0",modules:t.map((s)=>({kind:"javascript-module",path:`./${s.tag}.js`,declarations:[{kind:"class",name:s.name,description:s.description||void 0,customElement:!0,tagName:s.tag,members:Object.entries(s.properties).map(([i,p])=>({kind:"field",name:i,description:p.description,type:{text:xt(p)},default:p.default===void 0?void 0:JSON.stringify(p.default),attribute:p.attribute===!1?void 0:p.attribute||Ft(i),reflects:p.reflect})),events:Object.entries(s.events).map(([i,p])=>({name:i,description:p.description,type:{text:`CustomEvent<${p.detailType||"unknown"}>`}})),slots:s.slots,cssProperties:s.cssProperties}],exports:[{kind:"js",name:s.name,declaration:{name:s.name,module:`./${s.tag}.js`}}]}))}}function tn(t){if(!t.styles)return"";let s=t.styles.replace(/:host\b/g,":scope");if(/\@scope\s*\(/.test(s))return s;return`@scope (${t.tag}) {
378
378
  ${s}
379
379
  }`}function nn(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").replace(/\s*([{}:;,])\s*/g,"$1").replace(/;}/g,"}").trim()}function jr(t){let s=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),i=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}"),p=JSON.stringify('<slot(?:\\s+name=["\\\']([^"\\\']+)["\\\'])?\\s*\\/?>(?:<\\/slot>)?'),c=Object.fromEntries(t.map((m)=>[m.tag,{template:m.template,styles:m.styles,shadowMode:m.shadowMode,properties:m.properties}])),l=t.map((m)=>`export const render${m.name} = (props = {}, slots = {}) => renderComponent('${m.tag}', props, slots);`).join(`
380
380
  `);return`const definitions = ${JSON.stringify(c,null,2)};
@@ -410,21 +410,21 @@ export function renderComponent(tag, props = {}, slots = {}) {
410
410
  }
411
411
 
412
412
  ${l}
413
- `}async function no(t){let s=Pe.resolve(t.inputDir),i=Pe.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 lr(s)).map((x)=>({file:x}));if(!c.length)throw Error(`No .stx components found in ${s}`);let l=await Promise.all(c.map((x)=>Or(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 u=l.filter((x,C)=>l.findIndex((k)=>k.name===x.name)!==C);if(u.length)throw Error(`Duplicate component class name: ${u[0].name}`);await tr(i,{recursive:!0});let h=[],g=async(x,C)=>{let k=Pe.join(i,x);return await sr(k,C.endsWith(`
413
+ `}async function so(t){let s=Pe.resolve(t.inputDir),i=Pe.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 lr(s)).map((x)=>({file:x}));if(!c.length)throw Error(`No .stx components found in ${s}`);let l=await Promise.all(c.map((x)=>Pr(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 u=l.filter((x,C)=>l.findIndex((k)=>k.name===x.name)!==C);if(u.length)throw Error(`Duplicate component class name: ${u[0].name}`);await tr(i,{recursive:!0});let h=[],g=async(x,C)=>{let k=Pe.join(i,x);return await sr(k,C.endsWith(`
414
414
  `)?C:`${C}
415
- `,"utf8"),h.push(k),k};await g("runtime.js",Ar());for(let x of l){if(await g(`${x.tag}.js`,Dr(x)),t.declarations!==!1)await g(`${x.tag}.d.ts`,Mr(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(`
415
+ `,"utf8"),h.push(k),k};await g("runtime.js",Or());for(let x of l){if(await g(`${x.tag}.js`,Ar(x)),t.declarations!==!1)await g(`${x.tag}.d.ts`,Dr(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",jr(l)),t.declarations!==!1)await g("index.d.ts",l.map((x)=>`export * from './${x.tag}.js'`).join(`
417
- `)),await g("custom-elements.d.ts",Lr(l)),await g("ssr.d.ts",`${l.map((x)=>`export declare const render${x.name}: (props?: ${x.name}Props, slots?: Record<string, string>) => string`).join(`
417
+ `)),await g("custom-elements.d.ts",Mr(l)),await g("ssr.d.ts",`${l.map((x)=>`export declare const render${x.name}: (props?: ${x.name}Props, slots?: Record<string, string>) => string`).join(`
418
418
  `)}
419
419
  export declare function renderComponent(tag: string, props?: Record<string, unknown>, slots?: Record<string, string>): string
420
420
  ${l.map((x)=>`import type { ${x.name}Props } from './${x.tag}.js'`).join(`
421
- `)}`);let w;if(t.manifest!==!1)w=await g("custom-elements.json",JSON.stringify(Ir(l),null,2));let S;if(t.css!==!1){let x=l.filter((C)=>!C.shadowMode&&C.styles).map(tn).join(`
421
+ `)}`);let w;if(t.manifest!==!1)w=await g("custom-elements.json",JSON.stringify(Lr(l),null,2));let S;if(t.css!==!1){let x=l.filter((C)=>!C.shadowMode&&C.styles).map(tn).join(`
422
422
 
423
423
  `);if(x)S=await g("bundle.css",t.minify?nn(x):x)}let R;if(t.bundle!==!1){R=Pe.join(i,"bundle.js");let x;try{x=await Bun.build({entrypoints:[Pe.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((D)=>String(D).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:Pe.join(i,`${x.tag}.js`)})),files:h,manifest:w,bundle:R,cssBundle:S,totalBytes:v.reduce((x,C)=>x+C,0)}}var{serve:qr}=globalThis.Bun;import zt from"fs";import pt 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:Pe.join(i,`${x.tag}.js`)})),files:h,manifest:w,bundle:R,cssBundle:S,totalBytes:v.reduce((x,C)=>x+C,0)}}var{serve:qr}=globalThis.Bun;import Nt from"fs";import pt from"path";function vt(){return`
428
428
  /* Theme selector for code blocks */
429
429
  .theme-selector {
430
430
  margin: 1rem 0;
@@ -504,12 +504,12 @@ 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 Hr(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 Br(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 Fr(t){if(!await Hr(t))return!1;return await Br(t)}async function Ye(t,s=20){t=Number(t);for(let i=0;i<s;i++){let p=t+i;if(await Fr(p))return p}throw Error(`Could not find an available port between ${t} and ${t+s-1}`)}var zr={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function Nr(){try{let t=await import("./chunk-74j18qk0.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function dt(t,s={}){let i={...zr,...s},p=await Nr();if(!p)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 p.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 Ct(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 Hr(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 Br(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 Fr(t){if(!await Hr(t))return!1;return await Br(t)}async function Ye(t,s=20){t=Number(t);for(let i=0;i<s;i++){let p=t+i;if(await Fr(p))return p}throw Error(`Could not find an available port between ${t} and ${t+s-1}`)}var zr={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function Nr(){try{let t=await import("./chunk-74j18qk0.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function dt(t,s={}){let i={...zr,...s},p=await Nr();if(!p)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 p.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
- `,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 p=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(p)try{let c=p[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 Ft(){console.log(`
511
- Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in browser`),console.log(` ${e.cyan}c${e.reset} + Enter - Clear console`),console.log(` ${e.cyan}q${e.reset} + Enter (or ${e.cyan}Ctrl+C${e.reset}) - Quit server`),console.log(` ${e.cyan}h${e.reset} + Enter - Show this help`)}function Ur(t){console.log(`${e.green}Server running at ${e.cyan}${t}${e.reset}`),console.log(`Press ${e.cyan}Ctrl+C${e.reset} to stop the server`),Ft()}function Wr(t){console.log(`${e.dim}Opening ${e.cyan}${t}${e.dim} in your browser...${e.reset}`),Bun.spawn(["open",t],{stderr:"inherit"})}function Qe(t,s,i){if(!process.stdin.isTTY)return;process.stdin.setRawMode(!0),process.stdin.setEncoding("utf8"),process.stdin.resume(),Ft();let p="";process.stdin.on("data",(c)=>{if(c==="\x03"){if(i?.onQuit)i.onQuit();s(),process.exit(0)}if(p+=c,p.endsWith("\r")||p.endsWith(`
512
- `)){let l=p.trim().toLowerCase();p="",Vr(l,t,s,i)}})}function Vr(t,s,i,p){switch(t){case"o":if(p?.onOpen)p.onOpen();else Wr(s);break;case"c":if(p?.onClear)p.onClear();else console.clear(),Ur(s);break;case"q":if(p?.onQuit)p.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),i(),process.exit(0);break;case"h":if(p?.onHelp)p.onHelp();else Ft();break;default:break}}async function Ut(t,s={}){let i=s.port||3000,p=s.watch!==!1,c=pt.resolve(t);if(!zt.existsSync(c))return console.error(`${e.red}Error: File not found: ${e.bright}${c}${e.reset}`),!1;if(!c.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${c}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${t}${e.reset}...`);let l=null,m=async()=>{try{let{content:w,data:S}=await pe(c,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),R=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,v=R?.defaultTheme||"github-dark",x=["github-dark"],C=R?.additionalThemes||[],B=[...new Set([...x,...C])].map((D)=>`<option value="${D}"${D===v?" selected":""}>${D}</option>`).join(`
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 p=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(p)try{let c=p[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 zt(){console.log(`
511
+ Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in browser`),console.log(` ${e.cyan}c${e.reset} + Enter - Clear console`),console.log(` ${e.cyan}q${e.reset} + Enter (or ${e.cyan}Ctrl+C${e.reset}) - Quit server`),console.log(` ${e.cyan}h${e.reset} + Enter - Show this help`)}function Ur(t){console.log(`${e.green}Server running at ${e.cyan}${t}${e.reset}`),console.log(`Press ${e.cyan}Ctrl+C${e.reset} to stop the server`),zt()}function Wr(t){console.log(`${e.dim}Opening ${e.cyan}${t}${e.dim} in your browser...${e.reset}`),Bun.spawn(["open",t],{stderr:"inherit"})}function Qe(t,s,i){if(!process.stdin.isTTY)return;process.stdin.setRawMode(!0),process.stdin.setEncoding("utf8"),process.stdin.resume(),zt();let p="";process.stdin.on("data",(c)=>{if(c==="\x03"){if(i?.onQuit)i.onQuit();s(),process.exit(0)}if(p+=c,p.endsWith("\r")||p.endsWith(`
512
+ `)){let l=p.trim().toLowerCase();p="",Vr(l,t,s,i)}})}function Vr(t,s,i,p){switch(t){case"o":if(p?.onOpen)p.onOpen();else Wr(s);break;case"c":if(p?.onClear)p.onClear();else console.clear(),Ur(s);break;case"q":if(p?.onQuit)p.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),i(),process.exit(0);break;case"h":if(p?.onHelp)p.onHelp();else zt();break;default:break}}async function Ut(t,s={}){let i=s.port||3000,p=s.watch!==!1,c=pt.resolve(t);if(!Nt.existsSync(c))return console.error(`${e.red}Error: File not found: ${e.bright}${c}${e.reset}`),!1;if(!c.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${c}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${t}${e.reset}...`);let l=null,m=async()=>{try{let{content:w,data:S}=await pe(c,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),R=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,v=R?.defaultTheme||"github-dark",x=["github-dark"],C=R?.additionalThemes||[],B=[...new Set([...x,...C])].map((D)=>`<option value="${D}"${D===v?" selected":""}>${D}</option>`).join(`
513
513
  `);return l=`
514
514
  <!DOCTYPE html>
515
515
  <html lang="en">
@@ -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=pt.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`),Qe(g.url.toString(),()=>{if(p)zt.watch(pt.dirname(c),{recursive:!0}).close();g.stop()}),s.native)await dt(h,{title:pt.basename(c,".md")});if(p){let w=pt.dirname(c);console.log(`${e.blue}Watching ${e.bright}${w}${e.reset} for changes...`);let S=zt.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 Kr(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Gr}=globalThis.Bun;import Fe from"fs";import Se 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 p=0;p<i;p++)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 u=JSON.parse(m);if(u.type==="console"&&Array.isArray(u.args)){let h=u.args.join(" "),y={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[u.level]??"\x1B[36m";console.log(`${y}[browser]${u.level!=="log"?` ${u.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 p of this.clients)try{if(p.readyState===1)p.send(s),i++}catch{this.clients.delete(p)}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 Xr(t,s={}){let{showOverlay:i=!0,reconnectInterval:p=1000,maxReconnectAttempts:c=10}=s;return`
680
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(g.url.toString(),()=>{if(p)Nt.watch(pt.dirname(c),{recursive:!0}).close();g.stop()}),s.native)await dt(h,{title:pt.basename(c,".md")});if(p){let w=pt.dirname(c);console.log(`${e.blue}Watching ${e.bright}${w}${e.reset} for changes...`);let S=Nt.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 Kr(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Gr}=globalThis.Bun;import Fe from"fs";import Se 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 p=0;p<i;p++)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 u=JSON.parse(m);if(u.type==="console"&&Array.isArray(u.args)){let h=u.args.join(" "),y={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[u.level]??"\x1B[36m";console.log(`${y}[browser]${u.level!=="log"?` ${u.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 p of this.clients)try{if(p.readyState===1)p.send(s),i++}catch{this.clients.delete(p)}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 Xr(t,s={}){let{showOverlay:i=!0,reconnectInterval:p=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 Xe(t,s,i={}){let p=Xr(s,i),c=t.lastIndexOf("</body>");if(c!==-1)return t.slice(0,c)+p+t.slice(c);if(t.includes("</html>"))return t.replace("</html>",`${p}</html>`);return t+p}function Rt(t){let s=t.toLowerCase();return s.endsWith(".css")||s.endsWith(".scss")||s.endsWith(".sass")||s.endsWith(".less")}function Et(t){let s=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((p)=>s.endsWith(p))}function Pt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((i)=>i.test(t))}var ut=null;function At(t){if(!ut)ut=new an(t);return ut}function ht(){if(ut)ut.stop(),ut=null}import Dt from"path";var ft={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},p=new Set,c=i.webComponents?.enabled?`./${Dt.relative(Dt.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let m=await nr(i,p);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 u=new Set;if(i.cache&&i.cachePath){let x=await ln(m,i);if(x){if(i.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let h=await re(()=>Bun.file(m).text(),"",(x)=>{throw new kn(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!h)throw new kn(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:y,allScripts:w}=G.time("script-extraction",()=>{let x=h,C=te(h);if(C)x=C.content.trim();let k=h.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],B="",D=[];for(let E of k){let _=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",F=E.match(/<script\b([^>]*)>/i),q=F?F[1]:"";if(/\bserver\b/i.test(q))B=_;else D.push(E)}let j=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:B,templateContent:j,allScripts:D}}),S={__filename:m,__dirname:Dt.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await re(()=>d(g,S,m),void 0,(x)=>{let C=new Y(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(I.log(C,{filePath:m,scriptContent:g}),i.debug)throw C});let v=await G.timeAsync("directive-processing",async()=>await n(y,S,m,i,u));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-j83ax407.js"),C=x(w.join(`
879
+ `}function Xe(t,s,i={}){let p=Xr(s,i),c=t.lastIndexOf("</body>");if(c!==-1)return t.slice(0,c)+p+t.slice(c);if(t.includes("</html>"))return t.replace("</html>",`${p}</html>`);return t+p}function Ct(t){let s=t.toLowerCase();return s.endsWith(".css")||s.endsWith(".scss")||s.endsWith(".sass")||s.endsWith(".less")}function Et(t){let s=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((p)=>s.endsWith(p))}function Pt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((i)=>i.test(t))}var ut=null;function Ot(t){if(!ut)ut=new an(t);return ut}function ht(){if(ut)ut.stop(),ut=null}import At from"path";var ft={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},p=new Set,c=i.webComponents?.enabled?`./${At.relative(At.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let m=await rr(i,p);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 u=new Set;if(i.cache&&i.cachePath){let x=await dn(m,i);if(x){if(i.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let h=await re(()=>Bun.file(m).text(),"",(x)=>{throw new Cn(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!h)throw new Cn(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:y,allScripts:w}=G.time("script-extraction",()=>{let x=h,C=te(h);if(C)x=C.content.trim();let k=h.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],B="",D=[];for(let E of k){let _=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",F=E.match(/<script\b([^>]*)>/i),q=F?F[1]:"";if(/\bserver\b/i.test(q))B=_;else D.push(E)}let j=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:B,templateContent:j,allScripts:D}}),S={__filename:m,__dirname:At.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await re(()=>d(g,S,m),void 0,(x)=>{let C=new Y(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(I.log(C,{filePath:m,scriptContent:g}),i.debug)throw C});let v=await G.timeAsync("directive-processing",async()=>await n(y,S,m,i,u));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-mqy7g74k.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 J(v),u.forEach((x)=>p.add(x)),i.cache&&i.cachePath){if(await dn(m,v,u,i),i.debug)console.log(`Cached template ${m} with ${u.size} dependencies`)}return{contents:v,loader:"html"}}catch(u){let h=u instanceof Error?u:new Y(`Plugin processing failed: ${String(u)}`,m);if(I.log(h,{filePath:m,buildConfig:t.config}),Ot.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||M()?`<!DOCTYPE html>
882
+ ${C}`}if(v=await J(v),u.forEach((x)=>p.add(x)),i.cache&&i.cachePath){if(await un(m,v,u,i),i.debug)console.log(`Cached template ${m} with ${u.size} dependencies`)}return{contents:v,loader:"html"}}catch(u){let h=u instanceof Error?u:new Y(`Plugin processing failed: ${String(u)}`,m);if(I.log(h,{filePath:m,buildConfig:t.config}),Dt.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||M()?`<!DOCTYPE html>
883
883
  <html lang="en">
884
884
  <head>
885
885
  <meta charset="UTF-8">
@@ -920,7 +920,7 @@ ${C}`}if(v=await J(v),u.forEach((x)=>p.add(x)),i.cache&&i.cachePath){if(await dn
920
920
  <li>Check the syntax of your stx directives (e.g., @if, @foreach)</li>
921
921
  <li>Verify that all variables used in the template are properly defined</li>
922
922
  <li>Ensure script tags have valid JavaScript/TypeScript syntax</li>
923
- <li>Run <code>stx debug ${b(Dt.basename(m))}</code> for detailed analysis</li>
923
+ <li>Run <code>stx debug ${b(At.basename(m))}</code> for detailed analysis</li>
924
924
  <li>Enable debug mode in your stx config for more detailed error messages</li>
925
925
  </ul>
926
926
  </div>
@@ -939,12 +939,12 @@ ${C}`}if(v=await J(v),u.forEach((x)=>p.add(x)),i.cache&&i.cachePath){if(await dn
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 Pn(t,s={}){let i=s.port||3000,p=s.watch!==!1,c=s.hotReload!==!1&&p,l=null,m=s.hmrPort||i+1,u=Se.resolve(t);if(!Fe.existsSync(u))return console.error(`${e.red}Error: File not found: ${e.bright}${u}${e.reset}`),!1;if(u.endsWith(".md"))return Ut(u,s);else if(!u.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${u}${e.reset}. Only .stx and .md files are supported.`),!1;let h=a(process.cwd(),"output");Fe.mkdirSync(h,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,y=async()=>{try{let _={name:"public-assets",setup($e){$e.onResolve({filter:/^\/(images|fonts|assets|public)\//},(he)=>({path:he.path,external:!0}))}},F=await Bun.build({entrypoints:[u],outdir:h,plugins:[_,ft],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 q=F.outputs.find(($e)=>$e.path.endsWith(".html"));if(!q)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(q.path).text(),!0}catch(_){return console.error(`${e.red}Error building stx file:${e.reset}`,_),!1}};if(!await y())return!1;let S=Se.dirname(u);await Tt(S);let R=i;try{if(R=await Ye(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 _=s.hmrPort||R+1;l=At({wsPort:_,verbose:!1}),m=l.start(_)}let v={},x=null,C;try{let{loadStxConfig:_}=await import("./chunk-3bj1w990.js"),F=await _();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 q=Object.keys(v).length;if(q>0)console.log(`${e.blue}Loaded ${e.bright}${q} API route${q>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:q,loadChannels:Z}=await import("./chunk-ensp20xk.js"),$e=F.broadcasting;await q($e);let he=$e.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${he}/ws${e.reset}`);let De=Se.join(process.cwd(),"channels.ts");if(Fe.existsSync(De))try{let ae=await Z(De);console.log(`${e.blue}Loaded ${e.bright}${ae} broadcast channel${ae!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ae){console.warn(`${e.yellow}Failed to load channels.ts: ${ae.message}${e.reset}`)}}catch(q){console.warn(`${e.yellow}Broadcasting failed to start: ${q.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:B}=await import("./chunk-nr07vxm2.js"),D=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 j=Gr({port:R,async fetch(_){return Nt(_,await(async()=>{let F=new URL(_.url);if([h,Se.dirname(u),Se.join(process.cwd(),"public")].some((ae)=>B(Se.join(ae,F.pathname),process.cwd(),C)))return new Response("Not Found",{status:404});if(x)try{let ae=await x.handleRequest(_);if(ae.status!==404)return ae}catch{}if(v[F.pathname])try{return await v[F.pathname](_)}catch(ae){return new Response(JSON.stringify({error:ae.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await D(_);if(q)return q;if(F.pathname==="/")return(async()=>{let U=await f(g||"");if(c)U=Xe(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=Se.join(h,F.pathname);if(Fe.existsSync(Z)&&Fe.statSync(Z).isFile()){let ae=Bun.file(Z),U=Se.extname(Z).toLowerCase(),H="text/plain";if(U===".ts"||U===".tsx"){let ze=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),qe=await ae.text(),tt=ze.transformSync(qe);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(ae,{headers:{"Content-Type":H}})}let $e=Se.dirname(u),he=Se.join($e,F.pathname);if(Fe.existsSync(he)&&Fe.statSync(he).isFile()){let ae=Bun.file(he),U=Se.extname(he).toLowerCase(),H="text/plain";if(U===".ts"||U===".tsx"){let ze=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),qe=await ae.text(),tt=ze.transformSync(qe);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(ae,{headers:{"Content-Type":H}})}let De=Se.join(process.cwd(),"public",F.pathname);if(Fe.existsSync(De)&&Fe.statSync(De).isFile()){let ae=Bun.file(De),U=Se.extname(De).toLowerCase(),H="application/octet-stream";if(U===".ts"||U===".tsx"){let ze=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),qe=await ae.text(),tt=ze.transformSync(qe);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(ae,{headers:{"Content-Type":H}})}return new Response("Not Found",{status:404})})())},error(_){return new Response(`<pre>${_}
942
+ </html>`,loader:"html"}}})}};async function In(t,s={}){let i=s.port||3000,p=s.watch!==!1,c=s.hotReload!==!1&&p,l=null,m=s.hmrPort||i+1,u=Se.resolve(t);if(!Fe.existsSync(u))return console.error(`${e.red}Error: File not found: ${e.bright}${u}${e.reset}`),!1;if(u.endsWith(".md"))return Ut(u,s);else if(!u.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${u}${e.reset}. Only .stx and .md files are supported.`),!1;let h=a(process.cwd(),"output");Fe.mkdirSync(h,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,y=async()=>{try{let _={name:"public-assets",setup($e){$e.onResolve({filter:/^\/(images|fonts|assets|public)\//},(he)=>({path:he.path,external:!0}))}},F=await Bun.build({entrypoints:[u],outdir:h,plugins:[_,ft],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 q=F.outputs.find(($e)=>$e.path.endsWith(".html"));if(!q)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(q.path).text(),!0}catch(_){return console.error(`${e.red}Error building stx file:${e.reset}`,_),!1}};if(!await y())return!1;let S=Se.dirname(u);await $t(S);let R=i;try{if(R=await Ye(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 _=s.hmrPort||R+1;l=Ot({wsPort:_,verbose:!1}),m=l.start(_)}let v={},x=null,C;try{let{loadStxConfig:_}=await import("./chunk-yv5rwthv.js"),F=await _();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 q=Object.keys(v).length;if(q>0)console.log(`${e.blue}Loaded ${e.bright}${q} API route${q>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:q,loadChannels:Z}=await import("./chunk-hcgm37dy.js"),$e=F.broadcasting;await q($e);let he=$e.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${he}/ws${e.reset}`);let De=Se.join(process.cwd(),"channels.ts");if(Fe.existsSync(De))try{let ae=await Z(De);console.log(`${e.blue}Loaded ${e.bright}${ae} broadcast channel${ae!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ae){console.warn(`${e.yellow}Failed to load channels.ts: ${ae.message}${e.reset}`)}}catch(q){console.warn(`${e.yellow}Broadcasting failed to start: ${q.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:B}=await import("./chunk-vq0cb1m9.js"),D=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 j=Gr({port:R,async fetch(_){return Lt(_,await(async()=>{let F=new URL(_.url);if([h,Se.dirname(u),Se.join(process.cwd(),"public")].some((ae)=>B(Se.join(ae,F.pathname),process.cwd(),C)))return new Response("Not Found",{status:404});if(x)try{let ae=await x.handleRequest(_);if(ae.status!==404)return ae}catch{}if(v[F.pathname])try{return await v[F.pathname](_)}catch(ae){return new Response(JSON.stringify({error:ae.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await D(_);if(q)return q;if(F.pathname==="/")return(async()=>{let U=await f(g||"");if(c)U=Xe(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=Se.join(h,F.pathname);if(Fe.existsSync(Z)&&Fe.statSync(Z).isFile()){let ae=Bun.file(Z),U=Se.extname(Z).toLowerCase(),H="text/plain";if(U===".ts"||U===".tsx"){let ze=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),qe=await ae.text(),tt=ze.transformSync(qe);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(ae,{headers:{"Content-Type":H}})}let $e=Se.dirname(u),he=Se.join($e,F.pathname);if(Fe.existsSync(he)&&Fe.statSync(he).isFile()){let ae=Bun.file(he),U=Se.extname(he).toLowerCase(),H="text/plain";if(U===".ts"||U===".tsx"){let ze=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),qe=await ae.text(),tt=ze.transformSync(qe);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(ae,{headers:{"Content-Type":H}})}let De=Se.join(process.cwd(),"public",F.pathname);if(Fe.existsSync(De)&&Fe.statSync(De).isFile()){let ae=Bun.file(De),U=Se.extname(De).toLowerCase(),H="application/octet-stream";if(U===".ts"||U===".tsx"){let ze=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),qe=await ae.text(),tt=ze.transformSync(qe);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(ae,{headers:{"Content-Type":H}})}return new Response("Not Found",{status:404})})())},error(_){return new Response(`<pre>${_}
943
943
  ${_.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
944
944
  ${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
945
945
  ${e.bright}\u2192 ${e.cyan}http://localhost:${R}/${e.reset}`),console.log(`
946
946
  ${e.yellow}Routes:${e.reset}`);let E=Se.relative(process.cwd(),u);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`),Qe(j.url.toString(),()=>{if(p)Fe.watch(Se.dirname(u),{recursive:!0}).close();j.stop()}),s.native){let _=await Bun.file(u).text(),F=Ct(_);await dt(R,{title:Se.basename(u,".stx"),titlebarHidden:s.titlebarHidden===!0,nativeSidebar:!!F,sidebarConfig:F})}if(p){let _=Se.dirname(u);console.log(`${e.blue}Watching ${e.bright}${_}${e.reset} for changes...`);let F=Fe.watch(_,{recursive:!0},async(q,Z)=>{if(!Z||Pt(Z))return;if(Et(Z)){console.log(`${e.yellow}File ${e.bright}${Z}${e.yellow} changed, rebuilding...${e.reset}`),xe.clear(),ne();let $e=await y();if(await un(S),c&&l)if($e)l.reload(Z);else l.error("Build failed - check console for details")}else if(Rt(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)ht();j.stop(),process.exit(0)})}return!0}var{serve:Jr}=globalThis.Bun;import Ze from"fs";import Ae from"path";var cn=`
947
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(j.url.toString(),()=>{if(p)Fe.watch(Se.dirname(u),{recursive:!0}).close();j.stop()}),s.native){let _=await Bun.file(u).text(),F=Tt(_);await dt(R,{title:Se.basename(u,".stx"),titlebarHidden:s.titlebarHidden===!0,nativeSidebar:!!F,sidebarConfig:F})}if(p){let _=Se.dirname(u);console.log(`${e.blue}Watching ${e.bright}${_}${e.reset} for changes...`);let F=Fe.watch(_,{recursive:!0},async(q,Z)=>{if(!Z||Pt(Z))return;if(Et(Z)){console.log(`${e.yellow}File ${e.bright}${Z}${e.yellow} changed, rebuilding...${e.reset}`),xe.clear(),ne();let $e=await y();if(await pn(S),c&&l)if($e)l.reload(Z);else l.error("Build failed - check console for details")}else if(Ct(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)ht();j.stop(),process.exit(0)})}return!0}var{serve:Jr}=globalThis.Bun;import Ze from"fs";import Ae 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 fn(t){if(t.length===0)return"";if(t.length===1)return t[0];let s=t.map((p)=>p.split(Ae.sep)),i=[];for(let p=0;p<s[0].length;p++){let c=s[0][p];if(s.every((l)=>l[p]===c))i.push(c);else break}return i.join(Ae.sep)}async function In(t,s={}){let i=s.port||3000,p=s.watch!==!1;for(let v of t){let x=Ae.resolve(v);if(!Ze.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");Ze.mkdirSync(c,{recursive:!0});let l=fn(t.map((v)=>Ae.dirname(Ae.resolve(v))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let m={},u=[],h=async()=>{try{for(let v of t){let x=Ae.resolve(v);if(x.endsWith(".md"))try{let{content:k,data:B}=await pe(x,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),D=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,j=D?.defaultTheme||"github-dark",E=["github-dark"],_=D?.additionalThemes||[],q=[...new Set([...E,..._])].map((De)=>`<option value="${De}"${De===j?" selected":""}>${De}</option>`).join(`
1258
+ `;function fn(t){if(t.length===0)return"";if(t.length===1)return t[0];let s=t.map((p)=>p.split(Ae.sep)),i=[];for(let p=0;p<s[0].length;p++){let c=s[0][p];if(s.every((l)=>l[p]===c))i.push(c);else break}return i.join(Ae.sep)}async function On(t,s={}){let i=s.port||3000,p=s.watch!==!1;for(let v of t){let x=Ae.resolve(v);if(!Ze.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");Ze.mkdirSync(c,{recursive:!0});let l=fn(t.map((v)=>Ae.dirname(Ae.resolve(v))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let m={},u=[],h=async()=>{try{for(let v of t){let x=Ae.resolve(v);if(x.endsWith(".md"))try{let{content:k,data:B}=await pe(x,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),D=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,j=D?.defaultTheme||"github-dark",E=["github-dark"],_=D?.additionalThemes||[],q=[...new Set([...E,..._])].map((De)=>`<option value="${De}"${De===j?" selected":""}>${De}</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>${pn(B.title||Ae.basename(x))}</title>
1265
+ <title>${ln(B.title||Ae.basename(x))}</title>
1266
1266
  <!-- Syntax highlighting styles -->
1267
1267
  <style id="syntax-theme">
1268
1268
  :root {
@@ -1419,24 +1419,24 @@ else {
1419
1419
  </body>
1420
1420
  </html>
1421
1421
  `,he=`/${Ae.relative(l,x).replace(/\.md$/,"")}`;if(he.endsWith("/index"))he=he.slice(0,-6)||"/";m[he||"/"]={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)\//},(_)=>({path:_.path,external:!0}))}},B;try{let E=await Bun.build({entrypoints:[x],outdir:c,plugins:[k,ft],define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!E.success){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:`,le(E.logs,x));continue}let _=E.outputs.find((F)=>F.path.endsWith(".html"));if(!_){console.error(`${e.red}No HTML output found for ${e.bright}${v}${e.reset}`);continue}B=await Bun.file(_.path).text()}catch(E){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:
1422
- ${le(E,x)}`);continue}let j=`/${Ae.relative(l,x).replace(/\.stx$/,"")}`;if(j.endsWith("/index"))j=j.slice(0,-6)||"/";if(j.includes("[")){let{regex:E,params:_}=hr(j,{page:!0});u.push({pattern:E,paramNames:_,filePath:x,routeTemplate:j,fileType:"stx"}),m[j]={filePath:x,content:B,fileType:"stx"}}else m[j||"/"]={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}`,le(v)),!1}};if(!await h())return!1;let y=i;try{if(y=await Ye(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=Ae.join(process.cwd(),"public",x.pathname);if(Ze.existsSync(C)&&Ze.statSync(C).isFile()){let D=Bun.file(C),j=Ae.extname(C).toLowerCase(),E="application/octet-stream";if(j===".ts"||j===".tsx"){let _=new Bun.Transpiler({loader:j===".tsx"?"tsx":"ts"}),F=await D.text(),q=_.transformSync(F);return new Response(q,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(j){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(D,{headers:{"Content-Type":E}})}let k=m[x.pathname];if(!k&&!x.pathname.endsWith("/"))k=m[`${x.pathname}/`];if(!k)for(let D of u){let j=x.pathname.match(D.pattern);if(j){let E=m[D.routeTemplate];if(E){let _={};for(let Z=0;Z<D.paramNames.length;Z++)_[D.paramNames[Z]]=decodeURIComponent(j[Z+1]);let F=E.content,q=`<script>window.__routeParams = ${JSON.stringify(_)};</script>`;if(F.includes("</head>"))F=F.replace("</head>",`${q}
1422
+ ${le(E,x)}`);continue}let j=`/${Ae.relative(l,x).replace(/\.stx$/,"")}`;if(j.endsWith("/index"))j=j.slice(0,-6)||"/";if(j.includes("[")){let{regex:E,params:_}=yr(j,{page:!0});u.push({pattern:E,paramNames:_,filePath:x,routeTemplate:j,fileType:"stx"}),m[j]={filePath:x,content:B,fileType:"stx"}}else m[j||"/"]={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}`,le(v)),!1}};if(!await h())return!1;let y=i;try{if(y=await Ye(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=Ae.join(process.cwd(),"public",x.pathname);if(Ze.existsSync(C)&&Ze.statSync(C).isFile()){let D=Bun.file(C),j=Ae.extname(C).toLowerCase(),E="application/octet-stream";if(j===".ts"||j===".tsx"){let _=new Bun.Transpiler({loader:j===".tsx"?"tsx":"ts"}),F=await D.text(),q=_.transformSync(F);return new Response(q,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(j){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(D,{headers:{"Content-Type":E}})}let k=m[x.pathname];if(!k&&!x.pathname.endsWith("/"))k=m[`${x.pathname}/`];if(!k)for(let D of u){let j=x.pathname.match(D.pattern);if(j){let E=m[D.routeTemplate];if(E){let _={};for(let Z=0;Z<D.paramNames.length;Z++)_[D.paramNames[Z]]=decodeURIComponent(j[Z+1]);let F=E.content,q=`<script>window.__routeParams = ${JSON.stringify(_)};</script>`;if(F.includes("</head>"))F=F.replace("</head>",`${q}
1423
1423
  </head>`);else F=q+F;k={...E,content:F}}break}}if(k)return f(k.content).then((D)=>{if(D.includes("</head>"))D=D.replace("</head>",`${cn}
1424
- </head>`);return new Response(D,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let B=Ae.join(c,x.pathname);if(Ze.existsSync(B)&&Ze.statSync(B).isFile()){let D=Bun.file(B),j=Ae.extname(B).toLowerCase(),E="text/plain";if(j===".ts"||j===".tsx"){let _=new Bun.Transpiler({loader:j===".tsx"?"tsx":"ts"}),F=await D.text(),q=_.transformSync(F);return new Response(q,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(j){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(D,{headers:{"Content-Type":E}})}if(x.pathname!=="/"&&m["/"]){let D=se(v);return f(m["/"].content).then((j)=>{if(D){let E=j.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(E){let _=j.match(/<title[^>]*>([\s\S]*?)<\/title>/i),F=_?_[1]:"",q=`<!DOCTYPE html><html><head><title>${pn(F)}</title></head><body><main>${E[1]}</main></body></html>`;return new Response(q,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...T(),"Cache-Control":Oe,Pragma:"no-cache",Expires:"0"}})}}return new Response(j,{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(D,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let B=Ae.join(c,x.pathname);if(Ze.existsSync(B)&&Ze.statSync(B).isFile()){let D=Bun.file(B),j=Ae.extname(B).toLowerCase(),E="text/plain";if(j===".ts"||j===".tsx"){let _=new Bun.Transpiler({loader:j===".tsx"?"tsx":"ts"}),F=await D.text(),q=_.transformSync(F);return new Response(q,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(j){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(D,{headers:{"Content-Type":E}})}if(x.pathname!=="/"&&m["/"]){let D=se(v);return f(m["/"].content).then((j)=>{if(D){let E=j.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(E){let _=j.match(/<title[^>]*>([\s\S]*?)<\/title>/i),F=_?_[1]:"",q=`<!DOCTYPE html><html><head><title>${ln(F)}</title></head><body><main>${E[1]}</main></body></html>`;return new Response(q,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...T(),"Cache-Control":Oe,Pragma:"no-cache",Expires:"0"}})}}return new Response(j,{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
1428
  ${e.yellow}Routes:${e.reset}`);let S=new Set(u.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:Ae.relative(process.cwd(),x.filePath),fileType:x.fileType}));for(let v of u){let x=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");R.push({route:x,filePath:Ae.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`),Qe(w.url.toString(),()=>{if(p)Ze.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Ze.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}`),xe.clear(),ne(),await h()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function pn(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Yr}=globalThis.Bun;import ve from"fs";import ie from"path";async function mn(t){try{return $t(await Bun.file(t).text())}catch{return}}function Wt(t){let s=Bun.file(t),i=ie.extname(t).toLowerCase(),p={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":p[i]||"application/octet-stream",...l}})}async function On(t=".",s={}){let i=s.port||3000,p=s.watch!==!1,c=s.hotReload!==!1&&p,l=null,m=s.hmrPort||i+1,u=ie.resolve(t),{loadStxConfig:h}=await import("./chunk-3bj1w990.js"),g=await h(u),{createServerApi:y,isServerApiSource:w}=await import("./chunk-nr07vxm2.js"),S=s.stxOptions?.serverApi??g.serverApi,R=await y(u,S),v=g.root&&g.root!=="."?ie.join(u,g.root):u,x=s.pagesDir||g.pagesDir||"pages",C=ie.join(v,x);if(!ve.existsSync(C)&&!g._layerPageDirs?.some((O)=>ve.existsSync(O)))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=L(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||[],D=[];for(let{dir:O,prefix:z}of B)if(ve.existsSync(O)){let N=L(ie.dirname(O),{pagesDir:ie.basename(O)});for(let W of N){let we=z==="/"?W.pattern:`${z}${W.pattern==="/"?"":W.pattern}`;D.push({route:{...W,pattern:we},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 j=new Map,E=null,_=null;if(s.stxOptions?.shell!==!1){if(_=await ho(u,s.stxOptions?.shell),_){if(E=await Pr(_,s.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${ie.relative(u,_)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}rt(),await ot(u);let F=st();if(F.length>0)console.log(`${e.blue}Loaded ${e.bright}${F.length}${e.blue} middleware: ${e.dim}${F.join(", ")}${e.reset}`);let q={},Z=null;try{let{loadStxConfig:O}=await import("./chunk-3bj1w990.js"),z=await O(u);if(z?.apiRouter)Z=z?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(z?.apiRoutes){q=z.apiRoutes;let N=Object.keys(q).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-ensp20xk.js"),we=z.broadcasting;await N(we);let Ne=we.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Ne}/ws${e.reset}`);let Ge=ie.join(process.cwd(),"channels.ts");if(ve.existsSync(Ge))try{let ee=await W(Ge);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 $e=a(u,"output");ve.mkdirSync($e,{recursive:!0});let he=new Map,De=new Set,ae=async(O)=>{let z=yr(C,O);if(!z)return null;try{let N=await Bun.build({entrypoints:[z],outdir:$e,plugins:[ft],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!N.success)return null;let W=N.outputs.find((we)=>we.path.endsWith(".html"));if(!W)return null;return await Bun.file(W.path).text()}catch{return null}},U=new Map,H=async(O,z)=>{try{let{processDirectives:N,extractVariables:W,defaultConfig:we,loadStxConfig:Ne,injectRouterScript:Ge}=await import("./chunk-3bj1w990.js"),{checkCache:ee,cacheTemplate:Q,readFileCached:V,templateCache:K}=await import("./chunk-a51f04an.js"),ke=await Ne(u),Je=(ce)=>{if(!ce)return ce;if(ie.isAbsolute(ce))return ce;return ie.resolve(u,ce)},A={...we,...ke,...s.stxOptions,autoShell:!0};if(s.debugDirectives)A.debug=!0;A.partialsDir=Je(A.partialsDir),A.componentsDir=Je(A.componentsDir),A.layoutsDir=Je(A.layoutsDir),A.storesDir=Je(A.storesDir||"stores"),A.cachePath=Je(A.cachePath)??a(u,"cache");let be=!z&&!s.profile,de=A.cache!==!1;if(de&&be){let ce=K.get(O.filePath);if(ce)try{if((await ve.promises.stat(O.filePath)).mtime.getTime()<=ce.mtime){let Be=!0;for(let Re of ce.dependencies){if(!ve.existsSync(Re)){Be=!1;break}if((await ve.promises.stat(Re)).mtime.getTime()>ce.mtime){Be=!1;break}}if(Be){let Re=ce.output;if(E)Re=ye(Re,{preserveHead:!0});let gt=U.get(O.filePath);return{route:O,content:Re,status:gt?.status??await mn(O.filePath),headers:gt?.headers}}}}catch{}let Ie=await ee(O.filePath,A);if(Ie){let je=Ie;if(E)je=ye(je,{preserveHead:!0});let Be=U.get(O.filePath);return{route:O,content:je,status:Be?.status??await mn(O.filePath),headers:Be?.headers}}}let ge=de?await V(O.filePath):await Bun.file(O.filePath).text(),Ce=$t(ge),{classifyAllScripts:X}=await import("./chunk-3bj1w990.js"),Le=X(ge),We=Le.server.map((ce)=>ce.content),fe=ge;for(let ce of Le.server)fe=fe.replace(ce.fullTag,"");let me={__filename:O.filePath,__dirname:ie.dirname(O.filePath),__stx_options:A,params:z??{},__stx_runtime_head:{}};for(let ce of We)try{await W(ce,me,O.filePath)}catch(Ie){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",O.filePath,Ie?.message||Ie)}let Ke=new Set,Me;if(s.profile){let ce=performance.now();Me=await N(fe,me,O.filePath,A,Ke);let Ie=performance.now()-ce,je=ie.relative(u,O.filePath)||O.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else Me=await N(fe,me,O.filePath,A,Ke);if(!E)Me=await Ge(Me,{router:A.router});{let{interpolateScriptExpressions:ce}=await import("./chunk-j83ax407.js");Me=Me.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,je,Be)=>{if(!/function\s+__stx_setup_/.test(Be))return Ie;return`<script${je}>${ce(Be,me)}</script>`})}if(E)Me=ye(Me,{preserveHead:!0});if(de&&be)await Q(O.filePath,Me,Ke,A);let{extractStreamBoundaries:Kn}=await import("./chunk-nn462qm9.js"),lt=Kn(me),mt=me.__streamTemplates;if(mt&&typeof mt==="object"&&Object.keys(mt).length>0){let ce=me.streamBoundaries||{},Ie={...A,autoShell:!1},je=Object.keys(mt).map((Re)=>({id:Re,render:async()=>{let gt=typeof ce[Re]==="function"?await ce[Re]():void 0;return N(mt[Re],{...me,$boundary:gt},O.filePath,Ie,new Set)}})),Be=new Set(je.map((Re)=>Re.id));lt=[...(lt||[]).filter((Re)=>!Be.has(Re.id)),...je]}if(lt&&lt.length>0)De.add(O.pattern);else lt=void 0;let Kt=Ue(me),Xt=Ve(me);if(be)U.set(O.filePath,{status:Kt,headers:Xt});return{route:O,content:Me,status:Kt??Ce,headers:Xt,boundaries:lt}}catch(N){return console.error(`${e.red}Error building ${e.bright}${O.pattern}${e.reset}:`,N),null}},ze=8,qe=async()=>{he.clear(),j.clear();for(let O=0;O<k.length;O+=ze){let z=k.slice(O,O+ze),N=await Promise.all(z.map((W)=>H(W)));for(let W of N)if(W)he.set(W.route.pattern,W)}for(let O=0;O<D.length;O+=ze){let z=D.slice(O,O+ze),N=await Promise.all(z.map(({route:W})=>H(W)));for(let W of N)if(W)j.set(W.route.pattern,W)}return he.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await qe())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Tt(u);let et=i;try{if(et=await Ye(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 O=s.hmrPort||et+1;l=At({wsPort:O,verbose:!1}),m=l.start(O)}let _t=(O,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(O.includes("</head>"))return O.replace("</head>",`${W}</head>`);if(O.includes("<body"))return O.replace(/<body([^>]*)>/,`<body$1>${W}`);return W+O};console.log(`${e.blue}Starting server...${e.reset}`);let Lt=Yr({port:et,async fetch(O){let z=new URL(O.url),N=g?.publicDir||"public",W=ie.join(u,N,z.pathname),we=ie.join(u,z.pathname),Ne=ie.join($e,z.pathname);if([W,we,Ne].some((A)=>w(A,u,S)))return new Response("Not Found",{status:404});let[Ge,ee,Q]=await Promise.all([ve.promises.stat(W).catch(()=>null),ve.promises.stat(we).catch(()=>null),ve.promises.stat(Ne).catch(()=>null)]);if(Ge?.isFile()&&!w(W,u,S))return Wt(W);if(ee?.isFile()&&!w(we,u,S))return Wt(we);if(Q?.isFile()&&!w(Ne,u,S))return Wt(Ne);if(z.pathname.startsWith("/_stx/component/")){let A=decodeURIComponent(z.pathname.slice(16));if(A)try{let be=`<${A} />`,de={...buildConfig,autoShell:!1},ge=await processDirectives(be,{},ie.join(u,"components",`${A}.stx`),de,new Set);return new Response(ge,{headers:{"Content-Type":"text/html"}})}catch(be){return new Response(`<div class="stx-async-error">${be.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(z.pathname==="/_stx/img"){let{handleImageRequest:A}=await import("./chunk-6sasxbv9.js"),be=await A(O,{publicDir:ie.join(u,N),cacheDir:a(u,"cache","img")});if(be)return be}if(Z)try{let A=await Z.handleRequest(O);if(A.status!==404)return A}catch{}if(q[z.pathname])try{return await q[z.pathname](O)}catch(A){return new Response(JSON.stringify({error:A.message}),{status:500,headers:{"Content-Type":"application/json"}})}let V=await R(O);if(V)return V;let K=$n(z.pathname,k);if(K){let A=he.get(K.route.pattern),be=De.has(K.route.pattern);if(K.route.isDynamic&&Object.keys(K.params).length>0||be){let de=await H(K.route,K.params);if(de)A=de}if(A){let de=A.status??200,ge=A.headers??{},Ce=(K.route.filePath?He(await Bun.file(K.route.filePath).text().catch(()=>"")):null)??{};if(Ce.validate){if(!await Ce.validate({params:K.params})){let We=await ae(404);if(We){let fe=We;if(fe=await f(fe,u),c)fe=Xe(fe,m);return new Response(fe,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(Ce.middleware){let Le=it(z.pathname,K.params,Ce,z.search),We=at(Le,null,O,{isServer:!0}),fe=await ct(Ce.middleware,We);if(fe.redirect){let me=fe.redirect.path,Ke=fe.redirect.options.redirectCode||302,Me=new Headers(fe.responseHeaders);return Me.set("Location",me),new Response(null,{status:Ke,headers:Me})}if(fe.abort){let{statusCode:me,message:Ke}=fe.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${me}</title></head><body><h1>Error ${me}</h1><p>${Ke}</p></body></html>`,{status:me,headers:{"Content-Type":"text/html"}})}if(Object.keys(fe.state).length>0){let me=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(fe.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;A.content=A.content.replace("</head>",`${me}</head>`)}}let X=A.content;if(E&&yo(O)){let Le=Ee(X),We=ue(X),fe=X.match(/<title[^>]*>([\s\S]*?)<\/title>/i),me=fe?mo(fe[1].trim()):"";if(Object.keys(K.params).length>0)X=_t(X,K.params);X=await f(X,u);let Ke=g?.router?.container||"main";return X=oe(X,Ke),new Response(X,{status:de,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":We?"true":"false",...me&&{"X-STX-Title":encodeURIComponent(me)},[vi]:Cs(),...T(),"Cache-Control":Oe}})}if(E)X=Ln(E,X);if(Object.keys(K.params).length>0)X=_t(X,K.params);if(X=await f(X,u),c)X=Xe(X,m);if(s.native)if(X.includes("<head>"))X=X.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 X="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+X;if(s.titlebarHidden)if(X.includes("<head>"))X=X.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 X=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${X}`;if(A.boundaries&&A.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:We}=await import("./chunk-nn462qm9.js");return We(Le(X,A.boundaries,{timeoutMs:30000}),{status:de,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(X,{status:de,headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ge}})}}if(D.length>0){let A=D.map((de)=>de.route),be=$n(z.pathname,A);if(be){let de=j.get(be.route.pattern);if(de){let ge=de.content;if(E)ge=Ln(E,ge);if(Object.keys(be.params).length>0)ge=_t(ge,be.params);if(ge=await f(ge,u),c)ge=Xe(ge,m);return new Response(ge,{status:de.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:de}of B)if(de!=="/"&&z.pathname.startsWith(de)){let ge=j.get(de)||j.get(de+"/");if(ge){let Ce=ge.content;if(E)Ce=Ln(E,Ce);if(Ce=await f(Ce,u),c)Ce=Xe(Ce,m);return new Response(Ce,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(nt(z.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let ke=he.get("/");if(ke){let A=ke.content;if(A=await f(A,u),c)A=Xe(A,m);if(s.native)if(A.includes("<head>"))A=A.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 A="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+A;return new Response(A,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Je=await ae(404);if(Je){let A=Je;if(A=await f(A,u),c)A=Xe(A,m);return new Response(A,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(O){let z=await ae(500);if(z)return new Response(z,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${O}
1429
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(w.url.toString(),()=>{if(p)Ze.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Ze.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}`),xe.clear(),ne(),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 ve from"fs";import ie from"path";async function mn(t){try{return Rt(await Bun.file(t).text())}catch{return}}function Wt(t){let s=Bun.file(t),i=ie.extname(t).toLowerCase(),p={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":p[i]||"application/octet-stream",...l}})}async function Dn(t=".",s={}){let i=s.port||3000,p=s.watch!==!1,c=s.hotReload!==!1&&p,l=null,m=s.hmrPort||i+1,u=ie.resolve(t),{loadStxConfig:h}=await import("./chunk-yv5rwthv.js"),g=await h(u),{createServerApi:y,isServerApiSource:w}=await import("./chunk-vq0cb1m9.js"),S=s.stxOptions?.serverApi??g.serverApi,R=await y(u,S),v=g.root&&g.root!=="."?ie.join(u,g.root):u,x=s.pagesDir||g.pagesDir||"pages",C=ie.join(v,x);if(!ve.existsSync(C)&&!g._layerPageDirs?.some((O)=>ve.existsSync(O)))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=L(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||[],D=[];for(let{dir:O,prefix:z}of B)if(ve.existsSync(O)){let N=L(ie.dirname(O),{pagesDir:ie.basename(O)});for(let W of N){let we=z==="/"?W.pattern:`${z}${W.pattern==="/"?"":W.pattern}`;D.push({route:{...W,pattern:we},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 j=new Map,E=null,_=null;if(s.stxOptions?.shell!==!1){if(_=await bo(u,s.stxOptions?.shell),_){if(E=await Ir(_,s.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${ie.relative(u,_)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}rt(),await ot(u);let F=st();if(F.length>0)console.log(`${e.blue}Loaded ${e.bright}${F.length}${e.blue} middleware: ${e.dim}${F.join(", ")}${e.reset}`);let q={},Z=null;try{let{loadStxConfig:O}=await import("./chunk-yv5rwthv.js"),z=await O(u);if(z?.apiRouter)Z=z?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(z?.apiRoutes){q=z.apiRoutes;let N=Object.keys(q).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-hcgm37dy.js"),we=z.broadcasting;await N(we);let Ne=we.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Ne}/ws${e.reset}`);let Ge=ie.join(process.cwd(),"channels.ts");if(ve.existsSync(Ge))try{let ee=await W(Ge);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 $e=a(u,"output");ve.mkdirSync($e,{recursive:!0});let he=new Map,De=new Set,ae=async(O)=>{let z=br(C,O);if(!z)return null;try{let N=await Bun.build({entrypoints:[z],outdir:$e,plugins:[ft],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!N.success)return null;let W=N.outputs.find((we)=>we.path.endsWith(".html"));if(!W)return null;return await Bun.file(W.path).text()}catch{return null}},U=new Map,H=async(O,z)=>{try{let{processDirectives:N,extractVariables:W,defaultConfig:we,loadStxConfig:Ne,injectRouterScript:Ge}=await import("./chunk-yv5rwthv.js"),{checkCache:ee,cacheTemplate:Q,readFileCached:V,templateCache:K}=await import("./chunk-y1bppxgw.js"),ke=await Ne(u),Je=(ce)=>{if(!ce)return ce;if(ie.isAbsolute(ce))return ce;return ie.resolve(u,ce)},A={...we,...ke,...s.stxOptions,autoShell:!0};if(s.debugDirectives)A.debug=!0;A.partialsDir=Je(A.partialsDir),A.componentsDir=Je(A.componentsDir),A.layoutsDir=Je(A.layoutsDir),A.storesDir=Je(A.storesDir||"stores"),A.cachePath=Je(A.cachePath)??a(u,"cache");let be=!z&&!s.profile,de=A.cache!==!1;if(de&&be){let ce=K.get(O.filePath);if(ce)try{if((await ve.promises.stat(O.filePath)).mtime.getTime()<=ce.mtime){let Be=!0;for(let Re of ce.dependencies){if(!ve.existsSync(Re)){Be=!1;break}if((await ve.promises.stat(Re)).mtime.getTime()>ce.mtime){Be=!1;break}}if(Be){let Re=ce.output;if(E)Re=ye(Re,{preserveHead:!0});let gt=U.get(O.filePath);return{route:O,content:Re,status:gt?.status??await mn(O.filePath),headers:gt?.headers}}}}catch{}let Ie=await ee(O.filePath,A);if(Ie){let je=Ie;if(E)je=ye(je,{preserveHead:!0});let Be=U.get(O.filePath);return{route:O,content:je,status:Be?.status??await mn(O.filePath),headers:Be?.headers}}}let ge=de?await V(O.filePath):await Bun.file(O.filePath).text(),Ce=Rt(ge),{classifyAllScripts:X}=await import("./chunk-yv5rwthv.js"),Le=X(ge),We=Le.server.map((ce)=>ce.content),fe=ge;for(let ce of Le.server)fe=fe.replace(ce.fullTag,"");let me={__filename:O.filePath,__dirname:ie.dirname(O.filePath),__stx_options:A,params:z??{},__stx_runtime_head:{}};for(let ce of We)try{await W(ce,me,O.filePath)}catch(Ie){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",O.filePath,Ie?.message||Ie)}let Ke=new Set,Me;if(s.profile){let ce=performance.now();Me=await N(fe,me,O.filePath,A,Ke);let Ie=performance.now()-ce,je=ie.relative(u,O.filePath)||O.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else Me=await N(fe,me,O.filePath,A,Ke);if(!E)Me=await Ge(Me,{router:A.router});{let{interpolateScriptExpressions:ce}=await import("./chunk-mqy7g74k.js");Me=Me.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,je,Be)=>{if(!/function\s+__stx_setup_/.test(Be))return Ie;return`<script${je}>${ce(Be,me)}</script>`})}if(E)Me=ye(Me,{preserveHead:!0});if(de&&be)await Q(O.filePath,Me,Ke,A);let{extractStreamBoundaries:Kn}=await import("./chunk-1cat8kdj.js"),lt=Kn(me),mt=me.__streamTemplates;if(mt&&typeof mt==="object"&&Object.keys(mt).length>0){let ce=me.streamBoundaries||{},Ie={...A,autoShell:!1},je=Object.keys(mt).map((Re)=>({id:Re,render:async()=>{let gt=typeof ce[Re]==="function"?await ce[Re]():void 0;return N(mt[Re],{...me,$boundary:gt},O.filePath,Ie,new Set)}})),Be=new Set(je.map((Re)=>Re.id));lt=[...(lt||[]).filter((Re)=>!Be.has(Re.id)),...je]}if(lt&&lt.length>0)De.add(O.pattern);else lt=void 0;let Kt=Ue(me),Xt=Ve(me);if(be)U.set(O.filePath,{status:Kt,headers:Xt});return{route:O,content:Me,status:Kt??Ce,headers:Xt,boundaries:lt}}catch(N){return console.error(`${e.red}Error building ${e.bright}${O.pattern}${e.reset}:`,N),null}},ze=8,qe=async()=>{he.clear(),j.clear();for(let O=0;O<k.length;O+=ze){let z=k.slice(O,O+ze),N=await Promise.all(z.map((W)=>H(W)));for(let W of N)if(W)he.set(W.route.pattern,W)}for(let O=0;O<D.length;O+=ze){let z=D.slice(O,O+ze),N=await Promise.all(z.map(({route:W})=>H(W)));for(let W of N)if(W)j.set(W.route.pattern,W)}return he.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await qe())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await $t(u);let et=i;try{if(et=await Ye(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 O=s.hmrPort||et+1;l=Ot({wsPort:O,verbose:!1}),m=l.start(O)}let _t=(O,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(O.includes("</head>"))return O.replace("</head>",`${W}</head>`);if(O.includes("<body"))return O.replace(/<body([^>]*)>/,`<body$1>${W}`);return W+O};console.log(`${e.blue}Starting server...${e.reset}`);let It=Yr({port:et,async fetch(O){let z=new URL(O.url),N=g?.publicDir||"public",W=ie.join(u,N,z.pathname),we=ie.join(u,z.pathname),Ne=ie.join($e,z.pathname);if([W,we,Ne].some((A)=>w(A,u,S)))return new Response("Not Found",{status:404});let[Ge,ee,Q]=await Promise.all([ve.promises.stat(W).catch(()=>null),ve.promises.stat(we).catch(()=>null),ve.promises.stat(Ne).catch(()=>null)]);if(Ge?.isFile()&&!w(W,u,S))return Wt(W);if(ee?.isFile()&&!w(we,u,S))return Wt(we);if(Q?.isFile()&&!w(Ne,u,S))return Wt(Ne);if(z.pathname.startsWith("/_stx/component/")){let A=decodeURIComponent(z.pathname.slice(16));if(A)try{let be=`<${A} />`,de={...buildConfig,autoShell:!1},ge=await processDirectives(be,{},ie.join(u,"components",`${A}.stx`),de,new Set);return new Response(ge,{headers:{"Content-Type":"text/html"}})}catch(be){return new Response(`<div class="stx-async-error">${be.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(z.pathname==="/_stx/img"){let{handleImageRequest:A}=await import("./chunk-tn9v10q2.js"),be=await A(O,{publicDir:ie.join(u,N),cacheDir:a(u,"cache","img")});if(be)return be}if(Z)try{let A=await Z.handleRequest(O);if(A.status!==404)return A}catch{}if(q[z.pathname])try{return await q[z.pathname](O)}catch(A){return new Response(JSON.stringify({error:A.message}),{status:500,headers:{"Content-Type":"application/json"}})}let V=await R(O);if(V)return V;let K=Rn(z.pathname,k);if(K){let A=he.get(K.route.pattern),be=De.has(K.route.pattern);if(K.route.isDynamic&&Object.keys(K.params).length>0||be){let de=await H(K.route,K.params);if(de)A=de}if(A){let de=A.status??200,ge=A.headers??{},Ce=(K.route.filePath?He(await Bun.file(K.route.filePath).text().catch(()=>"")):null)??{};if(Ce.validate){if(!await Ce.validate({params:K.params})){let We=await ae(404);if(We){let fe=We;if(fe=await f(fe,u),c)fe=Xe(fe,m);return new Response(fe,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(Ce.middleware){let Le=it(z.pathname,K.params,Ce,z.search),We=at(Le,null,O,{isServer:!0}),fe=await ct(Ce.middleware,We);if(fe.redirect){let me=fe.redirect.path,Ke=fe.redirect.options.redirectCode||302,Me=new Headers(fe.responseHeaders);return Me.set("Location",me),new Response(null,{status:Ke,headers:Me})}if(fe.abort){let{statusCode:me,message:Ke}=fe.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${me}</title></head><body><h1>Error ${me}</h1><p>${Ke}</p></body></html>`,{status:me,headers:{"Content-Type":"text/html"}})}if(Object.keys(fe.state).length>0){let me=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(fe.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;A.content=A.content.replace("</head>",`${me}</head>`)}}let X=A.content;if(E&&wo(O)){let Le=Ee(X),We=ue(X),fe=X.match(/<title[^>]*>([\s\S]*?)<\/title>/i),me=fe?yo(fe[1].trim()):"";if(Object.keys(K.params).length>0)X=_t(X,K.params);X=await f(X,u);let Ke=g?.router?.container||"main";return X=oe(X,Ke),new Response(X,{status:de,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":We?"true":"false",...me&&{"X-STX-Title":encodeURIComponent(me)},[Si]:Es(),...T(),"Cache-Control":Oe}})}if(E)X=jn(E,X);if(Object.keys(K.params).length>0)X=_t(X,K.params);if(X=await f(X,u),c)X=Xe(X,m);if(s.native)if(X.includes("<head>"))X=X.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 X="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+X;if(s.titlebarHidden)if(X.includes("<head>"))X=X.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 X=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${X}`;if(A.boundaries&&A.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:We}=await import("./chunk-1cat8kdj.js");return We(Le(X,A.boundaries,{timeoutMs:30000}),{status:de,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(X,{status:de,headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ge}})}}if(D.length>0){let A=D.map((de)=>de.route),be=Rn(z.pathname,A);if(be){let de=j.get(be.route.pattern);if(de){let ge=de.content;if(E)ge=jn(E,ge);if(Object.keys(be.params).length>0)ge=_t(ge,be.params);if(ge=await f(ge,u),c)ge=Xe(ge,m);return new Response(ge,{status:de.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:de}of B)if(de!=="/"&&z.pathname.startsWith(de)){let ge=j.get(de)||j.get(de+"/");if(ge){let Ce=ge.content;if(E)Ce=jn(E,Ce);if(Ce=await f(Ce,u),c)Ce=Xe(Ce,m);return new Response(Ce,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(nt(z.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let ke=he.get("/");if(ke){let A=ke.content;if(A=await f(A,u),c)A=Xe(A,m);if(s.native)if(A.includes("<head>"))A=A.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 A="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+A;return new Response(A,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Je=await ae(404);if(Je){let A=Je;if(A=await f(A,u),c)A=Xe(A,m);return new Response(A,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(O){let z=await ae(500);if(z)return new Response(z,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${O}
1430
1430
  ${O.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 It=[...br(k,u)];for(let{route:O}of D)It.push(`${O.pattern}`);if(It.forEach((O,z)=>{let W=z===It.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${W}${e.reset}${O}`)}),console.log(`
1434
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(Lt.url.toString(),()=>{if(l)ht();Lt.stop()}),s.native){let O,z=ie.join(C,"index.stx");if(ve.existsSync(z)){let W=await Bun.file(z).text();O=Ct(W)}let N=g?.app?.window??{};await dt(et,{title:g?.app?.head?.title||ie.basename(u)||"stx App",width:N.width,height:N.height,darkMode:N.darkMode,hotReload:N.hotReload,titlebarHidden:N.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!O,sidebarConfig:O})}if(p){console.log(`${e.blue}Watching for changes...${e.reset}`);let O=(ee)=>ee.startsWith("public/")||ee.startsWith("public\\"),z=(ee)=>{let Q=ee.toLowerCase();return Q.endsWith(".stx")||Q.endsWith(".html")||Q.endsWith(".md")},N=new Map,W=()=>{let ee=new Set([u,...g._layerGraph?.layers.map((Q)=>Q.root)??[],...g._layerGraph?.configDependencies.map((Q)=>ie.dirname(Q))??[]].filter((Q)=>ve.existsSync(Q)).map((Q)=>ve.realpathSync(Q)));for(let Q of g._layerGraph?.layers??[])for(let V of Object.values(Q.resources)){if(!ve.existsSync(V))continue;let K=ve.realpathSync(V);if(![...ee].some((ke)=>K===ke||K.startsWith(`${ke}${ie.sep}`)))ee.add(K)}for(let[Q,V]of N)if(!ee.has(Q))V.close(),N.delete(Q);for(let Q of ee)if(!N.has(Q)&&ve.existsSync(Q))N.set(Q,ve.watch(Q,{recursive:!0},(V,K)=>{Ne(Q,V,K).catch((ke)=>console.error("[stx] Layer rebuild failed:",ke))}))},we=Promise.resolve(),Ne=(ee,Q,V)=>(we=we.catch(()=>{}).then(()=>Ge(ee,Q,V)),we),Ge=async(ee,Q,V)=>{if(!V||Pt(V))return;if(Et(V)){if(g._layerGraph){let K=await h(u);Object.assign(g,K),k.splice(0,k.length,...L(v,{pagesDir:x,pagesDirs:K._layerPageDirs?[C,...K._layerPageDirs.slice(1)]:void 0})),W()}if(O(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}`),xe.clear(),ne();try{let{invalidateFileCache:K,templateCache:ke}=await import("./chunk-a51f04an.js");K(ie.resolve(ee,V)),ke.delete(ie.resolve(ee,V))}catch{}if(_&&V){if(ie.resolve(ee,V)===_||ie.basename(_)===V){let ke=await Pr(_,s.stxOptions||{});if(ke)E=ke}}if(await qe(),await un(u),c&&l)l.reload(V)}else{console.log(`${e.yellow}${V} changed, rebuilding...${e.reset}`),xe.clear(),ne();try{let{invalidateFileCache:K,templateCache:ke}=await import("./chunk-a51f04an.js");K(ie.resolve(ee,V)),ke.delete(ie.resolve(ee,V))}catch{}if(await qe(),c&&l)l.reload(V)}}else if(Rt(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)ht();Lt.stop(),process.exit(0)})}return!0}import Vt from"fs";import yt 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 p=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(p))!==null){let u=m[1],h=m[2]||m[3]||m[4];if(!h)continue;let g={name:h},y=u.match(/@type\s+\{([^}]+)\}/i);if(y)g.type=y[1].trim();if(u.match(/@required/i))g.required=!0;let S=u.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)g.default=S[1].trim();let R=u.split(`
1433
+ ${e.yellow}Routes:${e.reset}`);let jt=[...wr(k,u)];for(let{route:O}of D)jt.push(`${O.pattern}`);if(jt.forEach((O,z)=>{let W=z===jt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${W}${e.reset}${O}`)}),console.log(`
1434
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(It.url.toString(),()=>{if(l)ht();It.stop()}),s.native){let O,z=ie.join(C,"index.stx");if(ve.existsSync(z)){let W=await Bun.file(z).text();O=Tt(W)}let N=g?.app?.window??{};await dt(et,{title:g?.app?.head?.title||ie.basename(u)||"stx App",width:N.width,height:N.height,darkMode:N.darkMode,hotReload:N.hotReload,titlebarHidden:N.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!O,sidebarConfig:O})}if(p){console.log(`${e.blue}Watching for changes...${e.reset}`);let O=(ee)=>ee.startsWith("public/")||ee.startsWith("public\\"),z=(ee)=>{let Q=ee.toLowerCase();return Q.endsWith(".stx")||Q.endsWith(".html")||Q.endsWith(".md")},N=new Map,W=()=>{let ee=new Set([u,...g._layerGraph?.layers.map((Q)=>Q.root)??[],...g._layerGraph?.configDependencies.map((Q)=>ie.dirname(Q))??[]].filter((Q)=>ve.existsSync(Q)).map((Q)=>ve.realpathSync(Q)));for(let Q of g._layerGraph?.layers??[])for(let V of Object.values(Q.resources)){if(!ve.existsSync(V))continue;let K=ve.realpathSync(V);if(![...ee].some((ke)=>K===ke||K.startsWith(`${ke}${ie.sep}`)))ee.add(K)}for(let[Q,V]of N)if(!ee.has(Q))V.close(),N.delete(Q);for(let Q of ee)if(!N.has(Q)&&ve.existsSync(Q))N.set(Q,ve.watch(Q,{recursive:!0},(V,K)=>{Ne(Q,V,K).catch((ke)=>console.error("[stx] Layer rebuild failed:",ke))}))},we=Promise.resolve(),Ne=(ee,Q,V)=>(we=we.catch(()=>{}).then(()=>Ge(ee,Q,V)),we),Ge=async(ee,Q,V)=>{if(!V||Pt(V))return;if(Et(V)){if(g._layerGraph){let K=await h(u);Object.assign(g,K),k.splice(0,k.length,...L(v,{pagesDir:x,pagesDirs:K._layerPageDirs?[C,...K._layerPageDirs.slice(1)]:void 0})),W()}if(O(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}`),xe.clear(),ne();try{let{invalidateFileCache:K,templateCache:ke}=await import("./chunk-y1bppxgw.js");K(ie.resolve(ee,V)),ke.delete(ie.resolve(ee,V))}catch{}if(_&&V){if(ie.resolve(ee,V)===_||ie.basename(_)===V){let ke=await Ir(_,s.stxOptions||{});if(ke)E=ke}}if(await qe(),await pn(u),c&&l)l.reload(V)}else{console.log(`${e.yellow}${V} changed, rebuilding...${e.reset}`),xe.clear(),ne();try{let{invalidateFileCache:K,templateCache:ke}=await import("./chunk-y1bppxgw.js");K(ie.resolve(ee,V)),ke.delete(ie.resolve(ee,V))}catch{}if(await qe(),c&&l)l.reload(V)}}else if(Ct(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)ht();It.stop(),process.exit(0)})}return!0}import Vt from"fs";import yt 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 p=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(p))!==null){let u=m[1],h=m[2]||m[3]||m[4];if(!h)continue;let g={name:h},y=u.match(/@type\s+\{([^}]+)\}/i);if(y)g.type=y[1].trim();if(u.match(/@required/i))g.required=!0;let S=u.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)g.default=S[1].trim();let R=u.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 u=p.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(u){let g=u[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
- `).map((p)=>p.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function ao(t,s=!1,i){let p=yt.basename(t,".stx"),c=await Qr(t),l=await Zr(t),m="";if(s&&i)m=`<${i}></${i}>`;else{let u=c.map((h)=>{if(h.type==="boolean")return`:${h.name}="true"`;return`${h.name}="value"`}).join(`
1436
+ `).map((p)=>p.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function eo(t,s=!1,i){let p=yt.basename(t,".stx"),c=await Qr(t),l=await Zr(t),m="";if(s&&i)m=`<${i}></${i}>`;else{let u=c.map((h)=>{if(h.type==="boolean")return`:${h.name}="true"`;return`${h.name}="value"`}).join(`
1437
1437
  `);m=`<${p}
1438
1438
  ${u}
1439
- />`}return{name:p,path:t,description:l,props:c,example:m,isWebComponent:s,tag:i}}async function gn(t){try{if(!await r(t))return console.warn(`Components directory does not exist: ${t}`),[];let s=await Vt.promises.readdir(t,{withFileTypes:!0}),i=[];for(let p of s){let c=yt.join(t,p.name);if(p.isDirectory()){let l=await gn(c);i.push(...l)}else if(p.isFile()&&p.name.endsWith(".stx"))i.push(c)}return i}catch(s){return console.error(`Error finding component files in ${t}:`,s),[]}}async function co(t,s){try{if(!await r(t))return[];let i=await gn(t),p=[],c=new Map;if(s?.components?.length)for(let l of s.components)c.set(l.file,l);for(let l of i){let m=c.get(l),u=!!m,h=m?.tag,g=await ao(l,u,h);p.push(g)}return p}catch(i){return console.error("Error generating component docs:",i),[]}}async function lo(t){try{if(!await r(t))return[];let s=await Vt.promises.readdir(t,{withFileTypes:!0}),i=[];for(let p of s){if(!p.isFile()||!p.name.endsWith(".stx"))continue;let c=yt.join(t,p.name),l=await Bun.file(c).text(),m=yt.basename(c,".stx"),u=l.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||l.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//),h=u?u[1].split(`
1439
+ />`}return{name:p,path:t,description:l,props:c,example:m,isWebComponent:s,tag:i}}async function gn(t){try{if(!await r(t))return console.warn(`Components directory does not exist: ${t}`),[];let s=await Vt.promises.readdir(t,{withFileTypes:!0}),i=[];for(let p of s){let c=yt.join(t,p.name);if(p.isDirectory()){let l=await gn(c);i.push(...l)}else if(p.isFile()&&p.name.endsWith(".stx"))i.push(c)}return i}catch(s){return console.error(`Error finding component files in ${t}:`,s),[]}}async function to(t,s){try{if(!await r(t))return[];let i=await gn(t),p=[],c=new Map;if(s?.components?.length)for(let l of s.components)c.set(l.file,l);for(let l of i){let m=c.get(l),u=!!m,h=m?.tag,g=await eo(l,u,h);p.push(g)}return p}catch(i){return console.error("Error generating component docs:",i),[]}}async function lo(t){try{if(!await r(t))return[];let s=await Vt.promises.readdir(t,{withFileTypes:!0}),i=[];for(let p of s){if(!p.isFile()||!p.name.endsWith(".stx"))continue;let c=yt.join(t,p.name),l=await Bun.file(c).text(),m=yt.basename(c,".stx"),u=l.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||l.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//),h=u?u[1].split(`
1440
1440
  `).map((x)=>x.trim().replace(/^\*\s*/,"")).join(" ").trim():"",g=/@component\(\s*['"]([^'"]+)['"]/g,y=/<([A-Z][a-zA-Z0-9]*|[a-z]+-[a-z0-9-]+)(?:\s[^>]*)?\/?>|\{\{\s*slot\s*\}\}/g,w=new Set,S;while((S=g.exec(l))!==null)w.add(S[1]);while((S=y.exec(l))!==null)if(S[1]&&S[1]!=="slot")w.add(S[1]);let R=/@([a-z]+)(?:\s*\(|\s+|$)/g,v=new Set;while((S=R.exec(l))!==null)v.add(S[1]);i.push({name:m,path:c,description:h,components:[...w],directives:[...v]})}return i}catch(s){return console.error("Error generating template docs:",s),[]}}async function po(t=[]){try{let s=[{name:"if",description:"Conditionally render content based on a condition",hasEndTag:!0,example:`@if(user.isLoggedIn)
1441
1441
  <p>Welcome, {{ user.name }}!</p>
1442
1442
  @endif`},{name:"else",description:"Provides an alternative if a condition is not met",hasEndTag:!1,example:`@if(user.isLoggedIn)
@@ -1570,15 +1570,15 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(Lt.
1570
1570
  <td>@${l.name}</td>
1571
1571
  <td>${l.description||"-"}</td>
1572
1572
  <td>${l.hasEndTag?"Yes":"No"}</td>
1573
- </tr>`;c+="</tbody></table>";for(let l of i)if(l.example)c+=`<h3>@${l.name}</h3>`,c+=`<p>${l.description||""}</p>`,c+="<h4>Example</h4>",c+=`<pre><code>${l.example.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}</code></pre>`}return c+="</body></html>",c}function go(t=[],s=[],i=[],p){return JSON.stringify({components:t,templates:s,directives:i,extraContent:p||""},null,2)}async function bo(t){try{let{componentsDir:s,templatesDir:i,webComponentsConfig:p,customDirectives:c,config:l}=t;if(!l.enabled)return!1;let m=l.outputDir||"docs";if(await Vt.promises.mkdir(m,{recursive:!0}),console.log("Generating documentation..."),s)console.log(`Components directory: ${s}`);if(i)console.log(`Templates directory: ${i}`);console.log(`Output directory: ${m}`);let u=[];if(l.components!==!1&&s)console.log("Generating component documentation..."),u=await co(s,p),console.log(`Found ${u.length} components`);let h=[];if(l.templates!==!1&&i)console.log("Generating template documentation..."),h=await lo(i),console.log(`Found ${h.length} templates`);let g=[];if(l.directives!==!1)console.log("Generating directive documentation..."),g=await po(c),console.log(`Found ${g.length} directives`);let y=l.format||"markdown",w=l.extraContent,S="",R="";switch(y){case"markdown":S=uo(u,h,g,w),R="md";break;case"html":S=fo(u,h,g,w),R="html";break;case"json":S=go(u,h,g,w),R="json";break;default:throw Error(`Unsupported documentation format: ${y}`)}let v=yt.join(m,`stx-docs.${R}`);return await Bun.write(v,S),console.log(`Documentation generated: ${v}`),!0}catch(s){return console.error("Error generating documentation:",s),!1}}async function ro(t){let s={enabled:!0,outputDir:t.output||"docs",format:t.format||"markdown",components:t.components!==!1,templates:t.templates!==!1,directives:t.directives!==!1,extraContent:t.extraContent},i=t.componentsDir||P.componentsDir,p=t.templatesDir||".";return bo({componentsDir:i,templatesDir:p,webComponentsConfig:P.webComponents,customDirectives:P.customDirectives,config:s})}var yn={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0};function kr(t,s={}){let i={...yn,...s};if(t.trim()==="")return`
1574
- `;let p=t;if(i.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,"");if(p=wo(p,i),p=$o(p,i),p=So(p,i),i.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,""),p=p.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(p=p.replace(/\r\n/g,`
1573
+ </tr>`;c+="</tbody></table>";for(let l of i)if(l.example)c+=`<h3>@${l.name}</h3>`,c+=`<p>${l.description||""}</p>`,c+="<h4>Example</h4>",c+=`<pre><code>${l.example.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}</code></pre>`}return c+="</body></html>",c}function mo(t=[],s=[],i=[],p){return JSON.stringify({components:t,templates:s,directives:i,extraContent:p||""},null,2)}async function go(t){try{let{componentsDir:s,templatesDir:i,webComponentsConfig:p,customDirectives:c,config:l}=t;if(!l.enabled)return!1;let m=l.outputDir||"docs";if(await Vt.promises.mkdir(m,{recursive:!0}),console.log("Generating documentation..."),s)console.log(`Components directory: ${s}`);if(i)console.log(`Templates directory: ${i}`);console.log(`Output directory: ${m}`);let u=[];if(l.components!==!1&&s)console.log("Generating component documentation..."),u=await to(s,p),console.log(`Found ${u.length} components`);let h=[];if(l.templates!==!1&&i)console.log("Generating template documentation..."),h=await lo(i),console.log(`Found ${h.length} templates`);let g=[];if(l.directives!==!1)console.log("Generating directive documentation..."),g=await po(c),console.log(`Found ${g.length} directives`);let y=l.format||"markdown",w=l.extraContent,S="",R="";switch(y){case"markdown":S=uo(u,h,g,w),R="md";break;case"html":S=fo(u,h,g,w),R="html";break;case"json":S=mo(u,h,g,w),R="json";break;default:throw Error(`Unsupported documentation format: ${y}`)}let v=yt.join(m,`stx-docs.${R}`);return await Bun.write(v,S),console.log(`Documentation generated: ${v}`),!0}catch(s){return console.error("Error generating documentation:",s),!1}}async function oo(t){let s={enabled:!0,outputDir:t.output||"docs",format:t.format||"markdown",components:t.components!==!1,templates:t.templates!==!1,directives:t.directives!==!1,extraContent:t.extraContent},i=t.componentsDir||P.componentsDir,p=t.templatesDir||".";return go({componentsDir:i,templatesDir:p,webComponentsConfig:P.webComponents,customDirectives:P.customDirectives,config:s})}var yn={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0};function Cr(t,s={}){let i={...yn,...s};if(t.trim()==="")return`
1574
+ `;let p=t;if(i.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,"");if(p=vo(p,i),p=$o(p,i),p=So(p,i),i.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,""),p=p.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(p=p.replace(/\r\n/g,`
1575
1575
  `).replace(/\r/g,`
1576
1576
  `),!p.endsWith(`
1577
1577
  `))p+=`
1578
- `;return p}function so(t,s={}){let i={...yn,...s};if(t.trim()==="")return`
1578
+ `;return p}function io(t,s={}){let i={...yn,...s};if(t.trim()==="")return`
1579
1579
  `;let p=t;if(p=p.replace(/^( *)```(html|stx)\n([\s\S]*?)^( *)```/gm,(c,l,m,u,h)=>{let g=u.split(`
1580
1580
  `),y=g.filter((x)=>x.trim().length>0);if(y.length===0)return c;let w=Math.min(...y.map((x)=>{let C=x.match(/^( *)/);return C?C[1].length:0})),S=g.map((x)=>{if(x.trim().length===0)return"";return x.substring(w)}).join(`
1581
- `),v=kr(S,i).trimEnd().split(`
1581
+ `),v=Cr(S,i).trimEnd().split(`
1582
1582
  `).map((x)=>{if(x.trim().length===0)return"";return l+x}).join(`
1583
1583
  `);return`${l}\`\`\`${m}
1584
1584
  ${v}
@@ -1586,7 +1586,7 @@ ${l}\`\`\``}),i.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,"");if(p=p.replac
1586
1586
  `).replace(/\r/g,`
1587
1587
  `),!p.endsWith(`
1588
1588
  `))p+=`
1589
- `;return p}function vo(t){let s=t,i=[],p="__PROTECTED_BLOCK_";return s=s.replace(/(<(?:pre|code|textarea)[^>]*>)([\s\S]*?)(<\/(?:pre|code|textarea)>)/gi,(c)=>{let l=i.length;return i.push(c),`${p}${l}__`}),s=s.replace(/(@(?:if|foreach|for|while|unless|section|component|slot|push|prepend|error|auth|guest|can)(?:\((?:[^()'"]|'[^']*'|"[^"]*"|\((?:[^()'"]|'[^']*'|"[^"]*")*\))*\))?)/g,`
1589
+ `;return p}function xo(t){let s=t,i=[],p="__PROTECTED_BLOCK_";return s=s.replace(/(<(?:pre|code|textarea)[^>]*>)([\s\S]*?)(<\/(?:pre|code|textarea)>)/gi,(c)=>{let l=i.length;return i.push(c),`${p}${l}__`}),s=s.replace(/(@(?:if|foreach|for|while|unless|section|component|slot|push|prepend|error|auth|guest|can)(?:\((?:[^()'"]|'[^']*'|"[^"]*"|\((?:[^()'"]|'[^']*'|"[^"]*")*\))*\))?)/g,`
1590
1590
  $1
1591
1591
  `),s=s.replace(/(@end\w+)/g,`
1592
1592
  $1
@@ -1600,10 +1600,10 @@ ${m}`}),s=s.replace(/(<\/[^>]+>)(?=<|$)/g,(c,l,m,u)=>{let h=u.substring(Math.max
1600
1600
  `}),s=s.replace(new RegExp(`${p}(\\d+)__`,"g"),(c,l)=>i[Number.parseInt(l,10)]),s=s.replace(/\n{2,}/g,`
1601
1601
  `),s=s.split(`
1602
1602
  `).map((c)=>c.trim()).join(`
1603
- `),s=s.replace(/^\n+/,"").replace(/\n+$/,""),s}function wo(t,s){let p=vo(t).split(`
1603
+ `),s=s.replace(/^\n+/,"").replace(/\n+$/,""),s}function vo(t,s){let p=xo(t).split(`
1604
1604
  `),c=[],l=0,m=!1,u=s.useTabs?"\t":" ".repeat(s.indentSize);for(let h=0;h<p.length;h++){let g=p[h],y=g.trim();if(y===""){c.push("");continue}let w=y.match(/<script\b/i),S=y.match(/<\/script>/i);if(m&&!S){c.push(g);continue}let R=y===">";if(hn(y)&&!y.startsWith("<")&&!y.startsWith("@")){c.push(u.repeat(l)+y);continue}let v=y.startsWith("@end"),x=y.startsWith("@else")||y.startsWith("@elseif"),C=y.startsWith("@")&&To(y),k=y.startsWith("<!DOCTYPE")||y.startsWith("<!doctype"),B=y.startsWith("<!--"),D=y.startsWith("</"),j=y.startsWith("<")&&!D&&!B&&!k,E=y.includes("/>")||ko(y),_=hn(y);if(D||v)l=Math.max(0,l-1);let F=x?Math.max(0,l-1):l;if(R)c.push(g);else c.push(u.repeat(F)+y);if(j&&!E&&!_&&!R||C)l++;if(w)m=!0;if(S)m=!1}return c.join(`
1605
1605
  `)}function So(t,s){if(t=t.replace(/@(if|elseif|foreach|for|while)\s*\(\s*([^)]+)\s*\)/g,(i,p,c)=>{let l=c.trim().replace(/\s+/g," ");return`@${p}(${l})`}),t=t.replace(/@(csrf|method)\s*\(\s*([^)]*)\s*\)/g,(i,p,c)=>{if(c.trim()==="")return`@${p}`;return`@${p}(${c.trim()})`}),s.normalizeWhitespace)t=t.replace(/\{\{\s*([^}]+)\s*\}\}/g,(i,p)=>`{{ ${p.trim()} }}`),t=t.replace(/\{!!\s*([^!]+)\s*!!\}/g,(i,p)=>`{!! ${p.trim()} !!}`);return t}function ko(t){let s=["br","hr","img","input","meta","link","area","base","col","embed","source","track","wbr"];if(t.includes("/>"))return!0;let i=t.match(/<(\w+)/);if(i){let p=i[1];return s.includes(p.toLowerCase())}return!1}function hn(t){return/<(\w+)(?:\s[^>]*)?>[\s\S]*?<\/\1>/.test(t)}function To(t){let s=["if","unless","foreach","for","while","section","push","component","slot","markdown","wrap","error"];for(let i of s)if(t.startsWith(`@${i}`))return!t.includes(`@end${i}`);return!1}function $o(t,s){if(!s.sortAttributes)return t;return t.replace(/<(\w+)([^>]*)>/g,(i,p,c)=>{if(!c.trim())return i;if(c.includes("<")||c.includes(`
1606
- `)||c.includes("@"))return i;let l=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,m=[],u;while((u=l.exec(c))!==null)m.push({name:u[1],value:u[2]});m.sort((g,y)=>{if(g.name==="id")return-1;if(y.name==="id")return 1;if(g.name==="class")return-1;if(y.name==="class")return 1;return g.name.localeCompare(y.name)});let h=m.map((g)=>g.value?`${g.name}=${g.value}`:g.name).join(" ");return`<${p}${h?` ${h}`:""}>`})}import bn from"fs";import qt from"path";async function oo(t="index.stx",s={}){try{let i=s.force||!1,p=qt.resolve(process.cwd(),t);if(await Bun.file(p).exists()){if(!i)throw Error(`File ${t} already exists. Use --force to overwrite.`);console.warn(`File ${t} already exists. Overwriting...`)}let c=qt.dirname(p);if(!bn.existsSync(c))bn.mkdirSync(c,{recursive:!0});let l;if(s.template){let m=qt.resolve(process.cwd(),s.template);if(!await Bun.file(m).exists())throw Error(`Template file ${s.template} does not exist.`);if(!m.endsWith(".stx"))console.warn(`Warning: Template file ${s.template} does not have a .stx extension. Using it anyway.`);l=await Bun.file(m).text(),console.warn(`Using template from ${s.template}`)}else if(s.preset)l=xn(s.preset),console.warn(`Using '${s.preset}' preset template`);else l=xn("basic");return await Bun.write(p,l),console.warn(`Created new stx file: ${t}`),!0}catch(i){return console.error(`Error creating file: ${i instanceof Error?i.message:String(i)}`),!1}}function xn(t){switch(t){case"basic":return vn();case"component":return Co();case"layout":return Ro();case"blog":return Eo();case"api":return Po();case"app":return Oo();default:return vn()}}function vn(){return`<script>
1606
+ `)||c.includes("@"))return i;let l=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,m=[],u;while((u=l.exec(c))!==null)m.push({name:u[1],value:u[2]});m.sort((g,y)=>{if(g.name==="id")return-1;if(y.name==="id")return 1;if(g.name==="class")return-1;if(y.name==="class")return 1;return g.name.localeCompare(y.name)});let h=m.map((g)=>g.value?`${g.name}=${g.value}`:g.name).join(" ");return`<${p}${h?` ${h}`:""}>`})}import bn from"fs";import qt from"path";async function ao(t="index.stx",s={}){try{let i=s.force||!1,p=qt.resolve(process.cwd(),t);if(await Bun.file(p).exists()){if(!i)throw Error(`File ${t} already exists. Use --force to overwrite.`);console.warn(`File ${t} already exists. Overwriting...`)}let c=qt.dirname(p);if(!bn.existsSync(c))bn.mkdirSync(c,{recursive:!0});let l;if(s.template){let m=qt.resolve(process.cwd(),s.template);if(!await Bun.file(m).exists())throw Error(`Template file ${s.template} does not exist.`);if(!m.endsWith(".stx"))console.warn(`Warning: Template file ${s.template} does not have a .stx extension. Using it anyway.`);l=await Bun.file(m).text(),console.warn(`Using template from ${s.template}`)}else if(s.preset)l=xn(s.preset),console.warn(`Using '${s.preset}' preset template`);else l=xn("basic");return await Bun.write(p,l),console.warn(`Created new stx file: ${t}`),!0}catch(i){return console.error(`Error creating file: ${i instanceof Error?i.message:String(i)}`),!1}}function xn(t){switch(t){case"basic":return vn();case"component":return Co();case"layout":return Ro();case"blog":return Eo();case"api":return Po();case"app":return Oo();default:return vn()}}function vn(){return`<script>
1607
1607
  const title = "My stx Page"
1608
1608
  const description = "A page built with stx"
1609
1609
  const features = [
@@ -2029,5 +2029,5 @@ const features = [
2029
2029
  })();
2030
2030
  </script>
2031
2031
  </body>
2032
- </html>`}var io="f9c3713";function Qi(t){return t}function ea(t){return t}function eo(t,s){let i=[],p=`${s}=`;for(let c=0;c<t.length;c++){let l=t[c];if(l.startsWith(p)){let m=l.slice(p.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 _e from"fs";import Te from"path";function Dn(t){try{return _e.statSync(t).mtimeMs}catch{return null}}function Mt(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 Di(t,s){try{return globalThis.Bun?.resolveSync(t,s)??null}catch{return null}}function Mn(t,s="stx"){let i=Te.resolve(t);for(let p=0;p<10;p++){let c=Te.join(i,"pantry","@stacksjs",s);if(_e.existsSync(c))return c;let l=Te.dirname(i);if(l===i)break;i=l}return null}var _n=["@stacksjs/stx","bun-plugin-stx"];function Mi(t){try{let s=_e.readFileSync(Te.join(t,"package.json"),"utf8"),i=JSON.parse(s)?.version;return typeof i==="string"?i:null}catch{return null}}function _i(t,s=6){let i=Te.resolve(t),p=[],c=new Set;function l(u,h){if(h>s)return;let g;try{g=_e.realpathSync(u)}catch{return}if(c.has(g))return;c.add(g);for(let w of _n){let S=Te.join(u,w),R=Mi(S);if(R!==null)p.push({name:w,version:R,dir:Te.relative(i,S)||S,nested:h>0})}let y;try{y=_e.readdirSync(u,{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=Te.join(u,w.name);if(w.name.startsWith("@")){let v;try{v=_e.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let x of v){let C=Te.join(S,x.name,"node_modules");if(_e.existsSync(C))l(C,h+1)}continue}let R=Te.join(S,"node_modules");if(_e.existsSync(R))l(R,h+1)}}let m=Te.join(i,"node_modules");if(_e.existsSync(m))l(m,0);return p}function Li(t){let s=[];for(let i of _n){let p=t.filter((m)=>m.name===i);if(p.length<=1)continue;let c=[...new Set(p.map((m)=>m.version))],l=p.map((m)=>`${m.version} at ${m.dir}`).join("; ");if(c.length===1){s.push({name:`${i} copies`,status:"info",detail:`${p.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 Cr(t={}){let s=t.cwd?Te.resolve(t.cwd):process.cwd(),i=t.resolve??Di,p=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 Li(_i(s)))c.push(h);let u=Mn(s,"stx");if(!u)c.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let h=Te.join(u,"src/signals.ts"),g=[Te.join(u,"dist/index.js"),Te.join(u,"dist/signals.js")].find((v)=>_e.existsSync(v))||null,y=Dn(h),w=g?Dn(g):null;if(y==null)c.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${u} 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 ${u} && bun build.ts`});else if(w<y){let v=Math.round((y-w)/1000);c.push({name:"pantry dist freshness",status:"error",detail:`dist (${Mt(w,p)}) is OLDER than src/signals.ts (${Mt(y,p)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${u} && bun build.ts`})}else c.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Mt(y,p)}, dist ${Mt(w,p)})`});let S=Te.join(s,"node_modules/@stacksjs/stx"),R=null;try{R=_e.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=_e.realpathSync(S)}catch{}let x=(()=>{try{return _e.realpathSync(u)}catch{return u}})();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 _r(t){let s={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},i=["stx runtime resolution:"];for(let p of t.checks)if(i.push(` ${s[p.status]} ${p.name}: ${p.detail}`),p.fix)i.push(` \u2192 ${p.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
- `)}export{eo,to,no,ro,kr,so,oo,io,Qi,ea,Cr,_r,Pn,In,On};
2032
+ </html>`}var co="f9c3713";function ta(t){return t}function na(t){return t}function no(t,s){let i=[],p=`${s}=`;for(let c=0;c<t.length;c++){let l=t[c];if(l.startsWith(p)){let m=l.slice(p.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 _e from"fs";import Te from"path";function An(t){try{return _e.statSync(t).mtimeMs}catch{return null}}function Mt(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 Di(t,s){try{return globalThis.Bun?.resolveSync(t,s)??null}catch{return null}}function Mn(t,s="stx"){let i=Te.resolve(t);for(let p=0;p<10;p++){let c=Te.join(i,"pantry","@stacksjs",s);if(_e.existsSync(c))return c;let l=Te.dirname(i);if(l===i)break;i=l}return null}var _n=["@stacksjs/stx","bun-plugin-stx"];function Mi(t){try{let s=_e.readFileSync(Te.join(t,"package.json"),"utf8"),i=JSON.parse(s)?.version;return typeof i==="string"?i:null}catch{return null}}function _i(t,s=6){let i=Te.resolve(t),p=[],c=new Set;function l(u,h){if(h>s)return;let g;try{g=_e.realpathSync(u)}catch{return}if(c.has(g))return;c.add(g);for(let w of _n){let S=Te.join(u,w),R=Mi(S);if(R!==null)p.push({name:w,version:R,dir:Te.relative(i,S)||S,nested:h>0})}let y;try{y=_e.readdirSync(u,{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=Te.join(u,w.name);if(w.name.startsWith("@")){let v;try{v=_e.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let x of v){let C=Te.join(S,x.name,"node_modules");if(_e.existsSync(C))l(C,h+1)}continue}let R=Te.join(S,"node_modules");if(_e.existsSync(R))l(R,h+1)}}let m=Te.join(i,"node_modules");if(_e.existsSync(m))l(m,0);return p}function Li(t){let s=[];for(let i of _n){let p=t.filter((m)=>m.name===i);if(p.length<=1)continue;let c=[...new Set(p.map((m)=>m.version))],l=p.map((m)=>`${m.version} at ${m.dir}`).join("; ");if(c.length===1){s.push({name:`${i} copies`,status:"info",detail:`${p.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 _r(t={}){let s=t.cwd?Te.resolve(t.cwd):process.cwd(),i=t.resolve??Di,p=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 Li(_i(s)))c.push(h);let u=Mn(s,"stx");if(!u)c.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let h=Te.join(u,"src/signals.ts"),g=[Te.join(u,"dist/index.js"),Te.join(u,"dist/signals.js")].find((v)=>_e.existsSync(v))||null,y=An(h),w=g?An(g):null;if(y==null)c.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${u} 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 ${u} && bun build.ts`});else if(w<y){let v=Math.round((y-w)/1000);c.push({name:"pantry dist freshness",status:"error",detail:`dist (${Mt(w,p)}) is OLDER than src/signals.ts (${Mt(y,p)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${u} && bun build.ts`})}else c.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Mt(y,p)}, dist ${Mt(w,p)})`});let S=Te.join(s,"node_modules/@stacksjs/stx"),R=null;try{R=_e.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=_e.realpathSync(S)}catch{}let x=(()=>{try{return _e.realpathSync(u)}catch{return u}})();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 Er(t){let s={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},i=["stx runtime resolution:"];for(let p of t.checks)if(i.push(` ${s[p.status]} ${p.name}: ${p.detail}`),p.fix)i.push(` \u2192 ${p.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
+ `)}export{no,ro,so,oo,Cr,io,ao,co,ta,na,_r,Er,In,On,Dn};