Initial commit

This commit is contained in:
2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 changed files with 5280367 additions and 0 deletions
@@ -0,0 +1,29 @@
import { getParent } from './getParent';
/**
* Similar functionality to `element.contains` DOM API for use without of order DOM elements that
* checks the virtual parent hierarchy. If a virtual parents exists, it is chosen over the actual parent
*
* @internal
* @returns true if the child can find the parent in its virtual hierarchy
*/ export function elementContains(parent, child) {
if (!parent || !child) {
return false;
}
if (parent === child) {
return true;
} else {
// Tracks references of nodes that have been visited to prevent infinite loops
const set = new WeakSet();
while(child){
const nextParent = getParent(child, {
skipVirtual: set.has(child)
});
set.add(child);
if (nextParent === parent) {
return true;
}
child = nextParent;
}
}
return false;
}