1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.isDefined = exports.isNotAGuard = exports.isGuard = exports.isAutoFocusAllowed = exports.notHiddenInput = exports.isRadioElement = exports.isHTMLInputElement = exports.isHTMLButtonElement = exports.getDataset = exports.isAutoFocusAllowedCached = exports.isVisibleCached = void 0;
|
4 | var constants_1 = require("../constants");
|
5 | var isElementHidden = function (node) {
|
6 |
|
7 |
|
8 | if (node.nodeType !== Node.ELEMENT_NODE) {
|
9 | return false;
|
10 | }
|
11 | var computedStyle = window.getComputedStyle(node, null);
|
12 | if (!computedStyle || !computedStyle.getPropertyValue) {
|
13 | return false;
|
14 | }
|
15 | return (computedStyle.getPropertyValue('display') === 'none' || computedStyle.getPropertyValue('visibility') === 'hidden');
|
16 | };
|
17 | var getParentNode = function (node) {
|
18 |
|
19 | return node.parentNode && node.parentNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE
|
20 | ?
|
21 | node.parentNode.host
|
22 | : node.parentNode;
|
23 | };
|
24 | var isTopNode = function (node) {
|
25 |
|
26 | return node === document || (node && node.nodeType === Node.DOCUMENT_NODE);
|
27 | };
|
28 | var isInert = function (node) { return node.hasAttribute('inert'); };
|
29 |
|
30 |
|
31 |
|
32 | var isVisibleUncached = function (node, checkParent) {
|
33 | return !node || isTopNode(node) || (!isElementHidden(node) && !isInert(node) && checkParent(getParentNode(node)));
|
34 | };
|
35 | var isVisibleCached = function (visibilityCache, node) {
|
36 | var cached = visibilityCache.get(node);
|
37 | if (cached !== undefined) {
|
38 | return cached;
|
39 | }
|
40 | var result = isVisibleUncached(node, exports.isVisibleCached.bind(undefined, visibilityCache));
|
41 | visibilityCache.set(node, result);
|
42 | return result;
|
43 | };
|
44 | exports.isVisibleCached = isVisibleCached;
|
45 | var isAutoFocusAllowedUncached = function (node, checkParent) {
|
46 | return node && !isTopNode(node) ? ((0, exports.isAutoFocusAllowed)(node) ? checkParent(getParentNode(node)) : false) : true;
|
47 | };
|
48 | var isAutoFocusAllowedCached = function (cache, node) {
|
49 | var cached = cache.get(node);
|
50 | if (cached !== undefined) {
|
51 | return cached;
|
52 | }
|
53 | var result = isAutoFocusAllowedUncached(node, exports.isAutoFocusAllowedCached.bind(undefined, cache));
|
54 | cache.set(node, result);
|
55 | return result;
|
56 | };
|
57 | exports.isAutoFocusAllowedCached = isAutoFocusAllowedCached;
|
58 | var getDataset = function (node) {
|
59 |
|
60 | return node.dataset;
|
61 | };
|
62 | exports.getDataset = getDataset;
|
63 | var isHTMLButtonElement = function (node) { return node.tagName === 'BUTTON'; };
|
64 | exports.isHTMLButtonElement = isHTMLButtonElement;
|
65 | var isHTMLInputElement = function (node) { return node.tagName === 'INPUT'; };
|
66 | exports.isHTMLInputElement = isHTMLInputElement;
|
67 | var isRadioElement = function (node) {
|
68 | return (0, exports.isHTMLInputElement)(node) && node.type === 'radio';
|
69 | };
|
70 | exports.isRadioElement = isRadioElement;
|
71 | var notHiddenInput = function (node) {
|
72 | return !(((0, exports.isHTMLInputElement)(node) || (0, exports.isHTMLButtonElement)(node)) && (node.type === 'hidden' || node.disabled));
|
73 | };
|
74 | exports.notHiddenInput = notHiddenInput;
|
75 | var isAutoFocusAllowed = function (node) {
|
76 | var attribute = node.getAttribute(constants_1.FOCUS_NO_AUTOFOCUS);
|
77 | return ![true, 'true', ''].includes(attribute);
|
78 | };
|
79 | exports.isAutoFocusAllowed = isAutoFocusAllowed;
|
80 | var isGuard = function (node) { var _a; return Boolean(node && ((_a = (0, exports.getDataset)(node)) === null || _a === void 0 ? void 0 : _a.focusGuard)); };
|
81 | exports.isGuard = isGuard;
|
82 | var isNotAGuard = function (node) { return !(0, exports.isGuard)(node); };
|
83 | exports.isNotAGuard = isNotAGuard;
|
84 | var isDefined = function (x) { return Boolean(x); };
|
85 | exports.isDefined = isDefined;
|