UNPKG

1.34 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.focusInside = void 0;
4var DOMutils_1 = require("./utils/DOMutils");
5var all_affected_1 = require("./utils/all-affected");
6var array_1 = require("./utils/array");
7var getActiveElement_1 = require("./utils/getActiveElement");
8var focusInFrame = function (frame, activeElement) { return frame === activeElement; };
9var focusInsideIframe = function (topNode, activeElement) {
10 return Boolean((0, array_1.toArray)(topNode.querySelectorAll('iframe')).some(function (node) { return focusInFrame(node, activeElement); }));
11};
12/**
13 * @returns {Boolean} true, if the current focus is inside given node or nodes.
14 * Supports nodes hidden inside shadowDom
15 */
16var focusInside = function (topNode, activeElement) {
17 // const activeElement = document && getActiveElement();
18 if (activeElement === void 0) { activeElement = (0, getActiveElement_1.getActiveElement)((0, array_1.getFirst)(topNode).ownerDocument); }
19 if (!activeElement || (activeElement.dataset && activeElement.dataset.focusGuard)) {
20 return false;
21 }
22 return (0, all_affected_1.getAllAffectedNodes)(topNode).some(function (node) {
23 return (0, DOMutils_1.contains)(node, activeElement) || focusInsideIframe(node, activeElement);
24 });
25};
26exports.focusInside = focusInside;