1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.allParentAutofocusables = exports.getTopCommonParent = exports.getCommonParent = void 0;
|
4 | var DOMutils_1 = require("./DOMutils");
|
5 | var DOMutils_2 = require("./DOMutils");
|
6 | var array_1 = require("./array");
|
7 | var getParents = function (node, parents) {
|
8 | if (parents === void 0) { parents = []; }
|
9 | parents.push(node);
|
10 | if (node.parentNode) {
|
11 | getParents(node.parentNode.host || node.parentNode, parents);
|
12 | }
|
13 | return parents;
|
14 | };
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var getCommonParent = function (nodeA, nodeB) {
|
22 | var parentsA = getParents(nodeA);
|
23 | var parentsB = getParents(nodeB);
|
24 |
|
25 | for (var i = 0; i < parentsA.length; i += 1) {
|
26 | var currentParent = parentsA[i];
|
27 | if (parentsB.indexOf(currentParent) >= 0) {
|
28 | return currentParent;
|
29 | }
|
30 | }
|
31 | return false;
|
32 | };
|
33 | exports.getCommonParent = getCommonParent;
|
34 | var getTopCommonParent = function (baseActiveElement, leftEntry, rightEntries) {
|
35 | var activeElements = (0, array_1.asArray)(baseActiveElement);
|
36 | var leftEntries = (0, array_1.asArray)(leftEntry);
|
37 | var activeElement = activeElements[0];
|
38 | var topCommon = false;
|
39 | leftEntries.filter(Boolean).forEach(function (entry) {
|
40 | topCommon = (0, exports.getCommonParent)(topCommon || entry, entry) || topCommon;
|
41 | rightEntries.filter(Boolean).forEach(function (subEntry) {
|
42 | var common = (0, exports.getCommonParent)(activeElement, subEntry);
|
43 | if (common) {
|
44 | if (!topCommon || (0, DOMutils_2.contains)(common, topCommon)) {
|
45 | topCommon = common;
|
46 | }
|
47 | else {
|
48 | topCommon = (0, exports.getCommonParent)(common, topCommon);
|
49 | }
|
50 | }
|
51 | });
|
52 | });
|
53 |
|
54 | return topCommon;
|
55 | };
|
56 | exports.getTopCommonParent = getTopCommonParent;
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | var allParentAutofocusables = function (entries, visibilityCache) {
|
63 | return entries.reduce(function (acc, node) { return acc.concat((0, DOMutils_1.parentAutofocusables)(node, visibilityCache)); }, []);
|
64 | };
|
65 | exports.allParentAutofocusables = allParentAutofocusables;
|