@y14e/accordion 1.3.3 → 1.4.0
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/dist/index.cjs +76 -26
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +76 -26
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -50,6 +50,62 @@ function saveAttributes(elements, attributes) {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
// node_modules/@y14e/button/dist/index.js
|
|
54
|
+
var Button = class {
|
|
55
|
+
#element;
|
|
56
|
+
#controller = null;
|
|
57
|
+
#isDestroyed = false;
|
|
58
|
+
constructor(element) {
|
|
59
|
+
if (!(element instanceof HTMLElement)) {
|
|
60
|
+
throw new TypeError("Invalid element");
|
|
61
|
+
}
|
|
62
|
+
if (element.hasAttribute("data-button-initialized")) {
|
|
63
|
+
console.warn("Already initialized");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.#element = element;
|
|
67
|
+
this.#initialize();
|
|
68
|
+
}
|
|
69
|
+
destroy() {
|
|
70
|
+
if (this.#isDestroyed) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.#isDestroyed = true;
|
|
74
|
+
this.#controller?.abort();
|
|
75
|
+
this.#controller = null;
|
|
76
|
+
this.#element.removeAttribute("data-button-initialized");
|
|
77
|
+
}
|
|
78
|
+
#initialize() {
|
|
79
|
+
this.#controller = new AbortController();
|
|
80
|
+
this.#element.addEventListener("keydown", this.#onKeyDown, {
|
|
81
|
+
signal: this.#controller.signal
|
|
82
|
+
});
|
|
83
|
+
this.#element.setAttribute("data-button-initialized", "");
|
|
84
|
+
}
|
|
85
|
+
#onKeyDown = (event) => {
|
|
86
|
+
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
87
|
+
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (!["Enter", " "].includes(key)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const active = getActiveElement();
|
|
94
|
+
if (!(active instanceof HTMLElement)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
active.click();
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
function getActiveElement() {
|
|
102
|
+
let current = document.activeElement;
|
|
103
|
+
while (current?.shadowRoot?.activeElement) {
|
|
104
|
+
current = current.shadowRoot.activeElement;
|
|
105
|
+
}
|
|
106
|
+
return current;
|
|
107
|
+
}
|
|
108
|
+
|
|
53
109
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
54
110
|
var defaultParser2 = (value) => value.split(/\s+/);
|
|
55
111
|
var defaultSerializer2 = (tokens) => tokens.join(" ");
|
|
@@ -416,7 +472,7 @@ var RovingTabIndex = class {
|
|
|
416
472
|
return;
|
|
417
473
|
}
|
|
418
474
|
}
|
|
419
|
-
const active =
|
|
475
|
+
const active = getActiveElement2();
|
|
420
476
|
if (!(active instanceof HTMLElement)) {
|
|
421
477
|
return;
|
|
422
478
|
}
|
|
@@ -542,7 +598,7 @@ var RovingTabIndex = class {
|
|
|
542
598
|
function focusElement(element) {
|
|
543
599
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
544
600
|
}
|
|
545
|
-
function
|
|
601
|
+
function getActiveElement2() {
|
|
546
602
|
let current = document.activeElement;
|
|
547
603
|
while (current?.shadowRoot?.activeElement) {
|
|
548
604
|
current = current.shadowRoot.activeElement;
|
|
@@ -568,6 +624,7 @@ var Accordion = class _Accordion {
|
|
|
568
624
|
#eventController = null;
|
|
569
625
|
#animationController = null;
|
|
570
626
|
#cleanupRovingTabIndex = null;
|
|
627
|
+
#buttons = [];
|
|
571
628
|
#isDestroyed = false;
|
|
572
629
|
constructor(root, options = {}) {
|
|
573
630
|
if (!(root instanceof HTMLElement)) {
|
|
@@ -641,6 +698,10 @@ var Accordion = class _Accordion {
|
|
|
641
698
|
this.#eventController = null;
|
|
642
699
|
this.#cleanupRovingTabIndex?.();
|
|
643
700
|
this.#cleanupRovingTabIndex = null;
|
|
701
|
+
this.#buttons.forEach((button) => {
|
|
702
|
+
button.destroy();
|
|
703
|
+
});
|
|
704
|
+
this.#buttons.length = 0;
|
|
644
705
|
!force && await this.#waitAnimationsFinish();
|
|
645
706
|
this.#contentElements.forEach((content) => {
|
|
646
707
|
force && this.#bindings.get(content)?.animation?.finish();
|
|
@@ -683,12 +744,12 @@ var Accordion = class _Accordion {
|
|
|
683
744
|
trigger2.style.setProperty("pointer-events", "none");
|
|
684
745
|
}
|
|
685
746
|
trigger2.addEventListener("click", this.#onTriggerClick, { signal });
|
|
686
|
-
trigger2.addEventListener("keydown", this.#onTriggerKeyDown, { signal });
|
|
687
747
|
addTokenToAttribute(content2, "aria-labelledby", trigger2.id);
|
|
688
748
|
content2.setAttribute("role", "region");
|
|
689
749
|
content2.addEventListener("beforematch", this.#onContentBeforeMatch, {
|
|
690
750
|
signal
|
|
691
751
|
});
|
|
752
|
+
this.#buttons.push(new Button(trigger2));
|
|
692
753
|
});
|
|
693
754
|
const { trigger, content } = this.#settings.selector;
|
|
694
755
|
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#rootElement, {
|
|
@@ -707,21 +768,6 @@ var Accordion = class _Accordion {
|
|
|
707
768
|
}
|
|
708
769
|
this.#toggle(trigger, trigger.ariaExpanded === "false");
|
|
709
770
|
};
|
|
710
|
-
#onTriggerKeyDown = (event) => {
|
|
711
|
-
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
712
|
-
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
if (!["Enter", " "].includes(key)) {
|
|
716
|
-
return;
|
|
717
|
-
}
|
|
718
|
-
const active = getActiveElement2();
|
|
719
|
-
if (!(active instanceof HTMLElement)) {
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
event.preventDefault();
|
|
723
|
-
active.click();
|
|
724
|
-
};
|
|
725
771
|
#onContentBeforeMatch = (event) => {
|
|
726
772
|
const content = event.currentTarget;
|
|
727
773
|
if (!(content instanceof HTMLElement)) {
|
|
@@ -818,13 +864,6 @@ var Accordion = class _Accordion {
|
|
|
818
864
|
function createBinding(trigger, content) {
|
|
819
865
|
return { trigger, content, animation: null };
|
|
820
866
|
}
|
|
821
|
-
function getActiveElement2() {
|
|
822
|
-
let current = document.activeElement;
|
|
823
|
-
while (current?.shadowRoot?.activeElement) {
|
|
824
|
-
current = current.shadowRoot.activeElement;
|
|
825
|
-
}
|
|
826
|
-
return current;
|
|
827
|
-
}
|
|
828
867
|
function isFocusable2(element) {
|
|
829
868
|
return !element.hasAttribute("disabled") && element.tabIndex >= 0;
|
|
830
869
|
}
|
|
@@ -841,7 +880,7 @@ function waitAnimationFinish(animation) {
|
|
|
841
880
|
* Accordion
|
|
842
881
|
* WAI-ARIA compliant accordion pattern implementation in TypeScript.
|
|
843
882
|
*
|
|
844
|
-
* @version 1.
|
|
883
|
+
* @version 1.4.0
|
|
845
884
|
* @author Yusuke Kamiyamane
|
|
846
885
|
* @license MIT
|
|
847
886
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -860,6 +899,17 @@ function waitAnimationFinish(animation) {
|
|
|
860
899
|
* @see {@link https://github.com/y14e/attributes-utils}
|
|
861
900
|
*)
|
|
862
901
|
|
|
902
|
+
@y14e/button/dist/index.js:
|
|
903
|
+
(**
|
|
904
|
+
* Button
|
|
905
|
+
*
|
|
906
|
+
* @version 1.0.0
|
|
907
|
+
* @author Yusuke Kamiyamane
|
|
908
|
+
* @license MIT
|
|
909
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
910
|
+
* @see {@link https://github.com/y14e/button}
|
|
911
|
+
*)
|
|
912
|
+
|
|
863
913
|
@y14e/roving-tabindex/dist/index.js:
|
|
864
914
|
(**
|
|
865
915
|
* Roving Tabindex
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -48,6 +48,62 @@ function saveAttributes(elements, attributes) {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
// node_modules/@y14e/button/dist/index.js
|
|
52
|
+
var Button = class {
|
|
53
|
+
#element;
|
|
54
|
+
#controller = null;
|
|
55
|
+
#isDestroyed = false;
|
|
56
|
+
constructor(element) {
|
|
57
|
+
if (!(element instanceof HTMLElement)) {
|
|
58
|
+
throw new TypeError("Invalid element");
|
|
59
|
+
}
|
|
60
|
+
if (element.hasAttribute("data-button-initialized")) {
|
|
61
|
+
console.warn("Already initialized");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.#element = element;
|
|
65
|
+
this.#initialize();
|
|
66
|
+
}
|
|
67
|
+
destroy() {
|
|
68
|
+
if (this.#isDestroyed) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.#isDestroyed = true;
|
|
72
|
+
this.#controller?.abort();
|
|
73
|
+
this.#controller = null;
|
|
74
|
+
this.#element.removeAttribute("data-button-initialized");
|
|
75
|
+
}
|
|
76
|
+
#initialize() {
|
|
77
|
+
this.#controller = new AbortController();
|
|
78
|
+
this.#element.addEventListener("keydown", this.#onKeyDown, {
|
|
79
|
+
signal: this.#controller.signal
|
|
80
|
+
});
|
|
81
|
+
this.#element.setAttribute("data-button-initialized", "");
|
|
82
|
+
}
|
|
83
|
+
#onKeyDown = (event) => {
|
|
84
|
+
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
85
|
+
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!["Enter", " "].includes(key)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const active = getActiveElement();
|
|
92
|
+
if (!(active instanceof HTMLElement)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
active.click();
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
function getActiveElement() {
|
|
100
|
+
let current = document.activeElement;
|
|
101
|
+
while (current?.shadowRoot?.activeElement) {
|
|
102
|
+
current = current.shadowRoot.activeElement;
|
|
103
|
+
}
|
|
104
|
+
return current;
|
|
105
|
+
}
|
|
106
|
+
|
|
51
107
|
// node_modules/@y14e/roving-tabindex/dist/index.js
|
|
52
108
|
var defaultParser2 = (value) => value.split(/\s+/);
|
|
53
109
|
var defaultSerializer2 = (tokens) => tokens.join(" ");
|
|
@@ -414,7 +470,7 @@ var RovingTabIndex = class {
|
|
|
414
470
|
return;
|
|
415
471
|
}
|
|
416
472
|
}
|
|
417
|
-
const active =
|
|
473
|
+
const active = getActiveElement2();
|
|
418
474
|
if (!(active instanceof HTMLElement)) {
|
|
419
475
|
return;
|
|
420
476
|
}
|
|
@@ -540,7 +596,7 @@ var RovingTabIndex = class {
|
|
|
540
596
|
function focusElement(element) {
|
|
541
597
|
"focus" in element && typeof element.focus === "function" && element.focus();
|
|
542
598
|
}
|
|
543
|
-
function
|
|
599
|
+
function getActiveElement2() {
|
|
544
600
|
let current = document.activeElement;
|
|
545
601
|
while (current?.shadowRoot?.activeElement) {
|
|
546
602
|
current = current.shadowRoot.activeElement;
|
|
@@ -566,6 +622,7 @@ var Accordion = class _Accordion {
|
|
|
566
622
|
#eventController = null;
|
|
567
623
|
#animationController = null;
|
|
568
624
|
#cleanupRovingTabIndex = null;
|
|
625
|
+
#buttons = [];
|
|
569
626
|
#isDestroyed = false;
|
|
570
627
|
constructor(root, options = {}) {
|
|
571
628
|
if (!(root instanceof HTMLElement)) {
|
|
@@ -639,6 +696,10 @@ var Accordion = class _Accordion {
|
|
|
639
696
|
this.#eventController = null;
|
|
640
697
|
this.#cleanupRovingTabIndex?.();
|
|
641
698
|
this.#cleanupRovingTabIndex = null;
|
|
699
|
+
this.#buttons.forEach((button) => {
|
|
700
|
+
button.destroy();
|
|
701
|
+
});
|
|
702
|
+
this.#buttons.length = 0;
|
|
642
703
|
!force && await this.#waitAnimationsFinish();
|
|
643
704
|
this.#contentElements.forEach((content) => {
|
|
644
705
|
force && this.#bindings.get(content)?.animation?.finish();
|
|
@@ -681,12 +742,12 @@ var Accordion = class _Accordion {
|
|
|
681
742
|
trigger2.style.setProperty("pointer-events", "none");
|
|
682
743
|
}
|
|
683
744
|
trigger2.addEventListener("click", this.#onTriggerClick, { signal });
|
|
684
|
-
trigger2.addEventListener("keydown", this.#onTriggerKeyDown, { signal });
|
|
685
745
|
addTokenToAttribute(content2, "aria-labelledby", trigger2.id);
|
|
686
746
|
content2.setAttribute("role", "region");
|
|
687
747
|
content2.addEventListener("beforematch", this.#onContentBeforeMatch, {
|
|
688
748
|
signal
|
|
689
749
|
});
|
|
750
|
+
this.#buttons.push(new Button(trigger2));
|
|
690
751
|
});
|
|
691
752
|
const { trigger, content } = this.#settings.selector;
|
|
692
753
|
this.#cleanupRovingTabIndex = createRovingTabIndex(this.#rootElement, {
|
|
@@ -705,21 +766,6 @@ var Accordion = class _Accordion {
|
|
|
705
766
|
}
|
|
706
767
|
this.#toggle(trigger, trigger.ariaExpanded === "false");
|
|
707
768
|
};
|
|
708
|
-
#onTriggerKeyDown = (event) => {
|
|
709
|
-
const { key, altKey, ctrlKey, metaKey, shiftKey } = event;
|
|
710
|
-
if (altKey || ctrlKey || metaKey || shiftKey) {
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
if (!["Enter", " "].includes(key)) {
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
716
|
-
const active = getActiveElement2();
|
|
717
|
-
if (!(active instanceof HTMLElement)) {
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
event.preventDefault();
|
|
721
|
-
active.click();
|
|
722
|
-
};
|
|
723
769
|
#onContentBeforeMatch = (event) => {
|
|
724
770
|
const content = event.currentTarget;
|
|
725
771
|
if (!(content instanceof HTMLElement)) {
|
|
@@ -816,13 +862,6 @@ var Accordion = class _Accordion {
|
|
|
816
862
|
function createBinding(trigger, content) {
|
|
817
863
|
return { trigger, content, animation: null };
|
|
818
864
|
}
|
|
819
|
-
function getActiveElement2() {
|
|
820
|
-
let current = document.activeElement;
|
|
821
|
-
while (current?.shadowRoot?.activeElement) {
|
|
822
|
-
current = current.shadowRoot.activeElement;
|
|
823
|
-
}
|
|
824
|
-
return current;
|
|
825
|
-
}
|
|
826
865
|
function isFocusable2(element) {
|
|
827
866
|
return !element.hasAttribute("disabled") && element.tabIndex >= 0;
|
|
828
867
|
}
|
|
@@ -839,7 +878,7 @@ function waitAnimationFinish(animation) {
|
|
|
839
878
|
* Accordion
|
|
840
879
|
* WAI-ARIA compliant accordion pattern implementation in TypeScript.
|
|
841
880
|
*
|
|
842
|
-
* @version 1.
|
|
881
|
+
* @version 1.4.0
|
|
843
882
|
* @author Yusuke Kamiyamane
|
|
844
883
|
* @license MIT
|
|
845
884
|
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
@@ -858,6 +897,17 @@ function waitAnimationFinish(animation) {
|
|
|
858
897
|
* @see {@link https://github.com/y14e/attributes-utils}
|
|
859
898
|
*)
|
|
860
899
|
|
|
900
|
+
@y14e/button/dist/index.js:
|
|
901
|
+
(**
|
|
902
|
+
* Button
|
|
903
|
+
*
|
|
904
|
+
* @version 1.0.0
|
|
905
|
+
* @author Yusuke Kamiyamane
|
|
906
|
+
* @license MIT
|
|
907
|
+
* @copyright Copyright (c) Yusuke Kamiyamane
|
|
908
|
+
* @see {@link https://github.com/y14e/button}
|
|
909
|
+
*)
|
|
910
|
+
|
|
861
911
|
@y14e/roving-tabindex/dist/index.js:
|
|
862
912
|
(**
|
|
863
913
|
* Roving Tabindex
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@y14e/accordion",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "WAI-ARIA compliant accordion pattern implementation in TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"homepage": "https://github.com/y14e/accordion#readme",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@y14e/attributes-utils": "^1.0.5",
|
|
47
|
+
"@y14e/button": "^1.0.0",
|
|
47
48
|
"@y14e/roving-tabindex": "^1.3.1",
|
|
48
49
|
"bun-types": "latest",
|
|
49
50
|
"tsup": "^8.0.0",
|