@stacksjs/stx 0.2.679 → 0.2.682
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-01ks1244.js +2 -0
- package/dist/{chunk-qr7a378v.js → chunk-03xn8244.js} +3 -3
- package/dist/{chunk-ccmc5rqj.js → chunk-0527ytat.js} +2 -2
- package/dist/chunk-0gmwqhs0.js +2 -0
- package/dist/chunk-18jfkg1q.js +2 -0
- package/dist/chunk-1gw26g89.js +31 -0
- package/dist/chunk-1t6dg4s8.js +2 -0
- package/dist/{chunk-n8wvqnfc.js → chunk-1y50gat7.js} +2 -2
- package/dist/chunk-23efje42.js +2 -0
- package/dist/chunk-247fg189.js +2 -0
- package/dist/{chunk-xnx06qqt.js → chunk-2a1eeywj.js} +2 -2
- package/dist/{chunk-hh58k0nh.js → chunk-2ajbhefk.js} +2 -2
- package/dist/{chunk-p9az13b2.js → chunk-2ar5g9pa.js} +2 -2
- package/dist/{chunk-7j7h1eg3.js → chunk-2hh6g3y1.js} +1 -1
- package/dist/chunk-2zepd4ps.js +2 -0
- package/dist/chunk-34ps2w1z.js +2 -0
- package/dist/chunk-3tkag58v.js +2 -0
- package/dist/{chunk-ga5kjf9b.js → chunk-3zbege39.js} +6 -6
- package/dist/{chunk-2933mvwr.js → chunk-42qtadka.js} +10 -10
- package/dist/chunk-47fwr1z7.js +2 -0
- package/dist/{chunk-fzc98qgn.js → chunk-49c5v5fh.js} +6 -6
- package/dist/chunk-4g9wrxkm.js +2 -0
- package/dist/chunk-4m5g3f2b.js +2 -0
- package/dist/{chunk-tx4wfk5v.js → chunk-4z4sqc8q.js} +5 -5
- package/dist/{chunk-6ycyaf5g.js → chunk-58dv14c3.js} +2 -2
- package/dist/{chunk-87em5xdg.js → chunk-5nfb4gxk.js} +82 -82
- package/dist/chunk-5nrqc6v4.js +20 -0
- package/dist/chunk-5rdfcpfe.js +2 -0
- package/dist/{chunk-xyk2zxkk.js → chunk-65jb75vz.js} +2 -2
- package/dist/{chunk-5z8mq37c.js → chunk-6e60jp4a.js} +4 -4
- package/dist/chunk-7jxj6cv1.js +2 -0
- package/dist/{chunk-dnjbzwwn.js → chunk-7yree929.js} +1 -1
- package/dist/chunk-8bwa63m3.js +2 -0
- package/dist/chunk-8d0rqqyx.js +2 -0
- package/dist/chunk-8j0zcyd7.js +2 -0
- package/dist/chunk-8jxqg7kb.js +2 -0
- package/dist/chunk-8nk56cs2.js +2 -0
- package/dist/chunk-8y7tpjfs.js +2 -0
- package/dist/{chunk-q3gactm1.js → chunk-912r15hr.js} +4 -4
- package/dist/chunk-96hkch4q.js +2 -0
- package/dist/{chunk-4fhbh04h.js → chunk-974prn41.js} +4 -4
- package/dist/{chunk-078qg8r5.js → chunk-9bgb9n12.js} +2 -2
- package/dist/chunk-9qx6ansy.js +2 -0
- package/dist/{chunk-tst8p27s.js → chunk-9tg4995v.js} +3 -3
- package/dist/{chunk-sr3hmrah.js → chunk-9wa3t87n.js} +1 -1
- package/dist/{chunk-k06n5bjp.js → chunk-ae12wgc5.js} +3 -3
- package/dist/chunk-b375wt1n.js +2 -0
- package/dist/chunk-b5vqp3b2.js +2 -0
- package/dist/{chunk-vg1pg6yt.js → chunk-b7z6rqfg.js} +1 -1
- package/dist/{chunk-wt7rp7wc.js → chunk-bmqker64.js} +6 -6
- package/dist/{chunk-53e9ta3g.js → chunk-bmv6spcd.js} +4 -4
- package/dist/chunk-bpf3xxng.js +3 -0
- package/dist/{chunk-chy90834.js → chunk-brcj3953.js} +5 -5
- package/dist/chunk-brftzqzj.js +3 -0
- package/dist/chunk-bv43s0gx.js +2 -0
- package/dist/chunk-c9jnkbdb.js +2 -0
- package/dist/{chunk-x7wr720m.js → chunk-d1ssvg9k.js} +5 -5
- package/dist/{chunk-5z0q3qv3.js → chunk-d7js6v1m.js} +5 -5
- package/dist/{chunk-vd5w1jaz.js → chunk-drabexxq.js} +3 -3
- package/dist/{chunk-k72jqz6a.js → chunk-e26pxzjj.js} +2 -2
- package/dist/{chunk-2pvcp0y6.js → chunk-e97xj3rf.js} +6 -6
- package/dist/chunk-ev1tnd36.js +2 -0
- package/dist/{chunk-j388n7v2.js → chunk-f1hxrs7b.js} +17 -17
- package/dist/{chunk-wr1gm35v.js → chunk-f4z9w4kc.js} +1 -1
- package/dist/chunk-f80aqbwm.js +2 -0
- package/dist/chunk-fbbp8j97.js +2 -0
- package/dist/{chunk-26ps9djm.js → chunk-fqts9wvd.js} +5 -5
- package/dist/chunk-fy1waxy0.js +2 -0
- package/dist/chunk-g2v6c7kf.js +2 -0
- package/dist/chunk-g5ep75vp.js +2 -0
- package/dist/{chunk-wejabf6y.js → chunk-g83qeh2x.js} +5 -5
- package/dist/chunk-g9a56wwk.js +2 -0
- package/dist/chunk-gkmh0xys.js +2 -0
- package/dist/{chunk-78yjmbbs.js → chunk-gtktv6nn.js} +2 -2
- package/dist/{chunk-f26n6y9p.js → chunk-gymmbbzc.js} +4 -4
- package/dist/{chunk-48ma0qcr.js → chunk-h3bdqqzy.js} +2 -2
- package/dist/chunk-h5r4c9v5.js +2 -0
- package/dist/{chunk-3xyv2fec.js → chunk-hg7ys8rn.js} +3 -3
- package/dist/{chunk-kxj8e1gd.js → chunk-hm69jxmh.js} +6 -6
- package/dist/{chunk-y4ncmvf2.js → chunk-hwaqwrc2.js} +3 -3
- package/dist/chunk-jecmxby7.js +2 -0
- package/dist/{chunk-a2zb5fgg.js → chunk-jkywbfb0.js} +2 -2
- package/dist/{chunk-haz2ezyk.js → chunk-k3e0hcv7.js} +2 -2
- package/dist/{chunk-drmgwjnb.js → chunk-ka3xmbrd.js} +76 -76
- package/dist/chunk-kerxevf9.js +2 -0
- package/dist/chunk-km37yrk4.js +43 -0
- package/dist/chunk-mdmwgthz.js +2 -0
- package/dist/chunk-myc60z74.js +2 -0
- package/dist/chunk-mzkyw4yx.js +2 -0
- package/dist/{chunk-nb3kkvet.js → chunk-n8jq9yjy.js} +11 -11
- package/dist/{chunk-y34tyrpb.js → chunk-nbjyed3q.js} +7 -7
- package/dist/{chunk-d40zjm6k.js → chunk-np3zdjhr.js} +6 -6
- package/dist/{chunk-wav0xbnb.js → chunk-pfn70zdr.js} +2 -2
- package/dist/{chunk-tbb4en1q.js → chunk-pmma4f1x.js} +4 -4
- package/dist/chunk-pqg3ghvh.js +2 -0
- package/dist/chunk-pvn0fc7j.js +2 -0
- package/dist/{chunk-q4rejyd2.js → chunk-pzxy40a2.js} +2 -2
- package/dist/chunk-q7mpearc.js +2 -0
- package/dist/{chunk-7z7zp8xq.js → chunk-qb806pks.js} +5 -5
- package/dist/{chunk-wscnjtss.js → chunk-qh7fvr2z.js} +2 -2
- package/dist/chunk-r8hszntk.js +2 -0
- package/dist/{chunk-wc5tt6da.js → chunk-remsyfdx.js} +2 -2
- package/dist/chunk-rk8kmshp.js +2 -0
- package/dist/chunk-rs67af2x.js +1592 -0
- package/dist/{chunk-97h9ga3b.js → chunk-rspe6qa5.js} +3 -3
- package/dist/{chunk-78x52gz3.js → chunk-ry501z40.js} +5 -5
- package/dist/chunk-s0wa7zjr.js +2 -0
- package/dist/{chunk-qvefcnyb.js → chunk-se4n8tth.js} +2 -2
- package/dist/chunk-sncp7jhv.js +2 -0
- package/dist/{chunk-jv021x8e.js → chunk-sq4w1e1g.js} +2 -2
- package/dist/chunk-sqvdrk81.js +2 -0
- package/dist/{chunk-9wdd7eq6.js → chunk-t6m5d64b.js} +2 -2
- package/dist/chunk-tdwqwxhf.js +25 -0
- package/dist/{chunk-dera8fmc.js → chunk-tenbwcts.js} +2 -2
- package/dist/chunk-th45zgbz.js +54 -0
- package/dist/{chunk-cxgremn0.js → chunk-tpdvgb3d.js} +1 -1
- package/dist/chunk-tq2m6m3j.js +2 -0
- package/dist/{chunk-aw3jfdca.js → chunk-veh25cv5.js} +1 -1
- package/dist/chunk-vqv5w6gs.js +2 -0
- package/dist/chunk-vt5e25xg.js +2 -0
- package/dist/{chunk-028e9fty.js → chunk-vxnf3xab.js} +2 -2
- package/dist/{chunk-mabja59q.js → chunk-vxrhvrr9.js} +2 -2
- package/dist/{chunk-tmqrbs98.js → chunk-w1wzydvp.js} +8 -5
- package/dist/{chunk-qwdcts9w.js → chunk-w28wc7mv.js} +13 -13
- package/dist/{chunk-yxw8gbnh.js → chunk-wfg5379k.js} +4 -4
- package/dist/chunk-wvz7rp5p.js +2 -0
- package/dist/{chunk-k4x8v39k.js → chunk-xfdfk4g4.js} +2 -2
- package/dist/chunk-xjx1xbey.js +2 -0
- package/dist/{chunk-mn47s2ef.js → chunk-xr9a0hcr.js} +5 -5
- package/dist/{chunk-1b9thkg5.js → chunk-xvnrm5c3.js} +2 -2
- package/dist/{chunk-mf19qxgv.js → chunk-xvs84gas.js} +2 -2
- package/dist/{chunk-8aq07a1j.js → chunk-y55pcfaj.js} +3 -3
- package/dist/{chunk-2hmyj5wh.js → chunk-yhfm939b.js} +2 -2
- package/dist/chunk-ykjzhfyf.js +2 -0
- package/dist/chunk-ypwetty7.js +21 -0
- package/dist/chunk-z4khbpx0.js +2 -0
- package/dist/{chunk-9rs12v0r.js → chunk-z5av310q.js} +9 -9
- package/dist/chunk-zr16mga0.js +2 -0
- package/dist/{chunk-dxh45gve.js → chunk-zt5hp5w5.js} +1 -1
- package/dist/chunk-zwawqx5q.js +2 -0
- package/dist/cli.js +20 -20
- package/dist/client/signals-manifest-hydration-runtime.js +4 -1
- package/dist/component-client-factories.js +14 -3
- package/dist/craft-entry.js +2 -2
- package/dist/craft.js +2 -2
- package/dist/dev-server/serve-app.js +10 -1
- package/dist/pwa.js +3 -3
- package/dist/ssg.js +6 -6
- package/dist/utils.js +13 -1
- package/package.json +5 -5
- package/dist/chunk-0fjwqs9h.js +0 -2
- package/dist/chunk-0gk78x3r.js +0 -2
- package/dist/chunk-0v35wpm7.js +0 -2
- package/dist/chunk-1dkcakve.js +0 -25
- package/dist/chunk-1gg5vxe8.js +0 -2
- package/dist/chunk-1j0sarne.js +0 -21
- package/dist/chunk-248a88mc.js +0 -2
- package/dist/chunk-2nqtmp8c.js +0 -2
- package/dist/chunk-2yzwrvq1.js +0 -2
- package/dist/chunk-3bfegbpw.js +0 -2
- package/dist/chunk-3wsm9g9c.js +0 -2
- package/dist/chunk-3xx9d934.js +0 -2
- package/dist/chunk-52x079ax.js +0 -2
- package/dist/chunk-54zkkxmb.js +0 -2
- package/dist/chunk-5fmxn52y.js +0 -2
- package/dist/chunk-61ww9d2z.js +0 -2
- package/dist/chunk-75zc8w68.js +0 -2
- package/dist/chunk-7b3phzx4.js +0 -2
- package/dist/chunk-8p92r2sc.js +0 -2
- package/dist/chunk-8xr8y9sq.js +0 -2
- package/dist/chunk-909ymsjz.js +0 -2
- package/dist/chunk-ac75vk0w.js +0 -2
- package/dist/chunk-arh1qgmp.js +0 -2
- package/dist/chunk-b0th3d8q.js +0 -888
- package/dist/chunk-bh19ezq0.js +0 -43
- package/dist/chunk-bm42rsaa.js +0 -2
- package/dist/chunk-cfm6a679.js +0 -2
- package/dist/chunk-cwmazy7y.js +0 -2
- package/dist/chunk-e492je6q.js +0 -2
- package/dist/chunk-ft1ht0b3.js +0 -2
- package/dist/chunk-ft3f9nj0.js +0 -2
- package/dist/chunk-ggwvnpwj.js +0 -2
- package/dist/chunk-gx6wxmbv.js +0 -2
- package/dist/chunk-hamk3dky.js +0 -2
- package/dist/chunk-hqj28381.js +0 -3
- package/dist/chunk-k093pr2w.js +0 -2
- package/dist/chunk-kcp392wy.js +0 -2
- package/dist/chunk-kejrhccx.js +0 -2
- package/dist/chunk-kmj127rm.js +0 -2
- package/dist/chunk-kqbpkg8n.js +0 -2
- package/dist/chunk-m0f3strn.js +0 -2
- package/dist/chunk-mjsebtg6.js +0 -2
- package/dist/chunk-n8f0zw1y.js +0 -31
- package/dist/chunk-nadgej53.js +0 -2
- package/dist/chunk-nh3kd03f.js +0 -2
- package/dist/chunk-nw2zh40z.js +0 -2
- package/dist/chunk-p01b07se.js +0 -54
- package/dist/chunk-p99an8rj.js +0 -2
- package/dist/chunk-pgvwysxq.js +0 -2
- package/dist/chunk-pz3mg7hr.js +0 -2
- package/dist/chunk-qyf3jcy1.js +0 -2
- package/dist/chunk-rc79yyqx.js +0 -2
- package/dist/chunk-s8qe247r.js +0 -2
- package/dist/chunk-sswy3tfc.js +0 -2
- package/dist/chunk-swxznm5v.js +0 -2
- package/dist/chunk-t3gmm1ja.js +0 -2
- package/dist/chunk-tsrf4zzy.js +0 -2
- package/dist/chunk-tz09earb.js +0 -2
- package/dist/chunk-vct8a1qf.js +0 -20
- package/dist/chunk-x4q4bx3q.js +0 -3
- package/dist/chunk-xna6b7km.js +0 -2
- package/dist/chunk-xw4rm5zj.js +0 -2
- package/dist/chunk-yar7fwrb.js +0 -2
- package/dist/chunk-yt33wzqk.js +0 -2
- package/dist/chunk-zcbp27x1.js +0 -2
- package/dist/chunk-zq7xbc1k.js +0 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{se,ue,un,At,Pt,g,n,pe,d}from"./chunk-5nfb4gxk.js";import{gt,$e,oa,Lr,to,no,o}from"./chunk-rs67af2x.js";import{ie,fr,xe,D,bn}from"./chunk-w28wc7mv.js";import{vt,tr,ns,rs,ss,wt,xt,St,kt,_t,Ct,Ye}from"./chunk-gymmbbzc.js";import{Jr,i,R}from"./chunk-42qtadka.js";import{ut,Ri,ke,O,Ai,Hs,Pr,Ve,Pi,_e}from"./chunk-1gw26g89.js";import{Zn,Qn}from"./chunk-yhfm939b.js";import{kn}from"./chunk-se4n8tth.js";import{e,nn,Gn,h}from"./chunk-bmqker64.js";import{Ge}from"./chunk-th45zgbz.js";import{Te}from"./chunk-374nhgyf.js";import{q,he,ye}from"./chunk-e97xj3rf.js";import{c}from"./chunk-xvs84gas.js";import{W}from"./chunk-2ajbhefk.js";async function Fn(t){try{let r=await Bun.file(t).text(),s=zn(r),p=Nn(r,t),a=Un(r,s),l=Wn(r,s);return{file:t,metrics:s,issues:p,suggestions:a,performance:l}}catch(r){throw Error(`Failed to analyze template ${t}: ${r instanceof Error?r.message:String(r)}`)}}function zn(t){let r=t.split(`
|
|
3
3
|
`),s=t.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),a=(s?s[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 f=(t.match(/\{\{[\s\S]*?\}\}/g)||[]).length,u=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,y=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,m=f+u+y,b=(t.match(/<[A-Z][^>]*>/g)||[]).length,w=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,C=0;for(let T of r)if(/@(?:if|unless|foreach|for|while|section)\b/.test(T)&&!/@end/.test(T)&&!/@else/.test(T))C++,S=Math.max(S,C);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(T))C--;let v=S>=4?3:0,x=Math.min(10,Math.ceil(l.total*0.5+m*0.1+b*0.3+(a>10?a*0.05:0)+v));return{lines:r.length,characters:t.length,directives:l,expressions:m,components:b,layouts:w,scriptLines:a,complexity:x}}function Nn(t,r){let s=[],p=
|
|
5
|
-
`).filter((b)=>b.length>120);if(y.length>0)s.push({type:"info",category:"maintainability",message:`Found ${y.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let m=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(m>3)s.push({type:"info",category:"maintainability",message:`Found ${m} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return s}function Un(t,r){let s=[];if(r.complexity>7)s.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(r.complexity>5&&r.directives.total>8)s.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(r.lines>100&&r.components===0)s.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(r.expressions>20)s.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let p=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(p&&p.length>0)s.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(r.directives.total===0&&r.expressions<5)s.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(r.scriptLines>50)s.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return s}function Wn(t,r){let s=1;if(s+=r.directives.conditionals*0.1,s+=r.directives.loops*0.5,s+=r.directives.includes*2,s+=r.expressions*0.05,s+=r.components*1,r.scriptLines>10)s+=r.scriptLines*0.1;let p;if(r.expressions===0&&r.directives.total===0)p="high";else if(r.expressions<5&&r.directives.total<3)p="medium";else p="low";let a=[];if(s>10)a.push("Consider optimizing template complexity");if(p==="low"&&r.directives.total>5)a.push("Reduce dynamic content for better caching");if(r.components===0&&r.lines>40)a.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(s*100)/100,complexityScore:r.complexity,cacheability:p,recommendations:a}}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 f=(t.match(/\{\{[\s\S]*?\}\}/g)||[]).length,u=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,y=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,m=f+u+y,b=(t.match(/<[A-Z][^>]*>/g)||[]).length,w=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,C=0;for(let T of r)if(/@(?:if|unless|foreach|for|while|section)\b/.test(T)&&!/@end/.test(T)&&!/@else/.test(T))C++,S=Math.max(S,C);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(T))C--;let v=S>=4?3:0,x=Math.min(10,Math.ceil(l.total*0.5+m*0.1+b*0.3+(a>10?a*0.05:0)+v));return{lines:r.length,characters:t.length,directives:l,expressions:m,components:b,layouts:w,scriptLines:a,complexity:x}}function Nn(t,r){let s=[],p=Kt(t,"if","endif");if(p>0)s.push({type:"error",category:"syntax",message:`Found ${p} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let a=Kt(t,"foreach","endforeach");if(a>0)s.push({type:"error",category:"syntax",message:`Found ${a} 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)s.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let f=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(f>0)s.push({type:"warning",category:"security",message:`Found ${f} raw output expression(s) {!! !!}`,suggestion:"Ensure raw outputs are properly sanitized to prevent XSS"});let u=t.match(/<img[^>]*>/g);if(u){let b=u.filter((w)=>!w.includes("alt="));if(b.length>0)s.push({type:"warning",category:"accessibility",message:`Found ${b.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let y=t.split(`
|
|
5
|
+
`).filter((b)=>b.length>120);if(y.length>0)s.push({type:"info",category:"maintainability",message:`Found ${y.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let m=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(m>3)s.push({type:"info",category:"maintainability",message:`Found ${m} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return s}function Un(t,r){let s=[];if(r.complexity>7)s.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(r.complexity>5&&r.directives.total>8)s.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(r.lines>100&&r.components===0)s.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(r.expressions>20)s.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let p=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(p&&p.length>0)s.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(r.directives.total===0&&r.expressions<5)s.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(r.scriptLines>50)s.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return s}function Wn(t,r){let s=1;if(s+=r.directives.conditionals*0.1,s+=r.directives.loops*0.5,s+=r.directives.includes*2,s+=r.expressions*0.05,s+=r.components*1,r.scriptLines>10)s+=r.scriptLines*0.1;let p;if(r.expressions===0&&r.directives.total===0)p="high";else if(r.expressions<5&&r.directives.total<3)p="medium";else p="low";let a=[];if(s>10)a.push("Consider optimizing template complexity");if(p==="low"&&r.directives.total>5)a.push("Reduce dynamic content for better caching");if(r.components===0&&r.lines>40)a.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(s*100)/100,complexityScore:r.complexity,cacheability:p,recommendations:a}}function Kt(t,r,s){let p=t.replace(/<!--[\s\S]*?-->/g,""),a=(p.match(new RegExp(`@${r}\\b`,"g"))||[]).length,l=(p.match(new RegExp(`@${s}\\b`,"g"))||[]).length;return Math.abs(a-l)}async function yi(t=["**/*.stx"],r){let s=[],p=[];for(let l of t){let f=await Array.fromAsync(new Bun.Glob(l).scan({cwd:r||process.cwd(),onlyFiles:!0,absolute:!0}));p.push(...f.filter((u)=>u.endsWith(".stx")))}for(let l of p)try{let f=await Fn(l);s.push(f)}catch(f){console.warn(`Failed to analyze ${l}:`,f)}let a=Vn(s);return{results:s,summary:a}}function Vn(t){let r=t.length,s=t.reduce((m,b)=>m+b.metrics.lines,0),p=r>0?t.reduce((m,b)=>m+b.metrics.complexity,0)/r:0,a=t.reduce((m,b)=>m+b.issues.length,0),l={};t.forEach((m)=>{m.issues.forEach((b)=>{l[b.category]=(l[b.category]||0)+1})});let f=r>0?t.reduce((m,b)=>m+b.performance.estimatedRenderTime,0)/r:0,u=Math.max(1,Math.min(10,Math.round(10-f/2-p/2))),y=[];if(p>6)y.push("Project has high average complexity. Consider refactoring complex templates.");if(a>r*2)y.push("High number of issues detected. Run detailed analysis on individual files.");if(l.security>0)y.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:r,totalLines:s,avgComplexity:Math.round(p*100)/100,totalIssues:a,issuesByCategory:l,performanceScore:u,recommendations:y}}import{mkdir as qn,readFile as Kn,readdir as Xn,stat as Xt,writeFile as Jn}from"fs/promises";import Ce from"path";function en(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 tn=new Set(["constructor","connectedCallback","disconnectedCallback","attributeChangedCallback","adoptedCallback"]);function Yn(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((r)=>r.charAt(0).toUpperCase()+r.slice(1)).join("")}function jt(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function er(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function nr(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function rr(t){let r=[];async function s(p){let a=await Xn(p,{withFileTypes:!0});a.sort((l,f)=>l.name.localeCompare(f.name));for(let l of a){let f=Ce.join(p,l.name);if(l.isDirectory()){if(!l.name.startsWith(".")&&l.name!=="node_modules")await s(f)}else if(l.isFile()&&l.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(l.name))r.push(f)}}return await s(t),r}function or(t,r){let s=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!s)return{};let p=s[1].trim();if(!p)return{};try{return JSON.parse(p)}catch(a){throw Error(`${r}: <script component> must contain JSON metadata (${a.message})`)}}function sr(t,r){let s={},p=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let a of p){if(!/\bclient\b/i.test(a[1])||/\bcomponent\b|\bstx:component\b/i.test(a[1]))continue;let l;try{l=new Bun.Transpiler({loader:"ts"}).transformSync(a[2])}catch(y){throw Error(`${r}: failed to transpile <script client> (${y.message})`)}let f=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,u;while(u=f.exec(l)){let y=u[1];if(tn.has(y))throw Error(`${r}: client ${en(y)}`);let m=f.lastIndex,b=1,w="",S=!1,C=m;for(;C<l.length&&b>0;C++){let x=l[C];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==="{")b++;else if(x==="}")b--}if(b!==0)throw Error(`${r}: unterminated client function "${y}"`);let v=u[0].includes("async")?"async ":"";s[y]=`${v}${y}(${u[2]}) {${l.slice(m,C-1)}}`,f.lastIndex=C}}return s}function ir(t){let r=t.match(/<template\b(?![^>]*\bshadowrootmode\b)[^>]*>([\s\S]*?)<\/template>/i);return(r?r[1]:t).replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").trim()}function Gt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((r)=>r[1].trim()).filter(Boolean).join(`
|
|
6
6
|
|
|
7
7
|
`)}function ar(t){if(!t)return null;let r=t.replace(/\s*\|\s*(?:undefined|null)\b/g,"").trim();if(/^string$/.test(r))return"string";if(/^number$/.test(r))return"number";if(/^boolean$/.test(r))return"boolean";if(/^(?:'[^']*'|"[^"]*")(?:\s*\|\s*(?:'[^']*'|"[^"]*"))*$/.test(r))return"string";return"object"}function cr(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 lr(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 dr(t){let r=[],s=0,p=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),a=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,l,f=(y)=>{if(p[y]!=="(")return null;let m=0,b="";for(let w=y;w<p.length;w++){let S=p[w];if(b!==""){if(S==="\\")w++;else if(S===b)b="";continue}if(S==="'"||S==='"'||S==="`"){b=S;continue}if(S==="(")m++;else if(S===")"){if(m--,m===0)return{expression:p.slice(y+1,w),end:w+1}}}return null},u=(y)=>{if(y==="")return;let m=0,b=/\{!!\s*([\s\S]*?)\s*!!\}|\{\{\s*([\s\S]*?)\s*\}\}/g,w;while(w=b.exec(y)){if(w.index>m)r.push(`out += ${JSON.stringify(y.slice(m,w.index))};`);r.push(w[1]!==void 0?`out += __raw(${w[1]});`:`out += __escape(${w[2]});`),m=w.index+w[0].length}if(m<y.length)r.push(`out += ${JSON.stringify(y.slice(m))};`)};while(l=a.exec(p)){u(p.slice(s,l.index)),s=l.index+l[0].length;let m=l[1]==="if"||l[1]==="elseif"||l[1]==="foreach"?f(s):null;if(m)s=m.end,a.lastIndex=m.end;let b=m?.expression;switch(l[1]){case"if":r.push(`if (${b}) {`);break;case"elseif":r.push(`} else if (${b}) {`);break;case"else":r.push("} else {");break;case"endif":case"endforeach":r.push("}");break;case"foreach":{let w=/^([\s\S]+?)\s+as\s+(?:([A-Za-z_$][\w$]*)\s*=>\s*)?([A-Za-z_$][\w$]*)$/.exec((b||"").trim());if(!w){r.push(`out += ${JSON.stringify(l[0]+(m?`(${b})`:""))};`);break}let[,S,C,v]=w;r.push(C?`for (const [${C}, ${v}] of __entries(${S})) {`:`for (const ${v} of __values(${S})) {`);break}}}return u(p.slice(s)),r.join(`
|
|
8
|
-
`)}function
|
|
8
|
+
`)}function ct(t,r,s,p){if(t[r]!==s)return-1;let a=0,l=null;for(let f=r;f<t.length;f++){let u=t[f];if(l){if(u==="\\"){f++;continue}if(u===l)l=null;continue}if(u==="'"||u==='"'||u==="`"){l=u;continue}if(u===s)a++;else if(u===p){if(p===">"&&t[f-1]==="=")continue;if(a--,a===0)return f+1}}return-1}function Lt(t,r,s){let p=s?"([{<":"([{",a=s?")]}>":")]}",l=[],f=0,u=null,y="";for(let m=0;m<t.length;m++){let b=t[m];if(u){if(y+=b,b==="\\"){y+=t[++m]??"";continue}if(b===u)u=null;continue}if(b==="'"||b==='"'||b==="`"){u=b,y+=b;continue}if(p.includes(b))f++;else if(a.includes(b))f--;if(f===0&&r.includes(b)){l.push(y),y="";continue}y+=b}return l.push(y),l.map((m)=>m.trim()).filter(Boolean)}function pr(t){let r=0,s=null;for(let p=0;p<t.length;p++){let a=t[p];if(s){if(a==="\\"){p++;continue}if(a===s)s=null;continue}if(a==="'"||a==='"'||a==="`"){s=a;continue}if("([{".includes(a))r++;else if(")]}".includes(a))r--;if(r!==0||a!=="=")continue;let l=t[p-1];if(t[p+1]==="="||l==="="||l==="!"||l==="<"||l===">")continue;return p}return-1}function Jt(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 ur(t){let r=/\bdefineProps\b/.exec(t);if(!r)return null;let s=/(?:^|[\s;{}()])(const|let|var)\s+/g,p=-1;for(let k=s.exec(t);k&&k.index<r.index;k=s.exec(t))p=k.index+k[0].indexOf(k[1]);if(p===-1)return null;let a={},l={},f=[],u=p+(/^(?:const|let|var)\s+/.exec(t.slice(p))?.[0].length??0),y=()=>{while(u<t.length&&/\s/.test(t[u]))u++},m;if(t[u]==="{"){let k=ct(t,u,"{","}");if(k===-1)return null;m=t.slice(u,k),u=k}else{let k=/^[A-Za-z_$][\w$]*/.exec(t.slice(u));if(!k)return null;m=k[0],u+=k[0].length}if(y(),t[u]!=="=")return null;u++,y();let b=/^withDefaults\s*\(\s*/.exec(t.slice(u)),w=Boolean(b);if(b)u+=b[0].length;let S=/^defineProps\b/.exec(t.slice(u));if(!S)return null;u+=S[0].length;let C="";if(y(),t[u]==="<"){let k=ct(t,u,"<",">");if(k===-1)return null;C=t.slice(u+1,k-1).trim(),u=k}if(y(),t[u]!=="(")return null;let v=ct(t,u,"(",")");if(v===-1)return null;let x=t.slice(u+1,v-1).trim();if(u=v,w){if(y(),t[u]===",")u++,y();if(t[u]==="{"){let k=ct(t,u,"{","}");if(k===-1)return null;for(let[I,A]of It(t.slice(u,k)))l[I]=A;u=k}if(y(),t[u]===",")u++,y();if(t[u]===")")u++}if(t[u]===";")u++;let T=/^[A-Za-z_$][\w$]*$/.test(C)?C:void 0;if(C.startsWith("{"))for(let k of Lt(C.replace(/^\{/,"").replace(/\}$/,""),",;",!0)){let I=/^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(k);if(I)a[I[1]]=I[2].trim()}if(x.startsWith("{"))for(let[k,I]of It(x)){if(f.push(k),!I.startsWith("{")){let A=Jt(I);if(A)a[k]=A;continue}for(let[A,_]of It(I))if(A==="default")l[k]=_;else if(A==="type"){let P=Jt(_);if(P)a[k]=P}}else if(x.startsWith("["))for(let k of Lt(x.slice(1,-1),",",!1))f.push(k.replace(/^['"`]/,"").replace(/['"`]$/,""));if(m.startsWith("{")){f.length=0;for(let k of Lt(m.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let I=pr(k),_=(I===-1?k:k.slice(0,I)).split(":")[0].trim().replace(/^\.\.\./,"");if(!_)continue;if(f.push(_),I!==-1)l[_]=k.slice(I+1).trim()}}else if(f.length===0)f.push(...Object.keys(a));return{text:t.slice(p,u),propNames:f,defaults:l,declared:a,typeName:T}}function It(t){let r=t.trim().replace(/^\{/,"").replace(/\}$/,""),s=[],p=0;while(p<r.length){let a=/\s*([A-Za-z_$][\w$]*)\s*:/y;a.lastIndex=p;let l=a.exec(r);if(!l)break;p=a.lastIndex;let f=0,u="",y=p;while(p<r.length){let b=r[p];if(u){if(b==="\\")p++;else if(b===u)u=""}else if(b==="'"||b==='"'||b==="`")u=b;else if(b==="{"||b==="["||b==="(")f++;else if(b==="}"||b==="]"||b===")")f--;else if(b===","&&f===0)break;p++}let m=r.slice(y,p).trim();if(m)s.push([l[1],m]);p++}return s}function mr(t,r,s){let a=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].find((S)=>!/\bcomponent\b|\bstx:component\b|\bclient\b/i.test(S[1]));if(!a)return{imports:[],body:"",propNames:[],defaults:{},declared:{}};let l=a[2],f=[],u=[],y={},m={};l=l.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm,(S)=>{if(/from\s*['"]stx['"]/.test(S))return"";return f.push(S.trim().replace(/(from\s*['"])(\.[^'"]*)(['"])/,(C,v,x,T)=>{let k=Ce.resolve(Ce.dirname(r),x),I=Ce.relative(s,k);return`${v}${I.startsWith(".")?I:`./${I}`}${T}`})),""});let b=ur(l);if(b)u.push(...b.propNames),Object.assign(y,b.defaults),Object.assign(m,b.declared),l=l.replace(b.text,"");let w={};for(let S of l.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)){let C=[];for(let v of S[2].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))m[v[1]]=v[2].trim(),C.push(v[1]);w[S[1]]=C}if(b&&b.propNames.length===0&&b.typeName){for(let S of w[b.typeName]??[])if(!u.includes(S))u.push(S)}return l=l.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g,""),{imports:f,body:l.trim(),propNames:u,defaults:y,declared:m}}function gr(t){let r=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(p,a,l,f,u)=>{let y=a.toLowerCase();r.add(y);let m=(l||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${y}="${u}"${m?` data-stx-mod-${y}="${m}"`:""}`}),eventTypes:[...r].sort()}}function hr(t){let r=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(p,a,l,f)=>{let u=r.length;return r.push({id:u,name:a,expression:f}),` data-stx-bind-${u}=""`}),bindings:r}}function yr(t){let r=new Set;for(let s of t.matchAll(/<slot\b([^>]*)>/gi))r.add(s[1].match(/\bname\s*=\s*["']([^"']+)["']/i)?.[1]||"");return[...r].map((s)=>({name:s}))}function br(t){return[...new Set([...t.matchAll(/(--[a-z0-9_-]+)\s*:/gi)].map((r)=>r[1]))].sort().map((r)=>({name:r}))}function Yt(t,r){if(!r||!new Set(["string","number","boolean","object","array"]).has(r.type))throw Error(`Property "${t}" must declare one of: string, number, boolean, object, array`);return{...r,reflect:r.reflect??r.attribute!==!1}}async function xr(t,r,s){let p=Ce.isAbsolute(r.file)?r.file:Ce.resolve(t,r.file),a=await Kn(p,"utf8"),l=or(a,p),f=Ce.basename(p,".stx"),u=r.name||l.name||Yn(f),y=`${jt(s.prefix||"stx")}-${jt(f)}`,m=r.tag||l.tag||y;if(!u||!/^[A-Za-z_$][\w$]*$/.test(u))throw Error(`${p}: invalid component class name "${u}"`);if(!er(m))throw Error(`${p}: invalid custom-element tag "${m}"; tags must be lowercase and contain a hyphen`);let b=r.properties||l.properties||l.props||{},w=Object.fromEntries(Object.entries(b).map(([A,_])=>[A,Yt(A,_)])),S=gr(ir(a)),C=hr(S.template),v=mr(a,p,Ce.resolve(s.outputDir)),x=dr(C.template);for(let A of v.propNames){if(w[A])continue;let _=v.defaults[A];w[A]=Yt(A,{type:ar(v.declared[A])??cr(_),..._===void 0?{}:{default:lr(_)}})}let T=l.methods||{},k=r.methods||{},I=sr(a,p);return{file:Ce.relative(t,p),sourcePath:p,name:u,tag:m,description:r.description||l.description||"",template:C.template,styles:Gt(a),shadowMode:nr(r.shadowDOM??l.shadowDOM??s.shadowDOM),progressive:r.progressive??l.progressive??s.progressive??!0,properties:w,events:r.events||l.events||{},methods:{...T,...k,...I},eventTypes:S.eventTypes,bindings:C.bindings,slots:yr(C.template),cssProperties:br(Gt(a)),scope:v,render:x}}function vr(){let t=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),r=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('>', '>')
|
|
@@ -303,7 +303,7 @@ export function defineComponent(Component, definition) {
|
|
|
303
303
|
}
|
|
304
304
|
return Component;
|
|
305
305
|
}
|
|
306
|
-
`}function wr(t){let r=JSON.stringify({tag:t.tag,template:t.template,styles:t.styles,shadowMode:t.shadowMode,progressive:t.progressive,properties:t.properties,eventTypes:t.eventTypes,bindings:t.bindings},null,2),s=Object.entries(t.methods).map(([u,y])=>{if(
|
|
306
|
+
`}function wr(t){let r=JSON.stringify({tag:t.tag,template:t.template,styles:t.styles,shadowMode:t.shadowMode,progressive:t.progressive,properties:t.properties,eventTypes:t.eventTypes,bindings:t.bindings},null,2),s=Object.entries(t.methods).map(([u,y])=>{if(tn.has(u))throw Error(`${t.sourcePath}: ${en(u)}`);if(/^(?:async\s+)?[A-Za-z_$][\w$]*\s*\(/.test(y.trim()))return` ${y.trim()}`;return` ${u}($event) {
|
|
307
307
|
${y}
|
|
308
308
|
}`}).join(`
|
|
309
309
|
|
|
@@ -328,8 +328,8 @@ ${s}${f}
|
|
|
328
328
|
|
|
329
329
|
defineComponent(${t.name}, ${r});
|
|
330
330
|
export default ${t.name};
|
|
331
|
-
`}function
|
|
332
|
-
`),s=Object.entries(t.properties).map(([l,f])=>` ${l}: ${
|
|
331
|
+
`}function lt(t){switch(t.type){case"boolean":return"boolean";case"number":return"number";case"array":return"unknown[]";case"object":return"Record<string, unknown>";default:return"string"}}function Sr(t){let r=Object.entries(t.properties).map(([l,f])=>` ${l}${f.required?"":"?"}: ${lt(f)}`).join(`
|
|
332
|
+
`),s=Object.entries(t.properties).map(([l,f])=>` ${l}: ${lt(f)}`).join(`
|
|
333
333
|
`),p=Object.entries(t.events).map(([l,f])=>` ${JSON.stringify(l)}: CustomEvent<${f.detailType||"unknown"}>`).join(`
|
|
334
334
|
`),a=Object.keys(t.methods).map((l)=>` ${l}($event?: Event): unknown`).join(`
|
|
335
335
|
`);return`export interface ${t.name}Props {
|
|
@@ -358,7 +358,7 @@ export default ${t.name}
|
|
|
358
358
|
`}function kr(t){return`declare global {
|
|
359
359
|
namespace JSX {
|
|
360
360
|
interface IntrinsicElements {
|
|
361
|
-
${t.map((s)=>{let p=Object.entries(s.properties).map(([l,f])=>` ${JSON.stringify(l)}?: ${
|
|
361
|
+
${t.map((s)=>{let p=Object.entries(s.properties).map(([l,f])=>` ${JSON.stringify(l)}?: ${lt(f)}`).join(`
|
|
362
362
|
`),a=Object.keys(s.events).map((l)=>` ${`on${l.split(/[-:]/).map((u)=>u.charAt(0).toUpperCase()+u.slice(1)).join("")}`}?: (event: CustomEvent<${s.events[l].detailType||"unknown"}>) => void`).join(`
|
|
363
363
|
`);return` ${JSON.stringify(s.tag)}: {
|
|
364
364
|
${p}
|
|
@@ -374,9 +374,9 @@ ${a}
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
export {}
|
|
377
|
-
`}function $r(t){return{schemaVersion:"1.0.0",modules:t.map((r)=>({kind:"javascript-module",path:`./${r.tag}.js`,declarations:[{kind:"class",name:r.name,description:r.description||void 0,customElement:!0,tagName:r.tag,members:Object.entries(r.properties).map(([s,p])=>({kind:"field",name:s,description:p.description,type:{text:
|
|
377
|
+
`}function $r(t){return{schemaVersion:"1.0.0",modules:t.map((r)=>({kind:"javascript-module",path:`./${r.tag}.js`,declarations:[{kind:"class",name:r.name,description:r.description||void 0,customElement:!0,tagName:r.tag,members:Object.entries(r.properties).map(([s,p])=>({kind:"field",name:s,description:p.description,type:{text:lt(p)},default:p.default===void 0?void 0:JSON.stringify(p.default),attribute:p.attribute===!1?void 0:p.attribute||jt(s),reflects:p.reflect})),events:Object.entries(r.events).map(([s,p])=>({name:s,description:p.description,type:{text:`CustomEvent<${p.detailType||"unknown"}>`}})),slots:r.slots,cssProperties:r.cssProperties}],exports:[{kind:"js",name:r.name,declaration:{name:r.name,module:`./${r.tag}.js`}}]}))}}function Qt(t){if(!t.styles)return"";let r=t.styles.replace(/:host\b/g,":scope");if(/\@scope\s*\(/.test(r))return r;return`@scope (${t.tag}) {
|
|
378
378
|
${r}
|
|
379
|
-
}`}function
|
|
379
|
+
}`}function Zt(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").replace(/\s*([{}:;,])\s*/g,"$1").replace(/;}/g,"}").trim()}function Rr(t){let r=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),s=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}"),p=JSON.stringify('<slot(?:\\s+name=["\\\']([^"\\\']+)["\\\'])?\\s*\\/?>(?:<\\/slot>)?'),a=Object.fromEntries(t.map((f)=>[f.tag,{template:f.template,styles:f.styles,shadowMode:f.shadowMode,properties:f.properties}])),l=t.map((f)=>`export const render${f.name} = (props = {}, slots = {}) => renderComponent('${f.tag}', props, slots);`).join(`
|
|
380
380
|
`);return`const definitions = ${JSON.stringify(a,null,2)};
|
|
381
381
|
const escapeHTML = (value) => String(value ?? '')
|
|
382
382
|
.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>')
|
|
@@ -410,21 +410,21 @@ export function renderComponent(tag, props = {}, slots = {}) {
|
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
${l}
|
|
413
|
-
`}async function
|
|
413
|
+
`}async function bi(t){let r=Ce.resolve(t.inputDir),s=Ce.resolve(t.outputDir);if(!(await Xt(r).catch(()=>null))?.isDirectory())throw Error(`Component-library input directory does not exist: ${r}`);let a=t.components?.length?t.components:(await rr(r)).map((x)=>({file:x}));if(!a.length)throw Error(`No .stx components found in ${r}`);let l=await Promise.all(a.map((x)=>xr(r,x,t)));l.sort((x,T)=>x.tag.localeCompare(T.tag));let f=l.filter((x,T)=>l.findIndex((k)=>k.tag===x.tag)!==T);if(f.length)throw Error(`Duplicate custom-element tag: ${f[0].tag}`);let u=l.filter((x,T)=>l.findIndex((k)=>k.name===x.name)!==T);if(u.length)throw Error(`Duplicate component class name: ${u[0].name}`);await qn(s,{recursive:!0});let y=[],m=async(x,T)=>{let k=Ce.join(s,x);return await Jn(k,T.endsWith(`
|
|
414
414
|
`)?T:`${T}
|
|
415
|
-
`,"utf8"),y.push(k),k};await m("runtime.js",vr());for(let x of l){if(await m(`${x.tag}.js`,wr(x)),t.declarations!==!1)await m(`${x.tag}.d.ts`,Sr(x));if(t.css!==!1&&x.styles){let T=x.shadowMode?x.styles:
|
|
415
|
+
`,"utf8"),y.push(k),k};await m("runtime.js",vr());for(let x of l){if(await m(`${x.tag}.js`,wr(x)),t.declarations!==!1)await m(`${x.tag}.d.ts`,Sr(x));if(t.css!==!1&&x.styles){let T=x.shadowMode?x.styles:Qt(x);await m(`${x.tag}.css`,t.minify?Zt(T):T)}}let b=l.map((x)=>`export { ${x.name}, default as ${x.name}Element } from './${x.tag}.js';`).join(`
|
|
416
416
|
`);if(await m("index.js",b),await m("ssr.js",Rr(l)),t.declarations!==!1)await m("index.d.ts",l.map((x)=>`export * from './${x.tag}.js'`).join(`
|
|
417
417
|
`)),await m("custom-elements.d.ts",kr(l)),await m("ssr.d.ts",`${l.map((x)=>`export declare const render${x.name}: (props?: ${x.name}Props, slots?: Record<string, string>) => string`).join(`
|
|
418
418
|
`)}
|
|
419
419
|
export declare function renderComponent(tag: string, props?: Record<string, unknown>, slots?: Record<string, string>): string
|
|
420
420
|
${l.map((x)=>`import type { ${x.name}Props } from './${x.tag}.js'`).join(`
|
|
421
|
-
`)}`);let w;if(t.manifest!==!1)w=await m("custom-elements.json",JSON.stringify($r(l),null,2));let S;if(t.css!==!1){let x=l.filter((T)=>!T.shadowMode&&T.styles).map(
|
|
421
|
+
`)}`);let w;if(t.manifest!==!1)w=await m("custom-elements.json",JSON.stringify($r(l),null,2));let S;if(t.css!==!1){let x=l.filter((T)=>!T.shadowMode&&T.styles).map(Qt).join(`
|
|
422
422
|
|
|
423
|
-
`);if(x)S=await m("bundle.css",t.minify?
|
|
424
|
-
`);throw AggregateError(k,`Failed to bundle component library${
|
|
425
|
-
${
|
|
423
|
+
`);if(x)S=await m("bundle.css",t.minify?Zt(x):x)}let C;if(t.bundle!==!1){C=Ce.join(s,"bundle.js");let x;try{x=await Bun.build({entrypoints:[Ce.join(s,"index.js")],outdir:s,naming:"bundle.js",target:"browser",format:"esm",minify:t.minify??!0,sourcemap:t.sourcemap||"none"})}catch(T){let k=T instanceof AggregateError?T.errors:[T],I=k.map((A)=>String(A).trim()).filter(Boolean).join(`
|
|
424
|
+
`);throw AggregateError(k,`Failed to bundle component library${I?`
|
|
425
|
+
${I}`:""}`)}if(!x.success){let T=x.logs.map((k)=>String(k).trim()).filter(Boolean).join(`
|
|
426
426
|
`);throw AggregateError(x.logs,`Failed to bundle component library${T?`
|
|
427
|
-
${T}`:""}`)}if(y.push(C),t.sourcemap==="external")y.push(`${C}.map`)}let v=await Promise.all(y.map(async(x)=>(await
|
|
427
|
+
${T}`:""}`)}if(y.push(C),t.sourcemap==="external")y.push(`${C}.map`)}let v=await Promise.all(y.map(async(x)=>(await Xt(x)).size));return{components:l.map((x)=>({name:x.name,tag:x.tag,source:x.sourcePath,module:Ce.join(s,`${x.tag}.js`)})),files:y,manifest:w,bundle:C,cssBundle:S,totalBytes:v.reduce((x,T)=>x+T,0)}}var{serve:Br}=globalThis.Bun;import Bt from"fs";import et from"path";function dt(){return`
|
|
428
428
|
/* Theme selector for code blocks */
|
|
429
429
|
.theme-selector {
|
|
430
430
|
margin: 1rem 0;
|
|
@@ -474,13 +474,13 @@ ${T}`:""}`)}if(y.push(C),t.sourcemap==="external")y.push(`${C}.map`)}let v=await
|
|
|
474
474
|
|
|
475
475
|
body.dark-mode a {
|
|
476
476
|
color: #58a6ff;
|
|
477
|
-
}`}function
|
|
477
|
+
}`}function pt(t){return`
|
|
478
478
|
<div class="theme-selector">
|
|
479
479
|
Theme:
|
|
480
480
|
<select id="themeSelector" onchange="changeTheme()">
|
|
481
481
|
${t}
|
|
482
482
|
</select>
|
|
483
|
-
</div>`}function
|
|
483
|
+
</div>`}function ft(){return`
|
|
484
484
|
function changeTheme() {
|
|
485
485
|
const theme = document.getElementById('themeSelector').value;
|
|
486
486
|
|
|
@@ -496,7 +496,7 @@ else {
|
|
|
496
496
|
}
|
|
497
497
|
|
|
498
498
|
// Initialize theme on page load
|
|
499
|
-
document.addEventListener('DOMContentLoaded', changeTheme);`}function
|
|
499
|
+
document.addEventListener('DOMContentLoaded', changeTheme);`}function mt(t){if(Object.keys(t).length===0)return"";return`
|
|
500
500
|
<div class="frontmatter">
|
|
501
501
|
<h3>Frontmatter</h3>
|
|
502
502
|
${Object.entries(t).map(([r,s])=>`
|
|
@@ -504,19 +504,19 @@ else {
|
|
|
504
504
|
<span class="frontmatter-label">${r}:</span>
|
|
505
505
|
<span>${Array.isArray(s)?s.join(", "):String(s)}</span>
|
|
506
506
|
</div>`).join("")}
|
|
507
|
-
</div>`}import
|
|
507
|
+
</div>`}import rn from"net";async function Or(t){return new Promise((r)=>{let s=rn.createServer();s.once("error",()=>r(!1)),s.once("listening",()=>{s.close(()=>r(!0))}),s.listen(t,"0.0.0.0")})}async function Ar(t){return new Promise((r)=>{let s=rn.createServer();s.once("error",()=>r(!1)),s.once("listening",()=>{s.close(()=>r(!0))}),s.listen(t,"::")})}async function Dr(t){if(!await Or(t))return!1;return await Ar(t)}async function We(t,r=20){t=Number(t);for(let s=0;s<r;s++){let p=t+s;if(await Dr(p))return p}throw Error(`Could not find an available port between ${t} and ${t+r-1}`)}var Mr={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function _r(){try{let t=await import("./chunk-fka2073f.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function Ze(t,r={}){let s={...Mr,...r},p=await _r();if(!p)return console.log(`${e.yellow}\u26A0${e.reset} Native window requested, but @stacksjs/desktop is not available.`),console.log(" Install & build the desktop package to enable --native."),!1;try{let a=await p.openDevWindow(t,{title:s.title,width:s.width,height:s.height,darkMode:s.darkMode,hotReload:s.hotReload,titlebarHidden:s.titlebarHidden,nativeSidebar:s.nativeSidebar,sidebarWidth:s.sidebarWidth,sidebarConfig:s.sidebarConfig});if(a&&s.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return a}catch(a){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,a),!1}}function ht(t){if(t.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let a=t.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(a){let l=a[1];try{let f=`
|
|
508
508
|
${l}
|
|
509
509
|
return typeof sidebarConfig !== 'undefined' ? sidebarConfig : null;
|
|
510
|
-
`,y=Function(f)();if(y)return y}catch(f){console.warn("Invalid sidebarConfig:",f)}}return{sections:[]}}let s=t.match(/@nativeSidebar\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(s)try{return JSON.parse(s[1])}catch{console.warn("Invalid @nativeSidebar configuration")}let p=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(p)try{let a=p[1].match(/(?:export\s+(?:default\s+)?|const\s+\w+\s*=\s*)(\{[\s\S]*\})/m);if(a)return Function(`return ${a[1]}`)()}catch(a){console.warn("Invalid native-sidebar script configuration:",a)}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
|
|
512
|
-
`)){let l=p.trim().toLowerCase();p="",
|
|
510
|
+
`,y=Function(f)();if(y)return y}catch(f){console.warn("Invalid sidebarConfig:",f)}}return{sections:[]}}let s=t.match(/@nativeSidebar\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(s)try{return JSON.parse(s[1])}catch{console.warn("Invalid @nativeSidebar configuration")}let p=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(p)try{let a=p[1].match(/(?:export\s+(?:default\s+)?|const\s+\w+\s*=\s*)(\{[\s\S]*\})/m);if(a)return Function(`return ${a[1]}`)()}catch(a){console.warn("Invalid native-sidebar script configuration:",a)}return}function Ht(){console.log(`
|
|
511
|
+
Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in browser`),console.log(` ${e.cyan}c${e.reset} + Enter - Clear console`),console.log(` ${e.cyan}q${e.reset} + Enter (or ${e.cyan}Ctrl+C${e.reset}) - Quit server`),console.log(` ${e.cyan}h${e.reset} + Enter - Show this help`)}function Ir(t){console.log(`${e.green}Server running at ${e.cyan}${t}${e.reset}`),console.log(`Press ${e.cyan}Ctrl+C${e.reset} to stop the server`),Ht()}function jr(t){console.log(`${e.dim}Opening ${e.cyan}${t}${e.dim} in your browser...${e.reset}`),Bun.spawn(["open",t],{stderr:"inherit"})}function qe(t,r,s){if(!process.stdin.isTTY)return;process.stdin.setRawMode(!0),process.stdin.setEncoding("utf8"),process.stdin.resume(),Ht();let p="";process.stdin.on("data",(a)=>{if(a==="\x03"){if(s?.onQuit)s.onQuit();r(),process.exit(0)}if(p+=a,p.endsWith("\r")||p.endsWith(`
|
|
512
|
+
`)){let l=p.trim().toLowerCase();p="",Hr(l,t,r,s)}})}function Hr(t,r,s,p){switch(t){case"o":if(p?.onOpen)p.onOpen();else jr(r);break;case"c":if(p?.onClear)p.onClear();else console.clear(),Ir(r);break;case"q":if(p?.onQuit)p.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),s(),process.exit(0);break;case"h":if(p?.onHelp)p.onHelp();else Ht();break;default:break}}async function Ft(t,r={}){let s=r.port||3000,p=r.watch!==!1,a=et.resolve(t);if(!Bt.existsSync(a))return console.error(`${e.red}Error: File not found: ${e.bright}${a}${e.reset}`),!1;if(!a.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${a}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${t}${e.reset}...`);let l=null,f=async()=>{try{let{content:w,data:S}=await $e(a,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:R.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),C=r.markdown?.syntaxHighlighting||R.markdown?.syntaxHighlighting,v=C?.defaultTheme||"github-dark",x=["github-dark"],T=C?.additionalThemes||[],I=[...new Set([...x,...T])].map((A)=>`<option value="${A}"${A===v?" selected":""}>${A}</option>`).join(`
|
|
513
513
|
`);return l=`
|
|
514
514
|
<!DOCTYPE html>
|
|
515
515
|
<html lang="en">
|
|
516
516
|
<head>
|
|
517
517
|
<meta charset="UTF-8">
|
|
518
518
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
519
|
-
<title>${
|
|
519
|
+
<title>${Fr(S.title||et.basename(a))}</title>
|
|
520
520
|
<!-- Syntax highlighting styles -->
|
|
521
521
|
<style id="syntax-theme">
|
|
522
522
|
:root {
|
|
@@ -658,26 +658,26 @@ Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in brow
|
|
|
658
658
|
min-width: 100px;
|
|
659
659
|
color: #555;
|
|
660
660
|
}
|
|
661
|
-
${
|
|
661
|
+
${dt()}
|
|
662
662
|
</style>
|
|
663
663
|
</head>
|
|
664
664
|
<body>
|
|
665
|
-
${
|
|
666
|
-
${
|
|
665
|
+
${mt(S)}
|
|
666
|
+
${pt(I)}
|
|
667
667
|
|
|
668
668
|
${w}
|
|
669
669
|
|
|
670
670
|
<script>
|
|
671
|
-
${
|
|
671
|
+
${ft()}
|
|
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 f())return!1;let y=s;try{if(y=await We(s),y!==s)console.log(`${e.yellow}Port ${s} 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 m=
|
|
675
|
+
`,!0}catch(w){return console.error(`${e.red}Error processing Markdown file:${e.reset}`,w),!1}};if(!await f())return!1;let y=s;try{if(y=await We(s),y!==s)console.log(`${e.yellow}Port ${s} 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 m=Br({port:y,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:${y}/${e.reset}`),console.log(`
|
|
679
679
|
${e.yellow}Routes:${e.reset}`);let b=et.relative(process.cwd(),a);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${b}${e.reset}`),console.log(`
|
|
680
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(m.url.toString(),()=>{if(p)
|
|
680
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(m.url.toString(),()=>{if(p)Bt.watch(et.dirname(a),{recursive:!0}).close();m.stop()}),r.native)await Ze(y,{title:et.basename(a,".md")});if(p){let w=et.dirname(a);console.log(`${e.blue}Watching ${e.bright}${w}${e.reset} for changes...`);let S=Bt.watch(w,{recursive:!0},async(C,v)=>{if(v&&v.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${v}${e.yellow} changed, reprocessing...${e.reset}`),await f()});process.on("SIGINT",()=>{S.close(),m.stop(),process.exit(0)})}return!0}function Fr(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Nr}=globalThis.Bun;import He from"fs";import me from"path";class on{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 r=t??this.options.wsPort,s=20;for(let p=0;p<s;p++)try{if(this.server=Bun.serve({port:r,fetch(a,l){if(l.upgrade(a,{data:{}}))return;return new Response("stx Hot Reload Server",{headers:{"Content-Type":"text/plain"}})},websocket:{open:(a)=>{if(this.clients.add(a),this.options.verbose)console.log(`[HMR] Client connected (${this.clients.size} total)`);a.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close:(a)=>{if(this.clients.delete(a),this.options.verbose)console.log(`[HMR] Client disconnected (${this.clients.size} total)`)},message:(a,l)=>{let f=typeof l==="string"?l:l.toString();if(f==="ping")return;try{let u=JSON.parse(f);if(u.type==="console"&&Array.isArray(u.args)){let y=u.args.join(" "),b={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[u.level]??"\x1B[36m";console.log(`${b}[browser]${u.level!=="log"?` ${u.level}`:""}\x1B[0m ${y}`)}}catch{}}}}),this.options.verbose)console.log(`[HMR] WebSocket server started on port ${r}`);return r}catch(a){if(a?.code==="EADDRINUSE"){r++;continue}throw a}throw Error(`Could not find an available port after ${s} 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 r=JSON.stringify(t),s=0;for(let p of this.clients)try{if(p.readyState===1)p.send(r),s++}catch{this.clients.delete(p)}if(this.options.verbose&&s>0)console.log(`[HMR] Broadcast ${t.type} to ${s} 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,r){this.broadcast({type:"css-update",path:t,content:r,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 zr(t,r={}){let{showOverlay:s=!0,reconnectInterval:p=1000,maxReconnectAttempts:a=10}=r;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
|
|
879
|
+
`}function Ne(t,r,s={}){let p=zr(r,s),a=t.lastIndexOf("</body>");if(a!==-1)return t.slice(0,a)+p+t.slice(a);if(t.includes("</html>"))return t.replace("</html>",`${p}</html>`);return t+p}function yt(t){let r=t.toLowerCase();return r.endsWith(".css")||r.endsWith(".scss")||r.endsWith(".sass")||r.endsWith(".less")}function bt(t){let r=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((p)=>r.endsWith(p))}function Tt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((s)=>s.test(t))}var tt=null;function $t(t){if(!tt)tt=new on(t);return tt}function st(){if(tt)tt.stop(),tt=null}import Rt from"path";var nt={name:"bun-plugin-stx",async setup(t){let s={...await i(),...t.config?.stx},p=new Set,a=s.webComponents?.enabled?`./${Rt.relative(Rt.dirname(t.config?.outdir||"dist"),s.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(s.webComponents?.enabled)try{let f=await Jr(s,p);if(l.push(...f),s.debug&&f.length>0)console.log(`Successfully built ${f.length} web components`)}catch(f){console.error("Failed to build web components:",f)}t.onLoad({filter:/\.stx$/},async({path:f})=>{try{let u=new Set;if(s.cache&&s.cachePath){let x=await Zn(f,s);if(x){if(s.debug)console.log(`Using cached version of ${f}`);return{contents:x,loader:"html"}}}let y=await xe(()=>Bun.file(f).text(),"",(x)=>{throw new fr(`Failed to read stx file: ${f}`,f,void 0,void 0,`File read error: ${x.message}`)});if(!y)throw new fr(`stx file is empty: ${f}`,f);let{scriptContent:m,templateContent:b,allScripts:w}=se.time("script-extraction",()=>{let x=y,T=ue(y);if(T)x=T.content.trim();let k=y.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],I="",A=[];for(let P of k){let M=P.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",j=P.match(/<script\b([^>]*)>/i),K=j?j[1]:"";if(/\bserver\b/i.test(K))I=M;else A.push(P)}let _=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:I,templateContent:_,allScripts:A}}),S={__filename:f,__dirname:Rt.dirname(f),__stx:{webComponentsPath:a,builtComponents:l}};await xe(()=>g(m,S,f),void 0,(x)=>{let T=new ie(`Script execution failed in ${f}: ${x.message}`,f,void 0,void 0,m.substring(0,100));if(D.log(T,{filePath:f,scriptContent:m}),s.debug)throw T});let v=await se.timeAsync("directive-processing",async()=>await o(b,S,f,s,u));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-4m5g3f2b.js"),T=x(w.join(`
|
|
880
880
|
`),S),k=v.search(/<\/body>/i);if(k!==-1)v=v.slice(0,k)+T+`
|
|
881
881
|
`+v.slice(k);else v+=`
|
|
882
|
-
${T}`}if(v=await ye(v),u.forEach((x)=>p.add(x)),s.cache&&s.cachePath){if(await Qn(f,v,u,s),s.debug)console.log(`Cached template ${f} with ${u.size} dependencies`)}return{contents:v,loader:"html"}}catch(u){let y=u instanceof Error?u:new ie(`Plugin processing failed: ${String(u)}`,f);if(D.log(y,{filePath:f,buildConfig:t.config}),bn.logDetailedError(y,{filePath:f,plugin:"bun-plugin-stx"}),s.debug)console.error("stx Plugin Error:",y);let m=y,b=m.line||null,w=m.context||null;return{contents:s.debug||
|
|
882
|
+
${T}`}if(v=await ye(v),u.forEach((x)=>p.add(x)),s.cache&&s.cachePath){if(await Qn(f,v,u,s),s.debug)console.log(`Cached template ${f} with ${u.size} dependencies`)}return{contents:v,loader:"html"}}catch(u){let y=u instanceof Error?u:new ie(`Plugin processing failed: ${String(u)}`,f);if(D.log(y,{filePath:f,buildConfig:t.config}),bn.logDetailedError(y,{filePath:f,plugin:"bun-plugin-stx"}),s.debug)console.error("stx Plugin Error:",y);let m=y,b=m.line||null,w=m.context||null;return{contents:s.debug||W()?`<!DOCTYPE html>
|
|
883
883
|
<html lang="en">
|
|
884
884
|
<head>
|
|
885
885
|
<meta charset="UTF-8">
|
|
@@ -920,7 +920,7 @@ ${T}`}if(v=await ye(v),u.forEach((x)=>p.add(x)),s.cache&&s.cachePath){if(await Q
|
|
|
920
920
|
<li>Check the syntax of your stx directives (e.g., @if, @foreach)</li>
|
|
921
921
|
<li>Verify that all variables used in the template are properly defined</li>
|
|
922
922
|
<li>Ensure script tags have valid JavaScript/TypeScript syntax</li>
|
|
923
|
-
<li>Run <code>stx debug ${d(
|
|
923
|
+
<li>Run <code>stx debug ${d(Rt.basename(f))}</code> for detailed analysis</li>
|
|
924
924
|
<li>Enable debug mode in your stx config for more detailed error messages</li>
|
|
925
925
|
</ul>
|
|
926
926
|
</div>
|
|
@@ -939,12 +939,12 @@ ${T}`}if(v=await ye(v),u.forEach((x)=>p.add(x)),s.cache&&s.cachePath){if(await Q
|
|
|
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 Cr(t,r={}){let s=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||s+1,u=
|
|
943
|
-
${
|
|
942
|
+
</html>`,loader:"html"}}})}};async function Cr(t,r={}){let s=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||s+1,u=me.resolve(t);if(!He.existsSync(u))return console.error(`${e.red}Error: File not found: ${e.bright}${u}${e.reset}`),!1;if(u.endsWith(".md"))return Ft(u,r);else if(!u.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${u}${e.reset}. Only .stx and .md files are supported.`),!1;let y=c(process.cwd(),"output");He.mkdirSync(y,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let m=null,b=async()=>{try{let M={name:"public-assets",setup(ve){ve.onResolve({filter:/^\/(images|fonts|assets|public)\//},(oe)=>({path:oe.path,external:!0}))}},j=await Bun.build({entrypoints:[u],outdir:y,plugins:[M,nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!j.success)return console.error(`${e.red}Build failed:${e.reset}`,j.logs),!1;let K=j.outputs.find((ve)=>ve.path.endsWith(".html"));if(!K)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return m=await Bun.file(K.path).text(),!0}catch(M){return console.error(`${e.red}Error building stx file:${e.reset}`,M),!1}};if(!await b())return!1;let S=me.dirname(u);await nn(S);let C=s;try{if(C=await We(s),C!==s)console.log(`${e.yellow}Port ${s} is busy, using port ${C} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(a){let M=r.hmrPort||C+1;l=$t({wsPort:M,verbose:!1}),f=l.start(M)}let v={},x=null,T;try{let{loadStxConfig:M}=await import("./chunk-fbbp8j97.js"),j=await M();if(T=r.stxOptions?.serverApi??j.serverApi,j?.apiRouter)x=j?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(j?.apiRoutes){v=j.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(j?.broadcasting?.enabled)try{let{startBroadcasting:K,loadChannels:J}=await import("./chunk-tq2m6m3j.js"),ve=j.broadcasting;await K(ve);let oe=ve.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${oe}/ws${e.reset}`);let Ee=me.join(process.cwd(),"channels.ts");if(He.existsSync(Ee))try{let ee=await J(Ee);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(K){console.warn(`${e.yellow}Broadcasting failed to start: ${K.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:I}=await import("./chunk-47fwr1z7.js"),A=await k(process.cwd(),T);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${C}/${e.reset}...`),a)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${f}${e.reset}`);let _=Nr({port:C,async fetch(M){return kn(M,await(async()=>{let j=new URL(M.url);if([y,me.dirname(u),me.join(process.cwd(),"public")].some((ee)=>I(me.join(ee,j.pathname),process.cwd(),T)))return new Response("Not Found",{status:404});if(x)try{let ee=await x.handleRequest(M);if(ee.status!==404)return ee}catch{}if(v[j.pathname])try{return await v[j.pathname](M)}catch(ee){return new Response(JSON.stringify({error:ee.message}),{status:500,headers:{"Content-Type":"application/json"}})}let K=await A(M);if(K)return K;if(j.pathname==="/")return(async()=>{let z=await h(m||"");if(a)z=Ne(z,f);if(r.native)if(z.includes("<head>"))z=z.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(z.includes("<html"))z=z.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 z="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+z;if(r.titlebarHidden)if(z.includes("<head>"))z=z.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(z.includes("<html"))z=z.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 z=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${z}`;return z})().then((z)=>new Response(z,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let J=me.join(y,j.pathname);if(He.existsSync(J)&&He.statSync(J).isFile()){let ee=Bun.file(J),z=me.extname(J).toLowerCase(),L="text/plain";if(z===".ts"||z===".tsx"){let Be=new Bun.Transpiler({loader:z===".tsx"?"tsx":"ts"}),ze=await ee.text(),Je=Be.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(z){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ee,{headers:{"Content-Type":L}})}let ve=me.dirname(u),oe=me.join(ve,j.pathname);if(He.existsSync(oe)&&He.statSync(oe).isFile()){let ee=Bun.file(oe),z=me.extname(oe).toLowerCase(),L="text/plain";if(z===".ts"||z===".tsx"){let Be=new Bun.Transpiler({loader:z===".tsx"?"tsx":"ts"}),ze=await ee.text(),Je=Be.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(z){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ee,{headers:{"Content-Type":L}})}let Ee=me.join(process.cwd(),"public",j.pathname);if(He.existsSync(Ee)&&He.statSync(Ee).isFile()){let ee=Bun.file(Ee),z=me.extname(Ee).toLowerCase(),L="application/octet-stream";if(z===".ts"||z===".tsx"){let Be=new Bun.Transpiler({loader:z===".tsx"?"tsx":"ts"}),ze=await ee.text(),Je=Be.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(z){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ee,{headers:{"Content-Type":L}})}return new Response("Not Found",{status:404})})())},error(M){return new Response(`<pre>${M}
|
|
943
|
+
${M.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
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:${C}/${e.reset}`),console.log(`
|
|
946
|
-
${e.yellow}Routes:${e.reset}`);let
|
|
947
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(
|
|
946
|
+
${e.yellow}Routes:${e.reset}`);let P=me.relative(process.cwd(),u);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${P}${e.reset}`),console.log(`
|
|
947
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(_.url.toString(),()=>{if(p)He.watch(me.dirname(u),{recursive:!0}).close();_.stop()}),r.native){let M=await Bun.file(u).text(),j=ht(M);await Ze(C,{title:me.basename(u,".stx"),titlebarHidden:r.titlebarHidden===!0,nativeSidebar:!!j,sidebarConfig:j})}if(p){let M=me.dirname(u);console.log(`${e.blue}Watching ${e.bright}${M}${e.reset} for changes...`);let j=He.watch(M,{recursive:!0},async(K,J)=>{if(!J||Tt(J))return;if(bt(J)){console.log(`${e.yellow}File ${e.bright}${J}${e.yellow} changed, rebuilding...${e.reset}`),Ge.clear(),pe();let ve=await b();if(await Gn(S),a&&l)if(ve)l.reload(J);else l.error("Build failed - check console for details")}else if(yt(J)){if(console.log(`${e.cyan}CSS ${e.bright}${J}${e.cyan} changed${e.reset}`),a&&l)l.updateCss(J)}});process.on("SIGINT",()=>{if(j.close(),l)st();_.stop(),process.exit(0)})}return!0}var{serve:Ur}=globalThis.Bun;import Ke from"fs";import Re from"path";var sn=`
|
|
948
948
|
<script data-stx-helpers>
|
|
949
949
|
(function() {
|
|
950
950
|
'use strict'
|
|
@@ -1255,14 +1255,14 @@ else {
|
|
|
1255
1255
|
|
|
1256
1256
|
})()
|
|
1257
1257
|
</script>
|
|
1258
|
-
`;function
|
|
1258
|
+
`;function cn(t){if(t.length===0)return"";if(t.length===1)return t[0];let r=t.map((p)=>p.split(Re.sep)),s=[];for(let p=0;p<r[0].length;p++){let a=r[0][p];if(r.every((l)=>l[p]===a))s.push(a);else break}return s.join(Re.sep)}async function Er(t,r={}){let s=r.port||3000,p=r.watch!==!1;for(let v of t){let x=Re.resolve(v);if(!Ke.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 a=c(process.cwd(),"output");Ke.mkdirSync(a,{recursive:!0});let l=cn(t.map((v)=>Re.dirname(Re.resolve(v))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let f={},u=[],y=async()=>{try{for(let v of t){let x=Re.resolve(v);if(x.endsWith(".md"))try{let{content:k,data:I}=await $e(x,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:R.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),A=r.markdown?.syntaxHighlighting||R.markdown?.syntaxHighlighting,_=A?.defaultTheme||"github-dark",P=["github-dark"],M=A?.additionalThemes||[],K=[...new Set([...P,...M])].map((Ee)=>`<option value="${Ee}"${Ee===_?" selected":""}>${Ee}</option>`).join(`
|
|
1259
1259
|
`),J=`
|
|
1260
1260
|
<!DOCTYPE html>
|
|
1261
1261
|
<html lang="en">
|
|
1262
1262
|
<head>
|
|
1263
1263
|
<meta charset="UTF-8">
|
|
1264
1264
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1265
|
-
<title>${
|
|
1265
|
+
<title>${an(I.title||Re.basename(x))}</title>
|
|
1266
1266
|
<!-- Syntax highlighting styles -->
|
|
1267
1267
|
<style id="syntax-theme">
|
|
1268
1268
|
:root {
|
|
@@ -1404,40 +1404,40 @@ else {
|
|
|
1404
1404
|
min-width: 100px;
|
|
1405
1405
|
color: #555;
|
|
1406
1406
|
}
|
|
1407
|
-
${
|
|
1407
|
+
${dt()}
|
|
1408
1408
|
</style>
|
|
1409
1409
|
</head>
|
|
1410
1410
|
<body>
|
|
1411
|
-
${
|
|
1412
|
-
${
|
|
1411
|
+
${mt(I)}
|
|
1412
|
+
${pt(K)}
|
|
1413
1413
|
|
|
1414
1414
|
${k}
|
|
1415
1415
|
|
|
1416
1416
|
<script>
|
|
1417
|
-
${
|
|
1417
|
+
${ft()}
|
|
1418
1418
|
</script>
|
|
1419
1419
|
</body>
|
|
1420
1420
|
</html>
|
|
1421
|
-
`,
|
|
1422
|
-
${Te(
|
|
1423
|
-
</head>`);else
|
|
1424
|
-
</head>`);return new Response(
|
|
1421
|
+
`,oe=`/${Re.relative(l,x).replace(/\.md$/,"")}`;if(oe.endsWith("/index"))oe=oe.slice(0,-6)||"/";f[oe||"/"]={filePath:x,content:J,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(P){P.onResolve({filter:/^\/(images|fonts|assets|public)\//},(M)=>({path:M.path,external:!0}))}},I;try{let P=await Bun.build({entrypoints:[x],outdir:a,plugins:[k,nt],define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!P.success){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:`,Te(P.logs,x));continue}let M=P.outputs.find((j)=>j.path.endsWith(".html"));if(!M){console.error(`${e.red}No HTML output found for ${e.bright}${v}${e.reset}`);continue}I=await Bun.file(M.path).text()}catch(P){console.error(`${e.red}Build failed for ${e.bright}${v}${e.reset}:
|
|
1422
|
+
${Te(P,x)}`);continue}let _=`/${Re.relative(l,x).replace(/\.stx$/,"")}`;if(_.endsWith("/index"))_=_.slice(0,-6)||"/";if(_.includes("[")){let{regex:P,params:M}=ns(_,{page:!0});u.push({pattern:P,paramNames:M,filePath:x,routeTemplate:_,fileType:"stx"}),f[_]={filePath:x,content:I,fileType:"stx"}}else f[_||"/"]={filePath:x,content:I,fileType:"stx"}}}if(Object.keys(f).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}`,Te(v)),!1}};if(!await y())return!1;let b=s;try{if(b=await We(s),b!==s)console.log(`${e.yellow}Port ${s} is busy, using port ${b} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${b}/${e.reset}...`);let w=Ur({port:b,async fetch(v){let x=new URL(v.url),T=Re.join(process.cwd(),"public",x.pathname);if(Ke.existsSync(T)&&Ke.statSync(T).isFile()){let A=Bun.file(T),_=Re.extname(T).toLowerCase(),P="application/octet-stream";if(_===".ts"||_===".tsx"){let M=new Bun.Transpiler({loader:_===".tsx"?"tsx":"ts"}),j=await A.text(),K=M.transformSync(j);return new Response(K,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(_){case".html":P="text/html";break;case".css":P="text/css";break;case".js":P="text/javascript";break;case".json":P="application/json";break;case".png":P="image/png";break;case".jpg":case".jpeg":P="image/jpeg";break;case".gif":P="image/gif";break;case".svg":P="image/svg+xml";break;case".ico":P="image/x-icon";break;case".woff":P="font/woff";break;case".woff2":P="font/woff2";break;case".ttf":P="font/ttf";break;case".otf":P="font/otf";break;case".eot":P="application/vnd.ms-fontobject";break}return new Response(A,{headers:{"Content-Type":P}})}let k=f[x.pathname];if(!k&&!x.pathname.endsWith("/"))k=f[`${x.pathname}/`];if(!k)for(let A of u){let _=x.pathname.match(A.pattern);if(_){let P=f[A.routeTemplate];if(P){let M={};for(let J=0;J<A.paramNames.length;J++)M[A.paramNames[J]]=decodeURIComponent(_[J+1]);let j=P.content,K=`<script>window.__routeParams = ${JSON.stringify(M)};</script>`;if(j.includes("</head>"))j=j.replace("</head>",`${K}
|
|
1423
|
+
</head>`);else j=K+j;k={...P,content:j}}break}}if(k)return h(k.content).then((A)=>{if(A.includes("</head>"))A=A.replace("</head>",`${sn}
|
|
1424
|
+
</head>`);return new Response(A,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let I=Re.join(a,x.pathname);if(Ke.existsSync(I)&&Ke.statSync(I).isFile()){let A=Bun.file(I),_=Re.extname(I).toLowerCase(),P="text/plain";if(_===".ts"||_===".tsx"){let M=new Bun.Transpiler({loader:_===".tsx"?"tsx":"ts"}),j=await A.text(),K=M.transformSync(j);return new Response(K,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(_){case".html":P="text/html";break;case".css":P="text/css";break;case".js":P="text/javascript";break;case".json":P="application/json";break;case".png":P="image/png";break;case".jpg":case".jpeg":P="image/jpeg";break;case".gif":P="image/gif";break;case".svg":P="image/svg+xml";break;case".ico":P="image/x-icon";break;case".woff":P="font/woff";break;case".woff2":P="font/woff2";break;case".ttf":P="font/ttf";break;case".otf":P="font/otf";break;case".eot":P="application/vnd.ms-fontobject";break}return new Response(A,{headers:{"Content-Type":P}})}if(x.pathname!=="/"&&f["/"]){let A=ke(v);return h(f["/"].content).then((_)=>{if(A){let P=_.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(P){let M=_.match(/<title[^>]*>([\s\S]*?)<\/title>/i),j=M?M[1]:"",K=`<!DOCTYPE html><html><head><title>${an(j)}</title></head><body><main>${P[1]}</main></body></html>`;return new Response(K,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...O(),"Cache-Control":ut,Pragma:"no-cache",Expires:"0"}})}}return new Response(_,{headers:{"Content-Type":"text/html",...O(),"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:${b}/${e.reset}`),console.log(`
|
|
1428
|
-
${e.yellow}Routes:${e.reset}`);let S=new Set(u.map((v)=>v.routeTemplate)),C=Object.entries(f).filter(([v])=>!S.has(v)).sort(([v],[x])=>v.localeCompare(x)).map(([v,x])=>({route:v==="/"?"/":v,filePath:
|
|
1429
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(w.url.toString(),()=>{if(p)Xe.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Xe.watch(l,{recursive:!0},async(x,T)=>{if(!T)return;if(T.endsWith(".stx")||T.endsWith(".js")||T.endsWith(".ts")||T.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${T}${e.yellow} changed, rebuilding...${e.reset}`),Ke.clear(),pe(),await y()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function sn(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Ur}=globalThis.Bun;import le from"fs";import Q from"path";async function cn(t){try{return un(await Bun.file(t).text())}catch{return}}function Ft(t){let r=Bun.file(t),s=Q.extname(t).toLowerCase(),p={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(s)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(r,{headers:{"Content-Type":p[s]||"application/octet-stream",...l}})}async function Tr(t=".",r={}){let s=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||s+1,u=Q.resolve(t),{loadStxConfig:y}=await import("./chunk-pgvwysxq.js"),m=await y(u),{createServerApi:b,isServerApiSource:w}=await import("./chunk-kmj127rm.js"),S=r.stxOptions?.serverApi??m.serverApi,C=await b(u,S),v=m.root&&m.root!=="."?Q.join(u,m.root):u,x=r.pagesDir||m.pagesDir||"pages",T=Q.join(v,x);if(!le.existsSync(T)&&!m._layerPageDirs?.some((P)=>le.existsSync(P)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${T}${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=W(v,{pagesDir:x,pagesDirs:m._layerPageDirs?[T,...m._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${T}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let j=m?._pluginPageDirs||[],M=[];for(let{dir:P,prefix:B}of j)if(le.existsSync(P)){let F=W(Q.dirname(P),{pagesDir:Q.basename(P)});for(let N of F){let de=B==="/"?N.pattern:`${B}${N.pattern==="/"?"":N.pattern}`;M.push({route:{...N,pattern:de},prefix:B})}if(F.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${F.length}${e.blue} routes at ${e.cyan}${B}${e.reset}`)}let L=new Map,E=null,_=null;if(r.stxOptions?.shell!==!1){if(_=await $i(u,r.stxOptions?.shell),_){if(E=await zs(_,r.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${Q.relative(u,_)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}wt(),await St(u);let H=xt();if(H.length>0)console.log(`${e.blue}Loaded ${e.bright}${H.length}${e.blue} middleware: ${e.dim}${H.join(", ")}${e.reset}`);let q={},J=null;try{let{loadStxConfig:P}=await import("./chunk-pgvwysxq.js"),B=await P(u);if(B?.apiRouter)J=B?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(B?.apiRoutes){q=B.apiRoutes;let F=Object.keys(q).length;if(F>0)console.log(`${e.blue}Loaded ${e.bright}${F} API route${F>1?"s":""}${e.reset}`)}if(B?.broadcasting?.enabled)try{let{startBroadcasting:F,loadChannels:N}=await import("./chunk-54zkkxmb.js"),de=B.broadcasting;await F(de);let je=de.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${je}/ws${e.reset}`);let Ne=Q.join(process.cwd(),"channels.ts");if(le.existsSync(Ne))try{let Y=await N(Ne);console.log(`${e.blue}Loaded ${e.bright}${Y} broadcast channel${Y!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(Y){console.warn(`${e.yellow}Failed to load channels.ts: ${Y.message}${e.reset}`)}}catch(F){console.warn(`${e.yellow}Broadcasting failed to start: ${F.message}${e.reset}`)}}catch{}let be=c(u,"output");le.mkdirSync(be,{recursive:!0});let ae=new Map,Re=new Set,Z=async(P)=>{let B=ns(T,P);if(!B)return null;try{let F=await Bun.build({entrypoints:[B],outdir:be,plugins:[nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!F.success)return null;let N=F.outputs.find((de)=>de.path.endsWith(".html"));if(!N)return null;return await Bun.file(N.path).text()}catch{return null}},z=new Map,I=async(P,B)=>{try{let{processDirectives:F,extractVariables:N,defaultConfig:de,loadStxConfig:je,injectRouterScript:Ne}=await import("./chunk-pgvwysxq.js"),{checkCache:Y,cacheTemplate:G,readFileCached:V,templateCache:K}=await import("./chunk-ac75vk0w.js"),me=await je(u),Ue=(ee)=>{if(!ee)return ee;if(Q.isAbsolute(ee))return ee;return Q.resolve(u,ee)},A={...de,...me,...r.stxOptions,autoShell:!0};if(r.debugDirectives)A.debug=!0;A.partialsDir=Ue(A.partialsDir),A.componentsDir=Ue(A.componentsDir),A.layoutsDir=Ue(A.layoutsDir),A.storesDir=Ue(A.storesDir||"stores"),A.cachePath=Ue(A.cachePath)??c(u,"cache");let ce=!B&&!r.profile,te=A.cache!==!1;if(te&&ce){let ee=K.get(P.filePath);if(ee)try{if((await le.promises.stat(P.filePath)).mtime.getTime()<=ee.mtime){let Me=!0;for(let we of ee.dependencies){if(!le.existsSync(we)){Me=!1;break}if((await le.promises.stat(we)).mtime.getTime()>ee.mtime){Me=!1;break}}if(Me){let we=ee.output;if(E)we=Ve(we,{preserveHead:!0});let ot=z.get(P.filePath);return{route:P,content:we,status:ot?.status??await cn(P.filePath),headers:ot?.headers}}}}catch{}let Ae=await Y(P.filePath,A);if(Ae){let De=Ae;if(E)De=Ve(De,{preserveHead:!0});let Me=z.get(P.filePath);return{route:P,content:De,status:Me?.status??await cn(P.filePath),headers:Me?.headers}}}let se=te?await V(P.filePath):await Bun.file(P.filePath).text(),ve=un(se),{classifyAllScripts:X}=await import("./chunk-pgvwysxq.js"),Oe=X(se),He=Oe.server.map((ee)=>ee.content),ne=se;for(let ee of Oe.server)ne=ne.replace(ee.fullTag,"");let oe={__filename:P.filePath,__dirname:Q.dirname(P.filePath),__stx_options:A,params:B??{},__stx_runtime_head:{}};for(let ee of He)try{await N(ee,oe,P.filePath)}catch(Ae){if(r.stxOptions?.debug)console.error("[stx] variable extraction error",P.filePath,Ae?.message||Ae)}let Fe=new Set,Ee;if(r.profile){let ee=performance.now();Ee=await F(ne,oe,P.filePath,A,Fe);let Ae=performance.now()-ee,De=Q.relative(u,P.filePath)||P.filePath;console.log(`[stx:profile] ${De} \u2192 ${Ae.toFixed(2)}ms`)}else Ee=await F(ne,oe,P.filePath,A,Fe);if(!E)Ee=await Ne(Ee,{router:A.router});{let{interpolateScriptExpressions:ee}=await import("./chunk-0v35wpm7.js");Ee=Ee.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ae,De,Me)=>{if(!/function\s+__stx_setup_/.test(Me))return Ae;return`<script${De}>${ee(Me,oe)}</script>`})}if(E)Ee=Ve(Ee,{preserveHead:!0});if(te&&ce)await G(P.filePath,Ee,Fe,A);let{extractStreamBoundaries:Hn}=await import("./chunk-m0f3strn.js"),Qe=Hn(oe),rt=oe.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let ee=oe.streamBoundaries||{},Ae={...A,autoShell:!1},De=Object.keys(rt).map((we)=>({id:we,render:async()=>{let ot=typeof ee[we]==="function"?await ee[we]():void 0;return F(rt[we],{...oe,$boundary:ot},P.filePath,Ae,new Set)}})),Me=new Set(De.map((we)=>we.id));Qe=[...(Qe||[]).filter((we)=>!Me.has(we.id)),...De]}if(Qe&&Qe.length>0)Re.add(P.pattern);else Qe=void 0;let Ut=At(oe),Wt=Pt(oe);if(ce)z.set(P.filePath,{status:Ut,headers:Wt});return{route:P,content:Ee,status:Ut??ve,headers:Wt,boundaries:Qe}}catch(F){return console.error(`${e.red}Error building ${e.bright}${P.pattern}${e.reset}:`,F),null}},Ie=8,Be=async()=>{ae.clear(),L.clear();for(let P=0;P<k.length;P+=Ie){let B=k.slice(P,P+Ie),F=await Promise.all(B.map((N)=>I(N)));for(let N of F)if(N)ae.set(N.route.pattern,N)}for(let P=0;P<M.length;P+=Ie){let B=M.slice(P,P+Ie),F=await Promise.all(B.map(({route:N})=>I(N)));for(let N of F)if(N)L.set(N.route.pattern,N)}return ae.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await Be())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await nn(u);let Ge=s;try{if(Ge=await We(s),Ge!==s)console.log(`${e.yellow}Port ${s} is busy, using port ${Ge} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(a){let P=r.hmrPort||Ge+1;l=Tt({wsPort:P,verbose:!1}),f=l.start(P)}let Et=(P,B)=>{let N=`<script data-stx-route-params>(function(){var p=${JSON.stringify(B).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(P.includes("</head>"))return P.replace("</head>",`${N}</head>`);if(P.includes("<body"))return P.replace(/<body([^>]*)>/,`<body$1>${N}`);return N+P};console.log(`${e.blue}Starting server...${e.reset}`);let Ot=Ur({port:Ge,async fetch(P){let B=new URL(P.url),F=m?.publicDir||"public",N=Q.join(u,F,B.pathname),de=Q.join(u,B.pathname),je=Q.join(be,B.pathname);if([N,de,je].some((A)=>w(A,u,S)))return new Response("Not Found",{status:404});let[Ne,Y,G]=await Promise.all([le.promises.stat(N).catch(()=>null),le.promises.stat(de).catch(()=>null),le.promises.stat(je).catch(()=>null)]);if(Ne?.isFile()&&!w(N,u,S))return Ft(N);if(Y?.isFile()&&!w(de,u,S))return Ft(de);if(G?.isFile()&&!w(je,u,S))return Ft(je);if(B.pathname.startsWith("/_stx/component/")){let A=decodeURIComponent(B.pathname.slice(16));if(A)try{let ce=`<${A} />`,te={...buildConfig,autoShell:!1},se=await processDirectives(ce,{},Q.join(u,"components",`${A}.stx`),te,new Set);return new Response(se,{headers:{"Content-Type":"text/html"}})}catch(ce){return new Response(`<div class="stx-async-error">${ce.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(B.pathname==="/_stx/img"){let{handleImageRequest:A}=await import("./chunk-kqbpkg8n.js"),ce=await A(P,{publicDir:Q.join(u,F),cacheDir:c(u,"cache","img")});if(ce)return ce}if(J)try{let A=await J.handleRequest(P);if(A.status!==404)return A}catch{}if(q[B.pathname])try{return await q[B.pathname](P)}catch(A){return new Response(JSON.stringify({error:A.message}),{status:500,headers:{"Content-Type":"application/json"}})}let V=await C(P);if(V)return V;let K=tr(B.pathname,k);if(K){let A=ae.get(K.route.pattern),ce=Re.has(K.route.pattern);if(K.route.isDynamic&&Object.keys(K.params).length>0||ce){let te=await I(K.route,K.params);if(te)A=te}if(A){let te=A.status??200,se=A.headers??{},ve=(K.route.filePath?gt(await Bun.file(K.route.filePath).text().catch(()=>"")):null)??{};if(ve.validate){if(!await ve.validate({params:K.params})){let He=await Z(404);if(He){let ne=He;if(ne=await h(ne,u),a)ne=ze(ne,f);return new Response(ne,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(ve.middleware){let Oe=kt(B.pathname,K.params,ve,B.search),He=_t(Oe,null,P,{isServer:!0}),ne=await Ct(ve.middleware,He);if(ne.redirect){let oe=ne.redirect.path,Fe=ne.redirect.options.redirectCode||302,Ee=new Headers(ne.responseHeaders);return Ee.set("Location",oe),new Response(null,{status:Fe,headers:Ee})}if(ne.abort){let{statusCode:oe,message:Fe}=ne.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${oe}</title></head><body><h1>Error ${oe}</h1><p>${Fe}</p></body></html>`,{status:oe,headers:{"Content-Type":"text/html"}})}if(Object.keys(ne.state).length>0){let oe=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(ne.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;A.content=A.content.replace("</head>",`${oe}</head>`)}}let X=A.content;if(E&&Ri(P)){let Oe=Ye(X),He=he(X),ne=X.match(/<title[^>]*>([\s\S]*?)<\/title>/i),oe=ne?Ti(ne[1].trim()):"";if(Object.keys(K.params).length>0)X=Et(X,K.params);X=await h(X,u);let Fe=m?.router?.container||"main";return X=_e(X,Fe),new Response(X,{status:te,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Oe.layout,"X-STX-Layout-Group":Oe.group,"X-STX-Runtime":He?"true":"false",...oe&&{"X-STX-Title":encodeURIComponent(oe)},[ra]:eo(),...O(),"Cache-Control":ut}})}if(E)X=Pr(E,X);if(Object.keys(K.params).length>0)X=Et(X,K.params);if(X=await h(X,u),a)X=ze(X,f);if(r.native)if(X.includes("<head>"))X=X.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else X="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+X;if(r.titlebarHidden)if(X.includes("<head>"))X=X.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else X=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${X}`;if(A.boundaries&&A.boundaries.length>0){let{renderStreamingPage:Oe,streamToResponse:He}=await import("./chunk-m0f3strn.js");return He(Oe(X,A.boundaries,{timeoutMs:30000}),{status:te,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(X,{status:te,headers:{"Content-Type":"text/html",...O(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...se}})}}if(M.length>0){let A=M.map((te)=>te.route),ce=tr(B.pathname,A);if(ce){let te=L.get(ce.route.pattern);if(te){let se=te.content;if(E)se=Pr(E,se);if(Object.keys(ce.params).length>0)se=Et(se,ce.params);if(se=await h(se,u),a)se=ze(se,f);return new Response(se,{status:te.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:te}of j)if(te!=="/"&&B.pathname.startsWith(te)){let se=L.get(te)||L.get(te+"/");if(se){let ve=se.content;if(E)ve=Pr(E,ve);if(ve=await h(ve,u),a)ve=ze(ve,f);return new Response(ve,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(vt(B.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let me=ae.get("/");if(me){let A=me.content;if(A=await h(A,u),a)A=ze(A,f);if(r.native)if(A.includes("<head>"))A=A.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else A="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+A;return new Response(A,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Ue=await Z(404);if(Ue){let A=Ue;if(A=await h(A,u),a)A=ze(A,f);return new Response(A,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(P){let B=await Z(500);if(B)return new Response(B,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${P}
|
|
1430
|
-
${
|
|
1428
|
+
${e.yellow}Routes:${e.reset}`);let S=new Set(u.map((v)=>v.routeTemplate)),C=Object.entries(f).filter(([v])=>!S.has(v)).sort(([v],[x])=>v.localeCompare(x)).map(([v,x])=>({route:v==="/"?"/":v,filePath:Re.relative(process.cwd(),x.filePath),fileType:x.fileType}));for(let v of u){let x=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");C.push({route:x,filePath:Re.relative(process.cwd(),v.filePath),fileType:"stx"})}if(C.sort((v,x)=>v.route.localeCompare(x.route)),C.forEach((v,x)=>{let k=x===C.length-1?"\u2514\u2500 ":"\u251C\u2500 ",I=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${k}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${I}`)}),console.log(`
|
|
1429
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(w.url.toString(),()=>{if(p)Ke.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Ke.watch(l,{recursive:!0},async(x,T)=>{if(!T)return;if(T.endsWith(".stx")||T.endsWith(".js")||T.endsWith(".ts")||T.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${T}${e.yellow} changed, rebuilding...${e.reset}`),Ge.clear(),pe(),await y()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function an(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Wr}=globalThis.Bun;import de from"fs";import Z from"path";async function ln(t){try{return un(await Bun.file(t).text())}catch{return}}function zt(t){let r=Bun.file(t),s=Z.extname(t).toLowerCase(),p={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(s)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(r,{headers:{"Content-Type":p[s]||"application/octet-stream",...l}})}async function Tr(t=".",r={}){let s=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||s+1,u=Z.resolve(t),{loadStxConfig:y}=await import("./chunk-fbbp8j97.js"),m=await y(u),{createServerApi:b,isServerApiSource:w}=await import("./chunk-47fwr1z7.js"),S=r.stxOptions?.serverApi??m.serverApi,C=await b(u,S),v=m.root&&m.root!=="."?Z.join(u,m.root):u,x=r.pagesDir||m.pagesDir||"pages",T=Z.join(v,x);if(!de.existsSync(T)&&!m._layerPageDirs?.some((E)=>de.existsSync(E)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${T}${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=q(v,{pagesDir:x,pagesDirs:m._layerPageDirs?[T,...m._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${T}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let I=m?._pluginPageDirs||[],A=[];for(let{dir:E,prefix:H}of I)if(de.existsSync(E)){let F=q(Z.dirname(E),{pagesDir:Z.basename(E)});for(let N of F){let fe=H==="/"?N.pattern:`${H}${N.pattern==="/"?"":N.pattern}`;A.push({route:{...N,pattern:fe},prefix:H})}if(F.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${F.length}${e.blue} routes at ${e.cyan}${H}${e.reset}`)}let _=new Map,P=null,M=null;if(r.stxOptions?.shell!==!1){if(M=await Ai(u,r.stxOptions?.shell),M){if(P=await Hs(M,r.stxOptions||{}),P)console.log(`${e.blue}Using app shell: ${e.bright}${Z.relative(u,M)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}wt(),await St(u);let j=xt();if(j.length>0)console.log(`${e.blue}Loaded ${e.bright}${j.length}${e.blue} middleware: ${e.dim}${j.join(", ")}${e.reset}`);let K={},J=null;try{let{loadStxConfig:E}=await import("./chunk-fbbp8j97.js"),H=await E(u);if(H?.apiRouter)J=H?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(H?.apiRoutes){K=H.apiRoutes;let F=Object.keys(K).length;if(F>0)console.log(`${e.blue}Loaded ${e.bright}${F} API route${F>1?"s":""}${e.reset}`)}if(H?.broadcasting?.enabled)try{let{startBroadcasting:F,loadChannels:N}=await import("./chunk-tq2m6m3j.js"),fe=H.broadcasting;await F(fe);let Fe=fe.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Fe}/ws${e.reset}`);let De=Z.join(process.cwd(),"channels.ts");if(de.existsSync(De))try{let Y=await N(De);console.log(`${e.blue}Loaded ${e.bright}${Y} broadcast channel${Y!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(Y){console.warn(`${e.yellow}Failed to load channels.ts: ${Y.message}${e.reset}`)}}catch(F){console.warn(`${e.yellow}Broadcasting failed to start: ${F.message}${e.reset}`)}}catch{}let ve=c(u,"output");de.mkdirSync(ve,{recursive:!0});let oe=new Map,Ee=new Set,ee=async(E)=>{let H=rs(T,E);if(!H)return null;try{let F=await Bun.build({entrypoints:[H],outdir:ve,plugins:[nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!F.success)return null;let N=F.outputs.find((fe)=>fe.path.endsWith(".html"));if(!N)return null;return await Bun.file(N.path).text()}catch{return null}},z=new Map,L=async(E,H)=>{try{let{processDirectives:F,extractVariables:N,defaultConfig:fe,loadStxConfig:Fe,injectRouterScript:De}=await import("./chunk-fbbp8j97.js"),{checkCache:Y,cacheTemplate:X,readFileCached:U,templateCache:ae}=await import("./chunk-18jfkg1q.js"),G=await Fe(u),Ue=(te)=>{if(!te)return te;if(Z.isAbsolute(te))return te;return Z.resolve(u,te)},re={...fe,...G,...r.stxOptions,autoShell:!0};if(r.debugDirectives)re.debug=!0;re.partialsDir=Ue(re.partialsDir),re.componentsDir=Ue(re.componentsDir),re.layoutsDir=Ue(re.layoutsDir),re.storesDir=Ue(re.storesDir||"stores"),re.cachePath=Ue(re.cachePath)??c(u,"cache");let B=!H&&!r.profile,ce=re.cache!==!1;if(ce&&B){let te=ae.get(E.filePath);if(te)try{if((await de.promises.stat(E.filePath)).mtime.getTime()<=te.mtime){let je=!0;for(let Se of te.dependencies){if(!de.existsSync(Se)){je=!1;break}if((await de.promises.stat(Se)).mtime.getTime()>te.mtime){je=!1;break}}if(je){let Se=te.output;if(P)Se=Ve(Se,{preserveHead:!0});let ot=z.get(E.filePath);return{route:E,content:Se,status:ot?.status??await ln(E.filePath),headers:ot?.headers}}}}catch{}let Le=await Y(E.filePath,re);if(Le){let Ie=Le;if(P)Ie=Ve(Ie,{preserveHead:!0});let je=z.get(E.filePath);return{route:E,content:Ie,status:je?.status??await ln(E.filePath),headers:je?.headers}}}let ne=ce?await U(E.filePath):await Bun.file(E.filePath).text(),le=un(ne),{classifyAllScripts:we}=await import("./chunk-fbbp8j97.js"),V=we(ne),Me=V.server.map((te)=>te.content),Oe=ne;for(let te of V.server)Oe=Oe.replace(te.fullTag,"");let Q={__filename:E.filePath,__dirname:Z.dirname(E.filePath),__stx_options:re,params:H??{},__stx_runtime_head:{}};for(let te of Me)try{await N(te,Q,E.filePath)}catch(Le){if(r.stxOptions?.debug)console.error("[stx] variable extraction error",E.filePath,Le?.message||Le)}let Pe=new Set,ge;if(r.profile){let te=performance.now();ge=await F(Oe,Q,E.filePath,re,Pe);let Le=performance.now()-te,Ie=Z.relative(u,E.filePath)||E.filePath;console.log(`[stx:profile] ${Ie} \u2192 ${Le.toFixed(2)}ms`)}else ge=await F(Oe,Q,E.filePath,re,Pe);if(!P)ge=await De(ge,{router:re.router});{let{interpolateScriptExpressions:te}=await import("./chunk-4m5g3f2b.js");ge=ge.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Le,Ie,je)=>{if(!/function\s+__stx_setup_/.test(je))return Le;return`<script${Ie}>${te(je,Q)}</script>`})}if(P)ge=Ve(ge,{preserveHead:!0});if(ce&&B)await X(E.filePath,ge,Pe,re);let{extractStreamBoundaries:at}=await import("./chunk-9qx6ansy.js"),Qe=at(Q),rt=Q.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let te=Q.streamBoundaries||{},Le={...re,autoShell:!1},Ie=Object.keys(rt).map((Se)=>({id:Se,render:async()=>{let ot=typeof te[Se]==="function"?await te[Se]():void 0;return F(rt[Se],{...Q,$boundary:ot},E.filePath,Le,new Set)}})),je=new Set(Ie.map((Se)=>Se.id));Qe=[...(Qe||[]).filter((Se)=>!je.has(Se.id)),...Ie]}if(Qe&&Qe.length>0)Ee.add(E.pattern);else Qe=void 0;let Wt=At(Q),Vt=Pt(Q);if(B)z.set(E.filePath,{status:Wt,headers:Vt});return{route:E,content:ge,status:Wt??le,headers:Vt,boundaries:Qe}}catch(F){return console.error(`${e.red}Error building ${e.bright}${E.pattern}${e.reset}:`,F),null}},Be=8,ze=async()=>{oe.clear(),_.clear();for(let E=0;E<k.length;E+=Be){let H=k.slice(E,E+Be),F=await Promise.all(H.map((N)=>L(N)));for(let N of F)if(N)oe.set(N.route.pattern,N)}for(let E=0;E<A.length;E+=Be){let H=A.slice(E,E+Be),F=await Promise.all(H.map(({route:N})=>L(N)));for(let N of F)if(N)_.set(N.route.pattern,N)}return oe.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await ze())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await nn(u);let Xe=s;try{if(Xe=await We(s),Xe!==s)console.log(`${e.yellow}Port ${s} is busy, using port ${Xe} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(a){let E=r.hmrPort||Xe+1;l=$t({wsPort:E,verbose:!1}),f=l.start(E)}let Ot=(E,H)=>{let N=`<script data-stx-route-params>(function(){var p=${JSON.stringify(H).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(E.includes("</head>"))return E.replace("</head>",`${N}</head>`);if(E.includes("<body"))return E.replace(/<body([^>]*)>/,`<body$1>${N}`);return N+E};console.log(`${e.blue}Starting server...${e.reset}`);let Dt=Wr({port:Xe,async fetch(E){let H=new URL(E.url),F=r.stxOptions?.offline??m.offline;if(H.pathname===to&&F?.enabled){if(!["GET","HEAD"].includes(E.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});return new Response(E.method==="HEAD"?null:no(F,Lr()),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let N=m?.publicDir||"public",fe=Z.join(u,N,H.pathname),Fe=Z.join(u,H.pathname),De=Z.join(ve,H.pathname);if([fe,Fe,De].some((B)=>w(B,u,S)))return new Response("Not Found",{status:404});let[Y,X,U]=await Promise.all([de.promises.stat(fe).catch(()=>null),de.promises.stat(Fe).catch(()=>null),de.promises.stat(De).catch(()=>null)]);if(Y?.isFile()&&!w(fe,u,S))return zt(fe);if(X?.isFile()&&!w(Fe,u,S))return zt(Fe);if(U?.isFile()&&!w(De,u,S))return zt(De);if(H.pathname.startsWith("/_stx/component/")){let B=decodeURIComponent(H.pathname.slice(16));if(B)try{let ce=`<${B} />`,ne={...buildConfig,autoShell:!1},le=await processDirectives(ce,{},Z.join(u,"components",`${B}.stx`),ne,new Set);return new Response(le,{headers:{"Content-Type":"text/html"}})}catch(ce){return new Response(`<div class="stx-async-error">${ce.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(H.pathname==="/_stx/img"){let{handleImageRequest:B}=await import("./chunk-ykjzhfyf.js"),ce=await B(E,{publicDir:Z.join(u,N),cacheDir:c(u,"cache","img")});if(ce)return ce}if(J)try{let B=await J.handleRequest(E);if(B.status!==404)return B}catch{}if(K[H.pathname])try{return await K[H.pathname](E)}catch(B){return new Response(JSON.stringify({error:B.message}),{status:500,headers:{"Content-Type":"application/json"}})}let ae=await C(E);if(ae)return ae;let G=tr(H.pathname,k);if(G){let B=oe.get(G.route.pattern),ce=Ee.has(G.route.pattern);if(G.route.isDynamic&&Object.keys(G.params).length>0||ce){let ne=await L(G.route,G.params);if(ne)B=ne}if(B){let ne=B.status??200,le=B.headers??{},we=(G.route.filePath?gt(await Bun.file(G.route.filePath).text().catch(()=>"")):null)??{};if(we.validate){if(!await we.validate({params:G.params})){let Oe=await ee(404);if(Oe){let Q=Oe;if(Q=await h(Q,u),a)Q=Ne(Q,f);return new Response(Q,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(we.middleware){let Me=kt(H.pathname,G.params,we,H.search),Oe=_t(Me,null,E,{isServer:!0}),Q=await Ct(we.middleware,Oe);if(Q.redirect){let Pe=Q.redirect.path,ge=Q.redirect.options.redirectCode||302,at=new Headers(Q.responseHeaders);return at.set("Location",Pe),new Response(null,{status:ge,headers:at})}if(Q.abort){let{statusCode:Pe,message:ge}=Q.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${Pe}</title></head><body><h1>Error ${Pe}</h1><p>${ge}</p></body></html>`,{status:Pe,headers:{"Content-Type":"text/html"}})}if(Object.keys(Q.state).length>0){let Pe=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(Q.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;B.content=B.content.replace("</head>",`${Pe}</head>`)}}let V=B.content;if(P&&Pi(E)){let Me=Ye(V),Oe=he(V),Q=V.match(/<title[^>]*>([\s\S]*?)<\/title>/i),Pe=Q?Ri(Q[1].trim()):"";if(Object.keys(G.params).length>0)V=Ot(V,G.params);V=await h(V,u);let ge=m?.router?.container||"main";return V=_e(V,ge),new Response(V,{status:ne,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Me.layout,"X-STX-Layout-Group":Me.group,"X-STX-Runtime":Oe?"true":"false",...Pe&&{"X-STX-Title":encodeURIComponent(Pe)},[oa]:Lr(),...O(),"Cache-Control":ut}})}if(P)V=Pr(P,V);if(Object.keys(G.params).length>0)V=Ot(V,G.params);if(V=await h(V,u),a)V=Ne(V,f);if(r.native)if(V.includes("<head>"))V=V.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 V="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+V;if(r.titlebarHidden)if(V.includes("<head>"))V=V.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 V=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${V}`;if(B.boundaries&&B.boundaries.length>0){let{renderStreamingPage:Me,streamToResponse:Oe}=await import("./chunk-9qx6ansy.js");return Oe(Me(V,B.boundaries,{timeoutMs:30000}),{status:ne,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(V,{status:ne,headers:{"Content-Type":"text/html",...O(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...le}})}}if(A.length>0){let B=A.map((ne)=>ne.route),ce=tr(H.pathname,B);if(ce){let ne=_.get(ce.route.pattern);if(ne){let le=ne.content;if(P)le=Pr(P,le);if(Object.keys(ce.params).length>0)le=Ot(le,ce.params);if(le=await h(le,u),a)le=Ne(le,f);return new Response(le,{status:ne.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:ne}of I)if(ne!=="/"&&H.pathname.startsWith(ne)){let le=_.get(ne)||_.get(ne+"/");if(le){let we=le.content;if(P)we=Pr(P,we);if(we=await h(we,u),a)we=Ne(we,f);return new Response(we,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(vt(H.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Ue=oe.get("/");if(Ue){let B=Ue.content;if(B=await h(B,u),a)B=Ne(B,f);if(r.native)if(B.includes("<head>"))B=B.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 B="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+B;return new Response(B,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let re=await ee(404);if(re){let B=re;if(B=await h(B,u),a)B=Ne(B,f);return new Response(B,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(E){let H=await ee(500);if(H)return new Response(H,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${E}
|
|
1430
|
+
${E.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
|
-
${e.bright}\u2192 ${e.cyan}http://localhost:${
|
|
1433
|
-
${e.yellow}Routes:${e.reset}`);let
|
|
1434
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(
|
|
1435
|
-
`).map((v)=>v.trim().replace(/^\*\s*/,"")).filter((v)=>!v.startsWith("@")&&v.length>0);m.description=C.join(" ").trim(),a.push(m)}if(a.length===0){let u=p.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(u){let m=u[1].split(",").map((b)=>b.trim()).filter(Boolean);for(let b of m){let[w]=b.split(":").map((S)=>S.trim());if(w)a.push({name:w})}}}return a}catch(r){return console.error(`Error extracting props from ${t}:`,r),[]}}async function
|
|
1436
|
-
`).map((p)=>p.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function
|
|
1432
|
+
${e.bright}\u2192 ${e.cyan}http://localhost:${Xe}/${e.reset}`),a)console.log(`${e.dim} HMR: ws://localhost:${f}${e.reset}`);console.log(`
|
|
1433
|
+
${e.yellow}Routes:${e.reset}`);let Mt=[...ss(k,u)];for(let{route:E}of A)Mt.push(`${E.pattern}`);if(Mt.forEach((E,H)=>{let N=H===Mt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${N}${e.reset}${E}`)}),console.log(`
|
|
1434
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(Dt.url.toString(),()=>{if(l)st();Dt.stop()}),r.native){let E,H=Z.join(T,"index.stx");if(de.existsSync(H)){let N=await Bun.file(H).text();E=ht(N)}let F=m?.app?.window??{};await Ze(Xe,{title:m?.app?.head?.title||Z.basename(u)||"stx App",width:F.width,height:F.height,darkMode:F.darkMode,hotReload:F.hotReload,titlebarHidden:F.titlebarHidden??r.titlebarHidden===!0,nativeSidebar:!!E,sidebarConfig:E})}if(p){console.log(`${e.blue}Watching for changes...${e.reset}`);let E=(Y)=>Y.startsWith("public/")||Y.startsWith("public\\"),H=(Y)=>{let X=Y.toLowerCase();return X.endsWith(".stx")||X.endsWith(".html")||X.endsWith(".md")},F=new Map,N=()=>{let Y=new Set([u,...m._layerGraph?.layers.map((X)=>X.root)??[],...m._layerGraph?.configDependencies.map((X)=>Z.dirname(X))??[]].filter((X)=>de.existsSync(X)).map((X)=>de.realpathSync(X)));for(let X of m._layerGraph?.layers??[])for(let U of Object.values(X.resources)){if(!de.existsSync(U))continue;let ae=de.realpathSync(U);if(![...Y].some((G)=>ae===G||ae.startsWith(`${G}${Z.sep}`)))Y.add(ae)}for(let[X,U]of F)if(!Y.has(X))U.close(),F.delete(X);for(let X of Y)if(!F.has(X)&&de.existsSync(X))F.set(X,de.watch(X,{recursive:!0},(U,ae)=>{Fe(X,U,ae).catch((G)=>console.error("[stx] Layer rebuild failed:",G))}))},fe=Promise.resolve(),Fe=(Y,X,U)=>(fe=fe.catch(()=>{}).then(()=>De(Y,X,U)),fe),De=async(Y,X,U)=>{if(!U||Tt(U))return;if(bt(U)){if(m._layerGraph){let ae=await y(u);Object.assign(m,ae),k.splice(0,k.length,...q(v,{pagesDir:x,pagesDirs:ae._layerPageDirs?[T,...ae._layerPageDirs.slice(1)]:void 0})),N()}if(E(U)){if(console.log(`${e.cyan}${U} changed${e.reset}`),a&&l)l.reload(U)}else if(H(U)){console.log(`${e.yellow}${U} changed, rebuilding...${e.reset}`),Ge.clear(),pe();try{let{invalidateFileCache:ae,templateCache:G}=await import("./chunk-18jfkg1q.js");ae(Z.resolve(Y,U)),G.delete(Z.resolve(Y,U))}catch{}if(M&&U){if(Z.resolve(Y,U)===M||Z.basename(M)===U){let G=await Hs(M,r.stxOptions||{});if(G)P=G}}if(await ze(),await Gn(u),a&&l)l.reload(U)}else{console.log(`${e.yellow}${U} changed, rebuilding...${e.reset}`),Ge.clear(),pe();try{let{invalidateFileCache:ae,templateCache:G}=await import("./chunk-18jfkg1q.js");ae(Z.resolve(Y,U)),G.delete(Z.resolve(Y,U))}catch{}if(await ze(),a&&l)l.reload(U)}}else if(yt(U)){if(console.log(`${e.cyan}CSS ${U} changed${e.reset}`),a&&l)l.updateCss(U)}};N(),process.on("SIGINT",()=>{for(let Y of F.values())Y.close();if(l)st();Dt.stop(),process.exit(0)})}return!0}import Nt from"fs";import it from"path";async function Vr(t){try{let s=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!s)return[];let p=s[1],a=[],l=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,f;while((f=l.exec(p))!==null){let u=f[1],y=f[2]||f[3]||f[4];if(!y)continue;let m={name:y},b=u.match(/@type\s+\{([^}]+)\}/i);if(b)m.type=b[1].trim();if(u.match(/@required/i))m.required=!0;let S=u.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)m.default=S[1].trim();let C=u.split(`
|
|
1435
|
+
`).map((v)=>v.trim().replace(/^\*\s*/,"")).filter((v)=>!v.startsWith("@")&&v.length>0);m.description=C.join(" ").trim(),a.push(m)}if(a.length===0){let u=p.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(u){let m=u[1].split(",").map((b)=>b.trim()).filter(Boolean);for(let b of m){let[w]=b.split(":").map((S)=>S.trim());if(w)a.push({name:w})}}}return a}catch(r){return console.error(`Error extracting props from ${t}:`,r),[]}}async function qr(t){try{let r=await Bun.file(t).text(),s=r.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||r.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(s)return s[1].split(`
|
|
1436
|
+
`).map((p)=>p.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Kr(t,r=!1,s){let p=it.basename(t,".stx"),a=await Vr(t),l=await qr(t),f="";if(r&&s)f=`<${s}></${s}>`;else{let u=a.map((y)=>{if(y.type==="boolean")return`:${y.name}="true"`;return`${y.name}="value"`}).join(`
|
|
1437
1437
|
`);f=`<${p}
|
|
1438
1438
|
${u}
|
|
1439
|
-
/>`}return{name:p,path:t,description:l,props:a,example:f,isWebComponent:r,tag:s}}async function
|
|
1440
|
-
`).map((x)=>x.trim().replace(/^\*\s*/,"")).join(" ").trim():"",m=/@component\(\s*['"]([^'"]+)['"]/g,b=/<([A-Z][a-zA-Z0-9]*|[a-z]+-[a-z0-9-]+)(?:\s[^>]*)?\/?>|\{\{\s*slot\s*\}\}/g,w=new Set,S;while((S=m.exec(l))!==null)w.add(S[1]);while((S=b.exec(l))!==null)if(S[1]&&S[1]!=="slot")w.add(S[1]);let C=/@([a-z]+)(?:\s*\(|\s+|$)/g,v=new Set;while((S=C.exec(l))!==null)v.add(S[1]);s.push({name:f,path:a,description:y,components:[...w],directives:[...v]})}return s}catch(r){return console.error("Error generating template docs:",r),[]}}async function
|
|
1439
|
+
/>`}return{name:p,path:t,description:l,props:a,example:f,isWebComponent:r,tag:s}}async function dn(t){try{if(!await n(t))return console.warn(`Components directory does not exist: ${t}`),[];let r=await Nt.promises.readdir(t,{withFileTypes:!0}),s=[];for(let p of r){let a=it.join(t,p.name);if(p.isDirectory()){let l=await dn(a);s.push(...l)}else if(p.isFile()&&p.name.endsWith(".stx"))s.push(a)}return s}catch(r){return console.error(`Error finding component files in ${t}:`,r),[]}}async function Xr(t,r){try{if(!await n(t))return[];let s=await dn(t),p=[],a=new Map;if(r?.components?.length)for(let l of r.components)a.set(l.file,l);for(let l of s){let f=a.get(l),u=!!f,y=f?.tag,m=await Kr(l,u,y);p.push(m)}return p}catch(s){return console.error("Error generating component docs:",s),[]}}async function Gr(t){try{if(!await n(t))return[];let r=await Nt.promises.readdir(t,{withFileTypes:!0}),s=[];for(let p of r){if(!p.isFile()||!p.name.endsWith(".stx"))continue;let a=it.join(t,p.name),l=await Bun.file(a).text(),f=it.basename(a,".stx"),u=l.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||l.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//),y=u?u[1].split(`
|
|
1440
|
+
`).map((x)=>x.trim().replace(/^\*\s*/,"")).join(" ").trim():"",m=/@component\(\s*['"]([^'"]+)['"]/g,b=/<([A-Z][a-zA-Z0-9]*|[a-z]+-[a-z0-9-]+)(?:\s[^>]*)?\/?>|\{\{\s*slot\s*\}\}/g,w=new Set,S;while((S=m.exec(l))!==null)w.add(S[1]);while((S=b.exec(l))!==null)if(S[1]&&S[1]!=="slot")w.add(S[1]);let C=/@([a-z]+)(?:\s*\(|\s+|$)/g,v=new Set;while((S=C.exec(l))!==null)v.add(S[1]);s.push({name:f,path:a,description:y,components:[...w],directives:[...v]})}return s}catch(r){return console.error("Error generating template docs:",r),[]}}async function Yr(t=[]){try{let r=[{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)
|
|
1443
1443
|
<p>Welcome back!</p>
|
|
@@ -1457,7 +1457,7 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(Ot.
|
|
|
1457
1457
|
<p>Page {{ page }}</p>
|
|
1458
1458
|
@endwhile`},{name:"component",description:"Include a component in the template",hasEndTag:!1,example:'@component("alert", { type: "warning", title: "Warning", message: "This is a warning" })'},{name:"include",description:"Include a partial template",hasEndTag:!1,example:'@include("partials/header")'},{name:"raw",description:"Display content without processing expressions",hasEndTag:!0,example:`@raw
|
|
1459
1459
|
{{ This will be displayed as-is }}
|
|
1460
|
-
@endraw`},{name:"translate",description:"Translate a string using the i18n system",hasEndTag:!1,example:'@translate("welcome.message", { name: user.name })'},{name:"t",description:"Short alias for translate directive",hasEndTag:!1,example:'@t("welcome.message", { name: user.name })'}];for(let s of t)r.push({name:s.name,description:s.description||"",hasEndTag:s.hasEndTag||!1,example:""});return r}catch(r){return console.error("Error generating directive docs:",r),[]}}function
|
|
1460
|
+
@endraw`},{name:"translate",description:"Translate a string using the i18n system",hasEndTag:!1,example:'@translate("welcome.message", { name: user.name })'},{name:"t",description:"Short alias for translate directive",hasEndTag:!1,example:'@t("welcome.message", { name: user.name })'}];for(let s of t)r.push({name:s.name,description:s.description||"",hasEndTag:s.hasEndTag||!1,example:""});return r}catch(r){return console.error("Error generating directive docs:",r),[]}}function Qr(t=[],r=[],s=[],p){let a=`# stx Documentation
|
|
1461
1461
|
|
|
1462
1462
|
`;if(p)a+=`${p}
|
|
1463
1463
|
|
|
@@ -1499,7 +1499,7 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(Ot.
|
|
|
1499
1499
|
|
|
1500
1500
|
`,a+=`#### Example
|
|
1501
1501
|
|
|
1502
|
-
`,a+="```html\n",a+=l.example,a+="\n```\n\n"}return a}function
|
|
1502
|
+
`,a+="```html\n",a+=l.example,a+="\n```\n\n"}return a}function Zr(t=[],r=[],s=[],p){let a=`<!DOCTYPE html>
|
|
1503
1503
|
<html lang="en">
|
|
1504
1504
|
<head>
|
|
1505
1505
|
<meta charset="UTF-8">
|
|
@@ -1570,15 +1570,15 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(Ot.
|
|
|
1570
1570
|
<td>@${l.name}</td>
|
|
1571
1571
|
<td>${l.description||"-"}</td>
|
|
1572
1572
|
<td>${l.hasEndTag?"Yes":"No"}</td>
|
|
1573
|
-
</tr>`;a+="</tbody></table>";for(let l of s)if(l.example)a+=`<h3>@${l.name}</h3>`,a+=`<p>${l.description||""}</p>`,a+="<h4>Example</h4>",a+=`<pre><code>${l.example.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}</code></pre>`}return a+="</body></html>",a}function
|
|
1574
|
-
`;let p=t;if(s.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,"");if(p=
|
|
1573
|
+
</tr>`;a+="</tbody></table>";for(let l of s)if(l.example)a+=`<h3>@${l.name}</h3>`,a+=`<p>${l.description||""}</p>`,a+="<h4>Example</h4>",a+=`<pre><code>${l.example.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}</code></pre>`}return a+="</body></html>",a}function eo(t=[],r=[],s=[],p){return JSON.stringify({components:t,templates:r,directives:s,extraContent:p||""},null,2)}async function ro(t){try{let{componentsDir:r,templatesDir:s,webComponentsConfig:p,customDirectives:a,config:l}=t;if(!l.enabled)return!1;let f=l.outputDir||"docs";if(await Nt.promises.mkdir(f,{recursive:!0}),console.log("Generating documentation..."),r)console.log(`Components directory: ${r}`);if(s)console.log(`Templates directory: ${s}`);console.log(`Output directory: ${f}`);let u=[];if(l.components!==!1&&r)console.log("Generating component documentation..."),u=await Xr(r,p),console.log(`Found ${u.length} components`);let y=[];if(l.templates!==!1&&s)console.log("Generating template documentation..."),y=await Gr(s),console.log(`Found ${y.length} templates`);let m=[];if(l.directives!==!1)console.log("Generating directive documentation..."),m=await Yr(a),console.log(`Found ${m.length} directives`);let b=l.format||"markdown",w=l.extraContent,S="",C="";switch(b){case"markdown":S=Qr(u,y,m,w),C="md";break;case"html":S=Zr(u,y,m,w),C="html";break;case"json":S=eo(u,y,m,w),C="json";break;default:throw Error(`Unsupported documentation format: ${b}`)}let v=it.join(f,`stx-docs.${C}`);return await Bun.write(v,S),console.log(`Documentation generated: ${v}`),!0}catch(r){return console.error("Error generating documentation:",r),!1}}async function vi(t){let r={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},s=t.componentsDir||R.componentsDir,p=t.templatesDir||".";return ro({componentsDir:s,templatesDir:p,webComponentsConfig:R.webComponents,customDirectives:R.customDirectives,config:r})}var fn={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0};function Ns(t,r={}){let s={...fn,...r};if(t.trim()==="")return`
|
|
1574
|
+
`;let p=t;if(s.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,"");if(p=io(p,s),p=po(p,s),p=ao(p,s),s.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,""),p=p.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(p=p.replace(/\r\n/g,`
|
|
1575
1575
|
`).replace(/\r/g,`
|
|
1576
1576
|
`),!p.endsWith(`
|
|
1577
1577
|
`))p+=`
|
|
1578
|
-
`;return p}function
|
|
1578
|
+
`;return p}function wi(t,r={}){let s={...fn,...r};if(t.trim()==="")return`
|
|
1579
1579
|
`;let p=t;if(p=p.replace(/^( *)```(html|stx)\n([\s\S]*?)^( *)```/gm,(a,l,f,u,y)=>{let m=u.split(`
|
|
1580
1580
|
`),b=m.filter((x)=>x.trim().length>0);if(b.length===0)return a;let w=Math.min(...b.map((x)=>{let T=x.match(/^( *)/);return T?T[1].length:0})),S=m.map((x)=>{if(x.trim().length===0)return"";return x.substring(w)}).join(`
|
|
1581
|
-
`),v=
|
|
1581
|
+
`),v=Ns(S,s).trimEnd().split(`
|
|
1582
1582
|
`).map((x)=>{if(x.trim().length===0)return"";return l+x}).join(`
|
|
1583
1583
|
`);return`${l}\`\`\`${f}
|
|
1584
1584
|
${v}
|
|
@@ -1586,7 +1586,7 @@ ${l}\`\`\``}),s.trimTrailingWhitespace)p=p.replace(/[ \t]+$/gm,"");if(p=p.replac
|
|
|
1586
1586
|
`).replace(/\r/g,`
|
|
1587
1587
|
`),!p.endsWith(`
|
|
1588
1588
|
`))p+=`
|
|
1589
|
-
`;return p}function
|
|
1589
|
+
`;return p}function so(t){let r=t,s=[],p="__PROTECTED_BLOCK_";return r=r.replace(/(<(?:pre|code|textarea)[^>]*>)([\s\S]*?)(<\/(?:pre|code|textarea)>)/gi,(a)=>{let l=s.length;return s.push(a),`${p}${l}__`}),r=r.replace(/(@(?:if|foreach|for|while|unless|section|component|slot|push|prepend|error|auth|guest|can)(?:\((?:[^()'"]|'[^']*'|"[^"]*"|\((?:[^()'"]|'[^']*'|"[^"]*")*\))*\))?)/g,`
|
|
1590
1590
|
$1
|
|
1591
1591
|
`),r=r.replace(/(@end\w+)/g,`
|
|
1592
1592
|
$1
|
|
@@ -1600,10 +1600,10 @@ ${f}`}),r=r.replace(/(<\/[^>]+>)(?=<|$)/g,(a,l,f,u)=>{let y=u.substring(Math.max
|
|
|
1600
1600
|
`}),r=r.replace(new RegExp(`${p}(\\d+)__`,"g"),(a,l)=>s[Number.parseInt(l,10)]),r=r.replace(/\n{2,}/g,`
|
|
1601
1601
|
`),r=r.split(`
|
|
1602
1602
|
`).map((a)=>a.trim()).join(`
|
|
1603
|
-
`),r=r.replace(/^\n+/,"").replace(/\n+$/,""),r}function
|
|
1604
|
-
`),a=[],l=0,f=!1,u=r.useTabs?"\t":" ".repeat(r.indentSize);for(let y=0;y<p.length;y++){let m=p[y],b=m.trim();if(b===""){a.push("");continue}let w=b.match(/<script\b/i),S=b.match(/<\/script>/i);if(f&&!S){a.push(m);continue}let C=b===">";if(
|
|
1605
|
-
`)}function
|
|
1606
|
-
`)||a.includes("@"))return s;let l=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,f=[],u;while((u=l.exec(a))!==null)f.push({name:u[1],value:u[2]});f.sort((m,b)=>{if(m.name==="id")return-1;if(b.name==="id")return 1;if(m.name==="class")return-1;if(b.name==="class")return 1;return m.name.localeCompare(b.name)});let y=f.map((m)=>m.value?`${m.name}=${m.value}`:m.name).join(" ");return`<${p}${y?` ${y}`:""}>`})}import
|
|
1603
|
+
`),r=r.replace(/^\n+/,"").replace(/\n+$/,""),r}function io(t,r){let p=so(t).split(`
|
|
1604
|
+
`),a=[],l=0,f=!1,u=r.useTabs?"\t":" ".repeat(r.indentSize);for(let y=0;y<p.length;y++){let m=p[y],b=m.trim();if(b===""){a.push("");continue}let w=b.match(/<script\b/i),S=b.match(/<\/script>/i);if(f&&!S){a.push(m);continue}let C=b===">";if(pn(b)&&!b.startsWith("<")&&!b.startsWith("@")){a.push(u.repeat(l)+b);continue}let v=b.startsWith("@end"),x=b.startsWith("@else")||b.startsWith("@elseif"),T=b.startsWith("@")&&lo(b),k=b.startsWith("<!DOCTYPE")||b.startsWith("<!doctype"),I=b.startsWith("<!--"),A=b.startsWith("</"),_=b.startsWith("<")&&!A&&!I&&!k,P=b.includes("/>")||co(b),M=pn(b);if(A||v)l=Math.max(0,l-1);let j=x?Math.max(0,l-1):l;if(C)a.push(m);else a.push(u.repeat(j)+b);if(_&&!P&&!M&&!C||T)l++;if(w)f=!0;if(S)f=!1}return a.join(`
|
|
1605
|
+
`)}function ao(t,r){if(t=t.replace(/@(if|elseif|foreach|for|while)\s*\(\s*([^)]+)\s*\)/g,(s,p,a)=>{let l=a.trim().replace(/\s+/g," ");return`@${p}(${l})`}),t=t.replace(/@(csrf|method)\s*\(\s*([^)]*)\s*\)/g,(s,p,a)=>{if(a.trim()==="")return`@${p}`;return`@${p}(${a.trim()})`}),r.normalizeWhitespace)t=t.replace(/\{\{\s*([^}]+)\s*\}\}/g,(s,p)=>`{{ ${p.trim()} }}`),t=t.replace(/\{!!\s*([^!]+)\s*!!\}/g,(s,p)=>`{!! ${p.trim()} !!}`);return t}function co(t){let r=["br","hr","img","input","meta","link","area","base","col","embed","source","track","wbr"];if(t.includes("/>"))return!0;let s=t.match(/<(\w+)/);if(s){let p=s[1];return r.includes(p.toLowerCase())}return!1}function pn(t){return/<(\w+)(?:\s[^>]*)?>[\s\S]*?<\/\1>/.test(t)}function lo(t){let r=["if","unless","foreach","for","while","section","push","component","slot","markdown","wrap","error"];for(let s of r)if(t.startsWith(`@${s}`))return!t.includes(`@end${s}`);return!1}function po(t,r){if(!r.sortAttributes)return t;return t.replace(/<(\w+)([^>]*)>/g,(s,p,a)=>{if(!a.trim())return s;if(a.includes("<")||a.includes(`
|
|
1606
|
+
`)||a.includes("@"))return s;let l=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,f=[],u;while((u=l.exec(a))!==null)f.push({name:u[1],value:u[2]});f.sort((m,b)=>{if(m.name==="id")return-1;if(b.name==="id")return 1;if(m.name==="class")return-1;if(b.name==="class")return 1;return m.name.localeCompare(b.name)});let y=f.map((m)=>m.value?`${m.name}=${m.value}`:m.name).join(" ");return`<${p}${y?` ${y}`:""}>`})}import mn from"fs";import Ut from"path";async function xi(t="index.stx",r={}){try{let s=r.force||!1,p=Ut.resolve(process.cwd(),t);if(await Bun.file(p).exists()){if(!s)throw Error(`File ${t} already exists. Use --force to overwrite.`);console.warn(`File ${t} already exists. Overwriting...`)}let a=Ut.dirname(p);if(!mn.existsSync(a))mn.mkdirSync(a,{recursive:!0});let l;if(r.template){let f=Ut.resolve(process.cwd(),r.template);if(!await Bun.file(f).exists())throw Error(`Template file ${r.template} does not exist.`);if(!f.endsWith(".stx"))console.warn(`Warning: Template file ${r.template} does not have a .stx extension. Using it anyway.`);l=await Bun.file(f).text(),console.warn(`Using template from ${r.template}`)}else if(r.preset)l=gn(r.preset),console.warn(`Using '${r.preset}' preset template`);else l=gn("basic");return await Bun.write(p,l),console.warn(`Created new stx file: ${t}`),!0}catch(s){return console.error(`Error creating file: ${s instanceof Error?s.message:String(s)}`),!1}}function gn(t){switch(t){case"basic":return hn();case"component":return uo();case"layout":return fo();case"blog":return mo();case"api":return go();case"app":return ho();default:return hn()}}function hn(){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 uo(){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>
|
|
@@ -1673,7 +1673,7 @@ const features = [
|
|
|
1673
1673
|
.card.collapsed .card__toggle { transform: rotate(-90deg); }
|
|
1674
1674
|
.card__body { padding: 1rem; }
|
|
1675
1675
|
.card.collapsed .card__body { display: none; }
|
|
1676
|
-
</style>`}function
|
|
1676
|
+
</style>`}function fo(){return`<!DOCTYPE html>
|
|
1677
1677
|
<html lang="en">
|
|
1678
1678
|
<head>
|
|
1679
1679
|
<meta charset="UTF-8">
|
|
@@ -1724,7 +1724,7 @@ const features = [
|
|
|
1724
1724
|
|
|
1725
1725
|
@yield('scripts')
|
|
1726
1726
|
</body>
|
|
1727
|
-
</html>`}function
|
|
1727
|
+
</html>`}function mo(){return`<script>
|
|
1728
1728
|
// Article metadata
|
|
1729
1729
|
const title = "My Blog Post"
|
|
1730
1730
|
const author = "Your Name"
|
|
@@ -1769,7 +1769,7 @@ const features = [
|
|
|
1769
1769
|
<p>Wrap up your thoughts here.</p>
|
|
1770
1770
|
</div>
|
|
1771
1771
|
</article>
|
|
1772
|
-
@endsection`}function
|
|
1772
|
+
@endsection`}function go(){return`<script>
|
|
1773
1773
|
// API endpoint configuration
|
|
1774
1774
|
const endpoint = "/api/data"
|
|
1775
1775
|
const method = "GET"
|
|
@@ -1804,7 +1804,7 @@ const features = [
|
|
|
1804
1804
|
}
|
|
1805
1805
|
@else
|
|
1806
1806
|
{{ JSON.stringify(data, null, 2) }}
|
|
1807
|
-
@endif`}function
|
|
1807
|
+
@endif`}function ho(){return`<!DOCTYPE html>
|
|
1808
1808
|
<html lang="en">
|
|
1809
1809
|
<head>
|
|
1810
1810
|
<meta charset="UTF-8">
|
|
@@ -2029,5 +2029,5 @@ const features = [
|
|
|
2029
2029
|
})();
|
|
2030
2030
|
</script>
|
|
2031
2031
|
</body>
|
|
2032
|
-
</html>`}var
|
|
2033
|
-
`)}export{
|
|
2032
|
+
</html>`}var Si="f9c3713";function Ec(t){return t}function Tc(t){return t}function hi(t,r){let s=[],p=`${r}=`;for(let a=0;a<t.length;a++){let l=t[a];if(l.startsWith(p)){let f=l.slice(p.length);if(f)s.push(f);continue}if(l===r){let f=t[a+1];if(f!==void 0&&!f.startsWith("-"))s.push(f),a++}}return s}import Ae from"fs";import be from"path";function Cn(t){try{return Ae.statSync(t).mtimeMs}catch{return null}}function Et(t,r){let s=Math.max(0,Math.round((r-t)/1000));if(s<60)return`${s}s ago`;if(s<3600)return`${Math.round(s/60)}m ago`;return`${Math.round(s/3600)}h ago`}function Mi(t,r){try{return globalThis.Bun?.resolveSync(t,r)??null}catch{return null}}function Rn(t,r="stx"){let s=be.resolve(t);for(let p=0;p<10;p++){let a=be.join(s,"pantry","@stacksjs",r);if(Ae.existsSync(a))return a;let l=be.dirname(s);if(l===s)break;s=l}return null}var En=["@stacksjs/stx","bun-plugin-stx"];function _i(t){try{let r=Ae.readFileSync(be.join(t,"package.json"),"utf8"),s=JSON.parse(r)?.version;return typeof s==="string"?s:null}catch{return null}}function Li(t,r=6){let s=be.resolve(t),p=[],a=new Set;function l(u,y){if(y>r)return;let m;try{m=Ae.realpathSync(u)}catch{return}if(a.has(m))return;a.add(m);for(let w of En){let S=be.join(u,w),C=_i(S);if(C!==null)p.push({name:w,version:C,dir:be.relative(s,S)||S,nested:y>0})}let b;try{b=Ae.readdirSync(u,{withFileTypes:!0})}catch{return}for(let w of b){if(!w.isDirectory()&&!w.isSymbolicLink())continue;if(w.name===".bin"||w.name===".cache")continue;let S=be.join(u,w.name);if(w.name.startsWith("@")){let v;try{v=Ae.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let x of v){let T=be.join(S,x.name,"node_modules");if(Ae.existsSync(T))l(T,y+1)}continue}let C=be.join(S,"node_modules");if(Ae.existsSync(C))l(C,y+1)}}let f=be.join(s,"node_modules");if(Ae.existsSync(f))l(f,0);return p}function Ii(t){let r=[];for(let s of En){let p=t.filter((f)=>f.name===s);if(p.length<=1)continue;let a=[...new Set(p.map((f)=>f.version))],l=p.map((f)=>`${f.version} at ${f.dir}`).join("; ");if(a.length===1){r.push({name:`${s} copies`,status:"info",detail:`${p.length} copies, all ${a[0]} \u2014 duplicated but in agreement`});continue}r.push({name:`${s} copies disagree`,status:"error",detail:`${a.length} versions installed, so which one runs depends on who imports it: ${l}`,fix:`remove the nested copies, or add an overrides entry pinning ${s}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${s}/package.json' -exec grep -H '"version"' {} +`})}return r}async function Ds(t={}){let r=t.cwd?be.resolve(t.cwd):process.cwd(),s=t.resolve??Mi,p=Date.now(),a=[],l=s("@stacksjs/stx",r);a.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 f=s("bun-plugin-stx",r);if(f)a.push({name:"bun-plugin-stx resolves to",status:"ok",detail:f});for(let y of Ii(Li(r)))a.push(y);let u=Rn(r,"stx");if(!u)a.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let y=be.join(u,"src/signals.ts"),m=[be.join(u,"dist/index.js"),be.join(u,"dist/signals.js")].find((v)=>Ae.existsSync(v))||null,b=Cn(y),w=m?Cn(m):null;if(b==null)a.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${u} but no src/signals.ts to compare`});else if(w==null)a.push({name:"pantry dist freshness",status:"error",detail:"pantry has src but no built dist \u2014 the dev server will resolve nothing (or a stale copy elsewhere)",fix:`cd ${u} && bun build.ts`});else if(w<b){let v=Math.round((b-w)/1000);a.push({name:"pantry dist freshness",status:"error",detail:`dist (${Et(w,p)}) is OLDER than src/signals.ts (${Et(b,p)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${u} && bun build.ts`})}else a.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Et(b,p)}, dist ${Et(w,p)})`});let S=be.join(r,"node_modules/@stacksjs/stx"),C=null;try{C=Ae.lstatSync(S)}catch{C=null}if(!C)a.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(C.isSymbolicLink()){let v=null;try{v=Ae.realpathSync(S)}catch{}let x=(()=>{try{return Ae.realpathSync(u)}catch{return u}})();a.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 a.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(a.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 m=t.generateRuntime().length;a.push(m>1000?{name:"signals runtime",status:"ok",detail:`generated ${m.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${m} chars \u2014 suspiciously short`})}catch(y){a.push({name:"signals runtime",status:"error",detail:`failed to generate: ${y.message}`})}return{checks:a,ok:!a.some((y)=>y.status==="error")}}function Ms(t){let r={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},s=["stx runtime resolution:"];for(let p of t.checks)if(s.push(` ${r[p.status]} ${p.name}: ${p.detail}`),p.fix)s.push(` \u2192 ${p.fix}`);return s.push(""),s.push(t.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),s.join(`
|
|
2033
|
+
`)}export{hi,yi,bi,vi,Ns,wi,xi,Si,Ec,Tc,Ds,Ms,Cr,Er,Tr};
|