UNPKG

422 BPlain TextView Raw
1export const getOwnerDocument = (el: Element | null | undefined): Document => {
2 return el?.ownerDocument ?? document;
3};
4
5export const getOwnerWindow = (
6 el: (Window & typeof global) | Element | null | undefined
7): Window & typeof global => {
8 if (el && 'window' in el && el.window === el) {
9 return el;
10 }
11
12 const doc = getOwnerDocument(el as Element | null | undefined);
13 return doc.defaultView || window;
14};