From f4726c28160e2be164505e9b86525e78eb7308f4 Mon Sep 17 00:00:00 2001 From: Nick Milton Date: Wed, 25 Sep 2024 18:20:45 +0000 Subject: [PATCH] docs: correct spelling throughout entire project --- .github/CONTRIBUTING.md | 2 +- demo/main.js | 2 +- dist/accessible-menu.cjs.js | 4 +- dist/accessible-menu.es.js | 446 ++++++++++-------- dist/accessible-menu.iife.js | 4 +- dist/disclosure-menu.cjs.js | 4 +- dist/disclosure-menu.es.js | 373 ++++++++------- dist/disclosure-menu.iife.js | 4 +- dist/menubar.cjs.js | 4 +- dist/menubar.es.js | 245 +++++----- dist/menubar.iife.js | 4 +- dist/top-link-disclosure-menu.cjs.js | 4 +- dist/top-link-disclosure-menu.es.js | 393 ++++++++------- dist/top-link-disclosure-menu.iife.js | 4 +- dist/treeview.cjs.js | 4 +- dist/treeview.es.js | 427 +++++++++-------- dist/treeview.iife.js | 4 +- docs/api/base-menu-item.md | 2 +- docs/api/base-menu-toggle.md | 4 +- docs/api/base-menu.md | 46 +- docs/api/disclosure-menu.md | 14 +- docs/api/menubar.md | 12 +- docs/api/top-link-disclosure-menu.md | 14 +- docs/api/treeview.md | 18 +- docs/hover-types.md | 2 +- docs/opening-and-closing.md | 2 +- docs/optional-keyboard-support.md | 2 +- docs/quick-start.md | 2 +- docs/upgrade-guide.md | 2 +- src/_baseMenu.js | 36 +- src/disclosureMenu.js | 12 +- src/menubar.js | 8 +- src/topLinkDisclosureMenu.js | 8 +- src/treeview.js | 8 +- tests/eventHandlers/keyPress.test.js | 2 +- tests/menus/DisclosureMenu/aria.test.js | 2 +- tests/menus/DisclosureMenu/initialize.test.js | 2 +- .../menus/DisclosureMenuToggle/public.test.js | 2 +- tests/menus/Menubar/aria.test.js | 2 +- tests/menus/Menubar/initialize.test.js | 2 +- tests/menus/Menubar/keyboard.test.js | 2 +- tests/menus/MenubarItem/public.test.js | 16 +- tests/menus/MenubarToggle/public.test.js | 2 +- .../menus/TopLinkDisclosureMenu/aria.test.js | 2 +- .../menus/TopLinkDisclosureMenu/hover.test.js | 4 +- .../TopLinkDisclosureMenu/initialize.test.js | 2 +- .../public.test.js | 2 +- tests/menus/Treeview/aria.test.js | 2 +- tests/menus/Treeview/initialize.test.js | 2 +- tests/menus/Treeview/keyboard.test.js | 2 +- tests/menus/TreeviewItem/public.test.js | 16 +- tests/menus/TreeviewToggle/public.test.js | 2 +- tests/menus/_baseMenu/aria.test.js | 2 +- tests/menus/_baseMenu/initialize.test.js | 2 +- tests/menus/_baseMenuItem/public.test.js | 16 +- tests/menus/_baseMenuToggle/public.test.js | 2 +- tests/validate/isValidInstance.test.js | 2 +- tests/validate/isValidType.test.js | 2 +- 58 files changed, 1193 insertions(+), 1019 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 2ed818a1..3aa1b772 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -13,7 +13,7 @@ All code changes happen through pull requests. Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests: 1. Fork the repo and create your branch from 4.x. -2. Link your pull request to any relavent open issues. +2. Link your pull request to any relevant open issues. 3. If you've added or changed functionality update the documentation. 4. Make sure your code functions. 5. Update existing tests or write a new test to ensure your code will _continue_ to function regardless of future changes. diff --git a/demo/main.js b/demo/main.js index 96dfc2e0..e9e89d7d 100644 --- a/demo/main.js +++ b/demo/main.js @@ -47,7 +47,7 @@ const options = { hoverType: "off", hoverDelay: 250, enterDelay: -1, - leaveDelat: -1, + leaveDelay: -1, transitionClass: "transitioning", transitionDuration: 250, openDuration: -1, diff --git a/dist/accessible-menu.cjs.js b/dist/accessible-menu.cjs.js index 7b4ad67c..36c3c60e 100644 --- a/dist/accessible-menu.cjs.js +++ b/dist/accessible-menu.cjs.js @@ -1,3 +1,3 @@ -"use strict";var V=Object.defineProperty;var P=(r,e,t)=>e in r?V(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var u=(r,e,t)=>P(r,typeof e!="symbol"?e+"":e,t);function w(r,e){r===""||r.length===0||(typeof r=="string"?e.classList.add(r):e.classList.add(...r))}function S(r,e){r===""||r.length===0||(typeof r=="string"?e.classList.remove(r):e.classList.remove(...r))}function k(r,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof r)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${r.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function d(r,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==r)throw new TypeError(`${t} must be a ${r}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function O(r){try{if(typeof r!="object"){const e=typeof r;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in r)try{if(r[e]===null)throw new Error;document.querySelector(r[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${r[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function D(r){try{if(typeof r!="object"||Array.isArray(r)){const e=typeof r;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in r){const t=typeof r[e];if(t!=="string")if(Array.isArray(r[e]))r[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=r[e],O(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function R(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function U(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function j(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function F(r,e){if(d("string",{tagName:r}).status&&k(HTMLElement,e).status){const t=r.toLowerCase();let s=!0;for(const n in e)e[n].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class A{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null}){u(this,"_dom",{toggle:null,parent:null});u(this,"_elements",{controlledMenu:null,parentMenu:null});u(this,"_open",!1);u(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));u(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=n}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){d("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",n=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),n=`${s}-${n}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${n}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${n}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:n,openDuration:i}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,n!==""?(w(n,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{S(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{w(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{S(n,this.elements.controlledMenu.dom.menu)},i)})})})):(w(s,this.elements.controlledMenu.dom.menu),S(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:n,closeDuration:i}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),n!==""?(w(n,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{S(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{w(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{S(n,this.elements.controlledMenu.dom.menu)},i)})})})):(w(t,this.elements.controlledMenu.dom.menu),S(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class L{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null}){u(this,"_dom",{item:null,link:null});u(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});u(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=i,this._elements.toggle=l,this._submenu=n}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function y(r){try{const e=r.key||r.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function o(r){r.preventDefault(),r.stopPropagation()}class v{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:n="li:has(ul)",submenuToggleSelector:i="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:m=null,openClass:a="show",closeClass:p="hide",transitionClass:f="transitioning",transitionDuration:c=250,openDuration:_=-1,closeDuration:M=-1,isTopLevel:g=!0,parentMenu:b=null,hoverType:C="off",hoverDelay:T=250,enterDelay:E=-1,leaveDelay:I=-1}){u(this,"_MenuType",v);u(this,"_MenuItemType",L);u(this,"_MenuToggleType",A);u(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});u(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});u(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});u(this,"_openClass","show");u(this,"_closeClass","hide");u(this,"_transitionClass","transitioning");u(this,"_transitionDuration",250);u(this,"_openDuration",-1);u(this,"_closeDuration",-1);u(this,"_root",!0);u(this,"_currentChild",0);u(this,"_focusState","none");u(this,"_currentEvent","none");u(this,"_hoverType","off");u(this,"_hoverDelay",250);u(this,"_enterDelay",-1);u(this,"_leaveDelay",-1);u(this,"_hoverTimeout",null);u(this,"_hasOpened",!1);u(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=m,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=n,this._selectors.submenuToggles=i,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=b,this._elements.rootMenu=g?this:null,this._openClass=a||"",this._closeClass=p||"",this._transitionClass=f||"",this._transitionDuration=c,this._openDuration=_,this._closeDuration=M,this._root=g,this._hoverType=C,this._hoverDelay=T,this._enterDelay=E,this._leaveDelay=I}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: +"use strict";var P=Object.defineProperty;var R=(r,e,t)=>e in r?P(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var u=(r,e,t)=>R(r,typeof e!="symbol"?e+"":e,t);function S(r,e){r===""||r.length===0||(typeof r=="string"?e.classList.add(r):e.classList.add(...r))}function D(r,e){r===""||r.length===0||(typeof r=="string"?e.classList.remove(r):e.classList.remove(...r))}function A(r,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof r)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${r.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function c(r,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==r)throw new TypeError(`${t} must be a ${r}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function x(r){try{if(typeof r!="object"){const e=typeof r;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in r)try{if(r[e]===null)throw new Error;document.querySelector(r[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${r[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function k(r){try{if(typeof r!="object"||Array.isArray(r)){const e=typeof r;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in r){const t=typeof r[e];if(t!=="string")if(Array.isArray(r[e]))r[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=r[e],x(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function U(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function W(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function N(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function F(r,e){if(c("string",{tagName:r}).status&&A(HTMLElement,e).status){const t=r.toLowerCase();let s=!0;for(const n in e)e[n].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class L{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null}){u(this,"_dom",{toggle:null,parent:null});u(this,"_elements",{controlledMenu:null,parentMenu:null});u(this,"_open",!1);u(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));u(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=n}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){c("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",n=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),n=`${s}-${n}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${n}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${n}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:n,openDuration:i}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,n!==""?(S(n,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{D(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{S(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{D(n,this.elements.controlledMenu.dom.menu)},i)})})})):(S(s,this.elements.controlledMenu.dom.menu),D(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:n,closeDuration:i}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),n!==""?(S(n,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{D(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{S(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{D(n,this.elements.controlledMenu.dom.menu)},i)})})})):(S(t,this.elements.controlledMenu.dom.menu),D(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class O{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null}){u(this,"_dom",{item:null,link:null});u(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});u(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=i,this._elements.toggle=l,this._submenu=n}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function _(r){try{const e=r.key||r.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function o(r){r.preventDefault(),r.stopPropagation()}class w{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:n="li:has(ul)",submenuToggleSelector:i="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:m=null,openClass:a="show",closeClass:p="hide",transitionClass:f="transitioning",transitionDuration:g=250,openDuration:d=-1,closeDuration:M=-1,isTopLevel:y=!0,parentMenu:b=null,hoverType:C="off",hoverDelay:T=250,enterDelay:E=-1,leaveDelay:I=-1,prefix:v="am-"}){u(this,"_MenuType",w);u(this,"_MenuItemType",O);u(this,"_MenuToggleType",L);u(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});u(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});u(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});u(this,"_openClass","show");u(this,"_closeClass","hide");u(this,"_transitionClass","transitioning");u(this,"_transitionDuration",250);u(this,"_openDuration",-1);u(this,"_closeDuration",-1);u(this,"_root",!0);u(this,"_currentChild",0);u(this,"_focusState","none");u(this,"_currentEvent","none");u(this,"_hoverType","off");u(this,"_hoverDelay",250);u(this,"_enterDelay",-1);u(this,"_leaveDelay",-1);u(this,"_prefix","am-");u(this,"_hoverTimeout",null);u(this,"_hasOpened",!1);u(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=m,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=n,this._selectors.submenuToggles=i,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=b,this._elements.rootMenu=y?this:null,this._openClass=a||"",this._closeClass=p||"",this._transitionClass=f||"",this._transitionDuration=g,this._openDuration=d,this._closeDuration=M,this._prefix=v||"",this._root=y,this._hoverType=C,this._hoverDelay=T,this._enterDelay=E,this._leaveDelay=I}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: - ${this.errors.join(` - - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});F("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){D({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){D({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){D({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){d("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){d("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){d("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){d("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let i=0,l=!1;for(;!l&&i=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){R({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){U({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){j({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){d("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){d("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){d("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set hasOpened(e){d("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=k(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=k(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=O({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=O({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const c=D({openClass:this._openClass});c.status||(this._errors.push(c.error.message),e=!1)}if(this._closeClass!==""){const c=D({closeClass:this._closeClass});c.status||(this._errors.push(c.error.message),e=!1)}if(this._transitionClass!==""){const c=D({transitionClass:this._transitionClass});c.status||(this._errors.push(c.error.message),e=!1)}const n=d("number",{transitionDuration:this._transitionDuration});n.status||(this._errors.push(n.error.message),e=!1);const i=d("number",{openDuration:this._openDuration});i.status||(this._errors.push(i.error.message),e=!1);const l=d("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=d("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const c=k(v,{parentMenu:this._elements.parentMenu});c.status||(this._errors.push(c.error.message),e=!1)}const m=j({hoverType:this._hoverType});m.status||(this._errors.push(m.error.message),e=!1);const a=d("number",{hoverDelay:this._hoverDelay});a.status||(this._errors.push(a.error.message),e=!1);const p=d("number",{enterDelay:this._enterDelay});p.status||(this._errors.push(p.error.message),e=!1);const f=d("number",{leaveDelay:this._leaveDelay});return f.status||(this._errors.push(f.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&k(HTMLElement,{base:t});const i=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=i:this._dom[e]=[...this._dom[e],...i]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),n=e.querySelector(this.selectors.submenus),i=new this._MenuType({menuElement:n,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:i,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:i,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){d("function",{callback:e}),d("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,n){o(n),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",n=>{this.currentEvent="mouse",e(this,t.elements.toggle,n)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=y(e);(t==="Space"||t==="Enter")&&o(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=y(e);(t==="Space"||t==="Enter")&&(o(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty("--am-transition-duration",`${this.transitionDuration}ms`),this.dom.menu.style.setProperty("--am-open-transition-duration",`${this.openDuration}ms`),this.dom.menu.style.setProperty("--am-close-transition-duration",`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class W extends L{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}}class Z extends A{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),F("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class $ extends v{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="button",submenuSelector:h="ul",controllerElement:m=null,containerElement:a=null,openClass:p="show",closeClass:f="hide",transitionClass:c="transitioning",transitionDuration:_=250,openDuration:M=-1,closeDuration:g=-1,isTopLevel:b=!0,parentMenu:C=null,hoverType:T="off",hoverDelay:E=250,enterDelay:I=-1,leaveDelay:x=-1,optionalKeySupport:K=!1,initialize:N=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:a,openClass:p,closeClass:f,transitionClass:c,transitionDuration:_,openDuration:M,closeDuration:g,isTopLevel:b,parentMenu:C,hoverType:T,hoverDelay:E,enterDelay:I,leaveDelay:x});u(this,"_MenuType",$);u(this,"_MenuItemType",W);u(this,"_MenuToggleType",Z);u(this,"_currentChild",-1);u(this,"_optionalSupport",!1);this._optionalSupport=K,N&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){d("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_validate(){let t=super._validate();const s=d("boolean",{optionalKeySupport:this._optionalSupport});return s.status||(this._errors.push(s.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=y(t);if(this.focusState==="self"){const n=["Space","Enter"],i=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&o(t):(this.currentMenuItem.isSubmenuItem&&n.includes(s)||this.elements.controller&&i.includes(s)||this.elements.parentMenu&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=y(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(i=>i.isOpen)?(o(t),this.closeChildren()):this.elements.parentMenu?(o(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())))})}}class Q extends L{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","menuitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=0)}blur(){super.blur(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=-1)}}class B extends A{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),this.dom.toggle.setAttribute("aria-haspopup","true")}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&(this.closeChildren(),this.elements.parentMenu&&this.elements.parentMenu.focusCurrentChild()),super.close()}}class z extends v{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:m=null,containerElement:a=null,openClass:p="show",closeClass:f="hide",transitionClass:c="transitioning",transitionDuration:_=250,isTopLevel:M=!0,parentMenu:g=null,hoverType:b="off",hoverDelay:C=250,enterDelay:T=-1,leaveDelay:E=-1,initialize:I=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:a,openClass:p,closeClass:f,transitionClass:c,transitionDuration:_,isTopLevel:M,parentMenu:g,hoverType:b,hoverDelay:C,enterDelay:T,leaveDelay:E});u(this,"_MenuType",z);u(this,"_MenuItemType",Q);u(this,"_MenuToggleType",B);I&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?this.dom.menu.setAttribute("role","menubar"):this.dom.menu.setAttribute("role","menu"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&(this.elements.menuItems[0].dom.link.tabIndex=0,this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-haspopup"))}catch(t){console.error(t)}}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=y(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?(this.elements.rootMenu.blur(),this.elements.rootMenu.closeChildren()):this.elements.rootMenu.focus()),s==="Character")o(t);else if(this.isTopLevel){if(this.focusState==="self"){const n=["ArrowRight","ArrowLeft","Home","End"],i=["Space","Enter","ArrowDown","ArrowUp"],l=["Escape"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&l.includes(s))&&o(t)}}else{const n=["Escape","ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"],i=["Space","Enter"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=y(t),{altKey:n,crtlKey:i,metaKey:l}=t;if(s==="Character"&&!(n||i||l))o(t),this.elements.rootMenu.currentEvent="character",this.focusNextChildWithCharacter(t.key);else if(this.isTopLevel){if(this.focusState==="self")if(s==="Space"||s==="Enter")this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click();else if(s==="ArrowRight"){o(t);const m=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusNextChild(),m&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else if(s==="ArrowLeft"){o(t);const m=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusPreviousChild(),m&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else s==="ArrowDown"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):s==="ArrowUp"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusLastChild()})):s==="Home"?(o(t),this.focusFirstChild()):s==="End"?(o(t),this.focusLastChild()):s==="Escape"&&(this.elements.submenuToggles.some(a=>a.isOpen)?(o(t),this.closeChildren()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(o(t),this.elements.controller.close(),this.focusController()))}else s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click():s==="Escape"?(o(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusCurrentChild()):s==="ArrowRight"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):(o(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusNextChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&this.elements.rootMenu.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?this.elements.parentMenu.currentMenuItem.isSubmenuItem&&(o(t),this.elements.parentMenu.currentMenuItem.elements.toggle.close(),this.elements.parentMenu.focusCurrentChild(),this.elements.parentMenu===this.elements.rootMenu&&(this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusPreviousChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&(this.elements.rootMenu.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.elements.rootMenu.currentMenuItem.elements.toggle.preview()))):s==="ArrowDown"?(o(t),this.focusNextChild()):s==="ArrowUp"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())})}focusNextChild(){this.currentChild===this.elements.menuItems.length-1?this.focusFirstChild():this.focusChild(this.currentChild+1)}focusPreviousChild(){this.currentChild===0?this.focusLastChild():this.focusChild(this.currentChild-1)}focusNextChildWithCharacter(t){const s=t.toLowerCase();let n=this.currentChild+1,i=!1;for(;!i&&n{let s,n;const i=t.querySelector(this.selectors.menuLinks);if(this.dom.submenuItems.includes(t)){const l=t.querySelector(this.selectors.submenuToggles),h=t.querySelector(this.selectors.submenus),m=new this._MenuType({menuElement:h,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuSubtoggles,submenuSelector:this.selectors.submenus,submenuSubtoggleSelector:this.selectors.submenuSubtoggles,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),a=new this._MenuToggleType({menuToggleElement:l,parentElement:t,controlledMenu:m,parentMenu:this});this._elements.submenuToggles.push(a),l!==i?(n=new this._MenuItemType({menuItemElement:t,menuLinkElement:l,parentMenu:this,isSubmenuItem:!0,childMenu:m,toggle:a}),s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this,submenuSibling:n})):s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this,isSubmenuItem:!0,childMenu:m,toggle:a})}else s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this});this._elements.menuItems.push(s),typeof n<"u"&&this._elements.menuItems.push(n)})}_validate(){let t=super._validate();const s=O({submenuSubtoggleSelector:this._selectors.submenuSubtoggles});s.status||(this._errors.push(s.error.message),t=!1);const n=d("boolean",{optionalKeySupport:this._optionalSupport});return n.status||(this._errors.push(n.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",n=>{if(!(n.pointerType==="pen"||n.pointerType==="touch")){if(this.hoverType==="on"){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s);let i=t.isSubmenuItem?t.elements.toggle:null;if(t.elements.sibling!==null&&(i=t.elements.sibling.elements.toggle),i===null)return;this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{i.preview()},this.enterDelay)):i.preview()}else if(this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),!this.isTopLevel||this.hasOpened)){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild();let i=t.isSubmenuItem?t.elements.toggle:null;t.elements.sibling!==null&&(i=t.elements.sibling.elements.toggle),i!==null?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{i.preview()},this.enterDelay)):i.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren()}}}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",t.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",t.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=y(t);if(this.focusState==="self"){const n=["Space","Enter"],i=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&o(t):(this.currentMenuItem.isSubmenuItem&&n.includes(s)||this.elements.controller&&i.includes(s)||this.elements.parentMenu&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=y(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(i=>i.isOpen)?(o(t),this.closeChildren()):this.elements.parentMenu?(o(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())))})}}class X extends L{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","treeitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.dom.link.tabIndex=0}blur(){super.blur(),this.dom.link.tabIndex=-1}}class Y extends A{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}initialize(){this._setIds(),this._setAriaAttributes(),this.dom.toggle.getAttribute("aria-expanded")==="true"?this.open():this._collapse(!1)}_setAriaAttributes(){this.dom.toggle.getAttribute("aria-expanded")!=="true"&&this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id),this.dom.toggle.setAttribute("aria-owns",this.elements.controlledMenu.dom.menu.id)}}class q extends v{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:m=null,containerElement:a=null,openClass:p="show",closeClass:f="hide",transitionClass:c="transitioning",transitionDuration:_=250,isTopLevel:M=!0,parentMenu:g=null,hoverType:b="off",hoverDelay:C=250,enterDelay:T=-1,leaveDelay:E=-1,initialize:I=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:a,openClass:p,closeClass:f,transitionClass:c,transitionDuration:_,isTopLevel:M,parentMenu:g,hoverType:b,hoverDelay:C,enterDelay:T,leaveDelay:E});u(this,"_MenuType",q);u(this,"_MenuItemType",X);u(this,"_MenuToggleType",Y);I&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?(this.dom.menu.setAttribute("role","tree"),this.elements.menuItems[0].dom.link.tabIndex=0):this.dom.menu.setAttribute("role","group"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-owns")}catch(t){console.error(t)}}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s),t.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),t.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview():this.enterDelay>0&&this._clearTimeout())))}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0&&this._clearTimeout():this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()})),this.isTopLevel&&this.dom.menu.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||this.hoverType==="on"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren(),this.blur()},this.leaveDelay)):(this.closeChildren(),this.blur()))})})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=y(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?this.elements.rootMenu.blur():this.elements.rootMenu.focus()),this.focusState==="self"){const n=["Space","ArrowUp","ArrowDown","ArrowLeft","Asterisk","Home","End"],i=["Enter","ArrowRight"],l=["Escape"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=y(t),{altKey:n,crtlKey:i,metaKey:l}=t;if(s==="Character"&&!(n||i||l))o(t),this.elements.rootMenu.currentEvent="character",this.focusNextNodeWithCharacter(t.key);else if(this.focusState==="self")if(s==="Enter"||s==="Space")o(t),this.currentMenuItem.isSubmenuItem?this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview():this.currentMenuItem.dom.link.click();else if(s==="Escape")this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController());else if(s==="ArrowDown")o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):!this.isTopLevel&&this.currentChild===this.elements.menuItems.length-1?this.focusParentsNextChild():this.focusNextChild();else if(s==="ArrowUp"){o(t);const m=this.elements.menuItems[this.currentChild-1];m&&m.isSubmenuItem&&m.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentChild=this.currentChild-1,this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.focusChildsLastNode()):!this.isTopLevel&&this.currentChild===0?(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild()):this.focusPreviousChild()}else s==="ArrowRight"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):this.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.blurCurrentChild(),this.currentMenuItem.elements.toggle.close()):this.isTopLevel||(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild())):s==="Home"?(o(t),this.blurCurrentChild(),this.elements.rootMenu.focusFirstChild()):s==="End"?(o(t),this.blurCurrentChild(),this.elements.rootMenu.focusLastNode()):s==="Asterisk"&&(o(t),this.openChildren())})}focusLastNode(){const t=this.elements.menuItems.length-1,s=this.elements.menuItems[t];s.isSubmenuItem&&s.elements.toggle.isOpen?(this.currentChild=t,s.elements.childMenu.currentEvent=this.currentEvent,s.elements.childMenu.focusLastNode()):this.focusLastChild()}openChildren(){this.elements.submenuToggles.forEach(t=>t.preview())}focusNextNodeWithCharacter(t){function s(p){let f=[];return p.elements.menuItems.forEach(c=>{f.push(c),c.isSubmenuItem&&c.elements.toggle.isOpen&&(f=[...f,...s(c.elements.toggle.elements.controlledMenu)])}),f}const n=t.toLowerCase(),i=s(this.elements.rootMenu),l=i.indexOf(this.currentMenuItem)+1,h=[...i.slice(l),...i.slice(0,l)];let m=0,a=!1;for(;!a&&m=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){U({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){W({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){N({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){c("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){c("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){c("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set prefix(e){c("string",{value:e}),this._prefix!==e&&(this._prefix=e)}set hasOpened(e){c("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=A(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=A(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=x({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=x({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const d=k({openClass:this._openClass});d.status||(this._errors.push(d.error.message),e=!1)}if(this._closeClass!==""){const d=k({closeClass:this._closeClass});d.status||(this._errors.push(d.error.message),e=!1)}if(this._transitionClass!==""){const d=k({transitionClass:this._transitionClass});d.status||(this._errors.push(d.error.message),e=!1)}const n=c("number",{transitionDuration:this._transitionDuration});n.status||(this._errors.push(n.error.message),e=!1);const i=c("number",{openDuration:this._openDuration});i.status||(this._errors.push(i.error.message),e=!1);const l=c("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=c("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const d=A(w,{parentMenu:this._elements.parentMenu});d.status||(this._errors.push(d.error.message),e=!1)}const m=N({hoverType:this._hoverType});m.status||(this._errors.push(m.error.message),e=!1);const a=c("number",{hoverDelay:this._hoverDelay});a.status||(this._errors.push(a.error.message),e=!1);const p=c("number",{enterDelay:this._enterDelay});p.status||(this._errors.push(p.error.message),e=!1);const f=c("number",{leaveDelay:this._leaveDelay});f.status||(this._errors.push(f.error.message),e=!1);const g=c("string",{prefix:this._prefix});return g.status||(this._errors.push(g.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&A(HTMLElement,{base:t});const i=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=i:this._dom[e]=[...this._dom[e],...i]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),n=e.querySelector(this.selectors.submenus),i=new this._MenuType({menuElement:n,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:i,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:i,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){c("function",{callback:e}),c("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,n){o(n),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",n=>{this.currentEvent="mouse",e(this,t.elements.toggle,n)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=_(e);(t==="Space"||t==="Enter")&&o(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=_(e);(t==="Space"||t==="Enter")&&(o(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty(`--${this.prefix}transition-duration`,`${this.transitionDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}open-transition-duration`,`${this.openDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}close-transition-duration`,`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class Z extends O{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}}class Q extends L{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),F("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class z extends w{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="button",submenuSelector:h="ul",controllerElement:m=null,containerElement:a=null,openClass:p="show",closeClass:f="hide",transitionClass:g="transitioning",transitionDuration:d=250,openDuration:M=-1,closeDuration:y=-1,isTopLevel:b=!0,parentMenu:C=null,hoverType:T="off",hoverDelay:E=250,enterDelay:I=-1,leaveDelay:v=-1,optionalKeySupport:K=!1,prefix:$="am-",initialize:V=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:a,openClass:p,closeClass:f,transitionClass:g,transitionDuration:d,openDuration:M,closeDuration:y,isTopLevel:b,parentMenu:C,hoverType:T,hoverDelay:E,enterDelay:I,leaveDelay:v,prefix:$});u(this,"_MenuType",z);u(this,"_MenuItemType",Z);u(this,"_MenuToggleType",Q);u(this,"_currentChild",-1);u(this,"_optionalSupport",!1);this._optionalSupport=K,V&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){c("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_validate(){let t=super._validate();const s=c("boolean",{optionalKeySupport:this._optionalSupport});return s.status||(this._errors.push(s.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=_(t);if(this.focusState==="self"){const n=["Space","Enter"],i=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&o(t):(this.currentMenuItem.isSubmenuItem&&n.includes(s)||this.elements.controller&&i.includes(s)||this.elements.parentMenu&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=_(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(i=>i.isOpen)?(o(t),this.closeChildren()):this.elements.parentMenu?(o(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())))})}}class B extends O{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","menuitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=0)}blur(){super.blur(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=-1)}}class G extends L{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),this.dom.toggle.setAttribute("aria-haspopup","true")}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&(this.closeChildren(),this.elements.parentMenu&&this.elements.parentMenu.focusCurrentChild()),super.close()}}class H extends w{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:m=null,containerElement:a=null,openClass:p="show",closeClass:f="hide",transitionClass:g="transitioning",transitionDuration:d=250,isTopLevel:M=!0,parentMenu:y=null,hoverType:b="off",hoverDelay:C=250,enterDelay:T=-1,leaveDelay:E=-1,prefix:I="am-",initialize:v=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:a,openClass:p,closeClass:f,transitionClass:g,transitionDuration:d,isTopLevel:M,parentMenu:y,hoverType:b,hoverDelay:C,enterDelay:T,leaveDelay:E,prefix:I});u(this,"_MenuType",H);u(this,"_MenuItemType",B);u(this,"_MenuToggleType",G);v&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?this.dom.menu.setAttribute("role","menubar"):this.dom.menu.setAttribute("role","menu"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&(this.elements.menuItems[0].dom.link.tabIndex=0,this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-haspopup"))}catch(t){console.error(t)}}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=_(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?(this.elements.rootMenu.blur(),this.elements.rootMenu.closeChildren()):this.elements.rootMenu.focus()),s==="Character")o(t);else if(this.isTopLevel){if(this.focusState==="self"){const n=["ArrowRight","ArrowLeft","Home","End"],i=["Space","Enter","ArrowDown","ArrowUp"],l=["Escape"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&l.includes(s))&&o(t)}}else{const n=["Escape","ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"],i=["Space","Enter"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=_(t),{altKey:n,crtlKey:i,metaKey:l}=t;if(s==="Character"&&!(n||i||l))o(t),this.elements.rootMenu.currentEvent="character",this.focusNextChildWithCharacter(t.key);else if(this.isTopLevel){if(this.focusState==="self")if(s==="Space"||s==="Enter")this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click();else if(s==="ArrowRight"){o(t);const m=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusNextChild(),m&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else if(s==="ArrowLeft"){o(t);const m=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusPreviousChild(),m&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else s==="ArrowDown"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):s==="ArrowUp"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusLastChild()})):s==="Home"?(o(t),this.focusFirstChild()):s==="End"?(o(t),this.focusLastChild()):s==="Escape"&&(this.elements.submenuToggles.some(a=>a.isOpen)?(o(t),this.closeChildren()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(o(t),this.elements.controller.close(),this.focusController()))}else s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click():s==="Escape"?(o(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusCurrentChild()):s==="ArrowRight"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):(o(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusNextChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&this.elements.rootMenu.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?this.elements.parentMenu.currentMenuItem.isSubmenuItem&&(o(t),this.elements.parentMenu.currentMenuItem.elements.toggle.close(),this.elements.parentMenu.focusCurrentChild(),this.elements.parentMenu===this.elements.rootMenu&&(this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusPreviousChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&(this.elements.rootMenu.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.elements.rootMenu.currentMenuItem.elements.toggle.preview()))):s==="ArrowDown"?(o(t),this.focusNextChild()):s==="ArrowUp"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())})}focusNextChild(){this.currentChild===this.elements.menuItems.length-1?this.focusFirstChild():this.focusChild(this.currentChild+1)}focusPreviousChild(){this.currentChild===0?this.focusLastChild():this.focusChild(this.currentChild-1)}focusNextChildWithCharacter(t){const s=t.toLowerCase();let n=this.currentChild+1,i=!1;for(;!i&&n{let s,n;const i=t.querySelector(this.selectors.menuLinks);if(this.dom.submenuItems.includes(t)){const l=t.querySelector(this.selectors.submenuToggles),h=t.querySelector(this.selectors.submenus),m=new this._MenuType({menuElement:h,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuSubtoggles,submenuSelector:this.selectors.submenus,submenuSubtoggleSelector:this.selectors.submenuSubtoggles,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),a=new this._MenuToggleType({menuToggleElement:l,parentElement:t,controlledMenu:m,parentMenu:this});this._elements.submenuToggles.push(a),l!==i?(n=new this._MenuItemType({menuItemElement:t,menuLinkElement:l,parentMenu:this,isSubmenuItem:!0,childMenu:m,toggle:a}),s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this,submenuSibling:n})):s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this,isSubmenuItem:!0,childMenu:m,toggle:a})}else s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this});this._elements.menuItems.push(s),typeof n<"u"&&this._elements.menuItems.push(n)})}_validate(){let t=super._validate();const s=x({submenuSubtoggleSelector:this._selectors.submenuSubtoggles});s.status||(this._errors.push(s.error.message),t=!1);const n=c("boolean",{optionalKeySupport:this._optionalSupport});return n.status||(this._errors.push(n.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",n=>{if(!(n.pointerType==="pen"||n.pointerType==="touch")){if(this.hoverType==="on"){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s);let i=t.isSubmenuItem?t.elements.toggle:null;if(t.elements.sibling!==null&&(i=t.elements.sibling.elements.toggle),i===null)return;this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{i.preview()},this.enterDelay)):i.preview()}else if(this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),!this.isTopLevel||this.hasOpened)){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild();let i=t.isSubmenuItem?t.elements.toggle:null;t.elements.sibling!==null&&(i=t.elements.sibling.elements.toggle),i!==null?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{i.preview()},this.enterDelay)):i.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren()}}}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",t.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",t.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=_(t);if(this.focusState==="self"){const n=["Space","Enter"],i=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&o(t):(this.currentMenuItem.isSubmenuItem&&n.includes(s)||this.elements.controller&&i.includes(s)||this.elements.parentMenu&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=_(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(i=>i.isOpen)?(o(t),this.closeChildren()):this.elements.parentMenu?(o(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())))})}}class Y extends O{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","treeitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.dom.link.tabIndex=0}blur(){super.blur(),this.dom.link.tabIndex=-1}}class ee extends L{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}initialize(){this._setIds(),this._setAriaAttributes(),this.dom.toggle.getAttribute("aria-expanded")==="true"?this.open():this._collapse(!1)}_setAriaAttributes(){this.dom.toggle.getAttribute("aria-expanded")!=="true"&&this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id),this.dom.toggle.setAttribute("aria-owns",this.elements.controlledMenu.dom.menu.id)}}class j extends w{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:m=null,containerElement:a=null,openClass:p="show",closeClass:f="hide",transitionClass:g="transitioning",transitionDuration:d=250,isTopLevel:M=!0,parentMenu:y=null,hoverType:b="off",hoverDelay:C=250,enterDelay:T=-1,leaveDelay:E=-1,prefix:I="am-",initialize:v=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:a,openClass:p,closeClass:f,transitionClass:g,transitionDuration:d,isTopLevel:M,parentMenu:y,hoverType:b,hoverDelay:C,enterDelay:T,leaveDelay:E,prefix:I});u(this,"_MenuType",j);u(this,"_MenuItemType",Y);u(this,"_MenuToggleType",ee);v&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?(this.dom.menu.setAttribute("role","tree"),this.elements.menuItems[0].dom.link.tabIndex=0):this.dom.menu.setAttribute("role","group"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-owns")}catch(t){console.error(t)}}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s),t.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),t.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview():this.enterDelay>0&&this._clearTimeout())))}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0&&this._clearTimeout():this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()})),this.isTopLevel&&this.dom.menu.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||this.hoverType==="on"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren(),this.blur()},this.leaveDelay)):(this.closeChildren(),this.blur()))})})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=_(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?this.elements.rootMenu.blur():this.elements.rootMenu.focus()),this.focusState==="self"){const n=["Space","ArrowUp","ArrowDown","ArrowLeft","Asterisk","Home","End"],i=["Enter","ArrowRight"],l=["Escape"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=_(t),{altKey:n,crtlKey:i,metaKey:l}=t;if(s==="Character"&&!(n||i||l))o(t),this.elements.rootMenu.currentEvent="character",this.focusNextNodeWithCharacter(t.key);else if(this.focusState==="self")if(s==="Enter"||s==="Space")o(t),this.currentMenuItem.isSubmenuItem?this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview():this.currentMenuItem.dom.link.click();else if(s==="Escape")this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController());else if(s==="ArrowDown")o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):!this.isTopLevel&&this.currentChild===this.elements.menuItems.length-1?this.focusParentsNextChild():this.focusNextChild();else if(s==="ArrowUp"){o(t);const m=this.elements.menuItems[this.currentChild-1];m&&m.isSubmenuItem&&m.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentChild=this.currentChild-1,this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.focusChildsLastNode()):!this.isTopLevel&&this.currentChild===0?(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild()):this.focusPreviousChild()}else s==="ArrowRight"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):this.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.blurCurrentChild(),this.currentMenuItem.elements.toggle.close()):this.isTopLevel||(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild())):s==="Home"?(o(t),this.blurCurrentChild(),this.elements.rootMenu.focusFirstChild()):s==="End"?(o(t),this.blurCurrentChild(),this.elements.rootMenu.focusLastNode()):s==="Asterisk"&&(o(t),this.openChildren())})}focusLastNode(){const t=this.elements.menuItems.length-1,s=this.elements.menuItems[t];s.isSubmenuItem&&s.elements.toggle.isOpen?(this.currentChild=t,s.elements.childMenu.currentEvent=this.currentEvent,s.elements.childMenu.focusLastNode()):this.focusLastChild()}openChildren(){this.elements.submenuToggles.forEach(t=>t.preview())}focusNextNodeWithCharacter(t){function s(p){let f=[];return p.elements.menuItems.forEach(g=>{f.push(g),g.isSubmenuItem&&g.elements.toggle.isOpen&&(f=[...f,...s(g.elements.toggle.elements.controlledMenu)])}),f}const n=t.toLowerCase(),i=s(this.elements.rootMenu),l=i.indexOf(this.currentMenuItem)+1,h=[...i.slice(l),...i.slice(0,l)];let m=0,a=!1;for(;!a&&m e in r ? V(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; -var u = (r, e, t) => P(r, typeof e != "symbol" ? e + "" : e, t); -function w(r, e) { +var P = Object.defineProperty; +var R = (r, e, t) => e in r ? P(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; +var u = (r, e, t) => R(r, typeof e != "symbol" ? e + "" : e, t); +function S(r, e) { r === "" || r.length === 0 || (typeof r == "string" ? e.classList.add(r) : e.classList.add(...r)); } -function S(r, e) { +function D(r, e) { r === "" || r.length === 0 || (typeof r == "string" ? e.classList.remove(r) : e.classList.remove(...r)); } -function k(r, e) { +function A(r, e) { try { if (typeof e != "object") { const t = typeof e; @@ -33,7 +33,7 @@ function k(r, e) { }; } } -function d(r, e) { +function c(r, e) { try { if (typeof e != "object") { const t = typeof e; @@ -57,7 +57,7 @@ function d(r, e) { }; } } -function O(r) { +function x(r) { try { if (typeof r != "object") { const e = typeof r; @@ -86,7 +86,7 @@ function O(r) { }; } } -function D(r) { +function k(r) { try { if (typeof r != "object" || Array.isArray(r)) { const e = typeof r; @@ -110,7 +110,7 @@ function D(r) { ); else { const s = {}; - s[e] = r[e], O(s); + s[e] = r[e], x(s); } } return { @@ -124,7 +124,7 @@ function D(r) { }; } } -function R(r) { +function U(r) { try { if (typeof r != "object") { const t = typeof r; @@ -151,7 +151,7 @@ function R(r) { }; } } -function U(r) { +function W(r) { try { if (typeof r != "object") { const t = typeof r; @@ -178,7 +178,7 @@ function U(r) { }; } } -function j(r) { +function N(r) { try { if (typeof r != "object") { const t = typeof r; @@ -206,7 +206,7 @@ function j(r) { } } function F(r, e) { - if (d("string", { tagName: r }).status && k(HTMLElement, e).status) { + if (c("string", { tagName: r }).status && A(HTMLElement, e).status) { const t = r.toLowerCase(); let s = !0; for (const n in e) @@ -215,7 +215,7 @@ function F(r, e) { } else return !1; } -class A { +class L { /** * Constructs a new `BaseMenuToggle`. * @@ -348,7 +348,7 @@ class A { return this._open; } set isOpen(e) { - d("boolean", { value: e }), this._open = e; + c("boolean", { value: e }), this._open = e; } /** * Sets unique IDs for the toggle and controlled menu. @@ -405,18 +405,18 @@ class A { */ _expand(e = !0) { const { closeClass: t, openClass: s, transitionClass: n, openDuration: i } = this.elements.controlledMenu; - this.dom.toggle.setAttribute("aria-expanded", "true"), this.elements.controlledMenu.elements.rootMenu.hasOpened = !0, n !== "" ? (w(n, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - S(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - w(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + this.dom.toggle.setAttribute("aria-expanded", "true"), this.elements.controlledMenu.elements.rootMenu.hasOpened = !0, n !== "" ? (S(n, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + D(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + S(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { setTimeout(() => { - S( + D( n, this.elements.controlledMenu.dom.menu ); }, i); }); }); - })) : (w(s, this.elements.controlledMenu.dom.menu), S(t, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._expandEvent); + })) : (S(s, this.elements.controlledMenu.dom.menu), D(t, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._expandEvent); } /** * Collapses the controlled menu. @@ -437,18 +437,18 @@ class A { */ _collapse(e = !0) { const { closeClass: t, openClass: s, transitionClass: n, closeDuration: i } = this.elements.controlledMenu; - this.dom.toggle.setAttribute("aria-expanded", "false"), n !== "" ? (w(n, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - S(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - w(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + this.dom.toggle.setAttribute("aria-expanded", "false"), n !== "" ? (S(n, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + D(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + S(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { setTimeout(() => { - S( + D( n, this.elements.controlledMenu.dom.menu ); }, i); }); }); - })) : (w(t, this.elements.controlledMenu.dom.menu), S(s, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._collapseEvent); + })) : (S(t, this.elements.controlledMenu.dom.menu), D(s, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._collapseEvent); } /** * Opens the controlled menu. @@ -517,7 +517,7 @@ class A { ); } } -class L { +class O { /** * Constructs a new `BaseMenuItem`. * @@ -641,7 +641,7 @@ class L { }); } } -function y(r) { +function _(r) { try { const e = r.key || r.keyCode, t = { Enter: e === "Enter" || e === 13, @@ -665,7 +665,7 @@ function y(r) { function o(r) { r.preventDefault(), r.stopPropagation(); } -class v { +class w { /** * Constructs a new `BaseMenu`. * @@ -681,15 +681,16 @@ class v { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). - * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in miliseconds). - * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). + * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in milliseconds). + * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = false] - A flag to mark the root menu. * @param {?BaseMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in milliseconds). + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. */ constructor({ menuElement: e, @@ -703,15 +704,16 @@ class v { openClass: a = "show", closeClass: p = "hide", transitionClass: f = "transitioning", - transitionDuration: c = 250, - openDuration: _ = -1, + transitionDuration: g = 250, + openDuration: d = -1, closeDuration: M = -1, - isTopLevel: g = !0, + isTopLevel: y = !0, parentMenu: b = null, hoverType: C = "off", hoverDelay: T = 250, enterDelay: E = -1, - leaveDelay: I = -1 + leaveDelay: I = -1, + prefix: v = "am-" }) { /** * The class to use when generating submenus. @@ -720,7 +722,7 @@ class v { * * @type {typeof BaseMenu} */ - u(this, "_MenuType", v); + u(this, "_MenuType", w); /** * The class to use when generating menu items. * @@ -728,7 +730,7 @@ class v { * * @type {typeof BaseMenuItem} */ - u(this, "_MenuItemType", L); + u(this, "_MenuItemType", O); /** * The class to use when generating submenu toggles. * @@ -736,7 +738,7 @@ class v { * * @type {typeof BaseMenuToggle} */ - u(this, "_MenuToggleType", A); + u(this, "_MenuToggleType", L); /** * The DOM elements within the menu. * @@ -826,7 +828,7 @@ class v { */ u(this, "_transitionClass", "transitioning"); /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * @protected * @@ -834,7 +836,7 @@ class v { */ u(this, "_transitionDuration", 250); /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * @protected * @@ -842,7 +844,7 @@ class v { */ u(this, "_openDuration", -1); /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * @protected * @@ -890,7 +892,7 @@ class v { */ u(this, "_hoverType", "off"); /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * @protected * @@ -898,7 +900,7 @@ class v { */ u(this, "_hoverDelay", 250); /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * @protected * @@ -906,13 +908,21 @@ class v { */ u(this, "_enterDelay", -1); /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * @protected * * @type {number} */ u(this, "_leaveDelay", -1); + /** + * The prefix to use for CSS custom properties. + * + * @protected + * + * @type {string} + */ + u(this, "_prefix", "am-"); /** * A variable to hold the hover timeout function. * @@ -937,7 +947,7 @@ class v { * @type {string[]} */ u(this, "_errors", []); - this._dom.menu = e, this._dom.controller = h, this._dom.container = m, this._selectors.menuItems = t, this._selectors.menuLinks = s, this._selectors.submenuItems = n, this._selectors.submenuToggles = i, this._selectors.submenus = l, this._elements.menuItems = [], this._elements.submenuToggles = [], this._elements.controller = null, this._elements.parentMenu = b, this._elements.rootMenu = g ? this : null, this._openClass = a || "", this._closeClass = p || "", this._transitionClass = f || "", this._transitionDuration = c, this._openDuration = _, this._closeDuration = M, this._root = g, this._hoverType = C, this._hoverDelay = T, this._enterDelay = E, this._leaveDelay = I; + this._dom.menu = e, this._dom.controller = h, this._dom.container = m, this._selectors.menuItems = t, this._selectors.menuLinks = s, this._selectors.submenuItems = n, this._selectors.submenuToggles = i, this._selectors.submenus = l, this._elements.menuItems = [], this._elements.submenuToggles = [], this._elements.controller = null, this._elements.parentMenu = b, this._elements.rootMenu = y ? this : null, this._openClass = a || "", this._closeClass = p || "", this._transitionClass = f || "", this._transitionDuration = g, this._openDuration = d, this._closeDuration = M, this._prefix = v || "", this._root = y, this._hoverType = C, this._hoverDelay = T, this._enterDelay = E, this._leaveDelay = I; } /** * Initializes the menu. @@ -1064,7 +1074,7 @@ class v { return this.isTopLevel ? this._transitionClass : this.elements.rootMenu.transitionClass; } /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's transition duration. @@ -1079,7 +1089,7 @@ class v { return this.isTopLevel ? this._transitionDuration : this.elements.rootMenu.transitionDuration; } /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's openDuration. @@ -1096,7 +1106,7 @@ class v { return this._openDuration === -1 ? this.transitionDuration : this.isTopLevel ? this._openDuration : this.elements.rootMenu.openDuration; } /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's closeDuration. @@ -1180,7 +1190,7 @@ class v { return this._root ? this._hoverType : this.elements.rootMenu.hoverType; } /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's hover delay. @@ -1193,7 +1203,7 @@ class v { return this._root ? this._hoverDelay : this.elements.rootMenu.hoverDelay; } /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's enter delay. @@ -1208,7 +1218,7 @@ class v { return this._enterDelay === -1 ? this.hoverDelay : this._root ? this._enterDelay : this.elements.rootMenu.enterDelay; } /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's leave delay. @@ -1222,6 +1232,19 @@ class v { get leaveDelay() { return this._leaveDelay === -1 ? this.hoverDelay : this._root ? this._leaveDelay : this.elements.rootMenu.leaveDelay; } + /** + * The prefix to use for CSS custom properties. + * + * This functions differently for root vs. submenus. + * Submenus will always inherit their root menu's prefix. + * + * @type {string} + * + * @see _prefix + */ + get prefix() { + return this._root ? this._prefix : this.elements.rootMenu.prefix; + } /** * A flag to check if the menu's focus methods should _actually_ move the focus in the DOM. * @@ -1265,25 +1288,25 @@ class v { return this._errors; } set openClass(e) { - D({ openClass: e }), this._openClass !== e && (this._openClass = e); + k({ openClass: e }), this._openClass !== e && (this._openClass = e); } set closeClass(e) { - D({ closeClass: e }), this._closeClass !== e && (this._closeClass = e); + k({ closeClass: e }), this._closeClass !== e && (this._closeClass = e); } set transitionClass(e) { - D({ transitionClass: e }), this._transitionClass !== e && (this._transitionClass = e); + k({ transitionClass: e }), this._transitionClass !== e && (this._transitionClass = e); } set transitionDuration(e) { - d("number", { value: e }), this._transitionDuration !== e && (this._transitionDuration = e, this._setTransitionDurations()); + c("number", { value: e }), this._transitionDuration !== e && (this._transitionDuration = e, this._setTransitionDurations()); } set openDuration(e) { - d("number", { value: e }), this._openDuration !== e && (this._openDuration = e, this._setTransitionDurations()); + c("number", { value: e }), this._openDuration !== e && (this._openDuration = e, this._setTransitionDurations()); } set closeDuration(e) { - d("number", { value: e }), this._closeDuration !== e && (this._closeDuration = e, this._setTransitionDurations()); + c("number", { value: e }), this._closeDuration !== e && (this._closeDuration = e, this._setTransitionDurations()); } set currentChild(e) { - d("number", { value: e }); + c("number", { value: e }); function t(s) { if (["mouse", "character"].includes(s.currentEvent) && s.elements.parentMenu) { let i = 0, l = !1; @@ -1296,29 +1319,32 @@ class v { e < -1 ? (this._currentChild = -1, t(this)) : e >= this.elements.menuItems.length ? (this._currentChild = this.elements.menuItems.length - 1, t(this)) : this.focusChild !== e && (this._currentChild = e, t(this)); } set focusState(e) { - R({ value: e }), this._focusState !== e && (this._focusState = e), this.elements.submenuToggles.length > 0 && (e === "self" || e === "none") && this.elements.submenuToggles.forEach((t) => { + U({ value: e }), this._focusState !== e && (this._focusState = e), this.elements.submenuToggles.length > 0 && (e === "self" || e === "none") && this.elements.submenuToggles.forEach((t) => { t.elements.controlledMenu.focusState = "none"; }), this.elements.parentMenu && (e === "self" || e === "child") && (this.elements.parentMenu.focusState = "child"); } set currentEvent(e) { - U({ value: e }), this._currentEvent !== e && (this._currentEvent = e, this.elements.submenuToggles.length > 0 && this.elements.submenuToggles.forEach((t) => { + W({ value: e }), this._currentEvent !== e && (this._currentEvent = e, this.elements.submenuToggles.length > 0 && this.elements.submenuToggles.forEach((t) => { t.elements.controlledMenu.currentEvent = e; })); } set hoverType(e) { - j({ value: e }), this._hoverType !== e && (this._hoverType = e); + N({ value: e }), this._hoverType !== e && (this._hoverType = e); } set hoverDelay(e) { - d("number", { value: e }), this._hoverDelay !== e && (this._hoverDelay = e); + c("number", { value: e }), this._hoverDelay !== e && (this._hoverDelay = e); } set enterDelay(e) { - d("number", { value: e }), this._enterDelay !== e && (this._enterDelay = e); + c("number", { value: e }), this._enterDelay !== e && (this._enterDelay = e); } set leaveDelay(e) { - d("number", { value: e }), this._leaveDelay !== e && (this._leaveDelay = e); + c("number", { value: e }), this._leaveDelay !== e && (this._leaveDelay = e); + } + set prefix(e) { + c("string", { value: e }), this._prefix !== e && (this._prefix = e); } set hasOpened(e) { - d("boolean", { value: e }), this._hasOpened !== e && (this._hasOpened = e); + c("boolean", { value: e }), this._hasOpened !== e && (this._hasOpened = e); } /** * Validates all aspects of the menu to ensure proper functionality. @@ -1329,72 +1355,74 @@ class v { */ _validate() { let e = !0, t; - this._dom.container !== null || this._dom.controller !== null ? t = k(HTMLElement, { + this._dom.container !== null || this._dom.controller !== null ? t = A(HTMLElement, { menuElement: this._dom.menu, controllerElement: this._dom.controller, containerElement: this._dom.container - }) : t = k(HTMLElement, { + }) : t = A(HTMLElement, { menuElement: this._dom.menu }), t.status || (this._errors.push(t.error.message), e = !1); let s; - if (this._selectors.submenuItems !== "" ? s = O({ + if (this._selectors.submenuItems !== "" ? s = x({ menuItemSelector: this._selectors.menuItems, menuLinkSelector: this._selectors.menuLinks, submenuItemSelector: this._selectors.submenuItems, submenuToggleSelector: this._selectors.submenuToggles, submenuSelector: this._selectors.submenus - }) : s = O({ + }) : s = x({ menuItemSelector: this._selectors.menuItems, menuLinkSelector: this._selectors.menuLinks }), s.status || (this._errors.push(s.error.message), e = !1), this._openClass !== "") { - const c = D({ openClass: this._openClass }); - c.status || (this._errors.push(c.error.message), e = !1); + const d = k({ openClass: this._openClass }); + d.status || (this._errors.push(d.error.message), e = !1); } if (this._closeClass !== "") { - const c = D({ + const d = k({ closeClass: this._closeClass }); - c.status || (this._errors.push(c.error.message), e = !1); + d.status || (this._errors.push(d.error.message), e = !1); } if (this._transitionClass !== "") { - const c = D({ + const d = k({ transitionClass: this._transitionClass }); - c.status || (this._errors.push(c.error.message), e = !1); + d.status || (this._errors.push(d.error.message), e = !1); } - const n = d("number", { + const n = c("number", { transitionDuration: this._transitionDuration }); n.status || (this._errors.push(n.error.message), e = !1); - const i = d("number", { + const i = c("number", { openDuration: this._openDuration }); i.status || (this._errors.push(i.error.message), e = !1); - const l = d("number", { + const l = c("number", { closeDuration: this._closeDuration }); l.status || (this._errors.push(l.error.message), e = !1); - const h = d("boolean", { isTopLevel: this._root }); + const h = c("boolean", { isTopLevel: this._root }); if (h.status || (this._errors.push(h.error.message), e = !1), this._elements.parentMenu !== null) { - const c = k(v, { + const d = A(w, { parentMenu: this._elements.parentMenu }); - c.status || (this._errors.push(c.error.message), e = !1); + d.status || (this._errors.push(d.error.message), e = !1); } - const m = j({ hoverType: this._hoverType }); + const m = N({ hoverType: this._hoverType }); m.status || (this._errors.push(m.error.message), e = !1); - const a = d("number", { + const a = c("number", { hoverDelay: this._hoverDelay }); a.status || (this._errors.push(a.error.message), e = !1); - const p = d("number", { + const p = c("number", { enterDelay: this._enterDelay }); p.status || (this._errors.push(p.error.message), e = !1); - const f = d("number", { + const f = c("number", { leaveDelay: this._leaveDelay }); - return f.status || (this._errors.push(f.error.message), e = !1), e; + f.status || (this._errors.push(f.error.message), e = !1); + const g = c("string", { prefix: this._prefix }); + return g.status || (this._errors.push(g.error.message), e = !1), e; } /** * Sets DOM elements within the menu. @@ -1413,7 +1441,7 @@ class v { throw new Error( `AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.` ); - t !== this.dom.menu && k(HTMLElement, { base: t }); + t !== this.dom.menu && A(HTMLElement, { base: t }); const i = Array.from( t.querySelectorAll(this.selectors[e]) ).filter( @@ -1547,7 +1575,7 @@ class v { * @param {number} delay - The delay time in milliseconds. */ _setTimeout(e, t) { - d("function", { callback: e }), d("number", { delay: t }), this._hoverTimeout = setTimeout(e, t); + c("function", { callback: e }), c("number", { delay: t }), this._hoverTimeout = setTimeout(e, t); } /** * Handles focus events throughout the menu for proper menu use. @@ -1688,7 +1716,7 @@ class v { "keydown", (e) => { this.currentEvent = "keyboard"; - const t = y(e); + const t = _(e); (t === "Space" || t === "Enter") && o(e); } ); @@ -1704,7 +1732,7 @@ class v { _handleKeyup() { this.isTopLevel && this.elements.controller && this.elements.controller.dom.toggle.addEventListener("keyup", (e) => { this.currentEvent = "keyboard"; - const t = y(e); + const t = _(e); (t === "Space" || t === "Enter") && (o(e), this.elements.controller.toggle(), this.elements.controller.isOpen && this.focusFirstChild()); }); } @@ -1716,17 +1744,19 @@ class v { * - `--am-open-transition-duration`, and * - `--am-close-transition-duration`. * + * The prefix of `am-` can be changed by setting the menu's prefix value. + * * @protected */ _setTransitionDurations() { this.dom.menu.style.setProperty( - "--am-transition-duration", + `--${this.prefix}transition-duration`, `${this.transitionDuration}ms` ), this.dom.menu.style.setProperty( - "--am-open-transition-duration", + `--${this.prefix}open-transition-duration`, `${this.openDuration}ms` ), this.dom.menu.style.setProperty( - "--am-close-transition-duration", + `--${this.prefix}close-transition-duration`, `${this.closeDuration}ms` ); } @@ -1847,7 +1877,7 @@ class v { }); } } -class W extends L { +class Z extends O { /** * Constructs a new `DisclosureMenuItem`. * @@ -1879,7 +1909,7 @@ class W extends L { }), h && this.initialize(); } } -class Z extends A { +class Q extends L { /** * Constructs a new `DisclosureMenuToggle`. * @@ -1957,7 +1987,7 @@ class Z extends A { this.isOpen && this.closeChildren(), super.close(); } } -class $ extends v { +class z extends w { /** * Constructs a new `DisclosureMenu`. * @@ -1973,16 +2003,17 @@ class $ extends v { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). - * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in miliseconds). - * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). + * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in milliseconds). + * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?DisclosureMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). * @param {boolean} [options.optionalKeySupport = false] - A flag to add optional keyboard support (Arrow keys, Home, and End) to the menu. + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. */ constructor({ @@ -1996,18 +2027,19 @@ class $ extends v { containerElement: a = null, openClass: p = "show", closeClass: f = "hide", - transitionClass: c = "transitioning", - transitionDuration: _ = 250, + transitionClass: g = "transitioning", + transitionDuration: d = 250, openDuration: M = -1, - closeDuration: g = -1, + closeDuration: y = -1, isTopLevel: b = !0, parentMenu: C = null, hoverType: T = "off", hoverDelay: E = 250, enterDelay: I = -1, - leaveDelay: x = -1, + leaveDelay: v = -1, optionalKeySupport: K = !1, - initialize: N = !0 + prefix: $ = "am-", + initialize: V = !0 }) { super({ menuElement: t, @@ -2020,16 +2052,17 @@ class $ extends v { containerElement: a, openClass: p, closeClass: f, - transitionClass: c, - transitionDuration: _, + transitionClass: g, + transitionDuration: d, openDuration: M, - closeDuration: g, + closeDuration: y, isTopLevel: b, parentMenu: C, hoverType: T, hoverDelay: E, enterDelay: I, - leaveDelay: x + leaveDelay: v, + prefix: $ }); /** * The class to use when generating submenus. @@ -2038,7 +2071,7 @@ class $ extends v { * * @type {typeof DisclosureMenu} */ - u(this, "_MenuType", $); + u(this, "_MenuType", z); /** * The class to use when generating menu items. * @@ -2046,7 +2079,7 @@ class $ extends v { * * @type {typeof DisclosureMenuItem} */ - u(this, "_MenuItemType", W); + u(this, "_MenuItemType", Z); /** * The class to use when generating submenu toggles. * @@ -2054,7 +2087,7 @@ class $ extends v { * * @type {typeof DisclosureMenuToggle} */ - u(this, "_MenuToggleType", Z); + u(this, "_MenuToggleType", Q); /** * The index of the currently selected menu item in the menu. * @@ -2071,7 +2104,7 @@ class $ extends v { * @type {boolean} */ u(this, "_optionalSupport", !1); - this._optionalSupport = K, N && this.initialize(); + this._optionalSupport = K, V && this.initialize(); } /** * Initializes the menu. @@ -2107,7 +2140,7 @@ class $ extends v { return this.isTopLevel ? this._optionalSupport : this.elements.rootMenu.optionalKeySupport; } set optionalKeySupport(t) { - d("boolean", { optionalKeySupport: t }), this._optionalSupport = t; + c("boolean", { optionalKeySupport: t }), this._optionalSupport = t; } /** * Validates all aspects of the menu to ensure proper functionality. @@ -2118,7 +2151,7 @@ class $ extends v { */ _validate() { let t = super._validate(); - const s = d("boolean", { + const s = c("boolean", { optionalKeySupport: this._optionalSupport }); return s.status || (this._errors.push(s.error.message), t = !1), t; @@ -2154,7 +2187,7 @@ class $ extends v { _handleKeydown() { super._handleKeydown(), this.dom.menu.addEventListener("keydown", (t) => { this.currentEvent = "keyboard"; - const s = y(t); + const s = _(t); if (this.focusState === "self") { const n = ["Space", "Enter"], i = ["Escape"], l = ["Escape"]; this.optionalKeySupport ? [ @@ -2193,14 +2226,14 @@ class $ extends v { _handleKeyup() { super._handleKeyup(), this.dom.menu.addEventListener("keyup", (t) => { this.currentEvent = "keyboard"; - const s = y(t); + const s = _(t); this.focusState === "self" && (s === "Space" || s === "Enter" ? this.currentMenuItem.isSubmenuItem ? (o(t), this.currentMenuItem.elements.toggle.isOpen ? this.currentMenuItem.elements.toggle.close() : this.currentMenuItem.elements.toggle.preview()) : this.currentMenuItem.dom.link.click() : s === "Escape" ? this.elements.submenuToggles.some( (i) => i.isOpen ) ? (o(t), this.closeChildren()) : this.elements.parentMenu ? (o(t), this.elements.parentMenu.currentEvent = this.currentEvent, this.elements.parentMenu.closeChildren(), this.elements.parentMenu.focusCurrentChild()) : this.isTopLevel && this.elements.controller && this.elements.controller.isOpen && (this.elements.controller.close(), this.focusController()) : this.optionalKeySupport && (s === "ArrowDown" || s === "ArrowRight" ? (o(t), this.currentMenuItem.isSubmenuItem && this.currentMenuItem.elements.toggle.isOpen ? (this.currentMenuItem.elements.childMenu.currentEvent = "keyboard", this.currentMenuItem.elements.childMenu.focusFirstChild()) : this.focusNextChild()) : s === "ArrowUp" || s === "ArrowLeft" ? (o(t), this.focusPreviousChild()) : s === "Home" ? (o(t), this.focusFirstChild()) : s === "End" && (o(t), this.focusLastChild()))); }); } } -class Q extends L { +class B extends O { /** * Constructs a new `MenubarItem`. * @@ -2269,7 +2302,7 @@ class Q extends L { super.blur(), this.elements.parentMenu.isTopLevel && (this.dom.link.tabIndex = -1); } } -class B extends A { +class G extends L { /** * Constructs a new `MenubarToggle`. * @@ -2340,7 +2373,7 @@ class B extends A { this.isOpen && (this.closeChildren(), this.elements.parentMenu && this.elements.parentMenu.focusCurrentChild()), super.close(); } } -class z extends v { +class H extends w { /** * Constructs a new `Menubar`. * @@ -2356,13 +2389,14 @@ class z extends v { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?Menubar} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. */ constructor({ @@ -2376,15 +2410,16 @@ class z extends v { containerElement: a = null, openClass: p = "show", closeClass: f = "hide", - transitionClass: c = "transitioning", - transitionDuration: _ = 250, + transitionClass: g = "transitioning", + transitionDuration: d = 250, isTopLevel: M = !0, - parentMenu: g = null, + parentMenu: y = null, hoverType: b = "off", hoverDelay: C = 250, enterDelay: T = -1, leaveDelay: E = -1, - initialize: I = !0 + prefix: I = "am-", + initialize: v = !0 }) { super({ menuElement: t, @@ -2397,14 +2432,15 @@ class z extends v { containerElement: a, openClass: p, closeClass: f, - transitionClass: c, - transitionDuration: _, + transitionClass: g, + transitionDuration: d, isTopLevel: M, - parentMenu: g, + parentMenu: y, hoverType: b, hoverDelay: C, enterDelay: T, - leaveDelay: E + leaveDelay: E, + prefix: I }); /** * The class to use when generating submenus. @@ -2413,7 +2449,7 @@ class z extends v { * * @type {typeof Menubar} */ - u(this, "_MenuType", z); + u(this, "_MenuType", H); /** * The class to use when generating menu items. * @@ -2421,7 +2457,7 @@ class z extends v { * * @type {typeof MenubarItem} */ - u(this, "_MenuItemType", Q); + u(this, "_MenuItemType", B); /** * The class to use when generating submenu toggles. * @@ -2429,8 +2465,8 @@ class z extends v { * * @type {typeof MenubarToggle} */ - u(this, "_MenuToggleType", B); - I && this.initialize(); + u(this, "_MenuToggleType", G); + v && this.initialize(); } /** * Initializes the menu. @@ -2488,7 +2524,7 @@ class z extends v { _handleKeydown() { super._handleKeydown(), this.dom.menu.addEventListener("keydown", (t) => { this.currentEvent = "keyboard"; - const s = y(t); + const s = _(t); if (s === "Tab" && (this.elements.rootMenu.focusState !== "none" ? (this.elements.rootMenu.blur(), this.elements.rootMenu.closeChildren()) : this.elements.rootMenu.focus()), s === "Character") o(t); else if (this.isTopLevel) { @@ -2550,7 +2586,7 @@ class z extends v { _handleKeyup() { super._handleKeyup(), this.dom.menu.addEventListener("keyup", (t) => { this.currentEvent = "keyboard"; - const s = y(t), { altKey: n, crtlKey: i, metaKey: l } = t; + const s = _(t), { altKey: n, crtlKey: i, metaKey: l } = t; if (s === "Character" && !(n || i || l)) o(t), this.elements.rootMenu.currentEvent = "character", this.focusNextChildWithCharacter(t.key); else if (this.isTopLevel) { @@ -2620,7 +2656,7 @@ class z extends v { } } } -class G extends L { +class J extends O { /** * Constructs a new `TopLinkDisclosureMenuItem`. * @@ -2673,7 +2709,7 @@ class G extends L { this._elements.parentMenu = n, this._elements.childMenu = l, this._elements.toggle = h, this._elements.sibling = a, m && this.initialize(); } } -class J extends A { +class X extends L { /** * Constructs a new `TopLinkDisclosureMenuToggle`. * @@ -2745,7 +2781,7 @@ class J extends A { this.isOpen && this.closeChildren(), super.close(); } } -class H extends v { +class q extends w { /** * Constructs a new `TopLinkDisclosureMenu`. * @@ -2762,14 +2798,15 @@ class H extends v { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?TopLinkDisclosureMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). * @param {boolean} [options.optionalKeySupport = false] - A flag to add optional keyboard support (Arrow keys, Home, and End) to the menu. + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. */ constructor({ @@ -2783,17 +2820,18 @@ class H extends v { controllerElement: a = null, containerElement: p = null, openClass: f = "show", - closeClass: c = "hide", - transitionClass: _ = "transitioning", + closeClass: g = "hide", + transitionClass: d = "transitioning", transitionDuration: M = 250, - isTopLevel: g = !0, + isTopLevel: y = !0, parentMenu: b = null, hoverType: C = "off", hoverDelay: T = 250, enterDelay: E = -1, leaveDelay: I = -1, - optionalKeySupport: x = !1, - initialize: K = !0 + optionalKeySupport: v = !1, + prefix: K = "am-", + initialize: $ = !0 }) { super({ menuElement: t, @@ -2805,15 +2843,16 @@ class H extends v { controllerElement: a, containerElement: p, openClass: f, - closeClass: c, - transitionClass: _, + closeClass: g, + transitionClass: d, transitionDuration: M, - isTopLevel: g, + isTopLevel: y, parentMenu: b, hoverType: C, hoverDelay: T, enterDelay: E, - leaveDelay: I + leaveDelay: I, + prefix: K }); /** * The class to use when generating submenus. @@ -2822,7 +2861,7 @@ class H extends v { * * @type {typeof TopLinkDisclosureMenu} */ - u(this, "_MenuType", H); + u(this, "_MenuType", q); /** * The class to use when generating menu items. * @@ -2830,7 +2869,7 @@ class H extends v { * * @type {typeof TopLinkDisclosureMenuItem} */ - u(this, "_MenuItemType", G); + u(this, "_MenuItemType", J); /** * The class to use when generating submenu toggles. * @@ -2838,7 +2877,7 @@ class H extends v { * * @type {typeof TopLinkDisclosureMenuToggle} */ - u(this, "_MenuToggleType", J); + u(this, "_MenuToggleType", X); /** * The index of the currently selected menu item in the menu. * @@ -2877,9 +2916,9 @@ class H extends v { * @type {boolean} */ u(this, "_optionalSupport", !1); - this._optionalSupport = x, this._selectors.menuItems = s, this._selectors.submenuItems = i, this._selectors.submenuToggles = l, this._selectors.submenus = h, this._selectors.submenuSubtoggles = m, this._selectors.menuLinks = [ + this._optionalSupport = v, this._selectors.menuItems = s, this._selectors.submenuItems = i, this._selectors.submenuToggles = l, this._selectors.submenus = h, this._selectors.submenuSubtoggles = m, this._selectors.menuLinks = [ .../* @__PURE__ */ new Set([n, l]) - ].join(","), K && this.initialize(); + ].join(","), $ && this.initialize(); } /** * Initializes the menu. @@ -2915,7 +2954,7 @@ class H extends v { return this.isTopLevel ? this._optionalSupport : this.elements.rootMenu.optionalKeySupport; } set optionalKeySupport(t) { - d("boolean", { optionalKeySupport: t }), this._optionalSupport = t; + c("boolean", { optionalKeySupport: t }), this._optionalSupport = t; } /** * Creates and initializes all menu items and submenus. @@ -2988,11 +3027,11 @@ class H extends v { */ _validate() { let t = super._validate(); - const s = O({ + const s = x({ submenuSubtoggleSelector: this._selectors.submenuSubtoggles }); s.status || (this._errors.push(s.error.message), t = !1); - const n = d("boolean", { + const n = c("boolean", { optionalKeySupport: this._optionalSupport }); return n.status || (this._errors.push(n.error.message), t = !1), t; @@ -3105,7 +3144,7 @@ class H extends v { _handleKeydown() { super._handleKeydown(), this.dom.menu.addEventListener("keydown", (t) => { this.currentEvent = "keyboard"; - const s = y(t); + const s = _(t); if (this.focusState === "self") { const n = ["Space", "Enter"], i = ["Escape"], l = ["Escape"]; this.optionalKeySupport ? [ @@ -3144,14 +3183,14 @@ class H extends v { _handleKeyup() { super._handleKeyup(), this.dom.menu.addEventListener("keyup", (t) => { this.currentEvent = "keyboard"; - const s = y(t); + const s = _(t); this.focusState === "self" && (s === "Space" || s === "Enter" ? this.currentMenuItem.isSubmenuItem ? (o(t), this.currentMenuItem.elements.toggle.isOpen ? this.currentMenuItem.elements.toggle.close() : this.currentMenuItem.elements.toggle.preview()) : this.currentMenuItem.dom.link.click() : s === "Escape" ? this.elements.submenuToggles.some( (i) => i.isOpen ) ? (o(t), this.closeChildren()) : this.elements.parentMenu ? (o(t), this.elements.parentMenu.currentEvent = this.currentEvent, this.elements.parentMenu.closeChildren(), this.elements.parentMenu.focusCurrentChild()) : this.isTopLevel && this.elements.controller && this.elements.controller.isOpen && (this.elements.controller.close(), this.focusController()) : this.optionalKeySupport && (s === "ArrowDown" || s === "ArrowRight" ? (o(t), this.currentMenuItem.isSubmenuItem && this.currentMenuItem.elements.toggle.isOpen ? (this.currentMenuItem.elements.childMenu.currentEvent = "keyboard", this.currentMenuItem.elements.childMenu.focusFirstChild()) : this.focusNextChild()) : s === "ArrowUp" || s === "ArrowLeft" ? (o(t), this.focusPreviousChild()) : s === "Home" ? (o(t), this.focusFirstChild()) : s === "End" && (o(t), this.focusLastChild()))); }); } } -class X extends L { +class Y extends O { /** * Constructs a new `TreeviewItem`. * @@ -3214,7 +3253,7 @@ class X extends L { super.blur(), this.dom.link.tabIndex = -1; } } -class Y extends A { +class ee extends L { /** * Constructs a new `TreeviewToggle`. * @@ -3273,7 +3312,7 @@ class Y extends A { ); } } -class q extends v { +class j extends w { /** * Constructs a new `Treeview`. * @@ -3289,13 +3328,14 @@ class q extends v { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?Treeview} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. */ constructor({ @@ -3309,15 +3349,16 @@ class q extends v { containerElement: a = null, openClass: p = "show", closeClass: f = "hide", - transitionClass: c = "transitioning", - transitionDuration: _ = 250, + transitionClass: g = "transitioning", + transitionDuration: d = 250, isTopLevel: M = !0, - parentMenu: g = null, + parentMenu: y = null, hoverType: b = "off", hoverDelay: C = 250, enterDelay: T = -1, leaveDelay: E = -1, - initialize: I = !0 + prefix: I = "am-", + initialize: v = !0 }) { super({ menuElement: t, @@ -3330,14 +3371,15 @@ class q extends v { containerElement: a, openClass: p, closeClass: f, - transitionClass: c, - transitionDuration: _, + transitionClass: g, + transitionDuration: d, isTopLevel: M, - parentMenu: g, + parentMenu: y, hoverType: b, hoverDelay: C, enterDelay: T, - leaveDelay: E + leaveDelay: E, + prefix: I }); /** * The class to use when generating submenus. @@ -3346,7 +3388,7 @@ class q extends v { * * @type {typeof Treeview} */ - u(this, "_MenuType", q); + u(this, "_MenuType", j); /** * The class to use when generating menu items. * @@ -3354,7 +3396,7 @@ class q extends v { * * @type {typeof TreeviewItem} */ - u(this, "_MenuItemType", X); + u(this, "_MenuItemType", Y); /** * The class to use when generating submenu toggles. * @@ -3362,8 +3404,8 @@ class q extends v { * * @type {typeof TreeviewToggle} */ - u(this, "_MenuToggleType", Y); - I && this.initialize(); + u(this, "_MenuToggleType", ee); + v && this.initialize(); } /** * Initializes the menu. @@ -3466,7 +3508,7 @@ class q extends v { _handleKeydown() { super._handleKeydown(), this.dom.menu.addEventListener("keydown", (t) => { this.currentEvent = "keyboard"; - const s = y(t); + const s = _(t); if (s === "Tab" && (this.elements.rootMenu.focusState !== "none" ? this.elements.rootMenu.blur() : this.elements.rootMenu.focus()), this.focusState === "self") { const n = [ "Space", @@ -3507,7 +3549,7 @@ class q extends v { _handleKeyup() { super._handleKeyup(), this.dom.menu.addEventListener("keyup", (t) => { this.currentEvent = "keyboard"; - const s = y(t), { altKey: n, crtlKey: i, metaKey: l } = t; + const s = _(t), { altKey: n, crtlKey: i, metaKey: l } = t; if (s === "Character" && !(n || i || l)) o(t), this.elements.rootMenu.currentEvent = "character", this.focusNextNodeWithCharacter(t.key); else if (this.focusState === "self") @@ -3557,11 +3599,11 @@ class q extends v { focusNextNodeWithCharacter(t) { function s(p) { let f = []; - return p.elements.menuItems.forEach((c) => { - f.push(c), c.isSubmenuItem && c.elements.toggle.isOpen && (f = [ + return p.elements.menuItems.forEach((g) => { + f.push(g), g.isSubmenuItem && g.elements.toggle.isOpen && (f = [ ...f, ...s( - c.elements.toggle.elements.controlledMenu + g.elements.toggle.elements.controlledMenu ) ]); }), f; @@ -3575,8 +3617,8 @@ class q extends v { let p = ""; if (h[m].dom.item.innerText ? p = h[m].dom.item.innerText : p = h[m].dom.item.textContent, p = p.replace(/[\s]/g, "").toLowerCase().charAt(0), p === n) { a = !0; - const f = h[m].elements.parentMenu, c = f.elements.menuItems.indexOf(h[m]); - this.elements.rootMenu.blurChildren(), f.focusChild(c); + const f = h[m].elements.parentMenu, g = f.elements.menuItems.indexOf(h[m]); + this.elements.rootMenu.blurChildren(), f.focusChild(g); } m++; } @@ -3602,12 +3644,12 @@ class q extends v { this.currentMenuItem.elements.childMenu.currentEvent = this.currentEvent, this.currentMenuItem.elements.childMenu.focusLastChild(), this.currentMenuItem.elements.childMenu.currentMenuItem.isSubmenuItem && this.currentMenuItem.elements.childMenu.currentMenuItem.elements.toggle.isOpen && (this.currentMenuItem.elements.childMenu.blurCurrentChild(), this.currentMenuItem.elements.childMenu.focusChildsLastNode()); } } -const te = { - DisclosureMenu: $, - Menubar: z, - TopLinkDisclosureMenu: H, - Treeview: q +const se = { + DisclosureMenu: z, + Menubar: H, + TopLinkDisclosureMenu: q, + Treeview: j }; export { - te as default + se as default }; diff --git a/dist/accessible-menu.iife.js b/dist/accessible-menu.iife.js index eab9d4c7..228947a9 100644 --- a/dist/accessible-menu.iife.js +++ b/dist/accessible-menu.iife.js @@ -1,3 +1,3 @@ -var AccessibleMenu=function(){"use strict";var X=Object.defineProperty;var Y=(y,g,_)=>g in y?X(y,g,{enumerable:!0,configurable:!0,writable:!0,value:_}):y[g]=_;var u=(y,g,_)=>Y(y,typeof g!="symbol"?g+"":g,_);function y(r,e){r===""||r.length===0||(typeof r=="string"?e.classList.add(r):e.classList.add(...r))}function g(r,e){r===""||r.length===0||(typeof r=="string"?e.classList.remove(r):e.classList.remove(...r))}function _(r,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof r)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${r.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function a(r,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==r)throw new TypeError(`${t} must be a ${r}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function O(r){try{if(typeof r!="object"){const e=typeof r;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in r)try{if(r[e]===null)throw new Error;document.querySelector(r[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${r[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function k(r){try{if(typeof r!="object"||Array.isArray(r)){const e=typeof r;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in r){const t=typeof r[e];if(t!=="string")if(Array.isArray(r[e]))r[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=r[e],O(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function N(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function V(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function j(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function x(r,e){if(a("string",{tagName:r}).status&&_(HTMLElement,e).status){const t=r.toLowerCase();let s=!0;for(const n in e)e[n].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class A{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null}){u(this,"_dom",{toggle:null,parent:null});u(this,"_elements",{controlledMenu:null,parentMenu:null});u(this,"_open",!1);u(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));u(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=n}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){a("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",n=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),n=`${s}-${n}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${n}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${n}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:n,openDuration:i}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,n!==""?(y(n,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{g(n,this.elements.controlledMenu.dom.menu)},i)})})})):(y(s,this.elements.controlledMenu.dom.menu),g(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:n,closeDuration:i}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),n!==""?(y(n,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{g(n,this.elements.controlledMenu.dom.menu)},i)})})})):(y(t,this.elements.controlledMenu.dom.menu),g(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class L{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null}){u(this,"_dom",{item:null,link:null});u(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});u(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=i,this._elements.toggle=l,this._submenu=n}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function M(r){try{const e=r.key||r.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function o(r){r.preventDefault(),r.stopPropagation()}class D{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:n="li:has(ul)",submenuToggleSelector:i="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:m=null,openClass:d="show",closeClass:p="hide",transitionClass:f="transitioning",transitionDuration:c=250,openDuration:C=-1,closeDuration:T=-1,isTopLevel:b=!0,parentMenu:E=null,hoverType:I="off",hoverDelay:v=250,enterDelay:w=-1,leaveDelay:S=-1}){u(this,"_MenuType",D);u(this,"_MenuItemType",L);u(this,"_MenuToggleType",A);u(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});u(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});u(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});u(this,"_openClass","show");u(this,"_closeClass","hide");u(this,"_transitionClass","transitioning");u(this,"_transitionDuration",250);u(this,"_openDuration",-1);u(this,"_closeDuration",-1);u(this,"_root",!0);u(this,"_currentChild",0);u(this,"_focusState","none");u(this,"_currentEvent","none");u(this,"_hoverType","off");u(this,"_hoverDelay",250);u(this,"_enterDelay",-1);u(this,"_leaveDelay",-1);u(this,"_hoverTimeout",null);u(this,"_hasOpened",!1);u(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=m,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=n,this._selectors.submenuToggles=i,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=E,this._elements.rootMenu=b?this:null,this._openClass=d||"",this._closeClass=p||"",this._transitionClass=f||"",this._transitionDuration=c,this._openDuration=C,this._closeDuration=T,this._root=b,this._hoverType=I,this._hoverDelay=v,this._enterDelay=w,this._leaveDelay=S}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: +var AccessibleMenu=function(){"use strict";var Y=Object.defineProperty;var ee=(_,y,M)=>y in _?Y(_,y,{enumerable:!0,configurable:!0,writable:!0,value:M}):_[y]=M;var u=(_,y,M)=>ee(_,typeof y!="symbol"?y+"":y,M);function _(r,e){r===""||r.length===0||(typeof r=="string"?e.classList.add(r):e.classList.add(...r))}function y(r,e){r===""||r.length===0||(typeof r=="string"?e.classList.remove(r):e.classList.remove(...r))}function M(r,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof r)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${r.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function c(r,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==r)throw new TypeError(`${t} must be a ${r}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function x(r){try{if(typeof r!="object"){const e=typeof r;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in r)try{if(r[e]===null)throw new Error;document.querySelector(r[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${r[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function A(r){try{if(typeof r!="object"||Array.isArray(r)){const e=typeof r;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in r){const t=typeof r[e];if(t!=="string")if(Array.isArray(r[e]))r[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=r[e],x(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function V(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function P(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function N(r){try{if(typeof r!="object"){const t=typeof r;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in r)if(!e.includes(r[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${r[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function K(r,e){if(c("string",{tagName:r}).status&&M(HTMLElement,e).status){const t=r.toLowerCase();let s=!0;for(const n in e)e[n].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class L{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null}){u(this,"_dom",{toggle:null,parent:null});u(this,"_elements",{controlledMenu:null,parentMenu:null});u(this,"_open",!1);u(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));u(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=n}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){c("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",n=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),n=`${s}-${n}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${n}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${n}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:n,openDuration:i}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,n!==""?(_(n,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{y(n,this.elements.controlledMenu.dom.menu)},i)})})})):(_(s,this.elements.controlledMenu.dom.menu),y(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:n,closeDuration:i}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),n!==""?(_(n,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{y(n,this.elements.controlledMenu.dom.menu)},i)})})})):(_(t,this.elements.controlledMenu.dom.menu),y(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class O{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null}){u(this,"_dom",{item:null,link:null});u(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});u(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=i,this._elements.toggle=l,this._submenu=n}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function b(r){try{const e=r.key||r.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function o(r){r.preventDefault(),r.stopPropagation()}class k{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:n="li:has(ul)",submenuToggleSelector:i="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:m=null,openClass:a="show",closeClass:p="hide",transitionClass:f="transitioning",transitionDuration:g=250,openDuration:d=-1,closeDuration:T=-1,isTopLevel:C=!0,parentMenu:E=null,hoverType:I="off",hoverDelay:v=250,enterDelay:w=-1,leaveDelay:S=-1,prefix:D="am-"}){u(this,"_MenuType",k);u(this,"_MenuItemType",O);u(this,"_MenuToggleType",L);u(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});u(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});u(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});u(this,"_openClass","show");u(this,"_closeClass","hide");u(this,"_transitionClass","transitioning");u(this,"_transitionDuration",250);u(this,"_openDuration",-1);u(this,"_closeDuration",-1);u(this,"_root",!0);u(this,"_currentChild",0);u(this,"_focusState","none");u(this,"_currentEvent","none");u(this,"_hoverType","off");u(this,"_hoverDelay",250);u(this,"_enterDelay",-1);u(this,"_leaveDelay",-1);u(this,"_prefix","am-");u(this,"_hoverTimeout",null);u(this,"_hasOpened",!1);u(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=m,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=n,this._selectors.submenuToggles=i,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=E,this._elements.rootMenu=C?this:null,this._openClass=a||"",this._closeClass=p||"",this._transitionClass=f||"",this._transitionDuration=g,this._openDuration=d,this._closeDuration=T,this._prefix=D||"",this._root=C,this._hoverType=I,this._hoverDelay=v,this._enterDelay=w,this._leaveDelay=S}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: - ${this.errors.join(` - - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});x("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){k({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){k({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){k({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){a("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){a("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){a("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){a("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let i=0,l=!1;for(;!l&&i=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){N({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){V({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){j({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){a("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){a("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){a("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set hasOpened(e){a("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=_(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=_(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=O({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=O({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const c=k({openClass:this._openClass});c.status||(this._errors.push(c.error.message),e=!1)}if(this._closeClass!==""){const c=k({closeClass:this._closeClass});c.status||(this._errors.push(c.error.message),e=!1)}if(this._transitionClass!==""){const c=k({transitionClass:this._transitionClass});c.status||(this._errors.push(c.error.message),e=!1)}const n=a("number",{transitionDuration:this._transitionDuration});n.status||(this._errors.push(n.error.message),e=!1);const i=a("number",{openDuration:this._openDuration});i.status||(this._errors.push(i.error.message),e=!1);const l=a("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=a("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const c=_(D,{parentMenu:this._elements.parentMenu});c.status||(this._errors.push(c.error.message),e=!1)}const m=j({hoverType:this._hoverType});m.status||(this._errors.push(m.error.message),e=!1);const d=a("number",{hoverDelay:this._hoverDelay});d.status||(this._errors.push(d.error.message),e=!1);const p=a("number",{enterDelay:this._enterDelay});p.status||(this._errors.push(p.error.message),e=!1);const f=a("number",{leaveDelay:this._leaveDelay});return f.status||(this._errors.push(f.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&_(HTMLElement,{base:t});const i=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=i:this._dom[e]=[...this._dom[e],...i]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),n=e.querySelector(this.selectors.submenus),i=new this._MenuType({menuElement:n,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:i,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:i,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){a("function",{callback:e}),a("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,n){o(n),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",n=>{this.currentEvent="mouse",e(this,t.elements.toggle,n)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&o(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&(o(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty("--am-transition-duration",`${this.transitionDuration}ms`),this.dom.menu.style.setProperty("--am-open-transition-duration",`${this.openDuration}ms`),this.dom.menu.style.setProperty("--am-close-transition-duration",`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class P extends L{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}}class R extends A{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),x("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class K extends D{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="button",submenuSelector:h="ul",controllerElement:m=null,containerElement:d=null,openClass:p="show",closeClass:f="hide",transitionClass:c="transitioning",transitionDuration:C=250,openDuration:T=-1,closeDuration:b=-1,isTopLevel:E=!0,parentMenu:I=null,hoverType:v="off",hoverDelay:w=250,enterDelay:S=-1,leaveDelay:H=-1,optionalKeySupport:q=!1,initialize:J=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:d,openClass:p,closeClass:f,transitionClass:c,transitionDuration:C,openDuration:T,closeDuration:b,isTopLevel:E,parentMenu:I,hoverType:v,hoverDelay:w,enterDelay:S,leaveDelay:H});u(this,"_MenuType",K);u(this,"_MenuItemType",P);u(this,"_MenuToggleType",R);u(this,"_currentChild",-1);u(this,"_optionalSupport",!1);this._optionalSupport=q,J&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){a("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_validate(){let t=super._validate();const s=a("boolean",{optionalKeySupport:this._optionalSupport});return s.status||(this._errors.push(s.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=M(t);if(this.focusState==="self"){const n=["Space","Enter"],i=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&o(t):(this.currentMenuItem.isSubmenuItem&&n.includes(s)||this.elements.controller&&i.includes(s)||this.elements.parentMenu&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=M(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(i=>i.isOpen)?(o(t),this.closeChildren()):this.elements.parentMenu?(o(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())))})}}class U extends L{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","menuitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=0)}blur(){super.blur(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=-1)}}class W extends A{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),this.dom.toggle.setAttribute("aria-haspopup","true")}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&(this.closeChildren(),this.elements.parentMenu&&this.elements.parentMenu.focusCurrentChild()),super.close()}}class F extends D{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:m=null,containerElement:d=null,openClass:p="show",closeClass:f="hide",transitionClass:c="transitioning",transitionDuration:C=250,isTopLevel:T=!0,parentMenu:b=null,hoverType:E="off",hoverDelay:I=250,enterDelay:v=-1,leaveDelay:w=-1,initialize:S=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:d,openClass:p,closeClass:f,transitionClass:c,transitionDuration:C,isTopLevel:T,parentMenu:b,hoverType:E,hoverDelay:I,enterDelay:v,leaveDelay:w});u(this,"_MenuType",F);u(this,"_MenuItemType",U);u(this,"_MenuToggleType",W);S&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?this.dom.menu.setAttribute("role","menubar"):this.dom.menu.setAttribute("role","menu"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&(this.elements.menuItems[0].dom.link.tabIndex=0,this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-haspopup"))}catch(t){console.error(t)}}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=M(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?(this.elements.rootMenu.blur(),this.elements.rootMenu.closeChildren()):this.elements.rootMenu.focus()),s==="Character")o(t);else if(this.isTopLevel){if(this.focusState==="self"){const n=["ArrowRight","ArrowLeft","Home","End"],i=["Space","Enter","ArrowDown","ArrowUp"],l=["Escape"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&l.includes(s))&&o(t)}}else{const n=["Escape","ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"],i=["Space","Enter"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=M(t),{altKey:n,crtlKey:i,metaKey:l}=t;if(s==="Character"&&!(n||i||l))o(t),this.elements.rootMenu.currentEvent="character",this.focusNextChildWithCharacter(t.key);else if(this.isTopLevel){if(this.focusState==="self")if(s==="Space"||s==="Enter")this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click();else if(s==="ArrowRight"){o(t);const m=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusNextChild(),m&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else if(s==="ArrowLeft"){o(t);const m=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusPreviousChild(),m&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else s==="ArrowDown"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):s==="ArrowUp"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusLastChild()})):s==="Home"?(o(t),this.focusFirstChild()):s==="End"?(o(t),this.focusLastChild()):s==="Escape"&&(this.elements.submenuToggles.some(d=>d.isOpen)?(o(t),this.closeChildren()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(o(t),this.elements.controller.close(),this.focusController()))}else s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click():s==="Escape"?(o(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusCurrentChild()):s==="ArrowRight"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):(o(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusNextChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&this.elements.rootMenu.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?this.elements.parentMenu.currentMenuItem.isSubmenuItem&&(o(t),this.elements.parentMenu.currentMenuItem.elements.toggle.close(),this.elements.parentMenu.focusCurrentChild(),this.elements.parentMenu===this.elements.rootMenu&&(this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusPreviousChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&(this.elements.rootMenu.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.elements.rootMenu.currentMenuItem.elements.toggle.preview()))):s==="ArrowDown"?(o(t),this.focusNextChild()):s==="ArrowUp"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())})}focusNextChild(){this.currentChild===this.elements.menuItems.length-1?this.focusFirstChild():this.focusChild(this.currentChild+1)}focusPreviousChild(){this.currentChild===0?this.focusLastChild():this.focusChild(this.currentChild-1)}focusNextChildWithCharacter(t){const s=t.toLowerCase();let n=this.currentChild+1,i=!1;for(;!i&&n{let s,n;const i=t.querySelector(this.selectors.menuLinks);if(this.dom.submenuItems.includes(t)){const l=t.querySelector(this.selectors.submenuToggles),h=t.querySelector(this.selectors.submenus),m=new this._MenuType({menuElement:h,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuSubtoggles,submenuSelector:this.selectors.submenus,submenuSubtoggleSelector:this.selectors.submenuSubtoggles,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),d=new this._MenuToggleType({menuToggleElement:l,parentElement:t,controlledMenu:m,parentMenu:this});this._elements.submenuToggles.push(d),l!==i?(n=new this._MenuItemType({menuItemElement:t,menuLinkElement:l,parentMenu:this,isSubmenuItem:!0,childMenu:m,toggle:d}),s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this,submenuSibling:n})):s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this,isSubmenuItem:!0,childMenu:m,toggle:d})}else s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this});this._elements.menuItems.push(s),typeof n<"u"&&this._elements.menuItems.push(n)})}_validate(){let t=super._validate();const s=O({submenuSubtoggleSelector:this._selectors.submenuSubtoggles});s.status||(this._errors.push(s.error.message),t=!1);const n=a("boolean",{optionalKeySupport:this._optionalSupport});return n.status||(this._errors.push(n.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",n=>{if(!(n.pointerType==="pen"||n.pointerType==="touch")){if(this.hoverType==="on"){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s);let i=t.isSubmenuItem?t.elements.toggle:null;if(t.elements.sibling!==null&&(i=t.elements.sibling.elements.toggle),i===null)return;this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{i.preview()},this.enterDelay)):i.preview()}else if(this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),!this.isTopLevel||this.hasOpened)){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild();let i=t.isSubmenuItem?t.elements.toggle:null;t.elements.sibling!==null&&(i=t.elements.sibling.elements.toggle),i!==null?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{i.preview()},this.enterDelay)):i.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren()}}}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",t.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",t.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=M(t);if(this.focusState==="self"){const n=["Space","Enter"],i=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&o(t):(this.currentMenuItem.isSubmenuItem&&n.includes(s)||this.elements.controller&&i.includes(s)||this.elements.parentMenu&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=M(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(i=>i.isOpen)?(o(t),this.closeChildren()):this.elements.parentMenu?(o(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())))})}}class B extends L{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","treeitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.dom.link.tabIndex=0}blur(){super.blur(),this.dom.link.tabIndex=-1}}class G extends A{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}initialize(){this._setIds(),this._setAriaAttributes(),this.dom.toggle.getAttribute("aria-expanded")==="true"?this.open():this._collapse(!1)}_setAriaAttributes(){this.dom.toggle.getAttribute("aria-expanded")!=="true"&&this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id),this.dom.toggle.setAttribute("aria-owns",this.elements.controlledMenu.dom.menu.id)}}class z extends D{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:m=null,containerElement:d=null,openClass:p="show",closeClass:f="hide",transitionClass:c="transitioning",transitionDuration:C=250,isTopLevel:T=!0,parentMenu:b=null,hoverType:E="off",hoverDelay:I=250,enterDelay:v=-1,leaveDelay:w=-1,initialize:S=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:d,openClass:p,closeClass:f,transitionClass:c,transitionDuration:C,isTopLevel:T,parentMenu:b,hoverType:E,hoverDelay:I,enterDelay:v,leaveDelay:w});u(this,"_MenuType",z);u(this,"_MenuItemType",B);u(this,"_MenuToggleType",G);S&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?(this.dom.menu.setAttribute("role","tree"),this.elements.menuItems[0].dom.link.tabIndex=0):this.dom.menu.setAttribute("role","group"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-owns")}catch(t){console.error(t)}}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s),t.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),t.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview():this.enterDelay>0&&this._clearTimeout())))}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0&&this._clearTimeout():this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()})),this.isTopLevel&&this.dom.menu.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||this.hoverType==="on"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren(),this.blur()},this.leaveDelay)):(this.closeChildren(),this.blur()))})})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=M(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?this.elements.rootMenu.blur():this.elements.rootMenu.focus()),this.focusState==="self"){const n=["Space","ArrowUp","ArrowDown","ArrowLeft","Asterisk","Home","End"],i=["Enter","ArrowRight"],l=["Escape"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=M(t),{altKey:n,crtlKey:i,metaKey:l}=t;if(s==="Character"&&!(n||i||l))o(t),this.elements.rootMenu.currentEvent="character",this.focusNextNodeWithCharacter(t.key);else if(this.focusState==="self")if(s==="Enter"||s==="Space")o(t),this.currentMenuItem.isSubmenuItem?this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview():this.currentMenuItem.dom.link.click();else if(s==="Escape")this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController());else if(s==="ArrowDown")o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):!this.isTopLevel&&this.currentChild===this.elements.menuItems.length-1?this.focusParentsNextChild():this.focusNextChild();else if(s==="ArrowUp"){o(t);const m=this.elements.menuItems[this.currentChild-1];m&&m.isSubmenuItem&&m.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentChild=this.currentChild-1,this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.focusChildsLastNode()):!this.isTopLevel&&this.currentChild===0?(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild()):this.focusPreviousChild()}else s==="ArrowRight"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):this.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.blurCurrentChild(),this.currentMenuItem.elements.toggle.close()):this.isTopLevel||(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild())):s==="Home"?(o(t),this.blurCurrentChild(),this.elements.rootMenu.focusFirstChild()):s==="End"?(o(t),this.blurCurrentChild(),this.elements.rootMenu.focusLastNode()):s==="Asterisk"&&(o(t),this.openChildren())})}focusLastNode(){const t=this.elements.menuItems.length-1,s=this.elements.menuItems[t];s.isSubmenuItem&&s.elements.toggle.isOpen?(this.currentChild=t,s.elements.childMenu.currentEvent=this.currentEvent,s.elements.childMenu.focusLastNode()):this.focusLastChild()}openChildren(){this.elements.submenuToggles.forEach(t=>t.preview())}focusNextNodeWithCharacter(t){function s(p){let f=[];return p.elements.menuItems.forEach(c=>{f.push(c),c.isSubmenuItem&&c.elements.toggle.isOpen&&(f=[...f,...s(c.elements.toggle.elements.controlledMenu)])}),f}const n=t.toLowerCase(),i=s(this.elements.rootMenu),l=i.indexOf(this.currentMenuItem)+1,h=[...i.slice(l),...i.slice(0,l)];let m=0,d=!1;for(;!d&&m=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){V({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){P({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){N({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){c("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){c("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){c("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set prefix(e){c("string",{value:e}),this._prefix!==e&&(this._prefix=e)}set hasOpened(e){c("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=M(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=M(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=x({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=x({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const d=A({openClass:this._openClass});d.status||(this._errors.push(d.error.message),e=!1)}if(this._closeClass!==""){const d=A({closeClass:this._closeClass});d.status||(this._errors.push(d.error.message),e=!1)}if(this._transitionClass!==""){const d=A({transitionClass:this._transitionClass});d.status||(this._errors.push(d.error.message),e=!1)}const n=c("number",{transitionDuration:this._transitionDuration});n.status||(this._errors.push(n.error.message),e=!1);const i=c("number",{openDuration:this._openDuration});i.status||(this._errors.push(i.error.message),e=!1);const l=c("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=c("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const d=M(k,{parentMenu:this._elements.parentMenu});d.status||(this._errors.push(d.error.message),e=!1)}const m=N({hoverType:this._hoverType});m.status||(this._errors.push(m.error.message),e=!1);const a=c("number",{hoverDelay:this._hoverDelay});a.status||(this._errors.push(a.error.message),e=!1);const p=c("number",{enterDelay:this._enterDelay});p.status||(this._errors.push(p.error.message),e=!1);const f=c("number",{leaveDelay:this._leaveDelay});f.status||(this._errors.push(f.error.message),e=!1);const g=c("string",{prefix:this._prefix});return g.status||(this._errors.push(g.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&M(HTMLElement,{base:t});const i=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=i:this._dom[e]=[...this._dom[e],...i]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),n=e.querySelector(this.selectors.submenus),i=new this._MenuType({menuElement:n,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:i,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:i,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){c("function",{callback:e}),c("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,n){o(n),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",n=>{this.currentEvent="mouse",e(this,t.elements.toggle,n)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=b(e);(t==="Space"||t==="Enter")&&o(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=b(e);(t==="Space"||t==="Enter")&&(o(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty(`--${this.prefix}transition-duration`,`${this.transitionDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}open-transition-duration`,`${this.openDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}close-transition-duration`,`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class R extends O{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}}class U extends L{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),K("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class $ extends k{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="button",submenuSelector:h="ul",controllerElement:m=null,containerElement:a=null,openClass:p="show",closeClass:f="hide",transitionClass:g="transitioning",transitionDuration:d=250,openDuration:T=-1,closeDuration:C=-1,isTopLevel:E=!0,parentMenu:I=null,hoverType:v="off",hoverDelay:w=250,enterDelay:S=-1,leaveDelay:D=-1,optionalKeySupport:q=!1,prefix:j="am-",initialize:X=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:a,openClass:p,closeClass:f,transitionClass:g,transitionDuration:d,openDuration:T,closeDuration:C,isTopLevel:E,parentMenu:I,hoverType:v,hoverDelay:w,enterDelay:S,leaveDelay:D,prefix:j});u(this,"_MenuType",$);u(this,"_MenuItemType",R);u(this,"_MenuToggleType",U);u(this,"_currentChild",-1);u(this,"_optionalSupport",!1);this._optionalSupport=q,X&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){c("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_validate(){let t=super._validate();const s=c("boolean",{optionalKeySupport:this._optionalSupport});return s.status||(this._errors.push(s.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=b(t);if(this.focusState==="self"){const n=["Space","Enter"],i=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&o(t):(this.currentMenuItem.isSubmenuItem&&n.includes(s)||this.elements.controller&&i.includes(s)||this.elements.parentMenu&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=b(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(i=>i.isOpen)?(o(t),this.closeChildren()):this.elements.parentMenu?(o(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())))})}}class W extends O{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","menuitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=0)}blur(){super.blur(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=-1)}}class Z extends L{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),this.dom.toggle.setAttribute("aria-haspopup","true")}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&(this.closeChildren(),this.elements.parentMenu&&this.elements.parentMenu.focusCurrentChild()),super.close()}}class F extends k{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:m=null,containerElement:a=null,openClass:p="show",closeClass:f="hide",transitionClass:g="transitioning",transitionDuration:d=250,isTopLevel:T=!0,parentMenu:C=null,hoverType:E="off",hoverDelay:I=250,enterDelay:v=-1,leaveDelay:w=-1,prefix:S="am-",initialize:D=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:a,openClass:p,closeClass:f,transitionClass:g,transitionDuration:d,isTopLevel:T,parentMenu:C,hoverType:E,hoverDelay:I,enterDelay:v,leaveDelay:w,prefix:S});u(this,"_MenuType",F);u(this,"_MenuItemType",W);u(this,"_MenuToggleType",Z);D&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?this.dom.menu.setAttribute("role","menubar"):this.dom.menu.setAttribute("role","menu"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&(this.elements.menuItems[0].dom.link.tabIndex=0,this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-haspopup"))}catch(t){console.error(t)}}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=b(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?(this.elements.rootMenu.blur(),this.elements.rootMenu.closeChildren()):this.elements.rootMenu.focus()),s==="Character")o(t);else if(this.isTopLevel){if(this.focusState==="self"){const n=["ArrowRight","ArrowLeft","Home","End"],i=["Space","Enter","ArrowDown","ArrowUp"],l=["Escape"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&l.includes(s))&&o(t)}}else{const n=["Escape","ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"],i=["Space","Enter"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=b(t),{altKey:n,crtlKey:i,metaKey:l}=t;if(s==="Character"&&!(n||i||l))o(t),this.elements.rootMenu.currentEvent="character",this.focusNextChildWithCharacter(t.key);else if(this.isTopLevel){if(this.focusState==="self")if(s==="Space"||s==="Enter")this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click();else if(s==="ArrowRight"){o(t);const m=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusNextChild(),m&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else if(s==="ArrowLeft"){o(t);const m=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusPreviousChild(),m&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else s==="ArrowDown"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):s==="ArrowUp"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusLastChild()})):s==="Home"?(o(t),this.focusFirstChild()):s==="End"?(o(t),this.focusLastChild()):s==="Escape"&&(this.elements.submenuToggles.some(a=>a.isOpen)?(o(t),this.closeChildren()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(o(t),this.elements.controller.close(),this.focusController()))}else s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click():s==="Escape"?(o(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusCurrentChild()):s==="ArrowRight"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):(o(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusNextChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&this.elements.rootMenu.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?this.elements.parentMenu.currentMenuItem.isSubmenuItem&&(o(t),this.elements.parentMenu.currentMenuItem.elements.toggle.close(),this.elements.parentMenu.focusCurrentChild(),this.elements.parentMenu===this.elements.rootMenu&&(this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusPreviousChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&(this.elements.rootMenu.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.elements.rootMenu.currentMenuItem.elements.toggle.preview()))):s==="ArrowDown"?(o(t),this.focusNextChild()):s==="ArrowUp"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())})}focusNextChild(){this.currentChild===this.elements.menuItems.length-1?this.focusFirstChild():this.focusChild(this.currentChild+1)}focusPreviousChild(){this.currentChild===0?this.focusLastChild():this.focusChild(this.currentChild-1)}focusNextChildWithCharacter(t){const s=t.toLowerCase();let n=this.currentChild+1,i=!1;for(;!i&&n{let s,n;const i=t.querySelector(this.selectors.menuLinks);if(this.dom.submenuItems.includes(t)){const l=t.querySelector(this.selectors.submenuToggles),h=t.querySelector(this.selectors.submenus),m=new this._MenuType({menuElement:h,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuSubtoggles,submenuSelector:this.selectors.submenus,submenuSubtoggleSelector:this.selectors.submenuSubtoggles,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),a=new this._MenuToggleType({menuToggleElement:l,parentElement:t,controlledMenu:m,parentMenu:this});this._elements.submenuToggles.push(a),l!==i?(n=new this._MenuItemType({menuItemElement:t,menuLinkElement:l,parentMenu:this,isSubmenuItem:!0,childMenu:m,toggle:a}),s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this,submenuSibling:n})):s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this,isSubmenuItem:!0,childMenu:m,toggle:a})}else s=new this._MenuItemType({menuItemElement:t,menuLinkElement:i,parentMenu:this});this._elements.menuItems.push(s),typeof n<"u"&&this._elements.menuItems.push(n)})}_validate(){let t=super._validate();const s=x({submenuSubtoggleSelector:this._selectors.submenuSubtoggles});s.status||(this._errors.push(s.error.message),t=!1);const n=c("boolean",{optionalKeySupport:this._optionalSupport});return n.status||(this._errors.push(n.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",n=>{if(!(n.pointerType==="pen"||n.pointerType==="touch")){if(this.hoverType==="on"){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s);let i=t.isSubmenuItem?t.elements.toggle:null;if(t.elements.sibling!==null&&(i=t.elements.sibling.elements.toggle),i===null)return;this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{i.preview()},this.enterDelay)):i.preview()}else if(this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),!this.isTopLevel||this.hasOpened)){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild();let i=t.isSubmenuItem?t.elements.toggle:null;t.elements.sibling!==null&&(i=t.elements.sibling.elements.toggle),i!==null?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{i.preview()},this.enterDelay)):i.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren()}}}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",t.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",t.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=b(t);if(this.focusState==="self"){const n=["Space","Enter"],i=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&o(t):(this.currentMenuItem.isSubmenuItem&&n.includes(s)||this.elements.controller&&i.includes(s)||this.elements.parentMenu&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=b(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(o(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(i=>i.isOpen)?(o(t),this.closeChildren()):this.elements.parentMenu?(o(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(o(t),this.focusPreviousChild()):s==="Home"?(o(t),this.focusFirstChild()):s==="End"&&(o(t),this.focusLastChild())))})}}class G extends O{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n=!1,childMenu:i=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:n,childMenu:i,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","treeitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.dom.link.tabIndex=0}blur(){super.blur(),this.dom.link.tabIndex=-1}}class J extends L{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n=null,initialize:i=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:n}),i&&this.initialize()}initialize(){this._setIds(),this._setAriaAttributes(),this.dom.toggle.getAttribute("aria-expanded")==="true"?this.open():this._collapse(!1)}_setAriaAttributes(){this.dom.toggle.getAttribute("aria-expanded")!=="true"&&this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id),this.dom.toggle.setAttribute("aria-owns",this.elements.controlledMenu.dom.menu.id)}}class H extends k{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:n="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:m=null,containerElement:a=null,openClass:p="show",closeClass:f="hide",transitionClass:g="transitioning",transitionDuration:d=250,isTopLevel:T=!0,parentMenu:C=null,hoverType:E="off",hoverDelay:I=250,enterDelay:v=-1,leaveDelay:w=-1,prefix:S="am-",initialize:D=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:n,submenuItemSelector:i,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:a,openClass:p,closeClass:f,transitionClass:g,transitionDuration:d,isTopLevel:T,parentMenu:C,hoverType:E,hoverDelay:I,enterDelay:v,leaveDelay:w,prefix:S});u(this,"_MenuType",H);u(this,"_MenuItemType",G);u(this,"_MenuToggleType",J);D&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?(this.dom.menu.setAttribute("role","tree"),this.elements.menuItems[0].dom.link.tabIndex=0):this.dom.menu.setAttribute("role","group"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-owns")}catch(t){console.error(t)}}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s),t.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),t.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview():this.enterDelay>0&&this._clearTimeout())))}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0&&this._clearTimeout():this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",n=>{n.pointerType==="pen"||n.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()})),this.isTopLevel&&this.dom.menu.addEventListener("pointerleave",n=>{n.pointerType==="pen"||n.pointerType==="touch"||this.hoverType==="on"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren(),this.blur()},this.leaveDelay)):(this.closeChildren(),this.blur()))})})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=b(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?this.elements.rootMenu.blur():this.elements.rootMenu.focus()),this.focusState==="self"){const n=["Space","ArrowUp","ArrowDown","ArrowLeft","Asterisk","Home","End"],i=["Enter","ArrowRight"],l=["Escape"];(n.includes(s)||this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&l.includes(s))&&o(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=b(t),{altKey:n,crtlKey:i,metaKey:l}=t;if(s==="Character"&&!(n||i||l))o(t),this.elements.rootMenu.currentEvent="character",this.focusNextNodeWithCharacter(t.key);else if(this.focusState==="self")if(s==="Enter"||s==="Space")o(t),this.currentMenuItem.isSubmenuItem?this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview():this.currentMenuItem.dom.link.click();else if(s==="Escape")this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController());else if(s==="ArrowDown")o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):!this.isTopLevel&&this.currentChild===this.elements.menuItems.length-1?this.focusParentsNextChild():this.focusNextChild();else if(s==="ArrowUp"){o(t);const m=this.elements.menuItems[this.currentChild-1];m&&m.isSubmenuItem&&m.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentChild=this.currentChild-1,this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.focusChildsLastNode()):!this.isTopLevel&&this.currentChild===0?(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild()):this.focusPreviousChild()}else s==="ArrowRight"?this.currentMenuItem.isSubmenuItem&&(o(t),this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):this.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?(o(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.blurCurrentChild(),this.currentMenuItem.elements.toggle.close()):this.isTopLevel||(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild())):s==="Home"?(o(t),this.blurCurrentChild(),this.elements.rootMenu.focusFirstChild()):s==="End"?(o(t),this.blurCurrentChild(),this.elements.rootMenu.focusLastNode()):s==="Asterisk"&&(o(t),this.openChildren())})}focusLastNode(){const t=this.elements.menuItems.length-1,s=this.elements.menuItems[t];s.isSubmenuItem&&s.elements.toggle.isOpen?(this.currentChild=t,s.elements.childMenu.currentEvent=this.currentEvent,s.elements.childMenu.focusLastNode()):this.focusLastChild()}openChildren(){this.elements.submenuToggles.forEach(t=>t.preview())}focusNextNodeWithCharacter(t){function s(p){let f=[];return p.elements.menuItems.forEach(g=>{f.push(g),g.isSubmenuItem&&g.elements.toggle.isOpen&&(f=[...f,...s(g.elements.toggle.elements.controlledMenu)])}),f}const n=t.toLowerCase(),i=s(this.elements.rootMenu),l=i.indexOf(this.currentMenuItem)+1,h=[...i.slice(l),...i.slice(0,l)];let m=0,a=!1;for(;!a&&me in n?q(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>z(n,typeof e!="symbol"?e+"":e,t);function g(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function _(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function b(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function l(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function I(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function y(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],I(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function H(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function P(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function O(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function $(n,e){if(l("string",{tagName:n}).status&&b(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class F{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){o(this,"_dom",{toggle:null,parent:null});o(this,"_elements",{controlledMenu:null,parentMenu:null});o(this,"_open",!1);o(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));o(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){l("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(g(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{_(i,this.elements.controlledMenu.dom.menu)},r)})})})):(g(s,this.elements.controlledMenu.dom.menu),_(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(g(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{_(i,this.elements.controlledMenu.dom.menu)},r)})})})):(g(t,this.elements.controlledMenu.dom.menu),_(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class j{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:u=null}){o(this,"_dom",{item:null,link:null});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});o(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=r,this._elements.toggle=u,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function M(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function a(n){n.preventDefault(),n.stopPropagation()}class E{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:r="a",submenuSelector:u="ul",controllerElement:c=null,containerElement:m=null,openClass:d="show",closeClass:f="hide",transitionClass:p="transitioning",transitionDuration:h=250,openDuration:T=-1,closeDuration:D=-1,isTopLevel:C=!0,parentMenu:v=null,hoverType:w="off",hoverDelay:S=250,enterDelay:k=-1,leaveDelay:A=-1}){o(this,"_MenuType",E);o(this,"_MenuItemType",j);o(this,"_MenuToggleType",F);o(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});o(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});o(this,"_openClass","show");o(this,"_closeClass","hide");o(this,"_transitionClass","transitioning");o(this,"_transitionDuration",250);o(this,"_openDuration",-1);o(this,"_closeDuration",-1);o(this,"_root",!0);o(this,"_currentChild",0);o(this,"_focusState","none");o(this,"_currentEvent","none");o(this,"_hoverType","off");o(this,"_hoverDelay",250);o(this,"_enterDelay",-1);o(this,"_leaveDelay",-1);o(this,"_hoverTimeout",null);o(this,"_hasOpened",!1);o(this,"_errors",[]);this._dom.menu=e,this._dom.controller=c,this._dom.container=m,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=r,this._selectors.submenus=u,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=v,this._elements.rootMenu=C?this:null,this._openClass=d||"",this._closeClass=f||"",this._transitionClass=p||"",this._transitionDuration=h,this._openDuration=T,this._closeDuration=D,this._root=C,this._hoverType=w,this._hoverDelay=S,this._enterDelay=k,this._leaveDelay=A}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: +"use strict";var z=Object.defineProperty;var H=(n,e,t)=>e in n?z(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var r=(n,e,t)=>H(n,typeof e!="symbol"?e+"":e,t);function _(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function y(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function C(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function l(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function L(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function b(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],L(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function P(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function R(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function $(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function x(n,e){if(l("string",{tagName:n}).status&&C(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class F{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){r(this,"_dom",{toggle:null,parent:null});r(this,"_elements",{controlledMenu:null,parentMenu:null});r(this,"_open",!1);r(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));r(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){l("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(_(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{y(i,this.elements.controlledMenu.dom.menu)},o)})})})):(_(s,this.elements.controlledMenu.dom.menu),y(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(_(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{y(i,this.elements.controlledMenu.dom.menu)},o)})})})):(_(t,this.elements.controlledMenu.dom.menu),y(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class j{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:o=null,toggle:u=null}){r(this,"_dom",{item:null,link:null});r(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});r(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=o,this._elements.toggle=u,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function E(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function a(n){n.preventDefault(),n.stopPropagation()}class T{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:o="a",submenuSelector:u="ul",controllerElement:c=null,containerElement:m=null,openClass:f="show",closeClass:d="hide",transitionClass:p="transitioning",transitionDuration:g=250,openDuration:h=-1,closeDuration:D=-1,isTopLevel:M=!0,parentMenu:v=null,hoverType:w="off",hoverDelay:S=250,enterDelay:k=-1,leaveDelay:A=-1,prefix:I="am-"}){r(this,"_MenuType",T);r(this,"_MenuItemType",j);r(this,"_MenuToggleType",F);r(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});r(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});r(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});r(this,"_openClass","show");r(this,"_closeClass","hide");r(this,"_transitionClass","transitioning");r(this,"_transitionDuration",250);r(this,"_openDuration",-1);r(this,"_closeDuration",-1);r(this,"_root",!0);r(this,"_currentChild",0);r(this,"_focusState","none");r(this,"_currentEvent","none");r(this,"_hoverType","off");r(this,"_hoverDelay",250);r(this,"_enterDelay",-1);r(this,"_leaveDelay",-1);r(this,"_prefix","am-");r(this,"_hoverTimeout",null);r(this,"_hasOpened",!1);r(this,"_errors",[]);this._dom.menu=e,this._dom.controller=c,this._dom.container=m,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=o,this._selectors.submenus=u,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=v,this._elements.rootMenu=M?this:null,this._openClass=f||"",this._closeClass=d||"",this._transitionClass=p||"",this._transitionDuration=g,this._openDuration=h,this._closeDuration=D,this._prefix=I||"",this._root=M,this._hoverType=w,this._hoverDelay=S,this._enterDelay=k,this._leaveDelay=A}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: - ${this.errors.join(` - - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});$("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){y({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){y({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){y({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){l("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){l("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){l("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){l("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let r=0,u=!1;for(;!u&&r=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){H({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){P({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){O({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){l("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){l("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){l("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set hasOpened(e){l("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=b(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=b(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=I({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=I({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const h=y({openClass:this._openClass});h.status||(this._errors.push(h.error.message),e=!1)}if(this._closeClass!==""){const h=y({closeClass:this._closeClass});h.status||(this._errors.push(h.error.message),e=!1)}if(this._transitionClass!==""){const h=y({transitionClass:this._transitionClass});h.status||(this._errors.push(h.error.message),e=!1)}const i=l("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const r=l("number",{openDuration:this._openDuration});r.status||(this._errors.push(r.error.message),e=!1);const u=l("number",{closeDuration:this._closeDuration});u.status||(this._errors.push(u.error.message),e=!1);const c=l("boolean",{isTopLevel:this._root});if(c.status||(this._errors.push(c.error.message),e=!1),this._elements.parentMenu!==null){const h=b(E,{parentMenu:this._elements.parentMenu});h.status||(this._errors.push(h.error.message),e=!1)}const m=O({hoverType:this._hoverType});m.status||(this._errors.push(m.error.message),e=!1);const d=l("number",{hoverDelay:this._hoverDelay});d.status||(this._errors.push(d.error.message),e=!1);const f=l("number",{enterDelay:this._enterDelay});f.status||(this._errors.push(f.error.message),e=!1);const p=l("number",{leaveDelay:this._leaveDelay});return p.status||(this._errors.push(p.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&b(HTMLElement,{base:t});const r=Array.from(t.querySelectorAll(this.selectors[e])).filter(u=>u.parentElement===t);s?this._dom[e]=r:this._dom[e]=[...this._dom[e],...r]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),r=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),u=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:r,parentMenu:this});this._elements.submenuToggles.push(u),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:r,toggle:u})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){l("function",{callback:e}),l("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){a(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&a(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&(a(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty("--am-transition-duration",`${this.transitionDuration}ms`),this.dom.menu.style.setProperty("--am-open-transition-duration",`${this.openDuration}ms`),this.dom.menu.style.setProperty("--am-close-transition-duration",`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class R extends j{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:u=null,initialize:c=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:r,toggle:u}),c&&this.initialize()}}class U extends F{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:r=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),r&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),$("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class L extends E{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:r="li:has(ul)",submenuToggleSelector:u="button",submenuSelector:c="ul",controllerElement:m=null,containerElement:d=null,openClass:f="show",closeClass:p="hide",transitionClass:h="transitioning",transitionDuration:T=250,openDuration:D=-1,closeDuration:C=-1,isTopLevel:v=!0,parentMenu:w=null,hoverType:S="off",hoverDelay:k=250,enterDelay:A=-1,leaveDelay:K=-1,optionalKeySupport:V=!1,initialize:x=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:r,submenuToggleSelector:u,submenuSelector:c,controllerElement:m,containerElement:d,openClass:f,closeClass:p,transitionClass:h,transitionDuration:T,openDuration:D,closeDuration:C,isTopLevel:v,parentMenu:w,hoverType:S,hoverDelay:k,enterDelay:A,leaveDelay:K});o(this,"_MenuType",L);o(this,"_MenuItemType",R);o(this,"_MenuToggleType",U);o(this,"_currentChild",-1);o(this,"_optionalSupport",!1);this._optionalSupport=V,x&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){l("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_validate(){let t=super._validate();const s=l("boolean",{optionalKeySupport:this._optionalSupport});return s.status||(this._errors.push(s.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=M(t);if(this.focusState==="self"){const i=["Space","Enter"],r=["Escape"],u=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&a(t):(this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&r.includes(s)||this.elements.parentMenu&&u.includes(s))&&a(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=M(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(a(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(r=>r.isOpen)?(a(t),this.closeChildren()):this.elements.parentMenu?(a(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(a(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(a(t),this.focusPreviousChild()):s==="Home"?(a(t),this.focusFirstChild()):s==="End"&&(a(t),this.focusLastChild())))})}}module.exports=L; + - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});x("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get prefix(){return this._root?this._prefix:this.elements.rootMenu.prefix}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){b({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){b({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){b({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){l("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){l("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){l("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){l("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let o=0,u=!1;for(;!u&&o=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){P({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){R({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){$({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){l("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){l("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){l("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set prefix(e){l("string",{value:e}),this._prefix!==e&&(this._prefix=e)}set hasOpened(e){l("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=C(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=C(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=L({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=L({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const h=b({openClass:this._openClass});h.status||(this._errors.push(h.error.message),e=!1)}if(this._closeClass!==""){const h=b({closeClass:this._closeClass});h.status||(this._errors.push(h.error.message),e=!1)}if(this._transitionClass!==""){const h=b({transitionClass:this._transitionClass});h.status||(this._errors.push(h.error.message),e=!1)}const i=l("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const o=l("number",{openDuration:this._openDuration});o.status||(this._errors.push(o.error.message),e=!1);const u=l("number",{closeDuration:this._closeDuration});u.status||(this._errors.push(u.error.message),e=!1);const c=l("boolean",{isTopLevel:this._root});if(c.status||(this._errors.push(c.error.message),e=!1),this._elements.parentMenu!==null){const h=C(T,{parentMenu:this._elements.parentMenu});h.status||(this._errors.push(h.error.message),e=!1)}const m=$({hoverType:this._hoverType});m.status||(this._errors.push(m.error.message),e=!1);const f=l("number",{hoverDelay:this._hoverDelay});f.status||(this._errors.push(f.error.message),e=!1);const d=l("number",{enterDelay:this._enterDelay});d.status||(this._errors.push(d.error.message),e=!1);const p=l("number",{leaveDelay:this._leaveDelay});p.status||(this._errors.push(p.error.message),e=!1);const g=l("string",{prefix:this._prefix});return g.status||(this._errors.push(g.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&C(HTMLElement,{base:t});const o=Array.from(t.querySelectorAll(this.selectors[e])).filter(u=>u.parentElement===t);s?this._dom[e]=o:this._dom[e]=[...this._dom[e],...o]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),o=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),u=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:o,parentMenu:this});this._elements.submenuToggles.push(u),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:o,toggle:u})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){l("function",{callback:e}),l("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){a(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=E(e);(t==="Space"||t==="Enter")&&a(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=E(e);(t==="Space"||t==="Enter")&&(a(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty(`--${this.prefix}transition-duration`,`${this.transitionDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}open-transition-duration`,`${this.openDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}close-transition-duration`,`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class U extends j{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:o=null,toggle:u=null,initialize:c=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:o,toggle:u}),c&&this.initialize()}}class Z extends F{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:o=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),o&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),x("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class O extends T{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:o="li:has(ul)",submenuToggleSelector:u="button",submenuSelector:c="ul",controllerElement:m=null,containerElement:f=null,openClass:d="show",closeClass:p="hide",transitionClass:g="transitioning",transitionDuration:h=250,openDuration:D=-1,closeDuration:M=-1,isTopLevel:v=!0,parentMenu:w=null,hoverType:S="off",hoverDelay:k=250,enterDelay:A=-1,leaveDelay:I=-1,optionalKeySupport:K=!1,prefix:V="am-",initialize:q=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:o,submenuToggleSelector:u,submenuSelector:c,controllerElement:m,containerElement:f,openClass:d,closeClass:p,transitionClass:g,transitionDuration:h,openDuration:D,closeDuration:M,isTopLevel:v,parentMenu:w,hoverType:S,hoverDelay:k,enterDelay:A,leaveDelay:I,prefix:V});r(this,"_MenuType",O);r(this,"_MenuItemType",U);r(this,"_MenuToggleType",Z);r(this,"_currentChild",-1);r(this,"_optionalSupport",!1);this._optionalSupport=K,q&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){l("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_validate(){let t=super._validate();const s=l("boolean",{optionalKeySupport:this._optionalSupport});return s.status||(this._errors.push(s.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=E(t);if(this.focusState==="self"){const i=["Space","Enter"],o=["Escape"],u=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&a(t):(this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&o.includes(s)||this.elements.parentMenu&&u.includes(s))&&a(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=E(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(a(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(o=>o.isOpen)?(a(t),this.closeChildren()):this.elements.parentMenu?(a(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(a(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(a(t),this.focusPreviousChild()):s==="Home"?(a(t),this.focusFirstChild()):s==="End"&&(a(t),this.focusLastChild())))})}}module.exports=O; diff --git a/dist/disclosure-menu.es.js b/dist/disclosure-menu.es.js index 6b83fae0..7a30f651 100644 --- a/dist/disclosure-menu.es.js +++ b/dist/disclosure-menu.es.js @@ -1,13 +1,13 @@ -var q = Object.defineProperty; -var z = (n, e, t) => e in n ? q(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; -var o = (n, e, t) => z(n, typeof e != "symbol" ? e + "" : e, t); -function g(n, e) { +var z = Object.defineProperty; +var H = (n, e, t) => e in n ? z(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; +var r = (n, e, t) => H(n, typeof e != "symbol" ? e + "" : e, t); +function _(n, e) { n === "" || n.length === 0 || (typeof n == "string" ? e.classList.add(n) : e.classList.add(...n)); } -function _(n, e) { +function y(n, e) { n === "" || n.length === 0 || (typeof n == "string" ? e.classList.remove(n) : e.classList.remove(...n)); } -function b(n, e) { +function C(n, e) { try { if (typeof e != "object") { const t = typeof e; @@ -57,7 +57,7 @@ function l(n, e) { }; } } -function I(n) { +function L(n) { try { if (typeof n != "object") { const e = typeof n; @@ -86,7 +86,7 @@ function I(n) { }; } } -function y(n) { +function b(n) { try { if (typeof n != "object" || Array.isArray(n)) { const e = typeof n; @@ -110,7 +110,7 @@ function y(n) { ); else { const s = {}; - s[e] = n[e], I(s); + s[e] = n[e], L(s); } } return { @@ -124,7 +124,7 @@ function y(n) { }; } } -function H(n) { +function P(n) { try { if (typeof n != "object") { const t = typeof n; @@ -151,7 +151,7 @@ function H(n) { }; } } -function P(n) { +function R(n) { try { if (typeof n != "object") { const t = typeof n; @@ -178,7 +178,7 @@ function P(n) { }; } } -function L(n) { +function O(n) { try { if (typeof n != "object") { const t = typeof n; @@ -205,8 +205,8 @@ function L(n) { }; } } -function O(n, e) { - if (l("string", { tagName: n }).status && b(HTMLElement, e).status) { +function $(n, e) { + if (l("string", { tagName: n }).status && C(HTMLElement, e).status) { const t = n.toLowerCase(); let s = !0; for (const i in e) @@ -215,7 +215,7 @@ function O(n, e) { } else return !1; } -class $ { +class x { /** * Constructs a new `BaseMenuToggle`. * @@ -241,7 +241,7 @@ class $ { * @property {HTMLElement} toggle - The menu toggle. * @property {HTMLElement} parent - The menu containing this toggle. */ - o(this, "_dom", { + r(this, "_dom", { toggle: null, parent: null }); @@ -255,7 +255,7 @@ class $ { * @property {BaseMenu} controlledMenu - The menu controlled by this toggle. * @property {BaseMenu} parentMenu - The menu containing this toggle. */ - o(this, "_elements", { + r(this, "_elements", { controlledMenu: null, parentMenu: null }); @@ -266,7 +266,7 @@ class $ { * * @type {boolean} */ - o(this, "_open", !1); + r(this, "_open", !1); /** * The event that is triggered when the menu toggle expands. * @@ -279,7 +279,7 @@ class $ { * @property {boolean} bubbles - A flag to bubble the event. * @property {Object} details - The details object containing the BaseMenuToggle itself. */ - o(this, "_expandEvent", new CustomEvent("accessibleMenuExpand", { + r(this, "_expandEvent", new CustomEvent("accessibleMenuExpand", { bubbles: !0, detail: { toggle: this } })); @@ -295,7 +295,7 @@ class $ { * @property {boolean} bubbles - A flag to bubble the event. * @property {Object} details - The details object containing the BaseMenuToggle itself. */ - o(this, "_collapseEvent", new CustomEvent("accessibleMenuCollapse", { + r(this, "_collapseEvent", new CustomEvent("accessibleMenuCollapse", { bubbles: !0, detail: { toggle: this } })); @@ -404,19 +404,19 @@ class $ { * @param {boolean} [emit = true] - A toggle to emit the expand event once expanded. */ _expand(e = !0) { - const { closeClass: t, openClass: s, transitionClass: i, openDuration: r } = this.elements.controlledMenu; - this.dom.toggle.setAttribute("aria-expanded", "true"), this.elements.controlledMenu.elements.rootMenu.hasOpened = !0, i !== "" ? (g(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - _(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - g(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + const { closeClass: t, openClass: s, transitionClass: i, openDuration: o } = this.elements.controlledMenu; + this.dom.toggle.setAttribute("aria-expanded", "true"), this.elements.controlledMenu.elements.rootMenu.hasOpened = !0, i !== "" ? (_(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + y(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + _(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { setTimeout(() => { - _( + y( i, this.elements.controlledMenu.dom.menu ); - }, r); + }, o); }); }); - })) : (g(s, this.elements.controlledMenu.dom.menu), _(t, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._expandEvent); + })) : (_(s, this.elements.controlledMenu.dom.menu), y(t, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._expandEvent); } /** * Collapses the controlled menu. @@ -436,19 +436,19 @@ class $ { * @param {boolean} [emit = true] - A toggle to emit the collapse event once collapsed. */ _collapse(e = !0) { - const { closeClass: t, openClass: s, transitionClass: i, closeDuration: r } = this.elements.controlledMenu; - this.dom.toggle.setAttribute("aria-expanded", "false"), i !== "" ? (g(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - _(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - g(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + const { closeClass: t, openClass: s, transitionClass: i, closeDuration: o } = this.elements.controlledMenu; + this.dom.toggle.setAttribute("aria-expanded", "false"), i !== "" ? (_(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + y(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + _(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { setTimeout(() => { - _( + y( i, this.elements.controlledMenu.dom.menu ); - }, r); + }, o); }); }); - })) : (g(t, this.elements.controlledMenu.dom.menu), _(s, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._collapseEvent); + })) : (_(t, this.elements.controlledMenu.dom.menu), y(s, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._collapseEvent); } /** * Opens the controlled menu. @@ -534,7 +534,7 @@ class F { menuLinkElement: t, parentMenu: s, isSubmenuItem: i = !1, - childMenu: r = null, + childMenu: o = null, toggle: u = null }) { /** @@ -547,7 +547,7 @@ class F { * @property {HTMLElement} item - The menu item. * @property {HTMLElement} link - The menu item's link. */ - o(this, "_dom", { + r(this, "_dom", { item: null, link: null }); @@ -562,7 +562,7 @@ class F { * @property {?BaseMenu} childMenu - The menu contained within this menu item. * @property {?BaseMenuToggle} toggle - The menu toggle within this menu item that controls the `childMenu`. */ - o(this, "_elements", { + r(this, "_elements", { parentMenu: null, childMenu: null, toggle: null @@ -574,8 +574,8 @@ class F { * * @type {boolean} */ - o(this, "_submenu", !1); - this._dom.item = e, this._dom.link = t, this._elements.parentMenu = s, this._elements.childMenu = r, this._elements.toggle = u, this._submenu = i; + r(this, "_submenu", !1); + this._dom.item = e, this._dom.link = t, this._elements.parentMenu = s, this._elements.childMenu = o, this._elements.toggle = u, this._submenu = i; } /** * Initialize the menu item. @@ -641,7 +641,7 @@ class F { }); } } -function M(n) { +function E(n) { try { const e = n.key || n.keyCode, t = { Enter: e === "Enter" || e === 13, @@ -665,7 +665,7 @@ function M(n) { function a(n) { n.preventDefault(), n.stopPropagation(); } -class E { +class T { /** * Constructs a new `BaseMenu`. * @@ -681,37 +681,39 @@ class E { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). - * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in miliseconds). - * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). + * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in milliseconds). + * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = false] - A flag to mark the root menu. * @param {?BaseMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in milliseconds). + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. */ constructor({ menuElement: e, menuItemSelector: t = "li", menuLinkSelector: s = "a", submenuItemSelector: i = "li:has(ul)", - submenuToggleSelector: r = "a", + submenuToggleSelector: o = "a", submenuSelector: u = "ul", controllerElement: c = null, containerElement: m = null, - openClass: d = "show", - closeClass: f = "hide", + openClass: f = "show", + closeClass: d = "hide", transitionClass: p = "transitioning", - transitionDuration: h = 250, - openDuration: T = -1, + transitionDuration: g = 250, + openDuration: h = -1, closeDuration: D = -1, - isTopLevel: C = !0, + isTopLevel: M = !0, parentMenu: v = null, hoverType: w = "off", hoverDelay: S = 250, enterDelay: k = -1, - leaveDelay: A = -1 + leaveDelay: A = -1, + prefix: I = "am-" }) { /** * The class to use when generating submenus. @@ -720,7 +722,7 @@ class E { * * @type {typeof BaseMenu} */ - o(this, "_MenuType", E); + r(this, "_MenuType", T); /** * The class to use when generating menu items. * @@ -728,7 +730,7 @@ class E { * * @type {typeof BaseMenuItem} */ - o(this, "_MenuItemType", F); + r(this, "_MenuItemType", F); /** * The class to use when generating submenu toggles. * @@ -736,7 +738,7 @@ class E { * * @type {typeof BaseMenuToggle} */ - o(this, "_MenuToggleType", $); + r(this, "_MenuToggleType", x); /** * The DOM elements within the menu. * @@ -752,7 +754,7 @@ class E { * @property {HTMLElement} controller - The toggle for this menu. * @property {HTMLElement} container - The container for this menu. */ - o(this, "_dom", { + r(this, "_dom", { menu: null, menuItems: [], submenuItems: [], @@ -774,7 +776,7 @@ class E { * @property {string} submenuToggles - The query selector for menu links that function as submenu toggles. * @property {string} submenus - The query selector for for submenus. */ - o(this, "_selectors", { + r(this, "_selectors", { menuItems: "", menuLinks: "", submenuItems: "", @@ -794,7 +796,7 @@ class E { * @property {?BaseMenu} parentMenu - The parent menu. * @property {?BaseMenu} rootMenu - The root menu of the menu tree. */ - o(this, "_elements", { + r(this, "_elements", { menuItems: [], submenuToggles: [], controller: null, @@ -808,7 +810,7 @@ class E { * * @type {string|string[]} */ - o(this, "_openClass", "show"); + r(this, "_openClass", "show"); /** * The class(es) to apply when the menu is closed. * @@ -816,7 +818,7 @@ class E { * * @type {string|string[]} */ - o(this, "_closeClass", "hide"); + r(this, "_closeClass", "hide"); /** * The class(es) to apply when the menu is transitioning between states. * @@ -824,31 +826,31 @@ class E { * * @type {string|string[]} */ - o(this, "_transitionClass", "transitioning"); + r(this, "_transitionClass", "transitioning"); /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * @protected * * @type {number} */ - o(this, "_transitionDuration", 250); + r(this, "_transitionDuration", 250); /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * @protected * * @type {number} */ - o(this, "_openDuration", -1); + r(this, "_openDuration", -1); /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * @protected * * @type {number} */ - o(this, "_closeDuration", -1); + r(this, "_closeDuration", -1); /** * A flag marking the root menu. * @@ -856,7 +858,7 @@ class E { * * @type {boolean} */ - o(this, "_root", !0); + r(this, "_root", !0); /** * The index of the currently selected menu item in the menu. * @@ -864,7 +866,7 @@ class E { * * @type {number} */ - o(this, "_currentChild", 0); + r(this, "_currentChild", 0); /** * The current state of the menu's focus. * @@ -872,7 +874,7 @@ class E { * * @type {string} */ - o(this, "_focusState", "none"); + r(this, "_focusState", "none"); /** * This last event triggered on the menu. * @@ -880,7 +882,7 @@ class E { * * @type {string} */ - o(this, "_currentEvent", "none"); + r(this, "_currentEvent", "none"); /** * The type of hoverability for the menu. * @@ -888,31 +890,39 @@ class E { * * @type {string} */ - o(this, "_hoverType", "off"); + r(this, "_hoverType", "off"); /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * @protected * * @type {number} */ - o(this, "_hoverDelay", 250); + r(this, "_hoverDelay", 250); /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * @protected * * @type {number} */ - o(this, "_enterDelay", -1); + r(this, "_enterDelay", -1); /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * @protected * * @type {number} */ - o(this, "_leaveDelay", -1); + r(this, "_leaveDelay", -1); + /** + * The prefix to use for CSS custom properties. + * + * @protected + * + * @type {string} + */ + r(this, "_prefix", "am-"); /** * A variable to hold the hover timeout function. * @@ -920,7 +930,7 @@ class E { * * @type {?Function} */ - o(this, "_hoverTimeout", null); + r(this, "_hoverTimeout", null); /** * A flag to check if the menu can dynamically hover based on if a menu has been opened already. * @@ -928,7 +938,7 @@ class E { * * @type {boolean} */ - o(this, "_hasOpened", !1); + r(this, "_hasOpened", !1); /** * An array of error messages generated by the menu. * @@ -936,8 +946,8 @@ class E { * * @type {string[]} */ - o(this, "_errors", []); - this._dom.menu = e, this._dom.controller = c, this._dom.container = m, this._selectors.menuItems = t, this._selectors.menuLinks = s, this._selectors.submenuItems = i, this._selectors.submenuToggles = r, this._selectors.submenus = u, this._elements.menuItems = [], this._elements.submenuToggles = [], this._elements.controller = null, this._elements.parentMenu = v, this._elements.rootMenu = C ? this : null, this._openClass = d || "", this._closeClass = f || "", this._transitionClass = p || "", this._transitionDuration = h, this._openDuration = T, this._closeDuration = D, this._root = C, this._hoverType = w, this._hoverDelay = S, this._enterDelay = k, this._leaveDelay = A; + r(this, "_errors", []); + this._dom.menu = e, this._dom.controller = c, this._dom.container = m, this._selectors.menuItems = t, this._selectors.menuLinks = s, this._selectors.submenuItems = i, this._selectors.submenuToggles = o, this._selectors.submenus = u, this._elements.menuItems = [], this._elements.submenuToggles = [], this._elements.controller = null, this._elements.parentMenu = v, this._elements.rootMenu = M ? this : null, this._openClass = f || "", this._closeClass = d || "", this._transitionClass = p || "", this._transitionDuration = g, this._openDuration = h, this._closeDuration = D, this._prefix = I || "", this._root = M, this._hoverType = w, this._hoverDelay = S, this._enterDelay = k, this._leaveDelay = A; } /** * Initializes the menu. @@ -970,7 +980,7 @@ class E { parentElement: this.dom.container, controlledMenu: this }); - O("button", { toggle: e.dom.toggle }) || e.dom.toggle.setAttribute("role", "button"), e.dom.toggle.setAttribute("aria-controls", this.dom.menu.id), this._elements.controller = e; + $("button", { toggle: e.dom.toggle }) || e.dom.toggle.setAttribute("role", "button"), e.dom.toggle.setAttribute("aria-controls", this.dom.menu.id), this._elements.controller = e; } this._createChildElements(), this._setTransitionDurations(), this.isTopLevel && (window.AccessibleMenu = window.AccessibleMenu || { menus: {} @@ -1064,7 +1074,7 @@ class E { return this.isTopLevel ? this._transitionClass : this.elements.rootMenu.transitionClass; } /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's transition duration. @@ -1079,7 +1089,7 @@ class E { return this.isTopLevel ? this._transitionDuration : this.elements.rootMenu.transitionDuration; } /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's openDuration. @@ -1096,7 +1106,7 @@ class E { return this._openDuration === -1 ? this.transitionDuration : this.isTopLevel ? this._openDuration : this.elements.rootMenu.openDuration; } /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's closeDuration. @@ -1180,7 +1190,7 @@ class E { return this._root ? this._hoverType : this.elements.rootMenu.hoverType; } /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's hover delay. @@ -1193,7 +1203,7 @@ class E { return this._root ? this._hoverDelay : this.elements.rootMenu.hoverDelay; } /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's enter delay. @@ -1208,7 +1218,7 @@ class E { return this._enterDelay === -1 ? this.hoverDelay : this._root ? this._enterDelay : this.elements.rootMenu.enterDelay; } /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's leave delay. @@ -1222,6 +1232,19 @@ class E { get leaveDelay() { return this._leaveDelay === -1 ? this.hoverDelay : this._root ? this._leaveDelay : this.elements.rootMenu.leaveDelay; } + /** + * The prefix to use for CSS custom properties. + * + * This functions differently for root vs. submenus. + * Submenus will always inherit their root menu's prefix. + * + * @type {string} + * + * @see _prefix + */ + get prefix() { + return this._root ? this._prefix : this.elements.rootMenu.prefix; + } /** * A flag to check if the menu's focus methods should _actually_ move the focus in the DOM. * @@ -1265,13 +1288,13 @@ class E { return this._errors; } set openClass(e) { - y({ openClass: e }), this._openClass !== e && (this._openClass = e); + b({ openClass: e }), this._openClass !== e && (this._openClass = e); } set closeClass(e) { - y({ closeClass: e }), this._closeClass !== e && (this._closeClass = e); + b({ closeClass: e }), this._closeClass !== e && (this._closeClass = e); } set transitionClass(e) { - y({ transitionClass: e }), this._transitionClass !== e && (this._transitionClass = e); + b({ transitionClass: e }), this._transitionClass !== e && (this._transitionClass = e); } set transitionDuration(e) { l("number", { value: e }), this._transitionDuration !== e && (this._transitionDuration = e, this._setTransitionDurations()); @@ -1286,27 +1309,27 @@ class E { l("number", { value: e }); function t(s) { if (["mouse", "character"].includes(s.currentEvent) && s.elements.parentMenu) { - let r = 0, u = !1; - for (; !u && r < s.elements.parentMenu.elements.menuItems.length; ) { - const c = s.elements.parentMenu.elements.menuItems[r]; - c.isSubmenuItem && c.elements.toggle.elements.controlledMenu === s && (u = !0, s.elements.parentMenu.currentEvent = s.currentEvent, s.elements.parentMenu.currentChild = r), r++; + let o = 0, u = !1; + for (; !u && o < s.elements.parentMenu.elements.menuItems.length; ) { + const c = s.elements.parentMenu.elements.menuItems[o]; + c.isSubmenuItem && c.elements.toggle.elements.controlledMenu === s && (u = !0, s.elements.parentMenu.currentEvent = s.currentEvent, s.elements.parentMenu.currentChild = o), o++; } } } e < -1 ? (this._currentChild = -1, t(this)) : e >= this.elements.menuItems.length ? (this._currentChild = this.elements.menuItems.length - 1, t(this)) : this.focusChild !== e && (this._currentChild = e, t(this)); } set focusState(e) { - H({ value: e }), this._focusState !== e && (this._focusState = e), this.elements.submenuToggles.length > 0 && (e === "self" || e === "none") && this.elements.submenuToggles.forEach((t) => { + P({ value: e }), this._focusState !== e && (this._focusState = e), this.elements.submenuToggles.length > 0 && (e === "self" || e === "none") && this.elements.submenuToggles.forEach((t) => { t.elements.controlledMenu.focusState = "none"; }), this.elements.parentMenu && (e === "self" || e === "child") && (this.elements.parentMenu.focusState = "child"); } set currentEvent(e) { - P({ value: e }), this._currentEvent !== e && (this._currentEvent = e, this.elements.submenuToggles.length > 0 && this.elements.submenuToggles.forEach((t) => { + R({ value: e }), this._currentEvent !== e && (this._currentEvent = e, this.elements.submenuToggles.length > 0 && this.elements.submenuToggles.forEach((t) => { t.elements.controlledMenu.currentEvent = e; })); } set hoverType(e) { - L({ value: e }), this._hoverType !== e && (this._hoverType = e); + O({ value: e }), this._hoverType !== e && (this._hoverType = e); } set hoverDelay(e) { l("number", { value: e }), this._hoverDelay !== e && (this._hoverDelay = e); @@ -1317,6 +1340,9 @@ class E { set leaveDelay(e) { l("number", { value: e }), this._leaveDelay !== e && (this._leaveDelay = e); } + set prefix(e) { + l("string", { value: e }), this._prefix !== e && (this._prefix = e); + } set hasOpened(e) { l("boolean", { value: e }), this._hasOpened !== e && (this._hasOpened = e); } @@ -1329,35 +1355,35 @@ class E { */ _validate() { let e = !0, t; - this._dom.container !== null || this._dom.controller !== null ? t = b(HTMLElement, { + this._dom.container !== null || this._dom.controller !== null ? t = C(HTMLElement, { menuElement: this._dom.menu, controllerElement: this._dom.controller, containerElement: this._dom.container - }) : t = b(HTMLElement, { + }) : t = C(HTMLElement, { menuElement: this._dom.menu }), t.status || (this._errors.push(t.error.message), e = !1); let s; - if (this._selectors.submenuItems !== "" ? s = I({ + if (this._selectors.submenuItems !== "" ? s = L({ menuItemSelector: this._selectors.menuItems, menuLinkSelector: this._selectors.menuLinks, submenuItemSelector: this._selectors.submenuItems, submenuToggleSelector: this._selectors.submenuToggles, submenuSelector: this._selectors.submenus - }) : s = I({ + }) : s = L({ menuItemSelector: this._selectors.menuItems, menuLinkSelector: this._selectors.menuLinks }), s.status || (this._errors.push(s.error.message), e = !1), this._openClass !== "") { - const h = y({ openClass: this._openClass }); + const h = b({ openClass: this._openClass }); h.status || (this._errors.push(h.error.message), e = !1); } if (this._closeClass !== "") { - const h = y({ + const h = b({ closeClass: this._closeClass }); h.status || (this._errors.push(h.error.message), e = !1); } if (this._transitionClass !== "") { - const h = y({ + const h = b({ transitionClass: this._transitionClass }); h.status || (this._errors.push(h.error.message), e = !1); @@ -1366,35 +1392,37 @@ class E { transitionDuration: this._transitionDuration }); i.status || (this._errors.push(i.error.message), e = !1); - const r = l("number", { + const o = l("number", { openDuration: this._openDuration }); - r.status || (this._errors.push(r.error.message), e = !1); + o.status || (this._errors.push(o.error.message), e = !1); const u = l("number", { closeDuration: this._closeDuration }); u.status || (this._errors.push(u.error.message), e = !1); const c = l("boolean", { isTopLevel: this._root }); if (c.status || (this._errors.push(c.error.message), e = !1), this._elements.parentMenu !== null) { - const h = b(E, { + const h = C(T, { parentMenu: this._elements.parentMenu }); h.status || (this._errors.push(h.error.message), e = !1); } - const m = L({ hoverType: this._hoverType }); + const m = O({ hoverType: this._hoverType }); m.status || (this._errors.push(m.error.message), e = !1); - const d = l("number", { + const f = l("number", { hoverDelay: this._hoverDelay }); - d.status || (this._errors.push(d.error.message), e = !1); - const f = l("number", { + f.status || (this._errors.push(f.error.message), e = !1); + const d = l("number", { enterDelay: this._enterDelay }); - f.status || (this._errors.push(f.error.message), e = !1); + d.status || (this._errors.push(d.error.message), e = !1); const p = l("number", { leaveDelay: this._leaveDelay }); - return p.status || (this._errors.push(p.error.message), e = !1), e; + p.status || (this._errors.push(p.error.message), e = !1); + const g = l("string", { prefix: this._prefix }); + return g.status || (this._errors.push(g.error.message), e = !1), e; } /** * Sets DOM elements within the menu. @@ -1413,15 +1441,15 @@ class E { throw new Error( `AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.` ); - t !== this.dom.menu && b(HTMLElement, { base: t }); - const r = Array.from( + t !== this.dom.menu && C(HTMLElement, { base: t }); + const o = Array.from( t.querySelectorAll(this.selectors[e]) ).filter( (u) => u.parentElement === t ); - s ? this._dom[e] = r : this._dom[e] = [ + s ? this._dom[e] = o : this._dom[e] = [ ...this._dom[e], - ...r + ...o ]; } else throw new Error( @@ -1486,7 +1514,7 @@ class E { this.dom.menuItems.forEach((e) => { let t; if (this.dom.submenuItems.includes(e)) { - const s = e.querySelector(this.selectors.submenuToggles), i = e.querySelector(this.selectors.submenus), r = new this._MenuType({ + const s = e.querySelector(this.selectors.submenuToggles), i = e.querySelector(this.selectors.submenus), o = new this._MenuType({ menuElement: i, menuItemSelector: this.selectors.menuItems, menuLinkSelector: this.selectors.menuLinks, @@ -1508,7 +1536,7 @@ class E { }), u = new this._MenuToggleType({ menuToggleElement: s, parentElement: e, - controlledMenu: r, + controlledMenu: o, parentMenu: this }); this._elements.submenuToggles.push(u), t = new this._MenuItemType({ @@ -1516,7 +1544,7 @@ class E { menuLinkElement: s, parentMenu: this, isSubmenuItem: !0, - childMenu: r, + childMenu: o, toggle: u }); } else { @@ -1688,7 +1716,7 @@ class E { "keydown", (e) => { this.currentEvent = "keyboard"; - const t = M(e); + const t = E(e); (t === "Space" || t === "Enter") && a(e); } ); @@ -1704,7 +1732,7 @@ class E { _handleKeyup() { this.isTopLevel && this.elements.controller && this.elements.controller.dom.toggle.addEventListener("keyup", (e) => { this.currentEvent = "keyboard"; - const t = M(e); + const t = E(e); (t === "Space" || t === "Enter") && (a(e), this.elements.controller.toggle(), this.elements.controller.isOpen && this.focusFirstChild()); }); } @@ -1716,17 +1744,19 @@ class E { * - `--am-open-transition-duration`, and * - `--am-close-transition-duration`. * + * The prefix of `am-` can be changed by setting the menu's prefix value. + * * @protected */ _setTransitionDurations() { this.dom.menu.style.setProperty( - "--am-transition-duration", + `--${this.prefix}transition-duration`, `${this.transitionDuration}ms` ), this.dom.menu.style.setProperty( - "--am-open-transition-duration", + `--${this.prefix}open-transition-duration`, `${this.openDuration}ms` ), this.dom.menu.style.setProperty( - "--am-close-transition-duration", + `--${this.prefix}close-transition-duration`, `${this.closeDuration}ms` ); } @@ -1847,7 +1877,7 @@ class E { }); } } -class R extends F { +class U extends F { /** * Constructs a new `DisclosureMenuItem`. * @@ -1865,7 +1895,7 @@ class R extends F { menuLinkElement: t, parentMenu: s, isSubmenuItem: i = !1, - childMenu: r = null, + childMenu: o = null, toggle: u = null, initialize: c = !0 }) { @@ -1874,12 +1904,12 @@ class R extends F { menuLinkElement: t, parentMenu: s, isSubmenuItem: i, - childMenu: r, + childMenu: o, toggle: u }), c && this.initialize(); } } -class U extends $ { +class Z extends x { /** * Constructs a new `DisclosureMenuToggle`. * @@ -1895,14 +1925,14 @@ class U extends $ { parentElement: t, controlledMenu: s, parentMenu: i = null, - initialize: r = !0 + initialize: o = !0 }) { super({ menuToggleElement: e, parentElement: t, controlledMenu: s, parentMenu: i - }), r && this.initialize(); + }), o && this.initialize(); } /** * Sets the ARIA attributes on the toggle and controlled menu. @@ -1918,7 +1948,7 @@ class U extends $ { * @protected */ _setAriaAttributes() { - super._setAriaAttributes(), O("button", { toggle: this.dom.toggle }) || this.dom.toggle.setAttribute("role", "button"), this.dom.toggle.setAttribute( + super._setAriaAttributes(), $("button", { toggle: this.dom.toggle }) || this.dom.toggle.setAttribute("role", "button"), this.dom.toggle.setAttribute( "aria-controls", this.elements.controlledMenu.dom.menu.id ); @@ -1957,7 +1987,7 @@ class U extends $ { this.isOpen && this.closeChildren(), super.close(); } } -class j extends E { +class j extends T { /** * Constructs a new `DisclosureMenu`. * @@ -1973,63 +2003,66 @@ class j extends E { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). - * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in miliseconds). - * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). + * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in milliseconds). + * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?DisclosureMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). * @param {boolean} [options.optionalKeySupport = false] - A flag to add optional keyboard support (Arrow keys, Home, and End) to the menu. + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. */ constructor({ menuElement: t, menuItemSelector: s = "li", menuLinkSelector: i = "a", - submenuItemSelector: r = "li:has(ul)", + submenuItemSelector: o = "li:has(ul)", submenuToggleSelector: u = "button", submenuSelector: c = "ul", controllerElement: m = null, - containerElement: d = null, - openClass: f = "show", + containerElement: f = null, + openClass: d = "show", closeClass: p = "hide", - transitionClass: h = "transitioning", - transitionDuration: T = 250, + transitionClass: g = "transitioning", + transitionDuration: h = 250, openDuration: D = -1, - closeDuration: C = -1, + closeDuration: M = -1, isTopLevel: v = !0, parentMenu: w = null, hoverType: S = "off", hoverDelay: k = 250, enterDelay: A = -1, - leaveDelay: K = -1, - optionalKeySupport: V = !1, - initialize: x = !0 + leaveDelay: I = -1, + optionalKeySupport: K = !1, + prefix: V = "am-", + initialize: q = !0 }) { super({ menuElement: t, menuItemSelector: s, menuLinkSelector: i, - submenuItemSelector: r, + submenuItemSelector: o, submenuToggleSelector: u, submenuSelector: c, controllerElement: m, - containerElement: d, - openClass: f, + containerElement: f, + openClass: d, closeClass: p, - transitionClass: h, - transitionDuration: T, + transitionClass: g, + transitionDuration: h, openDuration: D, - closeDuration: C, + closeDuration: M, isTopLevel: v, parentMenu: w, hoverType: S, hoverDelay: k, enterDelay: A, - leaveDelay: K + leaveDelay: I, + prefix: V }); /** * The class to use when generating submenus. @@ -2038,7 +2071,7 @@ class j extends E { * * @type {typeof DisclosureMenu} */ - o(this, "_MenuType", j); + r(this, "_MenuType", j); /** * The class to use when generating menu items. * @@ -2046,7 +2079,7 @@ class j extends E { * * @type {typeof DisclosureMenuItem} */ - o(this, "_MenuItemType", R); + r(this, "_MenuItemType", U); /** * The class to use when generating submenu toggles. * @@ -2054,7 +2087,7 @@ class j extends E { * * @type {typeof DisclosureMenuToggle} */ - o(this, "_MenuToggleType", U); + r(this, "_MenuToggleType", Z); /** * The index of the currently selected menu item in the menu. * @@ -2062,7 +2095,7 @@ class j extends E { * * @type {number} */ - o(this, "_currentChild", -1); + r(this, "_currentChild", -1); /** * A flag to add optional keyboard support (Arrow keys, "Home", and "End") to the menu. * @@ -2070,8 +2103,8 @@ class j extends E { * * @type {boolean} */ - o(this, "_optionalSupport", !1); - this._optionalSupport = V, x && this.initialize(); + r(this, "_optionalSupport", !1); + this._optionalSupport = K, q && this.initialize(); } /** * Initializes the menu. @@ -2154,9 +2187,9 @@ class j extends E { _handleKeydown() { super._handleKeydown(), this.dom.menu.addEventListener("keydown", (t) => { this.currentEvent = "keyboard"; - const s = M(t); + const s = E(t); if (this.focusState === "self") { - const i = ["Space", "Enter"], r = ["Escape"], u = ["Escape"]; + const i = ["Space", "Enter"], o = ["Escape"], u = ["Escape"]; this.optionalKeySupport ? [ "ArrowUp", "ArrowRight", @@ -2164,7 +2197,7 @@ class j extends E { "ArrowLeft", "Home", "End" - ].includes(s) && a(t) : (this.currentMenuItem.isSubmenuItem && i.includes(s) || this.elements.controller && r.includes(s) || this.elements.parentMenu && u.includes(s)) && a(t); + ].includes(s) && a(t) : (this.currentMenuItem.isSubmenuItem && i.includes(s) || this.elements.controller && o.includes(s) || this.elements.parentMenu && u.includes(s)) && a(t); } }); } @@ -2193,9 +2226,9 @@ class j extends E { _handleKeyup() { super._handleKeyup(), this.dom.menu.addEventListener("keyup", (t) => { this.currentEvent = "keyboard"; - const s = M(t); + const s = E(t); this.focusState === "self" && (s === "Space" || s === "Enter" ? this.currentMenuItem.isSubmenuItem ? (a(t), this.currentMenuItem.elements.toggle.isOpen ? this.currentMenuItem.elements.toggle.close() : this.currentMenuItem.elements.toggle.preview()) : this.currentMenuItem.dom.link.click() : s === "Escape" ? this.elements.submenuToggles.some( - (r) => r.isOpen + (o) => o.isOpen ) ? (a(t), this.closeChildren()) : this.elements.parentMenu ? (a(t), this.elements.parentMenu.currentEvent = this.currentEvent, this.elements.parentMenu.closeChildren(), this.elements.parentMenu.focusCurrentChild()) : this.isTopLevel && this.elements.controller && this.elements.controller.isOpen && (this.elements.controller.close(), this.focusController()) : this.optionalKeySupport && (s === "ArrowDown" || s === "ArrowRight" ? (a(t), this.currentMenuItem.isSubmenuItem && this.currentMenuItem.elements.toggle.isOpen ? (this.currentMenuItem.elements.childMenu.currentEvent = "keyboard", this.currentMenuItem.elements.childMenu.focusFirstChild()) : this.focusNextChild()) : s === "ArrowUp" || s === "ArrowLeft" ? (a(t), this.focusPreviousChild()) : s === "Home" ? (a(t), this.focusFirstChild()) : s === "End" && (a(t), this.focusLastChild()))); }); } diff --git a/dist/disclosure-menu.iife.js b/dist/disclosure-menu.iife.js index 69761cd7..89c2cd0c 100644 --- a/dist/disclosure-menu.iife.js +++ b/dist/disclosure-menu.iife.js @@ -1,3 +1,3 @@ -var DisclosureMenu=function(){"use strict";var R=Object.defineProperty;var U=(m,a,f)=>a in m?R(m,a,{enumerable:!0,configurable:!0,writable:!0,value:f}):m[a]=f;var o=(m,a,f)=>U(m,typeof a!="symbol"?a+"":a,f);function m(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function a(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function f(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function l(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function T(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function p(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],T(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function K(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function V(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function O(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function $(n,e){if(l("string",{tagName:n}).status&&f(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class F{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){o(this,"_dom",{toggle:null,parent:null});o(this,"_elements",{controlledMenu:null,parentMenu:null});o(this,"_open",!1);o(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));o(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){l("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(m(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{a(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{m(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{a(i,this.elements.controlledMenu.dom.menu)},r)})})})):(m(s,this.elements.controlledMenu.dom.menu),a(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(m(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{a(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{m(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{a(i,this.elements.controlledMenu.dom.menu)},r)})})})):(m(t,this.elements.controlledMenu.dom.menu),a(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class j{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:u=null}){o(this,"_dom",{item:null,link:null});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});o(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=r,this._elements.toggle=u,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function C(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function c(n){n.preventDefault(),n.stopPropagation()}class M{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:r="a",submenuSelector:u="ul",controllerElement:d=null,containerElement:g=null,openClass:_="show",closeClass:y="hide",transitionClass:b="transitioning",transitionDuration:h=250,openDuration:v=-1,closeDuration:w=-1,isTopLevel:E=!0,parentMenu:S=null,hoverType:k="off",hoverDelay:A=250,enterDelay:I=-1,leaveDelay:L=-1}){o(this,"_MenuType",M);o(this,"_MenuItemType",j);o(this,"_MenuToggleType",F);o(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});o(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});o(this,"_openClass","show");o(this,"_closeClass","hide");o(this,"_transitionClass","transitioning");o(this,"_transitionDuration",250);o(this,"_openDuration",-1);o(this,"_closeDuration",-1);o(this,"_root",!0);o(this,"_currentChild",0);o(this,"_focusState","none");o(this,"_currentEvent","none");o(this,"_hoverType","off");o(this,"_hoverDelay",250);o(this,"_enterDelay",-1);o(this,"_leaveDelay",-1);o(this,"_hoverTimeout",null);o(this,"_hasOpened",!1);o(this,"_errors",[]);this._dom.menu=e,this._dom.controller=d,this._dom.container=g,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=r,this._selectors.submenus=u,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=S,this._elements.rootMenu=E?this:null,this._openClass=_||"",this._closeClass=y||"",this._transitionClass=b||"",this._transitionDuration=h,this._openDuration=v,this._closeDuration=w,this._root=E,this._hoverType=k,this._hoverDelay=A,this._enterDelay=I,this._leaveDelay=L}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: +var DisclosureMenu=function(){"use strict";var U=Object.defineProperty;var Z=(m,a,d)=>a in m?U(m,a,{enumerable:!0,configurable:!0,writable:!0,value:d}):m[a]=d;var r=(m,a,d)=>Z(m,typeof a!="symbol"?a+"":a,d);function m(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function a(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function d(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function l(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function D(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function p(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],D(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function K(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function V(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function $(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function x(n,e){if(l("string",{tagName:n}).status&&d(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class F{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){r(this,"_dom",{toggle:null,parent:null});r(this,"_elements",{controlledMenu:null,parentMenu:null});r(this,"_open",!1);r(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));r(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){l("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(m(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{a(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{m(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{a(i,this.elements.controlledMenu.dom.menu)},o)})})})):(m(s,this.elements.controlledMenu.dom.menu),a(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(m(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{a(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{m(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{a(i,this.elements.controlledMenu.dom.menu)},o)})})})):(m(t,this.elements.controlledMenu.dom.menu),a(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class j{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:o=null,toggle:u=null}){r(this,"_dom",{item:null,link:null});r(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});r(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=o,this._elements.toggle=u,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function M(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function c(n){n.preventDefault(),n.stopPropagation()}class E{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:o="a",submenuSelector:u="ul",controllerElement:f=null,containerElement:g=null,openClass:_="show",closeClass:y="hide",transitionClass:b="transitioning",transitionDuration:C=250,openDuration:h=-1,closeDuration:w=-1,isTopLevel:T=!0,parentMenu:S=null,hoverType:k="off",hoverDelay:A=250,enterDelay:I=-1,leaveDelay:L=-1,prefix:O="am-"}){r(this,"_MenuType",E);r(this,"_MenuItemType",j);r(this,"_MenuToggleType",F);r(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});r(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});r(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});r(this,"_openClass","show");r(this,"_closeClass","hide");r(this,"_transitionClass","transitioning");r(this,"_transitionDuration",250);r(this,"_openDuration",-1);r(this,"_closeDuration",-1);r(this,"_root",!0);r(this,"_currentChild",0);r(this,"_focusState","none");r(this,"_currentEvent","none");r(this,"_hoverType","off");r(this,"_hoverDelay",250);r(this,"_enterDelay",-1);r(this,"_leaveDelay",-1);r(this,"_prefix","am-");r(this,"_hoverTimeout",null);r(this,"_hasOpened",!1);r(this,"_errors",[]);this._dom.menu=e,this._dom.controller=f,this._dom.container=g,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=o,this._selectors.submenus=u,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=S,this._elements.rootMenu=T?this:null,this._openClass=_||"",this._closeClass=y||"",this._transitionClass=b||"",this._transitionDuration=C,this._openDuration=h,this._closeDuration=w,this._prefix=O||"",this._root=T,this._hoverType=k,this._hoverDelay=A,this._enterDelay=I,this._leaveDelay=L}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: - ${this.errors.join(` - - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});$("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){p({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){p({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){p({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){l("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){l("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){l("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){l("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let r=0,u=!1;for(;!u&&r=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){K({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){V({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){O({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){l("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){l("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){l("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set hasOpened(e){l("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=f(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=f(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=T({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=T({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const h=p({openClass:this._openClass});h.status||(this._errors.push(h.error.message),e=!1)}if(this._closeClass!==""){const h=p({closeClass:this._closeClass});h.status||(this._errors.push(h.error.message),e=!1)}if(this._transitionClass!==""){const h=p({transitionClass:this._transitionClass});h.status||(this._errors.push(h.error.message),e=!1)}const i=l("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const r=l("number",{openDuration:this._openDuration});r.status||(this._errors.push(r.error.message),e=!1);const u=l("number",{closeDuration:this._closeDuration});u.status||(this._errors.push(u.error.message),e=!1);const d=l("boolean",{isTopLevel:this._root});if(d.status||(this._errors.push(d.error.message),e=!1),this._elements.parentMenu!==null){const h=f(M,{parentMenu:this._elements.parentMenu});h.status||(this._errors.push(h.error.message),e=!1)}const g=O({hoverType:this._hoverType});g.status||(this._errors.push(g.error.message),e=!1);const _=l("number",{hoverDelay:this._hoverDelay});_.status||(this._errors.push(_.error.message),e=!1);const y=l("number",{enterDelay:this._enterDelay});y.status||(this._errors.push(y.error.message),e=!1);const b=l("number",{leaveDelay:this._leaveDelay});return b.status||(this._errors.push(b.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&f(HTMLElement,{base:t});const r=Array.from(t.querySelectorAll(this.selectors[e])).filter(u=>u.parentElement===t);s?this._dom[e]=r:this._dom[e]=[...this._dom[e],...r]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),r=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),u=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:r,parentMenu:this});this._elements.submenuToggles.push(u),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:r,toggle:u})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){l("function",{callback:e}),l("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){c(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=C(e);(t==="Space"||t==="Enter")&&c(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=C(e);(t==="Space"||t==="Enter")&&(c(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty("--am-transition-duration",`${this.transitionDuration}ms`),this.dom.menu.style.setProperty("--am-open-transition-duration",`${this.openDuration}ms`),this.dom.menu.style.setProperty("--am-close-transition-duration",`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class q extends j{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:u=null,initialize:d=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:r,toggle:u}),d&&this.initialize()}}class x extends F{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:r=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),r&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),$("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class D extends M{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:r="li:has(ul)",submenuToggleSelector:u="button",submenuSelector:d="ul",controllerElement:g=null,containerElement:_=null,openClass:y="show",closeClass:b="hide",transitionClass:h="transitioning",transitionDuration:v=250,openDuration:w=-1,closeDuration:E=-1,isTopLevel:S=!0,parentMenu:k=null,hoverType:A="off",hoverDelay:I=250,enterDelay:L=-1,leaveDelay:z=-1,optionalKeySupport:H=!1,initialize:P=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:r,submenuToggleSelector:u,submenuSelector:d,controllerElement:g,containerElement:_,openClass:y,closeClass:b,transitionClass:h,transitionDuration:v,openDuration:w,closeDuration:E,isTopLevel:S,parentMenu:k,hoverType:A,hoverDelay:I,enterDelay:L,leaveDelay:z});o(this,"_MenuType",D);o(this,"_MenuItemType",q);o(this,"_MenuToggleType",x);o(this,"_currentChild",-1);o(this,"_optionalSupport",!1);this._optionalSupport=H,P&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){l("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_validate(){let t=super._validate();const s=l("boolean",{optionalKeySupport:this._optionalSupport});return s.status||(this._errors.push(s.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=C(t);if(this.focusState==="self"){const i=["Space","Enter"],r=["Escape"],u=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&c(t):(this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&r.includes(s)||this.elements.parentMenu&&u.includes(s))&&c(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=C(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(c(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(r=>r.isOpen)?(c(t),this.closeChildren()):this.elements.parentMenu?(c(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(c(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(c(t),this.focusPreviousChild()):s==="Home"?(c(t),this.focusFirstChild()):s==="End"&&(c(t),this.focusLastChild())))})}}return D}(); + - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});x("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get prefix(){return this._root?this._prefix:this.elements.rootMenu.prefix}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){p({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){p({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){p({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){l("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){l("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){l("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){l("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let o=0,u=!1;for(;!u&&o=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){K({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){V({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){$({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){l("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){l("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){l("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set prefix(e){l("string",{value:e}),this._prefix!==e&&(this._prefix=e)}set hasOpened(e){l("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=d(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=d(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=D({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=D({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const h=p({openClass:this._openClass});h.status||(this._errors.push(h.error.message),e=!1)}if(this._closeClass!==""){const h=p({closeClass:this._closeClass});h.status||(this._errors.push(h.error.message),e=!1)}if(this._transitionClass!==""){const h=p({transitionClass:this._transitionClass});h.status||(this._errors.push(h.error.message),e=!1)}const i=l("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const o=l("number",{openDuration:this._openDuration});o.status||(this._errors.push(o.error.message),e=!1);const u=l("number",{closeDuration:this._closeDuration});u.status||(this._errors.push(u.error.message),e=!1);const f=l("boolean",{isTopLevel:this._root});if(f.status||(this._errors.push(f.error.message),e=!1),this._elements.parentMenu!==null){const h=d(E,{parentMenu:this._elements.parentMenu});h.status||(this._errors.push(h.error.message),e=!1)}const g=$({hoverType:this._hoverType});g.status||(this._errors.push(g.error.message),e=!1);const _=l("number",{hoverDelay:this._hoverDelay});_.status||(this._errors.push(_.error.message),e=!1);const y=l("number",{enterDelay:this._enterDelay});y.status||(this._errors.push(y.error.message),e=!1);const b=l("number",{leaveDelay:this._leaveDelay});b.status||(this._errors.push(b.error.message),e=!1);const C=l("string",{prefix:this._prefix});return C.status||(this._errors.push(C.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&d(HTMLElement,{base:t});const o=Array.from(t.querySelectorAll(this.selectors[e])).filter(u=>u.parentElement===t);s?this._dom[e]=o:this._dom[e]=[...this._dom[e],...o]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),o=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),u=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:o,parentMenu:this});this._elements.submenuToggles.push(u),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:o,toggle:u})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){l("function",{callback:e}),l("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){c(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&c(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&(c(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty(`--${this.prefix}transition-duration`,`${this.transitionDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}open-transition-duration`,`${this.openDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}close-transition-duration`,`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class q extends j{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:o=null,toggle:u=null,initialize:f=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:o,toggle:u}),f&&this.initialize()}}class z extends F{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:o=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),o&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),x("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class v extends E{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:o="li:has(ul)",submenuToggleSelector:u="button",submenuSelector:f="ul",controllerElement:g=null,containerElement:_=null,openClass:y="show",closeClass:b="hide",transitionClass:C="transitioning",transitionDuration:h=250,openDuration:w=-1,closeDuration:T=-1,isTopLevel:S=!0,parentMenu:k=null,hoverType:A="off",hoverDelay:I=250,enterDelay:L=-1,leaveDelay:O=-1,optionalKeySupport:H=!1,prefix:P="am-",initialize:R=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:o,submenuToggleSelector:u,submenuSelector:f,controllerElement:g,containerElement:_,openClass:y,closeClass:b,transitionClass:C,transitionDuration:h,openDuration:w,closeDuration:T,isTopLevel:S,parentMenu:k,hoverType:A,hoverDelay:I,enterDelay:L,leaveDelay:O,prefix:P});r(this,"_MenuType",v);r(this,"_MenuItemType",q);r(this,"_MenuToggleType",z);r(this,"_currentChild",-1);r(this,"_optionalSupport",!1);this._optionalSupport=H,R&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){l("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_validate(){let t=super._validate();const s=l("boolean",{optionalKeySupport:this._optionalSupport});return s.status||(this._errors.push(s.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=M(t);if(this.focusState==="self"){const i=["Space","Enter"],o=["Escape"],u=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&c(t):(this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&o.includes(s)||this.elements.parentMenu&&u.includes(s))&&c(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=M(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(c(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(o=>o.isOpen)?(c(t),this.closeChildren()):this.elements.parentMenu?(c(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(c(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(c(t),this.focusPreviousChild()):s==="Home"?(c(t),this.focusFirstChild()):s==="End"&&(c(t),this.focusLastChild())))})}}return v}(); diff --git a/dist/menubar.cjs.js b/dist/menubar.cjs.js index 24774dbb..4cb70603 100644 --- a/dist/menubar.cjs.js +++ b/dist/menubar.cjs.js @@ -1,3 +1,3 @@ -"use strict";var x=Object.defineProperty;var j=(n,e,t)=>e in n?x(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>j(n,typeof e!="symbol"?e+"":e,t);function g(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function _(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function M(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function h(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function A(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function y(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],A(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function q(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function V(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function O(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function z(n,e){if(h("string",{tagName:n}).status&&M(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){o(this,"_dom",{toggle:null,parent:null});o(this,"_elements",{controlledMenu:null,parentMenu:null});o(this,"_open",!1);o(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));o(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){h("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(g(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{_(i,this.elements.controlledMenu.dom.menu)},r)})})})):(g(s,this.elements.controlledMenu.dom.menu),_(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(g(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{_(i,this.elements.controlledMenu.dom.menu)},r)})})})):(g(t,this.elements.controlledMenu.dom.menu),_(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:l=null}){o(this,"_dom",{item:null,link:null});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});o(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=r,this._elements.toggle=l,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function C(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function u(n){n.preventDefault(),n.stopPropagation()}class E{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:r="a",submenuSelector:l="ul",controllerElement:a=null,containerElement:c=null,openClass:d="show",closeClass:f="hide",transitionClass:p="transitioning",transitionDuration:m=250,openDuration:T=-1,closeDuration:D=-1,isTopLevel:b=!0,parentMenu:w=null,hoverType:I="off",hoverDelay:v=250,enterDelay:k=-1,leaveDelay:S=-1}){o(this,"_MenuType",E);o(this,"_MenuItemType",F);o(this,"_MenuToggleType",$);o(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});o(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});o(this,"_openClass","show");o(this,"_closeClass","hide");o(this,"_transitionClass","transitioning");o(this,"_transitionDuration",250);o(this,"_openDuration",-1);o(this,"_closeDuration",-1);o(this,"_root",!0);o(this,"_currentChild",0);o(this,"_focusState","none");o(this,"_currentEvent","none");o(this,"_hoverType","off");o(this,"_hoverDelay",250);o(this,"_enterDelay",-1);o(this,"_leaveDelay",-1);o(this,"_hoverTimeout",null);o(this,"_hasOpened",!1);o(this,"_errors",[]);this._dom.menu=e,this._dom.controller=a,this._dom.container=c,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=r,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=w,this._elements.rootMenu=b?this:null,this._openClass=d||"",this._closeClass=f||"",this._transitionClass=p||"",this._transitionDuration=m,this._openDuration=T,this._closeDuration=D,this._root=b,this._hoverType=I,this._hoverDelay=v,this._enterDelay=k,this._leaveDelay=S}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: +"use strict";var j=Object.defineProperty;var q=(n,e,t)=>e in n?j(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>q(n,typeof e!="symbol"?e+"":e,t);function _(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function y(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function b(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function h(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function L(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function M(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],L(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function V(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function z(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function x(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function H(n,e){if(h("string",{tagName:n}).status&&b(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){o(this,"_dom",{toggle:null,parent:null});o(this,"_elements",{controlledMenu:null,parentMenu:null});o(this,"_open",!1);o(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));o(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){h("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(_(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{y(i,this.elements.controlledMenu.dom.menu)},r)})})})):(_(s,this.elements.controlledMenu.dom.menu),y(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(_(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{y(i,this.elements.controlledMenu.dom.menu)},r)})})})):(_(t,this.elements.controlledMenu.dom.menu),y(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:l=null}){o(this,"_dom",{item:null,link:null});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});o(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=r,this._elements.toggle=l,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function E(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function u(n){n.preventDefault(),n.stopPropagation()}class T{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:r="a",submenuSelector:l="ul",controllerElement:a=null,containerElement:c=null,openClass:f="show",closeClass:d="hide",transitionClass:p="transitioning",transitionDuration:g=250,openDuration:m=-1,closeDuration:D=-1,isTopLevel:C=!0,parentMenu:w=null,hoverType:I="off",hoverDelay:v=250,enterDelay:k=-1,leaveDelay:S=-1,prefix:A="am-"}){o(this,"_MenuType",T);o(this,"_MenuItemType",F);o(this,"_MenuToggleType",$);o(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});o(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});o(this,"_openClass","show");o(this,"_closeClass","hide");o(this,"_transitionClass","transitioning");o(this,"_transitionDuration",250);o(this,"_openDuration",-1);o(this,"_closeDuration",-1);o(this,"_root",!0);o(this,"_currentChild",0);o(this,"_focusState","none");o(this,"_currentEvent","none");o(this,"_hoverType","off");o(this,"_hoverDelay",250);o(this,"_enterDelay",-1);o(this,"_leaveDelay",-1);o(this,"_prefix","am-");o(this,"_hoverTimeout",null);o(this,"_hasOpened",!1);o(this,"_errors",[]);this._dom.menu=e,this._dom.controller=a,this._dom.container=c,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=r,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=w,this._elements.rootMenu=C?this:null,this._openClass=f||"",this._closeClass=d||"",this._transitionClass=p||"",this._transitionDuration=g,this._openDuration=m,this._closeDuration=D,this._prefix=A||"",this._root=C,this._hoverType=I,this._hoverDelay=v,this._enterDelay=k,this._leaveDelay=S}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: - ${this.errors.join(` - - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});z("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){y({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){y({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){y({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){h("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){h("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){h("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){h("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let r=0,l=!1;for(;!l&&r=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){q({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){V({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){O({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){h("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){h("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){h("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set hasOpened(e){h("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=M(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=M(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=A({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=A({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const m=y({openClass:this._openClass});m.status||(this._errors.push(m.error.message),e=!1)}if(this._closeClass!==""){const m=y({closeClass:this._closeClass});m.status||(this._errors.push(m.error.message),e=!1)}if(this._transitionClass!==""){const m=y({transitionClass:this._transitionClass});m.status||(this._errors.push(m.error.message),e=!1)}const i=h("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const r=h("number",{openDuration:this._openDuration});r.status||(this._errors.push(r.error.message),e=!1);const l=h("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const a=h("boolean",{isTopLevel:this._root});if(a.status||(this._errors.push(a.error.message),e=!1),this._elements.parentMenu!==null){const m=M(E,{parentMenu:this._elements.parentMenu});m.status||(this._errors.push(m.error.message),e=!1)}const c=O({hoverType:this._hoverType});c.status||(this._errors.push(c.error.message),e=!1);const d=h("number",{hoverDelay:this._hoverDelay});d.status||(this._errors.push(d.error.message),e=!1);const f=h("number",{enterDelay:this._enterDelay});f.status||(this._errors.push(f.error.message),e=!1);const p=h("number",{leaveDelay:this._leaveDelay});return p.status||(this._errors.push(p.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&M(HTMLElement,{base:t});const r=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=r:this._dom[e]=[...this._dom[e],...r]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),r=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:r,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:r,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){h("function",{callback:e}),h("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){u(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=C(e);(t==="Space"||t==="Enter")&&u(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=C(e);(t==="Space"||t==="Enter")&&(u(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty("--am-transition-duration",`${this.transitionDuration}ms`),this.dom.menu.style.setProperty("--am-open-transition-duration",`${this.openDuration}ms`),this.dom.menu.style.setProperty("--am-close-transition-duration",`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class H extends F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:l=null,initialize:a=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:r,toggle:l}),a&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","menuitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=0)}blur(){super.blur(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=-1)}}class K extends ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:r=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),r&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),this.dom.toggle.setAttribute("aria-haspopup","true")}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&(this.closeChildren(),this.elements.parentMenu&&this.elements.parentMenu.focusCurrentChild()),super.close()}}class L extends E{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:r="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:a="ul",controllerElement:c=null,containerElement:d=null,openClass:f="show",closeClass:p="hide",transitionClass:m="transitioning",transitionDuration:T=250,isTopLevel:D=!0,parentMenu:b=null,hoverType:w="off",hoverDelay:I=250,enterDelay:v=-1,leaveDelay:k=-1,initialize:S=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:r,submenuToggleSelector:l,submenuSelector:a,controllerElement:c,containerElement:d,openClass:f,closeClass:p,transitionClass:m,transitionDuration:T,isTopLevel:D,parentMenu:b,hoverType:w,hoverDelay:I,enterDelay:v,leaveDelay:k});o(this,"_MenuType",L);o(this,"_MenuItemType",H);o(this,"_MenuToggleType",K);S&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?this.dom.menu.setAttribute("role","menubar"):this.dom.menu.setAttribute("role","menu"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&(this.elements.menuItems[0].dom.link.tabIndex=0,this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-haspopup"))}catch(t){console.error(t)}}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=C(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?(this.elements.rootMenu.blur(),this.elements.rootMenu.closeChildren()):this.elements.rootMenu.focus()),s==="Character")u(t);else if(this.isTopLevel){if(this.focusState==="self"){const i=["ArrowRight","ArrowLeft","Home","End"],r=["Space","Enter","ArrowDown","ArrowUp"],l=["Escape"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&r.includes(s)||this.elements.controller&&l.includes(s))&&u(t)}}else{const i=["Escape","ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"],r=["Space","Enter"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&r.includes(s))&&u(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=C(t),{altKey:i,crtlKey:r,metaKey:l}=t;if(s==="Character"&&!(i||r||l))u(t),this.elements.rootMenu.currentEvent="character",this.focusNextChildWithCharacter(t.key);else if(this.isTopLevel){if(this.focusState==="self")if(s==="Space"||s==="Enter")this.currentMenuItem.isSubmenuItem?(u(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click();else if(s==="ArrowRight"){u(t);const c=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusNextChild(),c&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else if(s==="ArrowLeft"){u(t);const c=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusPreviousChild(),c&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else s==="ArrowDown"?this.currentMenuItem.isSubmenuItem&&(u(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):s==="ArrowUp"?this.currentMenuItem.isSubmenuItem&&(u(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusLastChild()})):s==="Home"?(u(t),this.focusFirstChild()):s==="End"?(u(t),this.focusLastChild()):s==="Escape"&&(this.elements.submenuToggles.some(d=>d.isOpen)?(u(t),this.closeChildren()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(u(t),this.elements.controller.close(),this.focusController()))}else s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(u(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click():s==="Escape"?(u(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusCurrentChild()):s==="ArrowRight"?this.currentMenuItem.isSubmenuItem?(u(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):(u(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusNextChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&this.elements.rootMenu.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?this.elements.parentMenu.currentMenuItem.isSubmenuItem&&(u(t),this.elements.parentMenu.currentMenuItem.elements.toggle.close(),this.elements.parentMenu.focusCurrentChild(),this.elements.parentMenu===this.elements.rootMenu&&(this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusPreviousChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&(this.elements.rootMenu.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.elements.rootMenu.currentMenuItem.elements.toggle.preview()))):s==="ArrowDown"?(u(t),this.focusNextChild()):s==="ArrowUp"?(u(t),this.focusPreviousChild()):s==="Home"?(u(t),this.focusFirstChild()):s==="End"&&(u(t),this.focusLastChild())})}focusNextChild(){this.currentChild===this.elements.menuItems.length-1?this.focusFirstChild():this.focusChild(this.currentChild+1)}focusPreviousChild(){this.currentChild===0?this.focusLastChild():this.focusChild(this.currentChild-1)}focusNextChildWithCharacter(t){const s=t.toLowerCase();let i=this.currentChild+1,r=!1;for(;!r&&i=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){V({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){z({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){x({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){h("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){h("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){h("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set prefix(e){h("string",{value:e}),this._prefix!==e&&(this._prefix=e)}set hasOpened(e){h("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=b(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=b(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=L({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=L({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const m=M({openClass:this._openClass});m.status||(this._errors.push(m.error.message),e=!1)}if(this._closeClass!==""){const m=M({closeClass:this._closeClass});m.status||(this._errors.push(m.error.message),e=!1)}if(this._transitionClass!==""){const m=M({transitionClass:this._transitionClass});m.status||(this._errors.push(m.error.message),e=!1)}const i=h("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const r=h("number",{openDuration:this._openDuration});r.status||(this._errors.push(r.error.message),e=!1);const l=h("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const a=h("boolean",{isTopLevel:this._root});if(a.status||(this._errors.push(a.error.message),e=!1),this._elements.parentMenu!==null){const m=b(T,{parentMenu:this._elements.parentMenu});m.status||(this._errors.push(m.error.message),e=!1)}const c=x({hoverType:this._hoverType});c.status||(this._errors.push(c.error.message),e=!1);const f=h("number",{hoverDelay:this._hoverDelay});f.status||(this._errors.push(f.error.message),e=!1);const d=h("number",{enterDelay:this._enterDelay});d.status||(this._errors.push(d.error.message),e=!1);const p=h("number",{leaveDelay:this._leaveDelay});p.status||(this._errors.push(p.error.message),e=!1);const g=h("string",{prefix:this._prefix});return g.status||(this._errors.push(g.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&b(HTMLElement,{base:t});const r=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=r:this._dom[e]=[...this._dom[e],...r]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),r=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:r,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:r,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){h("function",{callback:e}),h("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){u(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=E(e);(t==="Space"||t==="Enter")&&u(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=E(e);(t==="Space"||t==="Enter")&&(u(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty(`--${this.prefix}transition-duration`,`${this.transitionDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}open-transition-duration`,`${this.openDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}close-transition-duration`,`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class K extends F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:l=null,initialize:a=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:r,toggle:l}),a&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","menuitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=0)}blur(){super.blur(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=-1)}}class P extends ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:r=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),r&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),this.dom.toggle.setAttribute("aria-haspopup","true")}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&(this.closeChildren(),this.elements.parentMenu&&this.elements.parentMenu.focusCurrentChild()),super.close()}}class O extends T{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:r="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:a="ul",controllerElement:c=null,containerElement:f=null,openClass:d="show",closeClass:p="hide",transitionClass:g="transitioning",transitionDuration:m=250,isTopLevel:D=!0,parentMenu:C=null,hoverType:w="off",hoverDelay:I=250,enterDelay:v=-1,leaveDelay:k=-1,prefix:S="am-",initialize:A=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:r,submenuToggleSelector:l,submenuSelector:a,controllerElement:c,containerElement:f,openClass:d,closeClass:p,transitionClass:g,transitionDuration:m,isTopLevel:D,parentMenu:C,hoverType:w,hoverDelay:I,enterDelay:v,leaveDelay:k,prefix:S});o(this,"_MenuType",O);o(this,"_MenuItemType",K);o(this,"_MenuToggleType",P);A&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?this.dom.menu.setAttribute("role","menubar"):this.dom.menu.setAttribute("role","menu"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&(this.elements.menuItems[0].dom.link.tabIndex=0,this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-haspopup"))}catch(t){console.error(t)}}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=E(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?(this.elements.rootMenu.blur(),this.elements.rootMenu.closeChildren()):this.elements.rootMenu.focus()),s==="Character")u(t);else if(this.isTopLevel){if(this.focusState==="self"){const i=["ArrowRight","ArrowLeft","Home","End"],r=["Space","Enter","ArrowDown","ArrowUp"],l=["Escape"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&r.includes(s)||this.elements.controller&&l.includes(s))&&u(t)}}else{const i=["Escape","ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"],r=["Space","Enter"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&r.includes(s))&&u(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=E(t),{altKey:i,crtlKey:r,metaKey:l}=t;if(s==="Character"&&!(i||r||l))u(t),this.elements.rootMenu.currentEvent="character",this.focusNextChildWithCharacter(t.key);else if(this.isTopLevel){if(this.focusState==="self")if(s==="Space"||s==="Enter")this.currentMenuItem.isSubmenuItem?(u(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click();else if(s==="ArrowRight"){u(t);const c=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusNextChild(),c&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else if(s==="ArrowLeft"){u(t);const c=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusPreviousChild(),c&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else s==="ArrowDown"?this.currentMenuItem.isSubmenuItem&&(u(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):s==="ArrowUp"?this.currentMenuItem.isSubmenuItem&&(u(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusLastChild()})):s==="Home"?(u(t),this.focusFirstChild()):s==="End"?(u(t),this.focusLastChild()):s==="Escape"&&(this.elements.submenuToggles.some(f=>f.isOpen)?(u(t),this.closeChildren()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(u(t),this.elements.controller.close(),this.focusController()))}else s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(u(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click():s==="Escape"?(u(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusCurrentChild()):s==="ArrowRight"?this.currentMenuItem.isSubmenuItem?(u(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):(u(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusNextChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&this.elements.rootMenu.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?this.elements.parentMenu.currentMenuItem.isSubmenuItem&&(u(t),this.elements.parentMenu.currentMenuItem.elements.toggle.close(),this.elements.parentMenu.focusCurrentChild(),this.elements.parentMenu===this.elements.rootMenu&&(this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusPreviousChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&(this.elements.rootMenu.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.elements.rootMenu.currentMenuItem.elements.toggle.preview()))):s==="ArrowDown"?(u(t),this.focusNextChild()):s==="ArrowUp"?(u(t),this.focusPreviousChild()):s==="Home"?(u(t),this.focusFirstChild()):s==="End"&&(u(t),this.focusLastChild())})}focusNextChild(){this.currentChild===this.elements.menuItems.length-1?this.focusFirstChild():this.focusChild(this.currentChild+1)}focusPreviousChild(){this.currentChild===0?this.focusLastChild():this.focusChild(this.currentChild-1)}focusNextChildWithCharacter(t){const s=t.toLowerCase();let i=this.currentChild+1,r=!1;for(;!r&&i e in n ? x(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; -var o = (n, e, t) => j(n, typeof e != "symbol" ? e + "" : e, t); -function g(n, e) { +var j = Object.defineProperty; +var q = (n, e, t) => e in n ? j(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; +var o = (n, e, t) => q(n, typeof e != "symbol" ? e + "" : e, t); +function _(n, e) { n === "" || n.length === 0 || (typeof n == "string" ? e.classList.add(n) : e.classList.add(...n)); } -function _(n, e) { +function y(n, e) { n === "" || n.length === 0 || (typeof n == "string" ? e.classList.remove(n) : e.classList.remove(...n)); } -function M(n, e) { +function b(n, e) { try { if (typeof e != "object") { const t = typeof e; @@ -57,7 +57,7 @@ function h(n, e) { }; } } -function A(n) { +function L(n) { try { if (typeof n != "object") { const e = typeof n; @@ -86,7 +86,7 @@ function A(n) { }; } } -function y(n) { +function M(n) { try { if (typeof n != "object" || Array.isArray(n)) { const e = typeof n; @@ -110,7 +110,7 @@ function y(n) { ); else { const s = {}; - s[e] = n[e], A(s); + s[e] = n[e], L(s); } } return { @@ -124,7 +124,7 @@ function y(n) { }; } } -function q(n) { +function V(n) { try { if (typeof n != "object") { const t = typeof n; @@ -151,7 +151,7 @@ function q(n) { }; } } -function V(n) { +function z(n) { try { if (typeof n != "object") { const t = typeof n; @@ -178,7 +178,7 @@ function V(n) { }; } } -function L(n) { +function O(n) { try { if (typeof n != "object") { const t = typeof n; @@ -205,8 +205,8 @@ function L(n) { }; } } -function z(n, e) { - if (h("string", { tagName: n }).status && M(HTMLElement, e).status) { +function H(n, e) { + if (h("string", { tagName: n }).status && b(HTMLElement, e).status) { const t = n.toLowerCase(); let s = !0; for (const i in e) @@ -215,7 +215,7 @@ function z(n, e) { } else return !1; } -class O { +class x { /** * Constructs a new `BaseMenuToggle`. * @@ -405,18 +405,18 @@ class O { */ _expand(e = !0) { const { closeClass: t, openClass: s, transitionClass: i, openDuration: r } = this.elements.controlledMenu; - this.dom.toggle.setAttribute("aria-expanded", "true"), this.elements.controlledMenu.elements.rootMenu.hasOpened = !0, i !== "" ? (g(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - _(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - g(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + this.dom.toggle.setAttribute("aria-expanded", "true"), this.elements.controlledMenu.elements.rootMenu.hasOpened = !0, i !== "" ? (_(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + y(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + _(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { setTimeout(() => { - _( + y( i, this.elements.controlledMenu.dom.menu ); }, r); }); }); - })) : (g(s, this.elements.controlledMenu.dom.menu), _(t, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._expandEvent); + })) : (_(s, this.elements.controlledMenu.dom.menu), y(t, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._expandEvent); } /** * Collapses the controlled menu. @@ -437,18 +437,18 @@ class O { */ _collapse(e = !0) { const { closeClass: t, openClass: s, transitionClass: i, closeDuration: r } = this.elements.controlledMenu; - this.dom.toggle.setAttribute("aria-expanded", "false"), i !== "" ? (g(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - _(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - g(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + this.dom.toggle.setAttribute("aria-expanded", "false"), i !== "" ? (_(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + y(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + _(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { setTimeout(() => { - _( + y( i, this.elements.controlledMenu.dom.menu ); }, r); }); }); - })) : (g(t, this.elements.controlledMenu.dom.menu), _(s, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._collapseEvent); + })) : (_(t, this.elements.controlledMenu.dom.menu), y(s, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._collapseEvent); } /** * Opens the controlled menu. @@ -641,7 +641,7 @@ class $ { }); } } -function C(n) { +function E(n) { try { const e = n.key || n.keyCode, t = { Enter: e === "Enter" || e === 13, @@ -665,7 +665,7 @@ function C(n) { function u(n) { n.preventDefault(), n.stopPropagation(); } -class E { +class T { /** * Constructs a new `BaseMenu`. * @@ -681,15 +681,16 @@ class E { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). - * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in miliseconds). - * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). + * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in milliseconds). + * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = false] - A flag to mark the root menu. * @param {?BaseMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in milliseconds). + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. */ constructor({ menuElement: e, @@ -700,18 +701,19 @@ class E { submenuSelector: l = "ul", controllerElement: a = null, containerElement: c = null, - openClass: d = "show", - closeClass: f = "hide", + openClass: f = "show", + closeClass: d = "hide", transitionClass: p = "transitioning", - transitionDuration: m = 250, - openDuration: T = -1, + transitionDuration: g = 250, + openDuration: m = -1, closeDuration: D = -1, - isTopLevel: b = !0, + isTopLevel: C = !0, parentMenu: w = null, hoverType: I = "off", hoverDelay: v = 250, enterDelay: k = -1, - leaveDelay: S = -1 + leaveDelay: S = -1, + prefix: A = "am-" }) { /** * The class to use when generating submenus. @@ -720,7 +722,7 @@ class E { * * @type {typeof BaseMenu} */ - o(this, "_MenuType", E); + o(this, "_MenuType", T); /** * The class to use when generating menu items. * @@ -736,7 +738,7 @@ class E { * * @type {typeof BaseMenuToggle} */ - o(this, "_MenuToggleType", O); + o(this, "_MenuToggleType", x); /** * The DOM elements within the menu. * @@ -826,7 +828,7 @@ class E { */ o(this, "_transitionClass", "transitioning"); /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * @protected * @@ -834,7 +836,7 @@ class E { */ o(this, "_transitionDuration", 250); /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * @protected * @@ -842,7 +844,7 @@ class E { */ o(this, "_openDuration", -1); /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * @protected * @@ -890,7 +892,7 @@ class E { */ o(this, "_hoverType", "off"); /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * @protected * @@ -898,7 +900,7 @@ class E { */ o(this, "_hoverDelay", 250); /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * @protected * @@ -906,13 +908,21 @@ class E { */ o(this, "_enterDelay", -1); /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * @protected * * @type {number} */ o(this, "_leaveDelay", -1); + /** + * The prefix to use for CSS custom properties. + * + * @protected + * + * @type {string} + */ + o(this, "_prefix", "am-"); /** * A variable to hold the hover timeout function. * @@ -937,7 +947,7 @@ class E { * @type {string[]} */ o(this, "_errors", []); - this._dom.menu = e, this._dom.controller = a, this._dom.container = c, this._selectors.menuItems = t, this._selectors.menuLinks = s, this._selectors.submenuItems = i, this._selectors.submenuToggles = r, this._selectors.submenus = l, this._elements.menuItems = [], this._elements.submenuToggles = [], this._elements.controller = null, this._elements.parentMenu = w, this._elements.rootMenu = b ? this : null, this._openClass = d || "", this._closeClass = f || "", this._transitionClass = p || "", this._transitionDuration = m, this._openDuration = T, this._closeDuration = D, this._root = b, this._hoverType = I, this._hoverDelay = v, this._enterDelay = k, this._leaveDelay = S; + this._dom.menu = e, this._dom.controller = a, this._dom.container = c, this._selectors.menuItems = t, this._selectors.menuLinks = s, this._selectors.submenuItems = i, this._selectors.submenuToggles = r, this._selectors.submenus = l, this._elements.menuItems = [], this._elements.submenuToggles = [], this._elements.controller = null, this._elements.parentMenu = w, this._elements.rootMenu = C ? this : null, this._openClass = f || "", this._closeClass = d || "", this._transitionClass = p || "", this._transitionDuration = g, this._openDuration = m, this._closeDuration = D, this._prefix = A || "", this._root = C, this._hoverType = I, this._hoverDelay = v, this._enterDelay = k, this._leaveDelay = S; } /** * Initializes the menu. @@ -970,7 +980,7 @@ class E { parentElement: this.dom.container, controlledMenu: this }); - z("button", { toggle: e.dom.toggle }) || e.dom.toggle.setAttribute("role", "button"), e.dom.toggle.setAttribute("aria-controls", this.dom.menu.id), this._elements.controller = e; + H("button", { toggle: e.dom.toggle }) || e.dom.toggle.setAttribute("role", "button"), e.dom.toggle.setAttribute("aria-controls", this.dom.menu.id), this._elements.controller = e; } this._createChildElements(), this._setTransitionDurations(), this.isTopLevel && (window.AccessibleMenu = window.AccessibleMenu || { menus: {} @@ -1064,7 +1074,7 @@ class E { return this.isTopLevel ? this._transitionClass : this.elements.rootMenu.transitionClass; } /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's transition duration. @@ -1079,7 +1089,7 @@ class E { return this.isTopLevel ? this._transitionDuration : this.elements.rootMenu.transitionDuration; } /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's openDuration. @@ -1096,7 +1106,7 @@ class E { return this._openDuration === -1 ? this.transitionDuration : this.isTopLevel ? this._openDuration : this.elements.rootMenu.openDuration; } /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's closeDuration. @@ -1180,7 +1190,7 @@ class E { return this._root ? this._hoverType : this.elements.rootMenu.hoverType; } /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's hover delay. @@ -1193,7 +1203,7 @@ class E { return this._root ? this._hoverDelay : this.elements.rootMenu.hoverDelay; } /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's enter delay. @@ -1208,7 +1218,7 @@ class E { return this._enterDelay === -1 ? this.hoverDelay : this._root ? this._enterDelay : this.elements.rootMenu.enterDelay; } /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's leave delay. @@ -1222,6 +1232,19 @@ class E { get leaveDelay() { return this._leaveDelay === -1 ? this.hoverDelay : this._root ? this._leaveDelay : this.elements.rootMenu.leaveDelay; } + /** + * The prefix to use for CSS custom properties. + * + * This functions differently for root vs. submenus. + * Submenus will always inherit their root menu's prefix. + * + * @type {string} + * + * @see _prefix + */ + get prefix() { + return this._root ? this._prefix : this.elements.rootMenu.prefix; + } /** * A flag to check if the menu's focus methods should _actually_ move the focus in the DOM. * @@ -1265,13 +1288,13 @@ class E { return this._errors; } set openClass(e) { - y({ openClass: e }), this._openClass !== e && (this._openClass = e); + M({ openClass: e }), this._openClass !== e && (this._openClass = e); } set closeClass(e) { - y({ closeClass: e }), this._closeClass !== e && (this._closeClass = e); + M({ closeClass: e }), this._closeClass !== e && (this._closeClass = e); } set transitionClass(e) { - y({ transitionClass: e }), this._transitionClass !== e && (this._transitionClass = e); + M({ transitionClass: e }), this._transitionClass !== e && (this._transitionClass = e); } set transitionDuration(e) { h("number", { value: e }), this._transitionDuration !== e && (this._transitionDuration = e, this._setTransitionDurations()); @@ -1296,17 +1319,17 @@ class E { e < -1 ? (this._currentChild = -1, t(this)) : e >= this.elements.menuItems.length ? (this._currentChild = this.elements.menuItems.length - 1, t(this)) : this.focusChild !== e && (this._currentChild = e, t(this)); } set focusState(e) { - q({ value: e }), this._focusState !== e && (this._focusState = e), this.elements.submenuToggles.length > 0 && (e === "self" || e === "none") && this.elements.submenuToggles.forEach((t) => { + V({ value: e }), this._focusState !== e && (this._focusState = e), this.elements.submenuToggles.length > 0 && (e === "self" || e === "none") && this.elements.submenuToggles.forEach((t) => { t.elements.controlledMenu.focusState = "none"; }), this.elements.parentMenu && (e === "self" || e === "child") && (this.elements.parentMenu.focusState = "child"); } set currentEvent(e) { - V({ value: e }), this._currentEvent !== e && (this._currentEvent = e, this.elements.submenuToggles.length > 0 && this.elements.submenuToggles.forEach((t) => { + z({ value: e }), this._currentEvent !== e && (this._currentEvent = e, this.elements.submenuToggles.length > 0 && this.elements.submenuToggles.forEach((t) => { t.elements.controlledMenu.currentEvent = e; })); } set hoverType(e) { - L({ value: e }), this._hoverType !== e && (this._hoverType = e); + O({ value: e }), this._hoverType !== e && (this._hoverType = e); } set hoverDelay(e) { h("number", { value: e }), this._hoverDelay !== e && (this._hoverDelay = e); @@ -1317,6 +1340,9 @@ class E { set leaveDelay(e) { h("number", { value: e }), this._leaveDelay !== e && (this._leaveDelay = e); } + set prefix(e) { + h("string", { value: e }), this._prefix !== e && (this._prefix = e); + } set hasOpened(e) { h("boolean", { value: e }), this._hasOpened !== e && (this._hasOpened = e); } @@ -1329,35 +1355,35 @@ class E { */ _validate() { let e = !0, t; - this._dom.container !== null || this._dom.controller !== null ? t = M(HTMLElement, { + this._dom.container !== null || this._dom.controller !== null ? t = b(HTMLElement, { menuElement: this._dom.menu, controllerElement: this._dom.controller, containerElement: this._dom.container - }) : t = M(HTMLElement, { + }) : t = b(HTMLElement, { menuElement: this._dom.menu }), t.status || (this._errors.push(t.error.message), e = !1); let s; - if (this._selectors.submenuItems !== "" ? s = A({ + if (this._selectors.submenuItems !== "" ? s = L({ menuItemSelector: this._selectors.menuItems, menuLinkSelector: this._selectors.menuLinks, submenuItemSelector: this._selectors.submenuItems, submenuToggleSelector: this._selectors.submenuToggles, submenuSelector: this._selectors.submenus - }) : s = A({ + }) : s = L({ menuItemSelector: this._selectors.menuItems, menuLinkSelector: this._selectors.menuLinks }), s.status || (this._errors.push(s.error.message), e = !1), this._openClass !== "") { - const m = y({ openClass: this._openClass }); + const m = M({ openClass: this._openClass }); m.status || (this._errors.push(m.error.message), e = !1); } if (this._closeClass !== "") { - const m = y({ + const m = M({ closeClass: this._closeClass }); m.status || (this._errors.push(m.error.message), e = !1); } if (this._transitionClass !== "") { - const m = y({ + const m = M({ transitionClass: this._transitionClass }); m.status || (this._errors.push(m.error.message), e = !1); @@ -1376,25 +1402,27 @@ class E { l.status || (this._errors.push(l.error.message), e = !1); const a = h("boolean", { isTopLevel: this._root }); if (a.status || (this._errors.push(a.error.message), e = !1), this._elements.parentMenu !== null) { - const m = M(E, { + const m = b(T, { parentMenu: this._elements.parentMenu }); m.status || (this._errors.push(m.error.message), e = !1); } - const c = L({ hoverType: this._hoverType }); + const c = O({ hoverType: this._hoverType }); c.status || (this._errors.push(c.error.message), e = !1); - const d = h("number", { + const f = h("number", { hoverDelay: this._hoverDelay }); - d.status || (this._errors.push(d.error.message), e = !1); - const f = h("number", { + f.status || (this._errors.push(f.error.message), e = !1); + const d = h("number", { enterDelay: this._enterDelay }); - f.status || (this._errors.push(f.error.message), e = !1); + d.status || (this._errors.push(d.error.message), e = !1); const p = h("number", { leaveDelay: this._leaveDelay }); - return p.status || (this._errors.push(p.error.message), e = !1), e; + p.status || (this._errors.push(p.error.message), e = !1); + const g = h("string", { prefix: this._prefix }); + return g.status || (this._errors.push(g.error.message), e = !1), e; } /** * Sets DOM elements within the menu. @@ -1413,7 +1441,7 @@ class E { throw new Error( `AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.` ); - t !== this.dom.menu && M(HTMLElement, { base: t }); + t !== this.dom.menu && b(HTMLElement, { base: t }); const r = Array.from( t.querySelectorAll(this.selectors[e]) ).filter( @@ -1688,7 +1716,7 @@ class E { "keydown", (e) => { this.currentEvent = "keyboard"; - const t = C(e); + const t = E(e); (t === "Space" || t === "Enter") && u(e); } ); @@ -1704,7 +1732,7 @@ class E { _handleKeyup() { this.isTopLevel && this.elements.controller && this.elements.controller.dom.toggle.addEventListener("keyup", (e) => { this.currentEvent = "keyboard"; - const t = C(e); + const t = E(e); (t === "Space" || t === "Enter") && (u(e), this.elements.controller.toggle(), this.elements.controller.isOpen && this.focusFirstChild()); }); } @@ -1716,17 +1744,19 @@ class E { * - `--am-open-transition-duration`, and * - `--am-close-transition-duration`. * + * The prefix of `am-` can be changed by setting the menu's prefix value. + * * @protected */ _setTransitionDurations() { this.dom.menu.style.setProperty( - "--am-transition-duration", + `--${this.prefix}transition-duration`, `${this.transitionDuration}ms` ), this.dom.menu.style.setProperty( - "--am-open-transition-duration", + `--${this.prefix}open-transition-duration`, `${this.openDuration}ms` ), this.dom.menu.style.setProperty( - "--am-close-transition-duration", + `--${this.prefix}close-transition-duration`, `${this.closeDuration}ms` ); } @@ -1847,7 +1877,7 @@ class E { }); } } -class H extends $ { +class K extends $ { /** * Constructs a new `MenubarItem`. * @@ -1916,7 +1946,7 @@ class H extends $ { super.blur(), this.elements.parentMenu.isTopLevel && (this.dom.link.tabIndex = -1); } } -class K extends O { +class P extends x { /** * Constructs a new `MenubarToggle`. * @@ -1987,7 +2017,7 @@ class K extends O { this.isOpen && (this.closeChildren(), this.elements.parentMenu && this.elements.parentMenu.focusCurrentChild()), super.close(); } } -class F extends E { +class F extends T { /** * Constructs a new `Menubar`. * @@ -2003,13 +2033,14 @@ class F extends E { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?Menubar} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. */ constructor({ @@ -2020,18 +2051,19 @@ class F extends E { submenuToggleSelector: l = "a", submenuSelector: a = "ul", controllerElement: c = null, - containerElement: d = null, - openClass: f = "show", + containerElement: f = null, + openClass: d = "show", closeClass: p = "hide", - transitionClass: m = "transitioning", - transitionDuration: T = 250, + transitionClass: g = "transitioning", + transitionDuration: m = 250, isTopLevel: D = !0, - parentMenu: b = null, + parentMenu: C = null, hoverType: w = "off", hoverDelay: I = 250, enterDelay: v = -1, leaveDelay: k = -1, - initialize: S = !0 + prefix: S = "am-", + initialize: A = !0 }) { super({ menuElement: t, @@ -2041,17 +2073,18 @@ class F extends E { submenuToggleSelector: l, submenuSelector: a, controllerElement: c, - containerElement: d, - openClass: f, + containerElement: f, + openClass: d, closeClass: p, - transitionClass: m, - transitionDuration: T, + transitionClass: g, + transitionDuration: m, isTopLevel: D, - parentMenu: b, + parentMenu: C, hoverType: w, hoverDelay: I, enterDelay: v, - leaveDelay: k + leaveDelay: k, + prefix: S }); /** * The class to use when generating submenus. @@ -2068,7 +2101,7 @@ class F extends E { * * @type {typeof MenubarItem} */ - o(this, "_MenuItemType", H); + o(this, "_MenuItemType", K); /** * The class to use when generating submenu toggles. * @@ -2076,8 +2109,8 @@ class F extends E { * * @type {typeof MenubarToggle} */ - o(this, "_MenuToggleType", K); - S && this.initialize(); + o(this, "_MenuToggleType", P); + A && this.initialize(); } /** * Initializes the menu. @@ -2135,7 +2168,7 @@ class F extends E { _handleKeydown() { super._handleKeydown(), this.dom.menu.addEventListener("keydown", (t) => { this.currentEvent = "keyboard"; - const s = C(t); + const s = E(t); if (s === "Tab" && (this.elements.rootMenu.focusState !== "none" ? (this.elements.rootMenu.blur(), this.elements.rootMenu.closeChildren()) : this.elements.rootMenu.focus()), s === "Character") u(t); else if (this.isTopLevel) { @@ -2197,7 +2230,7 @@ class F extends E { _handleKeyup() { super._handleKeyup(), this.dom.menu.addEventListener("keyup", (t) => { this.currentEvent = "keyboard"; - const s = C(t), { altKey: i, crtlKey: r, metaKey: l } = t; + const s = E(t), { altKey: i, crtlKey: r, metaKey: l } = t; if (s === "Character" && !(i || r || l)) u(t), this.elements.rootMenu.currentEvent = "character", this.focusNextChildWithCharacter(t.key); else if (this.isTopLevel) { @@ -2219,7 +2252,7 @@ class F extends E { })) : s === "ArrowUp" ? this.currentMenuItem.isSubmenuItem && (u(t), this.currentMenuItem.elements.childMenu.currentEvent = "keyboard", this.currentMenuItem.elements.toggle.open(), requestAnimationFrame(() => { this.currentMenuItem.elements.childMenu.focusLastChild(); })) : s === "Home" ? (u(t), this.focusFirstChild()) : s === "End" ? (u(t), this.focusLastChild()) : s === "Escape" && (this.elements.submenuToggles.some( - (d) => d.isOpen + (f) => f.isOpen ) ? (u(t), this.closeChildren()) : this.isTopLevel && this.elements.controller && this.elements.controller.isOpen && (u(t), this.elements.controller.close(), this.focusController())); } else s === "Space" || s === "Enter" ? this.currentMenuItem.isSubmenuItem ? (u(t), this.currentMenuItem.elements.childMenu.currentEvent = "keyboard", this.currentMenuItem.elements.toggle.open(), requestAnimationFrame(() => { diff --git a/dist/menubar.iife.js b/dist/menubar.iife.js index 629a8f51..aeaaeb82 100644 --- a/dist/menubar.iife.js +++ b/dist/menubar.iife.js @@ -1,3 +1,3 @@ -var Menubar=function(){"use strict";var H=Object.defineProperty;var K=(c,a,p)=>a in c?H(c,a,{enumerable:!0,configurable:!0,writable:!0,value:p}):c[a]=p;var o=(c,a,p)=>K(c,typeof a!="symbol"?a+"":a,p);function c(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function a(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function p(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function h(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function T(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function _(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],T(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function x(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function j(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function O(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function q(n,e){if(h("string",{tagName:n}).status&&p(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){o(this,"_dom",{toggle:null,parent:null});o(this,"_elements",{controlledMenu:null,parentMenu:null});o(this,"_open",!1);o(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));o(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){h("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(c(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{a(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{c(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{a(i,this.elements.controlledMenu.dom.menu)},r)})})})):(c(s,this.elements.controlledMenu.dom.menu),a(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(c(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{a(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{c(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{a(i,this.elements.controlledMenu.dom.menu)},r)})})})):(c(t,this.elements.controlledMenu.dom.menu),a(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:u=null}){o(this,"_dom",{item:null,link:null});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});o(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=r,this._elements.toggle=u,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function b(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function l(n){n.preventDefault(),n.stopPropagation()}class C{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:r="a",submenuSelector:u="ul",controllerElement:d=null,containerElement:f=null,openClass:g="show",closeClass:y="hide",transitionClass:M="transitioning",transitionDuration:m=250,openDuration:w=-1,closeDuration:I=-1,isTopLevel:E=!0,parentMenu:v=null,hoverType:k="off",hoverDelay:S=250,enterDelay:A=-1,leaveDelay:L=-1}){o(this,"_MenuType",C);o(this,"_MenuItemType",F);o(this,"_MenuToggleType",$);o(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});o(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});o(this,"_openClass","show");o(this,"_closeClass","hide");o(this,"_transitionClass","transitioning");o(this,"_transitionDuration",250);o(this,"_openDuration",-1);o(this,"_closeDuration",-1);o(this,"_root",!0);o(this,"_currentChild",0);o(this,"_focusState","none");o(this,"_currentEvent","none");o(this,"_hoverType","off");o(this,"_hoverDelay",250);o(this,"_enterDelay",-1);o(this,"_leaveDelay",-1);o(this,"_hoverTimeout",null);o(this,"_hasOpened",!1);o(this,"_errors",[]);this._dom.menu=e,this._dom.controller=d,this._dom.container=f,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=r,this._selectors.submenus=u,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=v,this._elements.rootMenu=E?this:null,this._openClass=g||"",this._closeClass=y||"",this._transitionClass=M||"",this._transitionDuration=m,this._openDuration=w,this._closeDuration=I,this._root=E,this._hoverType=k,this._hoverDelay=S,this._enterDelay=A,this._leaveDelay=L}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: +var Menubar=function(){"use strict";var K=Object.defineProperty;var P=(c,a,p)=>a in c?K(c,a,{enumerable:!0,configurable:!0,writable:!0,value:p}):c[a]=p;var o=(c,a,p)=>P(c,typeof a!="symbol"?a+"":a,p);function c(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function a(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function p(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function h(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function D(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function _(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],D(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function j(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function q(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function x(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function V(n,e){if(h("string",{tagName:n}).status&&p(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){o(this,"_dom",{toggle:null,parent:null});o(this,"_elements",{controlledMenu:null,parentMenu:null});o(this,"_open",!1);o(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));o(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){h("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(c(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{a(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{c(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{a(i,this.elements.controlledMenu.dom.menu)},r)})})})):(c(s,this.elements.controlledMenu.dom.menu),a(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(c(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{a(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{c(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{a(i,this.elements.controlledMenu.dom.menu)},r)})})})):(c(t,this.elements.controlledMenu.dom.menu),a(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:u=null}){o(this,"_dom",{item:null,link:null});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});o(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=r,this._elements.toggle=u,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function C(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function l(n){n.preventDefault(),n.stopPropagation()}class E{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:r="a",submenuSelector:u="ul",controllerElement:f=null,containerElement:d=null,openClass:g="show",closeClass:y="hide",transitionClass:M="transitioning",transitionDuration:b=250,openDuration:m=-1,closeDuration:I=-1,isTopLevel:T=!0,parentMenu:v=null,hoverType:k="off",hoverDelay:S=250,enterDelay:A=-1,leaveDelay:L=-1,prefix:O="am-"}){o(this,"_MenuType",E);o(this,"_MenuItemType",F);o(this,"_MenuToggleType",$);o(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});o(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});o(this,"_openClass","show");o(this,"_closeClass","hide");o(this,"_transitionClass","transitioning");o(this,"_transitionDuration",250);o(this,"_openDuration",-1);o(this,"_closeDuration",-1);o(this,"_root",!0);o(this,"_currentChild",0);o(this,"_focusState","none");o(this,"_currentEvent","none");o(this,"_hoverType","off");o(this,"_hoverDelay",250);o(this,"_enterDelay",-1);o(this,"_leaveDelay",-1);o(this,"_prefix","am-");o(this,"_hoverTimeout",null);o(this,"_hasOpened",!1);o(this,"_errors",[]);this._dom.menu=e,this._dom.controller=f,this._dom.container=d,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=r,this._selectors.submenus=u,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=v,this._elements.rootMenu=T?this:null,this._openClass=g||"",this._closeClass=y||"",this._transitionClass=M||"",this._transitionDuration=b,this._openDuration=m,this._closeDuration=I,this._prefix=O||"",this._root=T,this._hoverType=k,this._hoverDelay=S,this._enterDelay=A,this._leaveDelay=L}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: - ${this.errors.join(` - - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});q("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){_({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){_({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){_({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){h("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){h("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){h("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){h("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let r=0,u=!1;for(;!u&&r=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){x({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){j({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){O({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){h("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){h("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){h("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set hasOpened(e){h("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=p(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=p(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=T({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=T({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const m=_({openClass:this._openClass});m.status||(this._errors.push(m.error.message),e=!1)}if(this._closeClass!==""){const m=_({closeClass:this._closeClass});m.status||(this._errors.push(m.error.message),e=!1)}if(this._transitionClass!==""){const m=_({transitionClass:this._transitionClass});m.status||(this._errors.push(m.error.message),e=!1)}const i=h("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const r=h("number",{openDuration:this._openDuration});r.status||(this._errors.push(r.error.message),e=!1);const u=h("number",{closeDuration:this._closeDuration});u.status||(this._errors.push(u.error.message),e=!1);const d=h("boolean",{isTopLevel:this._root});if(d.status||(this._errors.push(d.error.message),e=!1),this._elements.parentMenu!==null){const m=p(C,{parentMenu:this._elements.parentMenu});m.status||(this._errors.push(m.error.message),e=!1)}const f=O({hoverType:this._hoverType});f.status||(this._errors.push(f.error.message),e=!1);const g=h("number",{hoverDelay:this._hoverDelay});g.status||(this._errors.push(g.error.message),e=!1);const y=h("number",{enterDelay:this._enterDelay});y.status||(this._errors.push(y.error.message),e=!1);const M=h("number",{leaveDelay:this._leaveDelay});return M.status||(this._errors.push(M.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&p(HTMLElement,{base:t});const r=Array.from(t.querySelectorAll(this.selectors[e])).filter(u=>u.parentElement===t);s?this._dom[e]=r:this._dom[e]=[...this._dom[e],...r]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),r=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),u=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:r,parentMenu:this});this._elements.submenuToggles.push(u),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:r,toggle:u})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){h("function",{callback:e}),h("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){l(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=b(e);(t==="Space"||t==="Enter")&&l(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=b(e);(t==="Space"||t==="Enter")&&(l(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty("--am-transition-duration",`${this.transitionDuration}ms`),this.dom.menu.style.setProperty("--am-open-transition-duration",`${this.openDuration}ms`),this.dom.menu.style.setProperty("--am-close-transition-duration",`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class V extends F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:u=null,initialize:d=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:r,toggle:u}),d&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","menuitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=0)}blur(){super.blur(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=-1)}}class z extends ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:r=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),r&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),this.dom.toggle.setAttribute("aria-haspopup","true")}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&(this.closeChildren(),this.elements.parentMenu&&this.elements.parentMenu.focusCurrentChild()),super.close()}}class D extends C{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:r="li:has(ul)",submenuToggleSelector:u="a",submenuSelector:d="ul",controllerElement:f=null,containerElement:g=null,openClass:y="show",closeClass:M="hide",transitionClass:m="transitioning",transitionDuration:w=250,isTopLevel:I=!0,parentMenu:E=null,hoverType:v="off",hoverDelay:k=250,enterDelay:S=-1,leaveDelay:A=-1,initialize:L=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:r,submenuToggleSelector:u,submenuSelector:d,controllerElement:f,containerElement:g,openClass:y,closeClass:M,transitionClass:m,transitionDuration:w,isTopLevel:I,parentMenu:E,hoverType:v,hoverDelay:k,enterDelay:S,leaveDelay:A});o(this,"_MenuType",D);o(this,"_MenuItemType",V);o(this,"_MenuToggleType",z);L&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?this.dom.menu.setAttribute("role","menubar"):this.dom.menu.setAttribute("role","menu"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&(this.elements.menuItems[0].dom.link.tabIndex=0,this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-haspopup"))}catch(t){console.error(t)}}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=b(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?(this.elements.rootMenu.blur(),this.elements.rootMenu.closeChildren()):this.elements.rootMenu.focus()),s==="Character")l(t);else if(this.isTopLevel){if(this.focusState==="self"){const i=["ArrowRight","ArrowLeft","Home","End"],r=["Space","Enter","ArrowDown","ArrowUp"],u=["Escape"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&r.includes(s)||this.elements.controller&&u.includes(s))&&l(t)}}else{const i=["Escape","ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"],r=["Space","Enter"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&r.includes(s))&&l(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=b(t),{altKey:i,crtlKey:r,metaKey:u}=t;if(s==="Character"&&!(i||r||u))l(t),this.elements.rootMenu.currentEvent="character",this.focusNextChildWithCharacter(t.key);else if(this.isTopLevel){if(this.focusState==="self")if(s==="Space"||s==="Enter")this.currentMenuItem.isSubmenuItem?(l(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click();else if(s==="ArrowRight"){l(t);const f=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusNextChild(),f&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else if(s==="ArrowLeft"){l(t);const f=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusPreviousChild(),f&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else s==="ArrowDown"?this.currentMenuItem.isSubmenuItem&&(l(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):s==="ArrowUp"?this.currentMenuItem.isSubmenuItem&&(l(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusLastChild()})):s==="Home"?(l(t),this.focusFirstChild()):s==="End"?(l(t),this.focusLastChild()):s==="Escape"&&(this.elements.submenuToggles.some(g=>g.isOpen)?(l(t),this.closeChildren()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(l(t),this.elements.controller.close(),this.focusController()))}else s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(l(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click():s==="Escape"?(l(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusCurrentChild()):s==="ArrowRight"?this.currentMenuItem.isSubmenuItem?(l(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):(l(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusNextChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&this.elements.rootMenu.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?this.elements.parentMenu.currentMenuItem.isSubmenuItem&&(l(t),this.elements.parentMenu.currentMenuItem.elements.toggle.close(),this.elements.parentMenu.focusCurrentChild(),this.elements.parentMenu===this.elements.rootMenu&&(this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusPreviousChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&(this.elements.rootMenu.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.elements.rootMenu.currentMenuItem.elements.toggle.preview()))):s==="ArrowDown"?(l(t),this.focusNextChild()):s==="ArrowUp"?(l(t),this.focusPreviousChild()):s==="Home"?(l(t),this.focusFirstChild()):s==="End"&&(l(t),this.focusLastChild())})}focusNextChild(){this.currentChild===this.elements.menuItems.length-1?this.focusFirstChild():this.focusChild(this.currentChild+1)}focusPreviousChild(){this.currentChild===0?this.focusLastChild():this.focusChild(this.currentChild-1)}focusNextChildWithCharacter(t){const s=t.toLowerCase();let i=this.currentChild+1,r=!1;for(;!r&&i=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){j({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){q({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){x({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){h("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){h("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){h("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set prefix(e){h("string",{value:e}),this._prefix!==e&&(this._prefix=e)}set hasOpened(e){h("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=p(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=p(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=D({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=D({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const m=_({openClass:this._openClass});m.status||(this._errors.push(m.error.message),e=!1)}if(this._closeClass!==""){const m=_({closeClass:this._closeClass});m.status||(this._errors.push(m.error.message),e=!1)}if(this._transitionClass!==""){const m=_({transitionClass:this._transitionClass});m.status||(this._errors.push(m.error.message),e=!1)}const i=h("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const r=h("number",{openDuration:this._openDuration});r.status||(this._errors.push(r.error.message),e=!1);const u=h("number",{closeDuration:this._closeDuration});u.status||(this._errors.push(u.error.message),e=!1);const f=h("boolean",{isTopLevel:this._root});if(f.status||(this._errors.push(f.error.message),e=!1),this._elements.parentMenu!==null){const m=p(E,{parentMenu:this._elements.parentMenu});m.status||(this._errors.push(m.error.message),e=!1)}const d=x({hoverType:this._hoverType});d.status||(this._errors.push(d.error.message),e=!1);const g=h("number",{hoverDelay:this._hoverDelay});g.status||(this._errors.push(g.error.message),e=!1);const y=h("number",{enterDelay:this._enterDelay});y.status||(this._errors.push(y.error.message),e=!1);const M=h("number",{leaveDelay:this._leaveDelay});M.status||(this._errors.push(M.error.message),e=!1);const b=h("string",{prefix:this._prefix});return b.status||(this._errors.push(b.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&p(HTMLElement,{base:t});const r=Array.from(t.querySelectorAll(this.selectors[e])).filter(u=>u.parentElement===t);s?this._dom[e]=r:this._dom[e]=[...this._dom[e],...r]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),r=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),u=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:r,parentMenu:this});this._elements.submenuToggles.push(u),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:r,toggle:u})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){h("function",{callback:e}),h("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){l(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=C(e);(t==="Space"||t==="Enter")&&l(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=C(e);(t==="Space"||t==="Enter")&&(l(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty(`--${this.prefix}transition-duration`,`${this.transitionDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}open-transition-duration`,`${this.openDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}close-transition-duration`,`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class z extends F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:u=null,initialize:f=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:r,toggle:u}),f&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","menuitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=0)}blur(){super.blur(),this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=-1)}}class H extends ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:r=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),r&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),this.dom.toggle.setAttribute("aria-haspopup","true")}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&(this.closeChildren(),this.elements.parentMenu&&this.elements.parentMenu.focusCurrentChild()),super.close()}}class w extends E{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:r="li:has(ul)",submenuToggleSelector:u="a",submenuSelector:f="ul",controllerElement:d=null,containerElement:g=null,openClass:y="show",closeClass:M="hide",transitionClass:b="transitioning",transitionDuration:m=250,isTopLevel:I=!0,parentMenu:T=null,hoverType:v="off",hoverDelay:k=250,enterDelay:S=-1,leaveDelay:A=-1,prefix:L="am-",initialize:O=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:r,submenuToggleSelector:u,submenuSelector:f,controllerElement:d,containerElement:g,openClass:y,closeClass:M,transitionClass:b,transitionDuration:m,isTopLevel:I,parentMenu:T,hoverType:v,hoverDelay:k,enterDelay:S,leaveDelay:A,prefix:L});o(this,"_MenuType",w);o(this,"_MenuItemType",z);o(this,"_MenuToggleType",H);O&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?this.dom.menu.setAttribute("role","menubar"):this.dom.menu.setAttribute("role","menu"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&(this.elements.menuItems[0].dom.link.tabIndex=0,this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-haspopup"))}catch(t){console.error(t)}}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=C(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?(this.elements.rootMenu.blur(),this.elements.rootMenu.closeChildren()):this.elements.rootMenu.focus()),s==="Character")l(t);else if(this.isTopLevel){if(this.focusState==="self"){const i=["ArrowRight","ArrowLeft","Home","End"],r=["Space","Enter","ArrowDown","ArrowUp"],u=["Escape"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&r.includes(s)||this.elements.controller&&u.includes(s))&&l(t)}}else{const i=["Escape","ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"],r=["Space","Enter"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&r.includes(s))&&l(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=C(t),{altKey:i,crtlKey:r,metaKey:u}=t;if(s==="Character"&&!(i||r||u))l(t),this.elements.rootMenu.currentEvent="character",this.focusNextChildWithCharacter(t.key);else if(this.isTopLevel){if(this.focusState==="self")if(s==="Space"||s==="Enter")this.currentMenuItem.isSubmenuItem?(l(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click();else if(s==="ArrowRight"){l(t);const d=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusNextChild(),d&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else if(s==="ArrowLeft"){l(t);const d=this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen;this.focusPreviousChild(),d&&(this.currentMenuItem.isSubmenuItem?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.preview()):this.closeChildren())}else s==="ArrowDown"?this.currentMenuItem.isSubmenuItem&&(l(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):s==="ArrowUp"?this.currentMenuItem.isSubmenuItem&&(l(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusLastChild()})):s==="Home"?(l(t),this.focusFirstChild()):s==="End"?(l(t),this.focusLastChild()):s==="Escape"&&(this.elements.submenuToggles.some(g=>g.isOpen)?(l(t),this.closeChildren()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(l(t),this.elements.controller.close(),this.focusController()))}else s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(l(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):this.currentMenuItem.dom.link.click():s==="Escape"?(l(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusCurrentChild()):s==="ArrowRight"?this.currentMenuItem.isSubmenuItem?(l(t),this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.toggle.open(),requestAnimationFrame(()=>{this.currentMenuItem.elements.childMenu.focusFirstChild()})):(l(t),this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusNextChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&this.elements.rootMenu.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?this.elements.parentMenu.currentMenuItem.isSubmenuItem&&(l(t),this.elements.parentMenu.currentMenuItem.elements.toggle.close(),this.elements.parentMenu.focusCurrentChild(),this.elements.parentMenu===this.elements.rootMenu&&(this.elements.rootMenu.closeChildren(),this.elements.rootMenu.focusPreviousChild(),this.elements.rootMenu.currentMenuItem.isSubmenuItem&&(this.elements.rootMenu.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.elements.rootMenu.currentMenuItem.elements.toggle.preview()))):s==="ArrowDown"?(l(t),this.focusNextChild()):s==="ArrowUp"?(l(t),this.focusPreviousChild()):s==="Home"?(l(t),this.focusFirstChild()):s==="End"&&(l(t),this.focusLastChild())})}focusNextChild(){this.currentChild===this.elements.menuItems.length-1?this.focusFirstChild():this.focusChild(this.currentChild+1)}focusPreviousChild(){this.currentChild===0?this.focusLastChild():this.focusChild(this.currentChild-1)}focusNextChildWithCharacter(t){const s=t.toLowerCase();let i=this.currentChild+1,r=!1;for(;!r&&ie in n?V(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var r=(n,e,t)=>x(n,typeof e!="symbol"?e+"":e,t);function g(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function _(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function b(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function u(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function C(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function y(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],C(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function z(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function H(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function O(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function $(n,e){if(u("string",{tagName:n}).status&&b(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class j{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){r(this,"_dom",{toggle:null,parent:null});r(this,"_elements",{controlledMenu:null,parentMenu:null});r(this,"_open",!1);r(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));r(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){u("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(g(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{_(i,this.elements.controlledMenu.dom.menu)},o)})})})):(g(s,this.elements.controlledMenu.dom.menu),_(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(g(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{_(i,this.elements.controlledMenu.dom.menu)},o)})})})):(g(t,this.elements.controlledMenu.dom.menu),_(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:o=null,toggle:l=null}){r(this,"_dom",{item:null,link:null});r(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});r(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=o,this._elements.toggle=l,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function M(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function m(n){n.preventDefault(),n.stopPropagation()}class E{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:o="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:c=null,openClass:p="show",closeClass:d="hide",transitionClass:f="transitioning",transitionDuration:a=250,openDuration:D=-1,closeDuration:v=-1,isTopLevel:T=!0,parentMenu:w=null,hoverType:S="off",hoverDelay:k=250,enterDelay:L=-1,leaveDelay:I=-1}){r(this,"_MenuType",E);r(this,"_MenuItemType",F);r(this,"_MenuToggleType",j);r(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});r(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});r(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});r(this,"_openClass","show");r(this,"_closeClass","hide");r(this,"_transitionClass","transitioning");r(this,"_transitionDuration",250);r(this,"_openDuration",-1);r(this,"_closeDuration",-1);r(this,"_root",!0);r(this,"_currentChild",0);r(this,"_focusState","none");r(this,"_currentEvent","none");r(this,"_hoverType","off");r(this,"_hoverDelay",250);r(this,"_enterDelay",-1);r(this,"_leaveDelay",-1);r(this,"_hoverTimeout",null);r(this,"_hasOpened",!1);r(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=c,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=o,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=w,this._elements.rootMenu=T?this:null,this._openClass=p||"",this._closeClass=d||"",this._transitionClass=f||"",this._transitionDuration=a,this._openDuration=D,this._closeDuration=v,this._root=T,this._hoverType=S,this._hoverDelay=k,this._enterDelay=L,this._leaveDelay=I}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: +"use strict";var V=Object.defineProperty;var z=(n,e,t)=>e in n?V(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>z(n,typeof e!="symbol"?e+"":e,t);function _(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function y(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function T(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function u(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function M(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function b(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],M(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function H(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function P(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function $(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function x(n,e){if(u("string",{tagName:n}).status&&T(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class j{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){o(this,"_dom",{toggle:null,parent:null});o(this,"_elements",{controlledMenu:null,parentMenu:null});o(this,"_open",!1);o(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));o(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){u("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(_(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{y(i,this.elements.controlledMenu.dom.menu)},r)})})})):(_(s,this.elements.controlledMenu.dom.menu),y(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(_(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{y(i,this.elements.controlledMenu.dom.menu)},r)})})})):(_(t,this.elements.controlledMenu.dom.menu),y(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:l=null}){o(this,"_dom",{item:null,link:null});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});o(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=r,this._elements.toggle=l,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function E(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function m(n){n.preventDefault(),n.stopPropagation()}class D{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:r="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:c=null,openClass:p="show",closeClass:f="hide",transitionClass:d="transitioning",transitionDuration:g=250,openDuration:a=-1,closeDuration:v=-1,isTopLevel:C=!0,parentMenu:w=null,hoverType:S="off",hoverDelay:k=250,enterDelay:L=-1,leaveDelay:I=-1,prefix:A="am-"}){o(this,"_MenuType",D);o(this,"_MenuItemType",F);o(this,"_MenuToggleType",j);o(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});o(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});o(this,"_openClass","show");o(this,"_closeClass","hide");o(this,"_transitionClass","transitioning");o(this,"_transitionDuration",250);o(this,"_openDuration",-1);o(this,"_closeDuration",-1);o(this,"_root",!0);o(this,"_currentChild",0);o(this,"_focusState","none");o(this,"_currentEvent","none");o(this,"_hoverType","off");o(this,"_hoverDelay",250);o(this,"_enterDelay",-1);o(this,"_leaveDelay",-1);o(this,"_prefix","am-");o(this,"_hoverTimeout",null);o(this,"_hasOpened",!1);o(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=c,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=r,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=w,this._elements.rootMenu=C?this:null,this._openClass=p||"",this._closeClass=f||"",this._transitionClass=d||"",this._transitionDuration=g,this._openDuration=a,this._closeDuration=v,this._prefix=A||"",this._root=C,this._hoverType=S,this._hoverDelay=k,this._enterDelay=L,this._leaveDelay=I}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: - ${this.errors.join(` - - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});$("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){y({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){y({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){y({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){u("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){u("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){u("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){u("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let o=0,l=!1;for(;!l&&o=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){z({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){H({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){O({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){u("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){u("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){u("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set hasOpened(e){u("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=b(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=b(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=C({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=C({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const a=y({openClass:this._openClass});a.status||(this._errors.push(a.error.message),e=!1)}if(this._closeClass!==""){const a=y({closeClass:this._closeClass});a.status||(this._errors.push(a.error.message),e=!1)}if(this._transitionClass!==""){const a=y({transitionClass:this._transitionClass});a.status||(this._errors.push(a.error.message),e=!1)}const i=u("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const o=u("number",{openDuration:this._openDuration});o.status||(this._errors.push(o.error.message),e=!1);const l=u("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=u("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const a=b(E,{parentMenu:this._elements.parentMenu});a.status||(this._errors.push(a.error.message),e=!1)}const c=O({hoverType:this._hoverType});c.status||(this._errors.push(c.error.message),e=!1);const p=u("number",{hoverDelay:this._hoverDelay});p.status||(this._errors.push(p.error.message),e=!1);const d=u("number",{enterDelay:this._enterDelay});d.status||(this._errors.push(d.error.message),e=!1);const f=u("number",{leaveDelay:this._leaveDelay});return f.status||(this._errors.push(f.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&b(HTMLElement,{base:t});const o=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=o:this._dom[e]=[...this._dom[e],...o]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),o=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:o,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:o,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){u("function",{callback:e}),u("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){m(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&m(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&(m(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty("--am-transition-duration",`${this.transitionDuration}ms`),this.dom.menu.style.setProperty("--am-open-transition-duration",`${this.openDuration}ms`),this.dom.menu.style.setProperty("--am-close-transition-duration",`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class P extends F{constructor({menuItemElement:t,menuLinkElement:s,parentMenu:i,isSubmenuItem:o=!1,childMenu:l=null,toggle:h=null,initialize:c=!0,submenuSibling:p=null}){super({menuItemElement:t,menuLinkElement:s,parentMenu:i,isSubmenuItem:o,childMenu:l,toggle:h});r(this,"_elements",{parentMenu:null,childMenu:null,toggle:null,sibling:null});this._elements.parentMenu=i,this._elements.childMenu=l,this._elements.toggle=h,this._elements.sibling=p,c&&this.initialize()}}class R extends j{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:o=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),o&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),$("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class A extends E{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:o="li:has(ul)",submenuToggleSelector:l="button",submenuSelector:h="ul",submenuSubtoggleSelector:c="a",controllerElement:p=null,containerElement:d=null,openClass:f="show",closeClass:a="hide",transitionClass:D="transitioning",transitionDuration:v=250,isTopLevel:T=!0,parentMenu:w=null,hoverType:S="off",hoverDelay:k=250,enterDelay:L=-1,leaveDelay:I=-1,optionalKeySupport:q=!1,initialize:K=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:o,submenuSelector:h,submenuToggleSelector:l,controllerElement:p,containerElement:d,openClass:f,closeClass:a,transitionClass:D,transitionDuration:v,isTopLevel:T,parentMenu:w,hoverType:S,hoverDelay:k,enterDelay:L,leaveDelay:I});r(this,"_MenuType",A);r(this,"_MenuItemType",P);r(this,"_MenuToggleType",R);r(this,"_currentChild",-1);r(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:"",submenuSubtoggles:""});r(this,"_optionalSupport",!1);this._optionalSupport=q,this._selectors.menuItems=s,this._selectors.submenuItems=o,this._selectors.submenuToggles=l,this._selectors.submenus=h,this._selectors.submenuSubtoggles=c,this._selectors.menuLinks=[...new Set([i,l])].join(","),K&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){u("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_createChildElements(){this.dom.menuItems.forEach(t=>{let s,i;const o=t.querySelector(this.selectors.menuLinks);if(this.dom.submenuItems.includes(t)){const l=t.querySelector(this.selectors.submenuToggles),h=t.querySelector(this.selectors.submenus),c=new this._MenuType({menuElement:h,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuSubtoggles,submenuSelector:this.selectors.submenus,submenuSubtoggleSelector:this.selectors.submenuSubtoggles,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),p=new this._MenuToggleType({menuToggleElement:l,parentElement:t,controlledMenu:c,parentMenu:this});this._elements.submenuToggles.push(p),l!==o?(i=new this._MenuItemType({menuItemElement:t,menuLinkElement:l,parentMenu:this,isSubmenuItem:!0,childMenu:c,toggle:p}),s=new this._MenuItemType({menuItemElement:t,menuLinkElement:o,parentMenu:this,submenuSibling:i})):s=new this._MenuItemType({menuItemElement:t,menuLinkElement:o,parentMenu:this,isSubmenuItem:!0,childMenu:c,toggle:p})}else s=new this._MenuItemType({menuItemElement:t,menuLinkElement:o,parentMenu:this});this._elements.menuItems.push(s),typeof i<"u"&&this._elements.menuItems.push(i)})}_validate(){let t=super._validate();const s=C({submenuSubtoggleSelector:this._selectors.submenuSubtoggles});s.status||(this._errors.push(s.error.message),t=!1);const i=u("boolean",{optionalKeySupport:this._optionalSupport});return i.status||(this._errors.push(i.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",i=>{if(!(i.pointerType==="pen"||i.pointerType==="touch")){if(this.hoverType==="on"){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s);let o=t.isSubmenuItem?t.elements.toggle:null;if(t.elements.sibling!==null&&(o=t.elements.sibling.elements.toggle),o===null)return;this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{o.preview()},this.enterDelay)):o.preview()}else if(this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),!this.isTopLevel||this.hasOpened)){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild();let o=t.isSubmenuItem?t.elements.toggle:null;t.elements.sibling!==null&&(o=t.elements.sibling.elements.toggle),o!==null?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{o.preview()},this.enterDelay)):o.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren()}}}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",t.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",t.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=M(t);if(this.focusState==="self"){const i=["Space","Enter"],o=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&m(t):(this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&o.includes(s)||this.elements.parentMenu&&l.includes(s))&&m(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=M(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(m(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(o=>o.isOpen)?(m(t),this.closeChildren()):this.elements.parentMenu?(m(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(m(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(m(t),this.focusPreviousChild()):s==="Home"?(m(t),this.focusFirstChild()):s==="End"&&(m(t),this.focusLastChild())))})}}module.exports=A; + - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});x("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get prefix(){return this._root?this._prefix:this.elements.rootMenu.prefix}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){b({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){b({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){b({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){u("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){u("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){u("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){u("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let r=0,l=!1;for(;!l&&r=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){H({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){P({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){$({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){u("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){u("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){u("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set prefix(e){u("string",{value:e}),this._prefix!==e&&(this._prefix=e)}set hasOpened(e){u("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=T(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=T(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=M({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=M({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const a=b({openClass:this._openClass});a.status||(this._errors.push(a.error.message),e=!1)}if(this._closeClass!==""){const a=b({closeClass:this._closeClass});a.status||(this._errors.push(a.error.message),e=!1)}if(this._transitionClass!==""){const a=b({transitionClass:this._transitionClass});a.status||(this._errors.push(a.error.message),e=!1)}const i=u("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const r=u("number",{openDuration:this._openDuration});r.status||(this._errors.push(r.error.message),e=!1);const l=u("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=u("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const a=T(D,{parentMenu:this._elements.parentMenu});a.status||(this._errors.push(a.error.message),e=!1)}const c=$({hoverType:this._hoverType});c.status||(this._errors.push(c.error.message),e=!1);const p=u("number",{hoverDelay:this._hoverDelay});p.status||(this._errors.push(p.error.message),e=!1);const f=u("number",{enterDelay:this._enterDelay});f.status||(this._errors.push(f.error.message),e=!1);const d=u("number",{leaveDelay:this._leaveDelay});d.status||(this._errors.push(d.error.message),e=!1);const g=u("string",{prefix:this._prefix});return g.status||(this._errors.push(g.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&T(HTMLElement,{base:t});const r=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=r:this._dom[e]=[...this._dom[e],...r]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),r=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:r,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:r,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){u("function",{callback:e}),u("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){m(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=E(e);(t==="Space"||t==="Enter")&&m(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=E(e);(t==="Space"||t==="Enter")&&(m(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty(`--${this.prefix}transition-duration`,`${this.transitionDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}open-transition-duration`,`${this.openDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}close-transition-duration`,`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class R extends F{constructor({menuItemElement:t,menuLinkElement:s,parentMenu:i,isSubmenuItem:r=!1,childMenu:l=null,toggle:h=null,initialize:c=!0,submenuSibling:p=null}){super({menuItemElement:t,menuLinkElement:s,parentMenu:i,isSubmenuItem:r,childMenu:l,toggle:h});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null,sibling:null});this._elements.parentMenu=i,this._elements.childMenu=l,this._elements.toggle=h,this._elements.sibling=p,c&&this.initialize()}}class U extends j{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:r=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),r&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),x("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class O extends D{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:r="li:has(ul)",submenuToggleSelector:l="button",submenuSelector:h="ul",submenuSubtoggleSelector:c="a",controllerElement:p=null,containerElement:f=null,openClass:d="show",closeClass:g="hide",transitionClass:a="transitioning",transitionDuration:v=250,isTopLevel:C=!0,parentMenu:w=null,hoverType:S="off",hoverDelay:k=250,enterDelay:L=-1,leaveDelay:I=-1,optionalKeySupport:A=!1,prefix:q="am-",initialize:K=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:r,submenuSelector:h,submenuToggleSelector:l,controllerElement:p,containerElement:f,openClass:d,closeClass:g,transitionClass:a,transitionDuration:v,isTopLevel:C,parentMenu:w,hoverType:S,hoverDelay:k,enterDelay:L,leaveDelay:I,prefix:q});o(this,"_MenuType",O);o(this,"_MenuItemType",R);o(this,"_MenuToggleType",U);o(this,"_currentChild",-1);o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:"",submenuSubtoggles:""});o(this,"_optionalSupport",!1);this._optionalSupport=A,this._selectors.menuItems=s,this._selectors.submenuItems=r,this._selectors.submenuToggles=l,this._selectors.submenus=h,this._selectors.submenuSubtoggles=c,this._selectors.menuLinks=[...new Set([i,l])].join(","),K&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){u("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_createChildElements(){this.dom.menuItems.forEach(t=>{let s,i;const r=t.querySelector(this.selectors.menuLinks);if(this.dom.submenuItems.includes(t)){const l=t.querySelector(this.selectors.submenuToggles),h=t.querySelector(this.selectors.submenus),c=new this._MenuType({menuElement:h,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuSubtoggles,submenuSelector:this.selectors.submenus,submenuSubtoggleSelector:this.selectors.submenuSubtoggles,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),p=new this._MenuToggleType({menuToggleElement:l,parentElement:t,controlledMenu:c,parentMenu:this});this._elements.submenuToggles.push(p),l!==r?(i=new this._MenuItemType({menuItemElement:t,menuLinkElement:l,parentMenu:this,isSubmenuItem:!0,childMenu:c,toggle:p}),s=new this._MenuItemType({menuItemElement:t,menuLinkElement:r,parentMenu:this,submenuSibling:i})):s=new this._MenuItemType({menuItemElement:t,menuLinkElement:r,parentMenu:this,isSubmenuItem:!0,childMenu:c,toggle:p})}else s=new this._MenuItemType({menuItemElement:t,menuLinkElement:r,parentMenu:this});this._elements.menuItems.push(s),typeof i<"u"&&this._elements.menuItems.push(i)})}_validate(){let t=super._validate();const s=M({submenuSubtoggleSelector:this._selectors.submenuSubtoggles});s.status||(this._errors.push(s.error.message),t=!1);const i=u("boolean",{optionalKeySupport:this._optionalSupport});return i.status||(this._errors.push(i.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",i=>{if(!(i.pointerType==="pen"||i.pointerType==="touch")){if(this.hoverType==="on"){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s);let r=t.isSubmenuItem?t.elements.toggle:null;if(t.elements.sibling!==null&&(r=t.elements.sibling.elements.toggle),r===null)return;this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{r.preview()},this.enterDelay)):r.preview()}else if(this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),!this.isTopLevel||this.hasOpened)){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild();let r=t.isSubmenuItem?t.elements.toggle:null;t.elements.sibling!==null&&(r=t.elements.sibling.elements.toggle),r!==null?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{r.preview()},this.enterDelay)):r.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren()}}}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",t.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",t.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=E(t);if(this.focusState==="self"){const i=["Space","Enter"],r=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&m(t):(this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&r.includes(s)||this.elements.parentMenu&&l.includes(s))&&m(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=E(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(m(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(r=>r.isOpen)?(m(t),this.closeChildren()):this.elements.parentMenu?(m(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(m(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(m(t),this.focusPreviousChild()):s==="Home"?(m(t),this.focusFirstChild()):s==="End"&&(m(t),this.focusLastChild())))})}}module.exports=O; diff --git a/dist/top-link-disclosure-menu.es.js b/dist/top-link-disclosure-menu.es.js index 0a2e194d..82e60122 100644 --- a/dist/top-link-disclosure-menu.es.js +++ b/dist/top-link-disclosure-menu.es.js @@ -1,13 +1,13 @@ var V = Object.defineProperty; -var x = (n, e, t) => e in n ? V(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; -var r = (n, e, t) => x(n, typeof e != "symbol" ? e + "" : e, t); -function g(n, e) { +var z = (n, e, t) => e in n ? V(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; +var o = (n, e, t) => z(n, typeof e != "symbol" ? e + "" : e, t); +function _(n, e) { n === "" || n.length === 0 || (typeof n == "string" ? e.classList.add(n) : e.classList.add(...n)); } -function _(n, e) { +function y(n, e) { n === "" || n.length === 0 || (typeof n == "string" ? e.classList.remove(n) : e.classList.remove(...n)); } -function b(n, e) { +function T(n, e) { try { if (typeof e != "object") { const t = typeof e; @@ -57,7 +57,7 @@ function u(n, e) { }; } } -function C(n) { +function M(n) { try { if (typeof n != "object") { const e = typeof n; @@ -86,7 +86,7 @@ function C(n) { }; } } -function y(n) { +function b(n) { try { if (typeof n != "object" || Array.isArray(n)) { const e = typeof n; @@ -110,7 +110,7 @@ function y(n) { ); else { const s = {}; - s[e] = n[e], C(s); + s[e] = n[e], M(s); } } return { @@ -124,7 +124,7 @@ function y(n) { }; } } -function z(n) { +function H(n) { try { if (typeof n != "object") { const t = typeof n; @@ -151,7 +151,7 @@ function z(n) { }; } } -function H(n) { +function P(n) { try { if (typeof n != "object") { const t = typeof n; @@ -178,7 +178,7 @@ function H(n) { }; } } -function A(n) { +function O(n) { try { if (typeof n != "object") { const t = typeof n; @@ -205,8 +205,8 @@ function A(n) { }; } } -function O(n, e) { - if (u("string", { tagName: n }).status && b(HTMLElement, e).status) { +function $(n, e) { + if (u("string", { tagName: n }).status && T(HTMLElement, e).status) { const t = n.toLowerCase(); let s = !0; for (const i in e) @@ -215,7 +215,7 @@ function O(n, e) { } else return !1; } -class $ { +class x { /** * Constructs a new `BaseMenuToggle`. * @@ -241,7 +241,7 @@ class $ { * @property {HTMLElement} toggle - The menu toggle. * @property {HTMLElement} parent - The menu containing this toggle. */ - r(this, "_dom", { + o(this, "_dom", { toggle: null, parent: null }); @@ -255,7 +255,7 @@ class $ { * @property {BaseMenu} controlledMenu - The menu controlled by this toggle. * @property {BaseMenu} parentMenu - The menu containing this toggle. */ - r(this, "_elements", { + o(this, "_elements", { controlledMenu: null, parentMenu: null }); @@ -266,7 +266,7 @@ class $ { * * @type {boolean} */ - r(this, "_open", !1); + o(this, "_open", !1); /** * The event that is triggered when the menu toggle expands. * @@ -279,7 +279,7 @@ class $ { * @property {boolean} bubbles - A flag to bubble the event. * @property {Object} details - The details object containing the BaseMenuToggle itself. */ - r(this, "_expandEvent", new CustomEvent("accessibleMenuExpand", { + o(this, "_expandEvent", new CustomEvent("accessibleMenuExpand", { bubbles: !0, detail: { toggle: this } })); @@ -295,7 +295,7 @@ class $ { * @property {boolean} bubbles - A flag to bubble the event. * @property {Object} details - The details object containing the BaseMenuToggle itself. */ - r(this, "_collapseEvent", new CustomEvent("accessibleMenuCollapse", { + o(this, "_collapseEvent", new CustomEvent("accessibleMenuCollapse", { bubbles: !0, detail: { toggle: this } })); @@ -404,19 +404,19 @@ class $ { * @param {boolean} [emit = true] - A toggle to emit the expand event once expanded. */ _expand(e = !0) { - const { closeClass: t, openClass: s, transitionClass: i, openDuration: o } = this.elements.controlledMenu; - this.dom.toggle.setAttribute("aria-expanded", "true"), this.elements.controlledMenu.elements.rootMenu.hasOpened = !0, i !== "" ? (g(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - _(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - g(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + const { closeClass: t, openClass: s, transitionClass: i, openDuration: r } = this.elements.controlledMenu; + this.dom.toggle.setAttribute("aria-expanded", "true"), this.elements.controlledMenu.elements.rootMenu.hasOpened = !0, i !== "" ? (_(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + y(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + _(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { setTimeout(() => { - _( + y( i, this.elements.controlledMenu.dom.menu ); - }, o); + }, r); }); }); - })) : (g(s, this.elements.controlledMenu.dom.menu), _(t, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._expandEvent); + })) : (_(s, this.elements.controlledMenu.dom.menu), y(t, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._expandEvent); } /** * Collapses the controlled menu. @@ -436,19 +436,19 @@ class $ { * @param {boolean} [emit = true] - A toggle to emit the collapse event once collapsed. */ _collapse(e = !0) { - const { closeClass: t, openClass: s, transitionClass: i, closeDuration: o } = this.elements.controlledMenu; - this.dom.toggle.setAttribute("aria-expanded", "false"), i !== "" ? (g(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - _(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - g(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + const { closeClass: t, openClass: s, transitionClass: i, closeDuration: r } = this.elements.controlledMenu; + this.dom.toggle.setAttribute("aria-expanded", "false"), i !== "" ? (_(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + y(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + _(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { setTimeout(() => { - _( + y( i, this.elements.controlledMenu.dom.menu ); - }, o); + }, r); }); }); - })) : (g(t, this.elements.controlledMenu.dom.menu), _(s, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._collapseEvent); + })) : (_(t, this.elements.controlledMenu.dom.menu), y(s, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._collapseEvent); } /** * Opens the controlled menu. @@ -534,7 +534,7 @@ class j { menuLinkElement: t, parentMenu: s, isSubmenuItem: i = !1, - childMenu: o = null, + childMenu: r = null, toggle: l = null }) { /** @@ -547,7 +547,7 @@ class j { * @property {HTMLElement} item - The menu item. * @property {HTMLElement} link - The menu item's link. */ - r(this, "_dom", { + o(this, "_dom", { item: null, link: null }); @@ -562,7 +562,7 @@ class j { * @property {?BaseMenu} childMenu - The menu contained within this menu item. * @property {?BaseMenuToggle} toggle - The menu toggle within this menu item that controls the `childMenu`. */ - r(this, "_elements", { + o(this, "_elements", { parentMenu: null, childMenu: null, toggle: null @@ -574,8 +574,8 @@ class j { * * @type {boolean} */ - r(this, "_submenu", !1); - this._dom.item = e, this._dom.link = t, this._elements.parentMenu = s, this._elements.childMenu = o, this._elements.toggle = l, this._submenu = i; + o(this, "_submenu", !1); + this._dom.item = e, this._dom.link = t, this._elements.parentMenu = s, this._elements.childMenu = r, this._elements.toggle = l, this._submenu = i; } /** * Initialize the menu item. @@ -641,7 +641,7 @@ class j { }); } } -function M(n) { +function E(n) { try { const e = n.key || n.keyCode, t = { Enter: e === "Enter" || e === 13, @@ -665,7 +665,7 @@ function M(n) { function m(n) { n.preventDefault(), n.stopPropagation(); } -class E { +class D { /** * Constructs a new `BaseMenu`. * @@ -681,37 +681,39 @@ class E { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). - * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in miliseconds). - * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). + * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in milliseconds). + * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = false] - A flag to mark the root menu. * @param {?BaseMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in milliseconds). + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. */ constructor({ menuElement: e, menuItemSelector: t = "li", menuLinkSelector: s = "a", submenuItemSelector: i = "li:has(ul)", - submenuToggleSelector: o = "a", + submenuToggleSelector: r = "a", submenuSelector: l = "ul", controllerElement: h = null, containerElement: c = null, openClass: p = "show", - closeClass: d = "hide", - transitionClass: f = "transitioning", - transitionDuration: a = 250, - openDuration: D = -1, + closeClass: f = "hide", + transitionClass: d = "transitioning", + transitionDuration: g = 250, + openDuration: a = -1, closeDuration: v = -1, - isTopLevel: T = !0, + isTopLevel: C = !0, parentMenu: w = null, hoverType: S = "off", hoverDelay: k = 250, enterDelay: L = -1, - leaveDelay: I = -1 + leaveDelay: I = -1, + prefix: A = "am-" }) { /** * The class to use when generating submenus. @@ -720,7 +722,7 @@ class E { * * @type {typeof BaseMenu} */ - r(this, "_MenuType", E); + o(this, "_MenuType", D); /** * The class to use when generating menu items. * @@ -728,7 +730,7 @@ class E { * * @type {typeof BaseMenuItem} */ - r(this, "_MenuItemType", j); + o(this, "_MenuItemType", j); /** * The class to use when generating submenu toggles. * @@ -736,7 +738,7 @@ class E { * * @type {typeof BaseMenuToggle} */ - r(this, "_MenuToggleType", $); + o(this, "_MenuToggleType", x); /** * The DOM elements within the menu. * @@ -752,7 +754,7 @@ class E { * @property {HTMLElement} controller - The toggle for this menu. * @property {HTMLElement} container - The container for this menu. */ - r(this, "_dom", { + o(this, "_dom", { menu: null, menuItems: [], submenuItems: [], @@ -774,7 +776,7 @@ class E { * @property {string} submenuToggles - The query selector for menu links that function as submenu toggles. * @property {string} submenus - The query selector for for submenus. */ - r(this, "_selectors", { + o(this, "_selectors", { menuItems: "", menuLinks: "", submenuItems: "", @@ -794,7 +796,7 @@ class E { * @property {?BaseMenu} parentMenu - The parent menu. * @property {?BaseMenu} rootMenu - The root menu of the menu tree. */ - r(this, "_elements", { + o(this, "_elements", { menuItems: [], submenuToggles: [], controller: null, @@ -808,7 +810,7 @@ class E { * * @type {string|string[]} */ - r(this, "_openClass", "show"); + o(this, "_openClass", "show"); /** * The class(es) to apply when the menu is closed. * @@ -816,7 +818,7 @@ class E { * * @type {string|string[]} */ - r(this, "_closeClass", "hide"); + o(this, "_closeClass", "hide"); /** * The class(es) to apply when the menu is transitioning between states. * @@ -824,31 +826,31 @@ class E { * * @type {string|string[]} */ - r(this, "_transitionClass", "transitioning"); + o(this, "_transitionClass", "transitioning"); /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * @protected * * @type {number} */ - r(this, "_transitionDuration", 250); + o(this, "_transitionDuration", 250); /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * @protected * * @type {number} */ - r(this, "_openDuration", -1); + o(this, "_openDuration", -1); /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * @protected * * @type {number} */ - r(this, "_closeDuration", -1); + o(this, "_closeDuration", -1); /** * A flag marking the root menu. * @@ -856,7 +858,7 @@ class E { * * @type {boolean} */ - r(this, "_root", !0); + o(this, "_root", !0); /** * The index of the currently selected menu item in the menu. * @@ -864,7 +866,7 @@ class E { * * @type {number} */ - r(this, "_currentChild", 0); + o(this, "_currentChild", 0); /** * The current state of the menu's focus. * @@ -872,7 +874,7 @@ class E { * * @type {string} */ - r(this, "_focusState", "none"); + o(this, "_focusState", "none"); /** * This last event triggered on the menu. * @@ -880,7 +882,7 @@ class E { * * @type {string} */ - r(this, "_currentEvent", "none"); + o(this, "_currentEvent", "none"); /** * The type of hoverability for the menu. * @@ -888,31 +890,39 @@ class E { * * @type {string} */ - r(this, "_hoverType", "off"); + o(this, "_hoverType", "off"); /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * @protected * * @type {number} */ - r(this, "_hoverDelay", 250); + o(this, "_hoverDelay", 250); /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * @protected * * @type {number} */ - r(this, "_enterDelay", -1); + o(this, "_enterDelay", -1); /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * @protected * * @type {number} */ - r(this, "_leaveDelay", -1); + o(this, "_leaveDelay", -1); + /** + * The prefix to use for CSS custom properties. + * + * @protected + * + * @type {string} + */ + o(this, "_prefix", "am-"); /** * A variable to hold the hover timeout function. * @@ -920,7 +930,7 @@ class E { * * @type {?Function} */ - r(this, "_hoverTimeout", null); + o(this, "_hoverTimeout", null); /** * A flag to check if the menu can dynamically hover based on if a menu has been opened already. * @@ -928,7 +938,7 @@ class E { * * @type {boolean} */ - r(this, "_hasOpened", !1); + o(this, "_hasOpened", !1); /** * An array of error messages generated by the menu. * @@ -936,8 +946,8 @@ class E { * * @type {string[]} */ - r(this, "_errors", []); - this._dom.menu = e, this._dom.controller = h, this._dom.container = c, this._selectors.menuItems = t, this._selectors.menuLinks = s, this._selectors.submenuItems = i, this._selectors.submenuToggles = o, this._selectors.submenus = l, this._elements.menuItems = [], this._elements.submenuToggles = [], this._elements.controller = null, this._elements.parentMenu = w, this._elements.rootMenu = T ? this : null, this._openClass = p || "", this._closeClass = d || "", this._transitionClass = f || "", this._transitionDuration = a, this._openDuration = D, this._closeDuration = v, this._root = T, this._hoverType = S, this._hoverDelay = k, this._enterDelay = L, this._leaveDelay = I; + o(this, "_errors", []); + this._dom.menu = e, this._dom.controller = h, this._dom.container = c, this._selectors.menuItems = t, this._selectors.menuLinks = s, this._selectors.submenuItems = i, this._selectors.submenuToggles = r, this._selectors.submenus = l, this._elements.menuItems = [], this._elements.submenuToggles = [], this._elements.controller = null, this._elements.parentMenu = w, this._elements.rootMenu = C ? this : null, this._openClass = p || "", this._closeClass = f || "", this._transitionClass = d || "", this._transitionDuration = g, this._openDuration = a, this._closeDuration = v, this._prefix = A || "", this._root = C, this._hoverType = S, this._hoverDelay = k, this._enterDelay = L, this._leaveDelay = I; } /** * Initializes the menu. @@ -970,7 +980,7 @@ class E { parentElement: this.dom.container, controlledMenu: this }); - O("button", { toggle: e.dom.toggle }) || e.dom.toggle.setAttribute("role", "button"), e.dom.toggle.setAttribute("aria-controls", this.dom.menu.id), this._elements.controller = e; + $("button", { toggle: e.dom.toggle }) || e.dom.toggle.setAttribute("role", "button"), e.dom.toggle.setAttribute("aria-controls", this.dom.menu.id), this._elements.controller = e; } this._createChildElements(), this._setTransitionDurations(), this.isTopLevel && (window.AccessibleMenu = window.AccessibleMenu || { menus: {} @@ -1064,7 +1074,7 @@ class E { return this.isTopLevel ? this._transitionClass : this.elements.rootMenu.transitionClass; } /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's transition duration. @@ -1079,7 +1089,7 @@ class E { return this.isTopLevel ? this._transitionDuration : this.elements.rootMenu.transitionDuration; } /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's openDuration. @@ -1096,7 +1106,7 @@ class E { return this._openDuration === -1 ? this.transitionDuration : this.isTopLevel ? this._openDuration : this.elements.rootMenu.openDuration; } /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's closeDuration. @@ -1180,7 +1190,7 @@ class E { return this._root ? this._hoverType : this.elements.rootMenu.hoverType; } /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's hover delay. @@ -1193,7 +1203,7 @@ class E { return this._root ? this._hoverDelay : this.elements.rootMenu.hoverDelay; } /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's enter delay. @@ -1208,7 +1218,7 @@ class E { return this._enterDelay === -1 ? this.hoverDelay : this._root ? this._enterDelay : this.elements.rootMenu.enterDelay; } /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's leave delay. @@ -1222,6 +1232,19 @@ class E { get leaveDelay() { return this._leaveDelay === -1 ? this.hoverDelay : this._root ? this._leaveDelay : this.elements.rootMenu.leaveDelay; } + /** + * The prefix to use for CSS custom properties. + * + * This functions differently for root vs. submenus. + * Submenus will always inherit their root menu's prefix. + * + * @type {string} + * + * @see _prefix + */ + get prefix() { + return this._root ? this._prefix : this.elements.rootMenu.prefix; + } /** * A flag to check if the menu's focus methods should _actually_ move the focus in the DOM. * @@ -1265,13 +1288,13 @@ class E { return this._errors; } set openClass(e) { - y({ openClass: e }), this._openClass !== e && (this._openClass = e); + b({ openClass: e }), this._openClass !== e && (this._openClass = e); } set closeClass(e) { - y({ closeClass: e }), this._closeClass !== e && (this._closeClass = e); + b({ closeClass: e }), this._closeClass !== e && (this._closeClass = e); } set transitionClass(e) { - y({ transitionClass: e }), this._transitionClass !== e && (this._transitionClass = e); + b({ transitionClass: e }), this._transitionClass !== e && (this._transitionClass = e); } set transitionDuration(e) { u("number", { value: e }), this._transitionDuration !== e && (this._transitionDuration = e, this._setTransitionDurations()); @@ -1286,27 +1309,27 @@ class E { u("number", { value: e }); function t(s) { if (["mouse", "character"].includes(s.currentEvent) && s.elements.parentMenu) { - let o = 0, l = !1; - for (; !l && o < s.elements.parentMenu.elements.menuItems.length; ) { - const h = s.elements.parentMenu.elements.menuItems[o]; - h.isSubmenuItem && h.elements.toggle.elements.controlledMenu === s && (l = !0, s.elements.parentMenu.currentEvent = s.currentEvent, s.elements.parentMenu.currentChild = o), o++; + let r = 0, l = !1; + for (; !l && r < s.elements.parentMenu.elements.menuItems.length; ) { + const h = s.elements.parentMenu.elements.menuItems[r]; + h.isSubmenuItem && h.elements.toggle.elements.controlledMenu === s && (l = !0, s.elements.parentMenu.currentEvent = s.currentEvent, s.elements.parentMenu.currentChild = r), r++; } } } e < -1 ? (this._currentChild = -1, t(this)) : e >= this.elements.menuItems.length ? (this._currentChild = this.elements.menuItems.length - 1, t(this)) : this.focusChild !== e && (this._currentChild = e, t(this)); } set focusState(e) { - z({ value: e }), this._focusState !== e && (this._focusState = e), this.elements.submenuToggles.length > 0 && (e === "self" || e === "none") && this.elements.submenuToggles.forEach((t) => { + H({ value: e }), this._focusState !== e && (this._focusState = e), this.elements.submenuToggles.length > 0 && (e === "self" || e === "none") && this.elements.submenuToggles.forEach((t) => { t.elements.controlledMenu.focusState = "none"; }), this.elements.parentMenu && (e === "self" || e === "child") && (this.elements.parentMenu.focusState = "child"); } set currentEvent(e) { - H({ value: e }), this._currentEvent !== e && (this._currentEvent = e, this.elements.submenuToggles.length > 0 && this.elements.submenuToggles.forEach((t) => { + P({ value: e }), this._currentEvent !== e && (this._currentEvent = e, this.elements.submenuToggles.length > 0 && this.elements.submenuToggles.forEach((t) => { t.elements.controlledMenu.currentEvent = e; })); } set hoverType(e) { - A({ value: e }), this._hoverType !== e && (this._hoverType = e); + O({ value: e }), this._hoverType !== e && (this._hoverType = e); } set hoverDelay(e) { u("number", { value: e }), this._hoverDelay !== e && (this._hoverDelay = e); @@ -1317,6 +1340,9 @@ class E { set leaveDelay(e) { u("number", { value: e }), this._leaveDelay !== e && (this._leaveDelay = e); } + set prefix(e) { + u("string", { value: e }), this._prefix !== e && (this._prefix = e); + } set hasOpened(e) { u("boolean", { value: e }), this._hasOpened !== e && (this._hasOpened = e); } @@ -1329,35 +1355,35 @@ class E { */ _validate() { let e = !0, t; - this._dom.container !== null || this._dom.controller !== null ? t = b(HTMLElement, { + this._dom.container !== null || this._dom.controller !== null ? t = T(HTMLElement, { menuElement: this._dom.menu, controllerElement: this._dom.controller, containerElement: this._dom.container - }) : t = b(HTMLElement, { + }) : t = T(HTMLElement, { menuElement: this._dom.menu }), t.status || (this._errors.push(t.error.message), e = !1); let s; - if (this._selectors.submenuItems !== "" ? s = C({ + if (this._selectors.submenuItems !== "" ? s = M({ menuItemSelector: this._selectors.menuItems, menuLinkSelector: this._selectors.menuLinks, submenuItemSelector: this._selectors.submenuItems, submenuToggleSelector: this._selectors.submenuToggles, submenuSelector: this._selectors.submenus - }) : s = C({ + }) : s = M({ menuItemSelector: this._selectors.menuItems, menuLinkSelector: this._selectors.menuLinks }), s.status || (this._errors.push(s.error.message), e = !1), this._openClass !== "") { - const a = y({ openClass: this._openClass }); + const a = b({ openClass: this._openClass }); a.status || (this._errors.push(a.error.message), e = !1); } if (this._closeClass !== "") { - const a = y({ + const a = b({ closeClass: this._closeClass }); a.status || (this._errors.push(a.error.message), e = !1); } if (this._transitionClass !== "") { - const a = y({ + const a = b({ transitionClass: this._transitionClass }); a.status || (this._errors.push(a.error.message), e = !1); @@ -1366,35 +1392,37 @@ class E { transitionDuration: this._transitionDuration }); i.status || (this._errors.push(i.error.message), e = !1); - const o = u("number", { + const r = u("number", { openDuration: this._openDuration }); - o.status || (this._errors.push(o.error.message), e = !1); + r.status || (this._errors.push(r.error.message), e = !1); const l = u("number", { closeDuration: this._closeDuration }); l.status || (this._errors.push(l.error.message), e = !1); const h = u("boolean", { isTopLevel: this._root }); if (h.status || (this._errors.push(h.error.message), e = !1), this._elements.parentMenu !== null) { - const a = b(E, { + const a = T(D, { parentMenu: this._elements.parentMenu }); a.status || (this._errors.push(a.error.message), e = !1); } - const c = A({ hoverType: this._hoverType }); + const c = O({ hoverType: this._hoverType }); c.status || (this._errors.push(c.error.message), e = !1); const p = u("number", { hoverDelay: this._hoverDelay }); p.status || (this._errors.push(p.error.message), e = !1); - const d = u("number", { + const f = u("number", { enterDelay: this._enterDelay }); - d.status || (this._errors.push(d.error.message), e = !1); - const f = u("number", { + f.status || (this._errors.push(f.error.message), e = !1); + const d = u("number", { leaveDelay: this._leaveDelay }); - return f.status || (this._errors.push(f.error.message), e = !1), e; + d.status || (this._errors.push(d.error.message), e = !1); + const g = u("string", { prefix: this._prefix }); + return g.status || (this._errors.push(g.error.message), e = !1), e; } /** * Sets DOM elements within the menu. @@ -1413,15 +1441,15 @@ class E { throw new Error( `AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.` ); - t !== this.dom.menu && b(HTMLElement, { base: t }); - const o = Array.from( + t !== this.dom.menu && T(HTMLElement, { base: t }); + const r = Array.from( t.querySelectorAll(this.selectors[e]) ).filter( (l) => l.parentElement === t ); - s ? this._dom[e] = o : this._dom[e] = [ + s ? this._dom[e] = r : this._dom[e] = [ ...this._dom[e], - ...o + ...r ]; } else throw new Error( @@ -1486,7 +1514,7 @@ class E { this.dom.menuItems.forEach((e) => { let t; if (this.dom.submenuItems.includes(e)) { - const s = e.querySelector(this.selectors.submenuToggles), i = e.querySelector(this.selectors.submenus), o = new this._MenuType({ + const s = e.querySelector(this.selectors.submenuToggles), i = e.querySelector(this.selectors.submenus), r = new this._MenuType({ menuElement: i, menuItemSelector: this.selectors.menuItems, menuLinkSelector: this.selectors.menuLinks, @@ -1508,7 +1536,7 @@ class E { }), l = new this._MenuToggleType({ menuToggleElement: s, parentElement: e, - controlledMenu: o, + controlledMenu: r, parentMenu: this }); this._elements.submenuToggles.push(l), t = new this._MenuItemType({ @@ -1516,7 +1544,7 @@ class E { menuLinkElement: s, parentMenu: this, isSubmenuItem: !0, - childMenu: o, + childMenu: r, toggle: l }); } else { @@ -1688,7 +1716,7 @@ class E { "keydown", (e) => { this.currentEvent = "keyboard"; - const t = M(e); + const t = E(e); (t === "Space" || t === "Enter") && m(e); } ); @@ -1704,7 +1732,7 @@ class E { _handleKeyup() { this.isTopLevel && this.elements.controller && this.elements.controller.dom.toggle.addEventListener("keyup", (e) => { this.currentEvent = "keyboard"; - const t = M(e); + const t = E(e); (t === "Space" || t === "Enter") && (m(e), this.elements.controller.toggle(), this.elements.controller.isOpen && this.focusFirstChild()); }); } @@ -1716,17 +1744,19 @@ class E { * - `--am-open-transition-duration`, and * - `--am-close-transition-duration`. * + * The prefix of `am-` can be changed by setting the menu's prefix value. + * * @protected */ _setTransitionDurations() { this.dom.menu.style.setProperty( - "--am-transition-duration", + `--${this.prefix}transition-duration`, `${this.transitionDuration}ms` ), this.dom.menu.style.setProperty( - "--am-open-transition-duration", + `--${this.prefix}open-transition-duration`, `${this.openDuration}ms` ), this.dom.menu.style.setProperty( - "--am-close-transition-duration", + `--${this.prefix}close-transition-duration`, `${this.closeDuration}ms` ); } @@ -1847,7 +1877,7 @@ class E { }); } } -class P extends j { +class R extends j { /** * Constructs a new `TopLinkDisclosureMenuItem`. * @@ -1865,7 +1895,7 @@ class P extends j { menuItemElement: t, menuLinkElement: s, parentMenu: i, - isSubmenuItem: o = !1, + isSubmenuItem: r = !1, childMenu: l = null, toggle: h = null, initialize: c = !0, @@ -1875,7 +1905,7 @@ class P extends j { menuItemElement: t, menuLinkElement: s, parentMenu: i, - isSubmenuItem: o, + isSubmenuItem: r, childMenu: l, toggle: h }); @@ -1891,7 +1921,7 @@ class P extends j { * @property {?TopLinkDisclosureMenuToggle} toggle - The menu toggle within this menu item that controls the `childMenu`. * @property {?TopLinkDisclosureMenuItem} sibling - The sibling menu item that is a submenu item. */ - r(this, "_elements", { + o(this, "_elements", { parentMenu: null, childMenu: null, toggle: null, @@ -1900,7 +1930,7 @@ class P extends j { this._elements.parentMenu = i, this._elements.childMenu = l, this._elements.toggle = h, this._elements.sibling = p, c && this.initialize(); } } -class R extends $ { +class U extends x { /** * Constructs a new `TopLinkDisclosureMenuToggle`. * @@ -1916,14 +1946,14 @@ class R extends $ { parentElement: t, controlledMenu: s, parentMenu: i = null, - initialize: o = !0 + initialize: r = !0 }) { super({ menuToggleElement: e, parentElement: t, controlledMenu: s, parentMenu: i - }), o && this.initialize(); + }), r && this.initialize(); } /** * Sets the ARIA attributes on the toggle and controlled menu. @@ -1939,7 +1969,7 @@ class R extends $ { * @protected */ _setAriaAttributes() { - super._setAriaAttributes(), O("button", { toggle: this.dom.toggle }) || this.dom.toggle.setAttribute("role", "button"), this.dom.toggle.setAttribute( + super._setAriaAttributes(), $("button", { toggle: this.dom.toggle }) || this.dom.toggle.setAttribute("role", "button"), this.dom.toggle.setAttribute( "aria-controls", this.elements.controlledMenu.dom.menu.id ); @@ -1972,7 +2002,7 @@ class R extends $ { this.isOpen && this.closeChildren(), super.close(); } } -class F extends E { +class F extends D { /** * Constructs a new `TopLinkDisclosureMenu`. * @@ -1989,58 +2019,61 @@ class F extends E { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?TopLinkDisclosureMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). * @param {boolean} [options.optionalKeySupport = false] - A flag to add optional keyboard support (Arrow keys, Home, and End) to the menu. + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. */ constructor({ menuElement: t, menuItemSelector: s = "li", menuLinkSelector: i = "a", - submenuItemSelector: o = "li:has(ul)", + submenuItemSelector: r = "li:has(ul)", submenuToggleSelector: l = "button", submenuSelector: h = "ul", submenuSubtoggleSelector: c = "a", controllerElement: p = null, - containerElement: d = null, - openClass: f = "show", - closeClass: a = "hide", - transitionClass: D = "transitioning", + containerElement: f = null, + openClass: d = "show", + closeClass: g = "hide", + transitionClass: a = "transitioning", transitionDuration: v = 250, - isTopLevel: T = !0, + isTopLevel: C = !0, parentMenu: w = null, hoverType: S = "off", hoverDelay: k = 250, enterDelay: L = -1, leaveDelay: I = -1, - optionalKeySupport: q = !1, + optionalKeySupport: A = !1, + prefix: q = "am-", initialize: K = !0 }) { super({ menuElement: t, menuItemSelector: s, menuLinkSelector: i, - submenuItemSelector: o, + submenuItemSelector: r, submenuSelector: h, submenuToggleSelector: l, controllerElement: p, - containerElement: d, - openClass: f, - closeClass: a, - transitionClass: D, + containerElement: f, + openClass: d, + closeClass: g, + transitionClass: a, transitionDuration: v, - isTopLevel: T, + isTopLevel: C, parentMenu: w, hoverType: S, hoverDelay: k, enterDelay: L, - leaveDelay: I + leaveDelay: I, + prefix: q }); /** * The class to use when generating submenus. @@ -2049,7 +2082,7 @@ class F extends E { * * @type {typeof TopLinkDisclosureMenu} */ - r(this, "_MenuType", F); + o(this, "_MenuType", F); /** * The class to use when generating menu items. * @@ -2057,7 +2090,7 @@ class F extends E { * * @type {typeof TopLinkDisclosureMenuItem} */ - r(this, "_MenuItemType", P); + o(this, "_MenuItemType", R); /** * The class to use when generating submenu toggles. * @@ -2065,7 +2098,7 @@ class F extends E { * * @type {typeof TopLinkDisclosureMenuToggle} */ - r(this, "_MenuToggleType", R); + o(this, "_MenuToggleType", U); /** * The index of the currently selected menu item in the menu. * @@ -2073,7 +2106,7 @@ class F extends E { * * @type {number} */ - r(this, "_currentChild", -1); + o(this, "_currentChild", -1); /** * The query selectors used by the menu to populate the dom. * @@ -2088,7 +2121,7 @@ class F extends E { * @property {string} submenus - The query selector for for submenus. * @property {string} submenuSubtoggles - The query selector for menu links that function as submenu toggles below the top level. */ - r(this, "_selectors", { + o(this, "_selectors", { menuItems: "", menuLinks: "", submenuItems: "", @@ -2103,8 +2136,8 @@ class F extends E { * * @type {boolean} */ - r(this, "_optionalSupport", !1); - this._optionalSupport = q, this._selectors.menuItems = s, this._selectors.submenuItems = o, this._selectors.submenuToggles = l, this._selectors.submenus = h, this._selectors.submenuSubtoggles = c, this._selectors.menuLinks = [ + o(this, "_optionalSupport", !1); + this._optionalSupport = A, this._selectors.menuItems = s, this._selectors.submenuItems = r, this._selectors.submenuToggles = l, this._selectors.submenus = h, this._selectors.submenuSubtoggles = c, this._selectors.menuLinks = [ .../* @__PURE__ */ new Set([i, l]) ].join(","), K && this.initialize(); } @@ -2152,7 +2185,7 @@ class F extends E { _createChildElements() { this.dom.menuItems.forEach((t) => { let s, i; - const o = t.querySelector(this.selectors.menuLinks); + const r = t.querySelector(this.selectors.menuLinks); if (this.dom.submenuItems.includes(t)) { const l = t.querySelector(this.selectors.submenuToggles), h = t.querySelector(this.selectors.submenus), c = new this._MenuType({ menuElement: h, @@ -2177,7 +2210,7 @@ class F extends E { controlledMenu: c, parentMenu: this }); - this._elements.submenuToggles.push(p), l !== o ? (i = new this._MenuItemType({ + this._elements.submenuToggles.push(p), l !== r ? (i = new this._MenuItemType({ menuItemElement: t, menuLinkElement: l, parentMenu: this, @@ -2186,12 +2219,12 @@ class F extends E { toggle: p }), s = new this._MenuItemType({ menuItemElement: t, - menuLinkElement: o, + menuLinkElement: r, parentMenu: this, submenuSibling: i })) : s = new this._MenuItemType({ menuItemElement: t, - menuLinkElement: o, + menuLinkElement: r, parentMenu: this, isSubmenuItem: !0, childMenu: c, @@ -2200,7 +2233,7 @@ class F extends E { } else s = new this._MenuItemType({ menuItemElement: t, - menuLinkElement: o, + menuLinkElement: r, parentMenu: this }); this._elements.menuItems.push(s), typeof i < "u" && this._elements.menuItems.push(i); @@ -2215,7 +2248,7 @@ class F extends E { */ _validate() { let t = super._validate(); - const s = C({ + const s = M({ submenuSubtoggleSelector: this._selectors.submenuSubtoggles }); s.status || (this._errors.push(s.error.message), t = !1); @@ -2290,17 +2323,17 @@ class F extends E { if (!(i.pointerType === "pen" || i.pointerType === "touch")) { if (this.hoverType === "on") { this.currentEvent = "mouse", this.elements.rootMenu.blurChildren(), this.focusChild(s); - let o = t.isSubmenuItem ? t.elements.toggle : null; - if (t.elements.sibling !== null && (o = t.elements.sibling.elements.toggle), o === null) return; + let r = t.isSubmenuItem ? t.elements.toggle : null; + if (t.elements.sibling !== null && (r = t.elements.sibling.elements.toggle), r === null) return; this.enterDelay > 0 ? (this._clearTimeout(), this._setTimeout(() => { - o.preview(); - }, this.enterDelay)) : o.preview(); + r.preview(); + }, this.enterDelay)) : r.preview(); } else if (this.hoverType === "dynamic" && (this.currentChild = s, (!this.isTopLevel || this.focusState !== "none") && (this.currentEvent = "mouse", this.elements.rootMenu.blurChildren(), this.focusCurrentChild()), !this.isTopLevel || this.hasOpened)) { this.currentEvent = "mouse", this.elements.rootMenu.blurChildren(), this.focusCurrentChild(); - let o = t.isSubmenuItem ? t.elements.toggle : null; - t.elements.sibling !== null && (o = t.elements.sibling.elements.toggle), o !== null ? this.enterDelay > 0 ? (this._clearTimeout(), this._setTimeout(() => { - o.preview(); - }, this.enterDelay)) : o.preview() : this.enterDelay > 0 ? (this._clearTimeout(), this._setTimeout(() => { + let r = t.isSubmenuItem ? t.elements.toggle : null; + t.elements.sibling !== null && (r = t.elements.sibling.elements.toggle), r !== null ? this.enterDelay > 0 ? (this._clearTimeout(), this._setTimeout(() => { + r.preview(); + }, this.enterDelay)) : r.preview() : this.enterDelay > 0 ? (this._clearTimeout(), this._setTimeout(() => { this.closeChildren(); }, this.enterDelay)) : this.closeChildren(); } @@ -2332,9 +2365,9 @@ class F extends E { _handleKeydown() { super._handleKeydown(), this.dom.menu.addEventListener("keydown", (t) => { this.currentEvent = "keyboard"; - const s = M(t); + const s = E(t); if (this.focusState === "self") { - const i = ["Space", "Enter"], o = ["Escape"], l = ["Escape"]; + const i = ["Space", "Enter"], r = ["Escape"], l = ["Escape"]; this.optionalKeySupport ? [ "ArrowUp", "ArrowRight", @@ -2342,7 +2375,7 @@ class F extends E { "ArrowLeft", "Home", "End" - ].includes(s) && m(t) : (this.currentMenuItem.isSubmenuItem && i.includes(s) || this.elements.controller && o.includes(s) || this.elements.parentMenu && l.includes(s)) && m(t); + ].includes(s) && m(t) : (this.currentMenuItem.isSubmenuItem && i.includes(s) || this.elements.controller && r.includes(s) || this.elements.parentMenu && l.includes(s)) && m(t); } }); } @@ -2371,9 +2404,9 @@ class F extends E { _handleKeyup() { super._handleKeyup(), this.dom.menu.addEventListener("keyup", (t) => { this.currentEvent = "keyboard"; - const s = M(t); + const s = E(t); this.focusState === "self" && (s === "Space" || s === "Enter" ? this.currentMenuItem.isSubmenuItem ? (m(t), this.currentMenuItem.elements.toggle.isOpen ? this.currentMenuItem.elements.toggle.close() : this.currentMenuItem.elements.toggle.preview()) : this.currentMenuItem.dom.link.click() : s === "Escape" ? this.elements.submenuToggles.some( - (o) => o.isOpen + (r) => r.isOpen ) ? (m(t), this.closeChildren()) : this.elements.parentMenu ? (m(t), this.elements.parentMenu.currentEvent = this.currentEvent, this.elements.parentMenu.closeChildren(), this.elements.parentMenu.focusCurrentChild()) : this.isTopLevel && this.elements.controller && this.elements.controller.isOpen && (this.elements.controller.close(), this.focusController()) : this.optionalKeySupport && (s === "ArrowDown" || s === "ArrowRight" ? (m(t), this.currentMenuItem.isSubmenuItem && this.currentMenuItem.elements.toggle.isOpen ? (this.currentMenuItem.elements.childMenu.currentEvent = "keyboard", this.currentMenuItem.elements.childMenu.focusFirstChild()) : this.focusNextChild()) : s === "ArrowUp" || s === "ArrowLeft" ? (m(t), this.focusPreviousChild()) : s === "Home" ? (m(t), this.focusFirstChild()) : s === "End" && (m(t), this.focusLastChild()))); }); } diff --git a/dist/top-link-disclosure-menu.iife.js b/dist/top-link-disclosure-menu.iife.js index 04471ce4..25552cc4 100644 --- a/dist/top-link-disclosure-menu.iife.js +++ b/dist/top-link-disclosure-menu.iife.js @@ -1,3 +1,3 @@ -var TopLinkDisclosureMenu=function(){"use strict";var P=Object.defineProperty;var R=(p,m,g)=>m in p?P(p,m,{enumerable:!0,configurable:!0,writable:!0,value:g}):p[m]=g;var r=(p,m,g)=>R(p,typeof m!="symbol"?m+"":m,g);function p(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function m(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function g(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function u(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function T(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function _(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],T(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function q(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function K(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function O(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function $(n,e){if(u("string",{tagName:n}).status&&g(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class j{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){r(this,"_dom",{toggle:null,parent:null});r(this,"_elements",{controlledMenu:null,parentMenu:null});r(this,"_open",!1);r(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));r(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){u("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(p(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{m(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{p(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{m(i,this.elements.controlledMenu.dom.menu)},o)})})})):(p(s,this.elements.controlledMenu.dom.menu),m(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(p(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{m(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{p(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{m(i,this.elements.controlledMenu.dom.menu)},o)})})})):(p(t,this.elements.controlledMenu.dom.menu),m(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:o=null,toggle:l=null}){r(this,"_dom",{item:null,link:null});r(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});r(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=o,this._elements.toggle=l,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function C(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function c(n){n.preventDefault(),n.stopPropagation()}class M{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:o="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:d=null,openClass:f="show",closeClass:y="hide",transitionClass:b="transitioning",transitionDuration:a=250,openDuration:v=-1,closeDuration:w=-1,isTopLevel:E=!0,parentMenu:S=null,hoverType:k="off",hoverDelay:L=250,enterDelay:I=-1,leaveDelay:A=-1}){r(this,"_MenuType",M);r(this,"_MenuItemType",F);r(this,"_MenuToggleType",j);r(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});r(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});r(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});r(this,"_openClass","show");r(this,"_closeClass","hide");r(this,"_transitionClass","transitioning");r(this,"_transitionDuration",250);r(this,"_openDuration",-1);r(this,"_closeDuration",-1);r(this,"_root",!0);r(this,"_currentChild",0);r(this,"_focusState","none");r(this,"_currentEvent","none");r(this,"_hoverType","off");r(this,"_hoverDelay",250);r(this,"_enterDelay",-1);r(this,"_leaveDelay",-1);r(this,"_hoverTimeout",null);r(this,"_hasOpened",!1);r(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=d,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=o,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=S,this._elements.rootMenu=E?this:null,this._openClass=f||"",this._closeClass=y||"",this._transitionClass=b||"",this._transitionDuration=a,this._openDuration=v,this._closeDuration=w,this._root=E,this._hoverType=k,this._hoverDelay=L,this._enterDelay=I,this._leaveDelay=A}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: +var TopLinkDisclosureMenu=function(){"use strict";var R=Object.defineProperty;var U=(p,m,g)=>m in p?R(p,m,{enumerable:!0,configurable:!0,writable:!0,value:g}):p[m]=g;var o=(p,m,g)=>U(p,typeof m!="symbol"?m+"":m,g);function p(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function m(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function g(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function u(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function C(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function _(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],C(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function q(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function K(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function $(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function x(n,e){if(u("string",{tagName:n}).status&&g(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class j{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){o(this,"_dom",{toggle:null,parent:null});o(this,"_elements",{controlledMenu:null,parentMenu:null});o(this,"_open",!1);o(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));o(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){u("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(p(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{m(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{p(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{m(i,this.elements.controlledMenu.dom.menu)},r)})})})):(p(s,this.elements.controlledMenu.dom.menu),m(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(p(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{m(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{p(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{m(i,this.elements.controlledMenu.dom.menu)},r)})})})):(p(t,this.elements.controlledMenu.dom.menu),m(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:l=null}){o(this,"_dom",{item:null,link:null});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});o(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=r,this._elements.toggle=l,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function M(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function c(n){n.preventDefault(),n.stopPropagation()}class E{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:r="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:f=null,openClass:d="show",closeClass:y="hide",transitionClass:b="transitioning",transitionDuration:T=250,openDuration:a=-1,closeDuration:w=-1,isTopLevel:D=!0,parentMenu:S=null,hoverType:k="off",hoverDelay:L=250,enterDelay:I=-1,leaveDelay:A=-1,prefix:O="am-"}){o(this,"_MenuType",E);o(this,"_MenuItemType",F);o(this,"_MenuToggleType",j);o(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});o(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});o(this,"_openClass","show");o(this,"_closeClass","hide");o(this,"_transitionClass","transitioning");o(this,"_transitionDuration",250);o(this,"_openDuration",-1);o(this,"_closeDuration",-1);o(this,"_root",!0);o(this,"_currentChild",0);o(this,"_focusState","none");o(this,"_currentEvent","none");o(this,"_hoverType","off");o(this,"_hoverDelay",250);o(this,"_enterDelay",-1);o(this,"_leaveDelay",-1);o(this,"_prefix","am-");o(this,"_hoverTimeout",null);o(this,"_hasOpened",!1);o(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=f,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=r,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=S,this._elements.rootMenu=D?this:null,this._openClass=d||"",this._closeClass=y||"",this._transitionClass=b||"",this._transitionDuration=T,this._openDuration=a,this._closeDuration=w,this._prefix=O||"",this._root=D,this._hoverType=k,this._hoverDelay=L,this._enterDelay=I,this._leaveDelay=A}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: - ${this.errors.join(` - - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});$("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){_({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){_({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){_({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){u("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){u("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){u("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){u("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let o=0,l=!1;for(;!l&&o=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){q({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){K({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){O({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){u("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){u("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){u("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set hasOpened(e){u("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=g(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=g(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=T({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=T({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const a=_({openClass:this._openClass});a.status||(this._errors.push(a.error.message),e=!1)}if(this._closeClass!==""){const a=_({closeClass:this._closeClass});a.status||(this._errors.push(a.error.message),e=!1)}if(this._transitionClass!==""){const a=_({transitionClass:this._transitionClass});a.status||(this._errors.push(a.error.message),e=!1)}const i=u("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const o=u("number",{openDuration:this._openDuration});o.status||(this._errors.push(o.error.message),e=!1);const l=u("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=u("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const a=g(M,{parentMenu:this._elements.parentMenu});a.status||(this._errors.push(a.error.message),e=!1)}const d=O({hoverType:this._hoverType});d.status||(this._errors.push(d.error.message),e=!1);const f=u("number",{hoverDelay:this._hoverDelay});f.status||(this._errors.push(f.error.message),e=!1);const y=u("number",{enterDelay:this._enterDelay});y.status||(this._errors.push(y.error.message),e=!1);const b=u("number",{leaveDelay:this._leaveDelay});return b.status||(this._errors.push(b.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&g(HTMLElement,{base:t});const o=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=o:this._dom[e]=[...this._dom[e],...o]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),o=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:o,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:o,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){u("function",{callback:e}),u("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){c(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=C(e);(t==="Space"||t==="Enter")&&c(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=C(e);(t==="Space"||t==="Enter")&&(c(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty("--am-transition-duration",`${this.transitionDuration}ms`),this.dom.menu.style.setProperty("--am-open-transition-duration",`${this.openDuration}ms`),this.dom.menu.style.setProperty("--am-close-transition-duration",`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class V extends F{constructor({menuItemElement:t,menuLinkElement:s,parentMenu:i,isSubmenuItem:o=!1,childMenu:l=null,toggle:h=null,initialize:d=!0,submenuSibling:f=null}){super({menuItemElement:t,menuLinkElement:s,parentMenu:i,isSubmenuItem:o,childMenu:l,toggle:h});r(this,"_elements",{parentMenu:null,childMenu:null,toggle:null,sibling:null});this._elements.parentMenu=i,this._elements.childMenu=l,this._elements.toggle=h,this._elements.sibling=f,d&&this.initialize()}}class x extends j{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:o=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),o&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),$("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class D extends M{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:o="li:has(ul)",submenuToggleSelector:l="button",submenuSelector:h="ul",submenuSubtoggleSelector:d="a",controllerElement:f=null,containerElement:y=null,openClass:b="show",closeClass:a="hide",transitionClass:v="transitioning",transitionDuration:w=250,isTopLevel:E=!0,parentMenu:S=null,hoverType:k="off",hoverDelay:L=250,enterDelay:I=-1,leaveDelay:A=-1,optionalKeySupport:z=!1,initialize:H=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:o,submenuSelector:h,submenuToggleSelector:l,controllerElement:f,containerElement:y,openClass:b,closeClass:a,transitionClass:v,transitionDuration:w,isTopLevel:E,parentMenu:S,hoverType:k,hoverDelay:L,enterDelay:I,leaveDelay:A});r(this,"_MenuType",D);r(this,"_MenuItemType",V);r(this,"_MenuToggleType",x);r(this,"_currentChild",-1);r(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:"",submenuSubtoggles:""});r(this,"_optionalSupport",!1);this._optionalSupport=z,this._selectors.menuItems=s,this._selectors.submenuItems=o,this._selectors.submenuToggles=l,this._selectors.submenus=h,this._selectors.submenuSubtoggles=d,this._selectors.menuLinks=[...new Set([i,l])].join(","),H&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){u("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_createChildElements(){this.dom.menuItems.forEach(t=>{let s,i;const o=t.querySelector(this.selectors.menuLinks);if(this.dom.submenuItems.includes(t)){const l=t.querySelector(this.selectors.submenuToggles),h=t.querySelector(this.selectors.submenus),d=new this._MenuType({menuElement:h,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuSubtoggles,submenuSelector:this.selectors.submenus,submenuSubtoggleSelector:this.selectors.submenuSubtoggles,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),f=new this._MenuToggleType({menuToggleElement:l,parentElement:t,controlledMenu:d,parentMenu:this});this._elements.submenuToggles.push(f),l!==o?(i=new this._MenuItemType({menuItemElement:t,menuLinkElement:l,parentMenu:this,isSubmenuItem:!0,childMenu:d,toggle:f}),s=new this._MenuItemType({menuItemElement:t,menuLinkElement:o,parentMenu:this,submenuSibling:i})):s=new this._MenuItemType({menuItemElement:t,menuLinkElement:o,parentMenu:this,isSubmenuItem:!0,childMenu:d,toggle:f})}else s=new this._MenuItemType({menuItemElement:t,menuLinkElement:o,parentMenu:this});this._elements.menuItems.push(s),typeof i<"u"&&this._elements.menuItems.push(i)})}_validate(){let t=super._validate();const s=T({submenuSubtoggleSelector:this._selectors.submenuSubtoggles});s.status||(this._errors.push(s.error.message),t=!1);const i=u("boolean",{optionalKeySupport:this._optionalSupport});return i.status||(this._errors.push(i.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",i=>{if(!(i.pointerType==="pen"||i.pointerType==="touch")){if(this.hoverType==="on"){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s);let o=t.isSubmenuItem?t.elements.toggle:null;if(t.elements.sibling!==null&&(o=t.elements.sibling.elements.toggle),o===null)return;this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{o.preview()},this.enterDelay)):o.preview()}else if(this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),!this.isTopLevel||this.hasOpened)){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild();let o=t.isSubmenuItem?t.elements.toggle:null;t.elements.sibling!==null&&(o=t.elements.sibling.elements.toggle),o!==null?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{o.preview()},this.enterDelay)):o.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren()}}}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",t.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",t.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=C(t);if(this.focusState==="self"){const i=["Space","Enter"],o=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&c(t):(this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&o.includes(s)||this.elements.parentMenu&&l.includes(s))&&c(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=C(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(c(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(o=>o.isOpen)?(c(t),this.closeChildren()):this.elements.parentMenu?(c(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(c(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(c(t),this.focusPreviousChild()):s==="Home"?(c(t),this.focusFirstChild()):s==="End"&&(c(t),this.focusLastChild())))})}}return D}(); + - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});x("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get prefix(){return this._root?this._prefix:this.elements.rootMenu.prefix}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){_({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){_({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){_({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){u("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){u("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){u("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){u("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let r=0,l=!1;for(;!l&&r=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){q({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){K({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){$({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){u("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){u("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){u("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set prefix(e){u("string",{value:e}),this._prefix!==e&&(this._prefix=e)}set hasOpened(e){u("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=g(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=g(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=C({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=C({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const a=_({openClass:this._openClass});a.status||(this._errors.push(a.error.message),e=!1)}if(this._closeClass!==""){const a=_({closeClass:this._closeClass});a.status||(this._errors.push(a.error.message),e=!1)}if(this._transitionClass!==""){const a=_({transitionClass:this._transitionClass});a.status||(this._errors.push(a.error.message),e=!1)}const i=u("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const r=u("number",{openDuration:this._openDuration});r.status||(this._errors.push(r.error.message),e=!1);const l=u("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=u("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const a=g(E,{parentMenu:this._elements.parentMenu});a.status||(this._errors.push(a.error.message),e=!1)}const f=$({hoverType:this._hoverType});f.status||(this._errors.push(f.error.message),e=!1);const d=u("number",{hoverDelay:this._hoverDelay});d.status||(this._errors.push(d.error.message),e=!1);const y=u("number",{enterDelay:this._enterDelay});y.status||(this._errors.push(y.error.message),e=!1);const b=u("number",{leaveDelay:this._leaveDelay});b.status||(this._errors.push(b.error.message),e=!1);const T=u("string",{prefix:this._prefix});return T.status||(this._errors.push(T.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&g(HTMLElement,{base:t});const r=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=r:this._dom[e]=[...this._dom[e],...r]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),r=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:r,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:r,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){u("function",{callback:e}),u("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){c(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&c(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&(c(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty(`--${this.prefix}transition-duration`,`${this.transitionDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}open-transition-duration`,`${this.openDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}close-transition-duration`,`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class V extends F{constructor({menuItemElement:t,menuLinkElement:s,parentMenu:i,isSubmenuItem:r=!1,childMenu:l=null,toggle:h=null,initialize:f=!0,submenuSibling:d=null}){super({menuItemElement:t,menuLinkElement:s,parentMenu:i,isSubmenuItem:r,childMenu:l,toggle:h});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null,sibling:null});this._elements.parentMenu=i,this._elements.childMenu=l,this._elements.toggle=h,this._elements.sibling=d,f&&this.initialize()}}class z extends j{constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:r=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),r&&this.initialize()}_setAriaAttributes(){super._setAriaAttributes(),x("button",{toggle:this.dom.toggle})||this.dom.toggle.setAttribute("role","button"),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id)}open(){this.closeSiblings(),super.open()}preview(){this.closeSiblings(),super.preview()}close(){this.isOpen&&this.closeChildren(),super.close()}}class v extends E{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:r="li:has(ul)",submenuToggleSelector:l="button",submenuSelector:h="ul",submenuSubtoggleSelector:f="a",controllerElement:d=null,containerElement:y=null,openClass:b="show",closeClass:T="hide",transitionClass:a="transitioning",transitionDuration:w=250,isTopLevel:D=!0,parentMenu:S=null,hoverType:k="off",hoverDelay:L=250,enterDelay:I=-1,leaveDelay:A=-1,optionalKeySupport:O=!1,prefix:H="am-",initialize:P=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:r,submenuSelector:h,submenuToggleSelector:l,controllerElement:d,containerElement:y,openClass:b,closeClass:T,transitionClass:a,transitionDuration:w,isTopLevel:D,parentMenu:S,hoverType:k,hoverDelay:L,enterDelay:I,leaveDelay:A,prefix:H});o(this,"_MenuType",v);o(this,"_MenuItemType",V);o(this,"_MenuToggleType",z);o(this,"_currentChild",-1);o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:"",submenuSubtoggles:""});o(this,"_optionalSupport",!1);this._optionalSupport=O,this._selectors.menuItems=s,this._selectors.submenuItems=r,this._selectors.submenuToggles=l,this._selectors.submenus=h,this._selectors.submenuSubtoggles=f,this._selectors.menuLinks=[...new Set([i,l])].join(","),P&&this.initialize()}initialize(){try{super.initialize(),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup()}catch(t){console.error(t)}}get optionalKeySupport(){return this.isTopLevel?this._optionalSupport:this.elements.rootMenu.optionalKeySupport}set optionalKeySupport(t){u("boolean",{optionalKeySupport:t}),this._optionalSupport=t}_createChildElements(){this.dom.menuItems.forEach(t=>{let s,i;const r=t.querySelector(this.selectors.menuLinks);if(this.dom.submenuItems.includes(t)){const l=t.querySelector(this.selectors.submenuToggles),h=t.querySelector(this.selectors.submenus),f=new this._MenuType({menuElement:h,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuSubtoggles,submenuSelector:this.selectors.submenus,submenuSubtoggleSelector:this.selectors.submenuSubtoggles,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),d=new this._MenuToggleType({menuToggleElement:l,parentElement:t,controlledMenu:f,parentMenu:this});this._elements.submenuToggles.push(d),l!==r?(i=new this._MenuItemType({menuItemElement:t,menuLinkElement:l,parentMenu:this,isSubmenuItem:!0,childMenu:f,toggle:d}),s=new this._MenuItemType({menuItemElement:t,menuLinkElement:r,parentMenu:this,submenuSibling:i})):s=new this._MenuItemType({menuItemElement:t,menuLinkElement:r,parentMenu:this,isSubmenuItem:!0,childMenu:f,toggle:d})}else s=new this._MenuItemType({menuItemElement:t,menuLinkElement:r,parentMenu:this});this._elements.menuItems.push(s),typeof i<"u"&&this._elements.menuItems.push(i)})}_validate(){let t=super._validate();const s=C({submenuSubtoggleSelector:this._selectors.submenuSubtoggles});s.status||(this._errors.push(s.error.message),t=!1);const i=u("boolean",{optionalKeySupport:this._optionalSupport});return i.status||(this._errors.push(i.error.message),t=!1),t}_handleClick(){super._handleClick(),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.closeChildren(),this.blur(),this.elements.controller&&this.elements.controller.close(),this.elements.rootMenu.hasOpened=!1))})}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",i=>{if(!(i.pointerType==="pen"||i.pointerType==="touch")){if(this.hoverType==="on"){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s);let r=t.isSubmenuItem?t.elements.toggle:null;if(t.elements.sibling!==null&&(r=t.elements.sibling.elements.toggle),r===null)return;this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{r.preview()},this.enterDelay)):r.preview()}else if(this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),!this.isTopLevel||this.hasOpened)){this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild();let r=t.isSubmenuItem?t.elements.toggle:null;t.elements.sibling!==null&&(r=t.elements.sibling.elements.toggle),r!==null?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{r.preview()},this.enterDelay)):r.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren()}}}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",t.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",t.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=M(t);if(this.focusState==="self"){const i=["Space","Enter"],r=["Escape"],l=["Escape"];this.optionalKeySupport?["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(s)&&c(t):(this.currentMenuItem.isSubmenuItem&&i.includes(s)||this.elements.controller&&r.includes(s)||this.elements.parentMenu&&l.includes(s))&&c(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=M(t);this.focusState==="self"&&(s==="Space"||s==="Enter"?this.currentMenuItem.isSubmenuItem?(c(t),this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview()):this.currentMenuItem.dom.link.click():s==="Escape"?this.elements.submenuToggles.some(r=>r.isOpen)?(c(t),this.closeChildren()):this.elements.parentMenu?(c(t),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.closeChildren(),this.elements.parentMenu.focusCurrentChild()):this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController()):this.optionalKeySupport&&(s==="ArrowDown"||s==="ArrowRight"?(c(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.currentEvent="keyboard",this.currentMenuItem.elements.childMenu.focusFirstChild()):this.focusNextChild()):s==="ArrowUp"||s==="ArrowLeft"?(c(t),this.focusPreviousChild()):s==="Home"?(c(t),this.focusFirstChild()):s==="End"&&(c(t),this.focusLastChild())))})}}return v}(); diff --git a/dist/treeview.cjs.js b/dist/treeview.cjs.js index cad57333..cd00a869 100644 --- a/dist/treeview.cjs.js +++ b/dist/treeview.cjs.js @@ -1,3 +1,3 @@ -"use strict";var F=Object.defineProperty;var j=(n,e,t)=>e in n?F(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>j(n,typeof e!="symbol"?e+"":e,t);function g(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function _(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function b(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function m(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function k(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function y(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],k(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function V(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function z(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function O(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function q(n,e){if(m("string",{tagName:n}).status&&b(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){o(this,"_dom",{toggle:null,parent:null});o(this,"_elements",{controlledMenu:null,parentMenu:null});o(this,"_open",!1);o(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));o(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){m("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(g(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{_(i,this.elements.controlledMenu.dom.menu)},r)})})})):(g(s,this.elements.controlledMenu.dom.menu),_(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(g(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{_(i,this.elements.controlledMenu.dom.menu)},r)})})})):(g(t,this.elements.controlledMenu.dom.menu),_(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class x{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:l=null}){o(this,"_dom",{item:null,link:null});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});o(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=r,this._elements.toggle=l,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function M(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function c(n){n.preventDefault(),n.stopPropagation()}class T{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:r="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:a=null,openClass:p="show",closeClass:d="hide",transitionClass:f="transitioning",transitionDuration:u=250,openDuration:E=-1,closeDuration:v=-1,isTopLevel:C=!0,parentMenu:D=null,hoverType:w="off",hoverDelay:I=250,enterDelay:L=-1,leaveDelay:S=-1}){o(this,"_MenuType",T);o(this,"_MenuItemType",x);o(this,"_MenuToggleType",$);o(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});o(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});o(this,"_openClass","show");o(this,"_closeClass","hide");o(this,"_transitionClass","transitioning");o(this,"_transitionDuration",250);o(this,"_openDuration",-1);o(this,"_closeDuration",-1);o(this,"_root",!0);o(this,"_currentChild",0);o(this,"_focusState","none");o(this,"_currentEvent","none");o(this,"_hoverType","off");o(this,"_hoverDelay",250);o(this,"_enterDelay",-1);o(this,"_leaveDelay",-1);o(this,"_hoverTimeout",null);o(this,"_hasOpened",!1);o(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=a,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=r,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=D,this._elements.rootMenu=C?this:null,this._openClass=p||"",this._closeClass=d||"",this._transitionClass=f||"",this._transitionDuration=u,this._openDuration=E,this._closeDuration=v,this._root=C,this._hoverType=w,this._hoverDelay=I,this._enterDelay=L,this._leaveDelay=S}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: +"use strict";var j=Object.defineProperty;var V=(n,e,t)=>e in n?j(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var r=(n,e,t)=>V(n,typeof e!="symbol"?e+"":e,t);function _(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function y(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function C(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function u(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function A(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function b(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],A(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function z(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function q(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function O(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function H(n,e){if(u("string",{tagName:n}).status&&C(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){r(this,"_dom",{toggle:null,parent:null});r(this,"_elements",{controlledMenu:null,parentMenu:null});r(this,"_open",!1);r(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));r(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){u("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(_(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{y(i,this.elements.controlledMenu.dom.menu)},o)})})})):(_(s,this.elements.controlledMenu.dom.menu),y(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(_(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{y(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{y(i,this.elements.controlledMenu.dom.menu)},o)})})})):(_(t,this.elements.controlledMenu.dom.menu),y(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:o=null,toggle:l=null}){r(this,"_dom",{item:null,link:null});r(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});r(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=o,this._elements.toggle=l,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function T(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function c(n){n.preventDefault(),n.stopPropagation()}class E{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:o="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:m=null,openClass:g="show",closeClass:d="hide",transitionClass:f="transitioning",transitionDuration:p=250,openDuration:a=-1,closeDuration:v=-1,isTopLevel:M=!0,parentMenu:D=null,hoverType:w="off",hoverDelay:I=250,enterDelay:L=-1,leaveDelay:S=-1,prefix:k="am-"}){r(this,"_MenuType",E);r(this,"_MenuItemType",F);r(this,"_MenuToggleType",$);r(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});r(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});r(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});r(this,"_openClass","show");r(this,"_closeClass","hide");r(this,"_transitionClass","transitioning");r(this,"_transitionDuration",250);r(this,"_openDuration",-1);r(this,"_closeDuration",-1);r(this,"_root",!0);r(this,"_currentChild",0);r(this,"_focusState","none");r(this,"_currentEvent","none");r(this,"_hoverType","off");r(this,"_hoverDelay",250);r(this,"_enterDelay",-1);r(this,"_leaveDelay",-1);r(this,"_prefix","am-");r(this,"_hoverTimeout",null);r(this,"_hasOpened",!1);r(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=m,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=o,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=D,this._elements.rootMenu=M?this:null,this._openClass=g||"",this._closeClass=d||"",this._transitionClass=f||"",this._transitionDuration=p,this._openDuration=a,this._closeDuration=v,this._prefix=k||"",this._root=M,this._hoverType=w,this._hoverDelay=I,this._enterDelay=L,this._leaveDelay=S}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: - ${this.errors.join(` - - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});q("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){y({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){y({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){y({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){m("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){m("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){m("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){m("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let r=0,l=!1;for(;!l&&r=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){V({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){z({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){O({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){m("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){m("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){m("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set hasOpened(e){m("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=b(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=b(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=k({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=k({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const u=y({openClass:this._openClass});u.status||(this._errors.push(u.error.message),e=!1)}if(this._closeClass!==""){const u=y({closeClass:this._closeClass});u.status||(this._errors.push(u.error.message),e=!1)}if(this._transitionClass!==""){const u=y({transitionClass:this._transitionClass});u.status||(this._errors.push(u.error.message),e=!1)}const i=m("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const r=m("number",{openDuration:this._openDuration});r.status||(this._errors.push(r.error.message),e=!1);const l=m("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=m("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const u=b(T,{parentMenu:this._elements.parentMenu});u.status||(this._errors.push(u.error.message),e=!1)}const a=O({hoverType:this._hoverType});a.status||(this._errors.push(a.error.message),e=!1);const p=m("number",{hoverDelay:this._hoverDelay});p.status||(this._errors.push(p.error.message),e=!1);const d=m("number",{enterDelay:this._enterDelay});d.status||(this._errors.push(d.error.message),e=!1);const f=m("number",{leaveDelay:this._leaveDelay});return f.status||(this._errors.push(f.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&b(HTMLElement,{base:t});const r=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=r:this._dom[e]=[...this._dom[e],...r]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),r=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:r,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:r,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){m("function",{callback:e}),m("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){c(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&c(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&(c(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty("--am-transition-duration",`${this.transitionDuration}ms`),this.dom.menu.style.setProperty("--am-open-transition-duration",`${this.openDuration}ms`),this.dom.menu.style.setProperty("--am-close-transition-duration",`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class H extends x{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:r,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","treeitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.dom.link.tabIndex=0}blur(){super.blur(),this.dom.link.tabIndex=-1}}class K extends ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:r=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),r&&this.initialize()}initialize(){this._setIds(),this._setAriaAttributes(),this.dom.toggle.getAttribute("aria-expanded")==="true"?this.open():this._collapse(!1)}_setAriaAttributes(){this.dom.toggle.getAttribute("aria-expanded")!=="true"&&this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id),this.dom.toggle.setAttribute("aria-owns",this.elements.controlledMenu.dom.menu.id)}}class A extends T{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:r="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:a=null,containerElement:p=null,openClass:d="show",closeClass:f="hide",transitionClass:u="transitioning",transitionDuration:E=250,isTopLevel:v=!0,parentMenu:C=null,hoverType:D="off",hoverDelay:w=250,enterDelay:I=-1,leaveDelay:L=-1,initialize:S=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:r,submenuToggleSelector:l,submenuSelector:h,controllerElement:a,containerElement:p,openClass:d,closeClass:f,transitionClass:u,transitionDuration:E,isTopLevel:v,parentMenu:C,hoverType:D,hoverDelay:w,enterDelay:I,leaveDelay:L});o(this,"_MenuType",A);o(this,"_MenuItemType",H);o(this,"_MenuToggleType",K);S&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?(this.dom.menu.setAttribute("role","tree"),this.elements.menuItems[0].dom.link.tabIndex=0):this.dom.menu.setAttribute("role","group"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-owns")}catch(t){console.error(t)}}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s),t.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),t.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview():this.enterDelay>0&&this._clearTimeout())))}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0&&this._clearTimeout():this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()})),this.isTopLevel&&this.dom.menu.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||this.hoverType==="on"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren(),this.blur()},this.leaveDelay)):(this.closeChildren(),this.blur()))})})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=M(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?this.elements.rootMenu.blur():this.elements.rootMenu.focus()),this.focusState==="self"){const i=["Space","ArrowUp","ArrowDown","ArrowLeft","Asterisk","Home","End"],r=["Enter","ArrowRight"],l=["Escape"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&r.includes(s)||this.elements.controller&&l.includes(s))&&c(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=M(t),{altKey:i,crtlKey:r,metaKey:l}=t;if(s==="Character"&&!(i||r||l))c(t),this.elements.rootMenu.currentEvent="character",this.focusNextNodeWithCharacter(t.key);else if(this.focusState==="self")if(s==="Enter"||s==="Space")c(t),this.currentMenuItem.isSubmenuItem?this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview():this.currentMenuItem.dom.link.click();else if(s==="Escape")this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController());else if(s==="ArrowDown")c(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):!this.isTopLevel&&this.currentChild===this.elements.menuItems.length-1?this.focusParentsNextChild():this.focusNextChild();else if(s==="ArrowUp"){c(t);const a=this.elements.menuItems[this.currentChild-1];a&&a.isSubmenuItem&&a.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentChild=this.currentChild-1,this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.focusChildsLastNode()):!this.isTopLevel&&this.currentChild===0?(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild()):this.focusPreviousChild()}else s==="ArrowRight"?this.currentMenuItem.isSubmenuItem&&(c(t),this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):this.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?(c(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.blurCurrentChild(),this.currentMenuItem.elements.toggle.close()):this.isTopLevel||(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild())):s==="Home"?(c(t),this.blurCurrentChild(),this.elements.rootMenu.focusFirstChild()):s==="End"?(c(t),this.blurCurrentChild(),this.elements.rootMenu.focusLastNode()):s==="Asterisk"&&(c(t),this.openChildren())})}focusLastNode(){const t=this.elements.menuItems.length-1,s=this.elements.menuItems[t];s.isSubmenuItem&&s.elements.toggle.isOpen?(this.currentChild=t,s.elements.childMenu.currentEvent=this.currentEvent,s.elements.childMenu.focusLastNode()):this.focusLastChild()}openChildren(){this.elements.submenuToggles.forEach(t=>t.preview())}focusNextNodeWithCharacter(t){function s(d){let f=[];return d.elements.menuItems.forEach(u=>{f.push(u),u.isSubmenuItem&&u.elements.toggle.isOpen&&(f=[...f,...s(u.elements.toggle.elements.controlledMenu)])}),f}const i=t.toLowerCase(),r=s(this.elements.rootMenu),l=r.indexOf(this.currentMenuItem)+1,h=[...r.slice(l),...r.slice(0,l)];let a=0,p=!1;for(;!p&&a=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){z({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){q({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){O({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){u("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){u("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){u("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set prefix(e){u("string",{value:e}),this._prefix!==e&&(this._prefix=e)}set hasOpened(e){u("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=C(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=C(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=A({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=A({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const a=b({openClass:this._openClass});a.status||(this._errors.push(a.error.message),e=!1)}if(this._closeClass!==""){const a=b({closeClass:this._closeClass});a.status||(this._errors.push(a.error.message),e=!1)}if(this._transitionClass!==""){const a=b({transitionClass:this._transitionClass});a.status||(this._errors.push(a.error.message),e=!1)}const i=u("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const o=u("number",{openDuration:this._openDuration});o.status||(this._errors.push(o.error.message),e=!1);const l=u("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=u("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const a=C(E,{parentMenu:this._elements.parentMenu});a.status||(this._errors.push(a.error.message),e=!1)}const m=O({hoverType:this._hoverType});m.status||(this._errors.push(m.error.message),e=!1);const g=u("number",{hoverDelay:this._hoverDelay});g.status||(this._errors.push(g.error.message),e=!1);const d=u("number",{enterDelay:this._enterDelay});d.status||(this._errors.push(d.error.message),e=!1);const f=u("number",{leaveDelay:this._leaveDelay});f.status||(this._errors.push(f.error.message),e=!1);const p=u("string",{prefix:this._prefix});return p.status||(this._errors.push(p.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&C(HTMLElement,{base:t});const o=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=o:this._dom[e]=[...this._dom[e],...o]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),o=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:o,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:o,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){u("function",{callback:e}),u("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){c(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=T(e);(t==="Space"||t==="Enter")&&c(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=T(e);(t==="Space"||t==="Enter")&&(c(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty(`--${this.prefix}transition-duration`,`${this.transitionDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}open-transition-duration`,`${this.openDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}close-transition-duration`,`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class K extends F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:o=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:o,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","treeitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.dom.link.tabIndex=0}blur(){super.blur(),this.dom.link.tabIndex=-1}}class P extends ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:o=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),o&&this.initialize()}initialize(){this._setIds(),this._setAriaAttributes(),this.dom.toggle.getAttribute("aria-expanded")==="true"?this.open():this._collapse(!1)}_setAriaAttributes(){this.dom.toggle.getAttribute("aria-expanded")!=="true"&&this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id),this.dom.toggle.setAttribute("aria-owns",this.elements.controlledMenu.dom.menu.id)}}class x extends E{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:o="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:m=null,containerElement:g=null,openClass:d="show",closeClass:f="hide",transitionClass:p="transitioning",transitionDuration:a=250,isTopLevel:v=!0,parentMenu:M=null,hoverType:D="off",hoverDelay:w=250,enterDelay:I=-1,leaveDelay:L=-1,prefix:S="am-",initialize:k=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:o,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:g,openClass:d,closeClass:f,transitionClass:p,transitionDuration:a,isTopLevel:v,parentMenu:M,hoverType:D,hoverDelay:w,enterDelay:I,leaveDelay:L,prefix:S});r(this,"_MenuType",x);r(this,"_MenuItemType",K);r(this,"_MenuToggleType",P);k&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?(this.dom.menu.setAttribute("role","tree"),this.elements.menuItems[0].dom.link.tabIndex=0):this.dom.menu.setAttribute("role","group"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-owns")}catch(t){console.error(t)}}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s),t.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),t.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview():this.enterDelay>0&&this._clearTimeout())))}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0&&this._clearTimeout():this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()})),this.isTopLevel&&this.dom.menu.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||this.hoverType==="on"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren(),this.blur()},this.leaveDelay)):(this.closeChildren(),this.blur()))})})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=T(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?this.elements.rootMenu.blur():this.elements.rootMenu.focus()),this.focusState==="self"){const i=["Space","ArrowUp","ArrowDown","ArrowLeft","Asterisk","Home","End"],o=["Enter","ArrowRight"],l=["Escape"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&o.includes(s)||this.elements.controller&&l.includes(s))&&c(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=T(t),{altKey:i,crtlKey:o,metaKey:l}=t;if(s==="Character"&&!(i||o||l))c(t),this.elements.rootMenu.currentEvent="character",this.focusNextNodeWithCharacter(t.key);else if(this.focusState==="self")if(s==="Enter"||s==="Space")c(t),this.currentMenuItem.isSubmenuItem?this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview():this.currentMenuItem.dom.link.click();else if(s==="Escape")this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController());else if(s==="ArrowDown")c(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):!this.isTopLevel&&this.currentChild===this.elements.menuItems.length-1?this.focusParentsNextChild():this.focusNextChild();else if(s==="ArrowUp"){c(t);const m=this.elements.menuItems[this.currentChild-1];m&&m.isSubmenuItem&&m.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentChild=this.currentChild-1,this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.focusChildsLastNode()):!this.isTopLevel&&this.currentChild===0?(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild()):this.focusPreviousChild()}else s==="ArrowRight"?this.currentMenuItem.isSubmenuItem&&(c(t),this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):this.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?(c(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.blurCurrentChild(),this.currentMenuItem.elements.toggle.close()):this.isTopLevel||(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild())):s==="Home"?(c(t),this.blurCurrentChild(),this.elements.rootMenu.focusFirstChild()):s==="End"?(c(t),this.blurCurrentChild(),this.elements.rootMenu.focusLastNode()):s==="Asterisk"&&(c(t),this.openChildren())})}focusLastNode(){const t=this.elements.menuItems.length-1,s=this.elements.menuItems[t];s.isSubmenuItem&&s.elements.toggle.isOpen?(this.currentChild=t,s.elements.childMenu.currentEvent=this.currentEvent,s.elements.childMenu.focusLastNode()):this.focusLastChild()}openChildren(){this.elements.submenuToggles.forEach(t=>t.preview())}focusNextNodeWithCharacter(t){function s(d){let f=[];return d.elements.menuItems.forEach(p=>{f.push(p),p.isSubmenuItem&&p.elements.toggle.isOpen&&(f=[...f,...s(p.elements.toggle.elements.controlledMenu)])}),f}const i=t.toLowerCase(),o=s(this.elements.rootMenu),l=o.indexOf(this.currentMenuItem)+1,h=[...o.slice(l),...o.slice(0,l)];let m=0,g=!1;for(;!g&&m e in n ? F(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; -var o = (n, e, t) => j(n, typeof e != "symbol" ? e + "" : e, t); -function g(n, e) { +var j = Object.defineProperty; +var V = (n, e, t) => e in n ? j(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; +var r = (n, e, t) => V(n, typeof e != "symbol" ? e + "" : e, t); +function _(n, e) { n === "" || n.length === 0 || (typeof n == "string" ? e.classList.add(n) : e.classList.add(...n)); } -function _(n, e) { +function y(n, e) { n === "" || n.length === 0 || (typeof n == "string" ? e.classList.remove(n) : e.classList.remove(...n)); } -function b(n, e) { +function C(n, e) { try { if (typeof e != "object") { const t = typeof e; @@ -33,7 +33,7 @@ function b(n, e) { }; } } -function m(n, e) { +function u(n, e) { try { if (typeof e != "object") { const t = typeof e; @@ -57,7 +57,7 @@ function m(n, e) { }; } } -function k(n) { +function A(n) { try { if (typeof n != "object") { const e = typeof n; @@ -86,7 +86,7 @@ function k(n) { }; } } -function y(n) { +function b(n) { try { if (typeof n != "object" || Array.isArray(n)) { const e = typeof n; @@ -110,7 +110,7 @@ function y(n) { ); else { const s = {}; - s[e] = n[e], k(s); + s[e] = n[e], A(s); } } return { @@ -124,7 +124,7 @@ function y(n) { }; } } -function V(n) { +function z(n) { try { if (typeof n != "object") { const t = typeof n; @@ -151,7 +151,7 @@ function V(n) { }; } } -function z(n) { +function q(n) { try { if (typeof n != "object") { const t = typeof n; @@ -178,7 +178,7 @@ function z(n) { }; } } -function A(n) { +function x(n) { try { if (typeof n != "object") { const t = typeof n; @@ -205,8 +205,8 @@ function A(n) { }; } } -function q(n, e) { - if (m("string", { tagName: n }).status && b(HTMLElement, e).status) { +function H(n, e) { + if (u("string", { tagName: n }).status && C(HTMLElement, e).status) { const t = n.toLowerCase(); let s = !0; for (const i in e) @@ -241,7 +241,7 @@ class O { * @property {HTMLElement} toggle - The menu toggle. * @property {HTMLElement} parent - The menu containing this toggle. */ - o(this, "_dom", { + r(this, "_dom", { toggle: null, parent: null }); @@ -255,7 +255,7 @@ class O { * @property {BaseMenu} controlledMenu - The menu controlled by this toggle. * @property {BaseMenu} parentMenu - The menu containing this toggle. */ - o(this, "_elements", { + r(this, "_elements", { controlledMenu: null, parentMenu: null }); @@ -266,7 +266,7 @@ class O { * * @type {boolean} */ - o(this, "_open", !1); + r(this, "_open", !1); /** * The event that is triggered when the menu toggle expands. * @@ -279,7 +279,7 @@ class O { * @property {boolean} bubbles - A flag to bubble the event. * @property {Object} details - The details object containing the BaseMenuToggle itself. */ - o(this, "_expandEvent", new CustomEvent("accessibleMenuExpand", { + r(this, "_expandEvent", new CustomEvent("accessibleMenuExpand", { bubbles: !0, detail: { toggle: this } })); @@ -295,7 +295,7 @@ class O { * @property {boolean} bubbles - A flag to bubble the event. * @property {Object} details - The details object containing the BaseMenuToggle itself. */ - o(this, "_collapseEvent", new CustomEvent("accessibleMenuCollapse", { + r(this, "_collapseEvent", new CustomEvent("accessibleMenuCollapse", { bubbles: !0, detail: { toggle: this } })); @@ -348,7 +348,7 @@ class O { return this._open; } set isOpen(e) { - m("boolean", { value: e }), this._open = e; + u("boolean", { value: e }), this._open = e; } /** * Sets unique IDs for the toggle and controlled menu. @@ -404,19 +404,19 @@ class O { * @param {boolean} [emit = true] - A toggle to emit the expand event once expanded. */ _expand(e = !0) { - const { closeClass: t, openClass: s, transitionClass: i, openDuration: r } = this.elements.controlledMenu; - this.dom.toggle.setAttribute("aria-expanded", "true"), this.elements.controlledMenu.elements.rootMenu.hasOpened = !0, i !== "" ? (g(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - _(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - g(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + const { closeClass: t, openClass: s, transitionClass: i, openDuration: o } = this.elements.controlledMenu; + this.dom.toggle.setAttribute("aria-expanded", "true"), this.elements.controlledMenu.elements.rootMenu.hasOpened = !0, i !== "" ? (_(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + y(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + _(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { setTimeout(() => { - _( + y( i, this.elements.controlledMenu.dom.menu ); - }, r); + }, o); }); }); - })) : (g(s, this.elements.controlledMenu.dom.menu), _(t, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._expandEvent); + })) : (_(s, this.elements.controlledMenu.dom.menu), y(t, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._expandEvent); } /** * Collapses the controlled menu. @@ -436,19 +436,19 @@ class O { * @param {boolean} [emit = true] - A toggle to emit the collapse event once collapsed. */ _collapse(e = !0) { - const { closeClass: t, openClass: s, transitionClass: i, closeDuration: r } = this.elements.controlledMenu; - this.dom.toggle.setAttribute("aria-expanded", "false"), i !== "" ? (g(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - _(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { - g(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + const { closeClass: t, openClass: s, transitionClass: i, closeDuration: o } = this.elements.controlledMenu; + this.dom.toggle.setAttribute("aria-expanded", "false"), i !== "" ? (_(i, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + y(s, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { + _(t, this.elements.controlledMenu.dom.menu), requestAnimationFrame(() => { setTimeout(() => { - _( + y( i, this.elements.controlledMenu.dom.menu ); - }, r); + }, o); }); }); - })) : (g(t, this.elements.controlledMenu.dom.menu), _(s, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._collapseEvent); + })) : (_(t, this.elements.controlledMenu.dom.menu), y(s, this.elements.controlledMenu.dom.menu)), e && this.dom.toggle.dispatchEvent(this._collapseEvent); } /** * Opens the controlled menu. @@ -534,7 +534,7 @@ class $ { menuLinkElement: t, parentMenu: s, isSubmenuItem: i = !1, - childMenu: r = null, + childMenu: o = null, toggle: l = null }) { /** @@ -547,7 +547,7 @@ class $ { * @property {HTMLElement} item - The menu item. * @property {HTMLElement} link - The menu item's link. */ - o(this, "_dom", { + r(this, "_dom", { item: null, link: null }); @@ -562,7 +562,7 @@ class $ { * @property {?BaseMenu} childMenu - The menu contained within this menu item. * @property {?BaseMenuToggle} toggle - The menu toggle within this menu item that controls the `childMenu`. */ - o(this, "_elements", { + r(this, "_elements", { parentMenu: null, childMenu: null, toggle: null @@ -574,8 +574,8 @@ class $ { * * @type {boolean} */ - o(this, "_submenu", !1); - this._dom.item = e, this._dom.link = t, this._elements.parentMenu = s, this._elements.childMenu = r, this._elements.toggle = l, this._submenu = i; + r(this, "_submenu", !1); + this._dom.item = e, this._dom.link = t, this._elements.parentMenu = s, this._elements.childMenu = o, this._elements.toggle = l, this._submenu = i; } /** * Initialize the menu item. @@ -641,7 +641,7 @@ class $ { }); } } -function M(n) { +function T(n) { try { const e = n.key || n.keyCode, t = { Enter: e === "Enter" || e === 13, @@ -665,7 +665,7 @@ function M(n) { function c(n) { n.preventDefault(), n.stopPropagation(); } -class T { +class E { /** * Constructs a new `BaseMenu`. * @@ -681,37 +681,39 @@ class T { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). - * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in miliseconds). - * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). + * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in milliseconds). + * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = false] - A flag to mark the root menu. * @param {?BaseMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in milliseconds). + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. */ constructor({ menuElement: e, menuItemSelector: t = "li", menuLinkSelector: s = "a", submenuItemSelector: i = "li:has(ul)", - submenuToggleSelector: r = "a", + submenuToggleSelector: o = "a", submenuSelector: l = "ul", controllerElement: h = null, - containerElement: a = null, - openClass: p = "show", + containerElement: m = null, + openClass: g = "show", closeClass: d = "hide", transitionClass: f = "transitioning", - transitionDuration: u = 250, - openDuration: E = -1, + transitionDuration: p = 250, + openDuration: a = -1, closeDuration: v = -1, - isTopLevel: C = !0, + isTopLevel: M = !0, parentMenu: D = null, hoverType: w = "off", hoverDelay: I = 250, enterDelay: L = -1, - leaveDelay: S = -1 + leaveDelay: S = -1, + prefix: k = "am-" }) { /** * The class to use when generating submenus. @@ -720,7 +722,7 @@ class T { * * @type {typeof BaseMenu} */ - o(this, "_MenuType", T); + r(this, "_MenuType", E); /** * The class to use when generating menu items. * @@ -728,7 +730,7 @@ class T { * * @type {typeof BaseMenuItem} */ - o(this, "_MenuItemType", $); + r(this, "_MenuItemType", $); /** * The class to use when generating submenu toggles. * @@ -736,7 +738,7 @@ class T { * * @type {typeof BaseMenuToggle} */ - o(this, "_MenuToggleType", O); + r(this, "_MenuToggleType", O); /** * The DOM elements within the menu. * @@ -752,7 +754,7 @@ class T { * @property {HTMLElement} controller - The toggle for this menu. * @property {HTMLElement} container - The container for this menu. */ - o(this, "_dom", { + r(this, "_dom", { menu: null, menuItems: [], submenuItems: [], @@ -774,7 +776,7 @@ class T { * @property {string} submenuToggles - The query selector for menu links that function as submenu toggles. * @property {string} submenus - The query selector for for submenus. */ - o(this, "_selectors", { + r(this, "_selectors", { menuItems: "", menuLinks: "", submenuItems: "", @@ -794,7 +796,7 @@ class T { * @property {?BaseMenu} parentMenu - The parent menu. * @property {?BaseMenu} rootMenu - The root menu of the menu tree. */ - o(this, "_elements", { + r(this, "_elements", { menuItems: [], submenuToggles: [], controller: null, @@ -808,7 +810,7 @@ class T { * * @type {string|string[]} */ - o(this, "_openClass", "show"); + r(this, "_openClass", "show"); /** * The class(es) to apply when the menu is closed. * @@ -816,7 +818,7 @@ class T { * * @type {string|string[]} */ - o(this, "_closeClass", "hide"); + r(this, "_closeClass", "hide"); /** * The class(es) to apply when the menu is transitioning between states. * @@ -824,31 +826,31 @@ class T { * * @type {string|string[]} */ - o(this, "_transitionClass", "transitioning"); + r(this, "_transitionClass", "transitioning"); /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * @protected * * @type {number} */ - o(this, "_transitionDuration", 250); + r(this, "_transitionDuration", 250); /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * @protected * * @type {number} */ - o(this, "_openDuration", -1); + r(this, "_openDuration", -1); /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * @protected * * @type {number} */ - o(this, "_closeDuration", -1); + r(this, "_closeDuration", -1); /** * A flag marking the root menu. * @@ -856,7 +858,7 @@ class T { * * @type {boolean} */ - o(this, "_root", !0); + r(this, "_root", !0); /** * The index of the currently selected menu item in the menu. * @@ -864,7 +866,7 @@ class T { * * @type {number} */ - o(this, "_currentChild", 0); + r(this, "_currentChild", 0); /** * The current state of the menu's focus. * @@ -872,7 +874,7 @@ class T { * * @type {string} */ - o(this, "_focusState", "none"); + r(this, "_focusState", "none"); /** * This last event triggered on the menu. * @@ -880,7 +882,7 @@ class T { * * @type {string} */ - o(this, "_currentEvent", "none"); + r(this, "_currentEvent", "none"); /** * The type of hoverability for the menu. * @@ -888,31 +890,39 @@ class T { * * @type {string} */ - o(this, "_hoverType", "off"); + r(this, "_hoverType", "off"); /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * @protected * * @type {number} */ - o(this, "_hoverDelay", 250); + r(this, "_hoverDelay", 250); /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * @protected * * @type {number} */ - o(this, "_enterDelay", -1); + r(this, "_enterDelay", -1); /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * @protected * * @type {number} */ - o(this, "_leaveDelay", -1); + r(this, "_leaveDelay", -1); + /** + * The prefix to use for CSS custom properties. + * + * @protected + * + * @type {string} + */ + r(this, "_prefix", "am-"); /** * A variable to hold the hover timeout function. * @@ -920,7 +930,7 @@ class T { * * @type {?Function} */ - o(this, "_hoverTimeout", null); + r(this, "_hoverTimeout", null); /** * A flag to check if the menu can dynamically hover based on if a menu has been opened already. * @@ -928,7 +938,7 @@ class T { * * @type {boolean} */ - o(this, "_hasOpened", !1); + r(this, "_hasOpened", !1); /** * An array of error messages generated by the menu. * @@ -936,8 +946,8 @@ class T { * * @type {string[]} */ - o(this, "_errors", []); - this._dom.menu = e, this._dom.controller = h, this._dom.container = a, this._selectors.menuItems = t, this._selectors.menuLinks = s, this._selectors.submenuItems = i, this._selectors.submenuToggles = r, this._selectors.submenus = l, this._elements.menuItems = [], this._elements.submenuToggles = [], this._elements.controller = null, this._elements.parentMenu = D, this._elements.rootMenu = C ? this : null, this._openClass = p || "", this._closeClass = d || "", this._transitionClass = f || "", this._transitionDuration = u, this._openDuration = E, this._closeDuration = v, this._root = C, this._hoverType = w, this._hoverDelay = I, this._enterDelay = L, this._leaveDelay = S; + r(this, "_errors", []); + this._dom.menu = e, this._dom.controller = h, this._dom.container = m, this._selectors.menuItems = t, this._selectors.menuLinks = s, this._selectors.submenuItems = i, this._selectors.submenuToggles = o, this._selectors.submenus = l, this._elements.menuItems = [], this._elements.submenuToggles = [], this._elements.controller = null, this._elements.parentMenu = D, this._elements.rootMenu = M ? this : null, this._openClass = g || "", this._closeClass = d || "", this._transitionClass = f || "", this._transitionDuration = p, this._openDuration = a, this._closeDuration = v, this._prefix = k || "", this._root = M, this._hoverType = w, this._hoverDelay = I, this._enterDelay = L, this._leaveDelay = S; } /** * Initializes the menu. @@ -970,7 +980,7 @@ class T { parentElement: this.dom.container, controlledMenu: this }); - q("button", { toggle: e.dom.toggle }) || e.dom.toggle.setAttribute("role", "button"), e.dom.toggle.setAttribute("aria-controls", this.dom.menu.id), this._elements.controller = e; + H("button", { toggle: e.dom.toggle }) || e.dom.toggle.setAttribute("role", "button"), e.dom.toggle.setAttribute("aria-controls", this.dom.menu.id), this._elements.controller = e; } this._createChildElements(), this._setTransitionDurations(), this.isTopLevel && (window.AccessibleMenu = window.AccessibleMenu || { menus: {} @@ -1064,7 +1074,7 @@ class T { return this.isTopLevel ? this._transitionClass : this.elements.rootMenu.transitionClass; } /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's transition duration. @@ -1079,7 +1089,7 @@ class T { return this.isTopLevel ? this._transitionDuration : this.elements.rootMenu.transitionDuration; } /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's openDuration. @@ -1096,7 +1106,7 @@ class T { return this._openDuration === -1 ? this.transitionDuration : this.isTopLevel ? this._openDuration : this.elements.rootMenu.openDuration; } /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's closeDuration. @@ -1180,7 +1190,7 @@ class T { return this._root ? this._hoverType : this.elements.rootMenu.hoverType; } /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's hover delay. @@ -1193,7 +1203,7 @@ class T { return this._root ? this._hoverDelay : this.elements.rootMenu.hoverDelay; } /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's enter delay. @@ -1208,7 +1218,7 @@ class T { return this._enterDelay === -1 ? this.hoverDelay : this._root ? this._enterDelay : this.elements.rootMenu.enterDelay; } /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's leave delay. @@ -1222,6 +1232,19 @@ class T { get leaveDelay() { return this._leaveDelay === -1 ? this.hoverDelay : this._root ? this._leaveDelay : this.elements.rootMenu.leaveDelay; } + /** + * The prefix to use for CSS custom properties. + * + * This functions differently for root vs. submenus. + * Submenus will always inherit their root menu's prefix. + * + * @type {string} + * + * @see _prefix + */ + get prefix() { + return this._root ? this._prefix : this.elements.rootMenu.prefix; + } /** * A flag to check if the menu's focus methods should _actually_ move the focus in the DOM. * @@ -1265,60 +1288,63 @@ class T { return this._errors; } set openClass(e) { - y({ openClass: e }), this._openClass !== e && (this._openClass = e); + b({ openClass: e }), this._openClass !== e && (this._openClass = e); } set closeClass(e) { - y({ closeClass: e }), this._closeClass !== e && (this._closeClass = e); + b({ closeClass: e }), this._closeClass !== e && (this._closeClass = e); } set transitionClass(e) { - y({ transitionClass: e }), this._transitionClass !== e && (this._transitionClass = e); + b({ transitionClass: e }), this._transitionClass !== e && (this._transitionClass = e); } set transitionDuration(e) { - m("number", { value: e }), this._transitionDuration !== e && (this._transitionDuration = e, this._setTransitionDurations()); + u("number", { value: e }), this._transitionDuration !== e && (this._transitionDuration = e, this._setTransitionDurations()); } set openDuration(e) { - m("number", { value: e }), this._openDuration !== e && (this._openDuration = e, this._setTransitionDurations()); + u("number", { value: e }), this._openDuration !== e && (this._openDuration = e, this._setTransitionDurations()); } set closeDuration(e) { - m("number", { value: e }), this._closeDuration !== e && (this._closeDuration = e, this._setTransitionDurations()); + u("number", { value: e }), this._closeDuration !== e && (this._closeDuration = e, this._setTransitionDurations()); } set currentChild(e) { - m("number", { value: e }); + u("number", { value: e }); function t(s) { if (["mouse", "character"].includes(s.currentEvent) && s.elements.parentMenu) { - let r = 0, l = !1; - for (; !l && r < s.elements.parentMenu.elements.menuItems.length; ) { - const h = s.elements.parentMenu.elements.menuItems[r]; - h.isSubmenuItem && h.elements.toggle.elements.controlledMenu === s && (l = !0, s.elements.parentMenu.currentEvent = s.currentEvent, s.elements.parentMenu.currentChild = r), r++; + let o = 0, l = !1; + for (; !l && o < s.elements.parentMenu.elements.menuItems.length; ) { + const h = s.elements.parentMenu.elements.menuItems[o]; + h.isSubmenuItem && h.elements.toggle.elements.controlledMenu === s && (l = !0, s.elements.parentMenu.currentEvent = s.currentEvent, s.elements.parentMenu.currentChild = o), o++; } } } e < -1 ? (this._currentChild = -1, t(this)) : e >= this.elements.menuItems.length ? (this._currentChild = this.elements.menuItems.length - 1, t(this)) : this.focusChild !== e && (this._currentChild = e, t(this)); } set focusState(e) { - V({ value: e }), this._focusState !== e && (this._focusState = e), this.elements.submenuToggles.length > 0 && (e === "self" || e === "none") && this.elements.submenuToggles.forEach((t) => { + z({ value: e }), this._focusState !== e && (this._focusState = e), this.elements.submenuToggles.length > 0 && (e === "self" || e === "none") && this.elements.submenuToggles.forEach((t) => { t.elements.controlledMenu.focusState = "none"; }), this.elements.parentMenu && (e === "self" || e === "child") && (this.elements.parentMenu.focusState = "child"); } set currentEvent(e) { - z({ value: e }), this._currentEvent !== e && (this._currentEvent = e, this.elements.submenuToggles.length > 0 && this.elements.submenuToggles.forEach((t) => { + q({ value: e }), this._currentEvent !== e && (this._currentEvent = e, this.elements.submenuToggles.length > 0 && this.elements.submenuToggles.forEach((t) => { t.elements.controlledMenu.currentEvent = e; })); } set hoverType(e) { - A({ value: e }), this._hoverType !== e && (this._hoverType = e); + x({ value: e }), this._hoverType !== e && (this._hoverType = e); } set hoverDelay(e) { - m("number", { value: e }), this._hoverDelay !== e && (this._hoverDelay = e); + u("number", { value: e }), this._hoverDelay !== e && (this._hoverDelay = e); } set enterDelay(e) { - m("number", { value: e }), this._enterDelay !== e && (this._enterDelay = e); + u("number", { value: e }), this._enterDelay !== e && (this._enterDelay = e); } set leaveDelay(e) { - m("number", { value: e }), this._leaveDelay !== e && (this._leaveDelay = e); + u("number", { value: e }), this._leaveDelay !== e && (this._leaveDelay = e); + } + set prefix(e) { + u("string", { value: e }), this._prefix !== e && (this._prefix = e); } set hasOpened(e) { - m("boolean", { value: e }), this._hasOpened !== e && (this._hasOpened = e); + u("boolean", { value: e }), this._hasOpened !== e && (this._hasOpened = e); } /** * Validates all aspects of the menu to ensure proper functionality. @@ -1329,72 +1355,74 @@ class T { */ _validate() { let e = !0, t; - this._dom.container !== null || this._dom.controller !== null ? t = b(HTMLElement, { + this._dom.container !== null || this._dom.controller !== null ? t = C(HTMLElement, { menuElement: this._dom.menu, controllerElement: this._dom.controller, containerElement: this._dom.container - }) : t = b(HTMLElement, { + }) : t = C(HTMLElement, { menuElement: this._dom.menu }), t.status || (this._errors.push(t.error.message), e = !1); let s; - if (this._selectors.submenuItems !== "" ? s = k({ + if (this._selectors.submenuItems !== "" ? s = A({ menuItemSelector: this._selectors.menuItems, menuLinkSelector: this._selectors.menuLinks, submenuItemSelector: this._selectors.submenuItems, submenuToggleSelector: this._selectors.submenuToggles, submenuSelector: this._selectors.submenus - }) : s = k({ + }) : s = A({ menuItemSelector: this._selectors.menuItems, menuLinkSelector: this._selectors.menuLinks }), s.status || (this._errors.push(s.error.message), e = !1), this._openClass !== "") { - const u = y({ openClass: this._openClass }); - u.status || (this._errors.push(u.error.message), e = !1); + const a = b({ openClass: this._openClass }); + a.status || (this._errors.push(a.error.message), e = !1); } if (this._closeClass !== "") { - const u = y({ + const a = b({ closeClass: this._closeClass }); - u.status || (this._errors.push(u.error.message), e = !1); + a.status || (this._errors.push(a.error.message), e = !1); } if (this._transitionClass !== "") { - const u = y({ + const a = b({ transitionClass: this._transitionClass }); - u.status || (this._errors.push(u.error.message), e = !1); + a.status || (this._errors.push(a.error.message), e = !1); } - const i = m("number", { + const i = u("number", { transitionDuration: this._transitionDuration }); i.status || (this._errors.push(i.error.message), e = !1); - const r = m("number", { + const o = u("number", { openDuration: this._openDuration }); - r.status || (this._errors.push(r.error.message), e = !1); - const l = m("number", { + o.status || (this._errors.push(o.error.message), e = !1); + const l = u("number", { closeDuration: this._closeDuration }); l.status || (this._errors.push(l.error.message), e = !1); - const h = m("boolean", { isTopLevel: this._root }); + const h = u("boolean", { isTopLevel: this._root }); if (h.status || (this._errors.push(h.error.message), e = !1), this._elements.parentMenu !== null) { - const u = b(T, { + const a = C(E, { parentMenu: this._elements.parentMenu }); - u.status || (this._errors.push(u.error.message), e = !1); + a.status || (this._errors.push(a.error.message), e = !1); } - const a = A({ hoverType: this._hoverType }); - a.status || (this._errors.push(a.error.message), e = !1); - const p = m("number", { + const m = x({ hoverType: this._hoverType }); + m.status || (this._errors.push(m.error.message), e = !1); + const g = u("number", { hoverDelay: this._hoverDelay }); - p.status || (this._errors.push(p.error.message), e = !1); - const d = m("number", { + g.status || (this._errors.push(g.error.message), e = !1); + const d = u("number", { enterDelay: this._enterDelay }); d.status || (this._errors.push(d.error.message), e = !1); - const f = m("number", { + const f = u("number", { leaveDelay: this._leaveDelay }); - return f.status || (this._errors.push(f.error.message), e = !1), e; + f.status || (this._errors.push(f.error.message), e = !1); + const p = u("string", { prefix: this._prefix }); + return p.status || (this._errors.push(p.error.message), e = !1), e; } /** * Sets DOM elements within the menu. @@ -1413,15 +1441,15 @@ class T { throw new Error( `AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.` ); - t !== this.dom.menu && b(HTMLElement, { base: t }); - const r = Array.from( + t !== this.dom.menu && C(HTMLElement, { base: t }); + const o = Array.from( t.querySelectorAll(this.selectors[e]) ).filter( (l) => l.parentElement === t ); - s ? this._dom[e] = r : this._dom[e] = [ + s ? this._dom[e] = o : this._dom[e] = [ ...this._dom[e], - ...r + ...o ]; } else throw new Error( @@ -1486,7 +1514,7 @@ class T { this.dom.menuItems.forEach((e) => { let t; if (this.dom.submenuItems.includes(e)) { - const s = e.querySelector(this.selectors.submenuToggles), i = e.querySelector(this.selectors.submenus), r = new this._MenuType({ + const s = e.querySelector(this.selectors.submenuToggles), i = e.querySelector(this.selectors.submenus), o = new this._MenuType({ menuElement: i, menuItemSelector: this.selectors.menuItems, menuLinkSelector: this.selectors.menuLinks, @@ -1508,7 +1536,7 @@ class T { }), l = new this._MenuToggleType({ menuToggleElement: s, parentElement: e, - controlledMenu: r, + controlledMenu: o, parentMenu: this }); this._elements.submenuToggles.push(l), t = new this._MenuItemType({ @@ -1516,7 +1544,7 @@ class T { menuLinkElement: s, parentMenu: this, isSubmenuItem: !0, - childMenu: r, + childMenu: o, toggle: l }); } else { @@ -1547,7 +1575,7 @@ class T { * @param {number} delay - The delay time in milliseconds. */ _setTimeout(e, t) { - m("function", { callback: e }), m("number", { delay: t }), this._hoverTimeout = setTimeout(e, t); + u("function", { callback: e }), u("number", { delay: t }), this._hoverTimeout = setTimeout(e, t); } /** * Handles focus events throughout the menu for proper menu use. @@ -1688,7 +1716,7 @@ class T { "keydown", (e) => { this.currentEvent = "keyboard"; - const t = M(e); + const t = T(e); (t === "Space" || t === "Enter") && c(e); } ); @@ -1704,7 +1732,7 @@ class T { _handleKeyup() { this.isTopLevel && this.elements.controller && this.elements.controller.dom.toggle.addEventListener("keyup", (e) => { this.currentEvent = "keyboard"; - const t = M(e); + const t = T(e); (t === "Space" || t === "Enter") && (c(e), this.elements.controller.toggle(), this.elements.controller.isOpen && this.focusFirstChild()); }); } @@ -1716,17 +1744,19 @@ class T { * - `--am-open-transition-duration`, and * - `--am-close-transition-duration`. * + * The prefix of `am-` can be changed by setting the menu's prefix value. + * * @protected */ _setTransitionDurations() { this.dom.menu.style.setProperty( - "--am-transition-duration", + `--${this.prefix}transition-duration`, `${this.transitionDuration}ms` ), this.dom.menu.style.setProperty( - "--am-open-transition-duration", + `--${this.prefix}open-transition-duration`, `${this.openDuration}ms` ), this.dom.menu.style.setProperty( - "--am-close-transition-duration", + `--${this.prefix}close-transition-duration`, `${this.closeDuration}ms` ); } @@ -1847,7 +1877,7 @@ class T { }); } } -class H extends $ { +class K extends $ { /** * Constructs a new `TreeviewItem`. * @@ -1865,7 +1895,7 @@ class H extends $ { menuLinkElement: t, parentMenu: s, isSubmenuItem: i = !1, - childMenu: r = null, + childMenu: o = null, toggle: l = null, initialize: h = !0 }) { @@ -1874,7 +1904,7 @@ class H extends $ { menuLinkElement: t, parentMenu: s, isSubmenuItem: i, - childMenu: r, + childMenu: o, toggle: l }), h && this.initialize(); } @@ -1910,7 +1940,7 @@ class H extends $ { super.blur(), this.dom.link.tabIndex = -1; } } -class K extends O { +class P extends O { /** * Constructs a new `TreeviewToggle`. * @@ -1926,14 +1956,14 @@ class K extends O { parentElement: t, controlledMenu: s, parentMenu: i = null, - initialize: r = !0 + initialize: o = !0 }) { super({ menuToggleElement: e, parentElement: t, controlledMenu: s, parentMenu: i - }), r && this.initialize(); + }), o && this.initialize(); } /** * Initializes the menu toggle. @@ -1969,7 +1999,7 @@ class K extends O { ); } } -class x extends T { +class F extends E { /** * Constructs a new `Treeview`. * @@ -1985,55 +2015,58 @@ class x extends T { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?Treeview} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). + * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. */ constructor({ menuElement: t, menuItemSelector: s = "li", menuLinkSelector: i = "a", - submenuItemSelector: r = "li:has(ul)", + submenuItemSelector: o = "li:has(ul)", submenuToggleSelector: l = "a", submenuSelector: h = "ul", - controllerElement: a = null, - containerElement: p = null, + controllerElement: m = null, + containerElement: g = null, openClass: d = "show", closeClass: f = "hide", - transitionClass: u = "transitioning", - transitionDuration: E = 250, + transitionClass: p = "transitioning", + transitionDuration: a = 250, isTopLevel: v = !0, - parentMenu: C = null, + parentMenu: M = null, hoverType: D = "off", hoverDelay: w = 250, enterDelay: I = -1, leaveDelay: L = -1, - initialize: S = !0 + prefix: S = "am-", + initialize: k = !0 }) { super({ menuElement: t, menuItemSelector: s, menuLinkSelector: i, - submenuItemSelector: r, + submenuItemSelector: o, submenuToggleSelector: l, submenuSelector: h, - controllerElement: a, - containerElement: p, + controllerElement: m, + containerElement: g, openClass: d, closeClass: f, - transitionClass: u, - transitionDuration: E, + transitionClass: p, + transitionDuration: a, isTopLevel: v, - parentMenu: C, + parentMenu: M, hoverType: D, hoverDelay: w, enterDelay: I, - leaveDelay: L + leaveDelay: L, + prefix: S }); /** * The class to use when generating submenus. @@ -2042,7 +2075,7 @@ class x extends T { * * @type {typeof Treeview} */ - o(this, "_MenuType", x); + r(this, "_MenuType", F); /** * The class to use when generating menu items. * @@ -2050,7 +2083,7 @@ class x extends T { * * @type {typeof TreeviewItem} */ - o(this, "_MenuItemType", H); + r(this, "_MenuItemType", K); /** * The class to use when generating submenu toggles. * @@ -2058,8 +2091,8 @@ class x extends T { * * @type {typeof TreeviewToggle} */ - o(this, "_MenuToggleType", K); - S && this.initialize(); + r(this, "_MenuToggleType", P); + k && this.initialize(); } /** * Initializes the menu. @@ -2162,7 +2195,7 @@ class x extends T { _handleKeydown() { super._handleKeydown(), this.dom.menu.addEventListener("keydown", (t) => { this.currentEvent = "keyboard"; - const s = M(t); + const s = T(t); if (s === "Tab" && (this.elements.rootMenu.focusState !== "none" ? this.elements.rootMenu.blur() : this.elements.rootMenu.focus()), this.focusState === "self") { const i = [ "Space", @@ -2172,8 +2205,8 @@ class x extends T { "Asterisk", "Home", "End" - ], r = ["Enter", "ArrowRight"], l = ["Escape"]; - (i.includes(s) || this.currentMenuItem.isSubmenuItem && r.includes(s) || this.elements.controller && l.includes(s)) && c(t); + ], o = ["Enter", "ArrowRight"], l = ["Escape"]; + (i.includes(s) || this.currentMenuItem.isSubmenuItem && o.includes(s) || this.elements.controller && l.includes(s)) && c(t); } }); } @@ -2203,8 +2236,8 @@ class x extends T { _handleKeyup() { super._handleKeyup(), this.dom.menu.addEventListener("keyup", (t) => { this.currentEvent = "keyboard"; - const s = M(t), { altKey: i, crtlKey: r, metaKey: l } = t; - if (s === "Character" && !(i || r || l)) + const s = T(t), { altKey: i, crtlKey: o, metaKey: l } = t; + if (s === "Character" && !(i || o || l)) c(t), this.elements.rootMenu.currentEvent = "character", this.focusNextNodeWithCharacter(t.key); else if (this.focusState === "self") if (s === "Enter" || s === "Space") @@ -2215,8 +2248,8 @@ class x extends T { c(t), this.currentMenuItem.isSubmenuItem && this.currentMenuItem.elements.toggle.isOpen ? (this.blurCurrentChild(), this.currentMenuItem.elements.childMenu.currentEvent = this.currentEvent, this.currentMenuItem.elements.childMenu.focusFirstChild()) : !this.isTopLevel && this.currentChild === this.elements.menuItems.length - 1 ? this.focusParentsNextChild() : this.focusNextChild(); else if (s === "ArrowUp") { c(t); - const a = this.elements.menuItems[this.currentChild - 1]; - a && a.isSubmenuItem && a.elements.toggle.isOpen ? (this.blurCurrentChild(), this.currentChild = this.currentChild - 1, this.currentMenuItem.elements.childMenu.currentEvent = this.currentEvent, this.focusChildsLastNode()) : !this.isTopLevel && this.currentChild === 0 ? (this.blurCurrentChild(), this.elements.parentMenu.currentEvent = this.currentEvent, this.elements.parentMenu.focusCurrentChild()) : this.focusPreviousChild(); + const m = this.elements.menuItems[this.currentChild - 1]; + m && m.isSubmenuItem && m.elements.toggle.isOpen ? (this.blurCurrentChild(), this.currentChild = this.currentChild - 1, this.currentMenuItem.elements.childMenu.currentEvent = this.currentEvent, this.focusChildsLastNode()) : !this.isTopLevel && this.currentChild === 0 ? (this.blurCurrentChild(), this.elements.parentMenu.currentEvent = this.currentEvent, this.elements.parentMenu.focusCurrentChild()) : this.focusPreviousChild(); } else s === "ArrowRight" ? this.currentMenuItem.isSubmenuItem && (c(t), this.currentMenuItem.elements.toggle.isOpen ? (this.blurCurrentChild(), this.currentMenuItem.elements.childMenu.currentEvent = this.currentEvent, this.currentMenuItem.elements.childMenu.focusFirstChild()) : this.currentMenuItem.elements.toggle.preview()) : s === "ArrowLeft" ? (c(t), this.currentMenuItem.isSubmenuItem && this.currentMenuItem.elements.toggle.isOpen ? (this.currentMenuItem.elements.childMenu.blurCurrentChild(), this.currentMenuItem.elements.toggle.close()) : this.isTopLevel || (this.blurCurrentChild(), this.elements.parentMenu.currentEvent = this.currentEvent, this.elements.parentMenu.focusCurrentChild())) : s === "Home" ? (c(t), this.blurCurrentChild(), this.elements.rootMenu.focusFirstChild()) : s === "End" ? (c(t), this.blurCurrentChild(), this.elements.rootMenu.focusLastNode()) : s === "Asterisk" && (c(t), this.openChildren()); }); } @@ -2253,28 +2286,28 @@ class x extends T { focusNextNodeWithCharacter(t) { function s(d) { let f = []; - return d.elements.menuItems.forEach((u) => { - f.push(u), u.isSubmenuItem && u.elements.toggle.isOpen && (f = [ + return d.elements.menuItems.forEach((p) => { + f.push(p), p.isSubmenuItem && p.elements.toggle.isOpen && (f = [ ...f, ...s( - u.elements.toggle.elements.controlledMenu + p.elements.toggle.elements.controlledMenu ) ]); }), f; } - const i = t.toLowerCase(), r = s(this.elements.rootMenu), l = r.indexOf(this.currentMenuItem) + 1, h = [ - ...r.slice(l), - ...r.slice(0, l) + const i = t.toLowerCase(), o = s(this.elements.rootMenu), l = o.indexOf(this.currentMenuItem) + 1, h = [ + ...o.slice(l), + ...o.slice(0, l) ]; - let a = 0, p = !1; - for (; !p && a < h.length; ) { + let m = 0, g = !1; + for (; !g && m < h.length; ) { let d = ""; - if (h[a].dom.item.innerText ? d = h[a].dom.item.innerText : d = h[a].dom.item.textContent, d = d.replace(/[\s]/g, "").toLowerCase().charAt(0), d === i) { - p = !0; - const f = h[a].elements.parentMenu, u = f.elements.menuItems.indexOf(h[a]); - this.elements.rootMenu.blurChildren(), f.focusChild(u); + if (h[m].dom.item.innerText ? d = h[m].dom.item.innerText : d = h[m].dom.item.textContent, d = d.replace(/[\s]/g, "").toLowerCase().charAt(0), d === i) { + g = !0; + const f = h[m].elements.parentMenu, p = f.elements.menuItems.indexOf(h[m]); + this.elements.rootMenu.blurChildren(), f.focusChild(p); } - a++; + m++; } } /** @@ -2299,5 +2332,5 @@ class x extends T { } } export { - x as default + F as default }; diff --git a/dist/treeview.iife.js b/dist/treeview.iife.js index 9b2361c2..cc4ee5e4 100644 --- a/dist/treeview.iife.js +++ b/dist/treeview.iife.js @@ -1,3 +1,3 @@ -var Treeview=function(){"use strict";var H=Object.defineProperty;var K=(g,d,_)=>d in g?H(g,d,{enumerable:!0,configurable:!0,writable:!0,value:_}):g[d]=_;var o=(g,d,_)=>K(g,typeof d!="symbol"?d+"":d,_);function g(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function d(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function _(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function h(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function E(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function b(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],E(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function F(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function j(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function O(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function V(n,e){if(h("string",{tagName:n}).status&&_(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){o(this,"_dom",{toggle:null,parent:null});o(this,"_elements",{controlledMenu:null,parentMenu:null});o(this,"_open",!1);o(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));o(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){h("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(g(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{d(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{d(i,this.elements.controlledMenu.dom.menu)},r)})})})):(g(s,this.elements.controlledMenu.dom.menu),d(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:r}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(g(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{d(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{g(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{d(i,this.elements.controlledMenu.dom.menu)},r)})})})):(g(t,this.elements.controlledMenu.dom.menu),d(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class x{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:l=null}){o(this,"_dom",{item:null,link:null});o(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});o(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=r,this._elements.toggle=l,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function C(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function c(n){n.preventDefault(),n.stopPropagation()}class M{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:r="a",submenuSelector:l="ul",controllerElement:m=null,containerElement:a=null,openClass:y="show",closeClass:f="hide",transitionClass:p="transitioning",transitionDuration:u=250,openDuration:D=-1,closeDuration:w=-1,isTopLevel:T=!0,parentMenu:I=null,hoverType:L="off",hoverDelay:S=250,enterDelay:k=-1,leaveDelay:A=-1}){o(this,"_MenuType",M);o(this,"_MenuItemType",x);o(this,"_MenuToggleType",$);o(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});o(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});o(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});o(this,"_openClass","show");o(this,"_closeClass","hide");o(this,"_transitionClass","transitioning");o(this,"_transitionDuration",250);o(this,"_openDuration",-1);o(this,"_closeDuration",-1);o(this,"_root",!0);o(this,"_currentChild",0);o(this,"_focusState","none");o(this,"_currentEvent","none");o(this,"_hoverType","off");o(this,"_hoverDelay",250);o(this,"_enterDelay",-1);o(this,"_leaveDelay",-1);o(this,"_hoverTimeout",null);o(this,"_hasOpened",!1);o(this,"_errors",[]);this._dom.menu=e,this._dom.controller=m,this._dom.container=a,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=r,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=I,this._elements.rootMenu=T?this:null,this._openClass=y||"",this._closeClass=f||"",this._transitionClass=p||"",this._transitionDuration=u,this._openDuration=D,this._closeDuration=w,this._root=T,this._hoverType=L,this._hoverDelay=S,this._enterDelay=k,this._leaveDelay=A}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: +var Treeview=function(){"use strict";var K=Object.defineProperty;var P=(_,d,y)=>d in _?K(_,d,{enumerable:!0,configurable:!0,writable:!0,value:y}):_[d]=y;var r=(_,d,y)=>P(_,typeof d!="symbol"?d+"":d,y);function _(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.add(n):e.classList.add(...n))}function d(n,e){n===""||n.length===0||(typeof n=="string"?e.classList.remove(n):e.classList.remove(...n))}function y(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Elements given to isValidInstance() must be inside of an object. "${t}" given.`)}for(const t in e)if(!(e[t]instanceof n)){const s=typeof e[t];throw new TypeError(`${t} must be an instance of ${n.name}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function u(n,e){try{if(typeof e!="object"){const t=typeof e;throw new TypeError(`Values given to isValidType() must be inside of an object. "${t}" given.`)}for(const t in e){const s=typeof e[t];if(s!==n)throw new TypeError(`${t} must be a ${n}. "${s}" given.`)}return{status:!0,error:null}}catch(t){return{status:!1,error:t}}}function v(n){try{if(typeof n!="object"){const e=typeof n;throw new TypeError(`Values given to isQuerySelector() must be inside of an object. "${e}" given.`)}for(const e in n)try{if(n[e]===null)throw new Error;document.querySelector(n[e])}catch{throw new TypeError(`${e} must be a valid query selector. "${n[e]}" given.`)}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function C(n){try{if(typeof n!="object"||Array.isArray(n)){const e=typeof n;throw new TypeError(`Values given to isValidClassList() must be inside of an object. "${e}" given.`)}for(const e in n){const t=typeof n[e];if(t!=="string")if(Array.isArray(n[e]))n[e].forEach(s=>{if(typeof s!="string")throw new TypeError(`${e} must be a string or an array of strings. An array containing non-strings given.`)});else throw new TypeError(`${e} must be a string or an array of strings. "${t}" given.`);else{const s={};s[e]=n[e],v(s)}}return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function j(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidState() must be inside of an object. "${t}" given.`)}const e=["none","self","child"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function V(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidEvent() must be inside of an object. "${t}" given.`)}const e=["none","mouse","keyboard","character"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function x(n){try{if(typeof n!="object"){const t=typeof n;throw new TypeError(`Values given to isValidHoverType() must be inside of an object. "${t}" given.`)}const e=["off","on","dynamic"];for(const t in n)if(!e.includes(n[t]))throw new TypeError(`${t} must be one of the following values: ${e.join(", ")}. "${n[t]}" given.`);return{status:!0,error:null}}catch(e){return{status:!1,error:e}}}function z(n,e){if(u("string",{tagName:n}).status&&y(HTMLElement,e).status){const t=n.toLowerCase();let s=!0;for(const i in e)e[i].tagName.toLowerCase()!==t&&(s=!1);return s}else return!1}class ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null}){r(this,"_dom",{toggle:null,parent:null});r(this,"_elements",{controlledMenu:null,parentMenu:null});r(this,"_open",!1);r(this,"_expandEvent",new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}));r(this,"_collapseEvent",new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}));this._dom.toggle=e,this._dom.parent=t,this._elements.controlledMenu=s,this._elements.parentMenu=i}initialize(){this._setIds(),this._setAriaAttributes(),this._collapse(!1)}get dom(){return this._dom}get elements(){return this._elements}get isOpen(){return this._open}set isOpen(e){u("boolean",{value:e}),this._open=e}_setIds(){var e;if(this.dom.toggle.id===""||this.elements.controlledMenu.dom.menu.id===""){const t=Math.random().toString(36).replace(/[^a-z]+/g,"").substring(0,10);let s=((e=this.dom.toggle.innerText)==null?void 0:e.replace(/[^a-zA-Z0-9\s]/g,""))||"",i=t;!s.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(s=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),s.replace(/\s/g,"").length>0&&(s=s.toLowerCase().replace(/\s+/g,"-"),s.startsWith("-")&&(s=s.substring(1)),s.endsWith("-")&&(s=s.slice(0,-1)),i=`${s}-${i}`),this.dom.toggle.id=this.dom.toggle.id||`menu-button-${i}`,this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||`menu-${i}`}}_setAriaAttributes(){this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id)}_expand(e=!0){const{closeClass:t,openClass:s,transitionClass:i,openDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","true"),this.elements.controlledMenu.elements.rootMenu.hasOpened=!0,i!==""?(_(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{d(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{d(i,this.elements.controlledMenu.dom.menu)},o)})})})):(_(s,this.elements.controlledMenu.dom.menu),d(t,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._expandEvent)}_collapse(e=!0){const{closeClass:t,openClass:s,transitionClass:i,closeDuration:o}=this.elements.controlledMenu;this.dom.toggle.setAttribute("aria-expanded","false"),i!==""?(_(i,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{d(s,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{_(t,this.elements.controlledMenu.dom.menu),requestAnimationFrame(()=>{setTimeout(()=>{d(i,this.elements.controlledMenu.dom.menu)},o)})})})):(_(t,this.elements.controlledMenu.dom.menu),d(s,this.elements.controlledMenu.dom.menu)),e&&this.dom.toggle.dispatchEvent(this._collapseEvent)}open(){this.elements.controlledMenu.focusState="self",this.isOpen||(this._expand(),this.isOpen=!0)}preview(){this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.isOpen||(this._expand(),this.isOpen=!0)}close(){this.isOpen&&(this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this._collapse(),this.isOpen=!1)}toggle(){this.isOpen?this.close():this.open()}closeSiblings(){this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach(e=>{e!==this&&e.close()})}closeChildren(){this.elements.controlledMenu.elements.submenuToggles.forEach(e=>e.close())}}class F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:o=null,toggle:l=null}){r(this,"_dom",{item:null,link:null});r(this,"_elements",{parentMenu:null,childMenu:null,toggle:null});r(this,"_submenu",!1);this._dom.item=e,this._dom.link=t,this._elements.parentMenu=s,this._elements.childMenu=o,this._elements.toggle=l,this._submenu=i}initialize(){}get dom(){return this._dom}get elements(){return this._elements}get isSubmenuItem(){return this._submenu}focus(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.focus()})}blur(){this.elements.parentMenu.shouldFocus&&requestAnimationFrame(()=>{this.dom.link.blur()})}}function M(n){try{const e=n.key||n.keyCode,t={Enter:e==="Enter"||e===13,Space:e===" "||e==="Spacebar"||e===32,Escape:e==="Escape"||e==="Esc"||e===27,ArrowUp:e==="ArrowUp"||e==="Up"||e===38,ArrowRight:e==="ArrowRight"||e==="Right"||e===39,ArrowDown:e==="ArrowDown"||e==="Down"||e===40,ArrowLeft:e==="ArrowLeft"||e==="Left"||e===37,Home:e==="Home"||e===36,End:e==="End"||e===35,Character:isNaN(e)&&!!e.match(/^[a-zA-Z]{1}$/),Tab:e==="Tab"||e===9,Asterisk:e==="*"||e===56};return Object.keys(t).find(s=>t[s]===!0)||""}catch{return""}}function a(n){n.preventDefault(),n.stopPropagation()}class T{constructor({menuElement:e,menuItemSelector:t="li",menuLinkSelector:s="a",submenuItemSelector:i="li:has(ul)",submenuToggleSelector:o="a",submenuSelector:l="ul",controllerElement:h=null,containerElement:m=null,openClass:b="show",closeClass:f="hide",transitionClass:p="transitioning",transitionDuration:g=250,openDuration:c=-1,closeDuration:w=-1,isTopLevel:E=!0,parentMenu:I=null,hoverType:L="off",hoverDelay:S=250,enterDelay:k=-1,leaveDelay:A=-1,prefix:O="am-"}){r(this,"_MenuType",T);r(this,"_MenuItemType",F);r(this,"_MenuToggleType",$);r(this,"_dom",{menu:null,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:null,container:null});r(this,"_selectors",{menuItems:"",menuLinks:"",submenuItems:"",submenuToggles:"",submenus:""});r(this,"_elements",{menuItems:[],submenuToggles:[],controller:null,parentMenu:null,rootMenu:null});r(this,"_openClass","show");r(this,"_closeClass","hide");r(this,"_transitionClass","transitioning");r(this,"_transitionDuration",250);r(this,"_openDuration",-1);r(this,"_closeDuration",-1);r(this,"_root",!0);r(this,"_currentChild",0);r(this,"_focusState","none");r(this,"_currentEvent","none");r(this,"_hoverType","off");r(this,"_hoverDelay",250);r(this,"_enterDelay",-1);r(this,"_leaveDelay",-1);r(this,"_prefix","am-");r(this,"_hoverTimeout",null);r(this,"_hasOpened",!1);r(this,"_errors",[]);this._dom.menu=e,this._dom.controller=h,this._dom.container=m,this._selectors.menuItems=t,this._selectors.menuLinks=s,this._selectors.submenuItems=i,this._selectors.submenuToggles=o,this._selectors.submenus=l,this._elements.menuItems=[],this._elements.submenuToggles=[],this._elements.controller=null,this._elements.parentMenu=I,this._elements.rootMenu=E?this:null,this._openClass=b||"",this._closeClass=f||"",this._transitionClass=p||"",this._transitionDuration=g,this._openDuration=c,this._closeDuration=w,this._prefix=O||"",this._root=E,this._hoverType=L,this._hoverDelay=S,this._enterDelay=k,this._leaveDelay=A}initialize(){if(!this._validate())throw new Error(`AccesibleMenu: cannot initialize menu. The following errors have been found: - ${this.errors.join(` - - `)}`);if(this.elements.rootMenu===null&&this._findRootMenu(this),this._setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){const e=new this._MenuToggleType({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this});V("button",{toggle:e.dom.toggle})||e.dom.toggle.setAttribute("role","button"),e.dom.toggle.setAttribute("aria-controls",this.dom.menu.id),this._elements.controller=e}this._createChildElements(),this._setTransitionDurations(),this.isTopLevel&&(window.AccessibleMenu=window.AccessibleMenu||{menus:{}},window.AccessibleMenu.menus[this.dom.menu.id]=this)}get dom(){return this._dom}get selectors(){return this._selectors}get elements(){return this._elements}get isTopLevel(){return this._root}get openClass(){return this.isTopLevel?this._openClass:this.elements.rootMenu.openClass}get closeClass(){return this.isTopLevel?this._closeClass:this.elements.rootMenu.closeClass}get transitionClass(){return this.isTopLevel?this._transitionClass:this.elements.rootMenu.transitionClass}get transitionDuration(){return this.isTopLevel?this._transitionDuration:this.elements.rootMenu.transitionDuration}get openDuration(){return this._openDuration===-1?this.transitionDuration:this.isTopLevel?this._openDuration:this.elements.rootMenu.openDuration}get closeDuration(){return this._closeDuration===-1?this.transitionDuration:this.isTopLevel?this._closeDuration:this.elements.rootMenu.closeDuration}get currentChild(){return this._currentChild}get focusState(){return this._focusState}get currentEvent(){return this._currentEvent}get currentMenuItem(){return this.elements.menuItems[this.currentChild]}get hoverType(){return this._root?this._hoverType:this.elements.rootMenu.hoverType}get hoverDelay(){return this._root?this._hoverDelay:this.elements.rootMenu.hoverDelay}get enterDelay(){return this._enterDelay===-1?this.hoverDelay:this._root?this._enterDelay:this.elements.rootMenu.enterDelay}get leaveDelay(){return this._leaveDelay===-1?this.hoverDelay:this._root?this._leaveDelay:this.elements.rootMenu.leaveDelay}get shouldFocus(){let e=!1;return(this.currentEvent==="keyboard"||this.currentEvent==="character")&&(e=!0),this.currentEvent==="mouse"&&this.hoverType==="dynamic"&&(e=!0),e}get hasOpened(){return this._root?this._hasOpened:this.elements.rootMenu.hasOpened}get errors(){return this._errors}set openClass(e){b({openClass:e}),this._openClass!==e&&(this._openClass=e)}set closeClass(e){b({closeClass:e}),this._closeClass!==e&&(this._closeClass=e)}set transitionClass(e){b({transitionClass:e}),this._transitionClass!==e&&(this._transitionClass=e)}set transitionDuration(e){h("number",{value:e}),this._transitionDuration!==e&&(this._transitionDuration=e,this._setTransitionDurations())}set openDuration(e){h("number",{value:e}),this._openDuration!==e&&(this._openDuration=e,this._setTransitionDurations())}set closeDuration(e){h("number",{value:e}),this._closeDuration!==e&&(this._closeDuration=e,this._setTransitionDurations())}set currentChild(e){h("number",{value:e});function t(s){if(["mouse","character"].includes(s.currentEvent)&&s.elements.parentMenu){let r=0,l=!1;for(;!l&&r=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){F({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){j({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){O({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){h("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){h("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){h("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set hasOpened(e){h("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=_(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=_(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=E({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=E({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const u=b({openClass:this._openClass});u.status||(this._errors.push(u.error.message),e=!1)}if(this._closeClass!==""){const u=b({closeClass:this._closeClass});u.status||(this._errors.push(u.error.message),e=!1)}if(this._transitionClass!==""){const u=b({transitionClass:this._transitionClass});u.status||(this._errors.push(u.error.message),e=!1)}const i=h("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const r=h("number",{openDuration:this._openDuration});r.status||(this._errors.push(r.error.message),e=!1);const l=h("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const m=h("boolean",{isTopLevel:this._root});if(m.status||(this._errors.push(m.error.message),e=!1),this._elements.parentMenu!==null){const u=_(M,{parentMenu:this._elements.parentMenu});u.status||(this._errors.push(u.error.message),e=!1)}const a=O({hoverType:this._hoverType});a.status||(this._errors.push(a.error.message),e=!1);const y=h("number",{hoverDelay:this._hoverDelay});y.status||(this._errors.push(y.error.message),e=!1);const f=h("number",{enterDelay:this._enterDelay});f.status||(this._errors.push(f.error.message),e=!1);const p=h("number",{leaveDelay:this._leaveDelay});return p.status||(this._errors.push(p.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&_(HTMLElement,{base:t});const r=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=r:this._dom[e]=[...this._dom[e],...r]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),r=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:r,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:r,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){h("function",{callback:e}),h("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){c(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=C(e);(t==="Space"||t==="Enter")&&c(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=C(e);(t==="Space"||t==="Enter")&&(c(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty("--am-transition-duration",`${this.transitionDuration}ms`),this.dom.menu.style.setProperty("--am-open-transition-duration",`${this.openDuration}ms`),this.dom.menu.style.setProperty("--am-close-transition-duration",`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class z extends x{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:r=null,toggle:l=null,initialize:m=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:r,toggle:l}),m&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","treeitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.dom.link.tabIndex=0}blur(){super.blur(),this.dom.link.tabIndex=-1}}class q extends ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:r=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),r&&this.initialize()}initialize(){this._setIds(),this._setAriaAttributes(),this.dom.toggle.getAttribute("aria-expanded")==="true"?this.open():this._collapse(!1)}_setAriaAttributes(){this.dom.toggle.getAttribute("aria-expanded")!=="true"&&this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id),this.dom.toggle.setAttribute("aria-owns",this.elements.controlledMenu.dom.menu.id)}}class v extends M{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:r="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:m="ul",controllerElement:a=null,containerElement:y=null,openClass:f="show",closeClass:p="hide",transitionClass:u="transitioning",transitionDuration:D=250,isTopLevel:w=!0,parentMenu:T=null,hoverType:I="off",hoverDelay:L=250,enterDelay:S=-1,leaveDelay:k=-1,initialize:A=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:r,submenuToggleSelector:l,submenuSelector:m,controllerElement:a,containerElement:y,openClass:f,closeClass:p,transitionClass:u,transitionDuration:D,isTopLevel:w,parentMenu:T,hoverType:I,hoverDelay:L,enterDelay:S,leaveDelay:k});o(this,"_MenuType",v);o(this,"_MenuItemType",z);o(this,"_MenuToggleType",q);A&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?(this.dom.menu.setAttribute("role","tree"),this.elements.menuItems[0].dom.link.tabIndex=0):this.dom.menu.setAttribute("role","group"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-owns")}catch(t){console.error(t)}}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s),t.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),t.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview():this.enterDelay>0&&this._clearTimeout())))}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0&&this._clearTimeout():this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()})),this.isTopLevel&&this.dom.menu.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||this.hoverType==="on"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren(),this.blur()},this.leaveDelay)):(this.closeChildren(),this.blur()))})})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=C(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?this.elements.rootMenu.blur():this.elements.rootMenu.focus()),this.focusState==="self"){const i=["Space","ArrowUp","ArrowDown","ArrowLeft","Asterisk","Home","End"],r=["Enter","ArrowRight"],l=["Escape"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&r.includes(s)||this.elements.controller&&l.includes(s))&&c(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=C(t),{altKey:i,crtlKey:r,metaKey:l}=t;if(s==="Character"&&!(i||r||l))c(t),this.elements.rootMenu.currentEvent="character",this.focusNextNodeWithCharacter(t.key);else if(this.focusState==="self")if(s==="Enter"||s==="Space")c(t),this.currentMenuItem.isSubmenuItem?this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview():this.currentMenuItem.dom.link.click();else if(s==="Escape")this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController());else if(s==="ArrowDown")c(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):!this.isTopLevel&&this.currentChild===this.elements.menuItems.length-1?this.focusParentsNextChild():this.focusNextChild();else if(s==="ArrowUp"){c(t);const a=this.elements.menuItems[this.currentChild-1];a&&a.isSubmenuItem&&a.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentChild=this.currentChild-1,this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.focusChildsLastNode()):!this.isTopLevel&&this.currentChild===0?(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild()):this.focusPreviousChild()}else s==="ArrowRight"?this.currentMenuItem.isSubmenuItem&&(c(t),this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):this.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?(c(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.blurCurrentChild(),this.currentMenuItem.elements.toggle.close()):this.isTopLevel||(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild())):s==="Home"?(c(t),this.blurCurrentChild(),this.elements.rootMenu.focusFirstChild()):s==="End"?(c(t),this.blurCurrentChild(),this.elements.rootMenu.focusLastNode()):s==="Asterisk"&&(c(t),this.openChildren())})}focusLastNode(){const t=this.elements.menuItems.length-1,s=this.elements.menuItems[t];s.isSubmenuItem&&s.elements.toggle.isOpen?(this.currentChild=t,s.elements.childMenu.currentEvent=this.currentEvent,s.elements.childMenu.focusLastNode()):this.focusLastChild()}openChildren(){this.elements.submenuToggles.forEach(t=>t.preview())}focusNextNodeWithCharacter(t){function s(f){let p=[];return f.elements.menuItems.forEach(u=>{p.push(u),u.isSubmenuItem&&u.elements.toggle.isOpen&&(p=[...p,...s(u.elements.toggle.elements.controlledMenu)])}),p}const i=t.toLowerCase(),r=s(this.elements.rootMenu),l=r.indexOf(this.currentMenuItem)+1,m=[...r.slice(l),...r.slice(0,l)];let a=0,y=!1;for(;!y&&a=this.elements.menuItems.length?(this._currentChild=this.elements.menuItems.length-1,t(this)):this.focusChild!==e&&(this._currentChild=e,t(this))}set focusState(e){j({value:e}),this._focusState!==e&&(this._focusState=e),this.elements.submenuToggles.length>0&&(e==="self"||e==="none")&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.focusState="none"}),this.elements.parentMenu&&(e==="self"||e==="child")&&(this.elements.parentMenu.focusState="child")}set currentEvent(e){V({value:e}),this._currentEvent!==e&&(this._currentEvent=e,this.elements.submenuToggles.length>0&&this.elements.submenuToggles.forEach(t=>{t.elements.controlledMenu.currentEvent=e}))}set hoverType(e){x({value:e}),this._hoverType!==e&&(this._hoverType=e)}set hoverDelay(e){u("number",{value:e}),this._hoverDelay!==e&&(this._hoverDelay=e)}set enterDelay(e){u("number",{value:e}),this._enterDelay!==e&&(this._enterDelay=e)}set leaveDelay(e){u("number",{value:e}),this._leaveDelay!==e&&(this._leaveDelay=e)}set prefix(e){u("string",{value:e}),this._prefix!==e&&(this._prefix=e)}set hasOpened(e){u("boolean",{value:e}),this._hasOpened!==e&&(this._hasOpened=e)}_validate(){let e=!0,t;this._dom.container!==null||this._dom.controller!==null?t=y(HTMLElement,{menuElement:this._dom.menu,controllerElement:this._dom.controller,containerElement:this._dom.container}):t=y(HTMLElement,{menuElement:this._dom.menu}),t.status||(this._errors.push(t.error.message),e=!1);let s;if(this._selectors.submenuItems!==""?s=v({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks,submenuItemSelector:this._selectors.submenuItems,submenuToggleSelector:this._selectors.submenuToggles,submenuSelector:this._selectors.submenus}):s=v({menuItemSelector:this._selectors.menuItems,menuLinkSelector:this._selectors.menuLinks}),s.status||(this._errors.push(s.error.message),e=!1),this._openClass!==""){const c=C({openClass:this._openClass});c.status||(this._errors.push(c.error.message),e=!1)}if(this._closeClass!==""){const c=C({closeClass:this._closeClass});c.status||(this._errors.push(c.error.message),e=!1)}if(this._transitionClass!==""){const c=C({transitionClass:this._transitionClass});c.status||(this._errors.push(c.error.message),e=!1)}const i=u("number",{transitionDuration:this._transitionDuration});i.status||(this._errors.push(i.error.message),e=!1);const o=u("number",{openDuration:this._openDuration});o.status||(this._errors.push(o.error.message),e=!1);const l=u("number",{closeDuration:this._closeDuration});l.status||(this._errors.push(l.error.message),e=!1);const h=u("boolean",{isTopLevel:this._root});if(h.status||(this._errors.push(h.error.message),e=!1),this._elements.parentMenu!==null){const c=y(T,{parentMenu:this._elements.parentMenu});c.status||(this._errors.push(c.error.message),e=!1)}const m=x({hoverType:this._hoverType});m.status||(this._errors.push(m.error.message),e=!1);const b=u("number",{hoverDelay:this._hoverDelay});b.status||(this._errors.push(b.error.message),e=!1);const f=u("number",{enterDelay:this._enterDelay});f.status||(this._errors.push(f.error.message),e=!1);const p=u("number",{leaveDelay:this._leaveDelay});p.status||(this._errors.push(p.error.message),e=!1);const g=u("string",{prefix:this._prefix});return g.status||(this._errors.push(g.error.message),e=!1),e}_setDOMElementType(e,t=this.dom.menu,s=!0){if(typeof this.selectors[e]=="string"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be set through _setDOMElementType.`);t!==this.dom.menu&&y(HTMLElement,{base:t});const o=Array.from(t.querySelectorAll(this.selectors[e])).filter(l=>l.parentElement===t);s?this._dom[e]=o:this._dom[e]=[...this._dom[e],...o]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_resetDOMElementType(e){if(typeof this.dom[e]<"u"){if(!Array.isArray(this.dom[e]))throw new Error(`AccessibleMenu: The "${e}" element cannot be reset through _resetDOMElementType.`);this._dom[e]=[]}else throw new Error(`AccessibleMenu: "${e}" is not a valid element type within the menu.`)}_setDOMElements(){this._setDOMElementType("menuItems"),this.selectors.submenuItems!==""&&(this._setDOMElementType("submenuItems"),this._resetDOMElementType("submenuToggles"),this._resetDOMElementType("submenus"),this.dom.submenuItems.forEach(e=>{this._setDOMElementType("submenuToggles",e,!1),this._setDOMElementType("submenus",e,!1)}))}_findRootMenu(e){if(e.isTopLevel)this._elements.rootMenu=e;else if(e.elements.parentMenu!==null)this._findRootMenu(e.elements.parentMenu);else throw new Error("Cannot find root menu.")}_createChildElements(){this.dom.menuItems.forEach(e=>{let t;if(this.dom.submenuItems.includes(e)){const s=e.querySelector(this.selectors.submenuToggles),i=e.querySelector(this.selectors.submenus),o=new this._MenuType({menuElement:i,menuItemSelector:this.selectors.menuItems,menuLinkSelector:this.selectors.menuLinks,submenuItemSelector:this.selectors.submenuItems,submenuToggleSelector:this.selectors.submenuToggles,submenuSelector:this.selectors.submenus,openClass:this.openClass,closeClass:this.closeClass,transitionClass:this.transitionClass,transitionDuration:this.transitionDuration,openDuration:this.openDuration,closeDuration:this.closeDuration,isTopLevel:!1,parentMenu:this,hoverType:this.hoverType,hoverDelay:this.hoverDelay,enterDelay:this.enterDelay,leaveDelay:this.leaveDelay}),l=new this._MenuToggleType({menuToggleElement:s,parentElement:e,controlledMenu:o,parentMenu:this});this._elements.submenuToggles.push(l),t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this,isSubmenuItem:!0,childMenu:o,toggle:l})}else{const s=e.querySelector(this.selectors.menuLinks);t=new this._MenuItemType({menuItemElement:e,menuLinkElement:s,parentMenu:this})}this._elements.menuItems.push(t)})}_clearTimeout(){clearTimeout(this._hoverTimeout)}_setTimeout(e,t){u("function",{callback:e}),u("number",{delay:t}),this._hoverTimeout=setTimeout(e,t)}_handleFocus(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("focus",()=>{this.focusState="self",this.currentChild=t})})}_handleClick(){function e(t,s,i){a(i),s.toggle(),s.isOpen&&(t.focusState="self",s.elements.controlledMenu.focusState="none")}this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerdown",()=>{this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this._clearTimeout(),this.focusChild(s)},{passive:!0}),t.isSubmenuItem&&t.elements.toggle.dom.toggle.addEventListener("pointerup",i=>{this.currentEvent="mouse",e(this,t.elements.toggle,i)})}),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("pointerup",t=>{this.currentEvent="mouse",e(this,this.elements.controller,t)}),document.addEventListener("pointerup",t=>{this.focusState!=="none"&&(this.currentEvent="mouse",!this.dom.menu.contains(t.target)&&!this.dom.menu!==t.target&&(this.elements.rootMenu.hasOpened=this.elements.submenuToggles.some(s=>s.isOpen)))})}_handleHover(){this.elements.menuItems.forEach((e,t)=>{e.dom.link.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(t),e.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=t,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),e.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{e.elements.toggle.preview()},this.enterDelay)):e.elements.toggle.preview():this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren()},this.enterDelay)):this.closeChildren())))}),e.isSubmenuItem&&(e.dom.item.addEventListener("pointerleave",s=>{s.pointerType==="pen"||s.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse",e.elements.toggle.close()},this.leaveDelay)):(this.currentEvent="mouse",e.elements.toggle.close()):this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),e.dom.item.addEventListener("pointerenter",s=>{s.pointerType==="pen"||s.pointerType==="touch"||e.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()}))})}_handleKeydown(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&a(e)})}_handleKeyup(){this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",e=>{this.currentEvent="keyboard";const t=M(e);(t==="Space"||t==="Enter")&&(a(e),this.elements.controller.toggle(),this.elements.controller.isOpen&&this.focusFirstChild())})}_setTransitionDurations(){this.dom.menu.style.setProperty(`--${this.prefix}transition-duration`,`${this.transitionDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}open-transition-duration`,`${this.openDuration}ms`),this.dom.menu.style.setProperty(`--${this.prefix}close-transition-duration`,`${this.closeDuration}ms`)}focus(){this.focusState="self",this.shouldFocus&&this.dom.menu.focus()}blur(){this.focusState="none",this.shouldFocus&&this.dom.menu.blur()}focusCurrentChild(){this.focusState="self",this.currentChild!==-1&&this.currentMenuItem.focus()}focusChild(e){this.blurCurrentChild(),this.currentChild=e,this.focusCurrentChild()}focusFirstChild(){this.focusChild(0)}focusLastChild(){this.focusChild(this.elements.menuItems.length-1)}focusNextChild(){this.currentChild0?this.focusChild(this.currentChild-1):this.focusCurrentChild()}blurCurrentChild(){this.focusState="none",this.currentChild!==-1&&this.currentMenuItem.blur()}focusController(){this.dom.controller&&(this.shouldFocus&&this.dom.controller.focus(),this.focusState="none")}focusContainer(){this.dom.container&&(this.shouldFocus&&this.dom.container.focus(),this.focusState="none")}closeChildren(){this.elements.submenuToggles.forEach(e=>e.close())}blurChildren(){this.elements.menuItems.forEach(e=>{e.blur(),e.isSubmenuItem&&e.elements.childMenu.blurChildren()})}}class q extends F{constructor({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i=!1,childMenu:o=null,toggle:l=null,initialize:h=!0}){super({menuItemElement:e,menuLinkElement:t,parentMenu:s,isSubmenuItem:i,childMenu:o,toggle:l}),h&&this.initialize()}initialize(){super.initialize(),this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","treeitem"),this.dom.link.tabIndex=-1}focus(){super.focus(),this.dom.link.tabIndex=0}blur(){super.blur(),this.dom.link.tabIndex=-1}}class H extends ${constructor({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i=null,initialize:o=!0}){super({menuToggleElement:e,parentElement:t,controlledMenu:s,parentMenu:i}),o&&this.initialize()}initialize(){this._setIds(),this._setAriaAttributes(),this.dom.toggle.getAttribute("aria-expanded")==="true"?this.open():this._collapse(!1)}_setAriaAttributes(){this.dom.toggle.getAttribute("aria-expanded")!=="true"&&this.dom.toggle.setAttribute("aria-expanded","false"),this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id),this.dom.toggle.setAttribute("aria-owns",this.elements.controlledMenu.dom.menu.id)}}class D extends T{constructor({menuElement:t,menuItemSelector:s="li",menuLinkSelector:i="a",submenuItemSelector:o="li:has(ul)",submenuToggleSelector:l="a",submenuSelector:h="ul",controllerElement:m=null,containerElement:b=null,openClass:f="show",closeClass:p="hide",transitionClass:g="transitioning",transitionDuration:c=250,isTopLevel:w=!0,parentMenu:E=null,hoverType:I="off",hoverDelay:L=250,enterDelay:S=-1,leaveDelay:k=-1,prefix:A="am-",initialize:O=!0}){super({menuElement:t,menuItemSelector:s,menuLinkSelector:i,submenuItemSelector:o,submenuToggleSelector:l,submenuSelector:h,controllerElement:m,containerElement:b,openClass:f,closeClass:p,transitionClass:g,transitionDuration:c,isTopLevel:w,parentMenu:E,hoverType:I,hoverDelay:L,enterDelay:S,leaveDelay:k,prefix:A});r(this,"_MenuType",D);r(this,"_MenuItemType",q);r(this,"_MenuToggleType",H);O&&this.initialize()}initialize(){try{super.initialize(),this.isTopLevel?(this.dom.menu.setAttribute("role","tree"),this.elements.menuItems[0].dom.link.tabIndex=0):this.dom.menu.setAttribute("role","group"),this._handleFocus(),this._handleClick(),this._handleHover(),this._handleKeydown(),this._handleKeyup(),this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.removeAttribute("aria-owns")}catch(t){console.error(t)}}_handleHover(){this.elements.menuItems.forEach((t,s)=>{t.dom.link.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusChild(s),t.isSubmenuItem&&(this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview())):this.hoverType==="dynamic"&&(this.currentChild=s,(!this.isTopLevel||this.focusState!=="none")&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild()),(!this.isTopLevel||this.hasOpened)&&(this.currentEvent="mouse",this.elements.rootMenu.blurChildren(),this.focusCurrentChild(),t.isSubmenuItem?this.enterDelay>0?(this._clearTimeout(),this._setTimeout(()=>{t.elements.toggle.preview()},this.enterDelay)):t.elements.toggle.preview():this.enterDelay>0&&this._clearTimeout())))}),t.isSubmenuItem&&(t.dom.item.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||(this.hoverType==="on"?this.leaveDelay>0&&this._clearTimeout():this.hoverType==="dynamic"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.currentEvent="mouse"},this.leaveDelay)):this.currentEvent="mouse"))}),t.dom.item.addEventListener("pointerenter",i=>{i.pointerType==="pen"||i.pointerType==="touch"||t.isSubmenuItem&&(this.hoverType==="on"||this.hoverType==="dynamic")&&this.leaveDelay>0&&this._clearTimeout()})),this.isTopLevel&&this.dom.menu.addEventListener("pointerleave",i=>{i.pointerType==="pen"||i.pointerType==="touch"||this.hoverType==="on"&&(this.leaveDelay>0?(this._clearTimeout(),this._setTimeout(()=>{this.closeChildren(),this.blur()},this.leaveDelay)):(this.closeChildren(),this.blur()))})})}_handleKeydown(){super._handleKeydown(),this.dom.menu.addEventListener("keydown",t=>{this.currentEvent="keyboard";const s=M(t);if(s==="Tab"&&(this.elements.rootMenu.focusState!=="none"?this.elements.rootMenu.blur():this.elements.rootMenu.focus()),this.focusState==="self"){const i=["Space","ArrowUp","ArrowDown","ArrowLeft","Asterisk","Home","End"],o=["Enter","ArrowRight"],l=["Escape"];(i.includes(s)||this.currentMenuItem.isSubmenuItem&&o.includes(s)||this.elements.controller&&l.includes(s))&&a(t)}})}_handleKeyup(){super._handleKeyup(),this.dom.menu.addEventListener("keyup",t=>{this.currentEvent="keyboard";const s=M(t),{altKey:i,crtlKey:o,metaKey:l}=t;if(s==="Character"&&!(i||o||l))a(t),this.elements.rootMenu.currentEvent="character",this.focusNextNodeWithCharacter(t.key);else if(this.focusState==="self")if(s==="Enter"||s==="Space")a(t),this.currentMenuItem.isSubmenuItem?this.currentMenuItem.elements.toggle.isOpen?this.currentMenuItem.elements.toggle.close():this.currentMenuItem.elements.toggle.preview():this.currentMenuItem.dom.link.click();else if(s==="Escape")this.isTopLevel&&this.elements.controller&&this.elements.controller.isOpen&&(this.elements.controller.close(),this.focusController());else if(s==="ArrowDown")a(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):!this.isTopLevel&&this.currentChild===this.elements.menuItems.length-1?this.focusParentsNextChild():this.focusNextChild();else if(s==="ArrowUp"){a(t);const m=this.elements.menuItems[this.currentChild-1];m&&m.isSubmenuItem&&m.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentChild=this.currentChild-1,this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.focusChildsLastNode()):!this.isTopLevel&&this.currentChild===0?(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild()):this.focusPreviousChild()}else s==="ArrowRight"?this.currentMenuItem.isSubmenuItem&&(a(t),this.currentMenuItem.elements.toggle.isOpen?(this.blurCurrentChild(),this.currentMenuItem.elements.childMenu.currentEvent=this.currentEvent,this.currentMenuItem.elements.childMenu.focusFirstChild()):this.currentMenuItem.elements.toggle.preview()):s==="ArrowLeft"?(a(t),this.currentMenuItem.isSubmenuItem&&this.currentMenuItem.elements.toggle.isOpen?(this.currentMenuItem.elements.childMenu.blurCurrentChild(),this.currentMenuItem.elements.toggle.close()):this.isTopLevel||(this.blurCurrentChild(),this.elements.parentMenu.currentEvent=this.currentEvent,this.elements.parentMenu.focusCurrentChild())):s==="Home"?(a(t),this.blurCurrentChild(),this.elements.rootMenu.focusFirstChild()):s==="End"?(a(t),this.blurCurrentChild(),this.elements.rootMenu.focusLastNode()):s==="Asterisk"&&(a(t),this.openChildren())})}focusLastNode(){const t=this.elements.menuItems.length-1,s=this.elements.menuItems[t];s.isSubmenuItem&&s.elements.toggle.isOpen?(this.currentChild=t,s.elements.childMenu.currentEvent=this.currentEvent,s.elements.childMenu.focusLastNode()):this.focusLastChild()}openChildren(){this.elements.submenuToggles.forEach(t=>t.preview())}focusNextNodeWithCharacter(t){function s(f){let p=[];return f.elements.menuItems.forEach(g=>{p.push(g),g.isSubmenuItem&&g.elements.toggle.isOpen&&(p=[...p,...s(g.elements.toggle.elements.controlledMenu)])}),p}const i=t.toLowerCase(),o=s(this.elements.rootMenu),l=o.indexOf(this.currentMenuItem)+1,h=[...o.slice(l),...o.slice(0,l)];let m=0,b=!1;for(;!b&&m {#method--closesiblings} -Closes all subling menus. +Closes all sibling menus. ```js BaseMenuToggle.closeSiblings(); diff --git a/docs/api/base-menu.md b/docs/api/base-menu.md index e9792e9b..512012eb 100644 --- a/docs/api/base-menu.md +++ b/docs/api/base-menu.md @@ -35,7 +35,7 @@ new BaseMenu({ }); ``` -The constructor populates the dom, selector, CSS class, and hover related properties. It will _not_ initialize the menu automatically; this is left to the subclasses to envoke. +The constructor populates the dom, selector, CSS class, and hover related properties. It will _not_ initialize the menu automatically; this is left to the subclasses to evoke. ### Parameters {#constructor--parameters} @@ -53,15 +53,15 @@ The constructor populates the dom, selector, CSS class, and hover related proper | options.openClass | `string`, `string[]`, `null` | The class to apply when a menu is "open". | `"show"` | | options.closeClass | `string`, `string[]`, `null` | The class to apply when a menu is "closed". | `"hide"` | | options.transitionClass | `string`, `string[]`, `null` | The class to apply when a menu is transitioning between "open" and "closed" states. | `transitioning` | -| options.transitionDuration | `number` | The duration of the transition between "open" and "closed" states (in miliseconds). | `250` | -| options.openDuration | `number` | The duration of the transition from "closed" to "open" states (in miliseconds). | `250` | -| options.closeDuration | `number` | The duration of the transition from "open" to "closed" states (in miliseconds). | `250` | +| options.transitionDuration | `number` | The duration of the transition between "open" and "closed" states (in milliseconds). | `250` | +| options.openDuration | `number` | The duration of the transition from "closed" to "open" states (in milliseconds). | `250` | +| options.closeDuration | `number` | The duration of the transition from "open" to "closed" states (in milliseconds). | `250` | | options.isTopLevel | `boolean` | A flag to mark the root menu. | `false` | | options.parentMenu | `BaseMenu`, `null` | The parent menu to this menu. | `null` | | options.hoverType | `string` | The type of hoverability a menu has. | `"off"` | -| options.hoverDelay | `number` | The delay for opening and closing menus if the menu is hoverable (in miliseconds). | `250` | -| options.enterDelay | `number` | The delay for opening menus if the menu is hoverable (in miliseconds). | `-1` | -| options.leaveDelay | `number` | The delay for closing menus if the menu is hoverable (in miliseconds). | `-1` | +| options.hoverDelay | `number` | The delay for opening and closing menus if the menu is hoverable (in milliseconds). | `250` | +| options.enterDelay | `number` | The delay for opening menus if the menu is hoverable (in milliseconds). | `-1` | +| options.leaveDelay | `number` | The delay for closing menus if the menu is hoverable (in milliseconds). | `-1` | | options.prefix | `string`, `null` | The prefix for the CSS custom properties. | `"am-"` | ## Initialize @@ -225,7 +225,7 @@ BaseMenu._transitionClass; // Default: `"transitioning`" ### _transitionDuration {#property--transitionduration} -The duration time (in miliseconds) for the transition between open and closed states. +The duration time (in milliseconds) for the transition between open and closed states. ```js BaseMenu._transitionDuration; // Default: `250`. @@ -237,7 +237,7 @@ BaseMenu._transitionDuration; // Default: `250`. ### _openDuration {#property--openduration} -The duration time (in miliseconds) for the transition from closed to open states. +The duration time (in milliseconds) for the transition from closed to open states. ```js BaseMenu._openDuration; // Default: `-1`. @@ -249,7 +249,7 @@ BaseMenu._openDuration; // Default: `-1`. ### _closeDuration {#property--closeduration} -The duration time (in miliseconds) for the transition from open to closed states. +The duration time (in milliseconds) for the transition from open to closed states. ```js BaseMenu._closeDuration; // Default: `-1`. @@ -329,7 +329,7 @@ You can read more about [supported hover types](../hover-types) in the docs. ### _hoverDelay {#property--hoverdelay} -The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. +The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. ```js BaseMenu._hoverDelay; // Default: `250`. @@ -341,7 +341,7 @@ BaseMenu._hoverDelay; // Default: `250`. ### _enterDelay {#property--enterdelay} -The delay time (in miliseconds) used for pointerenter events to take place. +The delay time (in milliseconds) used for pointerenter events to take place. ```js BaseMenu._enterDelay; // Default: `-1`. @@ -353,7 +353,7 @@ BaseMenu._enterDelay; // Default: `-1`. ### _leaveDelay {#property--leavedelay} -The delay time (in miliseconds) used for pointerleave events to take place. +The delay time (in milliseconds) used for pointerleave events to take place. ```js BaseMenu._leaveDelay; // Default: `-1`. @@ -527,7 +527,7 @@ See [_transitionClass](#property--transitionclass) for more information. ### transitionDuration {#getter-setter--transitionduration} -The duration time (in miliseconds) for the transition between open and closed states. +The duration time (in milliseconds) for the transition between open and closed states. ::: code-group @@ -549,7 +549,7 @@ See [_transitionDuration](#property--transitionduration) for more information. ### openDuration {#getter-setter--openduration} -The duration time (in miliseconds) for the transition from closed to open states. +The duration time (in milliseconds) for the transition from closed to open states. ::: code-group @@ -571,7 +571,7 @@ See [_openDuration](#property--openduration) for more information. ### closeDuration {#getter-setter--closeduration} -The duration time (in miliseconds) for the transition from open to closed states. +The duration time (in milliseconds) for the transition from open to closed states. ::: code-group @@ -695,7 +695,7 @@ See [_hoverType](#property--hovertype) for more information. ### hoverDelay {#getter-setter--hoverdelay} -The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. +The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. ::: code-group @@ -715,7 +715,7 @@ See [_hoverDelay](#property--hoverdelay) for more information. ### enterDelay {#getter-setter--enterdelay} -The delay time (in miliseconds) used for pointerenter events to take place. +The delay time (in milliseconds) used for pointerenter events to take place. ::: code-group @@ -737,7 +737,7 @@ See [_enterDelay](#property--enterdelay) for more information. ### leaveDelay {#getter-setter--leavedelay} -The delay time (in miliseconds) used for pointerleave events to take place. +The delay time (in milliseconds) used for pointerleave events to take place. ::: code-group @@ -972,13 +972,13 @@ Before executing anything, the event is checked to make sure the event wasn't tr This method will add the following behaviour: -#### Hover Type "on" {#method--handlefover--hovertype-on} +#### Hover Type "on" {#method--handlehover--hovertype-on} - When a `pointerenter` event triggers on any menu item the menu's [current child](#property--currentchild) value will change to that menu item. - When a `pointerenter` event triggers on a submenu item the [preview method](./base-menu-toggle#method--preview) for the submenu item's toggle will be called. - When a `pointerleave` event triggers on an open submenu item the [close method](./base-menu-toggle#method--close) for the submenu item's toggle will be called after a delay set by the menu's hover delay. -#### Hover Type "dynamic" {#method--handlefover--hovertype-dynamic} +#### Hover Type "dynamic" {#method--handlehover--hovertype-dynamic} - When a `pointerenter` event triggers on any menu item the menu's current child value will change to that menu item. - When a `pointerenter` event triggers on any menu item, and the menu's [focus state](#property--focusstate) is not "none", the menu item will be focused. @@ -988,7 +988,7 @@ This method will add the following behaviour: - When a `pointerleave` event triggers on an open submenu item that is not a root-level submenu item the close method for the submenu item's toggle will be called and the submenu item will be focused after a delay set by the menu's hover delay. - When a `pointerleave` event triggers on an open submenu item that is a root-level submenu item no submenu-specific methods will be called. -#### Hover Type "off" {#method--handlefover--hovertype-off} +#### Hover Type "off" {#method--handlehover--hovertype-off} All `pointerenter` and `pointerleave` events are ignored. @@ -1000,7 +1000,7 @@ Handles keydown events throughout the menu for proper menu use. BaseMenu._handleKeydown(); ``` -This method exists to assit the [_handleKeyup](#method--handlekeyup) method. +This method exists to assist the [_handleKeyup](#method--handlekeyup) method. This method will do the following: diff --git a/docs/api/disclosure-menu.md b/docs/api/disclosure-menu.md index 409e8044..c8e47b55 100644 --- a/docs/api/disclosure-menu.md +++ b/docs/api/disclosure-menu.md @@ -58,15 +58,15 @@ The constructor will call [BaseMenu's constructor](./base-menu#constructor) with | options.openClass | `string`, `string[]`, `null` | The class to apply when a menu is "open". | `"show"` | | options.closeClass | `string`, `string[]`, `null` | The class to apply when a menu is "closed". | `"hide"` | | options.transitionClass | `string`, `string[]`, `null` | The class to apply when a menu is transitioning between "open" and "closed" states. | `transitioning` | -| options.transitionDuration | `number` | The duration of the transition between "open" and "closed" states (in miliseconds). | `250` | -| options.openDuration | `number` | The duration of the transition from "closed" to "open" states (in miliseconds). | `250` | -| options.closeDuration | `number` | The duration of the transition from "open" to "closed" states (in miliseconds). | `250` | +| options.transitionDuration | `number` | The duration of the transition between "open" and "closed" states (in milliseconds). | `250` | +| options.openDuration | `number` | The duration of the transition from "closed" to "open" states (in milliseconds). | `250` | +| options.closeDuration | `number` | The duration of the transition from "open" to "closed" states (in milliseconds). | `250` | | options.isTopLevel | `boolean` | A flag to mark the root menu. | `true` | | options.parentMenu | `DisclosureMenu`, `null` | The parent menu to this menu. | `null` | | options.hoverType | `string` | The type of hoverability a menu has. | `"off"` | -| options.hoverDelay | `number` | The delay for opening and closing menus if the menu is hoverable (in miliseconds). | `250` | -| options.enterDelay | `number` | The delay for opening a menu if the menu is focusable (in miliseconds). | `-1` | -| options.leaveDelay | `number` | The delay for closing a menu if the menu is focusable (in miliseconds). | `-1` | +| options.hoverDelay | `number` | The delay for opening and closing menus if the menu is hoverable (in milliseconds). | `250` | +| options.enterDelay | `number` | The delay for opening a menu if the menu is focusable (in milliseconds). | `-1` | +| options.leaveDelay | `number` | The delay for closing a menu if the menu is focusable (in milliseconds). | `-1` | | options.optionalKeySupport | `boolean` | A flag to add optional keyboard support (Arrow keys, Home, and End) to the menu. | `false` | | options.prefix | `string`, `null` | The prefix for the CSS custom properties. | `"am-"` | | options.initialize | `boolean` | A flag to initialize the menu immediately upon creation. | `true` | @@ -237,7 +237,7 @@ DisclosureMenu._handleKeyup(); Adds all `keyup` listeners from [BaseMenu's _handleKeyup method](./base-menu#method--handlekeyup). -Adds the following keybindings (explanations are taken from the [WAI ARIA Pracitices Example Disclosure for Navigation Menus](https://www.w3.org/TR/wai-aria-practices-1.2/examples/disclosure/disclosure-navigation.html#kbd_label): +Adds the following keybindings (explanations are taken from the [WAI ARIA Practices Example Disclosure for Navigation Menus](https://www.w3.org/TR/wai-aria-practices-1.2/examples/disclosure/disclosure-navigation.html#kbd_label): | Key | Function | | --- | --- | diff --git a/docs/api/menubar.md b/docs/api/menubar.md index e324b06c..16e08d01 100644 --- a/docs/api/menubar.md +++ b/docs/api/menubar.md @@ -57,15 +57,15 @@ The constructor will call [BaseMenu's constructor](./base-menu#constructor) with | options.openClass | `string`, `string[]`, `null` | The class to apply when a menu is "open". | `"show"` | | options.closeClass | `string`, `string[]`, `null` | The class to apply when a menu is "closed". | `"hide"` | | options.transitionClass | `string`, `string[]`, `null` | The class to apply when a menu is transitioning between "open" and "closed" states. | `"transitioning"` | -| options.transitionDuration | `number` | The duration of the transition between "open" and "closed" states (in miliseconds). | `250` | -| options.openDuration | `number` | The duration of the transition from "closed" to "open" states (in miliseconds). | `250` | -| options.closeDuration | `number` | The duration of the transition from "open" to "closed" states (in miliseconds). | `250` | +| options.transitionDuration | `number` | The duration of the transition between "open" and "closed" states (in milliseconds). | `250` | +| options.openDuration | `number` | The duration of the transition from "closed" to "open" states (in milliseconds). | `250` | +| options.closeDuration | `number` | The duration of the transition from "open" to "closed" states (in milliseconds). | `250` | | options.isTopLevel | `boolean` | A flag to mark the root menu. | `true` | | options.parentMenu | `Menubar`, `null` | The parent menu to this menu. | `null` | | options.hoverType | `string` | The type of hoverability a menu has. | `"off"` | -| options.hoverDelay | `number` | The delay for opening and closing menus if the menu is hoverable (in miliseconds). | `250` | -| options.enterDelay | `number` | The delay for opening a menu if the menu is focusable (in miliseconds). | `-1` | -| options.leaveDelay | `number` | The delay for closing a menu if the menu is focusable (in miliseconds). | `-1` | +| options.hoverDelay | `number` | The delay for opening and closing menus if the menu is hoverable (in milliseconds). | `250` | +| options.enterDelay | `number` | The delay for opening a menu if the menu is focusable (in milliseconds). | `-1` | +| options.leaveDelay | `number` | The delay for closing a menu if the menu is focusable (in milliseconds). | `-1` | | options.prefix | `string`, `null` | The prefix for the CSS custom properties. | `"am-"` | | options.initialize | `boolean` | A flag to initialize the menu immediately upon creation. | `true` | diff --git a/docs/api/top-link-disclosure-menu.md b/docs/api/top-link-disclosure-menu.md index 500145be..3ab74a27 100644 --- a/docs/api/top-link-disclosure-menu.md +++ b/docs/api/top-link-disclosure-menu.md @@ -60,15 +60,15 @@ The constructor will call [BaseMenu's constructor](./base-menu#constructor) with | options.openClass | `(string`, `string[])`, `null` | The class to apply when a menu is "open". | `"show"` | | options.closeClass | `(string`, `string[])`, `null` | The class to apply when a menu is "closed". | `"hide"` | | options.transitionClass | `(string`, `string[])`, `null` | The class to apply when a menu is transitioning between "open" and "closed" states. | `"transitioning"` | -| options.transitionDuration | `number` | The duration of the transition between "open" and "closed" states (in miliseconds). | `250` | -| options.openDuration | `number` | The duration of the transition from "closed" to "open" states (in miliseconds). | `250` | -| options.closeDuration | `number` | The duration of the transition from "open" to "closed" states (in miliseconds). | `250` | +| options.transitionDuration | `number` | The duration of the transition between "open" and "closed" states (in milliseconds). | `250` | +| options.openDuration | `number` | The duration of the transition from "closed" to "open" states (in milliseconds). | `250` | +| options.closeDuration | `number` | The duration of the transition from "open" to "closed" states (in milliseconds). | `250` | | options.isTopLevel | `boolean` | A flag to mark the root menu. | `true` | | options.parentMenu | `TopLinkDisclosureMenu`, `null` | The parent menu to this menu. | `null` | | options.hoverType | `string` | The type of hoverability a menu has. | `"off"` | -| options.hoverDelay | `number` | The delay for opening and closing menus if the menu is hoverable (in miliseconds). | `250` | -| options.enterDelay | `number` | The delay for opening a menu if the menu is focusable (in miliseconds). | `-1` | -| options.leaveDelay | `number` | The delay for closing a menu if the menu is focusable (in miliseconds). | `-1` | +| options.hoverDelay | `number` | The delay for opening and closing menus if the menu is hoverable (in milliseconds). | `250` | +| options.enterDelay | `number` | The delay for opening a menu if the menu is focusable (in milliseconds). | `-1` | +| options.leaveDelay | `number` | The delay for closing a menu if the menu is focusable (in milliseconds). | `-1` | | options.optionalKeySupport | `boolean` | A flag to add optional keyboard support (Arrow keys, Home, and End) to the menu. | `false` | | options.prefix | `string`, `null` | The prefix for the CSS custom properties. | `"am-"` | | options.initialize | `boolean` | A flag to initialize the menu immediately upon creation. | `true` | @@ -283,7 +283,7 @@ TopLinkDisclosureMenu._handleKeyup(); Adds all `keyup` listeners from [BaseMenu's _handleKeyup method](./base-menu#method--handlekeyup). -Adds the following keybindings (explanations are taken from the [WAI ARIA Pracitices Example Disclosure for Navigation Menus](https://www.w3.org/TR/wai-aria-practices-1.2/examples/disclosure/disclosure-navigation.html#kbd_label): +Adds the following keybindings (explanations are taken from the [WAI ARIA Practices Example Disclosure for Navigation Menus](https://www.w3.org/TR/wai-aria-practices-1.2/examples/disclosure/disclosure-navigation.html#kbd_label): | Key | Function | | --- | --- | diff --git a/docs/api/treeview.md b/docs/api/treeview.md index 45ff10ed..3a6cbada 100644 --- a/docs/api/treeview.md +++ b/docs/api/treeview.md @@ -57,15 +57,15 @@ The constructor will call [BaseMenu's constructor](./base-menu#constructor) with | options.openClass | `string`, `string[]`, `null` | The class to apply when a menu is "open". | `null` | | options.closeClass | `string`, `string[]`, `null` | The class to apply when a menu is "closed". | `null` | | options.transitionClass | `string`, `string[]`, `null` | The class to apply when a menu is transitioning between "open" and "closed" states. | `null` | -| options.transitionDuration | `number` | The duration of the transition between "open" and "closed" states (in miliseconds). | `250` | -| options.openDuration | `number` | The duration of the transition from "closed" to "open" states (in miliseconds). | `250` | -| options.closeDuration | `number` | The duration of the transition from "open" to "closed" states (in miliseconds). | `250` | +| options.transitionDuration | `number` | The duration of the transition between "open" and "closed" states (in milliseconds). | `250` | +| options.openDuration | `number` | The duration of the transition from "closed" to "open" states (in milliseconds). | `250` | +| options.closeDuration | `number` | The duration of the transition from "open" to "closed" states (in milliseconds). | `250` | | options.isTopLevel | `boolean` | A flag to mark the root menu. | `true` | | options.parentMenu | `Treeview`, `null` | The parent menu to this menu. | `null` | | options.hoverType | `string` | The type of hoverability a menu has. | `"off"` | -| options.hoverDelay | `number` | The delay for opening and closing menus if the menu is hoverable (in miliseconds). | `250` | -| options.enterDelay | `number` | The delay for opening a menu if the menu is focusable (in miliseconds). | `-1` | -| options.leaveDelay | `number` | The delay for closing a menu if the menu is focusable (in miliseconds). | `-1` | +| options.hoverDelay | `number` | The delay for opening and closing menus if the menu is hoverable (in milliseconds). | `250` | +| options.enterDelay | `number` | The delay for opening a menu if the menu is focusable (in milliseconds). | `-1` | +| options.leaveDelay | `number` | The delay for closing a menu if the menu is focusable (in milliseconds). | `-1` | | options.prefix | `string`, `null` | The prefix for the CSS custom properties. | `"am-"` | | options.initialize | `boolean` | A flag to initialize the menu immediately upon creation. | `true` | @@ -149,13 +149,13 @@ Before executing anything, the event is checked to make sure the event wasn't tr This method will add the following behaviour: -#### Hover Type "on" {#method--handlefover--hovertype-on} +#### Hover Type "on" {#method--handlehover--hovertype-on} - When a `pointerenter` event triggers on any menu item the menu's [current child](#property--currentchild) value will change to that menu item. - When a `pointerenter` event triggers on a submenu item the [preview method](./base-menu-toggle#method--preview) for the submenu item's toggle will be called. - When a `pointerleave` event triggers on the menu itself the [closeChildren method](./base-menu#method--closechildren) will be called after a delay set by the menu's hover delay. -#### Hover Type "dynamic" {#method--handlefover--hovertype-dynamic} +#### Hover Type "dynamic" {#method--handlehover--hovertype-dynamic} - When a `pointerenter` event triggers on any menu item the menu's current child value will change to that menu item. - When a `pointerenter` event triggers on any menu item, and the menu's [focus state](#property--focusstate) is not "none", the menu item will be focused. @@ -163,7 +163,7 @@ This method will add the following behaviour: - When a `pointerenter` event triggers on a non-submenu item, and a submenu is already open, the closeChildren method for the menu will be called. - When a `pointerenter` event triggers on a submenu item, and no submenu is open, no submenu-specific methods will be called. -#### Hover Type "off" {#method--handlefover--hovertype-off} +#### Hover Type "off" {#method--handlehover--hovertype-off} All `pointerenter` and `pointerleave` events are ignored. diff --git a/docs/hover-types.md b/docs/hover-types.md index 1dc63a7b..13e689bc 100644 --- a/docs/hover-types.md +++ b/docs/hover-types.md @@ -28,7 +28,7 @@ new DisclosureMenu({ ### Treeviews and Hover On -When using a treeview menu with hover **on**, `pointerenter` events are triggered as expected, however `pointerleave` events are handled differently. Leaving a menu item that is open will _not_ close that menu in a treeview. The only way a `pointerleave` event will close a menu item is if the root menu itself is left. This is to prevent a lot of visual confusion when hovering/unhover menu items in a treeview. +When using a treeview menu with hover **on**, `pointerenter` events are triggered as expected, however `pointerleave` events are handled differently. Leaving a menu item that is open will _not_ close that menu in a treeview. The only way a `pointerleave` event will close a menu item is if the root menu itself is left. This is to prevent a lot of visual confusion when hovering/unhovering menu items in a treeview. ## Hover Dynamic diff --git a/docs/opening-and-closing.md b/docs/opening-and-closing.md index 72ba75ba..2281856d 100644 --- a/docs/opening-and-closing.md +++ b/docs/opening-and-closing.md @@ -99,7 +99,7 @@ new DisclosureMenu({ ## Transition Duration {#transition-duration} -When a menu has a transition class, the `transitionDuration` option can be used to set the duration (in miliseconds) of the transition, which will in turn set a timeout before finalizing the closing of a menu. +When a menu has a transition class, the `transitionDuration` option can be used to set the duration (in milliseconds) of the transition, which will in turn set a timeout before finalizing the closing of a menu. The reason for this is to allow for the menu's closing transition to be animated. Most of the time, when a menu is closed it will have the CSS property `display` set to `none`, which causes issues when trying to animate between states. Setting a timeout before the transition class is removed from the menu, allows you to transition between something like `opacity` or `transform` before the menu is visually removed. diff --git a/docs/optional-keyboard-support.md b/docs/optional-keyboard-support.md index fdaafd40..380e60a5 100644 --- a/docs/optional-keyboard-support.md +++ b/docs/optional-keyboard-support.md @@ -1,6 +1,6 @@ # Optional Keyboard Support -Accessible Menu supports keyboard navigation out of the box. However, for Disclosure Menus and Top Link Disclosure Menus there are addional keybindings that are optional in the ARIA Authoring Practices Guide (APG). +Accessible Menu supports keyboard navigation out of the box. However, for Disclosure Menus and Top Link Disclosure Menus there are additional keybindings that are optional in the ARIA Authoring Practices Guide (APG). Specifically, the APG states that the following keybindings should be optional: diff --git a/docs/quick-start.md b/docs/quick-start.md index 78d810b7..b9936aaa 100644 --- a/docs/quick-start.md +++ b/docs/quick-start.md @@ -64,7 +64,7 @@ const menu = new Treeview({ ::: -Accessible Menu will self-initialize once created adding the approriate roles, attributes, and keybindings. +Accessible Menu will self-initialize once created adding the appropriate roles, attributes, and keybindings. ### Two-level Menu diff --git a/docs/upgrade-guide.md b/docs/upgrade-guide.md index 9cd43ed3..8cb261b3 100644 --- a/docs/upgrade-guide.md +++ b/docs/upgrade-guide.md @@ -24,7 +24,7 @@ You may now use `import` and `require` to import accessible menu without needing - The default `menuToggleSelector` has been changes from `"a"` to `"button"`. -#### Top Link Disclousre Menus +#### Top Link Disclosure Menus - Added new menu type for [top link disclosure menus](/top-link-disclosure-menus). diff --git a/src/_baseMenu.js b/src/_baseMenu.js index e663e523..8b9a1e18 100644 --- a/src/_baseMenu.js +++ b/src/_baseMenu.js @@ -144,7 +144,7 @@ class BaseMenu { _transitionClass = "transitioning"; /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * @protected * @@ -153,7 +153,7 @@ class BaseMenu { _transitionDuration = 250; /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * @protected * @@ -162,7 +162,7 @@ class BaseMenu { _openDuration = -1; /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * @protected * @@ -216,7 +216,7 @@ class BaseMenu { _hoverType = "off"; /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * @protected * @@ -225,7 +225,7 @@ class BaseMenu { _hoverDelay = 250; /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * @protected * @@ -234,7 +234,7 @@ class BaseMenu { _enterDelay = -1; /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * @protected * @@ -293,15 +293,15 @@ class BaseMenu { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). - * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in miliseconds). - * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). + * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in milliseconds). + * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = false] - A flag to mark the root menu. * @param {?BaseMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening menus if the menu is hoverable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing menus if the menu is hoverable (in milliseconds). * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. */ constructor({ @@ -535,7 +535,7 @@ class BaseMenu { } /** - * The duration time (in miliseconds) for the transition between open and closed states. + * The duration time (in milliseconds) for the transition between open and closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's transition duration. @@ -553,7 +553,7 @@ class BaseMenu { } /** - * The duration time (in miliseconds) for the transition from closed to open states. + * The duration time (in milliseconds) for the transition from closed to open states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's openDuration. @@ -575,7 +575,7 @@ class BaseMenu { } /** - * The duration time (in miliseconds) for the transition from open to closed states. + * The duration time (in milliseconds) for the transition from open to closed states. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's closeDuration. @@ -669,7 +669,7 @@ class BaseMenu { } /** - * The delay time (in miliseconds) used for pointerenter/pointerleave events to take place. + * The delay time (in milliseconds) used for pointerenter/pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's hover delay. @@ -683,7 +683,7 @@ class BaseMenu { } /** - * The delay time (in miliseconds) used for pointerenter events to take place. + * The delay time (in milliseconds) used for pointerenter events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's enter delay. @@ -701,7 +701,7 @@ class BaseMenu { } /** - * The delay time (in miliseconds) used for pointerleave events to take place. + * The delay time (in milliseconds) used for pointerleave events to take place. * * This functions differently for root vs. submenus. * Submenus will always inherit their root menu's leave delay. diff --git a/src/disclosureMenu.js b/src/disclosureMenu.js index 962c21c2..93ae08a0 100644 --- a/src/disclosureMenu.js +++ b/src/disclosureMenu.js @@ -72,15 +72,15 @@ class DisclosureMenu extends BaseMenu { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). - * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in miliseconds). - * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). + * @param {boolean} [options.openDuration = -1] - The duration of the transition from "closed" to "open" states (in milliseconds). + * @param {boolean} [options.closeDuration = -1] - The duration of the transition from "open" to "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?DisclosureMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). * @param {boolean} [options.optionalKeySupport = false] - A flag to add optional keyboard support (Arrow keys, Home, and End) to the menu. * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. diff --git a/src/menubar.js b/src/menubar.js index f3a47a98..78b449c3 100644 --- a/src/menubar.js +++ b/src/menubar.js @@ -65,13 +65,13 @@ class Menubar extends BaseMenu { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?Menubar} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. */ diff --git a/src/topLinkDisclosureMenu.js b/src/topLinkDisclosureMenu.js index 8d5d38da..01ec78f1 100644 --- a/src/topLinkDisclosureMenu.js +++ b/src/topLinkDisclosureMenu.js @@ -108,13 +108,13 @@ class TopLinkDisclosureMenu extends BaseMenu { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?TopLinkDisclosureMenu} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). * @param {boolean} [options.optionalKeySupport = false] - A flag to add optional keyboard support (Arrow keys, Home, and End) to the menu. * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. diff --git a/src/treeview.js b/src/treeview.js index 390f5631..e9408319 100644 --- a/src/treeview.js +++ b/src/treeview.js @@ -65,13 +65,13 @@ class Treeview extends BaseMenu { * @param {?(string|string[])} [options.openClass = show] - The class to apply when a menu is "open". * @param {?(string|string[])} [options.closeClass = hide] - The class to apply when a menu is "closed". * @param {?(string|string[])} [options.transitionClass = transitioning] - The class to apply when a menu is transitioning between "open" and "closed" states. - * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in miliseconds). + * @param {number} [options.transitionDuration = 250] - The duration of the transition between "open" and "closed" states (in milliseconds). * @param {boolean} [options.isTopLevel = true] - A flag to mark the root menu. * @param {?Treeview} [options.parentMenu = null] - The parent menu to this menu. * @param {string} [options.hoverType = off] - The type of hoverability a menu has. - * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in miliseconds). - * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in miliseconds). - * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in miliseconds). + * @param {number} [options.hoverDelay = 250] - The delay for opening and closing menus if the menu is hoverable (in milliseconds). + * @param {number} [options.enterDelay = -1] - The delay for opening a menu if the menu is focusable (in milliseconds). + * @param {number} [options.leaveDelay = -1] - The delay for closing a menu if the menu is focusable (in milliseconds). * @param {?string} [options.prefix = am-] - The prefix to use for CSS custom properties. * @param {boolean} [options.initialize = true] - A flag to initialize the menu immediately upon creation. */ diff --git a/tests/eventHandlers/keyPress.test.js b/tests/eventHandlers/keyPress.test.js index fcca7868..cef996ee 100644 --- a/tests/eventHandlers/keyPress.test.js +++ b/tests/eventHandlers/keyPress.test.js @@ -168,7 +168,7 @@ describe("keyPress", () => { expect(keyPress(event)).toBe("Asterisk"); }); - // Test all character keys (A through Z both lowercase and captial). + // Test all character keys (A through Z both lowercase and capital). const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; it.each(characters.split(""))( "should return Character when the %s key is pressed", diff --git a/tests/menus/DisclosureMenu/aria.test.js b/tests/menus/DisclosureMenu/aria.test.js index 630c8e5c..96fd1e8c 100644 --- a/tests/menus/DisclosureMenu/aria.test.js +++ b/tests/menus/DisclosureMenu/aria.test.js @@ -17,7 +17,7 @@ describe("DisclosureMenu", () => { controllerElement: document.querySelector("button"), }); - // Test the root menu's aria-labbelledby attribute. + // Test the root menu's aria-labelledby attribute. it("should set the root menu's aria-labelledby attribute", () => { expect(menu.dom.menu.getAttribute("aria-labelledby")).toBe( menu.dom.controller.id diff --git a/tests/menus/DisclosureMenu/initialize.test.js b/tests/menus/DisclosureMenu/initialize.test.js index 40473566..69202b22 100644 --- a/tests/menus/DisclosureMenu/initialize.test.js +++ b/tests/menus/DisclosureMenu/initialize.test.js @@ -370,7 +370,7 @@ describe("DisclosureMenu (custom arguments)", () => { } ); - // Thest that the DisclosureMenu will initialize if isTopLevel is true. + // Test that the DisclosureMenu will initialize if isTopLevel is true. it("should initialize if isTopLevel is true", () => { // Test that the menu initializes. expect(() => { diff --git a/tests/menus/DisclosureMenuToggle/public.test.js b/tests/menus/DisclosureMenuToggle/public.test.js index b1a17ff7..95238f3d 100644 --- a/tests/menus/DisclosureMenuToggle/public.test.js +++ b/tests/menus/DisclosureMenuToggle/public.test.js @@ -287,7 +287,7 @@ describe("DisclosureMenuToggle public methods", () => { }); }); - // Test DisclosureMenuToggle closeSiblins(). + // Test DisclosureMenuToggle closeSiblings(). describe("closeSiblings", () => { // Test that DisclosureMenuToggle implements the BaseMenuToggle closeSiblings. it("should implement the BaseMenuToggle closeSiblings", () => { diff --git a/tests/menus/Menubar/aria.test.js b/tests/menus/Menubar/aria.test.js index 3b0f3533..2f38c5d3 100644 --- a/tests/menus/Menubar/aria.test.js +++ b/tests/menus/Menubar/aria.test.js @@ -17,7 +17,7 @@ describe("Menubar", () => { controllerElement: document.querySelector("button"), }); - // Test the root menu's aria-labbelledby attribute. + // Test the root menu's aria-labelledby attribute. it("should set the root menu's aria-labelledby attribute", () => { expect(menu.dom.menu.getAttribute("aria-labelledby")).toBe( menu.dom.controller.id diff --git a/tests/menus/Menubar/initialize.test.js b/tests/menus/Menubar/initialize.test.js index eefa041b..db812f06 100644 --- a/tests/menus/Menubar/initialize.test.js +++ b/tests/menus/Menubar/initialize.test.js @@ -370,7 +370,7 @@ describe("Menubar (custom arguments)", () => { } ); - // Thest that the Menubar will initialize if isTopLevel is true. + // Test that the Menubar will initialize if isTopLevel is true. it("should initialize if isTopLevel is true", () => { // Test that the menu initializes. expect(() => { diff --git a/tests/menus/Menubar/keyboard.test.js b/tests/menus/Menubar/keyboard.test.js index e78ed173..23f3ae8c 100644 --- a/tests/menus/Menubar/keyboard.test.js +++ b/tests/menus/Menubar/keyboard.test.js @@ -520,7 +520,7 @@ describe("Menubar", () => { expect(menu.currentEvent).toBe("character"); }); - // Test that thet menu's focusNextChildWithCharacter method is called with the key that was pressed. + // Test that the menu's focusNextChildWithCharacter method is called with the key that was pressed. it("should call the menu's focusNextChildWithCharacter method with the key that was pressed", () => { // Create a new Menubar instance for testing. const menu = new Menubar({ diff --git a/tests/menus/MenubarItem/public.test.js b/tests/menus/MenubarItem/public.test.js index c04847ca..5ba51e56 100644 --- a/tests/menus/MenubarItem/public.test.js +++ b/tests/menus/MenubarItem/public.test.js @@ -20,8 +20,8 @@ afterEach(() => { describe("MenubarItem public methods", () => { // Test MenubarItem focus(). describe("focus", () => { - // Test that focus does not call focus() on the link if the parent menu's shouldFoucs is false. - it("should not call focus() on the link if the parent menu's shouldFoucs is false", () => { + // Test that focus does not call focus() on the link if the parent menu's shouldFocus is false. + it("should not call focus() on the link if the parent menu's shouldFocus is false", () => { // Create a new Menubar instance for testing. const menu = new Menubar({ menuElement: document.querySelector("ul"), @@ -39,8 +39,8 @@ describe("MenubarItem public methods", () => { expect(spy).not.toHaveBeenCalled(); }); - // Test that focus calls focus() on the link if the parent menu's shouldFoucs is true. - it("should call focus() on the link if the parent menu's shouldFoucs is true", () => { + // Test that focus calls focus() on the link if the parent menu's shouldFocus is true. + it("should call focus() on the link if the parent menu's shouldFocus is true", () => { // Create a new Menubar instance for testing. const menu = new Menubar({ menuElement: document.querySelector("ul"), @@ -103,8 +103,8 @@ describe("MenubarItem public methods", () => { // Test MenubarItem blur(). describe("blur", () => { - // Test that blur does not call blur() on the link if the parent menu's shouldFoucs is false. - it("should not call blur() on the link if the parent menu's shouldFoucs is false", () => { + // Test that blur does not call blur() on the link if the parent menu's shouldFocus is false. + it("should not call blur() on the link if the parent menu's shouldFocus is false", () => { // Create a new Menubar instance for testing. const menu = new Menubar({ menuElement: document.querySelector("ul"), @@ -122,8 +122,8 @@ describe("MenubarItem public methods", () => { expect(spy).not.toHaveBeenCalled(); }); - // Test that blur calls blur() on the link if the parent menu's shouldFoucs is true. - it("should call blur() on the link if the parent menu's shouldFoucs is true", () => { + // Test that blur calls blur() on the link if the parent menu's shouldFocus is true. + it("should call blur() on the link if the parent menu's shouldFocus is true", () => { // Create a new Menubar instance for testing. const menu = new Menubar({ menuElement: document.querySelector("ul"), diff --git a/tests/menus/MenubarToggle/public.test.js b/tests/menus/MenubarToggle/public.test.js index 878355b6..81163141 100644 --- a/tests/menus/MenubarToggle/public.test.js +++ b/tests/menus/MenubarToggle/public.test.js @@ -328,7 +328,7 @@ describe("MenubarToggle public methods", () => { }); }); - // Test MenubarToggle closeSiblins(). + // Test MenubarToggle closeSiblings(). describe("closeSiblings", () => { // Test that MenubarToggle implements the BaseMenuToggle closeSiblings. it("should implement the BaseMenuToggle closeSiblings", () => { diff --git a/tests/menus/TopLinkDisclosureMenu/aria.test.js b/tests/menus/TopLinkDisclosureMenu/aria.test.js index acbb5a9d..20b53890 100644 --- a/tests/menus/TopLinkDisclosureMenu/aria.test.js +++ b/tests/menus/TopLinkDisclosureMenu/aria.test.js @@ -17,7 +17,7 @@ describe("TopLinkDisclosureMenu", () => { controllerElement: document.querySelector("button"), }); - // Test the root menu's aria-labbelledby attribute. + // Test the root menu's aria-labelledby attribute. it("should set the root menu's aria-labelledby attribute", () => { expect(menu.dom.menu.getAttribute("aria-labelledby")).toBe( menu.dom.controller.id diff --git a/tests/menus/TopLinkDisclosureMenu/hover.test.js b/tests/menus/TopLinkDisclosureMenu/hover.test.js index c6fe0dba..1c513a0c 100644 --- a/tests/menus/TopLinkDisclosureMenu/hover.test.js +++ b/tests/menus/TopLinkDisclosureMenu/hover.test.js @@ -430,7 +430,7 @@ describe("TopLinkDisclosureMenu", () => { expect(menu.elements.submenuToggles[0].isOpen).toBeTruthy(); }); }); - // Test when an open menu item's subling is unhovered and rehovered before the timeout it stays open. + // Test when an open menu item's sibling is unhovered and rehovered before the timeout it stays open. describe("when an open menu item's sibling is unhovered and rehovered before the timeout", () => { it("should keep the menu open", () => { // Create a new TopLinkDisclosureMenu instance for testing. @@ -1200,7 +1200,7 @@ describe("TopLinkDisclosureMenu", () => { expect(spy).toHaveBeenCalled(); }); }); - describe("if the menu item is not a submenu item and the menu is the root menu wtih an open submenu", () => { + describe("if the menu item is not a submenu item and the menu is the root menu with an open submenu", () => { // Test that the menu's closeChildren method is called after a delay. it("should call the menu's closeChildren method after a delay", () => { // Create a new TopLinkDisclosureMenu instance for testing. diff --git a/tests/menus/TopLinkDisclosureMenu/initialize.test.js b/tests/menus/TopLinkDisclosureMenu/initialize.test.js index d3a11723..d8eadc7b 100644 --- a/tests/menus/TopLinkDisclosureMenu/initialize.test.js +++ b/tests/menus/TopLinkDisclosureMenu/initialize.test.js @@ -370,7 +370,7 @@ describe("TopLinkDisclosureMenu (custom arguments)", () => { } ); - // Thest that the TopLinkDisclosureMenu will initialize if isTopLevel is true. + // Test that the TopLinkDisclosureMenu will initialize if isTopLevel is true. it("should initialize if isTopLevel is true", () => { // Test that the menu initializes. expect(() => { diff --git a/tests/menus/TopLinkDisclosureMenuToggle/public.test.js b/tests/menus/TopLinkDisclosureMenuToggle/public.test.js index 0d56d0eb..757f31a2 100644 --- a/tests/menus/TopLinkDisclosureMenuToggle/public.test.js +++ b/tests/menus/TopLinkDisclosureMenuToggle/public.test.js @@ -287,7 +287,7 @@ describe("TopLinkDisclosureMenuToggle public methods", () => { }); }); - // Test TopLinkDisclosureMenuToggle closeSiblins(). + // Test TopLinkDisclosureMenuToggle closeSiblings(). describe("closeSiblings", () => { // Test that TopLinkDisclosureMenuToggle implements the BaseMenuToggle closeSiblings. it("should implement the BaseMenuToggle closeSiblings", () => { diff --git a/tests/menus/Treeview/aria.test.js b/tests/menus/Treeview/aria.test.js index 6a3240c6..2f0e328b 100644 --- a/tests/menus/Treeview/aria.test.js +++ b/tests/menus/Treeview/aria.test.js @@ -17,7 +17,7 @@ describe("Treeview", () => { controllerElement: document.querySelector("button"), }); - // Test the root menu's aria-labbelledby attribute. + // Test the root menu's aria-labelledby attribute. it("should set the root menu's aria-labelledby attribute", () => { expect(menu.dom.menu.getAttribute("aria-labelledby")).toBe( menu.dom.controller.id diff --git a/tests/menus/Treeview/initialize.test.js b/tests/menus/Treeview/initialize.test.js index e7784d4e..f2edb88e 100644 --- a/tests/menus/Treeview/initialize.test.js +++ b/tests/menus/Treeview/initialize.test.js @@ -370,7 +370,7 @@ describe("Treeview (custom arguments)", () => { } ); - // Thest that the Treeview will initialize if isTopLevel is true. + // Test that the Treeview will initialize if isTopLevel is true. it("should initialize if isTopLevel is true", () => { // Test that the menu initializes. expect(() => { diff --git a/tests/menus/Treeview/keyboard.test.js b/tests/menus/Treeview/keyboard.test.js index 97ed54ce..f4e33f11 100644 --- a/tests/menus/Treeview/keyboard.test.js +++ b/tests/menus/Treeview/keyboard.test.js @@ -354,7 +354,7 @@ describe("Treeview", () => { expect(menu.currentEvent).toBe("character"); }); - // Test that thet menu's focusNextNodeWithCharacter method is called with the key that was pressed. + // Test that the menu's focusNextNodeWithCharacter method is called with the key that was pressed. it("should call the menu's focusNextNodeWithCharacter method with the key that was pressed", () => { // Create a new Treeview instance for testing. const menu = new Treeview({ diff --git a/tests/menus/TreeviewItem/public.test.js b/tests/menus/TreeviewItem/public.test.js index d6c1aff9..2e1c08dd 100644 --- a/tests/menus/TreeviewItem/public.test.js +++ b/tests/menus/TreeviewItem/public.test.js @@ -20,8 +20,8 @@ afterEach(() => { describe("TreeviewItem public methods", () => { // Test TreeviewItem focus(). describe("focus", () => { - // Test that focus does not call focus() on the link if the parent menu's shouldFoucs is false. - it("should not call focus() on the link if the parent menu's shouldFoucs is false", () => { + // Test that focus does not call focus() on the link if the parent menu's shouldFocus is false. + it("should not call focus() on the link if the parent menu's shouldFocus is false", () => { // Create a new Treeview instance for testing. const menu = new Treeview({ menuElement: document.querySelector("ul"), @@ -39,8 +39,8 @@ describe("TreeviewItem public methods", () => { expect(spy).not.toHaveBeenCalled(); }); - // Test that focus calls focus() on the link if the parent menu's shouldFoucs is true. - it("should call focus() on the link if the parent menu's shouldFoucs is true", () => { + // Test that focus calls focus() on the link if the parent menu's shouldFocus is true. + it("should call focus() on the link if the parent menu's shouldFocus is true", () => { // Create a new Treeview instance for testing. const menu = new Treeview({ menuElement: document.querySelector("ul"), @@ -85,8 +85,8 @@ describe("TreeviewItem public methods", () => { // Test TreeviewItem blur(). describe("blur", () => { - // Test that blur does not call blur() on the link if the parent menu's shouldFoucs is false. - it("should not call blur() on the link if the parent menu's shouldFoucs is false", () => { + // Test that blur does not call blur() on the link if the parent menu's shouldFocus is false. + it("should not call blur() on the link if the parent menu's shouldFocus is false", () => { // Create a new Treeview instance for testing. const menu = new Treeview({ menuElement: document.querySelector("ul"), @@ -104,8 +104,8 @@ describe("TreeviewItem public methods", () => { expect(spy).not.toHaveBeenCalled(); }); - // Test that blur calls blur() on the link if the parent menu's shouldFoucs is true. - it("should call blur() on the link if the parent menu's shouldFoucs is true", () => { + // Test that blur calls blur() on the link if the parent menu's shouldFocus is true. + it("should call blur() on the link if the parent menu's shouldFocus is true", () => { // Create a new Treeview instance for testing. const menu = new Treeview({ menuElement: document.querySelector("ul"), diff --git a/tests/menus/TreeviewToggle/public.test.js b/tests/menus/TreeviewToggle/public.test.js index 85436233..b5d741b8 100644 --- a/tests/menus/TreeviewToggle/public.test.js +++ b/tests/menus/TreeviewToggle/public.test.js @@ -46,7 +46,7 @@ describe("TreeviewToggle public methods", () => { }); }); - // Test TreeviewToggle closeSiblins(). + // Test TreeviewToggle closeSiblings(). describe("closeSiblings", () => { // Test that TreeviewToggle implements the BaseMenuToggle closeSiblings. it("should implement the BaseMenuToggle closeSiblings", () => { diff --git a/tests/menus/_baseMenu/aria.test.js b/tests/menus/_baseMenu/aria.test.js index e94aa9dd..f0199995 100644 --- a/tests/menus/_baseMenu/aria.test.js +++ b/tests/menus/_baseMenu/aria.test.js @@ -19,7 +19,7 @@ describe("BaseMenu", () => { }); initializeMenu(menu); - // Test the root menu's aria-labbelledby attribute. + // Test the root menu's aria-labelledby attribute. it("should set the root menu's aria-labelledby attribute", () => { expect(menu.dom.menu.getAttribute("aria-labelledby")).toBe( menu.dom.controller.id diff --git a/tests/menus/_baseMenu/initialize.test.js b/tests/menus/_baseMenu/initialize.test.js index 19910b62..b1524883 100644 --- a/tests/menus/_baseMenu/initialize.test.js +++ b/tests/menus/_baseMenu/initialize.test.js @@ -447,7 +447,7 @@ describe("BaseMenu (custom arguments)", () => { } ); - // Thest that the BaseMenu will initialize if isTopLevel is true. + // Test that the BaseMenu will initialize if isTopLevel is true. it("should initialize if isTopLevel is true", () => { // Create a new BaseMenu instance for testing. const menu = new BaseMenu({ diff --git a/tests/menus/_baseMenuItem/public.test.js b/tests/menus/_baseMenuItem/public.test.js index 57cb0bbe..6599b313 100644 --- a/tests/menus/_baseMenuItem/public.test.js +++ b/tests/menus/_baseMenuItem/public.test.js @@ -21,8 +21,8 @@ afterEach(() => { describe("BaseMenuItem public methods", () => { // Test BaseMenuItem focus(). describe("focus", () => { - // Test that focus does not call focus() on the link if the parent menu's shouldFoucs is false. - it("should not call focus() on the link if the parent menu's shouldFoucs is false", () => { + // Test that focus does not call focus() on the link if the parent menu's shouldFocus is false. + it("should not call focus() on the link if the parent menu's shouldFocus is false", () => { // Create a new BaseMenu instance for testing. const menu = new BaseMenu({ menuElement: document.querySelector("ul"), @@ -41,8 +41,8 @@ describe("BaseMenuItem public methods", () => { expect(spy).not.toHaveBeenCalled(); }); - // Test that focus calls focus() on the link if the parent menu's shouldFoucs is true. - it("should call focus() on the link if the parent menu's shouldFoucs is true", () => { + // Test that focus calls focus() on the link if the parent menu's shouldFocus is true. + it("should call focus() on the link if the parent menu's shouldFocus is true", () => { // Create a new BaseMenu instance for testing. const menu = new BaseMenu({ menuElement: document.querySelector("ul"), @@ -72,8 +72,8 @@ describe("BaseMenuItem public methods", () => { // Test BaseMenuItem blur(). describe("blur", () => { - // Test that blur does not call blur() on the link if the parent menu's shouldFoucs is false. - it("should not call blur() on the link if the parent menu's shouldFoucs is false", () => { + // Test that blur does not call blur() on the link if the parent menu's shouldFocus is false. + it("should not call blur() on the link if the parent menu's shouldFocus is false", () => { // Create a new BaseMenu instance for testing. const menu = new BaseMenu({ menuElement: document.querySelector("ul"), @@ -99,8 +99,8 @@ describe("BaseMenuItem public methods", () => { expect(spy).not.toHaveBeenCalled(); }); - // Test that blur calls blur() on the link if the parent menu's shouldFoucs is true. - it("should call blur() on the link if the parent menu's shouldFoucs is true", () => { + // Test that blur calls blur() on the link if the parent menu's shouldFocus is true. + it("should call blur() on the link if the parent menu's shouldFocus is true", () => { // Create a new BaseMenu instance for testing. const menu = new BaseMenu({ menuElement: document.querySelector("ul"), diff --git a/tests/menus/_baseMenuToggle/public.test.js b/tests/menus/_baseMenuToggle/public.test.js index ce0a1abd..1134943b 100644 --- a/tests/menus/_baseMenuToggle/public.test.js +++ b/tests/menus/_baseMenuToggle/public.test.js @@ -272,7 +272,7 @@ describe("BaseMenuToggle public methods", () => { }); }); - // Test BaseMenuToggle closeSiblins(). + // Test BaseMenuToggle closeSiblings(). describe("closeSiblings", () => { // Test that closeSiblings calls close() on each sibling toggle. it("should call close() on each sibling toggle", () => { diff --git a/tests/validate/isValidInstance.test.js b/tests/validate/isValidInstance.test.js index 2b0d177f..46fb05da 100644 --- a/tests/validate/isValidInstance.test.js +++ b/tests/validate/isValidInstance.test.js @@ -54,7 +54,7 @@ describe("isValidInstance", () => { expect(result.error).toBeInstanceOf(TypeError); }); - // Test pasing a non-valid constructor. + // Test passing a non-valid constructor. it("should return false when checking for a non-valid constructor", () => { const element = document.createElement("div"); const result = isValidInstance("string", { element }); diff --git a/tests/validate/isValidType.test.js b/tests/validate/isValidType.test.js index 5de82e7d..cfad2226 100644 --- a/tests/validate/isValidType.test.js +++ b/tests/validate/isValidType.test.js @@ -54,7 +54,7 @@ describe("isValidType", () => { expect(result.error).toBeInstanceOf(TypeError); }); - // Test pasing a non-valid type. + // Test passing a non-valid type. it("should return false when checking for a non-valid type", () => { const string = "string"; const result = isValidType(1, { string });