getDocumentForElement(node) returns the owning Document or ShadowRoot — it works for disconnected nodes and for nodes inside a shadow tree. Part of pota/use/dom.
getDocumentForElement(node)
Document
ShadowRoot
pota/use/dom