@stacksjs/stx 0.2.508 → 0.2.509
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-ag1j84s6.js → chunk-11j2dj0r.js} +1 -1
- package/dist/{chunk-pecwdp57.js → chunk-144xhefw.js} +1 -1
- package/dist/{chunk-mz7snf2b.js → chunk-18y7kk8n.js} +1 -1
- package/dist/{chunk-k5syze27.js → chunk-1r3fmmy8.js} +1 -1
- package/dist/{chunk-fkv8jmse.js → chunk-2a8dw04j.js} +1 -1
- package/dist/{chunk-h3rrsq05.js → chunk-2djfn17e.js} +1 -1
- package/dist/{chunk-cprcfp0j.js → chunk-2dkyyewm.js} +1 -1
- package/dist/{chunk-7sjmpfwy.js → chunk-2j1q5te2.js} +2 -2
- package/dist/{chunk-8zj1ebs5.js → chunk-33meqm5e.js} +1 -1
- package/dist/{chunk-06v0c3fz.js → chunk-4mmd282p.js} +1 -1
- package/dist/{chunk-nnrtwpvy.js → chunk-5tvxv2v1.js} +1 -1
- package/dist/{chunk-ph1xz7k5.js → chunk-5vzts63r.js} +1 -1
- package/dist/{chunk-w9mxt96c.js → chunk-5z69phk9.js} +5 -5
- package/dist/{chunk-rx90ktrb.js → chunk-6xmymt0g.js} +2 -2
- package/dist/{chunk-e4zks32s.js → chunk-6ygvfpc5.js} +1 -1
- package/dist/{chunk-4w358hpx.js → chunk-7bwkc5yf.js} +1 -1
- package/dist/{chunk-9z8mxp15.js → chunk-7pr8gvpc.js} +1 -1
- package/dist/{chunk-38xtsdk9.js → chunk-7wnw3h4p.js} +1 -1
- package/dist/{chunk-fwvqbx49.js → chunk-8nv7xakv.js} +2 -2
- package/dist/{chunk-spg0fzyv.js → chunk-8sjctqyw.js} +1 -1
- package/dist/{chunk-ea19gveh.js → chunk-a6djsvag.js} +2 -2
- package/dist/chunk-abxnep18.js +2 -0
- package/dist/{chunk-9xw416q3.js → chunk-aw8ehxde.js} +1 -1
- package/dist/{chunk-1b7dd8rn.js → chunk-azv7g8rr.js} +1 -1
- package/dist/chunk-c82gckm3.js +2 -0
- package/dist/{chunk-96kr2xrt.js → chunk-e07ptggk.js} +32 -32
- package/dist/{chunk-76g4jw9g.js → chunk-etbszapb.js} +1 -1
- package/dist/{chunk-mq6expbd.js → chunk-j7bncsd9.js} +1 -1
- package/dist/{chunk-k2331dfx.js → chunk-k14e9k4h.js} +1 -1
- package/dist/{chunk-5dh041x0.js → chunk-ke05jx3n.js} +1 -1
- package/dist/{chunk-7p6y0b47.js → chunk-m6xpg33p.js} +1 -1
- package/dist/{chunk-qt31at4s.js → chunk-mwz1mq51.js} +1 -1
- package/dist/{chunk-0vnr7mz7.js → chunk-npth2waq.js} +1 -1
- package/dist/{chunk-h87zhtw8.js → chunk-pan2t7h3.js} +1 -1
- package/dist/{chunk-h37bbgg8.js → chunk-ph4fszwq.js} +1 -1
- package/dist/{chunk-dv94gdv4.js → chunk-q5jc8hmg.js} +1 -1
- package/dist/{chunk-2wr0sk42.js → chunk-qa53jmk3.js} +1 -1
- package/dist/chunk-rfqsgs51.js +2 -0
- package/dist/{chunk-8nx5asjr.js → chunk-s7rbe4c6.js} +1 -1
- package/dist/{chunk-r14mvycg.js → chunk-s9fskxy7.js} +1 -1
- package/dist/{chunk-mvqhf6dn.js → chunk-tv2xr7s3.js} +1 -1
- package/dist/{chunk-v74acg2k.js → chunk-twqmyetp.js} +1 -1
- package/dist/{chunk-w925gtgg.js → chunk-vgkjmrf3.js} +1 -1
- package/dist/{chunk-36rwfhnb.js → chunk-w5w055g6.js} +1 -1
- package/dist/{chunk-cb1c9mvc.js → chunk-x2ghjgxm.js} +1 -1
- package/dist/{chunk-ces3vdjp.js → chunk-x5gbrjm5.js} +1 -1
- package/dist/{chunk-s87qrma5.js → chunk-xmw9e9zn.js} +1 -1
- package/dist/{chunk-r5fzxtbc.js → chunk-zddtnyp7.js} +1 -1
- package/dist/cli.js +7 -7
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/native/compiler/render-screen.js +2 -1
- package/dist/pwa.js +1 -1
- package/dist/ssg.js +2 -2
- package/dist/types/config-types.d.ts +8 -0
- package/dist/utils.js +5 -0
- package/package.json +5 -5
- package/dist/chunk-7z28hk7r.js +0 -2
- package/dist/chunk-j08y5n2k.js +0 -2
- package/dist/chunk-n1hd2fx6.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{W,Gr,Jr,Za,wt,Ho,Yr,Vo,Rd,Le,Zr,he}from"./chunk-
|
|
2
|
+
import{W,Gr,Jr,Za,wt,Ho,Yr,Vo,Rd,Le,Zr,he}from"./chunk-e07ptggk.js";import"./chunk-68tzytfz.js";import"./chunk-c57j92td.js";import{wi,s}from"./chunk-xemsypk7.js";import"./chunk-kp4mzspk.js";import"./chunk-twqmyetp.js";import"./chunk-zz5b1g50.js";import"./chunk-5tbqdz94.js";import"./chunk-9p3rtfbv.js";import"./chunk-g495xx4v.js";import"./chunk-ba88n1j7.js";import"./chunk-g1r4v0mc.js";import"./chunk-xd4zvm4x.js";import"./chunk-e6y6s7q8.js";export{W as BROWSER_CORE_IMPORTS,Za as STX_AUTO_IMPORTS,Gr as extractAndStripCssImports,Le as extractBridgeData,wi as findInterpolationEnd,Vo as generateAutoImportDestructuring,Rd as generateBrowserAutoImportDestructuring,Zr as generateServerDataBridge,wt as injectBrowserCoreAutoImports,he as processClientScript,Yr as referencesName,Jr as renderVendorStyleTags,s as stripCommentsAndLiterals,Ho as transformAutoImports};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Xd,$c,be,ui,Gd,ms,hs,ys}from"./chunk-
|
|
2
|
+
import{Xd,$c,be,ui,Gd,ms,hs,ys}from"./chunk-e07ptggk.js";import"./chunk-68tzytfz.js";import"./chunk-c57j92td.js";import"./chunk-kp4mzspk.js";import"./chunk-twqmyetp.js";import"./chunk-zz5b1g50.js";import"./chunk-5tbqdz94.js";import"./chunk-9p3rtfbv.js";import"./chunk-g495xx4v.js";import"./chunk-ba88n1j7.js";import"./chunk-g1r4v0mc.js";import"./chunk-xd4zvm4x.js";import"./chunk-e6y6s7q8.js";export{Gd as clearOnceStore,ui as onceStore,be as partialsCache,ms as processIncludes,hs as processStackPushDirectives,ys as processStackReplacements,Xd as resetUnscopedSignalWarnings,$c as topLevelElements};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Zc}from"./chunk-
|
|
2
|
+
import{Zc}from"./chunk-qa53jmk3.js";import"./chunk-e07ptggk.js";import"./chunk-68tzytfz.js";import"./chunk-c57j92td.js";import"./chunk-kp4mzspk.js";import"./chunk-twqmyetp.js";import"./chunk-zz5b1g50.js";import"./chunk-5tbqdz94.js";import"./chunk-9p3rtfbv.js";import"./chunk-g495xx4v.js";import"./chunk-ba88n1j7.js";import"./chunk-g1r4v0mc.js";import"./chunk-xd4zvm4x.js";import"./chunk-e6y6s7q8.js";export{Zc as startInteractive};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Ne,oc,Md,Nd,Ld,jd,ic,ac,Bd,Fd,Ko,zd,nn,rn,zn}from"./chunk-
|
|
2
|
+
import{Ne,oc,Md,Nd,Ld,jd,ic,ac,Bd,Fd,Ko,zd,nn,rn,zn}from"./chunk-e07ptggk.js";import"./chunk-68tzytfz.js";import"./chunk-c57j92td.js";import"./chunk-kp4mzspk.js";import"./chunk-twqmyetp.js";import"./chunk-zz5b1g50.js";import"./chunk-5tbqdz94.js";import"./chunk-9p3rtfbv.js";import"./chunk-g495xx4v.js";import"./chunk-ba88n1j7.js";import"./chunk-g1r4v0mc.js";import"./chunk-xd4zvm4x.js";import"./chunk-e6y6s7q8.js";export{jd as __setSignalsGeneratorsForTest,Ne as cacheEngineFingerprint,rn as cacheTemplate,nn as checkCache,zd as clearDevCaches,ac as getCachedRouterScript,ic as getCachedSignalsRuntime,Bd as getServeClientAsset,Ko as getServeModuleBundle,zn as hashFilePath,Nd as invalidateFileCache,Ld as invalidateFileCacheByDir,Md as readFileCached,Fd as registerServeModuleBundle,oc as templateCache};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Qc}from"./chunk-
|
|
2
|
+
import{Qc}from"./chunk-m6xpg33p.js";import"./chunk-8nv7xakv.js";import"./chunk-mwz1mq51.js";import"./chunk-e07ptggk.js";import"./chunk-68tzytfz.js";import"./chunk-c57j92td.js";import"./chunk-kp4mzspk.js";import"./chunk-twqmyetp.js";import"./chunk-zz5b1g50.js";import"./chunk-5tbqdz94.js";import"./chunk-9p3rtfbv.js";import"./chunk-g495xx4v.js";import"./chunk-ba88n1j7.js";import"./chunk-g1r4v0mc.js";import"./chunk-xd4zvm4x.js";import"./chunk-e6y6s7q8.js";export{Qc as startProductionServer};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{on,gc,as}from"./chunk-
|
|
2
|
+
import{on,gc,as}from"./chunk-e07ptggk.js";import"./chunk-68tzytfz.js";import"./chunk-c57j92td.js";import"./chunk-kp4mzspk.js";import"./chunk-twqmyetp.js";import"./chunk-zz5b1g50.js";import"./chunk-5tbqdz94.js";import"./chunk-9p3rtfbv.js";import{Se}from"./chunk-g495xx4v.js";import"./chunk-ba88n1j7.js";import"./chunk-g1r4v0mc.js";import"./chunk-xd4zvm4x.js";import"./chunk-e6y6s7q8.js";export{Se as freeIdentifiers,as as processComponents,gc as processESImports,on as rendersAsElement};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{o}from"./chunk-
|
|
2
|
+
import{o}from"./chunk-e07ptggk.js";import{$r}from"./chunk-2etevws0.js";import p from"path";async function vl(t={}){let d=performance.now(),s=t.root||process.cwd(),e=await o(s),u=t.ssr?.routeRules??e.routeRules??{};if($r(u),!e.ssr&&Object.keys(u).length)throw Error("routeRules require ssr: true and the production server; flat SSG output cannot apply request/cache policies");if(!e.ssr&&(t.ssr?.serverApi??e.serverApi))throw Error("serverApi requires ssr: true; flat SSG output cannot execute API endpoints");let r=e.ssr?"ssr":"ssg";console.log(`[stx build] Mode: ${r.toUpperCase()}${e.ssr?" (ssr: true in stx.config.ts)":" (default \u2014 ssr is false)"}`);let n,l;if(r==="ssg"){let{generateStaticSite:i}=await import("./ssg.js");n=await i({pagesDir:p.join(e.root||".",e.pagesDir||e.build?.pagesDir||"pages"),publicDir:e.publicDir||e.build?.publicDir||"public",outputDir:e.build?.outputDir||"dist",generate404:e.build?.generate404??!0,minify:e.build?.minify??!0,cleanOutput:e.build?.cleanOutput??!0,router:e.router,...t.ssg})}else{let{buildForProduction:i}=await import("./chunk-etbszapb.js");l=await i({root:s,outputDir:".output",debug:t.debug,...t.ssr})}let a=Math.round(performance.now()-d);return{mode:r,ssg:n,ssr:l,duration:a}}
|
|
3
3
|
export{vl};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{jn,Me,Le,he,Jo,Vn,Z,K,an,u,n,R}from"./chunk-
|
|
2
|
+
import{jn,Me,Le,he,Jo,Vn,Z,K,an,u,n,R}from"./chunk-e07ptggk.js";import{dirname as k,resolve as _}from"path";function h(o){return o.endsWith(".md")||o.endsWith(".markdown")}function C(o){let e=[];g(/<pre\b[^>]*>[\s\S]*?<\/pre>/gi);let r=[...e];g(/<code\b[^>]*>[\s\S]*?<\/code>/gi,r);function g(s,p){let m;while((m=s.exec(o))!==null){let t=m.index,i=t+m[0].length;if(p?.some((l)=>t>=l.start&&i<=l.end))continue;e.push({start:t,end:i})}}if(e.length===0)return o;e.sort((s,p)=>s.start-p.start);let a="",c=0;for(let s of e){if(s.start<c)continue;a+=o.slice(c,s.start),a+=`@raw${o.slice(s.start,s.end)}@endraw`,c=s.end}return a+=o.slice(c),a}async function b(o,e={}){let{data:r,content:g}=jn(o),c=await(e.renderer??((s)=>Me(s)))(g);return{html:C(c),frontmatter:r??{}}}function v(o){let e=o,r=Z(o);if(r)e=r.content.trim();let g=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,a=[],c=[],s=[],p=(i)=>/\b(?:state|derived|effect|batch)\s*(?:<[^<>()]*>)?\s*\(/.test(i),m;while((m=g.exec(o))!==null){let i=m[1],l=m[2],f=m[0],d=i.includes("server");if(p(l))s.push(f);else if(d)c.push(l);else a.push(f)}let t=e;{let i=/<script\b(?![^>]*\b(?:client|type\s*=\s*["']module["']|src\s*=))[^>]*>/gi,l,f=[];while((l=i.exec(t))!==null){let d=l.index+l[0].length,x=t.indexOf("</script>",d);if(x===-1)continue;f.push({start:l.index,end:x+9}),i.lastIndex=x+9}for(let d=f.length-1;d>=0;d--)t=t.substring(0,f[d].start)+t.substring(f[d].end)}for(let i of a)t=t.replace(i,"");return{templateContent:t,serverScripts:c,clientScripts:a,signalsScripts:s}}function M(o,e){return`<!DOCTYPE html>
|
|
3
3
|
<html lang="en">
|
|
4
4
|
<head>
|
|
5
5
|
<meta charset="UTF-8">
|
|
@@ -14,5 +14,5 @@ ${c.join(`
|
|
|
14
14
|
`)}`}else{if(r.processClientScripts!==!1&&c.length>0){let i=p.__stx_event_bindings||[],l=Le(p),d=(await Promise.all(c.map(async(w)=>{let y=w.match(/<script\b[^>]*>([\s\S]*?)<\/script>/);if(!y)return w;return await he(y[1],{eventBindings:i,templateContent:t,serverData:l,filePath:e})}))).join(`
|
|
15
15
|
`);if(t.match(/(<\/body>)/i))t=t.replace(/(<\/body>)/i,`${d}
|
|
16
16
|
$1`);else t+=`
|
|
17
|
-
${d}`}t=await K(t)}if(r.wrapInDocument){if(!t.trim().toLowerCase().startsWith("<!doctype")&&!t.trim().toLowerCase().startsWith("<html"))t=M(t,r.title)}if(r.injectCSS)try{let{injectCss:i}=await import("./chunk-
|
|
17
|
+
${d}`}t=await K(t)}if(r.wrapInDocument){if(!t.trim().toLowerCase().startsWith("<!doctype")&&!t.trim().toLowerCase().startsWith("<html"))t=M(t,r.title)}if(r.injectCSS)try{let{injectCss:i}=await import("./chunk-6ygvfpc5.js");t=await i(t)}catch{}return t}
|
|
18
18
|
export{Io};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{vt,Wr,qr,Kr,_d,Xr}from"./chunk-
|
|
2
|
+
import{vt,Wr,qr,Kr,_d,Xr}from"./chunk-mwz1mq51.js";import"./chunk-kp4mzspk.js";import"./chunk-zz5b1g50.js";import"./chunk-xd4zvm4x.js";export{qr as buildServerApi,_d as createServerApi,vt as discoverServerApi,Wr as generateApiTypes,Xr as isServerApiSource,Kr as productionApiDispatcher};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import m from"path";var y=/__stxModules\["((?:[^"\\]|\\.)*)"\]/g;function I(...o){let r=new Set;for(let s of o){if(!s||!s.includes("__stxModules["))continue;for(let e of s.matchAll(y))try{r.add(JSON.parse(`"${e[1]}"`))}catch{}}return[...r].sort()}async function w(o,r={}){if(o.length===0)return null;let s=process.cwd(),e=[],a=[];o.forEach((t,c)=>{let i=t.startsWith("npm:")?t.slice(4):m.resolve(s,t),l=`__stxRegistered${c}`,p=JSON.stringify(t);e.push(`import * as ${l} from ${JSON.stringify(i)};`),a.push(`if (!globalThis.__stxModules[${p}]) globalThis.__stxModules[${p}] = ${l};`)});let d=[...e,"globalThis.__stxModules = globalThis.__stxModules || {};",...a].join(`
|
|
3
|
-
`),n;try{let{bundleClientScript:t}=await import("./chunk-
|
|
3
|
+
`),n;try{let{bundleClientScript:t}=await import("./chunk-x5gbrjm5.js");n=await t(d,m.join(s,".stx-module-registry.ts"),{projectRoot:s,minify:r.minify,externalizeUserModules:!1,collectInputs:r.collectInputs,throwOnFailure:!0})}catch(t){let{formatBuildFailure:c}=await import("./chunk-0fad6jf4.js"),i=c(t);console.warn(`[stx] could not build the page module registry (#1957): ${i}`);let l=`[stx] the page module registry did not build, so ${o.join(", ")} cannot load (#1957): ${i}`;return`;console.error(${JSON.stringify(l)});`}let{transformAutoImports:f,generateAutoImportDestructuring:_}=await import("./chunk-11j2dj0r.js"),u=f(n),h=_(u.stxImports,u.browserImports),{transformStoreImports:x}=await import("./chunk-9z76qhdm.js");n=x(u.code);let g=JSON.stringify(new Bun.CryptoHasher("md5").update(d).digest("hex").slice(0,12));return[";(function() {"," var __stxBundles = globalThis.__stxModuleBundles || (globalThis.__stxModuleBundles = {});",` if (__stxBundles[${g}]) return;`,` __stxBundles[${g}] = true;`,h,n,"})();"].join(`
|
|
4
4
|
`)}export{w as buildModuleRegistryScript,I as registeredModuleIdsIn};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ld,So,La,dd,ud,pd,fd,gd,ja,Ba,md,hd,yd,bd}from"./chunk-
|
|
2
|
+
import{ld,So,La,dd,ud,pd,fd,gd,ja,Ba,md,hd,yd,bd}from"./chunk-7wnw3h4p.js";import"./chunk-e07ptggk.js";import"./chunk-68tzytfz.js";import"./chunk-c57j92td.js";import"./chunk-kp4mzspk.js";import"./chunk-twqmyetp.js";import"./chunk-zz5b1g50.js";import"./chunk-5tbqdz94.js";import"./chunk-9p3rtfbv.js";import"./chunk-g495xx4v.js";import"./chunk-ba88n1j7.js";import"./chunk-g1r4v0mc.js";import"./chunk-xd4zvm4x.js";import"./chunk-e6y6s7q8.js";export{La as SUSPENSE_RESOLVER_RUNTIME,So as buildSuspenseResolveScript,gd as createStreamRenderer,pd as extractStreamBoundaries,bd as generateHydrationRuntime,Ba as islandDirective,hd as processSectionDirectives,ud as processStreamDirectives,md as registerStreamingDirectives,dd as renderStreamingPage,ld as streamTemplate,fd as streamTemplateSimple,yd as streamToResponse,ja as streamingSuspenseDirective};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{De,Kt}from"./chunk-5zm23zrb.js";import{Ce}from"./chunk-xd4zvm4x.js";import{Uo,Wo,f,Ct,Q,N,n,R,o}from"./chunk-
|
|
2
|
+
import{De,Kt}from"./chunk-5zm23zrb.js";import{Ce}from"./chunk-xd4zvm4x.js";import{Uo,Wo,f,Ct,Q,N,n,R,o}from"./chunk-e07ptggk.js";import{C}from"./chunk-zz5b1g50.js";import{Cs}from"./chunk-twqmyetp.js";import{pn,fn,gn,hn,pe}from"./chunk-9p3rtfbv.js";import{ki}from"./chunk-kp4mzspk.js";import{me,re,uo,po,Ot}from"./chunk-8nv7xakv.js";import{vt,qr}from"./chunk-mwz1mq51.js";import{Mt}from"./chunk-2etevws0.js";import{ft,Yt,Zt}from"./chunk-g7ey7mtw.js";import{createHash as ee}from"crypto";function J(i){return ee("sha256").update(i).digest("hex").slice(0,8)}function U(i=!1){let l=i?Kt():De(),a=J(l);return{content:l,filename:`runtime.${a}.js`,hash:a}}function V(){let i=Ce(),l=J(i);return{content:i,filename:`router.${l}.js`,hash:l}}import m from"fs";import c from"path";import q from"path";import{createHash as te}from"crypto";function se(i={}){let l=new Set;return{context:new Proxy(i,{get(r,e){if(e in r)return r[e];if(typeof e==="string"&&!e.startsWith("__"))l.add(e);return},has(r,e){if(e in r)return!0;if(typeof e==="string"&&!e.startsWith("__"))l.add(e);return!1}}),accessedKeys:l}}async function X(i,l,a={}){let r=q.resolve(i),e=await Bun.file(r).text(),S=te("sha256").update(e).digest("hex").slice(0,16);Uo();let _={};try{_=await o(a.configDir)}catch{}let y=[],d=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,g;while((g=d.exec(e))!==null){let v=g[1];if(/\bserver\b/.test(v))y.push(g[2])}let u=new Set(y.flatMap((v)=>Q(v))),{context:A}=se({__filename:r,__dirname:q.dirname(r),__stx_serverDeclared:u}),w=new Set,P={...R,..._,...a,buildMode:"compile",strict:!1},b=await n(e,A,r,P,w),T=me(b),B=Wo();return{route:l,sourceFile:i,html:b,fragment:T,placeholders:B,hasServerScripts:y.length>0,serverScriptContent:y,dependencies:Array.from(w),contentHash:S,status:Ct(e),streamTemplates:A.__streamTemplates}}var ne=new Set([".DS_Store","Thumbs.db","desktop.ini",".gitkeep",".gitignore"]);function Z(i,l){let a=0,r=0;if(!m.existsSync(i))return{copied:a,bytes:r};m.mkdirSync(l,{recursive:!0});function e(S,_){let y=m.readdirSync(S,{withFileTypes:!0});for(let d of y){if(ne.has(d.name))continue;let g=c.join(S,d.name),u=c.join(_,d.name);if(d.isDirectory())m.mkdirSync(u,{recursive:!0}),e(g,u);else if(d.isFile()){if(m.existsSync(u))continue;m.copyFileSync(g,u),a++,r+=m.statSync(u).size}}}return e(i,l),{copied:a,bytes:r}}async function al(i={}){let l=Date.now(),a=c.resolve(i.root||process.cwd()),r=c.resolve(a,i.outputDir||".output");console.log("[stx build] Starting production build...");let e=await o(a),S=c.resolve(a,i.componentsDir??e.componentsDir??"components"),_=c.resolve(a,i.partialsDir??e.partialsDir??"partials"),y=c.resolve(a,i.layoutsDir??e.layoutsDir??"layouts"),d=i.publicDir??e.publicDir??"public",g=pe(e.app?.head,{known:hn,source:"app.head"}),u=e.app?.colorMode,A=e.router?.container||"main",w=i.routeRules??e.routeRules??{},P=Mt(w),b=i.serverApi??e.serverApi,T=typeof b==="object"?b:{};if(b)vt(a,T);if(e.runtimeConfig)C(e.runtimeConfig,{});if(m.existsSync(r))m.rmSync(r,{recursive:!0});let B=[c.join(r,"public","__stx"),c.join(r,"public","assets"),c.join(r,"server","pages"),c.join(r,"server","fragments")];for(let s of B)m.mkdirSync(s,{recursive:!0});console.log("[stx build] Discovering routes...");let v=N(a,{pagesDirs:e._layerPageDirs}),Y=["components","layouts","partials"],M=v.filter((s)=>!Y.some((h)=>s.pattern.startsWith(`/${h}/`)||s.pattern===`/${h}`));console.log(`[stx build] Found ${M.length} page routes (${v.length-M.length} non-page files excluded)`),console.log("[stx build] Generating shared assets...");let D=U(i.debug),x=V();await Bun.write(c.join(r,"public","__stx",D.filename),D.content),await Bun.write(c.join(r,"public","__stx",x.filename),x.content),console.log(`[stx build] Runtime: ${D.filename} (${(D.content.length/1024).toFixed(1)}KB)`),console.log(`[stx build] Router: ${x.filename} (${(x.content.length/1024).toFixed(1)}KB)`),console.log("[stx build] Compiling templates...");let O=[],E=[];for(let s of M){let h=P(s.pattern),k=h.rendering==="prerender";if(k&&(s.pattern.includes(":")||s.pattern.includes("[")))throw Error(`Cannot prerender parameter route ${s.pattern}; use dynamic rendering (explicit path enumeration is not supported here)`);try{let t=await X(s.filePath,s.pattern,{configDir:a,componentsDir:S,partialsDir:_,layoutsDir:y,debug:i.debug});if(O.push(t),t.html=t.html.replace(/runtime\.__STX_HASH__\.js/g,D.filename).replace(/router\.__STX_HASH__\.js/g,x.filename),t.html=gn(t.html,g,{bodyScripts:[`<script src="/__stx/${x.filename}"></script>`],...u&&{colorMode:u}}),u)t.html=pn(t.html,u);if(g.htmlAttrs)t.html=fn(t.html,g.htmlAttrs);if(!/<body[^>]*\bdata-stx=/.test(t.html)){let p=t.html.match(/<(?!body\b)[a-zA-Z][a-zA-Z0-9-]*\b[^>]*?\s(data-stx="[^"]+")[^>]*>/);if(p&&p[1]){let W=p[1];t.html=t.html.replace(" "+W,""),t.html=t.html.replace(/<body([^>]*)>/,`<body$1 ${W}>`)}}if(t.html=t.html.replace(/<style data-css="generated">[\s\S]*?<\/style>\s*/g,""),t.html=await f(t.html),k){let p=await Ot(t,{params:{},request:new Request(`http://stx.build${s.pattern}`),method:"GET",__stx_strict_hydration:!0});if(p.redirect||p.cookies?.length||p.boundaries?.length||p.headers&&Object.keys(p.headers).length)throw Error(`Prerendered route ${s.pattern} cannot set response headers/cookies, redirect or stream`);t.html=p.html,t.status=p.status??t.status,t.hasServerScripts=!1,t.serverScriptContent=[],t.placeholders={}}t.fragment=re(t.html,A);let z=s.pattern==="/"?"index":s.pattern.slice(1).replace(/\//g,"-").replace(/[[\]]/g,"_"),G=c.join("server","pages",`${z}.compiled.json`),I=c.join("server","fragments",`${z}.html`);await Bun.write(c.join(r,G),JSON.stringify(t,null,2)),await Bun.write(c.join(r,I),t.fragment),E.push({pattern:s.pattern,compiledPath:G,fragmentPath:I,isDynamic:t.hasServerScripts,hasParams:s.pattern.includes(":")||s.pattern.includes("["),prerendered:k}),console.log(`[stx build] \u2713 ${s.pattern}`)}catch(t){if(Object.keys(h).length)throw t;console.error(`[stx build] \u2717 ${s.pattern}:`,t instanceof Error?t.message:t)}}let H=c.resolve(a,d);if(m.existsSync(H)){let{copied:s,bytes:h}=Z(H,c.join(r,"public"));if(s>0)console.log(`[stx build] Copied ${s} public asset${s===1?"":"s"} (${(h/1024).toFixed(1)}KB) from ${d}/`)}let F=Zt(a);if(F){let{copied:s,bytes:h}=Z(F,c.join(r,"public",Yt));if(s>0)console.log(`[stx build] Copied ${s} asset${s===1?"":"s"} (${(h/1024).toFixed(1)}KB) from ${ft}/`)}let K={runtime:D.filename,router:x.filename},j=uo(E,K,r);if(j.routeRules=w,j.routerContainer=A,b)j.apiRoutes=await qr(a,r,T);if(e.runtimeConfig)await Bun.write(c.join(r,"server/runtime-config.json"),JSON.stringify(e.runtimeConfig)),await Cs(a,e.runtimeConfig);if(e._layerGraph)await Bun.write(c.join(r,"server/layers.json"),JSON.stringify(ki(e._layerGraph),null,2));po(j,r);let L=Date.now()-l;return console.log(`
|
|
3
3
|
[stx build] Done in ${L}ms \u2014 ${O.length} pages compiled`),{pageCount:O.length,assets:K,outputDir:r,duration:L}}
|
|
4
4
|
export{al};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{X,yn,te,P,Rt}from"./chunk-g495xx4v.js";import{Qe,xn,lr,dr,ur,et,tt,nt,rt,st,ot,ke}from"./chunk-xd4zvm4x.js";import{U,b,nn,rn,e,kt,sn,f,Be,Ct,Fe,ze,Z,N,ce,K,u,be,pi,bs,n,r,ee,Jn,o,A,le}from"./chunk-
|
|
2
|
+
import{X,yn,te,P,Rt}from"./chunk-g495xx4v.js";import{Qe,xn,lr,dr,ur,et,tt,nt,rt,st,ot,ke}from"./chunk-xd4zvm4x.js";import{U,b,nn,rn,e,kt,sn,f,Be,Ct,Fe,ze,Z,N,ce,K,u,be,pi,bs,n,r,ee,Jn,o,A,le}from"./chunk-e07ptggk.js";import{Ae,ao,ne,T,co,Cr,An,me,lo,re}from"./chunk-8nv7xakv.js";import{It}from"./chunk-m6xpg33p.js";import{ae}from"./chunk-2hc5mbw8.js";import{a}from"./chunk-dne8n6h3.js";import{O}from"./chunk-vtxzaj1h.js";function Ks(t,s){let i=[],d=`${s}=`;for(let c=0;c<t.length;c++){let l=t[c];if(l.startsWith(d)){let m=l.slice(d.length);if(m)i.push(m);continue}if(l===s){let m=t[c+1];if(m!==void 0&&!m.startsWith("-"))i.push(m),c++}}return i}var{serve:rr}=globalThis.Bun;import Bt from"fs";import pt from"path";function bt(){return`
|
|
3
3
|
/* Theme selector for code blocks */
|
|
4
4
|
.theme-selector {
|
|
5
5
|
margin: 1rem 0;
|
|
@@ -1786,7 +1786,7 @@ else {
|
|
|
1786
1786
|
})()
|
|
1787
1787
|
</script>
|
|
1788
1788
|
`;import _e from"fs";import $e from"path";function On(t){try{return _e.statSync(t).mtimeMs}catch{return null}}function Dt(t,s){let i=Math.max(0,Math.round((s-t)/1000));if(i<60)return`${i}s ago`;if(i<3600)return`${Math.round(i/60)}m ago`;return`${Math.round(i/3600)}h ago`}function Ei(t,s){try{return globalThis.Bun?.resolveSync(t,s)??null}catch{return null}}function Dn(t,s="stx"){let i=$e.resolve(t);for(let d=0;d<10;d++){let c=$e.join(i,"pantry","@stacksjs",s);if(_e.existsSync(c))return c;let l=$e.dirname(i);if(l===i)break;i=l}return null}var Mn=["@stacksjs/stx","bun-plugin-stx"];function Pi(t){try{let s=_e.readFileSync($e.join(t,"package.json"),"utf8"),i=JSON.parse(s)?.version;return typeof i==="string"?i:null}catch{return null}}function Oi(t,s=6){let i=$e.resolve(t),d=[],c=new Set;function l(p,h){if(h>s)return;let g;try{g=_e.realpathSync(p)}catch{return}if(c.has(g))return;c.add(g);for(let w of Mn){let S=$e.join(p,w),R=Pi(S);if(R!==null)d.push({name:w,version:R,dir:$e.relative(i,S)||S,nested:h>0})}let y;try{y=_e.readdirSync(p,{withFileTypes:!0})}catch{return}for(let w of y){if(!w.isDirectory()&&!w.isSymbolicLink())continue;if(w.name===".bin"||w.name===".cache")continue;let S=$e.join(p,w.name);if(w.name.startsWith("@")){let v;try{v=_e.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let x of v){let C=$e.join(S,x.name,"node_modules");if(_e.existsSync(C))l(C,h+1)}continue}let R=$e.join(S,"node_modules");if(_e.existsSync(R))l(R,h+1)}}let m=$e.join(i,"node_modules");if(_e.existsSync(m))l(m,0);return d}function Ai(t){let s=[];for(let i of Mn){let d=t.filter((m)=>m.name===i);if(d.length<=1)continue;let c=[...new Set(d.map((m)=>m.version))],l=d.map((m)=>`${m.version} at ${m.dir}`).join("; ");if(c.length===1){s.push({name:`${i} copies`,status:"info",detail:`${d.length} copies, all ${c[0]} \u2014 duplicated but in agreement`});continue}s.push({name:`${i} copies disagree`,status:"error",detail:`${c.length} versions installed, so which one runs depends on who imports it: ${l}`,fix:`remove the nested copies, or add an overrides entry pinning ${i}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${i}/package.json' -exec grep -H '"version"' {} +`})}return s}async function yr(t={}){let s=t.cwd?$e.resolve(t.cwd):process.cwd(),i=t.resolve??Ei,d=Date.now(),c=[],l=i("@stacksjs/stx",s);c.push(l?{name:"@stacksjs/stx resolves to",status:"ok",detail:l}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let m=i("bun-plugin-stx",s);if(m)c.push({name:"bun-plugin-stx resolves to",status:"ok",detail:m});for(let h of Ai(Oi(s)))c.push(h);let p=Dn(s,"stx");if(!p)c.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let h=$e.join(p,"src/signals.ts"),g=[$e.join(p,"dist/index.js"),$e.join(p,"dist/signals.js")].find((v)=>_e.existsSync(v))||null,y=On(h),w=g?On(g):null;if(y==null)c.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${p} but no src/signals.ts to compare`});else if(w==null)c.push({name:"pantry dist freshness",status:"error",detail:"pantry has src but no built dist \u2014 the dev server will resolve nothing (or a stale copy elsewhere)",fix:`cd ${p} && bun build.ts`});else if(w<y){let v=Math.round((y-w)/1000);c.push({name:"pantry dist freshness",status:"error",detail:`dist (${Dt(w,d)}) is OLDER than src/signals.ts (${Dt(y,d)}) by ${v}s \u2014 your edit isn't built`,fix:`cd ${p} && bun build.ts`})}else c.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Dt(y,d)}, dist ${Dt(w,d)})`});let S=$e.join(s,"node_modules/@stacksjs/stx"),R=null;try{R=_e.lstatSync(S)}catch{R=null}if(!R)c.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(R.isSymbolicLink()){let v=null;try{v=_e.realpathSync(S)}catch{}let x=(()=>{try{return _e.realpathSync(p)}catch{return p}})();c.push(v===x?{name:"node_modules \u2192 pantry",status:"ok",detail:"symlinked to pantry"}:{name:"node_modules \u2192 pantry",status:"warn",detail:`symlinked to ${v||"(dangling)"}, not pantry`})}else c.push({name:"node_modules \u2192 pantry",status:"warn",detail:"is a real directory, NOT symlinked to pantry \u2014 edits to pantry src/dist won't be resolved",fix:"rm -rf node_modules/@stacksjs/stx && ln -s ../../pantry/@stacksjs/stx node_modules/@stacksjs/stx"})}if(c.push({name:"dev runtime cache",status:"info",detail:"cleared automatically on source edits by the dev watcher (clearDevCaches, #1745 item C)"}),t.generateRuntime)try{let g=t.generateRuntime().length;c.push(g>1000?{name:"signals runtime",status:"ok",detail:`generated ${g.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${g} chars \u2014 suspiciously short`})}catch(h){c.push({name:"signals runtime",status:"error",detail:`failed to generate: ${h.message}`})}return{checks:c,ok:!c.some((h)=>h.status==="error")}}function br(t){let s={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},i=["stx runtime resolution:"];for(let d of t.checks)if(i.push(` ${s[d.status]} ${d.name}: ${d.detail}`),d.fix)i.push(` \u2192 ${d.fix}`);return i.push(""),i.push(t.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),i.join(`
|
|
1789
|
-
`)}var ft={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},d=new Set,c=i.webComponents?.enabled?`./${Mt.relative(Mt.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let m=await Jn(i,d);if(l.push(...m),i.debug&&m.length>0)console.log(`Successfully built ${m.length} web components`)}catch(m){console.error("Failed to build web components:",m)}t.onLoad({filter:/\.stx$/},async({path:m})=>{try{let p=new Set;if(i.cache&&i.cachePath){let x=await nn(m,i);if(x){if(i.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let h=await te(()=>Bun.file(m).text(),"",(x)=>{throw new yn(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!h)throw new yn(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:y,allScripts:w}=U.time("script-extraction",()=>{let x=h,C=Z(h);if(C)x=C.content.trim();let k=h.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],H="",_=[];for(let E of k){let L=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",B=E.match(/<script\b([^>]*)>/i),G=B?B[1]:"";if(/\bserver\b/i.test(G))H=L;else _.push(E)}let I=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:H,templateContent:I,allScripts:_}}),S={__filename:m,__dirname:Mt.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await te(()=>u(g,S,m),void 0,(x)=>{let C=new X(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(P.log(C,{filePath:m,scriptContent:g}),i.debug)throw C});let v=await U.timeAsync("directive-processing",async()=>await n(y,S,m,i,p));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-
|
|
1789
|
+
`)}var ft={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},d=new Set,c=i.webComponents?.enabled?`./${Mt.relative(Mt.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let m=await Jn(i,d);if(l.push(...m),i.debug&&m.length>0)console.log(`Successfully built ${m.length} web components`)}catch(m){console.error("Failed to build web components:",m)}t.onLoad({filter:/\.stx$/},async({path:m})=>{try{let p=new Set;if(i.cache&&i.cachePath){let x=await nn(m,i);if(x){if(i.debug)console.log(`Using cached version of ${m}`);return{contents:x,loader:"html"}}}let h=await te(()=>Bun.file(m).text(),"",(x)=>{throw new yn(`Failed to read stx file: ${m}`,m,void 0,void 0,`File read error: ${x.message}`)});if(!h)throw new yn(`stx file is empty: ${m}`,m);let{scriptContent:g,templateContent:y,allScripts:w}=U.time("script-extraction",()=>{let x=h,C=Z(h);if(C)x=C.content.trim();let k=h.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],H="",_=[];for(let E of k){let L=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",B=E.match(/<script\b([^>]*)>/i),G=B?B[1]:"";if(/\bserver\b/i.test(G))H=L;else _.push(E)}let I=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:H,templateContent:I,allScripts:_}}),S={__filename:m,__dirname:Mt.dirname(m),__stx:{webComponentsPath:c,builtComponents:l}};await te(()=>u(g,S,m),void 0,(x)=>{let C=new X(`Script execution failed in ${m}: ${x.message}`,m,void 0,void 0,g.substring(0,100));if(P.log(C,{filePath:m,scriptContent:g}),i.debug)throw C});let v=await U.timeAsync("directive-processing",async()=>await n(y,S,m,i,p));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-x2ghjgxm.js"),C=x(w.join(`
|
|
1790
1790
|
`),S),k=v.search(/<\/body>/i);if(k!==-1)v=v.slice(0,k)+C+`
|
|
1791
1791
|
`+v.slice(k);else v+=`
|
|
1792
1792
|
${C}`}if(v=await K(v),p.forEach((x)=>d.add(x)),i.cache&&i.cachePath){if(await rn(m,v,p,i),i.debug)console.log(`Cached template ${m} with ${p.size} dependencies`)}return{contents:v,loader:"html"}}catch(p){let h=p instanceof Error?p:new X(`Plugin processing failed: ${String(p)}`,m);if(P.log(h,{filePath:m,buildConfig:t.config}),Rt.logDetailedError(h,{filePath:m,plugin:"bun-plugin-stx"}),i.debug)console.error("stx Plugin Error:",h);let g=h,y=g.line||null,w=g.context||null;return{contents:i.debug||O()?`<!DOCTYPE html>
|
|
@@ -1849,7 +1849,7 @@ ${C}`}if(v=await K(v),p.forEach((x)=>d.add(x)),i.cache&&i.cachePath){if(await rn
|
|
|
1849
1849
|
<h1>Something went wrong</h1>
|
|
1850
1850
|
<p>An internal error occurred. Please try again later.</p>
|
|
1851
1851
|
</body>
|
|
1852
|
-
</html>`,loader:"html"}}})}};async function Cn(t,s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=Se.resolve(t);if(!Ne.existsSync(p))return console.error(`${e.red}Error: File not found: ${e.bright}${p}${e.reset}`),!1;if(p.endsWith(".md"))return Ft(p,s);else if(!p.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${p}${e.reset}. Only .stx and .md files are supported.`),!1;let h=a(process.cwd(),"output");Ne.mkdirSync(h,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,y=async()=>{try{let L={name:"public-assets",setup(Ce){Ce.onResolve({filter:/^\/(images|fonts|assets|public)\//},(ye)=>({path:ye.path,external:!0}))}},B=await Bun.build({entrypoints:[p],outdir:h,plugins:[L,ft],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!B.success)return console.error(`${e.red}Build failed:${e.reset}`,B.logs),!1;let G=B.outputs.find((Ce)=>Ce.path.endsWith(".html"));if(!G)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(G.path).text(),!0}catch(L){return console.error(`${e.red}Error building stx file:${e.reset}`,L),!1}};if(!await y())return!1;let S=Se.dirname(p);await kt(S);let R=i;try{if(R=await Ye(i),R!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${R} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let L=s.hmrPort||R+1;l=Pt({wsPort:L,verbose:!1}),m=l.start(L)}let v={},x=null,C;try{let{loadStxConfig:L}=await import("./chunk-
|
|
1852
|
+
</html>`,loader:"html"}}})}};async function Cn(t,s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=Se.resolve(t);if(!Ne.existsSync(p))return console.error(`${e.red}Error: File not found: ${e.bright}${p}${e.reset}`),!1;if(p.endsWith(".md"))return Ft(p,s);else if(!p.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${p}${e.reset}. Only .stx and .md files are supported.`),!1;let h=a(process.cwd(),"output");Ne.mkdirSync(h,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let g=null,y=async()=>{try{let L={name:"public-assets",setup(Ce){Ce.onResolve({filter:/^\/(images|fonts|assets|public)\//},(ye)=>({path:ye.path,external:!0}))}},B=await Bun.build({entrypoints:[p],outdir:h,plugins:[L,ft],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!B.success)return console.error(`${e.red}Build failed:${e.reset}`,B.logs),!1;let G=B.outputs.find((Ce)=>Ce.path.endsWith(".html"));if(!G)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return g=await Bun.file(G.path).text(),!0}catch(L){return console.error(`${e.red}Error building stx file:${e.reset}`,L),!1}};if(!await y())return!1;let S=Se.dirname(p);await kt(S);let R=i;try{if(R=await Ye(i),R!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${R} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let L=s.hmrPort||R+1;l=Pt({wsPort:L,verbose:!1}),m=l.start(L)}let v={},x=null,C;try{let{loadStxConfig:L}=await import("./chunk-c82gckm3.js"),B=await L();if(C=s.stxOptions?.serverApi??B.serverApi,B?.apiRouter)x=B?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(B?.apiRoutes){v=B.apiRoutes;let G=Object.keys(v).length;if(G>0)console.log(`${e.blue}Loaded ${e.bright}${G} API route${G>1?"s":""}${e.reset}`)}if(B?.broadcasting?.enabled)try{let{startBroadcasting:G,loadChannels:oe}=await import("./chunk-3c9t71pc.js"),Ce=B.broadcasting;await G(Ce);let ye=Ce.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${ye}/ws${e.reset}`);let De=Se.join(process.cwd(),"channels.ts");if(Ne.existsSync(De))try{let de=await oe(De);console.log(`${e.blue}Loaded ${e.bright}${de} broadcast channel${de!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(de){console.warn(`${e.yellow}Failed to load channels.ts: ${de.message}${e.reset}`)}}catch(G){console.warn(`${e.yellow}Broadcasting failed to start: ${G.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:H}=await import("./chunk-33meqm5e.js"),_=await k(process.cwd(),C);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${R}/${e.reset}...`),c)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${m}${e.reset}`);let I=Fi({port:R,async fetch(L){return It(L,await(async()=>{let B=new URL(L.url);if([h,Se.dirname(p),Se.join(process.cwd(),"public")].some((de)=>H(Se.join(de,B.pathname),process.cwd(),C)))return new Response("Not Found",{status:404});if(x)try{let de=await x.handleRequest(L);if(de.status!==404)return de}catch{}if(v[B.pathname])try{return await v[B.pathname](L)}catch(de){return new Response(JSON.stringify({error:de.message}),{status:500,headers:{"Content-Type":"application/json"}})}let G=await _(L);if(G)return G;if(B.pathname==="/")return(async()=>{let W=await f(g||"");if(c)W=Xe(W,m);if(s.native)if(W.includes("<head>"))W=W.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(W.includes("<html"))W=W.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 W="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+W;if(s.titlebarHidden)if(W.includes("<head>"))W=W.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(W.includes("<html"))W=W.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 W=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${W}`;return W})().then((W)=>new Response(W,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let oe=Se.join(h,B.pathname);if(Ne.existsSync(oe)&&Ne.statSync(oe).isFile()){let de=Bun.file(oe),W=Se.extname(oe).toLowerCase(),j="text/plain";if(W===".ts"||W===".tsx"){let Ue=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),qe=await de.text(),ct=Ue.transformSync(qe);return new Response(ct,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":j="text/html";break;case".css":j="text/css";break;case".js":j="text/javascript";break;case".json":j="application/json";break;case".png":j="image/png";break;case".jpg":case".jpeg":j="image/jpeg";break;case".gif":j="image/gif";break;case".woff":j="font/woff";break;case".woff2":j="font/woff2";break;case".ttf":j="font/ttf";break;case".otf":j="font/otf";break;case".eot":j="application/vnd.ms-fontobject";break}return new Response(de,{headers:{"Content-Type":j}})}let Ce=Se.dirname(p),ye=Se.join(Ce,B.pathname);if(Ne.existsSync(ye)&&Ne.statSync(ye).isFile()){let de=Bun.file(ye),W=Se.extname(ye).toLowerCase(),j="text/plain";if(W===".ts"||W===".tsx"){let Ue=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),qe=await de.text(),ct=Ue.transformSync(qe);return new Response(ct,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":j="text/html";break;case".css":j="text/css";break;case".js":j="text/javascript";break;case".json":j="application/json";break;case".png":j="image/png";break;case".jpg":case".jpeg":j="image/jpeg";break;case".gif":j="image/gif";break;case".svg":j="image/svg+xml";break;case".ico":j="image/x-icon";break;case".woff":j="font/woff";break;case".woff2":j="font/woff2";break;case".ttf":j="font/ttf";break;case".otf":j="font/otf";break;case".eot":j="application/vnd.ms-fontobject";break}return new Response(de,{headers:{"Content-Type":j}})}let De=Se.join(process.cwd(),"public",B.pathname);if(Ne.existsSync(De)&&Ne.statSync(De).isFile()){let de=Bun.file(De),W=Se.extname(De).toLowerCase(),j="application/octet-stream";if(W===".ts"||W===".tsx"){let Ue=new Bun.Transpiler({loader:W===".tsx"?"tsx":"ts"}),qe=await de.text(),ct=Ue.transformSync(qe);return new Response(ct,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(W){case".html":j="text/html";break;case".css":j="text/css";break;case".js":j="text/javascript";break;case".json":j="application/json";break;case".png":j="image/png";break;case".jpg":case".jpeg":j="image/jpeg";break;case".gif":j="image/gif";break;case".svg":j="image/svg+xml";break;case".ico":j="image/x-icon";break;case".woff":j="font/woff";break;case".woff2":j="font/woff2";break;case".ttf":j="font/ttf";break;case".otf":j="font/otf";break;case".eot":j="application/vnd.ms-fontobject";break}return new Response(de,{headers:{"Content-Type":j}})}return new Response("Not Found",{status:404})})())},error(L){return new Response(`<pre>${L}
|
|
1853
1853
|
${L.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
1854
1854
|
${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(`
|
|
1855
1855
|
${e.bright}\u2192 ${e.cyan}http://localhost:${R}/${e.reset}`),console.log(`
|
|
@@ -2025,9 +2025,9 @@ ${v.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),con
|
|
|
2025
2025
|
${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(`
|
|
2026
2026
|
${e.bright}\u2192 ${e.cyan}http://localhost:${y}/${e.reset}`),console.log(`
|
|
2027
2027
|
${e.yellow}Routes:${e.reset}`);let S=new Set(p.map((v)=>v.routeTemplate)),R=Object.entries(m).filter(([v])=>!S.has(v)).sort(([v],[x])=>v.localeCompare(x)).map(([v,x])=>({route:v==="/"?"/":v,filePath:Oe.relative(process.cwd(),x.filePath),fileType:x.fileType}));for(let v of p){let x=v.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");R.push({route:x,filePath:Oe.relative(process.cwd(),v.filePath),fileType:"stx"})}if(R.sort((v,x)=>v.route.localeCompare(x.route)),R.forEach((v,x)=>{let k=x===R.length-1?"\u2514\u2500 ":"\u251C\u2500 ",H=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${k}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${H}`)}),console.log(`
|
|
2028
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ze(w.url.toString(),()=>{if(d)it.watch(l,{recursive:!0}).close();w.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=it.watch(l,{recursive:!0},async(x,C)=>{if(!C)return;if(C.endsWith(".stx")||C.endsWith(".js")||C.endsWith(".ts")||C.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${C}${e.yellow} changed, rebuilding...${e.reset}`),be.clear(),ee(),await h()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function Wn(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Ni}=globalThis.Bun;import ve from"fs";import ie from"path";async function qn(t){try{return Ct(await Bun.file(t).text())}catch{return}}function qt(t){let s=Bun.file(t),i=ie.extname(t).toLowerCase(),d={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":d[i]||"application/octet-stream",...l}})}async function $n(t=".",s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=ie.resolve(t),{loadStxConfig:h}=await import("./chunk-j08y5n2k.js"),g=await h(p),{createServerApi:y,isServerApiSource:w}=await import("./chunk-8zj1ebs5.js"),S=s.stxOptions?.serverApi??g.serverApi,R=await y(p,S),v=g.root&&g.root!=="."?ie.join(p,g.root):p,x=s.pagesDir||g.pagesDir||"pages",C=ie.join(v,x);if(!ve.existsSync(C)&&!g._layerPageDirs?.some((D)=>ve.existsSync(D)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${C}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=N(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[C,...g._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${C}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let H=g?._pluginPageDirs||[],_=[];for(let{dir:D,prefix:F}of H)if(ve.existsSync(D)){let z=N(ie.dirname(D),{pagesDir:ie.basename(D)});for(let V of z){let we=F==="/"?V.pattern:`${F}${V.pattern==="/"?"":V.pattern}`;_.push({route:{...V,pattern:we},prefix:F})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${F}${e.reset}`)}let I=new Map,E=null,L=null;if(s.stxOptions?.shell!==!1){if(L=await co(p,s.stxOptions?.shell),L){if(E=await Cr(L,s.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${ie.relative(p,L)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}et(),await nt(p);let B=tt();if(B.length>0)console.log(`${e.blue}Loaded ${e.bright}${B.length}${e.blue} middleware: ${e.dim}${B.join(", ")}${e.reset}`);let G={},oe=null;try{let{loadStxConfig:D}=await import("./chunk-j08y5n2k.js"),F=await D(p);if(F?.apiRouter)oe=F?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(F?.apiRoutes){G=F.apiRoutes;let z=Object.keys(G).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:V}=await import("./chunk-3c9t71pc.js"),we=F.broadcasting;await z(we);let We=we.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${We}/ws${e.reset}`);let Ge=ie.join(process.cwd(),"channels.ts");if(ve.existsSync(Ge))try{let se=await V(Ge);console.log(`${e.blue}Loaded ${e.bright}${se} broadcast channel${se!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(se){console.warn(`${e.yellow}Failed to load channels.ts: ${se.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let Ce=a(p,"output");ve.mkdirSync(Ce,{recursive:!0});let ye=new Map,De=new Set,de=async(D)=>{let F=dr(C,D);if(!F)return null;try{let z=await Bun.build({entrypoints:[F],outdir:Ce,plugins:[ft],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!z.success)return null;let V=z.outputs.find((we)=>we.path.endsWith(".html"));if(!V)return null;return await Bun.file(V.path).text()}catch{return null}},W=new Map,j=async(D,F)=>{try{let{processDirectives:z,extractVariables:V,defaultConfig:we,loadStxConfig:We,injectRouterScript:Ge}=await import("./chunk-j08y5n2k.js"),{checkCache:se,cacheTemplate:Q,readFileCached:q,templateCache:J}=await import("./chunk-k5syze27.js"),Te=await We(p),Je=(pe)=>{if(!pe)return pe;if(ie.isAbsolute(pe))return pe;return ie.resolve(p,pe)},M={...we,...Te,...s.stxOptions,autoShell:!0};if(s.debugDirectives)M.debug=!0;M.partialsDir=Je(M.partialsDir),M.componentsDir=Je(M.componentsDir),M.layoutsDir=Je(M.layoutsDir),M.storesDir=Je(M.storesDir||"stores"),M.cachePath=Je(M.cachePath)??a(p,"cache");let xe=!F&&!s.profile,ue=M.cache!==!1;if(ue&&xe){let pe=J.get(D.filePath);if(pe)try{if((await ve.promises.stat(D.filePath)).mtime.getTime()<=pe.mtime){let He=!0;for(let Ee of pe.dependencies){if(!ve.existsSync(Ee)){He=!1;break}if((await ve.promises.stat(Ee)).mtime.getTime()>pe.mtime){He=!1;break}}if(He){let Ee=pe.output;if(E)Ee=me(Ee,{preserveHead:!0});let gt=W.get(D.filePath);return{route:D,content:Ee,status:gt?.status??await qn(D.filePath),headers:gt?.headers}}}}catch{}let Ie=await se(D.filePath,M);if(Ie){let je=Ie;if(E)je=me(je,{preserveHead:!0});let He=W.get(D.filePath);return{route:D,content:je,status:He?.status??await qn(D.filePath),headers:He?.headers}}}let he=ue?await q(D.filePath):await Bun.file(D.filePath).text(),Re=Ct(he),{classifyAllScripts:Y}=await import("./chunk-j08y5n2k.js"),Le=Y(he),Ve=Le.server.map((pe)=>pe.content),fe=he;for(let pe of Le.server)fe=fe.replace(pe.fullTag,"");let ge={__filename:D.filePath,__dirname:ie.dirname(D.filePath),__stx_options:M,params:F??{},__stx_runtime_head:{}};for(let pe of Ve)try{await V(pe,ge,D.filePath)}catch(Ie){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",D.filePath,Ie?.message||Ie)}let Ke=new Set,Me;if(s.profile){let pe=performance.now();Me=await z(fe,ge,D.filePath,M,Ke);let Ie=performance.now()-pe,je=ie.relative(p,D.filePath)||D.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else Me=await z(fe,ge,D.filePath,M,Ke);if(!E)Me=await Ge(Me,{router:M.router});{let{interpolateScriptExpressions:pe}=await import("./chunk-cb1c9mvc.js");Me=Me.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,je,He)=>{if(!/function\s+__stx_setup_/.test(He))return Ie;return`<script${je}>${pe(He,ge)}</script>`})}if(E)Me=me(Me,{preserveHead:!0});if(ue&&xe)await Q(D.filePath,Me,Ke,M);let{extractStreamBoundaries:Kn}=await import("./chunk-nnrtwpvy.js"),lt=Kn(ge),mt=ge.__streamTemplates;if(mt&&typeof mt==="object"&&Object.keys(mt).length>0){let pe=ge.streamBoundaries||{},Ie={...M,autoShell:!1},je=Object.keys(mt).map((Ee)=>({id:Ee,render:async()=>{let gt=typeof pe[Ee]==="function"?await pe[Ee]():void 0;return z(mt[Ee],{...ge,$boundary:gt},D.filePath,Ie,new Set)}})),He=new Set(je.map((Ee)=>Ee.id));lt=[...(lt||[]).filter((Ee)=>!He.has(Ee.id)),...je]}if(lt&<.length>0)De.add(D.pattern);else lt=void 0;let Kt=Fe(ge),Xt=ze(ge);if(xe)W.set(D.filePath,{status:Kt,headers:Xt});return{route:D,content:Me,status:Kt??Re,headers:Xt,boundaries:lt}}catch(z){return console.error(`${e.red}Error building ${e.bright}${D.pattern}${e.reset}:`,z),null}},Ue=8,qe=async()=>{ye.clear(),I.clear();for(let D=0;D<k.length;D+=Ue){let F=k.slice(D,D+Ue),z=await Promise.all(F.map((V)=>j(V)));for(let V of z)if(V)ye.set(V.route.pattern,V)}for(let D=0;D<_.length;D+=Ue){let F=_.slice(D,D+Ue),z=await Promise.all(F.map(({route:V})=>j(V)));for(let V of z)if(V)I.set(V.route.pattern,V)}return ye.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await qe())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await kt(p);let at=i;try{if(at=await Ye(i),at!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${at} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let D=s.hmrPort||at+1;l=Pt({wsPort:D,verbose:!1}),m=l.start(D)}let _t=(D,F)=>{let V=`<script data-stx-route-params>(function(){var p=${JSON.stringify(F).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(D.includes("</head>"))return D.replace("</head>",`${V}</head>`);if(D.includes("<body"))return D.replace(/<body([^>]*)>/,`<body$1>${V}`);return V+D};console.log(`${e.blue}Starting server...${e.reset}`);let Lt=Ni({port:at,async fetch(D){let F=new URL(D.url),z=g?.publicDir||"public",V=ie.join(p,z,F.pathname),we=ie.join(p,F.pathname),We=ie.join(Ce,F.pathname);if([V,we,We].some((M)=>w(M,p,S)))return new Response("Not Found",{status:404});let[Ge,se,Q]=await Promise.all([ve.promises.stat(V).catch(()=>null),ve.promises.stat(we).catch(()=>null),ve.promises.stat(We).catch(()=>null)]);if(Ge?.isFile()&&!w(V,p,S))return qt(V);if(se?.isFile()&&!w(we,p,S))return qt(we);if(Q?.isFile()&&!w(We,p,S))return qt(We);if(F.pathname.startsWith("/_stx/component/")){let M=decodeURIComponent(F.pathname.slice(16));if(M)try{let xe=`<${M} />`,ue={...buildConfig,autoShell:!1},he=await processDirectives(xe,{},ie.join(p,"components",`${M}.stx`),ue,new Set);return new Response(he,{headers:{"Content-Type":"text/html"}})}catch(xe){return new Response(`<div class="stx-async-error">${xe.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(F.pathname==="/_stx/img"){let{handleImageRequest:M}=await import("./chunk-vc1m5fr9.js"),xe=await M(D,{publicDir:ie.join(p,z),cacheDir:a(p,"cache","img")});if(xe)return xe}if(oe)try{let M=await oe.handleRequest(D);if(M.status!==404)return M}catch{}if(G[F.pathname])try{return await G[F.pathname](D)}catch(M){return new Response(JSON.stringify({error:M.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await R(D);if(q)return q;let J=xn(F.pathname,k);if(J){let M=ye.get(J.route.pattern),xe=De.has(J.route.pattern);if(J.route.isDynamic&&Object.keys(J.params).length>0||xe){let ue=await j(J.route,J.params);if(ue)M=ue}if(M){let ue=M.status??200,he=M.headers??{},Re=(J.route.filePath?Be(await Bun.file(J.route.filePath).text().catch(()=>"")):null)??{};if(Re.validate){if(!await Re.validate({params:J.params})){let Ve=await de(404);if(Ve){let fe=Ve;if(fe=await f(fe,p),c)fe=Xe(fe,m);return new Response(fe,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(Re.middleware){let Le=rt(F.pathname,J.params,Re,F.search),Ve=st(Le,null,D,{isServer:!0}),fe=await ot(Re.middleware,Ve);if(fe.redirect){let ge=fe.redirect.path,Ke=fe.redirect.options.redirectCode||302,Me=new Headers(fe.responseHeaders);return Me.set("Location",ge),new Response(null,{status:Ke,headers:Me})}if(fe.abort){let{statusCode:ge,message:Ke}=fe.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${ge}</title></head><body><h1>Error ${ge}</h1><p>${Ke}</p></body></html>`,{status:ge,headers:{"Content-Type":"text/html"}})}if(Object.keys(fe.state).length>0){let ge=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(fe.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;M.content=M.content.replace("</head>",`${ge}</head>`)}}let Y=M.content;if(E&&lo(D)){let Le=ke(Y),Ve=ce(Y),fe=Y.match(/<title[^>]*>([\s\S]*?)<\/title>/i),ge=fe?ao(fe[1].trim()):"";if(Object.keys(J.params).length>0)Y=_t(Y,J.params);Y=await f(Y,p);let Ke=g?.router?.container||"main";return Y=re(Y,Ke),new Response(Y,{status:ue,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":Ve?"true":"false",...ge&&{"X-STX-Title":encodeURIComponent(ge)},[pi]:bs(),...T(),"Cache-Control":Ae}})}if(E)Y=An(E,Y);if(Object.keys(J.params).length>0)Y=_t(Y,J.params);if(Y=await f(Y,p),c)Y=Xe(Y,m);if(s.native)if(Y.includes("<head>"))Y=Y.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 Y="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+Y;if(s.titlebarHidden)if(Y.includes("<head>"))Y=Y.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 Y=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${Y}`;if(M.boundaries&&M.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:Ve}=await import("./chunk-nnrtwpvy.js");return Ve(Le(Y,M.boundaries,{timeoutMs:30000}),{status:ue,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(Y,{status:ue,headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...he}})}}if(_.length>0){let M=_.map((ue)=>ue.route),xe=xn(F.pathname,M);if(xe){let ue=I.get(xe.route.pattern);if(ue){let he=ue.content;if(E)he=An(E,he);if(Object.keys(xe.params).length>0)he=_t(he,xe.params);if(he=await f(he,p),c)he=Xe(he,m);return new Response(he,{status:ue.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:ue}of H)if(ue!=="/"&&F.pathname.startsWith(ue)){let he=I.get(ue)||I.get(ue+"/");if(he){let Re=he.content;if(E)Re=An(E,Re);if(Re=await f(Re,p),c)Re=Xe(Re,m);return new Response(Re,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(Qe(F.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Te=ye.get("/");if(Te){let M=Te.content;if(M=await f(M,p),c)M=Xe(M,m);if(s.native)if(M.includes("<head>"))M=M.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else M="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+M;return new Response(M,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Je=await de(404);if(Je){let M=Je;if(M=await f(M,p),c)M=Xe(M,m);return new Response(M,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(D){let F=await de(500);if(F)return new Response(F,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${D}
|
|
2028
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ze(w.url.toString(),()=>{if(d)it.watch(l,{recursive:!0}).close();w.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=it.watch(l,{recursive:!0},async(x,C)=>{if(!C)return;if(C.endsWith(".stx")||C.endsWith(".js")||C.endsWith(".ts")||C.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${C}${e.yellow} changed, rebuilding...${e.reset}`),be.clear(),ee(),await h()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function Wn(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Ni}=globalThis.Bun;import ve from"fs";import ie from"path";async function qn(t){try{return Ct(await Bun.file(t).text())}catch{return}}function qt(t){let s=Bun.file(t),i=ie.extname(t).toLowerCase(),d={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(s,{headers:{"Content-Type":d[i]||"application/octet-stream",...l}})}async function $n(t=".",s={}){let i=s.port||3000,d=s.watch!==!1,c=s.hotReload!==!1&&d,l=null,m=s.hmrPort||i+1,p=ie.resolve(t),{loadStxConfig:h}=await import("./chunk-c82gckm3.js"),g=await h(p),{createServerApi:y,isServerApiSource:w}=await import("./chunk-33meqm5e.js"),S=s.stxOptions?.serverApi??g.serverApi,R=await y(p,S),v=g.root&&g.root!=="."?ie.join(p,g.root):p,x=s.pagesDir||g.pagesDir||"pages",C=ie.join(v,x);if(!ve.existsSync(C)&&!g._layerPageDirs?.some((D)=>ve.existsSync(D)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${C}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=N(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[C,...g._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${C}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let H=g?._pluginPageDirs||[],_=[];for(let{dir:D,prefix:F}of H)if(ve.existsSync(D)){let z=N(ie.dirname(D),{pagesDir:ie.basename(D)});for(let V of z){let we=F==="/"?V.pattern:`${F}${V.pattern==="/"?"":V.pattern}`;_.push({route:{...V,pattern:we},prefix:F})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${F}${e.reset}`)}let I=new Map,E=null,L=null;if(s.stxOptions?.shell!==!1){if(L=await co(p,s.stxOptions?.shell),L){if(E=await Cr(L,s.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${ie.relative(p,L)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}et(),await nt(p);let B=tt();if(B.length>0)console.log(`${e.blue}Loaded ${e.bright}${B.length}${e.blue} middleware: ${e.dim}${B.join(", ")}${e.reset}`);let G={},oe=null;try{let{loadStxConfig:D}=await import("./chunk-c82gckm3.js"),F=await D(p);if(F?.apiRouter)oe=F?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(F?.apiRoutes){G=F.apiRoutes;let z=Object.keys(G).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:V}=await import("./chunk-3c9t71pc.js"),we=F.broadcasting;await z(we);let We=we.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${We}/ws${e.reset}`);let Ge=ie.join(process.cwd(),"channels.ts");if(ve.existsSync(Ge))try{let se=await V(Ge);console.log(`${e.blue}Loaded ${e.bright}${se} broadcast channel${se!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(se){console.warn(`${e.yellow}Failed to load channels.ts: ${se.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let Ce=a(p,"output");ve.mkdirSync(Ce,{recursive:!0});let ye=new Map,De=new Set,de=async(D)=>{let F=dr(C,D);if(!F)return null;try{let z=await Bun.build({entrypoints:[F],outdir:Ce,plugins:[ft],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...s.stxOptions});if(!z.success)return null;let V=z.outputs.find((we)=>we.path.endsWith(".html"));if(!V)return null;return await Bun.file(V.path).text()}catch{return null}},W=new Map,j=async(D,F)=>{try{let{processDirectives:z,extractVariables:V,defaultConfig:we,loadStxConfig:We,injectRouterScript:Ge}=await import("./chunk-c82gckm3.js"),{checkCache:se,cacheTemplate:Q,readFileCached:q,templateCache:J}=await import("./chunk-1r3fmmy8.js"),Te=await We(p),Je=(pe)=>{if(!pe)return pe;if(ie.isAbsolute(pe))return pe;return ie.resolve(p,pe)},M={...we,...Te,...s.stxOptions,autoShell:!0};if(s.debugDirectives)M.debug=!0;M.partialsDir=Je(M.partialsDir),M.componentsDir=Je(M.componentsDir),M.layoutsDir=Je(M.layoutsDir),M.storesDir=Je(M.storesDir||"stores"),M.cachePath=Je(M.cachePath)??a(p,"cache");let xe=!F&&!s.profile,ue=M.cache!==!1;if(ue&&xe){let pe=J.get(D.filePath);if(pe)try{if((await ve.promises.stat(D.filePath)).mtime.getTime()<=pe.mtime){let He=!0;for(let Ee of pe.dependencies){if(!ve.existsSync(Ee)){He=!1;break}if((await ve.promises.stat(Ee)).mtime.getTime()>pe.mtime){He=!1;break}}if(He){let Ee=pe.output;if(E)Ee=me(Ee,{preserveHead:!0});let gt=W.get(D.filePath);return{route:D,content:Ee,status:gt?.status??await qn(D.filePath),headers:gt?.headers}}}}catch{}let Ie=await se(D.filePath,M);if(Ie){let je=Ie;if(E)je=me(je,{preserveHead:!0});let He=W.get(D.filePath);return{route:D,content:je,status:He?.status??await qn(D.filePath),headers:He?.headers}}}let he=ue?await q(D.filePath):await Bun.file(D.filePath).text(),Re=Ct(he),{classifyAllScripts:Y}=await import("./chunk-c82gckm3.js"),Le=Y(he),Ve=Le.server.map((pe)=>pe.content),fe=he;for(let pe of Le.server)fe=fe.replace(pe.fullTag,"");let ge={__filename:D.filePath,__dirname:ie.dirname(D.filePath),__stx_options:M,params:F??{},__stx_runtime_head:{}};for(let pe of Ve)try{await V(pe,ge,D.filePath)}catch(Ie){if(s.stxOptions?.debug)console.error("[stx] variable extraction error",D.filePath,Ie?.message||Ie)}let Ke=new Set,Me;if(s.profile){let pe=performance.now();Me=await z(fe,ge,D.filePath,M,Ke);let Ie=performance.now()-pe,je=ie.relative(p,D.filePath)||D.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else Me=await z(fe,ge,D.filePath,M,Ke);if(!E)Me=await Ge(Me,{router:M.router});{let{interpolateScriptExpressions:pe}=await import("./chunk-x2ghjgxm.js");Me=Me.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,je,He)=>{if(!/function\s+__stx_setup_/.test(He))return Ie;return`<script${je}>${pe(He,ge)}</script>`})}if(E)Me=me(Me,{preserveHead:!0});if(ue&&xe)await Q(D.filePath,Me,Ke,M);let{extractStreamBoundaries:Kn}=await import("./chunk-5tvxv2v1.js"),lt=Kn(ge),mt=ge.__streamTemplates;if(mt&&typeof mt==="object"&&Object.keys(mt).length>0){let pe=ge.streamBoundaries||{},Ie={...M,autoShell:!1},je=Object.keys(mt).map((Ee)=>({id:Ee,render:async()=>{let gt=typeof pe[Ee]==="function"?await pe[Ee]():void 0;return z(mt[Ee],{...ge,$boundary:gt},D.filePath,Ie,new Set)}})),He=new Set(je.map((Ee)=>Ee.id));lt=[...(lt||[]).filter((Ee)=>!He.has(Ee.id)),...je]}if(lt&<.length>0)De.add(D.pattern);else lt=void 0;let Kt=Fe(ge),Xt=ze(ge);if(xe)W.set(D.filePath,{status:Kt,headers:Xt});return{route:D,content:Me,status:Kt??Re,headers:Xt,boundaries:lt}}catch(z){return console.error(`${e.red}Error building ${e.bright}${D.pattern}${e.reset}:`,z),null}},Ue=8,qe=async()=>{ye.clear(),I.clear();for(let D=0;D<k.length;D+=Ue){let F=k.slice(D,D+Ue),z=await Promise.all(F.map((V)=>j(V)));for(let V of z)if(V)ye.set(V.route.pattern,V)}for(let D=0;D<_.length;D+=Ue){let F=_.slice(D,D+Ue),z=await Promise.all(F.map(({route:V})=>j(V)));for(let V of z)if(V)I.set(V.route.pattern,V)}return ye.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await qe())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await kt(p);let at=i;try{if(at=await Ye(i),at!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${at} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(c){let D=s.hmrPort||at+1;l=Pt({wsPort:D,verbose:!1}),m=l.start(D)}let _t=(D,F)=>{let V=`<script data-stx-route-params>(function(){var p=${JSON.stringify(F).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(D.includes("</head>"))return D.replace("</head>",`${V}</head>`);if(D.includes("<body"))return D.replace(/<body([^>]*)>/,`<body$1>${V}`);return V+D};console.log(`${e.blue}Starting server...${e.reset}`);let Lt=Ni({port:at,async fetch(D){let F=new URL(D.url),z=g?.publicDir||"public",V=ie.join(p,z,F.pathname),we=ie.join(p,F.pathname),We=ie.join(Ce,F.pathname);if([V,we,We].some((M)=>w(M,p,S)))return new Response("Not Found",{status:404});let[Ge,se,Q]=await Promise.all([ve.promises.stat(V).catch(()=>null),ve.promises.stat(we).catch(()=>null),ve.promises.stat(We).catch(()=>null)]);if(Ge?.isFile()&&!w(V,p,S))return qt(V);if(se?.isFile()&&!w(we,p,S))return qt(we);if(Q?.isFile()&&!w(We,p,S))return qt(We);if(F.pathname.startsWith("/_stx/component/")){let M=decodeURIComponent(F.pathname.slice(16));if(M)try{let xe=`<${M} />`,ue={...buildConfig,autoShell:!1},he=await processDirectives(xe,{},ie.join(p,"components",`${M}.stx`),ue,new Set);return new Response(he,{headers:{"Content-Type":"text/html"}})}catch(xe){return new Response(`<div class="stx-async-error">${xe.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(F.pathname==="/_stx/img"){let{handleImageRequest:M}=await import("./chunk-vc1m5fr9.js"),xe=await M(D,{publicDir:ie.join(p,z),cacheDir:a(p,"cache","img")});if(xe)return xe}if(oe)try{let M=await oe.handleRequest(D);if(M.status!==404)return M}catch{}if(G[F.pathname])try{return await G[F.pathname](D)}catch(M){return new Response(JSON.stringify({error:M.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await R(D);if(q)return q;let J=xn(F.pathname,k);if(J){let M=ye.get(J.route.pattern),xe=De.has(J.route.pattern);if(J.route.isDynamic&&Object.keys(J.params).length>0||xe){let ue=await j(J.route,J.params);if(ue)M=ue}if(M){let ue=M.status??200,he=M.headers??{},Re=(J.route.filePath?Be(await Bun.file(J.route.filePath).text().catch(()=>"")):null)??{};if(Re.validate){if(!await Re.validate({params:J.params})){let Ve=await de(404);if(Ve){let fe=Ve;if(fe=await f(fe,p),c)fe=Xe(fe,m);return new Response(fe,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(Re.middleware){let Le=rt(F.pathname,J.params,Re,F.search),Ve=st(Le,null,D,{isServer:!0}),fe=await ot(Re.middleware,Ve);if(fe.redirect){let ge=fe.redirect.path,Ke=fe.redirect.options.redirectCode||302,Me=new Headers(fe.responseHeaders);return Me.set("Location",ge),new Response(null,{status:Ke,headers:Me})}if(fe.abort){let{statusCode:ge,message:Ke}=fe.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${ge}</title></head><body><h1>Error ${ge}</h1><p>${Ke}</p></body></html>`,{status:ge,headers:{"Content-Type":"text/html"}})}if(Object.keys(fe.state).length>0){let ge=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(fe.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;M.content=M.content.replace("</head>",`${ge}</head>`)}}let Y=M.content;if(E&&lo(D)){let Le=ke(Y),Ve=ce(Y),fe=Y.match(/<title[^>]*>([\s\S]*?)<\/title>/i),ge=fe?ao(fe[1].trim()):"";if(Object.keys(J.params).length>0)Y=_t(Y,J.params);Y=await f(Y,p);let Ke=g?.router?.container||"main";return Y=re(Y,Ke),new Response(Y,{status:ue,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":Ve?"true":"false",...ge&&{"X-STX-Title":encodeURIComponent(ge)},[pi]:bs(),...T(),"Cache-Control":Ae}})}if(E)Y=An(E,Y);if(Object.keys(J.params).length>0)Y=_t(Y,J.params);if(Y=await f(Y,p),c)Y=Xe(Y,m);if(s.native)if(Y.includes("<head>"))Y=Y.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 Y="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+Y;if(s.titlebarHidden)if(Y.includes("<head>"))Y=Y.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 Y=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${Y}`;if(M.boundaries&&M.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:Ve}=await import("./chunk-5tvxv2v1.js");return Ve(Le(Y,M.boundaries,{timeoutMs:30000}),{status:ue,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(Y,{status:ue,headers:{"Content-Type":"text/html",...T(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...he}})}}if(_.length>0){let M=_.map((ue)=>ue.route),xe=xn(F.pathname,M);if(xe){let ue=I.get(xe.route.pattern);if(ue){let he=ue.content;if(E)he=An(E,he);if(Object.keys(xe.params).length>0)he=_t(he,xe.params);if(he=await f(he,p),c)he=Xe(he,m);return new Response(he,{status:ue.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:ue}of H)if(ue!=="/"&&F.pathname.startsWith(ue)){let he=I.get(ue)||I.get(ue+"/");if(he){let Re=he.content;if(E)Re=An(E,Re);if(Re=await f(Re,p),c)Re=Xe(Re,m);return new Response(Re,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(Qe(F.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Te=ye.get("/");if(Te){let M=Te.content;if(M=await f(M,p),c)M=Xe(M,m);if(s.native)if(M.includes("<head>"))M=M.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else M="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+M;return new Response(M,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let Je=await de(404);if(Je){let M=Je;if(M=await f(M,p),c)M=Xe(M,m);return new Response(M,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(D){let F=await de(500);if(F)return new Response(F,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${D}
|
|
2029
2029
|
${D.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});if(console.clear(),console.log(`
|
|
2030
2030
|
${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(`
|
|
2031
2031
|
${e.bright}\u2192 ${e.cyan}http://localhost:${at}/${e.reset}`),c)console.log(`${e.dim} HMR: ws://localhost:${m}${e.reset}`);console.log(`
|
|
2032
2032
|
${e.yellow}Routes:${e.reset}`);let jt=[...ur(k,p)];for(let{route:D}of _)jt.push(`${D.pattern}`);if(jt.forEach((D,F)=>{let V=F===jt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${V}${e.reset}${D}`)}),console.log(`
|
|
2033
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ze(Lt.url.toString(),()=>{if(l)ht();Lt.stop()}),s.native){let D,F=ie.join(C,"index.stx");if(ve.existsSync(F)){let V=await Bun.file(F).text();D=St(V)}let z=g?.app?.window??{};await dt(at,{title:g?.app?.head?.title||ie.basename(p)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!D,sidebarConfig:D})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let D=(se)=>se.startsWith("public/")||se.startsWith("public\\"),F=(se)=>{let Q=se.toLowerCase();return Q.endsWith(".stx")||Q.endsWith(".html")||Q.endsWith(".md")},z=new Map,V=()=>{let se=new Set([p,...g._layerGraph?.layers.map((Q)=>Q.root)??[],...g._layerGraph?.configDependencies.map((Q)=>ie.dirname(Q))??[]].filter((Q)=>ve.existsSync(Q)).map((Q)=>ve.realpathSync(Q)));for(let Q of g._layerGraph?.layers??[])for(let q of Object.values(Q.resources)){if(!ve.existsSync(q))continue;let J=ve.realpathSync(q);if(![...se].some((Te)=>J===Te||J.startsWith(`${Te}${ie.sep}`)))se.add(J)}for(let[Q,q]of z)if(!se.has(Q))q.close(),z.delete(Q);for(let Q of se)if(!z.has(Q)&&ve.existsSync(Q))z.set(Q,ve.watch(Q,{recursive:!0},(q,J)=>{We(Q,q,J).catch((Te)=>console.error("[stx] Layer rebuild failed:",Te))}))},we=Promise.resolve(),We=(se,Q,q)=>(we=we.catch(()=>{}).then(()=>Ge(se,Q,q)),we),Ge=async(se,Q,q)=>{if(!q||Et(q))return;if($t(q)){if(g._layerGraph){let J=await h(p);Object.assign(g,J),k.splice(0,k.length,...N(v,{pagesDir:x,pagesDirs:J._layerPageDirs?[C,...J._layerPageDirs.slice(1)]:void 0})),V()}if(D(q)){if(console.log(`${e.cyan}${q} changed${e.reset}`),c&&l)l.reload(q)}else if(F(q)){console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),be.clear(),ee();try{let{invalidateFileCache:J,templateCache:Te}=await import("./chunk-
|
|
2033
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ze(Lt.url.toString(),()=>{if(l)ht();Lt.stop()}),s.native){let D,F=ie.join(C,"index.stx");if(ve.existsSync(F)){let V=await Bun.file(F).text();D=St(V)}let z=g?.app?.window??{};await dt(at,{title:g?.app?.head?.title||ie.basename(p)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??s.titlebarHidden===!0,nativeSidebar:!!D,sidebarConfig:D})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let D=(se)=>se.startsWith("public/")||se.startsWith("public\\"),F=(se)=>{let Q=se.toLowerCase();return Q.endsWith(".stx")||Q.endsWith(".html")||Q.endsWith(".md")},z=new Map,V=()=>{let se=new Set([p,...g._layerGraph?.layers.map((Q)=>Q.root)??[],...g._layerGraph?.configDependencies.map((Q)=>ie.dirname(Q))??[]].filter((Q)=>ve.existsSync(Q)).map((Q)=>ve.realpathSync(Q)));for(let Q of g._layerGraph?.layers??[])for(let q of Object.values(Q.resources)){if(!ve.existsSync(q))continue;let J=ve.realpathSync(q);if(![...se].some((Te)=>J===Te||J.startsWith(`${Te}${ie.sep}`)))se.add(J)}for(let[Q,q]of z)if(!se.has(Q))q.close(),z.delete(Q);for(let Q of se)if(!z.has(Q)&&ve.existsSync(Q))z.set(Q,ve.watch(Q,{recursive:!0},(q,J)=>{We(Q,q,J).catch((Te)=>console.error("[stx] Layer rebuild failed:",Te))}))},we=Promise.resolve(),We=(se,Q,q)=>(we=we.catch(()=>{}).then(()=>Ge(se,Q,q)),we),Ge=async(se,Q,q)=>{if(!q||Et(q))return;if($t(q)){if(g._layerGraph){let J=await h(p);Object.assign(g,J),k.splice(0,k.length,...N(v,{pagesDir:x,pagesDirs:J._layerPageDirs?[C,...J._layerPageDirs.slice(1)]:void 0})),V()}if(D(q)){if(console.log(`${e.cyan}${q} changed${e.reset}`),c&&l)l.reload(q)}else if(F(q)){console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),be.clear(),ee();try{let{invalidateFileCache:J,templateCache:Te}=await import("./chunk-1r3fmmy8.js");J(ie.resolve(se,q)),Te.delete(ie.resolve(se,q))}catch{}if(L&&q){if(ie.resolve(se,q)===L||ie.basename(L)===q){let Te=await Cr(L,s.stxOptions||{});if(Te)E=Te}}if(await qe(),await sn(p),c&&l)l.reload(q)}else{console.log(`${e.yellow}${q} changed, rebuilding...${e.reset}`),be.clear(),ee();try{let{invalidateFileCache:J,templateCache:Te}=await import("./chunk-1r3fmmy8.js");J(ie.resolve(se,q)),Te.delete(ie.resolve(se,q))}catch{}if(await qe(),c&&l)l.reload(q)}}else if(Tt(q)){if(console.log(`${e.cyan}CSS ${q} changed${e.reset}`),c&&l)l.updateCss(q)}};V(),process.on("SIGINT",()=>{for(let se of z.values())se.close();if(l)ht();Lt.stop(),process.exit(0)})}return!0}export{Ks,Xs,Gs,Js,hr,Ys,Zs,Qs,Ui,Wi,yr,br,Cn,En,$n};
|