@y14e/disclosure 1.3.11 → 1.3.12

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/disclosure
10
10
 
11
11
  ```ts
12
12
  // npm
13
- import Disclosure from '@y14e/disclosure@1.3.11';
13
+ import Disclosure from '@y14e/disclosure@1.3.12';
14
14
 
15
15
  // CDNs
16
- import Disclosure from 'https://esm.sh/@y14e/disclosure@1.3.11';
16
+ import Disclosure from 'https://esm.sh/@y14e/disclosure@1.3.12';
17
17
  // or
18
- import Disclosure from 'https://cdn.jsdelivr.net/npm/@y14e/disclosure@1.3.11/+esm';
18
+ import Disclosure from 'https://cdn.jsdelivr.net/npm/@y14e/disclosure@1.3.12/+esm';
19
19
  // or
20
- import Disclosure from 'https://esm.unpkg.com/@y14e/disclosure@1.3.11';
20
+ import Disclosure from 'https://esm.unpkg.com/@y14e/disclosure@1.3.12';
21
21
  ```
22
22
 
23
23
  ## Usage
package/dist/index.cjs CHANGED
@@ -400,11 +400,10 @@ var RovingTabIndex = class {
400
400
  }
401
401
  #onFocusIn = (event) => {
402
402
  const { target } = event;
403
- if (!(target instanceof Element)) {
404
- return;
403
+ if (target instanceof Element) {
404
+ const isFocusable22 = this.#focusables.has(target);
405
+ this.#options.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
405
406
  }
406
- const isFocusable22 = this.#focusables.has(target);
407
- this.#options.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
408
407
  };
409
408
  #onKeyDown = (event) => {
410
409
  if (!event.composedPath().includes(this.#container)) {
@@ -494,11 +493,11 @@ var RovingTabIndex = class {
494
493
  if (!typeahead) {
495
494
  continue;
496
495
  }
496
+ const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
497
497
  const value = focusable.ariaKeyShortcuts?.trim();
498
498
  const keys = new Set(
499
499
  value ? value.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
500
500
  );
501
- const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
502
501
  if (char) {
503
502
  keys.add(char);
504
503
  saveAttributes2([focusable], ["aria-keyshortcuts"]);
@@ -611,13 +610,12 @@ var Disclosure = class _Disclosure {
611
610
  this.#detailsElements.forEach((details, i) => {
612
611
  const summary = this.#summaryElements[i];
613
612
  const content = this.#contentElements[i];
614
- if (!summary || !content) {
615
- return;
613
+ if (summary && content) {
614
+ const binding = createBinding(details, summary, content);
615
+ this.#bindings.set(details, binding);
616
+ this.#bindings.set(summary, binding);
617
+ this.#bindings.set(content, binding);
616
618
  }
617
- const binding = createBinding(details, summary, content);
618
- this.#bindings.set(details, binding);
619
- this.#bindings.set(summary, binding);
620
- this.#bindings.set(content, binding);
621
619
  });
622
620
  this.#initialize();
623
621
  }
@@ -625,11 +623,11 @@ var Disclosure = class _Disclosure {
625
623
  if (this.#isDestroyed) {
626
624
  return;
627
625
  }
628
- if (!(details instanceof HTMLDetailsElement) || !this.#bindings.has(details)) {
626
+ if (details instanceof HTMLDetailsElement && this.#bindings.has(details)) {
627
+ this.#toggle(details, false);
628
+ } else {
629
629
  console.warn("Invalid <details> element");
630
- return;
631
630
  }
632
- this.#toggle(details, false);
633
631
  }
634
632
  async destroy(force = false) {
635
633
  if (this.#isDestroyed) {
@@ -666,11 +664,11 @@ var Disclosure = class _Disclosure {
666
664
  if (this.#isDestroyed) {
667
665
  return;
668
666
  }
669
- if (!(details instanceof HTMLDetailsElement) || !this.#bindings.has(details)) {
667
+ if (details instanceof HTMLDetailsElement && this.#bindings.has(details)) {
668
+ this.#toggle(details, true);
669
+ } else {
670
670
  console.warn("Invalid <details> element");
671
- return;
672
671
  }
673
- this.#toggle(details, true);
674
672
  }
675
673
  #initialize() {
676
674
  saveAttributes(this.#summaryElements, [
@@ -715,11 +713,10 @@ var Disclosure = class _Disclosure {
715
713
  return;
716
714
  }
717
715
  const binding = this.#bindings.get(summary);
718
- if (!binding) {
719
- return;
716
+ if (binding) {
717
+ const { details } = binding;
718
+ this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
720
719
  }
721
- const { details } = binding;
722
- this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
723
720
  };
724
721
  #toggle(details, isOpen) {
725
722
  if (details.hasAttribute("data-disclosure-open") === isOpen) {
@@ -817,17 +814,18 @@ function isFocusable2(element) {
817
814
  function waitAnimationFinish(animation) {
818
815
  if (["idle", "finished"].includes(animation.playState)) {
819
816
  return Promise.resolve();
817
+ } else {
818
+ return new Promise(
819
+ (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
820
+ );
820
821
  }
821
- return new Promise(
822
- (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
823
- );
824
822
  }
825
823
  /**
826
824
  * Disclosure
827
825
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
828
826
  * Using the <details> and <summary> element.
829
827
  *
830
- * @version 1.3.11
828
+ * @version 1.3.12
831
829
  * @author Yusuke Kamiyamane
832
830
  * @license MIT
833
831
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -852,7 +850,7 @@ function waitAnimationFinish(animation) {
852
850
  * Lightweight roving tabindex utility with fully focus management.
853
851
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
854
852
  *
855
- * @version 3.0.2
853
+ * @version 3.0.4
856
854
  * @author Yusuke Kamiyamane
857
855
  * @license MIT
858
856
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@
3
3
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
4
4
  * Using the <details> and <summary> element.
5
5
  *
6
- * @version 1.3.11
6
+ * @version 1.3.12
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
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
4
4
  * Using the <details> and <summary> element.
5
5
  *
6
- * @version 1.3.11
6
+ * @version 1.3.12
7
7
  * @author Yusuke Kamiyamane
8
8
  * @license MIT
9
9
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -398,11 +398,10 @@ var RovingTabIndex = class {
398
398
  }
399
399
  #onFocusIn = (event) => {
400
400
  const { target } = event;
401
- if (!(target instanceof Element)) {
402
- return;
401
+ if (target instanceof Element) {
402
+ const isFocusable22 = this.#focusables.has(target);
403
+ this.#options.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
403
404
  }
404
- const isFocusable22 = this.#focusables.has(target);
405
- this.#options.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
406
405
  };
407
406
  #onKeyDown = (event) => {
408
407
  if (!event.composedPath().includes(this.#container)) {
@@ -492,11 +491,11 @@ var RovingTabIndex = class {
492
491
  if (!typeahead) {
493
492
  continue;
494
493
  }
494
+ const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
495
495
  const value = focusable.ariaKeyShortcuts?.trim();
496
496
  const keys = new Set(
497
497
  value ? value.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
498
498
  );
499
- const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
500
499
  if (char) {
501
500
  keys.add(char);
502
501
  saveAttributes2([focusable], ["aria-keyshortcuts"]);
@@ -609,13 +608,12 @@ var Disclosure = class _Disclosure {
609
608
  this.#detailsElements.forEach((details, i) => {
610
609
  const summary = this.#summaryElements[i];
611
610
  const content = this.#contentElements[i];
612
- if (!summary || !content) {
613
- return;
611
+ if (summary && content) {
612
+ const binding = createBinding(details, summary, content);
613
+ this.#bindings.set(details, binding);
614
+ this.#bindings.set(summary, binding);
615
+ this.#bindings.set(content, binding);
614
616
  }
615
- const binding = createBinding(details, summary, content);
616
- this.#bindings.set(details, binding);
617
- this.#bindings.set(summary, binding);
618
- this.#bindings.set(content, binding);
619
617
  });
620
618
  this.#initialize();
621
619
  }
@@ -623,11 +621,11 @@ var Disclosure = class _Disclosure {
623
621
  if (this.#isDestroyed) {
624
622
  return;
625
623
  }
626
- if (!(details instanceof HTMLDetailsElement) || !this.#bindings.has(details)) {
624
+ if (details instanceof HTMLDetailsElement && this.#bindings.has(details)) {
625
+ this.#toggle(details, false);
626
+ } else {
627
627
  console.warn("Invalid <details> element");
628
- return;
629
628
  }
630
- this.#toggle(details, false);
631
629
  }
632
630
  async destroy(force = false) {
633
631
  if (this.#isDestroyed) {
@@ -664,11 +662,11 @@ var Disclosure = class _Disclosure {
664
662
  if (this.#isDestroyed) {
665
663
  return;
666
664
  }
667
- if (!(details instanceof HTMLDetailsElement) || !this.#bindings.has(details)) {
665
+ if (details instanceof HTMLDetailsElement && this.#bindings.has(details)) {
666
+ this.#toggle(details, true);
667
+ } else {
668
668
  console.warn("Invalid <details> element");
669
- return;
670
669
  }
671
- this.#toggle(details, true);
672
670
  }
673
671
  #initialize() {
674
672
  saveAttributes(this.#summaryElements, [
@@ -713,11 +711,10 @@ var Disclosure = class _Disclosure {
713
711
  return;
714
712
  }
715
713
  const binding = this.#bindings.get(summary);
716
- if (!binding) {
717
- return;
714
+ if (binding) {
715
+ const { details } = binding;
716
+ this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
718
717
  }
719
- const { details } = binding;
720
- this.#toggle(details, !details.hasAttribute("data-disclosure-open"));
721
718
  };
722
719
  #toggle(details, isOpen) {
723
720
  if (details.hasAttribute("data-disclosure-open") === isOpen) {
@@ -815,17 +812,18 @@ function isFocusable2(element) {
815
812
  function waitAnimationFinish(animation) {
816
813
  if (["idle", "finished"].includes(animation.playState)) {
817
814
  return Promise.resolve();
815
+ } else {
816
+ return new Promise(
817
+ (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
818
+ );
818
819
  }
819
- return new Promise(
820
- (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
821
- );
822
820
  }
823
821
  /**
824
822
  * Disclosure
825
823
  * WAI-ARIA compliant disclosure pattern implementation in TypeScript.
826
824
  * Using the <details> and <summary> element.
827
825
  *
828
- * @version 1.3.11
826
+ * @version 1.3.12
829
827
  * @author Yusuke Kamiyamane
830
828
  * @license MIT
831
829
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -850,7 +848,7 @@ function waitAnimationFinish(animation) {
850
848
  * Lightweight roving tabindex utility with fully focus management.
851
849
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
852
850
  *
853
- * @version 3.0.2
851
+ * @version 3.0.4
854
852
  * @author Yusuke Kamiyamane
855
853
  * @license MIT
856
854
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/disclosure",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "description": "WAI-ARIA compliant disclosure pattern implementation in TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -44,7 +44,7 @@
44
44
  "homepage": "https://github.com/y14e/disclosure#readme",
45
45
  "devDependencies": {
46
46
  "@y14e/attributes-utils": "^1.1.2",
47
- "@y14e/roving-tabindex": "^3.0.2",
47
+ "@y14e/roving-tabindex": "^3.0.4",
48
48
  "bun-types": "latest",
49
49
  "tsup": "^8.0.0",
50
50
  "typescript": "^5.6.0",