@y14e/accordion 1.4.9 → 1.4.11

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.9';
13
+ import Accordion from '@y14e/accordion@1.4.11';
14
14
 
15
15
  // CDNs
16
- import Accordion from 'https://esm.sh/@y14e/accordion@1.4.9';
16
+ import Accordion from 'https://esm.sh/@y14e/accordion@1.4.11';
17
17
  // or
18
- import Accordion from 'https://cdn.jsdelivr.net/npm/@y14e/accordion@1.4.9/+esm';
18
+ import Accordion from 'https://cdn.jsdelivr.net/npm/@y14e/accordion@1.4.11/+esm';
19
19
  // or
20
- import Accordion from 'https://esm.unpkg.com/@y14e/accordion@1.4.9';
20
+ import Accordion from 'https://esm.unpkg.com/@y14e/accordion@1.4.11';
21
21
  ```
22
22
 
23
23
  ## Usage
package/dist/index.cjs CHANGED
@@ -572,11 +572,11 @@ var RovingTabIndex = class {
572
572
  if (!typeahead) {
573
573
  continue;
574
574
  }
575
+ const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
575
576
  const value = focusable.ariaKeyShortcuts?.trim();
576
577
  const keys = new Set(
577
578
  value ? value.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
578
579
  );
579
- const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
580
580
  if (char) {
581
581
  keys.add(char);
582
582
  saveAttributes2([focusable], ["aria-keyshortcuts"]);
@@ -680,12 +680,11 @@ var Accordion = class _Accordion {
680
680
  }
681
681
  this.#triggerElements.forEach((trigger2, i) => {
682
682
  const content2 = this.#contentElements[i];
683
- if (!content2) {
684
- return;
683
+ if (content2) {
684
+ const binding = createBinding(trigger2, content2);
685
+ this.#bindings.set(trigger2, binding);
686
+ this.#bindings.set(content2, binding);
685
687
  }
686
- const binding = createBinding(trigger2, content2);
687
- this.#bindings.set(trigger2, binding);
688
- this.#bindings.set(content2, binding);
689
688
  });
690
689
  this.#initialize();
691
690
  }
@@ -693,11 +692,11 @@ var Accordion = class _Accordion {
693
692
  if (this.#isDestroyed) {
694
693
  return;
695
694
  }
696
- if (!(trigger instanceof HTMLElement) || !this.#bindings.has(trigger)) {
695
+ if (!(trigger instanceof HTMLElement)) {
697
696
  console.warn("Invalid trigger element");
698
697
  return;
699
698
  }
700
- this.#toggle(trigger, false);
699
+ this.#bindings.has(trigger) && this.#toggle(trigger, false);
701
700
  }
702
701
  async destroy(force = false) {
703
702
  if (this.#isDestroyed) {
@@ -728,11 +727,11 @@ var Accordion = class _Accordion {
728
727
  if (this.#isDestroyed) {
729
728
  return;
730
729
  }
731
- if (!(trigger instanceof HTMLElement) || !this.#bindings.has(trigger)) {
730
+ if (!(trigger instanceof HTMLElement)) {
732
731
  console.warn("Invalid trigger element");
733
732
  return;
734
733
  }
735
- this.#toggle(trigger, true);
734
+ this.#bindings.has(trigger) && this.#toggle(trigger, true);
736
735
  }
737
736
  #initialize() {
738
737
  saveAttributes(this.#triggerElements, [
@@ -794,10 +793,7 @@ var Accordion = class _Accordion {
794
793
  return;
795
794
  }
796
795
  const binding = this.#bindings.get(content);
797
- if (!binding) {
798
- return;
799
- }
800
- binding.trigger.ariaExpanded === "false" && this.#toggle(binding.trigger, true, true);
796
+ binding && binding.trigger.ariaExpanded === "false" && this.#toggle(binding.trigger, true, true);
801
797
  };
802
798
  #toggle(trigger, isOpen, isMatch = false) {
803
799
  if (trigger.ariaExpanded === String(isOpen)) {
@@ -862,10 +858,7 @@ var Accordion = class _Accordion {
862
858
  }
863
859
  #onAnimationFinish(content) {
864
860
  const trigger = this.#bindings.get(content)?.trigger;
865
- if (!trigger) {
866
- return;
867
- }
868
- if (trigger.ariaExpanded === "false") {
861
+ if (trigger && trigger.ariaExpanded === "false") {
869
862
  content.setAttribute("hidden", "until-found");
870
863
  }
871
864
  ["block-size", "overflow"].forEach((name) => {
@@ -890,16 +883,17 @@ function isFocusable2(element) {
890
883
  function waitAnimationFinish(animation) {
891
884
  if (["idle", "finished"].includes(animation.playState)) {
892
885
  return Promise.resolve();
886
+ } else {
887
+ return new Promise(
888
+ (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
889
+ );
893
890
  }
894
- return new Promise(
895
- (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
896
- );
897
891
  }
898
892
  /**
899
893
  * Accordion
900
894
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
901
895
  *
902
- * @version 1.4.9
896
+ * @version 1.4.11
903
897
  * @author Yusuke Kamiyamane
904
898
  * @license MIT
905
899
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -922,7 +916,7 @@ function waitAnimationFinish(animation) {
922
916
  (**
923
917
  * Button
924
918
  *
925
- * @version 1.0.0
919
+ * @version 1.0.2
926
920
  * @author Yusuke Kamiyamane
927
921
  * @license MIT
928
922
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -935,7 +929,7 @@ function waitAnimationFinish(animation) {
935
929
  * Lightweight roving tabindex utility with fully focus management.
936
930
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
937
931
  *
938
- * @version 3.0.2
932
+ * @version 3.0.5
939
933
  * @author Yusuke Kamiyamane
940
934
  * @license MIT
941
935
  * @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.9
5
+ * @version 1.4.11
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.9
5
+ * @version 1.4.11
6
6
  * @author Yusuke Kamiyamane
7
7
  * @license MIT
8
8
  * @copyright Copyright (c) Yusuke Kamiyamane
package/dist/index.js CHANGED
@@ -570,11 +570,11 @@ var RovingTabIndex = class {
570
570
  if (!typeahead) {
571
571
  continue;
572
572
  }
573
+ const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
573
574
  const value = focusable.ariaKeyShortcuts?.trim();
574
575
  const keys = new Set(
575
576
  value ? value.split(/\s+/).filter((key) => /^\S$/i.test(key)).map((key) => key.toUpperCase()) : []
576
577
  );
577
- const char = focusable.textContent?.trim()?.at(0)?.toUpperCase();
578
578
  if (char) {
579
579
  keys.add(char);
580
580
  saveAttributes2([focusable], ["aria-keyshortcuts"]);
@@ -678,12 +678,11 @@ var Accordion = class _Accordion {
678
678
  }
679
679
  this.#triggerElements.forEach((trigger2, i) => {
680
680
  const content2 = this.#contentElements[i];
681
- if (!content2) {
682
- return;
681
+ if (content2) {
682
+ const binding = createBinding(trigger2, content2);
683
+ this.#bindings.set(trigger2, binding);
684
+ this.#bindings.set(content2, binding);
683
685
  }
684
- const binding = createBinding(trigger2, content2);
685
- this.#bindings.set(trigger2, binding);
686
- this.#bindings.set(content2, binding);
687
686
  });
688
687
  this.#initialize();
689
688
  }
@@ -691,11 +690,11 @@ var Accordion = class _Accordion {
691
690
  if (this.#isDestroyed) {
692
691
  return;
693
692
  }
694
- if (!(trigger instanceof HTMLElement) || !this.#bindings.has(trigger)) {
693
+ if (!(trigger instanceof HTMLElement)) {
695
694
  console.warn("Invalid trigger element");
696
695
  return;
697
696
  }
698
- this.#toggle(trigger, false);
697
+ this.#bindings.has(trigger) && this.#toggle(trigger, false);
699
698
  }
700
699
  async destroy(force = false) {
701
700
  if (this.#isDestroyed) {
@@ -726,11 +725,11 @@ var Accordion = class _Accordion {
726
725
  if (this.#isDestroyed) {
727
726
  return;
728
727
  }
729
- if (!(trigger instanceof HTMLElement) || !this.#bindings.has(trigger)) {
728
+ if (!(trigger instanceof HTMLElement)) {
730
729
  console.warn("Invalid trigger element");
731
730
  return;
732
731
  }
733
- this.#toggle(trigger, true);
732
+ this.#bindings.has(trigger) && this.#toggle(trigger, true);
734
733
  }
735
734
  #initialize() {
736
735
  saveAttributes(this.#triggerElements, [
@@ -792,10 +791,7 @@ var Accordion = class _Accordion {
792
791
  return;
793
792
  }
794
793
  const binding = this.#bindings.get(content);
795
- if (!binding) {
796
- return;
797
- }
798
- binding.trigger.ariaExpanded === "false" && this.#toggle(binding.trigger, true, true);
794
+ binding && binding.trigger.ariaExpanded === "false" && this.#toggle(binding.trigger, true, true);
799
795
  };
800
796
  #toggle(trigger, isOpen, isMatch = false) {
801
797
  if (trigger.ariaExpanded === String(isOpen)) {
@@ -860,10 +856,7 @@ var Accordion = class _Accordion {
860
856
  }
861
857
  #onAnimationFinish(content) {
862
858
  const trigger = this.#bindings.get(content)?.trigger;
863
- if (!trigger) {
864
- return;
865
- }
866
- if (trigger.ariaExpanded === "false") {
859
+ if (trigger && trigger.ariaExpanded === "false") {
867
860
  content.setAttribute("hidden", "until-found");
868
861
  }
869
862
  ["block-size", "overflow"].forEach((name) => {
@@ -888,16 +881,17 @@ function isFocusable2(element) {
888
881
  function waitAnimationFinish(animation) {
889
882
  if (["idle", "finished"].includes(animation.playState)) {
890
883
  return Promise.resolve();
884
+ } else {
885
+ return new Promise(
886
+ (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
887
+ );
891
888
  }
892
- return new Promise(
893
- (resolve) => animation.addEventListener("finish", () => resolve(), { once: true })
894
- );
895
889
  }
896
890
  /**
897
891
  * Accordion
898
892
  * WAI-ARIA compliant accordion pattern implementation in TypeScript.
899
893
  *
900
- * @version 1.4.9
894
+ * @version 1.4.11
901
895
  * @author Yusuke Kamiyamane
902
896
  * @license MIT
903
897
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -920,7 +914,7 @@ function waitAnimationFinish(animation) {
920
914
  (**
921
915
  * Button
922
916
  *
923
- * @version 1.0.0
917
+ * @version 1.0.2
924
918
  * @author Yusuke Kamiyamane
925
919
  * @license MIT
926
920
  * @copyright Copyright (c) Yusuke Kamiyamane
@@ -933,7 +927,7 @@ function waitAnimationFinish(animation) {
933
927
  * Lightweight roving tabindex utility with fully focus management.
934
928
  * Designed for accessible menus, tabs, toolbars, and composite widgets.
935
929
  *
936
- * @version 3.0.2
930
+ * @version 3.0.5
937
931
  * @author Yusuke Kamiyamane
938
932
  * @license MIT
939
933
  * @copyright Copyright (c) Yusuke Kamiyamane
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@y14e/accordion",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
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.0",
48
- "@y14e/roving-tabindex": "^3.0.2",
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",