defuss 2.0.5 → 2.0.7

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