(ctx, oldParent, newParent, insertionPoint = null, endPoint = null)
| 3401 | } |
| 3402 | }; |
| 3403 | function _morphChildren(ctx, oldParent, newParent, insertionPoint = null, endPoint = null) { |
| 3404 | if (oldParent instanceof HTMLTemplateElement && newParent instanceof HTMLTemplateElement) { |
| 3405 | oldParent = oldParent.content; |
| 3406 | newParent = newParent.content; |
| 3407 | } |
| 3408 | insertionPoint ||= oldParent.firstChild; |
| 3409 | let newChild = newParent.firstChild; |
| 3410 | while (newChild) { |
| 3411 | let matchedNode; |
| 3412 | if (insertionPoint && insertionPoint !== endPoint) { |
| 3413 | matchedNode = _findBestMatch(ctx, newChild, insertionPoint, endPoint); |
| 3414 | if (matchedNode && matchedNode !== insertionPoint) { |
| 3415 | let cursor = insertionPoint; |
| 3416 | while (cursor && cursor !== matchedNode) { |
| 3417 | let tempNode = cursor; |
| 3418 | cursor = cursor.nextSibling; |
| 3419 | if (tempNode instanceof Element && (ctx.idMap.has(tempNode) || _matchesUpcomingSibling(ctx, tempNode, newChild))) { |
| 3420 | _moveBefore(oldParent, tempNode, endPoint); |
| 3421 | } else { |
| 3422 | _removeNode(ctx, tempNode); |
| 3423 | } |
| 3424 | } |
| 3425 | } |
| 3426 | } |
| 3427 | if (!matchedNode && newChild instanceof Element && ctx.persistentIds.has(newChild.id)) { |
| 3428 | let escapedId = CSS.escape(newChild.id); |
| 3429 | matchedNode = ctx.target.id === newChild.id && ctx.target || ctx.target.querySelector('[id="' + escapedId + '"]') || ctx.pantry.querySelector('[id="' + escapedId + '"]'); |
| 3430 | let element = matchedNode; |
| 3431 | while (element = element.parentNode) { |
| 3432 | let idSet = ctx.idMap.get(element); |
| 3433 | if (idSet) { |
| 3434 | idSet.delete(matchedNode.id); |
| 3435 | if (!idSet.size) ctx.idMap.delete(element); |
| 3436 | } |
| 3437 | } |
| 3438 | _moveBefore(oldParent, matchedNode, insertionPoint); |
| 3439 | } |
| 3440 | if (matchedNode) { |
| 3441 | _morphNode(matchedNode, newChild, ctx); |
| 3442 | insertionPoint = matchedNode.nextSibling; |
| 3443 | newChild = newChild.nextSibling; |
| 3444 | continue; |
| 3445 | } |
| 3446 | let nextNewChild = newChild.nextSibling; |
| 3447 | if (ctx.idMap.has(newChild)) { |
| 3448 | let placeholder = document.createElement(newChild.tagName); |
| 3449 | oldParent.insertBefore(placeholder, insertionPoint); |
| 3450 | _morphNode(placeholder, newChild, ctx); |
| 3451 | insertionPoint = placeholder.nextSibling; |
| 3452 | } else { |
| 3453 | oldParent.insertBefore(newChild, insertionPoint); |
| 3454 | ctx.callbacks.afterNodeAdded?.(newChild); |
| 3455 | insertionPoint = newChild.nextSibling; |
| 3456 | } |
| 3457 | newChild = nextNewChild; |
| 3458 | } |
| 3459 | while (insertionPoint && insertionPoint !== endPoint) { |
| 3460 | let tempNode = insertionPoint; |
no test coverage detected