1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getAllAffectedNodes = void 0;
|
4 | var constants_1 = require("../constants");
|
5 | var array_1 = require("./array");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | var filterNested = function (nodes) {
|
14 | var contained = new Set();
|
15 | var l = nodes.length;
|
16 | for (var i = 0; i < l; i += 1) {
|
17 | for (var j = i + 1; j < l; j += 1) {
|
18 | var position = nodes[i].compareDocumentPosition(nodes[j]);
|
19 |
|
20 | if ((position & Node.DOCUMENT_POSITION_CONTAINED_BY) > 0) {
|
21 | contained.add(j);
|
22 | }
|
23 | if ((position & Node.DOCUMENT_POSITION_CONTAINS) > 0) {
|
24 | contained.add(i);
|
25 | }
|
26 |
|
27 | }
|
28 | }
|
29 | return nodes.filter(function (_, index) { return !contained.has(index); });
|
30 | };
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | var getTopParent = function (node) {
|
37 | return node.parentNode ? getTopParent(node.parentNode) : node;
|
38 | };
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | var getAllAffectedNodes = function (node) {
|
45 | var nodes = (0, array_1.asArray)(node);
|
46 | return nodes.filter(Boolean).reduce(function (acc, currentNode) {
|
47 | var group = currentNode.getAttribute(constants_1.FOCUS_GROUP);
|
48 | acc.push.apply(acc, (group
|
49 | ? filterNested((0, array_1.toArray)(getTopParent(currentNode).querySelectorAll("[".concat(constants_1.FOCUS_GROUP, "=\"").concat(group, "\"]:not([").concat(constants_1.FOCUS_DISABLED, "=\"disabled\"])"))))
|
50 | : [currentNode]));
|
51 | return acc;
|
52 | }, []);
|
53 | };
|
54 | exports.getAllAffectedNodes = getAllAffectedNodes;
|