@stacksjs/stx 0.2.633 → 0.2.635
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-0d7dqt4d.js +2 -0
- package/dist/chunk-0grt24vd.js +2 -0
- package/dist/{chunk-7q55jxf5.js → chunk-0tm9ep8b.js} +2 -2
- package/dist/{chunk-7gq7w95h.js → chunk-14yjt309.js} +3 -3
- package/dist/{chunk-ygpa12ez.js → chunk-1d25z8q2.js} +3 -3
- package/dist/{chunk-6bhaa9g7.js → chunk-1wb98s7b.js} +13 -13
- package/dist/{chunk-nh7bcc4h.js → chunk-2efrxnnt.js} +2 -2
- package/dist/chunk-2vzfn6vy.js +2 -0
- package/dist/chunk-3bsz101e.js +2 -0
- package/dist/{chunk-w9e17a74.js → chunk-3e2v2fdh.js} +4 -4
- package/dist/{chunk-jq7ymh7q.js → chunk-3f4xy76k.js} +6 -6
- package/dist/chunk-3jwjesb5.js +2 -0
- package/dist/{chunk-968jp303.js → chunk-3td99hnc.js} +3 -3
- package/dist/chunk-4b4es5wg.js +2 -0
- package/dist/{chunk-phbnrw2h.js → chunk-4n24jbfs.js} +2 -2
- package/dist/{chunk-72p9brmx.js → chunk-4vkpgz28.js} +9 -9
- package/dist/chunk-4xeafdr6.js +2 -0
- package/dist/chunk-4xkqdfqd.js +2 -0
- package/dist/chunk-5k989nr4.js +2 -0
- package/dist/chunk-5v95x083.js +3 -0
- package/dist/chunk-5yf9yzkp.js +2 -0
- package/dist/{chunk-923vrf9c.js → chunk-6gwrmn3w.js} +7 -7
- package/dist/{chunk-p77g4mhy.js → chunk-6w1ngwsd.js} +2 -2
- package/dist/chunk-7m5xrqnj.js +2852 -0
- package/dist/chunk-7mtdjjbt.js +2 -0
- package/dist/{chunk-94yycjz8.js → chunk-7vdcsr14.js} +2 -2
- package/dist/{chunk-k5atee35.js → chunk-839m1t8t.js} +1 -1
- package/dist/chunk-88dxeynx.js +2 -0
- package/dist/chunk-8er7jc3c.js +2 -0
- package/dist/chunk-8phbb8wj.js +2 -0
- package/dist/{chunk-p4hmv654.js → chunk-8y3mff5c.js} +2 -2
- package/dist/{chunk-gqdh68vx.js → chunk-954tcahb.js} +2 -2
- package/dist/{chunk-sg5zgq5v.js → chunk-97zrn4wb.js} +5 -5
- package/dist/{chunk-q6evk3a4.js → chunk-9gx5p7zh.js} +2 -2
- package/dist/{chunk-g2rxbaah.js → chunk-a6hv03yw.js} +3 -3
- package/dist/chunk-a7s1j320.js +127 -0
- package/dist/chunk-a83r1xx9.js +2 -0
- package/dist/chunk-abpeac2d.js +2 -0
- package/dist/chunk-adzsqsjt.js +2 -0
- package/dist/{chunk-4fv3jq16.js → chunk-ahyq08mp.js} +2 -2
- package/dist/chunk-b1ndskw9.js +2 -0
- package/dist/chunk-b7fp3zta.js +2 -0
- package/dist/{chunk-pbphq5pj.js → chunk-b7hv69ty.js} +2 -2
- package/dist/{chunk-avt9cske.js → chunk-baw176ay.js} +6 -6
- package/dist/chunk-bgfkbesj.js +2 -0
- package/dist/{chunk-cy1j2zpr.js → chunk-bk9bx2ns.js} +2 -2
- package/dist/{chunk-gh34r6qb.js → chunk-bsts9pr5.js} +2 -2
- package/dist/{chunk-jzmz66a3.js → chunk-bysyrwfa.js} +3 -3
- package/dist/{chunk-y89m80pf.js → chunk-c4ysk7x2.js} +4 -4
- package/dist/{chunk-90pe63me.js → chunk-camd8j1q.js} +3 -3
- package/dist/{chunk-0qt1887j.js → chunk-cdab66xt.js} +2 -2
- package/dist/{chunk-gv15dd41.js → chunk-cjr8cpb7.js} +3 -3
- package/dist/{chunk-y8h823cb.js → chunk-cw9pc5yx.js} +41 -41
- package/dist/chunk-cy83yfy9.js +2 -0
- package/dist/chunk-dbqb1a51.js +2 -0
- package/dist/{chunk-pk757m0k.js → chunk-e0nq8g9j.js} +1 -1
- package/dist/chunk-e8t64hxk.js +2 -0
- package/dist/chunk-e943xk88.js +2 -0
- package/dist/{chunk-w8bf4mbw.js → chunk-emcbmr0r.js} +3 -3
- package/dist/{chunk-kpxty3pe.js → chunk-f30t1g74.js} +2 -2
- package/dist/{chunk-tx4xxpgg.js → chunk-f3agc1a3.js} +3 -3
- package/dist/{chunk-27784ceh.js → chunk-fm80xpxn.js} +4 -4
- package/dist/{chunk-xrrkf04f.js → chunk-fwawm5r3.js} +2 -2
- package/dist/chunk-g039c67x.js +2 -0
- package/dist/{chunk-gxpgwpq7.js → chunk-g9dz0mx9.js} +2 -2
- package/dist/{chunk-bd5na0h0.js → chunk-g9sdjgfw.js} +5 -5
- package/dist/{chunk-k2nrx78c.js → chunk-gcj5jfbv.js} +2 -2
- package/dist/chunk-ghfxfcr9.js +2 -0
- package/dist/chunk-gvyq9xt6.js +2 -0
- package/dist/chunk-h30y9k44.js +2 -0
- package/dist/{chunk-236twqn4.js → chunk-hbzk179w.js} +3 -3
- package/dist/chunk-hwp3m8a8.js +2 -0
- package/dist/{chunk-2bxsc7gf.js → chunk-j79f6syh.js} +4 -4
- package/dist/chunk-jarptkbv.js +2 -0
- package/dist/{chunk-ftkrsvqp.js → chunk-jtr30kkz.js} +1 -1
- package/dist/{chunk-fdy0hka5.js → chunk-kjtvdqb9.js} +13 -13
- package/dist/chunk-kk6tq07c.js +3 -0
- package/dist/chunk-km4xp898.js +2 -0
- package/dist/{chunk-j1rnhv0w.js → chunk-kr14jt4m.js} +3 -3
- package/dist/{chunk-az1y9jks.js → chunk-kwwrrasa.js} +2 -2
- package/dist/chunk-kxbw0e2f.js +3 -0
- package/dist/{chunk-a887js9p.js → chunk-m56ee2tw.js} +5 -5
- package/dist/chunk-meze7k8v.js +2 -0
- package/dist/chunk-mfwrxz9z.js +2 -0
- package/dist/chunk-mmpm1awz.js +2 -0
- package/dist/{chunk-0whv8hnp.js → chunk-mn97jhaq.js} +2 -2
- package/dist/{chunk-3yh585yv.js → chunk-mpb0ezee.js} +3 -3
- package/dist/{chunk-g35zftfn.js → chunk-mvt5n2q4.js} +1 -1
- package/dist/chunk-n7vetrt4.js +2 -0
- package/dist/chunk-nd716zha.js +2 -0
- package/dist/{chunk-0hs8jgw5.js → chunk-npn3h566.js} +2 -2
- package/dist/{chunk-5x59qjzs.js → chunk-pak6ngv0.js} +6 -6
- package/dist/{chunk-v5500ews.js → chunk-pp6ycfay.js} +2 -2
- package/dist/{chunk-vhktd16g.js → chunk-psranzfr.js} +2 -2
- package/dist/chunk-ptjz4f2e.js +2 -0
- package/dist/{chunk-8qrhz7n7.js → chunk-ptv5f34x.js} +6 -6
- package/dist/{chunk-86zj56pf.js → chunk-q0kbn64j.js} +5 -5
- package/dist/chunk-q4hmgj72.js +2 -0
- package/dist/chunk-q841b6x4.js +2 -0
- package/dist/{chunk-v4tmwamd.js → chunk-qa58qdz8.js} +2 -2
- package/dist/{chunk-8hjrr8j3.js → chunk-qczse5w4.js} +33 -33
- package/dist/{chunk-tn7hgtyn.js → chunk-qjfgdcck.js} +5 -5
- package/dist/chunk-qnh5x7vv.js +2 -0
- package/dist/chunk-qxjfvkjt.js +2 -0
- package/dist/chunk-rhhwz7e9.js +2 -0
- package/dist/chunk-rpbe5h6v.js +2 -0
- package/dist/chunk-rrdn4qnn.js +2 -0
- package/dist/{chunk-xm911f1g.js → chunk-ry1w4ghk.js} +1 -1
- package/dist/chunk-s7c9kb53.js +2 -0
- package/dist/chunk-sfj84n72.js +2 -0
- package/dist/chunk-sgr2hhsc.js +2 -0
- package/dist/{chunk-jbmjcs83.js → chunk-shcn4wve.js} +2 -2
- package/dist/{chunk-zs7t42b5.js → chunk-sn0a8cjd.js} +5 -5
- package/dist/chunk-taztcvv3.js +2 -0
- package/dist/chunk-vczt5k2j.js +2 -0
- package/dist/chunk-vj5fghnv.js +2 -0
- package/dist/{chunk-6dzqjbsz.js → chunk-vyjdzpb8.js} +2 -2
- package/dist/chunk-wj4rf7sb.js +2 -0
- package/dist/chunk-wn1s8af8.js +2 -0
- package/dist/{chunk-t7e9y46s.js → chunk-x7g0946r.js} +1 -1
- package/dist/{chunk-rq1c46zb.js → chunk-xdwpbqzz.js} +34 -9
- package/dist/chunk-y3jyk5bj.js +2 -0
- package/dist/chunk-y51ndrdb.js +2 -0
- package/dist/{chunk-xrkechs8.js → chunk-y5b25eks.js} +5 -5
- package/dist/{chunk-tc7gm68a.js → chunk-ycz5th6b.js} +2 -2
- package/dist/{chunk-3kkf43fv.js → chunk-ym0e374a.js} +2 -2
- package/dist/{chunk-pxpmx8vc.js → chunk-ymntav9f.js} +1 -1
- package/dist/{chunk-8kc6byaz.js → chunk-yp8tk3v3.js} +5 -5
- package/dist/{chunk-bng1ayzm.js → chunk-ytv0k9gy.js} +9 -9
- package/dist/chunk-ytxzy6eg.js +2 -0
- package/dist/chunk-ywf319rp.js +2 -0
- package/dist/chunk-yww6c9we.js +2 -0
- package/dist/chunk-yy43hxb7.js +2 -0
- package/dist/chunk-z42jb949.js +2 -0
- package/dist/{chunk-y04hzz4w.js → chunk-zfrpss8y.js} +4 -4
- package/dist/{chunk-8b2452m1.js → chunk-zpzk4wd2.js} +11 -11
- package/dist/chunk-zw20a7q4.js +2 -0
- package/dist/cli.js +76 -76
- package/dist/client/signals-public-api-runtime.js +1 -0
- package/dist/client/signals-timer-runtime.js +24 -0
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/lazy-module.js +2 -1
- package/dist/menubar.d.ts +2 -0
- package/dist/menubar.js +15 -2
- package/dist/native/compiler/headwind-to-style.d.ts +6 -3
- package/dist/native/compiler/headwind-to-style.js +25 -3
- package/dist/native/compiler/html-to-ir.js +4 -4
- package/dist/native/prop-names.d.ts +1 -1
- package/dist/native/prop-names.js +3 -1
- package/dist/native/runtime/native-host.js +66 -7
- package/dist/pwa.js +3 -3
- package/dist/runtime-globals.js +1 -0
- package/dist/ssg.js +9 -9
- package/dist/stx-module.d.ts +1 -0
- package/package.json +5 -5
- package/stx-module.d.ts +1 -0
- package/stx.d.ts +7 -0
- package/dist/chunk-0mgtrbaa.js +0 -2
- package/dist/chunk-0xc6rncm.js +0 -2852
- package/dist/chunk-1tpr8d8n.js +0 -2
- package/dist/chunk-20kjbf3h.js +0 -2
- package/dist/chunk-3gcg3gvy.js +0 -2
- package/dist/chunk-3wsrhj0k.js +0 -2
- package/dist/chunk-575cqc6z.js +0 -2
- package/dist/chunk-5x836mv3.js +0 -2
- package/dist/chunk-5yceay9n.js +0 -2
- package/dist/chunk-6pg2kxsq.js +0 -2
- package/dist/chunk-7nthebqr.js +0 -2
- package/dist/chunk-7s5304ae.js +0 -2
- package/dist/chunk-8dybd0g5.js +0 -2
- package/dist/chunk-8em788gc.js +0 -2
- package/dist/chunk-9svygzeg.js +0 -2
- package/dist/chunk-9z4qr5w9.js +0 -2
- package/dist/chunk-af4ss0p5.js +0 -2
- package/dist/chunk-aj34t5h3.js +0 -2
- package/dist/chunk-atcy4zq6.js +0 -2
- package/dist/chunk-az28kd7f.js +0 -2
- package/dist/chunk-cncdgxk3.js +0 -2
- package/dist/chunk-d2t2pq1s.js +0 -3
- package/dist/chunk-dcx2t3sy.js +0 -2
- package/dist/chunk-dn28q0m3.js +0 -2
- package/dist/chunk-dn89zg1v.js +0 -2
- package/dist/chunk-dwddzp5f.js +0 -2
- package/dist/chunk-enchx79c.js +0 -2
- package/dist/chunk-ev8ma4ph.js +0 -2
- package/dist/chunk-ftrsaag8.js +0 -2
- package/dist/chunk-g6efz3ww.js +0 -2
- package/dist/chunk-gd59tkhr.js +0 -2
- package/dist/chunk-h1g9m148.js +0 -2
- package/dist/chunk-h8tew5mz.js +0 -2
- package/dist/chunk-hdrcgepx.js +0 -127
- package/dist/chunk-hn64343d.js +0 -2
- package/dist/chunk-htaed68z.js +0 -2
- package/dist/chunk-j5jkh05f.js +0 -2
- package/dist/chunk-j90yng9b.js +0 -2
- package/dist/chunk-jabb3v4c.js +0 -2
- package/dist/chunk-jczvjn7z.js +0 -2
- package/dist/chunk-kqkhcbrx.js +0 -2
- package/dist/chunk-mgzegkvk.js +0 -2
- package/dist/chunk-mk71833d.js +0 -2
- package/dist/chunk-n3s3w1f5.js +0 -2
- package/dist/chunk-nj0b4ryt.js +0 -2
- package/dist/chunk-ny6enm8b.js +0 -3
- package/dist/chunk-p8ndfekp.js +0 -2
- package/dist/chunk-qhjm9hvz.js +0 -2
- package/dist/chunk-qzy34xmt.js +0 -2
- package/dist/chunk-ra40trfh.js +0 -2
- package/dist/chunk-rjq597cn.js +0 -2
- package/dist/chunk-rrdwynz4.js +0 -2
- package/dist/chunk-sddytf9n.js +0 -2
- package/dist/chunk-shhtbdnj.js +0 -2
- package/dist/chunk-t4g97h08.js +0 -2
- package/dist/chunk-t7f9zmy8.js +0 -2
- package/dist/chunk-tme29zh9.js +0 -3
- package/dist/chunk-x1xx8qt0.js +0 -2
- package/dist/chunk-xmfhb2v0.js +0 -2
- package/dist/chunk-xsw183n7.js +0 -2
- package/dist/chunk-xtwe2rnp.js +0 -2
- package/dist/chunk-xxnh7gv8.js +0 -2
- package/dist/chunk-y84n0dvg.js +0 -2
- package/dist/chunk-zr0k9pz5.js +0 -2
- package/dist/chunk-zytcxy8p.js +0 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{J,b,
|
|
2
|
+
import{J,b,xn,Sn,e,Bt,_n,f,Ye,Ft,Ze,Qe,oe,j,ye,Q,u,Re,Mi,Bs,n,r,ie,yr,o,P,be}from"./chunk-7m5xrqnj.js";import{W,Ln,ae,O,Wt}from"./chunk-ptv5f34x.js";import{pt,Hn,Pr,Ir,Or,ft,gt,mt,ht,yt,bt,Ne}from"./chunk-c4ysk7x2.js";import{ze,Po,ce,T,Io,qr,Yn,ke,Oo,le}from"./chunk-qjfgdcck.js";import{Kt}from"./chunk-npn3h566.js";import{fe}from"./chunk-bsts9pr5.js";import{a}from"./chunk-5v95x083.js";import{D}from"./chunk-shcn4wve.js";async function Kn(t){try{let s=await Bun.file(t).text(),i=Xn(s),d=Jn(s,t),c=Qn(s,i),l=Zn(s,i);return{file:t,metrics:i,issues:d,suggestions:c,performance:l}}catch(s){throw Error(`Failed to analyze template ${t}: ${s instanceof Error?s.message:String(s)}`)}}function Xn(t){let s=t.split(`
|
|
3
3
|
`),i=t.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),c=(i?i[1]:"").split(`
|
|
4
|
-
`).length,l={conditionals:(t.match(/@(if|unless|elseif|else|endif|endunless)\b/g)||[]).length,loops:(t.match(/@(foreach|for|endforeach|endfor|while|endwhile)\b/g)||[]).length,includes:(t.match(/@(include|component|extends|section|yield)\b/g)||[]).length,custom:0,total:0};l.total=l.conditionals+l.loops+l.includes+l.custom;let m=(t.match(/\{\{[\s\S]*?\}\}/g)||[]).length,p=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,h=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,g=m+p+h,y=(t.match(/<[A-Z][^>]*>/g)||[]).length,w=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,R=0;for(let C of s)if(/@(?:if|unless|foreach|for|while|section)\b/.test(C)&&!/@end/.test(C)&&!/@else/.test(C))R++,S=Math.max(S,R);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(C))R--;let v=S>=4?3:0,x=Math.min(10,Math.ceil(l.total*0.5+g*0.1+y*0.3+(c>10?c*0.05:0)+v));return{lines:s.length,characters:t.length,directives:l,expressions:g,components:y,layouts:w,scriptLines:c,complexity:x}}function
|
|
5
|
-
`).filter((y)=>y.length>120);if(h.length>0)i.push({type:"info",category:"maintainability",message:`Found ${h.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let g=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(g>3)i.push({type:"info",category:"maintainability",message:`Found ${g} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return i}function Qn(t,s){let i=[];if(s.complexity>7)i.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(s.complexity>5&&s.directives.total>8)i.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(s.lines>100&&s.components===0)i.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(s.expressions>20)i.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let d=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(d&&d.length>0)i.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(s.directives.total===0&&s.expressions<5)i.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(s.scriptLines>50)i.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return i}function Zn(t,s){let i=1;if(i+=s.directives.conditionals*0.1,i+=s.directives.loops*0.5,i+=s.directives.includes*2,i+=s.expressions*0.05,i+=s.components*1,s.scriptLines>10)i+=s.scriptLines*0.1;let d;if(s.expressions===0&&s.directives.total===0)d="high";else if(s.expressions<5&&s.directives.total<3)d="medium";else d="low";let c=[];if(i>10)c.push("Consider optimizing template complexity");if(d==="low"&&s.directives.total>5)c.push("Reduce dynamic content for better caching");if(s.components===0&&s.lines>40)c.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(i*100)/100,complexityScore:s.complexity,cacheability:d,recommendations:c}}function Jt(t,s,i){let d=t.replace(/<!--[\s\S]*?-->/g,""),c=(d.match(new RegExp(`@${s}\\b`,"g"))||[]).length,l=(d.match(new RegExp(`@${i}\\b`,"g"))||[]).length;return Math.abs(c-l)}async function
|
|
4
|
+
`).length,l={conditionals:(t.match(/@(if|unless|elseif|else|endif|endunless)\b/g)||[]).length,loops:(t.match(/@(foreach|for|endforeach|endfor|while|endwhile)\b/g)||[]).length,includes:(t.match(/@(include|component|extends|section|yield)\b/g)||[]).length,custom:0,total:0};l.total=l.conditionals+l.loops+l.includes+l.custom;let m=(t.match(/\{\{[\s\S]*?\}\}/g)||[]).length,p=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,h=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,g=m+p+h,y=(t.match(/<[A-Z][^>]*>/g)||[]).length,w=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,R=0;for(let C of s)if(/@(?:if|unless|foreach|for|while|section)\b/.test(C)&&!/@end/.test(C)&&!/@else/.test(C))R++,S=Math.max(S,R);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(C))R--;let v=S>=4?3:0,x=Math.min(10,Math.ceil(l.total*0.5+g*0.1+y*0.3+(c>10?c*0.05:0)+v));return{lines:s.length,characters:t.length,directives:l,expressions:g,components:y,layouts:w,scriptLines:c,complexity:x}}function Jn(t,s){let i=[],d=Jt(t,"if","endif");if(d>0)i.push({type:"error",category:"syntax",message:`Found ${d} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let c=Jt(t,"foreach","endforeach");if(c>0)i.push({type:"error",category:"syntax",message:`Found ${c} unmatched @foreach directive(s)`,suggestion:"Ensure every @foreach has a corresponding @endforeach"});let l=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(l&&l.length>0)i.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let m=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(m>0)i.push({type:"warning",category:"security",message:`Found ${m} raw output expression(s) {!! !!}`,suggestion:"Ensure raw outputs are properly sanitized to prevent XSS"});let p=t.match(/<img[^>]*>/g);if(p){let y=p.filter((w)=>!w.includes("alt="));if(y.length>0)i.push({type:"warning",category:"accessibility",message:`Found ${y.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let h=t.split(`
|
|
5
|
+
`).filter((y)=>y.length>120);if(h.length>0)i.push({type:"info",category:"maintainability",message:`Found ${h.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let g=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(g>3)i.push({type:"info",category:"maintainability",message:`Found ${g} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return i}function Qn(t,s){let i=[];if(s.complexity>7)i.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(s.complexity>5&&s.directives.total>8)i.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(s.lines>100&&s.components===0)i.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(s.expressions>20)i.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let d=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(d&&d.length>0)i.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(s.directives.total===0&&s.expressions<5)i.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(s.scriptLines>50)i.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return i}function Zn(t,s){let i=1;if(i+=s.directives.conditionals*0.1,i+=s.directives.loops*0.5,i+=s.directives.includes*2,i+=s.expressions*0.05,i+=s.components*1,s.scriptLines>10)i+=s.scriptLines*0.1;let d;if(s.expressions===0&&s.directives.total===0)d="high";else if(s.expressions<5&&s.directives.total<3)d="medium";else d="low";let c=[];if(i>10)c.push("Consider optimizing template complexity");if(d==="low"&&s.directives.total>5)c.push("Reduce dynamic content for better caching");if(s.components===0&&s.lines>40)c.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(i*100)/100,complexityScore:s.complexity,cacheability:d,recommendations:c}}function Jt(t,s,i){let d=t.replace(/<!--[\s\S]*?-->/g,""),c=(d.match(new RegExp(`@${s}\\b`,"g"))||[]).length,l=(d.match(new RegExp(`@${i}\\b`,"g"))||[]).length;return Math.abs(c-l)}async function bo(t=["**/*.stx"],s){let i=[],d=[];for(let l of t){let m=await Array.fromAsync(new Bun.Glob(l).scan({cwd:s||process.cwd(),onlyFiles:!0,absolute:!0}));d.push(...m.filter((p)=>p.endsWith(".stx")))}for(let l of d)try{let m=await Kn(l);i.push(m)}catch(m){console.warn(`Failed to analyze ${l}:`,m)}let c=er(i);return{results:i,summary:c}}function er(t){let s=t.length,i=t.reduce((g,y)=>g+y.metrics.lines,0),d=s>0?t.reduce((g,y)=>g+y.metrics.complexity,0)/s:0,c=t.reduce((g,y)=>g+y.issues.length,0),l={};t.forEach((g)=>{g.issues.forEach((y)=>{l[y.category]=(l[y.category]||0)+1})});let m=s>0?t.reduce((g,y)=>g+y.performance.estimatedRenderTime,0)/s:0,p=Math.max(1,Math.min(10,Math.round(10-m/2-d/2))),h=[];if(d>6)h.push("Project has high average complexity. Consider refactoring complex templates.");if(c>s*2)h.push("High number of issues detected. Run detailed analysis on individual files.");if(l.security>0)h.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:s,totalLines:i,avgComplexity:Math.round(d*100)/100,totalIssues:c,issuesByCategory:l,performanceScore:p,recommendations:h}}import{mkdir as tr,readFile as nr,readdir as rr,stat as Yt,writeFile as or}from"fs/promises";import Ee from"path";function rn(t){if(t==="connectedCallback")return`method "${t}" is reserved; define "onConnect" instead, which the element calls once it is connected, rendered and bound`;if(t==="disconnectedCallback")return`method "${t}" is reserved; define "onDisconnect" instead, which the element calls as it leaves the DOM, before it releases its own listeners`;return`method "${t}" is reserved`}var on=new Set(["constructor","connectedCallback","disconnectedCallback","attributeChangedCallback","adoptedCallback"]);function sr(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((s)=>s.charAt(0).toUpperCase()+s.slice(1)).join("")}function It(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function ir(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function ar(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function cr(t){let s=[];async function i(d){let c=await rr(d,{withFileTypes:!0});c.sort((l,m)=>l.name.localeCompare(m.name));for(let l of c){let m=Ee.join(d,l.name);if(l.isDirectory()){if(!l.name.startsWith(".")&&l.name!=="node_modules")await i(m)}else if(l.isFile()&&l.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(l.name))s.push(m)}}return await i(t),s}function lr(t,s){let i=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!i)return{};let d=i[1].trim();if(!d)return{};try{return JSON.parse(d)}catch(c){throw Error(`${s}: <script component> must contain JSON metadata (${c.message})`)}}function dr(t,s){let i={},d=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let c of d){if(!/\bclient\b/i.test(c[1])||/\bcomponent\b|\bstx:component\b/i.test(c[1]))continue;let l;try{l=new Bun.Transpiler({loader:"ts"}).transformSync(c[2])}catch(h){throw Error(`${s}: failed to transpile <script client> (${h.message})`)}let m=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,p;while(p=m.exec(l)){let h=p[1];if(on.has(h))throw Error(`${s}: client ${rn(h)}`);let g=m.lastIndex,y=1,w="",S=!1,R=g;for(;R<l.length&&y>0;R++){let x=l[R];if(S){S=!1;continue}if(w){if(x==="\\")S=!0;else if(x===w)w="";continue}if(x==='"'||x==="'"||x==="`")w=x;else if(x==="{")y++;else if(x==="}")y--}if(y!==0)throw Error(`${s}: unterminated client function "${h}"`);let v=p[0].includes("async")?"async ":"";i[h]=`${v}${h}(${p[2]}) {${l.slice(g,R-1)}}`,m.lastIndex=R}}return i}function pr(t){let s=t.match(/<template\b(?![^>]*\bshadowrootmode\b)[^>]*>([\s\S]*?)<\/template>/i);return(s?s[1]:t).replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").trim()}function Qt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((s)=>s[1].trim()).filter(Boolean).join(`
|
|
6
6
|
|
|
7
7
|
`)}function ur(t){if(!t)return null;let s=t.replace(/\s*\|\s*(?:undefined|null)\b/g,"").trim();if(/^string$/.test(s))return"string";if(/^number$/.test(s))return"number";if(/^boolean$/.test(s))return"boolean";if(/^(?:'[^']*'|"[^"]*")(?:\s*\|\s*(?:'[^']*'|"[^"]*"))*$/.test(s))return"string";return"object"}function fr(t){if(t===void 0)return"object";if(t==="true"||t==="false")return"boolean";if(/^-?\d+(?:\.\d+)?$/.test(t))return"number";if(/^['"`]/.test(t))return"string";return"object"}function mr(t){if(t==="true")return!0;if(t==="false")return!1;if(/^-?\d+(?:\.\d+)?$/.test(t))return Number(t);if(/^['"`]/.test(t))return t.slice(1,-1);try{return JSON.parse(t)}catch{return}}function gr(t){let s=[],i=0,d=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),c=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,l,m=(h)=>{if(d[h]!=="(")return null;let g=0,y="";for(let w=h;w<d.length;w++){let S=d[w];if(y!==""){if(S==="\\")w++;else if(S===y)y="";continue}if(S==="'"||S==='"'||S==="`"){y=S;continue}if(S==="(")g++;else if(S===")"){if(g--,g===0)return{expression:d.slice(h+1,w),end:w+1}}}return null},p=(h)=>{if(h==="")return;let g=0,y=/\{!!\s*([\s\S]*?)\s*!!\}|\{\{\s*([\s\S]*?)\s*\}\}/g,w;while(w=y.exec(h)){if(w.index>g)s.push(`out += ${JSON.stringify(h.slice(g,w.index))};`);s.push(w[1]!==void 0?`out += __raw(${w[1]});`:`out += __escape(${w[2]});`),g=w.index+w[0].length}if(g<h.length)s.push(`out += ${JSON.stringify(h.slice(g))};`)};while(l=c.exec(d)){p(d.slice(i,l.index)),i=l.index+l[0].length;let g=l[1]==="if"||l[1]==="elseif"||l[1]==="foreach"?m(i):null;if(g)i=g.end,c.lastIndex=g.end;let y=g?.expression;switch(l[1]){case"if":s.push(`if (${y}) {`);break;case"elseif":s.push(`} else if (${y}) {`);break;case"else":s.push("} else {");break;case"endif":case"endforeach":s.push("}");break;case"foreach":{let w=/^([\s\S]+?)\s+as\s+(?:([A-Za-z_$][\w$]*)\s*=>\s*)?([A-Za-z_$][\w$]*)$/.exec((y||"").trim());if(!w){s.push(`out += ${JSON.stringify(l[0]+(g?`(${y})`:""))};`);break}let[,S,R,v]=w;s.push(R?`for (const [${R}, ${v}] of __entries(${S})) {`:`for (const ${v} of __values(${S})) {`);break}}}return p(d.slice(i)),s.join(`
|
|
8
|
-
`)}function
|
|
8
|
+
`)}function ut(t,s,i,d){if(t[s]!==i)return-1;let c=0,l=null;for(let m=s;m<t.length;m++){let p=t[m];if(l){if(p==="\\"){m++;continue}if(p===l)l=null;continue}if(p==="'"||p==='"'||p==="`"){l=p;continue}if(p===i)c++;else if(p===d){if(d===">"&&t[m-1]==="=")continue;if(c--,c===0)return m+1}}return-1}function _t(t,s,i){let d=i?"([{<":"([{",c=i?")]}>":")]}",l=[],m=0,p=null,h="";for(let g=0;g<t.length;g++){let y=t[g];if(p){if(h+=y,y==="\\"){h+=t[++g]??"";continue}if(y===p)p=null;continue}if(y==="'"||y==='"'||y==="`"){p=y,h+=y;continue}if(d.includes(y))m++;else if(c.includes(y))m--;if(m===0&&s.includes(y)){l.push(h),h="";continue}h+=y}return l.push(h),l.map((g)=>g.trim()).filter(Boolean)}function hr(t){let s=0,i=null;for(let d=0;d<t.length;d++){let c=t[d];if(i){if(c==="\\"){d++;continue}if(c===i)i=null;continue}if(c==="'"||c==='"'||c==="`"){i=c;continue}if("([{".includes(c))s++;else if(")]}".includes(c))s--;if(s!==0||c!=="=")continue;let l=t[d-1];if(t[d+1]==="="||l==="="||l==="!"||l==="<"||l===">")continue;return d}return-1}function Zt(t){switch(t.trim()){case"String":return"string";case"Number":return"number";case"Boolean":return"boolean";case"Array":return"unknown[]";case"Object":return"Record<string, unknown>";default:return}}function br(t){let s=/\bdefineProps\b/.exec(t);if(!s)return null;let i=/(?:^|[\s;{}()])(const|let|var)\s+/g,d=-1;for(let k=i.exec(t);k&&k.index<s.index;k=i.exec(t))d=k.index+k[0].indexOf(k[1]);if(d===-1)return null;let c={},l={},m=[],p=d+(/^(?:const|let|var)\s+/.exec(t.slice(d))?.[0].length??0),h=()=>{while(p<t.length&&/\s/.test(t[p]))p++},g;if(t[p]==="{"){let k=ut(t,p,"{","}");if(k===-1)return null;g=t.slice(p,k),p=k}else{let k=/^[A-Za-z_$][\w$]*/.exec(t.slice(p));if(!k)return null;g=k[0],p+=k[0].length}if(h(),t[p]!=="=")return null;p++,h();let y=/^withDefaults\s*\(\s*/.exec(t.slice(p)),w=Boolean(y);if(y)p+=y[0].length;let S=/^defineProps\b/.exec(t.slice(p));if(!S)return null;p+=S[0].length;let R="";if(h(),t[p]==="<"){let k=ut(t,p,"<",">");if(k===-1)return null;R=t.slice(p+1,k-1).trim(),p=k}if(h(),t[p]!=="(")return null;let v=ut(t,p,"(",")");if(v===-1)return null;let x=t.slice(p+1,v-1).trim();if(p=v,w){if(h(),t[p]===",")p++,h();if(t[p]==="{"){let k=ut(t,p,"{","}");if(k===-1)return null;for(let[B,_]of Lt(t.slice(p,k)))l[B]=_;p=k}if(h(),t[p]===",")p++,h();if(t[p]===")")p++}if(t[p]===";")p++;let C=/^[A-Za-z_$][\w$]*$/.test(R)?R:void 0;if(R.startsWith("{"))for(let k of _t(R.replace(/^\{/,"").replace(/\}$/,""),",;",!0)){let B=/^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(k);if(B)c[B[1]]=B[2].trim()}if(x.startsWith("{"))for(let[k,B]of Lt(x)){if(m.push(k),!B.startsWith("{")){let _=Zt(B);if(_)c[k]=_;continue}for(let[_,I]of Lt(B))if(_==="default")l[k]=I;else if(_==="type"){let E=Zt(I);if(E)c[k]=E}}else if(x.startsWith("["))for(let k of _t(x.slice(1,-1),",",!1))m.push(k.replace(/^['"`]/,"").replace(/['"`]$/,""));if(g.startsWith("{")){m.length=0;for(let k of _t(g.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let B=hr(k),I=(B===-1?k:k.slice(0,B)).split(":")[0].trim().replace(/^\.\.\./,"");if(!I)continue;if(m.push(I),B!==-1)l[I]=k.slice(B+1).trim()}}else if(m.length===0)m.push(...Object.keys(c));return{text:t.slice(d,p),propNames:m,defaults:l,declared:c,typeName:C}}function Lt(t){let s=t.trim().replace(/^\{/,"").replace(/\}$/,""),i=[],d=0;while(d<s.length){let c=/\s*([A-Za-z_$][\w$]*)\s*:/y;c.lastIndex=d;let l=c.exec(s);if(!l)break;d=c.lastIndex;let m=0,p="",h=d;while(d<s.length){let y=s[d];if(p){if(y==="\\")d++;else if(y===p)p=""}else if(y==="'"||y==='"'||y==="`")p=y;else if(y==="{"||y==="["||y==="(")m++;else if(y==="}"||y==="]"||y===")")m--;else if(y===","&&m===0)break;d++}let g=s.slice(h,d).trim();if(g)i.push([l[1],g]);d++}return i}function xr(t,s,i){let c=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].find((S)=>!/\bcomponent\b|\bstx:component\b|\bclient\b/i.test(S[1]));if(!c)return{imports:[],body:"",propNames:[],defaults:{},declared:{}};let l=c[2],m=[],p=[],h={},g={};l=l.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm,(S)=>{if(/from\s*['"]stx['"]/.test(S))return"";return m.push(S.trim().replace(/(from\s*['"])(\.[^'"]*)(['"])/,(R,v,x,C)=>{let k=Ee.resolve(Ee.dirname(s),x),B=Ee.relative(i,k);return`${v}${B.startsWith(".")?B:`./${B}`}${C}`})),""});let y=br(l);if(y)p.push(...y.propNames),Object.assign(h,y.defaults),Object.assign(g,y.declared),l=l.replace(y.text,"");let w={};for(let S of l.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)){let R=[];for(let v of S[2].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))g[v[1]]=v[2].trim(),R.push(v[1]);w[S[1]]=R}if(y&&y.propNames.length===0&&y.typeName){for(let S of w[y.typeName]??[])if(!p.includes(S))p.push(S)}return l=l.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g,""),{imports:m,body:l.trim(),propNames:p,defaults:h,declared:g}}function vr(t){let s=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(d,c,l,m,p)=>{let h=c.toLowerCase();s.add(h);let g=(l||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${h}="${p}"${g?` data-stx-mod-${h}="${g}"`:""}`}),eventTypes:[...s].sort()}}function wr(t){let s=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(d,c,l,m)=>{let p=s.length;return s.push({id:p,name:c,expression:m}),` data-stx-bind-${p}=""`}),bindings:s}}function Sr(t){let s=new Set;for(let i of t.matchAll(/<slot\b([^>]*)>/gi))s.add(i[1].match(/\bname\s*=\s*["']([^"']+)["']/i)?.[1]||"");return[...s].map((i)=>({name:i}))}function kr(t){return[...new Set([...t.matchAll(/(--[a-z0-9_-]+)\s*:/gi)].map((s)=>s[1]))].sort().map((s)=>({name:s}))}function en(t,s){if(!s||!new Set(["string","number","boolean","object","array"]).has(s.type))throw Error(`Property "${t}" must declare one of: string, number, boolean, object, array`);return{...s,reflect:s.reflect??s.attribute!==!1}}async function Tr(t,s,i){let d=Ee.isAbsolute(s.file)?s.file:Ee.resolve(t,s.file),c=await nr(d,"utf8"),l=lr(c,d),m=Ee.basename(d,".stx"),p=s.name||l.name||sr(m),h=`${It(i.prefix||"stx")}-${It(m)}`,g=s.tag||l.tag||h;if(!p||!/^[A-Za-z_$][\w$]*$/.test(p))throw Error(`${d}: invalid component class name "${p}"`);if(!ir(g))throw Error(`${d}: invalid custom-element tag "${g}"; tags must be lowercase and contain a hyphen`);let y=s.properties||l.properties||l.props||{},w=Object.fromEntries(Object.entries(y).map(([_,I])=>[_,en(_,I)])),S=vr(pr(c)),R=wr(S.template),v=xr(c,d,Ee.resolve(i.outputDir)),x=gr(R.template);for(let _ of v.propNames){if(w[_])continue;let I=v.defaults[_];w[_]=en(_,{type:ur(v.declared[_])??fr(I),...I===void 0?{}:{default:mr(I)}})}let C=l.methods||{},k=s.methods||{},B=dr(c,d);return{file:Ee.relative(t,d),sourcePath:d,name:p,tag:g,description:s.description||l.description||"",template:R.template,styles:Qt(c),shadowMode:ar(s.shadowDOM??l.shadowDOM??i.shadowDOM),progressive:s.progressive??l.progressive??i.progressive??!0,properties:w,events:s.events||l.events||{},methods:{...C,...k,...B},eventTypes:S.eventTypes,bindings:R.bindings,slots:Sr(R.template),cssProperties:kr(Qt(c)),scope:v,render:x}}function $r(){let t=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),s=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}");return`const HTMLElementBase = globalThis.HTMLElement || class {};
|
|
9
9
|
|
|
10
10
|
const escapeHTML = (value) => String(value ?? '')
|
|
11
11
|
.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>')
|
|
@@ -374,7 +374,7 @@ ${c}
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
export {}
|
|
377
|
-
`}function
|
|
377
|
+
`}function Ar(t){return{schemaVersion:"1.0.0",modules:t.map((s)=>({kind:"javascript-module",path:`./${s.tag}.js`,declarations:[{kind:"class",name:s.name,description:s.description||void 0,customElement:!0,tagName:s.tag,members:Object.entries(s.properties).map(([i,d])=>({kind:"field",name:i,description:d.description,type:{text:xt(d)},default:d.default===void 0?void 0:JSON.stringify(d.default),attribute:d.attribute===!1?void 0:d.attribute||It(i),reflects:d.reflect})),events:Object.entries(s.events).map(([i,d])=>({name:i,description:d.description,type:{text:`CustomEvent<${d.detailType||"unknown"}>`}})),slots:s.slots,cssProperties:s.cssProperties}],exports:[{kind:"js",name:s.name,declaration:{name:s.name,module:`./${s.tag}.js`}}]}))}}function tn(t){if(!t.styles)return"";let s=t.styles.replace(/:host\b/g,":scope");if(/\@scope\s*\(/.test(s))return s;return`@scope (${t.tag}) {
|
|
378
378
|
${s}
|
|
379
379
|
}`}function nn(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").replace(/\s*([{}:;,])\s*/g,"$1").replace(/;}/g,"}").trim()}function Dr(t){let s=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),i=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}"),d=JSON.stringify('<slot(?:\\s+name=["\\\']([^"\\\']+)["\\\'])?\\s*\\/?>(?:<\\/slot>)?'),c=Object.fromEntries(t.map((m)=>[m.tag,{template:m.template,styles:m.styles,shadowMode:m.shadowMode,properties:m.properties}])),l=t.map((m)=>`export const render${m.name} = (props = {}, slots = {}) => renderComponent('${m.tag}', props, slots);`).join(`
|
|
380
380
|
`);return`const definitions = ${JSON.stringify(c,null,2)};
|
|
@@ -410,7 +410,7 @@ export function renderComponent(tag, props = {}, slots = {}) {
|
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
${l}
|
|
413
|
-
`}async function
|
|
413
|
+
`}async function vo(t){let s=Ee.resolve(t.inputDir),i=Ee.resolve(t.outputDir);if(!(await Yt(s).catch(()=>null))?.isDirectory())throw Error(`Component-library input directory does not exist: ${s}`);let c=t.components?.length?t.components:(await cr(s)).map((x)=>({file:x}));if(!c.length)throw Error(`No .stx components found in ${s}`);let l=await Promise.all(c.map((x)=>Tr(s,x,t)));l.sort((x,C)=>x.tag.localeCompare(C.tag));let m=l.filter((x,C)=>l.findIndex((k)=>k.tag===x.tag)!==C);if(m.length)throw Error(`Duplicate custom-element tag: ${m[0].tag}`);let p=l.filter((x,C)=>l.findIndex((k)=>k.name===x.name)!==C);if(p.length)throw Error(`Duplicate component class name: ${p[0].name}`);await tr(i,{recursive:!0});let h=[],g=async(x,C)=>{let k=Ee.join(i,x);return await or(k,C.endsWith(`
|
|
414
414
|
`)?C:`${C}
|
|
415
415
|
`,"utf8"),h.push(k),k};await g("runtime.js",$r());for(let x of l){if(await g(`${x.tag}.js`,Cr(x)),t.declarations!==!1)await g(`${x.tag}.d.ts`,Rr(x));if(t.css!==!1&&x.styles){let C=x.shadowMode?x.styles:tn(x);await g(`${x.tag}.css`,t.minify?nn(C):C)}}let y=l.map((x)=>`export { ${x.name}, default as ${x.name}Element } from './${x.tag}.js';`).join(`
|
|
416
416
|
`);if(await g("index.js",y),await g("ssr.js",Dr(l)),t.declarations!==!1)await g("index.d.ts",l.map((x)=>`export * from './${x.tag}.js'`).join(`
|
|
@@ -418,13 +418,13 @@ ${l}
|
|
|
418
418
|
`)}
|
|
419
419
|
export declare function renderComponent(tag: string, props?: Record<string, unknown>, slots?: Record<string, string>): string
|
|
420
420
|
${l.map((x)=>`import type { ${x.name}Props } from './${x.tag}.js'`).join(`
|
|
421
|
-
`)}`);let w;if(t.manifest!==!1)w=await g("custom-elements.json",JSON.stringify(
|
|
421
|
+
`)}`);let w;if(t.manifest!==!1)w=await g("custom-elements.json",JSON.stringify(Ar(l),null,2));let S;if(t.css!==!1){let x=l.filter((C)=>!C.shadowMode&&C.styles).map(tn).join(`
|
|
422
422
|
|
|
423
423
|
`);if(x)S=await g("bundle.css",t.minify?nn(x):x)}let R;if(t.bundle!==!1){R=Ee.join(i,"bundle.js");let x;try{x=await Bun.build({entrypoints:[Ee.join(i,"index.js")],outdir:i,naming:"bundle.js",target:"browser",format:"esm",minify:t.minify??!0,sourcemap:t.sourcemap||"none"})}catch(C){let k=C instanceof AggregateError?C.errors:[C],B=k.map((_)=>String(_).trim()).filter(Boolean).join(`
|
|
424
424
|
`);throw AggregateError(k,`Failed to bundle component library${B?`
|
|
425
425
|
${B}`:""}`)}if(!x.success){let C=x.logs.map((k)=>String(k).trim()).filter(Boolean).join(`
|
|
426
426
|
`);throw AggregateError(x.logs,`Failed to bundle component library${C?`
|
|
427
|
-
${C}`:""}`)}if(h.push(R),t.sourcemap==="external")h.push(`${R}.map`)}let v=await Promise.all(h.map(async(x)=>(await Yt(x)).size));return{components:l.map((x)=>({name:x.name,tag:x.tag,source:x.sourcePath,module:Ee.join(i,`${x.tag}.js`)})),files:h,manifest:w,bundle:R,cssBundle:S,totalBytes:v.reduce((x,C)=>x+C,0)}}var{serve:
|
|
427
|
+
${C}`:""}`)}if(h.push(R),t.sourcemap==="external")h.push(`${R}.map`)}let v=await Promise.all(h.map(async(x)=>(await Yt(x)).size));return{components:l.map((x)=>({name:x.name,tag:x.tag,source:x.sourcePath,module:Ee.join(i,`${x.tag}.js`)})),files:h,manifest:w,bundle:R,cssBundle:S,totalBytes:v.reduce((x,C)=>x+C,0)}}var{serve:Vr}=globalThis.Bun;import Ht from"fs";import ot from"path";function vt(){return`
|
|
428
428
|
/* Theme selector for code blocks */
|
|
429
429
|
.theme-selector {
|
|
430
430
|
margin: 1rem 0;
|
|
@@ -504,12 +504,12 @@ else {
|
|
|
504
504
|
<span class="frontmatter-label">${s}:</span>
|
|
505
505
|
<span>${Array.isArray(i)?i.join(", "):String(i)}</span>
|
|
506
506
|
</div>`).join("")}
|
|
507
|
-
</div>`}import sn from"net";async function Mr(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"0.0.0.0")})}async function _r(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"::")})}async function
|
|
507
|
+
</div>`}import sn from"net";async function Mr(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"0.0.0.0")})}async function _r(t){return new Promise((s)=>{let i=sn.createServer();i.once("error",()=>s(!1)),i.once("listening",()=>{i.close(()=>s(!0))}),i.listen(t,"::")})}async function Lr(t){if(!await Mr(t))return!1;return await _r(t)}async function Xe(t,s=20){t=Number(t);for(let i=0;i<s;i++){let d=t+i;if(await Lr(d))return d}throw Error(`Could not find an available port between ${t} and ${t+s-1}`)}var Hr={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function zr(){try{let t=await import("./chunk-cw9pc5yx.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function rt(t,s={}){let i={...Hr,...s},d=await zr();if(!d)return console.log(`${e.yellow}\u26A0${e.reset} Native window requested, but @stacksjs/desktop is not available.`),console.log(" Install & build the desktop package to enable --native."),!1;try{let c=await d.openDevWindow(t,{title:i.title,width:i.width,height:i.height,darkMode:i.darkMode,hotReload:i.hotReload,titlebarHidden:i.titlebarHidden,nativeSidebar:i.nativeSidebar,sidebarWidth:i.sidebarWidth,sidebarConfig:i.sidebarConfig});if(c&&i.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return c}catch(c){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,c),!1}}function Tt(t){if(t.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let c=t.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(c){let l=c[1];try{let m=`
|
|
508
508
|
${l}
|
|
509
509
|
return typeof sidebarConfig !== 'undefined' ? sidebarConfig : null;
|
|
510
|
-
`,h=Function(m)();if(h)return h}catch(m){console.warn("Invalid sidebarConfig:",m)}}return{sections:[]}}let i=t.match(/@nativeSidebar\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(i)try{return JSON.parse(i[1])}catch{console.warn("Invalid @nativeSidebar configuration")}let d=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(d)try{let c=d[1].match(/(?:export\s+(?:default\s+)?|const\s+\w+\s*=\s*)(\{[\s\S]*\})/m);if(c)return Function(`return ${c[1]}`)()}catch(c){console.warn("Invalid native-sidebar script configuration:",c)}return}function
|
|
511
|
-
Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in browser`),console.log(` ${e.cyan}c${e.reset} + Enter - Clear console`),console.log(` ${e.cyan}q${e.reset} + Enter (or ${e.cyan}Ctrl+C${e.reset}) - Quit server`),console.log(` ${e.cyan}h${e.reset} + Enter - Show this help`)}function Nr(t){console.log(`${e.green}Server running at ${e.cyan}${t}${e.reset}`),console.log(`Press ${e.cyan}Ctrl+C${e.reset} to stop the server`),
|
|
512
|
-
`)){let l=d.trim().toLowerCase();d="",
|
|
510
|
+
`,h=Function(m)();if(h)return h}catch(m){console.warn("Invalid sidebarConfig:",m)}}return{sections:[]}}let i=t.match(/@nativeSidebar\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(i)try{return JSON.parse(i[1])}catch{console.warn("Invalid @nativeSidebar configuration")}let d=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(d)try{let c=d[1].match(/(?:export\s+(?:default\s+)?|const\s+\w+\s*=\s*)(\{[\s\S]*\})/m);if(c)return Function(`return ${c[1]}`)()}catch(c){console.warn("Invalid native-sidebar script configuration:",c)}return}function jt(){console.log(`
|
|
511
|
+
Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in browser`),console.log(` ${e.cyan}c${e.reset} + Enter - Clear console`),console.log(` ${e.cyan}q${e.reset} + Enter (or ${e.cyan}Ctrl+C${e.reset}) - Quit server`),console.log(` ${e.cyan}h${e.reset} + Enter - Show this help`)}function Nr(t){console.log(`${e.green}Server running at ${e.cyan}${t}${e.reset}`),console.log(`Press ${e.cyan}Ctrl+C${e.reset} to stop the server`),jt()}function Ur(t){console.log(`${e.dim}Opening ${e.cyan}${t}${e.dim} in your browser...${e.reset}`),Bun.spawn(["open",t],{stderr:"inherit"})}function Ge(t,s,i){if(!process.stdin.isTTY)return;process.stdin.setRawMode(!0),process.stdin.setEncoding("utf8"),process.stdin.resume(),jt();let d="";process.stdin.on("data",(c)=>{if(c==="\x03"){if(i?.onQuit)i.onQuit();s(),process.exit(0)}if(d+=c,d.endsWith("\r")||d.endsWith(`
|
|
512
|
+
`)){let l=d.trim().toLowerCase();d="",Wr(l,t,s,i)}})}function Wr(t,s,i,d){switch(t){case"o":if(d?.onOpen)d.onOpen();else Ur(s);break;case"c":if(d?.onClear)d.onClear();else console.clear(),Nr(s);break;case"q":if(d?.onQuit)d.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),i(),process.exit(0);break;case"h":if(d?.onHelp)d.onHelp();else jt();break;default:break}}async function zt(t,s={}){let i=s.port||3000,d=s.watch!==!1,c=ot.resolve(t);if(!Ht.existsSync(c))return console.error(`${e.red}Error: File not found: ${e.bright}${c}${e.reset}`),!1;if(!c.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${c}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${t}${e.reset}...`);let l=null,m=async()=>{try{let{content:w,data:S}=await be(c,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),R=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,v=R?.defaultTheme||"github-dark",x=["github-dark"],C=R?.additionalThemes||[],B=[...new Set([...x,...C])].map((_)=>`<option value="${_}"${_===v?" selected":""}>${_}</option>`).join(`
|
|
513
513
|
`);return l=`
|
|
514
514
|
<!DOCTYPE html>
|
|
515
515
|
<html lang="en">
|
|
@@ -672,12 +672,12 @@ Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in brow
|
|
|
672
672
|
</script>
|
|
673
673
|
</body>
|
|
674
674
|
</html>
|
|
675
|
-
`,!0}catch(w){return console.error(`${e.red}Error processing Markdown file:${e.reset}`,w),!1}};if(!await m())return!1;let h=i;try{if(h=await Xe(i),h!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${h} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${h}/${e.reset}...`);let g=
|
|
675
|
+
`,!0}catch(w){return console.error(`${e.red}Error processing Markdown file:${e.reset}`,w),!1}};if(!await m())return!1;let h=i;try{if(h=await Xe(i),h!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${h} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${h}/${e.reset}...`);let g=Vr({port:h,fetch(w){if(new URL(w.url).pathname==="/")return new Response(l,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}});return new Response("Not Found",{status:404})},error(w){return new Response(`<pre>${w}
|
|
676
676
|
${w.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
677
677
|
${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
|
|
678
678
|
${e.bright}\u2192 ${e.cyan}http://localhost:${h}/${e.reset}`),console.log(`
|
|
679
679
|
${e.yellow}Routes:${e.reset}`);let y=ot.relative(process.cwd(),c);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${y}${e.reset}`),console.log(`
|
|
680
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(g.url.toString(),()=>{if(d)
|
|
680
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(g.url.toString(),()=>{if(d)Ht.watch(ot.dirname(c),{recursive:!0}).close();g.stop()}),s.native)await rt(h,{title:ot.basename(c,".md")});if(d){let w=ot.dirname(c);console.log(`${e.blue}Watching ${e.bright}${w}${e.reset} for changes...`);let S=Ht.watch(w,{recursive:!0},async(R,v)=>{if(v&&v.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${v}${e.yellow} changed, reprocessing...${e.reset}`),await m()});process.on("SIGINT",()=>{S.close(),g.stop(),process.exit(0)})}return!0}function Kr(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Gr}=globalThis.Bun;import je from"fs";import ve from"path";class an{clients=new Set;server=null;options;constructor(t={}){this.options={wsPort:t.wsPort??3001,showOverlay:t.showOverlay??!0,reconnectInterval:t.reconnectInterval??1000,maxReconnectAttempts:t.maxReconnectAttempts??10,verbose:t.verbose??!1}}start(t){let s=t??this.options.wsPort,i=20;for(let d=0;d<i;d++)try{if(this.server=Bun.serve({port:s,fetch(c,l){if(l.upgrade(c,{data:{}}))return;return new Response("stx Hot Reload Server",{headers:{"Content-Type":"text/plain"}})},websocket:{open:(c)=>{if(this.clients.add(c),this.options.verbose)console.log(`[HMR] Client connected (${this.clients.size} total)`);c.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close:(c)=>{if(this.clients.delete(c),this.options.verbose)console.log(`[HMR] Client disconnected (${this.clients.size} total)`)},message:(c,l)=>{let m=typeof l==="string"?l:l.toString();if(m==="ping")return;try{let p=JSON.parse(m);if(p.type==="console"&&Array.isArray(p.args)){let h=p.args.join(" "),y={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[p.level]??"\x1B[36m";console.log(`${y}[browser]${p.level!=="log"?` ${p.level}`:""}\x1B[0m ${h}`)}}catch{}}}}),this.options.verbose)console.log(`[HMR] WebSocket server started on port ${s}`);return s}catch(c){if(c?.code==="EADDRINUSE"){s++;continue}throw c}throw Error(`Could not find an available port after ${i} attempts starting from ${t??this.options.wsPort}`)}stop(){for(let t of this.clients)try{t.close()}catch{}if(this.clients.clear(),this.server)this.server.stop(),this.server=null;if(this.options.verbose)console.log("[HMR] Server stopped")}broadcast(t){let s=JSON.stringify(t),i=0;for(let d of this.clients)try{if(d.readyState===1)d.send(s),i++}catch{this.clients.delete(d)}if(this.options.verbose&&i>0)console.log(`[HMR] Broadcast ${t.type} to ${i} client(s)`)}reload(t){if(this.options.verbose)console.log(`[HMR] Sending reload to ${this.clients.size} client(s) for: ${t||"all"}`);this.broadcast({type:"reload",path:t,timestamp:Date.now()})}updateCss(t,s){this.broadcast({type:"css-update",path:t,content:s,timestamp:Date.now()})}error(t){this.broadcast({type:"error",content:t,timestamp:Date.now()})}get clientCount(){return this.clients.size}get port(){return this.options.wsPort}}function Xr(t,s={}){let{showOverlay:i=!0,reconnectInterval:d=1000,maxReconnectAttempts:c=10}=s;return`
|
|
681
681
|
<script>
|
|
682
682
|
(function() {
|
|
683
683
|
// stx Hot Reload Client
|
|
@@ -876,10 +876,10 @@ else {
|
|
|
876
876
|
};
|
|
877
877
|
})();
|
|
878
878
|
</script>
|
|
879
|
-
`}function Ve(t,s,i={}){let d=Xr(s,i),c=t.lastIndexOf("</body>");if(c!==-1)return t.slice(0,c)+d+t.slice(c);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function $t(t){let s=t.toLowerCase();return s.endsWith(".css")||s.endsWith(".scss")||s.endsWith(".sass")||s.endsWith(".less")}function Ct(t){let s=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>s.endsWith(d))}function Rt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((i)=>i.test(t))}var st=null;function Et(t){if(!st)st=new an(t);return st}function lt(){if(st)st.stop(),st=null}import Pt from"path";var it={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},d=new Set,c=i.webComponents?.enabled?`./${Pt.relative(Pt.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let m=await
|
|
879
|
+
`}function Ve(t,s,i={}){let d=Xr(s,i),c=t.lastIndexOf("</body>");if(c!==-1)return t.slice(0,c)+d+t.slice(c);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function $t(t){let s=t.toLowerCase();return s.endsWith(".css")||s.endsWith(".scss")||s.endsWith(".sass")||s.endsWith(".less")}function Ct(t){let s=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>s.endsWith(d))}function Rt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((i)=>i.test(t))}var st=null;function Et(t){if(!st)st=new an(t);return st}function lt(){if(st)st.stop(),st=null}import Pt from"path";var it={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},d=new Set,c=i.webComponents?.enabled?`./${Pt.relative(Pt.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let m=await yr(i,d);if(l.push(...m),i.debug&&m.length>0)console.log(`Successfully built ${m.length} web components`)}catch(m){console.error("Failed to build web components:",m)}t.onLoad({filter:/\.stx$/},async({path:m})=>{try{let p=new Set;if(i.cache&&i.cachePath){let x=await xn(m,i);if(x){if(i.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let h=await ae(()=>Bun.file(m).text(),"",(x)=>{throw new Ln(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!h)throw new Ln(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:y,allScripts:w}=J.time("script-extraction",()=>{let x=h,C=oe(h);if(C)x=C.content.trim();let k=h.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],B="",_=[];for(let E of k){let L=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",F=E.match(/<script\b([^>]*)>/i),K=F?F[1]:"";if(/\bserver\b/i.test(K))B=L;else _.push(E)}let I=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:B,templateContent:I,allScripts:_}}),S={__filename:m,__dirname:Pt.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await ae(()=>u(g,S,m),void 0,(x)=>{let C=new W(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(O.log(C,{filePath:m,scriptContent:g}),i.debug)throw C});let v=await J.timeAsync("directive-processing",async()=>await n(y,S,m,i,p));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-mfwrxz9z.js"),C=x(w.join(`
|
|
880
880
|
`),S),k=v.search(/<\/body>/i);if(k!==-1)v=v.slice(0,k)+C+`
|
|
881
881
|
`+v.slice(k);else v+=`
|
|
882
|
-
${C}`}if(v=await Q(v),p.forEach((x)=>d.add(x)),i.cache&&i.cachePath){if(await
|
|
882
|
+
${C}`}if(v=await Q(v),p.forEach((x)=>d.add(x)),i.cache&&i.cachePath){if(await Sn(m,v,p,i),i.debug)console.log(`Cached template ${m} with ${p.size} dependencies`)}return{contents:v,loader:"html"}}catch(p){let h=p instanceof Error?p:new W(`Plugin processing failed: ${String(p)}`,m);if(O.log(h,{filePath:m,buildConfig:t.config}),Wt.logDetailedError(h,{filePath:m,plugin:"bun-plugin-stx"}),i.debug)console.error("stx Plugin Error:",h);let g=h,y=g.line||null,w=g.context||null;return{contents:i.debug||D()?`<!DOCTYPE html>
|
|
883
883
|
<html lang="en">
|
|
884
884
|
<head>
|
|
885
885
|
<meta charset="UTF-8">
|
|
@@ -939,12 +939,12 @@ ${C}`}if(v=await Q(v),p.forEach((x)=>d.add(x)),i.cache&&i.cachePath){if(await xn
|
|
|
939
939
|
<h1>Something went wrong</h1>
|
|
940
940
|
<p>An internal error occurred. Please try again later.</p>
|
|
941
941
|
</body>
|
|
942
|
-
</html>`,loader:"html"}}})}};async function
|
|
942
|
+
</html>`,loader:"html"}}})}};async function Wn(t,s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=ve.resolve(t);if(!je.existsSync(p))return console.error(`${e.red}Error: File not found: ${e.bright}${p}${e.reset}`),!1;if(p.endsWith(".md"))return zt(p,s);else if(!p.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${p}${e.reset}. Only .stx and .md files are supported.`),!1;let h=a(process.cwd(),"output");je.mkdirSync(h,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,y=async()=>{try{let L={name:"public-assets",setup(Te){Te.onResolve({filter:/^\/(images|fonts|assets|public)\//},(me)=>({path:me.path,external:!0}))}},F=await Bun.build({entrypoints:[p],outdir:h,plugins:[L,it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!F.success)return console.error(`${e.red}Build failed:${e.reset}`,F.logs),!1;let K=F.outputs.find((Te)=>Te.path.endsWith(".html"));if(!K)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(K.path).text(),!0}catch(L){return console.error(`${e.red}Error building stx file:${e.reset}`,L),!1}};if(!await y())return!1;let S=ve.dirname(p);await Bt(S);let R=i;try{if(R=await Xe(i),R!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${R} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let L=s.hmrPort||R+1;l=Et({wsPort:L,verbose:!1}),m=l.start(L)}let v={},x=null,C;try{let{loadStxConfig:L}=await import("./chunk-qxjfvkjt.js"),F=await L();if(C=s.stxOptions?.serverApi??F.serverApi,F?.apiRouter)x=F?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(F?.apiRoutes){v=F.apiRoutes;let K=Object.keys(v).length;if(K>0)console.log(`${e.blue}Loaded ${e.bright}${K} API route${K>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:K,loadChannels:Z}=await import("./chunk-4xeafdr6.js"),Te=F.broadcasting;await K(Te);let me=Te.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${me}/ws${e.reset}`);let Oe=ve.join(process.cwd(),"channels.ts");if(je.existsSync(Oe))try{let ne=await Z(Oe);console.log(`${e.blue}Loaded ${e.bright}${ne} broadcast channel${ne!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ne){console.warn(`${e.yellow}Failed to load channels.ts: ${ne.message}${e.reset}`)}}catch(K){console.warn(`${e.yellow}Broadcasting failed to start: ${K.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:B}=await import("./chunk-b1ndskw9.js"),_=await k(process.cwd(),C);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${R}/${e.reset}...`),c)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${m}${e.reset}`);let I=Gr({port:R,async fetch(L){return Kt(L,await(async()=>{let F=new URL(L.url);if([h,ve.dirname(p),ve.join(process.cwd(),"public")].some((ne)=>B(ve.join(ne,F.pathname),process.cwd(),C)))return new Response("Not Found",{status:404});if(x)try{let ne=await x.handleRequest(L);if(ne.status!==404)return ne}catch{}if(v[F.pathname])try{return await v[F.pathname](L)}catch(ne){return new Response(JSON.stringify({error:ne.message}),{status:500,headers:{"Content-Type":"application/json"}})}let K=await _(L);if(K)return K;if(F.pathname==="/")return(async()=>{let U=await f(g||"");if(c)U=Ve(U,m);if(s.native)if(U.includes("<head>"))U=U.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else if(U.includes("<html"))U=U.replace(/(<html[^>]*>)/,"$1<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>");else U="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+U;if(s.titlebarHidden)if(U.includes("<head>"))U=U.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else if(U.includes("<html"))U=U.replace(/(<html[^>]*>)/,"$1<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>");else U=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${U}`;return U})().then((U)=>new Response(U,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Z=ve.join(h,F.pathname);if(je.existsSync(Z)&&je.statSync(Z).isFile()){let ne=Bun.file(Z),U=ve.extname(Z).toLowerCase(),H="text/plain";if(U===".ts"||U===".tsx"){let He=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=He.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":H="text/html";break;case".css":H="text/css";break;case".js":H="text/javascript";break;case".json":H="application/json";break;case".png":H="image/png";break;case".jpg":case".jpeg":H="image/jpeg";break;case".gif":H="image/gif";break;case".woff":H="font/woff";break;case".woff2":H="font/woff2";break;case".ttf":H="font/ttf";break;case".otf":H="font/otf";break;case".eot":H="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":H}})}let Te=ve.dirname(p),me=ve.join(Te,F.pathname);if(je.existsSync(me)&&je.statSync(me).isFile()){let ne=Bun.file(me),U=ve.extname(me).toLowerCase(),H="text/plain";if(U===".ts"||U===".tsx"){let He=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=He.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":H="text/html";break;case".css":H="text/css";break;case".js":H="text/javascript";break;case".json":H="application/json";break;case".png":H="image/png";break;case".jpg":case".jpeg":H="image/jpeg";break;case".gif":H="image/gif";break;case".svg":H="image/svg+xml";break;case".ico":H="image/x-icon";break;case".woff":H="font/woff";break;case".woff2":H="font/woff2";break;case".ttf":H="font/ttf";break;case".otf":H="font/otf";break;case".eot":H="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":H}})}let Oe=ve.join(process.cwd(),"public",F.pathname);if(je.existsSync(Oe)&&je.statSync(Oe).isFile()){let ne=Bun.file(Oe),U=ve.extname(Oe).toLowerCase(),H="application/octet-stream";if(U===".ts"||U===".tsx"){let He=new Bun.Transpiler({loader:U===".tsx"?"tsx":"ts"}),Ue=await ne.text(),tt=He.transformSync(Ue);return new Response(tt,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(U){case".html":H="text/html";break;case".css":H="text/css";break;case".js":H="text/javascript";break;case".json":H="application/json";break;case".png":H="image/png";break;case".jpg":case".jpeg":H="image/jpeg";break;case".gif":H="image/gif";break;case".svg":H="image/svg+xml";break;case".ico":H="image/x-icon";break;case".woff":H="font/woff";break;case".woff2":H="font/woff2";break;case".ttf":H="font/ttf";break;case".otf":H="font/otf";break;case".eot":H="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":H}})}return new Response("Not Found",{status:404})})())},error(L){return new Response(`<pre>${L}
|
|
943
943
|
${L.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
944
944
|
${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
|
|
945
945
|
${e.bright}\u2192 ${e.cyan}http://localhost:${R}/${e.reset}`),console.log(`
|
|
946
946
|
${e.yellow}Routes:${e.reset}`);let E=ve.relative(process.cwd(),p);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${E}${e.reset}`),console.log(`
|
|
947
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(I.url.toString(),()=>{if(d)
|
|
947
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(I.url.toString(),()=>{if(d)je.watch(ve.dirname(p),{recursive:!0}).close();I.stop()}),s.native){let L=await Bun.file(p).text(),F=Tt(L);await rt(R,{title:ve.basename(p,".stx"),titlebarHidden:s.titlebarHidden===!0,nativeSidebar:!!F,sidebarConfig:F})}if(d){let L=ve.dirname(p);console.log(`${e.blue}Watching ${e.bright}${L}${e.reset} for changes...`);let F=je.watch(L,{recursive:!0},async(K,Z)=>{if(!Z||Rt(Z))return;if(Ct(Z)){console.log(`${e.yellow}File ${e.bright}${Z}${e.yellow} changed, rebuilding...${e.reset}`),Re.clear(),ie();let Te=await y();if(await _n(S),c&&l)if(Te)l.reload(Z);else l.error("Build failed - check console for details")}else if($t(Z)){if(console.log(`${e.cyan}CSS ${e.bright}${Z}${e.cyan} changed${e.reset}`),c&&l)l.updateCss(Z)}});process.on("SIGINT",()=>{if(F.close(),l)lt();I.stop(),process.exit(0)})}return!0}var{serve:Jr}=globalThis.Bun;import Je from"fs";import Pe from"path";var cn=`
|
|
948
948
|
<script data-stx-helpers>
|
|
949
949
|
(function() {
|
|
950
950
|
'use strict'
|
|
@@ -1255,7 +1255,7 @@ else {
|
|
|
1255
1255
|
|
|
1256
1256
|
})()
|
|
1257
1257
|
</script>
|
|
1258
|
-
`;function dn(t){if(t.length===0)return"";if(t.length===1)return t[0];let s=t.map((d)=>d.split(Pe.sep)),i=[];for(let d=0;d<s[0].length;d++){let c=s[0][d];if(s.every((l)=>l[d]===c))i.push(c);else break}return i.join(Pe.sep)}async function
|
|
1258
|
+
`;function dn(t){if(t.length===0)return"";if(t.length===1)return t[0];let s=t.map((d)=>d.split(Pe.sep)),i=[];for(let d=0;d<s[0].length;d++){let c=s[0][d];if(s.every((l)=>l[d]===c))i.push(c);else break}return i.join(Pe.sep)}async function qn(t,s={}){let i=s.port||3000,d=s.watch!==!1;for(let v of t){let x=Pe.resolve(v);if(!Je.existsSync(x))return console.error(`${e.red}Error: File not found: ${e.bright}${x}${e.reset}`),!1;if(!x.endsWith(".stx")&&!x.endsWith(".md"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${x}${e.reset}. Only .stx and .md files are supported.`),!1}let c=a(process.cwd(),"output");Je.mkdirSync(c,{recursive:!0});let l=dn(t.map((v)=>Pe.dirname(Pe.resolve(v))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let m={},p=[],h=async()=>{try{for(let v of t){let x=Pe.resolve(v);if(x.endsWith(".md"))try{let{content:k,data:B}=await be(x,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),_=s.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,I=_?.defaultTheme||"github-dark",E=["github-dark"],L=_?.additionalThemes||[],K=[...new Set([...E,...L])].map((Oe)=>`<option value="${Oe}"${Oe===I?" selected":""}>${Oe}</option>`).join(`
|
|
1259
1259
|
`),Z=`
|
|
1260
1260
|
<!DOCTYPE html>
|
|
1261
1261
|
<html lang="en">
|
|
@@ -1419,24 +1419,24 @@ else {
|
|
|
1419
1419
|
</body>
|
|
1420
1420
|
</html>
|
|
1421
1421
|
`,me=`/${Pe.relative(l,x).replace(/\.md$/,"")}`;if(me.endsWith("/index"))me=me.slice(0,-6)||"/";m[me||"/"]={filePath:x,content:Z,fileType:"md"}}catch(k){console.error(`${e.red}Error processing Markdown file ${e.bright}${v}${e.reset}:`,k);continue}else{let k={name:"public-assets",setup(E){E.onResolve({filter:/^\/(images|fonts|assets|public)\//},(L)=>({path:L.path,external:!0}))}},B;try{let E=await Bun.build({entrypoints:[x],outdir:c,plugins:[k,it],define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!E.success){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:`,fe(E.logs,x));continue}let L=E.outputs.find((F)=>F.path.endsWith(".html"));if(!L){console.error(`${e.red}No HTML output found for ${e.bright}${v}${e.reset}`);continue}B=await Bun.file(L.path).text()}catch(E){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:
|
|
1422
|
-
${fe(E,x)}`);continue}let I=`/${Pe.relative(l,x).replace(/\.stx$/,"")}`;if(I.endsWith("/index"))I=I.slice(0,-6)||"/";if(I.includes("[")){let{regex:E,params:L}=
|
|
1422
|
+
${fe(E,x)}`);continue}let I=`/${Pe.relative(l,x).replace(/\.stx$/,"")}`;if(I.endsWith("/index"))I=I.slice(0,-6)||"/";if(I.includes("[")){let{regex:E,params:L}=Pr(I,{page:!0});p.push({pattern:E,paramNames:L,filePath:x,routeTemplate:I,fileType:"stx"}),m[I]={filePath:x,content:B,fileType:"stx"}}else m[I||"/"]={filePath:x,content:B,fileType:"stx"}}}if(Object.keys(m).length===0)return console.error(`${e.red}No files were successfully processed${e.reset}`),!1;return!0}catch(v){return console.error(`${e.red}Error processing files:${e.reset}`,fe(v)),!1}};if(!await h())return!1;let y=i;try{if(y=await Xe(i),y!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${y} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${y}/${e.reset}...`);let w=Jr({port:y,async fetch(v){let x=new URL(v.url),C=Pe.join(process.cwd(),"public",x.pathname);if(Je.existsSync(C)&&Je.statSync(C).isFile()){let _=Bun.file(C),I=Pe.extname(C).toLowerCase(),E="application/octet-stream";if(I===".ts"||I===".tsx"){let L=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),F=await _.text(),K=L.transformSync(F);return new Response(K,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(I){case".html":E="text/html";break;case".css":E="text/css";break;case".js":E="text/javascript";break;case".json":E="application/json";break;case".png":E="image/png";break;case".jpg":case".jpeg":E="image/jpeg";break;case".gif":E="image/gif";break;case".svg":E="image/svg+xml";break;case".ico":E="image/x-icon";break;case".woff":E="font/woff";break;case".woff2":E="font/woff2";break;case".ttf":E="font/ttf";break;case".otf":E="font/otf";break;case".eot":E="application/vnd.ms-fontobject";break}return new Response(_,{headers:{"Content-Type":E}})}let k=m[x.pathname];if(!k&&!x.pathname.endsWith("/"))k=m[`${x.pathname}/`];if(!k)for(let _ of p){let I=x.pathname.match(_.pattern);if(I){let E=m[_.routeTemplate];if(E){let L={};for(let Z=0;Z<_.paramNames.length;Z++)L[_.paramNames[Z]]=decodeURIComponent(I[Z+1]);let F=E.content,K=`<script>window.__routeParams = ${JSON.stringify(L)};</script>`;if(F.includes("</head>"))F=F.replace("</head>",`${K}
|
|
1423
1423
|
</head>`);else F=K+F;k={...E,content:F}}break}}if(k)return f(k.content).then((_)=>{if(_.includes("</head>"))_=_.replace("</head>",`${cn}
|
|
1424
|
-
</head>`);return new Response(_,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let B=Pe.join(c,x.pathname);if(
|
|
1424
|
+
</head>`);return new Response(_,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let B=Pe.join(c,x.pathname);if(Je.existsSync(B)&&Je.statSync(B).isFile()){let _=Bun.file(B),I=Pe.extname(B).toLowerCase(),E="text/plain";if(I===".ts"||I===".tsx"){let L=new Bun.Transpiler({loader:I===".tsx"?"tsx":"ts"}),F=await _.text(),K=L.transformSync(F);return new Response(K,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(I){case".html":E="text/html";break;case".css":E="text/css";break;case".js":E="text/javascript";break;case".json":E="application/json";break;case".png":E="image/png";break;case".jpg":case".jpeg":E="image/jpeg";break;case".gif":E="image/gif";break;case".svg":E="image/svg+xml";break;case".ico":E="image/x-icon";break;case".woff":E="font/woff";break;case".woff2":E="font/woff2";break;case".ttf":E="font/ttf";break;case".otf":E="font/otf";break;case".eot":E="application/vnd.ms-fontobject";break}return new Response(_,{headers:{"Content-Type":E}})}if(x.pathname!=="/"&&m["/"]){let _=ce(v);return f(m["/"].content).then((I)=>{if(_){let E=I.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(E){let L=I.match(/<title[^>]*>([\s\S]*?)<\/title>/i),F=L?L[1]:"",K=`<!DOCTYPE html><html><head><title>${ln(F)}</title></head><body><main>${E[1]}</main></body></html>`;return new Response(K,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...T(),"Cache-Control":ze,Pragma:"no-cache",Expires:"0"}})}}return new Response(I,{headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})})}return new Response("Not Found",{status:404})},error(v){return new Response(`<pre>${v}
|
|
1425
1425
|
${v.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
1426
1426
|
${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
|
|
1427
1427
|
${e.bright}\u2192 ${e.cyan}http://localhost:${y}/${e.reset}`),console.log(`
|
|
1428
1428
|
${e.yellow}Routes:${e.reset}`);let S=new Set(p.map((v)=>v.routeTemplate)),R=Object.entries(m).filter(([v])=>!S.has(v)).sort(([v],[x])=>v.localeCompare(x)).map(([v,x])=>({route:v==="/"?"/":v,filePath:Pe.relative(process.cwd(),x.filePath),fileType:x.fileType}));for(let v of p){let x=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");R.push({route:x,filePath:Pe.relative(process.cwd(),v.filePath),fileType:"stx"})}if(R.sort((v,x)=>v.route.localeCompare(x.route)),R.forEach((v,x)=>{let k=x===R.length-1?"\u2514\u2500 ":"\u251C\u2500 ",B=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${k}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${B}`)}),console.log(`
|
|
1429
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(w.url.toString(),()=>{if(d)Qe.watch(l,{recursive:!0}).close();w.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Qe.watch(l,{recursive:!0},async(x,C)=>{if(!C)return;if(C.endsWith(".stx")||C.endsWith(".js")||C.endsWith(".ts")||C.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${C}${e.yellow} changed, rebuilding...${e.reset}`),$e.clear(),ie(),await h()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function ln(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Yr}=globalThis.Bun;import be from"fs";import te from"path";async function pn(t){try{return Bt(await Bun.file(t).text())}catch{return}}function Nt(t){let s=Bun.file(t),i=te.extname(t).toLowerCase(),d={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":d[i]||"application/octet-stream",...l}})}async function qn(t=".",s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=te.resolve(t),{loadStxConfig:h}=await import("./chunk-ev8ma4ph.js"),g=await h(p),{createServerApi:y,isServerApiSource:w}=await import("./chunk-xmfhb2v0.js"),S=s.stxOptions?.serverApi??g.serverApi,R=await y(p,S),v=g.root&&g.root!=="."?te.join(p,g.root):p,x=s.pagesDir||g.pagesDir||"pages",C=te.join(v,x);if(!be.existsSync(C)&&!g._layerPageDirs?.some((A)=>be.existsSync(A)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${C}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=j(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[C,...g._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${C}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let B=g?._pluginPageDirs||[],_=[];for(let{dir:A,prefix:z}of B)if(be.existsSync(A)){let N=j(te.dirname(A),{pagesDir:te.basename(A)});for(let V of N){let xe=z==="/"?V.pattern:`${z}${V.pattern==="/"?"":V.pattern}`;_.push({route:{...V,pattern:xe},prefix:z})}if(N.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${N.length}${e.blue} routes at ${e.cyan}${z}${e.reset}`)}let I=new Map,E=null,L=null;if(s.stxOptions?.shell!==!1){if(L=await Po(p,s.stxOptions?.shell),L){if(E=await Wr(L,s.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(p,L)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}pt(),await gt(p);let F=ft();if(F.length>0)console.log(`${e.blue}Loaded ${e.bright}${F.length}${e.blue} middleware: ${e.dim}${F.join(", ")}${e.reset}`);let K={},Z=null;try{let{loadStxConfig:A}=await import("./chunk-ev8ma4ph.js"),z=await A(p);if(z?.apiRouter)Z=z?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(z?.apiRoutes){K=z.apiRoutes;let N=Object.keys(K).length;if(N>0)console.log(`${e.blue}Loaded ${e.bright}${N} API route${N>1?"s":""}${e.reset}`)}if(z?.broadcasting?.enabled)try{let{startBroadcasting:N,loadChannels:V}=await import("./chunk-6pg2kxsq.js"),xe=z.broadcasting;await N(xe);let ze=xe.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${ze}/ws${e.reset}`);let qe=te.join(process.cwd(),"channels.ts");if(be.existsSync(qe))try{let ee=await V(qe);console.log(`${e.blue}Loaded ${e.bright}${ee} broadcast channel${ee!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ee){console.warn(`${e.yellow}Failed to load channels.ts: ${ee.message}${e.reset}`)}}catch(N){console.warn(`${e.yellow}Broadcasting failed to start: ${N.message}${e.reset}`)}}catch{}let Te=a(p,"output");be.mkdirSync(Te,{recursive:!0});let me=new Map,Ae=new Set,ne=async(A)=>{let z=Pr(C,A);if(!z)return null;try{let N=await Bun.build({entrypoints:[z],outdir:Te,plugins:[it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!N.success)return null;let V=N.outputs.find((xe)=>xe.path.endsWith(".html"));if(!V)return null;return await Bun.file(V.path).text()}catch{return null}},U=new Map,H=async(A,z)=>{try{let{processDirectives:N,extractVariables:V,defaultConfig:xe,loadStxConfig:ze,injectRouterScript:qe}=await import("./chunk-ev8ma4ph.js"),{checkCache:ee,cacheTemplate:Y,readFileCached:q,templateCache:X}=await import("./chunk-shhtbdnj.js"),we=await ze(p),Ke=(re)=>{if(!re)return re;if(te.isAbsolute(re))return re;return te.resolve(p,re)},M={...xe,...we,...s.stxOptions,autoShell:!0};if(s.debugDirectives)M.debug=!0;M.partialsDir=Ke(M.partialsDir),M.componentsDir=Ke(M.componentsDir),M.layoutsDir=Ke(M.layoutsDir),M.storesDir=Ke(M.storesDir||"stores"),M.cachePath=Ke(M.cachePath)??a(p,"cache");let ge=!z&&!s.profile,se=M.cache!==!1;if(se&&ge){let re=X.get(A.filePath);if(re)try{if((await be.promises.stat(A.filePath)).mtime.getTime()<=re.mtime){let je=!0;for(let Re of re.dependencies){if(!be.existsSync(Re)){je=!1;break}if((await be.promises.stat(Re)).mtime.getTime()>re.mtime){je=!1;break}}if(je){let Re=re.output;if(E)Re=Se(Re,{preserveHead:!0});let ct=U.get(A.filePath);return{route:A,content:Re,status:ct?.status??await pn(A.filePath),headers:ct?.headers}}}}catch{}let Le=await ee(A.filePath,M);if(Le){let Ie=Le;if(E)Ie=Se(Ie,{preserveHead:!0});let je=U.get(A.filePath);return{route:A,content:Ie,status:je?.status??await pn(A.filePath),headers:je?.headers}}}let ue=se?await q(A.filePath):await Bun.file(A.filePath).text(),Ce=Bt(ue),{classifyAllScripts:G}=await import("./chunk-ev8ma4ph.js"),_e=G(ue),Ne=_e.server.map((re)=>re.content),de=ue;for(let re of _e.server)de=de.replace(re.fullTag,"");let pe={__filename:A.filePath,__dirname:te.dirname(A.filePath),__stx_options:M,params:z??{},__stx_runtime_head:{}};for(let re of Ne)try{await V(re,pe,A.filePath)}catch(Le){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",A.filePath,Le?.message||Le)}let We=new Set,De;if(s.profile){let re=performance.now();De=await N(de,pe,A.filePath,M,We);let Le=performance.now()-re,Ie=te.relative(p,A.filePath)||A.filePath;console.log(`[stx:profile] ${Ie} \u2192 ${Le.toFixed(2)}ms`)}else De=await N(de,pe,A.filePath,M,We);if(!E)De=await qe(De,{router:M.router});{let{interpolateScriptExpressions:re}=await import("./chunk-7nthebqr.js");De=De.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Le,Ie,je)=>{if(!/function\s+__stx_setup_/.test(je))return Le;return`<script${Ie}>${re(je,pe)}</script>`})}if(E)De=Se(De,{preserveHead:!0});if(se&&ge)await Y(A.filePath,De,We,M);let{extractStreamBoundaries:Vn}=await import("./chunk-p8ndfekp.js"),nt=Vn(pe),at=pe.__streamTemplates;if(at&&typeof at==="object"&&Object.keys(at).length>0){let re=pe.streamBoundaries||{},Le={...M,autoShell:!1},Ie=Object.keys(at).map((Re)=>({id:Re,render:async()=>{let ct=typeof re[Re]==="function"?await re[Re]():void 0;return N(at[Re],{...pe,$boundary:ct},A.filePath,Le,new Set)}})),je=new Set(Ie.map((Re)=>Re.id));nt=[...(nt||[]).filter((Re)=>!je.has(Re.id)),...Ie]}if(nt&&nt.length>0)Ae.add(A.pattern);else nt=void 0;let qt=Ye(pe),Kt=Ze(pe);if(ge)U.set(A.filePath,{status:qt,headers:Kt});return{route:A,content:De,status:qt??Ce,headers:Kt,boundaries:nt}}catch(N){return console.error(`${e.red}Error building ${e.bright}${A.pattern}${e.reset}:`,N),null}},Be=8,Ue=async()=>{me.clear(),I.clear();for(let A=0;A<k.length;A+=Be){let z=k.slice(A,A+Be),N=await Promise.all(z.map((V)=>H(V)));for(let V of N)if(V)me.set(V.route.pattern,V)}for(let A=0;A<_.length;A+=Be){let z=_.slice(A,A+Be),N=await Promise.all(z.map(({route:V})=>H(V)));for(let V of N)if(V)I.set(V.route.pattern,V)}return me.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await Ue())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await jt(p);let et=i;try{if(et=await Xe(i),et!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${et} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let A=s.hmrPort||et+1;l=Et({wsPort:A,verbose:!1}),m=l.start(A)}let At=(A,z)=>{let V=`<script data-stx-route-params>(function(){var p=${JSON.stringify(z).replace(/</g,"\\u003C").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;if(A.includes("</head>"))return A.replace("</head>",`${V}</head>`);if(A.includes("<body"))return A.replace(/<body([^>]*)>/,`<body$1>${V}`);return V+A};console.log(`${e.blue}Starting server...${e.reset}`);let Dt=Yr({port:et,async fetch(A){let z=new URL(A.url),N=g?.publicDir||"public",V=te.join(p,N,z.pathname),xe=te.join(p,z.pathname),ze=te.join(Te,z.pathname);if([V,xe,ze].some((M)=>w(M,p,S)))return new Response("Not Found",{status:404});let[qe,ee,Y]=await Promise.all([be.promises.stat(V).catch(()=>null),be.promises.stat(xe).catch(()=>null),be.promises.stat(ze).catch(()=>null)]);if(qe?.isFile()&&!w(V,p,S))return Nt(V);if(ee?.isFile()&&!w(xe,p,S))return Nt(xe);if(Y?.isFile()&&!w(ze,p,S))return Nt(ze);if(z.pathname.startsWith("/_stx/component/")){let M=decodeURIComponent(z.pathname.slice(16));if(M)try{let ge=`<${M} />`,se={...buildConfig,autoShell:!1},ue=await processDirectives(ge,{},te.join(p,"components",`${M}.stx`),se,new Set);return new Response(ue,{headers:{"Content-Type":"text/html"}})}catch(ge){return new Response(`<div class="stx-async-error">${ge.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(z.pathname==="/_stx/img"){let{handleImageRequest:M}=await import("./chunk-qzy34xmt.js"),ge=await M(A,{publicDir:te.join(p,N),cacheDir:a(p,"cache","img")});if(ge)return ge}if(Z)try{let M=await Z.handleRequest(A);if(M.status!==404)return M}catch{}if(K[z.pathname])try{return await K[z.pathname](A)}catch(M){return new Response(JSON.stringify({error:M.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await R(A);if(q)return q;let X=zn(z.pathname,k);if(X){let M=me.get(X.route.pattern),ge=Ae.has(X.route.pattern);if(X.route.isDynamic&&Object.keys(X.params).length>0||ge){let se=await H(X.route,X.params);if(se)M=se}if(M){let se=M.status??200,ue=M.headers??{},Ce=(X.route.filePath?Je(await Bun.file(X.route.filePath).text().catch(()=>"")):null)??{};if(Ce.validate){if(!await Ce.validate({params:X.params})){let Ne=await ne(404);if(Ne){let de=Ne;if(de=await f(de,p),c)de=Ve(de,m);return new Response(de,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(Ce.middleware){let _e=mt(z.pathname,X.params,Ce,z.search),Ne=ht(_e,null,A,{isServer:!0}),de=await yt(Ce.middleware,Ne);if(de.redirect){let pe=de.redirect.path,We=de.redirect.options.redirectCode||302,De=new Headers(de.responseHeaders);return De.set("Location",pe),new Response(null,{status:We,headers:De})}if(de.abort){let{statusCode:pe,message:We}=de.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${pe}</title></head><body><h1>Error ${pe}</h1><p>${We}</p></body></html>`,{status:pe,headers:{"Content-Type":"text/html"}})}if(Object.keys(de.state).length>0){let pe=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(de.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;M.content=M.content.replace("</head>",`${pe}</head>`)}}let G=M.content;if(E&&Io(A)){let _e=Oe(G),Ne=he(G),de=G.match(/<title[^>]*>([\s\S]*?)<\/title>/i),pe=de?Ao(de[1].trim()):"";if(Object.keys(X.params).length>0)G=At(G,X.params);G=await f(G,p);let We=g?.router?.container||"main";return G=le(G,We),new Response(G,{status:se,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":_e.layout,"X-STX-Layout-Group":_e.group,"X-STX-Runtime":Ne?"true":"false",...pe&&{"X-STX-Title":encodeURIComponent(pe)},[Di]:js(),...T(),"Cache-Control":Fe}})}if(E)G=Jn(E,G);if(Object.keys(X.params).length>0)G=At(G,X.params);if(G=await f(G,p),c)G=Ve(G,m);if(s.native)if(G.includes("<head>"))G=G.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 G="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+G;if(s.titlebarHidden)if(G.includes("<head>"))G=G.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 G=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${G}`;if(M.boundaries&&M.boundaries.length>0){let{renderStreamingPage:_e,streamToResponse:Ne}=await import("./chunk-p8ndfekp.js");return Ne(_e(G,M.boundaries,{timeoutMs:30000}),{status:se,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(G,{status:se,headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ue}})}}if(_.length>0){let M=_.map((se)=>se.route),ge=zn(z.pathname,M);if(ge){let se=I.get(ge.route.pattern);if(se){let ue=se.content;if(E)ue=Jn(E,ue);if(Object.keys(ge.params).length>0)ue=At(ue,ge.params);if(ue=await f(ue,p),c)ue=Ve(ue,m);return new Response(ue,{status:se.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:se}of B)if(se!=="/"&&z.pathname.startsWith(se)){let ue=I.get(se)||I.get(se+"/");if(ue){let Ce=ue.content;if(E)Ce=Jn(E,Ce);if(Ce=await f(Ce,p),c)Ce=Ve(Ce,m);return new Response(Ce,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(dt(z.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let we=me.get("/");if(we){let M=we.content;if(M=await f(M,p),c)M=Ve(M,m);if(s.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 Ke=await ne(404);if(Ke){let M=Ke;if(M=await f(M,p),c)M=Ve(M,m);return new Response(M,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(A){let z=await ne(500);if(z)return new Response(z,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${A}
|
|
1429
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(w.url.toString(),()=>{if(d)Je.watch(l,{recursive:!0}).close();w.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Je.watch(l,{recursive:!0},async(x,C)=>{if(!C)return;if(C.endsWith(".stx")||C.endsWith(".js")||C.endsWith(".ts")||C.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${C}${e.yellow} changed, rebuilding...${e.reset}`),Re.clear(),ie(),await h()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function ln(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Yr}=globalThis.Bun;import he from"fs";import te from"path";async function pn(t){try{return Ft(await Bun.file(t).text())}catch{return}}function Nt(t){let s=Bun.file(t),i=te.extname(t).toLowerCase(),d={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":d[i]||"application/octet-stream",...l}})}async function Gn(t=".",s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=te.resolve(t),{loadStxConfig:h}=await import("./chunk-qxjfvkjt.js"),g=await h(p),{createServerApi:y,isServerApiSource:w}=await import("./chunk-b1ndskw9.js"),S=s.stxOptions?.serverApi??g.serverApi,R=await y(p,S),v=g.root&&g.root!=="."?te.join(p,g.root):p,x=s.pagesDir||g.pagesDir||"pages",C=te.join(v,x);if(!he.existsSync(C)&&!g._layerPageDirs?.some((A)=>he.existsSync(A)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${C}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=j(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[C,...g._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${C}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let B=g?._pluginPageDirs||[],_=[];for(let{dir:A,prefix:z}of B)if(he.existsSync(A)){let N=j(te.dirname(A),{pagesDir:te.basename(A)});for(let V of N){let xe=z==="/"?V.pattern:`${z}${V.pattern==="/"?"":V.pattern}`;_.push({route:{...V,pattern:xe},prefix:z})}if(N.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${N.length}${e.blue} routes at ${e.cyan}${z}${e.reset}`)}let I=new Map,E=null,L=null;if(s.stxOptions?.shell!==!1){if(L=await Io(p,s.stxOptions?.shell),L){if(E=await qr(L,s.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(p,L)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}ft(),await mt(p);let F=gt();if(F.length>0)console.log(`${e.blue}Loaded ${e.bright}${F.length}${e.blue} middleware: ${e.dim}${F.join(", ")}${e.reset}`);let K={},Z=null;try{let{loadStxConfig:A}=await import("./chunk-qxjfvkjt.js"),z=await A(p);if(z?.apiRouter)Z=z?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(z?.apiRoutes){K=z.apiRoutes;let N=Object.keys(K).length;if(N>0)console.log(`${e.blue}Loaded ${e.bright}${N} API route${N>1?"s":""}${e.reset}`)}if(z?.broadcasting?.enabled)try{let{startBroadcasting:N,loadChannels:V}=await import("./chunk-4xeafdr6.js"),xe=z.broadcasting;await N(xe);let Be=xe.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Be}/ws${e.reset}`);let qe=te.join(process.cwd(),"channels.ts");if(he.existsSync(qe))try{let ee=await V(qe);console.log(`${e.blue}Loaded ${e.bright}${ee} broadcast channel${ee!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ee){console.warn(`${e.yellow}Failed to load channels.ts: ${ee.message}${e.reset}`)}}catch(N){console.warn(`${e.yellow}Broadcasting failed to start: ${N.message}${e.reset}`)}}catch{}let Te=a(p,"output");he.mkdirSync(Te,{recursive:!0});let me=new Map,Oe=new Set,ne=async(A)=>{let z=Ir(C,A);if(!z)return null;try{let N=await Bun.build({entrypoints:[z],outdir:Te,plugins:[it],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!N.success)return null;let V=N.outputs.find((xe)=>xe.path.endsWith(".html"));if(!V)return null;return await Bun.file(V.path).text()}catch{return null}},U=new Map,H=async(A,z)=>{try{let{processDirectives:N,extractVariables:V,defaultConfig:xe,loadStxConfig:Be,injectRouterScript:qe}=await import("./chunk-qxjfvkjt.js"),{checkCache:ee,cacheTemplate:Y,readFileCached:q,templateCache:X}=await import("./chunk-q4hmgj72.js"),we=await Be(p),Ke=(re)=>{if(!re)return re;if(te.isAbsolute(re))return re;return te.resolve(p,re)},M={...xe,...we,...s.stxOptions,autoShell:!0};if(s.debugDirectives)M.debug=!0;M.partialsDir=Ke(M.partialsDir),M.componentsDir=Ke(M.componentsDir),M.layoutsDir=Ke(M.layoutsDir),M.storesDir=Ke(M.storesDir||"stores"),M.cachePath=Ke(M.cachePath)??a(p,"cache");let ge=!z&&!s.profile,se=M.cache!==!1;if(se&&ge){let re=X.get(A.filePath);if(re)try{if((await he.promises.stat(A.filePath)).mtime.getTime()<=re.mtime){let Ie=!0;for(let Ce of re.dependencies){if(!he.existsSync(Ce)){Ie=!1;break}if((await he.promises.stat(Ce)).mtime.getTime()>re.mtime){Ie=!1;break}}if(Ie){let Ce=re.output;if(E)Ce=ke(Ce,{preserveHead:!0});let ct=U.get(A.filePath);return{route:A,content:Ce,status:ct?.status??await pn(A.filePath),headers:ct?.headers}}}}catch{}let _e=await ee(A.filePath,M);if(_e){let Le=_e;if(E)Le=ke(Le,{preserveHead:!0});let Ie=U.get(A.filePath);return{route:A,content:Le,status:Ie?.status??await pn(A.filePath),headers:Ie?.headers}}}let ue=se?await q(A.filePath):await Bun.file(A.filePath).text(),$e=Ft(ue),{classifyAllScripts:G}=await import("./chunk-qxjfvkjt.js"),Me=G(ue),Fe=Me.server.map((re)=>re.content),de=ue;for(let re of Me.server)de=de.replace(re.fullTag,"");let pe={__filename:A.filePath,__dirname:te.dirname(A.filePath),__stx_options:M,params:z??{},__stx_runtime_head:{}};for(let re of Fe)try{await V(re,pe,A.filePath)}catch(_e){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",A.filePath,_e?.message||_e)}let We=new Set,Ae;if(s.profile){let re=performance.now();Ae=await N(de,pe,A.filePath,M,We);let _e=performance.now()-re,Le=te.relative(p,A.filePath)||A.filePath;console.log(`[stx:profile] ${Le} \u2192 ${_e.toFixed(2)}ms`)}else Ae=await N(de,pe,A.filePath,M,We);if(!E)Ae=await qe(Ae,{router:M.router});{let{interpolateScriptExpressions:re}=await import("./chunk-mfwrxz9z.js");Ae=Ae.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(_e,Le,Ie)=>{if(!/function\s+__stx_setup_/.test(Ie))return _e;return`<script${Le}>${re(Ie,pe)}</script>`})}if(E)Ae=ke(Ae,{preserveHead:!0});if(se&&ge)await Y(A.filePath,Ae,We,M);let{extractStreamBoundaries:Un}=await import("./chunk-g039c67x.js"),nt=Un(pe),at=pe.__streamTemplates;if(at&&typeof at==="object"&&Object.keys(at).length>0){let re=pe.streamBoundaries||{},_e={...M,autoShell:!1},Le=Object.keys(at).map((Ce)=>({id:Ce,render:async()=>{let ct=typeof re[Ce]==="function"?await re[Ce]():void 0;return N(at[Ce],{...pe,$boundary:ct},A.filePath,_e,new Set)}})),Ie=new Set(Le.map((Ce)=>Ce.id));nt=[...(nt||[]).filter((Ce)=>!Ie.has(Ce.id)),...Le]}if(nt&&nt.length>0)Oe.add(A.pattern);else nt=void 0;let qt=Ze(pe),Xt=Qe(pe);if(ge)U.set(A.filePath,{status:qt,headers:Xt});return{route:A,content:Ae,status:qt??$e,headers:Xt,boundaries:nt}}catch(N){return console.error(`${e.red}Error building ${e.bright}${A.pattern}${e.reset}:`,N),null}},He=8,Ue=async()=>{me.clear(),I.clear();for(let A=0;A<k.length;A+=He){let z=k.slice(A,A+He),N=await Promise.all(z.map((V)=>H(V)));for(let V of N)if(V)me.set(V.route.pattern,V)}for(let A=0;A<_.length;A+=He){let z=_.slice(A,A+He),N=await Promise.all(z.map(({route:V})=>H(V)));for(let V of N)if(V)I.set(V.route.pattern,V)}return me.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await Ue())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await Bt(p);let et=i;try{if(et=await Xe(i),et!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${et} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let A=s.hmrPort||et+1;l=Et({wsPort:A,verbose:!1}),m=l.start(A)}let At=(A,z)=>{let V=`<script data-stx-route-params>(function(){var p=${JSON.stringify(z).replace(/</g,"\\u003C").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;if(A.includes("</head>"))return A.replace("</head>",`${V}</head>`);if(A.includes("<body"))return A.replace(/<body([^>]*)>/,`<body$1>${V}`);return V+A};console.log(`${e.blue}Starting server...${e.reset}`);let Dt=Yr({port:et,async fetch(A){let z=new URL(A.url),N=g?.publicDir||"public",V=te.join(p,N,z.pathname),xe=te.join(p,z.pathname),Be=te.join(Te,z.pathname);if([V,xe,Be].some((M)=>w(M,p,S)))return new Response("Not Found",{status:404});let[qe,ee,Y]=await Promise.all([he.promises.stat(V).catch(()=>null),he.promises.stat(xe).catch(()=>null),he.promises.stat(Be).catch(()=>null)]);if(qe?.isFile()&&!w(V,p,S))return Nt(V);if(ee?.isFile()&&!w(xe,p,S))return Nt(xe);if(Y?.isFile()&&!w(Be,p,S))return Nt(Be);if(z.pathname.startsWith("/_stx/component/")){let M=decodeURIComponent(z.pathname.slice(16));if(M)try{let ge=`<${M} />`,se={...buildConfig,autoShell:!1},ue=await processDirectives(ge,{},te.join(p,"components",`${M}.stx`),se,new Set);return new Response(ue,{headers:{"Content-Type":"text/html"}})}catch(ge){return new Response(`<div class="stx-async-error">${ge.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(z.pathname==="/_stx/img"){let{handleImageRequest:M}=await import("./chunk-ptjz4f2e.js"),ge=await M(A,{publicDir:te.join(p,N),cacheDir:a(p,"cache","img")});if(ge)return ge}if(Z)try{let M=await Z.handleRequest(A);if(M.status!==404)return M}catch{}if(K[z.pathname])try{return await K[z.pathname](A)}catch(M){return new Response(JSON.stringify({error:M.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await R(A);if(q)return q;let X=Hn(z.pathname,k);if(X){let M=me.get(X.route.pattern),ge=Oe.has(X.route.pattern);if(X.route.isDynamic&&Object.keys(X.params).length>0||ge){let se=await H(X.route,X.params);if(se)M=se}if(M){let se=M.status??200,ue=M.headers??{},$e=(X.route.filePath?Ye(await Bun.file(X.route.filePath).text().catch(()=>"")):null)??{};if($e.validate){if(!await $e.validate({params:X.params})){let Fe=await ne(404);if(Fe){let de=Fe;if(de=await f(de,p),c)de=Ve(de,m);return new Response(de,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if($e.middleware){let Me=ht(z.pathname,X.params,$e,z.search),Fe=yt(Me,null,A,{isServer:!0}),de=await bt($e.middleware,Fe);if(de.redirect){let pe=de.redirect.path,We=de.redirect.options.redirectCode||302,Ae=new Headers(de.responseHeaders);return Ae.set("Location",pe),new Response(null,{status:We,headers:Ae})}if(de.abort){let{statusCode:pe,message:We}=de.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${pe}</title></head><body><h1>Error ${pe}</h1><p>${We}</p></body></html>`,{status:pe,headers:{"Content-Type":"text/html"}})}if(Object.keys(de.state).length>0){let pe=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(de.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;M.content=M.content.replace("</head>",`${pe}</head>`)}}let G=M.content;if(E&&Oo(A)){let Me=Ne(G),Fe=ye(G),de=G.match(/<title[^>]*>([\s\S]*?)<\/title>/i),pe=de?Po(de[1].trim()):"";if(Object.keys(X.params).length>0)G=At(G,X.params);G=await f(G,p);let We=g?.router?.container||"main";return G=le(G,We),new Response(G,{status:se,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Me.layout,"X-STX-Layout-Group":Me.group,"X-STX-Runtime":Fe?"true":"false",...pe&&{"X-STX-Title":encodeURIComponent(pe)},[Mi]:Bs(),...T(),"Cache-Control":ze}})}if(E)G=Yn(E,G);if(Object.keys(X.params).length>0)G=At(G,X.params);if(G=await f(G,p),c)G=Ve(G,m);if(s.native)if(G.includes("<head>"))G=G.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 G="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+G;if(s.titlebarHidden)if(G.includes("<head>"))G=G.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 G=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${G}`;if(M.boundaries&&M.boundaries.length>0){let{renderStreamingPage:Me,streamToResponse:Fe}=await import("./chunk-g039c67x.js");return Fe(Me(G,M.boundaries,{timeoutMs:30000}),{status:se,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(G,{status:se,headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ue}})}}if(_.length>0){let M=_.map((se)=>se.route),ge=Hn(z.pathname,M);if(ge){let se=I.get(ge.route.pattern);if(se){let ue=se.content;if(E)ue=Yn(E,ue);if(Object.keys(ge.params).length>0)ue=At(ue,ge.params);if(ue=await f(ue,p),c)ue=Ve(ue,m);return new Response(ue,{status:se.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:se}of B)if(se!=="/"&&z.pathname.startsWith(se)){let ue=I.get(se)||I.get(se+"/");if(ue){let $e=ue.content;if(E)$e=Yn(E,$e);if($e=await f($e,p),c)$e=Ve($e,m);return new Response($e,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(pt(z.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let we=me.get("/");if(we){let M=we.content;if(M=await f(M,p),c)M=Ve(M,m);if(s.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 Ke=await ne(404);if(Ke){let M=Ke;if(M=await f(M,p),c)M=Ve(M,m);return new Response(M,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(A){let z=await ne(500);if(z)return new Response(z,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${A}
|
|
1430
1430
|
${A.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});if(console.clear(),console.log(`
|
|
1431
1431
|
${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
|
|
1432
1432
|
${e.bright}\u2192 ${e.cyan}http://localhost:${et}/${e.reset}`),c)console.log(`${e.dim} HMR: ws://localhost:${m}${e.reset}`);console.log(`
|
|
1433
|
-
${e.yellow}Routes:${e.reset}`);let Mt=[...
|
|
1434
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(Dt.url.toString(),()=>{if(l)lt();Dt.stop()}),s.native){let A,z=te.join(C,"index.stx");if(
|
|
1433
|
+
${e.yellow}Routes:${e.reset}`);let Mt=[...Or(k,p)];for(let{route:A}of _)Mt.push(`${A.pattern}`);if(Mt.forEach((A,z)=>{let V=z===Mt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${V}${e.reset}${A}`)}),console.log(`
|
|
1434
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(Dt.url.toString(),()=>{if(l)lt();Dt.stop()}),s.native){let A,z=te.join(C,"index.stx");if(he.existsSync(z)){let V=await Bun.file(z).text();A=Tt(V)}let N=g?.app?.window??{};await rt(et,{title:g?.app?.head?.title||te.basename(p)||"stx App",width:N.width,height:N.height,darkMode:N.darkMode,hotReload:N.hotReload,titlebarHidden:N.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!A,sidebarConfig:A})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let A=(ee)=>ee.startsWith("public/")||ee.startsWith("public\\"),z=(ee)=>{let Y=ee.toLowerCase();return Y.endsWith(".stx")||Y.endsWith(".html")||Y.endsWith(".md")},N=new Map,V=()=>{let ee=new Set([p,...g._layerGraph?.layers.map((Y)=>Y.root)??[],...g._layerGraph?.configDependencies.map((Y)=>te.dirname(Y))??[]].filter((Y)=>he.existsSync(Y)).map((Y)=>he.realpathSync(Y)));for(let Y of g._layerGraph?.layers??[])for(let q of Object.values(Y.resources)){if(!he.existsSync(q))continue;let X=he.realpathSync(q);if(![...ee].some((we)=>X===we||X.startsWith(`${we}${te.sep}`)))ee.add(X)}for(let[Y,q]of N)if(!ee.has(Y))q.close(),N.delete(Y);for(let Y of ee)if(!N.has(Y)&&he.existsSync(Y))N.set(Y,he.watch(Y,{recursive:!0},(q,X)=>{Be(Y,q,X).catch((we)=>console.error("[stx] Layer rebuild failed:",we))}))},xe=Promise.resolve(),Be=(ee,Y,q)=>(xe=xe.catch(()=>{}).then(()=>qe(ee,Y,q)),xe),qe=async(ee,Y,q)=>{if(!q||Rt(q))return;if(Ct(q)){if(g._layerGraph){let X=await h(p);Object.assign(g,X),k.splice(0,k.length,...j(v,{pagesDir:x,pagesDirs:X._layerPageDirs?[C,...X._layerPageDirs.slice(1)]:void 0})),V()}if(A(q)){if(console.log(`${e.cyan}${q} changed${e.reset}`),c&&l)l.reload(q)}else if(z(q)){console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),Re.clear(),ie();try{let{invalidateFileCache:X,templateCache:we}=await import("./chunk-q4hmgj72.js");X(te.resolve(ee,q)),we.delete(te.resolve(ee,q))}catch{}if(L&&q){if(te.resolve(ee,q)===L||te.basename(L)===q){let we=await qr(L,s.stxOptions||{});if(we)E=we}}if(await Ue(),await _n(p),c&&l)l.reload(q)}else{console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),Re.clear(),ie();try{let{invalidateFileCache:X,templateCache:we}=await import("./chunk-q4hmgj72.js");X(te.resolve(ee,q)),we.delete(te.resolve(ee,q))}catch{}if(await Ue(),c&&l)l.reload(q)}}else if($t(q)){if(console.log(`${e.cyan}CSS ${q} changed${e.reset}`),c&&l)l.updateCss(q)}};V(),process.on("SIGINT",()=>{for(let ee of N.values())ee.close();if(l)lt();Dt.stop(),process.exit(0)})}return!0}import Ut from"fs";import dt from"path";async function Qr(t){try{let i=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!i)return[];let d=i[1],c=[],l=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,m;while((m=l.exec(d))!==null){let p=m[1],h=m[2]||m[3]||m[4];if(!h)continue;let g={name:h},y=p.match(/@type\s+\{([^}]+)\}/i);if(y)g.type=y[1].trim();if(p.match(/@required/i))g.required=!0;let S=p.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)g.default=S[1].trim();let R=p.split(`
|
|
1435
1435
|
`).map((v)=>v.trim().replace(/^\*\s*/,"")).filter((v)=>!v.startsWith("@")&&v.length>0);g.description=R.join(" ").trim(),c.push(g)}if(c.length===0){let p=d.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(p){let g=p[1].split(",").map((y)=>y.trim()).filter(Boolean);for(let y of g){let[w]=y.split(":").map((S)=>S.trim());if(w)c.push({name:w})}}}return c}catch(s){return console.error(`Error extracting props from ${t}:`,s),[]}}async function Zr(t){try{let s=await Bun.file(t).text(),i=s.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||s.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(i)return i[1].split(`
|
|
1436
|
-
`).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function eo(t,s=!1,i){let d=
|
|
1436
|
+
`).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function eo(t,s=!1,i){let d=dt.basename(t,".stx"),c=await Qr(t),l=await Zr(t),m="";if(s&&i)m=`<${i}></${i}>`;else{let p=c.map((h)=>{if(h.type==="boolean")return`:${h.name}="true"`;return`${h.name}="value"`}).join(`
|
|
1437
1437
|
`);m=`<${d}
|
|
1438
1438
|
${p}
|
|
1439
|
-
/>`}return{name:d,path:t,description:l,props:c,example:m,isWebComponent:s,tag:i}}async function un(t){try{if(!await r(t))return console.warn(`Components directory does not exist: ${t}`),[];let s=await
|
|
1439
|
+
/>`}return{name:d,path:t,description:l,props:c,example:m,isWebComponent:s,tag:i}}async function un(t){try{if(!await r(t))return console.warn(`Components directory does not exist: ${t}`),[];let s=await Ut.promises.readdir(t,{withFileTypes:!0}),i=[];for(let d of s){let c=dt.join(t,d.name);if(d.isDirectory()){let l=await un(c);i.push(...l)}else if(d.isFile()&&d.name.endsWith(".stx"))i.push(c)}return i}catch(s){return console.error(`Error finding component files in ${t}:`,s),[]}}async function to(t,s){try{if(!await r(t))return[];let i=await un(t),d=[],c=new Map;if(s?.components?.length)for(let l of s.components)c.set(l.file,l);for(let l of i){let m=c.get(l),p=!!m,h=m?.tag,g=await eo(l,p,h);d.push(g)}return d}catch(i){return console.error("Error generating component docs:",i),[]}}async function no(t){try{if(!await r(t))return[];let s=await Ut.promises.readdir(t,{withFileTypes:!0}),i=[];for(let d of s){if(!d.isFile()||!d.name.endsWith(".stx"))continue;let c=dt.join(t,d.name),l=await Bun.file(c).text(),m=dt.basename(c,".stx"),p=l.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||l.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//),h=p?p[1].split(`
|
|
1440
1440
|
`).map((x)=>x.trim().replace(/^\*\s*/,"")).join(" ").trim():"",g=/@component\(\s*['"]([^'"]+)['"]/g,y=/<([A-Z][a-zA-Z0-9]*|[a-z]+-[a-z0-9-]+)(?:\s[^>]*)?\/?>|\{\{\s*slot\s*\}\}/g,w=new Set,S;while((S=g.exec(l))!==null)w.add(S[1]);while((S=y.exec(l))!==null)if(S[1]&&S[1]!=="slot")w.add(S[1]);let R=/@([a-z]+)(?:\s*\(|\s+|$)/g,v=new Set;while((S=R.exec(l))!==null)v.add(S[1]);i.push({name:m,path:c,description:h,components:[...w],directives:[...v]})}return i}catch(s){return console.error("Error generating template docs:",s),[]}}async function ro(t=[]){try{let s=[{name:"if",description:"Conditionally render content based on a condition",hasEndTag:!0,example:`@if(user.isLoggedIn)
|
|
1441
1441
|
<p>Welcome, {{ user.name }}!</p>
|
|
1442
1442
|
@endif`},{name:"else",description:"Provides an alternative if a condition is not met",hasEndTag:!1,example:`@if(user.isLoggedIn)
|
|
@@ -1570,15 +1570,15 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ge(Dt.
|
|
|
1570
1570
|
<td>@${l.name}</td>
|
|
1571
1571
|
<td>${l.description||"-"}</td>
|
|
1572
1572
|
<td>${l.hasEndTag?"Yes":"No"}</td>
|
|
1573
|
-
</tr>`;c+="</tbody></table>";for(let l of i)if(l.example)c+=`<h3>@${l.name}</h3>`,c+=`<p>${l.description||""}</p>`,c+="<h4>Example</h4>",c+=`<pre><code>${l.example.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}</code></pre>`}return c+="</body></html>",c}function io(t=[],s=[],i=[],d){return JSON.stringify({components:t,templates:s,directives:i,extraContent:d||""},null,2)}async function ao(t){try{let{componentsDir:s,templatesDir:i,webComponentsConfig:d,customDirectives:c,config:l}=t;if(!l.enabled)return!1;let m=l.outputDir||"docs";if(await
|
|
1573
|
+
</tr>`;c+="</tbody></table>";for(let l of i)if(l.example)c+=`<h3>@${l.name}</h3>`,c+=`<p>${l.description||""}</p>`,c+="<h4>Example</h4>",c+=`<pre><code>${l.example.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}</code></pre>`}return c+="</body></html>",c}function io(t=[],s=[],i=[],d){return JSON.stringify({components:t,templates:s,directives:i,extraContent:d||""},null,2)}async function ao(t){try{let{componentsDir:s,templatesDir:i,webComponentsConfig:d,customDirectives:c,config:l}=t;if(!l.enabled)return!1;let m=l.outputDir||"docs";if(await Ut.promises.mkdir(m,{recursive:!0}),console.log("Generating documentation..."),s)console.log(`Components directory: ${s}`);if(i)console.log(`Templates directory: ${i}`);console.log(`Output directory: ${m}`);let p=[];if(l.components!==!1&&s)console.log("Generating component documentation..."),p=await to(s,d),console.log(`Found ${p.length} components`);let h=[];if(l.templates!==!1&&i)console.log("Generating template documentation..."),h=await no(i),console.log(`Found ${h.length} templates`);let g=[];if(l.directives!==!1)console.log("Generating directive documentation..."),g=await ro(c),console.log(`Found ${g.length} directives`);let y=l.format||"markdown",w=l.extraContent,S="",R="";switch(y){case"markdown":S=oo(p,h,g,w),R="md";break;case"html":S=so(p,h,g,w),R="html";break;case"json":S=io(p,h,g,w),R="json";break;default:throw Error(`Unsupported documentation format: ${y}`)}let v=dt.join(m,`stx-docs.${R}`);return await Bun.write(v,S),console.log(`Documentation generated: ${v}`),!0}catch(s){return console.error("Error generating documentation:",s),!1}}async function wo(t){let s={enabled:!0,outputDir:t.output||"docs",format:t.format||"markdown",components:t.components!==!1,templates:t.templates!==!1,directives:t.directives!==!1,extraContent:t.extraContent},i=t.componentsDir||P.componentsDir,d=t.templatesDir||".";return ao({componentsDir:i,templatesDir:d,webComponentsConfig:P.webComponents,customDirectives:P.customDirectives,config:s})}var mn={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0};function jr(t,s={}){let i={...mn,...s};if(t.trim()==="")return`
|
|
1574
1574
|
`;let d=t;if(i.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=po(d,i),d=go(d,i),d=uo(d,i),i.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,""),d=d.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(d=d.replace(/\r\n/g,`
|
|
1575
1575
|
`).replace(/\r/g,`
|
|
1576
1576
|
`),!d.endsWith(`
|
|
1577
1577
|
`))d+=`
|
|
1578
|
-
`;return d}function
|
|
1578
|
+
`;return d}function xo(t,s={}){let i={...mn,...s};if(t.trim()==="")return`
|
|
1579
1579
|
`;let d=t;if(d=d.replace(/^( *)```(html|stx)\n([\s\S]*?)^( *)```/gm,(c,l,m,p,h)=>{let g=p.split(`
|
|
1580
1580
|
`),y=g.filter((x)=>x.trim().length>0);if(y.length===0)return c;let w=Math.min(...y.map((x)=>{let C=x.match(/^( *)/);return C?C[1].length:0})),S=g.map((x)=>{if(x.trim().length===0)return"";return x.substring(w)}).join(`
|
|
1581
|
-
`),v=
|
|
1581
|
+
`),v=jr(S,i).trimEnd().split(`
|
|
1582
1582
|
`).map((x)=>{if(x.trim().length===0)return"";return l+x}).join(`
|
|
1583
1583
|
`);return`${l}\`\`\`${m}
|
|
1584
1584
|
${v}
|
|
@@ -1603,7 +1603,7 @@ ${m}`}),s=s.replace(/(<\/[^>]+>)(?=<|$)/g,(c,l,m,p)=>{let h=p.substring(Math.max
|
|
|
1603
1603
|
`),s=s.replace(/^\n+/,"").replace(/\n+$/,""),s}function po(t,s){let d=lo(t).split(`
|
|
1604
1604
|
`),c=[],l=0,m=!1,p=s.useTabs?"\t":" ".repeat(s.indentSize);for(let h=0;h<d.length;h++){let g=d[h],y=g.trim();if(y===""){c.push("");continue}let w=y.match(/<script\b/i),S=y.match(/<\/script>/i);if(m&&!S){c.push(g);continue}let R=y===">";if(fn(y)&&!y.startsWith("<")&&!y.startsWith("@")){c.push(p.repeat(l)+y);continue}let v=y.startsWith("@end"),x=y.startsWith("@else")||y.startsWith("@elseif"),C=y.startsWith("@")&&mo(y),k=y.startsWith("<!DOCTYPE")||y.startsWith("<!doctype"),B=y.startsWith("<!--"),_=y.startsWith("</"),I=y.startsWith("<")&&!_&&!B&&!k,E=y.includes("/>")||fo(y),L=fn(y);if(_||v)l=Math.max(0,l-1);let F=x?Math.max(0,l-1):l;if(R)c.push(g);else c.push(p.repeat(F)+y);if(I&&!E&&!L&&!R||C)l++;if(w)m=!0;if(S)m=!1}return c.join(`
|
|
1605
1605
|
`)}function uo(t,s){if(t=t.replace(/@(if|elseif|foreach|for|while)\s*\(\s*([^)]+)\s*\)/g,(i,d,c)=>{let l=c.trim().replace(/\s+/g," ");return`@${d}(${l})`}),t=t.replace(/@(csrf|method)\s*\(\s*([^)]*)\s*\)/g,(i,d,c)=>{if(c.trim()==="")return`@${d}`;return`@${d}(${c.trim()})`}),s.normalizeWhitespace)t=t.replace(/\{\{\s*([^}]+)\s*\}\}/g,(i,d)=>`{{ ${d.trim()} }}`),t=t.replace(/\{!!\s*([^!]+)\s*!!\}/g,(i,d)=>`{!! ${d.trim()} !!}`);return t}function fo(t){let s=["br","hr","img","input","meta","link","area","base","col","embed","source","track","wbr"];if(t.includes("/>"))return!0;let i=t.match(/<(\w+)/);if(i){let d=i[1];return s.includes(d.toLowerCase())}return!1}function fn(t){return/<(\w+)(?:\s[^>]*)?>[\s\S]*?<\/\1>/.test(t)}function mo(t){let s=["if","unless","foreach","for","while","section","push","component","slot","markdown","wrap","error"];for(let i of s)if(t.startsWith(`@${i}`))return!t.includes(`@end${i}`);return!1}function go(t,s){if(!s.sortAttributes)return t;return t.replace(/<(\w+)([^>]*)>/g,(i,d,c)=>{if(!c.trim())return i;if(c.includes("<")||c.includes(`
|
|
1606
|
-
`)||c.includes("@"))return i;let l=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,m=[],p;while((p=l.exec(c))!==null)m.push({name:p[1],value:p[2]});m.sort((g,y)=>{if(g.name==="id")return-1;if(y.name==="id")return 1;if(g.name==="class")return-1;if(y.name==="class")return 1;return g.name.localeCompare(y.name)});let h=m.map((g)=>g.value?`${g.name}=${g.value}`:g.name).join(" ");return`<${d}${h?` ${h}`:""}>`})}import gn from"fs";import Vt from"path";async function
|
|
1606
|
+
`)||c.includes("@"))return i;let l=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,m=[],p;while((p=l.exec(c))!==null)m.push({name:p[1],value:p[2]});m.sort((g,y)=>{if(g.name==="id")return-1;if(y.name==="id")return 1;if(g.name==="class")return-1;if(y.name==="class")return 1;return g.name.localeCompare(y.name)});let h=m.map((g)=>g.value?`${g.name}=${g.value}`:g.name).join(" ");return`<${d}${h?` ${h}`:""}>`})}import gn from"fs";import Vt from"path";async function So(t="index.stx",s={}){try{let i=s.force||!1,d=Vt.resolve(process.cwd(),t);if(await Bun.file(d).exists()){if(!i)throw Error(`File ${t} already exists. Use --force to overwrite.`);console.warn(`File ${t} already exists. Overwriting...`)}let c=Vt.dirname(d);if(!gn.existsSync(c))gn.mkdirSync(c,{recursive:!0});let l;if(s.template){let m=Vt.resolve(process.cwd(),s.template);if(!await Bun.file(m).exists())throw Error(`Template file ${s.template} does not exist.`);if(!m.endsWith(".stx"))console.warn(`Warning: Template file ${s.template} does not have a .stx extension. Using it anyway.`);l=await Bun.file(m).text(),console.warn(`Using template from ${s.template}`)}else if(s.preset)l=hn(s.preset),console.warn(`Using '${s.preset}' preset template`);else l=hn("basic");return await Bun.write(d,l),console.warn(`Created new stx file: ${t}`),!0}catch(i){return console.error(`Error creating file: ${i instanceof Error?i.message:String(i)}`),!1}}function hn(t){switch(t){case"basic":return yn();case"component":return ho();case"layout":return To();case"blog":return $o();case"api":return Co();case"app":return Ro();default:return yn()}}function yn(){return`<script>
|
|
1607
1607
|
const title = "My stx Page"
|
|
1608
1608
|
const description = "A page built with stx"
|
|
1609
1609
|
const features = [
|
|
@@ -1628,7 +1628,7 @@ const features = [
|
|
|
1628
1628
|
</div>
|
|
1629
1629
|
@endforeach
|
|
1630
1630
|
</main>
|
|
1631
|
-
@endsection`}function
|
|
1631
|
+
@endsection`}function ho(){return`{{-- Component: Card --}}
|
|
1632
1632
|
{{-- Props: title, variant, collapsible --}}
|
|
1633
1633
|
{{-- Usage: @component('card', { title: "Hello", variant: "primary", collapsible: true }) Content @endcomponent --}}
|
|
1634
1634
|
<script>
|
|
@@ -2029,5 +2029,5 @@ const features = [
|
|
|
2029
2029
|
})();
|
|
2030
2030
|
</script>
|
|
2031
2031
|
</body>
|
|
2032
|
-
</html>`}var
|
|
2033
|
-
`)}export{
|
|
2032
|
+
</html>`}var ko="f9c3713";function ma(t){return t}function ha(t){return t}function yo(t,s){let i=[],d=`${s}=`;for(let c=0;c<t.length;c++){let l=t[c];if(l.startsWith(d)){let m=l.slice(d.length);if(m)i.push(m);continue}if(l===s){let m=t[c+1];if(m!==void 0&&!m.startsWith("-"))i.push(m),c++}}return i}import De from"fs";import Se from"path";function Rn(t){try{return De.statSync(t).mtimeMs}catch{return null}}function Ot(t,s){let i=Math.max(0,Math.round((s-t)/1000));if(i<60)return`${i}s ago`;if(i<3600)return`${Math.round(i/60)}m ago`;return`${Math.round(i/3600)}h ago`}function Ai(t,s){try{return globalThis.Bun?.resolveSync(t,s)??null}catch{return null}}function En(t,s="stx"){let i=Se.resolve(t);for(let d=0;d<10;d++){let c=Se.join(i,"pantry","@stacksjs",s);if(De.existsSync(c))return c;let l=Se.dirname(i);if(l===i)break;i=l}return null}var Pn=["@stacksjs/stx","bun-plugin-stx"];function Di(t){try{let s=De.readFileSync(Se.join(t,"package.json"),"utf8"),i=JSON.parse(s)?.version;return typeof i==="string"?i:null}catch{return null}}function _i(t,s=6){let i=Se.resolve(t),d=[],c=new Set;function l(p,h){if(h>s)return;let g;try{g=De.realpathSync(p)}catch{return}if(c.has(g))return;c.add(g);for(let w of Pn){let S=Se.join(p,w),R=Di(S);if(R!==null)d.push({name:w,version:R,dir:Se.relative(i,S)||S,nested:h>0})}let y;try{y=De.readdirSync(p,{withFileTypes:!0})}catch{return}for(let w of y){if(!w.isDirectory()&&!w.isSymbolicLink())continue;if(w.name===".bin"||w.name===".cache")continue;let S=Se.join(p,w.name);if(w.name.startsWith("@")){let v;try{v=De.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let x of v){let C=Se.join(S,x.name,"node_modules");if(De.existsSync(C))l(C,h+1)}continue}let R=Se.join(S,"node_modules");if(De.existsSync(R))l(R,h+1)}}let m=Se.join(i,"node_modules");if(De.existsSync(m))l(m,0);return d}function Li(t){let s=[];for(let i of Pn){let d=t.filter((m)=>m.name===i);if(d.length<=1)continue;let c=[...new Set(d.map((m)=>m.version))],l=d.map((m)=>`${m.version} at ${m.dir}`).join("; ");if(c.length===1){s.push({name:`${i} copies`,status:"info",detail:`${d.length} copies, all ${c[0]} \u2014 duplicated but in agreement`});continue}s.push({name:`${i} copies disagree`,status:"error",detail:`${c.length} versions installed, so which one runs depends on who imports it: ${l}`,fix:`remove the nested copies, or add an overrides entry pinning ${i}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${i}/package.json' -exec grep -H '"version"' {} +`})}return s}async function Br(t={}){let s=t.cwd?Se.resolve(t.cwd):process.cwd(),i=t.resolve??Ai,d=Date.now(),c=[],l=i("@stacksjs/stx",s);c.push(l?{name:"@stacksjs/stx resolves to",status:"ok",detail:l}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let m=i("bun-plugin-stx",s);if(m)c.push({name:"bun-plugin-stx resolves to",status:"ok",detail:m});for(let h of Li(_i(s)))c.push(h);let p=En(s,"stx");if(!p)c.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let h=Se.join(p,"src/signals.ts"),g=[Se.join(p,"dist/index.js"),Se.join(p,"dist/signals.js")].find((v)=>De.existsSync(v))||null,y=Rn(h),w=g?Rn(g):null;if(y==null)c.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${p} but no src/signals.ts to compare`});else if(w==null)c.push({name:"pantry dist freshness",status:"error",detail:"pantry has src but no built dist \u2014 the dev server will resolve nothing (or a stale copy elsewhere)",fix:`cd ${p} && bun build.ts`});else if(w<y){let v=Math.round((y-w)/1000);c.push({name:"pantry dist freshness",status:"error",detail:`dist (${Ot(w,d)}) is OLDER than src/signals.ts (${Ot(y,d)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${p} && bun build.ts`})}else c.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Ot(y,d)}, dist ${Ot(w,d)})`});let S=Se.join(s,"node_modules/@stacksjs/stx"),R=null;try{R=De.lstatSync(S)}catch{R=null}if(!R)c.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(R.isSymbolicLink()){let v=null;try{v=De.realpathSync(S)}catch{}let x=(()=>{try{return De.realpathSync(p)}catch{return p}})();c.push(v===x?{name:"node_modules \u2192 pantry",status:"ok",detail:"symlinked to pantry"}:{name:"node_modules \u2192 pantry",status:"warn",detail:`symlinked to ${v||"(dangling)"}, not pantry`})}else c.push({name:"node_modules \u2192 pantry",status:"warn",detail:"is a real directory, NOT symlinked to pantry \u2014 edits to pantry src/dist won't be resolved",fix:"rm -rf node_modules/@stacksjs/stx && ln -s ../../pantry/@stacksjs/stx node_modules/@stacksjs/stx"})}if(c.push({name:"dev runtime cache",status:"info",detail:"cleared automatically on source edits by the dev watcher (clearDevCaches, #1745 item C)"}),t.generateRuntime)try{let g=t.generateRuntime().length;c.push(g>1000?{name:"signals runtime",status:"ok",detail:`generated ${g.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${g} chars \u2014 suspiciously short`})}catch(h){c.push({name:"signals runtime",status:"error",detail:`failed to generate: ${h.message}`})}return{checks:c,ok:!c.some((h)=>h.status==="error")}}function Fr(t){let s={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},i=["stx runtime resolution:"];for(let d of t.checks)if(i.push(` ${s[d.status]} ${d.name}: ${d.detail}`),d.fix)i.push(` \u2192 ${d.fix}`);return i.push(""),i.push(t.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),i.join(`
|
|
2033
|
+
`)}export{yo,bo,vo,wo,jr,xo,So,ko,ma,ha,Br,Fr,Wn,qn,Gn};
|