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