@stacksjs/bun-router 0.0.26 → 0.1.0

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 (103) hide show
  1. package/dist/chunk-0gjq8ttx.js +14 -0
  2. package/dist/chunk-0t5vz87j.js +35 -0
  3. package/dist/chunk-30rkn2ym.js +2 -0
  4. package/dist/chunk-38cmrard.js +2 -0
  5. package/dist/chunk-3qna6dwd.js +2 -0
  6. package/dist/chunk-4d5fmta0.js +2 -0
  7. package/dist/chunk-4x3b4b4q.js +2 -0
  8. package/dist/chunk-5be9x5cq.js +3 -0
  9. package/dist/chunk-5mxby3fd.js +1654 -0
  10. package/dist/chunk-5n0ckcmc.js +3 -0
  11. package/dist/chunk-5ncn73tp.js +3 -0
  12. package/dist/chunk-5s0pnsd6.js +12 -0
  13. package/dist/chunk-5s1pr62n.js +3 -0
  14. package/dist/chunk-67wgad4f.js +60 -0
  15. package/dist/chunk-6bbmkwng.js +3 -0
  16. package/dist/chunk-6s1kbajm.js +7851 -0
  17. package/dist/chunk-6sjvhy5f.js +3 -0
  18. package/dist/chunk-6xed4va1.js +2 -0
  19. package/dist/chunk-73k79n7q.js +15413 -0
  20. package/dist/chunk-748n6ydj.js +2 -0
  21. package/dist/chunk-7qnxdedn.js +321 -0
  22. package/dist/chunk-7rsf8tes.js +898 -0
  23. package/dist/chunk-8aspmtf1.js +2 -0
  24. package/dist/chunk-8wpj3fqe.js +351 -0
  25. package/dist/chunk-8yfdg595.js +2 -0
  26. package/dist/chunk-90eze7av.js +3 -0
  27. package/dist/chunk-9805tt8n.js +341 -0
  28. package/dist/chunk-9dvwyej7.js +2 -0
  29. package/dist/chunk-9ght4n4r.js +216 -0
  30. package/dist/chunk-a2w45krb.js +2 -0
  31. package/dist/chunk-a3wahyg7.js +3 -0
  32. package/dist/chunk-a547f2ab.js +48 -0
  33. package/dist/chunk-bqdycvtc.js +2 -0
  34. package/dist/chunk-brpgjyqg.js +3 -0
  35. package/dist/chunk-cd03rk3x.js +2 -0
  36. package/dist/chunk-csfrpsp7.js +185 -0
  37. package/dist/chunk-ct0m17q5.js +2 -0
  38. package/dist/chunk-dhbvvr5h.js +2 -0
  39. package/dist/chunk-dhptcsya.js +943 -0
  40. package/dist/chunk-dq93zag9.js +2 -0
  41. package/dist/chunk-dxg045wj.js +5 -0
  42. package/dist/chunk-e3qej0jr.js +4 -0
  43. package/dist/chunk-edrtesh7.js +2 -0
  44. package/dist/chunk-ejcws37w.js +2 -0
  45. package/dist/chunk-ex5fkjah.js +397 -0
  46. package/dist/chunk-ex890p45.js +51 -0
  47. package/dist/chunk-f69cpnhw.js +2 -0
  48. package/dist/chunk-fjf53b44.js +2 -0
  49. package/dist/chunk-fjzye4qj.js +2 -0
  50. package/dist/chunk-gfd23b6t.js +2 -0
  51. package/dist/chunk-habv0vef.js +12 -0
  52. package/dist/chunk-hmgedrmr.js +11 -0
  53. package/dist/chunk-hz6fc788.js +2 -0
  54. package/dist/chunk-jff6j9y3.js +10 -0
  55. package/dist/chunk-jmeb7n8k.js +70 -0
  56. package/dist/chunk-jrf5a2ap.js +2 -0
  57. package/dist/chunk-jy2jhcpy.js +246 -0
  58. package/dist/chunk-kc659vhx.js +4 -0
  59. package/dist/chunk-kjtjbcq4.js +71 -0
  60. package/dist/chunk-krkchy8v.js +4 -0
  61. package/dist/chunk-kxp888dn.js +4540 -0
  62. package/dist/chunk-m249t3je.js +3 -0
  63. package/dist/chunk-m9yabnjx.js +2 -0
  64. package/dist/chunk-mekrq9wd.js +2 -0
  65. package/dist/chunk-mmxv535f.js +82 -0
  66. package/dist/chunk-mypn7jss.js +2 -0
  67. package/dist/chunk-n18x1k3c.js +2 -0
  68. package/dist/chunk-nkddjzsa.js +2 -0
  69. package/dist/chunk-pjmhqmr9.js +2 -0
  70. package/dist/chunk-qyrnsaq1.js +2 -0
  71. package/dist/chunk-r19ff2qm.js +62 -0
  72. package/dist/chunk-r338fssq.js +2 -0
  73. package/dist/chunk-s36z58x2.js +29 -0
  74. package/dist/chunk-s3dn1kwx.js +231 -0
  75. package/dist/chunk-s79dd325.js +471 -0
  76. package/dist/chunk-sw0chtw4.js +4 -0
  77. package/dist/chunk-ta38j9em.js +2 -0
  78. package/dist/chunk-tpfgntwj.js +4211 -0
  79. package/dist/chunk-vr10sbbh.js +3 -0
  80. package/dist/chunk-vsh4390q.js +358 -0
  81. package/dist/chunk-vv3gb1m5.js +84 -0
  82. package/dist/chunk-vw8rwv6e.js +2 -0
  83. package/dist/chunk-w4r464v5.js +288 -0
  84. package/dist/chunk-wcrqs5z9.js +2 -0
  85. package/dist/chunk-x6d1rmwa.js +2 -0
  86. package/dist/chunk-x7ft15zz.js +2 -0
  87. package/dist/chunk-x8trwn7j.js +3 -0
  88. package/dist/chunk-xg9xscqz.js +1 -0
  89. package/dist/chunk-xhepdj1f.js +2 -0
  90. package/dist/chunk-xv2em0q4.js +4 -0
  91. package/dist/chunk-ypw6g0te.js +2 -0
  92. package/dist/chunk-z8szsm21.js +2 -0
  93. package/dist/chunk-zetqzgf3.js +194 -0
  94. package/dist/chunk-zfbh14qe.js +2 -0
  95. package/dist/chunk-zhx0hxdd.js +28 -0
  96. package/dist/cli.js +67 -3240
  97. package/dist/container/index.js +1 -321
  98. package/dist/index.js +80 -13987
  99. package/dist/types.d.ts +12 -2
  100. package/package.json +1 -1
  101. package/dist/chunk-1ahs68ys.js +0 -18
  102. package/dist/chunk-cgptvjdf.js +0 -18131
  103. package/dist/chunk-g3ybefhg.js +0 -1923
@@ -0,0 +1,29 @@
1
+ // @bun
2
+ import{Fu as x,Ku as B,Lu as k,Mu as O,Nu as U}from"./chunk-5n0ckcmc.js";import{Zu as H}from"./chunk-a3wahyg7.js";import{resolve as Y,basename as oe,extname as ce,join as de}from"path";import{mkdir as ue}from"fs/promises";var ae={enabled:!0,directory:".stx/media-cache",maxAge:30,maxSize:2000,cacheTranscoded:!0,cacheThumbnails:!0,cacheManifests:!0};class T{config;constructor(t={}){this.config={...ae,...t}}async get(t,e){return k(t,e,"video",this.config)}async set(t,e,a){return O(t,e,a,"video",this.config)}async clear(){return U("video",this.config)}updateConfig(t){this.config={...this.config,...t}}}var C=null;function V(t){if(!C)C=new T(t);else if(t)C.updateConfig(t);return C}async function D(t,e,a){let n=a?{directory:`${a.outputDir}/../.cache`}:{};return V(n).get(t,e)}async function M(t,e,a,n){let u=n?{directory:`${n.outputDir}/../.cache`}:{};return V(u).set(t,e,a)}async function ie(){return V().clear()}import{resolve as A,basename as I,extname as F,join as R}from"path";import{mkdir as W}from"fs/promises";async function q(){try{return await import("ts-videos")}catch{return null}}async function L(t,e,a,n){let u=await q();if(!u)return console.warn("[stx-media] ts-videos not installed, cannot generate poster"),null;try{let r=A(t);if(!await B(r))return null;await W(a,{recursive:!0});let i=await x(r),o=I(t,F(t)),s=e.format||"webp",h=e.timestamp||0,p=`${o}-poster-${i}.${s}`,l=R(a,p),m=await u.extractThumbnails(r,{timestamps:[h],width:e.width||1280,height:e.height,format:s,quality:e.quality||85,outputDir:a,outputPattern:p.replace(`.${s}`,"")});if(m&&m.length>0){let c=m[0];return{path:l,url:`${n}/${p}`,width:c.width||e.width||1280,height:c.height||720,timestamp:h,size:c.size||0}}return null}catch(r){return console.warn(`[stx-media] Failed to generate poster: ${r}`),null}}async function z(t,e,a,n){let u=await q();if(!u)return[];try{let r=A(t);if(!await B(r))return[];await W(a,{recursive:!0});let i=await x(r),o=I(t,F(t)),s=e.format||"webp",h=(await new u.Input(r).getInfo()).duration||60,p=e.count||10,l=e.interval||h/p,m=[];for(let d=0;d<p&&d*l<h;d++)m.push(d*l);let c=await u.extractThumbnails(r,{timestamps:m,width:e.width||320,format:s,quality:e.quality||80,outputDir:a,outputPattern:`${o}-thumb-${i}`});if(c&&c.length>0)return c.map((d,f)=>({path:d.path||R(a,`${o}-thumb-${i}-${f}.${s}`),url:`${n}/${o}-thumb-${i}-${f}.${s}`,width:d.width||e.width||320,height:d.height||180,timestamp:m[f],size:d.size||0}));return[]}catch(r){return console.warn(`[stx-media] Failed to generate thumbnails: ${r}`),[]}}async function re(t,e,a,n){let u=await q();if(!u)return console.warn("[stx-media] ts-videos not installed, cannot generate sprite sheet"),null;try{let r=A(t);if(!await B(r))return null;await W(a,{recursive:!0});let i=await x(r),o=I(t,F(t)),s=(await new u.Input(r).getInfo()).duration||60,h=e.columns||10,p=e.interval||5,l=e.thumbnailWidth||160,m=e.thumbnailHeight||90,c=e.format||"jpeg",d=Math.ceil(s/p),f=Math.ceil(d/h),b=`${o}-sprite-${i}.${c}`,w=R(a,b),y=[];for(let $=0;$<d;$++)y.push($*p);let g=await u.extractThumbnails(r,{timestamps:y,width:l,height:m,format:c,quality:e.quality||70,outputDir:R(a,".temp")});if(!g||g.length===0)return null;try{let $=await import("./chunk-gfd23b6t.js"),v=h*l,ge=f*m,pe=await $.createSprite({images:g.map((te)=>te.path),columns:h,padding:0,outputPath:w,format:c,quality:e.quality||70});return{url:`${n}/${b}`,path:w,columns:h,rows:f,thumbnailWidth:l,thumbnailHeight:m,interval:p,totalFrames:d}}catch{return console.warn("[stx-media] ts-images not installed, sprite sheet generation skipped"),null}}catch(r){return console.warn(`[stx-media] Failed to generate sprite sheet: ${r}`),null}}import{resolve as Q,basename as X,extname as _,join as S}from"path";import{mkdir as P,writeFile as G}from"fs/promises";async function J(){try{return await import("ts-videos")}catch{return null}}var K=[{label:"1080p",width:1920,height:1080,bitrate:5000000,audioBitrate:192000},{label:"720p",width:1280,height:720,bitrate:2500000,audioBitrate:128000},{label:"480p",width:854,height:480,bitrate:1e6,audioBitrate:96000},{label:"360p",width:640,height:360,bitrate:600000,audioBitrate:64000}];async function E(t,e,a,n,u){let r=await J();if(!r)return console.warn("[stx-media] ts-videos not installed, cannot generate HLS manifest"),null;try{let i=Q(t);if(!await B(i))return null;let o=await x(i),s=X(t,_(t)),h=S(a,`${s}-${o}-hls`);await P(h,{recursive:!0});let p=e.length>0?e:K,l=u?.segmentDuration||6,m=(await new r.Input(i).getInfo()).duration||0,c=[],d=0;for(let w of p){let y=S(h,w.label);await P(y,{recursive:!0});let g=`${w.label}.m3u8`,$=S(y,g);try{let v=await r.generateHLS(i,{outputDir:y,segmentDuration:l,width:w.width,height:w.height,videoBitrate:w.bitrate,audioBitrate:w.audioBitrate,playlistName:w.label});if(v)c.push({quality:w,url:`${n}/${s}-${o}-hls/${w.label}/${g}`,path:$}),d+=v.segmentCount||Math.ceil(m/l)}catch(v){console.warn(`[stx-media] Failed to generate HLS for ${w.label}: ${v}`)}}if(c.length===0)return null;let f=S(h,"master.m3u8"),b=ne(c,n,s,o);return await G(f,b),{manifestUrl:`${n}/${s}-${o}-hls/master.m3u8`,manifestPath:f,playlists:c,segmentCount:d,duration:m}}catch(i){return console.warn(`[stx-media] Failed to generate HLS manifest: ${i}`),null}}function ne(t,e,a,n){let u=["#EXTM3U","#EXT-X-VERSION:3"];for(let r of t){let{quality:i}=r,o=i.bitrate+(i.audioBitrate||128000),s=`${i.width}x${i.height||Math.round(i.width*9/16)}`;u.push(`#EXT-X-STREAM-INF:BANDWIDTH=${o},RESOLUTION=${s},NAME="${i.label}"`,`${i.label}/${i.label}.m3u8`)}return u.join(`
3
+ `)}async function j(t,e,a,n,u){let r=await J();if(!r)return console.warn("[stx-media] ts-videos not installed, cannot generate DASH manifest"),null;try{let i=Q(t);if(!await B(i))return null;let o=await x(i),s=X(t,_(t)),h=S(a,`${s}-${o}-dash`);await P(h,{recursive:!0});let p=e.length>0?e:K,l=u?.segmentDuration||4,m=u?.minBufferTime||2,c=(await new r.Input(i).getInfo()).duration||0,d=[],f=[];for(let g of p){let $=S(h,g.label);await P($,{recursive:!0});try{if(await r.generateDASH(i,{outputDir:$,segmentDuration:l,width:g.width,height:g.height,videoBitrate:g.bitrate,audioBitrate:g.audioBitrate})){if(d.push({bandwidth:g.bitrate,width:g.width,height:g.height||Math.round(g.width*9/16),url:`${n}/${s}-${o}-dash/${g.label}/video`}),g.audioBitrate)f.push({bandwidth:g.audioBitrate,url:`${n}/${s}-${o}-dash/${g.label}/audio`})}}catch(v){console.warn(`[stx-media] Failed to generate DASH for ${g.label}: ${v}`)}}if(d.length===0)return null;let b=S(h,"manifest.mpd"),w=se(d,f,c,l,m);await G(b,w);let y=[{type:"video",representations:d}];if(f.length>0)y.push({type:"audio",representations:f});return{manifestUrl:`${n}/${s}-${o}-dash/manifest.mpd`,manifestPath:b,adaptationSets:y,duration:c}}catch(i){return console.warn(`[stx-media] Failed to generate DASH manifest: ${i}`),null}}function se(t,e,a,n,u){let r=N(a),i=N(u),o=`<?xml version="1.0" encoding="UTF-8"?>
4
+ <MPD xmlns="urn:mpeg:dash:schema:mpd:2011"
5
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
+ xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd"
7
+ type="static"
8
+ mediaPresentationDuration="${r}"
9
+ minBufferTime="${i}"
10
+ profiles="urn:mpeg:dash:profile:isoff-on-demand:2011">
11
+ <Period>
12
+ <AdaptationSet mimeType="video/mp4" codecs="avc1.64001f" segmentAlignment="true" startWithSAP="1">
13
+ `;for(let s=0;s<t.length;s++){let h=t[s];o+=` <Representation id="video${s}" bandwidth="${h.bandwidth}" width="${h.width}" height="${h.height}">
14
+ <BaseURL>${h.url}/</BaseURL>
15
+ <SegmentBase indexRange="0-999">
16
+ <Initialization range="0-999"/>
17
+ </SegmentBase>
18
+ </Representation>
19
+ `}if(o+=` </AdaptationSet>
20
+ `,e.length>0){o+=` <AdaptationSet mimeType="audio/mp4" codecs="mp4a.40.2" segmentAlignment="true" startWithSAP="1">
21
+ `;for(let s=0;s<e.length;s++){let h=e[s];o+=` <Representation id="audio${s}" bandwidth="${h.bandwidth}">
22
+ <BaseURL>${h.url}/</BaseURL>
23
+ <SegmentBase indexRange="0-999">
24
+ <Initialization range="0-999"/>
25
+ </SegmentBase>
26
+ </Representation>
27
+ `}o+=` </AdaptationSet>
28
+ `}return o+=` </Period>
29
+ </MPD>`,o}function N(t){let e=Math.floor(t/3600),a=Math.floor(t%3600/60),n=Math.floor(t%60),u="PT";if(e>0)u+=`${e}H`;if(a>0)u+=`${a}M`;return u+=`${n}S`,u}async function Z(){try{return await import("ts-videos")}catch{return null}}function he(t){switch(t){case"very-low":return 500000;case"low":return 1e6;case"medium":return 2500000;case"high":return 5000000;case"very-high":return 1e7;case"lossless":return 0;default:return 2500000}}function le(t){switch(t){case"youtube":return{codec:"h264",maxWidth:1920,maxHeight:1080,frameRate:30,audioCodec:"aac",audioBitrate:128000};case"twitter":return{codec:"h264",maxWidth:1280,maxHeight:720,frameRate:30,bitrate:5000000,audioCodec:"aac",audioBitrate:128000};case"instagram-feed":return{codec:"h264",maxWidth:1080,maxHeight:1080,frameRate:30,bitrate:3500000,audioCodec:"aac",audioBitrate:128000};case"instagram-story":case"instagram-reels":return{codec:"h264",maxWidth:1080,maxHeight:1920,frameRate:30,bitrate:3500000,audioCodec:"aac",audioBitrate:128000};case"tiktok":return{codec:"h264",maxWidth:1080,maxHeight:1920,frameRate:30,bitrate:4000000,audioCodec:"aac",audioBitrate:128000};case"discord":return{codec:"h264",maxWidth:1920,maxHeight:1080,frameRate:60,bitrate:8000000,audioCodec:"aac",audioBitrate:192000};case"linkedin":return{codec:"h264",maxWidth:1920,maxHeight:1080,frameRate:30,bitrate:5000000,audioCodec:"aac",audioBitrate:128000};case"facebook":return{codec:"h264",maxWidth:1280,maxHeight:720,frameRate:30,bitrate:4000000,audioCodec:"aac",audioBitrate:128000};case"web-progressive":return{codec:"h264",maxWidth:1920,maxHeight:1080,frameRate:30,audioCodec:"aac",audioBitrate:128000,twoPass:!0};case"web-streaming":return{codec:"h264",maxWidth:1920,maxHeight:1080,frameRate:30,audioCodec:"aac",audioBitrate:128000};default:return{}}}async function ee(t){let e=await Z();if(!e)return null;try{let a=Y(t),n=await new e.Input(a).getInfo();return{duration:n.duration||0,width:n.width||0,height:n.height||0,frameRate:n.frameRate||0,bitrate:n.bitrate||0,codec:n.videoCodec||"",audioCodec:n.audioCodec}}catch(a){return console.warn(`[stx-media] Failed to analyze video: ${a}`),null}}async function me(t,e,a,n){let u=await Z();if(!u)return console.warn("[stx-media] ts-videos not installed, skipping processing"),{src:t,processed:!1};let r=await D(t,e,a);if(r)return r;try{let i=Y(t);if(!await B(i))return{src:t,processed:!1,errors:[`Source file not found: ${t}`]};let o=a.outputDir||"dist/videos",s=a.baseUrl||"/videos";await ue(o,{recursive:!0});let h=await x(i),p=oe(t,ce(t)),l={src:t,processed:!0,hash:h};n?.({percentage:5,stage:"analyzing"}),l.metadata=await ee(i)||void 0;let m={};if(e.quality)m.bitrate=he(e.quality);if(e.platform)Object.assign(m,le(e.platform));if(e.transcode)Object.assign(m,e.transcode);if(Object.keys(m).length>0||e.process){n?.({percentage:10,stage:"transcoding"});let c=`${p}-${h}.mp4`,d=de(o,c);try{let f=await fe(i,d,m,u,(b)=>n?.({percentage:10+b*0.5,stage:"transcoding"}));if(f)l.transcoded={path:d,url:`${s}/${c}`,duration:f.duration,size:f.size,video:{codec:m.codec||"h264",width:f.width,height:f.height,bitrate:f.bitrate,frameRate:f.frameRate},audio:f.audioCodec?{codec:m.audioCodec||"aac",bitrate:m.audioBitrate||128000,sampleRate:m.sampleRate||48000,channels:m.channels||2}:void 0}}catch(f){l.errors=l.errors||[],l.errors.push(`Transcoding failed: ${f}`)}}if(e.generatePoster){n?.({percentage:65,stage:"generating-poster"});let c=typeof e.generatePoster==="object"?e.generatePoster:{timestamp:0},d=await L(i,c,o,s);if(d)l.poster=d}if(a.thumbnails?.enabled){n?.({percentage:70,stage:"generating-thumbnails"});let c=await z(i,a.thumbnails,o,s);if(c.length>0)l.thumbnails=c}if(e.streaming){n?.({percentage:80,stage:"generating-manifests"});let c=typeof e.streaming==="object"?e.streaming:a.streaming||{format:"hls"};if(c.format==="hls"||c.format===void 0){let d=await E(i,c.qualities||a.streaming?.defaultQualities||[],o,s);if(d)l.streaming={...l.streaming,hls:d}}if(c.format==="dash"){let d=await j(i,c.qualities||a.streaming?.defaultQualities||[],o,s);if(d)l.streaming={...l.streaming,dash:d}}}if(e.spriteSheet)n?.({percentage:90,stage:"generating-sprite-sheet"});return n?.({percentage:100,stage:"complete"}),await M(t,e,l,a),l}catch(i){return{src:t,processed:!1,errors:[`Processing failed: ${i}`]}}}async function fe(t,e,a,n,u){try{let r=await new n.Conversion(t,e,{videoCodec:a.codec,videoBitrate:a.bitrate,width:a.maxWidth,height:a.maxHeight,frameRate:a.frameRate,audioCodec:a.audioCodec,audioBitrate:a.audioBitrate,sampleRate:a.sampleRate,channels:a.channels}).run((i)=>{u?.(i.percentage/100)});return{duration:r.duration||0,size:r.size||0,width:r.width||a.maxWidth||0,height:r.height||a.maxHeight||0,bitrate:r.bitrate||a.bitrate||0,frameRate:r.frameRate||a.frameRate||30,audioCodec:r.audioCodec}}catch(r){return console.error(`[stx-media] Transcoding failed: ${r}`),null}}export{T as uu,D as vu,M as wu,ie as xu,L as yu,z as zu,re as Au,E as Bu,j as Cu,ee as Du,me as Eu};
@@ -0,0 +1,231 @@
1
+ // @bun
2
+ import"./chunk-a3wahyg7.js";var d=0;function u(){return`eb-${++d}-${Date.now().toString(36)}`}function p(e,o={},n){let r=/@errorBoundary(?:\s*\(([^)]*)\))?\s*([\s\S]*?)@fallback\s*([\s\S]*?)@enderrorBoundary/gi;return e.replace(r,(t,a,l,s)=>{let i=u(),c=y(a||"");return b(i,l.trim(),s.trim(),c)})}function y(e){let o={},n=/(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|(\w+))/g,r;while((r=n.exec(e))!==null){let t=r[1],a=r[2]||r[3]||r[4];switch(t){case"id":o.id=a;break;case"logErrors":o.logErrors=a==="true";break}}return o}function b(e,o,n,r){let t=r.logErrors!==!1;return`
3
+ <div class="stx-error-boundary" data-boundary-id="${e}" data-has-error="false">
4
+ <div class="stx-error-boundary-content" data-boundary-content="${e}">
5
+ ${o}
6
+ </div>
7
+ <div class="stx-error-boundary-fallback" data-boundary-fallback="${e}" style="display: none;">
8
+ ${n}
9
+ </div>
10
+ </div>
11
+ <script>
12
+ (function() {
13
+ const boundaryId = '${e}';
14
+ const logErrors = ${t};
15
+ const boundary = document.querySelector('[data-boundary-id="' + boundaryId + '"]');
16
+ const contentEl = document.querySelector('[data-boundary-content="' + boundaryId + '"]');
17
+ const fallbackEl = document.querySelector('[data-boundary-fallback="' + boundaryId + '"]');
18
+
19
+ if (!boundary || !contentEl || !fallbackEl) return;
20
+
21
+ // Error state
22
+ let hasError = false;
23
+ let lastError = null;
24
+
25
+ // Show error fallback
26
+ function showFallback(error) {
27
+ hasError = true;
28
+ lastError = error;
29
+ boundary.setAttribute('data-has-error', 'true');
30
+ contentEl.style.display = 'none';
31
+ fallbackEl.style.display = '';
32
+
33
+ if (logErrors) {
34
+ console.error('[stx:errorBoundary:' + boundaryId + ']', error);
35
+ }
36
+
37
+ // Dispatch error event
38
+ boundary.dispatchEvent(new CustomEvent('stx:error', {
39
+ detail: { error: error, boundaryId: boundaryId },
40
+ bubbles: true
41
+ }));
42
+ }
43
+
44
+ // Retry function (resets the boundary)
45
+ function retry() {
46
+ hasError = false;
47
+ lastError = null;
48
+ boundary.setAttribute('data-has-error', 'false');
49
+ contentEl.style.display = '';
50
+ fallbackEl.style.display = 'none';
51
+
52
+ // Dispatch retry event
53
+ boundary.dispatchEvent(new CustomEvent('stx:retry', {
54
+ detail: { boundaryId: boundaryId },
55
+ bubbles: true
56
+ }));
57
+ }
58
+
59
+ // Expose retry function
60
+ window['$stxRetry_' + boundaryId.replace(/-/g, '_')] = retry;
61
+
62
+ // Make $retry available within the fallback
63
+ fallbackEl.querySelectorAll('[onclick*="$retry"]').forEach(function(el) {
64
+ const onclick = el.getAttribute('onclick');
65
+ if (onclick) {
66
+ el.setAttribute('onclick', onclick.replace(/\\$retry\\(\\)/g, "window['$stxRetry_" + boundaryId.replace(/-/g, '_') + "']()"));
67
+ }
68
+ });
69
+
70
+ // Handle @click="$retry()" syntax
71
+ fallbackEl.querySelectorAll('[\\\\@click*="$retry"]').forEach(function(el) {
72
+ el.addEventListener('click', function(e) {
73
+ e.preventDefault();
74
+ retry();
75
+ });
76
+ });
77
+
78
+ // Also check for data-onclick
79
+ fallbackEl.querySelectorAll('[data-onclick*="$retry"]').forEach(function(el) {
80
+ el.addEventListener('click', function(e) {
81
+ e.preventDefault();
82
+ retry();
83
+ });
84
+ });
85
+
86
+ // Catch errors in content
87
+ contentEl.addEventListener('error', function(e) {
88
+ showFallback(e.error || new Error('Unknown error'));
89
+ }, true);
90
+
91
+ // Wrap global error handler for this boundary
92
+ const originalOnError = window.onerror;
93
+ window.onerror = function(message, source, lineno, colno, error) {
94
+ // Check if error originated from within this boundary
95
+ if (contentEl.contains(document.activeElement) || isErrorFromBoundary(error)) {
96
+ showFallback(error || new Error(String(message)));
97
+ return true; // Prevent default handling
98
+ }
99
+ if (originalOnError) {
100
+ return originalOnError.apply(this, arguments);
101
+ }
102
+ return false;
103
+ };
104
+
105
+ // Helper to check if error is from this boundary (basic heuristic)
106
+ function isErrorFromBoundary(error) {
107
+ if (!error || !error.stack) return false;
108
+ return error.stack.includes(boundaryId);
109
+ }
110
+
111
+ // Expose error info
112
+ window.STX = window.STX || {};
113
+ window.STX.errorBoundaries = window.STX.errorBoundaries || {};
114
+ window.STX.errorBoundaries[boundaryId] = {
115
+ hasError: function() { return hasError; },
116
+ getError: function() { return lastError; },
117
+ retry: retry,
118
+ showFallback: showFallback
119
+ };
120
+ })();
121
+ </script>
122
+ `}async function f(e,o,n){try{return await e()}catch(r){if(n)n(r instanceof Error?r:Error(String(r)));else console.error("[stx:errorBoundary] SSR Error:",r);return o}}function E(e,o={}){let n=o.onError?(r)=>o.onError(r,{timestamp:Date.now(),boundaryId:"ssr"}):void 0;return(r)=>f(r,e,n)}function k(){return`
123
+ /* STX Error Boundary Styles */
124
+ .stx-error-boundary {
125
+ position: relative;
126
+ }
127
+
128
+ .stx-error-boundary[data-has-error="true"] .stx-error-boundary-content {
129
+ display: none;
130
+ }
131
+
132
+ .stx-error-boundary[data-has-error="true"] .stx-error-boundary-fallback {
133
+ display: block !important;
134
+ }
135
+
136
+ /* Default fallback styling (can be overridden) */
137
+ .stx-error-boundary-fallback {
138
+ padding: 1rem;
139
+ border: 1px solid #ef4444;
140
+ border-radius: 0.5rem;
141
+ background-color: #fef2f2;
142
+ color: #991b1b;
143
+ }
144
+
145
+ .stx-error-boundary-fallback button {
146
+ margin-top: 0.5rem;
147
+ padding: 0.5rem 1rem;
148
+ border: 1px solid #ef4444;
149
+ border-radius: 0.25rem;
150
+ background-color: #ef4444;
151
+ color: white;
152
+ cursor: pointer;
153
+ }
154
+
155
+ .stx-error-boundary-fallback button:hover {
156
+ background-color: #dc2626;
157
+ }
158
+
159
+ /* Dark mode support */
160
+ @media (prefers-color-scheme: dark) {
161
+ .stx-error-boundary-fallback {
162
+ background-color: #450a0a;
163
+ color: #fecaca;
164
+ }
165
+ }
166
+ `}function h(){return`
167
+ // STX Error Boundary Runtime
168
+ (function() {
169
+ if (typeof window === 'undefined') return;
170
+
171
+ window.STX = window.STX || {};
172
+ window.STX.errorBoundaries = window.STX.errorBoundaries || {};
173
+
174
+ // Create an error boundary programmatically
175
+ window.STX.createErrorBoundary = function(element, options) {
176
+ options = options || {};
177
+ const boundaryId = 'eb-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2);
178
+
179
+ let hasError = false;
180
+ let lastError = null;
181
+ let fallbackContent = options.fallback || '<p>Something went wrong</p>';
182
+
183
+ const contentWrapper = document.createElement('div');
184
+ contentWrapper.className = 'stx-error-boundary-content';
185
+
186
+ const fallbackWrapper = document.createElement('div');
187
+ fallbackWrapper.className = 'stx-error-boundary-fallback';
188
+ fallbackWrapper.style.display = 'none';
189
+ fallbackWrapper.innerHTML = fallbackContent;
190
+
191
+ // Move element's children to content wrapper
192
+ while (element.firstChild) {
193
+ contentWrapper.appendChild(element.firstChild);
194
+ }
195
+
196
+ element.appendChild(contentWrapper);
197
+ element.appendChild(fallbackWrapper);
198
+ element.classList.add('stx-error-boundary');
199
+ element.setAttribute('data-boundary-id', boundaryId);
200
+
201
+ function showFallback(error) {
202
+ hasError = true;
203
+ lastError = error;
204
+ element.setAttribute('data-has-error', 'true');
205
+ contentWrapper.style.display = 'none';
206
+ fallbackWrapper.style.display = '';
207
+ if (options.onError) options.onError(error);
208
+ }
209
+
210
+ function retry() {
211
+ hasError = false;
212
+ lastError = null;
213
+ element.setAttribute('data-has-error', 'false');
214
+ contentWrapper.style.display = '';
215
+ fallbackWrapper.style.display = 'none';
216
+ if (options.onRetry) options.onRetry();
217
+ }
218
+
219
+ window.STX.errorBoundaries[boundaryId] = {
220
+ hasError: function() { return hasError; },
221
+ getError: function() { return lastError; },
222
+ retry: retry,
223
+ showFallback: showFallback
224
+ };
225
+
226
+ return window.STX.errorBoundaries[boundaryId];
227
+ };
228
+
229
+ console.log('[stx] Error boundary runtime initialized');
230
+ })();
231
+ `}export{f as withErrorBoundary,p as processErrorBoundaryDirectives,h as generateErrorBoundaryRuntime,k as generateErrorBoundaryCSS,E as createErrorBoundary};