4cd4fd28
郭伟龙
feat: 初始化项目
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// @flow
import { isShadowRoot } from './instanceOf';
export default function contains(parent: Element, child: Element) {
const rootNode = child.getRootNode && child.getRootNode();
// First, attempt with faster native method
if (parent.contains(child)) {
return true;
}
// then fallback to custom implementation with Shadow DOM support
else if (rootNode && isShadowRoot(rootNode)) {
let next = child;
do {
if (next && parent.isSameNode(next)) {
return true;
}
// $FlowFixMe[prop-missing]: need a better way to handle this...
next = next.parentNode || next.host;
} while (next);
}
// Give up, the result is false
return false;
}
|