@stacksjs/stx 0.2.683 → 0.2.685

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.
Files changed (110) hide show
  1. package/dist/{chunk-d2nkm1jt.js → chunk-01bd9hrj.js} +1 -1
  2. package/dist/{chunk-q7z1ybcn.js → chunk-244tyyhx.js} +8 -8
  3. package/dist/{chunk-w28wc7mv.js → chunk-3tp7r57c.js} +4 -4
  4. package/dist/chunk-42c308vk.js +2 -0
  5. package/dist/{chunk-px9p7q26.js → chunk-4ht54p3j.js} +5 -5
  6. package/dist/{chunk-840aejkc.js → chunk-4k3jx9mm.js} +11 -11
  7. package/dist/{chunk-xv8yy1cz.js → chunk-4r8c96a0.js} +27 -27
  8. package/dist/{chunk-kbt9r41q.js → chunk-4rj9746b.js} +3 -3
  9. package/dist/{chunk-zt5hp5w5.js → chunk-5t9ndqfm.js} +1 -1
  10. package/dist/{chunk-1y50gat7.js → chunk-5tbey00z.js} +2 -2
  11. package/dist/chunk-6nhsvb9x.js +2 -0
  12. package/dist/{chunk-j87n6mh0.js → chunk-6qn368e7.js} +2 -2
  13. package/dist/{chunk-5wpny9k3.js → chunk-6zzg889q.js} +1 -1
  14. package/dist/{chunk-js8ytnrn.js → chunk-718rkxa7.js} +1 -1
  15. package/dist/{chunk-2rvprm39.js → chunk-7grjwpdq.js} +1 -1
  16. package/dist/{chunk-drd4t5v4.js → chunk-7st0prz9.js} +6 -6
  17. package/dist/{chunk-gny4j06b.js → chunk-8x34g2ad.js} +1 -1
  18. package/dist/chunk-9rv27cdd.js +2 -0
  19. package/dist/{chunk-cfbev664.js → chunk-9wd31tc6.js} +1 -1
  20. package/dist/{chunk-1dbw2j4q.js → chunk-9xp9hs7t.js} +1 -1
  21. package/dist/chunk-a1r3jbt4.js +2 -0
  22. package/dist/chunk-bhm9sdnv.js +2 -0
  23. package/dist/{chunk-kbagpk8a.js → chunk-bnggav14.js} +1 -1
  24. package/dist/chunk-bpk0qy53.js +2 -0
  25. package/dist/{chunk-jg4932ma.js → chunk-bxr4c8rg.js} +1 -1
  26. package/dist/{chunk-2ar5g9pa.js → chunk-bz3zn6f7.js} +2 -2
  27. package/dist/{chunk-hm69jxmh.js → chunk-cjf01cp4.js} +3 -3
  28. package/dist/{chunk-aenajaxk.js → chunk-cnvwrv5a.js} +1 -1
  29. package/dist/{chunk-w1wzydvp.js → chunk-ct0ee0fr.js} +3 -3
  30. package/dist/chunk-cxvka6g3.js +2 -0
  31. package/dist/{chunk-t257ye4c.js → chunk-d0g4zndy.js} +2 -2
  32. package/dist/{chunk-8jxqg7kb.js → chunk-dpghx4z6.js} +1 -1
  33. package/dist/{chunk-thkw9ez9.js → chunk-e5kz0y03.js} +7 -7
  34. package/dist/{chunk-cd6s5k6e.js → chunk-eykbcntx.js} +1 -1
  35. package/dist/{chunk-3353tc28.js → chunk-f5s2h2y8.js} +1 -1
  36. package/dist/{chunk-t0644y3k.js → chunk-fb84n8kz.js} +3 -3
  37. package/dist/{chunk-246k73ga.js → chunk-fbdmsw5j.js} +1 -1
  38. package/dist/chunk-fzfa35ft.js +2 -0
  39. package/dist/{chunk-xjx1xbey.js → chunk-gccwjjzw.js} +1 -1
  40. package/dist/{chunk-bsvwzma0.js → chunk-gn98ha90.js} +1 -1
  41. package/dist/{chunk-56w1njc8.js → chunk-gwqw8r2e.js} +1 -1
  42. package/dist/chunk-hqj28381.js +3 -0
  43. package/dist/chunk-jmjjjgy4.js +2 -0
  44. package/dist/{chunk-3vgfwsft.js → chunk-jrche9k7.js} +1 -1
  45. package/dist/{chunk-0t65m9nw.js → chunk-jsac71cy.js} +1 -1
  46. package/dist/{chunk-ff3d0eh9.js → chunk-kgcwx6nt.js} +1 -1
  47. package/dist/{chunk-yfr4tsn1.js → chunk-km6ggz8n.js} +1 -1
  48. package/dist/chunk-kxqvfdm9.js +2 -0
  49. package/dist/{chunk-gymmbbzc.js → chunk-kypwg2ws.js} +21 -9
  50. package/dist/chunk-m1cwgzqy.js +2 -0
  51. package/dist/{chunk-sme7phry.js → chunk-mf8yzpyy.js} +1 -1
  52. package/dist/{chunk-pvn0fc7j.js → chunk-mkaw0bn4.js} +1 -1
  53. package/dist/chunk-mn9xw0fe.js +2 -0
  54. package/dist/{chunk-zj5x4yk2.js → chunk-mxbp4vyy.js} +2 -2
  55. package/dist/{chunk-yrq24gyy.js → chunk-nqvex98n.js} +3 -3
  56. package/dist/{chunk-kq8t4xn9.js → chunk-nsvnxkyb.js} +2 -2
  57. package/dist/{chunk-zx468wjw.js → chunk-ppxfsqwh.js} +1 -1
  58. package/dist/{chunk-tkypg1xx.js → chunk-px7ryjd9.js} +1 -1
  59. package/dist/{chunk-smdxvjhn.js → chunk-qgs69nds.js} +3 -3
  60. package/dist/{chunk-551vqymy.js → chunk-qjmvcqfh.js} +1 -1
  61. package/dist/{chunk-qjccq0yd.js → chunk-qz314za9.js} +3 -3
  62. package/dist/{chunk-nbjyed3q.js → chunk-r7csb300.js} +1 -1
  63. package/dist/{chunk-d4f6dkrt.js → chunk-r8cn9qhr.js} +2 -2
  64. package/dist/chunk-sy19th0w.js +2 -0
  65. package/dist/{chunk-qq40hxg9.js → chunk-t3e5tv4h.js} +36 -36
  66. package/dist/chunk-t8djd28a.js +2 -0
  67. package/dist/chunk-tfhhxpda.js +2 -0
  68. package/dist/chunk-v3mmxk1y.js +2 -0
  69. package/dist/{chunk-7fgsqs43.js → chunk-w3q5czk5.js} +2 -2
  70. package/dist/{chunk-3waphqhe.js → chunk-w6frg42f.js} +1 -1
  71. package/dist/{chunk-2a1eeywj.js → chunk-wt6f9pk9.js} +1 -1
  72. package/dist/chunk-x519ewtq.js +2 -0
  73. package/dist/chunk-xe40yhcw.js +2 -0
  74. package/dist/chunk-xpch3mq8.js +2 -0
  75. package/dist/chunk-xs8228sa.js +2 -0
  76. package/dist/{chunk-jkywbfb0.js → chunk-yft8yn6y.js} +2 -2
  77. package/dist/chunk-yhba2f9d.js +2 -0
  78. package/dist/{chunk-qpvasda5.js → chunk-zf6kmw9q.js} +1 -1
  79. package/dist/{chunk-0h22d9cb.js → chunk-zhcb33s1.js} +1 -1
  80. package/dist/cli.js +8 -8
  81. package/dist/craft-entry.js +2 -2
  82. package/dist/craft.js +2 -2
  83. package/dist/dev-server/serve-app.js +34 -10
  84. package/dist/dev-server/types.d.ts +2 -0
  85. package/dist/dev-server/types.js +2 -0
  86. package/dist/pwa.js +1 -1
  87. package/dist/ssg.js +4 -4
  88. package/package.json +5 -5
  89. package/dist/chunk-29c177cz.js +0 -2
  90. package/dist/chunk-6rrr362d.js +0 -2
  91. package/dist/chunk-70fdw728.js +0 -2
  92. package/dist/chunk-8bwa63m3.js +0 -2
  93. package/dist/chunk-8s10jjf1.js +0 -2
  94. package/dist/chunk-979g7g0r.js +0 -2
  95. package/dist/chunk-bpf3xxng.js +0 -3
  96. package/dist/chunk-c3dqsjv0.js +0 -2
  97. package/dist/chunk-e1fgpb46.js +0 -2
  98. package/dist/chunk-g93jkztp.js +0 -2
  99. package/dist/chunk-hfk17t81.js +0 -2
  100. package/dist/chunk-jf717wps.js +0 -2
  101. package/dist/chunk-mjqf15e7.js +0 -2
  102. package/dist/chunk-p1a6y65v.js +0 -2
  103. package/dist/chunk-p21prjzh.js +0 -2
  104. package/dist/chunk-pqg3ghvh.js +0 -2
  105. package/dist/chunk-sk2ae1qj.js +0 -2
  106. package/dist/chunk-tq2m6m3j.js +0 -2
  107. package/dist/chunk-wbn3x66p.js +0 -2
  108. package/dist/chunk-yq9dtdkn.js +0 -2
  109. package/dist/chunk-yxy3brpr.js +0 -2
  110. package/dist/chunk-z9xhpkn6.js +0 -2
@@ -1,6 +1,6 @@
1
1
  // @bun
2
- import{gc,mc}from"./chunk-gtktv6nn.js";import{j,cs,ls,us,To,$o,ar,Ie,de,K,ps,oe,X,H,et,lr,Io,pr,je,n,d,V,mn}from"./chunk-qq40hxg9.js";import{p,E,tt,u}from"./chunk-w28wc7mv.js";import{re}from"./chunk-2a1eeywj.js";import{r}from"./chunk-9tg4995v.js";import{f}from"./chunk-b7e07ybq.js";import{createHash as Ct}from"crypto";import ee from"fs";import Q from"path";import{decode as sn,generateThumbHash as on}from"ts-images";import{createImageDeliveryCatalog as yt}from"ts-images/delivery";import Te from"fs";function Ce(e,t,s){let i=Buffer.alloc(s),o=Te.readSync(e,i,0,s,t);return i.subarray(0,o)}function De(e){if(e.length<25)return!1;let t=(i,o)=>String.fromCharCode(...e.subarray(i,o));if(t(0,4)!=="RIFF"||t(8,12)!=="WEBP")return!1;let s=t(12,16);if(s==="VP8X")return(e[20]&16)!==0;if(s==="VP8L")return((e[21]|e[22]<<8|e[23]<<16|e[24]<<24)>>>28&1)===1;return!1}function Me(e){let t;try{t=Te.openSync(e,"r");let s=Ce(t,0,33);if(s.length>=3&&s[0]===255&&s[1]===216&&s[2]===255)return"none";if(s.length>=26&&s[0]===137&&s.toString("latin1",1,4)==="PNG"){let i=s[25];if(i===4||i===6)return"possible";let o=8;for(let a=0;a<64;a++){let c=Ce(t,o,8);if(c.length<8)return"unknown";let g=c.toString("latin1",4,8);if(g==="tRNS")return"possible";if(g==="IDAT"||g==="IEND")return"none";o+=12+c.readUInt32BE(0)}return"unknown"}if(s.length>=25&&s.toString("latin1",0,4)==="RIFF"&&s.toString("latin1",8,12)==="WEBP"){if(De(s))return"possible";let i=s.toString("latin1",12,16);return i==="VP8 "||i==="VP8X"?"none":"unknown"}return"unknown"}catch{return"unknown"}finally{if(t!==void 0)Te.closeSync(t)}}import Jt from"fs";import Re from"os";import{join as dt}from"path";import{fileURLToPath as gt}from"url";import{Worker as mt}from"worker_threads";var ke=Symbol("stx.image-worker.unavailable");function Yt(e=typeof Re.availableParallelism==="function"?Re.availableParallelism():Re.cpus().length){return Math.max(1,Math.min(2,e-1))}var Ae=0,ht=[];async function Qt(){if(Ae<Yt()){Ae++;return}await new Promise((e)=>ht.push(e)),Ae++}function en(){Ae--,ht.shift()?.()}var tn="@stacksjs/stx/builtins/image-warmup-worker";function nn(e=process.cwd()){let t=import.meta.url.endsWith(".ts")?"ts":"js";try{let s=new URL(`./image-warmup-worker.${t}`,import.meta.url);if(s.protocol==="file:"&&Jt.existsSync(gt(s)))return gt(s)}catch{}try{let s=typeof Bun<"u"?Bun.resolveSync(tn,e):void 0;return s&&rn(s)?s:void 0}catch{return}}function rn(e,t=process.env){let s=e.replace(/\\/g,"/");if(s.split("/").some((o)=>/@\d[^/]*@@@\d+$/.test(o)))return!1;return![t.BUN_INSTALL_CACHE_DIR,dt(t.BUN_INSTALL||dt(Re.homedir(),".bun"),"install","cache")].filter((o)=>!!o).map((o)=>`${o.replace(/\\/g,"/").replace(/\/$/,"")}/`).some((o)=>s.startsWith(o))}var pt=!1;function pe(e){if(!pt)pt=!0,console.warn(`[stx] image worker unavailable (${e}); running the image pass on the serving thread instead. Results are the same, but requests may stall while it runs.`);return ke}function Le(e){return e instanceof Error?e.message:String(e)}async function ze(e,t){if(typeof mt!=="function")return pe("node:worker_threads has no Worker in this runtime");let s=nn();if(!s)return pe("no image-warmup-worker entry beside this module or in the installed @stacksjs/stx");await Qt();try{return await new Promise((i,o)=>{let a;try{a=new mt(s)}catch(h){i(pe(`could not start ${s}: ${Le(h)}`));return}let c=!1,g=!1,l=(h)=>{if(g)return;g=!0,h(),a.terminate()};a.on("message",(h)=>{if(h.type==="ready"){c=!0,a.postMessage({task:e,args:t});return}if(h.type==="result"){l(()=>i(h.value));return}let v=Error(h.error?.message??"image worker failed");if(h.error?.name)v.name=h.error.name;if(h.error?.stack)v.stack=h.error.stack;l(()=>o(v))}),a.on("error",(h)=>{l(()=>c?o(h instanceof Error?h:Error(Le(h)||"image worker crashed")):i(pe(`the worker failed before it was ready: ${Le(h)}`)))}),a.on("exit",(h)=>{l(()=>c?o(Error("image worker exited before it finished")):i(pe(`the worker exited with code ${h} before it was ready`)))})})}finally{en()}}var an=new Set([".avif",".jpeg",".jpg",".png",".webp"]),cn=[320,640,960,1280,1920],he="/_stx/images",ln=`stx:${he}:alpha-1`,un=`stx:${he}:opaque-1`,fn=["@stacksjs/ts-webp","@stacksjs/ts-avif","ts-images"],Pe;function dn(e,t){let s=Q.dirname(Bun.resolveSync(e,t));while(s!==Q.dirname(s)){let i=Q.join(s,"package.json");if(ee.existsSync(i)){let o=JSON.parse(ee.readFileSync(i,"utf8"));if(o.name===e)return o.version}s=Q.dirname(s)}return}function xt(){if(Pe!==void 0)return Pe;let e;try{e=Q.dirname(Bun.resolveSync("ts-images",import.meta.dir))}catch{}return Pe=fn.map((t)=>{let s;try{s=e?dn(t,e):void 0}catch{}return`${t.replace("@stacksjs/","")}@${s??"unknown"}`}).join("+"),Pe}var bt=Symbol.for("stx.image-delivery");function ye(){let e=globalThis;return e[bt]??={catalog:new Map,transparent:new Set},e[bt]}var vt=new Set;function gn(e){return`/${e.split(Q.sep).map(encodeURIComponent).join("/")}`}function pn(e){let t=Q.extname(e),s=e.slice(0,-t.length).replace(/[^a-zA-Z0-9_-]+/g,"-").replace(/^-+|-+$/g,""),i=Ct("sha256").update(e).digest("hex").slice(0,8);return`${s||"image"}-${i}`}function wt(e,t=`stx:${he}`){let s=(i)=>`${he}/${i.split("/").map(encodeURIComponent).join("/")}`;return{cacheNamespace:t,async stat(i){let o=Q.join(e,i);try{let a=await ee.promises.stat(o);return a.size>0?{bytes:a.size,path:o,url:s(i)}:null}catch{return null}},async write(i,o){let a=Q.join(e,i);await ee.promises.mkdir(Q.dirname(a),{recursive:!0});let c=`${a}.${process.pid}.tmp`;return await ee.promises.writeFile(c,o),await ee.promises.rename(c,a),{bytes:o.byteLength,path:a,url:s(i)}},url:s}}async function Rt(e,t=e){let s=await ee.promises.readdir(t,{withFileTypes:!0});s.sort((o,a)=>o.name.localeCompare(a.name));let i=[];for(let o of s){let a=Q.join(t,o.name);if(o.isDirectory()){i.push(...await Rt(e,a));continue}if(!o.isFile()||!an.has(Q.extname(o.name).toLowerCase()))continue;i.push({absolutePath:a,relativePath:Q.relative(e,a)})}return i}function $t(e,t){return e.map((s)=>({key:gn(s.relativePath),input:s.absolutePath,name:pn(s.relativePath),...hn(s.absolutePath)?{options:{storage:t}}:{}}))}function hn(e){return Me(e)==="possible"}function yn(e){for(let t=3;t<e.length;t+=4)if(e[t]!==255)return!0;return!1}async function xn(e){let t=Object.entries(e).filter(([,o])=>o.fallback.format==="png"),s=new Set,i=8;for(let o=0;o<t.length;o+=8)await Promise.all(t.slice(o,o+8).map(async([a,c])=>{let g=c.variants.filter((l)=>l.format==="png").sort((l,h)=>l.width-h.width)[0];try{let l=await sn(new Uint8Array(await ee.promises.readFile(g?.path??c.fallback.path)));if(yn(l.data))s.add(a)}catch{s.add(a)}}));return s}function bn(e,t){let s=[];for(let i of t){let o=e[i],a=o?.variants.filter((g)=>g.format==="webp")??[];if(!o||a.length===0)continue;if(!a.some((g)=>{let l;try{return l=ee.openSync(g.path,"r"),!De(Ce(l,0,32))}catch{return!0}finally{if(l!==void 0)ee.closeSync(l)}}))continue;if(o.variants=o.variants.filter((g)=>g.format!=="webp"),delete o.sources.webp,s.push(i),!vt.has(i))vt.add(i),console.warn(`[stx-images] ${i} is transparent but its WebP variants have no alpha channel; serving PNG instead. Upgrade @stacksjs/ts-webp to 0.1.6 or later.`)}return s}async function vn(e){let t=[],s=8;for(let i=0;i<e.length;i+=8){let o=e.slice(i,i+8),a=await Promise.all(o.map(async(c)=>{try{return await on(c.absolutePath),c}catch{return console.warn(`[stx-images] Skipping unreadable raster: ${c.relativePath}`),null}}));t.push(...a.filter((c)=>c!==null))}return t}function Ue(e){return Q.join(e,"undecodable.json")}function wn(e){try{let t=ee.readFileSync(Ue(e),"utf-8"),s=JSON.parse(t);return s&&typeof s==="object"?s:{}}catch{return{}}}function $n(e,t){try{ee.mkdirSync(Q.dirname(Ue(e)),{recursive:!0}),ee.writeFileSync(Ue(e),JSON.stringify(t))}catch{}}function St(e){try{let t=ee.statSync(e);return{mtimeMs:t.mtimeMs,size:t.size}}catch{return}}function At(e){if(!e||e.startsWith("data:")||e.startsWith("blob:")||/^https?:\/\//i.test(e)||e.startsWith("//"))return;let t=e.split(/[?#]/,1)[0];if(!t)return;try{return`/${t.replace(/^\/+/,"").split("/").map(decodeURIComponent).map(encodeURIComponent).join("/")}`}catch{return}}function so(e){let t=At(e);return t?ye().catalog.get(t):void 0}function oo(e){let t=At(e);return t?ye().transparent.has(t):!1}function io(e){let t=(i)=>e.variants.filter((o)=>o.format===i).reduce((o,a)=>o+a.bytes,0),s=t(e.fallback.format);return["avif","webp"].map((i)=>({format:i,srcset:e.sources[i]||"",bytes:t(i)})).filter((i)=>i.srcset&&i.bytes>0&&i.bytes<s).sort((i,o)=>i.bytes-o.bytes).map(({format:i,srcset:o})=>({format:i,srcset:o}))}function hp(e){let t=so(e);if(!t)return;return{src:t.fallback.url,srcset:t.sources[t.fallback.format]||"",sources:io(t).map(({format:s,srcset:i})=>({type:`image/${s}`,srcset:i})),width:t.source.width,height:t.source.height,placeholder:oo(e)?void 0:t.placeholder?.dataUrl}}function Hr(){let e=ye();e.catalog=new Map,e.transparent=new Set}function Sn(e){let t=ye();t.catalog=new Map(e.entries),t.transparent=new Set(e.transparent)}async function yp(e,t,s={}){if(!e||!ee.existsSync(e))return Hr(),{count:0,fingerprint:""};if(s.offThread){let m=await ze("delivery",{publicDir:e,outputDir:t});if(m!==ke)return Sn(m.state),m.result}let i=await Rt(e);if(i.length===0)return Hr(),{count:0,fingerprint:""};let o=wn(t),a=i.filter((m)=>{let b=o[m.relativePath];if(!b)return!0;let w=St(m.absolutePath);return!w||w.mtimeMs!==b.mtimeMs||w.size!==b.size});if(a.length===0)return Hr(),{count:0,fingerprint:""};let c=wt(Q.join(t,"_stx","images"),`${ln}:${xt()}`),g={outDir:Q.join(t,"_stx","images"),storage:wt(Q.join(t,"_stx","images"),`${un}:${xt()}`),baseUrl:he,widths:cn,formats:["avif","webp"],quality:{avif:70,webp:78,jpeg:82,png:100},includeOriginal:!1,placeholder:!0,batchConcurrency:4,concurrency:4},l=a,h;try{h=await yt({...g,entries:$t(a,c)})}catch(m){if(l=await vn(a),l.length===a.length)throw m;let b=new Set(l.map((C)=>C.relativePath)),w=!1;for(let C of a){if(b.has(C.relativePath))continue;let k=St(C.absolutePath);if(!k)continue;o[C.relativePath]=k,w=!0}if(w)$n(t,o);if(l.length===0)return Hr(),{count:0,fingerprint:""};h=await yt({...g,entries:$t(l,c)})}let v=await xn(h.entries),y=bn(h.entries,v),S=ye();S.catalog=new Map(Object.entries(h.entries)),S.transparent=v;let x=v.size===0&&y.length===0?h.fingerprint:Ct("sha256").update(h.fingerprint).update(JSON.stringify({transparent:[...v].sort(),droppedWebp:y.sort()})).digest("hex");return{count:l.length,fingerprint:x}}class kt{builtins=new Map;registerBuiltin(e){this.builtins.set(e.name.toLowerCase(),e);for(let t of e.aliases)this.builtins.set(t.toLowerCase(),e)}isBuiltin(e){return this.builtins.has(e.toLowerCase())}getBuiltin(e){return this.builtins.get(e.toLowerCase())??null}async resolveFile(e,t,s,i){let o=To(e,i);if(o!==void 0)return o;for(let a of $o(e,t,s,i))if(await n(a))return a;return null}}var le=new kt;function R(e){return V(e)}var se="\x00stx-boolean-attribute";function We(e){return e.indexOf("\x00")===-1?e:e.replace(/\0/g,"")}var Cn=new Set(["accesskey","autocapitalize","autofocus","class","contenteditable","dir","draggable","enterkeyhint","exportparts","hidden","id","inert","inputmode","is","itemid","itemprop","itemref","itemscope","itemtype","lang","nonce","part","role","slot","spellcheck","style","tabindex","title","translate","accept","action","alt","autocomplete","capture","cite","cols","colspan","content","controls","datetime","default","download","enctype","for","form","formaction","formenctype","formmethod","formnovalidate","formtarget","height","href","hreflang","kind","label","loading","loop","max","maxlength","media","method","min","minlength","multiple","muted","name","open","pattern","placeholder","playsinline","poster","preload","readonly","referrerpolicy","rel","required","reversed","rows","rowspan","scope","selected","shape","size","span","src","srcdoc","srclang","srcset","start","step","target","type","usemap","value","width","wrap"]);function Fe(e){let t=e.toLowerCase();return t.startsWith("aria-")||t.startsWith("data-")||Cn.has(t)}function ie(e,t){let s=[];for(let[i,o]of Object.entries(e.static)){if(t.has(i))continue;let a=e.staticNames?.[i]??i;if(typeof o==="boolean"){if(o)s.push(d(a));continue}if(o===se){s.push(d(a));continue}s.push(`${d(a)}="${mn(a,We(String(o)))}"`)}return s}function ae(e,t){let s=[];for(let[i,o]of Object.entries(e.serverDynamic??{})){if(t.has(i))continue;if(o===null||o===void 0||o===!1)continue;let a=e.serverDynamicNames?.[i]??i;if(o===!0){s.push(d(a));continue}if(typeof o==="object")continue;s.push(`${d(a)}="${mn(a,We(String(o)))}"`)}return s}function Rn(e){if(e.clientReactive.to)return{value:e.clientReactive.to,reactive:!0};if(e.serverDynamic.to!==void 0)return{value:String(e.serverDynamic.to),reactive:!1};if(typeof e.static.to==="string")return{value:e.static.to,reactive:!1};return{value:"#",reactive:!1}}var He={name:"StxLink",aliases:["stx-link"],render(e,t,s){let i=Rn(e),o=(typeof e.static.class==="string"?e.static.class:"")||(typeof e.static.className==="string"?e.static.className:""),a=typeof e.static.activeClass==="string"?e.static.activeClass:"active",c=typeof e.static.exactActiveClass==="string"?e.static.exactActiveClass:"exact-active",g=e.static.prefetch===!0||e.static.prefetch==="true"||e.serverDynamic.prefetch===!0,l=[];if(i.reactive)l.push(`:href="${R(i.value)}"`);else l.push(`href="${R(ar(i.value,"navigable"))}"`);if(o)l.push(`class="${R(o)}"`);if(l.push("data-stx-link"),l.push(`data-stx-active-class="${R(a)}"`),l.push(`data-stx-exact-active-class="${R(c)}"`),g)l.push("data-stx-prefetch");let h=typeof e.static.activeMatch==="string"?e.static.activeMatch.trim():"";if(h)l.push(`data-stx-active-match="${R(h)}"`);let v=new Set(["to","class","className","activeClass","exactActiveClass","activeMatch","prefetch"]);return l.push(...ie(e,v)),l.push(...ae(e,v)),`<a ${l.join(" ")}>${t}</a>`}};var An=new Map;function qe(e){if(!e)return;let t=e.split("?")[0].split("#")[0];return An.get(t)}var kn={sm:640,md:768,lg:1024,xl:1280,"2xl":1536},Xe=[320,640,768,1024,1280,1536,1920];function J(e,t){if(e.serverDynamic[t]!==void 0)return String(e.serverDynamic[t]);let s=e.static[t];if(typeof s==="string")return s;return}function _e(e,t,s=!1){let i=e.serverDynamic[t];if(i!==void 0)return i!==!1&&i!=="false";let o=e.static[t];if(o!==void 0)return o!=="false"&&o!==!1;return s}function Ze(e){if(e.includes("(")||e.includes(","))return e;let t=e.trim().split(/\s+/),s=[];for(let i of t)if(i.includes(":")){let[o,a]=i.split(":"),c=kn[o];if(c)s.push(`(max-width: ${c}px) ${a}`);else{let g=Number.parseInt(o);if(!Number.isNaN(g))s.push(`(max-width: ${g}px) ${a}`)}}else s.push(i);return s.join(", ")}function Ve(e,t,s,i){return t.map((o)=>`${xe(e,o,void 0,s,i)} ${o}w`).join(", ")}function Pn(e,t,s,i,o){return t.map((a)=>{let c=s?s*a:void 0;return`${xe(e,c,void 0,i,o)} ${a}x`}).join(", ")}function xe(e,t,s,i,o){if(!i||i==="local"||i==="static")return e;if(i==="cloudinary"){let a=[];if(t)a.push(`w_${t}`);if(s)a.push(`h_${s}`);if(o)a.push(`f_${o}`);a.push("q_auto");let c=a.join(",");return e.replace("/upload/",`/upload/${c}/`)}if(i==="imgix"){let a=new URLSearchParams;if(t)a.set("w",String(t));if(s)a.set("h",String(s));if(o)a.set("fm",o);a.set("auto","format");let c=e.includes("?")?"&":"?";return`${e}${c}${a.toString()}`}if(i==="bunny"){let a=new URLSearchParams;if(t)a.set("width",String(t));if(s)a.set("height",String(s));if(o)a.set("format",o);let c=e.includes("?")?"&":"?";return`${e}${c}${a.toString()}`}return e}function _n(e){return`var s=this.style;${e.map((t)=>`s.${t}=''`).join(";")}`}function In(e,t,s="#e5e7eb"){let i=`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${t}"><rect width="100%" height="100%" fill="${s}"/></svg>`;return`data:image/svg+xml;base64,${btoa(i)}`}var Ge={name:"StxImage",aliases:["Image","stx-image","stx-img"],render(e,t,s){let i=J(e,"src")||"",o=so(i),a=J(e,"alt")||"",c=J(e,"width")||(o?String(o.source.width):void 0),g=J(e,"height")||(o?String(o.source.height):void 0),l=J(e,"sizes"),h=J(e,"srcset"),v=J(e,"densities"),y=J(e,"format"),S=oo(i)||qe(i)?.transparent===!0,x=J(e,"placeholder")||(o&&!S?"thumbhash":void 0),m=J(e,"placeholderColor")||"#e5e7eb",b=J(e,"provider"),w=J(e,"class")||J(e,"className")||"",C=J(e,"style")||"",k=J(e,"objectFit")||J(e,"fit"),A=J(e,"objectPosition")||J(e,"position"),I=J(e,"quality"),U=_e(e,"lazy",!0),M=_e(e,"preload",!1),L=_e(e,"priority",!1),q=J(e,"loading"),N=J(e,"decoding")||"async",_=!!o||_e(e,"picture",!1)||!!y,O=c?Number.parseInt(c):void 0,B=g?Number.parseInt(g):void 0,z=h||"",G="";if(o)z=o.sources[o.fallback.format]||"",G=l?Ze(l):"100vw";else if(!z&&l&&b&&b!=="local"&&b!=="static")z=Ve(i,Xe,b,y),G=Ze(l);else if(!z&&v){let P=v.split(/\s+/).map((F)=>Number.parseFloat(F.replace("x","")));z=Pn(i,P,O,b,y)}else if(l)G=Ze(l);let D=[];if(C)D.push(C);if(k)D.push(`object-fit:${k}`);if(A)D.push(`object-position:${A}`);if(O&&B)D.push(`aspect-ratio:${O}/${B}`);let W=[],ce=x==="blur"||x==="color"||x==="thumbhash";if(ce&&!S){let P=o?.placeholder?{dataUrl:o.placeholder.dataUrl,color:m}:qe(i);if(P&&x==="color")D.push(`background-color:${P.color}`),W.push("backgroundColor");else if(P)D.push(`background-color:${P.color}`),D.push(`background-image:url(${P.dataUrl})`),D.push("background-size:cover"),D.push("background-repeat:no-repeat"),W.push("backgroundColor","backgroundImage");else{let F=In(O||16,B||9,m);D.push(`background-image:url(${F})`),D.push("background-size:cover"),D.push("background-repeat:no-repeat"),W.push("backgroundImage")}}else if(!ce&&x&&x!=="empty"&&x!=="none")D.push(`background-image:url(${R(x)})`),D.push("background-size:cover"),D.push("background-repeat:no-repeat"),W.push("backgroundImage");let we=o?.fallback.url||xe(i,O,B,b,y),Y=[];if(Y.push(`src="${R(ar(we,"fetched"))}"`),Y.push(`alt="${R(a)}"`),c)Y.push(`width="${R(c)}"`);if(g)Y.push(`height="${R(g)}"`);let ne=q||(L||M?"eager":U?"lazy":"");if(ne)Y.push(`loading="${R(ne)}"`);if(L)Y.push('fetchpriority="high"');if(Y.push(`decoding="${R(N)}"`),w)Y.push(`class="${R(w)}"`);if(D.length>0)Y.push(`style="${R(D.join(";"))}"`);if(z)Y.push(`srcset="${R(ar(z,"fetched"))}"`);if(G)Y.push(`sizes="${R(G)}"`);let $e=new Set(["src","alt","width","height","lazy","sizes","srcset","placeholder","placeholderColor","class","className","style","objectFit","objectPosition","fit","position","format","provider","quality","densities","preload","priority","picture","loading","decoding"]);if(W.length>0){let P=typeof e.static.onload==="string"?e.static.onload:"",F=_n(W)+(P?`;${P}`:"");Y.push(`onload="${R(F)}"`),$e.add("onload")}Y.push(...ie(e,$e)),Y.push(...ae(e,$e));let T=`<img ${Y.join(" ")} />`,Z="";if(M){let F=y==="webp"?"image/webp":y==="avif"?"image/avif":"";Z=`<link rel="preload" as="image" href="${R(we)}"${F?` type="${F}"`:""}${z?` imagesrcset="${R(z)}"`:""}${G?` imagesizes="${R(G)}"`:""} />
3
- `}if(_){let P=[];if(o)for(let F of io(o))P.push(`<source type="image/${F.format}" srcset="${R(F.srcset)}"${G?` sizes="${R(G)}"`:""} />`);if(!o&&(y==="avif"||y==="auto")){let F=xe(i,O,B,b,"avif"),te=z?Ve(i,Xe,b,"avif"):`${F}`;P.push(`<source type="image/avif" srcset="${R(te)}"${G?` sizes="${R(G)}"`:""} />`)}if(!o&&(y==="webp"||y==="auto")){let F=xe(i,O,B,b,"webp"),te=z?Ve(i,Xe,b,"webp"):`${F}`;P.push(`<source type="image/webp" srcset="${R(te)}"${G?` sizes="${R(G)}"`:""} />`)}return`${Z}<picture>
2
+ import{gc,mc}from"./chunk-gtktv6nn.js";import{j,cs,ls,us,To,$o,ar,Ie,de,G,ps,oe,X,H,et,lr,Io,pr,je,n,d,V,mn}from"./chunk-t3e5tv4h.js";import{p,E,tt,u}from"./chunk-3tp7r57c.js";import{re}from"./chunk-wt6f9pk9.js";import{r}from"./chunk-9tg4995v.js";import{f}from"./chunk-b7e07ybq.js";import{createHash as Ct}from"crypto";import ee from"fs";import Q from"path";import{decode as sn,generateThumbHash as on}from"ts-images";import{createImageDeliveryCatalog as yt}from"ts-images/delivery";import Te from"fs";function Ce(e,t,s){let i=Buffer.alloc(s),o=Te.readSync(e,i,0,s,t);return i.subarray(0,o)}function De(e){if(e.length<25)return!1;let t=(i,o)=>String.fromCharCode(...e.subarray(i,o));if(t(0,4)!=="RIFF"||t(8,12)!=="WEBP")return!1;let s=t(12,16);if(s==="VP8X")return(e[20]&16)!==0;if(s==="VP8L")return((e[21]|e[22]<<8|e[23]<<16|e[24]<<24)>>>28&1)===1;return!1}function Me(e){let t;try{t=Te.openSync(e,"r");let s=Ce(t,0,33);if(s.length>=3&&s[0]===255&&s[1]===216&&s[2]===255)return"none";if(s.length>=26&&s[0]===137&&s.toString("latin1",1,4)==="PNG"){let i=s[25];if(i===4||i===6)return"possible";let o=8;for(let a=0;a<64;a++){let c=Ce(t,o,8);if(c.length<8)return"unknown";let g=c.toString("latin1",4,8);if(g==="tRNS")return"possible";if(g==="IDAT"||g==="IEND")return"none";o+=12+c.readUInt32BE(0)}return"unknown"}if(s.length>=25&&s.toString("latin1",0,4)==="RIFF"&&s.toString("latin1",8,12)==="WEBP"){if(De(s))return"possible";let i=s.toString("latin1",12,16);return i==="VP8 "||i==="VP8X"?"none":"unknown"}return"unknown"}catch{return"unknown"}finally{if(t!==void 0)Te.closeSync(t)}}import Jt from"fs";import Re from"os";import{join as dt}from"path";import{fileURLToPath as gt}from"url";import{Worker as mt}from"worker_threads";var ke=Symbol("stx.image-worker.unavailable");function Yt(e=typeof Re.availableParallelism==="function"?Re.availableParallelism():Re.cpus().length){return Math.max(1,Math.min(2,e-1))}var Ae=0,ht=[];async function Qt(){if(Ae<Yt()){Ae++;return}await new Promise((e)=>ht.push(e)),Ae++}function en(){Ae--,ht.shift()?.()}var tn="@stacksjs/stx/builtins/image-warmup-worker";function nn(e=process.cwd()){let t=import.meta.url.endsWith(".ts")?"ts":"js";try{let s=new URL(`./image-warmup-worker.${t}`,import.meta.url);if(s.protocol==="file:"&&Jt.existsSync(gt(s)))return gt(s)}catch{}try{let s=typeof Bun<"u"?Bun.resolveSync(tn,e):void 0;return s&&rn(s)?s:void 0}catch{return}}function rn(e,t=process.env){let s=e.replace(/\\/g,"/");if(s.split("/").some((o)=>/@\d[^/]*@@@\d+$/.test(o)))return!1;return![t.BUN_INSTALL_CACHE_DIR,dt(t.BUN_INSTALL||dt(Re.homedir(),".bun"),"install","cache")].filter((o)=>!!o).map((o)=>`${o.replace(/\\/g,"/").replace(/\/$/,"")}/`).some((o)=>s.startsWith(o))}var pt=!1;function pe(e){if(!pt)pt=!0,console.warn(`[stx] image worker unavailable (${e}); running the image pass on the serving thread instead. Results are the same, but requests may stall while it runs.`);return ke}function Le(e){return e instanceof Error?e.message:String(e)}async function ze(e,t){if(typeof mt!=="function")return pe("node:worker_threads has no Worker in this runtime");let s=nn();if(!s)return pe("no image-warmup-worker entry beside this module or in the installed @stacksjs/stx");await Qt();try{return await new Promise((i,o)=>{let a;try{a=new mt(s)}catch(h){i(pe(`could not start ${s}: ${Le(h)}`));return}let c=!1,g=!1,l=(h)=>{if(g)return;g=!0,h(),a.terminate()};a.on("message",(h)=>{if(h.type==="ready"){c=!0,a.postMessage({task:e,args:t});return}if(h.type==="result"){l(()=>i(h.value));return}let v=Error(h.error?.message??"image worker failed");if(h.error?.name)v.name=h.error.name;if(h.error?.stack)v.stack=h.error.stack;l(()=>o(v))}),a.on("error",(h)=>{l(()=>c?o(h instanceof Error?h:Error(Le(h)||"image worker crashed")):i(pe(`the worker failed before it was ready: ${Le(h)}`)))}),a.on("exit",(h)=>{l(()=>c?o(Error("image worker exited before it finished")):i(pe(`the worker exited with code ${h} before it was ready`)))})})}finally{en()}}var an=new Set([".avif",".jpeg",".jpg",".png",".webp"]),cn=[320,640,960,1280,1920],he="/_stx/images",ln=`stx:${he}:alpha-1`,un=`stx:${he}:opaque-1`,fn=["@stacksjs/ts-webp","@stacksjs/ts-avif","ts-images"],Pe;function dn(e,t){let s=Q.dirname(Bun.resolveSync(e,t));while(s!==Q.dirname(s)){let i=Q.join(s,"package.json");if(ee.existsSync(i)){let o=JSON.parse(ee.readFileSync(i,"utf8"));if(o.name===e)return o.version}s=Q.dirname(s)}return}function xt(){if(Pe!==void 0)return Pe;let e;try{e=Q.dirname(Bun.resolveSync("ts-images",import.meta.dir))}catch{}return Pe=fn.map((t)=>{let s;try{s=e?dn(t,e):void 0}catch{}return`${t.replace("@stacksjs/","")}@${s??"unknown"}`}).join("+"),Pe}var bt=Symbol.for("stx.image-delivery");function ye(){let e=globalThis;return e[bt]??={catalog:new Map,transparent:new Set},e[bt]}var vt=new Set;function gn(e){return`/${e.split(Q.sep).map(encodeURIComponent).join("/")}`}function pn(e){let t=Q.extname(e),s=e.slice(0,-t.length).replace(/[^a-zA-Z0-9_-]+/g,"-").replace(/^-+|-+$/g,""),i=Ct("sha256").update(e).digest("hex").slice(0,8);return`${s||"image"}-${i}`}function wt(e,t=`stx:${he}`){let s=(i)=>`${he}/${i.split("/").map(encodeURIComponent).join("/")}`;return{cacheNamespace:t,async stat(i){let o=Q.join(e,i);try{let a=await ee.promises.stat(o);return a.size>0?{bytes:a.size,path:o,url:s(i)}:null}catch{return null}},async write(i,o){let a=Q.join(e,i);await ee.promises.mkdir(Q.dirname(a),{recursive:!0});let c=`${a}.${process.pid}.tmp`;return await ee.promises.writeFile(c,o),await ee.promises.rename(c,a),{bytes:o.byteLength,path:a,url:s(i)}},url:s}}async function Rt(e,t=e){let s=await ee.promises.readdir(t,{withFileTypes:!0});s.sort((o,a)=>o.name.localeCompare(a.name));let i=[];for(let o of s){let a=Q.join(t,o.name);if(o.isDirectory()){i.push(...await Rt(e,a));continue}if(!o.isFile()||!an.has(Q.extname(o.name).toLowerCase()))continue;i.push({absolutePath:a,relativePath:Q.relative(e,a)})}return i}function $t(e,t){return e.map((s)=>({key:gn(s.relativePath),input:s.absolutePath,name:pn(s.relativePath),...hn(s.absolutePath)?{options:{storage:t}}:{}}))}function hn(e){return Me(e)==="possible"}function yn(e){for(let t=3;t<e.length;t+=4)if(e[t]!==255)return!0;return!1}async function xn(e){let t=Object.entries(e).filter(([,o])=>o.fallback.format==="png"),s=new Set,i=8;for(let o=0;o<t.length;o+=8)await Promise.all(t.slice(o,o+8).map(async([a,c])=>{let g=c.variants.filter((l)=>l.format==="png").sort((l,h)=>l.width-h.width)[0];try{let l=await sn(new Uint8Array(await ee.promises.readFile(g?.path??c.fallback.path)));if(yn(l.data))s.add(a)}catch{s.add(a)}}));return s}function bn(e,t){let s=[];for(let i of t){let o=e[i],a=o?.variants.filter((g)=>g.format==="webp")??[];if(!o||a.length===0)continue;if(!a.some((g)=>{let l;try{return l=ee.openSync(g.path,"r"),!De(Ce(l,0,32))}catch{return!0}finally{if(l!==void 0)ee.closeSync(l)}}))continue;if(o.variants=o.variants.filter((g)=>g.format!=="webp"),delete o.sources.webp,s.push(i),!vt.has(i))vt.add(i),console.warn(`[stx-images] ${i} is transparent but its WebP variants have no alpha channel; serving PNG instead. Upgrade @stacksjs/ts-webp to 0.1.6 or later.`)}return s}async function vn(e){let t=[],s=8;for(let i=0;i<e.length;i+=8){let o=e.slice(i,i+8),a=await Promise.all(o.map(async(c)=>{try{return await on(c.absolutePath),c}catch{return console.warn(`[stx-images] Skipping unreadable raster: ${c.relativePath}`),null}}));t.push(...a.filter((c)=>c!==null))}return t}function Ue(e){return Q.join(e,"undecodable.json")}function wn(e){try{let t=ee.readFileSync(Ue(e),"utf-8"),s=JSON.parse(t);return s&&typeof s==="object"?s:{}}catch{return{}}}function $n(e,t){try{ee.mkdirSync(Q.dirname(Ue(e)),{recursive:!0}),ee.writeFileSync(Ue(e),JSON.stringify(t))}catch{}}function St(e){try{let t=ee.statSync(e);return{mtimeMs:t.mtimeMs,size:t.size}}catch{return}}function At(e){if(!e||e.startsWith("data:")||e.startsWith("blob:")||/^https?:\/\//i.test(e)||e.startsWith("//"))return;let t=e.split(/[?#]/,1)[0];if(!t)return;try{return`/${t.replace(/^\/+/,"").split("/").map(decodeURIComponent).map(encodeURIComponent).join("/")}`}catch{return}}function so(e){let t=At(e);return t?ye().catalog.get(t):void 0}function oo(e){let t=At(e);return t?ye().transparent.has(t):!1}function io(e){let t=(i)=>e.variants.filter((o)=>o.format===i).reduce((o,a)=>o+a.bytes,0),s=t(e.fallback.format);return["avif","webp"].map((i)=>({format:i,srcset:e.sources[i]||"",bytes:t(i)})).filter((i)=>i.srcset&&i.bytes>0&&i.bytes<s).sort((i,o)=>i.bytes-o.bytes).map(({format:i,srcset:o})=>({format:i,srcset:o}))}function hp(e){let t=so(e);if(!t)return;return{src:t.fallback.url,srcset:t.sources[t.fallback.format]||"",sources:io(t).map(({format:s,srcset:i})=>({type:`image/${s}`,srcset:i})),width:t.source.width,height:t.source.height,placeholder:oo(e)?void 0:t.placeholder?.dataUrl}}function Hr(){let e=ye();e.catalog=new Map,e.transparent=new Set}function Sn(e){let t=ye();t.catalog=new Map(e.entries),t.transparent=new Set(e.transparent)}async function yp(e,t,s={}){if(!e||!ee.existsSync(e))return Hr(),{count:0,fingerprint:""};if(s.offThread){let m=await ze("delivery",{publicDir:e,outputDir:t});if(m!==ke)return Sn(m.state),m.result}let i=await Rt(e);if(i.length===0)return Hr(),{count:0,fingerprint:""};let o=wn(t),a=i.filter((m)=>{let b=o[m.relativePath];if(!b)return!0;let w=St(m.absolutePath);return!w||w.mtimeMs!==b.mtimeMs||w.size!==b.size});if(a.length===0)return Hr(),{count:0,fingerprint:""};let c=wt(Q.join(t,"_stx","images"),`${ln}:${xt()}`),g={outDir:Q.join(t,"_stx","images"),storage:wt(Q.join(t,"_stx","images"),`${un}:${xt()}`),baseUrl:he,widths:cn,formats:["avif","webp"],quality:{avif:70,webp:78,jpeg:82,png:100},includeOriginal:!1,placeholder:!0,batchConcurrency:4,concurrency:4},l=a,h;try{h=await yt({...g,entries:$t(a,c)})}catch(m){if(l=await vn(a),l.length===a.length)throw m;let b=new Set(l.map((C)=>C.relativePath)),w=!1;for(let C of a){if(b.has(C.relativePath))continue;let k=St(C.absolutePath);if(!k)continue;o[C.relativePath]=k,w=!0}if(w)$n(t,o);if(l.length===0)return Hr(),{count:0,fingerprint:""};h=await yt({...g,entries:$t(l,c)})}let v=await xn(h.entries),y=bn(h.entries,v),S=ye();S.catalog=new Map(Object.entries(h.entries)),S.transparent=v;let x=v.size===0&&y.length===0?h.fingerprint:Ct("sha256").update(h.fingerprint).update(JSON.stringify({transparent:[...v].sort(),droppedWebp:y.sort()})).digest("hex");return{count:l.length,fingerprint:x}}class kt{builtins=new Map;registerBuiltin(e){this.builtins.set(e.name.toLowerCase(),e);for(let t of e.aliases)this.builtins.set(t.toLowerCase(),e)}isBuiltin(e){return this.builtins.has(e.toLowerCase())}getBuiltin(e){return this.builtins.get(e.toLowerCase())??null}async resolveFile(e,t,s,i){let o=To(e,i);if(o!==void 0)return o;for(let a of $o(e,t,s,i))if(await n(a))return a;return null}}var le=new kt;function R(e){return V(e)}var se="\x00stx-boolean-attribute";function We(e){return e.indexOf("\x00")===-1?e:e.replace(/\0/g,"")}var Cn=new Set(["accesskey","autocapitalize","autofocus","class","contenteditable","dir","draggable","enterkeyhint","exportparts","hidden","id","inert","inputmode","is","itemid","itemprop","itemref","itemscope","itemtype","lang","nonce","part","role","slot","spellcheck","style","tabindex","title","translate","accept","action","alt","autocomplete","capture","cite","cols","colspan","content","controls","datetime","default","download","enctype","for","form","formaction","formenctype","formmethod","formnovalidate","formtarget","height","href","hreflang","kind","label","loading","loop","max","maxlength","media","method","min","minlength","multiple","muted","name","open","pattern","placeholder","playsinline","poster","preload","readonly","referrerpolicy","rel","required","reversed","rows","rowspan","scope","selected","shape","size","span","src","srcdoc","srclang","srcset","start","step","target","type","usemap","value","width","wrap"]);function Fe(e){let t=e.toLowerCase();return t.startsWith("aria-")||t.startsWith("data-")||Cn.has(t)}function ie(e,t){let s=[];for(let[i,o]of Object.entries(e.static)){if(t.has(i))continue;let a=e.staticNames?.[i]??i;if(typeof o==="boolean"){if(o)s.push(d(a));continue}if(o===se){s.push(d(a));continue}s.push(`${d(a)}="${mn(a,We(String(o)))}"`)}return s}function ae(e,t){let s=[];for(let[i,o]of Object.entries(e.serverDynamic??{})){if(t.has(i))continue;if(o===null||o===void 0||o===!1)continue;let a=e.serverDynamicNames?.[i]??i;if(o===!0){s.push(d(a));continue}if(typeof o==="object")continue;s.push(`${d(a)}="${mn(a,We(String(o)))}"`)}return s}function Rn(e){if(e.clientReactive.to)return{value:e.clientReactive.to,reactive:!0};if(e.serverDynamic.to!==void 0)return{value:String(e.serverDynamic.to),reactive:!1};if(typeof e.static.to==="string")return{value:e.static.to,reactive:!1};return{value:"#",reactive:!1}}var He={name:"StxLink",aliases:["stx-link"],render(e,t,s){let i=Rn(e),o=(typeof e.static.class==="string"?e.static.class:"")||(typeof e.static.className==="string"?e.static.className:""),a=typeof e.static.activeClass==="string"?e.static.activeClass:"active",c=typeof e.static.exactActiveClass==="string"?e.static.exactActiveClass:"exact-active",g=e.static.prefetch===!0||e.static.prefetch==="true"||e.serverDynamic.prefetch===!0,l=[];if(i.reactive)l.push(`:href="${R(i.value)}"`);else l.push(`href="${R(ar(i.value,"navigable"))}"`);if(o)l.push(`class="${R(o)}"`);if(l.push("data-stx-link"),l.push(`data-stx-active-class="${R(a)}"`),l.push(`data-stx-exact-active-class="${R(c)}"`),g)l.push("data-stx-prefetch");let h=typeof e.static.activeMatch==="string"?e.static.activeMatch.trim():"";if(h)l.push(`data-stx-active-match="${R(h)}"`);let v=new Set(["to","class","className","activeClass","exactActiveClass","activeMatch","prefetch"]);return l.push(...ie(e,v)),l.push(...ae(e,v)),`<a ${l.join(" ")}>${t}</a>`}};var An=new Map;function qe(e){if(!e)return;let t=e.split("?")[0].split("#")[0];return An.get(t)}var kn={sm:640,md:768,lg:1024,xl:1280,"2xl":1536},Xe=[320,640,768,1024,1280,1536,1920];function J(e,t){if(e.serverDynamic[t]!==void 0)return String(e.serverDynamic[t]);let s=e.static[t];if(typeof s==="string")return s;return}function _e(e,t,s=!1){let i=e.serverDynamic[t];if(i!==void 0)return i!==!1&&i!=="false";let o=e.static[t];if(o!==void 0)return o!=="false"&&o!==!1;return s}function Ze(e){if(e.includes("(")||e.includes(","))return e;let t=e.trim().split(/\s+/),s=[];for(let i of t)if(i.includes(":")){let[o,a]=i.split(":"),c=kn[o];if(c)s.push(`(max-width: ${c}px) ${a}`);else{let g=Number.parseInt(o);if(!Number.isNaN(g))s.push(`(max-width: ${g}px) ${a}`)}}else s.push(i);return s.join(", ")}function Ve(e,t,s,i){return t.map((o)=>`${xe(e,o,void 0,s,i)} ${o}w`).join(", ")}function Pn(e,t,s,i,o){return t.map((a)=>{let c=s?s*a:void 0;return`${xe(e,c,void 0,i,o)} ${a}x`}).join(", ")}function xe(e,t,s,i,o){if(!i||i==="local"||i==="static")return e;if(i==="cloudinary"){let a=[];if(t)a.push(`w_${t}`);if(s)a.push(`h_${s}`);if(o)a.push(`f_${o}`);a.push("q_auto");let c=a.join(",");return e.replace("/upload/",`/upload/${c}/`)}if(i==="imgix"){let a=new URLSearchParams;if(t)a.set("w",String(t));if(s)a.set("h",String(s));if(o)a.set("fm",o);a.set("auto","format");let c=e.includes("?")?"&":"?";return`${e}${c}${a.toString()}`}if(i==="bunny"){let a=new URLSearchParams;if(t)a.set("width",String(t));if(s)a.set("height",String(s));if(o)a.set("format",o);let c=e.includes("?")?"&":"?";return`${e}${c}${a.toString()}`}return e}function _n(e){return`var s=this.style;${e.map((t)=>`s.${t}=''`).join(";")}`}function In(e,t,s="#e5e7eb"){let i=`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${t}"><rect width="100%" height="100%" fill="${s}"/></svg>`;return`data:image/svg+xml;base64,${btoa(i)}`}var Ge={name:"StxImage",aliases:["Image","stx-image","stx-img"],render(e,t,s){let i=J(e,"src")||"",o=so(i),a=J(e,"alt")||"",c=J(e,"width")||(o?String(o.source.width):void 0),g=J(e,"height")||(o?String(o.source.height):void 0),l=J(e,"sizes"),h=J(e,"srcset"),v=J(e,"densities"),y=J(e,"format"),S=oo(i)||qe(i)?.transparent===!0,x=J(e,"placeholder")||(o&&!S?"thumbhash":void 0),m=J(e,"placeholderColor")||"#e5e7eb",b=J(e,"provider"),w=J(e,"class")||J(e,"className")||"",C=J(e,"style")||"",k=J(e,"objectFit")||J(e,"fit"),A=J(e,"objectPosition")||J(e,"position"),I=J(e,"quality"),U=_e(e,"lazy",!0),M=_e(e,"preload",!1),L=_e(e,"priority",!1),q=J(e,"loading"),N=J(e,"decoding")||"async",_=!!o||_e(e,"picture",!1)||!!y,O=c?Number.parseInt(c):void 0,B=g?Number.parseInt(g):void 0,z=h||"",K="";if(o)z=o.sources[o.fallback.format]||"",K=l?Ze(l):"100vw";else if(!z&&l&&b&&b!=="local"&&b!=="static")z=Ve(i,Xe,b,y),K=Ze(l);else if(!z&&v){let P=v.split(/\s+/).map((F)=>Number.parseFloat(F.replace("x","")));z=Pn(i,P,O,b,y)}else if(l)K=Ze(l);let D=[];if(C)D.push(C);if(k)D.push(`object-fit:${k}`);if(A)D.push(`object-position:${A}`);if(O&&B)D.push(`aspect-ratio:${O}/${B}`);let W=[],ce=x==="blur"||x==="color"||x==="thumbhash";if(ce&&!S){let P=o?.placeholder?{dataUrl:o.placeholder.dataUrl,color:m}:qe(i);if(P&&x==="color")D.push(`background-color:${P.color}`),W.push("backgroundColor");else if(P)D.push(`background-color:${P.color}`),D.push(`background-image:url(${P.dataUrl})`),D.push("background-size:cover"),D.push("background-repeat:no-repeat"),W.push("backgroundColor","backgroundImage");else{let F=In(O||16,B||9,m);D.push(`background-image:url(${F})`),D.push("background-size:cover"),D.push("background-repeat:no-repeat"),W.push("backgroundImage")}}else if(!ce&&x&&x!=="empty"&&x!=="none")D.push(`background-image:url(${R(x)})`),D.push("background-size:cover"),D.push("background-repeat:no-repeat"),W.push("backgroundImage");let we=o?.fallback.url||xe(i,O,B,b,y),Y=[];if(Y.push(`src="${R(ar(we,"fetched"))}"`),Y.push(`alt="${R(a)}"`),c)Y.push(`width="${R(c)}"`);if(g)Y.push(`height="${R(g)}"`);let ne=q||(L||M?"eager":U?"lazy":"");if(ne)Y.push(`loading="${R(ne)}"`);if(L)Y.push('fetchpriority="high"');if(Y.push(`decoding="${R(N)}"`),w)Y.push(`class="${R(w)}"`);if(D.length>0)Y.push(`style="${R(D.join(";"))}"`);if(z)Y.push(`srcset="${R(ar(z,"fetched"))}"`);if(K)Y.push(`sizes="${R(K)}"`);let $e=new Set(["src","alt","width","height","lazy","sizes","srcset","placeholder","placeholderColor","class","className","style","objectFit","objectPosition","fit","position","format","provider","quality","densities","preload","priority","picture","loading","decoding"]);if(W.length>0){let P=typeof e.static.onload==="string"?e.static.onload:"",F=_n(W)+(P?`;${P}`:"");Y.push(`onload="${R(F)}"`),$e.add("onload")}Y.push(...ie(e,$e)),Y.push(...ae(e,$e));let T=`<img ${Y.join(" ")} />`,Z="";if(M){let F=y==="webp"?"image/webp":y==="avif"?"image/avif":"";Z=`<link rel="preload" as="image" href="${R(we)}"${F?` type="${F}"`:""}${z?` imagesrcset="${R(z)}"`:""}${K?` imagesizes="${R(K)}"`:""} />
3
+ `}if(_){let P=[];if(o)for(let F of io(o))P.push(`<source type="image/${F.format}" srcset="${R(F.srcset)}"${K?` sizes="${R(K)}"`:""} />`);if(!o&&(y==="avif"||y==="auto")){let F=xe(i,O,B,b,"avif"),te=z?Ve(i,Xe,b,"avif"):`${F}`;P.push(`<source type="image/avif" srcset="${R(te)}"${K?` sizes="${R(K)}"`:""} />`)}if(!o&&(y==="webp"||y==="auto")){let F=xe(i,O,B,b,"webp"),te=z?Ve(i,Xe,b,"webp"):`${F}`;P.push(`<source type="image/webp" srcset="${R(te)}"${K?` sizes="${R(K)}"`:""} />`)}return`${Z}<picture>
4
4
  ${P.join(`
5
5
  `)}
6
6
  ${T}
@@ -38,5 +38,5 @@ ${T}
38
38
  .stx-drawer-backdrop[data-stx-drawer-open]{display:block!important;opacity:1}
39
39
  .stx-drawer-backdrop[data-stx-drawer-open] .stx-drawer-panel{transform:translateX(0)}
40
40
  </style>`}};import{existsSync as On,readFileSync as Bn}from"fs";var Oe=new Map,Ot=new Set;function Tn(e){if(Ot.has(e))return;Ot.add(e),console.warn(`[stx] icon collection "${e}" is not installed, so its icons render as nothing. Install it with \`bun add -d @iconify-json/${e}\`.`)}function Dn(e){let t=process.cwd();for(let s of[`${t}/node_modules/@iconify-json/${e}/icons.json`,`${t}/pantry/@iconify-json/${e}/icons.json`,`${t}/node_modules/@iconify/json/json/${e}.json`,`${t}/pantry/@iconify/json/json/${e}.json`])if(On(s))return s;for(let s of[`@iconify-json/${e}/icons.json`,`@iconify/json/json/${e}.json`])try{return f.resolve(s)}catch{}return null}function jn(e){if(Oe.has(e))return Oe.get(e);let t=Dn(e);if(!t)return Tn(e),null;try{let s=JSON.parse(Bn(t,"utf8"));return Oe.set(e,s.icons),s.icons}catch{return null}}function ge(e,t){if(e.serverDynamic[t]!==void 0)return String(e.serverDynamic[t]);if(e.static[t]!==void 0)return String(e.static[t]);if(e.clientReactive[t]!==void 0)return e.clientReactive[t];return}var st={name:"Icon",aliases:["icon","stx-icon"],render(e,t,s){let i=ge(e,"name")??ge(e,"icon");if(!i)return"<!-- Icon: missing name/icon prop -->";let o="lucide",a=i;if(i.includes(":")){let k=i.split(":");o=k[0],a=k[1]}let c=R(ge(e,"size")||"24"),g=R(ge(e,"color")||"currentColor"),l=R(ge(e,"class")||""),h=R(ge(e,"style")||""),v=Oe.get(o)??jn(o);if(!v)return`<!-- Icon: collection "${o}" not loaded -->`;let y=v[a];if(!y)return`<!-- Icon: "${a}" not found in ${o} -->`;let S=y.width||24,x=y.height||24,m=`0 0 ${S} ${x}`,b=y.body;if(g!=="currentColor")b=b.replace(/currentColor/g,g);let w=l?` class="${l}"`:"",C=h?` style="${h}"`:"";return`<svg xmlns="http://www.w3.org/2000/svg" width="${c}" height="${c}" viewBox="${m}" fill="none"${w}${C}>${b}</svg>`}};function Bt(e,...t){for(let s of t){if(e.serverDynamic[s]!==void 0)return String(e.serverDynamic[s]);let i=e.static[s];if(typeof i==="string")return i}return}function Tt(e,t){let s=new RegExp(`<(template|div|span)[^>]*\\bslot=["']${t}["'][^>]*>([\\s\\S]*?)<\\/\\1>`,"i"),i=e.match(s);if(!i)return{region:null,rest:e};return{region:i[2],rest:e.replace(i[0],"")}}var it={name:"Suspense",aliases:["suspense"],render(e,t,s){let i=Tt(t,"fallback"),o=i.rest,a=Tt(o,"error"),c=a.rest,g=i.region??Bt(e,"fallback")??'<div class="stx-suspense-loading">Loading\u2026</div>',l=a.region??Bt(e,"errorFallback","error-fallback")??'<div class="stx-suspense-error">Something went wrong.</div>';return`<div data-stx-suspense><div data-stx-suspense-fallback>${g}</div><div data-stx-suspense-error hidden>${l}</div><div data-stx-suspense-content hidden>${c}</div></div>`}};function Be(e,...t){for(let s of t){if(e.serverDynamic[s]!==void 0)return String(e.serverDynamic[s]);let i=e.static[s];if(typeof i==="string")return i}return}var ot={name:"TransitionGroup",aliases:["transition-group"],render(e,t,s){let i=(Be(e,"name")||"v").replace(/["'<>]/g,""),o=(Be(e,"tag")||"div").replace(/[^a-z0-9-]/gi,"")||"div",a=Be(e,"class"),c=Be(e,"id"),g=[`data-stx-transition-group="${i}"`,a?`class="${a}"`:"",c?`id="${c}"`:""].filter(Boolean).join(" ");return`<${o} ${g}>${t}</${o}>`}};function Dt(e=le){e.registerBuiltin(He),e.registerBuiltin(Ge),e.registerBuiltin(Ke),e.registerBuiltin(Ye),e.registerBuiltin(Qe),e.registerBuiltin(nt),e.registerBuiltin(rt),e.registerBuiltin(st),e.registerBuiltin(it),e.registerBuiltin(ot)}var jt=new Map;function Mn(e){let t=jt.get(e.source);if(!t)t=new RegExp(`(${e.source})(?![\\w.:-])`,"y"),jt.set(e.source,t);return t}var Mt=new WeakMap;function Lt(e){let t=Mt.get(e);if(!t)t=new Set([...e].map((i)=>i.toLowerCase())),Mt.set(e,t);let s=t;return(i)=>!/[a-z]/.test(i)&&s.has(i.toLowerCase())}function Ln(e,t){let s="";for(let i=t;i<e.length;i++){let o=e[i];if(s){if(o==="\\")i++;else if(o===s)s=""}else if(o==='"'||o==="'")s=o;else if(o===">")return i}return e.length}function zt(e,t,s){let i=[],o=0,a=typeof s==="function"?s:s?(c)=>s.has(c.toLowerCase()):void 0;while(o<e.length){let c=e.indexOf("<",o);if(c===-1)break;let g=Mn(t);g.lastIndex=c+1;let l=g.exec(e);if(!l){o=c+1;continue}let h=l[1];if(a&&a(h)){let w=c+1+h.length;while(w<e.length&&e[w]!==">")w++;o=w+1;continue}let v=c+1+h.length,y=null,S=v,x=-1,m=!1;while(v<e.length){let w=e[v];if(y){if(w==="\\"&&v+1<e.length){v+=2;continue}if(w===y)y=null;v++;continue}if(w==='"'||w==="'"){y=w,v++;continue}if(w==="/"&&v+1<e.length&&e[v+1]===">"){x=v+2,m=!0;break}if(w===">"){x=v+1;break}v++}if(x===-1){o=c+1;continue}let b=e.slice(S,m?x-2:x-1).trim();if(m)i.push({fullMatch:e.slice(c,x),tagName:h,attributes:b,content:"",startIndex:c,endIndex:x,isSelfClosing:!0}),o=x;else{let w=`<${h}`,C=`</${h}>`,k=1,A=x,I=-1;while(k>0&&A<e.length){let L=e.indexOf(w,A),q=e.indexOf(C,A);if(q===-1)break;if(L!==-1&&L<q){let N=e[L+w.length];if(N===" "||N===">"||N==="/"||N===`
41
- `||N==="\t"){let _=Ln(e,L+w.length);if(e[_-1]!=="/")k++;A=_+1}else A=L+w.length}else{if(k--,k===0){I=q;break}A=q+C.length}}if(I===-1){o=x;continue}let U=e.slice(x,I),M=I+C.length;i.push({fullMatch:e.slice(c,M),tagName:h,attributes:b,content:U,startIndex:c,endIndex:M,isSelfClosing:!1}),o=M}}return i}function at(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#0?39;/g,"'").replace(/&#x27;/gi,"'").replace(/&amp;/g,"&")}function Ut(e,t){try{let s=Buffer.from(e,"base64").toString("utf8");return JSON.parse(s)}catch{}try{let s=e.replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");return JSON.parse(s)}catch(s){if(t?.debug)console.error("Error decoding __stx_ prop:",s);return e}}function ct(e,t){let s=0,i="",o=t;while(o<e.length){let a=e[o];if(i){if(a==="\\")o++;else if(a===i)i=""}else if(a==='"'||a==="'"||a==="`")i=a;else if(a==="{")s++;else if(a==="}"){if(s--,s===0)return e.slice(t,o+1)}o++}return e.slice(t)}function Wt(e){let t=e.trim();if(!t.startsWith("{")||!t.endsWith("}"))return null;if(ct(t,0).length!==t.length)return null;return t.slice(1,-1).trim()}var zn=new Set(["disabled","checked","readonly","required","autofocus","autoplay","controls","default","defer","formnovalidate","hidden","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","reversed","selected"]),Un=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function Wn(e){return lt(e).map((t)=>[t.start,t.end])}function lt(e){let t=[],s=/<([a-zA-Z][a-zA-Z0-9-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*)\s*\/?>/g,i;while((i=s.exec(e))!==null){let o=i[2]||"",a=/(?:^|\s)(?::for|x-for|v-for|@for)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/.exec(o);if(!a)continue;let c=X(a[1]??a[2]??a[3]??""),g=i.index,l=g+i[0].length,h=i[1].toLowerCase();if(i[0].endsWith("/>")||Un.has(h)){t.push({start:g,end:l,names:c});continue}let v=h.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),y=new RegExp(`<\\/?${v}\\b(?:[^>"']|"[^"]*"|'[^']*')*>`,"gi");y.lastIndex=l;let S=1,x=l,m;while((m=y.exec(e))!==null)if(m[0].startsWith("</")){if(S--,S===0){x=m.index+m[0].length;break}}else if(!m[0].endsWith("/>"))S++;t.push({start:g,end:x,names:c})}return t}function Ft(e){if(typeof e==="string")return e;if(Array.isArray(e))return e.filter(Boolean).map((t)=>Ft(t)).join(" ");if(e&&typeof e==="object")return Object.entries(e).filter(([,t])=>t).map(([t])=>t).join(" ");return e?String(e):""}function la(e,t){if(!/:[\w-]+=/.test(e))return e;let s=e,i=/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi,o=[],a;while((a=i.exec(e))!==null)o.push([a.index,a.index+a[0].length]);o.push(...Wn(e));let c=new Set([...et(t),...Array.isArray(t.__stx_client_declared_names)?t.__stx_client_declared_names:[]]);function g(S){return o.some(([x,m])=>S>=x&&S<m)}let l=/<([a-zA-Z][a-zA-Z0-9-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*?)\s*(\/?)>/g,h=[],v=new Map,y=256;while((a=l.exec(s))!==null){if(g(a.index))continue;let S=a[0],x=a[2];if(!x||!x.includes(":"))continue;let m=/(?:^|\s)data-native(?:\s|=|$)/i.test(x.replace(/"[^"]*"|'[^']*'/g,"")),b=/\s:([a-zA-Z_][\w-]*)\s*=\s*"([^"]*)"/g,w,C=x,k=!1;while((w=b.exec(x))!==null){if(ps(x,w.index,!0)?.kind==="attribute")continue;let A=w[1],I=w[2];if(gc(A))continue;if(H(I,c))continue;if(I.includes("()")&&!I.includes(".get(")||I.includes("$store")||I.includes("$ref"))continue;try{let U=Object.keys(t),M=Object.values(t),L=I.match(/^([a-zA-Z_$][\w$]*)/);if(L&&!U.includes(L[1])&&!["true","false","null","undefined","Math","JSON","String","Number","Array","Object","Date","parseInt","parseFloat"].includes(L[1]))continue;let q=JSON.stringify([U,I]),N=v.get(q);if(!N){if(N=Function(...U,`return (${I})`),v.size>=y)v.clear();v.set(q,N)}let _=N(...M);if(A==="class"){let O=V(Ft(_));if(O){let B=C.match(/\sclass="([^"]*)"/);if(B)C=C.replace(B[0],()=>` class="${B[1]} ${O}"`);else C=C.replace(w[0],()=>` class="${O}"`)}else C=C.replace(w[0],"");k=!0;continue}if(zn.has(A)){if(_)C=C.replace(w[0],` ${A}`);else C=C.replace(w[0],"");k=!0;continue}if(_===null||_===void 0||_===!1)C=C.replace(w[0],"");else{let O=m&&typeof _==="object"?JSON.stringify(_):String(_),B=mn(A,O);C=C.replace(w[0],()=>` ${A}="${B}"`)}k=!0}catch(U){if(U instanceof oe)throw U;continue}}if(k){let A=a[3]?" /":"",U=`<${a[1]}${C}${A}>`;h.push({start:a.index,end:a.index+S.length,replacement:U})}}if(h.length>0){let S=Array(h.length*2+1),x=0;for(let m=0;m<h.length;m++){let{start:b,end:w,replacement:C}=h[m];S[m*2]=s.slice(x,b),S[m*2+1]=C,x=w}S[h.length*2]=s.slice(x),s=S.join("")}return s}import Ht from"fs";import qt from"path";var Xt=!1;function Fn(e,t,s,i=!1,o=new Set){let a={static:{},staticNames:{},serverDynamic:{},serverDynamicNames:{},clientReactive:{},events:{}},c=new Set(Array.isArray(t.__stx_client_signal_names)?t.__stx_client_signal_names:[]),g=(y)=>{if(c.size===0)return!1;let S=r(y),x=S.match(/^\s*[!+~(-]*\s*([a-zA-Z_$][\w$]*)/)?.[1];if(x&&c.has(x))return!0;for(let m of c){let b=m.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");if(new RegExp(`(?:^|[^\\w$.])${b}\\s*\\(`).test(S))return!0}return!1},l=new Set(mc),h=(y)=>{if(!y.includes("-")||y.startsWith("@")||y.startsWith(":")||y.startsWith("x-")||y.startsWith("__"))return y;if(y.startsWith("aria-")||y.startsWith("data-"))return y;return y.replace(/-([a-z0-9])/g,(S,x)=>x.toUpperCase())},v=(y,S)=>{let x=h(y);if(a.static[x]=S,x!==y)a.staticNames[x]=y};for(let[y,S]of Object.entries(e)){let x=y.startsWith("x-")&&!l.has(y)&&!y.startsWith("x-bind:")&&!y.startsWith("x-on:")?`:${y.slice(2)}`:y;if(x.startsWith("@")){a.events[x]=S;continue}if(x.startsWith("__stx_")){let m=h(x.slice(6));a.serverDynamic[m]=Ut(S,s);continue}if(x.startsWith(":")){let m=h(x.slice(1)),b=S===se?m:S;if(m==="if"||m==="for"||m==="show"){a.clientReactive[m]=b;continue}if(i){a.clientReactive[m]=b;continue}if(H(b,o)){a.clientReactive[m]=b;continue}if(g(b)){a.clientReactive[m]=b;continue}try{if(!p(b)){if(s.debug)console.error(`Unsafe expression in :${m} binding: ${b}`);a.clientReactive[m]=b;continue}let w=Object.keys(t),C=new Set(["true","false","null","undefined","typeof","instanceof","in","of","new","this","return","void","delete","throw","if","else"]),k=new Set(Array.isArray(t.__stx_client_declared_names)?t.__stx_client_declared_names:[]);if(tt(b).some((M)=>!C.has(M)&&!w.includes(M)&&(!(M in globalThis)||k.has(M)))){a.clientReactive[m]=b;continue}let U=u(b,w)(...Object.values(t));if(a.serverDynamic[m]=U,m!==x.slice(1)&&a.serverDynamicNames)a.serverDynamicNames[m]=x.slice(1)}catch{a.clientReactive[m]=b}continue}if(typeof S==="string"&&S.includes("{{")&&S.includes("}}")){let m=Hn(S,o);if(m!==null){a.clientReactive[h(x)]=m;continue}let b=S.match(/^\{\{\s*([\s\S]+?)\s*\}\}$/);if(b)try{let w=b[1];if(p(w)){let k=u(w,Object.keys(t))(...Object.values(t));v(x,k!=null?String(k):"")}else{if(s.debug)console.error(`Unsafe expression in ${x}: ${w}`);v(x,S)}}catch(w){if(s.debug)console.error(`Error evaluating expression for ${x}:`,w);v(x,S)}else{let w=S,C=/\{\{\s*([\s\S]+?)\s*\}\}/g,k;while((k=C.exec(S))!==null)try{let A=k[1];if(!p(A)){if(s.debug)console.error(`Unsafe expression in ${x}: ${A}`);continue}let U=u(A,Object.keys(t))(...Object.values(t));w=w.replace(k[0],String(U??""))}catch(A){if(s.debug)console.error(`Error evaluating expression in ${x}:`,A)}v(x,w)}continue}v(x,S===se?"true":at(S))}return a}function Hn(e,t){if(t.size===0)return null;let s=/\{\{\s*([\s\S]+?)\s*\}\}/g,i=[...e.matchAll(s)];if(!i.some((g)=>H(g[1],t)))return null;let o=e.match(/^\{\{\s*([\s\S]+?)\s*\}\}$/);if(o&&i.length===1)return o[1];let a="",c=0;for(let g of i)a+=e.slice(c,g.index).replace(/[`\\$]/g,(l)=>`\\${l}`),a+=`\${${g[1]}}`,c=g.index+g[0].length;return a+=e.slice(c).replace(/[`\\$]/g,(g)=>`\\${g}`),`\`${a}\``}var qn=[[/@if\s*\(/,"@endif"],[/@unless\s*\(/,"@endunless"]];function Xn(e,t,s){if(!e.includes("@"))return e;if(!qn.some(([o,a])=>o.test(e)&&e.includes(a)))return e;try{return re(e,t,s)}catch{return e}}function me(e){let t={},s=0,i=e.length;while(s<i){while(s<i&&/\s/.test(e[s]))s++;if(s>=i)break;let o="";while(s<i&&!/[\s=]/.test(e[s]))o+=e[s],s++;if(!o)break;while(s<i&&/\s/.test(e[s]))s++;if(s<i&&e[s]==="="){s++;while(s<i&&/\s/.test(e[s]))s++;let a="";if(s<i&&(e[s]==='"'||e[s]==="'")){let c=e[s];s++;while(s<i){let g=e[s];if(g==="\\"&&s+1<i){s++,a+=e[s],s++;continue}if(g===c){s++;break}a+=g,s++}}else if(e[s]==="{"){a=ct(e,s),s+=a.length;let c=Wt(a);if(c!==null){t[`:${o}`]=c;continue}}else while(s<i&&!/\s/.test(e[s]))a+=e[s],s++;t[o]=a}else t[o]=se}return t}function Zt(e){return Object.entries(e).map(([t,s])=>s===se?t:`${t}="${Zn(s)}"`).join(" ")}function Zn(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Vn(e){let t=new Set,s=/<([A-Z][A-Za-z0-9]*|stx-[a-z0-9-]+)\b[^>]*>/g,i;while((i=s.exec(e))!==null){let o=i[1];if(le.isBuiltin(o))t.add(o)}return[...t].sort()}async function $l(e,t,s,i,o){if(!/import\s/.test(e))return e;if(!t.__importedComponents)t.__importedComponents=new Map;let a=t.__importedComponents,c=qt.dirname(s),g=[],l=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi;for(let y of e.matchAll(l)){let[S,x,m]=y,b=/import\s+(?:(\{[^}]*\})|([A-Za-z_$][\w$]*))\s+from\s+['"]([^'"]+)['"]\s*;?\s*\n?/g,w=m,C,k=[];while((C=b.exec(m))!==null){let[A,I,U,M]=C,L=null,q=null;if(M.startsWith(".")||M.startsWith("/")){let O=qt.resolve(c,M);if(O.endsWith(".stx"))q=O;else{let B=`${O}.stx`;try{if(Ht.statSync(B).isFile())q=B}catch{try{if(Ht.statSync(O).isDirectory())L=O}catch{}}}}else L=ls(M,c);if(!L&&!q)continue;let N=!1,_=(O,B)=>{a.set(O,B),a.set(O.toLowerCase(),B);let z=O.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();a.set(z,B),o.add(B)};if(U&&q)_(U,q),N=!0;else if(I){let O=I.slice(1,-1).split(",").map((z)=>z.trim()).filter(Boolean).map((z)=>{let G=z.match(/^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/);if(G)return{source:G[1],local:G[2]};return{source:z,local:z}}),B=L?cs(L):null;for(let{source:z,local:G}of O){let D=null;if(q)D=q;else if(B)D=B.get(z)??B.get(z.toLowerCase())??B.get(z.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase())??null;if(D)_(G,D),N=!0}}if(N)k.push({start:C.index,end:C.index+A.length})}if(k.length===0)continue;for(let A=k.length-1;A>=0;A--)w=w.slice(0,k[A].start)+w.slice(k[A].end);g.push({start:y.index,end:y.index+S.length,value:`<script${x}>${w}</script>`})}if(g.length===0)return e;let h=[],v=0;for(let y of g)h.push(e.slice(v,y.start),y.value),v=y.end;return h.push(e.slice(v)),h.join("")}async function Gn(e,t,s,i,o){let a=e;if(!t.__importedComponents)t.__importedComponents=new Map;let c=t.__importedComponents,g=/@import\s*\(\s*([^)]+)\s*\)/g,l;while((l=g.exec(a))!==null){let[h,v]=l,y=v.split(",").map((S)=>S.trim().replace(/^['"]|['"]$/g,"")).filter((S)=>S.length>0);for(let S of y){let x=S.split("/"),b=x[x.length-1].replace(/\.stx$/,""),w=b.includes("-")?b.split("-").map((A)=>A.charAt(0).toUpperCase()+A.slice(1)).join(""):b.charAt(0).toUpperCase()+b.slice(1),C=null,k=us(S,s,i);for(let A of k)try{if(await Bun.file(A).exists()){C=A;break}}catch{}if(C){c.set(w,C),c.set(b,C),c.set(b.toLowerCase(),C);let A=w.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();if(c.set(A,C),o.add(C),i.debug)console.log(`Imported component: ${w} -> ${C}`)}else if(i.debug)console.warn(`Could not resolve imported component: ${S}`)}a=a.replace(h,""),g.lastIndex=0}return a}async function Kn(e,t,s,i,o){let a=e,c=i.componentsDir||"components";if(!t.__processedComponents)t.__processedComponents=new Set;let g=t.__processedComponents,l=/@component\s*\(/g,h;while((h=l.exec(a))!==null){let v=h.index,y=v+h[0].length-1,S=1,x=y+1;while(x<a.length&&S>0){if(a[x]==="(")S++;else if(a[x]===")"){if(S--,S===0)break}x++}if(S!==0)break;let m=a.substring(y+1,x),b=x+1,w=m.match(/^\s*['"]([^'"]+)['"]/);if(!w){l.lastIndex=0;continue}let C=w[1],k,A=m.slice(w[0].length),I=A.match(/^\s*,\s*/);if(I)k=A.slice(I[0].length).trim();let U={};if(k)try{U=E(k,t)}catch(O){let B=O instanceof Error?O.message:String(O);a=a.replace(a.substring(v,b),`[Error parsing component props: ${B}]`);continue}let M="",L=b,N=a.substring(b).match(/^([\s\S]*?)@endcomponent/);if(N)M=N[1].trim(),L=b+N[0].length;let _=await je(C,U,M,c,t,s,i,g,o);a=a.substring(0,v)+_+a.substring(L),l.lastIndex=0}return a}async function Jn(e,t,s,i,o){if(!e)return e;let a=e,c=i.componentsDir||"components";if(!t.__processedComponents)t.__processedComponents=new Set;let g=t.__processedComponents,l=er(a);if(l.size>0){let b=Array.isArray(t.__stx_client_declared_names)?t.__stx_client_declared_names:[];t.__stx_client_declared_names=[...new Set([...b,...l])]}let h=K(a);a=h.output;let v=et(t);return a=await m(a,/[a-z][a-z0-9]*-[a-z0-9-]*/,!1),a=await m(a,/[A-Z][a-zA-Z0-9]*/,!0,Lt(lr)),a=await m(a,/[a-z][a-z0-9]*/,!1,lr),a=h.restore(a),a;async function m(b,w,C,k){if(!b)return b;let A=b,I=zt(A,w,k),U=lt(A),M=new Map;for(let N=I.length-1;N>=0;N--){let _=I[N],O=C?j(_.tagName):_.tagName,B=me(Xn(_.attributes,t,s)),z=U.filter(({start:Z,end:P})=>_.startIndex>=Z&&_.startIndex<P),G=z.length>0,D=new Set(v);for(let Z of z)for(let P of Z.names)D.add(P);let W=Fn(B,t,i,G,D);if(typeof W.clientReactive.for==="string")for(let Z of X(W.clientReactive.for))D.add(Z);let ce=le.getBuiltin(_.tagName),we=ce?await pr(_.tagName,c,t,s,i):!1;if(ce&&!we){let Z={context:t,filePath:s,options:i,dependencies:o},P=ce.render(W,_.content,Z);if(Object.keys(W.events).length>0){let F=Zt(W.events);P=P.replace(/^(\s*<[a-zA-Z][a-zA-Z0-9-]*)/,`$1 ${F}`)}if(Object.keys(W.clientReactive).length>0)P=Vt(P,W.clientReactive);M.set(N,P);continue}if(!C&&_.tagName.includes("-")&&!await pr(O,c,t,s,i))continue;let Y={};for(let[Z,P]of Object.entries(W.static))Y[Z]=P;for(let[Z,P]of Object.entries(W.serverDynamic))Y[Z]=P;let ne={declaredProps:new Set,consumedProps:new Set,reactiveProps:Object.keys(W.clientReactive),events:Object.keys(W.events)},T=await je(O,Y,h.restore(_.content),c,t,s,i,g,o,[...D],ne,_.tagName);if(T=Yn(T,W,ne.declaredProps,ne.consumedProps,i._nativeHostAttrs),i._nativeHostAttrs){let Z=ne.reactiveProps.filter((te)=>!ne.consumedProps.has(te)&&!["if","for","show","key","ref"].includes(te)).map(j),P=ut(T,!0);if(Z.length&&P){if(!Object.hasOwn(me(T.slice(P.insertPos,P.tagEnd)),"data-stx-native-host-root"))T=T.slice(0,P.insertPos)+' data-stx-native-host-root="true"'+T.slice(P.insertPos);let te=ve(T);T=T.slice(0,te.insertPos)+` data-stx-native-forward="${Z.join(" ")}"`+T.slice(te.insertPos)}let F=ut(T,!0);if(F){let te=me(T.slice(F.insertPos,F.tagEnd)),Se=ve(T),Kt=me(T.slice(Se.insertPos,Se.tagEnd));if(Object.hasOwn(te,"data-stx-native-host-root")&&!Object.hasOwn(Kt,"data-stx-native-host-owner"))T=T.slice(0,Se.insertPos)+" data-stx-native-host-owner"+T.slice(Se.insertPos)}}if(Object.keys(W.events).length>0){let Z=ve(T);if(Z){let P=Zt(W.events),F=Object.keys(W.events).map((te)=>te.replace(/^@/,"").split(".")[0]).join(" ");T=T.substring(0,Z.insertPos)+` data-stx-parent-events="${F}" ${P}`+T.substring(Z.insertPos)}}if(Object.keys(W.clientReactive).length>0)T=Vt(T,W.clientReactive);M.set(N,T)}if(M.size===0)return A;let L="",q=0;for(let N=0;N<I.length;N++){let _=M.get(N);if(_===void 0)continue;L+=A.slice(q,I[N].startIndex),L+=_,q=I[N].endIndex}return L+=A.slice(q),L}}function Vt(e,t){let s=new Set(["if","for"]),i=new Set(["show"]),o=Object.entries(t).filter(([v])=>!s.has(v)),a=o.filter(([v])=>!i.has(v)).map(([v])=>j(v)).join(" "),c=e,g=o.length>0?ve(c):null;if(g){let v=o.map(([S,x])=>`:${j(S)}="${x.replace(/"/g,"&quot;")}"`).join(" "),y=a?` data-stx-parent-bindings="${a}"`:"";c=c.substring(0,g.insertPos)+`${y} ${v}`+c.substring(g.insertPos)}let l=t.if;if(l)c=`<template :if="${l.replace(/"/g,"&quot;")}">${c}</template>`;let h=t.for;if(h){let v=t.key,y=v?` :key="${v.replace(/"/g,"&quot;")}"`:"";c=`<template :for="${h.replace(/"/g,"&quot;")}"${y}>${c}</template>`}return c}function Yn(e,t,s=new Set,i=new Set,o=!1){let a=ut(e,o);if(!a)return e;let c=e.slice(a.insertPos,a.tagEnd),g=t.serverDynamic.class??t.static.class;if(o&&typeof g==="string"&&g&&!i.has("class")){let m=/(^|\s)class\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i,b=m.test(c)?c.replace(m,(w,C,k,A,I)=>`${C}class="${R(`${at(k??A??I)} ${g}`)}"`):` class="${R(g)}"${c}`;e=e.slice(0,a.insertPos)+b+e.slice(a.tagEnd),a.tagEnd+=b.length-c.length,c=b}let l=o||/\bdata-native(?:\s|=)/i.test(c),h=l?i:s,v=new Set(Object.keys(me(c))),y=new Set(["class","className"]);for(let m of Object.keys(t.static)){let b=t.staticNames[m]??m;if(v.has(b)||h.has(m)||!l&&!Fe(b))y.add(m)}for(let m of Object.keys(t.serverDynamic)){let b=t.serverDynamicNames?.[m]??m;if(v.has(b)||h.has(m)||!l&&!Fe(b))y.add(m)}let S=[];if(l){for(let[m,b]of Object.entries(t.static)){if(y.has(m)||b!==!0&&b!==se)continue;y.add(m),S.push(`${R(t.staticNames?.[m]??m)}="true"`)}for(let[m,b]of Object.entries(t.serverDynamic)){if(y.has(m)||b!==!0)continue;y.add(m),S.push(`${R(t.serverDynamicNames?.[m]??m)}="true"`)}}let x=[...ie(t,y),...ae(t,y),...S];if(l){for(let[m,b]of Object.entries(t.serverDynamic)){if(y.has(m)||b!==!1)continue;let w=t.serverDynamicNames?.[m]??m;x.push(`${R(w)}="false"`)}for(let[m,b]of Object.entries(t.serverDynamic)){if(y.has(m)||b===null||typeof b!=="object")continue;let w=JSON.stringify(b);if(w!==void 0){let C=t.serverDynamicNames?.[m]??m;x.push(`${R(C)}="${R(w)}"`)}}}if(x.length===0)return e;return`${e.slice(0,a.insertPos)} ${x.join(" ")}${e.slice(a.insertPos)}`}function ve(e){let t=Gt(e,0);if(t)return t;let s=/<([a-zA-Z][a-zA-Z0-9-]*)\b[^>]*\bdata-stx-scope(?:\s|=|>)/i.exec(e);if(s)return{insertPos:s.index+1+s[1].length,tagEnd:ft(e,s.index+1+s[1].length)};return null}function ut(e,t=!1){let s=ve(e);if(!s)return null;let i=e.slice(s.insertPos,s.tagEnd),o=/\bdata-stx-component-wrapper(?:\s|=|>|$)/i.test(i)?Gt(e,s.tagEnd+1):s;return o&&t?Qn(e,o)??o:o}function Qn(e,t){if(!e.includes("data-stx-native-host-root"))return null;let s=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),i=e.lastIndexOf("<",t.insertPos),o=0,a;while(i>=0&&i<e.length){if(e.startsWith("<!--",i)){let v=e.indexOf("-->",i+4);if(v<0)return null;i=e.indexOf("<",v+3);continue}let c=/^<(\/?)([a-z][\w-]*)\b/i.exec(e.slice(i));if(!c){i=e.indexOf("<",i+1);continue}let g=c[2].toLowerCase(),l=i+c[0].length,h=ft(e,l);if(c[1]){if(o--,a!==void 0&&o<a)a=void 0;if(o<=0)return null}else if(g==="script"||g==="style"){let v=new RegExp(`</${g}\\s*>`,"gi");if(v.lastIndex=h+1,!v.exec(e))return null;i=e.indexOf("<",v.lastIndex);continue}else{let v=me(e.slice(l,h)),y=o>0&&(Object.hasOwn(v,"data-stx-component-wrapper")||Object.hasOwn(v,"data-stx-native-host-owner"));if(a===void 0&&!y&&Object.hasOwn(v,"data-stx-native-host-root"))return{insertPos:l,tagEnd:h};if(!s.has(g)&&e[h-1]!=="/"){if(o++,a===void 0&&y)a=o}else if(o===0)return null}i=e.indexOf("<",h+1)}return null}function Gt(e,t){let s=t;while(s<e.length){let i=e.slice(s),o=i.match(/^\s+/);if(o){s+=o[0].length;continue}if(i.startsWith("<!--")){let g=e.indexOf("-->",s+4);if(g===-1)return null;s=g+3;continue}let a=i.match(/^<(script|style)\b[^>]*>/i);if(a){let g=`</${a[1].toLowerCase()}>`,l=e.toLowerCase().indexOf(g,s+a[0].length);if(l===-1)return null;s=l+g.length;continue}let c=i.match(/^<([a-zA-Z][a-zA-Z0-9-]*)(?:\s|>|\/)/);if(!c)return null;return{insertPos:s+1+c[1].length,tagEnd:ft(e,s+1+c[1].length)}}return null}function ft(e,t){let s="";for(let i=t;i<e.length;i++){let o=e[i];if(s){if(o==="\\")i++;else if(o===s)s=""}else if(o==='"'||o==="'")s=o;else if(o===">")return i}return e.length}function er(e){let t=new Set;for(let s of e.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)){let i=s[1];if(!/\bclient\b/.test(i)||/\bserver\b/.test(i))continue;for(let o of Io(s[2]))t.add(o);for(let o of s[2].matchAll(/^\s*import\s+(?:type\s+)?(?:([\w$]+)\s*,?\s*)?(?:\{([^}]*)\}|\*\s+as\s+([\w$]+))?\s*from\s/gm)){if(o[1])t.add(o[1]);if(o[3])t.add(o[3]);for(let a of(o[2]??"").split(",")){let c=a.replace(/^\s*type\s+/,"").split(/\s+as\s+/).pop().trim();if(/^[A-Za-z_$][\w$]*$/.test(c))t.add(c)}}}return t}async function Vr(e,t,s,i,o){if(!Xt)Dt(le),Xt=!0;let a=await $l(e,t,s,i,o);a=await Gn(a,t,s,i,o),a=await Kn(a,t,s,i,o);let c=[];for(let g=0;g<3;g++){let l=c.length,h=de(a,Ie,(y,S)=>`\x00STX_COMPONENT_COMMENT_${l+S}\x00`,`STX_COMPONENT_COMMENT:${l}`);c.push(...h.tokens);let v=a;if(a=await Jn(h.output,t,s,i,o),a===v)break}if(c.length>0)a=a.replace(/\x00STX_COMPONENT_COMMENT_(\d+)\x00/g,(g,l)=>c[Number(l)]??"");if(i.debug){let g=Vn(a);if(g.length>0)console.warn(`[stx] ${s}: unresolved component tag(s) after render passes: ${g.join(", ")}. Check nested component output for malformed root tags or recursive component markup.`)}return a}
41
+ `||N==="\t"){let _=Ln(e,L+w.length);if(e[_-1]!=="/")k++;A=_+1}else A=L+w.length}else{if(k--,k===0){I=q;break}A=q+C.length}}if(I===-1){o=x;continue}let U=e.slice(x,I),M=I+C.length;i.push({fullMatch:e.slice(c,M),tagName:h,attributes:b,content:U,startIndex:c,endIndex:M,isSelfClosing:!1}),o=M}}return i}function at(e){return e.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#0?39;/g,"'").replace(/&#x27;/gi,"'").replace(/&amp;/g,"&")}function Ut(e,t){try{let s=Buffer.from(e,"base64").toString("utf8");return JSON.parse(s)}catch{}try{let s=e.replace(/&quot;/g,'"').replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&");return JSON.parse(s)}catch(s){if(t?.debug)console.error("Error decoding __stx_ prop:",s);return e}}function ct(e,t){let s=0,i="",o=t;while(o<e.length){let a=e[o];if(i){if(a==="\\")o++;else if(a===i)i=""}else if(a==='"'||a==="'"||a==="`")i=a;else if(a==="{")s++;else if(a==="}"){if(s--,s===0)return e.slice(t,o+1)}o++}return e.slice(t)}function Wt(e){let t=e.trim();if(!t.startsWith("{")||!t.endsWith("}"))return null;if(ct(t,0).length!==t.length)return null;return t.slice(1,-1).trim()}var zn=new Set(["disabled","checked","readonly","required","autofocus","autoplay","controls","default","defer","formnovalidate","hidden","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","reversed","selected"]),Un=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function Wn(e){return lt(e).map((t)=>[t.start,t.end])}function lt(e){let t=[],s=/<([a-zA-Z][a-zA-Z0-9-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*)\s*\/?>/g,i;while((i=s.exec(e))!==null){let o=i[2]||"",a=/(?:^|\s)(?::for|x-for|v-for|@for)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/.exec(o);if(!a)continue;let c=X(a[1]??a[2]??a[3]??""),g=i.index,l=g+i[0].length,h=i[1].toLowerCase();if(i[0].endsWith("/>")||Un.has(h)){t.push({start:g,end:l,names:c});continue}let v=h.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),y=new RegExp(`<\\/?${v}\\b(?:[^>"']|"[^"]*"|'[^']*')*>`,"gi");y.lastIndex=l;let S=1,x=l,m;while((m=y.exec(e))!==null)if(m[0].startsWith("</")){if(S--,S===0){x=m.index+m[0].length;break}}else if(!m[0].endsWith("/>"))S++;t.push({start:g,end:x,names:c})}return t}function Ft(e){if(typeof e==="string")return e;if(Array.isArray(e))return e.filter(Boolean).map((t)=>Ft(t)).join(" ");if(e&&typeof e==="object")return Object.entries(e).filter(([,t])=>t).map(([t])=>t).join(" ");return e?String(e):""}function la(e,t){if(!/:[\w-]+=/.test(e))return e;let s=e,i=/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi,o=[],a;while((a=i.exec(e))!==null)o.push([a.index,a.index+a[0].length]);o.push(...Wn(e));let c=new Set([...et(t),...Array.isArray(t.__stx_client_declared_names)?t.__stx_client_declared_names:[]]);function g(S){return o.some(([x,m])=>S>=x&&S<m)}let l=/<([a-zA-Z][a-zA-Z0-9-]*)\b((?:[^>"']|"[^"]*"|'[^']*')*?)\s*(\/?)>/g,h=[],v=new Map,y=256;while((a=l.exec(s))!==null){if(g(a.index))continue;let S=a[0],x=a[2];if(!x||!x.includes(":"))continue;let m=/(?:^|\s)data-native(?:\s|=|$)/i.test(x.replace(/"[^"]*"|'[^']*'/g,"")),b=/\s:([a-zA-Z_][\w-]*)\s*=\s*"([^"]*)"/g,w,C=x,k=!1;while((w=b.exec(x))!==null){if(ps(x,w.index,!0)?.kind==="attribute")continue;let A=w[1],I=w[2];if(gc(A))continue;if(H(I,c))continue;if(I.includes("()")&&!I.includes(".get(")||I.includes("$store")||I.includes("$ref"))continue;try{let U=Object.keys(t),M=Object.values(t),L=I.match(/^([a-zA-Z_$][\w$]*)/);if(L&&!U.includes(L[1])&&!["true","false","null","undefined","Math","JSON","String","Number","Array","Object","Date","parseInt","parseFloat"].includes(L[1]))continue;let q=JSON.stringify([U,I]),N=v.get(q);if(!N){if(N=Function(...U,`return (${I})`),v.size>=y)v.clear();v.set(q,N)}let _=N(...M);if(A==="class"){let O=V(Ft(_));if(O){let B=C.match(/\sclass="([^"]*)"/);if(B)C=C.replace(B[0],()=>` class="${B[1]} ${O}"`);else C=C.replace(w[0],()=>` class="${O}"`)}else C=C.replace(w[0],"");k=!0;continue}if(zn.has(A)){if(_)C=C.replace(w[0],` ${A}`);else C=C.replace(w[0],"");k=!0;continue}if(_===null||_===void 0||_===!1)C=C.replace(w[0],"");else{let O=m&&typeof _==="object"?JSON.stringify(_):String(_),B=mn(A,O);C=C.replace(w[0],()=>` ${A}="${B}"`)}k=!0}catch(U){if(U instanceof oe)throw U;continue}}if(k){let A=a[3]?" /":"",U=`<${a[1]}${C}${A}>`;h.push({start:a.index,end:a.index+S.length,replacement:U})}}if(h.length>0){let S=Array(h.length*2+1),x=0;for(let m=0;m<h.length;m++){let{start:b,end:w,replacement:C}=h[m];S[m*2]=s.slice(x,b),S[m*2+1]=C,x=w}S[h.length*2]=s.slice(x),s=S.join("")}return s}import Ht from"fs";import qt from"path";var Xt=!1;function Fn(e,t,s,i=!1,o=new Set){let a={static:{},staticNames:{},serverDynamic:{},serverDynamicNames:{},clientReactive:{},events:{}},c=new Set(Array.isArray(t.__stx_client_signal_names)?t.__stx_client_signal_names:[]),g=(y)=>{if(c.size===0)return!1;let S=r(y),x=S.match(/^\s*[!+~(-]*\s*([a-zA-Z_$][\w$]*)/)?.[1];if(x&&c.has(x))return!0;for(let m of c){let b=m.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");if(new RegExp(`(?:^|[^\\w$.])${b}\\s*\\(`).test(S))return!0}return!1},l=new Set(mc),h=(y)=>{if(!y.includes("-")||y.startsWith("@")||y.startsWith(":")||y.startsWith("x-")||y.startsWith("__"))return y;if(y.startsWith("aria-")||y.startsWith("data-"))return y;return y.replace(/-([a-z0-9])/g,(S,x)=>x.toUpperCase())},v=(y,S)=>{let x=h(y);if(a.static[x]=S,x!==y)a.staticNames[x]=y};for(let[y,S]of Object.entries(e)){let x=y.startsWith("x-")&&!l.has(y)&&!y.startsWith("x-bind:")&&!y.startsWith("x-on:")?`:${y.slice(2)}`:y;if(x.startsWith("@")){a.events[x]=S;continue}if(x.startsWith("__stx_")){let m=h(x.slice(6));a.serverDynamic[m]=Ut(S,s);continue}if(x.startsWith(":")){let m=h(x.slice(1)),b=S===se?m:S;if(m==="if"||m==="for"||m==="show"){a.clientReactive[m]=b;continue}if(i){a.clientReactive[m]=b;continue}if(H(b,o)){a.clientReactive[m]=b;continue}if(g(b)){a.clientReactive[m]=b;continue}try{if(!p(b)){if(s.debug)console.error(`Unsafe expression in :${m} binding: ${b}`);a.clientReactive[m]=b;continue}let w=Object.keys(t),C=new Set(["true","false","null","undefined","typeof","instanceof","in","of","new","this","return","void","delete","throw","if","else"]),k=new Set(Array.isArray(t.__stx_client_declared_names)?t.__stx_client_declared_names:[]);if(tt(b).some((M)=>!C.has(M)&&!w.includes(M)&&(!(M in globalThis)||k.has(M)))){a.clientReactive[m]=b;continue}let U=u(b,w)(...Object.values(t));if(a.serverDynamic[m]=U,m!==x.slice(1)&&a.serverDynamicNames)a.serverDynamicNames[m]=x.slice(1)}catch{a.clientReactive[m]=b}continue}if(typeof S==="string"&&S.includes("{{")&&S.includes("}}")){let m=Hn(S,o);if(m!==null){a.clientReactive[h(x)]=m;continue}let b=S.match(/^\{\{\s*([\s\S]+?)\s*\}\}$/);if(b)try{let w=b[1];if(p(w)){let k=u(w,Object.keys(t))(...Object.values(t));v(x,k!=null?String(k):"")}else{if(s.debug)console.error(`Unsafe expression in ${x}: ${w}`);v(x,S)}}catch(w){if(s.debug)console.error(`Error evaluating expression for ${x}:`,w);v(x,S)}else{let w=S,C=/\{\{\s*([\s\S]+?)\s*\}\}/g,k;while((k=C.exec(S))!==null)try{let A=k[1];if(!p(A)){if(s.debug)console.error(`Unsafe expression in ${x}: ${A}`);continue}let U=u(A,Object.keys(t))(...Object.values(t));w=w.replace(k[0],String(U??""))}catch(A){if(s.debug)console.error(`Error evaluating expression in ${x}:`,A)}v(x,w)}continue}v(x,S===se?"true":at(S))}return a}function Hn(e,t){if(t.size===0)return null;let s=/\{\{\s*([\s\S]+?)\s*\}\}/g,i=[...e.matchAll(s)];if(!i.some((g)=>H(g[1],t)))return null;let o=e.match(/^\{\{\s*([\s\S]+?)\s*\}\}$/);if(o&&i.length===1)return o[1];let a="",c=0;for(let g of i)a+=e.slice(c,g.index).replace(/[`\\$]/g,(l)=>`\\${l}`),a+=`\${${g[1]}}`,c=g.index+g[0].length;return a+=e.slice(c).replace(/[`\\$]/g,(g)=>`\\${g}`),`\`${a}\``}var qn=[[/@if\s*\(/,"@endif"],[/@unless\s*\(/,"@endunless"]];function Xn(e,t,s){if(!e.includes("@"))return e;if(!qn.some(([o,a])=>o.test(e)&&e.includes(a)))return e;try{return re(e,t,s)}catch{return e}}function me(e){let t={},s=0,i=e.length;while(s<i){while(s<i&&/\s/.test(e[s]))s++;if(s>=i)break;let o="";while(s<i&&!/[\s=]/.test(e[s]))o+=e[s],s++;if(!o)break;while(s<i&&/\s/.test(e[s]))s++;if(s<i&&e[s]==="="){s++;while(s<i&&/\s/.test(e[s]))s++;let a="";if(s<i&&(e[s]==='"'||e[s]==="'")){let c=e[s];s++;while(s<i){let g=e[s];if(g==="\\"&&s+1<i){s++,a+=e[s],s++;continue}if(g===c){s++;break}a+=g,s++}}else if(e[s]==="{"){a=ct(e,s),s+=a.length;let c=Wt(a);if(c!==null){t[`:${o}`]=c;continue}}else while(s<i&&!/\s/.test(e[s]))a+=e[s],s++;t[o]=a}else t[o]=se}return t}function Zt(e){return Object.entries(e).map(([t,s])=>s===se?t:`${t}="${Zn(s)}"`).join(" ")}function Zn(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Vn(e){let t=new Set,s=/<([A-Z][A-Za-z0-9]*|stx-[a-z0-9-]+)\b[^>]*>/g,i;while((i=s.exec(e))!==null){let o=i[1];if(le.isBuiltin(o))t.add(o)}return[...t].sort()}async function $l(e,t,s,i,o){if(!/import\s/.test(e))return e;if(!t.__importedComponents)t.__importedComponents=new Map;let a=t.__importedComponents,c=qt.dirname(s),g=[],l=/<script\b([^>]*)>([\s\S]*?)<\/script>/gi;for(let y of e.matchAll(l)){let[S,x,m]=y,b=/import\s+(?:(\{[^}]*\})|([A-Za-z_$][\w$]*))\s+from\s+['"]([^'"]+)['"]\s*;?\s*\n?/g,w=m,C,k=[];while((C=b.exec(m))!==null){let[A,I,U,M]=C,L=null,q=null;if(M.startsWith(".")||M.startsWith("/")){let O=qt.resolve(c,M);if(O.endsWith(".stx"))q=O;else{let B=`${O}.stx`;try{if(Ht.statSync(B).isFile())q=B}catch{try{if(Ht.statSync(O).isDirectory())L=O}catch{}}}}else L=ls(M,c);if(!L&&!q)continue;let N=!1,_=(O,B)=>{a.set(O,B),a.set(O.toLowerCase(),B);let z=O.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();a.set(z,B),o.add(B)};if(U&&q)_(U,q),N=!0;else if(I){let O=I.slice(1,-1).split(",").map((z)=>z.trim()).filter(Boolean).map((z)=>{let K=z.match(/^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/);if(K)return{source:K[1],local:K[2]};return{source:z,local:z}}),B=L?cs(L):null;for(let{source:z,local:K}of O){let D=null;if(q)D=q;else if(B)D=B.get(z)??B.get(z.toLowerCase())??B.get(z.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase())??null;if(D)_(K,D),N=!0}}if(N)k.push({start:C.index,end:C.index+A.length})}if(k.length===0)continue;for(let A=k.length-1;A>=0;A--)w=w.slice(0,k[A].start)+w.slice(k[A].end);g.push({start:y.index,end:y.index+S.length,value:`<script${x}>${w}</script>`})}if(g.length===0)return e;let h=[],v=0;for(let y of g)h.push(e.slice(v,y.start),y.value),v=y.end;return h.push(e.slice(v)),h.join("")}async function Gn(e,t,s,i,o){let a=e;if(!t.__importedComponents)t.__importedComponents=new Map;let c=t.__importedComponents,g=/@import\s*\(\s*([^)]+)\s*\)/g,l;while((l=g.exec(a))!==null){let[h,v]=l,y=v.split(",").map((S)=>S.trim().replace(/^['"]|['"]$/g,"")).filter((S)=>S.length>0);for(let S of y){let x=S.split("/"),b=x[x.length-1].replace(/\.stx$/,""),w=b.includes("-")?b.split("-").map((A)=>A.charAt(0).toUpperCase()+A.slice(1)).join(""):b.charAt(0).toUpperCase()+b.slice(1),C=null,k=us(S,s,i);for(let A of k)try{if(await Bun.file(A).exists()){C=A;break}}catch{}if(C){c.set(w,C),c.set(b,C),c.set(b.toLowerCase(),C);let A=w.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();if(c.set(A,C),o.add(C),i.debug)console.log(`Imported component: ${w} -> ${C}`)}else if(i.debug)console.warn(`Could not resolve imported component: ${S}`)}a=a.replace(h,""),g.lastIndex=0}return a}async function Kn(e,t,s,i,o){let a=e,c=i.componentsDir||"components";if(!t.__processedComponents)t.__processedComponents=new Set;let g=t.__processedComponents,l=/@component\s*\(/g,h;while((h=l.exec(a))!==null){let v=h.index,y=v+h[0].length-1,S=1,x=y+1;while(x<a.length&&S>0){if(a[x]==="(")S++;else if(a[x]===")"){if(S--,S===0)break}x++}if(S!==0)break;let m=a.substring(y+1,x),b=x+1,w=m.match(/^\s*['"]([^'"]+)['"]/);if(!w){l.lastIndex=0;continue}let C=w[1],k,A=m.slice(w[0].length),I=A.match(/^\s*,\s*/);if(I)k=A.slice(I[0].length).trim();let U={};if(k)try{U=E(k,t)}catch(O){let B=O instanceof Error?O.message:String(O);a=a.replace(a.substring(v,b),`[Error parsing component props: ${B}]`);continue}let M="",L=b,N=a.substring(b).match(/^([\s\S]*?)@endcomponent/);if(N)M=N[1].trim(),L=b+N[0].length;let _=await je(C,U,M,c,t,s,i,g,o);a=a.substring(0,v)+_+a.substring(L),l.lastIndex=0}return a}async function Jn(e,t,s,i,o){if(!e)return e;let a=e,c=i.componentsDir||"components";if(!t.__processedComponents)t.__processedComponents=new Set;let g=t.__processedComponents,l=er(a);if(l.size>0){let b=Array.isArray(t.__stx_client_declared_names)?t.__stx_client_declared_names:[];t.__stx_client_declared_names=[...new Set([...b,...l])]}let h=G(a);a=h.output;let v=et(t);return a=await m(a,/[a-z][a-z0-9]*-[a-z0-9-]*/,!1),a=await m(a,/[A-Z][a-zA-Z0-9]*/,!0,Lt(lr)),a=await m(a,/[a-z][a-z0-9]*/,!1,lr),a=h.restore(a),a;async function m(b,w,C,k){if(!b)return b;let A=b,I=zt(A,w,k),U=lt(A),M=new Map;for(let N=I.length-1;N>=0;N--){let _=I[N],O=C?j(_.tagName):_.tagName,B=me(Xn(_.attributes,t,s)),z=U.filter(({start:Z,end:P})=>_.startIndex>=Z&&_.startIndex<P),K=z.length>0,D=new Set(v);for(let Z of z)for(let P of Z.names)D.add(P);let W=Fn(B,t,i,K,D);if(typeof W.clientReactive.for==="string")for(let Z of X(W.clientReactive.for))D.add(Z);let ce=le.getBuiltin(_.tagName),we=ce?await pr(_.tagName,c,t,s,i):!1;if(ce&&!we){let Z={context:t,filePath:s,options:i,dependencies:o},P=ce.render(W,_.content,Z);if(Object.keys(W.events).length>0){let F=Zt(W.events);P=P.replace(/^(\s*<[a-zA-Z][a-zA-Z0-9-]*)/,`$1 ${F}`)}if(Object.keys(W.clientReactive).length>0)P=Vt(P,W.clientReactive);M.set(N,P);continue}if(!C&&_.tagName.includes("-")&&!await pr(O,c,t,s,i))continue;let Y={};for(let[Z,P]of Object.entries(W.static))Y[Z]=P;for(let[Z,P]of Object.entries(W.serverDynamic))Y[Z]=P;let ne={declaredProps:new Set,consumedProps:new Set,reactiveProps:Object.keys(W.clientReactive),events:Object.keys(W.events)},T=await je(O,Y,h.restore(_.content),c,t,s,i,g,o,[...D],ne,_.tagName);if(T=Yn(T,W,ne.declaredProps,ne.consumedProps,i._nativeHostAttrs),i._nativeHostAttrs){let Z=ne.reactiveProps.filter((te)=>!ne.consumedProps.has(te)&&!["if","for","show","key","ref"].includes(te)).map(j),P=ut(T,!0);if(Z.length&&P){if(!Object.hasOwn(me(T.slice(P.insertPos,P.tagEnd)),"data-stx-native-host-root"))T=T.slice(0,P.insertPos)+' data-stx-native-host-root="true"'+T.slice(P.insertPos);let te=ve(T);T=T.slice(0,te.insertPos)+` data-stx-native-forward="${Z.join(" ")}"`+T.slice(te.insertPos)}let F=ut(T,!0);if(F){let te=me(T.slice(F.insertPos,F.tagEnd)),Se=ve(T),Kt=me(T.slice(Se.insertPos,Se.tagEnd));if(Object.hasOwn(te,"data-stx-native-host-root")&&!Object.hasOwn(Kt,"data-stx-native-host-owner"))T=T.slice(0,Se.insertPos)+" data-stx-native-host-owner"+T.slice(Se.insertPos)}}if(Object.keys(W.events).length>0){let Z=ve(T);if(Z){let P=Zt(W.events),F=Object.keys(W.events).map((te)=>te.replace(/^@/,"").split(".")[0]).join(" ");T=T.substring(0,Z.insertPos)+` data-stx-parent-events="${F}" ${P}`+T.substring(Z.insertPos)}}if(Object.keys(W.clientReactive).length>0)T=Vt(T,W.clientReactive);M.set(N,T)}if(M.size===0)return A;let L="",q=0;for(let N=0;N<I.length;N++){let _=M.get(N);if(_===void 0)continue;L+=A.slice(q,I[N].startIndex),L+=_,q=I[N].endIndex}return L+=A.slice(q),L}}function Vt(e,t){let s=new Set(["if","for"]),i=new Set(["show"]),o=Object.entries(t).filter(([v])=>!s.has(v)),a=o.filter(([v])=>!i.has(v)).map(([v])=>j(v)).join(" "),c=e,g=o.length>0?ve(c):null;if(g){let v=o.map(([S,x])=>`:${j(S)}="${x.replace(/"/g,"&quot;")}"`).join(" "),y=a?` data-stx-parent-bindings="${a}"`:"";c=c.substring(0,g.insertPos)+`${y} ${v}`+c.substring(g.insertPos)}let l=t.if;if(l)c=`<template :if="${l.replace(/"/g,"&quot;")}">${c}</template>`;let h=t.for;if(h){let v=t.key,y=v?` :key="${v.replace(/"/g,"&quot;")}"`:"";c=`<template :for="${h.replace(/"/g,"&quot;")}"${y}>${c}</template>`}return c}function Yn(e,t,s=new Set,i=new Set,o=!1){let a=ut(e,o);if(!a)return e;let c=e.slice(a.insertPos,a.tagEnd),g=t.serverDynamic.class??t.static.class;if(o&&typeof g==="string"&&g&&!i.has("class")){let m=/(^|\s)class\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i,b=m.test(c)?c.replace(m,(w,C,k,A,I)=>`${C}class="${R(`${at(k??A??I)} ${g}`)}"`):` class="${R(g)}"${c}`;e=e.slice(0,a.insertPos)+b+e.slice(a.tagEnd),a.tagEnd+=b.length-c.length,c=b}let l=o||/\bdata-native(?:\s|=)/i.test(c),h=l?i:s,v=new Set(Object.keys(me(c))),y=new Set(["class","className"]);for(let m of Object.keys(t.static)){let b=t.staticNames[m]??m;if(v.has(b)||h.has(m)||!l&&!Fe(b))y.add(m)}for(let m of Object.keys(t.serverDynamic)){let b=t.serverDynamicNames?.[m]??m;if(v.has(b)||h.has(m)||!l&&!Fe(b))y.add(m)}let S=[];if(l){for(let[m,b]of Object.entries(t.static)){if(y.has(m)||b!==!0&&b!==se)continue;y.add(m),S.push(`${R(t.staticNames?.[m]??m)}="true"`)}for(let[m,b]of Object.entries(t.serverDynamic)){if(y.has(m)||b!==!0)continue;y.add(m),S.push(`${R(t.serverDynamicNames?.[m]??m)}="true"`)}}let x=[...ie(t,y),...ae(t,y),...S];if(l){for(let[m,b]of Object.entries(t.serverDynamic)){if(y.has(m)||b!==!1)continue;let w=t.serverDynamicNames?.[m]??m;x.push(`${R(w)}="false"`)}for(let[m,b]of Object.entries(t.serverDynamic)){if(y.has(m)||b===null||typeof b!=="object")continue;let w=JSON.stringify(b);if(w!==void 0){let C=t.serverDynamicNames?.[m]??m;x.push(`${R(C)}="${R(w)}"`)}}}if(x.length===0)return e;return`${e.slice(0,a.insertPos)} ${x.join(" ")}${e.slice(a.insertPos)}`}function ve(e){let t=Gt(e,0);if(t)return t;let s=/<([a-zA-Z][a-zA-Z0-9-]*)\b[^>]*\bdata-stx-scope(?:\s|=|>)/i.exec(e);if(s)return{insertPos:s.index+1+s[1].length,tagEnd:ft(e,s.index+1+s[1].length)};return null}function ut(e,t=!1){let s=ve(e);if(!s)return null;let i=e.slice(s.insertPos,s.tagEnd),o=/\bdata-stx-component-wrapper(?:\s|=|>|$)/i.test(i)?Gt(e,s.tagEnd+1):s;return o&&t?Qn(e,o)??o:o}function Qn(e,t){if(!e.includes("data-stx-native-host-root"))return null;let s=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),i=e.lastIndexOf("<",t.insertPos),o=0,a;while(i>=0&&i<e.length){if(e.startsWith("<!--",i)){let v=e.indexOf("-->",i+4);if(v<0)return null;i=e.indexOf("<",v+3);continue}let c=/^<(\/?)([a-z][\w-]*)\b/i.exec(e.slice(i));if(!c){i=e.indexOf("<",i+1);continue}let g=c[2].toLowerCase(),l=i+c[0].length,h=ft(e,l);if(c[1]){if(o--,a!==void 0&&o<a)a=void 0;if(o<=0)return null}else if(g==="script"||g==="style"){let v=new RegExp(`</${g}\\s*>`,"gi");if(v.lastIndex=h+1,!v.exec(e))return null;i=e.indexOf("<",v.lastIndex);continue}else{let v=me(e.slice(l,h)),y=o>0&&(Object.hasOwn(v,"data-stx-component-wrapper")||Object.hasOwn(v,"data-stx-native-host-owner"));if(a===void 0&&!y&&Object.hasOwn(v,"data-stx-native-host-root"))return{insertPos:l,tagEnd:h};if(!s.has(g)&&e[h-1]!=="/"){if(o++,a===void 0&&y)a=o}else if(o===0)return null}i=e.indexOf("<",h+1)}return null}function Gt(e,t){let s=t;while(s<e.length){let i=e.slice(s),o=i.match(/^\s+/);if(o){s+=o[0].length;continue}if(i.startsWith("<!--")){let g=e.indexOf("-->",s+4);if(g===-1)return null;s=g+3;continue}let a=i.match(/^<(script|style)\b[^>]*>/i);if(a){let g=`</${a[1].toLowerCase()}>`,l=e.toLowerCase().indexOf(g,s+a[0].length);if(l===-1)return null;s=l+g.length;continue}let c=i.match(/^<([a-zA-Z][a-zA-Z0-9-]*)(?:\s|>|\/)/);if(!c)return null;return{insertPos:s+1+c[1].length,tagEnd:ft(e,s+1+c[1].length)}}return null}function ft(e,t){let s="";for(let i=t;i<e.length;i++){let o=e[i];if(s){if(o==="\\")i++;else if(o===s)s=""}else if(o==='"'||o==="'")s=o;else if(o===">")return i}return e.length}function er(e){let t=new Set;for(let s of e.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)){let i=s[1];if(!/\bclient\b/.test(i)||/\bserver\b/.test(i))continue;for(let o of Io(s[2]))t.add(o);for(let o of s[2].matchAll(/^\s*import\s+(?:type\s+)?(?:([\w$]+)\s*,?\s*)?(?:\{([^}]*)\}|\*\s+as\s+([\w$]+))?\s*from\s/gm)){if(o[1])t.add(o[1]);if(o[3])t.add(o[3]);for(let a of(o[2]??"").split(",")){let c=a.replace(/^\s*type\s+/,"").split(/\s+as\s+/).pop().trim();if(/^[A-Za-z_$][\w$]*$/.test(c))t.add(c)}}}return t}async function Vr(e,t,s,i,o){if(!Xt)Dt(le),Xt=!0;let a=await $l(e,t,s,i,o);a=await Gn(a,t,s,i,o),a=await Kn(a,t,s,i,o);let c=[];for(let g=0;g<3;g++){let l=c.length,h=de(a,Ie,(y,S)=>`\x00STX_COMPONENT_COMMENT_${l+S}\x00`,`STX_COMPONENT_COMMENT:${l}`);c.push(...h.tokens);let v=a;if(a=await Jn(h.output,t,s,i,o),a===v)break}if(c.length>0)a=a.replace(/\x00STX_COMPONENT_COMMENT_(\d+)\x00/g,(g,l)=>c[Number(l)]??"");if(i.debug){let g=Vn(a);if(g.length>0)console.warn(`[stx] ${s}: unresolved component tag(s) after render passes: ${g.join(", ")}. Check nested component output for malformed root tags or recursive component markup.`)}return a}
42
42
  export{so,oo,io,hp,Hr,yp,la,$l,Vr};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{y}from"./chunk-w28wc7mv.js";function Xe(e,r){let n=v(e,r);return n.ok?{expression:n.expression,endPos:n.endPos}:null}function v(e,r){let n=r;while(n<e.length&&/\s/.test(e[n]))n++;if(e[n]!=="(")return{ok:!1,reason:"missing-open-paren",pos:n};let c=y(e,"(",")",n);if(c===-1)return{ok:!1,reason:"unclosed-paren",pos:n};return{ok:!0,expression:e.slice(n+1,c),endPos:c+1}}function k(e,r){let n=e.lastIndexOf("<",r);if(n===-1)return!1;return n>e.lastIndexOf(">",r)}function yt(e,r,n,c){let o=1,i=c,u=new RegExp(`@${r}\\s*\\(`,"g"),a=new RegExp(`@${n}(?![a-z])`,"g");while(i<e.length&&o>0){u.lastIndex=i,a.lastIndex=i;let p=u.exec(e),t=a.exec(e),s=p?p.index:1/0,f=t?t.index:1/0;if(s<f)o++,i=s+p[0].length;else if(f<1/0){if(o--,o===0)return f;i=f+t[0].length}else break}return-1}function P(e,r){let n=e.slice(r).match(/^@if\s*/);if(!n)return null;let c=r+n[0].length,o=Xe(e,c);if(!o)return null;let i=o.endPos,u=yt(e,"if","endif",i);if(u===-1)return null;let a=e.slice(i,u),p=[],t=0,s="if",f=o.expression,l=0,x=0;while(t<a.length){let h=a.indexOf("@",t);if(h===-1)break;t=h;let d=a.substring(h);if(k(a,h)){t++;continue}if(/^@if\s*\(/.test(d)){x++,t++;continue}if(/^@endif(?![a-z])/.test(d)){x--,t+=6;continue}if(x===0){let g=d.match(/^@elseif\s*/);if(g){p.push({type:s,condition:f,content:a.substring(l,t),start:i+l,end:i+t});let m=t+g[0].length,b=Xe(a,m);if(!b){t++;continue}s="elseif",f=b.expression,t=b.endPos,l=t;continue}else if(/^@else(?![a-z])/.test(d)){p.push({type:s,condition:f,content:a.substring(l,t),start:i+l,end:i+t}),s="else",f=void 0,t+=5,l=t;continue}}t++}return p.push({type:s,condition:f,content:a.slice(l),start:i+l,end:i+a.length}),{fullMatch:e.slice(r,u+6),branches:p,start:r,end:u+6}}function rn(e){let r=[],n=/@if\s*\(/g,c=n.exec(e);while(c!==null){if(r.some((u)=>c.index>u.start&&c.index<u.end)){c=n.exec(e);continue}let i=P(e,c.index);if(i)r.push(i),n.lastIndex=i.end;c=n.exec(e)}return r}function Kr(e,r,n){let c=[],o=new RegExp(`@${r}\\s*\\(`,"g"),i=o.exec(e);while(i!==null){if(c.some((d)=>i.index>d.start&&i.index<d.end)){i=o.exec(e);continue}let a=i.index,p=a+i[0].length-1,t=y(e,"(",")",p);if(t===-1){i=o.exec(e);continue}let s=e.slice(p+1,t),f=t+1,l=yt(e,r,n,f);if(l===-1){i=o.exec(e);continue}let x=e.slice(f,l),h=l+`@${n}`.length;c.push({fullMatch:e.slice(a,h),name:r,params:s,content:x,start:a,end:h}),o.lastIndex=h,i=o.exec(e)}return c}function mo(e,r){let n=e.slice(r).match(/^@switch\s*/);if(!n)return null;let c=r+n[0].length,o=Xe(e,c);if(!o)return null;let i=o.endPos,u=yt(e,"switch","endswitch",i);if(u===-1)return null;let a=e.slice(i,u),p=[],t=0,s=null,f=0;while(t<a.length){let l=a.slice(t),x=l.match(/^@switch\s*\(/),h=l.match(/^@endswitch(?![a-z])/);if(x){if(f++,s)s.content+=x[0];t+=x[0].length;continue}if(h){if(f--,s)s.content+=h[0];t+=h[0].length;continue}if(f>0){if(s)s.content+=a[t];t++;continue}let d=l.match(/^@case\s*/),g=l.match(/^@default(?![a-z])/),m=l.match(/^@break(?![a-z])/);if(d&&l.startsWith("@case")){if(s)p.push(s);let b=t+d[0].length,E=Xe(a,b);if(!E){t++;continue}s={type:"case",value:E.expression,content:""},t=E.endPos}else if(g&&l.startsWith("@default")){if(s)p.push(s);s={type:"default",content:""},t+=g[0].length}else if(m&&l.startsWith("@break"))t+=m[0].length;else{if(s)s.content+=a[t];t++}}if(s)p.push(s);return{fullMatch:e.slice(r,u+10),expression:o.expression,cases:p,start:r,end:u+10}}export{Xe,yt,rn,Kr,mo};
2
+ import{y}from"./chunk-3tp7r57c.js";function Xe(e,r){let n=v(e,r);return n.ok?{expression:n.expression,endPos:n.endPos}:null}function v(e,r){let n=r;while(n<e.length&&/\s/.test(e[n]))n++;if(e[n]!=="(")return{ok:!1,reason:"missing-open-paren",pos:n};let c=y(e,"(",")",n);if(c===-1)return{ok:!1,reason:"unclosed-paren",pos:n};return{ok:!0,expression:e.slice(n+1,c),endPos:c+1}}function k(e,r){let n=e.lastIndexOf("<",r);if(n===-1)return!1;return n>e.lastIndexOf(">",r)}function yt(e,r,n,c){let o=1,i=c,u=new RegExp(`@${r}\\s*\\(`,"g"),a=new RegExp(`@${n}(?![a-z])`,"g");while(i<e.length&&o>0){u.lastIndex=i,a.lastIndex=i;let p=u.exec(e),t=a.exec(e),s=p?p.index:1/0,f=t?t.index:1/0;if(s<f)o++,i=s+p[0].length;else if(f<1/0){if(o--,o===0)return f;i=f+t[0].length}else break}return-1}function P(e,r){let n=e.slice(r).match(/^@if\s*/);if(!n)return null;let c=r+n[0].length,o=Xe(e,c);if(!o)return null;let i=o.endPos,u=yt(e,"if","endif",i);if(u===-1)return null;let a=e.slice(i,u),p=[],t=0,s="if",f=o.expression,l=0,x=0;while(t<a.length){let h=a.indexOf("@",t);if(h===-1)break;t=h;let d=a.substring(h);if(k(a,h)){t++;continue}if(/^@if\s*\(/.test(d)){x++,t++;continue}if(/^@endif(?![a-z])/.test(d)){x--,t+=6;continue}if(x===0){let g=d.match(/^@elseif\s*/);if(g){p.push({type:s,condition:f,content:a.substring(l,t),start:i+l,end:i+t});let m=t+g[0].length,b=Xe(a,m);if(!b){t++;continue}s="elseif",f=b.expression,t=b.endPos,l=t;continue}else if(/^@else(?![a-z])/.test(d)){p.push({type:s,condition:f,content:a.substring(l,t),start:i+l,end:i+t}),s="else",f=void 0,t+=5,l=t;continue}}t++}return p.push({type:s,condition:f,content:a.slice(l),start:i+l,end:i+a.length}),{fullMatch:e.slice(r,u+6),branches:p,start:r,end:u+6}}function rn(e){let r=[],n=/@if\s*\(/g,c=n.exec(e);while(c!==null){if(r.some((u)=>c.index>u.start&&c.index<u.end)){c=n.exec(e);continue}let i=P(e,c.index);if(i)r.push(i),n.lastIndex=i.end;c=n.exec(e)}return r}function Gr(e,r,n){let c=[],o=new RegExp(`@${r}\\s*\\(`,"g"),i=o.exec(e);while(i!==null){if(c.some((d)=>i.index>d.start&&i.index<d.end)){i=o.exec(e);continue}let a=i.index,p=a+i[0].length-1,t=y(e,"(",")",p);if(t===-1){i=o.exec(e);continue}let s=e.slice(p+1,t),f=t+1,l=yt(e,r,n,f);if(l===-1){i=o.exec(e);continue}let x=e.slice(f,l),h=l+`@${n}`.length;c.push({fullMatch:e.slice(a,h),name:r,params:s,content:x,start:a,end:h}),o.lastIndex=h,i=o.exec(e)}return c}function mo(e,r){let n=e.slice(r).match(/^@switch\s*/);if(!n)return null;let c=r+n[0].length,o=Xe(e,c);if(!o)return null;let i=o.endPos,u=yt(e,"switch","endswitch",i);if(u===-1)return null;let a=e.slice(i,u),p=[],t=0,s=null,f=0;while(t<a.length){let l=a.slice(t),x=l.match(/^@switch\s*\(/),h=l.match(/^@endswitch(?![a-z])/);if(x){if(f++,s)s.content+=x[0];t+=x[0].length;continue}if(h){if(f--,s)s.content+=h[0];t+=h[0].length;continue}if(f>0){if(s)s.content+=a[t];t++;continue}let d=l.match(/^@case\s*/),g=l.match(/^@default(?![a-z])/),m=l.match(/^@break(?![a-z])/);if(d&&l.startsWith("@case")){if(s)p.push(s);let b=t+d[0].length,E=Xe(a,b);if(!E){t++;continue}s={type:"case",value:E.expression,content:""},t=E.endPos}else if(g&&l.startsWith("@default")){if(s)p.push(s);s={type:"default",content:""},t+=g[0].length}else if(m&&l.startsWith("@break"))t+=m[0].length;else{if(s)s.content+=a[t];t++}}if(s)p.push(s);return{fullMatch:e.slice(r,u+10),expression:o.expression,cases:p,start:r,end:u+10}}export{Xe,yt,rn,Gr,mo};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{Broadcast as s,BroadcastServer as h}from"ts-broadcasting";import{channel as Ju}from"ts-broadcasting";import{Broadcast as Yu,BroadcastServer as Zu}from"ts-broadcasting";var e=null,u=[];function Hu(){return e}async function Vu(n){if(e)return e;let t=n.driver??"bun",r=n.host??"0.0.0.0",c=n.port??6001,l=n.scheme??"ws",a={verbose:n.verbose??!1,driver:t,default:t,connections:{[t]:{driver:t,host:r,port:c,scheme:l}}};return e=new h(a),s.setServer(e),await e.start(),e}async function Uu(){for(let n of u)clearInterval(n);if(u.length=0,!e)return;await e.stop(),e=null}async function Wu(n){let t=await import(n),r=t.default??t;if(typeof r!=="function")throw Error(`routes/channels.ts must export a default function, got ${typeof r}`);let c=0;return r({channel(a,o){if(c++,o.authorize&&e)e.channels.channel(a,o.authorize);if(o.interval&&o.data){let d=o.event??`${a}.updated`,p=o.data,v=setInterval(async()=>{try{let g=await p();Fc(a,d,g)}catch{}},o.interval);u.push(v)}}}),c}var f=!1;function i(){if(e)return!0;if(!f)f=!0,console.warn("[stx] broadcast() called before server started \u2014 messages will be sent once broadcasting is ready");return!1}function Fc(n,t,r){if(!i())return;s.send(n,t,r)}function qu(n,t,r){if(!i())return;s.toUser(n,t,r)}function Gu(n,t,r){if(!i())return;s.toUsers(n,t,r)}function Ku(n,t,r){if(!i())return;s.send(`private-${n}`,t,r)}function Xu(n,t,r){if(!i())return;s.presence(n,t,r)}
3
- export{Hu,Vu,Uu,Wu,Fc,qu,Gu,Ku,Xu,Ju,Yu,Zu};
2
+ import{Broadcast as s,BroadcastServer as h}from"ts-broadcasting";import{channel as Ju}from"ts-broadcasting";import{Broadcast as Yu,BroadcastServer as Zu}from"ts-broadcasting";var e=null,u=[];function Hu(){return e}async function Vu(n){if(e)return e;let t=n.driver??"bun",r=n.host??"0.0.0.0",c=n.port??6001,l=n.scheme??"ws",a={verbose:n.verbose??!1,driver:t,default:t,connections:{[t]:{driver:t,host:r,port:c,scheme:l}}};return e=new h(a),s.setServer(e),await e.start(),e}async function Uu(){for(let n of u)clearInterval(n);if(u.length=0,!e)return;await e.stop(),e=null}async function Wu(n){let t=await import(n),r=t.default??t;if(typeof r!=="function")throw Error(`routes/channels.ts must export a default function, got ${typeof r}`);let c=0;return r({channel(a,o){if(c++,o.authorize&&e)e.channels.channel(a,o.authorize);if(o.interval&&o.data){let d=o.event??`${a}.updated`,p=o.data,v=setInterval(async()=>{try{let g=await p();Fc(a,d,g)}catch{}},o.interval);u.push(v)}}}),c}var f=!1;function i(){if(e)return!0;if(!f)f=!0,console.warn("[stx] broadcast() called before server started \u2014 messages will be sent once broadcasting is ready");return!1}function Fc(n,t,r){if(!i())return;s.send(n,t,r)}function qu(n,t,r){if(!i())return;s.toUser(n,t,r)}function Ku(n,t,r){if(!i())return;s.toUsers(n,t,r)}function Gu(n,t,r){if(!i())return;s.send(`private-${n}`,t,r)}function Xu(n,t,r){if(!i())return;s.presence(n,t,r)}
3
+ export{Hu,Vu,Uu,Wu,Fc,qu,Ku,Gu,Xu,Ju,Yu,Zu};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{up,ia,dp,aa,Sl,kl,nn,Kn,pp,_l,Cl,fp,h}from"./chunk-fb84n8kz.js";import"./chunk-fbdmsw5j.js";import"./chunk-t3e5tv4h.js";import"./chunk-8x34g2ad.js";import"./chunk-t6m5d64b.js";import"./chunk-3tp7r57c.js";import"./chunk-6beg47t4.js";import"./chunk-gtktv6nn.js";export{nn as buildCss,_l as extractClassNames,kl as fingerprintConfig,Cl as generateCss,pp as getCachedCSS,up as getCssServeAsset,h as injectCss,ia as loadCssEngine,aa as loadCssEngineConfig,Kn as rebuildCss,dp as resetCssCache,Sl as resolveUserCssConfig,fp as withLinkedModuleBundles};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{it,at,ct}from"./chunk-tp4eqfxq.js";import"./chunk-gtktv6nn.js";import"./chunk-6beg47t4.js";import{g}from"./chunk-qq40hxg9.js";import"./chunk-w28wc7mv.js";import"./chunk-t6m5d64b.js";import"./chunk-gny4j06b.js";import{Ft,Is,zt,pi,ot,fi,Os,Ht,mi,Vt}from"./chunk-vxnf3xab.js";import M from"fs";import x from"path";function E(t,e){let r=[x.join(t.root,"stx.config.ts"),x.join(t.root,"stx.config.js"),x.join(t.root,"stx.config.mjs")],s=e.debounceMs??300,o=null,a=[];for(let c of r)try{if(!M.existsSync(c))continue;let n=M.watch(c,(d)=>{if(d==="change"){if(o)clearTimeout(o);o=setTimeout(async()=>{fi("Config file changed, restarting...");try{await e.onChange()}catch(p){ot(`Failed to restart: ${p}`)}},s)}});a.push(n)}catch{}return{stop(){if(o)clearTimeout(o);for(let c of a)c.close()}}}import w from"fs";import j from"path";var st=".stx/story/analytics.json",dt=1,A=1e4;class k{storage;storagePath;currentSession=null;dirty=!1;viewStartTimes=new Map;constructor(t){this.storagePath=j.join(t,st),this.storage=this.loadStorage(),this.startSession()}loadStorage(){try{let t=w.readFileSync(this.storagePath,"utf-8");return JSON.parse(t)}catch{return{version:dt,events:[],sessions:[]}}}async save(){if(!this.dirty)return;let t=j.dirname(this.storagePath);if(await w.promises.mkdir(t,{recursive:!0}),this.storage.events.length>A)this.storage.events=this.storage.events.slice(-A);await w.promises.writeFile(this.storagePath,JSON.stringify(this.storage,null,2)),this.dirty=!1}startSession(){this.endSession(),this.currentSession={id:pt(),startTime:Date.now(),componentViews:[]},this.storage.sessions.push(this.currentSession),this.dirty=!0}endSession(){if(this.currentSession)this.currentSession.endTime=Date.now(),this.currentSession=null}track(t){this.storage.events.push({...t,timestamp:Date.now()}),this.dirty=!0}trackView(t,e){if(this.endViewTiming(t),this.viewStartTimes.set(t,Date.now()),this.track({type:"view",componentId:t,variantId:e}),this.currentSession&&!this.currentSession.componentViews.includes(t))this.currentSession.componentViews.push(t)}endViewTiming(t){let e=this.viewStartTimes.get(t);if(e){let r=Date.now()-e;this.track({type:"view",componentId:t,metadata:{duration:r,endView:!0}}),this.viewStartTimes.delete(t)}}trackPropChange(t,e,r){this.track({type:"prop_change",componentId:t,propName:e,metadata:{value:r}})}trackVariantSwitch(t,e){this.track({type:"variant_switch",componentId:t,variantId:e})}trackSearch(t,e){this.track({type:"search",query:t,metadata:{resultCount:e}})}getComponentAnalytics(t,e){let r=this.storage.events.filter((i)=>i.componentId===t),s=r.filter((i)=>i.type==="view"&&!i.metadata?.endView),o=r.filter((i)=>i.type==="prop_change"),a=r.filter((i)=>i.type==="variant_switch"),c={};for(let i of o)if(i.propName)c[i.propName]=(c[i.propName]||0)+1;let n={};for(let i of a)if(i.variantId)n[i.variantId]=(n[i.variantId]||0)+1;let d=new Set(this.storage.sessions.filter((i)=>i.componentViews.includes(t)).map((i)=>i.id)),p=r.filter((i)=>i.metadata?.duration).map((i)=>i.metadata.duration),u=p.length>0?p.reduce((i,l)=>i+l,0)/p.length:0,y=Object.entries(c).sort((i,l)=>l[1]-i[1]).slice(0,5).map(([i])=>i);return{componentId:t,componentName:e,viewCount:s.length,uniqueViews:d.size,lastViewed:s[s.length-1]?.timestamp,propChanges:c,topChangedProps:y,variantViews:n,avgTimeSpent:u}}getMostViewedComponents(t=10){let e=new Map;for(let r of this.storage.events)if(r.type==="view"&&r.componentId&&!r.metadata?.endView)e.set(r.componentId,(e.get(r.componentId)||0)+1);return Array.from(e.entries()).map(([r,s])=>({componentId:r,viewCount:s})).sort((r,s)=>s.viewCount-r.viewCount).slice(0,t)}getMostChangedProps(t=10){let e=new Map;for(let r of this.storage.events)if(r.type==="prop_change"&&r.propName)e.set(r.propName,(e.get(r.propName)||0)+1);return Array.from(e.entries()).map(([r,s])=>({propName:r,changeCount:s})).sort((r,s)=>s.changeCount-r.changeCount).slice(0,t)}getSearchAnalytics(){let t=this.storage.events.filter((o)=>o.type==="search"),e=new Map,r=0;for(let o of t){if(o.query)e.set(o.query,(e.get(o.query)||0)+1);if(o.metadata?.resultCount!==void 0)r+=o.metadata.resultCount}let s=Array.from(e.entries()).map(([o,a])=>({query:o,count:a})).sort((o,a)=>a.count-o.count).slice(0,10);return{totalSearches:t.length,topQueries:s,avgResultCount:t.length>0?r/t.length:0}}clear(){this.storage.events=[],this.storage.sessions=[],this.dirty=!0,this.startSession()}exportAnalytics(){return JSON.stringify({exportedAt:Date.now(),...this.storage},null,2)}}function pt(){return`session-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import S from"fs";import B from"path";var lt=".stx/story/bookmarks.json",mt=1;class P{storage;storagePath;dirty=!1;constructor(t){this.storagePath=B.join(t,lt),this.storage=this.loadStorage()}loadStorage(){try{let t=S.readFileSync(this.storagePath,"utf-8");return JSON.parse(t)}catch{return{version:mt,bookmarks:[]}}}async save(){if(!this.dirty)return;let t=B.dirname(this.storagePath);await S.promises.mkdir(t,{recursive:!0}),await S.promises.writeFile(this.storagePath,JSON.stringify(this.storage,null,2)),this.dirty=!1}addBookmark(t,e,r,s={}){let o={id:ut(),name:s.name||`${t}/${e}`,storyId:t,variantId:e,props:r,created:Date.now(),notes:s.notes,color:s.color};return this.storage.bookmarks.push(o),this.dirty=!0,o}getAllBookmarks(){return[...this.storage.bookmarks]}getBookmarksForStory(t){return this.storage.bookmarks.filter((e)=>e.storyId===t)}getBookmark(t){return this.storage.bookmarks.find((e)=>e.id===t)}isBookmarked(t,e){return this.storage.bookmarks.some((r)=>r.storyId===t&&r.variantId===e)}updateBookmark(t,e){let r=this.getBookmark(t);if(!r)return;return Object.assign(r,e),this.dirty=!0,r}deleteBookmark(t){let e=this.storage.bookmarks.findIndex((r)=>r.id===t);if(e===-1)return!1;return this.storage.bookmarks.splice(e,1),this.dirty=!0,!0}toggleBookmark(t,e,r){let s=this.storage.bookmarks.find((a)=>a.storyId===t&&a.variantId===e);if(s)return this.deleteBookmark(s.id),{added:!1};return{added:!0,bookmark:this.addBookmark(t,e,r)}}exportBookmarks(){return JSON.stringify(this.storage,null,2)}importBookmarks(t,e=!0){let r=JSON.parse(t),s=0;for(let o of r.bookmarks){if(e){let a=this.storage.bookmarks.find((c)=>c.id===o.id);if(a)Object.assign(a,o);else this.storage.bookmarks.push(o)}else this.storage.bookmarks.push(o);s++}if(s>0)this.dirty=!0;return s}}function ut(){return`bm-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}var v=new Set;function N(){return{open(t){v.add(t),t.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close(t){v.delete(t)},message(t,e){}}}function C(t){let e=JSON.stringify({...t,timestamp:t.timestamp||Date.now()});for(let r of v)try{r.send(e)}catch{v.delete(r)}}function V(t,e){C({type:"story-update",data:{storyId:t,...e}})}function H(t,e){C({type:"story-add",data:{storyId:t,...e}})}function O(t){C({type:"story-remove",data:{storyId:t}})}function F(t){return`
2
+ import{it,at,ct}from"./chunk-tp4eqfxq.js";import"./chunk-gtktv6nn.js";import"./chunk-6beg47t4.js";import{g}from"./chunk-t3e5tv4h.js";import"./chunk-3tp7r57c.js";import"./chunk-t6m5d64b.js";import"./chunk-8x34g2ad.js";import{Ft,Is,zt,pi,ot,fi,Os,Ht,mi,Vt}from"./chunk-vxnf3xab.js";import M from"fs";import x from"path";function E(t,e){let r=[x.join(t.root,"stx.config.ts"),x.join(t.root,"stx.config.js"),x.join(t.root,"stx.config.mjs")],s=e.debounceMs??300,o=null,a=[];for(let c of r)try{if(!M.existsSync(c))continue;let n=M.watch(c,(d)=>{if(d==="change"){if(o)clearTimeout(o);o=setTimeout(async()=>{fi("Config file changed, restarting...");try{await e.onChange()}catch(p){ot(`Failed to restart: ${p}`)}},s)}});a.push(n)}catch{}return{stop(){if(o)clearTimeout(o);for(let c of a)c.close()}}}import w from"fs";import j from"path";var st=".stx/story/analytics.json",dt=1,A=1e4;class k{storage;storagePath;currentSession=null;dirty=!1;viewStartTimes=new Map;constructor(t){this.storagePath=j.join(t,st),this.storage=this.loadStorage(),this.startSession()}loadStorage(){try{let t=w.readFileSync(this.storagePath,"utf-8");return JSON.parse(t)}catch{return{version:dt,events:[],sessions:[]}}}async save(){if(!this.dirty)return;let t=j.dirname(this.storagePath);if(await w.promises.mkdir(t,{recursive:!0}),this.storage.events.length>A)this.storage.events=this.storage.events.slice(-A);await w.promises.writeFile(this.storagePath,JSON.stringify(this.storage,null,2)),this.dirty=!1}startSession(){this.endSession(),this.currentSession={id:pt(),startTime:Date.now(),componentViews:[]},this.storage.sessions.push(this.currentSession),this.dirty=!0}endSession(){if(this.currentSession)this.currentSession.endTime=Date.now(),this.currentSession=null}track(t){this.storage.events.push({...t,timestamp:Date.now()}),this.dirty=!0}trackView(t,e){if(this.endViewTiming(t),this.viewStartTimes.set(t,Date.now()),this.track({type:"view",componentId:t,variantId:e}),this.currentSession&&!this.currentSession.componentViews.includes(t))this.currentSession.componentViews.push(t)}endViewTiming(t){let e=this.viewStartTimes.get(t);if(e){let r=Date.now()-e;this.track({type:"view",componentId:t,metadata:{duration:r,endView:!0}}),this.viewStartTimes.delete(t)}}trackPropChange(t,e,r){this.track({type:"prop_change",componentId:t,propName:e,metadata:{value:r}})}trackVariantSwitch(t,e){this.track({type:"variant_switch",componentId:t,variantId:e})}trackSearch(t,e){this.track({type:"search",query:t,metadata:{resultCount:e}})}getComponentAnalytics(t,e){let r=this.storage.events.filter((i)=>i.componentId===t),s=r.filter((i)=>i.type==="view"&&!i.metadata?.endView),o=r.filter((i)=>i.type==="prop_change"),a=r.filter((i)=>i.type==="variant_switch"),c={};for(let i of o)if(i.propName)c[i.propName]=(c[i.propName]||0)+1;let n={};for(let i of a)if(i.variantId)n[i.variantId]=(n[i.variantId]||0)+1;let d=new Set(this.storage.sessions.filter((i)=>i.componentViews.includes(t)).map((i)=>i.id)),p=r.filter((i)=>i.metadata?.duration).map((i)=>i.metadata.duration),u=p.length>0?p.reduce((i,l)=>i+l,0)/p.length:0,y=Object.entries(c).sort((i,l)=>l[1]-i[1]).slice(0,5).map(([i])=>i);return{componentId:t,componentName:e,viewCount:s.length,uniqueViews:d.size,lastViewed:s[s.length-1]?.timestamp,propChanges:c,topChangedProps:y,variantViews:n,avgTimeSpent:u}}getMostViewedComponents(t=10){let e=new Map;for(let r of this.storage.events)if(r.type==="view"&&r.componentId&&!r.metadata?.endView)e.set(r.componentId,(e.get(r.componentId)||0)+1);return Array.from(e.entries()).map(([r,s])=>({componentId:r,viewCount:s})).sort((r,s)=>s.viewCount-r.viewCount).slice(0,t)}getMostChangedProps(t=10){let e=new Map;for(let r of this.storage.events)if(r.type==="prop_change"&&r.propName)e.set(r.propName,(e.get(r.propName)||0)+1);return Array.from(e.entries()).map(([r,s])=>({propName:r,changeCount:s})).sort((r,s)=>s.changeCount-r.changeCount).slice(0,t)}getSearchAnalytics(){let t=this.storage.events.filter((o)=>o.type==="search"),e=new Map,r=0;for(let o of t){if(o.query)e.set(o.query,(e.get(o.query)||0)+1);if(o.metadata?.resultCount!==void 0)r+=o.metadata.resultCount}let s=Array.from(e.entries()).map(([o,a])=>({query:o,count:a})).sort((o,a)=>a.count-o.count).slice(0,10);return{totalSearches:t.length,topQueries:s,avgResultCount:t.length>0?r/t.length:0}}clear(){this.storage.events=[],this.storage.sessions=[],this.dirty=!0,this.startSession()}exportAnalytics(){return JSON.stringify({exportedAt:Date.now(),...this.storage},null,2)}}function pt(){return`session-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import S from"fs";import B from"path";var lt=".stx/story/bookmarks.json",mt=1;class P{storage;storagePath;dirty=!1;constructor(t){this.storagePath=B.join(t,lt),this.storage=this.loadStorage()}loadStorage(){try{let t=S.readFileSync(this.storagePath,"utf-8");return JSON.parse(t)}catch{return{version:mt,bookmarks:[]}}}async save(){if(!this.dirty)return;let t=B.dirname(this.storagePath);await S.promises.mkdir(t,{recursive:!0}),await S.promises.writeFile(this.storagePath,JSON.stringify(this.storage,null,2)),this.dirty=!1}addBookmark(t,e,r,s={}){let o={id:ut(),name:s.name||`${t}/${e}`,storyId:t,variantId:e,props:r,created:Date.now(),notes:s.notes,color:s.color};return this.storage.bookmarks.push(o),this.dirty=!0,o}getAllBookmarks(){return[...this.storage.bookmarks]}getBookmarksForStory(t){return this.storage.bookmarks.filter((e)=>e.storyId===t)}getBookmark(t){return this.storage.bookmarks.find((e)=>e.id===t)}isBookmarked(t,e){return this.storage.bookmarks.some((r)=>r.storyId===t&&r.variantId===e)}updateBookmark(t,e){let r=this.getBookmark(t);if(!r)return;return Object.assign(r,e),this.dirty=!0,r}deleteBookmark(t){let e=this.storage.bookmarks.findIndex((r)=>r.id===t);if(e===-1)return!1;return this.storage.bookmarks.splice(e,1),this.dirty=!0,!0}toggleBookmark(t,e,r){let s=this.storage.bookmarks.find((a)=>a.storyId===t&&a.variantId===e);if(s)return this.deleteBookmark(s.id),{added:!1};return{added:!0,bookmark:this.addBookmark(t,e,r)}}exportBookmarks(){return JSON.stringify(this.storage,null,2)}importBookmarks(t,e=!0){let r=JSON.parse(t),s=0;for(let o of r.bookmarks){if(e){let a=this.storage.bookmarks.find((c)=>c.id===o.id);if(a)Object.assign(a,o);else this.storage.bookmarks.push(o)}else this.storage.bookmarks.push(o);s++}if(s>0)this.dirty=!0;return s}}function ut(){return`bm-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}var v=new Set;function N(){return{open(t){v.add(t),t.send(JSON.stringify({type:"connected",timestamp:Date.now()}))},close(t){v.delete(t)},message(t,e){}}}function C(t){let e=JSON.stringify({...t,timestamp:t.timestamp||Date.now()});for(let r of v)try{r.send(e)}catch{v.delete(r)}}function V(t,e){C({type:"story-update",data:{storyId:t,...e}})}function H(t,e){C({type:"story-add",data:{storyId:t,...e}})}function O(t){C({type:"story-remove",data:{storyId:t}})}function F(t){return`
3
3
  <script>
4
4
  (function() {
5
5
  const ws = new WebSocket('${t}');
@@ -556,7 +556,7 @@ window.__stxPerformance = {
556
556
 
557
557
  window.clearPerformanceMetrics = () => window.__stxPerformance.clear();
558
558
  </script>
559
- `}import T from"fs";import K from"path";var ft=".stx/story/presets.json",R=1,yt=10;class I{storage;storagePath;dirty=!1;constructor(t){this.storagePath=K.join(t,ft),this.storage=this.loadStorage()}loadStorage(){try{let t=T.readFileSync(this.storagePath,"utf-8"),e=JSON.parse(t);if(e.version!==R)return this.migrateStorage(e);return e}catch{return{version:R,presets:[],recentIds:[]}}}migrateStorage(t){return{version:R,presets:t.presets||[],recentIds:t.recentIds||[]}}async save(){if(!this.dirty)return;let t=K.dirname(this.storagePath);await T.promises.mkdir(t,{recursive:!0}),await T.promises.writeFile(this.storagePath,JSON.stringify(this.storage,null,2)),this.dirty=!1}createPreset(t,e,r={}){let s={id:ht(),name:t,description:r.description,props:e,componentId:r.componentId,created:Date.now(),usageCount:0,tags:r.tags};return this.storage.presets.push(s),this.dirty=!0,s}getPreset(t){return this.storage.presets.find((e)=>e.id===t)}getAllPresets(){return[...this.storage.presets]}getPresetsForComponent(t){return this.storage.presets.filter((e)=>!e.componentId||e.componentId===t)}getRecentPresets(){return this.storage.recentIds.map((t)=>this.getPreset(t)).filter((t)=>t!==void 0)}usePreset(t){let e=this.getPreset(t);if(!e)return;return e.lastUsed=Date.now(),e.usageCount++,this.storage.recentIds=[t,...this.storage.recentIds.filter((r)=>r!==t)].slice(0,yt),this.dirty=!0,e}updatePreset(t,e){let r=this.getPreset(t);if(!r)return;return Object.assign(r,e),this.dirty=!0,r}deletePreset(t){let e=this.storage.presets.findIndex((r)=>r.id===t);if(e===-1)return!1;return this.storage.presets.splice(e,1),this.storage.recentIds=this.storage.recentIds.filter((r)=>r!==t),this.dirty=!0,!0}searchPresets(t){let e=t.toLowerCase();return this.storage.presets.filter((r)=>{if(r.name.toLowerCase().includes(e))return!0;if(r.description?.toLowerCase().includes(e))return!0;if(r.tags?.some((s)=>s.toLowerCase().includes(e)))return!0;return!1})}getMostUsedPresets(t=5){return[...this.storage.presets].sort((e,r)=>r.usageCount-e.usageCount).slice(0,t)}exportPresets(t){let e=t?this.storage.presets.filter((r)=>t.includes(r.id)):this.storage.presets;return JSON.stringify({presets:e},null,2)}importPresets(t,e=!1){let r=JSON.parse(t),s=0;for(let o of r.presets){let a=this.storage.presets.find((c)=>c.id===o.id);if(a&&!e)continue;if(a)Object.assign(a,o);else this.storage.presets.push(o);s++}if(s>0)this.dirty=!0;return s}}function ht(){return`preset-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import _ from"fs";var q=new Map;async function b(t,e,r={}){let s=performance.now(),o=[];try{let a=await _.promises.stat(e),c=q.get(e),n;if(c&&c.mtime===a.mtimeMs)n=c.content;else n=await _.promises.readFile(e,"utf-8"),q.set(e,{content:n,mtime:a.mtimeMs,analyzed:null});let{processDirectives:d}=await import("./chunk-8s10jjf1.js"),p={},u=h(n);if(u)try{await g(u,p,e)}catch(f){o.push(`Warning: Could not extract script variables: ${f instanceof Error?f.message:String(f)}`)}if(r.props)Object.assign(p,r.props);let i=await d(n,p,e,{},new Set),l=Z(n),m=h(n);return i=Q(i),i=tt(i,p),{html:i,css:l,js:m,errors:o,duration:performance.now()-s}}catch(a){return o.push(a instanceof Error?a.message:String(a)),{html:`<div class="stx-render-error">${et(o[0])}</div>`,css:"",js:"",errors:o,duration:performance.now()-s}}}async function vt(t){try{let e=await _.promises.readFile(t,"utf-8"),r=h(e);if(!r)return null;let s={};if(await g(r,s,t),Array.isArray(s.variants))return s.variants;return null}catch{return null}}async function Y(t,e,r,s){let o=e.story?.variants;if(!o){let n=await vt(e.path);if(n)o=n}if(!o&&r==="default")return b(t,e.path,{props:s||{}});if(!o)return b(t,e.path,{props:s||{}});let a=o.find((n)=>n.id===r);if(!a&&r==="default")return b(t,e.path,{props:s||{}});if(!a)return{html:'<div class="stx-render-error">Variant not found</div>',css:"",js:"",errors:[`Variant '${r}' not found`],duration:0};let c={...a.state,...s};if(a.source)return bt(t,a.source,c);return b(t,e.path,{props:c})}async function bt(t,e,r={}){let s=performance.now(),o=[];try{let{processDirectives:a}=await import("./chunk-8s10jjf1.js"),c={...r},n=h(e);if(n)try{await g(n,c,"inline-template.stx")}catch{}let p=await a(e,c,"inline-template.stx",{},new Set);return p=Q(p),p=tt(p,c),{html:p,css:Z(e),js:h(e),errors:o,duration:performance.now()-s}}catch(a){return o.push(a instanceof Error?a.message:String(a)),{html:`<div class="stx-render-error">${et(o[0])}</div>`,css:"",js:"",errors:o,duration:performance.now()-s}}}function Z(t){let e=[],r=/<style\b[^>]*>([\s\S]*?)<\/style>/gi,s=r.exec(t);while(s!==null)e.push(s[1].trim()),s=r.exec(t);return e.join(`
559
+ `}import T from"fs";import K from"path";var ft=".stx/story/presets.json",R=1,yt=10;class I{storage;storagePath;dirty=!1;constructor(t){this.storagePath=K.join(t,ft),this.storage=this.loadStorage()}loadStorage(){try{let t=T.readFileSync(this.storagePath,"utf-8"),e=JSON.parse(t);if(e.version!==R)return this.migrateStorage(e);return e}catch{return{version:R,presets:[],recentIds:[]}}}migrateStorage(t){return{version:R,presets:t.presets||[],recentIds:t.recentIds||[]}}async save(){if(!this.dirty)return;let t=K.dirname(this.storagePath);await T.promises.mkdir(t,{recursive:!0}),await T.promises.writeFile(this.storagePath,JSON.stringify(this.storage,null,2)),this.dirty=!1}createPreset(t,e,r={}){let s={id:ht(),name:t,description:r.description,props:e,componentId:r.componentId,created:Date.now(),usageCount:0,tags:r.tags};return this.storage.presets.push(s),this.dirty=!0,s}getPreset(t){return this.storage.presets.find((e)=>e.id===t)}getAllPresets(){return[...this.storage.presets]}getPresetsForComponent(t){return this.storage.presets.filter((e)=>!e.componentId||e.componentId===t)}getRecentPresets(){return this.storage.recentIds.map((t)=>this.getPreset(t)).filter((t)=>t!==void 0)}usePreset(t){let e=this.getPreset(t);if(!e)return;return e.lastUsed=Date.now(),e.usageCount++,this.storage.recentIds=[t,...this.storage.recentIds.filter((r)=>r!==t)].slice(0,yt),this.dirty=!0,e}updatePreset(t,e){let r=this.getPreset(t);if(!r)return;return Object.assign(r,e),this.dirty=!0,r}deletePreset(t){let e=this.storage.presets.findIndex((r)=>r.id===t);if(e===-1)return!1;return this.storage.presets.splice(e,1),this.storage.recentIds=this.storage.recentIds.filter((r)=>r!==t),this.dirty=!0,!0}searchPresets(t){let e=t.toLowerCase();return this.storage.presets.filter((r)=>{if(r.name.toLowerCase().includes(e))return!0;if(r.description?.toLowerCase().includes(e))return!0;if(r.tags?.some((s)=>s.toLowerCase().includes(e)))return!0;return!1})}getMostUsedPresets(t=5){return[...this.storage.presets].sort((e,r)=>r.usageCount-e.usageCount).slice(0,t)}exportPresets(t){let e=t?this.storage.presets.filter((r)=>t.includes(r.id)):this.storage.presets;return JSON.stringify({presets:e},null,2)}importPresets(t,e=!1){let r=JSON.parse(t),s=0;for(let o of r.presets){let a=this.storage.presets.find((c)=>c.id===o.id);if(a&&!e)continue;if(a)Object.assign(a,o);else this.storage.presets.push(o);s++}if(s>0)this.dirty=!0;return s}}function ht(){return`preset-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import _ from"fs";var q=new Map;async function b(t,e,r={}){let s=performance.now(),o=[];try{let a=await _.promises.stat(e),c=q.get(e),n;if(c&&c.mtime===a.mtimeMs)n=c.content;else n=await _.promises.readFile(e,"utf-8"),q.set(e,{content:n,mtime:a.mtimeMs,analyzed:null});let{processDirectives:d}=await import("./chunk-tfhhxpda.js"),p={},u=h(n);if(u)try{await g(u,p,e)}catch(f){o.push(`Warning: Could not extract script variables: ${f instanceof Error?f.message:String(f)}`)}if(r.props)Object.assign(p,r.props);let i=await d(n,p,e,{},new Set),l=Z(n),m=h(n);return i=Q(i),i=tt(i,p),{html:i,css:l,js:m,errors:o,duration:performance.now()-s}}catch(a){return o.push(a instanceof Error?a.message:String(a)),{html:`<div class="stx-render-error">${et(o[0])}</div>`,css:"",js:"",errors:o,duration:performance.now()-s}}}async function vt(t){try{let e=await _.promises.readFile(t,"utf-8"),r=h(e);if(!r)return null;let s={};if(await g(r,s,t),Array.isArray(s.variants))return s.variants;return null}catch{return null}}async function Y(t,e,r,s){let o=e.story?.variants;if(!o){let n=await vt(e.path);if(n)o=n}if(!o&&r==="default")return b(t,e.path,{props:s||{}});if(!o)return b(t,e.path,{props:s||{}});let a=o.find((n)=>n.id===r);if(!a&&r==="default")return b(t,e.path,{props:s||{}});if(!a)return{html:'<div class="stx-render-error">Variant not found</div>',css:"",js:"",errors:[`Variant '${r}' not found`],duration:0};let c={...a.state,...s};if(a.source)return bt(t,a.source,c);return b(t,e.path,{props:c})}async function bt(t,e,r={}){let s=performance.now(),o=[];try{let{processDirectives:a}=await import("./chunk-tfhhxpda.js"),c={...r},n=h(e);if(n)try{await g(n,c,"inline-template.stx")}catch{}let p=await a(e,c,"inline-template.stx",{},new Set);return p=Q(p),p=tt(p,c),{html:p,css:Z(e),js:h(e),errors:o,duration:performance.now()-s}}catch(a){return o.push(a instanceof Error?a.message:String(a)),{html:`<div class="stx-render-error">${et(o[0])}</div>`,css:"",js:"",errors:o,duration:performance.now()-s}}}function Z(t){let e=[],r=/<style\b[^>]*>([\s\S]*?)<\/style>/gi,s=r.exec(t);while(s!==null)e.push(s[1].trim()),s=r.exec(t);return e.join(`
560
560
  `)}function Q(t){return t.replace(/<!--[\s\S]*?-->/g,"").replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"").replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/^\s*\n/gm,"").trim()}function h(t){let e=[],r=/<script\b[^>]*>([\s\S]*?)<\/script>/gi,s=r.exec(t);while(s!==null)e.push(s[1].trim()),s=r.exec(t);return e.join(`
561
561
  `)}function tt(t,e){let r=`<script>window.__stxProps = ${JSON.stringify(e)};</script>`;return t+r}function et(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}async function rt(t,e){let r=await Ht(t);at(t,r);let s=Vt(t.config,r);ct(t,s),console.log(` Found ${r.length} story files`);let o=typeof e.host==="string"?e.host:e.host===!0?"0.0.0.0":"localhost",a=new I(t.root),c=new P(t.root),n=new k(t.root),d=N(),p=Bun.serve({port:e.port,hostname:o,fetch:async(i,l)=>{let f=new URL(i.url).pathname;if(f==="/__hmr"){if(l.upgrade(i,{data:{isHmr:!0}}))return;return new Response("WebSocket upgrade failed",{status:400})}if(f.startsWith("/api/"))return xt(t,f,i,{presetsManager:a,bookmarksManager:c,analyticsTracker:n});return wt(t,f,e.port)},websocket:{open(i){d.open(i)},close(i){d.close(i)},message(i,l){d.message(i,l)}}}),u=`http://${o}:${e.port}`,y=mi(t,async(i,l)=>{console.log(` [${i}] ${l.relativePath}`);let m=await Ht(t);at(t,m);let f=Vt(t.config,m);if(ct(t,f),i==="add")H(l.id,{fileName:l.fileName});else if(i==="unlink")O(l.id);else V(l.id,{fileName:l.fileName})});if(e.open){let i=u;try{let{exec:l}=await import("child_process"),m=process.platform;l(`${m==="darwin"?"open":m==="win32"?"start":"xdg-open"} ${i}`)}catch{}}return{server:p,url:u,close:async()=>{y(),p.stop()}}}async function xt(t,e,r,s){let{presetsManager:o,bookmarksManager:a,analyticsTracker:c}=s;if(e==="/api/stories")return Response.json({files:t.storyFiles.map((n)=>({id:n.id,fileName:n.fileName,relativePath:n.relativePath,treePath:n.treePath})),tree:t.tree});if(e.startsWith("/api/story/")){let n=e.slice(11),d=t.storyFiles.find((p)=>p.id===n);if(!d)return new Response("Story not found",{status:404});try{let p=await Bun.file(d.path).text();return Response.json({id:d.id,fileName:d.fileName,relativePath:d.relativePath,content:p})}catch{return new Response("Error reading story",{status:500})}}if(e==="/api/config")return Response.json({theme:t.config.theme,responsivePresets:t.config.responsivePresets,backgroundPresets:t.config.backgroundPresets});if(e.startsWith("/api/render/")){let n=new URL(r.url),d=e.slice(12).split("/"),p=d[0],u=d[1]||"default",y,i=n.searchParams.get("props");if(i)try{y=JSON.parse(i)}catch{}let l=t.storyFiles.find((m)=>m.id===p);if(!l)return new Response("Story not found",{status:404});try{let m=await Y(t,l,u,y);return Response.json({html:m.html,css:m.css,js:m.js,errors:m.errors,duration:m.duration})}catch(m){return Response.json({html:"",css:"",js:"",errors:[m instanceof Error?m.message:String(m)],duration:0},{status:500})}}if(e==="/api/presets"&&r.method==="GET")return Response.json({presets:o.getAllPresets()});if(e==="/api/presets"&&r.method==="POST")try{let n=await r.json(),d=o.createPreset(n.name,n.props,{componentId:n.componentId,description:n.description});return await o.save(),Response.json(d)}catch(n){return Response.json({error:String(n)},{status:400})}if(e.startsWith("/api/presets/")&&!e.includes("/use")&&r.method==="GET"){let n=e.slice(13),d=o.getPreset(n);if(!d)return new Response("Preset not found",{status:404});return Response.json(d)}if(e.endsWith("/use")&&r.method==="POST"){let n=e.slice(13,-4),d=o.usePreset(n);if(!d)return new Response("Preset not found",{status:404});return await o.save(),Response.json(d)}if(e.startsWith("/api/presets/")&&r.method==="DELETE"){let n=e.slice(13);if(!o.deletePreset(n))return new Response("Preset not found",{status:404});return await o.save(),Response.json({success:!0})}if(e==="/api/bookmarks"&&r.method==="GET")return Response.json({bookmarks:a.getAllBookmarks()});if(e==="/api/bookmarks"&&r.method==="POST")try{let n=await r.json(),d=a.addBookmark(n.storyId,n.variantId,n.props,{name:n.name,notes:n.notes,color:n.color});return await a.save(),Response.json(d)}catch(n){return Response.json({error:String(n)},{status:400})}if(e==="/api/bookmarks/toggle"&&r.method==="POST")try{let n=await r.json(),d=a.toggleBookmark(n.storyId,n.variantId,n.props);return await a.save(),Response.json(d)}catch(n){return Response.json({error:String(n)},{status:400})}if(e.startsWith("/api/bookmarks/")&&e!=="/api/bookmarks/toggle"&&r.method==="GET"){let n=e.slice(15),d=a.getBookmark(n);if(!d)return new Response("Bookmark not found",{status:404});return Response.json(d)}if(e.startsWith("/api/bookmarks/")&&r.method==="DELETE"){let n=e.slice(15);if(!a.deleteBookmark(n))return new Response("Bookmark not found",{status:404});return await a.save(),Response.json({success:!0})}if(e==="/api/analytics/track"&&r.method==="POST")try{let n=await r.json();if(n.type==="view"&&n.componentId)c.trackView(n.componentId,n.variantId);else if(n.type==="prop_change"&&n.componentId&&n.propName)c.trackPropChange(n.componentId,n.propName,null);else if(n.type==="variant_switch"&&n.componentId&&n.variantId)c.trackVariantSwitch(n.componentId,n.variantId);else if(n.type==="search"&&n.query)c.trackSearch(n.query,0);return await c.save(),Response.json({success:!0})}catch(n){return Response.json({error:String(n)},{status:400})}if(e==="/api/analytics/summary"&&r.method==="GET")return Response.json({mostViewed:c.getMostViewedComponents(10),mostChangedProps:c.getMostChangedProps(10),searchAnalytics:c.getSearchAnalytics()});if(e.startsWith("/api/analytics/component/")&&r.method==="GET"){let n=e.slice(25),d=t.storyFiles.find((u)=>u.id===n),p=c.getComponentAnalytics(n,d?.fileName||n);return Response.json(p)}return new Response("Not found",{status:404})}function wt(t,e,r){let s=kt(t,r);return new Response(s,{headers:{"Content-Type":"text/html; charset=utf-8"}})}function kt(t,e){let{theme:r}=t.config,s=r.title||"STX Story",o=`ws://localhost:${e}/__hmr`,a=F(o);return`<!DOCTYPE html>
562
562
  <html lang="en" class="${r.darkClass||"dark"}">
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Vn,Te}from"./chunk-374nhgyf.js";import{L,b,ir,ds,k}from"./chunk-qq40hxg9.js";import{i,R}from"./chunk-zj5x4yk2.js";import{eo}from"./chunk-d4f6dkrt.js";import{Qe}from"./chunk-yn9kvsk1.js";import{c}from"./chunk-xvs84gas.js";import{r,fe}from"./chunk-9tg4995v.js";import d from"path";import v from"fs";import{AsyncLocalStorage as gt}from"async_hooks";var ht=11;function X(t,e,n){return/^(?:(?:stx|ui)\.config\.[cm]?[jt]s|runtime-config-(?:server|loader)\.[cm]?[jt]s)$/.test(d.basename(t))||eo(t,e,n)}var ot=2;function gl(t){let e=process.env.STX_BUNDLE_CACHE_DIR?.trim();return e?d.resolve(e):c(t,"bundle-cache")}function nt(t,e){let n=t;for(let o of xt(e))if(o!==d.sep)n=n.split(o).join("\x00root");return n}var st=new Map;function xt(t){let e=d.resolve(t),n=st.get(e);if(!n){let o=e;try{o=v.realpathSync(e)}catch{}n=[...new Set([e,o])].sort((u,m)=>m.length-u.length),st.set(e,n)}return n}function $t(t,e){try{let n=v.statSync(t),o=d.resolve(e),u=t.startsWith(`${o}${d.sep}`);return{path:u?d.relative(o,t):t,...u?{inRoot:!0}:{},mtimeMs:n.mtimeMs,size:n.size,hash:Bun.hash(v.readFileSync(t)).toString(36)}}catch{return null}}function at(t,e){return t.inRoot?d.join(d.resolve(e),t.path):t.path}function yt(t,e){for(let n of t){let o=at(n,e);try{let u=v.statSync(o);if(u.size!==n.size)return!1;if(u.mtimeMs!==n.mtimeMs&&Bun.hash(v.readFileSync(o)).toString(36)!==n.hash)return!1}catch{return!1}}return!0}var ct=new Map,bt=100;function ml(t=process.env){let e=Number(t.STX_BUNDLE_CACHE_LIMIT);return Number.isFinite(e)&&e>=1?Math.floor(e):2000}var G=new Map;async function wt(t){let e=G.get(t)??0;if(e>0&&e<bt){G.set(t,e+1);return}G.set(t,1);try{let n=(await v.promises.readdir(t)).filter((l)=>l.endsWith(".js")),o=ml();if(n.length<=o)return;let m=(await Promise.all(n.map(async(l)=>{try{return{name:l,at:(await v.promises.stat(d.join(t,l))).mtimeMs}}catch{return null}}))).filter((l)=>l!==null);m.sort((l,y)=>y.at-l.at);for(let l of m.slice(o)){let y=l.name.slice(0,-3);await v.promises.rm(d.join(t,`${y}.js`),{force:!0}),await v.promises.rm(d.join(t,`${y}.deps.json`),{force:!0})}O("pruned bundle cache to",o,"entries")}catch{}}function Ee(t){return ct.get(t)??[]}function q(t,e){if(t)ct.set(t,e)}function hl(t=process.env){return t.STX_DEBUG==="true"||t.STX_DEBUG==="1"}function O(...t){if(hl())console.log("[stx:bundler]",...t)}var Y=[];function ra(t,e,n){Y.push({filePath:t||"<inline>",message:e,details:n})}function Xt(){return Y.slice()}function Jt(){Y.length=0}var Z;function cp(t){Z=t}function sa(){if(Z)return Z;try{let t=R.strict;return typeof t==="object"&&t!==null?t.bundlerFallback??"warn":"warn"}catch{return"warn"}}var Q=[/^stx$/,/^@stacksjs\/stx$/,/^@stores$/,/^stx\/stores$/,/^@composables$/];function Yt(t){let e=/^[ \t]*import[ \t]+(?!type(?:[ \t]|{))[\s\S]*?\s+from\s+['"]([^'"]+)['"][ \t]*;?/gm,n;while((n=e.exec(t))!==null){let u=n[1];if(!Q.some((l)=>l.test(u)))return O("detected user import:",u),!0}let o=/^[ \t]*import[ \t]*['"]([^'"]+)['"]/gm;while((n=o.exec(t))!==null){let u=n[1];if(/\.css(?:\?.*)?$/.test(u))continue;if(!Q.some((l)=>l.test(u)))return O("detected side-effect import:",u),!0}return!1}var Hn="stx-module:",St=/\.(?:[cm]?[jt]sx?|json)$/i;function yl(t,e){return d.relative(t,e).split(d.sep).join("/")}function bl(t,e){if(e.size===0)return t;return t.replace(/^([ \t]*import(?:(?:\s+|(?=[{*]))[^;"']*?\s*from\s*|\s*))(["'])([^"']+)\2/gm,(n,o,u,m)=>{let l=e.get(m);return l&&!m.startsWith(Hn)?`${o}${u}${l}${u}`:n})}function vl(t,e){let n=0,o=(m)=>{let l=`__stxMod${n++}`,y=JSON.stringify(m);return e.push(`var ${l} = globalThis.__stxModules && globalThis.__stxModules[${y}];`,`if (${l} === undefined) throw new Error("[stx] module " + ${JSON.stringify(y)} + " is not registered on this page (#1957)");`),l},u=(m,l)=>{for(let y of m.split(",")){let F=y.trim();if(!F)continue;let B=F.match(/^("(?:[^"\\]|\\.)*"|[\w$]+)(?:\s+as\s+([\w$]+))?$/);if(!B)continue;let j=B[1].startsWith('"')?JSON.parse(B[1]):B[1],p=B[2]??j;e.push(`var ${p} = ${l}[${JSON.stringify(j)}];`)}};return t=t.replace(/^[ \t]*import(?:\s+|(?=[{*]))([^;"']+?)\s*from\s*["'](stx-module:[^"']+)["'];?[ \t]*$/gm,(m,l,y)=>{let F=y.slice(Hn.length),B=o(F),j=l.trim(),p=j.match(/^([\w$]+)\s*(?:,\s*|$)/);if(p&&!j.startsWith("{")&&!j.startsWith("*"))e.push(`var ${p[1]} = ${B}.default;`),j=j.slice(p[0].length).trim();let s=j.match(/^\*\s*as\s+([\w$]+)$/);if(s)e.push(`var ${s[1]} = ${B};`);else if(j.startsWith("{"))u(j.replace(/^\{|\}$/g,""),B);return""}),t=t.replace(/^[ \t]*import\s*["'](stx-module:[^"']+)["'];?[ \t]*$/gm,(m,l)=>(o(l.slice(Hn.length)),"")),t}function rt(t){let e=[t,`${t}.ts`,`${t}.tsx`,`${t}.js`,`${t}.mjs`,`${t}.jsx`,d.join(t,"index.ts"),d.join(t,"index.tsx"),d.join(t,"index.js"),d.join(t,"index.mjs")];for(let n of e)try{if(v.existsSync(n)&&v.statSync(n,{throwIfNoEntry:!1})?.isFile())return n}catch{}return}var K=new gt;function Js(t,e){let n=new Bun.CryptoHasher("md5");for(let[o,u]of[...t].sort(([m],[l])=>m<l?-1:m>l?1:0))n.update(`${o}\x00${u}\x00`);return K.run({modules:t,key:n.digest("hex").slice(0,12)},e)}function Zt(){return K.getStore()?.key??""}function vt(t,e,n,o,u,m,l=new Map,y,F){let B=(p,s,a)=>{if(X(s,t,y))return null;if(!m||p!==n||!St.test(s))return null;try{if(!v.statSync(s,{throwIfNoEntry:!1})?.isFile())return null}catch{return null}u.add(s);let w=`${Hn}${yl(process.cwd(),s)}`;return l.set(a,w),{path:w,external:!0}},j=(p,s)=>{let a=p===n?e:d.dirname(p),w=d.resolve(a,s);return rt(w)??w};return{name:"stx-client-bundle",setup(p){if(p.onResolve({filter:/^(stx|@stacksjs\/stx)$/},(s)=>({path:s.path,external:!0})),p.onResolve({filter:/^(@stores|@composables|stx\/stores)$/},(s)=>({path:s.path,external:!0})),p.onResolve({filter:/^\//},(s)=>{if(s.path===n)return{path:n};let a=rt(s.path);if(a){let w=B(s.importer,a,s.path);if(w)return w;if(a!==n)u.add(a);return{path:a}}return{path:s.path,external:!0}}),p.onResolve({filter:/^\.\.?\//},(s)=>{let a=j(s.importer,s.path),w=B(s.importer,a,s.path);if(w)return w;return u.add(a),{path:a}}),p.onResolve({filter:/^[@~]\//},(s)=>{let a=d.resolve(t,s.path.slice(2)),w=[a,`${a}.ts`,`${a}.tsx`,`${a}.js`,`${a}.mjs`,`${a}.jsx`,d.join(a,"index.ts"),d.join(a,"index.tsx"),d.join(a,"index.js"),d.join(a,"index.mjs")];for(let x of w)if(v.existsSync(x)&&v.statSync(x,{throwIfNoEntry:!1})?.isFile()){let A=B(s.importer,x,s.path);if(A)return A;return O(`resolved ${s.path[0]}/ import:`,s.path,"\u2192",x),u.add(x),{path:x}}return console.warn(`[stx:bundler] could not resolve ${s.path[0]}/ import:`,s.path),{path:a}}),m)p.onResolve({filter:/^(?!node:|bun:)(?:@[\w.-]+\/)?[\w.-]/},(s)=>{if(s.importer!==n)return;let a=`${Hn}npm:${s.path}`;return l.set(s.path,a),{path:a,external:!0}});p.onLoad({filter:/\.(?:[cm]?[jt]sx?|json)$/},(s)=>{if(s.path===n)return{contents:o,loader:"ts"};if(X(s.path,t,y))throw Error(`Server-only API source cannot be imported by a client script: ${s.path}`);let a=d.extname(s.path).toLowerCase(),w=a===".json"?"json":a===".tsx"?"tsx":a===".jsx"?"jsx":a===".ts"||a===".mts"||a===".cts"?"ts":"js";if(s.path!==n)u.add(s.path);let x=F?.get(s.path);if(x!==void 0)return{contents:x,loader:"js"};return{contents:v.readFileSync(s.path,"utf8"),loader:w}})}}}var H=new Map,P=b(64),it=Symbol.for("stx.client-bundle-build-queue");function wl(t){let e=globalThis,o=(e[it]??Promise.resolve()).then(t,t);return e[it]=o.then(()=>{return},()=>{return}),o}async function Qt(t,e,n={}){let o=n.projectRoot||process.cwd(),u=(await i(o)).serverApi,m=n.minify??!1,l=n.externalizeUserModules??!0,y=n.expose?.length?[...new Set(n.expose)].sort():void 0,F=n.cacheDir||gl(o),B=K.getStore(),j=new Bun.CryptoHasher("md5");j.update(`${ht}\x00${Qe()}\x00${JSON.stringify(u??!1)}\x00${l?"registry":"inline"}\x00${y?y.join(","):"*"}\x00${m?"minified":"readable"}\x00${B?.key??""}\x00${nt(t,o)}\x00${nt(e,o)}`);let p=j.digest("hex").slice(0,12),s=d.join(F,`${p}.js`),a=P.get(s);if(a){if(ds(a.files)&&a.files.every((M)=>!X(M.path,o,u))){O("memo hit:",p);let M=a.files.map((C)=>C.path);return q(e,M),n.collectInputs?.push(...M),a.code}P.delete(s),O("memo invalidated by dep change:",p)}let w=d.join(F,`${p}.deps.json`),x=Bun.file(s);if(await x.exists()){let M=Bun.file(w),C=!1,D=null;if(await M.exists())try{let I=JSON.parse(await M.text());if(I.metadataVersion===ot&&Array.isArray(I.files)&&yt(I.files,o))D=ir(I.files.map((g)=>at(g,o))),C=D.length===I.files.length&&!D.some((g)=>X(g.path,o,u))}catch{C=!1}if(C){if(O("cache hit:",p),D)q(e,D.map((T)=>T.path)),n.collectInputs?.push(...D.map((T)=>T.path));let I=await x.text(),g=new Date;if(v.promises.utimes(s,g,g).catch(()=>{}),D)P.set(s,{code:I,files:D});return I}O("cache invalidated by dep change:",p)}let A=H.get(p);if(A){let M=await A;if(n.collectInputs)n.collectInputs.push(...(P.get(s)?.files??[]).map((C)=>C.path));return M}let V=wl(()=>jt(t,e,{projectRoot:o,minify:m,cacheDir:F,hash:p,cachePath:s,depsPath:w,collectInputs:n.collectInputs,externalizeUserModules:l,serverApi:u,expose:y,throwOnFailure:n.throwOnFailure,substitutes:B?.modules}));H.set(p,V);try{return await V}finally{H.delete(p)}}var Bt=0;function xl(t){return`${t}-${process.pid}-${++Bt}`}async function jt(t,e,n){let{projectRoot:o,minify:u,cacheDir:m,hash:l,cachePath:y,depsPath:F,externalizeUserModules:B}=n,j=c(o,"bundle-tmp"),p=xl(l),s=d.join(o,`.stx-client-${p}.ts`),a=d.join(j,"out",p);v.mkdirSync(a,{recursive:!0});let w=d.dirname(e),x=new Set,A=/^[ \t]*(export\s+)?(?:const|let|var)\s+(?:\{([^}]+)\}|(\w+))/gm,V=/^[ \t]*(export\s+)?(?:async\s+)?function\s+(\w+)/gm,M=r(t),{depths:C,balanced:D}=fe(M),I=(_)=>!D||C[_]===0,g;while((g=A.exec(M))!==null){if(g[1])continue;if(!I(g.index))continue;if(g[2])g[2].split(",").forEach((_)=>{let f=_t(_);if(f)x.add(f)});else if(g[3])x.add(g[3])}while((g=V.exec(M))!==null){if(g[1])continue;if(!I(g.index))continue;x.add(g[2])}let T=/^[ \t]*import[ \t]+(?!type\b)(?:(\w+)\s*(?:,\s*)?)?(?:\*\s+as\s+(\w+)|\{([^}]+)\})?\s+from\b/gm;while((g=T.exec(M))!==null){if(!I(g.index))continue;let _=/^\s*['"]([^'"]+)['"]/.exec(t.slice(g.index+g[0].length))?.[1];if(_&&Q.some((f)=>f.test(_)))continue;if(g[1])x.add(g[1]);if(g[2])x.add(g[2]);for(let f of(g[3]??"").split(",")){let S=f.trim();if(!S||/^type\s/.test(S))continue;let U=/\bas\s+(\w+)\s*$/.exec(S)?.[1]??/^\w+$/.exec(S)?.[0];if(U)x.add(U)}}for(let _ of M.matchAll(/\bexport\s*\{([^}]+)\}/g))for(let f of _[1].split(",")){let S=/\bas\s+(\w+)\s*$/.exec(f)?.[1]??/^\s*(\w+)\s*$/.exec(f)?.[1];if(S)x.delete(S)}let lt=x.size>0?`
2
+ import{Vn,Te}from"./chunk-374nhgyf.js";import{L,b,ir,ds,k}from"./chunk-t3e5tv4h.js";import{i,R}from"./chunk-mxbp4vyy.js";import{eo}from"./chunk-r8cn9qhr.js";import{Qe}from"./chunk-yn9kvsk1.js";import{c}from"./chunk-xvs84gas.js";import{r,fe}from"./chunk-9tg4995v.js";import d from"path";import v from"fs";import{AsyncLocalStorage as gt}from"async_hooks";var ht=11;function X(t,e,n){return/^(?:(?:stx|ui)\.config\.[cm]?[jt]s|runtime-config-(?:server|loader)\.[cm]?[jt]s)$/.test(d.basename(t))||eo(t,e,n)}var ot=2;function gl(t){let e=process.env.STX_BUNDLE_CACHE_DIR?.trim();return e?d.resolve(e):c(t,"bundle-cache")}function nt(t,e){let n=t;for(let o of xt(e))if(o!==d.sep)n=n.split(o).join("\x00root");return n}var st=new Map;function xt(t){let e=d.resolve(t),n=st.get(e);if(!n){let o=e;try{o=v.realpathSync(e)}catch{}n=[...new Set([e,o])].sort((u,m)=>m.length-u.length),st.set(e,n)}return n}function $t(t,e){try{let n=v.statSync(t),o=d.resolve(e),u=t.startsWith(`${o}${d.sep}`);return{path:u?d.relative(o,t):t,...u?{inRoot:!0}:{},mtimeMs:n.mtimeMs,size:n.size,hash:Bun.hash(v.readFileSync(t)).toString(36)}}catch{return null}}function at(t,e){return t.inRoot?d.join(d.resolve(e),t.path):t.path}function yt(t,e){for(let n of t){let o=at(n,e);try{let u=v.statSync(o);if(u.size!==n.size)return!1;if(u.mtimeMs!==n.mtimeMs&&Bun.hash(v.readFileSync(o)).toString(36)!==n.hash)return!1}catch{return!1}}return!0}var ct=new Map,bt=100;function ml(t=process.env){let e=Number(t.STX_BUNDLE_CACHE_LIMIT);return Number.isFinite(e)&&e>=1?Math.floor(e):2000}var G=new Map;async function wt(t){let e=G.get(t)??0;if(e>0&&e<bt){G.set(t,e+1);return}G.set(t,1);try{let n=(await v.promises.readdir(t)).filter((l)=>l.endsWith(".js")),o=ml();if(n.length<=o)return;let m=(await Promise.all(n.map(async(l)=>{try{return{name:l,at:(await v.promises.stat(d.join(t,l))).mtimeMs}}catch{return null}}))).filter((l)=>l!==null);m.sort((l,y)=>y.at-l.at);for(let l of m.slice(o)){let y=l.name.slice(0,-3);await v.promises.rm(d.join(t,`${y}.js`),{force:!0}),await v.promises.rm(d.join(t,`${y}.deps.json`),{force:!0})}O("pruned bundle cache to",o,"entries")}catch{}}function Ee(t){return ct.get(t)??[]}function q(t,e){if(t)ct.set(t,e)}function hl(t=process.env){return t.STX_DEBUG==="true"||t.STX_DEBUG==="1"}function O(...t){if(hl())console.log("[stx:bundler]",...t)}var Y=[];function ra(t,e,n){Y.push({filePath:t||"<inline>",message:e,details:n})}function Xt(){return Y.slice()}function Jt(){Y.length=0}var Z;function cp(t){Z=t}function sa(){if(Z)return Z;try{let t=R.strict;return typeof t==="object"&&t!==null?t.bundlerFallback??"warn":"warn"}catch{return"warn"}}var Q=[/^stx$/,/^@stacksjs\/stx$/,/^@stores$/,/^stx\/stores$/,/^@composables$/];function Yt(t){let e=/^[ \t]*import[ \t]+(?!type(?:[ \t]|{))[\s\S]*?\s+from\s+['"]([^'"]+)['"][ \t]*;?/gm,n;while((n=e.exec(t))!==null){let u=n[1];if(!Q.some((l)=>l.test(u)))return O("detected user import:",u),!0}let o=/^[ \t]*import[ \t]*['"]([^'"]+)['"]/gm;while((n=o.exec(t))!==null){let u=n[1];if(/\.css(?:\?.*)?$/.test(u))continue;if(!Q.some((l)=>l.test(u)))return O("detected side-effect import:",u),!0}return!1}var Hn="stx-module:",St=/\.(?:[cm]?[jt]sx?|json)$/i;function yl(t,e){return d.relative(t,e).split(d.sep).join("/")}function bl(t,e){if(e.size===0)return t;return t.replace(/^([ \t]*import(?:(?:\s+|(?=[{*]))[^;"']*?\s*from\s*|\s*))(["'])([^"']+)\2/gm,(n,o,u,m)=>{let l=e.get(m);return l&&!m.startsWith(Hn)?`${o}${u}${l}${u}`:n})}function vl(t,e){let n=0,o=(m)=>{let l=`__stxMod${n++}`,y=JSON.stringify(m);return e.push(`var ${l} = globalThis.__stxModules && globalThis.__stxModules[${y}];`,`if (${l} === undefined) throw new Error("[stx] module " + ${JSON.stringify(y)} + " is not registered on this page (#1957)");`),l},u=(m,l)=>{for(let y of m.split(",")){let F=y.trim();if(!F)continue;let B=F.match(/^("(?:[^"\\]|\\.)*"|[\w$]+)(?:\s+as\s+([\w$]+))?$/);if(!B)continue;let j=B[1].startsWith('"')?JSON.parse(B[1]):B[1],p=B[2]??j;e.push(`var ${p} = ${l}[${JSON.stringify(j)}];`)}};return t=t.replace(/^[ \t]*import(?:\s+|(?=[{*]))([^;"']+?)\s*from\s*["'](stx-module:[^"']+)["'];?[ \t]*$/gm,(m,l,y)=>{let F=y.slice(Hn.length),B=o(F),j=l.trim(),p=j.match(/^([\w$]+)\s*(?:,\s*|$)/);if(p&&!j.startsWith("{")&&!j.startsWith("*"))e.push(`var ${p[1]} = ${B}.default;`),j=j.slice(p[0].length).trim();let s=j.match(/^\*\s*as\s+([\w$]+)$/);if(s)e.push(`var ${s[1]} = ${B};`);else if(j.startsWith("{"))u(j.replace(/^\{|\}$/g,""),B);return""}),t=t.replace(/^[ \t]*import\s*["'](stx-module:[^"']+)["'];?[ \t]*$/gm,(m,l)=>(o(l.slice(Hn.length)),"")),t}function rt(t){let e=[t,`${t}.ts`,`${t}.tsx`,`${t}.js`,`${t}.mjs`,`${t}.jsx`,d.join(t,"index.ts"),d.join(t,"index.tsx"),d.join(t,"index.js"),d.join(t,"index.mjs")];for(let n of e)try{if(v.existsSync(n)&&v.statSync(n,{throwIfNoEntry:!1})?.isFile())return n}catch{}return}var K=new gt;function Js(t,e){let n=new Bun.CryptoHasher("md5");for(let[o,u]of[...t].sort(([m],[l])=>m<l?-1:m>l?1:0))n.update(`${o}\x00${u}\x00`);return K.run({modules:t,key:n.digest("hex").slice(0,12)},e)}function Zt(){return K.getStore()?.key??""}function vt(t,e,n,o,u,m,l=new Map,y,F){let B=(p,s,a)=>{if(X(s,t,y))return null;if(!m||p!==n||!St.test(s))return null;try{if(!v.statSync(s,{throwIfNoEntry:!1})?.isFile())return null}catch{return null}u.add(s);let w=`${Hn}${yl(process.cwd(),s)}`;return l.set(a,w),{path:w,external:!0}},j=(p,s)=>{let a=p===n?e:d.dirname(p),w=d.resolve(a,s);return rt(w)??w};return{name:"stx-client-bundle",setup(p){if(p.onResolve({filter:/^(stx|@stacksjs\/stx)$/},(s)=>({path:s.path,external:!0})),p.onResolve({filter:/^(@stores|@composables|stx\/stores)$/},(s)=>({path:s.path,external:!0})),p.onResolve({filter:/^\//},(s)=>{if(s.path===n)return{path:n};let a=rt(s.path);if(a){let w=B(s.importer,a,s.path);if(w)return w;if(a!==n)u.add(a);return{path:a}}return{path:s.path,external:!0}}),p.onResolve({filter:/^\.\.?\//},(s)=>{let a=j(s.importer,s.path),w=B(s.importer,a,s.path);if(w)return w;return u.add(a),{path:a}}),p.onResolve({filter:/^[@~]\//},(s)=>{let a=d.resolve(t,s.path.slice(2)),w=[a,`${a}.ts`,`${a}.tsx`,`${a}.js`,`${a}.mjs`,`${a}.jsx`,d.join(a,"index.ts"),d.join(a,"index.tsx"),d.join(a,"index.js"),d.join(a,"index.mjs")];for(let x of w)if(v.existsSync(x)&&v.statSync(x,{throwIfNoEntry:!1})?.isFile()){let A=B(s.importer,x,s.path);if(A)return A;return O(`resolved ${s.path[0]}/ import:`,s.path,"\u2192",x),u.add(x),{path:x}}return console.warn(`[stx:bundler] could not resolve ${s.path[0]}/ import:`,s.path),{path:a}}),m)p.onResolve({filter:/^(?!node:|bun:)(?:@[\w.-]+\/)?[\w.-]/},(s)=>{if(s.importer!==n)return;let a=`${Hn}npm:${s.path}`;return l.set(s.path,a),{path:a,external:!0}});p.onLoad({filter:/\.(?:[cm]?[jt]sx?|json)$/},(s)=>{if(s.path===n)return{contents:o,loader:"ts"};if(X(s.path,t,y))throw Error(`Server-only API source cannot be imported by a client script: ${s.path}`);let a=d.extname(s.path).toLowerCase(),w=a===".json"?"json":a===".tsx"?"tsx":a===".jsx"?"jsx":a===".ts"||a===".mts"||a===".cts"?"ts":"js";if(s.path!==n)u.add(s.path);let x=F?.get(s.path);if(x!==void 0)return{contents:x,loader:"js"};return{contents:v.readFileSync(s.path,"utf8"),loader:w}})}}}var H=new Map,P=b(64),it=Symbol.for("stx.client-bundle-build-queue");function wl(t){let e=globalThis,o=(e[it]??Promise.resolve()).then(t,t);return e[it]=o.then(()=>{return},()=>{return}),o}async function Qt(t,e,n={}){let o=n.projectRoot||process.cwd(),u=(await i(o)).serverApi,m=n.minify??!1,l=n.externalizeUserModules??!0,y=n.expose?.length?[...new Set(n.expose)].sort():void 0,F=n.cacheDir||gl(o),B=K.getStore(),j=new Bun.CryptoHasher("md5");j.update(`${ht}\x00${Qe()}\x00${JSON.stringify(u??!1)}\x00${l?"registry":"inline"}\x00${y?y.join(","):"*"}\x00${m?"minified":"readable"}\x00${B?.key??""}\x00${nt(t,o)}\x00${nt(e,o)}`);let p=j.digest("hex").slice(0,12),s=d.join(F,`${p}.js`),a=P.get(s);if(a){if(ds(a.files)&&a.files.every((M)=>!X(M.path,o,u))){O("memo hit:",p);let M=a.files.map((C)=>C.path);return q(e,M),n.collectInputs?.push(...M),a.code}P.delete(s),O("memo invalidated by dep change:",p)}let w=d.join(F,`${p}.deps.json`),x=Bun.file(s);if(await x.exists()){let M=Bun.file(w),C=!1,D=null;if(await M.exists())try{let I=JSON.parse(await M.text());if(I.metadataVersion===ot&&Array.isArray(I.files)&&yt(I.files,o))D=ir(I.files.map((g)=>at(g,o))),C=D.length===I.files.length&&!D.some((g)=>X(g.path,o,u))}catch{C=!1}if(C){if(O("cache hit:",p),D)q(e,D.map((T)=>T.path)),n.collectInputs?.push(...D.map((T)=>T.path));let I=await x.text(),g=new Date;if(v.promises.utimes(s,g,g).catch(()=>{}),D)P.set(s,{code:I,files:D});return I}O("cache invalidated by dep change:",p)}let A=H.get(p);if(A){let M=await A;if(n.collectInputs)n.collectInputs.push(...(P.get(s)?.files??[]).map((C)=>C.path));return M}let V=wl(()=>jt(t,e,{projectRoot:o,minify:m,cacheDir:F,hash:p,cachePath:s,depsPath:w,collectInputs:n.collectInputs,externalizeUserModules:l,serverApi:u,expose:y,throwOnFailure:n.throwOnFailure,substitutes:B?.modules}));H.set(p,V);try{return await V}finally{H.delete(p)}}var Bt=0;function xl(t){return`${t}-${process.pid}-${++Bt}`}async function jt(t,e,n){let{projectRoot:o,minify:u,cacheDir:m,hash:l,cachePath:y,depsPath:F,externalizeUserModules:B}=n,j=c(o,"bundle-tmp"),p=xl(l),s=d.join(o,`.stx-client-${p}.ts`),a=d.join(j,"out",p);v.mkdirSync(a,{recursive:!0});let w=d.dirname(e),x=new Set,A=/^[ \t]*(export\s+)?(?:const|let|var)\s+(?:\{([^}]+)\}|(\w+))/gm,V=/^[ \t]*(export\s+)?(?:async\s+)?function\s+(\w+)/gm,M=r(t),{depths:C,balanced:D}=fe(M),I=(_)=>!D||C[_]===0,g;while((g=A.exec(M))!==null){if(g[1])continue;if(!I(g.index))continue;if(g[2])g[2].split(",").forEach((_)=>{let f=_t(_);if(f)x.add(f)});else if(g[3])x.add(g[3])}while((g=V.exec(M))!==null){if(g[1])continue;if(!I(g.index))continue;x.add(g[2])}let T=/^[ \t]*import[ \t]+(?!type\b)(?:(\w+)\s*(?:,\s*)?)?(?:\*\s+as\s+(\w+)|\{([^}]+)\})?\s+from\b/gm;while((g=T.exec(M))!==null){if(!I(g.index))continue;let _=/^\s*['"]([^'"]+)['"]/.exec(t.slice(g.index+g[0].length))?.[1];if(_&&Q.some((f)=>f.test(_)))continue;if(g[1])x.add(g[1]);if(g[2])x.add(g[2]);for(let f of(g[3]??"").split(",")){let S=f.trim();if(!S||/^type\s/.test(S))continue;let U=/\bas\s+(\w+)\s*$/.exec(S)?.[1]??/^\w+$/.exec(S)?.[0];if(U)x.add(U)}}for(let _ of M.matchAll(/\bexport\s*\{([^}]+)\}/g))for(let f of _[1].split(",")){let S=/\bas\s+(\w+)\s*$/.exec(f)?.[1]??/^\s*(\w+)\s*$/.exec(f)?.[1];if(S)x.delete(S)}let lt=x.size>0?`
3
3
  export { ${[...x].join(", ")} }`:"";O("bundling:",l,"from:",d.basename(e));let tt=new Set,et=new Map;try{let _=await Bun.build({entrypoints:[s],outdir:a,target:"browser",format:"esm",minify:u?{whitespace:!1,identifiers:!0,syntax:!0}:!1,plugins:[vt(o,w,s,t+lt,tt,B,et,n.serverApi,n.substitutes)],define:{"process.env.NODE_ENV":u?'"production"':'"development"',...k()},root:o});if(!_.success){let E=_.logs.filter((N)=>N.level==="error").map((N)=>N.message).join(", ")||`Unable to bundle ${d.basename(e)}`,z=Vn(_.logs,e||void 0);if(console.warn("[stx:bundler] build failed:",E),ra(e||"",E,z),n.throwOnFailure||sa()==="error")throw Error(E);return t}let f="";for(let h of _.outputs){f=await h.text();break}let S=[];for(let h of f.matchAll(/^\s*export\s*\{([^}]*)\}\s*;?\s*$/gm))for(let E of h[1].split(",")){let z=E.trim().match(/^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/);if(z){S.push([z[2],z[1]]);continue}let N=E.trim();if(/^[A-Za-z_$][\w$]*$/.test(N))S.push([N,N])}if(n.expose){let h=new Set(n.expose);for(let E=S.length-1;E>=0;E--)if(!h.has(S[E][0]))S.splice(E,1)}let U=[];f=vl(bl(f,et),U);let ut=f.match(/^\s*import(?:\s+|(?=["'{*]))[^;]+;?\s*$/gm)||[];if(f=f.replace(/^\s*import(?:\s+|(?=["'{*]))[^;]+;?\s*$/gm,"").replace(/^\s*export\s*\{[^}]*\}\s*;?\s*$/gm,"").replace(/^\s*export\s+default\s+.*$/gm,"").trim(),u&&f)try{f=new Bun.Transpiler({loader:"js",minifyWhitespace:!0}).transformSync(f)}catch{}let J=`__stxBundle_${l}`,dt=new Set(L(t,!0).split(",").map((h)=>h.trim())),pt=S.map(([h,E])=>`get ${JSON.stringify(h)}() { return ${E} }${dt.has(h)?`, set ${JSON.stringify(h)}(__stxValue_${E}) { ${E} = __stxValue_${E} }`:""}`).join(", "),ft=S.map(([h])=>`var ${h} = undefined;`).join(`
4
4
  `),mt=S.map(([h])=>`${h} = ${J}[${JSON.stringify(h)}];`).join(`
5
5
  `);if(f=`${ut.join(`
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{g,Mo,Ga,Ka,eu,tu,nu,ru,su,vs,ou,Me,J,Le,iu,pr,au,Ya,Fo,je,n,gn,Za,m,pe,Np}from"./chunk-qq40hxg9.js";import"./chunk-gny4j06b.js";import"./chunk-t6m5d64b.js";import"./chunk-w28wc7mv.js";import"./chunk-6beg47t4.js";import"./chunk-gtktv6nn.js";export{pe as clearComponentCache,Fo as componentClientSignalNames,Mo as convertToCommonJS,m as createDetailedErrorMessage,su as extractDirectiveNames,Ga as extractScriptFromTemplate,g as extractVariables,n as fileExists,Np as getComponentCacheStats,tu as getPositionInfo,J as getSharedTranspiler,Za as getSourceLineInfo,ru as hasDirectives,Ka as hasVariables,au as isHydrateTrigger,ou as isJavaScriptScript,je as renderComponentWithSlot,gn as resolveTemplatePath,iu as scopeOnRootElement,vs as scopeSequenceKey,Me as shouldTranspileTypeScript,Ya as slotContentHasExpressions,Le as transpileTypeScript,pr as userComponentFileExists,nu as validateDirective,eu as validateTemplate};
2
+ import{g,Mo,Ka,Ga,eu,tu,nu,ru,su,vs,ou,Me,J,Le,iu,pr,au,Ya,Fo,je,n,gn,Za,m,pe,Np}from"./chunk-t3e5tv4h.js";import"./chunk-8x34g2ad.js";import"./chunk-t6m5d64b.js";import"./chunk-3tp7r57c.js";import"./chunk-6beg47t4.js";import"./chunk-gtktv6nn.js";export{pe as clearComponentCache,Fo as componentClientSignalNames,Mo as convertToCommonJS,m as createDetailedErrorMessage,su as extractDirectiveNames,Ka as extractScriptFromTemplate,g as extractVariables,n as fileExists,Np as getComponentCacheStats,tu as getPositionInfo,J as getSharedTranspiler,Za as getSourceLineInfo,ru as hasDirectives,Ga as hasVariables,au as isHydrateTrigger,ou as isJavaScriptScript,je as renderComponentWithSlot,gn as resolveTemplatePath,iu as scopeOnRootElement,vs as scopeSequenceKey,Me as shouldTranspileTypeScript,Ya as slotContentHasExpressions,Le as transpileTypeScript,pr as userComponentFileExists,nu as validateDirective,eu as validateTemplate};
@@ -1,4 +1,4 @@
1
1
  // @bun
2
2
  import m from"path";var y=/__stxModules\["((?:[^"\\]|\\.)*)"\]/g;function I(...o){let r=new Set;for(let s of o){if(!s||!s.includes("__stxModules["))continue;for(let e of s.matchAll(y))try{r.add(JSON.parse(`"${e[1]}"`))}catch{}}return[...r].sort()}async function w(o,r={}){if(o.length===0)return null;let s=process.cwd(),e=[],a=[];o.forEach((t,c)=>{let i=t.startsWith("npm:")?t.slice(4):m.resolve(s,t),l=`__stxRegistered${c}`,p=JSON.stringify(t);e.push(`import * as ${l} from ${JSON.stringify(i)};`),a.push(`if (!globalThis.__stxModules[${p}]) globalThis.__stxModules[${p}] = ${l};`)});let d=[...e,"globalThis.__stxModules = globalThis.__stxModules || {};",...a].join(`
3
- `),n;try{let{bundleClientScript:t}=await import("./chunk-d2nkm1jt.js");n=await t(d,m.join(s,".stx-module-registry.ts"),{projectRoot:s,minify:r.minify,externalizeUserModules:!1,collectInputs:r.collectInputs,throwOnFailure:!0})}catch(t){let{formatBuildFailure:c}=await import("./chunk-6kam8r5y.js"),i=c(t);console.warn(`[stx] could not build the page module registry (#1957): ${i}`);let l=`[stx] the page module registry did not build, so ${o.join(", ")} cannot load (#1957): ${i}`;return`;console.error(${JSON.stringify(l)});`}let{transformAutoImports:f,generateAutoImportDestructuring:_}=await import("./chunk-0t65m9nw.js"),u=f(n),h=_(u.stxImports,u.browserImports),{transformStoreImports:x}=await import("./chunk-9859r1d5.js");n=x(u.code);let g=JSON.stringify(new Bun.CryptoHasher("md5").update(d).digest("hex").slice(0,12));return[";(function() {"," var __stxBundles = globalThis.__stxModuleBundles || (globalThis.__stxModuleBundles = {});",` if (__stxBundles[${g}]) return;`,` __stxBundles[${g}] = true;`,h,n,"})();"].join(`
3
+ `),n;try{let{bundleClientScript:t}=await import("./chunk-01bd9hrj.js");n=await t(d,m.join(s,".stx-module-registry.ts"),{projectRoot:s,minify:r.minify,externalizeUserModules:!1,collectInputs:r.collectInputs,throwOnFailure:!0})}catch(t){let{formatBuildFailure:c}=await import("./chunk-6kam8r5y.js"),i=c(t);console.warn(`[stx] could not build the page module registry (#1957): ${i}`);let l=`[stx] the page module registry did not build, so ${o.join(", ")} cannot load (#1957): ${i}`;return`;console.error(${JSON.stringify(l)});`}let{transformAutoImports:f,generateAutoImportDestructuring:_}=await import("./chunk-jsac71cy.js"),u=f(n),h=_(u.stxImports,u.browserImports),{transformStoreImports:x}=await import("./chunk-9859r1d5.js");n=x(u.code);let g=JSON.stringify(new Bun.CryptoHasher("md5").update(d).digest("hex").slice(0,12));return[";(function() {"," var __stxBundles = globalThis.__stxModuleBundles || (globalThis.__stxModuleBundles = {});",` if (__stxBundles[${g}]) return;`,` __stxBundles[${g}] = true;`,h,n,"})();"].join(`
4
4
  `)}export{w as buildModuleRegistryScript,I as registeredModuleIdsIn};