dom.mjs 769 B

123456789101112131415161718192021222324
  1. /**
  2. * Returns:
  3. * - 'null' if the node is not attached to the DOM
  4. * - the root node (HTMLDocument | ShadowRoot) otherwise
  5. */
  6. export function attachedRoot(node) {
  7. /* istanbul ignore next */
  8. if (typeof node.getRootNode !== 'function') {
  9. // Shadow DOM not supported (IE11), lets find the root of this node
  10. while (node.parentNode) node = node.parentNode;
  11. // The root parent is the document if the node is attached to the DOM
  12. if (node !== document) return null;
  13. return document;
  14. }
  15. const root = node.getRootNode();
  16. // The composed root node is the document if the node is attached to the DOM
  17. if (root !== document && root.getRootNode({
  18. composed: true
  19. }) !== document) return null;
  20. return root;
  21. }
  22. //# sourceMappingURL=dom.mjs.map