@stacksjs/stx 0.2.771 → 0.2.774

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 (250) hide show
  1. package/dist/app-shell.d.ts +10 -0
  2. package/dist/app-shell.js +3 -0
  3. package/dist/{chunk-nk4jhdnk.js → chunk-06wqf3t8.js} +3 -3
  4. package/dist/chunk-08c2c9ee.js +2 -0
  5. package/dist/chunk-0jvrzpfs.js +2 -0
  6. package/dist/chunk-0perf9at.js +2 -0
  7. package/dist/{chunk-e6az23ep.js → chunk-1frxaa7e.js} +59 -59
  8. package/dist/{chunk-bwv5j7z3.js → chunk-1hdhfc4w.js} +6 -6
  9. package/dist/chunk-1msebzht.js +2 -0
  10. package/dist/chunk-1tvb2stj.js +2 -0
  11. package/dist/{chunk-v3kynq6v.js → chunk-200z6ew1.js} +5 -5
  12. package/dist/{chunk-krdc3c87.js → chunk-20afyff6.js} +3 -3
  13. package/dist/{chunk-p1mbbdwj.js → chunk-27rzdq3n.js} +2 -2
  14. package/dist/{chunk-xaqtk05e.js → chunk-2gqhfge6.js} +2 -2
  15. package/dist/chunk-2vnhyter.js +2 -0
  16. package/dist/{chunk-4833k99b.js → chunk-2yxva96k.js} +2 -2
  17. package/dist/{chunk-477gjb2b.js → chunk-416jy1m5.js} +2 -2
  18. package/dist/chunk-47qestfz.js +2 -0
  19. package/dist/chunk-4kx7pw6x.js +2 -0
  20. package/dist/{chunk-x148cxrj.js → chunk-4wc5pc19.js} +4 -4
  21. package/dist/{chunk-3csfmhg0.js → chunk-5emrarpf.js} +2 -2
  22. package/dist/{chunk-erjp2w63.js → chunk-5mng4x26.js} +5 -5
  23. package/dist/{chunk-bwzjjxnj.js → chunk-605b93pe.js} +4 -4
  24. package/dist/{chunk-g53y0v3f.js → chunk-6smzs5vp.js} +10 -10
  25. package/dist/chunk-6xapz9dx.js +2 -0
  26. package/dist/chunk-713az4kg.js +2 -0
  27. package/dist/{chunk-2g7yg3na.js → chunk-79b3sbft.js} +6 -6
  28. package/dist/chunk-7fhw11qd.js +2 -0
  29. package/dist/{chunk-6sa5adg6.js → chunk-7gdwvnwc.js} +2 -2
  30. package/dist/{chunk-g4k0svq6.js → chunk-7qk4exw1.js} +2 -2
  31. package/dist/{chunk-wmnzapn8.js → chunk-7sh9fa3q.js} +2 -2
  32. package/dist/chunk-7y2h7nfd.js +2 -0
  33. package/dist/chunk-7y6ad89y.js +2 -0
  34. package/dist/chunk-8dby49s0.js +2 -0
  35. package/dist/chunk-8ds59ttd.js +2 -0
  36. package/dist/{chunk-c9ygnsx5.js → chunk-8k4j2xv8.js} +68 -68
  37. package/dist/{chunk-4qng287p.js → chunk-8nb8b0nf.js} +2 -2
  38. package/dist/chunk-8pyyqev1.js +2 -0
  39. package/dist/chunk-8qhznykd.js +177 -0
  40. package/dist/{chunk-83fh7j8g.js → chunk-985afhhy.js} +2 -2
  41. package/dist/chunk-9896204h.js +2 -0
  42. package/dist/{chunk-2vbgm9t4.js → chunk-9ct3gbyv.js} +6 -6
  43. package/dist/{chunk-yzbdm457.js → chunk-9f6qx8b9.js} +2 -2
  44. package/dist/{chunk-qmwaqdc1.js → chunk-9jfva11p.js} +17 -17
  45. package/dist/chunk-9qwkyt81.js +2 -0
  46. package/dist/{chunk-tahdfsp4.js → chunk-9tec9eap.js} +2 -2
  47. package/dist/{chunk-f7h5ty84.js → chunk-9z6331xs.js} +2 -2
  48. package/dist/{chunk-cn7d3389.js → chunk-a10y92qp.js} +30 -30
  49. package/dist/{chunk-81x4xnv9.js → chunk-a7f2xqsh.js} +9 -9
  50. package/dist/{chunk-6d1jmx97.js → chunk-abfphkss.js} +9 -9
  51. package/dist/{chunk-vht2rhrj.js → chunk-ady8cnpb.js} +5 -5
  52. package/dist/chunk-aj5b9dm3.js +2 -0
  53. package/dist/chunk-ajj56vrw.js +2 -0
  54. package/dist/{chunk-spr5bxm8.js → chunk-ajmexj79.js} +1 -1
  55. package/dist/chunk-b3b9tfpx.js +2 -0
  56. package/dist/{chunk-3jv81hw3.js → chunk-bengxr5p.js} +3 -3
  57. package/dist/{chunk-efr9dgt6.js → chunk-bgc2fm73.js} +2 -2
  58. package/dist/{chunk-wabahwkj.js → chunk-bmfk3b29.js} +2 -2
  59. package/dist/{chunk-5s2dwh5z.js → chunk-bq9xf8nq.js} +16 -16
  60. package/dist/{chunk-zkwtrmwg.js → chunk-br91e06f.js} +2 -2
  61. package/dist/{chunk-hgm6f2t2.js → chunk-c0ejyxfj.js} +3 -3
  62. package/dist/{chunk-pqyhxpa6.js → chunk-c85dv6tv.js} +5 -5
  63. package/dist/chunk-c91y14ae.js +2 -0
  64. package/dist/{chunk-dmj9gk6d.js → chunk-cfpw4c6b.js} +2 -2
  65. package/dist/chunk-cgamtmxv.js +2 -0
  66. package/dist/chunk-cpq9b0fx.js +2 -0
  67. package/dist/{chunk-m207mdpy.js → chunk-cz8mka1b.js} +2 -2
  68. package/dist/{chunk-rkz3k2td.js → chunk-d18xd9x5.js} +3 -3
  69. package/dist/chunk-defwzg9q.js +2 -0
  70. package/dist/chunk-drwa5hjd.js +2 -0
  71. package/dist/{chunk-nbwmcm2p.js → chunk-dvcfhx4y.js} +6 -6
  72. package/dist/chunk-dxp022r0.js +2 -0
  73. package/dist/{chunk-xr28hjkp.js → chunk-e1gxykm8.js} +7 -7
  74. package/dist/{chunk-38c5cw2c.js → chunk-e7477r0v.js} +1 -1
  75. package/dist/{chunk-7h0mjwkq.js → chunk-eapt899m.js} +5 -5
  76. package/dist/{chunk-qtja7fpr.js → chunk-et1vz3wd.js} +2 -2
  77. package/dist/{chunk-m0deyakx.js → chunk-evb5y7sm.js} +6 -6
  78. package/dist/chunk-fbv7byxx.js +2 -0
  79. package/dist/chunk-fgstg93m.js +2 -0
  80. package/dist/chunk-fmzfmh9n.js +2 -0
  81. package/dist/{chunk-ssd9g1wz.js → chunk-fpn4dren.js} +1 -1
  82. package/dist/chunk-ft994mav.js +2 -0
  83. package/dist/chunk-gbgbhpms.js +2 -0
  84. package/dist/{chunk-cn7zpm1x.js → chunk-gbx5vw81.js} +5 -5
  85. package/dist/chunk-gdkcskm7.js +2 -0
  86. package/dist/chunk-gxp9ms4w.js +2 -0
  87. package/dist/chunk-hc0c0p0r.js +2 -0
  88. package/dist/{chunk-w07n2ddj.js → chunk-he85ksa7.js} +2 -2
  89. package/dist/chunk-hr8rzzcn.js +2 -0
  90. package/dist/{chunk-yjdnfxm7.js → chunk-j576e8tm.js} +3 -3
  91. package/dist/chunk-jdj1358b.js +3 -0
  92. package/dist/chunk-jpnptbtm.js +2 -0
  93. package/dist/{chunk-jasfbhp3.js → chunk-k003phkg.js} +7 -7
  94. package/dist/{chunk-z5vkzbct.js → chunk-k0aejzg9.js} +4 -4
  95. package/dist/{chunk-0wj31pqy.js → chunk-k3rcpnzm.js} +2 -2
  96. package/dist/{chunk-nnzmbfjq.js → chunk-k4bdf0dw.js} +3 -3
  97. package/dist/chunk-k9dg3nyy.js +2 -0
  98. package/dist/{chunk-ddhazq2g.js → chunk-kf8hzvb7.js} +3 -3
  99. package/dist/{chunk-rc4zsymn.js → chunk-kr8qdg0r.js} +2 -2
  100. package/dist/chunk-m1rdq29w.js +2 -0
  101. package/dist/chunk-m3qmj9ec.js +2 -0
  102. package/dist/{chunk-2bm97z09.js → chunk-m4mpyq3d.js} +3 -3
  103. package/dist/{chunk-g9kgxx0t.js → chunk-m6nkaxcc.js} +3 -3
  104. package/dist/chunk-m90wyzhd.js +2 -0
  105. package/dist/chunk-mcevnfnx.js +2 -0
  106. package/dist/{chunk-am4wadh7.js → chunk-mv3yhspn.js} +2 -2
  107. package/dist/chunk-ndjmt3vg.js +3 -0
  108. package/dist/chunk-nmtwqvq2.js +3 -0
  109. package/dist/chunk-nthzdhsf.js +2 -0
  110. package/dist/chunk-nx20kccb.js +2 -0
  111. package/dist/chunk-p43hw6ef.js +2 -0
  112. package/dist/{chunk-4fkxm22d.js → chunk-p45mzeek.js} +2 -2
  113. package/dist/{chunk-55rg4qyr.js → chunk-p7p3b4s1.js} +2 -2
  114. package/dist/{chunk-snbnhqn3.js → chunk-pebsj489.js} +10 -10
  115. package/dist/chunk-q71qqjy7.js +2 -0
  116. package/dist/{chunk-zs35vgyy.js → chunk-qa6r6mj6.js} +4 -4
  117. package/dist/{chunk-6b32wt31.js → chunk-qby3e5nm.js} +30 -30
  118. package/dist/chunk-qezg1070.js +2 -0
  119. package/dist/{chunk-ngzdcvry.js → chunk-qfcn4btf.js} +1 -1
  120. package/dist/{chunk-4q292036.js → chunk-qmj7g7s8.js} +6 -6
  121. package/dist/chunk-qtcxy3y3.js +2 -0
  122. package/dist/{chunk-618d3ng3.js → chunk-r1jzbqr3.js} +6 -6
  123. package/dist/chunk-r5qfxd9s.js +2 -0
  124. package/dist/{chunk-qk61pv1v.js → chunk-ra8f8sm2.js} +15 -10
  125. package/dist/chunk-rgsb3f0j.js +2 -0
  126. package/dist/{chunk-s369wfsp.js → chunk-rr58ynsn.js} +6 -6
  127. package/dist/chunk-s53psb1j.js +2 -0
  128. package/dist/{chunk-ddjkt87h.js → chunk-sxwgq49z.js} +1 -1
  129. package/dist/chunk-t482tgm6.js +2 -0
  130. package/dist/{chunk-91q55gjp.js → chunk-td3qp5my.js} +3 -3
  131. package/dist/chunk-tsvnhc0c.js +4 -0
  132. package/dist/{chunk-qr5ddqbf.js → chunk-tyjzye2d.js} +2 -2
  133. package/dist/{chunk-2s0157xg.js → chunk-vadbp45n.js} +3 -3
  134. package/dist/{chunk-nj2q40p8.js → chunk-vct6dec8.js} +2 -2
  135. package/dist/{chunk-e6ynacgc.js → chunk-vgd3r8g7.js} +2 -2
  136. package/dist/{chunk-1925kbjc.js → chunk-w9d18r1t.js} +1 -1
  137. package/dist/{chunk-5t33zwwg.js → chunk-wj78td69.js} +1 -1
  138. package/dist/{chunk-afxt272e.js → chunk-wm65y47g.js} +14 -14
  139. package/dist/chunk-wm8wz183.js +2 -0
  140. package/dist/chunk-wn7wmjcr.js +2 -0
  141. package/dist/chunk-x0e0pcn0.js +2 -0
  142. package/dist/chunk-x756yzrc.js +2 -0
  143. package/dist/{chunk-07thf07b.js → chunk-x8anspa5.js} +2 -2
  144. package/dist/{chunk-cak9fp9b.js → chunk-x8js27hd.js} +7 -7
  145. package/dist/chunk-xad5fg2a.js +2 -0
  146. package/dist/chunk-xj5v9rnx.js +2 -0
  147. package/dist/chunk-xq2tfg4v.js +2 -0
  148. package/dist/{chunk-vke28xq8.js → chunk-y38swh5t.js} +2 -2
  149. package/dist/{chunk-pgkcbm6g.js → chunk-y5f04xtb.js} +2 -2
  150. package/dist/{chunk-z1br7qeb.js → chunk-yewd8836.js} +4 -4
  151. package/dist/chunk-ypmx0jhd.js +2 -0
  152. package/dist/chunk-yrdxvphr.js +2 -0
  153. package/dist/chunk-yx563gzr.js +2 -0
  154. package/dist/{chunk-x0qtgyqr.js → chunk-yzs2afn7.js} +9 -9
  155. package/dist/{chunk-nwhv1889.js → chunk-z2m9p8xe.js} +3 -3
  156. package/dist/{chunk-xw8ygkyb.js → chunk-zbgh573z.js} +2 -2
  157. package/dist/chunk-zccysq9p.js +3 -0
  158. package/dist/chunk-zh8w0nb6.js +2 -0
  159. package/dist/{chunk-79x0812m.js → chunk-zxfptbac.js} +2 -2
  160. package/dist/cli.js +20 -20
  161. package/dist/client/signals-dom-ready-runtime.js +6 -1
  162. package/dist/craft-entry.js +2 -2
  163. package/dist/craft.js +2 -2
  164. package/dist/dev-server/serve-app.js +2 -2
  165. package/dist/native/bridge/protocol.d.ts +1 -1
  166. package/dist/native/compiler/headwind-to-style.d.ts +2 -10
  167. package/dist/native/compiler/headwind-to-style.js +31 -2
  168. package/dist/native/compiler/html-to-ir.js +14 -4
  169. package/dist/native/compiler/ir.d.ts +3 -0
  170. package/dist/native/event-names.js +14 -1
  171. package/dist/native/prop-names.js +8 -1
  172. package/dist/native/runtime/craft-bridge.js +7 -1
  173. package/dist/native/runtime/craft.d.ts +1 -1
  174. package/dist/native/runtime/native-host.d.ts +1 -0
  175. package/dist/native/runtime/native-host.js +8 -2
  176. package/dist/native/runtime/shared-screen.js +1 -0
  177. package/dist/native/testing.d.ts +1 -1
  178. package/dist/production-server.js +5 -5
  179. package/dist/pwa.js +3 -3
  180. package/dist/ssg.js +10 -10
  181. package/package.json +5 -5
  182. package/dist/chunk-0qgdex7z.js +0 -2
  183. package/dist/chunk-1gpvkgb0.js +0 -2
  184. package/dist/chunk-1se5y83a.js +0 -2
  185. package/dist/chunk-1y4agex5.js +0 -2
  186. package/dist/chunk-2p301rsb.js +0 -2
  187. package/dist/chunk-2zg3jmy7.js +0 -2
  188. package/dist/chunk-33gccrx0.js +0 -2
  189. package/dist/chunk-3jkbs3fc.js +0 -2
  190. package/dist/chunk-3pxche1k.js +0 -2
  191. package/dist/chunk-3vankrf5.js +0 -2
  192. package/dist/chunk-4tvty67c.js +0 -2
  193. package/dist/chunk-4xdapekt.js +0 -2
  194. package/dist/chunk-4xzk9529.js +0 -3
  195. package/dist/chunk-53md2scd.js +0 -2
  196. package/dist/chunk-5c4g0v5g.js +0 -2
  197. package/dist/chunk-5g5v7yns.js +0 -2
  198. package/dist/chunk-6weh2dhz.js +0 -177
  199. package/dist/chunk-75st1ttq.js +0 -2
  200. package/dist/chunk-7k95121a.js +0 -2
  201. package/dist/chunk-7p4tvw5x.js +0 -2
  202. package/dist/chunk-825zg5ar.js +0 -2
  203. package/dist/chunk-83aq0n9s.js +0 -2
  204. package/dist/chunk-83c3vrbg.js +0 -3
  205. package/dist/chunk-9pgnhayn.js +0 -2
  206. package/dist/chunk-9vgkp3nj.js +0 -2
  207. package/dist/chunk-9za2wr5r.js +0 -2
  208. package/dist/chunk-ba43drcj.js +0 -2
  209. package/dist/chunk-bpbhjn4w.js +0 -2
  210. package/dist/chunk-cgv3r6q9.js +0 -2
  211. package/dist/chunk-cnt08b67.js +0 -2
  212. package/dist/chunk-e645nk33.js +0 -4
  213. package/dist/chunk-g3sgf16e.js +0 -2
  214. package/dist/chunk-g5ebz7hm.js +0 -2
  215. package/dist/chunk-g6m3q9n4.js +0 -2
  216. package/dist/chunk-h2ymq7fa.js +0 -2
  217. package/dist/chunk-hnen9b45.js +0 -2
  218. package/dist/chunk-hy91tn1w.js +0 -2
  219. package/dist/chunk-j46nvncc.js +0 -2
  220. package/dist/chunk-jjvrm2j8.js +0 -2
  221. package/dist/chunk-k4pwpr5q.js +0 -2
  222. package/dist/chunk-kh0szwf3.js +0 -2
  223. package/dist/chunk-kzx3t7q6.js +0 -2
  224. package/dist/chunk-mvfj17fr.js +0 -2
  225. package/dist/chunk-nmjgcw4g.js +0 -2
  226. package/dist/chunk-p454tj1h.js +0 -2
  227. package/dist/chunk-p7ksex4f.js +0 -2
  228. package/dist/chunk-q245q8z1.js +0 -2
  229. package/dist/chunk-q4m5p4wx.js +0 -2
  230. package/dist/chunk-q85s8ne0.js +0 -2
  231. package/dist/chunk-qy01jdzk.js +0 -2
  232. package/dist/chunk-rfp5f55f.js +0 -2
  233. package/dist/chunk-tk17tjzw.js +0 -2
  234. package/dist/chunk-tw2c09tw.js +0 -2
  235. package/dist/chunk-tynz075x.js +0 -2
  236. package/dist/chunk-v0tewfbx.js +0 -2
  237. package/dist/chunk-vdxjyrjf.js +0 -3
  238. package/dist/chunk-vk494kgn.js +0 -2
  239. package/dist/chunk-vyr8zzyr.js +0 -2
  240. package/dist/chunk-w1sjp421.js +0 -2
  241. package/dist/chunk-wq0wbvgd.js +0 -2
  242. package/dist/chunk-wr6b3a1w.js +0 -2
  243. package/dist/chunk-wwnqbv9j.js +0 -3
  244. package/dist/chunk-x3xtyr95.js +0 -2
  245. package/dist/chunk-xb16yy2x.js +0 -2
  246. package/dist/chunk-y7df8y9a.js +0 -2
  247. package/dist/chunk-ybd2tfqm.js +0 -2
  248. package/dist/chunk-yrh9yfnv.js +0 -2
  249. package/dist/chunk-ysm6gaq9.js +0 -2
  250. package/dist/chunk-z6xfmrtc.js +0 -2
@@ -1,11 +1,11 @@
1
1
  // @bun
2
- import{oe,de,fn,It,Ot,m,r,fe,p}from"./chunk-e6az23ep.js";import{ht,Re,ec,rs,Po,Io,i}from"./chunk-cn7d3389.js";import{ae,Cr,ke,B,xn}from"./chunk-5s2dwh5z.js";import{xt,dr,Cs,Es,Ts,St,kt,_t,Ct,Et,Tt,Qe}from"./chunk-z1br7qeb.js";import{ws,a,P}from"./chunk-qmwaqdc1.js";import{pt,Rn,Ce,M,sa,po,Wr,We,oa,Ee}from"./chunk-s369wfsp.js";import{cr,lr}from"./chunk-4fkxm22d.js";import{Tn}from"./chunk-vdxjyrjf.js";import{e,an,rr,y}from"./chunk-6d1jmx97.js";import{Ge}from"./chunk-81x4xnv9.js";import{$e}from"./chunk-wmnzapn8.js";import{X,be,we}from"./chunk-jasfbhp3.js";import{l}from"./chunk-4xzk9529.js";import{K}from"./chunk-wabahwkj.js";async function zn(t){try{let n=await Bun.file(t).text(),o=Nn(n),d=Un(n,t),s=Wn(n,o),c=Vn(n,o);return{file:t,metrics:o,issues:d,suggestions:s,performance:c}}catch(n){throw Error(`Failed to analyze template ${t}: ${n instanceof Error?n.message:String(n)}`)}}function Nn(t){let n=t.split(`
2
+ import{oe,de,gn,Ot,Nt,m,r,fe,p}from"./chunk-1frxaa7e.js";import{yt,Re,tc,ss,Io,Oo,i}from"./chunk-a10y92qp.js";import{ae,Er,ke,B,Sn}from"./chunk-bq9xf8nq.js";import{St,pr,Es,Ts,$s,kt,_t,Ct,Et,Tt,$t,et}from"./chunk-yewd8836.js";import{vs,a,P}from"./chunk-9jfva11p.js";import{ft,An,Ce,M,oa,fo,qr,We,ia,qe,Ee}from"./chunk-rr58ynsn.js";import{lr,ur}from"./chunk-p45mzeek.js";import{$n}from"./chunk-nmtwqvq2.js";import{e,cn,sr,y}from"./chunk-abfphkss.js";import{Je}from"./chunk-a7f2xqsh.js";import{$e}from"./chunk-7sh9fa3q.js";import{X,be,we}from"./chunk-k003phkg.js";import{l}from"./chunk-jdj1358b.js";import{K}from"./chunk-bmfk3b29.js";async function Nn(t){try{let n=await Bun.file(t).text(),o=Un(n),d=Wn(n,t),s=Vn(n,o),c=qn(n,o);return{file:t,metrics:o,issues:d,suggestions:s,performance:c}}catch(n){throw Error(`Failed to analyze template ${t}: ${n instanceof Error?n.message:String(n)}`)}}function Un(t){let n=t.split(`
3
3
  `),o=t.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),s=(o?o[1]:"").split(`
4
- `).length,c={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};c.total=c.conditionals+c.loops+c.includes+c.custom;let u=(t.match(/\{\{[\s\S]*?\}\}/g)||[]).length,f=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,g=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,h=u+f+g,x=(t.match(/<[A-Z][^>]*>/g)||[]).length,v=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,T=0;for(let k of n)if(/@(?:if|unless|foreach|for|while|section)\b/.test(k)&&!/@end/.test(k)&&!/@else/.test(k))T++,S=Math.max(S,T);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(k))T--;let w=S>=4?3:0,b=Math.min(10,Math.ceil(c.total*0.5+h*0.1+x*0.3+(s>10?s*0.05:0)+w));return{lines:n.length,characters:t.length,directives:c,expressions:h,components:x,layouts:v,scriptLines:s,complexity:b}}function Un(t,n){let o=[],d=Kt(t,"if","endif");if(d>0)o.push({type:"error",category:"syntax",message:`Found ${d} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let s=Kt(t,"foreach","endforeach");if(s>0)o.push({type:"error",category:"syntax",message:`Found ${s} unmatched @foreach directive(s)`,suggestion:"Ensure every @foreach has a corresponding @endforeach"});let c=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(c&&c.length>0)o.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let u=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(u>0)o.push({type:"warning",category:"security",message:`Found ${u} raw output expression(s) {!! !!}`,suggestion:"Ensure raw outputs are properly sanitized to prevent XSS"});let f=t.match(/<img[^>]*>/g);if(f){let x=f.filter((v)=>!v.includes("alt="));if(x.length>0)o.push({type:"warning",category:"accessibility",message:`Found ${x.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let g=t.split(`
5
- `).filter((x)=>x.length>120);if(g.length>0)o.push({type:"info",category:"maintainability",message:`Found ${g.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let h=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(h>3)o.push({type:"info",category:"maintainability",message:`Found ${h} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return o}function Wn(t,n){let o=[];if(n.complexity>7)o.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(n.complexity>5&&n.directives.total>8)o.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(n.lines>100&&n.components===0)o.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(n.expressions>20)o.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let d=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(d&&d.length>0)o.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(n.directives.total===0&&n.expressions<5)o.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(n.scriptLines>50)o.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return o}function Vn(t,n){let o=1;if(o+=n.directives.conditionals*0.1,o+=n.directives.loops*0.5,o+=n.directives.includes*2,o+=n.expressions*0.05,o+=n.components*1,n.scriptLines>10)o+=n.scriptLines*0.1;let d;if(n.expressions===0&&n.directives.total===0)d="high";else if(n.expressions<5&&n.directives.total<3)d="medium";else d="low";let s=[];if(o>10)s.push("Consider optimizing template complexity");if(d==="low"&&n.directives.total>5)s.push("Reduce dynamic content for better caching");if(n.components===0&&n.lines>40)s.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(o*100)/100,complexityScore:n.complexity,cacheability:d,recommendations:s}}function Kt(t,n,o){let d=t.replace(/<!--[\s\S]*?-->/g,""),s=(d.match(new RegExp(`@${n}\\b`,"g"))||[]).length,c=(d.match(new RegExp(`@${o}\\b`,"g"))||[]).length;return Math.abs(s-c)}async function qi(t=["**/*.stx"],n){let o=[],d=[];for(let c of t){let u=await Array.fromAsync(new Bun.Glob(c).scan({cwd:n||process.cwd(),onlyFiles:!0,absolute:!0}));d.push(...u.filter((f)=>f.endsWith(".stx")))}for(let c of d)try{let u=await zn(c);o.push(u)}catch(u){console.warn(`Failed to analyze ${c}:`,u)}let s=qn(o);return{results:o,summary:s}}function qn(t){let n=t.length,o=t.reduce((h,x)=>h+x.metrics.lines,0),d=n>0?t.reduce((h,x)=>h+x.metrics.complexity,0)/n:0,s=t.reduce((h,x)=>h+x.issues.length,0),c={};t.forEach((h)=>{h.issues.forEach((x)=>{c[x.category]=(c[x.category]||0)+1})});let u=n>0?t.reduce((h,x)=>h+x.performance.estimatedRenderTime,0)/n:0,f=Math.max(1,Math.min(10,Math.round(10-u/2-d/2))),g=[];if(d>6)g.push("Project has high average complexity. Consider refactoring complex templates.");if(s>n*2)g.push("High number of issues detected. Run detailed analysis on individual files.");if(c.security>0)g.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:n,totalLines:o,avgComplexity:Math.round(d*100)/100,totalIssues:s,issuesByCategory:c,performanceScore:f,recommendations:g}}import{mkdir as Kn,readFile as Xn,readdir as Gn,stat as Xt,writeFile as Jn}from"fs/promises";import Te from"path";function en(t){if(t==="connectedCallback")return`method "${t}" is reserved; define "onConnect" instead, which the element calls once it is connected, rendered and bound`;if(t==="disconnectedCallback")return`method "${t}" is reserved; define "onDisconnect" instead, which the element calls as it leaves the DOM, before it releases its own listeners`;return`method "${t}" is reserved`}var tn=new Set(["constructor","connectedCallback","disconnectedCallback","attributeChangedCallback","adoptedCallback"]);function Yn(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((n)=>n.charAt(0).toUpperCase()+n.slice(1)).join("")}function Lt(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function Qn(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function Zn(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function er(t){let n=[];async function o(d){let s=await Gn(d,{withFileTypes:!0});s.sort((c,u)=>c.name.localeCompare(u.name));for(let c of s){let u=Te.join(d,c.name);if(c.isDirectory()){if(!c.name.startsWith(".")&&c.name!=="node_modules")await o(u)}else if(c.isFile()&&c.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(c.name))n.push(u)}}return await o(t),n}function tr(t,n){let o=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!o)return{};let d=o[1].trim();if(!d)return{};try{return JSON.parse(d)}catch(s){throw Error(`${n}: <script component> must contain JSON metadata (${s.message})`)}}function nr(t,n){let o={},d=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let s of d){if(!/\bclient\b/i.test(s[1])||/\bcomponent\b|\bstx:component\b/i.test(s[1]))continue;let c;try{c=new Bun.Transpiler({loader:"ts"}).transformSync(s[2])}catch(g){throw Error(`${n}: failed to transpile <script client> (${g.message})`)}let u=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,f;while(f=u.exec(c)){let g=f[1];if(tn.has(g))throw Error(`${n}: client ${en(g)}`);let h=u.lastIndex,x=1,v="",S=!1,T=h;for(;T<c.length&&x>0;T++){let b=c[T];if(S){S=!1;continue}if(v){if(b==="\\")S=!0;else if(b===v)v="";continue}if(b==='"'||b==="'"||b==="`")v=b;else if(b==="{")x++;else if(b==="}")x--}if(x!==0)throw Error(`${n}: unterminated client function "${g}"`);let w=f[0].includes("async")?"async ":"";o[g]=`${w}${g}(${f[2]}) {${c.slice(h,T-1)}}`,u.lastIndex=T}}return o}function or(t){let n=t.match(/<template\b(?![^>]*\bshadowrootmode\b)[^>]*>([\s\S]*?)<\/template>/i);return(n?n[1]:t).replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").trim()}function Gt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((n)=>n[1].trim()).filter(Boolean).join(`
4
+ `).length,c={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};c.total=c.conditionals+c.loops+c.includes+c.custom;let u=(t.match(/\{\{[\s\S]*?\}\}/g)||[]).length,f=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,g=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,h=u+f+g,x=(t.match(/<[A-Z][^>]*>/g)||[]).length,v=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,T=0;for(let k of n)if(/@(?:if|unless|foreach|for|while|section)\b/.test(k)&&!/@end/.test(k)&&!/@else/.test(k))T++,S=Math.max(S,T);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(k))T--;let w=S>=4?3:0,b=Math.min(10,Math.ceil(c.total*0.5+h*0.1+x*0.3+(s>10?s*0.05:0)+w));return{lines:n.length,characters:t.length,directives:c,expressions:h,components:x,layouts:v,scriptLines:s,complexity:b}}function Wn(t,n){let o=[],d=Xt(t,"if","endif");if(d>0)o.push({type:"error",category:"syntax",message:`Found ${d} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let s=Xt(t,"foreach","endforeach");if(s>0)o.push({type:"error",category:"syntax",message:`Found ${s} unmatched @foreach directive(s)`,suggestion:"Ensure every @foreach has a corresponding @endforeach"});let c=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(c&&c.length>0)o.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let u=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(u>0)o.push({type:"warning",category:"security",message:`Found ${u} raw output expression(s) {!! !!}`,suggestion:"Ensure raw outputs are properly sanitized to prevent XSS"});let f=t.match(/<img[^>]*>/g);if(f){let x=f.filter((v)=>!v.includes("alt="));if(x.length>0)o.push({type:"warning",category:"accessibility",message:`Found ${x.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let g=t.split(`
5
+ `).filter((x)=>x.length>120);if(g.length>0)o.push({type:"info",category:"maintainability",message:`Found ${g.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let h=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(h>3)o.push({type:"info",category:"maintainability",message:`Found ${h} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return o}function Vn(t,n){let o=[];if(n.complexity>7)o.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(n.complexity>5&&n.directives.total>8)o.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(n.lines>100&&n.components===0)o.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(n.expressions>20)o.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let d=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(d&&d.length>0)o.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(n.directives.total===0&&n.expressions<5)o.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(n.scriptLines>50)o.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return o}function qn(t,n){let o=1;if(o+=n.directives.conditionals*0.1,o+=n.directives.loops*0.5,o+=n.directives.includes*2,o+=n.expressions*0.05,o+=n.components*1,n.scriptLines>10)o+=n.scriptLines*0.1;let d;if(n.expressions===0&&n.directives.total===0)d="high";else if(n.expressions<5&&n.directives.total<3)d="medium";else d="low";let s=[];if(o>10)s.push("Consider optimizing template complexity");if(d==="low"&&n.directives.total>5)s.push("Reduce dynamic content for better caching");if(n.components===0&&n.lines>40)s.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(o*100)/100,complexityScore:n.complexity,cacheability:d,recommendations:s}}function Xt(t,n,o){let d=t.replace(/<!--[\s\S]*?-->/g,""),s=(d.match(new RegExp(`@${n}\\b`,"g"))||[]).length,c=(d.match(new RegExp(`@${o}\\b`,"g"))||[]).length;return Math.abs(s-c)}async function Ki(t=["**/*.stx"],n){let o=[],d=[];for(let c of t){let u=await Array.fromAsync(new Bun.Glob(c).scan({cwd:n||process.cwd(),onlyFiles:!0,absolute:!0}));d.push(...u.filter((f)=>f.endsWith(".stx")))}for(let c of d)try{let u=await Nn(c);o.push(u)}catch(u){console.warn(`Failed to analyze ${c}:`,u)}let s=Kn(o);return{results:o,summary:s}}function Kn(t){let n=t.length,o=t.reduce((h,x)=>h+x.metrics.lines,0),d=n>0?t.reduce((h,x)=>h+x.metrics.complexity,0)/n:0,s=t.reduce((h,x)=>h+x.issues.length,0),c={};t.forEach((h)=>{h.issues.forEach((x)=>{c[x.category]=(c[x.category]||0)+1})});let u=n>0?t.reduce((h,x)=>h+x.performance.estimatedRenderTime,0)/n:0,f=Math.max(1,Math.min(10,Math.round(10-u/2-d/2))),g=[];if(d>6)g.push("Project has high average complexity. Consider refactoring complex templates.");if(s>n*2)g.push("High number of issues detected. Run detailed analysis on individual files.");if(c.security>0)g.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:n,totalLines:o,avgComplexity:Math.round(d*100)/100,totalIssues:s,issuesByCategory:c,performanceScore:f,recommendations:g}}import{mkdir as Xn,readFile as Gn,readdir as Jn,stat as Gt,writeFile as Yn}from"fs/promises";import Te from"path";function tn(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 nn=new Set(["constructor","connectedCallback","disconnectedCallback","attributeChangedCallback","adoptedCallback"]);function Qn(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((n)=>n.charAt(0).toUpperCase()+n.slice(1)).join("")}function It(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function Zn(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function er(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function tr(t){let n=[];async function o(d){let s=await Jn(d,{withFileTypes:!0});s.sort((c,u)=>c.name.localeCompare(u.name));for(let c of s){let u=Te.join(d,c.name);if(c.isDirectory()){if(!c.name.startsWith(".")&&c.name!=="node_modules")await o(u)}else if(c.isFile()&&c.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(c.name))n.push(u)}}return await o(t),n}function nr(t,n){let o=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!o)return{};let d=o[1].trim();if(!d)return{};try{return JSON.parse(d)}catch(s){throw Error(`${n}: <script component> must contain JSON metadata (${s.message})`)}}function rr(t,n){let o={},d=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let s of d){if(!/\bclient\b/i.test(s[1])||/\bcomponent\b|\bstx:component\b/i.test(s[1]))continue;let c;try{c=new Bun.Transpiler({loader:"ts"}).transformSync(s[2])}catch(g){throw Error(`${n}: failed to transpile <script client> (${g.message})`)}let u=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,f;while(f=u.exec(c)){let g=f[1];if(nn.has(g))throw Error(`${n}: client ${tn(g)}`);let h=u.lastIndex,x=1,v="",S=!1,T=h;for(;T<c.length&&x>0;T++){let b=c[T];if(S){S=!1;continue}if(v){if(b==="\\")S=!0;else if(b===v)v="";continue}if(b==='"'||b==="'"||b==="`")v=b;else if(b==="{")x++;else if(b==="}")x--}if(x!==0)throw Error(`${n}: unterminated client function "${g}"`);let w=f[0].includes("async")?"async ":"";o[g]=`${w}${g}(${f[2]}) {${c.slice(h,T-1)}}`,u.lastIndex=T}}return o}function or(t){let n=t.match(/<template\b(?![^>]*\bshadowrootmode\b)[^>]*>([\s\S]*?)<\/template>/i);return(n?n[1]:t).replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").trim()}function Jt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((n)=>n[1].trim()).filter(Boolean).join(`
6
6
 
7
- `)}function sr(t){if(!t)return null;let n=t.replace(/\s*\|\s*(?:undefined|null)\b/g,"").trim();if(/^string$/.test(n))return"string";if(/^number$/.test(n))return"number";if(/^boolean$/.test(n))return"boolean";if(/^(?:'[^']*'|"[^"]*")(?:\s*\|\s*(?:'[^']*'|"[^"]*"))*$/.test(n))return"string";return"object"}function ir(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 ar(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 pr(t){let n=[],o=0,d=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),s=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,c,u=(g)=>{if(d[g]!=="(")return null;let h=0,x="";for(let v=g;v<d.length;v++){let S=d[v];if(x!==""){if(S==="\\")v++;else if(S===x)x="";continue}if(S==="'"||S==='"'||S==="`"){x=S;continue}if(S==="(")h++;else if(S===")"){if(h--,h===0)return{expression:d.slice(g+1,v),end:v+1}}}return null},f=(g)=>{if(g==="")return;let h=0,x=/\{!!\s*([\s\S]*?)\s*!!\}|\{\{\s*([\s\S]*?)\s*\}\}/g,v;while(v=x.exec(g)){if(v.index>h)n.push(`out += ${JSON.stringify(g.slice(h,v.index))};`);n.push(v[1]!==void 0?`out += __raw(${v[1]});`:`out += __escape(${v[2]});`),h=v.index+v[0].length}if(h<g.length)n.push(`out += ${JSON.stringify(g.slice(h))};`)};while(c=s.exec(d)){f(d.slice(o,c.index)),o=c.index+c[0].length;let h=c[1]==="if"||c[1]==="elseif"||c[1]==="foreach"?u(o):null;if(h)o=h.end,s.lastIndex=h.end;let x=h?.expression;switch(c[1]){case"if":n.push(`if (${x}) {`);break;case"elseif":n.push(`} else if (${x}) {`);break;case"else":n.push("} else {");break;case"endif":case"endforeach":n.push("}");break;case"foreach":{let v=/^([\s\S]+?)\s+as\s+(?:([A-Za-z_$][\w$]*)\s*=>\s*)?([A-Za-z_$][\w$]*)$/.exec((x||"").trim());if(!v){n.push(`out += ${JSON.stringify(c[0]+(h?`(${x})`:""))};`);break}let[,S,T,w]=v;n.push(T?`for (const [${T}, ${w}] of __entries(${S})) {`:`for (const ${w} of __values(${S})) {`);break}}}return f(d.slice(o)),n.join(`
8
- `)}function ct(t,n,o,d){if(t[n]!==o)return-1;let s=0,c=null;for(let u=n;u<t.length;u++){let f=t[u];if(c){if(f==="\\"){u++;continue}if(f===c)c=null;continue}if(f==="'"||f==='"'||f==="`"){c=f;continue}if(f===o)s++;else if(f===d){if(d===">"&&t[u-1]==="=")continue;if(s--,s===0)return u+1}}return-1}function Dt(t,n,o){let d=o?"([{<":"([{",s=o?")]}>":")]}",c=[],u=0,f=null,g="";for(let h=0;h<t.length;h++){let x=t[h];if(f){if(g+=x,x==="\\"){g+=t[++h]??"";continue}if(x===f)f=null;continue}if(x==="'"||x==='"'||x==="`"){f=x,g+=x;continue}if(d.includes(x))u++;else if(s.includes(x))u--;if(u===0&&n.includes(x)){c.push(g),g="";continue}g+=x}return c.push(g),c.map((h)=>h.trim()).filter(Boolean)}function ur(t){let n=0,o=null;for(let d=0;d<t.length;d++){let s=t[d];if(o){if(s==="\\"){d++;continue}if(s===o)o=null;continue}if(s==="'"||s==='"'||s==="`"){o=s;continue}if("([{".includes(s))n++;else if(")]}".includes(s))n--;if(n!==0||s!=="=")continue;let c=t[d-1];if(t[d+1]==="="||c==="="||c==="!"||c==="<"||c===">")continue;return d}return-1}function Jt(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 fr(t){let n=/\bdefineProps\b/.exec(t);if(!n)return null;let o=/(?:^|[\s;{}()])(const|let|var)\s+/g,d=-1;for(let E=o.exec(t);E&&E.index<n.index;E=o.exec(t))d=E.index+E[0].indexOf(E[1]);if(d===-1)return null;let s={},c={},u=[],f={},g=d+(/^(?:const|let|var)\s+/.exec(t.slice(d))?.[0].length??0),h=()=>{while(g<t.length&&/\s/.test(t[g]))g++},x;if(t[g]==="{"){let E=ct(t,g,"{","}");if(E===-1)return null;x=t.slice(g,E),g=E}else{let E=/^[A-Za-z_$][\w$]*/.exec(t.slice(g));if(!E)return null;x=E[0],g+=E[0].length}if(h(),t[g]!=="=")return null;g++,h();let v=/^withDefaults\s*\(\s*/.exec(t.slice(g)),S=Boolean(v);if(v)g+=v[0].length;let T=/^defineProps\b/.exec(t.slice(g));if(!T)return null;g+=T[0].length;let w="";if(h(),t[g]==="<"){let E=ct(t,g,"<",">");if(E===-1)return null;w=t.slice(g+1,E-1).trim(),g=E}if(h(),t[g]!=="(")return null;let b=ct(t,g,"(",")");if(b===-1)return null;let k=t.slice(g+1,b-1).trim();if(g=b,S){if(h(),t[g]===",")g++,h();if(t[g]==="{"){let E=ct(t,g,"{","}");if(E===-1)return null;for(let[R,A]of Mt(t.slice(g,E)))c[R]=A;g=E}if(h(),t[g]===",")g++,h();if(t[g]===")")g++}if(t[g]===";")g++;let _=/^[A-Za-z_$][\w$]*$/.test(w)?w:void 0;if(w.startsWith("{"))for(let E of Dt(w.replace(/^\{/,"").replace(/\}$/,""),",;",!0)){let R=/^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(E);if(R)s[R[1]]=R[2].trim()}if(k.startsWith("{"))for(let[E,R]of Mt(k)){if(u.push(E),!R.startsWith("{")){let A=Jt(R);if(A)s[E]=A;continue}for(let[A,C]of Mt(R))if(A==="default")c[E]=C;else if(A==="type"){let D=Jt(C);if(D)s[E]=D}}else if(k.startsWith("["))for(let E of Dt(k.slice(1,-1),",",!1))u.push(E.replace(/^['"`]/,"").replace(/['"`]$/,""));if(x.startsWith("{")){u.length=0;for(let E of Dt(x.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let R=ur(E),A=R===-1?E:E.slice(0,R),C=A.split(":")[0].trim().replace(/^\.\.\./,"");if(!C)continue;if(u.push(C),f[C]=A.trim(),R!==-1)c[C]=E.slice(R+1).trim()}}else if(u.length===0)u.push(...Object.keys(s));return{text:t.slice(d,g),propNames:u,propBindings:f,defaults:c,declared:s,typeName:_}}function Mt(t){let n=t.trim().replace(/^\{/,"").replace(/\}$/,""),o=[],d=0;while(d<n.length){let s=/\s*([A-Za-z_$][\w$]*)\s*:/y;s.lastIndex=d;let c=s.exec(n);if(!c)break;d=s.lastIndex;let u=0,f="",g=d;while(d<n.length){let x=n[d];if(f){if(x==="\\")d++;else if(x===f)f=""}else if(x==="'"||x==='"'||x==="`")f=x;else if(x==="{"||x==="["||x==="(")u++;else if(x==="}"||x==="]"||x===")")u--;else if(x===","&&u===0)break;d++}let h=n.slice(g,d).trim();if(h)o.push([c[1],h]);d++}return o}function mr(t,n,o){let s=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].find((T)=>!/\bcomponent\b|\bstx:component\b|\bclient\b/i.test(T[1]));if(!s)return{imports:[],body:"",propNames:[],propBindings:{},defaults:{},declared:{}};let c=s[2],u=[],f=[],g={},h={},x={};c=c.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm,(T)=>{if(/from\s*['"]stx['"]/.test(T))return"";return u.push(T.trim().replace(/(from\s*['"])(\.[^'"]*)(['"])/,(w,b,k,_)=>{let E=Te.resolve(Te.dirname(n),k),R=Te.relative(o,E);return`${b}${R.startsWith(".")?R:`./${R}`}${_}`})),""});let v=fr(c);if(v)f.push(...v.propNames),Object.assign(g,v.propBindings),Object.assign(h,v.defaults),Object.assign(x,v.declared),c=c.replace(v.text,"");let S={};for(let T of c.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)){let w=[];for(let b of T[2].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))x[b[1]]=b[2].trim(),w.push(b[1]);S[T[1]]=w}if(v&&v.propNames.length===0&&v.typeName){for(let T of S[v.typeName]??[])if(!f.includes(T))f.push(T)}return c=c.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g,""),{imports:u,body:c.trim(),propNames:f,propBindings:g,defaults:h,declared:x}}function gr(t){let n=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(d,s,c,u,f)=>{let g=s.toLowerCase();n.add(g);let h=(c||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${g}="${f}"${h?` data-stx-mod-${g}="${h}"`:""}`}),eventTypes:[...n].sort()}}function hr(t){let n=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(d,s,c,u)=>{let f=n.length;return n.push({id:f,name:s,expression:u}),` data-stx-bind-${f}=""`}),bindings:n}}function yr(t){let n=new Set;for(let o of t.matchAll(/<slot\b([^>]*)>/gi))n.add(o[1].match(/\bname\s*=\s*["']([^"']+)["']/i)?.[1]||"");return[...n].map((o)=>({name:o}))}function br(t){return[...new Set([...t.matchAll(/(--[a-z0-9_-]+)\s*:/gi)].map((n)=>n[1]))].sort().map((n)=>({name:n}))}function Yt(t,n){if(!n||!new Set(["string","number","boolean","object","array"]).has(n.type))throw Error(`Property "${t}" must declare one of: string, number, boolean, object, array`);return{...n,reflect:n.reflect??n.attribute!==!1}}async function xr(t,n,o){let d=Te.isAbsolute(n.file)?n.file:Te.resolve(t,n.file),s=await Xn(d,"utf8"),c=tr(s,d),u=Te.basename(d,".stx"),f=n.name||c.name||Yn(u),g=`${Lt(o.prefix||"stx")}-${Lt(u)}`,h=n.tag||c.tag||g;if(!f||!/^[A-Za-z_$][\w$]*$/.test(f))throw Error(`${d}: invalid component class name "${f}"`);if(!Qn(h))throw Error(`${d}: invalid custom-element tag "${h}"; tags must be lowercase and contain a hyphen`);let x=n.properties||c.properties||c.props||{},v=Object.fromEntries(Object.entries(x).map(([R,A])=>[R,Yt(R,A)])),S=gr(or(s)),T=hr(S.template),w=mr(s,d,Te.resolve(o.outputDir)),b=pr(T.template);for(let R of w.propNames){if(v[R])continue;let A=w.defaults[R];v[R]=Yt(R,{type:sr(w.declared[R])??ir(A),...A===void 0?{}:{default:ar(A)}})}let k=c.methods||{},_=n.methods||{},E=nr(s,d);return{file:Te.relative(t,d),sourcePath:d,name:f,tag:h,description:n.description||c.description||"",template:T.template,styles:Gt(s),shadowMode:Zn(n.shadowDOM??c.shadowDOM??o.shadowDOM),progressive:n.progressive??c.progressive??o.progressive??!0,properties:v,events:n.events||c.events||{},methods:{...k,..._,...E},eventTypes:S.eventTypes,bindings:T.bindings,slots:yr(T.template),cssProperties:br(Gt(s)),scope:w,render:b}}function vr(){let t=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),n=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}");return`const HTMLElementBase = globalThis.HTMLElement || class {};
7
+ `)}function ir(t){if(!t)return null;let n=t.replace(/\s*\|\s*(?:undefined|null)\b/g,"").trim();if(/^string$/.test(n))return"string";if(/^number$/.test(n))return"number";if(/^boolean$/.test(n))return"boolean";if(/^(?:'[^']*'|"[^"]*")(?:\s*\|\s*(?:'[^']*'|"[^"]*"))*$/.test(n))return"string";return"object"}function ar(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 cr(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 dr(t){let n=[],o=0,d=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),s=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,c,u=(g)=>{if(d[g]!=="(")return null;let h=0,x="";for(let v=g;v<d.length;v++){let S=d[v];if(x!==""){if(S==="\\")v++;else if(S===x)x="";continue}if(S==="'"||S==='"'||S==="`"){x=S;continue}if(S==="(")h++;else if(S===")"){if(h--,h===0)return{expression:d.slice(g+1,v),end:v+1}}}return null},f=(g)=>{if(g==="")return;let h=0,x=/\{!!\s*([\s\S]*?)\s*!!\}|\{\{\s*([\s\S]*?)\s*\}\}/g,v;while(v=x.exec(g)){if(v.index>h)n.push(`out += ${JSON.stringify(g.slice(h,v.index))};`);n.push(v[1]!==void 0?`out += __raw(${v[1]});`:`out += __escape(${v[2]});`),h=v.index+v[0].length}if(h<g.length)n.push(`out += ${JSON.stringify(g.slice(h))};`)};while(c=s.exec(d)){f(d.slice(o,c.index)),o=c.index+c[0].length;let h=c[1]==="if"||c[1]==="elseif"||c[1]==="foreach"?u(o):null;if(h)o=h.end,s.lastIndex=h.end;let x=h?.expression;switch(c[1]){case"if":n.push(`if (${x}) {`);break;case"elseif":n.push(`} else if (${x}) {`);break;case"else":n.push("} else {");break;case"endif":case"endforeach":n.push("}");break;case"foreach":{let v=/^([\s\S]+?)\s+as\s+(?:([A-Za-z_$][\w$]*)\s*=>\s*)?([A-Za-z_$][\w$]*)$/.exec((x||"").trim());if(!v){n.push(`out += ${JSON.stringify(c[0]+(h?`(${x})`:""))};`);break}let[,S,T,w]=v;n.push(T?`for (const [${T}, ${w}] of __entries(${S})) {`:`for (const ${w} of __values(${S})) {`);break}}}return f(d.slice(o)),n.join(`
8
+ `)}function lt(t,n,o,d){if(t[n]!==o)return-1;let s=0,c=null;for(let u=n;u<t.length;u++){let f=t[u];if(c){if(f==="\\"){u++;continue}if(f===c)c=null;continue}if(f==="'"||f==='"'||f==="`"){c=f;continue}if(f===o)s++;else if(f===d){if(d===">"&&t[u-1]==="=")continue;if(s--,s===0)return u+1}}return-1}function Mt(t,n,o){let d=o?"([{<":"([{",s=o?")]}>":")]}",c=[],u=0,f=null,g="";for(let h=0;h<t.length;h++){let x=t[h];if(f){if(g+=x,x==="\\"){g+=t[++h]??"";continue}if(x===f)f=null;continue}if(x==="'"||x==='"'||x==="`"){f=x,g+=x;continue}if(d.includes(x))u++;else if(s.includes(x))u--;if(u===0&&n.includes(x)){c.push(g),g="";continue}g+=x}return c.push(g),c.map((h)=>h.trim()).filter(Boolean)}function fr(t){let n=0,o=null;for(let d=0;d<t.length;d++){let s=t[d];if(o){if(s==="\\"){d++;continue}if(s===o)o=null;continue}if(s==="'"||s==='"'||s==="`"){o=s;continue}if("([{".includes(s))n++;else if(")]}".includes(s))n--;if(n!==0||s!=="=")continue;let c=t[d-1];if(t[d+1]==="="||c==="="||c==="!"||c==="<"||c===">")continue;return d}return-1}function Yt(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 mr(t){let n=/\bdefineProps\b/.exec(t);if(!n)return null;let o=/(?:^|[\s;{}()])(const|let|var)\s+/g,d=-1;for(let E=o.exec(t);E&&E.index<n.index;E=o.exec(t))d=E.index+E[0].indexOf(E[1]);if(d===-1)return null;let s={},c={},u=[],f={},g=d+(/^(?:const|let|var)\s+/.exec(t.slice(d))?.[0].length??0),h=()=>{while(g<t.length&&/\s/.test(t[g]))g++},x;if(t[g]==="{"){let E=lt(t,g,"{","}");if(E===-1)return null;x=t.slice(g,E),g=E}else{let E=/^[A-Za-z_$][\w$]*/.exec(t.slice(g));if(!E)return null;x=E[0],g+=E[0].length}if(h(),t[g]!=="=")return null;g++,h();let v=/^withDefaults\s*\(\s*/.exec(t.slice(g)),S=Boolean(v);if(v)g+=v[0].length;let T=/^defineProps\b/.exec(t.slice(g));if(!T)return null;g+=T[0].length;let w="";if(h(),t[g]==="<"){let E=lt(t,g,"<",">");if(E===-1)return null;w=t.slice(g+1,E-1).trim(),g=E}if(h(),t[g]!=="(")return null;let b=lt(t,g,"(",")");if(b===-1)return null;let k=t.slice(g+1,b-1).trim();if(g=b,S){if(h(),t[g]===",")g++,h();if(t[g]==="{"){let E=lt(t,g,"{","}");if(E===-1)return null;for(let[R,A]of Lt(t.slice(g,E)))c[R]=A;g=E}if(h(),t[g]===",")g++,h();if(t[g]===")")g++}if(t[g]===";")g++;let _=/^[A-Za-z_$][\w$]*$/.test(w)?w:void 0;if(w.startsWith("{"))for(let E of Mt(w.replace(/^\{/,"").replace(/\}$/,""),",;",!0)){let R=/^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(E);if(R)s[R[1]]=R[2].trim()}if(k.startsWith("{"))for(let[E,R]of Lt(k)){if(u.push(E),!R.startsWith("{")){let A=Yt(R);if(A)s[E]=A;continue}for(let[A,C]of Lt(R))if(A==="default")c[E]=C;else if(A==="type"){let D=Yt(C);if(D)s[E]=D}}else if(k.startsWith("["))for(let E of Mt(k.slice(1,-1),",",!1))u.push(E.replace(/^['"`]/,"").replace(/['"`]$/,""));if(x.startsWith("{")){u.length=0;for(let E of Mt(x.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let R=fr(E),A=R===-1?E:E.slice(0,R),C=A.split(":")[0].trim().replace(/^\.\.\./,"");if(!C)continue;if(u.push(C),f[C]=A.trim(),R!==-1)c[C]=E.slice(R+1).trim()}}else if(u.length===0)u.push(...Object.keys(s));return{text:t.slice(d,g),propNames:u,propBindings:f,defaults:c,declared:s,typeName:_}}function Lt(t){let n=t.trim().replace(/^\{/,"").replace(/\}$/,""),o=[],d=0;while(d<n.length){let s=/\s*([A-Za-z_$][\w$]*)\s*:/y;s.lastIndex=d;let c=s.exec(n);if(!c)break;d=s.lastIndex;let u=0,f="",g=d;while(d<n.length){let x=n[d];if(f){if(x==="\\")d++;else if(x===f)f=""}else if(x==="'"||x==='"'||x==="`")f=x;else if(x==="{"||x==="["||x==="(")u++;else if(x==="}"||x==="]"||x===")")u--;else if(x===","&&u===0)break;d++}let h=n.slice(g,d).trim();if(h)o.push([c[1],h]);d++}return o}function gr(t,n,o){let s=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].find((T)=>!/\bcomponent\b|\bstx:component\b|\bclient\b/i.test(T[1]));if(!s)return{imports:[],body:"",propNames:[],propBindings:{},defaults:{},declared:{}};let c=s[2],u=[],f=[],g={},h={},x={};c=c.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm,(T)=>{if(/from\s*['"]stx['"]/.test(T))return"";return u.push(T.trim().replace(/(from\s*['"])(\.[^'"]*)(['"])/,(w,b,k,_)=>{let E=Te.resolve(Te.dirname(n),k),R=Te.relative(o,E);return`${b}${R.startsWith(".")?R:`./${R}`}${_}`})),""});let v=mr(c);if(v)f.push(...v.propNames),Object.assign(g,v.propBindings),Object.assign(h,v.defaults),Object.assign(x,v.declared),c=c.replace(v.text,"");let S={};for(let T of c.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)){let w=[];for(let b of T[2].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))x[b[1]]=b[2].trim(),w.push(b[1]);S[T[1]]=w}if(v&&v.propNames.length===0&&v.typeName){for(let T of S[v.typeName]??[])if(!f.includes(T))f.push(T)}return c=c.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g,""),{imports:u,body:c.trim(),propNames:f,propBindings:g,defaults:h,declared:x}}function hr(t){let n=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(d,s,c,u,f)=>{let g=s.toLowerCase();n.add(g);let h=(c||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${g}="${f}"${h?` data-stx-mod-${g}="${h}"`:""}`}),eventTypes:[...n].sort()}}function yr(t){let n=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(d,s,c,u)=>{let f=n.length;return n.push({id:f,name:s,expression:u}),` data-stx-bind-${f}=""`}),bindings:n}}function br(t){let n=new Set;for(let o of t.matchAll(/<slot\b([^>]*)>/gi))n.add(o[1].match(/\bname\s*=\s*["']([^"']+)["']/i)?.[1]||"");return[...n].map((o)=>({name:o}))}function xr(t){return[...new Set([...t.matchAll(/(--[a-z0-9_-]+)\s*:/gi)].map((n)=>n[1]))].sort().map((n)=>({name:n}))}function Qt(t,n){if(!n||!new Set(["string","number","boolean","object","array"]).has(n.type))throw Error(`Property "${t}" must declare one of: string, number, boolean, object, array`);return{...n,reflect:n.reflect??n.attribute!==!1}}async function vr(t,n,o){let d=Te.isAbsolute(n.file)?n.file:Te.resolve(t,n.file),s=await Gn(d,"utf8"),c=nr(s,d),u=Te.basename(d,".stx"),f=n.name||c.name||Qn(u),g=`${It(o.prefix||"stx")}-${It(u)}`,h=n.tag||c.tag||g;if(!f||!/^[A-Za-z_$][\w$]*$/.test(f))throw Error(`${d}: invalid component class name "${f}"`);if(!Zn(h))throw Error(`${d}: invalid custom-element tag "${h}"; tags must be lowercase and contain a hyphen`);let x=n.properties||c.properties||c.props||{},v=Object.fromEntries(Object.entries(x).map(([R,A])=>[R,Qt(R,A)])),S=hr(or(s)),T=yr(S.template),w=gr(s,d,Te.resolve(o.outputDir)),b=dr(T.template);for(let R of w.propNames){if(v[R])continue;let A=w.defaults[R];v[R]=Qt(R,{type:ir(w.declared[R])??ar(A),...A===void 0?{}:{default:cr(A)}})}let k=c.methods||{},_=n.methods||{},E=rr(s,d);return{file:Te.relative(t,d),sourcePath:d,name:f,tag:h,description:n.description||c.description||"",template:T.template,styles:Jt(s),shadowMode:er(n.shadowDOM??c.shadowDOM??o.shadowDOM),progressive:n.progressive??c.progressive??o.progressive??!0,properties:v,events:n.events||c.events||{},methods:{...k,..._,...E},eventTypes:S.eventTypes,bindings:T.bindings,slots:br(T.template),cssProperties:xr(Jt(s)),scope:w,render:b}}function wr(){let t=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),n=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;')
@@ -314,7 +314,7 @@ export function defineComponent(Component, definition) {
314
314
  }
315
315
  return Component;
316
316
  }
317
- `}function wr(t){let n=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),o=Object.entries(t.methods).map(([f,g])=>{if(tn.has(f))throw Error(`${t.sourcePath}: ${en(f)}`);if(/^(?:async\s+)?[A-Za-z_$][\w$]*\s*\(/.test(g.trim()))return` ${g.trim()}`;return` ${f}($event) {
317
+ `}function Sr(t){let n=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),o=Object.entries(t.methods).map(([f,g])=>{if(nn.has(f))throw Error(`${t.sourcePath}: ${tn(f)}`);if(/^(?:async\s+)?[A-Za-z_$][\w$]*\s*\(/.test(g.trim()))return` ${g.trim()}`;return` ${f}($event) {
318
318
  ${g}
319
319
  }`}).join(`
320
320
 
@@ -339,7 +339,7 @@ ${o}${u}
339
339
 
340
340
  defineComponent(${t.name}, ${n});
341
341
  export default ${t.name};
342
- `}function jt(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 Sr(t){let n=Object.entries(t.properties).map(([s,c])=>` ${s}${c.required?"":"?"}: ${jt(c)}`).join(`
342
+ `}function jt(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 kr(t){let n=Object.entries(t.properties).map(([s,c])=>` ${s}${c.required?"":"?"}: ${jt(c)}`).join(`
343
343
  `),o=Object.entries(t.events).map(([s,c])=>` ${JSON.stringify(s)}: CustomEvent<${c.detailType||"unknown"}>`).join(`
344
344
  `),d=Object.keys(t.methods).map((s)=>` ${s}($event?: Event): unknown`).join(`
345
345
  `);return`export interface ${t.name}Props {
@@ -366,7 +366,7 @@ declare global {
366
366
  }
367
367
 
368
368
  export default ${t.name}
369
- `}function kr(t){return`declare global {
369
+ `}function Tr(t){return`declare global {
370
370
  namespace JSX {
371
371
  interface IntrinsicElements {
372
372
  ${t.map((o)=>{let d=Object.entries(o.properties).map(([c,u])=>` ${JSON.stringify(c)}?: ${jt(u)}`).join(`
@@ -385,9 +385,9 @@ ${s}
385
385
  }
386
386
 
387
387
  export {}
388
- `}function Tr(t){return{schemaVersion:"1.0.0",modules:t.map((n)=>({kind:"javascript-module",path:`./${n.tag}.js`,declarations:[{kind:"class",name:n.name,description:n.description||void 0,customElement:!0,tagName:n.tag,members:Object.entries(n.properties).map(([o,d])=>({kind:"field",name:o,description:d.description,type:{text:jt(d)},default:d.default===void 0?void 0:JSON.stringify(d.default),attribute:d.attribute===!1?void 0:d.attribute||Lt(o),reflects:d.reflect})),events:Object.entries(n.events).map(([o,d])=>({name:o,description:d.description,type:{text:`CustomEvent<${d.detailType||"unknown"}>`}})),slots:n.slots,cssProperties:n.cssProperties}],exports:[{kind:"js",name:n.name,declaration:{name:n.name,module:`./${n.tag}.js`}}]}))}}function Qt(t){if(!t.styles)return"";let n=t.styles.replace(/:host\b/g,":scope");if(/\@scope\s*\(/.test(n))return n;return`@scope (${t.tag}) {
388
+ `}function $r(t){return{schemaVersion:"1.0.0",modules:t.map((n)=>({kind:"javascript-module",path:`./${n.tag}.js`,declarations:[{kind:"class",name:n.name,description:n.description||void 0,customElement:!0,tagName:n.tag,members:Object.entries(n.properties).map(([o,d])=>({kind:"field",name:o,description:d.description,type:{text:jt(d)},default:d.default===void 0?void 0:JSON.stringify(d.default),attribute:d.attribute===!1?void 0:d.attribute||It(o),reflects:d.reflect})),events:Object.entries(n.events).map(([o,d])=>({name:o,description:d.description,type:{text:`CustomEvent<${d.detailType||"unknown"}>`}})),slots:n.slots,cssProperties:n.cssProperties}],exports:[{kind:"js",name:n.name,declaration:{name:n.name,module:`./${n.tag}.js`}}]}))}}function Zt(t){if(!t.styles)return"";let n=t.styles.replace(/:host\b/g,":scope");if(/\@scope\s*\(/.test(n))return n;return`@scope (${t.tag}) {
389
389
  ${n}
390
- }`}function Zt(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").replace(/\s*([{}:;,])\s*/g,"$1").replace(/;}/g,"}").trim()}function $r(t){let n=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),o=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}"),d=JSON.stringify('<slot(?:\\s+name=["\\\']([^"\\\']+)["\\\'])?\\s*\\/?>(?:<\\/slot>)?'),s=Object.fromEntries(t.map((u)=>[u.tag,{template:u.template,styles:u.styles,shadowMode:u.shadowMode,properties:u.properties}])),c=t.map((u)=>`export const render${u.name} = (props = {}, slots = {}) => renderComponent('${u.tag}', props, slots);`).join(`
390
+ }`}function en(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").replace(/\s*([{}:;,])\s*/g,"$1").replace(/;}/g,"}").trim()}function Cr(t){let n=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),o=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}"),d=JSON.stringify('<slot(?:\\s+name=["\\\']([^"\\\']+)["\\\'])?\\s*\\/?>(?:<\\/slot>)?'),s=Object.fromEntries(t.map((u)=>[u.tag,{template:u.template,styles:u.styles,shadowMode:u.shadowMode,properties:u.properties}])),c=t.map((u)=>`export const render${u.name} = (props = {}, slots = {}) => renderComponent('${u.tag}', props, slots);`).join(`
391
391
  `);return`const definitions = ${JSON.stringify(s,null,2)};
392
392
  const escapeHTML = (value) => String(value ?? '')
393
393
  .replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;')
@@ -421,21 +421,21 @@ export function renderComponent(tag, props = {}, slots = {}) {
421
421
  }
422
422
 
423
423
  ${c}
424
- `}async function Ki(t){let n=Te.resolve(t.inputDir),o=Te.resolve(t.outputDir);if(!(await Xt(n).catch(()=>null))?.isDirectory())throw Error(`Component-library input directory does not exist: ${n}`);let s=t.components?.length?t.components:(await er(n)).map((b)=>({file:b}));if(!s.length)throw Error(`No .stx components found in ${n}`);let c=await Promise.all(s.map((b)=>xr(n,b,t)));c.sort((b,k)=>b.tag.localeCompare(k.tag));let u=c.filter((b,k)=>c.findIndex((_)=>_.tag===b.tag)!==k);if(u.length)throw Error(`Duplicate custom-element tag: ${u[0].tag}`);let f=c.filter((b,k)=>c.findIndex((_)=>_.name===b.name)!==k);if(f.length)throw Error(`Duplicate component class name: ${f[0].name}`);await Kn(o,{recursive:!0});let g=[],h=async(b,k)=>{let _=Te.join(o,b);return await Jn(_,k.endsWith(`
424
+ `}async function Xi(t){let n=Te.resolve(t.inputDir),o=Te.resolve(t.outputDir);if(!(await Gt(n).catch(()=>null))?.isDirectory())throw Error(`Component-library input directory does not exist: ${n}`);let s=t.components?.length?t.components:(await tr(n)).map((b)=>({file:b}));if(!s.length)throw Error(`No .stx components found in ${n}`);let c=await Promise.all(s.map((b)=>vr(n,b,t)));c.sort((b,k)=>b.tag.localeCompare(k.tag));let u=c.filter((b,k)=>c.findIndex((_)=>_.tag===b.tag)!==k);if(u.length)throw Error(`Duplicate custom-element tag: ${u[0].tag}`);let f=c.filter((b,k)=>c.findIndex((_)=>_.name===b.name)!==k);if(f.length)throw Error(`Duplicate component class name: ${f[0].name}`);await Xn(o,{recursive:!0});let g=[],h=async(b,k)=>{let _=Te.join(o,b);return await Yn(_,k.endsWith(`
425
425
  `)?k:`${k}
426
- `,"utf8"),g.push(_),_};await h("runtime.js",vr());for(let b of c){if(await h(`${b.tag}.js`,wr(b)),t.declarations!==!1)await h(`${b.tag}.d.ts`,Sr(b));if(t.css!==!1&&b.styles){let k=b.shadowMode?b.styles:Qt(b);await h(`${b.tag}.css`,t.minify?Zt(k):k)}}let x=c.map((b)=>`export { ${b.name}, default as ${b.name}Element } from './${b.tag}.js';`).join(`
427
- `);if(await h("index.js",x),await h("ssr.js",$r(c)),t.declarations!==!1)await h("index.d.ts",c.map((b)=>`export * from './${b.tag}.js'`).join(`
428
- `)),await h("custom-elements.d.ts",kr(c)),await h("ssr.d.ts",`${c.map((b)=>`export declare const render${b.name}: (props?: ${b.name}Props, slots?: Record<string, string>) => string`).join(`
426
+ `,"utf8"),g.push(_),_};await h("runtime.js",wr());for(let b of c){if(await h(`${b.tag}.js`,Sr(b)),t.declarations!==!1)await h(`${b.tag}.d.ts`,kr(b));if(t.css!==!1&&b.styles){let k=b.shadowMode?b.styles:Zt(b);await h(`${b.tag}.css`,t.minify?en(k):k)}}let x=c.map((b)=>`export { ${b.name}, default as ${b.name}Element } from './${b.tag}.js';`).join(`
427
+ `);if(await h("index.js",x),await h("ssr.js",Cr(c)),t.declarations!==!1)await h("index.d.ts",c.map((b)=>`export * from './${b.tag}.js'`).join(`
428
+ `)),await h("custom-elements.d.ts",Tr(c)),await h("ssr.d.ts",`${c.map((b)=>`export declare const render${b.name}: (props?: ${b.name}Props, slots?: Record<string, string>) => string`).join(`
429
429
  `)}
430
430
  export declare function renderComponent(tag: string, props?: Record<string, unknown>, slots?: Record<string, string>): string
431
431
  ${c.map((b)=>`import type { ${b.name}Props } from './${b.tag}.js'`).join(`
432
- `)}`);let v;if(t.manifest!==!1)v=await h("custom-elements.json",JSON.stringify(Tr(c),null,2));let S;if(t.css!==!1){let b=c.filter((k)=>!k.shadowMode&&k.styles).map(Qt).join(`
432
+ `)}`);let v;if(t.manifest!==!1)v=await h("custom-elements.json",JSON.stringify($r(c),null,2));let S;if(t.css!==!1){let b=c.filter((k)=>!k.shadowMode&&k.styles).map(Zt).join(`
433
433
 
434
- `);if(b)S=await h("bundle.css",t.minify?Zt(b):b)}let T;if(t.bundle!==!1){T=Te.join(o,"bundle.js");let b;try{b=await Bun.build({entrypoints:[Te.join(o,"index.js")],outdir:o,naming:"bundle.js",target:"browser",format:"esm",minify:t.minify??!0,sourcemap:t.sourcemap||"none"})}catch(k){let _=k instanceof AggregateError?k.errors:[k],E=_.map((R)=>String(R).trim()).filter(Boolean).join(`
434
+ `);if(b)S=await h("bundle.css",t.minify?en(b):b)}let T;if(t.bundle!==!1){T=Te.join(o,"bundle.js");let b;try{b=await Bun.build({entrypoints:[Te.join(o,"index.js")],outdir:o,naming:"bundle.js",target:"browser",format:"esm",minify:t.minify??!0,sourcemap:t.sourcemap||"none"})}catch(k){let _=k instanceof AggregateError?k.errors:[k],E=_.map((R)=>String(R).trim()).filter(Boolean).join(`
435
435
  `);throw AggregateError(_,`Failed to bundle component library${E?`
436
436
  ${E}`:""}`)}if(!b.success){let k=b.logs.map((_)=>String(_).trim()).filter(Boolean).join(`
437
437
  `);throw AggregateError(b.logs,`Failed to bundle component library${k?`
438
- ${k}`:""}`)}if(g.push(T),t.sourcemap==="external")g.push(`${T}.map`)}let w=await Promise.all(g.map(async(b)=>(await Xt(b)).size));return{components:c.map((b)=>({name:b.name,tag:b.tag,source:b.sourcePath,module:Te.join(o,`${b.tag}.js`)})),files:g,manifest:v,bundle:T,cssBundle:S,totalBytes:w.reduce((b,k)=>b+k,0)}}var{serve:Lr}=globalThis.Bun;import Bt from"fs";import et from"path";function lt(){return`
438
+ ${k}`:""}`)}if(g.push(T),t.sourcemap==="external")g.push(`${T}.map`)}let w=await Promise.all(g.map(async(b)=>(await Gt(b)).size));return{components:c.map((b)=>({name:b.name,tag:b.tag,source:b.sourcePath,module:Te.join(o,`${b.tag}.js`)})),files:g,manifest:v,bundle:T,cssBundle:S,totalBytes:w.reduce((b,k)=>b+k,0)}}var{serve:Ir}=globalThis.Bun;import Bt from"fs";import tt from"path";function dt(){return`
439
439
  /* Theme selector for code blocks */
440
440
  .theme-selector {
441
441
  margin: 1rem 0;
@@ -485,7 +485,7 @@ ${k}`:""}`)}if(g.push(T),t.sourcemap==="external")g.push(`${T}.map`)}let w=await
485
485
 
486
486
  body.dark-mode a {
487
487
  color: #58a6ff;
488
- }`}function dt(t){return`
488
+ }`}function pt(t){return`
489
489
  <div class="theme-selector">
490
490
  Theme:
491
491
  <select id="themeSelector" onchange="changeTheme()">
@@ -507,7 +507,7 @@ else {
507
507
  }
508
508
 
509
509
  // Initialize theme on page load
510
- document.addEventListener('DOMContentLoaded', changeTheme);`}function ft(t){if(Object.keys(t).length===0)return"";return`
510
+ document.addEventListener('DOMContentLoaded', changeTheme);`}function mt(t){if(Object.keys(t).length===0)return"";return`
511
511
  <div class="frontmatter">
512
512
  <h3>Frontmatter</h3>
513
513
  ${Object.entries(t).map(([n,o])=>`
@@ -515,19 +515,19 @@ else {
515
515
  <span class="frontmatter-label">${n}:</span>
516
516
  <span>${Array.isArray(o)?o.join(", "):String(o)}</span>
517
517
  </div>`).join("")}
518
- </div>`}import nn from"net";async function Rr(t){return new Promise((n)=>{let o=nn.createServer();o.once("error",()=>n(!1)),o.once("listening",()=>{o.close(()=>n(!0))}),o.listen(t,"0.0.0.0")})}async function Er(t){return new Promise((n)=>{let o=nn.createServer();o.once("error",()=>n(!1)),o.once("listening",()=>{o.close(()=>n(!0))}),o.listen(t,"::")})}async function Pr(t){if(!await Rr(t))return!1;return await Er(t)}async function Ve(t,n=20){t=Number(t);for(let o=0;o<n;o++){let d=t+o;if(await Pr(d))return d}throw Error(`Could not find an available port between ${t} and ${t+n-1}`)}var Or={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function Ar(){try{let t=await import("./chunk-0qgdex7z.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function Ze(t,n={}){let o={...Or,...n},d=await Ar();if(!d)return console.log(`${e.yellow}\u26A0${e.reset} Native window requested, but @stacksjs/desktop is not available.`),console.log(" Install & build the desktop package to enable --native."),!1;try{let s=await d.openDevWindow(t,{title:o.title,width:o.width,height:o.height,darkMode:o.darkMode,hotReload:o.hotReload,titlebarHidden:o.titlebarHidden,nativeSidebar:o.nativeSidebar,sidebarWidth:o.sidebarWidth,sidebarConfig:o.sidebarConfig});if(s&&o.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return s}catch(s){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,s),!1}}function mt(t){if(t.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let s=t.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(s){let c=s[1];try{let u=`
518
+ </div>`}import rn from"net";async function Rr(t){return new Promise((n)=>{let o=rn.createServer();o.once("error",()=>n(!1)),o.once("listening",()=>{o.close(()=>n(!0))}),o.listen(t,"0.0.0.0")})}async function Pr(t){return new Promise((n)=>{let o=rn.createServer();o.once("error",()=>n(!1)),o.once("listening",()=>{o.close(()=>n(!0))}),o.listen(t,"::")})}async function Or(t){if(!await Rr(t))return!1;return await Pr(t)}async function Ve(t,n=20){t=Number(t);for(let o=0;o<n;o++){let d=t+o;if(await Or(d))return d}throw Error(`Could not find an available port between ${t} and ${t+n-1}`)}var Ar={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function Dr(){try{let t=await import("./chunk-7y6ad89y.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function Ze(t,n={}){let o={...Ar,...n},d=await Dr();if(!d)return console.log(`${e.yellow}\u26A0${e.reset} Native window requested, but @stacksjs/desktop is not available.`),console.log(" Install & build the desktop package to enable --native."),!1;try{let s=await d.openDevWindow(t,{title:o.title,width:o.width,height:o.height,darkMode:o.darkMode,hotReload:o.hotReload,titlebarHidden:o.titlebarHidden,nativeSidebar:o.nativeSidebar,sidebarWidth:o.sidebarWidth,sidebarConfig:o.sidebarConfig});if(s&&o.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return s}catch(s){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,s),!1}}function gt(t){if(t.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let s=t.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(s){let c=s[1];try{let u=`
519
519
  ${c}
520
520
  return typeof sidebarConfig !== 'undefined' ? sidebarConfig : null;
521
521
  `,g=Function(u)();if(g)return g}catch(u){console.warn("Invalid sidebarConfig:",u)}}return{sections:[]}}let o=t.match(/@nativeSidebar\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(o)try{return JSON.parse(o[1])}catch{console.warn("Invalid @nativeSidebar configuration")}let d=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(d)try{let s=d[1].match(/(?:export\s+(?:default\s+)?|const\s+\w+\s*=\s*)(\{[\s\S]*\})/m);if(s)return Function(`return ${s[1]}`)()}catch(s){console.warn("Invalid native-sidebar script configuration:",s)}return}function Ht(){console.log(`
522
- 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 Dr(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`),Ht()}function Mr(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,n,o){if(!process.stdin.isTTY)return;process.stdin.setRawMode(!0),process.stdin.setEncoding("utf8"),process.stdin.resume(),Ht();let d="";process.stdin.on("data",(s)=>{if(s==="\x03"){if(o?.onQuit)o.onQuit();n(),process.exit(0)}if(d+=s,d.endsWith("\r")||d.endsWith(`
523
- `)){let c=d.trim().toLowerCase();d="",_r(c,t,n,o)}})}function _r(t,n,o,d){switch(t){case"o":if(d?.onOpen)d.onOpen();else Mr(n);break;case"c":if(d?.onClear)d.onClear();else console.clear(),Dr(n);break;case"q":if(d?.onQuit)d.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),o(),process.exit(0);break;case"h":if(d?.onHelp)d.onHelp();else Ht();break;default:break}}async function Ft(t,n={}){let o=n.port||3000,d=n.watch!==!1,s=et.resolve(t);if(!Bt.existsSync(s))return console.error(`${e.red}Error: File not found: ${e.bright}${s}${e.reset}`),!1;if(!s.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${s}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${t}${e.reset}...`);let c=null,u=async()=>{try{let{content:v,data:S}=await Re(s,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),T=n.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,w=T?.defaultTheme||"github-dark",b=["github-dark"],k=T?.additionalThemes||[],E=[...new Set([...b,...k])].map((R)=>`<option value="${R}"${R===w?" selected":""}>${R}</option>`).join(`
522
+ 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 Mr(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`),Ht()}function _r(t){console.log(`${e.dim}Opening ${e.cyan}${t}${e.dim} in your browser...${e.reset}`),Bun.spawn(["open",t],{stderr:"inherit"})}function Ke(t,n,o){if(!process.stdin.isTTY)return;process.stdin.setRawMode(!0),process.stdin.setEncoding("utf8"),process.stdin.resume(),Ht();let d="";process.stdin.on("data",(s)=>{if(s==="\x03"){if(o?.onQuit)o.onQuit();n(),process.exit(0)}if(d+=s,d.endsWith("\r")||d.endsWith(`
523
+ `)){let c=d.trim().toLowerCase();d="",Lr(c,t,n,o)}})}function Lr(t,n,o,d){switch(t){case"o":if(d?.onOpen)d.onOpen();else _r(n);break;case"c":if(d?.onClear)d.onClear();else console.clear(),Mr(n);break;case"q":if(d?.onQuit)d.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),o(),process.exit(0);break;case"h":if(d?.onHelp)d.onHelp();else Ht();break;default:break}}async function Ft(t,n={}){let o=n.port||3000,d=n.watch!==!1,s=tt.resolve(t);if(!Bt.existsSync(s))return console.error(`${e.red}Error: File not found: ${e.bright}${s}${e.reset}`),!1;if(!s.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${s}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${t}${e.reset}...`);let c=null,u=async()=>{try{let{content:v,data:S}=await Re(s,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),T=n.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,w=T?.defaultTheme||"github-dark",b=["github-dark"],k=T?.additionalThemes||[],E=[...new Set([...b,...k])].map((R)=>`<option value="${R}"${R===w?" selected":""}>${R}</option>`).join(`
524
524
  `);return c=`
525
525
  <!DOCTYPE html>
526
526
  <html lang="en">
527
527
  <head>
528
528
  <meta charset="UTF-8">
529
529
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
530
- <title>${Ir(S.title||et.basename(s))}</title>
530
+ <title>${jr(S.title||tt.basename(s))}</title>
531
531
  <!-- Syntax highlighting styles -->
532
532
  <style id="syntax-theme">
533
533
  :root {
@@ -669,12 +669,12 @@ Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in brow
669
669
  min-width: 100px;
670
670
  color: #555;
671
671
  }
672
- ${lt()}
672
+ ${dt()}
673
673
  </style>
674
674
  </head>
675
675
  <body>
676
- ${ft(S)}
677
- ${dt(E)}
676
+ ${mt(S)}
677
+ ${pt(E)}
678
678
 
679
679
  ${v}
680
680
 
@@ -683,12 +683,12 @@ Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in brow
683
683
  </script>
684
684
  </body>
685
685
  </html>
686
- `,!0}catch(v){return console.error(`${e.red}Error processing Markdown file:${e.reset}`,v),!1}};if(!await u())return!1;let g=o;try{if(g=await Ve(o),g!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${g} 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:${g}/${e.reset}...`);let h=Lr({port:g,fetch(v){if(new URL(v.url).pathname==="/")return new Response(c,{headers:{"Content-Type":"text/html","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}
686
+ `,!0}catch(v){return console.error(`${e.red}Error processing Markdown file:${e.reset}`,v),!1}};if(!await u())return!1;let g=o;try{if(g=await Ve(o),g!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${g} 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:${g}/${e.reset}...`);let h=Ir({port:g,fetch(v){if(new URL(v.url).pathname==="/")return new Response(c,{headers:{"Content-Type":"text/html","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}
687
687
  ${v.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
688
688
  ${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(`
689
689
  ${e.bright}\u2192 ${e.cyan}http://localhost:${g}/${e.reset}`),console.log(`
690
- ${e.yellow}Routes:${e.reset}`);let x=et.relative(process.cwd(),s);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${x}${e.reset}`),console.log(`
691
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(h.url.toString(),()=>{if(d)Bt.watch(et.dirname(s),{recursive:!0}).close();h.stop()}),n.native)await Ze(g,{title:et.basename(s,".md")});if(d){let v=et.dirname(s);console.log(`${e.blue}Watching ${e.bright}${v}${e.reset} for changes...`);let S=Bt.watch(v,{recursive:!0},async(T,w)=>{if(w&&w.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${w}${e.yellow} changed, reprocessing...${e.reset}`),await u()});process.on("SIGINT",()=>{S.close(),h.stop(),process.exit(0)})}return!0}function Ir(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Hr}=globalThis.Bun;import Be from"fs";import ge from"path";class rn{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 n=t??this.options.wsPort,o=20;for(let d=0;d<o;d++)try{if(this.server=Bun.serve({port:n,fetch(s,c){if(c.upgrade(s,{data:{}}))return;return new Response("stx Hot Reload Server",{headers:{"Content-Type":"text/plain"}})},websocket:{open:(s)=>{if(this.clients.add(s),this.options.verbose)console.log(`[HMR] Client connected (${this.clients.size} total)`);s.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close:(s)=>{if(this.clients.delete(s),this.options.verbose)console.log(`[HMR] Client disconnected (${this.clients.size} total)`)},message:(s,c)=>{let u=typeof c==="string"?c:c.toString();if(u==="ping")return;try{let f=JSON.parse(u);if(f.type==="console"&&Array.isArray(f.args)){let g=f.args.join(" "),x={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[f.level]??"\x1B[36m";console.log(`${x}[browser]${f.level!=="log"?` ${f.level}`:""}\x1B[0m ${g}`)}}catch{}}}}),this.options.verbose)console.log(`[HMR] WebSocket server started on port ${n}`);return n}catch(s){if(s?.code==="EADDRINUSE"){n++;continue}throw s}throw Error(`Could not find an available port after ${o} 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 n=JSON.stringify(t),o=0;for(let d of this.clients)try{if(d.readyState===1)d.send(n),o++}catch{this.clients.delete(d)}if(this.options.verbose&&o>0)console.log(`[HMR] Broadcast ${t.type} to ${o} 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,n){this.broadcast({type:"css-update",path:t,content:n,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 jr(t,n={}){let{showOverlay:o=!0,reconnectInterval:d=1000,maxReconnectAttempts:s=10}=n;return`
690
+ ${e.yellow}Routes:${e.reset}`);let x=tt.relative(process.cwd(),s);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${x}${e.reset}`),console.log(`
691
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(h.url.toString(),()=>{if(d)Bt.watch(tt.dirname(s),{recursive:!0}).close();h.stop()}),n.native)await Ze(g,{title:tt.basename(s,".md")});if(d){let v=tt.dirname(s);console.log(`${e.blue}Watching ${e.bright}${v}${e.reset} for changes...`);let S=Bt.watch(v,{recursive:!0},async(T,w)=>{if(w&&w.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${w}${e.yellow} changed, reprocessing...${e.reset}`),await u()});process.on("SIGINT",()=>{S.close(),h.stop(),process.exit(0)})}return!0}function jr(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Nr}=globalThis.Bun;import Be from"fs";import ge from"path";class on{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 n=t??this.options.wsPort,o=20;for(let d=0;d<o;d++)try{if(this.server=Bun.serve({port:n,fetch(s,c){if(c.upgrade(s,{data:{}}))return;return new Response("stx Hot Reload Server",{headers:{"Content-Type":"text/plain"}})},websocket:{open:(s)=>{if(this.clients.add(s),this.options.verbose)console.log(`[HMR] Client connected (${this.clients.size} total)`);s.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close:(s)=>{if(this.clients.delete(s),this.options.verbose)console.log(`[HMR] Client disconnected (${this.clients.size} total)`)},message:(s,c)=>{let u=typeof c==="string"?c:c.toString();if(u==="ping")return;try{let f=JSON.parse(u);if(f.type==="console"&&Array.isArray(f.args)){let g=f.args.join(" "),x={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[f.level]??"\x1B[36m";console.log(`${x}[browser]${f.level!=="log"?` ${f.level}`:""}\x1B[0m ${g}`)}}catch{}}}}),this.options.verbose)console.log(`[HMR] WebSocket server started on port ${n}`);return n}catch(s){if(s?.code==="EADDRINUSE"){n++;continue}throw s}throw Error(`Could not find an available port after ${o} 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 n=JSON.stringify(t),o=0;for(let d of this.clients)try{if(d.readyState===1)d.send(n),o++}catch{this.clients.delete(d)}if(this.options.verbose&&o>0)console.log(`[HMR] Broadcast ${t.type} to ${o} 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,n){this.broadcast({type:"css-update",path:t,content:n,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 Br(t,n={}){let{showOverlay:o=!0,reconnectInterval:d=1000,maxReconnectAttempts:s=10}=n;return`
692
692
  <script>
693
693
  (function() {
694
694
  // stx Hot Reload Client
@@ -887,10 +887,10 @@ else {
887
887
  };
888
888
  })();
889
889
  </script>
890
- `}function Ne(t,n,o={}){let d=jr(n,o),s=t.lastIndexOf("</body>");if(s!==-1)return t.slice(0,s)+d+t.slice(s);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function gt(t){let n=t.toLowerCase();return n.endsWith(".css")||n.endsWith(".scss")||n.endsWith(".sass")||n.endsWith(".less")}function yt(t){let n=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>n.endsWith(d))}function bt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((o)=>o.test(t))}var tt=null;function vt(t){if(!tt)tt=new rn(t);return tt}function st(){if(tt)tt.stop(),tt=null}import wt from"path";var nt={name:"bun-plugin-stx",async setup(t){let o={...await a(),...t.config?.stx},d=new Set,s=o.webComponents?.enabled?`./${wt.relative(wt.dirname(t.config?.outdir||"dist"),o.webComponents.outputDir||"dist/web-components")}`:"/web-components",c=[];if(o.webComponents?.enabled)try{let u=await ws(o,d);if(c.push(...u),o.debug&&u.length>0)console.log(`Successfully built ${u.length} web components`)}catch(u){console.error("Failed to build web components:",u)}t.onLoad({filter:/\.stx$/},async({path:u})=>{try{let f=new Set;if(o.cache&&o.cachePath){let b=await cr(u,o);if(b){if(o.debug)console.log(`Using cached version of ${u}`);return{contents:b,loader:"html"}}}let g=await ke(()=>Bun.file(u).text(),"",(b)=>{throw new Cr(`Failed to read stx file: ${u}`,u,void 0,void 0,`File read error: ${b.message}`)});if(!g)throw new Cr(`stx file is empty: ${u}`,u);let{scriptContent:h,templateContent:x,allScripts:v}=oe.time("script-extraction",()=>{let b=g,k=de(g);if(k)b=k.content.trim();let _=g.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],E="",R=[];for(let C of _){let D=C.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",I=C.match(/<script\b([^>]*)>/i),V=I?I[1]:"";if(/\bserver\b/i.test(V))E=D;else R.push(C)}let A=b.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:E,templateContent:A,allScripts:R}}),S={__filename:u,__dirname:wt.dirname(u),__stx:{webComponentsPath:s,builtComponents:c}};await ke(()=>m(h,S,u),void 0,(b)=>{let k=new ae(`Script execution failed in ${u}: ${b.message}`,u,void 0,void 0,h.substring(0,100));if(B.log(k,{filePath:u,scriptContent:h}),o.debug)throw k});let w=await oe.timeAsync("directive-processing",async()=>await i(x,S,u,o,f));if(v.length>0){let{interpolateScriptsInTemplate:b}=await import("./chunk-ba43drcj.js"),k=b(v.join(`
890
+ `}function Ne(t,n,o={}){let d=Br(n,o),s=t.lastIndexOf("</body>");if(s!==-1)return t.slice(0,s)+d+t.slice(s);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function ht(t){let n=t.toLowerCase();return n.endsWith(".css")||n.endsWith(".scss")||n.endsWith(".sass")||n.endsWith(".less")}function bt(t){let n=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>n.endsWith(d))}function xt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((o)=>o.test(t))}var nt=null;function vt(t){if(!nt)nt=new on(t);return nt}function it(){if(nt)nt.stop(),nt=null}import wt from"path";var rt={name:"bun-plugin-stx",async setup(t){let o={...await a(),...t.config?.stx},d=new Set,s=o.webComponents?.enabled?`./${wt.relative(wt.dirname(t.config?.outdir||"dist"),o.webComponents.outputDir||"dist/web-components")}`:"/web-components",c=[];if(o.webComponents?.enabled)try{let u=await vs(o,d);if(c.push(...u),o.debug&&u.length>0)console.log(`Successfully built ${u.length} web components`)}catch(u){console.error("Failed to build web components:",u)}t.onLoad({filter:/\.stx$/},async({path:u})=>{try{let f=new Set;if(o.cache&&o.cachePath){let b=await lr(u,o);if(b){if(o.debug)console.log(`Using cached version of ${u}`);return{contents:b,loader:"html"}}}let g=await ke(()=>Bun.file(u).text(),"",(b)=>{throw new Er(`Failed to read stx file: ${u}`,u,void 0,void 0,`File read error: ${b.message}`)});if(!g)throw new Er(`stx file is empty: ${u}`,u);let{scriptContent:h,templateContent:x,allScripts:v}=oe.time("script-extraction",()=>{let b=g,k=de(g);if(k)b=k.content.trim();let _=g.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],E="",R=[];for(let C of _){let D=C.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",I=C.match(/<script\b([^>]*)>/i),V=I?I[1]:"";if(/\bserver\b/i.test(V))E=D;else R.push(C)}let A=b.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:E,templateContent:A,allScripts:R}}),S={__filename:u,__dirname:wt.dirname(u),__stx:{webComponentsPath:s,builtComponents:c}};await ke(()=>m(h,S,u),void 0,(b)=>{let k=new ae(`Script execution failed in ${u}: ${b.message}`,u,void 0,void 0,h.substring(0,100));if(B.log(k,{filePath:u,scriptContent:h}),o.debug)throw k});let w=await oe.timeAsync("directive-processing",async()=>await i(x,S,u,o,f));if(v.length>0){let{interpolateScriptsInTemplate:b}=await import("./chunk-7fhw11qd.js"),k=b(v.join(`
891
891
  `),S),_=w.search(/<\/body>/i);if(_!==-1)w=w.slice(0,_)+k+`
892
892
  `+w.slice(_);else w+=`
893
- ${k}`}if(w=await we(w),f.forEach((b)=>d.add(b)),o.cache&&o.cachePath){if(await lr(u,w,f,o),o.debug)console.log(`Cached template ${u} with ${f.size} dependencies`)}return{contents:w,loader:"html"}}catch(f){let g=f instanceof Error?f:new ae(`Plugin processing failed: ${String(f)}`,u);if(B.log(g,{filePath:u,buildConfig:t.config}),xn.logDetailedError(g,{filePath:u,plugin:"bun-plugin-stx"}),o.debug)console.error("stx Plugin Error:",g);let h=g,x=h.line||null,v=h.context||null;return{contents:o.debug||K()?`<!DOCTYPE html>
893
+ ${k}`}if(w=await we(w),f.forEach((b)=>d.add(b)),o.cache&&o.cachePath){if(await ur(u,w,f,o),o.debug)console.log(`Cached template ${u} with ${f.size} dependencies`)}return{contents:w,loader:"html"}}catch(f){let g=f instanceof Error?f:new ae(`Plugin processing failed: ${String(f)}`,u);if(B.log(g,{filePath:u,buildConfig:t.config}),Sn.logDetailedError(g,{filePath:u,plugin:"bun-plugin-stx"}),o.debug)console.error("stx Plugin Error:",g);let h=g,x=h.line||null,v=h.context||null;return{contents:o.debug||K()?`<!DOCTYPE html>
894
894
  <html lang="en">
895
895
  <head>
896
896
  <meta charset="UTF-8">
@@ -950,12 +950,12 @@ ${k}`}if(w=await we(w),f.forEach((b)=>d.add(b)),o.cache&&o.cachePath){if(await l
950
950
  <h1>Something went wrong</h1>
951
951
  <p>An internal error occurred. Please try again later.</p>
952
952
  </body>
953
- </html>`,loader:"html"}}})}};async function Br(t,n={}){let o=n.port||3000,d=n.watch!==!1,s=n.hotReload!==!1&&d,c=null,u=n.hmrPort||o+1,f=ge.resolve(t);if(!Be.existsSync(f))return console.error(`${e.red}Error: File not found: ${e.bright}${f}${e.reset}`),!1;if(f.endsWith(".md"))return Ft(f,n);else if(!f.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${f}${e.reset}. Only .stx and .md files are supported.`),!1;let g=l(process.cwd(),"output");Be.mkdirSync(g,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let h=null,x=async()=>{try{let D={name:"public-assets",setup(xe){xe.onResolve({filter:/^\/(images|fonts|assets|public)\//},(le)=>({path:le.path,external:!0}))}},I=await Bun.build({entrypoints:[f],outdir:g,plugins:[D,nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!I.success)return console.error(`${e.red}Build failed:${e.reset}`,I.logs),!1;let V=I.outputs.find((xe)=>xe.path.endsWith(".html"));if(!V)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return h=await Bun.file(V.path).text(),!0}catch(D){return console.error(`${e.red}Error building stx file:${e.reset}`,D),!1}};if(!await x())return!1;let S=ge.dirname(f);await an(S);let T=o;try{if(T=await Ve(o),T!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${T} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(s){let D=n.hmrPort||T+1;c=vt({wsPort:D,verbose:!1}),u=c.start(D)}let w={},b=null,k;try{let{loadStxConfig:D}=await import("./chunk-tynz075x.js"),I=await D();if(k=n.stxOptions?.serverApi??I.serverApi,I?.apiRouter)b=I?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(I?.apiRoutes){w=I.apiRoutes;let V=Object.keys(w).length;if(V>0)console.log(`${e.blue}Loaded ${e.bright}${V} API route${V>1?"s":""}${e.reset}`)}if(I?.broadcasting?.enabled)try{let{startBroadcasting:V,loadChannels:Y}=await import("./chunk-33gccrx0.js"),xe=I.broadcasting;await V(xe);let le=xe.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${le}/ws${e.reset}`);let Oe=ge.join(process.cwd(),"channels.ts");if(Be.existsSync(Oe))try{let ne=await Y(Oe);console.log(`${e.blue}Loaded ${e.bright}${ne} broadcast channel${ne!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ne){console.warn(`${e.yellow}Failed to load channels.ts: ${ne.message}${e.reset}`)}}catch(V){console.warn(`${e.yellow}Broadcasting failed to start: ${V.message}${e.reset}`)}}catch{}let{createServerApi:_,isServerApiSource:E}=await import("./chunk-qy01jdzk.js"),R=await _(process.cwd(),k);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${T}/${e.reset}...`),s)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${u}${e.reset}`);let A=Hr({port:T,async fetch(D){return Tn(D,await(async()=>{let I=new URL(D.url);if([g,ge.dirname(f),ge.join(process.cwd(),"public")].some((ne)=>E(ge.join(ne,I.pathname),process.cwd(),k)))return new Response("Not Found",{status:404});if(b)try{let ne=await b.handleRequest(D);if(ne.status!==404)return ne}catch{}if(w[I.pathname])try{return await w[I.pathname](D)}catch(ne){return new Response(JSON.stringify({error:ne.message}),{status:500,headers:{"Content-Type":"application/json"}})}let V=await R(D);if(V)return V;if(I.pathname==="/")return(async()=>{let F=await y(h||"");if(s)F=Ne(F,u);if(n.native)if(F.includes("<head>"))F=F.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else if(F.includes("<html"))F=F.replace(/(<html[^>]*>)/,"$1<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>");else F="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+F;if(n.titlebarHidden)if(F.includes("<head>"))F=F.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else if(F.includes("<html"))F=F.replace(/(<html[^>]*>)/,"$1<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>");else F=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${F}`;return F})().then((F)=>new Response(F,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Y=ge.join(g,I.pathname);if(Be.existsSync(Y)&&Be.statSync(Y).isFile()){let ne=Bun.file(Y),F=ge.extname(Y).toLowerCase(),L="text/plain";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}let xe=ge.dirname(f),le=ge.join(xe,I.pathname);if(Be.existsSync(le)&&Be.statSync(le).isFile()){let ne=Bun.file(le),F=ge.extname(le).toLowerCase(),L="text/plain";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}let Oe=ge.join(process.cwd(),"public",I.pathname);if(Be.existsSync(Oe)&&Be.statSync(Oe).isFile()){let ne=Bun.file(Oe),F=ge.extname(Oe).toLowerCase(),L="application/octet-stream";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}return new Response("Not Found",{status:404})})())},error(D){return new Response(`<pre>${D}
953
+ </html>`,loader:"html"}}})}};async function Fr(t,n={}){let o=n.port||3000,d=n.watch!==!1,s=n.hotReload!==!1&&d,c=null,u=n.hmrPort||o+1,f=ge.resolve(t);if(!Be.existsSync(f))return console.error(`${e.red}Error: File not found: ${e.bright}${f}${e.reset}`),!1;if(f.endsWith(".md"))return Ft(f,n);else if(!f.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${f}${e.reset}. Only .stx and .md files are supported.`),!1;let g=l(process.cwd(),"output");Be.mkdirSync(g,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let h=null,x=async()=>{try{let D={name:"public-assets",setup(xe){xe.onResolve({filter:/^\/(images|fonts|assets|public)\//},(le)=>({path:le.path,external:!0}))}},I=await Bun.build({entrypoints:[f],outdir:g,plugins:[D,rt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!I.success)return console.error(`${e.red}Build failed:${e.reset}`,I.logs),!1;let V=I.outputs.find((xe)=>xe.path.endsWith(".html"));if(!V)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return h=await Bun.file(V.path).text(),!0}catch(D){return console.error(`${e.red}Error building stx file:${e.reset}`,D),!1}};if(!await x())return!1;let S=ge.dirname(f);await cn(S);let T=o;try{if(T=await Ve(o),T!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${T} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(s){let D=n.hmrPort||T+1;c=vt({wsPort:D,verbose:!1}),u=c.start(D)}let w={},b=null,k;try{let{loadStxConfig:D}=await import("./chunk-wn7wmjcr.js"),I=await D();if(k=n.stxOptions?.serverApi??I.serverApi,I?.apiRouter)b=I?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(I?.apiRoutes){w=I.apiRoutes;let V=Object.keys(w).length;if(V>0)console.log(`${e.blue}Loaded ${e.bright}${V} API route${V>1?"s":""}${e.reset}`)}if(I?.broadcasting?.enabled)try{let{startBroadcasting:V,loadChannels:Y}=await import("./chunk-x0e0pcn0.js"),xe=I.broadcasting;await V(xe);let le=xe.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${le}/ws${e.reset}`);let Oe=ge.join(process.cwd(),"channels.ts");if(Be.existsSync(Oe))try{let ne=await Y(Oe);console.log(`${e.blue}Loaded ${e.bright}${ne} broadcast channel${ne!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ne){console.warn(`${e.yellow}Failed to load channels.ts: ${ne.message}${e.reset}`)}}catch(V){console.warn(`${e.yellow}Broadcasting failed to start: ${V.message}${e.reset}`)}}catch{}let{createServerApi:_,isServerApiSource:E}=await import("./chunk-hr8rzzcn.js"),R=await _(process.cwd(),k);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${T}/${e.reset}...`),s)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${u}${e.reset}`);let A=Nr({port:T,async fetch(D){return $n(D,await(async()=>{let I=new URL(D.url);if([g,ge.dirname(f),ge.join(process.cwd(),"public")].some((ne)=>E(ge.join(ne,I.pathname),process.cwd(),k)))return new Response("Not Found",{status:404});if(b)try{let ne=await b.handleRequest(D);if(ne.status!==404)return ne}catch{}if(w[I.pathname])try{return await w[I.pathname](D)}catch(ne){return new Response(JSON.stringify({error:ne.message}),{status:500,headers:{"Content-Type":"application/json"}})}let V=await R(D);if(V)return V;if(I.pathname==="/")return(async()=>{let z=await y(h||"");if(s)z=Ne(z,u);if(n.native)if(z.includes("<head>"))z=z.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(z.includes("<html"))z=z.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 z="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+z;if(n.titlebarHidden)if(z.includes("<head>"))z=z.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(z.includes("<html"))z=z.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 z=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${z}`;return z})().then((z)=>new Response(z,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Y=ge.join(g,I.pathname);if(Be.existsSync(Y)&&Be.statSync(Y).isFile()){let ne=Bun.file(Y),z=ge.extname(Y).toLowerCase(),L="text/plain";if(z===".ts"||z===".tsx"){let Fe=new Bun.Transpiler({loader:z===".tsx"?"tsx":"ts"}),ze=await ne.text(),Ye=Fe.transformSync(ze);return new Response(Ye,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(z){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}let xe=ge.dirname(f),le=ge.join(xe,I.pathname);if(Be.existsSync(le)&&Be.statSync(le).isFile()){let ne=Bun.file(le),z=ge.extname(le).toLowerCase(),L="text/plain";if(z===".ts"||z===".tsx"){let Fe=new Bun.Transpiler({loader:z===".tsx"?"tsx":"ts"}),ze=await ne.text(),Ye=Fe.transformSync(ze);return new Response(Ye,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(z){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}let Oe=ge.join(process.cwd(),"public",I.pathname);if(Be.existsSync(Oe)&&Be.statSync(Oe).isFile()){let ne=Bun.file(Oe),z=ge.extname(Oe).toLowerCase(),L="application/octet-stream";if(z===".ts"||z===".tsx"){let Fe=new Bun.Transpiler({loader:z===".tsx"?"tsx":"ts"}),ze=await ne.text(),Ye=Fe.transformSync(ze);return new Response(Ye,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(z){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}return new Response("Not Found",{status:404})})())},error(D){return new Response(`<pre>${D}
954
954
  ${D.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
955
955
  ${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(`
956
956
  ${e.bright}\u2192 ${e.cyan}http://localhost:${T}/${e.reset}`),console.log(`
957
957
  ${e.yellow}Routes:${e.reset}`);let C=ge.relative(process.cwd(),f);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${C}${e.reset}`),console.log(`
958
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(A.url.toString(),()=>{if(d)Be.watch(ge.dirname(f),{recursive:!0}).close();A.stop()}),n.native){let D=await Bun.file(f).text(),I=mt(D);await Ze(T,{title:ge.basename(f,".stx"),titlebarHidden:n.titlebarHidden===!0,nativeSidebar:!!I,sidebarConfig:I})}if(d){let D=ge.dirname(f);console.log(`${e.blue}Watching ${e.bright}${D}${e.reset} for changes...`);let I=Be.watch(D,{recursive:!0},async(V,Y)=>{if(!Y||bt(Y))return;if(yt(Y)){console.log(`${e.yellow}File ${e.bright}${Y}${e.yellow} changed, rebuilding...${e.reset}`),Ge.clear(),fe();let xe=await x();if(await rr(S),s&&c)if(xe)c.reload(Y);else c.error("Build failed - check console for details")}else if(gt(Y)){if(console.log(`${e.cyan}CSS ${e.bright}${Y}${e.cyan} changed${e.reset}`),s&&c)c.updateCss(Y)}});process.on("SIGINT",()=>{if(I.close(),c)st();A.stop(),process.exit(0)})}return!0}var{serve:Nr}=globalThis.Bun;import Ke from"fs";import Pe from"path";var on=`
958
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(A.url.toString(),()=>{if(d)Be.watch(ge.dirname(f),{recursive:!0}).close();A.stop()}),n.native){let D=await Bun.file(f).text(),I=gt(D);await Ze(T,{title:ge.basename(f,".stx"),titlebarHidden:n.titlebarHidden===!0,nativeSidebar:!!I,sidebarConfig:I})}if(d){let D=ge.dirname(f);console.log(`${e.blue}Watching ${e.bright}${D}${e.reset} for changes...`);let I=Be.watch(D,{recursive:!0},async(V,Y)=>{if(!Y||xt(Y))return;if(bt(Y)){console.log(`${e.yellow}File ${e.bright}${Y}${e.yellow} changed, rebuilding...${e.reset}`),Je.clear(),fe();let xe=await x();if(await sr(S),s&&c)if(xe)c.reload(Y);else c.error("Build failed - check console for details")}else if(ht(Y)){if(console.log(`${e.cyan}CSS ${e.bright}${Y}${e.cyan} changed${e.reset}`),s&&c)c.updateCss(Y)}});process.on("SIGINT",()=>{if(I.close(),c)it();A.stop(),process.exit(0)})}return!0}var{serve:Ur}=globalThis.Bun;import Xe from"fs";import Pe from"path";var sn=`
959
959
  <script data-stx-helpers>
960
960
  (function() {
961
961
  'use strict'
@@ -1266,14 +1266,14 @@ else {
1266
1266
 
1267
1267
  })()
1268
1268
  </script>
1269
- `;function cn(t){if(t.length===0)return"";if(t.length===1)return t[0];let n=t.map((d)=>d.split(Pe.sep)),o=[];for(let d=0;d<n[0].length;d++){let s=n[0][d];if(n.every((c)=>c[d]===s))o.push(s);else break}return o.join(Pe.sep)}async function Fr(t,n={}){let o=n.port||3000,d=n.watch!==!1;for(let w of t){let b=Pe.resolve(w);if(!Ke.existsSync(b))return console.error(`${e.red}Error: File not found: ${e.bright}${b}${e.reset}`),!1;if(!b.endsWith(".stx")&&!b.endsWith(".md"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${b}${e.reset}. Only .stx and .md files are supported.`),!1}let s=l(process.cwd(),"output");Ke.mkdirSync(s,{recursive:!0});let c=cn(t.map((w)=>Pe.dirname(Pe.resolve(w))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let u={},f=[],g=async()=>{try{for(let w of t){let b=Pe.resolve(w);if(b.endsWith(".md"))try{let{content:_,data:E}=await Re(b,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),R=n.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,A=R?.defaultTheme||"github-dark",C=["github-dark"],D=R?.additionalThemes||[],V=[...new Set([...C,...D])].map((Oe)=>`<option value="${Oe}"${Oe===A?" selected":""}>${Oe}</option>`).join(`
1269
+ `;function ln(t){if(t.length===0)return"";if(t.length===1)return t[0];let n=t.map((d)=>d.split(Pe.sep)),o=[];for(let d=0;d<n[0].length;d++){let s=n[0][d];if(n.every((c)=>c[d]===s))o.push(s);else break}return o.join(Pe.sep)}async function zr(t,n={}){let o=n.port||3000,d=n.watch!==!1;for(let w of t){let b=Pe.resolve(w);if(!Xe.existsSync(b))return console.error(`${e.red}Error: File not found: ${e.bright}${b}${e.reset}`),!1;if(!b.endsWith(".stx")&&!b.endsWith(".md"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${b}${e.reset}. Only .stx and .md files are supported.`),!1}let s=l(process.cwd(),"output");Xe.mkdirSync(s,{recursive:!0});let c=ln(t.map((w)=>Pe.dirname(Pe.resolve(w))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let u={},f=[],g=async()=>{try{for(let w of t){let b=Pe.resolve(w);if(b.endsWith(".md"))try{let{content:_,data:E}=await Re(b,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),R=n.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,A=R?.defaultTheme||"github-dark",C=["github-dark"],D=R?.additionalThemes||[],V=[...new Set([...C,...D])].map((Oe)=>`<option value="${Oe}"${Oe===A?" selected":""}>${Oe}</option>`).join(`
1270
1270
  `),Y=`
1271
1271
  <!DOCTYPE html>
1272
1272
  <html lang="en">
1273
1273
  <head>
1274
1274
  <meta charset="UTF-8">
1275
1275
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
1276
- <title>${sn(E.title||Pe.basename(b))}</title>
1276
+ <title>${an(E.title||Pe.basename(b))}</title>
1277
1277
  <!-- Syntax highlighting styles -->
1278
1278
  <style id="syntax-theme">
1279
1279
  :root {
@@ -1415,12 +1415,12 @@ else {
1415
1415
  min-width: 100px;
1416
1416
  color: #555;
1417
1417
  }
1418
- ${lt()}
1418
+ ${dt()}
1419
1419
  </style>
1420
1420
  </head>
1421
1421
  <body>
1422
- ${ft(E)}
1423
- ${dt(V)}
1422
+ ${mt(E)}
1423
+ ${pt(V)}
1424
1424
 
1425
1425
  ${_}
1426
1426
 
@@ -1429,26 +1429,26 @@ else {
1429
1429
  </script>
1430
1430
  </body>
1431
1431
  </html>
1432
- `,le=`/${Pe.relative(c,b).replace(/\.md$/,"")}`;if(le.endsWith("/index"))le=le.slice(0,-6)||"/";u[le||"/"]={filePath:b,content:Y,fileType:"md"}}catch(_){console.error(`${e.red}Error processing Markdown file ${e.bright}${w}${e.reset}:`,_);continue}else{let _={name:"public-assets",setup(C){C.onResolve({filter:/^\/(images|fonts|assets|public)\//},(D)=>({path:D.path,external:!0}))}},E;try{let C=await Bun.build({entrypoints:[b],outdir:s,plugins:[_,nt],define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!C.success){console.error(`${e.red}Build failed for ${e.bright}${w}${e.reset}:`,$e(C.logs,b));continue}let D=C.outputs.find((I)=>I.path.endsWith(".html"));if(!D){console.error(`${e.red}No HTML output found for ${e.bright}${w}${e.reset}`);continue}E=await Bun.file(D.path).text()}catch(C){console.error(`${e.red}Build failed for ${e.bright}${w}${e.reset}:
1433
- ${$e(C,b)}`);continue}let A=`/${Pe.relative(c,b).replace(/\.stx$/,"")}`;if(A.endsWith("/index"))A=A.slice(0,-6)||"/";if(A.includes("[")){let{regex:C,params:D}=Cs(A,{page:!0});f.push({pattern:C,paramNames:D,filePath:b,routeTemplate:A,fileType:"stx"}),u[A]={filePath:b,content:E,fileType:"stx"}}else u[A||"/"]={filePath:b,content:E,fileType:"stx"}}}if(Object.keys(u).length===0)return console.error(`${e.red}No files were successfully processed${e.reset}`),!1;return!0}catch(w){return console.error(`${e.red}Error processing files:${e.reset}`,$e(w)),!1}};if(!await g())return!1;let x=o;try{if(x=await Ve(o),x!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${x} 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:${x}/${e.reset}...`);let v=Nr({port:x,async fetch(w){let b=new URL(w.url),k=Pe.join(process.cwd(),"public",b.pathname);if(Ke.existsSync(k)&&Ke.statSync(k).isFile()){let R=Bun.file(k),A=Pe.extname(k).toLowerCase(),C="application/octet-stream";if(A===".ts"||A===".tsx"){let D=new Bun.Transpiler({loader:A===".tsx"?"tsx":"ts"}),I=await R.text(),V=D.transformSync(I);return new Response(V,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(A){case".html":C="text/html";break;case".css":C="text/css";break;case".js":C="text/javascript";break;case".json":C="application/json";break;case".png":C="image/png";break;case".jpg":case".jpeg":C="image/jpeg";break;case".gif":C="image/gif";break;case".svg":C="image/svg+xml";break;case".ico":C="image/x-icon";break;case".woff":C="font/woff";break;case".woff2":C="font/woff2";break;case".ttf":C="font/ttf";break;case".otf":C="font/otf";break;case".eot":C="application/vnd.ms-fontobject";break}return new Response(R,{headers:{"Content-Type":C}})}let _=u[b.pathname];if(!_&&!b.pathname.endsWith("/"))_=u[`${b.pathname}/`];if(!_)for(let R of f){let A=b.pathname.match(R.pattern);if(A){let C=u[R.routeTemplate];if(C){let D={};for(let Y=0;Y<R.paramNames.length;Y++)D[R.paramNames[Y]]=decodeURIComponent(A[Y+1]);let I=C.content,V=`<script>window.__routeParams = ${JSON.stringify(D)};</script>`;if(I.includes("</head>"))I=I.replace("</head>",`${V}
1434
- </head>`);else I=V+I;_={...C,content:I}}break}}if(_)return y(_.content).then((R)=>{if(R.includes("</head>"))R=R.replace("</head>",`${on}
1435
- </head>`);return new Response(R,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let E=Pe.join(s,b.pathname);if(Ke.existsSync(E)&&Ke.statSync(E).isFile()){let R=Bun.file(E),A=Pe.extname(E).toLowerCase(),C="text/plain";if(A===".ts"||A===".tsx"){let D=new Bun.Transpiler({loader:A===".tsx"?"tsx":"ts"}),I=await R.text(),V=D.transformSync(I);return new Response(V,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(A){case".html":C="text/html";break;case".css":C="text/css";break;case".js":C="text/javascript";break;case".json":C="application/json";break;case".png":C="image/png";break;case".jpg":case".jpeg":C="image/jpeg";break;case".gif":C="image/gif";break;case".svg":C="image/svg+xml";break;case".ico":C="image/x-icon";break;case".woff":C="font/woff";break;case".woff2":C="font/woff2";break;case".ttf":C="font/ttf";break;case".otf":C="font/otf";break;case".eot":C="application/vnd.ms-fontobject";break}return new Response(R,{headers:{"Content-Type":C}})}if(b.pathname!=="/"&&u["/"]){let R=Ce(w);return y(u["/"].content).then((A)=>{if(R){let C=A.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(C){let D=A.match(/<title[^>]*>([\s\S]*?)<\/title>/i),I=D?D[1]:"",V=`<!DOCTYPE html><html><head><title>${sn(I)}</title></head><body><main>${C[1]}</main></body></html>`;return new Response(V,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...M(),"Cache-Control":pt,Pragma:"no-cache",Expires:"0"}})}}return new Response(A,{headers:{"Content-Type":"text/html",...M(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})})}return new Response("Not Found",{status:404})},error(w){return new Response(`<pre>${w}
1432
+ `,le=`/${Pe.relative(c,b).replace(/\.md$/,"")}`;if(le.endsWith("/index"))le=le.slice(0,-6)||"/";u[le||"/"]={filePath:b,content:Y,fileType:"md"}}catch(_){console.error(`${e.red}Error processing Markdown file ${e.bright}${w}${e.reset}:`,_);continue}else{let _={name:"public-assets",setup(C){C.onResolve({filter:/^\/(images|fonts|assets|public)\//},(D)=>({path:D.path,external:!0}))}},E;try{let C=await Bun.build({entrypoints:[b],outdir:s,plugins:[_,rt],define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!C.success){console.error(`${e.red}Build failed for ${e.bright}${w}${e.reset}:`,$e(C.logs,b));continue}let D=C.outputs.find((I)=>I.path.endsWith(".html"));if(!D){console.error(`${e.red}No HTML output found for ${e.bright}${w}${e.reset}`);continue}E=await Bun.file(D.path).text()}catch(C){console.error(`${e.red}Build failed for ${e.bright}${w}${e.reset}:
1433
+ ${$e(C,b)}`);continue}let A=`/${Pe.relative(c,b).replace(/\.stx$/,"")}`;if(A.endsWith("/index"))A=A.slice(0,-6)||"/";if(A.includes("[")){let{regex:C,params:D}=Es(A,{page:!0});f.push({pattern:C,paramNames:D,filePath:b,routeTemplate:A,fileType:"stx"}),u[A]={filePath:b,content:E,fileType:"stx"}}else u[A||"/"]={filePath:b,content:E,fileType:"stx"}}}if(Object.keys(u).length===0)return console.error(`${e.red}No files were successfully processed${e.reset}`),!1;return!0}catch(w){return console.error(`${e.red}Error processing files:${e.reset}`,$e(w)),!1}};if(!await g())return!1;let x=o;try{if(x=await Ve(o),x!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${x} 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:${x}/${e.reset}...`);let v=Ur({port:x,async fetch(w){let b=new URL(w.url),k=Pe.join(process.cwd(),"public",b.pathname);if(Xe.existsSync(k)&&Xe.statSync(k).isFile()){let R=Bun.file(k),A=Pe.extname(k).toLowerCase(),C="application/octet-stream";if(A===".ts"||A===".tsx"){let D=new Bun.Transpiler({loader:A===".tsx"?"tsx":"ts"}),I=await R.text(),V=D.transformSync(I);return new Response(V,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(A){case".html":C="text/html";break;case".css":C="text/css";break;case".js":C="text/javascript";break;case".json":C="application/json";break;case".png":C="image/png";break;case".jpg":case".jpeg":C="image/jpeg";break;case".gif":C="image/gif";break;case".svg":C="image/svg+xml";break;case".ico":C="image/x-icon";break;case".woff":C="font/woff";break;case".woff2":C="font/woff2";break;case".ttf":C="font/ttf";break;case".otf":C="font/otf";break;case".eot":C="application/vnd.ms-fontobject";break}return new Response(R,{headers:{"Content-Type":C}})}let _=u[b.pathname];if(!_&&!b.pathname.endsWith("/"))_=u[`${b.pathname}/`];if(!_)for(let R of f){let A=b.pathname.match(R.pattern);if(A){let C=u[R.routeTemplate];if(C){let D={};for(let Y=0;Y<R.paramNames.length;Y++)D[R.paramNames[Y]]=decodeURIComponent(A[Y+1]);let I=C.content,V=`<script>window.__routeParams = ${JSON.stringify(D)};</script>`;if(I.includes("</head>"))I=I.replace("</head>",`${V}
1434
+ </head>`);else I=V+I;_={...C,content:I}}break}}if(_)return y(_.content).then((R)=>{if(R.includes("</head>"))R=R.replace("</head>",`${sn}
1435
+ </head>`);return new Response(R,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let E=Pe.join(s,b.pathname);if(Xe.existsSync(E)&&Xe.statSync(E).isFile()){let R=Bun.file(E),A=Pe.extname(E).toLowerCase(),C="text/plain";if(A===".ts"||A===".tsx"){let D=new Bun.Transpiler({loader:A===".tsx"?"tsx":"ts"}),I=await R.text(),V=D.transformSync(I);return new Response(V,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(A){case".html":C="text/html";break;case".css":C="text/css";break;case".js":C="text/javascript";break;case".json":C="application/json";break;case".png":C="image/png";break;case".jpg":case".jpeg":C="image/jpeg";break;case".gif":C="image/gif";break;case".svg":C="image/svg+xml";break;case".ico":C="image/x-icon";break;case".woff":C="font/woff";break;case".woff2":C="font/woff2";break;case".ttf":C="font/ttf";break;case".otf":C="font/otf";break;case".eot":C="application/vnd.ms-fontobject";break}return new Response(R,{headers:{"Content-Type":C}})}if(b.pathname!=="/"&&u["/"]){let R=Ce(w);return y(u["/"].content).then((A)=>{if(R){let C=A.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(C){let D=A.match(/<title[^>]*>([\s\S]*?)<\/title>/i),I=D?D[1]:"",V=`<!DOCTYPE html><html><head><title>${an(I)}</title></head><body><main>${C[1]}</main></body></html>`;return new Response(V,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...M(),"Cache-Control":ft,Pragma:"no-cache",Expires:"0"}})}}return new Response(A,{headers:{"Content-Type":"text/html",...M(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})})}return new Response("Not Found",{status:404})},error(w){return new Response(`<pre>${w}
1436
1436
  ${w.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
1437
1437
  ${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(`
1438
1438
  ${e.bright}\u2192 ${e.cyan}http://localhost:${x}/${e.reset}`),console.log(`
1439
1439
  ${e.yellow}Routes:${e.reset}`);let S=new Set(f.map((w)=>w.routeTemplate)),T=Object.entries(u).filter(([w])=>!S.has(w)).sort(([w],[b])=>w.localeCompare(b)).map(([w,b])=>({route:w==="/"?"/":w,filePath:Pe.relative(process.cwd(),b.filePath),fileType:b.fileType}));for(let w of f){let b=w.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");T.push({route:b,filePath:Pe.relative(process.cwd(),w.filePath),fileType:"stx"})}if(T.sort((w,b)=>w.route.localeCompare(b.route)),T.forEach((w,b)=>{let _=b===T.length-1?"\u2514\u2500 ":"\u251C\u2500 ",E=w.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${_}${w.route}${e.reset} \u2192 ${e.bright}${w.filePath}${e.reset} ${E}`)}),console.log(`
1440
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(v.url.toString(),()=>{if(d)Ke.watch(c,{recursive:!0}).close();v.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let w=Ke.watch(c,{recursive:!0},async(b,k)=>{if(!k)return;if(k.endsWith(".stx")||k.endsWith(".js")||k.endsWith(".ts")||k.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${k}${e.yellow} changed, rebuilding...${e.reset}`),Ge.clear(),fe(),await g()});process.on("SIGINT",()=>{w.close(),v.stop(),process.exit(0)})}return!0}function sn(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Ur}=globalThis.Bun;import me from"fs";import te from"path";async function ln(t){try{return fn(await Bun.file(t).text())}catch{return}}function zt(t){let n=Bun.file(t),o=te.extname(t).toLowerCase(),d={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},c=[".js",".css",".json"].includes(o)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(n,{headers:{"Content-Type":d[o]||"application/octet-stream",...c}})}async function zr(t=".",n={}){let o=n.port||3000,d=n.watch!==!1,s=n.hotReload!==!1&&d,c=null,u=n.hmrPort||o+1,f=te.resolve(t),{loadStxConfig:g}=await import("./chunk-tynz075x.js"),h=await g(f),{createServerApi:x,isServerApiSource:v}=await import("./chunk-qy01jdzk.js"),S=n.stxOptions?.serverApi??h.serverApi,T=await x(f,S),w=h.root&&h.root!=="."?te.join(f,h.root):f,b=n.pagesDir||h.pagesDir||"pages",k=te.join(w,b);if(!me.existsSync(k)&&!h._layerPageDirs?.some((O)=>me.existsSync(O)))return console.error(`${e.red}Error: No '${b}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${k}${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 ${b}/index.stx for the homepage.${e.reset}`),!1;let _=X(w,{pagesDir:b,pagesDirs:h._layerPageDirs?[k,...h._layerPageDirs.slice(1)]:void 0});if(_.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${k}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${_.length}${e.blue} routes${e.reset}`);let E=h?._pluginPageDirs||[],R=[];for(let{dir:O,prefix:j}of E)if(me.existsSync(O)){let z=X(te.dirname(O),{pagesDir:te.basename(O)});for(let Q of z){let q=j==="/"?Q.pattern:`${j}${Q.pattern==="/"?"":Q.pattern}`;R.push({route:{...Q,pattern:q},prefix:j})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${j}${e.reset}`)}let A=new Map,C=null,D=null;if(n.stxOptions?.shell!==!1){if(D=await sa(f,n.stxOptions?.shell),D){if(C=await po(D,n.stxOptions||{}),C)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(f,D)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}St(),await _t(f);let I=kt();if(I.length>0)console.log(`${e.blue}Loaded ${e.bright}${I.length}${e.blue} middleware: ${e.dim}${I.join(", ")}${e.reset}`);let V={},Y=null;try{let{loadStxConfig:O}=await import("./chunk-tynz075x.js"),j=await O(f);if(j?.apiRouter)Y=j?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(j?.apiRoutes){V=j.apiRoutes;let z=Object.keys(V).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(j?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:Q}=await import("./chunk-33gccrx0.js"),q=j.broadcasting;await z(q);let Ae=q.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Ae}/ws${e.reset}`);let ve=te.join(process.cwd(),"channels.ts");if(me.existsSync(ve))try{let N=await Q(ve);console.log(`${e.blue}Loaded ${e.bright}${N} broadcast channel${N!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(N){console.warn(`${e.yellow}Failed to load channels.ts: ${N.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let xe=l(f,"output");me.mkdirSync(xe,{recursive:!0});let le=new Map,Oe=new Set,ne=async(O)=>{let j=Es(k,O);if(!j)return null;try{let z=await Bun.build({entrypoints:[j],outdir:xe,plugins:[nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!z.success)return null;let Q=z.outputs.find((q)=>q.path.endsWith(".html"));if(!Q)return null;return await Bun.file(Q.path).text()}catch{return null}},F=new Map,L=async(O,j)=>{try{let{processDirectives:z,extractVariables:Q,defaultConfig:q,loadStxConfig:Ae,injectRouterScript:ve}=await import("./chunk-tynz075x.js"),{checkCache:N,cacheTemplate:J,readFileCached:W,templateCache:pe}=await import("./chunk-4xdapekt.js"),G=await Ae(f),Ue=(ie)=>{if(!ie)return ie;if(te.isAbsolute(ie))return ie;return te.resolve(f,ie)},ce={...q,...G,...n.stxOptions,autoShell:!0};if(n.debugDirectives)ce.debug=!0;ce.partialsDir=Ue(ce.partialsDir),ce.componentsDir=Ue(ce.componentsDir),ce.layoutsDir=Ue(ce.layoutsDir),ce.storesDir=Ue(ce.storesDir||"stores"),ce.cachePath=Ue(ce.cachePath)??l(f,"cache");let H=!j&&!n.profile,re=ce.cache!==!1;if(re&&H){let ie=pe.get(O.filePath);if(ie)try{if((await me.promises.stat(O.filePath)).mtime.getTime()<=ie.mtime){let He=!0;for(let Se of ie.dependencies){if(!me.existsSync(Se)){He=!1;break}if((await me.promises.stat(Se)).mtime.getTime()>ie.mtime){He=!1;break}}if(He){let Se=ie.output;if(C)Se=We(Se,{preserveHead:!0});let ot=F.get(O.filePath);return{route:O,content:Se,status:ot?.status??await ln(O.filePath),headers:ot?.headers}}}}catch{}let Ie=await N(O.filePath,ce);if(Ie){let je=Ie;if(C)je=We(je,{preserveHead:!0});let He=F.get(O.filePath);return{route:O,content:je,status:He?.status??await ln(O.filePath),headers:He?.headers}}}let Z=re?await W(O.filePath):await Bun.file(O.filePath).text(),se=fn(Z),{classifyAllScripts:ue}=await import("./chunk-tynz075x.js"),U=ue(Z),Le=U.server.map((ie)=>ie.content),Me=Z;for(let ie of U.server)Me=Me.replace(ie.fullTag,"");let ee={__filename:O.filePath,__dirname:te.dirname(O.filePath),__stx_options:ce,params:j??{},__stx_runtime_head:{}};for(let ie of Le)try{await Q(ie,ee,O.filePath)}catch(Ie){if(n.stxOptions?.debug)console.error("[stx] variable extraction error",O.filePath,Ie?.message||Ie)}let De=new Set,he;if(n.profile){let ie=performance.now();he=await z(Me,ee,O.filePath,ce,De);let Ie=performance.now()-ie,je=te.relative(f,O.filePath)||O.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else he=await z(Me,ee,O.filePath,ce,De);if(!C)he=await ve(he,{router:ce.router});{let{interpolateScriptExpressions:ie}=await import("./chunk-ba43drcj.js");he=he.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,je,He)=>{if(!/function\s+__stx_setup_/.test(He))return Ie;return`<script${je}>${ie(He,ee)}</script>`})}if(C)he=We(he,{preserveHead:!0});if(re&&H)await J(O.filePath,he,De,ce);let{extractStreamBoundaries:at}=await import("./chunk-ybd2tfqm.js"),Ye=at(ee),rt=ee.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let ie=ee.streamBoundaries||{},Ie={...ce,autoShell:!1},je=Object.keys(rt).map((Se)=>({id:Se,render:async()=>{let ot=typeof ie[Se]==="function"?await ie[Se]():void 0;return z(rt[Se],{...ee,$boundary:ot},O.filePath,Ie,new Set)}})),He=new Set(je.map((Se)=>Se.id));Ye=[...(Ye||[]).filter((Se)=>!He.has(Se.id)),...je]}if(Ye&&Ye.length>0)Oe.add(O.pattern);else Ye=void 0;let Wt=It(ee),Vt=Ot(ee);if(H)F.set(O.filePath,{status:Wt,headers:Vt});return{route:O,content:he,status:Wt??se,headers:Vt,boundaries:Ye}}catch(z){return console.error(`${e.red}Error building ${e.bright}${O.pattern}${e.reset}:`,z),null}},Fe=8,ze=async()=>{let O=new Set(le.keys()),j=new Set(A.keys());le.clear(),A.clear();let z=n.prebuild===!1?_.filter((q)=>O.has(q.pattern)):_,Q=n.prebuild===!1?R.filter(({route:q})=>j.has(q.pattern)):R;for(let q=0;q<z.length;q+=Fe){let Ae=z.slice(q,q+Fe),ve=await Promise.all(Ae.map((N)=>L(N)));for(let N of ve)if(N)le.set(N.route.pattern,N)}for(let q=0;q<Q.length;q+=Fe){let Ae=Q.slice(q,q+Fe),ve=await Promise.all(Ae.map(({route:N})=>L(N)));for(let N of ve)if(N)A.set(N.route.pattern,N)}return le.size>0};if(console.log(`${e.blue}${n.prebuild===!1?"Rendering pages on request...":"Building pages..."}${e.reset}`),!(n.prebuild===!1?_.length+R.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await an(f);let Xe=o;try{if(Xe=await Ve(o),Xe!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${Xe} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(s){let O=n.hmrPort||Xe+1;c=vt({wsPort:O,verbose:!1}),u=c.start(O)}let Rt=(O,j)=>{let Q=`<script data-stx-route-params>(function(){var p=${JSON.stringify(j).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>",`${Q}</head>`);if(O.includes("<body"))return O.replace(/<body([^>]*)>/,`<body$1>${Q}`);return Q+O};console.log(`${e.blue}Starting server...${e.reset}`);let Pt=Ur({port:Xe,hostname:n.hostname,async fetch(O){let j=new URL(O.url),z=n.stxOptions?.offline??h.offline;if(j.pathname===Po&&z?.enabled){if(!["GET","HEAD"].includes(O.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});return new Response(O.method==="HEAD"?null:Io(z,rs()),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let Q=h?.publicDir||"public",q=te.join(f,Q,j.pathname),Ae=te.join(f,j.pathname),ve=te.join(xe,j.pathname);if([q,Ae,ve].some((H)=>v(H,f,S)))return new Response("Not Found",{status:404});let[N,J,W]=await Promise.all([me.promises.stat(q).catch(()=>null),me.promises.stat(Ae).catch(()=>null),me.promises.stat(ve).catch(()=>null)]);if(N?.isFile()&&!v(q,f,S))return zt(q);if(J?.isFile()&&!v(Ae,f,S))return zt(Ae);if(W?.isFile()&&!v(ve,f,S))return zt(ve);if(j.pathname.startsWith("/_stx/component/")){let H=decodeURIComponent(j.pathname.slice(16));if(H)try{let re=`<${H} />`,Z={...buildConfig,autoShell:!1},se=await processDirectives(re,{},te.join(f,"components",`${H}.stx`),Z,new Set);return new Response(se,{headers:{"Content-Type":"text/html"}})}catch(re){return new Response(`<div class="stx-async-error">${re.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(j.pathname==="/_stx/img"){let{handleImageRequest:H}=await import("./chunk-mvfj17fr.js"),re=await H(O,{publicDir:te.join(f,Q),cacheDir:l(f,"cache","img")});if(re)return re}if(Y)try{let H=await Y.handleRequest(O);if(H.status!==404)return H}catch{}if(V[j.pathname])try{return await V[j.pathname](O)}catch(H){return new Response(JSON.stringify({error:H.message}),{status:500,headers:{"Content-Type":"application/json"}})}let pe=await T(O);if(pe)return pe;let G=dr(j.pathname,_);if(G){let H=le.get(G.route.pattern),re=Oe.has(G.route.pattern);if(!H||G.route.isDynamic&&Object.keys(G.params).length>0||re){let Z=await L(G.route,G.params);if(Z){if(H=Z,!G.route.isDynamic&&!re)le.set(G.route.pattern,Z)}}if(H){let Z=H.status??200,se=H.headers??{},ue=(G.route.filePath?ht(await Bun.file(G.route.filePath).text().catch(()=>"")):null)??{};if(ue.validate){if(!await ue.validate({params:G.params})){let Me=await ne(404);if(Me){let ee=Me;if(ee=await y(ee,f),s)ee=Ne(ee,u);return new Response(ee,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(ue.middleware){let Le=Ct(j.pathname,G.params,ue,j.search),Me=Et(Le,null,O,{isServer:!0}),ee=await Tt(ue.middleware,Me);if(ee.redirect){let De=ee.redirect.path,he=ee.redirect.options.redirectCode||302,at=new Headers(ee.responseHeaders);return at.set("Location",De),new Response(null,{status:he,headers:at})}if(ee.abort){let{statusCode:De,message:he}=ee.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${De}</title></head><body><h1>Error ${De}</h1><p>${he}</p></body></html>`,{status:De,headers:{"Content-Type":"text/html"}})}if(Object.keys(ee.state).length>0){let De=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(ee.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;H.content=H.content.replace("</head>",`${De}</head>`)}}let U=H.content;if(C&&oa(O)){let Le=Qe(U),Me=be(U),ee=U.match(/<title[^>]*>([\s\S]*?)<\/title>/i),De=ee?Rn(ee[1].trim()):"";if(Object.keys(G.params).length>0)U=Rt(U,G.params);U=await y(U,f);let he=h?.router?.container||"main";return U=Ee(U,he,!0),new Response(U,{status:Z,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":Me?"true":"false",...De&&{"X-STX-Title":encodeURIComponent(De)},[ec]:rs(),...M(),"Cache-Control":pt}})}if(C)U=Wr(C,U);if(Object.keys(G.params).length>0)U=Rt(U,G.params);if(U=await y(U,f),s)U=Ne(U,u);if(n.native)if(U.includes("<head>"))U=U.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else U="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+U;if(n.titlebarHidden)if(U.includes("<head>"))U=U.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else U=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${U}`;if(H.boundaries&&H.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:Me}=await import("./chunk-ybd2tfqm.js");return Me(Le(U,H.boundaries,{timeoutMs:30000}),{status:Z,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(U,{status:Z,headers:{"Content-Type":"text/html",...M(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...se}})}}if(R.length>0){let H=R.map((Z)=>Z.route),re=dr(j.pathname,H);if(re){let Z=A.get(re.route.pattern);if(!Z||re.route.isDynamic){let se=await L(re.route,re.params);if(se){if(Z=se,!re.route.isDynamic)A.set(re.route.pattern,se)}}if(Z){let se=Z.content;if(C)se=Wr(C,se);if(Object.keys(re.params).length>0)se=Rt(se,re.params);if(se=await y(se,f),s)se=Ne(se,u);return new Response(se,{status:Z.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:Z}of E)if(Z!=="/"&&j.pathname.startsWith(Z)){let se=A.get(Z)||A.get(Z+"/");if(!se){let ue=R.find(({route:U})=>U.pattern===Z||U.pattern===`${Z}/`);if(ue){let U=await L(ue.route);if(U)se=U,A.set(ue.route.pattern,U)}}if(se){let ue=se.content;if(C)ue=Wr(C,ue);if(ue=await y(ue,f),s)ue=Ne(ue,u);return new Response(ue,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(xt(j.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Ue=le.get("/");if(Ue){let H=Ue.content;if(H=await y(H,f),s)H=Ne(H,u);if(n.native)if(H.includes("<head>"))H=H.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 H="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+H;return new Response(H,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let ce=await ne(404);if(ce){let H=ce;if(H=await y(H,f),s)H=Ne(H,u);return new Response(H,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(O){let j=await ne(500);if(j)return new Response(j,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${O}
1440
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(v.url.toString(),()=>{if(d)Xe.watch(c,{recursive:!0}).close();v.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let w=Xe.watch(c,{recursive:!0},async(b,k)=>{if(!k)return;if(k.endsWith(".stx")||k.endsWith(".js")||k.endsWith(".ts")||k.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${k}${e.yellow} changed, rebuilding...${e.reset}`),Je.clear(),fe(),await g()});process.on("SIGINT",()=>{w.close(),v.stop(),process.exit(0)})}return!0}function an(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Wr}=globalThis.Bun;import me from"fs";import te from"path";async function dn(t){try{return gn(await Bun.file(t).text())}catch{return}}function zt(t){let n=Bun.file(t),o=te.extname(t).toLowerCase(),d={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},c=[".js",".css",".json"].includes(o)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(n,{headers:{"Content-Type":d[o]||"application/octet-stream",...c}})}async function Hr(t=".",n={}){let o=n.port||3000,d=n.watch!==!1,s=n.hotReload!==!1&&d,c=null,u=n.hmrPort||o+1,f=te.resolve(t),{loadStxConfig:g}=await import("./chunk-wn7wmjcr.js"),h=await g(f),{createServerApi:x,isServerApiSource:v}=await import("./chunk-hr8rzzcn.js"),S=n.stxOptions?.serverApi??h.serverApi,T=await x(f,S),w=h.root&&h.root!=="."?te.join(f,h.root):f,b=n.pagesDir||h.pagesDir||"pages",k=te.join(w,b);if(!me.existsSync(k)&&!h._layerPageDirs?.some((O)=>me.existsSync(O)))return console.error(`${e.red}Error: No '${b}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${k}${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 ${b}/index.stx for the homepage.${e.reset}`),!1;let _=X(w,{pagesDir:b,pagesDirs:h._layerPageDirs?[k,...h._layerPageDirs.slice(1)]:void 0});if(_.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${k}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${_.length}${e.blue} routes${e.reset}`);let E=h?._pluginPageDirs||[],R=[];for(let{dir:O,prefix:j}of E)if(me.existsSync(O)){let N=X(te.dirname(O),{pagesDir:te.basename(O)});for(let Q of N){let q=j==="/"?Q.pattern:`${j}${Q.pattern==="/"?"":Q.pattern}`;R.push({route:{...Q,pattern:q},prefix:j})}if(N.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${N.length}${e.blue} routes at ${e.cyan}${j}${e.reset}`)}let A=new Map,C=null,D=null;if(n.stxOptions?.shell!==!1){if(D=await oa(f,n.stxOptions?.shell),D){if(C=await fo(D,n.stxOptions||{}),C)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(f,D)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}kt(),await Ct(f);let I=_t();if(I.length>0)console.log(`${e.blue}Loaded ${e.bright}${I.length}${e.blue} middleware: ${e.dim}${I.join(", ")}${e.reset}`);let V={},Y=null;try{let{loadStxConfig:O}=await import("./chunk-wn7wmjcr.js"),j=await O(f);if(j?.apiRouter)Y=j?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(j?.apiRoutes){V=j.apiRoutes;let N=Object.keys(V).length;if(N>0)console.log(`${e.blue}Loaded ${e.bright}${N} API route${N>1?"s":""}${e.reset}`)}if(j?.broadcasting?.enabled)try{let{startBroadcasting:N,loadChannels:Q}=await import("./chunk-x0e0pcn0.js"),q=j.broadcasting;await N(q);let Ae=q.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Ae}/ws${e.reset}`);let ve=te.join(process.cwd(),"channels.ts");if(me.existsSync(ve))try{let U=await Q(ve);console.log(`${e.blue}Loaded ${e.bright}${U} broadcast channel${U!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(U){console.warn(`${e.yellow}Failed to load channels.ts: ${U.message}${e.reset}`)}}catch(N){console.warn(`${e.yellow}Broadcasting failed to start: ${N.message}${e.reset}`)}}catch{}let xe=l(f,"output");me.mkdirSync(xe,{recursive:!0});let le=new Map,Oe=new Set,ne=async(O)=>{let j=Ts(k,O);if(!j)return null;try{let N=await Bun.build({entrypoints:[j],outdir:xe,plugins:[rt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!N.success)return null;let Q=N.outputs.find((q)=>q.path.endsWith(".html"));if(!Q)return null;return await Bun.file(Q.path).text()}catch{return null}},z=new Map,L=async(O,j)=>{try{let{processDirectives:N,extractVariables:Q,defaultConfig:q,loadStxConfig:Ae,injectRouterScript:ve}=await import("./chunk-wn7wmjcr.js"),{checkCache:U,cacheTemplate:J,readFileCached:W,templateCache:pe}=await import("./chunk-qezg1070.js"),G=await Ae(f),Ue=(ie)=>{if(!ie)return ie;if(te.isAbsolute(ie))return ie;return te.resolve(f,ie)},ce={...q,...G,...n.stxOptions,autoShell:!0};if(n.debugDirectives)ce.debug=!0;ce.partialsDir=Ue(ce.partialsDir),ce.componentsDir=Ue(ce.componentsDir),ce.layoutsDir=Ue(ce.layoutsDir),ce.storesDir=Ue(ce.storesDir||"stores"),ce.cachePath=Ue(ce.cachePath)??l(f,"cache");let H=!j&&!n.profile,re=ce.cache!==!1;if(re&&H){let ie=pe.get(O.filePath);if(ie)try{if((await me.promises.stat(O.filePath)).mtime.getTime()<=ie.mtime){let He=!0;for(let Se of ie.dependencies){if(!me.existsSync(Se)){He=!1;break}if((await me.promises.stat(Se)).mtime.getTime()>ie.mtime){He=!1;break}}if(He){let Se=ie.output;if(C)Se=We(Se,{preserveHead:!0});let st=z.get(O.filePath);return{route:O,content:Se,status:st?.status??await dn(O.filePath),headers:st?.headers}}}}catch{}let Ie=await U(O.filePath,ce);if(Ie){let je=Ie;if(C)je=We(je,{preserveHead:!0});let He=z.get(O.filePath);return{route:O,content:je,status:He?.status??await dn(O.filePath),headers:He?.headers}}}let Z=re?await W(O.filePath):await Bun.file(O.filePath).text(),se=gn(Z),{classifyAllScripts:ue}=await import("./chunk-wn7wmjcr.js"),F=ue(Z),Le=F.server.map((ie)=>ie.content),Me=Z;for(let ie of F.server)Me=Me.replace(ie.fullTag,"");let ee={__filename:O.filePath,__dirname:te.dirname(O.filePath),__stx_options:ce,params:j??{},__stx_runtime_head:{}};for(let ie of Le)try{await Q(ie,ee,O.filePath)}catch(Ie){if(n.stxOptions?.debug)console.error("[stx] variable extraction error",O.filePath,Ie?.message||Ie)}let De=new Set,he;if(n.profile){let ie=performance.now();he=await N(Me,ee,O.filePath,ce,De);let Ie=performance.now()-ie,je=te.relative(f,O.filePath)||O.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else he=await N(Me,ee,O.filePath,ce,De);if(!C)he=await ve(he,{router:ce.router});{let{interpolateScriptExpressions:ie}=await import("./chunk-7fhw11qd.js");he=he.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,je,He)=>{if(!/function\s+__stx_setup_/.test(He))return Ie;return`<script${je}>${ie(He,ee)}</script>`})}if(C)he=We(he,{preserveHead:!0});if(re&&H)await J(O.filePath,he,De,ce);let{extractStreamBoundaries:ct}=await import("./chunk-gxp9ms4w.js"),Qe=ct(ee),ot=ee.__streamTemplates;if(ot&&typeof ot==="object"&&Object.keys(ot).length>0){let ie=ee.streamBoundaries||{},Ie={...ce,autoShell:!1},je=Object.keys(ot).map((Se)=>({id:Se,render:async()=>{let st=typeof ie[Se]==="function"?await ie[Se]():void 0;return N(ot[Se],{...ee,$boundary:st},O.filePath,Ie,new Set)}})),He=new Set(je.map((Se)=>Se.id));Qe=[...(Qe||[]).filter((Se)=>!He.has(Se.id)),...je]}if(Qe&&Qe.length>0)Oe.add(O.pattern);else Qe=void 0;let Vt=Ot(ee),qt=Nt(ee);if(H)z.set(O.filePath,{status:Vt,headers:qt});return{route:O,content:he,status:Vt??se,headers:qt,boundaries:Qe}}catch(N){return console.error(`${e.red}Error building ${e.bright}${O.pattern}${e.reset}:`,N),null}},Fe=8,ze=async()=>{let O=new Set(le.keys()),j=new Set(A.keys());le.clear(),A.clear();let N=n.prebuild===!1?_.filter((q)=>O.has(q.pattern)):_,Q=n.prebuild===!1?R.filter(({route:q})=>j.has(q.pattern)):R;for(let q=0;q<N.length;q+=Fe){let Ae=N.slice(q,q+Fe),ve=await Promise.all(Ae.map((U)=>L(U)));for(let U of ve)if(U)le.set(U.route.pattern,U)}for(let q=0;q<Q.length;q+=Fe){let Ae=Q.slice(q,q+Fe),ve=await Promise.all(Ae.map(({route:U})=>L(U)));for(let U of ve)if(U)A.set(U.route.pattern,U)}return le.size>0};if(console.log(`${e.blue}${n.prebuild===!1?"Rendering pages on request...":"Building pages..."}${e.reset}`),!(n.prebuild===!1?_.length+R.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await cn(f);let Ge=o;try{if(Ge=await Ve(o),Ge!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${Ge} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(s){let O=n.hmrPort||Ge+1;c=vt({wsPort:O,verbose:!1}),u=c.start(O)}let Pt=(O,j)=>{let Q=`<script data-stx-route-params>(function(){var p=${JSON.stringify(j).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>",`${Q}</head>`);if(O.includes("<body"))return O.replace(/<body([^>]*)>/,`<body$1>${Q}`);return Q+O};console.log(`${e.blue}Starting server...${e.reset}`);let At=Wr({port:Ge,hostname:n.hostname,async fetch(O){let j=new URL(O.url),N=n.stxOptions?.offline??h.offline;if(j.pathname===Io&&N?.enabled){if(!["GET","HEAD"].includes(O.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});return new Response(O.method==="HEAD"?null:Oo(N,ss()),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let Q=h?.publicDir||"public",q=te.join(f,Q,j.pathname),Ae=te.join(f,j.pathname),ve=te.join(xe,j.pathname);if([q,Ae,ve].some((H)=>v(H,f,S)))return new Response("Not Found",{status:404});let[U,J,W]=await Promise.all([me.promises.stat(q).catch(()=>null),me.promises.stat(Ae).catch(()=>null),me.promises.stat(ve).catch(()=>null)]);if(U?.isFile()&&!v(q,f,S))return zt(q);if(J?.isFile()&&!v(Ae,f,S))return zt(Ae);if(W?.isFile()&&!v(ve,f,S))return zt(ve);if(j.pathname.startsWith("/_stx/component/")){let H=decodeURIComponent(j.pathname.slice(16));if(H)try{let re=`<${H} />`,Z={...buildConfig,autoShell:!1},se=await processDirectives(re,{},te.join(f,"components",`${H}.stx`),Z,new Set);return new Response(se,{headers:{"Content-Type":"text/html"}})}catch(re){return new Response(`<div class="stx-async-error">${re.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(j.pathname==="/_stx/img"){let{handleImageRequest:H}=await import("./chunk-mcevnfnx.js"),re=await H(O,{publicDir:te.join(f,Q),cacheDir:l(f,"cache","img")});if(re)return re}if(Y)try{let H=await Y.handleRequest(O);if(H.status!==404)return H}catch{}if(V[j.pathname])try{return await V[j.pathname](O)}catch(H){return new Response(JSON.stringify({error:H.message}),{status:500,headers:{"Content-Type":"application/json"}})}let pe=await T(O);if(pe)return pe;let G=pr(j.pathname,_);if(G){let H=le.get(G.route.pattern),re=Oe.has(G.route.pattern);if(!H||G.route.isDynamic&&Object.keys(G.params).length>0||re){let Z=await L(G.route,G.params);if(Z){if(H=Z,!G.route.isDynamic&&!re)le.set(G.route.pattern,Z)}}if(H){let Z=H.status??200,se=H.headers??{},ue=(G.route.filePath?yt(await Bun.file(G.route.filePath).text().catch(()=>"")):null)??{};if(ue.validate){if(!await ue.validate({params:G.params})){let Me=await ne(404);if(Me){let ee=Me;if(ee=await y(ee,f),s)ee=Ne(ee,u);return new Response(ee,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(ue.middleware){let Le=Et(j.pathname,G.params,ue,j.search),Me=Tt(Le,null,O,{isServer:!0}),ee=await $t(ue.middleware,Me);if(ee.redirect){let De=ee.redirect.path,he=ee.redirect.options.redirectCode||302,ct=new Headers(ee.responseHeaders);return ct.set("Location",De),new Response(null,{status:he,headers:ct})}if(ee.abort){let{statusCode:De,message:he}=ee.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${De}</title></head><body><h1>Error ${De}</h1><p>${he}</p></body></html>`,{status:De,headers:{"Content-Type":"text/html"}})}if(Object.keys(ee.state).length>0){let De=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(ee.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;H.content=H.content.replace("</head>",`${De}</head>`)}}let F=H.content;if(C&&ia(O)&&qe(F,h?.router?.container||"main")){let Le=et(F),Me=be(F),ee=F.match(/<title[^>]*>([\s\S]*?)<\/title>/i),De=ee?An(ee[1].trim()):"";if(Object.keys(G.params).length>0)F=Pt(F,G.params);F=await y(F,f);let he=h?.router?.container||"main";return F=Ee(F,he,!0),new Response(F,{status:Z,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":Me?"true":"false",...De&&{"X-STX-Title":encodeURIComponent(De)},[tc]:ss(),...M(),"Cache-Control":ft}})}if(C)F=qr(C,F);if(Object.keys(G.params).length>0)F=Pt(F,G.params);if(F=await y(F,f),s)F=Ne(F,u);if(n.native)if(F.includes("<head>"))F=F.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else F="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+F;if(n.titlebarHidden)if(F.includes("<head>"))F=F.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else F=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${F}`;if(H.boundaries&&H.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:Me}=await import("./chunk-gxp9ms4w.js");return Me(Le(F,H.boundaries,{timeoutMs:30000}),{status:Z,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(F,{status:Z,headers:{"Content-Type":"text/html",...M(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...se}})}}if(R.length>0){let H=R.map((Z)=>Z.route),re=pr(j.pathname,H);if(re){let Z=A.get(re.route.pattern);if(!Z||re.route.isDynamic){let se=await L(re.route,re.params);if(se){if(Z=se,!re.route.isDynamic)A.set(re.route.pattern,se)}}if(Z){let se=Z.content;if(C)se=qr(C,se);if(Object.keys(re.params).length>0)se=Pt(se,re.params);if(se=await y(se,f),s)se=Ne(se,u);return new Response(se,{status:Z.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:Z}of E)if(Z!=="/"&&j.pathname.startsWith(Z)){let se=A.get(Z)||A.get(Z+"/");if(!se){let ue=R.find(({route:F})=>F.pattern===Z||F.pattern===`${Z}/`);if(ue){let F=await L(ue.route);if(F)se=F,A.set(ue.route.pattern,F)}}if(se){let ue=se.content;if(C)ue=qr(C,ue);if(ue=await y(ue,f),s)ue=Ne(ue,u);return new Response(ue,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(St(j.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Ue=le.get("/");if(Ue){let H=Ue.content;if(H=await y(H,f),s)H=Ne(H,u);if(n.native)if(H.includes("<head>"))H=H.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 H="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+H;return new Response(H,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let ce=await ne(404);if(ce){let H=ce;if(H=await y(H,f),s)H=Ne(H,u);return new Response(H,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(O){let j=await ne(500);if(j)return new Response(j,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${O}
1441
1441
  ${O.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});if(console.clear(),console.log(`
1442
1442
  ${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(`
1443
- ${e.bright}\u2192 ${e.cyan}http://localhost:${Xe}/${e.reset}`),s)console.log(`${e.dim} HMR: ws://localhost:${u}${e.reset}`);console.log(`
1444
- ${e.yellow}Routes:${e.reset}`);let At=[...Ts(_,f)];for(let{route:O}of R)At.push(`${O.pattern}`);if(At.forEach((O,j)=>{let Q=j===At.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${Q}${e.reset}${O}`)}),console.log(`
1445
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(Pt.url.toString(),()=>{if(c)st();Pt.stop()}),n.native){let O,j=te.join(k,"index.stx");if(me.existsSync(j)){let Q=await Bun.file(j).text();O=mt(Q)}let z=h?.app?.window??{};await Ze(Xe,{title:h?.app?.head?.title||te.basename(f)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??n.titlebarHidden===!0,nativeSidebar:!!O,sidebarConfig:O})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let O=(N)=>N.startsWith("public/")||N.startsWith("public\\"),j=(N)=>{let J=N.toLowerCase();return J.endsWith(".stx")||J.endsWith(".html")||J.endsWith(".md")},z=new Map,Q=()=>{let N=new Set([f,...h._layerGraph?.layers.map((J)=>J.root)??[],...h._layerGraph?.configDependencies.map((J)=>te.dirname(J))??[]].filter((J)=>me.existsSync(J)).map((J)=>me.realpathSync(J)));for(let J of h._layerGraph?.layers??[])for(let W of Object.values(J.resources)){if(!me.existsSync(W))continue;let pe=me.realpathSync(W);if(![...N].some((G)=>pe===G||pe.startsWith(`${G}${te.sep}`)))N.add(pe)}for(let[J,W]of z)if(!N.has(J))W.close(),z.delete(J);for(let J of N)if(!z.has(J)&&me.existsSync(J))z.set(J,me.watch(J,{recursive:!0},(W,pe)=>{Ae(J,W,pe).catch((G)=>console.error("[stx] Layer rebuild failed:",G))}))},q=Promise.resolve(),Ae=(N,J,W)=>(q=q.catch(()=>{}).then(()=>ve(N,J,W)),q),ve=async(N,J,W)=>{if(!W||bt(W))return;if(yt(W)){if(h._layerGraph){let pe=await g(f);Object.assign(h,pe),_.splice(0,_.length,...X(w,{pagesDir:b,pagesDirs:pe._layerPageDirs?[k,...pe._layerPageDirs.slice(1)]:void 0})),Q()}if(O(W)){if(console.log(`${e.cyan}${W} changed${e.reset}`),s&&c)c.reload(W)}else if(j(W)){console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),Ge.clear(),fe();try{let{invalidateFileCache:pe,templateCache:G}=await import("./chunk-4xdapekt.js");pe(te.resolve(N,W)),G.delete(te.resolve(N,W))}catch{}if(D&&W){if(te.resolve(N,W)===D||te.basename(D)===W){let G=await po(D,n.stxOptions||{});if(G)C=G}}if(await ze(),await rr(f),s&&c)c.reload(W)}else{console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),Ge.clear(),fe();try{let{invalidateFileCache:pe,templateCache:G}=await import("./chunk-4xdapekt.js");pe(te.resolve(N,W)),G.delete(te.resolve(N,W))}catch{}if(await ze(),s&&c)c.reload(W)}}else if(gt(W)){if(console.log(`${e.cyan}CSS ${W} changed${e.reset}`),s&&c)c.updateCss(W)}};Q(),process.on("SIGINT",()=>{for(let N of z.values())N.close();if(c)st();Pt.stop(),process.exit(0)})}return!0}import Nt from"fs";import it from"path";async function Vr(t){try{let o=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!o)return[];let d=o[1],s=[],c=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,u;while((u=c.exec(d))!==null){let f=u[1],g=u[2]||u[3]||u[4];if(!g)continue;let h={name:g},x=f.match(/@type\s+\{([^}]+)\}/i);if(x)h.type=x[1].trim();if(f.match(/@required/i))h.required=!0;let S=f.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)h.default=S[1].trim();let T=f.split(`
1446
- `).map((w)=>w.trim().replace(/^\*\s*/,"")).filter((w)=>!w.startsWith("@")&&w.length>0);h.description=T.join(" ").trim(),s.push(h)}if(s.length===0){let f=d.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(f){let h=f[1].split(",").map((x)=>x.trim()).filter(Boolean);for(let x of h){let[v]=x.split(":").map((S)=>S.trim());if(v)s.push({name:v})}}}return s}catch(n){return console.error(`Error extracting props from ${t}:`,n),[]}}async function qr(t){try{let n=await Bun.file(t).text(),o=n.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||n.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(o)return o[1].split(`
1447
- `).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Kr(t,n=!1,o){let d=it.basename(t,".stx"),s=await Vr(t),c=await qr(t),u="";if(n&&o)u=`<${o}></${o}>`;else{let f=s.map((g)=>{if(g.type==="boolean")return`:${g.name}="true"`;return`${g.name}="value"`}).join(`
1443
+ ${e.bright}\u2192 ${e.cyan}http://localhost:${Ge}/${e.reset}`),s)console.log(`${e.dim} HMR: ws://localhost:${u}${e.reset}`);console.log(`
1444
+ ${e.yellow}Routes:${e.reset}`);let Dt=[...$s(_,f)];for(let{route:O}of R)Dt.push(`${O.pattern}`);if(Dt.forEach((O,j)=>{let Q=j===Dt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${Q}${e.reset}${O}`)}),console.log(`
1445
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(At.url.toString(),()=>{if(c)it();At.stop()}),n.native){let O,j=te.join(k,"index.stx");if(me.existsSync(j)){let Q=await Bun.file(j).text();O=gt(Q)}let N=h?.app?.window??{};await Ze(Ge,{title:h?.app?.head?.title||te.basename(f)||"stx App",width:N.width,height:N.height,darkMode:N.darkMode,hotReload:N.hotReload,titlebarHidden:N.titlebarHidden??n.titlebarHidden===!0,nativeSidebar:!!O,sidebarConfig:O})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let O=(U)=>U.startsWith("public/")||U.startsWith("public\\"),j=(U)=>{let J=U.toLowerCase();return J.endsWith(".stx")||J.endsWith(".html")||J.endsWith(".md")},N=new Map,Q=()=>{let U=new Set([f,...h._layerGraph?.layers.map((J)=>J.root)??[],...h._layerGraph?.configDependencies.map((J)=>te.dirname(J))??[]].filter((J)=>me.existsSync(J)).map((J)=>me.realpathSync(J)));for(let J of h._layerGraph?.layers??[])for(let W of Object.values(J.resources)){if(!me.existsSync(W))continue;let pe=me.realpathSync(W);if(![...U].some((G)=>pe===G||pe.startsWith(`${G}${te.sep}`)))U.add(pe)}for(let[J,W]of N)if(!U.has(J))W.close(),N.delete(J);for(let J of U)if(!N.has(J)&&me.existsSync(J))N.set(J,me.watch(J,{recursive:!0},(W,pe)=>{Ae(J,W,pe).catch((G)=>console.error("[stx] Layer rebuild failed:",G))}))},q=Promise.resolve(),Ae=(U,J,W)=>(q=q.catch(()=>{}).then(()=>ve(U,J,W)),q),ve=async(U,J,W)=>{if(!W||xt(W))return;if(bt(W)){if(h._layerGraph){let pe=await g(f);Object.assign(h,pe),_.splice(0,_.length,...X(w,{pagesDir:b,pagesDirs:pe._layerPageDirs?[k,...pe._layerPageDirs.slice(1)]:void 0})),Q()}if(O(W)){if(console.log(`${e.cyan}${W} changed${e.reset}`),s&&c)c.reload(W)}else if(j(W)){console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),Je.clear(),fe();try{let{invalidateFileCache:pe,templateCache:G}=await import("./chunk-qezg1070.js");pe(te.resolve(U,W)),G.delete(te.resolve(U,W))}catch{}if(D&&W){if(te.resolve(U,W)===D||te.basename(D)===W){let G=await fo(D,n.stxOptions||{});if(G)C=G}}if(await ze(),await sr(f),s&&c)c.reload(W)}else{console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),Je.clear(),fe();try{let{invalidateFileCache:pe,templateCache:G}=await import("./chunk-qezg1070.js");pe(te.resolve(U,W)),G.delete(te.resolve(U,W))}catch{}if(await ze(),s&&c)c.reload(W)}}else if(ht(W)){if(console.log(`${e.cyan}CSS ${W} changed${e.reset}`),s&&c)c.updateCss(W)}};Q(),process.on("SIGINT",()=>{for(let U of N.values())U.close();if(c)it();At.stop(),process.exit(0)})}return!0}import Ut from"fs";import at from"path";async function Vr(t){try{let o=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!o)return[];let d=o[1],s=[],c=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,u;while((u=c.exec(d))!==null){let f=u[1],g=u[2]||u[3]||u[4];if(!g)continue;let h={name:g},x=f.match(/@type\s+\{([^}]+)\}/i);if(x)h.type=x[1].trim();if(f.match(/@required/i))h.required=!0;let S=f.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)h.default=S[1].trim();let T=f.split(`
1446
+ `).map((w)=>w.trim().replace(/^\*\s*/,"")).filter((w)=>!w.startsWith("@")&&w.length>0);h.description=T.join(" ").trim(),s.push(h)}if(s.length===0){let f=d.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(f){let h=f[1].split(",").map((x)=>x.trim()).filter(Boolean);for(let x of h){let[v]=x.split(":").map((S)=>S.trim());if(v)s.push({name:v})}}}return s}catch(n){return console.error(`Error extracting props from ${t}:`,n),[]}}async function Kr(t){try{let n=await Bun.file(t).text(),o=n.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||n.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(o)return o[1].split(`
1447
+ `).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Xr(t,n=!1,o){let d=at.basename(t,".stx"),s=await Vr(t),c=await Kr(t),u="";if(n&&o)u=`<${o}></${o}>`;else{let f=s.map((g)=>{if(g.type==="boolean")return`:${g.name}="true"`;return`${g.name}="value"`}).join(`
1448
1448
  `);u=`<${d}
1449
1449
  ${f}
1450
- />`}return{name:d,path:t,description:c,props:s,example:u,isWebComponent:n,tag:o}}async function dn(t){try{if(!await r(t))return console.warn(`Components directory does not exist: ${t}`),[];let n=await Nt.promises.readdir(t,{withFileTypes:!0}),o=[];for(let d of n){let s=it.join(t,d.name);if(d.isDirectory()){let c=await dn(s);o.push(...c)}else if(d.isFile()&&d.name.endsWith(".stx"))o.push(s)}return o}catch(n){return console.error(`Error finding component files in ${t}:`,n),[]}}async function Xr(t,n){try{if(!await r(t))return[];let o=await dn(t),d=[],s=new Map;if(n?.components?.length)for(let c of n.components)s.set(c.file,c);for(let c of o){let u=s.get(c),f=!!u,g=u?.tag,h=await Kr(c,f,g);d.push(h)}return d}catch(o){return console.error("Error generating component docs:",o),[]}}async function Gr(t){try{if(!await r(t))return[];let n=await Nt.promises.readdir(t,{withFileTypes:!0}),o=[];for(let d of n){if(!d.isFile()||!d.name.endsWith(".stx"))continue;let s=it.join(t,d.name),c=await Bun.file(s).text(),u=it.basename(s,".stx"),f=c.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||c.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//),g=f?f[1].split(`
1451
- `).map((b)=>b.trim().replace(/^\*\s*/,"")).join(" ").trim():"",h=/@component\(\s*['"]([^'"]+)['"]/g,x=/<([A-Z][a-zA-Z0-9]*|[a-z]+-[a-z0-9-]+)(?:\s[^>]*)?\/?>|\{\{\s*slot\s*\}\}/g,v=new Set,S;while((S=h.exec(c))!==null)v.add(S[1]);while((S=x.exec(c))!==null)if(S[1]&&S[1]!=="slot")v.add(S[1]);let T=/@([a-z]+)(?:\s*\(|\s+|$)/g,w=new Set;while((S=T.exec(c))!==null)w.add(S[1]);o.push({name:u,path:s,description:g,components:[...v],directives:[...w]})}return o}catch(n){return console.error("Error generating template docs:",n),[]}}async function Jr(t=[]){try{let n=[{name:"if",description:"Conditionally render content based on a condition",hasEndTag:!0,example:`@if(user.isLoggedIn)
1450
+ />`}return{name:d,path:t,description:c,props:s,example:u,isWebComponent:n,tag:o}}async function pn(t){try{if(!await r(t))return console.warn(`Components directory does not exist: ${t}`),[];let n=await Ut.promises.readdir(t,{withFileTypes:!0}),o=[];for(let d of n){let s=at.join(t,d.name);if(d.isDirectory()){let c=await pn(s);o.push(...c)}else if(d.isFile()&&d.name.endsWith(".stx"))o.push(s)}return o}catch(n){return console.error(`Error finding component files in ${t}:`,n),[]}}async function Gr(t,n){try{if(!await r(t))return[];let o=await pn(t),d=[],s=new Map;if(n?.components?.length)for(let c of n.components)s.set(c.file,c);for(let c of o){let u=s.get(c),f=!!u,g=u?.tag,h=await Xr(c,f,g);d.push(h)}return d}catch(o){return console.error("Error generating component docs:",o),[]}}async function Jr(t){try{if(!await r(t))return[];let n=await Ut.promises.readdir(t,{withFileTypes:!0}),o=[];for(let d of n){if(!d.isFile()||!d.name.endsWith(".stx"))continue;let s=at.join(t,d.name),c=await Bun.file(s).text(),u=at.basename(s,".stx"),f=c.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||c.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//),g=f?f[1].split(`
1451
+ `).map((b)=>b.trim().replace(/^\*\s*/,"")).join(" ").trim():"",h=/@component\(\s*['"]([^'"]+)['"]/g,x=/<([A-Z][a-zA-Z0-9]*|[a-z]+-[a-z0-9-]+)(?:\s[^>]*)?\/?>|\{\{\s*slot\s*\}\}/g,v=new Set,S;while((S=h.exec(c))!==null)v.add(S[1]);while((S=x.exec(c))!==null)if(S[1]&&S[1]!=="slot")v.add(S[1]);let T=/@([a-z]+)(?:\s*\(|\s+|$)/g,w=new Set;while((S=T.exec(c))!==null)w.add(S[1]);o.push({name:u,path:s,description:g,components:[...v],directives:[...w]})}return o}catch(n){return console.error("Error generating template docs:",n),[]}}async function Yr(t=[]){try{let n=[{name:"if",description:"Conditionally render content based on a condition",hasEndTag:!0,example:`@if(user.isLoggedIn)
1452
1452
  <p>Welcome, {{ user.name }}!</p>
1453
1453
  @endif`},{name:"else",description:"Provides an alternative if a condition is not met",hasEndTag:!1,example:`@if(user.isLoggedIn)
1454
1454
  <p>Welcome back!</p>
@@ -1468,7 +1468,7 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(Pt.
1468
1468
  <p>Page {{ page }}</p>
1469
1469
  @endwhile`},{name:"component",description:"Include a component in the template",hasEndTag:!1,example:'@component("alert", { type: "warning", title: "Warning", message: "This is a warning" })'},{name:"include",description:"Include a partial template",hasEndTag:!1,example:'@include("partials/header")'},{name:"raw",description:"Display content without processing expressions",hasEndTag:!0,example:`@raw
1470
1470
  {{ This will be displayed as-is }}
1471
- @endraw`},{name:"translate",description:"Translate a string using the i18n system",hasEndTag:!1,example:'@translate("welcome.message", { name: user.name })'},{name:"t",description:"Short alias for translate directive",hasEndTag:!1,example:'@t("welcome.message", { name: user.name })'}];for(let o of t)n.push({name:o.name,description:o.description||"",hasEndTag:o.hasEndTag||!1,example:""});return n}catch(n){return console.error("Error generating directive docs:",n),[]}}function Yr(t=[],n=[],o=[],d){let s=`# stx Documentation
1471
+ @endraw`},{name:"translate",description:"Translate a string using the i18n system",hasEndTag:!1,example:'@translate("welcome.message", { name: user.name })'},{name:"t",description:"Short alias for translate directive",hasEndTag:!1,example:'@t("welcome.message", { name: user.name })'}];for(let o of t)n.push({name:o.name,description:o.description||"",hasEndTag:o.hasEndTag||!1,example:""});return n}catch(n){return console.error("Error generating directive docs:",n),[]}}function Qr(t=[],n=[],o=[],d){let s=`# stx Documentation
1472
1472
 
1473
1473
  `;if(d)s+=`${d}
1474
1474
 
@@ -1510,7 +1510,7 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(Pt.
1510
1510
 
1511
1511
  `,s+=`#### Example
1512
1512
 
1513
- `,s+="```html\n",s+=c.example,s+="\n```\n\n"}return s}function Qr(t=[],n=[],o=[],d){let s=`<!DOCTYPE html>
1513
+ `,s+="```html\n",s+=c.example,s+="\n```\n\n"}return s}function Zr(t=[],n=[],o=[],d){let s=`<!DOCTYPE html>
1514
1514
  <html lang="en">
1515
1515
  <head>
1516
1516
  <meta charset="UTF-8">
@@ -1581,15 +1581,15 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(Pt.
1581
1581
  <td>@${c.name}</td>
1582
1582
  <td>${c.description||"-"}</td>
1583
1583
  <td>${c.hasEndTag?"Yes":"No"}</td>
1584
- </tr>`;s+="</tbody></table>";for(let c of o)if(c.example)s+=`<h3>@${c.name}</h3>`,s+=`<p>${c.description||""}</p>`,s+="<h4>Example</h4>",s+=`<pre><code>${c.example.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}</code></pre>`}return s+="</body></html>",s}function Zr(t=[],n=[],o=[],d){return JSON.stringify({components:t,templates:n,directives:o,extraContent:d||""},null,2)}async function eo(t){try{let{componentsDir:n,templatesDir:o,webComponentsConfig:d,customDirectives:s,config:c}=t;if(!c.enabled)return!1;let u=c.outputDir||"docs";if(await Nt.promises.mkdir(u,{recursive:!0}),console.log("Generating documentation..."),n)console.log(`Components directory: ${n}`);if(o)console.log(`Templates directory: ${o}`);console.log(`Output directory: ${u}`);let f=[];if(c.components!==!1&&n)console.log("Generating component documentation..."),f=await Xr(n,d),console.log(`Found ${f.length} components`);let g=[];if(c.templates!==!1&&o)console.log("Generating template documentation..."),g=await Gr(o),console.log(`Found ${g.length} templates`);let h=[];if(c.directives!==!1)console.log("Generating directive documentation..."),h=await Jr(s),console.log(`Found ${h.length} directives`);let x=c.format||"markdown",v=c.extraContent,S="",T="";switch(x){case"markdown":S=Yr(f,g,h,v),T="md";break;case"html":S=Qr(f,g,h,v),T="html";break;case"json":S=Zr(f,g,h,v),T="json";break;default:throw Error(`Unsupported documentation format: ${x}`)}let w=it.join(u,`stx-docs.${T}`);return await Bun.write(w,S),console.log(`Documentation generated: ${w}`),!0}catch(n){return console.error("Error generating documentation:",n),!1}}async function Xi(t){let n={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},o=t.componentsDir||P.componentsDir,d=t.templatesDir||".";return eo({componentsDir:o,templatesDir:d,webComponentsConfig:P.webComponents,customDirectives:P.customDirectives,config:n})}var un={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0};function ro(t,n={}){let o={...un,...n};if(t.trim()==="")return`
1585
- `;let d=t;if(o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=io(d,o),d=uo(d,o),d=ao(d,o),o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,""),d=d.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(d=d.replace(/\r\n/g,`
1584
+ </tr>`;s+="</tbody></table>";for(let c of o)if(c.example)s+=`<h3>@${c.name}</h3>`,s+=`<p>${c.description||""}</p>`,s+="<h4>Example</h4>",s+=`<pre><code>${c.example.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}</code></pre>`}return s+="</body></html>",s}function eo(t=[],n=[],o=[],d){return JSON.stringify({components:t,templates:n,directives:o,extraContent:d||""},null,2)}async function to(t){try{let{componentsDir:n,templatesDir:o,webComponentsConfig:d,customDirectives:s,config:c}=t;if(!c.enabled)return!1;let u=c.outputDir||"docs";if(await Ut.promises.mkdir(u,{recursive:!0}),console.log("Generating documentation..."),n)console.log(`Components directory: ${n}`);if(o)console.log(`Templates directory: ${o}`);console.log(`Output directory: ${u}`);let f=[];if(c.components!==!1&&n)console.log("Generating component documentation..."),f=await Gr(n,d),console.log(`Found ${f.length} components`);let g=[];if(c.templates!==!1&&o)console.log("Generating template documentation..."),g=await Jr(o),console.log(`Found ${g.length} templates`);let h=[];if(c.directives!==!1)console.log("Generating directive documentation..."),h=await Yr(s),console.log(`Found ${h.length} directives`);let x=c.format||"markdown",v=c.extraContent,S="",T="";switch(x){case"markdown":S=Qr(f,g,h,v),T="md";break;case"html":S=Zr(f,g,h,v),T="html";break;case"json":S=eo(f,g,h,v),T="json";break;default:throw Error(`Unsupported documentation format: ${x}`)}let w=at.join(u,`stx-docs.${T}`);return await Bun.write(w,S),console.log(`Documentation generated: ${w}`),!0}catch(n){return console.error("Error generating documentation:",n),!1}}async function Gi(t){let n={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},o=t.componentsDir||P.componentsDir,d=t.templatesDir||".";return to({componentsDir:o,templatesDir:d,webComponentsConfig:P.webComponents,customDirectives:P.customDirectives,config:n})}var fn={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0};function so(t,n={}){let o={...fn,...n};if(t.trim()==="")return`
1585
+ `;let d=t;if(o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=ao(d,o),d=uo(d,o),d=co(d,o),o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,""),d=d.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(d=d.replace(/\r\n/g,`
1586
1586
  `).replace(/\r/g,`
1587
1587
  `),!d.endsWith(`
1588
1588
  `))d+=`
1589
- `;return d}function Gi(t,n={}){let o={...un,...n};if(t.trim()==="")return`
1589
+ `;return d}function Ji(t,n={}){let o={...fn,...n};if(t.trim()==="")return`
1590
1590
  `;let d=t;if(d=d.replace(/^( *)```(html|stx)\n([\s\S]*?)^( *)```/gm,(s,c,u,f,g)=>{let h=f.split(`
1591
1591
  `),x=h.filter((b)=>b.trim().length>0);if(x.length===0)return s;let v=Math.min(...x.map((b)=>{let k=b.match(/^( *)/);return k?k[1].length:0})),S=h.map((b)=>{if(b.trim().length===0)return"";return b.substring(v)}).join(`
1592
- `),w=ro(S,o).trimEnd().split(`
1592
+ `),w=so(S,o).trimEnd().split(`
1593
1593
  `).map((b)=>{if(b.trim().length===0)return"";return c+b}).join(`
1594
1594
  `);return`${c}\`\`\`${u}
1595
1595
  ${w}
@@ -1597,7 +1597,7 @@ ${c}\`\`\``}),o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=d.replac
1597
1597
  `).replace(/\r/g,`
1598
1598
  `),!d.endsWith(`
1599
1599
  `))d+=`
1600
- `;return d}function no(t){let n=t,o=[],d="__PROTECTED_BLOCK_";return n=n.replace(/(<(?:pre|code|textarea)[^>]*>)([\s\S]*?)(<\/(?:pre|code|textarea)>)/gi,(s)=>{let c=o.length;return o.push(s),`${d}${c}__`}),n=n.replace(/(@(?:if|foreach|for|while|unless|section|component|slot|push|prepend|error|auth|guest|can)(?:\((?:[^()'"]|'[^']*'|"[^"]*"|\((?:[^()'"]|'[^']*'|"[^"]*")*\))*\))?)/g,`
1600
+ `;return d}function ro(t){let n=t,o=[],d="__PROTECTED_BLOCK_";return n=n.replace(/(<(?:pre|code|textarea)[^>]*>)([\s\S]*?)(<\/(?:pre|code|textarea)>)/gi,(s)=>{let c=o.length;return o.push(s),`${d}${c}__`}),n=n.replace(/(@(?:if|foreach|for|while|unless|section|component|slot|push|prepend|error|auth|guest|can)(?:\((?:[^()'"]|'[^']*'|"[^"]*"|\((?:[^()'"]|'[^']*'|"[^"]*")*\))*\))?)/g,`
1601
1601
  $1
1602
1602
  `),n=n.replace(/(@end\w+)/g,`
1603
1603
  $1
@@ -1611,10 +1611,10 @@ ${u}`}),n=n.replace(/(<\/[^>]+>)(?=<|$)/g,(s,c,u,f)=>{let g=f.substring(Math.max
1611
1611
  `}),n=n.replace(new RegExp(`${d}(\\d+)__`,"g"),(s,c)=>o[Number.parseInt(c,10)]),n=n.replace(/\n{2,}/g,`
1612
1612
  `),n=n.split(`
1613
1613
  `).map((s)=>s.trim()).join(`
1614
- `),n=n.replace(/^\n+/,"").replace(/\n+$/,""),n}function io(t,n){let d=no(t).split(`
1615
- `),s=[],c=0,u=!1,f=n.useTabs?"\t":" ".repeat(n.indentSize);for(let g=0;g<d.length;g++){let h=d[g],x=h.trim();if(x===""){s.push("");continue}let v=x.match(/<script\b/i),S=x.match(/<\/script>/i);if(u&&!S){s.push(h);continue}let T=x===">";if(pn(x)&&!x.startsWith("<")&&!x.startsWith("@")){s.push(f.repeat(c)+x);continue}let w=x.startsWith("@end"),b=x.startsWith("@else")||x.startsWith("@elseif"),k=x.startsWith("@")&&lo(x),_=x.startsWith("<!DOCTYPE")||x.startsWith("<!doctype"),E=x.startsWith("<!--"),R=x.startsWith("</"),A=x.startsWith("<")&&!R&&!E&&!_,C=x.includes("/>")||co(x),D=pn(x);if(R||w)c=Math.max(0,c-1);let I=b?Math.max(0,c-1):c;if(T)s.push(h);else s.push(f.repeat(I)+x);if(A&&!C&&!D&&!T||k)c++;if(v)u=!0;if(S)u=!1}return s.join(`
1616
- `)}function ao(t,n){if(t=t.replace(/@(if|elseif|foreach|for|while)\s*\(\s*([^)]+)\s*\)/g,(o,d,s)=>{let c=s.trim().replace(/\s+/g," ");return`@${d}(${c})`}),t=t.replace(/@(csrf|method)\s*\(\s*([^)]*)\s*\)/g,(o,d,s)=>{if(s.trim()==="")return`@${d}`;return`@${d}(${s.trim()})`}),n.normalizeWhitespace)t=t.replace(/\{\{\s*([^}]+)\s*\}\}/g,(o,d)=>`{{ ${d.trim()} }}`),t=t.replace(/\{!!\s*([^!]+)\s*!!\}/g,(o,d)=>`{!! ${d.trim()} !!}`);return t}function co(t){let n=["br","hr","img","input","meta","link","area","base","col","embed","source","track","wbr"];if(t.includes("/>"))return!0;let o=t.match(/<(\w+)/);if(o){let d=o[1];return n.includes(d.toLowerCase())}return!1}function pn(t){return/<(\w+)(?:\s[^>]*)?>[\s\S]*?<\/\1>/.test(t)}function lo(t){let n=["if","unless","foreach","for","while","section","push","component","slot","markdown","wrap","error"];for(let o of n)if(t.startsWith(`@${o}`))return!t.includes(`@end${o}`);return!1}function uo(t,n){if(!n.sortAttributes)return t;return t.replace(/<(\w+)([^>]*)>/g,(o,d,s)=>{if(!s.trim())return o;if(s.includes("<")||s.includes(`
1617
- `)||s.includes("@"))return o;let c=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,u=[],f;while((f=c.exec(s))!==null)u.push({name:f[1],value:f[2]});u.sort((h,x)=>{if(h.name==="id")return-1;if(x.name==="id")return 1;if(h.name==="class")return-1;if(x.name==="class")return 1;return h.name.localeCompare(x.name)});let g=u.map((h)=>h.value?`${h.name}=${h.value}`:h.name).join(" ");return`<${d}${g?` ${g}`:""}>`})}import mn from"fs";import Ut from"path";async function Ji(t="index.stx",n={}){try{let o=n.force||!1,d=Ut.resolve(process.cwd(),t);if(await Bun.file(d).exists()){if(!o)throw Error(`File ${t} already exists. Use --force to overwrite.`);console.warn(`File ${t} already exists. Overwriting...`)}let s=Ut.dirname(d);if(!mn.existsSync(s))mn.mkdirSync(s,{recursive:!0});let c;if(n.template){let u=Ut.resolve(process.cwd(),n.template);if(!await Bun.file(u).exists())throw Error(`Template file ${n.template} does not exist.`);if(!u.endsWith(".stx"))console.warn(`Warning: Template file ${n.template} does not have a .stx extension. Using it anyway.`);c=await Bun.file(u).text(),console.warn(`Using template from ${n.template}`)}else if(n.preset)c=gn(n.preset),console.warn(`Using '${n.preset}' preset template`);else c=gn("basic");return await Bun.write(d,c),console.warn(`Created new stx file: ${t}`),!0}catch(o){return console.error(`Error creating file: ${o instanceof Error?o.message:String(o)}`),!1}}function gn(t){switch(t){case"basic":return hn();case"component":return fo();case"layout":return mo();case"blog":return go();case"api":return ho();case"app":return yo();default:return hn()}}function hn(){return`<script>
1614
+ `),n=n.replace(/^\n+/,"").replace(/\n+$/,""),n}function ao(t,n){let d=ro(t).split(`
1615
+ `),s=[],c=0,u=!1,f=n.useTabs?"\t":" ".repeat(n.indentSize);for(let g=0;g<d.length;g++){let h=d[g],x=h.trim();if(x===""){s.push("");continue}let v=x.match(/<script\b/i),S=x.match(/<\/script>/i);if(u&&!S){s.push(h);continue}let T=x===">";if(un(x)&&!x.startsWith("<")&&!x.startsWith("@")){s.push(f.repeat(c)+x);continue}let w=x.startsWith("@end"),b=x.startsWith("@else")||x.startsWith("@elseif"),k=x.startsWith("@")&&po(x),_=x.startsWith("<!DOCTYPE")||x.startsWith("<!doctype"),E=x.startsWith("<!--"),R=x.startsWith("</"),A=x.startsWith("<")&&!R&&!E&&!_,C=x.includes("/>")||lo(x),D=un(x);if(R||w)c=Math.max(0,c-1);let I=b?Math.max(0,c-1):c;if(T)s.push(h);else s.push(f.repeat(I)+x);if(A&&!C&&!D&&!T||k)c++;if(v)u=!0;if(S)u=!1}return s.join(`
1616
+ `)}function co(t,n){if(t=t.replace(/@(if|elseif|foreach|for|while)\s*\(\s*([^)]+)\s*\)/g,(o,d,s)=>{let c=s.trim().replace(/\s+/g," ");return`@${d}(${c})`}),t=t.replace(/@(csrf|method)\s*\(\s*([^)]*)\s*\)/g,(o,d,s)=>{if(s.trim()==="")return`@${d}`;return`@${d}(${s.trim()})`}),n.normalizeWhitespace)t=t.replace(/\{\{\s*([^}]+)\s*\}\}/g,(o,d)=>`{{ ${d.trim()} }}`),t=t.replace(/\{!!\s*([^!]+)\s*!!\}/g,(o,d)=>`{!! ${d.trim()} !!}`);return t}function lo(t){let n=["br","hr","img","input","meta","link","area","base","col","embed","source","track","wbr"];if(t.includes("/>"))return!0;let o=t.match(/<(\w+)/);if(o){let d=o[1];return n.includes(d.toLowerCase())}return!1}function un(t){return/<(\w+)(?:\s[^>]*)?>[\s\S]*?<\/\1>/.test(t)}function po(t){let n=["if","unless","foreach","for","while","section","push","component","slot","markdown","wrap","error"];for(let o of n)if(t.startsWith(`@${o}`))return!t.includes(`@end${o}`);return!1}function uo(t,n){if(!n.sortAttributes)return t;return t.replace(/<(\w+)([^>]*)>/g,(o,d,s)=>{if(!s.trim())return o;if(s.includes("<")||s.includes(`
1617
+ `)||s.includes("@"))return o;let c=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,u=[],f;while((f=c.exec(s))!==null)u.push({name:f[1],value:f[2]});u.sort((h,x)=>{if(h.name==="id")return-1;if(x.name==="id")return 1;if(h.name==="class")return-1;if(x.name==="class")return 1;return h.name.localeCompare(x.name)});let g=u.map((h)=>h.value?`${h.name}=${h.value}`:h.name).join(" ");return`<${d}${g?` ${g}`:""}>`})}import mn from"fs";import Wt from"path";async function Yi(t="index.stx",n={}){try{let o=n.force||!1,d=Wt.resolve(process.cwd(),t);if(await Bun.file(d).exists()){if(!o)throw Error(`File ${t} already exists. Use --force to overwrite.`);console.warn(`File ${t} already exists. Overwriting...`)}let s=Wt.dirname(d);if(!mn.existsSync(s))mn.mkdirSync(s,{recursive:!0});let c;if(n.template){let u=Wt.resolve(process.cwd(),n.template);if(!await Bun.file(u).exists())throw Error(`Template file ${n.template} does not exist.`);if(!u.endsWith(".stx"))console.warn(`Warning: Template file ${n.template} does not have a .stx extension. Using it anyway.`);c=await Bun.file(u).text(),console.warn(`Using template from ${n.template}`)}else if(n.preset)c=hn(n.preset),console.warn(`Using '${n.preset}' preset template`);else c=hn("basic");return await Bun.write(d,c),console.warn(`Created new stx file: ${t}`),!0}catch(o){return console.error(`Error creating file: ${o instanceof Error?o.message:String(o)}`),!1}}function hn(t){switch(t){case"basic":return yn();case"component":return mo();case"layout":return go();case"blog":return ho();case"api":return yo();case"app":return bo();default:return yn()}}function yn(){return`<script>
1618
1618
  const title = "My stx Page"
1619
1619
  const description = "A page built with stx"
1620
1620
  const features = [
@@ -1639,7 +1639,7 @@ const features = [
1639
1639
  </div>
1640
1640
  @endforeach
1641
1641
  </main>
1642
- @endsection`}function fo(){return`{{-- Component: Card --}}
1642
+ @endsection`}function mo(){return`{{-- Component: Card --}}
1643
1643
  {{-- Props: title, variant, collapsible --}}
1644
1644
  {{-- Usage: @component('card', { title: "Hello", variant: "primary", collapsible: true }) Content @endcomponent --}}
1645
1645
  <script>
@@ -1684,7 +1684,7 @@ const features = [
1684
1684
  .card.collapsed .card__toggle { transform: rotate(-90deg); }
1685
1685
  .card__body { padding: 1rem; }
1686
1686
  .card.collapsed .card__body { display: none; }
1687
- </style>`}function mo(){return`<!DOCTYPE html>
1687
+ </style>`}function go(){return`<!DOCTYPE html>
1688
1688
  <html lang="en">
1689
1689
  <head>
1690
1690
  <meta charset="UTF-8">
@@ -1735,7 +1735,7 @@ const features = [
1735
1735
 
1736
1736
  @yield('scripts')
1737
1737
  </body>
1738
- </html>`}function go(){return`<script>
1738
+ </html>`}function ho(){return`<script>
1739
1739
  // Article metadata
1740
1740
  const title = "My Blog Post"
1741
1741
  const author = "Your Name"
@@ -1780,7 +1780,7 @@ const features = [
1780
1780
  <p>Wrap up your thoughts here.</p>
1781
1781
  </div>
1782
1782
  </article>
1783
- @endsection`}function ho(){return`<script>
1783
+ @endsection`}function yo(){return`<script>
1784
1784
  // API endpoint configuration
1785
1785
  const endpoint = "/api/data"
1786
1786
  const method = "GET"
@@ -1815,7 +1815,7 @@ const features = [
1815
1815
  }
1816
1816
  @else
1817
1817
  {{ JSON.stringify(data, null, 2) }}
1818
- @endif`}function yo(){return`<!DOCTYPE html>
1818
+ @endif`}function bo(){return`<!DOCTYPE html>
1819
1819
  <html lang="en">
1820
1820
  <head>
1821
1821
  <meta charset="UTF-8">
@@ -2040,5 +2040,5 @@ const features = [
2040
2040
  })();
2041
2041
  </script>
2042
2042
  </body>
2043
- </html>`}var Yi="f9c3713";function Sl(t){return t}function kl(t){return t}function Wi(t,n){let o=[],d=`${n}=`;for(let s=0;s<t.length;s++){let c=t[s];if(c.startsWith(d)){let u=c.slice(d.length);if(u)o.push(u);continue}if(c===n){let u=t[s+1];if(u!==void 0&&!u.startsWith("-"))o.push(u),s++}}return o}import _e from"fs";import ye from"path";function Cn(t){try{return _e.statSync(t).mtimeMs}catch{return null}}function $t(t,n){let o=Math.max(0,Math.round((n-t)/1000));if(o<60)return`${o}s ago`;if(o<3600)return`${Math.round(o/60)}m ago`;return`${Math.round(o/3600)}h ago`}function Ti(t,n){try{return globalThis.Bun?.resolveSync(t,n)??null}catch{return null}}function En(t,n="stx"){let o=ye.resolve(t);for(let d=0;d<10;d++){let s=ye.join(o,"pantry","@stacksjs",n);if(_e.existsSync(s))return s;let c=ye.dirname(o);if(c===o)break;o=c}return null}var Pn=["@stacksjs/stx","bun-plugin-stx"];function $i(t){try{let n=_e.readFileSync(ye.join(t,"package.json"),"utf8"),o=JSON.parse(n)?.version;return typeof o==="string"?o:null}catch{return null}}function Ci(t,n=6){let o=ye.resolve(t),d=[],s=new Set;function c(f,g){if(g>n)return;let h;try{h=_e.realpathSync(f)}catch{return}if(s.has(h))return;s.add(h);for(let v of Pn){let S=ye.join(f,v),T=$i(S);if(T!==null)d.push({name:v,version:T,dir:ye.relative(o,S)||S,nested:g>0})}let x;try{x=_e.readdirSync(f,{withFileTypes:!0})}catch{return}for(let v of x){if(!v.isDirectory()&&!v.isSymbolicLink())continue;if(v.name===".bin"||v.name===".cache")continue;let S=ye.join(f,v.name);if(v.name.startsWith("@")){let w;try{w=_e.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let b of w){let k=ye.join(S,b.name,"node_modules");if(_e.existsSync(k))c(k,g+1)}continue}let T=ye.join(S,"node_modules");if(_e.existsSync(T))c(T,g+1)}}let u=ye.join(o,"node_modules");if(_e.existsSync(u))c(u,0);return d}function Ri(t){let n=[];for(let o of Pn){let d=t.filter((u)=>u.name===o);if(d.length<=1)continue;let s=[...new Set(d.map((u)=>u.version))],c=d.map((u)=>`${u.version} at ${u.dir}`).join("; ");if(s.length===1){n.push({name:`${o} copies`,status:"info",detail:`${d.length} copies, all ${s[0]} \u2014 duplicated but in agreement`});continue}n.push({name:`${o} copies disagree`,status:"error",detail:`${s.length} versions installed, so which one runs depends on who imports it: ${c}`,fix:`remove the nested copies, or add an overrides entry pinning ${o}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${o}/package.json' -exec grep -H '"version"' {} +`})}return n}async function so(t={}){let n=t.cwd?ye.resolve(t.cwd):process.cwd(),o=t.resolve??Ti,d=Date.now(),s=[],c=o("@stacksjs/stx",n);s.push(c?{name:"@stacksjs/stx resolves to",status:"ok",detail:c}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let u=o("bun-plugin-stx",n);if(u)s.push({name:"bun-plugin-stx resolves to",status:"ok",detail:u});for(let g of Ri(Ci(n)))s.push(g);let f=En(n,"stx");if(!f)s.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let g=ye.join(f,"src/signals.ts"),h=[ye.join(f,"dist/index.js"),ye.join(f,"dist/signals.js")].find((w)=>_e.existsSync(w))||null,x=Cn(g),v=h?Cn(h):null;if(x==null)s.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${f} but no src/signals.ts to compare`});else if(v==null)s.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 ${f} && bun build.ts`});else if(v<x){let w=Math.round((x-v)/1000);s.push({name:"pantry dist freshness",status:"error",detail:`dist (${$t(v,d)}) is OLDER than src/signals.ts (${$t(x,d)}) by ${w}s \u2014 your edit isn't built`,fix:`cd ${f} && bun build.ts`})}else s.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${$t(x,d)}, dist ${$t(v,d)})`});let S=ye.join(n,"node_modules/@stacksjs/stx"),T=null;try{T=_e.lstatSync(S)}catch{T=null}if(!T)s.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(T.isSymbolicLink()){let w=null;try{w=_e.realpathSync(S)}catch{}let b=(()=>{try{return _e.realpathSync(f)}catch{return f}})();s.push(w===b?{name:"node_modules \u2192 pantry",status:"ok",detail:"symlinked to pantry"}:{name:"node_modules \u2192 pantry",status:"warn",detail:`symlinked to ${w||"(dangling)"}, not pantry`})}else s.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(s.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 h=t.generateRuntime().length;s.push(h>1000?{name:"signals runtime",status:"ok",detail:`generated ${h.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${h} chars \u2014 suspiciously short`})}catch(g){s.push({name:"signals runtime",status:"error",detail:`failed to generate: ${g.message}`})}return{checks:s,ok:!s.some((g)=>g.status==="error")}}function oo(t){let n={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},o=["stx runtime resolution:"];for(let d of t.checks)if(o.push(` ${n[d.status]} ${d.name}: ${d.detail}`),d.fix)o.push(` \u2192 ${d.fix}`);return o.push(""),o.push(t.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),o.join(`
2044
- `)}export{Wi,qi,Ki,Xi,ro,Gi,Ji,Yi,Sl,kl,so,oo,Br,Fr,zr};
2043
+ </html>`}var Zi="f9c3713";function kl(t){return t}function _l(t){return t}function qi(t,n){let o=[],d=`${n}=`;for(let s=0;s<t.length;s++){let c=t[s];if(c.startsWith(d)){let u=c.slice(d.length);if(u)o.push(u);continue}if(c===n){let u=t[s+1];if(u!==void 0&&!u.startsWith("-"))o.push(u),s++}}return o}import _e from"fs";import ye from"path";function Rn(t){try{return _e.statSync(t).mtimeMs}catch{return null}}function Rt(t,n){let o=Math.max(0,Math.round((n-t)/1000));if(o<60)return`${o}s ago`;if(o<3600)return`${Math.round(o/60)}m ago`;return`${Math.round(o/3600)}h ago`}function $i(t,n){try{return globalThis.Bun?.resolveSync(t,n)??null}catch{return null}}function En(t,n="stx"){let o=ye.resolve(t);for(let d=0;d<10;d++){let s=ye.join(o,"pantry","@stacksjs",n);if(_e.existsSync(s))return s;let c=ye.dirname(o);if(c===o)break;o=c}return null}var Pn=["@stacksjs/stx","bun-plugin-stx"];function Ci(t){try{let n=_e.readFileSync(ye.join(t,"package.json"),"utf8"),o=JSON.parse(n)?.version;return typeof o==="string"?o:null}catch{return null}}function Ri(t,n=6){let o=ye.resolve(t),d=[],s=new Set;function c(f,g){if(g>n)return;let h;try{h=_e.realpathSync(f)}catch{return}if(s.has(h))return;s.add(h);for(let v of Pn){let S=ye.join(f,v),T=Ci(S);if(T!==null)d.push({name:v,version:T,dir:ye.relative(o,S)||S,nested:g>0})}let x;try{x=_e.readdirSync(f,{withFileTypes:!0})}catch{return}for(let v of x){if(!v.isDirectory()&&!v.isSymbolicLink())continue;if(v.name===".bin"||v.name===".cache")continue;let S=ye.join(f,v.name);if(v.name.startsWith("@")){let w;try{w=_e.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let b of w){let k=ye.join(S,b.name,"node_modules");if(_e.existsSync(k))c(k,g+1)}continue}let T=ye.join(S,"node_modules");if(_e.existsSync(T))c(T,g+1)}}let u=ye.join(o,"node_modules");if(_e.existsSync(u))c(u,0);return d}function Ei(t){let n=[];for(let o of Pn){let d=t.filter((u)=>u.name===o);if(d.length<=1)continue;let s=[...new Set(d.map((u)=>u.version))],c=d.map((u)=>`${u.version} at ${u.dir}`).join("; ");if(s.length===1){n.push({name:`${o} copies`,status:"info",detail:`${d.length} copies, all ${s[0]} \u2014 duplicated but in agreement`});continue}n.push({name:`${o} copies disagree`,status:"error",detail:`${s.length} versions installed, so which one runs depends on who imports it: ${c}`,fix:`remove the nested copies, or add an overrides entry pinning ${o}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${o}/package.json' -exec grep -H '"version"' {} +`})}return n}async function oo(t={}){let n=t.cwd?ye.resolve(t.cwd):process.cwd(),o=t.resolve??$i,d=Date.now(),s=[],c=o("@stacksjs/stx",n);s.push(c?{name:"@stacksjs/stx resolves to",status:"ok",detail:c}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let u=o("bun-plugin-stx",n);if(u)s.push({name:"bun-plugin-stx resolves to",status:"ok",detail:u});for(let g of Ei(Ri(n)))s.push(g);let f=En(n,"stx");if(!f)s.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let g=ye.join(f,"src/signals.ts"),h=[ye.join(f,"dist/index.js"),ye.join(f,"dist/signals.js")].find((w)=>_e.existsSync(w))||null,x=Rn(g),v=h?Rn(h):null;if(x==null)s.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${f} but no src/signals.ts to compare`});else if(v==null)s.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 ${f} && bun build.ts`});else if(v<x){let w=Math.round((x-v)/1000);s.push({name:"pantry dist freshness",status:"error",detail:`dist (${Rt(v,d)}) is OLDER than src/signals.ts (${Rt(x,d)}) by ${w}s \u2014 your edit isn't built`,fix:`cd ${f} && bun build.ts`})}else s.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Rt(x,d)}, dist ${Rt(v,d)})`});let S=ye.join(n,"node_modules/@stacksjs/stx"),T=null;try{T=_e.lstatSync(S)}catch{T=null}if(!T)s.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(T.isSymbolicLink()){let w=null;try{w=_e.realpathSync(S)}catch{}let b=(()=>{try{return _e.realpathSync(f)}catch{return f}})();s.push(w===b?{name:"node_modules \u2192 pantry",status:"ok",detail:"symlinked to pantry"}:{name:"node_modules \u2192 pantry",status:"warn",detail:`symlinked to ${w||"(dangling)"}, not pantry`})}else s.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(s.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 h=t.generateRuntime().length;s.push(h>1000?{name:"signals runtime",status:"ok",detail:`generated ${h.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${h} chars \u2014 suspiciously short`})}catch(g){s.push({name:"signals runtime",status:"error",detail:`failed to generate: ${g.message}`})}return{checks:s,ok:!s.some((g)=>g.status==="error")}}function io(t){let n={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},o=["stx runtime resolution:"];for(let d of t.checks)if(o.push(` ${n[d.status]} ${d.name}: ${d.detail}`),d.fix)o.push(` \u2192 ${d.fix}`);return o.push(""),o.push(t.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),o.join(`
2044
+ `)}export{qi,Ki,Xi,Gi,so,Ji,Yi,Zi,kl,_l,oo,io,Fr,zr,Hr};