@y14e/portal 1.2.11 → 1.2.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/portal
10
10
 
11
11
  ```ts
12
12
  // npm
13
- import { createPortal } from '@y14e/portal@1.2.11';
13
+ import { createPortal } from '@y14e/portal@1.2.13';
14
14
 
15
15
  // CDNs
16
- import { createPortal } from 'https://esm.sh/@y14e/portal@1.2.11';
16
+ import { createPortal } from 'https://esm.sh/@y14e/portal@1.2.13';
17
17
  // or
18
- import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.2.11/+esm';
18
+ import { createPortal } from 'https://cdn.jsdelivr.net/npm/@y14e/portal@1.2.13/+esm';
19
19
  // or
20
- import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.2.11';
20
+ import { createPortal } from 'https://esm.unpkg.com/@y14e/portal@1.2.13';
21
21
  ```
22
22
 
23
23
  ## 📦 APIs
package/dist/index.cjs CHANGED
@@ -400,6 +400,7 @@ var Portal = class {
400
400
  #exitSentinel;
401
401
  #focusables = /* @__PURE__ */ new Set();
402
402
  #controller = null;
403
+ #timer;
403
404
  #isDestroyed = false;
404
405
  constructor(host, container) {
405
406
  this.#host = host;
@@ -415,6 +416,10 @@ var Portal = class {
415
416
  this.#isDestroyed = true;
416
417
  this.#controller?.abort();
417
418
  this.#controller = null;
419
+ if (this.#timer !== void 0) {
420
+ cancelAnimationFrame(this.#timer);
421
+ this.#timer = void 0;
422
+ }
418
423
  restoreAttributes([...this.#focusables]);
419
424
  this.#focusables.clear();
420
425
  this.#exitSentinel.after(this.#host);
@@ -452,15 +457,7 @@ var Portal = class {
452
457
  }
453
458
  this.#update();
454
459
  const first = [...this.#focusables][0];
455
- if (first) {
456
- focusElement(first);
457
- } else {
458
- const next = getNextFocusable(document.body, {
459
- anchor: this.#exitSentinel,
460
- composed: true
461
- });
462
- next && focusElement(next);
463
- }
460
+ first && focusElement(first);
464
461
  return;
465
462
  }
466
463
  if (current === this.#exitSentinel) {
@@ -470,15 +467,7 @@ var Portal = class {
470
467
  }
471
468
  this.#update();
472
469
  const last = [...this.#focusables].at(-1);
473
- if (last) {
474
- focusElement(last);
475
- } else {
476
- const previous = getPreviousFocusable(document.body, {
477
- anchor: this.#entranceSentinel,
478
- composed: true
479
- });
480
- previous && focusElement(previous);
481
- }
470
+ last && focusElement(last);
482
471
  return;
483
472
  }
484
473
  };
@@ -498,7 +487,7 @@ var Portal = class {
498
487
  const focusables = this.#getFocusables();
499
488
  if (!focusables.length) {
500
489
  event.preventDefault();
501
- this.#focusSentinel(shiftKey);
490
+ this.#moveFocus(shiftKey ? "previous" : "next");
502
491
  return;
503
492
  }
504
493
  const index = focusables.indexOf(active);
@@ -539,7 +528,8 @@ var Portal = class {
539
528
  return sentinel;
540
529
  }
541
530
  #focusSentinel(isPrevious) {
542
- requestAnimationFrame(
531
+ this.#timer && cancelAnimationFrame(this.#timer);
532
+ this.#timer = requestAnimationFrame(
543
533
  () => (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus()
544
534
  );
545
535
  }
@@ -583,7 +573,7 @@ function getActiveElement2() {
583
573
  * Lightweight DOM portal (teleport) utility with fully focus management.
584
574
  * Designed for accessible dialogs, menus, overlays, popovers.
585
575
  *
586
- * @version 1.2.11
576
+ * @version 1.2.13
587
577
  * @author Yusuke Kamiyamane
588
578
  * @license MIT
589
579
  * @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.11
6
+ * @version 1.2.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 DOM portal (teleport) utility with fully focus management.
4
4
  * Designed for accessible dialogs, menus, overlays, popovers.
5
5
  *
6
- * @version 1.2.11
6
+ * @version 1.2.13
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -398,6 +398,7 @@ var Portal = class {
398
398
  #exitSentinel;
399
399
  #focusables = /* @__PURE__ */ new Set();
400
400
  #controller = null;
401
+ #timer;
401
402
  #isDestroyed = false;
402
403
  constructor(host, container) {
403
404
  this.#host = host;
@@ -413,6 +414,10 @@ var Portal = class {
413
414
  this.#isDestroyed = true;
414
415
  this.#controller?.abort();
415
416
  this.#controller = null;
417
+ if (this.#timer !== void 0) {
418
+ cancelAnimationFrame(this.#timer);
419
+ this.#timer = void 0;
420
+ }
416
421
  restoreAttributes([...this.#focusables]);
417
422
  this.#focusables.clear();
418
423
  this.#exitSentinel.after(this.#host);
@@ -450,15 +455,7 @@ var Portal = class {
450
455
  }
451
456
  this.#update();
452
457
  const first = [...this.#focusables][0];
453
- if (first) {
454
- focusElement(first);
455
- } else {
456
- const next = getNextFocusable(document.body, {
457
- anchor: this.#exitSentinel,
458
- composed: true
459
- });
460
- next && focusElement(next);
461
- }
458
+ first && focusElement(first);
462
459
  return;
463
460
  }
464
461
  if (current === this.#exitSentinel) {
@@ -468,15 +465,7 @@ var Portal = class {
468
465
  }
469
466
  this.#update();
470
467
  const last = [...this.#focusables].at(-1);
471
- if (last) {
472
- focusElement(last);
473
- } else {
474
- const previous = getPreviousFocusable(document.body, {
475
- anchor: this.#entranceSentinel,
476
- composed: true
477
- });
478
- previous && focusElement(previous);
479
- }
468
+ last && focusElement(last);
480
469
  return;
481
470
  }
482
471
  };
@@ -496,7 +485,7 @@ var Portal = class {
496
485
  const focusables = this.#getFocusables();
497
486
  if (!focusables.length) {
498
487
  event.preventDefault();
499
- this.#focusSentinel(shiftKey);
488
+ this.#moveFocus(shiftKey ? "previous" : "next");
500
489
  return;
501
490
  }
502
491
  const index = focusables.indexOf(active);
@@ -537,7 +526,8 @@ var Portal = class {
537
526
  return sentinel;
538
527
  }
539
528
  #focusSentinel(isPrevious) {
540
- requestAnimationFrame(
529
+ this.#timer && cancelAnimationFrame(this.#timer);
530
+ this.#timer = requestAnimationFrame(
541
531
  () => (isPrevious ? this.#entranceSentinel : this.#exitSentinel).focus()
542
532
  );
543
533
  }
@@ -581,7 +571,7 @@ function getActiveElement2() {
581
571
  * Lightweight DOM portal (teleport) utility with fully focus management.
582
572
  * Designed for accessible dialogs, menus, overlays, popovers.
583
573
  *
584
- * @version 1.2.11
574
+ * @version 1.2.13
585
575
  * @author Yusuke Kamiyamane
586
576
  * @license MIT
587
577
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/portal",
3
- "version": "1.2.11",
3
+ "version": "1.2.13",
4
4
  "description": "Lightweight DOM portal (teleport) utility with fully focus management",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",