@stacksjs/stx 0.2.861 → 0.2.863

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 (291) hide show
  1. package/dist/analytics.js +3 -2
  2. package/dist/animation.js +3 -3
  3. package/dist/app-shell.js +4 -3
  4. package/dist/{chunk-14cvwsy1.js → chunk-01c16zw4.js} +2 -2
  5. package/dist/chunk-021tjkd6.js +3 -0
  6. package/dist/chunk-0bfgsv31.js +2 -0
  7. package/dist/chunk-0twkeh31.js +2 -0
  8. package/dist/chunk-0xtda6aw.js +2 -0
  9. package/dist/chunk-15m7jnc0.js +33 -0
  10. package/dist/{chunk-7bajrfb1.js → chunk-1grdbpsk.js} +8 -8
  11. package/dist/{chunk-9syvkm5z.js → chunk-1mqcttg3.js} +6 -6
  12. package/dist/chunk-2asyyky3.js +2 -0
  13. package/dist/{chunk-eye156nv.js → chunk-2c18y094.js} +1 -1
  14. package/dist/chunk-2n932qtv.js +20 -0
  15. package/dist/{chunk-76360zky.js → chunk-32ty2zx6.js} +9 -9
  16. package/dist/chunk-36j129p1.js +2 -0
  17. package/dist/chunk-3gk1e2b1.js +2 -0
  18. package/dist/chunk-3ryp43f3.js +2 -0
  19. package/dist/{chunk-12r22pf0.js → chunk-3z1mmar2.js} +2 -2
  20. package/dist/{chunk-zhxdpzga.js → chunk-46ddesnf.js} +3 -3
  21. package/dist/chunk-46pxmpeb.js +3 -0
  22. package/dist/chunk-4pr29yrx.js +2 -0
  23. package/dist/{chunk-tjz3r7rj.js → chunk-55zq2ha8.js} +5 -5
  24. package/dist/{chunk-avp271q4.js → chunk-58sh82aj.js} +2 -2
  25. package/dist/{chunk-gggadrs4.js → chunk-5a0d3048.js} +3 -3
  26. package/dist/{chunk-121cgm3s.js → chunk-5p1k2h5q.js} +8 -8
  27. package/dist/chunk-5s1fb8z4.js +4 -0
  28. package/dist/{chunk-x69457q9.js → chunk-5zzrrxns.js} +8 -8
  29. package/dist/chunk-64ebysb4.js +2 -0
  30. package/dist/{chunk-4rrxrxp6.js → chunk-669b2bya.js} +4 -4
  31. package/dist/{chunk-38qp2pg2.js → chunk-67dgp45w.js} +2 -2
  32. package/dist/{chunk-5xdkmn39.js → chunk-6ftee542.js} +2 -2
  33. package/dist/{chunk-5wr1qqz3.js → chunk-6k4ac74t.js} +2 -2
  34. package/dist/{chunk-c2w4wc9f.js → chunk-6m6y9bbx.js} +1 -1
  35. package/dist/chunk-6pczzq5f.js +2 -0
  36. package/dist/{chunk-6tp0w6hf.js → chunk-7ayvybdy.js} +3 -3
  37. package/dist/chunk-7mjf144y.js +2 -0
  38. package/dist/chunk-7wqevtks.js +2 -0
  39. package/dist/{chunk-bag9q4m0.js → chunk-8502xb4n.js} +39 -39
  40. package/dist/chunk-85zmxbt0.js +33 -0
  41. package/dist/{chunk-cxpq2zna.js → chunk-8arfg8kp.js} +3 -3
  42. package/dist/{chunk-xmy6g81m.js → chunk-8hhhmscy.js} +2 -2
  43. package/dist/{chunk-fyfvqd2s.js → chunk-8me8hamk.js} +2 -2
  44. package/dist/{chunk-pb09xy77.js → chunk-8s6s6nd0.js} +2 -2
  45. package/dist/chunk-8v1zpdef.js +2 -0
  46. package/dist/chunk-94mpe1ny.js +3 -0
  47. package/dist/{chunk-mzes9ds7.js → chunk-9zrvh3pz.js} +2 -2
  48. package/dist/chunk-a4cn8rf4.js +2 -0
  49. package/dist/{chunk-fpkp0bqf.js → chunk-adqh1gp1.js} +1 -1
  50. package/dist/chunk-ap84eenm.js +2 -0
  51. package/dist/chunk-as2ffje6.js +2 -0
  52. package/dist/chunk-az5xw3w8.js +2 -0
  53. package/dist/chunk-b6w0f610.js +712 -0
  54. package/dist/chunk-ba91r7q9.js +2 -0
  55. package/dist/{chunk-qkcn0exq.js → chunk-brzjass3.js} +6 -6
  56. package/dist/chunk-bwdbj60y.js +3 -0
  57. package/dist/{chunk-3wg9kr5z.js → chunk-bx5d87xx.js} +6 -7
  58. package/dist/chunk-c0t2tdfk.js +2 -0
  59. package/dist/chunk-caxqwrnc.js +2 -0
  60. package/dist/{chunk-37tefp7s.js → chunk-cqhwzd9y.js} +5 -5
  61. package/dist/chunk-cvgbtmxp.js +2 -0
  62. package/dist/chunk-czca8yds.js +42 -0
  63. package/dist/chunk-d0afg5f7.js +2 -0
  64. package/dist/chunk-d9vzfbdp.js +2 -0
  65. package/dist/{chunk-65cbfx5x.js → chunk-dpmayc2w.js} +2 -2
  66. package/dist/{chunk-d6216bcw.js → chunk-dtarm8x9.js} +9 -9
  67. package/dist/chunk-e634vffz.js +3 -0
  68. package/dist/chunk-eafqxbr0.js +2 -0
  69. package/dist/{chunk-qjm23ma2.js → chunk-ew5cey88.js} +1 -1
  70. package/dist/{chunk-xppm4cs4.js → chunk-farh4p7f.js} +3 -3
  71. package/dist/chunk-fnv94wc6.js +2 -0
  72. package/dist/chunk-g4gcf4jn.js +2 -0
  73. package/dist/chunk-g65dptx2.js +2 -0
  74. package/dist/{chunk-q6w7a1vc.js → chunk-gbtbfg7e.js} +3 -3
  75. package/dist/{chunk-15jymk6t.js → chunk-gd56arnm.js} +2 -2
  76. package/dist/{chunk-5ka3h8dy.js → chunk-gjngg182.js} +45 -46
  77. package/dist/{chunk-8hck9qqm.js → chunk-gp8hgpt9.js} +4 -4
  78. package/dist/chunk-gw7t6a3t.js +2 -0
  79. package/dist/chunk-h2qgqjkn.js +2 -0
  80. package/dist/chunk-h65shwe9.js +2 -0
  81. package/dist/{chunk-zpkgs5d3.js → chunk-h816ta81.js} +6 -6
  82. package/dist/chunk-hc6111md.js +54 -0
  83. package/dist/{chunk-cq2hedwn.js → chunk-hev4t4d5.js} +6 -6
  84. package/dist/{chunk-7yhhwv07.js → chunk-hmdkf6c6.js} +2 -2
  85. package/dist/{chunk-vggtxttf.js → chunk-j1efsjsb.js} +5 -5
  86. package/dist/chunk-j4zrq17p.js +2 -0
  87. package/dist/chunk-jfmj0wsy.js +2 -0
  88. package/dist/{chunk-bg0ywp5w.js → chunk-jgra00m8.js} +2 -2
  89. package/dist/{chunk-5rxks14t.js → chunk-k32q90b2.js} +2 -2
  90. package/dist/{chunk-naj146zq.js → chunk-k7dxm48r.js} +2 -2
  91. package/dist/chunk-ks5p5w6z.js +25 -0
  92. package/dist/chunk-kw11yydy.js +2 -0
  93. package/dist/chunk-m9cperj4.js +2 -0
  94. package/dist/{chunk-zs4s9fcq.js → chunk-mcnwvh06.js} +6 -6
  95. package/dist/chunk-meqsd5bt.js +2 -0
  96. package/dist/{chunk-dba4bwkd.js → chunk-mfa07erx.js} +16 -16
  97. package/dist/{chunk-jh2v1vvb.js → chunk-mrh08821.js} +3 -3
  98. package/dist/{chunk-9n8t7v78.js → chunk-n3jw3xpj.js} +2 -2
  99. package/dist/chunk-ns04v3am.js +2 -0
  100. package/dist/chunk-ntbe5q5x.js +16 -0
  101. package/dist/chunk-nttsc0aw.js +14 -0
  102. package/dist/chunk-p0tkhd12.js +2 -0
  103. package/dist/chunk-p2etn78y.js +2 -0
  104. package/dist/{chunk-1nankvf6.js → chunk-pbakxcv8.js} +2 -2
  105. package/dist/{chunk-h4aqpf2r.js → chunk-prrvggcy.js} +5 -5
  106. package/dist/chunk-pyckafsb.js +12 -0
  107. package/dist/{chunk-t5q31st4.js → chunk-q1wxgw5s.js} +2 -2
  108. package/dist/chunk-qa5y30sy.js +72 -0
  109. package/dist/{chunk-m3p4hksq.js → chunk-qbghf76y.js} +4 -4
  110. package/dist/{chunk-a6d92kv6.js → chunk-qcxrcypb.js} +2 -2
  111. package/dist/{chunk-1jwcp2k0.js → chunk-qjey0jk6.js} +2 -2
  112. package/dist/chunk-qmkaqjba.js +2 -0
  113. package/dist/chunk-qxw9h564.js +2 -0
  114. package/dist/chunk-r23zq8yk.js +2 -0
  115. package/dist/{chunk-68w65mhs.js → chunk-r4v4vswq.js} +3 -3
  116. package/dist/chunk-reeaknf2.js +2 -0
  117. package/dist/chunk-rqa92xm4.js +2 -0
  118. package/dist/chunk-rqmb09ss.js +2 -0
  119. package/dist/chunk-s92j8k4z.js +2 -0
  120. package/dist/chunk-s9df8srx.js +6 -0
  121. package/dist/{chunk-dt73ww6m.js → chunk-sb8n32rn.js} +1 -1
  122. package/dist/{chunk-5neezkj1.js → chunk-sj3ry5ck.js} +33 -25
  123. package/dist/chunk-snz2cxqv.js +2 -0
  124. package/dist/{chunk-36vksrry.js → chunk-srgnevws.js} +2 -2
  125. package/dist/chunk-sz6d3v6b.js +2 -0
  126. package/dist/{chunk-9pyvc0dc.js → chunk-tnp2ta5q.js} +2 -2
  127. package/dist/{chunk-gx96hctv.js → chunk-v37zmez0.js} +2 -2
  128. package/dist/chunk-v408qsze.js +2 -0
  129. package/dist/{chunk-thdnk1kd.js → chunk-v4xes880.js} +3 -3
  130. package/dist/chunk-va07zs9v.js +2 -0
  131. package/dist/chunk-vc42mvjn.js +2 -0
  132. package/dist/chunk-vk98r75z.js +2 -0
  133. package/dist/{chunk-yj9nyt93.js → chunk-vvzys1x7.js} +3 -3
  134. package/dist/chunk-vwwpbhd2.js +3 -0
  135. package/dist/{chunk-hyea17hp.js → chunk-w468n41y.js} +155 -157
  136. package/dist/{chunk-f1vvhbmw.js → chunk-w6pzkcjp.js} +2 -2
  137. package/dist/{chunk-15rkvc0t.js → chunk-wk4wg6sn.js} +5 -5
  138. package/dist/chunk-wtfamngc.js +20 -0
  139. package/dist/chunk-x3p4emdp.js +2 -0
  140. package/dist/{chunk-3gfd9t8a.js → chunk-x512h2gv.js} +4 -4
  141. package/dist/{chunk-nwxjh1gv.js → chunk-x7redxyd.js} +4 -4
  142. package/dist/chunk-xcjvx6zt.js +2 -0
  143. package/dist/chunk-xfd3yqgj.js +1327 -0
  144. package/dist/chunk-xjxcwrqs.js +2 -0
  145. package/dist/chunk-xymr4ys9.js +3 -0
  146. package/dist/chunk-xzdkjkyp.js +2 -0
  147. package/dist/{chunk-b1tctqn5.js → chunk-y036cwc7.js} +10 -10
  148. package/dist/chunk-y190sh29.js +16 -0
  149. package/dist/{chunk-wrbhq1y2.js → chunk-yakdcak2.js} +3 -3
  150. package/dist/chunk-ybkwnscv.js +2 -0
  151. package/dist/{chunk-6nb49h13.js → chunk-yhc1c4tr.js} +125 -126
  152. package/dist/chunk-ymdw4fhd.js +3 -0
  153. package/dist/chunk-ynkbv9jq.js +4 -0
  154. package/dist/chunk-yr1zx78b.js +3 -0
  155. package/dist/{chunk-e8nzbz66.js → chunk-ysfeg3cn.js} +2 -2
  156. package/dist/chunk-ytzzth34.js +2 -0
  157. package/dist/chunk-yxpjj003.js +2 -0
  158. package/dist/chunk-z1rs6b4x.js +2 -0
  159. package/dist/chunk-z383x16t.js +2 -0
  160. package/dist/chunk-z3gz5fy4.js +2 -0
  161. package/dist/{chunk-tm201m9x.js → chunk-z512gt4v.js} +3 -3
  162. package/dist/{chunk-5n7m8vqx.js → chunk-zbvfjm4a.js} +2 -2
  163. package/dist/chunk-zr22gtpf.js +2 -0
  164. package/dist/chunk-zsnmk5me.js +2 -0
  165. package/dist/chunk-ztbexx3h.js +2 -0
  166. package/dist/cli.js +35 -35
  167. package/dist/client/signals-timer-runtime.js +12 -4
  168. package/dist/craft-entry.js +2 -2
  169. package/dist/craft.js +2 -2
  170. package/dist/dev-server/serve-app.js +3 -2
  171. package/dist/dev-server/serve-multi.js +3 -4
  172. package/dist/dev-server/ts-css.js +4 -5
  173. package/dist/document-shell.js +4 -3
  174. package/dist/document-tags.d.ts +8 -0
  175. package/dist/document-tags.js +37 -0
  176. package/dist/events.js +2 -1
  177. package/dist/head-injection.js +2 -1
  178. package/dist/heatmap.js +2 -1
  179. package/dist/hot-reload.js +3 -1
  180. package/dist/index.d.ts +1 -1
  181. package/dist/index.js +1 -1
  182. package/dist/native-build.js +3 -3
  183. package/dist/process.js +5 -6
  184. package/dist/production-build.js +3 -3
  185. package/dist/pwa/inject.js +3 -3
  186. package/dist/pwa.js +3 -3
  187. package/dist/reactive-bindings.js +2 -1
  188. package/dist/reactive.js +2 -1
  189. package/dist/render.js +1 -1
  190. package/dist/runtime-injection.js +6 -6
  191. package/dist/serve.js +1 -1
  192. package/dist/site-builder/build.js +1 -1
  193. package/dist/site-builder/i18n.js +2 -2
  194. package/dist/site-builder/router.js +1 -1
  195. package/dist/site-builder/theme.js +1 -1
  196. package/dist/ssg.js +30 -31
  197. package/dist/template-hydrator.js +2 -1
  198. package/dist/web-components/css-scoping.js +3 -3
  199. package/dist/x-element.js +2 -1
  200. package/package.json +5 -5
  201. package/dist/body-close.d.ts +0 -13
  202. package/dist/body-close.js +0 -8
  203. package/dist/chunk-02css3vk.js +0 -14
  204. package/dist/chunk-0hqr6bff.js +0 -2
  205. package/dist/chunk-15sgdvyd.js +0 -2
  206. package/dist/chunk-261t62q4.js +0 -712
  207. package/dist/chunk-2b4a8tbd.js +0 -3
  208. package/dist/chunk-2fw36w1x.js +0 -2
  209. package/dist/chunk-2jcxsw75.js +0 -2
  210. package/dist/chunk-2pbhdaka.js +0 -2
  211. package/dist/chunk-2wba5ypm.js +0 -2
  212. package/dist/chunk-353gnvfe.js +0 -2
  213. package/dist/chunk-3cr5y8v1.js +0 -2
  214. package/dist/chunk-3y7yp0ka.js +0 -2
  215. package/dist/chunk-41wwqw0q.js +0 -2
  216. package/dist/chunk-4a1y51fs.js +0 -2
  217. package/dist/chunk-4a751brg.js +0 -2
  218. package/dist/chunk-4jgcd4d9.js +0 -33
  219. package/dist/chunk-5awhm4na.js +0 -2
  220. package/dist/chunk-5fhp9hxd.js +0 -2
  221. package/dist/chunk-5mg443dw.js +0 -2
  222. package/dist/chunk-5q4tncfw.js +0 -18
  223. package/dist/chunk-5x9ajbq0.js +0 -2
  224. package/dist/chunk-6g7tkmty.js +0 -2
  225. package/dist/chunk-72bj7ea4.js +0 -2
  226. package/dist/chunk-74g64pzt.js +0 -20
  227. package/dist/chunk-7de5y29a.js +0 -54
  228. package/dist/chunk-7ycmnsh5.js +0 -2
  229. package/dist/chunk-811hh6vp.js +0 -2
  230. package/dist/chunk-830ej8d2.js +0 -72
  231. package/dist/chunk-8fkmxrat.js +0 -2
  232. package/dist/chunk-8p9npc8y.js +0 -2
  233. package/dist/chunk-9fz3h6sx.js +0 -2
  234. package/dist/chunk-9jr30fns.js +0 -2
  235. package/dist/chunk-9xr628ew.js +0 -3
  236. package/dist/chunk-a9m6ajd7.js +0 -2
  237. package/dist/chunk-aj6vqdf7.js +0 -25
  238. package/dist/chunk-asr5v51s.js +0 -2
  239. package/dist/chunk-b7nmgkwa.js +0 -42
  240. package/dist/chunk-bv14vry8.js +0 -3
  241. package/dist/chunk-byx82s10.js +0 -2
  242. package/dist/chunk-c9y1g61m.js +0 -2
  243. package/dist/chunk-ck5nzbbv.js +0 -2
  244. package/dist/chunk-cvdm0hgq.js +0 -2
  245. package/dist/chunk-e0fxgbcc.js +0 -2
  246. package/dist/chunk-ed2m6pjf.js +0 -2
  247. package/dist/chunk-ednwdhv0.js +0 -2
  248. package/dist/chunk-egtphftq.js +0 -2
  249. package/dist/chunk-f18rxz70.js +0 -2
  250. package/dist/chunk-fahqq7c4.js +0 -2
  251. package/dist/chunk-fcbpzdyz.js +0 -2
  252. package/dist/chunk-gc79s0wh.js +0 -20
  253. package/dist/chunk-gjnrmz2q.js +0 -4
  254. package/dist/chunk-gp1dt8b8.js +0 -33
  255. package/dist/chunk-h0dsxxz4.js +0 -2
  256. package/dist/chunk-h2cvfp9y.js +0 -2
  257. package/dist/chunk-jhm1228j.js +0 -4
  258. package/dist/chunk-k3yym9zg.js +0 -2
  259. package/dist/chunk-k9fsd6t3.js +0 -2
  260. package/dist/chunk-kepxsjfx.js +0 -2
  261. package/dist/chunk-kgrvvtcy.js +0 -3
  262. package/dist/chunk-kh01rvag.js +0 -2
  263. package/dist/chunk-kv40xq53.js +0 -1329
  264. package/dist/chunk-mad172af.js +0 -2
  265. package/dist/chunk-mjkdskeg.js +0 -12
  266. package/dist/chunk-npt0mdzb.js +0 -2
  267. package/dist/chunk-p95fsnbk.js +0 -2
  268. package/dist/chunk-ptc3yqn3.js +0 -2
  269. package/dist/chunk-pybm7c9p.js +0 -2
  270. package/dist/chunk-q87hkwfg.js +0 -3
  271. package/dist/chunk-qe6631me.js +0 -2
  272. package/dist/chunk-qnx71b17.js +0 -2
  273. package/dist/chunk-qx8cav4w.js +0 -2
  274. package/dist/chunk-rb7cwck6.js +0 -2
  275. package/dist/chunk-s1e0t3hv.js +0 -2
  276. package/dist/chunk-s7vfmasx.js +0 -2
  277. package/dist/chunk-scwbttvt.js +0 -3
  278. package/dist/chunk-shy2hkvj.js +0 -2
  279. package/dist/chunk-sxtvy0sm.js +0 -3
  280. package/dist/chunk-t7z67vf6.js +0 -2
  281. package/dist/chunk-tarvase5.js +0 -2
  282. package/dist/chunk-tqs9pcga.js +0 -2
  283. package/dist/chunk-twjfrywv.js +0 -2
  284. package/dist/chunk-v0wdgxga.js +0 -3
  285. package/dist/chunk-vyna2rsq.js +0 -2
  286. package/dist/chunk-w4gjx2zs.js +0 -18
  287. package/dist/chunk-xhe7pw6e.js +0 -2
  288. package/dist/chunk-y86mpnrg.js +0 -2
  289. package/dist/chunk-z99bf0q0.js +0 -3
  290. package/dist/chunk-zm0g7ntw.js +0 -2
  291. package/dist/chunk-zrm2x65c.js +0 -2
package/dist/craft.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // @bun
2
- import"./chunk-261t62q4.js";import{Eo,Ta,$a}from"./chunk-gggadrs4.js";import"./chunk-bag9q4m0.js";import"./chunk-830ej8d2.js";import"./chunk-1jwcp2k0.js";import"./chunk-xppm4cs4.js";import"./chunk-5rxks14t.js";import"./chunk-naj146zq.js";import"./chunk-9pyvc0dc.js";import"./chunk-3gfd9t8a.js";import"./chunk-6nb49h13.js";import"./chunk-dba4bwkd.js";import"./chunk-4rrxrxp6.js";import"./chunk-z99bf0q0.js";import"./chunk-5q4tncfw.js";import"./chunk-kv40xq53.js";import"./chunk-b7nmgkwa.js";import"./chunk-7de5y29a.js";import"./chunk-b1tctqn5.js";import"./chunk-aj6vqdf7.js";import"./chunk-t5q31st4.js";import"./chunk-yj9nyt93.js";import{_u,Ra,Ih,Oh,Aa,To,ns,Pa,Ia,Nh,Mh,Oa,Na,Ma,Da}from"./chunk-5ka3h8dy.js";import"./chunk-w4gjx2zs.js";import"./chunk-2b4a8tbd.js";import"./chunk-v0wdgxga.js";import"./chunk-02css3vk.js";import"./chunk-h2cvfp9y.js";import"./chunk-68w65mhs.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
2
+ import"./chunk-b6w0f610.js";import{Ro,Pa,Ia}from"./chunk-5a0d3048.js";import"./chunk-8502xb4n.js";import"./chunk-qa5y30sy.js";import"./chunk-qjey0jk6.js";import"./chunk-farh4p7f.js";import"./chunk-k32q90b2.js";import"./chunk-k7dxm48r.js";import"./chunk-tnp2ta5q.js";import"./chunk-x512h2gv.js";import"./chunk-yhc1c4tr.js";import"./chunk-mfa07erx.js";import"./chunk-669b2bya.js";import"./chunk-021tjkd6.js";import"./chunk-y190sh29.js";import"./chunk-xfd3yqgj.js";import"./chunk-czca8yds.js";import"./chunk-hc6111md.js";import"./chunk-y036cwc7.js";import"./chunk-ks5p5w6z.js";import"./chunk-q1wxgw5s.js";import"./chunk-vvzys1x7.js";import{Tu,Oa,Mh,Dh,Na,Ao,os,Ma,Da,Lh,jh,La,ja,Ba,Fa}from"./chunk-gjngg182.js";import"./chunk-ntbe5q5x.js";import"./chunk-e634vffz.js";import"./chunk-xymr4ys9.js";import"./chunk-nttsc0aw.js";import"./chunk-zsnmk5me.js";import"./chunk-r4v4vswq.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
3
3
  `),scripts:t.scripts.join(`
4
4
  `),metadata:{renderTime:0,cacheHit:!0,totalSize:c.html.length,componentCount:t.metadata.componentCount}}}let a;if(n.streaming)a=await H(t.tree,e);else a=h(t.tree,e);let i;if(n.hydrate){let o=j(a,t,e);a=o.html,i=o.data}if(n.minify)a=D(a);if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`;d.set(o,{html:a,timestamp:Date.now()})}let s=performance.now()-r;return{html:a,styles:t.styles.join(`
5
5
  `),scripts:t.scripts.join(`
6
6
  `),hydrationData:i,metadata:{renderTime:s,cacheHit:!1,totalSize:a.length,componentCount:t.metadata.componentCount}}}function V(t,e){let n=[],r=[],a=[],i=new Map,s=[];return y(t.tree,(o,c)=>{if(o.type==="component"&&o.componentName){if(T(o.componentName))n.push(o.componentName)}if(o.type==="element"&&o.tag){let p=J(o);if(p)s.push(p);if(o.props){for(let[l,f]of Object.entries(o.props))if(l.startsWith("on")&&typeof f==="string"){let g=`handler_${i.size}`;i.set(g,f)}}}if(o.isStatic&&o.type==="element")r.push(b(o));else if(!o.isStatic&&o.type!=="text")a.push(o.tag||o.componentName||"unknown")}),{nativeComponents:n,staticHTML:r,dynamicParts:a,eventHandlers:i,nativeWidgets:s}}function Y(t,e={}){let n=R(t),r=P(n,e),a=new Map,i=[];return y(n.tree,(s)=>{if(s.type==="component"&&s.componentName){if(T(s.componentName)){i.push(s.componentName);let o=`<!--craft:${s.componentName}:${s.hydrationKey||"default"}-->`;a.set(s.hydrationKey||s.componentName,o)}}}),{staticHTML:r,dynamicPlaceholders:a,craftComponents:i}}function M(t){let e={type:"fragment",children:[]},n=e,r=[e],a=t,i=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);while(a.length>0){let s=a.match(/^<(@?[\w-]+)([^>]*)>/);if(s){let[p,l,f]=s,g=z(f),u=l.startsWith("@craft-"),C=u?l:l.toLowerCase(),S={type:u?"component":"element",tag:C,props:g,children:[],componentName:u?C.slice(1):void 0,isStatic:!v(f),hydrationKey:F()};if(n.children=n.children||[],n.children.push(S),!i.has(C)&&!f.endsWith("/"))r.push(S),n=S;a=a.slice(p.length);continue}let o=a.match(/^<\/(@?[\w-]+)>/);if(o){let[p,l]=o,g=l.startsWith("@craft-")?l:l.toLowerCase();while(r.length>1){let u=r.pop();if(n=r[r.length-1],u.tag===g)break}a=a.slice(p.length);continue}let c=a.match(/^[^<]+/);if(c){let p=c[0];if(p.trim()){let l={type:"text",text:p,isStatic:!v(p)};n.children=n.children||[],n.children.push(l)}a=a.slice(p.length);continue}a=a.slice(1)}return e}function z(t){let e={},n=/([\w-:@]+)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,r;while((r=n.exec(t))!==null){let[,a,i,s,o]=r,c=i??s??o??!0;e[a]=c}return e}function y(t,e,n=[]){if(e(t,n),t.children)t.children.forEach((r,a)=>{y(r,e,[...n,`${a}`])})}function h(t,e){switch(t.type){case"text":return x(t.text||"",e);case"element":case"component":{let n=t.tag||"div",r=N(t.props||{},e),a=(t.children||[]).map((i)=>h(i,e)).join("");if(!t.children||t.children.length===0){if(["input","br","hr","img","meta","link"].includes(n))return`<${n}${r} />`}return`<${n}${r}>${a}</${n}>`}case"fragment":return(t.children||[]).map((n)=>h(n,e)).join("");case"slot":return`<!--slot:${t.slotName||"default"}-->`;default:return""}}function b(t){if(t.type==="text")return t.text||"";let e=t.tag||"div",n=N(t.props||{},{});return`<${e}${n}></${e}>`}function N(t,e){let n=[];for(let[r,a]of Object.entries(t))if(a===!0)n.push(` ${r}`);else if(a!==!1&&a!==null&&a!==void 0){let i=x(String(a),e);n.push(` ${r}="${k(i)}"`)}return n.join("")}async function H(t,e){return h(t,e)}function P(t,e){let n=[];return y(t.tree,(r)=>{if(r.isStatic)n.push(h(r,e))}),n.join("")}function j(t,e,n){let r={templateId:e.id,context:n,dynamicParts:Array.from(e.dynamicParts.entries())},a=`
7
7
  <script data-craft-hydration>
8
8
  window.__CRAFT_HYDRATION__ = ${JSON.stringify(r)};
9
- </script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{_u as CRAFT_BRIDGE_SCRIPT,To as CRAFT_COMPONENTS,Pa as CRAFT_COMPONENT_RUNTIME,ns as CRAFT_COMPONENT_STYLES,Eo as NATIVE_COMPONENTS,Oa as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Ta as compileToNative,$a as createHotReloadServer,Na as findCraftBinary,Ra as generateCraftBridgeScript,V as generateCraftOptimizations,Da as getAvailableFormats,Ma as getAvailableTargets,Mh as getCraftComponents,G as getSSRCacheStats,Aa as injectCraftBridge,Ih as isCraftEnvironment,Y as prerenderForCraft,Ia as processCraftComponents,Oh as processCraftDirective,Nh as registerCraftComponent,Q as renderSSR};
9
+ </script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{Tu as CRAFT_BRIDGE_SCRIPT,Ao as CRAFT_COMPONENTS,Ma as CRAFT_COMPONENT_RUNTIME,os as CRAFT_COMPONENT_STYLES,Ro as NATIVE_COMPONENTS,La as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Pa as compileToNative,Ia as createHotReloadServer,ja as findCraftBinary,Oa as generateCraftBridgeScript,V as generateCraftOptimizations,Fa as getAvailableFormats,Ba as getAvailableTargets,jh as getCraftComponents,G as getSSRCacheStats,Na as injectCraftBridge,Mh as isCraftEnvironment,Y as prerenderForCraft,Da as processCraftComponents,Dh as processCraftDirective,Lh as registerCraftComponent,Q as renderSSR};
@@ -1,3 +1,4 @@
1
+ import { insertBeforeHeadClose } from "../document-tags.js";
1
2
  import { serve } from "bun";
2
3
  import fs from "node:fs";
3
4
  import path from "node:path";
@@ -361,7 +362,7 @@ export async function serveApp(appDir = ".", options = {}) {
361
362
  const injectRouteParams = (content, params) => {
362
363
  const paramsScript = `<script data-stx-route-params>(function(){var p=${JSON.stringify(params).replace(/</g, "\\u003C").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029")};window.__stx_rp=p;if(window.stx){window.stx._rp=p;if(window.stx.setRouteParams)window.stx.setRouteParams(p)}})()</script>`;
363
364
  if (content.includes("</head>"))
364
- return content.replace("</head>", `${paramsScript}</head>`);
365
+ return insertBeforeHeadClose(content, paramsScript, "");
365
366
  if (content.includes("<body"))
366
367
  return content.replace(/<body([^>]*)>/, `<body$1>${paramsScript}`);
367
368
  return paramsScript + content;
@@ -478,7 +479,7 @@ export async function serveApp(appDir = ".", options = {}) {
478
479
  }
479
480
  if (Object.keys(middlewareResult.state).length > 0) {
480
481
  const stateScript = `<script>(function(){var s=typeof stx!=='undefined'?stx:{};s._ms=${JSON.stringify(middlewareResult.state)};if(s.setMiddlewareState)s.setMiddlewareState(s._ms);})()</script>`;
481
- builtPage.content = builtPage.content.replace("</head>", `${stateScript}</head>`);
482
+ builtPage.content = insertBeforeHeadClose(builtPage.content, stateScript, "");
482
483
  }
483
484
  }
484
485
  let content = builtPage.content;
@@ -1,3 +1,4 @@
1
+ import { insertBeforeHeadClose } from "../document-tags.js";
1
2
  import { serve } from "bun";
2
3
  import fs from "node:fs";
3
4
  import path from "node:path";
@@ -411,8 +412,7 @@ export async function serveMultipleStxFiles(filePaths, options = {}) {
411
412
  let content = templateRoute.content;
412
413
  const paramScript = `<script>window.__routeParams = ${JSON.stringify(params)};</script>`;
413
414
  if (content.includes("</head>"))
414
- content = content.replace("</head>", `${paramScript}
415
- </head>`);
415
+ content = insertBeforeHeadClose(content, paramScript);
416
416
  else
417
417
  content = paramScript + content;
418
418
  routeMatched = { ...templateRoute, content };
@@ -423,8 +423,7 @@ export async function serveMultipleStxFiles(filePaths, options = {}) {
423
423
  if (routeMatched)
424
424
  return injectCss(routeMatched.content).then((content) => {
425
425
  if (content.includes("</head>"))
426
- content = content.replace("</head>", `${stxClientHelpers}
427
- </head>`);
426
+ content = insertBeforeHeadClose(content, stxClientHelpers);
428
427
  return new Response(content, {
429
428
  headers: {
430
429
  "Content-Type": "text/html",
@@ -1,3 +1,4 @@
1
+ import { headCloseIndex, insertBeforeHeadClose } from "../document-tags.js";
1
2
  import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import { hasLocalConfig } from "bunfig";
@@ -436,8 +437,7 @@ ${css}
436
437
  });
437
438
  }
438
439
  if (htmlContent.includes("</head>"))
439
- return htmlContent.replace("</head>", `${assetTag}
440
- </head>`);
440
+ return insertBeforeHeadClose(htmlContent, assetTag);
441
441
  if (htmlContent.includes("<body"))
442
442
  return htmlContent.replace(/<body([^>]*)>/, `<body$1>
443
443
  ${assetTag}`);
@@ -458,7 +458,7 @@ function injectCssAndDedupeScopedStyles(html, assetTag) {
458
458
  existingMatch = existing.exec(html);
459
459
  }
460
460
  } else {
461
- const headClose = html.indexOf("</head>");
461
+ const headClose = headCloseIndex(html);
462
462
  if (headClose !== -1)
463
463
  edits.push({ start: headClose, end: headClose, replacement: `${assetTag}
464
464
  ` });
@@ -501,8 +501,7 @@ function injectCssIntoHtml(htmlContent, assetTag) {
501
501
  });
502
502
  }
503
503
  if (htmlContent.includes("</head>"))
504
- return htmlContent.replace("</head>", `${assetTag}
505
- </head>`);
504
+ return insertBeforeHeadClose(htmlContent, assetTag);
506
505
  if (htmlContent.includes("<body"))
507
506
  return htmlContent.replace(/<body([^>]*)>/, `<body$1>
508
507
  ${assetTag}`);
@@ -1,3 +1,4 @@
1
+ import { headCloseIndex } from "./document-tags.js";
1
2
  import { generateColorModeBootScript } from "./color-mode-boot.js";
2
3
  export const COMPONENT_WRAPPER_RULE = "[data-stx-component-wrapper]:not([stx-hydrate]){display:contents}", CLOAK_STYLE = `<style data-stx-cloak>[x-cloak]{display:none !important}${COMPONENT_WRAPPER_RULE}</style>`, HTML_ATTRS_MARKER = "data-stx-html-attrs", HTML_CLASS_MARKER = "data-stx-html-class";
3
4
  const SAFE_ATTR_NAME = /^[A-Za-z_:][\w:.-]*$/;
@@ -137,13 +138,13 @@ export function injectCloakStyle(html) {
137
138
  const fragment = cloakStyleFragment(html);
138
139
  if (fragment === null)
139
140
  return html;
140
- const headCloseIdx = html.lastIndexOf("</head>");
141
+ const headCloseIdx = headCloseIndex(html);
141
142
  return `${html.slice(0, headCloseIdx)}${fragment}${html.slice(headCloseIdx)}`;
142
143
  }
143
144
  export function cloakStyleFragment(html) {
144
145
  if (html.includes("data-stx-cloak"))
145
146
  return null;
146
- if (html.lastIndexOf("</head>") === -1)
147
+ if (headCloseIndex(html) === -1)
147
148
  return null;
148
149
  return `${CLOAK_STYLE}
149
150
  `;
@@ -318,7 +319,7 @@ export function hasDocumentShell(html) {
318
319
  return startsDocument(html);
319
320
  }
320
321
  export function injectConfigHeadTags(html, headConfig = {}) {
321
- const headCloseIdx = html.lastIndexOf("</head>");
322
+ const headCloseIdx = headCloseIndex(html);
322
323
  if (headCloseIdx === -1)
323
324
  return html;
324
325
  const { meta = [], link = [], script = [], headRaw = "" } = headConfig, head = html.slice(0, headCloseIdx), parts = [];
@@ -0,0 +1,8 @@
1
+ /** The index of the document's `</head>`, or -1. */
2
+ export declare function headCloseIndex(html: string): number;
3
+ /** The index of the document's `</body>`, or -1. */
4
+ export declare function bodyCloseIndex(html: string): number;
5
+ /** Put markup just before the document's `</head>`. Unchanged when there is none. */
6
+ export declare function insertBeforeHeadClose(html: string, markup: string, separator?: string): string;
7
+ /** Put markup just before the document's `</body>`, or on the end when there is none. */
8
+ export declare function insertBeforeBodyClose(html: string, markup: string, separator?: string): string;
@@ -0,0 +1,37 @@
1
+ const RAW_TEXT_OR_TAG = /<!--[\s\S]*?-->|<(script|style|textarea|title)\b[^>]*>[\s\S]*?<\/\1\s*>|<\/(head|body)\s*>/gi;
2
+ function closeTagIndex(html, tag, which) {
3
+ if (!html.includes(`</${tag}`) && !html.includes(`</${tag.toUpperCase()}`))
4
+ return -1;
5
+ let found = -1;
6
+ RAW_TEXT_OR_TAG.lastIndex = 0;
7
+ for (let match = RAW_TEXT_OR_TAG.exec(html);match; match = RAW_TEXT_OR_TAG.exec(html)) {
8
+ if (match[2]?.toLowerCase() !== tag)
9
+ continue;
10
+ found = match.index;
11
+ if (which === "first")
12
+ break;
13
+ }
14
+ RAW_TEXT_OR_TAG.lastIndex = 0;
15
+ return found;
16
+ }
17
+ export function headCloseIndex(html) {
18
+ return closeTagIndex(html, "head", "first");
19
+ }
20
+ export function bodyCloseIndex(html) {
21
+ return closeTagIndex(html, "body", "last");
22
+ }
23
+ export function insertBeforeHeadClose(html, markup, separator = `
24
+ `) {
25
+ const at = headCloseIndex(html);
26
+ if (at === -1)
27
+ return html;
28
+ return `${html.slice(0, at)}${markup}${separator}${html.slice(at)}`;
29
+ }
30
+ export function insertBeforeBodyClose(html, markup, separator = `
31
+ `) {
32
+ const at = bodyCloseIndex(html);
33
+ if (at === -1)
34
+ return `${html}
35
+ ${markup}`;
36
+ return `${html.slice(0, at)}${markup}${separator}${html.slice(at)}`;
37
+ }
package/dist/events.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { bodyCloseIndex } from "./document-tags.js";
1
2
  import { templateHasReactiveContext } from "./runtime-globals.js";
2
3
  export const SCROLL_BLOCKING_EVENTS = new Set(["touchstart", "touchmove", "wheel", "mousewheel"]);
3
4
  export function listensPassively(event, modifiers) {
@@ -398,7 +399,7 @@ export function processEventDirectives(template, context, _filePath) {
398
399
  }
399
400
  output = output.slice(0, element.startIndex) + newTag + output.slice(element.endIndex);
400
401
  }
401
- const script = generateRuntimeScript(elements.flatMap((el) => el.events)), bodyIdx = output.lastIndexOf("</body>");
402
+ const script = generateRuntimeScript(elements.flatMap((el) => el.events)), bodyIdx = bodyCloseIndex(output);
402
403
  if (bodyIdx !== -1)
403
404
  output = output.slice(0, bodyIdx) + script + `
404
405
  ` + output.slice(bodyIdx);
@@ -1,3 +1,4 @@
1
+ import { headCloseIndex } from "./document-tags.js";
1
2
  export function createHeadInjections() {
2
3
  return { afterOpen: [], beforeClose: [] };
3
4
  }
@@ -7,7 +8,7 @@ export function hasHeadInjections(injections) {
7
8
  export function applyHeadInjections(html, injections) {
8
9
  if (!hasHeadInjections(injections))
9
10
  return html;
10
- const afterOpen = injections.afterOpen.join(""), beforeClose = injections.beforeClose.join(""), headCloseIdx = html.lastIndexOf("</head>"), openAt = afterOpen ? headInsertionPoint(html) : null, closeAt = beforeClose && headCloseIdx !== -1 ? headCloseIdx : null;
11
+ const afterOpen = injections.afterOpen.join(""), beforeClose = injections.beforeClose.join(""), headCloseIdx = headCloseIndex(html), openAt = afterOpen ? headInsertionPoint(html) : null, closeAt = beforeClose && headCloseIdx !== -1 ? headCloseIdx : null;
11
12
  if (openAt === null && closeAt === null)
12
13
  return html;
13
14
  if (openAt !== null && closeAt !== null)
package/dist/heatmap.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { bodyCloseIndex } from "./document-tags.js";
1
2
  export const defaultHeatmapConfig = {
2
3
  enabled: !1,
3
4
  trackMouse: !0,
@@ -426,7 +427,7 @@ export function injectHeatmap(html, options) {
426
427
  const heatmapScript = generateHeatmapScript(options);
427
428
  if (!heatmapScript)
428
429
  return html;
429
- const hmBodyIdx = html.lastIndexOf("</body>");
430
+ const hmBodyIdx = bodyCloseIndex(html);
430
431
  if (hmBodyIdx !== -1)
431
432
  return html.slice(0, hmBodyIdx) + heatmapScript + html.slice(hmBodyIdx);
432
433
  return html + heatmapScript;
@@ -1,3 +1,5 @@
1
+ import { bodyCloseIndex } from "./document-tags.js";
2
+
1
3
  export class HotReloadServer {
2
4
  clients = new Set;
3
5
  server = null;
@@ -333,7 +335,7 @@ else {
333
335
  `;
334
336
  }
335
337
  export function injectHotReload(html, wsPort, options = {}) {
336
- const script = generateHotReloadScript(wsPort, options), bodyIdx = html.lastIndexOf("</body>");
338
+ const script = generateHotReloadScript(wsPort, options), bodyIdx = bodyCloseIndex(html);
337
339
  if (bodyIdx !== -1)
338
340
  return html.slice(0, bodyIdx) + script + html.slice(bodyIdx);
339
341
  if (html.includes("</html>"))
package/dist/index.d.ts CHANGED
@@ -25,7 +25,7 @@ declare const __dtsx_default_export__: {};
25
25
  // ============================================================
26
26
  // Explicit re-exports to resolve wildcard ambiguities
27
27
  export { type BuildResult } from './build-optimizer.js';
28
- export { insertBeforeBodyClose } from './body-close.js';
28
+ export { bodyCloseIndex, headCloseIndex, insertBeforeBodyClose, insertBeforeHeadClose } from './document-tags.js';
29
29
  export { useServerData } from './server-data.js';
30
30
  export { useRuntimeConfig, useServerRuntimeConfig } from './runtime-config-server.js';
31
31
  export { useSearchParams, type SearchParamsRef, type SearchParamsCommitOptions } from './composables/use-router.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { insertBeforeBodyClose } from "./body-close.js";
1
+ export { bodyCloseIndex, headCloseIndex, insertBeforeBodyClose, insertBeforeHeadClose } from "./document-tags.js";
2
2
  export { useServerData } from "./server-data.js";
3
3
  export { useRuntimeConfig, useServerRuntimeConfig } from "./runtime-config-server.js";
4
4
  export { useSearchParams } from "./composables/use-router.js";
@@ -1,4 +1,5 @@
1
- var {require}=import.meta;import { existsSync, mkdirSync, copyFileSync, chmodSync, rmSync } from "node:fs";
1
+ var {require}=import.meta;import { insertBeforeHeadClose } from "./document-tags.js";
2
+ import { existsSync, mkdirSync, copyFileSync, chmodSync, rmSync } from "node:fs";
2
3
  import { join, dirname, basename, resolve } from "node:path";
3
4
  import { spawn } from "node:child_process";
4
5
  import { platform as osPlatform } from "node:os";
@@ -40,8 +41,7 @@ export async function buildNative(config) {
40
41
  html = processCraftComponents(html);
41
42
  if (!html.includes("craft-component-styles")) {
42
43
  if (html.includes("</head>"))
43
- html = html.replace("</head>", `${CRAFT_COMPONENT_STYLES}
44
- </head>`);
44
+ html = insertBeforeHeadClose(html, CRAFT_COMPONENT_STYLES);
45
45
  }
46
46
  const appName = config.name || basename(config.input, ".stx"), appVersion = config.version || "1.0.0";
47
47
  let craftPath = config.craftPath || findCraftBinary(config.runtimeProfile);
package/dist/process.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { bodyCloseIndex, headCloseIndex, insertBeforeHeadClose } from "./document-tags.js";
1
2
  import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import { injectCss } from "./dev-server/ts-css.js";
@@ -965,8 +966,7 @@ async function processOtherDirectives(template, context, filePath, options, depe
965
966
  return html;
966
967
  }
967
968
  if (/<\/head>/i.test(html))
968
- return html.replace(/<\/head>/i, `${snippet}
969
- </head>`);
969
+ return insertBeforeHeadClose(html, snippet);
970
970
  if (/<head\b[^>]*>/i.test(html))
971
971
  return html.replace(/(<head\b[^>]*>)/i, `$1
972
972
  ${snippet}`);
@@ -1000,14 +1000,13 @@ ${snippet}
1000
1000
  ${generateLifecycleRuntime()}
1001
1001
  </script>`;
1002
1002
  if (output.includes("</head>")) {
1003
- const headEndPos = output.indexOf("</head>"), firstScriptPos = output.slice(0, headEndPos).indexOf("<script");
1003
+ const headEndPos = headCloseIndex(output), firstScriptPos = output.slice(0, headEndPos).indexOf("<script");
1004
1004
  if (firstScriptPos !== -1) {
1005
1005
  const before = output.slice(0, firstScriptPos), after = output.slice(firstScriptPos);
1006
1006
  output = before + runtimeScript + `
1007
1007
  ` + after;
1008
1008
  } else
1009
- output = output.replace("</head>", `${runtimeScript}
1010
- </head>`);
1009
+ output = insertBeforeHeadClose(output, runtimeScript);
1011
1010
  } else if (output.includes("<body"))
1012
1011
  output = output.replace(/<body([^>]*)>/, `<body$1>
1013
1012
  ${runtimeScript}`);
@@ -1064,7 +1063,7 @@ ${runtimeScript}`);
1064
1063
  if (orphaned.length > 0) {
1065
1064
  const script = generateRuntimeScript(orphaned);
1066
1065
  if (script) {
1067
- const bodyIdx = output.lastIndexOf("</body>");
1066
+ const bodyIdx = bodyCloseIndex(output);
1068
1067
  output = bodyIdx === -1 ? output + script : output.slice(0, bodyIdx) + script + `
1069
1068
  ` + output.slice(bodyIdx);
1070
1069
  }
@@ -1,3 +1,4 @@
1
+ import { bodyCloseIndex, insertBeforeHeadClose } from "./document-tags.js";
1
2
  import { createHash } from "node:crypto";
2
3
  import { existsSync, mkdirSync, readFileSync, writeFileSync, readdirSync, statSync } from "node:fs";
3
4
  import { basename, dirname, extname, join, relative, resolve } from "node:path";
@@ -193,7 +194,7 @@ ${externalContent}`);
193
194
  hash: scriptHash,
194
195
  sources: [filePath]
195
196
  });
196
- const pbBodyIdx = output.lastIndexOf("</body>");
197
+ const pbBodyIdx = bodyCloseIndex(output);
197
198
  if (pbBodyIdx !== -1)
198
199
  output = output.slice(0, pbBodyIdx) + `<script src="${this.config.publicPath}${scriptFile}"></script>
199
200
  ` + output.slice(pbBodyIdx);
@@ -211,8 +212,7 @@ ${externalContent}`);
211
212
  hash: styleHash,
212
213
  sources: [filePath]
213
214
  });
214
- output = output.replace("</head>", `<link rel="stylesheet" href="${this.config.publicPath}${styleFile}">
215
- </head>`);
215
+ output = insertBeforeHeadClose(output, `<link rel="stylesheet" href="${this.config.publicPath}${styleFile}">`);
216
216
  }
217
217
  return output;
218
218
  }
@@ -1,3 +1,4 @@
1
+ import { bodyCloseIndex, insertBeforeHeadClose } from "../document-tags.js";
1
2
  import { getServiceWorkerFileName } from "./service-worker.js";
2
3
  export function generatePwaTags(options) {
3
4
  const pwa = options.pwa;
@@ -62,7 +63,7 @@ export function injectPwaTags(html, options) {
62
63
  if (html.includes("<!-- stx PWA Meta Tags -->"))
63
64
  return html;
64
65
  if (!html.includes("</head>")) {
65
- const pwaBodyIdx = html.lastIndexOf("</body>");
66
+ const pwaBodyIdx = bodyCloseIndex(html);
66
67
  if (pwaBodyIdx !== -1) {
67
68
  const pwaTags = generatePwaTags(options);
68
69
  return html.slice(0, pwaBodyIdx) + pwaTags + `
@@ -71,8 +72,7 @@ export function injectPwaTags(html, options) {
71
72
  return html + generatePwaTags(options);
72
73
  }
73
74
  const pwaTags = generatePwaTags(options);
74
- return html.replace("</head>", `${pwaTags}
75
- </head>`);
75
+ return insertBeforeHeadClose(html, pwaTags);
76
76
  }
77
77
  export function generateSwRegistrationScript(options) {
78
78
  if (!options.pwa?.enabled)
package/dist/pwa.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // @bun
2
- import{so,Wt,Ol,Fg}from"./chunk-m3p4hksq.js";import{ro,Bi,Lg,jg,Bg}from"./chunk-3wg9kr5z.js";import{Al,Pl,Il,Mg,Dg}from"./chunk-65cbfx5x.js";import{qe,Pn,Fi}from"./chunk-jh2v1vvb.js";import{zg,Hg,Vg,Ug,oo,$y}from"./chunk-36vksrry.js";import B from"fs";import w from"path";import O from"fs";import u from"path";var v=[72,96,128,144,152,192,384,512],S=[120,152,167,180],P=[16,32];async function M(n,t){let e={success:!0,generatedFiles:[],errors:[],warnings:[]},r=n.pwa?.icons;if(!r?.src)return e.errors.push("No source icon specified in pwa.icons.src"),e.success=!1,e;let o=u.isAbsolute(r.src)?r.src:u.resolve(process.cwd(),r.src);if(!await Bun.file(o).exists())return e.errors.push(`Source icon not found: ${o}`),e.success=!1,e;let a=u.resolve(t,r.outputDir||"pwa-icons");try{O.mkdirSync(a,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${a}`),e.success=!1,e}let s=r.sizes||v,l=r.generateWebP??!0,p=r.generateAppleIcons??!0;try{let c;try{c=await import("sharp")}catch{return e.errors.push(`sharp is not installed. Install it with: bun add sharp
3
- Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-0hqr6bff.js"),o=await Bun.file(e).text();return await r(o,{},e,n,new Set)}catch(r){console.warn(`[PWA] Failed to process custom offline page: ${r}`)}else console.warn(`[PWA] Custom offline page not found: ${e}`)}return E(n)}function E(n){let t=n.pwa?.offline,e=n.pwa?.manifest,r=t?.fallbackTitle||"You are offline",o=t?.fallbackMessage||"Please check your internet connection and try again.",a=e?.themeColor||"#4f46e5",s=e?.shortName||e?.name||"App";return`<!DOCTYPE html>
2
+ import{ao,Gt,Dl,Vg}from"./chunk-qbghf76y.js";import{io,Hi,Fg,zg,Hg}from"./chunk-bx5d87xx.js";import{Ol,Nl,Ml,jg,Bg}from"./chunk-dpmayc2w.js";import{Xe,Nn,Vi}from"./chunk-mrh08821.js";import{Ug,Wg,qg,Kg,co,Py}from"./chunk-srgnevws.js";import B from"fs";import w from"path";import O from"fs";import u from"path";var v=[72,96,128,144,152,192,384,512],S=[120,152,167,180],P=[16,32];async function M(n,t){let e={success:!0,generatedFiles:[],errors:[],warnings:[]},r=n.pwa?.icons;if(!r?.src)return e.errors.push("No source icon specified in pwa.icons.src"),e.success=!1,e;let o=u.isAbsolute(r.src)?r.src:u.resolve(process.cwd(),r.src);if(!await Bun.file(o).exists())return e.errors.push(`Source icon not found: ${o}`),e.success=!1,e;let a=u.resolve(t,r.outputDir||"pwa-icons");try{O.mkdirSync(a,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${a}`),e.success=!1,e}let s=r.sizes||v,l=r.generateWebP??!0,p=r.generateAppleIcons??!0;try{let c;try{c=await import("sharp")}catch{return e.errors.push(`sharp is not installed. Install it with: bun add sharp
3
+ Icon generation requires the sharp package for image processing.`),e.success=!1,e}let g=await c.default(o).metadata();if(g.width&&g.width<512)e.warnings.push(`Source icon is ${g.width}x${g.height}. Recommend using at least 512x512 for best quality.`);for(let i of s){let d=u.join(a,`icon-${i}x${i}.png`);if(await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d),l){let x=u.join(a,`icon-${i}x${i}.webp`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).webp({quality:90}).toFile(x),e.generatedFiles.push(x)}}if(p){for(let d of S){let x=u.join(a,`apple-touch-icon-${d}x${d}.png`);await c.default(o).resize(d,d,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(x),e.generatedFiles.push(x)}let i=u.join(a,"apple-touch-icon.png");await c.default(o).resize(180,180,{fit:"contain",background:{r:255,g:255,b:255,alpha:1}}).png().toFile(i),e.generatedFiles.push(i)}for(let i of P){let d=u.join(a,`favicon-${i}x${i}.png`);await c.default(o).resize(i,i,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).png().toFile(d),e.generatedFiles.push(d)}let f=512,y=u.join(a,`icon-maskable-${f}x${f}.png`),m=Math.floor(f*0.1),k=f-m*2;await c.default(o).resize(k,k,{fit:"contain",background:{r:0,g:0,b:0,alpha:0}}).extend({top:m,bottom:m,left:m,right:m,background:{r:255,g:255,b:255,alpha:1}}).png().toFile(y),e.generatedFiles.push(y)}catch(c){let h=c instanceof Error?c.message:String(c);e.errors.push(`Icon generation failed: ${h}`),e.success=!1}return e}function N(n){let t=n.sizes||v,e=n.outputDir?`/${n.outputDir}`:"/pwa-icons",r=n.generateWebP??!0,o=n.generateAppleIcons??!0,a=[];for(let s of t)if(a.push(`${e}/icon-${s}x${s}.png`),r)a.push(`${e}/icon-${s}x${s}.webp`);if(o){a.push(`${e}/apple-touch-icon.png`);for(let s of S)a.push(`${e}/apple-touch-icon-${s}x${s}.png`)}for(let s of P)a.push(`${e}/favicon-${s}x${s}.png`);return a.push(`${e}/icon-maskable-512x512.png`),a}async function I(){try{return await import("sharp"),!0}catch{return!1}}function A(n,t,e,r){let o=[],a=r.join(" ");for(let s of n)if(o.push({src:`${t}/icon-${s}x${s}.png`,sizes:`${s}x${s}`,type:"image/png",purpose:a}),e)o.push({src:`${t}/icon-${s}x${s}.webp`,sizes:`${s}x${s}`,type:"image/webp",purpose:a});return o}function C(n){return n.map((t)=>({name:t.name,short_name:t.shortName,description:t.description,url:t.url,icons:t.icons?.map((e)=>({src:e.src,sizes:e.sizes,type:e.type}))}))}function T(n){let t=n.pwa?.shareTarget;if(!t?.enabled)return;let e={action:t.action||"/share",method:t.method||"POST",enctype:t.enctype||"multipart/form-data",params:{title:t.params?.title||"title",text:t.params?.text||"text",url:t.params?.url||"url"}};if(t.acceptFiles&&t.acceptFiles.length>0)e.params.files=t.acceptFiles.map((r)=>({name:r.name,accept:r.accept}));return e}function H(n){let t=n.pwa?.fileHandlers;if(!t?.enabled||!t.accept)return;let e=[{action:t.action||"/",accept:t.accept,launch_type:t.launchType||"single-client"}];if(t.icons)e[0].icons=t.icons.map((r)=>({src:r.src,sizes:r.sizes,type:r.type}));return e}function W(n){let t=n.pwa?.protocolHandlers;if(!t||t.length===0)return;return t.map((e)=>({protocol:e.protocol,url:e.url}))}function j(n){let t=n.pwa;if(!t?.enabled||!t.manifest)return null;let{manifest:e,icons:r}=t,o=r?.sizes||[72,96,128,144,152,192,384,512],a=r?.outputDir?`/${r.outputDir}`:"/pwa-icons",s=r?.generateWebP??!0,l=r?.purpose||["any","maskable"],p={name:e.name,short_name:e.shortName||e.name,description:e.description,start_url:e.startUrl||"/",display:e.display||"standalone",display_override:e.displayOverride,orientation:e.orientation,theme_color:e.themeColor,background_color:e.backgroundColor,scope:e.scope||"/",lang:e.lang,dir:e.dir,id:e.id,categories:e.categories,icons:A(o,a,s,l)};if(e.shortcuts&&e.shortcuts.length>0)p.shortcuts=C(e.shortcuts);if(e.screenshots&&e.screenshots.length>0)p.screenshots=e.screenshots.map((f)=>({src:f.src,sizes:f.sizes,type:f.type,label:f.label,form_factor:f.platform}));let c=T(n);if(c)p.share_target=c;let h=H(n);if(h)p.file_handlers=h;let g=W(n);if(g)p.protocol_handlers=g;if(e.launchHandler)p.launch_handler={client_mode:e.launchHandler};if(e.handleLinks)p.handle_links=e.handleLinks;if(e.edgeSidePanel?.enabled)p.edge_side_panel={preferred_width:e.edgeSidePanel.preferredWidth};return p}function _(n){let t=j(n);if(!t)return"";let e=JSON.parse(JSON.stringify(t));return JSON.stringify(e,null,2)}function q(n,t){return{...t,...n,shortcuts:n.shortcuts||t.shortcuts,screenshots:n.screenshots||t.screenshots,categories:n.categories||t.categories}}function D(n){let t=[],e=n.pwa;if(!e?.enabled)return t;let r=e.manifest;if(!r)return t.push("PWA manifest configuration is missing"),t;if(!r.name)t.push("Manifest name is required");let o=["fullscreen","standalone","minimal-ui","browser"];if(r.display&&!o.includes(r.display))t.push(`Invalid display mode: ${r.display}. Must be one of: ${o.join(", ")}`);let a=["any","natural","landscape","landscape-primary","landscape-secondary","portrait","portrait-primary","portrait-secondary"];if(r.orientation&&!a.includes(r.orientation))t.push(`Invalid orientation: ${r.orientation}`);let s=/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;if(r.themeColor&&!s.test(r.themeColor))t.push(`Invalid theme color: ${r.themeColor}. Must be a valid hex color.`);if(r.backgroundColor&&!s.test(r.backgroundColor))t.push(`Invalid background color: ${r.backgroundColor}. Must be a valid hex color.`);if(e.shareTarget?.enabled){if(!e.shareTarget.action)t.push("Share target action URL is required")}if(e.fileHandlers?.enabled){if(!e.fileHandlers.accept||Object.keys(e.fileHandlers.accept).length===0)t.push("File handlers must specify accepted MIME types")}if(e.protocolHandlers)for(let l of e.protocolHandlers){if(!l.protocol)t.push("Protocol handler missing protocol");if(!l.url||!l.url.includes("%s"))t.push(`Protocol handler URL must contain %s placeholder: ${l.protocol}`)}return t}import z from"path";async function F(n){let t=n.pwa?.offline;if(!t?.enabled)return"";if(t.page){let e=z.isAbsolute(t.page)?t.page:z.resolve(process.cwd(),t.page);if(await Bun.file(e).exists())try{let{processDirectives:r}=await import("./chunk-xzdkjkyp.js"),o=await Bun.file(e).text();return await r(o,{},e,n,new Set)}catch(r){console.warn(`[PWA] Failed to process custom offline page: ${r}`)}else console.warn(`[PWA] Custom offline page not found: ${e}`)}return E(n)}function E(n){let t=n.pwa?.offline,e=n.pwa?.manifest,r=t?.fallbackTitle||"You are offline",o=t?.fallbackMessage||"Please check your internet connection and try again.",a=e?.themeColor||"#4f46e5",s=e?.shortName||e?.name||"App";return`<!DOCTYPE html>
4
4
  <html lang="en">
5
5
  <head>
6
6
  <meta charset="UTF-8">
@@ -233,4 +233,4 @@ Icon generation requires the sharp package for image processing.`),e.success=!1,
233
233
  }, 5000);
234
234
  </script>
235
235
  </body>
236
- </html>`}function b(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=qe(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=so(n,t);if(a){let s=Wt(n),l=w.join(t,s);await Bun.write(l,a),e.files.serviceWorker=l}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate service worker: ${s}`),e.success=!1}return e}function ae(n,t){return Bi(n,t)}function se(n){return n.pwa?.enabled===!0}export{S as APPLE_TOUCH_ICON_SIZES,v as DEFAULT_ICON_SIZES,P as FAVICON_SIZES,Pl as auditBuildOutput,Al as auditConfig,re as buildPwaAssets,Il as calculateAuditResult,Dg as formatAuditResult,Fi as formatSize,j as generateManifest,_ as generateManifestJson,jg as generateManifestLink,F as generateOfflinePage,qe as generatePrecacheManifest,Pn as generatePrecacheManifestJs,M as generatePwaIcons,ro as generatePwaTags,so as generateServiceWorker,Fg as generateServiceWorkerAuto,Lg as generateSwRegistrationScript,Bg as generateThemeColorMeta,N as getExpectedIconPaths,Wt as getServiceWorkerFileName,Bi as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,Ol as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,oo as pwaDirectives,zg as pwaInstallDirective,Vg as pwaOfflineDirective,Ug as pwaPushDirective,Hg as pwaUpdateDirective,$y as registerPwaDirectives,Mg as runPwaAudit,D as validateManifest};
236
+ </html>`}function b(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}async function re(n,t){let e={success:!0,files:{icons:[]},errors:[],warnings:[]},r=n.pwa;if(!r?.enabled)return e;try{B.mkdirSync(t,{recursive:!0})}catch{return e.errors.push(`Failed to create output directory: ${t}`),e.success=!1,e}try{let a=_(n);if(a){let s=w.join(t,"manifest.json");await Bun.write(s,a),e.files.manifest=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate manifest.json: ${s}`),e.success=!1}if(r.icons?.src)if(await I()){let s=await M(n,t);if(e.files.icons=s.generatedFiles,e.warnings.push(...s.warnings),!s.success)e.errors.push(...s.errors),e.success=!1}else e.warnings.push("sharp is not installed. Skipping icon generation. Install with: bun add sharp");if(r.offline?.enabled)try{let a=await F(n);if(a){let s=w.join(t,"offline.html");await Bun.write(s,a),e.files.offlinePage=s}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate offline page: ${s}`),e.success=!1}let o;if(r.precache?.enabled){let a=Xe(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=ao(n,t);if(a){let s=Gt(n),l=w.join(t,s);await Bun.write(l,a),e.files.serviceWorker=l}}catch(a){let s=a instanceof Error?a.message:String(a);e.errors.push(`Failed to generate service worker: ${s}`),e.success=!1}return e}function ae(n,t){return Hi(n,t)}function se(n){return n.pwa?.enabled===!0}export{S as APPLE_TOUCH_ICON_SIZES,v as DEFAULT_ICON_SIZES,P as FAVICON_SIZES,Nl as auditBuildOutput,Ol as auditConfig,re as buildPwaAssets,Ml as calculateAuditResult,Bg as formatAuditResult,Vi as formatSize,j as generateManifest,_ as generateManifestJson,zg as generateManifestLink,F as generateOfflinePage,Xe as generatePrecacheManifest,Nn as generatePrecacheManifestJs,M as generatePwaIcons,io as generatePwaTags,ao as generateServiceWorker,Vg as generateServiceWorkerAuto,Fg as generateSwRegistrationScript,Hg as generateThemeColorMeta,N as getExpectedIconPaths,Gt as getServiceWorkerFileName,Hi as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,Dl as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,co as pwaDirectives,Ug as pwaInstallDirective,qg as pwaOfflineDirective,Kg as pwaPushDirective,Wg as pwaUpdateDirective,Py as registerPwaDirectives,jg as runPwaAudit,D as validateManifest};
@@ -1,3 +1,4 @@
1
+ import { bodyCloseIndex } from "./document-tags.js";
1
2
  import * as crypto from "node:crypto";
2
3
  function extractStoreRefs(expression) {
3
4
  const storePattern = /\$(\w+)\./g, stores = [];
@@ -263,7 +264,7 @@ export function processTemplateBindings(html) {
263
264
  const { html: processedHtml, bindings, stores } = processReactiveBindings(html);
264
265
  if (bindings.length === 0)
265
266
  return html;
266
- const runtime = generateBindingsRuntime(bindings, stores), bodyIdx = processedHtml.lastIndexOf("</body>");
267
+ const runtime = generateBindingsRuntime(bindings, stores), bodyIdx = bodyCloseIndex(processedHtml);
267
268
  if (bodyIdx !== -1)
268
269
  return processedHtml.slice(0, bodyIdx) + runtime + processedHtml.slice(bodyIdx);
269
270
  return processedHtml + runtime;
package/dist/reactive.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { bodyCloseIndex } from "./document-tags.js";
1
2
  import { evaluateExpression } from "./expressions.js";
2
3
  import { scanAtElementPosition } from "./html-masking.js";
3
4
  let scopeCounter = 0, elementCounter = 0;
@@ -610,7 +611,7 @@ export function processReactiveDirectives(template, context, _filePath, deferIni
610
611
  if (scopes.length === 0)
611
612
  return template;
612
613
  let output = finalizeTemplate(template, scopes);
613
- const script = generateScopeInitializers(scopes, context, deferInit), bodyCloseIdx = output.lastIndexOf("</body>");
614
+ const script = generateScopeInitializers(scopes, context, deferInit), bodyCloseIdx = bodyCloseIndex(output);
614
615
  if (bodyCloseIdx !== -1)
615
616
  output = output.slice(0, bodyCloseIdx) + script + `
616
617
  ` + output.slice(bodyCloseIdx);
package/dist/render.js CHANGED
@@ -1,4 +1,4 @@
1
- import { insertBeforeBodyClose } from "./body-close.js";
1
+ import { insertBeforeBodyClose } from "./document-tags.js";
2
2
  import { dirname, resolve } from "node:path";
3
3
  import { defaultConfig } from "./config.js";
4
4
  import { extractVariables } from "./variable-extractor.js";
@@ -1,3 +1,4 @@
1
+ import { bodyCloseIndex, headCloseIndex, insertBeforeHeadClose } from "./document-tags.js";
1
2
  import { headInsertionPoint } from "./head-injection.js";
2
3
  import { BROWSER_CORE_IMPORTS } from "./browser-core-imports.js";
3
4
  import { getOwnedRouteMatchers } from "./owned-routes.js";
@@ -36,12 +37,11 @@ export function injectBrowserRuntime(template) {
36
37
  import '@stacksjs/browser'
37
38
  </script>`;
38
39
  if (template.includes("</head>")) {
39
- const headEndPos = template.indexOf("</head>"), firstScriptPos = template.slice(0, headEndPos).indexOf("<script");
40
+ const headEndPos = headCloseIndex(template), firstScriptPos = template.slice(0, headEndPos).indexOf("<script");
40
41
  if (firstScriptPos !== -1)
41
42
  return template.slice(0, firstScriptPos) + browserScript + `
42
43
  ` + template.slice(firstScriptPos);
43
- return template.replace("</head>", `${browserScript}
44
- </head>`);
44
+ return insertBeforeHeadClose(template, browserScript);
45
45
  }
46
46
  if (findBodyOpenTag(template))
47
47
  return replaceBodyOpenTag(template, (tag) => `${tag}
@@ -72,7 +72,7 @@ function placeRuntimeTag(template, runtimeScript) {
72
72
  return `${template.slice(0, headAt)}
73
73
  ${runtimeScript}${template.slice(headAt)}`;
74
74
  if (template.includes("</head>")) {
75
- const idx = template.indexOf("</head>");
75
+ const idx = headCloseIndex(template);
76
76
  return template.slice(0, idx) + runtimeScript + `
77
77
  ` + template.slice(idx);
78
78
  }
@@ -100,7 +100,7 @@ export function outputNeedsTooltipRuntime(html) {
100
100
  export function injectTooltipRuntime(html) {
101
101
  if (html.includes("data-stx-tooltip-runtime") || !outputNeedsTooltipRuntime(html))
102
102
  return html;
103
- const tag = `<script data-stx-scoped data-stx-tooltip-runtime>${getTooltipRuntime()}</script>`, bodyIdx = html.lastIndexOf("</body>");
103
+ const tag = `<script data-stx-scoped data-stx-tooltip-runtime>${getTooltipRuntime()}</script>`, bodyIdx = bodyCloseIndex(html);
104
104
  if (bodyIdx === -1)
105
105
  return `${html}
106
106
  ${tag}`;
@@ -169,7 +169,7 @@ export async function injectRouterScript(template, options) {
169
169
  configScript = `<script>window.__stxRouterConfig=${toScriptJson(configObj)};</script>
170
170
  `;
171
171
  }
172
- const { getCachedRouterScript, getServeClientAsset } = await import("./caching.js"), routerScript = options?.buildMode === "compile" ? '<script data-stx-router src="/__stx/router.__STX_HASH__.js"></script>' : options?.buildMode === "serve" ? `<script data-stx-router src="${(await getServeClientAsset("router")).url}"></script>` : `<script data-stx-router>${await getCachedRouterScript()}</script>`, bodyCloseIdx = template.lastIndexOf("</body>");
172
+ const { getCachedRouterScript, getServeClientAsset } = await import("./caching.js"), routerScript = options?.buildMode === "compile" ? '<script data-stx-router src="/__stx/router.__STX_HASH__.js"></script>' : options?.buildMode === "serve" ? `<script data-stx-router src="${(await getServeClientAsset("router")).url}"></script>` : `<script data-stx-router>${await getCachedRouterScript()}</script>`, bodyCloseIdx = bodyCloseIndex(template);
173
173
  return template.slice(0, bodyCloseIdx) + configScript + ownedRoutesScript + routerScript + `
174
174
  </body>` + template.slice(bodyCloseIdx + 7);
175
175
  }
package/dist/serve.js CHANGED
@@ -1,4 +1,4 @@
1
- import { insertBeforeBodyClose } from "./body-close.js";
1
+ import { insertBeforeBodyClose } from "./document-tags.js";
2
2
  import { serve as bunServe } from "bun";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
@@ -1,5 +1,5 @@
1
1
  import { Glob } from "bun";
2
- import { insertBeforeBodyClose } from "../body-close.js";
2
+ import { insertBeforeBodyClose } from "../document-tags.js";
3
3
  import {
4
4
  cpSync,
5
5
  existsSync,
@@ -1,3 +1,4 @@
1
+ import { insertBeforeHeadClose } from "../document-tags.js";
1
2
  import { existsSync, readFileSync } from "node:fs";
2
3
  import { join, resolve } from "node:path";
3
4
  import process from "node:process";
@@ -129,8 +130,7 @@ export function stampLocaleLayoutGroup(html, locale) {
129
130
  if (/<meta name="stx-layout-group"[^>]*>/i.test(html))
130
131
  return html.replace(/<meta name="stx-layout-group"[^>]*>/i, groupMeta);
131
132
  if (/<\/head>/i.test(html))
132
- return html.replace(/<\/head>/i, `${groupMeta}
133
- </head>`);
133
+ return insertBeforeHeadClose(html, groupMeta);
134
134
  return `${groupMeta}
135
135
  ${html}`;
136
136
  }
@@ -1,4 +1,4 @@
1
- import { insertBeforeBodyClose } from "../body-close.js";
1
+ import { insertBeforeBodyClose } from "../document-tags.js";
2
2
  let _cachedRouterScript = null;
3
3
  async function getRouterScript() {
4
4
  if (_cachedRouterScript !== null)
@@ -1,4 +1,4 @@
1
- import { insertBeforeBodyClose } from "../body-close.js";
1
+ import { insertBeforeBodyClose } from "../document-tags.js";
2
2
  import { COLOR_MODE_BOOT_MARKER } from "../color-mode-boot.js";
3
3
  const FAVICON_FN = `window.__stxThemeIcon=function(isDark){try{var want=isDark?'dark':'light';var pick=document.querySelector('link[rel~="icon"][media*="prefers-color-scheme: '+want+'"]');if(!pick)return;var live=document.querySelector('link[rel~="icon"]:not([media])');if(!live){live=document.createElement('link');live.setAttribute('rel','icon');document.head.appendChild(live)}if(pick.type)live.setAttribute('type',pick.type);var href=pick.getAttribute('href');if(live.getAttribute('href')!==href)live.setAttribute('href',href)}catch(e){}};`, FOUC_SCRIPT = (defaultTheme, storageKey, lightColor, darkColor) => `(function(){${FAVICON_FN}function read(){try{var k=${JSON.stringify(storageKey)};var t=localStorage.getItem(k);return t===null?(${JSON.stringify(defaultTheme)}==='dark'||(${JSON.stringify(defaultTheme)}==='auto'&&window.matchMedia('(prefers-color-scheme: dark)').matches)):t==='dark'}catch(e){return ${JSON.stringify(defaultTheme)}==='dark'}}function apply(){var isDark=read();var html=document.documentElement;html.classList[isDark?'add':'remove']('dark');var color=isDark?${JSON.stringify(darkColor)}:${JSON.stringify(lightColor)};if(!document.head)return;var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(!tc){tc=document.createElement('meta');tc.setAttribute('name','theme-color');tc.setAttribute('data-stx-theme-meta','1')}tc.setAttribute('content',color);if(tc!==document.head.firstChild){document.head.insertBefore(tc,document.head.firstChild)}if(window.__stxThemeIcon)window.__stxThemeIcon(isDark)}apply();window.addEventListener('stx:navigate',apply);window.addEventListener('popstate',apply)})();`, TOGGLE_HANDLER = (storageKey, lightColor, darkColor) => `document.addEventListener('click',function(e){var t=e.target&&e.target.closest&&e.target.closest('#theme-toggle');if(!t)return;var html=document.documentElement;var isDark=html.classList.toggle('dark');try{localStorage.setItem(${JSON.stringify(storageKey)},isDark?'dark':'light')}catch(e){}var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(tc)tc.setAttribute('content',isDark?${JSON.stringify(darkColor)}:${JSON.stringify(lightColor)});if(window.__stxThemeIcon)window.__stxThemeIcon(isDark)});`;
4
4
  export function injectThemeBootstrap(html, site) {