@y14e/portal 1.3.4 → 1.3.6

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
@@ -13,11 +13,11 @@ npm i @y14e/portal
13
13
  import { createPortal } from '@y14e/portal';
14
14
 
15
15
  // CDNs
16
- import { createPortal } from 'https://esm.sh/@y14e/portal@1.3.4';
16
+ import { createPortal } from 'https://esm.sh/@y14e/portal@1.3.6';
17
17
  // or
18
- import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.3.4/+esm';
18
+ import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.3.6/+esm';
19
19
  // or
20
- import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.3.4';
20
+ import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.3.6';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
@@ -16,20 +16,20 @@ function restoreAttributes(element_or_elements) {
16
16
  }
17
17
  function saveAttributes(element_or_elements, name_or_names) {
18
18
  const names = Array.isArray(name_or_names) ? name_or_names : [name_or_names];
19
- (Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]).forEach((element) => {
19
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
20
20
  let snapshot = snapshots.get(element);
21
21
  if (!snapshot) {
22
22
  snapshot = /* @__PURE__ */ new Map();
23
23
  snapshots.set(element, snapshot);
24
24
  }
25
- names.forEach((name) => {
25
+ for (const name of names) {
26
26
  snapshot.set(name, element.getAttribute(name));
27
- });
28
- });
27
+ }
28
+ }
29
29
  }
30
30
 
31
31
  // node_modules/power-focusable/dist/index.js
32
- 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"])`;
32
+ 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"])';
33
33
  var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
34
34
  /(,\s*)?\[tabindex="-1"\]/g,
35
35
  ""
@@ -39,37 +39,13 @@ function getFocusables(container = document.body, options = {}) {
39
39
  console.warn("Invalid container element. Fallback: <body> element.");
40
40
  container = document.body;
41
41
  }
42
- let {
43
- composed = false,
42
+ const {
43
+ composed,
44
44
  filter,
45
45
  include,
46
- skipNegativeTabIndexCheck = false,
47
- skipVisibilityCheck = false
48
- } = options;
49
- if (typeof composed !== "boolean") {
50
- console.warn("Invalid composed option. Fallback: false.");
51
- composed = false;
52
- }
53
- if (typeof filter !== "undefined" && typeof filter !== "function") {
54
- console.warn(
55
- "Invalid filter function. Fallback: no filter function (undefined)."
56
- );
57
- filter = void 0;
58
- }
59
- if (typeof include !== "undefined" && typeof include !== "function") {
60
- console.warn(
61
- "Invalid include function. Fallback: no include function (undefined)."
62
- );
63
- include = void 0;
64
- }
65
- if (typeof skipNegativeTabIndexCheck !== "boolean") {
66
- console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
67
- skipNegativeTabIndexCheck = false;
68
- }
69
- if (typeof skipVisibilityCheck !== "boolean") {
70
- console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
71
- skipVisibilityCheck = false;
72
- }
46
+ skipNegativeTabIndexCheck,
47
+ skipVisibilityCheck
48
+ } = resolveOptions(options);
73
49
  const candidates = [];
74
50
  if (composed || include) {
75
51
  let traverse2 = function(node) {
@@ -79,29 +55,19 @@ function getFocusables(container = document.body, options = {}) {
79
55
  }) || include?.(node)) {
80
56
  candidates[candidates.length] = node;
81
57
  }
82
- const children2 = composed ? getComposedChildren(node) : getChildren(node);
83
- for (let i = 0, l = children2.length; i < l; i++) {
84
- const child = children2[i];
85
- child && traverse2(child);
86
- }
58
+ (composed ? getComposedChildren(node) : getChildren(node)).map(traverse2);
87
59
  };
88
- const children = composed ? getComposedChildren(container) : getChildren(container);
89
- for (let i = 0, l = children.length; i < l; i++) {
90
- const child = children[i];
91
- child && traverse2(child);
92
- }
60
+ (composed ? getComposedChildren(container) : getChildren(container)).map(
61
+ traverse2
62
+ );
93
63
  } else {
94
- const matches = container.querySelectorAll(
64
+ for (const match of container.querySelectorAll(
95
65
  skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
96
- );
97
- for (let i = 0, l = matches.length; i < l; i++) {
98
- const matched = matches[i];
99
- if (matched && isFocusable(matched, {
66
+ )) {
67
+ match && isFocusable(match, {
100
68
  skipNegativeTabIndexCheck,
101
69
  skipVisibilityCheck
102
- })) {
103
- candidates[candidates.length] = matched;
104
- }
70
+ }) && candidates.push(match);
105
71
  }
106
72
  }
107
73
  return normalizeRadioGroup(
@@ -119,15 +85,7 @@ function isFocusable(element, options = {}) {
119
85
  console.warn("Invalid element");
120
86
  return false;
121
87
  }
122
- let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
123
- if (typeof skipNegativeTabIndexCheck !== "boolean") {
124
- console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
125
- skipNegativeTabIndexCheck = false;
126
- }
127
- if (typeof skipVisibilityCheck !== "boolean") {
128
- console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
129
- skipVisibilityCheck = false;
130
- }
88
+ const { skipNegativeTabIndexCheck, skipVisibilityCheck } = resolveOptions(options);
131
89
  if (element.hasAttribute("hidden") || isInert(element)) {
132
90
  return false;
133
91
  }
@@ -156,65 +114,30 @@ function getRelativeFocusable(container, offset, options) {
156
114
  console.warn("Invalid container element. Fallback: <body> element.");
157
115
  container = document.body;
158
116
  }
159
- let {
160
- anchor = getActiveElement(),
161
- composed = false,
117
+ const {
118
+ anchor,
119
+ composed,
162
120
  filter,
163
121
  include,
164
- skipNegativeTabIndexCheck = false,
165
- skipVisibilityCheck = false,
166
- wrap = false
167
- } = options;
122
+ skipNegativeTabIndexCheck,
123
+ skipVisibilityCheck,
124
+ wrap
125
+ } = resolveOptions(options);
168
126
  if (!(anchor instanceof Element)) {
169
- const active = getActiveElement();
170
- if (active instanceof Element) {
171
- console.warn("Invalid anchor element. Fallback: active element.");
172
- anchor = active;
173
- } else {
174
- console.warn("Invalid anchor element");
175
- return null;
176
- }
127
+ console.warn("Invalid anchor element");
128
+ return null;
177
129
  }
178
130
  if (!containsComposed(container, anchor)) {
179
131
  console.warn("Anchor (active) element not within container");
180
132
  return null;
181
133
  }
182
- if (typeof composed !== "boolean") {
183
- console.warn("Invalid composed option. Fallback: false.");
184
- composed = false;
185
- }
186
- if (typeof filter !== "undefined" && typeof filter !== "function") {
187
- console.warn(
188
- "Invalid filter function. Fallback: no filter function (undefined)."
189
- );
190
- filter = void 0;
191
- }
192
- if (typeof include !== "undefined" && typeof include !== "function") {
193
- console.warn(
194
- "Invalid include function. Fallback: no include function (undefined)."
195
- );
196
- include = void 0;
197
- }
198
- if (typeof skipNegativeTabIndexCheck !== "boolean") {
199
- console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
200
- skipNegativeTabIndexCheck = false;
201
- }
202
- if (typeof skipVisibilityCheck !== "boolean") {
203
- console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
204
- skipVisibilityCheck = false;
205
- }
206
- if (typeof wrap !== "boolean") {
207
- console.warn("Invalid wrap option. Fallback: false.");
208
- wrap = false;
209
- }
210
- const settings = {
134
+ const focusables = getFocusables(container, {
211
135
  composed,
136
+ filter,
137
+ include,
212
138
  skipNegativeTabIndexCheck,
213
139
  skipVisibilityCheck
214
- };
215
- filter && Object.assign(settings, { filter });
216
- include && Object.assign(settings, { include });
217
- const focusables = getFocusables(container, settings);
140
+ });
218
141
  const { length } = focusables;
219
142
  if (!length) {
220
143
  return null;
@@ -260,8 +183,7 @@ function isDisabledDeep(element) {
260
183
  }
261
184
  function normalizeRadioGroup(elements) {
262
185
  let map = null;
263
- for (let i = 0, l = elements.length; i < l; i++) {
264
- const element = elements[i];
186
+ for (const element of elements) {
265
187
  if (!(element instanceof HTMLInputElement)) {
266
188
  continue;
267
189
  }
@@ -311,23 +233,10 @@ function normalizeRadioGroup(elements) {
311
233
  function sortByTabIndex(elements) {
312
234
  const ordered = [];
313
235
  const natural = [];
314
- for (let i = 0, l = elements.length; i < l; i++) {
315
- const element = elements[i];
316
- if (element) {
317
- const target = getTabIndex(element) > 0 ? ordered : natural;
318
- target[target.length] = element;
319
- }
320
- }
321
- ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
322
- let count = 0;
323
- const sorted = new Array(ordered.length + natural.length);
324
- for (let i = 0, l = ordered.length; i < l; i++) {
325
- sorted[count++] = ordered[i];
326
- }
327
- for (let i = 0, l = natural.length; i < l; i++) {
328
- sorted[count++] = natural[i];
236
+ for (const element of elements) {
237
+ (getTabIndex(element) > 0 ? ordered : natural).push(element);
329
238
  }
330
- return sorted;
239
+ return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
331
240
  }
332
241
  function containsComposed(container, element) {
333
242
  let current = element;
@@ -391,6 +300,61 @@ function isInert(element) {
391
300
  function isUngroupedRadio(element) {
392
301
  return element.type === "radio" && !!element.name;
393
302
  }
303
+ function resolveOptions(options) {
304
+ let {
305
+ anchor = getActiveElement(),
306
+ composed = false,
307
+ filter,
308
+ include,
309
+ skipNegativeTabIndexCheck = false,
310
+ skipVisibilityCheck = false,
311
+ wrap = false
312
+ } = options;
313
+ if (!(anchor instanceof Element)) {
314
+ const active = getActiveElement();
315
+ if (active instanceof Element) {
316
+ console.warn("Invalid anchor element. Fallback: active element.");
317
+ anchor = active;
318
+ }
319
+ }
320
+ if (typeof composed !== "boolean") {
321
+ console.warn("Invalid composed option. Fallback: false.");
322
+ composed = false;
323
+ }
324
+ if (filter !== void 0 && typeof filter !== "function") {
325
+ console.warn(
326
+ "Invalid filter function. Fallback: no filter function (undefined)."
327
+ );
328
+ filter = void 0;
329
+ }
330
+ if (include !== void 0 && typeof include !== "function") {
331
+ console.warn(
332
+ "Invalid include function. Fallback: no include function (undefined)."
333
+ );
334
+ include = void 0;
335
+ }
336
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
337
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
338
+ skipNegativeTabIndexCheck = false;
339
+ }
340
+ if (typeof skipVisibilityCheck !== "boolean") {
341
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
342
+ skipVisibilityCheck = false;
343
+ }
344
+ if (typeof wrap !== "boolean") {
345
+ console.warn("Invalid wrap option. Fallback: false.");
346
+ wrap = false;
347
+ }
348
+ return {
349
+ anchor,
350
+ composed,
351
+ filter,
352
+ include,
353
+ skipNegativeTabIndexCheck,
354
+ skipVisibilityCheck,
355
+ wrap
356
+ };
357
+ }
394
358
 
395
359
  // src/index.ts
396
360
  var VISUALLY_HIDDEN_CSS = `border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;`;
@@ -429,7 +393,7 @@ var Portal = class {
429
393
  container = document.body;
430
394
  }
431
395
  this.#container = container;
432
- this.#settings = resolveOptions(options);
396
+ this.#settings = resolveOptions2(options);
433
397
  this.#entranceSentinel = this.#createSentinel();
434
398
  this.#exitSentinel = this.#createSentinel();
435
399
  this.#initialize();
@@ -455,9 +419,9 @@ var Portal = class {
455
419
  this.#update();
456
420
  this.#controller = new AbortController();
457
421
  const { signal } = this.#controller;
458
- [this.#entranceSentinel, this.#exitSentinel].forEach((sentinel) => {
422
+ for (const sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
459
423
  sentinel.addEventListener("focus", this.#onFocus, { signal });
460
- });
424
+ }
461
425
  this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
462
426
  this.#host.setAttribute("data-portaled", "");
463
427
  }
@@ -567,7 +531,7 @@ function containsComposed2(container, element) {
567
531
  }
568
532
  return false;
569
533
  }
570
- function resolveOptions(options) {
534
+ function resolveOptions2(options) {
571
535
  let { noInlineStyle = false } = options;
572
536
  if (typeof noInlineStyle !== "boolean") {
573
537
  console.warn("Invalid noInlineStyle option. Fallback: false.");
@@ -580,7 +544,7 @@ function resolveOptions(options) {
580
544
  * Lightweight DOM portal (teleport) utility with fully focus management.
581
545
  * Designed for accessible dialogs, menus, overlays, popovers.
582
546
  *
583
- * @version 1.3.4
547
+ * @version 1.3.6
584
548
  * @author Yusuke Kamiyamane
585
549
  * @license MIT
586
550
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -592,7 +556,7 @@ function resolveOptions(options) {
592
556
  (**
593
557
  * Attribute Utils
594
558
  *
595
- * @version 2.0.6
559
+ * @version 2.0.10
596
560
  * @author Yusuke Kamiyamane
597
561
  * @license MIT
598
562
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -605,7 +569,7 @@ power-focusable/dist/index.js:
605
569
  * High-precision focus management utility with full composed tree support.
606
570
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
607
571
  *
608
- * @version 4.3.28
572
+ * @version 4.3.30
609
573
  * @author Yusuke Kamiyamane
610
574
  * @license MIT
611
575
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -14,20 +14,20 @@ function restoreAttributes(element_or_elements) {
14
14
  }
15
15
  function saveAttributes(element_or_elements, name_or_names) {
16
16
  const names = Array.isArray(name_or_names) ? name_or_names : [name_or_names];
17
- (Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]).forEach((element) => {
17
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
18
18
  let snapshot = snapshots.get(element);
19
19
  if (!snapshot) {
20
20
  snapshot = /* @__PURE__ */ new Map();
21
21
  snapshots.set(element, snapshot);
22
22
  }
23
- names.forEach((name) => {
23
+ for (const name of names) {
24
24
  snapshot.set(name, element.getAttribute(name));
25
- });
26
- });
25
+ }
26
+ }
27
27
  }
28
28
 
29
29
  // node_modules/power-focusable/dist/index.js
30
- 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"])`;
30
+ 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"])';
31
31
  var FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX = FOCUSABLE_SELECTOR.replace(
32
32
  /(,\s*)?\[tabindex="-1"\]/g,
33
33
  ""
@@ -37,37 +37,13 @@ function getFocusables(container = document.body, options = {}) {
37
37
  console.warn("Invalid container element. Fallback: <body> element.");
38
38
  container = document.body;
39
39
  }
40
- let {
41
- composed = false,
40
+ const {
41
+ composed,
42
42
  filter,
43
43
  include,
44
- skipNegativeTabIndexCheck = false,
45
- skipVisibilityCheck = false
46
- } = options;
47
- if (typeof composed !== "boolean") {
48
- console.warn("Invalid composed option. Fallback: false.");
49
- composed = false;
50
- }
51
- if (typeof filter !== "undefined" && typeof filter !== "function") {
52
- console.warn(
53
- "Invalid filter function. Fallback: no filter function (undefined)."
54
- );
55
- filter = void 0;
56
- }
57
- if (typeof include !== "undefined" && typeof include !== "function") {
58
- console.warn(
59
- "Invalid include function. Fallback: no include function (undefined)."
60
- );
61
- include = void 0;
62
- }
63
- if (typeof skipNegativeTabIndexCheck !== "boolean") {
64
- console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
65
- skipNegativeTabIndexCheck = false;
66
- }
67
- if (typeof skipVisibilityCheck !== "boolean") {
68
- console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
69
- skipVisibilityCheck = false;
70
- }
44
+ skipNegativeTabIndexCheck,
45
+ skipVisibilityCheck
46
+ } = resolveOptions(options);
71
47
  const candidates = [];
72
48
  if (composed || include) {
73
49
  let traverse2 = function(node) {
@@ -77,29 +53,19 @@ function getFocusables(container = document.body, options = {}) {
77
53
  }) || include?.(node)) {
78
54
  candidates[candidates.length] = node;
79
55
  }
80
- const children2 = composed ? getComposedChildren(node) : getChildren(node);
81
- for (let i = 0, l = children2.length; i < l; i++) {
82
- const child = children2[i];
83
- child && traverse2(child);
84
- }
56
+ (composed ? getComposedChildren(node) : getChildren(node)).map(traverse2);
85
57
  };
86
- const children = composed ? getComposedChildren(container) : getChildren(container);
87
- for (let i = 0, l = children.length; i < l; i++) {
88
- const child = children[i];
89
- child && traverse2(child);
90
- }
58
+ (composed ? getComposedChildren(container) : getChildren(container)).map(
59
+ traverse2
60
+ );
91
61
  } else {
92
- const matches = container.querySelectorAll(
62
+ for (const match of container.querySelectorAll(
93
63
  skipNegativeTabIndexCheck ? FOCUSABLE_SELECTOR_WITH_NEGATIVE_TABINDEX : FOCUSABLE_SELECTOR
94
- );
95
- for (let i = 0, l = matches.length; i < l; i++) {
96
- const matched = matches[i];
97
- if (matched && isFocusable(matched, {
64
+ )) {
65
+ match && isFocusable(match, {
98
66
  skipNegativeTabIndexCheck,
99
67
  skipVisibilityCheck
100
- })) {
101
- candidates[candidates.length] = matched;
102
- }
68
+ }) && candidates.push(match);
103
69
  }
104
70
  }
105
71
  return normalizeRadioGroup(
@@ -117,15 +83,7 @@ function isFocusable(element, options = {}) {
117
83
  console.warn("Invalid element");
118
84
  return false;
119
85
  }
120
- let { skipNegativeTabIndexCheck = false, skipVisibilityCheck = false } = options;
121
- if (typeof skipNegativeTabIndexCheck !== "boolean") {
122
- console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
123
- skipNegativeTabIndexCheck = false;
124
- }
125
- if (typeof skipVisibilityCheck !== "boolean") {
126
- console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
127
- skipVisibilityCheck = false;
128
- }
86
+ const { skipNegativeTabIndexCheck, skipVisibilityCheck } = resolveOptions(options);
129
87
  if (element.hasAttribute("hidden") || isInert(element)) {
130
88
  return false;
131
89
  }
@@ -154,65 +112,30 @@ function getRelativeFocusable(container, offset, options) {
154
112
  console.warn("Invalid container element. Fallback: <body> element.");
155
113
  container = document.body;
156
114
  }
157
- let {
158
- anchor = getActiveElement(),
159
- composed = false,
115
+ const {
116
+ anchor,
117
+ composed,
160
118
  filter,
161
119
  include,
162
- skipNegativeTabIndexCheck = false,
163
- skipVisibilityCheck = false,
164
- wrap = false
165
- } = options;
120
+ skipNegativeTabIndexCheck,
121
+ skipVisibilityCheck,
122
+ wrap
123
+ } = resolveOptions(options);
166
124
  if (!(anchor instanceof Element)) {
167
- const active = getActiveElement();
168
- if (active instanceof Element) {
169
- console.warn("Invalid anchor element. Fallback: active element.");
170
- anchor = active;
171
- } else {
172
- console.warn("Invalid anchor element");
173
- return null;
174
- }
125
+ console.warn("Invalid anchor element");
126
+ return null;
175
127
  }
176
128
  if (!containsComposed(container, anchor)) {
177
129
  console.warn("Anchor (active) element not within container");
178
130
  return null;
179
131
  }
180
- if (typeof composed !== "boolean") {
181
- console.warn("Invalid composed option. Fallback: false.");
182
- composed = false;
183
- }
184
- if (typeof filter !== "undefined" && typeof filter !== "function") {
185
- console.warn(
186
- "Invalid filter function. Fallback: no filter function (undefined)."
187
- );
188
- filter = void 0;
189
- }
190
- if (typeof include !== "undefined" && typeof include !== "function") {
191
- console.warn(
192
- "Invalid include function. Fallback: no include function (undefined)."
193
- );
194
- include = void 0;
195
- }
196
- if (typeof skipNegativeTabIndexCheck !== "boolean") {
197
- console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
198
- skipNegativeTabIndexCheck = false;
199
- }
200
- if (typeof skipVisibilityCheck !== "boolean") {
201
- console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
202
- skipVisibilityCheck = false;
203
- }
204
- if (typeof wrap !== "boolean") {
205
- console.warn("Invalid wrap option. Fallback: false.");
206
- wrap = false;
207
- }
208
- const settings = {
132
+ const focusables = getFocusables(container, {
209
133
  composed,
134
+ filter,
135
+ include,
210
136
  skipNegativeTabIndexCheck,
211
137
  skipVisibilityCheck
212
- };
213
- filter && Object.assign(settings, { filter });
214
- include && Object.assign(settings, { include });
215
- const focusables = getFocusables(container, settings);
138
+ });
216
139
  const { length } = focusables;
217
140
  if (!length) {
218
141
  return null;
@@ -258,8 +181,7 @@ function isDisabledDeep(element) {
258
181
  }
259
182
  function normalizeRadioGroup(elements) {
260
183
  let map = null;
261
- for (let i = 0, l = elements.length; i < l; i++) {
262
- const element = elements[i];
184
+ for (const element of elements) {
263
185
  if (!(element instanceof HTMLInputElement)) {
264
186
  continue;
265
187
  }
@@ -309,23 +231,10 @@ function normalizeRadioGroup(elements) {
309
231
  function sortByTabIndex(elements) {
310
232
  const ordered = [];
311
233
  const natural = [];
312
- for (let i = 0, l = elements.length; i < l; i++) {
313
- const element = elements[i];
314
- if (element) {
315
- const target = getTabIndex(element) > 0 ? ordered : natural;
316
- target[target.length] = element;
317
- }
318
- }
319
- ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b));
320
- let count = 0;
321
- const sorted = new Array(ordered.length + natural.length);
322
- for (let i = 0, l = ordered.length; i < l; i++) {
323
- sorted[count++] = ordered[i];
324
- }
325
- for (let i = 0, l = natural.length; i < l; i++) {
326
- sorted[count++] = natural[i];
234
+ for (const element of elements) {
235
+ (getTabIndex(element) > 0 ? ordered : natural).push(element);
327
236
  }
328
- return sorted;
237
+ return ordered.sort((a, b) => getTabIndex(a) - getTabIndex(b)).concat(natural);
329
238
  }
330
239
  function containsComposed(container, element) {
331
240
  let current = element;
@@ -389,6 +298,61 @@ function isInert(element) {
389
298
  function isUngroupedRadio(element) {
390
299
  return element.type === "radio" && !!element.name;
391
300
  }
301
+ function resolveOptions(options) {
302
+ let {
303
+ anchor = getActiveElement(),
304
+ composed = false,
305
+ filter,
306
+ include,
307
+ skipNegativeTabIndexCheck = false,
308
+ skipVisibilityCheck = false,
309
+ wrap = false
310
+ } = options;
311
+ if (!(anchor instanceof Element)) {
312
+ const active = getActiveElement();
313
+ if (active instanceof Element) {
314
+ console.warn("Invalid anchor element. Fallback: active element.");
315
+ anchor = active;
316
+ }
317
+ }
318
+ if (typeof composed !== "boolean") {
319
+ console.warn("Invalid composed option. Fallback: false.");
320
+ composed = false;
321
+ }
322
+ if (filter !== void 0 && typeof filter !== "function") {
323
+ console.warn(
324
+ "Invalid filter function. Fallback: no filter function (undefined)."
325
+ );
326
+ filter = void 0;
327
+ }
328
+ if (include !== void 0 && typeof include !== "function") {
329
+ console.warn(
330
+ "Invalid include function. Fallback: no include function (undefined)."
331
+ );
332
+ include = void 0;
333
+ }
334
+ if (typeof skipNegativeTabIndexCheck !== "boolean") {
335
+ console.warn("Invalid skipNegativeTabIndexCheck option. Fallback: false.");
336
+ skipNegativeTabIndexCheck = false;
337
+ }
338
+ if (typeof skipVisibilityCheck !== "boolean") {
339
+ console.warn("Invalid skipVisibilityCheck option. Fallback: false.");
340
+ skipVisibilityCheck = false;
341
+ }
342
+ if (typeof wrap !== "boolean") {
343
+ console.warn("Invalid wrap option. Fallback: false.");
344
+ wrap = false;
345
+ }
346
+ return {
347
+ anchor,
348
+ composed,
349
+ filter,
350
+ include,
351
+ skipNegativeTabIndexCheck,
352
+ skipVisibilityCheck,
353
+ wrap
354
+ };
355
+ }
392
356
 
393
357
  // src/index.ts
394
358
  var VISUALLY_HIDDEN_CSS = `border: 0; clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; user-select: none; white-space: nowrap; width: 1px;`;
@@ -427,7 +391,7 @@ var Portal = class {
427
391
  container = document.body;
428
392
  }
429
393
  this.#container = container;
430
- this.#settings = resolveOptions(options);
394
+ this.#settings = resolveOptions2(options);
431
395
  this.#entranceSentinel = this.#createSentinel();
432
396
  this.#exitSentinel = this.#createSentinel();
433
397
  this.#initialize();
@@ -453,9 +417,9 @@ var Portal = class {
453
417
  this.#update();
454
418
  this.#controller = new AbortController();
455
419
  const { signal } = this.#controller;
456
- [this.#entranceSentinel, this.#exitSentinel].forEach((sentinel) => {
420
+ for (const sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
457
421
  sentinel.addEventListener("focus", this.#onFocus, { signal });
458
- });
422
+ }
459
423
  this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
460
424
  this.#host.setAttribute("data-portaled", "");
461
425
  }
@@ -565,7 +529,7 @@ function containsComposed2(container, element) {
565
529
  }
566
530
  return false;
567
531
  }
568
- function resolveOptions(options) {
532
+ function resolveOptions2(options) {
569
533
  let { noInlineStyle = false } = options;
570
534
  if (typeof noInlineStyle !== "boolean") {
571
535
  console.warn("Invalid noInlineStyle option. Fallback: false.");
@@ -578,7 +542,7 @@ function resolveOptions(options) {
578
542
  * Lightweight DOM portal (teleport) utility with fully focus management.
579
543
  * Designed for accessible dialogs, menus, overlays, popovers.
580
544
  *
581
- * @version 1.3.4
545
+ * @version 1.3.6
582
546
  * @author Yusuke Kamiyamane
583
547
  * @license MIT
584
548
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -590,7 +554,7 @@ function resolveOptions(options) {
590
554
  (**
591
555
  * Attribute Utils
592
556
  *
593
- * @version 2.0.6
557
+ * @version 2.0.10
594
558
  * @author Yusuke Kamiyamane
595
559
  * @license MIT
596
560
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -603,7 +567,7 @@ power-focusable/dist/index.js:
603
567
  * High-precision focus management utility with full composed tree support.
604
568
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
605
569
  *
606
- * @version 4.3.28
570
+ * @version 4.3.30
607
571
  * @author Yusuke Kamiyamane
608
572
  * @license MIT
609
573
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.cjs CHANGED
@@ -87,9 +87,9 @@ var Portal = class {
87
87
  this.#update();
88
88
  this.#controller = new AbortController();
89
89
  const { signal } = this.#controller;
90
- [this.#entranceSentinel, this.#exitSentinel].forEach((sentinel) => {
90
+ for (const sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
91
91
  sentinel.addEventListener("focus", this.#onFocus, { signal });
92
- });
92
+ }
93
93
  this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
94
94
  this.#host.setAttribute("data-portaled", "");
95
95
  }
@@ -212,7 +212,7 @@ function resolveOptions(options) {
212
212
  * Lightweight DOM portal (teleport) utility with fully focus management.
213
213
  * Designed for accessible dialogs, menus, overlays, popovers.
214
214
  *
215
- * @version 1.3.4
215
+ * @version 1.3.6
216
216
  * @author Yusuke Kamiyamane
217
217
  * @license MIT
218
218
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Lightweight DOM portal (teleport) utility with fully focus management.
4
4
  * Designed for accessible dialogs, menus, overlays, popovers.
5
5
  *
6
- * @version 1.3.4
6
+ * @version 1.3.6
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 DOM portal (teleport) utility with fully focus management.
4
4
  * Designed for accessible dialogs, menus, overlays, popovers.
5
5
  *
6
- * @version 1.3.4
6
+ * @version 1.3.6
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -64,9 +64,9 @@ var Portal = class {
64
64
  this.#update();
65
65
  this.#controller = new AbortController();
66
66
  const { signal } = this.#controller;
67
- [this.#entranceSentinel, this.#exitSentinel].forEach((sentinel) => {
67
+ for (const sentinel of [this.#entranceSentinel, this.#exitSentinel]) {
68
68
  sentinel.addEventListener("focus", this.#onFocus, { signal });
69
- });
69
+ }
70
70
  this.#host.addEventListener("keydown", this.#onKeyDown, { signal });
71
71
  this.#host.setAttribute("data-portaled", "");
72
72
  }
@@ -189,7 +189,7 @@ function resolveOptions(options) {
189
189
  * Lightweight DOM portal (teleport) utility with fully focus management.
190
190
  * Designed for accessible dialogs, menus, overlays, popovers.
191
191
  *
192
- * @version 1.3.4
192
+ * @version 1.3.6
193
193
  * @author Yusuke Kamiyamane
194
194
  * @license MIT
195
195
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,28 +1,7 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
4
4
  "description": "Lightweight DOM portal (teleport) utility with fully focus management",
5
- "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
14
- }
15
- },
16
- "files": [
17
- "dist",
18
- "LICENSE",
19
- "README.md"
20
- ],
21
- "scripts": {
22
- "build": "tsup",
23
- "prepublishOnly": "npm run build",
24
- "lint": "tsc --noEmit"
25
- },
26
5
  "keywords": [
27
6
  "a11y",
28
7
  "accessibility",
@@ -36,16 +15,37 @@
36
15
  "typescript",
37
16
  "utility"
38
17
  ],
39
- "author": "Yusuke Kamiyamane",
40
- "license": "MIT",
18
+ "homepage": "https://github.com/y14e/portal#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/y14e/portal/issues"
21
+ },
41
22
  "repository": {
42
23
  "type": "git",
43
24
  "url": "git+https://github.com/y14e/portal.git"
44
25
  },
45
- "bugs": {
46
- "url": "https://github.com/y14e/portal/issues"
26
+ "license": "MIT",
27
+ "author": "Yusuke Kamiyamane",
28
+ "type": "module",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js",
33
+ "require": "./dist/index.cjs"
34
+ }
35
+ },
36
+ "main": "./dist/index.cjs",
37
+ "module": "./dist/index.js",
38
+ "types": "./dist/index.d.ts",
39
+ "files": [
40
+ "dist",
41
+ "LICENSE",
42
+ "README.md"
43
+ ],
44
+ "scripts": {
45
+ "build": "tsup",
46
+ "lint": "tsc --noEmit",
47
+ "prepublishOnly": "npm run build"
47
48
  },
48
- "homepage": "https://github.com/y14e/portal#readme",
49
49
  "devDependencies": {
50
50
  "bun-types": "latest",
51
51
  "tsup": "^8.0.0",
@@ -58,7 +58,7 @@
58
58
  "esbuild": true
59
59
  },
60
60
  "dependencies": {
61
- "@y14e/attribute-utils": "^2.0.6",
62
- "power-focusable": "^4.3.28"
61
+ "@y14e/attribute-utils": "^2.0.10",
62
+ "power-focusable": "^4.3.30"
63
63
  }
64
64
  }