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