@y14e/roving-tabindex 3.0.11 → 3.0.13

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
@@ -10,14 +10,14 @@ npm i @y14e/roving-tabindex
10
10
 
11
11
  ```ts
12
12
  // npm
13
- import { createRovingTabIndex } from '@y14e/roving-tabindex@3.0.10';
13
+ import { createRovingTabIndex } from '@y14e/roving-tabindex@3.0.13';
14
14
 
15
15
  // CDNs
16
- import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.0.10';
16
+ import { createRovingTabIndex } from 'https://esm.sh/@y14e/roving-tabindex@3.0.13';
17
17
  // or
18
- import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.0.10/+esm';
18
+ import { createRovingTabIndex } from 'https://cdn.jsdelivr.net/npm/@y14e/roving-tabindex@3.0.13/+esm';
19
19
  // or
20
- import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.0.10';
20
+ import { createRovingTabIndex } from 'https://esm.unpkg.com/@y14e/roving-tabindex@3.0.13';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
@@ -1,7 +1,291 @@
1
1
  'use strict';
2
2
 
3
- var attributesUtils = require('@y14e/attributes-utils');
4
- var powerFocusable = require('power-focusable');
3
+ // node_modules/@y14e/attributes-utils/dist/index.js
4
+ var DEFAULT_PARSER = (value) => value.split(/\s+/);
5
+ var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
6
+ function addTokenToAttribute(element, attribute, token, options = {}) {
7
+ const {
8
+ caseInsensitive = false,
9
+ parse = DEFAULT_PARSER,
10
+ serialize = DEFAULT_SERIALIZER
11
+ } = options;
12
+ const value = element.getAttribute(attribute)?.trim();
13
+ const tokens = value ? parse(value).filter(Boolean) : [];
14
+ if (caseInsensitive) {
15
+ const lower = token.toLowerCase();
16
+ if (tokens.every((token2) => token2.toLowerCase() !== lower)) {
17
+ tokens.push(token);
18
+ element.setAttribute(attribute, serialize(tokens));
19
+ }
20
+ } else {
21
+ const set = new Set(tokens);
22
+ set.add(token);
23
+ element.setAttribute(attribute, serialize([...set]));
24
+ }
25
+ }
26
+ var snapshots = /* @__PURE__ */ new WeakMap();
27
+ function restoreAttributes(elements) {
28
+ for (const element of elements) {
29
+ const snapshot = snapshots.get(element);
30
+ if (!snapshot) {
31
+ continue;
32
+ }
33
+ for (const [attribute, value] of snapshot.entries()) {
34
+ value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
35
+ }
36
+ snapshots.delete(element);
37
+ }
38
+ }
39
+ function saveAttributes(elements, attributes) {
40
+ elements.forEach((element) => {
41
+ let snapshot = snapshots.get(element);
42
+ if (!snapshot) {
43
+ snapshot = /* @__PURE__ */ new Map();
44
+ snapshots.set(element, snapshot);
45
+ }
46
+ attributes.forEach((attribute) => {
47
+ snapshot.set(attribute, element.getAttribute(attribute));
48
+ });
49
+ });
50
+ }
51
+
52
+ // node_modules/power-focusable/dist/index.js
53
+ var FOCUSABLE_SELECTOR = `:is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])`;
54
+ function getFocusables(container = document.body, options = {}) {
55
+ if (!(container instanceof Element)) {
56
+ console.warn("Invalid container element. Fallback: <body> element.");
57
+ container = document.body;
58
+ }
59
+ let {
60
+ composed = false,
61
+ filter,
62
+ include,
63
+ skipNegativeTabIndexCheck = false,
64
+ skipVisibilityCheck = false
65
+ } = options;
66
+ if (typeof composed !== "boolean") {
67
+ console.warn("Invalid composed option. Fallback: false.");
68
+ composed = false;
69
+ }
70
+ if (typeof filter !== "undefined" && typeof filter !== "function") {
71
+ console.warn(
72
+ "Invalid filter function. Fallback: no filter function (undefined)."
73
+ );
74
+ filter = void 0;
75
+ }
76
+ if (typeof include !== "undefined" && typeof include !== "function") {
77
+ console.warn(
78
+ "Invalid include function. Fallback: no include function (undefined)."
79
+ );
80
+ include = void 0;
81
+ }
82
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
83
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
84
+ skipNegativeTabIndexCheck = false;
85
+ }
86
+ if (typeof skipVisibilityCheck !== "boolean") {
87
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
88
+ skipVisibilityCheck = false;
89
+ }
90
+ const elements = [];
91
+ if (composed || include) {
92
+ let traverse2 = function(node) {
93
+ if (!(node instanceof Element)) {
94
+ return;
95
+ }
96
+ if (isFocusable(node, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(node)) {
97
+ elements[elements.length] = node;
98
+ }
99
+ const children = getComposedChildren(node);
100
+ for (let i = 0, l = children.length; i < l; i++) {
101
+ const child = children[i];
102
+ child && traverse2(child);
103
+ }
104
+ };
105
+ traverse2(container);
106
+ } else {
107
+ const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
108
+ for (let i = 0, l = candidates.length; i < l; i++) {
109
+ const candidate = candidates[i];
110
+ if (candidate && isFocusable(candidate, {
111
+ skipNegativeTabIndexCheck,
112
+ skipVisibilityCheck
113
+ })) {
114
+ elements[elements.length] = candidate;
115
+ }
116
+ }
117
+ }
118
+ const unfiltered = normalizeRadioGroup(sortByTabIndex(elements));
119
+ return filter ? unfiltered.filter(filter) : unfiltered;
120
+ }
121
+ function isFocusable(element, options = {}) {
122
+ if (!(element instanceof Element)) {
123
+ console.warn("Invalid element");
124
+ return false;
125
+ }
126
+ let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
127
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
128
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
129
+ skipNegativeTabIndexCheck = false;
130
+ }
131
+ if (typeof skipVisibilityCheck !== "boolean") {
132
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
133
+ skipVisibilityCheck = false;
134
+ }
135
+ if (element.hasAttribute("hidden") || isInert(element)) {
136
+ return false;
137
+ }
138
+ if (!skipNegativeTabIndexCheck && getTabIndex(element) < 0) {
139
+ return false;
140
+ }
141
+ if (!element.matches(
142
+ skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR.replace(/(,\s*)?\[tabindex="-1"\]/g, "") : FOCUSABLE_SELECTOR
143
+ )) {
144
+ return false;
145
+ }
146
+ if (isDisabledDeep(element)) {
147
+ return false;
148
+ }
149
+ if (!skipVisibilityCheck && !element.checkVisibility({
150
+ contentVisibilityAuto: true,
151
+ opacityProperty: true,
152
+ visibilityProperty: true
153
+ })) {
154
+ return false;
155
+ }
156
+ return true;
157
+ }
158
+ function isDisabledDeep(element) {
159
+ let current = element;
160
+ while (current) {
161
+ if (current instanceof ShadowRoot) {
162
+ if (current.mode !== "open") {
163
+ return false;
164
+ }
165
+ current = current.host;
166
+ continue;
167
+ }
168
+ if (!(current instanceof Element)) {
169
+ current = current.parentNode;
170
+ continue;
171
+ }
172
+ if (current === element && isFormControl(current) && isDisabled(current)) {
173
+ return true;
174
+ }
175
+ if (isInert(current)) {
176
+ return true;
177
+ }
178
+ if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
179
+ if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
180
+ return true;
181
+ }
182
+ }
183
+ current = current.parentNode;
184
+ }
185
+ return false;
186
+ }
187
+ function normalizeRadioGroup(elements) {
188
+ let map = null;
189
+ for (let i = 0, l = elements.length; i < l; i++) {
190
+ const element = elements[i];
191
+ if (!(element instanceof HTMLInputElement)) {
192
+ continue;
193
+ }
194
+ if (!isUngroupedRadio(element)) {
195
+ continue;
196
+ }
197
+ if (!map) {
198
+ map = /* @__PURE__ */ new Map();
199
+ }
200
+ const key = `${element.form?.id ?? "no-form"}::${element.name}`;
201
+ const group = map.get(key) ?? map.set(key, []).get(key);
202
+ if (group) {
203
+ group[group.length] = element;
204
+ }
205
+ }
206
+ if (!map) {
207
+ return elements;
208
+ }
209
+ const placeholder = /* @__PURE__ */ new Set();
210
+ for (const group of map.values()) {
211
+ placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
212
+ }
213
+ return elements.filter(
214
+ (element) => isUngroupedRadio(element) ? placeholder.has(element) : true
215
+ );
216
+ }
217
+ function sortByTabIndex(elements) {
218
+ const ordered = [];
219
+ const natural = [];
220
+ for (let i = 0, l = elements.length; i < l; i++) {
221
+ const element = elements[i];
222
+ if (element) {
223
+ const target = getTabIndex(element) > 0 ? ordered : natural;
224
+ target[target.length] = element;
225
+ }
226
+ }
227
+ ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
228
+ let count = 0;
229
+ const sorted = new Array(ordered.length + natural.length);
230
+ for (let i = 0, l = ordered.length; i < l; i++) {
231
+ sorted[count++] = ordered[i];
232
+ }
233
+ for (let i = 0, l = natural.length; i < l; i++) {
234
+ sorted[count++] = natural[i];
235
+ }
236
+ return sorted;
237
+ }
238
+ function getComposedChildren(node) {
239
+ if (node instanceof ShadowRoot) {
240
+ return getChildren(node);
241
+ }
242
+ if (!(node instanceof Element)) {
243
+ return [];
244
+ }
245
+ if (node instanceof HTMLSlotElement) {
246
+ const assigned = node.assignedElements({ flatten: true });
247
+ if (assigned.length) {
248
+ return assigned;
249
+ }
250
+ }
251
+ if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
252
+ return getChildren(node.shadowRoot);
253
+ }
254
+ return getChildren(node);
255
+ }
256
+ function focusElement(element) {
257
+ "focus" in element && typeof element.focus === "function" && element.focus();
258
+ }
259
+ function getActiveElement() {
260
+ let current = document.activeElement;
261
+ while (current?.shadowRoot?.activeElement) {
262
+ current = current.shadowRoot.activeElement;
263
+ }
264
+ return current;
265
+ }
266
+ function getChildren(node) {
267
+ const elements = [];
268
+ for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
269
+ elements[elements.length] = child;
270
+ }
271
+ return elements;
272
+ }
273
+ function getTabIndex(element) {
274
+ return "tabIndex" in element ? Number(element.tabIndex) : 0;
275
+ }
276
+ function isDisabled(element) {
277
+ return "disabled" in element && !!element.disabled;
278
+ }
279
+ function isFormControl(element) {
280
+ const name = element.tagName;
281
+ return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
282
+ }
283
+ function isInert(element) {
284
+ return "inert" in element && !!element.inert;
285
+ }
286
+ function isUngroupedRadio(element) {
287
+ return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
288
+ }
5
289
 
6
290
  // src/index.ts
7
291
  function createRovingTabIndex(container, options = {}) {
@@ -10,8 +294,14 @@ function createRovingTabIndex(container, options = {}) {
10
294
  return () => {
11
295
  };
12
296
  }
13
- const roving = new RovingTabIndex(container, options);
14
- return () => roving.destroy();
297
+ try {
298
+ const roving = new RovingTabIndex(container, options);
299
+ return () => roving.destroy();
300
+ } catch (error) {
301
+ error instanceof Error && console.warn(error.message || error);
302
+ return () => {
303
+ };
304
+ }
15
305
  }
16
306
  var RovingTabIndex = class _RovingTabIndex {
17
307
  static #initialized = /* @__PURE__ */ new Set();
@@ -82,7 +372,7 @@ var RovingTabIndex = class _RovingTabIndex {
82
372
  this.#isDestroyed = true;
83
373
  this.#controller?.abort();
84
374
  this.#controller = null;
85
- attributesUtils.restoreAttributes([...this.#focusables]);
375
+ restoreAttributes([...this.#focusables]);
86
376
  this.#focusables.clear();
87
377
  this.#focusablesByFirstChar.clear();
88
378
  }
@@ -107,8 +397,8 @@ var RovingTabIndex = class _RovingTabIndex {
107
397
  if (!(target instanceof Element)) {
108
398
  return;
109
399
  }
110
- const isFocusable = this.#focusables.has(target);
111
- this.#settings.noMemory && !isFocusable ? this.#update(null) : isFocusable && this.#update(target);
400
+ const isFocusable2 = this.#focusables.has(target);
401
+ this.#settings.noMemory && !isFocusable2 ? this.#update(null) : isFocusable2 && this.#update(target);
112
402
  };
113
403
  #onKeyDown = (event) => {
114
404
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
@@ -128,7 +418,7 @@ var RovingTabIndex = class _RovingTabIndex {
128
418
  return;
129
419
  }
130
420
  }
131
- const active = powerFocusable.getActiveElement();
421
+ const active = getActiveElement();
132
422
  if (!(active instanceof HTMLElement)) {
133
423
  return;
134
424
  }
@@ -168,13 +458,13 @@ var RovingTabIndex = class _RovingTabIndex {
168
458
  }
169
459
  }
170
460
  const focusable = target.at(newIndex);
171
- focusable && powerFocusable.focusElement(focusable);
461
+ focusable && focusElement(focusable);
172
462
  };
173
463
  #update(active) {
174
464
  const current = new Set(this.#getFocusables());
175
465
  for (const focusable of this.#focusables) {
176
466
  if (!current.has(focusable)) {
177
- focusable.isConnected && attributesUtils.restoreAttributes([focusable]);
467
+ focusable.isConnected && restoreAttributes([focusable]);
178
468
  this.#focusables.delete(focusable);
179
469
  this.#focusablesByFirstChar.forEach((focusables) => {
180
470
  const index = focusables.indexOf(focusable);
@@ -193,7 +483,7 @@ var RovingTabIndex = class _RovingTabIndex {
193
483
  this.#focusables.add(focusable);
194
484
  _RovingTabIndex.#initialized.add(focusable);
195
485
  if (!navigationOnly) {
196
- attributesUtils.saveAttributes([focusable], ["tabindex"]);
486
+ saveAttributes([focusable], ["tabindex"]);
197
487
  focusable.setAttribute("tabindex", "-1");
198
488
  }
199
489
  if (!typeahead) {
@@ -206,8 +496,8 @@ var RovingTabIndex = class _RovingTabIndex {
206
496
  );
207
497
  if (char) {
208
498
  keys.add(char);
209
- attributesUtils.saveAttributes([focusable], ["aria-keyshortcuts"]);
210
- attributesUtils.addTokenToAttribute(focusable, "aria-keyshortcuts", char, {
499
+ saveAttributes([focusable], ["aria-keyshortcuts"]);
500
+ addTokenToAttribute(focusable, "aria-keyshortcuts", char, {
211
501
  caseInsensitive: true
212
502
  });
213
503
  }
@@ -234,7 +524,7 @@ var RovingTabIndex = class _RovingTabIndex {
234
524
  return (element) => !selector || [...this.#container.querySelectorAll(selector)].includes(element);
235
525
  }
236
526
  #getFocusables() {
237
- return powerFocusable.getFocusables(this.#container, {
527
+ return getFocusables(this.#container, {
238
528
  composed: true,
239
529
  filter: this.#selectorFilter,
240
530
  skipNegativeTabIndexCheck: !this.#settings.navigationOnly,
@@ -247,11 +537,37 @@ var RovingTabIndex = class _RovingTabIndex {
247
537
  * Lightweight roving tabindex utility with fully focus management.
248
538
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
249
539
  *
250
- * @version 3.0.11
540
+ * @version 3.0.13
251
541
  * @author Yusuke Kamiyamane
252
542
  * @license MIT
253
543
  * @copyright Copyright (c) Yusuke Kamiyamane
254
544
  * @see {@link https://github.com/y14e/roving-tabindex}
255
545
  */
546
+ /*! Bundled license information:
547
+
548
+ @y14e/attributes-utils/dist/index.js:
549
+ (**
550
+ * Attributes Utils
551
+ *
552
+ * @version 1.1.2
553
+ * @author Yusuke Kamiyamane
554
+ * @license MIT
555
+ * @copyright Copyright (c) Yusuke Kamiyamane
556
+ * @see {@link https://github.com/y14e/attributes-utils}
557
+ *)
558
+
559
+ power-focusable/dist/index.js:
560
+ (**
561
+ * Power Focusable
562
+ * High-precision focus management utility with full composed tree support.
563
+ * Handles complex focus rules including tabindex ordering, radio groups, inert.
564
+ *
565
+ * @version 4.3.3
566
+ * @author Yusuke Kamiyamane
567
+ * @license MIT
568
+ * @copyright Copyright (c) Yusuke Kamiyamane
569
+ * @see {@link https://github.com/y14e/power-focusable}
570
+ *)
571
+ */
256
572
 
257
573
  exports.createRovingTabIndex = createRovingTabIndex;
@@ -1,5 +1,289 @@
1
- import { restoreAttributes, saveAttributes, addTokenToAttribute } from '@y14e/attributes-utils';
2
- import { getActiveElement, focusElement, getFocusables } from 'power-focusable';
1
+ // node_modules/@y14e/attributes-utils/dist/index.js
2
+ var DEFAULT_PARSER = (value) => value.split(/\s+/);
3
+ var DEFAULT_SERIALIZER = (tokens) => tokens.join(" ");
4
+ function addTokenToAttribute(element, attribute, token, options = {}) {
5
+ const {
6
+ caseInsensitive = false,
7
+ parse = DEFAULT_PARSER,
8
+ serialize = DEFAULT_SERIALIZER
9
+ } = options;
10
+ const value = element.getAttribute(attribute)?.trim();
11
+ const tokens = value ? parse(value).filter(Boolean) : [];
12
+ if (caseInsensitive) {
13
+ const lower = token.toLowerCase();
14
+ if (tokens.every((token2) => token2.toLowerCase() !== lower)) {
15
+ tokens.push(token);
16
+ element.setAttribute(attribute, serialize(tokens));
17
+ }
18
+ } else {
19
+ const set = new Set(tokens);
20
+ set.add(token);
21
+ element.setAttribute(attribute, serialize([...set]));
22
+ }
23
+ }
24
+ var snapshots = /* @__PURE__ */ new WeakMap();
25
+ function restoreAttributes(elements) {
26
+ for (const element of elements) {
27
+ const snapshot = snapshots.get(element);
28
+ if (!snapshot) {
29
+ continue;
30
+ }
31
+ for (const [attribute, value] of snapshot.entries()) {
32
+ value === null ? element.removeAttribute(attribute) : element.setAttribute(attribute, value);
33
+ }
34
+ snapshots.delete(element);
35
+ }
36
+ }
37
+ function saveAttributes(elements, attributes) {
38
+ elements.forEach((element) => {
39
+ let snapshot = snapshots.get(element);
40
+ if (!snapshot) {
41
+ snapshot = /* @__PURE__ */ new Map();
42
+ snapshots.set(element, snapshot);
43
+ }
44
+ attributes.forEach((attribute) => {
45
+ snapshot.set(attribute, element.getAttribute(attribute));
46
+ });
47
+ });
48
+ }
49
+
50
+ // node_modules/power-focusable/dist/index.js
51
+ var FOCUSABLE_SELECTOR = `:is(a[href], area[href], button, embed, iframe, input:not([type="hidden" i]), object, select, details > summary:first-of-type, textarea, [contenteditable]:not([contenteditable="false" i]), [controls], [tabindex]):not(:disabled, [hidden], [inert], [tabindex="-1"])`;
52
+ function getFocusables(container = document.body, options = {}) {
53
+ if (!(container instanceof Element)) {
54
+ console.warn("Invalid container element. Fallback: <body> element.");
55
+ container = document.body;
56
+ }
57
+ let {
58
+ composed = false,
59
+ filter,
60
+ include,
61
+ skipNegativeTabIndexCheck = false,
62
+ skipVisibilityCheck = false
63
+ } = options;
64
+ if (typeof composed !== "boolean") {
65
+ console.warn("Invalid composed option. Fallback: false.");
66
+ composed = false;
67
+ }
68
+ if (typeof filter !== "undefined" && typeof filter !== "function") {
69
+ console.warn(
70
+ "Invalid filter function. Fallback: no filter function (undefined)."
71
+ );
72
+ filter = void 0;
73
+ }
74
+ if (typeof include !== "undefined" && typeof include !== "function") {
75
+ console.warn(
76
+ "Invalid include function. Fallback: no include function (undefined)."
77
+ );
78
+ include = void 0;
79
+ }
80
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
81
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
82
+ skipNegativeTabIndexCheck = false;
83
+ }
84
+ if (typeof skipVisibilityCheck !== "boolean") {
85
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
86
+ skipVisibilityCheck = false;
87
+ }
88
+ const elements = [];
89
+ if (composed || include) {
90
+ let traverse2 = function(node) {
91
+ if (!(node instanceof Element)) {
92
+ return;
93
+ }
94
+ if (isFocusable(node, { skipNegativeTabIndexCheck, skipVisibilityCheck }) || include?.(node)) {
95
+ elements[elements.length] = node;
96
+ }
97
+ const children = getComposedChildren(node);
98
+ for (let i = 0, l = children.length; i < l; i++) {
99
+ const child = children[i];
100
+ child && traverse2(child);
101
+ }
102
+ };
103
+ traverse2(container);
104
+ } else {
105
+ const candidates = container.querySelectorAll(FOCUSABLE_SELECTOR);
106
+ for (let i = 0, l = candidates.length; i < l; i++) {
107
+ const candidate = candidates[i];
108
+ if (candidate && isFocusable(candidate, {
109
+ skipNegativeTabIndexCheck,
110
+ skipVisibilityCheck
111
+ })) {
112
+ elements[elements.length] = candidate;
113
+ }
114
+ }
115
+ }
116
+ const unfiltered = normalizeRadioGroup(sortByTabIndex(elements));
117
+ return filter ? unfiltered.filter(filter) : unfiltered;
118
+ }
119
+ function isFocusable(element, options = {}) {
120
+ if (!(element instanceof Element)) {
121
+ console.warn("Invalid element");
122
+ return false;
123
+ }
124
+ let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
125
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
126
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
127
+ skipNegativeTabIndexCheck = false;
128
+ }
129
+ if (typeof skipVisibilityCheck !== "boolean") {
130
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
131
+ skipVisibilityCheck = false;
132
+ }
133
+ if (element.hasAttribute("hidden") || isInert(element)) {
134
+ return false;
135
+ }
136
+ if (!skipNegativeTabIndexCheck && getTabIndex(element) < 0) {
137
+ return false;
138
+ }
139
+ if (!element.matches(
140
+ skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR.replace(/(,\s*)?\[tabindex="-1"\]/g, "") : FOCUSABLE_SELECTOR
141
+ )) {
142
+ return false;
143
+ }
144
+ if (isDisabledDeep(element)) {
145
+ return false;
146
+ }
147
+ if (!skipVisibilityCheck && !element.checkVisibility({
148
+ contentVisibilityAuto: true,
149
+ opacityProperty: true,
150
+ visibilityProperty: true
151
+ })) {
152
+ return false;
153
+ }
154
+ return true;
155
+ }
156
+ function isDisabledDeep(element) {
157
+ let current = element;
158
+ while (current) {
159
+ if (current instanceof ShadowRoot) {
160
+ if (current.mode !== "open") {
161
+ return false;
162
+ }
163
+ current = current.host;
164
+ continue;
165
+ }
166
+ if (!(current instanceof Element)) {
167
+ current = current.parentNode;
168
+ continue;
169
+ }
170
+ if (current === element && isFormControl(current) && isDisabled(current)) {
171
+ return true;
172
+ }
173
+ if (isInert(current)) {
174
+ return true;
175
+ }
176
+ if (isFormControl(element) && current.tagName === "FIELDSET" && isDisabled(current)) {
177
+ if (!current.querySelector(":scope > legend:first-of-type")?.contains(element)) {
178
+ return true;
179
+ }
180
+ }
181
+ current = current.parentNode;
182
+ }
183
+ return false;
184
+ }
185
+ function normalizeRadioGroup(elements) {
186
+ let map = null;
187
+ for (let i = 0, l = elements.length; i < l; i++) {
188
+ const element = elements[i];
189
+ if (!(element instanceof HTMLInputElement)) {
190
+ continue;
191
+ }
192
+ if (!isUngroupedRadio(element)) {
193
+ continue;
194
+ }
195
+ if (!map) {
196
+ map = /* @__PURE__ */ new Map();
197
+ }
198
+ const key = `${element.form?.id ?? "no-form"}::${element.name}`;
199
+ const group = map.get(key) ?? map.set(key, []).get(key);
200
+ if (group) {
201
+ group[group.length] = element;
202
+ }
203
+ }
204
+ if (!map) {
205
+ return elements;
206
+ }
207
+ const placeholder = /* @__PURE__ */ new Set();
208
+ for (const group of map.values()) {
209
+ placeholder.add(group.find((radio) => radio.checked) ?? group[0]);
210
+ }
211
+ return elements.filter(
212
+ (element) => isUngroupedRadio(element) ? placeholder.has(element) : true
213
+ );
214
+ }
215
+ function sortByTabIndex(elements) {
216
+ const ordered = [];
217
+ const natural = [];
218
+ for (let i = 0, l = elements.length; i < l; i++) {
219
+ const element = elements[i];
220
+ if (element) {
221
+ const target = getTabIndex(element) > 0 ? ordered : natural;
222
+ target[target.length] = element;
223
+ }
224
+ }
225
+ ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
226
+ let count = 0;
227
+ const sorted = new Array(ordered.length + natural.length);
228
+ for (let i = 0, l = ordered.length; i < l; i++) {
229
+ sorted[count++] = ordered[i];
230
+ }
231
+ for (let i = 0, l = natural.length; i < l; i++) {
232
+ sorted[count++] = natural[i];
233
+ }
234
+ return sorted;
235
+ }
236
+ function getComposedChildren(node) {
237
+ if (node instanceof ShadowRoot) {
238
+ return getChildren(node);
239
+ }
240
+ if (!(node instanceof Element)) {
241
+ return [];
242
+ }
243
+ if (node instanceof HTMLSlotElement) {
244
+ const assigned = node.assignedElements({ flatten: true });
245
+ if (assigned.length) {
246
+ return assigned;
247
+ }
248
+ }
249
+ if (node instanceof HTMLElement && node.shadowRoot?.mode === "open") {
250
+ return getChildren(node.shadowRoot);
251
+ }
252
+ return getChildren(node);
253
+ }
254
+ function focusElement(element) {
255
+ "focus" in element && typeof element.focus === "function" && element.focus();
256
+ }
257
+ function getActiveElement() {
258
+ let current = document.activeElement;
259
+ while (current?.shadowRoot?.activeElement) {
260
+ current = current.shadowRoot.activeElement;
261
+ }
262
+ return current;
263
+ }
264
+ function getChildren(node) {
265
+ const elements = [];
266
+ for (let child = node.firstElementChild; child; child = child.nextElementSibling) {
267
+ elements[elements.length] = child;
268
+ }
269
+ return elements;
270
+ }
271
+ function getTabIndex(element) {
272
+ return "tabIndex" in element ? Number(element.tabIndex) : 0;
273
+ }
274
+ function isDisabled(element) {
275
+ return "disabled" in element && !!element.disabled;
276
+ }
277
+ function isFormControl(element) {
278
+ const name = element.tagName;
279
+ return name === "BUTTON" || name === "INPUT" || name === "SELECT" || name === "TEXTAREA";
280
+ }
281
+ function isInert(element) {
282
+ return "inert" in element && !!element.inert;
283
+ }
284
+ function isUngroupedRadio(element) {
285
+ return element instanceof HTMLInputElement && element.type === "radio" && !!element.name;
286
+ }
3
287
 
4
288
  // src/index.ts
5
289
  function createRovingTabIndex(container, options = {}) {
@@ -8,8 +292,14 @@ function createRovingTabIndex(container, options = {}) {
8
292
  return () => {
9
293
  };
10
294
  }
11
- const roving = new RovingTabIndex(container, options);
12
- return () => roving.destroy();
295
+ try {
296
+ const roving = new RovingTabIndex(container, options);
297
+ return () => roving.destroy();
298
+ } catch (error) {
299
+ error instanceof Error && console.warn(error.message || error);
300
+ return () => {
301
+ };
302
+ }
13
303
  }
14
304
  var RovingTabIndex = class _RovingTabIndex {
15
305
  static #initialized = /* @__PURE__ */ new Set();
@@ -105,8 +395,8 @@ var RovingTabIndex = class _RovingTabIndex {
105
395
  if (!(target instanceof Element)) {
106
396
  return;
107
397
  }
108
- const isFocusable = this.#focusables.has(target);
109
- this.#settings.noMemory && !isFocusable ? this.#update(null) : isFocusable && this.#update(target);
398
+ const isFocusable2 = this.#focusables.has(target);
399
+ this.#settings.noMemory && !isFocusable2 ? this.#update(null) : isFocusable2 && this.#update(target);
110
400
  };
111
401
  #onKeyDown = (event) => {
112
402
  const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
@@ -245,11 +535,37 @@ var RovingTabIndex = class _RovingTabIndex {
245
535
  * Lightweight roving tabindex utility with fully focus management.
246
536
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
247
537
  *
248
- * @version 3.0.11
538
+ * @version 3.0.13
249
539
  * @author Yusuke Kamiyamane
250
540
  * @license MIT
251
541
  * @copyright Copyright (c) Yusuke Kamiyamane
252
542
  * @see {@link https://github.com/y14e/roving-tabindex}
253
543
  */
544
+ /*! Bundled license information:
545
+
546
+ @y14e/attributes-utils/dist/index.js:
547
+ (**
548
+ * Attributes Utils
549
+ *
550
+ * @version 1.1.2
551
+ * @author Yusuke Kamiyamane
552
+ * @license MIT
553
+ * @copyright Copyright (c) Yusuke Kamiyamane
554
+ * @see {@link https://github.com/y14e/attributes-utils}
555
+ *)
556
+
557
+ power-focusable/dist/index.js:
558
+ (**
559
+ * Power Focusable
560
+ * High-precision focus management utility with full composed tree support.
561
+ * Handles complex focus rules including tabindex ordering, radio groups, inert.
562
+ *
563
+ * @version 4.3.3
564
+ * @author Yusuke Kamiyamane
565
+ * @license MIT
566
+ * @copyright Copyright (c) Yusuke Kamiyamane
567
+ * @see {@link https://github.com/y14e/power-focusable}
568
+ *)
569
+ */
254
570
 
255
571
  export { createRovingTabIndex };
package/dist/index.cjs CHANGED
@@ -10,8 +10,14 @@ function createRovingTabIndex(container, options = {}) {
10
10
  return () => {
11
11
  };
12
12
  }
13
- const roving = new RovingTabIndex(container, options);
14
- return () => roving.destroy();
13
+ try {
14
+ const roving = new RovingTabIndex(container, options);
15
+ return () => roving.destroy();
16
+ } catch (error) {
17
+ error instanceof Error && console.warn(error.message || error);
18
+ return () => {
19
+ };
20
+ }
15
21
  }
16
22
  var RovingTabIndex = class _RovingTabIndex {
17
23
  static #initialized = /* @__PURE__ */ new Set();
@@ -247,7 +253,7 @@ var RovingTabIndex = class _RovingTabIndex {
247
253
  * Lightweight roving tabindex utility with fully focus management.
248
254
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
249
255
  *
250
- * @version 3.0.11
256
+ * @version 3.0.13
251
257
  * @author Yusuke Kamiyamane
252
258
  * @license MIT
253
259
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Lightweight roving tabindex utility with fully focus management.
4
4
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
5
5
  *
6
- * @version 3.0.11
6
+ * @version 3.0.13
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
  * Lightweight roving tabindex utility with fully focus management.
4
4
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
5
5
  *
6
- * @version 3.0.11
6
+ * @version 3.0.13
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -8,8 +8,14 @@ function createRovingTabIndex(container, options = {}) {
8
8
  return () => {
9
9
  };
10
10
  }
11
- const roving = new RovingTabIndex(container, options);
12
- return () => roving.destroy();
11
+ try {
12
+ const roving = new RovingTabIndex(container, options);
13
+ return () => roving.destroy();
14
+ } catch (error) {
15
+ error instanceof Error && console.warn(error.message || error);
16
+ return () => {
17
+ };
18
+ }
13
19
  }
14
20
  var RovingTabIndex = class _RovingTabIndex {
15
21
  static #initialized = /* @__PURE__ */ new Set();
@@ -245,7 +251,7 @@ var RovingTabIndex = class _RovingTabIndex {
245
251
  * Lightweight roving tabindex utility with fully focus management.
246
252
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
247
253
  *
248
- * @version 3.0.11
254
+ * @version 3.0.13
249
255
  * @author Yusuke Kamiyamane
250
256
  * @license MIT
251
257
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/roving-tabindex",
3
- "version": "3.0.11",
3
+ "version": "3.0.13",
4
4
  "description": "Lightweight roving tabindex utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",