@y14e/accordion 1.4.10 → 1.4.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/accordion
10
10
 
11
11
  ```ts
12
12
  // npm
13
- import Accordion from '@y14e/accordion@1.4.10';
13
+ import Accordion from '@y14e/accordion@1.4.12';
14
14
 
15
15
  // CDNs
16
- import Accordion from 'https://esm.sh/@y14e/accordion@1.4.10';
16
+ import Accordion from 'https://esm.sh/@y14e/accordion@1.4.12';
17
17
  // or
18
- import Accordion from 'https://cdn.jsdelivr.net/npm/@y14e/accordion@1.4.10/+esm';
18
+ import Accordion from 'https://cdn.jsdelivr.net/npm/@y14e/accordion@1.4.12/+esm';
19
19
  // or
20
- import Accordion from 'https://esm.unpkg.com/@y14e/accordion@1.4.10';
20
+ import Accordion from 'https://esm.unpkg.com/@y14e/accordion@1.4.12';
21
21
  ```
22
22
 
23
23
  ## Usage
package/dist/index.cjs CHANGED
@@ -90,10 +90,11 @@ var Button = class {
90
90
  return;
91
91
  }
92
92
  const active = getActiveElement();
93
- if (active instanceof HTMLElement) {
94
- event.preventDefault();
95
- active.click();
93
+ if (!(active instanceof HTMLElement)) {
94
+ return;
96
95
  }
96
+ event.preventDefault();
97
+ active.click();
97
98
  };
98
99
  };
99
100
  function getActiveElement() {
@@ -477,10 +478,11 @@ var RovingTabIndex = class {
477
478
  }
478
479
  #onFocusIn = (event) => {
479
480
  const { target } = event;
480
- if (target instanceof Element) {
481
- const isFocusable22 = this.#focusables.has(target);
482
- this.#options.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
481
+ if (!(target instanceof Element)) {
482
+ return;
483
483
  }
484
+ const isFocusable22 = this.#focusables.has(target);
485
+ this.#options.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
484
486
  };
485
487
  #onKeyDown = (event) => {
486
488
  if (!event.composedPath().includes(this.#container)) {
@@ -678,11 +680,12 @@ var Accordion = class _Accordion {
678
680
  }
679
681
  this.#triggerElements.forEach((trigger2, i) => {
680
682
  const content2 = this.#contentElements[i];
681
- if (content2) {
682
- const binding = createBinding(trigger2, content2);
683
- this.#bindings.set(trigger2, binding);
684
- this.#bindings.set(content2, binding);
683
+ if (!content2) {
684
+ return;
685
685
  }
686
+ const binding = createBinding(trigger2, content2);
687
+ this.#bindings.set(trigger2, binding);
688
+ this.#bindings.set(content2, binding);
686
689
  });
687
690
  this.#initialize();
688
691
  }
@@ -690,11 +693,11 @@ var Accordion = class _Accordion {
690
693
  if (this.#isDestroyed) {
691
694
  return;
692
695
  }
693
- if (trigger instanceof HTMLElement && this.#bindings.has(trigger)) {
694
- this.#toggle(trigger, false);
695
- } else {
696
+ if (!(trigger instanceof HTMLElement) || !this.#bindings.has(trigger)) {
696
697
  console.warn("Invalid trigger element");
698
+ return;
697
699
  }
700
+ this.#toggle(trigger, false);
698
701
  }
699
702
  async destroy(force = false) {
700
703
  if (this.#isDestroyed) {
@@ -725,11 +728,11 @@ var Accordion = class _Accordion {
725
728
  if (this.#isDestroyed) {
726
729
  return;
727
730
  }
728
- if (trigger instanceof HTMLElement && this.#bindings.has(trigger)) {
729
- this.#toggle(trigger, true);
730
- } else {
731
+ if (!(trigger instanceof HTMLElement) || !this.#bindings.has(trigger)) {
731
732
  console.warn("Invalid trigger element");
733
+ return;
732
734
  }
735
+ this.#toggle(trigger, true);
733
736
  }
734
737
  #initialize() {
735
738
  saveAttributes(this.#triggerElements, [
@@ -780,16 +783,21 @@ var Accordion = class _Accordion {
780
783
  #onTriggerClick = (event) => {
781
784
  event.preventDefault();
782
785
  const trigger = event.currentTarget;
783
- if (trigger instanceof HTMLElement) {
784
- this.#toggle(trigger, trigger.ariaExpanded === "false");
786
+ if (!(trigger instanceof HTMLElement)) {
787
+ return;
785
788
  }
789
+ this.#toggle(trigger, trigger.ariaExpanded === "false");
786
790
  };
787
791
  #onContentBeforeMatch = (event) => {
788
792
  const content = event.currentTarget;
789
- if (content instanceof HTMLElement) {
790
- const binding = this.#bindings.get(content);
791
- binding && binding.trigger.ariaExpanded === "false" && this.#toggle(binding.trigger, true, true);
793
+ if (!(content instanceof HTMLElement)) {
794
+ return;
792
795
  }
796
+ const binding = this.#bindings.get(content);
797
+ if (!binding) {
798
+ return;
799
+ }
800
+ binding.trigger.ariaExpanded === "false" && this.#toggle(binding.trigger, true, true);
793
801
  };
794
802
  #toggle(trigger, isOpen, isMatch = false) {
795
803
  if (trigger.ariaExpanded === String(isOpen)) {
@@ -854,7 +862,10 @@ var Accordion = class _Accordion {
854
862
  }
855
863
  #onAnimationFinish(content) {
856
864
  const trigger = this.#bindings.get(content)?.trigger;
857
- if (trigger && trigger.ariaExpanded === "false") {
865
+ if (!trigger) {
866
+ return;
867
+ }
868
+ if (trigger.ariaExpanded === "false") {
858
869
  content.setAttribute("hidden", "until-found");
859
870
  }
860
871
  ["block-size", "overflow"].forEach((name) => {
@@ -889,7 +900,7 @@ function waitAnimationFinish(animation) {
889
900
  * Accordion
890
901
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
891
902
  *
892
- * @version 1.4.10
903
+ * @version 1.4.12
893
904
  * @author Yusuke Kamiyamane
894
905
  * @license MIT
895
906
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -912,7 +923,7 @@ function waitAnimationFinish(animation) {
912
923
  (**
913
924
  * Button
914
925
  *
915
- * @version 1.0.1
926
+ * @version 1.0.2
916
927
  * @author Yusuke Kamiyamane
917
928
  * @license MIT
918
929
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -925,7 +936,7 @@ function waitAnimationFinish(animation) {
925
936
  * Lightweight roving tabindex utility with fully focus management.
926
937
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
927
938
  *
928
- * @version 3.0.4
939
+ * @version 3.0.5
929
940
  * @author Yusuke Kamiyamane
930
941
  * @license MIT
931
942
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Accordion
3
3
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
4
4
  *
5
- * @version 1.4.10
5
+ * @version 1.4.12
6
6
  * @author Yusuke Kamiyamane
7
7
  * @license MIT
8
8
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Accordion
3
3
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
4
4
  *
5
- * @version 1.4.10
5
+ * @version 1.4.12
6
6
  * @author Yusuke Kamiyamane
7
7
  * @license MIT
8
8
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -88,10 +88,11 @@ var Button = class {
88
88
  return;
89
89
  }
90
90
  const active = getActiveElement();
91
- if (active instanceof HTMLElement) {
92
- event.preventDefault();
93
- active.click();
91
+ if (!(active instanceof HTMLElement)) {
92
+ return;
94
93
  }
94
+ event.preventDefault();
95
+ active.click();
95
96
  };
96
97
  };
97
98
  function getActiveElement() {
@@ -475,10 +476,11 @@ var RovingTabIndex = class {
475
476
  }
476
477
  #onFocusIn = (event) => {
477
478
  const { target } = event;
478
- if (target instanceof Element) {
479
- const isFocusable22 = this.#focusables.has(target);
480
- this.#options.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
479
+ if (!(target instanceof Element)) {
480
+ return;
481
481
  }
482
+ const isFocusable22 = this.#focusables.has(target);
483
+ this.#options.noMemory && !isFocusable22 ? this.#update(null) : isFocusable22 && this.#update(target);
482
484
  };
483
485
  #onKeyDown = (event) => {
484
486
  if (!event.composedPath().includes(this.#container)) {
@@ -676,11 +678,12 @@ var Accordion = class _Accordion {
676
678
  }
677
679
  this.#triggerElements.forEach((trigger2, i) => {
678
680
  const content2 = this.#contentElements[i];
679
- if (content2) {
680
- const binding = createBinding(trigger2, content2);
681
- this.#bindings.set(trigger2, binding);
682
- this.#bindings.set(content2, binding);
681
+ if (!content2) {
682
+ return;
683
683
  }
684
+ const binding = createBinding(trigger2, content2);
685
+ this.#bindings.set(trigger2, binding);
686
+ this.#bindings.set(content2, binding);
684
687
  });
685
688
  this.#initialize();
686
689
  }
@@ -688,11 +691,11 @@ var Accordion = class _Accordion {
688
691
  if (this.#isDestroyed) {
689
692
  return;
690
693
  }
691
- if (trigger instanceof HTMLElement && this.#bindings.has(trigger)) {
692
- this.#toggle(trigger, false);
693
- } else {
694
+ if (!(trigger instanceof HTMLElement) || !this.#bindings.has(trigger)) {
694
695
  console.warn("Invalid trigger element");
696
+ return;
695
697
  }
698
+ this.#toggle(trigger, false);
696
699
  }
697
700
  async destroy(force = false) {
698
701
  if (this.#isDestroyed) {
@@ -723,11 +726,11 @@ var Accordion = class _Accordion {
723
726
  if (this.#isDestroyed) {
724
727
  return;
725
728
  }
726
- if (trigger instanceof HTMLElement && this.#bindings.has(trigger)) {
727
- this.#toggle(trigger, true);
728
- } else {
729
+ if (!(trigger instanceof HTMLElement) || !this.#bindings.has(trigger)) {
729
730
  console.warn("Invalid trigger element");
731
+ return;
730
732
  }
733
+ this.#toggle(trigger, true);
731
734
  }
732
735
  #initialize() {
733
736
  saveAttributes(this.#triggerElements, [
@@ -778,16 +781,21 @@ var Accordion = class _Accordion {
778
781
  #onTriggerClick = (event) => {
779
782
  event.preventDefault();
780
783
  const trigger = event.currentTarget;
781
- if (trigger instanceof HTMLElement) {
782
- this.#toggle(trigger, trigger.ariaExpanded === "false");
784
+ if (!(trigger instanceof HTMLElement)) {
785
+ return;
783
786
  }
787
+ this.#toggle(trigger, trigger.ariaExpanded === "false");
784
788
  };
785
789
  #onContentBeforeMatch = (event) => {
786
790
  const content = event.currentTarget;
787
- if (content instanceof HTMLElement) {
788
- const binding = this.#bindings.get(content);
789
- binding && binding.trigger.ariaExpanded === "false" && this.#toggle(binding.trigger, true, true);
791
+ if (!(content instanceof HTMLElement)) {
792
+ return;
790
793
  }
794
+ const binding = this.#bindings.get(content);
795
+ if (!binding) {
796
+ return;
797
+ }
798
+ binding.trigger.ariaExpanded === "false" && this.#toggle(binding.trigger, true, true);
791
799
  };
792
800
  #toggle(trigger, isOpen, isMatch = false) {
793
801
  if (trigger.ariaExpanded === String(isOpen)) {
@@ -852,7 +860,10 @@ var Accordion = class _Accordion {
852
860
  }
853
861
  #onAnimationFinish(content) {
854
862
  const trigger = this.#bindings.get(content)?.trigger;
855
- if (trigger && trigger.ariaExpanded === "false") {
863
+ if (!trigger) {
864
+ return;
865
+ }
866
+ if (trigger.ariaExpanded === "false") {
856
867
  content.setAttribute("hidden", "until-found");
857
868
  }
858
869
  ["block-size", "overflow"].forEach((name) => {
@@ -887,7 +898,7 @@ function waitAnimationFinish(animation) {
887
898
  * Accordion
888
899
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
889
900
  *
890
- * @version 1.4.10
901
+ * @version 1.4.12
891
902
  * @author Yusuke Kamiyamane
892
903
  * @license MIT
893
904
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -910,7 +921,7 @@ function waitAnimationFinish(animation) {
910
921
  (**
911
922
  * Button
912
923
  *
913
- * @version 1.0.1
924
+ * @version 1.0.2
914
925
  * @author Yusuke Kamiyamane
915
926
  * @license MIT
916
927
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -923,7 +934,7 @@ function waitAnimationFinish(animation) {
923
934
  * Lightweight roving tabindex utility with fully focus management.
924
935
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
925
936
  *
926
- * @version 3.0.4
937
+ * @version 3.0.5
927
938
  * @author Yusuke Kamiyamane
928
939
  * @license MIT
929
940
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/accordion",
3
- "version": "1.4.10",
3
+ "version": "1.4.12",
4
4
  "description": "WAI-ARIA compliant accordion pattern implementation in TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -44,8 +44,8 @@
44
44
  "homepage": "https://github.com/y14e/accordion#readme",
45
45
  "devDependencies": {
46
46
  "@y14e/attributes-utils": "^1.1.2",
47
- "@y14e/button": "^1.0.1",
48
- "@y14e/roving-tabindex": "^3.0.4",
47
+ "@y14e/button": "^1.0.2",
48
+ "@y14e/roving-tabindex": "^3.0.5",
49
49
  "bun-types": "latest",
50
50
  "tsup": "^8.0.0",
51
51
  "typescript": "^5.6.0",