@stacksjs/stx 0.2.644 → 0.2.647

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 (265) 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-1m5cjrpw.js → chunk-04kg16qs.js} +4 -4
  9. package/dist/chunk-0jq3w712.js +65 -0
  10. package/dist/chunk-0ky1j84b.js +2 -0
  11. package/dist/chunk-0m08316b.js +2 -0
  12. package/dist/{chunk-qf210sfx.js → chunk-0z5cc7qn.js} +8 -8
  13. package/dist/{chunk-0ergsswn.js → chunk-120ze5ms.js} +3 -3
  14. package/dist/chunk-1c5p7ede.js +2 -0
  15. package/dist/chunk-1q6yvbdx.js +2 -0
  16. package/dist/chunk-1x4qn6fy.js +2 -0
  17. package/dist/chunk-20f1veqy.js +3 -0
  18. package/dist/chunk-2a4szpje.js +3 -0
  19. package/dist/chunk-2c3w367n.js +2 -0
  20. package/dist/chunk-2cxav9xe.js +2 -0
  21. package/dist/chunk-2f17h17f.js +2 -0
  22. package/dist/{chunk-ktvr45qg.js → chunk-2qbvsvwc.js} +2 -2
  23. package/dist/chunk-2v4s7xtx.js +2 -0
  24. package/dist/chunk-31714f76.js +2 -0
  25. package/dist/chunk-354jmw2k.js +3 -0
  26. package/dist/chunk-3e7haxwt.js +2 -0
  27. package/dist/{chunk-afsf6sp0.js → chunk-3ghbxena.js} +14 -14
  28. package/dist/chunk-40y6mb8t.js +2 -0
  29. package/dist/chunk-42rghbqe.js +12 -0
  30. package/dist/chunk-4fz2eq7g.js +2 -0
  31. package/dist/{chunk-1t0m4pwg.js → chunk-4yf1w261.js} +2 -2
  32. package/dist/chunk-4yt8tg4j.js +2 -0
  33. package/dist/chunk-52gp2xxk.js +2 -0
  34. package/dist/chunk-55x799st.js +49 -0
  35. package/dist/chunk-5e20mvke.js +2 -0
  36. package/dist/chunk-5fzh8n52.js +2 -0
  37. package/dist/chunk-5gtpswnm.js +2 -0
  38. package/dist/{chunk-a0ygyftk.js → chunk-5t4qtxgr.js} +2 -2
  39. package/dist/chunk-5yg3tkth.js +2 -0
  40. package/dist/chunk-67kj14at.js +2 -0
  41. package/dist/{chunk-gqz26wza.js → chunk-6ajahb2x.js} +3 -3
  42. package/dist/chunk-6vzktvyw.js +2 -0
  43. package/dist/chunk-70pmthc3.js +2 -0
  44. package/dist/chunk-74pej67a.js +18 -0
  45. package/dist/{chunk-g1ae3haw.js → chunk-7rta163c.js} +2 -2
  46. package/dist/chunk-7s32fe6k.js +3 -0
  47. package/dist/chunk-84djpte6.js +3 -0
  48. package/dist/chunk-864qtx7y.js +2 -0
  49. package/dist/chunk-8ttg2d3m.js +2 -0
  50. package/dist/{chunk-9yk5rasj.js → chunk-9am6dsb1.js} +3 -3
  51. package/dist/{chunk-5e063mgs.js → chunk-9p6efb17.js} +1 -1
  52. package/dist/chunk-9qeg5trh.js +2 -0
  53. package/dist/chunk-9szxxgv5.js +2 -0
  54. package/dist/{chunk-bsts9pr5.js → chunk-9y2ncrnq.js} +2 -2
  55. package/dist/chunk-9z9jtwct.js +33 -0
  56. package/dist/{chunk-y255yybn.js → chunk-a3d0g4mr.js} +2 -2
  57. package/dist/{chunk-9939fjh4.js → chunk-a8j91pqz.js} +11 -11
  58. package/dist/{chunk-hshcbe3p.js → chunk-aah6csjm.js} +11 -11
  59. package/dist/{chunk-cw8mx4qf.js → chunk-ajv5xmjx.js} +169 -169
  60. package/dist/chunk-apgb7r22.js +2 -0
  61. package/dist/{chunk-c858mepd.js → chunk-aprhqxky.js} +5 -5
  62. package/dist/{chunk-29sq7kqw.js → chunk-ar22s1e1.js} +2 -2
  63. package/dist/chunk-asqnaddf.js +3 -0
  64. package/dist/chunk-aze7k3a5.js +2 -0
  65. package/dist/chunk-b07djygp.js +18 -0
  66. package/dist/chunk-b0vhe6d4.js +4 -0
  67. package/dist/chunk-b4fd2dtk.js +2 -0
  68. package/dist/chunk-bk96wjaz.js +61 -0
  69. package/dist/chunk-c7fs96n6.js +4 -0
  70. package/dist/chunk-c9k40352.js +2 -0
  71. package/dist/{chunk-ahyq08mp.js → chunk-ce6zddpf.js} +3 -3
  72. package/dist/{chunk-cpxtmmvv.js → chunk-cj2xj1v6.js} +39 -40
  73. package/dist/chunk-cs0dd5w8.js +2 -0
  74. package/dist/chunk-cwd65649.js +2 -0
  75. package/dist/{chunk-2s3sxt48.js → chunk-da7x7y7j.js} +1 -1
  76. package/dist/{chunk-wjq1wqn6.js → chunk-dgb4z4kw.js} +2 -2
  77. package/dist/chunk-dpjnjs09.js +888 -0
  78. package/dist/chunk-e7sg0fa0.js +2 -0
  79. package/dist/chunk-edz1h5f9.js +2 -0
  80. package/dist/chunk-egg54kd0.js +12 -0
  81. package/dist/chunk-ek2adv0n.js +2 -0
  82. package/dist/chunk-emaexvgz.js +2 -0
  83. package/dist/{chunk-pp6ycfay.js → chunk-ewcrsyr7.js} +2 -2
  84. package/dist/chunk-fcn71bq1.js +2 -0
  85. package/dist/{chunk-dcwhp21g.js → chunk-fg3jw17w.js} +48 -48
  86. package/dist/chunk-fygp3cs9.js +2 -0
  87. package/dist/chunk-g2jmwh7p.js +2 -0
  88. package/dist/chunk-g8r0km7g.js +106 -0
  89. package/dist/{chunk-gmxrckgj.js → chunk-gc9ftf7r.js} +3 -3
  90. package/dist/chunk-ggwm8w5m.js +2 -0
  91. package/dist/chunk-h5zr710w.js +2 -0
  92. package/dist/chunk-hgy4c6mm.js +11 -0
  93. package/dist/chunk-hvtzw1jh.js +2 -0
  94. package/dist/{chunk-4n24jbfs.js → chunk-hvzzhkhr.js} +2 -2
  95. package/dist/chunk-j0v970k3.js +2 -0
  96. package/dist/chunk-jk41jwsc.js +2 -0
  97. package/dist/{chunk-6mnwvn9v.js → chunk-jkvr7e91.js} +2 -2
  98. package/dist/{chunk-639ngkgb.js → chunk-jsb4pvj1.js} +2 -2
  99. package/dist/{chunk-pf5s5gjp.js → chunk-jx3wpgv0.js} +2 -2
  100. package/dist/{chunk-fztvkacg.js → chunk-jxda11cg.js} +2 -2
  101. package/dist/chunk-jyth1zjy.js +127 -0
  102. package/dist/chunk-k2pa44rf.js +2 -0
  103. package/dist/{chunk-kad2cp0z.js → chunk-k79x96ra.js} +37 -37
  104. package/dist/{chunk-qy11cp1v.js → chunk-kgfgb971.js} +4 -4
  105. package/dist/chunk-ma7d95f0.js +31 -0
  106. package/dist/chunk-mmm6mm16.js +3 -0
  107. package/dist/{chunk-88p10v0w.js → chunk-mmwedr93.js} +5 -5
  108. package/dist/{chunk-dyg6sadv.js → chunk-mrrrngzd.js} +1 -1
  109. package/dist/{chunk-w41kp60h.js → chunk-msr25dhc.js} +4 -4
  110. package/dist/chunk-myq3hrww.js +6 -0
  111. package/dist/{chunk-fwdptew6.js → chunk-n38yb274.js} +6 -6
  112. package/dist/chunk-n4cvg2sw.js +2 -0
  113. package/dist/chunk-nph4d1ff.js +42 -0
  114. package/dist/{chunk-aztp8r80.js → chunk-nrvwejdw.js} +5 -5
  115. package/dist/{chunk-17x6e5mm.js → chunk-p08x0z86.js} +7 -7
  116. package/dist/chunk-p22w6mwr.js +2 -0
  117. package/dist/{chunk-xsmvcnmx.js → chunk-pdc9s7bg.js} +2 -2
  118. package/dist/chunk-pfk9ffbz.js +3 -0
  119. package/dist/{chunk-pvfx0dgz.js → chunk-prf164ct.js} +2 -2
  120. package/dist/chunk-pw9bhdaz.js +4 -0
  121. package/dist/chunk-qn63btbf.js +2 -0
  122. package/dist/{chunk-eyy6zmdk.js → chunk-qv6axke4.js} +2 -2
  123. package/dist/{chunk-60azcvwr.js → chunk-r3e6x87d.js} +3 -3
  124. package/dist/chunk-rb5xdcen.js +25 -0
  125. package/dist/{chunk-45xhjrha.js → chunk-rcadtv3x.js} +1 -1
  126. package/dist/{chunk-j00v4m56.js → chunk-rjh2jwxx.js} +9 -9
  127. package/dist/chunk-rwrbdpdk.js +2 -0
  128. package/dist/chunk-sf0wsq74.js +2 -0
  129. package/dist/chunk-shkysa02.js +20 -0
  130. package/dist/chunk-shpc1ttk.js +2 -0
  131. package/dist/{chunk-48yja477.js → chunk-t2pzy3x1.js} +3 -3
  132. package/dist/chunk-t6yjxhn8.js +2 -0
  133. package/dist/chunk-tkkvvt26.js +2 -0
  134. package/dist/{chunk-b4j5bpec.js → chunk-tre98h62.js} +2 -2
  135. package/dist/chunk-vac56rgd.js +12 -0
  136. package/dist/chunk-vdxjy7j2.js +4 -0
  137. package/dist/{chunk-gsp3627d.js → chunk-vgt9f7ac.js} +4 -4
  138. package/dist/{chunk-vq4sh8aq.js → chunk-vmwdt8fr.js} +5 -5
  139. package/dist/chunk-vn3yx05b.js +2 -0
  140. package/dist/{chunk-fqg0espy.js → chunk-vqc4h16r.js} +2 -2
  141. package/dist/chunk-w1v1d7rq.js +406 -0
  142. package/dist/chunk-w2q32x72.js +2 -0
  143. package/dist/chunk-weqc0ssb.js +2 -0
  144. package/dist/{chunk-kjspmegt.js → chunk-wpmrz872.js} +2 -2
  145. package/dist/chunk-wq712sw1.js +2 -0
  146. package/dist/chunk-wzgn9fv7.js +20 -0
  147. package/dist/{chunk-s775b8ra.js → chunk-x8k64g1e.js} +2 -2
  148. package/dist/chunk-xaa36b0x.js +3 -0
  149. package/dist/chunk-xnjf1zbn.js +21 -0
  150. package/dist/chunk-xyjn0rvj.js +3 -0
  151. package/dist/chunk-y3vget29.js +2 -0
  152. package/dist/chunk-y9x4pyp2.js +2 -0
  153. package/dist/chunk-yfrvbnc6.js +1312 -0
  154. package/dist/{chunk-drrczm0b.js → chunk-ym41ybz2.js} +6 -6
  155. package/dist/chunk-z8p6tk5z.js +2 -0
  156. package/dist/{chunk-gbxzqvez.js → chunk-zevx9866.js} +2 -2
  157. package/dist/chunk-zhf01af3.js +3 -0
  158. package/dist/{chunk-6avpd901.js → chunk-zqtbtqbq.js} +2 -2
  159. package/dist/chunk-ztbzktzg.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 +69 -28
  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/native-build.d.ts +5 -0
  174. package/dist/native-build.js +11 -27
  175. package/dist/process.js +4 -3
  176. package/dist/pwa.js +3 -3
  177. package/dist/server-bindings.js +12 -6
  178. package/dist/ssg.js +28 -28
  179. package/dist/utils.js +1 -2
  180. package/package.json +5 -5
  181. package/dist/chunk-12677ap2.js +0 -31
  182. package/dist/chunk-162gprh9.js +0 -2
  183. package/dist/chunk-1p6yd17s.js +0 -2
  184. package/dist/chunk-29gd2kkk.js +0 -20
  185. package/dist/chunk-3hkp5hym.js +0 -2
  186. package/dist/chunk-3jrssj8g.js +0 -2
  187. package/dist/chunk-444pz8yk.js +0 -2
  188. package/dist/chunk-47shfmkf.js +0 -3
  189. package/dist/chunk-4b5f28te.js +0 -2
  190. package/dist/chunk-4dpq1bnh.js +0 -2
  191. package/dist/chunk-4mm9ttc7.js +0 -2
  192. package/dist/chunk-5c511mj0.js +0 -2
  193. package/dist/chunk-5kbkx0np.js +0 -3
  194. package/dist/chunk-5wyp57g3.js +0 -4
  195. package/dist/chunk-6bdr0x43.js +0 -18
  196. package/dist/chunk-6vmvra0f.js +0 -65
  197. package/dist/chunk-70et0fbw.js +0 -12
  198. package/dist/chunk-7mkw98cr.js +0 -3
  199. package/dist/chunk-7qgsgfnt.js +0 -2
  200. package/dist/chunk-87kza2ez.js +0 -2
  201. package/dist/chunk-8bk1ghb7.js +0 -127
  202. package/dist/chunk-8cqx63aw.js +0 -3
  203. package/dist/chunk-8k5eac6p.js +0 -2
  204. package/dist/chunk-9nvrkpee.js +0 -2
  205. package/dist/chunk-9ny6xzw0.js +0 -2
  206. package/dist/chunk-9r538d93.js +0 -2
  207. package/dist/chunk-9xaztqhw.js +0 -2
  208. package/dist/chunk-b2teprjf.js +0 -2
  209. package/dist/chunk-bnfjwgtm.js +0 -20
  210. package/dist/chunk-br7xk2hb.js +0 -2
  211. package/dist/chunk-c8p5jwdq.js +0 -2
  212. package/dist/chunk-cd76dwdn.js +0 -2
  213. package/dist/chunk-degxqdbb.js +0 -2
  214. package/dist/chunk-dr4325et.js +0 -2
  215. package/dist/chunk-e7bd4vxb.js +0 -2
  216. package/dist/chunk-eh7qq39j.js +0 -2
  217. package/dist/chunk-ek5vrw4r.js +0 -2
  218. package/dist/chunk-erweevv2.js +0 -2
  219. package/dist/chunk-fdxyj3pk.js +0 -2
  220. package/dist/chunk-ft3r2rzs.js +0 -2
  221. package/dist/chunk-fywp8fcr.js +0 -2
  222. package/dist/chunk-g14mwhqz.js +0 -2
  223. package/dist/chunk-g6s0xdgb.js +0 -4
  224. package/dist/chunk-grg366m9.js +0 -2852
  225. package/dist/chunk-h3brvxbf.js +0 -3
  226. package/dist/chunk-hbk20w21.js +0 -2
  227. package/dist/chunk-hrdnz5q9.js +0 -2
  228. package/dist/chunk-hvk5zkpm.js +0 -4
  229. package/dist/chunk-j0jz4mfm.js +0 -2
  230. package/dist/chunk-j37720vw.js +0 -2
  231. package/dist/chunk-j6fxzkn5.js +0 -2
  232. package/dist/chunk-ja3m0h9h.js +0 -12
  233. package/dist/chunk-jmdrhpy7.js +0 -2
  234. package/dist/chunk-jshv1ye7.js +0 -2
  235. package/dist/chunk-jtk2p5p0.js +0 -2
  236. package/dist/chunk-k46gqnmk.js +0 -2
  237. package/dist/chunk-ktjvqwp4.js +0 -2
  238. package/dist/chunk-kv5mn1qr.js +0 -6
  239. package/dist/chunk-kxbw0e2f.js +0 -3
  240. package/dist/chunk-ky043mkv.js +0 -2
  241. package/dist/chunk-m2bnyrft.js +0 -2
  242. package/dist/chunk-m92q2jyt.js +0 -40
  243. package/dist/chunk-mbqqc20a.js +0 -2
  244. package/dist/chunk-mqmxhggf.js +0 -2
  245. package/dist/chunk-myq0m4h4.js +0 -2
  246. package/dist/chunk-nkgzwyad.js +0 -2
  247. package/dist/chunk-ns4pc13z.js +0 -2
  248. package/dist/chunk-nv9syzs0.js +0 -2
  249. package/dist/chunk-pn719qwa.js +0 -2
  250. package/dist/chunk-qmh6f1bt.js +0 -24
  251. package/dist/chunk-r00nn2qs.js +0 -4
  252. package/dist/chunk-re2mry1d.js +0 -2
  253. package/dist/chunk-s0tbc9t1.js +0 -33
  254. package/dist/chunk-s7e9ztgq.js +0 -2
  255. package/dist/chunk-t6awky15.js +0 -11
  256. package/dist/chunk-tcq0me7c.js +0 -2
  257. package/dist/chunk-vse0hhn9.js +0 -2
  258. package/dist/chunk-vvgs62za.js +0 -2
  259. package/dist/chunk-wj4rf7sb.js +0 -2
  260. package/dist/chunk-x901zq4q.js +0 -2
  261. package/dist/chunk-xe8qmf1d.js +0 -2
  262. package/dist/chunk-xqtzk9wr.js +0 -2
  263. package/dist/chunk-y51ndrdb.js +0 -2
  264. package/dist/chunk-yn2d8x8m.js +0 -3
  265. package/dist/chunk-zrngcg6r.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
+ }
@@ -3,6 +3,11 @@ import { type MacOSSigningOptions } from './native-signing';
3
3
  * Build an stx template into a native application
4
4
  */
5
5
  export declare function buildNative(config: NativeBuildConfig): Promise<NativeBuildResult>;
6
+ /**
7
+ * Use the Pantry runtime on PATH, with an explicit development override.
8
+ * A nearby source checkout must never silently replace an installed release.
9
+ */
10
+ export declare function findCraftBinary(): string | null;
6
11
  /**
7
12
  * Detect current platform
8
13
  */
@@ -1,7 +1,7 @@
1
1
  var {require}=import.meta;import { existsSync, mkdirSync, copyFileSync, chmodSync, rmSync } from "node:fs";
2
2
  import { join, dirname, basename, resolve } from "node:path";
3
- import { spawn, execSync } from "node:child_process";
4
- import { homedir, platform as osPlatform } from "node:os";
3
+ import { spawn } from "node:child_process";
4
+ import { platform as osPlatform } from "node:os";
5
5
  import { injectCraftBridge } from "./craft-bridge.js";
6
6
  import { processCraftComponents, CRAFT_COMPONENT_STYLES } from "./craft-components.js";
7
7
  import { renderTemplate } from "./render.js";
@@ -42,7 +42,7 @@ export async function buildNative(config) {
42
42
  success: !1,
43
43
  target,
44
44
  format,
45
- error: "Craft binary not found. Please install Craft or specify craftPath."
45
+ error: "Craft native binary not found on PATH. Run pantry install craft, or specify craftPath for framework development."
46
46
  };
47
47
  if (config.verbose) {
48
48
  console.log(`\uD83D\uDCE6 Building native app for ${target}...`);
@@ -368,30 +368,14 @@ async function buildAndroid(_html, appName, _appVersion, _outputDir, _config, _c
368
368
  error: `Android build requires Android SDK and additional setup. Use 'stx init:android ${appName}' to create an Android project.`
369
369
  };
370
370
  }
371
- async function findCraftBinary() {
372
- if (process.env.CRAFT_BIN && await Bun.file(process.env.CRAFT_BIN).exists())
373
- return process.env.CRAFT_BIN;
374
- const possiblePaths = [
375
- join(process.cwd(), "../../craft/packages/zig/zig-out/bin/craft"),
376
- join(process.cwd(), "../craft/packages/zig/zig-out/bin/craft"),
377
- join(homedir(), "Code/Tools/craft/packages/zig/zig-out/bin/craft"),
378
- join(homedir(), "Code/craft/packages/zig/zig-out/bin/craft"),
379
- "/usr/local/bin/craft",
380
- "/usr/bin/craft",
381
- join(homedir(), ".local/bin/craft"),
382
- join(process.env.LOCALAPPDATA || "", "craft", "craft.exe"),
383
- join(process.env.PROGRAMFILES || "", "craft", "craft.exe")
384
- ];
385
- for (const path of possiblePaths)
386
- if (await Bun.file(path).exists())
387
- return path;
388
- try {
389
- const craftPath = execSync("which craft 2>/dev/null || where craft 2>nul", { encoding: "utf-8" }).trim().split(`
390
- `)[0];
391
- if (craftPath && await Bun.file(craftPath).exists())
392
- return craftPath;
393
- } catch {}
394
- return null;
371
+ export function findCraftBinary() {
372
+ const explicit = process.env.CRAFT_BIN;
373
+ if (explicit) {
374
+ if (!existsSync(explicit))
375
+ throw Error(`CRAFT_BIN points to a missing file: ${explicit}`);
376
+ return explicit;
377
+ }
378
+ return Bun.which("craft", { PATH: process.env.PATH ?? "", cwd: process.cwd() });
395
379
  }
396
380
  function detectPlatform() {
397
381
  switch (osPlatform()) {
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,ui,yc}from"./chunk-w41kp60h.js";import{sr,ds,gc,mc,hc}from"./chunk-17x6e5mm.js";import{ai,ci,li,pc,fc}from"./chunk-kjspmegt.js";import{de,Tt,ps}from"./chunk-9yk5rasj.js";import{vl,wl,xl,Sl,Mr,Hd}from"./chunk-eyy6zmdk.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-dr4325et.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-msr25dhc.js";import{Cs,Xo,du,pu,fu}from"./chunk-p08x0z86.js";import{mc,hc,yc,lu,uu}from"./chunk-wpmrz872.js";import{Be,wn,Jo}from"./chunk-9am6dsb1.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-cs0dd5w8.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,ci as auditBuildOutput,ai as auditConfig,re as buildPwaAssets,li as calculateAuditResult,fc as formatAuditResult,ps as formatSize,j as generateManifest,_ as generateManifestJson,mc as generateManifestLink,F as generateOfflinePage,de as generatePrecacheManifest,Tt as generatePrecacheManifestJs,M as generatePwaIcons,sr as generatePwaTags,or as generateServiceWorker,yc as generateServiceWorkerAuto,gc as generateSwRegistrationScript,hc as generateThemeColorMeta,N as getExpectedIconPaths,qe as getServiceWorkerFileName,ds as injectPwaTags,se as isPwaEnabled,I as isSharpAvailable,ui as isWorkboxEnabled,q as mergeManifestConfig,ae as processPwaHtml,Mr as pwaDirectives,vl as pwaInstallDirective,xl as pwaOfflineDirective,Sl as pwaPushDirective,wl as pwaUpdateDirective,Hd as registerPwaDirectives,pc 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=Be(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,Be 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};
@@ -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
  }