@stacksjs/stx 0.2.667 → 0.2.669
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-ec9ztgxx.js → chunk-03wssg2z.js} +1 -1
- package/dist/{chunk-r883qzmx.js → chunk-0q0tpmr5.js} +1 -1
- package/dist/chunk-0zrskbkk.js +2 -0
- package/dist/{chunk-8gy90n5q.js → chunk-144yp2bw.js} +1 -1
- package/dist/{chunk-b54s3qde.js → chunk-1cnwcn01.js} +1 -1
- package/dist/{chunk-mekhzhes.js → chunk-1mz8fw0m.js} +4 -4
- package/dist/chunk-21jz51jg.js +2 -0
- package/dist/chunk-2bspyg11.js +2 -0
- package/dist/{chunk-f62hpbw8.js → chunk-43r0hjne.js} +1 -1
- package/dist/{chunk-t886718q.js → chunk-4b1ed4qv.js} +1 -1
- package/dist/chunk-5hqrw558.js +2 -0
- package/dist/{chunk-bj2xzkv6.js → chunk-5j970c0z.js} +1 -1
- package/dist/{chunk-b42p0kvz.js → chunk-5pe26hxm.js} +1 -1
- package/dist/{chunk-an6y1v5h.js → chunk-604yfrmq.js} +1 -1
- package/dist/{chunk-j045bcpb.js → chunk-679tc0c4.js} +1 -1
- package/dist/{chunk-fbcp9hm4.js → chunk-7n7078xp.js} +1 -1
- package/dist/chunk-7nsb5pxp.js +2 -0
- package/dist/chunk-7tp1j22e.js +2 -0
- package/dist/{chunk-qrq88ng0.js → chunk-87bs5f18.js} +1 -1
- package/dist/{chunk-mn3mc6ax.js → chunk-8rx1bves.js} +1 -1
- package/dist/{chunk-wpsm2p9x.js → chunk-8w9z30yx.js} +1 -1
- package/dist/{chunk-bey0cjrp.js → chunk-9hngzqp5.js} +1 -1
- package/dist/{chunk-bs7hq5a3.js → chunk-ackk8wq5.js} +1 -1
- package/dist/{chunk-gjck0t32.js → chunk-b5ktzth7.js} +5 -5
- package/dist/{chunk-gfmw85vw.js → chunk-b7vz9m5q.js} +1 -1
- package/dist/{chunk-yphmswg3.js → chunk-bmd035rk.js} +1 -1
- package/dist/{chunk-wfjq9ww1.js → chunk-cca86043.js} +1 -1
- package/dist/{chunk-6jwey47v.js → chunk-d2zzqfgq.js} +2 -2
- package/dist/{chunk-6h06rqmj.js → chunk-d5d1b6w0.js} +1 -1
- package/dist/{chunk-4htp92hr.js → chunk-e7wxt37f.js} +1 -1
- package/dist/{chunk-jzy0pqez.js → chunk-ea7ekakt.js} +4 -4
- package/dist/{chunk-4701f9eh.js → chunk-ev0t17cq.js} +1 -1
- package/dist/{chunk-rns1e0c5.js → chunk-fpbff6s1.js} +1 -1
- package/dist/{chunk-n5r1xek6.js → chunk-gea2ty3e.js} +1 -1
- package/dist/{chunk-ydf4fmr6.js → chunk-gmgdmsdz.js} +1 -1
- package/dist/{chunk-ghsmfkq9.js → chunk-hesyghn7.js} +1 -1
- package/dist/chunk-hnx88y3p.js +130 -0
- package/dist/{chunk-sgj6dt85.js → chunk-j10smv8e.js} +1 -1
- package/dist/{chunk-znb4y12p.js → chunk-jf1vs526.js} +2 -2
- package/dist/{chunk-dvrndj0q.js → chunk-jsqh5fyn.js} +1 -1
- package/dist/{chunk-85sa9q09.js → chunk-jz6t1nes.js} +1 -1
- package/dist/{chunk-bexp6dsp.js → chunk-kd6qactf.js} +2 -2
- package/dist/{chunk-w51q85zg.js → chunk-ken0q08p.js} +5 -5
- package/dist/chunk-kff0hgg5.js +2 -0
- package/dist/chunk-m1ggzh60.js +2 -0
- package/dist/{chunk-fwwt7nrc.js → chunk-mezzmwc5.js} +1 -1
- package/dist/chunk-msm3gqay.js +2 -0
- package/dist/{chunk-qxsvd26z.js → chunk-ndhkwfyq.js} +1 -1
- package/dist/{chunk-t226hswj.js → chunk-nt7jxmpy.js} +1 -1
- package/dist/{chunk-hjn7qqrq.js → chunk-nx6d1hj7.js} +1 -1
- package/dist/{chunk-fsef9nvs.js → chunk-nytb5e4v.js} +2 -2
- package/dist/{chunk-4qh789bq.js → chunk-nzj3a6mj.js} +1 -1
- package/dist/{chunk-c7d09931.js → chunk-p23sz4rr.js} +6 -6
- package/dist/{chunk-1y5ampxc.js → chunk-p5sjezzx.js} +1 -1
- package/dist/{chunk-ndffc344.js → chunk-xrdrwrfe.js} +1 -1
- package/dist/chunk-y1kaq1cd.js +2 -0
- package/dist/{chunk-1ffjj2c6.js → chunk-ynyssmdy.js} +2 -2
- package/dist/{chunk-hc70e121.js → chunk-ys3tmk8w.js} +1 -1
- package/dist/{chunk-crcypbbq.js → chunk-ywqs7x8g.js} +1 -1
- package/dist/{chunk-zx2vhrps.js → chunk-zshhn7nz.js} +1 -1
- package/dist/{chunk-j7mr8h2w.js → chunk-ztp2rgpp.js} +2 -2
- package/dist/cli.js +7 -7
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/native/compiler/headwind-to-style.js +24 -1
- package/dist/native/compiler/html-to-ir.js +44 -2
- package/dist/native/compiler/layout-chrome.js +51 -4
- package/dist/native/runtime/jsc-globals.d.ts +20 -0
- package/dist/native/runtime/jsc-globals.js +52 -0
- package/dist/native/testing.d.ts +0 -1
- package/dist/native/testing.js +31 -4
- package/dist/pwa.js +1 -1
- package/dist/ssg.js +2 -2
- package/package.json +5 -5
- package/dist/chunk-0syr525r.js +0 -2
- package/dist/chunk-2265dwpm.js +0 -2
- package/dist/chunk-4s284y6c.js +0 -2
- package/dist/chunk-7y2htsr8.js +0 -2
- package/dist/chunk-bheh3z8r.js +0 -2
- package/dist/chunk-dq42tzg1.js +0 -2
- package/dist/chunk-fmzhrwt1.js +0 -2
- package/dist/chunk-fqhmee37.js +0 -129
- package/dist/chunk-hqwr25qg.js +0 -2
- package/dist/chunk-m72b5043.js +0 -2
- package/dist/chunk-w1qvq9jf.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{te,ae,cn,Rt,At,g,n,de,d}from"./chunk-
|
|
2
|
+
import{te,ae,cn,Rt,At,g,n,de,d}from"./chunk-p23sz4rr.js";import{gt,Te,ta,Ys,s}from"./chunk-ken0q08p.js";import{re,ur,we,D,hn}from"./chunk-2dp7hyv7.js";import{vt,Zn,Zr,Qr,es,wt,xt,St,kt,_t,Ct,Je}from"./chunk-365vg0eg.js";import{qr,o,R}from"./chunk-nytb5e4v.js";import{ut,Ci,Se,O,Ei,js,$r,He,Ti,ke}from"./chunk-jf1vs526.js";import{Xn,Jn}from"./chunk-87bs5f18.js";import{xn}from"./chunk-7n7078xp.js";import{e,en,Wn,h}from"./chunk-ztp2rgpp.js";import{qe}from"./chunk-1mz8fw0m.js";import{Ee}from"./chunk-md2jn67b.js";import{V,ge,me}from"./chunk-ea7ekakt.js";import{c}from"./chunk-zhf01af3.js";import{H}from"./chunk-fbtv2k1p.js";async function Fn(t){try{let r=await Bun.file(t).text(),i=zn(r),p=Nn(r,t),a=Un(r,i),l=Vn(r,i);return{file:t,metrics:i,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
|
`),i=t.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),a=(i?i[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 i=[],p=qt(t,"if","endif");if(p>0)i.push({type:"error",category:"syntax",message:`Found ${p} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let a=qt(t,"foreach","endforeach");if(a>0)i.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)i.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let f=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(f>0)i.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)i.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)i.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)i.push({type:"info",category:"maintainability",message:`Found ${m} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return i}function Un(t,r){let i=[];if(r.complexity>7)i.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)i.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(r.lines>100&&r.components===0)i.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(r.expressions>20)i.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)i.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)i.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(r.scriptLines>50)i.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return i}function Vn(t,r){let i=1;if(i+=r.directives.conditionals*0.1,i+=r.directives.loops*0.5,i+=r.directives.includes*2,i+=r.expressions*0.05,i+=r.components*1,r.scriptLines>10)i+=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(i>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(i*100)/100,complexityScore:r.complexity,cacheability:p,recommendations:a}}function qt(t,r,i){let p=t.replace(/<!--[\s\S]*?-->/g,""),a=(p.match(new RegExp(`@${r}\\b`,"g"))||[]).length,l=(p.match(new RegExp(`@${i}\\b`,"g"))||[]).length;return Math.abs(a-l)}async function pi(t=["**/*.stx"],r){let i=[],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);i.push(f)}catch(f){console.warn(`Failed to analyze ${l}:`,f)}let a=qn(i);return{results:i,summary:a}}function qn(t){let r=t.length,i=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:i,avgComplexity:Math.round(p*100)/100,totalIssues:a,issuesByCategory:l,performanceScore:u,recommendations:y}}import{mkdir as Kn,readFile as Gn,readdir as Yn,stat as Kt,writeFile as Qn}from"fs/promises";import $e from"path";function Zt(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 er(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((r)=>r.charAt(0).toUpperCase()+r.slice(1)).join("")}function It(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function tr(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 i(p){let a=await Yn(p,{withFileTypes:!0});a.sort((l,f)=>l.name.localeCompare(f.name));for(let l of a){let f=$e.join(p,l.name);if(l.isDirectory()){if(!l.name.startsWith(".")&&l.name!=="node_modules")await i(f)}else if(l.isFile()&&l.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(l.name))r.push(f)}}return await i(t),r}function or(t,r){let i=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!i)return{};let p=i[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 i={},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 ${Zt(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 ":"";i[y]=`${v}${y}(${u[2]}) {${l.slice(m,C-1)}}`,f.lastIndex=C}}return i}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 Xt(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,i={}){let p=Fr(r,i),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 ht(t){let r=t.toLowerCase();return r.endsWith(".css")||r.endsWith(".scss")||r.endsWith(".sass")||r.endsWith(".less")}function yt(t){let r=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((p)=>r.endsWith(p))}function bt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((i)=>i.test(t))}var tt=null;function Tt(t){if(!tt)tt=new rn(t);return tt}function st(){if(tt)tt.stop(),tt=null}import $t from"path";var nt={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},p=new Set,a=i.webComponents?.enabled?`./${$t.relative($t.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let f=await qr(i,p);if(l.push(...f),i.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(i.cache&&i.cachePath){let x=await Xn(f,i);if(x){if(i.debug)console.log(`Using cached version of ${f}`);return{contents:x,loader:"html"}}}let y=await we(()=>Bun.file(f).text(),"",(x)=>{throw new ur(`Failed to read stx file: ${f}`,f,void 0,void 0,`File read error: ${x.message}`)});if(!y)throw new ur(`stx file is empty: ${f}`,f);let{scriptContent:m,templateContent:b,allScripts:w}=te.time("script-extraction",()=>{let x=y,T=ae(y);if(T)x=T.content.trim();let k=y.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],j="",M=[];for(let E of k){let _=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",B=E.match(/<script\b([^>]*)>/i),q=B?B[1]:"";if(/\bserver\b/i.test(q))j=_;else M.push(E)}let L=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:j,templateContent:L,allScripts:M}}),S={__filename:f,__dirname:$t.dirname(f),__stx:{webComponentsPath:a,builtComponents:l}};await we(()=>g(m,S,f),void 0,(x)=>{let T=new re(`Script execution failed in ${f}: ${x.message}`,f,void 0,void 0,m.substring(0,100));if(D.log(T,{filePath:f,scriptContent:m}),i.debug)throw T});let v=await te.timeAsync("directive-processing",async()=>await s(b,S,f,i,u));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-
|
|
879
|
+
`}function Ne(t,r,i={}){let p=Fr(r,i),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 ht(t){let r=t.toLowerCase();return r.endsWith(".css")||r.endsWith(".scss")||r.endsWith(".sass")||r.endsWith(".less")}function yt(t){let r=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((p)=>r.endsWith(p))}function bt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((i)=>i.test(t))}var tt=null;function Tt(t){if(!tt)tt=new rn(t);return tt}function st(){if(tt)tt.stop(),tt=null}import $t from"path";var nt={name:"bun-plugin-stx",async setup(t){let i={...await o(),...t.config?.stx},p=new Set,a=i.webComponents?.enabled?`./${$t.relative($t.dirname(t.config?.outdir||"dist"),i.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(i.webComponents?.enabled)try{let f=await qr(i,p);if(l.push(...f),i.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(i.cache&&i.cachePath){let x=await Xn(f,i);if(x){if(i.debug)console.log(`Using cached version of ${f}`);return{contents:x,loader:"html"}}}let y=await we(()=>Bun.file(f).text(),"",(x)=>{throw new ur(`Failed to read stx file: ${f}`,f,void 0,void 0,`File read error: ${x.message}`)});if(!y)throw new ur(`stx file is empty: ${f}`,f);let{scriptContent:m,templateContent:b,allScripts:w}=te.time("script-extraction",()=>{let x=y,T=ae(y);if(T)x=T.content.trim();let k=y.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],j="",M=[];for(let E of k){let _=E.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",B=E.match(/<script\b([^>]*)>/i),q=B?B[1]:"";if(/\bserver\b/i.test(q))j=_;else M.push(E)}let L=x.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:j,templateContent:L,allScripts:M}}),S={__filename:f,__dirname:$t.dirname(f),__stx:{webComponentsPath:a,builtComponents:l}};await we(()=>g(m,S,f),void 0,(x)=>{let T=new re(`Script execution failed in ${f}: ${x.message}`,f,void 0,void 0,m.substring(0,100));if(D.log(T,{filePath:f,scriptContent:m}),i.debug)throw T});let v=await te.timeAsync("directive-processing",async()=>await s(b,S,f,i,u));if(w.length>0){let{interpolateScriptsInTemplate:x}=await import("./chunk-zshhn7nz.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 me(v),u.forEach((x)=>p.add(x)),i.cache&&i.cachePath){if(await Jn(f,v,u,i),i.debug)console.log(`Cached template ${f} with ${u.size} dependencies`)}return{contents:v,loader:"html"}}catch(u){let y=u instanceof Error?u:new re(`Plugin processing failed: ${String(u)}`,f);if(D.log(y,{filePath:f,buildConfig:t.config}),hn.logDetailedError(y,{filePath:f,plugin:"bun-plugin-stx"}),i.debug)console.error("stx Plugin Error:",y);let m=y,b=m.line||null,w=m.context||null;return{contents:i.debug||H()?`<!DOCTYPE html>
|
|
@@ -939,7 +939,7 @@ ${T}`}if(v=await me(v),u.forEach((x)=>p.add(x)),i.cache&&i.cachePath){if(await J
|
|
|
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 Sr(t,r={}){let i=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||i+1,u=fe.resolve(t);if(!Le.existsSync(u))return console.error(`${e.red}Error: File not found: ${e.bright}${u}${e.reset}`),!1;if(u.endsWith(".md"))return Bt(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");Le.mkdirSync(y,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let m=null,b=async()=>{try{let _={name:"public-assets",setup(be){be.onResolve({filter:/^\/(images|fonts|assets|public)\//},(ce)=>({path:ce.path,external:!0}))}},B=await Bun.build({entrypoints:[u],outdir:y,plugins:[_,nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!B.success)return console.error(`${e.red}Build failed:${e.reset}`,B.logs),!1;let q=B.outputs.find((be)=>be.path.endsWith(".html"));if(!q)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return m=await Bun.file(q.path).text(),!0}catch(_){return console.error(`${e.red}Error building stx file:${e.reset}`,_),!1}};if(!await b())return!1;let S=fe.dirname(u);await en(S);let C=i;try{if(C=await Ve(i),C!==i)console.log(`${e.yellow}Port ${i} 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 _=r.hmrPort||C+1;l=Tt({wsPort:_,verbose:!1}),f=l.start(_)}let v={},x=null,T;try{let{loadStxConfig:_}=await import("./chunk-
|
|
942
|
+
</html>`,loader:"html"}}})}};async function Sr(t,r={}){let i=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||i+1,u=fe.resolve(t);if(!Le.existsSync(u))return console.error(`${e.red}Error: File not found: ${e.bright}${u}${e.reset}`),!1;if(u.endsWith(".md"))return Bt(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");Le.mkdirSync(y,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let m=null,b=async()=>{try{let _={name:"public-assets",setup(be){be.onResolve({filter:/^\/(images|fonts|assets|public)\//},(ce)=>({path:ce.path,external:!0}))}},B=await Bun.build({entrypoints:[u],outdir:y,plugins:[_,nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!B.success)return console.error(`${e.red}Build failed:${e.reset}`,B.logs),!1;let q=B.outputs.find((be)=>be.path.endsWith(".html"));if(!q)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return m=await Bun.file(q.path).text(),!0}catch(_){return console.error(`${e.red}Error building stx file:${e.reset}`,_),!1}};if(!await b())return!1;let S=fe.dirname(u);await en(S);let C=i;try{if(C=await Ve(i),C!==i)console.log(`${e.yellow}Port ${i} 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 _=r.hmrPort||C+1;l=Tt({wsPort:_,verbose:!1}),f=l.start(_)}let v={},x=null,T;try{let{loadStxConfig:_}=await import("./chunk-7tp1j22e.js"),B=await _();if(T=r.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 q=Object.keys(v).length;if(q>0)console.log(`${e.blue}Loaded ${e.bright}${q} API route${q>1?"s":""}${e.reset}`)}if(B?.broadcasting?.enabled)try{let{startBroadcasting:q,loadChannels:J}=await import("./chunk-j0v970k3.js"),be=B.broadcasting;await q(be);let ce=be.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${ce}/ws${e.reset}`);let Re=fe.join(process.cwd(),"channels.ts");if(Le.existsSync(Re))try{let Z=await J(Re);console.log(`${e.blue}Loaded ${e.bright}${Z} broadcast channel${Z!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(Z){console.warn(`${e.yellow}Failed to load channels.ts: ${Z.message}${e.reset}`)}}catch(q){console.warn(`${e.yellow}Broadcasting failed to start: ${q.message}${e.reset}`)}}catch{}let{createServerApi:k,isServerApiSource:j}=await import("./chunk-b7vz9m5q.js"),M=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 L=zr({port:C,async fetch(_){return xn(_,await(async()=>{let B=new URL(_.url);if([y,fe.dirname(u),fe.join(process.cwd(),"public")].some((Z)=>j(fe.join(Z,B.pathname),process.cwd(),T)))return new Response("Not Found",{status:404});if(x)try{let Z=await x.handleRequest(_);if(Z.status!==404)return Z}catch{}if(v[B.pathname])try{return await v[B.pathname](_)}catch(Z){return new Response(JSON.stringify({error:Z.message}),{status:500,headers:{"Content-Type":"application/json"}})}let q=await M(_);if(q)return q;if(B.pathname==="/")return(async()=>{let N=await h(m||"");if(a)N=Ne(N,f);if(r.native)if(N.includes("<head>"))N=N.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(N.includes("<html"))N=N.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 N="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+N;if(r.titlebarHidden)if(N.includes("<head>"))N=N.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(N.includes("<html"))N=N.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 N=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${N}`;return N})().then((N)=>new Response(N,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let J=fe.join(y,B.pathname);if(Le.existsSync(J)&&Le.statSync(J).isFile()){let Z=Bun.file(J),N=fe.extname(J).toLowerCase(),I="text/plain";if(N===".ts"||N===".tsx"){let Ie=new Bun.Transpiler({loader:N===".tsx"?"tsx":"ts"}),Fe=await Z.text(),Ye=Ie.transformSync(Fe);return new Response(Ye,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(N){case".html":I="text/html";break;case".css":I="text/css";break;case".js":I="text/javascript";break;case".json":I="application/json";break;case".png":I="image/png";break;case".jpg":case".jpeg":I="image/jpeg";break;case".gif":I="image/gif";break;case".woff":I="font/woff";break;case".woff2":I="font/woff2";break;case".ttf":I="font/ttf";break;case".otf":I="font/otf";break;case".eot":I="application/vnd.ms-fontobject";break}return new Response(Z,{headers:{"Content-Type":I}})}let be=fe.dirname(u),ce=fe.join(be,B.pathname);if(Le.existsSync(ce)&&Le.statSync(ce).isFile()){let Z=Bun.file(ce),N=fe.extname(ce).toLowerCase(),I="text/plain";if(N===".ts"||N===".tsx"){let Ie=new Bun.Transpiler({loader:N===".tsx"?"tsx":"ts"}),Fe=await Z.text(),Ye=Ie.transformSync(Fe);return new Response(Ye,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(N){case".html":I="text/html";break;case".css":I="text/css";break;case".js":I="text/javascript";break;case".json":I="application/json";break;case".png":I="image/png";break;case".jpg":case".jpeg":I="image/jpeg";break;case".gif":I="image/gif";break;case".svg":I="image/svg+xml";break;case".ico":I="image/x-icon";break;case".woff":I="font/woff";break;case".woff2":I="font/woff2";break;case".ttf":I="font/ttf";break;case".otf":I="font/otf";break;case".eot":I="application/vnd.ms-fontobject";break}return new Response(Z,{headers:{"Content-Type":I}})}let Re=fe.join(process.cwd(),"public",B.pathname);if(Le.existsSync(Re)&&Le.statSync(Re).isFile()){let Z=Bun.file(Re),N=fe.extname(Re).toLowerCase(),I="application/octet-stream";if(N===".ts"||N===".tsx"){let Ie=new Bun.Transpiler({loader:N===".tsx"?"tsx":"ts"}),Fe=await Z.text(),Ye=Ie.transformSync(Fe);return new Response(Ye,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(N){case".html":I="text/html";break;case".css":I="text/css";break;case".js":I="text/javascript";break;case".json":I="application/json";break;case".png":I="image/png";break;case".jpg":case".jpeg":I="image/jpeg";break;case".gif":I="image/gif";break;case".svg":I="image/svg+xml";break;case".ico":I="image/x-icon";break;case".woff":I="font/woff";break;case".woff2":I="font/woff2";break;case".ttf":I="font/ttf";break;case".otf":I="font/otf";break;case".eot":I="application/vnd.ms-fontobject";break}return new Response(Z,{headers:{"Content-Type":I}})}return new Response("Not Found",{status:404})})())},error(_){return new Response(`<pre>${_}
|
|
943
943
|
${_.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:Ce.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:Ce.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 ",j=v.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${k}${v.route}${e.reset} \u2192 ${e.bright}${v.filePath}${e.reset} ${j}`)}),console.log(`
|
|
1429
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(w.url.toString(),()=>{if(p)Xe.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Xe.watch(l,{recursive:!0},async(x,T)=>{if(!T)return;if(T.endsWith(".stx")||T.endsWith(".js")||T.endsWith(".ts")||T.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${T}${e.yellow} changed, rebuilding...${e.reset}`),qe.clear(),de(),await y()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function sn(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Ur}=globalThis.Bun;import pe from"fs";import Q from"path";async function ln(t){try{return cn(await Bun.file(t).text())}catch{return}}function Ft(t){let r=Bun.file(t),i=Q.extname(t).toLowerCase(),p={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(r,{headers:{"Content-Type":p[i]||"application/octet-stream",...l}})}async function _r(t=".",r={}){let i=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||i+1,u=Q.resolve(t),{loadStxConfig:y}=await import("./chunk-2265dwpm.js"),m=await y(u),{createServerApi:b,isServerApiSource:w}=await import("./chunk-gfmw85vw.js"),S=r.stxOptions?.serverApi??m.serverApi,C=await b(u,S),v=m.root&&m.root!=="."?Q.join(u,m.root):u,x=r.pagesDir||m.pagesDir||"pages",T=Q.join(v,x);if(!pe.existsSync(T)&&!m._layerPageDirs?.some((P)=>pe.existsSync(P)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${T}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=V(v,{pagesDir:x,pagesDirs:m._layerPageDirs?[T,...m._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${T}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let j=m?._pluginPageDirs||[],M=[];for(let{dir:P,prefix:F}of j)if(pe.existsSync(P)){let z=V(Q.dirname(P),{pagesDir:Q.basename(P)});for(let U of z){let ue=F==="/"?U.pattern:`${F}${U.pattern==="/"?"":U.pattern}`;M.push({route:{...U,pattern:ue},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 L=new Map,E=null,_=null;if(r.stxOptions?.shell!==!1){if(_=await Ei(u,r.stxOptions?.shell),_){if(E=await js(_,r.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${Q.relative(u,_)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}wt(),await St(u);let B=xt();if(B.length>0)console.log(`${e.blue}Loaded ${e.bright}${B.length}${e.blue} middleware: ${e.dim}${B.join(", ")}${e.reset}`);let q={},J=null;try{let{loadStxConfig:P}=await import("./chunk-2265dwpm.js"),F=await P(u);if(F?.apiRouter)J=F?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(F?.apiRoutes){q=F.apiRoutes;let z=Object.keys(q).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:U}=await import("./chunk-j0v970k3.js"),ue=F.broadcasting;await z(ue);let je=ue.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${je}/ws${e.reset}`);let Ue=Q.join(process.cwd(),"channels.ts");if(pe.existsSync(Ue))try{let Y=await U(Ue);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(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let be=c(u,"output");pe.mkdirSync(be,{recursive:!0});let ce=new Map,Re=new Set,Z=async(P)=>{let F=Qr(T,P);if(!F)return null;try{let z=await Bun.build({entrypoints:[F],outdir:be,plugins:[nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!z.success)return null;let U=z.outputs.find((ue)=>ue.path.endsWith(".html"));if(!U)return null;return await Bun.file(U.path).text()}catch{return null}},N=new Map,I=async(P,F)=>{try{let{processDirectives:z,extractVariables:U,defaultConfig:ue,loadStxConfig:je,injectRouterScript:Ue}=await import("./chunk-2265dwpm.js"),{checkCache:Y,cacheTemplate:G,readFileCached:W,templateCache:K}=await import("./chunk-dvrndj0q.js"),he=await je(u),We=(ee)=>{if(!ee)return ee;if(Q.isAbsolute(ee))return ee;return Q.resolve(u,ee)},A={...ue,...he,...r.stxOptions,autoShell:!0};if(r.debugDirectives)A.debug=!0;A.partialsDir=We(A.partialsDir),A.componentsDir=We(A.componentsDir),A.layoutsDir=We(A.layoutsDir),A.storesDir=We(A.storesDir||"stores"),A.cachePath=We(A.cachePath)??c(u,"cache");let le=!F&&!r.profile,ne=A.cache!==!1;if(ne&&le){let ee=K.get(P.filePath);if(ee)try{if((await pe.promises.stat(P.filePath)).mtime.getTime()<=ee.mtime){let _e=!0;for(let ve of ee.dependencies){if(!pe.existsSync(ve)){_e=!1;break}if((await pe.promises.stat(ve)).mtime.getTime()>ee.mtime){_e=!1;break}}if(_e){let ve=ee.output;if(E)ve=He(ve,{preserveHead:!0});let ot=N.get(P.filePath);return{route:P,content:ve,status:ot?.status??await ln(P.filePath),headers:ot?.headers}}}}catch{}let De=await Y(P.filePath,A);if(De){let Me=De;if(E)Me=He(Me,{preserveHead:!0});let _e=N.get(P.filePath);return{route:P,content:Me,status:_e?.status??await ln(P.filePath),headers:_e?.headers}}}let ie=ne?await W(P.filePath):await Bun.file(P.filePath).text(),xe=cn(ie),{classifyAllScripts:X}=await import("./chunk-2265dwpm.js"),Ae=X(ie),Be=Ae.server.map((ee)=>ee.content),oe=ie;for(let ee of Ae.server)oe=oe.replace(ee.fullTag,"");let se={__filename:P.filePath,__dirname:Q.dirname(P.filePath),__stx_options:A,params:F??{},__stx_runtime_head:{}};for(let ee of Be)try{await U(ee,se,P.filePath)}catch(De){if(r.stxOptions?.debug)console.error("[stx] variable extraction error",P.filePath,De?.message||De)}let ze=new Set,Pe;if(r.profile){let ee=performance.now();Pe=await z(oe,se,P.filePath,A,ze);let De=performance.now()-ee,Me=Q.relative(u,P.filePath)||P.filePath;console.log(`[stx:profile] ${Me} \u2192 ${De.toFixed(2)}ms`)}else Pe=await z(oe,se,P.filePath,A,ze);if(!E)Pe=await Ue(Pe,{router:A.router});{let{interpolateScriptExpressions:ee}=await import("./chunk-zx2vhrps.js");Pe=Pe.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(De,Me,_e)=>{if(!/function\s+__stx_setup_/.test(_e))return De;return`<script${Me}>${ee(_e,se)}</script>`})}if(E)Pe=He(Pe,{preserveHead:!0});if(ne&&le)await G(P.filePath,Pe,ze,A);let{extractStreamBoundaries:Hn}=await import("./chunk-m72b5043.js"),Qe=Hn(se),rt=se.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let ee=se.streamBoundaries||{},De={...A,autoShell:!1},Me=Object.keys(rt).map((ve)=>({id:ve,render:async()=>{let ot=typeof ee[ve]==="function"?await ee[ve]():void 0;return z(rt[ve],{...se,$boundary:ot},P.filePath,De,new Set)}})),_e=new Set(Me.map((ve)=>ve.id));Qe=[...(Qe||[]).filter((ve)=>!_e.has(ve.id)),...Me]}if(Qe&&Qe.length>0)Re.add(P.pattern);else Qe=void 0;let Ut=Rt(se),Wt=At(se);if(le)N.set(P.filePath,{status:Ut,headers:Wt});return{route:P,content:Pe,status:Ut??xe,headers:Wt,boundaries:Qe}}catch(z){return console.error(`${e.red}Error building ${e.bright}${P.pattern}${e.reset}:`,z),null}},Ie=8,Fe=async()=>{ce.clear(),L.clear();for(let P=0;P<k.length;P+=Ie){let F=k.slice(P,P+Ie),z=await Promise.all(F.map((U)=>I(U)));for(let U of z)if(U)ce.set(U.route.pattern,U)}for(let P=0;P<M.length;P+=Ie){let F=M.slice(P,P+Ie),z=await Promise.all(F.map(({route:U})=>I(U)));for(let U of z)if(U)L.set(U.route.pattern,U)}return ce.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await Fe())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await en(u);let Ge=i;try{if(Ge=await Ve(i),Ge!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${Ge} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(a){let P=r.hmrPort||Ge+1;l=Tt({wsPort:P,verbose:!1}),f=l.start(P)}let Pt=(P,F)=>{let U=`<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(P.includes("</head>"))return P.replace("</head>",`${U}</head>`);if(P.includes("<body"))return P.replace(/<body([^>]*)>/,`<body$1>${U}`);return U+P};console.log(`${e.blue}Starting server...${e.reset}`);let Ot=Ur({port:Ge,async fetch(P){let F=new URL(P.url),z=m?.publicDir||"public",U=Q.join(u,z,F.pathname),ue=Q.join(u,F.pathname),je=Q.join(be,F.pathname);if([U,ue,je].some((A)=>w(A,u,S)))return new Response("Not Found",{status:404});let[Ue,Y,G]=await Promise.all([pe.promises.stat(U).catch(()=>null),pe.promises.stat(ue).catch(()=>null),pe.promises.stat(je).catch(()=>null)]);if(Ue?.isFile()&&!w(U,u,S))return Ft(U);if(Y?.isFile()&&!w(ue,u,S))return Ft(ue);if(G?.isFile()&&!w(je,u,S))return Ft(je);if(F.pathname.startsWith("/_stx/component/")){let A=decodeURIComponent(F.pathname.slice(16));if(A)try{let le=`<${A} />`,ne={...buildConfig,autoShell:!1},ie=await processDirectives(le,{},Q.join(u,"components",`${A}.stx`),ne,new Set);return new Response(ie,{headers:{"Content-Type":"text/html"}})}catch(le){return new Response(`<div class="stx-async-error">${le.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(F.pathname==="/_stx/img"){let{handleImageRequest:A}=await import("./chunk-5zgrvj4b.js"),le=await A(P,{publicDir:Q.join(u,z),cacheDir:c(u,"cache","img")});if(le)return le}if(J)try{let A=await J.handleRequest(P);if(A.status!==404)return A}catch{}if(q[F.pathname])try{return await q[F.pathname](P)}catch(A){return new Response(JSON.stringify({error:A.message}),{status:500,headers:{"Content-Type":"application/json"}})}let W=await C(P);if(W)return W;let K=Zn(F.pathname,k);if(K){let A=ce.get(K.route.pattern),le=Re.has(K.route.pattern);if(K.route.isDynamic&&Object.keys(K.params).length>0||le){let ne=await I(K.route,K.params);if(ne)A=ne}if(A){let ne=A.status??200,ie=A.headers??{},xe=(K.route.filePath?gt(await Bun.file(K.route.filePath).text().catch(()=>"")):null)??{};if(xe.validate){if(!await xe.validate({params:K.params})){let Be=await Z(404);if(Be){let oe=Be;if(oe=await h(oe,u),a)oe=Ne(oe,f);return new Response(oe,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(xe.middleware){let Ae=kt(F.pathname,K.params,xe,F.search),Be=_t(Ae,null,P,{isServer:!0}),oe=await Ct(xe.middleware,Be);if(oe.redirect){let se=oe.redirect.path,ze=oe.redirect.options.redirectCode||302,Pe=new Headers(oe.responseHeaders);return Pe.set("Location",se),new Response(null,{status:ze,headers:Pe})}if(oe.abort){let{statusCode:se,message:ze}=oe.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${se}</title></head><body><h1>Error ${se}</h1><p>${ze}</p></body></html>`,{status:se,headers:{"Content-Type":"text/html"}})}if(Object.keys(oe.state).length>0){let se=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(oe.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;A.content=A.content.replace("</head>",`${se}</head>`)}}let X=A.content;if(E&&Ti(P)){let Ae=Je(X),Be=ge(X),oe=X.match(/<title[^>]*>([\s\S]*?)<\/title>/i),se=oe?Ci(oe[1].trim()):"";if(Object.keys(K.params).length>0)X=Pt(X,K.params);X=await h(X,u);let ze=m?.router?.container||"main";return X=ke(X,ze),new Response(X,{status:ne,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Ae.layout,"X-STX-Layout-Group":Ae.group,"X-STX-Runtime":Be?"true":"false",...se&&{"X-STX-Title":encodeURIComponent(se)},[ta]:Ys(),...O(),"Cache-Control":ut}})}if(E)X=$r(E,X);if(Object.keys(K.params).length>0)X=Pt(X,K.params);if(X=await h(X,u),a)X=Ne(X,f);if(r.native)if(X.includes("<head>"))X=X.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else X="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+X;if(r.titlebarHidden)if(X.includes("<head>"))X=X.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else X=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${X}`;if(A.boundaries&&A.boundaries.length>0){let{renderStreamingPage:Ae,streamToResponse:Be}=await import("./chunk-m72b5043.js");return Be(Ae(X,A.boundaries,{timeoutMs:30000}),{status:ne,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(X,{status:ne,headers:{"Content-Type":"text/html",...O(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ie}})}}if(M.length>0){let A=M.map((ne)=>ne.route),le=Zn(F.pathname,A);if(le){let ne=L.get(le.route.pattern);if(ne){let ie=ne.content;if(E)ie=$r(E,ie);if(Object.keys(le.params).length>0)ie=Pt(ie,le.params);if(ie=await h(ie,u),a)ie=Ne(ie,f);return new Response(ie,{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 j)if(ne!=="/"&&F.pathname.startsWith(ne)){let ie=L.get(ne)||L.get(ne+"/");if(ie){let xe=ie.content;if(E)xe=$r(E,xe);if(xe=await h(xe,u),a)xe=Ne(xe,f);return new Response(xe,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(vt(F.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let he=ce.get("/");if(he){let A=he.content;if(A=await h(A,u),a)A=Ne(A,f);if(r.native)if(A.includes("<head>"))A=A.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else A="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+A;return new Response(A,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let We=await Z(404);if(We){let A=We;if(A=await h(A,u),a)A=Ne(A,f);return new Response(A,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(P){let F=await Z(500);if(F)return new Response(F,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${P}
|
|
1429
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(w.url.toString(),()=>{if(p)Xe.watch(l,{recursive:!0}).close();w.stop()}),p){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Xe.watch(l,{recursive:!0},async(x,T)=>{if(!T)return;if(T.endsWith(".stx")||T.endsWith(".js")||T.endsWith(".ts")||T.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${T}${e.yellow} changed, rebuilding...${e.reset}`),qe.clear(),de(),await y()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function sn(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Ur}=globalThis.Bun;import pe from"fs";import Q from"path";async function ln(t){try{return cn(await Bun.file(t).text())}catch{return}}function Ft(t){let r=Bun.file(t),i=Q.extname(t).toLowerCase(),p={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},l=[".js",".css",".json"].includes(i)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(r,{headers:{"Content-Type":p[i]||"application/octet-stream",...l}})}async function _r(t=".",r={}){let i=r.port||3000,p=r.watch!==!1,a=r.hotReload!==!1&&p,l=null,f=r.hmrPort||i+1,u=Q.resolve(t),{loadStxConfig:y}=await import("./chunk-7tp1j22e.js"),m=await y(u),{createServerApi:b,isServerApiSource:w}=await import("./chunk-b7vz9m5q.js"),S=r.stxOptions?.serverApi??m.serverApi,C=await b(u,S),v=m.root&&m.root!=="."?Q.join(u,m.root):u,x=r.pagesDir||m.pagesDir||"pages",T=Q.join(v,x);if(!pe.existsSync(T)&&!m._layerPageDirs?.some((P)=>pe.existsSync(P)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${T}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=V(v,{pagesDir:x,pagesDirs:m._layerPageDirs?[T,...m._layerPageDirs.slice(1)]:void 0});if(k.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${T}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${k.length}${e.blue} routes${e.reset}`);let j=m?._pluginPageDirs||[],M=[];for(let{dir:P,prefix:F}of j)if(pe.existsSync(P)){let z=V(Q.dirname(P),{pagesDir:Q.basename(P)});for(let U of z){let ue=F==="/"?U.pattern:`${F}${U.pattern==="/"?"":U.pattern}`;M.push({route:{...U,pattern:ue},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 L=new Map,E=null,_=null;if(r.stxOptions?.shell!==!1){if(_=await Ei(u,r.stxOptions?.shell),_){if(E=await js(_,r.stxOptions||{}),E)console.log(`${e.blue}Using app shell: ${e.bright}${Q.relative(u,_)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}wt(),await St(u);let B=xt();if(B.length>0)console.log(`${e.blue}Loaded ${e.bright}${B.length}${e.blue} middleware: ${e.dim}${B.join(", ")}${e.reset}`);let q={},J=null;try{let{loadStxConfig:P}=await import("./chunk-7tp1j22e.js"),F=await P(u);if(F?.apiRouter)J=F?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(F?.apiRoutes){q=F.apiRoutes;let z=Object.keys(q).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(F?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:U}=await import("./chunk-j0v970k3.js"),ue=F.broadcasting;await z(ue);let je=ue.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${je}/ws${e.reset}`);let Ue=Q.join(process.cwd(),"channels.ts");if(pe.existsSync(Ue))try{let Y=await U(Ue);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(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let be=c(u,"output");pe.mkdirSync(be,{recursive:!0});let ce=new Map,Re=new Set,Z=async(P)=>{let F=Qr(T,P);if(!F)return null;try{let z=await Bun.build({entrypoints:[F],outdir:be,plugins:[nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...r.stxOptions});if(!z.success)return null;let U=z.outputs.find((ue)=>ue.path.endsWith(".html"));if(!U)return null;return await Bun.file(U.path).text()}catch{return null}},N=new Map,I=async(P,F)=>{try{let{processDirectives:z,extractVariables:U,defaultConfig:ue,loadStxConfig:je,injectRouterScript:Ue}=await import("./chunk-7tp1j22e.js"),{checkCache:Y,cacheTemplate:G,readFileCached:W,templateCache:K}=await import("./chunk-jsqh5fyn.js"),he=await je(u),We=(ee)=>{if(!ee)return ee;if(Q.isAbsolute(ee))return ee;return Q.resolve(u,ee)},A={...ue,...he,...r.stxOptions,autoShell:!0};if(r.debugDirectives)A.debug=!0;A.partialsDir=We(A.partialsDir),A.componentsDir=We(A.componentsDir),A.layoutsDir=We(A.layoutsDir),A.storesDir=We(A.storesDir||"stores"),A.cachePath=We(A.cachePath)??c(u,"cache");let le=!F&&!r.profile,ne=A.cache!==!1;if(ne&&le){let ee=K.get(P.filePath);if(ee)try{if((await pe.promises.stat(P.filePath)).mtime.getTime()<=ee.mtime){let _e=!0;for(let ve of ee.dependencies){if(!pe.existsSync(ve)){_e=!1;break}if((await pe.promises.stat(ve)).mtime.getTime()>ee.mtime){_e=!1;break}}if(_e){let ve=ee.output;if(E)ve=He(ve,{preserveHead:!0});let ot=N.get(P.filePath);return{route:P,content:ve,status:ot?.status??await ln(P.filePath),headers:ot?.headers}}}}catch{}let De=await Y(P.filePath,A);if(De){let Me=De;if(E)Me=He(Me,{preserveHead:!0});let _e=N.get(P.filePath);return{route:P,content:Me,status:_e?.status??await ln(P.filePath),headers:_e?.headers}}}let ie=ne?await W(P.filePath):await Bun.file(P.filePath).text(),xe=cn(ie),{classifyAllScripts:X}=await import("./chunk-7tp1j22e.js"),Ae=X(ie),Be=Ae.server.map((ee)=>ee.content),oe=ie;for(let ee of Ae.server)oe=oe.replace(ee.fullTag,"");let se={__filename:P.filePath,__dirname:Q.dirname(P.filePath),__stx_options:A,params:F??{},__stx_runtime_head:{}};for(let ee of Be)try{await U(ee,se,P.filePath)}catch(De){if(r.stxOptions?.debug)console.error("[stx] variable extraction error",P.filePath,De?.message||De)}let ze=new Set,Pe;if(r.profile){let ee=performance.now();Pe=await z(oe,se,P.filePath,A,ze);let De=performance.now()-ee,Me=Q.relative(u,P.filePath)||P.filePath;console.log(`[stx:profile] ${Me} \u2192 ${De.toFixed(2)}ms`)}else Pe=await z(oe,se,P.filePath,A,ze);if(!E)Pe=await Ue(Pe,{router:A.router});{let{interpolateScriptExpressions:ee}=await import("./chunk-zshhn7nz.js");Pe=Pe.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(De,Me,_e)=>{if(!/function\s+__stx_setup_/.test(_e))return De;return`<script${Me}>${ee(_e,se)}</script>`})}if(E)Pe=He(Pe,{preserveHead:!0});if(ne&&le)await G(P.filePath,Pe,ze,A);let{extractStreamBoundaries:Hn}=await import("./chunk-5hqrw558.js"),Qe=Hn(se),rt=se.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let ee=se.streamBoundaries||{},De={...A,autoShell:!1},Me=Object.keys(rt).map((ve)=>({id:ve,render:async()=>{let ot=typeof ee[ve]==="function"?await ee[ve]():void 0;return z(rt[ve],{...se,$boundary:ot},P.filePath,De,new Set)}})),_e=new Set(Me.map((ve)=>ve.id));Qe=[...(Qe||[]).filter((ve)=>!_e.has(ve.id)),...Me]}if(Qe&&Qe.length>0)Re.add(P.pattern);else Qe=void 0;let Ut=Rt(se),Wt=At(se);if(le)N.set(P.filePath,{status:Ut,headers:Wt});return{route:P,content:Pe,status:Ut??xe,headers:Wt,boundaries:Qe}}catch(z){return console.error(`${e.red}Error building ${e.bright}${P.pattern}${e.reset}:`,z),null}},Ie=8,Fe=async()=>{ce.clear(),L.clear();for(let P=0;P<k.length;P+=Ie){let F=k.slice(P,P+Ie),z=await Promise.all(F.map((U)=>I(U)));for(let U of z)if(U)ce.set(U.route.pattern,U)}for(let P=0;P<M.length;P+=Ie){let F=M.slice(P,P+Ie),z=await Promise.all(F.map(({route:U})=>I(U)));for(let U of z)if(U)L.set(U.route.pattern,U)}return ce.size>0};if(console.log(`${e.blue}Building pages...${e.reset}`),!await Fe())return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await en(u);let Ge=i;try{if(Ge=await Ve(i),Ge!==i)console.log(`${e.yellow}Port ${i} is busy, using port ${Ge} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(a){let P=r.hmrPort||Ge+1;l=Tt({wsPort:P,verbose:!1}),f=l.start(P)}let Pt=(P,F)=>{let U=`<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(P.includes("</head>"))return P.replace("</head>",`${U}</head>`);if(P.includes("<body"))return P.replace(/<body([^>]*)>/,`<body$1>${U}`);return U+P};console.log(`${e.blue}Starting server...${e.reset}`);let Ot=Ur({port:Ge,async fetch(P){let F=new URL(P.url),z=m?.publicDir||"public",U=Q.join(u,z,F.pathname),ue=Q.join(u,F.pathname),je=Q.join(be,F.pathname);if([U,ue,je].some((A)=>w(A,u,S)))return new Response("Not Found",{status:404});let[Ue,Y,G]=await Promise.all([pe.promises.stat(U).catch(()=>null),pe.promises.stat(ue).catch(()=>null),pe.promises.stat(je).catch(()=>null)]);if(Ue?.isFile()&&!w(U,u,S))return Ft(U);if(Y?.isFile()&&!w(ue,u,S))return Ft(ue);if(G?.isFile()&&!w(je,u,S))return Ft(je);if(F.pathname.startsWith("/_stx/component/")){let A=decodeURIComponent(F.pathname.slice(16));if(A)try{let le=`<${A} />`,ne={...buildConfig,autoShell:!1},ie=await processDirectives(le,{},Q.join(u,"components",`${A}.stx`),ne,new Set);return new Response(ie,{headers:{"Content-Type":"text/html"}})}catch(le){return new Response(`<div class="stx-async-error">${le.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(F.pathname==="/_stx/img"){let{handleImageRequest:A}=await import("./chunk-5zgrvj4b.js"),le=await A(P,{publicDir:Q.join(u,z),cacheDir:c(u,"cache","img")});if(le)return le}if(J)try{let A=await J.handleRequest(P);if(A.status!==404)return A}catch{}if(q[F.pathname])try{return await q[F.pathname](P)}catch(A){return new Response(JSON.stringify({error:A.message}),{status:500,headers:{"Content-Type":"application/json"}})}let W=await C(P);if(W)return W;let K=Zn(F.pathname,k);if(K){let A=ce.get(K.route.pattern),le=Re.has(K.route.pattern);if(K.route.isDynamic&&Object.keys(K.params).length>0||le){let ne=await I(K.route,K.params);if(ne)A=ne}if(A){let ne=A.status??200,ie=A.headers??{},xe=(K.route.filePath?gt(await Bun.file(K.route.filePath).text().catch(()=>"")):null)??{};if(xe.validate){if(!await xe.validate({params:K.params})){let Be=await Z(404);if(Be){let oe=Be;if(oe=await h(oe,u),a)oe=Ne(oe,f);return new Response(oe,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(xe.middleware){let Ae=kt(F.pathname,K.params,xe,F.search),Be=_t(Ae,null,P,{isServer:!0}),oe=await Ct(xe.middleware,Be);if(oe.redirect){let se=oe.redirect.path,ze=oe.redirect.options.redirectCode||302,Pe=new Headers(oe.responseHeaders);return Pe.set("Location",se),new Response(null,{status:ze,headers:Pe})}if(oe.abort){let{statusCode:se,message:ze}=oe.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${se}</title></head><body><h1>Error ${se}</h1><p>${ze}</p></body></html>`,{status:se,headers:{"Content-Type":"text/html"}})}if(Object.keys(oe.state).length>0){let se=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(oe.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;A.content=A.content.replace("</head>",`${se}</head>`)}}let X=A.content;if(E&&Ti(P)){let Ae=Je(X),Be=ge(X),oe=X.match(/<title[^>]*>([\s\S]*?)<\/title>/i),se=oe?Ci(oe[1].trim()):"";if(Object.keys(K.params).length>0)X=Pt(X,K.params);X=await h(X,u);let ze=m?.router?.container||"main";return X=ke(X,ze),new Response(X,{status:ne,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Ae.layout,"X-STX-Layout-Group":Ae.group,"X-STX-Runtime":Be?"true":"false",...se&&{"X-STX-Title":encodeURIComponent(se)},[ta]:Ys(),...O(),"Cache-Control":ut}})}if(E)X=$r(E,X);if(Object.keys(K.params).length>0)X=Pt(X,K.params);if(X=await h(X,u),a)X=Ne(X,f);if(r.native)if(X.includes("<head>"))X=X.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else X="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+X;if(r.titlebarHidden)if(X.includes("<head>"))X=X.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else X=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${X}`;if(A.boundaries&&A.boundaries.length>0){let{renderStreamingPage:Ae,streamToResponse:Be}=await import("./chunk-5hqrw558.js");return Be(Ae(X,A.boundaries,{timeoutMs:30000}),{status:ne,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(X,{status:ne,headers:{"Content-Type":"text/html",...O(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...ie}})}}if(M.length>0){let A=M.map((ne)=>ne.route),le=Zn(F.pathname,A);if(le){let ne=L.get(le.route.pattern);if(ne){let ie=ne.content;if(E)ie=$r(E,ie);if(Object.keys(le.params).length>0)ie=Pt(ie,le.params);if(ie=await h(ie,u),a)ie=Ne(ie,f);return new Response(ie,{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 j)if(ne!=="/"&&F.pathname.startsWith(ne)){let ie=L.get(ne)||L.get(ne+"/");if(ie){let xe=ie.content;if(E)xe=$r(E,xe);if(xe=await h(xe,u),a)xe=Ne(xe,f);return new Response(xe,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(vt(F.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let he=ce.get("/");if(he){let A=he.content;if(A=await h(A,u),a)A=Ne(A,f);if(r.native)if(A.includes("<head>"))A=A.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else A="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+A;return new Response(A,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let We=await Z(404);if(We){let A=We;if(A=await h(A,u),a)A=Ne(A,f);return new Response(A,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(P){let F=await Z(500);if(F)return new Response(F,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${P}
|
|
1430
1430
|
${P.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:${Ge}/${e.reset}`),a)console.log(`${e.dim} HMR: ws://localhost:${f}${e.reset}`);console.log(`
|
|
1433
1433
|
${e.yellow}Routes:${e.reset}`);let Dt=[...es(k,u)];for(let{route:P}of M)Dt.push(`${P.pattern}`);if(Dt.forEach((P,F)=>{let U=F===Dt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${U}${e.reset}${P}`)}),console.log(`
|
|
1434
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(Ot.url.toString(),()=>{if(l)st();Ot.stop()}),r.native){let P,F=Q.join(T,"index.stx");if(pe.existsSync(F)){let U=await Bun.file(F).text();P=mt(U)}let z=m?.app?.window??{};await Ze(Ge,{title:m?.app?.head?.title||Q.basename(u)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??r.titlebarHidden===!0,nativeSidebar:!!P,sidebarConfig:P})}if(p){console.log(`${e.blue}Watching for changes...${e.reset}`);let P=(Y)=>Y.startsWith("public/")||Y.startsWith("public\\"),F=(Y)=>{let G=Y.toLowerCase();return G.endsWith(".stx")||G.endsWith(".html")||G.endsWith(".md")},z=new Map,U=()=>{let Y=new Set([u,...m._layerGraph?.layers.map((G)=>G.root)??[],...m._layerGraph?.configDependencies.map((G)=>Q.dirname(G))??[]].filter((G)=>pe.existsSync(G)).map((G)=>pe.realpathSync(G)));for(let G of m._layerGraph?.layers??[])for(let W of Object.values(G.resources)){if(!pe.existsSync(W))continue;let K=pe.realpathSync(W);if(![...Y].some((he)=>K===he||K.startsWith(`${he}${Q.sep}`)))Y.add(K)}for(let[G,W]of z)if(!Y.has(G))W.close(),z.delete(G);for(let G of Y)if(!z.has(G)&&pe.existsSync(G))z.set(G,pe.watch(G,{recursive:!0},(W,K)=>{je(G,W,K).catch((he)=>console.error("[stx] Layer rebuild failed:",he))}))},ue=Promise.resolve(),je=(Y,G,W)=>(ue=ue.catch(()=>{}).then(()=>Ue(Y,G,W)),ue),Ue=async(Y,G,W)=>{if(!W||bt(W))return;if(yt(W)){if(m._layerGraph){let K=await y(u);Object.assign(m,K),k.splice(0,k.length,...V(v,{pagesDir:x,pagesDirs:K._layerPageDirs?[T,...K._layerPageDirs.slice(1)]:void 0})),U()}if(P(W)){if(console.log(`${e.cyan}${W} changed${e.reset}`),a&&l)l.reload(W)}else if(F(W)){console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),qe.clear(),de();try{let{invalidateFileCache:K,templateCache:he}=await import("./chunk-
|
|
1434
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ke(Ot.url.toString(),()=>{if(l)st();Ot.stop()}),r.native){let P,F=Q.join(T,"index.stx");if(pe.existsSync(F)){let U=await Bun.file(F).text();P=mt(U)}let z=m?.app?.window??{};await Ze(Ge,{title:m?.app?.head?.title||Q.basename(u)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??r.titlebarHidden===!0,nativeSidebar:!!P,sidebarConfig:P})}if(p){console.log(`${e.blue}Watching for changes...${e.reset}`);let P=(Y)=>Y.startsWith("public/")||Y.startsWith("public\\"),F=(Y)=>{let G=Y.toLowerCase();return G.endsWith(".stx")||G.endsWith(".html")||G.endsWith(".md")},z=new Map,U=()=>{let Y=new Set([u,...m._layerGraph?.layers.map((G)=>G.root)??[],...m._layerGraph?.configDependencies.map((G)=>Q.dirname(G))??[]].filter((G)=>pe.existsSync(G)).map((G)=>pe.realpathSync(G)));for(let G of m._layerGraph?.layers??[])for(let W of Object.values(G.resources)){if(!pe.existsSync(W))continue;let K=pe.realpathSync(W);if(![...Y].some((he)=>K===he||K.startsWith(`${he}${Q.sep}`)))Y.add(K)}for(let[G,W]of z)if(!Y.has(G))W.close(),z.delete(G);for(let G of Y)if(!z.has(G)&&pe.existsSync(G))z.set(G,pe.watch(G,{recursive:!0},(W,K)=>{je(G,W,K).catch((he)=>console.error("[stx] Layer rebuild failed:",he))}))},ue=Promise.resolve(),je=(Y,G,W)=>(ue=ue.catch(()=>{}).then(()=>Ue(Y,G,W)),ue),Ue=async(Y,G,W)=>{if(!W||bt(W))return;if(yt(W)){if(m._layerGraph){let K=await y(u);Object.assign(m,K),k.splice(0,k.length,...V(v,{pagesDir:x,pagesDirs:K._layerPageDirs?[T,...K._layerPageDirs.slice(1)]:void 0})),U()}if(P(W)){if(console.log(`${e.cyan}${W} changed${e.reset}`),a&&l)l.reload(W)}else if(F(W)){console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),qe.clear(),de();try{let{invalidateFileCache:K,templateCache:he}=await import("./chunk-jsqh5fyn.js");K(Q.resolve(Y,W)),he.delete(Q.resolve(Y,W))}catch{}if(_&&W){if(Q.resolve(Y,W)===_||Q.basename(_)===W){let he=await js(_,r.stxOptions||{});if(he)E=he}}if(await Fe(),await Wn(u),a&&l)l.reload(W)}else{console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),qe.clear(),de();try{let{invalidateFileCache:K,templateCache:he}=await import("./chunk-jsqh5fyn.js");K(Q.resolve(Y,W)),he.delete(Q.resolve(Y,W))}catch{}if(await Fe(),a&&l)l.reload(W)}}else if(ht(W)){if(console.log(`${e.cyan}CSS ${W} changed${e.reset}`),a&&l)l.updateCss(W)}};U(),process.on("SIGINT",()=>{for(let Y of z.values())Y.close();if(l)st();Ot.stop(),process.exit(0)})}return!0}import zt from"fs";import it from"path";async function Wr(t){try{let i=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!i)return[];let p=i[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 Vr(t){try{let r=await Bun.file(t).text(),i=r.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||r.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(i)return i[1].split(`
|
|
1436
1436
|
`).map((p)=>p.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Kr(t,r=!1,i){let p=it.basename(t,".stx"),a=await Wr(t),l=await Vr(t),f="";if(r&&i)f=`<${i}></${i}>`;else{let u=a.map((y)=>{if(y.type==="boolean")return`:${y.name}="true"`;return`${y.name}="value"`}).join(`
|
|
1437
1437
|
`);f=`<${p}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Zt,Gs,Ks,Xs,sp,Js}from"./chunk-
|
|
2
|
+
import{Zt,Gs,Ks,Xs,sp,Js}from"./chunk-03wssg2z.js";import"./chunk-04kg16qs.js";import"./chunk-365vg0eg.js";import"./chunk-1sr6c0nk.js";export{Ks as buildServerApi,sp as createServerApi,Zt as discoverServerApi,Gs as generateApiTypes,Js as isServerApiSource,Xs as productionApiDispatcher};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{x}from"./chunk-pxdww4rb.js";import{ye,$t,Co,Eo,Ra,Aa,Pa,Ia,ls,$o,Oa,Na,Da,un}from"./chunk-
|
|
2
|
+
import{x}from"./chunk-pxdww4rb.js";import{ye,$t,Co,Eo,Ra,Aa,Pa,Ia,ls,$o,Oa,Na,Da,un}from"./chunk-p23sz4rr.js";import{o}from"./chunk-nytb5e4v.js";import{zs}from"./chunk-679tc0c4.js";import{c}from"./chunk-zhf01af3.js";import{existsSync as M,readFileSync as K}from"fs";import h from"path";var ge=new Set(["module","exports","require","$bool","$num","window","document","console","confirm","alert","fetch"]),ee=un.filter((e)=>!ge.has(e)).sort(),te=[...x].sort(),me=[...new Set([...ee,...te])].sort(),he=new Set(ee),be=new Set(te),xe=new Set(me),Y=/\bimport\s+(?!type[\s{])\{([^}]*)\}\s*from\s*(['"])stx\2/g;function Se(e,t){if(t==="server")return`'${e}' is not provided by 'stx' in a <script server> block. The engine binds only its own names there (defineProps, state, useHead, ...); any other name becomes \`await import('stx')\`, which does not resolve, so the whole script fails when the page renders. Import it from '@stacksjs/stx' instead.`;return`'${e}' is not provided by 'stx' in a client <script> block. The import is replaced by the window.stx runtime, which has no '${e}', so it is undefined in the browser.`}function ne(e,t){let s=[];for(let u of t){if(u.offset===void 0)continue;let i=u.kind==="server"?he:be;Y.lastIndex=0;for(let l of u.code.matchAll(Y)){let g=l.index+l[0].indexOf("{")+1;for(let m of l[1].matchAll(/[^,]+/g)){let S=m[0];if(/^\s*type\s/.test(S))continue;let y=/^\s*([A-Za-z_$][\w$]*)/.exec(S);if(!y)continue;let r=y[1];if(!xe.has(r)||i.has(r))continue;let f=u.offset+g+m.index+y[0].length-r.length,p=e.slice(0,f),w=p.split(`
|
|
3
3
|
`).length;s.push({line:w,column:f-(p.lastIndexOf(`
|
|
4
4
|
`)+1)+1,offset:f,length:r.length,name:r,kind:u.kind,message:Se(r,u.kind)})}}}return s}import T from"path";var ke="@stacksjs/stx-typescript-plugin";function we(e,t){let s=T.resolve(e);for(;;){let u=T.join(s,"tsconfig.json");if(t(u))return u;let i=T.dirname(s);if(i===s)return;s=i}}function ie(e,t,s){let u=we(e,s);if(!u)return;let i=new Set,l=(g)=>{if(i.has(g))return;i.add(g);let m=t(g);if(!m)return;let S=m.compilerOptions?.plugins;if(Array.isArray(S)){let r=S.find((p)=>p?.name===ke),f=Array.isArray(r?.libs)?r.libs.filter((p)=>typeof p==="string"):[];return r?{configPath:g,libs:f.map((p)=>T.resolve(T.dirname(g),p))}:null}let y=typeof m.extends==="string"?[m.extends]:Array.isArray(m.extends)?m.extends:[];for(let r of[...y].reverse()){if(typeof r!=="string"||!r.startsWith("."))continue;let f=T.resolve(T.dirname(g),r.endsWith(".json")?r:`${r}.json`),p=l(f);if(p!==void 0)return p}return};return l(u)??void 0}function Pc(e,t="",s=""){let u=e.startLine>1?`
|
|
5
5
|
`.repeat(e.startLine-1):"",i=$o(e)+Eo(Co(e.code)),l=e.kind==="client"||e.kind==="plain"?Pa(t,e.code):"";return ls(`${u+i}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Ku}from"./chunk-
|
|
2
|
+
import{Ku}from"./chunk-43r0hjne.js";import"./chunk-nytb5e4v.js";import"./chunk-nt7jxmpy.js";import"./chunk-a3d0g4mr.js";import"./chunk-04kg16qs.js";import"./chunk-fzqj1mjz.js";import"./chunk-365vg0eg.js";import"./chunk-p23sz4rr.js";import"./chunk-144yp2bw.js";import"./chunk-1sr6c0nk.js";import"./chunk-2dp7hyv7.js";import"./chunk-ce6zddpf.js";import"./chunk-pxdww4rb.js";export{Ku as buildApp};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{ae,Ma,ds,ln,g,Oe,Ne}from"./chunk-
|
|
2
|
+
import{ae,Ma,ds,ln,g,Oe,Ne}from"./chunk-p23sz4rr.js";import{Yn,Xe,N}from"./chunk-nytb5e4v.js";import{Hn,s}from"./chunk-ken0q08p.js";import{me}from"./chunk-ea7ekakt.js";function b(o){return o.endsWith(".md")||o.endsWith(".markdown")}function C(o){let e=[];m(/<pre\b[^>]*>[\s\S]*?<\/pre>/gi);let r=[...e];m(/<code\b[^>]*>[\s\S]*?<\/code>/gi,r);function m(n,p){let u;while((u=n.exec(o))!==null){let t=u.index,i=t+u[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((n,p)=>n.start-p.start);let a="",c=0;for(let n of e){if(n.start<c)continue;a+=o.slice(c,n.start),a+=`@raw${o.slice(n.start,n.end)}@endraw`,c=n.end}return a+=o.slice(c),a}async function R(o,e={}){let{data:r,content:m}=Yn(o),c=await(e.renderer??((n)=>Xe(n)))(m);return{html:C(c),frontmatter:r??{}}}import{dirname as k,resolve as _}from"path";function v(o){let e=o,r=ae(o);if(r)e=r.content.trim();let m=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,a=[],c=[],n=[],p=(i)=>/\b(?:state|derived|effect|batch)\s*(?:<[^<>()]*>)?\s*\(/.test(i),u;while((u=m.exec(o))!==null){let i=u[1],l=u[2],d=u[0],f=i.includes("server");if(p(l))n.push(d);else if(f)c.push(l);else a.push(d)}let t=e;{let i=/<script\b(?![^>]*\b(?:client|type\s*=\s*["']module["']|src\s*=))[^>]*>/gi,l,d=[];while((l=i.exec(t))!==null){let f=l.index+l[0].length,w=t.indexOf("</script>",f);if(w===-1)continue;d.push({start:l.index,end:w+9}),i.lastIndex=w+9}for(let f=d.length-1;f>=0;f--)t=t.substring(0,d[f].start)+t.substring(d[f].end)}for(let i of a)t=t.replace(i,"");return{templateContent:t,serverScripts:c,clientScripts:a,signalsScripts:n}}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=Oe(p),d=await Promise.all(c.map(async(y)=>{let h=y.match(/<script\b[^>]*>([\s\S]*?)<\/script>/);if(!h)return y;return await Ne(h[1],{eventBindings:i,templateContent:t,serverData:l,filePath:e})})),w=[await Hn(d,{...n,buildMode:"compile"}),...d].filter(Boolean).join(`
|
|
15
15
|
`);if(t.match(/(<\/body>)/i))t=t.replace(/(<\/body>)/i,`${w}
|
|
16
16
|
$1`);else t+=`
|
|
17
|
-
${w}`}t=await me(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
|
+
${w}`}t=await me(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-0q0tpmr5.js");t=await i(t)}catch{}return t}
|
|
18
18
|
export{Ki};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Ye}from"./chunk-365vg0eg.js";import{ft,On}from"./chunk-3y41efsf.js";import{Ie,cn,Xa,Ja}from"./chunk-
|
|
2
|
+
import{Ye}from"./chunk-365vg0eg.js";import{ft,On}from"./chunk-3y41efsf.js";import{Ie,cn,Xa,Ja}from"./chunk-p23sz4rr.js";import{pr,fr,gr,hr,xe}from"./chunk-2dp7hyv7.js";import{A}from"./chunk-1sr6c0nk.js";import{jo}from"./chunk-144yp2bw.js";import{h}from"./chunk-ztp2rgpp.js";import{s}from"./chunk-ken0q08p.js";import{N,o}from"./chunk-nytb5e4v.js";import{wa}from"./chunk-04kg16qs.js";import{He,ke,$i,Ri,kn}from"./chunk-jf1vs526.js";import{Zt,Ks}from"./chunk-03wssg2z.js";import{_n}from"./chunk-vqc4h16r.js";import{qt,jn,Bn}from"./chunk-xaa36b0x.js";import{V}from"./chunk-ea7ekakt.js";import m from"fs";import c from"path";import{createHash as Q}from"crypto";function W(i){return Q("sha256").update(i).digest("hex").slice(0,8)}function J(i=!1){let l=i?On():ft(),a=W(l);return{content:l,filename:`runtime.${a}.js`,hash:a}}function U(){let i=Ye(),l=W(i);return{content:i,filename:`router.${l}.js`,hash:l}}import q from"path";import{createHash as ee}from"crypto";function te(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=ee("sha256").update(e).digest("hex").slice(0,16);Xa();let _={};try{_=await o(a.configDir)}catch{}let y=[],d=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,f;while((f=d.exec(e))!==null){let R=f[1];if(/\bserver\b/.test(R))y.push(f[2])}let u=new Set(y.flatMap((R)=>Ie(R))),{context:D}=te({__filename:r,__dirname:q.dirname(r),__stx_serverDeclared:u}),w=new Set,j={...N,..._,...a,buildMode:"compile",strict:!1},b=await s(e,D,r,j,w),C=He(b),P=Ja();return{route:l,sourceFile:i,html:b,fragment:C,placeholders:P,hasServerScripts:y.length>0,serverScriptContent:y,dependencies:Array.from(w),contentHash:S,status:cn(e),streamTemplates:D.__streamTemplates}}var re=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(re.has(d.name))continue;let f=c.join(S,d.name),u=c.join(_,d.name);if(d.isDirectory())m.mkdirSync(u,{recursive:!0}),e(f,u);else if(d.isFile()){if(m.existsSync(u))continue;m.copyFileSync(f,u),a++,r+=m.statSync(u).size}}}return e(i,l),{copied:a,bytes:r}}async function Mu(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",f=xe(e.app?.head,{known:hr,source:"app.head"}),u=e.app?.colorMode,D=e.router?.container||"main",w=i.routeRules??e.routeRules??{},j=_n(w),b=i.serverApi??e.serverApi,C=typeof b==="object"?b:{};if(b)Zt(a,C);if(e.runtimeConfig)A(e.runtimeConfig,{});if(m.existsSync(r))m.rmSync(r,{recursive:!0});let P=[c.join(r,"public","__stx"),c.join(r,"public","assets"),c.join(r,"server","pages"),c.join(r,"server","fragments")];for(let n of P)m.mkdirSync(n,{recursive:!0});console.log("[stx build] Discovering routes...");let R=V(a,{pagesDirs:e._layerPageDirs}),Y=["components","layouts","partials"],B=R.filter((n)=>!Y.some((g)=>n.pattern.startsWith(`/${g}/`)||n.pattern===`/${g}`));console.log(`[stx build] Found ${B.length} page routes (${R.length-B.length} non-page files excluded)`),console.log("[stx build] Generating shared assets...");let v=J(i.debug),x=U();await Bun.write(c.join(r,"public","__stx",v.filename),v.content),await Bun.write(c.join(r,"public","__stx",x.filename),x.content),console.log(`[stx build] Runtime: ${v.filename} (${(v.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 M=[],k=[];for(let n of B){let g=j(n.pattern),O=g.rendering==="prerender";if(O&&(n.pattern.includes(":")||n.pattern.includes("[")))throw Error(`Cannot prerender parameter route ${n.pattern}; use dynamic rendering (explicit path enumeration is not supported here)`);try{let t=await X(n.filePath,n.pattern,{configDir:a,componentsDir:S,partialsDir:_,layoutsDir:y,debug:i.debug});if(M.push(t),t.html=t.html.replace(/runtime\.__STX_HASH__\.js/g,v.filename).replace(/router\.__STX_HASH__\.js/g,x.filename),t.html=gr(t.html,f,{bodyScripts:[`<script src="/__stx/${x.filename}"></script>`],...u&&{colorMode:u}}),u)t.html=pr(t.html,u);if(f.htmlAttrs)t.html=fr(t.html,f.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 I=p[1];t.html=t.html.replace(" "+I,""),t.html=t.html.replace(/<body([^>]*)>/,`<body$1 ${I}>`)}}if(t.html=t.html.replace(/<style data-css="generated">[\s\S]*?<\/style>\s*/g,""),t.html=await h(t.html),O){let p=await kn(t,{params:{},request:new Request(`http://stx.build${n.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 ${n.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=ke(t.html,D);let L=n.pattern==="/"?"index":n.pattern.slice(1).replace(/\//g,"-").replace(/[[\]]/g,"_"),z=c.join("server","pages",`${L}.compiled.json`),G=c.join("server","fragments",`${L}.html`);await Bun.write(c.join(r,z),JSON.stringify(t,null,2)),await Bun.write(c.join(r,G),t.fragment),k.push({pattern:n.pattern,compiledPath:z,fragmentPath:G,isDynamic:t.hasServerScripts,hasParams:n.pattern.includes(":")||n.pattern.includes("["),prerendered:O}),console.log(`[stx build] \u2713 ${n.pattern}`)}catch(t){if(Object.keys(g).length)throw t;console.error(`[stx build] \u2717 ${n.pattern}:`,t instanceof Error?t.message:t)}}let E=c.resolve(a,d);if(m.existsSync(E)){let{copied:n,bytes:g}=Z(E,c.join(r,"public"));if(n>0)console.log(`[stx build] Copied ${n} public asset${n===1?"":"s"} (${(g/1024).toFixed(1)}KB) from ${d}/`)}let H=Bn(a);if(H){let{copied:n,bytes:g}=Z(H,c.join(r,"public",jn));if(n>0)console.log(`[stx build] Copied ${n} asset${n===1?"":"s"} (${(g/1024).toFixed(1)}KB) from ${qt}/`)}let F={runtime:v.filename,router:x.filename},T=$i(k,F,r);if(T.routeRules=w,T.routerContainer=D,b)T.apiRoutes=await Ks(a,r,C);if(e.runtimeConfig)await Bun.write(c.join(r,"server/runtime-config.json"),JSON.stringify(e.runtimeConfig)),await jo(a,e.runtimeConfig);if(e._layerGraph)await Bun.write(c.join(r,"server/layers.json"),JSON.stringify(wa(e._layerGraph),null,2));Ri(T,r);let K=Date.now()-l;return console.log(`
|
|
3
3
|
[stx build] Done in ${K}ms \u2014 ${M.length} pages compiled`),{pageCount:M.length,assets:F,outputDir:r,duration:K}}
|
|
4
4
|
export{Mu};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{o}from"./chunk-
|
|
2
|
+
import{o}from"./chunk-nytb5e4v.js";import{Ve,Q}from"./chunk-yfvm7q6t.js";import{Ki}from"./chunk-d2zzqfgq.js";import{f}from"./chunk-b7e07ybq.js";import{existsSync as A,mkdirSync as x,copyFileSync as T,chmodSync as P,rmSync as ue}from"fs";import{join as c,basename as be,resolve as H}from"path";import{spawn as q}from"child_process";import{platform as ge}from"os";var Xd=`
|
|
3
3
|
<script>
|
|
4
4
|
(function() {
|
|
5
5
|
'use strict';
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Qn}from"./chunk-365vg0eg.js";import{dr}from"./chunk-2dp7hyv7.js";import{o}from"./chunk-
|
|
2
|
+
import{Qn}from"./chunk-365vg0eg.js";import{dr}from"./chunk-2dp7hyv7.js";import{o}from"./chunk-nytb5e4v.js";import{U,Ge}from"./chunk-bnn7pd62.js";import{la}from"./chunk-g8r0km7g.js";var p=/<style\b[^>]*>/iy,x=/<\/style>/gi,R=/<script\b[^>]*>/iy,b=/<template(?=[\s>/])[^>]*>/iy,S=/<\/template\s*>/iy;function Gn(e){let r=0,t=0,s=-1;while(r<e.length){let n=e.indexOf("<",r);if(n===-1)return-1;if(e.startsWith("<!--",n)){let d=e.indexOf("-->",n+4);r=d===-1?e.length:d+3;continue}p.lastIndex=n;let u=p.exec(e);if(u){x.lastIndex=n+u[0].length;let d=x.exec(e);r=d===null?e.length:d.index+8;continue}b.lastIndex=n;let c=b.exec(e);if(c){if(t===0)s=n;t++,r=n+c[0].length;continue}S.lastIndex=n;let a=S.exec(e);if(a){if(t>0)t--;r=n+a[0].length;continue}if(R.lastIndex=n,R.test(e))return t>0?s:n;r=n+1}return-1}function V(e,r={}){return new Qn(e,r).routes}import w from"path";var T=new Map;async function y(e,r){let t=e,s=r;if(!t||!s)try{let a=await o();t||=a?.pagesDir||"pages",s||=a?.root||"."}catch{t||="pages",s||="."}let n=w.isAbsolute(t)?t:w.join(s,t),u=T.get(n);if(u)return u;let c=[];try{c=V(".",{pagesDir:n,emit:!1}).map((a)=>a.regex.source).filter(Boolean)}catch{c=[]}return T.set(n,c),c}function O(e){return e.replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function l(e){return O(JSON.stringify(e))}function ge(e){return e.includes("data-stx-runtime")}function aa(e){let r=/window\.stx\s*\.\s*[A-Za-z_$]|\}\s*=\s*window\.stx\s*;/g;for(let t=r.exec(e);t!==null;t=r.exec(e)){let s=e.slice(Math.max(0,t.index-80),t.index);if(/if\s*\(\s*window\.stx\s*\)|window\.stx\s*&&/.test(s))continue;return!0}return!1}function f(e,r){let t=Gn(e),s=e.search(/<!doctype\b/i);if(t!==-1&&(s===-1||t>s))return e.slice(0,t)+r+`
|
|
3
3
|
`+e.slice(t);let n=dr(e);if(n!==null)return`${e.slice(0,n)}
|
|
4
4
|
${r}${e.slice(n)}`;if(e.includes("</head>")){let c=e.indexOf("</head>");return e.slice(0,c)+r+`
|
|
5
5
|
`+e.slice(c)}if(U(e))return Ge(e,(c)=>`${c}
|
|
6
6
|
${r}`);return`${r}
|
|
7
|
-
${e}`}async function Kn(e,r){if(e.includes("data-stx-runtime")||e.includes("window.stx.state")||e.includes("STX Signals Runtime"))return e;if(r.buildMode==="serve"){let{getServeClientAsset:n}=await import("./chunk-
|
|
7
|
+
${e}`}async function Kn(e,r){if(e.includes("data-stx-runtime")||e.includes("window.stx.state")||e.includes("STX Signals Runtime"))return e;if(r.buildMode==="serve"){let{getServeClientAsset:n}=await import("./chunk-jsqh5fyn.js"),{url:u}=await n("runtime",r.debug===!0);return f(e,`<script data-stx-runtime src="${u}"></script>`)}if(r.buildMode==="compile")return f(e,'<script data-stx-runtime src="/__stx/runtime.__STX_HASH__.js"></script>');let{getCachedSignalsRuntime:t}=await import("./chunk-jsqh5fyn.js"),s=await t(r.debug);return f(e,`<script data-stx-scoped data-stx-runtime>${s}</script>`)}function m(e){return/<[a-z][^>]*?\sx-tooltip\s*=/i.test(e)}function ca(e){if(e.includes("data-stx-tooltip-runtime")||!m(e))return e;let r=`<script data-stx-scoped data-stx-tooltip-runtime>${la()}</script>`,t=e.lastIndexOf("</body>");if(t===-1)return`${e}
|
|
8
8
|
${r}`;return`${e.slice(0,t)}${r}
|
|
9
|
-
${e.slice(t)}`}var E=/<script\b[^>]*\sdata-stx-router(?=[\s=>])/i;function C(e){return E.test(e)||e.includes("__stxRouter)return")||e.includes("__stxRouter=true")}async function me(e,r){if(!e.includes("</body>"))return e;if(C(e))return e;let t=r?.router,s="",n="";{let i={};if(t){if(t.container)i.container=t.container;if(t.interceptAllLinks!==void 0)i.interceptAllLinks=t.interceptAllLinks;if(t.progress!==void 0)i.progress=t.progress;if(t.viewTransitions!==void 0)i.viewTransitions=t.viewTransitions;if(t.viewTransitionDuration!==void 0)i.viewTransitionDuration=t.viewTransitionDuration;if(t.viewTransitionEasing!==void 0)i.viewTransitionEasing=t.viewTransitionEasing;if(t.scrollToTop!==void 0)i.scrollToTop=t.scrollToTop;if(t.scrollRestoration!==void 0)i.scrollRestoration=t.scrollRestoration;if(t.prefetch!==void 0)i.prefetch=t.prefetch;if(t.cache!==void 0)i.cache=t.cache;if(t.progressColor!==void 0)i.progressColor=t.progressColor;if(t.progressHeight!==void 0)i.progressHeight=t.progressHeight;if(t.prefetchVisible!==void 0)i.prefetchVisible=t.prefetchVisible;if(t.prefetchVisibleMax!==void 0)i.prefetchVisibleMax=t.prefetchVisibleMax;if(t.keepOpening!==void 0)i.keepOpening=t.keepOpening}try{let g=await y(r?.pagesDir,r?.root);if(g.length>0)if(r?.buildMode==="serve"){let{registerServeModuleBundle:h}=await import("./chunk-
|
|
9
|
+
${e.slice(t)}`}var E=/<script\b[^>]*\sdata-stx-router(?=[\s=>])/i;function C(e){return E.test(e)||e.includes("__stxRouter)return")||e.includes("__stxRouter=true")}async function me(e,r){if(!e.includes("</body>"))return e;if(C(e))return e;let t=r?.router,s="",n="";{let i={};if(t){if(t.container)i.container=t.container;if(t.interceptAllLinks!==void 0)i.interceptAllLinks=t.interceptAllLinks;if(t.progress!==void 0)i.progress=t.progress;if(t.viewTransitions!==void 0)i.viewTransitions=t.viewTransitions;if(t.viewTransitionDuration!==void 0)i.viewTransitionDuration=t.viewTransitionDuration;if(t.viewTransitionEasing!==void 0)i.viewTransitionEasing=t.viewTransitionEasing;if(t.scrollToTop!==void 0)i.scrollToTop=t.scrollToTop;if(t.scrollRestoration!==void 0)i.scrollRestoration=t.scrollRestoration;if(t.prefetch!==void 0)i.prefetch=t.prefetch;if(t.cache!==void 0)i.cache=t.cache;if(t.progressColor!==void 0)i.progressColor=t.progressColor;if(t.progressHeight!==void 0)i.progressHeight=t.progressHeight;if(t.prefetchVisible!==void 0)i.prefetchVisible=t.prefetchVisible;if(t.prefetchVisibleMax!==void 0)i.prefetchVisibleMax=t.prefetchVisibleMax;if(t.keepOpening!==void 0)i.keepOpening=t.keepOpening}try{let g=await y(r?.pagesDir,r?.root);if(g.length>0)if(r?.buildMode==="serve"){let{registerServeModuleBundle:h}=await import("./chunk-jsqh5fyn.js");n=`<script data-stx-owned-routes src="${h(`(window.__stxRouterConfig=window.__stxRouterConfig||{}).ownedRoutes=${l(g)};
|
|
10
10
|
`)}"></script>
|
|
11
11
|
`}else i.ownedRoutes=g}catch{}if(Object.keys(i).length>0)s=`<script>window.__stxRouterConfig=${l(i)};</script>
|
|
12
|
-
`}let{getCachedRouterScript:u,getServeClientAsset:c}=await import("./chunk-
|
|
12
|
+
`}let{getCachedRouterScript:u,getServeClientAsset:c}=await import("./chunk-jsqh5fyn.js"),a=r?.buildMode==="compile"?'<script data-stx-router src="/__stx/router.__STX_HASH__.js"></script>':r?.buildMode==="serve"?`<script data-stx-router src="${(await c("router")).url}"></script>`:`<script data-stx-router>${await u()}</script>`,d=e.lastIndexOf("</body>");return e.slice(0,d)+s+n+a+`
|
|
13
13
|
</body>`+e.slice(d+7)}
|
|
14
14
|
export{Gn,V,ge,aa,Kn,ca,me};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{g,m,d}from"./chunk-
|
|
2
|
+
import{g,m,d}from"./chunk-p23sz4rr.js";import{N}from"./chunk-nytb5e4v.js";import{s}from"./chunk-ken0q08p.js";import k from"path";var q={enabled:!0,bufferSize:16384,strategy:"auto",timeout:30000},T=/<!-- @section:([\w-]+) -->([\s\S]*?)<!-- @endsection:\1 -->/g;var M=/<!-- @suspense:([\w-]+) -->([\s\S]*?)<!-- @endsuspense:\1 -->/g;function H(e){let t=[],o=0,n;M.lastIndex=0;while((n=M.exec(e))!==null){if(n.index>o){let a=e.slice(o,n.index);if(a.trim())t.push({type:t.length===0?"shell":"content",content:a})}let r=n[1],i=n[2];t.push({type:"suspense",name:r,content:i}),o=n.index+n[0].length}if(o<e.length){let r=e.slice(o);if(r.trim())t.push({type:t.length===0?"shell":"content",content:r})}if(t.length===0)t.push({type:"shell",content:e});return t}async function rd(e,t={},o={}){let n={...N,...o,streaming:{...q,...o.streaming}},r=n.streaming?.bufferSize||16384;return new ReadableStream({async start(i){try{let a=await Bun.file(e).text(),S=a.match(/<script\b[^>]*\bserver\b[^>]*>([\s\S]*?)<\/script>/i),f=S?S[1]:"",c=a.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,""),h={...t,__filename:e,__dirname:k.dirname(e)};if(f.trim())await g(f,h,e);let E=H(c),u=new Set;if(!E.some((w)=>w.type==="suspense")){let w=n.streaming?.strategy||"auto",x=new RegExp(T.source,"g");if(!(w!=="manual"&&x.test(c))){let p=await s(c,h,e,n,u);for(let b=0;b<p.length;b+=r)i.enqueue(p.slice(b,b+r)),await new Promise((y)=>setTimeout(y,0))}else{let p=[],b=new RegExp(T.source,"g"),y;while((y=b.exec(c))!==null)p.push({name:y[1],content:y[2],start:y.index,end:y.index+y[0].length});let v=0;for(let _ of p){if(_.start>v){let I=c.slice(v,_.start);if(I.trim()){let O=await s(I,h,e,n,u);i.enqueue(O),await new Promise((D)=>setTimeout(D,0))}}let C=await s(_.content,h,e,n,u);i.enqueue(C),await new Promise((I)=>setTimeout(I,0)),v=_.end}if(v<c.length){let _=c.slice(v);if(_.trim()){let C=await s(_,h,e,n,u);i.enqueue(C)}}}}else{let w=new Map;for(let l of E)if(l.type==="shell"||l.type==="content"){let p=await s(l.content,h,e,n,u);i.enqueue(p)}else if(l.type==="suspense"&&l.name){let p=`stx-suspense-${l.name}`;i.enqueue(`<div id="${p}" data-suspense="${l.name}" style="display:contents;">
|
|
3
3
|
<template data-suspense-fallback>Loading...</template>
|
|
4
4
|
</div>`),w.set(l.name,s(l.content,h,e,n,u))}i.enqueue(`
|
|
5
5
|
<script>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Qs,eo,to,dp,jr,pp}from"./chunk-
|
|
2
|
+
import{Qs,eo,to,dp,jr,pp}from"./chunk-nx6d1hj7.js";export{jr as clearImageDeliveryCatalog,dp as deliveredImage,to as efficientDeliverySources,Qs as getImageDelivery,eo as isTransparentImage,pp as prepareImageDelivery};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{lp,Sl,qe,sa,up,Dr,Mr,Lr}from"./chunk-
|
|
2
|
+
import{lp,Sl,qe,sa,up,Dr,Mr,Lr}from"./chunk-1mz8fw0m.js";import"./chunk-nx6d1hj7.js";import"./chunk-ka8befem.js";import"./chunk-p472crv1.js";import"./chunk-p23sz4rr.js";import"./chunk-144yp2bw.js";import"./chunk-1sr6c0nk.js";import"./chunk-2dp7hyv7.js";import"./chunk-ce6zddpf.js";import"./chunk-pxdww4rb.js";export{up as clearOnceStore,sa as onceStore,qe as partialsCache,Dr as processIncludes,Mr as processStackPushDirectives,Lr as processStackReplacements,lp as resetUnscopedSignalWarnings,Sl as topLevelElements};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{p,u}from"./chunk-2dp7hyv7.js";import{be,ue,d}from"./chunk-
|
|
2
|
+
import{p,u}from"./chunk-2dp7hyv7.js";import{be,ue,d}from"./chunk-p23sz4rr.js";function z(t,o){let i=1,r=o,e="<template",n="</template";while(r<t.length&&i>0){let s=t.indexOf("<",r);if(s===-1)break;if(r=s,t.startsWith(e,r)&&(r+e.length>=t.length||/[\s>\/]/.test(t[r+e.length]))){i++,r+=e.length;continue}if(t.startsWith(n,r)){let a=t.indexOf(">",r+n.length);if(a!==-1){if(i--,i===0)return a+1;r=a+1;continue}}r++}return i===0?r:-1}var N=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function k(t,o){let i=null;for(let r=o;r<t.length;r++){let e=t[r];if(i){if(e==="\\"){r++;continue}if(e===i)i=null;continue}if(e==='"'||e==="'"){i=e;continue}if(e===">")return r+1}return-1}function B(t,o,i){let r=o.toLowerCase(),e=1,n=i;while(n<t.length){let s=t.indexOf("<",n);if(s===-1)return-1;if(t.startsWith("<!--",s)){let g=t.indexOf("-->",s+4);n=g===-1?t.length:g+3;continue}let a=k(t,s+1);if(a===-1)return-1;let f=t.slice(s,a),c=f.match(/^<\s*(\/?)\s*([a-zA-Z][\w-]*)/);if(c&&c[2].toLowerCase()===r){if(c[1]==="/"){if(e--,e===0)return a}else if(!/\/\s*>$/.test(f))e++}n=a}return-1}function Z(t){let o=[],i=[],r=/\bslot\s*=\s*(?:"([^"]+)"|'([^']+)')/i,e=0;while(e<t.length){let n=t.indexOf("<",e);if(n===-1)break;if(t.startsWith("<!--",n)){let l=t.indexOf("-->",n+4);e=l===-1?t.length:l+3;continue}let s=k(t,n+1);if(s===-1)break;let a=t.slice(n,s),f=a.match(/^<\s*(\/?)\s*([a-zA-Z][\w-]*)/);if(!f){e=s;continue}let c=f[2].toLowerCase();if(f[1]==="/"){let l=i.lastIndexOf(c);if(l!==-1)i.splice(l);e=s;continue}let g=/\/\s*>$/.test(a),m=i.length===0?a.match(r):null;if(m){let l=m[1]||m[2],h=a.replace(r,"").replace(/\s+(?=\/?>$)/,"").replace(/\s{2,}/g," "),S=g||N.has(c)?-1:B(t,c,s);if(S===-1)o.push({start:n,end:s,slotName:l,element:h}),e=s;else o.push({start:n,end:S,slotName:l,element:h+t.slice(s,S)}),e=S;continue}if(!g&&!N.has(c)){if(i.push(c),c==="script"||c==="style"){let l=t.toLowerCase().indexOf(`</${c}>`,s);if(l!==-1){e=l;continue}}}e=s}return o}function L(t){let o=[],i=[],r=/^<template\s+(?:#([a-zA-Z][\w-]*)|v-slot:([a-zA-Z][\w-]*)|slot="([a-zA-Z][\w-]*)")(?:\s*=\s*"([^"]*)")?[^>]*>$/i,e=0;while(e<t.length){let n=t.indexOf("<",e);if(n===-1)break;if(t.startsWith("<!--",n)){let l=t.indexOf("-->",n+4);e=l===-1?t.length:l+3;continue}let s=k(t,n+1);if(s===-1)break;let a=t.slice(n,s),f=a.match(/^<\s*(\/?)\s*([a-zA-Z][\w-]*)/);if(!f){e=s;continue}let c=f[1]==="/",g=f[2].toLowerCase();if(c){let l=i.lastIndexOf(g);if(l!==-1)i.splice(l);e=s;continue}if(g==="template"&&i.length===0){let l=a.match(r);if(l){let h=z(t,s);if(h!==-1){let S=l[1]||l[2]||l[3];o.push({start:n,end:h,slotName:S,content:t.slice(s,h-11).trim(),propsBinding:l[4]||void 0}),e=h;continue}}}if(!/\/\s*>$/.test(a)&&!N.has(g)){if(i.push(g),g==="script"||g==="style"){let l=t.toLowerCase().indexOf(`</${g}>`,s);if(l!==-1){e=l;continue}}}e=s}return o}function Lc(t){let o={default:"",named:new Map},i=t,r=L(t);for(let n of r)o.named.set(n.slotName,{name:n.slotName,content:n.content,propsBinding:n.propsBinding});r.sort((n,s)=>s.start-n.start);for(let n of r)i=i.slice(0,n.start)+i.slice(n.end);let e=Z(i);for(let n of e){let s=o.named.get(n.slotName);if(s)s.content+=n.element;else o.named.set(n.slotName,{name:n.slotName,content:n.element})}for(let n=e.length-1;n>=0;n--){let s=e[n];i=i.slice(0,s.start)+i.slice(s.end)}return o.default=i.trim(),o}function Ju(t){let o=t.match(/name\s*=\s*["']([^"']+)["']/),i=o?o[1]:"",r={},e=/:([a-zA-Z][\w-]*)\s*=\s*["']([^"']+)["']/g,n;while((n=e.exec(t))!==null)r[n[1]]=n[2];let s=t.match(/<slot[^>]*>([\s\S]*?)<\/slot>/i),a=s?s[1].trim():"";return{name:i,props:r,defaultContent:a}}async function jc(t,o,i,r){if(!t)return i;let e=t.content;if(t.propsBinding&&Object.keys(o).length>0){let n=t.propsBinding.trim(),s={...r},a=new Set,f=new Set;if(n.startsWith("{")&&n.endsWith("}")){let c=n.slice(1,-1).split(",").map((g)=>g.trim()).filter(Boolean);for(let g of c){let[m,l]=g.split(":").map((S)=>S.trim()),h=l||m;if(s[h]=o[m],o[m]!==void 0)f.add(h);else a.add(h)}}else if(s[n]=o,Object.values(o).some((c)=>c===void 0))a.add(n);else f.add(n);e=j(e,s,a,f)}return e}function j(t,o,i,r){return t.replace(/\{\{\s*([^}]+)\s*\}\}/g,(e,n)=>{try{let s=n.trim();if(ue(s,i))return e;if(Array.isArray(o.__stx_preserved_client_expressions)&&o.__stx_preserved_client_expressions.includes(s)&&!ue(s,r))return e;let a=_(s,o);if(a===void 0)return e;return d(String(a??""))}catch{return`{{ ${n} }}`}})}function _(t,o){if(/^[a-zA-Z_$][\w$]*(\.[a-zA-Z_$][\w$]*)*$/.test(t)){let r=t.split("."),e=o;for(let n of r)if(e&&typeof e==="object"&&n in e)e=e[n];else return;return e}let i=t.match(/^([a-zA-Z_$][\w$]*)\s*([+\-*/])\s*(\d+)$/);if(i){let[,r,e,n]=i,s=o[r],a=parseInt(n,10);if(typeof s==="number")switch(e){case"+":return s+a;case"-":return s-a;case"*":return s*a;case"/":return s/a}}try{if(!p(t))return;return u(t,Object.keys(o))(...Object.values(o))}catch{return}}async function Bc(t,o,i,r){let e=t;e=await I(e,/<slot\s+name\s*=\s*["']([^"']+)["']([^>]*?)(?:\/>|>([\s\S]*?)<\/slot>)/gi,async(a,f,c,g)=>{let m=o.named.get(f),l=g?.trim()||"",h=c||"",S={},E=[],C=/:([a-zA-Z_$][\w$-]*)\s*=\s*["']([^"']+)["']/g,b;while((b=C.exec(h))!==null){let w=b[1],x=b[2];S[w]=_(x,i),E.push([w,x])}if(r!==void 0&&m?.propsBinding&&Object.values(S).some((w)=>w===void 0)){let w=m.propsBinding.trim(),x=be(`${w} in []`),y="__stx_slot_props";while(x.includes(y))y+="_";let M=E.map(([A,P])=>{let O=S[A],R;try{R=O===void 0?void 0:JSON.stringify(O)}catch{}return`${JSON.stringify(A)}:(${R??P})`}).join(","),v=d(JSON.stringify({binding:w,names:x,owner:r}));return`<template :for="${d(`${y} in [{${M}}]`)}" data-stx-slot-binding="${encodeURIComponent(w)}" data-stx-slot-scope="${v}">${m.content}</template>`}return await jc(m,S,l,i)});let s=/<slot\b((?:"[^"]*"|'[^']*'|[^>"'])*?)\s*(?:\/>|>([\s\S]*?)<\/slot>)/gi;return e=e.replace(s,(a,f,c)=>{if(/\bname\s*=/.test(f||""))return a;let g=c?.trim()||"";return o.default||g}),e}async function I(t,o,i){let r=[],e=[];t.replace(o,(a,...f)=>{let c=f[f.length-2];return e.push({match:a,index:c}),r.push(i(a,...f.slice(0,-2))),a});let n=await Promise.all(r),s=t;for(let a=e.length-1;a>=0;a--){let{match:f,index:c}=e[a];s=s.slice(0,c)+n[a]+s.slice(c+f.length)}return s}function Yu(t){let o=Lc(t);return{defaultSlot:o.default,namedSlots:o.named}}async function Zu(t,o,i,r,e){return await Bc(t,{default:o,named:i},r,e)}
|
|
3
3
|
export{Lc,Ju,jc,Bc,Yu,Zu};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-2dp7hyv7.js";import"./chunk-pxdww4rb.js";import"./chunk-ce6zddpf.js";import"./chunk-
|
|
2
|
+
import"./chunk-2dp7hyv7.js";import"./chunk-pxdww4rb.js";import"./chunk-ce6zddpf.js";import"./chunk-p23sz4rr.js";import"./chunk-1sr6c0nk.js";import"./chunk-144yp2bw.js";import"./chunk-a3d0g4mr.js";import"./chunk-nt7jxmpy.js";import{c}from"./chunk-zhf01af3.js";import u from"fs";import l from"path";async function d(e,t={}){let s=Date.now(),n={total:0,passed:0,failed:0,new:0,failures:[],duration:0},i=t.snapshotDir||c(e.root,"story","snapshots");await u.promises.mkdir(i,{recursive:!0});let r=e.storyFiles;if(t.filter&&t.filter.length>0)r=r.filter((a)=>t.filter.some((o)=>a.fileName.toLowerCase().includes(o.toLowerCase())));for(let a of r)await h(a,i,t,n);return n.duration=Date.now()-s,n}async function h(e,t,s,n){let i=e.story;if(!i)return;for(let r of i.variants){n.total++;let a=l.join(t,`${e.id}-${r.id}.snap`),o=g(r.source||""),f=await w(a);if(s.update||!f){let p={storyId:e.id,variantId:r.id,component:e.fileName,timestamp:Date.now(),hash:o};if(await u.promises.writeFile(a,JSON.stringify(p,null,2)),!f)n.new++;n.passed++}else try{let p=await u.promises.readFile(a,"utf-8"),m=JSON.parse(p);if(m.hash===o)n.passed++;else n.failed++,n.failures.push({storyId:e.id,variantId:r.id,component:e.fileName,message:"Snapshot mismatch",difference:y(m.hash,o)})}catch(p){n.failed++,n.failures.push({storyId:e.id,variantId:r.id,component:e.fileName,message:`Error reading snapshot: ${p}`})}}}async function x(e,t={}){return(await d(e,{...t,update:!0})).total}function g(e){let t=0;for(let s=0;s<e.length;s++){let n=e.charCodeAt(s);t=(t<<5)-t+n,t=t&t}return t.toString(16)}function y(e,t){if(e===t)return 0;let s=Math.abs(Number.parseInt(e,16)-Number.parseInt(t,16));return Math.min(s/1e6,1)}async function w(e){try{return await u.promises.access(e),!0}catch{return!1}}function F(e){let t=[];if(t.push(""),t.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"),t.push(" STX Story Visual Regression Tests"),t.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"),t.push(""),e.failures.length>0){t.push(" \u274C Failures:"),t.push("");for(let s of e.failures){if(t.push(` \u2022 ${s.component} / ${s.variantId}`),t.push(` ${s.message}`),s.difference!==void 0)t.push(` Difference: ${(s.difference*100).toFixed(2)}%`);t.push("")}}if(t.push(" Summary:"),t.push(` Total: ${e.total}`),t.push(` Passed: ${e.passed} \u2713`),t.push(` Failed: ${e.failed} \u2717`),e.new>0)t.push(` New: ${e.new} \u26A1`);return t.push(` Time: ${e.duration}ms`),t.push(""),t.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"),t.push(""),t.join(`
|
|
3
3
|
`)}export{F as formatTestResults,d as runVisualTests,x as updateSnapshots};
|