/** * Returns the document that owns `node`, falling back to the ambient * `document` global when `node` is null or detached. Use this instead of * reading `document` directly so realm-sensitive checks (e.g. `instanceof`) * work correctly across iframes. */ export function ownerDocument(node: Node | null | undefined): Document { return node?.ownerDocument ?? document; }