@stacksjs/stx 0.2.720 → 0.2.722
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/README.md +6 -0
- package/dist/{chunk-e13vngat.js → chunk-04pzzhn7.js} +1 -1
- package/dist/{chunk-gwq82dpy.js → chunk-1z0zmgsj.js} +4 -4
- package/dist/{chunk-6h0n7h97.js → chunk-2d31hmtc.js} +2 -2
- package/dist/{chunk-nb65s3b5.js → chunk-2dm1kn1w.js} +4 -4
- package/dist/{chunk-a82dg51h.js → chunk-3hsw0s60.js} +1 -1
- package/dist/chunk-3mqxasmr.js +2 -0
- package/dist/{chunk-zc116ep8.js → chunk-48v2mdxa.js} +1 -1
- package/dist/{chunk-2f3zw2wy.js → chunk-4haedk3v.js} +1 -1
- package/dist/chunk-52ysrkex.js +2 -0
- package/dist/{chunk-9vx6et01.js → chunk-6tf24hs3.js} +1 -1
- package/dist/{chunk-pz837t6v.js → chunk-6vd1tw4p.js} +1 -1
- package/dist/chunk-82hhwy20.js +2 -0
- package/dist/{chunk-qvwwpnyk.js → chunk-99ke9sz0.js} +3 -3
- package/dist/{chunk-0ktg5dw9.js → chunk-9gdz941b.js} +1 -1
- package/dist/chunk-a0ab1h7m.js +2 -0
- package/dist/{chunk-2gg3apz0.js → chunk-aj2mxp6q.js} +1 -1
- package/dist/{chunk-9v16zd8h.js → chunk-atz8z223.js} +1 -1
- package/dist/{chunk-jh8b3f9w.js → chunk-b4xavv78.js} +1 -1
- package/dist/{chunk-kn92y5yd.js → chunk-bdsp619m.js} +2 -2
- package/dist/{chunk-rfb00eqz.js → chunk-brwcbz1z.js} +5 -5
- package/dist/{chunk-11k6atcw.js → chunk-cr8kksjp.js} +1 -1
- package/dist/{chunk-ejp4d8cq.js → chunk-e8tyr2mk.js} +1 -1
- package/dist/{chunk-rm9rmyh2.js → chunk-eebn36ws.js} +1 -1
- package/dist/{chunk-dffe3vx2.js → chunk-ewen9p1d.js} +1 -1
- package/dist/{chunk-1xt84h16.js → chunk-f168pjxz.js} +1 -1
- package/dist/{chunk-m7hbk341.js → chunk-fxtqbtey.js} +1 -1
- package/dist/{chunk-jtf6sxgd.js → chunk-g6r1vft1.js} +1 -1
- package/dist/{chunk-43anje0a.js → chunk-ghf5pc18.js} +1 -1
- package/dist/{chunk-2rj4t9wz.js → chunk-gq58xt9y.js} +1 -1
- package/dist/{chunk-ve78svbr.js → chunk-gz5w84nz.js} +1 -1
- package/dist/{chunk-hp957nrn.js → chunk-h0mh5gec.js} +2 -2
- package/dist/{chunk-y0bepgyh.js → chunk-hh3ss945.js} +1 -1
- package/dist/chunk-hrjzd135.js +2 -0
- package/dist/{chunk-5rjfaj0b.js → chunk-kdp20nnt.js} +2 -2
- package/dist/{chunk-04xtzbf6.js → chunk-ke2t93w6.js} +1 -1
- package/dist/{chunk-pqrgaahp.js → chunk-m3qb17ad.js} +3 -3
- package/dist/{chunk-0wfbhs15.js → chunk-madkha56.js} +1 -1
- package/dist/{chunk-8csv4s4f.js → chunk-mj04jc44.js} +3 -3
- package/dist/{chunk-57ecpsqy.js → chunk-ncq1bzwh.js} +1 -1
- package/dist/{chunk-n0bw2kzs.js → chunk-p3n4z56e.js} +1 -1
- package/dist/{chunk-8deed4r2.js → chunk-p8z3fmz8.js} +1 -1
- package/dist/{chunk-5bm0nh5f.js → chunk-pcpt0661.js} +2 -2
- package/dist/{chunk-znknf1jt.js → chunk-pv9vw6y3.js} +101 -101
- package/dist/{chunk-hpg5bjzb.js → chunk-pxg67s3v.js} +1 -1
- package/dist/chunk-qbp5ne23.js +2 -0
- package/dist/{chunk-ty5rncss.js → chunk-r0cnxng9.js} +1 -1
- package/dist/{chunk-r1t5dcsn.js → chunk-t06tskeq.js} +1 -1
- package/dist/{chunk-kxp881ch.js → chunk-tef5t0b2.js} +1 -1
- package/dist/{chunk-0azq3w1a.js → chunk-v7gqjf44.js} +50 -50
- package/dist/{chunk-kbw75yd7.js → chunk-v7pzn7md.js} +1 -1
- package/dist/chunk-vejmjcmj.js +3 -0
- package/dist/{chunk-hsqqhjhr.js → chunk-vz9r5f1r.js} +1 -1
- package/dist/{chunk-b8a8900p.js → chunk-wd71x3xf.js} +1 -1
- package/dist/{chunk-xvkqa756.js → chunk-wf3sjfvb.js} +1 -1
- package/dist/chunk-x7yb70j1.js +2 -0
- package/dist/{chunk-009y9zkg.js → chunk-xb63rsr1.js} +1 -1
- package/dist/{chunk-bpds7e9v.js → chunk-xyy9shta.js} +1 -1
- package/dist/{chunk-pcsgj3a5.js → chunk-y43xak2g.js} +1 -1
- package/dist/chunk-y7hfh69h.js +2 -0
- package/dist/chunk-y9335aa8.js +2 -0
- package/dist/{chunk-xhpf68p4.js → chunk-ypvt1sy9.js} +1 -1
- package/dist/{chunk-mhpek1hj.js → chunk-yqrckcv0.js} +1 -1
- package/dist/chunk-zgkwpsyj.js +2 -0
- package/dist/cli.js +7 -7
- package/dist/component-library.js +12 -7
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/misc-directives.js +7 -3
- package/dist/native-backend.d.ts +1 -0
- package/dist/native-backend.js +16 -1
- package/dist/native-build.js +2 -2
- package/dist/pwa.js +1 -1
- package/dist/ssg.js +2 -2
- package/package.json +5 -5
- package/dist/chunk-2sjvj2gb.js +0 -2
- package/dist/chunk-4m1zv168.js +0 -2
- package/dist/chunk-5awvckb2.js +0 -2
- package/dist/chunk-5dvb2e8f.js +0 -2
- package/dist/chunk-6r1wzzt3.js +0 -2
- package/dist/chunk-ddxrb5zk.js +0 -2
- package/dist/chunk-g9vag1n2.js +0 -2
- package/dist/chunk-hgrtnyp3.js +0 -2
- package/dist/chunk-jy8m3dah.js +0 -3
- package/dist/chunk-sey2x612.js +0 -2
- package/dist/chunk-y7b9kqz8.js +0 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{oe,de,pn,Pt,It,m,r,fe,p}from"./chunk-
|
|
2
|
+
import{oe,de,pn,Pt,It,m,r,fe,p}from"./chunk-v7gqjf44.js";import{mt,Re,za,Jr,wo,xo,i}from"./chunk-brwcbz1z.js";import{ae,xr,Se,B,wn}from"./chunk-zkx2m308.js";import{wt,lr,hs,ys,bs,xt,St,kt,_t,Ct,Et,Ze}from"./chunk-2mqzpzy7.js";import{ls,a,P}from"./chunk-kdp20nnt.js";import{dt,Tn,_e,M,Ki,to,Br,Ue,Gi,Ce}from"./chunk-mj04jc44.js";import{ir,ar}from"./chunk-p8z3fmz8.js";import{Cn}from"./chunk-pxg67s3v.js";import{e,sn,tr,y}from"./chunk-2d31hmtc.js";import{Ge}from"./chunk-2dm1kn1w.js";import{$e}from"./chunk-1xjv71dw.js";import{G,ye,be}from"./chunk-1z0zmgsj.js";import{l}from"./chunk-qc93ce5h.js";import{K}from"./chunk-xaddgvkx.js";async function zn(t){try{let n=await Bun.file(t).text(),o=Nn(n),d=Un(n,t),s=Wn(n,o),c=Vn(n,o);return{file:t,metrics:o,issues:d,suggestions:s,performance:c}}catch(n){throw Error(`Failed to analyze template ${t}: ${n instanceof Error?n.message:String(n)}`)}}function Nn(t){let n=t.split(`
|
|
3
3
|
`),o=t.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),s=(o?o[1]:"").split(`
|
|
4
|
-
`).length,c={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};c.total=c.conditionals+c.loops+c.includes+c.custom;let
|
|
5
|
-
`).filter((
|
|
4
|
+
`).length,c={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};c.total=c.conditionals+c.loops+c.includes+c.custom;let u=(t.match(/\{\{[\s\S]*?\}\}/g)||[]).length,f=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length,g=(t.match(/@(?:if|unless|elseif|foreach|for|while)\s*\([^)]+\)/g)||[]).length,h=u+f+g,x=(t.match(/<[A-Z][^>]*>/g)||[]).length,v=(t.match(/@(?:layout|extends)\(/g)||[]).length,S=0,T=0;for(let k of n)if(/@(?:if|unless|foreach|for|while|section)\b/.test(k)&&!/@end/.test(k)&&!/@else/.test(k))T++,S=Math.max(S,T);else if(/@end(?:if|unless|foreach|for|while|section)\b/.test(k))T--;let w=S>=4?3:0,b=Math.min(10,Math.ceil(c.total*0.5+h*0.1+x*0.3+(s>10?s*0.05:0)+w));return{lines:n.length,characters:t.length,directives:c,expressions:h,components:x,layouts:v,scriptLines:s,complexity:b}}function Un(t,n){let o=[],d=Kt(t,"if","endif");if(d>0)o.push({type:"error",category:"syntax",message:`Found ${d} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let s=Kt(t,"foreach","endforeach");if(s>0)o.push({type:"error",category:"syntax",message:`Found ${s} unmatched @foreach directive(s)`,suggestion:"Ensure every @foreach has a corresponding @endforeach"});let c=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(c&&c.length>0)o.push({type:"warning",category:"performance",message:"Nested loops detected which may impact performance",suggestion:"Consider preprocessing data or using more efficient data structures"});let u=(t.match(/\{!![\s\S]*?!!\}/g)||[]).length;if(u>0)o.push({type:"warning",category:"security",message:`Found ${u} raw output expression(s) {!! !!}`,suggestion:"Ensure raw outputs are properly sanitized to prevent XSS"});let f=t.match(/<img[^>]*>/g);if(f){let x=f.filter((v)=>!v.includes("alt="));if(x.length>0)o.push({type:"warning",category:"accessibility",message:`Found ${x.length} image(s) without alt attributes`,suggestion:"Add alt attributes to all images for screen reader accessibility"})}let g=t.split(`
|
|
5
|
+
`).filter((x)=>x.length>120);if(g.length>0)o.push({type:"info",category:"maintainability",message:`Found ${g.length} line(s) longer than 120 characters`,suggestion:"Consider breaking long lines for better readability"});let h=(t.match(/style\s*=\s*["'][^"']*["']/g)||[]).length;if(h>3)o.push({type:"info",category:"maintainability",message:`Found ${h} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return o}function Wn(t,n){let o=[];if(n.complexity>7)o.push({type:"refactor",message:"Template complexity is high. Consider breaking into smaller components.",impact:"high",effort:"medium"});else if(n.complexity>5&&n.directives.total>8)o.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(n.lines>100&&n.components===0)o.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(n.expressions>20)o.push({type:"optimization",message:"Many template expressions detected. Consider preprocessing some data in the script section.",impact:"medium",effort:"low"});let d=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(d&&d.length>0)o.push({type:"optimization",message:"Nested loops detected. Consider preprocessing data or optimizing data structures.",impact:"high",effort:"medium"});if(n.directives.total===0&&n.expressions<5)o.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(n.scriptLines>50)o.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return o}function Vn(t,n){let o=1;if(o+=n.directives.conditionals*0.1,o+=n.directives.loops*0.5,o+=n.directives.includes*2,o+=n.expressions*0.05,o+=n.components*1,n.scriptLines>10)o+=n.scriptLines*0.1;let d;if(n.expressions===0&&n.directives.total===0)d="high";else if(n.expressions<5&&n.directives.total<3)d="medium";else d="low";let s=[];if(o>10)s.push("Consider optimizing template complexity");if(d==="low"&&n.directives.total>5)s.push("Reduce dynamic content for better caching");if(n.components===0&&n.lines>40)s.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(o*100)/100,complexityScore:n.complexity,cacheability:d,recommendations:s}}function Kt(t,n,o){let d=t.replace(/<!--[\s\S]*?-->/g,""),s=(d.match(new RegExp(`@${n}\\b`,"g"))||[]).length,c=(d.match(new RegExp(`@${o}\\b`,"g"))||[]).length;return Math.abs(s-c)}async function Di(t=["**/*.stx"],n){let o=[],d=[];for(let c of t){let u=await Array.fromAsync(new Bun.Glob(c).scan({cwd:n||process.cwd(),onlyFiles:!0,absolute:!0}));d.push(...u.filter((f)=>f.endsWith(".stx")))}for(let c of d)try{let u=await zn(c);o.push(u)}catch(u){console.warn(`Failed to analyze ${c}:`,u)}let s=qn(o);return{results:o,summary:s}}function qn(t){let n=t.length,o=t.reduce((h,x)=>h+x.metrics.lines,0),d=n>0?t.reduce((h,x)=>h+x.metrics.complexity,0)/n:0,s=t.reduce((h,x)=>h+x.issues.length,0),c={};t.forEach((h)=>{h.issues.forEach((x)=>{c[x.category]=(c[x.category]||0)+1})});let u=n>0?t.reduce((h,x)=>h+x.performance.estimatedRenderTime,0)/n:0,f=Math.max(1,Math.min(10,Math.round(10-u/2-d/2))),g=[];if(d>6)g.push("Project has high average complexity. Consider refactoring complex templates.");if(s>n*2)g.push("High number of issues detected. Run detailed analysis on individual files.");if(c.security>0)g.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:n,totalLines:o,avgComplexity:Math.round(d*100)/100,totalIssues:s,issuesByCategory:c,performanceScore:f,recommendations:g}}import{mkdir as Kn,readFile as Xn,readdir as Gn,stat as Xt,writeFile as Jn}from"fs/promises";import Te from"path";function en(t){if(t==="connectedCallback")return`method "${t}" is reserved; define "onConnect" instead, which the element calls once it is connected, rendered and bound`;if(t==="disconnectedCallback")return`method "${t}" is reserved; define "onDisconnect" instead, which the element calls as it leaves the DOM, before it releases its own listeners`;return`method "${t}" is reserved`}var tn=new Set(["constructor","connectedCallback","disconnectedCallback","attributeChangedCallback","adoptedCallback"]);function Yn(t){return t.replace(/\.stx$/i,"").split(/[^a-z0-9]+/i).filter(Boolean).map((n)=>n.charAt(0).toUpperCase()+n.slice(1)).join("")}function jt(t){return t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-z0-9]+/gi,"-").replace(/^-+|-+$/g,"").toLowerCase()}function Qn(t){return/^[a-z][.0-9_a-z-]*-[.0-9_a-z-]*$/.test(t)&&!t.startsWith("xml")&&!/[A-Z]/.test(t)}function Zn(t){if(t===!0)return"open";if(t==="open"||t==="closed")return t;return!1}async function er(t){let n=[];async function o(d){let s=await Gn(d,{withFileTypes:!0});s.sort((c,u)=>c.name.localeCompare(u.name));for(let c of s){let u=Te.join(d,c.name);if(c.isDirectory()){if(!c.name.startsWith(".")&&c.name!=="node_modules")await o(u)}else if(c.isFile()&&c.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(c.name))n.push(u)}}return await o(t),n}function nr(t,n){let o=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!o)return{};let d=o[1].trim();if(!d)return{};try{return JSON.parse(d)}catch(s){throw Error(`${n}: <script component> must contain JSON metadata (${s.message})`)}}function rr(t,n){let o={},d=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let s of d){if(!/\bclient\b/i.test(s[1])||/\bcomponent\b|\bstx:component\b/i.test(s[1]))continue;let c;try{c=new Bun.Transpiler({loader:"ts"}).transformSync(s[2])}catch(g){throw Error(`${n}: failed to transpile <script client> (${g.message})`)}let u=/(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*\{/g,f;while(f=u.exec(c)){let g=f[1];if(tn.has(g))throw Error(`${n}: client ${en(g)}`);let h=u.lastIndex,x=1,v="",S=!1,T=h;for(;T<c.length&&x>0;T++){let b=c[T];if(S){S=!1;continue}if(v){if(b==="\\")S=!0;else if(b===v)v="";continue}if(b==='"'||b==="'"||b==="`")v=b;else if(b==="{")x++;else if(b==="}")x--}if(x!==0)throw Error(`${n}: unterminated client function "${g}"`);let w=f[0].includes("async")?"async ":"";o[g]=`${w}${g}(${f[2]}) {${c.slice(h,T-1)}}`,u.lastIndex=T}}return o}function or(t){let n=t.match(/<template\b(?![^>]*\bshadowrootmode\b)[^>]*>([\s\S]*?)<\/template>/i);return(n?n[1]:t).replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").trim()}function Gt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((n)=>n[1].trim()).filter(Boolean).join(`
|
|
6
6
|
|
|
7
|
-
`)}function sr(t){if(!t)return null;let n=t.replace(/\s*\|\s*(?:undefined|null)\b/g,"").trim();if(/^string$/.test(n))return"string";if(/^number$/.test(n))return"number";if(/^boolean$/.test(n))return"boolean";if(/^(?:'[^']*'|"[^"]*")(?:\s*\|\s*(?:'[^']*'|"[^"]*"))*$/.test(n))return"string";return"object"}function cr(t){if(t===void 0)return"object";if(t==="true"||t==="false")return"boolean";if(/^-?\d+(?:\.\d+)?$/.test(t))return"number";if(/^['"`]/.test(t))return"string";return"object"}function dr(t){if(t==="true")return!0;if(t==="false")return!1;if(/^-?\d+(?:\.\d+)?$/.test(t))return Number(t);if(/^['"`]/.test(t))return t.slice(1,-1);try{return JSON.parse(t)}catch{return}}function pr(t){let n=[],o=0,d=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),s=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,c,
|
|
8
|
-
`)}function ct(t,n,o,d){if(t[n]!==o)return-1;let s=0,c=null;for(let
|
|
7
|
+
`)}function sr(t){if(!t)return null;let n=t.replace(/\s*\|\s*(?:undefined|null)\b/g,"").trim();if(/^string$/.test(n))return"string";if(/^number$/.test(n))return"number";if(/^boolean$/.test(n))return"boolean";if(/^(?:'[^']*'|"[^"]*")(?:\s*\|\s*(?:'[^']*'|"[^"]*"))*$/.test(n))return"string";return"object"}function cr(t){if(t===void 0)return"object";if(t==="true"||t==="false")return"boolean";if(/^-?\d+(?:\.\d+)?$/.test(t))return"number";if(/^['"`]/.test(t))return"string";return"object"}function dr(t){if(t==="true")return!0;if(t==="false")return!1;if(/^-?\d+(?:\.\d+)?$/.test(t))return Number(t);if(/^['"`]/.test(t))return t.slice(1,-1);try{return JSON.parse(t)}catch{return}}function pr(t){let n=[],o=0,d=t.replace(/\{\{--[\s\S]*?--\}\}/g,""),s=/@(if|elseif|else|endif|foreach|endforeach)\s*/g,c,u=(g)=>{if(d[g]!=="(")return null;let h=0,x="";for(let v=g;v<d.length;v++){let S=d[v];if(x!==""){if(S==="\\")v++;else if(S===x)x="";continue}if(S==="'"||S==='"'||S==="`"){x=S;continue}if(S==="(")h++;else if(S===")"){if(h--,h===0)return{expression:d.slice(g+1,v),end:v+1}}}return null},f=(g)=>{if(g==="")return;let h=0,x=/\{!!\s*([\s\S]*?)\s*!!\}|\{\{\s*([\s\S]*?)\s*\}\}/g,v;while(v=x.exec(g)){if(v.index>h)n.push(`out += ${JSON.stringify(g.slice(h,v.index))};`);n.push(v[1]!==void 0?`out += __raw(${v[1]});`:`out += __escape(${v[2]});`),h=v.index+v[0].length}if(h<g.length)n.push(`out += ${JSON.stringify(g.slice(h))};`)};while(c=s.exec(d)){f(d.slice(o,c.index)),o=c.index+c[0].length;let h=c[1]==="if"||c[1]==="elseif"||c[1]==="foreach"?u(o):null;if(h)o=h.end,s.lastIndex=h.end;let x=h?.expression;switch(c[1]){case"if":n.push(`if (${x}) {`);break;case"elseif":n.push(`} else if (${x}) {`);break;case"else":n.push("} else {");break;case"endif":case"endforeach":n.push("}");break;case"foreach":{let v=/^([\s\S]+?)\s+as\s+(?:([A-Za-z_$][\w$]*)\s*=>\s*)?([A-Za-z_$][\w$]*)$/.exec((x||"").trim());if(!v){n.push(`out += ${JSON.stringify(c[0]+(h?`(${x})`:""))};`);break}let[,S,T,w]=v;n.push(T?`for (const [${T}, ${w}] of __entries(${S})) {`:`for (const ${w} of __values(${S})) {`);break}}}return f(d.slice(o)),n.join(`
|
|
8
|
+
`)}function ct(t,n,o,d){if(t[n]!==o)return-1;let s=0,c=null;for(let u=n;u<t.length;u++){let f=t[u];if(c){if(f==="\\"){u++;continue}if(f===c)c=null;continue}if(f==="'"||f==='"'||f==="`"){c=f;continue}if(f===o)s++;else if(f===d){if(d===">"&&t[u-1]==="=")continue;if(s--,s===0)return u+1}}return-1}function Mt(t,n,o){let d=o?"([{<":"([{",s=o?")]}>":")]}",c=[],u=0,f=null,g="";for(let h=0;h<t.length;h++){let x=t[h];if(f){if(g+=x,x==="\\"){g+=t[++h]??"";continue}if(x===f)f=null;continue}if(x==="'"||x==='"'||x==="`"){f=x,g+=x;continue}if(d.includes(x))u++;else if(s.includes(x))u--;if(u===0&&n.includes(x)){c.push(g),g="";continue}g+=x}return c.push(g),c.map((h)=>h.trim()).filter(Boolean)}function ur(t){let n=0,o=null;for(let d=0;d<t.length;d++){let s=t[d];if(o){if(s==="\\"){d++;continue}if(s===o)o=null;continue}if(s==="'"||s==='"'||s==="`"){o=s;continue}if("([{".includes(s))n++;else if(")]}".includes(s))n--;if(n!==0||s!=="=")continue;let c=t[d-1];if(t[d+1]==="="||c==="="||c==="!"||c==="<"||c===">")continue;return d}return-1}function Jt(t){switch(t.trim()){case"String":return"string";case"Number":return"number";case"Boolean":return"boolean";case"Array":return"unknown[]";case"Object":return"Record<string, unknown>";default:return}}function fr(t){let n=/\bdefineProps\b/.exec(t);if(!n)return null;let o=/(?:^|[\s;{}()])(const|let|var)\s+/g,d=-1;for(let E=o.exec(t);E&&E.index<n.index;E=o.exec(t))d=E.index+E[0].indexOf(E[1]);if(d===-1)return null;let s={},c={},u=[],f={},g=d+(/^(?:const|let|var)\s+/.exec(t.slice(d))?.[0].length??0),h=()=>{while(g<t.length&&/\s/.test(t[g]))g++},x;if(t[g]==="{"){let E=ct(t,g,"{","}");if(E===-1)return null;x=t.slice(g,E),g=E}else{let E=/^[A-Za-z_$][\w$]*/.exec(t.slice(g));if(!E)return null;x=E[0],g+=E[0].length}if(h(),t[g]!=="=")return null;g++,h();let v=/^withDefaults\s*\(\s*/.exec(t.slice(g)),S=Boolean(v);if(v)g+=v[0].length;let T=/^defineProps\b/.exec(t.slice(g));if(!T)return null;g+=T[0].length;let w="";if(h(),t[g]==="<"){let E=ct(t,g,"<",">");if(E===-1)return null;w=t.slice(g+1,E-1).trim(),g=E}if(h(),t[g]!=="(")return null;let b=ct(t,g,"(",")");if(b===-1)return null;let k=t.slice(g+1,b-1).trim();if(g=b,S){if(h(),t[g]===",")g++,h();if(t[g]==="{"){let E=ct(t,g,"{","}");if(E===-1)return null;for(let[R,A]of Lt(t.slice(g,E)))c[R]=A;g=E}if(h(),t[g]===",")g++,h();if(t[g]===")")g++}if(t[g]===";")g++;let _=/^[A-Za-z_$][\w$]*$/.test(w)?w:void 0;if(w.startsWith("{"))for(let E of Mt(w.replace(/^\{/,"").replace(/\}$/,""),",;",!0)){let R=/^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(E);if(R)s[R[1]]=R[2].trim()}if(k.startsWith("{"))for(let[E,R]of Lt(k)){if(u.push(E),!R.startsWith("{")){let A=Jt(R);if(A)s[E]=A;continue}for(let[A,C]of Lt(R))if(A==="default")c[E]=C;else if(A==="type"){let D=Jt(C);if(D)s[E]=D}}else if(k.startsWith("["))for(let E of Mt(k.slice(1,-1),",",!1))u.push(E.replace(/^['"`]/,"").replace(/['"`]$/,""));if(x.startsWith("{")){u.length=0;for(let E of Mt(x.replace(/^\{/,"").replace(/\}$/,""),",",!1)){let R=ur(E),A=R===-1?E:E.slice(0,R),C=A.split(":")[0].trim().replace(/^\.\.\./,"");if(!C)continue;if(u.push(C),f[C]=A.trim(),R!==-1)c[C]=E.slice(R+1).trim()}}else if(u.length===0)u.push(...Object.keys(s));return{text:t.slice(d,g),propNames:u,propBindings:f,defaults:c,declared:s,typeName:_}}function Lt(t){let n=t.trim().replace(/^\{/,"").replace(/\}$/,""),o=[],d=0;while(d<n.length){let s=/\s*([A-Za-z_$][\w$]*)\s*:/y;s.lastIndex=d;let c=s.exec(n);if(!c)break;d=s.lastIndex;let u=0,f="",g=d;while(d<n.length){let x=n[d];if(f){if(x==="\\")d++;else if(x===f)f=""}else if(x==="'"||x==='"'||x==="`")f=x;else if(x==="{"||x==="["||x==="(")u++;else if(x==="}"||x==="]"||x===")")u--;else if(x===","&&u===0)break;d++}let h=n.slice(g,d).trim();if(h)o.push([c[1],h]);d++}return o}function mr(t,n,o){let s=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].find((T)=>!/\bcomponent\b|\bstx:component\b|\bclient\b/i.test(T[1]));if(!s)return{imports:[],body:"",propNames:[],propBindings:{},defaults:{},declared:{}};let c=s[2],u=[],f=[],g={},h={},x={};c=c.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm,(T)=>{if(/from\s*['"]stx['"]/.test(T))return"";return u.push(T.trim().replace(/(from\s*['"])(\.[^'"]*)(['"])/,(w,b,k,_)=>{let E=Te.resolve(Te.dirname(n),k),R=Te.relative(o,E);return`${b}${R.startsWith(".")?R:`./${R}`}${_}`})),""});let v=fr(c);if(v)f.push(...v.propNames),Object.assign(g,v.propBindings),Object.assign(h,v.defaults),Object.assign(x,v.declared),c=c.replace(v.text,"");let S={};for(let T of c.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)){let w=[];for(let b of T[2].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))x[b[1]]=b[2].trim(),w.push(b[1]);S[T[1]]=w}if(v&&v.propNames.length===0&&v.typeName){for(let T of S[v.typeName]??[])if(!f.includes(T))f.push(T)}return c=c.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g,""),{imports:u,body:c.trim(),propNames:f,propBindings:g,defaults:h,declared:x}}function gr(t){let n=new Set;return{template:t.replace(/\s@([a-z][\w:-]*)(\.[\w.-]+)?\s*=\s*(["'])([A-Za-z_$][\w$]*)\3/gi,(d,s,c,u,f)=>{let g=s.toLowerCase();n.add(g);let h=(c||"").split(".").filter(Boolean).join(" ");return` data-stx-on-${g}="${f}"${h?` data-stx-mod-${g}="${h}"`:""}`}),eventTypes:[...n].sort()}}function hr(t){let n=[];return{template:t.replace(/\s:([a-z][\w:-]*)\s*=\s*(["'])([\w$.]+)\2/gi,(d,s,c,u)=>{let f=n.length;return n.push({id:f,name:s,expression:u}),` data-stx-bind-${f}=""`}),bindings:n}}function yr(t){let n=new Set;for(let o of t.matchAll(/<slot\b([^>]*)>/gi))n.add(o[1].match(/\bname\s*=\s*["']([^"']+)["']/i)?.[1]||"");return[...n].map((o)=>({name:o}))}function br(t){return[...new Set([...t.matchAll(/(--[a-z0-9_-]+)\s*:/gi)].map((n)=>n[1]))].sort().map((n)=>({name:n}))}function Yt(t,n){if(!n||!new Set(["string","number","boolean","object","array"]).has(n.type))throw Error(`Property "${t}" must declare one of: string, number, boolean, object, array`);return{...n,reflect:n.reflect??n.attribute!==!1}}async function vr(t,n,o){let d=Te.isAbsolute(n.file)?n.file:Te.resolve(t,n.file),s=await Xn(d,"utf8"),c=nr(s,d),u=Te.basename(d,".stx"),f=n.name||c.name||Yn(u),g=`${jt(o.prefix||"stx")}-${jt(u)}`,h=n.tag||c.tag||g;if(!f||!/^[A-Za-z_$][\w$]*$/.test(f))throw Error(`${d}: invalid component class name "${f}"`);if(!Qn(h))throw Error(`${d}: invalid custom-element tag "${h}"; tags must be lowercase and contain a hyphen`);let x=n.properties||c.properties||c.props||{},v=Object.fromEntries(Object.entries(x).map(([R,A])=>[R,Yt(R,A)])),S=gr(or(s)),T=hr(S.template),w=mr(s,d,Te.resolve(o.outputDir)),b=pr(T.template);for(let R of w.propNames){if(v[R])continue;let A=w.defaults[R];v[R]=Yt(R,{type:sr(w.declared[R])??cr(A),...A===void 0?{}:{default:dr(A)}})}let k=c.methods||{},_=n.methods||{},E=rr(s,d);return{file:Te.relative(t,d),sourcePath:d,name:f,tag:h,description:n.description||c.description||"",template:T.template,styles:Gt(s),shadowMode:Zn(n.shadowDOM??c.shadowDOM??o.shadowDOM),progressive:n.progressive??c.progressive??o.progressive??!0,properties:v,events:n.events||c.events||{},methods:{...k,..._,...E},eventTypes:S.eventTypes,bindings:T.bindings,slots:yr(T.template),cssProperties:br(Gt(s)),scope:w,render:b}}function wr(){let t=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),n=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}");return`const HTMLElementBase = globalThis.HTMLElement || class {};
|
|
9
9
|
|
|
10
10
|
const escapeHTML = (value) => String(value ?? '')
|
|
11
11
|
.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>')
|
|
@@ -303,19 +303,19 @@ export function defineComponent(Component, definition) {
|
|
|
303
303
|
}
|
|
304
304
|
return Component;
|
|
305
305
|
}
|
|
306
|
-
`}function Sr(t){let n=JSON.stringify({tag:t.tag,template:t.template,styles:t.styles,shadowMode:t.shadowMode,progressive:t.progressive,properties:t.properties,eventTypes:t.eventTypes,bindings:t.bindings},null,2),o=Object.entries(t.methods).map(([
|
|
307
|
-
${
|
|
306
|
+
`}function Sr(t){let n=JSON.stringify({tag:t.tag,template:t.template,styles:t.styles,shadowMode:t.shadowMode,progressive:t.progressive,properties:t.properties,eventTypes:t.eventTypes,bindings:t.bindings},null,2),o=Object.entries(t.methods).map(([f,g])=>{if(tn.has(f))throw Error(`${t.sourcePath}: ${en(f)}`);if(/^(?:async\s+)?[A-Za-z_$][\w$]*\s*\(/.test(g.trim()))return` ${g.trim()}`;return` ${f}($event) {
|
|
307
|
+
${g}
|
|
308
308
|
}`}).join(`
|
|
309
309
|
|
|
310
|
-
`),d=t.scope,s=[...new Set([...Object.keys(t.properties),...d.propNames])].map((
|
|
311
|
-
`).map((
|
|
312
|
-
`),
|
|
313
|
-
`),
|
|
314
|
-
${
|
|
315
|
-
}`),
|
|
310
|
+
`),d=t.scope,s=[...new Set([...Object.keys(t.properties),...d.propNames])].map((f)=>{let g=d.propBindings[f]||f;return d.defaults[f]===void 0?g:`${g} = ${d.defaults[f]}`}).join(", "),c=(f)=>f.split(`
|
|
311
|
+
`).map((g)=>g.trim()===""?g:` ${g}`).join(`
|
|
312
|
+
`),u="";if(t.render.trim()!==""||d.body!==""||s!==""){let f=[s?`const { ${s} } = this._props();`:"",d.body,"let out = '';",t.render,"return out;"].filter(Boolean).join(`
|
|
313
|
+
`),g;try{let h=new Bun.Transpiler({loader:"ts"}).transformSync(`export function __render(__helpers) {
|
|
314
|
+
${f}
|
|
315
|
+
}`),x=h.indexOf("{"),v=h.lastIndexOf("}");g=h.slice(x+1,v).trim()}catch(h){throw Error(`${t.sourcePath}: failed to compile render (${h.message})`)}u=`
|
|
316
316
|
render(__helpers) {
|
|
317
317
|
const { escape: __escape, raw: __raw, values: __values, entries: __entries } = __helpers;
|
|
318
|
-
${c(
|
|
318
|
+
${c(g.trim())}
|
|
319
319
|
}
|
|
320
320
|
`}return`import { StxElement, defineComponent } from './runtime.js';
|
|
321
321
|
${d.imports.length?`${d.imports.join(`
|
|
@@ -323,14 +323,14 @@ ${d.imports.length?`${d.imports.join(`
|
|
|
323
323
|
`:""}
|
|
324
324
|
/** ${t.description||`${t.name} web component generated from ${t.file}.`} */
|
|
325
325
|
export class ${t.name} extends StxElement {
|
|
326
|
-
${o}${
|
|
326
|
+
${o}${u}
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
defineComponent(${t.name}, ${n});
|
|
330
330
|
export default ${t.name};
|
|
331
|
-
`}function lt(t){switch(t.type){case"boolean":return"boolean";case"number":return"number";case"array":return"unknown[]";case"object":return"Record<string, unknown>";default:return"string"}}function kr(t){let n=Object.entries(t.properties).map(([c,
|
|
332
|
-
`),o=Object.entries(t.properties).map(([c,
|
|
333
|
-
`),d=Object.entries(t.events).map(([c,
|
|
331
|
+
`}function lt(t){switch(t.type){case"boolean":return"boolean";case"number":return"number";case"array":return"unknown[]";case"object":return"Record<string, unknown>";default:return"string"}}function kr(t){let n=Object.entries(t.properties).map(([c,u])=>` ${c}${u.required?"":"?"}: ${lt(u)}`).join(`
|
|
332
|
+
`),o=Object.entries(t.properties).map(([c,u])=>` ${c}: ${lt(u)}`).join(`
|
|
333
|
+
`),d=Object.entries(t.events).map(([c,u])=>` ${JSON.stringify(c)}: CustomEvent<${u.detailType||"unknown"}>`).join(`
|
|
334
334
|
`),s=Object.keys(t.methods).map((c)=>` ${c}($event?: Event): unknown`).join(`
|
|
335
335
|
`);return`export interface ${t.name}Props {
|
|
336
336
|
${n}
|
|
@@ -358,8 +358,8 @@ export default ${t.name}
|
|
|
358
358
|
`}function Tr(t){return`declare global {
|
|
359
359
|
namespace JSX {
|
|
360
360
|
interface IntrinsicElements {
|
|
361
|
-
${t.map((o)=>{let d=Object.entries(o.properties).map(([c,
|
|
362
|
-
`),s=Object.keys(o.events).map((c)=>` ${`on${c.split(/[-:]/).map((
|
|
361
|
+
${t.map((o)=>{let d=Object.entries(o.properties).map(([c,u])=>` ${JSON.stringify(c)}?: ${lt(u)}`).join(`
|
|
362
|
+
`),s=Object.keys(o.events).map((c)=>` ${`on${c.split(/[-:]/).map((f)=>f.charAt(0).toUpperCase()+f.slice(1)).join("")}`}?: (event: CustomEvent<${o.events[c].detailType||"unknown"}>) => void`).join(`
|
|
363
363
|
`);return` ${JSON.stringify(o.tag)}: {
|
|
364
364
|
${d}
|
|
365
365
|
${s}
|
|
@@ -376,7 +376,7 @@ ${s}
|
|
|
376
376
|
export {}
|
|
377
377
|
`}function $r(t){return{schemaVersion:"1.0.0",modules:t.map((n)=>({kind:"javascript-module",path:`./${n.tag}.js`,declarations:[{kind:"class",name:n.name,description:n.description||void 0,customElement:!0,tagName:n.tag,members:Object.entries(n.properties).map(([o,d])=>({kind:"field",name:o,description:d.description,type:{text:lt(d)},default:d.default===void 0?void 0:JSON.stringify(d.default),attribute:d.attribute===!1?void 0:d.attribute||jt(o),reflects:d.reflect})),events:Object.entries(n.events).map(([o,d])=>({name:o,description:d.description,type:{text:`CustomEvent<${d.detailType||"unknown"}>`}})),slots:n.slots,cssProperties:n.cssProperties}],exports:[{kind:"js",name:n.name,declaration:{name:n.name,module:`./${n.tag}.js`}}]}))}}function Qt(t){if(!t.styles)return"";let n=t.styles.replace(/:host\b/g,":scope");if(/\@scope\s*\(/.test(n))return n;return`@scope (${t.tag}) {
|
|
378
378
|
${n}
|
|
379
|
-
}`}function Zt(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").replace(/\s*([{}:;,])\s*/g,"$1").replace(/;}/g,"}").trim()}function Cr(t){let n=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),o=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}"),d=JSON.stringify('<slot(?:\\s+name=["\\\']([^"\\\']+)["\\\'])?\\s*\\/?>(?:<\\/slot>)?'),s=Object.fromEntries(t.map((
|
|
379
|
+
}`}function Zt(t){return t.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").replace(/\s*([{}:;,])\s*/g,"$1").replace(/;}/g,"}").trim()}function Cr(t){let n=JSON.stringify("\\{!!\\s*([\\w$.]+)\\s*!!\\}"),o=JSON.stringify("\\{\\{\\s*([\\w$.]+)\\s*\\}\\}"),d=JSON.stringify('<slot(?:\\s+name=["\\\']([^"\\\']+)["\\\'])?\\s*\\/?>(?:<\\/slot>)?'),s=Object.fromEntries(t.map((u)=>[u.tag,{template:u.template,styles:u.styles,shadowMode:u.shadowMode,properties:u.properties}])),c=t.map((u)=>`export const render${u.name} = (props = {}, slots = {}) => renderComponent('${u.tag}', props, slots);`).join(`
|
|
380
380
|
`);return`const definitions = ${JSON.stringify(s,null,2)};
|
|
381
381
|
const escapeHTML = (value) => String(value ?? '')
|
|
382
382
|
.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>')
|
|
@@ -410,21 +410,21 @@ export function renderComponent(tag, props = {}, slots = {}) {
|
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
${c}
|
|
413
|
-
`}async function Mi(t){let n=Te.resolve(t.inputDir),o=Te.resolve(t.outputDir);if(!(await Xt(n).catch(()=>null))?.isDirectory())throw Error(`Component-library input directory does not exist: ${n}`);let s=t.components?.length?t.components:(await er(n)).map((
|
|
414
|
-
`)?
|
|
415
|
-
`,"utf8"),
|
|
416
|
-
`);if(await
|
|
417
|
-
`)),await
|
|
413
|
+
`}async function Mi(t){let n=Te.resolve(t.inputDir),o=Te.resolve(t.outputDir);if(!(await Xt(n).catch(()=>null))?.isDirectory())throw Error(`Component-library input directory does not exist: ${n}`);let s=t.components?.length?t.components:(await er(n)).map((b)=>({file:b}));if(!s.length)throw Error(`No .stx components found in ${n}`);let c=await Promise.all(s.map((b)=>vr(n,b,t)));c.sort((b,k)=>b.tag.localeCompare(k.tag));let u=c.filter((b,k)=>c.findIndex((_)=>_.tag===b.tag)!==k);if(u.length)throw Error(`Duplicate custom-element tag: ${u[0].tag}`);let f=c.filter((b,k)=>c.findIndex((_)=>_.name===b.name)!==k);if(f.length)throw Error(`Duplicate component class name: ${f[0].name}`);await Kn(o,{recursive:!0});let g=[],h=async(b,k)=>{let _=Te.join(o,b);return await Jn(_,k.endsWith(`
|
|
414
|
+
`)?k:`${k}
|
|
415
|
+
`,"utf8"),g.push(_),_};await h("runtime.js",wr());for(let b of c){if(await h(`${b.tag}.js`,Sr(b)),t.declarations!==!1)await h(`${b.tag}.d.ts`,kr(b));if(t.css!==!1&&b.styles){let k=b.shadowMode?b.styles:Qt(b);await h(`${b.tag}.css`,t.minify?Zt(k):k)}}let x=c.map((b)=>`export { ${b.name}, default as ${b.name}Element } from './${b.tag}.js';`).join(`
|
|
416
|
+
`);if(await h("index.js",x),await h("ssr.js",Cr(c)),t.declarations!==!1)await h("index.d.ts",c.map((b)=>`export * from './${b.tag}.js'`).join(`
|
|
417
|
+
`)),await h("custom-elements.d.ts",Tr(c)),await h("ssr.d.ts",`${c.map((b)=>`export declare const render${b.name}: (props?: ${b.name}Props, slots?: Record<string, string>) => string`).join(`
|
|
418
418
|
`)}
|
|
419
419
|
export declare function renderComponent(tag: string, props?: Record<string, unknown>, slots?: Record<string, string>): string
|
|
420
|
-
${c.map((
|
|
421
|
-
`)}`);let
|
|
422
|
-
|
|
423
|
-
`);if(
|
|
424
|
-
`);throw AggregateError(
|
|
425
|
-
${
|
|
426
|
-
`);throw AggregateError(
|
|
427
|
-
${
|
|
420
|
+
${c.map((b)=>`import type { ${b.name}Props } from './${b.tag}.js'`).join(`
|
|
421
|
+
`)}`);let v;if(t.manifest!==!1)v=await h("custom-elements.json",JSON.stringify($r(c),null,2));let S;if(t.css!==!1){let b=c.filter((k)=>!k.shadowMode&&k.styles).map(Qt).join(`
|
|
422
|
+
|
|
423
|
+
`);if(b)S=await h("bundle.css",t.minify?Zt(b):b)}let T;if(t.bundle!==!1){T=Te.join(o,"bundle.js");let b;try{b=await Bun.build({entrypoints:[Te.join(o,"index.js")],outdir:o,naming:"bundle.js",target:"browser",format:"esm",minify:t.minify??!0,sourcemap:t.sourcemap||"none"})}catch(k){let _=k instanceof AggregateError?k.errors:[k],E=_.map((R)=>String(R).trim()).filter(Boolean).join(`
|
|
424
|
+
`);throw AggregateError(_,`Failed to bundle component library${E?`
|
|
425
|
+
${E}`:""}`)}if(!b.success){let k=b.logs.map((_)=>String(_).trim()).filter(Boolean).join(`
|
|
426
|
+
`);throw AggregateError(b.logs,`Failed to bundle component library${k?`
|
|
427
|
+
${k}`:""}`)}if(g.push(T),t.sourcemap==="external")g.push(`${T}.map`)}let w=await Promise.all(g.map(async(b)=>(await Xt(b)).size));return{components:c.map((b)=>({name:b.name,tag:b.tag,source:b.sourcePath,module:Te.join(o,`${b.tag}.js`)})),files:g,manifest:v,bundle:T,cssBundle:S,totalBytes:w.reduce((b,k)=>b+k,0)}}var{serve:jr}=globalThis.Bun;import Bt from"fs";import et from"path";function pt(){return`
|
|
428
428
|
/* Theme selector for code blocks */
|
|
429
429
|
.theme-selector {
|
|
430
430
|
margin: 1rem 0;
|
|
@@ -504,12 +504,12 @@ else {
|
|
|
504
504
|
<span class="frontmatter-label">${n}:</span>
|
|
505
505
|
<span>${Array.isArray(o)?o.join(", "):String(o)}</span>
|
|
506
506
|
</div>`).join("")}
|
|
507
|
-
</div>`}import nn from"net";async function Rr(t){return new Promise((n)=>{let o=nn.createServer();o.once("error",()=>n(!1)),o.once("listening",()=>{o.close(()=>n(!0))}),o.listen(t,"0.0.0.0")})}async function Er(t){return new Promise((n)=>{let o=nn.createServer();o.once("error",()=>n(!1)),o.once("listening",()=>{o.close(()=>n(!0))}),o.listen(t,"::")})}async function Pr(t){if(!await Rr(t))return!1;return await Er(t)}async function Ve(t,n=20){t=Number(t);for(let o=0;o<n;o++){let d=t+o;if(await Pr(d))return d}throw Error(`Could not find an available port between ${t} and ${t+n-1}`)}var Ar={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function Mr(){try{let t=await import("./chunk-6ekn4zss.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function Qe(t,n={}){let o={...Ar,...n},d=await Mr();if(!d)return console.log(`${e.yellow}\u26A0${e.reset} Native window requested, but @stacksjs/desktop is not available.`),console.log(" Install & build the desktop package to enable --native."),!1;try{let s=await d.openDevWindow(t,{title:o.title,width:o.width,height:o.height,darkMode:o.darkMode,hotReload:o.hotReload,titlebarHidden:o.titlebarHidden,nativeSidebar:o.nativeSidebar,sidebarWidth:o.sidebarWidth,sidebarConfig:o.sidebarConfig});if(s&&o.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return s}catch(s){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,s),!1}}function ht(t){if(t.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let s=t.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(s){let c=s[1];try{let
|
|
507
|
+
</div>`}import nn from"net";async function Rr(t){return new Promise((n)=>{let o=nn.createServer();o.once("error",()=>n(!1)),o.once("listening",()=>{o.close(()=>n(!0))}),o.listen(t,"0.0.0.0")})}async function Er(t){return new Promise((n)=>{let o=nn.createServer();o.once("error",()=>n(!1)),o.once("listening",()=>{o.close(()=>n(!0))}),o.listen(t,"::")})}async function Pr(t){if(!await Rr(t))return!1;return await Er(t)}async function Ve(t,n=20){t=Number(t);for(let o=0;o<n;o++){let d=t+o;if(await Pr(d))return d}throw Error(`Could not find an available port between ${t} and ${t+n-1}`)}var Ar={title:"stx Development",width:1400,height:900,darkMode:!0,hotReload:!0,titlebarHidden:!1,nativeSidebar:!1,sidebarWidth:260,sidebarConfig:void 0};async function Mr(){try{let t=await import("./chunk-6ekn4zss.js");if(typeof t.openDevWindow!=="function")return null;return t}catch{return null}}async function Qe(t,n={}){let o={...Ar,...n},d=await Mr();if(!d)return console.log(`${e.yellow}\u26A0${e.reset} Native window requested, but @stacksjs/desktop is not available.`),console.log(" Install & build the desktop package to enable --native."),!1;try{let s=await d.openDevWindow(t,{title:o.title,width:o.width,height:o.height,darkMode:o.darkMode,hotReload:o.hotReload,titlebarHidden:o.titlebarHidden,nativeSidebar:o.nativeSidebar,sidebarWidth:o.sidebarWidth,sidebarConfig:o.sidebarConfig});if(s&&o.nativeSidebar)console.log(`${e.green}\u2713${e.reset} Native sidebar enabled (macOS Tahoe style)`);return s}catch(s){return console.log(`${e.red}\u2717${e.reset} Could not open native window:`,s),!1}}function ht(t){if(t.match(/<Sidebar[\s\S]*?variant=["'](?:tahoe|vibrancy|desktop)["'][\s\S]*?\/>/i)){let s=t.match(/<script\s+server[^>]*>([\s\S]*?)<\/script>/i);if(s){let c=s[1];try{let u=`
|
|
508
508
|
${c}
|
|
509
509
|
return typeof sidebarConfig !== 'undefined' ? sidebarConfig : null;
|
|
510
|
-
`,
|
|
510
|
+
`,g=Function(u)();if(g)return g}catch(u){console.warn("Invalid sidebarConfig:",u)}}return{sections:[]}}let o=t.match(/@nativeSidebar\s*\(\s*(\{[\s\S]*?\})\s*\)/m);if(o)try{return JSON.parse(o[1])}catch{console.warn("Invalid @nativeSidebar configuration")}let d=t.match(/<script\s+native-sidebar[^>]*>([\s\S]*?)<\/script>/i);if(d)try{let s=d[1].match(/(?:export\s+(?:default\s+)?|const\s+\w+\s*=\s*)(\{[\s\S]*\})/m);if(s)return Function(`return ${s[1]}`)()}catch(s){console.warn("Invalid native-sidebar script configuration:",s)}return}function Ht(){console.log(`
|
|
511
511
|
Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in browser`),console.log(` ${e.cyan}c${e.reset} + Enter - Clear console`),console.log(` ${e.cyan}q${e.reset} + Enter (or ${e.cyan}Ctrl+C${e.reset}) - Quit server`),console.log(` ${e.cyan}h${e.reset} + Enter - Show this help`)}function _r(t){console.log(`${e.green}Server running at ${e.cyan}${t}${e.reset}`),console.log(`Press ${e.cyan}Ctrl+C${e.reset} to stop the server`),Ht()}function Lr(t){console.log(`${e.dim}Opening ${e.cyan}${t}${e.dim} in your browser...${e.reset}`),Bun.spawn(["open",t],{stderr:"inherit"})}function qe(t,n,o){if(!process.stdin.isTTY)return;process.stdin.setRawMode(!0),process.stdin.setEncoding("utf8"),process.stdin.resume(),Ht();let d="";process.stdin.on("data",(s)=>{if(s==="\x03"){if(o?.onQuit)o.onQuit();n(),process.exit(0)}if(d+=s,d.endsWith("\r")||d.endsWith(`
|
|
512
|
-
`)){let c=d.trim().toLowerCase();d="",Ir(c,t,n,o)}})}function Ir(t,n,o,d){switch(t){case"o":if(d?.onOpen)d.onOpen();else Lr(n);break;case"c":if(d?.onClear)d.onClear();else console.clear(),_r(n);break;case"q":if(d?.onQuit)d.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),o(),process.exit(0);break;case"h":if(d?.onHelp)d.onHelp();else Ht();break;default:break}}async function Ft(t,n={}){let o=n.port||3000,d=n.watch!==!1,s=et.resolve(t);if(!Bt.existsSync(s))return console.error(`${e.red}Error: File not found: ${e.bright}${s}${e.reset}`),!1;if(!s.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${s}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${t}${e.reset}...`);let c=null,
|
|
512
|
+
`)){let c=d.trim().toLowerCase();d="",Ir(c,t,n,o)}})}function Ir(t,n,o,d){switch(t){case"o":if(d?.onOpen)d.onOpen();else Lr(n);break;case"c":if(d?.onClear)d.onClear();else console.clear(),_r(n);break;case"q":if(d?.onQuit)d.onQuit();console.log(`${e.yellow}Stopping server...${e.reset}`),o(),process.exit(0);break;case"h":if(d?.onHelp)d.onHelp();else Ht();break;default:break}}async function Ft(t,n={}){let o=n.port||3000,d=n.watch!==!1,s=et.resolve(t);if(!Bt.existsSync(s))return console.error(`${e.red}Error: File not found: ${e.bright}${s}${e.reset}`),!1;if(!s.endsWith(".md"))return console.error(`${e.red}Error: File must have .md extension: ${e.bright}${s}${e.reset}`),!1;console.log(`${e.blue}Processing${e.reset} ${e.bright}${t}${e.reset}...`);let c=null,u=async()=>{try{let{content:v,data:S}=await Re(s,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),T=n.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,w=T?.defaultTheme||"github-dark",b=["github-dark"],k=T?.additionalThemes||[],E=[...new Set([...b,...k])].map((R)=>`<option value="${R}"${R===w?" selected":""}>${R}</option>`).join(`
|
|
513
513
|
`);return c=`
|
|
514
514
|
<!DOCTYPE html>
|
|
515
515
|
<html lang="en">
|
|
@@ -663,21 +663,21 @@ Keyboard shortcuts:`),console.log(` ${e.cyan}o${e.reset} + Enter - Open in brow
|
|
|
663
663
|
</head>
|
|
664
664
|
<body>
|
|
665
665
|
${gt(S)}
|
|
666
|
-
${ut(
|
|
666
|
+
${ut(E)}
|
|
667
667
|
|
|
668
|
-
${
|
|
668
|
+
${v}
|
|
669
669
|
|
|
670
670
|
<script>
|
|
671
671
|
${ft()}
|
|
672
672
|
</script>
|
|
673
673
|
</body>
|
|
674
674
|
</html>
|
|
675
|
-
`,!0}catch(
|
|
676
|
-
${
|
|
675
|
+
`,!0}catch(v){return console.error(`${e.red}Error processing Markdown file:${e.reset}`,v),!1}};if(!await u())return!1;let g=o;try{if(g=await Ve(o),g!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${g} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${g}/${e.reset}...`);let h=jr({port:g,fetch(v){if(new URL(v.url).pathname==="/")return new Response(c,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}});return new Response("Not Found",{status:404})},error(v){return new Response(`<pre>${v}
|
|
676
|
+
${v.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
677
677
|
${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
|
|
678
|
-
${e.bright}\u2192 ${e.cyan}http://localhost:${
|
|
679
|
-
${e.yellow}Routes:${e.reset}`);let
|
|
680
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(
|
|
678
|
+
${e.bright}\u2192 ${e.cyan}http://localhost:${g}/${e.reset}`),console.log(`
|
|
679
|
+
${e.yellow}Routes:${e.reset}`);let x=et.relative(process.cwd(),s);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${x}${e.reset}`),console.log(`
|
|
680
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(h.url.toString(),()=>{if(d)Bt.watch(et.dirname(s),{recursive:!0}).close();h.stop()}),n.native)await Qe(g,{title:et.basename(s,".md")});if(d){let v=et.dirname(s);console.log(`${e.blue}Watching ${e.bright}${v}${e.reset} for changes...`);let S=Bt.watch(v,{recursive:!0},async(T,w)=>{if(w&&w.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${w}${e.yellow} changed, reprocessing...${e.reset}`),await u()});process.on("SIGINT",()=>{S.close(),h.stop(),process.exit(0)})}return!0}function Hr(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:zr}=globalThis.Bun;import Be from"fs";import ge from"path";class rn{clients=new Set;server=null;options;constructor(t={}){this.options={wsPort:t.wsPort??3001,showOverlay:t.showOverlay??!0,reconnectInterval:t.reconnectInterval??1000,maxReconnectAttempts:t.maxReconnectAttempts??10,verbose:t.verbose??!1}}start(t){let n=t??this.options.wsPort,o=20;for(let d=0;d<o;d++)try{if(this.server=Bun.serve({port:n,fetch(s,c){if(c.upgrade(s,{data:{}}))return;return new Response("stx Hot Reload Server",{headers:{"Content-Type":"text/plain"}})},websocket:{open:(s)=>{if(this.clients.add(s),this.options.verbose)console.log(`[HMR] Client connected (${this.clients.size} total)`);s.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close:(s)=>{if(this.clients.delete(s),this.options.verbose)console.log(`[HMR] Client disconnected (${this.clients.size} total)`)},message:(s,c)=>{let u=typeof c==="string"?c:c.toString();if(u==="ping")return;try{let f=JSON.parse(u);if(f.type==="console"&&Array.isArray(f.args)){let g=f.args.join(" "),x={log:"\x1B[36m",warn:"\x1B[33m",error:"\x1B[31m",info:"\x1B[34m"}[f.level]??"\x1B[36m";console.log(`${x}[browser]${f.level!=="log"?` ${f.level}`:""}\x1B[0m ${g}`)}}catch{}}}}),this.options.verbose)console.log(`[HMR] WebSocket server started on port ${n}`);return n}catch(s){if(s?.code==="EADDRINUSE"){n++;continue}throw s}throw Error(`Could not find an available port after ${o} attempts starting from ${t??this.options.wsPort}`)}stop(){for(let t of this.clients)try{t.close()}catch{}if(this.clients.clear(),this.server)this.server.stop(),this.server=null;if(this.options.verbose)console.log("[HMR] Server stopped")}broadcast(t){let n=JSON.stringify(t),o=0;for(let d of this.clients)try{if(d.readyState===1)d.send(n),o++}catch{this.clients.delete(d)}if(this.options.verbose&&o>0)console.log(`[HMR] Broadcast ${t.type} to ${o} client(s)`)}reload(t){if(this.options.verbose)console.log(`[HMR] Sending reload to ${this.clients.size} client(s) for: ${t||"all"}`);this.broadcast({type:"reload",path:t,timestamp:Date.now()})}updateCss(t,n){this.broadcast({type:"css-update",path:t,content:n,timestamp:Date.now()})}error(t){this.broadcast({type:"error",content:t,timestamp:Date.now()})}get clientCount(){return this.clients.size}get port(){return this.options.wsPort}}function Fr(t,n={}){let{showOverlay:o=!0,reconnectInterval:d=1000,maxReconnectAttempts:s=10}=n;return`
|
|
681
681
|
<script>
|
|
682
682
|
(function() {
|
|
683
683
|
// stx Hot Reload Client
|
|
@@ -876,10 +876,10 @@ else {
|
|
|
876
876
|
};
|
|
877
877
|
})();
|
|
878
878
|
</script>
|
|
879
|
-
`}function Ne(t,n,o={}){let d=Fr(n,o),s=t.lastIndexOf("</body>");if(s!==-1)return t.slice(0,s)+d+t.slice(s);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function yt(t){let n=t.toLowerCase();return n.endsWith(".css")||n.endsWith(".scss")||n.endsWith(".sass")||n.endsWith(".less")}function bt(t){let n=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>n.endsWith(d))}function vt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((o)=>o.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 o={...await a(),...t.config?.stx},d=new Set,s=o.webComponents?.enabled?`./${$t.relative($t.dirname(t.config?.outdir||"dist"),o.webComponents.outputDir||"dist/web-components")}`:"/web-components",c=[];if(o.webComponents?.enabled)try{let
|
|
880
|
-
`),S),
|
|
881
|
-
`+
|
|
882
|
-
${
|
|
879
|
+
`}function Ne(t,n,o={}){let d=Fr(n,o),s=t.lastIndexOf("</body>");if(s!==-1)return t.slice(0,s)+d+t.slice(s);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function yt(t){let n=t.toLowerCase();return n.endsWith(".css")||n.endsWith(".scss")||n.endsWith(".sass")||n.endsWith(".less")}function bt(t){let n=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>n.endsWith(d))}function vt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((o)=>o.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 o={...await a(),...t.config?.stx},d=new Set,s=o.webComponents?.enabled?`./${$t.relative($t.dirname(t.config?.outdir||"dist"),o.webComponents.outputDir||"dist/web-components")}`:"/web-components",c=[];if(o.webComponents?.enabled)try{let u=await ls(o,d);if(c.push(...u),o.debug&&u.length>0)console.log(`Successfully built ${u.length} web components`)}catch(u){console.error("Failed to build web components:",u)}t.onLoad({filter:/\.stx$/},async({path:u})=>{try{let f=new Set;if(o.cache&&o.cachePath){let b=await ir(u,o);if(b){if(o.debug)console.log(`Using cached version of ${u}`);return{contents:b,loader:"html"}}}let g=await Se(()=>Bun.file(u).text(),"",(b)=>{throw new xr(`Failed to read stx file: ${u}`,u,void 0,void 0,`File read error: ${b.message}`)});if(!g)throw new xr(`stx file is empty: ${u}`,u);let{scriptContent:h,templateContent:x,allScripts:v}=oe.time("script-extraction",()=>{let b=g,k=de(g);if(k)b=k.content.trim();let _=g.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],E="",R=[];for(let C of _){let D=C.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",I=C.match(/<script\b([^>]*)>/i),V=I?I[1]:"";if(/\bserver\b/i.test(V))E=D;else R.push(C)}let A=b.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:E,templateContent:A,allScripts:R}}),S={__filename:u,__dirname:$t.dirname(u),__stx:{webComponentsPath:s,builtComponents:c}};await Se(()=>m(h,S,u),void 0,(b)=>{let k=new ae(`Script execution failed in ${u}: ${b.message}`,u,void 0,void 0,h.substring(0,100));if(B.log(k,{filePath:u,scriptContent:h}),o.debug)throw k});let w=await oe.timeAsync("directive-processing",async()=>await i(x,S,u,o,f));if(v.length>0){let{interpolateScriptsInTemplate:b}=await import("./chunk-ke2t93w6.js"),k=b(v.join(`
|
|
880
|
+
`),S),_=w.search(/<\/body>/i);if(_!==-1)w=w.slice(0,_)+k+`
|
|
881
|
+
`+w.slice(_);else w+=`
|
|
882
|
+
${k}`}if(w=await be(w),f.forEach((b)=>d.add(b)),o.cache&&o.cachePath){if(await ar(u,w,f,o),o.debug)console.log(`Cached template ${u} with ${f.size} dependencies`)}return{contents:w,loader:"html"}}catch(f){let g=f instanceof Error?f:new ae(`Plugin processing failed: ${String(f)}`,u);if(B.log(g,{filePath:u,buildConfig:t.config}),wn.logDetailedError(g,{filePath:u,plugin:"bun-plugin-stx"}),o.debug)console.error("stx Plugin Error:",g);let h=g,x=h.line||null,v=h.context||null;return{contents:o.debug||K()?`<!DOCTYPE html>
|
|
883
883
|
<html lang="en">
|
|
884
884
|
<head>
|
|
885
885
|
<meta charset="UTF-8">
|
|
@@ -902,16 +902,16 @@ ${T}`}if(v=await be(v),u.forEach((x)=>d.add(x)),o.cache&&o.cachePath){if(await a
|
|
|
902
902
|
|
|
903
903
|
<div class="error-details">
|
|
904
904
|
<h3>Error Details</h3>
|
|
905
|
-
<p><strong>File:</strong> <span class="file-path">${p(
|
|
906
|
-
<p><strong>Error:</strong> ${p(
|
|
907
|
-
${
|
|
908
|
-
${
|
|
905
|
+
<p><strong>File:</strong> <span class="file-path">${p(u)}</span></p>
|
|
906
|
+
<p><strong>Error:</strong> ${p(g.message)}</p>
|
|
907
|
+
${x?`<p><strong>Line:</strong> ${p(String(x))}</p>`:""}
|
|
908
|
+
${v?`<p><strong>Context:</strong> ${p(String(v))}</p>`:""}
|
|
909
909
|
</div>
|
|
910
910
|
|
|
911
|
-
${
|
|
911
|
+
${g.stack?`
|
|
912
912
|
<div class="error-details">
|
|
913
913
|
<h3>Stack Trace</h3>
|
|
914
|
-
<pre class="error-code">${p(
|
|
914
|
+
<pre class="error-code">${p(g.stack)}</pre>
|
|
915
915
|
</div>`:""}
|
|
916
916
|
|
|
917
917
|
<div class="help-section">
|
|
@@ -920,7 +920,7 @@ ${T}`}if(v=await be(v),u.forEach((x)=>d.add(x)),o.cache&&o.cachePath){if(await a
|
|
|
920
920
|
<li>Check the syntax of your stx directives (e.g., @if, @foreach)</li>
|
|
921
921
|
<li>Verify that all variables used in the template are properly defined</li>
|
|
922
922
|
<li>Ensure script tags have valid JavaScript/TypeScript syntax</li>
|
|
923
|
-
<li>Run <code>stx debug ${p($t.basename(
|
|
923
|
+
<li>Run <code>stx debug ${p($t.basename(u))}</code> for detailed analysis</li>
|
|
924
924
|
<li>Enable debug mode in your stx config for more detailed error messages</li>
|
|
925
925
|
</ul>
|
|
926
926
|
</div>
|
|
@@ -939,12 +939,12 @@ ${T}`}if(v=await be(v),u.forEach((x)=>d.add(x)),o.cache&&o.cachePath){if(await a
|
|
|
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 Or(t,n={}){let o=n.port||3000,d=n.watch!==!1,s=n.hotReload!==!1&&d,c=null,
|
|
942
|
+
</html>`,loader:"html"}}})}};async function Or(t,n={}){let o=n.port||3000,d=n.watch!==!1,s=n.hotReload!==!1&&d,c=null,u=n.hmrPort||o+1,f=ge.resolve(t);if(!Be.existsSync(f))return console.error(`${e.red}Error: File not found: ${e.bright}${f}${e.reset}`),!1;if(f.endsWith(".md"))return Ft(f,n);else if(!f.endsWith(".stx"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${f}${e.reset}. Only .stx and .md files are supported.`),!1;let g=l(process.cwd(),"output");Be.mkdirSync(g,{recursive:!0}),console.log(`${e.blue}Building ${e.bright}${t}${e.reset}...`);let h=null,x=async()=>{try{let D={name:"public-assets",setup(ve){ve.onResolve({filter:/^\/(images|fonts|assets|public)\//},(le)=>({path:le.path,external:!0}))}},I=await Bun.build({entrypoints:[f],outdir:g,plugins:[D,nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!I.success)return console.error(`${e.red}Build failed:${e.reset}`,I.logs),!1;let V=I.outputs.find((ve)=>ve.path.endsWith(".html"));if(!V)return console.error(`${e.red}No HTML output found${e.reset}`),!1;return h=await Bun.file(V.path).text(),!0}catch(D){return console.error(`${e.red}Error building stx file:${e.reset}`,D),!1}};if(!await x())return!1;let S=ge.dirname(f);await sn(S);let T=o;try{if(T=await Ve(o),T!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${T} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(s){let D=n.hmrPort||T+1;c=Tt({wsPort:D,verbose:!1}),u=c.start(D)}let w={},b=null,k;try{let{loadStxConfig:D}=await import("./chunk-y9335aa8.js"),I=await D();if(k=n.stxOptions?.serverApi??I.serverApi,I?.apiRouter)b=I?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(I?.apiRoutes){w=I.apiRoutes;let V=Object.keys(w).length;if(V>0)console.log(`${e.blue}Loaded ${e.bright}${V} API route${V>1?"s":""}${e.reset}`)}if(I?.broadcasting?.enabled)try{let{startBroadcasting:V,loadChannels:Y}=await import("./chunk-79sjdpfy.js"),ve=I.broadcasting;await V(ve);let le=ve.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${le}/ws${e.reset}`);let Pe=ge.join(process.cwd(),"channels.ts");if(Be.existsSync(Pe))try{let ne=await Y(Pe);console.log(`${e.blue}Loaded ${e.bright}${ne} broadcast channel${ne!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(ne){console.warn(`${e.yellow}Failed to load channels.ts: ${ne.message}${e.reset}`)}}catch(V){console.warn(`${e.yellow}Broadcasting failed to start: ${V.message}${e.reset}`)}}catch{}let{createServerApi:_,isServerApiSource:E}=await import("./chunk-tef5t0b2.js"),R=await _(process.cwd(),k);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${T}/${e.reset}...`),s)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${u}${e.reset}`);let A=zr({port:T,async fetch(D){return Cn(D,await(async()=>{let I=new URL(D.url);if([g,ge.dirname(f),ge.join(process.cwd(),"public")].some((ne)=>E(ge.join(ne,I.pathname),process.cwd(),k)))return new Response("Not Found",{status:404});if(b)try{let ne=await b.handleRequest(D);if(ne.status!==404)return ne}catch{}if(w[I.pathname])try{return await w[I.pathname](D)}catch(ne){return new Response(JSON.stringify({error:ne.message}),{status:500,headers:{"Content-Type":"application/json"}})}let V=await R(D);if(V)return V;if(I.pathname==="/")return(async()=>{let F=await y(h||"");if(s)F=Ne(F,u);if(n.native)if(F.includes("<head>"))F=F.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(F.includes("<html"))F=F.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 F="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+F;if(n.titlebarHidden)if(F.includes("<head>"))F=F.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(F.includes("<html"))F=F.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 F=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${F}`;return F})().then((F)=>new Response(F,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}}));let Y=ge.join(g,I.pathname);if(Be.existsSync(Y)&&Be.statSync(Y).isFile()){let ne=Bun.file(Y),F=ge.extname(Y).toLowerCase(),L="text/plain";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}let ve=ge.dirname(f),le=ge.join(ve,I.pathname);if(Be.existsSync(le)&&Be.statSync(le).isFile()){let ne=Bun.file(le),F=ge.extname(le).toLowerCase(),L="text/plain";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}let Pe=ge.join(process.cwd(),"public",I.pathname);if(Be.existsSync(Pe)&&Be.statSync(Pe).isFile()){let ne=Bun.file(Pe),F=ge.extname(Pe).toLowerCase(),L="application/octet-stream";if(F===".ts"||F===".tsx"){let Fe=new Bun.Transpiler({loader:F===".tsx"?"tsx":"ts"}),ze=await ne.text(),Je=Fe.transformSync(ze);return new Response(Je,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(F){case".html":L="text/html";break;case".css":L="text/css";break;case".js":L="text/javascript";break;case".json":L="application/json";break;case".png":L="image/png";break;case".jpg":case".jpeg":L="image/jpeg";break;case".gif":L="image/gif";break;case".svg":L="image/svg+xml";break;case".ico":L="image/x-icon";break;case".woff":L="font/woff";break;case".woff2":L="font/woff2";break;case".ttf":L="font/ttf";break;case".otf":L="font/otf";break;case".eot":L="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":L}})}return new Response("Not Found",{status:404})})())},error(D){return new Response(`<pre>${D}
|
|
943
943
|
${D.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
|
-
${e.bright}\u2192 ${e.cyan}http://localhost:${
|
|
946
|
-
${e.yellow}Routes:${e.reset}`);let
|
|
947
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(A.url.toString(),()=>{if(d)Be.watch(ge.dirname(
|
|
945
|
+
${e.bright}\u2192 ${e.cyan}http://localhost:${T}/${e.reset}`),console.log(`
|
|
946
|
+
${e.yellow}Routes:${e.reset}`);let C=ge.relative(process.cwd(),f);if(console.log(` ${e.green}\u2514\u2500 /${e.reset} \u2192 ${e.bright}${C}${e.reset}`),console.log(`
|
|
947
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(A.url.toString(),()=>{if(d)Be.watch(ge.dirname(f),{recursive:!0}).close();A.stop()}),n.native){let D=await Bun.file(f).text(),I=ht(D);await Qe(T,{title:ge.basename(f,".stx"),titlebarHidden:n.titlebarHidden===!0,nativeSidebar:!!I,sidebarConfig:I})}if(d){let D=ge.dirname(f);console.log(`${e.blue}Watching ${e.bright}${D}${e.reset} for changes...`);let I=Be.watch(D,{recursive:!0},async(V,Y)=>{if(!Y||vt(Y))return;if(bt(Y)){console.log(`${e.yellow}File ${e.bright}${Y}${e.yellow} changed, rebuilding...${e.reset}`),Ge.clear(),fe();let ve=await x();if(await tr(S),s&&c)if(ve)c.reload(Y);else c.error("Build failed - check console for details")}else if(yt(Y)){if(console.log(`${e.cyan}CSS ${e.bright}${Y}${e.cyan} changed${e.reset}`),s&&c)c.updateCss(Y)}});process.on("SIGINT",()=>{if(I.close(),c)st();A.stop(),process.exit(0)})}return!0}var{serve:Ur}=globalThis.Bun;import Ke from"fs";import Ee from"path";var on=`
|
|
948
948
|
<script data-stx-helpers>
|
|
949
949
|
(function() {
|
|
950
950
|
'use strict'
|
|
@@ -1255,14 +1255,14 @@ else {
|
|
|
1255
1255
|
|
|
1256
1256
|
})()
|
|
1257
1257
|
</script>
|
|
1258
|
-
`;function cn(t){if(t.length===0)return"";if(t.length===1)return t[0];let n=t.map((d)=>d.split(Ee.sep)),o=[];for(let d=0;d<n[0].length;d++){let s=n[0][d];if(n.every((c)=>c[d]===s))o.push(s);else break}return o.join(Ee.sep)}async function Nr(t,n={}){let o=n.port||3000,d=n.watch!==!1;for(let
|
|
1258
|
+
`;function cn(t){if(t.length===0)return"";if(t.length===1)return t[0];let n=t.map((d)=>d.split(Ee.sep)),o=[];for(let d=0;d<n[0].length;d++){let s=n[0][d];if(n.every((c)=>c[d]===s))o.push(s);else break}return o.join(Ee.sep)}async function Nr(t,n={}){let o=n.port||3000,d=n.watch!==!1;for(let w of t){let b=Ee.resolve(w);if(!Ke.existsSync(b))return console.error(`${e.red}Error: File not found: ${e.bright}${b}${e.reset}`),!1;if(!b.endsWith(".stx")&&!b.endsWith(".md"))return console.error(`${e.red}Error: Unsupported file type: ${e.bright}${b}${e.reset}. Only .stx and .md files are supported.`),!1}let s=l(process.cwd(),"output");Ke.mkdirSync(s,{recursive:!0});let c=cn(t.map((w)=>Ee.dirname(Ee.resolve(w))));console.log(`${e.blue}Processing ${e.bright}${t.length}${e.reset} files...`);let u={},f=[],g=async()=>{try{for(let w of t){let b=Ee.resolve(w);if(b.endsWith(".md"))try{let{content:_,data:E}=await Re(b,{markdown:{syntaxHighlighting:{serverSide:!0,enabled:!0,defaultTheme:P.markdown?.syntaxHighlighting?.defaultTheme||"github-dark",highlightUnknownLanguages:!0}}}),R=n.markdown?.syntaxHighlighting||P.markdown?.syntaxHighlighting,A=R?.defaultTheme||"github-dark",C=["github-dark"],D=R?.additionalThemes||[],V=[...new Set([...C,...D])].map((Pe)=>`<option value="${Pe}"${Pe===A?" selected":""}>${Pe}</option>`).join(`
|
|
1259
1259
|
`),Y=`
|
|
1260
1260
|
<!DOCTYPE html>
|
|
1261
1261
|
<html lang="en">
|
|
1262
1262
|
<head>
|
|
1263
1263
|
<meta charset="UTF-8">
|
|
1264
1264
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
1265
|
-
<title>${an(
|
|
1265
|
+
<title>${an(E.title||Ee.basename(b))}</title>
|
|
1266
1266
|
<!-- Syntax highlighting styles -->
|
|
1267
1267
|
<style id="syntax-theme">
|
|
1268
1268
|
:root {
|
|
@@ -1408,36 +1408,36 @@ else {
|
|
|
1408
1408
|
</style>
|
|
1409
1409
|
</head>
|
|
1410
1410
|
<body>
|
|
1411
|
-
${gt(
|
|
1411
|
+
${gt(E)}
|
|
1412
1412
|
${ut(V)}
|
|
1413
1413
|
|
|
1414
|
-
${
|
|
1414
|
+
${_}
|
|
1415
1415
|
|
|
1416
1416
|
<script>
|
|
1417
1417
|
${ft()}
|
|
1418
1418
|
</script>
|
|
1419
1419
|
</body>
|
|
1420
1420
|
</html>
|
|
1421
|
-
`,le=`/${Ee.relative(c,
|
|
1422
|
-
${$e(
|
|
1423
|
-
</head>`);else I=V+I;
|
|
1424
|
-
</head>`);return new Response(
|
|
1425
|
-
${
|
|
1421
|
+
`,le=`/${Ee.relative(c,b).replace(/\.md$/,"")}`;if(le.endsWith("/index"))le=le.slice(0,-6)||"/";u[le||"/"]={filePath:b,content:Y,fileType:"md"}}catch(_){console.error(`${e.red}Error processing Markdown file ${e.bright}${w}${e.reset}:`,_);continue}else{let _={name:"public-assets",setup(C){C.onResolve({filter:/^\/(images|fonts|assets|public)\//},(D)=>({path:D.path,external:!0}))}},E;try{let C=await Bun.build({entrypoints:[b],outdir:s,plugins:[_,nt],define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!C.success){console.error(`${e.red}Build failed for ${e.bright}${w}${e.reset}:`,$e(C.logs,b));continue}let D=C.outputs.find((I)=>I.path.endsWith(".html"));if(!D){console.error(`${e.red}No HTML output found for ${e.bright}${w}${e.reset}`);continue}E=await Bun.file(D.path).text()}catch(C){console.error(`${e.red}Build failed for ${e.bright}${w}${e.reset}:
|
|
1422
|
+
${$e(C,b)}`);continue}let A=`/${Ee.relative(c,b).replace(/\.stx$/,"")}`;if(A.endsWith("/index"))A=A.slice(0,-6)||"/";if(A.includes("[")){let{regex:C,params:D}=hs(A,{page:!0});f.push({pattern:C,paramNames:D,filePath:b,routeTemplate:A,fileType:"stx"}),u[A]={filePath:b,content:E,fileType:"stx"}}else u[A||"/"]={filePath:b,content:E,fileType:"stx"}}}if(Object.keys(u).length===0)return console.error(`${e.red}No files were successfully processed${e.reset}`),!1;return!0}catch(w){return console.error(`${e.red}Error processing files:${e.reset}`,$e(w)),!1}};if(!await g())return!1;let x=o;try{if(x=await Ve(o),x!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${x} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${x}/${e.reset}...`);let v=Ur({port:x,async fetch(w){let b=new URL(w.url),k=Ee.join(process.cwd(),"public",b.pathname);if(Ke.existsSync(k)&&Ke.statSync(k).isFile()){let R=Bun.file(k),A=Ee.extname(k).toLowerCase(),C="application/octet-stream";if(A===".ts"||A===".tsx"){let D=new Bun.Transpiler({loader:A===".tsx"?"tsx":"ts"}),I=await R.text(),V=D.transformSync(I);return new Response(V,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(A){case".html":C="text/html";break;case".css":C="text/css";break;case".js":C="text/javascript";break;case".json":C="application/json";break;case".png":C="image/png";break;case".jpg":case".jpeg":C="image/jpeg";break;case".gif":C="image/gif";break;case".svg":C="image/svg+xml";break;case".ico":C="image/x-icon";break;case".woff":C="font/woff";break;case".woff2":C="font/woff2";break;case".ttf":C="font/ttf";break;case".otf":C="font/otf";break;case".eot":C="application/vnd.ms-fontobject";break}return new Response(R,{headers:{"Content-Type":C}})}let _=u[b.pathname];if(!_&&!b.pathname.endsWith("/"))_=u[`${b.pathname}/`];if(!_)for(let R of f){let A=b.pathname.match(R.pattern);if(A){let C=u[R.routeTemplate];if(C){let D={};for(let Y=0;Y<R.paramNames.length;Y++)D[R.paramNames[Y]]=decodeURIComponent(A[Y+1]);let I=C.content,V=`<script>window.__routeParams = ${JSON.stringify(D)};</script>`;if(I.includes("</head>"))I=I.replace("</head>",`${V}
|
|
1423
|
+
</head>`);else I=V+I;_={...C,content:I}}break}}if(_)return y(_.content).then((R)=>{if(R.includes("</head>"))R=R.replace("</head>",`${on}
|
|
1424
|
+
</head>`);return new Response(R,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})});let E=Ee.join(s,b.pathname);if(Ke.existsSync(E)&&Ke.statSync(E).isFile()){let R=Bun.file(E),A=Ee.extname(E).toLowerCase(),C="text/plain";if(A===".ts"||A===".tsx"){let D=new Bun.Transpiler({loader:A===".tsx"?"tsx":"ts"}),I=await R.text(),V=D.transformSync(I);return new Response(V,{headers:{"Content-Type":"application/javascript","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}switch(A){case".html":C="text/html";break;case".css":C="text/css";break;case".js":C="text/javascript";break;case".json":C="application/json";break;case".png":C="image/png";break;case".jpg":case".jpeg":C="image/jpeg";break;case".gif":C="image/gif";break;case".svg":C="image/svg+xml";break;case".ico":C="image/x-icon";break;case".woff":C="font/woff";break;case".woff2":C="font/woff2";break;case".ttf":C="font/ttf";break;case".otf":C="font/otf";break;case".eot":C="application/vnd.ms-fontobject";break}return new Response(R,{headers:{"Content-Type":C}})}if(b.pathname!=="/"&&u["/"]){let R=_e(w);return y(u["/"].content).then((A)=>{if(R){let C=A.match(/<main[^>]*>([\s\S]*?)<\/main>/i);if(C){let D=A.match(/<title[^>]*>([\s\S]*?)<\/title>/i),I=D?D[1]:"",V=`<!DOCTYPE html><html><head><title>${an(I)}</title></head><body><main>${C[1]}</main></body></html>`;return new Response(V,{headers:{"Content-Type":"text/html","X-STX-Partial":"true",...M(),"Cache-Control":dt,Pragma:"no-cache",Expires:"0"}})}}return new Response(A,{headers:{"Content-Type":"text/html",...M(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})})}return new Response("Not Found",{status:404})},error(w){return new Response(`<pre>${w}
|
|
1425
|
+
${w.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
1426
1426
|
${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
|
|
1427
|
-
${e.bright}\u2192 ${e.cyan}http://localhost:${
|
|
1428
|
-
${e.yellow}Routes:${e.reset}`);let S=new Set(
|
|
1429
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(w.url.toString(),()=>{if(d)Ke.watch(c,{recursive:!0}).close();w.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let v=Ke.watch(c,{recursive:!0},async(x,T)=>{if(!T)return;if(T.endsWith(".stx")||T.endsWith(".js")||T.endsWith(".ts")||T.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${T}${e.yellow} changed, rebuilding...${e.reset}`),Ge.clear(),fe(),await h()});process.on("SIGINT",()=>{v.close(),w.stop(),process.exit(0)})}return!0}function an(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Wr}=globalThis.Bun;import me from"fs";import te from"path";async function ln(t){try{return pn(await Bun.file(t).text())}catch{return}}function zt(t){let n=Bun.file(t),o=te.extname(t).toLowerCase(),d={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},c=[".js",".css",".json"].includes(o)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(n,{headers:{"Content-Type":d[o]||"application/octet-stream",...c}})}async function Dr(t=".",n={}){let o=n.port||3000,d=n.watch!==!1,s=n.hotReload!==!1&&d,c=null,f=n.hmrPort||o+1,u=te.resolve(t),{loadStxConfig:h}=await import("./chunk-ddxrb5zk.js"),g=await h(u),{createServerApi:b,isServerApiSource:w}=await import("./chunk-kxp881ch.js"),S=n.stxOptions?.serverApi??g.serverApi,C=await b(u,S),v=g.root&&g.root!=="."?te.join(u,g.root):u,x=n.pagesDir||g.pagesDir||"pages",T=te.join(v,x);if(!me.existsSync(T)&&!g._layerPageDirs?.some((E)=>me.existsSync(E)))return console.error(`${e.red}Error: No '${x}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${T}${e.reset}`),console.log(`${e.dim}Run stx dev from the app directory, pass it as an argument (stx dev <dir>),${e.reset}`),console.log(`${e.dim}point at another directory with --pages <dir>, or set pagesDir in stx.config.ts.${e.reset}`),console.log(`${e.dim}Starting fresh? Create ${x}/index.stx for the homepage.${e.reset}`),!1;let k=G(v,{pagesDir:x,pagesDirs:g._layerPageDirs?[T,...g._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 L=g?._pluginPageDirs||[],O=[];for(let{dir:E,prefix:j}of L)if(me.existsSync(E)){let z=G(te.dirname(E),{pagesDir:te.basename(E)});for(let Q of z){let q=j==="/"?Q.pattern:`${j}${Q.pattern==="/"?"":Q.pattern}`;O.push({route:{...Q,pattern:q},prefix:j})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${j}${e.reset}`)}let A=new Map,R=null,D=null;if(n.stxOptions?.shell!==!1){if(D=await Ki(u,n.stxOptions?.shell),D){if(R=await to(D,n.stxOptions||{}),R)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(u,D)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}xt(),await kt(u);let I=St();if(I.length>0)console.log(`${e.blue}Loaded ${e.bright}${I.length}${e.blue} middleware: ${e.dim}${I.join(", ")}${e.reset}`);let V={},Y=null;try{let{loadStxConfig:E}=await import("./chunk-ddxrb5zk.js"),j=await E(u);if(j?.apiRouter)Y=j?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(j?.apiRoutes){V=j.apiRoutes;let z=Object.keys(V).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(j?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:Q}=await import("./chunk-79sjdpfy.js"),q=j.broadcasting;await z(q);let Oe=q.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Oe}/ws${e.reset}`);let we=te.join(process.cwd(),"channels.ts");if(me.existsSync(we))try{let N=await Q(we);console.log(`${e.blue}Loaded ${e.bright}${N} broadcast channel${N!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(N){console.warn(`${e.yellow}Failed to load channels.ts: ${N.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let ve=l(u,"output");me.mkdirSync(ve,{recursive:!0});let le=new Map,Pe=new Set,ne=async(E)=>{let j=ys(T,E);if(!j)return null;try{let z=await Bun.build({entrypoints:[j],outdir:ve,plugins:[nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!z.success)return null;let Q=z.outputs.find((q)=>q.path.endsWith(".html"));if(!Q)return null;return await Bun.file(Q.path).text()}catch{return null}},F=new Map,_=async(E,j)=>{try{let{processDirectives:z,extractVariables:Q,defaultConfig:q,loadStxConfig:Oe,injectRouterScript:we}=await import("./chunk-ddxrb5zk.js"),{checkCache:N,cacheTemplate:J,readFileCached:W,templateCache:pe}=await import("./chunk-57ecpsqy.js"),X=await Oe(u),We=(ie)=>{if(!ie)return ie;if(te.isAbsolute(ie))return ie;return te.resolve(u,ie)},ce={...q,...X,...n.stxOptions,autoShell:!0};if(n.debugDirectives)ce.debug=!0;ce.partialsDir=We(ce.partialsDir),ce.componentsDir=We(ce.componentsDir),ce.layoutsDir=We(ce.layoutsDir),ce.storesDir=We(ce.storesDir||"stores"),ce.cachePath=We(ce.cachePath)??l(u,"cache");let H=!j&&!n.profile,re=ce.cache!==!1;if(re&&H){let ie=pe.get(E.filePath);if(ie)try{if((await me.promises.stat(E.filePath)).mtime.getTime()<=ie.mtime){let He=!0;for(let ke of ie.dependencies){if(!me.existsSync(ke)){He=!1;break}if((await me.promises.stat(ke)).mtime.getTime()>ie.mtime){He=!1;break}}if(He){let ke=ie.output;if(R)ke=Ue(ke,{preserveHead:!0});let ot=F.get(E.filePath);return{route:E,content:ke,status:ot?.status??await ln(E.filePath),headers:ot?.headers}}}}catch{}let Ie=await N(E.filePath,ce);if(Ie){let je=Ie;if(R)je=Ue(je,{preserveHead:!0});let He=F.get(E.filePath);return{route:E,content:je,status:He?.status??await ln(E.filePath),headers:He?.headers}}}let Z=re?await W(E.filePath):await Bun.file(E.filePath).text(),se=pn(Z),{classifyAllScripts:ue}=await import("./chunk-ddxrb5zk.js"),U=ue(Z),Le=U.server.map((ie)=>ie.content),De=Z;for(let ie of U.server)De=De.replace(ie.fullTag,"");let ee={__filename:E.filePath,__dirname:te.dirname(E.filePath),__stx_options:ce,params:j??{},__stx_runtime_head:{}};for(let ie of Le)try{await Q(ie,ee,E.filePath)}catch(Ie){if(n.stxOptions?.debug)console.error("[stx] variable extraction error",E.filePath,Ie?.message||Ie)}let Ae=new Set,he;if(n.profile){let ie=performance.now();he=await z(De,ee,E.filePath,ce,Ae);let Ie=performance.now()-ie,je=te.relative(u,E.filePath)||E.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else he=await z(De,ee,E.filePath,ce,Ae);if(!R)he=await we(he,{router:ce.router});{let{interpolateScriptExpressions:ie}=await import("./chunk-04xtzbf6.js");he=he.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,je,He)=>{if(!/function\s+__stx_setup_/.test(He))return Ie;return`<script${je}>${ie(He,ee)}</script>`})}if(R)he=Ue(he,{preserveHead:!0});if(re&&H)await J(E.filePath,he,Ae,ce);let{extractStreamBoundaries:at}=await import("./chunk-0ktg5dw9.js"),Ye=at(ee),rt=ee.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let ie=ee.streamBoundaries||{},Ie={...ce,autoShell:!1},je=Object.keys(rt).map((ke)=>({id:ke,render:async()=>{let ot=typeof ie[ke]==="function"?await ie[ke]():void 0;return z(rt[ke],{...ee,$boundary:ot},E.filePath,Ie,new Set)}})),He=new Set(je.map((ke)=>ke.id));Ye=[...(Ye||[]).filter((ke)=>!He.has(ke.id)),...je]}if(Ye&&Ye.length>0)Pe.add(E.pattern);else Ye=void 0;let Wt=Pt(ee),Vt=It(ee);if(H)F.set(E.filePath,{status:Wt,headers:Vt});return{route:E,content:he,status:Wt??se,headers:Vt,boundaries:Ye}}catch(z){return console.error(`${e.red}Error building ${e.bright}${E.pattern}${e.reset}:`,z),null}},Fe=8,ze=async()=>{let E=new Set(le.keys()),j=new Set(A.keys());le.clear(),A.clear();let z=n.prebuild===!1?k.filter((q)=>E.has(q.pattern)):k,Q=n.prebuild===!1?O.filter(({route:q})=>j.has(q.pattern)):O;for(let q=0;q<z.length;q+=Fe){let Oe=z.slice(q,q+Fe),we=await Promise.all(Oe.map((N)=>_(N)));for(let N of we)if(N)le.set(N.route.pattern,N)}for(let q=0;q<Q.length;q+=Fe){let Oe=Q.slice(q,q+Fe),we=await Promise.all(Oe.map(({route:N})=>_(N)));for(let N of we)if(N)A.set(N.route.pattern,N)}return le.size>0};if(console.log(`${e.blue}${n.prebuild===!1?"Rendering pages on request...":"Building pages..."}${e.reset}`),!(n.prebuild===!1?k.length+O.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await sn(u);let Xe=o;try{if(Xe=await Ve(o),Xe!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${Xe} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(s){let E=n.hmrPort||Xe+1;c=Tt({wsPort:E,verbose:!1}),f=c.start(E)}let Ot=(E,j)=>{let Q=`<script data-stx-route-params>(function(){var p=${JSON.stringify(j).replace(/</g,"\\u003C").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;if(E.includes("</head>"))return E.replace("</head>",`${Q}</head>`);if(E.includes("<body"))return E.replace(/<body([^>]*)>/,`<body$1>${Q}`);return Q+E};console.log(`${e.blue}Starting server...${e.reset}`);let At=Wr({port:Xe,hostname:n.hostname,async fetch(E){let j=new URL(E.url),z=n.stxOptions?.offline??g.offline;if(j.pathname===wo&&z?.enabled){if(!["GET","HEAD"].includes(E.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});return new Response(E.method==="HEAD"?null:xo(z,Jr()),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let Q=g?.publicDir||"public",q=te.join(u,Q,j.pathname),Oe=te.join(u,j.pathname),we=te.join(ve,j.pathname);if([q,Oe,we].some((H)=>w(H,u,S)))return new Response("Not Found",{status:404});let[N,J,W]=await Promise.all([me.promises.stat(q).catch(()=>null),me.promises.stat(Oe).catch(()=>null),me.promises.stat(we).catch(()=>null)]);if(N?.isFile()&&!w(q,u,S))return zt(q);if(J?.isFile()&&!w(Oe,u,S))return zt(Oe);if(W?.isFile()&&!w(we,u,S))return zt(we);if(j.pathname.startsWith("/_stx/component/")){let H=decodeURIComponent(j.pathname.slice(16));if(H)try{let re=`<${H} />`,Z={...buildConfig,autoShell:!1},se=await processDirectives(re,{},te.join(u,"components",`${H}.stx`),Z,new Set);return new Response(se,{headers:{"Content-Type":"text/html"}})}catch(re){return new Response(`<div class="stx-async-error">${re.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(j.pathname==="/_stx/img"){let{handleImageRequest:H}=await import("./chunk-ak04tgvw.js"),re=await H(E,{publicDir:te.join(u,Q),cacheDir:l(u,"cache","img")});if(re)return re}if(Y)try{let H=await Y.handleRequest(E);if(H.status!==404)return H}catch{}if(V[j.pathname])try{return await V[j.pathname](E)}catch(H){return new Response(JSON.stringify({error:H.message}),{status:500,headers:{"Content-Type":"application/json"}})}let pe=await C(E);if(pe)return pe;let X=lr(j.pathname,k);if(X){let H=le.get(X.route.pattern),re=Pe.has(X.route.pattern);if(!H||X.route.isDynamic&&Object.keys(X.params).length>0||re){let Z=await _(X.route,X.params);if(Z){if(H=Z,!X.route.isDynamic&&!re)le.set(X.route.pattern,Z)}}if(H){let Z=H.status??200,se=H.headers??{},ue=(X.route.filePath?mt(await Bun.file(X.route.filePath).text().catch(()=>"")):null)??{};if(ue.validate){if(!await ue.validate({params:X.params})){let De=await ne(404);if(De){let ee=De;if(ee=await y(ee,u),s)ee=Ne(ee,f);return new Response(ee,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(ue.middleware){let Le=_t(j.pathname,X.params,ue,j.search),De=Ct(Le,null,E,{isServer:!0}),ee=await Et(ue.middleware,De);if(ee.redirect){let Ae=ee.redirect.path,he=ee.redirect.options.redirectCode||302,at=new Headers(ee.responseHeaders);return at.set("Location",Ae),new Response(null,{status:he,headers:at})}if(ee.abort){let{statusCode:Ae,message:he}=ee.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${Ae}</title></head><body><h1>Error ${Ae}</h1><p>${he}</p></body></html>`,{status:Ae,headers:{"Content-Type":"text/html"}})}if(Object.keys(ee.state).length>0){let Ae=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(ee.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;H.content=H.content.replace("</head>",`${Ae}</head>`)}}let U=H.content;if(R&&Gi(E)){let Le=Ze(U),De=ye(U),ee=U.match(/<title[^>]*>([\s\S]*?)<\/title>/i),Ae=ee?Tn(ee[1].trim()):"";if(Object.keys(X.params).length>0)U=Ot(U,X.params);U=await y(U,u);let he=g?.router?.container||"main";return U=Ce(U,he,!0),new Response(U,{status:Z,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":De?"true":"false",...Ae&&{"X-STX-Title":encodeURIComponent(Ae)},[za]:Jr(),...M(),"Cache-Control":dt}})}if(R)U=Br(R,U);if(Object.keys(X.params).length>0)U=Ot(U,X.params);if(U=await y(U,u),s)U=Ne(U,f);if(n.native)if(U.includes("<head>"))U=U.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else U="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+U;if(n.titlebarHidden)if(U.includes("<head>"))U=U.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else U=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${U}`;if(H.boundaries&&H.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:De}=await import("./chunk-0ktg5dw9.js");return De(Le(U,H.boundaries,{timeoutMs:30000}),{status:Z,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(U,{status:Z,headers:{"Content-Type":"text/html",...M(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...se}})}}if(O.length>0){let H=O.map((Z)=>Z.route),re=lr(j.pathname,H);if(re){let Z=A.get(re.route.pattern);if(!Z||re.route.isDynamic){let se=await _(re.route,re.params);if(se){if(Z=se,!re.route.isDynamic)A.set(re.route.pattern,se)}}if(Z){let se=Z.content;if(R)se=Br(R,se);if(Object.keys(re.params).length>0)se=Ot(se,re.params);if(se=await y(se,u),s)se=Ne(se,f);return new Response(se,{status:Z.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:Z}of L)if(Z!=="/"&&j.pathname.startsWith(Z)){let se=A.get(Z)||A.get(Z+"/");if(!se){let ue=O.find(({route:U})=>U.pattern===Z||U.pattern===`${Z}/`);if(ue){let U=await _(ue.route);if(U)se=U,A.set(ue.route.pattern,U)}}if(se){let ue=se.content;if(R)ue=Br(R,ue);if(ue=await y(ue,u),s)ue=Ne(ue,f);return new Response(ue,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(wt(j.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let We=le.get("/");if(We){let H=We.content;if(H=await y(H,u),s)H=Ne(H,f);if(n.native)if(H.includes("<head>"))H=H.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 H="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+H;return new Response(H,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let ce=await ne(404);if(ce){let H=ce;if(H=await y(H,u),s)H=Ne(H,f);return new Response(H,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(E){let j=await ne(500);if(j)return new Response(j,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${E}
|
|
1430
|
-
${
|
|
1427
|
+
${e.bright}\u2192 ${e.cyan}http://localhost:${x}/${e.reset}`),console.log(`
|
|
1428
|
+
${e.yellow}Routes:${e.reset}`);let S=new Set(f.map((w)=>w.routeTemplate)),T=Object.entries(u).filter(([w])=>!S.has(w)).sort(([w],[b])=>w.localeCompare(b)).map(([w,b])=>({route:w==="/"?"/":w,filePath:Ee.relative(process.cwd(),b.filePath),fileType:b.fileType}));for(let w of f){let b=w.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");T.push({route:b,filePath:Ee.relative(process.cwd(),w.filePath),fileType:"stx"})}if(T.sort((w,b)=>w.route.localeCompare(b.route)),T.forEach((w,b)=>{let _=b===T.length-1?"\u2514\u2500 ":"\u251C\u2500 ",E=w.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${_}${w.route}${e.reset} \u2192 ${e.bright}${w.filePath}${e.reset} ${E}`)}),console.log(`
|
|
1429
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(v.url.toString(),()=>{if(d)Ke.watch(c,{recursive:!0}).close();v.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let w=Ke.watch(c,{recursive:!0},async(b,k)=>{if(!k)return;if(k.endsWith(".stx")||k.endsWith(".js")||k.endsWith(".ts")||k.endsWith(".md"))console.log(`${e.yellow}File ${e.bright}${k}${e.yellow} changed, rebuilding...${e.reset}`),Ge.clear(),fe(),await g()});process.on("SIGINT",()=>{w.close(),v.stop(),process.exit(0)})}return!0}function an(t){return String(t??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}var{serve:Wr}=globalThis.Bun;import me from"fs";import te from"path";async function ln(t){try{return pn(await Bun.file(t).text())}catch{return}}function zt(t){let n=Bun.file(t),o=te.extname(t).toLowerCase(),d={".html":"text/html",".css":"text/css",".js":"text/javascript",".json":"application/json",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"},c=[".js",".css",".json"].includes(o)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(n,{headers:{"Content-Type":d[o]||"application/octet-stream",...c}})}async function Dr(t=".",n={}){let o=n.port||3000,d=n.watch!==!1,s=n.hotReload!==!1&&d,c=null,u=n.hmrPort||o+1,f=te.resolve(t),{loadStxConfig:g}=await import("./chunk-y9335aa8.js"),h=await g(f),{createServerApi:x,isServerApiSource:v}=await import("./chunk-tef5t0b2.js"),S=n.stxOptions?.serverApi??h.serverApi,T=await x(f,S),w=h.root&&h.root!=="."?te.join(f,h.root):f,b=n.pagesDir||h.pagesDir||"pages",k=te.join(w,b);if(!me.existsSync(k)&&!h._layerPageDirs?.some((O)=>me.existsSync(O)))return console.error(`${e.red}Error: No '${b}' directory found${e.reset}`),console.log(`${e.dim}Looked in: ${e.bright}${k}${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 ${b}/index.stx for the homepage.${e.reset}`),!1;let _=G(w,{pagesDir:b,pagesDirs:h._layerPageDirs?[k,...h._layerPageDirs.slice(1)]:void 0});if(_.length===0)return console.error(`${e.red}Error: No page files found in ${e.bright}${k}${e.reset}`),!1;console.log(`${e.blue}Found ${e.bright}${_.length}${e.blue} routes${e.reset}`);let E=h?._pluginPageDirs||[],R=[];for(let{dir:O,prefix:j}of E)if(me.existsSync(O)){let z=G(te.dirname(O),{pagesDir:te.basename(O)});for(let Q of z){let q=j==="/"?Q.pattern:`${j}${Q.pattern==="/"?"":Q.pattern}`;R.push({route:{...Q,pattern:q},prefix:j})}if(z.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${z.length}${e.blue} routes at ${e.cyan}${j}${e.reset}`)}let A=new Map,C=null,D=null;if(n.stxOptions?.shell!==!1){if(D=await Ki(f,n.stxOptions?.shell),D){if(C=await to(D,n.stxOptions||{}),C)console.log(`${e.blue}Using app shell: ${e.bright}${te.relative(f,D)}${e.reset} ${e.dim}(deprecated: use layouts/default.stx instead)${e.reset}`)}}xt(),await kt(f);let I=St();if(I.length>0)console.log(`${e.blue}Loaded ${e.bright}${I.length}${e.blue} middleware: ${e.dim}${I.join(", ")}${e.reset}`);let V={},Y=null;try{let{loadStxConfig:O}=await import("./chunk-y9335aa8.js"),j=await O(f);if(j?.apiRouter)Y=j?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(j?.apiRoutes){V=j.apiRoutes;let z=Object.keys(V).length;if(z>0)console.log(`${e.blue}Loaded ${e.bright}${z} API route${z>1?"s":""}${e.reset}`)}if(j?.broadcasting?.enabled)try{let{startBroadcasting:z,loadChannels:Q}=await import("./chunk-79sjdpfy.js"),q=j.broadcasting;await z(q);let Oe=q.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Oe}/ws${e.reset}`);let we=te.join(process.cwd(),"channels.ts");if(me.existsSync(we))try{let N=await Q(we);console.log(`${e.blue}Loaded ${e.bright}${N} broadcast channel${N!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(N){console.warn(`${e.yellow}Failed to load channels.ts: ${N.message}${e.reset}`)}}catch(z){console.warn(`${e.yellow}Broadcasting failed to start: ${z.message}${e.reset}`)}}catch{}let ve=l(f,"output");me.mkdirSync(ve,{recursive:!0});let le=new Map,Pe=new Set,ne=async(O)=>{let j=ys(k,O);if(!j)return null;try{let z=await Bun.build({entrypoints:[j],outdir:ve,plugins:[nt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!z.success)return null;let Q=z.outputs.find((q)=>q.path.endsWith(".html"));if(!Q)return null;return await Bun.file(Q.path).text()}catch{return null}},F=new Map,L=async(O,j)=>{try{let{processDirectives:z,extractVariables:Q,defaultConfig:q,loadStxConfig:Oe,injectRouterScript:we}=await import("./chunk-y9335aa8.js"),{checkCache:N,cacheTemplate:J,readFileCached:W,templateCache:pe}=await import("./chunk-ncq1bzwh.js"),X=await Oe(f),We=(ie)=>{if(!ie)return ie;if(te.isAbsolute(ie))return ie;return te.resolve(f,ie)},ce={...q,...X,...n.stxOptions,autoShell:!0};if(n.debugDirectives)ce.debug=!0;ce.partialsDir=We(ce.partialsDir),ce.componentsDir=We(ce.componentsDir),ce.layoutsDir=We(ce.layoutsDir),ce.storesDir=We(ce.storesDir||"stores"),ce.cachePath=We(ce.cachePath)??l(f,"cache");let H=!j&&!n.profile,re=ce.cache!==!1;if(re&&H){let ie=pe.get(O.filePath);if(ie)try{if((await me.promises.stat(O.filePath)).mtime.getTime()<=ie.mtime){let He=!0;for(let ke of ie.dependencies){if(!me.existsSync(ke)){He=!1;break}if((await me.promises.stat(ke)).mtime.getTime()>ie.mtime){He=!1;break}}if(He){let ke=ie.output;if(C)ke=Ue(ke,{preserveHead:!0});let ot=F.get(O.filePath);return{route:O,content:ke,status:ot?.status??await ln(O.filePath),headers:ot?.headers}}}}catch{}let Ie=await N(O.filePath,ce);if(Ie){let je=Ie;if(C)je=Ue(je,{preserveHead:!0});let He=F.get(O.filePath);return{route:O,content:je,status:He?.status??await ln(O.filePath),headers:He?.headers}}}let Z=re?await W(O.filePath):await Bun.file(O.filePath).text(),se=pn(Z),{classifyAllScripts:ue}=await import("./chunk-y9335aa8.js"),U=ue(Z),Le=U.server.map((ie)=>ie.content),De=Z;for(let ie of U.server)De=De.replace(ie.fullTag,"");let ee={__filename:O.filePath,__dirname:te.dirname(O.filePath),__stx_options:ce,params:j??{},__stx_runtime_head:{}};for(let ie of Le)try{await Q(ie,ee,O.filePath)}catch(Ie){if(n.stxOptions?.debug)console.error("[stx] variable extraction error",O.filePath,Ie?.message||Ie)}let Ae=new Set,he;if(n.profile){let ie=performance.now();he=await z(De,ee,O.filePath,ce,Ae);let Ie=performance.now()-ie,je=te.relative(f,O.filePath)||O.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else he=await z(De,ee,O.filePath,ce,Ae);if(!C)he=await we(he,{router:ce.router});{let{interpolateScriptExpressions:ie}=await import("./chunk-ke2t93w6.js");he=he.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,(Ie,je,He)=>{if(!/function\s+__stx_setup_/.test(He))return Ie;return`<script${je}>${ie(He,ee)}</script>`})}if(C)he=Ue(he,{preserveHead:!0});if(re&&H)await J(O.filePath,he,Ae,ce);let{extractStreamBoundaries:at}=await import("./chunk-9gdz941b.js"),Ye=at(ee),rt=ee.__streamTemplates;if(rt&&typeof rt==="object"&&Object.keys(rt).length>0){let ie=ee.streamBoundaries||{},Ie={...ce,autoShell:!1},je=Object.keys(rt).map((ke)=>({id:ke,render:async()=>{let ot=typeof ie[ke]==="function"?await ie[ke]():void 0;return z(rt[ke],{...ee,$boundary:ot},O.filePath,Ie,new Set)}})),He=new Set(je.map((ke)=>ke.id));Ye=[...(Ye||[]).filter((ke)=>!He.has(ke.id)),...je]}if(Ye&&Ye.length>0)Pe.add(O.pattern);else Ye=void 0;let Wt=Pt(ee),Vt=It(ee);if(H)F.set(O.filePath,{status:Wt,headers:Vt});return{route:O,content:he,status:Wt??se,headers:Vt,boundaries:Ye}}catch(z){return console.error(`${e.red}Error building ${e.bright}${O.pattern}${e.reset}:`,z),null}},Fe=8,ze=async()=>{let O=new Set(le.keys()),j=new Set(A.keys());le.clear(),A.clear();let z=n.prebuild===!1?_.filter((q)=>O.has(q.pattern)):_,Q=n.prebuild===!1?R.filter(({route:q})=>j.has(q.pattern)):R;for(let q=0;q<z.length;q+=Fe){let Oe=z.slice(q,q+Fe),we=await Promise.all(Oe.map((N)=>L(N)));for(let N of we)if(N)le.set(N.route.pattern,N)}for(let q=0;q<Q.length;q+=Fe){let Oe=Q.slice(q,q+Fe),we=await Promise.all(Oe.map(({route:N})=>L(N)));for(let N of we)if(N)A.set(N.route.pattern,N)}return le.size>0};if(console.log(`${e.blue}${n.prebuild===!1?"Rendering pages on request...":"Building pages..."}${e.reset}`),!(n.prebuild===!1?_.length+R.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await sn(f);let Xe=o;try{if(Xe=await Ve(o),Xe!==o)console.log(`${e.yellow}Port ${o} is busy, using port ${Xe} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(s){let O=n.hmrPort||Xe+1;c=Tt({wsPort:O,verbose:!1}),u=c.start(O)}let Ot=(O,j)=>{let Q=`<script data-stx-route-params>(function(){var p=${JSON.stringify(j).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(O.includes("</head>"))return O.replace("</head>",`${Q}</head>`);if(O.includes("<body"))return O.replace(/<body([^>]*)>/,`<body$1>${Q}`);return Q+O};console.log(`${e.blue}Starting server...${e.reset}`);let At=Wr({port:Xe,hostname:n.hostname,async fetch(O){let j=new URL(O.url),z=n.stxOptions?.offline??h.offline;if(j.pathname===wo&&z?.enabled){if(!["GET","HEAD"].includes(O.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});return new Response(O.method==="HEAD"?null:xo(z,Jr()),{headers:{"Content-Type":"application/javascript; charset=utf-8","Cache-Control":"no-store","Service-Worker-Allowed":"/"}})}let Q=h?.publicDir||"public",q=te.join(f,Q,j.pathname),Oe=te.join(f,j.pathname),we=te.join(ve,j.pathname);if([q,Oe,we].some((H)=>v(H,f,S)))return new Response("Not Found",{status:404});let[N,J,W]=await Promise.all([me.promises.stat(q).catch(()=>null),me.promises.stat(Oe).catch(()=>null),me.promises.stat(we).catch(()=>null)]);if(N?.isFile()&&!v(q,f,S))return zt(q);if(J?.isFile()&&!v(Oe,f,S))return zt(Oe);if(W?.isFile()&&!v(we,f,S))return zt(we);if(j.pathname.startsWith("/_stx/component/")){let H=decodeURIComponent(j.pathname.slice(16));if(H)try{let re=`<${H} />`,Z={...buildConfig,autoShell:!1},se=await processDirectives(re,{},te.join(f,"components",`${H}.stx`),Z,new Set);return new Response(se,{headers:{"Content-Type":"text/html"}})}catch(re){return new Response(`<div class="stx-async-error">${re.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(j.pathname==="/_stx/img"){let{handleImageRequest:H}=await import("./chunk-ak04tgvw.js"),re=await H(O,{publicDir:te.join(f,Q),cacheDir:l(f,"cache","img")});if(re)return re}if(Y)try{let H=await Y.handleRequest(O);if(H.status!==404)return H}catch{}if(V[j.pathname])try{return await V[j.pathname](O)}catch(H){return new Response(JSON.stringify({error:H.message}),{status:500,headers:{"Content-Type":"application/json"}})}let pe=await T(O);if(pe)return pe;let X=lr(j.pathname,_);if(X){let H=le.get(X.route.pattern),re=Pe.has(X.route.pattern);if(!H||X.route.isDynamic&&Object.keys(X.params).length>0||re){let Z=await L(X.route,X.params);if(Z){if(H=Z,!X.route.isDynamic&&!re)le.set(X.route.pattern,Z)}}if(H){let Z=H.status??200,se=H.headers??{},ue=(X.route.filePath?mt(await Bun.file(X.route.filePath).text().catch(()=>"")):null)??{};if(ue.validate){if(!await ue.validate({params:X.params})){let De=await ne(404);if(De){let ee=De;if(ee=await y(ee,f),s)ee=Ne(ee,u);return new Response(ee,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(ue.middleware){let Le=_t(j.pathname,X.params,ue,j.search),De=Ct(Le,null,O,{isServer:!0}),ee=await Et(ue.middleware,De);if(ee.redirect){let Ae=ee.redirect.path,he=ee.redirect.options.redirectCode||302,at=new Headers(ee.responseHeaders);return at.set("Location",Ae),new Response(null,{status:he,headers:at})}if(ee.abort){let{statusCode:Ae,message:he}=ee.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${Ae}</title></head><body><h1>Error ${Ae}</h1><p>${he}</p></body></html>`,{status:Ae,headers:{"Content-Type":"text/html"}})}if(Object.keys(ee.state).length>0){let Ae=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(ee.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;H.content=H.content.replace("</head>",`${Ae}</head>`)}}let U=H.content;if(C&&Gi(O)){let Le=Ze(U),De=ye(U),ee=U.match(/<title[^>]*>([\s\S]*?)<\/title>/i),Ae=ee?Tn(ee[1].trim()):"";if(Object.keys(X.params).length>0)U=Ot(U,X.params);U=await y(U,f);let he=h?.router?.container||"main";return U=Ce(U,he,!0),new Response(U,{status:Z,headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Le.layout,"X-STX-Layout-Group":Le.group,"X-STX-Runtime":De?"true":"false",...Ae&&{"X-STX-Title":encodeURIComponent(Ae)},[za]:Jr(),...M(),"Cache-Control":dt}})}if(C)U=Br(C,U);if(Object.keys(X.params).length>0)U=Ot(U,X.params);if(U=await y(U,f),s)U=Ne(U,u);if(n.native)if(U.includes("<head>"))U=U.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else U="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+U;if(n.titlebarHidden)if(U.includes("<head>"))U=U.replace("<head>","<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script>");else U=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${U}`;if(H.boundaries&&H.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:De}=await import("./chunk-9gdz941b.js");return De(Le(U,H.boundaries,{timeoutMs:30000}),{status:Z,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(U,{status:Z,headers:{"Content-Type":"text/html",...M(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...se}})}}if(R.length>0){let H=R.map((Z)=>Z.route),re=lr(j.pathname,H);if(re){let Z=A.get(re.route.pattern);if(!Z||re.route.isDynamic){let se=await L(re.route,re.params);if(se){if(Z=se,!re.route.isDynamic)A.set(re.route.pattern,se)}}if(Z){let se=Z.content;if(C)se=Br(C,se);if(Object.keys(re.params).length>0)se=Ot(se,re.params);if(se=await y(se,f),s)se=Ne(se,u);return new Response(se,{status:Z.status??200,headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:Z}of E)if(Z!=="/"&&j.pathname.startsWith(Z)){let se=A.get(Z)||A.get(Z+"/");if(!se){let ue=R.find(({route:U})=>U.pattern===Z||U.pattern===`${Z}/`);if(ue){let U=await L(ue.route);if(U)se=U,A.set(ue.route.pattern,U)}}if(se){let ue=se.content;if(C)ue=Br(C,ue);if(ue=await y(ue,f),s)ue=Ne(ue,u);return new Response(ue,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}if(wt(j.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let We=le.get("/");if(We){let H=We.content;if(H=await y(H,f),s)H=Ne(H,u);if(n.native)if(H.includes("<head>"))H=H.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 H="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+H;return new Response(H,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let ce=await ne(404);if(ce){let H=ce;if(H=await y(H,f),s)H=Ne(H,u);return new Response(H,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(O){let j=await ne(500);if(j)return new Response(j,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${O}
|
|
1430
|
+
${O.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});if(console.clear(),console.log(`
|
|
1431
1431
|
${e.blue}stx${e.reset} ${e.green}${process.env.stx_VERSION||"v0.0.10"}${e.reset} ${e.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${e.reset}`),console.log(`
|
|
1432
|
-
${e.bright}\u2192 ${e.cyan}http://localhost:${Xe}/${e.reset}`),s)console.log(`${e.dim} HMR: ws://localhost:${
|
|
1433
|
-
${e.yellow}Routes:${e.reset}`);let Dt=[...bs(
|
|
1434
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(At.url.toString(),()=>{if(c)st();At.stop()}),n.native){let
|
|
1435
|
-
`).map((
|
|
1436
|
-
`).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Kr(t,n=!1,o){let d=it.basename(t,".stx"),s=await Vr(t),c=await qr(t),
|
|
1437
|
-
`);
|
|
1438
|
-
${
|
|
1439
|
-
/>`}return{name:d,path:t,description:c,props:s,example:
|
|
1440
|
-
`).map((
|
|
1432
|
+
${e.bright}\u2192 ${e.cyan}http://localhost:${Xe}/${e.reset}`),s)console.log(`${e.dim} HMR: ws://localhost:${u}${e.reset}`);console.log(`
|
|
1433
|
+
${e.yellow}Routes:${e.reset}`);let Dt=[...bs(_,f)];for(let{route:O}of R)Dt.push(`${O.pattern}`);if(Dt.forEach((O,j)=>{let Q=j===Dt.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${Q}${e.reset}${O}`)}),console.log(`
|
|
1434
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(At.url.toString(),()=>{if(c)st();At.stop()}),n.native){let O,j=te.join(k,"index.stx");if(me.existsSync(j)){let Q=await Bun.file(j).text();O=ht(Q)}let z=h?.app?.window??{};await Qe(Xe,{title:h?.app?.head?.title||te.basename(f)||"stx App",width:z.width,height:z.height,darkMode:z.darkMode,hotReload:z.hotReload,titlebarHidden:z.titlebarHidden??n.titlebarHidden===!0,nativeSidebar:!!O,sidebarConfig:O})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let O=(N)=>N.startsWith("public/")||N.startsWith("public\\"),j=(N)=>{let J=N.toLowerCase();return J.endsWith(".stx")||J.endsWith(".html")||J.endsWith(".md")},z=new Map,Q=()=>{let N=new Set([f,...h._layerGraph?.layers.map((J)=>J.root)??[],...h._layerGraph?.configDependencies.map((J)=>te.dirname(J))??[]].filter((J)=>me.existsSync(J)).map((J)=>me.realpathSync(J)));for(let J of h._layerGraph?.layers??[])for(let W of Object.values(J.resources)){if(!me.existsSync(W))continue;let pe=me.realpathSync(W);if(![...N].some((X)=>pe===X||pe.startsWith(`${X}${te.sep}`)))N.add(pe)}for(let[J,W]of z)if(!N.has(J))W.close(),z.delete(J);for(let J of N)if(!z.has(J)&&me.existsSync(J))z.set(J,me.watch(J,{recursive:!0},(W,pe)=>{Oe(J,W,pe).catch((X)=>console.error("[stx] Layer rebuild failed:",X))}))},q=Promise.resolve(),Oe=(N,J,W)=>(q=q.catch(()=>{}).then(()=>we(N,J,W)),q),we=async(N,J,W)=>{if(!W||vt(W))return;if(bt(W)){if(h._layerGraph){let pe=await g(f);Object.assign(h,pe),_.splice(0,_.length,...G(w,{pagesDir:b,pagesDirs:pe._layerPageDirs?[k,...pe._layerPageDirs.slice(1)]:void 0})),Q()}if(O(W)){if(console.log(`${e.cyan}${W} changed${e.reset}`),s&&c)c.reload(W)}else if(j(W)){console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),Ge.clear(),fe();try{let{invalidateFileCache:pe,templateCache:X}=await import("./chunk-ncq1bzwh.js");pe(te.resolve(N,W)),X.delete(te.resolve(N,W))}catch{}if(D&&W){if(te.resolve(N,W)===D||te.basename(D)===W){let X=await to(D,n.stxOptions||{});if(X)C=X}}if(await ze(),await tr(f),s&&c)c.reload(W)}else{console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),Ge.clear(),fe();try{let{invalidateFileCache:pe,templateCache:X}=await import("./chunk-ncq1bzwh.js");pe(te.resolve(N,W)),X.delete(te.resolve(N,W))}catch{}if(await ze(),s&&c)c.reload(W)}}else if(yt(W)){if(console.log(`${e.cyan}CSS ${W} changed${e.reset}`),s&&c)c.updateCss(W)}};Q(),process.on("SIGINT",()=>{for(let N of z.values())N.close();if(c)st();At.stop(),process.exit(0)})}return!0}import Nt from"fs";import it from"path";async function Vr(t){try{let o=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!o)return[];let d=o[1],s=[],c=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,u;while((u=c.exec(d))!==null){let f=u[1],g=u[2]||u[3]||u[4];if(!g)continue;let h={name:g},x=f.match(/@type\s+\{([^}]+)\}/i);if(x)h.type=x[1].trim();if(f.match(/@required/i))h.required=!0;let S=f.match(/@default\s+(.+?)(?:\s+|$)/i);if(S)h.default=S[1].trim();let T=f.split(`
|
|
1435
|
+
`).map((w)=>w.trim().replace(/^\*\s*/,"")).filter((w)=>!w.startsWith("@")&&w.length>0);h.description=T.join(" ").trim(),s.push(h)}if(s.length===0){let f=d.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(f){let h=f[1].split(",").map((x)=>x.trim()).filter(Boolean);for(let x of h){let[v]=x.split(":").map((S)=>S.trim());if(v)s.push({name:v})}}}return s}catch(n){return console.error(`Error extracting props from ${t}:`,n),[]}}async function qr(t){try{let n=await Bun.file(t).text(),o=n.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||n.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(o)return o[1].split(`
|
|
1436
|
+
`).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Kr(t,n=!1,o){let d=it.basename(t,".stx"),s=await Vr(t),c=await qr(t),u="";if(n&&o)u=`<${o}></${o}>`;else{let f=s.map((g)=>{if(g.type==="boolean")return`:${g.name}="true"`;return`${g.name}="value"`}).join(`
|
|
1437
|
+
`);u=`<${d}
|
|
1438
|
+
${f}
|
|
1439
|
+
/>`}return{name:d,path:t,description:c,props:s,example:u,isWebComponent:n,tag:o}}async function dn(t){try{if(!await r(t))return console.warn(`Components directory does not exist: ${t}`),[];let n=await Nt.promises.readdir(t,{withFileTypes:!0}),o=[];for(let d of n){let s=it.join(t,d.name);if(d.isDirectory()){let c=await dn(s);o.push(...c)}else if(d.isFile()&&d.name.endsWith(".stx"))o.push(s)}return o}catch(n){return console.error(`Error finding component files in ${t}:`,n),[]}}async function Xr(t,n){try{if(!await r(t))return[];let o=await dn(t),d=[],s=new Map;if(n?.components?.length)for(let c of n.components)s.set(c.file,c);for(let c of o){let u=s.get(c),f=!!u,g=u?.tag,h=await Kr(c,f,g);d.push(h)}return d}catch(o){return console.error("Error generating component docs:",o),[]}}async function Gr(t){try{if(!await r(t))return[];let n=await Nt.promises.readdir(t,{withFileTypes:!0}),o=[];for(let d of n){if(!d.isFile()||!d.name.endsWith(".stx"))continue;let s=it.join(t,d.name),c=await Bun.file(s).text(),u=it.basename(s,".stx"),f=c.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||c.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//),g=f?f[1].split(`
|
|
1440
|
+
`).map((b)=>b.trim().replace(/^\*\s*/,"")).join(" ").trim():"",h=/@component\(\s*['"]([^'"]+)['"]/g,x=/<([A-Z][a-zA-Z0-9]*|[a-z]+-[a-z0-9-]+)(?:\s[^>]*)?\/?>|\{\{\s*slot\s*\}\}/g,v=new Set,S;while((S=h.exec(c))!==null)v.add(S[1]);while((S=x.exec(c))!==null)if(S[1]&&S[1]!=="slot")v.add(S[1]);let T=/@([a-z]+)(?:\s*\(|\s+|$)/g,w=new Set;while((S=T.exec(c))!==null)w.add(S[1]);o.push({name:u,path:s,description:g,components:[...v],directives:[...w]})}return o}catch(n){return console.error("Error generating template docs:",n),[]}}async function Yr(t=[]){try{let n=[{name:"if",description:"Conditionally render content based on a condition",hasEndTag:!0,example:`@if(user.isLoggedIn)
|
|
1441
1441
|
<p>Welcome, {{ user.name }}!</p>
|
|
1442
1442
|
@endif`},{name:"else",description:"Provides an alternative if a condition is not met",hasEndTag:!1,example:`@if(user.isLoggedIn)
|
|
1443
1443
|
<p>Welcome back!</p>
|
|
@@ -1473,7 +1473,7 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(At.
|
|
|
1473
1473
|
|
|
1474
1474
|
`,s+=`| Name | Type | Required | Default | Description |
|
|
1475
1475
|
`,s+=`| ---- | ---- | -------- | ------- | ----------- |
|
|
1476
|
-
`;for(let
|
|
1476
|
+
`;for(let u of c.props)s+=`| ${u.name} | ${u.type||"any"} | ${u.required?"Yes":"No"} | ${u.default||"-"} | ${u.description||"-"} |
|
|
1477
1477
|
`;s+=`
|
|
1478
1478
|
`}if(c.example)s+=`#### Example
|
|
1479
1479
|
|
|
@@ -1552,12 +1552,12 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(At.
|
|
|
1552
1552
|
<th>Description</th>
|
|
1553
1553
|
</tr>
|
|
1554
1554
|
</thead>
|
|
1555
|
-
<tbody>`;for(let
|
|
1556
|
-
<td>${
|
|
1557
|
-
<td>${
|
|
1558
|
-
<td>${
|
|
1559
|
-
<td>${
|
|
1560
|
-
<td>${
|
|
1555
|
+
<tbody>`;for(let u of c.props)s+=`<tr>
|
|
1556
|
+
<td>${u.name}</td>
|
|
1557
|
+
<td>${u.type||"any"}</td>
|
|
1558
|
+
<td>${u.required?"Yes":"No"}</td>
|
|
1559
|
+
<td>${u.default||"-"}</td>
|
|
1560
|
+
<td>${u.description||"-"}</td>
|
|
1561
1561
|
</tr>`;s+="</tbody></table>"}if(c.example)s+="<h4>Example</h4>",s+=`<pre><code>${c.example.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}</code></pre>`}}if(n.length>0){s+="<h2>Templates</h2>";for(let c of n){if(s+=`<h3>${c.name}</h3>`,c.description)s+=`<p>${c.description}</p>`;if(c.components&&c.components.length>0)s+=`<p><strong>Components Used:</strong> ${c.components.join(", ")}</p>`;if(c.directives&&c.directives.length>0)s+=`<p><strong>Directives Used:</strong> ${c.directives.join(", ")}</p>`}}if(o.length>0){s+="<h2>Directives</h2>",s+=`<table>
|
|
1562
1562
|
<thead>
|
|
1563
1563
|
<tr>
|
|
@@ -1570,18 +1570,18 @@ Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),qe(At.
|
|
|
1570
1570
|
<td>@${c.name}</td>
|
|
1571
1571
|
<td>${c.description||"-"}</td>
|
|
1572
1572
|
<td>${c.hasEndTag?"Yes":"No"}</td>
|
|
1573
|
-
</tr>`;s+="</tbody></table>";for(let c of o)if(c.example)s+=`<h3>@${c.name}</h3>`,s+=`<p>${c.description||""}</p>`,s+="<h4>Example</h4>",s+=`<pre><code>${c.example.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}</code></pre>`}return s+="</body></html>",s}function eo(t=[],n=[],o=[],d){return JSON.stringify({components:t,templates:n,directives:o,extraContent:d||""},null,2)}async function no(t){try{let{componentsDir:n,templatesDir:o,webComponentsConfig:d,customDirectives:s,config:c}=t;if(!c.enabled)return!1;let
|
|
1573
|
+
</tr>`;s+="</tbody></table>";for(let c of o)if(c.example)s+=`<h3>@${c.name}</h3>`,s+=`<p>${c.description||""}</p>`,s+="<h4>Example</h4>",s+=`<pre><code>${c.example.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}</code></pre>`}return s+="</body></html>",s}function eo(t=[],n=[],o=[],d){return JSON.stringify({components:t,templates:n,directives:o,extraContent:d||""},null,2)}async function no(t){try{let{componentsDir:n,templatesDir:o,webComponentsConfig:d,customDirectives:s,config:c}=t;if(!c.enabled)return!1;let u=c.outputDir||"docs";if(await Nt.promises.mkdir(u,{recursive:!0}),console.log("Generating documentation..."),n)console.log(`Components directory: ${n}`);if(o)console.log(`Templates directory: ${o}`);console.log(`Output directory: ${u}`);let f=[];if(c.components!==!1&&n)console.log("Generating component documentation..."),f=await Xr(n,d),console.log(`Found ${f.length} components`);let g=[];if(c.templates!==!1&&o)console.log("Generating template documentation..."),g=await Gr(o),console.log(`Found ${g.length} templates`);let h=[];if(c.directives!==!1)console.log("Generating directive documentation..."),h=await Yr(s),console.log(`Found ${h.length} directives`);let x=c.format||"markdown",v=c.extraContent,S="",T="";switch(x){case"markdown":S=Qr(f,g,h,v),T="md";break;case"html":S=Zr(f,g,h,v),T="html";break;case"json":S=eo(f,g,h,v),T="json";break;default:throw Error(`Unsupported documentation format: ${x}`)}let w=it.join(u,`stx-docs.${T}`);return await Bun.write(w,S),console.log(`Documentation generated: ${w}`),!0}catch(n){return console.error("Error generating documentation:",n),!1}}async function Li(t){let n={enabled:!0,outputDir:t.output||"docs",format:t.format||"markdown",components:t.components!==!1,templates:t.templates!==!1,directives:t.directives!==!1,extraContent:t.extraContent},o=t.componentsDir||P.componentsDir,d=t.templatesDir||".";return no({componentsDir:o,templatesDir:d,webComponentsConfig:P.webComponents,customDirectives:P.customDirectives,config:n})}var fn={indentSize:2,useTabs:!1,maxLineLength:120,normalizeWhitespace:!0,sortAttributes:!1,trimTrailingWhitespace:!0};function Ks(t,n={}){let o={...fn,...n};if(t.trim()==="")return`
|
|
1574
1574
|
`;let d=t;if(o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=so(d,o),d=lo(d,o),d=io(d,o),o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,""),d=d.replace(/(\S)[ \t]+(<\/[^>]+>)/g,"$1$2");if(d=d.replace(/\r\n/g,`
|
|
1575
1575
|
`).replace(/\r/g,`
|
|
1576
1576
|
`),!d.endsWith(`
|
|
1577
1577
|
`))d+=`
|
|
1578
1578
|
`;return d}function ji(t,n={}){let o={...fn,...n};if(t.trim()==="")return`
|
|
1579
|
-
`;let d=t;if(d=d.replace(/^( *)```(html|stx)\n([\s\S]*?)^( *)```/gm,(s,c,f,
|
|
1580
|
-
`),
|
|
1581
|
-
`),
|
|
1582
|
-
`).map((
|
|
1583
|
-
`);return`${c}\`\`\`${
|
|
1584
|
-
${
|
|
1579
|
+
`;let d=t;if(d=d.replace(/^( *)```(html|stx)\n([\s\S]*?)^( *)```/gm,(s,c,u,f,g)=>{let h=f.split(`
|
|
1580
|
+
`),x=h.filter((b)=>b.trim().length>0);if(x.length===0)return s;let v=Math.min(...x.map((b)=>{let k=b.match(/^( *)/);return k?k[1].length:0})),S=h.map((b)=>{if(b.trim().length===0)return"";return b.substring(v)}).join(`
|
|
1581
|
+
`),w=Ks(S,o).trimEnd().split(`
|
|
1582
|
+
`).map((b)=>{if(b.trim().length===0)return"";return c+b}).join(`
|
|
1583
|
+
`);return`${c}\`\`\`${u}
|
|
1584
|
+
${w}
|
|
1585
1585
|
${c}\`\`\``}),o.trimTrailingWhitespace)d=d.replace(/[ \t]+$/gm,"");if(d=d.replace(/\r\n/g,`
|
|
1586
1586
|
`).replace(/\r/g,`
|
|
1587
1587
|
`),!d.endsWith(`
|
|
@@ -1594,16 +1594,16 @@ $1
|
|
|
1594
1594
|
$1
|
|
1595
1595
|
`),n=n.replace(/(@(?:csrf|method|include|extends|yield|stack|vite|asset)(?:\([^)]*\))?)/g,`
|
|
1596
1596
|
$1
|
|
1597
|
-
`),n=n.replace(/(?<=>)(<(?!\/)[^>]+>)/g,(s,c,f
|
|
1598
|
-
${s}`}),n=n.replace(/(>)(<\/)/g,(s,c,f,
|
|
1599
|
-
${
|
|
1597
|
+
`),n=n.replace(/(?<=>)(<(?!\/)[^>]+>)/g,(s,c,u,f)=>{let g=f.substring(u+s.length,Math.min(f.length,u+s.length+20)),h=s.match(/<(\w+)/)?.[1];if(h&&g.match(new RegExp(`^</${h}>`)))return s;return`
|
|
1598
|
+
${s}`}),n=n.replace(/(>)(<\/)/g,(s,c,u,f,g)=>{let h=g.substring(Math.max(0,f-50),f),v=g.substring(f+s.length,Math.min(g.length,f+s.length+20)).match(/^(\w+)>/)?.[1],S=h.match(/<(\w+)[^>]*$/)?.[1];if(S&&v&&S===v)return s;return`${c}
|
|
1599
|
+
${u}`}),n=n.replace(/(<\/[^>]+>)(?=<|$)/g,(s,c,u,f)=>{let g=f.substring(Math.max(0,u-20),u),h=s.match(/<\/(\w+)>/)?.[1],x=new RegExp(`<${h}[^>]*>$`);if(h&&g.match(x))return s;return`${s}
|
|
1600
1600
|
`}),n=n.replace(new RegExp(`${d}(\\d+)__`,"g"),(s,c)=>o[Number.parseInt(c,10)]),n=n.replace(/\n{2,}/g,`
|
|
1601
1601
|
`),n=n.split(`
|
|
1602
1602
|
`).map((s)=>s.trim()).join(`
|
|
1603
1603
|
`),n=n.replace(/^\n+/,"").replace(/\n+$/,""),n}function so(t,n){let d=oo(t).split(`
|
|
1604
|
-
`),s=[],c=0,
|
|
1604
|
+
`),s=[],c=0,u=!1,f=n.useTabs?"\t":" ".repeat(n.indentSize);for(let g=0;g<d.length;g++){let h=d[g],x=h.trim();if(x===""){s.push("");continue}let v=x.match(/<script\b/i),S=x.match(/<\/script>/i);if(u&&!S){s.push(h);continue}let T=x===">";if(un(x)&&!x.startsWith("<")&&!x.startsWith("@")){s.push(f.repeat(c)+x);continue}let w=x.startsWith("@end"),b=x.startsWith("@else")||x.startsWith("@elseif"),k=x.startsWith("@")&&co(x),_=x.startsWith("<!DOCTYPE")||x.startsWith("<!doctype"),E=x.startsWith("<!--"),R=x.startsWith("</"),A=x.startsWith("<")&&!R&&!E&&!_,C=x.includes("/>")||ao(x),D=un(x);if(R||w)c=Math.max(0,c-1);let I=b?Math.max(0,c-1):c;if(T)s.push(h);else s.push(f.repeat(I)+x);if(A&&!C&&!D&&!T||k)c++;if(v)u=!0;if(S)u=!1}return s.join(`
|
|
1605
1605
|
`)}function io(t,n){if(t=t.replace(/@(if|elseif|foreach|for|while)\s*\(\s*([^)]+)\s*\)/g,(o,d,s)=>{let c=s.trim().replace(/\s+/g," ");return`@${d}(${c})`}),t=t.replace(/@(csrf|method)\s*\(\s*([^)]*)\s*\)/g,(o,d,s)=>{if(s.trim()==="")return`@${d}`;return`@${d}(${s.trim()})`}),n.normalizeWhitespace)t=t.replace(/\{\{\s*([^}]+)\s*\}\}/g,(o,d)=>`{{ ${d.trim()} }}`),t=t.replace(/\{!!\s*([^!]+)\s*!!\}/g,(o,d)=>`{!! ${d.trim()} !!}`);return t}function ao(t){let n=["br","hr","img","input","meta","link","area","base","col","embed","source","track","wbr"];if(t.includes("/>"))return!0;let o=t.match(/<(\w+)/);if(o){let d=o[1];return n.includes(d.toLowerCase())}return!1}function un(t){return/<(\w+)(?:\s[^>]*)?>[\s\S]*?<\/\1>/.test(t)}function co(t){let n=["if","unless","foreach","for","while","section","push","component","slot","markdown","wrap","error"];for(let o of n)if(t.startsWith(`@${o}`))return!t.includes(`@end${o}`);return!1}function lo(t,n){if(!n.sortAttributes)return t;return t.replace(/<(\w+)([^>]*)>/g,(o,d,s)=>{if(!s.trim())return o;if(s.includes("<")||s.includes(`
|
|
1606
|
-
`)||s.includes("@"))return o;let c=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,
|
|
1606
|
+
`)||s.includes("@"))return o;let c=/(\w+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,u=[],f;while((f=c.exec(s))!==null)u.push({name:f[1],value:f[2]});u.sort((h,x)=>{if(h.name==="id")return-1;if(x.name==="id")return 1;if(h.name==="class")return-1;if(x.name==="class")return 1;return h.name.localeCompare(x.name)});let g=u.map((h)=>h.value?`${h.name}=${h.value}`:h.name).join(" ");return`<${d}${g?` ${g}`:""}>`})}import mn from"fs";import Ut from"path";async function Bi(t="index.stx",n={}){try{let o=n.force||!1,d=Ut.resolve(process.cwd(),t);if(await Bun.file(d).exists()){if(!o)throw Error(`File ${t} already exists. Use --force to overwrite.`);console.warn(`File ${t} already exists. Overwriting...`)}let s=Ut.dirname(d);if(!mn.existsSync(s))mn.mkdirSync(s,{recursive:!0});let c;if(n.template){let u=Ut.resolve(process.cwd(),n.template);if(!await Bun.file(u).exists())throw Error(`Template file ${n.template} does not exist.`);if(!u.endsWith(".stx"))console.warn(`Warning: Template file ${n.template} does not have a .stx extension. Using it anyway.`);c=await Bun.file(u).text(),console.warn(`Using template from ${n.template}`)}else if(n.preset)c=gn(n.preset),console.warn(`Using '${n.preset}' preset template`);else c=gn("basic");return await Bun.write(d,c),console.warn(`Created new stx file: ${t}`),!0}catch(o){return console.error(`Error creating file: ${o instanceof Error?o.message:String(o)}`),!1}}function gn(t){switch(t){case"basic":return hn();case"component":return po();case"layout":return uo();case"blog":return fo();case"api":return mo();case"app":return go();default:return hn()}}function hn(){return`<script>
|
|
1607
1607
|
const title = "My stx Page"
|
|
1608
1608
|
const description = "A page built with stx"
|
|
1609
1609
|
const features = [
|
|
@@ -2029,5 +2029,5 @@ const features = [
|
|
|
2029
2029
|
})();
|
|
2030
2030
|
</script>
|
|
2031
2031
|
</body>
|
|
2032
|
-
</html>`}var Fi="f9c3713";function cl(t){return t}function ll(t){return t}function Ni(t,n){let o=[],d=`${n}=`;for(let s=0;s<t.length;s++){let c=t[s];if(c.startsWith(d)){let
|
|
2032
|
+
</html>`}var Fi="f9c3713";function cl(t){return t}function ll(t){return t}function Ni(t,n){let o=[],d=`${n}=`;for(let s=0;s<t.length;s++){let c=t[s];if(c.startsWith(d)){let u=c.slice(d.length);if(u)o.push(u);continue}if(c===n){let u=t[s+1];if(u!==void 0&&!u.startsWith("-"))o.push(u),s++}}return o}import Me from"fs";import xe from"path";function Rn(t){try{return Me.statSync(t).mtimeMs}catch{return null}}function Rt(t,n){let o=Math.max(0,Math.round((n-t)/1000));if(o<60)return`${o}s ago`;if(o<3600)return`${Math.round(o/60)}m ago`;return`${Math.round(o/3600)}h ago`}function Ti(t,n){try{return globalThis.Bun?.resolveSync(t,n)??null}catch{return null}}function En(t,n="stx"){let o=xe.resolve(t);for(let d=0;d<10;d++){let s=xe.join(o,"pantry","@stacksjs",n);if(Me.existsSync(s))return s;let c=xe.dirname(o);if(c===o)break;o=c}return null}var Pn=["@stacksjs/stx","bun-plugin-stx"];function $i(t){try{let n=Me.readFileSync(xe.join(t,"package.json"),"utf8"),o=JSON.parse(n)?.version;return typeof o==="string"?o:null}catch{return null}}function Ci(t,n=6){let o=xe.resolve(t),d=[],s=new Set;function c(f,g){if(g>n)return;let h;try{h=Me.realpathSync(f)}catch{return}if(s.has(h))return;s.add(h);for(let v of Pn){let S=xe.join(f,v),T=$i(S);if(T!==null)d.push({name:v,version:T,dir:xe.relative(o,S)||S,nested:g>0})}let x;try{x=Me.readdirSync(f,{withFileTypes:!0})}catch{return}for(let v of x){if(!v.isDirectory()&&!v.isSymbolicLink())continue;if(v.name===".bin"||v.name===".cache")continue;let S=xe.join(f,v.name);if(v.name.startsWith("@")){let w;try{w=Me.readdirSync(S,{withFileTypes:!0})}catch{continue}for(let b of w){let k=xe.join(S,b.name,"node_modules");if(Me.existsSync(k))c(k,g+1)}continue}let T=xe.join(S,"node_modules");if(Me.existsSync(T))c(T,g+1)}}let u=xe.join(o,"node_modules");if(Me.existsSync(u))c(u,0);return d}function Ri(t){let n=[];for(let o of Pn){let d=t.filter((u)=>u.name===o);if(d.length<=1)continue;let s=[...new Set(d.map((u)=>u.version))],c=d.map((u)=>`${u.version} at ${u.dir}`).join("; ");if(s.length===1){n.push({name:`${o} copies`,status:"info",detail:`${d.length} copies, all ${s[0]} \u2014 duplicated but in agreement`});continue}n.push({name:`${o} copies disagree`,status:"error",detail:`${s.length} versions installed, so which one runs depends on who imports it: ${c}`,fix:`remove the nested copies, or add an overrides entry pinning ${o}, then reinstall \u2014 and verify with: find -L node_modules -path '*/${o}/package.json' -exec grep -H '"version"' {} +`})}return n}async function Gs(t={}){let n=t.cwd?xe.resolve(t.cwd):process.cwd(),o=t.resolve??Ti,d=Date.now(),s=[],c=o("@stacksjs/stx",n);s.push(c?{name:"@stacksjs/stx resolves to",status:"ok",detail:c}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let u=o("bun-plugin-stx",n);if(u)s.push({name:"bun-plugin-stx resolves to",status:"ok",detail:u});for(let g of Ri(Ci(n)))s.push(g);let f=En(n,"stx");if(!f)s.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let g=xe.join(f,"src/signals.ts"),h=[xe.join(f,"dist/index.js"),xe.join(f,"dist/signals.js")].find((w)=>Me.existsSync(w))||null,x=Rn(g),v=h?Rn(h):null;if(x==null)s.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${f} but no src/signals.ts to compare`});else if(v==null)s.push({name:"pantry dist freshness",status:"error",detail:"pantry has src but no built dist \u2014 the dev server will resolve nothing (or a stale copy elsewhere)",fix:`cd ${f} && bun build.ts`});else if(v<x){let w=Math.round((x-v)/1000);s.push({name:"pantry dist freshness",status:"error",detail:`dist (${Rt(v,d)}) is OLDER than src/signals.ts (${Rt(x,d)}) by ${w}s \u2014 your edit isn't built`,fix:`cd ${f} && bun build.ts`})}else s.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Rt(x,d)}, dist ${Rt(v,d)})`});let S=xe.join(n,"node_modules/@stacksjs/stx"),T=null;try{T=Me.lstatSync(S)}catch{T=null}if(!T)s.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(T.isSymbolicLink()){let w=null;try{w=Me.realpathSync(S)}catch{}let b=(()=>{try{return Me.realpathSync(f)}catch{return f}})();s.push(w===b?{name:"node_modules \u2192 pantry",status:"ok",detail:"symlinked to pantry"}:{name:"node_modules \u2192 pantry",status:"warn",detail:`symlinked to ${w||"(dangling)"}, not pantry`})}else s.push({name:"node_modules \u2192 pantry",status:"warn",detail:"is a real directory, NOT symlinked to pantry \u2014 edits to pantry src/dist won't be resolved",fix:"rm -rf node_modules/@stacksjs/stx && ln -s ../../pantry/@stacksjs/stx node_modules/@stacksjs/stx"})}if(s.push({name:"dev runtime cache",status:"info",detail:"cleared automatically on source edits by the dev watcher (clearDevCaches, #1745 item C)"}),t.generateRuntime)try{let h=t.generateRuntime().length;s.push(h>1000?{name:"signals runtime",status:"ok",detail:`generated ${h.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${h} chars \u2014 suspiciously short`})}catch(g){s.push({name:"signals runtime",status:"error",detail:`failed to generate: ${g.message}`})}return{checks:s,ok:!s.some((g)=>g.status==="error")}}function Xs(t){let n={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},o=["stx runtime resolution:"];for(let d of t.checks)if(o.push(` ${n[d.status]} ${d.name}: ${d.detail}`),d.fix)o.push(` \u2192 ${d.fix}`);return o.push(""),o.push(t.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),o.join(`
|
|
2033
2033
|
`)}export{Ni,Di,Mi,Li,Ks,ji,Bi,Fi,cl,ll,Gs,Xs,Or,Nr,Dr};
|