defuss-morph 0.1.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,1242 @@
1
+ 'use strict';
2
+
3
+ const queueCallback = (cb) => (...args) => queueMicrotask(() => cb(...args));
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 bubbleDispatched = /* @__PURE__ */ new WeakMap();
15
+ const captureDispatched = /* @__PURE__ */ new WeakMap();
16
+ const activeDispatches = /* @__PURE__ */ new WeakMap();
17
+ const parseEventPropName = (propName) => {
18
+ if (!propName.startsWith("on")) return null;
19
+ const raw = propName.slice(2);
20
+ if (!raw) return null;
21
+ const lower = raw.toLowerCase();
22
+ const isCapture = lower.endsWith("capture");
23
+ const eventType = isCapture ? lower.slice(0, -"capture".length) : lower;
24
+ if (!eventType) return null;
25
+ return { eventType, capture: isCapture };
26
+ };
27
+ const getOrCreateElementHandlers = (el) => {
28
+ const existing = elementHandlerMap.get(el);
29
+ if (existing) return existing;
30
+ const created = /* @__PURE__ */ new Map();
31
+ elementHandlerMap.set(el, created);
32
+ return created;
33
+ };
34
+ const getEventPath = (event) => {
35
+ const composedPath = event.composedPath?.();
36
+ if (composedPath && composedPath.length > 0) return composedPath;
37
+ const path = [];
38
+ let node = event.target;
39
+ while (node) {
40
+ path.push(node);
41
+ const maybeNode = node;
42
+ if (typeof maybeNode === "object" && maybeNode && "parentNode" in maybeNode) {
43
+ node = maybeNode.parentNode;
44
+ continue;
45
+ }
46
+ break;
47
+ }
48
+ const doc = event.target?.ownerDocument;
49
+ if (doc && path[path.length - 1] !== doc) path.push(doc);
50
+ const win = doc?.defaultView;
51
+ if (win && path[path.length - 1] !== win) path.push(win);
52
+ return path;
53
+ };
54
+ const createPhaseHandler = (eventType, phase) => {
55
+ const dispatched = phase === "capture" ? captureDispatched : bubbleDispatched;
56
+ return (event) => {
57
+ const path = getEventPath(event).filter(
58
+ (t) => typeof t === "object" && t !== null && t.nodeType === 1
59
+ );
60
+ const ordered = phase === "capture" ? [...path].reverse() : path;
61
+ for (const target of ordered) {
62
+ const handlersByEvent = elementHandlerMap.get(target);
63
+ if (!handlersByEvent) continue;
64
+ const entry = handlersByEvent.get(eventType);
65
+ if (!entry) continue;
66
+ let targets = dispatched.get(event);
67
+ if (targets?.has(target)) continue;
68
+ if (!targets) {
69
+ targets = /* @__PURE__ */ new WeakSet();
70
+ dispatched.set(event, targets);
71
+ }
72
+ targets.add(target);
73
+ const dispatchKey = `${eventType}:${phase}`;
74
+ let activeSet = activeDispatches.get(target);
75
+ if (activeSet?.has(dispatchKey)) continue;
76
+ if (!activeSet) {
77
+ activeSet = /* @__PURE__ */ new Set();
78
+ activeDispatches.set(target, activeSet);
79
+ }
80
+ activeSet.add(dispatchKey);
81
+ try {
82
+ if (phase === "capture") {
83
+ if (entry.capture) {
84
+ entry.capture.call(target, event);
85
+ if (event.cancelBubble)
86
+ return;
87
+ }
88
+ if (entry.captureSet) {
89
+ for (const handler of entry.captureSet) {
90
+ handler.call(target, event);
91
+ if (event.cancelBubble)
92
+ return;
93
+ }
94
+ }
95
+ } else {
96
+ if (entry.bubble) {
97
+ entry.bubble.call(target, event);
98
+ if (event.cancelBubble)
99
+ return;
100
+ }
101
+ if (entry.bubbleSet) {
102
+ for (const handler of entry.bubbleSet) {
103
+ handler.call(target, event);
104
+ if (event.cancelBubble)
105
+ return;
106
+ }
107
+ }
108
+ }
109
+ } finally {
110
+ activeSet.delete(dispatchKey);
111
+ }
112
+ }
113
+ };
114
+ };
115
+ const installedRootListeners = /* @__PURE__ */ new WeakMap();
116
+ const ensureRootListener = (root, eventType) => {
117
+ const installed = installedRootListeners.get(root) ?? /* @__PURE__ */ new Set();
118
+ installedRootListeners.set(root, installed);
119
+ const captureKey = `${eventType}:capture`;
120
+ if (!installed.has(captureKey)) {
121
+ root.addEventListener(
122
+ eventType,
123
+ createPhaseHandler(eventType, "capture"),
124
+ true
125
+ );
126
+ installed.add(captureKey);
127
+ }
128
+ const bubbleKey = `${eventType}:bubble`;
129
+ if (!installed.has(bubbleKey)) {
130
+ root.addEventListener(
131
+ eventType,
132
+ createPhaseHandler(eventType, "bubble"),
133
+ false
134
+ );
135
+ installed.add(bubbleKey);
136
+ }
137
+ };
138
+ const getEventRoot = (element) => {
139
+ const root = element.getRootNode();
140
+ if (root && root.nodeType === 9) {
141
+ return root;
142
+ }
143
+ if (root && root.nodeType === 11 && "host" in root) {
144
+ return root;
145
+ }
146
+ return null;
147
+ };
148
+ const registerDelegatedEvent = (element, eventType, handler, options = {}) => {
149
+ const root = getEventRoot(element);
150
+ const capture = options.capture || CAPTURE_ONLY_EVENTS.has(eventType);
151
+ if (root) {
152
+ ensureRootListener(root, eventType);
153
+ } else if (element.ownerDocument) {
154
+ ensureRootListener(element.ownerDocument, eventType);
155
+ } else {
156
+ element.addEventListener(eventType, handler, capture);
157
+ }
158
+ const byEvent = getOrCreateElementHandlers(element);
159
+ const entry = byEvent.get(eventType) ?? {};
160
+ byEvent.set(eventType, entry);
161
+ if (options.multi) {
162
+ if (capture) {
163
+ if (!entry.captureSet) entry.captureSet = /* @__PURE__ */ new Set();
164
+ entry.captureSet.add(handler);
165
+ } else {
166
+ if (!entry.bubbleSet) entry.bubbleSet = /* @__PURE__ */ new Set();
167
+ entry.bubbleSet.add(handler);
168
+ }
169
+ } else {
170
+ if (capture) {
171
+ entry.capture = handler;
172
+ } else {
173
+ entry.bubble = handler;
174
+ }
175
+ }
176
+ };
177
+ const isEntryEmpty = (entry) => !entry.capture && !entry.bubble && (!entry.captureSet || entry.captureSet.size === 0) && (!entry.bubbleSet || entry.bubbleSet.size === 0);
178
+ const removeDelegatedEvent = (target, eventType, handler, _options = {}) => {
179
+ const byEvent = elementHandlerMap.get(target);
180
+ if (!byEvent) return;
181
+ const entry = byEvent.get(eventType);
182
+ if (!entry) return;
183
+ if (handler) {
184
+ if (entry.captureSet) {
185
+ entry.captureSet.delete(handler);
186
+ }
187
+ if (entry.bubbleSet) {
188
+ entry.bubbleSet.delete(handler);
189
+ }
190
+ if (entry.capture === handler) {
191
+ entry.capture = void 0;
192
+ }
193
+ if (entry.bubble === handler) {
194
+ entry.bubble = void 0;
195
+ }
196
+ target.removeEventListener(eventType, handler, true);
197
+ target.removeEventListener(eventType, handler, false);
198
+ } else {
199
+ entry.capture = void 0;
200
+ entry.bubble = void 0;
201
+ entry.captureSet = void 0;
202
+ entry.bubbleSet = void 0;
203
+ }
204
+ if (isEntryEmpty(entry)) {
205
+ byEvent.delete(eventType);
206
+ }
207
+ };
208
+ const clearDelegatedEvents = (target) => {
209
+ const byEvent = elementHandlerMap.get(target);
210
+ if (!byEvent) return;
211
+ byEvent.clear();
212
+ };
213
+ const clearDelegatedEventsDeep = (root) => {
214
+ clearDelegatedEvents(root);
215
+ const doc = root.ownerDocument;
216
+ if (!doc) return;
217
+ const walker = doc.createTreeWalker(
218
+ root,
219
+ 1
220
+ /* NodeFilter.SHOW_ELEMENT */
221
+ );
222
+ let node = walker.nextNode();
223
+ while (node) {
224
+ clearDelegatedEvents(node);
225
+ node = walker.nextNode();
226
+ }
227
+ };
228
+ const getRegisteredEventTypes = (element) => {
229
+ const byEvent = elementHandlerMap.get(element);
230
+ if (!byEvent) return /* @__PURE__ */ new Set();
231
+ return new Set(byEvent.keys());
232
+ };
233
+ const getRegisteredEventKeys = (element) => {
234
+ const byEvent = elementHandlerMap.get(element);
235
+ if (!byEvent) return /* @__PURE__ */ new Set();
236
+ const keys = /* @__PURE__ */ new Set();
237
+ for (const [eventType, entry] of byEvent) {
238
+ if (entry.bubble || entry.bubbleSet?.size) keys.add(`${eventType}:bubble`);
239
+ if (entry.capture || entry.captureSet?.size)
240
+ keys.add(`${eventType}:capture`);
241
+ }
242
+ return keys;
243
+ };
244
+ const removeDelegatedEventByKey = (element, eventType, phase) => {
245
+ const byEvent = elementHandlerMap.get(element);
246
+ if (!byEvent) return;
247
+ const entry = byEvent.get(eventType);
248
+ if (!entry) return;
249
+ if (phase === "capture") {
250
+ entry.capture = void 0;
251
+ entry.captureSet = void 0;
252
+ } else {
253
+ entry.bubble = void 0;
254
+ entry.bubbleSet = void 0;
255
+ }
256
+ if (isEntryEmpty(entry)) byEvent.delete(eventType);
257
+ };
258
+
259
+ const CLASS_ATTRIBUTE_NAME = "class";
260
+ const XLINK_ATTRIBUTE_NAME = "xlink";
261
+ const XMLNS_ATTRIBUTE_NAME = "xmlns";
262
+ const REF_ATTRIBUTE_NAME = "ref";
263
+ const DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE = "dangerouslySetInnerHTML";
264
+ const nsMap = {
265
+ [XMLNS_ATTRIBUTE_NAME]: "http://www.w3.org/2000/xmlns/",
266
+ [XLINK_ATTRIBUTE_NAME]: "http://www.w3.org/1999/xlink",
267
+ svg: "http://www.w3.org/2000/svg"
268
+ };
269
+ const observeUnmount = (domNode, onUnmount) => {
270
+ if (!domNode || typeof onUnmount !== "function") {
271
+ throw new Error(
272
+ "Invalid arguments. Ensure domNode and onUnmount are valid."
273
+ );
274
+ }
275
+ if (typeof MutationObserver === "undefined") {
276
+ return;
277
+ }
278
+ let parentNode = domNode.parentNode;
279
+ if (!parentNode) {
280
+ throw new Error("The provided domNode does not have a parentNode.");
281
+ }
282
+ const observer = new MutationObserver((mutationsList) => {
283
+ for (const mutation of mutationsList) {
284
+ if (mutation.removedNodes.length > 0) {
285
+ for (const removedNode of mutation.removedNodes) {
286
+ if (removedNode === domNode) {
287
+ queueMicrotask(() => {
288
+ if (!domNode.isConnected) {
289
+ onUnmount();
290
+ observer.disconnect();
291
+ return;
292
+ }
293
+ const newParent = domNode.parentNode;
294
+ if (newParent && newParent !== parentNode) {
295
+ parentNode = newParent;
296
+ observer.disconnect();
297
+ observer.observe(parentNode, { childList: true });
298
+ }
299
+ });
300
+ return;
301
+ }
302
+ }
303
+ }
304
+ }
305
+ });
306
+ observer.observe(parentNode, { childList: true });
307
+ };
308
+ const handleLifecycleEventsForOnMount = (newEl) => {
309
+ if (typeof newEl?.$onMount === "function") {
310
+ newEl.$onMount(newEl);
311
+ newEl.$onMount = null;
312
+ }
313
+ if (typeof newEl?.$onUnmount === "function") {
314
+ observeUnmount(newEl, newEl.$onUnmount);
315
+ }
316
+ };
317
+ const getRenderer = (document) => {
318
+ const renderer = {
319
+ hasElNamespace: (domElement) => domElement.namespaceURI === nsMap.svg,
320
+ hasSvgNamespace: (parentElement, type) => renderer.hasElNamespace(parentElement) && type !== "STYLE" && type !== "SCRIPT",
321
+ createElementOrElements: (virtualNode, parentDomElement) => {
322
+ if (Array.isArray(virtualNode)) {
323
+ return renderer.createChildElements(virtualNode, parentDomElement);
324
+ }
325
+ if (typeof virtualNode !== "undefined") {
326
+ return renderer.createElement(virtualNode, parentDomElement);
327
+ }
328
+ return renderer.createTextNode("", parentDomElement);
329
+ },
330
+ createElement: (virtualNode, parentDomElement) => {
331
+ let newEl;
332
+ try {
333
+ if (typeof virtualNode === "function" && virtualNode.constructor.name === "AsyncFunction") {
334
+ newEl = document.createElement("div");
335
+ } else if (typeof virtualNode === "object" && virtualNode !== null && "type" in virtualNode) {
336
+ const vNode = virtualNode;
337
+ if (typeof vNode.type === "function") {
338
+ newEl = document.createElement("div");
339
+ newEl.innerText = `FATAL ERROR: ${vNode.type._error}`;
340
+ } else if (
341
+ // SVG support
342
+ typeof vNode.type === "string" && vNode.type.toUpperCase() === "SVG" || parentDomElement && renderer.hasSvgNamespace(
343
+ parentDomElement,
344
+ typeof vNode.type === "string" ? vNode.type.toUpperCase() : ""
345
+ )
346
+ ) {
347
+ newEl = document.createElementNS(nsMap.svg, vNode.type);
348
+ } else {
349
+ newEl = document.createElement(vNode.type);
350
+ }
351
+ if (vNode.attributes) {
352
+ renderer.setAttributes(vNode, newEl);
353
+ if (vNode.attributes.dangerouslySetInnerHTML) {
354
+ newEl.innerHTML = vNode.attributes.dangerouslySetInnerHTML.__html;
355
+ }
356
+ }
357
+ if (vNode.children && !vNode.attributes?.dangerouslySetInnerHTML) {
358
+ renderer.createChildElements(vNode.children, newEl);
359
+ }
360
+ } else {
361
+ if (typeof virtualNode === "string" || typeof virtualNode === "number") {
362
+ newEl = document.createElement(String(virtualNode));
363
+ }
364
+ }
365
+ if (newEl && parentDomElement) {
366
+ parentDomElement.appendChild(newEl);
367
+ handleLifecycleEventsForOnMount(newEl);
368
+ }
369
+ } catch (e) {
370
+ console.error(
371
+ "Fatal error! Error happend while rendering the VDOM!",
372
+ e,
373
+ virtualNode
374
+ );
375
+ throw e;
376
+ }
377
+ return newEl;
378
+ },
379
+ createTextNode: (text, domElement) => {
380
+ const node = document.createTextNode(text.toString());
381
+ if (domElement) {
382
+ domElement.appendChild(node);
383
+ }
384
+ return node;
385
+ },
386
+ createChildElements: (virtualChildren, domElement) => {
387
+ const children = [];
388
+ for (let i = 0; i < virtualChildren.length; i++) {
389
+ const virtualChild = virtualChildren[i];
390
+ if (typeof virtualChild === "boolean") {
391
+ continue;
392
+ }
393
+ if (virtualChild === null || typeof virtualChild !== "object" && typeof virtualChild !== "function") {
394
+ children.push(
395
+ renderer.createTextNode(
396
+ (typeof virtualChild === "undefined" || virtualChild === null ? "" : virtualChild).toString(),
397
+ domElement
398
+ )
399
+ );
400
+ } else {
401
+ children.push(
402
+ renderer.createElement(virtualChild, domElement)
403
+ );
404
+ }
405
+ }
406
+ return children;
407
+ },
408
+ setAttribute: (name, value, domElement) => {
409
+ if (typeof value === "undefined") return;
410
+ if (name === DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE) return;
411
+ if (name === "key") {
412
+ domElement._defussKey = String(value);
413
+ return;
414
+ }
415
+ if (name === REF_ATTRIBUTE_NAME && typeof value !== "function") {
416
+ const ref = value;
417
+ ref.current = domElement;
418
+ domElement._defussRef = value;
419
+ domElement.$onUnmount = queueCallback(() => {
420
+ });
421
+ if (domElement.parentNode) {
422
+ observeUnmount(domElement, domElement.$onUnmount);
423
+ } else {
424
+ queueMicrotask(() => {
425
+ if (domElement.parentNode) {
426
+ observeUnmount(domElement, domElement.$onUnmount);
427
+ }
428
+ });
429
+ }
430
+ return;
431
+ }
432
+ const parsed = parseEventPropName(name);
433
+ if (parsed && typeof value === "function") {
434
+ const { eventType, capture } = parsed;
435
+ if (eventType === "mount") {
436
+ domElement.$onMount = queueCallback(value);
437
+ return;
438
+ }
439
+ if (eventType === "unmount") {
440
+ if (domElement.$onUnmount) {
441
+ const existingUnmount = domElement.$onUnmount;
442
+ domElement.$onUnmount = () => {
443
+ existingUnmount();
444
+ value();
445
+ };
446
+ } else {
447
+ domElement.$onUnmount = queueCallback(value);
448
+ }
449
+ return;
450
+ }
451
+ registerDelegatedEvent(
452
+ domElement,
453
+ eventType,
454
+ value,
455
+ { capture }
456
+ );
457
+ return;
458
+ }
459
+ if (name === "className") {
460
+ name = CLASS_ATTRIBUTE_NAME;
461
+ }
462
+ if (name === CLASS_ATTRIBUTE_NAME && Array.isArray(value)) {
463
+ value = value.filter((val) => !!val).join(" ");
464
+ }
465
+ const nsEndIndex = name.match(/[A-Z]/)?.index;
466
+ if (renderer.hasElNamespace(domElement) && nsEndIndex) {
467
+ const ns = name.substring(0, nsEndIndex).toLowerCase();
468
+ const attrName = name.substring(nsEndIndex, name.length).toLowerCase();
469
+ const namespace = nsMap[ns] || null;
470
+ domElement.setAttributeNS(
471
+ namespace,
472
+ ns === XLINK_ATTRIBUTE_NAME || ns === XMLNS_ATTRIBUTE_NAME ? `${ns}:${attrName}` : name,
473
+ String(value)
474
+ );
475
+ } else if (name === "style" && typeof value !== "string") {
476
+ const styleObj = value;
477
+ for (const prop of Object.keys(styleObj)) {
478
+ domElement.style[prop] = String(
479
+ styleObj[prop]
480
+ );
481
+ }
482
+ } else if (typeof value === "boolean") {
483
+ domElement[name] = value;
484
+ if (value) {
485
+ domElement.setAttribute(name, "");
486
+ } else {
487
+ domElement.removeAttribute(name);
488
+ }
489
+ } else if (
490
+ // Controlled input props: use property assignment for live value,
491
+ // AND setAttribute so SSG serialization (w3c-xmlserializer) includes it
492
+ (name === "value" || name === "checked" || name === "selectedIndex") && (domElement.nodeName === "INPUT" || domElement.nodeName === "TEXTAREA" || domElement.nodeName === "SELECT")
493
+ ) {
494
+ domElement[name] = value;
495
+ if (name === "checked") {
496
+ if (value) {
497
+ domElement.setAttribute("checked", "");
498
+ } else {
499
+ domElement.removeAttribute("checked");
500
+ }
501
+ } else if (name === "value") {
502
+ domElement.setAttribute("value", String(value));
503
+ }
504
+ } else {
505
+ domElement.setAttribute(name, String(value));
506
+ }
507
+ },
508
+ setAttributes: (virtualNode, domElement) => {
509
+ const attrNames = Object.keys(virtualNode.attributes ?? {});
510
+ for (let i = 0; i < attrNames.length; i++) {
511
+ renderer.setAttribute(
512
+ attrNames[i],
513
+ virtualNode.attributes[attrNames[i]],
514
+ domElement
515
+ );
516
+ }
517
+ }
518
+ };
519
+ return renderer;
520
+ };
521
+
522
+ const FROM_DOM_MARKER = Symbol("defuss-morph.from-dom");
523
+ const HTML_BOOLEAN_ATTRIBUTES = /* @__PURE__ */ new Set([
524
+ "allowfullscreen",
525
+ "async",
526
+ "autofocus",
527
+ "autoplay",
528
+ "checked",
529
+ "controls",
530
+ "default",
531
+ "defer",
532
+ "disabled",
533
+ "formnovalidate",
534
+ "hidden",
535
+ "inert",
536
+ "ismap",
537
+ "itemscope",
538
+ "loop",
539
+ "multiple",
540
+ "muted",
541
+ "nomodule",
542
+ "novalidate",
543
+ "open",
544
+ "playsinline",
545
+ "readonly",
546
+ "required",
547
+ "reversed",
548
+ "selected"
549
+ ]);
550
+ const domAttributeToVNodeValue = (attr) => HTML_BOOLEAN_ATTRIBUTES.has(attr.name.toLowerCase()) ? true : attr.value;
551
+ function parseDOM(input, type, Parser) {
552
+ return new Parser().parseFromString(input, type);
553
+ }
554
+ function isSVG(input, Parser) {
555
+ const doc = parseDOM(input, "image/svg+xml", Parser);
556
+ if (!doc.documentElement) return false;
557
+ return doc.documentElement.nodeName.toLowerCase() === "svg";
558
+ }
559
+ function isHTML(input, Parser) {
560
+ const doc = parseDOM(input, "text/html", Parser);
561
+ return doc.documentElement.querySelectorAll("*").length > 2;
562
+ }
563
+ const isMarkup = (input, Parser) => input.indexOf("<") > -1 && input.indexOf(">") > -1 && (isHTML(input, Parser) || isSVG(input, Parser));
564
+ function renderMarkup(markup, Parser, doc) {
565
+ const parsed = doc ? doc : parseDOM(markup, getMimeType(markup, Parser), Parser);
566
+ if (parsed.body) return Array.from(parsed.body.childNodes);
567
+ return parsed.documentElement ? [parsed.documentElement] : [];
568
+ }
569
+ function getMimeType(input, Parser) {
570
+ if (isSVG(input, Parser)) {
571
+ return "image/svg+xml";
572
+ }
573
+ return "text/html";
574
+ }
575
+ function domNodeToVNode(node) {
576
+ if (node.nodeType === 3) {
577
+ return node.textContent || "";
578
+ }
579
+ if (node.nodeType === 1) {
580
+ const element = node;
581
+ const attributes = {};
582
+ for (let i = 0; i < element.attributes.length; i++) {
583
+ const attr = element.attributes[i];
584
+ attributes[attr.name] = domAttributeToVNodeValue(attr);
585
+ }
586
+ const children = [];
587
+ for (let i = 0; i < element.childNodes.length; i++) {
588
+ const childVNode = domNodeToVNode(element.childNodes[i]);
589
+ children.push(childVNode);
590
+ }
591
+ return {
592
+ type: element.tagName.toLowerCase(),
593
+ attributes: { ...attributes, [FROM_DOM_MARKER]: true },
594
+ children
595
+ };
596
+ }
597
+ return "";
598
+ }
599
+ function htmlStringToVNodes(html, Parser) {
600
+ const parser = new Parser();
601
+ const doc = parser.parseFromString(html, "text/html");
602
+ const vNodes = [];
603
+ for (let i = 0; i < doc.body.childNodes.length; i++) {
604
+ const vnode = domNodeToVNode(doc.body.childNodes[i]);
605
+ if (vnode !== "") {
606
+ vNodes.push(vnode);
607
+ }
608
+ }
609
+ return vNodes;
610
+ }
611
+
612
+ const areDomNodesEqual = (oldNode, newNode) => {
613
+ if (oldNode === newNode) return true;
614
+ if (oldNode.nodeType !== newNode.nodeType) return false;
615
+ if (oldNode.nodeType === 1) {
616
+ const oldElement = oldNode;
617
+ const newElement = newNode;
618
+ if (oldElement.tagName !== newElement.tagName) return false;
619
+ const oldAttrs = oldElement.attributes;
620
+ const newAttrs = newElement.attributes;
621
+ if (oldAttrs.length !== newAttrs.length) return false;
622
+ for (let i = 0; i < oldAttrs.length; i++) {
623
+ const oldAttr = oldAttrs[i];
624
+ const newAttrValue = newElement.getAttribute(oldAttr.name);
625
+ if (oldAttr.value !== newAttrValue) return false;
626
+ }
627
+ }
628
+ if (oldNode.nodeType === 3) {
629
+ if (oldNode.textContent !== newNode.textContent) return false;
630
+ }
631
+ return true;
632
+ };
633
+ function isTextLike(value) {
634
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
635
+ }
636
+ function isVNode(value) {
637
+ return Boolean(
638
+ value && typeof value === "object" && "type" in value
639
+ );
640
+ }
641
+ function toValidChild(child, lenient = false) {
642
+ if (child == null) return child;
643
+ if (isTextLike(child)) return child;
644
+ if (isVNode(child)) return child;
645
+ if (lenient && child && typeof child === "object" && "attributes" in child)
646
+ return child;
647
+ return void 0;
648
+ }
649
+ function normalizeChildren(input, lenient = false) {
650
+ const raw = [];
651
+ const pushChild = (child) => {
652
+ if (Array.isArray(child)) {
653
+ child.forEach(pushChild);
654
+ return;
655
+ }
656
+ const valid = toValidChild(child, lenient);
657
+ if (typeof valid === "undefined") return;
658
+ if (isVNode(valid) && (valid.type === "fragment" || valid.type === "Fragment")) {
659
+ const nested = Array.isArray(valid.children) ? valid.children : [];
660
+ nested.forEach(pushChild);
661
+ return;
662
+ }
663
+ if (valid === null || typeof valid === "undefined" || typeof valid === "boolean")
664
+ return;
665
+ raw.push(valid);
666
+ };
667
+ pushChild(input);
668
+ const fused = [];
669
+ let buffer = null;
670
+ const flush = () => {
671
+ if (buffer !== null && buffer.length > 0) fused.push(buffer);
672
+ buffer = null;
673
+ };
674
+ for (const child of raw) {
675
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
676
+ buffer = (buffer ?? "") + String(child);
677
+ continue;
678
+ }
679
+ flush();
680
+ fused.push(child);
681
+ }
682
+ flush();
683
+ return fused;
684
+ }
685
+ function getVNodeMatchKey(child) {
686
+ if (!child || typeof child !== "object") return null;
687
+ const key = child.attributes?.key;
688
+ if (typeof key === "string" || typeof key === "number")
689
+ return `k:${String(key)}`;
690
+ const id = child.attributes?.id;
691
+ if (typeof id === "string" && id.length > 0) return `id:${id}`;
692
+ return null;
693
+ }
694
+ function describePatchItem(child) {
695
+ if (child && typeof child === "object") {
696
+ return `<${typeof child.type === "string" ? child.type : "component"}>`;
697
+ }
698
+ return "plain text";
699
+ }
700
+ function getDomMatchKeys(node) {
701
+ if (node.nodeType !== 1) return [];
702
+ const el = node;
703
+ const keys = [];
704
+ const internalKey = el._defussKey;
705
+ if (internalKey) keys.push(`k:${internalKey}`);
706
+ const attrKey = el.getAttribute("key");
707
+ if (attrKey) keys.push(`k:${attrKey}`);
708
+ const id = el.id;
709
+ if (id) keys.push(`id:${id}`);
710
+ return keys;
711
+ }
712
+ function areNodeAndChildMatching(domNode, child) {
713
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
714
+ return domNode.nodeType === 3;
715
+ }
716
+ if (child && typeof child === "object") {
717
+ if (domNode.nodeType !== 1) return false;
718
+ const el = domNode;
719
+ const oldTag = el.tagName.toLowerCase();
720
+ const newTag = typeof child.type === "string" ? child.type.toLowerCase() : "";
721
+ if (!newTag || oldTag !== newTag) return false;
722
+ return true;
723
+ }
724
+ return false;
725
+ }
726
+ function createDomFromChild(child, globals) {
727
+ const renderer = getRenderer(globals.window.document);
728
+ if (child == null) return void 0;
729
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
730
+ return [globals.window.document.createTextNode(String(child))];
731
+ }
732
+ const created = renderer.createElementOrElements(child);
733
+ if (!created) return void 0;
734
+ const nodes = Array.isArray(created) ? created : [created];
735
+ return nodes.filter(Boolean);
736
+ }
737
+ function shouldPreserveFormStateAttribute(el, attrName, vnode) {
738
+ const tag = el.tagName.toLowerCase();
739
+ const hasExplicit = Object.hasOwn(vnode.attributes ?? {}, attrName);
740
+ if (hasExplicit) return false;
741
+ if (tag === "input") return attrName === "value" || attrName === "checked";
742
+ if (tag === "textarea") return attrName === "value";
743
+ if (tag === "select") return attrName === "value";
744
+ return false;
745
+ }
746
+ function patchElementInPlace(el, vnode, globals, mergeAttributes = false) {
747
+ const renderer = getRenderer(globals.window.document);
748
+ const existingAttrs = mergeAttributes ? [] : Array.from(el.attributes);
749
+ const nextAttrs = vnode.attributes ?? {};
750
+ for (const attr of existingAttrs) {
751
+ const { name } = attr;
752
+ if (name === "key") continue;
753
+ if (name.startsWith("on")) continue;
754
+ if (name === "class" && (Object.hasOwn(nextAttrs, "class") || Object.hasOwn(nextAttrs, "className"))) {
755
+ continue;
756
+ }
757
+ if (!Object.hasOwn(nextAttrs, name)) {
758
+ if (shouldPreserveFormStateAttribute(el, name, vnode)) continue;
759
+ el.removeAttribute(name);
760
+ }
761
+ }
762
+ const preserveDelegatedHandlers = mergeAttributes || Boolean(nextAttrs[FROM_DOM_MARKER]);
763
+ if (!preserveDelegatedHandlers) {
764
+ const registeredKeys = getRegisteredEventKeys(el);
765
+ const nextEventKeys = /* @__PURE__ */ new Set();
766
+ for (const propName of Object.keys(nextAttrs)) {
767
+ const parsed = parseEventPropName(propName);
768
+ if (parsed) {
769
+ const phase = parsed.capture ? "capture" : "bubble";
770
+ nextEventKeys.add(`${parsed.eventType}:${phase}`);
771
+ }
772
+ }
773
+ for (const key of registeredKeys) {
774
+ if (!nextEventKeys.has(key)) {
775
+ const [eventType, phase] = key.split(":");
776
+ removeDelegatedEventByKey(
777
+ el,
778
+ eventType,
779
+ phase
780
+ );
781
+ }
782
+ }
783
+ }
784
+ renderer.setAttributes(vnode, el);
785
+ handleLifecycleEventsForOnMount(el);
786
+ const d = vnode.attributes?.dangerouslySetInnerHTML;
787
+ if (d && typeof d === "object" && typeof d.__html === "string") {
788
+ el.innerHTML = d.__html;
789
+ return;
790
+ }
791
+ const tag = el.tagName.toLowerCase();
792
+ if (tag === "textarea") {
793
+ const isControlled = Object.hasOwn(nextAttrs, "value");
794
+ const isActive = el.ownerDocument?.activeElement === el;
795
+ if (isActive && !isControlled) return;
796
+ }
797
+ if (mergeAttributes && (vnode.children === void 0 || vnode.children.length === 0 && nextAttrs[FROM_DOM_MARKER]))
798
+ return;
799
+ morphDomDirect(el, vnode.children ?? [], globals);
800
+ }
801
+ function morphNode(domNode, child, globals, mergeAttributes = false) {
802
+ if (typeof child === "string" || typeof child === "number" || typeof child === "boolean") {
803
+ const text = String(child);
804
+ if (domNode.nodeType === 3) {
805
+ if (domNode.nodeValue !== text) domNode.nodeValue = text;
806
+ return domNode;
807
+ }
808
+ const next = globals.window.document.createTextNode(text);
809
+ domNode.parentNode?.replaceChild(next, domNode);
810
+ return next;
811
+ }
812
+ if (child && typeof child === "object") {
813
+ const newType = typeof child.type === "string" ? child.type : null;
814
+ if (!newType) return domNode;
815
+ if (domNode.nodeType !== 1) {
816
+ const created = createDomFromChild(child, globals);
817
+ const first = Array.isArray(created) ? created[0] : created;
818
+ if (!first) return null;
819
+ domNode.parentNode?.replaceChild(first, domNode);
820
+ handleLifecycleEventsForOnMount(first);
821
+ return first;
822
+ }
823
+ const el = domNode;
824
+ const oldTag = el.tagName.toLowerCase();
825
+ const newTag = newType.toLowerCase();
826
+ if (oldTag !== newTag) {
827
+ const created = createDomFromChild(child, globals);
828
+ const first = Array.isArray(created) ? created[0] : created;
829
+ if (!first) return null;
830
+ el.parentNode?.replaceChild(first, el);
831
+ handleLifecycleEventsForOnMount(first);
832
+ return first;
833
+ }
834
+ patchElementInPlace(el, child, globals, mergeAttributes);
835
+ return el;
836
+ }
837
+ domNode.parentNode?.removeChild(domNode);
838
+ return null;
839
+ }
840
+ const renderingNodes = /* @__PURE__ */ new WeakSet();
841
+ const pendingMorphs = /* @__PURE__ */ new Map();
842
+ const resolveGlobals = (el, globals) => {
843
+ if (globals) return globals;
844
+ const win = el?.ownerDocument?.defaultView ?? globalThis;
845
+ return { window: win };
846
+ };
847
+ function isAncestorRendering(el) {
848
+ let current = el.parentElement;
849
+ while (current) {
850
+ if (renderingNodes.has(current)) return true;
851
+ current = current.parentElement;
852
+ }
853
+ return false;
854
+ }
855
+ function flushPendingMorphs() {
856
+ if (pendingMorphs.size === 0) return;
857
+ const snapshot = [...pendingMorphs.entries()];
858
+ pendingMorphs.clear();
859
+ for (const [el, { vdom, globals, mode }] of snapshot) {
860
+ if (!el.isConnected) continue;
861
+ updateDomWithVdom(el, vdom, globals, mode);
862
+ }
863
+ }
864
+ function updateDomWithVdom(parentElement, newVDOM, globals, mode = "replace") {
865
+ const resolvedGlobals = resolveGlobals(parentElement, globals);
866
+ if (renderingNodes.has(parentElement) || isAncestorRendering(parentElement)) {
867
+ pendingMorphs.set(parentElement, {
868
+ vdom: newVDOM,
869
+ globals: resolvedGlobals,
870
+ mode
871
+ });
872
+ return;
873
+ }
874
+ renderingNodes.add(parentElement);
875
+ try {
876
+ morphDomDirect(parentElement, newVDOM, resolvedGlobals, mode);
877
+ } finally {
878
+ renderingNodes.delete(parentElement);
879
+ }
880
+ flushPendingMorphs();
881
+ }
882
+ function morphDiff(targetRoot, patchItems, globals) {
883
+ const keyedPool = /* @__PURE__ */ new Map();
884
+ for (const node of Array.from(targetRoot.childNodes)) {
885
+ for (const k of getDomMatchKeys(node)) {
886
+ if (!keyedPool.has(k)) keyedPool.set(k, node);
887
+ }
888
+ }
889
+ for (const item of patchItems) {
890
+ if (typeof item === "string" && item.trim() === "") continue;
891
+ const key = getVNodeMatchKey(item);
892
+ if (!key) {
893
+ throw new Error(
894
+ `morph diff: patch items must be elements with a key or id attribute (got ${describePatchItem(item)})`
895
+ );
896
+ }
897
+ const match = keyedPool.get(key);
898
+ if (match) {
899
+ const patchItem = item && typeof item === "object" && !item.type ? { ...item, type: match.tagName.toLowerCase() } : item;
900
+ morphNode(match, patchItem, globals, true);
901
+ continue;
902
+ }
903
+ if (!item?.type) {
904
+ throw new Error(
905
+ `morph diff: new (unmatched) patch items must declare a tag (type), got key/id "${key}"`
906
+ );
907
+ }
908
+ const created = createDomFromChild(item, globals) ?? [];
909
+ for (const node of created) {
910
+ targetRoot.appendChild(node);
911
+ handleLifecycleEventsForOnMount(node);
912
+ }
913
+ }
914
+ }
915
+ function morphDomDirect(parentElement, newVDOM, globals, mode = "replace") {
916
+ const el = parentElement;
917
+ const isCustomElement = el.tagName.includes("-");
918
+ const targetRoot = el.shadowRoot && !isCustomElement ? el.shadowRoot : parentElement;
919
+ const nextChildren = normalizeChildren(newVDOM, mode === "diff");
920
+ if (mode === "diff") {
921
+ morphDiff(targetRoot, nextChildren, globals);
922
+ return;
923
+ }
924
+ const existing = Array.from(targetRoot.childNodes);
925
+ const keyedPool = /* @__PURE__ */ new Map();
926
+ const nodeKeys = /* @__PURE__ */ new WeakMap();
927
+ const unkeyedPool = [];
928
+ for (const node of existing) {
929
+ const keys = getDomMatchKeys(node);
930
+ if (keys.length > 0) {
931
+ nodeKeys.set(node, keys);
932
+ let addedToKeyedPool = false;
933
+ for (const k of keys) {
934
+ if (!keyedPool.has(k)) {
935
+ keyedPool.set(k, node);
936
+ addedToKeyedPool = true;
937
+ }
938
+ }
939
+ if (!addedToKeyedPool) {
940
+ unkeyedPool.push(node);
941
+ }
942
+ } else {
943
+ unkeyedPool.push(node);
944
+ }
945
+ }
946
+ const consumeKeyedNode = (node) => {
947
+ const keys = nodeKeys.get(node) ?? [];
948
+ for (const k of keys) keyedPool.delete(k);
949
+ };
950
+ const takeUnkeyedMatch = (child) => {
951
+ for (let i = 0; i < unkeyedPool.length; i++) {
952
+ const candidate = unkeyedPool[i];
953
+ if (areNodeAndChildMatching(candidate, child)) {
954
+ unkeyedPool.splice(i, 1);
955
+ return candidate;
956
+ }
957
+ }
958
+ return void 0;
959
+ };
960
+ let domIndex = 0;
961
+ for (const child of nextChildren) {
962
+ const key = getVNodeMatchKey(child);
963
+ let match;
964
+ if (key) {
965
+ match = keyedPool.get(key);
966
+ if (match) consumeKeyedNode(match);
967
+ } else {
968
+ match = takeUnkeyedMatch(child);
969
+ }
970
+ const anchor = targetRoot.childNodes[domIndex] ?? null;
971
+ if (match) {
972
+ if (match !== anchor) {
973
+ targetRoot.insertBefore(match, anchor);
974
+ }
975
+ morphNode(match, child, globals);
976
+ domIndex++;
977
+ continue;
978
+ }
979
+ const created = createDomFromChild(child, globals);
980
+ if (!created || Array.isArray(created) && created.length === 0) continue;
981
+ const nodes = Array.isArray(created) ? created : [created];
982
+ for (const node of nodes) {
983
+ targetRoot.insertBefore(node, anchor);
984
+ handleLifecycleEventsForOnMount(node);
985
+ domIndex++;
986
+ }
987
+ }
988
+ const remaining = /* @__PURE__ */ new Set();
989
+ for (const node of unkeyedPool) remaining.add(node);
990
+ for (const node of keyedPool.values()) remaining.add(node);
991
+ for (const node of remaining) {
992
+ if (node.parentNode === targetRoot) {
993
+ if (node.nodeType === 1) {
994
+ clearDelegatedEventsDeep(node);
995
+ }
996
+ targetRoot.removeChild(node);
997
+ }
998
+ }
999
+ }
1000
+ function replaceDomWithVdom(parentElement, newVDOM, globals) {
1001
+ const resolvedGlobals = resolveGlobals(parentElement, globals);
1002
+ while (parentElement.firstChild) {
1003
+ parentElement.removeChild(parentElement.firstChild);
1004
+ }
1005
+ const renderer = getRenderer(resolvedGlobals.window.document);
1006
+ const newDom = renderer.createElementOrElements(
1007
+ newVDOM
1008
+ );
1009
+ if (Array.isArray(newDom)) {
1010
+ for (const node of newDom) {
1011
+ if (node) {
1012
+ parentElement.appendChild(node);
1013
+ handleLifecycleEventsForOnMount(node);
1014
+ }
1015
+ }
1016
+ } else if (newDom) {
1017
+ parentElement.appendChild(newDom);
1018
+ handleLifecycleEventsForOnMount(newDom);
1019
+ }
1020
+ }
1021
+
1022
+ const injectShakeKeyframes = (doc) => {
1023
+ if (!doc) return;
1024
+ if (!doc.getElementById("defuss-shake")) {
1025
+ const style = doc.createElement("style");
1026
+ style.id = "defuss-shake";
1027
+ 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)}}";
1028
+ doc.head.appendChild(style);
1029
+ }
1030
+ };
1031
+ const getTransitionStyles = (type, duration, easing = "ease-in-out") => {
1032
+ const t = `transform ${duration}ms ${easing}, opacity ${duration}ms ${easing}`;
1033
+ const styles = {
1034
+ fade: {
1035
+ enter: { opacity: "0", transition: t, transform: "translate3d(0,0,0)" },
1036
+ enterActive: { opacity: "1" },
1037
+ exit: { opacity: "1", transition: t, transform: "translate3d(0,0,0)" },
1038
+ exitActive: { opacity: "0" }
1039
+ },
1040
+ "slide-left": {
1041
+ enter: {
1042
+ transform: "translate3d(100%,0,0)",
1043
+ opacity: "0.5",
1044
+ transition: t
1045
+ },
1046
+ enterActive: { transform: "translate3d(0,0,0)", opacity: "1" },
1047
+ exit: { transform: "translate3d(0,0,0)", opacity: "1", transition: t },
1048
+ exitActive: { transform: "translate3d(-100%,0,0)", opacity: "0.5" }
1049
+ },
1050
+ "slide-right": {
1051
+ enter: {
1052
+ transform: "translate3d(-100%,0,0)",
1053
+ opacity: "0.5",
1054
+ transition: t
1055
+ },
1056
+ enterActive: { transform: "translate3d(0,0,0)", opacity: "1" },
1057
+ exit: { transform: "translate3d(0,0,0)", opacity: "1", transition: t },
1058
+ exitActive: { transform: "translate3d(100%,0,0)", opacity: "0.5" }
1059
+ },
1060
+ shake: (() => {
1061
+ injectShakeKeyframes(
1062
+ typeof document !== "undefined" ? document : void 0
1063
+ );
1064
+ return {
1065
+ enter: {
1066
+ transform: "translate3d(0,0,0)",
1067
+ opacity: "1",
1068
+ transition: "none"
1069
+ },
1070
+ enterActive: {
1071
+ transform: "translate3d(0,0,0)",
1072
+ opacity: "1",
1073
+ animation: `shake ${duration}ms cubic-bezier(0.36,0.07,0.19,0.97)`
1074
+ },
1075
+ exit: {
1076
+ transform: "translate3d(0,0,0)",
1077
+ opacity: "1",
1078
+ transition: "none"
1079
+ },
1080
+ exitActive: {
1081
+ transform: "translate3d(0,0,0)",
1082
+ opacity: "1",
1083
+ animation: `shake ${duration}ms cubic-bezier(0.36,0.07,0.19,0.97)`
1084
+ }
1085
+ };
1086
+ })()
1087
+ };
1088
+ return styles[type] || { enter: {}, enterActive: {}, exit: {}, exitActive: {} };
1089
+ };
1090
+ const applyStyles = (el, styles) => Object.entries(styles).forEach(
1091
+ ([k, v]) => el.style.setProperty(k, String(v))
1092
+ );
1093
+ const DEFAULT_TRANSITION_CONFIG = {
1094
+ type: "fade",
1095
+ duration: 300,
1096
+ easing: "ease-in-out",
1097
+ delay: 0,
1098
+ target: "parent"
1099
+ };
1100
+ const wait = (ms) => new Promise((r) => setTimeout(r, ms));
1101
+ const performCrossfade = async (element, updateCallback, duration, easing) => {
1102
+ const originalStyle = element.style.cssText;
1103
+ const snapshot = element.cloneNode(true);
1104
+ const doc = element.ownerDocument;
1105
+ try {
1106
+ const rect = element.getBoundingClientRect();
1107
+ 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;`;
1108
+ element.style.opacity = "0";
1109
+ element.style.transition = `opacity ${duration}ms ${easing}`;
1110
+ doc.body.appendChild(snapshot);
1111
+ await updateCallback();
1112
+ void element.offsetHeight;
1113
+ snapshot.style.opacity = "0";
1114
+ element.style.opacity = "1";
1115
+ await wait(duration);
1116
+ doc.body.removeChild(snapshot);
1117
+ } catch (error) {
1118
+ if (snapshot.parentElement) doc.body.removeChild(snapshot);
1119
+ throw error;
1120
+ } finally {
1121
+ element.style.cssText = originalStyle;
1122
+ }
1123
+ };
1124
+ const performTransition = async (element, updateCallback, config = {}) => {
1125
+ const {
1126
+ type = "fade",
1127
+ duration = 300,
1128
+ easing = "ease-in-out",
1129
+ delay = 0
1130
+ } = { ...DEFAULT_TRANSITION_CONFIG, ...config };
1131
+ if (type === "none") {
1132
+ await updateCallback();
1133
+ return;
1134
+ }
1135
+ if (delay > 0) await wait(delay);
1136
+ if (type === "fade") {
1137
+ await performCrossfade(element, updateCallback, duration, easing);
1138
+ return;
1139
+ }
1140
+ const styles = config.styles || getTransitionStyles(type, duration, easing);
1141
+ const originalTransition = element.style.transition;
1142
+ const originalAnimation = element.style.animation;
1143
+ try {
1144
+ if (type === "shake") {
1145
+ element.style.animation = "none";
1146
+ void element.offsetHeight;
1147
+ }
1148
+ applyStyles(element, styles.exit);
1149
+ void element.offsetHeight;
1150
+ applyStyles(element, styles.exitActive);
1151
+ await wait(duration);
1152
+ await updateCallback();
1153
+ applyStyles(element, styles.enter);
1154
+ void element.offsetHeight;
1155
+ applyStyles(element, styles.enterActive);
1156
+ await wait(duration);
1157
+ element.style.transition = originalTransition;
1158
+ element.style.animation = originalAnimation;
1159
+ } catch (error) {
1160
+ element.style.transition = originalTransition;
1161
+ element.style.animation = originalAnimation;
1162
+ throw error;
1163
+ }
1164
+ };
1165
+
1166
+ const inflightTransitions = /* @__PURE__ */ new WeakMap();
1167
+ const morph = (el, newContent, options = {}) => {
1168
+ const globals = resolveGlobals(el);
1169
+ const win = globals.window;
1170
+ const mode = options.diff ? "diff" : "replace";
1171
+ const apply = (content) => updateDomWithVdom(
1172
+ el,
1173
+ typeof content === "string" ? htmlStringToVNodes(content, win.DOMParser) : content,
1174
+ globals,
1175
+ mode
1176
+ );
1177
+ const transition = options.transition;
1178
+ if (transition && transition.type !== "none") {
1179
+ const config = { ...DEFAULT_TRANSITION_CONFIG, ...transition };
1180
+ const transitionTarget = config.target === "self" ? el : el.parentElement;
1181
+ if (!transitionTarget) {
1182
+ apply(newContent);
1183
+ return;
1184
+ }
1185
+ const slot2 = { content: newContent };
1186
+ inflightTransitions.set(el, slot2);
1187
+ return performTransition(
1188
+ transitionTarget,
1189
+ // apply the latest requested content — but only if this transition
1190
+ // still owns the slot; when a newer transition has taken it over (or
1191
+ // already completed and cleaned it up), this deferred update is stale
1192
+ // and must not clobber the newer content
1193
+ async () => {
1194
+ if (inflightTransitions.get(el) === slot2) apply(slot2.content);
1195
+ },
1196
+ config
1197
+ ).finally(() => {
1198
+ if (inflightTransitions.get(el) === slot2) inflightTransitions.delete(el);
1199
+ });
1200
+ }
1201
+ const slot = inflightTransitions.get(el);
1202
+ if (slot) slot.content = newContent;
1203
+ apply(newContent);
1204
+ };
1205
+
1206
+ exports.CAPTURE_ONLY_EVENTS = CAPTURE_ONLY_EVENTS;
1207
+ exports.CLASS_ATTRIBUTE_NAME = CLASS_ATTRIBUTE_NAME;
1208
+ exports.DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE = DANGEROUSLY_SET_INNER_HTML_ATTRIBUTE;
1209
+ exports.DEFAULT_TRANSITION_CONFIG = DEFAULT_TRANSITION_CONFIG;
1210
+ exports.FROM_DOM_MARKER = FROM_DOM_MARKER;
1211
+ exports.REF_ATTRIBUTE_NAME = REF_ATTRIBUTE_NAME;
1212
+ exports.XLINK_ATTRIBUTE_NAME = XLINK_ATTRIBUTE_NAME;
1213
+ exports.XMLNS_ATTRIBUTE_NAME = XMLNS_ATTRIBUTE_NAME;
1214
+ exports.applyStyles = applyStyles;
1215
+ exports.areDomNodesEqual = areDomNodesEqual;
1216
+ exports.clearDelegatedEvents = clearDelegatedEvents;
1217
+ exports.clearDelegatedEventsDeep = clearDelegatedEventsDeep;
1218
+ exports.domNodeToVNode = domNodeToVNode;
1219
+ exports.getMimeType = getMimeType;
1220
+ exports.getRegisteredEventKeys = getRegisteredEventKeys;
1221
+ exports.getRegisteredEventTypes = getRegisteredEventTypes;
1222
+ exports.getRenderer = getRenderer;
1223
+ exports.getTransitionStyles = getTransitionStyles;
1224
+ exports.handleLifecycleEventsForOnMount = handleLifecycleEventsForOnMount;
1225
+ exports.htmlStringToVNodes = htmlStringToVNodes;
1226
+ exports.isHTML = isHTML;
1227
+ exports.isMarkup = isMarkup;
1228
+ exports.isSVG = isSVG;
1229
+ exports.morph = morph;
1230
+ exports.nsMap = nsMap;
1231
+ exports.observeUnmount = observeUnmount;
1232
+ exports.parseDOM = parseDOM;
1233
+ exports.parseEventPropName = parseEventPropName;
1234
+ exports.performTransition = performTransition;
1235
+ exports.queueCallback = queueCallback;
1236
+ exports.registerDelegatedEvent = registerDelegatedEvent;
1237
+ exports.removeDelegatedEvent = removeDelegatedEvent;
1238
+ exports.removeDelegatedEventByKey = removeDelegatedEventByKey;
1239
+ exports.renderMarkup = renderMarkup;
1240
+ exports.replaceDomWithVdom = replaceDomWithVdom;
1241
+ exports.resolveGlobals = resolveGlobals;
1242
+ exports.updateDomWithVdom = updateDomWithVdom;