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

Function _findBestMatch

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

Source from the content-addressed store, hash-verified

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