@stacksjs/stx 0.2.850 → 0.2.852
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-e46n406k.js → chunk-02w7kaas.js} +1 -1
- package/dist/{chunk-62k66qj9.js → chunk-0b7knfwk.js} +1 -1
- package/dist/{chunk-tmftv8na.js → chunk-0kaph5qq.js} +5 -5
- package/dist/{chunk-5m4txcry.js → chunk-14vv64pw.js} +1 -1
- package/dist/{chunk-y8qdpb0p.js → chunk-1mqyt33c.js} +1 -1
- package/dist/{chunk-xa1f13nk.js → chunk-1pavg6q5.js} +4 -4
- package/dist/{chunk-9yp0t7zc.js → chunk-1sedjgmj.js} +1 -1
- package/dist/{chunk-td6b41vj.js → chunk-2stgv8kd.js} +2 -2
- package/dist/chunk-332qk8tm.js +3 -0
- package/dist/{chunk-918ws1g7.js → chunk-3bp76dx5.js} +3 -3
- package/dist/{chunk-jqsn4sgv.js → chunk-42hj9jnj.js} +1 -1
- package/dist/{chunk-d4kystzh.js → chunk-47z5w330.js} +1 -1
- package/dist/chunk-4e5wynb4.js +2 -0
- package/dist/{chunk-5wk40kjd.js → chunk-4hfh5ety.js} +1 -1
- package/dist/{chunk-t7ws9sth.js → chunk-6amqskpv.js} +1 -1
- package/dist/chunk-6ra9dqs2.js +2 -0
- package/dist/{chunk-gr8q8xqz.js → chunk-6tns3zet.js} +1 -1
- package/dist/{chunk-jt5cqq09.js → chunk-714p8awg.js} +1 -1
- package/dist/{chunk-jpyk0gtr.js → chunk-7x6aqvfe.js} +1 -1
- package/dist/{chunk-98qgcmxr.js → chunk-818kkhb8.js} +1 -1
- package/dist/{chunk-6rd4phe3.js → chunk-8f5dy08a.js} +1 -1
- package/dist/{chunk-6q6atv4g.js → chunk-9gzgfj19.js} +1 -1
- package/dist/{chunk-p2chmq36.js → chunk-a69v31q8.js} +1 -1
- package/dist/{chunk-9mryv01z.js → chunk-c1dkvqr5.js} +2 -2
- package/dist/{chunk-ar1prdev.js → chunk-cm5kpn54.js} +2 -2
- package/dist/{chunk-jqjw00qm.js → chunk-d5m6xy9p.js} +4 -4
- package/dist/{chunk-hg9354gt.js → chunk-dqrkteav.js} +1 -1
- package/dist/{chunk-sy0jtgmv.js → chunk-e0dgx3ev.js} +1 -1
- package/dist/{chunk-sznk5c66.js → chunk-epqp6mmn.js} +1 -1
- package/dist/chunk-et9fyzf6.js +2 -0
- package/dist/{chunk-sjpya8wm.js → chunk-fhd8e4mq.js} +1 -1
- package/dist/{chunk-btkazgdb.js → chunk-fkrf2099.js} +1 -1
- package/dist/chunk-ft43rx62.js +2 -0
- package/dist/{chunk-x80b12gr.js → chunk-g34tj6ny.js} +1 -1
- package/dist/{chunk-brheng7x.js → chunk-gn6yqcz2.js} +4 -4
- package/dist/{chunk-660g9vjn.js → chunk-hh9hnx1a.js} +1 -1
- package/dist/{chunk-ryb4jesm.js → chunk-j415w6dm.js} +1 -1
- package/dist/{chunk-j6r964wk.js → chunk-ja5ghh0f.js} +1 -1
- package/dist/{chunk-w8aj3f9v.js → chunk-jmjz23rf.js} +1 -1
- package/dist/{chunk-hhk46fzp.js → chunk-keeetray.js} +1 -1
- package/dist/{chunk-8hkgycpm.js → chunk-kp2g6sj6.js} +1 -1
- package/dist/{chunk-tbs24vx1.js → chunk-m150nmez.js} +1 -1
- package/dist/{chunk-qahz3n8z.js → chunk-n2z4kyba.js} +1 -1
- package/dist/{chunk-5jqz5qff.js → chunk-pbq1gn94.js} +2 -2
- package/dist/chunk-pd0wdjqd.js +2 -0
- package/dist/{chunk-nq2z2yrz.js → chunk-ptppavv8.js} +1 -1
- package/dist/{chunk-xe8m66a3.js → chunk-r53tqxmq.js} +65 -64
- package/dist/{chunk-kybes29w.js → chunk-s922rk4n.js} +1 -1
- package/dist/{chunk-qa1pcm7n.js → chunk-sb8vn22f.js} +1 -1
- package/dist/{chunk-z46mk8ym.js → chunk-tbms7m44.js} +1 -1
- package/dist/{chunk-eh8g8kr1.js → chunk-te090fxv.js} +4 -4
- package/dist/{chunk-ab1vk7jv.js → chunk-tgk6bst6.js} +2 -2
- package/dist/{chunk-7zxce1yw.js → chunk-tn9h4prj.js} +1 -1
- package/dist/{chunk-r2p2nyyq.js → chunk-tt3jxdy5.js} +1 -1
- package/dist/{chunk-je8ma636.js → chunk-v4kqxe8a.js} +1 -1
- package/dist/{chunk-5p6vpvmz.js → chunk-vffwkmt4.js} +1 -1
- package/dist/chunk-vqr3hn16.js +2 -0
- package/dist/{chunk-m6nhh5xf.js → chunk-w7dks1ev.js} +2 -2
- package/dist/{chunk-sa18tper.js → chunk-whdy7r35.js} +1 -1
- package/dist/{chunk-zteccxj9.js → chunk-x1c1aggq.js} +1 -1
- package/dist/chunk-xkvzg640.js +2 -0
- package/dist/chunk-xt7qsgk4.js +2 -0
- package/dist/{chunk-k0pm7p0f.js → chunk-yq12dhnt.js} +1 -1
- package/dist/chunk-z5z6442j.js +2 -0
- package/dist/cli.js +7 -7
- package/dist/craft-entry.js +1 -1
- package/dist/craft.js +1 -1
- package/dist/native/floating-actions.d.ts +1 -0
- package/dist/native/floating-actions.js +2 -0
- package/dist/native/runtime/browser-screen.js +12 -1
- package/dist/native/runtime/craft.d.ts +1 -0
- package/dist/pwa.js +1 -1
- package/dist/ssg.js +2 -2
- package/dist/stx-virtual-ts.d.ts +7 -0
- package/dist/stx-virtual-ts.js +83 -3
- package/package.json +5 -5
- package/dist/chunk-4pbrszgz.js +0 -2
- package/dist/chunk-5be6p256.js +0 -2
- package/dist/chunk-9bkgbyrs.js +0 -2
- package/dist/chunk-a2shk93y.js +0 -3
- package/dist/chunk-nnbr1q94.js +0 -2
- package/dist/chunk-r0btg48x.js +0 -2
- package/dist/chunk-tpax2gpz.js +0 -2
- package/dist/chunk-ts6sm467.js +0 -2
- package/dist/chunk-w005b56n.js +0 -2
- package/dist/chunk-xrdh4at4.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{rs,ss}from"./chunk-0dnetjh8.js";import{y}from"./chunk-
|
|
2
|
+
import{rs,ss}from"./chunk-0dnetjh8.js";import{y}from"./chunk-r53tqxmq.js";import{a}from"./chunk-c1dkvqr5.js";import{Ge,se}from"./chunk-t74qb5ej.js";import{nc}from"./chunk-2stgv8kd.js";import{B}from"./chunk-ybq56wam.js";import{g}from"./chunk-0dve54ne.js";import{existsSync as z,mkdirSync as S,copyFileSync as P,chmodSync as I,rmSync as ve}from"fs";import{join as c,basename as xe,resolve as X}from"path";import{spawn as _}from"child_process";import{platform as ye}from"os";function O(e,r,i){let n=new RegExp(`</${r}\\s*>`,"iy"),s=y(e,(t,o)=>(n.lastIndex=o,n.exec(t)?n.lastIndex:-1))[0];return s?e.slice(0,s.start)+i+e.slice(s.start):null}var vu=`
|
|
3
3
|
<script>
|
|
4
4
|
(function() {
|
|
5
5
|
'use strict';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"./chunk-k47addf7.js";import"./chunk-agbkv9ab.js";import"./chunk-xppm4cs4.js";import"./chunk-
|
|
2
|
+
import"./chunk-k47addf7.js";import"./chunk-agbkv9ab.js";import"./chunk-xppm4cs4.js";import"./chunk-r53tqxmq.js";import"./chunk-v4bqmzj9.js";import"./chunk-n2z4kyba.js";import"./chunk-jtccqpwa.js";import"./chunk-tt3jxdy5.js";import{c}from"./chunk-z33esms3.js";import u from"fs";import l from"path";async function d(e,t={}){let s=Date.now(),n={total:0,passed:0,failed:0,new:0,failures:[],duration:0},i=t.snapshotDir||c(e.root,"story","snapshots");await u.promises.mkdir(i,{recursive:!0});let r=e.storyFiles;if(t.filter&&t.filter.length>0)r=r.filter((a)=>t.filter.some((o)=>a.fileName.toLowerCase().includes(o.toLowerCase())));for(let a of r)await h(a,i,t,n);return n.duration=Date.now()-s,n}async function h(e,t,s,n){let i=e.story;if(!i)return;for(let r of i.variants){n.total++;let a=l.join(t,`${e.id}-${r.id}.snap`),o=g(r.source||""),f=await w(a);if(s.update||!f){let p={storyId:e.id,variantId:r.id,component:e.fileName,timestamp:Date.now(),hash:o};if(await u.promises.writeFile(a,JSON.stringify(p,null,2)),!f)n.new++;n.passed++}else try{let p=await u.promises.readFile(a,"utf-8"),m=JSON.parse(p);if(m.hash===o)n.passed++;else n.failed++,n.failures.push({storyId:e.id,variantId:r.id,component:e.fileName,message:"Snapshot mismatch",difference:y(m.hash,o)})}catch(p){n.failed++,n.failures.push({storyId:e.id,variantId:r.id,component:e.fileName,message:`Error reading snapshot: ${p}`})}}}async function x(e,t={}){return(await d(e,{...t,update:!0})).total}function g(e){let t=0;for(let s=0;s<e.length;s++){let n=e.charCodeAt(s);t=(t<<5)-t+n,t=t&t}return t.toString(16)}function y(e,t){if(e===t)return 0;let s=Math.abs(Number.parseInt(e,16)-Number.parseInt(t,16));return Math.min(s/1e6,1)}async function w(e){try{return await u.promises.access(e),!0}catch{return!1}}function F(e){let t=[];if(t.push(""),t.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"),t.push(" STX Story Visual Regression Tests"),t.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"),t.push(""),e.failures.length>0){t.push(" \u274C Failures:"),t.push("");for(let s of e.failures){if(t.push(` \u2022 ${s.component} / ${s.variantId}`),t.push(` ${s.message}`),s.difference!==void 0)t.push(` Difference: ${(s.difference*100).toFixed(2)}%`);t.push("")}}if(t.push(" Summary:"),t.push(` Total: ${e.total}`),t.push(` Passed: ${e.passed} \u2713`),t.push(` Failed: ${e.failed} \u2717`),e.new>0)t.push(` New: ${e.new} \u26A1`);return t.push(` Time: ${e.duration}ms`),t.push(""),t.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"),t.push(""),t.join(`
|
|
3
3
|
`)}export{F as formatTestResults,d as runVisualTests,x as updateSnapshots};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{pe,yn,Mt,Dt,m,s,ge,p}from"./chunk-
|
|
2
|
+
import{pe,yn,Mt,Dt,m,s,ge,p}from"./chunk-r53tqxmq.js";import{wt,Ae,uc,ls,jo,Bo,i}from"./chunk-1pavg6q5.js";import{ae,ce,Ar,_e,z,En}from"./chunk-k47addf7.js";import{_t,hr,Ps,Is,Os,Ct,Et,Tt,$t,Rt,At,tt}from"./chunk-8cvgm13s.js";import{Cs,a,O}from"./chunk-c1dkvqr5.js";import{mt,Jt,Ee,j,ga,wo,Jr,qe,ma,Ke,Te}from"./chunk-3bp76dx5.js";import{fr,gr}from"./chunk-7x6aqvfe.js";import{e,dn,cr,b}from"./chunk-cm5kpn54.js";import{Ye}from"./chunk-d5m6xy9p.js";import{Re}from"./chunk-hpwtjb4a.js";import{In}from"./chunk-1sedjgmj.js";import{X,we,ve}from"./chunk-te090fxv.js";import{c}from"./chunk-z33esms3.js";import{G}from"./chunk-ym5qgw03.js";async function zn(t){try{let n=await Bun.file(t).text(),r=Nn(n),d=Un(n,t),o=Wn(n,r),l=Vn(n,r);return{file:t,metrics:r,issues:d,suggestions:o,performance:l}}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
|
`),r=t.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i),o=(r?r[1]:"").split(`
|
|
4
4
|
`).length,l={conditionals:(t.match(/@(if|unless|elseif|else|endif|endunless)\b/g)||[]).length,loops:(t.match(/@(foreach|for|endforeach|endfor|while|endwhile)\b/g)||[]).length,includes:(t.match(/@(include|component|extends|section|yield)\b/g)||[]).length,custom:0,total:0};l.total=l.conditionals+l.loops+l.includes+l.custom;let 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,y=Math.min(10,Math.ceil(l.total*0.5+h*0.1+x*0.3+(o>10?o*0.05:0)+w));return{lines:n.length,characters:t.length,directives:l,expressions:h,components:x,layouts:v,scriptLines:o,complexity:y}}function Un(t,n){let r=[],d=Xt(t,"if","endif");if(d>0)r.push({type:"error",category:"syntax",message:`Found ${d} unmatched @if directive(s)`,suggestion:"Ensure every @if has a corresponding @endif"});let o=Xt(t,"foreach","endforeach");if(o>0)r.push({type:"error",category:"syntax",message:`Found ${o} unmatched @foreach directive(s)`,suggestion:"Ensure every @foreach has a corresponding @endforeach"});let l=t.match(/@foreach[\s\S]*?@foreach[\s\S]*?@endforeach[\s\S]*?@endforeach/g);if(l&&l.length>0)r.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)r.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)r.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
5
|
`).filter((x)=>x.length>120);if(g.length>0)r.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)r.push({type:"info",category:"maintainability",message:`Found ${h} inline style attributes`,suggestion:"Consider moving styles to CSS classes for better maintainability"});return r}function Wn(t,n){let r=[];if(n.complexity>7)r.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)r.push({type:"optimization",message:"Template has moderate complexity. Consider component extraction for reusability.",impact:"medium",effort:"low"});if(n.lines>100&&n.components===0)r.push({type:"refactor",message:"Large template with no components. Consider extracting reusable parts into components.",impact:"medium",effort:"medium"});if(n.expressions>20)r.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)r.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)r.push({type:"optimization",message:"Template appears static. Consider enabling aggressive caching.",impact:"high",effort:"low"});if(n.scriptLines>50)r.push({type:"refactor",message:"Large script section. Consider moving complex logic to external modules.",impact:"medium",effort:"medium"});return r}function Vn(t,n){let r=1;if(r+=n.directives.conditionals*0.1,r+=n.directives.loops*0.5,r+=n.directives.includes*2,r+=n.expressions*0.05,r+=n.components*1,n.scriptLines>10)r+=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 o=[];if(r>10)o.push("Consider optimizing template complexity");if(d==="low"&&n.directives.total>5)o.push("Reduce dynamic content for better caching");if(n.components===0&&n.lines>40)o.push("Extract components to improve reusability and performance");return{estimatedRenderTime:Math.round(r*100)/100,complexityScore:n.complexity,cacheability:d,recommendations:o}}function Xt(t,n,r){let d=t.replace(/<!--[\s\S]*?-->/g,""),o=(d.match(new RegExp(`@${n}\\b`,"g"))||[]).length,l=(d.match(new RegExp(`@${r}\\b`,"g"))||[]).length;return Math.abs(o-l)}async function ta(t=["**/*.stx"],n){let r=[],d=[];for(let l of t){let u=await Array.fromAsync(new Bun.Glob(l).scan({cwd:n||process.cwd(),onlyFiles:!0,absolute:!0}));d.push(...u.filter((f)=>f.endsWith(".stx")))}for(let l of d)try{let u=await zn(l);r.push(u)}catch(u){console.warn(`Failed to analyze ${l}:`,u)}let o=qn(r);return{results:r,summary:o}}function qn(t){let n=t.length,r=t.reduce((h,x)=>h+x.metrics.lines,0),d=n>0?t.reduce((h,x)=>h+x.metrics.complexity,0)/n:0,o=t.reduce((h,x)=>h+x.issues.length,0),l={};t.forEach((h)=>{h.issues.forEach((x)=>{l[x.category]=(l[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(o>n*2)g.push("High number of issues detected. Run detailed analysis on individual files.");if(l.security>0)g.push("Security issues found. Review raw output usage and input sanitization.");return{totalFiles:n,totalLines:r,avgComplexity:Math.round(d*100)/100,totalIssues:o,issuesByCategory:l,performanceScore:f,recommendations:g}}import{mkdir as Kn,readFile as Xn,readdir as Gn,stat as Gt,writeFile as Jn}from"fs/promises";import ke from"path";function nn(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 rn=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 r(d){let o=await Gn(d,{withFileTypes:!0});o.sort((l,u)=>l.name.localeCompare(u.name));for(let l of o){let u=ke.join(d,l.name);if(l.isDirectory()){if(!l.name.startsWith(".")&&l.name!=="node_modules")await r(u)}else if(l.isFile()&&l.name.endsWith(".stx")&&!/\.(?:test|spec)\.stx$/i.test(l.name))n.push(u)}}return await r(t),n}function tr(t,n){let r=t.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);if(!r)return{};let d=r[1].trim();if(!d)return{};try{return JSON.parse(d)}catch(o){throw Error(`${n}: <script component> must contain JSON metadata (${o.message})`)}}function nr(t,n){let r={},d=[...t.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];for(let o of d){if(!/\bclient\b/i.test(o[1])||/\bcomponent\b|\bstx:component\b/i.test(o[1]))continue;let l;try{l=new Bun.Transpiler({loader:"ts"}).transformSync(o[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(l)){let g=f[1];if(rn.has(g))throw Error(`${n}: client ${nn(g)}`);let h=u.lastIndex,x=1,v="",S=!1,T=h;for(;T<l.length&&x>0;T++){let y=l[T];if(S){S=!1;continue}if(v){if(y==="\\")S=!0;else if(y===v)v="";continue}if(y==='"'||y==="'"||y==="`")v=y;else if(y==="{")x++;else if(y==="}")x--}if(x!==0)throw Error(`${n}: unterminated client function "${g}"`);let w=f[0].includes("async")?"async ":"";r[g]=`${w}${g}(${f[2]}) {${l.slice(h,T-1)}}`,u.lastIndex=T}}return r}function rr(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 Yt(t){return[...t.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((n)=>n[1].trim()).filter(Boolean).join(`
|
|
@@ -887,7 +887,7 @@ else {
|
|
|
887
887
|
};
|
|
888
888
|
})();
|
|
889
889
|
</script>
|
|
890
|
-
`}function Ne(t,n,r={}){let d=jr(n,r),o=t.lastIndexOf("</body>");if(o!==-1)return t.slice(0,o)+d+t.slice(o);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function ht(t){let n=t.toLowerCase();return n.endsWith(".css")||n.endsWith(".scss")||n.endsWith(".sass")||n.endsWith(".less")}function yt(t){let n=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>n.endsWith(d))}function bt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((r)=>r.test(t))}var nt=null;function xt(t){if(!nt)nt=new on(t);return nt}function it(){if(nt)nt.stop(),nt=null}import vt from"path";var rt={name:"bun-plugin-stx",async setup(t){let r={...await a(),...t.config?.stx},d=new Set,o=r.webComponents?.enabled?`./${vt.relative(vt.dirname(t.config?.outdir||"dist"),r.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(r.webComponents?.enabled)try{let u=await Cs(r,d);if(l.push(...u),r.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(r.cache&&r.cachePath){let y=await fr(u,r);if(y){if(r.debug)console.log(`Using cached version of ${u}`);return{contents:y,loader:"html"}}}let g=await _e(()=>Bun.file(u).text(),"",(y)=>{throw new Ar(`Failed to read stx file: ${u}`,u,void 0,void 0,`File read error: ${y.message}`)});if(!g)throw new Ar(`stx file is empty: ${u}`,u);let{scriptContent:h,templateContent:x,allScripts:v}=ae.time("script-extraction",()=>{let y=g,k=pe(g);if(k)y=k.content.trim();let M=g.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],E="",R=[];for(let C of M){let D=C.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",L=C.match(/<script\b([^>]*)>/i),V=L?L[1]:"";if(/\bserver\b/i.test(V))E=D;else R.push(C)}let A=y.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:E,templateContent:A,allScripts:R}}),S={__filename:u,__dirname:vt.dirname(u),__stx:{webComponentsPath:o,builtComponents:l}};await _e(()=>m(h,S,u),void 0,(y)=>{let k=new ce(`Script execution failed in ${u}: ${y.message}`,u,void 0,void 0,h.substring(0,100));if(z.log(k,{filePath:u,scriptContent:h}),r.debug)throw k});let w=await ae.timeAsync("directive-processing",async()=>await i(x,S,u,r,f));if(v.length>0){let{interpolateScriptsInTemplate:y}=await import("./chunk-
|
|
890
|
+
`}function Ne(t,n,r={}){let d=jr(n,r),o=t.lastIndexOf("</body>");if(o!==-1)return t.slice(0,o)+d+t.slice(o);if(t.includes("</html>"))return t.replace("</html>",`${d}</html>`);return t+d}function ht(t){let n=t.toLowerCase();return n.endsWith(".css")||n.endsWith(".scss")||n.endsWith(".sass")||n.endsWith(".less")}function yt(t){let n=t.toLowerCase();return[".stx",".html",".htm",".md",".js",".ts",".jsx",".tsx",".json"].some((d)=>n.endsWith(d))}function bt(t){return[/^\./,/node_modules/,/\.stx\/output/,/\.stx\/cache/,/~$/,/\.swp$/,/\.swo$/].some((r)=>r.test(t))}var nt=null;function xt(t){if(!nt)nt=new on(t);return nt}function it(){if(nt)nt.stop(),nt=null}import vt from"path";var rt={name:"bun-plugin-stx",async setup(t){let r={...await a(),...t.config?.stx},d=new Set,o=r.webComponents?.enabled?`./${vt.relative(vt.dirname(t.config?.outdir||"dist"),r.webComponents.outputDir||"dist/web-components")}`:"/web-components",l=[];if(r.webComponents?.enabled)try{let u=await Cs(r,d);if(l.push(...u),r.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(r.cache&&r.cachePath){let y=await fr(u,r);if(y){if(r.debug)console.log(`Using cached version of ${u}`);return{contents:y,loader:"html"}}}let g=await _e(()=>Bun.file(u).text(),"",(y)=>{throw new Ar(`Failed to read stx file: ${u}`,u,void 0,void 0,`File read error: ${y.message}`)});if(!g)throw new Ar(`stx file is empty: ${u}`,u);let{scriptContent:h,templateContent:x,allScripts:v}=ae.time("script-extraction",()=>{let y=g,k=pe(g);if(k)y=k.content.trim();let M=g.match(/<script\b[^>]*>[\s\S]*?<\/script>/gi)||[],E="",R=[];for(let C of M){let D=C.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i)?.[1]||"",L=C.match(/<script\b([^>]*)>/i),V=L?L[1]:"";if(/\bserver\b/i.test(V))E=D;else R.push(C)}let A=y.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"");return{scriptContent:E,templateContent:A,allScripts:R}}),S={__filename:u,__dirname:vt.dirname(u),__stx:{webComponentsPath:o,builtComponents:l}};await _e(()=>m(h,S,u),void 0,(y)=>{let k=new ce(`Script execution failed in ${u}: ${y.message}`,u,void 0,void 0,h.substring(0,100));if(z.log(k,{filePath:u,scriptContent:h}),r.debug)throw k});let w=await ae.timeAsync("directive-processing",async()=>await i(x,S,u,r,f));if(v.length>0){let{interpolateScriptsInTemplate:y}=await import("./chunk-47z5w330.js"),k=y(v.join(`
|
|
891
891
|
`),S),M=w.search(/<\/body>/i);if(M!==-1)w=w.slice(0,M)+k+`
|
|
892
892
|
`+w.slice(M);else w+=`
|
|
893
893
|
${k}`}if(w=await ve(w),f.forEach((y)=>d.add(y)),r.cache&&r.cachePath){if(await gr(u,w,f,r),r.debug)console.log(`Cached template ${u} with ${f.size} dependencies`)}return{contents:w,loader:"html"}}catch(f){let g=f instanceof Error?f:new ce(`Plugin processing failed: ${String(f)}`,u);if(z.log(g,{filePath:u,buildConfig:t.config}),En.logDetailedError(g,{filePath:u,plugin:"bun-plugin-stx"}),r.debug)console.error("stx Plugin Error:",g);let h=g,x=h.line||null,v=h.context||null;return{contents:r.debug||G()?`<!DOCTYPE html>
|
|
@@ -950,7 +950,7 @@ ${k}`}if(w=await ve(w),f.forEach((y)=>d.add(y)),r.cache&&r.cachePath){if(await g
|
|
|
950
950
|
<h1>Something went wrong</h1>
|
|
951
951
|
<p>An internal error occurred. Please try again later.</p>
|
|
952
952
|
</body>
|
|
953
|
-
</html>`,loader:"html"}}})}};async function Ur(t,n={}){let r=n.port||3000,d=n.watch!==!1,o=n.hotReload!==!1&&d,l=null,u=n.hmrPort||r+1,f=me.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 zt(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=c(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(be){be.onResolve({filter:/^\/(images|fonts|assets|public)\//},(le)=>({path:le.path,external:!0}))}},L=await Bun.build({entrypoints:[f],outdir:g,plugins:[D,rt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!L.success)return console.error(`${e.red}Build failed:${e.reset}`,L.logs),!1;let V=L.outputs.find((be)=>be.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=me.dirname(f);await dn(S);let T=r;try{if(T=await We(r),T!==r)console.log(`${e.yellow}Port ${r} is busy, using port ${T} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(o){let D=n.hmrPort||T+1;l=xt({wsPort:D,verbose:!1}),u=l.start(D)}let w={},y=null,k;try{let{loadStxConfig:D}=await import("./chunk-
|
|
953
|
+
</html>`,loader:"html"}}})}};async function Ur(t,n={}){let r=n.port||3000,d=n.watch!==!1,o=n.hotReload!==!1&&d,l=null,u=n.hmrPort||r+1,f=me.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 zt(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=c(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(be){be.onResolve({filter:/^\/(images|fonts|assets|public)\//},(le)=>({path:le.path,external:!0}))}},L=await Bun.build({entrypoints:[f],outdir:g,plugins:[D,rt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!L.success)return console.error(`${e.red}Build failed:${e.reset}`,L.logs),!1;let V=L.outputs.find((be)=>be.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=me.dirname(f);await dn(S);let T=r;try{if(T=await We(r),T!==r)console.log(`${e.yellow}Port ${r} is busy, using port ${T} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(o){let D=n.hmrPort||T+1;l=xt({wsPort:D,verbose:!1}),u=l.start(D)}let w={},y=null,k;try{let{loadStxConfig:D}=await import("./chunk-6ra9dqs2.js"),L=await D();if(k=n.stxOptions?.serverApi??L.serverApi,L?.apiRouter)y=L?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(L?.apiRoutes){w=L.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(L?.broadcasting?.enabled)try{let{startBroadcasting:V,loadChannels:Y}=await import("./chunk-k1pyzf9e.js"),be=L.broadcasting;await V(be);let le=be.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${le}/ws${e.reset}`);let Ce=me.join(process.cwd(),"channels.ts");if(Be.existsSync(Ce))try{let ne=await Y(Ce);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:M,isServerApiSource:E}=await import("./chunk-a69v31q8.js"),R=await M(process.cwd(),k);if(console.log(`${e.blue}Starting server on ${e.cyan}http://localhost:${T}/${e.reset}...`),o)console.log(`${e.magenta}Hot reload enabled on ws://localhost:${u}${e.reset}`);let A=Hr({port:T,async fetch(D){return In(D,await(async()=>{let L=new URL(D.url);if([g,me.dirname(f),me.join(process.cwd(),"public")].some((ne)=>E(me.join(ne,L.pathname),process.cwd(),k)))return new Response("Not Found",{status:404});if(y)try{let ne=await y.handleRequest(D);if(ne.status!==404)return ne}catch{}if(w[L.pathname])try{return await w[L.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(L.pathname==="/")return(async()=>{let F=await b(h||"");if(o)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=me.join(g,L.pathname);if(Be.existsSync(Y)&&Be.statSync(Y).isFile()){let ne=Bun.file(Y),F=me.extname(Y).toLowerCase(),_="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":_="text/html";break;case".css":_="text/css";break;case".js":_="text/javascript";break;case".json":_="application/json";break;case".png":_="image/png";break;case".jpg":case".jpeg":_="image/jpeg";break;case".gif":_="image/gif";break;case".woff":_="font/woff";break;case".woff2":_="font/woff2";break;case".ttf":_="font/ttf";break;case".otf":_="font/otf";break;case".eot":_="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":_}})}let be=me.dirname(f),le=me.join(be,L.pathname);if(Be.existsSync(le)&&Be.statSync(le).isFile()){let ne=Bun.file(le),F=me.extname(le).toLowerCase(),_="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":_="text/html";break;case".css":_="text/css";break;case".js":_="text/javascript";break;case".json":_="application/json";break;case".png":_="image/png";break;case".jpg":case".jpeg":_="image/jpeg";break;case".gif":_="image/gif";break;case".svg":_="image/svg+xml";break;case".ico":_="image/x-icon";break;case".woff":_="font/woff";break;case".woff2":_="font/woff2";break;case".ttf":_="font/ttf";break;case".otf":_="font/otf";break;case".eot":_="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":_}})}let Ce=me.join(process.cwd(),"public",L.pathname);if(Be.existsSync(Ce)&&Be.statSync(Ce).isFile()){let ne=Bun.file(Ce),F=me.extname(Ce).toLowerCase(),_="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":_="text/html";break;case".css":_="text/css";break;case".js":_="text/javascript";break;case".json":_="application/json";break;case".png":_="image/png";break;case".jpg":case".jpeg":_="image/jpeg";break;case".gif":_="image/gif";break;case".svg":_="image/svg+xml";break;case".ico":_="image/x-icon";break;case".woff":_="font/woff";break;case".woff2":_="font/woff2";break;case".ttf":_="font/ttf";break;case".otf":_="font/otf";break;case".eot":_="application/vnd.ms-fontobject";break}return new Response(ne,{headers:{"Content-Type":_}})}return new Response("Not Found",{status:404})})())},error(D){return new Response(`<pre>${D}
|
|
954
954
|
${D.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),console.log(`
|
|
955
955
|
${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(`
|
|
956
956
|
${e.bright}\u2192 ${e.cyan}http://localhost:${T}/${e.reset}`),console.log(`
|
|
@@ -1437,12 +1437,12 @@ ${w.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),con
|
|
|
1437
1437
|
${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(`
|
|
1438
1438
|
${e.bright}\u2192 ${e.cyan}http://localhost:${x}/${e.reset}`),console.log(`
|
|
1439
1439
|
${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],[y])=>w.localeCompare(y)).map(([w,y])=>({route:w==="/"?"/":w,filePath:$e.relative(process.cwd(),y.filePath),fileType:y.fileType}));for(let w of f){let y=w.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");T.push({route:y,filePath:$e.relative(process.cwd(),w.filePath),fileType:"stx"})}if(T.sort((w,y)=>w.route.localeCompare(y.route)),T.forEach((w,y)=>{let M=y===T.length-1?"\u2514\u2500 ":"\u251C\u2500 ",E=w.fileType==="md"?`${e.magenta}(markdown)${e.reset}`:"";console.log(` ${e.green}${M}${w.route}${e.reset} \u2192 ${e.bright}${w.filePath}${e.reset} ${E}`)}),console.log(`
|
|
1440
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ve(v.url.toString(),()=>{if(d)Xe.watch(l,{recursive:!0}).close();v.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let w=Xe.watch(l,{recursive:!0},async(y,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}`),Ye.clear(),ge(),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:Fr}=globalThis.Bun;import fe from"fs";import te from"path";async function ln(t){try{return yn(await Bun.file(t).text())}catch{return}}function Nt(t){let n=Bun.file(t),r=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"},l=[".js",".css",".json"].includes(r)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(n,{headers:{"Content-Type":d[r]||"application/octet-stream",...l}})}async function qr(t=".",n={}){let r=n.port||3000,d=n.watch!==!1,o=n.hotReload!==!1&&d,l=null,u=n.hmrPort||r+1,f=te.resolve(t),{loadStxConfig:g}=await import("./chunk-ts6sm467.js"),h=await g(f),{createServerApi:x,isServerApiSource:v}=await import("./chunk-p2chmq36.js"),S=n.stxOptions?.serverApi??h.serverApi,T=await x(f,S),w=h.root&&h.root!=="."?te.join(f,h.root):f,y=n.pagesDir||h.pagesDir||"pages",k=te.join(w,y);if(!fe.existsSync(k)&&!h._layerPageDirs?.some((P)=>fe.existsSync(P)))return console.error(`${e.red}Error: No '${y}' 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 ${y}/index.stx for the homepage.${e.reset}`),!1;let M=X(w,{pagesDir:y,pagesDirs:h._layerPageDirs?[k,...h._layerPageDirs.slice(1)]:void 0});if(M.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}${M.length}${e.blue} routes${e.reset}`);let E=h?._pluginPageDirs||[],R=[];for(let{dir:P,prefix:I}of E)if(fe.existsSync(P)){let N=X(te.dirname(P),{pagesDir:te.basename(P)});for(let Q of N){let q=I==="/"?Q.pattern:`${I}${Q.pattern==="/"?"":Q.pattern}`;R.push({route:{...Q,pattern:q},prefix:I})}if(N.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${N.length}${e.blue} routes at ${e.cyan}${I}${e.reset}`)}let A=new Map,C=null,D=null;if(n.stxOptions?.shell!==!1){if(D=await ga(f,n.stxOptions?.shell),D){if(C=await wo(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}`)}}Ct(),await Tt(f);let L=Et();if(L.length>0)console.log(`${e.blue}Loaded ${e.bright}${L.length}${e.blue} middleware: ${e.dim}${L.join(", ")}${e.reset}`);let V={},Y=null;try{let{loadStxConfig:P}=await import("./chunk-ts6sm467.js"),I=await P(f);if(I?.apiRouter)Y=I?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(I?.apiRoutes){V=I.apiRoutes;let N=Object.keys(V).length;if(N>0)console.log(`${e.blue}Loaded ${e.bright}${N} API route${N>1?"s":""}${e.reset}`)}if(I?.broadcasting?.enabled)try{let{startBroadcasting:N,loadChannels:Q}=await import("./chunk-k1pyzf9e.js"),q=I.broadcasting;await N(q);let Pe=q.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Pe}/ws${e.reset}`);let xe=te.join(process.cwd(),"channels.ts");if(fe.existsSync(xe))try{let U=await Q(xe);console.log(`${e.blue}Loaded ${e.bright}${U} broadcast channel${U!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(U){console.warn(`${e.yellow}Failed to load channels.ts: ${U.message}${e.reset}`)}}catch(N){console.warn(`${e.yellow}Broadcasting failed to start: ${N.message}${e.reset}`)}}catch{}let be=c(f,"output");fe.mkdirSync(be,{recursive:!0});let le=new Map,Ce=new Set,ne=async(P)=>{let I=Is(k,P);if(!I)return null;try{let N=await Bun.build({entrypoints:[I],outdir:be,plugins:[rt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!N.success)return null;let Q=N.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(P,I)=>{try{let{processDirectives:N,extractVariables:Q,defaultConfig:q,loadStxConfig:Pe,injectRouterScript:xe}=await import("./chunk-ts6sm467.js"),{checkCache:U,cacheTemplate:J,readFileCached:W,templateCache:de}=await import("./chunk-w8aj3f9v.js"),K=await Pe(f),Ue=(se)=>{if(!se)return se;if(te.isAbsolute(se))return se;return te.resolve(f,se)},ie={...q,...K,...n.stxOptions,autoShell:!0};if(n.debugDirectives)ie.debug=!0;ie.partialsDir=Ue(ie.partialsDir),ie.componentsDir=Ue(ie.componentsDir),ie.layoutsDir=Ue(ie.layoutsDir),ie.storesDir=Ue(ie.storesDir||"stores"),ie.cachePath=Ue(ie.cachePath)??c(f,"cache");let H=!I&&!n.profile,re=ie.cache!==!1;if(re&&H){let se=de.get(P.filePath);if(se)try{if((await fe.promises.stat(P.filePath)).mtime.getTime()<=se.mtime){let He=!0;for(let Se of se.dependencies){if(!fe.existsSync(Se)){He=!1;break}if((await fe.promises.stat(Se)).mtime.getTime()>se.mtime){He=!1;break}}if(He){let Se=se.output;if(C)Se=qe(Se,{preserveHead:!0});let st=F.get(P.filePath);return{route:P,content:Se,status:st?.status??await ln(P.filePath),headers:st?.headers}}}}catch{}let Ie=await U(P.filePath,ie);if(Ie){let je=Ie;if(C)je=qe(je,{preserveHead:!0});let He=F.get(P.filePath);return{route:P,content:je,status:He?.status??await ln(P.filePath),headers:He?.headers}}}let Z=re?await W(P.filePath):await Bun.file(P.filePath).text(),oe=yn(Z),{classifyAllScripts:ue}=await import("./chunk-ts6sm467.js"),B=ue(Z),Le=B.server.map((se)=>se.content),De=Z;for(let se of B.server)De=De.replace(se.fullTag,"");let ee={__filename:P.filePath,__dirname:te.dirname(P.filePath),__stx_options:ie,params:I??{},__stx_runtime_head:{}};for(let se of Le)try{await Q(se,ee,P.filePath)}catch(Ie){if(n.stxOptions?.debug)console.error("[stx] variable extraction error",P.filePath,Ie?.message||Ie)}let Oe=new Set,he;if(n.profile){let se=performance.now();he=await N(De,ee,P.filePath,ie,Oe);let Ie=performance.now()-se,je=te.relative(f,P.filePath)||P.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else he=await N(De,ee,P.filePath,ie,Oe);if(!C)he=await xe(he,{router:ie.router});{let{interpolateScriptExpressions:se}=await import("./chunk-d4kystzh.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}>${se(He,ee)}</script>`})}if(C)he=qe(he,{preserveHead:!0});if(re&&H)await J(P.filePath,he,Oe,ie);let{extractStreamBoundaries:ct}=await import("./chunk-sznk5c66.js"),Qe=ct(ee),ot=ee.__streamTemplates;if(ot&&typeof ot==="object"&&Object.keys(ot).length>0){let se=ee.streamBoundaries||{},Ie={...ie,autoShell:!1},je=Object.keys(ot).map((Se)=>({id:Se,render:async()=>{let st=typeof se[Se]==="function"?await se[Se]():void 0;return N(ot[Se],{...ee,$boundary:st},P.filePath,Ie,new Set)}})),He=new Set(je.map((Se)=>Se.id));Qe=[...(Qe||[]).filter((Se)=>!He.has(Se.id)),...je]}if(Qe&&Qe.length>0)Ce.add(P.pattern);else Qe=void 0;let Vt=Mt(ee),qt=Dt(ee);if(H)F.set(P.filePath,{status:Vt,headers:qt});return{route:P,content:he,status:Vt??oe,headers:qt,boundaries:Qe}}catch(N){return console.error(`${e.red}Error building ${e.bright}${P.pattern}${e.reset}:`,N),null}},Fe=8,ze=async()=>{let P=new Set(le.keys()),I=new Set(A.keys());le.clear(),A.clear();let N=n.prebuild===!1?M.filter((q)=>P.has(q.pattern)):M,Q=n.prebuild===!1?R.filter(({route:q})=>I.has(q.pattern)):R;for(let q=0;q<N.length;q+=Fe){let Pe=N.slice(q,q+Fe),xe=await Promise.all(Pe.map((U)=>_(U)));for(let U of xe)if(U)le.set(U.route.pattern,U)}for(let q=0;q<Q.length;q+=Fe){let Pe=Q.slice(q,q+Fe),xe=await Promise.all(Pe.map(({route:U})=>_(U)));for(let U of xe)if(U)A.set(U.route.pattern,U)}return le.size>0};if(console.log(`${e.blue}${n.prebuild===!1?"Rendering pages on request...":"Building pages..."}${e.reset}`),!(n.prebuild===!1?M.length+R.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await dn(f);let Ge=r;try{if(Ge=await We(r),Ge!==r)console.log(`${e.yellow}Port ${r} is busy, using port ${Ge} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(o){let P=n.hmrPort||Ge+1;l=xt({wsPort:P,verbose:!1}),u=l.start(P)}let kt=(P,I)=>{let Q=`<script data-stx-route-params>(function(){var p=${JSON.stringify(I).replace(/</g,"\\u003C").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;if(P.includes("</head>"))return P.replace("</head>",`${Q}</head>`);if(P.includes("<body"))return P.replace(/<body([^>]*)>/,`<body$1>${Q}`);return Q+P};console.log(`${e.blue}Starting server...${e.reset}`);let Pt=Fr({port:Ge,hostname:n.hostname,async fetch(P){let I=new URL(P.url),N=n.stxOptions?.offline??h.offline;if(I.pathname===jo&&N?.enabled){if(!["GET","HEAD"].includes(P.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});return new Response(P.method==="HEAD"?null:Bo(N,ls()),{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,I.pathname),Pe=te.join(f,I.pathname),xe=te.join(be,I.pathname);if([q,Pe,xe].some((H)=>v(H,f,S)))return new Response("Not Found",{status:404});let[U,J,W]=await Promise.all([fe.promises.stat(q).catch(()=>null),fe.promises.stat(Pe).catch(()=>null),fe.promises.stat(xe).catch(()=>null)]);if(U?.isFile()&&!v(q,f,S))return Nt(q);if(J?.isFile()&&!v(Pe,f,S))return Nt(Pe);if(W?.isFile()&&!v(xe,f,S))return Nt(xe);if(I.pathname.startsWith("/_stx/component/")){let H=decodeURIComponent(I.pathname.slice(16));if(H)try{let re=`<${H} />`,Z={...buildConfig,autoShell:!1},oe=await processDirectives(re,{},te.join(f,"components",`${H}.stx`),Z,new Set);return new Response(oe,{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(I.pathname==="/_stx/img"){let{handleImageRequest:H}=await import("./chunk-m276y4f3.js"),re=await H(P,{publicDir:te.join(f,Q),cacheDir:c(f,"cache","img")});if(re)return re}if(Y)try{let H=await Y.handleRequest(P);if(H.status!==404)return H}catch{}if(V[I.pathname])try{return await V[I.pathname](P)}catch(H){return new Response(JSON.stringify({error:H.message}),{status:500,headers:{"Content-Type":"application/json"}})}let de=await T(P);if(de)return de;let K=hr(I.pathname,M);if(K){let H=le.get(K.route.pattern),re=Ce.has(K.route.pattern);if(!H||K.route.isDynamic&&Object.keys(K.params).length>0||re){let Z=await _(K.route,K.params);if(Z){if(H=Z,!K.route.isDynamic&&!re)le.set(K.route.pattern,Z)}}if(H){let Z=H.status??200,oe=H.headers??{},ue=(K.route.filePath?wt(await Bun.file(K.route.filePath).text().catch(()=>"")):null)??{};if(ue.validate){if(!await ue.validate({params:K.params})){let De=await ne(404);if(De){let ee=De;if(ee=await b(ee,f),o)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(I.pathname,K.params,ue,I.search),De=Rt(Le,null,P,{isServer:!0}),ee=await At(ue.middleware,De);if(ee.redirect){let Oe=ee.redirect.path,he=ee.redirect.options.redirectCode||302,ct=new Headers(ee.responseHeaders);return ct.set("Location",Oe),new Response(null,{status:he,headers:ct})}if(ee.abort){let{statusCode:Oe,message:he}=ee.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${Oe}</title></head><body><h1>Error ${Oe}</h1><p>${he}</p></body></html>`,{status:Oe,headers:{"Content-Type":"text/html"}})}if(Object.keys(ee.state).length>0){let Oe=`<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>",`${Oe}</head>`)}}let B=H.content;if(C&&ma(P)&&Ke(B,h?.router?.container||"main")){let Le=tt(B),De=we(B),ee=B.match(/<title[^>]*>([\s\S]*?)<\/title>/i),Oe=ee?Jt(ee[1].trim()):"";if(Object.keys(K.params).length>0)B=kt(B,K.params);B=await b(B,f);let he=h?.router?.container||"main";return B=Te(B,he,!0),new Response(B,{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",...Oe&&{"X-STX-Title":encodeURIComponent(Oe)},[uc]:ls(),...j(),"Cache-Control":mt}})}if(C)B=Jr(C,B);if(Object.keys(K.params).length>0)B=kt(B,K.params);if(B=await b(B,f),o)B=Ne(B,u);if(n.native)if(B.includes("<head>"))B=B.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else B="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+B;if(n.titlebarHidden)if(B.includes("<head>"))B=B.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 B=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${B}`;if(H.boundaries&&H.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:De}=await import("./chunk-sznk5c66.js");return De(Le(B,H.boundaries,{timeoutMs:30000}),{status:Z,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(B,{status:Z,headers:{"Content-Type":"text/html",...j(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...oe}})}}if(R.length>0){let H=R.map((Z)=>Z.route),re=hr(I.pathname,H);if(re){let Z=A.get(re.route.pattern);if(!Z||re.route.isDynamic){let oe=await _(re.route,re.params);if(oe){if(Z=oe,!re.route.isDynamic)A.set(re.route.pattern,oe)}}if(Z){let oe=Z.content;if(C)oe=Jr(C,oe);if(Object.keys(re.params).length>0)oe=kt(oe,re.params);if(oe=await b(oe,f),o)oe=Ne(oe,u);return new Response(oe,{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!=="/"&&I.pathname.startsWith(Z)){let oe=A.get(Z)||A.get(Z+"/");if(!oe){let ue=R.find(({route:B})=>B.pattern===Z||B.pattern===`${Z}/`);if(ue){let B=await _(ue.route);if(B)oe=B,A.set(ue.route.pattern,B)}}if(oe){let ue=oe.content;if(C)ue=Jr(C,ue);if(ue=await b(ue,f),o)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(_t(I.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Ue=le.get("/");if(Ue){let H=Ue.content;if(H=await b(H,f),o)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 ie=await ne(404);if(ie){let H=ie;if(H=await b(H,f),o)H=Ne(H,u);return new Response(H,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(P){let I=await ne(500);if(I)return new Response(I,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${P}
|
|
1440
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ve(v.url.toString(),()=>{if(d)Xe.watch(l,{recursive:!0}).close();v.stop()}),d){console.log(`${e.blue}Watching for changes...${e.reset}`);let w=Xe.watch(l,{recursive:!0},async(y,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}`),Ye.clear(),ge(),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:Fr}=globalThis.Bun;import fe from"fs";import te from"path";async function ln(t){try{return yn(await Bun.file(t).text())}catch{return}}function Nt(t){let n=Bun.file(t),r=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"},l=[".js",".css",".json"].includes(r)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(n,{headers:{"Content-Type":d[r]||"application/octet-stream",...l}})}async function qr(t=".",n={}){let r=n.port||3000,d=n.watch!==!1,o=n.hotReload!==!1&&d,l=null,u=n.hmrPort||r+1,f=te.resolve(t),{loadStxConfig:g}=await import("./chunk-6ra9dqs2.js"),h=await g(f),{createServerApi:x,isServerApiSource:v}=await import("./chunk-a69v31q8.js"),S=n.stxOptions?.serverApi??h.serverApi,T=await x(f,S),w=h.root&&h.root!=="."?te.join(f,h.root):f,y=n.pagesDir||h.pagesDir||"pages",k=te.join(w,y);if(!fe.existsSync(k)&&!h._layerPageDirs?.some((P)=>fe.existsSync(P)))return console.error(`${e.red}Error: No '${y}' 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 ${y}/index.stx for the homepage.${e.reset}`),!1;let M=X(w,{pagesDir:y,pagesDirs:h._layerPageDirs?[k,...h._layerPageDirs.slice(1)]:void 0});if(M.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}${M.length}${e.blue} routes${e.reset}`);let E=h?._pluginPageDirs||[],R=[];for(let{dir:P,prefix:I}of E)if(fe.existsSync(P)){let N=X(te.dirname(P),{pagesDir:te.basename(P)});for(let Q of N){let q=I==="/"?Q.pattern:`${I}${Q.pattern==="/"?"":Q.pattern}`;R.push({route:{...Q,pattern:q},prefix:I})}if(N.length>0)console.log(`${e.blue}Plugin pages: ${e.bright}${N.length}${e.blue} routes at ${e.cyan}${I}${e.reset}`)}let A=new Map,C=null,D=null;if(n.stxOptions?.shell!==!1){if(D=await ga(f,n.stxOptions?.shell),D){if(C=await wo(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}`)}}Ct(),await Tt(f);let L=Et();if(L.length>0)console.log(`${e.blue}Loaded ${e.bright}${L.length}${e.blue} middleware: ${e.dim}${L.join(", ")}${e.reset}`);let V={},Y=null;try{let{loadStxConfig:P}=await import("./chunk-6ra9dqs2.js"),I=await P(f);if(I?.apiRouter)Y=I?.apiRouter,console.log(`${e.blue}Using custom router for API handling${e.reset}`);if(I?.apiRoutes){V=I.apiRoutes;let N=Object.keys(V).length;if(N>0)console.log(`${e.blue}Loaded ${e.bright}${N} API route${N>1?"s":""}${e.reset}`)}if(I?.broadcasting?.enabled)try{let{startBroadcasting:N,loadChannels:Q}=await import("./chunk-k1pyzf9e.js"),q=I.broadcasting;await N(q);let Pe=q.port??6001;console.log(`${e.magenta}Broadcasting on ${e.cyan}ws://localhost:${Pe}/ws${e.reset}`);let xe=te.join(process.cwd(),"channels.ts");if(fe.existsSync(xe))try{let U=await Q(xe);console.log(`${e.blue}Loaded ${e.bright}${U} broadcast channel${U!==1?"s":""}${e.blue} from channels.ts${e.reset}`)}catch(U){console.warn(`${e.yellow}Failed to load channels.ts: ${U.message}${e.reset}`)}}catch(N){console.warn(`${e.yellow}Broadcasting failed to start: ${N.message}${e.reset}`)}}catch{}let be=c(f,"output");fe.mkdirSync(be,{recursive:!0});let le=new Map,Ce=new Set,ne=async(P)=>{let I=Is(k,P);if(!I)return null;try{let N=await Bun.build({entrypoints:[I],outdir:be,plugins:[rt],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...n.stxOptions});if(!N.success)return null;let Q=N.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(P,I)=>{try{let{processDirectives:N,extractVariables:Q,defaultConfig:q,loadStxConfig:Pe,injectRouterScript:xe}=await import("./chunk-6ra9dqs2.js"),{checkCache:U,cacheTemplate:J,readFileCached:W,templateCache:de}=await import("./chunk-jmjz23rf.js"),K=await Pe(f),Ue=(se)=>{if(!se)return se;if(te.isAbsolute(se))return se;return te.resolve(f,se)},ie={...q,...K,...n.stxOptions,autoShell:!0};if(n.debugDirectives)ie.debug=!0;ie.partialsDir=Ue(ie.partialsDir),ie.componentsDir=Ue(ie.componentsDir),ie.layoutsDir=Ue(ie.layoutsDir),ie.storesDir=Ue(ie.storesDir||"stores"),ie.cachePath=Ue(ie.cachePath)??c(f,"cache");let H=!I&&!n.profile,re=ie.cache!==!1;if(re&&H){let se=de.get(P.filePath);if(se)try{if((await fe.promises.stat(P.filePath)).mtime.getTime()<=se.mtime){let He=!0;for(let Se of se.dependencies){if(!fe.existsSync(Se)){He=!1;break}if((await fe.promises.stat(Se)).mtime.getTime()>se.mtime){He=!1;break}}if(He){let Se=se.output;if(C)Se=qe(Se,{preserveHead:!0});let st=F.get(P.filePath);return{route:P,content:Se,status:st?.status??await ln(P.filePath),headers:st?.headers}}}}catch{}let Ie=await U(P.filePath,ie);if(Ie){let je=Ie;if(C)je=qe(je,{preserveHead:!0});let He=F.get(P.filePath);return{route:P,content:je,status:He?.status??await ln(P.filePath),headers:He?.headers}}}let Z=re?await W(P.filePath):await Bun.file(P.filePath).text(),oe=yn(Z),{classifyAllScripts:ue}=await import("./chunk-6ra9dqs2.js"),B=ue(Z),Le=B.server.map((se)=>se.content),De=Z;for(let se of B.server)De=De.replace(se.fullTag,"");let ee={__filename:P.filePath,__dirname:te.dirname(P.filePath),__stx_options:ie,params:I??{},__stx_runtime_head:{}};for(let se of Le)try{await Q(se,ee,P.filePath)}catch(Ie){if(n.stxOptions?.debug)console.error("[stx] variable extraction error",P.filePath,Ie?.message||Ie)}let Oe=new Set,he;if(n.profile){let se=performance.now();he=await N(De,ee,P.filePath,ie,Oe);let Ie=performance.now()-se,je=te.relative(f,P.filePath)||P.filePath;console.log(`[stx:profile] ${je} \u2192 ${Ie.toFixed(2)}ms`)}else he=await N(De,ee,P.filePath,ie,Oe);if(!C)he=await xe(he,{router:ie.router});{let{interpolateScriptExpressions:se}=await import("./chunk-47z5w330.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}>${se(He,ee)}</script>`})}if(C)he=qe(he,{preserveHead:!0});if(re&&H)await J(P.filePath,he,Oe,ie);let{extractStreamBoundaries:ct}=await import("./chunk-epqp6mmn.js"),Qe=ct(ee),ot=ee.__streamTemplates;if(ot&&typeof ot==="object"&&Object.keys(ot).length>0){let se=ee.streamBoundaries||{},Ie={...ie,autoShell:!1},je=Object.keys(ot).map((Se)=>({id:Se,render:async()=>{let st=typeof se[Se]==="function"?await se[Se]():void 0;return N(ot[Se],{...ee,$boundary:st},P.filePath,Ie,new Set)}})),He=new Set(je.map((Se)=>Se.id));Qe=[...(Qe||[]).filter((Se)=>!He.has(Se.id)),...je]}if(Qe&&Qe.length>0)Ce.add(P.pattern);else Qe=void 0;let Vt=Mt(ee),qt=Dt(ee);if(H)F.set(P.filePath,{status:Vt,headers:qt});return{route:P,content:he,status:Vt??oe,headers:qt,boundaries:Qe}}catch(N){return console.error(`${e.red}Error building ${e.bright}${P.pattern}${e.reset}:`,N),null}},Fe=8,ze=async()=>{let P=new Set(le.keys()),I=new Set(A.keys());le.clear(),A.clear();let N=n.prebuild===!1?M.filter((q)=>P.has(q.pattern)):M,Q=n.prebuild===!1?R.filter(({route:q})=>I.has(q.pattern)):R;for(let q=0;q<N.length;q+=Fe){let Pe=N.slice(q,q+Fe),xe=await Promise.all(Pe.map((U)=>_(U)));for(let U of xe)if(U)le.set(U.route.pattern,U)}for(let q=0;q<Q.length;q+=Fe){let Pe=Q.slice(q,q+Fe),xe=await Promise.all(Pe.map(({route:U})=>_(U)));for(let U of xe)if(U)A.set(U.route.pattern,U)}return le.size>0};if(console.log(`${e.blue}${n.prebuild===!1?"Rendering pages on request...":"Building pages..."}${e.reset}`),!(n.prebuild===!1?M.length+R.length>0:await ze()))return console.error(`${e.red}No pages were successfully built${e.reset}`),!1;await dn(f);let Ge=r;try{if(Ge=await We(r),Ge!==r)console.log(`${e.yellow}Port ${r} is busy, using port ${Ge} instead${e.reset}`)}catch{return console.error(`${e.red}Could not find an available port${e.reset}`),!1}if(o){let P=n.hmrPort||Ge+1;l=xt({wsPort:P,verbose:!1}),u=l.start(P)}let kt=(P,I)=>{let Q=`<script data-stx-route-params>(function(){var p=${JSON.stringify(I).replace(/</g,"\\u003C").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;if(P.includes("</head>"))return P.replace("</head>",`${Q}</head>`);if(P.includes("<body"))return P.replace(/<body([^>]*)>/,`<body$1>${Q}`);return Q+P};console.log(`${e.blue}Starting server...${e.reset}`);let Pt=Fr({port:Ge,hostname:n.hostname,async fetch(P){let I=new URL(P.url),N=n.stxOptions?.offline??h.offline;if(I.pathname===jo&&N?.enabled){if(!["GET","HEAD"].includes(P.method))return new Response("Method Not Allowed",{status:405,headers:{Allow:"GET, HEAD"}});return new Response(P.method==="HEAD"?null:Bo(N,ls()),{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,I.pathname),Pe=te.join(f,I.pathname),xe=te.join(be,I.pathname);if([q,Pe,xe].some((H)=>v(H,f,S)))return new Response("Not Found",{status:404});let[U,J,W]=await Promise.all([fe.promises.stat(q).catch(()=>null),fe.promises.stat(Pe).catch(()=>null),fe.promises.stat(xe).catch(()=>null)]);if(U?.isFile()&&!v(q,f,S))return Nt(q);if(J?.isFile()&&!v(Pe,f,S))return Nt(Pe);if(W?.isFile()&&!v(xe,f,S))return Nt(xe);if(I.pathname.startsWith("/_stx/component/")){let H=decodeURIComponent(I.pathname.slice(16));if(H)try{let re=`<${H} />`,Z={...buildConfig,autoShell:!1},oe=await processDirectives(re,{},te.join(f,"components",`${H}.stx`),Z,new Set);return new Response(oe,{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(I.pathname==="/_stx/img"){let{handleImageRequest:H}=await import("./chunk-m276y4f3.js"),re=await H(P,{publicDir:te.join(f,Q),cacheDir:c(f,"cache","img")});if(re)return re}if(Y)try{let H=await Y.handleRequest(P);if(H.status!==404)return H}catch{}if(V[I.pathname])try{return await V[I.pathname](P)}catch(H){return new Response(JSON.stringify({error:H.message}),{status:500,headers:{"Content-Type":"application/json"}})}let de=await T(P);if(de)return de;let K=hr(I.pathname,M);if(K){let H=le.get(K.route.pattern),re=Ce.has(K.route.pattern);if(!H||K.route.isDynamic&&Object.keys(K.params).length>0||re){let Z=await _(K.route,K.params);if(Z){if(H=Z,!K.route.isDynamic&&!re)le.set(K.route.pattern,Z)}}if(H){let Z=H.status??200,oe=H.headers??{},ue=(K.route.filePath?wt(await Bun.file(K.route.filePath).text().catch(()=>"")):null)??{};if(ue.validate){if(!await ue.validate({params:K.params})){let De=await ne(404);if(De){let ee=De;if(ee=await b(ee,f),o)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(I.pathname,K.params,ue,I.search),De=Rt(Le,null,P,{isServer:!0}),ee=await At(ue.middleware,De);if(ee.redirect){let Oe=ee.redirect.path,he=ee.redirect.options.redirectCode||302,ct=new Headers(ee.responseHeaders);return ct.set("Location",Oe),new Response(null,{status:he,headers:ct})}if(ee.abort){let{statusCode:Oe,message:he}=ee.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${Oe}</title></head><body><h1>Error ${Oe}</h1><p>${he}</p></body></html>`,{status:Oe,headers:{"Content-Type":"text/html"}})}if(Object.keys(ee.state).length>0){let Oe=`<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>",`${Oe}</head>`)}}let B=H.content;if(C&&ma(P)&&Ke(B,h?.router?.container||"main")){let Le=tt(B),De=we(B),ee=B.match(/<title[^>]*>([\s\S]*?)<\/title>/i),Oe=ee?Jt(ee[1].trim()):"";if(Object.keys(K.params).length>0)B=kt(B,K.params);B=await b(B,f);let he=h?.router?.container||"main";return B=Te(B,he,!0),new Response(B,{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",...Oe&&{"X-STX-Title":encodeURIComponent(Oe)},[uc]:ls(),...j(),"Cache-Control":mt}})}if(C)B=Jr(C,B);if(Object.keys(K.params).length>0)B=kt(B,K.params);if(B=await b(B,f),o)B=Ne(B,u);if(n.native)if(B.includes("<head>"))B=B.replace("<head>","<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script>");else B="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+B;if(n.titlebarHidden)if(B.includes("<head>"))B=B.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 B=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${B}`;if(H.boundaries&&H.boundaries.length>0){let{renderStreamingPage:Le,streamToResponse:De}=await import("./chunk-epqp6mmn.js");return De(Le(B,H.boundaries,{timeoutMs:30000}),{status:Z,headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(B,{status:Z,headers:{"Content-Type":"text/html",...j(),"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0",...oe}})}}if(R.length>0){let H=R.map((Z)=>Z.route),re=hr(I.pathname,H);if(re){let Z=A.get(re.route.pattern);if(!Z||re.route.isDynamic){let oe=await _(re.route,re.params);if(oe){if(Z=oe,!re.route.isDynamic)A.set(re.route.pattern,oe)}}if(Z){let oe=Z.content;if(C)oe=Jr(C,oe);if(Object.keys(re.params).length>0)oe=kt(oe,re.params);if(oe=await b(oe,f),o)oe=Ne(oe,u);return new Response(oe,{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!=="/"&&I.pathname.startsWith(Z)){let oe=A.get(Z)||A.get(Z+"/");if(!oe){let ue=R.find(({route:B})=>B.pattern===Z||B.pattern===`${Z}/`);if(ue){let B=await _(ue.route);if(B)oe=B,A.set(ue.route.pattern,B)}}if(oe){let ue=oe.content;if(C)ue=Jr(C,ue);if(ue=await b(ue,f),o)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(_t(I.pathname))return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}});let Ue=le.get("/");if(Ue){let H=Ue.content;if(H=await b(H,f),o)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 ie=await ne(404);if(ie){let H=ie;if(H=await b(H,f),o)H=Ne(H,u);return new Response(H,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(P){let I=await ne(500);if(I)return new Response(I,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${P}
|
|
1441
1441
|
${P.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});if(console.clear(),console.log(`
|
|
1442
1442
|
${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(`
|
|
1443
1443
|
${e.bright}\u2192 ${e.cyan}http://localhost:${Ge}/${e.reset}`),o)console.log(`${e.dim} HMR: ws://localhost:${u}${e.reset}`);console.log(`
|
|
1444
1444
|
${e.yellow}Routes:${e.reset}`);let Ot=[...Os(M,f)];for(let{route:P}of R)Ot.push(`${P.pattern}`);if(Ot.forEach((P,I)=>{let Q=I===Ot.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${e.green}${Q}${e.reset}${P}`)}),console.log(`
|
|
1445
|
-
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ve(Pt.url.toString(),()=>{if(l)it();Pt.stop()}),n.native){let P,I=te.join(k,"index.stx");if(fe.existsSync(I)){let Q=await Bun.file(I).text();P=gt(Q)}let N=h?.app?.window??{};await Ze(Ge,{title:h?.app?.head?.title||te.basename(f)||"stx App",width:N.width,height:N.height,darkMode:N.darkMode,hotReload:N.hotReload,titlebarHidden:N.titlebarHidden??n.titlebarHidden===!0,nativeSidebar:!!P,sidebarConfig:P})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let P=(U)=>U.startsWith("public/")||U.startsWith("public\\"),I=(U)=>{let J=U.toLowerCase();return J.endsWith(".stx")||J.endsWith(".html")||J.endsWith(".md")},N=new Map,Q=()=>{let U=new Set([f,...h._layerGraph?.layers.map((J)=>J.root)??[],...h._layerGraph?.configDependencies.map((J)=>te.dirname(J))??[]].filter((J)=>fe.existsSync(J)).map((J)=>fe.realpathSync(J)));for(let J of h._layerGraph?.layers??[])for(let W of Object.values(J.resources)){if(!fe.existsSync(W))continue;let de=fe.realpathSync(W);if(![...U].some((K)=>de===K||de.startsWith(`${K}${te.sep}`)))U.add(de)}for(let[J,W]of N)if(!U.has(J))W.close(),N.delete(J);for(let J of U)if(!N.has(J)&&fe.existsSync(J))N.set(J,fe.watch(J,{recursive:!0},(W,de)=>{Pe(J,W,de).catch((K)=>console.error("[stx] Layer rebuild failed:",K))}))},q=Promise.resolve(),Pe=(U,J,W)=>(q=q.catch(()=>{}).then(()=>xe(U,J,W)),q),xe=async(U,J,W)=>{if(!W||bt(W))return;if(yt(W)){if(h._layerGraph){let de=await g(f);Object.assign(h,de),M.splice(0,M.length,...X(w,{pagesDir:y,pagesDirs:de._layerPageDirs?[k,...de._layerPageDirs.slice(1)]:void 0})),Q()}if(P(W)){if(console.log(`${e.cyan}${W} changed${e.reset}`),o&&l)l.reload(W)}else if(I(W)){console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),Ye.clear(),ge();try{let{invalidateFileCache:de,templateCache:K}=await import("./chunk-
|
|
1445
|
+
Press ${e.cyan}h${e.reset} + ${e.cyan}Enter${e.reset} to show shortcuts`),Ve(Pt.url.toString(),()=>{if(l)it();Pt.stop()}),n.native){let P,I=te.join(k,"index.stx");if(fe.existsSync(I)){let Q=await Bun.file(I).text();P=gt(Q)}let N=h?.app?.window??{};await Ze(Ge,{title:h?.app?.head?.title||te.basename(f)||"stx App",width:N.width,height:N.height,darkMode:N.darkMode,hotReload:N.hotReload,titlebarHidden:N.titlebarHidden??n.titlebarHidden===!0,nativeSidebar:!!P,sidebarConfig:P})}if(d){console.log(`${e.blue}Watching for changes...${e.reset}`);let P=(U)=>U.startsWith("public/")||U.startsWith("public\\"),I=(U)=>{let J=U.toLowerCase();return J.endsWith(".stx")||J.endsWith(".html")||J.endsWith(".md")},N=new Map,Q=()=>{let U=new Set([f,...h._layerGraph?.layers.map((J)=>J.root)??[],...h._layerGraph?.configDependencies.map((J)=>te.dirname(J))??[]].filter((J)=>fe.existsSync(J)).map((J)=>fe.realpathSync(J)));for(let J of h._layerGraph?.layers??[])for(let W of Object.values(J.resources)){if(!fe.existsSync(W))continue;let de=fe.realpathSync(W);if(![...U].some((K)=>de===K||de.startsWith(`${K}${te.sep}`)))U.add(de)}for(let[J,W]of N)if(!U.has(J))W.close(),N.delete(J);for(let J of U)if(!N.has(J)&&fe.existsSync(J))N.set(J,fe.watch(J,{recursive:!0},(W,de)=>{Pe(J,W,de).catch((K)=>console.error("[stx] Layer rebuild failed:",K))}))},q=Promise.resolve(),Pe=(U,J,W)=>(q=q.catch(()=>{}).then(()=>xe(U,J,W)),q),xe=async(U,J,W)=>{if(!W||bt(W))return;if(yt(W)){if(h._layerGraph){let de=await g(f);Object.assign(h,de),M.splice(0,M.length,...X(w,{pagesDir:y,pagesDirs:de._layerPageDirs?[k,...de._layerPageDirs.slice(1)]:void 0})),Q()}if(P(W)){if(console.log(`${e.cyan}${W} changed${e.reset}`),o&&l)l.reload(W)}else if(I(W)){console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),Ye.clear(),ge();try{let{invalidateFileCache:de,templateCache:K}=await import("./chunk-jmjz23rf.js");de(te.resolve(U,W)),K.delete(te.resolve(U,W))}catch{}if(D&&W){if(te.resolve(U,W)===D||te.basename(D)===W){let K=await wo(D,n.stxOptions||{});if(K)C=K}}if(await ze(),await cr(f),o&&l)l.reload(W)}else{console.log(`${e.yellow}${W} changed, rebuilding...${e.reset}`),Ye.clear(),ge();try{let{invalidateFileCache:de,templateCache:K}=await import("./chunk-jmjz23rf.js");de(te.resolve(U,W)),K.delete(te.resolve(U,W))}catch{}if(await ze(),o&&l)l.reload(W)}}else if(ht(W)){if(console.log(`${e.cyan}CSS ${W} changed${e.reset}`),o&&l)l.updateCss(W)}};Q(),process.on("SIGINT",()=>{for(let U of N.values())U.close();if(l)it();Pt.stop(),process.exit(0)})}return!0}import Ut from"fs";import at from"path";async function zr(t){try{let r=(await Bun.file(t).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!r)return[];let d=r[1],o=[],l=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,u;while((u=l.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(`
|
|
1446
1446
|
`).map((w)=>w.trim().replace(/^\*\s*/,"")).filter((w)=>!w.startsWith("@")&&w.length>0);h.description=T.join(" ").trim(),o.push(h)}if(o.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)o.push({name:v})}}}return o}catch(n){return console.error(`Error extracting props from ${t}:`,n),[]}}async function Nr(t){try{let n=await Bun.file(t).text(),r=n.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||n.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(r)return r[1].split(`
|
|
1447
1447
|
`).map((d)=>d.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function Vr(t,n=!1,r){let d=at.basename(t,".stx"),o=await zr(t),l=await Nr(t),u="";if(n&&r)u=`<${r}></${r}>`;else{let f=o.map((g)=>{if(g.type==="boolean")return`:${g.name}="true"`;return`${g.name}="value"`}).join(`
|
|
1448
1448
|
`);u=`<${d}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Vh,ys,Go,bs,ur,Xo,Jo,Vf,ws,vs,xs,Yo,mc,Uf,xt}from"./chunk-
|
|
2
|
+
import{Vh,ys,Go,bs,ur,Xo,Jo,Vf,ws,vs,xs,Yo,mc,Uf,xt}from"./chunk-w7dks1ev.js";import"./chunk-te090fxv.js";import"./chunk-833y1ndd.js";import"./chunk-c1dkvqr5.js";import"./chunk-tt3jxdy5.js";import"./chunk-jtccqpwa.js";import"./chunk-2rg9pqmh.js";import"./chunk-0rszcb0m.js";import"./chunk-8cvgm13s.js";import{V}from"./chunk-r53tqxmq.js";import"./chunk-n2z4kyba.js";import"./chunk-v4bqmzj9.js";import"./chunk-k47addf7.js";import"./chunk-xppm4cs4.js";import"./chunk-agbkv9ab.js";export{Vf as bindLoopInterpolations,Vh as clearScriptScanCache,ws as convertServerLoopAttributesToDirectives,Xo as convertSignalDirectivesToAttributes,vs as convertSignalLoopsToAttributes,ur as extractClientSignalNames,V as extractExports,mc as findMarkupIndexOutsideScripts,bs as hasSignalsSyntax,Go as parseLoopExpression,Jo as preEvalLiteralReactiveIfs,xs as processScriptSetup,Yo as processSignals,Uf as rewriteStxImportSpecifiers,ys as scanScriptTags,xt as stripStxRuntimeImports};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{hs,zf,Uo,Hf}from"./chunk-
|
|
2
|
+
import{hs,zf,Uo,Hf}from"./chunk-tn9h4prj.js";import"./chunk-m710wkr4.js";import"./chunk-w7dks1ev.js";import"./chunk-te090fxv.js";import"./chunk-833y1ndd.js";import"./chunk-c1dkvqr5.js";import"./chunk-tt3jxdy5.js";import"./chunk-jtccqpwa.js";import"./chunk-2rg9pqmh.js";import"./chunk-0rszcb0m.js";import"./chunk-8cvgm13s.js";import{Nt}from"./chunk-r53tqxmq.js";import"./chunk-n2z4kyba.js";import"./chunk-v4bqmzj9.js";import"./chunk-k47addf7.js";import"./chunk-xppm4cs4.js";import"./chunk-agbkv9ab.js";export{Hf as declareBareLoopHead,Nt as parseLoopBinding,zf as processLoops,Uo as processLoopsAsync,hs as reportDeferredLoopWarnings};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Bt,ae,_,u,f,P,t,ce,K,l,_e,Ai,z,En,Pi,Ht,Ii,dl,Ir,pl,ct,fl,Or,gl,Tn,Oi,ml,Nr,Dr,Ce,Ni}from"./chunk-k47addf7.js";import{pi,Mc,o,C,Ne,Ot,mn,Me,fe,J,kr,hn,Vs,Wc,qc,bn,$r,Ws,qs,Kc,wi,Gc,Xc,Jc,Yc,Le,je,Ks,ze,s,xn,h,p,W,Q,ke,E,Ei}from"./chunk-
|
|
2
|
+
import{Bt,ae,_,u,f,P,t,ce,K,l,_e,Ai,z,En,Pi,Ht,Ii,dl,Ir,pl,ct,fl,Or,gl,Tn,Oi,ml,Nr,Dr,Ce,Ni}from"./chunk-k47addf7.js";import{pi,Mc,o,C,Ne,Ot,mn,Me,fe,J,kr,hn,Vs,Wc,qc,bn,$r,Ws,qs,Kc,wi,Gc,Xc,Jc,Yc,Le,je,Ks,ze,s,xn,h,p,W,Q,ke,E,Ei}from"./chunk-r53tqxmq.js";import{jt}from"./chunk-v4bqmzj9.js";import{_n}from"./chunk-n2z4kyba.js";import{b}from"./chunk-cm5kpn54.js";import{br,Ns}from"./chunk-8cvgm13s.js";import{wc,vc,mr,et,xc,O}from"./chunk-c1dkvqr5.js";import{ri,si,oi,ii}from"./chunk-0rszcb0m.js";import{gc,ms}from"./chunk-e0dgx3ev.js";import{us,ds,ps}from"./chunk-d5m6xy9p.js";import{bs,Xo,Jo,ws,vs,Yo}from"./chunk-w7dks1ev.js";import{hs,Uo}from"./chunk-tn9h4prj.js";import{Fo}from"./chunk-t5q31st4.js";import{oe,Wo,qo,Ko}from"./chunk-m710wkr4.js";import{dr,we,hc,pr,yc}from"./chunk-te090fxv.js";import{B,Ze}from"./chunk-ybq56wam.js";import{Sc,kc}from"./chunk-tt3jxdy5.js";import{T,$n,Mi}from"./chunk-ym5qgw03.js";import Kn from"fs";import ie from"path";function dt(n){let e=Ot(n),c=e.find((x)=>x.closing&&x.name.toLowerCase()==="head");if(!c)return n;let a=new Set(["template","svg","noscript","math","textarea","title","xmp","iframe","noembed","noframes","plaintext"]),g=0,r=[];for(let x=0;x<e.length;x++){let w=e[x];if(w.start<c.end)continue;let v=w.name.toLowerCase();if(a.has(v)){g=Math.max(0,g+(w.closing?-1:w.selfClosing?0:1));continue}if(v!=="style"||w.closing||g>0)continue;let k=e[x+1];if(k?.name.toLowerCase()==="style"&&k.closing){if(/@scope\s*\{/.test(n.slice(w.end,k.start)))continue;r.push({start:w.start,end:k.end}),x++}}if(!r.length)return n;let d=r.map((x)=>n.slice(x.start,x.end)).join(`
|
|
3
3
|
`),y=[n.slice(0,c.start),d,`
|
|
4
4
|
`],m=c.start;for(let x of r)y.push(n.slice(m,x.start)),m=x.end;return y.push(n.slice(m)),y.join("")}function pt(){return`
|
|
5
5
|
// STX Lifecycle Runtime
|
|
@@ -1295,7 +1295,7 @@ ${R}
|
|
|
1295
1295
|
</style>`;a=a.replace(x,D),y.lastIndex=0}catch(R){}}}return a}import it from"path";var Wn=/(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+)(['"])(\.\.?\/[^'"]*)\2/g,Xn=/(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi;function zn(n,e){if(!e||!n.includes("/"))return n;let c=it.dirname(e);return n.replace(Wn,(a,g,r,d)=>{let y=it.resolve(c,d);return`${g}${r}${y.split(it.sep).join("/")}${r}`})}function lr(n,e){if(!e||!n.includes("<script"))return n;return n.replace(Xn,(c,a,g,r)=>`${a}${zn(g,e)}${r}`)}var Ee="<!--PARENT_CONTENT_PLACEHOLDER-->";function ur(n){return n.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function xr(n,e){let c=n.length,a=e,g=!0,r=[],d=(y)=>y+9<=c&&n[y]==="<"&&n[y+1]==="/"&&(n[y+2]==="s"||n[y+2]==="S")&&(n[y+3]==="c"||n[y+3]==="C")&&(n[y+4]==="r"||n[y+4]==="R")&&(n[y+5]==="i"||n[y+5]==="I")&&(n[y+6]==="p"||n[y+6]==="P")&&(n[y+7]==="t"||n[y+7]==="T")&&(n[y+8]===">"||/\s/.test(n[y+8]));while(a<c){let y=n[a];if(d(a))return a;if(y==="/"&&n[a+1]==="/"){if(a=n.indexOf(`
|
|
1296
1296
|
`,a+2),a===-1)return-1;a+=1,g=!0;continue}if(y==="/"&&n[a+1]==="*"){let m=n.indexOf("*/",a+2);if(m===-1)return-1;a=m+2,g=!0;continue}if(y==="/"&&g){let m=a+1,x=!1;while(m<c){let w=n[m];if(w==="\\"){m+=2;continue}if(w==="[")x=!0;else if(w==="]")x=!1;else if(w==="/"&&!x){m++;break}else if(w===`
|
|
1297
1297
|
`){m=-1;break}m++}if(m===-1){a++,g=!1;continue}while(m<c&&/[a-z]/.test(n[m]))m++;a=m,g=!1;continue}if(y==="'"||y==='"'){let m=y;a++;while(a<c){if(n[a]==="\\"){a+=2;continue}if(n[a]===m){a++;break}if(n[a]===`
|
|
1298
|
-
`)break;a++}g=!1;continue}if(y==="`"){a++;while(a<c){if(n[a]==="\\"){a+=2;continue}if(n[a]==="`"){a++;break}if(n[a]==="$"&&n[a+1]==="{"){r.push(!0),a+=2,g=!0;break}a++}if(r.length===0)g=!1;continue}if(y==="}"&&r.length>0){r.pop(),a++;while(a<c){if(n[a]==="\\"){a+=2;continue}if(n[a]==="`"){a++,g=!1;break}if(n[a]==="$"&&n[a+1]==="{"){r.push(!0),a+=2,g=!0;break}a++}continue}if(/\s/.test(y));else if(/[)\].\w$]/.test(y))g=!1;else g=!0;a++}return-1}function Sr(n,e){let c=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(`<script\\b(?=[^>]*\\b${c}(?:\\s|=|/?>))[^>]*>`,"i").exec(n);if(!a)return null;let g=a.index+a[0].length,r=n.indexOf("</script>",g);if(r===-1)return null;let d=n.indexOf(">",r);if(d===-1)return null;return{start:a.index,end:d+1}}var Gn=4096;async function ot(n,e,c){if(c.buildMode!=="serve"||e.length<Gn)return null;let{registerServeModuleBundle:a}=await import("./chunk-
|
|
1298
|
+
`)break;a++}g=!1;continue}if(y==="`"){a++;while(a<c){if(n[a]==="\\"){a+=2;continue}if(n[a]==="`"){a++;break}if(n[a]==="$"&&n[a+1]==="{"){r.push(!0),a+=2,g=!0;break}a++}if(r.length===0)g=!1;continue}if(y==="}"&&r.length>0){r.pop(),a++;while(a<c){if(n[a]==="\\"){a+=2;continue}if(n[a]==="`"){a++,g=!1;break}if(n[a]==="$"&&n[a+1]==="{"){r.push(!0),a+=2,g=!0;break}a++}continue}if(/\s/.test(y));else if(/[)\].\w$]/.test(y))g=!1;else g=!0;a++}return-1}function Sr(n,e){let c=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=new RegExp(`<script\\b(?=[^>]*\\b${c}(?:\\s|=|/?>))[^>]*>`,"i").exec(n);if(!a)return null;let g=a.index+a[0].length,r=n.indexOf("</script>",g);if(r===-1)return null;let d=n.indexOf(">",r);if(d===-1)return null;return{start:a.index,end:d+1}}var Gn=4096;async function ot(n,e,c){if(c.buildMode!=="serve"||e.length<Gn)return null;let{registerServeModuleBundle:a}=await import("./chunk-jmjz23rf.js");return`<script ${n} src="${a(e)}"></script>`}async function or(n,e,c,a){try{let{registeredModuleIdsIn:g,buildModuleRegistryScript:r}=await o("stx/client-module-registry",()=>import("./chunk-v4kqxe8a.js")),d=[],y=await r(g(...n),{minify:Mi(e.buildMode,e.minifyClient),collectInputs:d});for(let m of d)c?.add(m);if(a)a.inputs=d,a.code=y??void 0;if(!y)return null;if(e.buildMode==="serve"){let{registerServeModuleBundle:m}=await import("./chunk-jmjz23rf.js");return`<script data-stx-scoped data-stx-run="always" data-stx-modules src="${m(y)}"></script>`}return`<script data-stx-scoped data-stx-run="always" data-stx-modules>${y.replace(/<\/script/gi,"<\\/script")}</script>`}catch{return null}}async function Zn(n,e,c,a){let g={modulesTag:null,modulesCode:null,storeTag:null,storeCode:null,composableTag:null,composableCode:null,frameworkScript:null};try{let{getFrameworkComposableScript:k}=await o("stx/framework-composables",()=>import("./chunk-kp2g6sj6.js"));g.frameworkScript=await k(n)}catch{}let r=null;try{r=await o("stx/store-loader",()=>import("./chunk-xkvzg640.js"))}catch{}let d=e.storesDir,y=!!a.__stx_native_screen||(r?.pageStoresAll()??!0),m=y?"":n.replace(/<script\b[^>]*\bdata-stx-(?:runtime|router|hmr)\b[^>]*>[\s\S]*?<\/script>/gi,""),x=[],w=[],v=null;for(let k=0;k<8;k++){let S=null,M="",A=!1;try{if(r){let N=y?await r.getStoreScript(d).then((F)=>F?{code:F,stores:["*"],functions:null}:null):await r.getStoreScriptFor(d,[m],{reads:r.storesReadInFiles([...x,...w]),runOnce:!0});if(N)S=N.code,M=N.stores.join(","),A=!!N.functions&&!y}}catch{}if(v!==null&&M===v)break;v=M;let R=A?'data-stx-scoped data-stx-run="always" data-stx-stores':"data-stx-stores",D=S?`<script ${R}>${S}</script>`:null;g.storeCode=S,g.storeTag=S?await ot(R,S,e)??D:null;let j={};g.modulesTag=await or([n,D],e,c,j),g.modulesCode=j.code??null,x=j.inputs??[],g.composableTag=null,g.composableCode=null,w=[];try{let{getComposableScript:N}=await o("stx/composable-loader",()=>import("./chunk-et9fyzf6.js")),F=e.composablesDir,I=[g.modulesCode??g.modulesTag,D,g.frameworkScript].filter((H)=>H!==null),L=await N(e._layerComposableDirs??F,n,I,w);if(L)g.composableCode=L,g.composableTag=await ot('data-stx-scoped data-stx-run="always" data-stx-composables',L,e)??`<script data-stx-scoped data-stx-run="always" data-stx-composables>${L}</script>`}catch{}if(y||!r)break}return g}async function Jn(n,e,c,a={}){let{withModuleSubstitutes:g,moduleSubstitutionKey:r}=await import("./chunk-x1c1aggq.js"),d=await import("./chunk-ydjy26ch.js"),{messages:y,webModules:m}=e,x=null,w=null,v=r()===""&&!a.__stx_native_screen;if(y&&d.pageMessagesEnabled(e)&&v)try{x=await d.loadPageMessages(process.cwd(),y)}catch(R){Qn(R)}if(m&&Object.keys(m).length&&v)try{w=await(await import("./chunk-g046t3hb.js")).loadWebModules(process.cwd(),m)}catch(R){Yn(R)}let k=new Map([...w??[],...x?.stubs??[]]),S=()=>Zn(n,e,c,a),M=k.size?await g(k,S):await S(),A=null;if(x){let R=d.messageAreasIn(M.modulesCode,M.storeCode,M.composableCode),D=d.pageMessagesScript(x,d.pageLanguages(n,x),R);if(D)A=await ot('data-stx-scoped data-stx-run="always" data-stx-messages',D,e)??`<script data-stx-scoped data-stx-run="always" data-stx-messages>${D.replace(/<\/script/gi,"<\\/script")}</script>`}return[A,M.modulesTag,M.storeTag,M.composableTag,M.frameworkScript].filter((R)=>R!==null)}var fr=!1;function Qn(n){if(fr)return;fr=!0,console.warn(`[stx] messages: ${n instanceof Error?n.message:String(n)}; pages ship every language`)}var gr=!1;function Yn(n){if(gr)return;gr=!0,console.warn(`[stx] ${n instanceof Error?n.message:String(n)}; pages bundle the real modules`)}function es(n,e=""){let c=Sr(n,"data-stx-runtime");if(!c)return n;let a=dr(n);if(a===-1||a===c.start){if(!e)return n;return n.slice(0,c.end)+e+n.slice(c.end)}if(a<c.start)return n.slice(0,a)+n.slice(c.start,c.end)+e+`
|
|
1299
1299
|
`+n.slice(a,c.start)+n.slice(c.end);let g=n.slice(c.start,c.end),r=n.slice(0,c.start)+n.slice(c.end),d=dr(r);if(d===-1)return g+e+`
|
|
1300
1300
|
`+r;return r.slice(0,d)+g+e+`
|
|
1301
1301
|
`+r.slice(d)}function ts(n){let e=/\x00STX_ESC_MUSTACHE_OPEN\x00([\s\S]*?)\x00STX_ESC_MUSTACHE_CLOSE\x00/g;return n.replace(e,(c,a,g)=>{let r=n.slice(0,g);return r.lastIndexOf("<")>r.lastIndexOf(">")?`{{${a}}}`:`{<!--stx-literal-->{${a}}}`})}async function i(n,e,c,a,g){if(await _(),a.ssr===!1&&!a.autoShell&&a.buildMode==="spa")return n;if(e.__stx_signals_gate===void 0)e.__stx_signals_gate=ke(n,c);let r=!e.__stxProcessingDepth;bn(e);for(let d of a._layerGraph?.configDependencies??[])g.add(d);if(r&&a.runtimeConfig)await _n(e,c,a.runtimeConfig);if(r)Jc(e),e.__stx_scope_seq??={n:0,key:Ks(String(e.__filename??c))},e.__stx_head_injections=Ii(),e.__stx_seo_staged=!1;if(!e.__stxProcessingDepth)e.__stxProcessingDepth=0;if(e.__stxProcessingDepth++,!e.__onceStore)e.__onceStore=new Set;if((a.debug||!T()&&!$n())&&c&&c.endsWith(".stx"))Fo(n,c);try{return await ae.timeAsync("template-processing",async()=>{let d=await rs(n,e,c,a,g);if(r)d=wi(d);if(r&&a.autoShell&&a.buildMode!=="compile"){let y=Ce(a.app?.head,{known:Dr,source:"app.head"}),x=(e.__stx_runtime_head||null)??Ni(),w=(e.__stx_head_raw||"").trim(),v,k=w.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(k)v=k[1].trim(),w=w.replace(k[0],"").trim();let S=e.__sections?.title,M=S?E(S,e,c):void 0,A=x.title||v||M,R=!x.title&&(!!v||!!M),D=x.meta||[],j=new Set(D.map((V)=>ct(V)).filter(Boolean)),N={...y,...A&&{title:A},meta:[...(y.meta||[]).filter((V)=>!j.has(ct(V))),...D],link:[...y.link||[],...x.link||[]],script:[...y.script||[],...x.script||[]],headRaw:[y.headRaw,w].filter(Boolean).join(`
|
|
@@ -1310,7 +1310,7 @@ ${m.trim()}
|
|
|
1310
1310
|
@endsection`}}if(D&&m.includes("<script")){let I=J(m),L=I.scripts.map((H)=>hr(H,c)??H);m=kr(I.output,L)}if(m=m.replace(/@section\(\s*['"]([^'"]+)['"]\s*,\s*['"]([^'"]+)['"]\s*\)/g,(I,L,H)=>(R[L]=H,"")),m=m.replace(/@section\(\s*['"]([^'"]+)['"]\s*,\s*([^)]+?)\s*\)/g,(I,L,H)=>{if(/^(['"]).*\1$/.test(H.trim()))return I;try{let V=u(H.trim(),e);if(V===void 0)return I;let ee=(e.__stx_inline_section_values??=[]).push(V)-1;return R[L]=`{{ __stx_inline_section_values[${ee}] }}`,""}catch{return I}}),m=m.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@endsection|@show)/g,(I,L,H)=>{if(H.includes("@parent"))R[L]=H.replace("@parent",Ee);else R[L]=H.trim();return""}),e.__sections=R,m=m.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"](?:,\s*['"]([^'"]+)['"])?\)/g,(I,L,H)=>R[L]||H||""),!("slot"in e)||e.slot===void 0)m=m.replace(/\{\{\s*slot\s*\}\}/g,()=>R.content||"");if(m=ps(m,A),D){let I=[],L=J(m),H=fe(L.output,mn,(V,X)=>`\x00STX_ORPHAN_STYLE_${X}\x00`);if(m=H.output.replace(/\x00STX_(SCRIPT|ORPHAN_STYLE)_(\d+)\x00/g,(V,X,ee)=>{let te=X==="SCRIPT"?hr(L.scripts[Number(ee)],c):H.tokens[Number(ee)];if(te)I.push(te);return""}),I.length>0){let V=I.join(`
|
|
1311
1311
|
`);R.content=R.content?`${R.content}
|
|
1312
1312
|
${V}`:V,e.__sections=R}}if(D)try{let I;if(ie.isAbsolute(D))I=D,g.add(D);else I=await _e(()=>xn(D,c,d,g),null,()=>{throw new ce(`Failed to resolve layout path: ${D}`,c,void 0,void 0,`Layout referenced from ${c}`)});if(!I){let te=(G)=>{if(!G)return[];try{let me=ie.isAbsolute(G)?G:ie.resolve(process.cwd(),G);return Kn.readdirSync(me).filter((ve)=>ve.endsWith(".stx")).map((ve)=>ve.replace(/\.stx$/,""))}catch{return[]}},re=[...te(d.layoutsDir),...te(d.fallbackLayoutsDir)].filter((G,me,ve)=>ve.indexOf(G)===me).sort(),le=[d.layoutsDir,d.fallbackLayoutsDir].filter((G)=>typeof G==="string"&&G.length>0),de=le.length>0?` Searched: ${le.join(", ")} (set \`layoutsDir\` to look elsewhere).`:"",se=`Layout not found: ${D} (referenced from ${c})`+(re.length>0?`. Available layouts: ${re.join(", ")}`:d.layoutsDir?`. No .stx layouts found in ${d.layoutsDir}`:"")+de;if(z.log(Error(se),{layoutPath:D,filePath:c,available:re},"error"),console.error(`[stx] ${se}`),d.debug)throw new ce(se,c);return m}let L=await _e(()=>Bun.file(I).text(),"",()=>{throw new ce(`Failed to read layout file: ${I}`,c,void 0,void 0,"Layout content could not be loaded")});L=lr(L,I);let H=L.match(/@(?:layout|extends)\(\s*['"]([^'"]+)['"]\s*\)/);if(H){if(d.debug)console.log(`Found nested layout: ${H[1]} in ${I}`);let te={},re=L.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@show|@endsection)/g,(se,G,me)=>(te[G]=me.trim(),""));for(let[se,G]of Object.entries(te))if(R[se]&&R[se].includes(Ee)){let me=R[se].indexOf(Ee);R[se]=R[se].slice(0,me)+G+R[se].slice(me+Ee.length)}else if(!R[se])R[se]=G;let le={...e,__sections:R},de=`@layout('${H[1]}')${re}`;return await i(de,le,I,d,g)}let V=L.replace(/\{\{--[\s\S]*?--\}\}/g,""),X=ds(V,A),ee={};return X=X.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@show|@endsection)/g,(te,re,le)=>(ee[re]=le.trim(),`@slot('${re}')`)),X=X.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(te,re,le)=>{if(R[re]){let de=R[re];if(de.includes(Ee)){let se=ee[re]||"",G=de.indexOf(Ee);de=de.slice(0,G)+se+de.slice(G+Ee.length)}return de}return le||""}),X=ns(X,R),X=X.replace(/\{\{\s*slot\s*\}\}/g,()=>R.content||""),X=ps(X,A),e.__originalFilePath=c,m=await vr(X,e,I,d,g),m=`<!-- stx-layout: ${D} -->
|
|
1313
|
-
${m}`,v(m)}catch(I){if(I instanceof K)throw I;throw new ce(`Error processing layout ${D}: ${I instanceof Error?I.message:String(I)}`,c)}return v(await vr(m,e,c,d,g))}function ns(n,e){return n.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(c,a,g)=>{let r=e[a];if(r!==void 0){if(!new RegExp(`@(?:yield|slot)\\(\\s*['"]${a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}['"]`).test(r))return r}return g||""})}function ss(n,e){if(n.__stx_sfc_mode=!0,n.__stx_options=e,e.buildMode)n.__stx_buildMode=e.buildMode;let c=e.envPrefix||"STX_PUBLIC_",a={};for(let[g,r]of Object.entries(process.env))if(g.startsWith(c)&&r!==void 0)a[g]=r;n.$env=a}async function is(n,e){await _e(()=>Gt(n,e),void 0,(c)=>{z.log(c,{filePath:n,phase:"view-composer"},"warning"),console.warn(`[stx] view composer failed for ${n}: ${c.message}`)})}var at="data-stx-source";function hr(n,e){if(!n)return n;let c=/^<script\b([^>]*)>/i.exec(n);if(!c||!/\bserver\b/.test(c[1])||c[1].includes(at))return n;return`<script ${at}="${encodeURIComponent(e)}"${n.slice(7)}`}function os(n){let e=new RegExp(`${at}="([^"]*)"`).exec(n);return e?decodeURIComponent(e[1]):void 0}function yr(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function wr(n,e,c){return`<div data-stx-server-script-error role="alert" style="padding:12px 14px;border:1px solid #f0b4b4;border-left-width:4px;background:#fff5f5;color:#7a1f1f;font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace"><strong style="display:block;margin-bottom:4px">stx: a <script server> ${e==="module-resolution"?"imports a module that does not resolve":e==="syntax"?"does not parse":"names something that does not exist"}, so this component rendered nothing.</strong><span style="display:block;opacity:.85">${yr(n)}</span><span style="display:block;margin-top:4px">${yr(c)}</span></div>`}async function as(n,e,c,a){let{scanScriptTags:g}=await o("stx/signal-processing",()=>import("./chunk-
|
|
1313
|
+
${m}`,v(m)}catch(I){if(I instanceof K)throw I;throw new ce(`Error processing layout ${D}: ${I instanceof Error?I.message:String(I)}`,c)}return v(await vr(m,e,c,d,g))}function ns(n,e){return n.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(c,a,g)=>{let r=e[a];if(r!==void 0){if(!new RegExp(`@(?:yield|slot)\\(\\s*['"]${a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}['"]`).test(r))return r}return g||""})}function ss(n,e){if(n.__stx_sfc_mode=!0,n.__stx_options=e,e.buildMode)n.__stx_buildMode=e.buildMode;let c=e.envPrefix||"STX_PUBLIC_",a={};for(let[g,r]of Object.entries(process.env))if(g.startsWith(c)&&r!==void 0)a[g]=r;n.$env=a}async function is(n,e){await _e(()=>Gt(n,e),void 0,(c)=>{z.log(c,{filePath:n,phase:"view-composer"},"warning"),console.warn(`[stx] view composer failed for ${n}: ${c.message}`)})}var at="data-stx-source";function hr(n,e){if(!n)return n;let c=/^<script\b([^>]*)>/i.exec(n);if(!c||!/\bserver\b/.test(c[1])||c[1].includes(at))return n;return`<script ${at}="${encodeURIComponent(e)}"${n.slice(7)}`}function os(n){let e=new RegExp(`${at}="([^"]*)"`).exec(n);return e?decodeURIComponent(e[1]):void 0}function yr(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function wr(n,e,c){return`<div data-stx-server-script-error role="alert" style="padding:12px 14px;border:1px solid #f0b4b4;border-left-width:4px;background:#fff5f5;color:#7a1f1f;font:13px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace"><strong style="display:block;margin-bottom:4px">stx: a <script server> ${e==="module-resolution"?"imports a module that does not resolve":e==="syntax"?"does not parse":"names something that does not exist"}, so this component rendered nothing.</strong><span style="display:block;opacity:.85">${yr(n)}</span><span style="display:block;margin-top:4px">${yr(c)}</span></div>`}async function as(n,e,c,a){let{scanScriptTags:g}=await o("stx/signal-processing",()=>import("./chunk-14vv64pw.js")),r=[],d=!T()&&!$n();for(let m of g(n)){let x=m.attrs;if(!/\bserver\b/.test(x))continue;let w=m.start+m.fullMatch.indexOf(">")+1,v=xr(n,w);if(v===-1)continue;let k=n.slice(w,v);if(!k.trim())continue;let S=os(x)??c,M={index:m.start,length:v+9-m.start};try{let{extractVariables:A}=await o("stx/variable-extractor",()=>import("./chunk-ptppavv8.js"));await A(k,e,S,{preserveExisting:!0,onFailure:(R)=>{if(R.kind==="unknown")return;if(a?.onServerScriptError?.({sourcePath:S,kind:R.kind,message:R.message}),!d)return;r.push({...M,markup:wr(S,R.kind,R.message)})}})}catch(A){let R=A instanceof Error?A:Error(String(A));if(z.log(R,{filePath:S,phase:"server-script-extraction"},"warning"),console.warn(`[stx] server <script> extraction failed in ${S}: ${R.message}`),d)r.push({...M,markup:wr(S,"unknown",R.message)})}}if(r.length===0)return n;let y=n;for(let m of r.sort((x,w)=>w.index-x.index))y=y.slice(0,m.index)+m.markup+y.slice(m.index+m.length);return y}async function cs(n,e,c){try{let{interpolateScriptsInTemplate:a}=await o("stx/expressions",()=>import("./chunk-47z5w330.js"));return a(n,e,{skipServer:!0})}catch(a){let g=a instanceof Error?a:Error(String(a));return z.log(g,{filePath:c,phase:"script-expression-interpolation"},"warning"),console.warn(`[stx] script expression interpolation failed in ${c}: ${g.message}`),n}}async function vr(n,e,c,a,g){let r=n;await _();let d=a;if(r=await as(r,e,c,a),r=await Ft(r,e,c),r=await Ut(r,e,c),r=await cs(r,e,c),await _(),r=await Ct(r,e,c,d),ke(r))r=Xo(r,e),r=vs(r,e),r=ws(r,e);r=Jo(r),await _();let{processStreamDirectives:y}=await o("stx/streaming",()=>import("./chunk-epqp6mmn.js"));r=y(r,e),r=await Uo(r,e,c,d,!0),await _(),r=await tr(r,e,c,d,g),r=await ms(r,e,c,d,g),await _(),r=wc(r,e,c,d);let{processDeferDirectives:m}=await o("stx/defer",()=>import("./chunk-h7rcb74n.js"));r=m(r,e,c);let{processTeleportDirectives:x}=await o("stx/teleport",()=>import("./chunk-acbx3jn5.js"));r=x(r,e,c);let{processTransitionDirectives:w,processTransitionAttributes:v}=await o("stx/transitions",()=>import("./chunk-1qdhwjs4.js"));r=w(r,e,c),r=v(r);let{processErrorBoundaryDirectives:k,stripRenderFailedMarkers:S}=await o("stx/error-boundaries",()=>import("./chunk-h85hrwkq.js"));r=k(r,e,c),r=S(r);let{processSuspenseDirectives:M}=await o("stx/suspense",()=>import("./chunk-3w9xhs7k.js"));r=M(r,e,c);let{processAsyncDirectives:A}=await o("stx/async-components",()=>import("./chunk-yx37mvy7.js"));r=A(r,e,c);let{processKeepAliveDirectives:R}=await o("stx/keep-alive",()=>import("./chunk-4e6wkjtx.js"));r=R(r,e,c);let{processVirtualListDirectives:D,processVirtualGridDirectives:j,processInfiniteListDirectives:N}=await o("stx/virtual-scrolling",()=>import("./chunk-znfzh6fm.js"));r=D(r,e,c),r=j(r,e,c),r=N(r,e,c),await _();let{processPartialHydrationDirectives:F,processStaticDirectives:I}=await o("stx/partial-hydration",()=>import("./chunk-67bn31a3.js"));r=F(r,e,c),r=I(r);let{processComputedDirectives:L,processWatchDirectives:H}=await o("stx/computed",()=>import("./chunk-1xdzcy9d.js"));r=L(r,e,c),r=H(r,e,c);let{processFormValidationDirectives:V}=await o("stx/forms-validation",()=>import("./chunk-vffwkmt4.js"));r=V(r,e,c);let{processHeadDirective:X,processTitleDirective:ee,processMetaDirective:te,resetHead:re}=await o("stx/head",()=>import("./chunk-3gyq9rjx.js"));if(!e.__stx_head_preset&&!e.__stx_runtime_head)re();let le=X(r);if(r=le.content,le.headContent)e.__stx_head_raw=`${e.__stx_head_raw||""}${le.headContent}
|
|
1314
1314
|
`;if(r=ee(r,e),r=te(r,e,c),r=Kt(r),r=Wo(r,e),r=_t(r),r=Vt(r),r=await us(r,e,c,d,g),r=await ms(r,e,c,d,g),await _(),r=r.replace(/@push\s*\(\s*['"][^'"]+['"]\s*\)[\s\S]*?@endpush/g,""),r=wi(r),r=oe(r,e,c),r=hs(r),await _(),e.__stxProcessingDepth===1)r=Yc(r,e);if(r=Wc(r,e,{filePath:c,buildMode:d.buildMode}),r=qo(r,e),r=Ko(r,e),r=We(r,e),r=Pt(r,e),r=Nt(r,e),r=await bt(r,e,c,d),r=await xc(r,e,c),r=await Sc(r,e,c,d),await _(),r=kc(r,e,c,d),r=ri(r,e,c,d),r=si(r,e,c),r=oi(r,e,c,d),r=Et(r,e,c,d),r=Ws(r,e),r=qs(r),r=Kc(r),!d.skipEventDirectives)r=Mc(r,e,c);if(r=qc(r,e,c,a.skipSignalsRuntime===!0&&Number(e.__stxProcessingDepth)>0),await _(),d.debug){let U=/\bx-data\s*=/.test(r),q=bs(n);if(U&&q)console.warn(`[stx] ${c}: Template mixes Alpine-style (x-data) and signals (state/derived/effect) reactivity.
|
|
1315
1315
|
Both work on the same page, but they manage separate scopes.
|
|
1316
1316
|
Prefer signals (state/derived/effect) for new components.`)}r=gc(r,e),r=await Ei(r,e,c),await _(),r=Gc(r),r=Xc(r),r=mt(r);let{processXElementDirectives:de}=await o("stx/x-element",()=>import("./chunk-zhxdpzga.js"));r=de(r);let se=e.__originalFilePath||c,G=Le(e);if(r=await Yo(r,d,se,G),await _(),r=Dt(r,e),r=await zt(r,e,c,d),await _(),d.media?.image?.autoSiblings){let U=d.publicDir||"public",{rewriteImagesWithSiblings:q}=await o("stx/image-optimization/auto-sibling",()=>import("./chunk-j3x3e353.js"));r=await q(r,{publicDir:U})}if(d.seo?.enabled)r=ii(r,e,d);let me=(U,q,Z=!0)=>{if(!q)return U;let he=q.match(/<title\b[^>]*>[\s\S]*?<\/title>/i),ne=/<head\b[^>]*>[\s\S]*?(?:<\/head\s*>|<body\b|$)/i.exec(U),pe=ne?/<title\b[^>]*>[\s\S]*?<\/title>/i.exec(ne[0]):null;if(he&&ne&&pe){if(Z){let Te=ne.index+pe.index;U=U.slice(0,Te)+he[0]+U.slice(Te+pe[0].length)}if(q=q.replace(he[0],"").trim(),!q)return U}if(/<\/head>/i.test(U))return U.replace(/<\/head>/i,`${q}
|
|
@@ -1324,6 +1324,6 @@ ${pt()}
|
|
|
1324
1324
|
`+Te}else r=r.replace("</head>",`${q}
|
|
1325
1325
|
</head>`)}else if(r.includes("<body"))r=r.replace(/<body([^>]*)>/,`<body$1>
|
|
1326
1326
|
${q}`);else r=q+`
|
|
1327
|
-
`+r}{let{scanScriptTags:U}=await o("stx/signal-processing",()=>import("./chunk-
|
|
1327
|
+
`+r}{let{scanScriptTags:U}=await o("stx/signal-processing",()=>import("./chunk-14vv64pw.js")),q=[];for(let Z of U(r)){if(!/\bserver\b/i.test(Z.attrs))continue;let he=Z.start+Z.fullMatch.indexOf(">")+1,ne=xr(r,he);if(ne===-1)continue;let pe=ne+9;while(pe<r.length&&/\s/.test(r[pe]))pe++;q.push({start:Z.start,end:pe})}if(q.length>0){let Z=Array(q.length+1),he=0;for(let ne=0;ne<q.length;ne++){let{start:pe,end:Te}=q[ne];Z[ne]=r.slice(he,pe),he=Te}Z[q.length]=r.slice(he),r=Z.join("")}}let lt=Vs(r,c);if(lt.hasScoped)r=lt.html;let Ar=e.__stx_event_bindings||[],Ke=!1,ut=[],Rr=/\s:[a-z][\w.-]*\s*=/.test(r),{scanScriptTags:Mr}=await o("stx/signal-processing",()=>import("./chunk-14vv64pw.js"));for(let U of Mr(r,{skipAttrs:/\bserver\b|\bsrc\s*=|\bdata-stx-scoped\b|\bdata-stx-router\b|\btype\s*=\s*["'](?!(?:text\/javascript|application\/javascript|module)["'])[^"']*["']/}))ut.push({match:U.fullMatch,attrs:U.attrs,content:U.body});for(let{match:U,attrs:q,content:Z}of ut){Ke=!0;let he=Z;Ne(Z,c,a.strict,e.__originalFilePath);let ne=await je(Z,{eventBindings:Ar,attrs:q,hasColonDirectives:Rr,templateContent:n,filePath:c,projectRoot:process.cwd(),production:Mi(a.buildMode,a.minifyClient),serverData:G});r=r.replace(U,()=>ne)}if(Ke)e.__stx_event_bindings=[];if(!Ke&&e.__stxProcessingDepth===1){let U=e.__stx_event_bindings||[];if(U.length>0){let q=pi(U);if(q){let Z=r.lastIndexOf("</body>");r=Z===-1?r+q:r.slice(0,Z)+q+`
|
|
1328
1328
|
`+r.slice(Z)}e.__stx_event_bindings=[]}}if(!d.skipSignalsRuntime&&!we(r)&&hc(r))r=await pr(r,d);if(r=yc(r),d.csp?.enabled&&d.csp.useNonce&&typeof e.cspNonce==="string")r=$t(r,e.cspNonce);return r}
|
|
1329
1329
|
export{wt,Ae,uc,ls,jo,Bo,or,i};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{He,M,jt}from"./chunk-v4bqmzj9.js";import{R}from"./chunk-k47addf7.js";import{mt,Ee,j,Ke,Te,ba,vo,wa,Dn}from"./chunk-918ws1g7.js";import{_t,de,tt}from"./chunk-8cvgm13s.js";import{Do}from"./chunk-qa1pcm7n.js";import{Ln}from"./chunk-12r22pf0.js";import{we}from"./chunk-eh8g8kr1.js";import Z from"fs";import P from"path";var{serve:ae}=globalThis.Bun;import H from"zlib";import{promisify as Y}from"util";var K=["text/","application/json","application/javascript","application/xml","application/xhtml+xml","application/rss+xml","application/atom+xml","application/manifest+json","image/svg+xml"],ee=["text/event-stream","multipart/x-mixed-replace"],te=1024;function ne(t){if(!t)return!1;let e=t.toLowerCase();if(ee.some((a)=>e.startsWith(a)))return!1;return K.some((a)=>e.startsWith(a))}function re(t){let e=new Map;for(let a of t.split(",")){let[r,...i]=a.trim().split(";"),f=r.trim().toLowerCase();if(!f)continue;let h=1;for(let g of i){let l=/^\s*q\s*=\s*([\d.]+)\s*$/i.exec(g);if(!l)continue;let m=Number.parseFloat(l[1]);if(Number.isFinite(m))h=m}e.set(f,h)}return e}function se(t){if(!t)return null;let e=re(t),a=e.get("*"),r=(i)=>e.get(i)??a??0;if(r("br")>0)return"br";if(r("gzip")>0)return"gzip";return null}var J=33554432,F=new Map,z=0;function oe(t,e){if(e.length>J/8)return;F.set(t,e),z+=e.length;for(let[a,r]of F){if(z<=J)break;F.delete(a),z-=r.length}}async function In(t,e,a={}){if(e.headers.get("content-encoding"))return e;if(e.status===204||e.status===304||!e.body)return e;if(!ne(e.headers.get("content-type")))return e;let r=se(t.headers.get("accept-encoding"));if(!r)return e;let i;try{i=new Uint8Array(await e.arrayBuffer())}catch{return e}let f=()=>new Response(i,{status:e.status,statusText:e.statusText,headers:Q(e.headers)});if(i.length<(a.threshold??te))return f();try{let h=a.quality??5,g=`${r}:${h}:${i.length}:${Bun.hash(i)}`,l=F.get(g);if(!l)l=r==="br"?await Y(H.brotliCompress)(i,{params:{[H.constants.BROTLI_PARAM_QUALITY]:h,[H.constants.BROTLI_PARAM_SIZE_HINT]:i.length}}):await Y(H.gzip)(i),oe(g,l);if(l.length>=i.length)return f();let m=Q(e.headers);return m.set("Content-Encoding",r),m.set("Content-Length",String(l.length)),new Response(l,{status:e.status,statusText:e.statusText,headers:m})}catch{return f()}}function Q(t){let e=new Headers(t),a=e.get("Vary");if(!a)return e.set("Vary","Accept-Encoding"),e;if(!a.split(",").some((i)=>i.trim().toLowerCase()==="accept-encoding"))e.set("Vary",`${a}, Accept-Encoding`);return e}class G{now;entries=new R(1000,{maxBytes:33554432,sizeOf:(t)=>t.body.byteLength+JSON.stringify(t.headers).length*2});pending=new Map;generation=0;constructor(t=Date.now){this.now=t}invalidate(t){this.generation++,this.pending.clear();for(let e of Array.from(this.entries.keys()))if(t===void 0||this.entries.get(e)?.path===t)this.entries.delete(e)}async respond(t,e,a){let r,i=async()=>{let s=r??await a();return s.headers.set("Cache-Control","private, no-store"),s.headers.set("Vary",j(s.headers.get("Vary")).Vary),s};if(!e||t.method!=="GET"||t.headers.has("Cookie")||t.headers.has("Authorization")||t.headers.has("Range"))return i();let f=new URL(t.url),h=`${f.origin}${f.pathname}${f.search}|${Ee(t)?"fragment":"document"}`,g=this.entries.get(h),l=(s)=>{let S=new Headers(s.headers);return S.set("Cache-Control","private, no-store"),S.set("Age",String(Math.max(0,Math.floor((this.now()-s.created)/1000)))),new Response(s.body.slice(0),{headers:S})},m=g?(this.now()-g.created)/1000:1/0;if(g&&m<e.maxAge)return l(g);let b=this.generation,k=async()=>{let s=await a();r=s;let S=(s.headers.get("Vary")??"").toLowerCase().split(",").map((C)=>C.trim()).filter(Boolean);if(s.status!==200||s.headers.has("Set-Cookie")||/(?:private|no-store|no-cache)/i.test(s.headers.get("Cache-Control")??"")||S.some((C)=>C!=="x-stx-router"&&C!=="accept-encoding"))return null;let B=await s.clone().arrayBuffer();if(B.byteLength>1048576)return null;s.headers.set("Vary",j(s.headers.get("Vary")).Vary);let n={body:B,headers:Array.from(s.headers.entries()),created:this.now(),path:f.pathname};if(this.generation===b)this.entries.set(h,n);return n},v=this.pending.get(h);if(!v){if(this.pending.size>=1000)return i();v=k().finally(()=>{if(this.pending.get(h)===v)this.pending.delete(h)}),this.pending.set(h,v)}if(g&&m<e.maxAge+(e.swr??0))return v.catch(()=>{}),l(g);let E=await v;return E?l(E):i()}}var ie={".js":"application/javascript",".mjs":"application/javascript",".css":"text/css",".json":"application/json",".html":"text/html",".txt":"text/plain",".xml":"application/xml",".pdf":"application/pdf",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif",".svg":"image/svg+xml",".ico":"image/x-icon",".bmp":"image/bmp",".mp4":"video/mp4",".webm":"video/webm",".ogg":"audio/ogg",".mp3":"audio/mpeg",".wav":"audio/wav",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"};async function nm(t={}){let e=P.resolve(t.outputDir||".output"),a=t.port??3000,r=ba(e);if(!r)console.error("[stx] No build manifest found. Run `stx build` first."),process.exit(1);console.log(`[stx] Production server loading ${r.routes.length} routes...`);let i=Ln(r.routeRules),f=new G,h=Do(e,r.apiRoutes??[]),g=Bun.file(P.join(e,"server/runtime-config.json")),l=t.runtimeConfig??(await g.exists()?await g.json():void 0),m=l?M(l):void 0,b=new Map,k=new Map,v=new Map,E=new Map;for(let n of r.routes)try{let C=P.join(e,n.compiledPath),c=JSON.parse(await Bun.file(C).text());if(m)c.html=jt(c.html,m);b.set(n.pattern,c),v.set(n.pattern,tt(c.html)),E.set(n.pattern,we(c.html));let _=P.join(e,n.fragmentPath);if(Ke(c.html,r.routerContainer||"main")&&await Bun.file(_).exists()){let A=await Bun.file(_).text();k.set(n.pattern,m?jt(A,m):A)}}catch(C){console.warn(`[stx] Failed to load route ${n.pattern}:`,C)}let s=new Map,S=[];for(let n of r.routes)if(n.hasParams){let{regex:C,params:c}=de(n.pattern,{page:!0});S.push({regex:C,route:n,paramNames:c})}else s.set(n.pattern,n);let B=ae({port:a,async fetch(n){return In(n,await He(m??M(),async()=>{let c=new URL(n.url).pathname;if(t.onRequest){let p=await t.onRequest(n);if(p)return p}if(t.apiRouter){let p=await t.apiRouter.handleRequest(n);if(p.status!==404)return p}if(t.apiRoutes?.[c])return t.apiRoutes[c](n);let _=await h(n);if(_)return _;if((n.method==="GET"||n.method==="HEAD")&&c!=="/"){let p=P.resolve(e,"public"),d;try{d=decodeURIComponent(c)}catch{d=c}if(!d.includes("\x00")){let u=P.resolve(p,`.${d}`);if(u===p||u.startsWith(`${p}${P.sep}`))try{if(Z.existsSync(u)&&Z.statSync(u).isFile()){let y=P.extname(u).toLowerCase(),L=ie[y]||"application/octet-stream",N=c.startsWith("/__stx/")||/\.[0-9a-f]{8}\./.test(c);return new Response(Bun.file(u),{headers:{"Content-Type":L,"Cache-Control":N?"public, max-age=31536000, immutable":"public, max-age=3600"}})}}catch{}}}let A=Ee(n),w=null,q={};if(w=s.get(c)||null,!w)for(let{regex:p,route:d,paramNames:u}of S){let o=c.match(p);if(o){w=d,u.forEach((y,L)=>{q[y]=o[L+1]});break}}if(!w){let p=_t(c)?null:s.get("/404")||null;if(p){let d=b.get(p.pattern);if(d)return new Response(d.html,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}})}let O=i(c),W=Object.keys(O).length>0;return f.respond(n,O.cache,async()=>{let p=b.get(w.pattern);if(A&&n.method==="GET"&&p&&!p.hasServerScripts&&Object.keys(p.placeholders).length===0){let o=k.get(w.pattern);if(o){let y=v.get(w.pattern);return new Response(o,{status:p.status??200,headers:{"Content-Type":"text/html","X-STX-Fragment":"true",...E.has(w.pattern)?{"X-STX-Runtime":E.get(w.pattern)?"true":"false"}:{},...y?{"X-STX-Layout":y.layout,"X-STX-Layout-Group":y.group}:{},...j(),...O.cache?{}:{"Cache-Control":mt}}})}}let d=vo(n.method),u=b.get(w.pattern);if(!u){let o=s.get("/500")||null;if(o){let y=b.get(o.pattern);if(y)return new Response(y.html,{status:500,headers:{"Content-Type":"text/html"}})}return new Response("Internal Server Error",{status:500})}if(w.prerendered&&d)return new Response("Prerendered pages do not accept actions",{status:405,headers:{Allow:"GET, HEAD"}});if(!d&&!u.hasServerScripts&&Object.keys(u.placeholders).length===0)return new Response(u.html,{status:u.status??200,headers:{"Content-Type":"text/html",...j(),"Cache-Control":"public, max-age=60"}});try{let{html:o,boundaries:y,redirect:L,cookies:N,status:I,headers:D}=await Dn(u,{params:q,request:n,method:n.method,__stx_strict_hydration:W,__stx_runtime_config:m});if(L)return wa(L,N,D);if(y&&y.length>0){let{renderStreamingPage:T,streamToResponse:U}=await import("./chunk-sznk5c66.js"),X=new Headers({...j(),...D,"Cache-Control":"private, no-store"});for(let V of N??[])X.append("Set-Cookie",V);if(A&&!d&&Ke(o,r.routerContainer||"main")){let V=tt(o);X.set("X-STX-Fragment","true"),X.set("X-STX-Runtime",we(o)?"true":"false"),X.set("X-STX-Layout",V.layout),X.set("X-STX-Layout-Group",V.group)}return U(T(A&&!d&&Ke(o,r.routerContainer||"main")?Te(o,r.routerContainer||"main",!0):o,y,{timeoutMs:30000}),{status:I??u.status??200,headers:X})}let x=new Headers({"Content-Type":"text/html",...j(),...O.cache?{}:{"Cache-Control":"private, no-store"}});for(let T of N??[])x.append("Set-Cookie",T);for(let[T,U]of Object.entries(D??{}))x.set(T,U);if(x.set("Vary",j(x.get("Vary")).Vary),A&&!d&&Ke(o,r.routerContainer||"main")){let T=tt(o);return x.set("X-STX-Fragment","true"),x.set("X-STX-Runtime",we(o)?"true":"false"),x.set("X-STX-Layout",T.layout),x.set("X-STX-Layout-Group",T.group),new Response(Te(o,r.routerContainer||"main",!0),{status:I??u.status??200,headers:x})}return new Response(o,{status:I??u.status??200,headers:x})}catch(o){if(console.error(`[stx] Hydration error for ${c}:`,o),W)return new Response("Internal Server Error",{status:500});return new Response(u.html,{headers:{"Content-Type":"text/html"}})}})}))}});return console.log(`[stx] Production server running at http://localhost:${B.port}`),console.log(`[stx] Serving ${r.routes.length} routes (${b.size} pre-loaded)`),{port:B.port,stop:()=>{f.invalidate(),B.stop()},invalidate:(n)=>f.invalidate(n)}}
|
|
2
|
+
import{He,M,jt}from"./chunk-v4bqmzj9.js";import{R}from"./chunk-k47addf7.js";import{mt,Ee,j,Ke,Te,ba,vo,wa,Dn}from"./chunk-3bp76dx5.js";import{_t,de,tt}from"./chunk-8cvgm13s.js";import{Do}from"./chunk-sb8vn22f.js";import{Ln}from"./chunk-12r22pf0.js";import{we}from"./chunk-te090fxv.js";import Z from"fs";import P from"path";var{serve:ae}=globalThis.Bun;import H from"zlib";import{promisify as Y}from"util";var K=["text/","application/json","application/javascript","application/xml","application/xhtml+xml","application/rss+xml","application/atom+xml","application/manifest+json","image/svg+xml"],ee=["text/event-stream","multipart/x-mixed-replace"],te=1024;function ne(t){if(!t)return!1;let e=t.toLowerCase();if(ee.some((a)=>e.startsWith(a)))return!1;return K.some((a)=>e.startsWith(a))}function re(t){let e=new Map;for(let a of t.split(",")){let[r,...i]=a.trim().split(";"),f=r.trim().toLowerCase();if(!f)continue;let h=1;for(let g of i){let l=/^\s*q\s*=\s*([\d.]+)\s*$/i.exec(g);if(!l)continue;let m=Number.parseFloat(l[1]);if(Number.isFinite(m))h=m}e.set(f,h)}return e}function se(t){if(!t)return null;let e=re(t),a=e.get("*"),r=(i)=>e.get(i)??a??0;if(r("br")>0)return"br";if(r("gzip")>0)return"gzip";return null}var J=33554432,F=new Map,z=0;function oe(t,e){if(e.length>J/8)return;F.set(t,e),z+=e.length;for(let[a,r]of F){if(z<=J)break;F.delete(a),z-=r.length}}async function In(t,e,a={}){if(e.headers.get("content-encoding"))return e;if(e.status===204||e.status===304||!e.body)return e;if(!ne(e.headers.get("content-type")))return e;let r=se(t.headers.get("accept-encoding"));if(!r)return e;let i;try{i=new Uint8Array(await e.arrayBuffer())}catch{return e}let f=()=>new Response(i,{status:e.status,statusText:e.statusText,headers:Q(e.headers)});if(i.length<(a.threshold??te))return f();try{let h=a.quality??5,g=`${r}:${h}:${i.length}:${Bun.hash(i)}`,l=F.get(g);if(!l)l=r==="br"?await Y(H.brotliCompress)(i,{params:{[H.constants.BROTLI_PARAM_QUALITY]:h,[H.constants.BROTLI_PARAM_SIZE_HINT]:i.length}}):await Y(H.gzip)(i),oe(g,l);if(l.length>=i.length)return f();let m=Q(e.headers);return m.set("Content-Encoding",r),m.set("Content-Length",String(l.length)),new Response(l,{status:e.status,statusText:e.statusText,headers:m})}catch{return f()}}function Q(t){let e=new Headers(t),a=e.get("Vary");if(!a)return e.set("Vary","Accept-Encoding"),e;if(!a.split(",").some((i)=>i.trim().toLowerCase()==="accept-encoding"))e.set("Vary",`${a}, Accept-Encoding`);return e}class G{now;entries=new R(1000,{maxBytes:33554432,sizeOf:(t)=>t.body.byteLength+JSON.stringify(t.headers).length*2});pending=new Map;generation=0;constructor(t=Date.now){this.now=t}invalidate(t){this.generation++,this.pending.clear();for(let e of Array.from(this.entries.keys()))if(t===void 0||this.entries.get(e)?.path===t)this.entries.delete(e)}async respond(t,e,a){let r,i=async()=>{let s=r??await a();return s.headers.set("Cache-Control","private, no-store"),s.headers.set("Vary",j(s.headers.get("Vary")).Vary),s};if(!e||t.method!=="GET"||t.headers.has("Cookie")||t.headers.has("Authorization")||t.headers.has("Range"))return i();let f=new URL(t.url),h=`${f.origin}${f.pathname}${f.search}|${Ee(t)?"fragment":"document"}`,g=this.entries.get(h),l=(s)=>{let S=new Headers(s.headers);return S.set("Cache-Control","private, no-store"),S.set("Age",String(Math.max(0,Math.floor((this.now()-s.created)/1000)))),new Response(s.body.slice(0),{headers:S})},m=g?(this.now()-g.created)/1000:1/0;if(g&&m<e.maxAge)return l(g);let b=this.generation,k=async()=>{let s=await a();r=s;let S=(s.headers.get("Vary")??"").toLowerCase().split(",").map((C)=>C.trim()).filter(Boolean);if(s.status!==200||s.headers.has("Set-Cookie")||/(?:private|no-store|no-cache)/i.test(s.headers.get("Cache-Control")??"")||S.some((C)=>C!=="x-stx-router"&&C!=="accept-encoding"))return null;let B=await s.clone().arrayBuffer();if(B.byteLength>1048576)return null;s.headers.set("Vary",j(s.headers.get("Vary")).Vary);let n={body:B,headers:Array.from(s.headers.entries()),created:this.now(),path:f.pathname};if(this.generation===b)this.entries.set(h,n);return n},v=this.pending.get(h);if(!v){if(this.pending.size>=1000)return i();v=k().finally(()=>{if(this.pending.get(h)===v)this.pending.delete(h)}),this.pending.set(h,v)}if(g&&m<e.maxAge+(e.swr??0))return v.catch(()=>{}),l(g);let E=await v;return E?l(E):i()}}var ie={".js":"application/javascript",".mjs":"application/javascript",".css":"text/css",".json":"application/json",".html":"text/html",".txt":"text/plain",".xml":"application/xml",".pdf":"application/pdf",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif",".svg":"image/svg+xml",".ico":"image/x-icon",".bmp":"image/bmp",".mp4":"video/mp4",".webm":"video/webm",".ogg":"audio/ogg",".mp3":"audio/mpeg",".wav":"audio/wav",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"};async function nm(t={}){let e=P.resolve(t.outputDir||".output"),a=t.port??3000,r=ba(e);if(!r)console.error("[stx] No build manifest found. Run `stx build` first."),process.exit(1);console.log(`[stx] Production server loading ${r.routes.length} routes...`);let i=Ln(r.routeRules),f=new G,h=Do(e,r.apiRoutes??[]),g=Bun.file(P.join(e,"server/runtime-config.json")),l=t.runtimeConfig??(await g.exists()?await g.json():void 0),m=l?M(l):void 0,b=new Map,k=new Map,v=new Map,E=new Map;for(let n of r.routes)try{let C=P.join(e,n.compiledPath),c=JSON.parse(await Bun.file(C).text());if(m)c.html=jt(c.html,m);b.set(n.pattern,c),v.set(n.pattern,tt(c.html)),E.set(n.pattern,we(c.html));let _=P.join(e,n.fragmentPath);if(Ke(c.html,r.routerContainer||"main")&&await Bun.file(_).exists()){let A=await Bun.file(_).text();k.set(n.pattern,m?jt(A,m):A)}}catch(C){console.warn(`[stx] Failed to load route ${n.pattern}:`,C)}let s=new Map,S=[];for(let n of r.routes)if(n.hasParams){let{regex:C,params:c}=de(n.pattern,{page:!0});S.push({regex:C,route:n,paramNames:c})}else s.set(n.pattern,n);let B=ae({port:a,async fetch(n){return In(n,await He(m??M(),async()=>{let c=new URL(n.url).pathname;if(t.onRequest){let p=await t.onRequest(n);if(p)return p}if(t.apiRouter){let p=await t.apiRouter.handleRequest(n);if(p.status!==404)return p}if(t.apiRoutes?.[c])return t.apiRoutes[c](n);let _=await h(n);if(_)return _;if((n.method==="GET"||n.method==="HEAD")&&c!=="/"){let p=P.resolve(e,"public"),d;try{d=decodeURIComponent(c)}catch{d=c}if(!d.includes("\x00")){let u=P.resolve(p,`.${d}`);if(u===p||u.startsWith(`${p}${P.sep}`))try{if(Z.existsSync(u)&&Z.statSync(u).isFile()){let y=P.extname(u).toLowerCase(),L=ie[y]||"application/octet-stream",N=c.startsWith("/__stx/")||/\.[0-9a-f]{8}\./.test(c);return new Response(Bun.file(u),{headers:{"Content-Type":L,"Cache-Control":N?"public, max-age=31536000, immutable":"public, max-age=3600"}})}}catch{}}}let A=Ee(n),w=null,q={};if(w=s.get(c)||null,!w)for(let{regex:p,route:d,paramNames:u}of S){let o=c.match(p);if(o){w=d,u.forEach((y,L)=>{q[y]=o[L+1]});break}}if(!w){let p=_t(c)?null:s.get("/404")||null;if(p){let d=b.get(p.pattern);if(d)return new Response(d.html,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain; charset=utf-8"}})}let O=i(c),W=Object.keys(O).length>0;return f.respond(n,O.cache,async()=>{let p=b.get(w.pattern);if(A&&n.method==="GET"&&p&&!p.hasServerScripts&&Object.keys(p.placeholders).length===0){let o=k.get(w.pattern);if(o){let y=v.get(w.pattern);return new Response(o,{status:p.status??200,headers:{"Content-Type":"text/html","X-STX-Fragment":"true",...E.has(w.pattern)?{"X-STX-Runtime":E.get(w.pattern)?"true":"false"}:{},...y?{"X-STX-Layout":y.layout,"X-STX-Layout-Group":y.group}:{},...j(),...O.cache?{}:{"Cache-Control":mt}}})}}let d=vo(n.method),u=b.get(w.pattern);if(!u){let o=s.get("/500")||null;if(o){let y=b.get(o.pattern);if(y)return new Response(y.html,{status:500,headers:{"Content-Type":"text/html"}})}return new Response("Internal Server Error",{status:500})}if(w.prerendered&&d)return new Response("Prerendered pages do not accept actions",{status:405,headers:{Allow:"GET, HEAD"}});if(!d&&!u.hasServerScripts&&Object.keys(u.placeholders).length===0)return new Response(u.html,{status:u.status??200,headers:{"Content-Type":"text/html",...j(),"Cache-Control":"public, max-age=60"}});try{let{html:o,boundaries:y,redirect:L,cookies:N,status:I,headers:D}=await Dn(u,{params:q,request:n,method:n.method,__stx_strict_hydration:W,__stx_runtime_config:m});if(L)return wa(L,N,D);if(y&&y.length>0){let{renderStreamingPage:T,streamToResponse:U}=await import("./chunk-epqp6mmn.js"),X=new Headers({...j(),...D,"Cache-Control":"private, no-store"});for(let V of N??[])X.append("Set-Cookie",V);if(A&&!d&&Ke(o,r.routerContainer||"main")){let V=tt(o);X.set("X-STX-Fragment","true"),X.set("X-STX-Runtime",we(o)?"true":"false"),X.set("X-STX-Layout",V.layout),X.set("X-STX-Layout-Group",V.group)}return U(T(A&&!d&&Ke(o,r.routerContainer||"main")?Te(o,r.routerContainer||"main",!0):o,y,{timeoutMs:30000}),{status:I??u.status??200,headers:X})}let x=new Headers({"Content-Type":"text/html",...j(),...O.cache?{}:{"Cache-Control":"private, no-store"}});for(let T of N??[])x.append("Set-Cookie",T);for(let[T,U]of Object.entries(D??{}))x.set(T,U);if(x.set("Vary",j(x.get("Vary")).Vary),A&&!d&&Ke(o,r.routerContainer||"main")){let T=tt(o);return x.set("X-STX-Fragment","true"),x.set("X-STX-Runtime",we(o)?"true":"false"),x.set("X-STX-Layout",T.layout),x.set("X-STX-Layout-Group",T.group),new Response(Te(o,r.routerContainer||"main",!0),{status:I??u.status??200,headers:x})}return new Response(o,{status:I??u.status??200,headers:x})}catch(o){if(console.error(`[stx] Hydration error for ${c}:`,o),W)return new Response("Internal Server Error",{status:500});return new Response(u.html,{headers:{"Content-Type":"text/html"}})}})}))}});return console.log(`[stx] Production server running at http://localhost:${B.port}`),console.log(`[stx] Serving ${r.routes.length} routes (${b.size} pre-loaded)`),{port:B.port,stop:()=>{f.invalidate(),B.stop()},invalidate:(n)=>f.invalidate(n)}}
|
|
3
3
|
export{In,nm};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{pe,Uc,Us,bn,m,Le,je}from"./chunk-
|
|
2
|
+
import{pe,Uc,Us,bn,m,Le,je}from"./chunk-r53tqxmq.js";import{mr,et,F}from"./chunk-c1dkvqr5.js";import{or,i}from"./chunk-1pavg6q5.js";import{ve}from"./chunk-te090fxv.js";function b(s){return s.endsWith(".md")||s.endsWith(".markdown")}function k(s){let e=[];g(/<pre\b[^>]*>[\s\S]*?<\/pre>/gi);let r=[...e];g(/<code\b[^>]*>[\s\S]*?<\/code>/gi,r);function g(n,p){let u;while((u=n.exec(s))!==null){let t=u.index,o=t+u[0].length;if(p?.some((l)=>t>=l.start&&o<=l.end))continue;e.push({start:t,end:o})}}if(e.length===0)return s;e.sort((n,p)=>n.start-p.start);let c="",a=0;for(let n of e){if(n.start<a)continue;c+=s.slice(a,n.start),c+=`@raw${s.slice(n.start,n.end)}@endraw`,a=n.end}return c+=s.slice(a),c}async function R(s,e={}){let{data:r,content:g}=mr(s),a=await(e.renderer??((n)=>et(n)))(g);return{html:k(a),frontmatter:r??{}}}import{dirname as v,resolve as _}from"path";function M(s){let e=s,r=pe(s);if(r)e=r.content.trim();let g=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,c=[],a=[],n=[],p=(o)=>/\b(?:state|derived|effect|batch)\s*(?:<[^<>()]*>)?\s*\(/.test(o),u;while((u=g.exec(s))!==null){let o=u[1],l=u[2],d=u[0],f=o.includes("server");if(p(l))n.push(d);else if(f)a.push(l);else c.push(d)}let t=e;{let o=/<script\b(?![^>]*\b(?:client|type\s*=\s*["']module["']|src\s*=))[^>]*>/gi,l,d=[];while((l=o.exec(t))!==null){let f=l.index+l[0].length,x=t.indexOf("</script>",f);if(x===-1)continue;d.push({start:l.index,end:x+9}),o.lastIndex=x+9}for(let f=d.length-1;f>=0;f--)t=t.substring(0,d[f].start)+t.substring(d[f].end)}for(let o of c)t=t.replace(o,"");return{templateContent:t,serverScripts:a,clientScripts:c,signalsScripts:n}}function E(s,e){return`<!DOCTYPE html>
|
|
3
3
|
<html lang="en">
|
|
4
4
|
<head>
|
|
5
5
|
<meta charset="UTF-8">
|
|
@@ -14,5 +14,5 @@ ${a.join(`
|
|
|
14
14
|
`)}`}else{if(r.processClientScripts!==!1&&a.length>0){let o=p.__stx_event_bindings||[],l=Le(p),d=await Promise.all(a.map(async(w)=>{let C=w.match(/<script\b([^>]*)>/i)?.[1]||"";if(/\btype\s*=\s*["'](?!(?:text\/javascript|application\/javascript|module)["'])[^"']*["']/i.test(C))return w;let h=w.match(/<script\b[^>]*>([\s\S]*?)<\/script>/);if(!h)return w;return await je(h[1],{eventBindings:o,templateContent:t,serverData:l,filePath:e})})),x=[await or(d,{...n,buildMode:"compile"}),...d].filter(Boolean).join(`
|
|
15
15
|
`);if(t.match(/(<\/body>)/i))t=t.replace(/(<\/body>)/i,`${x}
|
|
16
16
|
$1`);else t+=`
|
|
17
|
-
${x}`}t=await ve(t)}if(r.wrapInDocument){if(!t.trim().toLowerCase().startsWith("<!doctype")&&!t.trim().toLowerCase().startsWith("<html"))t=E(t,r.title)}if(r.injectCSS)try{let{injectCss:o}=await import("./chunk-
|
|
17
|
+
${x}`}t=await ve(t)}if(r.wrapInDocument){if(!t.trim().toLowerCase().startsWith("<!doctype")&&!t.trim().toLowerCase().startsWith("<html"))t=E(t,r.title)}if(r.injectCSS)try{let{injectCss:o}=await import("./chunk-yq12dhnt.js");t=await o(t)}catch{}return t}
|
|
18
18
|
export{nc};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Tn}from"./chunk-k47addf7.js";import{q,y,Mt,Dt,$r,m,al,_i,W,A}from"./chunk-
|
|
2
|
+
import{Tn}from"./chunk-k47addf7.js";import{q,y,Mt,Dt,$r,m,al,_i,W,A}from"./chunk-r53tqxmq.js";import{nn}from"./chunk-m150nmez.js";import{n}from"./chunk-332qk8tm.js";import{G}from"./chunk-ym5qgw03.js";var X=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function J(t){let s=[],e=/<!--[\s\S]*?(?:-->|$)|<(script|style|textarea|title|template)\b[^>]*>[\s\S]*?<\/\1\s*>/gi,r;while((r=e.exec(t))!==null)s.push({start:r.index,end:r.index+r[0].length});return s}function N(t,s){return s.some((e)=>t>=e.start&&t<e.end)}function K(t){let s=(t||"").trim();if(!s)return null;if(/[\s>+~,:]/.test(s))return null;let e={},r=s,i=r.match(/^[a-z][\w-]*/i);if(i)e.tag=i[0].toLowerCase(),r=r.slice(i[0].length);while(r.length>0){let o=r.match(/^\[([\w-]+)(?:=(["']?)([^\]"']*)\2)?\]/);if(o){if(e.attr=o[1],o[3]!==void 0&&o[3]!=="")e.attrValue=o[3];r=r.slice(o[0].length);continue}let c=r.match(/^#([\w-]+)/);if(c){e.id=c[1],r=r.slice(c[0].length);continue}let a=r.match(/^\.([\w-]+)/);if(a){e.className=a[1],r=r.slice(a[0].length);continue}return null}if(!e.tag&&!e.attr&&!e.id&&!e.className)return null;return e}function Y(t,s){if(s.attr){if(!(s.attrValue===void 0?new RegExp(`\\b${s.attr}(?=[\\s=>/]|$)`,"i"):new RegExp(`\\b${s.attr}\\s*=\\s*(["'])\\s*${s.attrValue}\\s*\\1`,"i")).test(t))return!1}if(s.id){if(!new RegExp(`\\bid\\s*=\\s*(["'])\\s*${s.id}\\s*\\1`,"i").test(t))return!1}if(s.className){let e=t.match(/\bclass\s*=\s*(["'])([\s\S]*?)\1/i);if(!e)return!1;if(!e[2].split(/\s+/).includes(s.className))return!1}return!0}function P(t,s="main"){let e=K(s);if(!e)return null;let r=/<([a-z][\w-]*)\b([^>]*)>/gi,i=J(t),o;while((o=r.exec(t))!==null){if(N(o.index,i))continue;let c=o[1].toLowerCase(),a=o[2]||"";if(a.trimEnd().endsWith("/")||X.has(c))continue;if(e.tag&&e.tag!==c)continue;if(!Y(a,e))continue;let l=o[0],f=o.index+l.length,u=new RegExp(`<(/?)${c}\\b([^>]*)>`,"gi");u.lastIndex=f;let p=1,h;while((h=u.exec(t))!==null){if(N(h.index,i))continue;let S=h[1]==="/";if(!S&&(h[2]||"").trimEnd().endsWith("/"))continue;if(p+=S?-1:1,p===0)return{openTag:l,openIndex:o.index,start:f,end:h.index,tagName:c}}return null}return null}var mt="private, no-store";function Jt(t){return t.replace(/&#(\d+);/g,(s,e)=>F(Number(e),s)).replace(/&#x([0-9a-f]+);/gi,(s,e)=>F(Number.parseInt(e,16),s)).replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/&/g,"&")}function F(t,s){if(!Number.isInteger(t)||t<0||t>1114111)return s;try{return String.fromCodePoint(t)}catch{return s}}function Ee(t){return t.headers.get("X-STX-Router")==="true"}function Z(t,s){if(!t)return s;return t.split(",").some((r)=>r.trim().toLowerCase()===s.toLowerCase())?t:`${t}, ${s}`}function j(t){return{Vary:Z(t,"X-STX-Router")}}function E(t){return t.replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function D(t){let s=/<head\b[^>]*>([\s\S]*?)<\/head\s*>/i.exec(t)?.[1]??"",e=/<(meta|link)\b(?:[^>"']|"[^"]*"|'[^']*')*>|<title\b[^>]*>[\s\S]*?<\/title\s*>/giy;return y(s,(r,i)=>(e.lastIndex=i,e.exec(r)?e.lastIndex:-1)).map(({token:r})=>r)}function L(t){let s=Object.create(null),e=t.replace(/^<\w+\b|>$/g,"");for(let r of e.matchAll(/([^\s=/>]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g)){let i=r[1].toLowerCase();if(!(i in s))s[i]=r[2]??r[3]??r[4]??""}return s}function Nn(t){let s=[];for(let e of D(t)){if(/^<title\b/i.test(e)){s.push(`<title>${E(e.replace(/^<title\b[^>]*>|<\/title\s*>$/gi,""))}</title>`);continue}let r=L(e);if(/^<meta\b/i.test(e)){let i=r.property?"property":"name",o=Jt(r[i]??"").toLowerCase();if(o==="description"||/^(?:og|twitter):[\w:]+$/.test(o))s.push(`<meta ${i}="${n(o)}" content="${E(r.content??"")}">`)}else{let i=Jt(r.rel??"").toLowerCase();if(i==="canonical"||i==="alternate"&&r.hreflang)s.push(`<link rel="${i}" href="${E(r.href??"")}"${i==="alternate"?` hreflang="${E(r.hreflang)}"`:""}>`)}}return`<template data-stx-page-head="1">${s.join("")}</template>
|
|
3
3
|
`}var Q=["media","crossorigin","integrity"];function Mn(t){let s=[];for(let e of D(t)){if(!/^<link\b/i.test(e))continue;let r=L(e);if(Jt(r.rel??"").trim().toLowerCase()!=="stylesheet")continue;if(!r.href||"data-css"in r||"disabled"in r)continue;let i=Q.filter((o)=>(o in r)).map((o)=>` ${o}="${E(r[o])}"`).join("");s.push(`<link rel="stylesheet" href="${E(r.href)}"${i}>`)}return s.length?`<template data-stx-page-css="1">${s.join("")}</template>
|
|
4
|
-
`:""}import T from"path";var tt="stx-page-head:",et=/<!--stx-page-head:([A-Za-z0-9+/=]+)-->\n?/,_={dev:null,prod:null};function nt(){let t=G()?"dev":"prod",s=_[t];if(s!==null)return s;try{let e=import.meta.require("./chunk-dx31vsyf.js"),r=t==="dev"&&typeof e.getRouterScriptDev==="function"?e.getRouterScriptDev:e.getRouterScript;_[t]=`<script>${r()}</script>`}catch{_[t]=""}return _[t]}async function ga(t,s){if(s===!1)return null;if(s&&typeof s==="string"){let r=T.resolve(t,s);if(await Bun.file(r).exists())return r;return null}let e=T.join(t,"app.stx");if(await Bun.file(e).exists())return e;return null}async function wo(t,s){try{let e=await Bun.file(t).text(),r=e,i=e.match(/<template\b[^>]*>([\s\S]*?)<\/template>/i);if(i)r=i[1].trim();let o=nn(e),c=[...o.client.map((g)=>g.fullTag),...o.signals.map((g)=>g.fullTag)],a=[],l=/<style\b[^>]*>([\s\S]*?)<\/style>/gi,f;while((f=l.exec(e))!==null)a.push(f[0]);let u=r;for(let g of o.server)u=u.replace(g.fullTag,"");for(let g of o.client)u=u.replace(g.fullTag,"");u=u.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"");let p="<!--__STX_PAGE_SLOT__-->";if(u=u.replace(/<slot\s*\/>/gi,p).replace(/<slot\s*>\s*<\/slot>/gi,p),!u.includes(p))return console.warn(`[stx] Shell ${t} has no <slot /> \u2014 pages won't be injected`),null;let{processDirectives:h,extractVariables:S,defaultConfig:R,loadStxConfig:b}=await import("./chunk-
|
|
4
|
+
`:""}import T from"path";var tt="stx-page-head:",et=/<!--stx-page-head:([A-Za-z0-9+/=]+)-->\n?/,_={dev:null,prod:null};function nt(){let t=G()?"dev":"prod",s=_[t];if(s!==null)return s;try{let e=import.meta.require("./chunk-dx31vsyf.js"),r=t==="dev"&&typeof e.getRouterScriptDev==="function"?e.getRouterScriptDev:e.getRouterScript;_[t]=`<script>${r()}</script>`}catch{_[t]=""}return _[t]}async function ga(t,s){if(s===!1)return null;if(s&&typeof s==="string"){let r=T.resolve(t,s);if(await Bun.file(r).exists())return r;return null}let e=T.join(t,"app.stx");if(await Bun.file(e).exists())return e;return null}async function wo(t,s){try{let e=await Bun.file(t).text(),r=e,i=e.match(/<template\b[^>]*>([\s\S]*?)<\/template>/i);if(i)r=i[1].trim();let o=nn(e),c=[...o.client.map((g)=>g.fullTag),...o.signals.map((g)=>g.fullTag)],a=[],l=/<style\b[^>]*>([\s\S]*?)<\/style>/gi,f;while((f=l.exec(e))!==null)a.push(f[0]);let u=r;for(let g of o.server)u=u.replace(g.fullTag,"");for(let g of o.client)u=u.replace(g.fullTag,"");u=u.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"");let p="<!--__STX_PAGE_SLOT__-->";if(u=u.replace(/<slot\s*\/>/gi,p).replace(/<slot\s*>\s*<\/slot>/gi,p),!u.includes(p))return console.warn(`[stx] Shell ${t} has no <slot /> \u2014 pages won't be injected`),null;let{processDirectives:h,extractVariables:S,defaultConfig:R,loadStxConfig:b}=await import("./chunk-6ra9dqs2.js"),k=await b(),d={__filename:t,__dirname:T.dirname(t)};for(let g of c){let C=g.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(C&&!g.includes("client")&&!g.includes('type="module"'))await S(C[1],d,t)}let x=await h(u,d,t,{...R,...k,...s},new Set),w=x.indexOf(p);if(w===-1)return console.warn("[stx] Shell slot placeholder lost during processing"),null;return{beforeSlot:x.substring(0,w),afterSlot:x.substring(w+p.length),filePath:t,shellScripts:c,shellStyles:a}}catch(e){return console.error(`[stx] Error processing shell ${t}:`,e),null}}function Jr(t,s,e){let r,i="",o=s.match(et);if(o){s=s.replace(o[0],"");try{let u=Buffer.from(o[1],"base64").toString("utf8"),p=u.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(p)r=p[1].trim();i=u.replace(/<title[^>]*>[\s\S]*?<\/title>/i,"").trim()}catch{}}let c=e||r||"stx App",a=nt(),l="<script>window.__stxRouterConfig={container:'[data-stx-content]'};</script>";return`<!DOCTYPE html>
|
|
5
5
|
<html lang="en">
|
|
6
6
|
<head>
|
|
7
7
|
<meta charset="UTF-8">
|
|
@@ -29,5 +29,5 @@ ${a}
|
|
|
29
29
|
`));if(o.length>0)d.push(o.filter((x)=>!f.has(x)).join(`
|
|
30
30
|
`));if(R.length>0)d.push(R.filter((x)=>!f.has(x)).join(`
|
|
31
31
|
`));return d.push(S),d.join(`
|
|
32
|
-
`)}import O from"fs";import B from"path";function ha(t,s,e){return{version:1,buildTime:new Date().toISOString(),routes:t,assets:s,outputDir:e}}function ya(t,s){let e=B.join(s,"manifest.json");O.writeFileSync(e,JSON.stringify(t,null,2))}function ba(t){let s=B.join(t,"manifest.json");if(!O.existsSync(s))return null;try{let e=O.readFileSync(s,"utf-8"),r=JSON.parse(e);if(r.version!==1)return console.warn(`[stx] Manifest version mismatch: expected 1, got ${r.version}`),null;return r}catch(e){return console.warn("[stx] Failed to load manifest:",e),null}}function M(t,s,e={}){let r=`${encodeURIComponent(t)}=${encodeURIComponent(s)}`;if(e.maxAge!==void 0)r+=`; Max-Age=${e.maxAge}`;if(e.expires)r+=`; Expires=${e.expires.toUTCString()}`;if(e.path)r+=`; Path=${e.path}`;if(e.domain)r+=`; Domain=${e.domain}`;if(e.secure)r+="; Secure";if(e.httpOnly)r+="; HttpOnly";if(e.sameSite)r+=`; SameSite=${e.sameSite}`;return r}async function st(t){let s=t.headers.get("content-type")||"",e={},r=(i,o)=>{let c=e[i];if(c===void 0)e[i]=o;else if(Array.isArray(c))c.push(o);else e[i]=[c,o]};if(s.includes("multipart/form-data")){let i=await t.formData();for(let[o,c]of i.entries())if(typeof c==="string")r(o,c);return e}if(s.includes("application/x-www-form-urlencoded")){for(let[i,o]of new URLSearchParams(await t.text()).entries())r(i,o);return e}return e}function vo(t){if(!t)return!1;let s=t.toUpperCase();return s!=="GET"&&s!=="HEAD"}async function U(t,s={}){let e=s.request,r=s.method??e?.method;if(!e||!vo(r))return{ran:!1};if(typeof t.action!=="function")return{ran:!1};let i={};try{i=await st(e)}catch{}let o=await t.action({request:e,form:i,params:s.params??{},query:t.query??{},cookies:s.cookies??{}});if(o&&typeof o==="object"){let c=o,a=it(c.cookies),l=c.redirect;if(typeof l==="string"&&l)return{redirect:l,ran:!0,...a.length>0?{cookies:a}:{}};let{cookies:f,redirect:u,...p}=c;if(Object.assign(t,p),a.length>0)return{ran:!0,cookies:a}}return{ran:!0}}function it(t){if(!t||typeof t!=="object"||Array.isArray(t))return[];let s=[];for(let[e,r]of Object.entries(t)){if(!e)continue;if(typeof r==="string"){s.push(M(e,r));continue}if(r&&typeof r==="object"){let i=r;if(typeof i.value!=="string")continue;s.push(M(e,i.value,i))}}return s}function wa(t,s=[],e){let r=new Headers({Location:t,"Cache-Control":"no-store"});for(let i of s)r.append("Set-Cookie",i);for(let[i,o]of Object.entries(e??{}))if(i.toLowerCase()!=="location")r.set(i,o);return new Response(null,{status:303,headers:r})}async function Dn(t,s={}){let{html:e,context:r,redirect:i,cookies:o}=await ot(t,s),c=Mt(r),a=Dt(r);if(i)return{html:e,redirect:i,cookies:o,status:c,headers:a};let{extractStreamBoundaries:l}=await import("./chunk-
|
|
32
|
+
`)}import O from"fs";import B from"path";function ha(t,s,e){return{version:1,buildTime:new Date().toISOString(),routes:t,assets:s,outputDir:e}}function ya(t,s){let e=B.join(s,"manifest.json");O.writeFileSync(e,JSON.stringify(t,null,2))}function ba(t){let s=B.join(t,"manifest.json");if(!O.existsSync(s))return null;try{let e=O.readFileSync(s,"utf-8"),r=JSON.parse(e);if(r.version!==1)return console.warn(`[stx] Manifest version mismatch: expected 1, got ${r.version}`),null;return r}catch(e){return console.warn("[stx] Failed to load manifest:",e),null}}function M(t,s,e={}){let r=`${encodeURIComponent(t)}=${encodeURIComponent(s)}`;if(e.maxAge!==void 0)r+=`; Max-Age=${e.maxAge}`;if(e.expires)r+=`; Expires=${e.expires.toUTCString()}`;if(e.path)r+=`; Path=${e.path}`;if(e.domain)r+=`; Domain=${e.domain}`;if(e.secure)r+="; Secure";if(e.httpOnly)r+="; HttpOnly";if(e.sameSite)r+=`; SameSite=${e.sameSite}`;return r}async function st(t){let s=t.headers.get("content-type")||"",e={},r=(i,o)=>{let c=e[i];if(c===void 0)e[i]=o;else if(Array.isArray(c))c.push(o);else e[i]=[c,o]};if(s.includes("multipart/form-data")){let i=await t.formData();for(let[o,c]of i.entries())if(typeof c==="string")r(o,c);return e}if(s.includes("application/x-www-form-urlencoded")){for(let[i,o]of new URLSearchParams(await t.text()).entries())r(i,o);return e}return e}function vo(t){if(!t)return!1;let s=t.toUpperCase();return s!=="GET"&&s!=="HEAD"}async function U(t,s={}){let e=s.request,r=s.method??e?.method;if(!e||!vo(r))return{ran:!1};if(typeof t.action!=="function")return{ran:!1};let i={};try{i=await st(e)}catch{}let o=await t.action({request:e,form:i,params:s.params??{},query:t.query??{},cookies:s.cookies??{}});if(o&&typeof o==="object"){let c=o,a=it(c.cookies),l=c.redirect;if(typeof l==="string"&&l)return{redirect:l,ran:!0,...a.length>0?{cookies:a}:{}};let{cookies:f,redirect:u,...p}=c;if(Object.assign(t,p),a.length>0)return{ran:!0,cookies:a}}return{ran:!0}}function it(t){if(!t||typeof t!=="object"||Array.isArray(t))return[];let s=[];for(let[e,r]of Object.entries(t)){if(!e)continue;if(typeof r==="string"){s.push(M(e,r));continue}if(r&&typeof r==="object"){let i=r;if(typeof i.value!=="string")continue;s.push(M(e,i.value,i))}}return s}function wa(t,s=[],e){let r=new Headers({Location:t,"Cache-Control":"no-store"});for(let i of s)r.append("Set-Cookie",i);for(let[i,o]of Object.entries(e??{}))if(i.toLowerCase()!=="location")r.set(i,o);return new Response(null,{status:303,headers:r})}async function Dn(t,s={}){let{html:e,context:r,redirect:i,cookies:o}=await ot(t,s),c=Mt(r),a=Dt(r);if(i)return{html:e,redirect:i,cookies:o,status:c,headers:a};let{extractStreamBoundaries:l}=await import("./chunk-epqp6mmn.js"),f=l(r),u=t.streamTemplates;if(u&&Object.keys(u).length>0){let{processDirectives:p}=await import("./chunk-pd0wdjqd.js"),{defaultConfig:h}=await import("./chunk-j415w6dm.js"),S=r.streamBoundaries||{},R={...h,autoShell:!1},b=Object.keys(u).map((d)=>({id:d,render:async()=>{let x=typeof S[d]==="function"?await S[d]():void 0;return p(u[d],{...r,$boundary:x},t.sourceFile,R,new Set)}})),k=new Set(b.map((d)=>d.id));f=[...(f||[]).filter((d)=>!k.has(d.id)),...b]}return{html:e,boundaries:f&&f.length>0?f:void 0,cookies:o,status:c,headers:a}}async function ot(t,s){let e={__filename:t.sourceFile,__dirname:t.sourceFile.replace(/[/\\][^/\\]+$/,""),...s};if(!t.hasServerScripts&&!_i(t.html))return{html:t.html,context:e};for(let c of t.serverScriptContent)try{await m(c,e,t.sourceFile)}catch(a){if(s.__stx_strict_hydration)throw a;console.warn(`[stx] Server script error in ${t.sourceFile}:`,a)}let r=await U(e,{request:s.request,method:s.method,params:s.params??{},cookies:s.cookies??{}}),i=(c)=>{let a=c.replace(/<script\b[^>]*\bdata-stx-server-data\b[^>]*>[\s\S]*?<\/script>/gi,""),l=$r(e);if(!l)return a;let f=a.indexOf("</head>");return f<0?l+a:a.slice(0,f)+l+a.slice(f)};if(r.redirect)return{html:t.html,context:e,redirect:r.redirect,cookies:r.cookies};if(!_i(t.html))return{html:i(t.html),context:e,cookies:r.cookies};let o=new Map;for(let[c,a]of Object.entries(t.placeholders))if(a.expression)try{let l=A(a.expression,e);if(a.type==="raw")o.set(c,l!==void 0&&l!==null?String(l):"");else o.set(c,l!==void 0&&l!==null?W(String(l)):"")}catch(l){if(s.__stx_strict_hydration)throw l;o.set(c,"")}return{html:i(al(t.html,o)),context:e,cookies:r.cookies}}
|
|
33
33
|
export{mt,Jt,Ee,j,Nn,Mn,ga,wo,Jr,qe,ma,Ke,Te,ha,ya,ba,vo,wa,Dn};
|