(ctx, oldParent, newParent, insertionPoint = null, endPoint = null)
| 3561 | } |
| 3562 | }; |
| 3563 | function _morphChildren(ctx, oldParent, newParent, insertionPoint = null, endPoint = null) { |
| 3564 | if (oldParent instanceof HTMLTemplateElement && newParent instanceof HTMLTemplateElement) { |
| 3565 | oldParent = oldParent.content; |
| 3566 | newParent = newParent.content; |
| 3567 | } |
| 3568 | insertionPoint ||= oldParent.firstChild; |
| 3569 | let newChild = newParent.firstChild; |
| 3570 | while (newChild) { |
| 3571 | let matchedNode; |
| 3572 | if (insertionPoint && insertionPoint !== endPoint) { |
| 3573 | matchedNode = _findBestMatch(ctx, newChild, insertionPoint, endPoint); |
| 3574 | if (matchedNode && matchedNode !== insertionPoint) { |
| 3575 | let cursor = insertionPoint; |
| 3576 | while (cursor && cursor !== matchedNode) { |
| 3577 | let tempNode = cursor; |
| 3578 | cursor = cursor.nextSibling; |
| 3579 | if (tempNode instanceof Element && (ctx.idMap.has(tempNode) || _matchesUpcomingSibling(ctx, tempNode, newChild))) { |
| 3580 | _moveBefore(oldParent, tempNode, endPoint); |
| 3581 | } else { |
| 3582 | _removeNode(ctx, tempNode); |
| 3583 | } |
| 3584 | } |
| 3585 | } |
| 3586 | } |
| 3587 | if (!matchedNode && newChild instanceof Element && ctx.persistentIds.has(newChild.id)) { |
| 3588 | let escapedId = CSS.escape(newChild.id); |
| 3589 | matchedNode = ctx.target.id === newChild.id && ctx.target || ctx.target.querySelector('[id="' + escapedId + '"]') || ctx.pantry.querySelector('[id="' + escapedId + '"]'); |
| 3590 | let element = matchedNode; |
| 3591 | while (element = element.parentNode) { |
| 3592 | let idSet = ctx.idMap.get(element); |
| 3593 | if (idSet) { |
| 3594 | idSet.delete(matchedNode.id); |
| 3595 | if (!idSet.size) ctx.idMap.delete(element); |
| 3596 | } |
| 3597 | } |
| 3598 | _moveBefore(oldParent, matchedNode, insertionPoint); |
| 3599 | } |
| 3600 | if (matchedNode) { |
| 3601 | _morphNode(matchedNode, newChild, ctx); |
| 3602 | insertionPoint = matchedNode.nextSibling; |
| 3603 | newChild = newChild.nextSibling; |
| 3604 | continue; |
| 3605 | } |
| 3606 | let nextNewChild = newChild.nextSibling; |
| 3607 | if (ctx.idMap.has(newChild)) { |
| 3608 | let placeholder = document.createElement(newChild.tagName); |
| 3609 | oldParent.insertBefore(placeholder, insertionPoint); |
| 3610 | _morphNode(placeholder, newChild, ctx); |
| 3611 | insertionPoint = placeholder.nextSibling; |
| 3612 | } else { |
| 3613 | oldParent.insertBefore(newChild, insertionPoint); |
| 3614 | ctx.callbacks.afterNodeAdded?.(newChild); |
| 3615 | insertionPoint = newChild.nextSibling; |
| 3616 | } |
| 3617 | newChild = nextNewChild; |
| 3618 | } |
| 3619 | while (insertionPoint && insertionPoint !== endPoint) { |
| 3620 | let tempNode = insertionPoint; |
no test coverage detected