@stacksjs/stx 0.2.762 → 0.2.765

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 (246) hide show
  1. package/dist/chunk-01484snf.js +2 -0
  2. package/dist/{chunk-b51p56k5.js → chunk-07c8rk93.js} +2 -2
  3. package/dist/chunk-09cera09.js +2 -0
  4. package/dist/{chunk-zhrz4zvw.js → chunk-0d29b573.js} +4 -4
  5. package/dist/chunk-0f5276fm.js +2 -0
  6. package/dist/{chunk-8yyq3nfg.js → chunk-0nzeqc13.js} +2 -2
  7. package/dist/chunk-16n128gh.js +2 -0
  8. package/dist/chunk-171bbyqv.js +2 -0
  9. package/dist/{chunk-dnsf934e.js → chunk-1day2nbr.js} +5 -5
  10. package/dist/chunk-1g0g498y.js +2 -0
  11. package/dist/{chunk-x5seqmrv.js → chunk-1g5fg1ys.js} +2 -2
  12. package/dist/chunk-1qppvj48.js +2 -0
  13. package/dist/{chunk-tpfxvw4q.js → chunk-1w4a0xya.js} +14 -14
  14. package/dist/chunk-1z77g0j6.js +2 -0
  15. package/dist/chunk-2hbwpm36.js +177 -0
  16. package/dist/{chunk-rh2qth8r.js → chunk-2mckhfet.js} +5 -5
  17. package/dist/chunk-31e7xkrt.js +2 -0
  18. package/dist/chunk-3ffz7pd4.js +2 -0
  19. package/dist/{chunk-37y8sg48.js → chunk-3mf27gj6.js} +2 -2
  20. package/dist/{chunk-gwjh981q.js → chunk-49w4cbqb.js} +7 -7
  21. package/dist/chunk-4bhbtvtm.js +2 -0
  22. package/dist/{chunk-18chz0q4.js → chunk-4m3666pm.js} +1 -1
  23. package/dist/{chunk-xtwc2dbk.js → chunk-4tppbw4r.js} +2 -2
  24. package/dist/{chunk-rmk8efc3.js → chunk-4yk7zngj.js} +109 -109
  25. package/dist/{chunk-rj3p5fdy.js → chunk-51dxp9w9.js} +3 -3
  26. package/dist/chunk-59r38w60.js +2 -0
  27. package/dist/chunk-5ttj2c0h.js +2 -0
  28. package/dist/chunk-5x312c05.js +2 -0
  29. package/dist/chunk-65h2h51z.js +2 -0
  30. package/dist/chunk-6ch8t3d9.js +3 -0
  31. package/dist/{chunk-tshpcvcy.js → chunk-6h6teyxp.js} +2 -2
  32. package/dist/{chunk-319aez2f.js → chunk-6jnrpnxb.js} +3 -3
  33. package/dist/chunk-6rd0zz6k.js +2 -0
  34. package/dist/{chunk-8y54tpbr.js → chunk-74y29xxs.js} +5 -5
  35. package/dist/{chunk-t1shvfhm.js → chunk-7aw9qm74.js} +47 -47
  36. package/dist/chunk-7bvhpdqv.js +2 -0
  37. package/dist/{chunk-0fs9kx0h.js → chunk-7yx2ztt5.js} +2 -2
  38. package/dist/{chunk-f8p8ggvw.js → chunk-8hanmv49.js} +4 -4
  39. package/dist/{chunk-j1tsda22.js → chunk-8prk7e1z.js} +10 -10
  40. package/dist/{chunk-nm9tnxnw.js → chunk-8zgvr0fw.js} +5 -5
  41. package/dist/{chunk-pqbxa0r7.js → chunk-a2yptg7r.js} +2 -2
  42. package/dist/{chunk-qystt1qc.js → chunk-a627f39k.js} +1 -1
  43. package/dist/{chunk-ds6mbfdq.js → chunk-as4s0nf5.js} +3 -3
  44. package/dist/chunk-axxd53tn.js +2 -0
  45. package/dist/{chunk-evxp3wmv.js → chunk-ay02q27h.js} +7 -7
  46. package/dist/{chunk-2eamszdq.js → chunk-ay5g5cbk.js} +2 -2
  47. package/dist/chunk-b8ar6431.js +2 -0
  48. package/dist/{chunk-yb71b2d6.js → chunk-b8hsvzqb.js} +2 -2
  49. package/dist/chunk-bnm7ym0g.js +2 -0
  50. package/dist/{chunk-0sd4td6z.js → chunk-bnwkytme.js} +3 -3
  51. package/dist/chunk-brg2ydrk.js +2 -0
  52. package/dist/chunk-bwkw2dw3.js +2 -0
  53. package/dist/chunk-c0fwppzc.js +2 -0
  54. package/dist/{chunk-8rk79ha1.js → chunk-c1b481my.js} +2 -2
  55. package/dist/chunk-c5kpc7rn.js +2 -0
  56. package/dist/{chunk-59k4xb92.js → chunk-c5mbhfff.js} +5 -5
  57. package/dist/chunk-c8256r1a.js +2 -0
  58. package/dist/chunk-cap6exxx.js +2 -0
  59. package/dist/{chunk-mbe4gqd3.js → chunk-ccedry39.js} +2 -2
  60. package/dist/chunk-cft1sprt.js +2 -0
  61. package/dist/{chunk-qjbcp3tc.js → chunk-cswar3zs.js} +3 -3
  62. package/dist/{chunk-t2cq4bpe.js → chunk-dphhs29v.js} +6 -6
  63. package/dist/chunk-dt0deg4z.js +2 -0
  64. package/dist/{chunk-jgk5j35w.js → chunk-dvh63p75.js} +4 -4
  65. package/dist/{chunk-932zx5q4.js → chunk-dxk5r71v.js} +6 -6
  66. package/dist/{chunk-d96xddt9.js → chunk-e1e5xf8z.js} +13 -13
  67. package/dist/{chunk-w2pch5xn.js → chunk-e645nk33.js} +2 -2
  68. package/dist/{chunk-qpb80r4b.js → chunk-efr9dgt6.js} +2 -2
  69. package/dist/chunk-ejqr5cva.js +2 -0
  70. package/dist/{chunk-fxmc5006.js → chunk-et831a4y.js} +2 -2
  71. package/dist/{chunk-5yhv5eqq.js → chunk-ev4zxhpd.js} +2 -2
  72. package/dist/chunk-evbxyw80.js +2 -0
  73. package/dist/chunk-f66n66c8.js +2 -0
  74. package/dist/chunk-f6h8yagj.js +2 -0
  75. package/dist/{chunk-y8pftjg8.js → chunk-fjbhtakz.js} +1 -1
  76. package/dist/chunk-fpsm2qed.js +2 -0
  77. package/dist/{chunk-v1ff2dfp.js → chunk-fta169tc.js} +3 -3
  78. package/dist/{chunk-a222bwpc.js → chunk-ftt3r7wh.js} +5 -5
  79. package/dist/{chunk-48g9wez2.js → chunk-fz717vpc.js} +29 -29
  80. package/dist/chunk-fzf7yfpn.js +2 -0
  81. package/dist/chunk-gaatje2g.js +2 -0
  82. package/dist/{chunk-b0z2n941.js → chunk-h8yk9qm7.js} +2 -2
  83. package/dist/chunk-hfcmbbkq.js +2 -0
  84. package/dist/{chunk-3mz088mb.js → chunk-jb1c4e49.js} +2 -2
  85. package/dist/chunk-jhz0dvqz.js +2 -0
  86. package/dist/chunk-k54pgbzm.js +2 -0
  87. package/dist/{chunk-r8zhed35.js → chunk-kc3kt59e.js} +2 -2
  88. package/dist/chunk-kkx2gqk8.js +2 -0
  89. package/dist/{chunk-rqd6b2nc.js → chunk-knzp4c6m.js} +3 -3
  90. package/dist/{chunk-m3z13f59.js → chunk-kwy0spcd.js} +3 -3
  91. package/dist/{chunk-b7x8b83z.js → chunk-m15nbvck.js} +1 -1
  92. package/dist/{chunk-wby7qzha.js → chunk-m3dr63n0.js} +3 -3
  93. package/dist/{chunk-eb6p3p62.js → chunk-mdtjjzqc.js} +2 -2
  94. package/dist/{chunk-epa73jvs.js → chunk-mmcqgwk7.js} +2 -2
  95. package/dist/{chunk-02c46de1.js → chunk-mpaepc7n.js} +165 -42
  96. package/dist/{chunk-0kq0k4pg.js → chunk-n5dd6rpt.js} +2 -2
  97. package/dist/{chunk-jyp2mmts.js → chunk-n8gfetjx.js} +2 -2
  98. package/dist/chunk-n9zka6dg.js +2 -0
  99. package/dist/{chunk-bvctccab.js → chunk-nj5azxxj.js} +3 -3
  100. package/dist/{chunk-42zqmcnc.js → chunk-nr3pepv1.js} +3 -3
  101. package/dist/{chunk-r1tp2gnr.js → chunk-p42kp93g.js} +1 -1
  102. package/dist/{chunk-2zd51tj4.js → chunk-pqgk9mxp.js} +2 -2
  103. package/dist/chunk-pvx57vpw.js +2 -0
  104. package/dist/{chunk-fhpsf4z7.js → chunk-q22hwm64.js} +5 -5
  105. package/dist/chunk-qcz104h3.js +2 -0
  106. package/dist/chunk-qgvez75f.js +2 -0
  107. package/dist/{chunk-y4mp1rra.js → chunk-qv2k0qb1.js} +94 -94
  108. package/dist/{chunk-k2ex94n8.js → chunk-qv99gqee.js} +1 -1
  109. package/dist/chunk-r0j6jkxc.js +2 -0
  110. package/dist/{chunk-ben8bjnk.js → chunk-rv0yth27.js} +4 -4
  111. package/dist/chunk-rzh4xgb4.js +2 -0
  112. package/dist/chunk-rzv9xcyp.js +2 -0
  113. package/dist/{chunk-4tgn1frg.js → chunk-s2py8kg7.js} +2 -2
  114. package/dist/chunk-s922mx0k.js +2 -0
  115. package/dist/{chunk-rd33qkfs.js → chunk-s9m2gfns.js} +7 -7
  116. package/dist/{chunk-xt034729.js → chunk-scq0h2cs.js} +6 -6
  117. package/dist/{chunk-ak93e1zz.js → chunk-stww901w.js} +5 -5
  118. package/dist/chunk-sy4wqxta.js +2 -0
  119. package/dist/chunk-szdm8wfn.js +2 -0
  120. package/dist/chunk-t424gvwc.js +2 -0
  121. package/dist/{chunk-yk456jp4.js → chunk-t6d7m4tf.js} +7 -7
  122. package/dist/{chunk-mdvtermb.js → chunk-t70s45hc.js} +2 -2
  123. package/dist/{chunk-dvpk4c1y.js → chunk-t8cgxk8w.js} +2 -2
  124. package/dist/{chunk-edhxg3rz.js → chunk-tqf8a258.js} +56 -56
  125. package/dist/{chunk-9k8ztdcc.js → chunk-vkpmemb1.js} +2 -2
  126. package/dist/chunk-vtvaa8y9.js +2 -0
  127. package/dist/chunk-vvj09a7b.js +2 -0
  128. package/dist/{chunk-rxm1mjkb.js → chunk-vvm38ysm.js} +1 -1
  129. package/dist/chunk-vwjy6491.js +2 -0
  130. package/dist/{chunk-736ex6r5.js → chunk-vy1weqvj.js} +4 -4
  131. package/dist/chunk-w2nzevn0.js +2 -0
  132. package/dist/chunk-wadp2rmj.js +2 -0
  133. package/dist/{chunk-k9247v28.js → chunk-wb2ej5by.js} +1 -1
  134. package/dist/chunk-wbkcwj27.js +2 -0
  135. package/dist/{chunk-2typf9dh.js → chunk-wp4nqnn7.js} +1 -1
  136. package/dist/chunk-wzp8y0a4.js +2 -0
  137. package/dist/chunk-xc1he6hs.js +2 -0
  138. package/dist/{chunk-m6rzsbas.js → chunk-xcstrdhp.js} +4 -4
  139. package/dist/{chunk-cdcrd33m.js → chunk-ysfeg3cn.js} +2 -2
  140. package/dist/chunk-ytzzth34.js +2 -0
  141. package/dist/{chunk-xgnmgjpv.js → chunk-z6sg0dq3.js} +4 -4
  142. package/dist/{chunk-k9wr8xf5.js → chunk-zfaa5xn5.js} +6 -6
  143. package/dist/chunk-zhxg6b64.js +2 -0
  144. package/dist/{chunk-rha8sv1h.js → chunk-zjar9jdd.js} +2 -2
  145. package/dist/{chunk-89801pjp.js → chunk-zs8yjtaz.js} +5 -5
  146. package/dist/{chunk-q3azy64b.js → chunk-ztbk9yqv.js} +4 -4
  147. package/dist/cli.js +19 -19
  148. package/dist/client/signals-bootstrap-runtime.js +1 -1
  149. package/dist/client/signals-class-runtime.js +5 -5
  150. package/dist/client/signals-dom-ready-runtime.js +1 -0
  151. package/dist/client/signals-expression-runtime.js +118 -0
  152. package/dist/client/signals-for-runtime.js +7 -7
  153. package/dist/client/signals-if-chain-runtime.js +3 -3
  154. package/dist/client/signals-if-runtime.js +7 -7
  155. package/dist/client/signals-model-runtime.js +1 -1
  156. package/dist/client/signals-process-element-runtime.js +12 -8
  157. package/dist/client/signals-show-runtime.js +1 -1
  158. package/dist/client/signals-style-runtime.js +1 -1
  159. package/dist/composables/index.d.ts +2 -0
  160. package/dist/composables/index.js +1 -0
  161. package/dist/composables/use-virtual-list.d.ts +24 -0
  162. package/dist/composables/use-virtual-list.js +76 -0
  163. package/dist/config.js +3 -0
  164. package/dist/craft-entry.js +2 -2
  165. package/dist/craft.js +2 -2
  166. package/dist/document-shell.d.ts +10 -1
  167. package/dist/document-shell.js +1 -1
  168. package/dist/expressions.js +19 -0
  169. package/dist/index.d.ts +1 -1
  170. package/dist/native/compiler/render-screen.d.ts +2 -8
  171. package/dist/native/compiler/render-screen.js +3 -10
  172. package/dist/native/event-names.js +2 -0
  173. package/dist/native/primitives-dir.d.ts +13 -0
  174. package/dist/native/primitives-dir.js +14 -0
  175. package/dist/native/prop-names.js +1 -0
  176. package/dist/process.js +1 -1
  177. package/dist/pwa.js +3 -3
  178. package/dist/ssg.js +8 -8
  179. package/dist/state-management.d.ts +22 -0
  180. package/dist/types/config-types.d.ts +2 -0
  181. package/dist/unresolved-identifiers.js +1 -0
  182. package/dist/utils.js +20 -2
  183. package/package.json +5 -5
  184. package/stx.d.ts +4 -0
  185. package/dist/chunk-00nz3pas.js +0 -2
  186. package/dist/chunk-05jdq9tw.js +0 -177
  187. package/dist/chunk-0cajfv7y.js +0 -2
  188. package/dist/chunk-13v3vgb6.js +0 -2
  189. package/dist/chunk-1p8t2ekg.js +0 -2
  190. package/dist/chunk-1rcntvgx.js +0 -2
  191. package/dist/chunk-1w5gtkd6.js +0 -2
  192. package/dist/chunk-28vtqwxh.js +0 -2
  193. package/dist/chunk-298gj90a.js +0 -2
  194. package/dist/chunk-2gn6smrq.js +0 -2
  195. package/dist/chunk-2wq0h5ye.js +0 -2
  196. package/dist/chunk-3wxb7mfb.js +0 -2
  197. package/dist/chunk-528cn6qm.js +0 -2
  198. package/dist/chunk-5x0g7e9y.js +0 -2
  199. package/dist/chunk-633a53wg.js +0 -2
  200. package/dist/chunk-6b737vch.js +0 -2
  201. package/dist/chunk-72ns4q88.js +0 -2
  202. package/dist/chunk-86cg9qqm.js +0 -2
  203. package/dist/chunk-8czxtjwm.js +0 -2
  204. package/dist/chunk-8h5mqs28.js +0 -2
  205. package/dist/chunk-940wny2b.js +0 -2
  206. package/dist/chunk-9fh4ah7t.js +0 -2
  207. package/dist/chunk-a81rt2t4.js +0 -3
  208. package/dist/chunk-ad9dt9rk.js +0 -2
  209. package/dist/chunk-ak4w2emd.js +0 -2
  210. package/dist/chunk-b8dtz3v8.js +0 -2
  211. package/dist/chunk-cenvzm5q.js +0 -2
  212. package/dist/chunk-d49pst1m.js +0 -2
  213. package/dist/chunk-dj0qy19b.js +0 -2
  214. package/dist/chunk-e2q79dfs.js +0 -2
  215. package/dist/chunk-ebxncrd8.js +0 -2
  216. package/dist/chunk-fht1zs1r.js +0 -2
  217. package/dist/chunk-fjfrgef4.js +0 -2
  218. package/dist/chunk-fmk9hjht.js +0 -2
  219. package/dist/chunk-fxnk5ee8.js +0 -2
  220. package/dist/chunk-j1z7tgdp.js +0 -2
  221. package/dist/chunk-jq1698j4.js +0 -2
  222. package/dist/chunk-k0jkpw0q.js +0 -2
  223. package/dist/chunk-k469ym7a.js +0 -2
  224. package/dist/chunk-m5740sd3.js +0 -2
  225. package/dist/chunk-mdw96yhg.js +0 -2
  226. package/dist/chunk-mebf9vwb.js +0 -2
  227. package/dist/chunk-p2se8s6r.js +0 -2
  228. package/dist/chunk-p7zrz0wb.js +0 -2
  229. package/dist/chunk-pdnyfk2v.js +0 -2
  230. package/dist/chunk-qfhjtz2q.js +0 -2
  231. package/dist/chunk-r5tsewzd.js +0 -2
  232. package/dist/chunk-rnvrtcz6.js +0 -2
  233. package/dist/chunk-s36cpnxa.js +0 -2
  234. package/dist/chunk-tfy1m821.js +0 -2
  235. package/dist/chunk-vc3ppphz.js +0 -2
  236. package/dist/chunk-vttx66q0.js +0 -2
  237. package/dist/chunk-vxs07119.js +0 -2
  238. package/dist/chunk-x1x69g3s.js +0 -2
  239. package/dist/chunk-x8hz5gzb.js +0 -2
  240. package/dist/chunk-xfdtym3s.js +0 -2
  241. package/dist/chunk-y6mqq78g.js +0 -2
  242. package/dist/chunk-ycttwgpg.js +0 -2
  243. package/dist/chunk-yd6x9226.js +0 -2
  244. package/dist/chunk-yn3kff5k.js +0 -2
  245. package/dist/chunk-ynjm2tm0.js +0 -2
  246. package/dist/chunk-zpjdp0he.js +0 -2
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import"./chunk-b51p56k5.js";import"./chunk-4833k99b.js";import{b,x,C,Y}from"./chunk-y4mp1rra.js";import"./chunk-tpfxvw4q.js";import"./chunk-x5seqmrv.js";import"./chunk-dvpk4c1y.js";import f from"path";var h=["applyOfflineUpdate","broadcast","cacheMedia","calculateDistance","canNotify","clearCookies","clearFetchCache","clearOfflineData","clearStorage","copyToClipboard","createShareableFile","defineForm","getBatteryLevel","getCookie","getCurrentPosition","getStorageKeys","getStorageSize","getVoices","hasBattery","hasCameraPermission","hasGeolocationPermission","hasMicrophonePermission","hasNotificationPermission","hasResizeObserver","hexToHsl","hexToRgb","isBroadcastChannelSupported","isCharging","isDeviceMotionSupported","isDeviceOrientationSupported","isEventSourceSupported","isEyeDropperSupported","isInFullscreen","isMutationObserverSupported","isPermissionGranted","isSpeechRecognitionSupported","isSpeechSynthesisSupported","isWakeLockSupported","isWebSocketSupported","notify","onOfflineUpdateReady","parseCookies","pickColor","prefetch","removeCookie","requestMediaPermissions","requestMotionPermission","requestNotificationPermission","requestOrientationPermission","setCookie","share","shareCurrentPage","shareFiles","shareText","shareURL","shareWithFallback","speak","stopSpeaking","toggleFullscreen","useAmbientSound","useAnimationFrame","useAsyncData","useAttributeObserver","useAutoLogout","useAutoWakeLock","useBattery","useBreakpoint","useBreathPacer","useBroadcastChannel","useChannel","useChildListObserver","useClipboard","useColorHistory","useCompletion","useConditionalWakeLock","useCookies","useCopySelection","useDeviceMotion","useDeviceOrientation","useElementSize","useElementTextSelection","useElementVisibility","useEventSource","useEyeDropper","useFavicon","useForm","useFullscreen","useGeolocation","useGeolocationWatch","useHotkey","useIdle","useIdleState","useInfiniteScroll","useIntersectionObserver","useIntersectionObserverMultiple","useIsDesktop","useIsMobile","useIsTablet","useKeyPressed","useKeySequence","useKeyboard","useLastActive","useLazyLoad","useMeta","useMouse","useMouseInElement","useMutationObserver","useNetwork","useNotification","useOnline","useOutbox","useParallax","usePermission","usePermissions","usePointer","usePost","useResizeObserver","useResizeObserverMultiple","useSSE","useScroll","useSelectionPopup","useShare","useSpeechRecognition","useSpeechSynthesis","useStorage","useTextObserver","useTextSelection","useTitle","useVisibility","useWakeLock","useWindowSize"],L=new Set(h);var l=new Map,S=b(64),w=new Set,k=0,R=new Set(h);function T(){l.clear(),S.clear()}function P(n){let o=new Map;for(let r of n){let a=f.basename(r);if(a.endsWith(".d.ts"))continue;let t=a.replace(/\.[jt]s$/,"");if(t==="index")continue;if(t===a)continue;let i=o.get(t);if(i&&!i.endsWith(".js"))continue;o.set(t,r)}return[...o.values()].sort()}function I(n,o){let r=o.replace(/[$()*+.?[\\\]^{|}-]/g,"\\$&");return new RegExp(`(?:^|[^\\w$.])(?:const|let|var|function|class)\\s+${r}\\b`).test(n)}function M(n){if(!n)return[];let o=x(n,k),r=S.get(o);if(r)return r.slice();let a=n.replace(/<script\b[^>]*\bdata-stx-runtime\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<script\b[^>]*\bdata-stx-framework-composables\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<script\b[^>]*\bdata-stx-stores\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<script\b[^>]*\bdata-stx-composables\b[^>]*>[\s\S]*?<\/script>/gi,""),t=[];for(let i of R){if(w.has(i))continue;let u=i.replace(/[$()*+.?[\\\]^{|}-]/g,"\\$&");if(new RegExp(`(^|[^\\w$.])${u}\\s*\\(`).test(a))t.push(i)}return t.sort(),S.set(o,t),t.slice()}async function A(n,o){let r=M(n);if(r.length===0)return null;let a=o??f.join(import.meta.dir,"composables"),t=`${a}\x00${r.join(",")}`,i=l.get(t);if(i!==void 0)return i||null;let u=Y({loader:"ts",target:"browser",define:C()}),O=new Set(r),m=[],d=new Set,p=[];try{let s=new Bun.Glob("*.{ts,js}");for await(let e of s.scan({cwd:a,absolute:!0}))p.push(e)}catch{return l.set(t,""),null}p=P(p);for(let s of p){let e;try{e=await Bun.file(s).text()}catch{continue}let g=[];try{g=u.scan(e).exports.filter((c)=>c!=="default")}catch{continue}if(!g.some((c)=>O.has(c)))continue;try{e=e.replace(/^import\s+.*from\s+['"][^'"]+['"]\s*;?\s*$/gm,""),e=e.replace(/^import\s+type\s+.*$/gm,""),e=e.replace(/^export\s+\*\s+(?:as\s+\w+\s+)?from\s*['"][^'"]+['"]\s*;?\s*$/gm,""),e=e.replace(/^export\s+(?:type\s+)?\{[\s\S]*?\}\s*(?:from\s*['"][^'"]+['"]\s*)?;?\s*$/gm,""),e=e.replace(/^export\s+default\s+/gm,""),e=e.replace(/^export\s+(?=(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(?:function|class|const|let|var|type|interface|enum)\b)/gm,""),m.push(`// ${f.basename(s).replace(/\.[jt]s$/,"")}
2
+ import"./chunk-07c8rk93.js";import"./chunk-4833k99b.js";import{b,x,C,Y}from"./chunk-qv2k0qb1.js";import"./chunk-1w4a0xya.js";import"./chunk-1g5fg1ys.js";import"./chunk-t8cgxk8w.js";import f from"path";var h=["applyOfflineUpdate","broadcast","cacheMedia","calculateDistance","canNotify","clearCookies","clearFetchCache","clearOfflineData","clearStorage","copyToClipboard","createShareableFile","defineForm","getBatteryLevel","getCookie","getCurrentPosition","getStorageKeys","getStorageSize","getVoices","hasBattery","hasCameraPermission","hasGeolocationPermission","hasMicrophonePermission","hasNotificationPermission","hasResizeObserver","hexToHsl","hexToRgb","isBroadcastChannelSupported","isCharging","isDeviceMotionSupported","isDeviceOrientationSupported","isEventSourceSupported","isEyeDropperSupported","isInFullscreen","isMutationObserverSupported","isPermissionGranted","isSpeechRecognitionSupported","isSpeechSynthesisSupported","isWakeLockSupported","isWebSocketSupported","notify","onOfflineUpdateReady","parseCookies","pickColor","prefetch","removeCookie","requestMediaPermissions","requestMotionPermission","requestNotificationPermission","requestOrientationPermission","setCookie","share","shareCurrentPage","shareFiles","shareText","shareURL","shareWithFallback","speak","stopSpeaking","toggleFullscreen","useAmbientSound","useAnimationFrame","useAsyncData","useAttributeObserver","useAutoLogout","useAutoWakeLock","useBattery","useBreakpoint","useBreathPacer","useBroadcastChannel","useChannel","useChildListObserver","useClipboard","useColorHistory","useCompletion","useConditionalWakeLock","useCookies","useCopySelection","useDeviceMotion","useDeviceOrientation","useElementSize","useElementTextSelection","useElementVisibility","useEventSource","useEyeDropper","useFavicon","useForm","useFullscreen","useGeolocation","useGeolocationWatch","useHotkey","useIdle","useIdleState","useInfiniteScroll","useIntersectionObserver","useIntersectionObserverMultiple","useIsDesktop","useIsMobile","useIsTablet","useKeyPressed","useKeySequence","useKeyboard","useLastActive","useLazyLoad","useMeta","useMouse","useMouseInElement","useMutationObserver","useNetwork","useNotification","useOnline","useOutbox","useParallax","usePermission","usePermissions","usePointer","usePost","useResizeObserver","useResizeObserverMultiple","useSSE","useScroll","useSelectionPopup","useShare","useSpeechRecognition","useSpeechSynthesis","useStorage","useTextObserver","useTextSelection","useTitle","useVirtualList","useVisibility","useWakeLock","useWindowSize"],L=new Set(h);var l=new Map,S=b(64),w=new Set,k=0,R=new Set(h);function T(){l.clear(),S.clear()}function P(n){let o=new Map;for(let r of n){let a=f.basename(r);if(a.endsWith(".d.ts"))continue;let t=a.replace(/\.[jt]s$/,"");if(t==="index")continue;if(t===a)continue;let i=o.get(t);if(i&&!i.endsWith(".js"))continue;o.set(t,r)}return[...o.values()].sort()}function I(n,o){let r=o.replace(/[$()*+.?[\\\]^{|}-]/g,"\\$&");return new RegExp(`(?:^|[^\\w$.])(?:const|let|var|function|class)\\s+${r}\\b`).test(n)}function M(n){if(!n)return[];let o=x(n,k),r=S.get(o);if(r)return r.slice();let a=n.replace(/<script\b[^>]*\bdata-stx-runtime\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<script\b[^>]*\bdata-stx-framework-composables\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<script\b[^>]*\bdata-stx-stores\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<script\b[^>]*\bdata-stx-composables\b[^>]*>[\s\S]*?<\/script>/gi,""),t=[];for(let i of R){if(w.has(i))continue;let u=i.replace(/[$()*+.?[\\\]^{|}-]/g,"\\$&");if(new RegExp(`(^|[^\\w$.])${u}\\s*\\(`).test(a))t.push(i)}return t.sort(),S.set(o,t),t.slice()}async function A(n,o){let r=M(n);if(r.length===0)return null;let a=o??f.join(import.meta.dir,"composables"),t=`${a}\x00${r.join(",")}`,i=l.get(t);if(i!==void 0)return i||null;let u=Y({loader:"ts",target:"browser",define:C()}),O=new Set(r),m=[],d=new Set,p=[];try{let s=new Bun.Glob("*.{ts,js}");for await(let e of s.scan({cwd:a,absolute:!0}))p.push(e)}catch{return l.set(t,""),null}p=P(p);for(let s of p){let e;try{e=await Bun.file(s).text()}catch{continue}let g=[];try{g=u.scan(e).exports.filter((c)=>c!=="default")}catch{continue}if(!g.some((c)=>O.has(c)))continue;try{e=e.replace(/^import\s+.*from\s+['"][^'"]+['"]\s*;?\s*$/gm,""),e=e.replace(/^import\s+type\s+.*$/gm,""),e=e.replace(/^export\s+\*\s+(?:as\s+\w+\s+)?from\s*['"][^'"]+['"]\s*;?\s*$/gm,""),e=e.replace(/^export\s+(?:type\s+)?\{[\s\S]*?\}\s*(?:from\s*['"][^'"]+['"]\s*)?;?\s*$/gm,""),e=e.replace(/^export\s+default\s+/gm,""),e=e.replace(/^export\s+(?=(?:declare\s+)?(?:abstract\s+)?(?:async\s+)?(?:function|class|const|let|var|type|interface|enum)\b)/gm,""),m.push(`// ${f.basename(s).replace(/\.[jt]s$/,"")}
3
3
  ${u.transformSync(e).trim()}`);for(let c of g)d.add(c)}catch(c){console.warn(`[stx] framework composable ${f.basename(s)} could not be bundled:`,c)}}let y=r.filter((s)=>!d.has(s)&&!I(n,s));if(y.length>0)console.warn(`[stx] could not bundle ${y.join(", ")} from @stacksjs/stx/composables \u2014 `+"calls to them will throw ReferenceError in the browser. Import them explicitly so the bundler inlines them, or use a runtime equivalent from window.stx.");if(m.length===0)return l.set(t,""),null;let E=[...d].map((s)=>` try { if (!(${JSON.stringify(s)} in __s)) { __s[${JSON.stringify(s)}] = ${s}; if (!(${JSON.stringify(s)} in window)) window[${JSON.stringify(s)}] = ${s}; } } catch (e) {}`).join(`
4
4
  `),v=`<script data-stx-scoped data-stx-run="always" data-stx-framework-composables>
5
5
  ;(function(){
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{Xg}from"./chunk-mmcqgwk7.js";import"./chunk-q22hwm64.js";import"./chunk-mpaepc7n.js";import"./chunk-vvm38ysm.js";import"./chunk-c5mbhfff.js";import"./chunk-7aw9qm74.js";import"./chunk-s9m2gfns.js";import"./chunk-h8yk9qm7.js";import"./chunk-kwy0spcd.js";import"./chunk-49w4cbqb.js";import"./chunk-z6sg0dq3.js";import"./chunk-6ch8t3d9.js";import"./chunk-vkpmemb1.js";import"./chunk-t6d7m4tf.js";import"./chunk-dxk5r71v.js";import"./chunk-qv99gqee.js";import"./chunk-b8hsvzqb.js";import"./chunk-tqf8a258.js";import"./chunk-knzp4c6m.js";import"./chunk-c1b481my.js";import"./chunk-ztbk9yqv.js";import"./chunk-ay02q27h.js";import"./chunk-8hanmv49.js";import"./chunk-qv2k0qb1.js";import"./chunk-t8cgxk8w.js";import"./chunk-1g5fg1ys.js";import"./chunk-1w4a0xya.js";import"./chunk-4833k99b.js";import"./chunk-07c8rk93.js";export{Xg as buildForProduction};
@@ -1,7 +1,7 @@
1
1
  // @bun
2
- import{existsSync as x,realpathSync as S,statSync as y}from"fs";import d from"path";import k from"process";var E=/^[\w-]+(?:\/[\w-]+)*$/,j=/^[\w-]+$/;async function Mr(t,e){let a=d.resolve(t,e.dir);if(!e.languages?.length)throw Error("messages.languages must name at least one language");let n=new Map,r=new Map;for(let s of e.languages){if(!j.test(s))throw Error(`messages: "${s}" is not a language directory name`);let g=d.join(a,s);if(!x(g))throw Error(`messages: ${d.relative(t,g)} does not exist`);let o=new Map;for(let i of[...new Bun.Glob("**/*.{ts,js,mjs,json}").scanSync({cwd:g})].sort()){if(/\.(?:test|spec|d)\.[^.]+$/.test(i))continue;let c=i.replace(/\.[^./]+$/,"").split(d.sep).join("/");if(!E.test(c))throw Error(`messages: ${s}/${i} is not an area name`);if(o.has(c))throw Error(`messages: ${s}/${c} is defined twice`);let l=d.join(g,i),m=await import(l),M=Object.keys(m).filter((p)=>p!=="default");if(M.length)throw Error(`messages: ${s}/${i} exports ${M.join(", ")}; a message module exports its messages as default, and nothing else`);let f=m.default,u=f!==null&&typeof f==="object"&&!Array.isArray(f)?JSON.stringify(f):void 0;if(u===void 0||!Bun.deepEquals(JSON.parse(u),f,!0))throw Error(`messages: ${s}/${i} must export plain data (an object JSON can hold) as default`);o.set(c,u),n.set(l,{language:s,area:c})}r.set(s,o)}return{files:n,data:r}}function b(t,e){return`stx-messages:${t}:${e}`}function _(t,e){let a=JSON.stringify(b(t,e));return`var kept = globalThis.__stxMessages || (globalThis.__stxMessages = {});
3
- export default kept[${a}] || (kept[${a}] = {});`}var w=new Map;function Ig(t,e=k.env){if(!t.messages||e.STX_PAGE_MESSAGES==="0")return!1;return e.STX_PAGE_MESSAGES==="1"||e.NODE_ENV==="production"}async function Og(t,e){let a=d.resolve(t,e.dir),n=e.languages.map((l)=>{try{return`${l}:${y(d.join(a,l)).mtimeMs}`}catch{return`${l}:-`}}).join("|"),r=`${a}\x00${e.languages.join(",")}\x00${e.fallback??""}`,s=w.get(r);if(s&&s.signature===n)return s.messages;let g=await Mr(t,e),o=new Map;for(let[l,{language:m,area:M}]of g.files){let f=_(m,M),u=[l];try{u.push(S(l))}catch{}for(let p of[...u])if(p.startsWith("/private/"))u.push(p.slice(8));for(let p of u)o.set(p,f)}let i=e.fallback??e.languages[0];if(!e.languages.includes(i))throw Error(`messages.fallback "${i}" is not one of messages.languages`);let c={...g,stubs:o,languages:[...e.languages],fallback:i};return w.set(r,{signature:n,messages:c}),c}function Ng(...t){let e=new Set;for(let a of t){if(!a||!a.includes("stx-messages:"))continue;for(let n of a.matchAll(/stx-messages:[\w-]+:([\w/-]+)/g))e.add(n[1])}return e}function Dg(t,e){let a=/<html\b[^>]*>/i.exec(t)?.[0]??"",n=/\slang\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(a),r=(n?n[1]??n[2]??n[3]??"":"").trim().toLowerCase(),s=new Map(e.languages.map((o)=>[o.toLowerCase(),o])),g=s.get(r)??s.get(r.split(/[-_]/)[0]??"");if(!g)return[...e.languages];return[...new Set([g,e.fallback])]}var h=new WeakMap;function Mg(t,e,a){let n=[...a].sort(),r=h.get(t);if(!r)h.set(t,r=new Map);let s=`${e.join(",")}\x00${n.join(",")}`;if(r.has(s))return r.get(s);let g=P(t,e,n);return r.set(s,g),g}function P(t,e,a){let n=[];for(let r of e){let s=t.data.get(r);if(!s)continue;for(let g of a){let o=s.get(g);if(o!==void 0)n.push(`put(${JSON.stringify(b(r,g))},${JSON.stringify(o)})`)}}if(n.length===0)return null;return`;(function(){var kept=globalThis.__stxMessages||(globalThis.__stxMessages={}),filled=globalThis.__stxMessagesFilled||(globalThis.__stxMessagesFilled={});function put(key,json){if(filled[key])return;filled[key]=1;var into=kept[key]||(kept[key]={}),data=JSON.parse(json);for(var name in data)into[name]=data[name]}
2
+ import{existsSync as x,realpathSync as S,statSync as y}from"fs";import d from"path";import k from"process";var E=/^[\w-]+(?:\/[\w-]+)*$/,j=/^[\w-]+$/;async function Lr(t,e){let a=d.resolve(t,e.dir);if(!e.languages?.length)throw Error("messages.languages must name at least one language");let n=new Map,r=new Map;for(let s of e.languages){if(!j.test(s))throw Error(`messages: "${s}" is not a language directory name`);let g=d.join(a,s);if(!x(g))throw Error(`messages: ${d.relative(t,g)} does not exist`);let o=new Map;for(let i of[...new Bun.Glob("**/*.{ts,js,mjs,json}").scanSync({cwd:g})].sort()){if(/\.(?:test|spec|d)\.[^.]+$/.test(i))continue;let c=i.replace(/\.[^./]+$/,"").split(d.sep).join("/");if(!E.test(c))throw Error(`messages: ${s}/${i} is not an area name`);if(o.has(c))throw Error(`messages: ${s}/${c} is defined twice`);let l=d.join(g,i),m=await import(l),M=Object.keys(m).filter((p)=>p!=="default");if(M.length)throw Error(`messages: ${s}/${i} exports ${M.join(", ")}; a message module exports its messages as default, and nothing else`);let f=m.default,u=f!==null&&typeof f==="object"&&!Array.isArray(f)?JSON.stringify(f):void 0;if(u===void 0||!Bun.deepEquals(JSON.parse(u),f,!0))throw Error(`messages: ${s}/${i} must export plain data (an object JSON can hold) as default`);o.set(c,u),n.set(l,{language:s,area:c})}r.set(s,o)}return{files:n,data:r}}function b(t,e){return`stx-messages:${t}:${e}`}function _(t,e){let a=JSON.stringify(b(t,e));return`var kept = globalThis.__stxMessages || (globalThis.__stxMessages = {});
3
+ export default kept[${a}] || (kept[${a}] = {});`}var w=new Map;function Og(t,e=k.env){if(!t.messages||e.STX_PAGE_MESSAGES==="0")return!1;return e.STX_PAGE_MESSAGES==="1"||e.NODE_ENV==="production"}async function Ng(t,e){let a=d.resolve(t,e.dir),n=e.languages.map((l)=>{try{return`${l}:${y(d.join(a,l)).mtimeMs}`}catch{return`${l}:-`}}).join("|"),r=`${a}\x00${e.languages.join(",")}\x00${e.fallback??""}`,s=w.get(r);if(s&&s.signature===n)return s.messages;let g=await Lr(t,e),o=new Map;for(let[l,{language:m,area:M}]of g.files){let f=_(m,M),u=[l];try{u.push(S(l))}catch{}for(let p of[...u])if(p.startsWith("/private/"))u.push(p.slice(8));for(let p of u)o.set(p,f)}let i=e.fallback??e.languages[0];if(!e.languages.includes(i))throw Error(`messages.fallback "${i}" is not one of messages.languages`);let c={...g,stubs:o,languages:[...e.languages],fallback:i};return w.set(r,{signature:n,messages:c}),c}function Dg(...t){let e=new Set;for(let a of t){if(!a||!a.includes("stx-messages:"))continue;for(let n of a.matchAll(/stx-messages:[\w-]+:([\w/-]+)/g))e.add(n[1])}return e}function Mg(t,e){let a=/<html\b[^>]*>/i.exec(t)?.[0]??"",n=/\slang\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(a),r=(n?n[1]??n[2]??n[3]??"":"").trim().toLowerCase(),s=new Map(e.languages.map((o)=>[o.toLowerCase(),o])),g=s.get(r)??s.get(r.split(/[-_]/)[0]??"");if(!g)return[...e.languages];return[...new Set([g,e.fallback])]}var h=new WeakMap;function Lg(t,e,a){let n=[...a].sort(),r=h.get(t);if(!r)h.set(t,r=new Map);let s=`${e.join(",")}\x00${n.join(",")}`;if(r.has(s))return r.get(s);let g=P(t,e,n);return r.set(s,g),g}function P(t,e,a){let n=[];for(let r of e){let s=t.data.get(r);if(!s)continue;for(let g of a){let o=s.get(g);if(o!==void 0)n.push(`put(${JSON.stringify(b(r,g))},${JSON.stringify(o)})`)}}if(n.length===0)return null;return`;(function(){var kept=globalThis.__stxMessages||(globalThis.__stxMessages={}),filled=globalThis.__stxMessagesFilled||(globalThis.__stxMessagesFilled={});function put(key,json){if(filled[key])return;filled[key]=1;var into=kept[key]||(kept[key]={}),data=JSON.parse(json);for(var name in data)into[name]=data[name]}
4
4
  ${n.join(`;
5
5
  `)};
6
6
  })();`}
7
- export{Mr,Ig,Og,Ng,Dg,Mg};
7
+ export{Lr,Og,Ng,Dg,Mg,Lg};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{ct,lt,ut}from"./chunk-g4k0svq6.js";import"./chunk-b51p56k5.js";import"./chunk-4833k99b.js";import{m}from"./chunk-y4mp1rra.js";import"./chunk-tpfxvw4q.js";import"./chunk-x5seqmrv.js";import"./chunk-dvpk4c1y.js";import{Ht,Ys,Vt,Bi,at,Fi,Zs,Ut,Hi,Wt}from"./chunk-0kq0k4pg.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){at(`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 nt=".stx/story/analytics.json",st=1,A=1e4;class k{storage;storagePath;currentSession=null;dirty=!1;viewStartTimes=new Map;constructor(t){this.storagePath=j.join(t,nt),this.storage=this.loadStorage(),this.startSession()}loadStorage(){try{let t=w.readFileSync(this.storagePath,"utf-8");return JSON.parse(t)}catch{return{version:st,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:it(),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),g=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:g}}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 it(){return`session-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import S from"fs";import B from"path";var dt=".stx/story/bookmarks.json",pt=1;class P{storage;storagePath;dirty=!1;constructor(t){this.storagePath=B.join(t,dt),this.storage=this.loadStorage()}loadStorage(){try{let t=S.readFileSync(this.storagePath,"utf-8");return JSON.parse(t)}catch{return{version:pt,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:mt(),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 mt(){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{ct,lt,ut}from"./chunk-g4k0svq6.js";import"./chunk-07c8rk93.js";import"./chunk-4833k99b.js";import{m}from"./chunk-qv2k0qb1.js";import"./chunk-1w4a0xya.js";import"./chunk-1g5fg1ys.js";import"./chunk-t8cgxk8w.js";import{Ht,Zs,Vt,Fi,at,zi,Qs,Ut,Vi,Wt}from"./chunk-n5dd6rpt.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()=>{zi("Config file changed, restarting...");try{await e.onChange()}catch(p){at(`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 nt=".stx/story/analytics.json",st=1,A=1e4;class k{storage;storagePath;currentSession=null;dirty=!1;viewStartTimes=new Map;constructor(t){this.storagePath=j.join(t,nt),this.storage=this.loadStorage(),this.startSession()}loadStorage(){try{let t=w.readFileSync(this.storagePath,"utf-8");return JSON.parse(t)}catch{return{version:st,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:it(),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),g=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:g}}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 it(){return`session-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}import S from"fs";import B from"path";var dt=".stx/story/bookmarks.json",pt=1;class P{storage;storagePath;dirty=!1;constructor(t){this.storagePath=B.join(t,dt),this.storage=this.loadStorage()}loadStorage(){try{let t=S.readFileSync(this.storagePath,"utf-8");return JSON.parse(t)}catch{return{version:pt,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:mt(),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 mt(){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,9 +556,9 @@ 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-pdnyfk2v.js"),p={},g=h(n);if(g)try{await m(g,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),u=h(n);return i=Q(i),i=tt(i,p),{html:i,css:l,js:u,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 m(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-pdnyfk2v.js"),c={...r},n=h(e);if(n)try{await m(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-b8ar6431.js"),p={},g=h(n);if(g)try{await m(g,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),u=h(n);return i=Q(i),i=tt(i,p),{html:i,css:l,js:u,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 m(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-b8ar6431.js"),c={...r},n=h(e);if(n)try{await m(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
- `)}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 Ut(t);lt(t,r);let s=Wt(t.config,r);ut(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)}}}),g=`http://${o}:${e.port}`,y=Hi(t,async(i,l)=>{console.log(` [${i}] ${l.relativePath}`);let u=await Ut(t);lt(t,u);let f=Wt(t.config,u);if(ut(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=g;try{let{exec:l}=await import("child_process"),u=process.platform;l(`${u==="darwin"?"open":u==="win32"?"start":"xdg-open"} ${i}`)}catch{}}return{server:p,url:g,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],g=d[1]||"default",y,i=n.searchParams.get("props");if(i)try{y=JSON.parse(i)}catch{}let l=t.storyFiles.find((u)=>u.id===p);if(!l)return new Response("Story not found",{status:404});try{let u=await Y(t,l,g,y);return Response.json({html:u.html,css:u.css,js:u.js,errors:u.errors,duration:u.duration})}catch(u){return Response.json({html:"",css:"",js:"",errors:[u instanceof Error?u.message:String(u)],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((g)=>g.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>
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 Ut(t);lt(t,r);let s=Wt(t.config,r);ut(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)}}}),g=`http://${o}:${e.port}`,y=Vi(t,async(i,l)=>{console.log(` [${i}] ${l.relativePath}`);let u=await Ut(t);lt(t,u);let f=Wt(t.config,u);if(ut(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=g;try{let{exec:l}=await import("child_process"),u=process.platform;l(`${u==="darwin"?"open":u==="win32"?"start":"xdg-open"} ${i}`)}catch{}}return{server:p,url:g,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],g=d[1]||"default",y,i=n.searchParams.get("props");if(i)try{y=JSON.parse(i)}catch{}let l=t.storyFiles.find((u)=>u.id===p);if(!l)return new Response("Story not found",{status:404});try{let u=await Y(t,l,g,y);return Response.json({html:u.html,css:u.css,js:u.js,errors:u.errors,duration:u.duration})}catch(u){return Response.json({html:"",css:"",js:"",errors:[u instanceof Error?u.message:String(u)],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((g)=>g.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"}">
563
563
  <head>
564
564
  <meta charset="UTF-8">
@@ -1276,5 +1276,5 @@ else {
1276
1276
  <style>${W()}</style>
1277
1277
  ${D()}
1278
1278
  </body>
1279
- </html>`}import St from"fs";import Pt from"path";var Ct=new Map,Tt=[],Rt=[],It=new Map;async function ot(t){let e=t.config.setupFile;if(!e)return;let r=Pt.resolve(t.root,e);try{await St.promises.access(r)}catch{return}let s={storyContext:t,registerComponent:(o,a)=>{Ct.set(o,a)},addCSS:(o)=>{Tt.push(o)},addScript:(o)=>{Rt.push(o)},setState:(o,a)=>{It.set(o,a)}};try{let o=await import(r);if(typeof o.default==="function")await o.default(s);else if(typeof o.setupStory==="function")await o.setupStory(s)}catch(o){console.warn(`Warning: Failed to load setup file: ${o}`)}}async function we(t={}){Ht();let e=await ct({mode:"dev"});if(!e.config.enabled){at("Story feature is disabled in config.");return}await ot(e);let r=t.port??e.config.port,s,o=async()=>{s=await rt(e,{port:r,open:t.open,host:t.host}),Vt(e.storyFiles.length),Ys(s.url),Zs()};await o();let a=E(e,{onChange:async()=>{await s.close();let n=await ct({mode:"dev"});Object.assign(e,n),await o()}}),c=async()=>{console.log(`
1280
- `),a.stop(),await s.close(),process.exit(0)};if(process.on("SIGINT",c),process.on("SIGTERM",c),process.stdin.isTTY)process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.on("data",async(n)=>{switch(n.toString()){case"h":Zs();break;case"o":try{let{exec:p}=await import("child_process"),g=process.platform==="darwin"?"open":process.platform==="win32"?"start":"xdg-open";p(`${g} ${s.url}`)}catch{Bi("Failed to open browser")}break;case"r":await s.close(),await o();break;case"c":console.clear(),Ht(),Vt(e.storyFiles.length),Ys(s.url);break;case"q":case"\x03":await c();break}});await new Promise(()=>{})}export{we as devCommand};
1279
+ </html>`}import St from"fs";import Pt from"path";var Ct=new Map,Tt=[],Rt=[],It=new Map;async function ot(t){let e=t.config.setupFile;if(!e)return;let r=Pt.resolve(t.root,e);try{await St.promises.access(r)}catch{return}let s={storyContext:t,registerComponent:(o,a)=>{Ct.set(o,a)},addCSS:(o)=>{Tt.push(o)},addScript:(o)=>{Rt.push(o)},setState:(o,a)=>{It.set(o,a)}};try{let o=await import(r);if(typeof o.default==="function")await o.default(s);else if(typeof o.setupStory==="function")await o.setupStory(s)}catch(o){console.warn(`Warning: Failed to load setup file: ${o}`)}}async function we(t={}){Ht();let e=await ct({mode:"dev"});if(!e.config.enabled){at("Story feature is disabled in config.");return}await ot(e);let r=t.port??e.config.port,s,o=async()=>{s=await rt(e,{port:r,open:t.open,host:t.host}),Vt(e.storyFiles.length),Zs(s.url),Qs()};await o();let a=E(e,{onChange:async()=>{await s.close();let n=await ct({mode:"dev"});Object.assign(e,n),await o()}}),c=async()=>{console.log(`
1280
+ `),a.stop(),await s.close(),process.exit(0)};if(process.on("SIGINT",c),process.on("SIGTERM",c),process.stdin.isTTY)process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.on("data",async(n)=>{switch(n.toString()){case"h":Qs();break;case"o":try{let{exec:p}=await import("child_process"),g=process.platform==="darwin"?"open":process.platform==="win32"?"start":"xdg-open";p(`${g} ${s.url}`)}catch{Fi("Failed to open browser")}break;case"r":await s.close(),await o();break;case"c":console.clear(),Ht(),Vt(e.storyFiles.length),Zs(s.url);break;case"q":case"\x03":await c();break}});await new Promise(()=>{})}export{we as devCommand};