@stacksjs/stx 0.2.682 → 0.2.683
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-np3zdjhr.js → chunk-0h22d9cb.js} +1 -1
- package/dist/{chunk-4g9wrxkm.js → chunk-0t65m9nw.js} +1 -1
- package/dist/{chunk-ev1tnd36.js → chunk-1dbw2j4q.js} +1 -1
- package/dist/{chunk-yhfm939b.js → chunk-246k73ga.js} +1 -1
- package/dist/chunk-29c177cz.js +2 -0
- package/dist/{chunk-veh25cv5.js → chunk-2rvprm39.js} +1 -1
- package/dist/{chunk-bmv6spcd.js → chunk-3353tc28.js} +1 -1
- package/dist/{chunk-pmma4f1x.js → chunk-3vgfwsft.js} +1 -1
- package/dist/{chunk-s0wa7zjr.js → chunk-3waphqhe.js} +1 -1
- package/dist/{chunk-4m5g3f2b.js → chunk-551vqymy.js} +1 -1
- package/dist/{chunk-n8jq9yjy.js → chunk-56w1njc8.js} +1 -1
- package/dist/{chunk-5nrqc6v4.js → chunk-5wpny9k3.js} +1 -1
- package/dist/{chunk-zr16mga0.js → chunk-6rrr362d.js} +1 -1
- package/dist/{chunk-5rdfcpfe.js → chunk-70fdw728.js} +1 -1
- package/dist/{chunk-wfg5379k.js → chunk-7fgsqs43.js} +2 -2
- package/dist/{chunk-rs67af2x.js → chunk-840aejkc.js} +5 -5
- package/dist/chunk-8s10jjf1.js +2 -0
- package/dist/{chunk-r8hszntk.js → chunk-979g7g0r.js} +1 -1
- package/dist/{chunk-7yree929.js → chunk-aenajaxk.js} +1 -1
- package/dist/{chunk-0527ytat.js → chunk-bsvwzma0.js} +1 -1
- package/dist/chunk-c3dqsjv0.js +2 -0
- package/dist/{chunk-g2v6c7kf.js → chunk-cd6s5k6e.js} +1 -1
- package/dist/{chunk-hg7ys8rn.js → chunk-cfbev664.js} +1 -1
- package/dist/{chunk-1t6dg4s8.js → chunk-d2nkm1jt.js} +1 -1
- package/dist/{chunk-qb806pks.js → chunk-d4f6dkrt.js} +1 -1
- package/dist/{chunk-ypwetty7.js → chunk-drd4t5v4.js} +2 -2
- package/dist/chunk-e1fgpb46.js +2 -0
- package/dist/{chunk-65jb75vz.js → chunk-ff3d0eh9.js} +1 -1
- package/dist/{chunk-8nk56cs2.js → chunk-g93jkztp.js} +1 -1
- package/dist/{chunk-remsyfdx.js → chunk-gny4j06b.js} +1 -1
- package/dist/chunk-hfk17t81.js +2 -0
- package/dist/{chunk-fqts9wvd.js → chunk-j87n6mh0.js} +2 -2
- package/dist/chunk-jf717wps.js +2 -0
- package/dist/{chunk-18jfkg1q.js → chunk-jg4932ma.js} +1 -1
- package/dist/{chunk-b5vqp3b2.js → chunk-js8ytnrn.js} +1 -1
- package/dist/{chunk-xfdfk4g4.js → chunk-kbagpk8a.js} +1 -1
- package/dist/{chunk-brcj3953.js → chunk-kbt9r41q.js} +1 -1
- package/dist/{chunk-1gw26g89.js → chunk-kq8t4xn9.js} +2 -2
- package/dist/chunk-mjqf15e7.js +2 -0
- package/dist/chunk-p1a6y65v.js +2 -0
- package/dist/{chunk-bv43s0gx.js → chunk-p21prjzh.js} +1 -1
- package/dist/{chunk-e97xj3rf.js → chunk-px9p7q26.js} +4 -4
- package/dist/{chunk-f1hxrs7b.js → chunk-q7z1ybcn.js} +1 -1
- package/dist/{chunk-z5av310q.js → chunk-qjccq0yd.js} +1 -1
- package/dist/{chunk-47fwr1z7.js → chunk-qpvasda5.js} +1 -1
- package/dist/{chunk-5nfb4gxk.js → chunk-qq40hxg9.js} +6 -6
- package/dist/{chunk-rk8kmshp.js → chunk-sk2ae1qj.js} +1 -1
- package/dist/{chunk-tdwqwxhf.js → chunk-smdxvjhn.js} +1 -1
- package/dist/{chunk-4z4sqc8q.js → chunk-sme7phry.js} +1 -1
- package/dist/{chunk-bmqker64.js → chunk-t0644y3k.js} +2 -2
- package/dist/{chunk-h3bdqqzy.js → chunk-t257ye4c.js} +1 -1
- package/dist/{chunk-th45zgbz.js → chunk-thkw9ez9.js} +4 -4
- package/dist/{chunk-se4n8tth.js → chunk-tkypg1xx.js} +1 -1
- package/dist/{chunk-3tkag58v.js → chunk-wbn3x66p.js} +1 -1
- package/dist/{chunk-ka3xmbrd.js → chunk-xv8yy1cz.js} +5 -5
- package/dist/{chunk-hwaqwrc2.js → chunk-yfr4tsn1.js} +1 -1
- package/dist/chunk-yq9dtdkn.js +2 -0
- package/dist/{chunk-g83qeh2x.js → chunk-yrq24gyy.js} +3 -3
- package/dist/chunk-yxy3brpr.js +2 -0
- package/dist/chunk-z9xhpkn6.js +2 -0
- package/dist/{chunk-42qtadka.js → chunk-zj5x4yk2.js} +2 -2
- package/dist/{chunk-96hkch4q.js → chunk-zx468wjw.js} +1 -1
- package/dist/cli.js +7 -7
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/pwa.js +1 -1
- package/dist/ssg.js +2 -2
- package/package.json +5 -5
- package/dist/chunk-0gmwqhs0.js +0 -2
- package/dist/chunk-34ps2w1z.js +0 -2
- package/dist/chunk-9qx6ansy.js +0 -2
- package/dist/chunk-b375wt1n.js +0 -2
- package/dist/chunk-f80aqbwm.js +0 -2
- package/dist/chunk-fbbp8j97.js +0 -2
- package/dist/chunk-fy1waxy0.js +0 -2
- package/dist/chunk-g9a56wwk.js +0 -2
- package/dist/chunk-h5r4c9v5.js +0 -2
- package/dist/chunk-jecmxby7.js +0 -2
- package/dist/chunk-q7mpearc.js +0 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{B}from"./chunk-
|
|
2
|
+
import{B}from"./chunk-qq40hxg9.js";import{Be,A,Nt}from"./chunk-t6m5d64b.js";import{ut,ke,O,_e,Ni,Vs,Di,Cn}from"./chunk-kq8t4xn9.js";import{vt,le,Ye}from"./chunk-gymmbbzc.js";import{Qs}from"./chunk-d4f6dkrt.js";import{En}from"./chunk-pfn70zdr.js";import{he}from"./chunk-px9p7q26.js";import Z from"fs";import T from"path";var{serve:ce}=globalThis.Bun;import F from"zlib";import{promisify as Q}from"util";var K=Q(F.brotliCompress),ee=Q(F.gzip),te=["text/","application/json","application/javascript","application/xml","application/xhtml+xml","application/rss+xml","application/atom+xml","application/manifest+json","image/svg+xml"],ne=["text/event-stream","multipart/x-mixed-replace"],re=1024;function se(t){if(!t)return!1;let e=t.toLowerCase();if(ne.some((o)=>e.startsWith(o)))return!1;return te.some((o)=>e.startsWith(o))}function oe(t){let e=new Map;for(let o of t.split(",")){let[r,...a]=o.trim().split(";"),f=r.trim().toLowerCase();if(!f)continue;let h=1;for(let g of a){let l=/^\s*q\s*=\s*([\d.]+)\s*$/i.exec(g);if(!l)continue;let m=Number.parseFloat(l[1]);if(Number.isFinite(m))h=m}e.set(f,h)}return e}function ae(t){if(!t)return null;let e=oe(t),o=e.get("*"),r=(a)=>e.get(a)??o??0;if(r("br")>0)return"br";if(r("gzip")>0)return"gzip";return null}var Y=33554432,H=new Map,U=0;function ie(t,e){if(e.length>Y/8)return;H.set(t,e),U+=e.length;for(let[o,r]of H){if(U<=Y)break;H.delete(o),U-=r.length}}async function kn(t,e,o={}){if(e.headers.get("content-encoding"))return e;if(e.status===204||e.status===304||!e.body)return e;if(!se(e.headers.get("content-type")))return e;let r=ae(t.headers.get("accept-encoding"));if(!r)return e;let a;try{a=new Uint8Array(await e.arrayBuffer())}catch{return e}let f=()=>new Response(a,{status:e.status,statusText:e.statusText,headers:J(e.headers)});if(a.length<(o.threshold??re))return f();try{let h=o.quality??5,g=`${r}:${h}:${a.length}:${Bun.hash(a)}`,l=H.get(g);if(!l)l=r==="br"?await K(a,{params:{[F.constants.BROTLI_PARAM_QUALITY]:h,[F.constants.BROTLI_PARAM_SIZE_HINT]:a.length}}):await ee(a),ie(g,l);if(l.length>=a.length)return f();let m=J(e.headers);return m.set("Content-Encoding",r),m.set("Content-Length",String(l.length)),new Response(l,{status:e.status,statusText:e.statusText,headers:m})}catch{return f()}}function J(t){let e=new Headers(t),o=e.get("Vary");if(!o)return e.set("Vary","Accept-Encoding"),e;if(!o.split(",").some((a)=>a.trim().toLowerCase()==="accept-encoding"))e.set("Vary",`${o}, Accept-Encoding`);return e}class G{now;entries=new B(1000,{maxBytes:33554432,sizeOf:(t)=>t.body.byteLength+JSON.stringify(t.headers).length*2});pending=new Map;generation=0;constructor(t=Date.now){this.now=t}invalidate(t){this.generation++,this.pending.clear();for(let e of Array.from(this.entries.keys()))if(t===void 0||this.entries.get(e)?.path===t)this.entries.delete(e)}async respond(t,e,o){let r,a=async()=>{let s=r??await o();return s.headers.set("Cache-Control","private, no-store"),s.headers.set("Vary",O(s.headers.get("Vary")).Vary),s};if(!e||t.method!=="GET"||t.headers.has("Cookie")||t.headers.has("Authorization")||t.headers.has("Range"))return a();let f=new URL(t.url),h=`${f.origin}${f.pathname}${f.search}|${ke(t)?"fragment":"document"}`,g=this.entries.get(h),l=(s)=>{let b=new Headers(s.headers);return b.set("Cache-Control","private, no-store"),b.set("Age",String(Math.max(0,Math.floor((this.now()-s.created)/1000)))),new Response(s.body.slice(0),{headers:b})},m=g?(this.now()-g.created)/1000:1/0;if(g&&m<e.maxAge)return l(g);let v=this.generation,N=async()=>{let s=await o();r=s;let b=(s.headers.get("Vary")??"").toLowerCase().split(",").map((y)=>y.trim()).filter(Boolean);if(s.status!==200||s.headers.has("Set-Cookie")||/(?:private|no-store|no-cache)/i.test(s.headers.get("Cache-Control")??"")||b.some((y)=>y!=="x-stx-router"&&y!=="accept-encoding"))return null;let E=await s.clone().arrayBuffer();if(E.byteLength>1048576)return null;s.headers.set("Vary",O(s.headers.get("Vary")).Vary);let n={body:E,headers:Array.from(s.headers.entries()),created:this.now(),path:f.pathname};if(this.generation===v)this.entries.set(h,n);return n},x=this.pending.get(h);if(!x){if(this.pending.size>=1000)return a();x=N().finally(()=>{if(this.pending.get(h)===x)this.pending.delete(h)}),this.pending.set(h,x)}if(g&&m<e.maxAge+(e.swr??0))return x.catch(()=>{}),l(g);let M=await x;return M?l(M):a()}}var pe={".js":"application/javascript",".mjs":"application/javascript",".css":"text/css",".json":"application/json",".html":"text/html",".txt":"text/plain",".xml":"application/xml",".pdf":"application/pdf",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif",".svg":"image/svg+xml",".ico":"image/x-icon",".bmp":"image/bmp",".mp4":"video/mp4",".webm":"video/webm",".ogg":"audio/ogg",".mp3":"audio/mpeg",".wav":"audio/wav",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"};async function Ou(t={}){let e=T.resolve(t.outputDir||".output"),o=t.port??3000,r=Ni(e);if(!r)console.error("[stx] No build manifest found. Run `stx build` first."),process.exit(1);console.log(`[stx] Production server loading ${r.routes.length} routes...`);let a=En(r.routeRules),f=new G,h=Qs(e,r.apiRoutes??[]),g=Bun.file(T.join(e,"server/runtime-config.json")),l=t.runtimeConfig??(await g.exists()?await g.json():void 0),m=l?A(l):void 0,v=new Map,N=new Map,x=new Map,M=new Map;for(let n of r.routes)try{let y=T.join(e,n.compiledPath),i=JSON.parse(await Bun.file(y).text());if(m)i.html=Nt(i.html,m);v.set(n.pattern,i),x.set(n.pattern,Ye(i.html)),M.set(n.pattern,he(i.html));let X=T.join(e,n.fragmentPath);if(await Bun.file(X).exists()){let P=await Bun.file(X).text();N.set(n.pattern,m?Nt(P,m):P)}}catch(y){console.warn(`[stx] Failed to load route ${n.pattern}:`,y)}let s=new Map,b=[];for(let n of r.routes)if(n.hasParams){let{regex:y,params:i}=le(n.pattern,{page:!0});b.push({regex:y,route:n,paramNames:i})}else s.set(n.pattern,n);let E=ce({port:o,async fetch(n){return kn(n,await Be(m??A(),async()=>{let i=new URL(n.url).pathname;if(t.onRequest){let p=await t.onRequest(n);if(p)return p}if(t.apiRouter){let p=await t.apiRouter.handleRequest(n);if(p.status!==404)return p}if(t.apiRoutes?.[i])return t.apiRoutes[i](n);let X=await h(n);if(X)return X;if((n.method==="GET"||n.method==="HEAD")&&i!=="/"){let p=T.resolve(e,"public"),d;try{d=decodeURIComponent(i)}catch{d=i}if(!d.includes("\x00")){let u=T.resolve(p,`.${d}`);if(u===p||u.startsWith(`${p}${T.sep}`))try{if(Z.existsSync(u)&&Z.statSync(u).isFile()){let R=T.extname(u).toLowerCase(),L=pe[R]||"application/octet-stream",_=i.startsWith("/__stx/")||/\.[0-9a-f]{8}\./.test(i);return new Response(Bun.file(u),{headers:{"Content-Type":L,"Cache-Control":_?"public, max-age=31536000, immutable":"public, max-age=3600"}})}}catch{}}}let P=ke(n),C=null,q={};if(C=s.get(i)||null,!C)for(let{regex:p,route:d,paramNames:u}of b){let c=i.match(p);if(c){C=d,u.forEach((R,L)=>{q[R]=c[L+1]});break}}if(!C){let p=vt(i)?null:s.get("/404")||null;if(p){let d=v.get(p.pattern);if(d)return new Response(d.html,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}})}let k=a(i),W=Object.keys(k).length>0;return f.respond(n,k.cache,async()=>{let p=v.get(C.pattern);if(P&&n.method==="GET"&&p&&!p.hasServerScripts&&Object.keys(p.placeholders).length===0){let c=N.get(C.pattern);if(c){let R=x.get(C.pattern);return new Response(c,{status:p.status??200,headers:{"Content-Type":"text/html","X-STX-Fragment":"true",...M.has(C.pattern)?{"X-STX-Runtime":M.get(C.pattern)?"true":"false"}:{},...R?{"X-STX-Layout":R.layout,"X-STX-Layout-Group":R.group}:{},...O(),...k.cache?{}:{"Cache-Control":ut}}})}}let d=Vs(n.method),u=v.get(C.pattern);if(!u){let c=s.get("/500")||null;if(c){let R=v.get(c.pattern);if(R)return new Response(R.html,{status:500,headers:{"Content-Type":"text/html"}})}return new Response("Internal Server Error",{status:500})}if(C.prerendered&&d)return new Response("Prerendered pages do not accept actions",{status:405,headers:{Allow:"GET, HEAD"}});if(!d&&!u.hasServerScripts&&Object.keys(u.placeholders).length===0)return new Response(u.html,{status:u.status??200,headers:{"Content-Type":"text/html",...O(),"Cache-Control":"public, max-age=60"}});try{let{html:c,boundaries:R,redirect:L,cookies:_,status:I,headers:D}=await Cn(u,{params:q,request:n,method:n.method,__stx_strict_hydration:W,__stx_runtime_config:m});if(L)return Di(L,_,D);if(R&&R.length>0){let{renderStreamingPage:S,streamToResponse:z}=await import("./chunk-jf717wps.js"),j=new Headers({...O(),...D,"Cache-Control":"private, no-store"});for(let V of _??[])j.append("Set-Cookie",V);if(P&&!d){let V=Ye(c);j.set("X-STX-Fragment","true"),j.set("X-STX-Runtime",he(c)?"true":"false"),j.set("X-STX-Layout",V.layout),j.set("X-STX-Layout-Group",V.group)}return z(S(P&&!d?_e(c,r.routerContainer||"main"):c,R,{timeoutMs:30000}),{status:I??u.status??200,headers:j})}let w=new Headers({"Content-Type":"text/html",...O(),...k.cache?{}:{"Cache-Control":"private, no-store"}});for(let S of _??[])w.append("Set-Cookie",S);for(let[S,z]of Object.entries(D??{}))w.set(S,z);if(w.set("Vary",O(w.get("Vary")).Vary),P&&!d){let S=Ye(c);return w.set("X-STX-Fragment","true"),w.set("X-STX-Runtime",he(c)?"true":"false"),w.set("X-STX-Layout",S.layout),w.set("X-STX-Layout-Group",S.group),new Response(_e(c,r.routerContainer||"main"),{status:I??u.status??200,headers:w})}return new Response(c,{status:I??u.status??200,headers:w})}catch(c){if(console.error(`[stx] Hydration error for ${i}:`,c),W)return new Response("Internal Server Error",{status:500});return new Response(u.html,{headers:{"Content-Type":"text/html"}})}})}))}});return console.log(`[stx] Production server running at http://localhost:${E.port}`),console.log(`[stx] Serving ${r.routes.length} routes (${v.size} pre-loaded)`),{port:E.port,stop:()=>{f.invalidate(),E.stop()},invalidate:(n)=>f.invalidate(n)}}
|
|
3
3
|
export{kn,Ou};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Hc,td,Vc,Uc,nd,rd}from"./chunk-
|
|
2
|
+
import{Hc,td,Vc,Uc,nd,rd}from"./chunk-ff3d0eh9.js";import"./chunk-qq40hxg9.js";import"./chunk-gny4j06b.js";import"./chunk-t6m5d64b.js";import"./chunk-w28wc7mv.js";import"./chunk-6beg47t4.js";import"./chunk-gtktv6nn.js";export{rd as applySlots,nd as extractSlotContent,td as parseSlotElement,Hc as parseSlots,Uc as processSlots,Vc as renderSlot};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{se,ue,un,At,Pt,g,n,pe,d}from"./chunk-
|
|
2
|
+
import{se,ue,un,At,Pt,g,n,pe,d}from"./chunk-qq40hxg9.js";import{gt,$e,oa,Lr,to,no,o}from"./chunk-840aejkc.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-zj5x4yk2.js";import{ut,Ri,ke,O,Ai,Hs,Pr,Ve,Pi,_e}from"./chunk-kq8t4xn9.js";import{Zn,Qn}from"./chunk-246k73ga.js";import{kn}from"./chunk-tkypg1xx.js";import{e,nn,Gn,h}from"./chunk-t0644y3k.js";import{Ge}from"./chunk-thkw9ez9.js";import{Te}from"./chunk-374nhgyf.js";import{q,he,ye}from"./chunk-px9p7q26.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
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
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(`
|
|
@@ -876,7 +876,7 @@ else {
|
|
|
876
876
|
};
|
|
877
877
|
})();
|
|
878
878
|
</script>
|
|
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-
|
|
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-551vqymy.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
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>
|
|
@@ -939,7 +939,7 @@ ${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=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-
|
|
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-z9xhpkn6.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-qpvasda5.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
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(`
|
|
@@ -1426,12 +1426,12 @@ ${v.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),con
|
|
|
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
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}
|
|
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-z9xhpkn6.js"),m=await y(u),{createServerApi:b,isServerApiSource:w}=await import("./chunk-qpvasda5.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-z9xhpkn6.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-z9xhpkn6.js"),{checkCache:Y,cacheTemplate:X,readFileCached:U,templateCache:ae}=await import("./chunk-jg4932ma.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-z9xhpkn6.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-551vqymy.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-jf717wps.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-jf717wps.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
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
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
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-
|
|
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-jg4932ma.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-jg4932ma.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
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
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}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{x}from"./chunk-
|
|
2
|
+
import{x}from"./chunk-qq40hxg9.js";import{ce}from"./chunk-2ar5g9pa.js";function g(e,t){let r={};for(let n of e)r[n]=ce(t(n));return new Proxy({},{get:(n,a)=>r[a]?.(),set:(n,a,o)=>{if(r[a])r[a].set(o);else r[a]=ce(o);return!0},has:(n,a)=>(a in r),deleteProperty:(n,a)=>(delete r[a],!0),ownKeys:()=>Reflect.ownKeys(r),getOwnPropertyDescriptor:(n,a)=>(a in r)?{enumerable:!0,configurable:!0,writable:!0,value:r[a]()}:void 0})}function v(e,t){let r={};for(let n of t)r[n]=e[n];return r}function Fi(e,t){let r=Object.keys(e),n=g(r,(i)=>t?.[i]??e[i].getDefaultValue()),a=g(r,()=>[]),o=g(r,()=>!1),c=g(r,()=>!1),f=g(r,()=>!1),s=ce(!1);async function u(i){f[i]=!0;let d=await e[i].validate(n[i],n);return a[i]=d,f[i]=!1,d.length===0}async function l(){s.set(!0);let i=await Promise.all(r.map(u));return s.set(!1),i.every(Boolean)}function m(){for(let i of r)n[i]=t?.[i]??e[i].getDefaultValue(),a[i]=[],o[i]=!1,c[i]=!1}function h(i){for(let d of r)if(d in i)n[d]=i[d],c[d]=!0}function b(i,d){n[i]=d,c[i]=!0}function y(i,d=!0){if(o[i]=d,d)u(i)}function p(i){return{value:n[i],errors:a[i],touched:o[i],dirty:c[i],valid:a[i].length===0,validating:f[i]}}function V(i){return async(d)=>{d?.preventDefault?.();for(let w of r)o[w]=!0;if(await l())await i(v(n,r))}}return{values:n,errors:a,touched:o,dirty:c,get isValid(){return r.every((i)=>a[i].length===0)},get isValidating(){return s()||r.some((i)=>f[i])},get isDirty(){return r.some((i)=>c[i])},validate:l,validateField:u,reset:m,setValues:h,setFieldValue:b,setFieldTouched:y,getFieldState:p,handleSubmit:V}}var il=Fi;class On{rules=[];defaultValue="";addRule(e){let t=new On;return t.rules=[...this.rules,e],t.defaultValue=this.defaultValue,t}required(e="This field is required"){return this.addRule({name:"required",message:e,validate:(t)=>{if(t===null||t===void 0)return e;if(typeof t==="string"&&t.trim()==="")return e;if(Array.isArray(t)&&t.length===0)return e;return!0}})}email(e="Please enter a valid email"){return this.addRule({name:"email",message:e,validate:(t)=>{if(!t)return!0;return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(t))||e}})}url(e="Please enter a valid URL"){return this.addRule({name:"url",message:e,validate:(t)=>{if(!t)return!0;try{return new URL(String(t)),!0}catch{return e}}})}min(e,t){let r=t||`Must be at least ${e} characters`;return this.addRule({name:"min",message:r,validate:(n)=>{if(!n)return!0;return String(n).length>=e||r}})}max(e,t){let r=t||`Must be no more than ${e} characters`;return this.addRule({name:"max",message:r,validate:(n)=>{if(!n)return!0;return String(n).length<=e||r}})}length(e,t,r){let n=r||`Must be between ${e} and ${t} characters`;return this.addRule({name:"length",message:n,validate:(a)=>{if(!a)return!0;let o=String(a).length;return o>=e&&o<=t||n}})}pattern(e,t="Invalid format"){return this.addRule({name:"pattern",message:t,validate:(r)=>{if(!r)return!0;return e.test(String(r))||t}})}hasUppercase(e="Must contain an uppercase letter"){return this.pattern(/[A-Z]/,e)}hasLowercase(e="Must contain a lowercase letter"){return this.pattern(/[a-z]/,e)}hasNumber(e="Must contain a number"){return this.pattern(/\d/,e)}hasSpecial(e="Must contain a special character"){return this.pattern(/[!@#$%^&*(),.?":{}|<>]/,e)}alphanumeric(e="Only letters and numbers allowed"){return this.pattern(/^[a-zA-Z0-9]+$/,e)}startsWithLetter(e="Must start with a letter"){return this.pattern(/^[a-zA-Z]/,e)}noSpaces(e="Spaces are not allowed"){return this.addRule({name:"noSpaces",message:e,validate:(t)=>{if(!t)return!0;return!String(t).includes(" ")||e}})}number(e="Must be a number"){let t=this.addRule({name:"number",message:e,validate:(r)=>{if(!r&&r!==0)return!0;return!Number.isNaN(Number(r))||e}});return t.defaultValue=0,t}integer(e="Must be a whole number"){return this.addRule({name:"integer",message:e,validate:(t)=>{if(!t&&t!==0)return!0;return Number.isInteger(Number(t))||e}})}positive(e="Must be a positive number"){return this.addRule({name:"positive",message:e,validate:(t)=>{if(!t&&t!==0)return!0;return Number(t)>0||e}})}negative(e="Must be a negative number"){return this.addRule({name:"negative",message:e,validate:(t)=>{if(!t&&t!==0)return!0;return Number(t)<0||e}})}minValue(e,t){let r=t||`Must be at least ${e}`;return this.addRule({name:"minValue",message:r,validate:(n)=>{if(!n&&n!==0)return!0;return Number(n)>=e||r}})}maxValue(e,t){let r=t||`Must be no more than ${e}`;return this.addRule({name:"maxValue",message:r,validate:(n)=>{if(!n&&n!==0)return!0;return Number(n)<=e||r}})}between(e,t,r){let n=r||`Must be between ${e} and ${t}`;return this.addRule({name:"between",message:n,validate:(a)=>{if(!a&&a!==0)return!0;let o=Number(a);return o>=e&&o<=t||n}})}matches(e,t){let r=t||`Must match ${e}`;return this.addRule({name:"matches",message:r,validate:(n,a)=>{if(!a)return!0;return n===a[e]||r}})}oneOf(e,t){let r=t||`Must be one of: ${e.join(", ")}`;return this.addRule({name:"oneOf",message:r,validate:(n)=>{if(!n)return!0;return e.includes(n)||r}})}notOneOf(e,t){let r=t||`Cannot be one of: ${e.join(", ")}`;return this.addRule({name:"notOneOf",message:r,validate:(n)=>{if(!n)return!0;return!e.includes(n)||r}})}date(e="Must be a valid date"){return this.addRule({name:"date",message:e,validate:(t)=>{if(!t)return!0;let r=new Date(String(t));return!Number.isNaN(r.getTime())||e}})}before(e,t){let r=new Date(e),n=t||`Must be before ${r.toLocaleDateString()}`;return this.addRule({name:"before",message:n,validate:(a)=>{if(!a)return!0;return new Date(String(a))<r||n}})}after(e,t){let r=new Date(e),n=t||`Must be after ${r.toLocaleDateString()}`;return this.addRule({name:"after",message:n,validate:(a)=>{if(!a)return!0;return new Date(String(a))>r||n}})}custom(e,t="Invalid value"){return this.addRule({name:"custom",message:t,validate:e})}async(e,t="Invalid value"){return this.addRule({name:"async",message:t,async:!0,validate:e})}when(e,t){let r=new On;r.rules=[...this.rules],r.defaultValue=this.defaultValue;for(let n of t.getRules())r.rules.push({...n,validate:(a,o)=>{if(!e(a,o||{}))return!0;return n.validate(a,o)}});return r}getRules(){return this.rules}getDefaultValue(){return this.defaultValue}default(e){let t=new On;return t.rules=[...this.rules],t.defaultValue=e,t}async validate(e,t){let r=[];for(let n of this.rules){let a=await n.validate(e,t);if(a!==!0)r.push(a)}return r}validateSync(e,t){let r=[];for(let n of this.rules){if(n.async)continue;let a=n.validate(e,t);if(a!==!0)r.push(a)}return r}}var id=new On;function al(e,t,r){let n=/@error\s*\(\s*([^)]+)\s*\)([\s\S]*?)@enderror/g;return e.replace(n,(a,o,c)=>{try{let f=o.trim().split("."),s=t;for(let l of f)if(s&&typeof s==="object"&&l in s)s=s[l];else return"";let u=s;if(!u||!Array.isArray(u)||u.length===0)return"";return u.map((l)=>x(c,{...t,message:l},r)).join(`
|
|
3
3
|
`)}catch{return""}})}function cl(e,t,r){let n=/@errors\s*\(\s*([^)]+)\s*\)([\s\S]*?)@enderrors/g;return e.replace(n,(a,o,c)=>{try{let f=o.trim().split("."),s=t;for(let l of f)if(s&&typeof s==="object"&&l in s)s=s[l];else return"";let u=s;if(!u||!Array.isArray(u)||u.length===0)return"";return u.map((l)=>x(c,{...t,message:l},r)).join(`
|
|
4
4
|
`)}catch{return""}})}function ll(e,t,r){let n=/@hasErrors\s*\(\s*([^)]+)\s*\)([\s\S]*?)@endhasErrors/g;return e.replace(n,(a,o,c)=>{try{let f=o.trim().split("."),s=t;for(let l of f)if(s&&typeof s==="object"&&l in s)s=s[l];else return"";let u=s;if(!u||!Array.isArray(u)||u.length===0)return"";return c}catch{return""}})}function ad(e,t,r){let n=e;return n=al(n,t,r),n=cl(n,t,r),n=ll(n,t,r),n}export{Fi,il,On,id,al,cl,ll,ad};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{Ud,Wd}from"./chunk-3vgfwsft.js";import"./chunk-5wpny9k3.js";import"./chunk-d4f6dkrt.js";import"./chunk-374nhgyf.js";import"./chunk-drd4t5v4.js";import"./chunk-px9p7q26.js";import"./chunk-zt5hp5w5.js";import"./chunk-zj5x4yk2.js";import"./chunk-cfbev664.js";import"./chunk-tenbwcts.js";import"./chunk-912r15hr.js";import"./chunk-nbjyed3q.js";import"./chunk-gymmbbzc.js";import"./chunk-qq40hxg9.js";import"./chunk-gny4j06b.js";import"./chunk-t6m5d64b.js";import"./chunk-w28wc7mv.js";import"./chunk-6beg47t4.js";import"./chunk-gtktv6nn.js";export{Wd as clearStoreCache,Ud as getStoreScript};
|