@swiftwc/ui 0.0.0-dev.86 → 0.0.0-dev.88

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 (41) hide show
  1. package/generated/components/bordered-button.js +1 -1
  2. package/generated/components/bordered-prominent-button.js +1 -1
  3. package/generated/components/borderless-button.js +1 -1
  4. package/generated/components/date-picker.js +4 -3
  5. package/generated/components/glass-button.js +1 -1
  6. package/generated/components/glass-prominent-button.js +1 -1
  7. package/generated/components/image-view.js +10 -11
  8. package/generated/components/label-view.js +13 -10
  9. package/generated/components/labeled-content.js +43 -23
  10. package/generated/components/menu-view.js +3 -2
  11. package/generated/components/navigation-title.js +22 -16
  12. package/generated/components/picker-view.js +13 -8
  13. package/generated/components/progress-view.js +4 -3
  14. package/generated/components/scroll-view.js +26 -7
  15. package/generated/components/section-view.js +33 -17
  16. package/generated/components/table-view.js +5 -6
  17. package/generated/components/text-field.js +3 -2
  18. package/generated/components/toggle-view.js +3 -2
  19. package/generated/components/tool-bar-item.js +2 -2
  20. package/generated/internal/utils/ensure-placeholder.d.ts +1 -1
  21. package/generated/internal/utils/ensure-placeholder.js +74 -34
  22. package/generated/internal/utils/index.d.ts +0 -3
  23. package/generated/internal/utils/index.js +0 -3
  24. package/generated/internal/vendor/morphdom.d.ts +6 -0
  25. package/generated/internal/vendor/morphdom.js +720 -0
  26. package/generated/morphdom/html.d.ts +8 -0
  27. package/generated/morphdom/html.js +37 -0
  28. package/generated/morphdom/index.d.ts +6 -0
  29. package/generated/morphdom/index.js +6 -0
  30. package/generated/morphdom/morph.d.ts +4 -0
  31. package/generated/morphdom/morph.js +9 -0
  32. package/generated/morphdom/query-morph.d.ts +5 -0
  33. package/generated/morphdom/query-morph.js +12 -0
  34. package/package.json +4 -3
  35. package/web-components.html-data/en.json +3 -0
  36. package/generated/internal/utils/render-label-icon.d.ts +0 -2
  37. package/generated/internal/utils/render-label-icon.js +0 -19
  38. package/generated/internal/utils/render-label-title.d.ts +0 -2
  39. package/generated/internal/utils/render-label-title.js +0 -16
  40. package/generated/internal/utils/render-label.d.ts +0 -1
  41. package/generated/internal/utils/render-label.js +0 -19
@@ -0,0 +1,720 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * VENDORIZED FROM https://github.com/patrick-steele-idem/morphdom/blob/master/dist/morphdom-esm.js
4
+ * at 2026-06-21
5
+ */
6
+ var DOCUMENT_FRAGMENT_NODE = 11;
7
+ function morphAttrs(fromNode, toNode) {
8
+ var toNodeAttrs = toNode.attributes;
9
+ var attr;
10
+ var attrName;
11
+ var attrNamespaceURI;
12
+ var attrValue;
13
+ var fromValue;
14
+ // document-fragments dont have attributes so lets not do anything
15
+ if (toNode.nodeType === DOCUMENT_FRAGMENT_NODE || fromNode.nodeType === DOCUMENT_FRAGMENT_NODE) {
16
+ return;
17
+ }
18
+ // update attributes on original DOM element
19
+ for (var i = toNodeAttrs.length - 1; i >= 0; i--) {
20
+ attr = toNodeAttrs[i];
21
+ attrName = attr.name;
22
+ attrNamespaceURI = attr.namespaceURI;
23
+ attrValue = attr.value;
24
+ if (attrNamespaceURI) {
25
+ attrName = attr.localName || attrName;
26
+ fromValue = fromNode.getAttributeNS(attrNamespaceURI, attrName);
27
+ if (fromValue !== attrValue) {
28
+ if (attr.prefix === 'xmlns') {
29
+ attrName = attr.name; // It's not allowed to set an attribute with the XMLNS namespace without specifying the `xmlns` prefix
30
+ }
31
+ fromNode.setAttributeNS(attrNamespaceURI, attrName, attrValue);
32
+ }
33
+ }
34
+ else {
35
+ fromValue = fromNode.getAttribute(attrName);
36
+ if (fromValue !== attrValue) {
37
+ fromNode.setAttribute(attrName, attrValue);
38
+ }
39
+ }
40
+ }
41
+ // Remove any extra attributes found on the original DOM element that
42
+ // weren't found on the target element.
43
+ var fromNodeAttrs = fromNode.attributes;
44
+ for (var d = fromNodeAttrs.length - 1; d >= 0; d--) {
45
+ attr = fromNodeAttrs[d];
46
+ attrName = attr.name;
47
+ attrNamespaceURI = attr.namespaceURI;
48
+ if (attrNamespaceURI) {
49
+ attrName = attr.localName || attrName;
50
+ if (!toNode.hasAttributeNS(attrNamespaceURI, attrName)) {
51
+ fromNode.removeAttributeNS(attrNamespaceURI, attrName);
52
+ }
53
+ }
54
+ else {
55
+ if (!toNode.hasAttribute(attrName)) {
56
+ fromNode.removeAttribute(attrName);
57
+ }
58
+ }
59
+ }
60
+ }
61
+ var range; // Create a range object for efficently rendering strings to elements.
62
+ var NS_XHTML = 'http://www.w3.org/1999/xhtml';
63
+ var doc = typeof document === 'undefined' ? undefined : document;
64
+ var HAS_TEMPLATE_SUPPORT = !!doc && 'content' in doc.createElement('template');
65
+ var HAS_RANGE_SUPPORT = !!doc && doc.createRange && 'createContextualFragment' in doc.createRange();
66
+ function createFragmentFromTemplate(str) {
67
+ var template = doc.createElement('template');
68
+ template.innerHTML = str;
69
+ return template.content.childNodes[0];
70
+ }
71
+ function createFragmentFromRange(str) {
72
+ if (!range) {
73
+ range = doc.createRange();
74
+ range.selectNode(doc.body);
75
+ }
76
+ var fragment = range.createContextualFragment(str);
77
+ return fragment.childNodes[0];
78
+ }
79
+ function createFragmentFromWrap(str) {
80
+ var fragment = doc.createElement('body');
81
+ fragment.innerHTML = str;
82
+ return fragment.childNodes[0];
83
+ }
84
+ /**
85
+ * This is about the same
86
+ * var html = new DOMParser().parseFromString(str, 'text/html');
87
+ * return html.body.firstChild;
88
+ *
89
+ * @method toElement
90
+ * @param {String} str
91
+ */
92
+ function toElement(str) {
93
+ str = str.trim();
94
+ if (HAS_TEMPLATE_SUPPORT) {
95
+ // avoid restrictions on content for things like `<tr><th>Hi</th></tr>` which
96
+ // createContextualFragment doesn't support
97
+ // <template> support not available in IE
98
+ return createFragmentFromTemplate(str);
99
+ }
100
+ else if (HAS_RANGE_SUPPORT) {
101
+ return createFragmentFromRange(str);
102
+ }
103
+ return createFragmentFromWrap(str);
104
+ }
105
+ /**
106
+ * Returns true if two node's names are the same.
107
+ *
108
+ * NOTE: We don't bother checking `namespaceURI` because you will never find two HTML elements with the same
109
+ * nodeName and different namespace URIs.
110
+ *
111
+ * @param {Element} a
112
+ * @param {Element} b The target element
113
+ * @return {boolean}
114
+ */
115
+ function compareNodeNames(fromEl, toEl) {
116
+ var fromNodeName = fromEl.nodeName;
117
+ var toNodeName = toEl.nodeName;
118
+ var fromCodeStart, toCodeStart;
119
+ if (fromNodeName === toNodeName) {
120
+ return true;
121
+ }
122
+ fromCodeStart = fromNodeName.charCodeAt(0);
123
+ toCodeStart = toNodeName.charCodeAt(0);
124
+ // If the target element is a virtual DOM node or SVG node then we may
125
+ // need to normalize the tag name before comparing. Normal HTML elements that are
126
+ // in the "http://www.w3.org/1999/xhtml"
127
+ // are converted to upper case
128
+ if (fromCodeStart <= 90 && toCodeStart >= 97) {
129
+ // from is upper and to is lower
130
+ return fromNodeName === toNodeName.toUpperCase();
131
+ }
132
+ else if (toCodeStart <= 90 && fromCodeStart >= 97) {
133
+ // to is upper and from is lower
134
+ return toNodeName === fromNodeName.toUpperCase();
135
+ }
136
+ else {
137
+ return false;
138
+ }
139
+ }
140
+ /**
141
+ * Create an element, optionally with a known namespace URI.
142
+ *
143
+ * @param {string} name the element name, e.g. 'div' or 'svg'
144
+ * @param {string} [namespaceURI] the element's namespace URI, i.e. the value of
145
+ * its `xmlns` attribute or its inferred namespace.
146
+ *
147
+ * @return {Element}
148
+ */
149
+ function createElementNS(name, namespaceURI) {
150
+ return !namespaceURI || namespaceURI === NS_XHTML ? doc.createElement(name) : doc.createElementNS(namespaceURI, name);
151
+ }
152
+ /**
153
+ * Copies the children of one DOM element to another DOM element
154
+ */
155
+ function moveChildren(fromEl, toEl) {
156
+ var curChild = fromEl.firstChild;
157
+ while (curChild) {
158
+ var nextChild = curChild.nextSibling;
159
+ toEl.appendChild(curChild);
160
+ curChild = nextChild;
161
+ }
162
+ return toEl;
163
+ }
164
+ function syncBooleanAttrProp(fromEl, toEl, name) {
165
+ if (fromEl[name] !== toEl[name]) {
166
+ fromEl[name] = toEl[name];
167
+ if (fromEl[name]) {
168
+ fromEl.setAttribute(name, '');
169
+ }
170
+ else {
171
+ fromEl.removeAttribute(name);
172
+ }
173
+ }
174
+ }
175
+ var specialElHandlers = {
176
+ OPTION: function (fromEl, toEl) {
177
+ var parentNode = fromEl.parentNode;
178
+ if (parentNode) {
179
+ var parentName = parentNode.nodeName.toUpperCase();
180
+ if (parentName === 'OPTGROUP') {
181
+ parentNode = parentNode.parentNode;
182
+ parentName = parentNode && parentNode.nodeName.toUpperCase();
183
+ }
184
+ if (parentName === 'SELECT' && !parentNode.hasAttribute('multiple')) {
185
+ if (fromEl.hasAttribute('selected') && !toEl.selected) {
186
+ // Workaround for MS Edge bug where the 'selected' attribute can only be
187
+ // removed if set to a non-empty value:
188
+ // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12087679/
189
+ fromEl.setAttribute('selected', 'selected');
190
+ fromEl.removeAttribute('selected');
191
+ }
192
+ // We have to reset select element's selectedIndex to -1, otherwise setting
193
+ // fromEl.selected using the syncBooleanAttrProp below has no effect.
194
+ // The correct selectedIndex will be set in the SELECT special handler below.
195
+ parentNode.selectedIndex = -1;
196
+ }
197
+ }
198
+ syncBooleanAttrProp(fromEl, toEl, 'selected');
199
+ },
200
+ /**
201
+ * The "value" attribute is special for the <input> element since it sets
202
+ * the initial value. Changing the "value" attribute without changing the
203
+ * "value" property will have no effect since it is only used to the set the
204
+ * initial value. Similar for the "checked" attribute, and "disabled".
205
+ */
206
+ INPUT: function (fromEl, toEl) {
207
+ syncBooleanAttrProp(fromEl, toEl, 'checked');
208
+ syncBooleanAttrProp(fromEl, toEl, 'disabled');
209
+ if (fromEl.value !== toEl.value) {
210
+ fromEl.value = toEl.value;
211
+ }
212
+ if (!toEl.hasAttribute('value')) {
213
+ fromEl.removeAttribute('value');
214
+ }
215
+ },
216
+ TEXTAREA: function (fromEl, toEl) {
217
+ var newValue = toEl.value;
218
+ if (fromEl.value !== newValue) {
219
+ fromEl.value = newValue;
220
+ }
221
+ var firstChild = fromEl.firstChild;
222
+ if (firstChild) {
223
+ // Needed for IE. Apparently IE sets the placeholder as the
224
+ // node value and vise versa. This ignores an empty update.
225
+ var oldValue = firstChild.nodeValue;
226
+ if (oldValue == newValue || (!newValue && oldValue == fromEl.placeholder)) {
227
+ return;
228
+ }
229
+ firstChild.nodeValue = newValue;
230
+ }
231
+ },
232
+ SELECT: function (fromEl, toEl) {
233
+ if (!toEl.hasAttribute('multiple')) {
234
+ var selectedIndex = -1;
235
+ var i = 0;
236
+ // We have to loop through children of fromEl, not toEl since nodes can be moved
237
+ // from toEl to fromEl directly when morphing.
238
+ // At the time this special handler is invoked, all children have already been morphed
239
+ // and appended to / removed from fromEl, so using fromEl here is safe and correct.
240
+ var curChild = fromEl.firstChild;
241
+ var optgroup;
242
+ var nodeName;
243
+ while (curChild) {
244
+ nodeName = curChild.nodeName && curChild.nodeName.toUpperCase();
245
+ if (nodeName === 'OPTGROUP') {
246
+ optgroup = curChild;
247
+ curChild = optgroup.firstChild;
248
+ // handle empty optgroups
249
+ if (!curChild) {
250
+ curChild = optgroup.nextSibling;
251
+ optgroup = null;
252
+ }
253
+ }
254
+ else {
255
+ if (nodeName === 'OPTION') {
256
+ if (curChild.hasAttribute('selected')) {
257
+ selectedIndex = i;
258
+ break;
259
+ }
260
+ i++;
261
+ }
262
+ curChild = curChild.nextSibling;
263
+ if (!curChild && optgroup) {
264
+ curChild = optgroup.nextSibling;
265
+ optgroup = null;
266
+ }
267
+ }
268
+ }
269
+ fromEl.selectedIndex = selectedIndex;
270
+ }
271
+ },
272
+ };
273
+ var ELEMENT_NODE = 1;
274
+ var DOCUMENT_FRAGMENT_NODE$1 = 11;
275
+ var TEXT_NODE = 3;
276
+ var COMMENT_NODE = 8;
277
+ function noop() { }
278
+ function defaultGetNodeKey(node) {
279
+ if (node) {
280
+ return (node.getAttribute && node.getAttribute('id')) || node.id;
281
+ }
282
+ }
283
+ function morphdomFactory(morphAttrs) {
284
+ return function morphdom(fromNode, toNode, options) {
285
+ if (!options) {
286
+ options = {};
287
+ }
288
+ if (typeof toNode === 'string') {
289
+ if (fromNode.nodeName === '#document' || fromNode.nodeName === 'HTML') {
290
+ var toNodeHtml = toNode;
291
+ toNode = doc.createElement('html');
292
+ toNode.innerHTML = toNodeHtml;
293
+ }
294
+ else if (fromNode.nodeName === 'BODY') {
295
+ var toNodeBody = toNode;
296
+ toNode = doc.createElement('html');
297
+ toNode.innerHTML = toNodeBody;
298
+ // Extract the body element from the created HTML structure
299
+ var bodyElement = toNode.querySelector('body');
300
+ if (bodyElement) {
301
+ toNode = bodyElement;
302
+ }
303
+ }
304
+ else {
305
+ toNode = toElement(toNode);
306
+ }
307
+ }
308
+ else if (toNode.nodeType === DOCUMENT_FRAGMENT_NODE$1) {
309
+ toNode = toNode.firstElementChild;
310
+ }
311
+ var getNodeKey = options.getNodeKey || defaultGetNodeKey;
312
+ var onBeforeNodeAdded = options.onBeforeNodeAdded || noop;
313
+ var onNodeAdded = options.onNodeAdded || noop;
314
+ var onBeforeElUpdated = options.onBeforeElUpdated || noop;
315
+ var onElUpdated = options.onElUpdated || noop;
316
+ var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop;
317
+ var onNodeDiscarded = options.onNodeDiscarded || noop;
318
+ var onBeforeElChildrenUpdated = options.onBeforeElChildrenUpdated || noop;
319
+ var skipFromChildren = options.skipFromChildren || noop;
320
+ var addChild = options.addChild ||
321
+ function (parent, child) {
322
+ return parent.appendChild(child);
323
+ };
324
+ var childrenOnly = options.childrenOnly === true;
325
+ // This object is used as a lookup to quickly find all keyed elements in the original DOM tree.
326
+ var fromNodesLookup = Object.create(null);
327
+ var keyedRemovalList = [];
328
+ function addKeyedRemoval(key) {
329
+ keyedRemovalList.push(key);
330
+ }
331
+ function walkDiscardedChildNodes(node, skipKeyedNodes) {
332
+ if (node.nodeType === ELEMENT_NODE) {
333
+ var curChild = node.firstChild;
334
+ while (curChild) {
335
+ var key = undefined;
336
+ if (skipKeyedNodes && (key = getNodeKey(curChild))) {
337
+ // If we are skipping keyed nodes then we add the key
338
+ // to a list so that it can be handled at the very end.
339
+ addKeyedRemoval(key);
340
+ }
341
+ else {
342
+ // Only report the node as discarded if it is not keyed. We do this because
343
+ // at the end we loop through all keyed elements that were unmatched
344
+ // and then discard them in one final pass.
345
+ onNodeDiscarded(curChild);
346
+ if (curChild.firstChild) {
347
+ walkDiscardedChildNodes(curChild, skipKeyedNodes);
348
+ }
349
+ }
350
+ curChild = curChild.nextSibling;
351
+ }
352
+ }
353
+ }
354
+ /**
355
+ * Removes a DOM node out of the original DOM
356
+ *
357
+ * @param {Node} node The node to remove
358
+ * @param {Node} parentNode The nodes parent
359
+ * @param {Boolean} skipKeyedNodes If true then elements with keys will be skipped and not discarded.
360
+ * @return {undefined}
361
+ */
362
+ function removeNode(node, parentNode, skipKeyedNodes) {
363
+ if (onBeforeNodeDiscarded(node) === false) {
364
+ return;
365
+ }
366
+ if (parentNode) {
367
+ parentNode.removeChild(node);
368
+ }
369
+ onNodeDiscarded(node);
370
+ walkDiscardedChildNodes(node, skipKeyedNodes);
371
+ }
372
+ // // TreeWalker implementation is no faster, but keeping this around in case this changes in the future
373
+ // function indexTree(root) {
374
+ // var treeWalker = document.createTreeWalker(
375
+ // root,
376
+ // NodeFilter.SHOW_ELEMENT);
377
+ //
378
+ // var el;
379
+ // while((el = treeWalker.nextNode())) {
380
+ // var key = getNodeKey(el);
381
+ // if (key) {
382
+ // fromNodesLookup[key] = el;
383
+ // }
384
+ // }
385
+ // }
386
+ // // NodeIterator implementation is no faster, but keeping this around in case this changes in the future
387
+ //
388
+ // function indexTree(node) {
389
+ // var nodeIterator = document.createNodeIterator(node, NodeFilter.SHOW_ELEMENT);
390
+ // var el;
391
+ // while((el = nodeIterator.nextNode())) {
392
+ // var key = getNodeKey(el);
393
+ // if (key) {
394
+ // fromNodesLookup[key] = el;
395
+ // }
396
+ // }
397
+ // }
398
+ function indexTree(node) {
399
+ if (node.nodeType === ELEMENT_NODE || node.nodeType === DOCUMENT_FRAGMENT_NODE$1) {
400
+ var curChild = node.firstChild;
401
+ while (curChild) {
402
+ var key = getNodeKey(curChild);
403
+ if (key) {
404
+ fromNodesLookup[key] = curChild;
405
+ }
406
+ // Walk recursively
407
+ indexTree(curChild);
408
+ curChild = curChild.nextSibling;
409
+ }
410
+ }
411
+ }
412
+ indexTree(fromNode);
413
+ function handleNodeAdded(el) {
414
+ onNodeAdded(el);
415
+ var curChild = el.firstChild;
416
+ while (curChild) {
417
+ var nextSibling = curChild.nextSibling;
418
+ var key = getNodeKey(curChild);
419
+ if (key) {
420
+ var unmatchedFromEl = fromNodesLookup[key];
421
+ // if we find a duplicate #id node in cache, replace `el` with cache value
422
+ // and morph it to the child node.
423
+ if (unmatchedFromEl && compareNodeNames(curChild, unmatchedFromEl)) {
424
+ curChild.parentNode.replaceChild(unmatchedFromEl, curChild);
425
+ morphEl(unmatchedFromEl, curChild);
426
+ }
427
+ else {
428
+ handleNodeAdded(curChild);
429
+ }
430
+ }
431
+ else {
432
+ // recursively call for curChild and it's children to see if we find something in
433
+ // fromNodesLookup
434
+ handleNodeAdded(curChild);
435
+ }
436
+ curChild = nextSibling;
437
+ }
438
+ }
439
+ function cleanupFromEl(fromEl, curFromNodeChild, curFromNodeKey) {
440
+ // We have processed all of the "to nodes". If curFromNodeChild is
441
+ // non-null then we still have some from nodes left over that need
442
+ // to be removed
443
+ while (curFromNodeChild) {
444
+ var fromNextSibling = curFromNodeChild.nextSibling;
445
+ if ((curFromNodeKey = getNodeKey(curFromNodeChild))) {
446
+ // Since the node is keyed it might be matched up later so we defer
447
+ // the actual removal to later
448
+ addKeyedRemoval(curFromNodeKey);
449
+ }
450
+ else {
451
+ // NOTE: we skip nested keyed nodes from being removed since there is
452
+ // still a chance they will be matched up later
453
+ removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
454
+ }
455
+ curFromNodeChild = fromNextSibling;
456
+ }
457
+ }
458
+ function morphEl(fromEl, toEl, childrenOnly) {
459
+ var toElKey = getNodeKey(toEl);
460
+ if (toElKey) {
461
+ // If an element with an ID is being morphed then it will be in the final
462
+ // DOM so clear it out of the saved elements collection
463
+ delete fromNodesLookup[toElKey];
464
+ }
465
+ if (!childrenOnly) {
466
+ // optional
467
+ var beforeUpdateResult = onBeforeElUpdated(fromEl, toEl);
468
+ if (beforeUpdateResult === false) {
469
+ return;
470
+ }
471
+ else if (beforeUpdateResult instanceof HTMLElement) {
472
+ fromEl = beforeUpdateResult;
473
+ // reindex the new fromEl in case it's not in the same
474
+ // tree as the original fromEl
475
+ // (Phoenix LiveView sometimes returns a cloned tree,
476
+ // but keyed lookups would still point to the original tree)
477
+ indexTree(fromEl);
478
+ }
479
+ // update attributes on original DOM element first
480
+ morphAttrs(fromEl, toEl);
481
+ // optional
482
+ onElUpdated(fromEl);
483
+ if (onBeforeElChildrenUpdated(fromEl, toEl) === false) {
484
+ return;
485
+ }
486
+ }
487
+ if (fromEl.nodeName !== 'TEXTAREA') {
488
+ morphChildren(fromEl, toEl);
489
+ }
490
+ else {
491
+ specialElHandlers.TEXTAREA(fromEl, toEl);
492
+ }
493
+ }
494
+ function morphChildren(fromEl, toEl) {
495
+ var skipFrom = skipFromChildren(fromEl, toEl);
496
+ var curToNodeChild = toEl.firstChild;
497
+ var curFromNodeChild = fromEl.firstChild;
498
+ var curToNodeKey;
499
+ var curFromNodeKey;
500
+ var fromNextSibling;
501
+ var toNextSibling;
502
+ var matchingFromEl;
503
+ // walk the children
504
+ outer: while (curToNodeChild) {
505
+ toNextSibling = curToNodeChild.nextSibling;
506
+ curToNodeKey = getNodeKey(curToNodeChild);
507
+ // walk the fromNode children all the way through
508
+ while (!skipFrom && curFromNodeChild) {
509
+ fromNextSibling = curFromNodeChild.nextSibling;
510
+ if (curToNodeChild.isSameNode && curToNodeChild.isSameNode(curFromNodeChild)) {
511
+ curToNodeChild = toNextSibling;
512
+ curFromNodeChild = fromNextSibling;
513
+ continue outer;
514
+ }
515
+ curFromNodeKey = getNodeKey(curFromNodeChild);
516
+ var curFromNodeType = curFromNodeChild.nodeType;
517
+ // this means if the curFromNodeChild doesnt have a match with the curToNodeChild
518
+ var isCompatible = undefined;
519
+ if (curFromNodeType === curToNodeChild.nodeType) {
520
+ if (curFromNodeType === ELEMENT_NODE) {
521
+ // Both nodes being compared are Element nodes
522
+ if (curToNodeKey) {
523
+ // The target node has a key so we want to match it up with the correct element
524
+ // in the original DOM tree
525
+ if (curToNodeKey !== curFromNodeKey) {
526
+ // The current element in the original DOM tree does not have a matching key so
527
+ // let's check our lookup to see if there is a matching element in the original
528
+ // DOM tree
529
+ if ((matchingFromEl = fromNodesLookup[curToNodeKey])) {
530
+ if (fromNextSibling === matchingFromEl) {
531
+ // Special case for single element removals. To avoid removing the original
532
+ // DOM node out of the tree (since that can break CSS transitions, etc.),
533
+ // we will instead discard the current node and wait until the next
534
+ // iteration to properly match up the keyed target element with its matching
535
+ // element in the original tree
536
+ isCompatible = false;
537
+ }
538
+ else {
539
+ // We found a matching keyed element somewhere in the original DOM tree.
540
+ // Let's move the original DOM node into the current position and morph
541
+ // it.
542
+ // NOTE: We use insertBefore instead of replaceChild because we want to go through
543
+ // the `removeNode()` function for the node that is being discarded so that
544
+ // all lifecycle hooks are correctly invoked
545
+ fromEl.insertBefore(matchingFromEl, curFromNodeChild);
546
+ // fromNextSibling = curFromNodeChild.nextSibling;
547
+ if (curFromNodeKey) {
548
+ // Since the node is keyed it might be matched up later so we defer
549
+ // the actual removal to later
550
+ addKeyedRemoval(curFromNodeKey);
551
+ }
552
+ else {
553
+ // NOTE: we skip nested keyed nodes from being removed since there is
554
+ // still a chance they will be matched up later
555
+ removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
556
+ }
557
+ curFromNodeChild = matchingFromEl;
558
+ curFromNodeKey = getNodeKey(curFromNodeChild);
559
+ }
560
+ }
561
+ else {
562
+ // The nodes are not compatible since the "to" node has a key and there
563
+ // is no matching keyed node in the source tree
564
+ isCompatible = false;
565
+ }
566
+ }
567
+ }
568
+ else if (curFromNodeKey) {
569
+ // The original has a key
570
+ isCompatible = false;
571
+ }
572
+ isCompatible = isCompatible !== false && compareNodeNames(curFromNodeChild, curToNodeChild);
573
+ if (isCompatible) {
574
+ // We found compatible DOM elements so transform
575
+ // the current "from" node to match the current
576
+ // target DOM node.
577
+ // MORPH
578
+ morphEl(curFromNodeChild, curToNodeChild);
579
+ }
580
+ }
581
+ else if (curFromNodeType === TEXT_NODE || curFromNodeType == COMMENT_NODE) {
582
+ // Both nodes being compared are Text or Comment nodes
583
+ isCompatible = true;
584
+ // Simply update nodeValue on the original node to
585
+ // change the text value
586
+ if (curFromNodeChild.nodeValue !== curToNodeChild.nodeValue) {
587
+ curFromNodeChild.nodeValue = curToNodeChild.nodeValue;
588
+ }
589
+ }
590
+ }
591
+ if (isCompatible) {
592
+ // Advance both the "to" child and the "from" child since we found a match
593
+ // Nothing else to do as we already recursively called morphChildren above
594
+ curToNodeChild = toNextSibling;
595
+ curFromNodeChild = fromNextSibling;
596
+ continue outer;
597
+ }
598
+ // No compatible match so remove the old node from the DOM and continue trying to find a
599
+ // match in the original DOM. However, we only do this if the from node is not keyed
600
+ // since it is possible that a keyed node might match up with a node somewhere else in the
601
+ // target tree and we don't want to discard it just yet since it still might find a
602
+ // home in the final DOM tree. After everything is done we will remove any keyed nodes
603
+ // that didn't find a home
604
+ if (curFromNodeKey) {
605
+ // Since the node is keyed it might be matched up later so we defer
606
+ // the actual removal to later
607
+ addKeyedRemoval(curFromNodeKey);
608
+ }
609
+ else {
610
+ // NOTE: we skip nested keyed nodes from being removed since there is
611
+ // still a chance they will be matched up later
612
+ removeNode(curFromNodeChild, fromEl, true /* skip keyed nodes */);
613
+ }
614
+ curFromNodeChild = fromNextSibling;
615
+ } // END: while(curFromNodeChild) {}
616
+ // If we got this far then we did not find a candidate match for
617
+ // our "to node" and we exhausted all of the children "from"
618
+ // nodes. Therefore, we will just append the current "to" node
619
+ // to the end
620
+ if (curToNodeKey && (matchingFromEl = fromNodesLookup[curToNodeKey]) && compareNodeNames(matchingFromEl, curToNodeChild)) {
621
+ // MORPH
622
+ if (!skipFrom) {
623
+ addChild(fromEl, matchingFromEl);
624
+ }
625
+ morphEl(matchingFromEl, curToNodeChild);
626
+ }
627
+ else {
628
+ var onBeforeNodeAddedResult = onBeforeNodeAdded(curToNodeChild);
629
+ if (onBeforeNodeAddedResult !== false) {
630
+ if (onBeforeNodeAddedResult) {
631
+ curToNodeChild = onBeforeNodeAddedResult;
632
+ }
633
+ if (curToNodeChild.actualize) {
634
+ curToNodeChild = curToNodeChild.actualize(fromEl.ownerDocument || doc);
635
+ }
636
+ addChild(fromEl, curToNodeChild);
637
+ handleNodeAdded(curToNodeChild);
638
+ }
639
+ }
640
+ curToNodeChild = toNextSibling;
641
+ curFromNodeChild = fromNextSibling;
642
+ }
643
+ cleanupFromEl(fromEl, curFromNodeChild, curFromNodeKey);
644
+ var specialElHandler = specialElHandlers[fromEl.nodeName];
645
+ if (specialElHandler) {
646
+ specialElHandler(fromEl, toEl);
647
+ }
648
+ } // END: morphChildren(...)
649
+ var morphedNode = fromNode;
650
+ var morphedNodeType = morphedNode.nodeType;
651
+ var toNodeType = toNode.nodeType;
652
+ if (!childrenOnly) {
653
+ // Handle the case where we are given two DOM nodes that are not
654
+ // compatible (e.g. <div> --> <span> or <div> --> TEXT)
655
+ if (morphedNodeType === ELEMENT_NODE) {
656
+ if (toNodeType === ELEMENT_NODE) {
657
+ if (!compareNodeNames(fromNode, toNode)) {
658
+ onNodeDiscarded(fromNode);
659
+ morphedNode = moveChildren(fromNode, createElementNS(toNode.nodeName, toNode.namespaceURI));
660
+ }
661
+ }
662
+ else {
663
+ // Going from an element node to a text node
664
+ morphedNode = toNode;
665
+ }
666
+ }
667
+ else if (morphedNodeType === TEXT_NODE || morphedNodeType === COMMENT_NODE) {
668
+ // Text or comment node
669
+ if (toNodeType === morphedNodeType) {
670
+ if (morphedNode.nodeValue !== toNode.nodeValue) {
671
+ morphedNode.nodeValue = toNode.nodeValue;
672
+ }
673
+ return morphedNode;
674
+ }
675
+ else {
676
+ // Text node to something else
677
+ morphedNode = toNode;
678
+ }
679
+ }
680
+ }
681
+ if (morphedNode === toNode) {
682
+ // The "to node" was not compatible with the "from node" so we had to
683
+ // toss out the "from node" and use the "to node"
684
+ onNodeDiscarded(fromNode);
685
+ }
686
+ else {
687
+ if (toNode.isSameNode && toNode.isSameNode(morphedNode)) {
688
+ return;
689
+ }
690
+ morphEl(morphedNode, toNode, childrenOnly);
691
+ // We now need to loop over any keyed nodes that might need to be
692
+ // removed. We only do the removal if we know that the keyed node
693
+ // never found a match. When a keyed node is matched up we remove
694
+ // it out of fromNodesLookup and we use fromNodesLookup to determine
695
+ // if a keyed node has been matched up or not
696
+ if (keyedRemovalList) {
697
+ for (var i = 0, len = keyedRemovalList.length; i < len; i++) {
698
+ var elToRemove = fromNodesLookup[keyedRemovalList[i]];
699
+ if (elToRemove) {
700
+ removeNode(elToRemove, elToRemove.parentNode, false);
701
+ }
702
+ }
703
+ }
704
+ }
705
+ if (!childrenOnly && morphedNode !== fromNode && fromNode.parentNode) {
706
+ if (morphedNode.actualize) {
707
+ morphedNode = morphedNode.actualize(fromNode.ownerDocument || doc);
708
+ }
709
+ // If we had to swap out the from node with a new node because the old
710
+ // node was not compatible with the target node then we need to
711
+ // replace the old DOM node in the original DOM tree. This is only
712
+ // possible if the original DOM node was part of a DOM tree which
713
+ // we know is the case if it has a parent node.
714
+ fromNode.parentNode.replaceChild(morphedNode, fromNode);
715
+ }
716
+ return morphedNode;
717
+ };
718
+ }
719
+ var morphdom = morphdomFactory(morphAttrs);
720
+ export default morphdom;