defuss 3.2.1 → 3.4.0

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 (63) hide show
  1. package/dist/dom-B-9C61SZ.cjs +2575 -0
  2. package/dist/dom-B07u3Jy8.mjs +2824 -0
  3. package/dist/dom-BB4oELqs.cjs +2913 -0
  4. package/dist/dom-BGydgDUT.cjs +2522 -0
  5. package/dist/dom-BHKkCOeC.mjs +2492 -0
  6. package/dist/dom-BJ6DNN84.cjs +2585 -0
  7. package/dist/dom-BLB_aXSg.mjs +2540 -0
  8. package/dist/dom-BcQDGNER.cjs +2597 -0
  9. package/dist/dom-BcewbaMv.cjs +2623 -0
  10. package/dist/dom-Bmr_Yrhk.cjs +2508 -0
  11. package/dist/dom-BzCNLAR3.cjs +2508 -0
  12. package/dist/dom-C00yT3-P.mjs +2502 -0
  13. package/dist/dom-C85TOhdz.mjs +2439 -0
  14. package/dist/dom-CGQ6W4so.cjs +2617 -0
  15. package/dist/dom-CNuz9a59.mjs +2460 -0
  16. package/dist/dom-CPpNq1y5.mjs +2514 -0
  17. package/dist/dom-C_gMp8Gb.cjs +2629 -0
  18. package/dist/dom-D6BCnlWV.cjs +2533 -0
  19. package/dist/dom-DoTbNGQw.mjs +2425 -0
  20. package/dist/dom-Dtb9ntkd.mjs +2544 -0
  21. package/dist/dom-TG_CZFXn.mjs +2532 -0
  22. package/dist/dom-_VELJIcs.mjs +2425 -0
  23. package/dist/index-BbAz4UnJ.d.ts +1346 -0
  24. package/dist/index-CQF_ouqU.d.ts +1324 -0
  25. package/dist/index-CTOR1BhY.d.ts +1346 -0
  26. package/dist/index.cjs +2 -18
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.mjs +3 -3
  29. package/dist/mount-B1I95Cnc.cjs +29 -0
  30. package/dist/mount-BED_P6fK.cjs +29 -0
  31. package/dist/mount-BKy_CYIL.cjs +29 -0
  32. package/dist/mount-BQlHEvrh.cjs +29 -0
  33. package/dist/mount-BzkAnkiS.cjs +29 -0
  34. package/dist/mount-CDq5FRKR.cjs +29 -0
  35. package/dist/mount-CHc5DzXH.mjs +26 -0
  36. package/dist/mount-CWIEWD2-.mjs +26 -0
  37. package/dist/mount-CcFMMbk-.cjs +29 -0
  38. package/dist/mount-Cp5f2rYC.cjs +29 -0
  39. package/dist/mount-DNkfbJpF.mjs +26 -0
  40. package/dist/mount-DP7SPKxK.mjs +26 -0
  41. package/dist/mount-DWJFcCD1.mjs +26 -0
  42. package/dist/mount-DhCVjXJ8.cjs +29 -0
  43. package/dist/mount-DvMxZoXB.mjs +26 -0
  44. package/dist/mount-FWuAF8K9.mjs +26 -0
  45. package/dist/mount-JuZdCt-y.mjs +26 -0
  46. package/dist/mount-WR8eo8cq.cjs +29 -0
  47. package/dist/mount-WUpdjOeb.mjs +26 -0
  48. package/dist/mount-eqsxARBo.mjs +26 -0
  49. package/dist/mount-kkX1MJ-f.mjs +26 -0
  50. package/dist/mount-oYvkXOMe.cjs +29 -0
  51. package/dist/render/client.cjs +2 -2
  52. package/dist/render/client.d.ts +2 -2
  53. package/dist/render/client.mjs +3 -3
  54. package/dist/render/dev/index.cjs +1 -1
  55. package/dist/render/dev/index.d.ts +1 -1
  56. package/dist/render/dev/index.mjs +1 -1
  57. package/dist/render/index.cjs +2 -2
  58. package/dist/render/index.d.ts +2 -2
  59. package/dist/render/index.mjs +2 -2
  60. package/dist/render/server.cjs +2 -2
  61. package/dist/render/server.d.ts +2 -2
  62. package/dist/render/server.mjs +3 -3
  63. package/package.json +1 -1
@@ -0,0 +1,2575 @@
1
+ 'use strict';
2
+
3
+ var defussRuntime = require('defuss-runtime');
4
+
5
+ const CAPTURE_ONLY_EVENTS = /* @__PURE__ */ new Set([
6
+ "focus",
7
+ "blur",
8
+ "scroll",
9
+ "mouseenter",
10
+ "mouseleave"
11
+ // Note: focusin/focusout DO bubble, so they're not included here
12
+ ]);
13
+ const elementHandlerMap = /* @__PURE__ */ new WeakMap();
14
+ const parseEventPropName = (propName) => {
15
+ if (!propName.startsWith("on")) return null;
16
+ const raw = propName.slice(2);
17
+ if (!raw) return null;
18
+ const lower = raw.toLowerCase();
19
+ const isCapture = lower.endsWith("capture");
20
+ const eventType = isCapture ? lower.slice(0, -"capture".length) : lower;
21
+ if (!eventType) return null;
22
+ return { eventType, capture: isCapture };
23
+ };
24
+ const getOrCreateElementHandlers = (el) => {
25
+ const existing = elementHandlerMap.get(el);
26
+ if (existing) return existing;
27
+ const created = /* @__PURE__ */ new Map();
28
+ elementHandlerMap.set(el, created);
29
+ return created;
30
+ };
31
+ const getEventPath = (event) => {
32
+ const composedPath = event.composedPath?.();
33
+ if (composedPath && composedPath.length > 0) return composedPath;
34
+ const path = [];
35
+ let node = event.target;
36
+ while (node) {
37
+ path.push(node);
38
+ const maybeNode = node;
39
+ if (typeof maybeNode === "object" && maybeNode && "parentNode" in maybeNode) {
40
+ node = maybeNode.parentNode;
41
+ continue;
42
+ }
43
+ break;
44
+ }
45
+ const doc = event.target?.ownerDocument;
46
+ if (doc && path[path.length - 1] !== doc) path.push(doc);
47
+ const win = doc?.defaultView;
48
+ if (win && path[path.length - 1] !== win) path.push(win);
49
+ return path;
50
+ };
51
+ const createPhaseHandler = (eventType, phase) => {
52
+ return (event) => {
53
+ const path = getEventPath(event).filter(
54
+ (t) => typeof t === "object" && t !== null && t.nodeType === 1
55
+ );
56
+ const ordered = phase === "capture" ? [...path].reverse() : path;
57
+ for (const target of ordered) {
58
+ const handlersByEvent = elementHandlerMap.get(target);
59
+ if (!handlersByEvent) continue;
60
+ const entry = handlersByEvent.get(eventType);
61
+ if (!entry) continue;
62
+ if (phase === "capture") {
63
+ if (entry.capture) {
64
+ entry.capture.call(target, event);
65
+ if (event.cancelBubble) return;
66
+ }
67
+ if (entry.captureSet) {
68
+ for (const handler of entry.captureSet) {
69
+ handler.call(target, event);
70
+ if (event.cancelBubble) return;
71
+ }
72
+ }
73
+ } else {
74
+ if (entry.bubble) {
75
+ entry.bubble.call(target, event);
76
+ if (event.cancelBubble) return;
77
+ }
78
+ if (entry.bubbleSet) {
79
+ for (const handler of entry.bubbleSet) {
80
+ handler.call(target, event);
81
+ if (event.cancelBubble) return;
82
+ }
83
+ }
84
+ }
85
+ }
86
+ };
87
+ };
88
+ const installedRootListeners = /* @__PURE__ */ new WeakMap();
89
+ const ensureRootListener = (root, eventType) => {
90
+ const installed = installedRootListeners.get(root) ?? /* @__PURE__ */ new Set();
91
+ installedRootListeners.set(root, installed);
92
+ const captureKey = `${eventType}:capture`;
93
+ if (!installed.has(captureKey)) {
94
+ root.addEventListener(eventType, createPhaseHandler(eventType, "capture"), true);
95
+ installed.add(captureKey);
96
+ }
97
+ const bubbleKey = `${eventType}:bubble`;
98
+ if (!installed.has(bubbleKey)) {
99
+ root.addEventListener(eventType, createPhaseHandler(eventType, "bubble"), false);
100
+ installed.add(bubbleKey);
101
+ }
102
+ };
103
+ const getEventRoot = (element) => {
104
+ const root = element.getRootNode();
105
+ if (root && root.nodeType === 9) {
106
+ return root;
107
+ }
108
+ if (root && root.nodeType === 11 && "host" in root) {
109
+ return root;
110
+ }
111
+ return null;
112
+ };
113
+ const registerDelegatedEvent = (element, eventType, handler, options = {}) => {
114
+ const root = getEventRoot(element);
115
+ const capture = options.capture || CAPTURE_ONLY_EVENTS.has(eventType);
116
+ if (root) {
117
+ ensureRootListener(root, eventType);
118
+ } else if (element.ownerDocument) {
119
+ ensureRootListener(element.ownerDocument, eventType);
120
+ } else {
121
+ element.addEventListener(eventType, handler, capture);
122
+ }
123
+ const byEvent = getOrCreateElementHandlers(element);
124
+ const entry = byEvent.get(eventType) ?? {};
125
+ byEvent.set(eventType, entry);
126
+ if (options.multi) {
127
+ if (capture) {
128
+ if (!entry.captureSet) entry.captureSet = /* @__PURE__ */ new Set();
129
+ entry.captureSet.add(handler);
130
+ } else {
131
+ if (!entry.bubbleSet) entry.bubbleSet = /* @__PURE__ */ new Set();
132
+ entry.bubbleSet.add(handler);
133
+ }
134
+ } else {
135
+ if (capture) {
136
+ entry.capture = handler;
137
+ } else {
138
+ entry.bubble = handler;
139
+ }
140
+ }
141
+ };
142
+ const removeDelegatedEvent = (target, eventType, handler, options = {}) => {
143
+ options.capture || CAPTURE_ONLY_EVENTS.has(eventType);
144
+ const byEvent = elementHandlerMap.get(target);
145
+ if (!byEvent) return;
146
+ const entry = byEvent.get(eventType);
147
+ if (!entry) return;
148
+ if (handler) {
149
+ if (entry.captureSet) {
150
+ entry.captureSet.delete(handler);
151
+ }
152
+ if (entry.bubbleSet) {
153
+ entry.bubbleSet.delete(handler);
154
+ }
155
+ if (entry.capture === handler) {
156
+ entry.capture = void 0;
157
+ }
158
+ if (entry.bubble === handler) {
159
+ entry.bubble = void 0;
160
+ }
161
+ target.removeEventListener(eventType, handler, true);
162
+ target.removeEventListener(eventType, handler, false);
163
+ } else {
164
+ entry.capture = void 0;
165
+ entry.bubble = void 0;
166
+ entry.captureSet = void 0;
167
+ entry.bubbleSet = void 0;
168
+ }
169
+ const isEmpty = !entry.capture && !entry.bubble && (!entry.captureSet || entry.captureSet.size === 0) && (!entry.bubbleSet || entry.bubbleSet.size === 0);
170
+ if (isEmpty) {
171
+ byEvent.delete(eventType);
172
+ }
173
+ };
174
+ const clearDelegatedEvents = (target) => {
175
+ const byEvent = elementHandlerMap.get(target);
176
+ if (!byEvent) return;
177
+ byEvent.clear();
178
+ };
179
+ const clearDelegatedEventsDeep = (root) => {
180
+ clearDelegatedEvents(root);
181
+ const doc = root.ownerDocument;
182
+ if (!doc) return;
183
+ const walker = doc.createTreeWalker(
184
+ root,
185
+ 1
186
+ /* NodeFilter.SHOW_ELEMENT */
187
+ );
188
+ let node = walker.nextNode();
189
+ while (node) {
190
+ clearDelegatedEvents(node);
191
+ node = walker.nextNode();
192
+ }
193
+ };
194
+ const getRegisteredEventTypes = (element) => {
195
+ const byEvent = elementHandlerMap.get(element);
196
+ if (!byEvent) return /* @__PURE__ */ new Set();
197
+ return new Set(byEvent.keys());
198
+ };
199
+ const getRegisteredEventKeys = (element) => {
200
+ const byEvent = elementHandlerMap.get(element);
201
+ if (!byEvent) return /* @__PURE__ */ new Set();
202
+ const keys = /* @__PURE__ */ new Set();
203
+ for (const [eventType, entry] of byEvent) {
204
+ if (entry.bubble || entry.bubbleSet?.size) keys.add(`${eventType}:bubble`);
205
+ if (entry.capture || entry.captureSet?.size) keys.add(`${eventType}:capture`);
206
+ }
207
+ return keys;
208
+ };
209
+ const removeDelegatedEventByKey = (element, eventType, phase) => {
210
+ const byEvent = elementHandlerMap.get(element);
211
+ if (!byEvent) return;
212
+ const entry = byEvent.get(eventType);
213
+ if (!entry) return;
214
+ if (phase === "capture") {
215
+ entry.capture = void 0;
216
+ entry.captureSet = void 0;
217
+ } else {
218
+ entry.bubble = void 0;
219
+ entry.bubbleSet = void 0;
220
+ }
221
+ const isEmpty = !entry.capture && !entry.bubble && (!entry.captureSet || entry.captureSet.size === 0) && (!entry.bubbleSet || entry.bubbleSet.size === 0);
222
+ if (isEmpty) byEvent.delete(eventType);
223
+ };
224
+
225
+ const componentRegistry = /* @__PURE__ */ new WeakMap();
226
+ function isComponentRoot(el) {
227
+ return componentRegistry.has(el);
228
+ }
229
+ function getComponentInstance(el) {
230
+ return componentRegistry.get(el);
231
+ }
232
+ function registerComponent(el, renderFn, props) {
233
+ componentRegistry.set(el, { renderFn, props });
234
+ }
235
+ function unregisterComponent(el) {
236
+ componentRegistry.delete(el);
237
+ }
238
+
239
+ const emptyImpl = (nodes) => {
240
+ nodes.forEach((el) => {
241
+ const element = el;
242
+ const target = element.shadowRoot ?? element;
243
+ while (target.firstChild) {
244
+ const node = target.firstChild;
245
+ if (node instanceof HTMLElement) {
246
+ clearDelegatedEventsDeep(node);
247
+ }
248
+ node.remove();
249
+ }
250
+ });
251
+ return nodes;
252
+ };
253
+ function scrollHelper(methodName, elements, xOrOptions, y) {
254
+ elements.forEach((el) => {
255
+ const element = el;
256
+ if (typeof xOrOptions === "object") {
257
+ element[methodName](xOrOptions);
258
+ } else if (y !== void 0) {
259
+ element[methodName](xOrOptions, y);
260
+ } else {
261
+ element[methodName](xOrOptions, 0);
262
+ }
263
+ });
264
+ return elements;
265
+ }
266
+ function getAllFormValues(chain) {
267
+ const formFields = {};
268
+ const mapCheckboxValue = (value) => value === "on" ? true : value;
269
+ chain.nodes.forEach((el) => {
270
+ processAllFormElements(el, (input, key) => {
271
+ if (!key) return;
272
+ if (input instanceof HTMLInputElement) {
273
+ if (input.type === "checkbox") {
274
+ if (input.checked) {
275
+ const value = mapCheckboxValue(input.value);
276
+ if (typeof formFields[key] !== "undefined") {
277
+ formFields[key] = [formFields[key], value];
278
+ } else if (Array.isArray(formFields[key])) {
279
+ formFields[key].push(value);
280
+ } else {
281
+ formFields[key] = value;
282
+ }
283
+ }
284
+ } else if (input.type === "radio") {
285
+ if (input.checked) {
286
+ formFields[key] = input.value === "on" ? true : input.value;
287
+ }
288
+ } else if (input.type === "file") {
289
+ if (input.files?.length) {
290
+ const fileNames = Array.from(input.files).map((file) => file.name);
291
+ formFields[key] = fileNames.length === 1 ? fileNames[0] : fileNames;
292
+ }
293
+ } else {
294
+ formFields[key] = input.value;
295
+ }
296
+ } else if (input instanceof HTMLSelectElement) {
297
+ if (input.multiple) {
298
+ const values = Array.from(input.selectedOptions).map(
299
+ (option) => option.value
300
+ );
301
+ formFields[key] = values.length === 1 ? values[0] : values;
302
+ } else {
303
+ formFields[key] = input.value;
304
+ }
305
+ } else if (input instanceof HTMLTextAreaElement) {
306
+ formFields[key] = input.value;
307
+ }
308
+ });
309
+ });
310
+ return formFields;
311
+ }
312
+ function renderNodeSync(input, chain) {
313
+ if (input == null) return null;
314
+ if (typeof input === "string") {
315
+ if (isMarkup(input, chain.Parser)) {
316
+ return renderMarkup(input, chain.Parser)[0];
317
+ }
318
+ return chain.document.createTextNode(input);
319
+ }
320
+ if (isJSX(input)) {
321
+ return renderIsomorphicSync(
322
+ input,
323
+ chain.document.body,
324
+ chain.options.globals
325
+ );
326
+ }
327
+ if (isRef(input)) {
328
+ return input.current ?? null;
329
+ }
330
+ if (input && typeof input === "object" && "nodeType" in input) {
331
+ return input;
332
+ }
333
+ if (isDequery(input)) {
334
+ return input._nodes[0] ?? null;
335
+ }
336
+ console.warn("renderNodeSync: unsupported content type", input);
337
+ return null;
338
+ }
339
+ function resolveNodesSync(input, document) {
340
+ if (isRef(input)) {
341
+ const ref = input;
342
+ return ref.current ? [ref.current] : [];
343
+ }
344
+ if (typeof input === "string" && document) {
345
+ const el = document.querySelector(input);
346
+ return el ? [el] : [];
347
+ }
348
+ if (input && typeof input === "object" && "nodeType" in input) {
349
+ return [input];
350
+ }
351
+ if (isDequery(input)) {
352
+ return input._nodes.filter((el) => el.nodeType !== void 0).map((el) => el);
353
+ }
354
+ console.warn("resolveNodesSync: expected selector, ref or node, got", input);
355
+ return [];
356
+ }
357
+ function updateIndexAccess(chain) {
358
+ const elements = chain._nodes;
359
+ for (let i = 0; i < elements.length; i++) {
360
+ chain[i] = elements[i];
361
+ }
362
+ chain.length = elements.length;
363
+ }
364
+ class CallChainImpl {
365
+ options;
366
+ elementCreationOptions;
367
+ _nodes;
368
+ length;
369
+ // SSR-ability
370
+ document;
371
+ window;
372
+ performance;
373
+ Parser;
374
+ // result cache for CSS computed values
375
+ static resultCache = /* @__PURE__ */ new WeakMap();
376
+ constructor(options = {}) {
377
+ this.options = {
378
+ ...getDefaultDequeryOptions(),
379
+ ...options
380
+ };
381
+ const optionsKeys = Object.keys(getDefaultDequeryOptions());
382
+ this.options = defussRuntime.pick(this.options, optionsKeys);
383
+ this.window = this.options.globals.window;
384
+ this.document = this.options.globals.window.document;
385
+ this.performance = this.options.globals.performance;
386
+ this.Parser = this.options.globals.window.DOMParser;
387
+ const elementCreationOptions = defussRuntime.omit(
388
+ options,
389
+ optionsKeys
390
+ );
391
+ this.elementCreationOptions = elementCreationOptions;
392
+ this._nodes = options.resultStack ? [...options.resultStack] : [];
393
+ this.length = this._nodes.length;
394
+ updateIndexAccess(this);
395
+ }
396
+ get globals() {
397
+ return this.options.globals;
398
+ }
399
+ get nodes() {
400
+ return this._nodes;
401
+ }
402
+ [Symbol.iterator]() {
403
+ return this._nodes[Symbol.iterator]();
404
+ }
405
+ // --- Selection & Traversal (all sync) ---
406
+ query(selector) {
407
+ this._nodes = Array.from(this.document.querySelectorAll(selector));
408
+ updateIndexAccess(this);
409
+ return this;
410
+ }
411
+ find(selector) {
412
+ this._nodes = this._nodes.flatMap(
413
+ (el) => Array.from(el.querySelectorAll(selector))
414
+ );
415
+ updateIndexAccess(this);
416
+ return this;
417
+ }
418
+ ref(ref) {
419
+ this._nodes = ref.current ? [ref.current] : [];
420
+ updateIndexAccess(this);
421
+ return this;
422
+ }
423
+ parent() {
424
+ return this._traverse((el) => el.parentElement);
425
+ }
426
+ children() {
427
+ return this._traverse((el) => Array.from(el.children));
428
+ }
429
+ next() {
430
+ return this._traverse((el) => el.nextElementSibling);
431
+ }
432
+ prev() {
433
+ return this._traverse((el) => el.previousElementSibling);
434
+ }
435
+ closest(selector) {
436
+ return this._traverse((el) => el.closest(selector));
437
+ }
438
+ first() {
439
+ this._nodes = this._nodes.slice(0, 1);
440
+ updateIndexAccess(this);
441
+ return this;
442
+ }
443
+ last() {
444
+ this._nodes = this._nodes.slice(-1);
445
+ updateIndexAccess(this);
446
+ return this;
447
+ }
448
+ filter(selector) {
449
+ this._nodes = this._nodes.filter(
450
+ (el) => el instanceof Element && el.matches(selector)
451
+ );
452
+ updateIndexAccess(this);
453
+ return this;
454
+ }
455
+ _traverse(selector) {
456
+ this._nodes = this._nodes.flatMap((el) => {
457
+ if (el instanceof Element) {
458
+ try {
459
+ const result = selector(el);
460
+ if (Array.isArray(result)) {
461
+ return result.filter(
462
+ (item) => item instanceof Element
463
+ );
464
+ }
465
+ if (result instanceof Element) {
466
+ return [result];
467
+ }
468
+ } catch (err) {
469
+ console.warn("Error in traverse selector function:", err);
470
+ }
471
+ }
472
+ return [];
473
+ });
474
+ updateIndexAccess(this);
475
+ return this;
476
+ }
477
+ // --- Direct value methods ---
478
+ getFirstElement() {
479
+ return this[0];
480
+ }
481
+ toArray() {
482
+ return [...this._nodes];
483
+ }
484
+ map(cb) {
485
+ const results = new Array(this._nodes.length);
486
+ for (let i = 0; i < this._nodes.length; i++) {
487
+ results[i] = cb(this._nodes[i], i);
488
+ }
489
+ return results;
490
+ }
491
+ attr(name, value) {
492
+ if (value !== void 0) {
493
+ this._nodes.forEach((el) => {
494
+ el.setAttribute(name, value);
495
+ });
496
+ return this;
497
+ }
498
+ if (this._nodes.length === 0) return null;
499
+ return this._nodes[0].getAttribute(name);
500
+ }
501
+ prop(name, value) {
502
+ if (value !== void 0) {
503
+ this._nodes.forEach((el) => {
504
+ el[name] = value;
505
+ });
506
+ return this;
507
+ }
508
+ if (this._nodes.length === 0) return void 0;
509
+ return this._nodes[0][name];
510
+ }
511
+ css(prop, value) {
512
+ if (typeof prop === "object") {
513
+ this._nodes.forEach((el2) => {
514
+ const htmlEl = el2;
515
+ Object.entries(prop).forEach(([key, val]) => {
516
+ htmlEl.style.setProperty(
517
+ key.replace(/([A-Z])/g, "-$1").toLowerCase(),
518
+ String(val)
519
+ );
520
+ });
521
+ });
522
+ return this;
523
+ }
524
+ if (value !== void 0) {
525
+ this._nodes.forEach((el2) => {
526
+ el2.style.setProperty(prop, String(value));
527
+ const cache2 = CallChainImpl.resultCache.get(el2);
528
+ if (cache2) cache2.delete(`css:${prop}`);
529
+ });
530
+ return this;
531
+ }
532
+ if (this._nodes.length === 0) return "";
533
+ const el = this._nodes[0];
534
+ const cache = CallChainImpl.resultCache.get(el) || /* @__PURE__ */ new Map();
535
+ const cacheKey = `css:${prop}`;
536
+ if (cache.has(cacheKey)) return cache.get(cacheKey);
537
+ const computed = this.window.getComputedStyle(el);
538
+ const result = computed.getPropertyValue(prop);
539
+ cache.set(cacheKey, result);
540
+ CallChainImpl.resultCache.set(el, cache);
541
+ return result;
542
+ }
543
+ addClass(name) {
544
+ const list = Array.isArray(name) ? name : [name];
545
+ this._nodes.forEach((el) => {
546
+ el.classList.add(...list);
547
+ });
548
+ return this;
549
+ }
550
+ removeClass(name) {
551
+ const list = Array.isArray(name) ? name : [name];
552
+ this._nodes.forEach((el) => {
553
+ el.classList.remove(...list);
554
+ });
555
+ return this;
556
+ }
557
+ hasClass(name) {
558
+ return this._nodes.every(
559
+ (el) => el.classList.contains(name)
560
+ );
561
+ }
562
+ toggleClass(name) {
563
+ this._nodes.forEach((el) => {
564
+ el.classList.toggle(name);
565
+ });
566
+ return this;
567
+ }
568
+ animateClass(name, duration) {
569
+ this._nodes.forEach((el) => {
570
+ const e = el;
571
+ e.classList.add(name);
572
+ setTimeout(() => e.classList.remove(name), duration);
573
+ });
574
+ return this;
575
+ }
576
+ // --- Content Manipulation ---
577
+ empty() {
578
+ emptyImpl(this._nodes);
579
+ return this;
580
+ }
581
+ html(html) {
582
+ if (html !== void 0) {
583
+ this._nodes.forEach((el) => {
584
+ el.innerHTML = html;
585
+ });
586
+ return this;
587
+ }
588
+ if (this._nodes.length === 0) return "";
589
+ return this._nodes[0].innerHTML;
590
+ }
591
+ jsx(vdom) {
592
+ if (!isJSX(vdom)) {
593
+ throw new Error("Invalid JSX input");
594
+ }
595
+ this._nodes.forEach((el) => {
596
+ updateDomWithVdom(el, vdom, this.globals);
597
+ });
598
+ return this;
599
+ }
600
+ render(vdom) {
601
+ return this.jsx(vdom);
602
+ }
603
+ text(text) {
604
+ if (text !== void 0) {
605
+ this._nodes.forEach((el) => {
606
+ el.textContent = text;
607
+ });
608
+ return this;
609
+ }
610
+ if (this._nodes.length === 0) return "";
611
+ return this._nodes[0].textContent || "";
612
+ }
613
+ remove() {
614
+ const removedElements = [...this._nodes];
615
+ this._nodes.forEach((el) => {
616
+ el.remove();
617
+ });
618
+ this._nodes = removedElements;
619
+ return this;
620
+ }
621
+ replaceWith(content) {
622
+ const newElements = [];
623
+ const newElement = renderNodeSync(content, this);
624
+ for (let i = 0; i < this._nodes.length; i++) {
625
+ const originalEl = this._nodes[i];
626
+ if (!originalEl?.parentNode) continue;
627
+ if (!newElement) continue;
628
+ const nodeToUse = i === 0 ? newElement : newElement.cloneNode(true);
629
+ originalEl.parentNode.replaceChild(nodeToUse, originalEl);
630
+ newElements.push(nodeToUse);
631
+ }
632
+ this._nodes = newElements;
633
+ updateIndexAccess(this);
634
+ return this;
635
+ }
636
+ append(content) {
637
+ if (content == null) return this;
638
+ if (content instanceof Node) {
639
+ this._nodes.forEach((el, index) => {
640
+ if (el && content && !el.isEqualNode(content) && el.parentNode !== content) {
641
+ const nodeToAppend = index === 0 ? content : content.cloneNode(true);
642
+ el.appendChild(nodeToAppend);
643
+ }
644
+ });
645
+ return this;
646
+ }
647
+ if (isDequery(content)) {
648
+ const children = content._nodes;
649
+ this._nodes.forEach((parent, parentIndex) => {
650
+ children.forEach((child) => {
651
+ if (!child?.nodeType || !parent?.nodeType)
652
+ return;
653
+ if (child.isEqualNode(parent) || parent?.parentNode === child)
654
+ return;
655
+ const nodeToInsert = parentIndex === 0 ? child : child.cloneNode(true);
656
+ parent.appendChild(nodeToInsert);
657
+ });
658
+ });
659
+ return this;
660
+ }
661
+ if (typeof content === "string" && isMarkup(content, this.Parser)) {
662
+ const elements = renderMarkup(content, this.Parser);
663
+ this._nodes.forEach((el, parentIndex) => {
664
+ elements.forEach((childEl) => {
665
+ const node = parentIndex === 0 ? childEl : childEl.cloneNode(true);
666
+ el.appendChild(node);
667
+ });
668
+ });
669
+ return this;
670
+ }
671
+ const element = renderNodeSync(content, this);
672
+ if (!element) return this;
673
+ this._nodes.forEach((el, index) => {
674
+ if (!element) return;
675
+ const nodeToAppend = index === 0 ? element : element.cloneNode(true);
676
+ el.appendChild(nodeToAppend);
677
+ });
678
+ return this;
679
+ }
680
+ appendTo(target) {
681
+ const nodes = resolveNodesSync(target, this.document);
682
+ if (nodes.length === 0) return this;
683
+ nodes.forEach((node) => {
684
+ this._nodes.forEach((el) => {
685
+ if (!node || !el) return;
686
+ node.appendChild(el.cloneNode(true));
687
+ });
688
+ });
689
+ return this;
690
+ }
691
+ /**
692
+ * Updates the DOM content of elements. For transitions, uses fire-and-forget async.
693
+ * Use .jsx() or .render() for simpler JSX rendering.
694
+ */
695
+ update(input, transitionConfig) {
696
+ if (input && typeof input === "object" && !(input instanceof Node) && !isJSX(input) && !isRef(input) && !isDequery(input)) {
697
+ let didImplicitUpdate = false;
698
+ for (const node of this._nodes) {
699
+ if (!(node instanceof Element)) continue;
700
+ const instance = getComponentInstance(node);
701
+ if (!instance) continue;
702
+ Object.assign(instance.props, input);
703
+ const newVNode = instance.renderFn(instance.props);
704
+ updateDomWithVdom(
705
+ node,
706
+ newVNode,
707
+ this.globals
708
+ );
709
+ instance.prevVNode = newVNode;
710
+ didImplicitUpdate = true;
711
+ }
712
+ if (didImplicitUpdate) return this;
713
+ }
714
+ if (transitionConfig && transitionConfig.type !== "none") {
715
+ updateDom(
716
+ input,
717
+ this._nodes,
718
+ this.options.timeout,
719
+ this.Parser,
720
+ transitionConfig
721
+ );
722
+ return this;
723
+ }
724
+ let processedInput = input;
725
+ if (isDequery(processedInput)) {
726
+ processedInput = processedInput[0];
727
+ }
728
+ if (isRef(processedInput)) {
729
+ processedInput = processedInput.current;
730
+ }
731
+ const getGlobalsFromElement = (el) => {
732
+ const win = el.ownerDocument?.defaultView;
733
+ return win ?? globalThis;
734
+ };
735
+ const nodes = this._nodes;
736
+ if (typeof processedInput === "object" && processedInput !== null && "nodeType" in processedInput && typeof processedInput.nodeType === "number" && processedInput instanceof Node) {
737
+ const vnode = domNodeToVNode(processedInput);
738
+ nodes.forEach((el) => {
739
+ if (el)
740
+ updateDomWithVdom(
741
+ el,
742
+ vnode,
743
+ getGlobalsFromElement(el)
744
+ );
745
+ });
746
+ return this;
747
+ }
748
+ if (typeof processedInput === "string") {
749
+ if (isMarkup(processedInput, this.Parser)) {
750
+ const vNodes = htmlStringToVNodes(processedInput, this.Parser);
751
+ nodes.forEach((el) => {
752
+ if (el)
753
+ updateDomWithVdom(
754
+ el,
755
+ vNodes,
756
+ getGlobalsFromElement(el)
757
+ );
758
+ });
759
+ } else {
760
+ nodes.forEach((el) => {
761
+ if (el) {
762
+ updateDomWithVdom(
763
+ el,
764
+ processedInput,
765
+ getGlobalsFromElement(el)
766
+ );
767
+ }
768
+ });
769
+ }
770
+ } else if (isJSX(processedInput)) {
771
+ nodes.forEach((el) => {
772
+ if (el) {
773
+ updateDomWithVdom(
774
+ el,
775
+ processedInput,
776
+ getGlobalsFromElement(el)
777
+ );
778
+ }
779
+ });
780
+ } else if (processedInput != null) {
781
+ console.warn("update: unsupported content type", processedInput);
782
+ }
783
+ return this;
784
+ }
785
+ on(event, handler) {
786
+ this._nodes.forEach((el) => {
787
+ if (el && typeof el.addEventListener === "function") {
788
+ addElementEvent(el, event, handler);
789
+ }
790
+ });
791
+ return this;
792
+ }
793
+ off(event, handler) {
794
+ this._nodes.forEach((el) => {
795
+ removeElementEvent(el, event, handler);
796
+ });
797
+ return this;
798
+ }
799
+ clearEvents() {
800
+ this._nodes.forEach((el) => {
801
+ clearElementEvents(el);
802
+ });
803
+ return this;
804
+ }
805
+ trigger(eventType) {
806
+ this._nodes.forEach((el) => {
807
+ el.dispatchEvent(
808
+ new Event(eventType, { bubbles: true, cancelable: true })
809
+ );
810
+ });
811
+ return this;
812
+ }
813
+ // --- Position Methods ---
814
+ position() {
815
+ return {
816
+ top: this._nodes[0]?.offsetTop ?? 0,
817
+ left: this._nodes[0]?.offsetLeft ?? 0
818
+ };
819
+ }
820
+ offset() {
821
+ if (this._nodes.length === 0) return { top: 0, left: 0 };
822
+ const el = this._nodes[0];
823
+ const rect = el.getBoundingClientRect();
824
+ return {
825
+ top: rect.top + (this.window.scrollY ?? 0),
826
+ left: rect.left + (this.window.scrollX ?? 0)
827
+ };
828
+ }
829
+ data(name, value) {
830
+ if (value !== void 0) {
831
+ this._nodes.forEach((el) => {
832
+ el.dataset[name] = value;
833
+ });
834
+ return this;
835
+ }
836
+ if (this._nodes.length === 0) return void 0;
837
+ return this._nodes[0].dataset[name];
838
+ }
839
+ val(val) {
840
+ if (val !== void 0) {
841
+ this._nodes.forEach((el2) => {
842
+ const input = el2;
843
+ if (input.type === "checkbox" && typeof val === "boolean") {
844
+ input.checked = val;
845
+ } else {
846
+ input.value = String(val);
847
+ }
848
+ });
849
+ return this;
850
+ }
851
+ if (this._nodes.length === 0) return "";
852
+ const el = this._nodes[0];
853
+ if (el.type === "checkbox") return el.checked;
854
+ return el.value;
855
+ }
856
+ serialize(format = "querystring") {
857
+ const mapValue = (value) => typeof value === "boolean" ? value ? "on" : "off" : value;
858
+ const formData = getAllFormValues(this);
859
+ if (format === "json") return JSON.stringify(formData);
860
+ const urlSearchParams = new URLSearchParams();
861
+ Object.keys(formData).forEach((key) => {
862
+ const value = formData[key];
863
+ if (typeof value === "string") {
864
+ urlSearchParams.append(key, value);
865
+ } else if (typeof value === "boolean") {
866
+ urlSearchParams.append(key, mapValue(value));
867
+ } else if (Array.isArray(value)) {
868
+ value.forEach((v) => {
869
+ urlSearchParams.append(key, mapValue(v));
870
+ });
871
+ }
872
+ });
873
+ return urlSearchParams.toString();
874
+ }
875
+ form(formData) {
876
+ if (formData !== void 0) {
877
+ this._nodes.forEach((el) => {
878
+ processAllFormElements(el, (input, key) => {
879
+ if (formData[key] !== void 0) {
880
+ if (input.type === "checkbox") {
881
+ input.checked = Boolean(formData[key]);
882
+ } else {
883
+ input.value = String(formData[key]);
884
+ }
885
+ }
886
+ });
887
+ });
888
+ return this;
889
+ }
890
+ return getAllFormValues(this);
891
+ }
892
+ // --- Dimension Methods ---
893
+ dimension(includeMarginOrPadding, includePaddingIfMarginTrue) {
894
+ if (this._nodes.length === 0) return { width: 0, height: 0 };
895
+ const el = this._nodes[0];
896
+ const style = this.window.getComputedStyle(el);
897
+ if (!style) return { width: 0, height: 0 };
898
+ const rect = el.getBoundingClientRect();
899
+ let width = rect.width;
900
+ let height = rect.height;
901
+ let includeMargin = false;
902
+ let includePadding = true;
903
+ if (includePaddingIfMarginTrue !== void 0) {
904
+ includeMargin = !!includeMarginOrPadding;
905
+ includePadding = !!includePaddingIfMarginTrue;
906
+ } else if (includeMarginOrPadding !== void 0) {
907
+ includePadding = !!includeMarginOrPadding;
908
+ }
909
+ if (!includePadding) {
910
+ const paddingLeft = Number.parseFloat(style.paddingLeft) || 0;
911
+ const paddingRight = Number.parseFloat(style.paddingRight) || 0;
912
+ const paddingTop = Number.parseFloat(style.paddingTop) || 0;
913
+ const paddingBottom = Number.parseFloat(style.paddingBottom) || 0;
914
+ const borderLeft = Number.parseFloat(style.borderLeftWidth) || 0;
915
+ const borderRight = Number.parseFloat(style.borderRightWidth) || 0;
916
+ const borderTop = Number.parseFloat(style.borderTopWidth) || 0;
917
+ const borderBottom = Number.parseFloat(style.borderBottomWidth) || 0;
918
+ width -= paddingLeft + paddingRight + borderLeft + borderRight;
919
+ height -= paddingTop + paddingBottom + borderTop + borderBottom;
920
+ }
921
+ if (includeMargin) {
922
+ const marginLeft = Number.parseFloat(style.marginLeft) || 0;
923
+ const marginRight = Number.parseFloat(style.marginRight) || 0;
924
+ const marginTop = Number.parseFloat(style.marginTop) || 0;
925
+ const marginBottom = Number.parseFloat(style.marginBottom) || 0;
926
+ const baseWidthForOuter = includePadding ? rect.width : width;
927
+ const baseHeightForOuter = includePadding ? rect.height : height;
928
+ return {
929
+ width,
930
+ height,
931
+ outerWidth: baseWidthForOuter + marginLeft + marginRight,
932
+ outerHeight: baseHeightForOuter + marginTop + marginBottom
933
+ };
934
+ }
935
+ return { width, height };
936
+ }
937
+ // --- Visibility Methods ---
938
+ isVisible() {
939
+ if (this._nodes.length === 0) return false;
940
+ return checkElementVisibility(
941
+ this._nodes[0],
942
+ this.window,
943
+ this.document
944
+ );
945
+ }
946
+ isHidden() {
947
+ if (this._nodes.length === 0) return true;
948
+ return !checkElementVisibility(
949
+ this._nodes[0],
950
+ this.window,
951
+ this.document
952
+ );
953
+ }
954
+ // --- Scrolling Methods ---
955
+ scrollTo(xOrOptions, y) {
956
+ scrollHelper(
957
+ "scrollTo",
958
+ this._nodes,
959
+ xOrOptions,
960
+ y
961
+ );
962
+ return this;
963
+ }
964
+ scrollBy(xOrOptions, y) {
965
+ scrollHelper(
966
+ "scrollBy",
967
+ this._nodes,
968
+ xOrOptions,
969
+ y
970
+ );
971
+ return this;
972
+ }
973
+ scrollIntoView(options) {
974
+ if (this._nodes.length > 0) {
975
+ this._nodes[0].scrollIntoView(options);
976
+ }
977
+ return this;
978
+ }
979
+ // --- Debug ---
980
+ debug(cb) {
981
+ cb(this);
982
+ return this;
983
+ }
984
+ // --- Cleanup ---
985
+ dispose() {
986
+ this._nodes.forEach((el) => {
987
+ CallChainImpl.resultCache.delete(el);
988
+ });
989
+ this._nodes.length = 0;
990
+ this.length = 0;
991
+ }
992
+ // --- Ready ---
993
+ ready(callback) {
994
+ if (this.document.readyState === "complete" || this.document.readyState === "interactive") {
995
+ if (callback) callback();
996
+ } else {
997
+ const doc = this.document;
998
+ const handleDOMContentLoaded = () => {
999
+ doc.removeEventListener("DOMContentLoaded", handleDOMContentLoaded);
1000
+ if (callback) callback();
1001
+ };
1002
+ doc.addEventListener("DOMContentLoaded", handleDOMContentLoaded);
1003
+ }
1004
+ return this;
1005
+ }
1006
+ }
1007
+ function dequery(selectorRefOrEl, options = getDefaultDequeryOptions()) {
1008
+ if (typeof selectorRefOrEl === "function") {
1009
+ const result = selectorRefOrEl();
1010
+ if (typeof result !== "undefined") {
1011
+ return dequery(result, options);
1012
+ }
1013
+ return dequery("body", options);
1014
+ }
1015
+ const chain = new CallChainImpl({
1016
+ ...options,
1017
+ resultStack: []
1018
+ });
1019
+ if (!selectorRefOrEl)
1020
+ throw new Error("dequery: selector/ref/element required");
1021
+ if (typeof selectorRefOrEl === "string") {
1022
+ if (selectorRefOrEl.indexOf("<") === 0) {
1023
+ const elements = renderMarkup(selectorRefOrEl, chain.Parser);
1024
+ const renderRootEl = elements[0];
1025
+ const { text, html, ...attributes } = chain.elementCreationOptions;
1026
+ if (renderRootEl instanceof Element) {
1027
+ Object.entries(attributes).forEach(([key, value]) => {
1028
+ renderRootEl.setAttribute(key, String(value));
1029
+ });
1030
+ if (html) {
1031
+ renderRootEl.innerHTML = html;
1032
+ } else if (text) {
1033
+ renderRootEl.textContent = text;
1034
+ }
1035
+ }
1036
+ chain._nodes = elements;
1037
+ updateIndexAccess(chain);
1038
+ return chain;
1039
+ }
1040
+ chain.query(selectorRefOrEl);
1041
+ return chain;
1042
+ }
1043
+ if (isRef(selectorRefOrEl)) {
1044
+ chain.ref(selectorRefOrEl);
1045
+ return chain;
1046
+ }
1047
+ if (selectorRefOrEl.nodeType) {
1048
+ chain._nodes = [selectorRefOrEl];
1049
+ updateIndexAccess(chain);
1050
+ return chain;
1051
+ }
1052
+ if (isJSX(selectorRefOrEl)) {
1053
+ const renderResult = renderIsomorphicSync(
1054
+ selectorRefOrEl,
1055
+ chain.document.body,
1056
+ chain.globals
1057
+ );
1058
+ const elements = typeof renderResult !== "undefined" ? Array.isArray(renderResult) ? renderResult : [renderResult] : [];
1059
+ chain._nodes = elements;
1060
+ updateIndexAccess(chain);
1061
+ return chain;
1062
+ }
1063
+ throw new Error("Unsupported selectorOrEl type");
1064
+ }
1065
+ dequery.extend = (ExtensionClass, nonChainedReturnCalls = []) => {
1066
+ const extensionPrototype = ExtensionClass.prototype;
1067
+ const basePrototype = CallChainImpl.prototype;
1068
+ const extensionMethods = Object.getOwnPropertyNames(extensionPrototype);
1069
+ const baseMethods = Object.getOwnPropertyNames(basePrototype);
1070
+ extensionMethods.forEach((methodName) => {
1071
+ if (methodName !== "constructor" && !baseMethods.includes(methodName) && typeof extensionPrototype[methodName] === "function") {
1072
+ CallChainImpl.prototype[methodName] = extensionPrototype[methodName];
1073
+ }
1074
+ });
1075
+ return (selectorRefOrEl, options) => {
1076
+ return dequery(
1077
+ selectorRefOrEl,
1078
+ options
1079
+ );
1080
+ };
1081
+ };
1082
+ const $ = dequery;
1083
+ function isDequery(obj) {
1084
+ return typeof obj === "object" && obj !== null && obj instanceof CallChainImpl;
1085
+ }
1086
+ function isDequeryOptionsObject(o) {
1087
+ return o && typeof o === "object" && o.globals !== void 0;
1088
+ }
1089
+ let defaultOptions = null;
1090
+ function getDefaultDequeryOptions() {
1091
+ if (!defaultOptions) {
1092
+ defaultOptions = {
1093
+ timeout: 5e3,
1094
+ resultStack: [],
1095
+ globals: {
1096
+ document: globalThis.document,
1097
+ window: globalThis.window,
1098
+ performance: globalThis.performance
1099
+ }
1100
+ };
1101
+ }
1102
+ return { ...defaultOptions };
1103
+ }
1104
+ const CallChainImplThenable = CallChainImpl;
1105
+ function createCall(chain, methodName, handler, ...callArgs) {
1106
+ const result = handler();
1107
+ if (Array.isArray(result)) {
1108
+ chain._nodes = result;
1109
+ updateIndexAccess(chain);
1110
+ }
1111
+ return chain;
1112
+ }
1113
+ function createSyncCall(chain, methodName, handler, ...callArgs) {
1114
+ const result = handler();
1115
+ if (Array.isArray(result)) {
1116
+ chain._nodes = result;
1117
+ updateIndexAccess(chain);
1118
+ }
1119
+ return chain;
1120
+ }
1121
+ function mapArrayIndexAccess(source, target) {
1122
+ const elements = source._nodes;
1123
+ for (let i = 0; i < elements.length; i++) {
1124
+ target[i] = elements[i];
1125
+ }
1126
+ target.length = elements.length;
1127
+ }
1128
+ function addNonChainedReturnCallNames(_callNames) {
1129
+ }
1130
+ function getNonChainedReturnCallNames() {
1131
+ return [];
1132
+ }
1133
+ function isNonChainedReturnCall(_callName) {
1134
+ return false;
1135
+ }
1136
+ const renderNode = renderNodeSync;
1137
+ const resolveNodes = resolveNodesSync;
1138
+ function traverse(chain, _methodName, selector) {
1139
+ chain._nodes = chain._nodes.flatMap((el) => {
1140
+ if (el instanceof Element) {
1141
+ try {
1142
+ const result = selector(el);
1143
+ if (Array.isArray(result)) {
1144
+ return result.filter(
1145
+ (item) => item instanceof Element
1146
+ );
1147
+ }
1148
+ if (result instanceof Element) return [result];
1149
+ } catch (err) {
1150
+ console.warn("Error in traverse selector function:", err);
1151
+ }
1152
+ }
1153
+ return [];
1154
+ });
1155
+ updateIndexAccess(chain);
1156
+ return chain;
1157
+ }
1158
+
1159
+ const newInMemoryGenericStorageBackend = () => {
1160
+ const cache = /* @__PURE__ */ new Map();
1161
+ return {
1162
+ clear: () => {
1163
+ cache.clear();
1164
+ },
1165
+ getItem: (key) => {
1166
+ return cache.get(String(key)) ?? null;
1167
+ },
1168
+ removeItem: (key) => {
1169
+ cache.delete(String(key));
1170
+ },
1171
+ setItem: (key, value) => {
1172
+ cache.set(String(key), value);
1173
+ }
1174
+ };
1175
+ };
1176
+ const memory = newInMemoryGenericStorageBackend();
1177
+ class WebStorageProvider {
1178
+ storage;
1179
+ constructor(storage) {
1180
+ this.storage = storage || memory;
1181
+ }
1182
+ get(key, defaultValue, middlewareFn) {
1183
+ const rawValue = this.storage.getItem(key);
1184
+ if (rawValue === null) return defaultValue;
1185
+ let value;
1186
+ try {
1187
+ value = JSON.parse(rawValue);
1188
+ } catch {
1189
+ return defaultValue;
1190
+ }
1191
+ if (middlewareFn) {
1192
+ value = middlewareFn(key, value);
1193
+ }
1194
+ return value;
1195
+ }
1196
+ set(key, value, middlewareFn) {
1197
+ if (middlewareFn) {
1198
+ value = middlewareFn(key, value);
1199
+ }
1200
+ this.storage.setItem(key, JSON.stringify(value));
1201
+ }
1202
+ remove(key) {
1203
+ this.storage.removeItem(key);
1204
+ }
1205
+ removeAll() {
1206
+ this.storage.clear();
1207
+ }
1208
+ get backendApi() {
1209
+ return this.storage;
1210
+ }
1211
+ }
1212
+
1213
+ const getPersistenceProvider$1 = (provider, _options) => {
1214
+ switch (provider) {
1215
+ case "session":
1216
+ return new WebStorageProvider(window.sessionStorage);
1217
+ case "local":
1218
+ return new WebStorageProvider(window.localStorage);
1219
+ }
1220
+ return new WebStorageProvider();
1221
+ };
1222
+
1223
+ const getPersistenceProvider = (_provider, _options) => {
1224
+ return new WebStorageProvider();
1225
+ };
1226
+
1227
+ const isServer = () => typeof window === "undefined" || typeof window.document === "undefined";
1228
+
1229
+ const webstorage = (provider = "local", options) => {
1230
+ if (isServer()) {
1231
+ return getPersistenceProvider();
1232
+ } else {
1233
+ return getPersistenceProvider$1(provider);
1234
+ }
1235
+ };
1236
+
1237
+ const shallowEquals = (a, b) => Object.is(a, b);
1238
+ const deepEquals = (a, b) => JSON.stringify(a) === JSON.stringify(b);
1239
+ const createStore = (initialValue, options = {}) => {
1240
+ const equals = options.equals ?? shallowEquals;
1241
+ let value = initialValue;
1242
+ const listeners = [];
1243
+ const notify = (oldValue, changedKey) => {
1244
+ listeners.forEach((listener) => listener(value, oldValue, changedKey));
1245
+ };
1246
+ let storage = null;
1247
+ let storageKey = null;
1248
+ let storageProvider;
1249
+ const initStorage = (provider) => {
1250
+ if (!storage || storageProvider !== provider) {
1251
+ storage = webstorage(provider);
1252
+ storageProvider = provider;
1253
+ }
1254
+ return storage;
1255
+ };
1256
+ const persistToStorage = () => {
1257
+ if (storage && storageKey) {
1258
+ storage.set(storageKey, value);
1259
+ }
1260
+ };
1261
+ return {
1262
+ // allow reading value but prevent external mutation
1263
+ get value() {
1264
+ return value;
1265
+ },
1266
+ persist(key, provider = "local") {
1267
+ storage = initStorage(provider);
1268
+ storageKey = key;
1269
+ persistToStorage();
1270
+ },
1271
+ restore(key, provider = "local") {
1272
+ storage = initStorage(provider);
1273
+ storageKey = key;
1274
+ const storedValue = storage.get(key, value);
1275
+ const oldValue = value;
1276
+ if (!equals(oldValue, storedValue)) {
1277
+ value = storedValue;
1278
+ notify(oldValue);
1279
+ }
1280
+ },
1281
+ get(path) {
1282
+ return path ? defussRuntime.getByPath(value, path) : value;
1283
+ },
1284
+ /** Get entire store value (clearer API) */
1285
+ getRaw() {
1286
+ return value;
1287
+ },
1288
+ /** Replace entire store value (clearer API) */
1289
+ setRaw(newValue) {
1290
+ const oldValue = value;
1291
+ if (!equals(value, newValue)) {
1292
+ value = newValue;
1293
+ notify(oldValue);
1294
+ persistToStorage();
1295
+ }
1296
+ },
1297
+ /** Reset to initial or provided value */
1298
+ reset(resetValue) {
1299
+ const oldValue = value;
1300
+ const newValue = resetValue ?? initialValue;
1301
+ if (!equals(value, newValue)) {
1302
+ value = newValue;
1303
+ notify(oldValue);
1304
+ persistToStorage();
1305
+ }
1306
+ },
1307
+ set(pathOrValue, newValue) {
1308
+ const oldValue = value;
1309
+ if (newValue === void 0) {
1310
+ if (!equals(value, pathOrValue)) {
1311
+ value = pathOrValue;
1312
+ notify(oldValue);
1313
+ persistToStorage();
1314
+ }
1315
+ } else {
1316
+ const updatedValue = defussRuntime.setByPath(value, pathOrValue, newValue);
1317
+ if (!equals(value, updatedValue)) {
1318
+ value = updatedValue;
1319
+ notify(oldValue, pathOrValue);
1320
+ persistToStorage();
1321
+ }
1322
+ }
1323
+ },
1324
+ subscribe(listener) {
1325
+ listeners.push(listener);
1326
+ return () => {
1327
+ const index = listeners.indexOf(listener);
1328
+ if (index >= 0) listeners.splice(index, 1);
1329
+ };
1330
+ }
1331
+ };
1332
+ };
1333
+
1334
+ const isRef = (obj) => Boolean(obj && typeof obj === "object" && "current" in obj);
1335
+ function createRef(refUpdateFn, defaultState) {
1336
+ const stateStore = createStore(defaultState);
1337
+ const render = async (input, ref2) => await $(ref2.current).update(input);
1338
+ const ref = {
1339
+ current: null,
1340
+ store: stateStore,
1341
+ get state() {
1342
+ return stateStore.value;
1343
+ },
1344
+ set state(value) {
1345
+ stateStore.set(value);
1346
+ },
1347
+ persist: (key, provider = "local") => {
1348
+ stateStore.persist(key, provider);
1349
+ },
1350
+ restore: (key, provider = "local") => {
1351
+ stateStore.restore(key, provider);
1352
+ },
1353
+ updateState: (state) => {
1354
+ stateStore.set(state);
1355
+ },
1356
+ render: async (input) => render(input, ref),
1357
+ update: async (input) => render(input, ref),
1358
+ subscribe: (refUpdateFn2) => stateStore.subscribe(refUpdateFn2)
1359
+ };
1360
+ if (typeof refUpdateFn === "function") {
1361
+ ref.subscribe(refUpdateFn);
1362
+ }
1363
+ return ref;
1364
+ }
1365
+
1366
+ const injectShakeKeyframes = () => {
1367
+ if (!document.getElementById("defuss-shake")) {
1368
+ const style = document.createElement("style");
1369
+ style.id = "defuss-shake";
1370
+ style.textContent = "@keyframes shake{0%,100%{transform:translate3d(0,0,0)}10%,30%,50%,70%,90%{transform:translate3d(-10px,0,0)}20%,40%,60%,80%{transform:translate3d(10px,0,0)}}";
1371
+ document.head.appendChild(style);
1372
+ }
1373
+ };
1374
+ const getTransitionStyles = (type, duration, easing = "ease-in-out") => {
1375
+ const t = `transform ${duration}ms ${easing}, opacity ${duration}ms ${easing}`;
1376
+ const styles = {
1377
+ fade: {
1378
+ enter: { opacity: "0", transition: t, transform: "translate3d(0,0,0)" },
1379
+ enterActive: { opacity: "1" },
1380
+ exit: { opacity: "1", transition: t, transform: "translate3d(0,0,0)" },
1381
+ exitActive: { opacity: "0" }
1382
+ },
1383
+ "slide-left": {
1384
+ enter: {
1385
+ transform: "translate3d(100%,0,0)",
1386
+ opacity: "0.5",
1387
+ transition: t
1388
+ },
1389
+ enterActive: { transform: "translate3d(0,0,0)", opacity: "1" },
1390
+ exit: { transform: "translate3d(0,0,0)", opacity: "1", transition: t },
1391
+ exitActive: { transform: "translate3d(-100%,0,0)", opacity: "0.5" }
1392
+ },
1393
+ "slide-right": {
1394
+ enter: {
1395
+ transform: "translate3d(-100%,0,0)",
1396
+ opacity: "0.5",
1397
+ transition: t
1398
+ },
1399
+ enterActive: { transform: "translate3d(0,0,0)", opacity: "1" },
1400
+ exit: { transform: "translate3d(0,0,0)", opacity: "1", transition: t },
1401
+ exitActive: { transform: "translate3d(100%,0,0)", opacity: "0.5" }
1402
+ },
1403
+ shake: (() => {
1404
+ injectShakeKeyframes();
1405
+ return {
1406
+ enter: {
1407
+ transform: "translate3d(0,0,0)",
1408
+ opacity: "1",
1409
+ transition: "none"
1410
+ },
1411
+ enterActive: {
1412
+ transform: "translate3d(0,0,0)",
1413
+ opacity: "1",
1414
+ animation: `shake ${duration}ms cubic-bezier(0.36,0.07,0.19,0.97)`
1415
+ },
1416
+ exit: {
1417
+ transform: "translate3d(0,0,0)",
1418
+ opacity: "1",
1419
+ transition: "none"
1420
+ },
1421
+ exitActive: {
1422
+ transform: "translate3d(0,0,0)",
1423
+ opacity: "1",
1424
+ animation: `shake ${duration}ms cubic-bezier(0.36,0.07,0.19,0.97)`
1425
+ }
1426
+ };
1427
+ })()
1428
+ };
1429
+ return styles[type] || { enter: {}, enterActive: {}, exit: {}, exitActive: {} };
1430
+ };
1431
+ const applyStyles = (el, styles) => Object.entries(styles).forEach(
1432
+ ([k, v]) => el.style.setProperty(k, String(v))
1433
+ );
1434
+ const DEFAULT_TRANSITION_CONFIG = {
1435
+ type: "fade",
1436
+ duration: 300,
1437
+ easing: "ease-in-out",
1438
+ delay: 0,
1439
+ target: "parent"
1440
+ };
1441
+ const wait = (ms) => new Promise((r) => setTimeout(r, ms));
1442
+ const performCrossfade = async (element, updateCallback, duration, easing) => {
1443
+ const originalStyle = element.style.cssText;
1444
+ const snapshot = element.cloneNode(true);
1445
+ try {
1446
+ const container = element.parentElement || element;
1447
+ const rect = element.getBoundingClientRect();
1448
+ snapshot.style.cssText = `position:absolute;top:${rect.top}px;left:${rect.left}px;width:${rect.width}px;height:${rect.height}px;opacity:1;transition:opacity ${duration}ms ${easing};z-index:1000;`;
1449
+ element.style.opacity = "0";
1450
+ element.style.transition = `opacity ${duration}ms ${easing}`;
1451
+ document.body.appendChild(snapshot);
1452
+ await updateCallback();
1453
+ void element.offsetHeight;
1454
+ snapshot.style.opacity = "0";
1455
+ element.style.opacity = "1";
1456
+ await wait(duration);
1457
+ document.body.removeChild(snapshot);
1458
+ } catch (error) {
1459
+ if (snapshot.parentElement) document.body.removeChild(snapshot);
1460
+ throw error;
1461
+ } finally {
1462
+ element.style.cssText = originalStyle;
1463
+ }
1464
+ };
1465
+ const performTransition = async (element, updateCallback, config = {}) => {
1466
+ const {
1467
+ type = "fade",
1468
+ duration = 300,
1469
+ easing = "ease-in-out",
1470
+ delay = 0
1471
+ } = { ...DEFAULT_TRANSITION_CONFIG, ...config };
1472
+ if (type === "none") {
1473
+ await updateCallback();
1474
+ return;
1475
+ }
1476
+ if (delay > 0) await wait(delay);
1477
+ if (type === "fade") {
1478
+ await performCrossfade(element, updateCallback, duration, easing);
1479
+ return;
1480
+ }
1481
+ const styles = config.styles || getTransitionStyles(type, duration, easing);
1482
+ const originalTransition = element.style.transition;
1483
+ const originalAnimation = element.style.animation;
1484
+ try {
1485
+ if (type === "shake") {
1486
+ element.style.animation = "none";
1487
+ void element.offsetHeight;
1488
+ }
1489
+ applyStyles(element, styles.exit);
1490
+ void element.offsetHeight;
1491
+ applyStyles(element, styles.exitActive);
1492
+ await wait(duration);
1493
+ await updateCallback();
1494
+ applyStyles(element, styles.enter);
1495
+ void element.offsetHeight;
1496
+ applyStyles(element, styles.enterActive);
1497
+ await wait(duration);
1498
+ element.style.transition = originalTransition;
1499
+ element.style.animation = originalAnimation;
1500
+ } catch (error) {
1501
+ element.style.transition = originalTransition;
1502
+ element.style.animation = originalAnimation;
1503
+ throw error;
1504
+ }
1505
+ };
1506
+
1507
+ const queueCallback = (cb) => (...args) => queueMicrotask(() => cb(...args));
1508
+
1509
+ const CLASS_ATTRIBUTE_NAME = "class";
1510
+ const XLINK_ATTRIBUTE_NAME = "xlink";
1511
+ const XMLNS_ATTRIBUTE_NAME = "xmlns";
1512
+ const REF_ATTRIBUTE_NAME = "ref";
1513
+ const DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE = "dangerouslySetInnerHTML";
1514
+ const nsMap = {
1515
+ [XMLNS_ATTRIBUTE_NAME]: "http://www.w3.org/2000/xmlns/",
1516
+ [XLINK_ATTRIBUTE_NAME]: "http://www.w3.org/1999/xlink",
1517
+ svg: "http://www.w3.org/2000/svg"
1518
+ };
1519
+ const isJSXComment = (node) => (
1520
+ /* v8 ignore next */
1521
+ node && typeof node === "object" && !node.attributes && !node.type && !node.children
1522
+ );
1523
+ const filterComments = (children) => children.filter((child) => !isJSXComment(child));
1524
+ const createInPlaceErrorMessageVNode = (error) => ({
1525
+ type: "p",
1526
+ attributes: {},
1527
+ children: [`FATAL ERROR: ${error?.message || error}`]
1528
+ });
1529
+ const jsx = (type, attributes, key, sourceInfo) => {
1530
+ attributes = { ...attributes };
1531
+ if (typeof key !== "undefined") {
1532
+ attributes.key = key;
1533
+ }
1534
+ let children = (attributes?.children ? [].concat(
1535
+ attributes.children
1536
+ ) : []).filter((c) => c !== null && c !== void 0 && typeof c !== "boolean");
1537
+ delete attributes?.children;
1538
+ children = filterComments(
1539
+ // Implementation to flatten virtual node children structures like:
1540
+ // [<p>1</p>, [<p>2</p>,<p>3</p>]] to: [<p>1</p>,<p>2</p>,<p>3</p>]
1541
+ [].concat.apply(
1542
+ [],
1543
+ children
1544
+ )
1545
+ );
1546
+ if (type === "fragment") {
1547
+ return filterComments(children);
1548
+ }
1549
+ if (typeof type === "function" && type.constructor.name === "AsyncFunction") {
1550
+ const fallback = attributes?.fallback;
1551
+ const propsForAsyncFn = { ...attributes };
1552
+ delete propsForAsyncFn.fallback;
1553
+ const onMount = async (containerEl) => {
1554
+ try {
1555
+ const resolvedVNode = await type({
1556
+ ...propsForAsyncFn,
1557
+ children
1558
+ });
1559
+ if (containerEl && resolvedVNode) {
1560
+ const globals = {
1561
+ window: containerEl.ownerDocument?.defaultView ?? globalThis
1562
+ };
1563
+ updateDomWithVdom(containerEl, resolvedVNode, globals);
1564
+ }
1565
+ } catch (error) {
1566
+ console.error("[defuss] Async component error:", error);
1567
+ if (containerEl) {
1568
+ containerEl.textContent = `Error: ${error?.message || error}`;
1569
+ }
1570
+ }
1571
+ };
1572
+ return {
1573
+ type: "div",
1574
+ attributes: {
1575
+ key,
1576
+ onMount
1577
+ },
1578
+ children: fallback ? [fallback] : [],
1579
+ sourceInfo
1580
+ };
1581
+ }
1582
+ if (typeof type === "function" && type.constructor.name !== "AsyncFunction") {
1583
+ try {
1584
+ const rendered = type({
1585
+ children,
1586
+ ...attributes
1587
+ });
1588
+ if (rendered && typeof rendered === "object" && !Array.isArray(rendered) && sourceInfo) {
1589
+ if (!rendered.componentProps) {
1590
+ rendered.componentProps = { ...attributes };
1591
+ } else {
1592
+ }
1593
+ }
1594
+ if (typeof key !== "undefined" && rendered && typeof rendered === "object") {
1595
+ if ("attributes" in rendered) {
1596
+ rendered.attributes = {
1597
+ ...rendered.attributes,
1598
+ key
1599
+ };
1600
+ } else if (Array.isArray(rendered) && rendered.length === 1) {
1601
+ const only = rendered[0];
1602
+ if (only && typeof only === "object" && "attributes" in only) {
1603
+ only.attributes = {
1604
+ ...only.attributes,
1605
+ key
1606
+ };
1607
+ }
1608
+ }
1609
+ }
1610
+ return rendered;
1611
+ } catch (error) {
1612
+ if (typeof error === "string") {
1613
+ error = `[JsxError] in ${type.name}: ${error}`;
1614
+ } else if (error instanceof Error) {
1615
+ error.message = `[JsxError] in ${type.name}: ${error.message}`;
1616
+ }
1617
+ return createInPlaceErrorMessageVNode(error);
1618
+ }
1619
+ }
1620
+ return {
1621
+ type,
1622
+ attributes,
1623
+ children,
1624
+ sourceInfo
1625
+ };
1626
+ };
1627
+ const observeUnmount = (domNode, onUnmount) => {
1628
+ if (!domNode || typeof onUnmount !== "function") {
1629
+ throw new Error(
1630
+ "Invalid arguments. Ensure domNode and onUnmount are valid."
1631
+ );
1632
+ }
1633
+ if (typeof MutationObserver === "undefined") {
1634
+ return;
1635
+ }
1636
+ let parentNode = domNode.parentNode;
1637
+ if (!parentNode) {
1638
+ throw new Error("The provided domNode does not have a parentNode.");
1639
+ }
1640
+ const observer = new MutationObserver((mutationsList) => {
1641
+ for (const mutation of mutationsList) {
1642
+ if (mutation.removedNodes.length > 0) {
1643
+ for (const removedNode of mutation.removedNodes) {
1644
+ if (removedNode === domNode) {
1645
+ queueMicrotask(() => {
1646
+ if (!domNode.isConnected) {
1647
+ onUnmount();
1648
+ observer.disconnect();
1649
+ return;
1650
+ }
1651
+ const newParent = domNode.parentNode;
1652
+ if (newParent && newParent !== parentNode) {
1653
+ parentNode = newParent;
1654
+ observer.disconnect();
1655
+ observer.observe(parentNode, { childList: true });
1656
+ }
1657
+ });
1658
+ return;
1659
+ }
1660
+ }
1661
+ }
1662
+ }
1663
+ });
1664
+ observer.observe(parentNode, { childList: true });
1665
+ };
1666
+ const handleLifecycleEventsForOnMount = (newEl) => {
1667
+ if (typeof newEl?.$onMount === "function") {
1668
+ newEl.$onMount(newEl);
1669
+ newEl.$onMount = null;
1670
+ }
1671
+ if (typeof newEl?.$onUnmount === "function") {
1672
+ observeUnmount(newEl, newEl.$onUnmount);
1673
+ }
1674
+ };
1675
+ const getRenderer = (document) => {
1676
+ const renderer = {
1677
+ hasElNamespace: (domElement) => domElement.namespaceURI === nsMap.svg,
1678
+ hasSvgNamespace: (parentElement, type) => renderer.hasElNamespace(parentElement) && type !== "STYLE" && type !== "SCRIPT",
1679
+ createElementOrElements: (virtualNode, parentDomElement) => {
1680
+ if (Array.isArray(virtualNode)) {
1681
+ return renderer.createChildElements(virtualNode, parentDomElement);
1682
+ }
1683
+ if (typeof virtualNode !== "undefined") {
1684
+ return renderer.createElement(virtualNode, parentDomElement);
1685
+ }
1686
+ return renderer.createTextNode("", parentDomElement);
1687
+ },
1688
+ createElement: (virtualNode, parentDomElement) => {
1689
+ let newEl = void 0;
1690
+ try {
1691
+ if (typeof virtualNode === "function" && virtualNode.constructor.name === "AsyncFunction") {
1692
+ newEl = document.createElement("div");
1693
+ } else if (typeof virtualNode === "object" && virtualNode !== null && "type" in virtualNode) {
1694
+ const vNode = virtualNode;
1695
+ if (typeof vNode.type === "function") {
1696
+ newEl = document.createElement("div");
1697
+ newEl.innerText = `FATAL ERROR: ${vNode.type._error}`;
1698
+ } else if (
1699
+ // SVG support
1700
+ typeof vNode.type === "string" && vNode.type.toUpperCase() === "SVG" || parentDomElement && renderer.hasSvgNamespace(
1701
+ parentDomElement,
1702
+ typeof vNode.type === "string" ? vNode.type.toUpperCase() : ""
1703
+ )
1704
+ ) {
1705
+ newEl = document.createElementNS(nsMap.svg, vNode.type);
1706
+ } else {
1707
+ newEl = document.createElement(vNode.type);
1708
+ }
1709
+ if (vNode.attributes) {
1710
+ renderer.setAttributes(vNode, newEl);
1711
+ if (vNode.attributes.dangerouslySetInnerHTML) {
1712
+ newEl.innerHTML = vNode.attributes.dangerouslySetInnerHTML.__html;
1713
+ }
1714
+ }
1715
+ if (vNode.children && !vNode.attributes?.dangerouslySetInnerHTML) {
1716
+ renderer.createChildElements(vNode.children, newEl);
1717
+ }
1718
+ } else {
1719
+ if (typeof virtualNode === "string" || typeof virtualNode === "number") {
1720
+ newEl = document.createElement(String(virtualNode));
1721
+ }
1722
+ }
1723
+ if (newEl && parentDomElement) {
1724
+ parentDomElement.appendChild(newEl);
1725
+ handleLifecycleEventsForOnMount(newEl);
1726
+ }
1727
+ } catch (e) {
1728
+ console.error(
1729
+ "Fatal error! Error happend while rendering the VDOM!",
1730
+ e,
1731
+ virtualNode
1732
+ );
1733
+ throw e;
1734
+ }
1735
+ return newEl;
1736
+ },
1737
+ createTextNode: (text, domElement) => {
1738
+ const node = document.createTextNode(text.toString());
1739
+ if (domElement) {
1740
+ domElement.appendChild(node);
1741
+ }
1742
+ return node;
1743
+ },
1744
+ createChildElements: (virtualChildren, domElement) => {
1745
+ const children = [];
1746
+ for (let i = 0; i < virtualChildren.length; i++) {
1747
+ const virtualChild = virtualChildren[i];
1748
+ if (typeof virtualChild === "boolean") {
1749
+ continue;
1750
+ }
1751
+ if (virtualChild === null || typeof virtualChild !== "object" && typeof virtualChild !== "function") {
1752
+ children.push(
1753
+ renderer.createTextNode(
1754
+ (typeof virtualChild === "undefined" || virtualChild === null ? "" : virtualChild).toString(),
1755
+ domElement
1756
+ )
1757
+ );
1758
+ } else {
1759
+ children.push(
1760
+ renderer.createElement(virtualChild, domElement)
1761
+ );
1762
+ }
1763
+ }
1764
+ return children;
1765
+ },
1766
+ setAttribute: (name, value, domElement) => {
1767
+ if (typeof value === "undefined") return;
1768
+ if (name === DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE) return;
1769
+ if (name === "key") {
1770
+ domElement._defussKey = String(value);
1771
+ return;
1772
+ }
1773
+ if (name === REF_ATTRIBUTE_NAME && typeof value !== "function") {
1774
+ const ref = value;
1775
+ ref.current = domElement;
1776
+ domElement._defussRef = value;
1777
+ domElement.$onUnmount = queueCallback(() => {
1778
+ });
1779
+ if (domElement.parentNode) {
1780
+ observeUnmount(domElement, domElement.$onUnmount);
1781
+ } else {
1782
+ queueMicrotask(() => {
1783
+ if (domElement.parentNode) {
1784
+ observeUnmount(domElement, domElement.$onUnmount);
1785
+ }
1786
+ });
1787
+ }
1788
+ return;
1789
+ }
1790
+ const parsed = parseEventPropName(name);
1791
+ if (parsed && typeof value === "function") {
1792
+ const { eventType, capture } = parsed;
1793
+ if (eventType === "mount") {
1794
+ domElement.$onMount = queueCallback(value);
1795
+ return;
1796
+ }
1797
+ if (eventType === "unmount") {
1798
+ if (domElement.$onUnmount) {
1799
+ const existingUnmount = domElement.$onUnmount;
1800
+ domElement.$onUnmount = () => {
1801
+ existingUnmount();
1802
+ value();
1803
+ };
1804
+ } else {
1805
+ domElement.$onUnmount = queueCallback(value);
1806
+ }
1807
+ return;
1808
+ }
1809
+ registerDelegatedEvent(
1810
+ domElement,
1811
+ eventType,
1812
+ value,
1813
+ { capture }
1814
+ );
1815
+ return;
1816
+ }
1817
+ if (name === "className") {
1818
+ name = CLASS_ATTRIBUTE_NAME;
1819
+ }
1820
+ if (name === CLASS_ATTRIBUTE_NAME && Array.isArray(value)) {
1821
+ value = value.filter((val) => !!val).join(" ");
1822
+ }
1823
+ const nsEndIndex = name.match(/[A-Z]/)?.index;
1824
+ if (renderer.hasElNamespace(domElement) && nsEndIndex) {
1825
+ const ns = name.substring(0, nsEndIndex).toLowerCase();
1826
+ const attrName = name.substring(nsEndIndex, name.length).toLowerCase();
1827
+ const namespace = nsMap[ns] || null;
1828
+ domElement.setAttributeNS(
1829
+ namespace,
1830
+ ns === XLINK_ATTRIBUTE_NAME || ns === XMLNS_ATTRIBUTE_NAME ? `${ns}:${attrName}` : name,
1831
+ String(value)
1832
+ );
1833
+ } else if (name === "style" && typeof value !== "string") {
1834
+ const styleObj = value;
1835
+ for (const prop of Object.keys(styleObj)) {
1836
+ domElement.style[prop] = String(
1837
+ styleObj[prop]
1838
+ );
1839
+ }
1840
+ } else if (typeof value === "boolean") {
1841
+ domElement[name] = value;
1842
+ if (value) {
1843
+ domElement.setAttribute(name, "");
1844
+ } else {
1845
+ domElement.removeAttribute(name);
1846
+ }
1847
+ } else if (
1848
+ // Controlled input props: use property assignment for live value,
1849
+ // AND setAttribute so SSG serialization (w3c-xmlserializer) includes it
1850
+ (name === "value" || name === "checked" || name === "selectedIndex") && (domElement.nodeName === "INPUT" || domElement.nodeName === "TEXTAREA" || domElement.nodeName === "SELECT")
1851
+ ) {
1852
+ domElement[name] = value;
1853
+ if (name === "checked") {
1854
+ if (value) {
1855
+ domElement.setAttribute("checked", "");
1856
+ } else {
1857
+ domElement.removeAttribute("checked");
1858
+ }
1859
+ } else if (name === "value") {
1860
+ domElement.setAttribute("value", String(value));
1861
+ }
1862
+ } else {
1863
+ domElement.setAttribute(name, String(value));
1864
+ }
1865
+ },
1866
+ setAttributes: (virtualNode, domElement) => {
1867
+ const attrNames = Object.keys(virtualNode.attributes);
1868
+ for (let i = 0; i < attrNames.length; i++) {
1869
+ renderer.setAttribute(
1870
+ attrNames[i],
1871
+ virtualNode.attributes[attrNames[i]],
1872
+ domElement
1873
+ );
1874
+ }
1875
+ }
1876
+ };
1877
+ return renderer;
1878
+ };
1879
+ const renderIsomorphicSync = (virtualNode, parentDomElement, globals) => {
1880
+ if (isDequery(parentDomElement)) {
1881
+ parentDomElement = parentDomElement.getFirstElement() || parentDomElement;
1882
+ }
1883
+ let renderResult;
1884
+ if (typeof virtualNode === "string") {
1885
+ renderResult = getRenderer(globals.window.document).createTextNode(
1886
+ virtualNode,
1887
+ parentDomElement
1888
+ );
1889
+ } else {
1890
+ renderResult = getRenderer(globals.window.document).createElementOrElements(
1891
+ virtualNode,
1892
+ parentDomElement
1893
+ );
1894
+ }
1895
+ return renderResult;
1896
+ };
1897
+ const renderIsomorphicAsync = async (virtualNode, parentDomElement, globals) => {
1898
+ if (parentDomElement instanceof Promise) {
1899
+ parentDomElement = await parentDomElement;
1900
+ }
1901
+ if (isDequery(parentDomElement)) {
1902
+ parentDomElement = parentDomElement.toArray()[0];
1903
+ }
1904
+ if (virtualNode instanceof Promise) {
1905
+ virtualNode = await virtualNode;
1906
+ }
1907
+ return renderIsomorphicSync(
1908
+ virtualNode,
1909
+ parentDomElement,
1910
+ globals
1911
+ );
1912
+ };
1913
+ const globalScopeDomApis = (window, document) => {
1914
+ globalThis.__defuss_document = document;
1915
+ globalThis.__defuss_window = window;
1916
+ };
1917
+ const render = (jsx2, container) => {
1918
+ if (!container) {
1919
+ console.warn("render: container is null or undefined");
1920
+ return;
1921
+ }
1922
+ const globals = {
1923
+ window: container.ownerDocument?.defaultView ?? globalThis
1924
+ };
1925
+ updateDomWithVdom(container, jsx2, globals);
1926
+ };
1927
+ const renderInto = render;
1928
+ const isJSX = (o) => {
1929
+ if (o === null || typeof o !== "object") return false;
1930
+ if (Array.isArray(o)) {
1931
+ return o.every(
1932
+ (item) => isJSX(item) || typeof item === "string" || typeof item === "number"
1933
+ );
1934
+ }
1935
+ if (typeof o.type === "string") return true;
1936
+ if (typeof o.type === "function") return true;
1937
+ if (typeof o.attributes === "object" && typeof o.children === "object")
1938
+ return true;
1939
+ return false;
1940
+ };
1941
+ const Fragment = (props) => props.children;
1942
+ const jsxs = jsx;
1943
+ const jsxDEV = (type, attributes, key, allChildrenAreStatic, sourceInfo, selfReference) => {
1944
+ let renderResult;
1945
+ try {
1946
+ if (sourceInfo) {
1947
+ if (typeof type === "function" && type.constructor.name !== "AsyncFunction") {
1948
+ sourceInfo.exportName = type.name || sourceInfo?.exportName;
1949
+ }
1950
+ sourceInfo.allChildrenAreStatic = allChildrenAreStatic;
1951
+ sourceInfo.selfReference = selfReference;
1952
+ }
1953
+ renderResult = jsx(type, attributes, key, sourceInfo);
1954
+ } catch (error) {
1955
+ console.error(
1956
+ "JSX error:",
1957
+ error,
1958
+ "in",
1959
+ sourceInfo,
1960
+ "component",
1961
+ selfReference
1962
+ );
1963
+ }
1964
+ return renderResult;
1965
+ };
1966
+ async function performCoreDomUpdate(input, nodes, timeout, Parser) {
1967
+ let processedInput = input;
1968
+ if (isDequery(processedInput)) {
1969
+ processedInput = processedInput[0];
1970
+ }
1971
+ if (isRef(processedInput)) {
1972
+ await defussRuntime.waitForRef(processedInput, timeout);
1973
+ processedInput = processedInput.current;
1974
+ }
1975
+ const getGlobalsFromElement = (el) => {
1976
+ const win = el.ownerDocument?.defaultView;
1977
+ return win ?? globalThis;
1978
+ };
1979
+ if (typeof processedInput === "object" && processedInput !== null && "nodeType" in processedInput && typeof processedInput.nodeType === "number") {
1980
+ const vnode = domNodeToVNode(processedInput);
1981
+ nodes.forEach((el) => {
1982
+ if (el) {
1983
+ updateDomWithVdom(el, vnode, getGlobalsFromElement(el));
1984
+ }
1985
+ });
1986
+ return;
1987
+ }
1988
+ if (typeof processedInput === "string") {
1989
+ if (isMarkup(processedInput, Parser)) {
1990
+ const vNodes = htmlStringToVNodes(processedInput, Parser);
1991
+ nodes.forEach((el) => {
1992
+ if (el) {
1993
+ updateDomWithVdom(
1994
+ el,
1995
+ vNodes,
1996
+ getGlobalsFromElement(el)
1997
+ );
1998
+ }
1999
+ });
2000
+ } else {
2001
+ nodes.forEach((el) => {
2002
+ if (el) {
2003
+ updateDomWithVdom(
2004
+ el,
2005
+ processedInput,
2006
+ getGlobalsFromElement(el)
2007
+ );
2008
+ }
2009
+ });
2010
+ }
2011
+ } else if (isJSX(processedInput)) {
2012
+ nodes.forEach((el) => {
2013
+ if (el) {
2014
+ updateDomWithVdom(
2015
+ el,
2016
+ processedInput,
2017
+ getGlobalsFromElement(el)
2018
+ );
2019
+ }
2020
+ });
2021
+ } else {
2022
+ console.warn("update: unsupported content type", processedInput);
2023
+ }
2024
+ }
2025
+ async function updateDom(input, nodes, timeout, Parser, transitionConfig) {
2026
+ if (transitionConfig && transitionConfig.type !== "none") {
2027
+ const config = { ...DEFAULT_TRANSITION_CONFIG, ...transitionConfig };
2028
+ const { target = "self" } = config;
2029
+ const transitionPromises = nodes.map(async (node) => {
2030
+ if (!node) return node;
2031
+ const element = node;
2032
+ const transitionTarget = target === "self" ? element : element.parentElement;
2033
+ if (!transitionTarget) {
2034
+ await performCoreDomUpdate(input, [node], timeout, Parser);
2035
+ return node;
2036
+ }
2037
+ await performTransition(
2038
+ transitionTarget,
2039
+ () => performCoreDomUpdate(input, [node], timeout, Parser),
2040
+ config
2041
+ );
2042
+ return node;
2043
+ });
2044
+ await Promise.all(transitionPromises);
2045
+ return nodes;
2046
+ }
2047
+ await performCoreDomUpdate(input, nodes, timeout, Parser);
2048
+ return nodes;
2049
+ }
2050
+
2051
+ const areDomNodesEqual = (oldNode, newNode) => {
2052
+ if (oldNode === newNode) return true;
2053
+ if (oldNode.nodeType !== newNode.nodeType) return false;
2054
+ if (oldNode.nodeType === Node.ELEMENT_NODE) {
2055
+ const oldElement = oldNode;
2056
+ const newElement = newNode;
2057
+ if (oldElement.tagName !== newElement.tagName) return false;
2058
+ const oldAttrs = oldElement.attributes;
2059
+ const newAttrs = newElement.attributes;
2060
+ if (oldAttrs.length !== newAttrs.length) return false;
2061
+ for (let i = 0; i < oldAttrs.length; i++) {
2062
+ const oldAttr = oldAttrs[i];
2063
+ const newAttrValue = newElement.getAttribute(oldAttr.name);
2064
+ if (oldAttr.value !== newAttrValue) return false;
2065
+ }
2066
+ }
2067
+ if (oldNode.nodeType === Node.TEXT_NODE) {
2068
+ if (oldNode.textContent !== newNode.textContent) return false;
2069
+ }
2070
+ return true;
2071
+ };
2072
+ function isTextLike(value) {
2073
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
2074
+ }
2075
+ function isVNode(value) {
2076
+ return Boolean(value && typeof value === "object" && "type" in value);
2077
+ }
2078
+ function toValidChild(child) {
2079
+ if (child == null) return child;
2080
+ if (isTextLike(child)) return child;
2081
+ if (isVNode(child)) return child;
2082
+ return void 0;
2083
+ }
2084
+ function normalizeChildren(input) {
2085
+ const raw = [];
2086
+ const pushChild = (child) => {
2087
+ if (Array.isArray(child)) {
2088
+ child.forEach(pushChild);
2089
+ return;
2090
+ }
2091
+ const valid = toValidChild(child);
2092
+ if (typeof valid === "undefined") return;
2093
+ if (isVNode(valid) && (valid.type === "fragment" || valid.type === "Fragment")) {
2094
+ const nested = Array.isArray(valid.children) ? valid.children : [];
2095
+ nested.forEach(pushChild);
2096
+ return;
2097
+ }
2098
+ if (valid === null || typeof valid === "undefined" || typeof valid === "boolean") return;
2099
+ raw.push(valid);
2100
+ };
2101
+ pushChild(input);
2102
+ const fused = [];
2103
+ let buffer = null;
2104
+ const flush = () => {
2105
+ if (buffer !== null && buffer.length > 0) fused.push(buffer);
2106
+ buffer = null;
2107
+ };
2108
+ for (const child of raw) {
2109
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2110
+ buffer = (buffer ?? "") + String(child);
2111
+ continue;
2112
+ }
2113
+ flush();
2114
+ fused.push(child);
2115
+ }
2116
+ flush();
2117
+ return fused;
2118
+ }
2119
+ function getVNodeMatchKey(child) {
2120
+ if (!child || typeof child !== "object") return null;
2121
+ const key = child.attributes?.key;
2122
+ if (typeof key === "string" || typeof key === "number") return `k:${String(key)}`;
2123
+ const id = child.attributes?.id;
2124
+ if (typeof id === "string" && id.length > 0) return `id:${id}`;
2125
+ return null;
2126
+ }
2127
+ function getDomMatchKeys(node) {
2128
+ if (node.nodeType !== Node.ELEMENT_NODE) return [];
2129
+ const el = node;
2130
+ const keys = [];
2131
+ const internalKey = el._defussKey;
2132
+ if (internalKey) keys.push(`k:${internalKey}`);
2133
+ const attrKey = el.getAttribute("key");
2134
+ if (attrKey) keys.push(`k:${attrKey}`);
2135
+ const id = el.id;
2136
+ if (id) keys.push(`id:${id}`);
2137
+ return keys;
2138
+ }
2139
+ function areNodeAndChildMatching(domNode, child) {
2140
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2141
+ return domNode.nodeType === Node.TEXT_NODE;
2142
+ }
2143
+ if (child && typeof child === "object") {
2144
+ if (domNode.nodeType !== Node.ELEMENT_NODE) return false;
2145
+ const el = domNode;
2146
+ const oldTag = el.tagName.toLowerCase();
2147
+ const newTag = typeof child.type === "string" ? child.type.toLowerCase() : "";
2148
+ if (!newTag || oldTag !== newTag) return false;
2149
+ return true;
2150
+ }
2151
+ return false;
2152
+ }
2153
+ function createDomFromChild(child, globals) {
2154
+ const renderer = getRenderer(globals.window.document);
2155
+ if (child == null) return void 0;
2156
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2157
+ return [globals.window.document.createTextNode(String(child))];
2158
+ }
2159
+ const created = renderer.createElementOrElements(child);
2160
+ if (!created) return void 0;
2161
+ const nodes = Array.isArray(created) ? created : [created];
2162
+ return nodes.filter(Boolean);
2163
+ }
2164
+ function shouldPreserveFormStateAttribute(el, attrName, vnode) {
2165
+ const tag = el.tagName.toLowerCase();
2166
+ const hasExplicit = Object.prototype.hasOwnProperty.call(vnode.attributes ?? {}, attrName);
2167
+ if (hasExplicit) return false;
2168
+ if (tag === "input") return attrName === "value" || attrName === "checked";
2169
+ if (tag === "textarea") return attrName === "value";
2170
+ if (tag === "select") return attrName === "value";
2171
+ return false;
2172
+ }
2173
+ function patchElementInPlace(el, vnode, globals) {
2174
+ const renderer = getRenderer(globals.window.document);
2175
+ const existingAttrs = Array.from(el.attributes);
2176
+ const nextAttrs = vnode.attributes ?? {};
2177
+ for (const attr of existingAttrs) {
2178
+ const { name } = attr;
2179
+ if (name === "key") continue;
2180
+ if (name.startsWith("on")) continue;
2181
+ if (name === "class" && (Object.prototype.hasOwnProperty.call(nextAttrs, "class") || Object.prototype.hasOwnProperty.call(nextAttrs, "className"))) {
2182
+ continue;
2183
+ }
2184
+ if (!Object.prototype.hasOwnProperty.call(nextAttrs, name)) {
2185
+ if (shouldPreserveFormStateAttribute(el, name, vnode)) continue;
2186
+ el.removeAttribute(name);
2187
+ }
2188
+ }
2189
+ const registeredKeys = getRegisteredEventKeys(el);
2190
+ const nextEventKeys = /* @__PURE__ */ new Set();
2191
+ for (const propName of Object.keys(nextAttrs)) {
2192
+ const parsed = parseEventPropName(propName);
2193
+ if (parsed) {
2194
+ const phase = parsed.capture ? "capture" : "bubble";
2195
+ nextEventKeys.add(`${parsed.eventType}:${phase}`);
2196
+ }
2197
+ }
2198
+ for (const key of registeredKeys) {
2199
+ if (!nextEventKeys.has(key)) {
2200
+ const [eventType, phase] = key.split(":");
2201
+ removeDelegatedEventByKey(el, eventType, phase);
2202
+ }
2203
+ }
2204
+ renderer.setAttributes(vnode, el);
2205
+ handleLifecycleEventsForOnMount(el);
2206
+ const d = vnode.attributes?.dangerouslySetInnerHTML;
2207
+ if (d && typeof d === "object" && typeof d.__html === "string") {
2208
+ el.innerHTML = d.__html;
2209
+ return;
2210
+ }
2211
+ const tag = el.tagName.toLowerCase();
2212
+ if (tag === "textarea") {
2213
+ const isControlled = Object.prototype.hasOwnProperty.call(nextAttrs, "value");
2214
+ const isActive = el.ownerDocument?.activeElement === el;
2215
+ if (isActive && !isControlled) return;
2216
+ }
2217
+ updateDomWithVdom(el, vnode.children ?? [], globals);
2218
+ }
2219
+ function morphNode(domNode, child, globals) {
2220
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
2221
+ const text = String(child);
2222
+ if (domNode.nodeType === Node.TEXT_NODE) {
2223
+ if (domNode.nodeValue !== text) domNode.nodeValue = text;
2224
+ return domNode;
2225
+ }
2226
+ const next = globals.window.document.createTextNode(text);
2227
+ domNode.parentNode?.replaceChild(next, domNode);
2228
+ return next;
2229
+ }
2230
+ if (child && typeof child === "object") {
2231
+ const newType = typeof child.type === "string" ? child.type : null;
2232
+ if (!newType) return domNode;
2233
+ if (domNode.nodeType !== Node.ELEMENT_NODE) {
2234
+ const created = createDomFromChild(child, globals);
2235
+ const first = Array.isArray(created) ? created[0] : created;
2236
+ if (!first) return null;
2237
+ domNode.parentNode?.replaceChild(first, domNode);
2238
+ handleLifecycleEventsForOnMount(first);
2239
+ return first;
2240
+ }
2241
+ const el = domNode;
2242
+ const oldTag = el.tagName.toLowerCase();
2243
+ const newTag = newType.toLowerCase();
2244
+ if (oldTag !== newTag) {
2245
+ const created = createDomFromChild(child, globals);
2246
+ const first = Array.isArray(created) ? created[0] : created;
2247
+ if (!first) return null;
2248
+ el.parentNode?.replaceChild(first, el);
2249
+ handleLifecycleEventsForOnMount(first);
2250
+ return first;
2251
+ }
2252
+ patchElementInPlace(el, child, globals);
2253
+ return el;
2254
+ }
2255
+ domNode.parentNode?.removeChild(domNode);
2256
+ return null;
2257
+ }
2258
+ function updateDomWithVdom(parentElement, newVDOM, globals) {
2259
+ const el = parentElement;
2260
+ const isCustomElement = el.tagName.includes("-");
2261
+ const targetRoot = el.shadowRoot && !isCustomElement ? el.shadowRoot : parentElement;
2262
+ const nextChildren = normalizeChildren(newVDOM);
2263
+ const existing = Array.from(targetRoot.childNodes);
2264
+ const keyedPool = /* @__PURE__ */ new Map();
2265
+ const nodeKeys = /* @__PURE__ */ new WeakMap();
2266
+ const unkeyedPool = [];
2267
+ for (const node of existing) {
2268
+ const keys = getDomMatchKeys(node);
2269
+ if (keys.length > 0) {
2270
+ nodeKeys.set(node, keys);
2271
+ for (const k of keys) {
2272
+ if (!keyedPool.has(k)) keyedPool.set(k, node);
2273
+ }
2274
+ } else {
2275
+ unkeyedPool.push(node);
2276
+ }
2277
+ }
2278
+ const consumeKeyedNode = (node) => {
2279
+ const keys = nodeKeys.get(node) ?? [];
2280
+ for (const k of keys) keyedPool.delete(k);
2281
+ };
2282
+ const takeUnkeyedMatch = (child) => {
2283
+ for (let i = 0; i < unkeyedPool.length; i++) {
2284
+ const candidate = unkeyedPool[i];
2285
+ if (areNodeAndChildMatching(candidate, child)) {
2286
+ unkeyedPool.splice(i, 1);
2287
+ return candidate;
2288
+ }
2289
+ }
2290
+ return void 0;
2291
+ };
2292
+ let domIndex = 0;
2293
+ for (const child of nextChildren) {
2294
+ const key = getVNodeMatchKey(child);
2295
+ let match;
2296
+ if (key) {
2297
+ match = keyedPool.get(key);
2298
+ if (match) consumeKeyedNode(match);
2299
+ } else {
2300
+ match = takeUnkeyedMatch(child);
2301
+ }
2302
+ const anchor = targetRoot.childNodes[domIndex] ?? null;
2303
+ if (match) {
2304
+ if (match !== anchor) {
2305
+ targetRoot.insertBefore(match, anchor);
2306
+ }
2307
+ morphNode(match, child, globals);
2308
+ domIndex++;
2309
+ continue;
2310
+ }
2311
+ const created = createDomFromChild(child, globals);
2312
+ if (!created || Array.isArray(created) && created.length === 0) continue;
2313
+ const nodes = Array.isArray(created) ? created : [created];
2314
+ for (const node of nodes) {
2315
+ targetRoot.insertBefore(node, anchor);
2316
+ handleLifecycleEventsForOnMount(node);
2317
+ domIndex++;
2318
+ }
2319
+ }
2320
+ const remaining = /* @__PURE__ */ new Set();
2321
+ for (const node of unkeyedPool) remaining.add(node);
2322
+ for (const node of keyedPool.values()) remaining.add(node);
2323
+ for (const node of remaining) {
2324
+ if (node.parentNode === targetRoot) {
2325
+ if (node instanceof HTMLElement) {
2326
+ clearDelegatedEventsDeep(node);
2327
+ }
2328
+ targetRoot.removeChild(node);
2329
+ }
2330
+ }
2331
+ }
2332
+ function replaceDomWithVdom(parentElement, newVDOM, globals) {
2333
+ while (parentElement.firstChild) {
2334
+ parentElement.removeChild(parentElement.firstChild);
2335
+ }
2336
+ const renderer = getRenderer(globals.window.document);
2337
+ const newDom = renderer.createElementOrElements(
2338
+ newVDOM
2339
+ );
2340
+ if (Array.isArray(newDom)) {
2341
+ for (const node of newDom) {
2342
+ if (node) {
2343
+ parentElement.appendChild(node);
2344
+ handleLifecycleEventsForOnMount(node);
2345
+ }
2346
+ }
2347
+ } else if (newDom) {
2348
+ parentElement.appendChild(newDom);
2349
+ handleLifecycleEventsForOnMount(newDom);
2350
+ }
2351
+ }
2352
+ async function waitForDOM(check, timeout, document) {
2353
+ const initialResult = check();
2354
+ if (initialResult.length) return initialResult;
2355
+ return defussRuntime.createTimeoutPromise(timeout, () => {
2356
+ return new Promise((resolve) => {
2357
+ if (!document) {
2358
+ setTimeout(() => resolve(check()), 0);
2359
+ return;
2360
+ }
2361
+ const observer = new MutationObserver(() => {
2362
+ const result = check();
2363
+ if (result.length) {
2364
+ observer.disconnect();
2365
+ resolve(result);
2366
+ }
2367
+ });
2368
+ observer.observe(document.documentElement, {
2369
+ childList: true,
2370
+ subtree: true,
2371
+ attributes: true
2372
+ });
2373
+ return () => observer.disconnect();
2374
+ });
2375
+ });
2376
+ }
2377
+ function parseDOM(input, type, Parser) {
2378
+ return new Parser().parseFromString(input, type);
2379
+ }
2380
+ function isSVG(input, Parser) {
2381
+ const doc = parseDOM(input, "image/svg+xml", Parser);
2382
+ if (!doc.documentElement) return false;
2383
+ return doc.documentElement.nodeName.toLowerCase() === "svg";
2384
+ }
2385
+ function isHTML(input, Parser) {
2386
+ const doc = parseDOM(input, "text/html", Parser);
2387
+ return doc.documentElement.querySelectorAll("*").length > 2;
2388
+ }
2389
+ const isMarkup = (input, Parser) => input.indexOf("<") > -1 && input.indexOf(">") > -1 && (isHTML(input, Parser) || isSVG(input, Parser));
2390
+ function renderMarkup(markup, Parser, doc) {
2391
+ return Array.from(
2392
+ (doc ? doc : parseDOM(markup, getMimeType(markup, Parser), Parser)).body.childNodes
2393
+ );
2394
+ }
2395
+ function getMimeType(input, Parser) {
2396
+ if (isSVG(input, Parser)) {
2397
+ return "image/svg+xml";
2398
+ }
2399
+ return "text/html";
2400
+ }
2401
+ function processAllFormElements(node, callback) {
2402
+ if (node instanceof Element) {
2403
+ if (node instanceof HTMLFormElement) {
2404
+ Array.from(node.elements).forEach((element) => {
2405
+ if (element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) {
2406
+ const key = element.name || element.id;
2407
+ if (key) {
2408
+ callback(element, key);
2409
+ }
2410
+ }
2411
+ });
2412
+ } else {
2413
+ const inputElements = node.querySelectorAll("input, select, textarea");
2414
+ inputElements.forEach((element) => {
2415
+ if (element instanceof HTMLInputElement || element instanceof HTMLSelectElement || element instanceof HTMLTextAreaElement) {
2416
+ const key = element.name || element.id;
2417
+ if (key) {
2418
+ callback(element, key);
2419
+ }
2420
+ }
2421
+ });
2422
+ }
2423
+ }
2424
+ }
2425
+ function checkElementVisibility(element, window, document) {
2426
+ const style = window.getComputedStyle(element);
2427
+ if (!style) return false;
2428
+ if (element.offsetWidth === 0 || element.offsetHeight === 0) return false;
2429
+ if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" || Number.parseFloat(style.opacity) === 0)
2430
+ return false;
2431
+ if (!document.body.contains(element)) return false;
2432
+ let parent = element.parentElement;
2433
+ while (parent) {
2434
+ const parentStyle = window.getComputedStyle(parent);
2435
+ if (parentStyle && (parentStyle.display === "none" || parentStyle.visibility === "hidden" || parentStyle.opacity === "0" || Number.parseFloat(parentStyle.opacity) === 0)) {
2436
+ return false;
2437
+ }
2438
+ parent = parent.parentElement;
2439
+ }
2440
+ return true;
2441
+ }
2442
+ function getEventMap(element) {
2443
+ if (!element._dequeryEvents) {
2444
+ element._dequeryEvents = /* @__PURE__ */ new Map();
2445
+ }
2446
+ return element._dequeryEvents;
2447
+ }
2448
+ function addElementEvent(target, eventType, handler) {
2449
+ registerDelegatedEvent(target, eventType, handler, { multi: true });
2450
+ }
2451
+ function removeElementEvent(target, eventType, handler) {
2452
+ removeDelegatedEvent(target, eventType, handler);
2453
+ }
2454
+ function clearElementEvents(target) {
2455
+ clearDelegatedEvents(target);
2456
+ }
2457
+ function domNodeToVNode(node) {
2458
+ if (node.nodeType === Node.TEXT_NODE) {
2459
+ return node.textContent || "";
2460
+ }
2461
+ if (node.nodeType === Node.ELEMENT_NODE) {
2462
+ const element = node;
2463
+ const attributes = {};
2464
+ for (let i = 0; i < element.attributes.length; i++) {
2465
+ const attr = element.attributes[i];
2466
+ attributes[attr.name] = attr.value;
2467
+ }
2468
+ const children = [];
2469
+ for (let i = 0; i < element.childNodes.length; i++) {
2470
+ const childVNode = domNodeToVNode(element.childNodes[i]);
2471
+ children.push(childVNode);
2472
+ }
2473
+ return {
2474
+ type: element.tagName.toLowerCase(),
2475
+ attributes,
2476
+ children
2477
+ };
2478
+ }
2479
+ return "";
2480
+ }
2481
+ function htmlStringToVNodes(html, Parser) {
2482
+ const parser = new Parser();
2483
+ const doc = parser.parseFromString(html, "text/html");
2484
+ const vNodes = [];
2485
+ for (let i = 0; i < doc.body.childNodes.length; i++) {
2486
+ const vnode = domNodeToVNode(doc.body.childNodes[i]);
2487
+ if (vnode !== "") {
2488
+ vNodes.push(vnode);
2489
+ }
2490
+ }
2491
+ return vNodes;
2492
+ }
2493
+
2494
+ exports.$ = $;
2495
+ exports.CAPTURE_ONLY_EVENTS = CAPTURE_ONLY_EVENTS;
2496
+ exports.CLASS_ATTRIBUTE_NAME = CLASS_ATTRIBUTE_NAME;
2497
+ exports.CallChainImpl = CallChainImpl;
2498
+ exports.CallChainImplThenable = CallChainImplThenable;
2499
+ exports.DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE = DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE;
2500
+ exports.DEFAULT_TRANSITION_CONFIG = DEFAULT_TRANSITION_CONFIG;
2501
+ exports.Fragment = Fragment;
2502
+ exports.REF_ATTRIBUTE_NAME = REF_ATTRIBUTE_NAME;
2503
+ exports.XLINK_ATTRIBUTE_NAME = XLINK_ATTRIBUTE_NAME;
2504
+ exports.XMLNS_ATTRIBUTE_NAME = XMLNS_ATTRIBUTE_NAME;
2505
+ exports.addElementEvent = addElementEvent;
2506
+ exports.addNonChainedReturnCallNames = addNonChainedReturnCallNames;
2507
+ exports.applyStyles = applyStyles;
2508
+ exports.areDomNodesEqual = areDomNodesEqual;
2509
+ exports.checkElementVisibility = checkElementVisibility;
2510
+ exports.clearDelegatedEvents = clearDelegatedEvents;
2511
+ exports.clearDelegatedEventsDeep = clearDelegatedEventsDeep;
2512
+ exports.clearElementEvents = clearElementEvents;
2513
+ exports.createCall = createCall;
2514
+ exports.createInPlaceErrorMessageVNode = createInPlaceErrorMessageVNode;
2515
+ exports.createRef = createRef;
2516
+ exports.createStore = createStore;
2517
+ exports.createSyncCall = createSyncCall;
2518
+ exports.deepEquals = deepEquals;
2519
+ exports.dequery = dequery;
2520
+ exports.domNodeToVNode = domNodeToVNode;
2521
+ exports.emptyImpl = emptyImpl;
2522
+ exports.getAllFormValues = getAllFormValues;
2523
+ exports.getComponentInstance = getComponentInstance;
2524
+ exports.getDefaultDequeryOptions = getDefaultDequeryOptions;
2525
+ exports.getEventMap = getEventMap;
2526
+ exports.getMimeType = getMimeType;
2527
+ exports.getNonChainedReturnCallNames = getNonChainedReturnCallNames;
2528
+ exports.getRegisteredEventKeys = getRegisteredEventKeys;
2529
+ exports.getRegisteredEventTypes = getRegisteredEventTypes;
2530
+ exports.getRenderer = getRenderer;
2531
+ exports.getTransitionStyles = getTransitionStyles;
2532
+ exports.globalScopeDomApis = globalScopeDomApis;
2533
+ exports.handleLifecycleEventsForOnMount = handleLifecycleEventsForOnMount;
2534
+ exports.htmlStringToVNodes = htmlStringToVNodes;
2535
+ exports.isComponentRoot = isComponentRoot;
2536
+ exports.isDequery = isDequery;
2537
+ exports.isDequeryOptionsObject = isDequeryOptionsObject;
2538
+ exports.isHTML = isHTML;
2539
+ exports.isJSX = isJSX;
2540
+ exports.isMarkup = isMarkup;
2541
+ exports.isNonChainedReturnCall = isNonChainedReturnCall;
2542
+ exports.isRef = isRef;
2543
+ exports.isSVG = isSVG;
2544
+ exports.jsx = jsx;
2545
+ exports.jsxDEV = jsxDEV;
2546
+ exports.jsxs = jsxs;
2547
+ exports.mapArrayIndexAccess = mapArrayIndexAccess;
2548
+ exports.nsMap = nsMap;
2549
+ exports.observeUnmount = observeUnmount;
2550
+ exports.parseDOM = parseDOM;
2551
+ exports.parseEventPropName = parseEventPropName;
2552
+ exports.performTransition = performTransition;
2553
+ exports.processAllFormElements = processAllFormElements;
2554
+ exports.queueCallback = queueCallback;
2555
+ exports.registerComponent = registerComponent;
2556
+ exports.registerDelegatedEvent = registerDelegatedEvent;
2557
+ exports.removeDelegatedEvent = removeDelegatedEvent;
2558
+ exports.removeDelegatedEventByKey = removeDelegatedEventByKey;
2559
+ exports.removeElementEvent = removeElementEvent;
2560
+ exports.render = render;
2561
+ exports.renderInto = renderInto;
2562
+ exports.renderIsomorphicAsync = renderIsomorphicAsync;
2563
+ exports.renderIsomorphicSync = renderIsomorphicSync;
2564
+ exports.renderMarkup = renderMarkup;
2565
+ exports.renderNode = renderNode;
2566
+ exports.replaceDomWithVdom = replaceDomWithVdom;
2567
+ exports.resolveNodes = resolveNodes;
2568
+ exports.scrollHelper = scrollHelper;
2569
+ exports.shallowEquals = shallowEquals;
2570
+ exports.traverse = traverse;
2571
+ exports.unregisterComponent = unregisterComponent;
2572
+ exports.updateDom = updateDom;
2573
+ exports.updateDomWithVdom = updateDomWithVdom;
2574
+ exports.waitForDOM = waitForDOM;
2575
+ exports.webstorage = webstorage;