MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / _findBestMatch

Function _findBestMatch

www/js/_hyperscript-max.js:3635–3658  ·  view source on GitHub ↗
(ctx, node, startPoint, endPoint)

Source from the content-addressed store, hash-verified

3633 ctx.callbacks.afterNodeMorphed?.(oldNode);
3634 }
3635 function _findBestMatch(ctx, node, startPoint, endPoint) {
3636 if (!(node instanceof Element)) return null;
3637 var softMatch = null, displaceMatchCount = 0, scanLimit = 10;
3638 var newSet = ctx.idMap.get(node), nodeMatchCount = newSet?.size || 0;
3639 if (node.id && !newSet) return null;
3640 var cursor = startPoint;
3641 while (cursor && cursor !== endPoint) {
3642 var oldSet = ctx.idMap.get(cursor);
3643 if (_isSoftMatch(cursor, node)) {
3644 if (oldSet && newSet && [...oldSet].some((id) => newSet.has(id))) return cursor;
3645 if (!oldSet) {
3646 if (scanLimit > 0 && cursor.isEqualNode(node)) return cursor;
3647 if (!softMatch) softMatch = cursor;
3648 }
3649 }
3650 displaceMatchCount += oldSet?.size || 0;
3651 if (displaceMatchCount > nodeMatchCount) break;
3652 if (cursor.contains(document.activeElement)) break;
3653 if (--scanLimit < 1 && nodeMatchCount === 0) break;
3654 cursor = cursor.nextSibling;
3655 }
3656 if (softMatch && _matchesUpcomingSibling(ctx, softMatch, node)) return null;
3657 return softMatch;
3658 }
3659 function _matchesUpcomingSibling(ctx, oldElt, startNode) {
3660 if (ctx.futureMatches.has(oldElt)) return true;
3661 for (var sibling = startNode.nextSibling, i = 0; sibling && i < 10; sibling = sibling.nextSibling, i++) {

Callers 1

_morphChildrenFunction · 0.70

Calls 4

_isSoftMatchFunction · 0.70
_matchesUpcomingSiblingFunction · 0.70
getMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected