@stacksjs/stx 0.2.845 → 0.2.847

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 (237) hide show
  1. package/dist/app-shell.d.ts +2 -1
  2. package/dist/app-shell.js +3 -3
  3. package/dist/builtins/image-worker.d.ts +1 -17
  4. package/dist/builtins/image-worker.js +3 -16
  5. package/dist/{chunk-rb6vr5v9.js → chunk-09412heg.js} +7 -7
  6. package/dist/chunk-0d4zhbjz.js +2 -0
  7. package/dist/chunk-0g05v7m1.js +2 -0
  8. package/dist/chunk-0vbt87cv.js +2 -0
  9. package/dist/{chunk-n91sm385.js → chunk-0wms5teg.js} +2 -2
  10. package/dist/{chunk-6x6w0v1k.js → chunk-110s34yg.js} +3 -3
  11. package/dist/chunk-11snc6n0.js +2 -0
  12. package/dist/{chunk-py5x8fkq.js → chunk-12r22pf0.js} +2 -2
  13. package/dist/chunk-14cvwsy1.js +3 -0
  14. package/dist/chunk-1menbxwb.js +2 -0
  15. package/dist/chunk-1na30z8t.js +2 -0
  16. package/dist/chunk-1p968nww.js +2 -0
  17. package/dist/chunk-1pf4y2yr.js +2 -0
  18. package/dist/chunk-1rban2td.js +2 -0
  19. package/dist/{chunk-3rjgm7qk.js → chunk-25m74mh1.js} +5 -5
  20. package/dist/{chunk-79wb76ya.js → chunk-2j3gttzf.js} +1 -1
  21. package/dist/{chunk-ka5ea34g.js → chunk-2ts9pb6s.js} +2 -2
  22. package/dist/{chunk-ntg8ttm4.js → chunk-2xf323h9.js} +3 -3
  23. package/dist/chunk-31rtwv90.js +2 -0
  24. package/dist/chunk-341c732h.js +2 -0
  25. package/dist/chunk-343hxxq1.js +2 -0
  26. package/dist/chunk-37bzsnr7.js +2 -0
  27. package/dist/{chunk-97bvpszy.js → chunk-3c2hgvag.js} +3 -3
  28. package/dist/chunk-3m6n90sk.js +2 -0
  29. package/dist/{chunk-9vg3jtzw.js → chunk-3qyz80d6.js} +6 -6
  30. package/dist/{chunk-47n5s7wk.js → chunk-46t924aw.js} +2 -2
  31. package/dist/{chunk-c6yc6qsv.js → chunk-4fc8zs15.js} +5 -5
  32. package/dist/{chunk-6tyjvxgb.js → chunk-5aqvfnvy.js} +8 -8
  33. package/dist/chunk-5bm8hmwd.js +2 -0
  34. package/dist/{chunk-vhxrrqrg.js → chunk-5ghw26vq.js} +2 -2
  35. package/dist/{chunk-4rfedg2f.js → chunk-5m0nyt8d.js} +3 -3
  36. package/dist/{chunk-md84j62m.js → chunk-5njk2ba0.js} +10 -10
  37. package/dist/{chunk-fg80w4zk.js → chunk-5wr1qqz3.js} +2 -2
  38. package/dist/{chunk-7r4p7zjn.js → chunk-5x8q6e1q.js} +6 -6
  39. package/dist/chunk-6bemqsdj.js +2 -0
  40. package/dist/chunk-6hd83cj4.js +2 -0
  41. package/dist/{chunk-k7am94hr.js → chunk-6peq9s4s.js} +5 -5
  42. package/dist/{chunk-1h6pb8d1.js → chunk-6xcmeev9.js} +5 -5
  43. package/dist/chunk-77fs8281.js +2 -0
  44. package/dist/chunk-79pgjds2.js +2 -0
  45. package/dist/chunk-7ycmnsh5.js +2 -0
  46. package/dist/{chunk-78q3apyy.js → chunk-81ysx0tc.js} +2 -2
  47. package/dist/{chunk-s68p10zh.js → chunk-8586a2hh.js} +2 -2
  48. package/dist/chunk-86z8zrn9.js +3 -0
  49. package/dist/chunk-8xb9ecb9.js +2 -0
  50. package/dist/{chunk-mveqaxkr.js → chunk-907zya76.js} +9 -9
  51. package/dist/{chunk-fs5mshcs.js → chunk-93c08def.js} +5 -5
  52. package/dist/chunk-9c6yvh3p.js +2 -0
  53. package/dist/chunk-9fxeqf0e.js +2 -0
  54. package/dist/chunk-9m96yv69.js +2 -0
  55. package/dist/{chunk-6hb75r07.js → chunk-9qxx2teq.js} +6 -6
  56. package/dist/{chunk-rk2ex6qx.js → chunk-9sjtph54.js} +3 -3
  57. package/dist/{chunk-0gg7k9cj.js → chunk-acwdf0cf.js} +5 -5
  58. package/dist/chunk-atsjexk0.js +2 -0
  59. package/dist/{chunk-hc1f1yq8.js → chunk-b3n1m4m5.js} +2 -2
  60. package/dist/chunk-bcefawtc.js +2 -0
  61. package/dist/{chunk-8g5dsjr0.js → chunk-bttvkzxh.js} +6 -6
  62. package/dist/chunk-byjjz7h8.js +2 -0
  63. package/dist/chunk-c0azgkss.js +2 -0
  64. package/dist/{chunk-tzdwg9rw.js → chunk-c541s99z.js} +4 -4
  65. package/dist/chunk-cbz7jtzf.js +2 -0
  66. package/dist/chunk-cq06hsm4.js +2 -0
  67. package/dist/{chunk-5a7etvxz.js → chunk-cv0rmntr.js} +5 -5
  68. package/dist/{chunk-48vnw9t9.js → chunk-cww1zk8y.js} +2 -2
  69. package/dist/{chunk-010yhk6m.js → chunk-cz2s176s.js} +5 -5
  70. package/dist/chunk-dsh91n7n.js +2 -0
  71. package/dist/{chunk-2cafvex6.js → chunk-dv9q56r7.js} +2 -2
  72. package/dist/{chunk-r8xwd8r1.js → chunk-eg2p1cyw.js} +14 -14
  73. package/dist/{chunk-r4jwhy37.js → chunk-emf6ee94.js} +3 -3
  74. package/dist/{chunk-dhgjq9jx.js → chunk-eqbx4yj1.js} +6 -6
  75. package/dist/chunk-evdskc25.js +2 -0
  76. package/dist/chunk-f18rxz70.js +2 -0
  77. package/dist/chunk-f8akfzzn.js +2 -0
  78. package/dist/chunk-f8wmxwa3.js +2 -0
  79. package/dist/{chunk-b6qf7w2b.js → chunk-fa3ygt8c.js} +4 -4
  80. package/dist/{chunk-fm8gfj2g.js → chunk-fez9828r.js} +2 -2
  81. package/dist/chunk-fhyvdxhw.js +4 -0
  82. package/dist/{chunk-nqj1mkkz.js → chunk-fr658fhd.js} +2 -2
  83. package/dist/chunk-fseqwysr.js +2 -0
  84. package/dist/{chunk-zwxncs2e.js → chunk-fxk08je0.js} +9 -9
  85. package/dist/chunk-g891ftgz.js +2 -0
  86. package/dist/{chunk-8qjf16yr.js → chunk-ga650crj.js} +5 -5
  87. package/dist/chunk-gc7gh0g0.js +2 -0
  88. package/dist/chunk-gzx1f8ay.js +2 -0
  89. package/dist/chunk-h526qmg2.js +2 -0
  90. package/dist/{chunk-y06rw18j.js → chunk-h9778nxm.js} +2 -2
  91. package/dist/chunk-hazd1sh8.js +2 -0
  92. package/dist/{chunk-kbv5nwwd.js → chunk-he9dzchk.js} +1 -1
  93. package/dist/{chunk-xr8hg79c.js → chunk-hpaj7zjv.js} +4 -4
  94. package/dist/{chunk-4y6hes3h.js → chunk-hpwtjb4a.js} +2 -2
  95. package/dist/chunk-j08r18x1.js +2 -0
  96. package/dist/chunk-j1sm889p.js +2 -0
  97. package/dist/chunk-j539dz72.js +2 -0
  98. package/dist/{chunk-11kp389s.js → chunk-jaf44web.js} +1 -1
  99. package/dist/{chunk-5p96rafz.js → chunk-jcwtw3hd.js} +2 -2
  100. package/dist/{chunk-tpyk6b4c.js → chunk-jh36gqcq.js} +2 -2
  101. package/dist/chunk-jj5fz0fq.js +12 -0
  102. package/dist/{chunk-x0dx1pyf.js → chunk-jm0qsr3s.js} +3 -3
  103. package/dist/chunk-jmqwpnpd.js +2 -0
  104. package/dist/chunk-jqngvqby.js +2 -0
  105. package/dist/{chunk-9mtyxvhk.js → chunk-jtccqpwa.js} +2 -2
  106. package/dist/chunk-k33kgf8a.js +2 -0
  107. package/dist/{chunk-jabw4ck5.js → chunk-k44qj40k.js} +2 -2
  108. package/dist/chunk-ke8rxpp9.js +2 -0
  109. package/dist/{chunk-302gek13.js → chunk-ks0dwtp0.js} +3 -3
  110. package/dist/chunk-kvttzk86.js +2 -0
  111. package/dist/{chunk-87ksn02m.js → chunk-ma9yq04p.js} +2 -2
  112. package/dist/{chunk-6trgwvt0.js → chunk-mbcqpcyt.js} +12 -12
  113. package/dist/chunk-mfbqjkgp.js +3 -0
  114. package/dist/chunk-my8257pf.js +2 -0
  115. package/dist/{chunk-jf0a5ew8.js → chunk-na1x46xm.js} +3 -3
  116. package/dist/chunk-nm04926f.js +2 -0
  117. package/dist/chunk-nnnf8cjv.js +2 -0
  118. package/dist/{chunk-ncrrxp60.js → chunk-nws4zm4k.js} +4 -4
  119. package/dist/chunk-p2fkggw4.js +3 -0
  120. package/dist/{chunk-c62wxswd.js → chunk-prnebmz1.js} +39 -39
  121. package/dist/chunk-q18508s2.js +2 -0
  122. package/dist/{chunk-k1tbgnhf.js → chunk-q61r0m6r.js} +1 -1
  123. package/dist/chunk-qay7pgnq.js +2 -0
  124. package/dist/{chunk-rpapxkdm.js → chunk-qpz9jrvw.js} +3 -3
  125. package/dist/chunk-r6085mp4.js +2 -0
  126. package/dist/{chunk-7s411sa9.js → chunk-r96ahk8s.js} +5 -5
  127. package/dist/chunk-rke4q3jk.js +2 -0
  128. package/dist/{chunk-r3jf8v5a.js → chunk-rqjskxpw.js} +32 -32
  129. package/dist/chunk-rsa9ssz7.js +33 -0
  130. package/dist/{chunk-y7aqf8r7.js → chunk-s4wcksaw.js} +2 -2
  131. package/dist/{chunk-vf0xbptq.js → chunk-s6td2c1k.js} +2 -2
  132. package/dist/chunk-se79v0pe.js +2 -0
  133. package/dist/{chunk-rncmfgpk.js → chunk-sz2nax5v.js} +32 -32
  134. package/dist/{chunk-kxj5sp5w.js → chunk-t4dkcf28.js} +114 -25
  135. package/dist/{chunk-4dxq7ft1.js → chunk-t5q31st4.js} +2 -2
  136. package/dist/{chunk-5y3m5vzg.js → chunk-tb5h85ag.js} +2 -2
  137. package/dist/{chunk-02qbawwq.js → chunk-tm5t3hh3.js} +3 -3
  138. package/dist/{chunk-bqsrtvad.js → chunk-trgbdydw.js} +2 -2
  139. package/dist/chunk-twfx2scr.js +2 -0
  140. package/dist/{chunk-hgk1v60t.js → chunk-txs1vxas.js} +10 -10
  141. package/dist/{chunk-315q48qy.js → chunk-v5tzcd49.js} +7 -7
  142. package/dist/chunk-v7d7m4k1.js +2 -0
  143. package/dist/chunk-vdb3p2v3.js +2 -0
  144. package/dist/chunk-vm2y05sr.js +2 -0
  145. package/dist/{chunk-f34ce0pn.js → chunk-vm68yvgf.js} +6 -6
  146. package/dist/{chunk-69b8mr68.js → chunk-wdwx2aa6.js} +2 -2
  147. package/dist/{chunk-1c6kczkt.js → chunk-wp14sf2j.js} +2 -2
  148. package/dist/{chunk-2ytaezad.js → chunk-wzyc9da7.js} +2 -2
  149. package/dist/chunk-xc1k2zza.js +2 -0
  150. package/dist/{chunk-ndsygfeb.js → chunk-xn0ebqgw.js} +14 -14
  151. package/dist/{chunk-zjqvbcwa.js → chunk-xppm4cs4.js} +2 -2
  152. package/dist/{chunk-3ba0nqwm.js → chunk-y1cneng3.js} +2 -2
  153. package/dist/{chunk-tjnf4a8g.js → chunk-ybgzr6wn.js} +64 -64
  154. package/dist/{chunk-3sskqw4b.js → chunk-yrmppd8r.js} +1 -1
  155. package/dist/{chunk-pb9347sn.js → chunk-ysqzz2h3.js} +3 -3
  156. package/dist/{chunk-28zze2wm.js → chunk-z57xq46m.js} +1 -1
  157. package/dist/{chunk-mnt7jbek.js → chunk-zfb2wnha.js} +3 -3
  158. package/dist/cli.js +20 -20
  159. package/dist/craft-entry.js +2 -2
  160. package/dist/craft.js +2 -2
  161. package/dist/framework-composables.js +13 -1
  162. package/dist/installed-entry.d.ts +8 -0
  163. package/dist/installed-entry.js +19 -0
  164. package/dist/page-head.d.ts +15 -0
  165. package/dist/page-head.js +35 -10
  166. package/dist/pwa.js +3 -3
  167. package/dist/ssg.js +6 -6
  168. package/dist/template-compiler.js +2 -2
  169. package/package.json +5 -5
  170. package/dist/chunk-01gwdj2y.js +0 -2
  171. package/dist/chunk-07hvjvj1.js +0 -2
  172. package/dist/chunk-12tkqtrv.js +0 -2
  173. package/dist/chunk-168fwztf.js +0 -2
  174. package/dist/chunk-1cdxe8yt.js +0 -2
  175. package/dist/chunk-1k751fgt.js +0 -2
  176. package/dist/chunk-3qa40hgd.js +0 -2
  177. package/dist/chunk-3qstewq3.js +0 -2
  178. package/dist/chunk-40r740w1.js +0 -2
  179. package/dist/chunk-469nzheq.js +0 -2
  180. package/dist/chunk-5hhyqze9.js +0 -2
  181. package/dist/chunk-60jtrz9f.js +0 -2
  182. package/dist/chunk-64evx0my.js +0 -2
  183. package/dist/chunk-6vcpmt0y.js +0 -2
  184. package/dist/chunk-7tdwa595.js +0 -2
  185. package/dist/chunk-7xp2ec0v.js +0 -2
  186. package/dist/chunk-8hy5g1hq.js +0 -32
  187. package/dist/chunk-8nq2snvy.js +0 -2
  188. package/dist/chunk-8s27mteq.js +0 -2
  189. package/dist/chunk-8weaawqm.js +0 -2
  190. package/dist/chunk-afyvnpr9.js +0 -2
  191. package/dist/chunk-as6x6be8.js +0 -2
  192. package/dist/chunk-aw45yjrw.js +0 -2
  193. package/dist/chunk-b30fzxwd.js +0 -2
  194. package/dist/chunk-b3wcs8bk.js +0 -2
  195. package/dist/chunk-bygxt820.js +0 -3
  196. package/dist/chunk-c3y7cxe7.js +0 -2
  197. package/dist/chunk-d5bjpjbv.js +0 -2
  198. package/dist/chunk-dmmt4psb.js +0 -12
  199. package/dist/chunk-e1vf62ck.js +0 -2
  200. package/dist/chunk-eaz30495.js +0 -4
  201. package/dist/chunk-emzz6seq.js +0 -2
  202. package/dist/chunk-exr9599h.js +0 -2
  203. package/dist/chunk-f1wv2q2z.js +0 -2
  204. package/dist/chunk-fpc1n3je.js +0 -2
  205. package/dist/chunk-fyesbfvr.js +0 -2
  206. package/dist/chunk-fz433ybr.js +0 -2
  207. package/dist/chunk-hbkh87n2.js +0 -2
  208. package/dist/chunk-hpw6hq7p.js +0 -2
  209. package/dist/chunk-j274w1ac.js +0 -2
  210. package/dist/chunk-jf37tpj2.js +0 -2
  211. package/dist/chunk-jv2z9qb7.js +0 -2
  212. package/dist/chunk-k609nyan.js +0 -2
  213. package/dist/chunk-msd0ezxm.js +0 -2
  214. package/dist/chunk-n4c8srx8.js +0 -2
  215. package/dist/chunk-nfxd6y75.js +0 -2
  216. package/dist/chunk-pj1xj34h.js +0 -2
  217. package/dist/chunk-pv2mrc9g.js +0 -2
  218. package/dist/chunk-pwdnqe30.js +0 -2
  219. package/dist/chunk-qeej9h56.js +0 -2
  220. package/dist/chunk-rapk2r7b.js +0 -2
  221. package/dist/chunk-rrj3gv46.js +0 -3
  222. package/dist/chunk-sss23kn5.js +0 -2
  223. package/dist/chunk-st75663x.js +0 -2
  224. package/dist/chunk-sv52qc36.js +0 -3
  225. package/dist/chunk-t4n23dh5.js +0 -2
  226. package/dist/chunk-vkrxrt0a.js +0 -2
  227. package/dist/chunk-vzpbxgg7.js +0 -2
  228. package/dist/chunk-wvwca1e9.js +0 -2
  229. package/dist/chunk-xjbc3bhs.js +0 -2
  230. package/dist/chunk-xtbmntht.js +0 -2
  231. package/dist/chunk-xvd3vdrw.js +0 -2
  232. package/dist/chunk-xvtp7nyj.js +0 -2
  233. package/dist/chunk-xy45tx27.js +0 -2
  234. package/dist/chunk-yg5a54pj.js +0 -2
  235. package/dist/chunk-yhzakgpp.js +0 -2
  236. package/dist/chunk-z3qgv971.js +0 -2
  237. package/dist/chunk-zztfp9qh.js +0 -2
@@ -1,7 +1,7 @@
1
1
  // @bun
2
- import x from"fs";import u from"path";import p from"fs";import w from"path";var y=["components","layouts","partials","emails"];function M(e){return e.split(/[\\/]/).filter(Boolean).slice(0,-1).some((a)=>y.includes(a))}function b(e){return M(e.replace(/^\//,""))}function oi(e,t){let a=e.filter((i)=>!b(i.pattern)),r=["// Auto-generated by STX - do not edit"];if(a.length===0)r.push("// No page routes found \u2014 route paths stay typed as string.","export {}","");else{r.push("declare module '@stacksjs/stx' {"," interface KnownRoutes {");for(let i of a){let c=[];for(let l of i.params){let d=i.pattern.includes(`:${l}?`)?"?":"";c.push(`${l}${d}: string`)}let s=c.join("; ");r.push(` '${i.pattern}': { ${s} }`)}r.push(" }","}","","export {}","")}let n=r.join(`
3
- `),o=w.join(t,"route-types.d.ts");try{if(p.existsSync(o)&&p.readFileSync(o,"utf8")===n)return;p.mkdirSync(t,{recursive:!0}),p.writeFileSync(o,n)}catch{}}function ii(e,t,a){let r=process.cwd(),n=w.relative(r,a),o=e.filter((c)=>!b(c.pattern)),i=["// Auto-generated by stx \u2014 do not edit",`// Source: ${n||"pages"}/`,"","export const routes = ["];for(let c of o){let s=w.relative(r,c.filePath).replace(/\\/g,"/"),l=JSON.stringify(c.params),d=c.layout?`, layout: '${w.relative(r,c.layout).replace(/\\/g,"/")}'`:"";i.push(` { pattern: '${c.pattern}', filePath: '${s}', isDynamic: ${c.isDynamic}, params: ${l}${d} },`)}i.push("] as const",""),i.push("export type RouteName = typeof routes[number]['pattern']",""),p.mkdirSync(t,{recursive:!0}),p.writeFileSync(w.join(t,"routes.ts"),i.join(`
4
- `))}import I from"path";var N=Object.freeze(["ico","png","jpg","jpeg","gif","webp","avif","svg","bmp","tif","tiff","heic","css","js","mjs","cjs","map","wasm","webmanifest","json","xml","txt","rss","atom","woff","woff2","ttf","otf","eot","mp3","mp4","m4a","m4v","mov","webm","ogg","ogv","oga","wav","flac","avi","mkv","pdf","csv","doc","docx","xls","xlsx","ppt","pptx","rtf","odt","zip","gz","tgz","tar","rar","7z","bz2","xz","php","phtml","asp","aspx","jsp","cgi","env","ini","yml","yaml","toml","sql","bak","old","swp","log","conf","cfg","exe","dmg","pkg","apk","ipa","msi","iso","bin","dll"]),D=N.flatMap((e)=>e===e.toUpperCase()?[e]:[e,e.toUpperCase()]).join("|"),G=new RegExp(`\\.(?:${D})$`),E=`(?![^/]*\\.(?:${D})$)`;function kt(e){let t=e,a=t.search(/[?#]/);if(a!==-1)t=t.slice(0,a);let r=t.slice(t.lastIndexOf("/")+1);return r.length>0&&G.test(r)}function R(e,t){let r=I.relative(t,e).replace(/\.(stx|md)$/,"");if(r=r.split(I.sep).join("/"),r==="index")return"/";if(r.endsWith("/index"))r=r.slice(0,-6);return r=r.replace(/\[\[([^\]]+)\]\]/g,":$1?"),r=r.replace(/\[([^\]]+)\]/g,":$1"),r=r.replace(/:\.\.\.([^/]+)/g,":$1*"),`/${r}`}function de(e,t={}){let a=t.page?E:"",r=[],n="",o=0;while(o<e.length){let i=e.slice(o),c=/^\/:([^/?*]+)\?/.exec(i);if(c){r.push(c[1]);let d=o+c[0].length===e.length;n+=`(?:/${d?a:""}([^/]+))?`,o+=c[0].length;continue}let s=/^:([^/?*]+)\*/.exec(i);if(s){r.push(s[1]),n+="(.+)",o+=s[0].length;continue}let l=/^:([^/?*]+)/.exec(i);if(l){r.push(l[1]);let d=o+l[0].length===e.length;n+=`${d?a:""}([^/]+)`,o+=l[0].length;continue}n+=e[o].replace(/[.+^${}()|[\]\\*?]/g,"\\$&"),o+=1}return{regex:new RegExp(`^${n}$`),params:r}}function gr(e,t){let a=e===""?"/":e;for(let r of t){let n=a.match(r.regex);if(n){let o={};return r.params.forEach((i,c)=>{o[i]=n[c+1]}),{route:r,params:o}}}return null}function Rs(e,t={}){let a=e.replace(/\[\[([^\]]+)\]\]/g,":$1?").replace(/\[([^\]]+)\]/g,":$1").replace(/:\.\.\.([^/]+)/g,":$1*");return de(a,t)}import j from"fs";import L from"path";function _(e,t){let a=[],r=L.dirname(e);while(r.startsWith(t)||r===t){let n=L.join(r,"_layout.stx");if(j.existsSync(n))a.unshift(n);if(r===t)break;r=L.dirname(r)}return a}function B(e,t){let a=[];if(!x.existsSync(e))return a;let r=x.readdirSync(e,{withFileTypes:!0});for(let n of r){let o=u.join(e,n.name);if(n.isDirectory()){if(n.name.startsWith("."))continue;if(y.includes(n.name))continue;a.push(...B(o,t))}else if(n.isFile()){let i=u.extname(n.name);if(t.includes(i)){if(n.name.startsWith("_")&&n.name!=="_layout.stx")continue;if(n.name==="_layout.stx")continue;a.push(o)}}}return a}class mr{routes;pagesDir;pagesDirs;config;constructor(e,t={}){this.config=t;let a=t.pagesDirs&&t.pagesDirs.length>0?t.pagesDirs:[t.pagesDir||"pages"];this.pagesDirs=a.map((s)=>u.resolve(e,s)),this.pagesDir=this.pagesDirs[0];let r=t.extensions||[".stx"],n=(s)=>{let l=u.resolve(e,s);try{return x.realpathSync(l)}catch{return l}},o=(t.exclude??[]).filter((s)=>typeof s==="string"&&s.trim()!=="").map(n),i=(s)=>{if(o.length===0)return!1;let l=n(s);return o.some((d)=>l===d||l.startsWith(`${d}${u.sep}`))},c=new Set;this.routes=[];for(let s of this.pagesDirs){let l=B(s,r).filter((h)=>!i(h)),d=new Map;for(let h of l){let g=R(h,s),m=t.pagesDirs?g.replace(/:[\w]+/g,":param"):g;if(t.pagesDirs&&d.has(m))throw Error(`Conflicting layer pages for ${g}: ${d.get(m)} and ${h}`);if(d.set(m,h),c.has(m))continue;c.add(m);let{regex:X,params:P}=de(g,{page:!0}),C=t.layouts!==!1?_(h,s):[];this.routes.push({pattern:g,regex:X,params:P,filePath:h,isDynamic:P.length>0,layout:C.length>0?C[C.length-1]:void 0})}}if(this.routes.sort((s,l)=>{if(!s.isDynamic&&l.isDynamic)return-1;if(s.isDynamic&&!l.isDynamic)return 1;let d=s.pattern.split("/").length,h=l.pattern.split("/").length;if(d!==h)return h-d;return s.pattern.localeCompare(l.pattern)}),t.emit!==!1){let s=u.resolve(e,t.stateDir||process.env.STX_DIR?.trim()||".stx");oi(this.routes,s),ii(this.routes,s,this.pagesDir)}}match(e){let t=e===""?"/":e;for(let a of this.routes){let r=t.match(a.regex);if(r){let n={};return a.params.forEach((o,i)=>{n[o]=r[i+1]}),{route:a,params:n}}}return null}resolve(e,t){let a=this.routes.find((n)=>n.pattern===e||n.filePath.includes(e));if(!a)return"#not-found";let r=a.pattern;if(t)for(let[n,o]of Object.entries(t))r=r.replace(`:${n}`,encodeURIComponent(o));return r}addRoute(e){this.routes.push(e),this.routes.sort((t,a)=>{if(!t.isDynamic&&a.isDynamic)return-1;if(t.isDynamic&&!a.isDynamic)return 1;return t.pattern.localeCompare(a.pattern)})}getLayout(e){return e.layout??null}}function As(e,t){let a=[`${t}.stx`,"error.stx"];for(let r of a){let n=u.join(e,r);if(x.existsSync(n))return n}return null}function Ps(e,t){return e.map((a)=>{let r=u.relative(t,a.filePath),n=a.isDynamic?" (dynamic)":"";return`${a.pattern} \u2192 ${r}${n}`})}var f={},k="";function Kf(e){k=e.replace(/\/$/,"")}function Xf(e,t,a={}){f[e]={path:t,name:e,params:a}}function Gf(e){for(let[t,a]of Object.entries(e))if(typeof a==="string")f[t]={path:a,name:t};else f[t]={...a,name:t}}function hr(e,t={},a=!1){let r=f[e];if(!r)return console.warn(`Route [${e}] not defined.`),"#undefined-route";let n={...r.params,...t},o=r.path;o=o.replace(/:(\w+)/g,(c,s)=>{let l=n[s];if(l===void 0)return console.warn(`Missing parameter [${s}] for route [${e}].`),`:${s}`;return delete n[s],encodeURIComponent(String(l))});let i=Object.entries(n);if(i.length>0){let c=i.map(([s,l])=>`${encodeURIComponent(s)}=${encodeURIComponent(String(l))}`).join("&");o+=(o.includes("?")?"&":"?")+c}return a&&k?`${k}${o}`:o}function Jf(){for(let e of Object.keys(f))delete f[e];k=""}import F from"fs";import q from"path";function Yf(e,t={}){return{type:"redirect",path:e,options:{replace:t.replace??!1,external:t.external??!1,redirectCode:t.redirectCode??302}}}function Zf(e){return{type:"abort",error:typeof e==="string"?{statusCode:500,message:e}:e}}function Qf(e,t={}){return{handler:e,mode:t.mode??"universal"}}function O(e){let t={};if(!e)return t;let a=e.split(";");for(let r of a){let[n,...o]=r.split("=");if(n){let i=n.trim(),c=o.join("=").trim();if(i)t[i]=decodeURIComponent(c)}}return t}function S(e,t,a={}){let r=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;if(a.expires){let n=typeof a.expires==="number"?new Date(Date.now()+a.expires*1000):a.expires;r+=`; Expires=${n.toUTCString()}`}if(a.path)r+=`; Path=${a.path}`;if(a.domain)r+=`; Domain=${a.domain}`;if(a.secure)r+="; Secure";if(a.httpOnly)r+="; HttpOnly";if(a.sameSite)r+=`; SameSite=${a.sameSite}`;return r}function Tc(e,t){let a=e.headers.get("cookie")||"",r=O(a);return{get(n){return r[n]},set(n,o,i={}){r[n]=o,t.append("Set-Cookie",S(n,o,i))},delete(n){delete r[n],t.append("Set-Cookie",S(n,"",{expires:new Date(0),path:"/"}))},getAll(){return{...r}}}}function $c(){return{get(e){if(typeof document>"u")return;return O(document.cookie)[e]},set(e,t,a={}){if(typeof document>"u")return;document.cookie=S(e,t,a)},delete(e){if(typeof document>"u")return;document.cookie=S(e,"",{expires:new Date(0),path:"/"})},getAll(){if(typeof document>"u")return{};return O(document.cookie)}}}function Rc(){let e=typeof window<"u"&&typeof window.localStorage<"u";return{get(t){if(!e)return null;try{return window.localStorage.getItem(t)}catch{return null}},set(t,a){if(!e)return;try{window.localStorage.setItem(t,a)}catch{}},remove(t){if(!e)return;try{window.localStorage.removeItem(t)}catch{}},isAvailable(){return e}}}var v=new Map;function ai(e,t){v.set(e,t)}function Ac(e){return v.get(e)}function eg(e){return v.has(e)}function _t(){v.clear()}function Ct(){return Array.from(v.keys())}async function Et(e,t="middleware"){let a=q.resolve(e,t);if(!F.existsSync(a))return;let r=F.readdirSync(a);for(let n of r){if(!n.endsWith(".ts")&&!n.endsWith(".js"))continue;if(n.includes(".test.")||n.includes(".spec."))continue;let o=n.replace(/\.(ts|js)$/,""),i=q.join(a,n);try{let s=(await import(i)).default;if(s&&typeof s.handler==="function")ai(o,s);else if(typeof s==="function")ai(o,{handler:s,mode:"universal"})}catch(c){console.warn(`Failed to load middleware '${o}' from ${i}:`,c)}}}function K(e){let t={};if(!e)return t;let a=new URLSearchParams(e);for(let[r,n]of a)t[r]=n;return t}function Tt(e,t,a,r=""){return{path:e,params:t,query:K(r),fullPath:r?`${e}?${r}`:e,meta:a}}function $t(e,t,a,r){let n=r?.isServer??typeof window>"u",o=!n,i=new Headers;return{to:e,from:t,isClient:o,isServer:n,cookies:n&&a?Tc(a,i):$c(),storage:Rc(),state:{},request:a,responseHeaders:i}}async function Rt(e,t){let a=Array.isArray(e)?e:[e],r=t.isServer;for(let n of a){let o=Ac(n);if(!o)return console.error(`Route middleware '${n}' is not registered \u2014 failing the guard closed.`),{passed:!1,abort:{type:"abort",error:{statusCode:500,message:`Route middleware '${n}' is not registered`}},state:t.state,responseHeaders:t.responseHeaders};if(o.mode==="server"&&!r)continue;try{let i=await o.handler(t);if(i){if(i.type==="redirect")return{passed:!1,redirect:i,state:t.state,responseHeaders:t.responseHeaders};if(i.type==="abort")return{passed:!1,abort:i,state:t.state,responseHeaders:t.responseHeaders}}}catch(i){return console.error(`Error in middleware '${n}':`,i),{passed:!1,abort:{type:"abort",error:{statusCode:500,message:i instanceof Error?i.message:"Middleware error"}},state:t.state,responseHeaders:t.responseHeaders}}}return{passed:!0,state:t.state,responseHeaders:t.responseHeaders}}function Is(e){let a=e.replace(/\\/g,"/").split("/").filter(Boolean),r=a.lastIndexOf("layouts"),n=r>=0?a[r+1]:a.at(-1);if(!n)return"app";return n.replace(/\.stx$/i,"")||"app"}function tt(e){let t=e.match(/<meta\b[^>]*name=["']stx-layout["'][^>]*content=["']([^"']+)["'][^>]*>/i),a=e.match(/<meta\b[^>]*name=["']stx-layout-group["'][^>]*content=["']([^"']+)["'][^>]*>/i),r=e.match(/<!--\s*stx-layout:\s*([^ ]+)\s*-->/i),n=t?.[1]||r?.[1]||"";return{layout:n,group:a?.[1]||Is(n)}}var A,T;function W(e){let t=[],a="log(",r=0;while(r<e.length){let n=e.indexOf("log(",r);if(n===-1){t.push(e.slice(r));break}let o=n>0?e[n-1]:" ",i=/\bfunction\s+$/.test(e.slice(Math.max(0,n-16),n));if(/[\w$.]/.test(o)||i){t.push(e.slice(r,n+4)),r=n+4;continue}t.push(e.slice(r,n));let c=1,s=n+4;while(s<e.length&&c>0){let l=e[s];if(l==='"'||l==="'"||l==="`"){let d=l;s++;while(s<e.length&&e[s]!==d){if(e[s]==="\\")s++;s++}s++;continue}if(l==="(")c++;else if(l===")")c--;s++}t.push("0"),r=s}return t.join("")}function U(e,t=!1){try{return new Bun.Transpiler(t?{loader:"js",minify:{whitespace:!0,identifiers:!0}}:{loader:"js",minifyWhitespace:!0}).transformSync(e).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return e}}function H(){return`
2
+ import x from"fs";import u from"path";import p from"fs";import w from"path";var y=["components","layouts","partials","emails"];function M(e){return e.split(/[\\/]/).filter(Boolean).slice(0,-1).some((a)=>y.includes(a))}function b(e){return M(e.replace(/^\//,""))}function ai(e,t){let a=e.filter((i)=>!b(i.pattern)),r=["// Auto-generated by STX - do not edit"];if(a.length===0)r.push("// No page routes found \u2014 route paths stay typed as string.","export {}","");else{r.push("declare module '@stacksjs/stx' {"," interface KnownRoutes {");for(let i of a){let c=[];for(let l of i.params){let d=i.pattern.includes(`:${l}?`)?"?":"";c.push(`${l}${d}: string`)}let s=c.join("; ");r.push(` '${i.pattern}': { ${s} }`)}r.push(" }","}","","export {}","")}let n=r.join(`
3
+ `),o=w.join(t,"route-types.d.ts");try{if(p.existsSync(o)&&p.readFileSync(o,"utf8")===n)return;p.mkdirSync(t,{recursive:!0}),p.writeFileSync(o,n)}catch{}}function ci(e,t,a){let r=process.cwd(),n=w.relative(r,a),o=e.filter((c)=>!b(c.pattern)),i=["// Auto-generated by stx \u2014 do not edit",`// Source: ${n||"pages"}/`,"","export const routes = ["];for(let c of o){let s=w.relative(r,c.filePath).replace(/\\/g,"/"),l=JSON.stringify(c.params),d=c.layout?`, layout: '${w.relative(r,c.layout).replace(/\\/g,"/")}'`:"";i.push(` { pattern: '${c.pattern}', filePath: '${s}', isDynamic: ${c.isDynamic}, params: ${l}${d} },`)}i.push("] as const",""),i.push("export type RouteName = typeof routes[number]['pattern']",""),p.mkdirSync(t,{recursive:!0}),p.writeFileSync(w.join(t,"routes.ts"),i.join(`
4
+ `))}import I from"path";var N=Object.freeze(["ico","png","jpg","jpeg","gif","webp","avif","svg","bmp","tif","tiff","heic","css","js","mjs","cjs","map","wasm","webmanifest","json","xml","txt","rss","atom","woff","woff2","ttf","otf","eot","mp3","mp4","m4a","m4v","mov","webm","ogg","ogv","oga","wav","flac","avi","mkv","pdf","csv","doc","docx","xls","xlsx","ppt","pptx","rtf","odt","zip","gz","tgz","tar","rar","7z","bz2","xz","php","phtml","asp","aspx","jsp","cgi","env","ini","yml","yaml","toml","sql","bak","old","swp","log","conf","cfg","exe","dmg","pkg","apk","ipa","msi","iso","bin","dll"]),D=N.flatMap((e)=>e===e.toUpperCase()?[e]:[e,e.toUpperCase()]).join("|"),X=new RegExp(`\\.(?:${D})$`),E=`(?![^/]*\\.(?:${D})$)`;function kt(e){let t=e,a=t.search(/[?#]/);if(a!==-1)t=t.slice(0,a);let r=t.slice(t.lastIndexOf("/")+1);return r.length>0&&X.test(r)}function R(e,t){let r=I.relative(t,e).replace(/\.(stx|md)$/,"");if(r=r.split(I.sep).join("/"),r==="index")return"/";if(r.endsWith("/index"))r=r.slice(0,-6);return r=r.replace(/\[\[([^\]]+)\]\]/g,":$1?"),r=r.replace(/\[([^\]]+)\]/g,":$1"),r=r.replace(/:\.\.\.([^/]+)/g,":$1*"),`/${r}`}function de(e,t={}){let a=t.page?E:"",r=[],n="",o=0;while(o<e.length){let i=e.slice(o),c=/^\/:([^/?*]+)\?/.exec(i);if(c){r.push(c[1]);let d=o+c[0].length===e.length;n+=`(?:/${d?a:""}([^/]+))?`,o+=c[0].length;continue}let s=/^:([^/?*]+)\*/.exec(i);if(s){r.push(s[1]),n+="(.+)",o+=s[0].length;continue}let l=/^:([^/?*]+)/.exec(i);if(l){r.push(l[1]);let d=o+l[0].length===e.length;n+=`${d?a:""}([^/]+)`,o+=l[0].length;continue}n+=e[o].replace(/[.+^${}()|[\]\\*?]/g,"\\$&"),o+=1}return{regex:new RegExp(`^${n}$`),params:r}}function hr(e,t){let a=e===""?"/":e;for(let r of t){let n=a.match(r.regex);if(n){let o={};return r.params.forEach((i,c)=>{o[i]=n[c+1]}),{route:r,params:o}}}return null}function Ps(e,t={}){let a=e.replace(/\[\[([^\]]+)\]\]/g,":$1?").replace(/\[([^\]]+)\]/g,":$1").replace(/:\.\.\.([^/]+)/g,":$1*");return de(a,t)}import j from"fs";import L from"path";function _(e,t){let a=[],r=L.dirname(e);while(r.startsWith(t)||r===t){let n=L.join(r,"_layout.stx");if(j.existsSync(n))a.unshift(n);if(r===t)break;r=L.dirname(r)}return a}function B(e,t){let a=[];if(!x.existsSync(e))return a;let r=x.readdirSync(e,{withFileTypes:!0});for(let n of r){let o=u.join(e,n.name);if(n.isDirectory()){if(n.name.startsWith("."))continue;if(y.includes(n.name))continue;a.push(...B(o,t))}else if(n.isFile()){let i=u.extname(n.name);if(t.includes(i)){if(n.name.startsWith("_")&&n.name!=="_layout.stx")continue;if(n.name==="_layout.stx")continue;a.push(o)}}}return a}class yr{routes;pagesDir;pagesDirs;config;constructor(e,t={}){this.config=t;let a=t.pagesDirs&&t.pagesDirs.length>0?t.pagesDirs:[t.pagesDir||"pages"];this.pagesDirs=a.map((s)=>u.resolve(e,s)),this.pagesDir=this.pagesDirs[0];let r=t.extensions||[".stx"],n=(s)=>{let l=u.resolve(e,s);try{return x.realpathSync(l)}catch{return l}},o=(t.exclude??[]).filter((s)=>typeof s==="string"&&s.trim()!=="").map(n),i=(s)=>{if(o.length===0)return!1;let l=n(s);return o.some((d)=>l===d||l.startsWith(`${d}${u.sep}`))},c=new Set;this.routes=[];for(let s of this.pagesDirs){let l=B(s,r).filter((h)=>!i(h)),d=new Map;for(let h of l){let g=R(h,s),m=t.pagesDirs?g.replace(/:[\w]+/g,":param"):g;if(t.pagesDirs&&d.has(m))throw Error(`Conflicting layer pages for ${g}: ${d.get(m)} and ${h}`);if(d.set(m,h),c.has(m))continue;c.add(m);let{regex:G,params:P}=de(g,{page:!0}),T=t.layouts!==!1?_(h,s):[];this.routes.push({pattern:g,regex:G,params:P,filePath:h,isDynamic:P.length>0,layout:T.length>0?T[T.length-1]:void 0})}}if(this.routes.sort((s,l)=>{if(!s.isDynamic&&l.isDynamic)return-1;if(s.isDynamic&&!l.isDynamic)return 1;let d=s.pattern.split("/").length,h=l.pattern.split("/").length;if(d!==h)return h-d;return s.pattern.localeCompare(l.pattern)}),t.emit!==!1){let s=u.resolve(e,t.stateDir||process.env.STX_DIR?.trim()||".stx");ai(this.routes,s),ci(this.routes,s,this.pagesDir)}}match(e){let t=e===""?"/":e;for(let a of this.routes){let r=t.match(a.regex);if(r){let n={};return a.params.forEach((o,i)=>{n[o]=r[i+1]}),{route:a,params:n}}}return null}resolve(e,t){let a=this.routes.find((n)=>n.pattern===e||n.filePath.includes(e));if(!a)return"#not-found";let r=a.pattern;if(t)for(let[n,o]of Object.entries(t))r=r.replace(`:${n}`,encodeURIComponent(o));return r}addRoute(e){this.routes.push(e),this.routes.sort((t,a)=>{if(!t.isDynamic&&a.isDynamic)return-1;if(t.isDynamic&&!a.isDynamic)return 1;return t.pattern.localeCompare(a.pattern)})}getLayout(e){return e.layout??null}}function Is(e,t){let a=[`${t}.stx`,"error.stx"];for(let r of a){let n=u.join(e,r);if(x.existsSync(n))return n}return null}function Os(e,t){return e.map((a)=>{let r=u.relative(t,a.filePath),n=a.isDynamic?" (dynamic)":"";return`${a.pattern} \u2192 ${r}${n}`})}var f={},k="";function Gf(e){k=e.replace(/\/$/,"")}function Jf(e,t,a={}){f[e]={path:t,name:e,params:a}}function Yf(e){for(let[t,a]of Object.entries(e))if(typeof a==="string")f[t]={path:a,name:t};else f[t]={...a,name:t}}function br(e,t={},a=!1){let r=f[e];if(!r)return console.warn(`Route [${e}] not defined.`),"#undefined-route";let n={...r.params,...t},o=r.path;o=o.replace(/:(\w+)/g,(c,s)=>{let l=n[s];if(l===void 0)return console.warn(`Missing parameter [${s}] for route [${e}].`),`:${s}`;return delete n[s],encodeURIComponent(String(l))});let i=Object.entries(n);if(i.length>0){let c=i.map(([s,l])=>`${encodeURIComponent(s)}=${encodeURIComponent(String(l))}`).join("&");o+=(o.includes("?")?"&":"?")+c}return a&&k?`${k}${o}`:o}function Zf(){for(let e of Object.keys(f))delete f[e];k=""}import F from"fs";import q from"path";function Qf(e,t={}){return{type:"redirect",path:e,options:{replace:t.replace??!1,external:t.external??!1,redirectCode:t.redirectCode??302}}}function eg(e){return{type:"abort",error:typeof e==="string"?{statusCode:500,message:e}:e}}function tg(e,t={}){return{handler:e,mode:t.mode??"universal"}}function O(e){let t={};if(!e)return t;let a=e.split(";");for(let r of a){let[n,...o]=r.split("=");if(n){let i=n.trim(),c=o.join("=").trim();if(i)t[i]=decodeURIComponent(c)}}return t}function S(e,t,a={}){let r=`${encodeURIComponent(e)}=${encodeURIComponent(t)}`;if(a.expires){let n=typeof a.expires==="number"?new Date(Date.now()+a.expires*1000):a.expires;r+=`; Expires=${n.toUTCString()}`}if(a.path)r+=`; Path=${a.path}`;if(a.domain)r+=`; Domain=${a.domain}`;if(a.secure)r+="; Secure";if(a.httpOnly)r+="; HttpOnly";if(a.sameSite)r+=`; SameSite=${a.sameSite}`;return r}function Rc(e,t){let a=e.headers.get("cookie")||"",r=O(a);return{get(n){return r[n]},set(n,o,i={}){r[n]=o,t.append("Set-Cookie",S(n,o,i))},delete(n){delete r[n],t.append("Set-Cookie",S(n,"",{expires:new Date(0),path:"/"}))},getAll(){return{...r}}}}function Ac(){return{get(e){if(typeof document>"u")return;return O(document.cookie)[e]},set(e,t,a={}){if(typeof document>"u")return;document.cookie=S(e,t,a)},delete(e){if(typeof document>"u")return;document.cookie=S(e,"",{expires:new Date(0),path:"/"})},getAll(){if(typeof document>"u")return{};return O(document.cookie)}}}function Pc(){let e=typeof window<"u"&&typeof window.localStorage<"u";return{get(t){if(!e)return null;try{return window.localStorage.getItem(t)}catch{return null}},set(t,a){if(!e)return;try{window.localStorage.setItem(t,a)}catch{}},remove(t){if(!e)return;try{window.localStorage.removeItem(t)}catch{}},isAvailable(){return e}}}var v=new Map;function li(e,t){v.set(e,t)}function Ic(e){return v.get(e)}function ng(e){return v.has(e)}function _t(){v.clear()}function Ct(){return Array.from(v.keys())}async function Et(e,t="middleware"){let a=q.resolve(e,t);if(!F.existsSync(a))return;let r=F.readdirSync(a);for(let n of r){if(!n.endsWith(".ts")&&!n.endsWith(".js"))continue;if(n.includes(".test.")||n.includes(".spec."))continue;let o=n.replace(/\.(ts|js)$/,""),i=q.join(a,n);try{let s=(await import(i)).default;if(s&&typeof s.handler==="function")li(o,s);else if(typeof s==="function")li(o,{handler:s,mode:"universal"})}catch(c){console.warn(`Failed to load middleware '${o}' from ${i}:`,c)}}}function K(e){let t={};if(!e)return t;let a=new URLSearchParams(e);for(let[r,n]of a)t[r]=n;return t}function Tt(e,t,a,r=""){return{path:e,params:t,query:K(r),fullPath:r?`${e}?${r}`:e,meta:a}}function $t(e,t,a,r){let n=r?.isServer??typeof window>"u",o=!n,i=new Headers;return{to:e,from:t,isClient:o,isServer:n,cookies:n&&a?Rc(a,i):Ac(),storage:Pc(),state:{},request:a,responseHeaders:i}}async function Rt(e,t){let a=Array.isArray(e)?e:[e],r=t.isServer;for(let n of a){let o=Ic(n);if(!o)return console.error(`Route middleware '${n}' is not registered \u2014 failing the guard closed.`),{passed:!1,abort:{type:"abort",error:{statusCode:500,message:`Route middleware '${n}' is not registered`}},state:t.state,responseHeaders:t.responseHeaders};if(o.mode==="server"&&!r)continue;try{let i=await o.handler(t);if(i){if(i.type==="redirect")return{passed:!1,redirect:i,state:t.state,responseHeaders:t.responseHeaders};if(i.type==="abort")return{passed:!1,abort:i,state:t.state,responseHeaders:t.responseHeaders}}}catch(i){return console.error(`Error in middleware '${n}':`,i),{passed:!1,abort:{type:"abort",error:{statusCode:500,message:i instanceof Error?i.message:"Middleware error"}},state:t.state,responseHeaders:t.responseHeaders}}}return{passed:!0,state:t.state,responseHeaders:t.responseHeaders}}function Ns(e){let a=e.replace(/\\/g,"/").split("/").filter(Boolean),r=a.lastIndexOf("layouts"),n=r>=0?a[r+1]:a.at(-1);if(!n)return"app";return n.replace(/\.stx$/i,"")||"app"}function tt(e){let t=e.match(/<meta\b[^>]*name=["']stx-layout["'][^>]*content=["']([^"']+)["'][^>]*>/i),a=e.match(/<meta\b[^>]*name=["']stx-layout-group["'][^>]*content=["']([^"']+)["'][^>]*>/i),r=e.match(/<!--\s*stx-layout:\s*([^ ]+)\s*-->/i),n=t?.[1]||r?.[1]||"";return{layout:n,group:a?.[1]||Ns(n)}}var A,C;function W(e){let t=[],a="log(",r=0;while(r<e.length){let n=e.indexOf("log(",r);if(n===-1){t.push(e.slice(r));break}let o=n>0?e[n-1]:" ",i=/\bfunction\s+$/.test(e.slice(Math.max(0,n-16),n));if(/[\w$.]/.test(o)||i){t.push(e.slice(r,n+4)),r=n+4;continue}t.push(e.slice(r,n));let c=1,s=n+4;while(s<e.length&&c>0){let l=e[s];if(l==='"'||l==="'"||l==="`"){let d=l;s++;while(s<e.length&&e[s]!==d){if(e[s]==="\\")s++;s++}s++;continue}if(l==="(")c++;else if(l===")")c--;s++}t.push("0"),r=s}return t.join("")}function U(e,t=!1){try{return new Bun.Transpiler(t?{loader:"js",minify:{whitespace:!0,identifiers:!0}}:{loader:"js",minifyWhitespace:!0}).transformSync(e).replace(/\}(var |let |const |function )/g,"};$1").trim()}catch{return e}}function H(){return`
5
5
  ;(function(){
6
6
  'use strict';
7
7
  var ROUTER_REV=8;
@@ -1667,26 +1667,36 @@ else {
1667
1667
  link.setAttribute('data-css','generated');
1668
1668
  link.setAttribute('rel','stylesheet');
1669
1669
  link.setAttribute('href',new URL(href,location.href).href===abs?href:abs);
1670
- link.setAttribute('media','print');
1671
- link.setAttribute('data-stx-css-pending','');
1672
- link.__stxCssReady=new Promise(function(resolve){
1673
- var timer=setTimeout(finish,o.cssLoadTimeout);
1674
- function finish(failed){
1675
- clearTimeout(timer);link.onload=null;link.onerror=null;link.__stxCssReady=null;
1676
- // A sheet that failed (a 5xx, a dropped connection) is gone for good:
1677
- // swapping anyway painted the page with only the utilities the
1678
- // previous page happened to share, which reads as a broken layout.
1679
- // Drop the dead <link> so a retry fetches it again, and report it.
1680
- if(failed===true&&link.parentNode)link.parentNode.removeChild(link);
1681
- resolve(failed!==true);
1682
- }
1683
- link.onload=function(){finish(false)};
1684
- link.onerror=function(){finish(true)};
1685
- });
1686
- pending.push(link.__stxCssReady);
1687
- dhead().appendChild(link);
1670
+ pending.push(holdCss(link));
1671
+ });
1672
+ return allCss(pending);
1673
+ }
1674
+
1675
+ // Put a sheet in <head> unapplied and answer with its __stxCssReady, the
1676
+ // promise the swap waits on. Shared by generated and page stylesheets.
1677
+ function holdCss(link){
1678
+ link.setAttribute('media','print');
1679
+ link.setAttribute('data-stx-css-pending','');
1680
+ link.__stxCssReady=new Promise(function(resolve){
1681
+ var timer=setTimeout(finish,o.cssLoadTimeout);
1682
+ function finish(failed){
1683
+ clearTimeout(timer);link.onload=null;link.onerror=null;link.__stxCssReady=null;
1684
+ // A sheet that failed (a 5xx, a dropped connection) is gone for good:
1685
+ // swapping anyway painted the page with only the styles the
1686
+ // previous page happened to share, which reads as a broken layout.
1687
+ // Drop the dead <link> so a retry fetches it again, and report it.
1688
+ if(failed===true&&link.parentNode)link.parentNode.removeChild(link);
1689
+ resolve(failed!==true);
1690
+ }
1691
+ link.onload=function(){finish(false)};
1692
+ link.onerror=function(){finish(true)};
1688
1693
  });
1689
- return pending.length?Promise.all(pending).then(function(results){return results.every(function(ok){return ok!==false})}):null;
1694
+ dhead().appendChild(link);
1695
+ return link.__stxCssReady;
1696
+ }
1697
+ // One answer for every sheet a swap waits on: null when there is none.
1698
+ function allCss(pending){
1699
+ return pending.some(Boolean)?Promise.all(pending).then(function(results){return results.indexOf(false)===-1}):null;
1690
1700
  }
1691
1701
 
1692
1702
  // Swap once the destination's sheets are in, or hand the navigation to the
@@ -1737,6 +1747,73 @@ else {
1737
1747
  return hrefs;
1738
1748
  }
1739
1749
 
1750
+ // \u2500\u2500 Page stylesheets \u2500\u2500
1751
+ // A fragment is the container's inner content, so the <link rel="stylesheet">
1752
+ // tags the destination declares in its own <head> never arrived with it: a
1753
+ // page reached by a link click rendered with the previous page's CSS and
1754
+ // none of its own, while a full load of the same URL was fine. The server
1755
+ // lists them in a template of their own, behind the fragment marker and the
1756
+ // metadata. They are assets, not metadata (#2121), so applyPageHead never
1757
+ // sees them, and only stylesheet links are read out of the list.
1758
+ //
1759
+ // Additive and deduped by absolute URL, like the full-document path: a sheet
1760
+ // the document has stays where it is, one it lacks is appended once, and
1761
+ // nothing is ever removed or reordered. Generated utility sheets are not
1762
+ // listed; promoteGeneratedCss owns those.
1763
+ var PAGE_CSS=/^(?:<!--stx-fragment[^>]*>)?(?:<template data-stx-page-head[^]*?<\\/template>\\n?)?<template data-stx-page-css="1">([^]*?)<\\/template>\\n?/;
1764
+ var PAGE_CSS_LINK='link[rel="stylesheet"][href]:not([data-css])';
1765
+ function fragmentPageCss(html){
1766
+ var payload=PAGE_CSS.exec(html);
1767
+ if(!payload)return [];
1768
+ // Parsed inert: a <template>'s content fetches nothing and applies nothing.
1769
+ var list=ce('template');
1770
+ list.innerHTML=payload[1];
1771
+ return list.content.querySelectorAll(PAGE_CSS_LINK);
1772
+ }
1773
+ function findPageCss(abs){
1774
+ var found=null;
1775
+ qsa('head '+PAGE_CSS_LINK).forEach(function(link){
1776
+ try{if(!found&&new URL(link.getAttribute('href'),location.href).href===abs)found=link}catch(e){}
1777
+ });
1778
+ return found;
1779
+ }
1780
+ // A sheet this path added goes live under the media its page declared. One
1781
+ // the document already had is left exactly as it was.
1782
+ function releasePageCss(link,media){
1783
+ if(!link||!link.hasAttribute('data-stx-css-pending'))return;
1784
+ link.removeAttribute('data-stx-css-pending');
1785
+ if(media)link.setAttribute('media',media);else link.removeAttribute('media');
1786
+ }
1787
+ // Before the swap, as preloadGeneratedCss: the sheets the document lacks are
1788
+ // added unapplied, and the swap waits for them so the new markup never
1789
+ // paints without its own CSS. Called again at the swap with live set, which
1790
+ // is when they start to apply.
1791
+ //
1792
+ // Each href is resolved against the page that declared it, never the one on
1793
+ // screen: a relative 'assets/app.css' on /docs/intro is /docs/assets/app.css
1794
+ // (#1777). It is stored absolute, so it still names the same file once the
1795
+ // address bar has moved on.
1796
+ function pageCss(links,base,live){
1797
+ var pending=[];
1798
+ links.forEach(function(decl){
1799
+ var abs,link;
1800
+ try{abs=new URL(decl.getAttribute('href'),new URL(base,location.href)).href}catch(e){return}
1801
+ link=findPageCss(abs);
1802
+ if(!link){
1803
+ link=ce('link');
1804
+ ['crossorigin','integrity'].forEach(function(name){
1805
+ if(decl.hasAttribute(name))link.setAttribute(name,decl.getAttribute(name));
1806
+ });
1807
+ link.setAttribute('rel','stylesheet');
1808
+ link.setAttribute('href',abs);
1809
+ holdCss(link);
1810
+ }
1811
+ pending.push(link.__stxCssReady);
1812
+ if(live)releasePageCss(link,decl.getAttribute('media'));
1813
+ });
1814
+ return allCss(pending);
1815
+ }
1816
+
1740
1817
  // Everything page-level the outgoing page registered stays its own from
1741
1818
  // here on: the runtime runs those on stx:load and keeps whatever the
1742
1819
  // incoming page's scripts register next (see beginSwap in the runtime).
@@ -1752,6 +1829,10 @@ else {
1752
1829
  if(isFragment){
1753
1830
  var headPayload=/^<template data-stx-page-head="1">([\\s\\S]*?)<\\/template>\\n?/.exec(html);
1754
1831
  if(headPayload){incomingHead=headPayload[1];html=html.slice(headPayload[0].length)}
1832
+ // The page's stylesheet list comes off as well: it is read here, and
1833
+ // must not be written into the container with the content.
1834
+ var incomingCss=fragmentPageCss(html);
1835
+ html=html.replace(PAGE_CSS,'');
1755
1836
  }
1756
1837
  if(!isFragment&&!isStxDocument(html)){log('[router] non-stx document \u2014 full navigation to:',url);location.href=url;return Promise.resolve(false)}
1757
1838
  var ctx=pendingCtx||{direction:pushState==='replace'?'replace':pushState==='tab'?'tab':pushState===false?'pop':'push'};
@@ -1863,6 +1944,8 @@ else {
1863
1944
  dhead().appendChild(cw);
1864
1945
  }
1865
1946
  }
1947
+ // The page's own sheets first, so its generated one still ends last.
1948
+ pageCss(incomingCss,url,true);
1866
1949
  // Already present ones are MOVED last, not skipped \u2014 see
1867
1950
  // promoteGeneratedCss for why their order is the whole bug.
1868
1951
  promoteGeneratedCss(fragCssHrefs,location.href);
@@ -2018,7 +2101,8 @@ else {
2018
2101
  // swaps, or the new markup paints once without its utilities and then
2019
2102
  // jumps. Cleanup waits with it so the outgoing page stays live meanwhile.
2020
2103
  // With nothing new to load this runs in the same turn, as it always did.
2021
- var fragCssReady=preloadGeneratedCss(fragmentCssHrefs(html),location.href);
2104
+ // The page's own stylesheets wait the same way, for the same reason.
2105
+ var fragCssReady=allCss([preloadGeneratedCss(fragmentCssHrefs(html),location.href),pageCss(incomingCss,url)]);
2022
2106
  return afterCss(fragCssReady,url,startFragSwap);
2023
2107
  }
2024
2108
 
@@ -2126,7 +2210,9 @@ else {
2126
2210
  // below also reorders them.
2127
2211
  if(l.hasAttribute('data-css'))return;
2128
2212
  var abs=new URL(href,docBase).href;
2129
- if(curLinks[abs])return;
2213
+ // Present, but possibly still held unapplied by a fragment navigation
2214
+ // or a prefetch that never swapped; this page makes it live.
2215
+ if(curLinks[abs]){releasePageCss(findPageCss(abs),l.getAttribute('media'));return}
2130
2216
  curLinks[abs]=1;
2131
2217
  var nl=ce('link');
2132
2218
  Array.from(l.attributes).forEach(function(a){nl.setAttribute(a.name,a.value)});
@@ -3654,6 +3740,8 @@ else {
3654
3740
  // as a navigation adds it; the swap makes it live.
3655
3741
  // A whole document's generated sheets too, named the same way in its head.
3656
3742
  preloadGeneratedCss(fragmentCssHrefs(result.html),location.href);
3743
+ // And the stylesheets its own head links, which a fragment lists.
3744
+ pageCss(fragmentPageCss(result.html),href);
3657
3745
  }
3658
3746
  }).catch(function(){}).finally(function(){delete prefetching[key]})},!glance);
3659
3747
  }
@@ -3738,6 +3826,7 @@ else {
3738
3826
  // or loaded) rather than starting them; a failed sheet is the swap's to
3739
3827
  // handle, so it does not hold this up. Generated sheets are root paths.
3740
3828
  preloadGeneratedCss(fragmentCssHrefs(html),location.href);
3829
+ pageCss(fragmentPageCss(html),base);
3741
3830
  var waits=loadModuleRegistries(html,base);
3742
3831
  if(!waits)return null;
3743
3832
  return Promise.race([
@@ -4095,4 +4184,4 @@ else {
4095
4184
 
4096
4185
  if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',init);else init();
4097
4186
  })();
4098
- `}function nt(){if(A)return A;return A=U(W(H()),!0),A}function tg(){if(T)return T;return T=U(H()),T}export{oi,ii,kt,de,gr,Rs,mr,As,Ps,Kf,Xf,Gf,hr,Jf,Yf,Zf,Qf,Tc,$c,Rc,ai,Ac,eg,_t,Ct,Et,Tt,$t,Rt,Is,tt,nt,tg};
4187
+ `}function nt(){if(A)return A;return A=U(W(H()),!0),A}function rg(){if(C)return C;return C=U(H()),C}export{ai,ci,kt,de,hr,Ps,yr,Is,Os,Gf,Jf,Yf,br,Zf,Qf,eg,tg,Rc,Ac,Pc,li,Ic,ng,_t,Ct,Et,Tt,$t,Rt,Ns,tt,nt,rg};
@@ -1,4 +1,4 @@
1
1
  // @bun
2
2
  var f=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),b=new Set(["html","head","body","p","li","dt","dd","rt","rp","option","optgroup","thead","tbody","tfoot","tr","td","th","colgroup","caption"]);function l(i){return i.replace(/[^\n]/g," ")}function w(i){let o=i.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,l).replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,l).replace(/<!--[\s\S]*?-->/g,l).replace(/\{\{\{[\s\S]*?\}\}\}/g,l).replace(/\{\{[\s\S]*?\}\}/g,l).replace(/\{!![\s\S]*?!!\}/g,l),s=new Map,r=new Map,p=/<(\/?)([A-Za-z][\w-]*)\b(?:[^<>"']|"[^"]*"|'[^']*')*?(\/?)>/g,t;while((t=p.exec(o))!==null){let e=t[1]==="/",n=t[2],a=t[3]==="/";if(f.has(n.toLowerCase()))continue;if(a)continue;if(e)r.set(n,(r.get(n)??0)+1);else{let g=s.get(n);if(g)g.count++;else{let d=o.slice(0,t.index).split(`
3
- `).length;s.set(n,{count:1,firstLine:d})}}}let c=[];for(let e of new Set([...s.keys(),...r.keys()])){if(b.has(e.toLowerCase()))continue;let n=s.get(e)?.count??0,a=r.get(e)??0;if(n!==a)c.push({tag:e,opened:n,closed:a,firstOpenLine:s.get(e)?.firstLine??0})}return c}var u=new Set;function jo(i,o){let s;try{s=w(i)}catch{return}if(s.length===0)return;let r=`${o}:${i.length}`;if(u.has(r))return;u.add(r);let p=o?o.split(/[/\\]/).pop()||o:"template";for(let{tag:t,opened:c,closed:e,firstOpenLine:n}of s)if(c>e){let a=n?` (first opened at line ${n})`:"";console.warn(`[stx] ${p}: <${t}> ${c} opened, ${e} closed \u2014 an unclosed <${t}>${a} may swallow the content that follows it.`)}else console.warn(`[stx] ${p}: <${t}> ${c} opened, ${e} closed \u2014 ${e-c} stray </${t}>.`)}
4
- export{jo};
3
+ `).length;s.set(n,{count:1,firstLine:d})}}}let c=[];for(let e of new Set([...s.keys(),...r.keys()])){if(b.has(e.toLowerCase()))continue;let n=s.get(e)?.count??0,a=r.get(e)??0;if(n!==a)c.push({tag:e,opened:n,closed:a,firstOpenLine:s.get(e)?.firstLine??0})}return c}var u=new Set;function Fo(i,o){let s;try{s=w(i)}catch{return}if(s.length===0)return;let r=`${o}:${i.length}`;if(u.has(r))return;u.add(r);let p=o?o.split(/[/\\]/).pop()||o:"template";for(let{tag:t,opened:c,closed:e,firstOpenLine:n}of s)if(c>e){let a=n?` (first opened at line ${n})`:"";console.warn(`[stx] ${p}: <${t}> ${c} opened, ${e} closed \u2014 an unclosed <${t}>${a} may swallow the content that follows it.`)}else console.warn(`[stx] ${p}: <${t}> ${c} opened, ${e} closed \u2014 ${e-c} stray </${t}>.`)}
4
+ export{Fo};
@@ -72,7 +72,7 @@ else {
72
72
  ${t}
73
73
  })();
74
74
  </script>
75
- `}function Gm(i,n,o){f=0;let l=/@defer\s*\(([^)]*)\)\s*([\s\S]*?)@enddefer/g;return i.replace(l,(t,e,s)=>{let a=v(),r=p(t,e,s),d=r.placeholder?`<div data-defer-placeholder>${r.placeholder}</div>`:"",c=r.loading?`<div data-defer-loading style="display: none;">${r.loading}</div>`:'<div data-defer-loading style="display: none;"></div>',g=r.error?`<div data-defer-error style="display: none;">${r.error}</div>`:"",u=`<div data-defer-content style="display: none;">${r.content}</div>`,h=E(a,r);return`
75
+ `}function Ym(i,n,o){f=0;let l=/@defer\s*\(([^)]*)\)\s*([\s\S]*?)@enddefer/g;return i.replace(l,(t,e,s)=>{let a=v(),r=p(t,e,s),d=r.placeholder?`<div data-defer-placeholder>${r.placeholder}</div>`:"",c=r.loading?`<div data-defer-loading style="display: none;">${r.loading}</div>`:'<div data-defer-loading style="display: none;"></div>',g=r.error?`<div data-defer-error style="display: none;">${r.error}</div>`:"",u=`<div data-defer-content style="display: none;">${r.content}</div>`,h=E(a,r);return`
76
76
  <div id="${a}" class="stx-defer" data-defer-trigger="${r.trigger}">
77
77
  ${d}
78
78
  ${c}
@@ -81,4 +81,4 @@ else {
81
81
  </div>
82
82
  ${h}
83
83
  `})}
84
- export{Gm};
84
+ export{Ym};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import y from"fs";import R from"path";var S="_stx";function F(e){return Bun.hash(e).toString(16).slice(0,8)}function k(e){let t=[],n=(i)=>{for(let s of y.readdirSync(i,{withFileTypes:!0})){let r=R.join(i,s.name);if(s.isDirectory())n(r);else if(s.isFile()&&r.endsWith(".html"))t.push(r)}};if(y.existsSync(e))n(e);return t}var z=[{pattern:/<script\b([^>]*\bdata-stx-runtime\b[^>]*)>([\s\S]*?)<\/script>/gi,prefix:"runtime",extension:"js",contentType:"text/javascript; charset=utf-8",replace:(e)=>`<script data-stx-runtime src="${e}"></script>`},{pattern:/<script\b([^>]*\bdata-stx-router\b[^>]*)>([\s\S]*?)<\/script>/gi,prefix:"router",extension:"js",contentType:"text/javascript; charset=utf-8",replace:(e)=>`<script data-stx-router src="${e}"></script>`},{pattern:/<style\b([^>]*\bdata-css=(?:"generated"|'generated')[^>]*)>([\s\S]*?)<\/style>/gi,prefix:"css",extension:"css",contentType:"text/css; charset=utf-8",replace:(e)=>`<link data-css="generated" rel="stylesheet" href="${e}">`}];function I(e,t=`/${S}`){let n=[],i=new Set,s=0,r=e;for(let o of z)r=r.replace(o.pattern,(g,u,c)=>{if(/\b(?:src|href)\s*=/.test(u)||!c.trim())return g;let a=`${o.prefix}.${F(c)}.${o.extension}`;if(!i.has(a))i.add(a),n.push({filename:a,contents:c,contentType:o.contentType});return s+=c.length,o.replace(`${t}/${a}`)});return{html:r,assets:n,bytesInlined:s}}function tc(e){let t={pages:0,assets:0,bytesInlined:0},n=R.join(e,S),i=new Set;for(let s of k(e)){let r=y.readFileSync(s,"utf8"),{html:o,assets:g,bytesInlined:u}=I(r);if(o===r)continue;for(let c of g){if(i.has(c.filename))continue;i.add(c.filename),y.mkdirSync(n,{recursive:!0}),y.writeFileSync(R.join(n,c.filename),c.contents),t.assets++}y.writeFileSync(s,o),t.bytesInlined+=u,t.pages++}return t}import h from"fs";import T from"path";var L=1024,N=/<(script|style)\b([^>]*)>([\s\S]*?)<\/\1>/gi,_=new Set(["","module","text/javascript","application/javascript","module/javascript"]);function B(e){return Bun.hash(e).toString(16).slice(0,8)}function C(e){let t=[],n=(i)=>{for(let s of h.readdirSync(i,{withFileTypes:!0})){let r=T.join(i,s.name);if(s.isDirectory())n(r);else if(s.isFile()&&r.endsWith(".html"))t.push(r)}};if(h.existsSync(e))n(e);return t}function O(e,t){let n=e.match(new RegExp(`\\b${t}\\s*=\\s*("([^"]*)"|'([^']*)'|([^\\s>]+))`,"i"));if(!n)return;return n[2]??n[3]??n[4]??""}function H(e,t,n){if(n.length<L)return!1;if(/\b(?:src|href)\s*=/i.test(t))return!1;if(e.toLowerCase()==="script"){if(!_.has((O(t,"type")??"").trim().toLowerCase()))return!1;return!0}return!0}function D(e){let t=[];for(let n of e.matchAll(/<template\b[^>]*>[\s\S]*?<\/template>/gi))t.push([n.index,n.index+n[0].length]);return t}function nc(e){let t={pages:0,assets:0,bytesInlined:0},n=C(e);if(n.length<2)return t;let i=new Map,s=new Map;for(let a of n){let f=h.readFileSync(a,"utf8");i.set(a,f);let M=D(f);for(let d of f.matchAll(N)){let[x,p,l,m]=d;if(!H(p,l,m))continue;if(M.some(([j,A])=>d.index>=j&&d.index<A))continue;let w=`${p.toLowerCase()}\x00${m}`,b=s.get(w);if(b)b.push({file:a,whole:x,tag:p,attrs:l,body:m});else s.set(w,[{file:a,whole:x,tag:p,attrs:l,body:m}])}}let r=[...s.values()].filter((a)=>new Set(a.map((f)=>f.file)).size>1);if(r.length===0)return t;let o=T.join(e,S),g=new Map(i),u=new Map,c=[];for(let a of r){let{tag:f,body:M}=a[0],d=f.toLowerCase()==="script",x=`${d?"chunk":"style"}.${B(M)}.${d?"js":"css"}`;c.push({filename:x,contents:M,contentType:d?"text/javascript; charset=utf-8":"text/css; charset=utf-8"});let p=`/${S}/${x}`;for(let l of a){let m=d?`<script${l.attrs} src="${p}"></script>`:`<link${l.attrs} rel="stylesheet" href="${p}">`,w=g.get(l.file),b=w.replace(l.whole,()=>m);if(b===w)continue;g.set(l.file,b),u.set(l.file,(u.get(l.file)??0)+l.body.length)}}h.mkdirSync(o,{recursive:!0});for(let a of c)h.writeFileSync(T.join(o,a.filename),a.contents),t.assets++;for(let[a,f]of g){if(f===i.get(a))continue;h.writeFileSync(a,f),t.pages++,t.bytesInlined+=u.get(a)??0}return t}import E from"fs";import v from"path";var K="layout-types.d.ts";function P(e){let t=[],n=(i,s)=>{let r;try{r=E.readdirSync(i,{withFileTypes:!0})}catch{return}for(let o of r){if(o.name.startsWith("."))continue;let g=v.join(i,o.name);if(o.isDirectory())n(g,s?`${s}/${o.name}`:o.name);else if(o.isFile()&&o.name.endsWith(".stx")&&o.name!=="_layout.stx"){let u=o.name.slice(0,-4);t.push(s?`${s}/${u}`:u)}}};return n(e,""),t.sort()}function W(e){let t=["// Auto-generated by stx \u2014 do not edit.","//","// Makes `definePageMeta({ layout })` reject a name with no layout behind it.","// Include this file in your tsconfig (it lives in the stx state directory,","// `.stx/` by default) for the check to apply.",""];if(e.length===0)return t.push("// No layouts found \u2014 `layout` stays typed as `string`.","export {}",""),t.join(`
2
+ import y from"fs";import R from"path";var S="_stx";function F(e){return Bun.hash(e).toString(16).slice(0,8)}function k(e){let t=[],n=(i)=>{for(let s of y.readdirSync(i,{withFileTypes:!0})){let r=R.join(i,s.name);if(s.isDirectory())n(r);else if(s.isFile()&&r.endsWith(".html"))t.push(r)}};if(y.existsSync(e))n(e);return t}var z=[{pattern:/<script\b([^>]*\bdata-stx-runtime\b[^>]*)>([\s\S]*?)<\/script>/gi,prefix:"runtime",extension:"js",contentType:"text/javascript; charset=utf-8",replace:(e)=>`<script data-stx-runtime src="${e}"></script>`},{pattern:/<script\b([^>]*\bdata-stx-router\b[^>]*)>([\s\S]*?)<\/script>/gi,prefix:"router",extension:"js",contentType:"text/javascript; charset=utf-8",replace:(e)=>`<script data-stx-router src="${e}"></script>`},{pattern:/<style\b([^>]*\bdata-css=(?:"generated"|'generated')[^>]*)>([\s\S]*?)<\/style>/gi,prefix:"css",extension:"css",contentType:"text/css; charset=utf-8",replace:(e)=>`<link data-css="generated" rel="stylesheet" href="${e}">`}];function I(e,t=`/${S}`){let n=[],i=new Set,s=0,r=e;for(let o of z)r=r.replace(o.pattern,(g,u,c)=>{if(/\b(?:src|href)\s*=/.test(u)||!c.trim())return g;let a=`${o.prefix}.${F(c)}.${o.extension}`;if(!i.has(a))i.add(a),n.push({filename:a,contents:c,contentType:o.contentType});return s+=c.length,o.replace(`${t}/${a}`)});return{html:r,assets:n,bytesInlined:s}}function rc(e){let t={pages:0,assets:0,bytesInlined:0},n=R.join(e,S),i=new Set;for(let s of k(e)){let r=y.readFileSync(s,"utf8"),{html:o,assets:g,bytesInlined:u}=I(r);if(o===r)continue;for(let c of g){if(i.has(c.filename))continue;i.add(c.filename),y.mkdirSync(n,{recursive:!0}),y.writeFileSync(R.join(n,c.filename),c.contents),t.assets++}y.writeFileSync(s,o),t.bytesInlined+=u,t.pages++}return t}import h from"fs";import T from"path";var L=1024,N=/<(script|style)\b([^>]*)>([\s\S]*?)<\/\1>/gi,_=new Set(["","module","text/javascript","application/javascript","module/javascript"]);function B(e){return Bun.hash(e).toString(16).slice(0,8)}function C(e){let t=[],n=(i)=>{for(let s of h.readdirSync(i,{withFileTypes:!0})){let r=T.join(i,s.name);if(s.isDirectory())n(r);else if(s.isFile()&&r.endsWith(".html"))t.push(r)}};if(h.existsSync(e))n(e);return t}function O(e,t){let n=e.match(new RegExp(`\\b${t}\\s*=\\s*("([^"]*)"|'([^']*)'|([^\\s>]+))`,"i"));if(!n)return;return n[2]??n[3]??n[4]??""}function H(e,t,n){if(n.length<L)return!1;if(/\b(?:src|href)\s*=/i.test(t))return!1;if(e.toLowerCase()==="script"){if(!_.has((O(t,"type")??"").trim().toLowerCase()))return!1;return!0}return!0}function D(e){let t=[];for(let n of e.matchAll(/<template\b[^>]*>[\s\S]*?<\/template>/gi))t.push([n.index,n.index+n[0].length]);return t}function sc(e){let t={pages:0,assets:0,bytesInlined:0},n=C(e);if(n.length<2)return t;let i=new Map,s=new Map;for(let a of n){let f=h.readFileSync(a,"utf8");i.set(a,f);let M=D(f);for(let d of f.matchAll(N)){let[x,p,l,m]=d;if(!H(p,l,m))continue;if(M.some(([j,A])=>d.index>=j&&d.index<A))continue;let w=`${p.toLowerCase()}\x00${m}`,b=s.get(w);if(b)b.push({file:a,whole:x,tag:p,attrs:l,body:m});else s.set(w,[{file:a,whole:x,tag:p,attrs:l,body:m}])}}let r=[...s.values()].filter((a)=>new Set(a.map((f)=>f.file)).size>1);if(r.length===0)return t;let o=T.join(e,S),g=new Map(i),u=new Map,c=[];for(let a of r){let{tag:f,body:M}=a[0],d=f.toLowerCase()==="script",x=`${d?"chunk":"style"}.${B(M)}.${d?"js":"css"}`;c.push({filename:x,contents:M,contentType:d?"text/javascript; charset=utf-8":"text/css; charset=utf-8"});let p=`/${S}/${x}`;for(let l of a){let m=d?`<script${l.attrs} src="${p}"></script>`:`<link${l.attrs} rel="stylesheet" href="${p}">`,w=g.get(l.file),b=w.replace(l.whole,()=>m);if(b===w)continue;g.set(l.file,b),u.set(l.file,(u.get(l.file)??0)+l.body.length)}}h.mkdirSync(o,{recursive:!0});for(let a of c)h.writeFileSync(T.join(o,a.filename),a.contents),t.assets++;for(let[a,f]of g){if(f===i.get(a))continue;h.writeFileSync(a,f),t.pages++,t.bytesInlined+=u.get(a)??0}return t}import E from"fs";import v from"path";var K="layout-types.d.ts";function P(e){let t=[],n=(i,s)=>{let r;try{r=E.readdirSync(i,{withFileTypes:!0})}catch{return}for(let o of r){if(o.name.startsWith("."))continue;let g=v.join(i,o.name);if(o.isDirectory())n(g,s?`${s}/${o.name}`:o.name);else if(o.isFile()&&o.name.endsWith(".stx")&&o.name!=="_layout.stx"){let u=o.name.slice(0,-4);t.push(s?`${s}/${u}`:u)}}};return n(e,""),t.sort()}function W(e){let t=["// Auto-generated by stx \u2014 do not edit.","//","// Makes `definePageMeta({ layout })` reject a name with no layout behind it.","// Include this file in your tsconfig (it lives in the stx state directory,","// `.stx/` by default) for the check to apply.",""];if(e.length===0)return t.push("// No layouts found \u2014 `layout` stays typed as `string`.","export {}",""),t.join(`
3
3
  `);return t.push("declare module '@stacksjs/stx' {"," interface KnownLayouts {",...e.map((n)=>` '${n}': true`)," }","}","","export {}",""),t.join(`
4
- `)}function rc(e,t){if(!e)return[];let n=v.isAbsolute(e)?e:v.resolve(process.cwd(),e),i=P(n),s=W(i),r=v.join(t,K);try{if(E.existsSync(r)&&E.readFileSync(r,"utf8")===s)return i;E.mkdirSync(t,{recursive:!0}),E.writeFileSync(r,s)}catch{}return i}
5
- export{tc,nc,rc};
4
+ `)}function oc(e,t){if(!e)return[];let n=v.isAbsolute(e)?e:v.resolve(process.cwd(),e),i=P(n),s=W(i),r=v.join(t,K);try{if(E.existsSync(r)&&E.readFileSync(r,"utf8")===s)return i;E.mkdirSync(t,{recursive:!0}),E.writeFileSync(r,s)}catch{}return i}
5
+ export{rc,sc,oc};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- var{WebView:p}=globalThis.Bun;import{existsSync as y,mkdirSync as b,readdirSync as v,statSync as S}from"fs";import l from"path";var h=16384;function M(e){if(/^https?:\/\//.test(e)||e.startsWith("file://"))return e;return`file://${l.resolve(e)}`}function g(e,n,t,o){return new Promise((s)=>{let i=!1,r,m,c=()=>{if(!i){if(i=!0,clearTimeout(m),r)clearTimeout(r);e.onNavigated=void 0,s()}};m=setTimeout(c,o),e.onNavigated=()=>{if(!i)r=setTimeout(c,t)};try{let u=e.navigate(n);if(u&&typeof u.catch==="function")u.catch(c)}catch{c()}})}async function w(e,n,t){let o=`!!document.querySelector(${JSON.stringify(n)})`,s=Date.now()+t;while(Date.now()<s){try{if(await e.evaluate(o))return}catch{}await new Promise((i)=>setTimeout(i,100))}}async function T(e){try{let n=await e.evaluate("Math.ceil(Math.max(document.documentElement.scrollHeight, document.documentElement.offsetHeight, document.body ? document.body.scrollHeight : 0, document.body ? document.body.offsetHeight : 0))");return typeof n==="number"&&Number.isFinite(n)&&n>0?Math.min(n,h):0}catch{return 0}}async function Il(e,n,t={}){let o=Math.min(t.width??1440,h),s=Math.min(t.height??2200,h),i=t.waitMs??800,r=t.timeoutMs??15000,m=t.format??"png",c=M(e),u=(f)=>new p({width:o,height:f,headless:!0,...t.backend?{backend:t.backend}:{}}),a=u(s);try{if(await g(a,c,i,r),t.waitSelector)await w(a,t.waitSelector,r);if(t.fullPage){let d=await T(a);if(d>s){if(a.close(),a=u(d),await g(a,c,i,r),t.waitSelector)await w(a,t.waitSelector,r)}}let f=await a.screenshot({encoding:"buffer",format:m});b(l.dirname(l.resolve(n)),{recursive:!0}),await Bun.write(n,f)}finally{a.close()}if(!y(n))throw Error(`Screenshot was not produced for ${e}`);return{input:e,output:n,bytes:S(n).size}}async function Jg(e,n,t={}){b(n,{recursive:!0});let o;if(!/^https?:\/\//.test(e)&&y(e)&&S(e).isDirectory())o=v(e).filter((r)=>r.endsWith(".html")).map((r)=>l.join(e,r));else o=[e];let s=t.format??"png",i=[];for(let r of o){let m=/^https?:\/\//.test(r)?new URL(r).pathname.replace(/\W+/g,"-").replace(/^-|-$/g,"")||"index":l.basename(r).replace(/\.html?$/,"");i.push(await Il(r,l.join(n,`${m}.${s}`),t))}return i}
3
- export{Il,Jg};
2
+ var{WebView:p}=globalThis.Bun;import{existsSync as y,mkdirSync as b,readdirSync as v,statSync as S}from"fs";import l from"path";var h=16384;function M(e){if(/^https?:\/\//.test(e)||e.startsWith("file://"))return e;return`file://${l.resolve(e)}`}function g(e,n,t,o){return new Promise((s)=>{let i=!1,r,m,c=()=>{if(!i){if(i=!0,clearTimeout(m),r)clearTimeout(r);e.onNavigated=void 0,s()}};m=setTimeout(c,o),e.onNavigated=()=>{if(!i)r=setTimeout(c,t)};try{let u=e.navigate(n);if(u&&typeof u.catch==="function")u.catch(c)}catch{c()}})}async function w(e,n,t){let o=`!!document.querySelector(${JSON.stringify(n)})`,s=Date.now()+t;while(Date.now()<s){try{if(await e.evaluate(o))return}catch{}await new Promise((i)=>setTimeout(i,100))}}async function T(e){try{let n=await e.evaluate("Math.ceil(Math.max(document.documentElement.scrollHeight, document.documentElement.offsetHeight, document.body ? document.body.scrollHeight : 0, document.body ? document.body.offsetHeight : 0))");return typeof n==="number"&&Number.isFinite(n)&&n>0?Math.min(n,h):0}catch{return 0}}async function Nl(e,n,t={}){let o=Math.min(t.width??1440,h),s=Math.min(t.height??2200,h),i=t.waitMs??800,r=t.timeoutMs??15000,m=t.format??"png",c=M(e),u=(f)=>new p({width:o,height:f,headless:!0,...t.backend?{backend:t.backend}:{}}),a=u(s);try{if(await g(a,c,i,r),t.waitSelector)await w(a,t.waitSelector,r);if(t.fullPage){let d=await T(a);if(d>s){if(a.close(),a=u(d),await g(a,c,i,r),t.waitSelector)await w(a,t.waitSelector,r)}}let f=await a.screenshot({encoding:"buffer",format:m});b(l.dirname(l.resolve(n)),{recursive:!0}),await Bun.write(n,f)}finally{a.close()}if(!y(n))throw Error(`Screenshot was not produced for ${e}`);return{input:e,output:n,bytes:S(n).size}}async function Zg(e,n,t={}){b(n,{recursive:!0});let o;if(!/^https?:\/\//.test(e)&&y(e)&&S(e).isDirectory())o=v(e).filter((r)=>r.endsWith(".html")).map((r)=>l.join(e,r));else o=[e];let s=t.format??"png",i=[];for(let r of o){let m=/^https?:\/\//.test(r)?new URL(r).pathname.replace(/\W+/g,"-").replace(/^-|-$/g,"")||"index":l.basename(r).replace(/\.html?$/,"");i.push(await Nl(r,l.join(n,`${m}.${s}`),t))}return i}
3
+ export{Nl,Zg};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{Kl,Sm,Xl,Gl,km,_m}from"./chunk-h9778nxm.js";import"./chunk-ybgzr6wn.js";import"./chunk-5ghw26vq.js";import"./chunk-46t924aw.js";import"./chunk-eg2p1cyw.js";import"./chunk-xppm4cs4.js";import"./chunk-0wms5teg.js";export{_m as applySlots,km as extractSlotContent,Sm as parseSlotElement,Kl as parseSlots,Gl as processSlots,Xl as renderSlot};