@y14e/portal 1.2.22 → 1.2.24

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/portal
10
10
 
11
11
  ```ts
12
12
  // npm
13
- import { createPortal } from '@y14e/portal@1.2.22';
13
+ import { createPortal } from '@y14e/portal@1.2.24';
14
14
 
15
15
  // CDNs
16
- import { createPortal } from 'https://esm.sh/@y14e/portal@1.2.22';
16
+ import { createPortal } from 'https://esm.sh/@y14e/portal@1.2.24';
17
17
  // or
18
- import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.2.22/+esm';
18
+ import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.2.24/+esm';
19
19
  // or
20
- import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.2.22';
20
+ import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.2.24';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
@@ -388,6 +388,7 @@ var Portal = class {
388
388
  #exitSentinel;
389
389
  #focusables = /* @__PURE__ */ new Set();
390
390
  #controller = null;
391
+ #timer;
391
392
  #isDestroyed = false;
392
393
  constructor(host, container) {
393
394
  this.#host = host;
@@ -407,6 +408,10 @@ var Portal = class {
407
408
  this.#isDestroyed = true;
408
409
  this.#controller?.abort();
409
410
  this.#controller = null;
411
+ if (this.#timer !== void 0) {
412
+ cancelAnimationFrame(this.#timer);
413
+ this.#timer = void 0;
414
+ }
410
415
  restoreAttributes([...this.#focusables]);
411
416
  this.#focusables.clear();
412
417
  this.#exitSentinel.after(this.#host);
@@ -421,14 +426,8 @@ var Portal = class {
421
426
  this.#update();
422
427
  this.#controller = new AbortController();
423
428
  const { signal } = this.#controller;
424
- document.addEventListener("focusin", this.#onFocusIn, {
425
- capture: true,
426
- signal
427
- });
428
- document.addEventListener("keydown", this.#onKeyDown, {
429
- capture: true,
430
- signal
431
- });
429
+ document.addEventListener("focusin", this.#onFocusIn, { signal });
430
+ document.addEventListener("keydown", this.#onKeyDown, { signal });
432
431
  this.#host.setAttribute("data-portaled", "");
433
432
  }
434
433
  #onFocusIn = (event) => {
@@ -525,7 +524,10 @@ var Portal = class {
525
524
  return sentinel;
526
525
  }
527
526
  #focusSentinel(isPrevious) {
528
- (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
527
+ this.#timer && cancelAnimationFrame(this.#timer);
528
+ this.#timer = requestAnimationFrame(
529
+ () => (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus()
530
+ );
529
531
  }
530
532
  #getFocusables() {
531
533
  return getFocusables(this.#host, {
@@ -557,7 +559,7 @@ function containsComposed2(container, element) {
557
559
  * Lightweight DOM portal (teleport) utility with fully focus management.
558
560
  * Designed for accessible dialogs, menus, overlays, popovers.
559
561
  *
560
- * @version 1.2.22
562
+ * @version 1.2.24
561
563
  * @author Yusuke Kamiyamane
562
564
  * @license MIT
563
565
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -386,6 +386,7 @@ var Portal = class {
386
386
  #exitSentinel;
387
387
  #focusables = /* @__PURE__ */ new Set();
388
388
  #controller = null;
389
+ #timer;
389
390
  #isDestroyed = false;
390
391
  constructor(host, container) {
391
392
  this.#host = host;
@@ -405,6 +406,10 @@ var Portal = class {
405
406
  this.#isDestroyed = true;
406
407
  this.#controller?.abort();
407
408
  this.#controller = null;
409
+ if (this.#timer !== void 0) {
410
+ cancelAnimationFrame(this.#timer);
411
+ this.#timer = void 0;
412
+ }
408
413
  restoreAttributes([...this.#focusables]);
409
414
  this.#focusables.clear();
410
415
  this.#exitSentinel.after(this.#host);
@@ -419,14 +424,8 @@ var Portal = class {
419
424
  this.#update();
420
425
  this.#controller = new AbortController();
421
426
  const { signal } = this.#controller;
422
- document.addEventListener("focusin", this.#onFocusIn, {
423
- capture: true,
424
- signal
425
- });
426
- document.addEventListener("keydown", this.#onKeyDown, {
427
- capture: true,
428
- signal
429
- });
427
+ document.addEventListener("focusin", this.#onFocusIn, { signal });
428
+ document.addEventListener("keydown", this.#onKeyDown, { signal });
430
429
  this.#host.setAttribute("data-portaled", "");
431
430
  }
432
431
  #onFocusIn = (event) => {
@@ -523,7 +522,10 @@ var Portal = class {
523
522
  return sentinel;
524
523
  }
525
524
  #focusSentinel(isPrevious) {
526
- (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
525
+ this.#timer && cancelAnimationFrame(this.#timer);
526
+ this.#timer = requestAnimationFrame(
527
+ () => (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus()
528
+ );
527
529
  }
528
530
  #getFocusables() {
529
531
  return getFocusables(this.#host, {
@@ -555,7 +557,7 @@ function containsComposed2(container, element) {
555
557
  * Lightweight DOM portal (teleport) utility with fully focus management.
556
558
  * Designed for accessible dialogs, menus, overlays, popovers.
557
559
  *
558
- * @version 1.2.22
560
+ * @version 1.2.24
559
561
  * @author Yusuke Kamiyamane
560
562
  * @license MIT
561
563
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.cjs CHANGED
@@ -31,6 +31,7 @@ var Portal = class {
31
31
  #exitSentinel;
32
32
  #focusables = /* @__PURE__ */ new Set();
33
33
  #controller = null;
34
+ #timer;
34
35
  #isDestroyed = false;
35
36
  constructor(host, container) {
36
37
  this.#host = host;
@@ -50,6 +51,10 @@ var Portal = class {
50
51
  this.#isDestroyed = true;
51
52
  this.#controller?.abort();
52
53
  this.#controller = null;
54
+ if (this.#timer !== void 0) {
55
+ cancelAnimationFrame(this.#timer);
56
+ this.#timer = void 0;
57
+ }
53
58
  attributesUtils.restoreAttributes([...this.#focusables]);
54
59
  this.#focusables.clear();
55
60
  this.#exitSentinel.after(this.#host);
@@ -64,14 +69,8 @@ var Portal = class {
64
69
  this.#update();
65
70
  this.#controller = new AbortController();
66
71
  const { signal } = this.#controller;
67
- document.addEventListener("focusin", this.#onFocusIn, {
68
- capture: true,
69
- signal
70
- });
71
- document.addEventListener("keydown", this.#onKeyDown, {
72
- capture: true,
73
- signal
74
- });
72
+ document.addEventListener("focusin", this.#onFocusIn, { signal });
73
+ document.addEventListener("keydown", this.#onKeyDown, { signal });
75
74
  this.#host.setAttribute("data-portaled", "");
76
75
  }
77
76
  #onFocusIn = (event) => {
@@ -168,7 +167,10 @@ var Portal = class {
168
167
  return sentinel;
169
168
  }
170
169
  #focusSentinel(isPrevious) {
171
- (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
170
+ this.#timer && cancelAnimationFrame(this.#timer);
171
+ this.#timer = requestAnimationFrame(
172
+ () => (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus()
173
+ );
172
174
  }
173
175
  #getFocusables() {
174
176
  return powerFocusable.getFocusables(this.#host, {
@@ -200,7 +202,7 @@ function containsComposed(container, element) {
200
202
  * Lightweight DOM portal (teleport) utility with fully focus management.
201
203
  * Designed for accessible dialogs, menus, overlays, popovers.
202
204
  *
203
- * @version 1.2.22
205
+ * @version 1.2.24
204
206
  * @author Yusuke Kamiyamane
205
207
  * @license MIT
206
208
  * @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.2.22
6
+ * @version 1.2.24
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.2.22
6
+ * @version 1.2.24
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ var Portal = class {
29
29
  #exitSentinel;
30
30
  #focusables = /* @__PURE__ */ new Set();
31
31
  #controller = null;
32
+ #timer;
32
33
  #isDestroyed = false;
33
34
  constructor(host, container) {
34
35
  this.#host = host;
@@ -48,6 +49,10 @@ var Portal = class {
48
49
  this.#isDestroyed = true;
49
50
  this.#controller?.abort();
50
51
  this.#controller = null;
52
+ if (this.#timer !== void 0) {
53
+ cancelAnimationFrame(this.#timer);
54
+ this.#timer = void 0;
55
+ }
51
56
  restoreAttributes([...this.#focusables]);
52
57
  this.#focusables.clear();
53
58
  this.#exitSentinel.after(this.#host);
@@ -62,14 +67,8 @@ var Portal = class {
62
67
  this.#update();
63
68
  this.#controller = new AbortController();
64
69
  const { signal } = this.#controller;
65
- document.addEventListener("focusin", this.#onFocusIn, {
66
- capture: true,
67
- signal
68
- });
69
- document.addEventListener("keydown", this.#onKeyDown, {
70
- capture: true,
71
- signal
72
- });
70
+ document.addEventListener("focusin", this.#onFocusIn, { signal });
71
+ document.addEventListener("keydown", this.#onKeyDown, { signal });
73
72
  this.#host.setAttribute("data-portaled", "");
74
73
  }
75
74
  #onFocusIn = (event) => {
@@ -166,7 +165,10 @@ var Portal = class {
166
165
  return sentinel;
167
166
  }
168
167
  #focusSentinel(isPrevious) {
169
- (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus();
168
+ this.#timer && cancelAnimationFrame(this.#timer);
169
+ this.#timer = requestAnimationFrame(
170
+ () => (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus()
171
+ );
170
172
  }
171
173
  #getFocusables() {
172
174
  return getFocusables(this.#host, {
@@ -198,7 +200,7 @@ function containsComposed(container, element) {
198
200
  * Lightweight DOM portal (teleport) utility with fully focus management.
199
201
  * Designed for accessible dialogs, menus, overlays, popovers.
200
202
  *
201
- * @version 1.2.22
203
+ * @version 1.2.24
202
204
  * @author Yusuke Kamiyamane
203
205
  * @license MIT
204
206
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.2.22",
3
+ "version": "1.2.24",
4
4
  "description": "Lightweight DOM portal (teleport) utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",