1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import {getOwnerWindow} from '@react-aria/utils';
|
14 |
|
15 | function isStyleVisible(element: Element) {
|
16 | const windowObject = getOwnerWindow(element);
|
17 | if (!(element instanceof windowObject.HTMLElement) && !(element instanceof windowObject.SVGElement)) {
|
18 | return false;
|
19 | }
|
20 |
|
21 | let {display, visibility} = element.style;
|
22 |
|
23 | let isVisible = (
|
24 | display !== 'none' &&
|
25 | visibility !== 'hidden' &&
|
26 | visibility !== 'collapse'
|
27 | );
|
28 |
|
29 | if (isVisible) {
|
30 | const {getComputedStyle} = element.ownerDocument.defaultView as unknown as Window;
|
31 | let {display: computedDisplay, visibility: computedVisibility} = getComputedStyle(element);
|
32 |
|
33 | isVisible = (
|
34 | computedDisplay !== 'none' &&
|
35 | computedVisibility !== 'hidden' &&
|
36 | computedVisibility !== 'collapse'
|
37 | );
|
38 | }
|
39 |
|
40 | return isVisible;
|
41 | }
|
42 |
|
43 | function isAttributeVisible(element: Element, childElement?: Element) {
|
44 | return (
|
45 | !element.hasAttribute('hidden') &&
|
46 | (element.nodeName === 'DETAILS' &&
|
47 | childElement &&
|
48 | childElement.nodeName !== 'SUMMARY'
|
49 | ? element.hasAttribute('open')
|
50 | : true)
|
51 | );
|
52 | }
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | export function isElementVisible(element: Element, childElement?: Element) {
|
61 | return (
|
62 | element.nodeName !== '#comment' &&
|
63 | isStyleVisible(element) &&
|
64 | isAttributeVisible(element, childElement) &&
|
65 | (!element.parentElement || isElementVisible(element.parentElement, element))
|
66 | );
|
67 | }
|