power-focusable 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,7 +21,7 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
21
21
|
}
|
|
22
22
|
} else if (node instanceof HTMLSlotElement) {
|
|
23
23
|
const assigned = node.assignedElements({ flatten: true });
|
|
24
|
-
if (assigned.length
|
|
24
|
+
if (assigned.length) {
|
|
25
25
|
for (let i = 0, l = assigned.length; i < l; i++) {
|
|
26
26
|
walk2(assigned[i]);
|
|
27
27
|
}
|
|
@@ -64,7 +64,7 @@ function hasFocusable(container = document.body, options = {}) {
|
|
|
64
64
|
console.warn("Invalid container element. Fallback: <body> element.");
|
|
65
65
|
container = document.body;
|
|
66
66
|
}
|
|
67
|
-
return getFocusables(container, options).length
|
|
67
|
+
return !!getFocusables(container, options).length;
|
|
68
68
|
}
|
|
69
69
|
function isFocusable(element) {
|
|
70
70
|
if (!(element instanceof HTMLElement)) {
|
|
@@ -75,7 +75,7 @@ function isFocusable(element) {
|
|
|
75
75
|
return false;
|
|
76
76
|
}
|
|
77
77
|
const tabIndex = element.getAttribute("tabindex");
|
|
78
|
-
if (tabIndex
|
|
78
|
+
if (tabIndex) {
|
|
79
79
|
if (Number(tabIndex) < 0) {
|
|
80
80
|
return false;
|
|
81
81
|
}
|
|
@@ -99,11 +99,11 @@ function getRelativeFocusable(container, offset = 0, options) {
|
|
|
99
99
|
const { active: a = null, composed = false, wrap = false } = options;
|
|
100
100
|
const focusables = getFocusables(container, { composed });
|
|
101
101
|
const { length } = focusables;
|
|
102
|
-
if (length
|
|
102
|
+
if (!length) {
|
|
103
103
|
return null;
|
|
104
104
|
}
|
|
105
105
|
const active = a ?? getActiveElement();
|
|
106
|
-
if (active
|
|
106
|
+
if (!active || !containsDeep(container, active)) {
|
|
107
107
|
return null;
|
|
108
108
|
}
|
|
109
109
|
const currentIndex = focusables.indexOf(active);
|
|
@@ -118,7 +118,7 @@ function getRelativeFocusable(container, offset = 0, options) {
|
|
|
118
118
|
}
|
|
119
119
|
function containsDeep(container, element) {
|
|
120
120
|
function walk(node) {
|
|
121
|
-
if (node
|
|
121
|
+
if (!node) {
|
|
122
122
|
return false;
|
|
123
123
|
}
|
|
124
124
|
if (node === container) {
|
|
@@ -133,7 +133,7 @@ function containsDeep(container, element) {
|
|
|
133
133
|
}
|
|
134
134
|
function getActiveElement() {
|
|
135
135
|
function walk(node) {
|
|
136
|
-
if (node
|
|
136
|
+
if (!node) {
|
|
137
137
|
return null;
|
|
138
138
|
}
|
|
139
139
|
const active = node.shadowRoot?.activeElement;
|
|
@@ -156,7 +156,7 @@ function isDisabled(element) {
|
|
|
156
156
|
}
|
|
157
157
|
function isDisabledDeep(element) {
|
|
158
158
|
function walk(node) {
|
|
159
|
-
if (node
|
|
159
|
+
if (!node) {
|
|
160
160
|
return false;
|
|
161
161
|
}
|
|
162
162
|
if (node instanceof ShadowRoot) {
|
|
@@ -203,9 +203,9 @@ function normalizeRadioGroup(elements) {
|
|
|
203
203
|
}
|
|
204
204
|
const placeholder = /* @__PURE__ */ new Set();
|
|
205
205
|
for (const group of map.values()) {
|
|
206
|
-
if (group.length
|
|
206
|
+
if (group.length) {
|
|
207
207
|
const enabled = group.filter(isFocusable);
|
|
208
|
-
if (enabled.length
|
|
208
|
+
if (enabled.length) {
|
|
209
209
|
placeholder.add(enabled.find((radio) => radio.checked) ?? enabled[0]);
|
|
210
210
|
}
|
|
211
211
|
}
|
|
@@ -241,7 +241,7 @@ function sortByTabIndex(elements) {
|
|
|
241
241
|
* High-precision focus management utility with shadow DOM support.
|
|
242
242
|
* Handles complex focus rules including tabindex ordering, radio groups, etc.
|
|
243
243
|
*
|
|
244
|
-
* @version 2.1.
|
|
244
|
+
* @version 2.1.3
|
|
245
245
|
* @author Yusuke Kamiyamane
|
|
246
246
|
* @license MIT
|
|
247
247
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* High-precision focus management utility with shadow DOM support.
|
|
4
4
|
* Handles complex focus rules including tabindex ordering, radio groups, etc.
|
|
5
5
|
*
|
|
6
|
-
* @version 2.1.
|
|
6
|
+
* @version 2.1.3
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* High-precision focus management utility with shadow DOM support.
|
|
4
4
|
* Handles complex focus rules including tabindex ordering, radio groups, etc.
|
|
5
5
|
*
|
|
6
|
-
* @version 2.1.
|
|
6
|
+
* @version 2.1.3
|
|
7
7
|
* @author Yusuke Kamiyamane
|
|
8
8
|
* @license MIT
|
|
9
9
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,7 @@ function getFocusables(container = document.body, options = {}) {
|
|
|
19
19
|
}
|
|
20
20
|
} else if (node instanceof HTMLSlotElement) {
|
|
21
21
|
const assigned = node.assignedElements({ flatten: true });
|
|
22
|
-
if (assigned.length
|
|
22
|
+
if (assigned.length) {
|
|
23
23
|
for (let i = 0, l = assigned.length; i < l; i++) {
|
|
24
24
|
walk2(assigned[i]);
|
|
25
25
|
}
|
|
@@ -62,7 +62,7 @@ function hasFocusable(container = document.body, options = {}) {
|
|
|
62
62
|
console.warn("Invalid container element. Fallback: <body> element.");
|
|
63
63
|
container = document.body;
|
|
64
64
|
}
|
|
65
|
-
return getFocusables(container, options).length
|
|
65
|
+
return !!getFocusables(container, options).length;
|
|
66
66
|
}
|
|
67
67
|
function isFocusable(element) {
|
|
68
68
|
if (!(element instanceof HTMLElement)) {
|
|
@@ -73,7 +73,7 @@ function isFocusable(element) {
|
|
|
73
73
|
return false;
|
|
74
74
|
}
|
|
75
75
|
const tabIndex = element.getAttribute("tabindex");
|
|
76
|
-
if (tabIndex
|
|
76
|
+
if (tabIndex) {
|
|
77
77
|
if (Number(tabIndex) < 0) {
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
@@ -97,11 +97,11 @@ function getRelativeFocusable(container, offset = 0, options) {
|
|
|
97
97
|
const { active: a = null, composed = false, wrap = false } = options;
|
|
98
98
|
const focusables = getFocusables(container, { composed });
|
|
99
99
|
const { length } = focusables;
|
|
100
|
-
if (length
|
|
100
|
+
if (!length) {
|
|
101
101
|
return null;
|
|
102
102
|
}
|
|
103
103
|
const active = a ?? getActiveElement();
|
|
104
|
-
if (active
|
|
104
|
+
if (!active || !containsDeep(container, active)) {
|
|
105
105
|
return null;
|
|
106
106
|
}
|
|
107
107
|
const currentIndex = focusables.indexOf(active);
|
|
@@ -116,7 +116,7 @@ function getRelativeFocusable(container, offset = 0, options) {
|
|
|
116
116
|
}
|
|
117
117
|
function containsDeep(container, element) {
|
|
118
118
|
function walk(node) {
|
|
119
|
-
if (node
|
|
119
|
+
if (!node) {
|
|
120
120
|
return false;
|
|
121
121
|
}
|
|
122
122
|
if (node === container) {
|
|
@@ -131,7 +131,7 @@ function containsDeep(container, element) {
|
|
|
131
131
|
}
|
|
132
132
|
function getActiveElement() {
|
|
133
133
|
function walk(node) {
|
|
134
|
-
if (node
|
|
134
|
+
if (!node) {
|
|
135
135
|
return null;
|
|
136
136
|
}
|
|
137
137
|
const active = node.shadowRoot?.activeElement;
|
|
@@ -154,7 +154,7 @@ function isDisabled(element) {
|
|
|
154
154
|
}
|
|
155
155
|
function isDisabledDeep(element) {
|
|
156
156
|
function walk(node) {
|
|
157
|
-
if (node
|
|
157
|
+
if (!node) {
|
|
158
158
|
return false;
|
|
159
159
|
}
|
|
160
160
|
if (node instanceof ShadowRoot) {
|
|
@@ -201,9 +201,9 @@ function normalizeRadioGroup(elements) {
|
|
|
201
201
|
}
|
|
202
202
|
const placeholder = /* @__PURE__ */ new Set();
|
|
203
203
|
for (const group of map.values()) {
|
|
204
|
-
if (group.length
|
|
204
|
+
if (group.length) {
|
|
205
205
|
const enabled = group.filter(isFocusable);
|
|
206
|
-
if (enabled.length
|
|
206
|
+
if (enabled.length) {
|
|
207
207
|
placeholder.add(enabled.find((radio) => radio.checked) ?? enabled[0]);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
@@ -239,7 +239,7 @@ function sortByTabIndex(elements) {
|
|
|
239
239
|
* High-precision focus management utility with shadow DOM support.
|
|
240
240
|
* Handles complex focus rules including tabindex ordering, radio groups, etc.
|
|
241
241
|
*
|
|
242
|
-
* @version 2.1.
|
|
242
|
+
* @version 2.1.3
|
|
243
243
|
* @author Yusuke Kamiyamane
|
|
244
244
|
* @license MIT
|
|
245
245
|
* @copyright Copyright (c) Yusuke Kamiyamane
|