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