power-focusable 2.1.8 → 2.1.10

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 CHANGED
@@ -24,20 +24,14 @@ function getFocusables(container = document.body, options = {}) {
24
24
  const assigneds = node.assignedElements({ flatten: true });
25
25
  if (assigneds.length) {
26
26
  for (let i = 0, l = assigneds.length; i < l; i++) {
27
- const assigned = assigneds[i];
28
- if (assigned) {
29
- traverse2(assigned);
30
- }
27
+ traverse2(assigneds[i]);
31
28
  }
32
29
  return;
33
30
  }
34
31
  }
35
32
  const children = node.childNodes;
36
33
  for (let i = 0, l = children.length; i < l; i++) {
37
- const child = children[i];
38
- if (child) {
39
- traverse2(child);
40
- }
34
+ traverse2(children[i]);
41
35
  }
42
36
  };
43
37
  traverse2(container);
@@ -45,7 +39,7 @@ function getFocusables(container = document.body, options = {}) {
45
39
  const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
46
40
  for (let i = 0, l = candidates.length; i < l; i++) {
47
41
  const candidate = candidates[i];
48
- if (candidate && isFocusable(candidate)) {
42
+ if (isFocusable(candidate)) {
49
43
  elements[elements.length] = candidate;
50
44
  }
51
45
  }
@@ -81,8 +75,7 @@ function isFocusable(element) {
81
75
  if (element.hasAttribute("hidden") || element.hasAttribute("inert")) {
82
76
  return false;
83
77
  }
84
- const index = element.getAttribute("tabindex");
85
- if (index && Number(index) < 0) {
78
+ if (element.tabIndex < 0) {
86
79
  return false;
87
80
  }
88
81
  if (!element.matches(FOCUSABLE_SELECTOR)) {
@@ -141,16 +134,6 @@ function getActiveElement() {
141
134
  }
142
135
  return current;
143
136
  }
144
- var tabIndexCache = /* @__PURE__ */ new WeakMap();
145
- function getTabIndex(element) {
146
- const cached = tabIndexCache.get(element);
147
- if (cached !== void 0) {
148
- return cached;
149
- }
150
- const index = Number(element.getAttribute("tabindex"));
151
- tabIndexCache.set(element, index);
152
- return index;
153
- }
154
137
  function isDisabled(element) {
155
138
  return "disabled" in element && !!element.disabled;
156
139
  }
@@ -225,10 +208,10 @@ function sortByTabIndex(elements) {
225
208
  const natural = [];
226
209
  for (let i = 0, l = elements.length; i < l; i++) {
227
210
  const element = elements[i];
228
- const target = getTabIndex(element) > 0 ? ordered : natural;
211
+ const target = element.tabIndex > 0 ? ordered : natural;
229
212
  target[target.length] = element;
230
213
  }
231
- ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
214
+ ordered.sort((a, b) => a.tabIndex - b.tabIndex);
232
215
  let count = 0;
233
216
  const sorted = new Array(ordered.length + natural.length);
234
217
  for (let i = 0, l = ordered.length; i < l; i++) {
@@ -244,7 +227,7 @@ function sortByTabIndex(elements) {
244
227
  * High-precision focus management utility with shadow DOM support.
245
228
  * Handles complex focus rules including tabindex ordering, radio groups, etc.
246
229
  *
247
- * @version 2.1.8
230
+ * @version 2.1.10
248
231
  * @author Yusuke Kamiyamane
249
232
  * @license MIT
250
233
  * @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.8
6
+ * @version 2.1.10
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.8
6
+ * @version 2.1.10
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -22,20 +22,14 @@ function getFocusables(container = document.body, options = {}) {
22
22
  const assigneds = node.assignedElements({ flatten: true });
23
23
  if (assigneds.length) {
24
24
  for (let i = 0, l = assigneds.length; i < l; i++) {
25
- const assigned = assigneds[i];
26
- if (assigned) {
27
- traverse2(assigned);
28
- }
25
+ traverse2(assigneds[i]);
29
26
  }
30
27
  return;
31
28
  }
32
29
  }
33
30
  const children = node.childNodes;
34
31
  for (let i = 0, l = children.length; i < l; i++) {
35
- const child = children[i];
36
- if (child) {
37
- traverse2(child);
38
- }
32
+ traverse2(children[i]);
39
33
  }
40
34
  };
41
35
  traverse2(container);
@@ -43,7 +37,7 @@ function getFocusables(container = document.body, options = {}) {
43
37
  const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
44
38
  for (let i = 0, l = candidates.length; i < l; i++) {
45
39
  const candidate = candidates[i];
46
- if (candidate && isFocusable(candidate)) {
40
+ if (isFocusable(candidate)) {
47
41
  elements[elements.length] = candidate;
48
42
  }
49
43
  }
@@ -79,8 +73,7 @@ function isFocusable(element) {
79
73
  if (element.hasAttribute("hidden") || element.hasAttribute("inert")) {
80
74
  return false;
81
75
  }
82
- const index = element.getAttribute("tabindex");
83
- if (index && Number(index) < 0) {
76
+ if (element.tabIndex < 0) {
84
77
  return false;
85
78
  }
86
79
  if (!element.matches(FOCUSABLE_SELECTOR)) {
@@ -139,16 +132,6 @@ function getActiveElement() {
139
132
  }
140
133
  return current;
141
134
  }
142
- var tabIndexCache = /* @__PURE__ */ new WeakMap();
143
- function getTabIndex(element) {
144
- const cached = tabIndexCache.get(element);
145
- if (cached !== void 0) {
146
- return cached;
147
- }
148
- const index = Number(element.getAttribute("tabindex"));
149
- tabIndexCache.set(element, index);
150
- return index;
151
- }
152
135
  function isDisabled(element) {
153
136
  return "disabled" in element && !!element.disabled;
154
137
  }
@@ -223,10 +206,10 @@ function sortByTabIndex(elements) {
223
206
  const natural = [];
224
207
  for (let i = 0, l = elements.length; i < l; i++) {
225
208
  const element = elements[i];
226
- const target = getTabIndex(element) > 0 ? ordered : natural;
209
+ const target = element.tabIndex > 0 ? ordered : natural;
227
210
  target[target.length] = element;
228
211
  }
229
- ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
212
+ ordered.sort((a, b) => a.tabIndex - b.tabIndex);
230
213
  let count = 0;
231
214
  const sorted = new Array(ordered.length + natural.length);
232
215
  for (let i = 0, l = ordered.length; i < l; i++) {
@@ -242,7 +225,7 @@ function sortByTabIndex(elements) {
242
225
  * High-precision focus management utility with shadow DOM support.
243
226
  * Handles complex focus rules including tabindex ordering, radio groups, etc.
244
227
  *
245
- * @version 2.1.8
228
+ * @version 2.1.10
246
229
  * @author Yusuke Kamiyamane
247
230
  * @license MIT
248
231
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "power-focusable",
3
- "version": "2.1.8",
3
+ "version": "2.1.10",
4
4
  "description": "High-precision focus management utility with shadow DOM support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",