1 | export const getOwnerDocument = (el: Element | null | undefined): Document => {
|
2 | return el?.ownerDocument ?? document;
|
3 | };
|
4 |
|
5 | export 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 | };
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function isNode(value: unknown): value is Node {
|
20 | return value !== null &&
|
21 | typeof value === 'object' &&
|
22 | 'nodeType' in value &&
|
23 | typeof (value as Node).nodeType === 'number';
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export function isShadowRoot(node: Node | null): node is ShadowRoot {
|
30 | return isNode(node) &&
|
31 | node.nodeType === Node.DOCUMENT_FRAGMENT_NODE &&
|
32 | 'host' in node;
|
33 | }
|