aria-ease 6.14.0 → 7.0.1

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.
Files changed (94) hide show
  1. package/README.md +1 -1
  2. package/dist/AccordionComponentStrategy-2SWMNUR6.js +1 -0
  3. package/dist/ComboboxComponentStrategy-YSYLR2U5.js +5 -0
  4. package/dist/MenuComponentStrategy-C22BZEBH.js +5 -0
  5. package/dist/RelativeTargetResolver-T4P25J2M.js +1 -0
  6. package/dist/TabsComponentStrategy-ADEEFJXM.js +1 -0
  7. package/dist/audit-WBKVW7H6.js +9 -0
  8. package/dist/badgeHelper-IB5RTMAG.js +11 -0
  9. package/dist/badgeHelper-JSROP5ML.js +1 -0
  10. package/dist/buildContracts-T4XQZBDU.js +13 -0
  11. package/dist/chunk-52I3INNG.js +11 -0
  12. package/dist/chunk-APUMBDOT.js +1 -0
  13. package/dist/chunk-BHNO4ZI3.js +1 -0
  14. package/dist/chunk-CNU4N4AY.js +1 -0
  15. package/dist/chunk-SM6ZKEDR.js +1 -0
  16. package/dist/chunk-ZNQ5BXVJ.js +1 -0
  17. package/dist/cli.cjs +132 -3560
  18. package/dist/cli.js +19 -161
  19. package/dist/configLoader-ZEJVXLX7.js +1 -0
  20. package/dist/configLoader-ZXTSCIP6.js +1 -0
  21. package/dist/contractTestRunnerPlaywright-FOCQTM4L.js +46 -0
  22. package/dist/contractTestRunnerPlaywright-QPU6HZXG.js +46 -0
  23. package/dist/formatters-H3CPDLG5.js +87 -0
  24. package/dist/index.cjs +64 -5103
  25. package/dist/index.d.cts +4 -6
  26. package/dist/index.d.ts +4 -6
  27. package/dist/index.js +17 -2703
  28. package/dist/src/accordion/index.cjs +1 -183
  29. package/dist/src/accordion/index.js +1 -181
  30. package/dist/src/block/index.cjs +1 -124
  31. package/dist/src/block/index.js +1 -122
  32. package/dist/src/checkbox/index.cjs +1 -109
  33. package/dist/src/checkbox/index.js +1 -107
  34. package/dist/src/combobox/index.cjs +1 -265
  35. package/dist/src/combobox/index.js +1 -263
  36. package/dist/src/menu/index.cjs +1 -339
  37. package/dist/src/menu/index.js +1 -337
  38. package/dist/src/radio/index.cjs +1 -117
  39. package/dist/src/radio/index.js +1 -115
  40. package/dist/src/tabs/index.cjs +1 -265
  41. package/dist/src/tabs/index.js +1 -263
  42. package/dist/src/toggle/index.cjs +1 -119
  43. package/dist/src/toggle/index.js +1 -117
  44. package/dist/src/utils/test/AccordionComponentStrategy-X2GSQ5KT.js +1 -0
  45. package/dist/src/utils/test/ComboboxComponentStrategy-SICWLI27.js +5 -0
  46. package/dist/src/utils/test/MenuComponentStrategy-R4VPAHDE.js +5 -0
  47. package/dist/src/utils/test/RelativeTargetResolver-UQQMZHI6.js +1 -0
  48. package/dist/src/utils/test/TabsComponentStrategy-L2PYNEW6.js +1 -0
  49. package/dist/src/utils/test/badgeHelper-ER5ZOHWF.js +11 -0
  50. package/dist/src/utils/test/chunk-APUMBDOT.js +1 -0
  51. package/dist/src/utils/test/chunk-BHNO4ZI3.js +1 -0
  52. package/dist/src/utils/test/configLoader-NCYRL2O6.js +1 -0
  53. package/dist/src/utils/test/contractTestRunnerPlaywright-YZCMF64Q.js +46 -0
  54. package/dist/src/utils/test/dsl/index.cjs +1 -838
  55. package/dist/src/utils/test/dsl/index.d.cts +2 -4
  56. package/dist/src/utils/test/dsl/index.d.ts +2 -4
  57. package/dist/src/utils/test/dsl/index.js +1 -836
  58. package/dist/src/utils/test/index.cjs +64 -2672
  59. package/dist/src/utils/test/index.d.cts +2 -2
  60. package/dist/src/utils/test/index.d.ts +2 -2
  61. package/dist/src/utils/test/index.js +16 -340
  62. package/dist/test-VXSCSKV5.js +19 -0
  63. package/package.json +8 -10
  64. package/dist/AccordionComponentStrategy-4ZEIQ2V6.js +0 -42
  65. package/dist/ComboboxComponentStrategy-DU342VMB.js +0 -64
  66. package/dist/MenuComponentStrategy-VYCC2XOM.js +0 -81
  67. package/dist/RelativeTargetResolver-DJAITO6D.js +0 -7
  68. package/dist/TabsComponentStrategy-3SQURPMX.js +0 -29
  69. package/dist/audit-JYEPKLHR.js +0 -63
  70. package/dist/badgeHelper-JOWO6RQG.js +0 -15
  71. package/dist/badgeHelper-RDOMCC6E.js +0 -108
  72. package/dist/buildContracts-VIV6GM56.js +0 -437
  73. package/dist/chunk-4DU5Z5BR.js +0 -340
  74. package/dist/chunk-GJGUY643.js +0 -182
  75. package/dist/chunk-GLT43UVH.js +0 -43
  76. package/dist/chunk-I2KLQ2HA.js +0 -22
  77. package/dist/chunk-JJEPLK7L.js +0 -107
  78. package/dist/chunk-PK5L2SAF.js +0 -17
  79. package/dist/configLoader-Q7N5XV4P.js +0 -183
  80. package/dist/configLoader-REHK3S3Q.js +0 -7
  81. package/dist/contractTestRunnerPlaywright-B2HLZKKK.js +0 -1394
  82. package/dist/contractTestRunnerPlaywright-RWK52C7S.js +0 -1394
  83. package/dist/formatters-32KQIIYS.js +0 -183
  84. package/dist/src/utils/test/AccordionComponentStrategy-WRHZOEN6.js +0 -38
  85. package/dist/src/utils/test/ComboboxComponentStrategy-XKQ72RFD.js +0 -60
  86. package/dist/src/utils/test/MenuComponentStrategy-6XWU5KLW.js +0 -77
  87. package/dist/src/utils/test/RelativeTargetResolver-G2XDN2VV.js +0 -1
  88. package/dist/src/utils/test/TabsComponentStrategy-BKG53SEV.js +0 -26
  89. package/dist/src/utils/test/badgeHelper-HZKGOPB4.js +0 -102
  90. package/dist/src/utils/test/chunk-4DU5Z5BR.js +0 -332
  91. package/dist/src/utils/test/chunk-GLT43UVH.js +0 -41
  92. package/dist/src/utils/test/configLoader-NA7IBCS3.js +0 -181
  93. package/dist/src/utils/test/contractTestRunnerPlaywright-5FIGA5G4.js +0 -1372
  94. package/dist/test-WDBS5JWO.js +0 -358
@@ -1,109 +1 @@
1
- 'use strict';
2
-
3
- // src/checkbox/src/makeCheckboxAccessible/makeCheckboxAccessible.ts
4
- function makeCheckboxAccessible({ checkboxGroupId, checkboxesClass }) {
5
- const checkboxGroup = document.querySelector(`#${checkboxGroupId}`);
6
- if (!checkboxGroup) {
7
- console.error(`[aria-ease] Element with id="${checkboxGroupId}" not found. Make sure the checkbox group container exists before calling makeCheckboxAccessible.`);
8
- return { cleanup: () => {
9
- } };
10
- }
11
- const checkboxes = Array.from(checkboxGroup.querySelectorAll(`.${checkboxesClass}`));
12
- if (checkboxes.length === 0) {
13
- console.error(`[aria-ease] No elements with class="${checkboxesClass}" found. Make sure checkboxes exist before calling makeCheckboxAccessible.`);
14
- return { cleanup: () => {
15
- } };
16
- }
17
- const handlerMap = /* @__PURE__ */ new WeakMap();
18
- const clickHandlerMap = /* @__PURE__ */ new WeakMap();
19
- function initialize() {
20
- if (!checkboxGroup.getAttribute("role")) {
21
- checkboxGroup.setAttribute("role", "group");
22
- }
23
- checkboxes.forEach((checkbox) => {
24
- checkbox.setAttribute("role", "checkbox");
25
- if (!checkbox.hasAttribute("aria-checked")) {
26
- checkbox.setAttribute("aria-checked", "false");
27
- }
28
- if (!checkbox.hasAttribute("tabindex")) {
29
- checkbox.setAttribute("tabindex", "0");
30
- }
31
- });
32
- }
33
- function toggleCheckbox(index) {
34
- if (index < 0 || index >= checkboxes.length) {
35
- console.error(`[aria-ease] Invalid checkbox index: ${index}`);
36
- return;
37
- }
38
- const checkbox = checkboxes[index];
39
- const isChecked = checkbox.getAttribute("aria-checked") === "true";
40
- checkbox.setAttribute("aria-checked", isChecked ? "false" : "true");
41
- }
42
- function setCheckboxState(index, checked) {
43
- if (index < 0 || index >= checkboxes.length) {
44
- console.error(`[aria-ease] Invalid checkbox index: ${index}`);
45
- return;
46
- }
47
- checkboxes[index].setAttribute("aria-checked", checked ? "true" : "false");
48
- }
49
- function handleCheckboxClick(index) {
50
- return () => {
51
- toggleCheckbox(index);
52
- };
53
- }
54
- function handleCheckboxKeydown(index) {
55
- return (event) => {
56
- const { key } = event;
57
- switch (key) {
58
- case " ":
59
- event.preventDefault();
60
- toggleCheckbox(index);
61
- break;
62
- }
63
- };
64
- }
65
- function addListeners() {
66
- checkboxes.forEach((checkbox, index) => {
67
- const clickHandler = handleCheckboxClick(index);
68
- const keydownHandler = handleCheckboxKeydown(index);
69
- checkbox.addEventListener("click", clickHandler);
70
- checkbox.addEventListener("keydown", keydownHandler);
71
- handlerMap.set(checkbox, keydownHandler);
72
- clickHandlerMap.set(checkbox, clickHandler);
73
- });
74
- }
75
- function removeListeners() {
76
- checkboxes.forEach((checkbox) => {
77
- const keydownHandler = handlerMap.get(checkbox);
78
- const clickHandler = clickHandlerMap.get(checkbox);
79
- if (keydownHandler) {
80
- checkbox.removeEventListener("keydown", keydownHandler);
81
- handlerMap.delete(checkbox);
82
- }
83
- if (clickHandler) {
84
- checkbox.removeEventListener("click", clickHandler);
85
- clickHandlerMap.delete(checkbox);
86
- }
87
- });
88
- }
89
- function cleanup() {
90
- removeListeners();
91
- }
92
- function getCheckedStates() {
93
- return checkboxes.map((checkbox) => checkbox.getAttribute("aria-checked") === "true");
94
- }
95
- function getCheckedIndices() {
96
- return checkboxes.map((checkbox, index) => checkbox.getAttribute("aria-checked") === "true" ? index : -1).filter((index) => index !== -1);
97
- }
98
- initialize();
99
- addListeners();
100
- return {
101
- toggleCheckbox,
102
- setCheckboxState,
103
- getCheckedStates,
104
- getCheckedIndices,
105
- cleanup
106
- };
107
- }
108
-
109
- exports.makeCheckboxAccessible = makeCheckboxAccessible;
1
+ 'use strict';function C({checkboxGroupId:o,checkboxesClass:i}){if(o==="")return console.error("[aria-ease] 'checkboxGroupId' should not be an empty string. Provide an id to the checkbox group container element that exists before calling makeCheckboxAccessible."),{cleanup:()=>{}};let a=document.querySelector(`#${o}`);if(!a)return console.error(`[aria-ease] Element with id="${o}" not found. Make sure the checkbox group container exists before calling makeCheckboxAccessible.`),{cleanup:()=>{}};if(i==="")return console.error("[aria-ease] 'checkboxesClass' should not be an empty string. Provide a class name that exists on the checkbox elements before calling makeCheckboxAccessible."),{cleanup:()=>{}};let n=Array.from(a.querySelectorAll(`.${i}`));if(n.length===0)return console.error(`[aria-ease] No elements with class="${i}" found. Make sure checkboxes exist before calling makeCheckboxAccessible.`),{cleanup:()=>{}};let c=new WeakMap,s=new WeakMap;function b(){a.getAttribute("role")||a.setAttribute("role","group"),n.forEach(e=>{e.setAttribute("role","checkbox"),e.hasAttribute("aria-checked")||e.setAttribute("aria-checked","false"),e.hasAttribute("tabindex")||e.setAttribute("tabindex","0");});}function l(e){if(e<0||e>=n.length){console.error(`[aria-ease] Invalid checkbox index: ${e}`);return}let t=n[e],r=t.getAttribute("aria-checked")==="true";t.setAttribute("aria-checked",r?"false":"true");}function d(e,t){if(e<0||e>=n.length){console.error(`[aria-ease] Invalid checkbox index: ${e}`);return}n[e].setAttribute("aria-checked",t?"true":"false");}function f(e){return ()=>{l(e);}}function h(e){return t=>{let{key:r}=t;switch(r){case " ":t.preventDefault(),l(e);break}}}function k(){n.forEach((e,t)=>{let r=f(t),u=h(t);e.addEventListener("click",r),e.addEventListener("keydown",u),c.set(e,u),s.set(e,r);});}function m(){n.forEach(e=>{let t=c.get(e),r=s.get(e);t&&(e.removeEventListener("keydown",t),c.delete(e)),r&&(e.removeEventListener("click",r),s.delete(e));});}function g(){m();}function p(){return n.map(e=>e.getAttribute("aria-checked")==="true")}function A(){return n.map((e,t)=>e.getAttribute("aria-checked")==="true"?t:-1).filter(e=>e!==-1)}return b(),k(),{toggleCheckbox:l,setCheckboxState:d,getCheckedStates:p,getCheckedIndices:A,cleanup:g}}exports.makeCheckboxAccessible=C;
@@ -1,107 +1 @@
1
- // src/checkbox/src/makeCheckboxAccessible/makeCheckboxAccessible.ts
2
- function makeCheckboxAccessible({ checkboxGroupId, checkboxesClass }) {
3
- const checkboxGroup = document.querySelector(`#${checkboxGroupId}`);
4
- if (!checkboxGroup) {
5
- console.error(`[aria-ease] Element with id="${checkboxGroupId}" not found. Make sure the checkbox group container exists before calling makeCheckboxAccessible.`);
6
- return { cleanup: () => {
7
- } };
8
- }
9
- const checkboxes = Array.from(checkboxGroup.querySelectorAll(`.${checkboxesClass}`));
10
- if (checkboxes.length === 0) {
11
- console.error(`[aria-ease] No elements with class="${checkboxesClass}" found. Make sure checkboxes exist before calling makeCheckboxAccessible.`);
12
- return { cleanup: () => {
13
- } };
14
- }
15
- const handlerMap = /* @__PURE__ */ new WeakMap();
16
- const clickHandlerMap = /* @__PURE__ */ new WeakMap();
17
- function initialize() {
18
- if (!checkboxGroup.getAttribute("role")) {
19
- checkboxGroup.setAttribute("role", "group");
20
- }
21
- checkboxes.forEach((checkbox) => {
22
- checkbox.setAttribute("role", "checkbox");
23
- if (!checkbox.hasAttribute("aria-checked")) {
24
- checkbox.setAttribute("aria-checked", "false");
25
- }
26
- if (!checkbox.hasAttribute("tabindex")) {
27
- checkbox.setAttribute("tabindex", "0");
28
- }
29
- });
30
- }
31
- function toggleCheckbox(index) {
32
- if (index < 0 || index >= checkboxes.length) {
33
- console.error(`[aria-ease] Invalid checkbox index: ${index}`);
34
- return;
35
- }
36
- const checkbox = checkboxes[index];
37
- const isChecked = checkbox.getAttribute("aria-checked") === "true";
38
- checkbox.setAttribute("aria-checked", isChecked ? "false" : "true");
39
- }
40
- function setCheckboxState(index, checked) {
41
- if (index < 0 || index >= checkboxes.length) {
42
- console.error(`[aria-ease] Invalid checkbox index: ${index}`);
43
- return;
44
- }
45
- checkboxes[index].setAttribute("aria-checked", checked ? "true" : "false");
46
- }
47
- function handleCheckboxClick(index) {
48
- return () => {
49
- toggleCheckbox(index);
50
- };
51
- }
52
- function handleCheckboxKeydown(index) {
53
- return (event) => {
54
- const { key } = event;
55
- switch (key) {
56
- case " ":
57
- event.preventDefault();
58
- toggleCheckbox(index);
59
- break;
60
- }
61
- };
62
- }
63
- function addListeners() {
64
- checkboxes.forEach((checkbox, index) => {
65
- const clickHandler = handleCheckboxClick(index);
66
- const keydownHandler = handleCheckboxKeydown(index);
67
- checkbox.addEventListener("click", clickHandler);
68
- checkbox.addEventListener("keydown", keydownHandler);
69
- handlerMap.set(checkbox, keydownHandler);
70
- clickHandlerMap.set(checkbox, clickHandler);
71
- });
72
- }
73
- function removeListeners() {
74
- checkboxes.forEach((checkbox) => {
75
- const keydownHandler = handlerMap.get(checkbox);
76
- const clickHandler = clickHandlerMap.get(checkbox);
77
- if (keydownHandler) {
78
- checkbox.removeEventListener("keydown", keydownHandler);
79
- handlerMap.delete(checkbox);
80
- }
81
- if (clickHandler) {
82
- checkbox.removeEventListener("click", clickHandler);
83
- clickHandlerMap.delete(checkbox);
84
- }
85
- });
86
- }
87
- function cleanup() {
88
- removeListeners();
89
- }
90
- function getCheckedStates() {
91
- return checkboxes.map((checkbox) => checkbox.getAttribute("aria-checked") === "true");
92
- }
93
- function getCheckedIndices() {
94
- return checkboxes.map((checkbox, index) => checkbox.getAttribute("aria-checked") === "true" ? index : -1).filter((index) => index !== -1);
95
- }
96
- initialize();
97
- addListeners();
98
- return {
99
- toggleCheckbox,
100
- setCheckboxState,
101
- getCheckedStates,
102
- getCheckedIndices,
103
- cleanup
104
- };
105
- }
106
-
107
- export { makeCheckboxAccessible };
1
+ function C({checkboxGroupId:o,checkboxesClass:i}){if(o==="")return console.error("[aria-ease] 'checkboxGroupId' should not be an empty string. Provide an id to the checkbox group container element that exists before calling makeCheckboxAccessible."),{cleanup:()=>{}};let a=document.querySelector(`#${o}`);if(!a)return console.error(`[aria-ease] Element with id="${o}" not found. Make sure the checkbox group container exists before calling makeCheckboxAccessible.`),{cleanup:()=>{}};if(i==="")return console.error("[aria-ease] 'checkboxesClass' should not be an empty string. Provide a class name that exists on the checkbox elements before calling makeCheckboxAccessible."),{cleanup:()=>{}};let n=Array.from(a.querySelectorAll(`.${i}`));if(n.length===0)return console.error(`[aria-ease] No elements with class="${i}" found. Make sure checkboxes exist before calling makeCheckboxAccessible.`),{cleanup:()=>{}};let c=new WeakMap,s=new WeakMap;function b(){a.getAttribute("role")||a.setAttribute("role","group"),n.forEach(e=>{e.setAttribute("role","checkbox"),e.hasAttribute("aria-checked")||e.setAttribute("aria-checked","false"),e.hasAttribute("tabindex")||e.setAttribute("tabindex","0");});}function l(e){if(e<0||e>=n.length){console.error(`[aria-ease] Invalid checkbox index: ${e}`);return}let t=n[e],r=t.getAttribute("aria-checked")==="true";t.setAttribute("aria-checked",r?"false":"true");}function d(e,t){if(e<0||e>=n.length){console.error(`[aria-ease] Invalid checkbox index: ${e}`);return}n[e].setAttribute("aria-checked",t?"true":"false");}function f(e){return ()=>{l(e);}}function h(e){return t=>{let{key:r}=t;switch(r){case " ":t.preventDefault(),l(e);break}}}function k(){n.forEach((e,t)=>{let r=f(t),u=h(t);e.addEventListener("click",r),e.addEventListener("keydown",u),c.set(e,u),s.set(e,r);});}function m(){n.forEach(e=>{let t=c.get(e),r=s.get(e);t&&(e.removeEventListener("keydown",t),c.delete(e)),r&&(e.removeEventListener("click",r),s.delete(e));});}function g(){m();}function p(){return n.map(e=>e.getAttribute("aria-checked")==="true")}function A(){return n.map((e,t)=>e.getAttribute("aria-checked")==="true"?t:-1).filter(e=>e!==-1)}return b(),k(),{toggleCheckbox:l,setCheckboxState:d,getCheckedStates:p,getCheckedIndices:A,cleanup:g}}export{C as makeCheckboxAccessible};
@@ -1,265 +1 @@
1
- 'use strict';
2
-
3
- // src/combobox/src/makeComboBoxAccessible/makeComboBoxAccessible.ts
4
- function makeComboboxAccessible({ comboboxInputId, comboboxButtonId, listBoxId, listBoxItemsClass, callback }) {
5
- const comboboxInput = document.getElementById(`${comboboxInputId}`);
6
- if (!comboboxInput) {
7
- console.error(`[aria-ease] Element with id="${comboboxInputId}" not found. Make sure the combobox input element exists before calling makeComboboxAccessible.`);
8
- return { cleanup: () => {
9
- } };
10
- }
11
- const listBox = document.getElementById(`${listBoxId}`);
12
- if (!listBox) {
13
- console.error(`[aria-ease] Element with id="${listBoxId}" not found. Make sure the combobox listbox element exists before calling makeComboboxAccessible.`);
14
- return { cleanup: () => {
15
- } };
16
- }
17
- const listButton = comboboxButtonId ? document.getElementById(`${comboboxButtonId}`) : null;
18
- let activeIndex = -1;
19
- comboboxInput.setAttribute("role", "combobox");
20
- comboboxInput.setAttribute("aria-autocomplete", "list");
21
- comboboxInput.setAttribute("aria-controls", listBoxId);
22
- comboboxInput.setAttribute("aria-expanded", "false");
23
- comboboxInput.setAttribute("aria-haspopup", "listbox");
24
- listBox.setAttribute("role", "listbox");
25
- let cachedItems = null;
26
- function getVisibleItems() {
27
- if (!cachedItems) {
28
- cachedItems = listBox.querySelectorAll(`.${listBoxItemsClass}`);
29
- }
30
- return Array.from(cachedItems).filter((item) => !item.hidden && item.style.display !== "none");
31
- }
32
- function isListboxOpen() {
33
- return comboboxInput.getAttribute("aria-expanded") === "true";
34
- }
35
- function setActiveDescendant(index) {
36
- const visibleItems = getVisibleItems();
37
- if (index >= 0 && index < visibleItems.length) {
38
- const activeItem = visibleItems[index];
39
- const itemId = activeItem.id || `${listBoxId}-option-${index}`;
40
- if (!activeItem.id) {
41
- activeItem.id = itemId;
42
- }
43
- comboboxInput.setAttribute("aria-activedescendant", itemId);
44
- if (typeof activeItem.scrollIntoView === "function") {
45
- activeItem.scrollIntoView({ block: "nearest", behavior: "smooth" });
46
- }
47
- if (callback?.onActiveDescendantChange) {
48
- try {
49
- callback.onActiveDescendantChange(itemId, activeItem);
50
- } catch (error) {
51
- console.error("[aria-ease] Error in combobox onActiveDescendantChange callback:", error);
52
- }
53
- }
54
- } else {
55
- comboboxInput.setAttribute("aria-activedescendant", "");
56
- }
57
- activeIndex = index;
58
- }
59
- function openListbox() {
60
- comboboxInput.setAttribute("aria-expanded", "true");
61
- listBox.style.display = "block";
62
- if (callback?.onOpenChange) {
63
- try {
64
- callback.onOpenChange(true);
65
- } catch (error) {
66
- console.error("[aria-ease] Error in combobox onOpenChange callback:", error);
67
- }
68
- }
69
- }
70
- function closeListbox() {
71
- comboboxInput.setAttribute("aria-expanded", "false");
72
- comboboxInput.setAttribute("aria-activedescendant", "");
73
- listBox.style.display = "none";
74
- activeIndex = -1;
75
- if (callback?.onOpenChange) {
76
- try {
77
- callback.onOpenChange(false);
78
- } catch (error) {
79
- console.error("[aria-ease] Error in combobox onOpenChange callback:", error);
80
- }
81
- }
82
- }
83
- function selectOption(item) {
84
- const value = item.textContent?.trim() || "";
85
- comboboxInput.value = value;
86
- item.setAttribute("aria-selected", "true");
87
- closeListbox();
88
- if (callback?.onSelect) {
89
- try {
90
- callback.onSelect(item);
91
- } catch (error) {
92
- console.error("[aria-ease] Error in combobox onSelect callback:", error);
93
- }
94
- }
95
- }
96
- function handleInputKeyDown(event) {
97
- const visibleItems = getVisibleItems();
98
- const isOpen = isListboxOpen();
99
- switch (event.key) {
100
- case "ArrowDown":
101
- event.preventDefault();
102
- if (!isOpen) {
103
- openListbox();
104
- return;
105
- }
106
- if (visibleItems.length === 0) return;
107
- {
108
- const newIndex = activeIndex >= visibleItems.length - 1 ? 0 : activeIndex + 1;
109
- setActiveDescendant(newIndex);
110
- }
111
- break;
112
- case "ArrowUp":
113
- event.preventDefault();
114
- if (!isOpen) return;
115
- if (visibleItems.length > 0) {
116
- const newIndex = activeIndex <= 0 ? visibleItems.length - 1 : activeIndex - 1;
117
- setActiveDescendant(newIndex);
118
- }
119
- break;
120
- case "Enter":
121
- if (isOpen && activeIndex >= 0 && activeIndex < visibleItems.length) {
122
- event.preventDefault();
123
- selectOption(visibleItems[activeIndex]);
124
- }
125
- break;
126
- case "Escape":
127
- if (isOpen) {
128
- event.preventDefault();
129
- closeListbox();
130
- } else if (comboboxInput.value) {
131
- event.preventDefault();
132
- comboboxInput.value = "";
133
- comboboxInput.setAttribute("aria-activedescendant", "");
134
- const visibleItems2 = getVisibleItems();
135
- visibleItems2.forEach((item) => {
136
- if (item.getAttribute("aria-selected") === "true") item.setAttribute("aria-selected", "false");
137
- });
138
- if (callback?.onClear) {
139
- try {
140
- callback.onClear();
141
- } catch (error) {
142
- console.error("[aria-ease] Error in combobox onClear callback:", error);
143
- }
144
- }
145
- }
146
- break;
147
- case "Home":
148
- if (isOpen && visibleItems.length > 0) {
149
- event.preventDefault();
150
- setActiveDescendant(0);
151
- }
152
- break;
153
- case "End":
154
- if (isOpen && visibleItems.length > 0) {
155
- event.preventDefault();
156
- setActiveDescendant(visibleItems.length - 1);
157
- }
158
- break;
159
- case "Tab":
160
- if (isOpen && activeIndex >= 0 && activeIndex < visibleItems.length) {
161
- selectOption(visibleItems[activeIndex]);
162
- }
163
- if (isOpen) {
164
- closeListbox();
165
- }
166
- break;
167
- }
168
- }
169
- function handleMouseMove(event) {
170
- const target = event.target;
171
- if (target.classList.contains(listBoxItemsClass)) {
172
- const visibleItems = getVisibleItems();
173
- const index = visibleItems.indexOf(target);
174
- if (index >= 0) {
175
- setActiveDescendant(index);
176
- }
177
- }
178
- }
179
- function handleMouseDown(event) {
180
- const target = event.target;
181
- if (target.classList.contains(listBoxItemsClass)) {
182
- event.preventDefault();
183
- selectOption(target);
184
- }
185
- }
186
- function handleClickOutside(event) {
187
- const target = event.target;
188
- if (!comboboxInput.contains(target) && !listBox.contains(target) && (!listButton || !listButton.contains(target))) {
189
- closeListbox();
190
- }
191
- }
192
- function handleListButtonClick() {
193
- if (isListboxOpen()) {
194
- closeListbox();
195
- } else {
196
- openListbox();
197
- comboboxInput.focus();
198
- }
199
- }
200
- function handleListButtonKeyDown(event) {
201
- if (event.key === "Enter" || event.key === " ") {
202
- event.preventDefault();
203
- handleListButtonClick();
204
- }
205
- }
206
- comboboxInput.addEventListener("keydown", handleInputKeyDown);
207
- listBox.addEventListener("mousemove", handleMouseMove);
208
- listBox.addEventListener("mousedown", handleMouseDown);
209
- document.addEventListener("mousedown", handleClickOutside);
210
- if (listButton) {
211
- listButton.setAttribute("tabindex", "-1");
212
- listButton.setAttribute("aria-label", "Toggle options");
213
- listButton.addEventListener("click", handleListButtonClick);
214
- listButton.addEventListener("keydown", handleListButtonKeyDown);
215
- }
216
- function initializeOptions() {
217
- const items = listBox.querySelectorAll(`.${listBoxItemsClass}`);
218
- if (items.length === 0) return;
219
- let selectedValue = null;
220
- for (const item of items) {
221
- if (item.getAttribute("aria-selected") === "true") {
222
- selectedValue = item.textContent?.trim() || null;
223
- break;
224
- }
225
- }
226
- if (!selectedValue && comboboxInput.value) {
227
- selectedValue = comboboxInput.value.trim();
228
- }
229
- items.forEach((item, index) => {
230
- item.setAttribute("role", "option");
231
- const itemValue = item.textContent?.trim() || "";
232
- if (selectedValue && itemValue === selectedValue) {
233
- item.setAttribute("aria-selected", "true");
234
- } else {
235
- item.setAttribute("aria-selected", "false");
236
- }
237
- const currentId = item.getAttribute("id");
238
- if (!currentId || currentId === "") {
239
- const itemId = `${listBoxId}-option-${index}`;
240
- item.id = itemId;
241
- item.setAttribute("id", itemId);
242
- }
243
- });
244
- }
245
- initializeOptions();
246
- function cleanup() {
247
- comboboxInput.removeEventListener("keydown", handleInputKeyDown);
248
- listBox.removeEventListener("mousemove", handleMouseMove);
249
- listBox.removeEventListener("mousedown", handleMouseDown);
250
- document.removeEventListener("mousedown", handleClickOutside);
251
- if (listButton) {
252
- listButton.removeEventListener("click", handleListButtonClick);
253
- listButton.removeEventListener("keydown", handleListButtonKeyDown);
254
- }
255
- }
256
- function refresh() {
257
- cachedItems = null;
258
- initializeOptions();
259
- activeIndex = -1;
260
- setActiveDescendant(-1);
261
- }
262
- return { cleanup, refresh, openListbox, closeListbox };
263
- }
264
-
265
- exports.makeComboboxAccessible = makeComboboxAccessible;
1
+ 'use strict';function $({comboboxInputId:h,comboboxButtonId:A,listBoxId:b,listBoxItemsClass:u,callback:a}){if(h==="")return console.error("[aria-ease] 'comboboxInputId' should not be an empty string. Provide an id to the combobox input element that exists before calling makeComboboxAccessible."),{cleanup:()=>{}};let o=document.getElementById(`${h}`);if(!o)return console.error(`[aria-ease] Element with id="${h}" not found. Make sure the combobox input element exists before calling makeComboboxAccessible.`),{cleanup:()=>{}};if(b==="")return console.error("[aria-ease] 'listBoxId' should not be an empty string. Provide an id to the combobox listbox element that exists before calling makeComboboxAccessible."),{cleanup:()=>{}};let s=document.getElementById(`${b}`);if(!s)return console.error(`[aria-ease] Element with id="${b}" not found. Make sure the combobox listbox element exists before calling makeComboboxAccessible.`),{cleanup:()=>{}};if(u==="")return console.error("[aria-ease] 'listboxItemsClass' class should not be an empty string. Provide a class name to at least a listbox option that exists before calling makeComboboxAccessible."),{cleanup:()=>{}};if(!document.querySelectorAll(u))return console.error(`[aria-ease] Listbox option(s) with class="${u}" not found. Make sure at least a combobox listbox option exists before calling makeComboboxAccessible.`),{cleanup:()=>{}};let l=A?document.getElementById(`${A}`):null,r=-1;o.setAttribute("role","combobox"),o.setAttribute("aria-autocomplete","list"),o.setAttribute("aria-controls",b),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-haspopup","listbox"),s.setAttribute("role","listbox");let m=null;function p(){return m||(m=s.querySelectorAll(`.${u}`)),Array.from(m).filter(e=>!e.hidden&&e.style.display!=="none")}function x(){return o.getAttribute("aria-expanded")==="true"}function f(e){let t=p();if(e>=0&&e<t.length){let n=t[e],i=n.id||`${b}-option-${e}`;if(n.id||(n.id=i),o.setAttribute("aria-activedescendant",i),typeof n.scrollIntoView=="function"&&n.scrollIntoView({block:"nearest",behavior:"smooth"}),a?.onActiveDescendantChange)try{a.onActiveDescendantChange(i,n);}catch(c){console.error("[aria-ease] Error in combobox onActiveDescendantChange callback:",c);}}else o.setAttribute("aria-activedescendant","");r=e;}function v(){if(o.setAttribute("aria-expanded","true"),s.style.display="block",a?.onOpenChange)try{a.onOpenChange(!0);}catch(e){console.error("[aria-ease] Error in combobox onOpenChange callback:",e);}}function d(){if(o.setAttribute("aria-expanded","false"),o.setAttribute("aria-activedescendant",""),s.style.display="none",r=-1,a?.onOpenChange)try{a.onOpenChange(!1);}catch(e){console.error("[aria-ease] Error in combobox onOpenChange callback:",e);}}function g(e){let t=e.textContent?.trim()||"";if(o.value=t,e.setAttribute("aria-selected","true"),d(),a?.onSelect)try{a.onSelect(e);}catch(n){console.error("[aria-ease] Error in combobox onSelect callback:",n);}}function L(e){let t=p(),n=x();switch(e.key){case "ArrowDown":if(e.preventDefault(),!n){v();return}if(t.length===0)return;{let i=r>=t.length-1?0:r+1;f(i);}break;case "ArrowUp":if(e.preventDefault(),!n)return;if(t.length>0){let i=r<=0?t.length-1:r-1;f(i);}break;case "Enter":n&&r>=0&&r<t.length&&(e.preventDefault(),g(t[r]));break;case "Escape":if(n)e.preventDefault(),d();else if(o.value&&(e.preventDefault(),o.value="",o.setAttribute("aria-activedescendant",""),p().forEach(c=>{c.getAttribute("aria-selected")==="true"&&c.setAttribute("aria-selected","false");}),a?.onClear))try{a.onClear();}catch(c){console.error("[aria-ease] Error in combobox onClear callback:",c);}break;case "Home":n&&t.length>0&&(e.preventDefault(),f(0));break;case "End":n&&t.length>0&&(e.preventDefault(),f(t.length-1));break;case "Tab":n&&r>=0&&r<t.length&&g(t[r]),n&&d();break}}function y(e){let t=e.target;if(t.classList.contains(u)){let i=p().indexOf(t);i>=0&&f(i);}}function k(e){let t=e.target;t.classList.contains(u)&&(e.preventDefault(),g(t));}function C(e){let t=e.target;!o.contains(t)&&!s.contains(t)&&(!l||!l.contains(t))&&d();}function E(){x()?d():(v(),o.focus());}function w(e){(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),E());}o.addEventListener("keydown",L),s.addEventListener("mousemove",y),s.addEventListener("mousedown",k),document.addEventListener("mousedown",C),l&&(l.setAttribute("tabindex","-1"),l.setAttribute("aria-label","Toggle options"),l.addEventListener("click",E),l.addEventListener("keydown",w));function M(){let e=s.querySelectorAll(`.${u}`);if(e.length===0)return;let t=null;for(let n of e)if(n.getAttribute("aria-selected")==="true"){t=n.textContent?.trim()||null;break}!t&&o.value&&(t=o.value.trim()),e.forEach((n,i)=>{n.setAttribute("role","option");let c=n.textContent?.trim()||"";t&&c===t?n.setAttribute("aria-selected","true"):n.setAttribute("aria-selected","false");let O=n.getAttribute("id");if(!O||O===""){let D=`${b}-option-${i}`;n.id=D,n.setAttribute("id",D);}});}M();function T(){o.removeEventListener("keydown",L),s.removeEventListener("mousemove",y),s.removeEventListener("mousedown",k),document.removeEventListener("mousedown",C),l&&(l.removeEventListener("click",E),l.removeEventListener("keydown",w));}function H(){m=null,M(),r=-1,f(-1);}return {cleanup:T,refresh:H,openListbox:v,closeListbox:d}}exports.makeComboboxAccessible=$;