power-focusable 4.3.20 → 4.3.22

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/README.md CHANGED
@@ -24,11 +24,11 @@ import {
24
24
  } from 'power-focusable';
25
25
 
26
26
  // CDNs
27
- import { ... } 'https://esm.sh/power-focusable@4.3.20';
27
+ import { ... } 'https://esm.sh/power-focusable@4.3.22';
28
28
  // or
29
- import { ... } 'https://cdn.jsdelivr.net/npm/power-focusable@4.3.20/+esm';
29
+ import { ... } 'https://cdn.jsdelivr.net/npm/power-focusable@4.3.22/+esm';
30
30
  // or
31
- import { ... } 'https://esm.unpkg.com/power-focusable@4.3.20';
31
+ import { ... } 'https://esm.unpkg.com/power-focusable@4.3.22';
32
32
  ```
33
33
 
34
34
  ## 🪄 Options
package/dist/index.cjs CHANGED
@@ -96,14 +96,14 @@ function getFocusables(container = document.body, options = {}) {
96
96
  console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
97
97
  skipVisibilityCheck = false;
98
98
  }
99
- const elements = [];
99
+ const candidates = [];
100
100
  if (composed || include) {
101
101
  let traverse2 = function(node) {
102
102
  if (isFocusable(node, {
103
103
  skipNegativeTabIndexCheck,
104
104
  skipVisibilityCheck
105
105
  }) || include?.(node)) {
106
- elements[elements.length] = node;
106
+ candidates[candidates.length] = node;
107
107
  }
108
108
  const children2 = composed ? getComposedChildren(node) : getChildren(node);
109
109
  for (let i = 0, l = children2.length; i < l; i++) {
@@ -117,21 +117,22 @@ function getFocusables(container = document.body, options = {}) {
117
117
  child && traverse2(child);
118
118
  }
119
119
  } else {
120
- const candidates = container.querySelectorAll(
120
+ const matches = container.querySelectorAll(
121
121
  skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
122
122
  );
123
- for (let i = 0, l = candidates.length; i < l; i++) {
124
- const candidate = candidates[i];
125
- if (candidate && isFocusable(candidate, {
123
+ for (let i = 0, l = matches.length; i < l; i++) {
124
+ const matched = matches[i];
125
+ if (matched && isFocusable(matched, {
126
126
  skipNegativeTabIndexCheck,
127
127
  skipVisibilityCheck
128
128
  })) {
129
- elements[elements.length] = candidate;
129
+ candidates[candidates.length] = matched;
130
130
  }
131
131
  }
132
132
  }
133
- const filtered = filter ? elements.filter(filter) : elements;
134
- return normalizeRadioGroup(sortByTabIndex(filtered));
133
+ return normalizeRadioGroup(
134
+ sortByTabIndex(filter ? candidates.filter(filter) : candidates)
135
+ );
135
136
  }
136
137
  function getNextFocusable(container = document.body, options = {}) {
137
138
  return getRelativeFocusable(container, 1, options);
@@ -148,21 +149,22 @@ function inertOutside(element) {
148
149
  return () => {
149
150
  };
150
151
  }
151
- function traverse(node, callback) {
152
+ function traverse(node, fn) {
152
153
  const parent = getComposedParent(node);
153
154
  if (parent) {
154
155
  for (const sibling of getComposedSiblings(node)) {
155
- callback(sibling);
156
+ fn(sibling);
156
157
  }
157
- traverse(parent, callback);
158
+ traverse(parent, fn);
158
159
  }
159
160
  }
160
161
  const elements = [];
161
162
  traverse(element, (node) => node && applyInert(node) && elements.push(node));
162
163
  return () => {
163
- elements.forEach((element2) => {
164
- restoreInert(element2);
165
- });
164
+ for (let i = 0, l = elements.length; i < l; i++) {
165
+ const element2 = elements[i];
166
+ element2 && restoreInert(element2);
167
+ }
166
168
  };
167
169
  }
168
170
  function isFocusable(element, options = {}) {
@@ -270,11 +272,11 @@ function getRelativeFocusable(container, offset, options) {
270
272
  if (!length) {
271
273
  return null;
272
274
  }
273
- const currentIndex = focusables.indexOf(anchor);
274
- if (currentIndex === -1) {
275
+ const anchorIndex = focusables.indexOf(anchor);
276
+ if (anchorIndex === -1) {
275
277
  return null;
276
278
  }
277
- const offsetIndex = currentIndex + offset;
279
+ const offsetIndex = anchorIndex + offset;
278
280
  if ((offsetIndex < 0 || offsetIndex >= length) && !wrap) {
279
281
  return null;
280
282
  }
@@ -437,7 +439,7 @@ function applyInert(element) {
437
439
  if (!isInert(element) || inertRefCounts.has(element)) {
438
440
  const count = inertRefCounts.get(element) ?? 0;
439
441
  inertRefCounts.set(element, count + 1);
440
- count === 0 && element.setAttribute("inert", "");
442
+ !count && element.setAttribute("inert", "");
441
443
  return true;
442
444
  } else {
443
445
  return false;
@@ -493,7 +495,7 @@ function isUngroupedRadio(element) {
493
495
  * High-precision focus management utility with full composed tree support.
494
496
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
495
497
  *
496
- * @version 4.3.20
498
+ * @version 4.3.22
497
499
  * @author Yusuke Kamiyamane
498
500
  * @license MIT
499
501
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * High-precision focus management utility with full composed tree support.
4
4
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
5
5
  *
6
- * @version 4.3.20
6
+ * @version 4.3.22
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 full composed tree support.
4
4
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
5
5
  *
6
- * @version 4.3.20
6
+ * @version 4.3.22
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -94,14 +94,14 @@ function getFocusables(container = document.body, options = {}) {
94
94
  console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
95
95
  skipVisibilityCheck = false;
96
96
  }
97
- const elements = [];
97
+ const candidates = [];
98
98
  if (composed || include) {
99
99
  let traverse2 = function(node) {
100
100
  if (isFocusable(node, {
101
101
  skipNegativeTabIndexCheck,
102
102
  skipVisibilityCheck
103
103
  }) || include?.(node)) {
104
- elements[elements.length] = node;
104
+ candidates[candidates.length] = node;
105
105
  }
106
106
  const children2 = composed ? getComposedChildren(node) : getChildren(node);
107
107
  for (let i = 0, l = children2.length; i < l; i++) {
@@ -115,21 +115,22 @@ function getFocusables(container = document.body, options = {}) {
115
115
  child && traverse2(child);
116
116
  }
117
117
  } else {
118
- const candidates = container.querySelectorAll(
118
+ const matches = container.querySelectorAll(
119
119
  skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
120
120
  );
121
- for (let i = 0, l = candidates.length; i < l; i++) {
122
- const candidate = candidates[i];
123
- if (candidate && isFocusable(candidate, {
121
+ for (let i = 0, l = matches.length; i < l; i++) {
122
+ const matched = matches[i];
123
+ if (matched && isFocusable(matched, {
124
124
  skipNegativeTabIndexCheck,
125
125
  skipVisibilityCheck
126
126
  })) {
127
- elements[elements.length] = candidate;
127
+ candidates[candidates.length] = matched;
128
128
  }
129
129
  }
130
130
  }
131
- const filtered = filter ? elements.filter(filter) : elements;
132
- return normalizeRadioGroup(sortByTabIndex(filtered));
131
+ return normalizeRadioGroup(
132
+ sortByTabIndex(filter ? candidates.filter(filter) : candidates)
133
+ );
133
134
  }
134
135
  function getNextFocusable(container = document.body, options = {}) {
135
136
  return getRelativeFocusable(container, 1, options);
@@ -146,21 +147,22 @@ function inertOutside(element) {
146
147
  return () => {
147
148
  };
148
149
  }
149
- function traverse(node, callback) {
150
+ function traverse(node, fn) {
150
151
  const parent = getComposedParent(node);
151
152
  if (parent) {
152
153
  for (const sibling of getComposedSiblings(node)) {
153
- callback(sibling);
154
+ fn(sibling);
154
155
  }
155
- traverse(parent, callback);
156
+ traverse(parent, fn);
156
157
  }
157
158
  }
158
159
  const elements = [];
159
160
  traverse(element, (node) => node && applyInert(node) && elements.push(node));
160
161
  return () => {
161
- elements.forEach((element2) => {
162
- restoreInert(element2);
163
- });
162
+ for (let i = 0, l = elements.length; i < l; i++) {
163
+ const element2 = elements[i];
164
+ element2 && restoreInert(element2);
165
+ }
164
166
  };
165
167
  }
166
168
  function isFocusable(element, options = {}) {
@@ -268,11 +270,11 @@ function getRelativeFocusable(container, offset, options) {
268
270
  if (!length) {
269
271
  return null;
270
272
  }
271
- const currentIndex = focusables.indexOf(anchor);
272
- if (currentIndex === -1) {
273
+ const anchorIndex = focusables.indexOf(anchor);
274
+ if (anchorIndex === -1) {
273
275
  return null;
274
276
  }
275
- const offsetIndex = currentIndex + offset;
277
+ const offsetIndex = anchorIndex + offset;
276
278
  if ((offsetIndex < 0 || offsetIndex >= length) && !wrap) {
277
279
  return null;
278
280
  }
@@ -435,7 +437,7 @@ function applyInert(element) {
435
437
  if (!isInert(element) || inertRefCounts.has(element)) {
436
438
  const count = inertRefCounts.get(element) ?? 0;
437
439
  inertRefCounts.set(element, count + 1);
438
- count === 0 && element.setAttribute("inert", "");
440
+ !count && element.setAttribute("inert", "");
439
441
  return true;
440
442
  } else {
441
443
  return false;
@@ -491,7 +493,7 @@ function isUngroupedRadio(element) {
491
493
  * High-precision focus management utility with full composed tree support.
492
494
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
493
495
  *
494
- * @version 4.3.20
496
+ * @version 4.3.22
495
497
  * @author Yusuke Kamiyamane
496
498
  * @license MIT
497
499
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "power-focusable",
3
- "version": "4.3.20",
3
+ "version": "4.3.22",
4
4
  "description": "High-precision focus management utility with full composed tree support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",