defuss 2.0.3 → 2.0.5

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.
@@ -0,0 +1,1977 @@
1
+ import { getByPath, setByPath, pick, omit, createTimeoutPromise, waitForRef } from 'defuss-runtime';
2
+
3
+ const newInMemoryGenericStorageBackend = () => {
4
+ const cache = /* @__PURE__ */ new Map();
5
+ return {
6
+ clear: () => {
7
+ cache.clear();
8
+ },
9
+ getItem: (key) => {
10
+ return cache.get(String(key)) ?? null;
11
+ },
12
+ removeItem: (key) => {
13
+ cache.delete(String(key));
14
+ },
15
+ setItem: (key, value) => {
16
+ cache.set(String(key), value);
17
+ }
18
+ };
19
+ };
20
+ const memory = newInMemoryGenericStorageBackend();
21
+ class WebStorageProvider {
22
+ storage;
23
+ constructor(storage) {
24
+ this.storage = storage || memory;
25
+ }
26
+ get(key, defaultValue, middlewareFn) {
27
+ const rawValue = this.storage.getItem(key);
28
+ if (rawValue === null) return defaultValue;
29
+ let value = JSON.parse(rawValue);
30
+ if (middlewareFn) {
31
+ value = middlewareFn(key, value);
32
+ }
33
+ return value;
34
+ }
35
+ set(key, value, middlewareFn) {
36
+ if (middlewareFn) {
37
+ value = middlewareFn(key, value);
38
+ }
39
+ this.storage.setItem(key, JSON.stringify(value));
40
+ }
41
+ remove(key) {
42
+ this.storage.removeItem(key);
43
+ }
44
+ removeAll() {
45
+ this.storage.clear();
46
+ }
47
+ get backendApi() {
48
+ return this.storage;
49
+ }
50
+ }
51
+
52
+ const getPersistenceProvider$1 = (provider, _options) => {
53
+ switch (provider) {
54
+ case "session":
55
+ return new WebStorageProvider(window.sessionStorage);
56
+ case "local":
57
+ return new WebStorageProvider(window.localStorage);
58
+ }
59
+ return new WebStorageProvider();
60
+ };
61
+
62
+ const getPersistenceProvider = (_provider, _options) => {
63
+ return new WebStorageProvider();
64
+ };
65
+
66
+ const isServer = () => typeof window === "undefined" || typeof window.document === "undefined";
67
+
68
+ const webstorage = (provider = "local", options) => {
69
+ if (isServer()) {
70
+ return getPersistenceProvider();
71
+ } else {
72
+ return getPersistenceProvider$1(provider);
73
+ }
74
+ };
75
+
76
+ const createStore = (initialValue) => {
77
+ let value = initialValue;
78
+ const listeners = [];
79
+ const notify = (oldValue, changedKey) => {
80
+ listeners.forEach((listener) => listener(value, oldValue, changedKey));
81
+ };
82
+ let storage = null;
83
+ let storageKey = null;
84
+ let storageProvider;
85
+ const initStorage = (provider) => {
86
+ if (!storage || storageProvider !== provider) {
87
+ storage = webstorage(provider);
88
+ storageProvider = provider;
89
+ }
90
+ return storage;
91
+ };
92
+ const persistToStorage = () => {
93
+ if (storage && storageKey) {
94
+ storage.set(storageKey, value);
95
+ }
96
+ };
97
+ return {
98
+ // allow reading value but prevent external mutation
99
+ get value() {
100
+ return value;
101
+ },
102
+ persist(key, provider = "local") {
103
+ storage = initStorage(provider);
104
+ storageKey = key;
105
+ persistToStorage();
106
+ },
107
+ restore(key, provider = "local") {
108
+ storage = initStorage(provider);
109
+ storageKey = key;
110
+ const storedValue = storage.get(key, value);
111
+ const valueAsString = JSON.stringify(value);
112
+ const storedValueAsString = JSON.stringify(storedValue);
113
+ if (valueAsString !== storedValueAsString) {
114
+ value = storedValue;
115
+ notify(value);
116
+ }
117
+ },
118
+ get(path) {
119
+ return path ? getByPath(value, path) : value;
120
+ },
121
+ set(pathOrValue, newValue) {
122
+ const oldValue = value;
123
+ if (newValue === void 0) {
124
+ const valueAsString = JSON.stringify(value);
125
+ const newValueAsString = JSON.stringify(pathOrValue);
126
+ if (valueAsString !== newValueAsString) {
127
+ value = pathOrValue;
128
+ notify(oldValue);
129
+ persistToStorage();
130
+ }
131
+ } else {
132
+ const updatedValue = setByPath(value, pathOrValue, newValue);
133
+ const updatedValueAsString = JSON.stringify(updatedValue);
134
+ const oldValueAsString = JSON.stringify(oldValue);
135
+ if (oldValueAsString !== updatedValueAsString) {
136
+ value = updatedValue;
137
+ notify(oldValue, pathOrValue);
138
+ persistToStorage();
139
+ }
140
+ }
141
+ },
142
+ subscribe(listener) {
143
+ listeners.push(listener);
144
+ return () => {
145
+ const index = listeners.indexOf(listener);
146
+ if (index >= 0) listeners.splice(index, 1);
147
+ };
148
+ }
149
+ };
150
+ };
151
+
152
+ const isRef = (obj) => Boolean(obj && typeof obj === "object" && "current" in obj);
153
+ function createRef(refUpdateFn, defaultState) {
154
+ const stateStore = createStore(defaultState);
155
+ const ref = {
156
+ current: null,
157
+ store: stateStore,
158
+ get state() {
159
+ return stateStore.value;
160
+ },
161
+ set state(value) {
162
+ stateStore.set(value);
163
+ },
164
+ persist: (key, provider = "local") => {
165
+ stateStore.persist(key, provider);
166
+ },
167
+ restore: (key, provider = "local") => {
168
+ stateStore.restore(key, provider);
169
+ },
170
+ updateState: (state) => {
171
+ stateStore.set(state);
172
+ },
173
+ update: async (input) => await $(ref.current).update(input),
174
+ subscribe: (refUpdateFn2) => stateStore.subscribe(refUpdateFn2)
175
+ };
176
+ if (typeof refUpdateFn === "function") {
177
+ ref.subscribe(refUpdateFn);
178
+ }
179
+ return ref;
180
+ }
181
+
182
+ class Call {
183
+ name;
184
+ fn;
185
+ args;
186
+ constructor(name, fn, ...args) {
187
+ this.name = name;
188
+ this.fn = fn;
189
+ this.args = args;
190
+ }
191
+ }
192
+ const NonChainedReturnCallNames = [
193
+ "getFirstElement",
194
+ "toArray",
195
+ "map",
196
+ "isHidden",
197
+ "isVisible",
198
+ "hasClass",
199
+ "dimension",
200
+ "position",
201
+ "offset",
202
+ "prop",
203
+ "val",
204
+ "form",
205
+ "attr",
206
+ "data",
207
+ "css",
208
+ "html",
209
+ "serialize"
210
+ ];
211
+ const emptyImpl = async (nodes) => {
212
+ nodes.forEach((el) => {
213
+ const element = el;
214
+ while (element.firstChild) {
215
+ element.firstChild.remove();
216
+ }
217
+ });
218
+ return nodes;
219
+ };
220
+ class CallChainImpl {
221
+ isResolved;
222
+ options;
223
+ elementCreationOptions;
224
+ callStack;
225
+ resultStack;
226
+ stackPointer;
227
+ lastResolvedStackPointer;
228
+ stoppedWithError;
229
+ lastResult;
230
+ length;
231
+ chainStartTime;
232
+ chainAsyncStartTime;
233
+ chainAsyncFinishTime;
234
+ // SSR-ability
235
+ document;
236
+ window;
237
+ performance;
238
+ Parser;
239
+ constructor(options = {}) {
240
+ this.options = {
241
+ ...getDefaultDequeryOptions(),
242
+ ...options
243
+ };
244
+ const optionsKeys = Object.keys(getDefaultDequeryOptions());
245
+ this.options = pick(this.options, optionsKeys);
246
+ this.window = this.options.globals.window;
247
+ this.document = this.options.globals.window.document;
248
+ this.performance = this.options.globals.performance;
249
+ this.Parser = this.options.globals.window.DOMParser;
250
+ const elementCreationOptions = omit(
251
+ options,
252
+ optionsKeys
253
+ );
254
+ this.elementCreationOptions = elementCreationOptions;
255
+ this.callStack = [];
256
+ this.resultStack = options.resultStack ? [options.resultStack] : [];
257
+ this.stackPointer = 0;
258
+ this.lastResolvedStackPointer = 0;
259
+ this.stoppedWithError = null;
260
+ this.lastResult = [];
261
+ this.length = 0;
262
+ this.isResolved = false;
263
+ this.chainStartTime = this.performance.now() ?? 0;
264
+ this.chainAsyncStartTime = 0;
265
+ this.chainAsyncFinishTime = 0;
266
+ }
267
+ get globals() {
268
+ return this.options.globals;
269
+ }
270
+ // sync methods
271
+ // currently selected nodes
272
+ get nodes() {
273
+ return this.resultStack.length > 0 ? this.resultStack[this.resultStack.length - 1] : [];
274
+ }
275
+ // allow for for .. of loop
276
+ [Symbol.iterator]() {
277
+ return this.nodes[Symbol.iterator]();
278
+ }
279
+ // async, direct result method
280
+ getFirstElement() {
281
+ return createCall(
282
+ this,
283
+ "getFirstElement",
284
+ async () => this[0]
285
+ );
286
+ }
287
+ // async, wrapped/chainable API methods
288
+ debug(cb) {
289
+ return createCall(this, "debug", async () => {
290
+ cb(this);
291
+ return this.nodes;
292
+ });
293
+ }
294
+ ref(ref) {
295
+ return createCall(this, "ref", async () => {
296
+ await waitForRef(ref, this.options.timeout);
297
+ if (ref.current) {
298
+ return [ref.current];
299
+ } else {
300
+ throw new Error("Ref is null or undefined");
301
+ }
302
+ });
303
+ }
304
+ query(selector) {
305
+ return createCall(this, "query", async () => {
306
+ return Array.from(
307
+ await waitForDOM(
308
+ () => Array.from(this.document.querySelectorAll(selector) || []),
309
+ this.options.timeout,
310
+ this.document
311
+ )
312
+ );
313
+ });
314
+ }
315
+ next() {
316
+ return traverse(this, "next", (el) => el.nextElementSibling);
317
+ }
318
+ prev() {
319
+ return traverse(this, "prev", (el) => el.previousElementSibling);
320
+ }
321
+ find(selector) {
322
+ return createCall(this, "find", async () => {
323
+ const results = await Promise.all(
324
+ this.nodes.map(async (el) => {
325
+ return await waitForDOM(
326
+ () => Array.from(el.querySelectorAll(selector)),
327
+ this.options.timeout,
328
+ this.document
329
+ );
330
+ })
331
+ );
332
+ return results.flat();
333
+ });
334
+ }
335
+ parent() {
336
+ return traverse(this, "parent", (el) => el.parentElement);
337
+ }
338
+ children() {
339
+ return traverse(this, "children", (el) => Array.from(el.children));
340
+ }
341
+ closest(selector) {
342
+ return traverse(this, "closest", (el) => el.closest(selector));
343
+ }
344
+ first() {
345
+ return createCall(this, "first", async () => {
346
+ return this.nodes.slice(0, 1);
347
+ });
348
+ }
349
+ last() {
350
+ return createCall(this, "last", async () => {
351
+ return this.nodes.slice(-1);
352
+ });
353
+ }
354
+ attr(name, value) {
355
+ return createGetterSetterCall(
356
+ this,
357
+ "attr",
358
+ value,
359
+ // Getter function
360
+ () => {
361
+ if (this.nodes.length === 0) return null;
362
+ return this.nodes[0].getAttribute(name);
363
+ },
364
+ // Setter function
365
+ (val) => {
366
+ this.nodes.forEach((el) => el.setAttribute(name, val));
367
+ }
368
+ );
369
+ }
370
+ prop(name, value) {
371
+ return createGetterSetterCall(
372
+ this,
373
+ "prop",
374
+ value,
375
+ // Getter function
376
+ () => {
377
+ if (this.nodes.length === 0) return void 0;
378
+ return this.nodes[0][name];
379
+ },
380
+ // Setter function
381
+ (val) => {
382
+ this.nodes.forEach((el) => {
383
+ el[name] = val;
384
+ });
385
+ }
386
+ );
387
+ }
388
+ // --- CSS & Class Methods ---
389
+ static resultCache = /* @__PURE__ */ new WeakMap();
390
+ css(prop, value) {
391
+ if (typeof prop === "object") {
392
+ return createCall(this, "css", async () => {
393
+ const elements = this.nodes;
394
+ elements.forEach((el) => {
395
+ const htmlEl = el;
396
+ Object.entries(prop).forEach(([key, val]) => {
397
+ htmlEl.style.setProperty(
398
+ key.replace(/([A-Z])/g, "-$1").toLowerCase(),
399
+ String(val)
400
+ );
401
+ });
402
+ });
403
+ return this.nodes;
404
+ });
405
+ }
406
+ return createGetterSetterCall(
407
+ this,
408
+ "css",
409
+ value,
410
+ // Getter with caching
411
+ () => {
412
+ if (this.nodes.length === 0) return "";
413
+ const el = this.nodes[0];
414
+ const cache = CallChainImpl.resultCache.get(el) || /* @__PURE__ */ new Map();
415
+ const cacheKey = `css:${prop}`;
416
+ if (cache.has(cacheKey)) {
417
+ return cache.get(cacheKey);
418
+ }
419
+ const result = el.style.getPropertyValue(prop);
420
+ cache.set(cacheKey, result);
421
+ CallChainImpl.resultCache.set(el, cache);
422
+ return result;
423
+ },
424
+ // Setter with cache invalidation
425
+ (val) => {
426
+ this.nodes.forEach((el) => {
427
+ el.style.setProperty(prop, String(val));
428
+ const cache = CallChainImpl.resultCache.get(el);
429
+ if (cache) {
430
+ cache.delete(`css:${prop}`);
431
+ }
432
+ });
433
+ }
434
+ );
435
+ }
436
+ addClass(name) {
437
+ return createCall(this, "addClass", async () => {
438
+ const list = Array.isArray(name) ? name : [name];
439
+ this.nodes.forEach((el) => el.classList.add(...list));
440
+ return this.nodes;
441
+ });
442
+ }
443
+ removeClass(name) {
444
+ return createCall(this, "removeClass", async () => {
445
+ const list = Array.isArray(name) ? name : [name];
446
+ this.nodes.forEach((el) => el.classList.remove(...list));
447
+ return this.nodes;
448
+ });
449
+ }
450
+ hasClass(name) {
451
+ return createCall(
452
+ this,
453
+ "hasClass",
454
+ async () => this.nodes.every(
455
+ (el) => el.classList.contains(name)
456
+ )
457
+ );
458
+ }
459
+ toggleClass(name) {
460
+ return createCall(this, "toggleClass", async () => {
461
+ this.nodes.forEach((el) => el.classList.toggle(name));
462
+ return this.nodes;
463
+ });
464
+ }
465
+ animateClass(name, duration) {
466
+ return createCall(this, "animateClass", async () => {
467
+ this.nodes.forEach((el) => {
468
+ const e = el;
469
+ e.classList.add(name);
470
+ setTimeout(() => e.classList.remove(name), duration);
471
+ });
472
+ return this.nodes;
473
+ });
474
+ }
475
+ // --- Content Manipulation Methods ---
476
+ empty() {
477
+ return createCall(
478
+ this,
479
+ "empty",
480
+ async () => emptyImpl(this.nodes)
481
+ );
482
+ }
483
+ html(html) {
484
+ return createGetterSetterCall(
485
+ this,
486
+ "html",
487
+ html,
488
+ () => {
489
+ if (this.nodes.length === 0) return "";
490
+ return this.nodes[0].innerHTML;
491
+ },
492
+ (val) => {
493
+ this.nodes.forEach((el) => {
494
+ el.innerHTML = val;
495
+ });
496
+ }
497
+ );
498
+ }
499
+ jsx(vdom) {
500
+ if (!isJSX(vdom)) {
501
+ throw new Error("Invalid JSX input");
502
+ }
503
+ return createCall(this, "jsx", async () => {
504
+ this.nodes.forEach(
505
+ (el) => updateDomWithVdom(el, vdom, globalThis)
506
+ );
507
+ return this.nodes;
508
+ });
509
+ }
510
+ text(text) {
511
+ return createGetterSetterCall(
512
+ this,
513
+ "text",
514
+ text,
515
+ // Getter function
516
+ () => {
517
+ if (this.nodes.length === 0) return "";
518
+ return this.nodes[0].textContent || "";
519
+ },
520
+ // Setter function
521
+ (val) => {
522
+ this.nodes.forEach((el) => {
523
+ el.textContent = val;
524
+ });
525
+ }
526
+ );
527
+ }
528
+ remove() {
529
+ return createCall(this, "remove", async () => {
530
+ const removedElements = [...this.nodes];
531
+ this.nodes.forEach((el) => el.remove());
532
+ return removedElements;
533
+ });
534
+ }
535
+ replaceWith(content) {
536
+ return createCall(this, "replaceWith", async () => {
537
+ const newElement = await renderNode(content, this);
538
+ if (!newElement) return this.nodes;
539
+ this.nodes.forEach((el, index) => {
540
+ if (!el || !newElement) return;
541
+ if (el.parentNode) {
542
+ const clone = newElement.cloneNode(true);
543
+ el.parentNode.replaceChild(clone, el);
544
+ this.nodes[index] = clone;
545
+ mapArrayIndexAccess(this, this);
546
+ }
547
+ });
548
+ return this.nodes;
549
+ });
550
+ }
551
+ append(content) {
552
+ return createCall(this, "append", async () => {
553
+ if (content == null) {
554
+ return this.nodes;
555
+ }
556
+ if (content instanceof Node) {
557
+ this.nodes.forEach((el) => {
558
+ if (el && content && !el.isEqualNode(content) && el.parentNode !== content) {
559
+ el.appendChild(content);
560
+ }
561
+ });
562
+ return this.nodes;
563
+ }
564
+ const element = await renderNode(content, this);
565
+ if (!element) return this.nodes;
566
+ if (isDequery(content)) {
567
+ this.nodes.forEach((el) => {
568
+ content.nodes.forEach((childEl) => {
569
+ if (childEl.nodeType && el.nodeType && !childEl.isEqualNode(el) && el.parentNode !== childEl) {
570
+ el.appendChild(childEl);
571
+ }
572
+ });
573
+ });
574
+ } else if (typeof content === "string" && isMarkup(content, this.Parser)) {
575
+ const elements = renderMarkup(content, this.Parser);
576
+ this.nodes.forEach((el) => {
577
+ elements.forEach(
578
+ (childEl) => el.appendChild(childEl.cloneNode(true))
579
+ );
580
+ });
581
+ } else {
582
+ this.nodes.forEach((el) => {
583
+ if (!element) return;
584
+ el.appendChild(element.cloneNode(true));
585
+ });
586
+ }
587
+ return this.nodes;
588
+ });
589
+ }
590
+ appendTo(target) {
591
+ return createCall(this, "appendTo", async () => {
592
+ const nodes = await resolveNodes(
593
+ target,
594
+ this.options.timeout,
595
+ this.document
596
+ );
597
+ if (nodes.length === 0) {
598
+ console.warn("appendTo: no target elements found");
599
+ return this.nodes;
600
+ }
601
+ nodes.forEach((node) => {
602
+ this.nodes.forEach((el) => {
603
+ if (!node || !el) return;
604
+ node.appendChild(el.cloneNode(true));
605
+ });
606
+ });
607
+ return this.nodes;
608
+ });
609
+ }
610
+ update(input) {
611
+ return createCall(this, "update", async () => {
612
+ if (isDequery(input)) {
613
+ input = input[0];
614
+ }
615
+ if (input instanceof Node) {
616
+ await emptyImpl(this.nodes);
617
+ for (let i = 0; i < this.nodes.length; i++) {
618
+ const el = this.nodes[i];
619
+ if (!el || !input || el.isEqualNode(input) || el.parentNode === input) {
620
+ continue;
621
+ }
622
+ el.appendChild(input);
623
+ }
624
+ return this.nodes;
625
+ }
626
+ if (typeof input === "string") {
627
+ if (isMarkup(input, this.Parser)) {
628
+ this.nodes.forEach((el) => {
629
+ updateDom(el, input, this.Parser);
630
+ });
631
+ } else {
632
+ this.nodes.forEach((el) => {
633
+ el.textContent = input;
634
+ });
635
+ }
636
+ } else if (isJSX(input)) {
637
+ this.nodes.forEach((el) => {
638
+ updateDomWithVdom(
639
+ el,
640
+ input,
641
+ globalThis
642
+ );
643
+ });
644
+ } else {
645
+ console.warn("update: unsupported content type", input);
646
+ }
647
+ return this.nodes;
648
+ });
649
+ }
650
+ // --- Event Methods ---
651
+ on(event, handler) {
652
+ return createCall(this, "on", async () => {
653
+ this.nodes.forEach((el) => {
654
+ addElementEvent(el, event, handler);
655
+ });
656
+ return this.nodes;
657
+ });
658
+ }
659
+ off(event, handler) {
660
+ return createCall(this, "off", async () => {
661
+ this.nodes.forEach((el) => {
662
+ removeElementEvent(el, event, handler);
663
+ });
664
+ return this.nodes;
665
+ });
666
+ }
667
+ clearEvents() {
668
+ return createCall(this, "clearEvents", async () => {
669
+ this.nodes.forEach((el) => {
670
+ clearElementEvents(el);
671
+ });
672
+ return this.nodes;
673
+ });
674
+ }
675
+ trigger(eventType) {
676
+ return createCall(this, "trigger", async () => {
677
+ this.nodes.forEach(
678
+ (el) => el.dispatchEvent(
679
+ new Event(eventType, { bubbles: true, cancelable: true })
680
+ )
681
+ );
682
+ return this.nodes;
683
+ });
684
+ }
685
+ // --- Position Methods ---
686
+ position() {
687
+ return createCall(
688
+ this,
689
+ "position",
690
+ async () => ({
691
+ top: this.nodes[0].offsetTop,
692
+ left: this.nodes[0].offsetLeft
693
+ })
694
+ );
695
+ }
696
+ offset() {
697
+ return createCall(this, "offset", async () => {
698
+ const el = this.nodes[0];
699
+ const rect = el.getBoundingClientRect();
700
+ return {
701
+ top: rect.top + window.scrollY,
702
+ left: rect.left + window.scrollX
703
+ };
704
+ });
705
+ }
706
+ // --- Data Methods ---
707
+ data(name, value) {
708
+ return createGetterSetterCall(
709
+ this,
710
+ "data",
711
+ value,
712
+ // Getter function
713
+ () => {
714
+ if (this.nodes.length === 0) return void 0;
715
+ return this.nodes[0].dataset[name];
716
+ },
717
+ // Setter function
718
+ (val) => {
719
+ this.nodes.forEach((el) => {
720
+ el.dataset[name] = val;
721
+ });
722
+ }
723
+ );
724
+ }
725
+ val(val) {
726
+ return createGetterSetterCall(
727
+ this,
728
+ "val",
729
+ val,
730
+ // Getter function
731
+ () => {
732
+ if (this.nodes.length === 0) return "";
733
+ const el = this.nodes[0];
734
+ if (el.type === "checkbox") {
735
+ return el.checked;
736
+ }
737
+ return el.value;
738
+ },
739
+ // Setter function
740
+ (value) => {
741
+ this.nodes.forEach((el) => {
742
+ const input = el;
743
+ if (input.type === "checkbox" && typeof value === "boolean") {
744
+ input.checked = value;
745
+ } else {
746
+ input.value = String(value);
747
+ }
748
+ });
749
+ }
750
+ );
751
+ }
752
+ serialize(format = "querystring") {
753
+ const mapValue = (value) => typeof value === "boolean" ? value ? "on" : "off" : value;
754
+ return createCall(this, "serialize", async () => {
755
+ const formData = getAllFormValues(this);
756
+ if (format === "json") {
757
+ return JSON.stringify(formData);
758
+ } else {
759
+ const urlSearchParams = new URLSearchParams();
760
+ const keys = Object.keys(formData);
761
+ keys.forEach((key) => {
762
+ const value = formData[key];
763
+ if (typeof value === "string") {
764
+ urlSearchParams.append(key, value);
765
+ } else if (typeof value === "boolean") {
766
+ urlSearchParams.append(key, mapValue(value));
767
+ } else if (Array.isArray(value)) {
768
+ value.forEach(
769
+ (value2) => urlSearchParams.append(key, mapValue(value2))
770
+ );
771
+ }
772
+ });
773
+ return urlSearchParams.toString();
774
+ }
775
+ });
776
+ }
777
+ form(formData) {
778
+ return createGetterSetterCall(
779
+ this,
780
+ "form",
781
+ formData,
782
+ // Getter function
783
+ () => getAllFormValues(this),
784
+ // Setter function
785
+ (values) => {
786
+ this.nodes.forEach((el) => {
787
+ processAllFormElements(el, (input, key) => {
788
+ if (values[key] !== void 0) {
789
+ if (input.type === "checkbox") {
790
+ input.checked = Boolean(values[key]);
791
+ } else {
792
+ input.value = String(values[key]);
793
+ }
794
+ }
795
+ });
796
+ });
797
+ }
798
+ );
799
+ }
800
+ // --- Dimension Methods ---
801
+ dimension(includeMarginOrPadding, includePaddingIfMarginTrue) {
802
+ return createCall(this, "dimension", async () => {
803
+ if (this.nodes.length === 0) {
804
+ return { width: 0, height: 0 };
805
+ }
806
+ const el = this.nodes[0];
807
+ const style = this.window.getComputedStyle(el);
808
+ if (!style) return { width: 0, height: 0 };
809
+ const rect = el.getBoundingClientRect();
810
+ let width = rect.width;
811
+ let height = rect.height;
812
+ let includeMargin = false;
813
+ let includePadding = true;
814
+ if (includePaddingIfMarginTrue !== void 0) {
815
+ includeMargin = !!includeMarginOrPadding;
816
+ includePadding = !!includePaddingIfMarginTrue;
817
+ } else if (includeMarginOrPadding !== void 0) {
818
+ includePadding = !!includeMarginOrPadding;
819
+ }
820
+ if (!includePadding) {
821
+ const paddingLeft = Number.parseFloat(style.paddingLeft) || 0;
822
+ const paddingRight = Number.parseFloat(style.paddingRight) || 0;
823
+ const paddingTop = Number.parseFloat(style.paddingTop) || 0;
824
+ const paddingBottom = Number.parseFloat(style.paddingBottom) || 0;
825
+ const borderLeft = Number.parseFloat(style.borderLeftWidth) || 0;
826
+ const borderRight = Number.parseFloat(style.borderRightWidth) || 0;
827
+ const borderTop = Number.parseFloat(style.borderTopWidth) || 0;
828
+ const borderBottom = Number.parseFloat(style.borderBottomWidth) || 0;
829
+ width -= paddingLeft + paddingRight + borderLeft + borderRight;
830
+ height -= paddingTop + paddingBottom + borderTop + borderBottom;
831
+ }
832
+ if (includeMargin) {
833
+ const marginLeft = Number.parseFloat(style.marginLeft) || 0;
834
+ const marginRight = Number.parseFloat(style.marginRight) || 0;
835
+ const marginTop = Number.parseFloat(style.marginTop) || 0;
836
+ const marginBottom = Number.parseFloat(style.marginBottom) || 0;
837
+ const baseWidthForOuter = includePadding ? rect.width : width;
838
+ const baseHeightForOuter = includePadding ? rect.height : height;
839
+ const outerWidth = baseWidthForOuter + marginLeft + marginRight;
840
+ const outerHeight = baseHeightForOuter + marginTop + marginBottom;
841
+ return {
842
+ width,
843
+ height,
844
+ outerWidth,
845
+ outerHeight
846
+ };
847
+ }
848
+ return {
849
+ width,
850
+ height
851
+ };
852
+ });
853
+ }
854
+ // --- Visibility Methods ---
855
+ isVisible() {
856
+ return createCall(this, "isVisible", async () => {
857
+ if (this.nodes.length === 0) return false;
858
+ const el = this.nodes[0];
859
+ return checkElementVisibility(el, this.window, this.document);
860
+ });
861
+ }
862
+ isHidden() {
863
+ return createCall(this, "isHidden", async () => {
864
+ if (this.nodes.length === 0) return true;
865
+ const el = this.nodes[0];
866
+ return !checkElementVisibility(el, this.window, this.document);
867
+ });
868
+ }
869
+ // --- Scrolling Methods ---
870
+ scrollTo(xOrOptions, y) {
871
+ return createCall(this, "scrollTo", async () => {
872
+ return scrollHelper("scrollTo", this.nodes, xOrOptions, y);
873
+ });
874
+ }
875
+ scrollBy(xOrOptions, y) {
876
+ return createCall(this, "scrollBy", async () => {
877
+ return scrollHelper("scrollBy", this.nodes, xOrOptions, y);
878
+ });
879
+ }
880
+ scrollIntoView(options) {
881
+ return createCall(this, "scrollIntoView", async () => {
882
+ if (this.nodes.length === 0) return this.nodes;
883
+ this.nodes[0].scrollIntoView(options);
884
+ return this.nodes;
885
+ });
886
+ }
887
+ // --- Transformation Methods ---
888
+ map(cb) {
889
+ return createCall(this, "map", async () => {
890
+ const elements = this.nodes;
891
+ const results = new Array(elements.length);
892
+ for (let i = 0; i < elements.length; i++) {
893
+ results[i] = cb(elements[i], i);
894
+ }
895
+ return results;
896
+ });
897
+ }
898
+ toArray() {
899
+ return createCall(
900
+ this,
901
+ "toArray",
902
+ async () => [...this.nodes]
903
+ );
904
+ }
905
+ filter(selector) {
906
+ return createCall(
907
+ this,
908
+ "filter",
909
+ async () => this.nodes.filter(
910
+ (el) => el instanceof Element && el.matches(selector)
911
+ )
912
+ );
913
+ }
914
+ // --- Cleanup Methods ---
915
+ /** memory cleanup (chain becomes useless after calling this method) */
916
+ dispose() {
917
+ return createCall(this, "dispose", async () => {
918
+ this.nodes.forEach((el) => {
919
+ CallChainImpl.resultCache.delete(el);
920
+ });
921
+ this.callStack.length = 0;
922
+ this.resultStack.length = 0;
923
+ this.stackPointer = 0;
924
+ this.lastResolvedStackPointer = 0;
925
+ return void 0;
926
+ });
927
+ }
928
+ // TODO:
929
+ // - ready (isReady)
930
+ // - deserialize (from URL string, JSON, etc.)
931
+ }
932
+ class CallChainImplThenable extends CallChainImpl {
933
+ constructor(options = {}, isResolved = false) {
934
+ super(options);
935
+ this.isResolved = isResolved;
936
+ }
937
+ // biome-ignore lint/suspicious/noThenProperty: <explanation>
938
+ then(onfulfilled, onrejected) {
939
+ this.chainAsyncStartTime = this.performance.now() ?? 0;
940
+ if (this.stoppedWithError) {
941
+ return Promise.reject(this.stoppedWithError).then(
942
+ onfulfilled,
943
+ onrejected
944
+ );
945
+ }
946
+ if (this.isResolved && this.stackPointer >= this.callStack.length) {
947
+ this.lastResolvedStackPointer = this.stackPointer;
948
+ const lastCallName = this.callStack[this.callStack.length - 1]?.name;
949
+ let result;
950
+ if (NonChainedReturnCallNames.includes(lastCallName)) {
951
+ result = this.lastResult;
952
+ } else {
953
+ result = createSubChain(this, CallChainImpl, true);
954
+ }
955
+ this.chainAsyncFinishTime = (this.performance.now() ?? 0) - this.chainAsyncStartTime;
956
+ return Promise.resolve(result).then(onfulfilled, onrejected);
957
+ }
958
+ return runWithTimeGuard(
959
+ this.options.timeout,
960
+ async () => {
961
+ const startTime = Date.now();
962
+ let call;
963
+ while (this.stackPointer < this.callStack.length) {
964
+ call = this.callStack[this.stackPointer];
965
+ if (Date.now() - startTime > this.options.timeout) {
966
+ throw new Error(`Timeout after ${this.options.timeout}ms`);
967
+ }
968
+ try {
969
+ const callReturnValue = await call.fn.apply(this);
970
+ this.lastResult = callReturnValue;
971
+ if (!NonChainedReturnCallNames.includes(call.name)) {
972
+ this.resultStack.push(callReturnValue);
973
+ }
974
+ if (Array.isArray(this.lastResult)) {
975
+ mapArrayIndexAccess(this, this);
976
+ }
977
+ this.stackPointer++;
978
+ } catch (err) {
979
+ this.stoppedWithError = err;
980
+ throw err;
981
+ }
982
+ }
983
+ this.isResolved = true;
984
+ this.chainAsyncFinishTime = (this.performance.now() ?? 0) - this.chainAsyncStartTime;
985
+ return this;
986
+ },
987
+ [],
988
+ (ms, call) => {
989
+ this.stoppedWithError = new Error(`Timeout after ${ms}ms`);
990
+ }
991
+ ).then((result) => {
992
+ onfulfilled(result);
993
+ return result;
994
+ }).catch(onrejected);
995
+ }
996
+ catch(onrejected) {
997
+ return this.then(void 0, onrejected);
998
+ }
999
+ finally(onfinally) {
1000
+ return this.then(
1001
+ (value) => {
1002
+ onfinally?.();
1003
+ return value;
1004
+ },
1005
+ (reason) => {
1006
+ onfinally?.();
1007
+ throw reason;
1008
+ }
1009
+ );
1010
+ }
1011
+ }
1012
+ function scrollHelper(methodName, elements, xOrOptions, y) {
1013
+ elements.forEach((el) => {
1014
+ const element = el;
1015
+ if (typeof xOrOptions === "object") {
1016
+ element[methodName](xOrOptions);
1017
+ } else if (y !== void 0) {
1018
+ element[methodName](xOrOptions, y);
1019
+ } else {
1020
+ element[methodName](xOrOptions, 0);
1021
+ }
1022
+ });
1023
+ return elements;
1024
+ }
1025
+ function getAllFormValues(chain) {
1026
+ const formFields = {};
1027
+ const mapCheckboxValue = (value) => value === "on" ? true : value;
1028
+ chain.nodes.forEach((el) => {
1029
+ processAllFormElements(el, (input, key) => {
1030
+ if (!key) return;
1031
+ if (input instanceof HTMLInputElement) {
1032
+ if (input.type === "checkbox") {
1033
+ if (input.checked) {
1034
+ const value = mapCheckboxValue(input.value);
1035
+ if (typeof formFields[key] !== "undefined") {
1036
+ formFields[key] = [formFields[key], value];
1037
+ } else if (Array.isArray(formFields[key])) {
1038
+ formFields[key].push(value);
1039
+ } else {
1040
+ formFields[key] = value;
1041
+ }
1042
+ }
1043
+ } else if (input.type === "radio") {
1044
+ if (input.checked) {
1045
+ console.log("input radio value", input.value);
1046
+ formFields[key] = input.value === "on" ? true : input.value;
1047
+ }
1048
+ } else if (input.type === "file") {
1049
+ if (input.files?.length) {
1050
+ const fileNames = Array.from(input.files).map((file) => file.name);
1051
+ formFields[key] = fileNames.length === 1 ? fileNames[0] : fileNames;
1052
+ }
1053
+ } else {
1054
+ formFields[key] = input.value;
1055
+ }
1056
+ } else if (input instanceof HTMLSelectElement) {
1057
+ if (input.multiple) {
1058
+ const values = Array.from(input.selectedOptions).map(
1059
+ (option) => option.value
1060
+ );
1061
+ formFields[key] = values.length === 1 ? values[0] : values;
1062
+ } else {
1063
+ formFields[key] = input.value;
1064
+ }
1065
+ } else if (input instanceof HTMLTextAreaElement) {
1066
+ formFields[key] = input.value;
1067
+ }
1068
+ });
1069
+ });
1070
+ console.log("formFields", formFields);
1071
+ return formFields;
1072
+ }
1073
+ function delayedAutoStart(chain) {
1074
+ if (chain.options.autoStart) {
1075
+ setTimeout(async () => {
1076
+ if (chain.chainAsyncStartTime === 0) {
1077
+ chain = await chain;
1078
+ }
1079
+ }, chain.options.autoStartDelay);
1080
+ }
1081
+ return chain;
1082
+ }
1083
+ function dequery(selectorRefOrEl, options = getDefaultDequeryOptions()) {
1084
+ if (typeof selectorRefOrEl === "function") {
1085
+ const syncChain = dequery("body", options);
1086
+ queueMicrotask(async () => {
1087
+ const result = await selectorRefOrEl();
1088
+ if (!syncChain.isResolved) {
1089
+ if (typeof result !== "undefined") {
1090
+ const newChain = dequery(result, options);
1091
+ syncChain.resultStack = newChain.resultStack;
1092
+ syncChain.lastResult = newChain.lastResult;
1093
+ mapArrayIndexAccess(newChain, syncChain);
1094
+ }
1095
+ }
1096
+ });
1097
+ return delayedAutoStart(syncChain);
1098
+ }
1099
+ const chain = new CallChainImplThenable({
1100
+ ...options,
1101
+ resultStack: []
1102
+ });
1103
+ if (!selectorRefOrEl)
1104
+ throw new Error("dequery: selector/ref/element required");
1105
+ if (typeof selectorRefOrEl === "string") {
1106
+ if (selectorRefOrEl.indexOf("<") === 0) {
1107
+ const elements = renderMarkup(selectorRefOrEl, chain.Parser);
1108
+ const renderRootEl = elements[0];
1109
+ const { text, html, ...attributes } = chain.elementCreationOptions;
1110
+ if (renderRootEl instanceof Element) {
1111
+ Object.entries(attributes).forEach(([key, value]) => {
1112
+ renderRootEl.setAttribute(key, String(value));
1113
+ });
1114
+ if (html) {
1115
+ renderRootEl.innerHTML = html;
1116
+ } else if (text) {
1117
+ renderRootEl.textContent = text;
1118
+ }
1119
+ }
1120
+ chain.resultStack = [elements];
1121
+ return delayedAutoStart(chain);
1122
+ } else {
1123
+ return delayedAutoStart(
1124
+ chain.query(selectorRefOrEl)
1125
+ );
1126
+ }
1127
+ } else if (isRef(selectorRefOrEl)) {
1128
+ return delayedAutoStart(
1129
+ chain.ref(selectorRefOrEl)
1130
+ );
1131
+ } else if (selectorRefOrEl.nodeType) {
1132
+ chain.resultStack = [[selectorRefOrEl]];
1133
+ return delayedAutoStart(chain);
1134
+ } else if (isJSX(selectorRefOrEl)) {
1135
+ const renderResult = renderIsomorphicSync(
1136
+ selectorRefOrEl,
1137
+ chain.document.body,
1138
+ chain.globals
1139
+ );
1140
+ const elements = typeof renderResult !== "undefined" ? Array.isArray(renderResult) ? renderResult : [renderResult] : [];
1141
+ chain.resultStack = [elements];
1142
+ return delayedAutoStart(chain);
1143
+ }
1144
+ throw new Error("Unsupported selectorOrEl type");
1145
+ }
1146
+ dequery.extend = (ExtensionClass) => {
1147
+ const extensionPrototype = ExtensionClass.prototype;
1148
+ const basePrototype = CallChainImpl.prototype;
1149
+ const extensionMethods = Object.getOwnPropertyNames(extensionPrototype);
1150
+ const baseMethods = Object.getOwnPropertyNames(basePrototype);
1151
+ extensionMethods.forEach((methodName) => {
1152
+ if (methodName !== "constructor" && !baseMethods.includes(methodName) && typeof extensionPrototype[methodName] === "function") {
1153
+ CallChainImpl.prototype[methodName] = extensionPrototype[methodName];
1154
+ CallChainImplThenable.prototype[methodName] = extensionPrototype[methodName];
1155
+ }
1156
+ });
1157
+ return (selectorRefOrEl, options) => {
1158
+ return dequery(
1159
+ selectorRefOrEl,
1160
+ options
1161
+ );
1162
+ };
1163
+ };
1164
+ const $ = dequery;
1165
+ function isDequery(obj) {
1166
+ return typeof obj === "object" && obj !== null && "isResolved" in obj && "lastResult" in obj && "resultStack" in obj && "callStack" in obj && "stackPointer" in obj;
1167
+ }
1168
+ function isDequeryOptionsObject(o) {
1169
+ return o && typeof o === "object" && o.timeout !== void 0 && o.globals !== void 0;
1170
+ }
1171
+ let defaultOptions = null;
1172
+ function getDefaultDequeryOptions() {
1173
+ if (!defaultOptions) {
1174
+ defaultOptions = {
1175
+ timeout: 500,
1176
+ // even long sync chains would execute in < .1ms
1177
+ // so after 1ms, we can assume the "await" in front is
1178
+ // missing (intentionally non-blocking in sync code)
1179
+ autoStartDelay: 1,
1180
+ autoStart: true,
1181
+ resultStack: [],
1182
+ globals: {
1183
+ document: globalThis.document,
1184
+ window: globalThis.window,
1185
+ performance: globalThis.performance
1186
+ }
1187
+ };
1188
+ }
1189
+ return { ...defaultOptions };
1190
+ }
1191
+ function mapArrayIndexAccess(source, target) {
1192
+ const elements = source.nodes;
1193
+ for (let i = 0; i < elements.length; i++) {
1194
+ target[i] = elements[i];
1195
+ }
1196
+ target.length = elements.length;
1197
+ }
1198
+ function createCall(chain, methodName, handler) {
1199
+ chain.callStack.push(new Call(methodName, handler));
1200
+ return subChainForNextAwait(chain);
1201
+ }
1202
+ function createGetterSetterCall(chain, methodName, value, getter, setter) {
1203
+ if (value !== void 0) {
1204
+ return createCall(chain, methodName, async () => {
1205
+ setter(value);
1206
+ return chain.nodes;
1207
+ });
1208
+ } else {
1209
+ return createCall(chain, methodName, async () => {
1210
+ return getter();
1211
+ });
1212
+ }
1213
+ }
1214
+ function createSubChain(source, Constructor = CallChainImpl, isResolved = false) {
1215
+ const subChain = new Constructor(source.options);
1216
+ subChain.callStack = source.callStack;
1217
+ subChain.resultStack = source.resultStack;
1218
+ subChain.stackPointer = source.stackPointer;
1219
+ subChain.stoppedWithError = source.stoppedWithError;
1220
+ subChain.lastResult = source.lastResult;
1221
+ subChain.isResolved = typeof isResolved !== "undefined" ? isResolved : source.isResolved;
1222
+ subChain.lastResolvedStackPointer = source.lastResolvedStackPointer;
1223
+ if (Array.isArray(subChain.lastResult)) {
1224
+ mapArrayIndexAccess(source, subChain);
1225
+ }
1226
+ return delayedAutoStart(subChain);
1227
+ }
1228
+ function subChainForNextAwait(source) {
1229
+ if (source.lastResolvedStackPointer) {
1230
+ source.callStack = source.callStack.slice(source.lastResolvedStackPointer);
1231
+ source.stackPointer = source.stackPointer - source.lastResolvedStackPointer;
1232
+ source.resultStack = source.resultStack.slice(
1233
+ source.lastResolvedStackPointer
1234
+ );
1235
+ source.lastResult = source.resultStack[source.resultStack.length - 1] || [];
1236
+ source.lastResolvedStackPointer = 0;
1237
+ source.stoppedWithError = null;
1238
+ }
1239
+ return source instanceof CallChainImplThenable ? source : createSubChain(source, CallChainImplThenable);
1240
+ }
1241
+ function runWithTimeGuard(timeout, fn, args, onError) {
1242
+ return createTimeoutPromise(
1243
+ timeout,
1244
+ () => fn(...args),
1245
+ (ms) => {
1246
+ const fakeCall = new Call("timeout", async () => []);
1247
+ onError(ms, fakeCall);
1248
+ }
1249
+ );
1250
+ }
1251
+ async function renderNode(input, chain) {
1252
+ if (input == null) {
1253
+ return null;
1254
+ }
1255
+ if (typeof input === "string") {
1256
+ if (isMarkup(input, chain.Parser)) {
1257
+ return renderMarkup(input, chain.Parser)[0];
1258
+ } else {
1259
+ return chain.document.createTextNode(input);
1260
+ }
1261
+ } else if (isJSX(input)) {
1262
+ return renderIsomorphicSync(
1263
+ input,
1264
+ chain.document.body,
1265
+ chain.options.globals
1266
+ );
1267
+ } else if (isRef(input)) {
1268
+ await waitForRef(input, chain.options.timeout);
1269
+ return input.current;
1270
+ } else if (input && typeof input === "object" && "nodeType" in input) {
1271
+ return input;
1272
+ } else if (isDequery(input)) {
1273
+ return await input.getFirstElement();
1274
+ }
1275
+ console.warn("resolveContent: unsupported content type", input);
1276
+ return null;
1277
+ }
1278
+ async function resolveNodes(input, timeout, document) {
1279
+ let nodes = [];
1280
+ if (isRef(input)) {
1281
+ await waitForRef(input, timeout);
1282
+ nodes = [input.current];
1283
+ } else if (typeof input === "string" && document) {
1284
+ const result = await waitForDOM(
1285
+ () => {
1286
+ const el2 = document.querySelector(input);
1287
+ if (el2) {
1288
+ return [el2];
1289
+ } else {
1290
+ return [];
1291
+ }
1292
+ },
1293
+ timeout,
1294
+ document
1295
+ );
1296
+ const el = result[0];
1297
+ if (el) nodes = [el];
1298
+ } else if (input && typeof input === "object" && "nodeType" in input) {
1299
+ nodes = [input];
1300
+ } else if (isDequery(input)) {
1301
+ const elements = input.nodes;
1302
+ nodes = elements.filter((el) => el.nodeType !== void 0).map((el) => el);
1303
+ } else {
1304
+ console.warn("resolveTargets: expected selector, ref or node, got", input);
1305
+ }
1306
+ return nodes;
1307
+ }
1308
+ function traverse(chain, methodName, selector) {
1309
+ return createCall(chain, methodName, async () => {
1310
+ return chain.nodes.flatMap((el) => {
1311
+ if (el instanceof Element) {
1312
+ try {
1313
+ const result = selector(el);
1314
+ if (Array.isArray(result)) {
1315
+ return result.filter(
1316
+ (item) => item instanceof Element
1317
+ );
1318
+ } else if (result instanceof Element) {
1319
+ return [result];
1320
+ }
1321
+ } catch (err) {
1322
+ console.warn("Error in traverse selector function:", err);
1323
+ }
1324
+ }
1325
+ return [];
1326
+ });
1327
+ });
1328
+ }
1329
+
1330
+ const CLASS_ATTRIBUTE_NAME = "class";
1331
+ const XLINK_ATTRIBUTE_NAME = "xlink";
1332
+ const XMLNS_ATTRIBUTE_NAME = "xmlns";
1333
+ const REF_ATTRIBUTE_NAME = "ref";
1334
+ const nsMap = {
1335
+ [XMLNS_ATTRIBUTE_NAME]: "http://www.w3.org/2000/xmlns/",
1336
+ [XLINK_ATTRIBUTE_NAME]: "http://www.w3.org/1999/xlink",
1337
+ svg: "http://www.w3.org/2000/svg"
1338
+ };
1339
+ const isJSXComment = (node) => (
1340
+ /* v8 ignore next */
1341
+ node && typeof node === "object" && !node.attributes && !node.type && !node.children
1342
+ );
1343
+ const filterComments = (children) => children.filter((child) => !isJSXComment(child));
1344
+ const createInPlaceErrorMessageVNode = (error) => ({
1345
+ type: "p",
1346
+ attributes: {},
1347
+ children: [`FATAL ERROR: ${error?.message || error}`]
1348
+ });
1349
+ const jsx = (type, attributes, key) => {
1350
+ attributes = { ...attributes };
1351
+ if (typeof key !== "undefined") {
1352
+ attributes.key = key;
1353
+ }
1354
+ let children = (attributes?.children ? [].concat(attributes.children) : []).filter(Boolean);
1355
+ delete attributes?.children;
1356
+ children = filterComments(
1357
+ // Implementation to flatten virtual node children structures like:
1358
+ // [<p>1</p>, [<p>2</p>,<p>3</p>]] to: [<p>1</p>,<p>2</p>,<p>3</p>]
1359
+ [].concat.apply(
1360
+ [],
1361
+ children
1362
+ )
1363
+ );
1364
+ if (type === "fragment") {
1365
+ return filterComments(children);
1366
+ }
1367
+ if (typeof type === "function" && type.constructor.name !== "AsyncFunction") {
1368
+ try {
1369
+ return type({
1370
+ children,
1371
+ ...attributes
1372
+ });
1373
+ } catch (error) {
1374
+ if (typeof error === "string") {
1375
+ error = `[JsxError] in ${type.name}: ${error}`;
1376
+ } else if (error instanceof Error) {
1377
+ error.message = `[JsxError] in ${type.name}: ${error.message}`;
1378
+ }
1379
+ return createInPlaceErrorMessageVNode(error);
1380
+ }
1381
+ }
1382
+ return {
1383
+ type,
1384
+ attributes,
1385
+ children
1386
+ };
1387
+ };
1388
+ const observeUnmount = (domNode, onUnmount) => {
1389
+ if (!domNode || typeof onUnmount !== "function") {
1390
+ throw new Error(
1391
+ "Invalid arguments. Ensure domNode and onUnmount are valid."
1392
+ );
1393
+ }
1394
+ const parentNode = domNode.parentNode;
1395
+ if (!parentNode) {
1396
+ throw new Error("The provided domNode does not have a parentNode.");
1397
+ }
1398
+ const observer = new MutationObserver((mutationsList) => {
1399
+ for (const mutation of mutationsList) {
1400
+ if (mutation.removedNodes.length > 0) {
1401
+ for (const removedNode of mutation.removedNodes) {
1402
+ if (removedNode === domNode) {
1403
+ onUnmount();
1404
+ observer.disconnect();
1405
+ return;
1406
+ }
1407
+ }
1408
+ }
1409
+ }
1410
+ });
1411
+ observer.observe(parentNode, { childList: true });
1412
+ };
1413
+ const handleLifecycleEventsForOnMount = (newEl) => {
1414
+ if (typeof newEl?.$onMount === "function") {
1415
+ newEl.$onMount();
1416
+ newEl.$onMount = null;
1417
+ }
1418
+ if (typeof newEl?.$onUnmount === "function") {
1419
+ observeUnmount(newEl, newEl.$onUnmount);
1420
+ }
1421
+ };
1422
+ const getRenderer = (document) => {
1423
+ const renderer = {
1424
+ hasElNamespace: (domElement) => domElement.namespaceURI === nsMap.svg,
1425
+ hasSvgNamespace: (parentElement, type) => renderer.hasElNamespace(parentElement) && type !== "STYLE" && type !== "SCRIPT",
1426
+ createElementOrElements: (virtualNode, parentDomElement) => {
1427
+ if (Array.isArray(virtualNode)) {
1428
+ return renderer.createChildElements(virtualNode, parentDomElement);
1429
+ }
1430
+ if (typeof virtualNode !== "undefined") {
1431
+ return renderer.createElement(virtualNode, parentDomElement);
1432
+ }
1433
+ return renderer.createTextNode("", parentDomElement);
1434
+ },
1435
+ createElement: (virtualNode, parentDomElement) => {
1436
+ let newEl = void 0;
1437
+ try {
1438
+ if (virtualNode.constructor.name === "AsyncFunction") {
1439
+ newEl = document.createElement("div");
1440
+ } else if (typeof virtualNode.type === "function") {
1441
+ newEl = document.createElement("div");
1442
+ newEl.innerText = `FATAL ERROR: ${virtualNode.type._error}`;
1443
+ } else if (
1444
+ // SVG support
1445
+ virtualNode.type.toUpperCase() === "SVG" || parentDomElement && renderer.hasSvgNamespace(
1446
+ parentDomElement,
1447
+ virtualNode.type.toUpperCase()
1448
+ )
1449
+ ) {
1450
+ newEl = document.createElementNS(
1451
+ nsMap.svg,
1452
+ virtualNode.type
1453
+ );
1454
+ } else {
1455
+ newEl = document.createElement(virtualNode.type);
1456
+ }
1457
+ if (virtualNode.attributes) {
1458
+ renderer.setAttributes(virtualNode, newEl);
1459
+ if (virtualNode.attributes.dangerouslySetInnerHTML) {
1460
+ newEl.innerHTML = virtualNode.attributes.dangerouslySetInnerHTML.__html;
1461
+ }
1462
+ }
1463
+ if (virtualNode.children) {
1464
+ renderer.createChildElements(virtualNode.children, newEl);
1465
+ }
1466
+ if (parentDomElement) {
1467
+ parentDomElement.appendChild(newEl);
1468
+ handleLifecycleEventsForOnMount(newEl);
1469
+ }
1470
+ } catch (e) {
1471
+ console.error(
1472
+ "Fatal error! Error happend while rendering the VDOM!",
1473
+ e,
1474
+ virtualNode
1475
+ );
1476
+ throw e;
1477
+ }
1478
+ return newEl;
1479
+ },
1480
+ createTextNode: (text, domElement) => {
1481
+ const node = document.createTextNode(text.toString());
1482
+ if (domElement) {
1483
+ domElement.appendChild(node);
1484
+ }
1485
+ return node;
1486
+ },
1487
+ createChildElements: (virtualChildren, domElement) => {
1488
+ const children = [];
1489
+ for (let i = 0; i < virtualChildren.length; i++) {
1490
+ const virtualChild = virtualChildren[i];
1491
+ if (virtualChild === null || typeof virtualChild !== "object" && typeof virtualChild !== "function") {
1492
+ children.push(
1493
+ renderer.createTextNode(
1494
+ (typeof virtualChild === "undefined" || virtualChild === null ? "" : virtualChild).toString(),
1495
+ domElement
1496
+ )
1497
+ );
1498
+ } else {
1499
+ children.push(
1500
+ renderer.createElement(virtualChild, domElement)
1501
+ );
1502
+ }
1503
+ }
1504
+ return children;
1505
+ },
1506
+ setAttribute: (name, value, domElement, virtualNode) => {
1507
+ if (typeof value === "undefined") return;
1508
+ if (name === "dangerouslySetInnerHTML") return;
1509
+ if (name === REF_ATTRIBUTE_NAME && typeof value !== "function") {
1510
+ value.current = domElement;
1511
+ return;
1512
+ }
1513
+ if (name.startsWith("on") && typeof value === "function") {
1514
+ let eventName = name.substring(2).toLowerCase();
1515
+ const capturePos = eventName.indexOf("capture");
1516
+ const doCapture = capturePos > -1;
1517
+ if (eventName === "mount") {
1518
+ domElement.$onMount = value;
1519
+ }
1520
+ if (eventName === "unmount") {
1521
+ domElement.$onUnmount = value;
1522
+ }
1523
+ if (doCapture) {
1524
+ eventName = eventName.substring(0, capturePos);
1525
+ }
1526
+ domElement.addEventListener(eventName, value, doCapture);
1527
+ return;
1528
+ }
1529
+ if (name === "className") {
1530
+ name = CLASS_ATTRIBUTE_NAME;
1531
+ }
1532
+ if (name === CLASS_ATTRIBUTE_NAME && Array.isArray(value)) {
1533
+ value = value.join(" ");
1534
+ }
1535
+ const nsEndIndex = name.match(/[A-Z]/)?.index;
1536
+ if (renderer.hasElNamespace(domElement) && nsEndIndex) {
1537
+ const ns = name.substring(0, nsEndIndex).toLowerCase();
1538
+ const attrName = name.substring(nsEndIndex, name.length).toLowerCase();
1539
+ const namespace = nsMap[ns] || null;
1540
+ domElement.setAttributeNS(
1541
+ namespace,
1542
+ ns === XLINK_ATTRIBUTE_NAME || ns === "xmlns" ? `${ns}:${attrName}` : name,
1543
+ value
1544
+ );
1545
+ } else if (name === "style" && typeof value !== "string") {
1546
+ const propNames = Object.keys(value);
1547
+ for (let i = 0; i < propNames.length; i++) {
1548
+ domElement.style[propNames[i]] = value[propNames[i]];
1549
+ }
1550
+ } else if (typeof value === "boolean") {
1551
+ domElement[name] = value;
1552
+ } else {
1553
+ domElement.setAttribute(name, value);
1554
+ }
1555
+ },
1556
+ setAttributes: (virtualNode, domElement) => {
1557
+ const attrNames = Object.keys(virtualNode.attributes);
1558
+ for (let i = 0; i < attrNames.length; i++) {
1559
+ renderer.setAttribute(
1560
+ attrNames[i],
1561
+ virtualNode.attributes[attrNames[i]],
1562
+ domElement,
1563
+ virtualNode
1564
+ );
1565
+ }
1566
+ }
1567
+ };
1568
+ return renderer;
1569
+ };
1570
+ const renderIsomorphicSync = (virtualNode, parentDomElement, globals) => {
1571
+ if (isDequery(parentDomElement)) {
1572
+ parentDomElement = parentDomElement.getFirstElement() || parentDomElement;
1573
+ }
1574
+ let renderResult;
1575
+ if (typeof virtualNode === "string") {
1576
+ renderResult = getRenderer(globals.window.document).createTextNode(
1577
+ virtualNode,
1578
+ parentDomElement
1579
+ );
1580
+ } else {
1581
+ renderResult = getRenderer(globals.window.document).createElementOrElements(
1582
+ virtualNode,
1583
+ parentDomElement
1584
+ );
1585
+ }
1586
+ return renderResult;
1587
+ };
1588
+ const renderIsomorphicAsync = async (virtualNode, parentDomElement, globals) => {
1589
+ if (parentDomElement instanceof Promise) {
1590
+ parentDomElement = await parentDomElement;
1591
+ }
1592
+ if (isDequery(parentDomElement)) {
1593
+ parentDomElement = (await parentDomElement.toArray())[0];
1594
+ }
1595
+ if (virtualNode instanceof Promise) {
1596
+ virtualNode = await virtualNode;
1597
+ }
1598
+ return renderIsomorphicSync(
1599
+ virtualNode,
1600
+ parentDomElement,
1601
+ globals
1602
+ );
1603
+ };
1604
+ const globalScopeDomApis = (window, document) => {
1605
+ globalThis.__defuss_document = document;
1606
+ globalThis.__defuss_window = window;
1607
+ };
1608
+ const isJSX = (o) => {
1609
+ if (o === null || typeof o !== "object") return false;
1610
+ if (Array.isArray(o)) return o.every(isJSX);
1611
+ if (typeof o.type === "string") return true;
1612
+ if (typeof o.type === "function") return true;
1613
+ if (typeof o.attributes === "object" && typeof o.children === "object")
1614
+ return true;
1615
+ return false;
1616
+ };
1617
+ const Fragment = (props) => props.children;
1618
+ const jsxs = jsx;
1619
+ const jsxDEV = (type, attributes, key, allChildrenAreStatic, sourceInfo, selfReference) => {
1620
+ let renderResult;
1621
+ try {
1622
+ renderResult = jsx(type, attributes, key);
1623
+ } catch (error) {
1624
+ console.error(
1625
+ "JSX error:",
1626
+ error,
1627
+ "in",
1628
+ sourceInfo,
1629
+ "component",
1630
+ selfReference
1631
+ );
1632
+ }
1633
+ return renderResult;
1634
+ };
1635
+
1636
+ const areDomNodesEqual = (oldNode, newNode) => {
1637
+ if (oldNode === newNode) return true;
1638
+ if (oldNode.nodeType !== newNode.nodeType) return false;
1639
+ if (oldNode.nodeType === Node.ELEMENT_NODE) {
1640
+ const oldElement = oldNode;
1641
+ const newElement = newNode;
1642
+ if (oldElement.tagName !== newElement.tagName) return false;
1643
+ const oldAttrs = oldElement.attributes;
1644
+ const newAttrs = newElement.attributes;
1645
+ if (oldAttrs.length !== newAttrs.length) return false;
1646
+ for (let i = 0; i < oldAttrs.length; i++) {
1647
+ const oldAttr = oldAttrs[i];
1648
+ const newAttrValue = newElement.getAttribute(oldAttr.name);
1649
+ if (oldAttr.value !== newAttrValue) return false;
1650
+ }
1651
+ }
1652
+ if (oldNode.nodeType === Node.TEXT_NODE) {
1653
+ if (oldNode.textContent !== newNode.textContent) return false;
1654
+ }
1655
+ return true;
1656
+ };
1657
+ const updateNode = (oldNode, newNode) => {
1658
+ if (!areDomNodesEqual(oldNode, newNode)) {
1659
+ oldNode.parentNode?.replaceChild(newNode.cloneNode(true), oldNode);
1660
+ return;
1661
+ }
1662
+ if (oldNode.nodeType === Node.ELEMENT_NODE) {
1663
+ const oldChildren = oldNode.childNodes;
1664
+ const newChildren = newNode.childNodes;
1665
+ const maxLength = Math.max(oldChildren.length, newChildren.length);
1666
+ for (let i = 0; i < maxLength; i++) {
1667
+ const oldChild = oldChildren[i];
1668
+ const newChild = newChildren[i];
1669
+ if (oldChild && newChild) {
1670
+ updateNode(oldChild, newChild);
1671
+ } else if (newChild && !oldChild) {
1672
+ oldNode.appendChild(newChild.cloneNode(true));
1673
+ } else if (oldChild && !newChild) {
1674
+ oldNode.removeChild(oldChild);
1675
+ }
1676
+ }
1677
+ }
1678
+ };
1679
+ const updateDom = (targetElement, newHTML, Parser) => {
1680
+ const parser = new Parser();
1681
+ const doc = parser.parseFromString(newHTML, "text/html");
1682
+ const newNodes = Array.from(doc.body.childNodes);
1683
+ if (newNodes.length === 0) {
1684
+ console.warn("No content found in the new HTML.");
1685
+ return;
1686
+ }
1687
+ for (let i = 0; i < newNodes.length; i++) {
1688
+ const newNode = newNodes[i];
1689
+ const oldNode = targetElement.childNodes[i];
1690
+ if (oldNode) {
1691
+ updateNode(oldNode, newNode);
1692
+ } else {
1693
+ targetElement.appendChild(newNode.cloneNode(true));
1694
+ }
1695
+ }
1696
+ while (targetElement.childNodes.length > newNodes.length) {
1697
+ targetElement.removeChild(targetElement.lastChild);
1698
+ }
1699
+ };
1700
+ function toValidChild(child) {
1701
+ if (child == null) return child;
1702
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
1703
+ return child;
1704
+ }
1705
+ if (typeof child === "object" && "type" in child) {
1706
+ return child;
1707
+ }
1708
+ return void 0;
1709
+ }
1710
+ function areNodeAndChildMatching(domNode, child) {
1711
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
1712
+ return domNode.nodeType === Node.TEXT_NODE;
1713
+ } else if (child && typeof child === "object") {
1714
+ if (domNode.nodeType !== Node.ELEMENT_NODE) return false;
1715
+ const oldTag = domNode.tagName.toLowerCase();
1716
+ const newTag = child.type.toLowerCase();
1717
+ return oldTag === newTag;
1718
+ }
1719
+ return false;
1720
+ }
1721
+ function patchDomInPlace(domNode, child, globals) {
1722
+ const renderer = getRenderer(globals.window.document);
1723
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
1724
+ const newText = String(child);
1725
+ if (domNode.nodeValue !== newText) {
1726
+ domNode.nodeValue = newText;
1727
+ }
1728
+ return;
1729
+ }
1730
+ if (domNode.nodeType === Node.ELEMENT_NODE && child && typeof child === "object") {
1731
+ const el = domNode;
1732
+ const existingAttrs = Array.from(el.attributes);
1733
+ for (const attr of existingAttrs) {
1734
+ const { name } = attr;
1735
+ if (!Object.prototype.hasOwnProperty.call(child.attributes, name) && name !== "style") {
1736
+ el.removeAttribute(name);
1737
+ }
1738
+ }
1739
+ renderer.setAttributes(child, el);
1740
+ if (child.attributes?.dangerouslySetInnerHTML) {
1741
+ el.innerHTML = child.attributes.dangerouslySetInnerHTML.__html;
1742
+ return;
1743
+ }
1744
+ if (child.children) {
1745
+ updateDomWithVdom(el, child.children, globals);
1746
+ } else {
1747
+ while (el.firstChild) {
1748
+ el.removeChild(el.firstChild);
1749
+ }
1750
+ }
1751
+ }
1752
+ }
1753
+ function createDomFromChild(child, globals) {
1754
+ const renderer = getRenderer(globals.window.document);
1755
+ if (child == null) return void 0;
1756
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
1757
+ return globals.window.document.createTextNode(String(child));
1758
+ }
1759
+ let renderResult = renderer.createElementOrElements(child);
1760
+ if (renderResult && !Array.isArray(renderResult)) {
1761
+ renderResult = [renderResult];
1762
+ }
1763
+ return renderResult;
1764
+ }
1765
+ function updateDomWithVdom(parentElement, newVDOM, globals) {
1766
+ let newChildren = [];
1767
+ if (Array.isArray(newVDOM)) {
1768
+ newChildren = newVDOM.map(toValidChild).filter((c) => c !== void 0);
1769
+ } else if (typeof newVDOM === "string" || typeof newVDOM === "number" || typeof newVDOM === "boolean") {
1770
+ newChildren = [newVDOM];
1771
+ } else if (newVDOM) {
1772
+ const child = toValidChild(newVDOM);
1773
+ if (child !== void 0) newChildren = [child];
1774
+ }
1775
+ const newDomArray = newChildren.map(
1776
+ (vdomChild) => createDomFromChild(vdomChild, globals)
1777
+ );
1778
+ const oldNodes = Array.from(parentElement.childNodes);
1779
+ const maxLen = Math.max(oldNodes.length, newDomArray.length);
1780
+ for (let i = 0; i < maxLen; i++) {
1781
+ const oldNode = oldNodes[i];
1782
+ const newDom = newDomArray[i];
1783
+ const newChild = newChildren[i];
1784
+ if (oldNode && newDom !== void 0) {
1785
+ if (Array.isArray(newDom)) {
1786
+ if (newDom.length === 0) {
1787
+ parentElement.removeChild(oldNode);
1788
+ } else {
1789
+ const first = newDom[0];
1790
+ parentElement.replaceChild(first, oldNode);
1791
+ if (typeof first !== "undefined") {
1792
+ handleLifecycleEventsForOnMount(first);
1793
+ }
1794
+ for (let k = 1; k < newDom.length; k++) {
1795
+ if (newDom[k]) {
1796
+ parentElement.insertBefore(newDom[k], first.nextSibling);
1797
+ if (typeof newDom[k] !== "undefined") {
1798
+ handleLifecycleEventsForOnMount(newDom[k]);
1799
+ }
1800
+ }
1801
+ }
1802
+ }
1803
+ } else if (newDom) {
1804
+ if (newChild && areNodeAndChildMatching(oldNode, newChild)) {
1805
+ patchDomInPlace(oldNode, newChild, globals);
1806
+ } else {
1807
+ parentElement.replaceChild(newDom, oldNode);
1808
+ handleLifecycleEventsForOnMount(newDom);
1809
+ }
1810
+ }
1811
+ } else if (!oldNode && newDom !== void 0) {
1812
+ if (Array.isArray(newDom)) {
1813
+ newDom.forEach((newNode) => {
1814
+ const wasAdded = newNode && parentElement.appendChild(newNode);
1815
+ if (wasAdded) {
1816
+ handleLifecycleEventsForOnMount(newNode);
1817
+ }
1818
+ return wasAdded;
1819
+ });
1820
+ } else if (newDom) {
1821
+ parentElement.appendChild(newDom);
1822
+ handleLifecycleEventsForOnMount(newDom);
1823
+ }
1824
+ } else if (oldNode && newDom === void 0) {
1825
+ parentElement.removeChild(oldNode);
1826
+ }
1827
+ }
1828
+ }
1829
+ function replaceDomWithVdom(parentElement, newVDOM, globals) {
1830
+ while (parentElement.firstChild) {
1831
+ parentElement.removeChild(parentElement.firstChild);
1832
+ }
1833
+ const renderer = getRenderer(globals.window.document);
1834
+ const newDom = renderer.createElementOrElements(
1835
+ newVDOM
1836
+ );
1837
+ if (Array.isArray(newDom)) {
1838
+ for (const node of newDom) {
1839
+ if (node) parentElement.appendChild(node);
1840
+ }
1841
+ } else if (newDom) {
1842
+ parentElement.appendChild(newDom);
1843
+ }
1844
+ }
1845
+ async function waitForDOM(check, timeout, document) {
1846
+ const initialResult = check();
1847
+ if (initialResult.length) return initialResult;
1848
+ return createTimeoutPromise(timeout, () => {
1849
+ return new Promise((resolve) => {
1850
+ if (!document) {
1851
+ setTimeout(() => resolve(check()), 0);
1852
+ return;
1853
+ }
1854
+ const observer = new MutationObserver(() => {
1855
+ const result = check();
1856
+ if (result.length) {
1857
+ observer.disconnect();
1858
+ resolve(result);
1859
+ }
1860
+ });
1861
+ observer.observe(document.documentElement, {
1862
+ childList: true,
1863
+ subtree: true,
1864
+ attributes: true
1865
+ });
1866
+ return () => observer.disconnect();
1867
+ });
1868
+ });
1869
+ }
1870
+ function parseDOM(input, type, Parser) {
1871
+ return new Parser().parseFromString(input, type);
1872
+ }
1873
+ function isSVG(input, Parser) {
1874
+ const doc = parseDOM(input, "image/svg+xml", Parser);
1875
+ if (!doc.documentElement) return false;
1876
+ return doc.documentElement.nodeName.toLowerCase() === "svg";
1877
+ }
1878
+ function isHTML(input, Parser) {
1879
+ const doc = parseDOM(input, "text/html", Parser);
1880
+ return doc.documentElement.querySelectorAll("*").length > 2;
1881
+ }
1882
+ const isMarkup = (input, Parser) => input.indexOf("<") > -1 && input.indexOf(">") > -1 && (isHTML(input, Parser) || isSVG(input, Parser));
1883
+ function renderMarkup(markup, Parser, doc) {
1884
+ return Array.from(
1885
+ (doc ? doc : parseDOM(markup, getMimeType(markup, Parser), Parser)).body.childNodes
1886
+ );
1887
+ }
1888
+ function getMimeType(input, Parser) {
1889
+ if (isSVG(input, Parser)) {
1890
+ return "image/svg+xml";
1891
+ }
1892
+ return "text/html";
1893
+ }
1894
+ function processAllFormElements(node, callback) {
1895
+ if (node instanceof Element) {
1896
+ if (node instanceof HTMLFormElement) {
1897
+ Array.from(node.elements).forEach((element) => {
1898
+ if (element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) {
1899
+ const key = element.name || element.id;
1900
+ if (key) {
1901
+ callback(element, key);
1902
+ }
1903
+ }
1904
+ });
1905
+ } else {
1906
+ const inputElements = node.querySelectorAll("input, select, textarea");
1907
+ inputElements.forEach((element) => {
1908
+ if (element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) {
1909
+ const key = element.name || element.id;
1910
+ if (key) {
1911
+ callback(element, key);
1912
+ }
1913
+ }
1914
+ });
1915
+ }
1916
+ }
1917
+ }
1918
+ function checkElementVisibility(element, window, document) {
1919
+ const style = window.getComputedStyle(element);
1920
+ if (!style) return false;
1921
+ if (element.offsetWidth === 0 || element.offsetHeight === 0) return false;
1922
+ if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" || Number.parseFloat(style.opacity) === 0)
1923
+ return false;
1924
+ if (!document.body.contains(element)) return false;
1925
+ let parent = element.parentElement;
1926
+ while (parent) {
1927
+ const parentStyle = window.getComputedStyle(parent);
1928
+ if (parentStyle && (parentStyle.display === "none" || parentStyle.visibility === "hidden" || parentStyle.opacity === "0" || Number.parseFloat(parentStyle.opacity) === 0)) {
1929
+ return false;
1930
+ }
1931
+ parent = parent.parentElement;
1932
+ }
1933
+ return true;
1934
+ }
1935
+ function getEventMap(element) {
1936
+ if (!element._dequeryEvents) {
1937
+ element._dequeryEvents = /* @__PURE__ */ new Map();
1938
+ }
1939
+ return element._dequeryEvents;
1940
+ }
1941
+ function addElementEvent(element, eventType, handler) {
1942
+ const eventMap = getEventMap(element);
1943
+ if (!eventMap.has(eventType)) {
1944
+ eventMap.set(eventType, /* @__PURE__ */ new Set());
1945
+ }
1946
+ eventMap.get(eventType).add(handler);
1947
+ element.addEventListener(eventType, handler);
1948
+ }
1949
+ function removeElementEvent(element, eventType, handler) {
1950
+ const eventMap = getEventMap(element);
1951
+ if (!eventMap.has(eventType)) return;
1952
+ if (handler) {
1953
+ if (eventMap.get(eventType).has(handler)) {
1954
+ element.removeEventListener(eventType, handler);
1955
+ eventMap.get(eventType).delete(handler);
1956
+ if (eventMap.get(eventType).size === 0) {
1957
+ eventMap.delete(eventType);
1958
+ }
1959
+ }
1960
+ } else {
1961
+ eventMap.get(eventType).forEach((h) => {
1962
+ element.removeEventListener(eventType, h);
1963
+ });
1964
+ eventMap.delete(eventType);
1965
+ }
1966
+ }
1967
+ function clearElementEvents(element) {
1968
+ const eventMap = getEventMap(element);
1969
+ eventMap.forEach((handlers, eventType) => {
1970
+ handlers.forEach((handler) => {
1971
+ element.removeEventListener(eventType, handler);
1972
+ });
1973
+ });
1974
+ eventMap.clear();
1975
+ }
1976
+
1977
+ export { $, checkElementVisibility as A, getEventMap as B, addElementEvent as C, removeElementEvent as D, clearElementEvents as E, Fragment as F, Call as G, emptyImpl as H, CallChainImpl as I, CallChainImplThenable as J, scrollHelper as K, getAllFormValues as L, delayedAutoStart as M, NonChainedReturnCallNames as N, dequery as O, isDequery as P, isDequeryOptionsObject as Q, getDefaultDequeryOptions as R, mapArrayIndexAccess as S, createCall as T, createGetterSetterCall as U, createSubChain as V, subChainForNextAwait as W, runWithTimeGuard as X, renderNode as Y, resolveNodes as Z, traverse as _, renderIsomorphicAsync as a, webstorage as a0, globalScopeDomApis as b, createInPlaceErrorMessageVNode as c, jsxs as d, jsxDEV as e, isRef as f, getRenderer as g, handleLifecycleEventsForOnMount as h, isJSX as i, jsx as j, createRef as k, createStore as l, areDomNodesEqual as m, updateDomWithVdom as n, observeUnmount as o, replaceDomWithVdom as p, parseDOM as q, renderIsomorphicSync as r, isSVG as s, isHTML as t, updateDom as u, isMarkup as v, waitForDOM as w, renderMarkup as x, getMimeType as y, processAllFormElements as z };