@stacksjs/stx 0.2.84 → 0.2.85
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/app-shell.js +50 -50
- package/dist/build-mode-detector.js +95 -95
- package/dist/build-views.js +149 -149
- package/dist/build.js +37 -37
- package/dist/cli.js +51 -51
- package/dist/component-processing.js +16 -16
- package/dist/component-renderer.js +32 -32
- package/dist/components.js +95 -95
- package/dist/dev-server/index.js +36 -36
- package/dist/dev-server/serve-app.js +50 -50
- package/dist/dev-server/serve-file.js +50 -50
- package/dist/dev-server/serve-markdown.js +36 -36
- package/dist/dev-server/serve-multi.js +49 -49
- package/dist/dev-server.js +50 -50
- package/dist/docs.js +96 -96
- package/dist/dynamic-components.js +32 -32
- package/dist/includes.js +32 -32
- package/dist/index.js +50 -50
- package/dist/interactive.js +96 -96
- package/dist/lazy-loader.js +95 -95
- package/dist/plugin.js +44 -44
- package/dist/process.js +31 -31
- package/dist/production-builder.js +31 -31
- package/dist/production-server.js +31 -31
- package/dist/pwa/index.js +95 -95
- package/dist/pwa/offline.js +95 -95
- package/dist/pwa.js +84 -84
- package/dist/render.js +153 -153
- package/dist/serve.js +106 -106
- package/dist/site-builder/build.js +97 -97
- package/dist/site-builder/index.js +38 -38
- package/dist/ssg.js +13 -13
- package/dist/ssr.js +83 -83
- package/dist/story/cli.js +36 -36
- package/dist/story/commands/dev.js +36 -36
- package/dist/story/commands/index.js +36 -36
- package/dist/story/index.js +36 -36
- package/dist/story/renderer.js +96 -96
- package/dist/story/server.js +36 -36
- package/dist/story/visual-testing.js +96 -96
- package/dist/streaming.js +32 -32
- package/dist/template-compiler.js +24 -24
- package/dist/template-hydrator.js +110 -110
- package/dist/testing.js +95 -95
- package/dist/utils.js +32 -32
- package/dist/variable-extractor.js +11 -11
- package/dist/web-components.js +95 -95
- package/package.json +5 -5
|
@@ -493,7 +493,7 @@ Check your site ID or create a new site at https://app.netlify.com`,"SITE_NOT_FO
|
|
|
493
493
|
`),J&&!J.endsWith(`
|
|
494
494
|
`))J+=`
|
|
495
495
|
`}J+=`NETLIFY_SITE_ID=${$.siteId}
|
|
496
|
-
`,await Bun.write(X,J)}return{configPath:Y,siteId:$.siteId}}function QN($){let Z=process.platform,Y=Z==="darwin"?"open":Z==="win32"?"start":"xdg-open";Bun.spawn([Y,$],{stdio:["ignore","ignore","ignore"]})}var R$;var QX=k(()=>{YX();YX();R$=class R$ extends Error{code;constructor($,Z){super($);this.name="DeployError",this.code=Z}}});var XW={};t(XW,{resizeAndConvert:()=>YW,processImage:()=>p1,isSharpAvailable:()=>A4,isImageFile:()=>w4,isImageBackendAvailable:()=>m1,groupVariantsByFormat:()=>i5,getTotalSize:()=>d3,getMimeType:()=>M1,getImageMetadata:()=>p5,getFallbackVariant:()=>l5,generateSrcSet:()=>B5,generateSizes:()=>c5,formatSize:()=>u3,ImageProcessingError:()=>n5,DEFAULT_WIDTHS:()=>A1,DEFAULT_QUALITY:()=>R1,DEFAULT_FORMATS:()=>w1});import KX from"fs";import m5 from"path";import $W from"os";import WX from"crypto";import{generatePlaceholder as GN,processImage as KN}from"ts-images";async function h3(){if(eK)return GX;eK=!0;try{let $=await import("sharp");return GX=$.default||$,GX}catch{return null}}async function A4(){return await h3()!==null}async function m1(){return!0}async function p1($,Z={}){let{widths:Y=A1,formats:X=w1,quality:J=R1,fit:Q="cover",placeholder:G="none",outputDir:K=".stx/images",baseUrl:W="/images"}=Z,U,B;if(typeof $==="string"){if(B=$,!await Bun.file($).exists())throw new n5(`Image not found: ${$}`,"NOT_FOUND");U=await Bun.file($).arrayBuffer().then((N)=>Buffer.from(N))}else B="buffer-input",U=$;let _=WX.createHash("sha256").update(U).digest("hex").slice(0,12),z=await p5(U),{width:q,height:j}=z,H=q/j;await KX.promises.mkdir(K,{recursive:!0});let L=[],F=m5.basename(B,m5.extname(B)),O=Y.filter((N)=>N<=q);if(!O.includes(q)&&q<=Math.max(...Y))O.push(q);O.sort((N,A)=>N-A);for(let N of O){let A=Math.round(N/H);for(let w of X){let R=`${F}-${N}w-${_}.${w}`,M=m5.join(K,R),T=`${W}/${R}`,E=await YW(U,{width:N,height:A,format:w,quality:J,fit:Q});await Bun.write(M,E),L.push({path:M,url:T,width:N,height:A,format:w,size:E.length})}}let V;if(G!=="none")V=await BN(U,G);return{src:B,variants:L,placeholder:V,width:q,height:j,aspectRatio:H,hash:_}}async function p5($){let Z=typeof $==="string"?Buffer.from(await Bun.file($).arrayBuffer()):$,Y=await h3();if(Y){let J=await Y(Z).metadata();return{width:J.width||0,height:J.height||0,format:J.format||"unknown",hasAlpha:J.hasAlpha}}return UN(Z)}function UN($){if($[0]===137&&$[1]===80&&$[2]===78&&$[3]===71){let Z=$.readUInt32BE(16),Y=$.readUInt32BE(20);return{width:Z,height:Y,format:"png",hasAlpha:!0}}if($[0]===255&&$[1]===216){let Z=2;while(Z<$.length){if($[Z]!==255)break;let Y=$[Z+1];if(Y>=192&&Y<=207&&Y!==196&&Y!==200&&Y!==204){let J=$.readUInt16BE(Z+5);return{width:$.readUInt16BE(Z+7),height:J,format:"jpeg",hasAlpha:!1}}let X=$.readUInt16BE(Z+2);Z+=2+X}}if($.toString("utf8",0,4)==="RIFF"&&$.toString("utf8",8,12)==="WEBP"){let Z=$.toString("utf8",12,16);if(Z==="VP8 "){let Y=$.readUInt16LE(26)&16383,X=$.readUInt16LE(28)&16383;return{width:Y,height:X,format:"webp",hasAlpha:!1}}if(Z==="VP8L"){let Y=$.readUInt32LE(21),X=(Y&16383)+1,J=(Y>>14&16383)+1;return{width:X,height:J,format:"webp",hasAlpha:!0}}}if($.toString("utf8",0,3)==="GIF"){let Z=$.readUInt16LE(6),Y=$.readUInt16LE(8);return{width:Z,height:Y,format:"gif",hasAlpha:!0}}throw new n5("Unable to parse image dimensions","PARSE_ERROR")}async function YW($,Z){let Y=await h3();if(Y){let J=Y($).resize(Z.width,Z.height,{fit:Z.fit});switch(Z.format){case"webp":J=J.webp({quality:Z.quality});break;case"avif":J=J.avif({quality:Z.quality});break;case"jpeg":J=J.jpeg({quality:Z.quality});break;case"png":J=J.png({quality:Z.quality});break}return J.toBuffer()}let X=m5.join($W.tmpdir(),`stx-img-${WX.randomBytes(8).toString("hex")}.${Z.format}`);try{return await KN({input:$,output:X,format:Z.format,quality:Z.quality,resize:{width:Z.width,height:Z.height,fit:Z.fit}}),Buffer.from(await Bun.file(X).arrayBuffer())}finally{await KX.promises.unlink(X).catch(()=>{})}}async function BN($,Z){let Y=await h3();if(Z==="blur"&&Y){let G=(await Y($).resize(20).blur(10).toBuffer()).toString("base64"),K=await p5($);return`data:${ZW[K.format]||"image/jpeg"};base64,${G}`}if(Z==="dominant-color"&&Y){let{dominant:Q}=await Y($).resize(1,1).toBuffer().then(async(G)=>{let K=await Y(G).metadata();return{dominant:{r:128,g:128,b:128}}}).catch(()=>({dominant:{r:128,g:128,b:128}}));return`rgb(${Q.r}, ${Q.g}, ${Q.b})`}let X=await p5($),J=m5.join($W.tmpdir(),`stx-ph-${WX.randomBytes(8).toString("hex")}.${X.format==="unknown"?"bin":X.format}`);try{await Bun.write(J,$);let Q=Z==="blur"?"blur":Z==="thumbhash"?"thumbhash":"dominant-color",K=await GN(J,{strategy:Q,width:Q==="thumbhash"?void 0:32});if(Z==="dominant-color"&&K.dominantColor)return K.dominantColor;if(K.dataURL)return K.dataURL;return"rgb(128, 128, 128)"}catch{return"rgb(128, 128, 128)"}finally{await KX.promises.unlink(J).catch(()=>{})}}function B5($,Z){return(Z?$.filter((X)=>X.format===Z):$).sort((X,J)=>X.width-J.width).map((X)=>`${X.url} ${X.width}w`).join(", ")}function c5($){if(!$||Object.keys($).length===0)return"100vw";return Object.entries($).sort((Y,X)=>{let J=Number.parseInt(Y[0].replace(/\D/g,""))||0;return(Number.parseInt(X[0].replace(/\D/g,""))||0)-J}).map(([Y,X])=>`(max-width: ${Y}) ${X}`).join(", ")+", 100vw"}function l5($){let Z=$.filter((X)=>X.format==="jpeg");if(Z.length===0)return $[Math.floor($.length/2)];let Y=Z.sort((X,J)=>X.width-J.width);return Y[Math.floor(Y.length/2)]}function i5($){let Z=new Map;for(let Y of $){let X=Z.get(Y.format)||[];X.push(Y),Z.set(Y.format,X)}return Z}function w4($){let Z=m5.extname($).toLowerCase();return WN.includes(Z)}function M1($){return ZW[$]||"application/octet-stream"}function d3($){return $.reduce((Z,Y)=>Z+Y.size,0)}function u3($){if($<1024)return`${$} B`;if($<1048576)return`${($/1024).toFixed(1)} KB`;return`${($/1048576).toFixed(2)} MB`}var A1,w1,R1=80,WN,ZW,GX=null,eK=!1,n5;var _5=k(()=>{A1=[320,640,768,1024,1280,1536,1920],w1=["webp","jpeg"],WN=[".jpg",".jpeg",".png",".webp",".avif",".gif",".svg"],ZW={webp:"image/webp",avif:"image/avif",jpeg:"image/jpeg",png:"image/png"};n5=class n5 extends Error{code;constructor($,Z){super($);this.name="ImageProcessingError",this.code=Z}}});var JW={};t(JW,{rewriteImagesWithSiblings:()=>UX});import Y$ from"path";async function UX($,Z){let Y=Z.formats??zN;if(!Z.publicDir)return $;let X=HN($),J=[],Q=/<img\b[^>]*?>/gi,G=[],K;while((K=Q.exec($))!==null){let _=K[0],z=_.match(/\bsrc=["']([^"']+)["']/i);if(!z)continue;if(ON(K.index,X))continue;G.push({idx:K.index,length:_.length,src:z[1],raw:_})}if(G.length===0)return $;let W=await Promise.all(G.map(async(_)=>{let z=await qN(_.src,Z.publicDir,Y);return{match:_,sources:z}}));for(let{match:_,sources:z}of W){if(z.length===0)continue;let j=`<picture>${z.map((H)=>`<source type="${H.mime}" srcset="${LN(H.url)}">`).join("")}${_.raw}</picture>`;J.push({start:_.idx,end:_.idx+_.length,replacement:j})}if(J.length===0)return $;let U="",B=0;for(let _ of J)U+=$.slice(B,_.start),U+=_.replacement,B=_.end;return U+=$.slice(B),U}async function qN($,Z,Y){if(!jN($))return[];let X=Y$.extname($).toLowerCase();if(!_N.has(X))return[];if(!$.startsWith("/"))return[];let J=Y$.join(Z,$.slice(1)),Q=Y$.dirname(J),G=Y$.basename(J,X),K=Y$.resolve(Q),W=Y$.resolve(Z);if(!K.startsWith(W))return[];let U=Y$.posix.dirname($),B=Y.map(async(z)=>{let q=Y$.join(Q,`${G}${z.ext}`);if(!await Bun.file(q).exists())return null;return{url:Y$.posix.join(U,`${G}${z.ext}`),mime:z.mime}});return(await Promise.all(B)).filter((z)=>z!==null)}function jN($){if(!$)return!1;if($.startsWith("http://")||$.startsWith("https://"))return!1;if($.startsWith("//"))return!1;if($.startsWith("data:"))return!1;return!0}function HN($){let Z=[],Y=/<picture\b[^>]*>[\s\S]*?<\/picture>/gi,X;while((X=Y.exec($))!==null)Z.push([X.index,X.index+X[0].length]);return Z}function ON($,Z){for(let[Y,X]of Z)if($>=Y&&$<X)return!0;return!1}function LN($){return $.replace(/&/g,"&").replace(/"/g,""")}var _N,zN;var BX=k(()=>{_N=new Set([".jpg",".jpeg",".png",".gif"]),zN=[{ext:".avif",mime:"image/avif"},{ext:".webp",mime:"image/webp"}]});var UW={};t(UW,{handleImageRequest:()=>m3,createImageHandler:()=>_X});import QW from"fs";import R4 from"path";import FN from"crypto";async function m3($,Z){let Y=Z.routePath??"/_stx/img",X=new URL($.url);if(X.pathname!==Y)return null;let J=wN(X,Z);if(!J.ok)return new Response(J.error,{status:J.status,headers:{"Content-Type":"text/plain"}});let{srcFsPath:Q,srcUrl:G,width:K,height:W,format:U,quality:B,fit:_}=J,z;try{z=QW.statSync(Q)}catch{return new Response(`Source image not found: ${G}`,{status:404,headers:{"Content-Type":"text/plain"}})}if(!z.isFile())return new Response("Not a file",{status:404,headers:{"Content-Type":"text/plain"}});let q=Z.cacheDir??".stx/cache/img";await QW.promises.mkdir(q,{recursive:!0});let j=`${Q}:${z.mtimeMs}:${z.size}`,H=`${K}x${W}:${U}:${B}:${_}`,L=FN.createHash("sha256").update(`${j}|${H}`).digest("hex").slice(0,16),F=R4.join(q,`${L}.${U}`),V={"Content-Type":M1(U),"Cache-Control":"public, max-age=31536000, immutable",ETag:`"${L}"`,"X-Stx-Image-Cache":"HIT"};if($.headers.get("if-none-match")===`"${L}"`)return new Response(null,{status:304,headers:V});let N=Bun.file(F);if(await N.exists())return new Response(N,{headers:V});try{let A=Buffer.from(await Bun.file(Q).arrayBuffer()),{resizeAndConvert:w}=await RN(),R=await w(A,{width:K,height:W,format:U,quality:B,fit:_});return await Bun.write(F,R),V["X-Stx-Image-Cache"]="MISS",new Response(new Uint8Array(R),{headers:V})}catch(A){let w=A.message;return new Response(`Image processing failed: ${w}`,{status:500,headers:{"Content-Type":"text/plain"}})}}function _X($){return async(Z)=>{return await m3(Z,$)??new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain"}})}}function wN($,Z){let Y=$.searchParams.get("src");if(!Y)return{ok:!1,error:"Missing required param: src",status:400};if(!Y.startsWith("/"))return{ok:!1,error:"src must be an absolute URL path (start with /)",status:400};if(Y.startsWith("//"))return{ok:!1,error:"src must be a local path",status:400};let X=R4.extname(Y).toLowerCase();if(!VN.has(X))return{ok:!1,error:`Unsupported source extension: ${X}`,status:400};let J=R4.resolve(Z.publicDir),Q=R4.resolve(J,Y.slice(1));if(!Q.startsWith(`${J}${R4.sep}`)&&Q!==J)return{ok:!1,error:"src is outside publicDir",status:400};let G=Z.maxWidth??WW,K=Z.maxHeight??WW,W=$.searchParams.get("w"),U=$.searchParams.get("h"),B=W?Number.parseInt(W,10):0,_=U?Number.parseInt(U,10):0;if(W&&(!Number.isFinite(B)||B<=0))return{ok:!1,error:"Invalid w (must be positive integer)",status:400};if(U&&(!Number.isFinite(_)||_<=0))return{ok:!1,error:"Invalid h (must be positive integer)",status:400};if(!W&&!U)return{ok:!1,error:"At least one of w or h is required",status:400};let z=Math.min(B||G,G),q=Math.min(_||K,K),j=$.searchParams.get("f")||"webp";if(!GW.has(j))return{ok:!1,error:`Invalid f (must be one of: ${[...GW].join(", ")})`,status:400};let H=j,L=$.searchParams.get("q"),F=L?Number.parseInt(L,10):Z.defaultQuality??NN;if(!Number.isFinite(F)||F<1||F>100)return{ok:!1,error:"Invalid q (must be 1-100)",status:400};let O=$.searchParams.get("fit")||Z.defaultFit||AN;if(!KW.has(O))return{ok:!1,error:`Invalid fit (must be one of: ${[...KW].join(", ")})`,status:400};return{ok:!0,srcFsPath:Q,srcUrl:Y,width:z,height:q,format:H,quality:F,fit:O}}async function RN(){return await Promise.resolve().then(() => (_5(),XW))}var GW,KW,VN,WW=4096,NN=80,AN="cover";var zX=k(()=>{_5();GW=new Set(["webp","avif","jpeg","png"]),KW=new Set(["cover","contain","fill","inside","outside"]),VN=new Set([".jpg",".jpeg",".png",".webp",".avif",".gif"])});function BW($,Z={}){let{src:Y,alt:X,width:J,height:Q,sizes:G="100vw",loading:K="lazy",priority:W=!1,quality:U=R1,placeholder:B="none",formats:_=w1,widths:z=A1,decoding:q="async",fetchpriority:j,objectFit:H,objectPosition:L}=$,F=$.class,O=$.style,{processedImage:V,variants:N,optimize:A=!0,isDev:w=!1}=Z;if(N&&N.length>0)return MN($,N,V);if(w||!A)return TN($);return IN($)}function MN($,Z,Y){let{src:X,alt:J,width:Q,height:G,sizes:K="100vw",loading:W="lazy",priority:U=!1,decoding:B="async",fetchpriority:_,objectFit:z,objectPosition:q,placeholder:j="none"}=$,H=$.class,L=$.style,F=i5(Z),O=l5(Z),V=typeof K==="object"?c5(K):K,N=Y?Y.aspectRatio:Q&&G?Number(Q)/Number(G):void 0,A=[];if(N)A.push(`aspect-ratio: ${N}`);if(z)A.push(`object-fit: ${z}`);if(q)A.push(`object-position: ${q}`);if(L)A.push(L);let w=A.length>0?` style="${A.join("; ")}"`:"",R=H?` class="${H}"`:"",M=U?"":` loading="${W}"`,T=` decoding="${B}"`,E=_?` fetchpriority="${_}"`:U?' fetchpriority="high"':"",D=["avif","webp","jpeg","png"],S=[];for(let h of D){let m=F.get(h);if(m&&m.length>0){let n=B5(m),r=M1(h);S.push(` <source type="${r}" srcset="${n}" sizes="${V}" />`)}}let C="",P="",b;if(j!=="none"&&Y?.placeholder){let h=`img-${Math.random().toString(36).slice(2,8)}`;if(C=`<div class="stx-image-wrapper" id="${h}">`,P="</div>",j==="blur")b=`
|
|
496
|
+
`,await Bun.write(X,J)}return{configPath:Y,siteId:$.siteId}}function QN($){let Z=process.platform,Y=Z==="darwin"?"open":Z==="win32"?"start":"xdg-open";Bun.spawn([Y,$],{stdio:["ignore","ignore","ignore"]})}var R$;var QX=k(()=>{YX();YX();R$=class R$ extends Error{code;constructor($,Z){super($);this.name="DeployError",this.code=Z}}});var XW={};t(XW,{resizeAndConvert:()=>YW,processImage:()=>p1,isSharpAvailable:()=>A4,isImageFile:()=>w4,isImageBackendAvailable:()=>m1,groupVariantsByFormat:()=>i5,getTotalSize:()=>d3,getMimeType:()=>M1,getImageMetadata:()=>p5,getFallbackVariant:()=>l5,generateSrcSet:()=>B5,generateSizes:()=>c5,formatSize:()=>u3,ImageProcessingError:()=>n5,DEFAULT_WIDTHS:()=>A1,DEFAULT_QUALITY:()=>R1,DEFAULT_FORMATS:()=>w1});import KX from"fs";import m5 from"path";import $W from"os";import WX from"crypto";import{generatePlaceholder as GN,processImage as KN}from"ts-images";async function h3(){if(eK)return GX;eK=!0;try{let $=await import("sharp");return GX=$.default||$,GX}catch{return null}}async function A4(){return await h3()!==null}async function m1(){return!0}async function p1($,Z={}){let{widths:Y=A1,formats:X=w1,quality:J=R1,fit:Q="cover",placeholder:G="none",outputDir:K=".stx/images",baseUrl:W="/images"}=Z,U,B;if(typeof $==="string"){if(B=$,!await Bun.file($).exists())throw new n5(`Image not found: ${$}`,"NOT_FOUND");U=await Bun.file($).arrayBuffer().then((N)=>Buffer.from(N))}else B="buffer-input",U=$;let _=WX.createHash("sha256").update(U).digest("hex").slice(0,12),z=await p5(U),{width:q,height:j}=z,H=q/j;await KX.promises.mkdir(K,{recursive:!0});let L=[],F=m5.basename(B,m5.extname(B)),O=Y.filter((N)=>N<=q);if(!O.includes(q)&&q<=Math.max(...Y))O.push(q);O.sort((N,A)=>N-A);for(let N of O){let A=Math.round(N/H);for(let w of X){let R=`${F}-${N}w-${_}.${w}`,M=m5.join(K,R),T=`${W}/${R}`,E=await YW(U,{width:N,height:A,format:w,quality:J,fit:Q});await Bun.write(M,E),L.push({path:M,url:T,width:N,height:A,format:w,size:E.length})}}let V;if(G!=="none")V=await BN(U,G);return{src:B,variants:L,placeholder:V,width:q,height:j,aspectRatio:H,hash:_}}async function p5($){let Z=typeof $==="string"?Buffer.from(await Bun.file($).arrayBuffer()):$,Y=await h3();if(Y){let J=await Y(Z).metadata();return{width:J.width||0,height:J.height||0,format:J.format||"unknown",hasAlpha:J.hasAlpha}}return UN(Z)}function UN($){if($[0]===137&&$[1]===80&&$[2]===78&&$[3]===71){let Z=$.readUInt32BE(16),Y=$.readUInt32BE(20);return{width:Z,height:Y,format:"png",hasAlpha:!0}}if($[0]===255&&$[1]===216){let Z=2;while(Z<$.length){if($[Z]!==255)break;let Y=$[Z+1];if(Y>=192&&Y<=207&&Y!==196&&Y!==200&&Y!==204){let J=$.readUInt16BE(Z+5);return{width:$.readUInt16BE(Z+7),height:J,format:"jpeg",hasAlpha:!1}}let X=$.readUInt16BE(Z+2);Z+=2+X}}if($.toString("utf8",0,4)==="RIFF"&&$.toString("utf8",8,12)==="WEBP"){let Z=$.toString("utf8",12,16);if(Z==="VP8 "){let Y=$.readUInt16LE(26)&16383,X=$.readUInt16LE(28)&16383;return{width:Y,height:X,format:"webp",hasAlpha:!1}}if(Z==="VP8L"){let Y=$.readUInt32LE(21),X=(Y&16383)+1,J=(Y>>14&16383)+1;return{width:X,height:J,format:"webp",hasAlpha:!0}}}if($.toString("utf8",0,3)==="GIF"){let Z=$.readUInt16LE(6),Y=$.readUInt16LE(8);return{width:Z,height:Y,format:"gif",hasAlpha:!0}}throw new n5("Unable to parse image dimensions","PARSE_ERROR")}async function YW($,Z){let Y=await h3();if(Y){let J=Y($).resize(Z.width,Z.height,{fit:Z.fit});switch(Z.format){case"webp":J=J.webp({quality:Z.quality});break;case"avif":J=J.avif({quality:Z.quality});break;case"jpeg":J=J.jpeg({quality:Z.quality});break;case"png":J=J.png({quality:Z.quality});break}return J.toBuffer()}let X=m5.join($W.tmpdir(),`stx-img-${WX.randomBytes(8).toString("hex")}.${Z.format}`);try{return await KN({input:$,output:X,format:Z.format,quality:Z.quality,resize:{width:Z.width,height:Z.height,fit:Z.fit}}),Buffer.from(await Bun.file(X).arrayBuffer())}finally{await KX.promises.unlink(X).catch(()=>{})}}async function BN($,Z){let Y=await h3();if(Z==="blur"&&Y){let G=(await Y($).resize(20).blur(10).toBuffer()).toString("base64"),K=await p5($);return`data:${ZW[K.format]||"image/jpeg"};base64,${G}`}if(Z==="dominant-color"&&Y){let{dominant:Q}=await Y($).resize(1,1).toBuffer().then(async(G)=>{let K=await Y(G).metadata();return{dominant:{r:128,g:128,b:128}}}).catch(()=>({dominant:{r:128,g:128,b:128}}));return`rgb(${Q.r}, ${Q.g}, ${Q.b})`}let X=await p5($),J=m5.join($W.tmpdir(),`stx-ph-${WX.randomBytes(8).toString("hex")}.${X.format==="unknown"?"bin":X.format}`);try{await Bun.write(J,$);let Q=Z==="blur"?"blur":Z==="thumbhash"?"thumbhash":"dominant-color",K=await GN(J,{strategy:Q,width:Q==="thumbhash"?void 0:32});if(Z==="dominant-color"&&K.dominantColor)return K.dominantColor;if(K.dataURL)return K.dataURL;return"rgb(128, 128, 128)"}catch{return"rgb(128, 128, 128)"}finally{await KX.promises.unlink(J).catch(()=>{})}}function B5($,Z){return(Z?$.filter((X)=>X.format===Z):$).sort((X,J)=>X.width-J.width).map((X)=>`${X.url} ${X.width}w`).join(", ")}function c5($){if(!$||Object.keys($).length===0)return"100vw";return Object.entries($).sort((Y,X)=>{let J=Number.parseInt(Y[0].replace(/\D/g,""))||0;return(Number.parseInt(X[0].replace(/\D/g,""))||0)-J}).map(([Y,X])=>`(max-width: ${Y}) ${X}`).join(", ")+", 100vw"}function l5($){let Z=$.filter((X)=>X.format==="jpeg");if(Z.length===0)return $[Math.floor($.length/2)];let Y=Z.sort((X,J)=>X.width-J.width);return Y[Math.floor(Y.length/2)]}function i5($){let Z=new Map;for(let Y of $){let X=Z.get(Y.format)||[];X.push(Y),Z.set(Y.format,X)}return Z}function w4($){let Z=m5.extname($).toLowerCase();return WN.includes(Z)}function M1($){return ZW[$]||"application/octet-stream"}function d3($){return $.reduce((Z,Y)=>Z+Y.size,0)}function u3($){if($<1024)return`${$} B`;if($<1048576)return`${($/1024).toFixed(1)} KB`;return`${($/1048576).toFixed(2)} MB`}var A1,w1,R1=80,WN,ZW,GX=null,eK=!1,n5;var _5=k(()=>{A1=[320,640,768,1024,1280,1536,1920],w1=["webp","jpeg"],WN=[".jpg",".jpeg",".png",".webp",".avif",".gif",".svg"],ZW={webp:"image/webp",avif:"image/avif",jpeg:"image/jpeg",png:"image/png"};n5=class n5 extends Error{code;constructor($,Z){super($);this.name="ImageProcessingError",this.code=Z}}});var JW={};t(JW,{rewriteImagesWithSiblings:()=>UX});import Y$ from"path";async function UX($,Z){let Y=Z.formats??zN;if(!Z.publicDir)return $;let X=HN($),J=[],Q=/<img\b[^>]*?>/gi,G=[],K;while((K=Q.exec($))!==null){let _=K[0],z=_.match(/\bsrc=["']([^"']+)["']/i);if(!z)continue;if(ON(K.index,X))continue;G.push({idx:K.index,length:_.length,src:z[1],raw:_})}if(G.length===0)return $;let W=await Promise.all(G.map(async(_)=>{let z=await qN(_.src,Z.publicDir,Y);return{match:_,sources:z}}));for(let{match:_,sources:z}of W){if(z.length===0)continue;let j=`<picture>${z.map((H)=>`<source type="${H.mime}" srcset="${LN(H.url)}">`).join("")}${_.raw}</picture>`;J.push({start:_.idx,end:_.idx+_.length,replacement:j})}if(J.length===0)return $;let U="",B=0;for(let _ of J)U+=$.slice(B,_.start),U+=_.replacement,B=_.end;return U+=$.slice(B),U}async function qN($,Z,Y){if(!jN($))return[];let X=Y$.extname($).toLowerCase();if(!_N.has(X))return[];if(!$.startsWith("/"))return[];let J=Y$.join(Z,$.slice(1)),Q=Y$.dirname(J),G=Y$.basename(J,X),K=Y$.resolve(Q),W=Y$.resolve(Z);if(!K.startsWith(W))return[];let U=Y$.posix.dirname($),B=Y.map(async(z)=>{let q=Y$.join(Q,`${G}${z.ext}`);if(!await Bun.file(q).exists())return null;return{url:Y$.posix.join(U,`${G}${z.ext}`),mime:z.mime}});return(await Promise.all(B)).filter((z)=>z!==null)}function jN($){if(!$)return!1;if($.startsWith("http://")||$.startsWith("https://"))return!1;if($.startsWith("//"))return!1;if($.startsWith("data:"))return!1;return!0}function HN($){let Z=[],Y=/<picture\b[^>]*>[\s\S]*?<\/picture>/gi,X;while((X=Y.exec($))!==null)Z.push([X.index,X.index+X[0].length]);return Z}function ON($,Z){for(let[Y,X]of Z)if($>=Y&&$<X)return!0;return!1}function LN($){return $.replace(/&/g,"&").replace(/"/g,""")}var _N,zN;var BX=k(()=>{_N=new Set([".jpg",".jpeg",".png",".gif"]),zN=[{ext:".avif",mime:"image/avif"},{ext:".webp",mime:"image/webp"}]});var UW={};t(UW,{handleImageRequest:()=>m3,createImageHandler:()=>_X});import QW from"fs";import R4 from"path";import FN from"crypto";async function m3($,Z){let Y=Z.routePath??"/_stx/img",X=new URL($.url);if(X.pathname!==Y)return null;let J=wN(X,Z);if(!J.ok)return new Response(J.error,{status:J.status,headers:{"Content-Type":"text/plain"}});let{srcFsPath:Q,srcUrl:G,width:K,height:W,format:U,quality:B,fit:_}=J,z;try{z=QW.statSync(Q)}catch{return new Response(`Source image not found: ${G}`,{status:404,headers:{"Content-Type":"text/plain"}})}if(!z.isFile())return new Response("Not a file",{status:404,headers:{"Content-Type":"text/plain"}});let q=Z.cacheDir??".stx/cache/img";await QW.promises.mkdir(q,{recursive:!0});let j=`${Q}:${z.mtimeMs}:${z.size}`,H=`${K}x${W}:${U}:${B}:${_}`,L=FN.createHash("sha256").update(`${j}|${H}`).digest("hex").slice(0,16),F=R4.join(q,`${L}.${U}`),V={"Content-Type":M1(U),"Cache-Control":"public, max-age=31536000, immutable",ETag:`"${L}"`,"X-Stx-Image-Cache":"HIT"};if($.headers.get("if-none-match")===`"${L}"`)return new Response(null,{status:304,headers:V});let N=Bun.file(F);if(await N.exists())return new Response(N,{headers:V});try{let A=Buffer.from(await Bun.file(Q).arrayBuffer()),{resizeAndConvert:w}=await RN(),R=await w(A,{width:K,height:W,format:U,quality:B,fit:_});return await Bun.write(F,R),V["X-Stx-Image-Cache"]="MISS",new Response(new Uint8Array(R),{headers:V})}catch(A){let w=A.message;return new Response(`Image processing failed: ${w}`,{status:500,headers:{"Content-Type":"text/plain"}})}}function _X($){return async(Z)=>{return await m3(Z,$)??new Response("Not Found",{status:404,headers:{"Content-Type":"text/plain"}})}}function wN($,Z){let Y=$.searchParams.get("src");if(!Y)return{ok:!1,error:"Missing required param: src",status:400};if(!Y.startsWith("/"))return{ok:!1,error:"src must be an absolute URL path (start with /)",status:400};if(Y.startsWith("//"))return{ok:!1,error:"src must be a local path",status:400};let X=R4.extname(Y).toLowerCase();if(!VN.has(X))return{ok:!1,error:`Unsupported source extension: ${X}`,status:400};let J=R4.resolve(Z.publicDir),Q=R4.resolve(J,Y.slice(1));if(!Q.startsWith(`${J}${R4.sep}`)&&Q!==J)return{ok:!1,error:"src is outside publicDir",status:400};let G=Z.maxWidth??WW,K=Z.maxHeight??WW,W=$.searchParams.get("w"),U=$.searchParams.get("h"),B=W?Number.parseInt(W,10):0,_=U?Number.parseInt(U,10):0;if(W&&(!Number.isFinite(B)||B<=0))return{ok:!1,error:"Invalid w (must be positive integer)",status:400};if(U&&(!Number.isFinite(_)||_<=0))return{ok:!1,error:"Invalid h (must be positive integer)",status:400};if(!W&&!U)return{ok:!1,error:"At least one of w or h is required",status:400};let z=Math.min(B||G,G),q=Math.min(_||K,K),j=$.searchParams.get("f")||"webp";if(!GW.has(j))return{ok:!1,error:`Invalid f (must be one of: ${[...GW].join(", ")})`,status:400};let H=j,L=$.searchParams.get("q"),F=L?Number.parseInt(L,10):Z.defaultQuality??NN;if(!Number.isFinite(F)||F<1||F>100)return{ok:!1,error:"Invalid q (must be 1-100)",status:400};let O=$.searchParams.get("fit")||Z.defaultFit||AN;if(!KW.has(O))return{ok:!1,error:`Invalid fit (must be one of: ${[...KW].join(", ")})`,status:400};return{ok:!0,srcFsPath:Q,srcUrl:Y,width:z,height:q,format:H,quality:F,fit:O}}async function RN(){return await Promise.resolve().then(() => (_5(),XW))}var GW,KW,VN,WW=4096,NN=80,AN="cover";var zX=k(()=>{_5();GW=new Set(["webp","avif","jpeg","png"]),KW=new Set(["cover","contain","fill","inside","outside"]),VN=new Set([".jpg",".jpeg",".png",".webp",".avif",".gif"])});function BW($,Z={}){let{src:Y,alt:X,width:J,height:Q,sizes:G="100vw",loading:K="lazy",priority:W=!1,quality:U=R1,placeholder:B="none",formats:_=w1,widths:z=A1,decoding:q="async",fetchpriority:j,objectFit:H,objectPosition:L}=$,F=$.class,O=$.style,{processedImage:V,variants:N,optimize:A=!0,isDev:w=!1}=Z;if(N&&N.length>0)return MN($,N,V);if(w||!A)return TN($);return IN($)}function MN($,Z,Y){let{src:X,alt:J,width:Q,height:G,sizes:K="100vw",loading:W="lazy",priority:U=!1,decoding:B="async",fetchpriority:_,objectFit:z,objectPosition:q,placeholder:j="none"}=$,H=$.class,L=$.style,F=i5(Z),O=l5(Z),V=typeof K==="object"?c5(K):K,N=Y?Y.aspectRatio:Q&&G?Number(Q)/Number(G):void 0,A=[];if(N)A.push(`aspect-ratio: ${N}`);if(z)A.push(`object-fit: ${z}`);if(q)A.push(`object-position: ${q}`);if(L)A.push(L);let w=A.length>0?` style="${A.join("; ")}"`:"",R=H?` class="${H}"`:"",M=U?"":` loading="${W}"`,T=` decoding="${B}"`,E=_?` fetchpriority="${_}"`:U?' fetchpriority="high"':"",D=["avif","webp","jpeg","png"],S=[];for(let h of D){let p=F.get(h);if(p&&p.length>0){let n=B5(p),r=M1(h);S.push(` <source type="${r}" srcset="${n}" sizes="${V}" />`)}}let C="",P="",b;if(j!=="none"&&Y?.placeholder){let h=`img-${Math.random().toString(36).slice(2,8)}`;if(C=`<div class="stx-image-wrapper" id="${h}">`,P="</div>",j==="blur")b=`
|
|
497
497
|
#${h} {
|
|
498
498
|
position: relative;
|
|
499
499
|
background-image: url('${Y.placeholder}');
|
|
@@ -517,7 +517,7 @@ ${S.join(`
|
|
|
517
517
|
src="${O?.url||X}"
|
|
518
518
|
alt="${jX(J)}"${x}${s}${R}${w}${M}${T}${E}
|
|
519
519
|
/>
|
|
520
|
-
</picture>${P}`,y;if(U&&O){let h=F.get("webp"),
|
|
520
|
+
</picture>${P}`,y;if(U&&O){let h=F.get("webp"),p=h?.[Math.floor(h.length/2)]||O,n=M1(p.format);y=`<link rel="preload" as="image" href="${p.url}" type="${n}" />`}return{html:u,preloadLink:y,placeholderCss:b}}function TN($){let{src:Z,alt:Y,width:X,height:J,loading:Q="lazy",decoding:G="async",priority:K=!1,fetchpriority:W,objectFit:U,objectPosition:B}=$,_=$.class,z=$.style,q=[];if(U)q.push(`object-fit: ${U}`);if(B)q.push(`object-position: ${B}`);if(z)q.push(z);let j=q.length>0?` style="${q.join("; ")}"`:"",H=_?` class="${_}"`:"",L=X?` width="${X}"`:"",F=J?` height="${J}"`:"",O=K?"":` loading="${Q}"`,V=` decoding="${G}"`,N=W?` fetchpriority="${W}"`:K?' fetchpriority="high"':"";return{html:`<img src="${Z}" alt="${jX(Y)}"${L}${F}${H}${j}${O}${V}${N} />`}}function IN($){let{src:Z,alt:Y,width:X,height:J,sizes:Q="100vw",loading:G="lazy",priority:K=!1,quality:W=R1,formats:U=w1,widths:B=A1,decoding:_="async",fetchpriority:z,objectFit:q,objectPosition:j}=$,H=$.class,L=$.style,F=[];if(q)F.push(`object-fit: ${q}`);if(j)F.push(`object-position: ${j}`);if(L)F.push(L);let O=F.length>0?` style="${F.join("; ")}"`:"",V=H?` class="${H}"`:"",N=X?` width="${X}"`:"",A=J?` height="${J}"`:"",w=K?"":` loading="${G}"`,R=` decoding="${_}"`,M=z?` fetchpriority="${z}"`:K?' fetchpriority="high"':"",T=typeof Q==="object"?c5(Q):Q,E=`
|
|
521
521
|
data-stx-image
|
|
522
522
|
data-src="${Z}"
|
|
523
523
|
data-sizes="${T}"
|
|
@@ -1187,7 +1187,7 @@ ${H}
|
|
|
1187
1187
|
filter: blur(0);
|
|
1188
1188
|
transform: scale(1);
|
|
1189
1189
|
}
|
|
1190
|
-
`.trim();$7=new Map});import{createHash as $J}from"crypto";import{readFile as jA,stat as $U}from"fs/promises";async function l0($){try{let Z=await jA($);return $J("sha256").update(Z).digest("hex").slice(0,16)}catch{return""}}function ZU($){return $J("sha256").update($).digest("hex").slice(0,16)}function U8($){return $J("sha256").update($).digest("hex").slice(0,16)}function Y7($,Z){let Y=JSON.stringify(Z,Object.keys(Z).sort());return`${U8($)}-${U8(Y)}`}async function p4($){try{return(await $U($)).mtimeMs}catch{return 0}}async function i0($){try{return await $U($),!0}catch{return!1}}var I$=()=>{};import{mkdir as HA,readFile as XU,writeFile as OA,readdir as JU,rm as ZJ,stat as LA}from"fs/promises";import{join as X7,dirname as FA}from"path";async function VA($){try{await HA($,{recursive:!0})}catch{}}function QU($,Z,Y){return X7($,Y,`${Z}.json`)}async function YU($,Z,Y){if((Date.now()-$.createdAt)/86400000>Y)return!1;if(await p4(Z)!==$.srcMtime)return!1;return!0}async function Q7($,Z,Y,X=J7){if(!X.enabled)return null;let J=Y7($,Z),Q=l1.get(J);if(Q){if(await YU(Q,$,X.maxAge))return Q.lastAccessedAt=Date.now(),Q.data;l1.delete(J)}let G=QU(X.directory,J,Y);if(await i0(G))try{let K=await XU(G,"utf-8"),W=JSON.parse(K);if(await YU(W,$,X.maxAge))return W.lastAccessedAt=Date.now(),l1.set(J,W),W.data}catch{}return null}async function G7($,Z,Y,X,J=J7){if(!J.enabled)return;let Q=Y7($,Z),G=await l0($),K=await p4($),W={key:Q,src:$,srcHash:G,srcMtime:K,optionsHash:Y7("",Z),data:Y,createdAt:Date.now(),lastAccessedAt:Date.now()};l1.set(Q,W);let U=QU(J.directory,Q,X);try{await VA(FA(U)),await OA(U,JSON.stringify(W,null,2))}catch(B){console.warn(`[stx-media] Failed to write cache: ${B}`)}}async function Ex($,Z,Y=J7){for(let[X,J]of l1.entries())if(J.src===$)l1.delete(X)}async function K7($,Z=J7){if($==="all")l1.clear();else l1.clear();let Y=$==="all"?["image","video"]:[$];for(let X of Y){let J=X7(Z.directory,X);try{await ZJ(J,{recursive:!0,force:!0})}catch{}}}async function GU($=J7){let Z={memoryEntries:l1.size,diskEntries:{image:0,video:0},totalSizeMB:0};for(let Y of["image","video"]){let X=X7($.directory,Y);try{let J=await JU(X);Z.diskEntries[Y]=J.length;for(let Q of J){let G=X7(X,Q),K=await LA(G);Z.totalSizeMB+=K.size/1048576}}catch{}}return Z}async function KU($=J7){let Z=0,Y=$.maxAge*24*60*60*1000;for(let X of["image","video"]){let J=X7($.directory,X);try{let Q=await JU(J);for(let G of Q){let K=X7(J,G);try{let W=await XU(K,"utf-8"),U=JSON.parse(W);if(Date.now()-U.createdAt>Y)await ZJ(K),l1.delete(U.key),Z++}catch{await ZJ(K).catch(()=>{}),Z++}}}catch{}}return Z}var l1,J7;var B8=k(()=>{I$();l1=new Map,J7={enabled:!0,directory:".stx/media-cache",maxAge:30,maxSize:500}});class W7{config;constructor($={}){this.config={...NA,...$}}async get($,Z){return Q7($,Z,"image",this.config)}async set($,Z,Y){return G7($,Z,Y,"image",this.config)}async clear(){return K7("image",this.config)}updateConfig($){this.config={...this.config,...$}}}function YJ($){if(!_8)_8=new W7($);else if($)_8.updateConfig($);return _8}async function U7($,Z,Y){let X=Y?{directory:`${Y.outputDir}/../.cache`}:{};return YJ(X).get($,Z)}async function B7($,Z,Y,X){let J=X?{directory:`${X.outputDir}/../.cache`}:{};return YJ(J).set($,Z,Y)}async function XJ(){return YJ().clear()}var NA,_8=null;var JJ=k(()=>{B8();NA={enabled:!0,directory:".stx/media-cache",maxAge:30,maxSize:500,cacheVariants:!0,cachePlaceholders:!0}});import{resolve as AA,basename as wA,extname as RA,join as MA}from"path";import{mkdir as TA}from"fs/promises";async function QJ(){try{return await import("ts-images")}catch{return null}}function WU($){switch($){case"quality":return{jpeg:{quality:90,mozjpeg:!0,progressive:!0},png:{compressionLevel:6,palette:!1},webp:{quality:90,effort:6,smartSubsample:!0},avif:{quality:85,effort:6}};case"performance":return{jpeg:{quality:70,mozjpeg:!0,progressive:!0},png:{compressionLevel:9,palette:!0},webp:{quality:70,effort:4,smartSubsample:!0},avif:{quality:60,effort:2}};case"web":default:return{jpeg:{quality:82,mozjpeg:!0,progressive:!0},png:{compressionLevel:8,palette:!1},webp:{quality:82,effort:5,smartSubsample:!0},avif:{quality:75,effort:4}}}}function IA($,Z){let Y=Z?WU(Z):WU("web"),X=$.formatQuality||{};return{jpeg:{...Y.jpeg,...X.jpeg},png:{...Y.png,...X.png},webp:{...Y.webp,...X.webp},avif:{...Y.avif,...X.avif}}}async function GJ($,Z,Y){let X=await QJ();if(!X)return console.warn("[stx-media] ts-images not installed, skipping optimization"),{src:$,processed:!1};let J=await U7($,Z,Y);if(J)return J;try{let Q=AA($);if(!await i0(Q))return{src:$,processed:!1,errors:[`Source file not found: ${$}`]};let G=IA(Y,Z.preset),K=Y.outputDir||"dist/images",W=Y.baseUrl||"/images";await TA(K,{recursive:!0});let U=await l0(Q),B=wA($,RA($)),_=Z.outputFormat?[Z.outputFormat]:Y.defaultFormats||["avif","webp","jpeg"],z={src:$,processed:!0,variants:[],hash:U},q=null;if(Z.transformations&&Z.transformations.length>0)q=await c4(Q,Z.transformations,X);for(let j of _){let H=G[j]||{},L=`${B}-${U}.${j}`,F=MA(K,L);try{let O=await X.optimizeImage({input:q||Q,output:F,format:j,quality:H.quality,progressive:H.progressive});if(O){if(z.variants.push({path:F,url:`${W}/${L}`,width:O.width||0,height:O.height||0,format:j,size:O.outputSize||0}),!z.originalWidth&&O.width)z.originalWidth=O.width,z.originalHeight=O.height}}catch(O){z.errors=z.errors||[],z.errors.push(`Failed to optimize ${j}: ${O}`)}}if(Z.embedThumbhash||Z.placeholder==="thumbhash")try{let j=await X.generateThumbHash(Q);z.placeholder=j.dataUrl}catch(j){z.errors=z.errors||[],z.errors.push(`Failed to generate thumbhash: ${j}`)}if(Z.useDominantColor)try{let j=await X.generatePlaceholder(Q,{strategy:"dominant-color"});z.dominantColor=j.dominantColor}catch(j){z.errors=z.errors||[],z.errors.push(`Failed to extract dominant color: ${j}`)}return await B7($,Z,z,Y),z}catch(Q){return{src:$,processed:!1,errors:[`Processing failed: ${Q}`]}}}async function KJ($,Z,Y,X){let J=await QJ();if(!J)return{success:!1,error:"ts-images not installed"};try{return{success:!0,size:(await J.optimizeImage({input:$,output:X,format:Z,quality:Y}))?.outputSize}}catch(Q){return{success:!1,error:String(Q)}}}async function c4($,Z,Y){let X=Y||await QJ();if(!X)return console.warn("[stx-media] ts-images not installed, skipping transformations"),null;try{let J=await X.decode($);for(let Q of Z){let G=Q.options||{};switch(Q.type){case"resize":if(G.width||G.height)J=await X.resize(J,{width:G.width,height:G.height,fit:G.fit});break;case"blur":if(G.sigma!==void 0)J=await X.blur(J,G.sigma);break;case"sharpen":if(G.amount!==void 0)J=await X.sharpen(J,G.amount);break;case"grayscale":J=await X.grayscale(J);break;case"rotate":if(G.angle!==void 0)J=await X.rotate(J,G.angle);break;case"flip":J=await X.flip(J);break;case"flop":J=await X.flop(J);break;case"brightness":if(G.value!==void 0)J=await X.brightness(J,G.value);break;case"contrast":if(G.value!==void 0)J=await X.contrast(J,G.value);break;case"saturation":if(G.value!==void 0)J=await X.saturation(J,G.value);break}}return await X.encode(J,"png")}catch(J){return console.error(`[stx-media] Transformation failed: ${J}`),null}}var UU=k(()=>{I$();JJ()});import{resolve as EA,basename as DA,extname as kA,join as SA}from"path";import{mkdir as bA}from"fs/promises";async function CA(){try{return await import("ts-images")}catch{return null}}async function l4($,Z,Y){let X=await CA();if(!X)return console.warn("[stx-media] ts-images not installed, skipping responsive generation"),null;let J=EA($);if(!await i0(J))return console.warn(`[stx-media] Source file not found: ${$}`),null;try{let Q=Z.responsiveWidths||Y.breakpoints||PA,G=Z.formats||Y.defaultFormats||["avif","webp","jpeg"],K=Y.outputDir||"dist/images",W=Y.baseUrl||"/images";await bA(K,{recursive:!0});let U=await l0(J),B=DA($,kA($)),_=Y.formatQuality||{jpeg:{quality:82},png:{quality:80},webp:{quality:82},avif:{quality:75}},z={src:$,byFormat:{},srcsets:{}};for(let j of G){z.byFormat[j]=[];let H=[];for(let L of Q){let F=`${B}-${L}w-${U}.${j}`,O=SA(K,F),V=`${W}/${F}`;try{let N=_[j]?.quality||80;if(await i0(O)){z.byFormat[j].push({path:O,url:V,width:L,height:0,format:j,size:0}),H.push(`${V} ${L}w`);continue}let A=await X.processImage({input:J,output:O,format:j,quality:N,resize:{width:L}});if(A)z.byFormat[j].push({path:O,url:V,width:L,height:A.height||Math.round(L*(A.height||1)/(A.width||1)),format:j,size:A.outputSize||0}),H.push(`${V} ${L}w`)}catch(N){console.warn(`[stx-media] Failed to generate ${j} at ${L}w: ${N}`)}}z.srcsets[j]=H.join(", ")}let q=Z.placeholder||Y.placeholderStrategy||"thumbhash";if(q!=="none")try{if(q==="thumbhash"){let j=await X.generateThumbHash(J);z.placeholder={dataURL:j.dataUrl,width:j.width||32,height:j.height||32,strategy:"thumbhash"}}else{let j=await X.generatePlaceholder(J,{strategy:q,width:20});z.placeholder={dataURL:j.dataURL,width:j.width,height:j.height,strategy:q}}}catch(j){console.warn(`[stx-media] Failed to generate placeholder: ${j}`)}return z.sizes=Z.sizes||yA(Q),z}catch(Q){return console.error(`[stx-media] Responsive generation failed: ${Q}`),null}}function yA($){let Z=[...$].sort((X,J)=>X-J),Y=[];for(let X=0;X<Z.length-1;X++){let J=Z[X];Y.push(`(max-width: ${J}px) ${J}px`)}return Y.push(`${Z[Z.length-1]}px`),Y.join(", ")}function z8($,Z="width"){if(!$||$.length===0)return"";if(Z==="dpr")return $.filter((Y)=>Y.dpr).map((Y)=>`${Y.url} ${Y.dpr}x`).join(", ");return $.map((Y)=>`${Y.url} ${Y.width}w`).join(", ")}async function ux($,Z,Y){let X=[];for(let J of Z){let Q=await l4(J.src,{responsiveWidths:J.widths},Y);if(Q){for(let[G,K]of Object.entries(Q.srcsets))if(K)X.push({media:J.media,srcset:K,type:xA(G)})}}return X}function xA($){switch($){case"avif":return"image/avif";case"webp":return"image/webp";case"jpeg":return"image/jpeg";case"png":return"image/png";case"gif":return"image/gif";default:return"image/jpeg"}}var PA;var BU=k(()=>{I$();PA=[320,480,640,768,1024,1280,1536,1920]});var _U={};t(_U,{setCachedImageResult:()=>B7,processImage:()=>GJ,optimizeImage:()=>KJ,getCachedImageResult:()=>U7,generateSrcset:()=>z8,generateResponsiveVariants:()=>l4,clearImageCache:()=>XJ,applyTransformations:()=>c4,ImageProcessorCache:()=>W7});var WJ=k(()=>{UU();BU();JJ()});async function vA(){try{return await Promise.resolve().then(() => (WJ(),_U))}catch($){if(!zU)console.warn("[stx-media] Image processor not available, some features disabled:",$),zU=!0;return null}}async function E$($,Z={}){let Y=Z,X=$;if(X.process&&!X.skipOptimization){if(Y.tsImagesConfig?.enabled&&!Y.isDev)return dA(X,Y)}if(Y.processedResult?.processed)return qJ($,Y.processedResult,Z);if(Y.responsiveVariants)return OU($,Y.responsiveVariants,Z);let{src:J,alt:Q,width:G,height:K,sizes:W,widths:U=c1,dpr:B,formats:_=Q$,quality:z=UJ,params:q={},placeholder:j="none",placeholderOptions:H={},lazy:L=!0,priority:F=!1,loading:O=F?"eager":j8,decoding:V=q8,fetchpriority:N,objectFit:A,objectPosition:w,crossorigin:R,referrerpolicy:M}=$,T=$.class,E=$.style,D=$.id,S=$.data||{},{isDev:C=!1,baseUrl:P=""}=Z;if(C&&!Z.optimize)return hA($);let b,x,s=D||`stx-img-${Math.random().toString(36).slice(2,8)}`;if(j!=="none"&&!F)try{b=await m4(J,{strategy:j,...H}),x=u4(s,b,H)}catch{}let u=B!==void 0&&G!==void 0,y;if(u)y=gA($,s,b,Z);else y=await fA($,s,b,Z);let h;if(F){let r=_.includes("webp")?"webp":_[0],K0=T$(J,U,{...q,q:z},r),Z0=typeof W==="object"?e5(W):W||"100vw";h=`<link rel="preload" as="image" imagesrcset="${K0}" imagesizes="${Z0}" />`}let m=[];if(!qU&&j!=="none")m.push(Z7),qU=!0;if(x)m.push(x);let n=L?HU(s):void 0;return{html:y,preloadLink:h,css:m.length>0?m.join(`
|
|
1190
|
+
`.trim();$7=new Map});import{createHash as $J}from"crypto";import{readFile as jA,stat as $U}from"fs/promises";async function l0($){try{let Z=await jA($);return $J("sha256").update(Z).digest("hex").slice(0,16)}catch{return""}}function ZU($){return $J("sha256").update($).digest("hex").slice(0,16)}function U8($){return $J("sha256").update($).digest("hex").slice(0,16)}function Y7($,Z){let Y=JSON.stringify(Z,Object.keys(Z).sort());return`${U8($)}-${U8(Y)}`}async function p4($){try{return(await $U($)).mtimeMs}catch{return 0}}async function i0($){try{return await $U($),!0}catch{return!1}}var I$=()=>{};import{mkdir as HA,readFile as XU,writeFile as OA,readdir as JU,rm as ZJ,stat as LA}from"fs/promises";import{join as X7,dirname as FA}from"path";async function VA($){try{await HA($,{recursive:!0})}catch{}}function QU($,Z,Y){return X7($,Y,`${Z}.json`)}async function YU($,Z,Y){if((Date.now()-$.createdAt)/86400000>Y)return!1;if(await p4(Z)!==$.srcMtime)return!1;return!0}async function Q7($,Z,Y,X=J7){if(!X.enabled)return null;let J=Y7($,Z),Q=l1.get(J);if(Q){if(await YU(Q,$,X.maxAge))return Q.lastAccessedAt=Date.now(),Q.data;l1.delete(J)}let G=QU(X.directory,J,Y);if(await i0(G))try{let K=await XU(G,"utf-8"),W=JSON.parse(K);if(await YU(W,$,X.maxAge))return W.lastAccessedAt=Date.now(),l1.set(J,W),W.data}catch{}return null}async function G7($,Z,Y,X,J=J7){if(!J.enabled)return;let Q=Y7($,Z),G=await l0($),K=await p4($),W={key:Q,src:$,srcHash:G,srcMtime:K,optionsHash:Y7("",Z),data:Y,createdAt:Date.now(),lastAccessedAt:Date.now()};l1.set(Q,W);let U=QU(J.directory,Q,X);try{await VA(FA(U)),await OA(U,JSON.stringify(W,null,2))}catch(B){console.warn(`[stx-media] Failed to write cache: ${B}`)}}async function Ex($,Z,Y=J7){for(let[X,J]of l1.entries())if(J.src===$)l1.delete(X)}async function K7($,Z=J7){if($==="all")l1.clear();else l1.clear();let Y=$==="all"?["image","video"]:[$];for(let X of Y){let J=X7(Z.directory,X);try{await ZJ(J,{recursive:!0,force:!0})}catch{}}}async function GU($=J7){let Z={memoryEntries:l1.size,diskEntries:{image:0,video:0},totalSizeMB:0};for(let Y of["image","video"]){let X=X7($.directory,Y);try{let J=await JU(X);Z.diskEntries[Y]=J.length;for(let Q of J){let G=X7(X,Q),K=await LA(G);Z.totalSizeMB+=K.size/1048576}}catch{}}return Z}async function KU($=J7){let Z=0,Y=$.maxAge*24*60*60*1000;for(let X of["image","video"]){let J=X7($.directory,X);try{let Q=await JU(J);for(let G of Q){let K=X7(J,G);try{let W=await XU(K,"utf-8"),U=JSON.parse(W);if(Date.now()-U.createdAt>Y)await ZJ(K),l1.delete(U.key),Z++}catch{await ZJ(K).catch(()=>{}),Z++}}}catch{}}return Z}var l1,J7;var B8=k(()=>{I$();l1=new Map,J7={enabled:!0,directory:".stx/media-cache",maxAge:30,maxSize:500}});class W7{config;constructor($={}){this.config={...NA,...$}}async get($,Z){return Q7($,Z,"image",this.config)}async set($,Z,Y){return G7($,Z,Y,"image",this.config)}async clear(){return K7("image",this.config)}updateConfig($){this.config={...this.config,...$}}}function YJ($){if(!_8)_8=new W7($);else if($)_8.updateConfig($);return _8}async function U7($,Z,Y){let X=Y?{directory:`${Y.outputDir}/../.cache`}:{};return YJ(X).get($,Z)}async function B7($,Z,Y,X){let J=X?{directory:`${X.outputDir}/../.cache`}:{};return YJ(J).set($,Z,Y)}async function XJ(){return YJ().clear()}var NA,_8=null;var JJ=k(()=>{B8();NA={enabled:!0,directory:".stx/media-cache",maxAge:30,maxSize:500,cacheVariants:!0,cachePlaceholders:!0}});import{resolve as AA,basename as wA,extname as RA,join as MA}from"path";import{mkdir as TA}from"fs/promises";async function QJ(){try{return await import("ts-images")}catch{return null}}function WU($){switch($){case"quality":return{jpeg:{quality:90,mozjpeg:!0,progressive:!0},png:{compressionLevel:6,palette:!1},webp:{quality:90,effort:6,smartSubsample:!0},avif:{quality:85,effort:6}};case"performance":return{jpeg:{quality:70,mozjpeg:!0,progressive:!0},png:{compressionLevel:9,palette:!0},webp:{quality:70,effort:4,smartSubsample:!0},avif:{quality:60,effort:2}};case"web":default:return{jpeg:{quality:82,mozjpeg:!0,progressive:!0},png:{compressionLevel:8,palette:!1},webp:{quality:82,effort:5,smartSubsample:!0},avif:{quality:75,effort:4}}}}function IA($,Z){let Y=Z?WU(Z):WU("web"),X=$.formatQuality||{};return{jpeg:{...Y.jpeg,...X.jpeg},png:{...Y.png,...X.png},webp:{...Y.webp,...X.webp},avif:{...Y.avif,...X.avif}}}async function GJ($,Z,Y){let X=await QJ();if(!X)return console.warn("[stx-media] ts-images not installed, skipping optimization"),{src:$,processed:!1};let J=await U7($,Z,Y);if(J)return J;try{let Q=AA($);if(!await i0(Q))return{src:$,processed:!1,errors:[`Source file not found: ${$}`]};let G=IA(Y,Z.preset),K=Y.outputDir||"dist/images",W=Y.baseUrl||"/images";await TA(K,{recursive:!0});let U=await l0(Q),B=wA($,RA($)),_=Z.outputFormat?[Z.outputFormat]:Y.defaultFormats||["avif","webp","jpeg"],z={src:$,processed:!0,variants:[],hash:U},q=null;if(Z.transformations&&Z.transformations.length>0)q=await c4(Q,Z.transformations,X);for(let j of _){let H=G[j]||{},L=`${B}-${U}.${j}`,F=MA(K,L);try{let O=await X.optimizeImage({input:q||Q,output:F,format:j,quality:H.quality,progressive:H.progressive});if(O){if(z.variants.push({path:F,url:`${W}/${L}`,width:O.width||0,height:O.height||0,format:j,size:O.outputSize||0}),!z.originalWidth&&O.width)z.originalWidth=O.width,z.originalHeight=O.height}}catch(O){z.errors=z.errors||[],z.errors.push(`Failed to optimize ${j}: ${O}`)}}if(Z.embedThumbhash||Z.placeholder==="thumbhash")try{let j=await X.generateThumbHash(Q);z.placeholder=j.dataUrl}catch(j){z.errors=z.errors||[],z.errors.push(`Failed to generate thumbhash: ${j}`)}if(Z.useDominantColor)try{let j=await X.generatePlaceholder(Q,{strategy:"dominant-color"});z.dominantColor=j.dominantColor}catch(j){z.errors=z.errors||[],z.errors.push(`Failed to extract dominant color: ${j}`)}return await B7($,Z,z,Y),z}catch(Q){return{src:$,processed:!1,errors:[`Processing failed: ${Q}`]}}}async function KJ($,Z,Y,X){let J=await QJ();if(!J)return{success:!1,error:"ts-images not installed"};try{return{success:!0,size:(await J.optimizeImage({input:$,output:X,format:Z,quality:Y}))?.outputSize}}catch(Q){return{success:!1,error:String(Q)}}}async function c4($,Z,Y){let X=Y||await QJ();if(!X)return console.warn("[stx-media] ts-images not installed, skipping transformations"),null;try{let J=await X.decode($);for(let Q of Z){let G=Q.options||{};switch(Q.type){case"resize":if(G.width||G.height)J=await X.resize(J,{width:G.width,height:G.height,fit:G.fit});break;case"blur":if(G.sigma!==void 0)J=await X.blur(J,G.sigma);break;case"sharpen":if(G.amount!==void 0)J=await X.sharpen(J,G.amount);break;case"grayscale":J=await X.grayscale(J);break;case"rotate":if(G.angle!==void 0)J=await X.rotate(J,G.angle);break;case"flip":J=await X.flip(J);break;case"flop":J=await X.flop(J);break;case"brightness":if(G.value!==void 0)J=await X.brightness(J,G.value);break;case"contrast":if(G.value!==void 0)J=await X.contrast(J,G.value);break;case"saturation":if(G.value!==void 0)J=await X.saturation(J,G.value);break}}return await X.encode(J,"png")}catch(J){return console.error(`[stx-media] Transformation failed: ${J}`),null}}var UU=k(()=>{I$();JJ()});import{resolve as EA,basename as DA,extname as kA,join as SA}from"path";import{mkdir as bA}from"fs/promises";async function CA(){try{return await import("ts-images")}catch{return null}}async function l4($,Z,Y){let X=await CA();if(!X)return console.warn("[stx-media] ts-images not installed, skipping responsive generation"),null;let J=EA($);if(!await i0(J))return console.warn(`[stx-media] Source file not found: ${$}`),null;try{let Q=Z.responsiveWidths||Y.breakpoints||PA,G=Z.formats||Y.defaultFormats||["avif","webp","jpeg"],K=Y.outputDir||"dist/images",W=Y.baseUrl||"/images";await bA(K,{recursive:!0});let U=await l0(J),B=DA($,kA($)),_=Y.formatQuality||{jpeg:{quality:82},png:{quality:80},webp:{quality:82},avif:{quality:75}},z={src:$,byFormat:{},srcsets:{}};for(let j of G){z.byFormat[j]=[];let H=[];for(let L of Q){let F=`${B}-${L}w-${U}.${j}`,O=SA(K,F),V=`${W}/${F}`;try{let N=_[j]?.quality||80;if(await i0(O)){z.byFormat[j].push({path:O,url:V,width:L,height:0,format:j,size:0}),H.push(`${V} ${L}w`);continue}let A=await X.processImage({input:J,output:O,format:j,quality:N,resize:{width:L}});if(A)z.byFormat[j].push({path:O,url:V,width:L,height:A.height||Math.round(L*(A.height||1)/(A.width||1)),format:j,size:A.outputSize||0}),H.push(`${V} ${L}w`)}catch(N){console.warn(`[stx-media] Failed to generate ${j} at ${L}w: ${N}`)}}z.srcsets[j]=H.join(", ")}let q=Z.placeholder||Y.placeholderStrategy||"thumbhash";if(q!=="none")try{if(q==="thumbhash"){let j=await X.generateThumbHash(J);z.placeholder={dataURL:j.dataUrl,width:j.width||32,height:j.height||32,strategy:"thumbhash"}}else{let j=await X.generatePlaceholder(J,{strategy:q,width:20});z.placeholder={dataURL:j.dataURL,width:j.width,height:j.height,strategy:q}}}catch(j){console.warn(`[stx-media] Failed to generate placeholder: ${j}`)}return z.sizes=Z.sizes||yA(Q),z}catch(Q){return console.error(`[stx-media] Responsive generation failed: ${Q}`),null}}function yA($){let Z=[...$].sort((X,J)=>X-J),Y=[];for(let X=0;X<Z.length-1;X++){let J=Z[X];Y.push(`(max-width: ${J}px) ${J}px`)}return Y.push(`${Z[Z.length-1]}px`),Y.join(", ")}function z8($,Z="width"){if(!$||$.length===0)return"";if(Z==="dpr")return $.filter((Y)=>Y.dpr).map((Y)=>`${Y.url} ${Y.dpr}x`).join(", ");return $.map((Y)=>`${Y.url} ${Y.width}w`).join(", ")}async function ux($,Z,Y){let X=[];for(let J of Z){let Q=await l4(J.src,{responsiveWidths:J.widths},Y);if(Q){for(let[G,K]of Object.entries(Q.srcsets))if(K)X.push({media:J.media,srcset:K,type:xA(G)})}}return X}function xA($){switch($){case"avif":return"image/avif";case"webp":return"image/webp";case"jpeg":return"image/jpeg";case"png":return"image/png";case"gif":return"image/gif";default:return"image/jpeg"}}var PA;var BU=k(()=>{I$();PA=[320,480,640,768,1024,1280,1536,1920]});var _U={};t(_U,{setCachedImageResult:()=>B7,processImage:()=>GJ,optimizeImage:()=>KJ,getCachedImageResult:()=>U7,generateSrcset:()=>z8,generateResponsiveVariants:()=>l4,clearImageCache:()=>XJ,applyTransformations:()=>c4,ImageProcessorCache:()=>W7});var WJ=k(()=>{UU();BU();JJ()});async function vA(){try{return await Promise.resolve().then(() => (WJ(),_U))}catch($){if(!zU)console.warn("[stx-media] Image processor not available, some features disabled:",$),zU=!0;return null}}async function E$($,Z={}){let Y=Z,X=$;if(X.process&&!X.skipOptimization){if(Y.tsImagesConfig?.enabled&&!Y.isDev)return dA(X,Y)}if(Y.processedResult?.processed)return qJ($,Y.processedResult,Z);if(Y.responsiveVariants)return OU($,Y.responsiveVariants,Z);let{src:J,alt:Q,width:G,height:K,sizes:W,widths:U=c1,dpr:B,formats:_=Q$,quality:z=UJ,params:q={},placeholder:j="none",placeholderOptions:H={},lazy:L=!0,priority:F=!1,loading:O=F?"eager":j8,decoding:V=q8,fetchpriority:N,objectFit:A,objectPosition:w,crossorigin:R,referrerpolicy:M}=$,T=$.class,E=$.style,D=$.id,S=$.data||{},{isDev:C=!1,baseUrl:P=""}=Z;if(C&&!Z.optimize)return hA($);let b,x,s=D||`stx-img-${Math.random().toString(36).slice(2,8)}`;if(j!=="none"&&!F)try{b=await m4(J,{strategy:j,...H}),x=u4(s,b,H)}catch{}let u=B!==void 0&&G!==void 0,y;if(u)y=gA($,s,b,Z);else y=await fA($,s,b,Z);let h;if(F){let r=_.includes("webp")?"webp":_[0],K0=T$(J,U,{...q,q:z},r),Z0=typeof W==="object"?e5(W):W||"100vw";h=`<link rel="preload" as="image" imagesrcset="${K0}" imagesizes="${Z0}" />`}let p=[];if(!qU&&j!=="none")p.push(Z7),qU=!0;if(x)p.push(x);let n=L?HU(s):void 0;return{html:y,preloadLink:h,css:p.length>0?p.join(`
|
|
1191
1191
|
`):void 0,script:n}}async function fA($,Z,Y,X){let{src:J,alt:Q,width:G,height:K,sizes:W,widths:U=c1,formats:B=Q$,quality:_=UJ,params:z={},lazy:q=!0,priority:j=!1,loading:H=j?"eager":j8,decoding:L=q8,fetchpriority:F,objectFit:O,objectPosition:V,crossorigin:N,referrerpolicy:A}=$,w=$.class,R=$.style,M=$.data||{},T=typeof W==="object"?e5(W):W||"100vw",E=[];for(let C of B){let P=T$(J,U,{...z,q:_},C),b=h4(C);if(q&&!j)E.push(` <source type="${b}" data-srcset="${P}" data-sizes="${T}" />`);else E.push(` <source type="${b}" srcset="${P}" sizes="${T}" />`)}let D=BJ({src:C1(J,{...z,q:_}),alt:Q,width:G,height:K,loading:j?void 0:H,decoding:L,fetchpriority:j?"high":F,objectFit:O,objectPosition:V,crossorigin:N,referrerpolicy:A,className:jU(w,Y),style:_J(R,O,V,Y),lazy:q&&!j,data:M}),S;if(Y){let C=`background-image: url('${Y.dataURL}'); background-size: cover; background-position: center;`;S=`<div id="${Z}" class="stx-img-placeholder" style="${C}">
|
|
1192
1192
|
<picture>
|
|
1193
1193
|
${E.join(`
|
|
@@ -4242,12 +4242,12 @@ document.addEventListener("focusout",function(e){
|
|
|
4242
4242
|
</script>`}),J}async function bh($,Z,Y,X,J){let Q=$;if(!Z.__importedComponents)Z.__importedComponents=new Map;let G=Z.__importedComponents,K=/@import\s*\(\s*([^)]+)\s*\)/g,W;while((W=K.exec(Q))!==null){let[U,B]=W,_=B.split(",").map((z)=>z.trim().replace(/^['"]|['"]$/g,"")).filter((z)=>z.length>0);for(let z of _){let q=z.split("/"),H=q[q.length-1].replace(/\.stx$/,""),L=H.includes("-")?H.split("-").map((V)=>V.charAt(0).toUpperCase()+V.slice(1)).join(""):H.charAt(0).toUpperCase()+H.slice(1),F=null,O=[g7.resolve(g7.dirname(Y),`${z}.stx`),g7.resolve(g7.dirname(Y),z),g7.resolve(X.componentsDir||"components",`${z}.stx`),g7.resolve(X.componentsDir||"components",z),z.endsWith(".stx")?z:`${z}.stx`];for(let V of O)try{if(await Bun.file(V).exists()){F=V;break}}catch{}if(F){G.set(L,F),G.set(H,F),G.set(H.toLowerCase(),F);let V=L.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();if(G.set(V,F),J.add(F),X.debug)console.log(`Imported component: ${L} -> ${F}`)}else if(X.debug)console.warn(`Could not resolve imported component: ${z}`)}Q=Q.replace(U,""),K.lastIndex=0}return Q}async function Ch($,Z,Y,X,J,Q){let G=$;if(!Z.__processedComponents)Z.__processedComponents=new Set;let K=Z.__processedComponents,W=/@component\s*\(/g,U;while((U=W.exec(G))!==null){let B=U.index,_=B+U[0].length-1,z=1,q=_+1;while(q<G.length&&z>0){if(G[q]==="(")z++;else if(G[q]===")"){if(z--,z===0)break}q++}if(z!==0)break;let j=G.substring(_+1,q),H=q+1,L=j.match(/^\s*['"]([^'"]+)['"]/);if(!L){W.lastIndex=0;continue}let F=L[1],O,V=j.slice(L[0].length),N=V.match(/^\s*,\s*/);if(N)O=V.slice(N[0].length).trim();let A={};if(O)try{A=b0(O,Z)}catch(S){let C=S instanceof Error?S.message:String(S);G=G.replace(G.substring(B,H),`[Error parsing component props: ${C}]`);continue}let w="",R=H,T=G.substring(H).match(/^([\s\S]*?)@endcomponent/);if(T)w=T[1].trim(),R=H+T[0].length;let E=G.substring(B,R),D=await D1(F,A,w,X,Z,Y,J,K,Q);G=G.substring(0,B)+D+G.substring(R),W.lastIndex=0}return G}async function Ph($,Z,Y,X,J,Q){let G=$;if(!Z.__processedComponents)Z.__processedComponents=new Set;let K=Z.__processedComponents,W=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","path","circle","rect","line","polygon","polyline","ellipse","text","tspan","textPath","g","defs","use","symbol","image","clipPath","mask","pattern","marker","linearGradient","radialGradient","stop","filter","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDropShadow","feFlood","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","feSpecularLighting","feTile","feTurbulence","foreignObject","animate","animateMotion","animateTransform","set","mpath","desc","metadata","switch","view"]),U=a3(G);return G=U.output,G=await q(G,/[a-z][a-z0-9]*-[a-z0-9-]*/,!1),G=await q(G,/[A-Z][a-zA-Z0-9]*/,!0),G=await q(G,/[a-z][a-z0-9]*/,!1,W),G=t3(G,U.scripts),G;async function q(j,H,L,F){let O=j,V=j9(O,H,F);for(let N=V.length-1;N>=0;N--){let A=V[N],w=L?q9(A.tagName):A.tagName,R=mM(A.attributes),M={};for(let[E,D]of Object.entries(R)){if(E.startsWith("@"))continue;if(E.startsWith("__stx_")){let S=E.slice(6);M[S]=H9(D,J);continue}if(E.startsWith(":")){let S=E.slice(1),C=D==="true"?S:D;try{if(!_0(C)){if(J.debug)console.error(`Unsafe expression in :${S} binding: ${C}`);M[S]=D}else{let P=z0(C,Object.keys(Z));M[S]=P(...Object.values(Z))}}catch(P){if(J.debug)console.error(`Error evaluating :${S} binding:`,P);M[S]=D}continue}if(typeof D==="string"&&D.includes("{{")&&D.includes("}}")){let S=D.match(/^\{\{\s*([\s\S]+?)\s*\}\}$/);if(S)try{let C=S[1];if(!_0(C)){if(J.debug)console.error(`Unsafe expression in ${E}: ${C}`);M[E]=D}else{let P=z0(C,Object.keys(Z));M[E]=P(...Object.values(Z))}}catch(C){if(J.debug)console.error(`Error evaluating expression for ${E}:`,C);M[E]=D}else{let C=D,P=/\{\{\s*([\s\S]+?)\s*\}\}/g,b;while((b=P.exec(D))!==null)try{let x=b[1];if(!_0(x)){if(J.debug)console.error(`Unsafe expression in ${E}: ${x}`);continue}let u=z0(x,Object.keys(Z))(...Object.values(Z));C=C.replace(b[0],String(u??""))}catch(x){if(J.debug)console.error(`Error evaluating expression in ${E}:`,x)}M[E]=C}}else M[E]=D}let T=await D1(w,M,A.content,X,Z,Y,J,K,Q);O=O.substring(0,A.startIndex)+T+O.substring(A.endIndex)}return O}}var Xz=k(()=>{d0();N0();e3()});var Uz={};t(Uz,{processESImports:()=>Wz,processComponents:()=>HZ});import jZ from"fs";import F1 from"path";function cM($,Z,Y){let X={static:{},serverDynamic:{},clientReactive:{},events:{}},J=new Set(["x-cloak","x-show","x-if","x-for","x-data","x-init","x-transition","x-ref","x-effect","x-model","x-text","x-html","x-class","x-style","x-on","x-bind"]),Q=(G)=>{if(!G.includes("-")||G.startsWith("@")||G.startsWith(":")||G.startsWith("x-")||G.startsWith("__"))return G;return G.replace(/-([a-z0-9])/g,(K,W)=>W.toUpperCase())};for(let[G,K]of Object.entries($)){let W=G.startsWith("x-")&&!J.has(G)&&!G.startsWith("x-bind:")&&!G.startsWith("x-on:")?`:${G.slice(2)}`:G;if(W.startsWith("@")){X.events[W]=K;continue}if(W.startsWith("__stx_")){let U=Q(W.slice(6));X.serverDynamic[U]=H9(K,Y);continue}if(W.startsWith(":")){let U=Q(W.slice(1)),B=K==="true"?U:K;try{if(!_0(B)){if(Y.debug)console.error(`Unsafe expression in :${U} binding: ${B}`);X.clientReactive[U]=B;continue}let _=Object.keys(Z),q=z0(B,_)(...Object.values(Z));if(q===void 0){let j=B.match(/\b[a-zA-Z_$][a-zA-Z0-9_$]*\b/g)||[],H=new Set(["true","false","null","undefined","typeof","instanceof","in","of","new","this","return","void","delete","throw","if","else"]);if(j.some((F)=>!H.has(F)&&!_.includes(F))){X.clientReactive[U]=B;continue}}X.serverDynamic[U]=q}catch{X.clientReactive[U]=B}continue}if(typeof K==="string"&&K.includes("{{")&&K.includes("}}")){let U=K.match(/^\{\{\s*([\s\S]+?)\s*\}\}$/);if(U)try{let B=U[1];if(_0(B)){let z=z0(B,Object.keys(Z))(...Object.values(Z));X.static[W]=z!=null?String(z):""}else{if(Y.debug)console.error(`Unsafe expression in ${W}: ${B}`);X.static[W]=K}}catch(B){if(Y.debug)console.error(`Error evaluating expression for ${W}:`,B);X.static[W]=K}else{let B=K,_=/\{\{\s*([\s\S]+?)\s*\}\}/g,z;while((z=_.exec(K))!==null)try{let q=z[1];if(!_0(q)){if(Y.debug)console.error(`Unsafe expression in ${W}: ${q}`);continue}let H=z0(q,Object.keys(Z))(...Object.values(Z));B=B.replace(z[0],String(H??""))}catch(q){if(Y.debug)console.error(`Error evaluating expression in ${W}:`,q)}X.static[W]=B}continue}X.static[W]=K}return X}function lM($){let Z={},Y=0,X=$.length;while(Y<X){while(Y<X&&/\s/.test($[Y]))Y++;if(Y>=X)break;let J="";while(Y<X&&!/[\s=]/.test($[Y]))J+=$[Y],Y++;if(!J)break;while(Y<X&&/\s/.test($[Y]))Y++;if(Y<X&&$[Y]==="="){Y++;while(Y<X&&/\s/.test($[Y]))Y++;let Q="";if(Y<X&&($[Y]==='"'||$[Y]==="'")){let G=$[Y];Y++;while(Y<X){let K=$[Y];if(K==="\\"&&Y+1<X){Y++,Q+=$[Y],Y++;continue}if(K===G){Y++;break}Q+=K,Y++}}else while(Y<X&&!/\s/.test($[Y]))Q+=$[Y],Y++;Z[J]=Q}else Z[J]="true"}return Z}function Qz($){return $.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function iM($){let Z=new Set,Y=/<([A-Z][A-Za-z0-9]*|stx-[a-z0-9-]+)\b[^>]*>/g,X;while((X=Y.exec($))!==null){let J=X[1];if(B1.isBuiltin(J))Z.add(J)}return[...Z].sort()}function nM($){let Z=Gz.get($);if(Z)return Z;let Y=new Map,X=[F1.join($,"src"),F1.join($,"dist"),$];function J(Q,G){if(G>6)return;let K;try{K=jZ.readdirSync(Q,{withFileTypes:!0})}catch{return}for(let W of K){let U=F1.join(Q,W.name);if(W.isDirectory()){if(W.name==="node_modules"||W.name.startsWith("."))continue;J(U,G+1)}else if(W.isFile()&&W.name.endsWith(".stx")){let B=W.name.slice(0,-4);if(!Y.has(B))Y.set(B,U);let _=B.toLowerCase();if(!Y.has(_))Y.set(_,U);let z=B.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();if(!Y.has(z))Y.set(z,U)}}}for(let Q of X)if(J(Q,0),Y.size>0)break;return Gz.set($,Y),Y}function sM($,Z){if($.startsWith(".")||$.startsWith("/"))return null;let Y=Z;while(!0){let X=F1.join(Y,"node_modules",$);try{if(jZ.statSync(X).isDirectory())return X}catch{}let J=F1.dirname(Y);if(J===Y)return null;Y=J}}async function Wz($,Z,Y,X,J){if(!$.includes("import"))return $;if(!Z.__importedComponents)Z.__importedComponents=new Map;let Q=Z.__importedComponents,G=F1.dirname(Y),K=$,W=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi;return K=K.replace(W,(U,B,_)=>{let z=/import\s+(?:(\{[^}]*\})|([A-Za-z_$][\w$]*))\s+from\s+['"]([^'"]+)['"]\s*;?\s*\n?/g,q=_,j,H=[];while((j=z.exec(_))!==null){let[L,F,O,V]=j,N=null,A=null;if(V.startsWith(".")||V.startsWith("/")){let M=F1.resolve(G,V);if(M.endsWith(".stx"))A=M;else{let T=`${M}.stx`;try{if(jZ.statSync(T).isFile())A=T}catch{try{if(jZ.statSync(M).isDirectory())N=M}catch{}}}}else N=sM(V,G);if(!N&&!A)continue;let w=!1,R=(M,T)=>{Q.set(M,T),Q.set(M.toLowerCase(),T);let E=M.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();Q.set(E,T),J.add(T)};if(O&&A)R(O,A),w=!0;else if(F){let M=F.slice(1,-1).split(",").map((E)=>E.trim()).filter(Boolean).map((E)=>{let D=E.match(/^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/);if(D)return{source:D[1],local:D[2]};return{source:E,local:E}}),T=N?nM(N):null;for(let{source:E,local:D}of M){let S=null;if(A)S=A;else if(T)S=T.get(E)??T.get(E.toLowerCase())??T.get(E.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase())??null;if(S)R(D,S),w=!0}}if(w)H.push({start:j.index,end:j.index+L.length})}if(H.length===0)return U;for(let L=H.length-1;L>=0;L--)q=q.slice(0,H[L].start)+q.slice(H[L].end);return`<script${B}>${q}</script>`}),K}async function rM($,Z,Y,X,J){let Q=$;if(!Z.__importedComponents)Z.__importedComponents=new Map;let G=Z.__importedComponents,K=/@import\s*\(\s*([^)]+)\s*\)/g,W;while((W=K.exec(Q))!==null){let[U,B]=W,_=B.split(",").map((z)=>z.trim().replace(/^['"]|['"]$/g,"")).filter((z)=>z.length>0);for(let z of _){let q=z.split("/"),H=q[q.length-1].replace(/\.stx$/,""),L=H.includes("-")?H.split("-").map((V)=>V.charAt(0).toUpperCase()+V.slice(1)).join(""):H.charAt(0).toUpperCase()+H.slice(1),F=null,O=[F1.resolve(F1.dirname(Y),`${z}.stx`),F1.resolve(F1.dirname(Y),z),F1.resolve(X.componentsDir||"components",`${z}.stx`),F1.resolve(X.componentsDir||"components",z),z.endsWith(".stx")?z:`${z}.stx`];for(let V of O)try{if(await Bun.file(V).exists()){F=V;break}}catch{}if(F){G.set(L,F),G.set(H,F),G.set(H.toLowerCase(),F);let V=L.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();if(G.set(V,F),J.add(F),X.debug)console.log(`Imported component: ${L} -> ${F}`)}else if(X.debug)console.warn(`Could not resolve imported component: ${z}`)}Q=Q.replace(U,""),K.lastIndex=0}return Q}async function oM($,Z,Y,X,J){let Q=$,G=X.componentsDir||"components";if(!Z.__processedComponents)Z.__processedComponents=new Set;let K=Z.__processedComponents,W=/@component\s*\(/g,U;while((U=W.exec(Q))!==null){let B=U.index,_=B+U[0].length-1,z=1,q=_+1;while(q<Q.length&&z>0){if(Q[q]==="(")z++;else if(Q[q]===")"){if(z--,z===0)break}q++}if(z!==0)break;let j=Q.substring(_+1,q),H=q+1,L=j.match(/^\s*['"]([^'"]+)['"]/);if(!L){W.lastIndex=0;continue}let F=L[1],O,V=j.slice(L[0].length),N=V.match(/^\s*,\s*/);if(N)O=V.slice(N[0].length).trim();let A={};if(O)try{A=b0(O,Z)}catch(D){let S=D instanceof Error?D.message:String(D);Q=Q.replace(Q.substring(B,H),`[Error parsing component props: ${S}]`);continue}let w="",R=H,T=Q.substring(H).match(/^([\s\S]*?)@endcomponent/);if(T)w=T[1].trim(),R=H+T[0].length;let E=await D1(F,A,w,G,Z,Y,X,K,J);Q=Q.substring(0,B)+E+Q.substring(R),W.lastIndex=0}return Q}async function aM($,Z,Y,X,J){if(!$)return $;let Q=$,G=X.componentsDir||"components";if(!Z.__processedComponents)Z.__processedComponents=new Set;let K=Z.__processedComponents,W=a3(Q);return Q=W.output,Q=await z(Q,/[a-z][a-z0-9]*-[a-z0-9-]*/,!1),Q=await z(Q,/[A-Z][a-zA-Z0-9]*/,!0),Q=await z(Q,/[a-z][a-z0-9]*/,!1,pM),Q=t3(Q,W.scripts),Q;async function z(q,j,H,L){if(!q)return q;let F=q,O=j9(F,j,L);for(let V=O.length-1;V>=0;V--){let N=O[V],A=H?q9(N.tagName):N.tagName,w=lM(N.attributes),R=cM(w,Z,X),M=B1.getBuiltin(N.tagName),T=M?await L9(A,G,Z,Y,X):!1;if(M&&!T){let C={context:Z,filePath:Y,options:X,dependencies:J},P=M.render(R,N.content,C);if(Object.keys(R.clientReactive).length>0)P=Kz(P,R.clientReactive);if(Object.keys(R.events).length>0){let b=Object.entries(R.events).map(([x,s])=>`${x}="${Qz(s)}"`).join(" ");P=P.replace(/^(\s*<[a-zA-Z][a-zA-Z0-9-]*)/,`$1 ${b}`)}F=F.substring(0,N.startIndex)+P+F.substring(N.endIndex);continue}let E={};for(let[C,P]of Object.entries(R.static))E[C]=P;for(let[C,P]of Object.entries(R.serverDynamic))E[C]=P;let S=await D1(A,E,N.content,G,Z,Y,X,K,J);if(Object.keys(R.clientReactive).length>0)S=Kz(S,R.clientReactive);if(Object.keys(R.events).length>0){let C=S.match(/^(\s*<)([a-zA-Z][a-zA-Z0-9-]*)(\s|>|\/)/s);if(C){let P=Object.entries(R.events).map(([x,s])=>`${x}="${Qz(s)}"`).join(" "),b=C[1].length+C[2].length;S=S.substring(0,b)+" "+P+S.substring(b)}}F=F.substring(0,N.startIndex)+S+F.substring(N.endIndex)}return F}}function Kz($,Z){let Y=$.match(/^(\s*<)([a-zA-Z][a-zA-Z0-9-]*)(\s|>|\/)/s);if(!Y)return $;let X=Object.entries(Z).map(([Q,G])=>`:${Q}="${G.replace(/"/g,""")}"`).join(" "),J=Y[1].length+Y[2].length;return $.substring(0,J)+" "+X+$.substring(J)}async function HZ($,Z,Y,X,J){if(!Jz)Yz(),Jz=!0;let Q=await Wz($,Z,Y,X,J);Q=await rM(Q,Z,Y,X,J),Q=await oM(Q,Z,Y,X,J);for(let G=0;G<3;G++){let K=Q;if(Q=await aM(Q,Z,Y,X,J),Q===K)break}if(X.debug){let G=iM(Q);if(G.length>0)console.warn(`[stx] ${Y}: unresolved component tag(s) after render passes: ${G.join(", ")}. Check nested component output for malformed root tags or recursive component markup.`)}return Q}var Jz=!1,pM,Gz;var O9=k(()=>{p2();z9();Xz();N0();d0();pM=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","path","circle","rect","line","polygon","polyline","ellipse","text","tspan","textPath","g","defs","use","symbol","image","clipPath","mask","pattern","marker","linearGradient","radialGradient","stop","filter","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDropShadow","feFlood","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","feSpecularLighting","feTile","feTurbulence","foreignObject","animate","animateMotion","animateTransform","set","mpath","desc","metadata","switch","view"]);Gz=new Map});var LZ={};t(LZ,{stripTypeScript:()=>jz,hasVariables:()=>N9,extractVariables:()=>D0,extractScriptFromTemplate:()=>V9,convertToCommonJS:()=>OZ});import h7 from"path";import j6 from"process";function tM($){let Z=[],Y=0,X=$.split(`
|
|
4243
4243
|
`);for(let J of X){let Q=Y,G=null,K=!1;for(let W=0;W<J.length;W++){let U=J[W];if(K){K=!1;continue}if(U==="\\"){K=!0;continue}if(G){if(U===G)G=null;continue}if(U==="'"||U==='"'||U==="`"){G=U;continue}if(U==="/"&&W+1<J.length&&J[W+1]==="/")break;if(U==="{")Y++;else if(U==="}")Y--}if(Q===0){let W=J.match(/(?:const|let|var)\s+(\w+)\s*=/);if(W)Z.push(W[1]);else if(/^\s*(?:const|let|var)\s+\w+\s*;?\s*$/.test(J)){let U=J.match(/(?:const|let|var)\s+(\w+)/);if(U)Z.push(U[1])}else{let U=J.match(/(?:const|let|var)\s+(\{[^}]+\}|\[[^\]]+\])\s*=/);if(U){let _=U[1].slice(1,-1).split(",").map((z)=>{let q=z.split(":");return(q.length>1?q[1]:q[0]).trim()}).filter((z)=>/^\w+$/.test(z));Z.push(..._)}}}}return[...new Set(Z)]}function jz($){let Z=$;Z=Z.replace(/^\s*import\s+.*?from\s+['"][^'"]+['"]\s*;?\s*$/gm,""),Z=Z.replace(/^\s*import\s+['"][^'"]+['"]\s*;?\s*$/gm,""),Z=Z.replace(/^\s*interface\s+\w+\s*\{[\s\S]*?\n\}\s*$/gm,""),Z=Z.replace(/^\s*type\s+\w+\s*=[\s\S]*?(?=\n(?:const|let|var|function|export|interface|type|$))/gm,""),Z=Z.replace(/^(\s*(?:export\s+)?(?:const|let|var)\s+)(\w+|\{[^}]+\}|\[[^\]]+\])\s*:\s*[^=]+(\s*=)/gm,"$1$2$3");function Y(X){if(!X.includes(":"))return X;let J=[],Q="",G=0,K=0,W=null;for(let U=0;U<X.length;U++){let B=X[U];if(W){if(Q+=B,B===W)W=null;continue}if(B==='"'||B==="'"||B==="`"){W=B,Q+=B;continue}if(B==="<")G++;else if(B===">"&&G>0)G--;else if(B==="(")K++;else if(B===")")K--;if(B===","&&G===0&&K===0){J.push(Q),Q="";continue}Q+=B}if(Q)J.push(Q);return J.map((U)=>{let B=U.trim(),_=B.startsWith("..."),z=_?B.slice(3):B,q=-1,j=0;for(let A=0;A<z.length;A++)if(z[A]==="<")j++;else if(z[A]===">")j--;else if(z[A]===":"&&j===0){q=A;break}if(q===-1)return U;let L=z.substring(0,q).trim().replace(/\?$/,""),F=z.substring(q+1),O=-1,V=0;for(let A=0;A<F.length;A++)if(F[A]==="<")V++;else if(F[A]===">")V--;else if(F[A]==="="&&V===0){O=A;break}let N=_?"...":"";if(O!==-1)return`${N}${L} = ${F.substring(O+1).trim()}`;return`${N}${L}`}).join(", ")}Z=Z.replace(/\b(function\s+\w*\s*)\(([^)]*)\)/g,(X,J,Q)=>{if(!Q.includes(":"))return X;return`${J}(${Y(Q)})`});{let X=/\b(function\s+\w*\s*)\(/g,J,Q=[];while((J=X.exec(Z))!==null){let G=J.index+J[0].length-1,K=1,W=G+1,U=0,B=null;while(W<Z.length&&K>0){let q=Z[W];if(B){if(q===B)B=null;W++;continue}if(q==='"'||q==="'"||q==="`"){B=q,W++;continue}if(q==="<")U++;else if(q===">"&&U>0)U--;else if(U===0){if(q==="(")K++;else if(q===")")K--}if(K>0)W++}if(K!==0)continue;let _=Z.substring(G+1,W);if(!_.includes(":"))continue;let z=Y(_);Q.push({start:G+1,end:W,replacement:z})}for(let G=Q.length-1;G>=0;G--){let{start:K,end:W,replacement:U}=Q[G];Z=Z.substring(0,K)+U+Z.substring(W)}}return Z=Z.replace(/\(([^)]*)\)\s*(?::\s*[^=]+)?\s*=>/g,(X,J)=>{if(!J.includes(":"))return X;if(J.includes("{")||J.includes("}"))return X;return`(${J.split(",").map((G)=>{let[K,...W]=G.split("="),U=K.split(":")[0].trim();if(W.length>0)return`${U} = ${W.join("=").trim()}`;return U}).join(", ")}) =>`}),Z=Z.replace(/(\))\s*:\s*([A-Z]\w*|void|string|number|boolean|any|unknown|never|null|undefined)(?:<[^>]+>)?(?:\s*\|\s*(?:[A-Z]\w*|void|string|number|boolean|any|unknown|never|null|undefined))*\s*(\{)/g,"$1$3"),Z=Z.replace(/(\b(?:function|class|interface|type|extends|implements)\s+\w+)\s*<[^<>()]*>/g,"$1"),Z=Z.replace(/(\b(?:defineProps|withDefaults|defineEmits|defineSlots|Array|Promise|Map|Set|Record|Partial|Required|Readonly|Pick|Omit|Exclude|Extract))\s*<[^<>()]*>/g,"$1"),Z=Z.replace(/(\w+)\s*<[A-Z][^<>()]*>\s*(?=\()/g,"$1"),Z=Z.replace(/\s+as\s+(?:const|[A-Za-z]\w*(?:\[\])?(?:\s*\|\s*\w+(?:\[\])?)*)/g,""),Z=Z.replace(/\s+satisfies\s+\w+(?:<[^>]*>)?/g,""),Z=Z.replace(/(\w|\)|\])\s*!(?!=)/g,"$1"),Z=Z.replace(/^\s*(?:export\s+)?(?:const\s+)?enum\s+\w+\s*\{[^}]*\}\s*$/gm,""),Z=Z.replace(/(?<=[\s=,(])<[A-Z]\w*(?:\[\])?>/g,""),Z=Z.replace(/\n\s*\n\s*\n/g,`
|
|
4244
4244
|
|
|
4245
|
-
`),Z}async function D0($,Z,Y,X={}){if(!$.trim())return;let J;try{let v=new Bun.Transpiler({loader:"ts",target:"browser",define:T1()}),d=$.replace(/^\s*import\s+\w+\s+from\s+['"][^'"]*\.stx['"]\s*;?\s*$/gm,"");d=d.replace(/^\s*import\s+['"][^'"]*\.stx['"]\s*;?\s*$/gm,""),J=v.transformSync(d)}catch{J=jz($)}let Q={exports:{}},G=Q.exports,K=j6.cwd(),W={},U=[...J.matchAll(/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g)||[]].map((v)=>v[1]).filter((v)=>!v.startsWith("node:")&&!v.startsWith(".")&&!["fs","path","os","child_process","crypto","http","https","url","util","stream","events","buffer","net","querystring","zlib","tls"].includes(v));for(let v of U)try{let d=h7.resolve(K,"node_modules",v),
|
|
4246
|
-
`),w0=Z.params??{},W0=[],o0=[];for(let G0=0;G0<
|
|
4245
|
+
`),Z}async function D0($,Z,Y,X={}){if(!$.trim())return;let J;try{let v=new Bun.Transpiler({loader:"ts",target:"browser",define:T1()}),d=$.replace(/^\s*import\s+\w+\s+from\s+['"][^'"]*\.stx['"]\s*;?\s*$/gm,"");d=d.replace(/^\s*import\s+['"][^'"]*\.stx['"]\s*;?\s*$/gm,""),J=v.transformSync(d)}catch{J=jz($)}let Q={exports:{}},G=Q.exports,K=j6.cwd(),W={},U=[...J.matchAll(/require\s*\(\s*['"]([^'"]+)['"]\s*\)/g)||[]].map((v)=>v[1]).filter((v)=>!v.startsWith("node:")&&!v.startsWith(".")&&!["fs","path","os","child_process","crypto","http","https","url","util","stream","events","buffer","net","querystring","zlib","tls"].includes(v));for(let v of U)try{let d=h7.resolve(K,"node_modules",v),m=h7.join(d,"package.json"),g=JSON.parse(j0("fs").readFileSync(m,"utf8")),c=g.main||"index.js";if(g.exports){let a=typeof g.exports==="string"?g.exports:g.exports["."];if(typeof a==="string")c=a;else if(a?.bun)c=a.bun;else if(a?.import)c=a.import;else if(a?.default)c=a.default}W[v]=await import(h7.resolve(d,c))}catch{}let B=(v)=>{if(W[v])return W[v];return j0(v)},_=Z.props||{},z=Object.assign((v)=>{if(!v)return _;let d={};for(let[m,g]of Object.entries(v)){let c=_[m];if(c!==void 0)d[m]=c;else if(typeof g==="function")d[m]=g();else d[m]=g}return d},_),q=(v)=>{if(!v)return _;let d={..._};for(let[m,g]of Object.entries(v)){let c=g&&typeof g==="object"&&!Array.isArray(g)?g:{type:g};if(d[m]===void 0&&c.default!==void 0)d[m]=typeof c.default==="function"?c.default():c.default}return d},j=()=>Z.slots||{},H=(v,d)=>{let m={...v};for(let[g,c]of Object.entries(d))if(m[g]===void 0)if(typeof c==="function")m[g]=c();else m[g]=c;return m},L=(v)=>{let d=()=>v;return d.set=(m)=>{},d.update=(m)=>{},d},F=(v)=>{let d,m=!1;return()=>{if(!m)try{d=v(),m=!0}catch{d=void 0}return d}},O=(v)=>{},V=(v)=>v(),N=(v)=>{},A=(v)=>{},w=(v)=>{},R=()=>{let v=Z.__stxServeContext,d=Z.__stxServeSearch??v?.search??"",m=v?.path??"";return{params:Z.params??{},query:Object.fromEntries(new URLSearchParams(d)),path:m,name:"",fullPath:m+d,hash:"",matched:[]}},M=()=>({push:(v)=>{},replace:(v)=>{},back:()=>{},forward:()=>{},go:(v)=>{}}),T=(v)=>{v$(v);let d=Z.__stx_runtime_head||{},m=v||{};Z.__stx_runtime_head={...d,...m.title&&{title:m.title},meta:[...d.meta||[],...m.meta||[]],link:[...d.link||[],...m.link||[]],script:[...d.script||[],...m.script||[]],htmlAttrs:{...d.htmlAttrs||{},...m.htmlAttrs||{}},bodyAttrs:{...d.bodyAttrs||{},...m.bodyAttrs||{}}}},E=(v)=>{G6(v);let d=C7();Z.__stx_runtime_head={...Z.__stx_runtime_head||{},...d.title&&{title:d.title},meta:d.meta?[...d.meta]:[]}},D=(v)=>({value:v}),S=(v)=>v,C=(v)=>({value:typeof v==="function"?v():v}),P=(v,d)=>{},b=(v)=>{},x=(v)=>{},s=(v)=>v?v():Promise.resolve(),u=(v)=>(d,...m)=>{},y=(v)=>{},h=(v,d)=>{},p=(v,d)=>d,n=()=>({value:"light"}),r=()=>({value:!1}),K0={siteId:void 0,API_ENDPOINT:"",ANALYTICS_SITE_ID:void 0,location:{href:"",pathname:"",search:"",hash:"",origin:"",host:"",hostname:"",protocol:"https:",assign:()=>{},replace:()=>{},reload:()=>{}},localStorage:{getItem:()=>null,setItem:()=>{},removeItem:()=>{},clear:()=>{}},sessionStorage:{getItem:()=>null,setItem:()=>{},removeItem:()=>{},clear:()=>{}},fetch:globalThis.fetch,addEventListener:()=>{},removeEventListener:()=>{},setTimeout:()=>0,clearTimeout:()=>{},setInterval:()=>0,clearInterval:()=>{},requestAnimationFrame:()=>0,cancelAnimationFrame:()=>{},alert:()=>{},confirm:()=>!1,prompt:()=>null,getComputedStyle:()=>({}),matchMedia:()=>({matches:!1,addListener:()=>{},removeListener:()=>{}}),getDateRangeParams:()=>"",stx:{}},Z0=new Proxy(K0,{get(v,d){if(d in v)return v[d];return},set(v,d,m){return v[d]=m,!0}}),F0={getElementById:()=>null,querySelector:()=>null,querySelectorAll:()=>[],createElement:()=>({}),createTextNode:()=>({}),body:{},head:{},documentElement:{},addEventListener:()=>{},removeEventListener:()=>{}},R0=console;try{let v=OZ(J,Y),d=new Set(Object.keys(_)),m=Object.keys(Z).filter((G0)=>!d.has(G0)&&G0!=="props"),g=m.map((G0)=>Z[G0]),c=new Set(["break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","function","if","import","in","instanceof","let","new","return","super","switch","this","throw","try","typeof","var","void","while","with","yield","enum","await","async","module","exports","require","params","window","document","console","state","derived","effect"]),a=[],l=[];for(let[G0,k0]of Object.entries(_)){if(!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(G0))continue;if(c.has(G0))continue;if(new RegExp(`(?:^|[\\s;{])(?:const|let|var|function)\\s+${G0}\\b`).test(v))continue;a.push(G0),l.push(k0)}let M0=tM(v).map((G0)=>`module.exports.${G0} = typeof ${G0} !== 'undefined' ? ${G0} : module.exports.${G0};`).join(`
|
|
4246
|
+
`),w0=Z.params??{},W0=[],o0=[];for(let G0=0;G0<m.length;G0++){if(m[G0]==="params")continue;W0.push(m[G0]),o0.push(g[G0])}let u5=await Function("module","exports","require","props","$props","defineProps","withDefaults","state","derived","effect","batch","onMount","onDestroy","definePageMeta","useRoute","useRouter","useHead","useSeoMeta","ref","reactive","computed","watch","onMounted","onUnmounted","nextTick","defineEmits","defineExpose","defineSlots","provide","inject","useColorMode","useDark","window","document","console","confirm","alert","fetch","params",...a,...W0,`return (async () => {
|
|
4247
4247
|
${v}
|
|
4248
4248
|
${M0}
|
|
4249
4249
|
return module.exports
|
|
4250
|
-
})()`)(Q,G,B,_,z,q,H,L,F,O,V,N,A,w,R,M,T,E,D,S,C,P,b,x,s,u,y,j,h,
|
|
4250
|
+
})()`)(Q,G,B,_,z,q,H,L,F,O,V,N,A,w,R,M,T,E,D,S,C,P,b,x,s,u,y,j,h,p,n,r,Z0,F0,R0,K0.confirm,K0.alert,K0.fetch,w0,...l,...o0);if(X.preserveExisting){for(let[G0,k0]of Object.entries(u5))if(!(G0 in Z)||Z[G0]===void 0)Z[G0]=k0}else Object.assign(Z,u5);for(let[G0,k0]of Object.entries(_))if(!(G0 in Z))Z[G0]=k0}catch(v){if(j6.env.STX_DEBUG){let d=v instanceof Error?v.message:String(v);console.warn(`[stx] server <script> did not execute in ${Y??"<unknown>"} \u2014 falling back to static extraction. Cause: ${d}`)}try{await XT(J,Z,Y)}catch(d){if(j6.env.STX_DEBUG){let m=d instanceof Error?d.message:String(d);console.warn(`[stx] fallback extraction also failed in ${Y??"<unknown>"}: ${m}`)}}}}function OZ($,Z){let Y=Z?h7.dirname(Z):j6.cwd(),X=$.split(`
|
|
4251
4251
|
`),J=[],Q=0;while(Q<X.length){let G=X[Q].trim();if(G.startsWith("interface ")||G.startsWith("export interface ")||G.startsWith("type ")||G.startsWith("export type ")){if(G.includes("{")&&!G.includes("}")){let K=0;for(;Q<X.length;Q++){for(let W of X[Q])if(W==="{")K++;else if(W==="}")K--;if(K<=0)break}}Q++;continue}if(G.startsWith("definePageMeta(")){let K=0,W=!1;for(let U=Q;U<X.length&&!W;U++){let B=null,_=!1,z=X[U];for(let q=0;q<z.length;q++){let j=z[q];if(_){_=!1;continue}if(j==="\\"){_=!0;continue}if(B){if(j===B)B=null;continue}if(j==='"'||j==="'"||j==="`"){B=j;continue}if(j==="(")K++;else if(j===")"){if(K--,K===0){Q=U+1,W=!0;break}}}}if(!W)Q=X.length;continue}if(G.startsWith("import ")){let K=G.match(/^import\s+(\w+)\s+from\s+['"](.+)['"]/),W=G.match(/^import\s+\{([^}]+)\}\s+from\s+['"](.+)['"]/),U=G.match(/^import\s+['"](.+)['"]/),B=(_)=>{if(_.startsWith("."))return h7.resolve(Y,_);return _};if(K){let[,_,z]=K,q=B(z);J.push(`const ${_} = await import('${q}')`),J.push(`module.exports.${_} = ${_};`)}else if(W){let[,_,z]=W,q=_.trim(),j=B(z);J.push(`const { ${q} } = await import('${j}')`);for(let H of q.split(",")){let L=H.trim().split(/\s+as\s+/).pop()?.trim();if(L)J.push(`module.exports.${L} = ${L};`)}}else if(U){let _=B(U[1]);J.push(`await import('${_}')`)}else J.push(G);Q++;continue}if((G.startsWith("const ")||G.startsWith("let ")||G.startsWith("var ")||G.startsWith("export const ")||G.startsWith("export let ")||G.startsWith("export var "))&&!G.includes("="))J.push(X[Q]),Q++;else if(G.startsWith("export const ")||G.startsWith("export let ")||G.startsWith("export var ")){let K=Bz(X,Q),{type:W,name:U,value:B}=K;J.push(`${W} ${U} = ${B};`),J.push(`module.exports.${U} = ${U};`),Q=K.nextIndex}else if(G.startsWith("export function ")||G.startsWith("export async function ")){let K=F9(X,Q);J.push(K.functionCode),J.push(`module.exports.${K.name} = ${K.name};`),Q=K.nextIndex}else if(G.startsWith("const ")||G.startsWith("let ")||G.startsWith("var ")){let K=Bz(X,Q),{type:W,name:U,value:B}=K;J.push(`${W} ${U} = ${B};`),J.push(`module.exports.${U} = ${U};`),Q=K.nextIndex}else if(G.startsWith("function ")||G.startsWith("async function ")){let K=F9(X,Q);J.push(K.functionCode),J.push(`module.exports.${K.name} = ${K.name};`),Q=K.nextIndex}else if(G.startsWith("export default function ")||G.startsWith("export default async function ")){let K=X[Q].replace(/^(\s*)export\s+default\s+/,"$1"),W=[...X];W[Q]=K;let U=F9(W,Q);if(J.push(U.functionCode),U.name)J.push(`module.exports.default = ${U.name};`);Q=U.nextIndex}else if(G.startsWith("export default ")){let K=G.replace(/^export\s+default\s+/,"").replace(/;$/,"");J.push(`module.exports.default = ${K};`),Q++}else if(G.startsWith("class ")||G.startsWith("export class ")){let K=G.match(/(?:export\s+)?class\s+(\w+)/);if(K){let W=K[1],U=X[Q].replace(/^export\s+/,""),B=0,_=Q;for(;_<X.length;_++){let z=X[_];for(let q of z)if(q==="{")B++;else if(q==="}")B--;if(_>Q)U+=`
|
|
4252
4252
|
`+z;if(B<=0&&_>=Q)break}J.push(U),J.push(`module.exports.${W} = ${W};`),Q=_+1}else J.push(G),Q++}else if(G.includes("module.exports"))J.push(G),Q++;else if(G.trim()&&!G.startsWith("//"))J.push(G),Q++;else Q++}return eM(J.join(`
|
|
4253
4253
|
`),Y)}function eM($,Z){let Y=$.length,X="",J=0,Q=null,G=!1,K=!1,W=0;while(J<Y){let U=$[J],B=$[J+1];if(G){if(X+=U,U===`
|
|
@@ -4314,8 +4314,8 @@ ${OT($).split(",").map((W)=>W.trim()).filter(Boolean).map((W)=>` try { __scopeR
|
|
|
4314
4314
|
} finally {
|
|
4315
4315
|
if (typeof window !== 'undefined') window.__STX_CURRENT_ELEMENT__ = __stxPrevEl;
|
|
4316
4316
|
}
|
|
4317
|
-
})();`}function FT($,Z){let Y=$.match(/^(\s*(?:(?:<!--[\s\S]*?-->|\x00STX_HTML_COMMENT_\d+\x00)\s*)*)(<[a-zA-Z][a-zA-Z0-9-]*)(\s[^>]*>|>)/s);if(Y){let J=(Y[2]+Y[3]).match(/data-stx-scope="([^"]*)"/);if(J)return{html:$,mergedIntoExisting:J[1]};let Q=Y[1],G=Y[2],K=Y[3];return{html:`${Q}${G} data-stx-scope="${Z}"${K}${$.slice(Y[0].length)}`,mergedIntoExisting:null}}return{html:$,mergedIntoExisting:null}}function VT(){w9.clear()}function NT($){if($.__onceStore instanceof Set)return $.__onceStore;return w9}async function RZ($,Z,Y,X,J,Q=new Set){let G=X.partialsDir||I0.join(I0.dirname(Y),"partials");if(G&&!I0.isAbsolute(G))G=I0.resolve(process.cwd(),G);let K=jT($,"@partial","@include"),W=NT(Z);K=K.replace(/@once([\s\S]*?)@endonce/g,(j,H,L)=>{let F=H.trim(),O=`${Y}:${F}`;if(W.has(O))return"";return W.add(O),H});{let j=/@includeIf\s*\(/g,H;while((H=j.exec(K))!==null){let L=H.index,F=L+H[0].length-1,O=1,V=F+1;while(V<K.length&&O>0){if(K[V]==="(")O++;else if(K[V]===")")O--;V++}if(O!==0)break;let N=K.substring(F+1,V-1),A=N.match(/^\s*['"]([^'"]+)['"]/);if(!A){j.lastIndex=V;continue}let w=A[1],R=U(w,G,Y),M="";if(R&&await Bun.file(R).exists())J.add(R),M=`@include(${N})`;K=K.substring(0,L)+M+K.substring(V),j.lastIndex=0}}for(let[j,H]of[["@includeWhen",!1],["@includeUnless",!0]]){let L=new RegExp(`${j.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*\\(`,"g"),F;while((F=L.exec(K))!==null){let O=F.index,V=O+F[0].length-1,N=1,A=V+1;while(A<K.length&&N>0){if(K[A]==="(")N++;else if(K[A]===")")N--;A++}if(N!==0)break;let w=K.substring(V+1,A-1),R=A9(w,0);if(R===-1){L.lastIndex=A;continue}let M=w.substring(0,R).trim(),T=w.substring(R+1).trim(),E=T.match(/^\s*['"]([^'"]+)['"]/);if(!E){L.lastIndex=A;continue}let D=E[1],S=T.substring(E[0].length),C,P=A9(S,0);if(P!==-1)C=S.substring(P+1).trim();try{let b=`Boolean(${M})`,x;if(_0(b)){let y=z0(b,Object.keys(Z));x=Boolean(y(...Object.values(Z)))}else x=Boolean(B0(b,Z));let s=H?!x:x,u="";if(s){let y=U(D,G,Y);if(y&&await Bun.file(y).exists())J.add(y);u=`@include('${D}'${C?`, ${C}`:""})`}K=K.substring(0,O)+u+K.substring(A),L.lastIndex=0}catch(b){let x=b instanceof Error?b.message:String(b),s=L0("Include",`Error evaluating ${j} condition: ${x}`,Y,$,O);K=K.substring(0,O)+s+K.substring(A),L.lastIndex=0}}}{let j=/@each\s*\(/g,H;while((H=j.exec(K))!==null){let L=H.index,F=L+H[0].length-1,O=1,V=F+1;while(V<K.length&&O>0){if(K[V]==="(")O++;else if(K[V]===")"){if(O--,O===0)break}V++}if(O!==0)break;let N=K.substring(F+1,V),A=K.substring(L,V+1),w=N.match(/^\s*['"]([^'"]+)['"]\s*,\s*([^,]+)\s*,\s*['"]([^'"]+)['"](?:\s*,\s*['"]([^'"]+)['"])?\s*$/);if(!w){j.lastIndex=0,K=K.replace(A,"");continue}let[,R,M,T,E]=w;try{let D,S=M.trim();if(_0(S))D=z0(S,Object.keys(Z))(...Object.values(Z));else D=B0(S,Z);let C="";if(Array.isArray(D)&&D.length>0)for(let P of D){let b={...Z,[T]:P},x=await _(R,b,$,L);C+=x}else if(E)C=await _(E,{},$,L);K=K.substring(0,L)+C+K.substring(V+1),j.lastIndex=0}catch(D){let S=D instanceof Error?D.message:String(D);K=K.substring(0,L)+L0("Each",`Error in @each: ${S}`,Y,$,L)+K.substring(V+1),j.lastIndex=0}}}{let j=/@includeFirst\s*\(/g,H;while((H=j.exec(K))!==null){let L=H.index,F=L+H[0].length-1,O=1,V=F+1;while(V<K.length&&O>0){if(K[V]==="(")O++;else if(K[V]===")"){if(O--,O===0)break}V++}if(O!==0)break;let N=K.substring(F+1,V),A=K.substring(L,V+1),w=N.match(/^\s*(\[[^\]]+\])/);if(!w){j.lastIndex=0,K=K.replace(A,"");continue}let R=w[1],M=N.slice(w[0].length),T,E=M.match(/^\s*,\s*\{/);if(E){M=M.slice(E[0].length-1);let C=1,P=1;while(P<M.length&&C>0){if(M[P]==="{")C++;else if(M[P]==="}"){if(C--,C===0)break}P++}T=M.substring(0,P+1),M=M.slice(P+1)}let D,S=M.match(/^\s*,\s*['"]([^'"]*)['"]\s*$/);if(S)D=S[1];try{let C=JSON.parse(R.replace(/'/g,'"')),P={};if(T)try{P=b0(T,Z)}catch(x){let s=x instanceof Error?x.message:String(x);if(X.debug){let u=L0("Include",`Error parsing includeFirst variables: ${s}`,Y,$,L,A);K=K.replace(A,()=>u)}else K=K.replace(A,()=>D||"");continue}let b=!1;for(let x of C){let s=U(x,G,Y);if(!s)continue;if(await e(s)){let u=await _(x,P,$,L);K=K.replace(A,()=>u),b=!0;break}}if(!b)if(D!==void 0)K=K.replace(A,()=>D);else if(X.debug){let x=L0("Include",`None of the includeFirst paths exist: ${R}`,Y,$,L,A);K=K.replace(A,()=>x)}else K=K.replace(A,"")}catch(C){let P=C instanceof Error?C.message:String(C),b=L0("Include",`Error processing @includeFirst: ${P}`,Y,$,L,A);K=K.replace(A,()=>b)}j.lastIndex=0}}function U(j,H,L){try{let F=j;if(!j.endsWith(".stx"))F=`${j}.stx`;let O=I0.resolve(H),V=I0.resolve(I0.dirname(L)),N;if(!F.startsWith("./")&&!F.startsWith("../"))N=I0.resolve(H,F);else N=I0.resolve(V,F);let A=I0.normalize(N),w=A.startsWith(O+I0.sep)||A===O,R=A.startsWith(V+I0.sep)||A===V,M=!1,T=I0.dirname(V);if(A.startsWith(T+I0.sep)){if(!I0.relative(T,A).split(I0.sep).some((C)=>C.startsWith(".")&&C!=="."&&C!==".."))M=!0}if(!w&&!R&&!M)return console.error(`Security: Path traversal attempt blocked for include path: ${j}`),console.error(` Resolved to: ${A}`),console.error(` Allowed dirs: ${O}, ${V}`),null;return A}catch(F){return console.error(`Error resolving path ${j}: ${F}`),null}}let B=I0.resolve(Y);Q.add(B);async function _(j,H={},L,F){let O=U(j,G,Y);if(!O)return L0("Include",`Could not resolve path for include: ${j}`,Y,L,F);let V=I0.resolve(O);if(Q.has(V)){let N=[...Q,V].map((A)=>I0.basename(A)).join(" -> ");return L0("Include",`Circular include detected: ${N}`,Y,L,F)}try{J.add(O);let N;if(!N)try{N=await Bun.file(O).text()}catch(u){let y=u instanceof Error?u.message:String(u);return L0("Include",`Error loading include file ${j}: ${y}`,Y,L,F)}if(N&&N.includes("@stream")){let{processStreamDirectives:u}=await Promise.resolve().then(() => (h$(),A5));N=u(N,Z)}if(N&&(X.debug||!V7()&&!r4()))try{let{warnUnbalancedTags:u}=await Promise.resolve().then(() => (u2(),p_));u(N,O)}catch{}let A=N;try{let{processESImports:u}=await Promise.resolve().then(() => (O9(),Uz));await u(N,Z,O,X,J)}catch(u){if(X.debug)console.warn(`[stx] partial ES import extraction skipped for ${O}:`,u instanceof Error?u.message:u)}let w=A.match(/<template\b(?![^>]*\b(?:id|x-for|x-if|@for|@if|:for|:if)\s*=)[^>]*>([\s\S]*?)<\/template>/i);if(w)A=w[1].trim();let M=N.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").match(/<style\b([^>]*)>([\s\S]*?)<\/style>/i),T="";if(M)T=`<style${M[1]}>${M[2]}</style>`;A=A.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,""),A=A.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"");let E={...Z};for(let[u,y]of Object.entries(H))E[u]=y;let D=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,S=[...N.matchAll(D)],C="",P=null;for(let u of S){let y=u[1]||"",h=u[2]||"",
|
|
4318
|
-
`;continue}if(
|
|
4317
|
+
})();`}function FT($,Z){let Y=$.match(/^(\s*(?:(?:<!--[\s\S]*?-->|\x00STX_HTML_COMMENT_\d+\x00)\s*)*)(<[a-zA-Z][a-zA-Z0-9-]*)(\s[^>]*>|>)/s);if(Y){let J=(Y[2]+Y[3]).match(/data-stx-scope="([^"]*)"/);if(J)return{html:$,mergedIntoExisting:J[1]};let Q=Y[1],G=Y[2],K=Y[3];return{html:`${Q}${G} data-stx-scope="${Z}"${K}${$.slice(Y[0].length)}`,mergedIntoExisting:null}}return{html:$,mergedIntoExisting:null}}function VT(){w9.clear()}function NT($){if($.__onceStore instanceof Set)return $.__onceStore;return w9}async function RZ($,Z,Y,X,J,Q=new Set){let G=X.partialsDir||I0.join(I0.dirname(Y),"partials");if(G&&!I0.isAbsolute(G))G=I0.resolve(process.cwd(),G);let K=jT($,"@partial","@include"),W=NT(Z);K=K.replace(/@once([\s\S]*?)@endonce/g,(j,H,L)=>{let F=H.trim(),O=`${Y}:${F}`;if(W.has(O))return"";return W.add(O),H});{let j=/@includeIf\s*\(/g,H;while((H=j.exec(K))!==null){let L=H.index,F=L+H[0].length-1,O=1,V=F+1;while(V<K.length&&O>0){if(K[V]==="(")O++;else if(K[V]===")")O--;V++}if(O!==0)break;let N=K.substring(F+1,V-1),A=N.match(/^\s*['"]([^'"]+)['"]/);if(!A){j.lastIndex=V;continue}let w=A[1],R=U(w,G,Y),M="";if(R&&await Bun.file(R).exists())J.add(R),M=`@include(${N})`;K=K.substring(0,L)+M+K.substring(V),j.lastIndex=0}}for(let[j,H]of[["@includeWhen",!1],["@includeUnless",!0]]){let L=new RegExp(`${j.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\s*\\(`,"g"),F;while((F=L.exec(K))!==null){let O=F.index,V=O+F[0].length-1,N=1,A=V+1;while(A<K.length&&N>0){if(K[A]==="(")N++;else if(K[A]===")")N--;A++}if(N!==0)break;let w=K.substring(V+1,A-1),R=A9(w,0);if(R===-1){L.lastIndex=A;continue}let M=w.substring(0,R).trim(),T=w.substring(R+1).trim(),E=T.match(/^\s*['"]([^'"]+)['"]/);if(!E){L.lastIndex=A;continue}let D=E[1],S=T.substring(E[0].length),C,P=A9(S,0);if(P!==-1)C=S.substring(P+1).trim();try{let b=`Boolean(${M})`,x;if(_0(b)){let y=z0(b,Object.keys(Z));x=Boolean(y(...Object.values(Z)))}else x=Boolean(B0(b,Z));let s=H?!x:x,u="";if(s){let y=U(D,G,Y);if(y&&await Bun.file(y).exists())J.add(y);u=`@include('${D}'${C?`, ${C}`:""})`}K=K.substring(0,O)+u+K.substring(A),L.lastIndex=0}catch(b){let x=b instanceof Error?b.message:String(b),s=L0("Include",`Error evaluating ${j} condition: ${x}`,Y,$,O);K=K.substring(0,O)+s+K.substring(A),L.lastIndex=0}}}{let j=/@each\s*\(/g,H;while((H=j.exec(K))!==null){let L=H.index,F=L+H[0].length-1,O=1,V=F+1;while(V<K.length&&O>0){if(K[V]==="(")O++;else if(K[V]===")"){if(O--,O===0)break}V++}if(O!==0)break;let N=K.substring(F+1,V),A=K.substring(L,V+1),w=N.match(/^\s*['"]([^'"]+)['"]\s*,\s*([^,]+)\s*,\s*['"]([^'"]+)['"](?:\s*,\s*['"]([^'"]+)['"])?\s*$/);if(!w){j.lastIndex=0,K=K.replace(A,"");continue}let[,R,M,T,E]=w;try{let D,S=M.trim();if(_0(S))D=z0(S,Object.keys(Z))(...Object.values(Z));else D=B0(S,Z);let C="";if(Array.isArray(D)&&D.length>0)for(let P of D){let b={...Z,[T]:P},x=await _(R,b,$,L);C+=x}else if(E)C=await _(E,{},$,L);K=K.substring(0,L)+C+K.substring(V+1),j.lastIndex=0}catch(D){let S=D instanceof Error?D.message:String(D);K=K.substring(0,L)+L0("Each",`Error in @each: ${S}`,Y,$,L)+K.substring(V+1),j.lastIndex=0}}}{let j=/@includeFirst\s*\(/g,H;while((H=j.exec(K))!==null){let L=H.index,F=L+H[0].length-1,O=1,V=F+1;while(V<K.length&&O>0){if(K[V]==="(")O++;else if(K[V]===")"){if(O--,O===0)break}V++}if(O!==0)break;let N=K.substring(F+1,V),A=K.substring(L,V+1),w=N.match(/^\s*(\[[^\]]+\])/);if(!w){j.lastIndex=0,K=K.replace(A,"");continue}let R=w[1],M=N.slice(w[0].length),T,E=M.match(/^\s*,\s*\{/);if(E){M=M.slice(E[0].length-1);let C=1,P=1;while(P<M.length&&C>0){if(M[P]==="{")C++;else if(M[P]==="}"){if(C--,C===0)break}P++}T=M.substring(0,P+1),M=M.slice(P+1)}let D,S=M.match(/^\s*,\s*['"]([^'"]*)['"]\s*$/);if(S)D=S[1];try{let C=JSON.parse(R.replace(/'/g,'"')),P={};if(T)try{P=b0(T,Z)}catch(x){let s=x instanceof Error?x.message:String(x);if(X.debug){let u=L0("Include",`Error parsing includeFirst variables: ${s}`,Y,$,L,A);K=K.replace(A,()=>u)}else K=K.replace(A,()=>D||"");continue}let b=!1;for(let x of C){let s=U(x,G,Y);if(!s)continue;if(await e(s)){let u=await _(x,P,$,L);K=K.replace(A,()=>u),b=!0;break}}if(!b)if(D!==void 0)K=K.replace(A,()=>D);else if(X.debug){let x=L0("Include",`None of the includeFirst paths exist: ${R}`,Y,$,L,A);K=K.replace(A,()=>x)}else K=K.replace(A,"")}catch(C){let P=C instanceof Error?C.message:String(C),b=L0("Include",`Error processing @includeFirst: ${P}`,Y,$,L,A);K=K.replace(A,()=>b)}j.lastIndex=0}}function U(j,H,L){try{let F=j;if(!j.endsWith(".stx"))F=`${j}.stx`;let O=I0.resolve(H),V=I0.resolve(I0.dirname(L)),N;if(!F.startsWith("./")&&!F.startsWith("../"))N=I0.resolve(H,F);else N=I0.resolve(V,F);let A=I0.normalize(N),w=A.startsWith(O+I0.sep)||A===O,R=A.startsWith(V+I0.sep)||A===V,M=!1,T=I0.dirname(V);if(A.startsWith(T+I0.sep)){if(!I0.relative(T,A).split(I0.sep).some((C)=>C.startsWith(".")&&C!=="."&&C!==".."))M=!0}if(!w&&!R&&!M)return console.error(`Security: Path traversal attempt blocked for include path: ${j}`),console.error(` Resolved to: ${A}`),console.error(` Allowed dirs: ${O}, ${V}`),null;return A}catch(F){return console.error(`Error resolving path ${j}: ${F}`),null}}let B=I0.resolve(Y);Q.add(B);async function _(j,H={},L,F){let O=U(j,G,Y);if(!O)return L0("Include",`Could not resolve path for include: ${j}`,Y,L,F);let V=I0.resolve(O);if(Q.has(V)){let N=[...Q,V].map((A)=>I0.basename(A)).join(" -> ");return L0("Include",`Circular include detected: ${N}`,Y,L,F)}try{J.add(O);let N;if(!N)try{N=await Bun.file(O).text()}catch(u){let y=u instanceof Error?u.message:String(u);return L0("Include",`Error loading include file ${j}: ${y}`,Y,L,F)}if(N&&N.includes("@stream")){let{processStreamDirectives:u}=await Promise.resolve().then(() => (h$(),A5));N=u(N,Z)}if(N&&(X.debug||!V7()&&!r4()))try{let{warnUnbalancedTags:u}=await Promise.resolve().then(() => (u2(),p_));u(N,O)}catch{}let A=N;try{let{processESImports:u}=await Promise.resolve().then(() => (O9(),Uz));await u(N,Z,O,X,J)}catch(u){if(X.debug)console.warn(`[stx] partial ES import extraction skipped for ${O}:`,u instanceof Error?u.message:u)}let w=A.match(/<template\b(?![^>]*\b(?:id|x-for|x-if|@for|@if|:for|:if)\s*=)[^>]*>([\s\S]*?)<\/template>/i);if(w)A=w[1].trim();let M=N.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").match(/<style\b([^>]*)>([\s\S]*?)<\/style>/i),T="";if(M)T=`<style${M[1]}>${M[2]}</style>`;A=A.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,""),A=A.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"");let E={...Z};for(let[u,y]of Object.entries(H))E[u]=y;let D=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,S=[...N.matchAll(D)],C="",P=null;for(let u of S){let y=u[1]||"",h=u[2]||"",p=y.includes("server"),n=l$(y),r="";try{let{extractAndStripCssImports:Z0,renderVendorStyleTags:F0}=await Promise.resolve().then(() => (R5(),Iz)),R0=Z0(h,{filePath:O,projectRoot:process.cwd()});h=R0.code,r=F0(R0.styles)}catch(Z0){if(X.debug)console.warn(`[stx] vendor-css extractor skipped for ${O}:`,Z0 instanceof Error?Z0.message:Z0)}if(n&&h.trim())h=i$(h);if(!p)try{let{hasUserImports:Z0,bundleClientScript:F0}=await Promise.resolve().then(() => (n3(),i3));if(Z0(h))h=await F0(h,O,{projectRoot:process.cwd()})}catch(Z0){if(X.debug)console.warn(`[stx] bundler skipped for ${O}:`,Z0 instanceof Error?Z0.message:Z0)}let K0=HT(h);if(K0&&!p){P=`stx_scope_${I0.basename(O,".stx").replace(/[^a-zA-Z0-9]/g,"_")}_${++Tz}`;let Z0=J$(h),F0=LT(Z0,P);C+=`${r}<script data-stx-scoped>${F0}</script>
|
|
4318
|
+
`;continue}if(p)try{let{extractVariables:Z0}=await Promise.resolve().then(() => (p$(),LZ));await Z0(h,E,O)}catch(Z0){if(X.debug)console.warn(`Warning: Could not extract variables from server script in ${O}:`,Z0)}if(!p&&!K0){let Z0=y.replace(/\bclient\b/i,"").trim();P=`stx_scope_${I0.basename(O,".stx").replace(/[^a-zA-Z0-9]/g,"_")}_${++Tz}`;let F0=J$(h),R0=`
|
|
4319
4319
|
if (!window.stx._scopes) window.stx._scopes = {};
|
|
4320
4320
|
window.stx._scopes['${P}'] = { __destroyCallbacks: __destroyHooks };
|
|
4321
4321
|
`,v=Ez(F0,R0);C+=`${r}<script data-stx-scoped${Z0?` ${Z0}`:""}>${v}</script>
|
|
@@ -13484,26 +13484,26 @@ ${W.trim()}
|
|
|
13484
13484
|
`);j.content=j.content?`${j.content}
|
|
13485
13485
|
${V}`:V,Z.__sections=j}}if(H)try{let O;if(_1.isAbsolute(H))O=H,J.add(H);else O=await i1(()=>$6(H,Y,G,J),null,()=>{throw new y1(`Failed to resolve layout path: ${H}`,Y,void 0,void 0,`Layout referenced from ${Y}`)});if(!O){let M=`Layout not found: ${H} (referenced from ${Y})`;if(n0.log(Error(M),{layoutPath:H,filePath:Y},"warning"),G.debug)throw new y1(M,Y);return W}let V=await i1(()=>Bun.file(O).text(),"",()=>{throw new y1(`Failed to read layout file: ${O}`,Y,void 0,void 0,"Layout content could not be loaded")}),N=V.match(/@(?:layout|extends)\(\s*['"]([^'"]+)['"]\s*\)/);if(N){if(G.debug)console.log(`Found nested layout: ${N[1]} in ${O}`);let M={},T=V.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@show|@endsection)/g,(S,C,P)=>{return M[C]=P.trim(),""});for(let[S,C]of Object.entries(M))if(j[S]&&j[S].includes(k5)){let P=j[S].indexOf(k5);j[S]=j[S].slice(0,P)+C+j[S].slice(P+k5.length)}else if(!j[S])j[S]=C;let E={...Z,__sections:j},D=`@layout('${N[1]}')${T}`;return await X0(D,E,O,G,J)}let A=V.replace(/\{\{--[\s\S]*?--\}\}/g,""),w=MZ(A,q),R={};return w=w.replace(/@section\(\s*['"]([^'"]+)['"]\s*\)([\s\S]*?)(?:@show|@endsection)/g,(M,T,E)=>{return R[T]=E.trim(),`@slot('${T}')`}),w=w.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(M,T,E)=>{if(j[T]){let D=j[T];if(D.includes(k5)){let S=R[T]||"",C=D.indexOf(k5);D=D.slice(0,C)+S+D.slice(C+k5.length)}return D}return E||""}),w=wE(w,j),w=w.replace(/\{\{\s*slot\s*\}\}/g,()=>{return j.content||""}),w=TZ(w,q),Z.__originalFilePath=Y,W=await nj(w,Z,O,G,J),W=`<!-- stx-layout: ${H} -->
|
|
13486
13486
|
${W}`,_(W)}catch(O){return n0.log(O instanceof Error?O:Error(String(O)),{layoutPath:H,filePath:Y},"error"),`[Error processing layout: ${O instanceof Error?O.message:String(O)}]`}return _(await nj(W,Z,Y,G,J))}function wE($,Z){return $.replace(/@(?:yield|slot)\(\s*['"]([^'"]+)['"]\s*(?:,\s*['"]([^'"]+)['"]\s*)?\)/g,(Y,X,J)=>{let Q=Z[X];if(Q!==void 0){if(!new RegExp(`@(?:yield|slot)\\(\\s*['"]${X.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}['"]`).test(Q))return Q}return J||""})}function RE($,Z){if($.__stx_sfc_mode=!0,$.__stx_options=Z,Z.buildMode)$.__stx_buildMode=Z.buildMode;let Y=Z.envPrefix||"STX_PUBLIC_",X={};for(let[J,Q]of Object.entries(process.env))if(J.startsWith(Y)&&Q!==void 0)X[J]=Q;$.$env=X}async function ME($,Z){await i1(()=>xz($,Z),void 0,(Y)=>{n0.log(Y,{filePath:$,phase:"view-composer"},"warning"),console.warn(`[stx] view composer failed for ${$}: ${Y.message}`)})}async function TE($,Z,Y){let X=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,J;while((J=X.exec($))!==null){let Q=J[1],G=J[2];if(!/\bserver\b/.test(Q)||!G.trim())continue;try{let{extractVariables:W}=await Promise.resolve().then(() => (p$(),LZ));await W(G,Z,Y,{preserveExisting:!0})}catch(W){let U=W instanceof Error?W:Error(String(W));n0.log(U,{filePath:Y,phase:"server-script-extraction"},"warning"),console.warn(`[stx] server <script> extraction failed in ${Y}: ${U.message}`)}}}async function IE($,Z,Y){try{let{interpolateScriptsInTemplate:X}=await Promise.resolve().then(() => (c0(),b4));return X($,Z,{skipServer:!0})}catch(X){let J=X instanceof Error?X:Error(String(X));return n0.log(J,{filePath:Y,phase:"script-expression-interpolation"},"warning"),console.warn(`[stx] script expression interpolation failed in ${Y}: ${J.message}`),$}}async function nj($,Z,Y,X,J){let Q=$,G=X;if(await TE(Q,Z,Y),Q=await IE(Q,Z,Y),Q=await Dz(Q,Z,Y),Q=await kz(Q,Z,Y),Q=await A2(Q,Z,Y,G),q5(Q))Q=h9(Q,Z),Q=u9(Q,Z);Q=d9(Q);let{processStreamDirectives:K}=await Promise.resolve().then(() => (h$(),A5));Q=K(Q,Z),Q=AZ(Q,Z,Y,G),Q=await HZ(Q,Z,Y,G,J),Q=await b9(Q,Z,Y,G,J),Q=aY(Q,Z,Y,G);let{processDeferDirectives:W}=await Promise.resolve().then(() => Rq);Q=W(Q,Z,Y);let{processTeleportDirectives:U}=await Promise.resolve().then(() => Eq);Q=U(Q,Z,Y);let{processTransitionDirectives:B,processTransitionAttributes:_}=await Promise.resolve().then(() => fq);Q=B(Q,Z,Y),Q=_(Q);let{processErrorBoundaryDirectives:z}=await Promise.resolve().then(() => hq);Q=z(Q,Z,Y);let{processSuspenseDirectives:q}=await Promise.resolve().then(() => lq);Q=q(Q,Z,Y);let{processAsyncDirectives:j}=await Promise.resolve().then(() => $j);Q=j(Q,Z,Y);let{processKeepAliveDirectives:H}=await Promise.resolve().then(() => Uj);Q=H(Q,Z,Y);let{processVirtualListDirectives:L,processVirtualGridDirectives:F,processInfiniteListDirectives:O}=await Promise.resolve().then(() => (a9(),Bj));Q=L(Q,Z,Y),Q=F(Q,Z,Y),Q=O(Q,Z,Y);let{processPartialHydrationDirectives:V,processStaticDirectives:N}=await Promise.resolve().then(() => (_Q(),_j));Q=V(Q,Z,Y),Q=N(Q);let{processComputedDirectives:A,processWatchDirectives:w}=await Promise.resolve().then(() => (Rj(),wj));Q=A(Q,Z,Y),Q=w(Q,Z,Y);let{processFormValidationDirectives:R}=await Promise.resolve().then(() => (Dj(),Ej));Q=R(Q,Z,Y);let{processHeadDirective:M,processTitleDirective:T,processMetaDirective:E,resetHead:D}=await Promise.resolve().then(() => (f$(),$Z));if(!Z.__stx_head_preset&&!Z.__stx_runtime_head)D();let S=M(Q);if(Q=S.content,S.headContent)Z.__stx_head_raw=`${Z.__stx_head_raw||""}${S.headContent}
|
|
13487
|
-
`;if(Q=T(Q,Z),Q=E(Q,Z),Q=Pz(Q),Q=z2(Q,Z),Q=tB(Q),Q=Cz(Q),Q=await RZ(Q,Z,Y,G,J),Q=await HZ(Q,Z,Y,G,J),Q=Q.replace(/@push\s*\(\s*['"][^'"]+['"]\s*\)[\s\S]*?@endpush/g,""),Q=c9(Q),Q=F5(Q,Z,Y),Q=q2(Q,Z),Q=j2(Q,Z),Q=P7(Q,Z),Q=XZ(Q,Z),Q=JZ(Q,Z),Q=await K2(Q,Z,Y,G),Q=await X8(Q,Z,Y),Q=await QZ(Q,Z,Y,G),Q=E3(Q,Z,Y,G),Q=xJ(Q,Z,Y,G),Q=vJ(Q,Z,Y),Q=fJ(Q,Z,Y,G),Q=V2(Q,Z,Y,G),Q=I6(Q,Z),Q=E6(Q),Q=Oq(Q),!G.skipEventDirectives)Q=J2(Q,Z,Y);if(Q=CB(Q,Z,Y),G.debug){let
|
|
13487
|
+
`;if(Q=T(Q,Z),Q=E(Q,Z),Q=Pz(Q),Q=z2(Q,Z),Q=tB(Q),Q=Cz(Q),Q=await RZ(Q,Z,Y,G,J),Q=await HZ(Q,Z,Y,G,J),Q=Q.replace(/@push\s*\(\s*['"][^'"]+['"]\s*\)[\s\S]*?@endpush/g,""),Q=c9(Q),Q=F5(Q,Z,Y),Q=q2(Q,Z),Q=j2(Q,Z),Q=P7(Q,Z),Q=XZ(Q,Z),Q=JZ(Q,Z),Q=await K2(Q,Z,Y,G),Q=await X8(Q,Z,Y),Q=await QZ(Q,Z,Y,G),Q=E3(Q,Z,Y,G),Q=xJ(Q,Z,Y,G),Q=vJ(Q,Z,Y),Q=fJ(Q,Z,Y,G),Q=V2(Q,Z,Y,G),Q=I6(Q,Z),Q=E6(Q),Q=Oq(Q),!G.skipEventDirectives)Q=J2(Q,Z,Y);if(Q=CB(Q,Z,Y),G.debug){let m=/\bx-data\s*=/.test(Q),g=pZ($);if(m&&g)console.warn(`[stx] ${Y}: Template mixes Alpine-style (x-data) and signals (state/derived/effect) reactivity.
|
|
13488
13488
|
Both work on the same page, but they manage separate scopes.
|
|
13489
|
-
Prefer signals (state/derived/effect) for new components.`)}Q=IZ(Q,Z),Q=await G1(Q,Z,Y),Q=Lq(Q),Q=Fq(Q),Q=Y2(Q);let{processXElementDirectives:C}=await Promise.resolve().then(() => bj);Q=C(Q);let P=Z.__originalFilePath||Y,b=a$(Z);if(Q=await m9(Q,G,P,b),Q=await I9(Q,Z,Y,G),G.media?.image?.autoSiblings){let
|
|
13490
|
-
</head>`);if(/<head\b[^>]*>/i.test(
|
|
13491
|
-
${g}`);if(/<html\b[^>]*>/i.test(
|
|
13489
|
+
Prefer signals (state/derived/effect) for new components.`)}Q=IZ(Q,Z),Q=await G1(Q,Z,Y),Q=Lq(Q),Q=Fq(Q),Q=Y2(Q);let{processXElementDirectives:C}=await Promise.resolve().then(() => bj);Q=C(Q);let P=Z.__originalFilePath||Y,b=a$(Z);if(Q=await m9(Q,G,P,b),Q=await I9(Q,Z,Y,G),G.media?.image?.autoSiblings){let m=G.publicDir||"public",{rewriteImagesWithSiblings:g}=await Promise.resolve().then(() => (BX(),JW));Q=await g(Q,{publicDir:m})}if(G.seo?.enabled)Q=gJ(Q,Z,G);let x=(m,g)=>{if(!g)return m;if(/<\/head>/i.test(m))return m.replace(/<\/head>/i,`${g}
|
|
13490
|
+
</head>`);if(/<head\b[^>]*>/i.test(m))return m.replace(/(<head\b[^>]*>)/i,`$1
|
|
13491
|
+
${g}`);if(/<html\b[^>]*>/i.test(m))return m.replace(/(<html\b[^>]*>)/i,`$1
|
|
13492
13492
|
<head>
|
|
13493
13493
|
${g}
|
|
13494
|
-
</head>`);return
|
|
13494
|
+
</head>`);return m},{renderHead:s,getHead:u}=await Promise.resolve().then(() => (f$(),$Z)),y=Z.__stx_runtime_head,h=y&&(y.title||y.meta?.length||y.link?.length)?y:u();if(h.title||h.meta?.length||h.link?.length){let m=s(h);if(m)Q=x(Q,m)}if(S.headContent)Q=x(Q,S.headContent);if(G.csp?.enabled&&G.csp.addMetaTag)Q=F2(Q,G.csp,Z);if(G.analytics?.enabled)Q=sY(Q,G);if(G.heatmap?.enabled)Q=bX(Q,G);if(G.pwa?.enabled&&G.pwa.autoInject!==!1){let{injectPwaTags:m}=await Promise.resolve().then(() => (lj(),cj));Q=m(Q,G)}let p=/<script\b(?![^>]*\bserver\b)[^>]*>[\s\S]*?<\/script>/i.test(Q),n=/\bSTX\.\w+/.test(Q),r=/window\.STX\s*=/.test(Q);if(p&&n&&!r){let g=`<script data-stx-scoped>
|
|
13495
13495
|
${LB()}
|
|
13496
13496
|
</script>`;if(Q.includes("</head>")){let c=Q.indexOf("</head>"),l=Q.slice(0,c).indexOf("<script");if(l!==-1){let Q0=Q.slice(0,l),M0=Q.slice(l);Q=Q0+g+`
|
|
13497
13497
|
`+M0}else Q=Q.replace("</head>",`${g}
|
|
13498
13498
|
</head>`)}else if(Q.includes("<body"))Q=Q.replace(/<body([^>]*)>/,`<body$1>
|
|
13499
13499
|
${g}`);else Q=g+`
|
|
13500
|
-
`+Q}{let
|
|
13500
|
+
`+Q}{let m=/<script\s+server\b[^>]*>/gi,g,c=[];while((g=m.exec(Q))!==null){let a=g.index+g[0].length,l=NE(Q,a);if(l===-1)continue;let Q0=l+9;while(Q0<Q.length&&/\s/.test(Q[Q0]))Q0++;c.push({start:g.index,end:Q0}),m.lastIndex=Q0}for(let a=c.length-1;a>=0;a--){let{start:l,end:Q0}=c[a];Q=Q.substring(0,l)+Q.substring(Q0)}}let K0=H6(Q,Y);if(K0.hasScoped)Q=K0.html;let Z0=Z.__stx_event_bindings||[],F0=!1,R0=[],v=/\s:[a-z][\w.-]*\s*=/.test(Q),{scanScriptTags:d}=await Promise.resolve().then(() => (p9(),_q));for(let m of d(Q,{skipAttrs:/\bserver\b|\bsrc\s*=|\bdata-stx-scoped\b|\bdata-stx-router\b|\btype\s*=\s*["'](?!(?:text\/javascript|application\/javascript|module)["'])[^"']*["']/}))R0.push({match:m.fullMatch,attrs:m.attrs,content:m.body});for(let{match:m,attrs:g,content:c}of R0){F0=!0;let a=c;D6(c,Y,X.strict);let l=await t$(c,{eventBindings:Z0,attrs:g,hasColonDirectives:v,templateContent:$,filePath:Y,projectRoot:process.cwd(),production:X.buildMode==="compile",serverData:b});Q=Q.replace(m,()=>l)}if(F0)Z.__stx_event_bindings=[];return Q}var k5="<!--PARENT_CONTENT_PLACEHOLDER-->";var L1=k(()=>{n1();e3();D3();FB();X2();rY();Y8();P3();Q2();R5();PB();k7();r8();N2();eB();w2();O1();f$();c0();T2();x2();d7();bz();wZ();Q8();E9();O5();yz();y8();N0();vz();D9();S9();C9();DZ();p9();O9();Hq();l9();i9();d0();u2();l9();i9()});function rj($){let Z=[],Y=[];return SE($,Z),bE($,Z,Y),CE($,Y),PE($,Z),{valid:Z.length===0,errors:Z,warnings:Y}}function SE($,Z){let Y=($.match(/\{\{/g)||[]).length,X=($.match(/\}\}/g)||[]).length;if(Y!==X)Z.push({type:"expression",message:`Unclosed expression brackets: found ${Y} opening '{{' and ${X} closing '}}'`,suggestion:"Ensure every {{ has a matching }}"})}function bE($,Z,Y){for(let X of EE){let J=new RegExp(`${X.open}(?:\\s|\\()`,"g"),Q=new RegExp(X.close,"g"),G=($.match(J)||[]).length,K=($.match(Q)||[]).length;if(X.altClose){let W=new RegExp(X.altClose,"g");K+=($.match(W)||[]).length}if(G>K)Z.push({type:"directive",message:`Unclosed @${X.name} directive: found ${G} opening and ${K} closing`,suggestion:`Add ${G-K} missing ${X.close} tag(s)`});else if(K>G)Y.push({type:"directive",message:`Extra ${X.close} found: ${K-G} more closing than opening`,suggestion:`Check for orphaned ${X.close} tags`})}}function CE($,Z){for(let Y of DE)if(Y.pattern.test($))Z.push({type:"syntax",message:Y.message,suggestion:Y.suggestion})}function PE($,Z){for(let Y of kE)if(Y.pattern.test($))Z.push({type:"expression",message:`Security warning: ${Y.message}`,suggestion:"Remove dangerous code from template expressions"})}function oj($,Z){let Y=$.slice(0,Z).split(`
|
|
13501
13501
|
`);return{line:Y.length,column:Y[Y.length-1].length+1}}function aj($,Z,Y){let X=[];switch($){case"if":case"elseif":case"unless":if(Y.length===0)X.push({type:"syntax",message:`@${$} requires a condition`,suggestion:`Use @${$}(condition)`});break;case"foreach":if(Y.length===0||!Y[0].includes(" as "))X.push({type:"syntax",message:'@foreach requires "items as item" syntax',suggestion:"Use @foreach(items as item) or @foreach(items as key => value)"});break;case"for":if(Y.length===0)X.push({type:"syntax",message:"@for requires loop parameters",suggestion:"Use @for(let i = 0; i < 10; i++)"});break;case"switch":if(Y.length===0)X.push({type:"syntax",message:"@switch requires an expression",suggestion:"Use @switch(expression)"});break;case"case":if(Y.length===0)X.push({type:"syntax",message:"@case requires a value",suggestion:"Use @case(value)"});break;case"include":case"extends":case"component":if(Y.length===0)X.push({type:"syntax",message:`@${$} requires a path`,suggestion:`Use @${$}('path/to/template')`});break}return X}function tj($){return/@[a-z]+/i.test($)||/\{\{/.test($)}function ej($){let Z=$.matchAll(/@([a-z]+)/gi),Y=new Set;for(let X of Z){let J=X[1].toLowerCase();if(!J.startsWith("end"))Y.add(J)}return Array.from(Y)}var EE,DE,kE;var $H=k(()=>{EE=[{open:"@if",close:"@endif",name:"if"},{open:"@unless",close:"@endunless",name:"unless"},{open:"@foreach",close:"@endforeach",name:"foreach"},{open:"@for",close:"@endfor",name:"for"},{open:"@while",close:"@endwhile",name:"while"},{open:"@forelse",close:"@endforelse",name:"forelse"},{open:"@switch",close:"@endswitch",name:"switch"},{open:"@isset",close:"@endisset",name:"isset"},{open:"@empty",close:"@endempty",name:"empty"},{open:"@auth",close:"@endauth",name:"auth"},{open:"@guest",close:"@endguest",name:"guest"},{open:"@can",close:"@endcan",name:"can"},{open:"@cannot",close:"@endcannot",name:"cannot"},{open:"@section",close:"@endsection",name:"section",altClose:"@show"},{open:"@push",close:"@endpush",name:"push"},{open:"@prepend",close:"@endprepend",name:"prepend"},{open:"@once",close:"@endonce",name:"once"},{open:"@markdown",close:"@endmarkdown",name:"markdown"},{open:"@component",close:"@endcomponent",name:"component"}],DE=[{pattern:/@if\s*[^(]/,message:"@if directive missing parentheses",suggestion:"Use @if(condition)"},{pattern:/@foreach\s*[^(]/,message:"@foreach directive missing parentheses",suggestion:"Use @foreach(items as item)"},{pattern:/@foreach\([^)]*\)\s*[^@\n<]/,message:"@foreach may have content on same line",suggestion:"Put content on new line after @foreach()"},{pattern:/@include\s*[^(]/,message:"@include directive missing parentheses",suggestion:"Use @include('partial-name')"},{pattern:/@extends\s*[^(]/,message:"@extends directive missing parentheses",suggestion:"Use @extends('layout-name') or @layout('layout-name')"},{pattern:/@layout\s*[^(]/,message:"@layout directive missing parentheses",suggestion:"Use @layout('layout-name')"}],kE=[{pattern:/\{\{\s*constructor\s*\}\}/,message:"Attempting to access constructor property"},{pattern:/\{\{\s*__proto__\s*\}\}/,message:"Attempting to access __proto__ property"},{pattern:/\{\{\s*eval\s*\(/,message:"Attempting to use eval in expression"}]});var QH={};t(QH,{renderSlot:()=>LQ,processSlots:()=>FQ,parseSlots:()=>OQ,parseSlotElement:()=>ZH,extractSlotContent:()=>XH,applySlots:()=>JH});function yE($,Z){let Y=1,X=Z,J="<template",Q="</template";while(X<$.length&&Y>0){let G=$.indexOf("<",X);if(G===-1)break;if(X=G,$.startsWith(J,X)&&(X+J.length>=$.length||/[\s>\/]/.test($[X+J.length]))){Y++,X+=J.length;continue}if($.startsWith(Q,X)){let K=$.indexOf(">",X+Q.length);if(K!==-1){if(Y--,Y===0)return K+1;X=K+1;continue}}X++}return Y===0?X:-1}function OQ($){let Z={default:"",named:new Map},Y=$,X=/<template\s+(?:#([a-zA-Z][\w-]*)|v-slot:([a-zA-Z][\w-]*)|slot="([a-zA-Z][\w-]*)")(?:\s*=\s*"([^"]*)")?[^>]*>/gi,J=[],Q;while((Q=X.exec($))!==null){let[B,_,z,q,j]=Q,H=_||z||q,L=Q.index+B.length,F=yE($,L);if(F!==-1){let O=$.slice(L,F-11).trim();J.push({start:Q.index,end:F,slotName:H,content:O,propsBinding:j||void 0}),Z.named.set(H,{name:H,content:O,propsBinding:j||void 0})}}J.sort((B,_)=>_.start-B.start);for(let B of J)Y=Y.slice(0,B.start)+Y.slice(B.end);let G=[],K=/<([a-zA-Z][a-zA-Z0-9-]*)\b([^>]*?)\bslot="([^"]+)"([^>]*)>([\s\S]*?)<\/\1>/gi,W;while((W=K.exec(Y))!==null){let[B,_,z,q,j,H]=W,L=z.replace(/\s*slot="[^"]*"\s*/," ").trimEnd(),F=j.replace(/\s*slot="[^"]*"\s*/," ").trimEnd(),O=(L+F).trim(),V=`<${_}${O?" "+O:""}>${H}</${_}>`;G.push({start:W.index,end:W.index+B.length,slotName:q,element:V})}let U=/<([a-zA-Z][a-zA-Z0-9-]*)\b([^>]*?)\bslot="([^"]+)"([^>]*?)\/>/gi;while((W=U.exec(Y))!==null){let[B,_,z,q,j]=W,H=z.replace(/\s*slot="[^"]*"\s*/," ").trimEnd(),L=j.replace(/\s*slot="[^"]*"\s*/," ").trimEnd(),F=(H+L).trim(),O=`<${_}${F?" "+F:""} />`;G.push({start:W.index,end:W.index+B.length,slotName:q,element:O})}G.sort((B,_)=>_.start-B.start);for(let B of G){let _=Z.named.get(B.slotName);if(_)_.content+=B.element;else Z.named.set(B.slotName,{name:B.slotName,content:B.element});Y=Y.slice(0,B.start)+Y.slice(B.end)}return Z.default=Y.trim(),Z}function ZH($){let Z=$.match(/name\s*=\s*["']([^"']+)["']/),Y=Z?Z[1]:"",X={},J=/:([a-zA-Z][\w-]*)\s*=\s*["']([^"']+)["']/g,Q;while((Q=J.exec($))!==null)X[Q[1]]=Q[2];let G=$.match(/<slot[^>]*>([\s\S]*?)<\/slot>/i),K=G?G[1].trim():"";return{name:Y,props:X,defaultContent:K}}async function LQ($,Z,Y,X){if(!$)return Y;let J=$.content;if($.propsBinding&&Object.keys(Z).length>0){let Q=$.propsBinding.trim(),G={...X};if(Q.startsWith("{")&&Q.endsWith("}")){let K=Q.slice(1,-1).split(",").map((W)=>W.trim()).filter(Boolean);for(let W of K){let[U,B]=W.split(":").map((z)=>z.trim()),_=B||U;if(Z[U]!==void 0)G[_]=Z[U]}}else G[Q]=Z;J=xE(J,G)}return J}function xE($,Z){return $.replace(/\{\{\s*([^}]+)\s*\}\}/g,(Y,X)=>{try{let J=X.trim(),Q=YH(J,Z);return E0(String(Q??""))}catch{return`{{ ${X} }}`}})}function YH($,Z){if(/^[a-zA-Z_$][\w$]*(\.[a-zA-Z_$][\w$]*)*$/.test($)){let X=$.split("."),J=Z;for(let Q of X)if(J&&typeof J==="object"&&Q in J)J=J[Q];else return;return J}let Y=$.match(/^([a-zA-Z_$][\w$]*)\s*([+\-*/])\s*(\d+)$/);if(Y){let[,X,J,Q]=Y,G=Z[X],K=parseInt(Q,10);if(typeof G==="number")switch(J){case"+":return G+K;case"-":return G-K;case"*":return G*K;case"/":return G/K}}try{if(!_0($))return;return z0($,Object.keys(Z))(...Object.values(Z))}catch{return}}async function FQ($,Z,Y){let X=$;X=await vE(X,/<slot\s+name\s*=\s*["']([^"']+)["']([^>]*?)(?:\/>|>([\s\S]*?)<\/slot>)/gi,async(G,K,W,U)=>{let B=Z.named.get(K),_=U?.trim()||"",z=W||"",q={},j=/:([a-zA-Z_$][\w$-]*)\s*=\s*["']([^"']+)["']/g,H;while((H=j.exec(z))!==null){let L=H[1],F=H[2];q[L]=YH(F,Y)}return await LQ(B,q,_,Y)});let Q=/<slot\s*(?:\/>|>([\s\S]*?)<\/slot>)/gi;return X=X.replace(Q,(G,K)=>{if(G.includes("name="))return G;let W=K?.trim()||"";return Z.default||W}),X}async function vE($,Z,Y){let X=[],J=[];$.replace(Z,(K,...W)=>{let U=W[W.length-2];return J.push({match:K,index:U}),X.push(Y(K,...W.slice(0,-2))),K});let Q=await Promise.all(X),G=$;for(let K=J.length-1;K>=0;K--){let{match:W,index:U}=J[K];G=G.slice(0,U)+Q[K]+G.slice(U+W.length)}return G}function XH($){let Z=OQ($);return{defaultSlot:Z.default,namedSlots:Z.named}}async function JH($,Z,Y,X){return await FQ($,{default:Z,named:Y},X)}var VQ=k(()=>{c0();d0()});import fE from"fs";import o from"path";function GH($){return $.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}function KH($){return/\bjs\b/.test($)||/\blang\s*=\s*["']?(js|javascript)["']?/i.test($)}function l$($){return!KH($)}function i$($){try{let Z=$.replace(/^\s*import\s+\w+\s+from\s+['"][^'"]*\.stx['"]\s*;?\s*$/gm,"");Z=Z.replace(/^\s*import\s+['"][^'"]*\.stx['"]\s*;?\s*$/gm,"");let Y=[];Z=Z.replace(/\{!![\s\S]*?!!\}/g,(Q)=>{let G=Y.length;return Y.push(Q),`"__STX_EXPR_${G}__"`}),Z=Z.replace(/\{\{\{[\s\S]*?\}\}\}/g,(Q)=>{let G=Y.length;return Y.push(Q),`"__STX_EXPR_${G}__"`}),Z=Z.replace(/\{\{[\s\S]*?\}\}/g,(Q)=>{let G=Y.length;return Y.push(Q),`"__STX_EXPR_${G}__"`});let J=new Bun.Transpiler({loader:"ts",target:"browser",define:T1()}).transformSync(Z);for(let Q=0;Q<Y.length;Q++)J=J.replace(`"__STX_EXPR_${Q}__"`,Y[Q]),J=J.replace(`'__STX_EXPR_${Q}__'`,Y[Q]);return J}catch(Z){if(process.env.STX_DEBUG_TS)console.warn("[STX] TypeScript transpilation error:",Z);return $}}function hE($){let Z=[],Y=new Set,X=0,J=0,Q=$.length,G=(B)=>{J++;while(J<Q){if($[J]==="\\"){J+=2;continue}if($[J]===B){J++;return}J++}},K=()=>{J++;while(J<Q){if($[J]==="\\"){J+=2;continue}if($[J]==="`"){J++;return}if($[J]==="$"&&$[J+1]==="{"){J+=2;let B=1;while(J<Q&&B>0)if($[J]==="{")B++,J++;else if($[J]==="}")B--,J++;else if($[J]==="'"||$[J]==='"')G($[J]);else if($[J]==="`")K();else J++;continue}J++}},W=()=>{if($[J]==="/"&&$[J+1]==="/"){while(J<Q&&$[J]!==`
|
|
13502
|
-
`)J++;return!0}if($[J]==="/"&&$[J+1]==="*"){J+=2;while(J<Q-1&&!($[J]==="*"&&$[J+1]==="/"))J++;return J+=2,!0}return!1},U=()=>{if(X!==0)return;let B=$.slice(J).match(/^(const|let|var)\s*\{([^}]+)\}\s*=/);if(B){let j=B[2].split(",").map((H)=>{let L=H.trim().split(":");return L[L.length-1].trim()});for(let H of j)if(H&&/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(H)&&!Y.has(H))Z.push(H),Y.add(H);return}let _=$.slice(J).match(/^(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=/);if(_){let j=_[2];if(!Y.has(j))Z.push(j),Y.add(j);return}let z=$.slice(J).match(/^function\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/);if(z){let j=z[1];if(!Y.has(j))Z.push(j),Y.add(j);return}let q=$.slice(J).match(/^async\s+function\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/);if(q){let j=q[1];if(!Y.has(j))Z.push(j),Y.add(j)}};while(J<Q){if(W())continue;if($[J]==="'"||$[J]==='"'){G($[J]);continue}if($[J]==="`"){K();continue}if($[J]==="{"){X++,J++;continue}if($[J]==="}"){X--,J++;continue}if(X===0&&/[a-z]/i.test($[J])&&(J===0||/\s|[;{}()]/.test($[J-1])))U();J++}return Z}function dE($){let Z=[],Y=0,X=0,J=null;for(let Q=0;Q<$.length;Q++){let G=$[Q];if(J){if(G==="\\"){Q++;continue}if(G===J)J=null;continue}if(G==='"'||G==="'"||G==="`"){J=G;continue}if(G==="("||G==="["||G==="{")Y++;else if(G===")"||G==="]"||G==="}")Y--;else if(G===","&&Y===0)Z.push($.slice(X,Q)),X=Q+1}if(X<$.length)Z.push($.slice(X));return Z}function uE($){let Z=0,Y=null;for(let X=0;X<$.length;X++){let J=$[X];if(Y){if(J==="\\"){X++;continue}if(J===Y)Y=null;continue}if(J==='"'||J==="'"||J==="`"){Y=J;continue}if(J==="("||J==="["||J==="{")Z++;else if(J===")"||J==="]"||J==="}")Z--;else if(J==="="&&Z===0){let Q=$[X-1],G=$[X+1];if(Q==="!"||Q==="<"||Q===">"||Q==="=")continue;if(G==="="||G===">")continue;return X}}return-1}function mE($,Z){try{let Y=/=\s*(?:withDefaults\s*\([\s\S]*?defineProps|defineProps)\b/.exec($);if(!Y)return;let X=Y.index-1;while(X>=0&&/\s/.test($[X]))X--;if($[X]!=="}")return;let J=X,Q=0,G=-1;for(;X>=0;X--){let W=$[X];if(W==="}")Q++;else if(W==="{"){if(Q--,Q===0){G=X;break}}}if(G===-1)return;let K=$.slice(G+1,J);for(let W of dE(K)){let U=W.trim();if(!U||U.startsWith("..."))continue;let B=uE(U);if(B===-1)continue;let _=U.slice(0,B).trim();if(!/^[A-Z_$][\w$]*$/i.test(_))continue;if(Z[_]!==void 0)continue;let z=U.slice(B+1).trim();if(!z)continue;try{let q=Object.keys(Z),j=Function(...q,`"use strict"; return (${z});`);Z[_]=j(...q.map((H)=>Z[H]))}catch{}}}catch{}}async function L9($,Z,Y,X,J){let Q=$.endsWith(".stx")?$.slice(0,-4):$,G=(L)=>L.split("-").map((F)=>F.charAt(0).toUpperCase()+F.slice(1)).join(""),K=(L)=>L.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),W=Y.__importedComponents;if(W){for(let L of[Q,Q.toLowerCase(),G(Q),K(Q)])if(W.has(L))return!0}let U=[...new Set([`${Q}.stx`,`${G(Q)}.stx`,`${K(Q)}.stx`])],B=typeof J.root==="string"?o.resolve(J.root):void 0,_=B??o.dirname(X),z=[],q=(L)=>{if(L&&!z.includes(L))z.push(L)},j=Y.__originalFilePath;if(j)q(o.join(o.dirname(j),"components"));q(Z),q(o.join(o.dirname(X),"components")),q(J.componentsDir);let H=J._pluginComponentDirs;if(Array.isArray(H))for(let L of H)q(typeof L==="string"?L:null);if(B)q(o.resolve(B,"resources/views/components")),q(o.resolve(B,"resources/components")),q(o.resolve(B,"src/components")),q(o.resolve(B,"components"));if(Q.startsWith("./")||Q.startsWith("../"))return e(o.resolve(o.dirname(X),`${Q}.stx`));for(let L of z){let F=o.isAbsolute(L)?L:o.resolve(_,L);for(let O of U)if(await e(o.join(F,O)))return!0}return!1}function WH($){return $==="visible"||$==="idle"||$==="interaction"||$.startsWith("media:")}async function D1($,Z,Y,X,J,Q,G,K=new Set,W){let{extractVariables:U}=await Promise.resolve().then(() => (p$(),LZ)),B=K??new Set;if(B.has($))return`[Circular component reference: ${$}]`;let _=new Set(B);_.add($);let z=typeof Z.client==="string"?Z.client.trim():"";if("client"in Z)delete Z.client;let q=z&&z!=="load"&&WH(z)?z:"";try{let j=(v)=>v.split("-").map((d)=>d.charAt(0).toUpperCase()+d.slice(1)).join(""),H=(v)=>v.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),L=$.endsWith(".stx")?$.slice(0,-4):$,F=null,O=J.__importedComponents;if(O){let v=[L,L.toLowerCase(),j(L),H(L)];for(let d of v)if(O.has(d)){F=O.get(d);break}}let V=[];if(!F){let v=[`${L}.stx`,`${j(L)}.stx`,`${H(L)}.stx`],d=[...new Set(v)],
|
|
13502
|
+
`)J++;return!0}if($[J]==="/"&&$[J+1]==="*"){J+=2;while(J<Q-1&&!($[J]==="*"&&$[J+1]==="/"))J++;return J+=2,!0}return!1},U=()=>{if(X!==0)return;let B=$.slice(J).match(/^(const|let|var)\s*\{([^}]+)\}\s*=/);if(B){let j=B[2].split(",").map((H)=>{let L=H.trim().split(":");return L[L.length-1].trim()});for(let H of j)if(H&&/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(H)&&!Y.has(H))Z.push(H),Y.add(H);return}let _=$.slice(J).match(/^(const|let|var)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*=/);if(_){let j=_[2];if(!Y.has(j))Z.push(j),Y.add(j);return}let z=$.slice(J).match(/^function\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/);if(z){let j=z[1];if(!Y.has(j))Z.push(j),Y.add(j);return}let q=$.slice(J).match(/^async\s+function\s+([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\(/);if(q){let j=q[1];if(!Y.has(j))Z.push(j),Y.add(j)}};while(J<Q){if(W())continue;if($[J]==="'"||$[J]==='"'){G($[J]);continue}if($[J]==="`"){K();continue}if($[J]==="{"){X++,J++;continue}if($[J]==="}"){X--,J++;continue}if(X===0&&/[a-z]/i.test($[J])&&(J===0||/\s|[;{}()]/.test($[J-1])))U();J++}return Z}function dE($){let Z=[],Y=0,X=0,J=null;for(let Q=0;Q<$.length;Q++){let G=$[Q];if(J){if(G==="\\"){Q++;continue}if(G===J)J=null;continue}if(G==='"'||G==="'"||G==="`"){J=G;continue}if(G==="("||G==="["||G==="{")Y++;else if(G===")"||G==="]"||G==="}")Y--;else if(G===","&&Y===0)Z.push($.slice(X,Q)),X=Q+1}if(X<$.length)Z.push($.slice(X));return Z}function uE($){let Z=0,Y=null;for(let X=0;X<$.length;X++){let J=$[X];if(Y){if(J==="\\"){X++;continue}if(J===Y)Y=null;continue}if(J==='"'||J==="'"||J==="`"){Y=J;continue}if(J==="("||J==="["||J==="{")Z++;else if(J===")"||J==="]"||J==="}")Z--;else if(J==="="&&Z===0){let Q=$[X-1],G=$[X+1];if(Q==="!"||Q==="<"||Q===">"||Q==="=")continue;if(G==="="||G===">")continue;return X}}return-1}function mE($,Z){try{let Y=/=\s*(?:withDefaults\s*\([\s\S]*?defineProps|defineProps)\b/.exec($);if(!Y)return;let X=Y.index-1;while(X>=0&&/\s/.test($[X]))X--;if($[X]!=="}")return;let J=X,Q=0,G=-1;for(;X>=0;X--){let W=$[X];if(W==="}")Q++;else if(W==="{"){if(Q--,Q===0){G=X;break}}}if(G===-1)return;let K=$.slice(G+1,J);for(let W of dE(K)){let U=W.trim();if(!U||U.startsWith("..."))continue;let B=uE(U);if(B===-1)continue;let _=U.slice(0,B).trim();if(!/^[A-Z_$][\w$]*$/i.test(_))continue;if(Z[_]!==void 0)continue;let z=U.slice(B+1).trim();if(!z)continue;try{let q=Object.keys(Z),j=Function(...q,`"use strict"; return (${z});`);Z[_]=j(...q.map((H)=>Z[H]))}catch{}}}catch{}}async function L9($,Z,Y,X,J){let Q=$.endsWith(".stx")?$.slice(0,-4):$,G=(L)=>L.split("-").map((F)=>F.charAt(0).toUpperCase()+F.slice(1)).join(""),K=(L)=>L.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),W=Y.__importedComponents;if(W){for(let L of[Q,Q.toLowerCase(),G(Q),K(Q)])if(W.has(L))return!0}let U=[...new Set([`${Q}.stx`,`${G(Q)}.stx`,`${K(Q)}.stx`])],B=typeof J.root==="string"?o.resolve(J.root):void 0,_=B??o.dirname(X),z=[],q=(L)=>{if(L&&!z.includes(L))z.push(L)},j=Y.__originalFilePath;if(j)q(o.join(o.dirname(j),"components"));q(Z),q(o.join(o.dirname(X),"components")),q(J.componentsDir);let H=J._pluginComponentDirs;if(Array.isArray(H))for(let L of H)q(typeof L==="string"?L:null);if(B)q(o.resolve(B,"resources/views/components")),q(o.resolve(B,"resources/components")),q(o.resolve(B,"src/components")),q(o.resolve(B,"components"));if(Q.startsWith("./")||Q.startsWith("../"))return e(o.resolve(o.dirname(X),`${Q}.stx`));for(let L of z){let F=o.isAbsolute(L)?L:o.resolve(_,L);for(let O of U)if(await e(o.join(F,O)))return!0}return!1}function WH($){return $==="visible"||$==="idle"||$==="interaction"||$.startsWith("media:")}async function D1($,Z,Y,X,J,Q,G,K=new Set,W){let{extractVariables:U}=await Promise.resolve().then(() => (p$(),LZ)),B=K??new Set;if(B.has($))return`[Circular component reference: ${$}]`;let _=new Set(B);_.add($);let z=typeof Z.client==="string"?Z.client.trim():"";if("client"in Z)delete Z.client;let q=z&&z!=="load"&&WH(z)?z:"";try{let j=(v)=>v.split("-").map((d)=>d.charAt(0).toUpperCase()+d.slice(1)).join(""),H=(v)=>v.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),L=$.endsWith(".stx")?$.slice(0,-4):$,F=null,O=J.__importedComponents;if(O){let v=[L,L.toLowerCase(),j(L),H(L)];for(let d of v)if(O.has(d)){F=O.get(d);break}}let V=[];if(!F){let v=[`${L}.stx`,`${j(L)}.stx`,`${H(L)}.stx`],d=[...new Set(v)],m=J.__originalFilePath,g=[];if(m){let W0=o.join(o.dirname(m),"components");g.push(W0)}if(X)g.push(X);let c=o.join(o.dirname(Q),"components");if(!g.includes(c))g.push(c);if(G.componentsDir&&G.componentsDir!==X&&!g.includes(G.componentsDir))g.push(G.componentsDir);let a=G._pluginComponentDirs;if(Array.isArray(a)){for(let W0 of a)if(typeof W0==="string"&&!g.includes(W0))g.push(W0)}let l=typeof G.root==="string"?o.resolve(G.root):void 0,Q0=l??o.dirname(Q),M0=[];if(l)M0.push(o.resolve(l,"resources/views/components")),M0.push(o.resolve(l,"resources/components")),M0.push(o.resolve(l,"src/components")),M0.push(o.resolve(l,"components"));M0.push(o.resolve(import.meta.dir,"components"));for(let W0 of M0)if(!g.includes(W0))g.push(W0);let w0=[...new Set(g.map((W0)=>{if(!W0)return W0;return o.isAbsolute(W0)?W0:o.resolve(Q0,W0)}))];if(g.length=0,g.push(...w0),L.startsWith("./")||L.startsWith("../"))F=o.resolve(o.dirname(Q),`${L}.stx`),V.push(F);else for(let W0 of g){if(!W0)continue;for(let o0 of d){let p0=o.join(W0,o0);if(V.push(p0),await e(p0)){F=p0;break}}if(F)break;if(!F)try{let o0=await import("fs");if(!o0.statSync(W0,{throwIfNoEntry:!1})?.isDirectory())continue;let u5=8,G0=[{path:W0,depth:0}];while(G0.length>0&&!F){let k0=G0.pop();if(k0.depth>=u5)continue;let H4;try{H4=o0.readdirSync(k0.path,{withFileTypes:!0})}catch{continue}for(let k1 of H4){if(!k1.isDirectory())continue;if(k1.name==="node_modules"||k1.name.startsWith("."))continue;let N$=o.join(k0.path,k1.name);for(let V0 of d){let $1=o.join(N$,V0);if(V.push($1),await e($1)){F=$1;break}}if(F)break;G0.push({path:N$,depth:k0.depth+1})}}}catch{}if(F)break}}if(!F||!await e(F)){let v=V.length>0?`
|
|
13503
13503
|
Searched paths:
|
|
13504
13504
|
${V.map((d)=>` - ${d}`).join(`
|
|
13505
|
-
`)}`:"";return`[Error loading component: ENOENT: no such file or directory, open '${$}']${v}`}W.add(F);let N;if(C6.has(F))N=C6.get(F);else try{N=await Bun.file(F).text(),C6.set(F,N)}catch(v){return`[Error loading component: ${v instanceof Error?v.message:String(v)}]`}let A=new Set(["__originalFilePath","__importedComponents"]),w={};for(let[v,d]of Object.entries(J))if(!v.startsWith("__")||A.has(v))w[v]=d;let R={...w,...Z,props:Z,slot:Y,__processedComponents:_,__sections:{}};mE(N,R);let M=N,T=M.match(/<template\b(?![^>]*\b(?:id|x-for|x-if|@for|@if|:for|:if)\s*=)[^>]*>([\s\S]*?)<\/template>/i);if(T)M=T[1].trim();let E=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,D=[...N.matchAll(E)],S=[];for(let v of D){let d=v[1]||"",
|
|
13506
|
-
`)}`}if(Y&&u.includes("{{ text || slot }}"))u=u.replace(/\{\{\s*text\s*\|\|\s*slot\s*\}\}/g,()=>Y);let{extractSlotContent:y,applySlots:h}=await Promise.resolve().then(() => (VQ(),QH)),{defaultSlot:
|
|
13505
|
+
`)}`:"";return`[Error loading component: ENOENT: no such file or directory, open '${$}']${v}`}W.add(F);let N;if(C6.has(F))N=C6.get(F);else try{N=await Bun.file(F).text(),C6.set(F,N)}catch(v){return`[Error loading component: ${v instanceof Error?v.message:String(v)}]`}let A=new Set(["__originalFilePath","__importedComponents"]),w={};for(let[v,d]of Object.entries(J))if(!v.startsWith("__")||A.has(v))w[v]=d;let R={...w,...Z,props:Z,slot:Y,__processedComponents:_,__sections:{}};mE(N,R);let M=N,T=M.match(/<template\b(?![^>]*\b(?:id|x-for|x-if|@for|@if|:for|:if)\s*=)[^>]*>([\s\S]*?)<\/template>/i);if(T)M=T[1].trim();let E=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,D=[...N.matchAll(E)],S=[];for(let v of D){let d=v[1]||"",m=v[2]||"",g=d.includes("server");if(l$(d)&&m.trim())m=i$(m);if(g&&m)try{await U(m,R,F)}catch(a){}if(!g){let a=m.replace(/^\s*const\s*\{[^}]+\}\s*=\s*window\.stx\s*;?\s*\n?/gm,"");if(a.includes("{{")&&a.includes("}}"))a=G1(a,R,F);let l=d.replace(/\s*\bts\b/g,"").replace(/\s*\blang\s*=\s*["']?(ts|typescript)["']?/gi,"");S.push(`<script${l}>${a}</script>`)}}let C=N.match(/<style\b([^>]*)>([\s\S]*?)<\/style>/i),P=C?C[1]:"",b=C?C[2]:"",x="",s=P&&/\bscoped\b/i.test(P);if(C)x=`<style${P}>${b}</style>`;let u=M;if(u=u.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,""),C)u=u.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"");{let v=/@push\s*\(\s*['"]styles['"]\s*\)([\s\S]*?)@endpush/gi,d=[];if(u=u.replace(v,(m,g)=>{let c=g.match(/<style\b([^>]*)>([\s\S]*?)<\/style>/i);if(c)d.push(`<style${c[1]}>${c[2]}</style>`);return""}),u=u.replace(/@push\s*\(\s*['"][^'"]+['"]\s*\)[\s\S]*?@endpush/gi,""),d.length>0)x=`${x}${d.join(`
|
|
13506
|
+
`)}`}if(Y&&u.includes("{{ text || slot }}"))u=u.replace(/\{\{\s*text\s*\|\|\s*slot\s*\}\}/g,()=>Y);let{extractSlotContent:y,applySlots:h}=await Promise.resolve().then(() => (VQ(),QH)),{defaultSlot:p,namedSlots:n}=y(Y);u=await h(u,p||Y,n,R);for(let[v,d]of Object.entries(R))if(typeof d==="string"){if(d.includes("<")&&d.includes(">")||d.includes("<")||d.includes(""")){let m=$8(d);R[v]=m}}let r=S.some((v)=>/\b(state|derived|effect)\s*(?:<[^<>()]*>)?\s*\(/.test(v)),K0={...G,componentsDir:o.dirname(F),skipSignalsRuntime:!0,skipEventDirectives:r,defaultLayout:void 0};R.__stxProcessingDepth=(J.__stxProcessingDepth||0)+1;let Z0=await X0(u,R,F,K0,W),F0=`stx_${L.replace(/[^a-zA-Z0-9]/g,"_")}_${++gE}_${Math.random().toString(36).slice(2,8)}`,R0=Z0;if(r){let v="";if(Object.keys(Z).length>0)try{v=` data-stx-props="${GH(JSON.stringify(Z))}"`}catch{}let d=q?` stx-hydrate="${GH(q)}"`:"";if(R0=`<div data-stx-scope="${F0}"${v}${d}>${Z0}</div>`,R0=S.map((g)=>{let c=g.match(/<script([^>]*)>([\s\S]*)<\/script>/i);if(!c)return g;let[,a,l]=c,Q0=J$(l),M0=`
|
|
13507
13507
|
(function() {
|
|
13508
13508
|
const { state, derived, effect, batch, defineEmits, defineExpose, defineSlots, defineProps, withDefaults, useStore, useFetch, useRef, useQuery, useMutation, useOptimistic, useDebounce, useDebouncedValue, useThrottle, useInterval, useTimeout, useToggle, useCounter, useClickOutside, useFocus, useAsync, useLocalStorage, useSessionStorage, useCookie, useReactiveProp, useEventListener, useWebSocket, useColorMode, useDark, useHead, useSeoMeta, definePageMeta, useRoute, useSearchParams, navigate, goBack, goForward, provide, inject, ref, reactive, computed, watch, watchEffect, nextTick } = window.stx;
|
|
13509
13509
|
const __scope = window.stx._scopes = window.stx._scopes || {};
|
|
@@ -13529,8 +13529,8 @@ catch (e) {}
|
|
|
13529
13529
|
`)+`
|
|
13530
13530
|
`+R0,x)R0+=`
|
|
13531
13531
|
`+x}else{if(x)R0+=`
|
|
13532
|
-
`+x;if(S.length>0){let v=R.__stx_event_bindings||[],d=a$(R),
|
|
13533
|
-
`+
|
|
13532
|
+
`+x;if(S.length>0){let v=R.__stx_event_bindings||[],d=a$(R),m=await Promise.all(S.map(async(g)=>{let c=g.match(/<script\b[^>]*>([\s\S]*?)<\/script>/);if(!c)return g;return await t$(c[1],{eventBindings:v,templateContent:R0,filePath:F,projectRoot:process.cwd(),serverData:d})}));R0+=`
|
|
13533
|
+
`+m.join(`
|
|
13534
13534
|
`),R.__stx_event_bindings=[]}}if(s){let v=H6(R0,F);if(v.hasScoped)R0=v.html}return R0}catch(j){return`[Error processing component: ${j instanceof Error?j.message:String(j)}]`}finally{B.delete($)}}async function e($){return Bun.file($).exists()}function NQ($,Z){let Y=o.resolve(Z),X=o.resolve($),J=Y.endsWith(o.sep)?Y:Y+o.sep;if(X===Y||X.startsWith(J))return X;return null}async function $6($,Z,Y,X){let J=await pE($,Z,Y,X);if(J===null)return null;let Q=NQ(J,process.cwd());if(Q)return Q;let G=[Y.root,Y.layoutsDir,Y.componentsDir,Y.partialsDir,Y.pagesDir].filter((K)=>typeof K==="string"&&K.length>0);for(let K of G){let W=o.isAbsolute(K)?K:o.resolve(process.cwd(),K);if(NQ(J,W))return o.resolve(J)}return console.warn(`[stx] rejected resolved template path that escapes project root: ${J} (template: ${$}, from: ${Z})`),null}async function pE($,Z,Y,X){if(Y.debug)console.log(`Resolving template path: ${$} from ${Z}`);let J=o.dirname(Z),Q=process.cwd();if($.startsWith("/")){let z=o.join(Q,$),q=NQ(z,Q);if(!q)return console.warn(`[stx] rejected template path that escapes project root: ${$} (from ${Z})`),null;if(Y.debug)console.log(`Checking absolute path: ${q}`);if(await e(q)&&X)X.add(q);return q}let G=o.join(J,$);if(await e(G)){if(Y.debug)console.log(`Found direct path: ${G}`);if(X)X.add(G);return G}if(!$.endsWith(".stx")&&!$.endsWith(".jsx")&&!$.endsWith(".tsx"))for(let z of[".stx",".tsx",".jsx"]){let q=`${G}${z}`;if(await e(q)){if(Y.debug)console.log(`Found direct path with extension: ${q}`);if(X)X.add(q);return q}}let K="",W=o.resolve(J),U=process.cwd();for(let z=0;z<10;z++){let q=o.join(W,"layouts"),j=!1;try{j=fE.statSync(q,{throwIfNoEntry:!1})?.isDirectory()??!1}catch{}if(j){K=q;break}let H=o.dirname(W);if(H===W||H.length<U.length)break;W=H}if(K){let z=$.startsWith("layouts/")?$.slice(8):$,q=o.join(K,z);if(await e(q)){if(Y.debug)console.log(`Found in current layouts dir: ${q}`);if(X)X.add(q);return q}if(!z.endsWith(".stx")){let j=`${q}.stx`;if(await e(j)){if(Y.debug)console.log(`Found in current layouts dir with extension: ${j}`);if(X)X.add(j);return j}}}if(Y.layoutsDir){let z=o.isAbsolute(Y.layoutsDir)?Y.layoutsDir:o.resolve(process.cwd(),Y.layoutsDir),q=$.startsWith("layouts/")?$.slice(8):$,j=o.join(z,q);if(await e(j)){if(Y.debug)console.log(`Found in options.layoutsDir: ${j}`);if(X)X.add(j);return j}if(!$.endsWith(".stx")){let H=`${j}.stx`;if(await e(H)){if(Y.debug)console.log(`Found in options.layoutsDir with extension: ${H}`);if(X)X.add(H);return H}}}if($.startsWith("layouts/")||$.includes("/layouts/")){let z=$.split("layouts/"),q=o.join(Y.partialsDir||J,"layouts",z[1]);if(await e(q)){if(Y.debug)console.log(`Found in layouts path: ${q}`);if(X)X.add(q);return q}if(!q.endsWith(".stx")){let j=`${q}.stx`;if(await e(j)){if(Y.debug)console.log(`Found in layouts path with extension: ${j}`);if(X)X.add(j);return j}}}if(Y.partialsDir){if(K=o.join(Y.partialsDir,"layouts"),await e(K)){let z=o.join(K,$);if(await e(z)){if(Y.debug)console.log(`Found in partials layouts dir: ${z}`);if(X)X.add(z);return z}if(!$.endsWith(".stx")){let q=`${z}.stx`;if(await e(q)){if(Y.debug)console.log(`Found in partials layouts dir with extension: ${q}`);if(X)X.add(q);return q}}}}let B=Y.partialsDir||o.join(process.cwd(),"views"),_=o.join(B,$);if(await e(_)){if(Y.debug)console.log(`Found in views path: ${_}`);if(X)X.add(_);return _}if(!$.endsWith(".stx")){let z=`${_}.stx`;if(await e(z)){if(Y.debug)console.log(`Found in views path with extension: ${z}`);if(X)X.add(z);return z}}if(J.includes("temp")){let z=o.join(o.dirname(J),"layouts",$);if(await e(z)){if(Y.debug)console.log(`Found in temp layouts dir: ${z}`);if(X)X.add(z);return z}if(!$.endsWith(".stx")){let q=`${z}.stx`;if(await e(q)){if(Y.debug)console.log(`Found in temp layouts dir with extension: ${q}`);if(X)X.add(q);return q}}}if(Y.debug)console.warn(`Template not found after trying all paths: ${$} (referenced from ${Z})`);else console.warn(`Template not found: ${$} (referenced from ${Z})`);return null}function AQ($,Z,Y){let X=0,J="",Q="";try{if(typeof Z==="number"&&Z>=0){let G=$.split(`
|
|
13535
13535
|
`),K=0;for(let W=0;W<G.length;W++)if(K+=G[W].length+1,K>=Z){X=W+1,J=G[W].trim();let U=Math.max(0,W-2),B=Math.min(G.length,W+3);Q=G.slice(U,B).map((_,z)=>{let q=U+z+1;return`${q===X?"> ":" "}${q}: ${_}`}).join(`
|
|
13536
13536
|
`);break}}else if(Y){let G=$.indexOf(Y);if(G>=0)return AQ($,G)}}catch{}return{lineNumber:X,lineContent:J,context:Q}}function L0($,Z,Y,X,J,Q){let{lineNumber:G,context:K}=AQ(X,J,Q),W=Y.split("/").pop(),U=0;if(typeof J==="number"&&J>=0&&X){let _=X.lastIndexOf(`
|
|
@@ -13829,10 +13829,10 @@ ${$.map((X)=>{let J=new URL(X.loc,Z).href,Q=` <url>
|
|
|
13829
13829
|
${Y.join(`
|
|
13830
13830
|
`)}
|
|
13831
13831
|
</channel>
|
|
13832
|
-
</rss>`}async function IH($={}){let Z=Date.now(),Y=await x0(),X={pagesDir:$.pagesDir||"pages",outputDir:$.outputDir||"dist",baseUrl:$.baseUrl||"/",domain:$.domain||"http://localhost",revalidate:$.revalidate??!1,sitemap:$.sitemap??!0,rss:$.rss??!1,concurrency:$.concurrency||10,cache:$.cache??!0,cacheDir:$.cacheDir||".stx/ssg-cache",contentLoaders:$.contentLoaders||[],hooks:$.hooks||{},minify:$.minify??!1,generate404:$.generate404??!0,publicDir:$.publicDir||"public",trailingSlash:$.trailingSlash??!1,cleanOutput:$.cleanOutput??!0,chunkIslands:$.chunkIslands===!0,prefetchIslands:$.prefetchIslands===!0,integrityIslands:$.integrityIslands===!0},J={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},Q=new Set,G=0,K={},W={};await X.hooks.onBuildStart?.();try{if(X.cleanOutput&&g0.existsSync(X.outputDir))await g0.promises.rm(X.outputDir,{recursive:!0});await g0.promises.mkdir(X.outputDir,{recursive:!0});let B=new RH(X.cacheDir);if(X.cache)await B.load();try{let{preloadIconCollection:V}=await Promise.resolve().then(() => (zZ(),e_));await V("lucide")}catch{}try{let{generateCrosswindCSS:V}=await Promise.resolve().then(() => (n1(),u8));await V('<div class="bg-black"></div>')}catch{}y6();let _=Y?.routeMiddleware?.dir||"middleware";await g6(process.cwd(),_);let z=f6();if(z.length>0)console.log(`Loaded ${z.length} middleware: ${z.join(", ")}`);let q=Y?.routeMiddleware?.global||[],j=z$(".",{pagesDir:X.pagesDir});console.log(`Found ${j.length} routes`);let H=[];for(let V of j){let N=await Jk(V);for(let A of N)H.push({route:V,url:A.url,params:A.params,props:A.props,revalidate:A.revalidate??X.revalidate})}J.totalPages=H.length,console.log(`Generating ${J.totalPages} pages...`);let L=[],F=[];for(let V=0;V<H.length;V+=X.concurrency)F.push(H.slice(V,V+X.concurrency));for(let V of F)await Promise.all(V.map(async(N)=>{let{route:A,url:w,params:R,props:M,revalidate:T}=N;try{await X.hooks.onPageStart?.(w);let E=await Bun.file(A.filePath).text(),D=_k(E),S=D?.middleware?Array.isArray(D.middleware)?D.middleware:[D.middleware]:[],C=[...q,...S];if(C.length>0){let y=v6(w,R,D||{}),h=x6(y,null),
|
|
13832
|
+
</rss>`}async function IH($={}){let Z=Date.now(),Y=await x0(),X={pagesDir:$.pagesDir||"pages",outputDir:$.outputDir||"dist",baseUrl:$.baseUrl||"/",domain:$.domain||"http://localhost",revalidate:$.revalidate??!1,sitemap:$.sitemap??!0,rss:$.rss??!1,concurrency:$.concurrency||10,cache:$.cache??!0,cacheDir:$.cacheDir||".stx/ssg-cache",contentLoaders:$.contentLoaders||[],hooks:$.hooks||{},minify:$.minify??!1,generate404:$.generate404??!0,publicDir:$.publicDir||"public",trailingSlash:$.trailingSlash??!1,cleanOutput:$.cleanOutput??!0,chunkIslands:$.chunkIslands===!0,prefetchIslands:$.prefetchIslands===!0,integrityIslands:$.integrityIslands===!0},J={totalPages:0,successCount:0,failedCount:0,cachedCount:0,buildTime:0,pages:[],errors:[]},Q=new Set,G=0,K={},W={};await X.hooks.onBuildStart?.();try{if(X.cleanOutput&&g0.existsSync(X.outputDir))await g0.promises.rm(X.outputDir,{recursive:!0});await g0.promises.mkdir(X.outputDir,{recursive:!0});let B=new RH(X.cacheDir);if(X.cache)await B.load();try{let{preloadIconCollection:V}=await Promise.resolve().then(() => (zZ(),e_));await V("lucide")}catch{}try{let{generateCrosswindCSS:V}=await Promise.resolve().then(() => (n1(),u8));await V('<div class="bg-black"></div>')}catch{}y6();let _=Y?.routeMiddleware?.dir||"middleware";await g6(process.cwd(),_);let z=f6();if(z.length>0)console.log(`Loaded ${z.length} middleware: ${z.join(", ")}`);let q=Y?.routeMiddleware?.global||[],j=z$(".",{pagesDir:X.pagesDir});console.log(`Found ${j.length} routes`);let H=[];for(let V of j){let N=await Jk(V);for(let A of N)H.push({route:V,url:A.url,params:A.params,props:A.props,revalidate:A.revalidate??X.revalidate})}J.totalPages=H.length,console.log(`Generating ${J.totalPages} pages...`);let L=[],F=[];for(let V=0;V<H.length;V+=X.concurrency)F.push(H.slice(V,V+X.concurrency));for(let V of F)await Promise.all(V.map(async(N)=>{let{route:A,url:w,params:R,props:M,revalidate:T}=N;try{await X.hooks.onPageStart?.(w);let E=await Bun.file(A.filePath).text(),D=_k(E),S=D?.middleware?Array.isArray(D.middleware)?D.middleware:[D.middleware]:[],C=[...q,...S];if(C.length>0){let y=v6(w,R,D||{}),h=x6(y,null),p=await h6(C,h);if(p.redirect){let n=typeof p.redirect==="string"?p.redirect:p.redirect.path||p.redirect,r=zk(String(n),w),K0=qk(w,X);await g0.promises.mkdir(O0.dirname(K0),{recursive:!0}),await Bun.write(K0,r),J.successCount++,J.pages.push({route:w,outputPath:K0,size:Buffer.byteLength(r),cached:!1}),L.push({loc:w,lastmod:new Date().toISOString()}),console.log(` \u21B3 ${w} \u2192 redirect to ${n}`);return}if(p.abort){let n=typeof p.abort==="string"?p.abort:p.abort?.error?.message||"aborted";console.warn(` \u21B3 ${w} \u2014 middleware aborted: ${n}`);return}}let P=E.match(/definePageMeta\s*\(\s*\{[\s\S]*?validate\s*:\s*((?:\([^)]*\)|[^,}])*(?:\{[\s\S]*?\})?)/m);if(P)try{if(!await Function("route",`
|
|
13833
13833
|
const validate = ${P[1]};
|
|
13834
13834
|
return validate(route);
|
|
13835
|
-
`)({params:R})){console.warn(`Validation failed for ${w}, skipping...`);return}}catch{}let b=null,x=!1;if(X.cache){if(b=B.get(w,A.filePath),b)x=!0,J.cachedCount++}if(!b){let y=await TH(A,R,M,X,Y);if(b=y.html,X.cache)B.set(w,A.filePath,y.dependencies,b)}let s;if(X.trailingSlash)s=O0.join(X.outputDir,w,"index.html");else s=w==="/"?O0.join(X.outputDir,"index.html"):O0.join(X.outputDir,`${w}.html`);if(X.chunkIslands){let{html:y,chunks:h}=NH(b,{integrity:X.integrityIslands,minify:X.minify});if(h.length>0){let
|
|
13835
|
+
`)({params:R})){console.warn(`Validation failed for ${w}, skipping...`);return}}catch{}let b=null,x=!1;if(X.cache){if(b=B.get(w,A.filePath),b)x=!0,J.cachedCount++}if(!b){let y=await TH(A,R,M,X,Y);if(b=y.html,X.cache)B.set(w,A.filePath,y.dependencies,b)}let s;if(X.trailingSlash)s=O0.join(X.outputDir,w,"index.html");else s=w==="/"?O0.join(X.outputDir,"index.html"):O0.join(X.outputDir,`${w}.html`);if(X.chunkIslands){let{html:y,chunks:h}=NH(b,{integrity:X.integrityIslands,minify:X.minify});if(h.length>0){let p=O0.join(X.outputDir,"_stx","islands");await g0.promises.mkdir(p,{recursive:!0});for(let n of h){let r=O0.join(p,`${n.hash}.js`);if(!await Bun.file(r).exists())await Bun.write(r,n.code);if(!Q.has(n.hash)){Q.add(n.hash);let K0=Buffer.byteLength(n.code,"utf8");G+=K0,K[n.hash]={bytes:K0,file:`/_stx/islands/${n.hash}.js`}}}if(W[w]=h.map((n)=>n.hash),b=y,X.prefetchIslands)b=AH(b)}}await g0.promises.mkdir(O0.dirname(s),{recursive:!0}),await Bun.write(s,b),L.push({loc:w,lastmod:new Date().toISOString().split("T")[0],priority:w==="/"?1:0.8});let u={route:w,outputPath:s,size:Buffer.byteLength(b,"utf8"),cached:x};if(T!==!1)u.revalidateAt=Date.now()+T*1000;J.pages.push(u),J.successCount++,await X.hooks.onPageEnd?.(w,b)}catch(E){J.failedCount++,J.errors.push({route:w,error:E}),await X.hooks.onError?.(E,w),console.error(`Error generating ${w}:`,E)}}));if(X.cache)await B.save();if(X.generate404){let V=O0.join(X.pagesDir,"404.stx");if(await Bun.file(V).exists()){let N=new Set,A={...Y,debug:!1,cache:!1},w=await X0(await Bun.file(V).text(),{},V,A,N);await Bun.write(O0.join(X.outputDir,"404.html"),w)}else await Bun.write(O0.join(X.outputDir,"404.html"),`<!DOCTYPE html>
|
|
13836
13836
|
<html lang="en">
|
|
13837
13837
|
<head>
|
|
13838
13838
|
<meta charset="UTF-8">
|
|
@@ -14884,12 +14884,12 @@ ${j.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});console.clear(),con
|
|
|
14884
14884
|
${I.blue}stx${I.reset} ${I.green}${process.env.stx_VERSION||"v0.0.10"}${I.reset} ${I.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${I.reset}`),console.log(`
|
|
14885
14885
|
${I.bright}\u2192 ${I.cyan}http://localhost:${B}/${I.reset}`),console.log(`
|
|
14886
14886
|
${I.yellow}Routes:${I.reset}`);let z=new Set(K.map((j)=>j.routeTemplate)),q=Object.entries(G).filter(([j])=>!z.has(j)).sort(([j],[H])=>j.localeCompare(H)).map(([j,H])=>({route:j==="/"?"/":j,filePath:e0.relative(process.cwd(),H.filePath),fileType:H.fileType}));for(let j of K){let H=j.routeTemplate.replace(/\[([^\]]+)\]/g,":$1");q.push({route:H,filePath:e0.relative(process.cwd(),j.filePath),fileType:"stx"})}if(q.sort((j,H)=>j.route.localeCompare(H.route)),q.forEach((j,H)=>{let F=H===q.length-1?"\u2514\u2500 ":"\u251C\u2500 ",O=j.fileType==="md"?`${I.magenta}(markdown)${I.reset}`:"";console.log(` ${I.green}${F}${j.route}${I.reset} \u2192 ${I.bright}${j.filePath}${I.reset} ${O}`)}),console.log(`
|
|
14887
|
-
Press ${I.cyan}h${I.reset} + ${I.cyan}Enter${I.reset} to show shortcuts`),Z5(_.url.toString(),()=>{if(X)X5.watch(Q,{recursive:!0}).close();_.stop()}),X){console.log(`${I.blue}Watching for changes...${I.reset}`);let j=X5.watch(Q,{recursive:!0},async(H,L)=>{if(!L)return;if(L.endsWith(".stx")||L.endsWith(".js")||L.endsWith(".ts")||L.endsWith(".md"))console.log(`${I.yellow}File ${I.bright}${L}${I.yellow} changed, rebuilding...${I.reset}`),c$.clear(),e$(),await W()});process.on("SIGINT",()=>{j.close(),_.stop(),process.exit(0)})}return!0}var RO=k(()=>{k7();s0();d7();qY();N0();p6()});var{serve:ck}=globalThis.Bun;import z1 from"fs";import H0 from"path";function nQ($){let Z=Bun.file($),Y=H0.extname($).toLowerCase(),X={".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"},Q=[".js",".css",".json"].includes(Y)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(Z,{headers:{"Content-Type":X[Y]||"application/octet-stream",...Q}})}async function MO($=".",Z={}){let Y=Z.port||3000,X=Z.watch!==!1,J=Z.hotReload!==!1&&X,Q=null,G=Z.hmrPort||Y+1,K=H0.resolve($),{loadStxConfig:W}=await Promise.resolve().then(() => (Y5(),P5)),U=await W(K),B=U.root&&U.root!=="."?H0.join(K,U.root):K,_=U.pagesDir||"pages",z=H0.join(B,_);if(!z1.existsSync(z))return console.error(`${I.red}Error: No '${_}' directory found in ${I.bright}${B}${I.reset}`),console.log(`${I.dim}Create a ${_}/ directory with .stx files to define your routes.${I.reset}`),console.log(`${I.dim}Example: ${_}/index.stx for the homepage.${I.reset}`),!1;let q=z$(B);if(q.length===0)return console.error(`${I.red}Error: No page files found in ${I.bright}${z}${I.reset}`),!1;console.log(`${I.blue}Found ${I.bright}${q.length}${I.blue} routes${I.reset}`);let j=U?._pluginPageDirs||[],H=[];for(let{dir:y,prefix:h}of j)if(z1.existsSync(y)){let m=z$(H0.dirname(y),{pagesDir:H0.basename(y)});for(let n of m){let r=h==="/"?n.pattern:`${h}${n.pattern==="/"?"":n.pattern}`;H.push({route:{...n,pattern:r},prefix:h})}if(m.length>0)console.log(`${I.blue}Plugin pages: ${I.bright}${m.length}${I.blue} routes at ${I.cyan}${h}${I.reset}`)}let L=new Map,F=null,O=null;if(Z.stxOptions?.shell!==!1){if(O=await sQ(K,Z.stxOptions?.shell),O){if(F=await jY(O,Z.stxOptions||{}),F)console.log(`${I.blue}Using app shell: ${I.bright}${H0.relative(K,O)}${I.reset} ${I.dim}(deprecated: use layouts/default.stx instead)${I.reset}`)}}y6(),await g6(K);let V=f6();if(V.length>0)console.log(`${I.blue}Loaded ${I.bright}${V.length}${I.blue} middleware: ${I.dim}${V.join(", ")}${I.reset}`);let N={},A=null;try{let{loadStxConfig:y}=await Promise.resolve().then(() => (Y5(),P5)),h=await y(K);if(h?.apiRouter)A=h?.apiRouter,console.log(`${I.blue}Using custom router for API handling${I.reset}`);if(h?.apiRoutes){N=h.apiRoutes;let m=Object.keys(N).length;if(m>0)console.log(`${I.blue}Loaded ${I.bright}${m} API route${m>1?"s":""}${I.reset}`)}if(h?.broadcasting?.enabled)try{let{startBroadcasting:m,loadChannels:n}=await Promise.resolve().then(() => (GY(),dQ)),r=h.broadcasting;await m(r);let K0=r.port??6001;console.log(`${I.magenta}Broadcasting on ${I.cyan}ws://localhost:${K0}/ws${I.reset}`);let Z0=H0.join(process.cwd(),"channels.ts");if(z1.existsSync(Z0))try{let F0=await n(Z0);console.log(`${I.blue}Loaded ${I.bright}${F0} broadcast channel${F0!==1?"s":""}${I.blue} from channels.ts${I.reset}`)}catch(F0){console.warn(`${I.yellow}Failed to load channels.ts: ${F0.message}${I.reset}`)}}catch(m){console.warn(`${I.yellow}Broadcasting failed to start: ${m.message}${I.reset}`)}}catch{}let w=H0.join(K,".stx/output");z1.mkdirSync(w,{recursive:!0});let R=new Map,M=new Set,T=async(y)=>{let h=MQ(z,y);if(!h)return null;try{let m=await Bun.build({entrypoints:[h],outdir:w,plugins:[C5],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...Z.stxOptions});if(!m.success)return null;let n=m.outputs.find((r)=>r.path.endsWith(".html"));if(!n)return null;return await Bun.file(n.path).text()}catch{return null}},E=async(y,h)=>{try{let{processDirectives:m,extractVariables:n,defaultConfig:r,loadStxConfig:K0,injectRouterScript:Z0}=await Promise.resolve().then(() => (Y5(),P5)),{checkCache:F0,cacheTemplate:R0,readFileCached:v,templateCache:d}=await Promise.resolve().then(() => (E5(),c7)),p=await K0(K),g=(V0)=>{if(!V0)return V0;if(H0.isAbsolute(V0))return V0;return H0.resolve(K,V0)},c={...r,...p,...Z.stxOptions,autoShell:!0};if(Z.debugDirectives)c.debug=!0;c.partialsDir=g(c.partialsDir),c.componentsDir=g(c.componentsDir),c.layoutsDir=g(c.layoutsDir),c.storesDir=g(c.storesDir||"stores"),c.cachePath=g(c.cachePath||".stx/cache");let a=!h&&!Z.profile,l=c.cache!==!1;if(l&&a){let V0=d.get(y.filePath);if(V0)try{if((await z1.promises.stat(y.filePath)).mtime.getTime()<=V0.mtime){let A$=!0;for(let Z1 of V0.dependencies){if(!z1.existsSync(Z1)){A$=!1;break}if((await z1.promises.stat(Z1)).mtime.getTime()>V0.mtime){A$=!1;break}}if(A$){let Z1=V0.output;if(F)Z1=j$(Z1,{preserveHead:!0});return{route:y,content:Z1}}}}catch{}let $1=await F0(y.filePath,c);if($1){let S1=$1;if(F)S1=j$(S1,{preserveHead:!0});return{route:y,content:S1}}}let Q0=l?await v(y.filePath):await Bun.file(y.filePath).text(),{classifyAllScripts:M0}=await Promise.resolve().then(() => (Y5(),P5)),w0=M0(Q0),W0=w0.server.map((V0)=>V0.content),o0=Q0;for(let V0 of w0.server)o0=o0.replace(V0.fullTag,"");let p0={__filename:y.filePath,__dirname:H0.dirname(y.filePath),params:h??{}},{resetHead:u5}=await Promise.resolve().then(() => (f$(),$Z));u5();for(let V0 of W0)try{await n(V0,p0,y.filePath)}catch($1){if(Z.stxOptions?.debug)console.error("[stx] variable extraction error",y.filePath,$1?.message||$1)}let G0=new Set,k0;if(Z.profile){let V0=performance.now();k0=await m(o0,p0,y.filePath,c,G0);let $1=performance.now()-V0,S1=H0.relative(K,y.filePath)||y.filePath;console.log(`[stx:profile] ${S1} \u2192 ${$1.toFixed(2)}ms`)}else k0=await m(o0,p0,y.filePath,c,G0);if(!F)k0=await Z0(k0);{let{interpolateScriptExpressions:V0}=await Promise.resolve().then(() => (c0(),b4));k0=k0.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,($1,S1,A$)=>{if(!/function\s+__stx_setup_/.test(A$))return $1;return`<script${S1}>${V0(A$,p0)}</script>`})}if(F)k0=j$(k0,{preserveHead:!0});if(l&&a)await R0(y.filePath,k0,G0,c);let{extractStreamBoundaries:H4}=await Promise.resolve().then(() => (h$(),A5)),k1=H4(p0),N$=p0.__streamTemplates;if(N$&&typeof N$==="object"&&Object.keys(N$).length>0){let V0=p0.streamBoundaries||{},$1={...c,autoShell:!1},S1=Object.keys(N$).map((Z1)=>({id:Z1,render:async()=>{let fK=typeof V0[Z1]==="function"?await V0[Z1]():void 0;return m(N$[Z1],{...p0,$boundary:fK},y.filePath,$1,new Set)}})),A$=new Set(S1.map((Z1)=>Z1.id));k1=[...(k1||[]).filter((Z1)=>!A$.has(Z1.id)),...S1]}if(k1&&k1.length>0)M.add(y.pattern);else k1=void 0;return{route:y,content:k0,boundaries:k1}}catch(m){return console.error(`${I.red}Error building ${I.bright}${y.pattern}${I.reset}:`,m),null}},D=8,S=async()=>{R.clear(),L.clear();for(let y=0;y<q.length;y+=D){let h=q.slice(y,y+D),m=await Promise.all(h.map((n)=>E(n)));for(let n of m)if(n)R.set(n.route.pattern,n)}for(let y=0;y<H.length;y+=D){let h=H.slice(y,y+D),m=await Promise.all(h.map(({route:n})=>E(n)));for(let n of m)if(n)L.set(n.route.pattern,n)}return R.size>0};if(console.log(`${I.blue}Building pages...${I.reset}`),!await S())return console.error(`${I.red}No pages were successfully built${I.reset}`),!1;await D7(K);let P=Y;try{if(P=await q$(Y),P!==Y)console.log(`${I.yellow}Port ${Y} is busy, using port ${P} instead${I.reset}`)}catch{return console.error(`${I.red}Could not find an available port${I.reset}`),!1}if(J){let y=Z.hmrPort||P+1;Q=n6({wsPort:y,verbose:!1}),G=Q.start(y)}let b=(y,h)=>{let m=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._rp=${JSON.stringify(h)};if(s.setRouteParams)s.setRouteParams(s._rp);})()</script>`;if(y.includes("</head>"))return y.replace("</head>",`${m}</head>`);if(y.includes("<body"))return y.replace(/<body([^>]*)>/,`<body$1>${m}`);return m+y};console.log(`${I.blue}Starting server...${I.reset}`);let x=ck({port:P,async fetch(y){let h=new URL(y.url),m=U?.publicDir||"public",n=H0.join(K,m,h.pathname),r=H0.join(K,h.pathname),K0=H0.join(w,h.pathname),[Z0,F0,R0]=await Promise.all([z1.promises.stat(n).catch(()=>null),z1.promises.stat(r).catch(()=>null),z1.promises.stat(K0).catch(()=>null)]);if(Z0?.isFile())return nQ(n);if(F0?.isFile())return nQ(r);if(R0?.isFile())return nQ(K0);if(h.pathname.startsWith("/_stx/component/")){let g=decodeURIComponent(h.pathname.slice(16));if(g)try{let c=`<${g} />`,a={...buildConfig,autoShell:!1},l=await processDirectives(c,{},H0.join(K,"components",`${g}.stx`),a,new Set);return new Response(l,{headers:{"Content-Type":"text/html"}})}catch(c){return new Response(`<div class="stx-async-error">${c.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(h.pathname==="/_stx/img"){let{handleImageRequest:g}=await Promise.resolve().then(() => (zX(),UW)),c=await g(y,{publicDir:H0.join(K,m),cacheDir:H0.join(K,".stx/cache/img")});if(c)return c}if(A)try{let g=await A.handleRequest(y);if(g.status!==404)return g}catch{}if(N[h.pathname])try{return await N[h.pathname](y)}catch(g){return new Response(JSON.stringify({error:g.message}),{status:500,headers:{"Content-Type":"application/json"}})}let v=YY(h.pathname,q);if(v){let g=R.get(v.route.pattern),c=M.has(v.route.pattern);if(v.route.isDynamic&&Object.keys(v.params).length>0||c){let a=await E(v.route,v.params);if(a)g=a}if(g){let a=e8();if(a.validate){if(!await a.validate({params:v.params})){let M0=await T(404);if(M0){let w0=M0;if(w0=await T0(w0,K),J)w0=a1(w0,G);return new Response(w0,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(a.middleware){let Q0=v6(h.pathname,v.params,a,h.search),M0=x6(Q0,null,y),w0=await h6(a.middleware,M0);if(w0.redirect){let W0=w0.redirect.path,o0=w0.redirect.options.redirectCode||302,p0=new Headers(w0.responseHeaders);return p0.set("Location",W0),new Response(null,{status:o0,headers:p0})}if(w0.abort){let{statusCode:W0,message:o0}=w0.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${W0}</title></head><body><h1>Error ${W0}</h1><p>${o0}</p></body></html>`,{status:W0,headers:{"Content-Type":"text/html"}})}if(Object.keys(w0.state).length>0){let W0=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(w0.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;g.content=g.content.replace("</head>",`${W0}</head>`)}}let l=g.content;if(F&&rQ(y)){let Q0=o6(l);if(Object.keys(v.params).length>0)l=b(l,v.params);l=await T0(l,K);let M0=U?.router?.container||"main";return l=u6(l,M0),new Response(l,{headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Q0.layout,"X-STX-Layout-Group":Q0.group,"Cache-Control":"no-store, no-cache, must-revalidate"}})}if(F)l=r6(F,l);if(Object.keys(v.params).length>0)l=b(l,v.params);if(l=await T0(l,K),J)l=a1(l,G);if(Z.native)if(l.includes("<head>"))l=l.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 l="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+l;if(Z.titlebarHidden)if(l.includes("<head>"))l=l.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 l=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${l}`;if(g.boundaries&&g.boundaries.length>0){let{renderStreamingPage:Q0,streamToResponse:M0}=await Promise.resolve().then(() => (h$(),A5));return M0(Q0(l,g.boundaries,{timeoutMs:30000}),{headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(l,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}if(H.length>0){let g=H.map((a)=>a.route),c=YY(h.pathname,g);if(c){let a=L.get(c.route.pattern);if(a){let l=a.content;if(F)l=r6(F,l);if(Object.keys(c.params).length>0)l=b(l,c.params);if(l=await T0(l,K),J)l=a1(l,G);return new Response(l,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:a}of j)if(a!=="/"&&h.pathname.startsWith(a)){let l=L.get(a)||L.get(a+"/");if(l){let Q0=l.content;if(F)Q0=r6(F,Q0);if(Q0=await T0(Q0,K),J)Q0=a1(Q0,G);return new Response(Q0,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}let d=R.get("/");if(d){let g=d.content;if(g=await T0(g,K),J)g=a1(g,G);if(Z.native)if(g.includes("<head>"))g=g.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 g="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+g;return new Response(g,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let p=await T(404);if(p){let g=p;if(g=await T0(g,K),J)g=a1(g,G);return new Response(g,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(y){let h=await T(500);if(h)return new Response(h,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${y}
|
|
14887
|
+
Press ${I.cyan}h${I.reset} + ${I.cyan}Enter${I.reset} to show shortcuts`),Z5(_.url.toString(),()=>{if(X)X5.watch(Q,{recursive:!0}).close();_.stop()}),X){console.log(`${I.blue}Watching for changes...${I.reset}`);let j=X5.watch(Q,{recursive:!0},async(H,L)=>{if(!L)return;if(L.endsWith(".stx")||L.endsWith(".js")||L.endsWith(".ts")||L.endsWith(".md"))console.log(`${I.yellow}File ${I.bright}${L}${I.yellow} changed, rebuilding...${I.reset}`),c$.clear(),e$(),await W()});process.on("SIGINT",()=>{j.close(),_.stop(),process.exit(0)})}return!0}var RO=k(()=>{k7();s0();d7();qY();N0();p6()});var{serve:ck}=globalThis.Bun;import z1 from"fs";import H0 from"path";function nQ($){let Z=Bun.file($),Y=H0.extname($).toLowerCase(),X={".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"},Q=[".js",".css",".json"].includes(Y)?{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}:{};return new Response(Z,{headers:{"Content-Type":X[Y]||"application/octet-stream",...Q}})}async function MO($=".",Z={}){let Y=Z.port||3000,X=Z.watch!==!1,J=Z.hotReload!==!1&&X,Q=null,G=Z.hmrPort||Y+1,K=H0.resolve($),{loadStxConfig:W}=await Promise.resolve().then(() => (Y5(),P5)),U=await W(K),B=U.root&&U.root!=="."?H0.join(K,U.root):K,_=U.pagesDir||"pages",z=H0.join(B,_);if(!z1.existsSync(z))return console.error(`${I.red}Error: No '${_}' directory found in ${I.bright}${B}${I.reset}`),console.log(`${I.dim}Create a ${_}/ directory with .stx files to define your routes.${I.reset}`),console.log(`${I.dim}Example: ${_}/index.stx for the homepage.${I.reset}`),!1;let q=z$(B);if(q.length===0)return console.error(`${I.red}Error: No page files found in ${I.bright}${z}${I.reset}`),!1;console.log(`${I.blue}Found ${I.bright}${q.length}${I.blue} routes${I.reset}`);let j=U?._pluginPageDirs||[],H=[];for(let{dir:y,prefix:h}of j)if(z1.existsSync(y)){let p=z$(H0.dirname(y),{pagesDir:H0.basename(y)});for(let n of p){let r=h==="/"?n.pattern:`${h}${n.pattern==="/"?"":n.pattern}`;H.push({route:{...n,pattern:r},prefix:h})}if(p.length>0)console.log(`${I.blue}Plugin pages: ${I.bright}${p.length}${I.blue} routes at ${I.cyan}${h}${I.reset}`)}let L=new Map,F=null,O=null;if(Z.stxOptions?.shell!==!1){if(O=await sQ(K,Z.stxOptions?.shell),O){if(F=await jY(O,Z.stxOptions||{}),F)console.log(`${I.blue}Using app shell: ${I.bright}${H0.relative(K,O)}${I.reset} ${I.dim}(deprecated: use layouts/default.stx instead)${I.reset}`)}}y6(),await g6(K);let V=f6();if(V.length>0)console.log(`${I.blue}Loaded ${I.bright}${V.length}${I.blue} middleware: ${I.dim}${V.join(", ")}${I.reset}`);let N={},A=null;try{let{loadStxConfig:y}=await Promise.resolve().then(() => (Y5(),P5)),h=await y(K);if(h?.apiRouter)A=h?.apiRouter,console.log(`${I.blue}Using custom router for API handling${I.reset}`);if(h?.apiRoutes){N=h.apiRoutes;let p=Object.keys(N).length;if(p>0)console.log(`${I.blue}Loaded ${I.bright}${p} API route${p>1?"s":""}${I.reset}`)}if(h?.broadcasting?.enabled)try{let{startBroadcasting:p,loadChannels:n}=await Promise.resolve().then(() => (GY(),dQ)),r=h.broadcasting;await p(r);let K0=r.port??6001;console.log(`${I.magenta}Broadcasting on ${I.cyan}ws://localhost:${K0}/ws${I.reset}`);let Z0=H0.join(process.cwd(),"channels.ts");if(z1.existsSync(Z0))try{let F0=await n(Z0);console.log(`${I.blue}Loaded ${I.bright}${F0} broadcast channel${F0!==1?"s":""}${I.blue} from channels.ts${I.reset}`)}catch(F0){console.warn(`${I.yellow}Failed to load channels.ts: ${F0.message}${I.reset}`)}}catch(p){console.warn(`${I.yellow}Broadcasting failed to start: ${p.message}${I.reset}`)}}catch{}let w=H0.join(K,".stx/output");z1.mkdirSync(w,{recursive:!0});let R=new Map,M=new Set,T=async(y)=>{let h=MQ(z,y);if(!h)return null;try{let p=await Bun.build({entrypoints:[h],outdir:w,plugins:[C5],publicPath:"/",define:{"process.env.NODE_ENV":'"development"'},...Z.stxOptions});if(!p.success)return null;let n=p.outputs.find((r)=>r.path.endsWith(".html"));if(!n)return null;return await Bun.file(n.path).text()}catch{return null}},E=async(y,h)=>{try{let{processDirectives:p,extractVariables:n,defaultConfig:r,loadStxConfig:K0,injectRouterScript:Z0}=await Promise.resolve().then(() => (Y5(),P5)),{checkCache:F0,cacheTemplate:R0,readFileCached:v,templateCache:d}=await Promise.resolve().then(() => (E5(),c7)),m=await K0(K),g=(V0)=>{if(!V0)return V0;if(H0.isAbsolute(V0))return V0;return H0.resolve(K,V0)},c={...r,...m,...Z.stxOptions,autoShell:!0};if(Z.debugDirectives)c.debug=!0;c.partialsDir=g(c.partialsDir),c.componentsDir=g(c.componentsDir),c.layoutsDir=g(c.layoutsDir),c.storesDir=g(c.storesDir||"stores"),c.cachePath=g(c.cachePath||".stx/cache");let a=!h&&!Z.profile,l=c.cache!==!1;if(l&&a){let V0=d.get(y.filePath);if(V0)try{if((await z1.promises.stat(y.filePath)).mtime.getTime()<=V0.mtime){let A$=!0;for(let Z1 of V0.dependencies){if(!z1.existsSync(Z1)){A$=!1;break}if((await z1.promises.stat(Z1)).mtime.getTime()>V0.mtime){A$=!1;break}}if(A$){let Z1=V0.output;if(F)Z1=j$(Z1,{preserveHead:!0});return{route:y,content:Z1}}}}catch{}let $1=await F0(y.filePath,c);if($1){let S1=$1;if(F)S1=j$(S1,{preserveHead:!0});return{route:y,content:S1}}}let Q0=l?await v(y.filePath):await Bun.file(y.filePath).text(),{classifyAllScripts:M0}=await Promise.resolve().then(() => (Y5(),P5)),w0=M0(Q0),W0=w0.server.map((V0)=>V0.content),o0=Q0;for(let V0 of w0.server)o0=o0.replace(V0.fullTag,"");let p0={__filename:y.filePath,__dirname:H0.dirname(y.filePath),params:h??{}},{resetHead:u5}=await Promise.resolve().then(() => (f$(),$Z));u5();for(let V0 of W0)try{await n(V0,p0,y.filePath)}catch($1){if(Z.stxOptions?.debug)console.error("[stx] variable extraction error",y.filePath,$1?.message||$1)}let G0=new Set,k0;if(Z.profile){let V0=performance.now();k0=await p(o0,p0,y.filePath,c,G0);let $1=performance.now()-V0,S1=H0.relative(K,y.filePath)||y.filePath;console.log(`[stx:profile] ${S1} \u2192 ${$1.toFixed(2)}ms`)}else k0=await p(o0,p0,y.filePath,c,G0);if(!F)k0=await Z0(k0);{let{interpolateScriptExpressions:V0}=await Promise.resolve().then(() => (c0(),b4));k0=k0.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/g,($1,S1,A$)=>{if(!/function\s+__stx_setup_/.test(A$))return $1;return`<script${S1}>${V0(A$,p0)}</script>`})}if(F)k0=j$(k0,{preserveHead:!0});if(l&&a)await R0(y.filePath,k0,G0,c);let{extractStreamBoundaries:H4}=await Promise.resolve().then(() => (h$(),A5)),k1=H4(p0),N$=p0.__streamTemplates;if(N$&&typeof N$==="object"&&Object.keys(N$).length>0){let V0=p0.streamBoundaries||{},$1={...c,autoShell:!1},S1=Object.keys(N$).map((Z1)=>({id:Z1,render:async()=>{let fK=typeof V0[Z1]==="function"?await V0[Z1]():void 0;return p(N$[Z1],{...p0,$boundary:fK},y.filePath,$1,new Set)}})),A$=new Set(S1.map((Z1)=>Z1.id));k1=[...(k1||[]).filter((Z1)=>!A$.has(Z1.id)),...S1]}if(k1&&k1.length>0)M.add(y.pattern);else k1=void 0;return{route:y,content:k0,boundaries:k1}}catch(p){return console.error(`${I.red}Error building ${I.bright}${y.pattern}${I.reset}:`,p),null}},D=8,S=async()=>{R.clear(),L.clear();for(let y=0;y<q.length;y+=D){let h=q.slice(y,y+D),p=await Promise.all(h.map((n)=>E(n)));for(let n of p)if(n)R.set(n.route.pattern,n)}for(let y=0;y<H.length;y+=D){let h=H.slice(y,y+D),p=await Promise.all(h.map(({route:n})=>E(n)));for(let n of p)if(n)L.set(n.route.pattern,n)}return R.size>0};if(console.log(`${I.blue}Building pages...${I.reset}`),!await S())return console.error(`${I.red}No pages were successfully built${I.reset}`),!1;await D7(K);let P=Y;try{if(P=await q$(Y),P!==Y)console.log(`${I.yellow}Port ${Y} is busy, using port ${P} instead${I.reset}`)}catch{return console.error(`${I.red}Could not find an available port${I.reset}`),!1}if(J){let y=Z.hmrPort||P+1;Q=n6({wsPort:y,verbose:!1}),G=Q.start(y)}let b=(y,h)=>{let p=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._rp=${JSON.stringify(h)};if(s.setRouteParams)s.setRouteParams(s._rp);})()</script>`;if(y.includes("</head>"))return y.replace("</head>",`${p}</head>`);if(y.includes("<body"))return y.replace(/<body([^>]*)>/,`<body$1>${p}`);return p+y};console.log(`${I.blue}Starting server...${I.reset}`);let x=ck({port:P,async fetch(y){let h=new URL(y.url),p=U?.publicDir||"public",n=H0.join(K,p,h.pathname),r=H0.join(K,h.pathname),K0=H0.join(w,h.pathname),[Z0,F0,R0]=await Promise.all([z1.promises.stat(n).catch(()=>null),z1.promises.stat(r).catch(()=>null),z1.promises.stat(K0).catch(()=>null)]);if(Z0?.isFile())return nQ(n);if(F0?.isFile())return nQ(r);if(R0?.isFile())return nQ(K0);if(h.pathname.startsWith("/_stx/component/")){let g=decodeURIComponent(h.pathname.slice(16));if(g)try{let c=`<${g} />`,a={...buildConfig,autoShell:!1},l=await processDirectives(c,{},H0.join(K,"components",`${g}.stx`),a,new Set);return new Response(l,{headers:{"Content-Type":"text/html"}})}catch(c){return new Response(`<div class="stx-async-error">${c.message}</div>`,{status:500,headers:{"Content-Type":"text/html"}})}}if(h.pathname==="/_stx/img"){let{handleImageRequest:g}=await Promise.resolve().then(() => (zX(),UW)),c=await g(y,{publicDir:H0.join(K,p),cacheDir:H0.join(K,".stx/cache/img")});if(c)return c}if(A)try{let g=await A.handleRequest(y);if(g.status!==404)return g}catch{}if(N[h.pathname])try{return await N[h.pathname](y)}catch(g){return new Response(JSON.stringify({error:g.message}),{status:500,headers:{"Content-Type":"application/json"}})}let v=YY(h.pathname,q);if(v){let g=R.get(v.route.pattern),c=M.has(v.route.pattern);if(v.route.isDynamic&&Object.keys(v.params).length>0||c){let a=await E(v.route,v.params);if(a)g=a}if(g){let a=e8();if(a.validate){if(!await a.validate({params:v.params})){let M0=await T(404);if(M0){let w0=M0;if(w0=await T0(w0,K),J)w0=a1(w0,G);return new Response(w0,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}}if(a.middleware){let Q0=v6(h.pathname,v.params,a,h.search),M0=x6(Q0,null,y),w0=await h6(a.middleware,M0);if(w0.redirect){let W0=w0.redirect.path,o0=w0.redirect.options.redirectCode||302,p0=new Headers(w0.responseHeaders);return p0.set("Location",W0),new Response(null,{status:o0,headers:p0})}if(w0.abort){let{statusCode:W0,message:o0}=w0.abort.error;return new Response(`<!DOCTYPE html><html><head><title>Error ${W0}</title></head><body><h1>Error ${W0}</h1><p>${o0}</p></body></html>`,{status:W0,headers:{"Content-Type":"text/html"}})}if(Object.keys(w0.state).length>0){let W0=`<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(w0.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;g.content=g.content.replace("</head>",`${W0}</head>`)}}let l=g.content;if(F&&rQ(y)){let Q0=o6(l);if(Object.keys(v.params).length>0)l=b(l,v.params);l=await T0(l,K);let M0=U?.router?.container||"main";return l=u6(l,M0),new Response(l,{headers:{"Content-Type":"text/html","X-STX-Fragment":"true","X-STX-Layout":Q0.layout,"X-STX-Layout-Group":Q0.group,"Cache-Control":"no-store, no-cache, must-revalidate"}})}if(F)l=r6(F,l);if(Object.keys(v.params).length>0)l=b(l,v.params);if(l=await T0(l,K),J)l=a1(l,G);if(Z.native)if(l.includes("<head>"))l=l.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 l="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+l;if(Z.titlebarHidden)if(l.includes("<head>"))l=l.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 l=`<head><style>html.stx-titlebar-hidden .stx-traffic-lights-dot{visibility:hidden}</style><script>document.documentElement.classList.add('stx-titlebar-hidden')</script></head>${l}`;if(g.boundaries&&g.boundaries.length>0){let{renderStreamingPage:Q0,streamToResponse:M0}=await Promise.resolve().then(() => (h$(),A5));return M0(Q0(l,g.boundaries,{timeoutMs:30000}),{headers:{"Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}return new Response(l,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}if(H.length>0){let g=H.map((a)=>a.route),c=YY(h.pathname,g);if(c){let a=L.get(c.route.pattern);if(a){let l=a.content;if(F)l=r6(F,l);if(Object.keys(c.params).length>0)l=b(l,c.params);if(l=await T0(l,K),J)l=a1(l,G);return new Response(l,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}for(let{prefix:a}of j)if(a!=="/"&&h.pathname.startsWith(a)){let l=L.get(a)||L.get(a+"/");if(l){let Q0=l.content;if(F)Q0=r6(F,Q0);if(Q0=await T0(Q0,K),J)Q0=a1(Q0,G);return new Response(Q0,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}}}let d=R.get("/");if(d){let g=d.content;if(g=await T0(g,K),J)g=a1(g,G);if(Z.native)if(g.includes("<head>"))g=g.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 g="<head><style>[data-stx-sidebar],.stx-sidebar{display:none!important}</style><script>window.__craftNativeSidebar=true;document.documentElement.classList.add('has-native-sidebar')</script></head>"+g;return new Response(g,{headers:{"Content-Type":"text/html","Cache-Control":"no-store, no-cache, must-revalidate",Pragma:"no-cache",Expires:"0"}})}let m=await T(404);if(m){let g=m;if(g=await T0(g,K),J)g=a1(g,G);return new Response(g,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})},async error(y){let h=await T(500);if(h)return new Response(h,{status:500,headers:{"Content-Type":"text/html"}});return new Response(`<pre>${y}
|
|
14888
14888
|
${y.stack}</pre>`,{headers:{"Content-Type":"text/html"}})}});if(console.clear(),console.log(`
|
|
14889
14889
|
${I.blue}stx${I.reset} ${I.green}${process.env.stx_VERSION||"v0.0.10"}${I.reset} ${I.dim}ready in ${Math.random()*10+5|0}.${Math.random()*90+10|0} ms${I.reset}`),console.log(`
|
|
14890
14890
|
${I.bright}\u2192 ${I.cyan}http://localhost:${P}/${I.reset}`),J)console.log(`${I.dim} HMR: ws://localhost:${G}${I.reset}`);console.log(`
|
|
14891
14891
|
${I.yellow}Routes:${I.reset}`);let u=[...TQ(q,K)];for(let{route:y}of H)u.push(`${y.pattern}`);if(u.forEach((y,h)=>{let n=h===u.length-1?"\u2514\u2500 ":"\u251C\u2500 ";console.log(` ${I.green}${n}${I.reset}${y}`)}),console.log(`
|
|
14892
|
-
Press ${I.cyan}h${I.reset} + ${I.cyan}Enter${I.reset} to show shortcuts`),Z5(x.url.toString(),()=>{if(Q)Z4();x.stop()}),Z.native){let y,h=H0.join(z,"index.stx");if(z1.existsSync(h)){let n=await Bun.file(h).text();y=_Y(n)}let
|
|
14892
|
+
Press ${I.cyan}h${I.reset} + ${I.cyan}Enter${I.reset} to show shortcuts`),Z5(x.url.toString(),()=>{if(Q)Z4();x.stop()}),Z.native){let y,h=H0.join(z,"index.stx");if(z1.existsSync(h)){let n=await Bun.file(h).text();y=_Y(n)}let p=U?.app?.window??{};await t7(P,{title:U?.app?.head?.title||H0.basename(K)||"stx App",width:p.width,height:p.height,darkMode:p.darkMode,hotReload:p.hotReload,titlebarHidden:p.titlebarHidden??Z.titlebarHidden===!0,nativeSidebar:!!y,sidebarConfig:y})}if(X){console.log(`${I.blue}Watching for changes...${I.reset}`);let y=(n)=>{return n.startsWith("public/")||n.startsWith("public\\")},h=(n)=>{let r=n.toLowerCase();return r.endsWith(".stx")||r.endsWith(".html")||r.endsWith(".md")},p=z1.watch(K,{recursive:!0},async(n,r)=>{if(!r||i6(r))return;if(l6(r))if(y(r)){if(console.log(`${I.cyan}${r} changed${I.reset}`),J&&Q)Q.reload(r)}else if(h(r)){console.log(`${I.yellow}${r} changed, rebuilding...${I.reset}`),c$.clear(),e$();try{let{invalidateFileCache:K0,templateCache:Z0}=await Promise.resolve().then(() => (E5(),c7));K0(H0.resolve(K,r)),Z0.delete(H0.resolve(K,r))}catch{}if(O&&r){if(H0.resolve(K,r)===O||H0.basename(O)===r){let Z0=await jY(O,Z.stxOptions||{});if(Z0)F=Z0}}if(await S(),await Y6(K),J&&Q)Q.reload(r)}else{console.log(`${I.yellow}${r} changed, rebuilding...${I.reset}`),c$.clear(),e$();try{let{invalidateFileCache:K0,templateCache:Z0}=await Promise.resolve().then(() => (E5(),c7));K0(H0.resolve(K,r)),Z0.delete(H0.resolve(K,r))}catch{}if(await S(),J&&Q)Q.reload(r)}else if(c6(r)){if(console.log(`${I.cyan}CSS ${r} changed${I.reset}`),J&&Q)Q.updateCss(r)}});process.on("SIGINT",()=>{if(p.close(),Q)Z4();x.stop(),process.exit(0)})}return!0}var TO=k(()=>{o7();d7();qY();d6();$Y();f$();N0();p6()});var IO=k(()=>{pQ();AO();RO();TO()});import oQ from"fs";import a6 from"path";async function EO($){try{let Y=(await Bun.file($).text()).match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!Y)return[];let X=Y[1],J=[],Q=/\/\*\*\s*([\s\S]*?)\s*\*\/\s*(?:(?:const|let|var)\s*)?(?:([\w$]+)\s*=|module\.exports\.([\w$]+)\s*=|\s*([\w$]+)\s*:)/g,G;while((G=Q.exec(X))!==null){let K=G[1],W=G[2]||G[3]||G[4];if(!W)continue;let U={name:W},B=K.match(/@type\s+\{([^}]+)\}/i);if(B)U.type=B[1].trim();if(K.match(/@required/i))U.required=!0;let z=K.match(/@default\s+(.+?)(?:\s+|$)/i);if(z)U.default=z[1].trim();let q=K.split(`
|
|
14893
14893
|
`).map((j)=>j.trim().replace(/^\*\s*/,"")).filter((j)=>!j.startsWith("@")&&j.length>0);U.description=q.join(" ").trim(),J.push(U)}if(J.length===0){let K=X.match(/module\.exports\s*=\s*\{([^}]+)\}/i);if(K){let U=K[1].split(",").map((B)=>B.trim()).filter(Boolean);for(let B of U){let[_]=B.split(":").map((z)=>z.trim());if(_)J.push({name:_})}}}return J}catch(Z){return console.error(`Error extracting props from ${$}:`,Z),[]}}async function DO($){try{let Z=await Bun.file($).text(),Y=Z.match(/^\s*<!--\s*([\s\S]*?)\s*-->/)||Z.match(/^\s*\/\*\*\s*([\s\S]*?)\s*\*\//);if(Y)return Y[1].split(`
|
|
14894
14894
|
`).map((X)=>X.trim().replace(/^\*\s*/,"")).join(" ").trim();return""}catch{return""}}async function kO($,Z=!1,Y){let X=a6.basename($,".stx"),J=await EO($),Q=await DO($),G="";if(Z&&Y)G=`<${Y}></${Y}>`;else{let K=J.map((W)=>{if(W.type==="boolean")return`:${W.name}="true"`;return`${W.name}="value"`}).join(`
|
|
14895
14895
|
`);G=`<${X}
|
|
@@ -16032,7 +16032,7 @@ describe('Example', () => {
|
|
|
16032
16032
|
</footer>
|
|
16033
16033
|
@yield('scripts')
|
|
16034
16034
|
</body>
|
|
16035
|
-
</html>`}function kb(){return"<!-- Hero section -->"}function Sb(){return"<!-- Features -->"}function bb(){return"<!-- Pricing -->"}function Cb(){return"<!-- Button -->"}function J3($){if(!X3($))JG($,{recursive:!0})}function Pb(){if(X3("bun.lockb"))return"bun";if(X3("pnpm-lock.yaml"))return"pnpm";if(X3("yarn.lock"))return"yarn";return"bun"}function QG($){return $.replace(/[-_\s]+(.)?/g,(Z,Y)=>Y?Y.toUpperCase():"").replace(/^./,(Z)=>Z.toUpperCase())}function yb($){return $.replace(/[-_\s]+(.)?/g,(Z,Y)=>Y?Y.toUpperCase():"").replace(/^./,(Z)=>Z.toLowerCase())}function x5($){return $.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}var oS;var FL=k(()=>{oS={default:{description:"Standard stx project with pages, components, and stores",features:["Pages","Components","Layouts","Stores","Dev server"]},minimal:{description:"Minimal setup with just the essentials",features:["Single page","Basic styles"]},full:{description:"Full-featured project with all stx capabilities",features:["Pages","Components","Layouts","Stores","API routes","PWA","i18n","Testing"]},blog:{description:"Blog template with markdown support",features:["Blog layout","Post pages","Tags","RSS feed","Markdown"]},dashboard:{description:"Admin dashboard template",features:["Sidebar","Charts","Tables","Forms","Auth pages"]},landing:{description:"Marketing landing page template",features:["Hero section","Features","Pricing","CTA","Contact form"]}}});var{serve:xb}=globalThis.Bun;import Q3 from"fs";import K5 from"path";function vb($,Z=200,Y={}){return new Response($,{status:Z,headers:{"Content-Type":"text/html; charset=utf-8",...Y}})}async function VL($={}){let{port:Z=3000,root:Y=".",stxOptions:X={},watch:J=!0,onRequest:Q,routes:G={},middleware:K=[],on404:W,onError:U}=$,B=K5.resolve(Y),_=new Map;async function z(O){let V=Q3.statSync(O),N=`${O}:${V.mtimeMs}`,A=_.get(N);if(A)return A.content;for(let y of _.keys())if(y.startsWith(`${O}:`)&&y!==N)_.delete(y);let w=await Bun.file(O).text(),R=w,M=w.match(/<template\b(?![^>]*\b(?:id|x-for|x-if|@for|@if|:for|:if)\s*=)[^>]*>/i);if(M&&M.index!==void 0){let y=M.index+M[0].length,h=1,
|
|
16035
|
+
</html>`}function kb(){return"<!-- Hero section -->"}function Sb(){return"<!-- Features -->"}function bb(){return"<!-- Pricing -->"}function Cb(){return"<!-- Button -->"}function J3($){if(!X3($))JG($,{recursive:!0})}function Pb(){if(X3("bun.lockb"))return"bun";if(X3("pnpm-lock.yaml"))return"pnpm";if(X3("yarn.lock"))return"yarn";return"bun"}function QG($){return $.replace(/[-_\s]+(.)?/g,(Z,Y)=>Y?Y.toUpperCase():"").replace(/^./,(Z)=>Z.toUpperCase())}function yb($){return $.replace(/[-_\s]+(.)?/g,(Z,Y)=>Y?Y.toUpperCase():"").replace(/^./,(Z)=>Z.toLowerCase())}function x5($){return $.replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase()}var oS;var FL=k(()=>{oS={default:{description:"Standard stx project with pages, components, and stores",features:["Pages","Components","Layouts","Stores","Dev server"]},minimal:{description:"Minimal setup with just the essentials",features:["Single page","Basic styles"]},full:{description:"Full-featured project with all stx capabilities",features:["Pages","Components","Layouts","Stores","API routes","PWA","i18n","Testing"]},blog:{description:"Blog template with markdown support",features:["Blog layout","Post pages","Tags","RSS feed","Markdown"]},dashboard:{description:"Admin dashboard template",features:["Sidebar","Charts","Tables","Forms","Auth pages"]},landing:{description:"Marketing landing page template",features:["Hero section","Features","Pricing","CTA","Contact form"]}}});var{serve:xb}=globalThis.Bun;import Q3 from"fs";import K5 from"path";function vb($,Z=200,Y={}){return new Response($,{status:Z,headers:{"Content-Type":"text/html; charset=utf-8",...Y}})}async function VL($={}){let{port:Z=3000,root:Y=".",stxOptions:X={},watch:J=!0,onRequest:Q,routes:G={},middleware:K=[],on404:W,onError:U}=$,B=K5.resolve(Y),_=new Map;async function z(O){let V=Q3.statSync(O),N=`${O}:${V.mtimeMs}`,A=_.get(N);if(A)return A.content;for(let y of _.keys())if(y.startsWith(`${O}:`)&&y!==N)_.delete(y);let w=await Bun.file(O).text(),R=w,M=w.match(/<template\b(?![^>]*\b(?:id|x-for|x-if|@for|@if|:for|:if)\s*=)[^>]*>/i);if(M&&M.index!==void 0){let y=M.index+M[0].length,h=1,p=y;while(p<w.length&&h>0){let n=w.indexOf("<template",p),r=w.indexOf("</template>",p);if(r===-1)break;if(n!==-1&&n<r)h++,p=n+9;else{if(h--,h===0){R=w.substring(y,r).trim();break}p=r+11}}}let T=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,E=[],D=[],S;while((S=T.exec(w))!==null){let y=S[1],h=S[2],p=S[0];if(y.includes("server"))D.push(h);else E.push(p)}let C=w.match(/<style\b[^>]*>[\s\S]*?<\/style>/gi)||[],P=R.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,""),b={__filename:O,__dirname:K5.dirname(O)};for(let y of D)await D0(y,b,O);let u=await X0(P,b,O,X,new Set);if(C.length>0){let y=C.join(`
|
|
16036
16036
|
`);if(u.match(/(<\/head>)/i))u=u.replace(/(<\/head>)/i,`${y}
|
|
16037
16037
|
$1`)}if(E.length>0){let{interpolateScriptsInTemplate:y}=await Promise.resolve().then(() => (c0(),b4)),h=y(E.join(`
|
|
16038
16038
|
`),b);if(u.match(/(<\/body>)/i))u=u.replace(/(<\/body>)/i,`${h}
|