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

Function _findBestMatch

www/js/_hyperscript.js:3636–3659  ·  view source on GitHub ↗
(ctx, node, startPoint, endPoint)

Source from the content-addressed store, hash-verified

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