@stacksjs/stx 0.2.606 → 0.2.611

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 (231) hide show
  1. package/dist/chunk-02dcqhzy.js +2 -0
  2. package/dist/{chunk-vw62fjpv.js → chunk-0ff64x1p.js} +3 -3
  3. package/dist/chunk-0fgp13q4.js +2 -0
  4. package/dist/chunk-0gpjks6k.js +2 -0
  5. package/dist/chunk-1239cnda.js +2 -0
  6. package/dist/chunk-1qx531pp.js +2 -0
  7. package/dist/chunk-24tx4ysv.js +2 -0
  8. package/dist/{chunk-zs3ezqy3.js → chunk-2h8xmmtk.js} +1 -1
  9. package/dist/{chunk-6xsm53pz.js → chunk-2pgvbe5x.js} +4 -4
  10. package/dist/chunk-2pkx524z.js +2 -0
  11. package/dist/{chunk-0v89nfz1.js → chunk-2y0qy214.js} +2 -2
  12. package/dist/chunk-2y80c34h.js +2 -0
  13. package/dist/{chunk-tbsjg23k.js → chunk-2z56183d.js} +4 -4
  14. package/dist/{chunk-vntpfbwy.js → chunk-34x22hbs.js} +1 -1
  15. package/dist/{chunk-qh07a85k.js → chunk-39fqkzyb.js} +3 -3
  16. package/dist/{chunk-81qmj3sd.js → chunk-3d658f6n.js} +7 -7
  17. package/dist/{chunk-tyb481p0.js → chunk-3v862v2c.js} +1 -1
  18. package/dist/{chunk-5s47qfp6.js → chunk-3wmt7ykt.js} +2 -2
  19. package/dist/chunk-4j3fmxeg.js +2 -0
  20. package/dist/{chunk-y54fz9rk.js → chunk-4rtxkqwh.js} +2 -2
  21. package/dist/chunk-5f330rrj.js +2 -0
  22. package/dist/{chunk-s4pjf2pc.js → chunk-5rtatjwq.js} +2 -2
  23. package/dist/{chunk-wzjf33es.js → chunk-5vnx8dmz.js} +2 -2
  24. package/dist/chunk-5ys7azpj.js +2 -0
  25. package/dist/chunk-64vnwrkw.js +2 -0
  26. package/dist/chunk-65jsp5fd.js +3 -0
  27. package/dist/{chunk-bsy8v1xj.js → chunk-66e4ga0z.js} +3 -3
  28. package/dist/{chunk-4tj0ap61.js → chunk-6yrjyrc2.js} +5 -5
  29. package/dist/{chunk-td5100fz.js → chunk-70n1t4ht.js} +7 -7
  30. package/dist/chunk-7446n6a3.js +2 -0
  31. package/dist/{chunk-y8h823cb.js → chunk-74j18qk0.js} +28 -28
  32. package/dist/chunk-76ebcf61.js +2 -0
  33. package/dist/chunk-7aa4qncj.js +2 -0
  34. package/dist/chunk-7awf2gqs.js +2 -0
  35. package/dist/{chunk-vm2d4hap.js → chunk-7g47wdd9.js} +3 -3
  36. package/dist/{chunk-m9h7pmkh.js → chunk-8211vr9v.js} +5 -5
  37. package/dist/chunk-84f8tft8.js +2 -0
  38. package/dist/{chunk-yzj55rfs.js → chunk-8f616tym.js} +3 -3
  39. package/dist/chunk-8t8wf1w2.js +2 -0
  40. package/dist/chunk-961nvcxw.js +43 -0
  41. package/dist/{chunk-xjxc4q3w.js → chunk-999d4sns.js} +21 -21
  42. package/dist/{chunk-r4h8fg1x.js → chunk-9dx519z6.js} +1 -1
  43. package/dist/{chunk-dnqq1ze0.js → chunk-9kzdk4na.js} +3 -3
  44. package/dist/chunk-9mmy9m0y.js +2 -0
  45. package/dist/{chunk-bhf9yt2w.js → chunk-9n7ehv7w.js} +2 -2
  46. package/dist/{chunk-dmdhbwmn.js → chunk-9nh7vxk1.js} +3 -3
  47. package/dist/chunk-9vxdjpn5.js +2 -0
  48. package/dist/chunk-aw79nm5c.js +127 -0
  49. package/dist/chunk-brbybne9.js +2 -0
  50. package/dist/chunk-cg8hg6cs.js +3 -0
  51. package/dist/{chunk-azpkje69.js → chunk-cjrfazzb.js} +34 -10
  52. package/dist/chunk-cjvq46n8.js +3 -0
  53. package/dist/chunk-cwvazqab.js +2 -0
  54. package/dist/{chunk-67tpacz0.js → chunk-cwxkgbck.js} +1 -1
  55. package/dist/chunk-d17mhbz9.js +2850 -0
  56. package/dist/{chunk-vp3fzjsc.js → chunk-det49x62.js} +2 -2
  57. package/dist/{chunk-tydv84gj.js → chunk-dtt7k0bz.js} +2 -2
  58. package/dist/{chunk-5taenpfg.js → chunk-e98jqwnf.js} +1 -1
  59. package/dist/{chunk-y9a9cvke.js → chunk-eg5yfnrn.js} +33 -33
  60. package/dist/chunk-ekfmad19.js +2 -0
  61. package/dist/{chunk-ghdyqt98.js → chunk-ewsd3apq.js} +2 -2
  62. package/dist/chunk-exwjabr5.js +2 -0
  63. package/dist/chunk-f19bzr36.js +2 -0
  64. package/dist/{chunk-5e182xqt.js → chunk-f8tts10s.js} +1 -1
  65. package/dist/chunk-fa0aa98d.js +2 -0
  66. package/dist/chunk-fgrjv29d.js +18 -0
  67. package/dist/chunk-fjx1sbg2.js +2 -0
  68. package/dist/{chunk-sswjv8p9.js → chunk-g22q68ds.js} +2 -2
  69. package/dist/chunk-g24kapd5.js +2 -0
  70. package/dist/{chunk-9734nkc8.js → chunk-gbk2dbt1.js} +4 -4
  71. package/dist/{chunk-rmv35cx0.js → chunk-gk4c8d1c.js} +2 -2
  72. package/dist/{chunk-mtxs4fya.js → chunk-gn75qghq.js} +1 -1
  73. package/dist/chunk-gvv4d0tp.js +2 -0
  74. package/dist/chunk-h3fr7c5y.js +2 -0
  75. package/dist/{chunk-mn7a5b55.js → chunk-h3tzc41t.js} +2 -2
  76. package/dist/{chunk-vehtypx0.js → chunk-h7y89m22.js} +2 -2
  77. package/dist/{chunk-1jxdkp8x.js → chunk-hj49vk9e.js} +6 -6
  78. package/dist/chunk-hjp38m0w.js +3 -0
  79. package/dist/chunk-hwt7pyqt.js +2 -0
  80. package/dist/{chunk-x8q5przn.js → chunk-hxzy2t7r.js} +11 -11
  81. package/dist/{chunk-tcd2zez3.js → chunk-j18z5nxq.js} +2 -2
  82. package/dist/chunk-jp1xjh1f.js +2 -0
  83. package/dist/chunk-jrccxnbt.js +2 -0
  84. package/dist/chunk-jv3rdes9.js +2 -0
  85. package/dist/chunk-k36ve5ct.js +2 -0
  86. package/dist/chunk-k5vytrbx.js +2 -0
  87. package/dist/chunk-k7vg01vv.js +2 -0
  88. package/dist/chunk-kayh4pcw.js +2 -0
  89. package/dist/chunk-myg6gz76.js +2 -0
  90. package/dist/{chunk-jpxekhdh.js → chunk-n05hxy7w.js} +3 -3
  91. package/dist/{chunk-t9t66sz4.js → chunk-n1qr6n92.js} +6 -6
  92. package/dist/{chunk-4dfqgmgs.js → chunk-n4f3fzp5.js} +85 -85
  93. package/dist/chunk-n6tspwf9.js +2 -0
  94. package/dist/{chunk-w67rrd1f.js → chunk-nd8yx3qq.js} +10 -10
  95. package/dist/chunk-nfdma5hp.js +2 -0
  96. package/dist/chunk-ng819bkf.js +2 -0
  97. package/dist/{chunk-kxjd6e2h.js → chunk-pc15w7bb.js} +2 -2
  98. package/dist/{chunk-z8fhtym2.js → chunk-pkgmyg4r.js} +2 -2
  99. package/dist/{chunk-53y4z4p2.js → chunk-pm1gnjs5.js} +3 -3
  100. package/dist/{chunk-6by8dtan.js → chunk-pmpqzqq8.js} +2 -2
  101. package/dist/chunk-pnyxqze0.js +2 -0
  102. package/dist/{chunk-cfpenvc7.js → chunk-pyqrj2wk.js} +3 -3
  103. package/dist/chunk-qa5c5x2n.js +2 -0
  104. package/dist/chunk-qqenm7pg.js +40 -0
  105. package/dist/{chunk-rg7wvcqw.js → chunk-r4xnqag4.js} +2 -2
  106. package/dist/chunk-r8a96bbd.js +2 -0
  107. package/dist/{chunk-3cnwstra.js → chunk-s5s1w8na.js} +2 -2
  108. package/dist/chunk-sakagfdq.js +2 -0
  109. package/dist/chunk-sj0bkdy8.js +2 -0
  110. package/dist/chunk-spkwmfbm.js +2 -0
  111. package/dist/chunk-swv69q75.js +4 -0
  112. package/dist/{chunk-ktvr45qg.js → chunk-t61vdbje.js} +6 -6
  113. package/dist/{chunk-htf3z9et.js → chunk-tk50q4zs.js} +12 -12
  114. package/dist/chunk-v6xk1q66.js +2 -0
  115. package/dist/{chunk-zs3tmd12.js → chunk-vep8d57h.js} +1 -1
  116. package/dist/chunk-vfk3vn6j.js +2 -0
  117. package/dist/{chunk-vvfpb3k3.js → chunk-vyjwag3f.js} +9 -9
  118. package/dist/{chunk-w8g2ppnr.js → chunk-w0h27sf8.js} +2 -2
  119. package/dist/chunk-w1szscbz.js +2 -0
  120. package/dist/{chunk-20k77e2a.js → chunk-wa26bn4s.js} +4 -4
  121. package/dist/chunk-wb9rbwb1.js +2 -0
  122. package/dist/{chunk-td30jg06.js → chunk-wdy6y0fq.js} +2 -2
  123. package/dist/chunk-wkx2m2br.js +2 -0
  124. package/dist/{chunk-mvwcf4xy.js → chunk-wyndxr8w.js} +4 -4
  125. package/dist/chunk-x73w6v8m.js +2 -0
  126. package/dist/{chunk-fwp1en28.js → chunk-x8y7yqwh.js} +7 -7
  127. package/dist/{chunk-7095f0hb.js → chunk-xap2cbkd.js} +9 -9
  128. package/dist/{chunk-s45envb5.js → chunk-xh98677z.js} +5 -5
  129. package/dist/chunk-yagzr2ry.js +2 -0
  130. package/dist/chunk-yda8t21j.js +2 -0
  131. package/dist/{chunk-efy3038a.js → chunk-ydz9j0d3.js} +2 -2
  132. package/dist/chunk-yydx0sfy.js +2 -0
  133. package/dist/{chunk-r69jfs59.js → chunk-z79gnz6z.js} +1 -1
  134. package/dist/{chunk-vhajhs44.js → chunk-z7ezxqmg.js} +5 -5
  135. package/dist/{chunk-k3f4044e.js → chunk-zatgmkx7.js} +2 -2
  136. package/dist/chunk-zg0z8qt6.js +2 -0
  137. package/dist/{chunk-y6gj9jq8.js → chunk-znwnacwz.js} +5 -5
  138. package/dist/cli.js +46 -46
  139. package/dist/craft-entry.js +2 -2
  140. package/dist/craft.js +2 -2
  141. package/dist/expressions.d.ts +0 -23
  142. package/dist/expressions.js +14 -11
  143. package/dist/includes.js +6 -0
  144. package/dist/native/compiler/component-mapping.js +1 -0
  145. package/dist/native/compiler/headwind-to-style.js +17 -0
  146. package/dist/native/compiler/html-to-ir.js +2 -0
  147. package/dist/native/compiler/inline-style.js +2 -0
  148. package/dist/native/compiler/ir.d.ts +3 -1
  149. package/dist/native/components/primitives.d.ts +66 -20
  150. package/dist/native/components/primitives.js +1 -0
  151. package/dist/native/event-names.js +1 -0
  152. package/dist/native/primitives/MapPolygon.stx +2 -0
  153. package/dist/native/prop-names.js +4 -4
  154. package/dist/native/runtime/craft-bridge.js +22 -1
  155. package/dist/native/runtime/craft.d.ts +10 -0
  156. package/dist/process.js +3 -2
  157. package/dist/pwa.js +3 -3
  158. package/dist/script-validation.js +4 -4
  159. package/dist/serve.js +5 -1
  160. package/dist/server-bindings.js +5 -2
  161. package/dist/ssg.js +13 -13
  162. package/dist/utils.js +15 -2
  163. package/package.json +5 -5
  164. package/dist/chunk-06wv8qwy.js +0 -40
  165. package/dist/chunk-0d6b3eeb.js +0 -2
  166. package/dist/chunk-1e28n9q2.js +0 -2
  167. package/dist/chunk-1fdrhfc0.js +0 -2
  168. package/dist/chunk-1veeefpn.js +0 -2
  169. package/dist/chunk-2r4an7bh.js +0 -2
  170. package/dist/chunk-304vaxnk.js +0 -2
  171. package/dist/chunk-327bt8zb.js +0 -2
  172. package/dist/chunk-36n8yz6t.js +0 -2
  173. package/dist/chunk-3gm6013p.js +0 -2
  174. package/dist/chunk-3ttnn4t3.js +0 -2
  175. package/dist/chunk-3yttgk0s.js +0 -2
  176. package/dist/chunk-4ck2xc8m.js +0 -2
  177. package/dist/chunk-4jasfhh6.js +0 -2
  178. package/dist/chunk-605c6zks.js +0 -2
  179. package/dist/chunk-61d0gr5b.js +0 -2
  180. package/dist/chunk-7renf4zp.js +0 -2
  181. package/dist/chunk-8t3c2myr.js +0 -2
  182. package/dist/chunk-8x2ejkcc.js +0 -2
  183. package/dist/chunk-915s0may.js +0 -2
  184. package/dist/chunk-93na8hh0.js +0 -2
  185. package/dist/chunk-9fpnnfr3.js +0 -2
  186. package/dist/chunk-9zwdpa7p.js +0 -18
  187. package/dist/chunk-ajd5w5c4.js +0 -2
  188. package/dist/chunk-b4tbqz8r.js +0 -2
  189. package/dist/chunk-be2kmw0p.js +0 -2
  190. package/dist/chunk-bkjre6xk.js +0 -127
  191. package/dist/chunk-bnpb6ez9.js +0 -2
  192. package/dist/chunk-c0h9cxew.js +0 -2
  193. package/dist/chunk-cw76y2p5.js +0 -2
  194. package/dist/chunk-d0kes50w.js +0 -2
  195. package/dist/chunk-dzbkgsv8.js +0 -4
  196. package/dist/chunk-dzekcand.js +0 -2
  197. package/dist/chunk-en388k3h.js +0 -2
  198. package/dist/chunk-ewkza45r.js +0 -2
  199. package/dist/chunk-fcgf8d5k.js +0 -2
  200. package/dist/chunk-fese2cf6.js +0 -2
  201. package/dist/chunk-gk7mmc2e.js +0 -2
  202. package/dist/chunk-gw2dvp35.js +0 -2
  203. package/dist/chunk-h9drxwva.js +0 -2
  204. package/dist/chunk-hrr7k1qc.js +0 -2
  205. package/dist/chunk-j04brkj0.js +0 -2
  206. package/dist/chunk-jbvwg4gs.js +0 -2
  207. package/dist/chunk-jshj69dy.js +0 -2
  208. package/dist/chunk-k7spjpr0.js +0 -2
  209. package/dist/chunk-kgvm5ytn.js +0 -2
  210. package/dist/chunk-km9a5gp4.js +0 -2
  211. package/dist/chunk-m95zjk91.js +0 -3
  212. package/dist/chunk-mfery7a4.js +0 -2
  213. package/dist/chunk-n35yc890.js +0 -3
  214. package/dist/chunk-n882b1fy.js +0 -2
  215. package/dist/chunk-p8sv5fqs.js +0 -2
  216. package/dist/chunk-pndhb1nk.js +0 -2
  217. package/dist/chunk-pt7e0be5.js +0 -2
  218. package/dist/chunk-q40ahbjs.js +0 -2
  219. package/dist/chunk-qjxxhdv7.js +0 -2
  220. package/dist/chunk-qygr4pv8.js +0 -2
  221. package/dist/chunk-r4wqh5fd.js +0 -2845
  222. package/dist/chunk-rp93n4z7.js +0 -3
  223. package/dist/chunk-rrw2jg26.js +0 -2
  224. package/dist/chunk-wjhhb6dn.js +0 -2
  225. package/dist/chunk-wm8w2721.js +0 -2
  226. package/dist/chunk-wy53pys4.js +0 -43
  227. package/dist/chunk-y2wr7c9e.js +0 -2
  228. package/dist/chunk-y8jjmwa9.js +0 -2
  229. package/dist/chunk-yn2d8x8m.js +0 -3
  230. package/dist/chunk-z8mdsjzw.js +0 -2
  231. package/dist/chunk-zg87pybq.js +0 -2
@@ -1,11 +1,11 @@
1
1
  // @bun
2
- import{G,b,yn,bn,e,Nt,xn,f,Ke,Mt,Xe,Je,re,L,ge,J,u,Ee,Ai,Ds,n,r,se,pr,o,P,me}from"./chunk-r4wqh5fd.js";import{Y,On,oe,I,zt}from"./chunk-06wv8qwy.js";import{ct,jn,Er,Tr,$r,lt,ut,dt,pt,ft,gt,Pe}from"./chunk-azpkje69.js";import{je,_o,ie,T,Eo,zr,Gn,we,To,ae}from"./chunk-vvfpb3k3.js";import{Ut}from"./chunk-rg7wvcqw.js";import{de}from"./chunk-s4pjf2pc.js";import{a}from"./chunk-n35yc890.js";import{N}from"./chunk-k3f4044e.js";async function Xn(t){try{let s=await Bun.file(t).text(),i=Jn(s),d=Yn(s,t),c=Qn(s,i),l=Zn(s,i);return{file:t,metrics:i,issues:d,suggestions:c,performance:l}}catch(s){throw Error(`Failed to analyze template ${t}: ${s instanceof Error?s.message:String(s)}`)}}function Jn(t){let s=t.split(`
2
+ import{X,b,vn,wn,e,Lt,kn,f,Xe,jt,Je,Ye,se,L,me,Z,d,Te,Pi,Ns,n,r,oe,gr,o,P,he}from"./chunk-d17mhbz9.js";import{U,Nn,ie,O,Vt}from"./chunk-qqenm7pg.js";import{dt,Fn,Tr,$r,Rr,ut,pt,ft,gt,mt,ht,Ie}from"./chunk-cjrfazzb.js";import{Be,Eo,ae,T,To,Hr,Xn,xe,$o,ce}from"./chunk-vyjwag3f.js";import{qt}from"./chunk-r4xnqag4.js";import{pe}from"./chunk-5rtatjwq.js";import{a}from"./chunk-cjvq46n8.js";import{N}from"./chunk-zatgmkx7.js";async function Gn(t){try{let s=await Bun.file(t).text(),i=Jn(s),p=Yn(s,t),c=Qn(s,i),l=Zn(s,i);return{file:t,metrics:i,issues:p,suggestions:c,performance:l}}catch(s){throw Error(`Failed to analyze template ${t}: ${s instanceof Error?s.message:String(s)}`)}}function Jn(t){let s=t.split(`
3
3
  `),i=t.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),c=(i?i[1]:"").split(`
4
- `).length,l={conditionals:(t.match(/@(if|unless|elseif|else|endif|endunless)\b/g)||[]).length,loops:(t.match(/@(foreach|for|endforeach|endfor|while|endwhile)\b/g)||[]).length,includes:(t.match(/@(include|component|extends|section|yield)\b/g)||[]).length,custom:0,total:0};l.total=l.conditionals+l.loops+l.includes+l.custom;let m=(t.match(/\{\{[\s\S]*?\}\}/g)||[]).length,p=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,h=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,g=m+p+h,y=(t.match(/<[A-Z][^>]*>/g)||[]).length,w=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,R=0;for(let C of s)if(/@(?:if|unless|foreach|for|while|section)\b/.test(C)&&!/@end/.test(C)&&!/@else/.test(C))R++,S=Math.max(S,R);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(C))R--;let v=S>=4?3:0,x=Math.min(10,Math.ceil(l.total*0.5+g*0.1+y*0.3+(c>10?c*0.05:0)+v));return{lines:s.length,characters:t.length,directives:l,expressions:g,components:y,layouts:w,scriptLines:c,complexity:x}}function Yn(t,s){let i=[],d=Jt(t,"if","endif");if(d>0)i.push({type:"error",category:"syntax",message:`Found ${d} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let c=Jt(t,"foreach","endforeach");if(c>0)i.push({type:"error",category:"syntax",message:`Found ${c} unmatched @foreach directive(s)`,suggestion:"Ensure every @foreach has a corresponding @endforeach"});let l=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(l&&l.length>0)i.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let m=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(m>0)i.push({type:"warning",category:"security",message:`Found ${m} raw output expression(s) {!! !!}`,suggestion:"Ensure raw outputs are properly sanitized to prevent XSS"});let p=t.match(/<img[^>]*>/g);if(p){let y=p.filter((w)=>!w.includes("alt="));if(y.length>0)i.push({type:"warning",category:"accessibility",message:`Found ${y.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let h=t.split(`
5
- `).filter((y)=>y.length>120);if(h.length>0)i.push({type:"info",category:"maintainability",message:`Found ${h.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let g=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(g>3)i.push({type:"info",category:"maintainability",message:`Found ${g} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return i}function Qn(t,s){let i=[];if(s.complexity>7)i.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(s.complexity>5&&s.directives.total>8)i.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(s.lines>100&&s.components===0)i.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(s.expressions>20)i.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let d=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(d&&d.length>0)i.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(s.directives.total===0&&s.expressions<5)i.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(s.scriptLines>50)i.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return i}function Zn(t,s){let i=1;if(i+=s.directives.conditionals*0.1,i+=s.directives.loops*0.5,i+=s.directives.includes*2,i+=s.expressions*0.05,i+=s.components*1,s.scriptLines>10)i+=s.scriptLines*0.1;let d;if(s.expressions===0&&s.directives.total===0)d="high";else if(s.expressions<5&&s.directives.total<3)d="medium";else d="low";let c=[];if(i>10)c.push("Consider optimizing template complexity");if(d==="low"&&s.directives.total>5)c.push("Reduce dynamic content for better caching");if(s.components===0&&s.lines>40)c.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(i*100)/100,complexityScore:s.complexity,cacheability:d,recommendations:c}}function Jt(t,s,i){let d=t.replace(/<!--[\s\S]*?-->/g,""),c=(d.match(new RegExp(`@${s}\\b`,"g"))||[]).length,l=(d.match(new RegExp(`@${i}\\b`,"g"))||[]).length;return Math.abs(c-l)}async function po(t=["**/*.stx"],s){let i=[],d=[];for(let l of t){let m=await Array.fromAsync(new Bun.Glob(l).scan({cwd:s||process.cwd(),onlyFiles:!0,absolute:!0}));d.push(...m.filter((p)=>p.endsWith(".stx")))}for(let l of d)try{let m=await Xn(l);i.push(m)}catch(m){console.warn(`Failed to analyze ${l}:`,m)}let c=er(i);return{results:i,summary:c}}function er(t){let s=t.length,i=t.reduce((g,y)=>g+y.metrics.lines,0),d=s>0?t.reduce((g,y)=>g+y.metrics.complexity,0)/s:0,c=t.reduce((g,y)=>g+y.issues.length,0),l={};t.forEach((g)=>{g.issues.forEach((y)=>{l[y.category]=(l[y.category]||0)+1})});let m=s>0?t.reduce((g,y)=>g+y.performance.estimatedRenderTime,0)/s:0,p=Math.max(1,Math.min(10,Math.round(10-m/2-d/2))),h=[];if(d>6)h.push("Project has high average complexity. Consider refactoring complex templates.");if(c>s*2)h.push("High number of issues detected. Run detailed analysis on individual files.");if(l.security>0)h.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:s,totalLines:i,avgComplexity:Math.round(d*100)/100,totalIssues:c,issuesByCategory:l,performanceScore:p,recommendations:h}}import{mkdir as tr,readFile as nr,readdir as rr,stat as Yt,writeFile as or}from"fs/promises";import Re from"path";function rn(t){if(t==="connectedCallback")return`method "${t}" is reserved; define "onConnect" instead, which the element calls once it is connected, rendered and bound`;if(t==="disconnectedCallback")return`method "${t}" is reserved; define "onDisconnect" instead, which the element calls as it leaves the DOM, before it releases its own listeners`;return`method "${t}" is reserved`}var on=new Set(["constructor","connectedCallback","disconnectedCallback","attributeChangedCallback","adoptedCallback"]);function sr(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((s)=>s.charAt(0).toUpperCase()+s.slice(1)).join("")}function jt(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function ir(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function ar(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function cr(t){let s=[];async function i(d){let c=await rr(d,{withFileTypes:!0});c.sort((l,m)=>l.name.localeCompare(m.name));for(let l of c){let m=Re.join(d,l.name);if(l.isDirectory()){if(!l.name.startsWith(".")&&l.name!=="node_modules")await i(m)}else if(l.isFile()&&l.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(l.name))s.push(m)}}return await i(t),s}function lr(t,s){let i=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!i)return{};let d=i[1].trim();if(!d)return{};try{return JSON.parse(d)}catch(c){throw Error(`${s}: <script component> must contain JSON metadata (${c.message})`)}}function dr(t,s){let i={},d=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let c of d){if(!/\bclient\b/i.test(c[1])||/\bcomponent\b|\bstx:component\b/i.test(c[1]))continue;let l;try{l=new Bun.Transpiler({loader:"ts"}).transformSync(c[2])}catch(h){throw Error(`${s}: failed to transpile <script client> (${h.message})`)}let m=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,p;while(p=m.exec(l)){let h=p[1];if(on.has(h))throw Error(`${s}: client ${rn(h)}`);let g=m.lastIndex,y=1,w="",S=!1,R=g;for(;R<l.length&&y>0;R++){let x=l[R];if(S){S=!1;continue}if(w){if(x==="\\")S=!0;else if(x===w)w="";continue}if(x==='"'||x==="'"||x==="`")w=x;else if(x==="{")y++;else if(x==="}")y--}if(y!==0)throw Error(`${s}: unterminated client function "${h}"`);let v=p[0].includes("async")?"async ":"";i[h]=`${v}${h}(${p[2]}) {${l.slice(g,R-1)}}`,m.lastIndex=R}}return i}function ur(t){let s=t.match(/<template\b(?![^>]*\bshadowrootmode\b)[^>]*>([\s\S]*?)<\/template>/i);return(s?s[1]:t).replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").trim()}function Qt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((s)=>s[1].trim()).filter(Boolean).join(`
4
+ `).length,l={conditionals:(t.match(/@(if|unless|elseif|else|endif|endunless)\b/g)||[]).length,loops:(t.match(/@(foreach|for|endforeach|endfor|while|endwhile)\b/g)||[]).length,includes:(t.match(/@(include|component|extends|section|yield)\b/g)||[]).length,custom:0,total:0};l.total=l.conditionals+l.loops+l.includes+l.custom;let m=(t.match(/\{\{[\s\S]*?\}\}/g)||[]).length,u=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,h=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,g=m+u+h,y=(t.match(/<[A-Z][^>]*>/g)||[]).length,w=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,R=0;for(let C of s)if(/@(?:if|unless|foreach|for|while|section)\b/.test(C)&&!/@end/.test(C)&&!/@else/.test(C))R++,S=Math.max(S,R);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(C))R--;let v=S>=4?3:0,x=Math.min(10,Math.ceil(l.total*0.5+g*0.1+y*0.3+(c>10?c*0.05:0)+v));return{lines:s.length,characters:t.length,directives:l,expressions:g,components:y,layouts:w,scriptLines:c,complexity:x}}function Yn(t,s){let i=[],p=Jt(t,"if","endif");if(p>0)i.push({type:"error",category:"syntax",message:`Found ${p} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let c=Jt(t,"foreach","endforeach");if(c>0)i.push({type:"error",category:"syntax",message:`Found ${c} unmatched @foreach directive(s)`,suggestion:"Ensure every @foreach has a corresponding @endforeach"});let l=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(l&&l.length>0)i.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let m=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(m>0)i.push({type:"warning",category:"security",message:`Found ${m} raw output expression(s) {!! !!}`,suggestion:"Ensure raw outputs are properly sanitized to prevent XSS"});let u=t.match(/<img[^>]*>/g);if(u){let y=u.filter((w)=>!w.includes("alt="));if(y.length>0)i.push({type:"warning",category:"accessibility",message:`Found ${y.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let h=t.split(`
5
+ `).filter((y)=>y.length>120);if(h.length>0)i.push({type:"info",category:"maintainability",message:`Found ${h.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let g=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(g>3)i.push({type:"info",category:"maintainability",message:`Found ${g} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return i}function Qn(t,s){let i=[];if(s.complexity>7)i.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(s.complexity>5&&s.directives.total>8)i.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(s.lines>100&&s.components===0)i.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(s.expressions>20)i.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let p=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(p&&p.length>0)i.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(s.directives.total===0&&s.expressions<5)i.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(s.scriptLines>50)i.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return i}function Zn(t,s){let i=1;if(i+=s.directives.conditionals*0.1,i+=s.directives.loops*0.5,i+=s.directives.includes*2,i+=s.expressions*0.05,i+=s.components*1,s.scriptLines>10)i+=s.scriptLines*0.1;let p;if(s.expressions===0&&s.directives.total===0)p="high";else if(s.expressions<5&&s.directives.total<3)p="medium";else p="low";let c=[];if(i>10)c.push("Consider optimizing template complexity");if(p==="low"&&s.directives.total>5)c.push("Reduce dynamic content for better caching");if(s.components===0&&s.lines>40)c.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(i*100)/100,complexityScore:s.complexity,cacheability:p,recommendations:c}}function Jt(t,s,i){let p=t.replace(/<!--[\s\S]*?-->/g,""),c=(p.match(new RegExp(`@${s}\\b`,"g"))||[]).length,l=(p.match(new RegExp(`@${i}\\b`,"g"))||[]).length;return Math.abs(c-l)}async function fo(t=["**/*.stx"],s){let i=[],p=[];for(let l of t){let m=await Array.fromAsync(new Bun.Glob(l).scan({cwd:s||process.cwd(),onlyFiles:!0,absolute:!0}));p.push(...m.filter((u)=>u.endsWith(".stx")))}for(let l of p)try{let m=await Gn(l);i.push(m)}catch(m){console.warn(`Failed to analyze ${l}:`,m)}let c=er(i);return{results:i,summary:c}}function er(t){let s=t.length,i=t.reduce((g,y)=>g+y.metrics.lines,0),p=s>0?t.reduce((g,y)=>g+y.metrics.complexity,0)/s:0,c=t.reduce((g,y)=>g+y.issues.length,0),l={};t.forEach((g)=>{g.issues.forEach((y)=>{l[y.category]=(l[y.category]||0)+1})});let m=s>0?t.reduce((g,y)=>g+y.performance.estimatedRenderTime,0)/s:0,u=Math.max(1,Math.min(10,Math.round(10-m/2-p/2))),h=[];if(p>6)h.push("Project has high average complexity. Consider refactoring complex templates.");if(c>s*2)h.push("High number of issues detected. Run detailed analysis on individual files.");if(l.security>0)h.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:s,totalLines:i,avgComplexity:Math.round(p*100)/100,totalIssues:c,issuesByCategory:l,performanceScore:u,recommendations:h}}import{mkdir as tr,readFile as nr,readdir as rr,stat as Yt,writeFile as or}from"fs/promises";import Ee from"path";function rn(t){if(t==="connectedCallback")return`method "${t}" is reserved; define "onConnect" instead, which the element calls once it is connected, rendered and bound`;if(t==="disconnectedCallback")return`method "${t}" is reserved; define "onDisconnect" instead, which the element calls as it leaves the DOM, before it releases its own listeners`;return`method "${t}" is reserved`}var on=new Set(["constructor","connectedCallback","disconnectedCallback","attributeChangedCallback","adoptedCallback"]);function sr(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((s)=>s.charAt(0).toUpperCase()+s.slice(1)).join("")}function Ht(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function ir(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function ar(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function cr(t){let s=[];async function i(p){let c=await rr(p,{withFileTypes:!0});c.sort((l,m)=>l.name.localeCompare(m.name));for(let l of c){let m=Ee.join(p,l.name);if(l.isDirectory()){if(!l.name.startsWith(".")&&l.name!=="node_modules")await i(m)}else if(l.isFile()&&l.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(l.name))s.push(m)}}return await i(t),s}function lr(t,s){let i=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!i)return{};let p=i[1].trim();if(!p)return{};try{return JSON.parse(p)}catch(c){throw Error(`${s}: <script component> must contain JSON metadata (${c.message})`)}}function dr(t,s){let i={},p=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let c of p){if(!/\bclient\b/i.test(c[1])||/\bcomponent\b|\bstx:component\b/i.test(c[1]))continue;let l;try{l=new Bun.Transpiler({loader:"ts"}).transformSync(c[2])}catch(h){throw Error(`${s}: failed to transpile <script client> (${h.message})`)}let m=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,u;while(u=m.exec(l)){let h=u[1];if(on.has(h))throw Error(`${s}: client ${rn(h)}`);let g=m.lastIndex,y=1,w="",S=!1,R=g;for(;R<l.length&&y>0;R++){let x=l[R];if(S){S=!1;continue}if(w){if(x==="\\")S=!0;else if(x===w)w="";continue}if(x==='"'||x==="'"||x==="`")w=x;else if(x==="{")y++;else if(x==="}")y--}if(y!==0)throw Error(`${s}: unterminated client function "${h}"`);let v=u[0].includes("async")?"async ":"";i[h]=`${v}${h}(${u[2]}) {${l.slice(g,R-1)}}`,m.lastIndex=R}}return i}function pr(t){let s=t.match(/<template\b(?![^>]*\bshadowrootmode\b)[^>]*>([\s\S]*?)<\/template>/i);return(s?s[1]:t).replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").trim()}function Qt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((s)=>s[1].trim()).filter(Boolean).join(`
6
6
 
7
- `)}function fr(t){if(!t)return null;let s=t.replace(/\s*\|\s*(?:undefined|null)\b/g,"").trim();if(/^string$/.test(s))return"string";if(/^number$/.test(s))return"number";if(/^boolean$/.test(s))return"boolean";if(/^(?:'[^']*'|"[^"]*")(?:\s*\|\s*(?:'[^']*'|"[^"]*"))*$/.test(s))return"string";return"object"}function mr(t){if(t===void 0)return"object";if(t==="true"||t==="false")return"boolean";if(/^-?\d+(?:\.\d+)?$/.test(t))return"number";if(/^['"`]/.test(t))return"string";return"object"}function gr(t){if(t==="true")return!0;if(t==="false")return!1;if(/^-?\d+(?:\.\d+)?$/.test(t))return Number(t);if(/^['"`]/.test(t))return t.slice(1,-1);try{return JSON.parse(t)}catch{return}}function hr(t){let s=[],i=0,d=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),c=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,l,m=(h)=>{if(d[h]!=="(")return null;let g=0,y="";for(let w=h;w<d.length;w++){let S=d[w];if(y!==""){if(S==="\\")w++;else if(S===y)y="";continue}if(S==="'"||S==='"'||S==="`"){y=S;continue}if(S==="(")g++;else if(S===")"){if(g--,g===0)return{expression:d.slice(h+1,w),end:w+1}}}return null},p=(h)=>{if(h==="")return;let g=0,y=/\{!!\s*([\s\S]*?)\s*!!\}|\{\{\s*([\s\S]*?)\s*\}\}/g,w;while(w=y.exec(h)){if(w.index>g)s.push(`out += ${JSON.stringify(h.slice(g,w.index))};`);s.push(w[1]!==void 0?`out += __raw(${w[1]});`:`out += __escape(${w[2]});`),g=w.index+w[0].length}if(g<h.length)s.push(`out += ${JSON.stringify(h.slice(g))};`)};while(l=c.exec(d)){p(d.slice(i,l.index)),i=l.index+l[0].length;let g=l[1]==="if"||l[1]==="elseif"||l[1]==="foreach"?m(i):null;if(g)i=g.end,c.lastIndex=g.end;let y=g?.expression;switch(l[1]){case"if":s.push(`if (${y}) {`);break;case"elseif":s.push(`} else if (${y}) {`);break;case"else":s.push("} else {");break;case"endif":case"endforeach":s.push("}");break;case"foreach":{let w=/^([\s\S]+?)\s+as\s+(?:([A-Za-z_$][\w$]*)\s*=>\s*)?([A-Za-z_$][\w$]*)$/.exec((y||"").trim());if(!w){s.push(`out += ${JSON.stringify(l[0]+(g?`(${y})`:""))};`);break}let[,S,R,v]=w;s.push(R?`for (const [${R}, ${v}] of __entries(${S})) {`:`for (const ${v} of __values(${S})) {`);break}}}return p(d.slice(i)),s.join(`
8
- `)}function bt(t,s,i,d){if(t[s]!==i)return-1;let c=0,l=null;for(let m=s;m<t.length;m++){let p=t[m];if(l){if(p==="\\"){m++;continue}if(p===l)l=null;continue}if(p==="'"||p==='"'||p==="`"){l=p;continue}if(p===i)c++;else if(p===d){if(d===">"&&t[m-1]==="=")continue;if(c--,c===0)return m+1}}return-1}function Lt(t,s,i){let d=i?"([{<":"([{",c=i?")]}>":")]}",l=[],m=0,p=null,h="";for(let g=0;g<t.length;g++){let y=t[g];if(p){if(h+=y,y==="\\"){h+=t[++g]??"";continue}if(y===p)p=null;continue}if(y==="'"||y==='"'||y==="`"){p=y,h+=y;continue}if(d.includes(y))m++;else if(c.includes(y))m--;if(m===0&&s.includes(y)){l.push(h),h="";continue}h+=y}return l.push(h),l.map((g)=>g.trim()).filter(Boolean)}function yr(t){let s=0,i=null;for(let d=0;d<t.length;d++){let c=t[d];if(i){if(c==="\\"){d++;continue}if(c===i)i=null;continue}if(c==="'"||c==='"'||c==="`"){i=c;continue}if("([{".includes(c))s++;else if(")]}".includes(c))s--;if(s!==0||c!=="=")continue;let l=t[d-1];if(t[d+1]==="="||l==="="||l==="!"||l==="<"||l===">")continue;return d}return-1}function Zt(t){switch(t.trim()){case"String":return"string";case"Number":return"number";case"Boolean":return"boolean";case"Array":return"unknown[]";case"Object":return"Record<string, unknown>";default:return}}function br(t){let s=/\bdefineProps\b/.exec(t);if(!s)return null;let i=/(?:^|[\s;{}()])(const|let|var)\s+/g,d=-1;for(let k=i.exec(t);k&&k.index<s.index;k=i.exec(t))d=k.index+k[0].indexOf(k[1]);if(d===-1)return null;let c={},l={},m=[],p=d+(/^(?:const|let|var)\s+/.exec(t.slice(d))?.[0].length??0),h=()=>{while(p<t.length&&/\s/.test(t[p]))p++},g;if(t[p]==="{"){let k=bt(t,p,"{","}");if(k===-1)return null;g=t.slice(p,k),p=k}else{let k=/^[A-Za-z_$][\w$]*/.exec(t.slice(p));if(!k)return null;g=k[0],p+=k[0].length}if(h(),t[p]!=="=")return null;p++,h();let y=/^withDefaults\s*\(\s*/.exec(t.slice(p)),w=Boolean(y);if(y)p+=y[0].length;let S=/^defineProps\b/.exec(t.slice(p));if(!S)return null;p+=S[0].length;let R="";if(h(),t[p]==="<"){let k=bt(t,p,"<",">");if(k===-1)return null;R=t.slice(p+1,k-1).trim(),p=k}if(h(),t[p]!=="(")return null;let v=bt(t,p,"(",")");if(v===-1)return null;let x=t.slice(p+1,v-1).trim();if(p=v,w){if(h(),t[p]===",")p++,h();if(t[p]==="{"){let k=bt(t,p,"{","}");if(k===-1)return null;for(let[H,D]of It(t.slice(p,k)))l[H]=D;p=k}if(h(),t[p]===",")p++,h();if(t[p]===")")p++}if(t[p]===";")p++;let C=/^[A-Za-z_$][\w$]*$/.test(R)?R:void 0;if(R.startsWith("{"))for(let k of Lt(R.replace(/^\{/,"").replace(/\}$/,""),",;",!0)){let H=/^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(k);if(H)c[H[1]]=H[2].trim()}if(x.startsWith("{"))for(let[k,H]of It(x)){if(m.push(k),!H.startsWith("{")){let D=Zt(H);if(D)c[k]=D;continue}for(let[D,_]of It(H))if(D==="default")l[k]=_;else if(D==="type"){let E=Zt(_);if(E)c[k]=E}}else if(x.startsWith("["))for(let k of Lt(x.slice(1,-1),",",!1))m.push(k.replace(/^['"`]/,"").replace(/['"`]$/,""));if(g.startsWith("{")){m.length=0;for(let k of Lt(g.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let H=yr(k),_=(H===-1?k:k.slice(0,H)).split(":")[0].trim().replace(/^\.\.\./,"");if(!_)continue;if(m.push(_),H!==-1)l[_]=k.slice(H+1).trim()}}else if(m.length===0)m.push(...Object.keys(c));return{text:t.slice(d,p),propNames:m,defaults:l,declared:c,typeName:C}}function It(t){let s=t.trim().replace(/^\{/,"").replace(/\}$/,""),i=[],d=0;while(d<s.length){let c=/\s*([A-Za-z_$][\w$]*)\s*:/y;c.lastIndex=d;let l=c.exec(s);if(!l)break;d=c.lastIndex;let m=0,p="",h=d;while(d<s.length){let y=s[d];if(p){if(y==="\\")d++;else if(y===p)p=""}else if(y==="'"||y==='"'||y==="`")p=y;else if(y==="{"||y==="["||y==="(")m++;else if(y==="}"||y==="]"||y===")")m--;else if(y===","&&m===0)break;d++}let g=s.slice(h,d).trim();if(g)i.push([l[1],g]);d++}return i}function xr(t,s,i){let c=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].find((S)=>!/\bcomponent\b|\bstx:component\b|\bclient\b/i.test(S[1]));if(!c)return{imports:[],body:"",propNames:[],defaults:{},declared:{}};let l=c[2],m=[],p=[],h={},g={};l=l.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm,(S)=>{if(/from\s*['"]stx['"]/.test(S))return"";return m.push(S.trim().replace(/(from\s*['"])(\.[^'"]*)(['"])/,(R,v,x,C)=>{let k=Re.resolve(Re.dirname(s),x),H=Re.relative(i,k);return`${v}${H.startsWith(".")?H:`./${H}`}${C}`})),""});let y=br(l);if(y)p.push(...y.propNames),Object.assign(h,y.defaults),Object.assign(g,y.declared),l=l.replace(y.text,"");let w={};for(let S of l.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)){let R=[];for(let v of S[2].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))g[v[1]]=v[2].trim(),R.push(v[1]);w[S[1]]=R}if(y&&y.propNames.length===0&&y.typeName){for(let S of w[y.typeName]??[])if(!p.includes(S))p.push(S)}return l=l.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g,""),{imports:m,body:l.trim(),propNames:p,defaults:h,declared:g}}function vr(t){let s=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(d,c,l,m,p)=>{let h=c.toLowerCase();s.add(h);let g=(l||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${h}="${p}"${g?` data-stx-mod-${h}="${g}"`:""}`}),eventTypes:[...s].sort()}}function wr(t){let s=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(d,c,l,m)=>{let p=s.length;return s.push({id:p,name:c,expression:m}),` data-stx-bind-${p}=""`}),bindings:s}}function Sr(t){let s=new Set;for(let i of t.matchAll(/<slot\b([^>]*)>/gi))s.add(i[1].match(/\bname\s*=\s*["']([^"']+)["']/i)?.[1]||"");return[...s].map((i)=>({name:i}))}function kr(t){return[...new Set([...t.matchAll(/(--[a-z0-9_-]+)\s*:/gi)].map((s)=>s[1]))].sort().map((s)=>({name:s}))}function en(t,s){if(!s||!new Set(["string","number","boolean","object","array"]).has(s.type))throw Error(`Property "${t}" must declare one of: string, number, boolean, object, array`);return{...s,reflect:s.reflect??s.attribute!==!1}}async function Cr(t,s,i){let d=Re.isAbsolute(s.file)?s.file:Re.resolve(t,s.file),c=await nr(d,"utf8"),l=lr(c,d),m=Re.basename(d,".stx"),p=s.name||l.name||sr(m),h=`${jt(i.prefix||"stx")}-${jt(m)}`,g=s.tag||l.tag||h;if(!p||!/^[A-Za-z_$][\w$]*$/.test(p))throw Error(`${d}: invalid component class name "${p}"`);if(!ir(g))throw Error(`${d}: invalid custom-element tag "${g}"; tags must be lowercase and contain a hyphen`);let y=s.properties||l.properties||l.props||{},w=Object.fromEntries(Object.entries(y).map(([D,_])=>[D,en(D,_)])),S=vr(ur(c)),R=wr(S.template),v=xr(c,d,Re.resolve(i.outputDir)),x=hr(R.template);for(let D of v.propNames){if(w[D])continue;let _=v.defaults[D];w[D]=en(D,{type:fr(v.declared[D])??mr(_),..._===void 0?{}:{default:gr(_)}})}let C=l.methods||{},k=s.methods||{},H=dr(c,d);return{file:Re.relative(t,d),sourcePath:d,name:p,tag:g,description:s.description||l.description||"",template:R.template,styles:Qt(c),shadowMode:ar(s.shadowDOM??l.shadowDOM??i.shadowDOM),progressive:s.progressive??l.progressive??i.progressive??!0,properties:w,events:s.events||l.events||{},methods:{...C,...k,...H},eventTypes:S.eventTypes,bindings:R.bindings,slots:Sr(R.template),cssProperties:kr(Qt(c)),scope:v,render:x}}function Rr(){let t=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),s=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}");return`const HTMLElementBase = globalThis.HTMLElement || class {};
7
+ `)}function ur(t){if(!t)return null;let s=t.replace(/\s*\|\s*(?:undefined|null)\b/g,"").trim();if(/^string$/.test(s))return"string";if(/^number$/.test(s))return"number";if(/^boolean$/.test(s))return"boolean";if(/^(?:'[^']*'|"[^"]*")(?:\s*\|\s*(?:'[^']*'|"[^"]*"))*$/.test(s))return"string";return"object"}function fr(t){if(t===void 0)return"object";if(t==="true"||t==="false")return"boolean";if(/^-?\d+(?:\.\d+)?$/.test(t))return"number";if(/^['"`]/.test(t))return"string";return"object"}function mr(t){if(t==="true")return!0;if(t==="false")return!1;if(/^-?\d+(?:\.\d+)?$/.test(t))return Number(t);if(/^['"`]/.test(t))return t.slice(1,-1);try{return JSON.parse(t)}catch{return}}function hr(t){let s=[],i=0,p=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),c=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,l,m=(h)=>{if(p[h]!=="(")return null;let g=0,y="";for(let w=h;w<p.length;w++){let S=p[w];if(y!==""){if(S==="\\")w++;else if(S===y)y="";continue}if(S==="'"||S==='"'||S==="`"){y=S;continue}if(S==="(")g++;else if(S===")"){if(g--,g===0)return{expression:p.slice(h+1,w),end:w+1}}}return null},u=(h)=>{if(h==="")return;let g=0,y=/\{!!\s*([\s\S]*?)\s*!!\}|\{\{\s*([\s\S]*?)\s*\}\}/g,w;while(w=y.exec(h)){if(w.index>g)s.push(`out += ${JSON.stringify(h.slice(g,w.index))};`);s.push(w[1]!==void 0?`out += __raw(${w[1]});`:`out += __escape(${w[2]});`),g=w.index+w[0].length}if(g<h.length)s.push(`out += ${JSON.stringify(h.slice(g))};`)};while(l=c.exec(p)){u(p.slice(i,l.index)),i=l.index+l[0].length;let g=l[1]==="if"||l[1]==="elseif"||l[1]==="foreach"?m(i):null;if(g)i=g.end,c.lastIndex=g.end;let y=g?.expression;switch(l[1]){case"if":s.push(`if (${y}) {`);break;case"elseif":s.push(`} else if (${y}) {`);break;case"else":s.push("} else {");break;case"endif":case"endforeach":s.push("}");break;case"foreach":{let w=/^([\s\S]+?)\s+as\s+(?:([A-Za-z_$][\w$]*)\s*=>\s*)?([A-Za-z_$][\w$]*)$/.exec((y||"").trim());if(!w){s.push(`out += ${JSON.stringify(l[0]+(g?`(${y})`:""))};`);break}let[,S,R,v]=w;s.push(R?`for (const [${R}, ${v}] of __entries(${S})) {`:`for (const ${v} of __values(${S})) {`);break}}}return u(p.slice(i)),s.join(`
8
+ `)}function bt(t,s,i,p){if(t[s]!==i)return-1;let c=0,l=null;for(let m=s;m<t.length;m++){let u=t[m];if(l){if(u==="\\"){m++;continue}if(u===l)l=null;continue}if(u==="'"||u==='"'||u==="`"){l=u;continue}if(u===i)c++;else if(u===p){if(p===">"&&t[m-1]==="=")continue;if(c--,c===0)return m+1}}return-1}function _t(t,s,i){let p=i?"([{<":"([{",c=i?")]}>":")]}",l=[],m=0,u=null,h="";for(let g=0;g<t.length;g++){let y=t[g];if(u){if(h+=y,y==="\\"){h+=t[++g]??"";continue}if(y===u)u=null;continue}if(y==="'"||y==='"'||y==="`"){u=y,h+=y;continue}if(p.includes(y))m++;else if(c.includes(y))m--;if(m===0&&s.includes(y)){l.push(h),h="";continue}h+=y}return l.push(h),l.map((g)=>g.trim()).filter(Boolean)}function yr(t){let s=0,i=null;for(let p=0;p<t.length;p++){let c=t[p];if(i){if(c==="\\"){p++;continue}if(c===i)i=null;continue}if(c==="'"||c==='"'||c==="`"){i=c;continue}if("([{".includes(c))s++;else if(")]}".includes(c))s--;if(s!==0||c!=="=")continue;let l=t[p-1];if(t[p+1]==="="||l==="="||l==="!"||l==="<"||l===">")continue;return p}return-1}function Zt(t){switch(t.trim()){case"String":return"string";case"Number":return"number";case"Boolean":return"boolean";case"Array":return"unknown[]";case"Object":return"Record<string, unknown>";default:return}}function br(t){let s=/\bdefineProps\b/.exec(t);if(!s)return null;let i=/(?:^|[\s;{}()])(const|let|var)\s+/g,p=-1;for(let k=i.exec(t);k&&k.index<s.index;k=i.exec(t))p=k.index+k[0].indexOf(k[1]);if(p===-1)return null;let c={},l={},m=[],u=p+(/^(?:const|let|var)\s+/.exec(t.slice(p))?.[0].length??0),h=()=>{while(u<t.length&&/\s/.test(t[u]))u++},g;if(t[u]==="{"){let k=bt(t,u,"{","}");if(k===-1)return null;g=t.slice(u,k),u=k}else{let k=/^[A-Za-z_$][\w$]*/.exec(t.slice(u));if(!k)return null;g=k[0],u+=k[0].length}if(h(),t[u]!=="=")return null;u++,h();let y=/^withDefaults\s*\(\s*/.exec(t.slice(u)),w=Boolean(y);if(y)u+=y[0].length;let S=/^defineProps\b/.exec(t.slice(u));if(!S)return null;u+=S[0].length;let R="";if(h(),t[u]==="<"){let k=bt(t,u,"<",">");if(k===-1)return null;R=t.slice(u+1,k-1).trim(),u=k}if(h(),t[u]!=="(")return null;let v=bt(t,u,"(",")");if(v===-1)return null;let x=t.slice(u+1,v-1).trim();if(u=v,w){if(h(),t[u]===",")u++,h();if(t[u]==="{"){let k=bt(t,u,"{","}");if(k===-1)return null;for(let[H,M]of It(t.slice(u,k)))l[H]=M;u=k}if(h(),t[u]===",")u++,h();if(t[u]===")")u++}if(t[u]===";")u++;let C=/^[A-Za-z_$][\w$]*$/.test(R)?R:void 0;if(R.startsWith("{"))for(let k of _t(R.replace(/^\{/,"").replace(/\}$/,""),",;",!0)){let H=/^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(k);if(H)c[H[1]]=H[2].trim()}if(x.startsWith("{"))for(let[k,H]of It(x)){if(m.push(k),!H.startsWith("{")){let M=Zt(H);if(M)c[k]=M;continue}for(let[M,I]of It(H))if(M==="default")l[k]=I;else if(M==="type"){let E=Zt(I);if(E)c[k]=E}}else if(x.startsWith("["))for(let k of _t(x.slice(1,-1),",",!1))m.push(k.replace(/^['"`]/,"").replace(/['"`]$/,""));if(g.startsWith("{")){m.length=0;for(let k of _t(g.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let H=yr(k),I=(H===-1?k:k.slice(0,H)).split(":")[0].trim().replace(/^\.\.\./,"");if(!I)continue;if(m.push(I),H!==-1)l[I]=k.slice(H+1).trim()}}else if(m.length===0)m.push(...Object.keys(c));return{text:t.slice(p,u),propNames:m,defaults:l,declared:c,typeName:C}}function It(t){let s=t.trim().replace(/^\{/,"").replace(/\}$/,""),i=[],p=0;while(p<s.length){let c=/\s*([A-Za-z_$][\w$]*)\s*:/y;c.lastIndex=p;let l=c.exec(s);if(!l)break;p=c.lastIndex;let m=0,u="",h=p;while(p<s.length){let y=s[p];if(u){if(y==="\\")p++;else if(y===u)u=""}else if(y==="'"||y==='"'||y==="`")u=y;else if(y==="{"||y==="["||y==="(")m++;else if(y==="}"||y==="]"||y===")")m--;else if(y===","&&m===0)break;p++}let g=s.slice(h,p).trim();if(g)i.push([l[1],g]);p++}return i}function xr(t,s,i){let c=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].find((S)=>!/\bcomponent\b|\bstx:component\b|\bclient\b/i.test(S[1]));if(!c)return{imports:[],body:"",propNames:[],defaults:{},declared:{}};let l=c[2],m=[],u=[],h={},g={};l=l.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm,(S)=>{if(/from\s*['"]stx['"]/.test(S))return"";return m.push(S.trim().replace(/(from\s*['"])(\.[^'"]*)(['"])/,(R,v,x,C)=>{let k=Ee.resolve(Ee.dirname(s),x),H=Ee.relative(i,k);return`${v}${H.startsWith(".")?H:`./${H}`}${C}`})),""});let y=br(l);if(y)u.push(...y.propNames),Object.assign(h,y.defaults),Object.assign(g,y.declared),l=l.replace(y.text,"");let w={};for(let S of l.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)){let R=[];for(let v of S[2].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))g[v[1]]=v[2].trim(),R.push(v[1]);w[S[1]]=R}if(y&&y.propNames.length===0&&y.typeName){for(let S of w[y.typeName]??[])if(!u.includes(S))u.push(S)}return l=l.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g,""),{imports:m,body:l.trim(),propNames:u,defaults:h,declared:g}}function vr(t){let s=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(p,c,l,m,u)=>{let h=c.toLowerCase();s.add(h);let g=(l||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${h}="${u}"${g?` data-stx-mod-${h}="${g}"`:""}`}),eventTypes:[...s].sort()}}function wr(t){let s=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(p,c,l,m)=>{let u=s.length;return s.push({id:u,name:c,expression:m}),` data-stx-bind-${u}=""`}),bindings:s}}function Sr(t){let s=new Set;for(let i of t.matchAll(/<slot\b([^>]*)>/gi))s.add(i[1].match(/\bname\s*=\s*["']([^"']+)["']/i)?.[1]||"");return[...s].map((i)=>({name:i}))}function kr(t){return[...new Set([...t.matchAll(/(--[a-z0-9_-]+)\s*:/gi)].map((s)=>s[1]))].sort().map((s)=>({name:s}))}function en(t,s){if(!s||!new Set(["string","number","boolean","object","array"]).has(s.type))throw Error(`Property "${t}" must declare one of: string, number, boolean, object, array`);return{...s,reflect:s.reflect??s.attribute!==!1}}async function Cr(t,s,i){let p=Ee.isAbsolute(s.file)?s.file:Ee.resolve(t,s.file),c=await nr(p,"utf8"),l=lr(c,p),m=Ee.basename(p,".stx"),u=s.name||l.name||sr(m),h=`${Ht(i.prefix||"stx")}-${Ht(m)}`,g=s.tag||l.tag||h;if(!u||!/^[A-Za-z_$][\w$]*$/.test(u))throw Error(`${p}: invalid component class name "${u}"`);if(!ir(g))throw Error(`${p}: invalid custom-element tag "${g}"; tags must be lowercase and contain a hyphen`);let y=s.properties||l.properties||l.props||{},w=Object.fromEntries(Object.entries(y).map(([M,I])=>[M,en(M,I)])),S=vr(pr(c)),R=wr(S.template),v=xr(c,p,Ee.resolve(i.outputDir)),x=hr(R.template);for(let M of v.propNames){if(w[M])continue;let I=v.defaults[M];w[M]=en(M,{type:ur(v.declared[M])??fr(I),...I===void 0?{}:{default:mr(I)}})}let C=l.methods||{},k=s.methods||{},H=dr(c,p);return{file:Ee.relative(t,p),sourcePath:p,name:u,tag:g,description:s.description||l.description||"",template:R.template,styles:Qt(c),shadowMode:ar(s.shadowDOM??l.shadowDOM??i.shadowDOM),progressive:s.progressive??l.progressive??i.progressive??!0,properties:w,events:s.events||l.events||{},methods:{...C,...k,...H},eventTypes:S.eventTypes,bindings:R.bindings,slots:Sr(R.template),cssProperties:kr(Qt(c)),scope:v,render:x}}function Er(){let t=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),s=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}");return`const HTMLElementBase = globalThis.HTMLElement || class {};
9
9
 
10
10
  const escapeHTML = (value) => String(value ?? '')
11
11
  .replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;')
@@ -303,22 +303,22 @@ export function defineComponent(Component, definition) {
303
303
  }
304
304
  return Component;
305
305
  }
306
- `}function Pr(t){let s=JSON.stringify({tag:t.tag,template:t.template,styles:t.styles,shadowMode:t.shadowMode,progressive:t.progressive,properties:t.properties,eventTypes:t.eventTypes,bindings:t.bindings},null,2),i=Object.entries(t.methods).map(([p,h])=>{if(on.has(p))throw Error(`${t.sourcePath}: ${rn(p)}`);if(/^(?:async\s+)?[A-Za-z_$][\w$]*\s*\(/.test(h.trim()))return` ${h.trim()}`;return` ${p}($event) {
306
+ `}function Pr(t){let s=JSON.stringify({tag:t.tag,template:t.template,styles:t.styles,shadowMode:t.shadowMode,progressive:t.progressive,properties:t.properties,eventTypes:t.eventTypes,bindings:t.bindings},null,2),i=Object.entries(t.methods).map(([u,h])=>{if(on.has(u))throw Error(`${t.sourcePath}: ${rn(u)}`);if(/^(?:async\s+)?[A-Za-z_$][\w$]*\s*\(/.test(h.trim()))return` ${h.trim()}`;return` ${u}($event) {
307
307
  ${h}
308
308
  }`}).join(`
309
309
 
310
- `),d=t.scope,c=[...new Set([...Object.keys(t.properties),...d.propNames])].map((p)=>d.defaults[p]===void 0?p:`${p} = ${d.defaults[p]}`).join(", "),l=(p)=>p.split(`
310
+ `),p=t.scope,c=[...new Set([...Object.keys(t.properties),...p.propNames])].map((u)=>p.defaults[u]===void 0?u:`${u} = ${p.defaults[u]}`).join(", "),l=(u)=>u.split(`
311
311
  `).map((h)=>h.trim()===""?h:` ${h}`).join(`
312
- `),m="";if(t.render.trim()!==""||d.body!==""||c!==""){let p=[c?`const { ${c} } = this._props();`:"",d.body,"let out = '';",t.render,"return out;"].filter(Boolean).join(`
312
+ `),m="";if(t.render.trim()!==""||p.body!==""||c!==""){let u=[c?`const { ${c} } = this._props();`:"",p.body,"let out = '';",t.render,"return out;"].filter(Boolean).join(`
313
313
  `),h;try{let g=new Bun.Transpiler({loader:"ts"}).transformSync(`export function __render(__helpers) {
314
- ${p}
314
+ ${u}
315
315
  }`),y=g.indexOf("{"),w=g.lastIndexOf("}");h=g.slice(y+1,w).trim()}catch(g){throw Error(`${t.sourcePath}: failed to compile render (${g.message})`)}m=`
316
316
  render(__helpers) {
317
317
  const { escape: __escape, raw: __raw, values: __values, entries: __entries } = __helpers;
318
318
  ${l(h.trim())}
319
319
  }
320
320
  `}return`import { StxElement, defineComponent } from './runtime.js';
321
- ${d.imports.length?`${d.imports.join(`
321
+ ${p.imports.length?`${p.imports.join(`
322
322
  `)}
323
323
  `:""}
324
324
  /** ${t.description||`${t.name} web component generated from ${t.file}.`} */
@@ -328,16 +328,16 @@ ${i}${m}
328
328
 
329
329
  defineComponent(${t.name}, ${s});
330
330
  export default ${t.name};
331
- `}function xt(t){switch(t.type){case"boolean":return"boolean";case"number":return"number";case"array":return"unknown[]";case"object":return"Record<string, unknown>";default:return"string"}}function Ar(t){let s=Object.entries(t.properties).map(([l,m])=>` ${l}${m.required?"":"?"}: ${xt(m)}`).join(`
331
+ `}function xt(t){switch(t.type){case"boolean":return"boolean";case"number":return"number";case"array":return"unknown[]";case"object":return"Record<string, unknown>";default:return"string"}}function Or(t){let s=Object.entries(t.properties).map(([l,m])=>` ${l}${m.required?"":"?"}: ${xt(m)}`).join(`
332
332
  `),i=Object.entries(t.properties).map(([l,m])=>` ${l}: ${xt(m)}`).join(`
333
- `),d=Object.entries(t.events).map(([l,m])=>` ${JSON.stringify(l)}: CustomEvent<${m.detailType||"unknown"}>`).join(`
333
+ `),p=Object.entries(t.events).map(([l,m])=>` ${JSON.stringify(l)}: CustomEvent<${m.detailType||"unknown"}>`).join(`
334
334
  `),c=Object.keys(t.methods).map((l)=>` ${l}($event?: Event): unknown`).join(`
335
335
  `);return`export interface ${t.name}Props {
336
336
  ${s}
337
337
  }
338
338
 
339
339
  export interface ${t.name}EventMap {
340
- ${d}
340
+ ${p}
341
341
  }
342
342
 
343
343
  export declare class ${t.name} extends HTMLElement {
@@ -355,13 +355,13 @@ declare global {
355
355
  }
356
356
 
357
357
  export default ${t.name}
358
- `}function Mr(t){return`declare global {
358
+ `}function Ar(t){return`declare global {
359
359
  namespace JSX {
360
360
  interface IntrinsicElements {
361
- ${t.map((i)=>{let d=Object.entries(i.properties).map(([l,m])=>` ${JSON.stringify(l)}?: ${xt(m)}`).join(`
362
- `),c=Object.keys(i.events).map((l)=>` ${`on${l.split(/[-:]/).map((p)=>p.charAt(0).toUpperCase()+p.slice(1)).join("")}`}?: (event: CustomEvent<${i.events[l].detailType||"unknown"}>) => void`).join(`
361
+ ${t.map((i)=>{let p=Object.entries(i.properties).map(([l,m])=>` ${JSON.stringify(l)}?: ${xt(m)}`).join(`
362
+ `),c=Object.keys(i.events).map((l)=>` ${`on${l.split(/[-:]/).map((u)=>u.charAt(0).toUpperCase()+u.slice(1)).join("")}`}?: (event: CustomEvent<${i.events[l].detailType||"unknown"}>) => void`).join(`
363
363
  `);return` ${JSON.stringify(i.tag)}: {
364
- ${d}
364
+ ${p}
365
365
  ${c}
366
366
  children?: unknown
367
367
  slot?: string
@@ -374,9 +374,9 @@ ${c}
374
374
  }
375
375
 
376
376
  export {}
377
- `}function _r(t){return{schemaVersion:"1.0.0",modules:t.map((s)=>({kind:"javascript-module",path:`./${s.tag}.js`,declarations:[{kind:"class",name:s.name,description:s.description||void 0,customElement:!0,tagName:s.tag,members:Object.entries(s.properties).map(([i,d])=>({kind:"field",name:i,description:d.description,type:{text:xt(d)},default:d.default===void 0?void 0:JSON.stringify(d.default),attribute:d.attribute===!1?void 0:d.attribute||jt(i),reflects:d.reflect})),events:Object.entries(s.events).map(([i,d])=>({name:i,description:d.description,type:{text:`CustomEvent<${d.detailType||"unknown"}>`}})),slots:s.slots,cssProperties:s.cssProperties}],exports:[{kind:"js",name:s.name,declaration:{name:s.name,module:`./${s.tag}.js`}}]}))}}function tn(t){if(!t.styles)return"";let s=t.styles.replace(/:host\b/g,":scope");if(/\@scope\s*\(/.test(s))return s;return`@scope (${t.tag}) {
377
+ `}function _r(t){return{schemaVersion:"1.0.0",modules:t.map((s)=>({kind:"javascript-module",path:`./${s.tag}.js`,declarations:[{kind:"class",name:s.name,description:s.description||void 0,customElement:!0,tagName:s.tag,members:Object.entries(s.properties).map(([i,p])=>({kind:"field",name:i,description:p.description,type:{text:xt(p)},default:p.default===void 0?void 0:JSON.stringify(p.default),attribute:p.attribute===!1?void 0:p.attribute||Ht(i),reflects:p.reflect})),events:Object.entries(s.events).map(([i,p])=>({name:i,description:p.description,type:{text:`CustomEvent<${p.detailType||"unknown"}>`}})),slots:s.slots,cssProperties:s.cssProperties}],exports:[{kind:"js",name:s.name,declaration:{name:s.name,module:`./${s.tag}.js`}}]}))}}function tn(t){if(!t.styles)return"";let s=t.styles.replace(/:host\b/g,":scope");if(/\@scope\s*\(/.test(s))return s;return`@scope (${t.tag}) {
378
378
  ${s}
379
- }`}function nn(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").replace(/\s*([{}:;,])\s*/g,"$1").replace(/;}/g,"}").trim()}function Lr(t){let s=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),i=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}"),d=JSON.stringify('<slot(?:\\s+name=["\\\']([^"\\\']+)["\\\'])?\\s*\\/?>(?:<\\/slot>)?'),c=Object.fromEntries(t.map((m)=>[m.tag,{template:m.template,styles:m.styles,shadowMode:m.shadowMode,properties:m.properties}])),l=t.map((m)=>`export const render${m.name} = (props = {}, slots = {}) => renderComponent('${m.tag}', props, slots);`).join(`
379
+ }`}function nn(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").replace(/\s*([{}:;,])\s*/g,"$1").replace(/;}/g,"}").trim()}function Lr(t){let s=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),i=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}"),p=JSON.stringify('<slot(?:\\s+name=["\\\']([^"\\\']+)["\\\'])?\\s*\\/?>(?:<\\/slot>)?'),c=Object.fromEntries(t.map((m)=>[m.tag,{template:m.template,styles:m.styles,shadowMode:m.shadowMode,properties:m.properties}])),l=t.map((m)=>`export const render${m.name} = (props = {}, slots = {}) => renderComponent('${m.tag}', props, slots);`).join(`
380
380
  `);return`const definitions = ${JSON.stringify(c,null,2)};
381
381
  const escapeHTML = (value) => String(value ?? '')
382
382
  .replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;')
@@ -391,7 +391,7 @@ export function renderComponent(tag, props = {}, slots = {}) {
391
391
  let template = definition.template
392
392
  .replace(new RegExp(${s}, 'g'), (_match, expression) => String(valueAt(values, expression) ?? ''))
393
393
  .replace(new RegExp(${i}, 'g'), (_match, expression) => escapeHTML(valueAt(values, expression)))
394
- .replace(new RegExp(${d}, 'gi'), (_match, name) => String(slots[name || 'default'] ?? ''));
394
+ .replace(new RegExp(${p}, 'gi'), (_match, name) => String(slots[name || 'default'] ?? ''));
395
395
  const attributes = Object.entries(definition.properties).flatMap(([name, property]) => {
396
396
  if (property.attribute === false || !(name in props)) return [];
397
397
  const attribute = property.attribute || name.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase());
@@ -410,21 +410,21 @@ export function renderComponent(tag, props = {}, slots = {}) {
410
410
  }
411
411
 
412
412
  ${l}
413
- `}async function fo(t){let s=Re.resolve(t.inputDir),i=Re.resolve(t.outputDir);if(!(await Yt(s).catch(()=>null))?.isDirectory())throw Error(`Component-library input directory does not exist: ${s}`);let c=t.components?.length?t.components:(await cr(s)).map((x)=>({file:x}));if(!c.length)throw Error(`No .stx components found in ${s}`);let l=await Promise.all(c.map((x)=>Cr(s,x,t)));l.sort((x,C)=>x.tag.localeCompare(C.tag));let m=l.filter((x,C)=>l.findIndex((k)=>k.tag===x.tag)!==C);if(m.length)throw Error(`Duplicate custom-element tag: ${m[0].tag}`);let p=l.filter((x,C)=>l.findIndex((k)=>k.name===x.name)!==C);if(p.length)throw Error(`Duplicate component class name: ${p[0].name}`);await tr(i,{recursive:!0});let h=[],g=async(x,C)=>{let k=Re.join(i,x);return await or(k,C.endsWith(`
413
+ `}async function go(t){let s=Ee.resolve(t.inputDir),i=Ee.resolve(t.outputDir);if(!(await Yt(s).catch(()=>null))?.isDirectory())throw Error(`Component-library input directory does not exist: ${s}`);let c=t.components?.length?t.components:(await cr(s)).map((x)=>({file:x}));if(!c.length)throw Error(`No .stx components found in ${s}`);let l=await Promise.all(c.map((x)=>Cr(s,x,t)));l.sort((x,C)=>x.tag.localeCompare(C.tag));let m=l.filter((x,C)=>l.findIndex((k)=>k.tag===x.tag)!==C);if(m.length)throw Error(`Duplicate custom-element tag: ${m[0].tag}`);let u=l.filter((x,C)=>l.findIndex((k)=>k.name===x.name)!==C);if(u.length)throw Error(`Duplicate component class name: ${u[0].name}`);await tr(i,{recursive:!0});let h=[],g=async(x,C)=>{let k=Ee.join(i,x);return await or(k,C.endsWith(`
414
414
  `)?C:`${C}
415
- `,"utf8"),h.push(k),k};await g("runtime.js",Rr());for(let x of l){if(await g(`${x.tag}.js`,Pr(x)),t.declarations!==!1)await g(`${x.tag}.d.ts`,Ar(x));if(t.css!==!1&&x.styles){let C=x.shadowMode?x.styles:tn(x);await g(`${x.tag}.css`,t.minify?nn(C):C)}}let y=l.map((x)=>`export { ${x.name}, default as ${x.name}Element } from './${x.tag}.js';`).join(`
415
+ `,"utf8"),h.push(k),k};await g("runtime.js",Er());for(let x of l){if(await g(`${x.tag}.js`,Pr(x)),t.declarations!==!1)await g(`${x.tag}.d.ts`,Or(x));if(t.css!==!1&&x.styles){let C=x.shadowMode?x.styles:tn(x);await g(`${x.tag}.css`,t.minify?nn(C):C)}}let y=l.map((x)=>`export { ${x.name}, default as ${x.name}Element } from './${x.tag}.js';`).join(`
416
416
  `);if(await g("index.js",y),await g("ssr.js",Lr(l)),t.declarations!==!1)await g("index.d.ts",l.map((x)=>`export * from './${x.tag}.js'`).join(`
417
- `)),await g("custom-elements.d.ts",Mr(l)),await g("ssr.d.ts",`${l.map((x)=>`export declare const render${x.name}: (props?: ${x.name}Props, slots?: Record<string, string>) => string`).join(`
417
+ `)),await g("custom-elements.d.ts",Ar(l)),await g("ssr.d.ts",`${l.map((x)=>`export declare const render${x.name}: (props?: ${x.name}Props, slots?: Record<string, string>) => string`).join(`
418
418
  `)}
419
419
  export declare function renderComponent(tag: string, props?: Record<string, unknown>, slots?: Record<string, string>): string
420
420
  ${l.map((x)=>`import type { ${x.name}Props } from './${x.tag}.js'`).join(`
421
421
  `)}`);let w;if(t.manifest!==!1)w=await g("custom-elements.json",JSON.stringify(_r(l),null,2));let S;if(t.css!==!1){let x=l.filter((C)=>!C.shadowMode&&C.styles).map(tn).join(`
422
422
 
423
- `);if(x)S=await g("bundle.css",t.minify?nn(x):x)}let R;if(t.bundle!==!1){R=Re.join(i,"bundle.js");let x;try{x=await Bun.build({entrypoints:[Re.join(i,"index.js")],outdir:i,naming:"bundle.js",target:"browser",format:"esm",minify:t.minify??!0,sourcemap:t.sourcemap||"none"})}catch(C){let k=C instanceof AggregateError?C.errors:[C],H=k.map((D)=>String(D).trim()).filter(Boolean).join(`
423
+ `);if(x)S=await g("bundle.css",t.minify?nn(x):x)}let R;if(t.bundle!==!1){R=Ee.join(i,"bundle.js");let x;try{x=await Bun.build({entrypoints:[Ee.join(i,"index.js")],outdir:i,naming:"bundle.js",target:"browser",format:"esm",minify:t.minify??!0,sourcemap:t.sourcemap||"none"})}catch(C){let k=C instanceof AggregateError?C.errors:[C],H=k.map((M)=>String(M).trim()).filter(Boolean).join(`
424
424
  `);throw AggregateError(k,`Failed to bundle component library${H?`
425
425
  ${H}`:""}`)}if(!x.success){let C=x.logs.map((k)=>String(k).trim()).filter(Boolean).join(`
426
426
  `);throw AggregateError(x.logs,`Failed to bundle component library${C?`
427
- ${C}`:""}`)}if(h.push(R),t.sourcemap==="external")h.push(`${R}.map`)}let v=await Promise.all(h.map(async(x)=>(await Yt(x)).size));return{components:l.map((x)=>({name:x.name,tag:x.tag,source:x.sourcePath,module:Re.join(i,`${x.tag}.js`)})),files:h,manifest:w,bundle:R,cssBundle:S,totalBytes:v.reduce((x,C)=>x+C,0)}}var{serve:qr}=globalThis.Bun;import Bt from"fs";import ot from"path";function vt(){return`
427
+ ${C}`:""}`)}if(h.push(R),t.sourcemap==="external")h.push(`${R}.map`)}let v=await Promise.all(h.map(async(x)=>(await Yt(x)).size));return{components:l.map((x)=>({name:x.name,tag:x.tag,source:x.sourcePath,module:Ee.join(i,`${x.tag}.js`)})),files:h,manifest:w,bundle:R,cssBundle:S,totalBytes:v.reduce((x,C)=>x+C,0)}}var{serve:qr}=globalThis.Bun;import Ft from"fs";import ot from"path";function vt(){return`
428
428
  /* Theme selector for code blocks */
429
429
  .theme-selector {
430
430
  margin: 1rem 0;
@@ -504,12 +504,12 @@ else {
504
504
  <span class="frontmatter-label">${s}:</span>
505
505
  <span>${Array.isArray(i)?i.join(", "):String(i)}</span>
506
506
  </div>`).join("")}
507
- </div>`}import sn from"net";async function Ir(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"0.0.0.0")})}async function jr(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"::")})}async function Hr(t){if(!await Ir(t))return!1;return await jr(t)}async function Ye(t,s=20){t=Number(t);for(let i=0;i<s;i++){let d=t+i;if(await Hr(d))return d}throw Error(`Could not find an available port between ${t} and ${t+s-1}`)}var Br={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function Fr(){try{let t=await import("./chunk-y8h823cb.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function rt(t,s={}){let i={...Br,...s},d=await Fr();if(!d)return console.log(`${e.yellow}\u26A0${e.reset} Native window requested, but @stacksjs/desktop is not available.`),console.log(" Install & build the desktop package to enable --native."),!1;try{let c=await d.openDevWindow(t,{title:i.title,width:i.width,height:i.height,darkMode:i.darkMode,hotReload:i.hotReload,titlebarHidden:i.titlebarHidden,nativeSidebar:i.nativeSidebar,sidebarWidth:i.sidebarWidth,sidebarConfig:i.sidebarConfig});if(c&&i.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return c}catch(c){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,c),!1}}function Tt(t){if(t.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let c=t.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(c){let l=c[1];try{let m=`
507
+ </div>`}import sn from"net";async function Ir(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"0.0.0.0")})}async function jr(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"::")})}async function Br(t){if(!await Ir(t))return!1;return await jr(t)}async function Ge(t,s=20){t=Number(t);for(let i=0;i<s;i++){let p=t+i;if(await Br(p))return p}throw Error(`Could not find an available port between ${t} and ${t+s-1}`)}var Fr={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function zr(){try{let t=await import("./chunk-74j18qk0.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function rt(t,s={}){let i={...Fr,...s},p=await zr();if(!p)return console.log(`${e.yellow}\u26A0${e.reset} Native window requested, but @stacksjs/desktop is not available.`),console.log(" Install & build the desktop package to enable --native."),!1;try{let c=await p.openDevWindow(t,{title:i.title,width:i.width,height:i.height,darkMode:i.darkMode,hotReload:i.hotReload,titlebarHidden:i.titlebarHidden,nativeSidebar:i.nativeSidebar,sidebarWidth:i.sidebarWidth,sidebarConfig:i.sidebarConfig});if(c&&i.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return c}catch(c){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,c),!1}}function Tt(t){if(t.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let c=t.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(c){let l=c[1];try{let m=`
508
508
  ${l}
509
509
  return typeof sidebarConfig !== 'undefined' ? sidebarConfig : null;
510
- `,h=Function(m)();if(h)return h}catch(m){console.warn("Invalid sidebarConfig:",m)}}return{sections:[]}}let i=t.match(/@nativeSidebar\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(i)try{return JSON.parse(i[1])}catch{console.warn("Invalid @nativeSidebar configuration")}let d=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(d)try{let c=d[1].match(/(?:export\s+(?:default\s+)?|const\s+\w+\s*=\s*)(\{[\s\S]*\})/m);if(c)return Function(`return ${c[1]}`)()}catch(c){console.warn("Invalid native-sidebar script configuration:",c)}return}function Ht(){console.log(`
511
- Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in browser`),console.log(` ${e.cyan}c${e.reset} + Enter - Clear console`),console.log(` ${e.cyan}q${e.reset} + Enter (or ${e.cyan}Ctrl+C${e.reset}) - Quit server`),console.log(` ${e.cyan}h${e.reset} + Enter - Show this help`)}function Ur(t){console.log(`${e.green}Server running at ${e.cyan}${t}${e.reset}`),console.log(`Press ${e.cyan}Ctrl+C${e.reset} to stop the server`),Ht()}function Wr(t){console.log(`${e.dim}Opening ${e.cyan}${t}${e.dim} in your browser...${e.reset}`),Bun.spawn(["open",t],{stderr:"inherit"})}function Qe(t,s,i){if(!process.stdin.isTTY)return;process.stdin.setRawMode(!0),process.stdin.setEncoding("utf8"),process.stdin.resume(),Ht();let d="";process.stdin.on("data",(c)=>{if(c==="\x03"){if(i?.onQuit)i.onQuit();s(),process.exit(0)}if(d+=c,d.endsWith("\r")||d.endsWith(`
512
- `)){let l=d.trim().toLowerCase();d="",Vr(l,t,s,i)}})}function Vr(t,s,i,d){switch(t){case"o":if(d?.onOpen)d.onOpen();else Wr(s);break;case"c":if(d?.onClear)d.onClear();else console.clear(),Ur(s);break;case"q":if(d?.onQuit)d.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),i(),process.exit(0);break;case"h":if(d?.onHelp)d.onHelp();else Ht();break;default:break}}async function Ft(t,s={}){let i=s.port||3000,d=s.watch!==!1,c=ot.resolve(t);if(!Bt.existsSync(c))return console.error(`${e.red}Error: File not found: ${e.bright}${c}${e.reset}`),!1;if(!c.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${c}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${t}${e.reset}...`);let l=null,m=async()=>{try{let{content:w,data:S}=await me(c,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),R=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,v=R?.defaultTheme||"github-dark",x=["github-dark"],C=R?.additionalThemes||[],H=[...new Set([...x,...C])].map((D)=>`<option value="${D}"${D===v?" selected":""}>${D}</option>`).join(`
510
+ `,h=Function(m)();if(h)return h}catch(m){console.warn("Invalid sidebarConfig:",m)}}return{sections:[]}}let i=t.match(/@nativeSidebar\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(i)try{return JSON.parse(i[1])}catch{console.warn("Invalid @nativeSidebar configuration")}let p=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(p)try{let c=p[1].match(/(?:export\s+(?:default\s+)?|const\s+\w+\s*=\s*)(\{[\s\S]*\})/m);if(c)return Function(`return ${c[1]}`)()}catch(c){console.warn("Invalid native-sidebar script configuration:",c)}return}function Bt(){console.log(`
511
+ Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in browser`),console.log(` ${e.cyan}c${e.reset} + Enter - Clear console`),console.log(` ${e.cyan}q${e.reset} + Enter (or ${e.cyan}Ctrl+C${e.reset}) - Quit server`),console.log(` ${e.cyan}h${e.reset} + Enter - Show this help`)}function Ur(t){console.log(`${e.green}Server running at ${e.cyan}${t}${e.reset}`),console.log(`Press ${e.cyan}Ctrl+C${e.reset} to stop the server`),Bt()}function Wr(t){console.log(`${e.dim}Opening ${e.cyan}${t}${e.dim} in your browser...${e.reset}`),Bun.spawn(["open",t],{stderr:"inherit"})}function Qe(t,s,i){if(!process.stdin.isTTY)return;process.stdin.setRawMode(!0),process.stdin.setEncoding("utf8"),process.stdin.resume(),Bt();let p="";process.stdin.on("data",(c)=>{if(c==="\x03"){if(i?.onQuit)i.onQuit();s(),process.exit(0)}if(p+=c,p.endsWith("\r")||p.endsWith(`
512
+ `)){let l=p.trim().toLowerCase();p="",Vr(l,t,s,i)}})}function Vr(t,s,i,p){switch(t){case"o":if(p?.onOpen)p.onOpen();else Wr(s);break;case"c":if(p?.onClear)p.onClear();else console.clear(),Ur(s);break;case"q":if(p?.onQuit)p.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),i(),process.exit(0);break;case"h":if(p?.onHelp)p.onHelp();else Bt();break;default:break}}async function zt(t,s={}){let i=s.port||3000,p=s.watch!==!1,c=ot.resolve(t);if(!Ft.existsSync(c))return console.error(`${e.red}Error: File not found: ${e.bright}${c}${e.reset}`),!1;if(!c.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${c}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${t}${e.reset}...`);let l=null,m=async()=>{try{let{content:w,data:S}=await he(c,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),R=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,v=R?.defaultTheme||"github-dark",x=["github-dark"],C=R?.additionalThemes||[],H=[...new Set([...x,...C])].map((M)=>`<option value="${M}"${M===v?" selected":""}>${M}</option>`).join(`
513
513
  `);return l=`
514
514
  <!DOCTYPE html>
515
515
  <html lang="en">
@@ -672,19 +672,19 @@ Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in brow
672
672
  </script>
673
673
  </body>
674
674
  </html>
675
- `,!0}catch(w){return console.error(`${e.red}Error processing Markdown file:${e.reset}`,w),!1}};if(!await m())return!1;let h=i;try{if(h=await Ye(i),h!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${h} 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:${h}/${e.reset}...`);let g=qr({port:h,fetch(w){if(new URL(w.url).pathname==="/")return new Response(l,{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(w){return new Response(`<pre>${w}
675
+ `,!0}catch(w){return console.error(`${e.red}Error processing Markdown file:${e.reset}`,w),!1}};if(!await m())return!1;let h=i;try{if(h=await Ge(i),h!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${h} 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:${h}/${e.reset}...`);let g=qr({port:h,fetch(w){if(new URL(w.url).pathname==="/")return new Response(l,{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(w){return new Response(`<pre>${w}
676
676
  ${w.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
677
677
  ${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
678
678
  ${e.bright}\u2192 ${e.cyan}http://localhost:${h}/${e.reset}`),console.log(`
679
679
  ${e.yellow}Routes:${e.reset}`);let y=ot.relative(process.cwd(),c);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${y}${e.reset}`),console.log(`
680
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(g.url.toString(),()=>{if(d)Bt.watch(ot.dirname(c),{recursive:!0}).close();g.stop()}),s.native)await rt(h,{title:ot.basename(c,".md")});if(d){let w=ot.dirname(c);console.log(`${e.blue}Watching ${e.bright}${w}${e.reset} for changes...`);let S=Bt.watch(w,{recursive:!0},async(R,v)=>{if(v&&v.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${v}${e.yellow} changed, reprocessing...${e.reset}`),await m()});process.on("SIGINT",()=>{S.close(),g.stop(),process.exit(0)})}return!0}function Kr(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Gr}=globalThis.Bun;import Be from"fs";import ve from"path";class an{clients=new Set;server=null;options;constructor(t={}){this.options={wsPort:t.wsPort??3001,showOverlay:t.showOverlay??!0,reconnectInterval:t.reconnectInterval??1000,maxReconnectAttempts:t.maxReconnectAttempts??10,verbose:t.verbose??!1}}start(t){let s=t??this.options.wsPort,i=20;for(let d=0;d<i;d++)try{if(this.server=Bun.serve({port:s,fetch(c,l){if(l.upgrade(c,{data:{}}))return;return new Response("stx Hot Reload Server",{headers:{"Content-Type":"text/plain"}})},websocket:{open:(c)=>{if(this.clients.add(c),this.options.verbose)console.log(`[HMR] Client connected (${this.clients.size} total)`);c.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close:(c)=>{if(this.clients.delete(c),this.options.verbose)console.log(`[HMR] Client disconnected (${this.clients.size} total)`)},message:(c,l)=>{let m=typeof l==="string"?l:l.toString();if(m==="ping")return;try{let p=JSON.parse(m);if(p.type==="console"&&Array.isArray(p.args)){let h=p.args.join(" "),y={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[p.level]??"\x1B[36m";console.log(`${y}[browser]${p.level!=="log"?` ${p.level}`:""}\x1B[0m ${h}`)}}catch{}}}}),this.options.verbose)console.log(`[HMR] WebSocket server started on port ${s}`);return s}catch(c){if(c?.code==="EADDRINUSE"){s++;continue}throw c}throw Error(`Could not find an available port after ${i} attempts starting from ${t??this.options.wsPort}`)}stop(){for(let t of this.clients)try{t.close()}catch{}if(this.clients.clear(),this.server)this.server.stop(),this.server=null;if(this.options.verbose)console.log("[HMR] Server stopped")}broadcast(t){let s=JSON.stringify(t),i=0;for(let d of this.clients)try{if(d.readyState===1)d.send(s),i++}catch{this.clients.delete(d)}if(this.options.verbose&&i>0)console.log(`[HMR] Broadcast ${t.type} to ${i} client(s)`)}reload(t){if(this.options.verbose)console.log(`[HMR] Sending reload to ${this.clients.size} client(s) for: ${t||"all"}`);this.broadcast({type:"reload",path:t,timestamp:Date.now()})}updateCss(t,s){this.broadcast({type:"css-update",path:t,content:s,timestamp:Date.now()})}error(t){this.broadcast({type:"error",content:t,timestamp:Date.now()})}get clientCount(){return this.clients.size}get port(){return this.options.wsPort}}function Xr(t,s={}){let{showOverlay:i=!0,reconnectInterval:d=1000,maxReconnectAttempts:c=10}=s;return`
680
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(g.url.toString(),()=>{if(p)Ft.watch(ot.dirname(c),{recursive:!0}).close();g.stop()}),s.native)await rt(h,{title:ot.basename(c,".md")});if(p){let w=ot.dirname(c);console.log(`${e.blue}Watching ${e.bright}${w}${e.reset} for changes...`);let S=Ft.watch(w,{recursive:!0},async(R,v)=>{if(v&&v.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${v}${e.yellow} changed, reprocessing...${e.reset}`),await m()});process.on("SIGINT",()=>{S.close(),g.stop(),process.exit(0)})}return!0}function Kr(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Gr}=globalThis.Bun;import He from"fs";import we from"path";class an{clients=new Set;server=null;options;constructor(t={}){this.options={wsPort:t.wsPort??3001,showOverlay:t.showOverlay??!0,reconnectInterval:t.reconnectInterval??1000,maxReconnectAttempts:t.maxReconnectAttempts??10,verbose:t.verbose??!1}}start(t){let s=t??this.options.wsPort,i=20;for(let p=0;p<i;p++)try{if(this.server=Bun.serve({port:s,fetch(c,l){if(l.upgrade(c,{data:{}}))return;return new Response("stx Hot Reload Server",{headers:{"Content-Type":"text/plain"}})},websocket:{open:(c)=>{if(this.clients.add(c),this.options.verbose)console.log(`[HMR] Client connected (${this.clients.size} total)`);c.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close:(c)=>{if(this.clients.delete(c),this.options.verbose)console.log(`[HMR] Client disconnected (${this.clients.size} total)`)},message:(c,l)=>{let m=typeof l==="string"?l:l.toString();if(m==="ping")return;try{let u=JSON.parse(m);if(u.type==="console"&&Array.isArray(u.args)){let h=u.args.join(" "),y={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[u.level]??"\x1B[36m";console.log(`${y}[browser]${u.level!=="log"?` ${u.level}`:""}\x1B[0m ${h}`)}}catch{}}}}),this.options.verbose)console.log(`[HMR] WebSocket server started on port ${s}`);return s}catch(c){if(c?.code==="EADDRINUSE"){s++;continue}throw c}throw Error(`Could not find an available port after ${i} attempts starting from ${t??this.options.wsPort}`)}stop(){for(let t of this.clients)try{t.close()}catch{}if(this.clients.clear(),this.server)this.server.stop(),this.server=null;if(this.options.verbose)console.log("[HMR] Server stopped")}broadcast(t){let s=JSON.stringify(t),i=0;for(let p of this.clients)try{if(p.readyState===1)p.send(s),i++}catch{this.clients.delete(p)}if(this.options.verbose&&i>0)console.log(`[HMR] Broadcast ${t.type} to ${i} client(s)`)}reload(t){if(this.options.verbose)console.log(`[HMR] Sending reload to ${this.clients.size} client(s) for: ${t||"all"}`);this.broadcast({type:"reload",path:t,timestamp:Date.now()})}updateCss(t,s){this.broadcast({type:"css-update",path:t,content:s,timestamp:Date.now()})}error(t){this.broadcast({type:"error",content:t,timestamp:Date.now()})}get clientCount(){return this.clients.size}get port(){return this.options.wsPort}}function Xr(t,s={}){let{showOverlay:i=!0,reconnectInterval:p=1000,maxReconnectAttempts:c=10}=s;return`
681
681
  <script>
682
682
  (function() {
683
683
  // stx Hot Reload Client
684
684
  var wsUrl = 'ws://' + window.location.hostname + ':${t}';
685
685
  var reconnectAttempts = 0;
686
686
  var maxAttempts = ${c};
687
- var reconnectInterval = ${d};
687
+ var reconnectInterval = ${p};
688
688
  var socket = null;
689
689
  var overlay = null;
690
690
  var wasConnected = false; // Track if we ever connected successfully
@@ -876,10 +876,10 @@ else {
876
876
  };
877
877
  })();
878
878
  </script>
879
- `}function Ve(t,s,i={}){let d=Xr(s,i),c=t.lastIndexOf("</body>");if(c!==-1)return t.slice(0,c)+d+t.slice(c);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function $t(t){let s=t.toLowerCase();return s.endsWith(".css")||s.endsWith(".scss")||s.endsWith(".sass")||s.endsWith(".less")}function Ct(t){let s=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>s.endsWith(d))}function Rt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((i)=>i.test(t))}var st=null;function Et(t){if(!st)st=new an(t);return st}function ht(){if(st)st.stop(),st=null}import Pt from"path";var it={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},d=new Set,c=i.webComponents?.enabled?`./${Pt.relative(Pt.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let m=await pr(i,d);if(l.push(...m),i.debug&&m.length>0)console.log(`Successfully built ${m.length} web components`)}catch(m){console.error("Failed to build web components:",m)}t.onLoad({filter:/\.stx$/},async({path:m})=>{try{let p=new Set;if(i.cache&&i.cachePath){let x=await yn(m,i);if(x){if(i.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let h=await oe(()=>Bun.file(m).text(),"",(x)=>{throw new On(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!h)throw new On(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:y,allScripts:w}=G.time("script-extraction",()=>{let x=h,C=re(h);if(C)x=C.content.trim();let k=h.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],H="",D=[];for(let E of k){let M=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",B=E.match(/<script\b([^>]*)>/i),q=B?B[1]:"";if(/\bserver\b/i.test(q))H=M;else D.push(E)}let _=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:H,templateContent:_,allScripts:D}}),S={__filename:m,__dirname:Pt.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await oe(()=>u(g,S,m),void 0,(x)=>{let C=new Y(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(I.log(C,{filePath:m,scriptContent:g}),i.debug)throw C});let v=await G.timeAsync("directive-processing",async()=>await n(y,S,m,i,p));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-3gm6013p.js"),C=x(w.join(`
879
+ `}function Ve(t,s,i={}){let p=Xr(s,i),c=t.lastIndexOf("</body>");if(c!==-1)return t.slice(0,c)+p+t.slice(c);if(t.includes("</html>"))return t.replace("</html>",`${p}</html>`);return t+p}function $t(t){let s=t.toLowerCase();return s.endsWith(".css")||s.endsWith(".scss")||s.endsWith(".sass")||s.endsWith(".less")}function Ct(t){let s=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((p)=>s.endsWith(p))}function Rt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((i)=>i.test(t))}var st=null;function Et(t){if(!st)st=new an(t);return st}function lt(){if(st)st.stop(),st=null}import Pt from"path";var it={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},p=new Set,c=i.webComponents?.enabled?`./${Pt.relative(Pt.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let m=await gr(i,p);if(l.push(...m),i.debug&&m.length>0)console.log(`Successfully built ${m.length} web components`)}catch(m){console.error("Failed to build web components:",m)}t.onLoad({filter:/\.stx$/},async({path:m})=>{try{let u=new Set;if(i.cache&&i.cachePath){let x=await vn(m,i);if(x){if(i.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let h=await ie(()=>Bun.file(m).text(),"",(x)=>{throw new Nn(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!h)throw new Nn(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:y,allScripts:w}=X.time("script-extraction",()=>{let x=h,C=se(h);if(C)x=C.content.trim();let k=h.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],H="",M=[];for(let E of k){let _=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",B=E.match(/<script\b([^>]*)>/i),K=B?B[1]:"";if(/\bserver\b/i.test(K))H=_;else M.push(E)}let I=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:H,templateContent:I,allScripts:M}}),S={__filename:m,__dirname:Pt.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await ie(()=>d(g,S,m),void 0,(x)=>{let C=new U(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(O.log(C,{filePath:m,scriptContent:g}),i.debug)throw C});let v=await X.timeAsync("directive-processing",async()=>await n(y,S,m,i,u));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-64vnwrkw.js"),C=x(w.join(`
880
880
  `),S),k=v.search(/<\/body>/i);if(k!==-1)v=v.slice(0,k)+C+`
881
881
  `+v.slice(k);else v+=`
882
- ${C}`}if(v=await J(v),p.forEach((x)=>d.add(x)),i.cache&&i.cachePath){if(await bn(m,v,p,i),i.debug)console.log(`Cached template ${m} with ${p.size} dependencies`)}return{contents:v,loader:"html"}}catch(p){let h=p instanceof Error?p:new Y(`Plugin processing failed: ${String(p)}`,m);if(I.log(h,{filePath:m,buildConfig:t.config}),zt.logDetailedError(h,{filePath:m,plugin:"bun-plugin-stx"}),i.debug)console.error("stx Plugin Error:",h);let g=h,y=g.line||null,w=g.context||null;return{contents:i.debug||N()?`<!DOCTYPE html>
882
+ ${C}`}if(v=await Z(v),u.forEach((x)=>p.add(x)),i.cache&&i.cachePath){if(await wn(m,v,u,i),i.debug)console.log(`Cached template ${m} with ${u.size} dependencies`)}return{contents:v,loader:"html"}}catch(u){let h=u instanceof Error?u:new U(`Plugin processing failed: ${String(u)}`,m);if(O.log(h,{filePath:m,buildConfig:t.config}),Vt.logDetailedError(h,{filePath:m,plugin:"bun-plugin-stx"}),i.debug)console.error("stx Plugin Error:",h);let g=h,y=g.line||null,w=g.context||null;return{contents:i.debug||N()?`<!DOCTYPE html>
883
883
  <html lang="en">
884
884
  <head>
885
885
  <meta charset="UTF-8">
@@ -939,12 +939,12 @@ ${C}`}if(v=await J(v),p.forEach((x)=>d.add(x)),i.cache&&i.cachePath){if(await bn
939
939
  <h1>Something went wrong</h1>
940
940
  <p>An internal error occurred. Please try again later.</p>
941
941
  </body>
942
- </html>`,loader:"html"}}})}};async function zn(t,s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=ve.resolve(t);if(!Be.existsSync(p))return console.error(`${e.red}Error: File not found: ${e.bright}${p}${e.reset}`),!1;if(p.endsWith(".md"))return Ft(p,s);else if(!p.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${p}${e.reset}. Only .stx and .md files are supported.`),!1;let h=a(process.cwd(),"output");Be.mkdirSync(h,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,y=async()=>{try{let M={name:"public-assets",setup(Te){Te.onResolve({filter:/^\/(images|fonts|assets|public)\//},(he)=>({path:he.path,external:!0}))}},B=await Bun.build({entrypoints:[p],outdir:h,plugins:[M,it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!B.success)return console.error(`${e.red}Build failed:${e.reset}`,B.logs),!1;let q=B.outputs.find((Te)=>Te.path.endsWith(".html"));if(!q)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(q.path).text(),!0}catch(M){return console.error(`${e.red}Error building stx file:${e.reset}`,M),!1}};if(!await y())return!1;let S=ve.dirname(p);await Nt(S);let R=i;try{if(R=await Ye(i),R!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${R} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let M=s.hmrPort||R+1;l=Et({wsPort:M,verbose:!1}),m=l.start(M)}let v={},x=null,C;try{let{loadStxConfig:M}=await import("./chunk-mfery7a4.js"),B=await M();if(C=s.stxOptions?.serverApi??B.serverApi,B?.apiRouter)x=B?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(B?.apiRoutes){v=B.apiRoutes;let q=Object.keys(v).length;if(q>0)console.log(`${e.blue}Loaded ${e.bright}${q} API route${q>1?"s":""}${e.reset}`)}if(B?.broadcasting?.enabled)try{let{startBroadcasting:q,loadChannels:Z}=await import("./chunk-zs3ezqy3.js"),Te=B.broadcasting;await q(Te);let he=Te.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${he}/ws${e.reset}`);let Ae=ve.join(process.cwd(),"channels.ts");if(Be.existsSync(Ae))try{let ne=await Z(Ae);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(q){console.warn(`${e.yellow}Broadcasting failed to start: ${q.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:H}=await import("./chunk-gk7mmc2e.js"),D=await k(process.cwd(),C);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${R}/${e.reset}...`),c)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${m}${e.reset}`);let _=Gr({port:R,async fetch(M){return Ut(M,await(async()=>{let B=new URL(M.url);if([h,ve.dirname(p),ve.join(process.cwd(),"public")].some((ne)=>H(ve.join(ne,B.pathname),process.cwd(),C)))return new Response("Not Found",{status:404});if(x)try{let ne=await x.handleRequest(M);if(ne.status!==404)return ne}catch{}if(v[B.pathname])try{return await v[B.pathname](M)}catch(ne){return new Response(JSON.stringify({error:ne.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await D(M);if(q)return q;if(B.pathname==="/")return(async()=>{let U=await f(g||"");if(c)U=Ve(U,m);if(s.native)if(U.includes("<head>"))U=U.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else if(U.includes("<html"))U=U.replace(/(<html[^>]*>)/,"$1<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>");else U="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+U;if(s.titlebarHidden)if(U.includes("<head>"))U=U.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else if(U.includes("<html"))U=U.replace(/(<html[^>]*>)/,"$1<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>");else U=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${U}`;return U})().then((U)=>new Response(U,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Z=ve.join(h,B.pathname);if(Be.existsSync(Z)&&Be.statSync(Z).isFile()){let ne=Bun.file(Z),U=ve.extname(Z).toLowerCase(),j="text/plain";if(U===".ts"||U===".tsx"){let Fe=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=Fe.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":j="text/html";break;case".css":j="text/css";break;case".js":j="text/javascript";break;case".json":j="application/json";break;case".png":j="image/png";break;case".jpg":case".jpeg":j="image/jpeg";break;case".gif":j="image/gif";break;case".woff":j="font/woff";break;case".woff2":j="font/woff2";break;case".ttf":j="font/ttf";break;case".otf":j="font/otf";break;case".eot":j="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":j}})}let Te=ve.dirname(p),he=ve.join(Te,B.pathname);if(Be.existsSync(he)&&Be.statSync(he).isFile()){let ne=Bun.file(he),U=ve.extname(he).toLowerCase(),j="text/plain";if(U===".ts"||U===".tsx"){let Fe=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=Fe.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":j="text/html";break;case".css":j="text/css";break;case".js":j="text/javascript";break;case".json":j="application/json";break;case".png":j="image/png";break;case".jpg":case".jpeg":j="image/jpeg";break;case".gif":j="image/gif";break;case".svg":j="image/svg+xml";break;case".ico":j="image/x-icon";break;case".woff":j="font/woff";break;case".woff2":j="font/woff2";break;case".ttf":j="font/ttf";break;case".otf":j="font/otf";break;case".eot":j="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":j}})}let Ae=ve.join(process.cwd(),"public",B.pathname);if(Be.existsSync(Ae)&&Be.statSync(Ae).isFile()){let ne=Bun.file(Ae),U=ve.extname(Ae).toLowerCase(),j="application/octet-stream";if(U===".ts"||U===".tsx"){let Fe=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=Fe.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":j="text/html";break;case".css":j="text/css";break;case".js":j="text/javascript";break;case".json":j="application/json";break;case".png":j="image/png";break;case".jpg":case".jpeg":j="image/jpeg";break;case".gif":j="image/gif";break;case".svg":j="image/svg+xml";break;case".ico":j="image/x-icon";break;case".woff":j="font/woff";break;case".woff2":j="font/woff2";break;case".ttf":j="font/ttf";break;case".otf":j="font/otf";break;case".eot":j="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":j}})}return new Response("Not Found",{status:404})})())},error(M){return new Response(`<pre>${M}
943
- ${M.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
942
+ </html>`,loader:"html"}}})}};async function Vn(t,s={}){let i=s.port||3000,p=s.watch!==!1,c=s.hotReload!==!1&&p,l=null,m=s.hmrPort||i+1,u=we.resolve(t);if(!He.existsSync(u))return console.error(`${e.red}Error: File not found: ${e.bright}${u}${e.reset}`),!1;if(u.endsWith(".md"))return zt(u,s);else if(!u.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${u}${e.reset}. Only .stx and .md files are supported.`),!1;let h=a(process.cwd(),"output");He.mkdirSync(h,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,y=async()=>{try{let _={name:"public-assets",setup($e){$e.onResolve({filter:/^\/(images|fonts|assets|public)\//},(ge)=>({path:ge.path,external:!0}))}},B=await Bun.build({entrypoints:[u],outdir:h,plugins:[_,it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!B.success)return console.error(`${e.red}Build failed:${e.reset}`,B.logs),!1;let K=B.outputs.find(($e)=>$e.path.endsWith(".html"));if(!K)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(K.path).text(),!0}catch(_){return console.error(`${e.red}Error building stx file:${e.reset}`,_),!1}};if(!await y())return!1;let S=we.dirname(u);await Lt(S);let R=i;try{if(R=await Ge(i),R!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${R} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let _=s.hmrPort||R+1;l=Et({wsPort:_,verbose:!1}),m=l.start(_)}let v={},x=null,C;try{let{loadStxConfig:_}=await import("./chunk-yagzr2ry.js"),B=await _();if(C=s.stxOptions?.serverApi??B.serverApi,B?.apiRouter)x=B?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(B?.apiRoutes){v=B.apiRoutes;let K=Object.keys(v).length;if(K>0)console.log(`${e.blue}Loaded ${e.bright}${K} API route${K>1?"s":""}${e.reset}`)}if(B?.broadcasting?.enabled)try{let{startBroadcasting:K,loadChannels:Q}=await import("./chunk-2h8xmmtk.js"),$e=B.broadcasting;await K($e);let ge=$e.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${ge}/ws${e.reset}`);let Oe=we.join(process.cwd(),"channels.ts");if(He.existsSync(Oe))try{let ne=await Q(Oe);console.log(`${e.blue}Loaded ${e.bright}${ne} broadcast channel${ne!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ne){console.warn(`${e.yellow}Failed to load channels.ts: ${ne.message}${e.reset}`)}}catch(K){console.warn(`${e.yellow}Broadcasting failed to start: ${K.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:H}=await import("./chunk-7aa4qncj.js"),M=await k(process.cwd(),C);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${R}/${e.reset}...`),c)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${m}${e.reset}`);let I=Gr({port:R,async fetch(_){return qt(_,await(async()=>{let B=new URL(_.url);if([h,we.dirname(u),we.join(process.cwd(),"public")].some((ne)=>H(we.join(ne,B.pathname),process.cwd(),C)))return new Response("Not Found",{status:404});if(x)try{let ne=await x.handleRequest(_);if(ne.status!==404)return ne}catch{}if(v[B.pathname])try{return await v[B.pathname](_)}catch(ne){return new Response(JSON.stringify({error:ne.message}),{status:500,headers:{"Content-Type":"application/json"}})}let K=await M(_);if(K)return K;if(B.pathname==="/")return(async()=>{let W=await f(g||"");if(c)W=Ve(W,m);if(s.native)if(W.includes("<head>"))W=W.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else if(W.includes("<html"))W=W.replace(/(<html[^>]*>)/,"$1<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>");else W="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+W;if(s.titlebarHidden)if(W.includes("<head>"))W=W.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else if(W.includes("<html"))W=W.replace(/(<html[^>]*>)/,"$1<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>");else W=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${W}`;return W})().then((W)=>new Response(W,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Q=we.join(h,B.pathname);if(He.existsSync(Q)&&He.statSync(Q).isFile()){let ne=Bun.file(Q),W=we.extname(Q).toLowerCase(),j="text/plain";if(W===".ts"||W===".tsx"){let Fe=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=Fe.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":j="text/html";break;case".css":j="text/css";break;case".js":j="text/javascript";break;case".json":j="application/json";break;case".png":j="image/png";break;case".jpg":case".jpeg":j="image/jpeg";break;case".gif":j="image/gif";break;case".woff":j="font/woff";break;case".woff2":j="font/woff2";break;case".ttf":j="font/ttf";break;case".otf":j="font/otf";break;case".eot":j="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":j}})}let $e=we.dirname(u),ge=we.join($e,B.pathname);if(He.existsSync(ge)&&He.statSync(ge).isFile()){let ne=Bun.file(ge),W=we.extname(ge).toLowerCase(),j="text/plain";if(W===".ts"||W===".tsx"){let Fe=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=Fe.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":j="text/html";break;case".css":j="text/css";break;case".js":j="text/javascript";break;case".json":j="application/json";break;case".png":j="image/png";break;case".jpg":case".jpeg":j="image/jpeg";break;case".gif":j="image/gif";break;case".svg":j="image/svg+xml";break;case".ico":j="image/x-icon";break;case".woff":j="font/woff";break;case".woff2":j="font/woff2";break;case".ttf":j="font/ttf";break;case".otf":j="font/otf";break;case".eot":j="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":j}})}let Oe=we.join(process.cwd(),"public",B.pathname);if(He.existsSync(Oe)&&He.statSync(Oe).isFile()){let ne=Bun.file(Oe),W=we.extname(Oe).toLowerCase(),j="application/octet-stream";if(W===".ts"||W===".tsx"){let Fe=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=Fe.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":j="text/html";break;case".css":j="text/css";break;case".js":j="text/javascript";break;case".json":j="application/json";break;case".png":j="image/png";break;case".jpg":case".jpeg":j="image/jpeg";break;case".gif":j="image/gif";break;case".svg":j="image/svg+xml";break;case".ico":j="image/x-icon";break;case".woff":j="font/woff";break;case".woff2":j="font/woff2";break;case".ttf":j="font/ttf";break;case".otf":j="font/otf";break;case".eot":j="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":j}})}return new Response("Not Found",{status:404})})())},error(_){return new Response(`<pre>${_}
943
+ ${_.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
944
944
  ${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
945
945
  ${e.bright}\u2192 ${e.cyan}http://localhost:${R}/${e.reset}`),console.log(`
946
- ${e.yellow}Routes:${e.reset}`);let E=ve.relative(process.cwd(),p);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${E}${e.reset}`),console.log(`
947
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(_.url.toString(),()=>{if(d)Be.watch(ve.dirname(p),{recursive:!0}).close();_.stop()}),s.native){let M=await Bun.file(p).text(),B=Tt(M);await rt(R,{title:ve.basename(p,".stx"),titlebarHidden:s.titlebarHidden===!0,nativeSidebar:!!B,sidebarConfig:B})}if(d){let M=ve.dirname(p);console.log(`${e.blue}Watching ${e.bright}${M}${e.reset} for changes...`);let B=Be.watch(M,{recursive:!0},async(q,Z)=>{if(!Z||Rt(Z))return;if(Ct(Z)){console.log(`${e.yellow}File ${e.bright}${Z}${e.yellow} changed, rebuilding...${e.reset}`),Ee.clear(),se();let Te=await y();if(await xn(S),c&&l)if(Te)l.reload(Z);else l.error("Build failed - check console for details")}else if($t(Z)){if(console.log(`${e.cyan}CSS ${e.bright}${Z}${e.cyan} changed${e.reset}`),c&&l)l.updateCss(Z)}});process.on("SIGINT",()=>{if(B.close(),l)ht();_.stop(),process.exit(0)})}return!0}var{serve:Jr}=globalThis.Bun;import Ze from"fs";import Oe from"path";var cn=`
946
+ ${e.yellow}Routes:${e.reset}`);let E=we.relative(process.cwd(),u);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${E}${e.reset}`),console.log(`
947
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(I.url.toString(),()=>{if(p)He.watch(we.dirname(u),{recursive:!0}).close();I.stop()}),s.native){let _=await Bun.file(u).text(),B=Tt(_);await rt(R,{title:we.basename(u,".stx"),titlebarHidden:s.titlebarHidden===!0,nativeSidebar:!!B,sidebarConfig:B})}if(p){let _=we.dirname(u);console.log(`${e.blue}Watching ${e.bright}${_}${e.reset} for changes...`);let B=He.watch(_,{recursive:!0},async(K,Q)=>{if(!Q||Rt(Q))return;if(Ct(Q)){console.log(`${e.yellow}File ${e.bright}${Q}${e.yellow} changed, rebuilding...${e.reset}`),Te.clear(),oe();let $e=await y();if(await kn(S),c&&l)if($e)l.reload(Q);else l.error("Build failed - check console for details")}else if($t(Q)){if(console.log(`${e.cyan}CSS ${e.bright}${Q}${e.cyan} changed${e.reset}`),c&&l)l.updateCss(Q)}});process.on("SIGINT",()=>{if(B.close(),l)lt();I.stop(),process.exit(0)})}return!0}var{serve:Jr}=globalThis.Bun;import Ze from"fs";import Pe from"path";var cn=`
948
948
  <script data-stx-helpers>
949
949
  (function() {
950
950
  'use strict'
@@ -1255,14 +1255,14 @@ else {
1255
1255
 
1256
1256
  })()
1257
1257
  </script>
1258
- `;function dn(t){if(t.length===0)return"";if(t.length===1)return t[0];let s=t.map((d)=>d.split(Oe.sep)),i=[];for(let d=0;d<s[0].length;d++){let c=s[0][d];if(s.every((l)=>l[d]===c))i.push(c);else break}return i.join(Oe.sep)}async function Hn(t,s={}){let i=s.port||3000,d=s.watch!==!1;for(let v of t){let x=Oe.resolve(v);if(!Ze.existsSync(x))return console.error(`${e.red}Error: File not found: ${e.bright}${x}${e.reset}`),!1;if(!x.endsWith(".stx")&&!x.endsWith(".md"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${x}${e.reset}. Only .stx and .md files are supported.`),!1}let c=a(process.cwd(),"output");Ze.mkdirSync(c,{recursive:!0});let l=dn(t.map((v)=>Oe.dirname(Oe.resolve(v))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let m={},p=[],h=async()=>{try{for(let v of t){let x=Oe.resolve(v);if(x.endsWith(".md"))try{let{content:k,data:H}=await me(x,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),D=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,_=D?.defaultTheme||"github-dark",E=["github-dark"],M=D?.additionalThemes||[],q=[...new Set([...E,...M])].map((Ae)=>`<option value="${Ae}"${Ae===_?" selected":""}>${Ae}</option>`).join(`
1259
- `),Z=`
1258
+ `;function dn(t){if(t.length===0)return"";if(t.length===1)return t[0];let s=t.map((p)=>p.split(Pe.sep)),i=[];for(let p=0;p<s[0].length;p++){let c=s[0][p];if(s.every((l)=>l[p]===c))i.push(c);else break}return i.join(Pe.sep)}async function Un(t,s={}){let i=s.port||3000,p=s.watch!==!1;for(let v of t){let x=Pe.resolve(v);if(!Ze.existsSync(x))return console.error(`${e.red}Error: File not found: ${e.bright}${x}${e.reset}`),!1;if(!x.endsWith(".stx")&&!x.endsWith(".md"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${x}${e.reset}. Only .stx and .md files are supported.`),!1}let c=a(process.cwd(),"output");Ze.mkdirSync(c,{recursive:!0});let l=dn(t.map((v)=>Pe.dirname(Pe.resolve(v))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let m={},u=[],h=async()=>{try{for(let v of t){let x=Pe.resolve(v);if(x.endsWith(".md"))try{let{content:k,data:H}=await he(x,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),M=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,I=M?.defaultTheme||"github-dark",E=["github-dark"],_=M?.additionalThemes||[],K=[...new Set([...E,..._])].map((Oe)=>`<option value="${Oe}"${Oe===I?" selected":""}>${Oe}</option>`).join(`
1259
+ `),Q=`
1260
1260
  <!DOCTYPE html>
1261
1261
  <html lang="en">
1262
1262
  <head>
1263
1263
  <meta charset="UTF-8">
1264
1264
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
1265
- <title>${ln(H.title||Oe.basename(x))}</title>
1265
+ <title>${ln(H.title||Pe.basename(x))}</title>
1266
1266
  <!-- Syntax highlighting styles -->
1267
1267
  <style id="syntax-theme">
1268
1268
  :root {
@@ -1409,7 +1409,7 @@ else {
1409
1409
  </head>
1410
1410
  <body>
1411
1411
  ${kt(H)}
1412
- ${wt(q)}
1412
+ ${wt(K)}
1413
1413
 
1414
1414
  ${k}
1415
1415
 
@@ -1418,25 +1418,25 @@ else {
1418
1418
  </script>
1419
1419
  </body>
1420
1420
  </html>
1421
- `,he=`/${Oe.relative(l,x).replace(/\.md$/,"")}`;if(he.endsWith("/index"))he=he.slice(0,-6)||"/";m[he||"/"]={filePath:x,content:Z,fileType:"md"}}catch(k){console.error(`${e.red}Error processing Markdown file ${e.bright}${v}${e.reset}:`,k);continue}else{let k={name:"public-assets",setup(E){E.onResolve({filter:/^\/(images|fonts|assets|public)\//},(M)=>({path:M.path,external:!0}))}},H;try{let E=await Bun.build({entrypoints:[x],outdir:c,plugins:[k,it],define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!E.success){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:`,de(E.logs,x));continue}let M=E.outputs.find((B)=>B.path.endsWith(".html"));if(!M){console.error(`${e.red}No HTML output found for ${e.bright}${v}${e.reset}`);continue}H=await Bun.file(M.path).text()}catch(E){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:
1422
- ${de(E,x)}`);continue}let _=`/${Oe.relative(l,x).replace(/\.stx$/,"")}`;if(_.endsWith("/index"))_=_.slice(0,-6)||"/";if(_.includes("[")){let{regex:E,params:M}=Er(_,{page:!0});p.push({pattern:E,paramNames:M,filePath:x,routeTemplate:_,fileType:"stx"}),m[_]={filePath:x,content:H,fileType:"stx"}}else m[_||"/"]={filePath:x,content:H,fileType:"stx"}}}if(Object.keys(m).length===0)return console.error(`${e.red}No files were successfully processed${e.reset}`),!1;return!0}catch(v){return console.error(`${e.red}Error processing files:${e.reset}`,de(v)),!1}};if(!await h())return!1;let y=i;try{if(y=await Ye(i),y!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${y} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${y}/${e.reset}...`);let w=Jr({port:y,async fetch(v){let x=new URL(v.url),C=Oe.join(process.cwd(),"public",x.pathname);if(Ze.existsSync(C)&&Ze.statSync(C).isFile()){let D=Bun.file(C),_=Oe.extname(C).toLowerCase(),E="application/octet-stream";if(_===".ts"||_===".tsx"){let M=new Bun.Transpiler({loader:_===".tsx"?"tsx":"ts"}),B=await D.text(),q=M.transformSync(B);return new Response(q,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(_){case".html":E="text/html";break;case".css":E="text/css";break;case".js":E="text/javascript";break;case".json":E="application/json";break;case".png":E="image/png";break;case".jpg":case".jpeg":E="image/jpeg";break;case".gif":E="image/gif";break;case".svg":E="image/svg+xml";break;case".ico":E="image/x-icon";break;case".woff":E="font/woff";break;case".woff2":E="font/woff2";break;case".ttf":E="font/ttf";break;case".otf":E="font/otf";break;case".eot":E="application/vnd.ms-fontobject";break}return new Response(D,{headers:{"Content-Type":E}})}let k=m[x.pathname];if(!k&&!x.pathname.endsWith("/"))k=m[`${x.pathname}/`];if(!k)for(let D of p){let _=x.pathname.match(D.pattern);if(_){let E=m[D.routeTemplate];if(E){let M={};for(let Z=0;Z<D.paramNames.length;Z++)M[D.paramNames[Z]]=decodeURIComponent(_[Z+1]);let B=E.content,q=`<script>window.__routeParams = ${JSON.stringify(M)};</script>`;if(B.includes("</head>"))B=B.replace("</head>",`${q}
1423
- </head>`);else B=q+B;k={...E,content:B}}break}}if(k)return f(k.content).then((D)=>{if(D.includes("</head>"))D=D.replace("</head>",`${cn}
1424
- </head>`);return new Response(D,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let H=Oe.join(c,x.pathname);if(Ze.existsSync(H)&&Ze.statSync(H).isFile()){let D=Bun.file(H),_=Oe.extname(H).toLowerCase(),E="text/plain";if(_===".ts"||_===".tsx"){let M=new Bun.Transpiler({loader:_===".tsx"?"tsx":"ts"}),B=await D.text(),q=M.transformSync(B);return new Response(q,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(_){case".html":E="text/html";break;case".css":E="text/css";break;case".js":E="text/javascript";break;case".json":E="application/json";break;case".png":E="image/png";break;case".jpg":case".jpeg":E="image/jpeg";break;case".gif":E="image/gif";break;case".svg":E="image/svg+xml";break;case".ico":E="image/x-icon";break;case".woff":E="font/woff";break;case".woff2":E="font/woff2";break;case".ttf":E="font/ttf";break;case".otf":E="font/otf";break;case".eot":E="application/vnd.ms-fontobject";break}return new Response(D,{headers:{"Content-Type":E}})}if(x.pathname!=="/"&&m["/"]){let D=ie(v);return f(m["/"].content).then((_)=>{if(D){let E=_.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(E){let M=_.match(/<title[^>]*>([\s\S]*?)<\/title>/i),B=M?M[1]:"",q=`<!DOCTYPE html><html><head><title>${ln(B)}</title></head><body><main>${E[1]}</main></body></html>`;return new Response(q,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...T(),"Cache-Control":je,Pragma:"no-cache",Expires:"0"}})}}return new Response(_,{headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})})}return new Response("Not Found",{status:404})},error(v){return new Response(`<pre>${v}
1421
+ `,ge=`/${Pe.relative(l,x).replace(/\.md$/,"")}`;if(ge.endsWith("/index"))ge=ge.slice(0,-6)||"/";m[ge||"/"]={filePath:x,content:Q,fileType:"md"}}catch(k){console.error(`${e.red}Error processing Markdown file ${e.bright}${v}${e.reset}:`,k);continue}else{let k={name:"public-assets",setup(E){E.onResolve({filter:/^\/(images|fonts|assets|public)\//},(_)=>({path:_.path,external:!0}))}},H;try{let E=await Bun.build({entrypoints:[x],outdir:c,plugins:[k,it],define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!E.success){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:`,pe(E.logs,x));continue}let _=E.outputs.find((B)=>B.path.endsWith(".html"));if(!_){console.error(`${e.red}No HTML output found for ${e.bright}${v}${e.reset}`);continue}H=await Bun.file(_.path).text()}catch(E){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:
1422
+ ${pe(E,x)}`);continue}let I=`/${Pe.relative(l,x).replace(/\.stx$/,"")}`;if(I.endsWith("/index"))I=I.slice(0,-6)||"/";if(I.includes("[")){let{regex:E,params:_}=Tr(I,{page:!0});u.push({pattern:E,paramNames:_,filePath:x,routeTemplate:I,fileType:"stx"}),m[I]={filePath:x,content:H,fileType:"stx"}}else m[I||"/"]={filePath:x,content:H,fileType:"stx"}}}if(Object.keys(m).length===0)return console.error(`${e.red}No files were successfully processed${e.reset}`),!1;return!0}catch(v){return console.error(`${e.red}Error processing files:${e.reset}`,pe(v)),!1}};if(!await h())return!1;let y=i;try{if(y=await Ge(i),y!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${y} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${y}/${e.reset}...`);let w=Jr({port:y,async fetch(v){let x=new URL(v.url),C=Pe.join(process.cwd(),"public",x.pathname);if(Ze.existsSync(C)&&Ze.statSync(C).isFile()){let M=Bun.file(C),I=Pe.extname(C).toLowerCase(),E="application/octet-stream";if(I===".ts"||I===".tsx"){let _=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),B=await M.text(),K=_.transformSync(B);return new Response(K,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(I){case".html":E="text/html";break;case".css":E="text/css";break;case".js":E="text/javascript";break;case".json":E="application/json";break;case".png":E="image/png";break;case".jpg":case".jpeg":E="image/jpeg";break;case".gif":E="image/gif";break;case".svg":E="image/svg+xml";break;case".ico":E="image/x-icon";break;case".woff":E="font/woff";break;case".woff2":E="font/woff2";break;case".ttf":E="font/ttf";break;case".otf":E="font/otf";break;case".eot":E="application/vnd.ms-fontobject";break}return new Response(M,{headers:{"Content-Type":E}})}let k=m[x.pathname];if(!k&&!x.pathname.endsWith("/"))k=m[`${x.pathname}/`];if(!k)for(let M of u){let I=x.pathname.match(M.pattern);if(I){let E=m[M.routeTemplate];if(E){let _={};for(let Q=0;Q<M.paramNames.length;Q++)_[M.paramNames[Q]]=decodeURIComponent(I[Q+1]);let B=E.content,K=`<script>window.__routeParams = ${JSON.stringify(_)};</script>`;if(B.includes("</head>"))B=B.replace("</head>",`${K}
1423
+ </head>`);else B=K+B;k={...E,content:B}}break}}if(k)return f(k.content).then((M)=>{if(M.includes("</head>"))M=M.replace("</head>",`${cn}
1424
+ </head>`);return new Response(M,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let H=Pe.join(c,x.pathname);if(Ze.existsSync(H)&&Ze.statSync(H).isFile()){let M=Bun.file(H),I=Pe.extname(H).toLowerCase(),E="text/plain";if(I===".ts"||I===".tsx"){let _=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),B=await M.text(),K=_.transformSync(B);return new Response(K,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(I){case".html":E="text/html";break;case".css":E="text/css";break;case".js":E="text/javascript";break;case".json":E="application/json";break;case".png":E="image/png";break;case".jpg":case".jpeg":E="image/jpeg";break;case".gif":E="image/gif";break;case".svg":E="image/svg+xml";break;case".ico":E="image/x-icon";break;case".woff":E="font/woff";break;case".woff2":E="font/woff2";break;case".ttf":E="font/ttf";break;case".otf":E="font/otf";break;case".eot":E="application/vnd.ms-fontobject";break}return new Response(M,{headers:{"Content-Type":E}})}if(x.pathname!=="/"&&m["/"]){let M=ae(v);return f(m["/"].content).then((I)=>{if(M){let E=I.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(E){let _=I.match(/<title[^>]*>([\s\S]*?)<\/title>/i),B=_?_[1]:"",K=`<!DOCTYPE html><html><head><title>${ln(B)}</title></head><body><main>${E[1]}</main></body></html>`;return new Response(K,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...T(),"Cache-Control":Be,Pragma:"no-cache",Expires:"0"}})}}return new Response(I,{headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})})}return new Response("Not Found",{status:404})},error(v){return new Response(`<pre>${v}
1425
1425
  ${v.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
1426
1426
  ${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
1427
1427
  ${e.bright}\u2192 ${e.cyan}http://localhost:${y}/${e.reset}`),console.log(`
1428
- ${e.yellow}Routes:${e.reset}`);let S=new Set(p.map((v)=>v.routeTemplate)),R=Object.entries(m).filter(([v])=>!S.has(v)).sort(([v],[x])=>v.localeCompare(x)).map(([v,x])=>({route:v==="/"?"/":v,filePath:Oe.relative(process.cwd(),x.filePath),fileType:x.fileType}));for(let v of p){let x=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");R.push({route:x,filePath:Oe.relative(process.cwd(),v.filePath),fileType:"stx"})}if(R.sort((v,x)=>v.route.localeCompare(x.route)),R.forEach((v,x)=>{let k=x===R.length-1?"\u2514\u2500 ":"\u251C\u2500 ",H=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${k}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${H}`)}),console.log(`
1429
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(w.url.toString(),()=>{if(d)Ze.watch(l,{recursive:!0}).close();w.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Ze.watch(l,{recursive:!0},async(x,C)=>{if(!C)return;if(C.endsWith(".stx")||C.endsWith(".js")||C.endsWith(".ts")||C.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${C}${e.yellow} changed, rebuilding...${e.reset}`),Ee.clear(),se(),await h()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function ln(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Yr}=globalThis.Bun;import be from"fs";import te from"path";async function pn(t){try{return Mt(await Bun.file(t).text())}catch{return}}function Wt(t){let s=Bun.file(t),i=te.extname(t).toLowerCase(),d={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":d[i]||"application/octet-stream",...l}})}async function Vn(t=".",s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=te.resolve(t),{loadStxConfig:h}=await import("./chunk-mfery7a4.js"),g=await h(p),{createServerApi:y,isServerApiSource:w}=await import("./chunk-gk7mmc2e.js"),S=s.stxOptions?.serverApi??g.serverApi,R=await y(p,S),v=g.root&&g.root!=="."?te.join(p,g.root):p,x=s.pagesDir||g.pagesDir||"pages",C=te.join(v,x);if(!be.existsSync(C)&&!g._layerPageDirs?.some((O)=>be.existsSync(O)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${C}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=L(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[C,...g._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${C}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let H=g?._pluginPageDirs||[],D=[];for(let{dir:O,prefix:F}of H)if(be.existsSync(O)){let z=L(te.dirname(O),{pagesDir:te.basename(O)});for(let W of z){let xe=F==="/"?W.pattern:`${F}${W.pattern==="/"?"":W.pattern}`;D.push({route:{...W,pattern:xe},prefix:F})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${F}${e.reset}`)}let _=new Map,E=null,M=null;if(s.stxOptions?.shell!==!1){if(M=await Eo(p,s.stxOptions?.shell),M){if(E=await zr(M,s.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(p,M)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}lt(),await dt(p);let B=ut();if(B.length>0)console.log(`${e.blue}Loaded ${e.bright}${B.length}${e.blue} middleware: ${e.dim}${B.join(", ")}${e.reset}`);let q={},Z=null;try{let{loadStxConfig:O}=await import("./chunk-mfery7a4.js"),F=await O(p);if(F?.apiRouter)Z=F?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(F?.apiRoutes){q=F.apiRoutes;let z=Object.keys(q).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:W}=await import("./chunk-zs3ezqy3.js"),xe=F.broadcasting;await z(xe);let ze=xe.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${ze}/ws${e.reset}`);let qe=te.join(process.cwd(),"channels.ts");if(be.existsSync(qe))try{let ee=await W(qe);console.log(`${e.blue}Loaded ${e.bright}${ee} broadcast channel${ee!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ee){console.warn(`${e.yellow}Failed to load channels.ts: ${ee.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let Te=a(p,"output");be.mkdirSync(Te,{recursive:!0});let he=new Map,Ae=new Set,ne=async(O)=>{let F=Tr(C,O);if(!F)return null;try{let z=await Bun.build({entrypoints:[F],outdir:Te,plugins:[it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!z.success)return null;let W=z.outputs.find((xe)=>xe.path.endsWith(".html"));if(!W)return null;return await Bun.file(W.path).text()}catch{return null}},U=new Map,j=async(O,F)=>{try{let{processDirectives:z,extractVariables:W,defaultConfig:xe,loadStxConfig:ze,injectRouterScript:qe}=await import("./chunk-mfery7a4.js"),{checkCache:ee,cacheTemplate:Q,readFileCached:V,templateCache:K}=await import("./chunk-93na8hh0.js"),Se=await ze(p),Ge=(ce)=>{if(!ce)return ce;if(te.isAbsolute(ce))return ce;return te.resolve(p,ce)},A={...xe,...Se,...s.stxOptions,autoShell:!0};if(s.debugDirectives)A.debug=!0;A.partialsDir=Ge(A.partialsDir),A.componentsDir=Ge(A.componentsDir),A.layoutsDir=Ge(A.layoutsDir),A.storesDir=Ge(A.storesDir||"stores"),A.cachePath=Ge(A.cachePath)??a(p,"cache");let ye=!F&&!s.profile,le=A.cache!==!1;if(le&&ye){let ce=K.get(O.filePath);if(ce)try{if((await be.promises.stat(O.filePath)).mtime.getTime()<=ce.mtime){let He=!0;for(let Ce of ce.dependencies){if(!be.existsSync(Ce)){He=!1;break}if((await be.promises.stat(Ce)).mtime.getTime()>ce.mtime){He=!1;break}}if(He){let Ce=ce.output;if(E)Ce=we(Ce,{preserveHead:!0});let mt=U.get(O.filePath);return{route:O,content:Ce,status:mt?.status??await pn(O.filePath),headers:mt?.headers}}}}catch{}let Le=await ee(O.filePath,A);if(Le){let Ie=Le;if(E)Ie=we(Ie,{preserveHead:!0});let He=U.get(O.filePath);return{route:O,content:Ie,status:He?.status??await pn(O.filePath),headers:He?.headers}}}let fe=le?await V(O.filePath):await Bun.file(O.filePath).text(),$e=Mt(fe),{classifyAllScripts:X}=await import("./chunk-mfery7a4.js"),_e=X(fe),Ne=_e.server.map((ce)=>ce.content),pe=fe;for(let ce of _e.server)pe=pe.replace(ce.fullTag,"");let ue={__filename:O.filePath,__dirname:te.dirname(O.filePath),__stx_options:A,params:F??{},__stx_runtime_head:{}};for(let ce of Ne)try{await W(ce,ue,O.filePath)}catch(Le){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",O.filePath,Le?.message||Le)}let We=new Set,De;if(s.profile){let ce=performance.now();De=await z(pe,ue,O.filePath,A,We);let Le=performance.now()-ce,Ie=te.relative(p,O.filePath)||O.filePath;console.log(`[stx:profile] ${Ie} \u2192 ${Le.toFixed(2)}ms`)}else De=await z(pe,ue,O.filePath,A,We);if(!E)De=await qe(De,{router:A.router});{let{interpolateScriptExpressions:ce}=await import("./chunk-3gm6013p.js");De=De.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Le,Ie,He)=>{if(!/function\s+__stx_setup_/.test(He))return Le;return`<script${Ie}>${ce(He,ue)}</script>`})}if(E)De=we(De,{preserveHead:!0});if(le&&ye)await Q(O.filePath,De,We,A);let{extractStreamBoundaries:qn}=await import("./chunk-d0kes50w.js"),nt=qn(ue),at=ue.__streamTemplates;if(at&&typeof at==="object"&&Object.keys(at).length>0){let ce=ue.streamBoundaries||{},Le={...A,autoShell:!1},Ie=Object.keys(at).map((Ce)=>({id:Ce,render:async()=>{let mt=typeof ce[Ce]==="function"?await ce[Ce]():void 0;return z(at[Ce],{...ue,$boundary:mt},O.filePath,Le,new Set)}})),He=new Set(Ie.map((Ce)=>Ce.id));nt=[...(nt||[]).filter((Ce)=>!He.has(Ce.id)),...Ie]}if(nt&&nt.length>0)Ae.add(O.pattern);else nt=void 0;let Kt=Xe(ue),Xt=Je(ue);if(ye)U.set(O.filePath,{status:Kt,headers:Xt});return{route:O,content:De,status:Kt??$e,headers:Xt,boundaries:nt}}catch(z){return console.error(`${e.red}Error building ${e.bright}${O.pattern}${e.reset}:`,z),null}},Fe=8,Ue=async()=>{he.clear(),_.clear();for(let O=0;O<k.length;O+=Fe){let F=k.slice(O,O+Fe),z=await Promise.all(F.map((W)=>j(W)));for(let W of z)if(W)he.set(W.route.pattern,W)}for(let O=0;O<D.length;O+=Fe){let F=D.slice(O,O+Fe),z=await Promise.all(F.map(({route:W})=>j(W)));for(let W of z)if(W)_.set(W.route.pattern,W)}return he.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await Ue())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Nt(p);let et=i;try{if(et=await Ye(i),et!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${et} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let O=s.hmrPort||et+1;l=Et({wsPort:O,verbose:!1}),m=l.start(O)}let At=(O,F)=>{let W=`<script data-stx-route-params>(function(){var p=${JSON.stringify(F).replace(/</g,"\\u003C").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;if(O.includes("</head>"))return O.replace("</head>",`${W}</head>`);if(O.includes("<body"))return O.replace(/<body([^>]*)>/,`<body$1>${W}`);return W+O};console.log(`${e.blue}Starting server...${e.reset}`);let Dt=Yr({port:et,async fetch(O){let F=new URL(O.url),z=g?.publicDir||"public",W=te.join(p,z,F.pathname),xe=te.join(p,F.pathname),ze=te.join(Te,F.pathname);if([W,xe,ze].some((A)=>w(A,p,S)))return new Response("Not Found",{status:404});let[qe,ee,Q]=await Promise.all([be.promises.stat(W).catch(()=>null),be.promises.stat(xe).catch(()=>null),be.promises.stat(ze).catch(()=>null)]);if(qe?.isFile()&&!w(W,p,S))return Wt(W);if(ee?.isFile()&&!w(xe,p,S))return Wt(xe);if(Q?.isFile()&&!w(ze,p,S))return Wt(ze);if(F.pathname.startsWith("/_stx/component/")){let A=decodeURIComponent(F.pathname.slice(16));if(A)try{let ye=`<${A} />`,le={...buildConfig,autoShell:!1},fe=await processDirectives(ye,{},te.join(p,"components",`${A}.stx`),le,new Set);return new Response(fe,{headers:{"Content-Type":"text/html"}})}catch(ye){return new Response(`<div class="stx-async-error">${ye.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(F.pathname==="/_stx/img"){let{handleImageRequest:A}=await import("./chunk-7renf4zp.js"),ye=await A(O,{publicDir:te.join(p,z),cacheDir:a(p,"cache","img")});if(ye)return ye}if(Z)try{let A=await Z.handleRequest(O);if(A.status!==404)return A}catch{}if(q[F.pathname])try{return await q[F.pathname](O)}catch(A){return new Response(JSON.stringify({error:A.message}),{status:500,headers:{"Content-Type":"application/json"}})}let V=await R(O);if(V)return V;let K=jn(F.pathname,k);if(K){let A=he.get(K.route.pattern),ye=Ae.has(K.route.pattern);if(K.route.isDynamic&&Object.keys(K.params).length>0||ye){let le=await j(K.route,K.params);if(le)A=le}if(A){let le=A.status??200,fe=A.headers??{},$e=(K.route.filePath?Ke(await Bun.file(K.route.filePath).text().catch(()=>"")):null)??{};if($e.validate){if(!await $e.validate({params:K.params})){let Ne=await ne(404);if(Ne){let pe=Ne;if(pe=await f(pe,p),c)pe=Ve(pe,m);return new Response(pe,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if($e.middleware){let _e=pt(F.pathname,K.params,$e,F.search),Ne=ft(_e,null,O,{isServer:!0}),pe=await gt($e.middleware,Ne);if(pe.redirect){let ue=pe.redirect.path,We=pe.redirect.options.redirectCode||302,De=new Headers(pe.responseHeaders);return De.set("Location",ue),new Response(null,{status:We,headers:De})}if(pe.abort){let{statusCode:ue,message:We}=pe.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${ue}</title></head><body><h1>Error ${ue}</h1><p>${We}</p></body></html>`,{status:ue,headers:{"Content-Type":"text/html"}})}if(Object.keys(pe.state).length>0){let ue=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(pe.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;A.content=A.content.replace("</head>",`${ue}</head>`)}}let X=A.content;if(E&&To(O)){let _e=Pe(X),Ne=ge(X),pe=X.match(/<title[^>]*>([\s\S]*?)<\/title>/i),ue=pe?_o(pe[1].trim()):"";if(Object.keys(K.params).length>0)X=At(X,K.params);X=await f(X,p);let We=g?.router?.container||"main";return X=ae(X,We),new Response(X,{status:le,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":_e.layout,"X-STX-Layout-Group":_e.group,"X-STX-Runtime":Ne?"true":"false",...ue&&{"X-STX-Title":encodeURIComponent(ue)},[Ai]:Ds(),...T(),"Cache-Control":je}})}if(E)X=Gn(E,X);if(Object.keys(K.params).length>0)X=At(X,K.params);if(X=await f(X,p),c)X=Ve(X,m);if(s.native)if(X.includes("<head>"))X=X.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else X="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+X;if(s.titlebarHidden)if(X.includes("<head>"))X=X.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else X=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${X}`;if(A.boundaries&&A.boundaries.length>0){let{renderStreamingPage:_e,streamToResponse:Ne}=await import("./chunk-d0kes50w.js");return Ne(_e(X,A.boundaries,{timeoutMs:30000}),{status:le,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(X,{status:le,headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...fe}})}}if(D.length>0){let A=D.map((le)=>le.route),ye=jn(F.pathname,A);if(ye){let le=_.get(ye.route.pattern);if(le){let fe=le.content;if(E)fe=Gn(E,fe);if(Object.keys(ye.params).length>0)fe=At(fe,ye.params);if(fe=await f(fe,p),c)fe=Ve(fe,m);return new Response(fe,{status:le.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:le}of H)if(le!=="/"&&F.pathname.startsWith(le)){let fe=_.get(le)||_.get(le+"/");if(fe){let $e=fe.content;if(E)$e=Gn(E,$e);if($e=await f($e,p),c)$e=Ve($e,m);return new Response($e,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(ct(F.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Se=he.get("/");if(Se){let A=Se.content;if(A=await f(A,p),c)A=Ve(A,m);if(s.native)if(A.includes("<head>"))A=A.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else A="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+A;return new Response(A,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Ge=await ne(404);if(Ge){let A=Ge;if(A=await f(A,p),c)A=Ve(A,m);return new Response(A,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(O){let F=await ne(500);if(F)return new Response(F,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${O}
1430
- ${O.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});if(console.clear(),console.log(`
1428
+ ${e.yellow}Routes:${e.reset}`);let S=new Set(u.map((v)=>v.routeTemplate)),R=Object.entries(m).filter(([v])=>!S.has(v)).sort(([v],[x])=>v.localeCompare(x)).map(([v,x])=>({route:v==="/"?"/":v,filePath:Pe.relative(process.cwd(),x.filePath),fileType:x.fileType}));for(let v of u){let x=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");R.push({route:x,filePath:Pe.relative(process.cwd(),v.filePath),fileType:"stx"})}if(R.sort((v,x)=>v.route.localeCompare(x.route)),R.forEach((v,x)=>{let k=x===R.length-1?"\u2514\u2500 ":"\u251C\u2500 ",H=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${k}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${H}`)}),console.log(`
1429
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(w.url.toString(),()=>{if(p)Ze.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Ze.watch(l,{recursive:!0},async(x,C)=>{if(!C)return;if(C.endsWith(".stx")||C.endsWith(".js")||C.endsWith(".ts")||C.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${C}${e.yellow} changed, rebuilding...${e.reset}`),Te.clear(),oe(),await h()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function ln(t){return String(t??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var{serve:Yr}=globalThis.Bun;import be from"fs";import te from"path";async function pn(t){try{return jt(await Bun.file(t).text())}catch{return}}function Nt(t){let s=Bun.file(t),i=te.extname(t).toLowerCase(),p={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":p[i]||"application/octet-stream",...l}})}async function Wn(t=".",s={}){let i=s.port||3000,p=s.watch!==!1,c=s.hotReload!==!1&&p,l=null,m=s.hmrPort||i+1,u=te.resolve(t),{loadStxConfig:h}=await import("./chunk-yagzr2ry.js"),g=await h(u),{createServerApi:y,isServerApiSource:w}=await import("./chunk-7aa4qncj.js"),S=s.stxOptions?.serverApi??g.serverApi,R=await y(u,S),v=g.root&&g.root!=="."?te.join(u,g.root):u,x=s.pagesDir||g.pagesDir||"pages",C=te.join(v,x);if(!be.existsSync(C)&&!g._layerPageDirs?.some((A)=>be.existsSync(A)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${C}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=L(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[C,...g._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${C}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let H=g?._pluginPageDirs||[],M=[];for(let{dir:A,prefix:F}of H)if(be.existsSync(A)){let z=L(te.dirname(A),{pagesDir:te.basename(A)});for(let V of z){let ve=F==="/"?V.pattern:`${F}${V.pattern==="/"?"":V.pattern}`;M.push({route:{...V,pattern:ve},prefix:F})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${F}${e.reset}`)}let I=new Map,E=null,_=null;if(s.stxOptions?.shell!==!1){if(_=await To(u,s.stxOptions?.shell),_){if(E=await Hr(_,s.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(u,_)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}ut(),await ft(u);let B=pt();if(B.length>0)console.log(`${e.blue}Loaded ${e.bright}${B.length}${e.blue} middleware: ${e.dim}${B.join(", ")}${e.reset}`);let K={},Q=null;try{let{loadStxConfig:A}=await import("./chunk-yagzr2ry.js"),F=await A(u);if(F?.apiRouter)Q=F?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(F?.apiRoutes){K=F.apiRoutes;let z=Object.keys(K).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:V}=await import("./chunk-2h8xmmtk.js"),ve=F.broadcasting;await z(ve);let ze=ve.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${ze}/ws${e.reset}`);let qe=te.join(process.cwd(),"channels.ts");if(be.existsSync(qe))try{let ee=await V(qe);console.log(`${e.blue}Loaded ${e.bright}${ee} broadcast channel${ee!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ee){console.warn(`${e.yellow}Failed to load channels.ts: ${ee.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let $e=a(u,"output");be.mkdirSync($e,{recursive:!0});let ge=new Map,Oe=new Set,ne=async(A)=>{let F=$r(C,A);if(!F)return null;try{let z=await Bun.build({entrypoints:[F],outdir:$e,plugins:[it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!z.success)return null;let V=z.outputs.find((ve)=>ve.path.endsWith(".html"));if(!V)return null;return await Bun.file(V.path).text()}catch{return null}},W=new Map,j=async(A,F)=>{try{let{processDirectives:z,extractVariables:V,defaultConfig:ve,loadStxConfig:ze,injectRouterScript:qe}=await import("./chunk-yagzr2ry.js"),{checkCache:ee,cacheTemplate:Y,readFileCached:q,templateCache:G}=await import("./chunk-4j3fmxeg.js"),Se=await ze(u),Ke=(re)=>{if(!re)return re;if(te.isAbsolute(re))return re;return te.resolve(u,re)},D={...ve,...Se,...s.stxOptions,autoShell:!0};if(s.debugDirectives)D.debug=!0;D.partialsDir=Ke(D.partialsDir),D.componentsDir=Ke(D.componentsDir),D.layoutsDir=Ke(D.layoutsDir),D.storesDir=Ke(D.storesDir||"stores"),D.cachePath=Ke(D.cachePath)??a(u,"cache");let ye=!F&&!s.profile,le=D.cache!==!1;if(le&&ye){let re=G.get(A.filePath);if(re)try{if((await be.promises.stat(A.filePath)).mtime.getTime()<=re.mtime){let je=!0;for(let Re of re.dependencies){if(!be.existsSync(Re)){je=!1;break}if((await be.promises.stat(Re)).mtime.getTime()>re.mtime){je=!1;break}}if(je){let Re=re.output;if(E)Re=xe(Re,{preserveHead:!0});let ct=W.get(A.filePath);return{route:A,content:Re,status:ct?.status??await pn(A.filePath),headers:ct?.headers}}}}catch{}let _e=await ee(A.filePath,D);if(_e){let Le=_e;if(E)Le=xe(Le,{preserveHead:!0});let je=W.get(A.filePath);return{route:A,content:Le,status:je?.status??await pn(A.filePath),headers:je?.headers}}}let fe=le?await q(A.filePath):await Bun.file(A.filePath).text(),Ce=jt(fe),{classifyAllScripts:J}=await import("./chunk-yagzr2ry.js"),Me=J(fe),Ne=Me.server.map((re)=>re.content),de=fe;for(let re of Me.server)de=de.replace(re.fullTag,"");let ue={__filename:A.filePath,__dirname:te.dirname(A.filePath),__stx_options:D,params:F??{},__stx_runtime_head:{}};for(let re of Ne)try{await V(re,ue,A.filePath)}catch(_e){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",A.filePath,_e?.message||_e)}let We=new Set,Ae;if(s.profile){let re=performance.now();Ae=await z(de,ue,A.filePath,D,We);let _e=performance.now()-re,Le=te.relative(u,A.filePath)||A.filePath;console.log(`[stx:profile] ${Le} \u2192 ${_e.toFixed(2)}ms`)}else Ae=await z(de,ue,A.filePath,D,We);if(!E)Ae=await qe(Ae,{router:D.router});{let{interpolateScriptExpressions:re}=await import("./chunk-64vnwrkw.js");Ae=Ae.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(_e,Le,je)=>{if(!/function\s+__stx_setup_/.test(je))return _e;return`<script${Le}>${re(je,ue)}</script>`})}if(E)Ae=xe(Ae,{preserveHead:!0});if(le&&ye)await Y(A.filePath,Ae,We,D);let{extractStreamBoundaries:qn}=await import("./chunk-k5vytrbx.js"),nt=qn(ue),at=ue.__streamTemplates;if(at&&typeof at==="object"&&Object.keys(at).length>0){let re=ue.streamBoundaries||{},_e={...D,autoShell:!1},Le=Object.keys(at).map((Re)=>({id:Re,render:async()=>{let ct=typeof re[Re]==="function"?await re[Re]():void 0;return z(at[Re],{...ue,$boundary:ct},A.filePath,_e,new Set)}})),je=new Set(Le.map((Re)=>Re.id));nt=[...(nt||[]).filter((Re)=>!je.has(Re.id)),...Le]}if(nt&&nt.length>0)Oe.add(A.pattern);else nt=void 0;let Kt=Je(ue),Xt=Ye(ue);if(ye)W.set(A.filePath,{status:Kt,headers:Xt});return{route:A,content:Ae,status:Kt??Ce,headers:Xt,boundaries:nt}}catch(z){return console.error(`${e.red}Error building ${e.bright}${A.pattern}${e.reset}:`,z),null}},Fe=8,Ue=async()=>{ge.clear(),I.clear();for(let A=0;A<k.length;A+=Fe){let F=k.slice(A,A+Fe),z=await Promise.all(F.map((V)=>j(V)));for(let V of z)if(V)ge.set(V.route.pattern,V)}for(let A=0;A<M.length;A+=Fe){let F=M.slice(A,A+Fe),z=await Promise.all(F.map(({route:V})=>j(V)));for(let V of z)if(V)I.set(V.route.pattern,V)}return ge.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await Ue())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Lt(u);let et=i;try{if(et=await Ge(i),et!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${et} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let A=s.hmrPort||et+1;l=Et({wsPort:A,verbose:!1}),m=l.start(A)}let At=(A,F)=>{let V=`<script data-stx-route-params>(function(){var p=${JSON.stringify(F).replace(/</g,"\\u003C").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;if(A.includes("</head>"))return A.replace("</head>",`${V}</head>`);if(A.includes("<body"))return A.replace(/<body([^>]*)>/,`<body$1>${V}`);return V+A};console.log(`${e.blue}Starting server...${e.reset}`);let Dt=Yr({port:et,async fetch(A){let F=new URL(A.url),z=g?.publicDir||"public",V=te.join(u,z,F.pathname),ve=te.join(u,F.pathname),ze=te.join($e,F.pathname);if([V,ve,ze].some((D)=>w(D,u,S)))return new Response("Not Found",{status:404});let[qe,ee,Y]=await Promise.all([be.promises.stat(V).catch(()=>null),be.promises.stat(ve).catch(()=>null),be.promises.stat(ze).catch(()=>null)]);if(qe?.isFile()&&!w(V,u,S))return Nt(V);if(ee?.isFile()&&!w(ve,u,S))return Nt(ve);if(Y?.isFile()&&!w(ze,u,S))return Nt(ze);if(F.pathname.startsWith("/_stx/component/")){let D=decodeURIComponent(F.pathname.slice(16));if(D)try{let ye=`<${D} />`,le={...buildConfig,autoShell:!1},fe=await processDirectives(ye,{},te.join(u,"components",`${D}.stx`),le,new Set);return new Response(fe,{headers:{"Content-Type":"text/html"}})}catch(ye){return new Response(`<div class="stx-async-error">${ye.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(F.pathname==="/_stx/img"){let{handleImageRequest:D}=await import("./chunk-2pkx524z.js"),ye=await D(A,{publicDir:te.join(u,z),cacheDir:a(u,"cache","img")});if(ye)return ye}if(Q)try{let D=await Q.handleRequest(A);if(D.status!==404)return D}catch{}if(K[F.pathname])try{return await K[F.pathname](A)}catch(D){return new Response(JSON.stringify({error:D.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await R(A);if(q)return q;let G=Fn(F.pathname,k);if(G){let D=ge.get(G.route.pattern),ye=Oe.has(G.route.pattern);if(G.route.isDynamic&&Object.keys(G.params).length>0||ye){let le=await j(G.route,G.params);if(le)D=le}if(D){let le=D.status??200,fe=D.headers??{},Ce=(G.route.filePath?Xe(await Bun.file(G.route.filePath).text().catch(()=>"")):null)??{};if(Ce.validate){if(!await Ce.validate({params:G.params})){let Ne=await ne(404);if(Ne){let de=Ne;if(de=await f(de,u),c)de=Ve(de,m);return new Response(de,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(Ce.middleware){let Me=gt(F.pathname,G.params,Ce,F.search),Ne=mt(Me,null,A,{isServer:!0}),de=await ht(Ce.middleware,Ne);if(de.redirect){let ue=de.redirect.path,We=de.redirect.options.redirectCode||302,Ae=new Headers(de.responseHeaders);return Ae.set("Location",ue),new Response(null,{status:We,headers:Ae})}if(de.abort){let{statusCode:ue,message:We}=de.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${ue}</title></head><body><h1>Error ${ue}</h1><p>${We}</p></body></html>`,{status:ue,headers:{"Content-Type":"text/html"}})}if(Object.keys(de.state).length>0){let ue=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(de.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;D.content=D.content.replace("</head>",`${ue}</head>`)}}let J=D.content;if(E&&$o(A)){let Me=Ie(J),Ne=me(J),de=J.match(/<title[^>]*>([\s\S]*?)<\/title>/i),ue=de?Eo(de[1].trim()):"";if(Object.keys(G.params).length>0)J=At(J,G.params);J=await f(J,u);let We=g?.router?.container||"main";return J=ce(J,We),new Response(J,{status:le,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Me.layout,"X-STX-Layout-Group":Me.group,"X-STX-Runtime":Ne?"true":"false",...ue&&{"X-STX-Title":encodeURIComponent(ue)},[Pi]:Ns(),...T(),"Cache-Control":Be}})}if(E)J=Xn(E,J);if(Object.keys(G.params).length>0)J=At(J,G.params);if(J=await f(J,u),c)J=Ve(J,m);if(s.native)if(J.includes("<head>"))J=J.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 J="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+J;if(s.titlebarHidden)if(J.includes("<head>"))J=J.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 J=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${J}`;if(D.boundaries&&D.boundaries.length>0){let{renderStreamingPage:Me,streamToResponse:Ne}=await import("./chunk-k5vytrbx.js");return Ne(Me(J,D.boundaries,{timeoutMs:30000}),{status:le,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(J,{status:le,headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...fe}})}}if(M.length>0){let D=M.map((le)=>le.route),ye=Fn(F.pathname,D);if(ye){let le=I.get(ye.route.pattern);if(le){let fe=le.content;if(E)fe=Xn(E,fe);if(Object.keys(ye.params).length>0)fe=At(fe,ye.params);if(fe=await f(fe,u),c)fe=Ve(fe,m);return new Response(fe,{status:le.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:le}of H)if(le!=="/"&&F.pathname.startsWith(le)){let fe=I.get(le)||I.get(le+"/");if(fe){let Ce=fe.content;if(E)Ce=Xn(E,Ce);if(Ce=await f(Ce,u),c)Ce=Ve(Ce,m);return new Response(Ce,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(dt(F.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Se=ge.get("/");if(Se){let D=Se.content;if(D=await f(D,u),c)D=Ve(D,m);if(s.native)if(D.includes("<head>"))D=D.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else D="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+D;return new Response(D,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Ke=await ne(404);if(Ke){let D=Ke;if(D=await f(D,u),c)D=Ve(D,m);return new Response(D,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(A){let F=await ne(500);if(F)return new Response(F,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${A}
1430
+ ${A.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});if(console.clear(),console.log(`
1431
1431
  ${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
1432
1432
  ${e.bright}\u2192 ${e.cyan}http://localhost:${et}/${e.reset}`),c)console.log(`${e.dim} HMR: ws://localhost:${m}${e.reset}`);console.log(`
1433
- ${e.yellow}Routes:${e.reset}`);let _t=[...$r(k,p)];for(let{route:O}of D)_t.push(`${O.pattern}`);if(_t.forEach((O,F)=>{let W=F===_t.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${W}${e.reset}${O}`)}),console.log(`
1434
- Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(Dt.url.toString(),()=>{if(l)ht();Dt.stop()}),s.native){let O,F=te.join(C,"index.stx");if(be.existsSync(F)){let W=await Bun.file(F).text();O=Tt(W)}let z=g?.app?.window??{};await rt(et,{title:g?.app?.head?.title||te.basename(p)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!O,sidebarConfig:O})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let O=(ee)=>ee.startsWith("public/")||ee.startsWith("public\\"),F=(ee)=>{let Q=ee.toLowerCase();return Q.endsWith(".stx")||Q.endsWith(".html")||Q.endsWith(".md")},z=new Map,W=()=>{let ee=new Set([p,...g._layerGraph?.layers.map((Q)=>Q.root)??[],...g._layerGraph?.configDependencies.map((Q)=>te.dirname(Q))??[]].filter((Q)=>be.existsSync(Q)).map((Q)=>be.realpathSync(Q)));for(let Q of g._layerGraph?.layers??[])for(let V of Object.values(Q.resources)){if(!be.existsSync(V))continue;let K=be.realpathSync(V);if(![...ee].some((Se)=>K===Se||K.startsWith(`${Se}${te.sep}`)))ee.add(K)}for(let[Q,V]of z)if(!ee.has(Q))V.close(),z.delete(Q);for(let Q of ee)if(!z.has(Q)&&be.existsSync(Q))z.set(Q,be.watch(Q,{recursive:!0},(V,K)=>{ze(Q,V,K).catch((Se)=>console.error("[stx] Layer rebuild failed:",Se))}))},xe=Promise.resolve(),ze=(ee,Q,V)=>(xe=xe.catch(()=>{}).then(()=>qe(ee,Q,V)),xe),qe=async(ee,Q,V)=>{if(!V||Rt(V))return;if(Ct(V)){if(g._layerGraph){let K=await h(p);Object.assign(g,K),k.splice(0,k.length,...L(v,{pagesDir:x,pagesDirs:K._layerPageDirs?[C,...K._layerPageDirs.slice(1)]:void 0})),W()}if(O(V)){if(console.log(`${e.cyan}${V} changed${e.reset}`),c&&l)l.reload(V)}else if(F(V)){console.log(`${e.yellow}${V} changed, rebuilding...${e.reset}`),Ee.clear(),se();try{let{invalidateFileCache:K,templateCache:Se}=await import("./chunk-93na8hh0.js");K(te.resolve(ee,V)),Se.delete(te.resolve(ee,V))}catch{}if(M&&V){if(te.resolve(ee,V)===M||te.basename(M)===V){let Se=await zr(M,s.stxOptions||{});if(Se)E=Se}}if(await Ue(),await xn(p),c&&l)l.reload(V)}else{console.log(`${e.yellow}${V} changed, rebuilding...${e.reset}`),Ee.clear(),se();try{let{invalidateFileCache:K,templateCache:Se}=await import("./chunk-93na8hh0.js");K(te.resolve(ee,V)),Se.delete(te.resolve(ee,V))}catch{}if(await Ue(),c&&l)l.reload(V)}}else if($t(V)){if(console.log(`${e.cyan}CSS ${V} changed${e.reset}`),c&&l)l.updateCss(V)}};W(),process.on("SIGINT",()=>{for(let ee of z.values())ee.close();if(l)ht();Dt.stop(),process.exit(0)})}return!0}import Vt from"fs";import yt from"path";async function Qr(t){try{let i=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!i)return[];let d=i[1],c=[],l=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,m;while((m=l.exec(d))!==null){let p=m[1],h=m[2]||m[3]||m[4];if(!h)continue;let g={name:h},y=p.match(/@type\s+\{([^}]+)\}/i);if(y)g.type=y[1].trim();if(p.match(/@required/i))g.required=!0;let S=p.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)g.default=S[1].trim();let R=p.split(`
1435
- `).map((v)=>v.trim().replace(/^\*\s*/,"")).filter((v)=>!v.startsWith("@")&&v.length>0);g.description=R.join(" ").trim(),c.push(g)}if(c.length===0){let p=d.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(p){let g=p[1].split(",").map((y)=>y.trim()).filter(Boolean);for(let y of g){let[w]=y.split(":").map((S)=>S.trim());if(w)c.push({name:w})}}}return c}catch(s){return console.error(`Error extracting props from ${t}:`,s),[]}}async function Zr(t){try{let s=await Bun.file(t).text(),i=s.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||s.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(i)return i[1].split(`
1436
- `).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function eo(t,s=!1,i){let d=yt.basename(t,".stx"),c=await Qr(t),l=await Zr(t),m="";if(s&&i)m=`<${i}></${i}>`;else{let p=c.map((h)=>{if(h.type==="boolean")return`:${h.name}="true"`;return`${h.name}="value"`}).join(`
1437
- `);m=`<${d}
1438
- ${p}
1439
- />`}return{name:d,path:t,description:l,props:c,example:m,isWebComponent:s,tag:i}}async function un(t){try{if(!await r(t))return console.warn(`Components directory does not exist: ${t}`),[];let s=await Vt.promises.readdir(t,{withFileTypes:!0}),i=[];for(let d of s){let c=yt.join(t,d.name);if(d.isDirectory()){let l=await un(c);i.push(...l)}else if(d.isFile()&&d.name.endsWith(".stx"))i.push(c)}return i}catch(s){return console.error(`Error finding component files in ${t}:`,s),[]}}async function to(t,s){try{if(!await r(t))return[];let i=await un(t),d=[],c=new Map;if(s?.components?.length)for(let l of s.components)c.set(l.file,l);for(let l of i){let m=c.get(l),p=!!m,h=m?.tag,g=await eo(l,p,h);d.push(g)}return d}catch(i){return console.error("Error generating component docs:",i),[]}}async function no(t){try{if(!await r(t))return[];let s=await Vt.promises.readdir(t,{withFileTypes:!0}),i=[];for(let d of s){if(!d.isFile()||!d.name.endsWith(".stx"))continue;let c=yt.join(t,d.name),l=await Bun.file(c).text(),m=yt.basename(c,".stx"),p=l.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||l.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//),h=p?p[1].split(`
1433
+ ${e.yellow}Routes:${e.reset}`);let Mt=[...Rr(k,u)];for(let{route:A}of M)Mt.push(`${A.pattern}`);if(Mt.forEach((A,F)=>{let V=F===Mt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${V}${e.reset}${A}`)}),console.log(`
1434
+ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(Dt.url.toString(),()=>{if(l)lt();Dt.stop()}),s.native){let A,F=te.join(C,"index.stx");if(be.existsSync(F)){let V=await Bun.file(F).text();A=Tt(V)}let z=g?.app?.window??{};await rt(et,{title:g?.app?.head?.title||te.basename(u)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!A,sidebarConfig:A})}if(p){console.log(`${e.blue}Watching for changes...${e.reset}`);let A=(ee)=>ee.startsWith("public/")||ee.startsWith("public\\"),F=(ee)=>{let Y=ee.toLowerCase();return Y.endsWith(".stx")||Y.endsWith(".html")||Y.endsWith(".md")},z=new Map,V=()=>{let ee=new Set([u,...g._layerGraph?.layers.map((Y)=>Y.root)??[],...g._layerGraph?.configDependencies.map((Y)=>te.dirname(Y))??[]].filter((Y)=>be.existsSync(Y)).map((Y)=>be.realpathSync(Y)));for(let Y of g._layerGraph?.layers??[])for(let q of Object.values(Y.resources)){if(!be.existsSync(q))continue;let G=be.realpathSync(q);if(![...ee].some((Se)=>G===Se||G.startsWith(`${Se}${te.sep}`)))ee.add(G)}for(let[Y,q]of z)if(!ee.has(Y))q.close(),z.delete(Y);for(let Y of ee)if(!z.has(Y)&&be.existsSync(Y))z.set(Y,be.watch(Y,{recursive:!0},(q,G)=>{ze(Y,q,G).catch((Se)=>console.error("[stx] Layer rebuild failed:",Se))}))},ve=Promise.resolve(),ze=(ee,Y,q)=>(ve=ve.catch(()=>{}).then(()=>qe(ee,Y,q)),ve),qe=async(ee,Y,q)=>{if(!q||Rt(q))return;if(Ct(q)){if(g._layerGraph){let G=await h(u);Object.assign(g,G),k.splice(0,k.length,...L(v,{pagesDir:x,pagesDirs:G._layerPageDirs?[C,...G._layerPageDirs.slice(1)]:void 0})),V()}if(A(q)){if(console.log(`${e.cyan}${q} changed${e.reset}`),c&&l)l.reload(q)}else if(F(q)){console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),Te.clear(),oe();try{let{invalidateFileCache:G,templateCache:Se}=await import("./chunk-4j3fmxeg.js");G(te.resolve(ee,q)),Se.delete(te.resolve(ee,q))}catch{}if(_&&q){if(te.resolve(ee,q)===_||te.basename(_)===q){let Se=await Hr(_,s.stxOptions||{});if(Se)E=Se}}if(await Ue(),await kn(u),c&&l)l.reload(q)}else{console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),Te.clear(),oe();try{let{invalidateFileCache:G,templateCache:Se}=await import("./chunk-4j3fmxeg.js");G(te.resolve(ee,q)),Se.delete(te.resolve(ee,q))}catch{}if(await Ue(),c&&l)l.reload(q)}}else if($t(q)){if(console.log(`${e.cyan}CSS ${q} changed${e.reset}`),c&&l)l.updateCss(q)}};V(),process.on("SIGINT",()=>{for(let ee of z.values())ee.close();if(l)lt();Dt.stop(),process.exit(0)})}return!0}import Ut from"fs";import yt from"path";async function Qr(t){try{let i=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!i)return[];let p=i[1],c=[],l=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,m;while((m=l.exec(p))!==null){let u=m[1],h=m[2]||m[3]||m[4];if(!h)continue;let g={name:h},y=u.match(/@type\s+\{([^}]+)\}/i);if(y)g.type=y[1].trim();if(u.match(/@required/i))g.required=!0;let S=u.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)g.default=S[1].trim();let R=u.split(`
1435
+ `).map((v)=>v.trim().replace(/^\*\s*/,"")).filter((v)=>!v.startsWith("@")&&v.length>0);g.description=R.join(" ").trim(),c.push(g)}if(c.length===0){let u=p.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(u){let g=u[1].split(",").map((y)=>y.trim()).filter(Boolean);for(let y of g){let[w]=y.split(":").map((S)=>S.trim());if(w)c.push({name:w})}}}return c}catch(s){return console.error(`Error extracting props from ${t}:`,s),[]}}async function Zr(t){try{let s=await Bun.file(t).text(),i=s.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||s.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(i)return i[1].split(`
1436
+ `).map((p)=>p.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function eo(t,s=!1,i){let p=yt.basename(t,".stx"),c=await Qr(t),l=await Zr(t),m="";if(s&&i)m=`<${i}></${i}>`;else{let u=c.map((h)=>{if(h.type==="boolean")return`:${h.name}="true"`;return`${h.name}="value"`}).join(`
1437
+ `);m=`<${p}
1438
+ ${u}
1439
+ />`}return{name:p,path:t,description:l,props:c,example:m,isWebComponent:s,tag:i}}async function un(t){try{if(!await r(t))return console.warn(`Components directory does not exist: ${t}`),[];let s=await Ut.promises.readdir(t,{withFileTypes:!0}),i=[];for(let p of s){let c=yt.join(t,p.name);if(p.isDirectory()){let l=await un(c);i.push(...l)}else if(p.isFile()&&p.name.endsWith(".stx"))i.push(c)}return i}catch(s){return console.error(`Error finding component files in ${t}:`,s),[]}}async function to(t,s){try{if(!await r(t))return[];let i=await un(t),p=[],c=new Map;if(s?.components?.length)for(let l of s.components)c.set(l.file,l);for(let l of i){let m=c.get(l),u=!!m,h=m?.tag,g=await eo(l,u,h);p.push(g)}return p}catch(i){return console.error("Error generating component docs:",i),[]}}async function no(t){try{if(!await r(t))return[];let s=await Ut.promises.readdir(t,{withFileTypes:!0}),i=[];for(let p of s){if(!p.isFile()||!p.name.endsWith(".stx"))continue;let c=yt.join(t,p.name),l=await Bun.file(c).text(),m=yt.basename(c,".stx"),u=l.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||l.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//),h=u?u[1].split(`
1440
1440
  `).map((x)=>x.trim().replace(/^\*\s*/,"")).join(" ").trim():"",g=/@component\(\s*['"]([^'"]+)['"]/g,y=/<([A-Z][a-zA-Z0-9]*|[a-z]+-[a-z0-9-]+)(?:\s[^>]*)?\/?>|\{\{\s*slot\s*\}\}/g,w=new Set,S;while((S=g.exec(l))!==null)w.add(S[1]);while((S=y.exec(l))!==null)if(S[1]&&S[1]!=="slot")w.add(S[1]);let R=/@([a-z]+)(?:\s*\(|\s+|$)/g,v=new Set;while((S=R.exec(l))!==null)v.add(S[1]);i.push({name:m,path:c,description:h,components:[...w],directives:[...v]})}return i}catch(s){return console.error("Error generating template docs:",s),[]}}async function ro(t=[]){try{let s=[{name:"if",description:"Conditionally render content based on a condition",hasEndTag:!0,example:`@if(user.isLoggedIn)
1441
1441
  <p>Welcome, {{ user.name }}!</p>
1442
1442
  @endif`},{name:"else",description:"Provides an alternative if a condition is not met",hasEndTag:!1,example:`@if(user.isLoggedIn)
@@ -1457,9 +1457,9 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(Dt.
1457
1457
  <p>Page {{ page }}</p>
1458
1458
  @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
1459
1459
  {{ This will be displayed as-is }}
1460
- @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 i of t)s.push({name:i.name,description:i.description||"",hasEndTag:i.hasEndTag||!1,example:""});return s}catch(s){return console.error("Error generating directive docs:",s),[]}}function oo(t=[],s=[],i=[],d){let c=`# stx Documentation
1460
+ @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 i of t)s.push({name:i.name,description:i.description||"",hasEndTag:i.hasEndTag||!1,example:""});return s}catch(s){return console.error("Error generating directive docs:",s),[]}}function oo(t=[],s=[],i=[],p){let c=`# stx Documentation
1461
1461
 
1462
- `;if(d)c+=`${d}
1462
+ `;if(p)c+=`${p}
1463
1463
 
1464
1464
  `;if(t.length>0){c+=`## Components
1465
1465
 
@@ -1499,7 +1499,7 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(Dt.
1499
1499
 
1500
1500
  `,c+=`#### Example
1501
1501
 
1502
- `,c+="```html\n",c+=l.example,c+="\n```\n\n"}return c}function so(t=[],s=[],i=[],d){let c=`<!DOCTYPE html>
1502
+ `,c+="```html\n",c+=l.example,c+="\n```\n\n"}return c}function so(t=[],s=[],i=[],p){let c=`<!DOCTYPE html>
1503
1503
  <html lang="en">
1504
1504
  <head>
1505
1505
  <meta charset="UTF-8">
@@ -1542,7 +1542,7 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(Dt.
1542
1542
  </head>
1543
1543
  <body>
1544
1544
  <h1>stx Documentation</h1>
1545
- `;if(d)c+=`<div>${d}</div>`;if(t.length>0){c+="<h2>Components</h2>";for(let l of t){if(c+=`<h3>${l.name}</h3>`,l.description)c+=`<p>${l.description}</p>`;if(l.isWebComponent)c+=`<p><strong>Web Component Tag:</strong> <code>${l.tag}</code></p>`;if(l.props.length>0){c+="<h4>Properties</h4>",c+=`<table>
1545
+ `;if(p)c+=`<div>${p}</div>`;if(t.length>0){c+="<h2>Components</h2>";for(let l of t){if(c+=`<h3>${l.name}</h3>`,l.description)c+=`<p>${l.description}</p>`;if(l.isWebComponent)c+=`<p><strong>Web Component Tag:</strong> <code>${l.tag}</code></p>`;if(l.props.length>0){c+="<h4>Properties</h4>",c+=`<table>
1546
1546
  <thead>
1547
1547
  <tr>
1548
1548
  <th>Name</th>
@@ -1570,23 +1570,23 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Qe(Dt.
1570
1570
  <td>@${l.name}</td>
1571
1571
  <td>${l.description||"-"}</td>
1572
1572
  <td>${l.hasEndTag?"Yes":"No"}</td>
1573
- </tr>`;c+="</tbody></table>";for(let l of i)if(l.example)c+=`<h3>@${l.name}</h3>`,c+=`<p>${l.description||""}</p>`,c+="<h4>Example</h4>",c+=`<pre><code>${l.example.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}</code></pre>`}return c+="</body></html>",c}function io(t=[],s=[],i=[],d){return JSON.stringify({components:t,templates:s,directives:i,extraContent:d||""},null,2)}async function ao(t){try{let{componentsDir:s,templatesDir:i,webComponentsConfig:d,customDirectives:c,config:l}=t;if(!l.enabled)return!1;let m=l.outputDir||"docs";if(await Vt.promises.mkdir(m,{recursive:!0}),console.log("Generating documentation..."),s)console.log(`Components directory: ${s}`);if(i)console.log(`Templates directory: ${i}`);console.log(`Output directory: ${m}`);let p=[];if(l.components!==!1&&s)console.log("Generating component documentation..."),p=await to(s,d),console.log(`Found ${p.length} components`);let h=[];if(l.templates!==!1&&i)console.log("Generating template documentation..."),h=await no(i),console.log(`Found ${h.length} templates`);let g=[];if(l.directives!==!1)console.log("Generating directive documentation..."),g=await ro(c),console.log(`Found ${g.length} directives`);let y=l.format||"markdown",w=l.extraContent,S="",R="";switch(y){case"markdown":S=oo(p,h,g,w),R="md";break;case"html":S=so(p,h,g,w),R="html";break;case"json":S=io(p,h,g,w),R="json";break;default:throw Error(`Unsupported documentation format: ${y}`)}let v=yt.join(m,`stx-docs.${R}`);return await Bun.write(v,S),console.log(`Documentation generated: ${v}`),!0}catch(s){return console.error("Error generating documentation:",s),!1}}async function go(t){let s={enabled:!0,outputDir:t.output||"docs",format:t.format||"markdown",components:t.components!==!1,templates:t.templates!==!1,directives:t.directives!==!1,extraContent:t.extraContent},i=t.componentsDir||P.componentsDir,d=t.templatesDir||".";return ao({componentsDir:i,templatesDir:d,webComponentsConfig:P.webComponents,customDirectives:P.customDirectives,config:s})}var mn={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0};function Or(t,s={}){let i={...mn,...s};if(t.trim()==="")return`
1574
- `;let d=t;if(i.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=bo(d,i),d=So(d,i),d=xo(d,i),i.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,""),d=d.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(d=d.replace(/\r\n/g,`
1573
+ </tr>`;c+="</tbody></table>";for(let l of i)if(l.example)c+=`<h3>@${l.name}</h3>`,c+=`<p>${l.description||""}</p>`,c+="<h4>Example</h4>",c+=`<pre><code>${l.example.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}</code></pre>`}return c+="</body></html>",c}function io(t=[],s=[],i=[],p){return JSON.stringify({components:t,templates:s,directives:i,extraContent:p||""},null,2)}async function ao(t){try{let{componentsDir:s,templatesDir:i,webComponentsConfig:p,customDirectives:c,config:l}=t;if(!l.enabled)return!1;let m=l.outputDir||"docs";if(await Ut.promises.mkdir(m,{recursive:!0}),console.log("Generating documentation..."),s)console.log(`Components directory: ${s}`);if(i)console.log(`Templates directory: ${i}`);console.log(`Output directory: ${m}`);let u=[];if(l.components!==!1&&s)console.log("Generating component documentation..."),u=await to(s,p),console.log(`Found ${u.length} components`);let h=[];if(l.templates!==!1&&i)console.log("Generating template documentation..."),h=await no(i),console.log(`Found ${h.length} templates`);let g=[];if(l.directives!==!1)console.log("Generating directive documentation..."),g=await ro(c),console.log(`Found ${g.length} directives`);let y=l.format||"markdown",w=l.extraContent,S="",R="";switch(y){case"markdown":S=oo(u,h,g,w),R="md";break;case"html":S=so(u,h,g,w),R="html";break;case"json":S=io(u,h,g,w),R="json";break;default:throw Error(`Unsupported documentation format: ${y}`)}let v=yt.join(m,`stx-docs.${R}`);return await Bun.write(v,S),console.log(`Documentation generated: ${v}`),!0}catch(s){return console.error("Error generating documentation:",s),!1}}async function mo(t){let s={enabled:!0,outputDir:t.output||"docs",format:t.format||"markdown",components:t.components!==!1,templates:t.templates!==!1,directives:t.directives!==!1,extraContent:t.extraContent},i=t.componentsDir||P.componentsDir,p=t.templatesDir||".";return ao({componentsDir:i,templatesDir:p,webComponentsConfig:P.webComponents,customDirectives:P.customDirectives,config:s})}var mn={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0};function Dr(t,s={}){let i={...mn,...s};if(t.trim()==="")return`
1574
+ `;let p=t;if(i.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,"");if(p=uo(p,i),p=So(p,i),p=xo(p,i),i.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,""),p=p.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(p=p.replace(/\r\n/g,`
1575
1575
  `).replace(/\r/g,`
1576
- `),!d.endsWith(`
1577
- `))d+=`
1578
- `;return d}function mo(t,s={}){let i={...mn,...s};if(t.trim()==="")return`
1579
- `;let d=t;if(d=d.replace(/^( *)```(html|stx)\n([\s\S]*?)^( *)```/gm,(c,l,m,p,h)=>{let g=p.split(`
1576
+ `),!p.endsWith(`
1577
+ `))p+=`
1578
+ `;return p}function ho(t,s={}){let i={...mn,...s};if(t.trim()==="")return`
1579
+ `;let p=t;if(p=p.replace(/^( *)```(html|stx)\n([\s\S]*?)^( *)```/gm,(c,l,m,u,h)=>{let g=u.split(`
1580
1580
  `),y=g.filter((x)=>x.trim().length>0);if(y.length===0)return c;let w=Math.min(...y.map((x)=>{let C=x.match(/^( *)/);return C?C[1].length:0})),S=g.map((x)=>{if(x.trim().length===0)return"";return x.substring(w)}).join(`
1581
- `),v=Or(S,i).trimEnd().split(`
1581
+ `),v=Dr(S,i).trimEnd().split(`
1582
1582
  `).map((x)=>{if(x.trim().length===0)return"";return l+x}).join(`
1583
1583
  `);return`${l}\`\`\`${m}
1584
1584
  ${v}
1585
- ${l}\`\`\``}),i.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=d.replace(/\r\n/g,`
1585
+ ${l}\`\`\``}),i.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,"");if(p=p.replace(/\r\n/g,`
1586
1586
  `).replace(/\r/g,`
1587
- `),!d.endsWith(`
1588
- `))d+=`
1589
- `;return d}function lo(t){let s=t,i=[],d="__PROTECTED_BLOCK_";return s=s.replace(/(<(?:pre|code|textarea)[^>]*>)([\s\S]*?)(<\/(?:pre|code|textarea)>)/gi,(c)=>{let l=i.length;return i.push(c),`${d}${l}__`}),s=s.replace(/(@(?:if|foreach|for|while|unless|section|component|slot|push|prepend|error|auth|guest|can)(?:\((?:[^()'"]|'[^']*'|"[^"]*"|\((?:[^()'"]|'[^']*'|"[^"]*")*\))*\))?)/g,`
1587
+ `),!p.endsWith(`
1588
+ `))p+=`
1589
+ `;return p}function lo(t){let s=t,i=[],p="__PROTECTED_BLOCK_";return s=s.replace(/(<(?:pre|code|textarea)[^>]*>)([\s\S]*?)(<\/(?:pre|code|textarea)>)/gi,(c)=>{let l=i.length;return i.push(c),`${p}${l}__`}),s=s.replace(/(@(?:if|foreach|for|while|unless|section|component|slot|push|prepend|error|auth|guest|can)(?:\((?:[^()'"]|'[^']*'|"[^"]*"|\((?:[^()'"]|'[^']*'|"[^"]*")*\))*\))?)/g,`
1590
1590
  $1
1591
1591
  `),s=s.replace(/(@end\w+)/g,`
1592
1592
  $1
@@ -1594,16 +1594,16 @@ $1
1594
1594
  $1
1595
1595
  `),s=s.replace(/(@(?:csrf|method|include|extends|yield|stack|vite|asset)(?:\([^)]*\))?)/g,`
1596
1596
  $1
1597
- `),s=s.replace(/(?<=>)(<(?!\/)[^>]+>)/g,(c,l,m,p)=>{let h=p.substring(m+c.length,Math.min(p.length,m+c.length+20)),g=c.match(/<(\w+)/)?.[1];if(g&&h.match(new RegExp(`^</${g}>`)))return c;return`
1598
- ${c}`}),s=s.replace(/(>)(<\/)/g,(c,l,m,p,h)=>{let g=h.substring(Math.max(0,p-50),p),w=h.substring(p+c.length,Math.min(h.length,p+c.length+20)).match(/^(\w+)>/)?.[1],S=g.match(/<(\w+)[^>]*$/)?.[1];if(S&&w&&S===w)return c;return`${l}
1599
- ${m}`}),s=s.replace(/(<\/[^>]+>)(?=<|$)/g,(c,l,m,p)=>{let h=p.substring(Math.max(0,m-20),m),g=c.match(/<\/(\w+)>/)?.[1],y=new RegExp(`<${g}[^>]*>$`);if(g&&h.match(y))return c;return`${c}
1600
- `}),s=s.replace(new RegExp(`${d}(\\d+)__`,"g"),(c,l)=>i[Number.parseInt(l,10)]),s=s.replace(/\n{2,}/g,`
1597
+ `),s=s.replace(/(?<=>)(<(?!\/)[^>]+>)/g,(c,l,m,u)=>{let h=u.substring(m+c.length,Math.min(u.length,m+c.length+20)),g=c.match(/<(\w+)/)?.[1];if(g&&h.match(new RegExp(`^</${g}>`)))return c;return`
1598
+ ${c}`}),s=s.replace(/(>)(<\/)/g,(c,l,m,u,h)=>{let g=h.substring(Math.max(0,u-50),u),w=h.substring(u+c.length,Math.min(h.length,u+c.length+20)).match(/^(\w+)>/)?.[1],S=g.match(/<(\w+)[^>]*$/)?.[1];if(S&&w&&S===w)return c;return`${l}
1599
+ ${m}`}),s=s.replace(/(<\/[^>]+>)(?=<|$)/g,(c,l,m,u)=>{let h=u.substring(Math.max(0,m-20),m),g=c.match(/<\/(\w+)>/)?.[1],y=new RegExp(`<${g}[^>]*>$`);if(g&&h.match(y))return c;return`${c}
1600
+ `}),s=s.replace(new RegExp(`${p}(\\d+)__`,"g"),(c,l)=>i[Number.parseInt(l,10)]),s=s.replace(/\n{2,}/g,`
1601
1601
  `),s=s.split(`
1602
1602
  `).map((c)=>c.trim()).join(`
1603
- `),s=s.replace(/^\n+/,"").replace(/\n+$/,""),s}function bo(t,s){let d=lo(t).split(`
1604
- `),c=[],l=0,m=!1,p=s.useTabs?"\t":" ".repeat(s.indentSize);for(let h=0;h<d.length;h++){let g=d[h],y=g.trim();if(y===""){c.push("");continue}let w=y.match(/<script\b/i),S=y.match(/<\/script>/i);if(m&&!S){c.push(g);continue}let R=y===">";if(fn(y)&&!y.startsWith("<")&&!y.startsWith("@")){c.push(p.repeat(l)+y);continue}let v=y.startsWith("@end"),x=y.startsWith("@else")||y.startsWith("@elseif"),C=y.startsWith("@")&&wo(y),k=y.startsWith("<!DOCTYPE")||y.startsWith("<!doctype"),H=y.startsWith("<!--"),D=y.startsWith("</"),_=y.startsWith("<")&&!D&&!H&&!k,E=y.includes("/>")||vo(y),M=fn(y);if(D||v)l=Math.max(0,l-1);let B=x?Math.max(0,l-1):l;if(R)c.push(g);else c.push(p.repeat(B)+y);if(_&&!E&&!M&&!R||C)l++;if(w)m=!0;if(S)m=!1}return c.join(`
1605
- `)}function xo(t,s){if(t=t.replace(/@(if|elseif|foreach|for|while)\s*\(\s*([^)]+)\s*\)/g,(i,d,c)=>{let l=c.trim().replace(/\s+/g," ");return`@${d}(${l})`}),t=t.replace(/@(csrf|method)\s*\(\s*([^)]*)\s*\)/g,(i,d,c)=>{if(c.trim()==="")return`@${d}`;return`@${d}(${c.trim()})`}),s.normalizeWhitespace)t=t.replace(/\{\{\s*([^}]+)\s*\}\}/g,(i,d)=>`{{ ${d.trim()} }}`),t=t.replace(/\{!!\s*([^!]+)\s*!!\}/g,(i,d)=>`{!! ${d.trim()} !!}`);return t}function vo(t){let s=["br","hr","img","input","meta","link","area","base","col","embed","source","track","wbr"];if(t.includes("/>"))return!0;let i=t.match(/<(\w+)/);if(i){let d=i[1];return s.includes(d.toLowerCase())}return!1}function fn(t){return/<(\w+)(?:\s[^>]*)?>[\s\S]*?<\/\1>/.test(t)}function wo(t){let s=["if","unless","foreach","for","while","section","push","component","slot","markdown","wrap","error"];for(let i of s)if(t.startsWith(`@${i}`))return!t.includes(`@end${i}`);return!1}function So(t,s){if(!s.sortAttributes)return t;return t.replace(/<(\w+)([^>]*)>/g,(i,d,c)=>{if(!c.trim())return i;if(c.includes("<")||c.includes(`
1606
- `)||c.includes("@"))return i;let l=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,m=[],p;while((p=l.exec(c))!==null)m.push({name:p[1],value:p[2]});m.sort((g,y)=>{if(g.name==="id")return-1;if(y.name==="id")return 1;if(g.name==="class")return-1;if(y.name==="class")return 1;return g.name.localeCompare(y.name)});let h=m.map((g)=>g.value?`${g.name}=${g.value}`:g.name).join(" ");return`<${d}${h?` ${h}`:""}>`})}import gn from"fs";import qt from"path";async function ho(t="index.stx",s={}){try{let i=s.force||!1,d=qt.resolve(process.cwd(),t);if(await Bun.file(d).exists()){if(!i)throw Error(`File ${t} already exists. Use --force to overwrite.`);console.warn(`File ${t} already exists. Overwriting...`)}let c=qt.dirname(d);if(!gn.existsSync(c))gn.mkdirSync(c,{recursive:!0});let l;if(s.template){let m=qt.resolve(process.cwd(),s.template);if(!await Bun.file(m).exists())throw Error(`Template file ${s.template} does not exist.`);if(!m.endsWith(".stx"))console.warn(`Warning: Template file ${s.template} does not have a .stx extension. Using it anyway.`);l=await Bun.file(m).text(),console.warn(`Using template from ${s.template}`)}else if(s.preset)l=hn(s.preset),console.warn(`Using '${s.preset}' preset template`);else l=hn("basic");return await Bun.write(d,l),console.warn(`Created new stx file: ${t}`),!0}catch(i){return console.error(`Error creating file: ${i instanceof Error?i.message:String(i)}`),!1}}function hn(t){switch(t){case"basic":return vn();case"component":return ko();case"layout":return $o();case"blog":return Co();case"api":return Ro();case"app":return Po();default:return vn()}}function vn(){return`<script>
1603
+ `),s=s.replace(/^\n+/,"").replace(/\n+$/,""),s}function uo(t,s){let p=lo(t).split(`
1604
+ `),c=[],l=0,m=!1,u=s.useTabs?"\t":" ".repeat(s.indentSize);for(let h=0;h<p.length;h++){let g=p[h],y=g.trim();if(y===""){c.push("");continue}let w=y.match(/<script\b/i),S=y.match(/<\/script>/i);if(m&&!S){c.push(g);continue}let R=y===">";if(fn(y)&&!y.startsWith("<")&&!y.startsWith("@")){c.push(u.repeat(l)+y);continue}let v=y.startsWith("@end"),x=y.startsWith("@else")||y.startsWith("@elseif"),C=y.startsWith("@")&&wo(y),k=y.startsWith("<!DOCTYPE")||y.startsWith("<!doctype"),H=y.startsWith("<!--"),M=y.startsWith("</"),I=y.startsWith("<")&&!M&&!H&&!k,E=y.includes("/>")||vo(y),_=fn(y);if(M||v)l=Math.max(0,l-1);let B=x?Math.max(0,l-1):l;if(R)c.push(g);else c.push(u.repeat(B)+y);if(I&&!E&&!_&&!R||C)l++;if(w)m=!0;if(S)m=!1}return c.join(`
1605
+ `)}function xo(t,s){if(t=t.replace(/@(if|elseif|foreach|for|while)\s*\(\s*([^)]+)\s*\)/g,(i,p,c)=>{let l=c.trim().replace(/\s+/g," ");return`@${p}(${l})`}),t=t.replace(/@(csrf|method)\s*\(\s*([^)]*)\s*\)/g,(i,p,c)=>{if(c.trim()==="")return`@${p}`;return`@${p}(${c.trim()})`}),s.normalizeWhitespace)t=t.replace(/\{\{\s*([^}]+)\s*\}\}/g,(i,p)=>`{{ ${p.trim()} }}`),t=t.replace(/\{!!\s*([^!]+)\s*!!\}/g,(i,p)=>`{!! ${p.trim()} !!}`);return t}function vo(t){let s=["br","hr","img","input","meta","link","area","base","col","embed","source","track","wbr"];if(t.includes("/>"))return!0;let i=t.match(/<(\w+)/);if(i){let p=i[1];return s.includes(p.toLowerCase())}return!1}function fn(t){return/<(\w+)(?:\s[^>]*)?>[\s\S]*?<\/\1>/.test(t)}function wo(t){let s=["if","unless","foreach","for","while","section","push","component","slot","markdown","wrap","error"];for(let i of s)if(t.startsWith(`@${i}`))return!t.includes(`@end${i}`);return!1}function So(t,s){if(!s.sortAttributes)return t;return t.replace(/<(\w+)([^>]*)>/g,(i,p,c)=>{if(!c.trim())return i;if(c.includes("<")||c.includes(`
1606
+ `)||c.includes("@"))return i;let l=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,m=[],u;while((u=l.exec(c))!==null)m.push({name:u[1],value:u[2]});m.sort((g,y)=>{if(g.name==="id")return-1;if(y.name==="id")return 1;if(g.name==="class")return-1;if(y.name==="class")return 1;return g.name.localeCompare(y.name)});let h=m.map((g)=>g.value?`${g.name}=${g.value}`:g.name).join(" ");return`<${p}${h?` ${h}`:""}>`})}import gn from"fs";import Wt from"path";async function yo(t="index.stx",s={}){try{let i=s.force||!1,p=Wt.resolve(process.cwd(),t);if(await Bun.file(p).exists()){if(!i)throw Error(`File ${t} already exists. Use --force to overwrite.`);console.warn(`File ${t} already exists. Overwriting...`)}let c=Wt.dirname(p);if(!gn.existsSync(c))gn.mkdirSync(c,{recursive:!0});let l;if(s.template){let m=Wt.resolve(process.cwd(),s.template);if(!await Bun.file(m).exists())throw Error(`Template file ${s.template} does not exist.`);if(!m.endsWith(".stx"))console.warn(`Warning: Template file ${s.template} does not have a .stx extension. Using it anyway.`);l=await Bun.file(m).text(),console.warn(`Using template from ${s.template}`)}else if(s.preset)l=hn(s.preset),console.warn(`Using '${s.preset}' preset template`);else l=hn("basic");return await Bun.write(p,l),console.warn(`Created new stx file: ${t}`),!0}catch(i){return console.error(`Error creating file: ${i instanceof Error?i.message:String(i)}`),!1}}function hn(t){switch(t){case"basic":return yn();case"component":return ko();case"layout":return Co();case"blog":return Ro();case"api":return Po();case"app":return Oo();default:return yn()}}function yn(){return`<script>
1607
1607
  const title = "My stx Page"
1608
1608
  const description = "A page built with stx"
1609
1609
  const features = [
@@ -1673,7 +1673,7 @@ const features = [
1673
1673
  .card.collapsed .card__toggle { transform: rotate(-90deg); }
1674
1674
  .card__body { padding: 1rem; }
1675
1675
  .card.collapsed .card__body { display: none; }
1676
- </style>`}function $o(){return`<!DOCTYPE html>
1676
+ </style>`}function Co(){return`<!DOCTYPE html>
1677
1677
  <html lang="en">
1678
1678
  <head>
1679
1679
  <meta charset="UTF-8">
@@ -1724,7 +1724,7 @@ const features = [
1724
1724
 
1725
1725
  @yield('scripts')
1726
1726
  </body>
1727
- </html>`}function Co(){return`<script>
1727
+ </html>`}function Ro(){return`<script>
1728
1728
  // Article metadata
1729
1729
  const title = "My Blog Post"
1730
1730
  const author = "Your Name"
@@ -1769,7 +1769,7 @@ const features = [
1769
1769
  <p>Wrap up your thoughts here.</p>
1770
1770
  </div>
1771
1771
  </article>
1772
- @endsection`}function Ro(){return`<script>
1772
+ @endsection`}function Po(){return`<script>
1773
1773
  // API endpoint configuration
1774
1774
  const endpoint = "/api/data"
1775
1775
  const method = "GET"
@@ -1804,7 +1804,7 @@ const features = [
1804
1804
  }
1805
1805
  @else
1806
1806
  {{ JSON.stringify(data, null, 2) }}
1807
- @endif`}function Po(){return`<!DOCTYPE html>
1807
+ @endif`}function Oo(){return`<!DOCTYPE html>
1808
1808
  <html lang="en">
1809
1809
  <head>
1810
1810
  <meta charset="UTF-8">
@@ -2029,5 +2029,5 @@ const features = [
2029
2029
  })();
2030
2030
  </script>
2031
2031
  </body>
2032
- </html>`}var yo="f9c3713";function la(t){return t}function ua(t){return t}function uo(t,s){let i=[],d=`${s}=`;for(let c=0;c<t.length;c++){let l=t[c];if(l.startsWith(d)){let m=l.slice(d.length);if(m)i.push(m);continue}if(l===s){let m=t[c+1];if(m!==void 0&&!m.startsWith("-"))i.push(m),c++}}return i}import Me from"fs";import ke from"path";function En(t){try{return Me.statSync(t).mtimeMs}catch{return null}}function Ot(t,s){let i=Math.max(0,Math.round((s-t)/1000));if(i<60)return`${i}s ago`;if(i<3600)return`${Math.round(i/60)}m ago`;return`${Math.round(i/3600)}h ago`}function Di(t,s){try{return globalThis.Bun?.resolveSync(t,s)??null}catch{return null}}function Pn(t,s="stx"){let i=ke.resolve(t);for(let d=0;d<10;d++){let c=ke.join(i,"pantry","@stacksjs",s);if(Me.existsSync(c))return c;let l=ke.dirname(i);if(l===i)break;i=l}return null}var An=["@stacksjs/stx","bun-plugin-stx"];function Mi(t){try{let s=Me.readFileSync(ke.join(t,"package.json"),"utf8"),i=JSON.parse(s)?.version;return typeof i==="string"?i:null}catch{return null}}function _i(t,s=6){let i=ke.resolve(t),d=[],c=new Set;function l(p,h){if(h>s)return;let g;try{g=Me.realpathSync(p)}catch{return}if(c.has(g))return;c.add(g);for(let w of An){let S=ke.join(p,w),R=Mi(S);if(R!==null)d.push({name:w,version:R,dir:ke.relative(i,S)||S,nested:h>0})}let y;try{y=Me.readdirSync(p,{withFileTypes:!0})}catch{return}for(let w of y){if(!w.isDirectory()&&!w.isSymbolicLink())continue;if(w.name===".bin"||w.name===".cache")continue;let S=ke.join(p,w.name);if(w.name.startsWith("@")){let v;try{v=Me.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let x of v){let C=ke.join(S,x.name,"node_modules");if(Me.existsSync(C))l(C,h+1)}continue}let R=ke.join(S,"node_modules");if(Me.existsSync(R))l(R,h+1)}}let m=ke.join(i,"node_modules");if(Me.existsSync(m))l(m,0);return d}function Li(t){let s=[];for(let i of An){let d=t.filter((m)=>m.name===i);if(d.length<=1)continue;let c=[...new Set(d.map((m)=>m.version))],l=d.map((m)=>`${m.version} at ${m.dir}`).join("; ");if(c.length===1){s.push({name:`${i} copies`,status:"info",detail:`${d.length} copies, all ${c[0]} \u2014 duplicated but in agreement`});continue}s.push({name:`${i} copies disagree`,status:"error",detail:`${c.length} versions installed, so which one runs depends on who imports it: ${l}`,fix:`remove the nested copies, or add an overrides entry pinning ${i}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${i}/package.json' -exec grep -H '"version"' {} +`})}return s}async function Dr(t={}){let s=t.cwd?ke.resolve(t.cwd):process.cwd(),i=t.resolve??Di,d=Date.now(),c=[],l=i("@stacksjs/stx",s);c.push(l?{name:"@stacksjs/stx resolves to",status:"ok",detail:l}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let m=i("bun-plugin-stx",s);if(m)c.push({name:"bun-plugin-stx resolves to",status:"ok",detail:m});for(let h of Li(_i(s)))c.push(h);let p=Pn(s,"stx");if(!p)c.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let h=ke.join(p,"src/signals.ts"),g=[ke.join(p,"dist/index.js"),ke.join(p,"dist/signals.js")].find((v)=>Me.existsSync(v))||null,y=En(h),w=g?En(g):null;if(y==null)c.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${p} but no src/signals.ts to compare`});else if(w==null)c.push({name:"pantry dist freshness",status:"error",detail:"pantry has src but no built dist \u2014 the dev server will resolve nothing (or a stale copy elsewhere)",fix:`cd ${p} && bun build.ts`});else if(w<y){let v=Math.round((y-w)/1000);c.push({name:"pantry dist freshness",status:"error",detail:`dist (${Ot(w,d)}) is OLDER than src/signals.ts (${Ot(y,d)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${p} && bun build.ts`})}else c.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Ot(y,d)}, dist ${Ot(w,d)})`});let S=ke.join(s,"node_modules/@stacksjs/stx"),R=null;try{R=Me.lstatSync(S)}catch{R=null}if(!R)c.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(R.isSymbolicLink()){let v=null;try{v=Me.realpathSync(S)}catch{}let x=(()=>{try{return Me.realpathSync(p)}catch{return p}})();c.push(v===x?{name:"node_modules \u2192 pantry",status:"ok",detail:"symlinked to pantry"}:{name:"node_modules \u2192 pantry",status:"warn",detail:`symlinked to ${v||"(dangling)"}, not pantry`})}else c.push({name:"node_modules \u2192 pantry",status:"warn",detail:"is a real directory, NOT symlinked to pantry \u2014 edits to pantry src/dist won't be resolved",fix:"rm -rf node_modules/@stacksjs/stx && ln -s ../../pantry/@stacksjs/stx node_modules/@stacksjs/stx"})}if(c.push({name:"dev runtime cache",status:"info",detail:"cleared automatically on source edits by the dev watcher (clearDevCaches, #1745 item C)"}),t.generateRuntime)try{let g=t.generateRuntime().length;c.push(g>1000?{name:"signals runtime",status:"ok",detail:`generated ${g.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${g} chars \u2014 suspiciously short`})}catch(h){c.push({name:"signals runtime",status:"error",detail:`failed to generate: ${h.message}`})}return{checks:c,ok:!c.some((h)=>h.status==="error")}}function Nr(t){let s={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},i=["stx runtime resolution:"];for(let d of t.checks)if(i.push(` ${s[d.status]} ${d.name}: ${d.detail}`),d.fix)i.push(` \u2192 ${d.fix}`);return i.push(""),i.push(t.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),i.join(`
2033
- `)}export{uo,po,fo,go,Or,mo,ho,yo,la,ua,Dr,Nr,zn,Hn,Vn};
2032
+ </html>`}var bo="f9c3713";function da(t){return t}function ua(t){return t}function po(t,s){let i=[],p=`${s}=`;for(let c=0;c<t.length;c++){let l=t[c];if(l.startsWith(p)){let m=l.slice(p.length);if(m)i.push(m);continue}if(l===s){let m=t[c+1];if(m!==void 0&&!m.startsWith("-"))i.push(m),c++}}return i}import De from"fs";import ke from"path";function En(t){try{return De.statSync(t).mtimeMs}catch{return null}}function Ot(t,s){let i=Math.max(0,Math.round((s-t)/1000));if(i<60)return`${i}s ago`;if(i<3600)return`${Math.round(i/60)}m ago`;return`${Math.round(i/3600)}h ago`}function Di(t,s){try{return globalThis.Bun?.resolveSync(t,s)??null}catch{return null}}function Pn(t,s="stx"){let i=ke.resolve(t);for(let p=0;p<10;p++){let c=ke.join(i,"pantry","@stacksjs",s);if(De.existsSync(c))return c;let l=ke.dirname(i);if(l===i)break;i=l}return null}var On=["@stacksjs/stx","bun-plugin-stx"];function Mi(t){try{let s=De.readFileSync(ke.join(t,"package.json"),"utf8"),i=JSON.parse(s)?.version;return typeof i==="string"?i:null}catch{return null}}function _i(t,s=6){let i=ke.resolve(t),p=[],c=new Set;function l(u,h){if(h>s)return;let g;try{g=De.realpathSync(u)}catch{return}if(c.has(g))return;c.add(g);for(let w of On){let S=ke.join(u,w),R=Mi(S);if(R!==null)p.push({name:w,version:R,dir:ke.relative(i,S)||S,nested:h>0})}let y;try{y=De.readdirSync(u,{withFileTypes:!0})}catch{return}for(let w of y){if(!w.isDirectory()&&!w.isSymbolicLink())continue;if(w.name===".bin"||w.name===".cache")continue;let S=ke.join(u,w.name);if(w.name.startsWith("@")){let v;try{v=De.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let x of v){let C=ke.join(S,x.name,"node_modules");if(De.existsSync(C))l(C,h+1)}continue}let R=ke.join(S,"node_modules");if(De.existsSync(R))l(R,h+1)}}let m=ke.join(i,"node_modules");if(De.existsSync(m))l(m,0);return p}function Li(t){let s=[];for(let i of On){let p=t.filter((m)=>m.name===i);if(p.length<=1)continue;let c=[...new Set(p.map((m)=>m.version))],l=p.map((m)=>`${m.version} at ${m.dir}`).join("; ");if(c.length===1){s.push({name:`${i} copies`,status:"info",detail:`${p.length} copies, all ${c[0]} \u2014 duplicated but in agreement`});continue}s.push({name:`${i} copies disagree`,status:"error",detail:`${c.length} versions installed, so which one runs depends on who imports it: ${l}`,fix:`remove the nested copies, or add an overrides entry pinning ${i}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${i}/package.json' -exec grep -H '"version"' {} +`})}return s}async function Nr(t={}){let s=t.cwd?ke.resolve(t.cwd):process.cwd(),i=t.resolve??Di,p=Date.now(),c=[],l=i("@stacksjs/stx",s);c.push(l?{name:"@stacksjs/stx resolves to",status:"ok",detail:l}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let m=i("bun-plugin-stx",s);if(m)c.push({name:"bun-plugin-stx resolves to",status:"ok",detail:m});for(let h of Li(_i(s)))c.push(h);let u=Pn(s,"stx");if(!u)c.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let h=ke.join(u,"src/signals.ts"),g=[ke.join(u,"dist/index.js"),ke.join(u,"dist/signals.js")].find((v)=>De.existsSync(v))||null,y=En(h),w=g?En(g):null;if(y==null)c.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${u} but no src/signals.ts to compare`});else if(w==null)c.push({name:"pantry dist freshness",status:"error",detail:"pantry has src but no built dist \u2014 the dev server will resolve nothing (or a stale copy elsewhere)",fix:`cd ${u} && bun build.ts`});else if(w<y){let v=Math.round((y-w)/1000);c.push({name:"pantry dist freshness",status:"error",detail:`dist (${Ot(w,p)}) is OLDER than src/signals.ts (${Ot(y,p)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${u} && bun build.ts`})}else c.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Ot(y,p)}, dist ${Ot(w,p)})`});let S=ke.join(s,"node_modules/@stacksjs/stx"),R=null;try{R=De.lstatSync(S)}catch{R=null}if(!R)c.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(R.isSymbolicLink()){let v=null;try{v=De.realpathSync(S)}catch{}let x=(()=>{try{return De.realpathSync(u)}catch{return u}})();c.push(v===x?{name:"node_modules \u2192 pantry",status:"ok",detail:"symlinked to pantry"}:{name:"node_modules \u2192 pantry",status:"warn",detail:`symlinked to ${v||"(dangling)"}, not pantry`})}else c.push({name:"node_modules \u2192 pantry",status:"warn",detail:"is a real directory, NOT symlinked to pantry \u2014 edits to pantry src/dist won't be resolved",fix:"rm -rf node_modules/@stacksjs/stx && ln -s ../../pantry/@stacksjs/stx node_modules/@stacksjs/stx"})}if(c.push({name:"dev runtime cache",status:"info",detail:"cleared automatically on source edits by the dev watcher (clearDevCaches, #1745 item C)"}),t.generateRuntime)try{let g=t.generateRuntime().length;c.push(g>1000?{name:"signals runtime",status:"ok",detail:`generated ${g.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${g} chars \u2014 suspiciously short`})}catch(h){c.push({name:"signals runtime",status:"error",detail:`failed to generate: ${h.message}`})}return{checks:c,ok:!c.some((h)=>h.status==="error")}}function Mr(t){let s={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},i=["stx runtime resolution:"];for(let p of t.checks)if(i.push(` ${s[p.status]} ${p.name}: ${p.detail}`),p.fix)i.push(` \u2192 ${p.fix}`);return i.push(""),i.push(t.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),i.join(`
2033
+ `)}export{po,fo,go,mo,Dr,ho,yo,bo,da,ua,Nr,Mr,Vn,Un,Wn};