1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getParentAutofocusables = exports.getFocusables = void 0;
|
4 | var constants_1 = require("../constants");
|
5 | var array_1 = require("./array");
|
6 | var tabbables_1 = require("./tabbables");
|
7 | var queryTabbables = tabbables_1.tabbables.join(',');
|
8 | var queryGuardTabbables = "".concat(queryTabbables, ", [data-focus-guard]");
|
9 | var getFocusablesWithShadowDom = function (parent, withGuards) {
|
10 | return (0, array_1.toArray)((parent.shadowRoot || parent).children).reduce(function (acc, child) {
|
11 | return acc.concat(child.matches(withGuards ? queryGuardTabbables : queryTabbables) ? [child] : [], getFocusablesWithShadowDom(child));
|
12 | }, []);
|
13 | };
|
14 | var getFocusablesWithIFrame = function (parent, withGuards) {
|
15 | var _a;
|
16 |
|
17 | if (parent instanceof HTMLIFrameElement && ((_a = parent.contentDocument) === null || _a === void 0 ? void 0 : _a.body)) {
|
18 | return (0, exports.getFocusables)([parent.contentDocument.body], withGuards);
|
19 | }
|
20 | return [parent];
|
21 | };
|
22 | var getFocusables = function (parents, withGuards) {
|
23 | return parents.reduce(function (acc, parent) {
|
24 | var _a;
|
25 | var focusableWithShadowDom = getFocusablesWithShadowDom(parent, withGuards);
|
26 | var focusableWithIframes = (_a = []).concat.apply(_a, focusableWithShadowDom.map(function (node) { return getFocusablesWithIFrame(node, withGuards); }));
|
27 | return acc.concat(
|
28 |
|
29 | focusableWithIframes,
|
30 |
|
31 | parent.parentNode
|
32 | ? (0, array_1.toArray)(parent.parentNode.querySelectorAll(queryTabbables)).filter(function (node) { return node === parent; })
|
33 | : []);
|
34 | }, []);
|
35 | };
|
36 | exports.getFocusables = getFocusables;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | var getParentAutofocusables = function (parent) {
|
42 | var parentFocus = parent.querySelectorAll("[".concat(constants_1.FOCUS_AUTO, "]"));
|
43 | return (0, array_1.toArray)(parentFocus)
|
44 | .map(function (node) { return (0, exports.getFocusables)([node]); })
|
45 | .reduce(function (acc, nodes) { return acc.concat(nodes); }, []);
|
46 | };
|
47 | exports.getParentAutofocusables = getParentAutofocusables;
|