defuss 2.0.17 → 2.1.1

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 (154) hide show
  1. package/dist/dom-051FL7DA.cjs +2499 -0
  2. package/dist/dom-2urZevPa.cjs +2604 -0
  3. package/dist/dom-3Q6GgiEP.cjs +2386 -0
  4. package/dist/dom-7TUAWNZF.mjs +2620 -0
  5. package/dist/dom-9gOgXC15.mjs +2530 -0
  6. package/dist/dom-Ac1HaELT.cjs +2383 -0
  7. package/dist/dom-B0JKQVLo.mjs +2159 -0
  8. package/dist/dom-B1A7C07a.cjs +2278 -0
  9. package/dist/dom-B35D5snD.cjs +2565 -0
  10. package/dist/dom-B3H4AWT8.cjs +2560 -0
  11. package/dist/dom-B4SRsxUl.cjs +2560 -0
  12. package/dist/dom-B6LaR9hr.mjs +2479 -0
  13. package/dist/dom-B8Nu6WeP.cjs +2278 -0
  14. package/dist/dom-B9S2ESUN.mjs +2496 -0
  15. package/dist/dom-BBt7XE-h.mjs +2634 -0
  16. package/dist/dom-BCQkRmTA.mjs +2480 -0
  17. package/dist/dom-BEht0Cox.mjs +2428 -0
  18. package/dist/dom-BIbibRMj.mjs +2680 -0
  19. package/dist/dom-BIjjeDUU.mjs +2216 -0
  20. package/dist/dom-BNGg_cbb.mjs +2491 -0
  21. package/dist/dom-BOSr7iWk.cjs +2706 -0
  22. package/dist/dom-BQR3Ktxk.mjs +2479 -0
  23. package/dist/dom-BRy0f7HK.cjs +2714 -0
  24. package/dist/dom-BZFXy5pV.cjs +2703 -0
  25. package/dist/dom-B_e7yDzd.cjs +2928 -0
  26. package/dist/dom-B_lCwk1Q.mjs +2315 -0
  27. package/dist/dom-Baq533m0.mjs +2857 -0
  28. package/dist/dom-BcaFBnxf.mjs +2208 -0
  29. package/dist/dom-BfByzUuR.cjs +2159 -0
  30. package/dist/dom-BgRqSIRj.mjs +2517 -0
  31. package/dist/dom-Bm2vH_qI.mjs +2431 -0
  32. package/dist/dom-BpYh7n5K.cjs +2562 -0
  33. package/dist/dom-BwxduwV-.mjs +2097 -0
  34. package/dist/dom-BxFiaTgP.mjs +2169 -0
  35. package/dist/dom-BycLWyql.mjs +2564 -0
  36. package/dist/dom-ByuC2gIO.cjs +2598 -0
  37. package/dist/dom-C0Md-XPg.cjs +2553 -0
  38. package/dist/dom-C274_6Go.cjs +2556 -0
  39. package/dist/dom-C95ue10z.cjs +2274 -0
  40. package/dist/dom-CEXwGUHT.mjs +2175 -0
  41. package/dist/dom-CKDuv_GB.cjs +2700 -0
  42. package/dist/dom-CRmy0cD5.cjs +2274 -0
  43. package/dist/dom-CX9zlNhe.mjs +2492 -0
  44. package/dist/dom-CbnDrfq8.mjs +2491 -0
  45. package/dist/dom-Cg8xF9s2.mjs +2634 -0
  46. package/dist/dom-Cgi1LYfG.mjs +2626 -0
  47. package/dist/dom-CiUM5iRV.mjs +2208 -0
  48. package/dist/dom-Cj-ITpFq.mjs +2312 -0
  49. package/dist/dom-Cka7SFtU.mjs +2486 -0
  50. package/dist/dom-Cl4KLBe2.mjs +2212 -0
  51. package/dist/dom-Co9qKYKH.mjs +2208 -0
  52. package/dist/dom-CqXRRKMq.cjs +2502 -0
  53. package/dist/dom-Cvxyn1jX.cjs +2751 -0
  54. package/dist/dom-CwVNwwYO.mjs +2622 -0
  55. package/dist/dom-D1h0E-Gl.cjs +2276 -0
  56. package/dist/dom-D1tJ6iHK.mjs +2208 -0
  57. package/dist/dom-D3B4oBiG.cjs +2560 -0
  58. package/dist/dom-D3kiX0Hd.mjs +2240 -0
  59. package/dist/dom-D6Z2Nh2a.cjs +2658 -0
  60. package/dist/dom-D88_i9KL.cjs +2758 -0
  61. package/dist/dom-D98Bwft7.mjs +2674 -0
  62. package/dist/dom-DDUT5VJn.cjs +2308 -0
  63. package/dist/dom-DEyxBtEp.cjs +2386 -0
  64. package/dist/dom-DFRuG-Zh.cjs +2243 -0
  65. package/dist/dom-DG8glurk.cjs +2235 -0
  66. package/dist/dom-DHoO2wC0.cjs +2554 -0
  67. package/dist/dom-DK9OsuHY.cjs +2281 -0
  68. package/dist/dom-DLelllDB.mjs +2479 -0
  69. package/dist/dom-DM9F1UXd.cjs +2755 -0
  70. package/dist/dom-DPcA3iwZ.mjs +2315 -0
  71. package/dist/dom-DSrDBeAh.cjs +2383 -0
  72. package/dist/dom-DTqN1pTP.mjs +2215 -0
  73. package/dist/dom-DWF-s1Su.cjs +2560 -0
  74. package/dist/dom-DXqKDT61.mjs +2636 -0
  75. package/dist/dom-DZaG_1dy.cjs +2523 -0
  76. package/dist/dom-Da94we67.mjs +2482 -0
  77. package/dist/dom-Db4PHLSs.cjs +2282 -0
  78. package/dist/dom-DbLKf6Jh.mjs +2452 -0
  79. package/dist/dom-DcxhioDc.mjs +2312 -0
  80. package/dist/dom-Dd4Xeoid.cjs +2225 -0
  81. package/dist/dom-DdmtiIFy.mjs +2240 -0
  82. package/dist/dom-DeobYYW6.cjs +2565 -0
  83. package/dist/dom-DfOG-SOC.mjs +2524 -0
  84. package/dist/dom-DfoXi_Ge.mjs +2491 -0
  85. package/dist/dom-DgH5XaDf.cjs +2566 -0
  86. package/dist/dom-Dh6j0hU3.cjs +2216 -0
  87. package/dist/dom-DoY3LzGN.cjs +2716 -0
  88. package/dist/dom-DrkvmJc0.mjs +2604 -0
  89. package/dist/dom-DtoQzVf_.mjs +2420 -0
  90. package/dist/dom-DuPDCLQ6.cjs +2274 -0
  91. package/dist/dom-Dv7NYXDp.cjs +2278 -0
  92. package/dist/dom-DxgDiOaA.cjs +2565 -0
  93. package/dist/dom-G04drjmU.cjs +2491 -0
  94. package/dist/dom-H0GABHXb.mjs +2150 -0
  95. package/dist/dom-JCkS89Rd.cjs +2567 -0
  96. package/dist/dom-KqUQZkfM.cjs +2308 -0
  97. package/dist/dom-TFwB-0L9.cjs +2678 -0
  98. package/dist/dom-TZFkL5KJ.cjs +2644 -0
  99. package/dist/dom-TouShoro.mjs +2177 -0
  100. package/dist/dom-VETbfxjz.mjs +2677 -0
  101. package/dist/dom-Vsf53vAt.mjs +2488 -0
  102. package/dist/dom-XAoDKik2.cjs +2241 -0
  103. package/dist/dom-YFfM2w3z.mjs +2041 -0
  104. package/dist/dom-_tAEgP75.mjs +2578 -0
  105. package/dist/dom-aBdjDw0s.cjs +2308 -0
  106. package/dist/dom-aW_a5G16.mjs +2240 -0
  107. package/dist/dom-fZQn7O9l.cjs +2278 -0
  108. package/dist/dom-gRbdIyyK.cjs +2604 -0
  109. package/dist/dom-nqHAD9D_.mjs +2212 -0
  110. package/dist/dom-qpb9kPPR.mjs +2212 -0
  111. package/dist/dom-rGg1mmtQ.cjs +2103 -0
  112. package/dist/dom-unkLyMam.mjs +2486 -0
  113. package/dist/dom-vZS7gOVB.cjs +2714 -0
  114. package/dist/dom-wNstqp5x.mjs +2212 -0
  115. package/dist/index-2LUk-rix.d.ts +1509 -0
  116. package/dist/index-5Ez8v0Mw.d.ts +1568 -0
  117. package/dist/index-B8ImEI1u.d.ts +1509 -0
  118. package/dist/index-BBk97lC7.d.ts +1465 -0
  119. package/dist/index-BTOeLZBB.d.ts +1527 -0
  120. package/dist/index-BTaR1jax.d.ts +1509 -0
  121. package/dist/index-Bae31vFS.d.ts +1570 -0
  122. package/dist/index-Bb1GxtDc.d.ts +1472 -0
  123. package/dist/index-Bfz7852w.d.ts +1567 -0
  124. package/dist/index-Bywe1fkx.d.ts +1509 -0
  125. package/dist/index-CCeeNIcc.d.ts +1496 -0
  126. package/dist/index-C_P6zlvR.d.ts +1558 -0
  127. package/dist/index-DBvUJqwo.d.ts +1509 -0
  128. package/dist/index-DPVHaQn9.d.ts +1521 -0
  129. package/dist/index-DbR8em5t.d.ts +1497 -0
  130. package/dist/index-Dhjx6sE5.d.ts +1570 -0
  131. package/dist/index-Dzgvlh_Y.d.ts +1509 -0
  132. package/dist/index-Fi1RplM1.d.ts +1496 -0
  133. package/dist/index-ep2QX2G6.d.ts +1579 -0
  134. package/dist/index-gq002HdC.d.ts +1568 -0
  135. package/dist/index-u-BP7aQx.d.ts +1553 -0
  136. package/dist/index.cjs +50 -8
  137. package/dist/index.d.cts +8 -4
  138. package/dist/index.d.ts +8 -4
  139. package/dist/index.mjs +47 -9
  140. package/dist/render/client.cjs +6 -4
  141. package/dist/render/client.d.cts +2 -2
  142. package/dist/render/client.d.ts +2 -2
  143. package/dist/render/client.mjs +3 -5
  144. package/dist/render/index.cjs +5 -1
  145. package/dist/render/index.d.cts +1 -1
  146. package/dist/render/index.d.ts +1 -1
  147. package/dist/render/index.mjs +1 -1
  148. package/dist/render/server.cjs +5 -1
  149. package/dist/render/server.d.cts +2 -2
  150. package/dist/render/server.d.ts +2 -2
  151. package/dist/render/server.mjs +2 -2
  152. package/dist/transitions-BTnlvkEd.mjs +102 -0
  153. package/dist/transitions-D6dj9XXM.cjs +109 -0
  154. package/package.json +2 -2
@@ -0,0 +1,2482 @@
1
+ import { pick, omit, createTimeoutPromise, waitForRef, setByPath, getByPath } from 'defuss-runtime';
2
+
3
+ class Call {
4
+ name;
5
+ fn;
6
+ args;
7
+ constructor(name, fn, ...args) {
8
+ this.name = name;
9
+ this.fn = fn;
10
+ this.args = args;
11
+ }
12
+ }
13
+ const globalRegistry = globalThis;
14
+ if (!globalRegistry.__defuss_nonChainedReturnCallNames) {
15
+ globalRegistry.__defuss_nonChainedReturnCallNames = [
16
+ "getFirstElement",
17
+ "toArray",
18
+ "map",
19
+ "isHidden",
20
+ "isVisible",
21
+ "hasClass",
22
+ "dimension",
23
+ "position",
24
+ "offset",
25
+ "prop",
26
+ "val",
27
+ "form",
28
+ "attr",
29
+ "data",
30
+ "css",
31
+ "html",
32
+ "serialize"
33
+ ];
34
+ }
35
+ function addNonChainedReturnCallNames(callNames) {
36
+ const global = globalRegistry.__defuss_nonChainedReturnCallNames;
37
+ callNames.forEach((name) => {
38
+ if (!global.includes(name)) {
39
+ global.push(name);
40
+ }
41
+ });
42
+ }
43
+ function getNonChainedReturnCallNames() {
44
+ return [...globalRegistry.__defuss_nonChainedReturnCallNames];
45
+ }
46
+ function isNonChainedReturnCall(callName) {
47
+ return globalRegistry.__defuss_nonChainedReturnCallNames.includes(callName);
48
+ }
49
+ const emptyImpl = (nodes) => {
50
+ nodes.forEach((el) => {
51
+ const element = el;
52
+ while (element.firstChild) {
53
+ element.firstChild.remove();
54
+ }
55
+ });
56
+ return nodes;
57
+ };
58
+ class CallChainImpl {
59
+ isResolved;
60
+ options;
61
+ elementCreationOptions;
62
+ callStack;
63
+ resultStack;
64
+ stackPointer;
65
+ lastResolvedStackPointer;
66
+ stoppedWithError;
67
+ lastResult;
68
+ length;
69
+ chainStartTime;
70
+ chainAsyncStartTime;
71
+ chainAsyncFinishTime;
72
+ // SSR-ability
73
+ document;
74
+ window;
75
+ performance;
76
+ Parser;
77
+ constructor(options = {}) {
78
+ this.options = {
79
+ ...getDefaultDequeryOptions(),
80
+ ...options
81
+ };
82
+ const optionsKeys = Object.keys(getDefaultDequeryOptions());
83
+ this.options = pick(this.options, optionsKeys);
84
+ this.window = this.options.globals.window;
85
+ this.document = this.options.globals.window.document;
86
+ this.performance = this.options.globals.performance;
87
+ this.Parser = this.options.globals.window.DOMParser;
88
+ const elementCreationOptions = omit(
89
+ options,
90
+ optionsKeys
91
+ );
92
+ this.elementCreationOptions = elementCreationOptions;
93
+ this.callStack = [];
94
+ this.resultStack = options.resultStack ? [options.resultStack] : [];
95
+ this.stackPointer = 0;
96
+ this.lastResolvedStackPointer = 0;
97
+ this.stoppedWithError = null;
98
+ this.lastResult = [];
99
+ this.length = 0;
100
+ this.isResolved = false;
101
+ this.chainStartTime = this.performance.now() ?? 0;
102
+ this.chainAsyncStartTime = 0;
103
+ this.chainAsyncFinishTime = 0;
104
+ }
105
+ get globals() {
106
+ return this.options.globals;
107
+ }
108
+ // sync methods
109
+ // currently selected nodes
110
+ get nodes() {
111
+ return this.resultStack.length > 0 ? this.resultStack[this.resultStack.length - 1] : [];
112
+ }
113
+ // allow for for .. of loop
114
+ [Symbol.iterator]() {
115
+ return this.nodes[Symbol.iterator]();
116
+ }
117
+ // async, direct result method
118
+ getFirstElement() {
119
+ return createCall(
120
+ this,
121
+ "getFirstElement",
122
+ async () => this[0]
123
+ );
124
+ }
125
+ // async, wrapped/chainable API methods
126
+ debug(cb) {
127
+ return createCall(this, "debug", async () => {
128
+ cb(this);
129
+ return this.nodes;
130
+ });
131
+ }
132
+ ref(ref) {
133
+ return createCall(this, "ref", async () => {
134
+ await waitForRef(ref, this.options.timeout);
135
+ if (ref.current) {
136
+ return [ref.current];
137
+ } else {
138
+ throw new Error("Ref is null or undefined");
139
+ }
140
+ });
141
+ }
142
+ query(selector) {
143
+ return createCall(this, "query", async () => {
144
+ return Array.from(
145
+ await waitForDOM(
146
+ () => Array.from(this.document.querySelectorAll(selector) || []),
147
+ this.options.timeout,
148
+ this.document
149
+ )
150
+ );
151
+ });
152
+ }
153
+ next() {
154
+ return traverse(this, "next", (el) => el.nextElementSibling);
155
+ }
156
+ prev() {
157
+ return traverse(this, "prev", (el) => el.previousElementSibling);
158
+ }
159
+ find(selector) {
160
+ return createCall(this, "find", async () => {
161
+ const results = await Promise.all(
162
+ this.nodes.map(async (el) => {
163
+ return await waitForDOM(
164
+ () => Array.from(el.querySelectorAll(selector)),
165
+ this.options.timeout,
166
+ this.document
167
+ );
168
+ })
169
+ );
170
+ return results.flat();
171
+ });
172
+ }
173
+ parent() {
174
+ return traverse(this, "parent", (el) => el.parentElement);
175
+ }
176
+ children() {
177
+ return traverse(this, "children", (el) => Array.from(el.children));
178
+ }
179
+ closest(selector) {
180
+ return traverse(this, "closest", (el) => el.closest(selector));
181
+ }
182
+ first() {
183
+ return createCall(this, "first", async () => {
184
+ return this.nodes.slice(0, 1);
185
+ });
186
+ }
187
+ last() {
188
+ return createCall(this, "last", async () => {
189
+ return this.nodes.slice(-1);
190
+ });
191
+ }
192
+ attr(name, value) {
193
+ return createGetterSetterCall(
194
+ this,
195
+ "attr",
196
+ value,
197
+ // Getter function
198
+ () => {
199
+ if (this.nodes.length === 0) return null;
200
+ return this.nodes[0].getAttribute(name);
201
+ },
202
+ // Setter function
203
+ (val) => {
204
+ this.nodes.forEach((el) => el.setAttribute(name, val));
205
+ }
206
+ );
207
+ }
208
+ prop(name, value) {
209
+ return createGetterSetterCall(
210
+ this,
211
+ "prop",
212
+ value,
213
+ // Getter function
214
+ () => {
215
+ if (this.nodes.length === 0) return void 0;
216
+ return this.nodes[0][name];
217
+ },
218
+ // Setter function
219
+ (val) => {
220
+ this.nodes.forEach((el) => {
221
+ el[name] = val;
222
+ });
223
+ }
224
+ );
225
+ }
226
+ // --- CSS & Class Methods ---
227
+ static resultCache = /* @__PURE__ */ new WeakMap();
228
+ css(prop, value) {
229
+ if (typeof prop === "object") {
230
+ return createCall(this, "css", async () => {
231
+ const elements = this.nodes;
232
+ elements.forEach((el) => {
233
+ const htmlEl = el;
234
+ Object.entries(prop).forEach(([key, val]) => {
235
+ htmlEl.style.setProperty(
236
+ key.replace(/([A-Z])/g, "-$1").toLowerCase(),
237
+ String(val)
238
+ );
239
+ });
240
+ });
241
+ return this.nodes;
242
+ });
243
+ }
244
+ return createGetterSetterCall(
245
+ this,
246
+ "css",
247
+ value,
248
+ // Getter with caching
249
+ () => {
250
+ if (this.nodes.length === 0) return "";
251
+ const el = this.nodes[0];
252
+ const cache = CallChainImpl.resultCache.get(el) || /* @__PURE__ */ new Map();
253
+ const cacheKey = `css:${prop}`;
254
+ if (cache.has(cacheKey)) {
255
+ return cache.get(cacheKey);
256
+ }
257
+ const result = el.style.getPropertyValue(prop);
258
+ cache.set(cacheKey, result);
259
+ CallChainImpl.resultCache.set(el, cache);
260
+ return result;
261
+ },
262
+ // Setter with cache invalidation
263
+ (val) => {
264
+ this.nodes.forEach((el) => {
265
+ el.style.setProperty(prop, String(val));
266
+ const cache = CallChainImpl.resultCache.get(el);
267
+ if (cache) {
268
+ cache.delete(`css:${prop}`);
269
+ }
270
+ });
271
+ }
272
+ );
273
+ }
274
+ addClass(name) {
275
+ return createCall(this, "addClass", async () => {
276
+ const list = Array.isArray(name) ? name : [name];
277
+ this.nodes.forEach((el) => el.classList.add(...list));
278
+ return this.nodes;
279
+ });
280
+ }
281
+ removeClass(name) {
282
+ return createCall(this, "removeClass", async () => {
283
+ const list = Array.isArray(name) ? name : [name];
284
+ this.nodes.forEach((el) => el.classList.remove(...list));
285
+ return this.nodes;
286
+ });
287
+ }
288
+ hasClass(name) {
289
+ return createCall(
290
+ this,
291
+ "hasClass",
292
+ async () => this.nodes.every(
293
+ (el) => el.classList.contains(name)
294
+ )
295
+ );
296
+ }
297
+ toggleClass(name) {
298
+ return createCall(this, "toggleClass", async () => {
299
+ this.nodes.forEach((el) => el.classList.toggle(name));
300
+ return this.nodes;
301
+ });
302
+ }
303
+ animateClass(name, duration) {
304
+ return createCall(this, "animateClass", async () => {
305
+ this.nodes.forEach((el) => {
306
+ const e = el;
307
+ e.classList.add(name);
308
+ setTimeout(() => e.classList.remove(name), duration);
309
+ });
310
+ return this.nodes;
311
+ });
312
+ }
313
+ // --- Content Manipulation Methods ---
314
+ empty() {
315
+ return createCall(
316
+ this,
317
+ "empty",
318
+ async () => emptyImpl(this.nodes)
319
+ );
320
+ }
321
+ html(html) {
322
+ return createGetterSetterCall(
323
+ this,
324
+ "html",
325
+ html,
326
+ () => {
327
+ if (this.nodes.length === 0) return "";
328
+ return this.nodes[0].innerHTML;
329
+ },
330
+ (val) => {
331
+ this.nodes.forEach((el) => {
332
+ el.innerHTML = val;
333
+ });
334
+ }
335
+ );
336
+ }
337
+ jsx(vdom) {
338
+ if (!isJSX(vdom)) {
339
+ throw new Error("Invalid JSX input");
340
+ }
341
+ return createCall(this, "jsx", async () => {
342
+ this.nodes.forEach(
343
+ (el) => updateDomWithVdom(el, vdom, globalThis)
344
+ );
345
+ return this.nodes;
346
+ });
347
+ }
348
+ text(text) {
349
+ return createGetterSetterCall(
350
+ this,
351
+ "text",
352
+ text,
353
+ // Getter function
354
+ () => {
355
+ if (this.nodes.length === 0) return "";
356
+ return this.nodes[0].textContent || "";
357
+ },
358
+ // Setter function
359
+ (val) => {
360
+ this.nodes.forEach((el) => {
361
+ el.textContent = val;
362
+ });
363
+ }
364
+ );
365
+ }
366
+ remove() {
367
+ return createCall(this, "remove", async () => {
368
+ const removedElements = [...this.nodes];
369
+ this.nodes.forEach((el) => el.remove());
370
+ return removedElements;
371
+ });
372
+ }
373
+ replaceWith(content) {
374
+ return createCall(this, "replaceWith", async () => {
375
+ const newElements = [];
376
+ const newElement = await renderNode(content, this);
377
+ for (const originalEl of this.nodes) {
378
+ if (!originalEl?.parentNode) continue;
379
+ if (!newElement) continue;
380
+ originalEl.parentNode.replaceChild(newElement, originalEl);
381
+ newElements.push(newElement);
382
+ }
383
+ this.resultStack[this.resultStack.length - 1] = newElements;
384
+ mapArrayIndexAccess(this, this);
385
+ return newElements;
386
+ });
387
+ }
388
+ append(content) {
389
+ return createCall(this, "append", async () => {
390
+ if (content == null) {
391
+ return this.nodes;
392
+ }
393
+ if (content instanceof Node) {
394
+ this.nodes.forEach((el) => {
395
+ if (el && content && !el.isEqualNode(content) && el.parentNode !== content) {
396
+ el.appendChild(content);
397
+ }
398
+ });
399
+ return this.nodes;
400
+ }
401
+ const element = await renderNode(content, this);
402
+ if (!element) return this.nodes;
403
+ if (isDequery(content)) {
404
+ this.nodes.forEach((el) => {
405
+ content.nodes.forEach((childEl) => {
406
+ if (childEl.nodeType && el.nodeType && !childEl.isEqualNode(el) && el.parentNode !== childEl) {
407
+ el.appendChild(childEl);
408
+ }
409
+ });
410
+ });
411
+ } else if (typeof content === "string" && isMarkup(content, this.Parser)) {
412
+ const elements = renderMarkup(content, this.Parser);
413
+ this.nodes.forEach((el) => {
414
+ elements.forEach(
415
+ (childEl) => el.appendChild(childEl.cloneNode(true))
416
+ );
417
+ });
418
+ } else {
419
+ this.nodes.forEach((el) => {
420
+ if (!element) return;
421
+ el.appendChild(element.cloneNode(true));
422
+ });
423
+ }
424
+ return this.nodes;
425
+ });
426
+ }
427
+ appendTo(target) {
428
+ return createCall(this, "appendTo", async () => {
429
+ const nodes = await resolveNodes(
430
+ target,
431
+ this.options.timeout,
432
+ this.document
433
+ );
434
+ if (nodes.length === 0) {
435
+ console.warn("appendTo: no target elements found");
436
+ return this.nodes;
437
+ }
438
+ nodes.forEach((node) => {
439
+ this.nodes.forEach((el) => {
440
+ if (!node || !el) return;
441
+ node.appendChild(el.cloneNode(true));
442
+ });
443
+ });
444
+ return this.nodes;
445
+ });
446
+ }
447
+ update(input, transitionConfig) {
448
+ return createCall(this, "update", async () => {
449
+ return await updateDom(
450
+ input,
451
+ this.nodes,
452
+ this.options.timeout,
453
+ this.Parser,
454
+ transitionConfig
455
+ );
456
+ });
457
+ }
458
+ // --- Event Methods ---
459
+ on(event, handler) {
460
+ return createCall(this, "on", async () => {
461
+ this.nodes.forEach((el) => {
462
+ addElementEvent(el, event, handler);
463
+ });
464
+ return this.nodes;
465
+ });
466
+ }
467
+ off(event, handler) {
468
+ return createCall(this, "off", async () => {
469
+ this.nodes.forEach((el) => {
470
+ removeElementEvent(el, event, handler);
471
+ });
472
+ return this.nodes;
473
+ });
474
+ }
475
+ clearEvents() {
476
+ return createCall(this, "clearEvents", async () => {
477
+ this.nodes.forEach((el) => {
478
+ clearElementEvents(el);
479
+ });
480
+ return this.nodes;
481
+ });
482
+ }
483
+ trigger(eventType) {
484
+ return createCall(this, "trigger", async () => {
485
+ this.nodes.forEach(
486
+ (el) => el.dispatchEvent(
487
+ new Event(eventType, { bubbles: true, cancelable: true })
488
+ )
489
+ );
490
+ return this.nodes;
491
+ });
492
+ }
493
+ // --- Position Methods ---
494
+ position() {
495
+ return createCall(
496
+ this,
497
+ "position",
498
+ async () => ({
499
+ top: this.nodes[0].offsetTop,
500
+ left: this.nodes[0].offsetLeft
501
+ })
502
+ );
503
+ }
504
+ offset() {
505
+ return createCall(this, "offset", async () => {
506
+ const el = this.nodes[0];
507
+ const rect = el.getBoundingClientRect();
508
+ return {
509
+ top: rect.top + window.scrollY,
510
+ left: rect.left + window.scrollX
511
+ };
512
+ });
513
+ }
514
+ // --- Data Methods ---
515
+ data(name, value) {
516
+ return createGetterSetterCall(
517
+ this,
518
+ "data",
519
+ value,
520
+ // Getter function
521
+ () => {
522
+ if (this.nodes.length === 0) return void 0;
523
+ return this.nodes[0].dataset[name];
524
+ },
525
+ // Setter function
526
+ (val) => {
527
+ this.nodes.forEach((el) => {
528
+ el.dataset[name] = val;
529
+ });
530
+ }
531
+ );
532
+ }
533
+ val(val) {
534
+ return createGetterSetterCall(
535
+ this,
536
+ "val",
537
+ val,
538
+ // Getter function
539
+ () => {
540
+ if (this.nodes.length === 0) return "";
541
+ const el = this.nodes[0];
542
+ if (el.type === "checkbox") {
543
+ return el.checked;
544
+ }
545
+ return el.value;
546
+ },
547
+ // Setter function
548
+ (value) => {
549
+ this.nodes.forEach((el) => {
550
+ const input = el;
551
+ if (input.type === "checkbox" && typeof value === "boolean") {
552
+ input.checked = value;
553
+ } else {
554
+ input.value = String(value);
555
+ }
556
+ });
557
+ }
558
+ );
559
+ }
560
+ serialize(format = "querystring") {
561
+ const mapValue = (value) => typeof value === "boolean" ? value ? "on" : "off" : value;
562
+ return createCall(this, "serialize", async () => {
563
+ const formData = getAllFormValues(this);
564
+ if (format === "json") {
565
+ return JSON.stringify(formData);
566
+ } else {
567
+ const urlSearchParams = new URLSearchParams();
568
+ const keys = Object.keys(formData);
569
+ keys.forEach((key) => {
570
+ const value = formData[key];
571
+ if (typeof value === "string") {
572
+ urlSearchParams.append(key, value);
573
+ } else if (typeof value === "boolean") {
574
+ urlSearchParams.append(key, mapValue(value));
575
+ } else if (Array.isArray(value)) {
576
+ value.forEach(
577
+ (value2) => urlSearchParams.append(key, mapValue(value2))
578
+ );
579
+ }
580
+ });
581
+ return urlSearchParams.toString();
582
+ }
583
+ });
584
+ }
585
+ form(formData) {
586
+ return createGetterSetterCall(
587
+ this,
588
+ "form",
589
+ formData,
590
+ // Getter function
591
+ () => getAllFormValues(this),
592
+ // Setter function
593
+ (values) => {
594
+ this.nodes.forEach((el) => {
595
+ processAllFormElements(el, (input, key) => {
596
+ if (values[key] !== void 0) {
597
+ if (input.type === "checkbox") {
598
+ input.checked = Boolean(values[key]);
599
+ } else {
600
+ input.value = String(values[key]);
601
+ }
602
+ }
603
+ });
604
+ });
605
+ }
606
+ );
607
+ }
608
+ // --- Dimension Methods ---
609
+ dimension(includeMarginOrPadding, includePaddingIfMarginTrue) {
610
+ return createCall(this, "dimension", async () => {
611
+ if (this.nodes.length === 0) {
612
+ return { width: 0, height: 0 };
613
+ }
614
+ const el = this.nodes[0];
615
+ const style = this.window.getComputedStyle(el);
616
+ if (!style) return { width: 0, height: 0 };
617
+ const rect = el.getBoundingClientRect();
618
+ let width = rect.width;
619
+ let height = rect.height;
620
+ let includeMargin = false;
621
+ let includePadding = true;
622
+ if (includePaddingIfMarginTrue !== void 0) {
623
+ includeMargin = !!includeMarginOrPadding;
624
+ includePadding = !!includePaddingIfMarginTrue;
625
+ } else if (includeMarginOrPadding !== void 0) {
626
+ includePadding = !!includeMarginOrPadding;
627
+ }
628
+ if (!includePadding) {
629
+ const paddingLeft = Number.parseFloat(style.paddingLeft) || 0;
630
+ const paddingRight = Number.parseFloat(style.paddingRight) || 0;
631
+ const paddingTop = Number.parseFloat(style.paddingTop) || 0;
632
+ const paddingBottom = Number.parseFloat(style.paddingBottom) || 0;
633
+ const borderLeft = Number.parseFloat(style.borderLeftWidth) || 0;
634
+ const borderRight = Number.parseFloat(style.borderRightWidth) || 0;
635
+ const borderTop = Number.parseFloat(style.borderTopWidth) || 0;
636
+ const borderBottom = Number.parseFloat(style.borderBottomWidth) || 0;
637
+ width -= paddingLeft + paddingRight + borderLeft + borderRight;
638
+ height -= paddingTop + paddingBottom + borderTop + borderBottom;
639
+ }
640
+ if (includeMargin) {
641
+ const marginLeft = Number.parseFloat(style.marginLeft) || 0;
642
+ const marginRight = Number.parseFloat(style.marginRight) || 0;
643
+ const marginTop = Number.parseFloat(style.marginTop) || 0;
644
+ const marginBottom = Number.parseFloat(style.marginBottom) || 0;
645
+ const baseWidthForOuter = includePadding ? rect.width : width;
646
+ const baseHeightForOuter = includePadding ? rect.height : height;
647
+ const outerWidth = baseWidthForOuter + marginLeft + marginRight;
648
+ const outerHeight = baseHeightForOuter + marginTop + marginBottom;
649
+ return {
650
+ width,
651
+ height,
652
+ outerWidth,
653
+ outerHeight
654
+ };
655
+ }
656
+ return {
657
+ width,
658
+ height
659
+ };
660
+ });
661
+ }
662
+ // --- Visibility Methods ---
663
+ isVisible() {
664
+ return createCall(this, "isVisible", async () => {
665
+ if (this.nodes.length === 0) return false;
666
+ const el = this.nodes[0];
667
+ return checkElementVisibility(el, this.window, this.document);
668
+ });
669
+ }
670
+ isHidden() {
671
+ return createCall(this, "isHidden", async () => {
672
+ if (this.nodes.length === 0) return true;
673
+ const el = this.nodes[0];
674
+ return !checkElementVisibility(el, this.window, this.document);
675
+ });
676
+ }
677
+ // --- Scrolling Methods ---
678
+ scrollTo(xOrOptions, y) {
679
+ return createCall(this, "scrollTo", async () => {
680
+ return scrollHelper("scrollTo", this.nodes, xOrOptions, y);
681
+ });
682
+ }
683
+ scrollBy(xOrOptions, y) {
684
+ return createCall(this, "scrollBy", async () => {
685
+ return scrollHelper("scrollBy", this.nodes, xOrOptions, y);
686
+ });
687
+ }
688
+ scrollIntoView(options) {
689
+ return createCall(this, "scrollIntoView", async () => {
690
+ if (this.nodes.length === 0) return this.nodes;
691
+ this.nodes[0].scrollIntoView(options);
692
+ return this.nodes;
693
+ });
694
+ }
695
+ // --- Transformation Methods ---
696
+ map(cb) {
697
+ return createCall(this, "map", async () => {
698
+ const elements = this.nodes;
699
+ const results = new Array(elements.length);
700
+ for (let i = 0; i < elements.length; i++) {
701
+ results[i] = cb(elements[i], i);
702
+ }
703
+ return results;
704
+ });
705
+ }
706
+ toArray() {
707
+ return createCall(
708
+ this,
709
+ "toArray",
710
+ async () => [...this.nodes]
711
+ );
712
+ }
713
+ filter(selector) {
714
+ return createCall(
715
+ this,
716
+ "filter",
717
+ async () => this.nodes.filter(
718
+ (el) => el instanceof Element && el.matches(selector)
719
+ )
720
+ );
721
+ }
722
+ // --- Cleanup Methods ---
723
+ /** memory cleanup (chain becomes useless after calling this method) */
724
+ dispose() {
725
+ return createCall(this, "dispose", async () => {
726
+ this.nodes.forEach((el) => {
727
+ CallChainImpl.resultCache.delete(el);
728
+ });
729
+ this.callStack.length = 0;
730
+ this.resultStack.length = 0;
731
+ this.stackPointer = 0;
732
+ this.lastResolvedStackPointer = 0;
733
+ return void 0;
734
+ });
735
+ }
736
+ ready(callback) {
737
+ return createCall(this, "ready", async () => {
738
+ if (this.document.readyState === "complete" || this.document.readyState === "interactive") {
739
+ if (callback) {
740
+ callback();
741
+ }
742
+ return this.nodes;
743
+ }
744
+ const nodes = this.nodes;
745
+ const document = this.document;
746
+ return new Promise((resolve) => {
747
+ const handleDOMContentLoaded = () => {
748
+ document.removeEventListener(
749
+ "DOMContentLoaded",
750
+ handleDOMContentLoaded
751
+ );
752
+ if (callback) {
753
+ callback();
754
+ }
755
+ resolve(nodes);
756
+ };
757
+ document.addEventListener("DOMContentLoaded", handleDOMContentLoaded);
758
+ });
759
+ });
760
+ }
761
+ // TODO:
762
+ // - deserialize (from URL string, JSON, etc.)
763
+ }
764
+ class CallChainImplThenable extends CallChainImpl {
765
+ constructor(options = {}, isResolved = false) {
766
+ super(options);
767
+ this.isResolved = isResolved;
768
+ }
769
+ // biome-ignore lint/suspicious/noThenProperty: <explanation>
770
+ then(onfulfilled, onrejected) {
771
+ this.chainAsyncStartTime = this.performance.now() ?? 0;
772
+ if (this.stoppedWithError) {
773
+ return Promise.reject(this.stoppedWithError).then(
774
+ onfulfilled,
775
+ onrejected
776
+ );
777
+ }
778
+ if (this.isResolved && this.stackPointer >= this.callStack.length) {
779
+ this.lastResolvedStackPointer = this.stackPointer;
780
+ const lastCallName = this.callStack[this.callStack.length - 1]?.name;
781
+ let result;
782
+ if (isNonChainedReturnCall(lastCallName)) {
783
+ result = this.lastResult;
784
+ } else {
785
+ result = createSubChain(this, CallChainImpl, true);
786
+ }
787
+ this.chainAsyncFinishTime = (this.performance.now() ?? 0) - this.chainAsyncStartTime;
788
+ return Promise.resolve(result).then(onfulfilled, onrejected);
789
+ }
790
+ return runWithTimeGuard(
791
+ this.options.timeout,
792
+ async () => {
793
+ const startTime = Date.now();
794
+ let call;
795
+ while (this.stackPointer < this.callStack.length) {
796
+ call = this.callStack[this.stackPointer];
797
+ if (Date.now() - startTime > this.options.timeout) {
798
+ throw new Error(`Timeout after ${this.options.timeout}ms`);
799
+ }
800
+ try {
801
+ const callReturnValue = await call.fn.apply(this);
802
+ this.lastResult = callReturnValue;
803
+ if (!isNonChainedReturnCall(call.name)) {
804
+ this.resultStack.push(callReturnValue);
805
+ }
806
+ if (Array.isArray(this.lastResult)) {
807
+ mapArrayIndexAccess(this, this);
808
+ }
809
+ this.stackPointer++;
810
+ } catch (err) {
811
+ this.stoppedWithError = err;
812
+ throw err;
813
+ }
814
+ }
815
+ this.isResolved = true;
816
+ this.chainAsyncFinishTime = (this.performance.now() ?? 0) - this.chainAsyncStartTime;
817
+ return this;
818
+ },
819
+ [],
820
+ (ms, call) => {
821
+ this.stoppedWithError = new Error(`Timeout after ${ms}ms`);
822
+ }
823
+ ).then((result) => {
824
+ onfulfilled(result);
825
+ return result;
826
+ }).catch(onrejected);
827
+ }
828
+ catch(onrejected) {
829
+ return this.then(void 0, onrejected);
830
+ }
831
+ finally(onfinally) {
832
+ return this.then(
833
+ (value) => {
834
+ onfinally?.();
835
+ return value;
836
+ },
837
+ (reason) => {
838
+ onfinally?.();
839
+ throw reason;
840
+ }
841
+ );
842
+ }
843
+ }
844
+ function scrollHelper(methodName, elements, xOrOptions, y) {
845
+ elements.forEach((el) => {
846
+ const element = el;
847
+ if (typeof xOrOptions === "object") {
848
+ element[methodName](xOrOptions);
849
+ } else if (y !== void 0) {
850
+ element[methodName](xOrOptions, y);
851
+ } else {
852
+ element[methodName](xOrOptions, 0);
853
+ }
854
+ });
855
+ return elements;
856
+ }
857
+ function getAllFormValues(chain) {
858
+ const formFields = {};
859
+ const mapCheckboxValue = (value) => value === "on" ? true : value;
860
+ chain.nodes.forEach((el) => {
861
+ processAllFormElements(el, (input, key) => {
862
+ if (!key) return;
863
+ if (input instanceof HTMLInputElement) {
864
+ if (input.type === "checkbox") {
865
+ if (input.checked) {
866
+ const value = mapCheckboxValue(input.value);
867
+ if (typeof formFields[key] !== "undefined") {
868
+ formFields[key] = [formFields[key], value];
869
+ } else if (Array.isArray(formFields[key])) {
870
+ formFields[key].push(value);
871
+ } else {
872
+ formFields[key] = value;
873
+ }
874
+ }
875
+ } else if (input.type === "radio") {
876
+ if (input.checked) {
877
+ console.log("input radio value", input.value);
878
+ formFields[key] = input.value === "on" ? true : input.value;
879
+ }
880
+ } else if (input.type === "file") {
881
+ if (input.files?.length) {
882
+ const fileNames = Array.from(input.files).map((file) => file.name);
883
+ formFields[key] = fileNames.length === 1 ? fileNames[0] : fileNames;
884
+ }
885
+ } else {
886
+ formFields[key] = input.value;
887
+ }
888
+ } else if (input instanceof HTMLSelectElement) {
889
+ if (input.multiple) {
890
+ const values = Array.from(input.selectedOptions).map(
891
+ (option) => option.value
892
+ );
893
+ formFields[key] = values.length === 1 ? values[0] : values;
894
+ } else {
895
+ formFields[key] = input.value;
896
+ }
897
+ } else if (input instanceof HTMLTextAreaElement) {
898
+ formFields[key] = input.value;
899
+ }
900
+ });
901
+ });
902
+ return formFields;
903
+ }
904
+ function delayedAutoStart(chain) {
905
+ if (chain.options.autoStart) {
906
+ setTimeout(async () => {
907
+ if (chain.chainAsyncStartTime === 0) {
908
+ chain = await chain;
909
+ }
910
+ }, chain.options.autoStartDelay);
911
+ }
912
+ return chain;
913
+ }
914
+ function dequery(selectorRefOrEl, options = getDefaultDequeryOptions()) {
915
+ if (typeof selectorRefOrEl === "function") {
916
+ const syncChain = dequery("body", options);
917
+ queueMicrotask(async () => {
918
+ const result = await selectorRefOrEl();
919
+ if (!syncChain.isResolved) {
920
+ if (typeof result !== "undefined") {
921
+ const newChain = dequery(result, options);
922
+ syncChain.resultStack = newChain.resultStack;
923
+ syncChain.lastResult = newChain.lastResult;
924
+ mapArrayIndexAccess(newChain, syncChain);
925
+ }
926
+ }
927
+ });
928
+ return delayedAutoStart(syncChain);
929
+ }
930
+ const chain = new CallChainImplThenable({
931
+ ...options,
932
+ resultStack: []
933
+ });
934
+ if (!selectorRefOrEl)
935
+ throw new Error("dequery: selector/ref/element required");
936
+ if (typeof selectorRefOrEl === "string") {
937
+ if (selectorRefOrEl.indexOf("<") === 0) {
938
+ const elements = renderMarkup(selectorRefOrEl, chain.Parser);
939
+ const renderRootEl = elements[0];
940
+ const { text, html, ...attributes } = chain.elementCreationOptions;
941
+ if (renderRootEl instanceof Element) {
942
+ Object.entries(attributes).forEach(([key, value]) => {
943
+ renderRootEl.setAttribute(key, String(value));
944
+ });
945
+ if (html) {
946
+ renderRootEl.innerHTML = html;
947
+ } else if (text) {
948
+ renderRootEl.textContent = text;
949
+ }
950
+ }
951
+ chain.resultStack = [elements];
952
+ return delayedAutoStart(chain);
953
+ } else {
954
+ return delayedAutoStart(
955
+ chain.query(selectorRefOrEl)
956
+ );
957
+ }
958
+ } else if (isRef(selectorRefOrEl)) {
959
+ return delayedAutoStart(
960
+ chain.ref(selectorRefOrEl)
961
+ );
962
+ } else if (selectorRefOrEl.nodeType) {
963
+ chain.resultStack = [[selectorRefOrEl]];
964
+ return delayedAutoStart(chain);
965
+ } else if (isJSX(selectorRefOrEl)) {
966
+ const renderResult = renderIsomorphicSync(
967
+ selectorRefOrEl,
968
+ chain.document.body,
969
+ chain.globals
970
+ );
971
+ const elements = typeof renderResult !== "undefined" ? Array.isArray(renderResult) ? renderResult : [renderResult] : [];
972
+ chain.resultStack = [elements];
973
+ return delayedAutoStart(chain);
974
+ }
975
+ throw new Error("Unsupported selectorOrEl type");
976
+ }
977
+ dequery.extend = (ExtensionClass, nonChainedReturnCalls = []) => {
978
+ const extensionPrototype = ExtensionClass.prototype;
979
+ const basePrototype = CallChainImpl.prototype;
980
+ const extensionMethods = Object.getOwnPropertyNames(extensionPrototype);
981
+ const baseMethods = Object.getOwnPropertyNames(basePrototype);
982
+ extensionMethods.forEach((methodName) => {
983
+ if (methodName !== "constructor" && !baseMethods.includes(methodName) && typeof extensionPrototype[methodName] === "function") {
984
+ CallChainImpl.prototype[methodName] = extensionPrototype[methodName];
985
+ CallChainImplThenable.prototype[methodName] = extensionPrototype[methodName];
986
+ }
987
+ });
988
+ if (nonChainedReturnCalls.length > 0) {
989
+ addNonChainedReturnCallNames(nonChainedReturnCalls);
990
+ }
991
+ return (selectorRefOrEl, options) => {
992
+ return dequery(
993
+ selectorRefOrEl,
994
+ options
995
+ );
996
+ };
997
+ };
998
+ const $ = dequery;
999
+ function isDequery(obj) {
1000
+ return typeof obj === "object" && obj !== null && "isResolved" in obj && "lastResult" in obj && "resultStack" in obj && "callStack" in obj && "stackPointer" in obj;
1001
+ }
1002
+ function isDequeryOptionsObject(o) {
1003
+ return o && typeof o === "object" && o.timeout !== void 0 && o.globals !== void 0;
1004
+ }
1005
+ let defaultOptions = null;
1006
+ function getDefaultDequeryOptions() {
1007
+ if (!defaultOptions) {
1008
+ defaultOptions = {
1009
+ timeout: 500,
1010
+ // even long sync chains would execute in < .1ms
1011
+ // so after 1ms, we can assume the "await" in front is
1012
+ // missing (intentionally non-blocking in sync code)
1013
+ autoStartDelay: 1,
1014
+ autoStart: true,
1015
+ resultStack: [],
1016
+ globals: {
1017
+ document: globalThis.document,
1018
+ window: globalThis.window,
1019
+ performance: globalThis.performance
1020
+ }
1021
+ };
1022
+ }
1023
+ return { ...defaultOptions };
1024
+ }
1025
+ function mapArrayIndexAccess(source, target) {
1026
+ const elements = source.nodes;
1027
+ for (let i = 0; i < elements.length; i++) {
1028
+ target[i] = elements[i];
1029
+ }
1030
+ target.length = elements.length;
1031
+ }
1032
+ function createCall(chain, methodName, handler) {
1033
+ chain.callStack.push(new Call(methodName, handler));
1034
+ return subChainForNextAwait(chain);
1035
+ }
1036
+ function createGetterSetterCall(chain, methodName, value, getter, setter) {
1037
+ if (value !== void 0) {
1038
+ return createCall(chain, methodName, async () => {
1039
+ setter(value);
1040
+ return chain.nodes;
1041
+ });
1042
+ } else {
1043
+ return createCall(chain, methodName, async () => {
1044
+ return getter();
1045
+ });
1046
+ }
1047
+ }
1048
+ function createSubChain(source, Constructor = CallChainImpl, isResolved = false) {
1049
+ const subChain = new Constructor(source.options);
1050
+ subChain.callStack = source.callStack;
1051
+ subChain.resultStack = source.resultStack;
1052
+ subChain.stackPointer = source.stackPointer;
1053
+ subChain.stoppedWithError = source.stoppedWithError;
1054
+ subChain.lastResult = source.lastResult;
1055
+ subChain.isResolved = typeof isResolved !== "undefined" ? isResolved : source.isResolved;
1056
+ subChain.lastResolvedStackPointer = source.lastResolvedStackPointer;
1057
+ if (Array.isArray(subChain.lastResult)) {
1058
+ mapArrayIndexAccess(source, subChain);
1059
+ }
1060
+ return delayedAutoStart(subChain);
1061
+ }
1062
+ function subChainForNextAwait(source) {
1063
+ if (source.lastResolvedStackPointer) {
1064
+ source.callStack = source.callStack.slice(source.lastResolvedStackPointer);
1065
+ source.stackPointer = source.stackPointer - source.lastResolvedStackPointer;
1066
+ source.resultStack = source.resultStack.slice(
1067
+ source.lastResolvedStackPointer
1068
+ );
1069
+ source.lastResult = source.resultStack[source.resultStack.length - 1] || [];
1070
+ source.lastResolvedStackPointer = 0;
1071
+ source.stoppedWithError = null;
1072
+ }
1073
+ return source instanceof CallChainImplThenable ? source : createSubChain(source, CallChainImplThenable);
1074
+ }
1075
+ function runWithTimeGuard(timeout, fn, args, onError) {
1076
+ return createTimeoutPromise(
1077
+ timeout,
1078
+ () => fn(...args),
1079
+ (ms) => {
1080
+ const fakeCall = new Call("timeout", async () => []);
1081
+ onError(ms, fakeCall);
1082
+ }
1083
+ );
1084
+ }
1085
+ async function renderNode(input, chain) {
1086
+ if (input == null) {
1087
+ return null;
1088
+ }
1089
+ if (typeof input === "string") {
1090
+ if (isMarkup(input, chain.Parser)) {
1091
+ return renderMarkup(input, chain.Parser)[0];
1092
+ } else {
1093
+ return chain.document.createTextNode(input);
1094
+ }
1095
+ } else if (isJSX(input)) {
1096
+ return renderIsomorphicSync(
1097
+ input,
1098
+ chain.document.body,
1099
+ chain.options.globals
1100
+ );
1101
+ } else if (isRef(input)) {
1102
+ await waitForRef(input, chain.options.timeout);
1103
+ return input.current;
1104
+ } else if (input && typeof input === "object" && "nodeType" in input) {
1105
+ return input;
1106
+ } else if (isDequery(input)) {
1107
+ return await input.getFirstElement();
1108
+ }
1109
+ console.warn("resolveContent: unsupported content type", input);
1110
+ return null;
1111
+ }
1112
+ async function resolveNodes(input, timeout, document) {
1113
+ let nodes = [];
1114
+ if (isRef(input)) {
1115
+ await waitForRef(input, timeout);
1116
+ nodes = [input.current];
1117
+ } else if (typeof input === "string" && document) {
1118
+ const result = await waitForDOM(
1119
+ () => {
1120
+ const el2 = document.querySelector(input);
1121
+ if (el2) {
1122
+ return [el2];
1123
+ } else {
1124
+ return [];
1125
+ }
1126
+ },
1127
+ timeout,
1128
+ document
1129
+ );
1130
+ const el = result[0];
1131
+ if (el) nodes = [el];
1132
+ } else if (input && typeof input === "object" && "nodeType" in input) {
1133
+ nodes = [input];
1134
+ } else if (isDequery(input)) {
1135
+ const elements = input.nodes;
1136
+ nodes = elements.filter((el) => el.nodeType !== void 0).map((el) => el);
1137
+ } else {
1138
+ console.warn("resolveTargets: expected selector, ref or node, got", input);
1139
+ }
1140
+ return nodes;
1141
+ }
1142
+ function traverse(chain, methodName, selector) {
1143
+ return createCall(chain, methodName, async () => {
1144
+ return chain.nodes.flatMap((el) => {
1145
+ if (el instanceof Element) {
1146
+ try {
1147
+ const result = selector(el);
1148
+ if (Array.isArray(result)) {
1149
+ return result.filter(
1150
+ (item) => item instanceof Element
1151
+ );
1152
+ } else if (result instanceof Element) {
1153
+ return [result];
1154
+ }
1155
+ } catch (err) {
1156
+ console.warn("Error in traverse selector function:", err);
1157
+ }
1158
+ }
1159
+ return [];
1160
+ });
1161
+ });
1162
+ }
1163
+
1164
+ const newInMemoryGenericStorageBackend = () => {
1165
+ const cache = /* @__PURE__ */ new Map();
1166
+ return {
1167
+ clear: () => {
1168
+ cache.clear();
1169
+ },
1170
+ getItem: (key) => {
1171
+ return cache.get(String(key)) ?? null;
1172
+ },
1173
+ removeItem: (key) => {
1174
+ cache.delete(String(key));
1175
+ },
1176
+ setItem: (key, value) => {
1177
+ cache.set(String(key), value);
1178
+ }
1179
+ };
1180
+ };
1181
+ const memory = newInMemoryGenericStorageBackend();
1182
+ class WebStorageProvider {
1183
+ storage;
1184
+ constructor(storage) {
1185
+ this.storage = storage || memory;
1186
+ }
1187
+ get(key, defaultValue, middlewareFn) {
1188
+ const rawValue = this.storage.getItem(key);
1189
+ if (rawValue === null) return defaultValue;
1190
+ let value = JSON.parse(rawValue);
1191
+ if (middlewareFn) {
1192
+ value = middlewareFn(key, value);
1193
+ }
1194
+ return value;
1195
+ }
1196
+ set(key, value, middlewareFn) {
1197
+ if (middlewareFn) {
1198
+ value = middlewareFn(key, value);
1199
+ }
1200
+ this.storage.setItem(key, JSON.stringify(value));
1201
+ }
1202
+ remove(key) {
1203
+ this.storage.removeItem(key);
1204
+ }
1205
+ removeAll() {
1206
+ this.storage.clear();
1207
+ }
1208
+ get backendApi() {
1209
+ return this.storage;
1210
+ }
1211
+ }
1212
+
1213
+ const getPersistenceProvider$1 = (provider, _options) => {
1214
+ switch (provider) {
1215
+ case "session":
1216
+ return new WebStorageProvider(window.sessionStorage);
1217
+ case "local":
1218
+ return new WebStorageProvider(window.localStorage);
1219
+ }
1220
+ return new WebStorageProvider();
1221
+ };
1222
+
1223
+ const getPersistenceProvider = (_provider, _options) => {
1224
+ return new WebStorageProvider();
1225
+ };
1226
+
1227
+ const isServer = () => typeof window === "undefined" || typeof window.document === "undefined";
1228
+
1229
+ const webstorage = (provider = "local", options) => {
1230
+ if (isServer()) {
1231
+ return getPersistenceProvider();
1232
+ } else {
1233
+ return getPersistenceProvider$1(provider);
1234
+ }
1235
+ };
1236
+
1237
+ const createStore = (initialValue) => {
1238
+ let value = initialValue;
1239
+ const listeners = [];
1240
+ const notify = (oldValue, changedKey) => {
1241
+ listeners.forEach((listener) => listener(value, oldValue, changedKey));
1242
+ };
1243
+ let storage = null;
1244
+ let storageKey = null;
1245
+ let storageProvider;
1246
+ const initStorage = (provider) => {
1247
+ if (!storage || storageProvider !== provider) {
1248
+ storage = webstorage(provider);
1249
+ storageProvider = provider;
1250
+ }
1251
+ return storage;
1252
+ };
1253
+ const persistToStorage = () => {
1254
+ if (storage && storageKey) {
1255
+ storage.set(storageKey, value);
1256
+ }
1257
+ };
1258
+ return {
1259
+ // allow reading value but prevent external mutation
1260
+ get value() {
1261
+ return value;
1262
+ },
1263
+ persist(key, provider = "local") {
1264
+ storage = initStorage(provider);
1265
+ storageKey = key;
1266
+ persistToStorage();
1267
+ },
1268
+ restore(key, provider = "local") {
1269
+ storage = initStorage(provider);
1270
+ storageKey = key;
1271
+ const storedValue = storage.get(key, value);
1272
+ const valueAsString = JSON.stringify(value);
1273
+ const storedValueAsString = JSON.stringify(storedValue);
1274
+ if (valueAsString !== storedValueAsString) {
1275
+ value = storedValue;
1276
+ notify(value);
1277
+ }
1278
+ },
1279
+ get(path) {
1280
+ return path ? getByPath(value, path) : value;
1281
+ },
1282
+ set(pathOrValue, newValue) {
1283
+ const oldValue = value;
1284
+ if (newValue === void 0) {
1285
+ const valueAsString = JSON.stringify(value);
1286
+ const newValueAsString = JSON.stringify(pathOrValue);
1287
+ if (valueAsString !== newValueAsString) {
1288
+ value = pathOrValue;
1289
+ notify(oldValue);
1290
+ persistToStorage();
1291
+ }
1292
+ } else {
1293
+ const updatedValue = setByPath(value, pathOrValue, newValue);
1294
+ const updatedValueAsString = JSON.stringify(updatedValue);
1295
+ const oldValueAsString = JSON.stringify(oldValue);
1296
+ if (oldValueAsString !== updatedValueAsString) {
1297
+ value = updatedValue;
1298
+ notify(oldValue, pathOrValue);
1299
+ persistToStorage();
1300
+ }
1301
+ }
1302
+ },
1303
+ subscribe(listener) {
1304
+ listeners.push(listener);
1305
+ return () => {
1306
+ const index = listeners.indexOf(listener);
1307
+ if (index >= 0) listeners.splice(index, 1);
1308
+ };
1309
+ }
1310
+ };
1311
+ };
1312
+
1313
+ const isRef = (obj) => Boolean(obj && typeof obj === "object" && "current" in obj);
1314
+ function createRef(refUpdateFn, defaultState) {
1315
+ const stateStore = createStore(defaultState);
1316
+ const ref = {
1317
+ current: null,
1318
+ store: stateStore,
1319
+ get state() {
1320
+ return stateStore.value;
1321
+ },
1322
+ set state(value) {
1323
+ stateStore.set(value);
1324
+ },
1325
+ persist: (key, provider = "local") => {
1326
+ stateStore.persist(key, provider);
1327
+ },
1328
+ restore: (key, provider = "local") => {
1329
+ stateStore.restore(key, provider);
1330
+ },
1331
+ updateState: (state) => {
1332
+ stateStore.set(state);
1333
+ },
1334
+ update: async (input) => await $(ref.current).update(input),
1335
+ subscribe: (refUpdateFn2) => stateStore.subscribe(refUpdateFn2)
1336
+ };
1337
+ if (typeof refUpdateFn === "function") {
1338
+ ref.subscribe(refUpdateFn);
1339
+ }
1340
+ return ref;
1341
+ }
1342
+
1343
+ const getTransitionStyles = (type, duration, easing = "ease-in-out") => {
1344
+ const baseTransition = `all ${duration}ms ${easing}`;
1345
+ const filterUndefined = (obj) => {
1346
+ const filtered = {};
1347
+ Object.entries(obj).forEach(([key, value]) => {
1348
+ if (value !== void 0) {
1349
+ filtered[key] = value;
1350
+ }
1351
+ });
1352
+ return filtered;
1353
+ };
1354
+ switch (type) {
1355
+ case "fade":
1356
+ return {
1357
+ enter: filterUndefined({ opacity: "0", transition: baseTransition }),
1358
+ enterActive: filterUndefined({ opacity: "1" }),
1359
+ exit: filterUndefined({ opacity: "1", transition: baseTransition }),
1360
+ exitActive: filterUndefined({ opacity: "0" })
1361
+ };
1362
+ case "slide-left":
1363
+ return {
1364
+ enter: filterUndefined({
1365
+ transform: "translateX(100%)",
1366
+ opacity: "0",
1367
+ transition: baseTransition
1368
+ }),
1369
+ enterActive: filterUndefined({
1370
+ transform: "translateX(0%)",
1371
+ opacity: "1"
1372
+ }),
1373
+ exit: filterUndefined({
1374
+ transform: "translateX(0%)",
1375
+ opacity: "1",
1376
+ transition: baseTransition
1377
+ }),
1378
+ exitActive: filterUndefined({
1379
+ transform: "translateX(-200%)",
1380
+ opacity: "0"
1381
+ })
1382
+ };
1383
+ case "slide-right":
1384
+ return {
1385
+ enter: filterUndefined({
1386
+ transform: "translateX(-200%)",
1387
+ opacity: "0",
1388
+ transition: baseTransition
1389
+ }),
1390
+ enterActive: filterUndefined({
1391
+ transform: "translateX(0%)",
1392
+ opacity: "1"
1393
+ }),
1394
+ exit: filterUndefined({
1395
+ transform: "translateX(0%)",
1396
+ opacity: "1",
1397
+ transition: baseTransition
1398
+ }),
1399
+ exitActive: filterUndefined({
1400
+ transform: "translateX(100%)",
1401
+ opacity: "0"
1402
+ })
1403
+ };
1404
+ case "slide-up":
1405
+ return {
1406
+ enter: filterUndefined({
1407
+ transform: "translateY(100%)",
1408
+ opacity: "0",
1409
+ transition: baseTransition
1410
+ }),
1411
+ enterActive: filterUndefined({
1412
+ transform: "translateY(0%)",
1413
+ opacity: "1"
1414
+ }),
1415
+ exit: filterUndefined({
1416
+ transform: "translateY(0%)",
1417
+ opacity: "1",
1418
+ transition: baseTransition
1419
+ }),
1420
+ exitActive: filterUndefined({
1421
+ transform: "translateY(-200%)",
1422
+ opacity: "0"
1423
+ })
1424
+ };
1425
+ case "slide-down":
1426
+ return {
1427
+ enter: filterUndefined({
1428
+ transform: "translateY(-200%)",
1429
+ opacity: "0",
1430
+ transition: baseTransition
1431
+ }),
1432
+ enterActive: filterUndefined({
1433
+ transform: "translateY(0%)",
1434
+ opacity: "1"
1435
+ }),
1436
+ exit: filterUndefined({
1437
+ transform: "translateY(0%)",
1438
+ opacity: "1",
1439
+ transition: baseTransition
1440
+ }),
1441
+ exitActive: filterUndefined({
1442
+ transform: "translateY(100%)",
1443
+ opacity: "0"
1444
+ })
1445
+ };
1446
+ case "zoom":
1447
+ return {
1448
+ enter: filterUndefined({
1449
+ transform: "scale(0)",
1450
+ opacity: "0",
1451
+ transition: baseTransition
1452
+ }),
1453
+ enterActive: filterUndefined({ transform: "scale(1)", opacity: "1" }),
1454
+ exit: filterUndefined({
1455
+ transform: "scale(1)",
1456
+ opacity: "1",
1457
+ transition: baseTransition
1458
+ }),
1459
+ exitActive: filterUndefined({ transform: "scale(0)", opacity: "0" })
1460
+ };
1461
+ case "rotate":
1462
+ return {
1463
+ enter: filterUndefined({
1464
+ transform: "rotate(-360deg)",
1465
+ opacity: "0",
1466
+ transition: baseTransition
1467
+ }),
1468
+ enterActive: filterUndefined({
1469
+ transform: "rotate(0deg)",
1470
+ opacity: "1"
1471
+ }),
1472
+ exit: filterUndefined({
1473
+ transform: "rotate(0deg)",
1474
+ opacity: "1",
1475
+ transition: baseTransition
1476
+ }),
1477
+ exitActive: filterUndefined({
1478
+ transform: "rotate(360deg)",
1479
+ opacity: "0"
1480
+ })
1481
+ };
1482
+ case "flip-horizontal":
1483
+ return {
1484
+ enter: filterUndefined({
1485
+ transform: "perspective(1000px) rotateY(-360deg)",
1486
+ opacity: "0",
1487
+ transition: baseTransition
1488
+ }),
1489
+ enterActive: filterUndefined({
1490
+ transform: "perspective(1000px) rotateY(0deg)",
1491
+ opacity: "1"
1492
+ }),
1493
+ exit: filterUndefined({
1494
+ transform: "perspective(1000px) rotateY(0deg)",
1495
+ opacity: "1",
1496
+ transition: baseTransition
1497
+ }),
1498
+ exitActive: filterUndefined({
1499
+ transform: "perspective(1000px) rotateY(360deg)",
1500
+ opacity: "0"
1501
+ })
1502
+ };
1503
+ case "flip-vertical":
1504
+ return {
1505
+ enter: filterUndefined({
1506
+ transform: "perspective(1000px) rotateX(-360deg)",
1507
+ opacity: "0",
1508
+ transition: baseTransition
1509
+ }),
1510
+ enterActive: filterUndefined({
1511
+ transform: "perspective(1000px) rotateX(0deg)",
1512
+ opacity: "1"
1513
+ }),
1514
+ exit: filterUndefined({
1515
+ transform: "perspective(1000px) rotateX(0deg)",
1516
+ opacity: "1",
1517
+ transition: baseTransition
1518
+ }),
1519
+ exitActive: filterUndefined({
1520
+ transform: "perspective(1000px) rotateX(360deg)",
1521
+ opacity: "0"
1522
+ })
1523
+ };
1524
+ case "bounce":
1525
+ return {
1526
+ enter: filterUndefined({
1527
+ transform: "scale(0.3)",
1528
+ opacity: "0",
1529
+ transition: `all ${duration}ms cubic-bezier(0.68, -0.55, 0.265, 1.55)`
1530
+ }),
1531
+ enterActive: filterUndefined({
1532
+ transform: "scale(1)",
1533
+ opacity: "1"
1534
+ }),
1535
+ exit: filterUndefined({
1536
+ transform: "scale(1)",
1537
+ opacity: "1",
1538
+ transition: `all ${duration}ms cubic-bezier(0.68, -0.55, 0.265, 1.55)`
1539
+ }),
1540
+ exitActive: filterUndefined({
1541
+ transform: "scale(0.3)",
1542
+ opacity: "0"
1543
+ })
1544
+ };
1545
+ default:
1546
+ return {
1547
+ enter: {},
1548
+ enterActive: {},
1549
+ exit: {},
1550
+ exitActive: {}
1551
+ };
1552
+ }
1553
+ };
1554
+ const applyStyles = (element, styles) => {
1555
+ Object.entries(styles).forEach(([property, value]) => {
1556
+ element.style.setProperty(property, String(value));
1557
+ });
1558
+ };
1559
+ const createContentSnapshot = (element) => {
1560
+ const snapshot = element.cloneNode(true);
1561
+ const computedStyle = window.getComputedStyle(element);
1562
+ const rect = element.getBoundingClientRect();
1563
+ applyStyles(snapshot, {
1564
+ position: "absolute",
1565
+ top: `${rect.top + window.scrollY}px`,
1566
+ left: `${rect.left + window.scrollX}px`,
1567
+ width: `${rect.width}px`,
1568
+ height: `${rect.height}px`,
1569
+ zIndex: "-1",
1570
+ // Behind the original content
1571
+ pointerEvents: "none",
1572
+ // Don't interfere with interactions
1573
+ // Copy important visual styles
1574
+ background: computedStyle.background,
1575
+ border: computedStyle.border,
1576
+ borderRadius: computedStyle.borderRadius,
1577
+ boxShadow: computedStyle.boxShadow,
1578
+ // Preserve text and content styles
1579
+ font: computedStyle.font,
1580
+ color: computedStyle.color,
1581
+ textAlign: computedStyle.textAlign,
1582
+ lineHeight: computedStyle.lineHeight
1583
+ });
1584
+ snapshot.classList.add("defuss-content-snapshot");
1585
+ return snapshot;
1586
+ };
1587
+ const insertContentSnapshot = (snapshot, targetElement) => {
1588
+ const positionedParent = getPositionedParent(targetElement);
1589
+ (positionedParent || document.body).appendChild(snapshot);
1590
+ };
1591
+ const removeContentSnapshot = (snapshot) => {
1592
+ if (snapshot.parentNode) {
1593
+ snapshot.parentNode.removeChild(snapshot);
1594
+ }
1595
+ };
1596
+ const getPositionedParent = (element) => {
1597
+ let parent = element.parentElement;
1598
+ while (parent) {
1599
+ const style = window.getComputedStyle(parent);
1600
+ if (style.position !== "static") {
1601
+ return parent;
1602
+ }
1603
+ parent = parent.parentElement;
1604
+ }
1605
+ return null;
1606
+ };
1607
+ const DEFAULT_TRANSITION_CONFIG = {
1608
+ type: "fade",
1609
+ duration: 300,
1610
+ easing: "ease-in-out",
1611
+ delay: 0
1612
+ };
1613
+ const waitForTransition = (element, duration) => {
1614
+ return new Promise((resolve) => {
1615
+ const handleTransitionEnd = () => {
1616
+ element.removeEventListener("transitionend", handleTransitionEnd);
1617
+ resolve();
1618
+ };
1619
+ element.addEventListener("transitionend", handleTransitionEnd);
1620
+ setTimeout(resolve, duration + 50);
1621
+ });
1622
+ };
1623
+ const scheduleTransitionStep = (callback) => {
1624
+ queueMicrotask(callback);
1625
+ };
1626
+ const scheduleDelayedStep = (callback, delay) => {
1627
+ if (delay > 0) {
1628
+ setTimeout(callback, delay);
1629
+ } else {
1630
+ queueMicrotask(callback);
1631
+ }
1632
+ };
1633
+ const scheduleTransitionEnd = (element, duration, callback) => {
1634
+ let resolved = false;
1635
+ const handleTransitionEnd = () => {
1636
+ if (!resolved) {
1637
+ resolved = true;
1638
+ element.removeEventListener("transitionend", handleTransitionEnd);
1639
+ queueMicrotask(callback);
1640
+ }
1641
+ };
1642
+ element.addEventListener("transitionend", handleTransitionEnd);
1643
+ setTimeout(() => {
1644
+ if (!resolved) {
1645
+ resolved = true;
1646
+ element.removeEventListener("transitionend", handleTransitionEnd);
1647
+ queueMicrotask(callback);
1648
+ }
1649
+ }, duration + 50);
1650
+ };
1651
+ const storeOriginalStyles = (element, styleProperties) => {
1652
+ const originalStyles = {};
1653
+ styleProperties.forEach((property) => {
1654
+ const currentValue = element.style.getPropertyValue(property) || window.getComputedStyle(element).getPropertyValue(property);
1655
+ originalStyles[property] = currentValue;
1656
+ });
1657
+ return originalStyles;
1658
+ };
1659
+ const restoreOriginalStyles = (element, originalStyles) => {
1660
+ Object.entries(originalStyles).forEach(([property, value]) => {
1661
+ if (value) {
1662
+ element.style.setProperty(property, value);
1663
+ } else {
1664
+ element.style.removeProperty(property);
1665
+ }
1666
+ });
1667
+ };
1668
+
1669
+ var transitions = /*#__PURE__*/Object.freeze({
1670
+ __proto__: null,
1671
+ DEFAULT_TRANSITION_CONFIG: DEFAULT_TRANSITION_CONFIG,
1672
+ applyStyles: applyStyles,
1673
+ createContentSnapshot: createContentSnapshot,
1674
+ getTransitionStyles: getTransitionStyles,
1675
+ insertContentSnapshot: insertContentSnapshot,
1676
+ removeContentSnapshot: removeContentSnapshot,
1677
+ restoreOriginalStyles: restoreOriginalStyles,
1678
+ scheduleDelayedStep: scheduleDelayedStep,
1679
+ scheduleTransitionEnd: scheduleTransitionEnd,
1680
+ scheduleTransitionStep: scheduleTransitionStep,
1681
+ storeOriginalStyles: storeOriginalStyles,
1682
+ waitForTransition: waitForTransition
1683
+ });
1684
+
1685
+ const queueCallback = (cb) => () => queueMicrotask(cb);
1686
+
1687
+ const CLASS_ATTRIBUTE_NAME = "class";
1688
+ const XLINK_ATTRIBUTE_NAME = "xlink";
1689
+ const XMLNS_ATTRIBUTE_NAME = "xmlns";
1690
+ const REF_ATTRIBUTE_NAME = "ref";
1691
+ const nsMap = {
1692
+ [XMLNS_ATTRIBUTE_NAME]: "http://www.w3.org/2000/xmlns/",
1693
+ [XLINK_ATTRIBUTE_NAME]: "http://www.w3.org/1999/xlink",
1694
+ svg: "http://www.w3.org/2000/svg"
1695
+ };
1696
+ const isJSXComment = (node) => (
1697
+ /* v8 ignore next */
1698
+ node && typeof node === "object" && !node.attributes && !node.type && !node.children
1699
+ );
1700
+ const filterComments = (children) => children.filter((child) => !isJSXComment(child));
1701
+ const createInPlaceErrorMessageVNode = (error) => ({
1702
+ type: "p",
1703
+ attributes: {},
1704
+ children: [`FATAL ERROR: ${error?.message || error}`]
1705
+ });
1706
+ const jsx = (type, attributes, key) => {
1707
+ attributes = { ...attributes };
1708
+ if (typeof key !== "undefined") {
1709
+ attributes.key = key;
1710
+ }
1711
+ let children = (attributes?.children ? [].concat(attributes.children) : []).filter(Boolean);
1712
+ delete attributes?.children;
1713
+ children = filterComments(
1714
+ // Implementation to flatten virtual node children structures like:
1715
+ // [<p>1</p>, [<p>2</p>,<p>3</p>]] to: [<p>1</p>,<p>2</p>,<p>3</p>]
1716
+ [].concat.apply(
1717
+ [],
1718
+ children
1719
+ )
1720
+ );
1721
+ if (type === "fragment") {
1722
+ return filterComments(children);
1723
+ }
1724
+ if (typeof type === "function" && type.constructor.name !== "AsyncFunction") {
1725
+ try {
1726
+ return type({
1727
+ children,
1728
+ ...attributes
1729
+ });
1730
+ } catch (error) {
1731
+ if (typeof error === "string") {
1732
+ error = `[JsxError] in ${type.name}: ${error}`;
1733
+ } else if (error instanceof Error) {
1734
+ error.message = `[JsxError] in ${type.name}: ${error.message}`;
1735
+ }
1736
+ return createInPlaceErrorMessageVNode(error);
1737
+ }
1738
+ }
1739
+ return {
1740
+ type,
1741
+ attributes,
1742
+ children
1743
+ };
1744
+ };
1745
+ const observeUnmount = (domNode, onUnmount) => {
1746
+ if (!domNode || typeof onUnmount !== "function") {
1747
+ throw new Error(
1748
+ "Invalid arguments. Ensure domNode and onUnmount are valid."
1749
+ );
1750
+ }
1751
+ const parentNode = domNode.parentNode;
1752
+ if (!parentNode) {
1753
+ throw new Error("The provided domNode does not have a parentNode.");
1754
+ }
1755
+ const observer = new MutationObserver((mutationsList) => {
1756
+ for (const mutation of mutationsList) {
1757
+ if (mutation.removedNodes.length > 0) {
1758
+ for (const removedNode of mutation.removedNodes) {
1759
+ if (removedNode === domNode) {
1760
+ onUnmount();
1761
+ observer.disconnect();
1762
+ return;
1763
+ }
1764
+ }
1765
+ }
1766
+ }
1767
+ });
1768
+ observer.observe(parentNode, { childList: true });
1769
+ };
1770
+ const handleLifecycleEventsForOnMount = (newEl) => {
1771
+ if (typeof newEl?.$onMount === "function") {
1772
+ newEl.$onMount();
1773
+ newEl.$onMount = null;
1774
+ }
1775
+ if (typeof newEl?.$onUnmount === "function") {
1776
+ observeUnmount(newEl, newEl.$onUnmount);
1777
+ }
1778
+ };
1779
+ const getRenderer = (document) => {
1780
+ const renderer = {
1781
+ hasElNamespace: (domElement) => domElement.namespaceURI === nsMap.svg,
1782
+ hasSvgNamespace: (parentElement, type) => renderer.hasElNamespace(parentElement) && type !== "STYLE" && type !== "SCRIPT",
1783
+ createElementOrElements: (virtualNode, parentDomElement) => {
1784
+ if (Array.isArray(virtualNode)) {
1785
+ return renderer.createChildElements(virtualNode, parentDomElement);
1786
+ }
1787
+ if (typeof virtualNode !== "undefined") {
1788
+ return renderer.createElement(virtualNode, parentDomElement);
1789
+ }
1790
+ return renderer.createTextNode("", parentDomElement);
1791
+ },
1792
+ createElement: (virtualNode, parentDomElement) => {
1793
+ let newEl = void 0;
1794
+ try {
1795
+ if (virtualNode.constructor.name === "AsyncFunction") {
1796
+ newEl = document.createElement("div");
1797
+ } else if (typeof virtualNode.type === "function") {
1798
+ newEl = document.createElement("div");
1799
+ newEl.innerText = `FATAL ERROR: ${virtualNode.type._error}`;
1800
+ } else if (
1801
+ // SVG support
1802
+ virtualNode.type.toUpperCase() === "SVG" || parentDomElement && renderer.hasSvgNamespace(
1803
+ parentDomElement,
1804
+ virtualNode.type.toUpperCase()
1805
+ )
1806
+ ) {
1807
+ newEl = document.createElementNS(
1808
+ nsMap.svg,
1809
+ virtualNode.type
1810
+ );
1811
+ } else {
1812
+ newEl = document.createElement(virtualNode.type);
1813
+ }
1814
+ if (virtualNode.attributes) {
1815
+ renderer.setAttributes(virtualNode, newEl);
1816
+ if (virtualNode.attributes.dangerouslySetInnerHTML) {
1817
+ updateDom(
1818
+ virtualNode.attributes.dangerouslySetInnerHTML.__html,
1819
+ [newEl],
1820
+ 1e3,
1821
+ // timeout in ms
1822
+ globalThis.DOMParser
1823
+ );
1824
+ }
1825
+ }
1826
+ if (virtualNode.children) {
1827
+ renderer.createChildElements(virtualNode.children, newEl);
1828
+ }
1829
+ if (parentDomElement) {
1830
+ parentDomElement.appendChild(newEl);
1831
+ handleLifecycleEventsForOnMount(newEl);
1832
+ }
1833
+ } catch (e) {
1834
+ console.error(
1835
+ "Fatal error! Error happend while rendering the VDOM!",
1836
+ e,
1837
+ virtualNode
1838
+ );
1839
+ throw e;
1840
+ }
1841
+ return newEl;
1842
+ },
1843
+ createTextNode: (text, domElement) => {
1844
+ const node = document.createTextNode(text.toString());
1845
+ if (domElement) {
1846
+ domElement.appendChild(node);
1847
+ }
1848
+ return node;
1849
+ },
1850
+ createChildElements: (virtualChildren, domElement) => {
1851
+ const children = [];
1852
+ for (let i = 0; i < virtualChildren.length; i++) {
1853
+ const virtualChild = virtualChildren[i];
1854
+ if (virtualChild === null || typeof virtualChild !== "object" && typeof virtualChild !== "function") {
1855
+ children.push(
1856
+ renderer.createTextNode(
1857
+ (typeof virtualChild === "undefined" || virtualChild === null ? "" : virtualChild).toString(),
1858
+ domElement
1859
+ )
1860
+ );
1861
+ } else {
1862
+ children.push(
1863
+ renderer.createElement(virtualChild, domElement)
1864
+ );
1865
+ }
1866
+ }
1867
+ return children;
1868
+ },
1869
+ setAttribute: (name, value, domElement, virtualNode) => {
1870
+ if (typeof value === "undefined") return;
1871
+ if (name === "dangerouslySetInnerHTML") return;
1872
+ if (name === REF_ATTRIBUTE_NAME && typeof value !== "function") {
1873
+ value.current = domElement;
1874
+ return;
1875
+ }
1876
+ if (name.startsWith("on") && typeof value === "function") {
1877
+ let eventName = name.substring(2).toLowerCase();
1878
+ const capturePos = eventName.indexOf("capture");
1879
+ const doCapture = capturePos > -1;
1880
+ if (eventName === "mount") {
1881
+ domElement.$onMount = queueCallback(value);
1882
+ }
1883
+ if (eventName === "unmount") {
1884
+ domElement.$onUnmount = queueCallback(value);
1885
+ }
1886
+ if (doCapture) {
1887
+ eventName = eventName.substring(0, capturePos);
1888
+ }
1889
+ domElement.addEventListener(eventName, value, doCapture);
1890
+ return;
1891
+ }
1892
+ if (name === "className") {
1893
+ name = CLASS_ATTRIBUTE_NAME;
1894
+ }
1895
+ if (name === CLASS_ATTRIBUTE_NAME && Array.isArray(value)) {
1896
+ value = value.join(" ");
1897
+ }
1898
+ const nsEndIndex = name.match(/[A-Z]/)?.index;
1899
+ if (renderer.hasElNamespace(domElement) && nsEndIndex) {
1900
+ const ns = name.substring(0, nsEndIndex).toLowerCase();
1901
+ const attrName = name.substring(nsEndIndex, name.length).toLowerCase();
1902
+ const namespace = nsMap[ns] || null;
1903
+ domElement.setAttributeNS(
1904
+ namespace,
1905
+ ns === XLINK_ATTRIBUTE_NAME || ns === "xmlns" ? `${ns}:${attrName}` : name,
1906
+ value
1907
+ );
1908
+ } else if (name === "style" && typeof value !== "string") {
1909
+ const propNames = Object.keys(value);
1910
+ for (let i = 0; i < propNames.length; i++) {
1911
+ domElement.style[propNames[i]] = value[propNames[i]];
1912
+ }
1913
+ } else if (typeof value === "boolean") {
1914
+ domElement[name] = value;
1915
+ } else {
1916
+ domElement.setAttribute(name, value);
1917
+ }
1918
+ },
1919
+ setAttributes: (virtualNode, domElement) => {
1920
+ const attrNames = Object.keys(virtualNode.attributes);
1921
+ for (let i = 0; i < attrNames.length; i++) {
1922
+ renderer.setAttribute(
1923
+ attrNames[i],
1924
+ virtualNode.attributes[attrNames[i]],
1925
+ domElement,
1926
+ virtualNode
1927
+ );
1928
+ }
1929
+ }
1930
+ };
1931
+ return renderer;
1932
+ };
1933
+ const renderIsomorphicSync = (virtualNode, parentDomElement, globals) => {
1934
+ if (isDequery(parentDomElement)) {
1935
+ parentDomElement = parentDomElement.getFirstElement() || parentDomElement;
1936
+ }
1937
+ let renderResult;
1938
+ if (typeof virtualNode === "string") {
1939
+ renderResult = getRenderer(globals.window.document).createTextNode(
1940
+ virtualNode,
1941
+ parentDomElement
1942
+ );
1943
+ } else {
1944
+ renderResult = getRenderer(globals.window.document).createElementOrElements(
1945
+ virtualNode,
1946
+ parentDomElement
1947
+ );
1948
+ }
1949
+ return renderResult;
1950
+ };
1951
+ const renderIsomorphicAsync = async (virtualNode, parentDomElement, globals) => {
1952
+ if (parentDomElement instanceof Promise) {
1953
+ parentDomElement = await parentDomElement;
1954
+ }
1955
+ if (isDequery(parentDomElement)) {
1956
+ parentDomElement = (await parentDomElement.toArray())[0];
1957
+ }
1958
+ if (virtualNode instanceof Promise) {
1959
+ virtualNode = await virtualNode;
1960
+ }
1961
+ return renderIsomorphicSync(
1962
+ virtualNode,
1963
+ parentDomElement,
1964
+ globals
1965
+ );
1966
+ };
1967
+ const globalScopeDomApis = (window, document) => {
1968
+ globalThis.__defuss_document = document;
1969
+ globalThis.__defuss_window = window;
1970
+ };
1971
+ const isJSX = (o) => {
1972
+ if (o === null || typeof o !== "object") return false;
1973
+ if (Array.isArray(o)) return o.every(isJSX);
1974
+ if (typeof o.type === "string") return true;
1975
+ if (typeof o.type === "function") return true;
1976
+ if (typeof o.attributes === "object" && typeof o.children === "object")
1977
+ return true;
1978
+ return false;
1979
+ };
1980
+ const Fragment = (props) => props.children;
1981
+ const jsxs = jsx;
1982
+ const jsxDEV = (type, attributes, key, allChildrenAreStatic, sourceInfo, selfReference) => {
1983
+ let renderResult;
1984
+ try {
1985
+ renderResult = jsx(type, attributes, key);
1986
+ } catch (error) {
1987
+ console.error(
1988
+ "JSX error:",
1989
+ error,
1990
+ "in",
1991
+ sourceInfo,
1992
+ "component",
1993
+ selfReference
1994
+ );
1995
+ }
1996
+ return renderResult;
1997
+ };
1998
+ async function performCoreDomUpdate(input, nodes, timeout, Parser) {
1999
+ let processedInput = input;
2000
+ if (isDequery(processedInput)) {
2001
+ processedInput = processedInput[0];
2002
+ }
2003
+ if (isRef(processedInput)) {
2004
+ await waitForRef(processedInput, timeout);
2005
+ processedInput = processedInput.current;
2006
+ }
2007
+ if (processedInput instanceof Node) {
2008
+ const vnode = domNodeToVNode(processedInput);
2009
+ nodes.forEach((el) => {
2010
+ if (el) {
2011
+ updateDomWithVdom(el, vnode, globalThis);
2012
+ }
2013
+ });
2014
+ return;
2015
+ }
2016
+ if (typeof processedInput === "string") {
2017
+ if (isMarkup(processedInput, Parser)) {
2018
+ const vNodes = htmlStringToVNodes(processedInput, Parser);
2019
+ nodes.forEach((el) => {
2020
+ if (el) {
2021
+ updateDomWithVdom(el, vNodes, globalThis);
2022
+ }
2023
+ });
2024
+ } else {
2025
+ nodes.forEach((el) => {
2026
+ if (el) {
2027
+ updateDomWithVdom(
2028
+ el,
2029
+ processedInput,
2030
+ globalThis
2031
+ );
2032
+ }
2033
+ });
2034
+ }
2035
+ } else if (isJSX(processedInput)) {
2036
+ nodes.forEach((el) => {
2037
+ if (el) {
2038
+ updateDomWithVdom(
2039
+ el,
2040
+ processedInput,
2041
+ globalThis
2042
+ );
2043
+ }
2044
+ });
2045
+ } else {
2046
+ console.warn("update: unsupported content type", processedInput);
2047
+ }
2048
+ }
2049
+ async function updateDom(input, nodes, timeout, Parser, transitionConfig) {
2050
+ if (transitionConfig && transitionConfig.type !== "none") {
2051
+ const {
2052
+ getTransitionStyles,
2053
+ applyStyles,
2054
+ storeOriginalStyles,
2055
+ restoreOriginalStyles,
2056
+ waitForTransition,
2057
+ createContentSnapshot,
2058
+ insertContentSnapshot,
2059
+ removeContentSnapshot,
2060
+ scheduleTransitionEnd,
2061
+ scheduleDelayedStep,
2062
+ DEFAULT_TRANSITION_CONFIG
2063
+ } = await Promise.resolve().then(function () { return transitions; });
2064
+ const config = { ...DEFAULT_TRANSITION_CONFIG, ...transitionConfig };
2065
+ const { duration = 300, easing = "ease-in-out", delay = 0 } = config;
2066
+ const transitionStyles = config.styles || getTransitionStyles(config.type || "fade", duration, easing);
2067
+ const transitionPromises = nodes.map(async (node) => {
2068
+ if (!node || !node.parentElement) {
2069
+ await performCoreDomUpdate(input, [node], timeout, Parser);
2070
+ return node;
2071
+ }
2072
+ const element = node;
2073
+ const parentElement = element.parentElement;
2074
+ let contentSnapshot = null;
2075
+ const shouldUseSnapshot = config.type === "fade";
2076
+ if (shouldUseSnapshot) {
2077
+ try {
2078
+ contentSnapshot = createContentSnapshot(parentElement);
2079
+ insertContentSnapshot(contentSnapshot, parentElement);
2080
+ } catch (error) {
2081
+ console.warn(
2082
+ "Failed to create content snapshot, falling back to regular transition:",
2083
+ error
2084
+ );
2085
+ contentSnapshot = null;
2086
+ }
2087
+ }
2088
+ const stylesToStore = [
2089
+ "opacity",
2090
+ "transform",
2091
+ "transition",
2092
+ "overflow",
2093
+ "position",
2094
+ "z-index"
2095
+ ];
2096
+ const originalStyles = storeOriginalStyles(parentElement, stylesToStore);
2097
+ return new Promise((resolve, reject) => {
2098
+ const cleanup = () => {
2099
+ if (contentSnapshot) {
2100
+ removeContentSnapshot(contentSnapshot);
2101
+ }
2102
+ restoreOriginalStyles(parentElement, originalStyles);
2103
+ };
2104
+ const handleError = (error) => {
2105
+ cleanup();
2106
+ reject(error);
2107
+ };
2108
+ const startTransition = () => {
2109
+ try {
2110
+ applyStyles(parentElement, transitionStyles.exit);
2111
+ parentElement.offsetHeight;
2112
+ applyStyles(parentElement, transitionStyles.exitActive);
2113
+ scheduleTransitionEnd(parentElement, duration / 2, performUpdate);
2114
+ } catch (error) {
2115
+ handleError(error);
2116
+ }
2117
+ };
2118
+ const performUpdate = () => {
2119
+ try {
2120
+ performCoreDomUpdate(input, [node], timeout, Parser).then(() => {
2121
+ applyStyles(parentElement, transitionStyles.enter);
2122
+ parentElement.offsetHeight;
2123
+ applyStyles(parentElement, transitionStyles.enterActive);
2124
+ scheduleTransitionEnd(parentElement, duration / 2, finishTransition);
2125
+ }).catch(handleError);
2126
+ } catch (error) {
2127
+ handleError(error);
2128
+ }
2129
+ };
2130
+ const finishTransition = () => {
2131
+ try {
2132
+ cleanup();
2133
+ resolve(node);
2134
+ } catch (error) {
2135
+ handleError(error);
2136
+ }
2137
+ };
2138
+ scheduleDelayedStep(startTransition, delay);
2139
+ });
2140
+ });
2141
+ await Promise.all(transitionPromises);
2142
+ return nodes;
2143
+ }
2144
+ await performCoreDomUpdate(input, nodes, timeout, Parser);
2145
+ return nodes;
2146
+ }
2147
+
2148
+ const areDomNodesEqual = (oldNode, newNode) => {
2149
+ if (oldNode === newNode) return true;
2150
+ if (oldNode.nodeType !== newNode.nodeType) return false;
2151
+ if (oldNode.nodeType === Node.ELEMENT_NODE) {
2152
+ const oldElement = oldNode;
2153
+ const newElement = newNode;
2154
+ if (oldElement.tagName !== newElement.tagName) return false;
2155
+ const oldAttrs = oldElement.attributes;
2156
+ const newAttrs = newElement.attributes;
2157
+ if (oldAttrs.length !== newAttrs.length) return false;
2158
+ for (let i = 0; i < oldAttrs.length; i++) {
2159
+ const oldAttr = oldAttrs[i];
2160
+ const newAttrValue = newElement.getAttribute(oldAttr.name);
2161
+ if (oldAttr.value !== newAttrValue) return false;
2162
+ }
2163
+ }
2164
+ if (oldNode.nodeType === Node.TEXT_NODE) {
2165
+ if (oldNode.textContent !== newNode.textContent) return false;
2166
+ }
2167
+ return true;
2168
+ };
2169
+ function toValidChild(child) {
2170
+ if (child == null) return child;
2171
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2172
+ return child;
2173
+ }
2174
+ if (typeof child === "object" && "type" in child) {
2175
+ return child;
2176
+ }
2177
+ return void 0;
2178
+ }
2179
+ function areNodeAndChildMatching(domNode, child) {
2180
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2181
+ return domNode.nodeType === Node.TEXT_NODE;
2182
+ } else if (child && typeof child === "object") {
2183
+ if (domNode.nodeType !== Node.ELEMENT_NODE) return false;
2184
+ const oldTag = domNode.tagName.toLowerCase();
2185
+ const newTag = child.type.toLowerCase();
2186
+ return oldTag === newTag;
2187
+ }
2188
+ return false;
2189
+ }
2190
+ function patchDomInPlace(domNode, child, globals) {
2191
+ const renderer = getRenderer(globals.window.document);
2192
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2193
+ const newText = String(child);
2194
+ if (domNode.nodeValue !== newText) {
2195
+ domNode.nodeValue = newText;
2196
+ }
2197
+ return;
2198
+ }
2199
+ if (domNode.nodeType === Node.ELEMENT_NODE && child && typeof child === "object") {
2200
+ const el = domNode;
2201
+ const existingAttrs = Array.from(el.attributes);
2202
+ for (const attr of existingAttrs) {
2203
+ const { name } = attr;
2204
+ if (!Object.prototype.hasOwnProperty.call(child.attributes, name) && name !== "style") {
2205
+ el.removeAttribute(name);
2206
+ }
2207
+ }
2208
+ renderer.setAttributes(child, el);
2209
+ if (child.attributes?.dangerouslySetInnerHTML) {
2210
+ el.innerHTML = child.attributes.dangerouslySetInnerHTML.__html;
2211
+ return;
2212
+ }
2213
+ if (child.children) {
2214
+ updateDomWithVdom(el, child.children, globals);
2215
+ } else {
2216
+ while (el.firstChild) {
2217
+ el.removeChild(el.firstChild);
2218
+ }
2219
+ }
2220
+ }
2221
+ }
2222
+ function createDomFromChild(child, globals) {
2223
+ const renderer = getRenderer(globals.window.document);
2224
+ if (child == null) return void 0;
2225
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2226
+ return globals.window.document.createTextNode(String(child));
2227
+ }
2228
+ let renderResult = renderer.createElementOrElements(child);
2229
+ if (renderResult && !Array.isArray(renderResult)) {
2230
+ renderResult = [renderResult];
2231
+ }
2232
+ return renderResult;
2233
+ }
2234
+ function updateDomWithVdom(parentElement, newVDOM, globals) {
2235
+ let newChildren = [];
2236
+ if (Array.isArray(newVDOM)) {
2237
+ newChildren = newVDOM.map(toValidChild).filter((c) => c !== void 0);
2238
+ } else if (typeof newVDOM === "string" || typeof newVDOM === "number" || typeof newVDOM === "boolean") {
2239
+ newChildren = [newVDOM];
2240
+ } else if (newVDOM) {
2241
+ const child = toValidChild(newVDOM);
2242
+ if (child !== void 0) newChildren = [child];
2243
+ }
2244
+ const newDomArray = newChildren.map(
2245
+ (vdomChild) => createDomFromChild(vdomChild, globals)
2246
+ );
2247
+ const oldNodes = Array.from(parentElement.childNodes);
2248
+ const maxLen = Math.max(oldNodes.length, newDomArray.length);
2249
+ for (let i = 0; i < maxLen; i++) {
2250
+ const oldNode = oldNodes[i];
2251
+ const newDom = newDomArray[i];
2252
+ const newChild = newChildren[i];
2253
+ if (oldNode && newDom !== void 0) {
2254
+ if (Array.isArray(newDom)) {
2255
+ if (newDom.length === 0) {
2256
+ parentElement.removeChild(oldNode);
2257
+ } else {
2258
+ const first = newDom[0];
2259
+ parentElement.replaceChild(first, oldNode);
2260
+ for (let k = 1; k < newDom.length; k++) {
2261
+ if (newDom[k]) {
2262
+ parentElement.insertBefore(newDom[k], first.nextSibling);
2263
+ if (typeof newDom[k] !== "undefined") {
2264
+ handleLifecycleEventsForOnMount(newDom[k]);
2265
+ }
2266
+ }
2267
+ }
2268
+ if (typeof first !== "undefined") {
2269
+ handleLifecycleEventsForOnMount(first);
2270
+ }
2271
+ }
2272
+ } else if (newDom) {
2273
+ if (newChild && areNodeAndChildMatching(oldNode, newChild)) {
2274
+ patchDomInPlace(oldNode, newChild, globals);
2275
+ } else {
2276
+ parentElement.replaceChild(newDom, oldNode);
2277
+ handleLifecycleEventsForOnMount(newDom);
2278
+ }
2279
+ }
2280
+ } else if (!oldNode && newDom !== void 0) {
2281
+ if (Array.isArray(newDom)) {
2282
+ newDom.forEach((newNode) => {
2283
+ const wasAdded = newNode && parentElement.appendChild(newNode);
2284
+ if (wasAdded) {
2285
+ handleLifecycleEventsForOnMount(newNode);
2286
+ }
2287
+ return wasAdded;
2288
+ });
2289
+ } else if (newDom) {
2290
+ parentElement.appendChild(newDom);
2291
+ handleLifecycleEventsForOnMount(newDom);
2292
+ }
2293
+ } else if (oldNode && newDom === void 0) {
2294
+ parentElement.removeChild(oldNode);
2295
+ }
2296
+ }
2297
+ }
2298
+ function replaceDomWithVdom(parentElement, newVDOM, globals) {
2299
+ while (parentElement.firstChild) {
2300
+ parentElement.removeChild(parentElement.firstChild);
2301
+ }
2302
+ const renderer = getRenderer(globals.window.document);
2303
+ const newDom = renderer.createElementOrElements(
2304
+ newVDOM
2305
+ );
2306
+ if (Array.isArray(newDom)) {
2307
+ for (const node of newDom) {
2308
+ if (node) parentElement.appendChild(node);
2309
+ }
2310
+ } else if (newDom) {
2311
+ parentElement.appendChild(newDom);
2312
+ }
2313
+ }
2314
+ async function waitForDOM(check, timeout, document) {
2315
+ const initialResult = check();
2316
+ if (initialResult.length) return initialResult;
2317
+ return createTimeoutPromise(timeout, () => {
2318
+ return new Promise((resolve) => {
2319
+ if (!document) {
2320
+ setTimeout(() => resolve(check()), 0);
2321
+ return;
2322
+ }
2323
+ const observer = new MutationObserver(() => {
2324
+ const result = check();
2325
+ if (result.length) {
2326
+ observer.disconnect();
2327
+ resolve(result);
2328
+ }
2329
+ });
2330
+ observer.observe(document.documentElement, {
2331
+ childList: true,
2332
+ subtree: true,
2333
+ attributes: true
2334
+ });
2335
+ return () => observer.disconnect();
2336
+ });
2337
+ });
2338
+ }
2339
+ function parseDOM(input, type, Parser) {
2340
+ return new Parser().parseFromString(input, type);
2341
+ }
2342
+ function isSVG(input, Parser) {
2343
+ const doc = parseDOM(input, "image/svg+xml", Parser);
2344
+ if (!doc.documentElement) return false;
2345
+ return doc.documentElement.nodeName.toLowerCase() === "svg";
2346
+ }
2347
+ function isHTML(input, Parser) {
2348
+ const doc = parseDOM(input, "text/html", Parser);
2349
+ return doc.documentElement.querySelectorAll("*").length > 2;
2350
+ }
2351
+ const isMarkup = (input, Parser) => input.indexOf("<") > -1 && input.indexOf(">") > -1 && (isHTML(input, Parser) || isSVG(input, Parser));
2352
+ function renderMarkup(markup, Parser, doc) {
2353
+ return Array.from(
2354
+ (doc ? doc : parseDOM(markup, getMimeType(markup, Parser), Parser)).body.childNodes
2355
+ );
2356
+ }
2357
+ function getMimeType(input, Parser) {
2358
+ if (isSVG(input, Parser)) {
2359
+ return "image/svg+xml";
2360
+ }
2361
+ return "text/html";
2362
+ }
2363
+ function processAllFormElements(node, callback) {
2364
+ if (node instanceof Element) {
2365
+ if (node instanceof HTMLFormElement) {
2366
+ Array.from(node.elements).forEach((element) => {
2367
+ if (element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) {
2368
+ const key = element.name || element.id;
2369
+ if (key) {
2370
+ callback(element, key);
2371
+ }
2372
+ }
2373
+ });
2374
+ } else {
2375
+ const inputElements = node.querySelectorAll("input, select, textarea");
2376
+ inputElements.forEach((element) => {
2377
+ if (element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) {
2378
+ const key = element.name || element.id;
2379
+ if (key) {
2380
+ callback(element, key);
2381
+ }
2382
+ }
2383
+ });
2384
+ }
2385
+ }
2386
+ }
2387
+ function checkElementVisibility(element, window, document) {
2388
+ const style = window.getComputedStyle(element);
2389
+ if (!style) return false;
2390
+ if (element.offsetWidth === 0 || element.offsetHeight === 0) return false;
2391
+ if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" || Number.parseFloat(style.opacity) === 0)
2392
+ return false;
2393
+ if (!document.body.contains(element)) return false;
2394
+ let parent = element.parentElement;
2395
+ while (parent) {
2396
+ const parentStyle = window.getComputedStyle(parent);
2397
+ if (parentStyle && (parentStyle.display === "none" || parentStyle.visibility === "hidden" || parentStyle.opacity === "0" || Number.parseFloat(parentStyle.opacity) === 0)) {
2398
+ return false;
2399
+ }
2400
+ parent = parent.parentElement;
2401
+ }
2402
+ return true;
2403
+ }
2404
+ function getEventMap(element) {
2405
+ if (!element._dequeryEvents) {
2406
+ element._dequeryEvents = /* @__PURE__ */ new Map();
2407
+ }
2408
+ return element._dequeryEvents;
2409
+ }
2410
+ function addElementEvent(element, eventType, handler) {
2411
+ const eventMap = getEventMap(element);
2412
+ if (!eventMap.has(eventType)) {
2413
+ eventMap.set(eventType, /* @__PURE__ */ new Set());
2414
+ }
2415
+ eventMap.get(eventType).add(handler);
2416
+ element.addEventListener(eventType, handler);
2417
+ }
2418
+ function removeElementEvent(element, eventType, handler) {
2419
+ const eventMap = getEventMap(element);
2420
+ if (!eventMap.has(eventType)) return;
2421
+ if (handler) {
2422
+ if (eventMap.get(eventType).has(handler)) {
2423
+ element.removeEventListener(eventType, handler);
2424
+ eventMap.get(eventType).delete(handler);
2425
+ if (eventMap.get(eventType).size === 0) {
2426
+ eventMap.delete(eventType);
2427
+ }
2428
+ }
2429
+ } else {
2430
+ eventMap.get(eventType).forEach((h) => {
2431
+ element.removeEventListener(eventType, h);
2432
+ });
2433
+ eventMap.delete(eventType);
2434
+ }
2435
+ }
2436
+ function clearElementEvents(element) {
2437
+ const eventMap = getEventMap(element);
2438
+ eventMap.forEach((handlers, eventType) => {
2439
+ handlers.forEach((handler) => {
2440
+ element.removeEventListener(eventType, handler);
2441
+ });
2442
+ });
2443
+ eventMap.clear();
2444
+ }
2445
+ function domNodeToVNode(node) {
2446
+ if (node.nodeType === Node.TEXT_NODE) {
2447
+ return node.textContent || "";
2448
+ }
2449
+ if (node.nodeType === Node.ELEMENT_NODE) {
2450
+ const element = node;
2451
+ const attributes = {};
2452
+ for (let i = 0; i < element.attributes.length; i++) {
2453
+ const attr = element.attributes[i];
2454
+ attributes[attr.name] = attr.value;
2455
+ }
2456
+ const children = [];
2457
+ for (let i = 0; i < element.childNodes.length; i++) {
2458
+ const childVNode = domNodeToVNode(element.childNodes[i]);
2459
+ children.push(childVNode);
2460
+ }
2461
+ return {
2462
+ type: element.tagName.toLowerCase(),
2463
+ attributes,
2464
+ children
2465
+ };
2466
+ }
2467
+ return "";
2468
+ }
2469
+ function htmlStringToVNodes(html, Parser) {
2470
+ const parser = new Parser();
2471
+ const doc = parser.parseFromString(html, "text/html");
2472
+ const vNodes = [];
2473
+ for (let i = 0; i < doc.body.childNodes.length; i++) {
2474
+ const vnode = domNodeToVNode(doc.body.childNodes[i]);
2475
+ if (vnode !== "") {
2476
+ vNodes.push(vnode);
2477
+ }
2478
+ }
2479
+ return vNodes;
2480
+ }
2481
+
2482
+ export { $, isServer as A, areDomNodesEqual as B, updateDomWithVdom as C, DEFAULT_TRANSITION_CONFIG as D, replaceDomWithVdom as E, Fragment as F, waitForDOM as G, parseDOM as H, isSVG as I, isHTML as J, isMarkup as K, renderMarkup as L, getMimeType as M, processAllFormElements as N, checkElementVisibility as O, getEventMap as P, addElementEvent as Q, removeElementEvent as R, clearElementEvents as S, domNodeToVNode as T, htmlStringToVNodes as U, queueCallback as V, Call as W, addNonChainedReturnCallNames as X, getNonChainedReturnCallNames as Y, isNonChainedReturnCall as Z, emptyImpl as _, renderIsomorphicAsync as a, CallChainImpl as a0, CallChainImplThenable as a1, scrollHelper as a2, getAllFormValues as a3, delayedAutoStart as a4, dequery as a5, isDequery as a6, isDequeryOptionsObject as a7, getDefaultDequeryOptions as a8, mapArrayIndexAccess as a9, createCall as aa, createGetterSetterCall as ab, createSubChain as ac, subChainForNextAwait as ad, runWithTimeGuard as ae, renderNode as af, resolveNodes as ag, traverse as ah, webstorage as ai, globalScopeDomApis as b, createInPlaceErrorMessageVNode as c, jsxs as d, jsxDEV as e, isRef as f, getRenderer as g, handleLifecycleEventsForOnMount as h, isJSX as i, jsx as j, createRef as k, getTransitionStyles as l, applyStyles as m, createContentSnapshot as n, observeUnmount as o, insertContentSnapshot as p, removeContentSnapshot as q, renderIsomorphicSync as r, scheduleTransitionStep as s, scheduleDelayedStep as t, updateDom as u, scheduleTransitionEnd as v, waitForTransition as w, storeOriginalStyles as x, restoreOriginalStyles as y, createStore as z };