You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
759 B
19 lines
759 B
import getNodeName from "./getNodeName.js";
|
|
import getDocumentElement from "./getDocumentElement.js";
|
|
import { isShadowRoot } from "./instanceOf.js";
|
|
export default function getParentNode(element) {
|
|
if (getNodeName(element) === 'html') {
|
|
return element;
|
|
}
|
|
|
|
return (// this is a quicker (but less type safe) way to save quite some bytes from the bundle
|
|
// $FlowFixMe[incompatible-return]
|
|
// $FlowFixMe[prop-missing]
|
|
element.assignedSlot || // step into the shadow DOM of the parent of a slotted node
|
|
element.parentNode || ( // DOM Element detected
|
|
isShadowRoot(element) ? element.host : null) || // ShadowRoot detected
|
|
// $FlowFixMe[incompatible-call]: HTMLElement is a Node
|
|
getDocumentElement(element) // fallback
|
|
|
|
);
|
|
}
|