defuss 2.1.11 → 3.2.0

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 (278) hide show
  1. package/dist/component-registry-CPBzgkm2.cjs +20 -0
  2. package/dist/component-registry-rwX6GHzq.mjs +15 -0
  3. package/dist/dom--qQgTXnx.mjs +2603 -0
  4. package/dist/dom-0JFHc2kn.cjs +2810 -0
  5. package/dist/dom-4vhaViIf.mjs +2801 -0
  6. package/dist/dom-5V9JcMrR.mjs +2695 -0
  7. package/dist/dom-B0lpSx0p.mjs +2604 -0
  8. package/dist/dom-B0mZwIcb.cjs +2859 -0
  9. package/dist/dom-B4MQngSF.cjs +2782 -0
  10. package/dist/dom-B58Ij3VD.cjs +2907 -0
  11. package/dist/dom-B5zbx-3T.mjs +2810 -0
  12. package/dist/dom-B6fFOlKv.cjs +2898 -0
  13. package/dist/dom-B7UqtWqL.cjs +2814 -0
  14. package/dist/dom-BDL4winW.cjs +2892 -0
  15. package/dist/dom-BHi3SKvU.mjs +2595 -0
  16. package/dist/dom-BMSWQp9d.cjs +2899 -0
  17. package/dist/dom-BOjwen4W.cjs +2894 -0
  18. package/dist/dom-BSXG5cMV.mjs +2678 -0
  19. package/dist/dom-BUUPuzZG.cjs +2681 -0
  20. package/dist/dom-BW8oGJV-.cjs +2890 -0
  21. package/dist/dom-B_g5muLk.mjs +2798 -0
  22. package/dist/dom-Ba8Rmsy6.mjs +2557 -0
  23. package/dist/dom-BaaPAgsv.mjs +2569 -0
  24. package/dist/dom-Bb17xYzx.mjs +2599 -0
  25. package/dist/dom-BcW3GkDu.cjs +2897 -0
  26. package/dist/dom-BfqchTxj.mjs +2696 -0
  27. package/dist/dom-Bg0Eqh-g.cjs +2718 -0
  28. package/dist/dom-Bi5Eowqw.cjs +2728 -0
  29. package/dist/dom-BjFpmoeW.mjs +2818 -0
  30. package/dist/dom-BjwVMyGv.mjs +2644 -0
  31. package/dist/dom-Bjy_d0D1.mjs +2652 -0
  32. package/dist/dom-BkrsFnv4.mjs +2719 -0
  33. package/dist/dom-Bl9sFsMf.mjs +2797 -0
  34. package/dist/dom-BpugjT-d.cjs +2764 -0
  35. package/dist/dom-BzcdRPS7.cjs +2676 -0
  36. package/dist/dom-C1Dv_k31.cjs +2831 -0
  37. package/dist/dom-C2miKN96.cjs +2887 -0
  38. package/dist/dom-C3iIctYx.cjs +2602 -0
  39. package/dist/dom-C6c71RsI.cjs +2892 -0
  40. package/dist/dom-C6qPzZDU.mjs +2526 -0
  41. package/dist/dom-C91wPWgb.mjs +2587 -0
  42. package/dist/dom-CEEtTZJb.cjs +2891 -0
  43. package/dist/dom-CG8ZC5zA.cjs +2645 -0
  44. package/dist/dom-CHfN0q0-.cjs +2805 -0
  45. package/dist/dom-CLpZk5Ok.cjs +2890 -0
  46. package/dist/dom-CMwQ9pmp.cjs +2767 -0
  47. package/dist/dom-COTHhb5r.mjs +2634 -0
  48. package/dist/dom-CRRoa52F.mjs +2805 -0
  49. package/dist/dom-CUHgK6d1.mjs +2807 -0
  50. package/dist/dom-CfCTjzif.mjs +2803 -0
  51. package/dist/dom-Cg17fK2D.mjs +2490 -0
  52. package/dist/dom-CjffEyZp.mjs +2809 -0
  53. package/dist/dom-Cn7eypGU.cjs +2898 -0
  54. package/dist/dom-CoBIe6TZ.mjs +2685 -0
  55. package/dist/dom-Cr99biSm.mjs +2795 -0
  56. package/dist/dom-CuPnZIwb.mjs +2803 -0
  57. package/dist/dom-CyaFGBis.cjs +2897 -0
  58. package/dist/dom-CzDaYcdd.cjs +2896 -0
  59. package/dist/dom-D-M2CWHK.cjs +2805 -0
  60. package/dist/dom-D00lHhSQ.cjs +2887 -0
  61. package/dist/dom-DA76MFiR.mjs +2808 -0
  62. package/dist/dom-DCxc_aGE.mjs +2634 -0
  63. package/dist/dom-DDB7B6E0.mjs +2801 -0
  64. package/dist/dom-DDtrH45u.cjs +2673 -0
  65. package/dist/dom-DKZZG5RP.mjs +2798 -0
  66. package/dist/dom-DOswyRty.mjs +2681 -0
  67. package/dist/dom-DQiJQigd.cjs +2890 -0
  68. package/dist/dom-DRUJMjpd.cjs +2736 -0
  69. package/dist/dom-DU3JvIZO.cjs +2886 -0
  70. package/dist/dom-DWDVSwjd.cjs +2566 -0
  71. package/dist/dom-D_3LE_Qi.mjs +2722 -0
  72. package/dist/dom-DbhNF_Km.cjs +2665 -0
  73. package/dist/dom-Deh17qfR.mjs +2795 -0
  74. package/dist/dom-DfIL_s0t.mjs +2634 -0
  75. package/dist/dom-DhzvIchP.cjs +2680 -0
  76. package/dist/dom-DjEOa9GM.mjs +2801 -0
  77. package/dist/dom-DqWHLuln.cjs +2763 -0
  78. package/dist/dom-Dw0cUaXk.cjs +2717 -0
  79. package/dist/dom-FaIf556X.mjs +2801 -0
  80. package/dist/dom-Kdtm5aoM.mjs +2798 -0
  81. package/dist/dom-O2cdv0jV.cjs +2887 -0
  82. package/dist/dom-YfFA0iKZ.mjs +2726 -0
  83. package/dist/dom-YpZtMxDS.cjs +2783 -0
  84. package/dist/dom-YuuCUzeb.mjs +2744 -0
  85. package/dist/dom-_naqXmaM.mjs +2677 -0
  86. package/dist/dom-iQGpbrON.cjs +2718 -0
  87. package/dist/dom-j57Lsb1X.cjs +2884 -0
  88. package/dist/dom-jKUS5flE.mjs +2771 -0
  89. package/dist/dom-khd7HASe.cjs +2771 -0
  90. package/dist/dom-lEWdDKb4.mjs +2718 -0
  91. package/dist/dom-mA0CVs3o.mjs +2809 -0
  92. package/dist/dom-mt5spBGS.cjs +2634 -0
  93. package/dist/dom-rjEgJGTC.cjs +2806 -0
  94. package/dist/dom-smXiaXEP.mjs +2718 -0
  95. package/dist/dom-wcIpcL6F.mjs +2807 -0
  96. package/dist/dom-xtwhQmkx.cjs +2884 -0
  97. package/dist/dom-xu1m78jm.mjs +2808 -0
  98. package/dist/index-B4BHyohJ.d.ts +1536 -0
  99. package/dist/index-BDnHS4Fq.d.ts +1425 -0
  100. package/dist/index-BENswTvz.d.ts +1505 -0
  101. package/dist/index-BFHuQ4xu.d.ts +1435 -0
  102. package/dist/index-BM5mxtvJ.d.ts +1543 -0
  103. package/dist/index-BOHKDFwH.d.ts +1435 -0
  104. package/dist/index-BRnR4FIe.d.ts +1436 -0
  105. package/dist/index-B_mKPzYo.d.ts +1578 -0
  106. package/dist/index-BctcSoO5.d.ts +1576 -0
  107. package/dist/index-BfvJsCS_.d.ts +1426 -0
  108. package/dist/index-BhNZrSrs.d.ts +1352 -0
  109. package/dist/index-Bi8j-_h_.d.cts +1488 -0
  110. package/dist/index-Bi8j-_h_.d.ts +1488 -0
  111. package/dist/index-BkobKBZk.d.ts +1430 -0
  112. package/dist/index-Bu2vwaJ2.d.ts +1352 -0
  113. package/dist/index-BvvZRMKD.d.ts +1569 -0
  114. package/dist/index-C1AAn__7.d.ts +1433 -0
  115. package/dist/index-C6Eg-vsd.d.ts +1424 -0
  116. package/dist/index-C6OhaPcR.d.ts +1433 -0
  117. package/dist/index-CCeP2S3d.d.ts +1434 -0
  118. package/dist/index-CEIsFrMM.d.ts +1542 -0
  119. package/dist/index-CFDpKGh7.d.ts +1428 -0
  120. package/dist/index-CFrYY_Mt.d.ts +1436 -0
  121. package/dist/index-CGDnSWTS.d.ts +1527 -0
  122. package/dist/index-CKwxYOvH.d.ts +1437 -0
  123. package/dist/index-CLBqO3Y7.d.ts +1544 -0
  124. package/dist/index-CRsLiENw.d.ts +1436 -0
  125. package/dist/index-CTjaPtOu.d.ts +1544 -0
  126. package/dist/index-CWP_xArI.d.ts +1433 -0
  127. package/dist/index-CZunST0r.d.ts +1436 -0
  128. package/dist/index-CeqDyZsK.d.ts +1436 -0
  129. package/dist/index-CiDj5eUV.d.ts +1576 -0
  130. package/dist/index-CidSP07o.d.ts +1361 -0
  131. package/dist/index-Cj_9DtdX.d.ts +1436 -0
  132. package/dist/index-Cm1e5jei.d.ts +1436 -0
  133. package/dist/index-CnQ2vhtJ.d.ts +1563 -0
  134. package/dist/index-CpkEL1jH.d.ts +1569 -0
  135. package/dist/index-Cq5d1Zz3.d.ts +1437 -0
  136. package/dist/index-CuCNTbJn.d.ts +1503 -0
  137. package/dist/index-CxFq13gU.d.ts +1352 -0
  138. package/dist/index-D5dNz_3e.d.ts +1571 -0
  139. package/dist/index-D5yYZNhb.d.ts +1428 -0
  140. package/dist/index-D64A9cbc.d.ts +1428 -0
  141. package/dist/index-DE8BSmm3.d.ts +1575 -0
  142. package/dist/index-DG6bq7_g.d.ts +1436 -0
  143. package/dist/index-DHy5_GN-.d.ts +1437 -0
  144. package/dist/index-DTegsEZx.d.ts +1435 -0
  145. package/dist/index-DXx9mqPm.d.ts +1352 -0
  146. package/dist/index-DbOTogCX.d.ts +1435 -0
  147. package/dist/index-DfXUO0lq.d.ts +1352 -0
  148. package/dist/index-DirmTpEb.d.ts +1352 -0
  149. package/dist/index-DnUO13Ql.d.ts +1365 -0
  150. package/dist/index-DqFnifuO.d.ts +1576 -0
  151. package/dist/index-DsAkAm0h.d.ts +1429 -0
  152. package/dist/index-DsDkGdbl.d.ts +1352 -0
  153. package/dist/index-DugBnSpg.d.ts +1439 -0
  154. package/dist/index-DyF8SurV.d.ts +1437 -0
  155. package/dist/index-VAwbjQuD.d.ts +1436 -0
  156. package/dist/index-VRdwaTq1.d.ts +1544 -0
  157. package/dist/index-WJDLtNz6.d.ts +1437 -0
  158. package/dist/index-XHQiCZJu.d.ts +1344 -0
  159. package/dist/index-YGI08ZC3.d.ts +1435 -0
  160. package/dist/index-YlvmjCMz.d.ts +1574 -0
  161. package/dist/index-_R_iWuBk.d.ts +1435 -0
  162. package/dist/index-bKRdI8Js.d.ts +1544 -0
  163. package/dist/index-sdb3nXP9.d.ts +1436 -0
  164. package/dist/index-u8kUqFhR.d.ts +1442 -0
  165. package/dist/index-uCL6lDoN.d.ts +1365 -0
  166. package/dist/index-wMtGrbTW.d.ts +1435 -0
  167. package/dist/index-wmq1KsvF.d.ts +1523 -0
  168. package/dist/index.cjs +298 -92
  169. package/dist/index.d.cts +6 -5
  170. package/dist/index.d.ts +198 -35
  171. package/dist/index.mjs +277 -94
  172. package/dist/mount--bdP_py-.cjs +27 -0
  173. package/dist/mount-5mGNlNE0.cjs +29 -0
  174. package/dist/mount-9aJ90VEy.cjs +29 -0
  175. package/dist/mount-B-nSxYMI.cjs +29 -0
  176. package/dist/mount-B1ZGm6Vx.mjs +26 -0
  177. package/dist/mount-B268CIyG.mjs +26 -0
  178. package/dist/mount-B7ZORKUE.mjs +26 -0
  179. package/dist/mount-BDMCcckP.mjs +26 -0
  180. package/dist/mount-BFwjtKGf.mjs +23 -0
  181. package/dist/mount-BIX7Q5ve.cjs +29 -0
  182. package/dist/mount-BIjY0oQo.cjs +29 -0
  183. package/dist/mount-BJ2d7Snl.cjs +29 -0
  184. package/dist/mount-BJUfLVrn.cjs +27 -0
  185. package/dist/mount-BL3IoYf-.cjs +29 -0
  186. package/dist/mount-BLgGRFKO.mjs +26 -0
  187. package/dist/mount-BPdF-23b.mjs +26 -0
  188. package/dist/mount-BREA5x3R.mjs +26 -0
  189. package/dist/mount-BSj7I235.cjs +29 -0
  190. package/dist/mount-BSqj-PWe.cjs +26 -0
  191. package/dist/mount-B_MohJp1.mjs +24 -0
  192. package/dist/mount-BhJaAQYc.cjs +29 -0
  193. package/dist/mount-BmhdXDtN.mjs +26 -0
  194. package/dist/mount-Bn8gK_5W.mjs +26 -0
  195. package/dist/mount-BnITFgq_.mjs +26 -0
  196. package/dist/mount-BoeMXBAs.cjs +29 -0
  197. package/dist/mount-BsWXMcQo.mjs +26 -0
  198. package/dist/mount-BvArK3iG.cjs +26 -0
  199. package/dist/mount-Bw7-xmEB.mjs +24 -0
  200. package/dist/mount-BwNr0Cw7.cjs +29 -0
  201. package/dist/mount-C1WHPtGU.mjs +26 -0
  202. package/dist/mount-C6Wj_FWd.cjs +29 -0
  203. package/dist/mount-C7-zVnHp.mjs +26 -0
  204. package/dist/mount-C99AnUyn.mjs +24 -0
  205. package/dist/mount-CC8_T-gT.cjs +29 -0
  206. package/dist/mount-CE1mUC04.cjs +27 -0
  207. package/dist/mount-CGOXBqpC.cjs +29 -0
  208. package/dist/mount-CJGmuyD_.cjs +29 -0
  209. package/dist/mount-COdfKsz3.mjs +26 -0
  210. package/dist/mount-CTXA2JwJ.cjs +29 -0
  211. package/dist/mount-CVcZv8p4.mjs +24 -0
  212. package/dist/mount-CY2jiisH.cjs +27 -0
  213. package/dist/mount-C_THF3G-.mjs +26 -0
  214. package/dist/mount-CgYRpExe.mjs +24 -0
  215. package/dist/mount-CiSuPb2d.cjs +29 -0
  216. package/dist/mount-CjvdhG7D.mjs +24 -0
  217. package/dist/mount-Ck4Sw7qu.cjs +29 -0
  218. package/dist/mount-CkBH-ziv.mjs +26 -0
  219. package/dist/mount-Cl5bq4AK.mjs +26 -0
  220. package/dist/mount-CnRlxDvH.cjs +26 -0
  221. package/dist/mount-Cnhy4x8j.cjs +29 -0
  222. package/dist/mount-CofCsKEL.cjs +27 -0
  223. package/dist/mount-CuZ9kuJ_.cjs +29 -0
  224. package/dist/mount-Cz18Dqhg.cjs +29 -0
  225. package/dist/mount-CzoPJJ3U.cjs +29 -0
  226. package/dist/mount-D-08N9KC.mjs +26 -0
  227. package/dist/mount-D-RpVmv-.cjs +27 -0
  228. package/dist/mount-D0wRLhsJ.mjs +23 -0
  229. package/dist/mount-DBHsNvGL.mjs +24 -0
  230. package/dist/mount-DE_6OU5O.cjs +27 -0
  231. package/dist/mount-DFrJC1Ee.mjs +26 -0
  232. package/dist/mount-DRpQI95j.mjs +26 -0
  233. package/dist/mount-DaS_nGtr.cjs +26 -0
  234. package/dist/mount-DbFi8R0Q.mjs +26 -0
  235. package/dist/mount-DeqZS1eY.mjs +26 -0
  236. package/dist/mount-DetJmqRg.mjs +26 -0
  237. package/dist/mount-DhMUtUgA.cjs +29 -0
  238. package/dist/mount-DlsFpu0l.mjs +26 -0
  239. package/dist/mount-DmThSQhX.mjs +26 -0
  240. package/dist/mount-DpCAhV34.cjs +29 -0
  241. package/dist/mount-DqMUI3Li.cjs +29 -0
  242. package/dist/mount-DrvT4c9H.mjs +23 -0
  243. package/dist/mount-DyrgmigG.mjs +26 -0
  244. package/dist/mount-E-PFWZoH.cjs +29 -0
  245. package/dist/mount-EbSuNkcp.cjs +29 -0
  246. package/dist/mount-FGWwjyl3.mjs +23 -0
  247. package/dist/mount-NvaShFIJ.mjs +24 -0
  248. package/dist/mount-OwEsrEgH.mjs +26 -0
  249. package/dist/mount-OzbDDNzG.cjs +29 -0
  250. package/dist/mount-TA9rAjfX.mjs +26 -0
  251. package/dist/mount-Ta6JNwOd.cjs +29 -0
  252. package/dist/mount-WayWo_Wo.cjs +29 -0
  253. package/dist/mount-cbdw4Rn8.mjs +26 -0
  254. package/dist/mount-euC2wM_H.mjs +26 -0
  255. package/dist/mount-gY0N84Yl.cjs +29 -0
  256. package/dist/mount-j5GGTHgL.mjs +26 -0
  257. package/dist/mount-lrm6DtLS.cjs +29 -0
  258. package/dist/mount-mI6oAeYn.mjs +26 -0
  259. package/dist/mount-qXpzCgOn.cjs +27 -0
  260. package/dist/mount-s4KN8Ng-.mjs +26 -0
  261. package/dist/mount-wMBAOpuQ.mjs +26 -0
  262. package/dist/mount-yB4RTAZ9.cjs +29 -0
  263. package/dist/mount-zEZORNEX.mjs +26 -0
  264. package/dist/mount-zk9YB0XU.cjs +29 -0
  265. package/dist/render/client.cjs +28 -11
  266. package/dist/render/client.d.ts +4 -4
  267. package/dist/render/client.mjs +13 -13
  268. package/dist/render/dev/index.cjs +4 -1
  269. package/dist/render/dev/index.d.ts +2 -3
  270. package/dist/render/dev/index.mjs +1 -1
  271. package/dist/render/index.cjs +20 -1
  272. package/dist/render/index.d.cts +76 -1
  273. package/dist/render/index.d.ts +88 -3
  274. package/dist/render/index.mjs +2 -1
  275. package/dist/render/server.cjs +19 -1
  276. package/dist/render/server.d.ts +4 -4
  277. package/dist/render/server.mjs +3 -2
  278. package/package.json +19 -11
@@ -0,0 +1,2810 @@
1
+ 'use strict';
2
+
3
+ var defussRuntime = require('defuss-runtime');
4
+
5
+ const CAPTURE_ONLY_EVENTS = /* @__PURE__ */ new Set([
6
+ "focus",
7
+ "blur",
8
+ "scroll",
9
+ "mouseenter",
10
+ "mouseleave"
11
+ // Note: focusin/focusout DO bubble, so they're not included here
12
+ ]);
13
+ const elementHandlerMap = /* @__PURE__ */ new WeakMap();
14
+ const parseEventPropName = (propName) => {
15
+ if (!propName.startsWith("on")) return null;
16
+ const raw = propName.slice(2);
17
+ if (!raw) return null;
18
+ const lower = raw.toLowerCase();
19
+ const isCapture = lower.endsWith("capture");
20
+ const eventType = isCapture ? lower.slice(0, -"capture".length) : lower;
21
+ if (!eventType) return null;
22
+ return { eventType, capture: isCapture };
23
+ };
24
+ const getOrCreateElementHandlers = (el) => {
25
+ const existing = elementHandlerMap.get(el);
26
+ if (existing) return existing;
27
+ const created = /* @__PURE__ */ new Map();
28
+ elementHandlerMap.set(el, created);
29
+ return created;
30
+ };
31
+ const getEventPath = (event) => {
32
+ const composedPath = event.composedPath?.();
33
+ if (composedPath && composedPath.length > 0) return composedPath;
34
+ const path = [];
35
+ let node = event.target;
36
+ while (node) {
37
+ path.push(node);
38
+ const maybeNode = node;
39
+ if (typeof maybeNode === "object" && maybeNode && "parentNode" in maybeNode) {
40
+ node = maybeNode.parentNode;
41
+ continue;
42
+ }
43
+ break;
44
+ }
45
+ const doc = event.target?.ownerDocument;
46
+ if (doc && path[path.length - 1] !== doc) path.push(doc);
47
+ const win = doc?.defaultView;
48
+ if (win && path[path.length - 1] !== win) path.push(win);
49
+ return path;
50
+ };
51
+ const createPhaseHandler = (eventType, phase) => {
52
+ return (event) => {
53
+ const path = getEventPath(event).filter(
54
+ (t) => typeof t === "object" && t !== null && t.nodeType === Node.ELEMENT_NODE
55
+ );
56
+ const ordered = phase === "capture" ? [...path].reverse() : path;
57
+ for (const target of ordered) {
58
+ const handlersByEvent = elementHandlerMap.get(target);
59
+ if (!handlersByEvent) continue;
60
+ const entry = handlersByEvent.get(eventType);
61
+ if (!entry) continue;
62
+ if (phase === "capture") {
63
+ if (entry.capture) {
64
+ entry.capture.call(target, event);
65
+ if (event.cancelBubble) return;
66
+ }
67
+ if (entry.captureSet) {
68
+ for (const handler of entry.captureSet) {
69
+ handler.call(target, event);
70
+ if (event.cancelBubble) return;
71
+ }
72
+ }
73
+ } else {
74
+ if (entry.bubble) {
75
+ entry.bubble.call(target, event);
76
+ if (event.cancelBubble) return;
77
+ }
78
+ if (entry.bubbleSet) {
79
+ for (const handler of entry.bubbleSet) {
80
+ handler.call(target, event);
81
+ if (event.cancelBubble) return;
82
+ }
83
+ }
84
+ }
85
+ }
86
+ };
87
+ };
88
+ const installedRootListeners = /* @__PURE__ */ new WeakMap();
89
+ const ensureRootListener = (root, eventType) => {
90
+ const installed = installedRootListeners.get(root) ?? /* @__PURE__ */ new Set();
91
+ installedRootListeners.set(root, installed);
92
+ const captureKey = `${eventType}:capture`;
93
+ if (!installed.has(captureKey)) {
94
+ root.addEventListener(eventType, createPhaseHandler(eventType, "capture"), true);
95
+ installed.add(captureKey);
96
+ }
97
+ const bubbleKey = `${eventType}:bubble`;
98
+ if (!installed.has(bubbleKey)) {
99
+ root.addEventListener(eventType, createPhaseHandler(eventType, "bubble"), false);
100
+ installed.add(bubbleKey);
101
+ }
102
+ };
103
+ const getEventRoot = (element) => {
104
+ const root = element.getRootNode();
105
+ if (root instanceof Document || root instanceof ShadowRoot) {
106
+ return root;
107
+ }
108
+ return null;
109
+ };
110
+ const registerDelegatedEvent = (element, eventType, handler, options = {}) => {
111
+ const root = getEventRoot(element);
112
+ const capture = options.capture || CAPTURE_ONLY_EVENTS.has(eventType);
113
+ if (root) {
114
+ ensureRootListener(root, eventType);
115
+ } else if (element.ownerDocument) {
116
+ ensureRootListener(element.ownerDocument, eventType);
117
+ } else {
118
+ element.addEventListener(eventType, handler, capture);
119
+ }
120
+ const byEvent = getOrCreateElementHandlers(element);
121
+ const entry = byEvent.get(eventType) ?? {};
122
+ byEvent.set(eventType, entry);
123
+ if (options.multi) {
124
+ if (capture) {
125
+ if (!entry.captureSet) entry.captureSet = /* @__PURE__ */ new Set();
126
+ entry.captureSet.add(handler);
127
+ } else {
128
+ if (!entry.bubbleSet) entry.bubbleSet = /* @__PURE__ */ new Set();
129
+ entry.bubbleSet.add(handler);
130
+ }
131
+ } else {
132
+ if (capture) {
133
+ entry.capture = handler;
134
+ } else {
135
+ entry.bubble = handler;
136
+ }
137
+ }
138
+ };
139
+ const removeDelegatedEvent = (element, eventType, handler, options = {}) => {
140
+ options.capture || CAPTURE_ONLY_EVENTS.has(eventType);
141
+ const byEvent = elementHandlerMap.get(element);
142
+ if (!byEvent) return;
143
+ const entry = byEvent.get(eventType);
144
+ if (!entry) return;
145
+ if (handler) {
146
+ if (entry.captureSet) {
147
+ entry.captureSet.delete(handler);
148
+ }
149
+ if (entry.bubbleSet) {
150
+ entry.bubbleSet.delete(handler);
151
+ }
152
+ if (entry.capture === handler) {
153
+ entry.capture = void 0;
154
+ }
155
+ if (entry.bubble === handler) {
156
+ entry.bubble = void 0;
157
+ }
158
+ element.removeEventListener(eventType, handler, true);
159
+ element.removeEventListener(eventType, handler, false);
160
+ } else {
161
+ entry.capture = void 0;
162
+ entry.bubble = void 0;
163
+ entry.captureSet = void 0;
164
+ entry.bubbleSet = void 0;
165
+ }
166
+ const isEmpty = !entry.capture && !entry.bubble && (!entry.captureSet || entry.captureSet.size === 0) && (!entry.bubbleSet || entry.bubbleSet.size === 0);
167
+ if (isEmpty) {
168
+ byEvent.delete(eventType);
169
+ }
170
+ };
171
+ const clearDelegatedEvents = (element) => {
172
+ const byEvent = elementHandlerMap.get(element);
173
+ if (!byEvent) return;
174
+ byEvent.clear();
175
+ };
176
+ const clearDelegatedEventsDeep = (root) => {
177
+ clearDelegatedEvents(root);
178
+ const doc = root.ownerDocument ?? document;
179
+ const walker = doc.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
180
+ let node = walker.nextNode();
181
+ while (node) {
182
+ clearDelegatedEvents(node);
183
+ node = walker.nextNode();
184
+ }
185
+ };
186
+ const getRegisteredEventTypes = (element) => {
187
+ const byEvent = elementHandlerMap.get(element);
188
+ if (!byEvent) return /* @__PURE__ */ new Set();
189
+ return new Set(byEvent.keys());
190
+ };
191
+ const getRegisteredEventKeys = (element) => {
192
+ const byEvent = elementHandlerMap.get(element);
193
+ if (!byEvent) return /* @__PURE__ */ new Set();
194
+ const keys = /* @__PURE__ */ new Set();
195
+ for (const [eventType, entry] of byEvent) {
196
+ if (entry.bubble || entry.bubbleSet?.size) keys.add(`${eventType}:bubble`);
197
+ if (entry.capture || entry.captureSet?.size) keys.add(`${eventType}:capture`);
198
+ }
199
+ return keys;
200
+ };
201
+ const removeDelegatedEventByKey = (element, eventType, phase) => {
202
+ const byEvent = elementHandlerMap.get(element);
203
+ if (!byEvent) return;
204
+ const entry = byEvent.get(eventType);
205
+ if (!entry) return;
206
+ if (phase === "capture") {
207
+ entry.capture = void 0;
208
+ entry.captureSet = void 0;
209
+ } else {
210
+ entry.bubble = void 0;
211
+ entry.bubbleSet = void 0;
212
+ }
213
+ const isEmpty = !entry.capture && !entry.bubble && (!entry.captureSet || entry.captureSet.size === 0) && (!entry.bubbleSet || entry.bubbleSet.size === 0);
214
+ if (isEmpty) byEvent.delete(eventType);
215
+ };
216
+
217
+ const componentRegistry = /* @__PURE__ */ new WeakMap();
218
+ function isComponentRoot(el) {
219
+ return componentRegistry.has(el);
220
+ }
221
+ function getComponentInstance(el) {
222
+ return componentRegistry.get(el);
223
+ }
224
+ function registerComponent(el, renderFn, props) {
225
+ componentRegistry.set(el, { renderFn, props });
226
+ }
227
+ function unregisterComponent(el) {
228
+ componentRegistry.delete(el);
229
+ }
230
+
231
+ class Call {
232
+ name;
233
+ fn;
234
+ args;
235
+ constructor(name, fn, ...args) {
236
+ this.name = name;
237
+ this.fn = fn;
238
+ this.args = args;
239
+ }
240
+ }
241
+ const globalRegistry = globalThis;
242
+ if (!globalRegistry.__defuss_nonChainedReturnCallNames) {
243
+ globalRegistry.__defuss_nonChainedReturnCallNames = [
244
+ "getFirstElement",
245
+ "toArray",
246
+ "map",
247
+ "isHidden",
248
+ "isVisible",
249
+ "hasClass",
250
+ "dimension",
251
+ "position",
252
+ "offset",
253
+ "prop",
254
+ "val",
255
+ "form",
256
+ "attr",
257
+ "data",
258
+ "css",
259
+ "html",
260
+ "serialize"
261
+ ];
262
+ }
263
+ function addNonChainedReturnCallNames(callNames) {
264
+ const global = globalRegistry.__defuss_nonChainedReturnCallNames;
265
+ callNames.forEach((name) => {
266
+ if (!global.includes(name)) {
267
+ global.push(name);
268
+ }
269
+ });
270
+ }
271
+ function getNonChainedReturnCallNames() {
272
+ return [...globalRegistry.__defuss_nonChainedReturnCallNames];
273
+ }
274
+ function isNonChainedReturnCall(callName) {
275
+ return globalRegistry.__defuss_nonChainedReturnCallNames.includes(callName);
276
+ }
277
+ const emptyImpl = (nodes) => {
278
+ nodes.forEach((el) => {
279
+ const element = el;
280
+ const target = element.shadowRoot ?? element;
281
+ while (target.firstChild) {
282
+ const node = target.firstChild;
283
+ if (node instanceof HTMLElement) {
284
+ clearDelegatedEventsDeep(node);
285
+ }
286
+ node.remove();
287
+ }
288
+ });
289
+ return nodes;
290
+ };
291
+ class CallChainImpl {
292
+ isResolved;
293
+ options;
294
+ elementCreationOptions;
295
+ callStack;
296
+ resultStack;
297
+ stackPointer;
298
+ lastResolvedStackPointer;
299
+ stoppedWithError;
300
+ lastResult;
301
+ length;
302
+ chainStartTime;
303
+ chainAsyncStartTime;
304
+ chainAsyncFinishTime;
305
+ // SSR-ability
306
+ document;
307
+ window;
308
+ performance;
309
+ Parser;
310
+ constructor(options = {}) {
311
+ this.options = {
312
+ ...getDefaultDequeryOptions(),
313
+ ...options
314
+ };
315
+ const optionsKeys = Object.keys(getDefaultDequeryOptions());
316
+ this.options = defussRuntime.pick(this.options, optionsKeys);
317
+ this.window = this.options.globals.window;
318
+ this.document = this.options.globals.window.document;
319
+ this.performance = this.options.globals.performance;
320
+ this.Parser = this.options.globals.window.DOMParser;
321
+ const elementCreationOptions = defussRuntime.omit(
322
+ options,
323
+ optionsKeys
324
+ );
325
+ this.elementCreationOptions = elementCreationOptions;
326
+ this.callStack = [];
327
+ this.resultStack = options.resultStack ? [options.resultStack] : [];
328
+ this.stackPointer = 0;
329
+ this.lastResolvedStackPointer = 0;
330
+ this.stoppedWithError = null;
331
+ this.lastResult = [];
332
+ this.length = 0;
333
+ this.isResolved = false;
334
+ this.chainStartTime = this.performance.now() ?? 0;
335
+ this.chainAsyncStartTime = 0;
336
+ this.chainAsyncFinishTime = 0;
337
+ }
338
+ get globals() {
339
+ return this.options.globals;
340
+ }
341
+ // sync methods
342
+ // currently selected nodes
343
+ get nodes() {
344
+ return this.resultStack.length > 0 ? this.resultStack[this.resultStack.length - 1] : [];
345
+ }
346
+ // allow for for .. of loop
347
+ [Symbol.iterator]() {
348
+ return this.nodes[Symbol.iterator]();
349
+ }
350
+ // async, direct result method
351
+ getFirstElement() {
352
+ return createCall(
353
+ this,
354
+ "getFirstElement",
355
+ async () => this[0]
356
+ );
357
+ }
358
+ // async, wrapped/chainable API methods
359
+ debug(cb) {
360
+ return createCall(this, "debug", async () => {
361
+ cb(this);
362
+ return this.nodes;
363
+ });
364
+ }
365
+ ref(ref) {
366
+ return createCall(this, "ref", async () => {
367
+ if (ref.current) {
368
+ return [ref.current];
369
+ }
370
+ await defussRuntime.waitForRef(ref, this.options.timeout);
371
+ if (ref.current) {
372
+ return [ref.current];
373
+ } else {
374
+ console.log("\u274C ref() - ref is still null after timeout");
375
+ throw new Error("Ref is null or undefined after timeout");
376
+ }
377
+ });
378
+ }
379
+ query(selector) {
380
+ return createCall(
381
+ this,
382
+ "query",
383
+ async () => {
384
+ return Array.from(
385
+ await waitForDOM(
386
+ () => Array.from(this.document.querySelectorAll(selector)),
387
+ this.options.timeout,
388
+ this.document
389
+ )
390
+ );
391
+ },
392
+ selector
393
+ );
394
+ }
395
+ next() {
396
+ return traverse(this, "next", (el) => el.nextElementSibling);
397
+ }
398
+ prev() {
399
+ return traverse(this, "prev", (el) => el.previousElementSibling);
400
+ }
401
+ find(selector) {
402
+ return createCall(
403
+ this,
404
+ "find",
405
+ async () => {
406
+ const results = await Promise.all(
407
+ this.nodes.map(async (el) => {
408
+ return await waitForDOM(
409
+ () => Array.from(el.querySelectorAll(selector)),
410
+ this.options.timeout,
411
+ this.document
412
+ );
413
+ })
414
+ );
415
+ return results.flat();
416
+ },
417
+ selector
418
+ );
419
+ }
420
+ parent() {
421
+ return traverse(this, "parent", (el) => el.parentElement);
422
+ }
423
+ children() {
424
+ return traverse(this, "children", (el) => Array.from(el.children));
425
+ }
426
+ closest(selector) {
427
+ return traverse(this, "closest", (el) => el.closest(selector));
428
+ }
429
+ first() {
430
+ return createCall(this, "first", async () => {
431
+ return this.nodes.slice(0, 1);
432
+ });
433
+ }
434
+ last() {
435
+ return createCall(this, "last", async () => {
436
+ return this.nodes.slice(-1);
437
+ });
438
+ }
439
+ attr(name, value) {
440
+ return createGetterSetterCall(
441
+ this,
442
+ "attr",
443
+ value,
444
+ // Getter function
445
+ () => {
446
+ if (this.nodes.length === 0) return null;
447
+ return this.nodes[0].getAttribute(name);
448
+ },
449
+ // Setter function
450
+ (val) => {
451
+ this.nodes.forEach((el) => el.setAttribute(name, val));
452
+ }
453
+ );
454
+ }
455
+ prop(name, value) {
456
+ return createGetterSetterCall(
457
+ this,
458
+ "prop",
459
+ value,
460
+ // Getter function
461
+ () => {
462
+ if (this.nodes.length === 0) return void 0;
463
+ return this.nodes[0][name];
464
+ },
465
+ // Setter function
466
+ (val) => {
467
+ this.nodes.forEach((el) => {
468
+ el[name] = val;
469
+ });
470
+ }
471
+ );
472
+ }
473
+ // --- CSS & Class Methods ---
474
+ static resultCache = /* @__PURE__ */ new WeakMap();
475
+ css(prop, value) {
476
+ if (typeof prop === "object") {
477
+ return createCall(this, "css", async () => {
478
+ const elements = this.nodes;
479
+ elements.forEach((el) => {
480
+ const htmlEl = el;
481
+ Object.entries(prop).forEach(([key, val]) => {
482
+ htmlEl.style.setProperty(
483
+ key.replace(/([A-Z])/g, "-$1").toLowerCase(),
484
+ String(val)
485
+ );
486
+ });
487
+ });
488
+ return this.nodes;
489
+ });
490
+ }
491
+ return createGetterSetterCall(
492
+ this,
493
+ "css",
494
+ value,
495
+ // Getter with caching - returns computed style (jQuery behavior)
496
+ () => {
497
+ if (this.nodes.length === 0) return "";
498
+ const el = this.nodes[0];
499
+ const cache = CallChainImpl.resultCache.get(el) || /* @__PURE__ */ new Map();
500
+ const cacheKey = `css:${prop}`;
501
+ if (cache.has(cacheKey)) {
502
+ return cache.get(cacheKey);
503
+ }
504
+ const computed = this.window.getComputedStyle(el);
505
+ const result = computed.getPropertyValue(prop);
506
+ cache.set(cacheKey, result);
507
+ CallChainImpl.resultCache.set(el, cache);
508
+ return result;
509
+ },
510
+ // Setter with cache invalidation
511
+ (val) => {
512
+ this.nodes.forEach((el) => {
513
+ el.style.setProperty(prop, String(val));
514
+ const cache = CallChainImpl.resultCache.get(el);
515
+ if (cache) {
516
+ cache.delete(`css:${prop}`);
517
+ }
518
+ });
519
+ }
520
+ );
521
+ }
522
+ addClass(name) {
523
+ return createCall(this, "addClass", async () => {
524
+ const list = Array.isArray(name) ? name : [name];
525
+ this.nodes.forEach((el) => el.classList.add(...list));
526
+ return this.nodes;
527
+ });
528
+ }
529
+ removeClass(name) {
530
+ return createCall(this, "removeClass", async () => {
531
+ const list = Array.isArray(name) ? name : [name];
532
+ this.nodes.forEach((el) => el.classList.remove(...list));
533
+ return this.nodes;
534
+ });
535
+ }
536
+ hasClass(name) {
537
+ return createCall(
538
+ this,
539
+ "hasClass",
540
+ async () => this.nodes.every(
541
+ (el) => el.classList.contains(name)
542
+ )
543
+ );
544
+ }
545
+ toggleClass(name) {
546
+ return createCall(this, "toggleClass", async () => {
547
+ this.nodes.forEach((el) => el.classList.toggle(name));
548
+ return this.nodes;
549
+ });
550
+ }
551
+ animateClass(name, duration) {
552
+ return createCall(this, "animateClass", async () => {
553
+ this.nodes.forEach((el) => {
554
+ const e = el;
555
+ e.classList.add(name);
556
+ setTimeout(() => e.classList.remove(name), duration);
557
+ });
558
+ return this.nodes;
559
+ });
560
+ }
561
+ // --- Content Manipulation Methods ---
562
+ empty() {
563
+ return createCall(
564
+ this,
565
+ "empty",
566
+ async () => emptyImpl(this.nodes)
567
+ );
568
+ }
569
+ html(html) {
570
+ return createGetterSetterCall(
571
+ this,
572
+ "html",
573
+ html,
574
+ () => {
575
+ if (this.nodes.length === 0) return "";
576
+ return this.nodes[0].innerHTML;
577
+ },
578
+ (val) => {
579
+ this.nodes.forEach((el) => {
580
+ el.innerHTML = val;
581
+ });
582
+ }
583
+ );
584
+ }
585
+ jsx(vdom) {
586
+ if (!isJSX(vdom)) {
587
+ throw new Error("Invalid JSX input");
588
+ }
589
+ return createCall(this, "jsx", async () => {
590
+ this.nodes.forEach(
591
+ (el) => updateDomWithVdom(el, vdom, this.globals)
592
+ );
593
+ return this.nodes;
594
+ });
595
+ }
596
+ text(text) {
597
+ return createGetterSetterCall(
598
+ this,
599
+ "text",
600
+ text,
601
+ // Getter function
602
+ () => {
603
+ if (this.nodes.length === 0) return "";
604
+ return this.nodes[0].textContent || "";
605
+ },
606
+ // Setter function
607
+ (val) => {
608
+ this.nodes.forEach((el) => {
609
+ el.textContent = val;
610
+ });
611
+ }
612
+ );
613
+ }
614
+ remove() {
615
+ return createCall(this, "remove", async () => {
616
+ const removedElements = [...this.nodes];
617
+ this.nodes.forEach((el) => el.remove());
618
+ return removedElements;
619
+ });
620
+ }
621
+ replaceWith(content) {
622
+ return createCall(this, "replaceWith", async () => {
623
+ const newElements = [];
624
+ const newElement = await renderNode(content, this);
625
+ for (let i = 0; i < this.nodes.length; i++) {
626
+ const originalEl = this.nodes[i];
627
+ if (!originalEl?.parentNode) continue;
628
+ if (!newElement) continue;
629
+ const nodeToUse = i === 0 ? newElement : newElement.cloneNode(true);
630
+ originalEl.parentNode.replaceChild(nodeToUse, originalEl);
631
+ newElements.push(nodeToUse);
632
+ }
633
+ this.resultStack[this.resultStack.length - 1] = newElements;
634
+ mapArrayIndexAccess(this, this);
635
+ return newElements;
636
+ });
637
+ }
638
+ append(content) {
639
+ return createCall(this, "append", async () => {
640
+ if (content == null) {
641
+ return this.nodes;
642
+ }
643
+ if (content instanceof Node) {
644
+ this.nodes.forEach((el, index) => {
645
+ if (el && content && !el.isEqualNode(content) && el.parentNode !== content) {
646
+ const nodeToAppend = index === 0 ? content : content.cloneNode(true);
647
+ el.appendChild(nodeToAppend);
648
+ }
649
+ });
650
+ return this.nodes;
651
+ }
652
+ const element = await renderNode(content, this);
653
+ if (!element) return this.nodes;
654
+ if (isDequery(content)) {
655
+ const children = content.nodes;
656
+ this.nodes.forEach((parent, parentIndex) => {
657
+ children.forEach((child) => {
658
+ if (!child?.nodeType || !parent?.nodeType) return;
659
+ if (child.isEqualNode(parent) || parent?.parentNode === child) return;
660
+ const nodeToInsert = parentIndex === 0 ? child : child.cloneNode(true);
661
+ parent.appendChild(nodeToInsert);
662
+ });
663
+ });
664
+ } else if (typeof content === "string" && isMarkup(content, this.Parser)) {
665
+ const elements = renderMarkup(content, this.Parser);
666
+ this.nodes.forEach((el, parentIndex) => {
667
+ elements.forEach((childEl) => {
668
+ const node = parentIndex === 0 ? childEl : childEl.cloneNode(true);
669
+ el.appendChild(node);
670
+ });
671
+ });
672
+ } else {
673
+ this.nodes.forEach((el, index) => {
674
+ if (!element) return;
675
+ const nodeToAppend = index === 0 ? element : element.cloneNode(true);
676
+ el.appendChild(nodeToAppend);
677
+ });
678
+ }
679
+ return this.nodes;
680
+ });
681
+ }
682
+ appendTo(target) {
683
+ return createCall(this, "appendTo", async () => {
684
+ const nodes = await resolveNodes(
685
+ target,
686
+ this.options.timeout,
687
+ this.document
688
+ );
689
+ if (nodes.length === 0) {
690
+ return this.nodes;
691
+ }
692
+ nodes.forEach((node) => {
693
+ this.nodes.forEach((el) => {
694
+ if (!node || !el) return;
695
+ node.appendChild(el.cloneNode(true));
696
+ });
697
+ });
698
+ return this.nodes;
699
+ });
700
+ }
701
+ update(input, transitionConfig) {
702
+ return createCall(this, "update", async () => {
703
+ if (input && typeof input === "object" && !(input instanceof Node) && !isJSX(input) && !isRef(input) && !isDequery(input)) {
704
+ let didImplicitUpdate = false;
705
+ for (const node of this.nodes) {
706
+ if (!(node instanceof Element)) continue;
707
+ const instance = getComponentInstance(node);
708
+ if (!instance) continue;
709
+ Object.assign(instance.props, input);
710
+ const newVNode = instance.renderFn(instance.props);
711
+ updateDomWithVdom(node, newVNode, this.globals);
712
+ instance.prevVNode = newVNode;
713
+ didImplicitUpdate = true;
714
+ }
715
+ if (didImplicitUpdate) {
716
+ return this.nodes;
717
+ }
718
+ }
719
+ return await updateDom(
720
+ input,
721
+ this.nodes,
722
+ this.options.timeout,
723
+ this.Parser,
724
+ transitionConfig
725
+ );
726
+ });
727
+ }
728
+ // --- Event Methods ---
729
+ on(event, handler) {
730
+ return createCall(
731
+ this,
732
+ "on",
733
+ async () => {
734
+ this.nodes.forEach((el) => {
735
+ addElementEvent(el, event, handler);
736
+ });
737
+ return this.nodes;
738
+ },
739
+ event,
740
+ handler
741
+ );
742
+ }
743
+ off(event, handler) {
744
+ return createCall(this, "off", async () => {
745
+ this.nodes.forEach((el) => {
746
+ removeElementEvent(el, event, handler);
747
+ });
748
+ return this.nodes;
749
+ });
750
+ }
751
+ clearEvents() {
752
+ return createCall(this, "clearEvents", async () => {
753
+ this.nodes.forEach((el) => {
754
+ clearElementEvents(el);
755
+ });
756
+ return this.nodes;
757
+ });
758
+ }
759
+ trigger(eventType) {
760
+ return createCall(this, "trigger", async () => {
761
+ this.nodes.forEach(
762
+ (el) => el.dispatchEvent(
763
+ new Event(eventType, { bubbles: true, cancelable: true })
764
+ )
765
+ );
766
+ return this.nodes;
767
+ });
768
+ }
769
+ // --- Position Methods ---
770
+ position() {
771
+ return createCall(
772
+ this,
773
+ "position",
774
+ async () => ({
775
+ top: this.nodes[0].offsetTop,
776
+ left: this.nodes[0].offsetLeft
777
+ })
778
+ );
779
+ }
780
+ offset() {
781
+ return createCall(this, "offset", async () => {
782
+ const el = this.nodes[0];
783
+ const rect = el.getBoundingClientRect();
784
+ return {
785
+ top: rect.top + window.scrollY,
786
+ left: rect.left + window.scrollX
787
+ };
788
+ });
789
+ }
790
+ // --- Data Methods ---
791
+ data(name, value) {
792
+ return createGetterSetterCall(
793
+ this,
794
+ "data",
795
+ value,
796
+ // Getter function
797
+ () => {
798
+ if (this.nodes.length === 0) return void 0;
799
+ return this.nodes[0].dataset[name];
800
+ },
801
+ // Setter function
802
+ (val) => {
803
+ this.nodes.forEach((el) => {
804
+ el.dataset[name] = val;
805
+ });
806
+ }
807
+ );
808
+ }
809
+ val(val) {
810
+ return createGetterSetterCall(
811
+ this,
812
+ "val",
813
+ val,
814
+ // Getter function
815
+ () => {
816
+ if (this.nodes.length === 0) return "";
817
+ const el = this.nodes[0];
818
+ if (el.type === "checkbox") {
819
+ return el.checked;
820
+ }
821
+ return el.value;
822
+ },
823
+ // Setter function
824
+ (value) => {
825
+ this.nodes.forEach((el) => {
826
+ const input = el;
827
+ if (input.type === "checkbox" && typeof value === "boolean") {
828
+ input.checked = value;
829
+ } else {
830
+ input.value = String(value);
831
+ }
832
+ });
833
+ }
834
+ );
835
+ }
836
+ serialize(format = "querystring") {
837
+ const mapValue = (value) => typeof value === "boolean" ? value ? "on" : "off" : value;
838
+ return createCall(this, "serialize", async () => {
839
+ const formData = getAllFormValues(this);
840
+ if (format === "json") {
841
+ return JSON.stringify(formData);
842
+ } else {
843
+ const urlSearchParams = new URLSearchParams();
844
+ const keys = Object.keys(formData);
845
+ keys.forEach((key) => {
846
+ const value = formData[key];
847
+ if (typeof value === "string") {
848
+ urlSearchParams.append(key, value);
849
+ } else if (typeof value === "boolean") {
850
+ urlSearchParams.append(key, mapValue(value));
851
+ } else if (Array.isArray(value)) {
852
+ value.forEach(
853
+ (value2) => urlSearchParams.append(key, mapValue(value2))
854
+ );
855
+ }
856
+ });
857
+ return urlSearchParams.toString();
858
+ }
859
+ });
860
+ }
861
+ form(formData) {
862
+ return createGetterSetterCall(
863
+ this,
864
+ "form",
865
+ formData,
866
+ // Getter function
867
+ () => getAllFormValues(this),
868
+ // Setter function
869
+ (values) => {
870
+ this.nodes.forEach((el) => {
871
+ processAllFormElements(el, (input, key) => {
872
+ if (values[key] !== void 0) {
873
+ if (input.type === "checkbox") {
874
+ input.checked = Boolean(values[key]);
875
+ } else {
876
+ input.value = String(values[key]);
877
+ }
878
+ }
879
+ });
880
+ });
881
+ }
882
+ );
883
+ }
884
+ // --- Dimension Methods ---
885
+ dimension(includeMarginOrPadding, includePaddingIfMarginTrue) {
886
+ return createCall(this, "dimension", async () => {
887
+ if (this.nodes.length === 0) {
888
+ return { width: 0, height: 0 };
889
+ }
890
+ const el = this.nodes[0];
891
+ const style = this.window.getComputedStyle(el);
892
+ if (!style) return { width: 0, height: 0 };
893
+ const rect = el.getBoundingClientRect();
894
+ let width = rect.width;
895
+ let height = rect.height;
896
+ let includeMargin = false;
897
+ let includePadding = true;
898
+ if (includePaddingIfMarginTrue !== void 0) {
899
+ includeMargin = !!includeMarginOrPadding;
900
+ includePadding = !!includePaddingIfMarginTrue;
901
+ } else if (includeMarginOrPadding !== void 0) {
902
+ includePadding = !!includeMarginOrPadding;
903
+ }
904
+ if (!includePadding) {
905
+ const paddingLeft = Number.parseFloat(style.paddingLeft) || 0;
906
+ const paddingRight = Number.parseFloat(style.paddingRight) || 0;
907
+ const paddingTop = Number.parseFloat(style.paddingTop) || 0;
908
+ const paddingBottom = Number.parseFloat(style.paddingBottom) || 0;
909
+ const borderLeft = Number.parseFloat(style.borderLeftWidth) || 0;
910
+ const borderRight = Number.parseFloat(style.borderRightWidth) || 0;
911
+ const borderTop = Number.parseFloat(style.borderTopWidth) || 0;
912
+ const borderBottom = Number.parseFloat(style.borderBottomWidth) || 0;
913
+ width -= paddingLeft + paddingRight + borderLeft + borderRight;
914
+ height -= paddingTop + paddingBottom + borderTop + borderBottom;
915
+ }
916
+ if (includeMargin) {
917
+ const marginLeft = Number.parseFloat(style.marginLeft) || 0;
918
+ const marginRight = Number.parseFloat(style.marginRight) || 0;
919
+ const marginTop = Number.parseFloat(style.marginTop) || 0;
920
+ const marginBottom = Number.parseFloat(style.marginBottom) || 0;
921
+ const baseWidthForOuter = includePadding ? rect.width : width;
922
+ const baseHeightForOuter = includePadding ? rect.height : height;
923
+ const outerWidth = baseWidthForOuter + marginLeft + marginRight;
924
+ const outerHeight = baseHeightForOuter + marginTop + marginBottom;
925
+ return {
926
+ width,
927
+ height,
928
+ outerWidth,
929
+ outerHeight
930
+ };
931
+ }
932
+ return {
933
+ width,
934
+ height
935
+ };
936
+ });
937
+ }
938
+ // --- Visibility Methods ---
939
+ isVisible() {
940
+ return createCall(this, "isVisible", async () => {
941
+ if (this.nodes.length === 0) return false;
942
+ const el = this.nodes[0];
943
+ return checkElementVisibility(el, this.window, this.document);
944
+ });
945
+ }
946
+ isHidden() {
947
+ return createCall(this, "isHidden", async () => {
948
+ if (this.nodes.length === 0) return true;
949
+ const el = this.nodes[0];
950
+ return !checkElementVisibility(el, this.window, this.document);
951
+ });
952
+ }
953
+ // --- Scrolling Methods ---
954
+ scrollTo(xOrOptions, y) {
955
+ return createCall(this, "scrollTo", async () => {
956
+ return scrollHelper("scrollTo", this.nodes, xOrOptions, y);
957
+ });
958
+ }
959
+ scrollBy(xOrOptions, y) {
960
+ return createCall(this, "scrollBy", async () => {
961
+ return scrollHelper("scrollBy", this.nodes, xOrOptions, y);
962
+ });
963
+ }
964
+ scrollIntoView(options) {
965
+ return createCall(this, "scrollIntoView", async () => {
966
+ if (this.nodes.length === 0) return this.nodes;
967
+ this.nodes[0].scrollIntoView(options);
968
+ return this.nodes;
969
+ });
970
+ }
971
+ // --- Transformation Methods ---
972
+ map(cb) {
973
+ return createCall(this, "map", async () => {
974
+ const elements = this.nodes;
975
+ const results = new Array(elements.length);
976
+ for (let i = 0; i < elements.length; i++) {
977
+ results[i] = cb(elements[i], i);
978
+ }
979
+ return results;
980
+ });
981
+ }
982
+ toArray() {
983
+ return createCall(
984
+ this,
985
+ "toArray",
986
+ async () => [...this.nodes]
987
+ );
988
+ }
989
+ filter(selector) {
990
+ return createCall(
991
+ this,
992
+ "filter",
993
+ async () => this.nodes.filter(
994
+ (el) => el instanceof Element && el.matches(selector)
995
+ )
996
+ );
997
+ }
998
+ // --- Cleanup Methods ---
999
+ /** memory cleanup (chain becomes useless after calling this method) */
1000
+ dispose() {
1001
+ return createCall(this, "dispose", async () => {
1002
+ this.nodes.forEach((el) => {
1003
+ CallChainImpl.resultCache.delete(el);
1004
+ });
1005
+ this.callStack.length = 0;
1006
+ this.resultStack.length = 0;
1007
+ this.stackPointer = 0;
1008
+ this.lastResolvedStackPointer = 0;
1009
+ return void 0;
1010
+ });
1011
+ }
1012
+ ready(callback) {
1013
+ return createCall(this, "ready", async () => {
1014
+ if (this.document.readyState === "complete" || this.document.readyState === "interactive") {
1015
+ if (callback) {
1016
+ callback();
1017
+ }
1018
+ return this.nodes;
1019
+ }
1020
+ const nodes = this.nodes;
1021
+ const document = this.document;
1022
+ return new Promise((resolve) => {
1023
+ const handleDOMContentLoaded = () => {
1024
+ document.removeEventListener(
1025
+ "DOMContentLoaded",
1026
+ handleDOMContentLoaded
1027
+ );
1028
+ if (callback) {
1029
+ callback();
1030
+ }
1031
+ resolve(nodes);
1032
+ };
1033
+ document.addEventListener("DOMContentLoaded", handleDOMContentLoaded);
1034
+ });
1035
+ });
1036
+ }
1037
+ // TODO:
1038
+ // - deserialize (from URL string, JSON, etc.)
1039
+ }
1040
+ class CallChainImplThenable extends CallChainImpl {
1041
+ constructor(options = {}, isResolved = false) {
1042
+ super(options);
1043
+ this.isResolved = isResolved;
1044
+ }
1045
+ // biome-ignore lint/suspicious/noThenProperty: <explanation>
1046
+ then(onfulfilled, onrejected) {
1047
+ this.chainAsyncStartTime = this.performance.now() ?? 0;
1048
+ if (this.stoppedWithError) {
1049
+ return Promise.reject(this.stoppedWithError).then(
1050
+ onfulfilled,
1051
+ onrejected
1052
+ );
1053
+ }
1054
+ if (this.isResolved && this.stackPointer >= this.callStack.length) {
1055
+ this.lastResolvedStackPointer = this.stackPointer;
1056
+ const lastCallName = this.callStack[this.callStack.length - 1]?.name;
1057
+ let result;
1058
+ if (isNonChainedReturnCall(lastCallName)) {
1059
+ result = this.lastResult;
1060
+ } else {
1061
+ result = createSubChain(this, CallChainImpl, true);
1062
+ }
1063
+ this.chainAsyncFinishTime = (this.performance.now() ?? 0) - this.chainAsyncStartTime;
1064
+ return Promise.resolve(result).then(onfulfilled, onrejected);
1065
+ }
1066
+ return runWithTimeGuard(
1067
+ this.options.timeout,
1068
+ async () => {
1069
+ let call;
1070
+ while (this.stackPointer < this.callStack.length) {
1071
+ call = this.callStack[this.stackPointer];
1072
+ try {
1073
+ const callReturnValue = await call.fn.apply(this);
1074
+ this.lastResult = callReturnValue;
1075
+ if (!isNonChainedReturnCall(call.name)) {
1076
+ this.resultStack.push(callReturnValue);
1077
+ }
1078
+ if (Array.isArray(this.lastResult)) {
1079
+ mapArrayIndexAccess(this, this);
1080
+ }
1081
+ this.stackPointer++;
1082
+ } catch (err) {
1083
+ this.stoppedWithError = err;
1084
+ throw err;
1085
+ }
1086
+ }
1087
+ this.isResolved = true;
1088
+ this.chainAsyncFinishTime = (this.performance.now() ?? 0) - this.chainAsyncStartTime;
1089
+ return this;
1090
+ },
1091
+ [this],
1092
+ // ← Pass the chain context as args[0]
1093
+ // Timeout error handler - called by runWithTimeGuard when timeout is exceeded
1094
+ (ms, call) => {
1095
+ this.stoppedWithError = new Error(
1096
+ `Chain execution timeout after ${ms}ms`
1097
+ );
1098
+ }
1099
+ ).then((result) => {
1100
+ onfulfilled(result);
1101
+ return result;
1102
+ }).catch(onrejected);
1103
+ }
1104
+ catch(onrejected) {
1105
+ return this.then(void 0, onrejected);
1106
+ }
1107
+ finally(onfinally) {
1108
+ return this.then(
1109
+ (value) => {
1110
+ onfinally?.();
1111
+ return value;
1112
+ },
1113
+ (reason) => {
1114
+ onfinally?.();
1115
+ throw reason;
1116
+ }
1117
+ );
1118
+ }
1119
+ }
1120
+ function scrollHelper(methodName, elements, xOrOptions, y) {
1121
+ elements.forEach((el) => {
1122
+ const element = el;
1123
+ if (typeof xOrOptions === "object") {
1124
+ element[methodName](xOrOptions);
1125
+ } else if (y !== void 0) {
1126
+ element[methodName](xOrOptions, y);
1127
+ } else {
1128
+ element[methodName](xOrOptions, 0);
1129
+ }
1130
+ });
1131
+ return elements;
1132
+ }
1133
+ function getAllFormValues(chain) {
1134
+ const formFields = {};
1135
+ const mapCheckboxValue = (value) => value === "on" ? true : value;
1136
+ chain.nodes.forEach((el) => {
1137
+ processAllFormElements(el, (input, key) => {
1138
+ if (!key) return;
1139
+ if (input instanceof HTMLInputElement) {
1140
+ if (input.type === "checkbox") {
1141
+ if (input.checked) {
1142
+ const value = mapCheckboxValue(input.value);
1143
+ if (typeof formFields[key] !== "undefined") {
1144
+ formFields[key] = [formFields[key], value];
1145
+ } else if (Array.isArray(formFields[key])) {
1146
+ formFields[key].push(value);
1147
+ } else {
1148
+ formFields[key] = value;
1149
+ }
1150
+ }
1151
+ } else if (input.type === "radio") {
1152
+ if (input.checked) {
1153
+ formFields[key] = input.value === "on" ? true : input.value;
1154
+ }
1155
+ } else if (input.type === "file") {
1156
+ if (input.files?.length) {
1157
+ const fileNames = Array.from(input.files).map((file) => file.name);
1158
+ formFields[key] = fileNames.length === 1 ? fileNames[0] : fileNames;
1159
+ }
1160
+ } else {
1161
+ formFields[key] = input.value;
1162
+ }
1163
+ } else if (input instanceof HTMLSelectElement) {
1164
+ if (input.multiple) {
1165
+ const values = Array.from(input.selectedOptions).map(
1166
+ (option) => option.value
1167
+ );
1168
+ formFields[key] = values.length === 1 ? values[0] : values;
1169
+ } else {
1170
+ formFields[key] = input.value;
1171
+ }
1172
+ } else if (input instanceof HTMLTextAreaElement) {
1173
+ formFields[key] = input.value;
1174
+ }
1175
+ });
1176
+ });
1177
+ return formFields;
1178
+ }
1179
+ function delayedAutoStart(chain) {
1180
+ if (chain.options.autoStart) {
1181
+ setTimeout(async () => {
1182
+ if (chain.chainAsyncStartTime === 0) {
1183
+ chain = await chain;
1184
+ }
1185
+ }, chain.options.autoStartDelay);
1186
+ }
1187
+ return chain;
1188
+ }
1189
+ function dequery(selectorRefOrEl, options = getDefaultDequeryOptions()) {
1190
+ if (typeof selectorRefOrEl === "function") {
1191
+ const syncChain = dequery("body", options);
1192
+ queueMicrotask(async () => {
1193
+ const result = await selectorRefOrEl();
1194
+ if (!syncChain.isResolved) {
1195
+ if (typeof result !== "undefined") {
1196
+ const newChain = dequery(result, options);
1197
+ syncChain.resultStack = newChain.resultStack;
1198
+ syncChain.lastResult = newChain.lastResult;
1199
+ mapArrayIndexAccess(newChain, syncChain);
1200
+ }
1201
+ }
1202
+ });
1203
+ return delayedAutoStart(syncChain);
1204
+ }
1205
+ const chain = new CallChainImplThenable({
1206
+ ...options,
1207
+ resultStack: []
1208
+ });
1209
+ if (!selectorRefOrEl)
1210
+ throw new Error("dequery: selector/ref/element required");
1211
+ if (typeof selectorRefOrEl === "string") {
1212
+ if (selectorRefOrEl.indexOf("<") === 0) {
1213
+ const elements = renderMarkup(selectorRefOrEl, chain.Parser);
1214
+ const renderRootEl = elements[0];
1215
+ const { text, html, ...attributes } = chain.elementCreationOptions;
1216
+ if (renderRootEl instanceof Element) {
1217
+ Object.entries(attributes).forEach(([key, value]) => {
1218
+ renderRootEl.setAttribute(key, String(value));
1219
+ });
1220
+ if (html) {
1221
+ renderRootEl.innerHTML = html;
1222
+ } else if (text) {
1223
+ renderRootEl.textContent = text;
1224
+ }
1225
+ }
1226
+ chain.resultStack = [elements];
1227
+ return delayedAutoStart(chain);
1228
+ } else {
1229
+ return delayedAutoStart(
1230
+ chain.query(selectorRefOrEl)
1231
+ );
1232
+ }
1233
+ } else if (isRef(selectorRefOrEl)) {
1234
+ return delayedAutoStart(
1235
+ chain.ref(selectorRefOrEl)
1236
+ );
1237
+ } else if (selectorRefOrEl.nodeType) {
1238
+ chain.resultStack = [[selectorRefOrEl]];
1239
+ return delayedAutoStart(chain);
1240
+ } else if (isJSX(selectorRefOrEl)) {
1241
+ const renderResult = renderIsomorphicSync(
1242
+ selectorRefOrEl,
1243
+ chain.document.body,
1244
+ chain.globals
1245
+ );
1246
+ const elements = typeof renderResult !== "undefined" ? Array.isArray(renderResult) ? renderResult : [renderResult] : [];
1247
+ chain.resultStack = [elements];
1248
+ return delayedAutoStart(chain);
1249
+ }
1250
+ throw new Error("Unsupported selectorOrEl type");
1251
+ }
1252
+ dequery.extend = (ExtensionClass, nonChainedReturnCalls = []) => {
1253
+ const extensionPrototype = ExtensionClass.prototype;
1254
+ const basePrototype = CallChainImpl.prototype;
1255
+ const extensionMethods = Object.getOwnPropertyNames(extensionPrototype);
1256
+ const baseMethods = Object.getOwnPropertyNames(basePrototype);
1257
+ extensionMethods.forEach((methodName) => {
1258
+ if (methodName !== "constructor" && !baseMethods.includes(methodName) && typeof extensionPrototype[methodName] === "function") {
1259
+ CallChainImpl.prototype[methodName] = extensionPrototype[methodName];
1260
+ CallChainImplThenable.prototype[methodName] = extensionPrototype[methodName];
1261
+ }
1262
+ });
1263
+ if (nonChainedReturnCalls.length > 0) {
1264
+ addNonChainedReturnCallNames(nonChainedReturnCalls);
1265
+ }
1266
+ return (selectorRefOrEl, options) => {
1267
+ return dequery(
1268
+ selectorRefOrEl,
1269
+ options
1270
+ );
1271
+ };
1272
+ };
1273
+ const $ = dequery;
1274
+ function isDequery(obj) {
1275
+ return typeof obj === "object" && obj !== null && "isResolved" in obj && "lastResult" in obj && "resultStack" in obj && "callStack" in obj && "stackPointer" in obj;
1276
+ }
1277
+ function isDequeryOptionsObject(o) {
1278
+ return o && typeof o === "object" && o.timeout !== void 0 && o.globals !== void 0;
1279
+ }
1280
+ let defaultOptions = null;
1281
+ function getDefaultDequeryOptions() {
1282
+ if (!defaultOptions) {
1283
+ defaultOptions = {
1284
+ timeout: 5e3,
1285
+ // even long sync chains would execute in < .1ms
1286
+ // so after 1ms, we can assume the "await" in front is
1287
+ // missing (intentionally non-blocking in sync code)
1288
+ autoStartDelay: 1,
1289
+ autoStart: true,
1290
+ resultStack: [],
1291
+ globals: {
1292
+ document: globalThis.document,
1293
+ window: globalThis.window,
1294
+ performance: globalThis.performance
1295
+ }
1296
+ };
1297
+ }
1298
+ return { ...defaultOptions };
1299
+ }
1300
+ function mapArrayIndexAccess(source, target) {
1301
+ const elements = source.nodes;
1302
+ for (let i = 0; i < elements.length; i++) {
1303
+ target[i] = elements[i];
1304
+ }
1305
+ target.length = elements.length;
1306
+ }
1307
+ function createCall(chain, methodName, handler, ...callArgs) {
1308
+ chain.callStack.push(new Call(methodName, handler, ...callArgs));
1309
+ return subChainForNextAwait(chain);
1310
+ }
1311
+ function createGetterSetterCall(chain, methodName, value, getter, setter) {
1312
+ if (value !== void 0) {
1313
+ return createCall(chain, methodName, async () => {
1314
+ setter(value);
1315
+ return chain.nodes;
1316
+ });
1317
+ } else {
1318
+ return createCall(chain, methodName, async () => {
1319
+ return getter();
1320
+ });
1321
+ }
1322
+ }
1323
+ function createSubChain(source, Constructor = CallChainImpl, isResolved = false) {
1324
+ const subChain = new Constructor(source.options);
1325
+ subChain.callStack = source.callStack;
1326
+ subChain.resultStack = source.resultStack;
1327
+ subChain.stackPointer = source.stackPointer;
1328
+ subChain.stoppedWithError = source.stoppedWithError;
1329
+ subChain.lastResult = source.lastResult;
1330
+ subChain.isResolved = typeof isResolved !== "undefined" ? isResolved : source.isResolved;
1331
+ subChain.lastResolvedStackPointer = source.lastResolvedStackPointer;
1332
+ if (Array.isArray(subChain.lastResult)) {
1333
+ mapArrayIndexAccess(source, subChain);
1334
+ }
1335
+ return delayedAutoStart(subChain);
1336
+ }
1337
+ function subChainForNextAwait(source) {
1338
+ if (source.lastResolvedStackPointer) {
1339
+ source.callStack = source.callStack.slice(source.lastResolvedStackPointer);
1340
+ source.stackPointer = source.stackPointer - source.lastResolvedStackPointer;
1341
+ source.resultStack = source.resultStack.slice(
1342
+ source.lastResolvedStackPointer
1343
+ );
1344
+ source.lastResult = source.resultStack[source.resultStack.length - 1] || [];
1345
+ source.lastResolvedStackPointer = 0;
1346
+ source.stoppedWithError = null;
1347
+ }
1348
+ return source instanceof CallChainImplThenable ? source : createSubChain(source, CallChainImplThenable);
1349
+ }
1350
+ function runWithTimeGuard(timeout, fn, args, onError) {
1351
+ const operationId = Math.random().toString(36).substr(2, 9);
1352
+ return defussRuntime.createTimeoutPromise(
1353
+ timeout,
1354
+ async () => {
1355
+ const chainContext = args[0];
1356
+ if (chainContext?.callStack && chainContext.stackPointer !== void 0) {
1357
+ chainContext.callStack.slice(chainContext.stackPointer).map((call) => call.name).join(" -> ");
1358
+ }
1359
+ const result = await fn(...args);
1360
+ return result;
1361
+ },
1362
+ (ms) => {
1363
+ console.log(`\u{1F534} TIMEOUT [${operationId}] after ${ms}ms`);
1364
+ const chainContext = args[0];
1365
+ if (chainContext?.callStack && chainContext.stackPointer !== void 0) {
1366
+ const currentCall = chainContext.callStack[chainContext.stackPointer];
1367
+ const remainingCalls = chainContext.callStack.slice(chainContext.stackPointer).map((call) => `${call.name}(${call.args.join(", ")})`).join(" -> ");
1368
+ console.log(
1369
+ `\u{1F534} TIMEOUT occurred during call: ${currentCall?.name || "unknown"}`
1370
+ );
1371
+ console.log(`\u{1F534} Remaining calls were: ${remainingCalls}`);
1372
+ } else {
1373
+ console.log("\u{1F534} Call stack at timeout: unknown");
1374
+ }
1375
+ const fakeCall = new Call("timeout", async () => []);
1376
+ onError(ms, fakeCall);
1377
+ }
1378
+ );
1379
+ }
1380
+ async function renderNode(input, chain) {
1381
+ if (input == null) {
1382
+ return null;
1383
+ }
1384
+ if (typeof input === "string") {
1385
+ if (isMarkup(input, chain.Parser)) {
1386
+ return renderMarkup(input, chain.Parser)[0];
1387
+ } else {
1388
+ return chain.document.createTextNode(input);
1389
+ }
1390
+ } else if (isJSX(input)) {
1391
+ return renderIsomorphicSync(
1392
+ input,
1393
+ chain.document.body,
1394
+ chain.options.globals
1395
+ );
1396
+ } else if (isRef(input)) {
1397
+ await defussRuntime.waitForRef(input, chain.options.timeout);
1398
+ return input.current;
1399
+ } else if (input && typeof input === "object" && "nodeType" in input) {
1400
+ return input;
1401
+ } else if (isDequery(input)) {
1402
+ return await input.getFirstElement();
1403
+ }
1404
+ console.warn("resolveContent: unsupported content type", input);
1405
+ return null;
1406
+ }
1407
+ async function resolveNodes(input, timeout, document) {
1408
+ let nodes = [];
1409
+ if (isRef(input)) {
1410
+ await defussRuntime.waitForRef(input, timeout);
1411
+ nodes = [input.current];
1412
+ } else if (typeof input === "string" && document) {
1413
+ const result = await waitForDOM(
1414
+ () => {
1415
+ const el2 = document.querySelector(input);
1416
+ if (el2) {
1417
+ return [el2];
1418
+ } else {
1419
+ return [];
1420
+ }
1421
+ },
1422
+ timeout,
1423
+ document
1424
+ );
1425
+ const el = result[0];
1426
+ if (el) nodes = [el];
1427
+ } else if (input && typeof input === "object" && "nodeType" in input) {
1428
+ nodes = [input];
1429
+ } else if (isDequery(input)) {
1430
+ const elements = input.nodes;
1431
+ nodes = elements.filter((el) => el.nodeType !== void 0).map((el) => el);
1432
+ } else {
1433
+ console.warn("resolveTargets: expected selector, ref or node, got", input);
1434
+ }
1435
+ return nodes;
1436
+ }
1437
+ function traverse(chain, methodName, selector) {
1438
+ return createCall(chain, methodName, async () => {
1439
+ return chain.nodes.flatMap((el) => {
1440
+ if (el instanceof Element) {
1441
+ try {
1442
+ const result = selector(el);
1443
+ if (Array.isArray(result)) {
1444
+ return result.filter(
1445
+ (item) => item instanceof Element
1446
+ );
1447
+ } else if (result instanceof Element) {
1448
+ return [result];
1449
+ }
1450
+ } catch (err) {
1451
+ console.warn("Error in traverse selector function:", err);
1452
+ }
1453
+ }
1454
+ return [];
1455
+ });
1456
+ });
1457
+ }
1458
+
1459
+ const newInMemoryGenericStorageBackend = () => {
1460
+ const cache = /* @__PURE__ */ new Map();
1461
+ return {
1462
+ clear: () => {
1463
+ cache.clear();
1464
+ },
1465
+ getItem: (key) => {
1466
+ return cache.get(String(key)) ?? null;
1467
+ },
1468
+ removeItem: (key) => {
1469
+ cache.delete(String(key));
1470
+ },
1471
+ setItem: (key, value) => {
1472
+ cache.set(String(key), value);
1473
+ }
1474
+ };
1475
+ };
1476
+ const memory = newInMemoryGenericStorageBackend();
1477
+ class WebStorageProvider {
1478
+ storage;
1479
+ constructor(storage) {
1480
+ this.storage = storage || memory;
1481
+ }
1482
+ get(key, defaultValue, middlewareFn) {
1483
+ const rawValue = this.storage.getItem(key);
1484
+ if (rawValue === null) return defaultValue;
1485
+ let value;
1486
+ try {
1487
+ value = JSON.parse(rawValue);
1488
+ } catch {
1489
+ return defaultValue;
1490
+ }
1491
+ if (middlewareFn) {
1492
+ value = middlewareFn(key, value);
1493
+ }
1494
+ return value;
1495
+ }
1496
+ set(key, value, middlewareFn) {
1497
+ if (middlewareFn) {
1498
+ value = middlewareFn(key, value);
1499
+ }
1500
+ this.storage.setItem(key, JSON.stringify(value));
1501
+ }
1502
+ remove(key) {
1503
+ this.storage.removeItem(key);
1504
+ }
1505
+ removeAll() {
1506
+ this.storage.clear();
1507
+ }
1508
+ get backendApi() {
1509
+ return this.storage;
1510
+ }
1511
+ }
1512
+
1513
+ const getPersistenceProvider$1 = (provider, _options) => {
1514
+ switch (provider) {
1515
+ case "session":
1516
+ return new WebStorageProvider(window.sessionStorage);
1517
+ case "local":
1518
+ return new WebStorageProvider(window.localStorage);
1519
+ }
1520
+ return new WebStorageProvider();
1521
+ };
1522
+
1523
+ const getPersistenceProvider = (_provider, _options) => {
1524
+ return new WebStorageProvider();
1525
+ };
1526
+
1527
+ const isServer = () => typeof window === "undefined" || typeof window.document === "undefined";
1528
+
1529
+ const webstorage = (provider = "local", options) => {
1530
+ if (isServer()) {
1531
+ return getPersistenceProvider();
1532
+ } else {
1533
+ return getPersistenceProvider$1(provider);
1534
+ }
1535
+ };
1536
+
1537
+ const shallowEquals = (a, b) => Object.is(a, b);
1538
+ const deepEquals = (a, b) => JSON.stringify(a) === JSON.stringify(b);
1539
+ const createStore = (initialValue, options = {}) => {
1540
+ const equals = options.equals ?? shallowEquals;
1541
+ let value = initialValue;
1542
+ const listeners = [];
1543
+ const notify = (oldValue, changedKey) => {
1544
+ listeners.forEach((listener) => listener(value, oldValue, changedKey));
1545
+ };
1546
+ let storage = null;
1547
+ let storageKey = null;
1548
+ let storageProvider;
1549
+ const initStorage = (provider) => {
1550
+ if (!storage || storageProvider !== provider) {
1551
+ storage = webstorage(provider);
1552
+ storageProvider = provider;
1553
+ }
1554
+ return storage;
1555
+ };
1556
+ const persistToStorage = () => {
1557
+ if (storage && storageKey) {
1558
+ storage.set(storageKey, value);
1559
+ }
1560
+ };
1561
+ return {
1562
+ // allow reading value but prevent external mutation
1563
+ get value() {
1564
+ return value;
1565
+ },
1566
+ persist(key, provider = "local") {
1567
+ storage = initStorage(provider);
1568
+ storageKey = key;
1569
+ persistToStorage();
1570
+ },
1571
+ restore(key, provider = "local") {
1572
+ storage = initStorage(provider);
1573
+ storageKey = key;
1574
+ const storedValue = storage.get(key, value);
1575
+ const oldValue = value;
1576
+ if (!equals(oldValue, storedValue)) {
1577
+ value = storedValue;
1578
+ notify(oldValue);
1579
+ }
1580
+ },
1581
+ get(path) {
1582
+ return path ? defussRuntime.getByPath(value, path) : value;
1583
+ },
1584
+ /** Get entire store value (clearer API) */
1585
+ getRaw() {
1586
+ return value;
1587
+ },
1588
+ /** Replace entire store value (clearer API) */
1589
+ setRaw(newValue) {
1590
+ const oldValue = value;
1591
+ if (!equals(value, newValue)) {
1592
+ value = newValue;
1593
+ notify(oldValue);
1594
+ persistToStorage();
1595
+ }
1596
+ },
1597
+ /** Reset to initial or provided value */
1598
+ reset(resetValue) {
1599
+ const oldValue = value;
1600
+ const newValue = resetValue ?? initialValue;
1601
+ if (!equals(value, newValue)) {
1602
+ value = newValue;
1603
+ notify(oldValue);
1604
+ persistToStorage();
1605
+ }
1606
+ },
1607
+ set(pathOrValue, newValue) {
1608
+ const oldValue = value;
1609
+ if (newValue === void 0) {
1610
+ if (!equals(value, pathOrValue)) {
1611
+ value = pathOrValue;
1612
+ notify(oldValue);
1613
+ persistToStorage();
1614
+ }
1615
+ } else {
1616
+ const updatedValue = defussRuntime.setByPath(value, pathOrValue, newValue);
1617
+ if (!equals(value, updatedValue)) {
1618
+ value = updatedValue;
1619
+ notify(oldValue, pathOrValue);
1620
+ persistToStorage();
1621
+ }
1622
+ }
1623
+ },
1624
+ subscribe(listener) {
1625
+ listeners.push(listener);
1626
+ return () => {
1627
+ const index = listeners.indexOf(listener);
1628
+ if (index >= 0) listeners.splice(index, 1);
1629
+ };
1630
+ }
1631
+ };
1632
+ };
1633
+
1634
+ const isRef = (obj) => Boolean(obj && typeof obj === "object" && "current" in obj);
1635
+ function createRef(refUpdateFn, defaultState) {
1636
+ const stateStore = createStore(defaultState);
1637
+ const ref = {
1638
+ current: null,
1639
+ store: stateStore,
1640
+ get state() {
1641
+ return stateStore.value;
1642
+ },
1643
+ set state(value) {
1644
+ stateStore.set(value);
1645
+ },
1646
+ persist: (key, provider = "local") => {
1647
+ stateStore.persist(key, provider);
1648
+ },
1649
+ restore: (key, provider = "local") => {
1650
+ stateStore.restore(key, provider);
1651
+ },
1652
+ updateState: (state) => {
1653
+ stateStore.set(state);
1654
+ },
1655
+ update: async (input) => await $(ref.current).update(input),
1656
+ subscribe: (refUpdateFn2) => stateStore.subscribe(refUpdateFn2)
1657
+ };
1658
+ if (typeof refUpdateFn === "function") {
1659
+ ref.subscribe(refUpdateFn);
1660
+ }
1661
+ return ref;
1662
+ }
1663
+
1664
+ const injectShakeKeyframes = () => {
1665
+ if (!document.getElementById("defuss-shake")) {
1666
+ const style = document.createElement("style");
1667
+ style.id = "defuss-shake";
1668
+ style.textContent = "@keyframes shake{0%,100%{transform:translate3d(0,0,0)}10%,30%,50%,70%,90%{transform:translate3d(-10px,0,0)}20%,40%,60%,80%{transform:translate3d(10px,0,0)}}";
1669
+ document.head.appendChild(style);
1670
+ }
1671
+ };
1672
+ const getTransitionStyles = (type, duration, easing = "ease-in-out") => {
1673
+ const t = `transform ${duration}ms ${easing}, opacity ${duration}ms ${easing}`;
1674
+ const styles = {
1675
+ fade: {
1676
+ enter: { opacity: "0", transition: t, transform: "translate3d(0,0,0)" },
1677
+ enterActive: { opacity: "1" },
1678
+ exit: { opacity: "1", transition: t, transform: "translate3d(0,0,0)" },
1679
+ exitActive: { opacity: "0" }
1680
+ },
1681
+ "slide-left": {
1682
+ enter: {
1683
+ transform: "translate3d(100%,0,0)",
1684
+ opacity: "0.5",
1685
+ transition: t
1686
+ },
1687
+ enterActive: { transform: "translate3d(0,0,0)", opacity: "1" },
1688
+ exit: { transform: "translate3d(0,0,0)", opacity: "1", transition: t },
1689
+ exitActive: { transform: "translate3d(-100%,0,0)", opacity: "0.5" }
1690
+ },
1691
+ "slide-right": {
1692
+ enter: {
1693
+ transform: "translate3d(-100%,0,0)",
1694
+ opacity: "0.5",
1695
+ transition: t
1696
+ },
1697
+ enterActive: { transform: "translate3d(0,0,0)", opacity: "1" },
1698
+ exit: { transform: "translate3d(0,0,0)", opacity: "1", transition: t },
1699
+ exitActive: { transform: "translate3d(100%,0,0)", opacity: "0.5" }
1700
+ },
1701
+ shake: (() => {
1702
+ injectShakeKeyframes();
1703
+ return {
1704
+ enter: {
1705
+ transform: "translate3d(0,0,0)",
1706
+ opacity: "1",
1707
+ transition: "none"
1708
+ },
1709
+ enterActive: {
1710
+ transform: "translate3d(0,0,0)",
1711
+ opacity: "1",
1712
+ animation: `shake ${duration}ms cubic-bezier(0.36,0.07,0.19,0.97)`
1713
+ },
1714
+ exit: {
1715
+ transform: "translate3d(0,0,0)",
1716
+ opacity: "1",
1717
+ transition: "none"
1718
+ },
1719
+ exitActive: {
1720
+ transform: "translate3d(0,0,0)",
1721
+ opacity: "1",
1722
+ animation: `shake ${duration}ms cubic-bezier(0.36,0.07,0.19,0.97)`
1723
+ }
1724
+ };
1725
+ })()
1726
+ };
1727
+ return styles[type] || { enter: {}, enterActive: {}, exit: {}, exitActive: {} };
1728
+ };
1729
+ const applyStyles = (el, styles) => Object.entries(styles).forEach(
1730
+ ([k, v]) => el.style.setProperty(k, String(v))
1731
+ );
1732
+ const DEFAULT_TRANSITION_CONFIG = {
1733
+ type: "fade",
1734
+ duration: 300,
1735
+ easing: "ease-in-out",
1736
+ delay: 0,
1737
+ target: "parent"
1738
+ };
1739
+ const wait = (ms) => new Promise((r) => setTimeout(r, ms));
1740
+ const performCrossfade = async (element, updateCallback, duration, easing) => {
1741
+ const originalStyle = element.style.cssText;
1742
+ const snapshot = element.cloneNode(true);
1743
+ try {
1744
+ const container = element.parentElement || element;
1745
+ const rect = element.getBoundingClientRect();
1746
+ snapshot.style.cssText = `position:absolute;top:${rect.top}px;left:${rect.left}px;width:${rect.width}px;height:${rect.height}px;opacity:1;transition:opacity ${duration}ms ${easing};z-index:1000;`;
1747
+ element.style.opacity = "0";
1748
+ element.style.transition = `opacity ${duration}ms ${easing}`;
1749
+ document.body.appendChild(snapshot);
1750
+ await updateCallback();
1751
+ void element.offsetHeight;
1752
+ snapshot.style.opacity = "0";
1753
+ element.style.opacity = "1";
1754
+ await wait(duration);
1755
+ document.body.removeChild(snapshot);
1756
+ } catch (error) {
1757
+ if (snapshot.parentElement) document.body.removeChild(snapshot);
1758
+ throw error;
1759
+ } finally {
1760
+ element.style.cssText = originalStyle;
1761
+ }
1762
+ };
1763
+ const performTransition = async (element, updateCallback, config = {}) => {
1764
+ const {
1765
+ type = "fade",
1766
+ duration = 300,
1767
+ easing = "ease-in-out",
1768
+ delay = 0
1769
+ } = { ...DEFAULT_TRANSITION_CONFIG, ...config };
1770
+ if (type === "none") {
1771
+ await updateCallback();
1772
+ return;
1773
+ }
1774
+ if (delay > 0) await wait(delay);
1775
+ if (type === "fade") {
1776
+ await performCrossfade(element, updateCallback, duration, easing);
1777
+ return;
1778
+ }
1779
+ const styles = config.styles || getTransitionStyles(type, duration, easing);
1780
+ const originalTransition = element.style.transition;
1781
+ const originalAnimation = element.style.animation;
1782
+ try {
1783
+ if (type === "shake") {
1784
+ element.style.animation = "none";
1785
+ void element.offsetHeight;
1786
+ }
1787
+ applyStyles(element, styles.exit);
1788
+ void element.offsetHeight;
1789
+ applyStyles(element, styles.exitActive);
1790
+ await wait(duration);
1791
+ await updateCallback();
1792
+ applyStyles(element, styles.enter);
1793
+ void element.offsetHeight;
1794
+ applyStyles(element, styles.enterActive);
1795
+ await wait(duration);
1796
+ element.style.transition = originalTransition;
1797
+ element.style.animation = originalAnimation;
1798
+ } catch (error) {
1799
+ element.style.transition = originalTransition;
1800
+ element.style.animation = originalAnimation;
1801
+ throw error;
1802
+ }
1803
+ };
1804
+
1805
+ const queueCallback = (cb) => () => queueMicrotask(cb);
1806
+
1807
+ const CLASS_ATTRIBUTE_NAME = "class";
1808
+ const XLINK_ATTRIBUTE_NAME = "xlink";
1809
+ const XMLNS_ATTRIBUTE_NAME = "xmlns";
1810
+ const REF_ATTRIBUTE_NAME = "ref";
1811
+ const DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE = "dangerouslySetInnerHTML";
1812
+ const nsMap = {
1813
+ [XMLNS_ATTRIBUTE_NAME]: "http://www.w3.org/2000/xmlns/",
1814
+ [XLINK_ATTRIBUTE_NAME]: "http://www.w3.org/1999/xlink",
1815
+ svg: "http://www.w3.org/2000/svg"
1816
+ };
1817
+ const isJSXComment = (node) => (
1818
+ /* v8 ignore next */
1819
+ node && typeof node === "object" && !node.attributes && !node.type && !node.children
1820
+ );
1821
+ const filterComments = (children) => children.filter((child) => !isJSXComment(child));
1822
+ const createInPlaceErrorMessageVNode = (error) => ({
1823
+ type: "p",
1824
+ attributes: {},
1825
+ children: [`FATAL ERROR: ${error?.message || error}`]
1826
+ });
1827
+ const jsx = (type, attributes, key, sourceInfo) => {
1828
+ attributes = { ...attributes };
1829
+ if (typeof key !== "undefined") {
1830
+ attributes.key = key;
1831
+ }
1832
+ let children = (attributes?.children ? [].concat(attributes.children) : []).filter((c) => c !== null && c !== void 0 && typeof c !== "boolean");
1833
+ delete attributes?.children;
1834
+ children = filterComments(
1835
+ // Implementation to flatten virtual node children structures like:
1836
+ // [<p>1</p>, [<p>2</p>,<p>3</p>]] to: [<p>1</p>,<p>2</p>,<p>3</p>]
1837
+ [].concat.apply(
1838
+ [],
1839
+ children
1840
+ )
1841
+ );
1842
+ if (type === "fragment") {
1843
+ return filterComments(children);
1844
+ }
1845
+ if (typeof type === "function" && type.constructor.name !== "AsyncFunction") {
1846
+ try {
1847
+ const rendered = type({
1848
+ children,
1849
+ ...attributes
1850
+ });
1851
+ if (typeof key !== "undefined" && rendered && typeof rendered === "object") {
1852
+ if ("attributes" in rendered) {
1853
+ rendered.attributes = {
1854
+ ...rendered.attributes,
1855
+ key
1856
+ };
1857
+ } else if (Array.isArray(rendered) && rendered.length === 1) {
1858
+ const only = rendered[0];
1859
+ if (only && typeof only === "object" && "attributes" in only) {
1860
+ only.attributes = {
1861
+ ...only.attributes,
1862
+ key
1863
+ };
1864
+ }
1865
+ }
1866
+ }
1867
+ return rendered;
1868
+ } catch (error) {
1869
+ if (typeof error === "string") {
1870
+ error = `[JsxError] in ${type.name}: ${error}`;
1871
+ } else if (error instanceof Error) {
1872
+ error.message = `[JsxError] in ${type.name}: ${error.message}`;
1873
+ }
1874
+ return createInPlaceErrorMessageVNode(error);
1875
+ }
1876
+ }
1877
+ return {
1878
+ type,
1879
+ attributes,
1880
+ children,
1881
+ sourceInfo
1882
+ };
1883
+ };
1884
+ const observeUnmount = (domNode, onUnmount) => {
1885
+ if (!domNode || typeof onUnmount !== "function") {
1886
+ throw new Error(
1887
+ "Invalid arguments. Ensure domNode and onUnmount are valid."
1888
+ );
1889
+ }
1890
+ let parentNode = domNode.parentNode;
1891
+ if (!parentNode) {
1892
+ throw new Error("The provided domNode does not have a parentNode.");
1893
+ }
1894
+ const observer = new MutationObserver((mutationsList) => {
1895
+ for (const mutation of mutationsList) {
1896
+ if (mutation.removedNodes.length > 0) {
1897
+ for (const removedNode of mutation.removedNodes) {
1898
+ if (removedNode === domNode) {
1899
+ queueMicrotask(() => {
1900
+ if (!domNode.isConnected) {
1901
+ onUnmount();
1902
+ observer.disconnect();
1903
+ return;
1904
+ }
1905
+ const newParent = domNode.parentNode;
1906
+ if (newParent && newParent !== parentNode) {
1907
+ parentNode = newParent;
1908
+ observer.disconnect();
1909
+ observer.observe(parentNode, { childList: true });
1910
+ }
1911
+ });
1912
+ return;
1913
+ }
1914
+ }
1915
+ }
1916
+ }
1917
+ });
1918
+ observer.observe(parentNode, { childList: true });
1919
+ };
1920
+ const handleLifecycleEventsForOnMount = (newEl) => {
1921
+ if (typeof newEl?.$onMount === "function") {
1922
+ newEl.$onMount();
1923
+ newEl.$onMount = null;
1924
+ }
1925
+ if (typeof newEl?.$onUnmount === "function") {
1926
+ observeUnmount(newEl, newEl.$onUnmount);
1927
+ }
1928
+ };
1929
+ const getRenderer = (document) => {
1930
+ const renderer = {
1931
+ hasElNamespace: (domElement) => domElement.namespaceURI === nsMap.svg,
1932
+ hasSvgNamespace: (parentElement, type) => renderer.hasElNamespace(parentElement) && type !== "STYLE" && type !== "SCRIPT",
1933
+ createElementOrElements: (virtualNode, parentDomElement) => {
1934
+ if (Array.isArray(virtualNode)) {
1935
+ return renderer.createChildElements(virtualNode, parentDomElement);
1936
+ }
1937
+ if (typeof virtualNode !== "undefined") {
1938
+ return renderer.createElement(virtualNode, parentDomElement);
1939
+ }
1940
+ return renderer.createTextNode("", parentDomElement);
1941
+ },
1942
+ createElement: (virtualNode, parentDomElement) => {
1943
+ let newEl = void 0;
1944
+ try {
1945
+ if (virtualNode.constructor.name === "AsyncFunction") {
1946
+ newEl = document.createElement("div");
1947
+ } else if (typeof virtualNode.type === "function") {
1948
+ newEl = document.createElement("div");
1949
+ newEl.innerText = `FATAL ERROR: ${virtualNode.type._error}`;
1950
+ } else if (
1951
+ // SVG support
1952
+ virtualNode.type.toUpperCase() === "SVG" || parentDomElement && renderer.hasSvgNamespace(
1953
+ parentDomElement,
1954
+ virtualNode.type.toUpperCase()
1955
+ )
1956
+ ) {
1957
+ newEl = document.createElementNS(
1958
+ nsMap.svg,
1959
+ virtualNode.type
1960
+ );
1961
+ } else {
1962
+ newEl = document.createElement(virtualNode.type);
1963
+ }
1964
+ if (virtualNode.attributes) {
1965
+ renderer.setAttributes(virtualNode, newEl);
1966
+ if (virtualNode.attributes.dangerouslySetInnerHTML) {
1967
+ newEl.innerHTML = virtualNode.attributes.dangerouslySetInnerHTML.__html;
1968
+ }
1969
+ }
1970
+ if (virtualNode.children && !virtualNode.attributes?.dangerouslySetInnerHTML) {
1971
+ renderer.createChildElements(virtualNode.children, newEl);
1972
+ }
1973
+ if (parentDomElement) {
1974
+ parentDomElement.appendChild(newEl);
1975
+ handleLifecycleEventsForOnMount(newEl);
1976
+ }
1977
+ } catch (e) {
1978
+ console.error(
1979
+ "Fatal error! Error happend while rendering the VDOM!",
1980
+ e,
1981
+ virtualNode
1982
+ );
1983
+ throw e;
1984
+ }
1985
+ return newEl;
1986
+ },
1987
+ createTextNode: (text, domElement) => {
1988
+ const node = document.createTextNode(text.toString());
1989
+ if (domElement) {
1990
+ domElement.appendChild(node);
1991
+ }
1992
+ return node;
1993
+ },
1994
+ createChildElements: (virtualChildren, domElement) => {
1995
+ const children = [];
1996
+ for (let i = 0; i < virtualChildren.length; i++) {
1997
+ const virtualChild = virtualChildren[i];
1998
+ if (typeof virtualChild === "boolean") {
1999
+ continue;
2000
+ }
2001
+ if (virtualChild === null || typeof virtualChild !== "object" && typeof virtualChild !== "function") {
2002
+ children.push(
2003
+ renderer.createTextNode(
2004
+ (typeof virtualChild === "undefined" || virtualChild === null ? "" : virtualChild).toString(),
2005
+ domElement
2006
+ )
2007
+ );
2008
+ } else {
2009
+ children.push(
2010
+ renderer.createElement(virtualChild, domElement)
2011
+ );
2012
+ }
2013
+ }
2014
+ return children;
2015
+ },
2016
+ setAttribute: (name, value, domElement, virtualNode) => {
2017
+ if (typeof value === "undefined") return;
2018
+ if (name === DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE) return;
2019
+ if (name === "key") {
2020
+ domElement._defussKey = String(value);
2021
+ return;
2022
+ }
2023
+ if (name === REF_ATTRIBUTE_NAME && typeof value !== "function") {
2024
+ const ref = value;
2025
+ ref.current = domElement;
2026
+ domElement._defussRef = value;
2027
+ domElement.$onUnmount = queueCallback(() => {
2028
+ });
2029
+ if (domElement.parentNode) {
2030
+ observeUnmount(domElement, domElement.$onUnmount);
2031
+ } else {
2032
+ queueMicrotask(() => {
2033
+ if (domElement.parentNode) {
2034
+ observeUnmount(domElement, domElement.$onUnmount);
2035
+ }
2036
+ });
2037
+ }
2038
+ return;
2039
+ }
2040
+ const parsed = parseEventPropName(name);
2041
+ if (parsed && typeof value === "function") {
2042
+ const { eventType, capture } = parsed;
2043
+ if (eventType === "mount") {
2044
+ domElement.$onMount = queueCallback(value);
2045
+ return;
2046
+ }
2047
+ if (eventType === "unmount") {
2048
+ if (domElement.$onUnmount) {
2049
+ const existingUnmount = domElement.$onUnmount;
2050
+ domElement.$onUnmount = () => {
2051
+ existingUnmount();
2052
+ value();
2053
+ };
2054
+ } else {
2055
+ domElement.$onUnmount = queueCallback(value);
2056
+ }
2057
+ return;
2058
+ }
2059
+ registerDelegatedEvent(domElement, eventType, value, { capture });
2060
+ return;
2061
+ }
2062
+ if (name === "className") {
2063
+ name = CLASS_ATTRIBUTE_NAME;
2064
+ }
2065
+ if (name === CLASS_ATTRIBUTE_NAME && Array.isArray(value)) {
2066
+ value = value.join(" ");
2067
+ }
2068
+ const nsEndIndex = name.match(/[A-Z]/)?.index;
2069
+ if (renderer.hasElNamespace(domElement) && nsEndIndex) {
2070
+ const ns = name.substring(0, nsEndIndex).toLowerCase();
2071
+ const attrName = name.substring(nsEndIndex, name.length).toLowerCase();
2072
+ const namespace = nsMap[ns] || null;
2073
+ domElement.setAttributeNS(
2074
+ namespace,
2075
+ ns === XLINK_ATTRIBUTE_NAME || ns === XMLNS_ATTRIBUTE_NAME ? `${ns}:${attrName}` : name,
2076
+ String(value)
2077
+ );
2078
+ } else if (name === "style" && typeof value !== "string") {
2079
+ const styleObj = value;
2080
+ for (const prop of Object.keys(styleObj)) {
2081
+ domElement.style[prop] = String(styleObj[prop]);
2082
+ }
2083
+ } else if (typeof value === "boolean") {
2084
+ domElement[name] = value;
2085
+ } else if (
2086
+ // Controlled input props: use property assignment, not setAttribute
2087
+ // setAttribute updates the default value, property updates the live value
2088
+ (name === "value" || name === "checked" || name === "selectedIndex") && (domElement instanceof HTMLInputElement || domElement instanceof HTMLTextAreaElement || domElement instanceof HTMLSelectElement)
2089
+ ) {
2090
+ domElement[name] = value;
2091
+ } else {
2092
+ domElement.setAttribute(name, String(value));
2093
+ }
2094
+ },
2095
+ setAttributes: (virtualNode, domElement) => {
2096
+ const attrNames = Object.keys(virtualNode.attributes);
2097
+ for (let i = 0; i < attrNames.length; i++) {
2098
+ renderer.setAttribute(
2099
+ attrNames[i],
2100
+ virtualNode.attributes[attrNames[i]],
2101
+ domElement,
2102
+ virtualNode
2103
+ );
2104
+ }
2105
+ }
2106
+ };
2107
+ return renderer;
2108
+ };
2109
+ const renderIsomorphicSync = (virtualNode, parentDomElement, globals) => {
2110
+ if (isDequery(parentDomElement)) {
2111
+ parentDomElement = parentDomElement.getFirstElement() || parentDomElement;
2112
+ }
2113
+ let renderResult;
2114
+ if (typeof virtualNode === "string") {
2115
+ renderResult = getRenderer(globals.window.document).createTextNode(
2116
+ virtualNode,
2117
+ parentDomElement
2118
+ );
2119
+ } else {
2120
+ renderResult = getRenderer(globals.window.document).createElementOrElements(
2121
+ virtualNode,
2122
+ parentDomElement
2123
+ );
2124
+ }
2125
+ return renderResult;
2126
+ };
2127
+ const renderIsomorphicAsync = async (virtualNode, parentDomElement, globals) => {
2128
+ if (parentDomElement instanceof Promise) {
2129
+ parentDomElement = await parentDomElement;
2130
+ }
2131
+ if (isDequery(parentDomElement)) {
2132
+ parentDomElement = (await parentDomElement.toArray())[0];
2133
+ }
2134
+ if (virtualNode instanceof Promise) {
2135
+ virtualNode = await virtualNode;
2136
+ }
2137
+ return renderIsomorphicSync(
2138
+ virtualNode,
2139
+ parentDomElement,
2140
+ globals
2141
+ );
2142
+ };
2143
+ const globalScopeDomApis = (window, document) => {
2144
+ globalThis.__defuss_document = document;
2145
+ globalThis.__defuss_window = window;
2146
+ };
2147
+ const renderInto = (jsx2, container) => {
2148
+ if (!container) {
2149
+ console.warn("renderInto: container is null or undefined");
2150
+ return;
2151
+ }
2152
+ const globals = {
2153
+ window: container.ownerDocument?.defaultView ?? globalThis
2154
+ };
2155
+ updateDomWithVdom(container, jsx2, globals);
2156
+ };
2157
+ const render = renderInto;
2158
+ const isJSX = (o) => {
2159
+ if (o === null || typeof o !== "object") return false;
2160
+ if (Array.isArray(o)) {
2161
+ return o.every(
2162
+ (item) => isJSX(item) || typeof item === "string" || typeof item === "number"
2163
+ );
2164
+ }
2165
+ if (typeof o.type === "string") return true;
2166
+ if (typeof o.type === "function") return true;
2167
+ if (typeof o.attributes === "object" && typeof o.children === "object")
2168
+ return true;
2169
+ return false;
2170
+ };
2171
+ const Fragment = (props) => props.children;
2172
+ const jsxs = jsx;
2173
+ const jsxDEV = (type, attributes, key, allChildrenAreStatic, sourceInfo, selfReference) => {
2174
+ let renderResult;
2175
+ try {
2176
+ if (sourceInfo) {
2177
+ if (typeof type === "function" && type.constructor.name !== "AsyncFunction") {
2178
+ sourceInfo.exportName = type.name || sourceInfo?.exportName;
2179
+ }
2180
+ sourceInfo.allChildrenAreStatic = allChildrenAreStatic;
2181
+ sourceInfo.selfReference = selfReference;
2182
+ }
2183
+ renderResult = jsx(type, attributes, key, sourceInfo);
2184
+ } catch (error) {
2185
+ console.error(
2186
+ "JSX error:",
2187
+ error,
2188
+ "in",
2189
+ sourceInfo,
2190
+ "component",
2191
+ selfReference
2192
+ );
2193
+ }
2194
+ return renderResult;
2195
+ };
2196
+ async function performCoreDomUpdate(input, nodes, timeout, Parser) {
2197
+ let processedInput = input;
2198
+ if (isDequery(processedInput)) {
2199
+ processedInput = processedInput[0];
2200
+ }
2201
+ if (isRef(processedInput)) {
2202
+ await defussRuntime.waitForRef(processedInput, timeout);
2203
+ processedInput = processedInput.current;
2204
+ }
2205
+ const getGlobalsFromElement = (el) => {
2206
+ const win = el.ownerDocument?.defaultView;
2207
+ return win ?? globalThis;
2208
+ };
2209
+ if (processedInput instanceof Node) {
2210
+ const vnode = domNodeToVNode(processedInput);
2211
+ nodes.forEach((el) => {
2212
+ if (el) {
2213
+ updateDomWithVdom(el, vnode, getGlobalsFromElement(el));
2214
+ }
2215
+ });
2216
+ return;
2217
+ }
2218
+ if (typeof processedInput === "string") {
2219
+ if (isMarkup(processedInput, Parser)) {
2220
+ const vNodes = htmlStringToVNodes(processedInput, Parser);
2221
+ nodes.forEach((el) => {
2222
+ if (el) {
2223
+ updateDomWithVdom(el, vNodes, getGlobalsFromElement(el));
2224
+ }
2225
+ });
2226
+ } else {
2227
+ nodes.forEach((el) => {
2228
+ if (el) {
2229
+ updateDomWithVdom(
2230
+ el,
2231
+ processedInput,
2232
+ getGlobalsFromElement(el)
2233
+ );
2234
+ }
2235
+ });
2236
+ }
2237
+ } else if (isJSX(processedInput)) {
2238
+ nodes.forEach((el) => {
2239
+ if (el) {
2240
+ updateDomWithVdom(
2241
+ el,
2242
+ processedInput,
2243
+ getGlobalsFromElement(el)
2244
+ );
2245
+ }
2246
+ });
2247
+ } else {
2248
+ console.warn("update: unsupported content type", processedInput);
2249
+ }
2250
+ }
2251
+ async function updateDom(input, nodes, timeout, Parser, transitionConfig) {
2252
+ if (transitionConfig && transitionConfig.type !== "none") {
2253
+ const config = { ...DEFAULT_TRANSITION_CONFIG, ...transitionConfig };
2254
+ const { target = "self" } = config;
2255
+ const transitionPromises = nodes.map(async (node) => {
2256
+ if (!node) return node;
2257
+ const element = node;
2258
+ const transitionTarget = target === "self" ? element : element.parentElement;
2259
+ if (!transitionTarget) {
2260
+ await performCoreDomUpdate(input, [node], timeout, Parser);
2261
+ return node;
2262
+ }
2263
+ await performTransition(
2264
+ transitionTarget,
2265
+ () => performCoreDomUpdate(input, [node], timeout, Parser),
2266
+ config
2267
+ );
2268
+ return node;
2269
+ });
2270
+ await Promise.all(transitionPromises);
2271
+ return nodes;
2272
+ }
2273
+ await performCoreDomUpdate(input, nodes, timeout, Parser);
2274
+ return nodes;
2275
+ }
2276
+
2277
+ const areDomNodesEqual = (oldNode, newNode) => {
2278
+ if (oldNode === newNode) return true;
2279
+ if (oldNode.nodeType !== newNode.nodeType) return false;
2280
+ if (oldNode.nodeType === Node.ELEMENT_NODE) {
2281
+ const oldElement = oldNode;
2282
+ const newElement = newNode;
2283
+ if (oldElement.tagName !== newElement.tagName) return false;
2284
+ const oldAttrs = oldElement.attributes;
2285
+ const newAttrs = newElement.attributes;
2286
+ if (oldAttrs.length !== newAttrs.length) return false;
2287
+ for (let i = 0; i < oldAttrs.length; i++) {
2288
+ const oldAttr = oldAttrs[i];
2289
+ const newAttrValue = newElement.getAttribute(oldAttr.name);
2290
+ if (oldAttr.value !== newAttrValue) return false;
2291
+ }
2292
+ }
2293
+ if (oldNode.nodeType === Node.TEXT_NODE) {
2294
+ if (oldNode.textContent !== newNode.textContent) return false;
2295
+ }
2296
+ return true;
2297
+ };
2298
+ function isTextLike(value) {
2299
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
2300
+ }
2301
+ function isVNode(value) {
2302
+ return Boolean(value && typeof value === "object" && "type" in value);
2303
+ }
2304
+ function toValidChild(child) {
2305
+ if (child == null) return child;
2306
+ if (isTextLike(child)) return child;
2307
+ if (isVNode(child)) return child;
2308
+ return void 0;
2309
+ }
2310
+ function normalizeChildren(input) {
2311
+ const raw = [];
2312
+ const pushChild = (child) => {
2313
+ if (Array.isArray(child)) {
2314
+ child.forEach(pushChild);
2315
+ return;
2316
+ }
2317
+ const valid = toValidChild(child);
2318
+ if (typeof valid === "undefined") return;
2319
+ if (isVNode(valid) && (valid.type === "fragment" || valid.type === "Fragment")) {
2320
+ const nested = Array.isArray(valid.children) ? valid.children : [];
2321
+ nested.forEach(pushChild);
2322
+ return;
2323
+ }
2324
+ if (valid === null || typeof valid === "undefined" || typeof valid === "boolean") return;
2325
+ raw.push(valid);
2326
+ };
2327
+ pushChild(input);
2328
+ const fused = [];
2329
+ let buffer = null;
2330
+ const flush = () => {
2331
+ if (buffer !== null && buffer.length > 0) fused.push(buffer);
2332
+ buffer = null;
2333
+ };
2334
+ for (const child of raw) {
2335
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2336
+ buffer = (buffer ?? "") + String(child);
2337
+ continue;
2338
+ }
2339
+ flush();
2340
+ fused.push(child);
2341
+ }
2342
+ flush();
2343
+ return fused;
2344
+ }
2345
+ function getVNodeMatchKey(child) {
2346
+ if (!child || typeof child !== "object") return null;
2347
+ const key = child.attributes?.key;
2348
+ if (typeof key === "string" || typeof key === "number") return `k:${String(key)}`;
2349
+ const id = child.attributes?.id;
2350
+ if (typeof id === "string" && id.length > 0) return `id:${id}`;
2351
+ return null;
2352
+ }
2353
+ function getDomMatchKeys(node) {
2354
+ if (node.nodeType !== Node.ELEMENT_NODE) return [];
2355
+ const el = node;
2356
+ const keys = [];
2357
+ const internalKey = el._defussKey;
2358
+ if (internalKey) keys.push(`k:${internalKey}`);
2359
+ const attrKey = el.getAttribute("key");
2360
+ if (attrKey) keys.push(`k:${attrKey}`);
2361
+ const id = el.id;
2362
+ if (id) keys.push(`id:${id}`);
2363
+ return keys;
2364
+ }
2365
+ function areNodeAndChildMatching(domNode, child) {
2366
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2367
+ return domNode.nodeType === Node.TEXT_NODE;
2368
+ }
2369
+ if (child && typeof child === "object") {
2370
+ if (domNode.nodeType !== Node.ELEMENT_NODE) return false;
2371
+ const el = domNode;
2372
+ const oldTag = el.tagName.toLowerCase();
2373
+ const newTag = typeof child.type === "string" ? child.type.toLowerCase() : "";
2374
+ if (!newTag || oldTag !== newTag) return false;
2375
+ const vnodeClass = child.attributes?.className ?? child.attributes?.class;
2376
+ if (typeof vnodeClass === "string") {
2377
+ if ((el.getAttribute("class") ?? "") !== vnodeClass) return false;
2378
+ }
2379
+ return true;
2380
+ }
2381
+ return false;
2382
+ }
2383
+ function createDomFromChild(child, globals) {
2384
+ const renderer = getRenderer(globals.window.document);
2385
+ if (child == null) return void 0;
2386
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2387
+ return [globals.window.document.createTextNode(String(child))];
2388
+ }
2389
+ const created = renderer.createElementOrElements(child);
2390
+ if (!created) return void 0;
2391
+ const nodes = Array.isArray(created) ? created : [created];
2392
+ return nodes.filter(Boolean);
2393
+ }
2394
+ function shouldPreserveFormStateAttribute(el, attrName, vnode) {
2395
+ const tag = el.tagName.toLowerCase();
2396
+ const hasExplicit = Object.prototype.hasOwnProperty.call(vnode.attributes ?? {}, attrName);
2397
+ if (hasExplicit) return false;
2398
+ if (tag === "input") return attrName === "value" || attrName === "checked";
2399
+ if (tag === "textarea") return attrName === "value";
2400
+ if (tag === "select") return attrName === "value";
2401
+ return false;
2402
+ }
2403
+ function patchElementInPlace(el, vnode, globals) {
2404
+ const renderer = getRenderer(globals.window.document);
2405
+ const existingAttrs = Array.from(el.attributes);
2406
+ const nextAttrs = vnode.attributes ?? {};
2407
+ for (const attr of existingAttrs) {
2408
+ const { name } = attr;
2409
+ if (name === "key") continue;
2410
+ if (name.startsWith("on")) continue;
2411
+ if (name === "class" && (Object.prototype.hasOwnProperty.call(nextAttrs, "class") || Object.prototype.hasOwnProperty.call(nextAttrs, "className"))) {
2412
+ continue;
2413
+ }
2414
+ if (!Object.prototype.hasOwnProperty.call(nextAttrs, name)) {
2415
+ if (shouldPreserveFormStateAttribute(el, name, vnode)) continue;
2416
+ el.removeAttribute(name);
2417
+ }
2418
+ }
2419
+ const registeredKeys = getRegisteredEventKeys(el);
2420
+ const nextEventKeys = /* @__PURE__ */ new Set();
2421
+ for (const propName of Object.keys(nextAttrs)) {
2422
+ const parsed = parseEventPropName(propName);
2423
+ if (parsed) {
2424
+ const phase = parsed.capture ? "capture" : "bubble";
2425
+ nextEventKeys.add(`${parsed.eventType}:${phase}`);
2426
+ }
2427
+ }
2428
+ for (const key of registeredKeys) {
2429
+ if (!nextEventKeys.has(key)) {
2430
+ const [eventType, phase] = key.split(":");
2431
+ removeDelegatedEventByKey(el, eventType, phase);
2432
+ }
2433
+ }
2434
+ renderer.setAttributes(vnode, el);
2435
+ handleLifecycleEventsForOnMount(el);
2436
+ const d = vnode.attributes?.dangerouslySetInnerHTML;
2437
+ if (d && typeof d === "object" && typeof d.__html === "string") {
2438
+ el.innerHTML = d.__html;
2439
+ return;
2440
+ }
2441
+ const tag = el.tagName.toLowerCase();
2442
+ if (tag === "textarea") {
2443
+ const isControlled = Object.prototype.hasOwnProperty.call(nextAttrs, "value");
2444
+ const isActive = el.ownerDocument?.activeElement === el;
2445
+ if (isActive && !isControlled) return;
2446
+ }
2447
+ updateDomWithVdom(el, vnode.children ?? [], globals);
2448
+ }
2449
+ function morphNode(domNode, child, globals) {
2450
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2451
+ const text = String(child);
2452
+ if (domNode.nodeType === Node.TEXT_NODE) {
2453
+ if (domNode.nodeValue !== text) domNode.nodeValue = text;
2454
+ return domNode;
2455
+ }
2456
+ const next = globals.window.document.createTextNode(text);
2457
+ domNode.parentNode?.replaceChild(next, domNode);
2458
+ return next;
2459
+ }
2460
+ if (child && typeof child === "object") {
2461
+ const newType = typeof child.type === "string" ? child.type : null;
2462
+ if (!newType) return domNode;
2463
+ if (domNode.nodeType !== Node.ELEMENT_NODE) {
2464
+ const created = createDomFromChild(child, globals);
2465
+ const first = Array.isArray(created) ? created[0] : created;
2466
+ if (!first) return null;
2467
+ domNode.parentNode?.replaceChild(first, domNode);
2468
+ handleLifecycleEventsForOnMount(first);
2469
+ return first;
2470
+ }
2471
+ const el = domNode;
2472
+ const oldTag = el.tagName.toLowerCase();
2473
+ const newTag = newType.toLowerCase();
2474
+ if (oldTag !== newTag) {
2475
+ const created = createDomFromChild(child, globals);
2476
+ const first = Array.isArray(created) ? created[0] : created;
2477
+ if (!first) return null;
2478
+ el.parentNode?.replaceChild(first, el);
2479
+ handleLifecycleEventsForOnMount(first);
2480
+ return first;
2481
+ }
2482
+ patchElementInPlace(el, child, globals);
2483
+ return el;
2484
+ }
2485
+ domNode.parentNode?.removeChild(domNode);
2486
+ return null;
2487
+ }
2488
+ function updateDomWithVdom(parentElement, newVDOM, globals) {
2489
+ const el = parentElement;
2490
+ const isCustomElement = el.tagName.includes("-");
2491
+ const targetRoot = el.shadowRoot && !isCustomElement ? el.shadowRoot : parentElement;
2492
+ const nextChildren = normalizeChildren(newVDOM);
2493
+ const existing = Array.from(targetRoot.childNodes);
2494
+ const keyedPool = /* @__PURE__ */ new Map();
2495
+ const nodeKeys = /* @__PURE__ */ new WeakMap();
2496
+ const unkeyedPool = [];
2497
+ for (const node of existing) {
2498
+ const keys = getDomMatchKeys(node);
2499
+ if (keys.length > 0) {
2500
+ nodeKeys.set(node, keys);
2501
+ for (const k of keys) {
2502
+ if (!keyedPool.has(k)) keyedPool.set(k, node);
2503
+ }
2504
+ } else {
2505
+ unkeyedPool.push(node);
2506
+ }
2507
+ }
2508
+ const consumeKeyedNode = (node) => {
2509
+ const keys = nodeKeys.get(node) ?? [];
2510
+ for (const k of keys) keyedPool.delete(k);
2511
+ };
2512
+ const takeUnkeyedMatch = (child) => {
2513
+ for (let i = 0; i < unkeyedPool.length; i++) {
2514
+ const candidate = unkeyedPool[i];
2515
+ if (areNodeAndChildMatching(candidate, child)) {
2516
+ unkeyedPool.splice(i, 1);
2517
+ return candidate;
2518
+ }
2519
+ }
2520
+ return void 0;
2521
+ };
2522
+ let domIndex = 0;
2523
+ for (const child of nextChildren) {
2524
+ const key = getVNodeMatchKey(child);
2525
+ let match;
2526
+ if (key) {
2527
+ match = keyedPool.get(key);
2528
+ if (match) consumeKeyedNode(match);
2529
+ } else {
2530
+ match = takeUnkeyedMatch(child);
2531
+ }
2532
+ const anchor = targetRoot.childNodes[domIndex] ?? null;
2533
+ if (match) {
2534
+ if (match !== anchor) {
2535
+ targetRoot.insertBefore(match, anchor);
2536
+ }
2537
+ morphNode(match, child, globals);
2538
+ domIndex++;
2539
+ continue;
2540
+ }
2541
+ const created = createDomFromChild(child, globals);
2542
+ if (!created || Array.isArray(created) && created.length === 0) continue;
2543
+ const nodes = Array.isArray(created) ? created : [created];
2544
+ for (const node of nodes) {
2545
+ targetRoot.insertBefore(node, anchor);
2546
+ handleLifecycleEventsForOnMount(node);
2547
+ domIndex++;
2548
+ }
2549
+ }
2550
+ const remaining = /* @__PURE__ */ new Set();
2551
+ for (const node of unkeyedPool) remaining.add(node);
2552
+ for (const node of keyedPool.values()) remaining.add(node);
2553
+ for (const node of remaining) {
2554
+ if (node.parentNode === targetRoot) {
2555
+ if (node instanceof HTMLElement) {
2556
+ clearDelegatedEventsDeep(node);
2557
+ }
2558
+ targetRoot.removeChild(node);
2559
+ }
2560
+ }
2561
+ }
2562
+ function replaceDomWithVdom(parentElement, newVDOM, globals) {
2563
+ while (parentElement.firstChild) {
2564
+ parentElement.removeChild(parentElement.firstChild);
2565
+ }
2566
+ const renderer = getRenderer(globals.window.document);
2567
+ const newDom = renderer.createElementOrElements(
2568
+ newVDOM
2569
+ );
2570
+ if (Array.isArray(newDom)) {
2571
+ for (const node of newDom) {
2572
+ if (node) {
2573
+ parentElement.appendChild(node);
2574
+ handleLifecycleEventsForOnMount(node);
2575
+ }
2576
+ }
2577
+ } else if (newDom) {
2578
+ parentElement.appendChild(newDom);
2579
+ handleLifecycleEventsForOnMount(newDom);
2580
+ }
2581
+ }
2582
+ async function waitForDOM(check, timeout, document) {
2583
+ const initialResult = check();
2584
+ if (initialResult.length) return initialResult;
2585
+ return defussRuntime.createTimeoutPromise(timeout, () => {
2586
+ return new Promise((resolve) => {
2587
+ if (!document) {
2588
+ setTimeout(() => resolve(check()), 0);
2589
+ return;
2590
+ }
2591
+ const observer = new MutationObserver(() => {
2592
+ const result = check();
2593
+ if (result.length) {
2594
+ observer.disconnect();
2595
+ resolve(result);
2596
+ }
2597
+ });
2598
+ observer.observe(document.documentElement, {
2599
+ childList: true,
2600
+ subtree: true,
2601
+ attributes: true
2602
+ });
2603
+ return () => observer.disconnect();
2604
+ });
2605
+ });
2606
+ }
2607
+ function parseDOM(input, type, Parser) {
2608
+ return new Parser().parseFromString(input, type);
2609
+ }
2610
+ function isSVG(input, Parser) {
2611
+ const doc = parseDOM(input, "image/svg+xml", Parser);
2612
+ if (!doc.documentElement) return false;
2613
+ return doc.documentElement.nodeName.toLowerCase() === "svg";
2614
+ }
2615
+ function isHTML(input, Parser) {
2616
+ const doc = parseDOM(input, "text/html", Parser);
2617
+ return doc.documentElement.querySelectorAll("*").length > 2;
2618
+ }
2619
+ const isMarkup = (input, Parser) => input.indexOf("<") > -1 && input.indexOf(">") > -1 && (isHTML(input, Parser) || isSVG(input, Parser));
2620
+ function renderMarkup(markup, Parser, doc) {
2621
+ return Array.from(
2622
+ (doc ? doc : parseDOM(markup, getMimeType(markup, Parser), Parser)).body.childNodes
2623
+ );
2624
+ }
2625
+ function getMimeType(input, Parser) {
2626
+ if (isSVG(input, Parser)) {
2627
+ return "image/svg+xml";
2628
+ }
2629
+ return "text/html";
2630
+ }
2631
+ function processAllFormElements(node, callback) {
2632
+ if (node instanceof Element) {
2633
+ if (node instanceof HTMLFormElement) {
2634
+ Array.from(node.elements).forEach((element) => {
2635
+ if (element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) {
2636
+ const key = element.name || element.id;
2637
+ if (key) {
2638
+ callback(element, key);
2639
+ }
2640
+ }
2641
+ });
2642
+ } else {
2643
+ const inputElements = node.querySelectorAll("input, select, textarea");
2644
+ inputElements.forEach((element) => {
2645
+ if (element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) {
2646
+ const key = element.name || element.id;
2647
+ if (key) {
2648
+ callback(element, key);
2649
+ }
2650
+ }
2651
+ });
2652
+ }
2653
+ }
2654
+ }
2655
+ function checkElementVisibility(element, window, document) {
2656
+ const style = window.getComputedStyle(element);
2657
+ if (!style) return false;
2658
+ if (element.offsetWidth === 0 || element.offsetHeight === 0) return false;
2659
+ if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" || Number.parseFloat(style.opacity) === 0)
2660
+ return false;
2661
+ if (!document.body.contains(element)) return false;
2662
+ let parent = element.parentElement;
2663
+ while (parent) {
2664
+ const parentStyle = window.getComputedStyle(parent);
2665
+ if (parentStyle && (parentStyle.display === "none" || parentStyle.visibility === "hidden" || parentStyle.opacity === "0" || Number.parseFloat(parentStyle.opacity) === 0)) {
2666
+ return false;
2667
+ }
2668
+ parent = parent.parentElement;
2669
+ }
2670
+ return true;
2671
+ }
2672
+ function getEventMap(element) {
2673
+ if (!element._dequeryEvents) {
2674
+ element._dequeryEvents = /* @__PURE__ */ new Map();
2675
+ }
2676
+ return element._dequeryEvents;
2677
+ }
2678
+ function addElementEvent(element, eventType, handler) {
2679
+ registerDelegatedEvent(element, eventType, handler, { multi: true });
2680
+ }
2681
+ function removeElementEvent(element, eventType, handler) {
2682
+ removeDelegatedEvent(element, eventType, handler);
2683
+ }
2684
+ function clearElementEvents(element) {
2685
+ clearDelegatedEvents(element);
2686
+ }
2687
+ function domNodeToVNode(node) {
2688
+ if (node.nodeType === Node.TEXT_NODE) {
2689
+ return node.textContent || "";
2690
+ }
2691
+ if (node.nodeType === Node.ELEMENT_NODE) {
2692
+ const element = node;
2693
+ const attributes = {};
2694
+ for (let i = 0; i < element.attributes.length; i++) {
2695
+ const attr = element.attributes[i];
2696
+ attributes[attr.name] = attr.value;
2697
+ }
2698
+ const children = [];
2699
+ for (let i = 0; i < element.childNodes.length; i++) {
2700
+ const childVNode = domNodeToVNode(element.childNodes[i]);
2701
+ children.push(childVNode);
2702
+ }
2703
+ return {
2704
+ type: element.tagName.toLowerCase(),
2705
+ attributes,
2706
+ children
2707
+ };
2708
+ }
2709
+ return "";
2710
+ }
2711
+ function htmlStringToVNodes(html, Parser) {
2712
+ const parser = new Parser();
2713
+ const doc = parser.parseFromString(html, "text/html");
2714
+ const vNodes = [];
2715
+ for (let i = 0; i < doc.body.childNodes.length; i++) {
2716
+ const vnode = domNodeToVNode(doc.body.childNodes[i]);
2717
+ if (vnode !== "") {
2718
+ vNodes.push(vnode);
2719
+ }
2720
+ }
2721
+ return vNodes;
2722
+ }
2723
+
2724
+ exports.$ = $;
2725
+ exports.CAPTURE_ONLY_EVENTS = CAPTURE_ONLY_EVENTS;
2726
+ exports.CLASS_ATTRIBUTE_NAME = CLASS_ATTRIBUTE_NAME;
2727
+ exports.Call = Call;
2728
+ exports.CallChainImpl = CallChainImpl;
2729
+ exports.CallChainImplThenable = CallChainImplThenable;
2730
+ exports.DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE = DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE;
2731
+ exports.DEFAULT_TRANSITION_CONFIG = DEFAULT_TRANSITION_CONFIG;
2732
+ exports.Fragment = Fragment;
2733
+ exports.REF_ATTRIBUTE_NAME = REF_ATTRIBUTE_NAME;
2734
+ exports.XLINK_ATTRIBUTE_NAME = XLINK_ATTRIBUTE_NAME;
2735
+ exports.XMLNS_ATTRIBUTE_NAME = XMLNS_ATTRIBUTE_NAME;
2736
+ exports.addElementEvent = addElementEvent;
2737
+ exports.addNonChainedReturnCallNames = addNonChainedReturnCallNames;
2738
+ exports.applyStyles = applyStyles;
2739
+ exports.areDomNodesEqual = areDomNodesEqual;
2740
+ exports.checkElementVisibility = checkElementVisibility;
2741
+ exports.clearDelegatedEvents = clearDelegatedEvents;
2742
+ exports.clearDelegatedEventsDeep = clearDelegatedEventsDeep;
2743
+ exports.clearElementEvents = clearElementEvents;
2744
+ exports.createCall = createCall;
2745
+ exports.createGetterSetterCall = createGetterSetterCall;
2746
+ exports.createInPlaceErrorMessageVNode = createInPlaceErrorMessageVNode;
2747
+ exports.createRef = createRef;
2748
+ exports.createStore = createStore;
2749
+ exports.createSubChain = createSubChain;
2750
+ exports.deepEquals = deepEquals;
2751
+ exports.delayedAutoStart = delayedAutoStart;
2752
+ exports.dequery = dequery;
2753
+ exports.domNodeToVNode = domNodeToVNode;
2754
+ exports.emptyImpl = emptyImpl;
2755
+ exports.getAllFormValues = getAllFormValues;
2756
+ exports.getComponentInstance = getComponentInstance;
2757
+ exports.getDefaultDequeryOptions = getDefaultDequeryOptions;
2758
+ exports.getEventMap = getEventMap;
2759
+ exports.getMimeType = getMimeType;
2760
+ exports.getNonChainedReturnCallNames = getNonChainedReturnCallNames;
2761
+ exports.getRegisteredEventKeys = getRegisteredEventKeys;
2762
+ exports.getRegisteredEventTypes = getRegisteredEventTypes;
2763
+ exports.getRenderer = getRenderer;
2764
+ exports.getTransitionStyles = getTransitionStyles;
2765
+ exports.globalScopeDomApis = globalScopeDomApis;
2766
+ exports.handleLifecycleEventsForOnMount = handleLifecycleEventsForOnMount;
2767
+ exports.htmlStringToVNodes = htmlStringToVNodes;
2768
+ exports.isComponentRoot = isComponentRoot;
2769
+ exports.isDequery = isDequery;
2770
+ exports.isDequeryOptionsObject = isDequeryOptionsObject;
2771
+ exports.isHTML = isHTML;
2772
+ exports.isJSX = isJSX;
2773
+ exports.isMarkup = isMarkup;
2774
+ exports.isNonChainedReturnCall = isNonChainedReturnCall;
2775
+ exports.isRef = isRef;
2776
+ exports.isSVG = isSVG;
2777
+ exports.isServer = isServer;
2778
+ exports.jsx = jsx;
2779
+ exports.jsxDEV = jsxDEV;
2780
+ exports.jsxs = jsxs;
2781
+ exports.mapArrayIndexAccess = mapArrayIndexAccess;
2782
+ exports.observeUnmount = observeUnmount;
2783
+ exports.parseDOM = parseDOM;
2784
+ exports.parseEventPropName = parseEventPropName;
2785
+ exports.performTransition = performTransition;
2786
+ exports.processAllFormElements = processAllFormElements;
2787
+ exports.queueCallback = queueCallback;
2788
+ exports.registerComponent = registerComponent;
2789
+ exports.registerDelegatedEvent = registerDelegatedEvent;
2790
+ exports.removeDelegatedEvent = removeDelegatedEvent;
2791
+ exports.removeDelegatedEventByKey = removeDelegatedEventByKey;
2792
+ exports.removeElementEvent = removeElementEvent;
2793
+ exports.render = render;
2794
+ exports.renderInto = renderInto;
2795
+ exports.renderIsomorphicAsync = renderIsomorphicAsync;
2796
+ exports.renderIsomorphicSync = renderIsomorphicSync;
2797
+ exports.renderMarkup = renderMarkup;
2798
+ exports.renderNode = renderNode;
2799
+ exports.replaceDomWithVdom = replaceDomWithVdom;
2800
+ exports.resolveNodes = resolveNodes;
2801
+ exports.runWithTimeGuard = runWithTimeGuard;
2802
+ exports.scrollHelper = scrollHelper;
2803
+ exports.shallowEquals = shallowEquals;
2804
+ exports.subChainForNextAwait = subChainForNextAwait;
2805
+ exports.traverse = traverse;
2806
+ exports.unregisterComponent = unregisterComponent;
2807
+ exports.updateDom = updateDom;
2808
+ exports.updateDomWithVdom = updateDomWithVdom;
2809
+ exports.waitForDOM = waitForDOM;
2810
+ exports.webstorage = webstorage;