@stacksjs/stx 0.2.887 → 0.2.889

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 (242) hide show
  1. package/dist/{chunk-c0g30cjs.js → chunk-05x1rd86.js} +2 -2
  2. package/dist/chunk-0g9cceht.js +2 -0
  3. package/dist/chunk-0k437z3q.js +2 -0
  4. package/dist/{chunk-69ezjc8k.js → chunk-0ncafcs2.js} +4 -4
  5. package/dist/chunk-0rpj5t80.js +2 -0
  6. package/dist/{chunk-sc1gmts0.js → chunk-1gyxxfdf.js} +2 -2
  7. package/dist/{chunk-aaea157p.js → chunk-1knk403z.js} +2 -2
  8. package/dist/{chunk-q74affc4.js → chunk-1n33yrar.js} +2 -2
  9. package/dist/chunk-1p4q6t48.js +2 -0
  10. package/dist/chunk-1z6pqvmf.js +2 -0
  11. package/dist/{chunk-s29hp1qw.js → chunk-2a5g80mq.js} +3 -3
  12. package/dist/chunk-2ba4zfa0.js +2 -0
  13. package/dist/chunk-2gn2nc2j.js +2 -0
  14. package/dist/chunk-2nqmw4dv.js +2 -0
  15. package/dist/chunk-2wkpksg1.js +2 -0
  16. package/dist/chunk-3dqfjpz4.js +68 -0
  17. package/dist/{chunk-zpj6ggee.js → chunk-3hsv6ejp.js} +4 -4
  18. package/dist/{chunk-8e1cv1hh.js → chunk-3qk8vf9m.js} +3 -3
  19. package/dist/chunk-3yjyjq0m.js +2 -0
  20. package/dist/chunk-444haxxa.js +2 -0
  21. package/dist/{chunk-azf6tdq6.js → chunk-446tb2th.js} +28 -28
  22. package/dist/{chunk-4251fy7d.js → chunk-48rwqchc.js} +11 -11
  23. package/dist/chunk-4akw3bym.js +2 -0
  24. package/dist/{chunk-twmkz0xs.js → chunk-4kmg6g5n.js} +9 -9
  25. package/dist/chunk-4rvfeee5.js +2 -0
  26. package/dist/{chunk-4n45qa0b.js → chunk-51720m79.js} +5 -5
  27. package/dist/chunk-53kcqdjj.js +2 -0
  28. package/dist/{chunk-02qmvcmv.js → chunk-55tc5w32.js} +3 -3
  29. package/dist/{chunk-0mx7rg07.js → chunk-58qzyyyv.js} +3 -3
  30. package/dist/chunk-5aa83bpm.js +2 -0
  31. package/dist/{chunk-d2pexm3z.js → chunk-5kqezrjt.js} +2 -2
  32. package/dist/chunk-5ssv10ep.js +2 -0
  33. package/dist/chunk-67rppc5v.js +2 -0
  34. package/dist/{chunk-care745q.js → chunk-6gtecbe7.js} +2 -2
  35. package/dist/{chunk-km14pdrt.js → chunk-6kyqejnq.js} +22 -22
  36. package/dist/{chunk-32twt3wx.js → chunk-6pdy7ajr.js} +3 -3
  37. package/dist/{chunk-fg67643b.js → chunk-6pz5gq6v.js} +9 -9
  38. package/dist/{chunk-rsxxajv6.js → chunk-700m927w.js} +2 -2
  39. package/dist/{chunk-gvd8nb8z.js → chunk-7212fwzz.js} +2 -2
  40. package/dist/chunk-732gb689.js +2 -0
  41. package/dist/chunk-77c89d23.js +2 -0
  42. package/dist/chunk-79vbkez0.js +2 -0
  43. package/dist/{chunk-88tshy2f.js → chunk-7hpca9c7.js} +6 -6
  44. package/dist/chunk-80xzjxah.js +2 -0
  45. package/dist/chunk-8354mzpd.js +2 -0
  46. package/dist/{chunk-2v7v6jcs.js → chunk-87g5xmmr.js} +12 -12
  47. package/dist/{chunk-sv7fdqmc.js → chunk-8hwfdwgn.js} +6 -6
  48. package/dist/chunk-8ygf6jnt.js +2 -0
  49. package/dist/{chunk-0rdh8bw3.js → chunk-95sd8h5g.js} +7 -7
  50. package/dist/{chunk-50cnypys.js → chunk-967ydrq4.js} +6 -6
  51. package/dist/chunk-9afkttvz.js +2 -0
  52. package/dist/{chunk-7wqz32ay.js → chunk-9d91h636.js} +2 -2
  53. package/dist/{chunk-kwf3kfr0.js → chunk-9n5h4sqc.js} +2 -2
  54. package/dist/chunk-9ztn7w4y.js +2 -0
  55. package/dist/chunk-ah8az9vv.js +2 -0
  56. package/dist/chunk-ankap9pc.js +2 -0
  57. package/dist/chunk-asnd03sr.js +2 -0
  58. package/dist/chunk-b0b5yr97.js +2 -0
  59. package/dist/chunk-b0e7dgv8.js +3 -0
  60. package/dist/{chunk-zj5eq4b6.js → chunk-b15c4g3e.js} +5 -5
  61. package/dist/{chunk-czcx3nbx.js → chunk-b6bf0t02.js} +6 -6
  62. package/dist/chunk-b7jj45bz.js +2 -0
  63. package/dist/{chunk-ybjgnnyf.js → chunk-bgfs3mbg.js} +5 -5
  64. package/dist/{chunk-f2twg7ze.js → chunk-bqtj62ys.js} +8 -8
  65. package/dist/{chunk-a0q0kb0s.js → chunk-bw2m1e7g.js} +5 -5
  66. package/dist/chunk-bwx6w87c.js +2 -0
  67. package/dist/{chunk-ef9m5fjb.js → chunk-cgfjrgfw.js} +14 -14
  68. package/dist/{chunk-463weehv.js → chunk-ch9028z3.js} +1 -1
  69. package/dist/{chunk-57q4nvs9.js → chunk-cmg9x1ka.js} +3 -3
  70. package/dist/{chunk-9f31gs4m.js → chunk-cz1sdes5.js} +2 -2
  71. package/dist/{chunk-satrf398.js → chunk-dvjv4c3a.js} +1 -1
  72. package/dist/{chunk-dz7amds0.js → chunk-dymck524.js} +5 -5
  73. package/dist/chunk-dzqfv801.js +3 -0
  74. package/dist/{chunk-agd2b928.js → chunk-eceeqy74.js} +4 -4
  75. package/dist/{chunk-c47stwqj.js → chunk-eqffvse2.js} +1 -1
  76. package/dist/chunk-ery4tty7.js +20 -0
  77. package/dist/chunk-evwrxsxd.js +3 -0
  78. package/dist/{chunk-6t04tqvh.js → chunk-eyx92t9n.js} +2 -2
  79. package/dist/{chunk-6mfpns00.js → chunk-f3cyghnb.js} +5 -5
  80. package/dist/chunk-f60k8j9m.js +2 -0
  81. package/dist/chunk-fdqdz018.js +2 -0
  82. package/dist/chunk-g6ap4085.js +2 -0
  83. package/dist/chunk-gz9pknbw.js +1204 -0
  84. package/dist/{chunk-pgrm1vet.js → chunk-hgf7bc50.js} +7 -7
  85. package/dist/chunk-hjb4c8g2.js +2 -0
  86. package/dist/chunk-hk241gt2.js +2 -0
  87. package/dist/{chunk-yasdj4ve.js → chunk-hm9d40yf.js} +2 -2
  88. package/dist/{chunk-6df3j3qq.js → chunk-hpzje67q.js} +2 -2
  89. package/dist/{chunk-qt39mb2a.js → chunk-htx5yezj.js} +2 -2
  90. package/dist/{chunk-xpbakn6t.js → chunk-hxws025y.js} +3 -3
  91. package/dist/chunk-jhbj9ja2.js +2 -0
  92. package/dist/chunk-k4x680e3.js +2 -0
  93. package/dist/chunk-k9abxnpa.js +2 -0
  94. package/dist/{chunk-c73c0wf9.js → chunk-kbbbpae2.js} +2 -2
  95. package/dist/chunk-kfdmm240.js +2 -0
  96. package/dist/{chunk-xcsgpf83.js → chunk-kj43fbzm.js} +1 -1
  97. package/dist/{chunk-59er0fc7.js → chunk-kk2p2tgv.js} +3 -3
  98. package/dist/{chunk-dwyhpbpx.js → chunk-ksmn19qw.js} +2 -2
  99. package/dist/{chunk-16aqrwmk.js → chunk-kx09v9ya.js} +7 -7
  100. package/dist/{chunk-3bfheqe3.js → chunk-m95sygv4.js} +3 -3
  101. package/dist/{chunk-nzpzyz22.js → chunk-mctzpw0w.js} +1 -1
  102. package/dist/{chunk-y6eaqs8v.js → chunk-me4yq8c2.js} +3 -3
  103. package/dist/{chunk-n22xtagg.js → chunk-mgh5rst1.js} +2 -2
  104. package/dist/{chunk-zch65qrd.js → chunk-mhxg6j6s.js} +1 -1
  105. package/dist/{chunk-pc8dt8xs.js → chunk-mjp1z9kz.js} +1 -1
  106. package/dist/{chunk-gtv9jd68.js → chunk-mt8edb75.js} +49 -49
  107. package/dist/chunk-mvavjydq.js +2 -0
  108. package/dist/{chunk-e362e615.js → chunk-mw7hacm3.js} +30 -30
  109. package/dist/{chunk-cv4bfhn1.js → chunk-nbdscgvj.js} +6 -6
  110. package/dist/{chunk-qx1nbryq.js → chunk-njpva3zq.js} +2 -2
  111. package/dist/{chunk-6qpe4f8e.js → chunk-nkyff7v6.js} +11 -11
  112. package/dist/{chunk-mxvgft6p.js → chunk-p8shtje2.js} +32 -32
  113. package/dist/{chunk-cb0c6959.js → chunk-pctf14yw.js} +1 -1
  114. package/dist/{chunk-3cq4a4x7.js → chunk-pjj54ddk.js} +3 -3
  115. package/dist/{chunk-pdprhg5k.js → chunk-pnmafbv5.js} +1 -1
  116. package/dist/{chunk-kee5a3ce.js → chunk-pz554g43.js} +3 -3
  117. package/dist/{chunk-h63ma36g.js → chunk-q0y8gv18.js} +2 -2
  118. package/dist/{chunk-ws2h92mm.js → chunk-q9tc9rdv.js} +2 -2
  119. package/dist/chunk-qqng9545.js +2 -0
  120. package/dist/{chunk-8va3fs07.js → chunk-r5ecgcx2.js} +5 -5
  121. package/dist/{chunk-q1mb0fbt.js → chunk-ranjkpc8.js} +2 -2
  122. package/dist/{chunk-ssg6ne5b.js → chunk-rb2zbdqd.js} +4 -4
  123. package/dist/{chunk-e41pgmgk.js → chunk-rf0smj4c.js} +2 -2
  124. package/dist/chunk-rjm515e2.js +2 -0
  125. package/dist/chunk-rye4b2x3.js +2 -0
  126. package/dist/chunk-ryj8139z.js +2 -0
  127. package/dist/{chunk-q3epnfp4.js → chunk-s0mf56y1.js} +5 -5
  128. package/dist/{chunk-kaem8q20.js → chunk-s93yh7ed.js} +2 -2
  129. package/dist/chunk-s9b809n2.js +2 -0
  130. package/dist/chunk-sb67wg5x.js +2 -0
  131. package/dist/{chunk-rv0a3stz.js → chunk-sjjw6y49.js} +6 -6
  132. package/dist/chunk-snkbn5y8.js +2 -0
  133. package/dist/{chunk-7mcs59pr.js → chunk-snv80b1b.js} +2 -2
  134. package/dist/chunk-sqwx2g02.js +2 -0
  135. package/dist/{chunk-2r0nrvqe.js → chunk-t0ttxayz.js} +2 -2
  136. package/dist/chunk-tbh7r1wh.js +2 -0
  137. package/dist/chunk-tpyekw0q.js +2 -0
  138. package/dist/chunk-v2627s75.js +2 -0
  139. package/dist/chunk-v3jyb8k6.js +2 -0
  140. package/dist/chunk-v98n53nk.js +2 -0
  141. package/dist/{chunk-sfyyn0mg.js → chunk-vc432a0w.js} +9 -9
  142. package/dist/{chunk-a7ryj8z8.js → chunk-vf4ejngv.js} +6 -6
  143. package/dist/{chunk-hxhmhw23.js → chunk-vk2jy6mn.js} +3 -3
  144. package/dist/chunk-w34vvhm7.js +2 -0
  145. package/dist/chunk-w82nk19t.js +2 -0
  146. package/dist/{chunk-ezna4dhj.js → chunk-x5bn2svk.js} +2 -2
  147. package/dist/chunk-x6565mhk.js +2 -0
  148. package/dist/{chunk-gbncp2gp.js → chunk-xvncq3m5.js} +2 -2
  149. package/dist/chunk-xwgdcc7w.js +2 -0
  150. package/dist/{chunk-ram5944w.js → chunk-xy8smv5e.js} +2 -2
  151. package/dist/{chunk-yp4tn4zn.js → chunk-y1d3j2j7.js} +4 -4
  152. package/dist/chunk-yjwa7ktk.js +2 -0
  153. package/dist/{chunk-94ctmp0j.js → chunk-ytjn0gq2.js} +2 -2
  154. package/dist/chunk-z47p2gx8.js +2 -0
  155. package/dist/chunk-z4tdnfxd.js +2 -0
  156. package/dist/chunk-z6kw6sct.js +4 -0
  157. package/dist/{chunk-shcnt6aa.js → chunk-zf68afyh.js} +3 -3
  158. package/dist/chunk-zhywjwdr.js +2 -0
  159. package/dist/{chunk-g2xy0z0e.js → chunk-zwwhpxp7.js} +2 -2
  160. package/dist/cli.js +21 -21
  161. package/dist/component-library.d.ts +2 -1
  162. package/dist/component-library.js +126 -308
  163. package/dist/craft-entry.js +2 -2
  164. package/dist/craft.js +2 -2
  165. package/dist/directive-arguments.js +39 -6
  166. package/dist/parser/tokenizer.d.ts +2 -1
  167. package/dist/parser/tokenizer.js +7 -5
  168. package/dist/props-declaration.d.ts +64 -0
  169. package/dist/props-declaration.js +354 -0
  170. package/dist/pwa.js +3 -3
  171. package/dist/ssg.js +7 -7
  172. package/dist/utils.js +20 -109
  173. package/package.json +5 -5
  174. package/dist/chunk-08cb7cyw.js +0 -2
  175. package/dist/chunk-0gkxqcpj.js +0 -2
  176. package/dist/chunk-0h1dyd38.js +0 -2
  177. package/dist/chunk-0sew66hf.js +0 -2
  178. package/dist/chunk-13dgqekj.js +0 -2
  179. package/dist/chunk-15n20xwe.js +0 -2
  180. package/dist/chunk-1ta1pj1t.js +0 -2
  181. package/dist/chunk-1z3r2jjp.js +0 -2
  182. package/dist/chunk-1z6rrqvm.js +0 -2
  183. package/dist/chunk-295bykzd.js +0 -61
  184. package/dist/chunk-41353gyc.js +0 -2
  185. package/dist/chunk-4j50hrgq.js +0 -20
  186. package/dist/chunk-4pjqj54a.js +0 -2
  187. package/dist/chunk-53cc06w7.js +0 -2
  188. package/dist/chunk-5m02cbxg.js +0 -2
  189. package/dist/chunk-5rd0an89.js +0 -2
  190. package/dist/chunk-5s0w910j.js +0 -2
  191. package/dist/chunk-6fy11vfb.js +0 -2
  192. package/dist/chunk-6mjk28s3.js +0 -2
  193. package/dist/chunk-8h5nje66.js +0 -2
  194. package/dist/chunk-97kgrevs.js +0 -4
  195. package/dist/chunk-9h3qq2d2.js +0 -2
  196. package/dist/chunk-9kza7gxd.js +0 -2
  197. package/dist/chunk-a02gt4tz.js +0 -1199
  198. package/dist/chunk-a30zpnqp.js +0 -2
  199. package/dist/chunk-aq0fz4mr.js +0 -2
  200. package/dist/chunk-aqxh80vh.js +0 -2
  201. package/dist/chunk-axra1yas.js +0 -2
  202. package/dist/chunk-b2vhsyf9.js +0 -2
  203. package/dist/chunk-c42b1y7z.js +0 -2
  204. package/dist/chunk-c89wryyz.js +0 -2
  205. package/dist/chunk-cev5z6gj.js +0 -2
  206. package/dist/chunk-ch57kgb6.js +0 -2
  207. package/dist/chunk-cv1vm1w0.js +0 -2
  208. package/dist/chunk-d7b30bg6.js +0 -2
  209. package/dist/chunk-f3j1h3ch.js +0 -2
  210. package/dist/chunk-fz4c5e9m.js +0 -2
  211. package/dist/chunk-gd04nvj3.js +0 -2
  212. package/dist/chunk-gmp10259.js +0 -2
  213. package/dist/chunk-gr956aar.js +0 -2
  214. package/dist/chunk-h3fv0q25.js +0 -2
  215. package/dist/chunk-jghpzx5m.js +0 -2
  216. package/dist/chunk-kcqfrw10.js +0 -2
  217. package/dist/chunk-kfzvtzsz.js +0 -2
  218. package/dist/chunk-kqgspa3s.js +0 -2
  219. package/dist/chunk-mast9wb2.js +0 -2
  220. package/dist/chunk-mqy1wz09.js +0 -3
  221. package/dist/chunk-mv21mc9p.js +0 -2
  222. package/dist/chunk-n9bw9bsn.js +0 -2
  223. package/dist/chunk-ngzyzcrp.js +0 -2
  224. package/dist/chunk-nnqyn7db.js +0 -2
  225. package/dist/chunk-p5qac909.js +0 -2
  226. package/dist/chunk-p6hcrg3r.js +0 -3
  227. package/dist/chunk-pa2vt2ej.js +0 -2
  228. package/dist/chunk-pa6kgbmw.js +0 -2
  229. package/dist/chunk-pd089tq0.js +0 -2
  230. package/dist/chunk-pjjrx9pk.js +0 -2
  231. package/dist/chunk-pt3rp3zg.js +0 -2
  232. package/dist/chunk-qg1kw5yf.js +0 -2
  233. package/dist/chunk-s7xywsqd.js +0 -3
  234. package/dist/chunk-t8r40wgf.js +0 -2
  235. package/dist/chunk-w5zzwe2f.js +0 -2
  236. package/dist/chunk-wjafpvjv.js +0 -2
  237. package/dist/chunk-x44f0eq1.js +0 -2
  238. package/dist/chunk-xhr35ctb.js +0 -2
  239. package/dist/chunk-xk15vzb6.js +0 -2
  240. package/dist/chunk-xmmr0916.js +0 -2
  241. package/dist/chunk-ywnqjqns.js +0 -2
  242. package/dist/chunk-z7k1xn6k.js +0 -2
@@ -1,9 +1,13 @@
1
1
  import { scanHtmlScriptElements } from "./html-masking.js";
2
- import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
2
+ import { mkdir, readFile, readdir, realpath, stat, writeFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
+ import { builtinModules } from "node:module";
4
5
  import { scriptAttributes, scriptContainsCode } from "./script-attributes.js";
5
6
  import { topLevelDeclarationSites } from "./client-parameter-bindings.js";
6
7
  import { bracketDepths, stripCommentsAndLiterals } from "./strip-literals.js";
8
+ import { Tokenizer } from "./parser/tokenizer.js";
9
+ import { literalValue, parseDefaults, parsePropsDeclaration, skipBalanced, splitTopLevel } from "./props-declaration.js";
10
+ export { parseDefaults } from "./props-declaration.js";
7
11
  function reservedMethodMessage(name) {
8
12
  if (name === "connectedCallback")
9
13
  return `method "${name}" is reserved; define "onConnect" instead, which the element calls once it is connected, rendered and bound`;
@@ -17,7 +21,7 @@ const RESERVED_METHODS = new Set([
17
21
  "disconnectedCallback",
18
22
  "attributeChangedCallback",
19
23
  "adoptedCallback"
20
- ]);
24
+ ]), SERVER_MODULES = new Set(builtinModules);
21
25
  function toPascalCase(value) {
22
26
  return value.replace(/\.stx$/i, "").split(/[^a-z0-9]+/i).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
23
27
  }
@@ -163,17 +167,18 @@ export function methodDeclaration(method) {
163
167
  return `${method.name}${method.generic}(${parameters}): ${method.returns || (method.async ? "Promise<unknown>" : "unknown")}`;
164
168
  }
165
169
  function extractClientMethods(source, file) {
166
- const methods = {}, declarations = {}, types = [], imports = [], scripts = scanHtmlScriptElements(componentScriptSource(source));
170
+ const methods = {}, declarations = {}, types = [], imports = [], scripts = scanHtmlScriptElements(componentScriptSource(source)).map((script) => ({
171
+ code: source.slice(script.bodyStart, script.bodyEnd),
172
+ attributes: scriptAttributes(script.attrs)
173
+ })).filter(({ attributes }) => !["src", "server", "component", "stx:component"].some((name) => attributes.has(name)) && scriptContainsCode(attributes));
167
174
  for (const script of scripts) {
168
- const code = source.slice(script.bodyStart, script.bodyEnd), attributes = scriptAttributes(script.attrs);
169
- if (attributes.has("src") || attributes.has("server") || attributes.has("component") || attributes.has("stx:component") || !scriptContainsCode(attributes))
170
- continue;
175
+ const { code, attributes } = script;
171
176
  try {
172
177
  new Bun.Transpiler({ loader: "ts" }).transformSync(code);
173
178
  } catch (error) {
174
179
  throw Error(`${file}: failed to transpile <script client> (${error.message})`);
175
180
  }
176
- const extracted = attributes.has("client") ? clientMethods(code) : [], overloads = new Set(extracted.filter((method) => !method.source).map((method) => method.name));
181
+ const props = attributes.has("client") ? null : parsePropsDeclaration(code), extracted = attributes.has("client") ? clientMethods(code) : [], overloads = new Set(extracted.filter((method) => !method.source).map((method) => method.name));
177
182
  for (const method of extracted) {
178
183
  if (RESERVED_METHODS.has(method.name))
179
184
  throw Error(`${file}: client ${reservedMethodMessage(method.name)}`);
@@ -218,7 +223,13 @@ function extractClientMethods(source, file) {
218
223
  } catch {}
219
224
  }
220
225
  }
221
- types.push(code.slice(match.index, cursor).replace(/^export\s+/, "").trim());
226
+ const declaration = code.slice(match.index, cursor), declarationStart = match.index, name = /(?:interface|type)\s+([A-Za-z_$][\w$]*)/.exec(match[0])?.[1], remaining = scripts.map((other) => {
227
+ const body = other === script ? code.slice(0, declarationStart) + code.slice(cursor) : other.code;
228
+ return stripCommentsAndLiterals(body.replace(parsePropsDeclaration(other.code)?.text ?? "\x00", ""));
229
+ }).join(`
230
+ `);
231
+ if (!(props?.typeName === name && !/^export\s/.test(declaration) && name && !new RegExp(`\\b${name}\\b`).test(remaining)))
232
+ types.push(declaration.replace(/^export\s+/, "").trim());
222
233
  typePattern.lastIndex = cursor + 1;
223
234
  }
224
235
  }
@@ -269,21 +280,6 @@ function inferPropertyType(fallback) {
269
280
  return "string";
270
281
  return "object";
271
282
  }
272
- function literalValue(fallback) {
273
- if (fallback === "true")
274
- return !0;
275
- if (fallback === "false")
276
- return !1;
277
- if (/^-?\d+(?:\.\d+)?$/.test(fallback))
278
- return Number(fallback);
279
- if (/^['"`]/.test(fallback))
280
- return fallback.slice(1, -1);
281
- try {
282
- return JSON.parse(fallback);
283
- } catch {
284
- return;
285
- }
286
- }
287
283
  export function componentDirectiveExpression(source, open) {
288
284
  if (source[open] !== "(")
289
285
  return null;
@@ -374,304 +370,72 @@ function compileTemplateToRender(template) {
374
370
  return parts.join(`
375
371
  `);
376
372
  }
377
- function skipBalanced(source, index, open, close) {
378
- if (source[index] !== open)
379
- return -1;
380
- let depth = 0, quote = null;
381
- for (let i = index;i < source.length; i++) {
382
- const char = source[i];
383
- if (quote) {
384
- if (char === "\\") {
385
- i++;
386
- continue;
387
- }
388
- if (char === quote)
389
- quote = null;
373
+ function hoistScriptImports(code) {
374
+ const masked = stripCommentsAndLiterals(code), depths = bracketDepths(masked).depths, imports = [], spans = [];
375
+ for (const match of masked.matchAll(/\bimport\b/g)) {
376
+ const start = match.index;
377
+ if (depths[start] !== 0)
390
378
  continue;
391
- }
392
- if (char === "'" || char === '"' || char === "`") {
393
- quote = char;
394
- continue;
395
- }
396
- if (char === open)
397
- depth++;
398
- else if (char === close) {
399
- if (close === ">" && source[i - 1] === "=")
400
- continue;
401
- depth--;
402
- if (depth === 0)
403
- return i + 1;
404
- }
405
- }
406
- return -1;
407
- }
408
- function splitTopLevel(body, separators, angles) {
409
- const opening = angles ? "([{<" : "([{", closing = angles ? ")]}>" : ")]}", parts = [];
410
- let depth = 0, quote = null, current = "";
411
- for (let i = 0;i < body.length; i++) {
412
- const char = body[i];
413
- if (quote) {
414
- current += char;
415
- if (char === "\\") {
416
- current += body[++i] ?? "";
417
- continue;
418
- }
419
- if (char === quote)
420
- quote = null;
421
- continue;
422
- }
423
- if (char === "'" || char === '"' || char === "`") {
424
- quote = char;
425
- current += char;
379
+ const tokens = new Tokenizer(code.slice(start)).tokenize().filter((token) => !["COMMENT", "WHITESPACE"].includes(token.type));
380
+ if (tokens[1]?.value === "(" || tokens[1]?.value === ".")
426
381
  continue;
382
+ let specifierIndex = tokens[1]?.type === "STRING" ? 1 : -1, depth = 0;
383
+ for (let index = 1;specifierIndex === -1 && index < tokens.length; index++) {
384
+ const token = tokens[index];
385
+ if (token.value === ";" || token.type === "EOF")
386
+ break;
387
+ if (token.value === "{")
388
+ depth++;
389
+ else if (token.value === "}")
390
+ depth--;
391
+ else if (depth === 0 && token.value === "from" && tokens[index + 1]?.type === "STRING")
392
+ specifierIndex = index + 1;
427
393
  }
428
- if (opening.includes(char))
429
- depth++;
430
- else if (closing.includes(char) && !(angles && char === ">" && body[i - 1] === "="))
431
- depth--;
432
- if (depth === 0 && separators.includes(char)) {
433
- parts.push(current);
434
- current = "";
394
+ if (specifierIndex === -1)
435
395
  continue;
436
- }
437
- current += char;
438
- }
439
- parts.push(current);
440
- return parts.map((part) => part.trim()).filter(Boolean);
441
- }
442
- function defaultAssignmentIndex(entry) {
443
- let depth = 0, quote = null;
444
- for (let i = 0;i < entry.length; i++) {
445
- const char = entry[i];
446
- if (quote) {
447
- if (char === "\\") {
448
- i++;
449
- continue;
396
+ const specifier = tokens[specifierIndex];
397
+ let last = specifierIndex;
398
+ if (tokens[last + 1]?.value === "with" && tokens[last + 2]?.value === "{") {
399
+ last += 2;
400
+ let attributesDepth = 1;
401
+ while (attributesDepth && tokens[last + 1]?.type !== "EOF") {
402
+ last++;
403
+ if (tokens[last]?.value === "{")
404
+ attributesDepth++;
405
+ else if (tokens[last]?.value === "}")
406
+ attributesDepth--;
450
407
  }
451
- if (char === quote)
452
- quote = null;
453
- continue;
454
408
  }
455
- if (char === "'" || char === '"' || char === "`") {
456
- quote = char;
457
- continue;
458
- }
459
- if ("([{".includes(char))
460
- depth++;
461
- else if (")]}".includes(char))
462
- depth--;
463
- if (depth !== 0 || char !== "=")
464
- continue;
465
- const previous = entry[i - 1];
466
- if (entry[i + 1] === "=" || previous === "=" || previous === "!" || previous === "<" || previous === ">")
467
- continue;
468
- return i;
409
+ if (tokens[last + 1]?.value === ";")
410
+ last++;
411
+ const end = start + tokens[last].end;
412
+ spans.push({ start, end });
413
+ if (specifier.value.slice(1, -1) !== "stx")
414
+ imports.push(code.slice(start, end));
469
415
  }
470
- return -1;
416
+ let body = code;
417
+ for (const span of spans.reverse())
418
+ body = body.slice(0, span.start) + body.slice(span.end);
419
+ return { imports, body };
471
420
  }
472
- function typeFromConstructor(value) {
473
- switch (value.trim()) {
474
- case "String":
475
- return "string";
476
- case "Number":
477
- return "number";
478
- case "Boolean":
479
- return "boolean";
480
- case "Array":
481
- return "unknown[]";
482
- case "Object":
483
- return "Record<string, unknown>";
484
- default:
485
- return;
486
- }
487
- }
488
- function parsePropsDeclaration(code) {
489
- const call = /\bdefineProps\b/.exec(code);
490
- if (!call)
491
- return null;
492
- const keyword = /(?:^|[\s;{}()])(const|let|var)\s+/g;
493
- let start = -1;
494
- for (let found = keyword.exec(code);found && found.index < call.index; found = keyword.exec(code))
495
- start = found.index + found[0].indexOf(found[1]);
496
- if (start === -1)
497
- return null;
498
- const declared = {}, defaults = {}, propNames = [], propBindings = {};
499
- let cursor = start + (/^(?:const|let|var)\s+/.exec(code.slice(start))?.[0].length ?? 0);
500
- const skipSpace = () => {
501
- while (cursor < code.length && /\s/.test(code[cursor]))
502
- cursor++;
503
- };
504
- let pattern;
505
- if (code[cursor] === "{") {
506
- const end = skipBalanced(code, cursor, "{", "}");
507
- if (end === -1)
508
- return null;
509
- pattern = code.slice(cursor, end);
510
- cursor = end;
511
- } else {
512
- const identifier = /^[A-Za-z_$][\w$]*/.exec(code.slice(cursor));
513
- if (!identifier)
514
- return null;
515
- pattern = identifier[0];
516
- cursor += identifier[0].length;
517
- }
518
- skipSpace();
519
- if (code[cursor] !== "=")
520
- return null;
521
- cursor++;
522
- skipSpace();
523
- const wrapper = /^withDefaults\s*\(\s*/.exec(code.slice(cursor)), wrapped = Boolean(wrapper);
524
- if (wrapper)
525
- cursor += wrapper[0].length;
526
- const marker = /^defineProps\b/.exec(code.slice(cursor));
527
- if (!marker)
528
- return null;
529
- cursor += marker[0].length;
530
- let typeText = "";
531
- skipSpace();
532
- if (code[cursor] === "<") {
533
- const end = skipBalanced(code, cursor, "<", ">");
534
- if (end === -1)
535
- return null;
536
- typeText = code.slice(cursor + 1, end - 1).trim();
537
- cursor = end;
538
- }
539
- skipSpace();
540
- if (code[cursor] !== "(")
541
- return null;
542
- const callEnd = skipBalanced(code, cursor, "(", ")");
543
- if (callEnd === -1)
544
- return null;
545
- const runtimeArgument = code.slice(cursor + 1, callEnd - 1).trim();
546
- cursor = callEnd;
547
- if (wrapped) {
548
- skipSpace();
549
- if (code[cursor] === ",") {
550
- cursor++;
551
- skipSpace();
552
- }
553
- if (code[cursor] === "{") {
554
- const end = skipBalanced(code, cursor, "{", "}");
555
- if (end === -1)
556
- return null;
557
- for (const [name, value] of parseDefaults(code.slice(cursor, end)))
558
- defaults[name] = value;
559
- cursor = end;
560
- }
561
- skipSpace();
562
- if (code[cursor] === ",") {
563
- cursor++;
564
- skipSpace();
565
- }
566
- if (code[cursor] === ")")
567
- cursor++;
568
- }
569
- if (code[cursor] === ";")
570
- cursor++;
571
- const typeName = /^[A-Za-z_$][\w$]*$/.test(typeText) ? typeText : void 0;
572
- if (typeText.startsWith("{"))
573
- for (const member of splitTopLevel(typeText.replace(/^\{/, "").replace(/\}$/, ""), ",;", !0)) {
574
- const parsed = /^(?:readonly\s+)?([A-Za-z_$][\w$]*)\s*\??\s*:\s*([\s\S]+)$/.exec(member);
575
- if (parsed)
576
- declared[parsed[1]] = parsed[2].trim();
577
- }
578
- if (runtimeArgument.startsWith("{"))
579
- for (const [name, value] of parseDefaults(runtimeArgument)) {
580
- propNames.push(name);
581
- if (!value.startsWith("{")) {
582
- const fromConstructor = typeFromConstructor(value);
583
- if (fromConstructor)
584
- declared[name] = fromConstructor;
585
- continue;
586
- }
587
- for (const [key, inner] of parseDefaults(value))
588
- if (key === "default")
589
- defaults[name] = inner;
590
- else if (key === "type") {
591
- const fromConstructor = typeFromConstructor(inner);
592
- if (fromConstructor)
593
- declared[name] = fromConstructor;
594
- }
595
- }
596
- else if (runtimeArgument.startsWith("["))
597
- for (const entry of splitTopLevel(runtimeArgument.slice(1, -1), ",", !1))
598
- propNames.push(entry.replace(/^['"`]/, "").replace(/['"`]$/, ""));
599
- if (pattern.startsWith("{")) {
600
- propNames.length = 0;
601
- for (const entry of splitTopLevel(pattern.replace(/^\{/, "").replace(/\}$/, ""), ",", !1)) {
602
- const assignment = defaultAssignmentIndex(entry), binding = assignment === -1 ? entry : entry.slice(0, assignment), name = binding.split(":")[0].trim().replace(/^\.\.\./, "");
603
- if (!name)
604
- continue;
605
- propNames.push(name);
606
- propBindings[name] = binding.trim();
607
- if (assignment !== -1)
608
- defaults[name] = entry.slice(assignment + 1).trim();
609
- }
610
- } else if (propNames.length === 0)
611
- propNames.push(...Object.keys(declared));
612
- return { text: code.slice(start, cursor), propNames, propBindings, defaults, declared, typeName };
613
- }
614
- export function parseDefaults(object) {
615
- const body = object.trim().replace(/^\{/, "").replace(/\}$/, ""), pairs = [];
616
- let index = 0;
617
- while (index < body.length) {
618
- const key = /\s*([A-Za-z_$][\w$]*)\s*:/y;
619
- key.lastIndex = index;
620
- const match = key.exec(body);
621
- if (!match)
622
- break;
623
- index = key.lastIndex;
624
- let depth = 0, quote = "";
625
- const start = index;
626
- while (index < body.length) {
627
- const char = body[index];
628
- if (quote) {
629
- if (char === "\\")
630
- index++;
631
- else if (char === quote)
632
- quote = "";
633
- } else if (char === "'" || char === '"' || char === "`")
634
- quote = char;
635
- else if (char === "{" || char === "[" || char === "(")
636
- depth++;
637
- else if (char === "}" || char === "]" || char === ")")
638
- depth--;
639
- else if (char === "," && depth === 0)
640
- break;
641
- index++;
642
- }
643
- const value = body.slice(start, index).trim();
644
- if (value)
645
- pairs.push([match[1], value]);
646
- index++;
647
- }
648
- return pairs;
649
- }
650
- function compileScriptScope(source, file, outputDir) {
421
+ function compileScriptScope(source) {
651
422
  const block = scanHtmlScriptElements(componentScriptSource(source)).find((script) => {
652
423
  const attrs = scriptAttributes(script.attrs);
653
- return scriptContainsCode(attrs) && !["component", "stx:component", "client", "src"].some((name) => attrs.has(name));
424
+ return scriptContainsCode(attrs) && !["component", "stx:component", "client", "server", "src"].some((name) => attrs.has(name));
654
425
  });
655
426
  if (!block)
656
427
  return { imports: [], body: "", propNames: [], propBindings: {}, defaults: {}, declared: {} };
657
428
  let code = source.slice(block.bodyStart, block.bodyEnd);
658
- const imports = [], propNames = [], propBindings = {}, defaults = {}, declared = {};
659
- code = code.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm, (statement) => {
660
- if (/from\s*['"]stx['"]/.test(statement))
661
- return "";
662
- imports.push(statement.trim().replace(/(from\s*['"])(\.[^'"]*)(['"])/, (_all, open, specifier, close) => {
663
- const target = path.resolve(path.dirname(file), specifier), rewritten = path.relative(outputDir, target);
664
- return `${open}${rewritten.startsWith(".") ? rewritten : `./${rewritten}`}${close}`;
665
- }));
666
- return "";
667
- });
429
+ const imports = [], propNames = [], propBindings = Object.create(null), defaults = Object.create(null), declared = Object.create(null), hoisted = hoistScriptImports(code);
430
+ imports.push(...hoisted.imports);
431
+ code = hoisted.body;
668
432
  const props = parsePropsDeclaration(code);
669
433
  if (props) {
670
434
  propNames.push(...props.propNames);
671
435
  Object.assign(propBindings, props.propBindings);
672
436
  Object.assign(defaults, props.defaults);
673
437
  Object.assign(declared, props.declared);
674
- code = code.replace(props.text, "");
438
+ code = code.replace(props.text, props.identifier ? `const ${props.identifier} = this._props();` : "");
675
439
  }
676
440
  const interfaceMembers = {};
677
441
  for (const block of code.matchAll(/(?:export\s+)?interface\s+([A-Za-z_$][\w$]*)\s*\{([\s\S]*?)\n\}/g)) {
@@ -730,7 +494,15 @@ async function compileComponent(inputDir, entry, defaults) {
730
494
  throw Error(`${sourcePath}: invalid component class name "${name}"`);
731
495
  if (!validCustomElementTag(tag))
732
496
  throw Error(`${sourcePath}: invalid custom-element tag "${tag}"; tags must be lowercase and contain a hyphen`);
733
- const propertyInput = entry.properties || metadata.properties || metadata.props || {}, properties = Object.fromEntries(Object.entries(propertyInput).map(([propertyName, property]) => [propertyName, normalizeProperty(propertyName, property)])), eventCompilation = compileEventDirectives(extractTemplate(source)), bindingCompilation = compileDynamicBindings(eventCompilation.template), scope = compileScriptScope(source, sourcePath, path.resolve(defaults.outputDir)), render = compileTemplateToRender(bindingCompilation.template);
497
+ const propertyInput = entry.properties || metadata.properties || metadata.props || {}, properties = Object.fromEntries(Object.entries(propertyInput).map(([propertyName, property]) => [propertyName, normalizeProperty(propertyName, property)])), eventCompilation = compileEventDirectives(extractTemplate(source)), bindingCompilation = compileDynamicBindings(eventCompilation.template), scope = compileScriptScope(source);
498
+ for (const script of scanHtmlScriptElements(componentScriptSource(source))) {
499
+ const attrs = scriptAttributes(script.attrs);
500
+ if (!attrs.has("client") || ["server", "component", "stx:component", "src"].some((name) => attrs.has(name)) || !scriptContainsCode(attrs))
501
+ continue;
502
+ scope.imports.push(...hoistScriptImports(source.slice(script.bodyStart, script.bodyEnd)).imports);
503
+ }
504
+ scope.imports = [...new Set(scope.imports)];
505
+ const render = compileTemplateToRender(bindingCompilation.template);
734
506
  for (const propertyName of scope.propNames) {
735
507
  if (properties[propertyName])
736
508
  continue;
@@ -1089,7 +861,7 @@ export function defineComponent(Component, definition) {
1089
861
  }
1090
862
  `;
1091
863
  }
1092
- function componentModule(component) {
864
+ function componentModule(component, runtimeImport = "./runtime.js") {
1093
865
  const definition = JSON.stringify({
1094
866
  tag: component.tag,
1095
867
  template: component.template,
@@ -1141,7 +913,7 @@ ${indent(compiled.trim())}
1141
913
  }
1142
914
  `;
1143
915
  }
1144
- return `import { StxElement, defineComponent } from './runtime.js';
916
+ return `import { StxElement, defineComponent } from ${runtimeImport === "./runtime.js" ? "'./runtime.js'" : JSON.stringify(runtimeImport)};
1145
917
  ${scope.imports.length ? `${scope.imports.join(`
1146
918
  `)}
1147
919
  ` : ""}
@@ -1337,10 +1109,12 @@ export async function buildComponentLibrary(config) {
1337
1109
  await mkdir(outputDir, { recursive: !0 });
1338
1110
  const files = [], emit = async (filename, content) => {
1339
1111
  const target = path.join(outputDir, filename);
1340
- await writeFile(target, content.endsWith(`
1341
- `) ? content : `${content}
1342
- `, "utf8");
1343
- files.push(target);
1112
+ await mkdir(path.dirname(target), { recursive: !0 });
1113
+ await writeFile(target, typeof content === "string" && !content.endsWith(`
1114
+ `) ? `${content}
1115
+ ` : content);
1116
+ if (!files.includes(target))
1117
+ files.push(target);
1344
1118
  return target;
1345
1119
  };
1346
1120
  await emit("runtime.js", runtimeModule());
@@ -1353,6 +1127,50 @@ export async function buildComponentLibrary(config) {
1353
1127
  await emit(`${component.tag}.css`, config.minify ? minifyCss(css) : css);
1354
1128
  }
1355
1129
  }
1130
+ const importScanner = new Bun.Transpiler({ loader: "ts" });
1131
+ if (components.some((component) => component.scope.imports.length || importScanner.scanImports(componentModule(component)).some((imported) => imported.kind === "dynamic-import"))) {
1132
+ const entrypoints = components.map((component) => path.join(outputDir, `${component.tag}.js`)), canonicalEntries = new Map(await Promise.all(entrypoints.map(async (file, index) => [await realpath(file), components[index]])));
1133
+ for (const [index, file] of entrypoints.entries())
1134
+ canonicalEntries.set(file, components[index]);
1135
+ const sourceEntries = new Map(components.map((component) => [path.join(path.dirname(component.sourcePath), `.stx-library-${component.tag}.ts`), component])), runtimePath = path.join(outputDir, "runtime.js"), built = await Bun.build({
1136
+ entrypoints,
1137
+ outdir: outputDir,
1138
+ root: outputDir,
1139
+ target: "browser",
1140
+ format: "esm",
1141
+ splitting: !0,
1142
+ naming: { entry: "[name].js", chunk: "chunks/[name]-[hash].js" },
1143
+ minify: !1,
1144
+ loader: { ".js": "ts" },
1145
+ plugins: [{ name: "stx-element-runtime", setup(builder) {
1146
+ builder.onResolve({ filter: /.*/ }, (args) => {
1147
+ if (args.path === "bun" || args.path.startsWith("bun:") || args.path.startsWith("node:") || SERVER_MODULES.has(args.path))
1148
+ throw Error(`Server-only import ${JSON.stringify(args.path)} is not available in a browser component (${args.importer})`);
1149
+ const entry = canonicalEntries.get(args.path);
1150
+ if (!args.importer && entry)
1151
+ return { path: path.join(path.dirname(entry.sourcePath), `.stx-library-${entry.tag}.ts`) };
1152
+ if (args.path === runtimePath && sourceEntries.has(args.importer))
1153
+ return { path: "./runtime.js", external: !0 };
1154
+ });
1155
+ builder.onLoad({ filter: /\.ts$/ }, (args) => {
1156
+ const component = sourceEntries.get(args.path);
1157
+ if (component)
1158
+ return { contents: componentModule(component, runtimePath), loader: "ts" };
1159
+ });
1160
+ } }]
1161
+ }).catch((error) => {
1162
+ const details = (error instanceof AggregateError ? error.errors : [error]).map(String).join(`
1163
+ `);
1164
+ throw Error(`Failed to bundle browser component imports
1165
+ ${details}`);
1166
+ });
1167
+ if (!built.success)
1168
+ throw Error(`Failed to bundle component imports
1169
+ ${built.logs.map(String).join(`
1170
+ `)}`);
1171
+ for (const output of built.outputs)
1172
+ await emit(path.relative(outputDir, output.path), new Uint8Array(await output.arrayBuffer()));
1173
+ }
1356
1174
  const indexSource = components.map((component) => `export { ${component.name}, default as ${component.name}Element } from './${component.tag}.js';`).join(`
1357
1175
  `);
1358
1176
  await emit("index.js", indexSource);
@@ -1,9 +1,9 @@
1
1
  // @bun
2
- import"./chunk-a02gt4tz.js";import{Fo,Ha,Va}from"./chunk-57q4nvs9.js";import"./chunk-e362e615.js";import"./chunk-s29hp1qw.js";import"./chunk-295bykzd.js";import"./chunk-n22xtagg.js";import"./chunk-hxhmhw23.js";import"./chunk-kwf3kfr0.js";import"./chunk-6t04tqvh.js";import"./chunk-kaem8q20.js";import"./chunk-h63ma36g.js";import"./chunk-agd2b928.js";import"./chunk-mxvgft6p.js";import"./chunk-0rdh8bw3.js";import"./chunk-ssg6ne5b.js";import"./chunk-7wqz32ay.js";import"./chunk-sfyyn0mg.js";import"./chunk-gtv9jd68.js";import"./chunk-pgrm1vet.js";import"./chunk-4251fy7d.js";import"./chunk-twmkz0xs.js";import"./chunk-dz7amds0.js";import"./chunk-c0g30cjs.js";import"./chunk-kee5a3ce.js";import{Fu,Ua,Kh,Gh,Wa,zo,ps,qa,Ka,Xh,Jh,Ga,Xa,Ja,Ya}from"./chunk-km14pdrt.js";import"./chunk-6mfpns00.js";import"./chunk-mqy1wz09.js";import"./chunk-d2pexm3z.js";import"./chunk-f2twg7ze.js";import"./chunk-cb0c6959.js";import"./chunk-c47stwqj.js";import"./chunk-0mx7rg07.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-gz9pknbw.js";import{Vo,Ua,Wa}from"./chunk-cmg9x1ka.js";import"./chunk-mw7hacm3.js";import"./chunk-2a5g80mq.js";import"./chunk-3dqfjpz4.js";import"./chunk-mgh5rst1.js";import"./chunk-vk2jy6mn.js";import"./chunk-9n5h4sqc.js";import"./chunk-eyx92t9n.js";import"./chunk-s93yh7ed.js";import"./chunk-q0y8gv18.js";import"./chunk-eceeqy74.js";import"./chunk-p8shtje2.js";import"./chunk-95sd8h5g.js";import"./chunk-rb2zbdqd.js";import"./chunk-9d91h636.js";import"./chunk-vc432a0w.js";import"./chunk-mt8edb75.js";import"./chunk-hgf7bc50.js";import"./chunk-48rwqchc.js";import"./chunk-4kmg6g5n.js";import"./chunk-dymck524.js";import"./chunk-05x1rd86.js";import"./chunk-pz554g43.js";import{Hu,qa,Xh,Jh,Ka,Uo,hs,Ga,Xa,Yh,Zh,Ja,Ya,Za,Qa}from"./chunk-6kyqejnq.js";import"./chunk-f3cyghnb.js";import"./chunk-b0e7dgv8.js";import"./chunk-5kqezrjt.js";import"./chunk-bqtj62ys.js";import"./chunk-pctf14yw.js";import"./chunk-eqffvse2.js";import"./chunk-58qzyyyv.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{Fu as CRAFT_BRIDGE_SCRIPT,zo as CRAFT_COMPONENTS,qa as CRAFT_COMPONENT_RUNTIME,ps as CRAFT_COMPONENT_STYLES,Fo as NATIVE_COMPONENTS,Ga as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Ha as compileToNative,Va as createHotReloadServer,Xa as findCraftBinary,Ua as generateCraftBridgeScript,V as generateCraftOptimizations,Ya as getAvailableFormats,Ja as getAvailableTargets,Jh as getCraftComponents,G as getSSRCacheStats,Wa as injectCraftBridge,Kh as isCraftEnvironment,Y as prerenderForCraft,Ka as processCraftComponents,Gh as processCraftDirective,Xh 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{Hu as CRAFT_BRIDGE_SCRIPT,Uo as CRAFT_COMPONENTS,Ga as CRAFT_COMPONENT_RUNTIME,hs as CRAFT_COMPONENT_STYLES,Vo as NATIVE_COMPONENTS,Ja as buildNative,B as clearAllCaches,q as clearRenderCache,U as clearTemplateCache,R as compileTemplate,Ua as compileToNative,Wa as createHotReloadServer,Ya as findCraftBinary,qa as generateCraftBridgeScript,V as generateCraftOptimizations,Qa as getAvailableFormats,Za as getAvailableTargets,Zh as getCraftComponents,G as getSSRCacheStats,Ka as injectCraftBridge,Xh as isCraftEnvironment,Y as prerenderForCraft,Xa as processCraftComponents,Jh as processCraftDirective,Yh as registerCraftComponent,Q as renderSSR};