1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.orderByTabIndex = exports.tabSort = void 0;
|
4 | var array_1 = require("./array");
|
5 | var tabSort = function (a, b) {
|
6 | var aTab = Math.max(0, a.tabIndex);
|
7 | var bTab = Math.max(0, b.tabIndex);
|
8 | var tabDiff = aTab - bTab;
|
9 | var indexDiff = a.index - b.index;
|
10 | if (tabDiff) {
|
11 | if (!aTab) {
|
12 | return 1;
|
13 | }
|
14 | if (!bTab) {
|
15 | return -1;
|
16 | }
|
17 | }
|
18 | return tabDiff || indexDiff;
|
19 | };
|
20 | exports.tabSort = tabSort;
|
21 | var getTabIndex = function (node) {
|
22 | if (node.tabIndex < 0) {
|
23 |
|
24 |
|
25 |
|
26 | if (!node.hasAttribute('tabindex')) {
|
27 | return 0;
|
28 | }
|
29 | }
|
30 | return node.tabIndex;
|
31 | };
|
32 | var orderByTabIndex = function (nodes, filterNegative, keepGuards) {
|
33 | return (0, array_1.toArray)(nodes)
|
34 | .map(function (node, index) {
|
35 | var tabIndex = getTabIndex(node);
|
36 | return {
|
37 | node: node,
|
38 | index: index,
|
39 | tabIndex: keepGuards && tabIndex === -1 ? ((node.dataset || {}).focusGuard ? 0 : -1) : tabIndex,
|
40 | };
|
41 | })
|
42 | .filter(function (data) { return !filterNegative || data.tabIndex >= 0; })
|
43 | .sort(exports.tabSort);
|
44 | };
|
45 | exports.orderByTabIndex = orderByTabIndex;
|