(ctx, node, startPoint, endPoint)
| 3474 | ctx.callbacks.afterNodeMorphed?.(oldNode); |
| 3475 | } |
| 3476 | function _findBestMatch(ctx, node, startPoint, endPoint) { |
| 3477 | if (!(node instanceof Element)) return null; |
| 3478 | var softMatch = null, displaceMatchCount = 0, scanLimit = 10; |
| 3479 | var newSet = ctx.idMap.get(node), nodeMatchCount = newSet?.size || 0; |
| 3480 | if (node.id && !newSet) return null; |
| 3481 | var cursor = startPoint; |
| 3482 | while (cursor && cursor !== endPoint) { |
| 3483 | var oldSet = ctx.idMap.get(cursor); |
| 3484 | if (_isSoftMatch(cursor, node)) { |
| 3485 | if (oldSet && newSet && [...oldSet].some((id) => newSet.has(id))) return cursor; |
| 3486 | if (!oldSet) { |
| 3487 | if (scanLimit > 0 && cursor.isEqualNode(node)) return cursor; |
| 3488 | if (!softMatch) softMatch = cursor; |
| 3489 | } |
| 3490 | } |
| 3491 | displaceMatchCount += oldSet?.size || 0; |
| 3492 | if (displaceMatchCount > nodeMatchCount) break; |
| 3493 | if (cursor.contains(document.activeElement)) break; |
| 3494 | if (--scanLimit < 1 && nodeMatchCount === 0) break; |
| 3495 | cursor = cursor.nextSibling; |
| 3496 | } |
| 3497 | if (softMatch && _matchesUpcomingSibling(ctx, softMatch, node)) return null; |
| 3498 | return softMatch; |
| 3499 | } |
| 3500 | function _matchesUpcomingSibling(ctx, oldElt, startNode) { |
| 3501 | if (ctx.futureMatches.has(oldElt)) return true; |
| 3502 | for (var sibling = startNode.nextSibling, i = 0; sibling && i < 10; sibling = sibling.nextSibling, i++) { |
no test coverage detected