@stacksjs/stx 0.2.919 → 0.2.921
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.
- package/dist/chunk-0678sab4.js +2 -0
- package/dist/chunk-0bnv0aaz.js +2 -0
- package/dist/chunk-0bvfm5h5.js +2 -0
- package/dist/chunk-0c3q5h03.js +2 -0
- package/dist/chunk-0fh84wr5.js +2 -0
- package/dist/chunk-0p9x0m5n.js +2 -0
- package/dist/{chunk-m390z8w8.js → chunk-0rq1w0xr.js} +7 -7
- package/dist/{chunk-fwxgzktt.js → chunk-1pc2p489.js} +2 -2
- package/dist/{chunk-2szhk8mh.js → chunk-29cy41z3.js} +4 -4
- package/dist/{chunk-9mack1g8.js → chunk-2d0pemtc.js} +3 -3
- package/dist/{chunk-1bf0grbf.js → chunk-2qnpr0ty.js} +3 -3
- package/dist/{chunk-fjpt8arw.js → chunk-2r2tayyd.js} +2 -2
- package/dist/chunk-2sfxj244.js +2 -0
- package/dist/{chunk-wxqay5c2.js → chunk-30d298vs.js} +1 -1
- package/dist/{chunk-d69k67bn.js → chunk-36j2drjv.js} +9 -9
- package/dist/{chunk-9gr7m3tb.js → chunk-3d0bjcn7.js} +1 -1
- package/dist/chunk-3k9d0h11.js +2 -0
- package/dist/{chunk-whnzf9hn.js → chunk-3mc9ew9r.js} +6 -6
- package/dist/chunk-43r0h76m.js +2 -0
- package/dist/{chunk-cbqe84g3.js → chunk-4f8h38xr.js} +2 -2
- package/dist/{chunk-858p3hkz.js → chunk-4jg8ddfy.js} +2 -2
- package/dist/chunk-4jh5t3rz.js +2 -0
- package/dist/{chunk-rk16391e.js → chunk-4nabpd82.js} +5 -5
- package/dist/{chunk-p3x7kwb5.js → chunk-4w203ddt.js} +6 -6
- package/dist/chunk-4y2k14ec.js +2 -0
- package/dist/chunk-57xcb1wn.js +2 -0
- package/dist/chunk-5ekbye3p.js +2 -0
- package/dist/chunk-5s1q4y2j.js +2 -0
- package/dist/chunk-6359fekc.js +2 -0
- package/dist/{chunk-wv0wsavj.js → chunk-66cz2ph7.js} +2 -2
- package/dist/{chunk-p0xqm2ne.js → chunk-7767n5k6.js} +1 -1
- package/dist/{chunk-xpsg91dh.js → chunk-78j6c3sf.js} +5 -5
- package/dist/{chunk-qtzfbv7e.js → chunk-7d0h2pa3.js} +5 -5
- package/dist/{chunk-jgtn9t5n.js → chunk-7g720sk3.js} +2 -2
- package/dist/chunk-7nshr15z.js +2 -0
- package/dist/{chunk-14df2jzs.js → chunk-875wejw1.js} +2 -2
- package/dist/chunk-8g6cmgn8.js +2 -0
- package/dist/chunk-8gfdy17b.js +2 -0
- package/dist/{chunk-fn0y9z1t.js → chunk-8vjsmyrk.js} +5 -5
- package/dist/chunk-8yx65vb0.js +2 -0
- package/dist/{chunk-09xqy448.js → chunk-90ps064x.js} +2 -2
- package/dist/chunk-91nwc581.js +2 -0
- package/dist/{chunk-yzqb7y45.js → chunk-94001bha.js} +5 -5
- package/dist/chunk-94skx5m6.js +2 -0
- package/dist/chunk-9aegppj7.js +2 -0
- package/dist/{chunk-gjyz5ma7.js → chunk-9ch2qhbw.js} +1 -1
- package/dist/{chunk-m6hrb7rm.js → chunk-9sk596tw.js} +25 -25
- package/dist/{chunk-3ftrv1f7.js → chunk-a3qb13vr.js} +20 -20
- package/dist/chunk-a5vzdhsk.js +2 -0
- package/dist/{chunk-jjq7c8s2.js → chunk-a78k8fkg.js} +2 -2
- package/dist/{chunk-txk2z7v0.js → chunk-ag07tdhn.js} +4 -4
- package/dist/{chunk-0wctbtad.js → chunk-amnfd29h.js} +3 -3
- package/dist/chunk-aqh48tyw.js +2 -0
- package/dist/{chunk-zaj3nnvv.js → chunk-avtq2p0c.js} +2 -2
- package/dist/{chunk-3kpxkjgm.js → chunk-b0kq5mzq.js} +2 -2
- package/dist/chunk-b6am4h24.js +2 -0
- package/dist/{chunk-qzqqzraq.js → chunk-b9z4nb1v.js} +6 -6
- package/dist/{chunk-d4xjwebv.js → chunk-bwnx71s8.js} +5 -5
- package/dist/{chunk-mr9pp5cf.js → chunk-c3nmjx26.js} +2 -2
- package/dist/chunk-cajg2sz0.js +2 -0
- package/dist/{chunk-3efpqm1f.js → chunk-dhx4m7mf.js} +2 -2
- package/dist/chunk-dktqmf4t.js +2 -0
- package/dist/chunk-dqwxyk1m.js +2 -0
- package/dist/chunk-e2kk1d9z.js +2 -0
- package/dist/{chunk-zrxvj3zf.js → chunk-e8aqkt1b.js} +6 -6
- package/dist/{chunk-mztjpp7m.js → chunk-e8hvbc53.js} +2 -2
- package/dist/{chunk-kk9h53xg.js → chunk-edjzm0vj.js} +3 -3
- package/dist/chunk-ee4ejnk2.js +2 -0
- package/dist/chunk-eezp4a40.js +2 -0
- package/dist/chunk-eh2ynja3.js +2 -0
- package/dist/chunk-emk29htn.js +2 -0
- package/dist/{chunk-xq5s4vc1.js → chunk-eqj8nj5c.js} +1 -1
- package/dist/{chunk-ktv65e3n.js → chunk-f8sh6289.js} +7 -7
- package/dist/{chunk-6n6kndk0.js → chunk-fb1hyhgf.js} +3 -3
- package/dist/chunk-fd0vnz09.js +2 -0
- package/dist/chunk-fyhtp2nt.js +2 -0
- package/dist/{chunk-xk7hdpq5.js → chunk-g2fxp9zp.js} +3 -3
- package/dist/chunk-gbct53j0.js +2 -0
- package/dist/{chunk-m9ta0640.js → chunk-gsm3rk4j.js} +2 -2
- package/dist/{chunk-x40j67z1.js → chunk-gt9bt8xa.js} +2 -2
- package/dist/{chunk-ft34x0h1.js → chunk-gxdy4qjj.js} +4 -4
- package/dist/chunk-gxtq25gr.js +2 -0
- package/dist/chunk-h1dnjn9g.js +2 -0
- package/dist/{chunk-yvaqgdv1.js → chunk-h7z23fpq.js} +1 -1
- package/dist/{chunk-sxrcac01.js → chunk-hakevnm1.js} +2 -2
- package/dist/chunk-hn7fv830.js +2 -0
- package/dist/chunk-hx6tr46s.js +1459 -0
- package/dist/chunk-jenk04c8.js +2 -0
- package/dist/{chunk-1baxccfq.js → chunk-jfy0r3hx.js} +24 -24
- package/dist/{chunk-9zwmfkfg.js → chunk-jh007a8k.js} +5 -5
- package/dist/chunk-jh1hdq31.js +3 -0
- package/dist/{chunk-tb4be5ct.js → chunk-jk1hzawb.js} +3 -3
- package/dist/{chunk-hht7n4zd.js → chunk-jya12bfn.js} +2 -2
- package/dist/chunk-k1qbgpfy.js +2 -0
- package/dist/chunk-kgmwja6f.js +2 -0
- package/dist/{chunk-z6nyyt3n.js → chunk-khf62zkn.js} +5 -5
- package/dist/chunk-kppj8rqa.js +2 -0
- package/dist/{chunk-514yg4dr.js → chunk-m3ra99h8.js} +6 -6
- package/dist/{chunk-qsnw0qyp.js → chunk-m8rzaqm8.js} +2 -2
- package/dist/chunk-msvphygp.js +2 -0
- package/dist/chunk-mzbejejf.js +2 -0
- package/dist/{chunk-v1x96kjr.js → chunk-nkgqhb7s.js} +7 -7
- package/dist/{chunk-9707zz6v.js → chunk-p17jeqz0.js} +2 -2
- package/dist/{chunk-2f46pcg0.js → chunk-pe5sstex.js} +2 -2
- package/dist/{chunk-vtj3dwhh.js → chunk-pqr4gn9b.js} +2 -2
- package/dist/{chunk-40j2pmnb.js → chunk-prj38cyp.js} +5 -5
- package/dist/{chunk-mn9t5fnv.js → chunk-q8snpht6.js} +2 -2
- package/dist/chunk-q99y5115.js +3 -0
- package/dist/{chunk-7axtwg1f.js → chunk-qzspvwv6.js} +2 -2
- package/dist/chunk-r02asm46.js +2 -0
- package/dist/{chunk-vf7tpgqz.js → chunk-r7zvrh58.js} +16 -16
- package/dist/{chunk-ex6dne7e.js → chunk-ra35ptjg.js} +2 -2
- package/dist/chunk-rc4712qh.js +2 -0
- package/dist/chunk-rq7sg012.js +33 -0
- package/dist/{chunk-v060015m.js → chunk-rt4gzqs9.js} +1 -1
- package/dist/chunk-rx1xw7q2.js +2 -0
- package/dist/{chunk-mnpfvxpa.js → chunk-rzmephr2.js} +30 -30
- package/dist/{chunk-0xyfs691.js → chunk-s3rhbwgf.js} +4 -4
- package/dist/{chunk-xap1f1bw.js → chunk-s6w14v6h.js} +2 -2
- package/dist/{chunk-nkbnsbb0.js → chunk-sdvv8zge.js} +2 -2
- package/dist/{chunk-3br07y64.js → chunk-sgppgy5e.js} +5 -5
- package/dist/{chunk-v1a5h1tc.js → chunk-sk7pptzf.js} +9 -9
- package/dist/{chunk-50zzar2c.js → chunk-sk8x8nw8.js} +3 -3
- package/dist/chunk-skjm3zdh.js +2 -0
- package/dist/{chunk-5fdc8pej.js → chunk-t4exh7c9.js} +7 -7
- package/dist/{chunk-3hfv217t.js → chunk-t64mp8x1.js} +6 -6
- package/dist/{chunk-neymp1bb.js → chunk-tfpd7aht.js} +3 -3
- package/dist/chunk-tsnzhke9.js +2 -0
- package/dist/{chunk-yye2pec5.js → chunk-tt6n2mx6.js} +14 -14
- package/dist/chunk-txyze88n.js +2 -0
- package/dist/chunk-v1t7sees.js +2 -0
- package/dist/{chunk-1a2c4pv8.js → chunk-vhp5hqwp.js} +10 -10
- package/dist/{chunk-1vsjmwr1.js → chunk-vn3hsx7v.js} +2 -2
- package/dist/chunk-vt410s5m.js +2 -0
- package/dist/{chunk-3tcy9r6r.js → chunk-w27j0apm.js} +14 -14
- package/dist/{chunk-2zb642qr.js → chunk-w5vxzk5j.js} +6 -6
- package/dist/chunk-w81a1e14.js +9 -0
- package/dist/{chunk-tnbzg7fd.js → chunk-wajvxzt0.js} +2 -2
- package/dist/chunk-wrva7jes.js +2 -0
- package/dist/{chunk-p4twxjfs.js → chunk-ws25jw6x.js} +3 -3
- package/dist/{chunk-m86sjbx7.js → chunk-ww24mxmd.js} +3 -3
- package/dist/chunk-xdprx6tx.js +1331 -0
- package/dist/chunk-xgv3gy1b.js +2 -0
- package/dist/chunk-xjhv5e5f.js +2 -0
- package/dist/chunk-xnvh4jk2.js +21 -0
- package/dist/chunk-xtakhmnb.js +2 -0
- package/dist/{chunk-zb6my502.js → chunk-y97g0kwc.js} +1 -1
- package/dist/chunk-y9f9d4zv.js +2 -0
- package/dist/{chunk-qda8tmk9.js → chunk-yfe380a4.js} +2 -2
- package/dist/{chunk-6x5a2w5a.js → chunk-ygtz9kc7.js} +2 -2
- package/dist/chunk-yyypc7s3.js +2 -0
- package/dist/chunk-z5j4prza.js +2 -0
- package/dist/{chunk-2jm7map2.js → chunk-z68teecy.js} +2 -2
- package/dist/cli.js +20 -20
- package/dist/composables/use-media-query.js +23 -22
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/native/accessibility.d.ts +1 -1
- package/dist/native/accessibility.js +5 -3
- package/dist/native/bridge/protocol.d.ts +1 -0
- package/dist/native/compiler/html-to-ir.js +14 -1
- package/dist/native/compiler/ir.d.ts +7 -0
- package/dist/native/components/primitives.d.ts +1 -0
- package/dist/native/event-names.js +4 -0
- package/dist/native/prop-names.js +3 -1
- package/dist/native/runtime/browser-renderer.js +4 -0
- package/dist/native/runtime/craft-bridge.js +1 -0
- package/dist/native/runtime/craft.d.ts +3 -0
- package/dist/native/runtime/jsc-globals.js +1 -1
- package/dist/native/runtime/native-media.js +8 -3
- package/dist/native/runtime/shared-screen.js +8 -3
- package/dist/native/testing.d.ts +2 -1
- package/dist/native/testing.js +2 -1
- package/dist/process.js +6 -3
- package/dist/pwa.js +3 -3
- package/dist/signal-processing.d.ts +2 -2
- package/dist/signal-processing.js +17 -11
- package/dist/ssg.js +9 -9
- package/dist/utils.js +2 -1
- package/dist/vue-template.d.ts +2 -0
- package/dist/vue-template.js +72 -2
- package/package.json +6 -6
- package/dist/chunk-0ebaf0pr.js +0 -2
- package/dist/chunk-0jjq552g.js +0 -2
- package/dist/chunk-15rc8t28.js +0 -2
- package/dist/chunk-1jrhjn2b.js +0 -2
- package/dist/chunk-1svffhzq.js +0 -2
- package/dist/chunk-2m4ydym0.js +0 -33
- package/dist/chunk-2mv29s6w.js +0 -9
- package/dist/chunk-3aayrnbh.js +0 -21
- package/dist/chunk-426gq0g5.js +0 -2
- package/dist/chunk-4ge80k8j.js +0 -2
- package/dist/chunk-4vdfqr64.js +0 -2
- package/dist/chunk-4yz33vzb.js +0 -2
- package/dist/chunk-4zcswx6x.js +0 -2
- package/dist/chunk-5ht628zp.js +0 -2
- package/dist/chunk-67zy5p7x.js +0 -2
- package/dist/chunk-8153bfpx.js +0 -2
- package/dist/chunk-86p0m920.js +0 -2
- package/dist/chunk-88texeh4.js +0 -2
- package/dist/chunk-8mye65n9.js +0 -2
- package/dist/chunk-8ycgk8w6.js +0 -2
- package/dist/chunk-9xcsn4pb.js +0 -2
- package/dist/chunk-a5tg553d.js +0 -2
- package/dist/chunk-agxxqjjt.js +0 -2
- package/dist/chunk-b44pvac7.js +0 -2
- package/dist/chunk-b4yp16a2.js +0 -2
- package/dist/chunk-fb63xppz.js +0 -2
- package/dist/chunk-ffqqkeye.js +0 -2
- package/dist/chunk-g1v12bjm.js +0 -2
- package/dist/chunk-gg0kkn2e.js +0 -2
- package/dist/chunk-ggg8b8n1.js +0 -2
- package/dist/chunk-ggrcg7k7.js +0 -2
- package/dist/chunk-gmn9ba8f.js +0 -3
- package/dist/chunk-gqe574d9.js +0 -2
- package/dist/chunk-hajamm16.js +0 -2
- package/dist/chunk-hg2n2264.js +0 -2
- package/dist/chunk-hxabvt31.js +0 -2
- package/dist/chunk-j3sat6vn.js +0 -2
- package/dist/chunk-j9gbnqxq.js +0 -2
- package/dist/chunk-jj2z4nxa.js +0 -2
- package/dist/chunk-k289127j.js +0 -2
- package/dist/chunk-m1hfh2t4.js +0 -2
- package/dist/chunk-m3qwqhxp.js +0 -2
- package/dist/chunk-m9smh7fs.js +0 -2
- package/dist/chunk-mhnjtc42.js +0 -2
- package/dist/chunk-n4bxb2hx.js +0 -2
- package/dist/chunk-n958bxm6.js +0 -2
- package/dist/chunk-nkr1aa5z.js +0 -2
- package/dist/chunk-p3vswt0f.js +0 -2
- package/dist/chunk-p8wnp4p1.js +0 -2
- package/dist/chunk-q3z252d9.js +0 -2
- package/dist/chunk-qfkak3jb.js +0 -2
- package/dist/chunk-rt7xy537.js +0 -2
- package/dist/chunk-rwjye578.js +0 -2
- package/dist/chunk-sbr3wg75.js +0 -1467
- package/dist/chunk-sftznswb.js +0 -2
- package/dist/chunk-tz5ktd6d.js +0 -2
- package/dist/chunk-vb609vbj.js +0 -1323
- package/dist/chunk-vtcyber4.js +0 -2
- package/dist/chunk-wq2bpt0w.js +0 -2
- package/dist/chunk-wv8zt78c.js +0 -2
- package/dist/chunk-xakqpa4z.js +0 -3
- package/dist/chunk-xy3ex6ht.js +0 -2
- package/dist/chunk-y899wtm8.js +0 -2
- package/dist/chunk-ye45znz5.js +0 -2
- package/dist/chunk-yegp50jb.js +0 -2
- package/dist/chunk-yq9aqpk8.js +0 -2
- package/dist/chunk-zt45dqfx.js +0 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{B,In,Kt,Xt,b,s,
|
|
2
|
+
import{B,In,Kt,Xt,b,s,Ee,m}from"./chunk-xdprx6tx.js";import{It,Ue,Bc,$s,ci,li,i}from"./chunk-hx6tr46s.js";import{xe}from"./chunk-a78k8fkg.js";import{le,Kr,De,X,Fn,nn,nt,Le,J}from"./chunk-r7zvrh58.js";import{Ar,Pr}from"./chunk-1pc2p489.js";import{Lt,Or,Gs,Js,Ys,jt,Bt,Ft,zt,Ht,Ut,We}from"./chunk-t4exh7c9.js";import{Us,a,j}from"./chunk-w27j0apm.js";import{Fa,Uo,ms,it,za,$t,Fe}from"./chunk-rq7sg012.js";import{e,Cn,Cr,S}from"./chunk-0rq1w0xr.js";import{ut}from"./chunk-vhp5hqwp.js";import{He}from"./chunk-s1x2pc9b.js";import{Gn}from"./chunk-sdvv8zge.js";import{oe,Pe,Ie}from"./chunk-nkgqhb7s.js";import{l}from"./chunk-ygtz9kc7.js";import{se}from"./chunk-q99y5115.js";import{c,f}from"./chunk-ws25jw6x.js";async function Pn(n){try{let t=await Bun.file(n).text(),o=En(t),d=On(t,n),r=An(t,o),p=Dn(t,o);return{file:n,metrics:o,issues:d,suggestions:r,performance:p}}catch(t){throw Error(`Failed to analyze template ${n}: ${t instanceof Error?t.message:String(t)}`)}}function En(n){let t=n.split(`
|
|
3
3
|
`),o=n.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),r=(o?o[1]:"").split(`
|
|
4
4
|
`).length,p={conditionals:(n.match(/@(if|unless|elseif|else|endif|endunless)\b/g)||[]).length,loops:(n.match(/@(foreach|for|endforeach|endfor|while|endwhile)\b/g)||[]).length,includes:(n.match(/@(include|component|extends|section|yield)\b/g)||[]).length,custom:0,total:0};p.total=p.conditionals+p.loops+p.includes+p.custom;let u=(n.match(/\{\{[\s\S]*?\}\}/g)||[]).length,g=(n.match(/\{!![\s\S]*?!!\}/g)||[]).length,y=(n.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,h=u+g+y,x=(n.match(/<[A-Z][^>]*>/g)||[]).length,C=(n.match(/@(?:layout|extends)\(/g)||[]).length,R=0,O=0;for(let A of t)if(/@(?:if|unless|foreach|for|while|section)\b/.test(A)&&!/@end/.test(A)&&!/@else/.test(A))O++,R=Math.max(R,O);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(A))O--;let v=R>=4?3:0,w=Math.min(10,Math.ceil(p.total*0.5+h*0.1+x*0.3+(r>10?r*0.05:0)+v));return{lines:t.length,characters:n.length,directives:p,expressions:h,components:x,layouts:C,scriptLines:r,complexity:w}}function On(n,t){let o=[],d=Nt(n,"if","endif");if(d>0)o.push({type:"error",category:"syntax",message:`Found ${d} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let r=Nt(n,"foreach","endforeach");if(r>0)o.push({type:"error",category:"syntax",message:`Found ${r} unmatched @foreach directive(s)`,suggestion:"Ensure every @foreach has a corresponding @endforeach"});let p=n.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(p&&p.length>0)o.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let u=(n.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(u>0)o.push({type:"warning",category:"security",message:`Found ${u} raw output expression(s) {!! !!}`,suggestion:"Ensure raw outputs are properly sanitized to prevent XSS"});let g=n.match(/<img[^>]*>/g);if(g){let x=g.filter((C)=>!C.includes("alt="));if(x.length>0)o.push({type:"warning",category:"accessibility",message:`Found ${x.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let y=n.split(`
|
|
5
|
-
`).filter((x)=>x.length>120);if(y.length>0)o.push({type:"info",category:"maintainability",message:`Found ${y.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let h=(n.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(h>3)o.push({type:"info",category:"maintainability",message:`Found ${h} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return o}function An(n,t){let o=[];if(t.complexity>7)o.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(t.complexity>5&&t.directives.total>8)o.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(t.lines>100&&t.components===0)o.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(t.expressions>20)o.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let d=n.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(d&&d.length>0)o.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(t.directives.total===0&&t.expressions<5)o.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(t.scriptLines>50)o.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return o}function Dn(n,t){let o=1;if(o+=t.directives.conditionals*0.1,o+=t.directives.loops*0.5,o+=t.directives.includes*2,o+=t.expressions*0.05,o+=t.components*1,t.scriptLines>10)o+=t.scriptLines*0.1;let d;if(t.expressions===0&&t.directives.total===0)d="high";else if(t.expressions<5&&t.directives.total<3)d="medium";else d="low";let r=[];if(o>10)r.push("Consider optimizing template complexity");if(d==="low"&&t.directives.total>5)r.push("Reduce dynamic content for better caching");if(t.components===0&&t.lines>40)r.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(o*100)/100,complexityScore:t.complexity,cacheability:d,recommendations:r}}function Nt(n,t,o){let d=n.replace(/<!--[\s\S]*?-->/g,""),r=(d.match(new RegExp(`@${t}\\b`,"g"))||[]).length,p=(d.match(new RegExp(`@${o}\\b`,"g"))||[]).length;return Math.abs(r-p)}async function
|
|
5
|
+
`).filter((x)=>x.length>120);if(y.length>0)o.push({type:"info",category:"maintainability",message:`Found ${y.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let h=(n.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(h>3)o.push({type:"info",category:"maintainability",message:`Found ${h} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return o}function An(n,t){let o=[];if(t.complexity>7)o.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(t.complexity>5&&t.directives.total>8)o.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(t.lines>100&&t.components===0)o.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(t.expressions>20)o.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let d=n.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(d&&d.length>0)o.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(t.directives.total===0&&t.expressions<5)o.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(t.scriptLines>50)o.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return o}function Dn(n,t){let o=1;if(o+=t.directives.conditionals*0.1,o+=t.directives.loops*0.5,o+=t.directives.includes*2,o+=t.expressions*0.05,o+=t.components*1,t.scriptLines>10)o+=t.scriptLines*0.1;let d;if(t.expressions===0&&t.directives.total===0)d="high";else if(t.expressions<5&&t.directives.total<3)d="medium";else d="low";let r=[];if(o>10)r.push("Consider optimizing template complexity");if(d==="low"&&t.directives.total>5)r.push("Reduce dynamic content for better caching");if(t.components===0&&t.lines>40)r.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(o*100)/100,complexityScore:t.complexity,cacheability:d,recommendations:r}}function Nt(n,t,o){let d=n.replace(/<!--[\s\S]*?-->/g,""),r=(d.match(new RegExp(`@${t}\\b`,"g"))||[]).length,p=(d.match(new RegExp(`@${o}\\b`,"g"))||[]).length;return Math.abs(r-p)}async function Ra(n=["**/*.stx"],t){let o=[],d=[];for(let p of n){let u=await Array.fromAsync(new Bun.Glob(p).scan({cwd:t||process.cwd(),onlyFiles:!0,absolute:!0}));d.push(...u.filter((g)=>g.endsWith(".stx")))}for(let p of d)try{let u=await Pn(p);o.push(u)}catch(u){console.warn(`Failed to analyze ${p}:`,u)}let r=Mn(o);return{results:o,summary:r}}function Mn(n){let t=n.length,o=n.reduce((h,x)=>h+x.metrics.lines,0),d=t>0?n.reduce((h,x)=>h+x.metrics.complexity,0)/t:0,r=n.reduce((h,x)=>h+x.issues.length,0),p={};n.forEach((h)=>{h.issues.forEach((x)=>{p[x.category]=(p[x.category]||0)+1})});let u=t>0?n.reduce((h,x)=>h+x.performance.estimatedRenderTime,0)/t:0,g=Math.max(1,Math.min(10,Math.round(10-u/2-d/2))),y=[];if(d>6)y.push("Project has high average complexity. Consider refactoring complex templates.");if(r>t*2)y.push("High number of issues detected. Run detailed analysis on individual files.");if(p.security>0)y.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:t,totalLines:o,avgComplexity:Math.round(d*100)/100,totalIssues:r,issuesByCategory:p,performanceScore:g,recommendations:y}}var{serve:Wn}=globalThis.Bun;import Rt from"fs";import Ze from"path";function dt(){return`
|
|
6
6
|
/* Theme selector for code blocks */
|
|
7
7
|
.theme-selector {
|
|
8
8
|
margin: 1rem 0;
|
|
@@ -82,12 +82,12 @@ else {
|
|
|
82
82
|
<span class="frontmatter-label">${t}:</span>
|
|
83
83
|
<span>${Array.isArray(o)?o.join(", "):String(o)}</span>
|
|
84
84
|
</div>`).join("")}
|
|
85
|
-
</div>`}async function _n(n){let{default:t}=await import("net");return new Promise((o)=>{let d=t.createServer();d.once("error",()=>o(!1)),d.once("listening",()=>{d.close(()=>o(!0))}),d.listen(n,"0.0.0.0")})}async function Ln(n){let{default:t}=await import("net");return new Promise((o)=>{let d=t.createServer();d.once("error",()=>o(!1)),d.once("listening",()=>{d.close(()=>o(!0))}),d.listen(n,"::")})}async function jn(n){if(!await _n(n))return!1;return await Ln(n)}async function qe(n,t=20){n=Number(n);for(let o=0;o<t;o++){let d=n+o;if(await jn(d))return d}throw Error(`Could not find an available port between ${n} and ${n+t-1}`)}var Hn={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function Bn(){try{let n=await import("./chunk-
|
|
85
|
+
</div>`}async function _n(n){let{default:t}=await import("net");return new Promise((o)=>{let d=t.createServer();d.once("error",()=>o(!1)),d.once("listening",()=>{d.close(()=>o(!0))}),d.listen(n,"0.0.0.0")})}async function Ln(n){let{default:t}=await import("net");return new Promise((o)=>{let d=t.createServer();d.once("error",()=>o(!1)),d.once("listening",()=>{d.close(()=>o(!0))}),d.listen(n,"::")})}async function jn(n){if(!await _n(n))return!1;return await Ln(n)}async function qe(n,t=20){n=Number(n);for(let o=0;o<t;o++){let d=n+o;if(await jn(d))return d}throw Error(`Could not find an available port between ${n} and ${n+t-1}`)}var Hn={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function Bn(){try{let n=await import("./chunk-43r0h76m.js");if(typeof n.openDevWindow!=="function")return null;return n}catch{return null}}async function Qe(n,t={}){let o={...Hn,...t},d=await Bn();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 r=await d.openDevWindow(n,{title:o.title,width:o.width,height:o.height,darkMode:o.darkMode,hotReload:o.hotReload,titlebarHidden:o.titlebarHidden,nativeSidebar:o.nativeSidebar,sidebarWidth:o.sidebarWidth,sidebarConfig:o.sidebarConfig});if(r&&o.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return r}catch(r){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,r),!1}}function gt(n){if(n.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let r=n.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(r){let p=r[1];try{let u=`
|
|
86
86
|
${p}
|
|
87
87
|
return typeof sidebarConfig !== 'undefined' ? sidebarConfig : null;
|
|
88
88
|
`,y=Function(u)();if(y)return y}catch(u){console.warn("Invalid sidebarConfig:",u)}}return{sections:[]}}let o=n.match(/@nativeSidebar\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(o)try{return JSON.parse(o[1])}catch{console.warn("Invalid @nativeSidebar configuration")}let d=n.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(d)try{let r=d[1].match(/(?:export\s+(?:default\s+)?|const\s+\w+\s*=\s*)(\{[\s\S]*\})/m);if(r)return Function(`return ${r[1]}`)()}catch(r){console.warn("Invalid native-sidebar script configuration:",r)}return}function Ct(){console.log(`
|
|
89
89
|
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 zn(n){console.log(`${e.green}Server running at ${e.cyan}${n}${e.reset}`),console.log(`Press ${e.cyan}Ctrl+C${e.reset} to stop the server`),Ct()}function Nn(n){console.log(`${e.dim}Opening ${e.cyan}${n}${e.dim} in your browser...${e.reset}`),Bun.spawn(["open",n],{stderr:"inherit"})}function Ke(n,t,o){if(!process.stdin.isTTY)return;process.stdin.setRawMode(!0),process.stdin.setEncoding("utf8"),process.stdin.resume(),Ct();let d="";process.stdin.on("data",(r)=>{if(r==="\x03"){if(o?.onQuit)o.onQuit();t(),process.exit(0)}if(d+=r,d.endsWith("\r")||d.endsWith(`
|
|
90
|
-
`)){let p=d.trim().toLowerCase();d="",Un(p,n,t,o)}})}function Un(n,t,o,d){switch(n){case"o":if(d?.onOpen)d.onOpen();else Nn(t);break;case"c":if(d?.onClear)d.onClear();else console.clear(),zn(t);break;case"q":if(d?.onQuit)d.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),o(),process.exit(0);break;case"h":if(d?.onHelp)d.onHelp();else Ct();break;default:break}}async function Pt(n,t={}){let o=t.port||3000,d=t.watch!==!1,r=Ze.resolve(n);if(!Rt.existsSync(r))return console.error(`${e.red}Error: File not found: ${e.bright}${r}${e.reset}`),!1;if(!r.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${r}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${n}${e.reset}...`);let p=null,u=async()=>{try{let{content:C,data:R}=await Ue(r,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:j.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),O=t.markdown?.syntaxHighlighting||j.markdown?.syntaxHighlighting,v=O?.defaultTheme||"github-dark",w=["github-dark"],A=O?.additionalThemes||[],
|
|
90
|
+
`)){let p=d.trim().toLowerCase();d="",Un(p,n,t,o)}})}function Un(n,t,o,d){switch(n){case"o":if(d?.onOpen)d.onOpen();else Nn(t);break;case"c":if(d?.onClear)d.onClear();else console.clear(),zn(t);break;case"q":if(d?.onQuit)d.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),o(),process.exit(0);break;case"h":if(d?.onHelp)d.onHelp();else Ct();break;default:break}}async function Pt(n,t={}){let o=t.port||3000,d=t.watch!==!1,r=Ze.resolve(n);if(!Rt.existsSync(r))return console.error(`${e.red}Error: File not found: ${e.bright}${r}${e.reset}`),!1;if(!r.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${r}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${n}${e.reset}...`);let p=null,u=async()=>{try{let{content:C,data:R}=await Ue(r,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:j.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),O=t.markdown?.syntaxHighlighting||j.markdown?.syntaxHighlighting,v=O?.defaultTheme||"github-dark",w=["github-dark"],A=O?.additionalThemes||[],re=[...new Set([...w,...A])].map((L)=>`<option value="${L}"${L===v?" selected":""}>${L}</option>`).join(`
|
|
91
91
|
`);return p=`
|
|
92
92
|
<!DOCTYPE html>
|
|
93
93
|
<html lang="en">
|
|
@@ -241,7 +241,7 @@ Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in brow
|
|
|
241
241
|
</head>
|
|
242
242
|
<body>
|
|
243
243
|
${mt(R)}
|
|
244
|
-
${pt(
|
|
244
|
+
${pt(re)}
|
|
245
245
|
|
|
246
246
|
${C}
|
|
247
247
|
|
|
@@ -454,10 +454,10 @@ else {
|
|
|
454
454
|
};
|
|
455
455
|
})();
|
|
456
456
|
</script>
|
|
457
|
-
`}function Ne(n,t,o={}){let d=qn(t,o),r=c(n);if(r!==-1)return n.slice(0,r)+d+n.slice(r);if(n.includes("</html>"))return n.replace("</html>",`${d}</html>`);return n+d}function ht(n){let t=n.toLowerCase();return t.endsWith(".css")||t.endsWith(".scss")||t.endsWith(".sass")||t.endsWith(".less")}function yt(n){let t=n.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>t.endsWith(d))}function xt(n){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((o)=>o.test(n))}var et=null;function bt(n){if(!et)et=new Wt(n);return et}function st(){if(et)et.stop(),et=null}import vt from"path";var tt={name:"bun-plugin-stx",async setup(n){let o={...await a(),...n.config?.stx},d=new Set,r=o.webComponents?.enabled?`./${vt.relative(vt.dirname(n.config?.outdir||"dist"),o.webComponents.outputDir||"dist/web-components")}`:"/web-components",p=[];if(o.webComponents?.enabled)try{let u=await
|
|
457
|
+
`}function Ne(n,t,o={}){let d=qn(t,o),r=c(n);if(r!==-1)return n.slice(0,r)+d+n.slice(r);if(n.includes("</html>"))return n.replace("</html>",`${d}</html>`);return n+d}function ht(n){let t=n.toLowerCase();return t.endsWith(".css")||t.endsWith(".scss")||t.endsWith(".sass")||t.endsWith(".less")}function yt(n){let t=n.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>t.endsWith(d))}function xt(n){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((o)=>o.test(n))}var et=null;function bt(n){if(!et)et=new Wt(n);return et}function st(){if(et)et.stop(),et=null}import vt from"path";var tt={name:"bun-plugin-stx",async setup(n){let o={...await a(),...n.config?.stx},d=new Set,r=o.webComponents?.enabled?`./${vt.relative(vt.dirname(n.config?.outdir||"dist"),o.webComponents.outputDir||"dist/web-components")}`:"/web-components",p=[];if(o.webComponents?.enabled)try{let u=await Us(o,d);if(p.push(...u),o.debug&&u.length>0)console.log(`Successfully built ${u.length} web components`)}catch(u){console.error("Failed to build web components:",u)}n.onLoad({filter:/\.stx$/},async({path:u})=>{try{let g=new Set;if(o.cache&&o.cachePath){let w=await Ar(u,o);if(w){if(o.debug)console.log(`Using cached version of ${u}`);return{contents:w,loader:"html"}}}let y=await De(()=>Bun.file(u).text(),"",(w)=>{throw new Kr(`Failed to read stx file: ${u}`,u,void 0,void 0,`File read error: ${w.message}`)});if(!y)throw new Kr(`stx file is empty: ${u}`,u);let{scriptContent:h,templateContent:x,allScripts:C}=xe.time("script-extraction",()=>{let w=y,A=B(y);if(A)w=A.content.trim();let U=y.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],re="",L=[];for(let k of U){let P=k.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",D=k.match(/<script\b([^>]*)>/i),V=D?D[1]:"";if(/\bserver\b/i.test(V))re=P;else L.push(k)}let I=w.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:re,templateContent:I,allScripts:L}}),R={__filename:u,__dirname:vt.dirname(u),__stx:{webComponentsPath:r,builtComponents:p}};await De(()=>b(h,R,u),void 0,(w)=>{let A=new le(`Script execution failed in ${u}: ${w.message}`,u,void 0,void 0,h.substring(0,100));if(X.log(A,{filePath:u,scriptContent:h}),o.debug)throw A});let v=await xe.timeAsync("directive-processing",async()=>await i(x,R,u,o,g));if(C.length>0){let{interpolateScriptsInTemplate:w}=await import("./chunk-emk29htn.js"),A=w(C.join(`
|
|
458
458
|
`),R),U=v.search(/<\/body>/i);if(U!==-1)v=v.slice(0,U)+A+`
|
|
459
459
|
`+v.slice(U);else v+=`
|
|
460
|
-
${A}`}if(v=await
|
|
460
|
+
${A}`}if(v=await Ie(v),g.forEach((w)=>d.add(w)),o.cache&&o.cachePath){if(await Pr(u,v,g,o),o.debug)console.log(`Cached template ${u} with ${g.size} dependencies`)}return{contents:v,loader:"html"}}catch(g){let y=g instanceof Error?g:new le(`Plugin processing failed: ${String(g)}`,u);if(X.log(y,{filePath:u,buildConfig:n.config}),Fn.logDetailedError(y,{filePath:u,plugin:"bun-plugin-stx"}),o.debug)console.error("stx Plugin Error:",y);let h=y,x=h.line||null,C=h.context||null;return{contents:o.debug||se()?`<!DOCTYPE html>
|
|
461
461
|
<html lang="en">
|
|
462
462
|
<head>
|
|
463
463
|
<meta charset="UTF-8">
|
|
@@ -517,12 +517,12 @@ ${A}`}if(v=await Pe(v),g.forEach((w)=>d.add(w)),o.cache&&o.cachePath){if(await P
|
|
|
517
517
|
<h1>Something went wrong</h1>
|
|
518
518
|
<p>An internal error occurred. Please try again later.</p>
|
|
519
519
|
</body>
|
|
520
|
-
</html>`,loader:"html"}}})}};async function
|
|
520
|
+
</html>`,loader:"html"}}})}};async function cs(n,t={}){let o=t.port||3000,d=t.watch!==!1,r=t.hotReload!==!1&&d,p=null,u=t.hmrPort||o+1,g=ge.resolve(n);if(!je.existsSync(g))return console.error(`${e.red}Error: File not found: ${e.bright}${g}${e.reset}`),!1;if(g.endsWith(".md"))return Pt(g,t);else if(!g.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${g}${e.reset}. Only .stx and .md files are supported.`),!1;let y=l(process.cwd(),"output");je.mkdirSync(y,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${n}${e.reset}...`);let h=null,x=async()=>{try{let P={name:"public-assets",setup(be){be.onResolve({filter:/^\/(images|fonts|assets|public)\//},(pe)=>({path:pe.path,external:!0}))}},D=await Bun.build({entrypoints:[g],outdir:y,plugins:[P,tt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...t.stxOptions});if(!D.success)return console.error(`${e.red}Build failed:${e.reset}`,D.logs),!1;let V=D.outputs.find((be)=>be.path.endsWith(".html"));if(!V)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return h=await Bun.file(V.path).text(),!0}catch(P){return console.error(`${e.red}Error building stx file:${e.reset}`,P),!1}};if(!await x())return!1;let R=ge.dirname(g);await Cn(R);let O=o;try{if(O=await qe(o),O!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${O} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(r){let P=t.hmrPort||O+1;p=bt({wsPort:P,verbose:!1}),u=p.start(P)}let v={},w=null,A;try{let{loadStxConfig:P}=await import("./chunk-txyze88n.js"),D=await P();if(A=t.stxOptions?.serverApi??D.serverApi,D?.apiRouter)w=D?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(D?.apiRoutes){v=D.apiRoutes;let V=Object.keys(v).length;if(V>0)console.log(`${e.blue}Loaded ${e.bright}${V} API route${V>1?"s":""}${e.reset}`)}if(D?.broadcasting?.enabled)try{let{startBroadcasting:V,loadChannels:Q}=await import("./chunk-z5j4prza.js"),be=D.broadcasting;await V(be);let pe=be.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${pe}/ws${e.reset}`);let ke=ge.join(process.cwd(),"channels.ts");if(je.existsSync(ke))try{let ie=await Q(ke);console.log(`${e.blue}Loaded ${e.bright}${ie} broadcast channel${ie!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ie){console.warn(`${e.yellow}Failed to load channels.ts: ${ie.message}${e.reset}`)}}catch(V){console.warn(`${e.yellow}Broadcasting failed to start: ${V.message}${e.reset}`)}}catch{}let{createServerApi:U,isServerApiSource:re}=await import("./chunk-skjm3zdh.js"),L=await U(process.cwd(),A);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${O}/${e.reset}...`),r)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${u}${e.reset}`);let I=Kn({port:O,async fetch(P){return Gn(P,await(async()=>{let D=new URL(P.url);if([y,ge.dirname(g),ge.join(process.cwd(),"public")].some((ie)=>re(ge.join(ie,D.pathname),process.cwd(),A)))return new Response("Not Found",{status:404});if(w)try{let ie=await w.handleRequest(P);if(ie.status!==404)return ie}catch{}if(v[D.pathname])try{return await v[D.pathname](P)}catch(ie){return new Response(JSON.stringify({error:ie.message}),{status:500,headers:{"Content-Type":"application/json"}})}let V=await L(P);if(V)return V;if(D.pathname==="/")return(async()=>{let F=await S(h||"");if(r)F=Ne(F,u);if(t.native)if(F.includes("<head>"))F=F.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else if(F.includes("<html"))F=F.replace(/(<html[^>]*>)/,"$1<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>");else F="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+F;if(t.titlebarHidden)if(F.includes("<head>"))F=F.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else if(F.includes("<html"))F=F.replace(/(<html[^>]*>)/,"$1<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>");else F=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${F}`;return F})().then((F)=>new Response(F,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Q=ge.join(y,D.pathname);if(je.existsSync(Q)&&je.statSync(Q).isFile()){let ie=Bun.file(Q),F=ge.extname(Q).toLowerCase(),E="text/plain";if(F===".ts"||F===".tsx"){let Be=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ie.text(),Je=Be.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":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".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(ie,{headers:{"Content-Type":E}})}let be=ge.dirname(g),pe=ge.join(be,D.pathname);if(je.existsSync(pe)&&je.statSync(pe).isFile()){let ie=Bun.file(pe),F=ge.extname(pe).toLowerCase(),E="text/plain";if(F===".ts"||F===".tsx"){let Be=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ie.text(),Je=Be.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":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(ie,{headers:{"Content-Type":E}})}let ke=ge.join(process.cwd(),"public",D.pathname);if(je.existsSync(ke)&&je.statSync(ke).isFile()){let ie=Bun.file(ke),F=ge.extname(ke).toLowerCase(),E="application/octet-stream";if(F===".ts"||F===".tsx"){let Be=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ie.text(),Je=Be.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":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(ie,{headers:{"Content-Type":E}})}return new Response("Not Found",{status:404})})())},error(P){return new Response(`<pre>${P}
|
|
521
521
|
${P.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
522
522
|
${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(`
|
|
523
523
|
${e.bright}\u2192 ${e.cyan}http://localhost:${O}/${e.reset}`),console.log(`
|
|
524
524
|
${e.yellow}Routes:${e.reset}`);let k=ge.relative(process.cwd(),g);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${k}${e.reset}`),console.log(`
|
|
525
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(I.url.toString(),()=>{if(d)je.watch(ge.dirname(g),{recursive:!0}).close();I.stop()}),t.native){let P=await Bun.file(g).text(),D=gt(P);await Qe(O,{title:ge.basename(g,".stx"),titlebarHidden:t.titlebarHidden===!0,nativeSidebar:!!D,sidebarConfig:D})}if(d){let P=ge.dirname(g);console.log(`${e.blue}Watching ${e.bright}${P}${e.reset} for changes...`);let D=je.watch(P,{recursive:!0},async(V,Q)=>{if(!Q||xt(Q))return;if(yt(Q)){console.log(`${e.yellow}File ${e.bright}${Q}${e.yellow} changed, rebuilding...${e.reset}`),ut.clear(),
|
|
525
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(I.url.toString(),()=>{if(d)je.watch(ge.dirname(g),{recursive:!0}).close();I.stop()}),t.native){let P=await Bun.file(g).text(),D=gt(P);await Qe(O,{title:ge.basename(g,".stx"),titlebarHidden:t.titlebarHidden===!0,nativeSidebar:!!D,sidebarConfig:D})}if(d){let P=ge.dirname(g);console.log(`${e.blue}Watching ${e.bright}${P}${e.reset} for changes...`);let D=je.watch(P,{recursive:!0},async(V,Q)=>{if(!Q||xt(Q))return;if(yt(Q)){console.log(`${e.yellow}File ${e.bright}${Q}${e.yellow} changed, rebuilding...${e.reset}`),ut.clear(),Ee();let be=await x();if(await Cr(R),r&&p)if(be)p.reload(Q);else p.error("Build failed - check console for details")}else if(ht(Q)){if(console.log(`${e.cyan}CSS ${e.bright}${Q}${e.cyan} changed${e.reset}`),r&&p)p.updateCss(Q)}});process.on("SIGINT",()=>{if(D.close(),p)st();I.stop(),process.exit(0)})}return!0}var{serve:Xn}=globalThis.Bun;import Xe from"fs";import Se from"path";var Vt=`
|
|
526
526
|
<script data-stx-helpers>
|
|
527
527
|
(function() {
|
|
528
528
|
'use strict'
|
|
@@ -833,14 +833,14 @@ else {
|
|
|
833
833
|
|
|
834
834
|
})()
|
|
835
835
|
</script>
|
|
836
|
-
`;function Gt(n){if(n.length===0)return"";if(n.length===1)return n[0];let t=n.map((d)=>d.split(Se.sep)),o=[];for(let d=0;d<t[0].length;d++){let r=t[0][d];if(t.every((p)=>p[d]===r))o.push(r);else break}return o.join(Se.sep)}async function
|
|
836
|
+
`;function Gt(n){if(n.length===0)return"";if(n.length===1)return n[0];let t=n.map((d)=>d.split(Se.sep)),o=[];for(let d=0;d<t[0].length;d++){let r=t[0][d];if(t.every((p)=>p[d]===r))o.push(r);else break}return o.join(Se.sep)}async function ls(n,t={}){let o=t.port||3000,d=t.watch!==!1;for(let v of n){let w=Se.resolve(v);if(!Xe.existsSync(w))return console.error(`${e.red}Error: File not found: ${e.bright}${w}${e.reset}`),!1;if(!w.endsWith(".stx")&&!w.endsWith(".md"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${w}${e.reset}. Only .stx and .md files are supported.`),!1}let r=l(process.cwd(),"output");Xe.mkdirSync(r,{recursive:!0});let p=Gt(n.map((v)=>Se.dirname(Se.resolve(v))));console.log(`${e.blue}Processing ${e.bright}${n.length}${e.reset} files...`);let u={},g=[],y=async()=>{try{for(let v of n){let w=Se.resolve(v);if(w.endsWith(".md"))try{let{content:U,data:re}=await Ue(w,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:j.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),L=t.markdown?.syntaxHighlighting||j.markdown?.syntaxHighlighting,I=L?.defaultTheme||"github-dark",k=["github-dark"],P=L?.additionalThemes||[],V=[...new Set([...k,...P])].map((ke)=>`<option value="${ke}"${ke===I?" selected":""}>${ke}</option>`).join(`
|
|
837
837
|
`),Q=`
|
|
838
838
|
<!DOCTYPE html>
|
|
839
839
|
<html lang="en">
|
|
840
840
|
<head>
|
|
841
841
|
<meta charset="UTF-8">
|
|
842
842
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
843
|
-
<title>${qt(
|
|
843
|
+
<title>${qt(re.title||Se.basename(w))}</title>
|
|
844
844
|
<!-- Syntax highlighting styles -->
|
|
845
845
|
<style id="syntax-theme">
|
|
846
846
|
:root {
|
|
@@ -986,7 +986,7 @@ else {
|
|
|
986
986
|
</style>
|
|
987
987
|
</head>
|
|
988
988
|
<body>
|
|
989
|
-
${mt(
|
|
989
|
+
${mt(re)}
|
|
990
990
|
${pt(V)}
|
|
991
991
|
|
|
992
992
|
${U}
|
|
@@ -996,18 +996,18 @@ else {
|
|
|
996
996
|
</script>
|
|
997
997
|
</body>
|
|
998
998
|
</html>
|
|
999
|
-
`,pe=`/${Se.relative(p,w).replace(/\.md$/,"")}`;if(pe.endsWith("/index"))pe=pe.slice(0,-6)||"/";u[pe||"/"]={filePath:w,content:Q,fileType:"md"}}catch(U){console.error(`${e.red}Error processing Markdown file ${e.bright}${v}${e.reset}:`,U);continue}else{let U={name:"public-assets",setup(k){k.onResolve({filter:/^\/(images|fonts|assets|public)\//},(P)=>({path:P.path,external:!0}))}},
|
|
1000
|
-
${He(k,w)}`);continue}let I=`/${Se.relative(p,w).replace(/\.stx$/,"")}`;if(I.endsWith("/index"))I=I.slice(0,-6)||"/";if(I.includes("[")){let{regex:k,params:P}=
|
|
999
|
+
`,pe=`/${Se.relative(p,w).replace(/\.md$/,"")}`;if(pe.endsWith("/index"))pe=pe.slice(0,-6)||"/";u[pe||"/"]={filePath:w,content:Q,fileType:"md"}}catch(U){console.error(`${e.red}Error processing Markdown file ${e.bright}${v}${e.reset}:`,U);continue}else{let U={name:"public-assets",setup(k){k.onResolve({filter:/^\/(images|fonts|assets|public)\//},(P)=>({path:P.path,external:!0}))}},re;try{let k=await Bun.build({entrypoints:[w],outdir:r,plugins:[U,tt],define:{"process.env.NODE_ENV":'"development"'},...t.stxOptions});if(!k.success){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:`,He(k.logs,w));continue}let P=k.outputs.find((D)=>D.path.endsWith(".html"));if(!P){console.error(`${e.red}No HTML output found for ${e.bright}${v}${e.reset}`);continue}re=await Bun.file(P.path).text()}catch(k){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:
|
|
1000
|
+
${He(k,w)}`);continue}let I=`/${Se.relative(p,w).replace(/\.stx$/,"")}`;if(I.endsWith("/index"))I=I.slice(0,-6)||"/";if(I.includes("[")){let{regex:k,params:P}=Gs(I,{page:!0});g.push({pattern:k,paramNames:P,filePath:w,routeTemplate:I,fileType:"stx"}),u[I]={filePath:w,content:re,fileType:"stx"}}else u[I||"/"]={filePath:w,content:re,fileType:"stx"}}}if(Object.keys(u).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}`,He(v)),!1}};if(!await y())return!1;let x=o;try{if(x=await qe(o),x!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${x} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${x}/${e.reset}...`);let C=Xn({port:x,async fetch(v){let w=new URL(v.url),A=Se.join(process.cwd(),"public",w.pathname);if(Xe.existsSync(A)&&Xe.statSync(A).isFile()){let L=Bun.file(A),I=Se.extname(A).toLowerCase(),k="application/octet-stream";if(I===".ts"||I===".tsx"){let P=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),D=await L.text(),V=P.transformSync(D);return new Response(V,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(I){case".html":k="text/html";break;case".css":k="text/css";break;case".js":k="text/javascript";break;case".json":k="application/json";break;case".png":k="image/png";break;case".jpg":case".jpeg":k="image/jpeg";break;case".gif":k="image/gif";break;case".svg":k="image/svg+xml";break;case".ico":k="image/x-icon";break;case".woff":k="font/woff";break;case".woff2":k="font/woff2";break;case".ttf":k="font/ttf";break;case".otf":k="font/otf";break;case".eot":k="application/vnd.ms-fontobject";break}return new Response(L,{headers:{"Content-Type":k}})}let U=u[w.pathname];if(!U&&!w.pathname.endsWith("/"))U=u[`${w.pathname}/`];if(!U)for(let L of g){let I=w.pathname.match(L.pattern);if(I){let k=u[L.routeTemplate];if(k){let P={};for(let Q=0;Q<L.paramNames.length;Q++)P[L.paramNames[Q]]=decodeURIComponent(I[Q+1]);let D=k.content,V=`<script>window.__routeParams = ${JSON.stringify(P)};</script>`;if(D.includes("</head>"))D=f(D,V);else D=V+D;U={...k,content:D}}break}}if(U)return S(U.content).then((L)=>{if(L.includes("</head>"))L=f(L,Vt);return new Response(L,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let re=Se.join(r,w.pathname);if(Xe.existsSync(re)&&Xe.statSync(re).isFile()){let L=Bun.file(re),I=Se.extname(re).toLowerCase(),k="text/plain";if(I===".ts"||I===".tsx"){let P=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),D=await L.text(),V=P.transformSync(D);return new Response(V,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(I){case".html":k="text/html";break;case".css":k="text/css";break;case".js":k="text/javascript";break;case".json":k="application/json";break;case".png":k="image/png";break;case".jpg":case".jpeg":k="image/jpeg";break;case".gif":k="image/gif";break;case".svg":k="image/svg+xml";break;case".ico":k="image/x-icon";break;case".woff":k="font/woff";break;case".woff2":k="font/woff2";break;case".ttf":k="font/ttf";break;case".otf":k="font/otf";break;case".eot":k="application/vnd.ms-fontobject";break}return new Response(L,{headers:{"Content-Type":k}})}if(w.pathname!=="/"&&u["/"]){let L=Le(v);return S(u["/"].content).then((I)=>{if(L){let k=I.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(k){let P=I.match(/<title[^>]*>([\s\S]*?)<\/title>/i),D=P?P[1]:"",V=`<!DOCTYPE html><html><head><title>${qt(D)}</title></head><body><main>${k[1]}</main></body></html>`;return new Response(V,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...J(),"Cache-Control":nn,Pragma:"no-cache",Expires:"0"}})}}return new Response(I,{headers:{"Content-Type":"text/html",...J(),"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}
|
|
1001
1001
|
${v.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
1002
1002
|
${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(`
|
|
1003
1003
|
${e.bright}\u2192 ${e.cyan}http://localhost:${x}/${e.reset}`),console.log(`
|
|
1004
|
-
${e.yellow}Routes:${e.reset}`);let R=new Set(g.map((v)=>v.routeTemplate)),O=Object.entries(u).filter(([v])=>!R.has(v)).sort(([v],[w])=>v.localeCompare(w)).map(([v,w])=>({route:v==="/"?"/":v,filePath:Se.relative(process.cwd(),w.filePath),fileType:w.fileType}));for(let v of g){let w=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");O.push({route:w,filePath:Se.relative(process.cwd(),v.filePath),fileType:"stx"})}if(O.sort((v,w)=>v.route.localeCompare(w.route)),O.forEach((v,w)=>{let U=w===O.length-1?"\u2514\u2500 ":"\u251C\u2500 ",
|
|
1005
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(C.url.toString(),()=>{if(d)Xe.watch(p,{recursive:!0}).close();C.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Xe.watch(p,{recursive:!0},async(w,A)=>{if(!A)return;if(A.endsWith(".stx")||A.endsWith(".js")||A.endsWith(".ts")||A.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${A}${e.yellow} changed, rebuilding...${e.reset}`),ut.clear(),Ce(),await y()});process.on("SIGINT",()=>{v.close(),C.stop(),process.exit(0)})}return!0}function qt(n){return String(n??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Jn}=globalThis.Bun;import me from"fs";import ne from"path";async function Jt(n){try{return In(await Bun.file(n).text())}catch{return}}function Et(n){let t=Bun.file(n),o=ne.extname(n).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"},p=[".js",".css",".json"].includes(o)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(t,{headers:{"Content-Type":d[o]||"application/octet-stream",...p}})}async function ls(n=".",t={}){let o=t.port||3000,d=t.watch!==!1,r=t.hotReload!==!1&&d,p=null,u=t.hmrPort||o+1,g=ne.resolve(n),{loadStxConfig:y}=await import("./chunk-vtcyber4.js"),h=await y(g),{createServerApi:x,isServerApiSource:C}=await import("./chunk-rwjye578.js"),R=t.stxOptions?.serverApi??h.serverApi,O=await x(g,R),v=h.root&&h.root!=="."?ne.join(g,h.root):g,w=t.pagesDir||h.pagesDir||"pages",A=ne.join(v,w);if(!me.existsSync(A)&&!h._layerPageDirs?.some((T)=>me.existsSync(T)))return console.error(`${e.red}Error: No '${w}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${A}${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 ${w}/index.stx for the homepage.${e.reset}`),!1;let U=se(v,{pagesDir:w,pagesDirs:h._layerPageDirs?[A,...h._layerPageDirs.slice(1)]:void 0});if(U.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${A}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${U.length}${e.blue} routes${e.reset}`);let oe=h?._pluginPageDirs||[],L=[];for(let{dir:T,prefix:_}of oe)if(me.existsSync(T)){let z=se(ne.dirname(T),{pagesDir:ne.basename(T)});for(let Z of z){let q=_==="/"?Z.pattern:`${_}${Z.pattern==="/"?"":Z.pattern}`;L.push({route:{...Z,pattern:q},prefix:_})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${_}${e.reset}`)}let I=new Map,k=null,P=null;if(t.stxOptions?.shell!==!1){if(P=await ja(g,t.stxOptions?.shell),P){if(k=await zo(P,t.stxOptions||{}),k)console.log(`${e.blue}Using app shell: ${e.bright}${ne.relative(g,P)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}jt(),await Ft(g);let D=Bt();if(D.length>0)console.log(`${e.blue}Loaded ${e.bright}${D.length}${e.blue} middleware: ${e.dim}${D.join(", ")}${e.reset}`);let V={},Q=null;try{let{loadStxConfig:T}=await import("./chunk-vtcyber4.js"),_=await T(g);if(_?.apiRouter)Q=_?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(_?.apiRoutes){V=_.apiRoutes;let z=Object.keys(V).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(_?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:Z}=await import("./chunk-4yz33vzb.js"),q=_.broadcasting;await z(q);let Te=q.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Te}/ws${e.reset}`);let be=ne.join(process.cwd(),"channels.ts");if(me.existsSync(be))try{let N=await Z(be);console.log(`${e.blue}Loaded ${e.bright}${N} broadcast channel${N!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(N){console.warn(`${e.yellow}Failed to load channels.ts: ${N.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let xe=l(g,"output");me.mkdirSync(xe,{recursive:!0});let pe=new Map,ke=new Set,ie=async(T)=>{let _=Gs(A,T);if(!_)return null;try{let z=await Bun.build({entrypoints:[_],outdir:xe,plugins:[tt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...t.stxOptions});if(!z.success)return null;let Z=z.outputs.find((q)=>q.path.endsWith(".html"));if(!Z)return null;return await Bun.file(Z.path).text()}catch{return null}},F=new Map,E=async(T,_)=>{try{let{processDirectives:z,extractVariables:Z,defaultConfig:q,loadStxConfig:Te,injectRouterScript:be}=await import("./chunk-vtcyber4.js"),{checkCache:N,cacheTemplate:Y,readFileCached:W,templateCache:ue}=await import("./chunk-tz5ktd6d.js"),G=await Te(g),Ve=(le)=>{if(!le)return le;if(ne.isAbsolute(le))return le;return ne.resolve(g,le)},de={...q,...G,...t.stxOptions,autoShell:!0};if(t.debugDirectives)de.debug=!0;de.partialsDir=Ve(de.partialsDir),de.componentsDir=Ve(de.componentsDir),de.layoutsDir=Ve(de.layoutsDir),de.storesDir=Ve(de.storesDir||"stores"),de.cachePath=Ve(de.cachePath)??l(g,"cache");let M=!_&&!t.profile,J=de.cache!==!1;if(J&&M){let le=ue.get(T.filePath);if(le)try{if((await me.promises.stat(T.filePath)).mtime.getTime()<=le.mtime){let Ie=!0;for(let we of le.dependencies){if(!me.existsSync(we)){Ie=!1;break}if((await me.promises.stat(we)).mtime.getTime()>le.mtime){Ie=!1;break}}if(Ie){let we=le.output;if(k)we=it(we,{preserveHead:!0});let ot=F.get(T.filePath);return{route:T,content:we,status:ot?.status??await Jt(T.filePath),headers:ot?.headers}}}}catch{}let De=await N(T.filePath,de);if(De){let _e=De;if(k)_e=it(_e,{preserveHead:!0});let Ie=F.get(T.filePath);return{route:T,content:_e,status:Ie?.status??await Jt(T.filePath),headers:Ie?.headers}}}let ee=J?await W(T.filePath):await Bun.file(T.filePath).text(),ae=In(ee),{classifyAllScripts:fe}=await import("./chunk-vtcyber4.js"),H=fe(ee),Oe=H.server.map((le)=>le.content),Re=ee;for(let le of H.server)Re=Re.replace(le.fullTag,"");let te={__filename:T.filePath,__dirname:ne.dirname(T.filePath),__stx_options:de,params:_??{},__stx_runtime_head:{}};for(let le of Oe)try{await Z(le,te,T.filePath)}catch(De){if(t.stxOptions?.debug)console.error("[stx] variable extraction error",T.filePath,De?.message||De)}let $e=new Set,he;if(t.profile){let le=performance.now();he=await z(Re,te,T.filePath,de,$e);let De=performance.now()-le,_e=ne.relative(g,T.filePath)||T.filePath;console.log(`[stx:profile] ${_e} \u2192 ${De.toFixed(2)}ms`)}else he=await z(Re,te,T.filePath,de,$e);if(!k)he=await be(he,{router:de.router});{let{interpolateScriptExpressions:le}=await import("./chunk-p8wnp4p1.js");he=he.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(De,_e,Ie)=>{if(!/function\s+__stx_setup_/.test(Ie))return De;return`<script${_e}>${le(Ie,te)}</script>`})}if(k)he=it(he,{preserveHead:!0});if(J&&M)await Y(T.filePath,he,$e,de);let{extractStreamBoundaries:lt}=await import("./chunk-m1hfh2t4.js"),Ye=lt(te),rt=te.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let le=te.streamBoundaries||{},De={...de,autoShell:!1},_e=Object.keys(rt).map((we)=>({id:we,render:async()=>{let ot=typeof le[we]==="function"?await le[we]():void 0;return z(rt[we],{...te,$boundary:ot},T.filePath,De,new Set)}})),Ie=new Set(_e.map((we)=>we.id));Ye=[...(Ye||[]).filter((we)=>!Ie.has(we.id)),..._e]}if(Ye&&Ye.length>0)ke.add(T.pattern);else Ye=void 0;let Dt=Kt(te),Mt=Xt(te);if(M)F.set(T.filePath,{status:Dt,headers:Mt});return{route:T,content:he,status:Dt??ae,headers:Mt,boundaries:Ye}}catch(z){return console.error(`${e.red}Error building ${e.bright}${T.pattern}${e.reset}:`,z),null}},Be=8,ze=async()=>{let T=new Set(pe.keys()),_=new Set(I.keys());pe.clear(),I.clear();let z=t.prebuild===!1?U.filter((q)=>T.has(q.pattern)):U,Z=t.prebuild===!1?L.filter(({route:q})=>_.has(q.pattern)):L;for(let q=0;q<z.length;q+=Be){let Te=z.slice(q,q+Be),be=await Promise.all(Te.map((N)=>E(N)));for(let N of be)if(N)pe.set(N.route.pattern,N)}for(let q=0;q<Z.length;q+=Be){let Te=Z.slice(q,q+Be),be=await Promise.all(Te.map(({route:N})=>E(N)));for(let N of be)if(N)I.set(N.route.pattern,N)}return pe.size>0};if(console.log(`${e.blue}${t.prebuild===!1?"Rendering pages on request...":"Building pages..."}${e.reset}`),!(t.prebuild===!1?U.length+L.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Cn(g);let Ge=o;try{if(Ge=await qe(o),Ge!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${Ge} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(r){let T=t.hmrPort||Ge+1;p=bt({wsPort:T,verbose:!1}),u=p.start(T)}let St=(T,_)=>{let Z=`<script data-stx-route-params>(function(){var p=${JSON.stringify(_).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(T.includes("</head>"))return f(T,Z,"");if(T.includes("<body"))return T.replace(/<body([^>]*)>/,`<body$1>${Z}`);return Z+T};console.log(`${e.blue}Starting server...${e.reset}`);let kt=Jn({port:Ge,hostname:t.hostname,async fetch(T){let _=new URL(T.url),z=t.stxOptions?.offline??h.offline;if(_.pathname===ii&&z?.enabled){if(!["GET","HEAD"].includes(T.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});let M=[...U,...L.map(({route:J})=>J)].filter((J)=>!J.isDynamic).map((J)=>J.pattern);return new Response(T.method==="HEAD"?null:ai(z,Ts(),M),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let Z=h?.publicDir||"public",q=ne.join(g,Z,_.pathname),Te=ne.join(g,_.pathname),be=ne.join(xe,_.pathname);if([q,Te,be].some((M)=>C(M,g,R)))return new Response("Not Found",{status:404});let[N,Y,W]=await Promise.all([me.promises.stat(q).catch(()=>null),me.promises.stat(Te).catch(()=>null),me.promises.stat(be).catch(()=>null)]);if(N?.isFile()&&!C(q,g,R))return Et(q);if(Y?.isFile()&&!C(Te,g,R))return Et(Te);if(W?.isFile()&&!C(be,g,R))return Et(be);if(_.pathname.startsWith("/_stx/component/")){let M=decodeURIComponent(_.pathname.slice(16));if(M)try{let J=`<${M} />`,ee={...buildConfig,autoShell:!1},ae=await processDirectives(J,{},ne.join(g,"components",`${M}.stx`),ee,new Set);return new Response(ae,{headers:{"Content-Type":"text/html"}})}catch(J){return new Response(`<div class="stx-async-error">${J.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(_.pathname==="/_stx/img"){let{handleImageRequest:M}=await import("./chunk-wq2bpt0w.js"),J=await M(T,{publicDir:ne.join(g,Z),cacheDir:l(g,"cache","img")});if(J)return J}if(Q)try{let M=await Q.handleRequest(T);if(M.status!==404)return M}catch{}if(V[_.pathname])try{return await V[_.pathname](T)}catch(M){return new Response(JSON.stringify({error:M.message}),{status:500,headers:{"Content-Type":"application/json"}})}let ue=await O(T);if(ue)return ue;let G=Or(_.pathname,U);if(G){let M=pe.get(G.route.pattern),J=ke.has(G.route.pattern);if(!M||G.route.isDynamic&&Object.keys(G.params).length>0||J){let ee=await E(G.route,G.params);if(ee){if(M=ee,!G.route.isDynamic&&!J)pe.set(G.route.pattern,ee)}}if(M){let ee=M.status??200,ae=M.headers??{},fe=(G.route.filePath?It(await Bun.file(G.route.filePath).text().catch(()=>"")):null)??{};if(fe.validate){if(!await fe.validate({params:G.params})){let Re=await ie(404);if(Re){let te=Re;if(te=await S(te,g),r)te=Ne(te,u);return new Response(te,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(fe.middleware){let Oe=zt(_.pathname,G.params,fe,_.search),Re=Ht(Oe,null,T,{isServer:!0}),te=await Ut(fe.middleware,Re);if(te.redirect){let $e=te.redirect.path,he=te.redirect.options.redirectCode||302,lt=new Headers(te.responseHeaders);return lt.set("Location",$e),new Response(null,{status:he,headers:lt})}if(te.abort){let{statusCode:$e,message:he}=te.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${$e}</title></head><body><h1>Error ${$e}</h1><p>${he}</p></body></html>`,{status:$e,headers:{"Content-Type":"text/html"}})}if(Object.keys(te.state).length>0){let $e=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(te.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;M.content=f(M.content,$e,"")}}let H=M.content;if(k&&Ba(T)&&$t(H,h?.router?.container||"main")){let Oe=We(H),Re=Ae(H),te=H.match(/<title[^>]*>([\s\S]*?)<\/title>/i),$e=te?nt(te[1].trim()):"";if(Object.keys(G.params).length>0)H=St(H,G.params);H=await S(H,g);let he=h?.router?.container||"main";return H=Fe(H,he,!0),new Response(H,{status:ee,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Oe.layout,"X-STX-Layout-Group":Oe.group,"X-STX-Runtime":Re?"true":"false",...$e&&{"X-STX-Title":encodeURIComponent($e)},[Lc]:Ts(),...X(),"Cache-Control":nn}})}if(k)H=gs(k,H);if(Object.keys(G.params).length>0)H=St(H,G.params);if(H=await S(H,g),r)H=Ne(H,u);if(t.native)if(H.includes("<head>"))H=H.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else H="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+H;if(t.titlebarHidden)if(H.includes("<head>"))H=H.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 H=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${H}`;if(M.boundaries&&M.boundaries.length>0){let{renderStreamingPage:Oe,streamToResponse:Re}=await import("./chunk-m1hfh2t4.js");return Re(Oe(H,M.boundaries,{timeoutMs:30000}),{status:ee,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(H,{status:ee,headers:{"Content-Type":"text/html",...X(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ae}})}}if(L.length>0){let M=L.map((ee)=>ee.route),J=Or(_.pathname,M);if(J){let ee=I.get(J.route.pattern);if(!ee||J.route.isDynamic){let ae=await E(J.route,J.params);if(ae){if(ee=ae,!J.route.isDynamic)I.set(J.route.pattern,ae)}}if(ee){let ae=ee.content;if(k)ae=gs(k,ae);if(Object.keys(J.params).length>0)ae=St(ae,J.params);if(ae=await S(ae,g),r)ae=Ne(ae,u);return new Response(ae,{status:ee.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:ee}of oe)if(ee!=="/"&&_.pathname.startsWith(ee)){let ae=I.get(ee)||I.get(ee+"/");if(!ae){let fe=L.find(({route:H})=>H.pattern===ee||H.pattern===`${ee}/`);if(fe){let H=await E(fe.route);if(H)ae=H,I.set(fe.route.pattern,H)}}if(ae){let fe=ae.content;if(k)fe=gs(k,fe);if(fe=await S(fe,g),r)fe=Ne(fe,u);return new Response(fe,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(Lt(_.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Ve=pe.get("/");if(Ve){let M=Ve.content;if(M=await S(M,g),r)M=Ne(M,u);if(t.native)if(M.includes("<head>"))M=M.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else M="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+M;return new Response(M,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let de=await ie(404);if(de){let M=de;if(M=await S(M,g),r)M=Ne(M,u);return new Response(M,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(T){let _=await ie(500);if(_)return new Response(_,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${T}
|
|
1004
|
+
${e.yellow}Routes:${e.reset}`);let R=new Set(g.map((v)=>v.routeTemplate)),O=Object.entries(u).filter(([v])=>!R.has(v)).sort(([v],[w])=>v.localeCompare(w)).map(([v,w])=>({route:v==="/"?"/":v,filePath:Se.relative(process.cwd(),w.filePath),fileType:w.fileType}));for(let v of g){let w=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");O.push({route:w,filePath:Se.relative(process.cwd(),v.filePath),fileType:"stx"})}if(O.sort((v,w)=>v.route.localeCompare(w.route)),O.forEach((v,w)=>{let U=w===O.length-1?"\u2514\u2500 ":"\u251C\u2500 ",re=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${U}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${re}`)}),console.log(`
|
|
1005
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(C.url.toString(),()=>{if(d)Xe.watch(p,{recursive:!0}).close();C.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Xe.watch(p,{recursive:!0},async(w,A)=>{if(!A)return;if(A.endsWith(".stx")||A.endsWith(".js")||A.endsWith(".ts")||A.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${A}${e.yellow} changed, rebuilding...${e.reset}`),ut.clear(),Ee(),await y()});process.on("SIGINT",()=>{v.close(),C.stop(),process.exit(0)})}return!0}function qt(n){return String(n??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Jn}=globalThis.Bun;import me from"fs";import ne from"path";async function Jt(n){try{return In(await Bun.file(n).text())}catch{return}}function Et(n){let t=Bun.file(n),o=ne.extname(n).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"},p=[".js",".css",".json"].includes(o)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(t,{headers:{"Content-Type":d[o]||"application/octet-stream",...p}})}async function us(n=".",t={}){let o=t.port||3000,d=t.watch!==!1,r=t.hotReload!==!1&&d,p=null,u=t.hmrPort||o+1,g=ne.resolve(n),{loadStxConfig:y}=await import("./chunk-txyze88n.js"),h=await y(g),{createServerApi:x,isServerApiSource:C}=await import("./chunk-skjm3zdh.js"),R=t.stxOptions?.serverApi??h.serverApi,O=await x(g,R),v=h.root&&h.root!=="."?ne.join(g,h.root):g,w=t.pagesDir||h.pagesDir||"pages",A=ne.join(v,w);if(!me.existsSync(A)&&!h._layerPageDirs?.some((T)=>me.existsSync(T)))return console.error(`${e.red}Error: No '${w}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${A}${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 ${w}/index.stx for the homepage.${e.reset}`),!1;let U=oe(v,{pagesDir:w,pagesDirs:h._layerPageDirs?[A,...h._layerPageDirs.slice(1)]:void 0});if(U.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${A}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${U.length}${e.blue} routes${e.reset}`);let re=h?._pluginPageDirs||[],L=[];for(let{dir:T,prefix:_}of re)if(me.existsSync(T)){let z=oe(ne.dirname(T),{pagesDir:ne.basename(T)});for(let Z of z){let q=_==="/"?Z.pattern:`${_}${Z.pattern==="/"?"":Z.pattern}`;L.push({route:{...Z,pattern:q},prefix:_})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${_}${e.reset}`)}let I=new Map,k=null,P=null;if(t.stxOptions?.shell!==!1){if(P=await Fa(g,t.stxOptions?.shell),P){if(k=await Uo(P,t.stxOptions||{}),k)console.log(`${e.blue}Using app shell: ${e.bright}${ne.relative(g,P)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}jt(),await Ft(g);let D=Bt();if(D.length>0)console.log(`${e.blue}Loaded ${e.bright}${D.length}${e.blue} middleware: ${e.dim}${D.join(", ")}${e.reset}`);let V={},Q=null;try{let{loadStxConfig:T}=await import("./chunk-txyze88n.js"),_=await T(g);if(_?.apiRouter)Q=_?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(_?.apiRoutes){V=_.apiRoutes;let z=Object.keys(V).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(_?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:Z}=await import("./chunk-z5j4prza.js"),q=_.broadcasting;await z(q);let Te=q.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Te}/ws${e.reset}`);let ve=ne.join(process.cwd(),"channels.ts");if(me.existsSync(ve))try{let N=await Z(ve);console.log(`${e.blue}Loaded ${e.bright}${N} broadcast channel${N!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(N){console.warn(`${e.yellow}Failed to load channels.ts: ${N.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let be=l(g,"output");me.mkdirSync(be,{recursive:!0});let pe=new Map,ke=new Set,ie=async(T)=>{let _=Js(A,T);if(!_)return null;try{let z=await Bun.build({entrypoints:[_],outdir:be,plugins:[tt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...t.stxOptions});if(!z.success)return null;let Z=z.outputs.find((q)=>q.path.endsWith(".html"));if(!Z)return null;return await Bun.file(Z.path).text()}catch{return null}},F=new Map,E=async(T,_)=>{try{let{processDirectives:z,extractVariables:Z,defaultConfig:q,loadStxConfig:Te,injectRouterScript:ve}=await import("./chunk-txyze88n.js"),{checkCache:N,cacheTemplate:Y,readFileCached:W,templateCache:ue}=await import("./chunk-h1dnjn9g.js"),K=await Te(g),Ve=(ce)=>{if(!ce)return ce;if(ne.isAbsolute(ce))return ce;return ne.resolve(g,ce)},de={...q,...K,...t.stxOptions,autoShell:!0};if(t.debugDirectives)de.debug=!0;de.partialsDir=Ve(de.partialsDir),de.componentsDir=Ve(de.componentsDir),de.layoutsDir=Ve(de.layoutsDir),de.storesDir=Ve(de.storesDir||"stores"),de.cachePath=Ve(de.cachePath)??l(g,"cache");let M=!_&&!t.profile,G=de.cache!==!1;if(G&&M){let ce=ue.get(T.filePath);if(ce)try{if((await me.promises.stat(T.filePath)).mtime.getTime()<=ce.mtime){let _e=!0;for(let we of ce.dependencies){if(!me.existsSync(we)){_e=!1;break}if((await me.promises.stat(we)).mtime.getTime()>ce.mtime){_e=!1;break}}if(_e){let we=ce.output;if(k)we=it(we,{preserveHead:!0});let ot=F.get(T.filePath);return{route:T,content:we,status:ot?.status??await Jt(T.filePath),headers:ot?.headers}}}}catch{}let Ae=await N(T.filePath,de);if(Ae){let Me=Ae;if(k)Me=it(Me,{preserveHead:!0});let _e=F.get(T.filePath);return{route:T,content:Me,status:_e?.status??await Jt(T.filePath),headers:_e?.headers}}}let ee=G?await W(T.filePath):await Bun.file(T.filePath).text(),ae=In(ee),{classifyAllScripts:fe}=await import("./chunk-txyze88n.js"),H=fe(ee),Oe=H.server.map((ce)=>ce.content),$e=ee;for(let ce of H.server)$e=$e.replace(ce.fullTag,"");let te={__filename:T.filePath,__dirname:ne.dirname(T.filePath),__stx_options:de,params:_??{},__stx_runtime_head:{}};for(let ce of Oe)try{await Z(ce,te,T.filePath)}catch(Ae){if(t.stxOptions?.debug)console.error("[stx] variable extraction error",T.filePath,Ae?.message||Ae)}let Ce=new Set,he;if(t.profile){let ce=performance.now();he=await z($e,te,T.filePath,de,Ce);let Ae=performance.now()-ce,Me=ne.relative(g,T.filePath)||T.filePath;console.log(`[stx:profile] ${Me} \u2192 ${Ae.toFixed(2)}ms`)}else he=await z($e,te,T.filePath,de,Ce);if(!k)he=await ve(he,{router:de.router});{let{interpolateScriptExpressions:ce}=await import("./chunk-emk29htn.js");he=he.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ae,Me,_e)=>{if(!/function\s+__stx_setup_/.test(_e))return Ae;return`<script${Me}>${ce(_e,te)}</script>`})}if(k)he=it(he,{preserveHead:!0});if(G&&M)await Y(T.filePath,he,Ce,de);let{extractStreamBoundaries:lt}=await import("./chunk-r02asm46.js"),Ye=lt(te),rt=te.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let ce=te.streamBoundaries||{},Ae={...de,autoShell:!1},Me=Object.keys(rt).map((we)=>({id:we,render:async()=>{let ot=typeof ce[we]==="function"?await ce[we]():void 0;return z(rt[we],{...te,$boundary:ot},T.filePath,Ae,new Set)}})),_e=new Set(Me.map((we)=>we.id));Ye=[...(Ye||[]).filter((we)=>!_e.has(we.id)),...Me]}if(Ye&&Ye.length>0)ke.add(T.pattern);else Ye=void 0;let Dt=Kt(te),Mt=Xt(te);if(M)F.set(T.filePath,{status:Dt,headers:Mt});return{route:T,content:he,status:Dt??ae,headers:Mt,boundaries:Ye}}catch(z){return console.error(`${e.red}Error building ${e.bright}${T.pattern}${e.reset}:`,z),null}},Be=8,ze=async()=>{let T=new Set(pe.keys()),_=new Set(I.keys());pe.clear(),I.clear();let z=t.prebuild===!1?U.filter((q)=>T.has(q.pattern)):U,Z=t.prebuild===!1?L.filter(({route:q})=>_.has(q.pattern)):L;for(let q=0;q<z.length;q+=Be){let Te=z.slice(q,q+Be),ve=await Promise.all(Te.map((N)=>E(N)));for(let N of ve)if(N)pe.set(N.route.pattern,N)}for(let q=0;q<Z.length;q+=Be){let Te=Z.slice(q,q+Be),ve=await Promise.all(Te.map(({route:N})=>E(N)));for(let N of ve)if(N)I.set(N.route.pattern,N)}return pe.size>0};if(console.log(`${e.blue}${t.prebuild===!1?"Rendering pages on request...":"Building pages..."}${e.reset}`),!(t.prebuild===!1?U.length+L.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Cn(g);let Ge=o;try{if(Ge=await qe(o),Ge!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${Ge} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(r){let T=t.hmrPort||Ge+1;p=bt({wsPort:T,verbose:!1}),u=p.start(T)}let St=(T,_)=>{let Z=`<script data-stx-route-params>(function(){var p=${JSON.stringify(_).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(T.includes("</head>"))return f(T,Z,"");if(T.includes("<body"))return T.replace(/<body([^>]*)>/,`<body$1>${Z}`);return Z+T};console.log(`${e.blue}Starting server...${e.reset}`);let kt=Jn({port:Ge,hostname:t.hostname,async fetch(T){let _=new URL(T.url),z=t.stxOptions?.offline??h.offline;if(_.pathname===ci&&z?.enabled){if(!["GET","HEAD"].includes(T.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});let M=[...U,...L.map(({route:G})=>G)].filter((G)=>!G.isDynamic).map((G)=>G.pattern);return new Response(T.method==="HEAD"?null:li(z,$s(),M),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let Z=h?.publicDir||"public",q=ne.join(g,Z,_.pathname),Te=ne.join(g,_.pathname),ve=ne.join(be,_.pathname);if([q,Te,ve].some((M)=>C(M,g,R)))return new Response("Not Found",{status:404});let[N,Y,W]=await Promise.all([me.promises.stat(q).catch(()=>null),me.promises.stat(Te).catch(()=>null),me.promises.stat(ve).catch(()=>null)]);if(N?.isFile()&&!C(q,g,R))return Et(q);if(Y?.isFile()&&!C(Te,g,R))return Et(Te);if(W?.isFile()&&!C(ve,g,R))return Et(ve);if(_.pathname.startsWith("/_stx/component/")){let M=decodeURIComponent(_.pathname.slice(16));if(M)try{let G=`<${M} />`,ee={...buildConfig,autoShell:!1},ae=await processDirectives(G,{},ne.join(g,"components",`${M}.stx`),ee,new Set);return new Response(ae,{headers:{"Content-Type":"text/html"}})}catch(G){return new Response(`<div class="stx-async-error">${G.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(_.pathname==="/_stx/img"){let{handleImageRequest:M}=await import("./chunk-xgv3gy1b.js"),G=await M(T,{publicDir:ne.join(g,Z),cacheDir:l(g,"cache","img")});if(G)return G}if(Q)try{let M=await Q.handleRequest(T);if(M.status!==404)return M}catch{}if(V[_.pathname])try{return await V[_.pathname](T)}catch(M){return new Response(JSON.stringify({error:M.message}),{status:500,headers:{"Content-Type":"application/json"}})}let ue=await O(T);if(ue)return ue;let K=Or(_.pathname,U);if(K){let M=pe.get(K.route.pattern),G=ke.has(K.route.pattern);if(!M||K.route.isDynamic&&Object.keys(K.params).length>0||G){let ee=await E(K.route,K.params);if(ee){if(M=ee,!K.route.isDynamic&&!G)pe.set(K.route.pattern,ee)}}if(M){let ee=M.status??200,ae=M.headers??{},fe=(K.route.filePath?It(await Bun.file(K.route.filePath).text().catch(()=>"")):null)??{};if(fe.validate){if(!await fe.validate({params:K.params})){let $e=await ie(404);if($e){let te=$e;if(te=await S(te,g),r)te=Ne(te,u);return new Response(te,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(fe.middleware){let Oe=zt(_.pathname,K.params,fe,_.search),$e=Ht(Oe,null,T,{isServer:!0}),te=await Ut(fe.middleware,$e);if(te.redirect){let Ce=te.redirect.path,he=te.redirect.options.redirectCode||302,lt=new Headers(te.responseHeaders);return lt.set("Location",Ce),new Response(null,{status:he,headers:lt})}if(te.abort){let{statusCode:Ce,message:he}=te.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${Ce}</title></head><body><h1>Error ${Ce}</h1><p>${he}</p></body></html>`,{status:Ce,headers:{"Content-Type":"text/html"}})}if(Object.keys(te.state).length>0){let Ce=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(te.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;M.content=f(M.content,Ce,"")}}let H=M.content;if(k&&za(T)&&$t(H,h?.router?.container||"main")){let Oe=We(H),$e=Pe(H),te=H.match(/<title[^>]*>([\s\S]*?)<\/title>/i),Ce=te?nt(te[1].trim()):"";if(Object.keys(K.params).length>0)H=St(H,K.params);H=await S(H,g);let he=h?.router?.container||"main";return H=Fe(H,he,!0),new Response(H,{status:ee,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Oe.layout,"X-STX-Layout-Group":Oe.group,"X-STX-Runtime":$e?"true":"false",...Ce&&{"X-STX-Title":encodeURIComponent(Ce)},[Bc]:$s(),...J(),"Cache-Control":nn}})}if(k)H=ms(k,H);if(Object.keys(K.params).length>0)H=St(H,K.params);if(H=await S(H,g),r)H=Ne(H,u);if(t.native)if(H.includes("<head>"))H=H.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else H="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+H;if(t.titlebarHidden)if(H.includes("<head>"))H=H.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 H=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${H}`;if(M.boundaries&&M.boundaries.length>0){let{renderStreamingPage:Oe,streamToResponse:$e}=await import("./chunk-r02asm46.js");return $e(Oe(H,M.boundaries,{timeoutMs:30000}),{status:ee,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(H,{status:ee,headers:{"Content-Type":"text/html",...J(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ae}})}}if(L.length>0){let M=L.map((ee)=>ee.route),G=Or(_.pathname,M);if(G){let ee=I.get(G.route.pattern);if(!ee||G.route.isDynamic){let ae=await E(G.route,G.params);if(ae){if(ee=ae,!G.route.isDynamic)I.set(G.route.pattern,ae)}}if(ee){let ae=ee.content;if(k)ae=ms(k,ae);if(Object.keys(G.params).length>0)ae=St(ae,G.params);if(ae=await S(ae,g),r)ae=Ne(ae,u);return new Response(ae,{status:ee.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:ee}of re)if(ee!=="/"&&_.pathname.startsWith(ee)){let ae=I.get(ee)||I.get(ee+"/");if(!ae){let fe=L.find(({route:H})=>H.pattern===ee||H.pattern===`${ee}/`);if(fe){let H=await E(fe.route);if(H)ae=H,I.set(fe.route.pattern,H)}}if(ae){let fe=ae.content;if(k)fe=ms(k,fe);if(fe=await S(fe,g),r)fe=Ne(fe,u);return new Response(fe,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(Lt(_.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Ve=pe.get("/");if(Ve){let M=Ve.content;if(M=await S(M,g),r)M=Ne(M,u);if(t.native)if(M.includes("<head>"))M=M.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else M="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+M;return new Response(M,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let de=await ie(404);if(de){let M=de;if(M=await S(M,g),r)M=Ne(M,u);return new Response(M,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(T){let _=await ie(500);if(_)return new Response(_,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${T}
|
|
1006
1006
|
${T.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});if(console.clear(),console.log(`
|
|
1007
1007
|
${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(`
|
|
1008
1008
|
${e.bright}\u2192 ${e.cyan}http://localhost:${Ge}/${e.reset}`),r)console.log(`${e.dim} HMR: ws://localhost:${u}${e.reset}`);console.log(`
|
|
1009
|
-
${e.yellow}Routes:${e.reset}`);let Tt=[...
|
|
1010
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(kt.url.toString(),()=>{if(p)st();kt.stop()}),t.native){let T,_=ne.join(A,"index.stx");if(me.existsSync(_)){let Z=await Bun.file(_).text();T=gt(Z)}let z=h?.app?.window??{};await Qe(Ge,{title:h?.app?.head?.title||ne.basename(g)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??t.titlebarHidden===!0,nativeSidebar:!!T,sidebarConfig:T})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let T=(N)=>N.startsWith("public/")||N.startsWith("public\\"),_=(N)=>{let Y=N.toLowerCase();return Y.endsWith(".stx")||Y.endsWith(".html")||Y.endsWith(".md")},z=new Map,Z=()=>{let N=new Set([g,...h._layerGraph?.layers.map((Y)=>Y.root)??[],...h._layerGraph?.configDependencies.map((Y)=>ne.dirname(Y))??[]].filter((Y)=>me.existsSync(Y)).map((Y)=>me.realpathSync(Y)));for(let Y of h._layerGraph?.layers??[])for(let W of Object.values(Y.resources)){if(!me.existsSync(W))continue;let ue=me.realpathSync(W);if(![...N].some((
|
|
1009
|
+
${e.yellow}Routes:${e.reset}`);let Tt=[...Ys(U,g)];for(let{route:T}of L)Tt.push(`${T.pattern}`);if(Tt.forEach((T,_)=>{let Z=_===Tt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${Z}${e.reset}${T}`)}),console.log(`
|
|
1010
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(kt.url.toString(),()=>{if(p)st();kt.stop()}),t.native){let T,_=ne.join(A,"index.stx");if(me.existsSync(_)){let Z=await Bun.file(_).text();T=gt(Z)}let z=h?.app?.window??{};await Qe(Ge,{title:h?.app?.head?.title||ne.basename(g)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??t.titlebarHidden===!0,nativeSidebar:!!T,sidebarConfig:T})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let T=(N)=>N.startsWith("public/")||N.startsWith("public\\"),_=(N)=>{let Y=N.toLowerCase();return Y.endsWith(".stx")||Y.endsWith(".html")||Y.endsWith(".md")},z=new Map,Z=()=>{let N=new Set([g,...h._layerGraph?.layers.map((Y)=>Y.root)??[],...h._layerGraph?.configDependencies.map((Y)=>ne.dirname(Y))??[]].filter((Y)=>me.existsSync(Y)).map((Y)=>me.realpathSync(Y)));for(let Y of h._layerGraph?.layers??[])for(let W of Object.values(Y.resources)){if(!me.existsSync(W))continue;let ue=me.realpathSync(W);if(![...N].some((K)=>ue===K||ue.startsWith(`${K}${ne.sep}`)))N.add(ue)}for(let[Y,W]of z)if(!N.has(Y))W.close(),z.delete(Y);for(let Y of N)if(!z.has(Y)&&me.existsSync(Y))z.set(Y,me.watch(Y,{recursive:!0},(W,ue)=>{Te(Y,W,ue).catch((K)=>console.error("[stx] Layer rebuild failed:",K))}))},q=Promise.resolve(),Te=(N,Y,W)=>(q=q.catch(()=>{}).then(()=>ve(N,Y,W)),q),ve=async(N,Y,W)=>{if(!W||xt(W))return;if(yt(W)){if(h._layerGraph){let ue=await y(g);Object.assign(h,ue),U.splice(0,U.length,...oe(v,{pagesDir:w,pagesDirs:ue._layerPageDirs?[A,...ue._layerPageDirs.slice(1)]:void 0})),Z()}if(T(W)){if(console.log(`${e.cyan}${W} changed${e.reset}`),r&&p)p.reload(W)}else if(_(W)){console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),ut.clear(),Ee();try{let{invalidateFileCache:ue,templateCache:K}=await import("./chunk-h1dnjn9g.js");ue(ne.resolve(N,W)),K.delete(ne.resolve(N,W))}catch{}if(P&&W){if(ne.resolve(N,W)===P||ne.basename(P)===W){let K=await Uo(P,t.stxOptions||{});if(K)k=K}}if(await ze(),await Cr(g),r&&p)p.reload(W)}else{console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),ut.clear(),Ee();try{let{invalidateFileCache:ue,templateCache:K}=await import("./chunk-h1dnjn9g.js");ue(ne.resolve(N,W)),K.delete(ne.resolve(N,W))}catch{}if(await ze(),r&&p)p.reload(W)}}else if(ht(W)){if(console.log(`${e.cyan}CSS ${W} changed${e.reset}`),r&&p)p.updateCss(W)}};Z(),process.on("SIGINT",()=>{for(let N of z.values())N.close();if(p)st();kt.stop(),process.exit(0)})}return!0}import Ot from"fs";import at from"path";async function Yn(n){try{let o=(await Bun.file(n).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!o)return[];let d=o[1],r=[],p=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,u;while((u=p.exec(d))!==null){let g=u[1],y=u[2]||u[3]||u[4];if(!y)continue;let h={name:y},x=g.match(/@type\s+\{([^}]+)\}/i);if(x)h.type=x[1].trim();if(g.match(/@required/i))h.required=!0;let R=g.match(/@default\s+(.+?)(?:\s+|$)/i);if(R)h.default=R[1].trim();let O=g.split(`
|
|
1011
1011
|
`).map((v)=>v.trim().replace(/^\*\s*/,"")).filter((v)=>!v.startsWith("@")&&v.length>0);h.description=O.join(" ").trim(),r.push(h)}if(r.length===0){let g=d.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(g){let h=g[1].split(",").map((x)=>x.trim()).filter(Boolean);for(let x of h){let[C]=x.split(":").map((R)=>R.trim());if(C)r.push({name:C})}}}return r}catch(t){return console.error(`Error extracting props from ${n}:`,t),[]}}async function Qn(n){try{let t=await Bun.file(n).text(),o=t.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||t.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(o)return o[1].split(`
|
|
1012
1012
|
`).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Zn(n,t=!1,o){let d=at.basename(n,".stx"),r=await Yn(n),p=await Qn(n),u="";if(t&&o)u=`<${o}></${o}>`;else{let g=r.map((y)=>{if(y.type==="boolean")return`:${y.name}="true"`;return`${y.name}="value"`}).join(`
|
|
1013
1013
|
`);u=`<${d}
|
|
@@ -1146,15 +1146,15 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(kt.
|
|
|
1146
1146
|
<td>@${p.name}</td>
|
|
1147
1147
|
<td>${p.description||"-"}</td>
|
|
1148
1148
|
<td>${p.hasEndTag?"Yes":"No"}</td>
|
|
1149
|
-
</tr>`;r+="</tbody></table>";for(let p of o)if(p.example)r+=`<h3>@${p.name}</h3>`,r+=`<p>${p.description||""}</p>`,r+="<h4>Example</h4>",r+=`<pre><code>${p.example.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}</code></pre>`}return r+="</body></html>",r}function sr(n=[],t=[],o=[],d){return JSON.stringify({components:n,templates:t,directives:o,extraContent:d||""},null,2)}async function ir(n){try{let{componentsDir:t,templatesDir:o,webComponentsConfig:d,customDirectives:r,config:p}=n;if(!p.enabled)return!1;let u=p.outputDir||"docs";if(await Ot.promises.mkdir(u,{recursive:!0}),console.log("Generating documentation..."),t)console.log(`Components directory: ${t}`);if(o)console.log(`Templates directory: ${o}`);console.log(`Output directory: ${u}`);let g=[];if(p.components!==!1&&t)console.log("Generating component documentation..."),g=await er(t,d),console.log(`Found ${g.length} components`);let y=[];if(p.templates!==!1&&o)console.log("Generating template documentation..."),y=await tr(o),console.log(`Found ${y.length} templates`);let h=[];if(p.directives!==!1)console.log("Generating directive documentation..."),h=await nr(r),console.log(`Found ${h.length} directives`);let x=p.format||"markdown",C=p.extraContent,R="",O="";switch(x){case"markdown":R=rr(g,y,h,C),O="md";break;case"html":R=or(g,y,h,C),O="html";break;case"json":R=sr(g,y,h,C),O="json";break;default:throw Error(`Unsupported documentation format: ${x}`)}let v=at.join(u,`stx-docs.${O}`);return await Bun.write(v,R),console.log(`Documentation generated: ${v}`),!0}catch(t){return console.error("Error generating documentation:",t),!1}}async function
|
|
1149
|
+
</tr>`;r+="</tbody></table>";for(let p of o)if(p.example)r+=`<h3>@${p.name}</h3>`,r+=`<p>${p.description||""}</p>`,r+="<h4>Example</h4>",r+=`<pre><code>${p.example.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}</code></pre>`}return r+="</body></html>",r}function sr(n=[],t=[],o=[],d){return JSON.stringify({components:n,templates:t,directives:o,extraContent:d||""},null,2)}async function ir(n){try{let{componentsDir:t,templatesDir:o,webComponentsConfig:d,customDirectives:r,config:p}=n;if(!p.enabled)return!1;let u=p.outputDir||"docs";if(await Ot.promises.mkdir(u,{recursive:!0}),console.log("Generating documentation..."),t)console.log(`Components directory: ${t}`);if(o)console.log(`Templates directory: ${o}`);console.log(`Output directory: ${u}`);let g=[];if(p.components!==!1&&t)console.log("Generating component documentation..."),g=await er(t,d),console.log(`Found ${g.length} components`);let y=[];if(p.templates!==!1&&o)console.log("Generating template documentation..."),y=await tr(o),console.log(`Found ${y.length} templates`);let h=[];if(p.directives!==!1)console.log("Generating directive documentation..."),h=await nr(r),console.log(`Found ${h.length} directives`);let x=p.format||"markdown",C=p.extraContent,R="",O="";switch(x){case"markdown":R=rr(g,y,h,C),O="md";break;case"html":R=or(g,y,h,C),O="html";break;case"json":R=sr(g,y,h,C),O="json";break;default:throw Error(`Unsupported documentation format: ${x}`)}let v=at.join(u,`stx-docs.${O}`);return await Bun.write(v,R),console.log(`Documentation generated: ${v}`),!0}catch(t){return console.error("Error generating documentation:",t),!1}}async function Aa(n){let t={enabled:!0,outputDir:n.output||"docs",format:n.format||"markdown",components:n.components!==!1,templates:n.templates!==!1,directives:n.directives!==!1,extraContent:n.extraContent},o=n.componentsDir||j.componentsDir,d=n.templatesDir||".";return ir({componentsDir:o,templatesDir:d,webComponentsConfig:j.webComponents,customDirectives:j.customDirectives,config:t})}var Zt={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0};function No(n,t={}){let o={...Zt,...t};if(n.trim()==="")return`
|
|
1150
1150
|
`;let d=n;if(o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=lr(d,o),d=fr(d,o),d=dr(d,o),o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,""),d=d.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(d=d.replace(/\r\n/g,`
|
|
1151
1151
|
`).replace(/\r/g,`
|
|
1152
1152
|
`),!d.endsWith(`
|
|
1153
1153
|
`))d+=`
|
|
1154
|
-
`;return d}function
|
|
1154
|
+
`;return d}function Pa(n,t={}){let o={...Zt,...t};if(n.trim()==="")return`
|
|
1155
1155
|
`;let d=n;if(d=d.replace(/^( *)```(html|stx)\n([\s\S]*?)^( *)```/gm,(r,p,u,g,y)=>{let h=g.split(`
|
|
1156
1156
|
`),x=h.filter((w)=>w.trim().length>0);if(x.length===0)return r;let C=Math.min(...x.map((w)=>{let A=w.match(/^( *)/);return A?A[1].length:0})),R=h.map((w)=>{if(w.trim().length===0)return"";return w.substring(C)}).join(`
|
|
1157
|
-
`),v=
|
|
1157
|
+
`),v=No(R,o).trimEnd().split(`
|
|
1158
1158
|
`).map((w)=>{if(w.trim().length===0)return"";return p+w}).join(`
|
|
1159
1159
|
`);return`${p}\`\`\`${u}
|
|
1160
1160
|
${v}
|
|
@@ -1177,9 +1177,9 @@ ${u}`}),t=t.replace(/(<\/[^>]+>)(?=<|$)/g,(r,p,u,g)=>{let y=g.substring(Math.max
|
|
|
1177
1177
|
`),t=t.split(`
|
|
1178
1178
|
`).map((r)=>r.trim()).join(`
|
|
1179
1179
|
`),t=t.replace(/^\n+/,"").replace(/\n+$/,""),t}function lr(n,t){let d=cr(n).split(`
|
|
1180
|
-
`),r=[],p=0,u=!1,g=t.useTabs?"\t":" ".repeat(t.indentSize);for(let y=0;y<d.length;y++){let h=d[y],x=h.trim();if(x===""){r.push("");continue}let C=x.match(/<script\b/i),R=x.match(/<\/script>/i);if(u&&!R){r.push(h);continue}let O=x===">";if(Qt(x)&&!x.startsWith("<")&&!x.startsWith("@")){r.push(g.repeat(p)+x);continue}let v=x.startsWith("@end"),w=x.startsWith("@else")||x.startsWith("@elseif"),A=x.startsWith("@")&&ur(x),U=x.startsWith("<!DOCTYPE")||x.startsWith("<!doctype"),
|
|
1180
|
+
`),r=[],p=0,u=!1,g=t.useTabs?"\t":" ".repeat(t.indentSize);for(let y=0;y<d.length;y++){let h=d[y],x=h.trim();if(x===""){r.push("");continue}let C=x.match(/<script\b/i),R=x.match(/<\/script>/i);if(u&&!R){r.push(h);continue}let O=x===">";if(Qt(x)&&!x.startsWith("<")&&!x.startsWith("@")){r.push(g.repeat(p)+x);continue}let v=x.startsWith("@end"),w=x.startsWith("@else")||x.startsWith("@elseif"),A=x.startsWith("@")&&ur(x),U=x.startsWith("<!DOCTYPE")||x.startsWith("<!doctype"),re=x.startsWith("<!--"),L=x.startsWith("</"),I=x.startsWith("<")&&!L&&!re&&!U,k=x.includes("/>")||pr(x),P=Qt(x);if(L||v)p=Math.max(0,p-1);let D=w?Math.max(0,p-1):p;if(O)r.push(h);else r.push(g.repeat(D)+x);if(I&&!k&&!P&&!O||A)p++;if(C)u=!0;if(R)u=!1}return r.join(`
|
|
1181
1181
|
`)}function dr(n,t){if(n=n.replace(/@(if|elseif|foreach|for|while)\s*\(\s*([^)]+)\s*\)/g,(o,d,r)=>{let p=r.trim().replace(/\s+/g," ");return`@${d}(${p})`}),n=n.replace(/@(csrf|method)\s*\(\s*([^)]*)\s*\)/g,(o,d,r)=>{if(r.trim()==="")return`@${d}`;return`@${d}(${r.trim()})`}),t.normalizeWhitespace)n=n.replace(/\{\{\s*([^}]+)\s*\}\}/g,(o,d)=>`{{ ${d.trim()} }}`),n=n.replace(/\{!!\s*([^!]+)\s*!!\}/g,(o,d)=>`{!! ${d.trim()} !!}`);return n}function pr(n){let t=["br","hr","img","input","meta","link","area","base","col","embed","source","track","wbr"];if(n.includes("/>"))return!0;let o=n.match(/<(\w+)/);if(o){let d=o[1];return t.includes(d.toLowerCase())}return!1}function Qt(n){return/<(\w+)(?:\s[^>]*)?>[\s\S]*?<\/\1>/.test(n)}function ur(n){let t=["if","unless","foreach","for","while","section","push","component","slot","markdown","wrap","error"];for(let o of t)if(n.startsWith(`@${o}`))return!n.includes(`@end${o}`);return!1}function fr(n,t){if(!t.sortAttributes)return n;return n.replace(/<(\w+)([^>]*)>/g,(o,d,r)=>{if(!r.trim())return o;if(r.includes("<")||r.includes(`
|
|
1182
|
-
`)||r.includes("@"))return o;let p=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,u=[],g;while((g=p.exec(r))!==null)u.push({name:g[1],value:g[2]});u.sort((h,x)=>{if(h.name==="id")return-1;if(x.name==="id")return 1;if(h.name==="class")return-1;if(x.name==="class")return 1;return h.name.localeCompare(x.name)});let y=u.map((h)=>h.value?`${h.name}=${h.value}`:h.name).join(" ");return`<${d}${y?` ${y}`:""}>`})}import en from"fs";import At from"path";async function
|
|
1182
|
+
`)||r.includes("@"))return o;let p=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,u=[],g;while((g=p.exec(r))!==null)u.push({name:g[1],value:g[2]});u.sort((h,x)=>{if(h.name==="id")return-1;if(x.name==="id")return 1;if(h.name==="class")return-1;if(x.name==="class")return 1;return h.name.localeCompare(x.name)});let y=u.map((h)=>h.value?`${h.name}=${h.value}`:h.name).join(" ");return`<${d}${y?` ${y}`:""}>`})}import en from"fs";import At from"path";async function Ia(n="index.stx",t={}){try{let o=t.force||!1,d=At.resolve(process.cwd(),n);if(await Bun.file(d).exists()){if(!o)throw Error(`File ${n} already exists. Use --force to overwrite.`);console.warn(`File ${n} already exists. Overwriting...`)}let r=At.dirname(d);if(!en.existsSync(r))en.mkdirSync(r,{recursive:!0});let p;if(t.template){let u=At.resolve(process.cwd(),t.template);if(!await Bun.file(u).exists())throw Error(`Template file ${t.template} does not exist.`);if(!u.endsWith(".stx"))console.warn(`Warning: Template file ${t.template} does not have a .stx extension. Using it anyway.`);p=await Bun.file(u).text(),console.warn(`Using template from ${t.template}`)}else if(t.preset)p=tn(t.preset),console.warn(`Using '${t.preset}' preset template`);else p=tn("basic");return await Bun.write(d,p),console.warn(`Created new stx file: ${n}`),!0}catch(o){return console.error(`Error creating file: ${o instanceof Error?o.message:String(o)}`),!1}}function tn(n){switch(n){case"basic":return rn();case"component":return mr();case"layout":return gr();case"blog":return hr();case"api":return yr();case"app":return xr();default:return rn()}}function rn(){return`<script>
|
|
1183
1183
|
const title = "My stx Page"
|
|
1184
1184
|
const description = "A page built with stx"
|
|
1185
1185
|
const features = [
|
|
@@ -1605,5 +1605,5 @@ const features = [
|
|
|
1605
1605
|
})();
|
|
1606
1606
|
</script>
|
|
1607
1607
|
</body>
|
|
1608
|
-
</html>`}var
|
|
1609
|
-
`)}export{
|
|
1608
|
+
</html>`}var Oa="f9c3713";function pu(n){return n}function fu(n){return n}function $a(n,t){let o=[],d=`${t}=`;for(let r=0;r<n.length;r++){let p=n[r];if(p.startsWith(d)){let u=p.slice(d.length);if(u)o.push(u);continue}if(p===t){let u=n[r+1];if(u!==void 0&&!u.startsWith("-"))o.push(u),r++}}return o}import Re from"fs";import ye from"path";function un(n){try{return Re.statSync(n).mtimeMs}catch{return null}}function wt(n,t){let o=Math.max(0,Math.round((t-n)/1000));if(o<60)return`${o}s ago`;if(o<3600)return`${Math.round(o/60)}m ago`;return`${Math.round(o/3600)}h ago`}function Ms(n,t){try{return globalThis.Bun?.resolveSync(n,t)??null}catch{return null}}function fn(n,t="stx"){let o=ye.resolve(n);for(let d=0;d<10;d++){let r=ye.join(o,"pantry","@stacksjs",t);if(Re.existsSync(r))return r;let p=ye.dirname(o);if(p===o)break;o=p}return null}var mn=["@stacksjs/stx","bun-plugin-stx"];function _s(n){try{let t=Re.readFileSync(ye.join(n,"package.json"),"utf8"),o=JSON.parse(t)?.version;return typeof o==="string"?o:null}catch{return null}}function Is(n,t=6){let o=ye.resolve(n),d=[],r=new Set;function p(g,y){if(y>t)return;let h;try{h=Re.realpathSync(g)}catch{return}if(r.has(h))return;r.add(h);for(let C of mn){let R=ye.join(g,C),O=_s(R);if(O!==null)d.push({name:C,version:O,dir:ye.relative(o,R)||R,nested:y>0})}let x;try{x=Re.readdirSync(g,{withFileTypes:!0})}catch{return}for(let C of x){if(!C.isDirectory()&&!C.isSymbolicLink())continue;if(C.name===".bin"||C.name===".cache")continue;let R=ye.join(g,C.name);if(C.name.startsWith("@")){let v;try{v=Re.readdirSync(R,{withFileTypes:!0})}catch{continue}for(let w of v){let A=ye.join(R,w.name,"node_modules");if(Re.existsSync(A))p(A,y+1)}continue}let O=ye.join(R,"node_modules");if(Re.existsSync(O))p(O,y+1)}}let u=ye.join(o,"node_modules");if(Re.existsSync(u))p(u,0);return d}function Ls(n){let t=[];for(let o of mn){let d=n.filter((u)=>u.name===o);if(d.length<=1)continue;let r=[...new Set(d.map((u)=>u.version))],p=d.map((u)=>`${u.version} at ${u.dir}`).join("; ");if(r.length===1){t.push({name:`${o} copies`,status:"info",detail:`${d.length} copies, all ${r[0]} \u2014 duplicated but in agreement`});continue}t.push({name:`${o} copies disagree`,status:"error",detail:`${r.length} versions installed, so which one runs depends on who imports it: ${p}`,fix:`remove the nested copies, or add an overrides entry pinning ${o}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${o}/package.json' -exec grep -H '"version"' {} +`})}return t}async function Mo(n={}){let t=n.cwd?ye.resolve(n.cwd):process.cwd(),o=n.resolve??Ms,d=Date.now(),r=[],p=o("@stacksjs/stx",t);r.push(p?{name:"@stacksjs/stx resolves to",status:"ok",detail:p}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let u=o("bun-plugin-stx",t);if(u)r.push({name:"bun-plugin-stx resolves to",status:"ok",detail:u});for(let y of Ls(Is(t)))r.push(y);let g=fn(t,"stx");if(!g)r.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let y=ye.join(g,"src/signals.ts"),h=[ye.join(g,"dist/index.js"),ye.join(g,"dist/signals.js")].find((v)=>Re.existsSync(v))||null,x=un(y),C=h?un(h):null;if(x==null)r.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${g} but no src/signals.ts to compare`});else if(C==null)r.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 ${g} && bun build.ts`});else if(C<x){let v=Math.round((x-C)/1000);r.push({name:"pantry dist freshness",status:"error",detail:`dist (${wt(C,d)}) is OLDER than src/signals.ts (${wt(x,d)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${g} && bun build.ts`})}else r.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${wt(x,d)}, dist ${wt(C,d)})`});let R=ye.join(t,"node_modules/@stacksjs/stx"),O=null;try{O=Re.lstatSync(R)}catch{O=null}if(!O)r.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(O.isSymbolicLink()){let v=null;try{v=Re.realpathSync(R)}catch{}let w=(()=>{try{return Re.realpathSync(g)}catch{return g}})();r.push(v===w?{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 r.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(r.push({name:"dev runtime cache",status:"info",detail:"cleared automatically on source edits by the dev watcher (clearDevCaches, #1745 item C)"}),n.generateRuntime)try{let h=n.generateRuntime().length;r.push(h>1000?{name:"signals runtime",status:"ok",detail:`generated ${h.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${h} chars \u2014 suspiciously short`})}catch(y){r.push({name:"signals runtime",status:"error",detail:`failed to generate: ${y.message}`})}return{checks:r,ok:!r.some((y)=>y.status==="error")}}function Do(n){let t={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},o=["stx runtime resolution:"];for(let d of n.checks)if(o.push(` ${t[d.status]} ${d.name}: ${d.detail}`),d.fix)o.push(` \u2192 ${d.fix}`);return o.push(""),o.push(n.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),o.join(`
|
|
1609
|
+
`)}export{$a,Ra,Aa,No,Pa,Ia,Oa,pu,fu,Mo,Do,cs,ls,us};
|