aria-ease 2.0.2 → 2.0.3

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 (67) hide show
  1. package/README.md +2 -3
  2. package/dist/Types.d-p85gN5m_.d.cts +22 -0
  3. package/dist/Types.d-p85gN5m_.d.ts +22 -0
  4. package/dist/chunk-4366LRNM.js +38 -0
  5. package/dist/chunk-4366LRNM.js.map +1 -0
  6. package/dist/chunk-4WO5XJ5K.js +58 -0
  7. package/dist/chunk-4WO5XJ5K.js.map +1 -0
  8. package/dist/chunk-5HQ6LLC5.js +21 -0
  9. package/dist/chunk-5HQ6LLC5.js.map +1 -0
  10. package/dist/chunk-FBQ5LF2T.js +21 -0
  11. package/dist/chunk-FBQ5LF2T.js.map +1 -0
  12. package/dist/chunk-KGYGCX67.js +18 -0
  13. package/dist/chunk-KGYGCX67.js.map +1 -0
  14. package/dist/chunk-KVTLMA4J.js +58 -0
  15. package/dist/chunk-KVTLMA4J.js.map +1 -0
  16. package/dist/chunk-MEA5U2G4.js +24 -0
  17. package/dist/chunk-MEA5U2G4.js.map +1 -0
  18. package/dist/chunk-RK3JUAFZ.js +18 -0
  19. package/dist/chunk-RK3JUAFZ.js.map +1 -0
  20. package/dist/chunk-RT5IROW4.js +99 -0
  21. package/dist/chunk-RT5IROW4.js.map +1 -0
  22. package/dist/index.cjs +6 -55
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +7 -115
  25. package/dist/index.d.ts +7 -115
  26. package/dist/index.js +7 -313
  27. package/dist/index.js.map +1 -1
  28. package/dist/src/accordion/index.cjs +25 -0
  29. package/dist/src/accordion/index.cjs.map +1 -0
  30. package/dist/src/accordion/index.d.cts +13 -0
  31. package/dist/src/accordion/index.d.ts +13 -0
  32. package/dist/src/accordion/index.js +2 -0
  33. package/dist/src/accordion/index.js.map +1 -0
  34. package/dist/src/block/index.cjs +121 -0
  35. package/dist/src/block/index.cjs.map +1 -0
  36. package/dist/src/block/index.d.cts +8 -0
  37. package/dist/src/block/index.d.ts +8 -0
  38. package/dist/src/block/index.js +3 -0
  39. package/dist/src/block/index.js.map +1 -0
  40. package/dist/src/checkbox/index.cjs +19 -0
  41. package/dist/src/checkbox/index.cjs.map +1 -0
  42. package/dist/src/checkbox/index.d.cts +13 -0
  43. package/dist/src/checkbox/index.d.ts +13 -0
  44. package/dist/src/checkbox/index.js +2 -0
  45. package/dist/src/checkbox/index.js.map +1 -0
  46. package/dist/src/menu/index.cjs +155 -0
  47. package/dist/src/menu/index.cjs.map +1 -0
  48. package/dist/src/menu/index.d.cts +17 -0
  49. package/dist/src/menu/index.d.ts +17 -0
  50. package/dist/src/menu/index.js +3 -0
  51. package/dist/src/menu/index.js.map +1 -0
  52. package/dist/src/radio/index.cjs +22 -0
  53. package/dist/src/radio/index.cjs.map +1 -0
  54. package/dist/src/radio/index.d.cts +13 -0
  55. package/dist/src/radio/index.d.ts +13 -0
  56. package/dist/src/radio/index.js +2 -0
  57. package/dist/src/radio/index.js.map +1 -0
  58. package/dist/src/toggle/index.cjs +22 -0
  59. package/dist/src/toggle/index.cjs.map +1 -0
  60. package/dist/src/toggle/index.d.cts +13 -0
  61. package/dist/src/toggle/index.d.ts +13 -0
  62. package/dist/src/toggle/index.js +2 -0
  63. package/dist/src/toggle/index.js.map +1 -0
  64. package/package.json +26 -2
  65. package/dist/index.d.mts +0 -140
  66. package/dist/index.mjs +0 -110
  67. package/dist/index.mjs.map +0 -1
package/README.md CHANGED
@@ -19,7 +19,7 @@ Add accessibility to menu: menu can be a dropdown, combo box, slide navigation m
19
19
  #### Usage
20
20
 
21
21
  ```javascript
22
- import { Menu } from "aria-ease";
22
+ import * as Menu from "aria-ease/menu";
23
23
 
24
24
  useEffect(() => {
25
25
  menuRef.current = Menu.makeMenuAccessible({
@@ -29,8 +29,7 @@ useEffect(() => {
29
29
  });
30
30
  }, []);
31
31
 
32
- const toggleMenuDisplay = (event) => {
33
- event.preventDefault();
32
+ const toggleMenuDisplay = () => {
34
33
  const menuDiv = document.querySelector("#menu-div");
35
34
  if (getComputedStyle(menuDiv).display === "none") {
36
35
  menuRef.current.openMenu();
@@ -0,0 +1,22 @@
1
+ declare global {
2
+ type HTMLElement = Element;
3
+ type NodeListOf<HTMLElement> = Iterable<HTMLElement>;
4
+ }
5
+
6
+ interface AccordionStates {
7
+ display: boolean;
8
+ }
9
+
10
+ interface CheckboxStates {
11
+ checked: boolean;
12
+ }
13
+
14
+ interface RadioStates {
15
+ checked: boolean;
16
+ }
17
+
18
+ interface ToggleStates {
19
+ pressed: boolean;
20
+ }
21
+
22
+ export type { AccordionStates as A, CheckboxStates as C, RadioStates as R, ToggleStates as T };
@@ -0,0 +1,22 @@
1
+ declare global {
2
+ type HTMLElement = Element;
3
+ type NodeListOf<HTMLElement> = Iterable<HTMLElement>;
4
+ }
5
+
6
+ interface AccordionStates {
7
+ display: boolean;
8
+ }
9
+
10
+ interface CheckboxStates {
11
+ checked: boolean;
12
+ }
13
+
14
+ interface RadioStates {
15
+ checked: boolean;
16
+ }
17
+
18
+ interface ToggleStates {
19
+ pressed: boolean;
20
+ }
21
+
22
+ export type { AccordionStates as A, CheckboxStates as C, RadioStates as R, ToggleStates as T };
@@ -0,0 +1,38 @@
1
+ import { handleKeyPress } from './chunk-RT5IROW4.js';
2
+ // src/block/src/makeBlockAccessible/makeBlockAccessible.ts
3
+ var eventListenersMap = /* @__PURE__ */ new Map();
4
+ function makeBlockAccessible(blockId, blockElementsClass) {
5
+ var blockDiv = document.querySelector("#".concat(blockId));
6
+ if (!blockDiv) {
7
+ throw new Error("Invalid block main div id provided.");
8
+ }
9
+ var blockItems = blockDiv.querySelectorAll(".".concat(blockElementsClass));
10
+ if (!blockItems) {
11
+ throw new Error("Invalid block items shared class provided.");
12
+ }
13
+ blockItems.forEach(function(blockItem) {
14
+ if (!eventListenersMap.has(blockItem)) {
15
+ blockItem.addEventListener("keydown", function(event) {
16
+ var items = blockDiv.querySelectorAll(".".concat(blockElementsClass));
17
+ var index = Array.prototype.indexOf.call(items, blockItem);
18
+ handleKeyPress(event, items, index);
19
+ var handler = function(event2) {
20
+ return handleKeyPress(event2, items, index);
21
+ };
22
+ eventListenersMap.set(blockItem, handler);
23
+ });
24
+ }
25
+ });
26
+ return function cleanUpBlockEventListeners() {
27
+ blockItems.forEach(function(blockItem, blockItemIndex) {
28
+ if (eventListenersMap.has(blockItem)) {
29
+ blockItem.removeEventListener("keydown", function(event) {
30
+ return handleKeyPress(event, blockItems, blockItemIndex);
31
+ });
32
+ eventListenersMap.delete(blockItem);
33
+ }
34
+ });
35
+ };
36
+ }
37
+ export { makeBlockAccessible }; //# sourceMappingURL=chunk-4366LRNM.js.map
38
+ //# sourceMappingURL=chunk-4366LRNM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/macx/aria-ease/package/dist/chunk-4366LRNM.js","../src/block/src/makeBlockAccessible/makeBlockAccessible.ts"],"names":["handleKeyPress","blockDiv","Error","blockItems","querySelectorAll","blockElementsClass","forEach","blockItem","eventListenersMap","has","addEventListener","event","items","index","Array","prototype","indexOf","call","handler","set","cleanUpBlockEventListeners","blockItemIndex"],"mappings":"AAAA,SAASA,cAAc,QAAQ,sBAAsB;MCanD,EAAG,CAACC,UAAU,KAAA,IAAA,CAAA,OAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,EAAA,OAAA,GAAA,GAAA;UACZ,MAAM,GAAA,CAAIC,IAAAA,EAAM,EAAA,CAAA,OAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,EAAA,OAAA,GAAA;UAClB,MAAA,GAAA,CAAA,MAAA,EAAA,CAAA,OAAA,EAAA,GAAA,CAAA,IAAA,OAAA,GAAA;YAEA,IAAMC,GAAAA,CAAAA,MAAAA,EAAAA,CAAoCF,SAASG,GAAAA,CAAAA,IAAA,CAAiB,IAAsB,EAAvCA,KAAqBC;cACxE,EAAG,CAACF,EAAAA,CAAAA,MAAAA,GAAY,SAAA,gBAAA,CAAA,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EAAA,CAAA,CAAA,GAAA,CAAA,IAAA,QAAA,GAAA;wBACF,EAAA,GAAA,IAAA,KAAA,EAAA,CAAA,CAAA,GAAA,CAAA,IAAA,OAAA,SAAA,GAAA;2BAAA,eAAA,OAAA,YAAA;;8BAIA,EAAA,EAAA,GAAO,GAAA,CAAA,KAASE,EAAAA,CAAAA,CAAAA,GAAAA,CAAAA,IAAAA,OAAAA,SAAAA,GAAAA;iCAAAA,eAAAA,OAAAA,YAAAA;;gCACdjB,EAAAA,EAAAA,MAAAA,CAAWG,OAAA,CAAQ,CAAA,GAAA,CAAA,IAACC,OAAAA,SAAAA,GAAwBc;iCAAAA,eAAAA,OAAAA,YAAAA;8BAC1C,CAAA,GAAIb,EAAAA,MAAAA,CAAAA,SAAkBC,GAAA,CAAIF,SAAY,EAAZA,OAAY,EAAA,IAAA,OAAA,YAAA","sourcesContent":["import { handleKeyPress } from './chunk-RT5IROW4.js';\n\n// src/block/src/makeBlockAccessible/makeBlockAccessible.ts\nvar eventListenersMap = /* @__PURE__ */ new Map();\nfunction makeBlockAccessible(blockId, blockElementsClass) {\n const blockDiv = document.querySelector(`#${blockId}`);\n if (!blockDiv) {\n throw new Error(\"Invalid block main div id provided.\");\n }\n const blockItems = blockDiv.querySelectorAll(`.${blockElementsClass}`);\n if (!blockItems) {\n throw new Error(\"Invalid block items shared class provided.\");\n }\n blockItems.forEach((blockItem) => {\n if (!eventListenersMap.has(blockItem)) {\n blockItem.addEventListener(\"keydown\", (event) => {\n const items = blockDiv.querySelectorAll(`.${blockElementsClass}`);\n const index = Array.prototype.indexOf.call(items, blockItem);\n handleKeyPress(event, items, index);\n const handler = (event2) => handleKeyPress(event2, items, index);\n eventListenersMap.set(blockItem, handler);\n });\n }\n });\n return function cleanUpBlockEventListeners() {\n blockItems.forEach((blockItem, blockItemIndex) => {\n if (eventListenersMap.has(blockItem)) {\n blockItem.removeEventListener(\"keydown\", (event) => handleKeyPress(event, blockItems, blockItemIndex));\n eventListenersMap.delete(blockItem);\n }\n });\n };\n}\n\nexport { makeBlockAccessible };\n//# sourceMappingURL=chunk-4366LRNM.js.map\n","/** \n * Adds keyboard interaction to block. The block traps focus and can be interacted with using the keyboard.\n * @param {string} blockId The id of the block container.\n * @param {string} blockElementsClass The shared class of the elements that are children of the block.\n*/\n\nimport { HTMLElement, NodeListOfHTMLElement } from \"../../../../Types\"\nimport { handleKeyPress } from \"../../../utils/handleKeyPress/handleKeyPress\";\n\nconst eventListenersMap = new Map<HTMLElement, (event: KeyboardEvent) => void>();\n\nexport function makeBlockAccessible(blockId: string, blockElementsClass: string) {\n const blockDiv: HTMLElement = document.querySelector(`#${blockId}`) as HTMLElement\n if(!blockDiv) {\n throw new Error(\"Invalid block main div id provided.\")\n }\n\n const blockItems: NodeListOfHTMLElement = blockDiv.querySelectorAll(`.${blockElementsClass}`);\n if(!blockItems) {\n throw new Error(\"Invalid block items shared class provided.\")\n }\n\n blockItems.forEach((blockItem: HTMLElement): void => {\n if (!eventListenersMap.has(blockItem)) {\n blockItem.addEventListener(\"keydown\", (event: KeyboardEvent) => {\n const items = blockDiv.querySelectorAll(`.${blockElementsClass}`) as NodeListOf<HTMLElement>;\n const index = Array.prototype.indexOf.call(items, blockItem);\n handleKeyPress(event, items, index);\n const handler = (event: KeyboardEvent) => handleKeyPress(event, items, index);\n eventListenersMap.set(blockItem, handler);\n });\n \n }\n });\n\n\n\n return function cleanUpBlockEventListeners(): void {\n blockItems.forEach((blockItem: HTMLElement, blockItemIndex: number): void => {\n if (eventListenersMap.has(blockItem)) {\n blockItem.removeEventListener(\"keydown\", (event: KeyboardEvent) => handleKeyPress(event, blockItems, blockItemIndex));\n eventListenersMap.delete(blockItem);\n }\n });\n };\n}"]}
@@ -0,0 +1,58 @@
1
+ import { handleKeyPress } from './chunk-RT5IROW4.js';
2
+ // src/menu/src/makeMenuAccessible/makeMenuAccessible.ts
3
+ function makeMenuAccessible(param) {
4
+ var menuId = param.menuId, menuElementsClass = param.menuElementsClass, triggerId = param.triggerId;
5
+ var menuDiv = document.querySelector("#".concat(menuId));
6
+ if (!menuDiv) throw new Error("Invalid menu div id provided");
7
+ var triggerButton = document.querySelector("#".concat(triggerId));
8
+ if (!triggerButton) throw new Error("Invalid trigger button id provided");
9
+ var handlerMap = /* @__PURE__ */ new Map();
10
+ function setAria(isOpen) {
11
+ triggerButton.setAttribute("aria-expanded", isOpen ? "true" : "false");
12
+ }
13
+ function addListeners() {
14
+ var menuItems = menuDiv.querySelectorAll(".".concat(menuElementsClass));
15
+ menuItems.forEach(function(menuItem, index) {
16
+ if (!handlerMap.has(menuItem)) {
17
+ var handler = function(event) {
18
+ return handleKeyPress(event, menuItems, index, menuDiv, triggerButton);
19
+ };
20
+ menuItem.addEventListener("keydown", handler);
21
+ handlerMap.set(menuItem, handler);
22
+ }
23
+ });
24
+ }
25
+ function removeListeners() {
26
+ var menuItems = menuDiv.querySelectorAll(".".concat(menuElementsClass));
27
+ menuItems.forEach(function(menuItem) {
28
+ var handler = handlerMap.get(menuItem);
29
+ if (handler) {
30
+ menuItem.removeEventListener("keydown", handler);
31
+ handlerMap.delete(menuItem);
32
+ }
33
+ });
34
+ }
35
+ function openMenu() {
36
+ menuDiv.style.display = "block";
37
+ setAria(true);
38
+ addListeners();
39
+ var menuItems = menuDiv.querySelectorAll(".".concat(menuElementsClass));
40
+ if (menuItems.length > 0) menuItems[0].focus();
41
+ }
42
+ function closeMenu() {
43
+ removeListeners();
44
+ menuDiv.style.display = "none";
45
+ setAria(false);
46
+ triggerButton.focus();
47
+ }
48
+ function cleanup() {
49
+ removeListeners();
50
+ }
51
+ return {
52
+ openMenu: openMenu,
53
+ closeMenu: closeMenu,
54
+ cleanup: cleanup
55
+ };
56
+ }
57
+ export { makeMenuAccessible }; //# sourceMappingURL=chunk-4WO5XJ5K.js.map
58
+ //# sourceMappingURL=chunk-4WO5XJ5K.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/macx/aria-ease/package/dist/chunk-4WO5XJ5K.js","../src/menu/src/makeMenuAccessible/makeMenuAccessible.ts"],"names":["handleKeyPress","makeMenuAccessible","menuId","menuElementsClass","triggerId","menuDiv","document","querySelector","Error","triggerButton","handlerMap","Map","setAria","isOpen","setAttribute","addListeners","menuItems","querySelectorAll","forEach","menuItem","index","has","handler","event","addEventListener","set","removeListeners","get","removeEventListener","delete","openMenu","style","display","length","focus","closeMenu","cleanup"],"mappings":"AAAA,SAASA,cAAc,QAAQ,sBAAsB;ACU9C,SAASC,mBAAmB,KAAuC,uBAAA;QAArCC,CAAAA,QAAF,MAAEA,KAAAA,KAAQC,QAAmBC,YAA7B,MAA6BA;QAA3BF,SAAAA,MAAAA,CAAQC,OAAAA,oBAARD,MAAQC,aAAV,MAAUA,YAARD;MACnC,EAAMG,UAAUC,SAASC,aAAA,CAAc,IAAIL,OAAM;MACjD,EAAA,CAAA,CAAI,CAACG,OAAAA,EAAS,IAAA,EAAM,EAAA,EAAIG,IAAAA,EAAM;MAE9B,EAAMC,gBAAgBH,SAASC,aAAA,CAAc,IAAIH,OAAS,OAATA;MACjD,EAAA,CAAA,CAAI,CAACK,aAAAA,EAAe,IAAA,EAAM,EAAA,EAAID,IAAAA,EAAM;MAGpC,EAAME,aAAA,aAAA,GAAA,IAAiBC;MAEvB,OAAA,EAASC,MAAAA,EAAQC,IAAAA,EAAA;YACfJ,UAAAA,IAAcK,QAAAA,CAAAA,GAAA,CAAa,aAAA,IAAiBD,KAAAA,IAAS,KAAA,IAAS;MAChE;MAEA,OAAA,EAASE;YACP,EAAMC,UAAAA,EAAYX,MAAAA,EAAQY,cAAAA,CAAA,AAAAA,CAAiB,GAAId,OAAJ,EAAqB,OAAjBA;YAC/Ca,MAAAA,IAAUE,GAAAA,CAAAA,SAAAA,EAAA,CAAQ,OAAA,EAACC,UAAuBC;kBACxC,IAAI,CAACV,KAAAA,GAAAA,CAAAA,EAAWW,GAAA,CAAIF,KAAAA,MAAW;sBAC7B,IAAMG,IAAAA,SAAAA,KAAU;2BAAA,IA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A,SAAAA,SAAAA,GAAAA,SAAUK,WAAAA,uBAAAA","sourcesContent":["import { handleKeyPress } from './chunk-RT5IROW4.js';\n\n// src/menu/src/makeMenuAccessible/makeMenuAccessible.ts\nfunction makeMenuAccessible({ menuId, menuElementsClass, triggerId }) {\n const menuDiv = document.querySelector(`#${menuId}`);\n if (!menuDiv) throw new Error(\"Invalid menu div id provided\");\n const triggerButton = document.querySelector(`#${triggerId}`);\n if (!triggerButton) throw new Error(\"Invalid trigger button id provided\");\n const handlerMap = /* @__PURE__ */ new Map();\n function setAria(isOpen) {\n triggerButton.setAttribute(\"aria-expanded\", isOpen ? \"true\" : \"false\");\n }\n function addListeners() {\n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`);\n menuItems.forEach((menuItem, index) => {\n if (!handlerMap.has(menuItem)) {\n const handler = (event) => handleKeyPress(event, menuItems, index, menuDiv, triggerButton);\n menuItem.addEventListener(\"keydown\", handler);\n handlerMap.set(menuItem, handler);\n }\n });\n }\n function removeListeners() {\n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`);\n menuItems.forEach((menuItem) => {\n const handler = handlerMap.get(menuItem);\n if (handler) {\n menuItem.removeEventListener(\"keydown\", handler);\n handlerMap.delete(menuItem);\n }\n });\n }\n function openMenu() {\n menuDiv.style.display = \"block\";\n setAria(true);\n addListeners();\n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`);\n if (menuItems.length > 0) menuItems[0].focus();\n }\n function closeMenu() {\n removeListeners();\n menuDiv.style.display = \"none\";\n setAria(false);\n triggerButton.focus();\n }\n function cleanup() {\n removeListeners();\n }\n return { openMenu, closeMenu, cleanup };\n}\n\nexport { makeMenuAccessible };\n//# sourceMappingURL=chunk-4WO5XJ5K.js.map\n","/**\n * Adds keyboard interaction to toggle menu. The menu traps focus and can be interacted with using the keyboard. The first interactive item of the menu has focus when menu open.\n * @param {string} menuId - The id of the menu.\n * @param {string} menuElementsClass - The class of the items that are children of the menu.\n * @param {string} triggerId - The id of the button that triggers the menu.\n*/\n\nimport { handleKeyPress } from \"../../../utils/handleKeyPress/handleKeyPress\";\nimport { NodeListOfHTMLElement } from \"../../../../Types\";\n\nexport function makeMenuAccessible({ menuId, menuElementsClass, triggerId }: {menuId: string; menuElementsClass: string; triggerId: string;}) {\n const menuDiv = document.querySelector(`#${menuId}`) as HTMLElement;\n if (!menuDiv) throw new Error(\"Invalid menu div id provided\");\n\n const triggerButton = document.querySelector(`#${triggerId}`) as HTMLElement;\n if (!triggerButton) throw new Error(\"Invalid trigger button id provided\");\n\n\n const handlerMap = new Map<HTMLElement, (event: KeyboardEvent) => void>();\n\n function setAria(isOpen: boolean) {\n triggerButton.setAttribute(\"aria-expanded\", isOpen ? \"true\" : \"false\");\n }\n\n function addListeners() {\n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`) as NodeListOfHTMLElement<HTMLElement>;\n menuItems.forEach((menuItem: HTMLElement, index: number) => {\n if (!handlerMap.has(menuItem)) {\n const handler = (event: KeyboardEvent) => handleKeyPress(event, menuItems, index, menuDiv, triggerButton);\n menuItem.addEventListener(\"keydown\", handler);\n handlerMap.set(menuItem, handler);\n }\n });\n }\n\n function removeListeners() {\n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`) as NodeListOfHTMLElement<HTMLElement>;\n menuItems.forEach((menuItem: HTMLElement) => {\n const handler = handlerMap.get(menuItem);\n if (handler) {\n menuItem.removeEventListener(\"keydown\", handler);\n handlerMap.delete(menuItem);\n }\n });\n }\n\n function openMenu() {\n menuDiv.style.display = \"block\";\n setAria(true);\n addListeners();\n \n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`) as NodeListOfHTMLElement<HTMLElement>;\n if (menuItems.length > 0) menuItems[0].focus();\n }\n\n function closeMenu() {\n removeListeners();\n menuDiv.style.display = \"none\";\n setAria(false);\n triggerButton.focus();\n }\n\n function cleanup() {\n removeListeners();\n }\n\n return { openMenu, closeMenu, cleanup };\n}\n"]}
@@ -0,0 +1,21 @@
1
+ // src/radio/src/updateRadioAriaAttributes/updateRadioAriaAttributes.ts
2
+ function updateRadioAriaAttributes(radioId, radiosClass, radioStates, currentPressedRadioIndex) {
3
+ var radioDiv = document.querySelector("#".concat(radioId));
4
+ if (!radioDiv) {
5
+ throw new Error("Invalid radio main div id provided.");
6
+ }
7
+ var radioItems = Array.from(radioDiv.querySelectorAll(".".concat(radiosClass)));
8
+ if (radioItems.length === 0) {
9
+ throw new Error("Invalid radios shared class provided.");
10
+ }
11
+ radioItems.forEach(function(radioItem, index) {
12
+ var state = radioStates[index];
13
+ var checked = radioItem.getAttribute("aria-checked");
14
+ var shouldBeChecked = index === currentPressedRadioIndex ? state.checked ? "true" : "false" : "false";
15
+ if (checked && checked !== shouldBeChecked) {
16
+ radioItem.setAttribute("aria-checked", shouldBeChecked);
17
+ }
18
+ });
19
+ }
20
+ export { updateRadioAriaAttributes }; //# sourceMappingURL=chunk-5HQ6LLC5.js.map
21
+ //# sourceMappingURL=chunk-5HQ6LLC5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/macx/aria-ease/package/dist/chunk-5HQ6LLC5.js","../src/radio/src/updateRadioAriaAttributes/updateRadioAriaAttributes.ts"],"names":["updateRadioAriaAttributes","radioId","radiosClass","radioStates","currentPressedRadioIndex","radioDiv","document","querySelector","Error","radioItems","Array","from","querySelectorAll","length","forEach","radioItem","index","state","checked","getAttribute","shouldBeChecked","setAttribute"],"mappings":"AAAA,uEAAuE;ACUhE,SAASA,0BAA0BC,OAAA,EAAiBC,WAAA,EAAqBC,WAAA,EAA4BC,wBAAA;QAClGC,WAA+BC,SAASC,aAAA,CAAc,IAAW,KAAPN,CAAAA,CAAAA,MAAO,CAAA;YACvE,CAAA,CAAA,CAAA,CAAI,CAACI,EAAAA,EAAAA,EAAAA,EAAAA,EAAU;wBACX,EAAA,EAAA,EAAM,EAAA,EAAIG,EAAAA,IAAM;YACpB;QAEMC,aAA4BC,MAAMC,IAAA,CAAKN,SAASO,gBA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Attributes(radioId, radiosClass, radioStates, currentPressedRadioIndex) {\n const radioDiv = document.querySelector(`#${radioId}`);\n if (!radioDiv) {\n throw new Error(\"Invalid radio main div id provided.\");\n }\n const radioItems = Array.from(radioDiv.querySelectorAll(`.${radiosClass}`));\n if (radioItems.length === 0) {\n throw new Error(\"Invalid radios shared class provided.\");\n }\n radioItems.forEach((radioItem, index) => {\n const state = radioStates[index];\n const checked = radioItem.getAttribute(\"aria-checked\");\n const shouldBeChecked = index === currentPressedRadioIndex ? state.checked ? \"true\" : \"false\" : \"false\";\n if (checked && checked !== shouldBeChecked) {\n radioItem.setAttribute(\"aria-checked\", shouldBeChecked);\n }\n });\n}\n\nexport { updateRadioAriaAttributes };\n//# sourceMappingURL=chunk-5HQ6LLC5.js.map\n","/**\n * Adds screen reader accessibility to multiple radio buttons. Updates the aria attributes of the radio buttons. Radio elements must possess the following aria attributes; aria-checked and aria-label.\n * @param {string} radioId The id of the radio parent container.\n * @param {string} radiosClass The shared class of all the radios.\n * @param {RadioStates[]} radioStates Array of objects containing radio buttons state information.\n * @param {number} currentPressedRadioIndex Index of the currently checked or unchecked radio button.\n */\n\nimport { HTMLElement, RadioStates } from \"../../../../Types\";\n\nexport function updateRadioAriaAttributes(radioId: string, radiosClass: string, radioStates: RadioStates[], currentPressedRadioIndex: number): void {\n const radioDiv: HTMLElement | null = document.querySelector(`#${radioId}`);\n if (!radioDiv) {\n throw new Error(\"Invalid radio main div id provided.\");\n }\n \n const radioItems: HTMLElement[] = Array.from(radioDiv.querySelectorAll(`.${radiosClass}`));\n if(radioItems.length === 0) {\n throw new Error('Invalid radios shared class provided.');\n }\n\n radioItems.forEach((radioItem: HTMLElement, index: number) => {\n const state = radioStates[index];\n const checked = radioItem.getAttribute(\"aria-checked\");\n const shouldBeChecked = index === currentPressedRadioIndex ? (state.checked ? \"true\" : \"false\") : \"false\";\n if (checked && checked !== shouldBeChecked) {\n radioItem.setAttribute(\"aria-checked\", shouldBeChecked);\n }\n });\n}"]}
@@ -0,0 +1,21 @@
1
+ // src/toggle/src/updateToggleAriaAttribute/updateToggleAriaAttribute.ts
2
+ function updateToggleAriaAttribute(toggleId, togglesClass, toggleStates, currentPressedToggleIndex) {
3
+ var toggleDiv = document.querySelector("#".concat(toggleId));
4
+ if (!toggleDiv) {
5
+ throw new Error("Invalid toggle main div id provided.");
6
+ }
7
+ var toggleItems = Array.from(toggleDiv.querySelectorAll(".".concat(togglesClass)));
8
+ if (toggleItems.length === 0) {
9
+ throw new Error("Invalid toggles shared class provided.");
10
+ }
11
+ if (toggleItems.length !== toggleStates.length) {
12
+ throw new Error("Toggle state/DOM length mismatch: found ".concat(toggleItems.length, " triggers, but got ").concat(toggleStates.length, " state objects."));
13
+ }
14
+ toggleItems.forEach(function(toggle, index) {
15
+ if (index === currentPressedToggleIndex) {
16
+ toggle.setAttribute("aria-pressed", toggleStates[index].pressed ? "true" : "false");
17
+ }
18
+ });
19
+ }
20
+ export { updateToggleAriaAttribute }; //# sourceMappingURL=chunk-FBQ5LF2T.js.map
21
+ //# sourceMappingURL=chunk-FBQ5LF2T.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/macx/aria-ease/package/dist/chunk-FBQ5LF2T.js","../src/toggle/src/updateToggleAriaAttribute/updateToggleAriaAttribute.ts"],"names":["updateToggleAriaAttribute","toggleId","togglesClass","toggleStates","currentPressedToggleIndex","toggleDiv","document","querySelector","Error","toggleItems","Array","from","querySelectorAll","length","forEach","toggle","index","setAttribute","pressed"],"mappings":"AAAA,wEAAwE;ACUjE,SAASA,0BAA0BC,QAAA,EAAkBC,YAAA,EAAsBC,YAAA,EAA8BC,yBAAA;QACxGC,YAAgCC,SAASC,aAAA,CAAc,IAAY,GAARN,EAAAA,EAAAA,KAAQ,EAAA;YACzE,CAAA,CAAA,CAAA,CAAI,CAACI,GAAAA,EAAAA,EAAAA,EAAAA,EAAW;wBACd,EAAA,EAAA,EAAM,EAAA,EAAIG,EAAAA,IAAM;YAClB;QAEMC,cA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GAAAA,CAAAA,CAAAA,CAAAA,GAAA,CAAaa,CAAAA,CAAAA,GAAAA,CAAK,CAAEE,CAAAA,GAAAA,GAAA,GAAU,GAAA,MAAS;wBAC7E;YACF;AACF","sourcesContent":["// src/toggle/src/updateToggleAriaAttribute/updateToggleAriaAttribute.ts\nfunction updateToggleAriaAttribute(toggleId, togglesClass, toggleStates, currentPressedToggleIndex) {\n const toggleDiv = document.querySelector(`#${toggleId}`);\n if (!toggleDiv) {\n throw new Error(\"Invalid toggle main div id provided.\");\n }\n const toggleItems = Array.from(toggleDiv.querySelectorAll(`.${togglesClass}`));\n if (toggleItems.length === 0) {\n throw new Error(\"Invalid toggles shared class provided.\");\n }\n if (toggleItems.length !== toggleStates.length) {\n throw new Error(`Toggle state/DOM length mismatch: found ${toggleItems.length} triggers, but got ${toggleStates.length} state objects.`);\n }\n toggleItems.forEach((toggle, index) => {\n if (index === currentPressedToggleIndex) {\n toggle.setAttribute(\"aria-pressed\", toggleStates[index].pressed ? \"true\" : \"false\");\n }\n });\n}\n\nexport { updateToggleAriaAttribute };\n//# sourceMappingURL=chunk-FBQ5LF2T.js.map\n","/**\n * Adds screen reader accessibility to toggle buttons. Updates the aria attributes of the toggle buttons. Button must be a semantic button element or a non-semantic element with a role of button, and possess the aria-pressed attribute.\n * @param {string} toggleId The id of the toggle buttons parent container.\n * @param {string} togglesClass The shared class of all the toggle buttons.\n * @param {ToggleStates[]} toggleStates Array of objects containing toggle buttons state information.\n * @param {number} currentPressedToggleIndex Index of the currently pressed or unpressed toggle button.\n*/\n\nimport { HTMLElement, ToggleStates } from \"../../../../Types\";\n\nexport function updateToggleAriaAttribute(toggleId: string, togglesClass: string, toggleStates: ToggleStates[], currentPressedToggleIndex: number): void {\n const toggleDiv: HTMLElement | null = document.querySelector(`#${toggleId}`);\n if (!toggleDiv) {\n throw new Error(\"Invalid toggle main div id provided.\");\n }\n\n const toggleItems: HTMLElement[] = Array.from(toggleDiv.querySelectorAll(`.${togglesClass}`));\n if (toggleItems.length === 0) {\n throw new Error('Invalid toggles shared class provided.');\n }\n\n if(toggleItems.length !== toggleStates.length) {\n throw new Error(`Toggle state/DOM length mismatch: found ${toggleItems.length} triggers, but got ${toggleStates.length} state objects.`);\n }\n\n toggleItems.forEach((toggle, index) => {\n if (index === currentPressedToggleIndex) {\n toggle.setAttribute(\"aria-pressed\", toggleStates[index].pressed ? 'true' : 'false');\n }\n });\n}"]}
@@ -0,0 +1,18 @@
1
+ // src/checkbox/src/updateCheckboxAriaAttributes/updateCheckboxAriaAttributes.ts
2
+ function updateCheckboxAriaAttributes(checkboxId, checkboxesClass, checkboxStates, currentPressedCheckboxIndex) {
3
+ var checkboxDiv = document.querySelector("#".concat(checkboxId));
4
+ if (!checkboxDiv) {
5
+ throw new Error("Invalid checkbox main div id provided.");
6
+ }
7
+ var checkboxItems = Array.from(document.querySelectorAll(".".concat(checkboxesClass)));
8
+ if (checkboxItems.length === 0) {
9
+ throw new Error("Invalid checkboxes shared class provided.");
10
+ }
11
+ checkboxItems.forEach(function(checkbox, index) {
12
+ if (index === currentPressedCheckboxIndex) {
13
+ checkbox.setAttribute("aria-checked", checkboxStates[index].checked ? "true" : "false");
14
+ }
15
+ });
16
+ }
17
+ export { updateCheckboxAriaAttributes }; //# sourceMappingURL=chunk-KGYGCX67.js.map
18
+ //# sourceMappingURL=chunk-KGYGCX67.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/macx/aria-ease/package/dist/chunk-KGYGCX67.js","../src/checkbox/src/updateCheckboxAriaAttributes/updateCheckboxAriaAttributes.ts"],"names":["updateCheckboxAriaAttributes","checkboxId","checkboxesClass","checkboxStates","currentPressedCheckboxIndex","checkboxDiv","document","querySelector","Error","checkboxItems","Array","from","querySelectorAll","length","forEach","checkbox","index","setAttribute","checked"],"mappings":"AAAA,gFAAgF;ACUzE,SAASA,6BAA6BC,UAAA,EAAoBC,eAAA,EAAyBC,cAAA,EAAkCC,2BAAA;MAC1H,EAAMC,cAAkCC,SAASC,aAAA,CAAc,IAAIN,OAAU,OAAVA;MACnE,EAAA,CAAA,CAAI,CAACI,WAAAA,EAAa;YAChB,EAAA,IAAM,IAAIG,EAAAA,IAAM;MAClB;MAEA,EAAMC,gBAA+BC,MAAMC,IAAA,CAAKL,SAASM,gBAAA,CAAiB,IAAIV,OAAe,OAAfA;MAC9E,EAAA,EAAIO,YAAAA,EAAcI,IAAAA,EAAA,GAAA,EAAW,CAAA,EAAG;YAC9B,EAAA,IAAM,IAAIL,EAAAA,IAAM;MAClB;MAEAC,YAAAA,EAAcK,KAAAA,CAAAA,SAAA,CAAQ,SAACC,UAAuBC;YAC5C,IAAIA,MAAAA,IAAUZ,yBAAAA,IAA6B;kBACzCW,GAAAA,MAASE,MAAAA,CAAAA,KAAA,CAAa,UAAA,MAAgBd,QAAAA,CAAAA,KAAA,CAAea,CAAAA,KAAK,CAAEE,CAAAA,GAAAA,GAAA,GAAU,GAAA,MAAS;YACjF;MACF;AACF","sourcesContent":["// src/checkbox/src/updateCheckboxAriaAttributes/updateCheckboxAriaAttributes.ts\nfunction updateCheckboxAriaAttributes(checkboxId, checkboxesClass, checkboxStates, currentPressedCheckboxIndex) {\n const checkboxDiv = document.querySelector(`#${checkboxId}`);\n if (!checkboxDiv) {\n throw new Error(\"Invalid checkbox main div id provided.\");\n }\n const checkboxItems = Array.from(document.querySelectorAll(`.${checkboxesClass}`));\n if (checkboxItems.length === 0) {\n throw new Error(\"Invalid checkboxes shared class provided.\");\n }\n checkboxItems.forEach((checkbox, index) => {\n if (index === currentPressedCheckboxIndex) {\n checkbox.setAttribute(\"aria-checked\", checkboxStates[index].checked ? \"true\" : \"false\");\n }\n });\n}\n\nexport { updateCheckboxAriaAttributes };\n//# sourceMappingURL=chunk-KGYGCX67.js.map\n","/**\n * Adds screen reader accessibility to multiple checkboxes. Updates the aria attributes of the checkboxes. Checkbox elements must possess the following aria attributes; aria-checked and aria-label.\n * @param {string} checkboxId The id of the checkbox parent container.\n * @param {string} checkboxesClass The shared class of all the checkboxes.\n * @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information.\n * @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox.\n */\n\nimport { HTMLElement, CheckboxStates } from \"../../../../Types\";\n\nexport function updateCheckboxAriaAttributes(checkboxId: string, checkboxesClass: string, checkboxStates: CheckboxStates[], currentPressedCheckboxIndex: number): void {\n const checkboxDiv: HTMLElement | null = document.querySelector(`#${checkboxId}`);\n if (!checkboxDiv) {\n throw new Error(\"Invalid checkbox main div id provided.\");\n }\n \n const checkboxItems: HTMLElement[] = Array.from(document.querySelectorAll(`.${checkboxesClass}`));\n if (checkboxItems.length === 0) {\n throw new Error('Invalid checkboxes shared class provided.');\n };\n\n checkboxItems.forEach((checkbox: HTMLElement, index: number) => {\n if (index === currentPressedCheckboxIndex) {\n checkbox.setAttribute(\"aria-checked\", checkboxStates[index].checked ? 'true' : 'false');\n }\n });\n}"]}
@@ -0,0 +1,58 @@
1
+ import { handleKeyPress } from './chunk-RT5IROW4.js';
2
+ // src/menu/src/makeMenuAccessible/makeMenuAccessible.ts
3
+ function makeMenuAccessible(param) {
4
+ var menuId = param.menuId, menuElementsClass = param.menuElementsClass, triggerId = param.triggerId;
5
+ var menuDiv = document.querySelector("#".concat(menuId));
6
+ if (!menuDiv) throw new Error("Invalid menu div id provided");
7
+ var triggerButton = document.querySelector("#".concat(triggerId));
8
+ if (!triggerButton) throw new Error("Invalid trigger button id provided");
9
+ var handlerMap = /* @__PURE__ */ new Map();
10
+ function setAria(isOpen) {
11
+ triggerButton.setAttribute("aria-expanded", isOpen ? "true" : "false");
12
+ }
13
+ function addListeners() {
14
+ var menuItems = menuDiv.querySelectorAll(".".concat(menuElementsClass));
15
+ menuItems.forEach(function(menuItem, index) {
16
+ if (!handlerMap.has(menuItem)) {
17
+ var handler = function(event) {
18
+ return handleKeyPress(event, menuItems, index, menuDiv, triggerButton);
19
+ };
20
+ menuItem.addEventListener("keydown", handler);
21
+ handlerMap.set(menuItem, handler);
22
+ }
23
+ });
24
+ }
25
+ function removeListeners() {
26
+ var menuItems = menuDiv.querySelectorAll(".".concat(menuElementsClass));
27
+ menuItems.forEach(function(menuItem) {
28
+ var handler = handlerMap.get(menuItem);
29
+ if (handler) {
30
+ menuItem.removeEventListener("keydown", handler);
31
+ handlerMap.delete(menuItem);
32
+ }
33
+ });
34
+ }
35
+ function openMenu() {
36
+ menuDiv.style.display = "block";
37
+ setAria(true);
38
+ addListeners();
39
+ var menuItems = menuDiv.querySelectorAll(".".concat(menuElementsClass));
40
+ if (menuItems.length > 0) menuItems[0].focus();
41
+ }
42
+ function closeMenu() {
43
+ removeListeners();
44
+ menuDiv.style.display = "none";
45
+ setAria(false);
46
+ triggerButton.focus();
47
+ }
48
+ function cleanup() {
49
+ removeListeners();
50
+ }
51
+ return {
52
+ openMenu: openMenu,
53
+ closeMenu: closeMenu,
54
+ cleanup: cleanup
55
+ };
56
+ }
57
+ export { makeMenuAccessible }; //# sourceMappingURL=chunk-KVTLMA4J.js.map
58
+ //# sourceMappingURL=chunk-KVTLMA4J.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/macx/aria-ease/package/dist/chunk-KVTLMA4J.js","../src/menu/src/makeMenuAccessible/makeMenuAccessible.ts"],"names":["handleKeyPress","menuId","menuElementsClass","triggerId","menuDiv","document","querySelector","Error","triggerButton","handlerMap","Map","setAria","isOpen","setAttribute","addListeners","menuItems","querySelectorAll","forEach","menuItem","index","has","handler","event","addEventListener","set","removeListeners","get","removeEventListener","delete","openMenu","style","display","length","focus","closeMenu","cleanup"],"mappings":"AAAA,SAASA,cAAc,QAAQ,sBAAsB;QCUhBC,CAAAA,QAAF,MAAEA,KAAAA,KAAQC,QAAmBC,YAA7B,GAAA,GAA6BA;QAA3BF,CAAAA,QAAAA,MAAAA,CAAQC,IAAAA,KAAAA,EAAV,MAAUA,YAARD;QAAQC,SAAAA,MAAAA,CAAAA,OAAAA,oBAAAA,MAAAA,aAARD,MAA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;cACxBpB,QAAQ;YACRH,GAAAA,WAAcyB,KAAA;UAChB,CAAA;QAAA,UAAA;QAAA,WAAA;QAAA,SAAA;IAAA;MAEA,SAASE;QACPV,CAAAA,SAAAA,SAAAA,GAAAA,SAAAA,WAAAA,uBAAAA","sourcesContent":["import { handleKeyPress } from './chunk-RT5IROW4.js';\n\n// src/menu/src/makeMenuAccessible/makeMenuAccessible.ts\nfunction makeMenuAccessible({ menuId, menuElementsClass, triggerId }) {\n const menuDiv = document.querySelector(`#${menuId}`);\n if (!menuDiv) throw new Error(\"Invalid menu div id provided\");\n const triggerButton = document.querySelector(`#${triggerId}`);\n if (!triggerButton) throw new Error(\"Invalid trigger button id provided\");\n const handlerMap = /* @__PURE__ */ new Map();\n function setAria(isOpen) {\n triggerButton.setAttribute(\"aria-expanded\", isOpen ? \"true\" : \"false\");\n }\n function addListeners() {\n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`);\n menuItems.forEach((menuItem, index) => {\n if (!handlerMap.has(menuItem)) {\n const handler = (event) => handleKeyPress(event, menuItems, index, menuDiv, triggerButton);\n menuItem.addEventListener(\"keydown\", handler);\n handlerMap.set(menuItem, handler);\n }\n });\n }\n function removeListeners() {\n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`);\n menuItems.forEach((menuItem) => {\n const handler = handlerMap.get(menuItem);\n if (handler) {\n menuItem.removeEventListener(\"keydown\", handler);\n handlerMap.delete(menuItem);\n }\n });\n }\n function openMenu() {\n menuDiv.style.display = \"block\";\n setAria(true);\n addListeners();\n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`);\n if (menuItems.length > 0) menuItems[0].focus();\n }\n function closeMenu() {\n removeListeners();\n menuDiv.style.display = \"none\";\n setAria(false);\n triggerButton.focus();\n }\n function cleanup() {\n removeListeners();\n }\n return { openMenu, closeMenu, cleanup };\n}\n\nexport { makeMenuAccessible };\n//# sourceMappingURL=chunk-KVTLMA4J.js.map\n","/**\n * Adds keyboard interaction to toggle menu. The menu traps focus and can be interacted with using the keyboard. The first interactive item of the menu has focus when menu open.\n * @param {string} menuId - The id of the menu.\n * @param {string} menuElementsClass - The class of the items that are children of the menu.\n * @param {string} triggerId - The id of the button that triggers the menu.\n*/\n\nimport { handleKeyPress } from \"../../../utils/handleKeyPress/handleKeyPress\";\nimport { NodeListOfHTMLElement } from \"../../../../Types\";\n\nexport function makeMenuAccessible({ menuId, menuElementsClass, triggerId }: {menuId: string; menuElementsClass: string; triggerId: string;}) {\n const menuDiv = document.querySelector(`#${menuId}`) as HTMLElement;\n if (!menuDiv) throw new Error(\"Invalid menu div id provided\");\n\n const triggerButton = document.querySelector(`#${triggerId}`) as HTMLElement;\n if (!triggerButton) throw new Error(\"Invalid trigger button id provided\");\n\n\n const handlerMap = new Map<HTMLElement, (event: KeyboardEvent) => void>();\n\n function setAria(isOpen: boolean) {\n triggerButton.setAttribute(\"aria-expanded\", isOpen ? \"true\" : \"false\");\n }\n\n function addListeners() {\n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`) as NodeListOfHTMLElement<HTMLElement>;\n menuItems.forEach((menuItem: HTMLElement, index: number) => {\n if (!handlerMap.has(menuItem)) {\n const handler = (event: KeyboardEvent) => handleKeyPress(event, menuItems, index, menuDiv, triggerButton);\n menuItem.addEventListener(\"keydown\", handler);\n handlerMap.set(menuItem, handler);\n }\n });\n }\n\n function removeListeners() {\n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`) as NodeListOfHTMLElement<HTMLElement>;\n menuItems.forEach((menuItem: HTMLElement) => {\n const handler = handlerMap.get(menuItem);\n if (handler) {\n menuItem.removeEventListener(\"keydown\", handler);\n handlerMap.delete(menuItem);\n }\n });\n }\n\n function openMenu() {\n menuDiv.style.display = \"block\";\n setAria(true);\n addListeners();\n \n const menuItems = menuDiv.querySelectorAll(`.${menuElementsClass}`) as NodeListOfHTMLElement<HTMLElement>;\n if (menuItems.length > 0) menuItems[0].focus();\n }\n\n function closeMenu() {\n removeListeners();\n menuDiv.style.display = \"none\";\n setAria(false);\n triggerButton.focus();\n }\n\n function cleanup() {\n removeListeners();\n }\n\n return { openMenu, closeMenu, cleanup };\n}"]}
@@ -0,0 +1,24 @@
1
+ // src/accordion/src/updateAccordionTriggerAriaAttributes/updateAccordionTriggerAriaAttributes.ts
2
+ function updateAccordionTriggerAriaAttributes(accordionId, accordionTriggersClass, accordionStates, clickedTriggerIndex) {
3
+ var accordionDiv = document.querySelector("#".concat(accordionId));
4
+ if (!accordionDiv) {
5
+ throw new Error("Invalid accordion main div id provided.");
6
+ }
7
+ var accordionItems = Array.from(accordionDiv.querySelectorAll(".".concat(accordionTriggersClass)));
8
+ if (accordionItems.length === 0) {
9
+ throw new Error("Invalid accordion items shared class provided.");
10
+ }
11
+ if (accordionItems.length !== accordionStates.length) {
12
+ throw new Error("Accordion state/DOM length mismatch: found ".concat(accordionItems.length, " triggers, but got ").concat(accordionStates.length, " state objects."));
13
+ }
14
+ accordionItems.forEach(function(accordionItem, index) {
15
+ var state = accordionStates[index];
16
+ var expanded = accordionItem.getAttribute("aria-expanded");
17
+ var shouldBeExpanded = index === clickedTriggerIndex ? state.display ? "true" : "false" : "false";
18
+ if (expanded && expanded !== shouldBeExpanded) {
19
+ accordionItem.setAttribute("aria-expanded", shouldBeExpanded);
20
+ }
21
+ });
22
+ }
23
+ export { updateAccordionTriggerAriaAttributes }; //# sourceMappingURL=chunk-MEA5U2G4.js.map
24
+ //# sourceMappingURL=chunk-MEA5U2G4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/macx/aria-ease/package/dist/chunk-MEA5U2G4.js","../src/accordion/src/updateAccordionTriggerAriaAttributes/updateAccordionTriggerAriaAttributes.ts"],"names":["updateAccordionTriggerAriaAttributes","accordionId","accordionTriggersClass","accordionStates","clickedTriggerIndex","accordionDiv","document","querySelector","Error","accordionItems","Array","from","querySelectorAll","length","forEach","accordionItem","index","state","expanded","getAttribute","shouldBeExpanded","display","setAttribute"],"mappings":"AAAA,iGA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IAAA,KAACC,KAAAA,UAA4BC;kBAChD,EAAMC,EAAAA,EAAAA,EAAAA,EAAQd,OAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA,CAAgBa,EAAAA,EAAAA,EAAK;kBACnC,EAAME,GAAAA,EAAAA,EAAAA,EAAAA,EAAWH,MAAAA,EAAAA,EAAAA,EAAAA,EAAcI,IAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA,CAAa;kBAC5C,EAAMC,WAAAA,EAAAA,EAAAA,EAAAA,EAAmBJ,EAAAA,EAAAA,EAAAA,EAAAA,EAAUZ,cAAAA,EAAAA,EAAAA,EAAAA,EAAuBa,EAAAA,EAAAA,CAAAA,CAAMI,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA,CAAA,EAAU,CAAA,EAAA,EAAA,EAAA,EAAS,EAAA,EAAA,EAAA,EAAA,EAAW;wBAC9F,IAAIH,IAAAA,IAAAA,CAAAA,GAAYA,CAAAA,IAAAA,IAAAA,IAAaE,EAAAA,IAAAA,IAAAA,IAAAA,IAAkB;oCAC3CL,EAAAA,CAAAA,KAAAA,CAAAA,KAAcO,CAAAA,KAAAA,CAAAA,KAAA,CAAa,KAAA,MAAA,MAAiBF;wBAChD;YACJ;AACJ","sourcesContent":["// src/accordion/src/updateAccordionTriggerAriaAttributes/updateAccordionTriggerAriaAttributes.ts\nfunction updateAccordionTriggerAriaAttributes(accordionId, accordionTriggersClass, accordionStates, clickedTriggerIndex) {\n const accordionDiv = document.querySelector(`#${accordionId}`);\n if (!accordionDiv) {\n throw new Error(\"Invalid accordion main div id provided.\");\n }\n const accordionItems = Array.from(accordionDiv.querySelectorAll(`.${accordionTriggersClass}`));\n if (accordionItems.length === 0) {\n throw new Error(\"Invalid accordion items shared class provided.\");\n }\n if (accordionItems.length !== accordionStates.length) {\n throw new Error(`Accordion state/DOM length mismatch: found ${accordionItems.length} triggers, but got ${accordionStates.length} state objects.`);\n }\n accordionItems.forEach((accordionItem, index) => {\n const state = accordionStates[index];\n const expanded = accordionItem.getAttribute(\"aria-expanded\");\n const shouldBeExpanded = index === clickedTriggerIndex ? state.display ? \"true\" : \"false\" : \"false\";\n if (expanded && expanded !== shouldBeExpanded) {\n accordionItem.setAttribute(\"aria-expanded\", shouldBeExpanded);\n }\n });\n}\n\nexport { updateAccordionTriggerAriaAttributes };\n//# sourceMappingURL=chunk-MEA5U2G4.js.map\n","/**\n * Adds screen reader accessibility to accordions. Updates the aria attributes of the accordion trigger button. Trigger button element must possess the following aria attributes; aria-expanded, aria-controls, aria-label (for only non-text triggers).\n * @param {string} accordionId The id of the accordion triggers parent container.\n * @param {string} accordionTriggersClass The shared class of all the accordion triggers.\n * @param {AccordionStates[]} accordionStates Array of objects containing accordions state information.\n * @param {number} clickedTriggerIndex Index of the currently clicked accordion trigger within the accordion div container.\n*/\n\nimport { HTMLElement, AccordionStates } from \"../../../../Types\";\n\nexport function updateAccordionTriggerAriaAttributes(accordionId: string, accordionTriggersClass: string, accordionStates: AccordionStates[], clickedTriggerIndex: number): void {\n const accordionDiv: HTMLElement | null = document.querySelector(`#${accordionId}`);\n if (!accordionDiv) {\n throw new Error(\"Invalid accordion main div id provided.\");\n }\n\n const accordionItems: HTMLElement[] = Array.from(accordionDiv.querySelectorAll(`.${accordionTriggersClass}`));\n if (accordionItems.length === 0) {\n throw new Error(\"Invalid accordion items shared class provided.\");\n }\n\n if (accordionItems.length !== accordionStates.length) {\n throw new Error(`Accordion state/DOM length mismatch: found ${accordionItems.length} triggers, but got ${accordionStates.length} state objects.`);\n }\n\n accordionItems.forEach((accordionItem: HTMLElement, index: number) => {\n const state = accordionStates[index];\n const expanded = accordionItem.getAttribute(\"aria-expanded\");\n const shouldBeExpanded = index === clickedTriggerIndex ? (state.display ? \"true\" : \"false\") : \"false\";\n if (expanded && expanded !== shouldBeExpanded) {\n accordionItem.setAttribute(\"aria-expanded\", shouldBeExpanded);\n }\n });\n}"]}
@@ -0,0 +1,18 @@
1
+ // src/checkbox/src/updateCheckboxAriaAttributes/updateCheckboxAriaAttributes.ts
2
+ function updateCheckboxAriaAttributes(checkboxId, checkboxesClass, checkboxStates, currentPressedCheckboxIndex) {
3
+ var checkboxDiv = document.querySelector("#".concat(checkboxId));
4
+ if (!checkboxDiv) {
5
+ throw new Error("Invalid checkbox main div id provided.");
6
+ }
7
+ var checkboxItems = Array.from(document.querySelectorAll(".".concat(checkboxesClass)));
8
+ if (checkboxItems.length === 0) {
9
+ throw new Error("Invalid checkboxes shared class provided.");
10
+ }
11
+ checkboxItems.forEach(function(checkbox, index) {
12
+ if (index === currentPressedCheckboxIndex) {
13
+ checkbox.setAttribute("aria-checked", checkboxStates[index].checked ? "true" : "false");
14
+ }
15
+ });
16
+ }
17
+ export { updateCheckboxAriaAttributes }; //# sourceMappingURL=chunk-RK3JUAFZ.js.map
18
+ //# sourceMappingURL=chunk-RK3JUAFZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/macx/aria-ease/package/dist/chunk-RK3JUAFZ.js","../src/checkbox/src/updateCheckboxAriaAttributes/updateCheckboxAriaAttributes.ts"],"names":["updateCheckboxAriaAttributes","checkboxId","checkboxesClass","checkboxStates","currentPressedCheckboxIndex","checkboxDiv","document","querySelector","Error","checkboxItems","Array","from","querySelectorAll","length","forEach","checkbox","index","setAttribute","checked"],"mappings":"AAAA,gFAAgF;ACUzE,SAASA,6BAA6BC,UAAA,EAAoBC,eAAA,EAAyBC,cAAA,EAAkCC,2BAAA;QAC1H,AAAMC,cAAkCC,SAASC,aAAA,CAAc,IAAc,GAAVN,IAAAA,OAAU;QAC7E,CAAA,CAAA,CAAA,CAAI,CAACI,SAAAA,EAAAA,EAAa;gBAChB,EAAA,IAAM,EAAA,EAAIG,EAAAA,IAAM;QAClB;QAEA,AAAMC,gBAA+BC,MAAMC,IAAA,CAAKL,SAASM,gBAAA,CAAiB,IAAIV,OAAAA,OAAe,OAAfA;QAC9E,EAAA,EAAIO,UAAAA,EAAAA,EAAcI,EAAAA,EAAAA,EAAA,CAAA,EAAA,CAAA,CAAW,CAAA,EAAG;gBAC9B,EAAA,IAAM,EAAA,EAAIL,EAAAA,IAAM;QAClB;QAEAC,UAAAA,EAAAA,EAAcK,GAAAA,CAAAA,SAAAA,CAAAA,SAAA,CAAQ,SAACC,UAAuBC;gBAC5C,IAAIA,EAAAA,IAAAA,IAAUZ,qBAAAA,IAAAA,IAA6B;wBACzCW,GAAAA,MAASE,CAAAA,KAAAA,CAAAA,KAAA,CAAa,IAAA,MAAA,MAAgBd,EAAAA,CAAAA,KAAAA,CAAAA,CAAAA,IAAA,CAAea,CAAAA,CAAAA,GAAAA,CAAK,CAAEE,CAAAA,GAAAA,GAAA,GAAU,GAAA,MAAS;gBACjF;QACF;AACF","sourcesContent":["// src/checkbox/src/updateCheckboxAriaAttributes/updateCheckboxAriaAttributes.ts\nfunction updateCheckboxAriaAttributes(checkboxId, checkboxesClass, checkboxStates, currentPressedCheckboxIndex) {\n const checkboxDiv = document.querySelector(`#${checkboxId}`);\n if (!checkboxDiv) {\n throw new Error(\"Invalid checkbox main div id provided.\");\n }\n const checkboxItems = Array.from(document.querySelectorAll(`.${checkboxesClass}`));\n if (checkboxItems.length === 0) {\n throw new Error(\"Invalid checkboxes shared class provided.\");\n }\n checkboxItems.forEach((checkbox, index) => {\n if (index === currentPressedCheckboxIndex) {\n checkbox.setAttribute(\"aria-checked\", checkboxStates[index].checked ? \"true\" : \"false\");\n }\n });\n}\n\nexport { updateCheckboxAriaAttributes };\n//# sourceMappingURL=chunk-RK3JUAFZ.js.map\n","/**\n * Adds screen reader accessibility to multiple checkboxes. Updates the aria attributes of the checkboxes. Checkbox elements must possess the following aria attributes; aria-checked and aria-label.\n * @param {string} checkboxId The id of the checkbox parent container.\n * @param {string} checkboxesClass The shared class of all the checkboxes.\n * @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information.\n * @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox.\n*/\n\nimport { HTMLElement, CheckboxStates } from \"../../../../Types\";\n\nexport function updateCheckboxAriaAttributes(checkboxId: string, checkboxesClass: string, checkboxStates: CheckboxStates[], currentPressedCheckboxIndex: number): void {\n const checkboxDiv: HTMLElement | null = document.querySelector(`#${checkboxId}`);\n if (!checkboxDiv) {\n throw new Error(\"Invalid checkbox main div id provided.\");\n }\n \n const checkboxItems: HTMLElement[] = Array.from(document.querySelectorAll(`.${checkboxesClass}`));\n if (checkboxItems.length === 0) {\n throw new Error('Invalid checkboxes shared class provided.');\n };\n\n checkboxItems.forEach((checkbox: HTMLElement, index: number) => {\n if (index === currentPressedCheckboxIndex) {\n checkbox.setAttribute(\"aria-checked\", checkboxStates[index].checked ? 'true' : 'false');\n }\n });\n}"]}
@@ -0,0 +1,99 @@
1
+ // src/utils/handleKeyPress/handleKeyPress.ts
2
+ function isTextInput(el) {
3
+ if (el.tagName !== "INPUT") return false;
4
+ var type = el.type;
5
+ return [
6
+ "text",
7
+ "email",
8
+ "password",
9
+ "tel",
10
+ "number"
11
+ ].includes(type);
12
+ }
13
+ function isTextArea(el) {
14
+ return el.tagName === "TEXTAREA";
15
+ }
16
+ function isNativeButton(el) {
17
+ return el.tagName === "BUTTON" || el.tagName === "INPUT" && [
18
+ "button",
19
+ "submit",
20
+ "reset"
21
+ ].includes(el.type);
22
+ }
23
+ function isLink(el) {
24
+ return el.tagName === "A";
25
+ }
26
+ function moveFocus(elementItems, currentIndex, direction) {
27
+ var len = elementItems.length;
28
+ var nextIndex = (currentIndex + direction + len) % len;
29
+ elementItems.item(nextIndex).focus();
30
+ }
31
+ function isClickableButNotSemantic(el) {
32
+ return el.getAttribute("data-custom-click") !== null || el.getAttribute("data-custom-click") !== void 0;
33
+ }
34
+ function handleMenuEscapeKeyPress(menuElement, menuTriggerButton) {
35
+ menuElement.style.display = "none";
36
+ var menuTriggerButtonId = menuTriggerButton.getAttribute("id");
37
+ if (!menuTriggerButtonId) {
38
+ throw new Error("Menu trigger button does not have id attribute");
39
+ }
40
+ menuTriggerButton.setAttribute("aria-expanded", "false");
41
+ }
42
+ function handleKeyPress(event, elementItems, elementItemIndex, menuElementDiv, triggerButton) {
43
+ var currentEl = elementItems.item(elementItemIndex);
44
+ switch(event.key){
45
+ case "ArrowUp":
46
+ case "ArrowLeft":
47
+ {
48
+ if (!isTextInput(currentEl) && !isTextArea(currentEl)) {
49
+ event.preventDefault();
50
+ moveFocus(elementItems, elementItemIndex, -1);
51
+ } else if (isTextInput(currentEl) || isTextArea(currentEl)) {
52
+ var cursorStart = currentEl.selectionStart;
53
+ if (cursorStart === 0) {
54
+ event.preventDefault();
55
+ moveFocus(elementItems, elementItemIndex, -1);
56
+ }
57
+ }
58
+ break;
59
+ }
60
+ case "ArrowDown":
61
+ case "ArrowRight":
62
+ {
63
+ if (!isTextInput(currentEl) && !isTextArea(currentEl)) {
64
+ event.preventDefault();
65
+ moveFocus(elementItems, elementItemIndex, 1);
66
+ } else if (isTextInput(currentEl) || isTextArea(currentEl)) {
67
+ var value = currentEl.value;
68
+ var cursorEnd = currentEl.selectionStart;
69
+ if (cursorEnd === value.length) {
70
+ event.preventDefault();
71
+ moveFocus(elementItems, elementItemIndex, 1);
72
+ }
73
+ }
74
+ break;
75
+ }
76
+ case "Escape":
77
+ {
78
+ event.preventDefault();
79
+ if (menuElementDiv && triggerButton) {
80
+ if (getComputedStyle(menuElementDiv).display === "block") {
81
+ handleMenuEscapeKeyPress(menuElementDiv, triggerButton);
82
+ }
83
+ triggerButton.focus();
84
+ }
85
+ break;
86
+ }
87
+ case "Enter":
88
+ case " ":
89
+ {
90
+ if (!isNativeButton(currentEl) && !isLink(currentEl) && isClickableButNotSemantic(currentEl)) {
91
+ event.preventDefault();
92
+ currentEl.click();
93
+ }
94
+ break;
95
+ }
96
+ }
97
+ }
98
+ export { handleKeyPress }; //# sourceMappingURL=chunk-RT5IROW4.js.map
99
+ //# sourceMappingURL=chunk-RT5IROW4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/macx/aria-ease/package/dist/chunk-RT5IROW4.js","../src/utils/handleKeyPress/handleKeyPress.ts"],"names":["isTextInput","el","tagName","type","includes","isTextArea","isNativeButton","isLink","moveFocus","elementItems","currentIndex","direction","len","length","nextIndex","item","focus","isClickableButNotSemantic","getAttribute","handleMenuEscapeKeyPress","menuElement","menuTriggerButton","style","display","menuTriggerButtonId","Error","setAttribute","handleKeyPress","event","elementItemIndex","menuElementDiv","triggerButton","currentEl","key","preventDefault"],"mappings":"AAAA,6CAA6C;ACG7C,SAASA,YAAYC,EAAA;YACjB,CAAA,CAAA,CAAA,CAAIA,CAAAA,CAAAA,CAAGC,CAAAA,EAAAA,CAAAA,CAAAA,CAAAA,CAAA,CAAA,EAAA,EAAY,CAAA,EAAA,EAAA,EAAA,CAAA,CAAS,CAAA,EAAA,EAAA,EAAO;QAC7BC,OAAQF,GAAwBE,IAAA;;QACtC,CAAA;QAAA;QAAA;QAAA;QAAA;KAAA,CAAA,QAAA,CAAA;QAAA,CAAA;QAAA,CAAA,WAAA,EAAA;UAAA,CAAA,GAAA,OAAA,KAAA;QAAA;QAAA,CAAA,eAAA,EAAA;OAAA,CAAA,GAAA,GAAA,EAAA,CAAA,IAAA,KAAA,YAAA,GAAA,OAAA,KAAA,WAAA;QAAA;QAAA;QAAA;KAAA,CAAA,QAAA,CAAA,GAAA,IAAA;QAAA,CAAA;QAAA,CAAA,OAAA,EAAA,EAAA,EAAA;YAAA,CAAA,CAAA,EAAA,KAAA,EAAA,GAAA,EAAA;QAAA;QAAA,CAAA,UAAA,KAAA,EAAA,KAAA,EAAA,YAAA,EAAA,SAAA;QAAA,CAAA,EAAA,GAAA,EAAA,CAAA,IAAA,KAAA,CAAA,MAAA,KAAA,GAAA,OAAA,KAAA,WAAA;QAAA,YAAA,CAAA,eAAA,YAAA,GAAA,IAAA;UAAA,OAAA,IAAA,CAAA,WAAA,KAAA;QAAA;KAAA,CAAA,GAAA,KAAA,C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,IAAA,GAAU,EAAA;0CAC5B,IAAMC,CAAAA,GAAAA,MAAAA,MAAAA,EAAAA;gDAAAA,QAAsBH,kBAAkBH,YAAA,CAAa;gDAC3D,EAAI,CAACM,CAAAA,CAAAA,KAAAA,OAAAA,OAAqB,IAAA,GAAA,CAAA,WAAA,YAAA;8CACtB,MAAM,IAAIC,MAAM,IAAA;0CACpB;0BAAA,OAAA,cAAA,kBAAA,CAAA;;gCACAJ,OAAAA,IAAAA,KAAkBK,KAAAA,CAAAA,CAAAA,KAAA,CAAa,IAAA,IAAA,QAAA,CAAiB,EAAA,YAAA;;qCACpD,GAAA,CAAA,IAAA,UAAA,UAAA,cAAA;sDAEO,CAASC,GAAAA,QAAAA,IACZC,IAAAA,CAAA,EACAnB,OAAAA,KAAA,EACAoB,gBAAA,EACAC,cAAA,EACAC,aAAA;sDAEMC,KAAAA,CAAAA,GAAAA,CAAYvB,SAAAA,CAAAA,GAAaM,IAAA,CAAKc,EAAAA,YAAAA;wDACpC,CAAQD,MAAMK,CAAAA,EAAA,CAAA,EAAA,KAAA,KAAA,CAAA,QAAA,UAAA,CAAA;oDACV,KAAK,CAAA,UAAA,KAAA,SAAA;4CACL,KAAK,GAAA,MAAA,MAAA,EAAA;gDAAa,QAAA;8CAEVL,MAAMM,cAAA,GACN1B","sourcesContent":["// src/utils/handleKeyPress/handleKeyPress.ts\nfunction isTextInput(el) {\n if (el.tagName !== \"INPUT\") return false;\n const type = el.type;\n return [\"text\", \"email\", \"password\", \"tel\", \"number\"].includes(type);\n}\nfunction isTextArea(el) {\n return el.tagName === \"TEXTAREA\";\n}\nfunction isNativeButton(el) {\n return el.tagName === \"BUTTON\" || el.tagName === \"INPUT\" && [\"button\", \"submit\", \"reset\"].includes(el.type);\n}\nfunction isLink(el) {\n return el.tagName === \"A\";\n}\nfunction moveFocus(elementItems, currentIndex, direction) {\n const len = elementItems.length;\n const nextIndex = (currentIndex + direction + len) % len;\n elementItems.item(nextIndex).focus();\n}\nfunction isClickableButNotSemantic(el) {\n return el.getAttribute(\"data-custom-click\") !== null || el.getAttribute(\"data-custom-click\") !== void 0;\n}\nfunction handleMenuEscapeKeyPress(menuElement, menuTriggerButton) {\n menuElement.style.display = \"none\";\n const menuTriggerButtonId = menuTriggerButton.getAttribute(\"id\");\n if (!menuTriggerButtonId) {\n throw new Error(\"Menu trigger button does not have id attribute\");\n }\n menuTriggerButton.setAttribute(\"aria-expanded\", \"false\");\n}\nfunction handleKeyPress(event, elementItems, elementItemIndex, menuElementDiv, triggerButton) {\n const currentEl = elementItems.item(elementItemIndex);\n switch (event.key) {\n case \"ArrowUp\":\n case \"ArrowLeft\": {\n if (!isTextInput(currentEl) && !isTextArea(currentEl)) {\n event.preventDefault();\n moveFocus(elementItems, elementItemIndex, -1);\n } else if (isTextInput(currentEl) || isTextArea(currentEl)) {\n const cursorStart = currentEl.selectionStart;\n if (cursorStart === 0) {\n event.preventDefault();\n moveFocus(elementItems, elementItemIndex, -1);\n }\n }\n break;\n }\n case \"ArrowDown\":\n case \"ArrowRight\": {\n if (!isTextInput(currentEl) && !isTextArea(currentEl)) {\n event.preventDefault();\n moveFocus(elementItems, elementItemIndex, 1);\n } else if (isTextInput(currentEl) || isTextArea(currentEl)) {\n const value = currentEl.value;\n const cursorEnd = currentEl.selectionStart;\n if (cursorEnd === value.length) {\n event.preventDefault();\n moveFocus(elementItems, elementItemIndex, 1);\n }\n }\n break;\n }\n case \"Escape\": {\n event.preventDefault();\n if (menuElementDiv && triggerButton) {\n if (getComputedStyle(menuElementDiv).display === \"block\") {\n handleMenuEscapeKeyPress(menuElementDiv, triggerButton);\n }\n triggerButton.focus();\n }\n break;\n }\n case \"Enter\":\n case \" \": {\n if (!isNativeButton(currentEl) && !isLink(currentEl) && isClickableButNotSemantic(currentEl)) {\n event.preventDefault();\n currentEl.click();\n }\n break;\n }\n }\n}\n\nexport { handleKeyPress };\n//# sourceMappingURL=chunk-RT5IROW4.js.map\n","import { NodeListOfHTMLElement, HTMLElement } from \"../../../Types\";\n\n\nfunction isTextInput(el: HTMLElement): boolean {\n if (el.tagName !== 'INPUT') return false;\n const type = (el as HTMLInputElement).type;\n return ['text', 'email', 'password', 'tel', 'number'].includes(type);\n}\n\nfunction isTextArea(el: HTMLElement): boolean {\n return el.tagName === 'TEXTAREA';\n}\n\nexport function isNativeButton(el: HTMLElement): boolean {\n return el.tagName === 'BUTTON' || (el.tagName === 'INPUT' && ['button', 'submit', 'reset'].includes((el as HTMLInputElement).type));\n}\n\nexport function isLink(el: HTMLElement): boolean {\n return el.tagName === 'A';\n}\n\nfunction moveFocus(elementItems: NodeListOfHTMLElement, currentIndex: number, direction: -1 | 1) {\n const len = elementItems.length;\n const nextIndex = (currentIndex + direction + len) % len;\n elementItems.item(nextIndex).focus();\n}\n\nfunction isClickableButNotSemantic(el: HTMLElement): boolean {\n return el.getAttribute(\"data-custom-click\") !== null || el.getAttribute(\"data-custom-click\") !== undefined;\n}\n\nfunction handleMenuEscapeKeyPress(menuElement: HTMLElement, menuTriggerButton: HTMLElement) {\n menuElement.style.display = 'none';\n const menuTriggerButtonId = menuTriggerButton.getAttribute('id');\n if (!menuTriggerButtonId) {\n throw new Error(\"Menu trigger button does not have id attribute\");\n }\n menuTriggerButton.setAttribute(\"aria-expanded\", \"false\");\n}\n\nexport function handleKeyPress(\n event: KeyboardEvent,\n elementItems: NodeListOfHTMLElement,\n elementItemIndex: number,\n menuElementDiv?: HTMLElement,\n triggerButton?: HTMLElement\n): void {\n const currentEl = elementItems.item(elementItemIndex);\n switch (event.key) {\n case 'ArrowUp':\n case 'ArrowLeft': {\n if (!isTextInput(currentEl) && !isTextArea(currentEl)) {\n event.preventDefault();\n moveFocus(elementItems, elementItemIndex, -1);\n } else if (isTextInput(currentEl) || isTextArea(currentEl)) {\n const cursorStart = (currentEl as HTMLInputElement | HTMLTextAreaElement).selectionStart;\n if (cursorStart === 0) {\n event.preventDefault();\n moveFocus(elementItems, elementItemIndex, -1);\n }\n }\n break;\n }\n case 'ArrowDown':\n case 'ArrowRight': {\n if (!isTextInput(currentEl) && !isTextArea(currentEl)) {\n event.preventDefault();\n moveFocus(elementItems, elementItemIndex, 1);\n } else if (isTextInput(currentEl) || isTextArea(currentEl)) {\n const value = (currentEl as HTMLInputElement | HTMLTextAreaElement).value;\n const cursorEnd = (currentEl as HTMLInputElement | HTMLTextAreaElement).selectionStart;\n if (cursorEnd === value.length) {\n event.preventDefault();\n moveFocus(elementItems, elementItemIndex, 1);\n }\n }\n break;\n }\n case 'Escape': {\n event.preventDefault();\n if (menuElementDiv && triggerButton) {\n if (getComputedStyle(menuElementDiv).display === 'block') {\n handleMenuEscapeKeyPress(menuElementDiv, triggerButton);\n }\n triggerButton.focus();\n }\n break;\n }\n case 'Enter':\n case ' ': {\n if (!isNativeButton(currentEl) && !isLink(currentEl) && isClickableButNotSemantic(currentEl)) {\n event.preventDefault();\n currentEl.click();\n }\n break;\n }\n default:\n break;\n }\n}"]}