@stacksjs/stx 0.2.874 → 0.2.875

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 (244) hide show
  1. package/dist/chunk-003ph86a.js +2 -0
  2. package/dist/chunk-027meh1k.js +2 -0
  3. package/dist/chunk-0bc3mwqd.js +2 -0
  4. package/dist/{chunk-gbtbfg7e.js → chunk-0g2mg8cw.js} +3 -3
  5. package/dist/chunk-0gv2mmr0.js +2 -0
  6. package/dist/{chunk-c8jhskx8.js → chunk-0h6r7nvn.js} +38 -38
  7. package/dist/chunk-0j8zre1m.js +2 -0
  8. package/dist/{chunk-vxtx0khv.js → chunk-0qwbhv3f.js} +9 -9
  9. package/dist/{chunk-6mkn81pd.js → chunk-0sa9gqmc.js} +7 -7
  10. package/dist/chunk-1gfg6qmr.js +2 -0
  11. package/dist/{chunk-6ftee542.js → chunk-1q5w3xav.js} +2 -2
  12. package/dist/chunk-1tqp2s13.js +2 -0
  13. package/dist/chunk-1y7kfp5d.js +2 -0
  14. package/dist/chunk-1ztp5vkh.js +3 -0
  15. package/dist/chunk-24e4dapm.js +2 -0
  16. package/dist/{chunk-c3kanj1m.js → chunk-2qb9kp21.js} +3 -3
  17. package/dist/{chunk-01mwbg1r.js → chunk-2zaatnnh.js} +4 -4
  18. package/dist/chunk-32wvc376.js +2 -0
  19. package/dist/{chunk-gxan9w4e.js → chunk-3f9wctns.js} +2 -2
  20. package/dist/{chunk-v4xes880.js → chunk-3mz9bdf7.js} +3 -3
  21. package/dist/chunk-3te2y9qf.js +2 -0
  22. package/dist/{chunk-farh4p7f.js → chunk-3w7gacva.js} +2 -2
  23. package/dist/chunk-447jc6zc.js +2 -0
  24. package/dist/{chunk-s584xnzx.js → chunk-4517hny7.js} +2 -2
  25. package/dist/chunk-45rzd16g.js +1609 -0
  26. package/dist/{chunk-p1a1kbhz.js → chunk-4m11kcxz.js} +8 -8
  27. package/dist/chunk-51ymssz5.js +2 -0
  28. package/dist/{chunk-a0dsp485.js → chunk-644ckv6e.js} +10 -10
  29. package/dist/{chunk-2xc457bf.js → chunk-6az66mrc.js} +14 -14
  30. package/dist/chunk-6dz5za5z.js +2 -0
  31. package/dist/{chunk-fr72bsqd.js → chunk-6ezt9kbe.js} +11 -11
  32. package/dist/chunk-6grkdknk.js +2 -0
  33. package/dist/chunk-6q9a5bph.js +2 -0
  34. package/dist/chunk-6rqef7wp.js +2 -0
  35. package/dist/{chunk-atpscb2m.js → chunk-6ykfy7eh.js} +2 -2
  36. package/dist/{chunk-wa3z5c8j.js → chunk-72p5annm.js} +4 -4
  37. package/dist/chunk-74x6j229.js +4 -0
  38. package/dist/{chunk-n3jw3xpj.js → chunk-75v0yxeh.js} +2 -2
  39. package/dist/chunk-7j11vgm1.js +3 -0
  40. package/dist/chunk-7ngfcdv9.js +2 -0
  41. package/dist/chunk-7njy024g.js +2 -0
  42. package/dist/{chunk-b8z3vepm.js → chunk-88xayf21.js} +9 -9
  43. package/dist/{chunk-w5nw8e2p.js → chunk-95hbmv7k.js} +7 -7
  44. package/dist/{chunk-nack2xs5.js → chunk-976kgb3r.js} +5 -5
  45. package/dist/{chunk-ykapdv6d.js → chunk-9anqwafq.js} +3 -3
  46. package/dist/chunk-9e3ggwk7.js +2 -0
  47. package/dist/chunk-9mz2n39m.js +2 -0
  48. package/dist/chunk-a262spx7.js +2 -0
  49. package/dist/{chunk-xakypz4t.js → chunk-a5yb8w7s.js} +3 -3
  50. package/dist/chunk-a8wn0snv.js +2 -0
  51. package/dist/{chunk-55zq2ha8.js → chunk-ae8q4gze.js} +5 -5
  52. package/dist/{chunk-n56x7jg8.js → chunk-af6m1s2b.js} +1 -1
  53. package/dist/{chunk-hev4t4d5.js → chunk-afxfkb60.js} +6 -6
  54. package/dist/{chunk-kdmwy40c.js → chunk-az5rh7fs.js} +2 -2
  55. package/dist/chunk-b1tcym2x.js +2 -0
  56. package/dist/{chunk-j1efsjsb.js → chunk-b4d4tjvx.js} +5 -5
  57. package/dist/{chunk-pqgc8k6k.js → chunk-b61dq7pz.js} +1 -1
  58. package/dist/{chunk-j89p53vx.js → chunk-bdh73gxd.js} +2 -2
  59. package/dist/{chunk-4068rmzv.js → chunk-bjjfr7qt.js} +2 -2
  60. package/dist/chunk-bs7g6jtt.js +2 -0
  61. package/dist/chunk-bspj1rf1.js +2 -0
  62. package/dist/chunk-bx3hpsxn.js +2 -0
  63. package/dist/chunk-byq488g4.js +2 -0
  64. package/dist/chunk-c8pzj57b.js +2 -0
  65. package/dist/{chunk-79mmzprp.js → chunk-cmh0bfkb.js} +5 -5
  66. package/dist/{chunk-7j0qkye5.js → chunk-d3q0cg47.js} +2 -2
  67. package/dist/{chunk-b666d8m6.js → chunk-d6gqh2wv.js} +1 -1
  68. package/dist/{chunk-vvxcebpn.js → chunk-dbvsa5ya.js} +2 -2
  69. package/dist/{chunk-zt9j94ak.js → chunk-dw0ttj6p.js} +2 -2
  70. package/dist/chunk-e2b2f502.js +2 -0
  71. package/dist/chunk-ec6mrad6.js +2 -0
  72. package/dist/chunk-eh2gec79.js +2 -0
  73. package/dist/{chunk-8hhhmscy.js → chunk-eknm4jrm.js} +2 -2
  74. package/dist/chunk-em31p5pb.js +2 -0
  75. package/dist/chunk-eqfsw6x4.js +2 -0
  76. package/dist/{chunk-4nb7egk0.js → chunk-esjr9qhe.js} +2 -2
  77. package/dist/chunk-ey1vwfpc.js +24 -0
  78. package/dist/{chunk-wk2rge05.js → chunk-f4vgagjb.js} +3 -3
  79. package/dist/chunk-fa57bncd.js +2 -0
  80. package/dist/{chunk-qjey0jk6.js → chunk-fdjx4vs3.js} +2 -2
  81. package/dist/chunk-fk79jbzn.js +2 -0
  82. package/dist/{chunk-pqy58ps0.js → chunk-fnjm3xbf.js} +6 -6
  83. package/dist/{chunk-zfrzdje6.js → chunk-ft6em3wm.js} +6 -6
  84. package/dist/{chunk-bv9dbf4m.js → chunk-fy6ts0n4.js} +2 -2
  85. package/dist/{chunk-hr147ys5.js → chunk-g33ycxe3.js} +5 -5
  86. package/dist/{chunk-p219rr27.js → chunk-g7qpnmbm.js} +14 -14
  87. package/dist/chunk-g97krv0d.js +2 -0
  88. package/dist/chunk-gn16yq49.js +2 -0
  89. package/dist/{chunk-qcxrcypb.js → chunk-gqtb53s8.js} +2 -2
  90. package/dist/chunk-gvs61tqn.js +2 -0
  91. package/dist/chunk-h2928108.js +2 -0
  92. package/dist/chunk-hd5bny2c.js +2 -0
  93. package/dist/chunk-j1ytbd6r.js +1184 -0
  94. package/dist/chunk-jm7qa3v3.js +2 -0
  95. package/dist/chunk-jmjgj3nh.js +2 -0
  96. package/dist/chunk-jqtpzzz4.js +12 -0
  97. package/dist/{chunk-hmdkf6c6.js → chunk-jqxerj6k.js} +2 -2
  98. package/dist/{chunk-3z1mmar2.js → chunk-jt5tzddc.js} +2 -2
  99. package/dist/{chunk-q50x1gfd.js → chunk-k1ew643q.js} +2 -2
  100. package/dist/chunk-kq8mffgf.js +2 -0
  101. package/dist/chunk-kx06jzdw.js +2 -0
  102. package/dist/{chunk-ysfeg3cn.js → chunk-kywe0f1v.js} +2 -2
  103. package/dist/{chunk-60yppcbb.js → chunk-kzc2tqzr.js} +2 -2
  104. package/dist/{chunk-9zrvh3pz.js → chunk-mce3g2wb.js} +2 -2
  105. package/dist/{chunk-bbq79tap.js → chunk-mw0rb1sf.js} +4 -4
  106. package/dist/chunk-n344ss97.js +2 -0
  107. package/dist/chunk-n5pvdrkb.js +2 -0
  108. package/dist/chunk-ne8q191s.js +2 -0
  109. package/dist/{chunk-e7s109j6.js → chunk-nnp6rf4c.js} +1 -1
  110. package/dist/chunk-np8wgbsa.js +3 -0
  111. package/dist/{chunk-tyvm49be.js → chunk-nv4c25zj.js} +3 -3
  112. package/dist/{chunk-xdfmrv49.js → chunk-p4e8myzj.js} +6 -6
  113. package/dist/{chunk-dhbpbjt3.js → chunk-p5m1z6e1.js} +6 -6
  114. package/dist/{chunk-18a3vdnq.js → chunk-pk714ynv.js} +4 -4
  115. package/dist/{chunk-csymxc5a.js → chunk-pp99rmjm.js} +15 -15
  116. package/dist/chunk-pqmjeea6.js +2 -0
  117. package/dist/chunk-q0k2gmva.js +2 -0
  118. package/dist/{chunk-3z4p70t5.js → chunk-q7zc78az.js} +6 -6
  119. package/dist/chunk-qggwr60r.js +2 -0
  120. package/dist/chunk-qm3v4qb7.js +2 -0
  121. package/dist/{chunk-40h07m5w.js → chunk-qnwd5bz4.js} +1 -1
  122. package/dist/chunk-qrn1nza9.js +2 -0
  123. package/dist/chunk-qty0t69x.js +2 -0
  124. package/dist/{chunk-tabkp672.js → chunk-qvrew79n.js} +1 -1
  125. package/dist/{chunk-tnp2ta5q.js → chunk-r09kz9bf.js} +2 -2
  126. package/dist/{chunk-q1wxgw5s.js → chunk-r2bxjna3.js} +2 -2
  127. package/dist/chunk-rzadf7vx.js +20 -0
  128. package/dist/{chunk-6vgr5g6d.js → chunk-rzd9hyhv.js} +2 -2
  129. package/dist/{chunk-8tk8yf91.js → chunk-s7fhpkvf.js} +6 -6
  130. package/dist/{chunk-ew5cey88.js → chunk-saqzk45g.js} +1 -1
  131. package/dist/{chunk-srgnevws.js → chunk-stn7p7f1.js} +2 -2
  132. package/dist/{chunk-bast33qy.js → chunk-t4g3ka8c.js} +6 -6
  133. package/dist/chunk-ts37jw3s.js +2 -0
  134. package/dist/{chunk-cqhwzd9y.js → chunk-v0tdg16k.js} +5 -5
  135. package/dist/{chunk-0k11nsv1.js → chunk-vmssv78v.js} +3 -3
  136. package/dist/{chunk-ymdw4fhd.js → chunk-vnrbjbrw.js} +2 -2
  137. package/dist/{chunk-ttm0gvrc.js → chunk-vznf808n.js} +5 -5
  138. package/dist/chunk-wkb7dhp7.js +2 -0
  139. package/dist/{chunk-m131znxe.js → chunk-wm029dh0.js} +13 -13
  140. package/dist/{chunk-hhbt8grm.js → chunk-wp0qpa50.js} +4 -4
  141. package/dist/chunk-wxyqp6g9.js +2 -0
  142. package/dist/{chunk-01c16zw4.js → chunk-wzvdr4ta.js} +2 -2
  143. package/dist/{chunk-e2t7mk29.js → chunk-x2ftkaz3.js} +2 -2
  144. package/dist/chunk-x76qvq1n.js +2 -0
  145. package/dist/{chunk-v37zmez0.js → chunk-xmws1gaf.js} +2 -2
  146. package/dist/{chunk-a8164hnf.js → chunk-xtaq95em.js} +1 -1
  147. package/dist/{chunk-5a0d3048.js → chunk-y2e2zm6y.js} +3 -3
  148. package/dist/chunk-y4hn1qh0.js +2 -0
  149. package/dist/{chunk-pywz8q4k.js → chunk-y75bds1g.js} +31 -31
  150. package/dist/chunk-yc8ggeh2.js +2 -0
  151. package/dist/{chunk-r0v2chpn.js → chunk-ydppkb8y.js} +2 -2
  152. package/dist/chunk-ydy0tfar.js +2 -0
  153. package/dist/chunk-yfed67yc.js +2 -0
  154. package/dist/{chunk-7ayvybdy.js → chunk-ysfgabpf.js} +3 -3
  155. package/dist/{chunk-fd1bpv35.js → chunk-yxdhz4ps.js} +2 -2
  156. package/dist/{chunk-rw5492e2.js → chunk-zc8a2erc.js} +4 -4
  157. package/dist/{chunk-7cvbz4eq.js → chunk-zn6n075d.js} +3 -3
  158. package/dist/cli.js +22 -22
  159. package/dist/component-library.d.ts +31 -1
  160. package/dist/component-library.js +74 -54
  161. package/dist/craft-entry.js +2 -2
  162. package/dist/craft.js +2 -2
  163. package/dist/inherited-context.d.ts +14 -0
  164. package/dist/inherited-context.js +102 -0
  165. package/dist/native-component-context.d.ts +10 -0
  166. package/dist/native-component-context.js +94 -0
  167. package/dist/pwa.js +3 -3
  168. package/dist/ssg.js +12 -12
  169. package/dist/stx-virtual-ts.d.ts +14 -2
  170. package/dist/stx-virtual-ts.js +64 -34
  171. package/dist/typecheck.d.ts +5 -2
  172. package/dist/typecheck.js +29 -19
  173. package/package.json +5 -5
  174. package/dist/chunk-09jz09k9.js +0 -20
  175. package/dist/chunk-10h8v5d4.js +0 -2
  176. package/dist/chunk-19dsn6tp.js +0 -2
  177. package/dist/chunk-26vxgd2w.js +0 -2
  178. package/dist/chunk-277dpq3b.js +0 -2
  179. package/dist/chunk-2asyyky3.js +0 -2
  180. package/dist/chunk-2r9s38f6.js +0 -2
  181. package/dist/chunk-2xhwadvn.js +0 -2
  182. package/dist/chunk-46pxmpeb.js +0 -3
  183. package/dist/chunk-4es07dwb.js +0 -2
  184. package/dist/chunk-4pr29yrx.js +0 -2
  185. package/dist/chunk-4v70bs2q.js +0 -2
  186. package/dist/chunk-4ygesqbx.js +0 -2
  187. package/dist/chunk-54jx5hqh.js +0 -2
  188. package/dist/chunk-5nj2k8zf.js +0 -2
  189. package/dist/chunk-6pczzq5f.js +0 -2
  190. package/dist/chunk-73k579v7.js +0 -2
  191. package/dist/chunk-7c9pzpsw.js +0 -2
  192. package/dist/chunk-7etvn4dx.js +0 -2
  193. package/dist/chunk-7wqevtks.js +0 -2
  194. package/dist/chunk-93538x9s.js +0 -2
  195. package/dist/chunk-9fyw1xkh.js +0 -3
  196. package/dist/chunk-9waxasf6.js +0 -712
  197. package/dist/chunk-a5qxcz86.js +0 -4
  198. package/dist/chunk-asrzmw7w.js +0 -2
  199. package/dist/chunk-awmfyb3t.js +0 -2
  200. package/dist/chunk-ba91r7q9.js +0 -2
  201. package/dist/chunk-cvgbtmxp.js +0 -2
  202. package/dist/chunk-d0h18m2r.js +0 -2
  203. package/dist/chunk-d5zh2663.js +0 -2
  204. package/dist/chunk-djdganvr.js +0 -2
  205. package/dist/chunk-dmcmxf3a.js +0 -2
  206. package/dist/chunk-eczy00w6.js +0 -2
  207. package/dist/chunk-esb34a1r.js +0 -20
  208. package/dist/chunk-f4wezqh4.js +0 -2
  209. package/dist/chunk-f52b9hjv.js +0 -2
  210. package/dist/chunk-f8pp58kw.js +0 -2
  211. package/dist/chunk-g3tfct27.js +0 -2
  212. package/dist/chunk-g9m84nqk.js +0 -2
  213. package/dist/chunk-gc4bgven.js +0 -2
  214. package/dist/chunk-gvh45ddc.js +0 -2
  215. package/dist/chunk-gvz0kqkz.js +0 -2
  216. package/dist/chunk-h2qgqjkn.js +0 -2
  217. package/dist/chunk-hcaedzck.js +0 -2
  218. package/dist/chunk-j4zrq17p.js +0 -2
  219. package/dist/chunk-kz0txvqb.js +0 -2
  220. package/dist/chunk-m9cperj4.js +0 -2
  221. package/dist/chunk-me7cxs0e.js +0 -2
  222. package/dist/chunk-meqsd5bt.js +0 -2
  223. package/dist/chunk-p2kqsb5k.js +0 -2
  224. package/dist/chunk-pvrgv5cx.js +0 -2051
  225. package/dist/chunk-rqa92xm4.js +0 -2
  226. package/dist/chunk-s54e61xt.js +0 -2
  227. package/dist/chunk-s92j8k4z.js +0 -2
  228. package/dist/chunk-sw8ms82g.js +0 -2
  229. package/dist/chunk-swfvh1cz.js +0 -3
  230. package/dist/chunk-tp2ftck2.js +0 -2
  231. package/dist/chunk-vd679g2w.js +0 -2
  232. package/dist/chunk-vk98r75z.js +0 -2
  233. package/dist/chunk-vmq773pb.js +0 -2
  234. package/dist/chunk-vv65gsys.js +0 -2
  235. package/dist/chunk-w6ry02z8.js +0 -2
  236. package/dist/chunk-w8qr5414.js +0 -2
  237. package/dist/chunk-xjxcwrqs.js +0 -2
  238. package/dist/chunk-xye2mkbh.js +0 -2
  239. package/dist/chunk-ytzzth34.js +0 -2
  240. package/dist/chunk-yxpjj003.js +0 -2
  241. package/dist/chunk-z6c4c951.js +0 -2
  242. package/dist/chunk-z9xe3xkg.js +0 -12
  243. package/dist/chunk-zmfqx1b1.js +0 -2
  244. package/dist/chunk-zze8tw0h.js +0 -2
@@ -48,21 +48,27 @@ async function discoverStxFiles(inputDir) {
48
48
  await visit(inputDir);
49
49
  return files;
50
50
  }
51
- function parseMetadata(source, file) {
52
- const match = source.match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);
51
+ export function componentScriptSource(source) {
52
+ return source.replace(/<!--[\s\S]*?-->|\{\{--[\s\S]*?--\}\}/g, (comment) => comment.replace(/[^\n]/g, " "));
53
+ }
54
+ export function parseMetadata(source, file) {
55
+ const match = componentScriptSource(source).match(/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))[^>]*>([\s\S]*?)<\/script>/i);
53
56
  if (!match)
54
57
  return {};
55
- const raw = match[1].trim();
58
+ const bodyStart = match.index + match[0].indexOf(">") + 1, raw = source.slice(bodyStart, bodyStart + match[1].length).trim();
56
59
  if (!raw)
57
60
  return {};
58
61
  try {
59
- return JSON.parse(raw);
62
+ const metadata = JSON.parse(raw);
63
+ if (!metadata || typeof metadata !== "object" || Array.isArray(metadata))
64
+ throw Error("expected a JSON object");
65
+ return metadata;
60
66
  } catch (error) {
61
67
  throw Error(`${file}: <script component> must contain JSON metadata (${error.message})`);
62
68
  }
63
69
  }
64
- function clientMethods(code) {
65
- const masked = stripCommentsAndLiterals(code), pattern = /(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)/g, result = [], parser = new Bun.Transpiler({ loader: "ts" });
70
+ export function clientMethods(code, validate) {
71
+ const masked = stripCommentsAndLiterals(code), pattern = /(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][\w$]*)/g, result = [], parser = validate ? void 0 : new Bun.Transpiler({ loader: "ts" });
66
72
  let match;
67
73
  while (match = pattern.exec(masked)) {
68
74
  let cursor = pattern.lastIndex;
@@ -86,16 +92,21 @@ function clientMethods(code) {
86
92
  if (token !== "{" && token !== ";")
87
93
  continue;
88
94
  const header = code.slice(match.index, cursor).trim();
89
- let compiled;
90
- try {
91
- compiled = parser.transformSync(header + (token === "{" ? "{}" : ";"));
92
- } catch {
93
- continue;
95
+ if (validate) {
96
+ if (!validate(header, token, match[1]))
97
+ continue;
98
+ } else {
99
+ let compiled;
100
+ try {
101
+ compiled = parser.transformSync(header + (token === "{" ? "{}" : ";"));
102
+ } catch {
103
+ continue;
104
+ }
105
+ if (token === "{" && !compiled.includes(`function ${match[1]}(`))
106
+ continue;
107
+ if (token === ";" && compiled.trim())
108
+ continue;
94
109
  }
95
- if (token === "{" && !compiled.includes(`function ${match[1]}(`))
96
- continue;
97
- if (token === ";" && compiled.trim())
98
- continue;
99
110
  const bodyEnd = token === "{" ? skipBalanced(masked, cursor, "{", "}") : cursor + 1;
100
111
  if (bodyEnd < 0)
101
112
  break;
@@ -103,6 +114,7 @@ function clientMethods(code) {
103
114
  name: match[1],
104
115
  header,
105
116
  generic,
117
+ parameterOffset: parameterStart + 1,
106
118
  parameters: code.slice(parameterStart + 1, parameterEnd - 1),
107
119
  returns: code.slice(parameterEnd, cursor).trim().replace(/^:\s*/, ""),
108
120
  async: /\basync\s+function/.test(match[0]),
@@ -114,7 +126,7 @@ function clientMethods(code) {
114
126
  }
115
127
  return result;
116
128
  }
117
- function methodDeclaration(method) {
129
+ export function methodDeclaration(method) {
118
130
  const parameters = splitTopLevel(method.parameters, ",", !0).flatMap((raw, index) => {
119
131
  const masked = stripCommentsAndLiterals(raw);
120
132
  let depth = 0, assignment = -1;
@@ -138,16 +150,17 @@ function methodDeclaration(method) {
138
150
  return `${method.name}${method.generic}(${parameters}): ${method.returns || (method.async ? "Promise<unknown>" : "unknown")}`;
139
151
  }
140
152
  function extractClientMethods(source, file) {
141
- const methods = {}, declarations = {}, types = [], imports = [], scripts = [...source.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];
153
+ const methods = {}, declarations = {}, types = [], imports = [], scripts = [...componentScriptSource(source).matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)];
142
154
  for (const script of scripts) {
155
+ const bodyStart = script.index + script[0].indexOf(">") + 1, code = source.slice(bodyStart, bodyStart + script[2].length);
143
156
  if (/\bserver\b|\bcomponent\b|\bstx:component\b/i.test(script[1]) || /\btype=["']application\//i.test(script[1]))
144
157
  continue;
145
158
  try {
146
- new Bun.Transpiler({ loader: "ts" }).transformSync(script[2]);
159
+ new Bun.Transpiler({ loader: "ts" }).transformSync(code);
147
160
  } catch (error) {
148
161
  throw Error(`${file}: failed to transpile <script client> (${error.message})`);
149
162
  }
150
- const extracted = /\bclient\b/i.test(script[1]) ? clientMethods(script[2]) : [], overloads = new Set(extracted.filter((method) => !method.source).map((method) => method.name));
163
+ const extracted = /\bclient\b/i.test(script[1]) ? clientMethods(code) : [], overloads = new Set(extracted.filter((method) => !method.source).map((method) => method.name));
151
164
  for (const method of extracted) {
152
165
  if (RESERVED_METHODS.has(method.name))
153
166
  throw Error(`${file}: client ${reservedMethodMessage(method.name)}`);
@@ -156,9 +169,9 @@ function extractClientMethods(source, file) {
156
169
  if (!method.source || !overloads.has(method.name))
157
170
  (declarations[method.name] ??= []).push(methodDeclaration(method));
158
171
  }
159
- for (const imported of script[2].matchAll(/^\s*import\s+(?:type\s+)?([\s\S]*?)\s+from\s*(['"])([^'"]+)\2\s*;?/gm))
172
+ for (const imported of code.matchAll(/^\s*import\s+(?:type\s+)?([\s\S]*?)\s+from\s*(['"])([^'"]+)\2\s*;?/gm))
160
173
  imports.push({ binding: imported[1].trim(), module: imported[3] });
161
- const masked = stripCommentsAndLiterals(script[2]), depths = bracketDepths(masked).depths, typePattern = /(?:export\s+)?(interface|type)\s+[A-Za-z_$][\w$]*/g;
174
+ const masked = stripCommentsAndLiterals(code), depths = bracketDepths(masked).depths, typePattern = /(?:export\s+)?(interface|type)\s+[A-Za-z_$][\w$]*/g;
162
175
  let match;
163
176
  while (match = typePattern.exec(masked)) {
164
177
  if (depths[match.index] !== 0)
@@ -187,12 +200,12 @@ function extractClientMethods(source, file) {
187
200
  ` && /^[\s]*[|&]/.test(masked.slice(cursor + 1)))
188
201
  continue;
189
202
  try {
190
- new Bun.Transpiler({ loader: "ts" }).transformSync(script[2].slice(match.index, cursor));
203
+ new Bun.Transpiler({ loader: "ts" }).transformSync(code.slice(match.index, cursor));
191
204
  break;
192
205
  } catch {}
193
206
  }
194
207
  }
195
- types.push(script[2].slice(match.index, cursor).replace(/^export\s+/, "").trim());
208
+ types.push(code.slice(match.index, cursor).replace(/^export\s+/, "").trim());
196
209
  typePattern.lastIndex = cursor + 1;
197
210
  }
198
211
  }
@@ -257,38 +270,43 @@ function literalValue(fallback) {
257
270
  return;
258
271
  }
259
272
  }
273
+ export function componentDirectiveExpression(source, open) {
274
+ if (source[open] !== "(")
275
+ return null;
276
+ let depth = 0, quote = "";
277
+ for (let index = open;index < source.length; index++) {
278
+ const char = source[index];
279
+ if (quote !== "") {
280
+ if (char === "\\")
281
+ index++;
282
+ else if (char === quote)
283
+ quote = "";
284
+ continue;
285
+ }
286
+ if (char === "'" || char === '"' || char === "`") {
287
+ quote = char;
288
+ continue;
289
+ }
290
+ if (char === "(")
291
+ depth++;
292
+ else if (char === ")") {
293
+ depth--;
294
+ if (depth === 0)
295
+ return { expression: source.slice(open + 1, index), end: index + 1 };
296
+ }
297
+ }
298
+ return null;
299
+ }
300
+ export function parseNativeComponentLoop(expression) {
301
+ const pair = /^([\s\S]+?)\s+as\s+(?:([A-Za-z_$][\w$]*)\s*=>\s*)?([A-Za-z_$][\w$]*)$/.exec(expression.trim());
302
+ return pair ? { iterable: pair[1], key: pair[2], value: pair[3] } : void 0;
303
+ }
260
304
  function compileTemplateToRender(template) {
261
305
  const parts = [];
262
306
  let cursor = 0;
263
307
  const source = template.replace(/\{\{--[\s\S]*?--\}\}/g, ""), directive = /@(if|elseif|else|endif|foreach|endforeach)\s*/g;
264
308
  let match;
265
- const expressionAt = (open) => {
266
- if (source[open] !== "(")
267
- return null;
268
- let depth = 0, quote = "";
269
- for (let index = open;index < source.length; index++) {
270
- const char = source[index];
271
- if (quote !== "") {
272
- if (char === "\\")
273
- index++;
274
- else if (char === quote)
275
- quote = "";
276
- continue;
277
- }
278
- if (char === "'" || char === '"' || char === "`") {
279
- quote = char;
280
- continue;
281
- }
282
- if (char === "(")
283
- depth++;
284
- else if (char === ")") {
285
- depth--;
286
- if (depth === 0)
287
- return { expression: source.slice(open + 1, index), end: index + 1 };
288
- }
289
- }
290
- return null;
291
- }, text = (raw) => {
309
+ const text = (raw) => {
292
310
  if (raw === "")
293
311
  return;
294
312
  let index = 0;
@@ -306,7 +324,7 @@ function compileTemplateToRender(template) {
306
324
  while (match = directive.exec(source)) {
307
325
  text(source.slice(cursor, match.index));
308
326
  cursor = match.index + match[0].length;
309
- const parsed = match[1] === "if" || match[1] === "elseif" || match[1] === "foreach" ? expressionAt(cursor) : null;
327
+ const parsed = match[1] === "if" || match[1] === "elseif" || match[1] === "foreach" ? componentDirectiveExpression(source, cursor) : null;
310
328
  if (parsed) {
311
329
  cursor = parsed.end;
312
330
  directive.lastIndex = parsed.end;
@@ -327,12 +345,12 @@ function compileTemplateToRender(template) {
327
345
  parts.push("}");
328
346
  break;
329
347
  case "foreach": {
330
- const pair = /^([\s\S]+?)\s+as\s+(?:([A-Za-z_$][\w$]*)\s*=>\s*)?([A-Za-z_$][\w$]*)$/.exec((expression || "").trim());
348
+ const pair = parseNativeComponentLoop(expression || "");
331
349
  if (!pair) {
332
350
  parts.push(`out += ${JSON.stringify(match[0] + (parsed ? `(${expression})` : ""))};`);
333
351
  break;
334
352
  }
335
- const [, iterable, key, value] = pair;
353
+ const { iterable, key, value } = pair;
336
354
  parts.push(key ? `for (const [${key}, ${value}] of __entries(${iterable})) {` : `for (const ${value} of __values(${iterable})) {`);
337
355
  break;
338
356
  }
@@ -1107,7 +1125,9 @@ defineComponent(${component.name}, ${definition});
1107
1125
  export default ${component.name};
1108
1126
  `;
1109
1127
  }
1110
- function typeForProperty(property) {
1128
+ export function typeForProperty(property) {
1129
+ if (!property || typeof property !== "object")
1130
+ return "unknown";
1111
1131
  switch (property.type) {
1112
1132
  case "boolean":
1113
1133
  return "boolean";
@@ -1,9 +1,9 @@
1
1
  // @bun
2
- import"./chunk-9waxasf6.js";import{Ro,Pa,Ia}from"./chunk-5a0d3048.js";import"./chunk-pywz8q4k.js";import"./chunk-csymxc5a.js";import"./chunk-qjey0jk6.js";import"./chunk-farh4p7f.js";import"./chunk-60yppcbb.js";import"./chunk-atpscb2m.js";import"./chunk-tnp2ta5q.js";import"./chunk-hhbt8grm.js";import"./chunk-2xc457bf.js";import"./chunk-6mkn81pd.js";import"./chunk-rw5492e2.js";import"./chunk-zt9j94ak.js";import"./chunk-a0dsp485.js";import"./chunk-c8jhskx8.js";import"./chunk-b8z3vepm.js";import"./chunk-fr72bsqd.js";import"./chunk-p1a1kbhz.js";import"./chunk-c3kanj1m.js";import"./chunk-q1wxgw5s.js";import"./chunk-wk2rge05.js";import{Tu,Oa,Dh,Mh,Na,Ao,os,Da,Ma,Lh,jh,La,ja,Ba,Fa}from"./chunk-p219rr27.js";import"./chunk-hr147ys5.js";import"./chunk-swfvh1cz.js";import"./chunk-vvxcebpn.js";import"./chunk-w5nw8e2p.js";import"./chunk-a8164hnf.js";import"./chunk-xakypz4t.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
2
+ import"./chunk-j1ytbd6r.js";import{Oo,Na,Da}from"./chunk-y2e2zm6y.js";import"./chunk-y75bds1g.js";import"./chunk-pp99rmjm.js";import"./chunk-fdjx4vs3.js";import"./chunk-3w7gacva.js";import"./chunk-kzc2tqzr.js";import"./chunk-6ykfy7eh.js";import"./chunk-r09kz9bf.js";import"./chunk-wp0qpa50.js";import"./chunk-6az66mrc.js";import"./chunk-0sa9gqmc.js";import"./chunk-zc8a2erc.js";import"./chunk-dw0ttj6p.js";import"./chunk-644ckv6e.js";import"./chunk-0h6r7nvn.js";import"./chunk-88xayf21.js";import"./chunk-6ezt9kbe.js";import"./chunk-4m11kcxz.js";import"./chunk-2qb9kp21.js";import"./chunk-r2bxjna3.js";import"./chunk-f4vgagjb.js";import{Au,Ma,jh,Bh,La,No,is,ja,Ba,Fh,zh,Fa,za,Ha,Va}from"./chunk-g7qpnmbm.js";import"./chunk-g33ycxe3.js";import"./chunk-7j11vgm1.js";import"./chunk-dbvsa5ya.js";import"./chunk-95hbmv7k.js";import"./chunk-xtaq95em.js";import"./chunk-a5yb8w7s.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{Tu as CRAFT_BRIDGE_SCRIPT,Ao as CRAFT_COMPONENTS,Da as CRAFT_COMPONENT_RUNTIME,os as CRAFT_COMPONENT_STYLES,Ro as NATIVE_COMPONENTS,La as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Pa as compileToNative,Ia as createHotReloadServer,ja as findCraftBinary,Oa as generateCraftBridgeScript,V as generateCraftOptimizations,Fa as getAvailableFormats,Ba as getAvailableTargets,jh as getCraftComponents,G as getSSRCacheStats,Na as injectCraftBridge,Dh as isCraftEnvironment,Y as prerenderForCraft,Ma as processCraftComponents,Mh as processCraftDirective,Lh 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{Au as CRAFT_BRIDGE_SCRIPT,No as CRAFT_COMPONENTS,ja as CRAFT_COMPONENT_RUNTIME,is as CRAFT_COMPONENT_STYLES,Oo as NATIVE_COMPONENTS,Fa as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Na as compileToNative,Da as createHotReloadServer,za as findCraftBinary,Ma as generateCraftBridgeScript,V as generateCraftOptimizations,Va as getAvailableFormats,Ha as getAvailableTargets,zh as getCraftComponents,G as getSSRCacheStats,La as injectCraftBridge,jh as isCraftEnvironment,Y as prerenderForCraft,Ba as processCraftComponents,Bh as processCraftDirective,Fh as registerCraftComponent,Q as renderSSR};
package/dist/craft.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // @bun
2
- import"./chunk-9waxasf6.js";import{Ro,Pa,Ia}from"./chunk-5a0d3048.js";import"./chunk-pywz8q4k.js";import"./chunk-csymxc5a.js";import"./chunk-qjey0jk6.js";import"./chunk-farh4p7f.js";import"./chunk-60yppcbb.js";import"./chunk-atpscb2m.js";import"./chunk-tnp2ta5q.js";import"./chunk-hhbt8grm.js";import"./chunk-2xc457bf.js";import"./chunk-6mkn81pd.js";import"./chunk-rw5492e2.js";import"./chunk-zt9j94ak.js";import"./chunk-a0dsp485.js";import"./chunk-c8jhskx8.js";import"./chunk-b8z3vepm.js";import"./chunk-fr72bsqd.js";import"./chunk-p1a1kbhz.js";import"./chunk-c3kanj1m.js";import"./chunk-q1wxgw5s.js";import"./chunk-wk2rge05.js";import{Tu,Oa,Dh,Mh,Na,Ao,os,Da,Ma,Lh,jh,La,ja,Ba,Fa}from"./chunk-p219rr27.js";import"./chunk-hr147ys5.js";import"./chunk-swfvh1cz.js";import"./chunk-vvxcebpn.js";import"./chunk-w5nw8e2p.js";import"./chunk-a8164hnf.js";import"./chunk-xakypz4t.js";var m=new Map,d=new Map;function R(t,e){let n=e?.id||E(t),r=I(t),a=m.get(n);if(a&&a.hash===r)return a;let i=M(t),s=L(t),o=W(t),c=O(i),{staticParts:p,dynamicParts:l}=A(i),f=_(t),g={id:n,hash:r,tree:i,scripts:s,styles:o,staticParts:p,dynamicParts:l,dependencies:f,metadata:c};return m.set(n,g),g}async function Q(t,e={},n={}){let r=performance.now();if(n.cache){let o=`${t.id}:${JSON.stringify(e)}`,c=d.get(o);if(c&&Date.now()-c.timestamp<(n.cacheTTL||60000))return{html:c.html,styles:t.styles.join(`
2
+ import"./chunk-j1ytbd6r.js";import{Oo,Na,Da}from"./chunk-y2e2zm6y.js";import"./chunk-y75bds1g.js";import"./chunk-pp99rmjm.js";import"./chunk-fdjx4vs3.js";import"./chunk-3w7gacva.js";import"./chunk-kzc2tqzr.js";import"./chunk-6ykfy7eh.js";import"./chunk-r09kz9bf.js";import"./chunk-wp0qpa50.js";import"./chunk-6az66mrc.js";import"./chunk-0sa9gqmc.js";import"./chunk-zc8a2erc.js";import"./chunk-dw0ttj6p.js";import"./chunk-644ckv6e.js";import"./chunk-0h6r7nvn.js";import"./chunk-88xayf21.js";import"./chunk-6ezt9kbe.js";import"./chunk-4m11kcxz.js";import"./chunk-2qb9kp21.js";import"./chunk-r2bxjna3.js";import"./chunk-f4vgagjb.js";import{Au,Ma,jh,Bh,La,No,is,ja,Ba,Fh,zh,Fa,za,Ha,Va}from"./chunk-g7qpnmbm.js";import"./chunk-g33ycxe3.js";import"./chunk-7j11vgm1.js";import"./chunk-dbvsa5ya.js";import"./chunk-95hbmv7k.js";import"./chunk-xtaq95em.js";import"./chunk-a5yb8w7s.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{Tu as CRAFT_BRIDGE_SCRIPT,Ao as CRAFT_COMPONENTS,Da as CRAFT_COMPONENT_RUNTIME,os as CRAFT_COMPONENT_STYLES,Ro as NATIVE_COMPONENTS,La as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Pa as compileToNative,Ia as createHotReloadServer,ja as findCraftBinary,Oa as generateCraftBridgeScript,V as generateCraftOptimizations,Fa as getAvailableFormats,Ba as getAvailableTargets,jh as getCraftComponents,G as getSSRCacheStats,Na as injectCraftBridge,Dh as isCraftEnvironment,Y as prerenderForCraft,Ma as processCraftComponents,Mh as processCraftDirective,Lh 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{Au as CRAFT_BRIDGE_SCRIPT,No as CRAFT_COMPONENTS,ja as CRAFT_COMPONENT_RUNTIME,is as CRAFT_COMPONENT_STYLES,Oo as NATIVE_COMPONENTS,Fa as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Na as compileToNative,Da as createHotReloadServer,za as findCraftBinary,Ma as generateCraftBridgeScript,V as generateCraftOptimizations,Va as getAvailableFormats,Ha as getAvailableTargets,zh as getCraftComponents,G as getSSRCacheStats,La as injectCraftBridge,jh as isCraftEnvironment,Y as prerenderForCraft,Ba as processCraftComponents,Bh as processCraftDirective,Fh as registerCraftComponent,Q as renderSSR};
@@ -0,0 +1,14 @@
1
+ import type { ContractCheck } from './component-contract-checks.js';
2
+ export declare function inheritedContextContract(code: string): Contract | undefined;
3
+ /** These names are already present at runtime; only an explicit contract types them. */
4
+ export declare function inheritedContextBindings(code: string): string;
5
+ export declare function inheritedContextChecks(source: string, options: InheritedContextOptions): { declarations: string, checks: ContractCheck[], dependencies: Map<string, string> };
6
+ declare interface Contract { keys: string[], types: string }
7
+ export declare interface InheritedContextOptions {
8
+ filePath: string
9
+ partialsDir?: string
10
+ layoutsDir?: string
11
+ contractsKnown?: boolean
12
+ readTemplate?: (file: string) => string | undefined
13
+ }
14
+ export {};
@@ -0,0 +1,102 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { componentContract, COMPONENT_CONTRACT_HELPERS } from "./component-contract.js";
4
+ import { componentDirectiveExpression } from "./component-library.js";
5
+ import { stripCommentsAndLiterals } from "./strip-literals.js";
6
+ import { absolutizeRelativeSpecifiers, blankScriptDirectives, collectBlockDeclarations, extractScriptBlocks, extractTypeDeclarations, maskNonTemplateRegions, typeScopeImports } from "./stx-virtual-ts.js";
7
+ export function inheritedContextContract(code) {
8
+ const types = extractTypeDeclarations(code), declaration = types.find((type) => type.name === "InheritedContext");
9
+ if (!declaration)
10
+ return;
11
+ const body = declaration.text.slice(declaration.text.indexOf("{") + 1, declaration.text.lastIndexOf("}"));
12
+ return { keys: [...stripCommentsAndLiterals(body).matchAll(/(?:^|[;\n])\s*(?:readonly\s+)?([A-Za-z_$][\w$]*)\??\s*:/g)].map((match) => match[1]), types: types.map((type) => type.text).join(`
13
+ `) };
14
+ }
15
+ export function inheritedContextBindings(code) {
16
+ const contract = inheritedContextContract(code);
17
+ if (!contract)
18
+ return "";
19
+ const own = new Set(collectBlockDeclarations(code));
20
+ return contract.keys.filter((key) => !own.has(key)).map((key) => `declare const ${key}: InheritedContext[${JSON.stringify(key)}];`).join(`
21
+ `);
22
+ }
23
+ export function inheritedContextChecks(source, options) {
24
+ const declarations = [COMPONENT_CONTRACT_HELPERS], checks = [], dependencies = new Map, file = path.resolve(options.filePath), views = file.split(path.sep).lastIndexOf("views"), inferredRoot = views >= 0 ? file.split(path.sep).slice(0, views).join(path.sep) : path.dirname(file), partials = path.resolve(options.partialsDir || path.join(inferredRoot, "partials")), layouts = path.resolve(options.layoutsDir || path.join(inferredRoot, "views/layouts"));
25
+ if ([partials, layouts].some((directory) => file === directory || file.startsWith(directory + path.sep)))
26
+ return { declarations: "", checks, dependencies };
27
+ const read = (target) => options.readTemplate?.(target) ?? (fs.existsSync(target) ? fs.readFileSync(target, "utf8") : void 0);
28
+ let next = 0, foundContract = !1;
29
+ const limitations = [];
30
+ function check(offset, text) {
31
+ const line = source.slice(0, offset).split(`
32
+ `).length, column = offset - source.lastIndexOf(`
33
+ `, offset - 1), expression = { code: source.slice(offset, source.indexOf(`
34
+ `, offset) < 0 ? source.length : source.indexOf(`
35
+ `, offset)), line, column, kind: "directive", offset, anchor: !0 };
36
+ checks.push({ expression, statement: { text, prefixLength: 0 } });
37
+ }
38
+ function visit(text, currentFile, parentType, parentKeys, anchor, stack) {
39
+ const id = `__StxInherited${next++}`, code = extractScriptBlocks(text).filter((block) => block.kind === "server").map((block) => block.code).join(`
40
+ `), scope = typeScopeImports(absolutizeRelativeSpecifiers(code, path.dirname(currentFile)), id);
41
+ declarations.push(...scope.imports);
42
+ const contract = inheritedContextContract(code);
43
+ if (contract && anchor !== void 0) {
44
+ foundContract = !0;
45
+ const imports = scope.imports.length ? scope.aliases.join(`
46
+ `) : "", projected = componentContract(`${imports}
47
+ ${contract.types}
48
+ const __contract = defineProps<InheritedContext>();`, `${id}Contract`);
49
+ declarations.push(projected.declarations);
50
+ declarations.push(`declare const ${id}Input: ${parentType};`);
51
+ check(anchor, `${id}Input satisfies ${projected.props};`);
52
+ }
53
+ const own = collectBlockDeclarations(code), input = [...new Set([...parentKeys, ...contract?.keys || []])].filter((key) => !own.includes(key)), inheritedType = contract ? `${parentType} & ${id}Contract.__StxProps` : parentType, body = blankScriptDirectives(scope.body).replace(/^[ \t]*export[ \t]+(?=(?:const|let|var|function|async|class|interface|type)\b)/gm, ""), edges = [], masked = maskNonTemplateRegions(text), directive = /@(include|extends|layout)\s*\(/g;
54
+ let match;
55
+ while (match = directive.exec(masked)) {
56
+ const parsed = componentDirectiveExpression(masked, directive.lastIndex - 1);
57
+ if (!parsed)
58
+ continue;
59
+ directive.lastIndex = parsed.end;
60
+ const literal = /^\s*(['"])(.*?)\1\s*(?:,\s*([\s\S]*))?$/.exec(parsed.expression);
61
+ if (!literal) {
62
+ limitations.push({ offset: anchor ?? match.index, message: `Inherited context cannot be checked across dynamic @${match[1]}` });
63
+ continue;
64
+ }
65
+ const name = literal[2], kind = match[1];
66
+ if (kind !== "include" && literal[3])
67
+ limitations.push({ offset: anchor ?? match.index, message: `Inherited context cannot be checked for unsupported @${kind} data arguments` });
68
+ const directory = kind === "include" ? partials : layouts, target = path.resolve(name.startsWith(".") ? path.dirname(currentFile) : directory, name.endsWith(".stx") ? name : name + ".stx");
69
+ if (read(target) === void 0) {
70
+ limitations.push({ offset: anchor ?? match.index, message: `Inherited context target cannot be resolved: ${name}` });
71
+ continue;
72
+ }
73
+ edges.push({ name: `edge${edges.length}`, target, kind, args: kind === "include" ? literal[3] || "{}" : "{}", offset: anchor ?? match.index });
74
+ }
75
+ const context = `{ ...parent${own.length ? ", " + own.join(", ") : ""} }`;
76
+ declarations.push(`namespace ${id} {
77
+ ${scope.aliases.join(`
78
+ `)}
79
+ export async function read(parent: ${anchor === void 0 ? "{}" : inheritedType}) {
80
+ ${input.length ? `const { ${input.join(", ")} } = parent;` : ""}
81
+ ${body}
82
+ return { context: ${context}${edges.map((edge) => `, ${edge.name}: { ...${context}, ...(${edge.args}) }`).join("")} };
83
+ }
84
+ }`);
85
+ for (const edge of edges) {
86
+ if (stack.includes(edge.target) || stack.length >= 32) {
87
+ limitations.push({ offset: edge.offset, message: "Inherited context cannot be checked across a cyclic or overly deep template graph" });
88
+ continue;
89
+ }
90
+ const target = read(edge.target);
91
+ dependencies.set(edge.target, target);
92
+ visit(target, edge.target, `Awaited<ReturnType<typeof ${id}.read>>[${JSON.stringify(edge.name)}]`, [...new Set([...parentKeys, ...own])], edge.offset, [...stack, edge.target]);
93
+ }
94
+ return id;
95
+ }
96
+ visit(source, file, "{}", [], void 0, [file]);
97
+ if (foundContract || options.contractsKnown)
98
+ for (const limit of limitations)
99
+ check(limit.offset, `({})[${JSON.stringify(limit.message)}];`);
100
+ return { declarations: foundContract ? declarations.join(`
101
+ `) : "", checks, dependencies };
102
+ }
@@ -0,0 +1,10 @@
1
+ import type { ClientMethodValidator } from './component-library.js';
2
+ import type { ScriptColumnEdit } from './stx-virtual-ts.js';
3
+ export declare function nativeComponentContext(source: string, validate?: ClientMethodValidator): NativeComponentContext | undefined;
4
+ /** Native block loops are lexical, including sibling and nested aliases. */
5
+ export declare function nativeComponentLoops(masked: string): Array<{ start: number, end: number, iterable: string, binding: string }>;
6
+ export declare interface NativeComponentContext {
7
+ declarations: string
8
+ checks: Array<{ text: string, line: number, column: number, origin: 'client' | 'component' }>
9
+ project(code: string): { code: string, columns: Map<number, ScriptColumnEdit[]> }
10
+ }
@@ -0,0 +1,94 @@
1
+ import { clientMethods, componentScriptSource, componentDirectiveExpression, parseMetadata, parseNativeComponentLoop, typeForProperty } from "./component-library.js";
2
+ import { stripCommentsAndLiterals } from "./strip-literals.js";
3
+ export function nativeComponentContext(source, validate) {
4
+ const scannable = componentScriptSource(source);
5
+ if (!/<script\b(?=[^>]*(?:\bcomponent\b|\bstx:component\b))/i.test(scannable))
6
+ return;
7
+ let metadata;
8
+ try {
9
+ metadata = parseMetadata(source, "component");
10
+ } catch (error) {
11
+ const at = source.search(/<script\b(?=[^>]*\bcomponent\b)/i), message = error instanceof Error ? error.message : "Invalid component metadata";
12
+ return { declarations: "", checks: [{ text: `({})[${JSON.stringify(message)}];`, line: source.slice(0, at).split(`
13
+ `).length, column: at - source.lastIndexOf(`
14
+ `, at - 1), origin: "component" }], project: (code) => ({ code, columns: new Map }) };
15
+ }
16
+ const blocks = [...scannable.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)].filter((block) => /\bclient\b/.test(block[1]) && !/\bcomponent\b/.test(block[1])), script = blocks.map((block) => {
17
+ const at = block.index + block[0].indexOf(">") + 1;
18
+ return source.slice(at, at + block[2].length);
19
+ }).join(`
20
+ `), methods = clientMethods(script, validate), hasState = /\b(?:interface|type)\s+ComponentState\b/.test(stripCommentsAndLiterals(script)), properties = Object.entries(metadata.properties || metadata.props || {}).map(([name, property]) => `${JSON.stringify(name)}: ${typeForProperty(property)}`).join("; "), names = [...new Set(methods.map((method) => method.name))], declarations = [
21
+ `interface __StxNativeProperties { ${properties} }`,
22
+ hasState ? "declare const __stxStateProperties: Pick<ComponentState, Extract<keyof ComponentState, keyof __StxNativeProperties>>;" : "",
23
+ `type __StxNativeComponent = Omit<HTMLElement, keyof __StxNativeProperties | ${hasState ? "keyof ComponentState | " : ""}${names.map((name) => JSON.stringify(name)).join(" | ") || "never"}> & ${hasState ? "Omit<__StxNativeProperties, keyof ComponentState> & ComponentState" : "__StxNativeProperties"} & {`,
24
+ "readonly updateComplete: Promise<void>; requestUpdate(): Promise<void>; readonly renderRoot: HTMLElement | ShadowRoot;",
25
+ "emit<T = unknown>(name: string, detail?: T, options?: CustomEventInit<T>): boolean;",
26
+ ...names.map((name) => `${JSON.stringify(name)}: typeof ${name};`),
27
+ "}"
28
+ ].filter(Boolean).join(`
29
+ `);
30
+ let stateOffset = -1;
31
+ for (const block of blocks) {
32
+ const bodyStart = block.index + block[0].indexOf(">") + 1, found = /\b(?:interface|type)\s+ComponentState\b/.exec(stripCommentsAndLiterals(source.slice(bodyStart, bodyStart + block[2].length)));
33
+ if (found) {
34
+ stateOffset = bodyStart + found.index;
35
+ break;
36
+ }
37
+ }
38
+ const checks = hasState && stateOffset >= 0 ? [{ origin: "client", text: "__stxStateProperties satisfies Pick<__StxNativeProperties, Extract<keyof ComponentState, keyof __StxNativeProperties>>;", line: source.slice(0, stateOffset).split(`
39
+ `).length, column: stateOffset - source.lastIndexOf(`
40
+ `, stateOffset - 1) }] : [];
41
+ for (const [name, property] of Object.entries(metadata.properties || metadata.props || {})) {
42
+ const at = source.indexOf(JSON.stringify(name), source.indexOf("<script")), line = source.slice(0, at).split(`
43
+ `).length, column = at - source.lastIndexOf(`
44
+ `, at - 1);
45
+ if (!property || typeof property !== "object" || !["string", "number", "boolean", "object", "array"].includes(property.type))
46
+ checks.push({ text: `({})[${JSON.stringify(`Property ${name} must declare string, number, boolean, object or array`)}];`, line, column, origin: "component" });
47
+ if (property && property.default !== void 0)
48
+ checks.push({ text: `const __stxDefault${checks.length}: ${typeForProperty(property)} = ${JSON.stringify(property.default)};`, line, column, origin: "component" });
49
+ }
50
+ return {
51
+ declarations,
52
+ checks,
53
+ project(code) {
54
+ const columns = new Map, chunks = [];
55
+ let cursor = 0;
56
+ for (const method of clientMethods(code, validate)) {
57
+ if (/^\s*this\s*:/.test(method.parameters))
58
+ continue;
59
+ const at = method.parameterOffset, inserted = `this: __StxNativeComponent${method.parameters.trim() ? ", " : ""}`;
60
+ chunks.push(code.slice(cursor, at), inserted);
61
+ const line = code.slice(0, at).split(`
62
+ `).length, column = at - code.lastIndexOf(`
63
+ `, at - 1), edits = columns.get(line) || [], previous = edits.at(-1), generatedStart = column + (previous ? previous.generatedEnd - previous.sourceEnd : 0);
64
+ edits.push({ sourceStart: column, sourceEnd: column, generatedStart, generatedEnd: generatedStart + inserted.length });
65
+ columns.set(line, edits);
66
+ cursor = at;
67
+ }
68
+ chunks.push(code.slice(cursor));
69
+ return { code: chunks.join(""), columns };
70
+ }
71
+ };
72
+ }
73
+ export function nativeComponentLoops(masked) {
74
+ const scopes = [], stack = [], tokens = /@foreach\s*\(|@endforeach\b/g;
75
+ let token;
76
+ while (token = tokens.exec(masked)) {
77
+ if (token[0].startsWith("@endforeach")) {
78
+ const scope = stack.pop();
79
+ if (scope) {
80
+ scope.end = token.index;
81
+ scopes.push(scope);
82
+ }
83
+ continue;
84
+ }
85
+ const parsed = componentDirectiveExpression(masked, tokens.lastIndex - 1);
86
+ if (!parsed)
87
+ continue;
88
+ const loop = parseNativeComponentLoop(parsed.expression), cursor = parsed.end;
89
+ if (loop)
90
+ stack.push({ start: cursor, end: masked.length, iterable: loop.iterable, binding: loop.key ? `${loop.value}, ${loop.key}` : loop.value });
91
+ tokens.lastIndex = cursor;
92
+ }
93
+ return scopes.sort((a, b) => a.start - b.start);
94
+ }