@stacksjs/stx 0.2.645 → 0.2.648

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 (264) hide show
  1. package/dist/builtins/attrs.js +6 -6
  2. package/dist/builtins/escape.d.ts +0 -11
  3. package/dist/builtins/escape.js +2 -1
  4. package/dist/builtins/safe-image.js +1 -3
  5. package/dist/builtins/stx-image.js +1 -3
  6. package/dist/builtins/stx-link.d.ts +3 -0
  7. package/dist/builtins/stx-link.js +1 -3
  8. package/dist/{chunk-apeyn69a.js → chunk-04kg16qs.js} +4 -4
  9. package/dist/chunk-06w0z1cm.js +31 -0
  10. package/dist/chunk-0en5jwjy.js +2 -0
  11. package/dist/{chunk-ph8dqgr5.js → chunk-0h8tg21j.js} +14 -14
  12. package/dist/{chunk-g2mcw1r4.js → chunk-0jhdrgpr.js} +2 -2
  13. package/dist/chunk-0vkawews.js +21 -0
  14. package/dist/{chunk-hpggz2t4.js → chunk-120ze5ms.js} +3 -3
  15. package/dist/chunk-2a4szpje.js +3 -0
  16. package/dist/chunk-2f17h17f.js +2 -0
  17. package/dist/{chunk-a0ygyftk.js → chunk-2h8ea0we.js} +2 -2
  18. package/dist/{chunk-3ns5k9nf.js → chunk-2jh21f1n.js} +2 -2
  19. package/dist/chunk-2n3pa5gm.js +2 -0
  20. package/dist/{chunk-ktvr45qg.js → chunk-2qbvsvwc.js} +2 -2
  21. package/dist/chunk-354jmw2k.js +3 -0
  22. package/dist/chunk-3b5bphcn.js +2 -0
  23. package/dist/chunk-3p7mk3mw.js +2 -0
  24. package/dist/chunk-3q163st5.js +1312 -0
  25. package/dist/chunk-3zyjqvsq.js +42 -0
  26. package/dist/{chunk-mfd3fca7.js → chunk-481d4kr9.js} +11 -11
  27. package/dist/chunk-4q2dtxdk.js +2 -0
  28. package/dist/{chunk-1t0m4pwg.js → chunk-4yf1w261.js} +2 -2
  29. package/dist/chunk-4yt8tg4j.js +2 -0
  30. package/dist/chunk-52gp2xxk.js +2 -0
  31. package/dist/chunk-55zaxb4s.js +61 -0
  32. package/dist/chunk-57md41g9.js +2 -0
  33. package/dist/chunk-67kj14at.js +2 -0
  34. package/dist/chunk-67xhsacd.js +12 -0
  35. package/dist/{chunk-me1tdtzz.js → chunk-6ajahb2x.js} +3 -3
  36. package/dist/chunk-6ea6az61.js +4 -0
  37. package/dist/chunk-6vh8s0pg.js +2 -0
  38. package/dist/chunk-6vzktvyw.js +2 -0
  39. package/dist/{chunk-r2seygb5.js → chunk-7rta163c.js} +2 -2
  40. package/dist/chunk-84djpte6.js +3 -0
  41. package/dist/chunk-864qtx7y.js +2 -0
  42. package/dist/chunk-88z4wkrj.js +6 -0
  43. package/dist/chunk-89yj6tcd.js +2 -0
  44. package/dist/chunk-8d2f2e42.js +2 -0
  45. package/dist/chunk-8fsq2ynj.js +2 -0
  46. package/dist/chunk-8p9kpfk8.js +4 -0
  47. package/dist/chunk-8tpmz4as.js +2 -0
  48. package/dist/chunk-9121nkpj.js +11 -0
  49. package/dist/{chunk-rmj0n3ss.js → chunk-9p6efb17.js} +1 -1
  50. package/dist/chunk-9szxxgv5.js +2 -0
  51. package/dist/{chunk-4g8zase6.js → chunk-9txn4rvb.js} +2 -2
  52. package/dist/chunk-9x0zt65f.js +2 -0
  53. package/dist/chunk-a2bw46t9.js +2 -0
  54. package/dist/{chunk-gvr10eqb.js → chunk-a3d0g4mr.js} +2 -2
  55. package/dist/chunk-a4sggwcz.js +2 -0
  56. package/dist/chunk-ab7zqtax.js +3 -0
  57. package/dist/{chunk-v1mvbf82.js → chunk-aprhqxky.js} +5 -5
  58. package/dist/chunk-b0hpshvk.js +2 -0
  59. package/dist/chunk-b4fd2dtk.js +2 -0
  60. package/dist/chunk-c1479y92.js +2 -0
  61. package/dist/{chunk-kchphxkm.js → chunk-c1dkh0es.js} +3 -3
  62. package/dist/chunk-c9k40352.js +2 -0
  63. package/dist/{chunk-ahyq08mp.js → chunk-ce6zddpf.js} +3 -3
  64. package/dist/{chunk-9wbtj6tj.js → chunk-dgb4z4kw.js} +2 -2
  65. package/dist/chunk-e87xa4r3.js +4 -0
  66. package/dist/chunk-egg54kd0.js +12 -0
  67. package/dist/chunk-embejqx4.js +2 -0
  68. package/dist/chunk-er60h3j3.js +2 -0
  69. package/dist/{chunk-pp6ycfay.js → chunk-ewcrsyr7.js} +2 -2
  70. package/dist/chunk-eyfxw7ds.js +2 -0
  71. package/dist/chunk-f3y4fnaa.js +2 -0
  72. package/dist/chunk-f46ht5kq.js +20 -0
  73. package/dist/chunk-f7930sce.js +2 -0
  74. package/dist/chunk-fcn71bq1.js +2 -0
  75. package/dist/{chunk-38ngmh6h.js → chunk-fg3jw17w.js} +48 -48
  76. package/dist/chunk-fsbjat59.js +2 -0
  77. package/dist/chunk-g2jmwh7p.js +2 -0
  78. package/dist/chunk-g8r0km7g.js +106 -0
  79. package/dist/{chunk-qa625vwc.js → chunk-gv793yqq.js} +4 -4
  80. package/dist/chunk-gz90fqn8.js +2 -0
  81. package/dist/chunk-h15xb2vd.js +2 -0
  82. package/dist/chunk-h5nmf98w.js +2 -0
  83. package/dist/{chunk-w9zxb26s.js → chunk-hfpv56cp.js} +1 -1
  84. package/dist/chunk-hhmj9gpk.js +2 -0
  85. package/dist/chunk-hjm69qnj.js +2 -0
  86. package/dist/chunk-hvtzw1jh.js +2 -0
  87. package/dist/{chunk-4n24jbfs.js → chunk-hvzzhkhr.js} +2 -2
  88. package/dist/chunk-j0v970k3.js +2 -0
  89. package/dist/chunk-j393gsfd.js +20 -0
  90. package/dist/chunk-j5gd0e53.js +2 -0
  91. package/dist/chunk-jk41jwsc.js +2 -0
  92. package/dist/{chunk-kvn23sz5.js → chunk-jkaszw24.js} +4 -4
  93. package/dist/{chunk-6mnwvn9v.js → chunk-jkvr7e91.js} +2 -2
  94. package/dist/{chunk-2zcbx82x.js → chunk-jxda11cg.js} +2 -2
  95. package/dist/chunk-k2pa44rf.js +2 -0
  96. package/dist/{chunk-kad2cp0z.js → chunk-k79x96ra.js} +37 -37
  97. package/dist/{chunk-75c46b62.js → chunk-kgfgb971.js} +4 -4
  98. package/dist/chunk-m6qfqkbh.js +2 -0
  99. package/dist/{chunk-r7haw6r7.js → chunk-mmwedr93.js} +5 -5
  100. package/dist/chunk-mnp8ecj9.js +2 -0
  101. package/dist/{chunk-dyg6sadv.js → chunk-mrrrngzd.js} +1 -1
  102. package/dist/{chunk-fk1rs7jb.js → chunk-n38yb274.js} +6 -6
  103. package/dist/chunk-ncqh5qe5.js +2 -0
  104. package/dist/chunk-nj1t4g3a.js +25 -0
  105. package/dist/{chunk-3cqxtkqv.js → chunk-np4zm2ph.js} +7 -7
  106. package/dist/{chunk-7jgtphhg.js → chunk-nrvwejdw.js} +5 -5
  107. package/dist/{chunk-c96f3eq5.js → chunk-nt0n0vjm.js} +8 -8
  108. package/dist/chunk-p44kmbdg.js +65 -0
  109. package/dist/chunk-pbtkbe48.js +888 -0
  110. package/dist/{chunk-pf5s5gjp.js → chunk-pg0xzsss.js} +2 -2
  111. package/dist/{chunk-pvfx0dgz.js → chunk-prf164ct.js} +2 -2
  112. package/dist/chunk-pxs7sgnp.js +3 -0
  113. package/dist/chunk-qfe7ps3v.js +18 -0
  114. package/dist/chunk-qm4672dj.js +18 -0
  115. package/dist/{chunk-2bsrmqr8.js → chunk-qv6axke4.js} +2 -2
  116. package/dist/chunk-r1r6311d.js +14 -0
  117. package/dist/{chunk-n54c06wt.js → chunk-r3e6x87d.js} +3 -3
  118. package/dist/chunk-radggg3p.js +49 -0
  119. package/dist/{chunk-zm4s3n4p.js → chunk-rcadtv3x.js} +1 -1
  120. package/dist/{chunk-vbqts5sf.js → chunk-rjh2jwxx.js} +9 -9
  121. package/dist/chunk-sf0wsq74.js +2 -0
  122. package/dist/{chunk-kfq594fh.js → chunk-sgptbhrc.js} +2 -2
  123. package/dist/chunk-shpc1ttk.js +2 -0
  124. package/dist/chunk-sszhz1zh.js +2 -0
  125. package/dist/chunk-szyqxcfj.js +3 -0
  126. package/dist/{chunk-392pj66x.js → chunk-t1k9160w.js} +29 -29
  127. package/dist/{chunk-22hdbqad.js → chunk-t2pzy3x1.js} +3 -3
  128. package/dist/chunk-t6yjxhn8.js +2 -0
  129. package/dist/chunk-t82be9yf.js +2 -0
  130. package/dist/{chunk-g06qzkmp.js → chunk-tre98h62.js} +2 -2
  131. package/dist/{chunk-bsts9pr5.js → chunk-v2x9vzgw.js} +2 -2
  132. package/dist/chunk-vdxjy7j2.js +4 -0
  133. package/dist/{chunk-xbdbn3bf.js → chunk-vmwdt8fr.js} +5 -5
  134. package/dist/{chunk-fqg0espy.js → chunk-vqc4h16r.js} +2 -2
  135. package/dist/chunk-w2zceynt.js +2 -0
  136. package/dist/chunk-weqc0ssb.js +2 -0
  137. package/dist/chunk-wjt0kej9.js +3 -0
  138. package/dist/{chunk-9yk5rasj.js → chunk-wpm58d6p.js} +3 -3
  139. package/dist/{chunk-0zr1zxar.js → chunk-wpmrz872.js} +2 -2
  140. package/dist/chunk-wq6j2h32.js +33 -0
  141. package/dist/chunk-wq712sw1.js +2 -0
  142. package/dist/chunk-x34scshq.js +3 -0
  143. package/dist/{chunk-fb17t651.js → chunk-x5tjb4y4.js} +2 -2
  144. package/dist/chunk-xaa36b0x.js +3 -0
  145. package/dist/chunk-xfzcv0jc.js +2 -0
  146. package/dist/{chunk-dmg8dpah.js → chunk-xm2mee4a.js} +169 -169
  147. package/dist/chunk-xvs04cnp.js +2 -0
  148. package/dist/chunk-y9x4pyp2.js +2 -0
  149. package/dist/chunk-ye8tgmd3.js +2 -0
  150. package/dist/{chunk-febtq3xj.js → chunk-ym41ybz2.js} +6 -6
  151. package/dist/chunk-ymymwzt5.js +3 -0
  152. package/dist/{chunk-wpc04ygt.js → chunk-yq021b3r.js} +11 -11
  153. package/dist/chunk-z8p6tk5z.js +2 -0
  154. package/dist/chunk-zdnc7a4t.js +127 -0
  155. package/dist/chunk-zhf01af3.js +3 -0
  156. package/dist/chunk-zmh9p9aa.js +2 -0
  157. package/dist/{chunk-jtvcxbwd.js → chunk-zqtbtqbq.js} +2 -2
  158. package/dist/chunk-zsgcsqat.js +406 -0
  159. package/dist/chunk-zyqs6a3p.js +2 -0
  160. package/dist/cli.js +62 -62
  161. package/dist/craft-entry.js +2 -2
  162. package/dist/craft.js +2 -2
  163. package/dist/expressions.d.ts +6 -21
  164. package/dist/expressions.js +12 -41
  165. package/dist/forms-validation.d.ts +0 -16
  166. package/dist/forms-validation.js +4 -2
  167. package/dist/forms.js +8 -6
  168. package/dist/i18n.js +6 -4
  169. package/dist/interpolation-context.js +173 -29
  170. package/dist/loops.js +70 -90
  171. package/dist/mustache-span.d.ts +21 -0
  172. package/dist/mustache-span.js +35 -0
  173. package/dist/process.js +4 -3
  174. package/dist/pwa.js +3 -3
  175. package/dist/runtime-injection.js +9 -3
  176. package/dist/server-bindings.js +12 -6
  177. package/dist/ssg.js +28 -28
  178. package/dist/utils.js +1 -2
  179. package/package.json +5 -5
  180. package/dist/chunk-1jgsst0v.js +0 -2
  181. package/dist/chunk-1vrqmdfe.js +0 -2
  182. package/dist/chunk-1vx1ha9v.js +0 -2
  183. package/dist/chunk-1y9jphbg.js +0 -2
  184. package/dist/chunk-22kgdhxy.js +0 -2
  185. package/dist/chunk-2etamr31.js +0 -4
  186. package/dist/chunk-2s49ggrz.js +0 -12
  187. package/dist/chunk-2zbnc6jq.js +0 -2
  188. package/dist/chunk-39beqd1g.js +0 -2
  189. package/dist/chunk-3q5yn5r0.js +0 -6
  190. package/dist/chunk-3tcy2hdt.js +0 -2
  191. package/dist/chunk-3ycbhpa2.js +0 -2
  192. package/dist/chunk-3yqs2ekt.js +0 -2
  193. package/dist/chunk-4mm9ttc7.js +0 -2
  194. package/dist/chunk-4q4vy4g6.js +0 -2
  195. package/dist/chunk-4zapx8zt.js +0 -20
  196. package/dist/chunk-5zkwems4.js +0 -2
  197. package/dist/chunk-6e4es31t.js +0 -3
  198. package/dist/chunk-6hmbzqt8.js +0 -2
  199. package/dist/chunk-7a3kffqy.js +0 -2
  200. package/dist/chunk-7mkw98cr.js +0 -3
  201. package/dist/chunk-7xks65hg.js +0 -3
  202. package/dist/chunk-8k38mddf.js +0 -2
  203. package/dist/chunk-8q05cxzd.js +0 -2
  204. package/dist/chunk-a7y0fk20.js +0 -12
  205. package/dist/chunk-abwxa3tj.js +0 -2
  206. package/dist/chunk-ayjje1hk.js +0 -2
  207. package/dist/chunk-c93291jk.js +0 -2
  208. package/dist/chunk-cf6d5kgb.js +0 -65
  209. package/dist/chunk-crahn5xa.js +0 -4
  210. package/dist/chunk-d1jyxxcm.js +0 -3
  211. package/dist/chunk-d365tseq.js +0 -20
  212. package/dist/chunk-d67qvrzc.js +0 -24
  213. package/dist/chunk-dwnvqy3f.js +0 -4
  214. package/dist/chunk-dxb7jw7g.js +0 -2
  215. package/dist/chunk-e8483tnk.js +0 -2
  216. package/dist/chunk-eaphbqqx.js +0 -2
  217. package/dist/chunk-em0chjea.js +0 -18
  218. package/dist/chunk-ercd4pqc.js +0 -2
  219. package/dist/chunk-ewj4gqwe.js +0 -31
  220. package/dist/chunk-f7bgg2e4.js +0 -2
  221. package/dist/chunk-g6s0xdgb.js +0 -4
  222. package/dist/chunk-jxsgky4v.js +0 -2
  223. package/dist/chunk-k90yzxwp.js +0 -2
  224. package/dist/chunk-kfx4cte8.js +0 -127
  225. package/dist/chunk-kxbw0e2f.js +0 -3
  226. package/dist/chunk-ky043mkv.js +0 -2
  227. package/dist/chunk-mbqqc20a.js +0 -2
  228. package/dist/chunk-mq2kpg6w.js +0 -2
  229. package/dist/chunk-n58ky78d.js +0 -2
  230. package/dist/chunk-n80wh9b5.js +0 -2
  231. package/dist/chunk-p7sfjgtm.js +0 -2
  232. package/dist/chunk-ps9htxmp.js +0 -2
  233. package/dist/chunk-qhaw7f32.js +0 -2
  234. package/dist/chunk-rh33ra9e.js +0 -2
  235. package/dist/chunk-rzs2hpqa.js +0 -2
  236. package/dist/chunk-s3sckkvv.js +0 -2
  237. package/dist/chunk-s89pq4v1.js +0 -2
  238. package/dist/chunk-sdqgmcbk.js +0 -2
  239. package/dist/chunk-srmm69d4.js +0 -2852
  240. package/dist/chunk-t00y30w3.js +0 -2
  241. package/dist/chunk-t1a39rpd.js +0 -2
  242. package/dist/chunk-tj4rzy69.js +0 -2
  243. package/dist/chunk-tme51pg1.js +0 -2
  244. package/dist/chunk-tv1qtqab.js +0 -3
  245. package/dist/chunk-twh5ck5w.js +0 -2
  246. package/dist/chunk-v4tt3t1y.js +0 -2
  247. package/dist/chunk-v5ekdsw0.js +0 -2
  248. package/dist/chunk-vdsrae92.js +0 -2
  249. package/dist/chunk-w88mpbxk.js +0 -11
  250. package/dist/chunk-wg6n7txf.js +0 -2
  251. package/dist/chunk-wj4rf7sb.js +0 -2
  252. package/dist/chunk-wrd5me1w.js +0 -33
  253. package/dist/chunk-xbevgwks.js +0 -2
  254. package/dist/chunk-y2k3ynr2.js +0 -2
  255. package/dist/chunk-y51ndrdb.js +0 -2
  256. package/dist/chunk-y9wqzvxt.js +0 -2
  257. package/dist/chunk-yn2d8x8m.js +0 -3
  258. package/dist/chunk-ysmt4jpn.js +0 -2
  259. package/dist/chunk-zmccfvbf.js +0 -2
  260. package/dist/chunk-ztpqxs72.js +0 -2
  261. package/dist/chunk-ztwnn466.js +0 -2
  262. package/dist/chunk-zx7v6a4g.js +0 -40
  263. package/dist/chunk-zx94g4pg.js +0 -2
  264. package/dist/chunk-zze1ez1c.js +0 -2
package/dist/loops.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { parseLoopBinding } from "./loop-binding.js";
2
2
  import { processConditionals } from "./conditionals.js";
3
3
  import { ErrorCodes, inlineError } from "./error-handling.js";
4
- import { processExpressions } from "./expressions.js";
4
+ import { escapeInterpolatedHtmlValue, findMustacheEnd, processExpressions, replaceInterpolations } from "./expressions.js";
5
5
  import { findDirectiveBlocks, findMatchingDelimiter } from "./parser/index.js";
6
6
  import { createSafeFunction, freeIdentifiers, isExpressionSafe, isForExpressionSafe, SANITIZE_CACHE, sanitizeExpression, safeEvaluate, safeEvaluateObject } from "./safe-evaluator.js";
7
7
  const DEFAULT_MAX_WHILE_ITERATIONS = 1000, DEFAULT_USE_ALT_LOOP_VARIABLE = !1;
@@ -145,51 +145,52 @@ function processPropBindings(content, context) {
145
145
  return result;
146
146
  }
147
147
  const BREAK_MARKER = "<!--__STX_BREAK__-->", CONTINUE_MARKER = "<!--__STX_CONTINUE__-->";
148
- function processConditionalLoopControl(content, context) {
149
- let result = content;
150
- result = replaceWithBalancedParens(result, "@break", (condition) => {
151
- try {
152
- const boolExpr = `!!(${condition.trim()})`;
153
- let shouldBreak;
154
- if (isExpressionSafe(boolExpr)) {
155
- const condFn = createSafeFunction(boolExpr, Object.keys(context));
156
- shouldBreak = Boolean(condFn(...Object.values(context)));
157
- } else
158
- shouldBreak = Boolean(safeEvaluate(boolExpr, context));
159
- return shouldBreak ? BREAK_MARKER : "";
160
- } catch {
161
- return "";
148
+ function processLoopControl(content, context) {
149
+ const tokens = /\{\{\{?|\{!!|@(break|continue)(?![\w$])/g;
150
+ let result = "", cursor = 0;
151
+ for (let match = tokens.exec(content);match; match = tokens.exec(content)) {
152
+ if (!match[1]) {
153
+ const braces = match[0].length === 3 && match[0] === "{{{" ? 3 : 2, end = match[0] === "{!!" ? content.indexOf("!!}", tokens.lastIndex) : findMustacheEnd(content, match.index, braces);
154
+ if (end < 0)
155
+ break;
156
+ tokens.lastIndex = end + (match[0] === "{!!" ? 3 : braces);
157
+ continue;
162
158
  }
163
- });
164
- result = replaceWithBalancedParens(result, "@continue", (condition) => {
165
- try {
166
- const boolExpr = `!!(${condition.trim()})`;
167
- let shouldContinue;
168
- if (isExpressionSafe(boolExpr)) {
169
- const condFn = createSafeFunction(boolExpr, Object.keys(context));
170
- shouldContinue = Boolean(condFn(...Object.values(context)));
171
- } else
172
- shouldContinue = Boolean(safeEvaluate(boolExpr, context));
173
- return shouldContinue ? CONTINUE_MARKER : "";
174
- } catch {
175
- return "";
159
+ let end = tokens.lastIndex, shouldStop = !0;
160
+ const suffix = /^\s*\(/.exec(content.slice(end));
161
+ if (suffix) {
162
+ const open = end + suffix[0].length - 1, close = findMatchingDelimiter(content, "(", ")", open);
163
+ if (close < 0)
164
+ break;
165
+ end = close + 1;
166
+ try {
167
+ const expression = `!!(${content.slice(open + 1, close).trim()})`;
168
+ shouldStop = isExpressionSafe(expression) ? Boolean(createSafeFunction(expression, Object.keys(context))(...Object.values(context))) : Boolean(safeEvaluate(expression, context));
169
+ } catch {
170
+ shouldStop = !1;
171
+ }
176
172
  }
177
- });
178
- return result;
179
- }
180
- function processUnconditionalLoopControl(content) {
181
- let result = content;
182
- result = result.replace(/@break(?!\()/g, BREAK_MARKER);
183
- result = result.replace(/@continue(?!\()/g, CONTINUE_MARKER);
184
- return result;
173
+ result += content.slice(cursor, match.index);
174
+ if (shouldStop)
175
+ return result + (match[1] === "break" ? BREAK_MARKER : CONTINUE_MARKER);
176
+ cursor = end;
177
+ tokens.lastIndex = end;
178
+ }
179
+ return result + content.slice(cursor);
185
180
  }
186
- function checkAndCleanBreak(content) {
187
- const hasBreak = content.includes(BREAK_MARKER), cleanContent = hasBreak ? content.substring(0, content.indexOf(BREAK_MARKER)) : content;
188
- return { hasBreak, content: cleanContent };
181
+ function compileLoopContent(content) {
182
+ const literal = (text) => text.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
183
+ let body = "", cursor = 0;
184
+ replaceInterpolations(content, (match, expr, offset) => {
185
+ body += convertLoopControlToJS(literal(content.slice(cursor, offset)));
186
+ body += `\${__stxRenderLoopValue(${offset}, (${expr}), ${match.length})}`;
187
+ cursor = offset + match.length;
188
+ return match;
189
+ });
190
+ return body + convertLoopControlToJS(literal(content.slice(cursor)));
189
191
  }
190
- function checkAndCleanContinue(content) {
191
- const hasContinue = content.includes(CONTINUE_MARKER), cleanContent = hasContinue ? content.substring(0, content.indexOf(CONTINUE_MARKER)) : content;
192
- return { hasContinue, content: cleanContent };
192
+ function renderLoopValue(content, offset, value, length) {
193
+ return escapeInterpolatedHtmlValue(content, offset, value == null ? "" : String(value), !1, length);
193
194
  }
194
195
  function convertLoopControlToJS(content) {
195
196
  let result = content;
@@ -502,35 +503,20 @@ export function processLoops(template, context, filePath, options, deferWarnings
502
503
  itemContext[itemName] = item[1];
503
504
  } else
504
505
  itemContext[indexName] = index;
505
- let processedContent = processConditionalLoopControl(content, itemContext), continueCheck = checkAndCleanContinue(processedContent);
506
- if (continueCheck.hasContinue) {
507
- loopResult += continueCheck.content;
508
- continue;
509
- }
510
- let breakCheck = checkAndCleanBreak(processedContent);
511
- if (breakCheck.hasBreak) {
512
- loopResult += breakCheck.content;
513
- break;
514
- }
515
- processedContent = processForelse(processedContent, itemContext);
516
- processedContent = processForeachWithContext(processedContent, itemContext);
506
+ let processedContent = processForelse(content, itemContext);
507
+ processedContent = processLoops(processedContent, itemContext, filePath, options, !0);
517
508
  processedContent = processConditionals(processedContent, itemContext, filePath);
518
- processedContent = processUnconditionalLoopControl(processedContent);
519
- breakCheck = checkAndCleanBreak(processedContent);
520
- if (breakCheck.hasBreak) {
521
- loopResult += breakCheck.content;
522
- break;
523
- }
524
- continueCheck = checkAndCleanContinue(processedContent);
525
- if (continueCheck.hasContinue) {
526
- loopResult += continueCheck.content;
527
- continue;
528
- }
509
+ processedContent = processLoopControl(processedContent, itemContext);
510
+ const breakAt = processedContent.indexOf(BREAK_MARKER), continueAt = processedContent.indexOf(CONTINUE_MARKER), stopAt = breakAt < 0 ? continueAt : continueAt < 0 ? breakAt : Math.min(breakAt, continueAt);
511
+ if (stopAt >= 0)
512
+ processedContent = processedContent.slice(0, stopAt);
529
513
  processedContent = processExpressions(processedContent, itemContext, filePath);
530
514
  processedContent = processPropBindings(processedContent, itemContext);
531
515
  processedContent = preEvaluateComponentProps(processedContent, itemContext);
532
516
  processedContent = preEvaluateIncludeData(processedContent, itemContext);
533
517
  loopResult += processedContent;
518
+ if (stopAt >= 0 && stopAt === breakAt)
519
+ break;
534
520
  }
535
521
  result = result.substring(0, start) + loopResult + result.substring(end);
536
522
  } catch (error) {
@@ -591,17 +577,14 @@ function processForLoops(template, context, filePath, options) {
591
577
  continue;
592
578
  }
593
579
  const loopKeys = Object.keys(context), loopValues = Object.values(context);
594
- let processedContent = content.replace(/`/g, "\\`").replace(/\$\{/g, "\\${").replace(/\{\{([^}]+)\}\}/g, (_match, expr) => {
595
- return `\${${expr}}`;
596
- });
597
- processedContent = convertLoopControlToJS(processedContent);
598
- const result = Function(...loopKeys, `
580
+ let processedContent = compileLoopContent(content);
581
+ const result = Function(...loopKeys, "__stxRenderLoopValue", `
599
582
  let result = '';
600
583
  for (${forExpr}) {
601
584
  result += \`${processedContent}\`;
602
585
  }
603
586
  return result;
604
- `)(...loopValues);
587
+ `)(...loopValues, (offset, value, length) => renderLoopValue(content, offset, value, length));
605
588
  output = output.substring(0, startPos) + result + output.substring(endPos);
606
589
  processedAny = !0;
607
590
  } catch (error) {
@@ -638,26 +621,26 @@ function parseForIterVarNames(expr) {
638
621
  return [];
639
622
  }
640
623
  function renderForLoopWithRecursion(args) {
641
- const { forExpr, content, iterVarNames, context, filePath, options } = args, contextKeys = Object.keys(context), contextValues = Object.values(context), captureFn = Function(...contextKeys, "__pushIter", `
624
+ const { forExpr, content, iterVarNames, context, filePath, options } = args, contextKeys = Object.keys(context), contextValues = Object.values(context), fp = filePath ?? "inline.stx";
625
+ let rendered = "";
626
+ Function(...contextKeys, "__renderIteration", `
642
627
  for (${forExpr}) {
643
- __pushIter([${iterVarNames.join(", ")}])
628
+ if (!__renderIteration([${iterVarNames.join(", ")}])) break;
644
629
  }
645
- `), captured = [];
646
- captureFn(...contextValues, (vals) => {
647
- captured.push(vals);
648
- });
649
- const fp = filePath ?? "inline.stx";
650
- let rendered = "";
651
- for (const values of captured) {
630
+ `)(...contextValues, (values) => {
652
631
  const iterContext = { ...context };
653
632
  iterVarNames.forEach((name, idx) => {
654
633
  iterContext[name] = values[idx];
655
634
  });
656
- let chunk = processForLoops(content, iterContext, filePath, options);
635
+ let chunk = processLoops(content, iterContext, fp, options, !0);
657
636
  chunk = processConditionals(chunk, iterContext, fp);
658
- chunk = processExpressions(chunk, iterContext, fp);
659
- rendered += chunk;
660
- }
637
+ chunk = processLoopControl(chunk, iterContext);
638
+ const breakAt = chunk.indexOf(BREAK_MARKER), continueAt = chunk.indexOf(CONTINUE_MARKER), stopAt = breakAt < 0 ? continueAt : continueAt < 0 ? breakAt : Math.min(breakAt, continueAt);
639
+ if (stopAt >= 0)
640
+ chunk = chunk.slice(0, stopAt);
641
+ rendered += processExpressions(chunk, iterContext, fp);
642
+ return stopAt < 0 || stopAt !== breakAt;
643
+ });
661
644
  return rendered;
662
645
  }
663
646
  function processWhileLoops(template, context, maxIterations) {
@@ -682,11 +665,8 @@ function processWhileLoops(template, context, maxIterations) {
682
665
  }
683
666
  try {
684
667
  const loopKeys = Object.keys(context), loopValues = Object.values(context);
685
- let processedContent = content.replace(/`/g, "\\`").replace(/\$\{/g, "\\${").replace(/\{\{([^}]+)\}\}/g, (_match, expr) => {
686
- return `\${${expr}}`;
687
- });
688
- processedContent = convertLoopControlToJS(processedContent);
689
- const result = Function(...loopKeys, `
668
+ let processedContent = compileLoopContent(content);
669
+ const result = Function(...loopKeys, "__stxRenderLoopValue", `
690
670
  let result = '';
691
671
  let maxIterations = ${maxIterations}; // Configurable safety limit
692
672
  let counter = 0;
@@ -698,7 +678,7 @@ function processWhileLoops(template, context, maxIterations) {
698
678
  result += '<!-- [While Error [1104]]: Maximum iterations (${maxIterations}) exceeded in while loop. Configure via options.loops.maxWhileIterations -->';
699
679
  }
700
680
  return result;
701
- `)(...loopValues);
681
+ `)(...loopValues, (offset, value, length) => renderLoopValue(content, offset, value, length));
702
682
  output = output.substring(0, startPos) + result + output.substring(endPos);
703
683
  processedAny = !0;
704
684
  } catch (error) {
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The index of the `}` that starts the `}}` closing a mustache span opened at
3
+ * `openIndex` (the index of its first `{`), or -1 when nothing closes it.
4
+ *
5
+ * Not to be confused with strip-literals' findInterpolationEnd, which closes a
6
+ * JS `${ ... }` interpolation on a single brace.
7
+ *
8
+ * Braces inside the expression are counted and string literals are skipped, so
9
+ * the span is read whole. The matchers here were `/\{\{([\s\S]*?)\}\}/`, which
10
+ * is lazy and knows neither, so ONE level of object nesting ended the
11
+ * expression early:
12
+ *
13
+ * {{ JSON.stringify({a:1}) }} worked
14
+ * {{ JSON.stringify({a:{b:1}}) }} became `JSON.stringify({a:{b:1`
15
+ *
16
+ * The truncated expression failed to evaluate, which yields empty, and the rest
17
+ * of it leaked as literal text -- pages shipped `) }}` where a value belonged,
18
+ * including inside attribute values, with no error and no warning. A `}}` in a
19
+ * string (`{{ "a}}b" }}`) ended it early the same way.
20
+ */
21
+ export declare function findMustacheEnd(input: string, openIndex: number, braces?: number): number;
@@ -0,0 +1,35 @@
1
+ export function findMustacheEnd(input, openIndex, braces = 2) {
2
+ let depth = 0, quote = null;
3
+ for (let i = openIndex + braces;i < input.length; i++) {
4
+ const character = input[i];
5
+ if (quote) {
6
+ if (character === "\\") {
7
+ i++;
8
+ continue;
9
+ }
10
+ if (character === quote)
11
+ quote = null;
12
+ continue;
13
+ }
14
+ if (character === '"' || character === "'" || character === "`") {
15
+ quote = character;
16
+ continue;
17
+ }
18
+ if (character === "{") {
19
+ depth++;
20
+ continue;
21
+ }
22
+ if (character === "}") {
23
+ if (depth > 0) {
24
+ depth--;
25
+ continue;
26
+ }
27
+ let run = 0;
28
+ while (input[i + run] === "}")
29
+ run++;
30
+ if (run >= braces)
31
+ return i;
32
+ }
33
+ }
34
+ return -1;
35
+ }
package/dist/process.js CHANGED
@@ -312,7 +312,7 @@ export async function processDirectives(template, context, filePath, options, de
312
312
  pageHeadTitle = rawTitleMatch[1].trim();
313
313
  pageHeadRaw = pageHeadRaw.replace(rawTitleMatch[0], "").trim();
314
314
  }
315
- const sectionTitle = context.__sections?.title, pageTitle = runtimeHead.title || pageHeadTitle || sectionTitle, titleIsHtml = !runtimeHead.title && (!!pageHeadTitle || !!sectionTitle), runtimeMeta = runtimeHead.meta || [], overriddenMetaKeys = new Set(runtimeMeta.map((m) => metaDedupKey(m)).filter(Boolean)), headConfig = {
315
+ const storedSectionTitle = context.__sections?.title, sectionTitle = storedSectionTitle ? processExpressions(storedSectionTitle, context, filePath) : void 0, pageTitle = runtimeHead.title || pageHeadTitle || sectionTitle, titleIsHtml = !runtimeHead.title && (!!pageHeadTitle || !!sectionTitle), runtimeMeta = runtimeHead.meta || [], overriddenMetaKeys = new Set(runtimeMeta.map((m) => metaDedupKey(m)).filter(Boolean)), headConfig = {
316
316
  ...baseHeadConfig,
317
317
  ...pageTitle && { title: pageTitle },
318
318
  meta: [
@@ -510,7 +510,8 @@ ${output.trim()}
510
510
  const value = safeEvaluate(expr.trim(), context);
511
511
  if (value === void 0)
512
512
  return full;
513
- sections[name] = String(value ?? "");
513
+ const index = (context.__stx_inline_section_values ??= []).push(value) - 1;
514
+ sections[name] = `{{ __stx_inline_section_values[${index}] }}`;
514
515
  return "";
515
516
  } catch {
516
517
  return full;
@@ -736,9 +737,9 @@ async function processOtherDirectives(template, context, filePath, options, depe
736
737
  let output = template;
737
738
  const opts = options;
738
739
  output = await extractServerScriptVariables(output, context, filePath, options);
739
- output = await interpolateClientScriptExpressions(output, context, filePath);
740
740
  output = await processJsDirectives(output, context, filePath);
741
741
  output = await processTsDirectives(output, context, filePath);
742
+ output = await interpolateClientScriptExpressions(output, context, filePath);
742
743
  output = await processCustomDirectives(output, context, filePath, opts);
743
744
  if (usesSignalsInScript(output)) {
744
745
  output = convertSignalDirectivesToAttributes(output, context);
package/dist/pwa.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // @bun
2
- import{or,qe,di,bc}from"./chunk-kvn23sz5.js";import{sr,ds,mc,hc,yc}from"./chunk-3cqxtkqv.js";import{ci,li,ui,fc,gc}from"./chunk-0zr1zxar.js";import{de,Tt,ps}from"./chunk-9yk5rasj.js";import{wl,xl,Sl,kl,Mr,Vd}from"./chunk-2bsrmqr8.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-1vrqmdfe.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{Es,jt,bc,gu}from"./chunk-jkaszw24.js";import{Cs,Xo,du,pu,fu}from"./chunk-np4zm2ph.js";import{mc,hc,yc,lu,uu}from"./chunk-wpmrz872.js";import{Fe,wn,Jo}from"./chunk-wpm58d6p.js";import{mu,hu,yu,bu,Ts,qp}from"./chunk-qv6axke4.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-zyqs6a3p.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=de(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=or(n,t);if(a){let s=qe(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 ds(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,li as auditBuildOutput,ci as auditConfig,re as buildPwaAssets,ui as calculateAuditResult,gc as formatAuditResult,ps as formatSize,j as generateManifest,_ as generateManifestJson,hc as generateManifestLink,F as generateOfflinePage,de as generatePrecacheManifest,Tt as generatePrecacheManifestJs,M as generatePwaIcons,sr as generatePwaTags,or as generateServiceWorker,bc as generateServiceWorkerAuto,mc as generateSwRegistrationScript,yc as generateThemeColorMeta,N as getExpectedIconPaths,qe as getServiceWorkerFileName,ds as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,di as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,Mr as pwaDirectives,wl as pwaInstallDirective,Sl as pwaOfflineDirective,kl as pwaPushDirective,xl as pwaUpdateDirective,Vd as registerPwaDirectives,fc 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=Fe(t,n);o={fileCount:a.fileCount,totalSize:a.totalSize},e.precacheStats=o}try{let a=Es(n,t);if(a){let s=jt(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 Xo(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,hc as auditBuildOutput,mc as auditConfig,re as buildPwaAssets,yc as calculateAuditResult,uu as formatAuditResult,Jo as formatSize,j as generateManifest,_ as generateManifestJson,pu as generateManifestLink,F as generateOfflinePage,Fe as generatePrecacheManifest,wn as generatePrecacheManifestJs,M as generatePwaIcons,Cs as generatePwaTags,Es as generateServiceWorker,gu as generateServiceWorkerAuto,du as generateSwRegistrationScript,fu as generateThemeColorMeta,N as getExpectedIconPaths,jt as getServiceWorkerFileName,Xo as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,bc as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,Ts as pwaDirectives,mu as pwaInstallDirective,yu as pwaOfflineDirective,bu as pwaPushDirective,hu as pwaUpdateDirective,qp as registerPwaDirectives,lu as runPwaAudit,D as validateManifest};
@@ -117,7 +117,7 @@ export async function injectRouterScript(template, options) {
117
117
  if (hasRouterScript(template))
118
118
  return template;
119
119
  const routerConfig = options?.router;
120
- let configScript = "";
120
+ let configScript = "", ownedRoutesScript = "";
121
121
  {
122
122
  const configObj = {};
123
123
  if (routerConfig) {
@@ -155,13 +155,19 @@ export async function injectRouterScript(template, options) {
155
155
  try {
156
156
  const owned = await getOwnedRouteMatchers(options?.pagesDir, options?.root);
157
157
  if (owned.length > 0)
158
- configObj.ownedRoutes = owned;
158
+ if (options?.buildMode === "serve") {
159
+ const { registerServeModuleBundle } = await import("./caching.js");
160
+ ownedRoutesScript = `<script data-stx-owned-routes src="${registerServeModuleBundle(`(window.__stxRouterConfig=window.__stxRouterConfig||{}).ownedRoutes=${toScriptJson(owned)};
161
+ `)}"></script>
162
+ `;
163
+ } else
164
+ configObj.ownedRoutes = owned;
159
165
  } catch {}
160
166
  if (Object.keys(configObj).length > 0)
161
167
  configScript = `<script>window.__stxRouterConfig=${toScriptJson(configObj)};</script>
162
168
  `;
163
169
  }
164
170
  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>");
165
- return template.slice(0, bodyCloseIdx) + configScript + routerScript + `
171
+ return template.slice(0, bodyCloseIdx) + configScript + ownedRoutesScript + routerScript + `
166
172
  </body>` + template.slice(bodyCloseIdx + 7);
167
173
  }
@@ -1,3 +1,5 @@
1
+ import { classifyHtmlInterpolation, UnsafeInterpolationContextError } from "./interpolation-context.js";
2
+ import { escapeAttributeValue, escapeHtmlValue } from "./expressions.js";
1
3
  import { inheritedClientLoopNames, loopBoundNames, readsAnyName } from "./loop-binding.js";
2
4
  import { isRuntimeOwnedColonAttr } from "./runtime-globals.js";
3
5
  const BOOLEAN_ATTRS = new Set([
@@ -104,6 +106,8 @@ export function processServerBindings(template, context) {
104
106
  const nativeHost = /(?:^|\s)data-native(?:\s|=|$)/i.test(attrs.replace(/"[^"]*"|'[^']*'/g, "")), bindingRegex = /\s:([a-zA-Z_][\w-]*)\s*=\s*"([^"]*)"/g;
105
107
  let attrMatch, newAttrs = attrs, hadReplacement = !1;
106
108
  while ((attrMatch = bindingRegex.exec(attrs)) !== null) {
109
+ if (classifyHtmlInterpolation(attrs, attrMatch.index, !0)?.kind === "attribute")
110
+ continue;
107
111
  const attrName = attrMatch[1], expression = attrMatch[2];
108
112
  if (isRuntimeOwnedColonAttr(attrName))
109
113
  continue;
@@ -125,13 +129,13 @@ export function processServerBindings(template, context) {
125
129
  }
126
130
  const value = fn(...contextValues);
127
131
  if (attrName === "class") {
128
- const classStr = resolveClassBinding(value);
132
+ const classStr = escapeHtmlValue(resolveClassBinding(value));
129
133
  if (classStr) {
130
134
  const existingClassMatch = newAttrs.match(/\sclass="([^"]*)"/);
131
135
  if (existingClassMatch)
132
- newAttrs = newAttrs.replace(existingClassMatch[0], ` class="${existingClassMatch[1]} ${classStr}"`);
136
+ newAttrs = newAttrs.replace(existingClassMatch[0], () => ` class="${existingClassMatch[1]} ${classStr}"`);
133
137
  else
134
- newAttrs = newAttrs.replace(attrMatch[0], ` class="${classStr}"`);
138
+ newAttrs = newAttrs.replace(attrMatch[0], () => ` class="${classStr}"`);
135
139
  } else
136
140
  newAttrs = newAttrs.replace(attrMatch[0], "");
137
141
  hadReplacement = !0;
@@ -148,11 +152,13 @@ export function processServerBindings(template, context) {
148
152
  if (value === null || value === void 0 || value === !1)
149
153
  newAttrs = newAttrs.replace(attrMatch[0], "");
150
154
  else {
151
- const escaped = (nativeHost && typeof value === "object" ? JSON.stringify(value) : String(value)).replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
152
- newAttrs = newAttrs.replace(attrMatch[0], ` ${attrName}="${escaped}"`);
155
+ const serialized = nativeHost && typeof value === "object" ? JSON.stringify(value) : String(value), escaped = escapeAttributeValue(attrName, serialized);
156
+ newAttrs = newAttrs.replace(attrMatch[0], () => ` ${attrName}="${escaped}"`);
153
157
  }
154
158
  hadReplacement = !0;
155
- } catch {
159
+ } catch (error) {
160
+ if (error instanceof UnsafeInterpolationContextError)
161
+ throw error;
156
162
  continue;
157
163
  }
158
164
  }