@stacksjs/stx 0.2.760 → 0.2.762

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 (249) hide show
  1. package/dist/chunk-00nz3pas.js +2 -0
  2. package/dist/{chunk-eazvp48w.js → chunk-02c46de1.js} +26 -9
  3. package/dist/chunk-05jdq9tw.js +177 -0
  4. package/dist/chunk-0cajfv7y.js +2 -0
  5. package/dist/{chunk-3nxe5xmy.js → chunk-0fs9kx0h.js} +3 -3
  6. package/dist/{chunk-42hcspws.js → chunk-0kq0k4pg.js} +2 -2
  7. package/dist/{chunk-y8srg0q3.js → chunk-0sd4td6z.js} +3 -3
  8. package/dist/{chunk-f4gqzg1y.js → chunk-0wj31pqy.js} +2 -2
  9. package/dist/chunk-13v3vgb6.js +2 -0
  10. package/dist/{chunk-v5afjcy3.js → chunk-18chz0q4.js} +1 -1
  11. package/dist/chunk-1p8t2ekg.js +2 -0
  12. package/dist/chunk-1rcntvgx.js +2 -0
  13. package/dist/chunk-1w5gtkd6.js +2 -0
  14. package/dist/chunk-28vtqwxh.js +2 -0
  15. package/dist/chunk-298gj90a.js +2 -0
  16. package/dist/{chunk-n8s5301s.js → chunk-2eamszdq.js} +2 -2
  17. package/dist/chunk-2gn6smrq.js +2 -0
  18. package/dist/{chunk-h692k9xn.js → chunk-2typf9dh.js} +4 -4
  19. package/dist/chunk-2wq0h5ye.js +2 -0
  20. package/dist/{chunk-prej5pk6.js → chunk-2zd51tj4.js} +2 -2
  21. package/dist/chunk-2zg3jmy7.js +2 -0
  22. package/dist/{chunk-ztdjdxjt.js → chunk-319aez2f.js} +3 -3
  23. package/dist/{chunk-7g9vd5fv.js → chunk-37y8sg48.js} +2 -2
  24. package/dist/{chunk-j2mpqa4p.js → chunk-3csfmhg0.js} +2 -2
  25. package/dist/{chunk-jb1dk0w7.js → chunk-3mz088mb.js} +2 -2
  26. package/dist/chunk-3wxb7mfb.js +2 -0
  27. package/dist/{chunk-cehjp06v.js → chunk-42zqmcnc.js} +3 -3
  28. package/dist/{chunk-89h4snzd.js → chunk-4833k99b.js} +2 -2
  29. package/dist/{chunk-jevd16gq.js → chunk-48g9wez2.js} +30 -30
  30. package/dist/chunk-4tgn1frg.js +3 -0
  31. package/dist/chunk-528cn6qm.js +2 -0
  32. package/dist/{chunk-afj19nsj.js → chunk-59k4xb92.js} +5 -5
  33. package/dist/chunk-5x0g7e9y.js +2 -0
  34. package/dist/{chunk-83ezv8yz.js → chunk-5yhv5eqq.js} +3 -3
  35. package/dist/chunk-633a53wg.js +2 -0
  36. package/dist/chunk-6b737vch.js +2 -0
  37. package/dist/chunk-72ns4q88.js +2 -0
  38. package/dist/chunk-736ex6r5.js +26 -0
  39. package/dist/chunk-86cg9qqm.js +2 -0
  40. package/dist/{chunk-gs6wc7sr.js → chunk-89801pjp.js} +5 -5
  41. package/dist/chunk-8czxtjwm.js +2 -0
  42. package/dist/chunk-8h5mqs28.js +2 -0
  43. package/dist/{chunk-yp6w740k.js → chunk-8rk79ha1.js} +2 -2
  44. package/dist/{chunk-kpr09x3g.js → chunk-8y54tpbr.js} +7 -7
  45. package/dist/{chunk-s4y26fk6.js → chunk-8yyq3nfg.js} +2 -2
  46. package/dist/{chunk-30j6mbrf.js → chunk-932zx5q4.js} +7 -7
  47. package/dist/chunk-940wny2b.js +2 -0
  48. package/dist/chunk-9fh4ah7t.js +2 -0
  49. package/dist/{chunk-sgm6tg8h.js → chunk-9k8ztdcc.js} +2 -2
  50. package/dist/{chunk-vvc39v6p.js → chunk-a222bwpc.js} +5 -5
  51. package/dist/chunk-a81rt2t4.js +3 -0
  52. package/dist/chunk-ad9dt9rk.js +2 -0
  53. package/dist/chunk-ak4w2emd.js +2 -0
  54. package/dist/{chunk-tb56j1zt.js → chunk-ak93e1zz.js} +5 -5
  55. package/dist/{chunk-jt28zh50.js → chunk-b0z2n941.js} +2 -2
  56. package/dist/{chunk-xgegyttg.js → chunk-b51p56k5.js} +2 -2
  57. package/dist/{chunk-r4sawwmp.js → chunk-b7x8b83z.js} +1 -1
  58. package/dist/chunk-b8dtz3v8.js +2 -0
  59. package/dist/{chunk-frk6rzrq.js → chunk-ben8bjnk.js} +4 -4
  60. package/dist/{chunk-w8p1y4c0.js → chunk-bvctccab.js} +4 -4
  61. package/dist/{chunk-hk98vptc.js → chunk-cdcrd33m.js} +2 -2
  62. package/dist/chunk-cenvzm5q.js +2 -0
  63. package/dist/chunk-d49pst1m.js +2 -0
  64. package/dist/{chunk-hfbzfrpv.js → chunk-d96xddt9.js} +14 -14
  65. package/dist/chunk-dj0qy19b.js +2 -0
  66. package/dist/{chunk-asp7ett1.js → chunk-dnsf934e.js} +9 -9
  67. package/dist/{chunk-7r7j7vwt.js → chunk-ds6mbfdq.js} +3 -3
  68. package/dist/{chunk-bsgg8zzk.js → chunk-dvpk4c1y.js} +2 -2
  69. package/dist/chunk-e2q79dfs.js +2 -0
  70. package/dist/{chunk-9s1qnf90.js → chunk-eb6p3p62.js} +2 -2
  71. package/dist/chunk-ebxncrd8.js +2 -0
  72. package/dist/{chunk-q49ykyq9.js → chunk-edhxg3rz.js} +14 -14
  73. package/dist/{chunk-rcfmwx8r.js → chunk-epa73jvs.js} +2 -2
  74. package/dist/{chunk-3cn9y08d.js → chunk-evxp3wmv.js} +7 -7
  75. package/dist/{chunk-z8k3fx4r.js → chunk-f8p8ggvw.js} +4 -4
  76. package/dist/{chunk-se28p2xy.js → chunk-fhpsf4z7.js} +6 -6
  77. package/dist/chunk-fht1zs1r.js +2 -0
  78. package/dist/chunk-fjfrgef4.js +2 -0
  79. package/dist/chunk-fmk9hjht.js +2 -0
  80. package/dist/{chunk-4s9kytdz.js → chunk-fxmc5006.js} +2 -2
  81. package/dist/chunk-fxnk5ee8.js +2 -0
  82. package/dist/{chunk-6ts3sthp.js → chunk-g4k0svq6.js} +2 -2
  83. package/dist/{chunk-2qz891k4.js → chunk-gwjh981q.js} +10 -10
  84. package/dist/chunk-hnen9b45.js +2 -0
  85. package/dist/{chunk-7v2srnpv.js → chunk-j1tsda22.js} +10 -10
  86. package/dist/chunk-j1z7tgdp.js +2 -0
  87. package/dist/{chunk-4zw118tn.js → chunk-jgk5j35w.js} +4 -4
  88. package/dist/chunk-jq1698j4.js +2 -0
  89. package/dist/{chunk-pwmkhs7z.js → chunk-jyp2mmts.js} +2 -2
  90. package/dist/chunk-k0jkpw0q.js +2 -0
  91. package/dist/{chunk-3kfbs0mw.js → chunk-k2ex94n8.js} +1 -1
  92. package/dist/chunk-k469ym7a.js +2 -0
  93. package/dist/{chunk-m00c7sh0.js → chunk-k9247v28.js} +1 -1
  94. package/dist/{chunk-rprewgyj.js → chunk-k9wr8xf5.js} +6 -6
  95. package/dist/chunk-m3z13f59.js +25 -0
  96. package/dist/chunk-m5740sd3.js +2 -0
  97. package/dist/{chunk-qw9kgzb3.js → chunk-m6rzsbas.js} +5 -5
  98. package/dist/{chunk-5vmbycy5.js → chunk-mbe4gqd3.js} +2 -2
  99. package/dist/{chunk-myynywry.js → chunk-mdvtermb.js} +2 -2
  100. package/dist/chunk-mdw96yhg.js +2 -0
  101. package/dist/chunk-mebf9vwb.js +2 -0
  102. package/dist/{chunk-ej1jkt9a.js → chunk-nm9tnxnw.js} +6 -6
  103. package/dist/chunk-p2se8s6r.js +2 -0
  104. package/dist/chunk-p7zrz0wb.js +2 -0
  105. package/dist/chunk-pdnyfk2v.js +2 -0
  106. package/dist/{chunk-fjxhga6w.js → chunk-pqbxa0r7.js} +2 -2
  107. package/dist/chunk-q245q8z1.js +2 -0
  108. package/dist/{chunk-5q9ss7ty.js → chunk-q3azy64b.js} +4 -4
  109. package/dist/chunk-qfhjtz2q.js +2 -0
  110. package/dist/chunk-qjbcp3tc.js +33 -0
  111. package/dist/{chunk-qwsgc5rc.js → chunk-qystt1qc.js} +1 -1
  112. package/dist/{chunk-dh9aagwm.js → chunk-r1tp2gnr.js} +1 -1
  113. package/dist/chunk-r5tsewzd.js +2 -0
  114. package/dist/{chunk-pes27snj.js → chunk-r8zhed35.js} +3 -3
  115. package/dist/{chunk-g4e6egrr.js → chunk-rd33qkfs.js} +8 -8
  116. package/dist/{chunk-hmydy949.js → chunk-rh2qth8r.js} +5 -5
  117. package/dist/chunk-rha8sv1h.js +3 -0
  118. package/dist/{chunk-n7s4n62j.js → chunk-rj3p5fdy.js} +3 -3
  119. package/dist/{chunk-94ymndc5.js → chunk-rmk8efc3.js} +43 -43
  120. package/dist/chunk-rnvrtcz6.js +2 -0
  121. package/dist/{chunk-xsf7ax50.js → chunk-rqd6b2nc.js} +3 -3
  122. package/dist/{chunk-vtv7165t.js → chunk-rxm1mjkb.js} +2 -2
  123. package/dist/chunk-s36cpnxa.js +2 -0
  124. package/dist/{chunk-0y2zzqsq.js → chunk-t1shvfhm.js} +76 -76
  125. package/dist/{chunk-vh1d5eqk.js → chunk-t2cq4bpe.js} +6 -6
  126. package/dist/chunk-tfy1m821.js +2 -0
  127. package/dist/{chunk-465resq9.js → chunk-tpfxvw4q.js} +17 -17
  128. package/dist/{chunk-t6qn1374.js → chunk-tshpcvcy.js} +2 -2
  129. package/dist/chunk-v1ff2dfp.js +7 -0
  130. package/dist/chunk-vc3ppphz.js +2 -0
  131. package/dist/chunk-vttx66q0.js +2 -0
  132. package/dist/chunk-vxs07119.js +2 -0
  133. package/dist/chunk-w2pch5xn.js +4 -0
  134. package/dist/{chunk-j4snweyz.js → chunk-wby7qzha.js} +3 -3
  135. package/dist/{chunk-19safa6y.js → chunk-wmnzapn8.js} +2 -2
  136. package/dist/chunk-wwnqbv9j.js +3 -0
  137. package/dist/chunk-x1x69g3s.js +2 -0
  138. package/dist/{chunk-gs373714.js → chunk-x5seqmrv.js} +2 -2
  139. package/dist/chunk-x8hz5gzb.js +2 -0
  140. package/dist/chunk-xfdtym3s.js +2 -0
  141. package/dist/{chunk-q9npggak.js → chunk-xgnmgjpv.js} +8 -8
  142. package/dist/{chunk-bsq9zg9j.js → chunk-xt034729.js} +6 -6
  143. package/dist/{chunk-m220n98m.js → chunk-xtwc2dbk.js} +2 -2
  144. package/dist/{chunk-0ggwm837.js → chunk-y4mp1rra.js} +101 -101
  145. package/dist/chunk-y6mqq78g.js +2 -0
  146. package/dist/chunk-y8pftjg8.js +12 -0
  147. package/dist/{chunk-wz5m7ybz.js → chunk-yb71b2d6.js} +2 -2
  148. package/dist/chunk-ycttwgpg.js +2 -0
  149. package/dist/chunk-yd6x9226.js +2 -0
  150. package/dist/{chunk-3m9vrhja.js → chunk-yk456jp4.js} +8 -8
  151. package/dist/chunk-yn3kff5k.js +2 -0
  152. package/dist/chunk-ynjm2tm0.js +2 -0
  153. package/dist/{chunk-j04v4rgf.js → chunk-zhrz4zvw.js} +5 -5
  154. package/dist/chunk-zpjdp0he.js +2 -0
  155. package/dist/cli.js +20 -20
  156. package/dist/client/signals-hydration-audit-runtime.js +2 -0
  157. package/dist/client/signals-process-element-runtime.js +17 -2
  158. package/dist/composable-loader.d.ts +1 -1
  159. package/dist/composable-loader.js +47 -10
  160. package/dist/composables/index.d.ts +3 -0
  161. package/dist/composables/index.js +1 -0
  162. package/dist/composables/use-completion.d.ts +29 -0
  163. package/dist/composables/use-completion.js +125 -0
  164. package/dist/craft-entry.js +2 -2
  165. package/dist/craft.js +2 -2
  166. package/dist/message-catalogs.d.ts +39 -0
  167. package/dist/message-catalogs.js +128 -0
  168. package/dist/native/compiler/bundle.js +3 -33
  169. package/dist/process.d.ts +1 -1
  170. package/dist/process.js +87 -22
  171. package/dist/pwa.js +3 -3
  172. package/dist/ssg.js +14 -14
  173. package/dist/store-loader.d.ts +27 -3
  174. package/dist/store-loader.js +115 -10
  175. package/dist/types/config-types.d.ts +1 -0
  176. package/dist/unresolved-identifiers.js +1 -0
  177. package/package.json +5 -5
  178. package/dist/chunk-0b7f2mby.js +0 -2
  179. package/dist/chunk-0j7e56zm.js +0 -2
  180. package/dist/chunk-1khg5vjs.js +0 -2
  181. package/dist/chunk-3h2yz805.js +0 -2
  182. package/dist/chunk-3kmwgpm1.js +0 -2
  183. package/dist/chunk-3wfewscj.js +0 -2
  184. package/dist/chunk-4tz00fkp.js +0 -2
  185. package/dist/chunk-52q8184e.js +0 -2
  186. package/dist/chunk-59ytzyp1.js +0 -2
  187. package/dist/chunk-5e2ez5n0.js +0 -2
  188. package/dist/chunk-6ndeycxk.js +0 -2
  189. package/dist/chunk-75r09rqt.js +0 -2
  190. package/dist/chunk-76679dw7.js +0 -33
  191. package/dist/chunk-7h5d35bf.js +0 -2
  192. package/dist/chunk-7kac7hdw.js +0 -2
  193. package/dist/chunk-7nz28a6c.js +0 -16
  194. package/dist/chunk-82ybmdqk.js +0 -2
  195. package/dist/chunk-8av44gw2.js +0 -2
  196. package/dist/chunk-8frs2dtp.js +0 -2
  197. package/dist/chunk-8prq9t3b.js +0 -2
  198. package/dist/chunk-8sxngenk.js +0 -2
  199. package/dist/chunk-9epeb4sn.js +0 -2
  200. package/dist/chunk-9zmb7dcv.js +0 -2
  201. package/dist/chunk-abs1k04e.js +0 -2
  202. package/dist/chunk-akgt21vw.js +0 -2
  203. package/dist/chunk-b561wv5x.js +0 -2
  204. package/dist/chunk-bfdd0nmc.js +0 -2
  205. package/dist/chunk-c05r0rzw.js +0 -3
  206. package/dist/chunk-c7yjhjr2.js +0 -2
  207. package/dist/chunk-c9xq89nt.js +0 -2
  208. package/dist/chunk-cpep999n.js +0 -2
  209. package/dist/chunk-cr7mn65s.js +0 -2
  210. package/dist/chunk-dqs4bgec.js +0 -2
  211. package/dist/chunk-e30kgg28.js +0 -2
  212. package/dist/chunk-e3fkq9gb.js +0 -2
  213. package/dist/chunk-e9kajy9a.js +0 -2
  214. package/dist/chunk-eab8na0z.js +0 -2
  215. package/dist/chunk-ec5q50ve.js +0 -2
  216. package/dist/chunk-ec8gn2m0.js +0 -2
  217. package/dist/chunk-ex2397dc.js +0 -2
  218. package/dist/chunk-exg7ry7b.js +0 -2
  219. package/dist/chunk-f4j42tsg.js +0 -2
  220. package/dist/chunk-fj105fff.js +0 -2
  221. package/dist/chunk-gk775pcy.js +0 -177
  222. package/dist/chunk-ha6tr22a.js +0 -2
  223. package/dist/chunk-htc7pasb.js +0 -2
  224. package/dist/chunk-jfvr1135.js +0 -2
  225. package/dist/chunk-k3wnmpt3.js +0 -2
  226. package/dist/chunk-kb8654dp.js +0 -4
  227. package/dist/chunk-kfqdx75m.js +0 -2
  228. package/dist/chunk-mmdfjmgk.js +0 -25
  229. package/dist/chunk-mreh1t5x.js +0 -2
  230. package/dist/chunk-n839v6az.js +0 -2
  231. package/dist/chunk-ptzzpf97.js +0 -2
  232. package/dist/chunk-py7g5hxd.js +0 -2
  233. package/dist/chunk-qgsrxyh9.js +0 -2
  234. package/dist/chunk-qmxcs806.js +0 -2
  235. package/dist/chunk-qvcs4f4v.js +0 -2
  236. package/dist/chunk-qz9fzz5k.js +0 -2
  237. package/dist/chunk-rh90yh1c.js +0 -2
  238. package/dist/chunk-s0wst4wj.js +0 -2
  239. package/dist/chunk-sj5t0tnv.js +0 -2
  240. package/dist/chunk-stddpecv.js +0 -2
  241. package/dist/chunk-t4mpq6t0.js +0 -3
  242. package/dist/chunk-tb6jcr2v.js +0 -2
  243. package/dist/chunk-tdjw105v.js +0 -2
  244. package/dist/chunk-tn40nh9e.js +0 -3
  245. package/dist/chunk-tp2g09ca.js +0 -3
  246. package/dist/chunk-wpgq0tq4.js +0 -2
  247. package/dist/chunk-xabs41cv.js +0 -12
  248. package/dist/chunk-yme43vbp.js +0 -2
  249. package/dist/chunk-zg5xh20b.js +0 -2
@@ -0,0 +1,125 @@
1
+ import { state } from "../signals-api.js";
2
+ export function useCompletion(options) {
3
+ const debounceMs = Math.max(0, options.debounceMs ?? 250), minChars = Math.max(0, options.minChars ?? 12), ghost = state(""), pending = state(!1), error = state(null);
4
+ let timer, controller, token = 0, lastKey = "", latest = { before: "", after: "", caret: 0 }, suggestion = "", anchor = null, destroyed = !1;
5
+ function isEnabled() {
6
+ const value = options.enabled, resolved = typeof value === "function" ? value() : value;
7
+ if (typeof resolved === "string")
8
+ return !["false", "0", "off", "no"].includes(resolved.trim().toLowerCase());
9
+ return resolved !== !1;
10
+ }
11
+ function cancelRequest() {
12
+ if (timer !== void 0) {
13
+ clearTimeout(timer);
14
+ timer = void 0;
15
+ }
16
+ token++;
17
+ if (controller) {
18
+ controller.abort();
19
+ controller = void 0;
20
+ }
21
+ if (pending())
22
+ pending.set(!1);
23
+ }
24
+ function clearSuggestion() {
25
+ suggestion = "";
26
+ anchor = null;
27
+ if (ghost() !== "")
28
+ ghost.set("");
29
+ }
30
+ function schedule(context) {
31
+ const mine = ++token;
32
+ timer = setTimeout(() => {
33
+ timer = void 0;
34
+ if (destroyed || mine !== token)
35
+ return;
36
+ const abort = new AbortController;
37
+ controller = abort;
38
+ pending.set(!0);
39
+ error.set(null);
40
+ Promise.resolve().then(() => options.fetch(context, abort.signal)).then((result) => {
41
+ if (destroyed || mine !== token)
42
+ return;
43
+ if (latest.before !== context.before || latest.after !== context.after || latest.caret !== context.caret)
44
+ return;
45
+ controller = void 0;
46
+ pending.set(!1);
47
+ const text = typeof result === "string" ? result : "";
48
+ if (!text) {
49
+ clearSuggestion();
50
+ return;
51
+ }
52
+ suggestion = text;
53
+ anchor = { before: context.before, after: context.after };
54
+ ghost.set(text);
55
+ }).catch((failure) => {
56
+ if (destroyed || mine !== token)
57
+ return;
58
+ controller = void 0;
59
+ pending.set(!1);
60
+ clearSuggestion();
61
+ if (!(failure instanceof Error && failure.name === "AbortError"))
62
+ error.set(failure instanceof Error ? failure : Error(String(failure)));
63
+ });
64
+ }, debounceMs);
65
+ }
66
+ function update(before, after, caret, meta = {}) {
67
+ if (destroyed)
68
+ return;
69
+ const key = `${caret}\x00${meta.composing ? 1 : 0}${meta.selecting ? 1 : 0}${meta.blocked ? 1 : 0}\x00${before}\x00${after}`;
70
+ if (key === lastKey)
71
+ return;
72
+ lastKey = key;
73
+ latest = { before, after, caret };
74
+ if (!isEnabled() || meta.composing || meta.selecting || meta.blocked) {
75
+ cancelRequest();
76
+ clearSuggestion();
77
+ return;
78
+ }
79
+ if (anchor && suggestion && after === anchor.after && before.length >= anchor.before.length && before.startsWith(anchor.before)) {
80
+ const typed = before.slice(anchor.before.length);
81
+ if (suggestion.startsWith(typed)) {
82
+ cancelRequest();
83
+ const rest = suggestion.slice(typed.length);
84
+ if (rest) {
85
+ if (ghost() !== rest)
86
+ ghost.set(rest);
87
+ } else
88
+ clearSuggestion();
89
+ return;
90
+ }
91
+ }
92
+ cancelRequest();
93
+ clearSuggestion();
94
+ if (before.trim().length < minChars)
95
+ return;
96
+ if (/^[\p{L}\p{N}_]/u.test(after))
97
+ return;
98
+ schedule({ before, after, caret });
99
+ }
100
+ function accept() {
101
+ const text = ghost();
102
+ if (!text)
103
+ return "";
104
+ ghost.set("");
105
+ return text;
106
+ }
107
+ function acceptWord() {
108
+ const text = ghost();
109
+ if (!text)
110
+ return "";
111
+ const match = /^\s*\S+/.exec(text), word = match ? match[0] : text;
112
+ ghost.set(text.slice(word.length));
113
+ return word;
114
+ }
115
+ function dismiss() {
116
+ cancelRequest();
117
+ clearSuggestion();
118
+ }
119
+ function destroy() {
120
+ destroyed = !0;
121
+ cancelRequest();
122
+ clearSuggestion();
123
+ }
124
+ return { ghost, pending, error, update, accept, acceptWord, dismiss, destroy };
125
+ }
@@ -1,9 +1,9 @@
1
1
  // @bun
2
- import{ho,xa,Sa}from"./chunk-ztdjdxjt.js";import"./chunk-jevd16gq.js";import"./chunk-465resq9.js";import"./chunk-xgegyttg.js";import"./chunk-89h4snzd.js";import"./chunk-0ggwm837.js";import"./chunk-gs373714.js";import"./chunk-bsgg8zzk.js";import"./chunk-yp6w740k.js";import"./chunk-z8k3fx4r.js";import"./chunk-q49ykyq9.js";import"./chunk-3cn9y08d.js";import"./chunk-5q9ss7ty.js";import"./chunk-wz5m7ybz.js";import"./chunk-g4e6egrr.js";import"./chunk-0y2zzqsq.js";import"./chunk-q9npggak.js";import"./chunk-2qz891k4.js";import"./chunk-3m9vrhja.js";import"./chunk-mmdfjmgk.js";import"./chunk-jt28zh50.js";import"./chunk-pes27snj.js";import{au,fa,eh,th,ga,mo,Gr,ma,ha,nh,rh,ya,ba,va,wa}from"./chunk-hfbzfrpv.js";import"./chunk-qw9kgzb3.js";import"./chunk-tp2g09ca.js";import"./chunk-sgm6tg8h.js";import"./chunk-30j6mbrf.js";import"./chunk-3kfbs0mw.js";import"./chunk-xsf7ax50.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
2
+ import{yo,ga,ma}from"./chunk-319aez2f.js";import"./chunk-48g9wez2.js";import"./chunk-tpfxvw4q.js";import"./chunk-b51p56k5.js";import"./chunk-4833k99b.js";import"./chunk-y4mp1rra.js";import"./chunk-x5seqmrv.js";import"./chunk-dvpk4c1y.js";import"./chunk-8rk79ha1.js";import"./chunk-f8p8ggvw.js";import"./chunk-edhxg3rz.js";import"./chunk-evxp3wmv.js";import"./chunk-q3azy64b.js";import"./chunk-yb71b2d6.js";import"./chunk-rd33qkfs.js";import"./chunk-t1shvfhm.js";import"./chunk-xgnmgjpv.js";import"./chunk-gwjh981q.js";import"./chunk-yk456jp4.js";import"./chunk-m3z13f59.js";import"./chunk-b0z2n941.js";import"./chunk-r8zhed35.js";import{cu,ha,lh,uh,ya,bo,Xr,ba,wa,dh,ph,va,xa,Sa,ka}from"./chunk-d96xddt9.js";import"./chunk-m6rzsbas.js";import"./chunk-a81rt2t4.js";import"./chunk-9k8ztdcc.js";import"./chunk-932zx5q4.js";import"./chunk-k2ex94n8.js";import"./chunk-rqd6b2nc.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
3
3
  `),scripts:t.scripts.join(`
4
4
  `),metadata:{renderTime:0,cacheHit:!0,totalSize:c.html.length,componentCount:t.metadata.componentCount}}}let a;if(n.streaming)a=await H(t.tree,e);else a=h(t.tree,e);let i;if(n.hydrate){let o=j(a,t,e);a=o.html,i=o.data}if(n.minify)a=D(a);if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`;d.set(o,{html:a,timestamp:Date.now()})}let s=performance.now()-r;return{html:a,styles:t.styles.join(`
5
5
  `),scripts:t.scripts.join(`
6
6
  `),hydrationData:i,metadata:{renderTime:s,cacheHit:!1,totalSize:a.length,componentCount:t.metadata.componentCount}}}function V(t,e){let n=[],r=[],a=[],i=new Map,s=[];return y(t.tree,(o,c)=>{if(o.type==="component"&&o.componentName){if(T(o.componentName))n.push(o.componentName)}if(o.type==="element"&&o.tag){let p=J(o);if(p)s.push(p);if(o.props){for(let[l,f]of Object.entries(o.props))if(l.startsWith("on")&&typeof f==="string"){let g=`handler_${i.size}`;i.set(g,f)}}}if(o.isStatic&&o.type==="element")r.push(b(o));else if(!o.isStatic&&o.type!=="text")a.push(o.tag||o.componentName||"unknown")}),{nativeComponents:n,staticHTML:r,dynamicParts:a,eventHandlers:i,nativeWidgets:s}}function Y(t,e={}){let n=R(t),r=P(n,e),a=new Map,i=[];return y(n.tree,(s)=>{if(s.type==="component"&&s.componentName){if(T(s.componentName)){i.push(s.componentName);let o=`<!--craft:${s.componentName}:${s.hydrationKey||"default"}-->`;a.set(s.hydrationKey||s.componentName,o)}}}),{staticHTML:r,dynamicPlaceholders:a,craftComponents:i}}function M(t){let e={type:"fragment",children:[]},n=e,r=[e],a=t,i=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);while(a.length>0){let s=a.match(/^<(@?[\w-]+)([^>]*)>/);if(s){let[p,l,f]=s,g=z(f),u=l.startsWith("@craft-"),C=u?l:l.toLowerCase(),S={type:u?"component":"element",tag:C,props:g,children:[],componentName:u?C.slice(1):void 0,isStatic:!v(f),hydrationKey:F()};if(n.children=n.children||[],n.children.push(S),!i.has(C)&&!f.endsWith("/"))r.push(S),n=S;a=a.slice(p.length);continue}let o=a.match(/^<\/(@?[\w-]+)>/);if(o){let[p,l]=o,g=l.startsWith("@craft-")?l:l.toLowerCase();while(r.length>1){let u=r.pop();if(n=r[r.length-1],u.tag===g)break}a=a.slice(p.length);continue}let c=a.match(/^[^<]+/);if(c){let p=c[0];if(p.trim()){let l={type:"text",text:p,isStatic:!v(p)};n.children=n.children||[],n.children.push(l)}a=a.slice(p.length);continue}a=a.slice(1)}return e}function z(t){let e={},n=/([\w-:@]+)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,r;while((r=n.exec(t))!==null){let[,a,i,s,o]=r,c=i??s??o??!0;e[a]=c}return e}function y(t,e,n=[]){if(e(t,n),t.children)t.children.forEach((r,a)=>{y(r,e,[...n,`${a}`])})}function h(t,e){switch(t.type){case"text":return x(t.text||"",e);case"element":case"component":{let n=t.tag||"div",r=N(t.props||{},e),a=(t.children||[]).map((i)=>h(i,e)).join("");if(!t.children||t.children.length===0){if(["input","br","hr","img","meta","link"].includes(n))return`<${n}${r} />`}return`<${n}${r}>${a}</${n}>`}case"fragment":return(t.children||[]).map((n)=>h(n,e)).join("");case"slot":return`<!--slot:${t.slotName||"default"}-->`;default:return""}}function b(t){if(t.type==="text")return t.text||"";let e=t.tag||"div",n=N(t.props||{},{});return`<${e}${n}></${e}>`}function N(t,e){let n=[];for(let[r,a]of Object.entries(t))if(a===!0)n.push(` ${r}`);else if(a!==!1&&a!==null&&a!==void 0){let i=x(String(a),e);n.push(` ${r}="${k(i)}"`)}return n.join("")}async function H(t,e){return h(t,e)}function P(t,e){let n=[];return y(t.tree,(r)=>{if(r.isStatic)n.push(h(r,e))}),n.join("")}function j(t,e,n){let r={templateId:e.id,context:n,dynamicParts:Array.from(e.dynamicParts.entries())},a=`
7
7
  <script data-craft-hydration>
8
8
  window.__CRAFT_HYDRATION__ = ${JSON.stringify(r)};
9
- </script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{au as CRAFT_BRIDGE_SCRIPT,mo as CRAFT_COMPONENTS,ma as CRAFT_COMPONENT_RUNTIME,Gr as CRAFT_COMPONENT_STYLES,ho as NATIVE_COMPONENTS,ya as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,xa as compileToNative,Sa as createHotReloadServer,ba as findCraftBinary,fa as generateCraftBridgeScript,V as generateCraftOptimizations,wa as getAvailableFormats,va as getAvailableTargets,rh as getCraftComponents,G as getSSRCacheStats,ga as injectCraftBridge,eh as isCraftEnvironment,Y as prerenderForCraft,ha as processCraftComponents,th as processCraftDirective,nh as registerCraftComponent,Q as renderSSR};
9
+ </script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{cu as CRAFT_BRIDGE_SCRIPT,bo as CRAFT_COMPONENTS,ba as CRAFT_COMPONENT_RUNTIME,Xr as CRAFT_COMPONENT_STYLES,yo as NATIVE_COMPONENTS,va as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,ga as compileToNative,ma as createHotReloadServer,xa as findCraftBinary,ha as generateCraftBridgeScript,V as generateCraftOptimizations,ka as getAvailableFormats,Sa as getAvailableTargets,ph as getCraftComponents,G as getSSRCacheStats,ya as injectCraftBridge,lh as isCraftEnvironment,Y as prerenderForCraft,wa as processCraftComponents,uh as processCraftDirective,dh as registerCraftComponent,Q as renderSSR};
package/dist/craft.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // @bun
2
- import{ho,xa,Sa}from"./chunk-ztdjdxjt.js";import"./chunk-jevd16gq.js";import"./chunk-465resq9.js";import"./chunk-xgegyttg.js";import"./chunk-89h4snzd.js";import"./chunk-0ggwm837.js";import"./chunk-gs373714.js";import"./chunk-bsgg8zzk.js";import"./chunk-yp6w740k.js";import"./chunk-z8k3fx4r.js";import"./chunk-q49ykyq9.js";import"./chunk-3cn9y08d.js";import"./chunk-5q9ss7ty.js";import"./chunk-wz5m7ybz.js";import"./chunk-g4e6egrr.js";import"./chunk-0y2zzqsq.js";import"./chunk-q9npggak.js";import"./chunk-2qz891k4.js";import"./chunk-3m9vrhja.js";import"./chunk-mmdfjmgk.js";import"./chunk-jt28zh50.js";import"./chunk-pes27snj.js";import{au,fa,eh,th,ga,mo,Gr,ma,ha,nh,rh,ya,ba,va,wa}from"./chunk-hfbzfrpv.js";import"./chunk-qw9kgzb3.js";import"./chunk-tp2g09ca.js";import"./chunk-sgm6tg8h.js";import"./chunk-30j6mbrf.js";import"./chunk-3kfbs0mw.js";import"./chunk-xsf7ax50.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
2
+ import{yo,ga,ma}from"./chunk-319aez2f.js";import"./chunk-48g9wez2.js";import"./chunk-tpfxvw4q.js";import"./chunk-b51p56k5.js";import"./chunk-4833k99b.js";import"./chunk-y4mp1rra.js";import"./chunk-x5seqmrv.js";import"./chunk-dvpk4c1y.js";import"./chunk-8rk79ha1.js";import"./chunk-f8p8ggvw.js";import"./chunk-edhxg3rz.js";import"./chunk-evxp3wmv.js";import"./chunk-q3azy64b.js";import"./chunk-yb71b2d6.js";import"./chunk-rd33qkfs.js";import"./chunk-t1shvfhm.js";import"./chunk-xgnmgjpv.js";import"./chunk-gwjh981q.js";import"./chunk-yk456jp4.js";import"./chunk-m3z13f59.js";import"./chunk-b0z2n941.js";import"./chunk-r8zhed35.js";import{cu,ha,lh,uh,ya,bo,Xr,ba,wa,dh,ph,va,xa,Sa,ka}from"./chunk-d96xddt9.js";import"./chunk-m6rzsbas.js";import"./chunk-a81rt2t4.js";import"./chunk-9k8ztdcc.js";import"./chunk-932zx5q4.js";import"./chunk-k2ex94n8.js";import"./chunk-rqd6b2nc.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
3
3
  `),scripts:t.scripts.join(`
4
4
  `),metadata:{renderTime:0,cacheHit:!0,totalSize:c.html.length,componentCount:t.metadata.componentCount}}}let a;if(n.streaming)a=await H(t.tree,e);else a=h(t.tree,e);let i;if(n.hydrate){let o=j(a,t,e);a=o.html,i=o.data}if(n.minify)a=D(a);if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`;d.set(o,{html:a,timestamp:Date.now()})}let s=performance.now()-r;return{html:a,styles:t.styles.join(`
5
5
  `),scripts:t.scripts.join(`
6
6
  `),hydrationData:i,metadata:{renderTime:s,cacheHit:!1,totalSize:a.length,componentCount:t.metadata.componentCount}}}function V(t,e){let n=[],r=[],a=[],i=new Map,s=[];return y(t.tree,(o,c)=>{if(o.type==="component"&&o.componentName){if(T(o.componentName))n.push(o.componentName)}if(o.type==="element"&&o.tag){let p=J(o);if(p)s.push(p);if(o.props){for(let[l,f]of Object.entries(o.props))if(l.startsWith("on")&&typeof f==="string"){let g=`handler_${i.size}`;i.set(g,f)}}}if(o.isStatic&&o.type==="element")r.push(b(o));else if(!o.isStatic&&o.type!=="text")a.push(o.tag||o.componentName||"unknown")}),{nativeComponents:n,staticHTML:r,dynamicParts:a,eventHandlers:i,nativeWidgets:s}}function Y(t,e={}){let n=R(t),r=P(n,e),a=new Map,i=[];return y(n.tree,(s)=>{if(s.type==="component"&&s.componentName){if(T(s.componentName)){i.push(s.componentName);let o=`<!--craft:${s.componentName}:${s.hydrationKey||"default"}-->`;a.set(s.hydrationKey||s.componentName,o)}}}),{staticHTML:r,dynamicPlaceholders:a,craftComponents:i}}function M(t){let e={type:"fragment",children:[]},n=e,r=[e],a=t,i=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);while(a.length>0){let s=a.match(/^<(@?[\w-]+)([^>]*)>/);if(s){let[p,l,f]=s,g=z(f),u=l.startsWith("@craft-"),C=u?l:l.toLowerCase(),S={type:u?"component":"element",tag:C,props:g,children:[],componentName:u?C.slice(1):void 0,isStatic:!v(f),hydrationKey:F()};if(n.children=n.children||[],n.children.push(S),!i.has(C)&&!f.endsWith("/"))r.push(S),n=S;a=a.slice(p.length);continue}let o=a.match(/^<\/(@?[\w-]+)>/);if(o){let[p,l]=o,g=l.startsWith("@craft-")?l:l.toLowerCase();while(r.length>1){let u=r.pop();if(n=r[r.length-1],u.tag===g)break}a=a.slice(p.length);continue}let c=a.match(/^[^<]+/);if(c){let p=c[0];if(p.trim()){let l={type:"text",text:p,isStatic:!v(p)};n.children=n.children||[],n.children.push(l)}a=a.slice(p.length);continue}a=a.slice(1)}return e}function z(t){let e={},n=/([\w-:@]+)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,r;while((r=n.exec(t))!==null){let[,a,i,s,o]=r,c=i??s??o??!0;e[a]=c}return e}function y(t,e,n=[]){if(e(t,n),t.children)t.children.forEach((r,a)=>{y(r,e,[...n,`${a}`])})}function h(t,e){switch(t.type){case"text":return x(t.text||"",e);case"element":case"component":{let n=t.tag||"div",r=N(t.props||{},e),a=(t.children||[]).map((i)=>h(i,e)).join("");if(!t.children||t.children.length===0){if(["input","br","hr","img","meta","link"].includes(n))return`<${n}${r} />`}return`<${n}${r}>${a}</${n}>`}case"fragment":return(t.children||[]).map((n)=>h(n,e)).join("");case"slot":return`<!--slot:${t.slotName||"default"}-->`;default:return""}}function b(t){if(t.type==="text")return t.text||"";let e=t.tag||"div",n=N(t.props||{},{});return`<${e}${n}></${e}>`}function N(t,e){let n=[];for(let[r,a]of Object.entries(t))if(a===!0)n.push(` ${r}`);else if(a!==!1&&a!==null&&a!==void 0){let i=x(String(a),e);n.push(` ${r}="${k(i)}"`)}return n.join("")}async function H(t,e){return h(t,e)}function P(t,e){let n=[];return y(t.tree,(r)=>{if(r.isStatic)n.push(h(r,e))}),n.join("")}function j(t,e,n){let r={templateId:e.id,context:n,dynamicParts:Array.from(e.dynamicParts.entries())},a=`
7
7
  <script data-craft-hydration>
8
8
  window.__CRAFT_HYDRATION__ = ${JSON.stringify(r)};
9
- </script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{au as CRAFT_BRIDGE_SCRIPT,mo as CRAFT_COMPONENTS,ma as CRAFT_COMPONENT_RUNTIME,Gr as CRAFT_COMPONENT_STYLES,ho as NATIVE_COMPONENTS,ya as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,xa as compileToNative,Sa as createHotReloadServer,ba as findCraftBinary,fa as generateCraftBridgeScript,V as generateCraftOptimizations,wa as getAvailableFormats,va as getAvailableTargets,rh as getCraftComponents,G as getSSRCacheStats,ga as injectCraftBridge,eh as isCraftEnvironment,Y as prerenderForCraft,ha as processCraftComponents,th as processCraftDirective,nh as registerCraftComponent,Q as renderSSR};
9
+ </script>`;return{html:t+a,data:r}}function O(t){let e=!1,n=!1,r=!1,a=!1,i=0,s=0;function o(c,p){if(s=Math.max(s,p),c.type==="slot")e=!0;if(c.type==="component")i++;if(!c.isStatic)n=!0;if(c.props)for(let l of Object.keys(c.props)){if(l.startsWith("on"))r=!0;if(l==="@async"||l==="data-async")a=!0}if(c.children)c.children.forEach((l)=>o(l,p+1))}return o(t,0),{hasSlots:e,hasDynamicContent:n,hasEventHandlers:r,hasAsyncContent:a,componentCount:i,maxDepth:s,estimatedSize:JSON.stringify(t).length}}function A(t){let e=new Map,n=new Map;return y(t,(r,a)=>{let i=a.join(".");if(r.isStatic)e.set(i,b(r));else n.set(i,r.tag||r.componentName||"dynamic")}),{staticParts:e,dynamicParts:n}}function L(t){let e=[],n=/<script[^>]*>([\s\S]*?)<\/script>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function W(t){let e=[],n=/<style[^>]*>([\s\S]*?)<\/style>/gi,r;while((r=n.exec(t))!==null)e.push(r[1]);return e}function _(t){let e=[],n=/@include\s*\(\s*['"]([^'"]+)['"]/g,r;while((r=n.exec(t))!==null)e.push(r[1]);let a=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((r=a.exec(t))!==null)e.push(r[1]);let i=/<@craft-[\w-]+/g;while((r=i.exec(t))!==null)e.push(r[0].slice(2));return[...new Set(e)]}function v(t){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(t)}function x(t,e){let n=t.replace(/\{\{\s*(.+?)\s*\}\}/g,(r,a)=>{try{let i=w(a.trim(),e);return k(String(i??""))}catch{return""}});return n=n.replace(/\{!!\s*(.+?)\s*!!\}/g,(r,a)=>{try{let i=w(a.trim(),e);return String(i??"")}catch{return""}}),n}function w(t,e){if(/^[\w.]+$/.test(t)){let n=t.split("."),r=e;for(let a of n)if(r&&typeof r==="object"&&a in r)r=r[a];else return;return r}try{return Function(...Object.keys(e),`return ${t}`)(...Object.values(e))}catch{return}}function k(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function D(t){return t.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function E(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function I(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return Math.abs(e).toString(36)}var K=0;function F(){return`h_${++K}`}function T(t){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(t)}function J(t){let e=t.tag?.toLowerCase(),n=t.props?.type,r={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},a=n?`${e}:${n}`:e,i=r[a||""]||r[e||""];if(i)return{htmlSelector:a||e||"",nativeComponent:i.component,confidence:i.confidence,reason:i.reason};return null}function U(){m.clear()}function q(){d.clear()}function B(){U(),q()}function G(){return{templateCacheSize:m.size,renderCacheSize:d.size,totalEntries:m.size+d.size}}export{cu as CRAFT_BRIDGE_SCRIPT,bo as CRAFT_COMPONENTS,ba as CRAFT_COMPONENT_RUNTIME,Xr as CRAFT_COMPONENT_STYLES,yo as NATIVE_COMPONENTS,va as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,ga as compileToNative,ma as createHotReloadServer,xa as findCraftBinary,ha as generateCraftBridgeScript,V as generateCraftOptimizations,ka as getAvailableFormats,Sa as getAvailableTargets,ph as getCraftComponents,G as getSSRCacheStats,ya as injectCraftBridge,lh as isCraftEnvironment,Y as prerenderForCraft,wa as processCraftComponents,uh as processCraftDirective,dh as registerCraftComponent,Q as renderSSR};
@@ -0,0 +1,39 @@
1
+ /** Read every language's message modules, at build time. */
2
+ export declare function collectMessageCatalogs(root: string, options: MessageCatalogsOptions): Promise<CollectedMessages>;
3
+ /**
4
+ * Whether web pages ship messages a language at a time: with the `messages`
5
+ * option, in production. `STX_PAGE_MESSAGES=0` turns it off; `=1` turns it
6
+ * on outside production too (a development server re-reads a catalog only
7
+ * when it restarts, so it is off there by default).
8
+ */
9
+ export declare function pageMessagesEnabled(options: { messages?: PageMessagesOptions }, env?: Record<string, string | undefined>): boolean;
10
+ /** The app's message catalogs, read once per version of the language directories. */
11
+ export declare function loadPageMessages(root: string, options: PageMessagesOptions): Promise<PageMessages>;
12
+ /** The areas built code imports messages for (its stubs' keys), whatever the language. */
13
+ export declare function messageAreasIn(...codes: Array<string | null | undefined>): Set<string>;
14
+ /**
15
+ * The languages a page ships: the one `<html lang>` names and the fallback.
16
+ * Every language when the page names none of them, since nothing then says
17
+ * which one its scripts will read.
18
+ */
19
+ export declare function pageLanguages(html: string, messages: Pick<PageMessages, 'languages' | 'fallback'>): string[];
20
+ export declare function pageMessagesScript(messages: PageMessages, languages: string[], areas: Iterable<string>): string | null;
21
+ /** Where an app keeps its messages, a directory per language. */
22
+ export declare interface MessageCatalogsOptions {
23
+ dir: string
24
+ languages: string[]
25
+ }
26
+ /** The web pages' `messages` option. */
27
+ export declare interface PageMessagesOptions extends MessageCatalogsOptions {
28
+ fallback?: string
29
+ }
30
+ export declare interface CollectedMessages {
31
+ files: Map<string, { language: string, area: string }>
32
+ data: Map<string, Map<string, string>>
33
+ }
34
+ /** A collection, with the stub for every message module (by path as written and as Bun resolves it). */
35
+ export declare interface PageMessages extends CollectedMessages {
36
+ stubs: Map<string, string>
37
+ languages: string[]
38
+ fallback: string
39
+ }
@@ -0,0 +1,128 @@
1
+ import { existsSync, realpathSync, statSync } from "node:fs";
2
+ import path from "node:path";
3
+ import process from "node:process";
4
+ const MESSAGE_AREA = /^[\w-]+(?:\/[\w-]+)*$/, MESSAGE_LANGUAGE = /^[\w-]+$/;
5
+ export async function collectMessageCatalogs(root, options) {
6
+ const dir = path.resolve(root, options.dir);
7
+ if (!options.languages?.length)
8
+ throw Error("messages.languages must name at least one language");
9
+ const files = new Map, data = new Map;
10
+ for (const language of options.languages) {
11
+ if (!MESSAGE_LANGUAGE.test(language))
12
+ throw Error(`messages: "${language}" is not a language directory name`);
13
+ const base = path.join(dir, language);
14
+ if (!existsSync(base))
15
+ throw Error(`messages: ${path.relative(root, base)} does not exist`);
16
+ const areas = new Map;
17
+ for (const relative of [...new Bun.Glob("**/*.{ts,js,mjs,json}").scanSync({ cwd: base })].sort()) {
18
+ if (/\.(?:test|spec|d)\.[^.]+$/.test(relative))
19
+ continue;
20
+ const area = relative.replace(/\.[^./]+$/, "").split(path.sep).join("/");
21
+ if (!MESSAGE_AREA.test(area))
22
+ throw Error(`messages: ${language}/${relative} is not an area name`);
23
+ if (areas.has(area))
24
+ throw Error(`messages: ${language}/${area} is defined twice`);
25
+ const file = path.join(base, relative), module = await import(file), others = Object.keys(module).filter((name) => name !== "default");
26
+ if (others.length)
27
+ throw Error(`messages: ${language}/${relative} exports ${others.join(", ")}; a message module exports its messages as default, and nothing else`);
28
+ const value = module.default, json = value !== null && typeof value === "object" && !Array.isArray(value) ? JSON.stringify(value) : void 0;
29
+ if (json === void 0 || !Bun.deepEquals(JSON.parse(json), value, !0))
30
+ throw Error(`messages: ${language}/${relative} must export plain data (an object JSON can hold) as default`);
31
+ areas.set(area, json);
32
+ files.set(file, { language, area });
33
+ }
34
+ data.set(language, areas);
35
+ }
36
+ return { files, data };
37
+ }
38
+ function messagesKey(language, area) {
39
+ return `stx-messages:${language}:${area}`;
40
+ }
41
+ function pageMessagesStub(language, area) {
42
+ const key = JSON.stringify(messagesKey(language, area));
43
+ return `var kept = globalThis.__stxMessages || (globalThis.__stxMessages = {});
44
+ export default kept[${key}] || (kept[${key}] = {});`;
45
+ }
46
+ const collected = new Map;
47
+ export function pageMessagesEnabled(options, env = process.env) {
48
+ if (!options.messages || env.STX_PAGE_MESSAGES === "0")
49
+ return !1;
50
+ return env.STX_PAGE_MESSAGES === "1" || env.NODE_ENV === "production";
51
+ }
52
+ export async function loadPageMessages(root, options) {
53
+ const dir = path.resolve(root, options.dir), signature = options.languages.map((language) => {
54
+ try {
55
+ return `${language}:${statSync(path.join(dir, language)).mtimeMs}`;
56
+ } catch {
57
+ return `${language}:-`;
58
+ }
59
+ }).join("|"), cacheKey = `${dir}\x00${options.languages.join(",")}\x00${options.fallback ?? ""}`, cached = collected.get(cacheKey);
60
+ if (cached && cached.signature === signature)
61
+ return cached.messages;
62
+ const catalogs = await collectMessageCatalogs(root, options), stubs = new Map;
63
+ for (const [file, { language, area }] of catalogs.files) {
64
+ const stub = pageMessagesStub(language, area), names = [file];
65
+ try {
66
+ names.push(realpathSync(file));
67
+ } catch {}
68
+ for (const named of [...names])
69
+ if (named.startsWith("/private/"))
70
+ names.push(named.slice(8));
71
+ for (const named of names)
72
+ stubs.set(named, stub);
73
+ }
74
+ const fallback = options.fallback ?? options.languages[0];
75
+ if (!options.languages.includes(fallback))
76
+ throw Error(`messages.fallback "${fallback}" is not one of messages.languages`);
77
+ const messages = { ...catalogs, stubs, languages: [...options.languages], fallback };
78
+ collected.set(cacheKey, { signature, messages });
79
+ return messages;
80
+ }
81
+ export function messageAreasIn(...codes) {
82
+ const areas = new Set;
83
+ for (const code of codes) {
84
+ if (!code || !code.includes("stx-messages:"))
85
+ continue;
86
+ for (const match of code.matchAll(/stx-messages:[\w-]+:([\w/-]+)/g))
87
+ areas.add(match[1]);
88
+ }
89
+ return areas;
90
+ }
91
+ export function pageLanguages(html, messages) {
92
+ const htmlTag = /<html\b[^>]*>/i.exec(html)?.[0] ?? "", lang = /\slang\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(htmlTag), value = (lang ? lang[1] ?? lang[2] ?? lang[3] ?? "" : "").trim().toLowerCase(), known = new Map(messages.languages.map((language) => [language.toLowerCase(), language])), language = known.get(value) ?? known.get(value.split(/[-_]/)[0] ?? "");
93
+ if (!language)
94
+ return [...messages.languages];
95
+ return [...new Set([language, messages.fallback])];
96
+ }
97
+ const scripts = new WeakMap;
98
+ export function pageMessagesScript(messages, languages, areas) {
99
+ const wanted = [...areas].sort();
100
+ let built = scripts.get(messages);
101
+ if (!built)
102
+ scripts.set(messages, built = new Map);
103
+ const key = `${languages.join(",")}\x00${wanted.join(",")}`;
104
+ if (built.has(key))
105
+ return built.get(key);
106
+ const code = buildPageMessagesScript(messages, languages, wanted);
107
+ built.set(key, code);
108
+ return code;
109
+ }
110
+ function buildPageMessagesScript(messages, languages, wanted) {
111
+ const puts = [];
112
+ for (const language of languages) {
113
+ const catalog = messages.data.get(language);
114
+ if (!catalog)
115
+ continue;
116
+ for (const area of wanted) {
117
+ const json = catalog.get(area);
118
+ if (json !== void 0)
119
+ puts.push(`put(${JSON.stringify(messagesKey(language, area))},${JSON.stringify(json)})`);
120
+ }
121
+ }
122
+ if (puts.length === 0)
123
+ return null;
124
+ return `;(function(){var kept=globalThis.__stxMessages||(globalThis.__stxMessages={}),filled=globalThis.__stxMessagesFilled||(globalThis.__stxMessagesFilled={});function put(key,json){if(filled[key])return;filled[key]=1;var into=kept[key]||(kept[key]={}),data=JSON.parse(json);for(var name in data)into[name]=data[name]}
125
+ ${puts.join(`;
126
+ `)};
127
+ })();`;
128
+ }
@@ -5,6 +5,7 @@ import { nativeStyleConfigFrom, withNativeStyleConfig } from "./style-config.js"
5
5
  import { NATIVE_APP_ROUTE } from "../runtime/shared-screen.js";
6
6
  import { generateSignalsRuntime } from "../../signals.js";
7
7
  import { withModuleSubstitutes } from "../../client-script-bundler.js";
8
+ import { collectMessageCatalogs } from "../../message-catalogs.js";
8
9
  import { shareComponentScripts } from "./shared-scripts.js";
9
10
  import { compactDocument, compactManifest } from "../runtime/compact-document.js";
10
11
  import { buildSharedModuleRegistries, registeredModuleIdsIn, registeredModuleNamesIn } from "../../client-module-registry.js";
@@ -50,39 +51,8 @@ ${messages}`);
50
51
  }
51
52
  return (await result.outputs[0].text()).trim();
52
53
  }
53
- const MESSAGE_AREA = /^[\w-]+(?:\/[\w-]+)*$/, MESSAGE_LANGUAGE = /^[\w-]+$/;
54
- async function collectMessages(root, options) {
55
- const dir = path.resolve(root, options.dir);
56
- if (!options.languages?.length)
57
- throw Error("messages.languages must name at least one language");
58
- const files = new Map, data = new Map;
59
- for (const language of options.languages) {
60
- if (!MESSAGE_LANGUAGE.test(language))
61
- throw Error(`messages: "${language}" is not a language directory name`);
62
- const base = path.join(dir, language);
63
- if (!existsSync(base))
64
- throw Error(`messages: ${path.relative(root, base)} does not exist`);
65
- const areas = new Map;
66
- for (const relative of [...new Bun.Glob("**/*.{ts,js,mjs,json}").scanSync({ cwd: base })].sort()) {
67
- if (/\.(?:test|spec|d)\.[^.]+$/.test(relative))
68
- continue;
69
- const area = relative.replace(/\.[^./]+$/, "").split(path.sep).join("/");
70
- if (!MESSAGE_AREA.test(area))
71
- throw Error(`messages: ${language}/${relative} is not an area name`);
72
- if (areas.has(area))
73
- throw Error(`messages: ${language}/${area} is defined twice`);
74
- const file = path.join(base, relative), module = await import(file), others = Object.keys(module).filter((name) => name !== "default");
75
- if (others.length)
76
- throw Error(`messages: ${language}/${relative} exports ${others.join(", ")}; a message module exports its messages as default, and nothing else`);
77
- const value = module.default, json = value !== null && typeof value === "object" && !Array.isArray(value) ? JSON.stringify(value) : void 0;
78
- if (json === void 0 || !Bun.deepEquals(JSON.parse(json), value, !0))
79
- throw Error(`messages: ${language}/${relative} must export plain data (an object JSON can hold) as default`);
80
- areas.set(area, json);
81
- files.set(file, { language, area });
82
- }
83
- data.set(language, areas);
84
- }
85
- return { files, data };
54
+ function collectMessages(root, options) {
55
+ return collectMessageCatalogs(root, options);
86
56
  }
87
57
  function messagesStub(language, area) {
88
58
  return `export default globalThis.__stxNativeRuntime.messages(${JSON.stringify(language)}, ${JSON.stringify(area)});`;
package/dist/process.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { processJsonDirective, processOnceDirective } from './misc-directives';
2
2
  import { validateClientScript } from './script-validation';
3
3
  import type { StxOptions } from './types';
4
- export declare function buildModulesTag(sources: Array<string | null>, options: StxOptions, dependencies?: Set<string>): Promise<string | null>;
4
+ export declare function buildModulesTag(sources: Array<string | null>, options: StxOptions, dependencies?: Set<string>, built?: { code?: string, inputs?: string[] }): Promise<string | null>;
5
5
  export declare function processDirectives(template: string, context: Record<string, any>, filePath: string, options: StxOptions, dependencies: Set<string>): Promise<string>;
6
6
  // Re-export public API from extracted modules (preserves backwards compatibility)
7
7
  export { injectRouterScript } from './runtime-injection';
package/dist/process.js CHANGED
@@ -226,7 +226,7 @@ async function externalBundleTag(attrs, code, options) {
226
226
  const { registerServeModuleBundle } = await import("./caching.js");
227
227
  return `<script ${attrs} src="${registerServeModuleBundle(code)}"></script>`;
228
228
  }
229
- export async function buildModulesTag(sources, options, dependencies) {
229
+ export async function buildModulesTag(sources, options, dependencies, built) {
230
230
  try {
231
231
  const { registeredModuleIdsIn, buildModuleRegistryScript } = await importOnce("stx/client-module-registry", () => import("./client-module-registry.js")), inputs = [], code = await buildModuleRegistryScript(registeredModuleIdsIn(...sources), {
232
232
  minify: minifiesClientCode(options.buildMode, options.minifyClient),
@@ -234,6 +234,10 @@ export async function buildModulesTag(sources, options, dependencies) {
234
234
  });
235
235
  for (const input of inputs)
236
236
  dependencies?.add(input);
237
+ if (built) {
238
+ built.inputs = inputs;
239
+ built.code = code ?? void 0;
240
+ }
237
241
  if (!code)
238
242
  return null;
239
243
  if (options.buildMode === "serve") {
@@ -245,6 +249,85 @@ export async function buildModulesTag(sources, options, dependencies) {
245
249
  return null;
246
250
  }
247
251
  }
252
+ async function buildPageBundles(result, options, dependencies, context) {
253
+ const built = { modulesTag: null, modulesCode: null, storeTag: null, storeCode: null, composableTag: null, composableCode: null, frameworkScript: null };
254
+ try {
255
+ const { getFrameworkComposableScript } = await importOnce("stx/framework-composables", () => import("./framework-composables.js"));
256
+ built.frameworkScript = await getFrameworkComposableScript(result);
257
+ } catch {}
258
+ let storeLoader = null;
259
+ try {
260
+ storeLoader = await importOnce("stx/store-loader", () => import("./store-loader.js"));
261
+ } catch {}
262
+ const storesDir = options.storesDir, everyStore = !!context.__stx_native_screen || (storeLoader?.pageStoresAll() ?? !0), authored = everyStore ? "" : result.replace(/<script\b[^>]*\bdata-stx-(?:runtime|router|hmr)\b[^>]*>[\s\S]*?<\/script>/gi, "");
263
+ let registryInputs = [], composableInputs = [], shipped = null;
264
+ for (let round = 0;round < 8; round++) {
265
+ let storeCode = null, storeNames = "", runOnce = !1;
266
+ try {
267
+ if (storeLoader) {
268
+ const stores = everyStore ? await storeLoader.getStoreScript(storesDir).then((code) => code ? { code, stores: ["*"], functions: null } : null) : await storeLoader.getStoreScriptFor(storesDir, [authored], {
269
+ reads: storeLoader.storesReadInFiles([...registryInputs, ...composableInputs]),
270
+ runOnce: !0
271
+ });
272
+ if (stores) {
273
+ storeCode = stores.code;
274
+ storeNames = stores.stores.join(",");
275
+ runOnce = !!stores.functions && !everyStore;
276
+ }
277
+ }
278
+ } catch {}
279
+ if (shipped !== null && storeNames === shipped)
280
+ break;
281
+ shipped = storeNames;
282
+ const storeAttrs = runOnce ? 'data-stx-scoped data-stx-run="always" data-stx-stores' : "data-stx-stores", storeScan = storeCode ? `<script ${storeAttrs}>${storeCode}</script>` : null;
283
+ built.storeCode = storeCode;
284
+ built.storeTag = storeCode ? await externalBundleTag(storeAttrs, storeCode, options) ?? storeScan : null;
285
+ const registry = {};
286
+ built.modulesTag = await buildModulesTag([result, storeScan], options, dependencies, registry);
287
+ built.modulesCode = registry.code ?? null;
288
+ registryInputs = registry.inputs ?? [];
289
+ built.composableTag = null;
290
+ built.composableCode = null;
291
+ composableInputs = [];
292
+ try {
293
+ const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, pending = [built.modulesCode ?? built.modulesTag, storeScan, built.frameworkScript].filter((text) => text !== null), composableCode = await getComposableScript(options._layerComposableDirs ?? resolvedComposablesDir, result, pending, composableInputs);
294
+ if (composableCode) {
295
+ built.composableCode = composableCode;
296
+ built.composableTag = await externalBundleTag('data-stx-scoped data-stx-run="always" data-stx-composables', composableCode, options) ?? `<script data-stx-scoped data-stx-run="always" data-stx-composables>${composableCode}</script>`;
297
+ }
298
+ } catch {}
299
+ if (everyStore || !storeLoader)
300
+ break;
301
+ }
302
+ return built;
303
+ }
304
+ async function pageBundleTags(result, options, dependencies, context = {}) {
305
+ const { withModuleSubstitutes, moduleSubstitutionKey } = await import("./client-script-bundler.js"), catalogs = await import("./message-catalogs.js"), messagesOption = options.messages;
306
+ let messages = null;
307
+ if (messagesOption && catalogs.pageMessagesEnabled(options) && moduleSubstitutionKey() === "" && !context.__stx_native_screen)
308
+ try {
309
+ messages = await catalogs.loadPageMessages(process.cwd(), messagesOption);
310
+ } catch (error) {
311
+ warnPageMessagesOnce(error);
312
+ }
313
+ const build = () => buildPageBundles(result, options, dependencies, context), built = messages ? await withModuleSubstitutes(messages.stubs, build) : await build();
314
+ let messagesTag = null;
315
+ if (messages) {
316
+ const areas = catalogs.messageAreasIn(built.modulesCode, built.storeCode, built.composableCode), code = catalogs.pageMessagesScript(messages, catalogs.pageLanguages(result, messages), areas);
317
+ if (code) {
318
+ const attrs = 'data-stx-scoped data-stx-run="always" data-stx-messages';
319
+ messagesTag = await externalBundleTag(attrs, code, options) ?? `<script ${attrs}>${code.replace(/<\/script/gi, "<\\/script")}</script>`;
320
+ }
321
+ }
322
+ return [messagesTag, built.modulesTag, built.storeTag, built.composableTag, built.frameworkScript].filter((tag) => tag !== null);
323
+ }
324
+ let warnedPageMessages = !1;
325
+ function warnPageMessagesOnce(error) {
326
+ if (warnedPageMessages)
327
+ return;
328
+ warnedPageMessages = !0;
329
+ console.warn(`[stx] messages: ${error instanceof Error ? error.message : String(error)}; pages ship every language`);
330
+ }
248
331
  function placeSignalsRuntimeBeforeScripts(html, afterRuntime = "") {
249
332
  const runtime = findScriptBlockByAttribute(html, "data-stx-runtime");
250
333
  if (!runtime)
@@ -364,27 +447,9 @@ export async function processDirectives(template, context, filePath, options, de
364
447
  }
365
448
  if (isTopLevel)
366
449
  if (findScriptBlockByAttribute(result, "data-stx-runtime")) {
367
- let modulesTag = null, storeTag = null, storeScan = null, composableTag = null, frameworkScript = null;
368
- try {
369
- const { getStoreScript } = await importOnce("stx/store-loader", () => import("./store-loader.js")), resolvedStoresDir = options.storesDir, storeCode = await getStoreScript(resolvedStoresDir);
370
- if (storeCode) {
371
- storeScan = `<script data-stx-stores>${storeCode}</script>`;
372
- storeTag = await externalBundleTag("data-stx-stores", storeCode, options) ?? storeScan;
373
- }
374
- } catch {}
375
- modulesTag = await buildModulesTag([result, storeScan], options, dependencies);
376
- try {
377
- const { getFrameworkComposableScript } = await importOnce("stx/framework-composables", () => import("./framework-composables.js"));
378
- frameworkScript = await getFrameworkComposableScript(result);
379
- } catch {}
380
- try {
381
- const { getComposableScript } = await importOnce("stx/composable-loader", () => import("./composable-loader.js")), resolvedComposablesDir = options.composablesDir, pending = [modulesTag, storeScan, frameworkScript].filter((text) => text !== null), composableCode = await getComposableScript(options._layerComposableDirs ?? resolvedComposablesDir, result, pending);
382
- if (composableCode)
383
- composableTag = await externalBundleTag('data-stx-scoped data-stx-run="always" data-stx-composables', composableCode, options) ?? `<script data-stx-scoped data-stx-run="always" data-stx-composables>${composableCode}</script>`;
384
- } catch {}
385
- const tags = [modulesTag, storeTag, composableTag, frameworkScript].filter((text) => text !== null).map((tag) => `
386
- ${tag}`).join("");
387
- result = placeSignalsRuntimeBeforeScripts(result, tags);
450
+ const tags = await pageBundleTags(result, options, dependencies, context);
451
+ result = placeSignalsRuntimeBeforeScripts(result, tags.map((tag) => `
452
+ ${tag}`).join(""));
388
453
  } else {
389
454
  const modulesTag = await buildModulesTag([result], options, dependencies);
390
455
  if (modulesTag) {