defuss 2.0.1 → 2.0.3

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