@y14e/portal 1.3.8 → 1.4.1

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.8';
16
+ import { createPortal } from 'https://esm.sh/@y14e/portal@1.4.1';
17
17
  // or
18
- import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.3.8/+esm';
18
+ import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.4.1/+esm';
19
19
  // or
20
- import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.3.8';
20
+ import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.4.1';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
@@ -3,27 +3,27 @@
3
3
  // node_modules/@y14e/attribute-utils/dist/index.js
4
4
  var snapshots = /* @__PURE__ */ new WeakMap();
5
5
  function restoreAttributes(element_or_elements) {
6
- for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
7
- const snapshot = snapshots.get(e);
6
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
7
+ const snapshot = snapshots.get(element);
8
8
  if (!snapshot) {
9
9
  continue;
10
10
  }
11
- for (const [n, v] of snapshot.entries()) {
12
- v === null ? e.removeAttribute(n) : e.setAttribute(n, v);
11
+ for (const [name, value] of snapshot.entries()) {
12
+ value === null ? element.removeAttribute(name) : element.setAttribute(name, value);
13
13
  }
14
- snapshots.delete(e);
14
+ snapshots.delete(element);
15
15
  }
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
- for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
20
- let snapshot = snapshots.get(e);
19
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
20
+ let snapshot = snapshots.get(element);
21
21
  if (!snapshot) {
22
22
  snapshot = /* @__PURE__ */ new Map();
23
- snapshots.set(e, snapshot);
23
+ snapshots.set(element, snapshot);
24
24
  }
25
- for (const n of names) {
26
- snapshot.set(n, e.getAttribute(n));
25
+ for (const name of names) {
26
+ snapshot.set(name, element.getAttribute(name));
27
27
  }
28
28
  }
29
29
  }
@@ -194,31 +194,25 @@ function normalizeRadioGroup(elements) {
194
194
  map = /* @__PURE__ */ new Map();
195
195
  }
196
196
  const root = element.getRootNode();
197
- let groups = map.get(root);
197
+ const groups = map.get(root) ?? map.set(root, /* @__PURE__ */ new Map()).get(root);
198
198
  if (!groups) {
199
- groups = /* @__PURE__ */ new Map();
200
- map.set(root, groups);
201
- }
202
- let group = groups.get(element.form);
203
- if (!group) {
204
- group = /* @__PURE__ */ new Map();
205
- groups.set(element.form, group);
199
+ continue;
206
200
  }
207
- let radios = group.get(element.name);
201
+ const { form, name } = element;
202
+ const radios = groups.get(form) ?? groups.set(form, /* @__PURE__ */ new Map()).get(form);
208
203
  if (!radios) {
209
- radios = [];
210
- group.set(element.name, radios);
204
+ continue;
211
205
  }
212
- radios.push(element);
206
+ (radios.get(name) ?? radios.set(name, []).get(name))?.push(element);
213
207
  }
214
208
  if (!map) {
215
209
  return elements;
216
210
  }
217
211
  const placeholder = /* @__PURE__ */ new Set();
218
- for (const groups of map.values()) {
219
- for (const group of groups.values()) {
220
- for (const radios of group.values()) {
221
- const radio = radios.find((r) => r.checked) ?? radios[0];
212
+ for (const v of map.values()) {
213
+ for (const w of v.values()) {
214
+ for (const x of w.values()) {
215
+ const radio = x.find((r) => r.checked) ?? x[0];
222
216
  radio && placeholder.add(radio);
223
217
  }
224
218
  }
@@ -362,7 +356,7 @@ function createPortal(host, container = document.body, options = {}) {
362
356
  return () => {
363
357
  };
364
358
  }
365
- if (containsComposed2(host, container)) {
359
+ if (containsComposed(host, container)) {
366
360
  console.warn("Host element cannot contain the container element");
367
361
  return () => {
368
362
  };
@@ -386,7 +380,7 @@ var Portal = class {
386
380
  container = document.body;
387
381
  }
388
382
  this.#container = container;
389
- this.#settings = resolveOptions2(options);
383
+ this.#settings = this.#resolveOptions(options);
390
384
  this.#entranceSentinel = this.#createSentinel();
391
385
  this.#exitSentinel = this.#createSentinel();
392
386
  this.#initialize();
@@ -513,31 +507,21 @@ var Portal = class {
513
507
  const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
514
508
  focusable && focusElement(focusable);
515
509
  }
516
- };
517
- function containsComposed2(container, element) {
518
- let current = element;
519
- while (current) {
520
- if (current === container) {
521
- return true;
510
+ #resolveOptions(options) {
511
+ let { noInlineStyle = false } = options;
512
+ if (typeof noInlineStyle !== "boolean") {
513
+ console.warn("Invalid noInlineStyle option. Fallback: false.");
514
+ noInlineStyle = false;
522
515
  }
523
- current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
524
- }
525
- return false;
526
- }
527
- function resolveOptions2(options) {
528
- let { noInlineStyle = false } = options;
529
- if (typeof noInlineStyle !== "boolean") {
530
- console.warn("Invalid noInlineStyle option. Fallback: false.");
531
- noInlineStyle = false;
516
+ return { noInlineStyle };
532
517
  }
533
- return { noInlineStyle };
534
- }
518
+ };
535
519
  /**
536
520
  * Portal
537
521
  * Lightweight DOM portal (teleport) utility with fully focus management.
538
522
  * Designed for accessible dialogs, menus, overlays, popovers.
539
523
  *
540
- * @version 1.3.8
524
+ * @version 1.4.1
541
525
  * @author Yusuke Kamiyamane
542
526
  * @license MIT
543
527
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -549,7 +533,7 @@ function resolveOptions2(options) {
549
533
  (**
550
534
  * Attribute Utils
551
535
  *
552
- * @version 2.0.11
536
+ * @version 2.0.12
553
537
  * @author Yusuke Kamiyamane
554
538
  * @license MIT
555
539
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -562,7 +546,7 @@ power-focusable/dist/index.js:
562
546
  * High-precision focus management utility with full composed tree support.
563
547
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
564
548
  *
565
- * @version 4.3.33
549
+ * @version 4.4.3
566
550
  * @author Yusuke Kamiyamane
567
551
  * @license MIT
568
552
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -1,27 +1,27 @@
1
1
  // node_modules/@y14e/attribute-utils/dist/index.js
2
2
  var snapshots = /* @__PURE__ */ new WeakMap();
3
3
  function restoreAttributes(element_or_elements) {
4
- for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
5
- const snapshot = snapshots.get(e);
4
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
5
+ const snapshot = snapshots.get(element);
6
6
  if (!snapshot) {
7
7
  continue;
8
8
  }
9
- for (const [n, v] of snapshot.entries()) {
10
- v === null ? e.removeAttribute(n) : e.setAttribute(n, v);
9
+ for (const [name, value] of snapshot.entries()) {
10
+ value === null ? element.removeAttribute(name) : element.setAttribute(name, value);
11
11
  }
12
- snapshots.delete(e);
12
+ snapshots.delete(element);
13
13
  }
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
- for (const e of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
18
- let snapshot = snapshots.get(e);
17
+ for (const element of Array.isArray(element_or_elements) ? element_or_elements : [element_or_elements]) {
18
+ let snapshot = snapshots.get(element);
19
19
  if (!snapshot) {
20
20
  snapshot = /* @__PURE__ */ new Map();
21
- snapshots.set(e, snapshot);
21
+ snapshots.set(element, snapshot);
22
22
  }
23
- for (const n of names) {
24
- snapshot.set(n, e.getAttribute(n));
23
+ for (const name of names) {
24
+ snapshot.set(name, element.getAttribute(name));
25
25
  }
26
26
  }
27
27
  }
@@ -192,31 +192,25 @@ function normalizeRadioGroup(elements) {
192
192
  map = /* @__PURE__ */ new Map();
193
193
  }
194
194
  const root = element.getRootNode();
195
- let groups = map.get(root);
195
+ const groups = map.get(root) ?? map.set(root, /* @__PURE__ */ new Map()).get(root);
196
196
  if (!groups) {
197
- groups = /* @__PURE__ */ new Map();
198
- map.set(root, groups);
199
- }
200
- let group = groups.get(element.form);
201
- if (!group) {
202
- group = /* @__PURE__ */ new Map();
203
- groups.set(element.form, group);
197
+ continue;
204
198
  }
205
- let radios = group.get(element.name);
199
+ const { form, name } = element;
200
+ const radios = groups.get(form) ?? groups.set(form, /* @__PURE__ */ new Map()).get(form);
206
201
  if (!radios) {
207
- radios = [];
208
- group.set(element.name, radios);
202
+ continue;
209
203
  }
210
- radios.push(element);
204
+ (radios.get(name) ?? radios.set(name, []).get(name))?.push(element);
211
205
  }
212
206
  if (!map) {
213
207
  return elements;
214
208
  }
215
209
  const placeholder = /* @__PURE__ */ new Set();
216
- for (const groups of map.values()) {
217
- for (const group of groups.values()) {
218
- for (const radios of group.values()) {
219
- const radio = radios.find((r) => r.checked) ?? radios[0];
210
+ for (const v of map.values()) {
211
+ for (const w of v.values()) {
212
+ for (const x of w.values()) {
213
+ const radio = x.find((r) => r.checked) ?? x[0];
220
214
  radio && placeholder.add(radio);
221
215
  }
222
216
  }
@@ -360,7 +354,7 @@ function createPortal(host, container = document.body, options = {}) {
360
354
  return () => {
361
355
  };
362
356
  }
363
- if (containsComposed2(host, container)) {
357
+ if (containsComposed(host, container)) {
364
358
  console.warn("Host element cannot contain the container element");
365
359
  return () => {
366
360
  };
@@ -384,7 +378,7 @@ var Portal = class {
384
378
  container = document.body;
385
379
  }
386
380
  this.#container = container;
387
- this.#settings = resolveOptions2(options);
381
+ this.#settings = this.#resolveOptions(options);
388
382
  this.#entranceSentinel = this.#createSentinel();
389
383
  this.#exitSentinel = this.#createSentinel();
390
384
  this.#initialize();
@@ -511,31 +505,21 @@ var Portal = class {
511
505
  const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
512
506
  focusable && focusElement(focusable);
513
507
  }
514
- };
515
- function containsComposed2(container, element) {
516
- let current = element;
517
- while (current) {
518
- if (current === container) {
519
- return true;
508
+ #resolveOptions(options) {
509
+ let { noInlineStyle = false } = options;
510
+ if (typeof noInlineStyle !== "boolean") {
511
+ console.warn("Invalid noInlineStyle option. Fallback: false.");
512
+ noInlineStyle = false;
520
513
  }
521
- current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
522
- }
523
- return false;
524
- }
525
- function resolveOptions2(options) {
526
- let { noInlineStyle = false } = options;
527
- if (typeof noInlineStyle !== "boolean") {
528
- console.warn("Invalid noInlineStyle option. Fallback: false.");
529
- noInlineStyle = false;
514
+ return { noInlineStyle };
530
515
  }
531
- return { noInlineStyle };
532
- }
516
+ };
533
517
  /**
534
518
  * Portal
535
519
  * Lightweight DOM portal (teleport) utility with fully focus management.
536
520
  * Designed for accessible dialogs, menus, overlays, popovers.
537
521
  *
538
- * @version 1.3.8
522
+ * @version 1.4.1
539
523
  * @author Yusuke Kamiyamane
540
524
  * @license MIT
541
525
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -547,7 +531,7 @@ function resolveOptions2(options) {
547
531
  (**
548
532
  * Attribute Utils
549
533
  *
550
- * @version 2.0.11
534
+ * @version 2.0.12
551
535
  * @author Yusuke Kamiyamane
552
536
  * @license MIT
553
537
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -560,7 +544,7 @@ power-focusable/dist/index.js:
560
544
  * High-precision focus management utility with full composed tree support.
561
545
  * Handles complex focus rules including tabindex ordering, radio groups, inert.
562
546
  *
563
- * @version 4.3.33
547
+ * @version 4.4.3
564
548
  * @author Yusuke Kamiyamane
565
549
  * @license MIT
566
550
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.cjs CHANGED
@@ -1,28 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var utils = require('@y14e/attribute-utils');
4
- var pf = require('power-focusable');
5
-
6
- function _interopNamespace(e) {
7
- if (e && e.__esModule) return e;
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var utils__namespace = /*#__PURE__*/_interopNamespace(utils);
25
- var pf__namespace = /*#__PURE__*/_interopNamespace(pf);
3
+ var attributeUtils = require('@y14e/attribute-utils');
4
+ var powerFocusable = require('power-focusable');
26
5
 
27
6
  // src/index.ts
28
7
  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;";
@@ -37,7 +16,7 @@ function createPortal(host, container = document.body, options = {}) {
37
16
  return () => {
38
17
  };
39
18
  }
40
- if (containsComposed(host, container)) {
19
+ if (powerFocusable.containsComposed(host, container)) {
41
20
  console.warn("Host element cannot contain the container element");
42
21
  return () => {
43
22
  };
@@ -61,7 +40,7 @@ var Portal = class {
61
40
  container = document.body;
62
41
  }
63
42
  this.#container = container;
64
- this.#settings = resolveOptions(options);
43
+ this.#settings = this.#resolveOptions(options);
65
44
  this.#entranceSentinel = this.#createSentinel();
66
45
  this.#exitSentinel = this.#createSentinel();
67
46
  this.#initialize();
@@ -73,7 +52,7 @@ var Portal = class {
73
52
  this.#isDestroyed = true;
74
53
  this.#controller?.abort();
75
54
  this.#controller = null;
76
- utils__namespace.restoreAttributes([...this.#focusables]);
55
+ attributeUtils.restoreAttributes([...this.#focusables]);
77
56
  this.#focusables.clear();
78
57
  this.#exitSentinel.after(this.#host);
79
58
  this.#entranceSentinel.remove();
@@ -105,7 +84,7 @@ var Portal = class {
105
84
  }
106
85
  this.#update();
107
86
  const first = [...this.#focusables][0];
108
- first ? pf__namespace.focusElement(first) : this.#moveFocus("next");
87
+ first ? powerFocusable.focusElement(first) : this.#moveFocus("next");
109
88
  } else {
110
89
  if (this.#host.contains(previous)) {
111
90
  this.#moveFocus("next");
@@ -113,7 +92,7 @@ var Portal = class {
113
92
  }
114
93
  this.#update();
115
94
  const last = [...this.#focusables].at(-1);
116
- last ? pf__namespace.focusElement(last) : this.#moveFocus("previous");
95
+ last ? powerFocusable.focusElement(last) : this.#moveFocus("previous");
117
96
  }
118
97
  };
119
98
  #onKeyDown = (event) => {
@@ -124,7 +103,7 @@ var Portal = class {
124
103
  if (key !== "Tab" || altKey || ctrlKey || metaKey) {
125
104
  return;
126
105
  }
127
- const active = pf__namespace.getActiveElement();
106
+ const active = powerFocusable.getActiveElement();
128
107
  if (!(active instanceof Element)) {
129
108
  return;
130
109
  }
@@ -135,7 +114,7 @@ var Portal = class {
135
114
  if (index >= 0) {
136
115
  event.preventDefault();
137
116
  const focusable = focusables[index + (shiftKey ? -1 : 1)];
138
- focusable ? pf__namespace.focusElement(focusable) : this.#focusSentinel(shiftKey);
117
+ focusable ? powerFocusable.focusElement(focusable) : this.#focusSentinel(shiftKey);
139
118
  }
140
119
  } else {
141
120
  event.preventDefault();
@@ -145,18 +124,18 @@ var Portal = class {
145
124
  #update() {
146
125
  const current = /* @__PURE__ */ new Set([
147
126
  ...this.#getFocusables(),
148
- ...pf__namespace.getFocusables(this.#host, { composed: true })
127
+ ...powerFocusable.getFocusables(this.#host, { composed: true })
149
128
  ]);
150
129
  for (const focusable of this.#focusables) {
151
130
  if (!current.has(focusable)) {
152
- utils__namespace.restoreAttributes(focusable);
131
+ attributeUtils.restoreAttributes(focusable);
153
132
  this.#focusables.delete(focusable);
154
133
  }
155
134
  }
156
135
  for (const focusable of current) {
157
136
  if (!this.#focusables.has(focusable)) {
158
137
  this.#focusables.add(focusable);
159
- utils__namespace.saveAttributes(focusable, "tabindex");
138
+ attributeUtils.saveAttributes(focusable, "tabindex");
160
139
  focusable.setAttribute("tabindex", "-1");
161
140
  }
162
141
  }
@@ -175,7 +154,7 @@ var Portal = class {
175
154
  (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
176
155
  }
177
156
  #getFocusables() {
178
- return pf__namespace.getFocusables(this.#host, {
157
+ return powerFocusable.getFocusables(this.#host, {
179
158
  composed: true,
180
159
  include: (element) => this.#focusables.has(element)
181
160
  });
@@ -185,34 +164,24 @@ var Portal = class {
185
164
  anchor: direction === "previous" ? this.#entranceSentinel : this.#exitSentinel,
186
165
  composed: true
187
166
  };
188
- const focusable = direction === "previous" ? pf__namespace.getPreviousFocusable(document.body, options) : pf__namespace.getNextFocusable(document.body, options);
189
- focusable && pf__namespace.focusElement(focusable);
167
+ const focusable = direction === "previous" ? powerFocusable.getPreviousFocusable(document.body, options) : powerFocusable.getNextFocusable(document.body, options);
168
+ focusable && powerFocusable.focusElement(focusable);
190
169
  }
191
- };
192
- function containsComposed(container, element) {
193
- let current = element;
194
- while (current) {
195
- if (current === container) {
196
- return true;
170
+ #resolveOptions(options) {
171
+ let { noInlineStyle = false } = options;
172
+ if (typeof noInlineStyle !== "boolean") {
173
+ console.warn("Invalid noInlineStyle option. Fallback: false.");
174
+ noInlineStyle = false;
197
175
  }
198
- current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
199
- }
200
- return false;
201
- }
202
- function resolveOptions(options) {
203
- let { noInlineStyle = false } = options;
204
- if (typeof noInlineStyle !== "boolean") {
205
- console.warn("Invalid noInlineStyle option. Fallback: false.");
206
- noInlineStyle = false;
176
+ return { noInlineStyle };
207
177
  }
208
- return { noInlineStyle };
209
- }
178
+ };
210
179
  /**
211
180
  * Portal
212
181
  * Lightweight DOM portal (teleport) utility with fully focus management.
213
182
  * Designed for accessible dialogs, menus, overlays, popovers.
214
183
  *
215
- * @version 1.3.8
184
+ * @version 1.4.1
216
185
  * @author Yusuke Kamiyamane
217
186
  * @license MIT
218
187
  * @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.8
6
+ * @version 1.4.1
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.8
6
+ * @version 1.4.1
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import * as utils from '@y14e/attribute-utils';
2
- import * as pf from 'power-focusable';
1
+ import { restoreAttributes, saveAttributes } from '@y14e/attribute-utils';
2
+ import { containsComposed, focusElement, getActiveElement, getFocusables, getPreviousFocusable, getNextFocusable } from 'power-focusable';
3
3
 
4
4
  // src/index.ts
5
5
  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;";
@@ -38,7 +38,7 @@ var Portal = class {
38
38
  container = document.body;
39
39
  }
40
40
  this.#container = container;
41
- this.#settings = resolveOptions(options);
41
+ this.#settings = this.#resolveOptions(options);
42
42
  this.#entranceSentinel = this.#createSentinel();
43
43
  this.#exitSentinel = this.#createSentinel();
44
44
  this.#initialize();
@@ -50,7 +50,7 @@ var Portal = class {
50
50
  this.#isDestroyed = true;
51
51
  this.#controller?.abort();
52
52
  this.#controller = null;
53
- utils.restoreAttributes([...this.#focusables]);
53
+ restoreAttributes([...this.#focusables]);
54
54
  this.#focusables.clear();
55
55
  this.#exitSentinel.after(this.#host);
56
56
  this.#entranceSentinel.remove();
@@ -82,7 +82,7 @@ var Portal = class {
82
82
  }
83
83
  this.#update();
84
84
  const first = [...this.#focusables][0];
85
- first ? pf.focusElement(first) : this.#moveFocus("next");
85
+ first ? focusElement(first) : this.#moveFocus("next");
86
86
  } else {
87
87
  if (this.#host.contains(previous)) {
88
88
  this.#moveFocus("next");
@@ -90,7 +90,7 @@ var Portal = class {
90
90
  }
91
91
  this.#update();
92
92
  const last = [...this.#focusables].at(-1);
93
- last ? pf.focusElement(last) : this.#moveFocus("previous");
93
+ last ? focusElement(last) : this.#moveFocus("previous");
94
94
  }
95
95
  };
96
96
  #onKeyDown = (event) => {
@@ -101,7 +101,7 @@ var Portal = class {
101
101
  if (key !== "Tab" || altKey || ctrlKey || metaKey) {
102
102
  return;
103
103
  }
104
- const active = pf.getActiveElement();
104
+ const active = getActiveElement();
105
105
  if (!(active instanceof Element)) {
106
106
  return;
107
107
  }
@@ -112,7 +112,7 @@ var Portal = class {
112
112
  if (index >= 0) {
113
113
  event.preventDefault();
114
114
  const focusable = focusables[index + (shiftKey ? -1 : 1)];
115
- focusable ? pf.focusElement(focusable) : this.#focusSentinel(shiftKey);
115
+ focusable ? focusElement(focusable) : this.#focusSentinel(shiftKey);
116
116
  }
117
117
  } else {
118
118
  event.preventDefault();
@@ -122,18 +122,18 @@ var Portal = class {
122
122
  #update() {
123
123
  const current = /* @__PURE__ */ new Set([
124
124
  ...this.#getFocusables(),
125
- ...pf.getFocusables(this.#host, { composed: true })
125
+ ...getFocusables(this.#host, { composed: true })
126
126
  ]);
127
127
  for (const focusable of this.#focusables) {
128
128
  if (!current.has(focusable)) {
129
- utils.restoreAttributes(focusable);
129
+ restoreAttributes(focusable);
130
130
  this.#focusables.delete(focusable);
131
131
  }
132
132
  }
133
133
  for (const focusable of current) {
134
134
  if (!this.#focusables.has(focusable)) {
135
135
  this.#focusables.add(focusable);
136
- utils.saveAttributes(focusable, "tabindex");
136
+ saveAttributes(focusable, "tabindex");
137
137
  focusable.setAttribute("tabindex", "-1");
138
138
  }
139
139
  }
@@ -152,7 +152,7 @@ var Portal = class {
152
152
  (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
153
153
  }
154
154
  #getFocusables() {
155
- return pf.getFocusables(this.#host, {
155
+ return getFocusables(this.#host, {
156
156
  composed: true,
157
157
  include: (element) => this.#focusables.has(element)
158
158
  });
@@ -162,34 +162,24 @@ var Portal = class {
162
162
  anchor: direction === "previous" ? this.#entranceSentinel : this.#exitSentinel,
163
163
  composed: true
164
164
  };
165
- const focusable = direction === "previous" ? pf.getPreviousFocusable(document.body, options) : pf.getNextFocusable(document.body, options);
166
- focusable && pf.focusElement(focusable);
165
+ const focusable = direction === "previous" ? getPreviousFocusable(document.body, options) : getNextFocusable(document.body, options);
166
+ focusable && focusElement(focusable);
167
167
  }
168
- };
169
- function containsComposed(container, element) {
170
- let current = element;
171
- while (current) {
172
- if (current === container) {
173
- return true;
168
+ #resolveOptions(options) {
169
+ let { noInlineStyle = false } = options;
170
+ if (typeof noInlineStyle !== "boolean") {
171
+ console.warn("Invalid noInlineStyle option. Fallback: false.");
172
+ noInlineStyle = false;
174
173
  }
175
- current = current instanceof ShadowRoot ? current.mode === "open" ? current.host : null : current.parentNode;
176
- }
177
- return false;
178
- }
179
- function resolveOptions(options) {
180
- let { noInlineStyle = false } = options;
181
- if (typeof noInlineStyle !== "boolean") {
182
- console.warn("Invalid noInlineStyle option. Fallback: false.");
183
- noInlineStyle = false;
174
+ return { noInlineStyle };
184
175
  }
185
- return { noInlineStyle };
186
- }
176
+ };
187
177
  /**
188
178
  * Portal
189
179
  * Lightweight DOM portal (teleport) utility with fully focus management.
190
180
  * Designed for accessible dialogs, menus, overlays, popovers.
191
181
  *
192
- * @version 1.3.8
182
+ * @version 1.4.1
193
183
  * @author Yusuke Kamiyamane
194
184
  * @license MIT
195
185
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.3.8",
3
+ "version": "1.4.1",
4
4
  "description": "Lightweight DOM portal (teleport) utility with fully focus management",
5
5
  "keywords": [
6
6
  "a11y",
@@ -58,7 +58,7 @@
58
58
  "esbuild": true
59
59
  },
60
60
  "dependencies": {
61
- "@y14e/attribute-utils": "^2.0.11",
62
- "power-focusable": "^4.3.33"
61
+ "@y14e/attribute-utils": "^2.0.12",
62
+ "power-focusable": "^4.4.3"
63
63
  }
64
64
  }