@stacksjs/stx 0.2.914 → 0.2.917
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/build-defer-scripts.d.ts +12 -0
- package/dist/build-defer-scripts.js +37 -0
- package/dist/build-externalize-repeated.js +2 -0
- package/dist/build-externalize.js +1 -1
- package/dist/builtins/image-delivery.js +2 -0
- package/dist/builtins/image-placeholder.js +2 -0
- package/dist/{chunk-2vdbt2a7.js → chunk-0adc8x2h.js} +1 -1
- package/dist/{chunk-tykdvjbe.js → chunk-0asdv3hk.js} +2 -2
- package/dist/{chunk-1mmv8wb8.js → chunk-0atz8fjx.js} +4 -4
- package/dist/chunk-0fm6avxt.js +3 -0
- package/dist/{chunk-5ya4nmmr.js → chunk-0sj79ha5.js} +4 -4
- package/dist/{chunk-dhkw1r4y.js → chunk-0v7555tr.js} +4 -4
- package/dist/{chunk-5jn2qyv7.js → chunk-11c7xg1z.js} +1 -1
- package/dist/chunk-11rnqey0.js +2 -0
- package/dist/{chunk-4b110x6r.js → chunk-16sfjkc4.js} +2 -2
- package/dist/{chunk-kmy34he2.js → chunk-1hbf5e1h.js} +2 -2
- package/dist/{chunk-9atdw0p8.js → chunk-1jvt9t3r.js} +2 -2
- package/dist/chunk-1mx3j280.js +2 -0
- package/dist/{chunk-0d3pkkrv.js → chunk-23x3k751.js} +2 -2
- package/dist/chunk-29v3b5ks.js +2 -0
- package/dist/chunk-2cay3heb.js +2 -0
- package/dist/{chunk-6yketqa1.js → chunk-2f5jjxcj.js} +2 -2
- package/dist/{chunk-razwegar.js → chunk-2vx2ben8.js} +2 -2
- package/dist/{chunk-132j46ey.js → chunk-302nw40c.js} +1 -1
- package/dist/chunk-31yx4sjh.js +2 -0
- package/dist/chunk-33fnbw33.js +2 -0
- package/dist/{chunk-wbsbrm6n.js → chunk-36cz2v8k.js} +30 -30
- package/dist/{chunk-9gptdyqq.js → chunk-388xpdw5.js} +31 -5
- package/dist/chunk-38kerh2r.js +2 -0
- package/dist/chunk-38y11q8x.js +2 -0
- package/dist/{chunk-kyfydbtg.js → chunk-3h4db9yb.js} +3 -3
- package/dist/{chunk-3m457a9q.js → chunk-3jc6yb02.js} +3 -3
- package/dist/chunk-3q80f7mt.js +2 -0
- package/dist/{chunk-fghf6amb.js → chunk-43sgpy4e.js} +5 -5
- package/dist/{chunk-w4177qn3.js → chunk-4e18r89n.js} +2 -2
- package/dist/chunk-4pve3r5a.js +2 -0
- package/dist/{chunk-c08jvjqt.js → chunk-4vz17ytv.js} +8 -8
- package/dist/chunk-5afnyvw5.js +2 -0
- package/dist/chunk-5d5dxts6.js +2 -0
- package/dist/chunk-5fdsyyfe.js +2 -0
- package/dist/chunk-67yr4m5h.js +2 -0
- package/dist/chunk-6aqr0e6s.js +2 -0
- package/dist/chunk-6bw02d1t.js +2 -0
- package/dist/chunk-76mn123c.js +2 -0
- package/dist/{chunk-3z3b98f0.js → chunk-789yp1tg.js} +3 -3
- package/dist/chunk-7ar11ccn.js +2 -0
- package/dist/chunk-7fc0vrs5.js +2 -0
- package/dist/chunk-82fg5gp6.js +2 -0
- package/dist/{chunk-gyv2bsmn.js → chunk-88fx8xc1.js} +2 -2
- package/dist/chunk-89r7bbsk.js +2 -0
- package/dist/{chunk-h8tgqq8x.js → chunk-8b8az19t.js} +5 -5
- package/dist/chunk-8egbh6z1.js +2 -0
- package/dist/chunk-8n9jd8cz.js +2 -0
- package/dist/{chunk-9tj16d70.js → chunk-8wqhzzkn.js} +2 -2
- package/dist/chunk-8x3yaahc.js +2 -0
- package/dist/{chunk-rcwg2pdk.js → chunk-91p8p2cc.js} +5 -5
- package/dist/chunk-94qc4zwb.js +2 -0
- package/dist/{chunk-d4hnj3ct.js → chunk-952dfmcb.js} +2 -2
- package/dist/{chunk-72pbhpq8.js → chunk-95j8660f.js} +2 -2
- package/dist/{chunk-75r2p1cz.js → chunk-9928zdej.js} +2 -2
- package/dist/{chunk-8f5x16ht.js → chunk-9ay18k46.js} +1 -1
- package/dist/{chunk-2gwgcybp.js → chunk-9kn81bmp.js} +1 -1
- package/dist/{chunk-9bexzgws.js → chunk-9tv0tw7f.js} +1 -1
- package/dist/{chunk-0h06ry05.js → chunk-9w9y84t5.js} +6 -6
- package/dist/chunk-a5h9bwrc.js +2 -0
- package/dist/{chunk-gg31th5s.js → chunk-ar6jeqmm.js} +4 -4
- package/dist/{chunk-kx3mmpfd.js → chunk-b5qzed8y.js} +37 -37
- package/dist/chunk-bej9kz05.js +2 -0
- package/dist/chunk-bh2khcet.js +2 -0
- package/dist/{chunk-4h48fgkz.js → chunk-bm6y085n.js} +3 -3
- package/dist/{chunk-9phqwza2.js → chunk-c13dv3wm.js} +10 -10
- package/dist/chunk-c6096ssb.js +2 -0
- package/dist/chunk-ccgabq3a.js +2 -0
- package/dist/{chunk-sdf4c754.js → chunk-cxsc37fg.js} +2 -2
- package/dist/{chunk-jap66ea8.js → chunk-da05660m.js} +37 -37
- package/dist/{chunk-2671myh8.js → chunk-dwt2drzf.js} +5 -5
- package/dist/chunk-e0tvd7jj.js +2 -0
- package/dist/{chunk-sg95ne5m.js → chunk-ezqfrea9.js} +5 -5
- package/dist/{chunk-z27szg5v.js → chunk-f0sxbgbm.js} +1 -1
- package/dist/{chunk-08bzdet4.js → chunk-fn1reean.js} +19 -19
- package/dist/{chunk-2m4d8jkv.js → chunk-frpsrv1e.js} +2 -2
- package/dist/{chunk-pc89t52s.js → chunk-ftvpz1j4.js} +5 -5
- package/dist/{chunk-zjrnz9yt.js → chunk-fvr3h2fr.js} +3 -3
- package/dist/{chunk-8p3vqt2q.js → chunk-fzcqw147.js} +2 -2
- package/dist/{chunk-jttzrv0w.js → chunk-gg715pj6.js} +5 -5
- package/dist/chunk-gmmqz698.js +2 -0
- package/dist/{chunk-nzw0y1ny.js → chunk-h0aw9hmc.js} +3 -3
- package/dist/chunk-hxftzw0x.js +2 -0
- package/dist/{chunk-mpfm5ctr.js → chunk-jr2r2nh5.js} +4 -4
- package/dist/chunk-js1wayhb.js +2 -0
- package/dist/chunk-k2t0w8z1.js +2 -0
- package/dist/chunk-k8s3hyh2.js +2 -0
- package/dist/chunk-kcpxqsdj.js +2 -0
- package/dist/{chunk-nan0ysys.js → chunk-m8n14s3z.js} +2 -2
- package/dist/{chunk-as1p2pch.js → chunk-ma5ptt4m.js} +2 -2
- package/dist/{chunk-fyb9qy7x.js → chunk-mf5cqv1k.js} +9 -9
- package/dist/{chunk-jhegz7az.js → chunk-mgj074y2.js} +5 -5
- package/dist/chunk-mjr5fkc2.js +2 -0
- package/dist/{chunk-gqh8shzf.js → chunk-mt5ewkbg.js} +2 -2
- package/dist/{chunk-0m0w8rr1.js → chunk-n4m50dpk.js} +14 -14
- package/dist/chunk-na0e3s88.js +2 -0
- package/dist/chunk-new89wh2.js +2 -0
- package/dist/{chunk-eyw4g6kq.js → chunk-ngqb22wj.js} +9 -9
- package/dist/{chunk-v0yay1kw.js → chunk-nhyv3w4r.js} +1 -1
- package/dist/{chunk-yzgtsrjb.js → chunk-npj20tj9.js} +2 -2
- package/dist/{chunk-j01a1am0.js → chunk-nwef47nx.js} +1 -1
- package/dist/{chunk-zk1c6tg7.js → chunk-p3fepzt9.js} +3 -3
- package/dist/{chunk-z8rf8abt.js → chunk-p3x84jj0.js} +1 -1
- package/dist/chunk-p9bghe13.js +2 -0
- package/dist/{chunk-fycxc75p.js → chunk-pyyda92j.js} +1 -1
- package/dist/chunk-q2cwzgd0.js +2 -0
- package/dist/chunk-q60afqr7.js +2 -0
- package/dist/chunk-qdwtemy1.js +2 -0
- package/dist/chunk-qp0ndbk6.js +2 -0
- package/dist/{chunk-1ezcxbpg.js → chunk-qsexsrw2.js} +5 -5
- package/dist/{chunk-w3y8408q.js → chunk-r7y1196g.js} +2 -2
- package/dist/{chunk-ta7cwykn.js → chunk-ra2tzsvz.js} +4 -4
- package/dist/chunk-rzsvxjse.js +2 -0
- package/dist/chunk-s2c0ynn9.js +2 -0
- package/dist/{chunk-6w9av0n9.js → chunk-sdmq09jw.js} +1 -1
- package/dist/{chunk-qvjg8w1a.js → chunk-t65f98qv.js} +2 -2
- package/dist/chunk-v1wr2vdx.js +2 -0
- package/dist/{chunk-4fmfc48n.js → chunk-v78hjbz0.js} +3 -3
- package/dist/{chunk-ekyx5z50.js → chunk-vayzmvf5.js} +6 -6
- package/dist/{chunk-f9vch452.js → chunk-w6ydg43d.js} +3 -3
- package/dist/{chunk-e52rtbde.js → chunk-wc10m4tp.js} +3 -3
- package/dist/chunk-wcxa8xy2.js +2 -0
- package/dist/chunk-wgrj0cvs.js +2 -0
- package/dist/{chunk-49n9xce7.js → chunk-wj9bqkc0.js} +1 -1
- package/dist/{chunk-r4za879x.js → chunk-wm24jx3t.js} +2 -2
- package/dist/chunk-wpkwx3wq.js +2 -0
- package/dist/chunk-wq17dce6.js +2 -0
- package/dist/chunk-wvc6eayq.js +2 -0
- package/dist/chunk-xa98a901.js +2 -0
- package/dist/chunk-xjt5129x.js +2 -0
- package/dist/{chunk-eca022er.js → chunk-xnp031ba.js} +6 -6
- package/dist/{chunk-hgtcgz9b.js → chunk-yc3frw0z.js} +2 -2
- package/dist/chunk-yn02d599.js +2 -0
- package/dist/{chunk-g9bsafzx.js → chunk-yq2krsc9.js} +4 -4
- package/dist/chunk-ywrpmyzj.js +5 -0
- package/dist/{chunk-95x3jvmz.js → chunk-z110bf2c.js} +8 -6
- package/dist/{chunk-3syagjd7.js → chunk-zv3rn0ch.js} +4 -4
- package/dist/cli.js +14 -14
- package/dist/client/signals-mount-runtime.js +4 -2
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/dev-server/ts-css.d.ts +1 -1
- package/dist/dev-server/ts-css.js +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/native/compiler/html-to-ir.d.ts +3 -1
- package/dist/native/compiler/html-to-ir.js +30 -0
- package/dist/process.js +1 -1
- package/dist/pwa.js +3 -3
- package/dist/serve-page-assets.d.ts +2 -0
- package/dist/serve-page-assets.js +14 -0
- package/dist/ssg.js +25 -25
- package/dist/types/config-types.d.ts +2 -0
- package/package.json +5 -5
- package/dist/chunk-1dc6h93m.js +0 -2
- package/dist/chunk-1htdsypj.js +0 -3
- package/dist/chunk-1k5ns68h.js +0 -2
- package/dist/chunk-2870sk9z.js +0 -2
- package/dist/chunk-2fyey6pn.js +0 -2
- package/dist/chunk-2jkq15je.js +0 -2
- package/dist/chunk-3d3f35fz.js +0 -2
- package/dist/chunk-3e3zsgke.js +0 -2
- package/dist/chunk-3fabcebr.js +0 -2
- package/dist/chunk-41y868zf.js +0 -2
- package/dist/chunk-5xsghm23.js +0 -2
- package/dist/chunk-7k1thytm.js +0 -2
- package/dist/chunk-8n42epb6.js +0 -5
- package/dist/chunk-94r6mkcy.js +0 -2
- package/dist/chunk-9s8he3d1.js +0 -2
- package/dist/chunk-9y4gz22m.js +0 -2
- package/dist/chunk-a02sy0m5.js +0 -2
- package/dist/chunk-abs4fwmf.js +0 -2
- package/dist/chunk-abxwggen.js +0 -2
- package/dist/chunk-asewbsct.js +0 -2
- package/dist/chunk-bprjp80g.js +0 -2
- package/dist/chunk-c60egpe6.js +0 -2
- package/dist/chunk-cjq455ve.js +0 -2
- package/dist/chunk-cqq68aw8.js +0 -2
- package/dist/chunk-d9066gp6.js +0 -2
- package/dist/chunk-dmsrpf7h.js +0 -2
- package/dist/chunk-fzh73jtc.js +0 -2
- package/dist/chunk-g3a2gx3p.js +0 -2
- package/dist/chunk-g6s4151k.js +0 -2
- package/dist/chunk-gcc5tp4j.js +0 -2
- package/dist/chunk-gf4a9h9x.js +0 -2
- package/dist/chunk-gmczbe3j.js +0 -2
- package/dist/chunk-h13csdpm.js +0 -2
- package/dist/chunk-h7k1y40p.js +0 -2
- package/dist/chunk-h7xqba9k.js +0 -2
- package/dist/chunk-hpxhxwda.js +0 -2
- package/dist/chunk-j846tv4t.js +0 -2
- package/dist/chunk-jnk3nk5k.js +0 -2
- package/dist/chunk-jy5gh22e.js +0 -2
- package/dist/chunk-jzbte09f.js +0 -2
- package/dist/chunk-k0b1t59r.js +0 -2
- package/dist/chunk-k5v22gn4.js +0 -2
- package/dist/chunk-kwh5pjqd.js +0 -2
- package/dist/chunk-mgcakk1m.js +0 -2
- package/dist/chunk-n3bt1sv5.js +0 -2
- package/dist/chunk-n62nqhey.js +0 -2
- package/dist/chunk-n6ve45hj.js +0 -2
- package/dist/chunk-ptrz5xwt.js +0 -2
- package/dist/chunk-q3ha3fcj.js +0 -2
- package/dist/chunk-qgc59a7d.js +0 -2
- package/dist/chunk-qjkpwjg6.js +0 -2
- package/dist/chunk-t4paeg33.js +0 -2
- package/dist/chunk-tfn3x8t2.js +0 -2
- package/dist/chunk-vhk7a79j.js +0 -2
- package/dist/chunk-vmn8vpp8.js +0 -2
- package/dist/chunk-x1svtz8k.js +0 -2
- package/dist/chunk-ykx4zt07.js +0 -2
- package/dist/chunk-zb75qq5j.js +0 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{B,An,Kt,Xt,y,s,Ce,g}from"./chunk-
|
|
2
|
+
import{B,An,Kt,Xt,y,s,Ce,g}from"./chunk-b5qzed8y.js";import{Pt,Ue,Mc,Es,si,oi,i}from"./chunk-n4m50dpk.js";import{we}from"./chunk-0jdz31q1.js";import{ce,Vr,De,K,jn}from"./chunk-4vz17ytv.js";import{Er,Tr}from"./chunk-t65f98qv.js";import{Dt,Rr,Ks,Xs,Gs,Lt,jt,Bt,Ft,zt,Ht,We}from"./chunk-388xpdw5.js";import{zs,a,j}from"./chunk-mf5cqv1k.js";import{Et,cn,Be,V,Da,Bo,ps,ot,La,Tt,Fe}from"./chunk-3h4db9yb.js";import{e,Sn,xr,S}from"./chunk-ngqb22wj.js";import{lt}from"./chunk-43sgpy4e.js";import{He}from"./chunk-cwcmmgvz.js";import{Wn}from"./chunk-yc3frw0z.js";import{re,Ae,Pe}from"./chunk-8b8az19t.js";import{l}from"./chunk-4e18r89n.js";import{ne}from"./chunk-e5rag6rh.js";import{c,f}from"./chunk-8tfpv6zf.js";async function Pn(n){try{let t=await Bun.file(n).text(),o=En(t),d=On(t,n),r=Dn(t,o),p=Mn(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
|
-
`).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,m=(n.match(/\{!![\s\S]*?!!\}/g)||[]).length,x=(n.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,h=u+m+x,b=(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+b*0.3+(r>10?r*0.05:0)+v));return{lines:t.length,characters:n.length,directives:p,expressions:h,components:b,layouts:C,scriptLines:r,complexity:w}}function
|
|
5
|
-
`).filter((b)=>b.length>120);if(x.length>0)o.push({type:"info",category:"maintainability",message:`Found ${x.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
|
|
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,m=(n.match(/\{!![\s\S]*?!!\}/g)||[]).length,x=(n.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,h=u+m+x,b=(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+b*0.3+(r>10?r*0.05:0)+v));return{lines:t.length,characters:n.length,directives:p,expressions:h,components:b,layouts:C,scriptLines:r,complexity:w}}function On(n,t){let o=[],d=Ut(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=Ut(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 m=n.match(/<img[^>]*>/g);if(m){let b=m.filter((C)=>!C.includes("alt="));if(b.length>0)o.push({type:"warning",category:"accessibility",message:`Found ${b.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let x=n.split(`
|
|
5
|
+
`).filter((b)=>b.length>120);if(x.length>0)o.push({type:"info",category:"maintainability",message:`Found ${x.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 Dn(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 Mn(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 Ut(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 Ca(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((m)=>m.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=_n(o);return{results:o,summary:r}}function _n(n){let t=n.length,o=n.reduce((h,b)=>h+b.metrics.lines,0),d=t>0?n.reduce((h,b)=>h+b.metrics.complexity,0)/t:0,r=n.reduce((h,b)=>h+b.issues.length,0),p={};n.forEach((h)=>{h.issues.forEach((b)=>{p[b.category]=(p[b.category]||0)+1})});let u=t>0?n.reduce((h,b)=>h+b.performance.estimatedRenderTime,0)/t:0,m=Math.max(1,Math.min(10,Math.round(10-u/2-d/2))),x=[];if(d>6)x.push("Project has high average complexity. Consider refactoring complex templates.");if(r>t*2)x.push("High number of issues detected. Run detailed analysis on individual files.");if(p.security>0)x.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:m,recommendations:x}}var{serve:Vn}=globalThis.Bun;import $t 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,19 +82,19 @@ 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
|
|
85
|
+
</div>`}async function In(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 Hn(n){if(!await In(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 Hn(d))return d}throw Error(`Could not find an available port between ${n} and ${n+t-1}`)}var Bn={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function Fn(){try{let n=await import("./chunk-29v3b5ks.js");if(typeof n.openDevWindow!=="function")return null;return n}catch{return null}}async function Qe(n,t={}){let o={...Bn,...t},d=await Fn();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 mt(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
|
`,x=Function(u)();if(x)return x}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
|
-
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
|
|
90
|
-
`)){let p=d.trim().toLowerCase();d="",
|
|
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 Rt(n,t={}){let o=t.port||3000,d=t.watch!==!1,r=Ze.resolve(n);if(!$t.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||[],se=[...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">
|
|
94
94
|
<head>
|
|
95
95
|
<meta charset="UTF-8">
|
|
96
96
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
97
|
-
<title>${
|
|
97
|
+
<title>${qn(R.title||Ze.basename(r))}</title>
|
|
98
98
|
<!-- Syntax highlighting styles -->
|
|
99
99
|
<style id="syntax-theme">
|
|
100
100
|
:root {
|
|
@@ -250,12 +250,12 @@ Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in brow
|
|
|
250
250
|
</script>
|
|
251
251
|
</body>
|
|
252
252
|
</html>
|
|
253
|
-
`,!0}catch(C){return console.error(`${e.red}Error processing Markdown file:${e.reset}`,C),!1}};if(!await u())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 h=
|
|
253
|
+
`,!0}catch(C){return console.error(`${e.red}Error processing Markdown file:${e.reset}`,C),!1}};if(!await u())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 h=Vn({port:x,fetch(C){if(new URL(C.url).pathname==="/")return new Response(p,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}});return new Response("Not Found",{status:404})},error(C){return new Response(`<pre>${C}
|
|
254
254
|
${C.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
255
255
|
${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(`
|
|
256
256
|
${e.bright}\u2192 ${e.cyan}http://localhost:${x}/${e.reset}`),console.log(`
|
|
257
257
|
${e.yellow}Routes:${e.reset}`);let b=Ze.relative(process.cwd(),r);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${b}${e.reset}`),console.log(`
|
|
258
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(h.url.toString(),()=>{if(d)$t.watch(Ze.dirname(r),{recursive:!0}).close();h.stop()}),t.native)await Qe(x,{title:Ze.basename(r,".md")});if(d){let C=Ze.dirname(r);console.log(`${e.blue}Watching ${e.bright}${C}${e.reset} for changes...`);let R=$t.watch(C,{recursive:!0},async(O,v)=>{if(v&&v.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${v}${e.yellow} changed, reprocessing...${e.reset}`),await u()});process.on("SIGINT",()=>{R.close(),h.stop(),process.exit(0)})}return!0}function
|
|
258
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(h.url.toString(),()=>{if(d)$t.watch(Ze.dirname(r),{recursive:!0}).close();h.stop()}),t.native)await Qe(x,{title:Ze.basename(r,".md")});if(d){let C=Ze.dirname(r);console.log(`${e.blue}Watching ${e.bright}${C}${e.reset} for changes...`);let R=$t.watch(C,{recursive:!0},async(O,v)=>{if(v&&v.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${v}${e.yellow} changed, reprocessing...${e.reset}`),await u()});process.on("SIGINT",()=>{R.close(),h.stop(),process.exit(0)})}return!0}function qn(n){return String(n??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Xn}=globalThis.Bun;import Le from"fs";import ge from"path";class Wt{clients=new Set;server=null;options;constructor(n={}){this.options={wsPort:n.wsPort??3001,showOverlay:n.showOverlay??!0,reconnectInterval:n.reconnectInterval??1000,maxReconnectAttempts:n.maxReconnectAttempts??10,verbose:n.verbose??!1}}start(n){let t=n??this.options.wsPort,o=20;for(let d=0;d<o;d++)try{if(this.server=Bun.serve({port:t,fetch(r,p){if(p.upgrade(r,{data:{}}))return;return new Response("stx Hot Reload Server",{headers:{"Content-Type":"text/plain"}})},websocket:{open:(r)=>{if(this.clients.add(r),this.options.verbose)console.log(`[HMR] Client connected (${this.clients.size} total)`);r.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close:(r)=>{if(this.clients.delete(r),this.options.verbose)console.log(`[HMR] Client disconnected (${this.clients.size} total)`)},message:(r,p)=>{let u=typeof p==="string"?p:p.toString();if(u==="ping")return;try{let m=JSON.parse(u);if(m.type==="console"&&Array.isArray(m.args)){let x=m.args.join(" "),b={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[m.level]??"\x1B[36m";console.log(`${b}[browser]${m.level!=="log"?` ${m.level}`:""}\x1B[0m ${x}`)}}catch{}}}}),this.options.verbose)console.log(`[HMR] WebSocket server started on port ${t}`);return t}catch(r){if(r?.code==="EADDRINUSE"){t++;continue}throw r}throw Error(`Could not find an available port after ${o} attempts starting from ${n??this.options.wsPort}`)}stop(){for(let n of this.clients)try{n.close()}catch{}if(this.clients.clear(),this.server)this.server.stop(),this.server=null;if(this.options.verbose)console.log("[HMR] Server stopped")}broadcast(n){let t=JSON.stringify(n),o=0;for(let d of this.clients)try{if(d.readyState===1)d.send(t),o++}catch{this.clients.delete(d)}if(this.options.verbose&&o>0)console.log(`[HMR] Broadcast ${n.type} to ${o} client(s)`)}reload(n){if(this.options.verbose)console.log(`[HMR] Sending reload to ${this.clients.size} client(s) for: ${n||"all"}`);this.broadcast({type:"reload",path:n,timestamp:Date.now()})}updateCss(n,t){this.broadcast({type:"css-update",path:n,content:t,timestamp:Date.now()})}error(n){this.broadcast({type:"error",content:n,timestamp:Date.now()})}get clientCount(){return this.clients.size}get port(){return this.options.wsPort}}function Kn(n,t={}){let{showOverlay:o=!0,reconnectInterval:d=1000,maxReconnectAttempts:r=10}=t;return`
|
|
259
259
|
<script>
|
|
260
260
|
(function() {
|
|
261
261
|
// stx Hot Reload Client
|
|
@@ -454,7 +454,7 @@ else {
|
|
|
454
454
|
};
|
|
455
455
|
})();
|
|
456
456
|
</script>
|
|
457
|
-
`}function Ne(n,t,o={}){let d=
|
|
457
|
+
`}function Ne(n,t,o={}){let d=Kn(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 gt(n){let t=n.toLowerCase();return t.endsWith(".css")||t.endsWith(".scss")||t.endsWith(".sass")||t.endsWith(".less")}function ht(n){let t=n.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>t.endsWith(d))}function yt(n){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((o)=>o.test(n))}var et=null;function xt(n){if(!et)et=new Wt(n);return et}function st(){if(et)et.stop(),et=null}import bt 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?`./${bt.relative(bt.dirname(n.config?.outdir||"dist"),o.webComponents.outputDir||"dist/web-components")}`:"/web-components",p=[];if(o.webComponents?.enabled)try{let u=await zs(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 m=new Set;if(o.cache&&o.cachePath){let w=await Er(u,o);if(w){if(o.debug)console.log(`Using cached version of ${u}`);return{contents:w,loader:"html"}}}let x=await De(()=>Bun.file(u).text(),"",(w)=>{throw new Vr(`Failed to read stx file: ${u}`,u,void 0,void 0,`File read error: ${w.message}`)});if(!x)throw new Vr(`stx file is empty: ${u}`,u);let{scriptContent:h,templateContent:b,allScripts:C}=we.time("script-extraction",()=>{let w=x,A=B(x);if(A)w=A.content.trim();let U=x.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],se="",L=[];for(let k of U){let P=k.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",D=k.match(/<script\b([^>]*)>/i),q=D?D[1]:"";if(/\bserver\b/i.test(q))se=P;else L.push(k)}let I=w.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:se,templateContent:I,allScripts:L}}),R={__filename:u,__dirname:bt.dirname(u),__stx:{webComponentsPath:r,builtComponents:p}};await De(()=>y(h,R,u),void 0,(w)=>{let A=new ce(`Script execution failed in ${u}: ${w.message}`,u,void 0,void 0,h.substring(0,100));if(K.log(A,{filePath:u,scriptContent:h}),o.debug)throw A});let v=await we.timeAsync("directive-processing",async()=>await i(b,R,u,o,m));if(C.length>0){let{interpolateScriptsInTemplate:w}=await import("./chunk-kcpxqsdj.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
460
|
${A}`}if(v=await Pe(v),m.forEach((w)=>d.add(w)),o.cache&&o.cachePath){if(await Tr(u,v,m,o),o.debug)console.log(`Cached template ${u} with ${m.size} dependencies`)}return{contents:v,loader:"html"}}catch(m){let x=m instanceof Error?m:new ce(`Plugin processing failed: ${String(m)}`,u);if(K.log(x,{filePath:u,buildConfig:n.config}),jn.logDetailedError(x,{filePath:u,plugin:"bun-plugin-stx"}),o.debug)console.error("stx Plugin Error:",x);let h=x,b=h.line||null,C=h.context||null;return{contents:o.debug||ne()?`<!DOCTYPE html>
|
|
@@ -517,12 +517,12 @@ ${A}`}if(v=await Pe(v),m.forEach((w)=>d.add(w)),o.cache&&o.cachePath){if(await T
|
|
|
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 os(n,t={}){let o=t.port||3000,d=t.watch!==!1,r=t.hotReload!==!1&&d,p=null,u=t.hmrPort||o+1,m=ge.resolve(n);if(!
|
|
520
|
+
</html>`,loader:"html"}}})}};async function os(n,t={}){let o=t.port||3000,d=t.watch!==!1,r=t.hotReload!==!1&&d,p=null,u=t.hmrPort||o+1,m=ge.resolve(n);if(!Le.existsSync(m))return console.error(`${e.red}Error: File not found: ${e.bright}${m}${e.reset}`),!1;if(m.endsWith(".md"))return Rt(m,t);else if(!m.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${m}${e.reset}. Only .stx and .md files are supported.`),!1;let x=l(process.cwd(),"output");Le.mkdirSync(x,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${n}${e.reset}...`);let h=null,b=async()=>{try{let P={name:"public-assets",setup(xe){xe.onResolve({filter:/^\/(images|fonts|assets|public)\//},(pe)=>({path:pe.path,external:!0}))}},D=await Bun.build({entrypoints:[m],outdir:x,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 q=D.outputs.find((xe)=>xe.path.endsWith(".html"));if(!q)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return h=await Bun.file(q.path).text(),!0}catch(P){return console.error(`${e.red}Error building stx file:${e.reset}`,P),!1}};if(!await b())return!1;let R=ge.dirname(m);await Sn(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=xt({wsPort:P,verbose:!1}),u=p.start(P)}let v={},w=null,A;try{let{loadStxConfig:P}=await import("./chunk-k2t0w8z1.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 q=Object.keys(v).length;if(q>0)console.log(`${e.blue}Loaded ${e.bright}${q} API route${q>1?"s":""}${e.reset}`)}if(D?.broadcasting?.enabled)try{let{startBroadcasting:q,loadChannels:Q}=await import("./chunk-38y11q8x.js"),xe=D.broadcasting;await q(xe);let pe=xe.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(Le.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(q){console.warn(`${e.yellow}Broadcasting failed to start: ${q.message}${e.reset}`)}}catch{}let{createServerApi:U,isServerApiSource:se}=await import("./chunk-6bw02d1t.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=Xn({port:O,async fetch(P){return Wn(P,await(async()=>{let D=new URL(P.url);if([x,ge.dirname(m),ge.join(process.cwd(),"public")].some((ie)=>se(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 q=await L(P);if(q)return q;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(x,D.pathname);if(Le.existsSync(Q)&&Le.statSync(Q).isFile()){let ie=Bun.file(Q),F=ge.extname(Q).toLowerCase(),E="text/plain";if(F===".ts"||F===".tsx"){let je=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ie.text(),Je=je.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 xe=ge.dirname(m),pe=ge.join(xe,D.pathname);if(Le.existsSync(pe)&&Le.statSync(pe).isFile()){let ie=Bun.file(pe),F=ge.extname(pe).toLowerCase(),E="text/plain";if(F===".ts"||F===".tsx"){let je=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ie.text(),Je=je.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(Le.existsSync(ke)&&Le.statSync(ke).isFile()){let ie=Bun.file(ke),F=ge.extname(ke).toLowerCase(),E="application/octet-stream";if(F===".ts"||F===".tsx"){let je=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ie.text(),Je=je.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(),m);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(
|
|
525
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(I.url.toString(),()=>{if(d)Le.watch(ge.dirname(m),{recursive:!0}).close();I.stop()}),t.native){let P=await Bun.file(m).text(),D=mt(P);await Qe(O,{title:ge.basename(m,".stx"),titlebarHidden:t.titlebarHidden===!0,nativeSidebar:!!D,sidebarConfig:D})}if(d){let P=ge.dirname(m);console.log(`${e.blue}Watching ${e.bright}${P}${e.reset} for changes...`);let D=Le.watch(P,{recursive:!0},async(q,Q)=>{if(!Q||yt(Q))return;if(ht(Q)){console.log(`${e.yellow}File ${e.bright}${Q}${e.yellow} changed, rebuilding...${e.reset}`),lt.clear(),Ce();let xe=await b();if(await xr(R),r&&p)if(xe)p.reload(Q);else p.error("Build failed - check console for details")}else if(gt(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:Gn}=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,7 +833,7 @@ 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 is(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={},m=[],x=async()=>{try{for(let v of n){let w=Se.resolve(v);if(w.endsWith(".md"))try{let{content:U,data:se}=await Ue(w,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:j.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),
|
|
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 is(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={},m=[],x=async()=>{try{for(let v of n){let w=Se.resolve(v);if(w.endsWith(".md"))try{let{content:U,data:se}=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||[],q=[...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">
|
|
@@ -997,23 +997,23 @@ else {
|
|
|
997
997
|
</body>
|
|
998
998
|
</html>
|
|
999
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}))}},se;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}se=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
|
|
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}=Ks(I,{page:!0});m.push({pattern:k,paramNames:P,filePath:w,routeTemplate:I,fileType:"stx"}),u[I]={filePath:w,content:se,fileType:"stx"}}else u[I||"/"]={filePath:w,content:se,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 x())return!1;let b=o;try{if(b=await qe(o),b!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${b} 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:${b}/${e.reset}...`);let C=Gn({port:b,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(),q=P.transformSync(D);return new Response(q,{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 m){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,q=`<script>window.__routeParams = ${JSON.stringify(P)};</script>`;if(D.includes("</head>"))D=f(D,q);else D=q+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 se=Se.join(r,w.pathname);if(Xe.existsSync(se)&&Xe.statSync(se).isFile()){let L=Bun.file(se),I=Se.extname(se).toLowerCase(),k="text/plain";if(I===".ts"||I===".tsx"){let P=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),D=await L.text(),q=P.transformSync(D);return new Response(q,{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=Be(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]:"",q=`<!DOCTYPE html><html><head><title>${qt(D)}</title></head><body><main>${k[1]}</main></body></html>`;return new Response(q,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...V(),"Cache-Control":Et,Pragma:"no-cache",Expires:"0"}})}}return new Response(I,{headers:{"Content-Type":"text/html",...V(),"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:${b}/${e.reset}`),console.log(`
|
|
1004
1004
|
${e.yellow}Routes:${e.reset}`);let R=new Set(m.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 m){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 ",se=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${U}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${se}`)}),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}`),lt.clear(),Ce(),await x()});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:Gn}=globalThis.Bun;import me from"fs";import oe from"path";async function Jt(n){try{return An(await Bun.file(n).text())}catch{return}}function Ot(n){let t=Bun.file(n),o=oe.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 as(n=".",t={}){let o=t.port||3000,d=t.watch!==!1,r=t.hotReload!==!1&&d,p=null,u=t.hmrPort||o+1,m=oe.resolve(n),{loadStxConfig:x}=await import("./chunk-h13csdpm.js"),h=await x(m),{createServerApi:b,isServerApiSource:C}=await import("./chunk-abs4fwmf.js"),R=t.stxOptions?.serverApi??h.serverApi,O=await b(m,R),v=h.root&&h.root!=="."?oe.join(m,h.root):m,w=t.pagesDir||h.pagesDir||"pages",A=oe.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=re(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 se=h?._pluginPageDirs||[],I=[];for(let{dir:T,prefix:_}of se)if(me.existsSync(T)){let z=re(oe.dirname(T),{pagesDir:oe.basename(T)});for(let Z of z){let X=_==="/"?Z.pattern:`${_}${Z.pattern==="/"?"":Z.pattern}`;I.push({route:{...Z,pattern:X},prefix:_})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${_}${e.reset}`)}let L=new Map,k=null,P=null;if(t.stxOptions?.shell!==!1){if(P=await Da(m,t.stxOptions?.shell),P){if(k=await Bo(P,t.stxOptions||{}),k)console.log(`${e.blue}Using app shell: ${e.bright}${oe.relative(m,P)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}Lt(),await Bt(m);let D=jt();if(D.length>0)console.log(`${e.blue}Loaded ${e.bright}${D.length}${e.blue} middleware: ${e.dim}${D.join(", ")}${e.reset}`);let q={},Q=null;try{let{loadStxConfig:T}=await import("./chunk-h13csdpm.js"),_=await T(m);if(_?.apiRouter)Q=_?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(_?.apiRoutes){q=_.apiRoutes;let z=Object.keys(q).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(_?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:Z}=await import("./chunk-cjq455ve.js"),X=_.broadcasting;await z(X);let Te=X.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Te}/ws${e.reset}`);let be=oe.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(m,"output");me.mkdirSync(xe,{recursive:!0});let pe=new Map,ke=new Set,ie=async(T)=>{let _=Xs(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((X)=>X.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:X,loadStxConfig:Te,injectRouterScript:be}=await import("./chunk-h13csdpm.js"),{checkCache:N,cacheTemplate:Y,readFileCached:W,templateCache:ue}=await import("./chunk-vhk7a79j.js"),G=await Te(m),Ve=(le)=>{if(!le)return le;if(oe.isAbsolute(le))return le;return oe.resolve(m,le)},de={...X,...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(m,"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 Le=!0;for(let ve of le.dependencies){if(!me.existsSync(ve)){Le=!1;break}if((await me.promises.stat(ve)).mtime.getTime()>le.mtime){Le=!1;break}}if(Le){let ve=le.output;if(k)ve=ot(ve,{preserveHead:!0});let rt=F.get(T.filePath);return{route:T,content:ve,status:rt?.status??await Jt(T.filePath),headers:rt?.headers}}}}catch{}let Me=await N(T.filePath,de);if(Me){let _e=Me;if(k)_e=ot(_e,{preserveHead:!0});let Le=F.get(T.filePath);return{route:T,content:_e,status:Le?.status??await Jt(T.filePath),headers:Le?.headers}}}let ee=J?await W(T.filePath):await Bun.file(T.filePath).text(),ae=An(ee),{classifyAllScripts:fe}=await import("./chunk-h13csdpm.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:oe.dirname(T.filePath),__stx_options:de,params:_??{},__stx_runtime_head:{}};for(let le of Oe)try{await Z(le,te,T.filePath)}catch(Me){if(t.stxOptions?.debug)console.error("[stx] variable extraction error",T.filePath,Me?.message||Me)}let $e=new Set,he;if(t.profile){let le=performance.now();he=await z(Re,te,T.filePath,de,$e);let Me=performance.now()-le,_e=oe.relative(m,T.filePath)||T.filePath;console.log(`[stx:profile] ${_e} \u2192 ${Me.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-a02sy0m5.js");he=he.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Me,_e,Le)=>{if(!/function\s+__stx_setup_/.test(Le))return Me;return`<script${_e}>${le(Le,te)}</script>`})}if(k)he=ot(he,{preserveHead:!0});if(J&&M)await Y(T.filePath,he,$e,de);let{extractStreamBoundaries:ct}=await import("./chunk-j846tv4t.js"),Ye=ct(te),nt=te.__streamTemplates;if(nt&&typeof nt==="object"&&Object.keys(nt).length>0){let le=te.streamBoundaries||{},Me={...de,autoShell:!1},_e=Object.keys(nt).map((ve)=>({id:ve,render:async()=>{let rt=typeof le[ve]==="function"?await le[ve]():void 0;return z(nt[ve],{...te,$boundary:rt},T.filePath,Me,new Set)}})),Le=new Set(_e.map((ve)=>ve.id));Ye=[...(Ye||[]).filter((ve)=>!Le.has(ve.id)),..._e]}if(Ye&&Ye.length>0)ke.add(T.pattern);else Ye=void 0;let _t=Kt(te),It=Xt(te);if(M)F.set(T.filePath,{status:_t,headers:It});return{route:T,content:he,status:_t??ae,headers:It,boundaries:Ye}}catch(z){return console.error(`${e.red}Error building ${e.bright}${T.pattern}${e.reset}:`,z),null}},je=8,ze=async()=>{let T=new Set(pe.keys()),_=new Set(L.keys());pe.clear(),L.clear();let z=t.prebuild===!1?U.filter((X)=>T.has(X.pattern)):U,Z=t.prebuild===!1?I.filter(({route:X})=>_.has(X.pattern)):I;for(let X=0;X<z.length;X+=je){let Te=z.slice(X,X+je),be=await Promise.all(Te.map((N)=>E(N)));for(let N of be)if(N)pe.set(N.route.pattern,N)}for(let X=0;X<Z.length;X+=je){let Te=Z.slice(X,X+je),be=await Promise.all(Te.map(({route:N})=>E(N)));for(let N of be)if(N)L.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+I.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Sn(m);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=xt({wsPort:T,verbose:!1}),u=p.start(T)}let wt=(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 St=Gn({port:Ge,hostname:t.hostname,async fetch(T){let _=new URL(T.url),z=t.stxOptions?.offline??h.offline;if(_.pathname===si&&z?.enabled){if(!["GET","HEAD"].includes(T.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});let M=[...U,...I.map(({route:J})=>J)].filter((J)=>!J.isDynamic).map((J)=>J.pattern);return new Response(T.method==="HEAD"?null:oi(z,Es(),M),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let Z=h?.publicDir||"public",X=oe.join(m,Z,_.pathname),Te=oe.join(m,_.pathname),be=oe.join(xe,_.pathname);if([X,Te,be].some((M)=>C(M,m,R)))return new Response("Not Found",{status:404});let[N,Y,W]=await Promise.all([me.promises.stat(X).catch(()=>null),me.promises.stat(Te).catch(()=>null),me.promises.stat(be).catch(()=>null)]);if(N?.isFile()&&!C(X,m,R))return Ot(X);if(Y?.isFile()&&!C(Te,m,R))return Ot(Te);if(W?.isFile()&&!C(be,m,R))return Ot(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,{},oe.join(m,"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-h7xqba9k.js"),J=await M(T,{publicDir:oe.join(m,Z),cacheDir:l(m,"cache","img")});if(J)return J}if(Q)try{let M=await Q.handleRequest(T);if(M.status!==404)return M}catch{}if(q[_.pathname])try{return await q[_.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=Rr(_.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?Pt(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,m),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=Ft(_.pathname,G.params,fe,_.search),Re=zt(Oe,null,T,{isServer:!0}),te=await Ht(fe.middleware,Re);if(te.redirect){let $e=te.redirect.path,he=te.redirect.options.redirectCode||302,ct=new Headers(te.responseHeaders);return ct.set("Location",$e),new Response(null,{status:he,headers:ct})}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&&La(T)&&Tt(H,h?.router?.container||"main")){let Oe=We(H),Re=Ae(H),te=H.match(/<title[^>]*>([\s\S]*?)<\/title>/i),$e=te?cn(te[1].trim()):"";if(Object.keys(G.params).length>0)H=wt(H,G.params);H=await S(H,m);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)},[Oc]:Es(),...V(),"Cache-Control":Et}})}if(k)H=ps(k,H);if(Object.keys(G.params).length>0)H=wt(H,G.params);if(H=await S(H,m),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-j846tv4t.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",...V(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ae}})}}if(I.length>0){let M=I.map((ee)=>ee.route),J=Rr(_.pathname,M);if(J){let ee=L.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)L.set(J.route.pattern,ae)}}if(ee){let ae=ee.content;if(k)ae=ps(k,ae);if(Object.keys(J.params).length>0)ae=wt(ae,J.params);if(ae=await S(ae,m),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 se)if(ee!=="/"&&_.pathname.startsWith(ee)){let ae=L.get(ee)||L.get(ee+"/");if(!ae){let fe=I.find(({route:H})=>H.pattern===ee||H.pattern===`${ee}/`);if(fe){let H=await E(fe.route);if(H)ae=H,L.set(fe.route.pattern,H)}}if(ae){let fe=ae.content;if(k)fe=ps(k,fe);if(fe=await S(fe,m),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(Dt(_.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,m),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,m),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}
|
|
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}`),lt.clear(),Ce(),await x()});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 oe from"path";async function Jt(n){try{return An(await Bun.file(n).text())}catch{return}}function Ot(n){let t=Bun.file(n),o=oe.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 as(n=".",t={}){let o=t.port||3000,d=t.watch!==!1,r=t.hotReload!==!1&&d,p=null,u=t.hmrPort||o+1,m=oe.resolve(n),{loadStxConfig:x}=await import("./chunk-k2t0w8z1.js"),h=await x(m),{createServerApi:b,isServerApiSource:C}=await import("./chunk-6bw02d1t.js"),R=t.stxOptions?.serverApi??h.serverApi,O=await b(m,R),v=h.root&&h.root!=="."?oe.join(m,h.root):m,w=t.pagesDir||h.pagesDir||"pages",A=oe.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=re(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 se=h?._pluginPageDirs||[],L=[];for(let{dir:T,prefix:_}of se)if(me.existsSync(T)){let z=re(oe.dirname(T),{pagesDir:oe.basename(T)});for(let Z of z){let X=_==="/"?Z.pattern:`${_}${Z.pattern==="/"?"":Z.pattern}`;L.push({route:{...Z,pattern:X},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 Da(m,t.stxOptions?.shell),P){if(k=await Bo(P,t.stxOptions||{}),k)console.log(`${e.blue}Using app shell: ${e.bright}${oe.relative(m,P)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}Lt(),await Bt(m);let D=jt();if(D.length>0)console.log(`${e.blue}Loaded ${e.bright}${D.length}${e.blue} middleware: ${e.dim}${D.join(", ")}${e.reset}`);let q={},Q=null;try{let{loadStxConfig:T}=await import("./chunk-k2t0w8z1.js"),_=await T(m);if(_?.apiRouter)Q=_?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(_?.apiRoutes){q=_.apiRoutes;let z=Object.keys(q).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(_?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:Z}=await import("./chunk-38y11q8x.js"),X=_.broadcasting;await z(X);let Te=X.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Te}/ws${e.reset}`);let be=oe.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(m,"output");me.mkdirSync(xe,{recursive:!0});let pe=new Map,ke=new Set,ie=async(T)=>{let _=Xs(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((X)=>X.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:X,loadStxConfig:Te,injectRouterScript:be}=await import("./chunk-k2t0w8z1.js"),{checkCache:N,cacheTemplate:Y,readFileCached:W,templateCache:ue}=await import("./chunk-e0tvd7jj.js"),G=await Te(m),Ve=(le)=>{if(!le)return le;if(oe.isAbsolute(le))return le;return oe.resolve(m,le)},de={...X,...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(m,"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 ve of le.dependencies){if(!me.existsSync(ve)){Ie=!1;break}if((await me.promises.stat(ve)).mtime.getTime()>le.mtime){Ie=!1;break}}if(Ie){let ve=le.output;if(k)ve=ot(ve,{preserveHead:!0});let rt=F.get(T.filePath);return{route:T,content:ve,status:rt?.status??await Jt(T.filePath),headers:rt?.headers}}}}catch{}let Me=await N(T.filePath,de);if(Me){let _e=Me;if(k)_e=ot(_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=An(ee),{classifyAllScripts:fe}=await import("./chunk-k2t0w8z1.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:oe.dirname(T.filePath),__stx_options:de,params:_??{},__stx_runtime_head:{}};for(let le of Oe)try{await Z(le,te,T.filePath)}catch(Me){if(t.stxOptions?.debug)console.error("[stx] variable extraction error",T.filePath,Me?.message||Me)}let $e=new Set,he;if(t.profile){let le=performance.now();he=await z(Re,te,T.filePath,de,$e);let Me=performance.now()-le,_e=oe.relative(m,T.filePath)||T.filePath;console.log(`[stx:profile] ${_e} \u2192 ${Me.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-kcpxqsdj.js");he=he.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Me,_e,Ie)=>{if(!/function\s+__stx_setup_/.test(Ie))return Me;return`<script${_e}>${le(Ie,te)}</script>`})}if(k)he=ot(he,{preserveHead:!0});if(J&&M)await Y(T.filePath,he,$e,de);let{extractStreamBoundaries:ct}=await import("./chunk-6aqr0e6s.js"),Ye=ct(te),nt=te.__streamTemplates;if(nt&&typeof nt==="object"&&Object.keys(nt).length>0){let le=te.streamBoundaries||{},Me={...de,autoShell:!1},_e=Object.keys(nt).map((ve)=>({id:ve,render:async()=>{let rt=typeof le[ve]==="function"?await le[ve]():void 0;return z(nt[ve],{...te,$boundary:rt},T.filePath,Me,new Set)}})),Ie=new Set(_e.map((ve)=>ve.id));Ye=[...(Ye||[]).filter((ve)=>!Ie.has(ve.id)),..._e]}if(Ye&&Ye.length>0)ke.add(T.pattern);else Ye=void 0;let _t=Kt(te),It=Xt(te);if(M)F.set(T.filePath,{status:_t,headers:It});return{route:T,content:he,status:_t??ae,headers:It,boundaries:Ye}}catch(z){return console.error(`${e.red}Error building ${e.bright}${T.pattern}${e.reset}:`,z),null}},je=8,ze=async()=>{let T=new Set(pe.keys()),_=new Set(I.keys());pe.clear(),I.clear();let z=t.prebuild===!1?U.filter((X)=>T.has(X.pattern)):U,Z=t.prebuild===!1?L.filter(({route:X})=>_.has(X.pattern)):L;for(let X=0;X<z.length;X+=je){let Te=z.slice(X,X+je),be=await Promise.all(Te.map((N)=>E(N)));for(let N of be)if(N)pe.set(N.route.pattern,N)}for(let X=0;X<Z.length;X+=je){let Te=Z.slice(X,X+je),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 Sn(m);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=xt({wsPort:T,verbose:!1}),u=p.start(T)}let wt=(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 St=Jn({port:Ge,hostname:t.hostname,async fetch(T){let _=new URL(T.url),z=t.stxOptions?.offline??h.offline;if(_.pathname===si&&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:oi(z,Es(),M),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let Z=h?.publicDir||"public",X=oe.join(m,Z,_.pathname),Te=oe.join(m,_.pathname),be=oe.join(xe,_.pathname);if([X,Te,be].some((M)=>C(M,m,R)))return new Response("Not Found",{status:404});let[N,Y,W]=await Promise.all([me.promises.stat(X).catch(()=>null),me.promises.stat(Te).catch(()=>null),me.promises.stat(be).catch(()=>null)]);if(N?.isFile()&&!C(X,m,R))return Ot(X);if(Y?.isFile()&&!C(Te,m,R))return Ot(Te);if(W?.isFile()&&!C(be,m,R))return Ot(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,{},oe.join(m,"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-xa98a901.js"),J=await M(T,{publicDir:oe.join(m,Z),cacheDir:l(m,"cache","img")});if(J)return J}if(Q)try{let M=await Q.handleRequest(T);if(M.status!==404)return M}catch{}if(q[_.pathname])try{return await q[_.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=Rr(_.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?Pt(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,m),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=Ft(_.pathname,G.params,fe,_.search),Re=zt(Oe,null,T,{isServer:!0}),te=await Ht(fe.middleware,Re);if(te.redirect){let $e=te.redirect.path,he=te.redirect.options.redirectCode||302,ct=new Headers(te.responseHeaders);return ct.set("Location",$e),new Response(null,{status:he,headers:ct})}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&&La(T)&&Tt(H,h?.router?.container||"main")){let Oe=We(H),Re=Ae(H),te=H.match(/<title[^>]*>([\s\S]*?)<\/title>/i),$e=te?cn(te[1].trim()):"";if(Object.keys(G.params).length>0)H=wt(H,G.params);H=await S(H,m);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)},[Mc]:Es(),...V(),"Cache-Control":Et}})}if(k)H=ps(k,H);if(Object.keys(G.params).length>0)H=wt(H,G.params);if(H=await S(H,m),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-6aqr0e6s.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",...V(),"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=Rr(_.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=ps(k,ae);if(Object.keys(J.params).length>0)ae=wt(ae,J.params);if(ae=await S(ae,m),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 se)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=ps(k,fe);if(fe=await S(fe,m),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(Dt(_.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,m),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,m),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 kt=[...Gs(U,m)];for(let{route:T}of
|
|
1010
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(St.url.toString(),()=>{if(p)st();St.stop()}),t.native){let T,_=oe.join(A,"index.stx");if(me.existsSync(_)){let Z=await Bun.file(_).text();T=mt(Z)}let z=h?.app?.window??{};await Qe(Ge,{title:h?.app?.head?.title||oe.basename(m)||"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([m,...h._layerGraph?.layers.map((Y)=>Y.root)??[],...h._layerGraph?.configDependencies.map((Y)=>oe.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((G)=>ue===G||ue.startsWith(`${G}${oe.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((G)=>console.error("[stx] Layer rebuild failed:",G))}))},X=Promise.resolve(),Te=(N,Y,W)=>(X=X.catch(()=>{}).then(()=>be(N,Y,W)),X),be=async(N,Y,W)=>{if(!W||yt(W))return;if(ht(W)){if(h._layerGraph){let ue=await x(m);Object.assign(h,ue),U.splice(0,U.length,...re(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}`),lt.clear(),Ce();try{let{invalidateFileCache:ue,templateCache:G}=await import("./chunk-
|
|
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 m=d.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(m){let h=m[1].split(",").map((b)=>b.trim()).filter(Boolean);for(let b of h){let[C]=b.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
|
|
1012
|
-
`).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function
|
|
1009
|
+
${e.yellow}Routes:${e.reset}`);let kt=[...Gs(U,m)];for(let{route:T}of L)kt.push(`${T.pattern}`);if(kt.forEach((T,_)=>{let Z=_===kt.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(St.url.toString(),()=>{if(p)st();St.stop()}),t.native){let T,_=oe.join(A,"index.stx");if(me.existsSync(_)){let Z=await Bun.file(_).text();T=mt(Z)}let z=h?.app?.window??{};await Qe(Ge,{title:h?.app?.head?.title||oe.basename(m)||"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([m,...h._layerGraph?.layers.map((Y)=>Y.root)??[],...h._layerGraph?.configDependencies.map((Y)=>oe.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((G)=>ue===G||ue.startsWith(`${G}${oe.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((G)=>console.error("[stx] Layer rebuild failed:",G))}))},X=Promise.resolve(),Te=(N,Y,W)=>(X=X.catch(()=>{}).then(()=>be(N,Y,W)),X),be=async(N,Y,W)=>{if(!W||yt(W))return;if(ht(W)){if(h._layerGraph){let ue=await x(m);Object.assign(h,ue),U.splice(0,U.length,...re(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}`),lt.clear(),Ce();try{let{invalidateFileCache:ue,templateCache:G}=await import("./chunk-e0tvd7jj.js");ue(oe.resolve(N,W)),G.delete(oe.resolve(N,W))}catch{}if(P&&W){if(oe.resolve(N,W)===P||oe.basename(P)===W){let G=await Bo(P,t.stxOptions||{});if(G)k=G}}if(await ze(),await xr(m),r&&p)p.reload(W)}else{console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),lt.clear(),Ce();try{let{invalidateFileCache:ue,templateCache:G}=await import("./chunk-e0tvd7jj.js");ue(oe.resolve(N,W)),G.delete(oe.resolve(N,W))}catch{}if(await ze(),r&&p)p.reload(W)}}else if(gt(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();St.stop(),process.exit(0)})}return!0}import At from"fs";import it 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 m=u[1],x=u[2]||u[3]||u[4];if(!x)continue;let h={name:x},b=m.match(/@type\s+\{([^}]+)\}/i);if(b)h.type=b[1].trim();if(m.match(/@required/i))h.required=!0;let R=m.match(/@default\s+(.+?)(?:\s+|$)/i);if(R)h.default=R[1].trim();let O=m.split(`
|
|
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 m=d.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(m){let h=m[1].split(",").map((b)=>b.trim()).filter(Boolean);for(let b of h){let[C]=b.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
|
+
`).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Zn(n,t=!1,o){let d=it.basename(n,".stx"),r=await Yn(n),p=await Qn(n),u="";if(t&&o)u=`<${o}></${o}>`;else{let m=r.map((x)=>{if(x.type==="boolean")return`:${x.name}="true"`;return`${x.name}="value"`}).join(`
|
|
1013
1013
|
`);u=`<${d}
|
|
1014
1014
|
${m}
|
|
1015
|
-
/>`}return{name:d,path:n,description:p,props:r,example:u,isWebComponent:t,tag:o}}async function Yt(n){try{if(!await s(n))return console.warn(`Components directory does not exist: ${n}`),[];let t=await At.promises.readdir(n,{withFileTypes:!0}),o=[];for(let d of t){let r=it.join(n,d.name);if(d.isDirectory()){let p=await Yt(r);o.push(...p)}else if(d.isFile()&&d.name.endsWith(".stx"))o.push(r)}return o}catch(t){return console.error(`Error finding component files in ${n}:`,t),[]}}async function
|
|
1016
|
-
`).map((w)=>w.trim().replace(/^\*\s*/,"")).join(" ").trim():"",h=/@component\(\s*['"]([^'"]+)['"]/g,b=/<([A-Z][a-zA-Z0-9]*|[a-z]+-[a-z0-9-]+)(?:\s[^>]*)?\/?>|\{\{\s*slot\s*\}\}/g,C=new Set,R;while((R=h.exec(p))!==null)C.add(R[1]);while((R=b.exec(p))!==null)if(R[1]&&R[1]!=="slot")C.add(R[1]);let O=/@([a-z]+)(?:\s*\(|\s+|$)/g,v=new Set;while((R=O.exec(p))!==null)v.add(R[1]);o.push({name:u,path:r,description:x,components:[...C],directives:[...v]})}return o}catch(t){return console.error("Error generating template docs:",t),[]}}async function
|
|
1015
|
+
/>`}return{name:d,path:n,description:p,props:r,example:u,isWebComponent:t,tag:o}}async function Yt(n){try{if(!await s(n))return console.warn(`Components directory does not exist: ${n}`),[];let t=await At.promises.readdir(n,{withFileTypes:!0}),o=[];for(let d of t){let r=it.join(n,d.name);if(d.isDirectory()){let p=await Yt(r);o.push(...p)}else if(d.isFile()&&d.name.endsWith(".stx"))o.push(r)}return o}catch(t){return console.error(`Error finding component files in ${n}:`,t),[]}}async function er(n,t){try{if(!await s(n))return[];let o=await Yt(n),d=[],r=new Map;if(t?.components?.length)for(let p of t.components)r.set(p.file,p);for(let p of o){let u=r.get(p),m=!!u,x=u?.tag,h=await Zn(p,m,x);d.push(h)}return d}catch(o){return console.error("Error generating component docs:",o),[]}}async function tr(n){try{if(!await s(n))return[];let t=await At.promises.readdir(n,{withFileTypes:!0}),o=[];for(let d of t){if(!d.isFile()||!d.name.endsWith(".stx"))continue;let r=it.join(n,d.name),p=await Bun.file(r).text(),u=it.basename(r,".stx"),m=p.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||p.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//),x=m?m[1].split(`
|
|
1016
|
+
`).map((w)=>w.trim().replace(/^\*\s*/,"")).join(" ").trim():"",h=/@component\(\s*['"]([^'"]+)['"]/g,b=/<([A-Z][a-zA-Z0-9]*|[a-z]+-[a-z0-9-]+)(?:\s[^>]*)?\/?>|\{\{\s*slot\s*\}\}/g,C=new Set,R;while((R=h.exec(p))!==null)C.add(R[1]);while((R=b.exec(p))!==null)if(R[1]&&R[1]!=="slot")C.add(R[1]);let O=/@([a-z]+)(?:\s*\(|\s+|$)/g,v=new Set;while((R=O.exec(p))!==null)v.add(R[1]);o.push({name:u,path:r,description:x,components:[...C],directives:[...v]})}return o}catch(t){return console.error("Error generating template docs:",t),[]}}async function nr(n=[]){try{let t=[{name:"if",description:"Conditionally render content based on a condition",hasEndTag:!0,example:`@if(user.isLoggedIn)
|
|
1017
1017
|
<p>Welcome, {{ user.name }}!</p>
|
|
1018
1018
|
@endif`},{name:"else",description:"Provides an alternative if a condition is not met",hasEndTag:!1,example:`@if(user.isLoggedIn)
|
|
1019
1019
|
<p>Welcome back!</p>
|
|
@@ -1033,7 +1033,7 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(St.
|
|
|
1033
1033
|
<p>Page {{ page }}</p>
|
|
1034
1034
|
@endwhile`},{name:"component",description:"Include a component in the template",hasEndTag:!1,example:'@component("alert", { type: "warning", title: "Warning", message: "This is a warning" })'},{name:"include",description:"Include a partial template",hasEndTag:!1,example:'@include("partials/header")'},{name:"raw",description:"Display content without processing expressions",hasEndTag:!0,example:`@raw
|
|
1035
1035
|
{{ This will be displayed as-is }}
|
|
1036
|
-
@endraw`},{name:"translate",description:"Translate a string using the i18n system",hasEndTag:!1,example:'@translate("welcome.message", { name: user.name })'},{name:"t",description:"Short alias for translate directive",hasEndTag:!1,example:'@t("welcome.message", { name: user.name })'}];for(let o of n)t.push({name:o.name,description:o.description||"",hasEndTag:o.hasEndTag||!1,example:""});return t}catch(t){return console.error("Error generating directive docs:",t),[]}}function
|
|
1036
|
+
@endraw`},{name:"translate",description:"Translate a string using the i18n system",hasEndTag:!1,example:'@translate("welcome.message", { name: user.name })'},{name:"t",description:"Short alias for translate directive",hasEndTag:!1,example:'@t("welcome.message", { name: user.name })'}];for(let o of n)t.push({name:o.name,description:o.description||"",hasEndTag:o.hasEndTag||!1,example:""});return t}catch(t){return console.error("Error generating directive docs:",t),[]}}function rr(n=[],t=[],o=[],d){let r=`# stx Documentation
|
|
1037
1037
|
|
|
1038
1038
|
`;if(d)r+=`${d}
|
|
1039
1039
|
|
|
@@ -1075,7 +1075,7 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(St.
|
|
|
1075
1075
|
|
|
1076
1076
|
`,r+=`#### Example
|
|
1077
1077
|
|
|
1078
|
-
`,r+="```html\n",r+=p.example,r+="\n```\n\n"}return r}function
|
|
1078
|
+
`,r+="```html\n",r+=p.example,r+="\n```\n\n"}return r}function or(n=[],t=[],o=[],d){let r=`<!DOCTYPE html>
|
|
1079
1079
|
<html lang="en">
|
|
1080
1080
|
<head>
|
|
1081
1081
|
<meta charset="UTF-8">
|
|
@@ -1146,8 +1146,8 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(St.
|
|
|
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
|
|
1150
|
-
`;let d=n;if(o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=
|
|
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 At.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 m=[];if(p.components!==!1&&t)console.log("Generating component documentation..."),m=await er(t,d),console.log(`Found ${m.length} components`);let x=[];if(p.templates!==!1&&o)console.log("Generating template documentation..."),x=await tr(o),console.log(`Found ${x.length} templates`);let h=[];if(p.directives!==!1)console.log("Generating directive documentation..."),h=await nr(r),console.log(`Found ${h.length} directives`);let b=p.format||"markdown",C=p.extraContent,R="",O="";switch(b){case"markdown":R=rr(m,x,h,C),O="md";break;case"html":R=or(m,x,h,C),O="html";break;case"json":R=sr(m,x,h,C),O="json";break;default:throw Error(`Unsupported documentation format: ${b}`)}let v=it.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 Ea(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 Ao(n,t={}){let o={...Zt,...t};if(n.trim()==="")return`
|
|
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+=`
|
|
@@ -1162,7 +1162,7 @@ ${p}\`\`\``}),o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=d.replac
|
|
|
1162
1162
|
`).replace(/\r/g,`
|
|
1163
1163
|
`),!d.endsWith(`
|
|
1164
1164
|
`))d+=`
|
|
1165
|
-
`;return d}function
|
|
1165
|
+
`;return d}function cr(n){let t=n,o=[],d="__PROTECTED_BLOCK_";return t=t.replace(/(<(?:pre|code|textarea)[^>]*>)([\s\S]*?)(<\/(?:pre|code|textarea)>)/gi,(r)=>{let p=o.length;return o.push(r),`${d}${p}__`}),t=t.replace(/(@(?:if|foreach|for|while|unless|section|component|slot|push|prepend|error|auth|guest|can)(?:\((?:[^()'"]|'[^']*'|"[^"]*"|\((?:[^()'"]|'[^']*'|"[^"]*")*\))*\))?)/g,`
|
|
1166
1166
|
$1
|
|
1167
1167
|
`),t=t.replace(/(@end\w+)/g,`
|
|
1168
1168
|
$1
|
|
@@ -1176,10 +1176,10 @@ ${u}`}),t=t.replace(/(<\/[^>]+>)(?=<|$)/g,(r,p,u,m)=>{let x=m.substring(Math.max
|
|
|
1176
1176
|
`}),t=t.replace(new RegExp(`${d}(\\d+)__`,"g"),(r,p)=>o[Number.parseInt(p,10)]),t=t.replace(/\n{2,}/g,`
|
|
1177
1177
|
`),t=t.split(`
|
|
1178
1178
|
`).map((r)=>r.trim()).join(`
|
|
1179
|
-
`),t=t.replace(/^\n+/,"").replace(/\n+$/,""),t}function
|
|
1180
|
-
`),r=[],p=0,u=!1,m=t.useTabs?"\t":" ".repeat(t.indentSize);for(let x=0;x<d.length;x++){let h=d[x],b=h.trim();if(b===""){r.push("");continue}let C=b.match(/<script\b/i),R=b.match(/<\/script>/i);if(u&&!R){r.push(h);continue}let O=b===">";if(Qt(b)&&!b.startsWith("<")&&!b.startsWith("@")){r.push(m.repeat(p)+b);continue}let v=b.startsWith("@end"),w=b.startsWith("@else")||b.startsWith("@elseif"),A=b.startsWith("@")&&
|
|
1181
|
-
`)}function
|
|
1182
|
-
`)||r.includes("@"))return o;let p=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,u=[],m;while((m=p.exec(r))!==null)u.push({name:m[1],value:m[2]});u.sort((h,b)=>{if(h.name==="id")return-1;if(b.name==="id")return 1;if(h.name==="class")return-1;if(b.name==="class")return 1;return h.name.localeCompare(b.name)});let x=u.map((h)=>h.value?`${h.name}=${h.value}`:h.name).join(" ");return`<${d}${x?` ${x}`:""}>`})}import en from"fs";import Mt from"path";async function $a(n="index.stx",t={}){try{let o=t.force||!1,d=Mt.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=Mt.dirname(d);if(!en.existsSync(r))en.mkdirSync(r,{recursive:!0});let p;if(t.template){let u=Mt.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 nn();case"component":return
|
|
1179
|
+
`),t=t.replace(/^\n+/,"").replace(/\n+$/,""),t}function lr(n,t){let d=cr(n).split(`
|
|
1180
|
+
`),r=[],p=0,u=!1,m=t.useTabs?"\t":" ".repeat(t.indentSize);for(let x=0;x<d.length;x++){let h=d[x],b=h.trim();if(b===""){r.push("");continue}let C=b.match(/<script\b/i),R=b.match(/<\/script>/i);if(u&&!R){r.push(h);continue}let O=b===">";if(Qt(b)&&!b.startsWith("<")&&!b.startsWith("@")){r.push(m.repeat(p)+b);continue}let v=b.startsWith("@end"),w=b.startsWith("@else")||b.startsWith("@elseif"),A=b.startsWith("@")&&ur(b),U=b.startsWith("<!DOCTYPE")||b.startsWith("<!doctype"),se=b.startsWith("<!--"),L=b.startsWith("</"),I=b.startsWith("<")&&!L&&!se&&!U,k=b.includes("/>")||pr(b),P=Qt(b);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(m.repeat(D)+b);if(I&&!k&&!P&&!O||A)p++;if(C)u=!0;if(R)u=!1}return r.join(`
|
|
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=[],m;while((m=p.exec(r))!==null)u.push({name:m[1],value:m[2]});u.sort((h,b)=>{if(h.name==="id")return-1;if(b.name==="id")return 1;if(h.name==="class")return-1;if(b.name==="class")return 1;return h.name.localeCompare(b.name)});let x=u.map((h)=>h.value?`${h.name}=${h.value}`:h.name).join(" ");return`<${d}${x?` ${x}`:""}>`})}import en from"fs";import Mt from"path";async function $a(n="index.stx",t={}){try{let o=t.force||!1,d=Mt.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=Mt.dirname(d);if(!en.existsSync(r))en.mkdirSync(r,{recursive:!0});let p;if(t.template){let u=Mt.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 nn();case"component":return mr();case"layout":return gr();case"blog":return hr();case"api":return yr();case"app":return br();default:return nn()}}function nn(){return`<script>
|
|
1183
1183
|
const title = "My stx Page"
|
|
1184
1184
|
const description = "A page built with stx"
|
|
1185
1185
|
const features = [
|
|
@@ -1204,7 +1204,7 @@ const features = [
|
|
|
1204
1204
|
</div>
|
|
1205
1205
|
@endforeach
|
|
1206
1206
|
</main>
|
|
1207
|
-
@endsection`}function
|
|
1207
|
+
@endsection`}function mr(){return`{{-- Component: Card --}}
|
|
1208
1208
|
{{-- Props: title, variant, collapsible --}}
|
|
1209
1209
|
{{-- Usage: @component('card', { title: "Hello", variant: "primary", collapsible: true }) Content @endcomponent --}}
|
|
1210
1210
|
<script>
|
|
@@ -1249,7 +1249,7 @@ const features = [
|
|
|
1249
1249
|
.card.collapsed .card__toggle { transform: rotate(-90deg); }
|
|
1250
1250
|
.card__body { padding: 1rem; }
|
|
1251
1251
|
.card.collapsed .card__body { display: none; }
|
|
1252
|
-
</style>`}function
|
|
1252
|
+
</style>`}function gr(){return`<!DOCTYPE html>
|
|
1253
1253
|
<html lang="en">
|
|
1254
1254
|
<head>
|
|
1255
1255
|
<meta charset="UTF-8">
|
|
@@ -1300,7 +1300,7 @@ const features = [
|
|
|
1300
1300
|
|
|
1301
1301
|
@yield('scripts')
|
|
1302
1302
|
</body>
|
|
1303
|
-
</html>`}function
|
|
1303
|
+
</html>`}function hr(){return`<script>
|
|
1304
1304
|
// Article metadata
|
|
1305
1305
|
const title = "My Blog Post"
|
|
1306
1306
|
const author = "Your Name"
|
|
@@ -1345,7 +1345,7 @@ const features = [
|
|
|
1345
1345
|
<p>Wrap up your thoughts here.</p>
|
|
1346
1346
|
</div>
|
|
1347
1347
|
</article>
|
|
1348
|
-
@endsection`}function
|
|
1348
|
+
@endsection`}function yr(){return`<script>
|
|
1349
1349
|
// API endpoint configuration
|
|
1350
1350
|
const endpoint = "/api/data"
|
|
1351
1351
|
const method = "GET"
|
|
@@ -1380,7 +1380,7 @@ const features = [
|
|
|
1380
1380
|
}
|
|
1381
1381
|
@else
|
|
1382
1382
|
{{ JSON.stringify(data, null, 2) }}
|
|
1383
|
-
@endif`}function
|
|
1383
|
+
@endif`}function br(){return`<!DOCTYPE html>
|
|
1384
1384
|
<html lang="en">
|
|
1385
1385
|
<head>
|
|
1386
1386
|
<meta charset="UTF-8">
|
|
@@ -1605,5 +1605,5 @@ const features = [
|
|
|
1605
1605
|
})();
|
|
1606
1606
|
</script>
|
|
1607
1607
|
</body>
|
|
1608
|
-
</html>`}var Ra="f9c3713";function
|
|
1609
|
-
`)}export{_a,Ca,Ea,Ao,Ta,$a,Ra,
|
|
1608
|
+
</html>`}var Ra="f9c3713";function au(n){return n}function cu(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 Ee from"fs";import ye from"path";function un(n){try{return Ee.statSync(n).mtimeMs}catch{return null}}function vt(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(Ee.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=Ee.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(m,x){if(x>t)return;let h;try{h=Ee.realpathSync(m)}catch{return}if(r.has(h))return;r.add(h);for(let C of mn){let R=ye.join(m,C),O=_s(R);if(O!==null)d.push({name:C,version:O,dir:ye.relative(o,R)||R,nested:x>0})}let b;try{b=Ee.readdirSync(m,{withFileTypes:!0})}catch{return}for(let C of b){if(!C.isDirectory()&&!C.isSymbolicLink())continue;if(C.name===".bin"||C.name===".cache")continue;let R=ye.join(m,C.name);if(C.name.startsWith("@")){let v;try{v=Ee.readdirSync(R,{withFileTypes:!0})}catch{continue}for(let w of v){let A=ye.join(R,w.name,"node_modules");if(Ee.existsSync(A))p(A,x+1)}continue}let O=ye.join(R,"node_modules");if(Ee.existsSync(O))p(O,x+1)}}let u=ye.join(o,"node_modules");if(Ee.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 Po(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 x of Ls(Is(t)))r.push(x);let m=fn(t,"stx");if(!m)r.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let x=ye.join(m,"src/signals.ts"),h=[ye.join(m,"dist/index.js"),ye.join(m,"dist/signals.js")].find((v)=>Ee.existsSync(v))||null,b=un(x),C=h?un(h):null;if(b==null)r.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${m} 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 ${m} && bun build.ts`});else if(C<b){let v=Math.round((b-C)/1000);r.push({name:"pantry dist freshness",status:"error",detail:`dist (${vt(C,d)}) is OLDER than src/signals.ts (${vt(b,d)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${m} && bun build.ts`})}else r.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${vt(b,d)}, dist ${vt(C,d)})`});let R=ye.join(t,"node_modules/@stacksjs/stx"),O=null;try{O=Ee.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=Ee.realpathSync(R)}catch{}let w=(()=>{try{return Ee.realpathSync(m)}catch{return m}})();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(x){r.push({name:"signals runtime",status:"error",detail:`failed to generate: ${x.message}`})}return{checks:r,ok:!r.some((x)=>x.status==="error")}}function Io(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,Ca,Ea,Ao,Ta,$a,Ra,au,cu,Po,Io,os,is,as};
|