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