var AccessibleMenu=function(){"use strict";var e,t,n,r;function o(e){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function l(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&a(e,t)}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function a(e,t){return(a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function m(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function h(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=c(e);if(t){var o=c(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return m(this,n)}}function f(e,t,n){return(f="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=c(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(n):o.value}})(e,t,n||e)}function d(e){return function(e){if(Array.isArray(e))return p(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return p(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return p(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function v(e){var t="element";try{if(e instanceof HTMLElement)return!0;if("object"!==o(e))throw Error;for(var n in e)if(t=n,!(e[n]instanceof HTMLElement))throw Error}catch(e){throw new TypeError("".concat(t," must be an HTML Element."))}}function y(e){E(e);var t="value";try{if("object"===o(e))for(var n in e){if(t=n,"string"!=typeof e[n])throw Error;document.querySelector(e[n])}else document.querySelector(e);return!0}catch(e){throw new TypeError("".concat(t," must be a valid CSS selector."))}}function g(e){var t="value";try{if("boolean"==typeof e)return!0;if("object"!==o(e))throw Error;for(var n in e)if(t=n,"boolean"!=typeof e[n])throw Error}catch(e){throw new TypeError("".concat(t," must be a boolean."))}}function b(e){var t="value";try{if("number"==typeof e)return!0;if("object"!==o(e))throw Error;for(var n in e)if(t=n,"number"!=typeof e[n])throw Error}catch(e){throw new TypeError("".concat(t," must be a number."))}}function E(e){var t="value";try{if("string"==typeof e)return!0;if("object"!==o(e))throw Error;for(var n in e)if(t=n,"string"!=typeof e[n])throw Error}catch(e){throw new TypeError("".concat(t," must be a string."))}}function C(e){var t="element";try{if(e instanceof T)return!0;if("object"!==o(e))throw Error;for(var n in e)if(t=n,!(e[n]instanceof T))throw Error}catch(e){throw new TypeError("".concat(t," must be an instance of either BaseMenu, Menubar, or DisclosureMenu"))}}function M(e,t){return E(e),v(t),void 0!==t["on".concat(e)]}function w(e){var t="value";try{if("string"==typeof e)return!0;if("object"===o(e)){for(var n in e)if(t=n,"string"!=typeof e[n]){if(!Array.isArray(e[n]))throw Error;e[n].forEach((function(e){E(e)}))}}else{if(!Array.isArray(e))throw Error;E(e)}}catch(e){throw new TypeError("".concat(t," must be either a string or an array of strings."))}}Array.from||(Array.from=(e=Object.prototype.toString,t=function(t){return"function"==typeof t||"[object Function]"===e.call(t)},n=Math.pow(2,53)-1,r=function(e){var t=function(e){var t=Number(e);return isNaN(t)?0:0!==t&&isFinite(t)?(t>0?1:-1)*Math.floor(Math.abs(t)):t}(e);return Math.min(Math.max(t,0),n)},function(e){var n=this,o=Object(e);if(null==e)throw new TypeError("Array.from requires an array-like object - not null or undefined");var s,i=arguments.length>1?arguments[1]:void 0;if(void 0!==i){if(!t(i))throw new TypeError("Array.from: when provided, the second argument must be a function");arguments.length>2&&(s=arguments[2])}for(var l,u=r(o.length),c=t(n)?Object(new n(u)):new Array(u),a=0;a<u;)l=o[a],c[a]=i?void 0===s?i(l,a):i.call(s,l,a):l,a+=1;return c.length=u,c})),Array.includes||(Array.prototype.includes=function(e){return!!~this.indexOf(e)}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(e){if(null==this)throw TypeError('"this" is null or not defined');var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw TypeError("predicate must be a function");for(var r=arguments[1],o=0;o<n;){var s=t[o];if(e.call(r,s,o,t))return s;o++}},configurable:!0,writable:!0}),String.prototype.startsWith||Object.defineProperty(String.prototype,"startsWith",{value:function(e,t){var n=t>0?0|t:0;return this.substring(n,n+e.length)===e}}),String.prototype.endsWith||(String.prototype.endsWith=function(e,t){return(void 0===t||t>this.length)&&(t=this.length),this.substring(t-e.length,t)===e});var S=function(){function e(t){var n=t.menuToggleElement,r=t.parentElement,o=t.controlledMenu,i=t.openClass,l=void 0===i?"show":i,u=t.closeClass,c=void 0===u?"hide":u,a=t.parentMenu,m=void 0===a?null:a;s(this,e),v({menuToggleElement:n,parentElement:r}),C(null!==m?{controlledMenu:o,parentMenu:m}:{controlledMenu:o}),this.domElements={toggle:n,parent:r},this.menuElements={controlledMenu:o,parentMenu:m},this.openClass=l||"",this.closeClass=c||"",this.isOpen=!1,this.expandEvent=new CustomEvent("accessibleMenuExpand",{bubbles:!0,detail:{toggle:this}}),this.collapseEvent=new CustomEvent("accessibleMenuCollapse",{bubbles:!0,detail:{toggle:this}}),this.initialize()}return l(e,[{key:"initialize",value:function(){var e=this;if(this.dom.toggle.setAttribute("aria-haspopup","true"),this.dom.toggle.setAttribute("aria-expanded","false"),function(e,t){E(e),v(t);var n=e.toLowerCase();if(t instanceof HTMLElement)return t.tagName.toLowerCase()===n;var r=!0;for(var o in t)t[o].tagName.toLowerCase()!==n&&(r=!1);return r}("button",this.dom.toggle)||this.dom.toggle.setAttribute("role","button"),""===this.dom.toggle.id||""===this.elements.controlledMenu.dom.menu.id){var t=Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,10),n=this.dom.toggle.innerText.replace(/[^a-zA-Z0-9\s]/g,""),r=t;!n.replace(/\s/g,"").length&&this.dom.toggle.getAttribute("aria-label")&&(n=this.dom.toggle.getAttribute("aria-label").replace(/[^a-zA-Z0-9\s]/g,"")),n.replace(/\s/g,"").length>0&&((n=n.toLowerCase().replace(/\s+/g,"-")).startsWith("-")&&(n=n.substring(1)),n.endsWith("-")&&(n=n.slice(0,-1)),r="".concat(n,"-").concat(r)),this.dom.toggle.id=this.dom.toggle.id||"".concat(r,"-menu-button"),this.elements.controlledMenu.dom.menu.id=this.elements.controlledMenu.dom.menu.id||"".concat(r,"-menu")}this.elements.controlledMenu.dom.menu.setAttribute("aria-labelledby",this.dom.toggle.id),this.dom.toggle.setAttribute("aria-controls",this.elements.controlledMenu.dom.menu.id),""!==this.closeClass&&("string"==typeof this.closeClass?this.elements.controlledMenu.dom.menu.classList.add(this.closeClass):Array.isArray(this.closeClass)&&this.closeClass.forEach((function(t){e.elements.controlledMenu.dom.menu.classList.add(t)})))}},{key:"expand",value:function(){var e=this;this.dom.toggle.setAttribute("aria-expanded","true"),""!==this.openClass&&("string"==typeof this.openClass?this.elements.controlledMenu.dom.menu.classList.add(this.openClass):Array.isArray(this.openClass)&&this.openClass.forEach((function(t){e.elements.controlledMenu.dom.menu.classList.add(t)}))),""!==this.closeClass&&("string"==typeof this.closeClass?this.elements.controlledMenu.dom.menu.classList.remove(this.closeClass):Array.isArray(this.closeClass)&&this.closeClass.forEach((function(t){e.elements.controlledMenu.dom.menu.classList.remove(t)}))),this.dom.toggle.dispatchEvent(this.expandEvent)}},{key:"collapse",value:function(){var e=this;this.dom.toggle.setAttribute("aria-expanded","false"),""!==this.closeClass&&("string"==typeof this.closeClass?this.elements.controlledMenu.dom.menu.classList.add(this.closeClass):Array.isArray(this.closeClass)&&this.closeClass.forEach((function(t){e.elements.controlledMenu.dom.menu.classList.add(t)}))),""!==this.openClass&&("string"==typeof this.openClass?this.elements.controlledMenu.dom.menu.classList.remove(this.openClass):Array.isArray(this.openClass)&&this.openClass.forEach((function(t){e.elements.controlledMenu.dom.menu.classList.remove(t)}))),this.dom.toggle.dispatchEvent(this.collapseEvent)}},{key:"open",value:function(){this.isOpen=!0,this.expand(),this.closeSiblings(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="child"),this.elements.controlledMenu.focusState="self"}},{key:"preview",value:function(){this.isOpen=!0,this.expand(),this.closeSiblings(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"),this.elements.controlledMenu.focusState="none"}},{key:"close",value:function(){this.isOpen&&(this.isOpen=!1,this.collapse(),this.closeChildren(),this.elements.controlledMenu.currentChild=0,this.elements.controlledMenu.blur(),this.elements.parentMenu&&(this.elements.parentMenu.focusState="self"))}},{key:"toggle",value:function(){this.isOpen?this.close():this.open()}},{key:"closeSiblings",value:function(){var e=this;this.elements.parentMenu&&this.elements.parentMenu.elements.submenuToggles.forEach((function(t){t!==e&&t.close()}))}},{key:"closeChildren",value:function(){this.elements.controlledMenu.elements.submenuToggles.forEach((function(e){return e.close()}))}},{key:"dom",get:function(){return this.domElements}},{key:"elements",get:function(){return this.menuElements}},{key:"isOpen",get:function(){return this.show},set:function(e){g({value:e}),this.show=e}},{key:"openClass",get:function(){return this.controlledMenuOpenClass},set:function(e){w({openClass:e}),this.controlledMenuOpenClass=e}},{key:"closeClass",get:function(){return this.controlledMenuCloseClass},set:function(e){w({closeClass:e}),this.controlledMenuCloseClass=e}}]),e}(),k=function(){function e(t){var n=t.menuItemElement,r=t.menuLinkElement,i=t.parentMenu,l=t.isSubmenuItem,u=void 0!==l&&l,c=t.childMenu,a=void 0===c?null:c,m=t.toggle,h=void 0===m?null:m;s(this,e),v({menuItemElement:n,menuLinkElement:r}),g({isSubmenuItem:u}),C(null!==a?{parentMenu:i,childMenu:a}:{parentMenu:i}),null!==h&&function(e){var t="element";try{if(e instanceof S)return!0;if("object"!==o(e)||e instanceof S)throw Error;for(var n in e)if(t=n,!(e[n]instanceof S))throw Error}catch(e){throw new TypeError("".concat(t," must be a MenuToggle."))}}({toggle:h}),this.domElements={item:n,link:r},this.menuElements={parentMenu:i,childMenu:a,toggle:h},this.isController=u,this.initialize()}return l(e,[{key:"initialize",value:function(){this.isMenubar=this.elements.parentMenu instanceof L,this.isMenubar&&(this.dom.item.setAttribute("role","none"),this.dom.link.setAttribute("role","menuitem"),this.dom.link.tabIndex=-1)}},{key:"focus",value:function(){"mouse"!==this.elements.parentMenu.currentEvent&&this.dom.link.focus(),this.isMenubar&&this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=0)}},{key:"blur",value:function(){"mouse"!==this.elements.parentMenu.currentEvent&&this.dom.link.blur(),this.isMenubar&&this.elements.parentMenu.isTopLevel&&(this.dom.link.tabIndex=-1)}},{key:"dom",get:function(){return this.domElements}},{key:"elements",get:function(){return this.menuElements}},{key:"isSubmenuItem",get:function(){return this.isController}}]),e}();function I(e){!function(e){var t="event";try{if(e instanceof KeyboardEvent)return!0;if("object"!==o(e))throw Error;for(var n in e)if(t=n,!(e[n]instanceof KeyboardEvent))throw Error}catch(e){throw new TypeError("".concat(t," must be a KeyboardEvent."))}}(e);try{var t=e.key||e.keyCode,n={Enter:"Enter"===t||13===t,Space:" "===t||"Spacebar"===t||32===t,Escape:"Escape"===t||"Esc"===t||27===t,ArrowUp:"ArrowUp"===t||"Up"===t||38===t,ArrowRight:"ArrowRight"===t||"Right"===t||39===t,ArrowDown:"ArrowDown"===t||"Down"===t||40===t,ArrowLeft:"ArrowLeft"===t||"Left"===t||37===t,Home:"Home"===t||36===t,End:"End"===t||35===t,Character:!!t.match(/^[a-zA-Z]{1}$/),Tab:"Tab"===t||9===t};return Object.keys(n).find((function(e){return!0===n[e]}))}catch(e){return""}}function A(e){!function(e){var t="event";try{if(e instanceof Event)return!0;if("object"!==o(e))throw Error;for(var n in e)if(t=n,!(e[n]instanceof Event))throw Error}catch(e){throw new TypeError("".concat(t," must be an Event."))}}(e),e.preventDefault(),e.stopPropagation()}var T=function(){function e(t){var n=t.menuElement,r=t.menuItemSelector,o=void 0===r?"li":r,i=t.menuLinkSelector,l=void 0===i?"a":i,u=t.submenuItemSelector,c=void 0===u?"":u,a=t.submenuToggleSelector,m=void 0===a?"a":a,h=t.submenuSelector,f=void 0===h?"ul":h,d=t.controllerElement,p=void 0===d?null:d,b=t.containerElement,E=void 0===b?null:b,M=t.openClass,w=void 0===M?"show":M,S=t.closeClass,k=void 0===S?"hide":S,I=t.isTopLevel,A=void 0===I||I,T=t.parentMenu,L=void 0===T?null:T,O=t.isHoverable,j=void 0!==O&&O,D=t.hoverDelay,H=void 0===D?250:D;s(this,e),g({isTopLevel:A}),y(""!==c?{menuItemSelector:o,menuLinkSelector:l,submenuItemSelector:c,submenuToggleSelector:m,submenuSelector:f}:{menuItemSelector:o,menuLinkSelector:l}),v(null!==p||null!==E?{menuElement:n,controllerElement:p,containerElement:E}:{menuElement:n}),null!==L&&C({parentMenu:L}),this.domElements={menu:n,menuItems:[],submenuItems:[],submenuToggles:[],submenus:[],controller:p,container:E},this.domSelectors={menuItems:o,menuLinks:l,submenuItems:c,submenuToggles:m,submenus:f},this.menuElements={menuItems:[],submenuToggles:[],controller:null,parentMenu:L,rootMenu:A?this:null},this.openClass=w||"",this.closeClass=k||"",this.root=A,this.currentChild=0,this.focusState="none",this.currentEvent="none",this.isHoverable=j,this.hoverDelay=H,this.initialize()}return l(e,[{key:"initialize",value:function(){if(null===this.elements.rootMenu&&this.findRootMenu(this),this.setDOMElements(),this.isTopLevel&&this.dom.controller&&this.dom.container){var e=new S({menuToggleElement:this.dom.controller,parentElement:this.dom.container,controlledMenu:this,openClass:this.openClass,closeClass:this.closeClass});this.menuElements.controller=e}}},{key:"setDOMElementType",value:function(e,t,n){if("string"!=typeof this.selectors[e])throw new Error("".concat(e," is not a valid element type within the menu."));t&&v({base:t});var r=t||this.dom.menu,o=this.selectors[e],s=Array.from(r.querySelectorAll(o));this.domElements[e]=void 0!==n?"function"==typeof n?s.filter((function(e){return n(e)})):s:s.filter((function(e){return function(e){return e.parentElement===r}(e)}))}},{key:"addDOMElementType",value:function(e,t,n){if("string"!=typeof this.selectors[e])throw new Error("".concat(e," is not a valid element type within the menu."));t&&v({base:t});var r=t||this.dom.menu,o=this.selectors[e],s=Array.from(r.querySelectorAll(o));this.domElements[e]=[].concat(d(this.domElements[e]),d(void 0!==n?"function"==typeof n?s.filter((function(e){return n(e)})):s:s.filter((function(e){return function(e){return e.parentElement===r}(e)}))))}},{key:"clearDOMElementType",value:function(e){if("menu"!==e)if(Array.isArray(this.domElements[e]))this.domElements[e]=[];else{if(void 0===this.domElements[e])throw new Error("".concat(e," is not a valid element type within the menu."));this.domElements[e]=null}}},{key:"setDOMElements",value:function(){var e=this;this.setDOMElementType("menuItems"),""!==this.selectors.submenuItems&&(this.setDOMElementType("submenuItems"),this.clearDOMElementType("submenuToggles"),this.clearDOMElementType("submenus"),this.dom.submenuItems.forEach((function(t){e.addDOMElementType("submenuToggles",t),e.addDOMElementType("submenus",t)})))}},{key:"findRootMenu",value:function(e){if(e.isTopLevel)this.menuElements.rootMenu=e;else{if(null===e.elements.parentMenu)throw new Error("Cannot find root menu.");this.findRootMenu(e.elements.parentMenu)}}},{key:"createChildElements",value:function(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e;this.dom.menuItems.forEach((function(e){var r;if(t.dom.submenuItems.includes(e)){var o=e.querySelector(t.selectors.submenuToggles),s=e.querySelector(t.selectors.submenus),i=new n({menuElement:s,menuItemSelector:t.selectors.menuItems,menuLinkSelector:t.selectors.menuLinks,submenuItemSelector:t.selectors.submenuItems,submenuToggleSelector:t.selectors.submenuToggles,submenuSelector:t.selectors.submenus,openClass:t.openClass,closeClass:t.closeClass,isTopLevel:!1,parentMenu:t,isHoverable:t.isHoverable,hoverDelay:t.hoverDelay}),l=new S({menuToggleElement:o,parentElement:e,controlledMenu:i,openClass:t.openClass,closeClass:t.closeClass,parentMenu:t});t.menuElements.submenuToggles.push(l),r=new k({menuItemElement:e,menuLinkElement:o,parentMenu:t,isSubmenuItem:!0,childMenu:i,toggle:l})}else{var u=e.querySelector(t.selectors.menuLinks);r=new k({menuItemElement:e,menuLinkElement:u,parentMenu:t})}t.menuElements.menuItems.push(r)}))}},{key:"handleFocus",value:function(){var e=this;this.elements.menuItems.forEach((function(t,n){t.dom.link.addEventListener("focus",(function(){e.elements.parentMenu&&(e.elements.parentMenu.focusState="child"),t.elements.childMenu&&(t.elements.childMenu.focusState="none"),e.focusState="self",e.currentChild=n}))}))}},{key:"handleClick",value:function(){var e=this;function t(e,t,n){A(n),e.currentEvent="mouse",t.toggle(),t.isOpen&&(e.focusState="self",t.elements.controlledMenu.focusState="none")}document.addEventListener("mouseup",(function(t){"none"!==e.focusState&&(e.currentEvent="mouse",e.dom.menu.contains(t.target)||!e.dom.menu===t.target||(e.closeChildren(),e.blur(),e.elements.controller&&e.elements.controller.close()))})),this.elements.submenuToggles.forEach((function(n){M("touchend",n.dom.toggle)?n.dom.toggle.ontouchend=function(r){t(e,n,r)}:n.dom.toggle.onmouseup=function(r){t(e,n,r)}})),this.isTopLevel&&this.elements.controller&&(M("touchend",this.elements.controller.dom.toggle)?this.elements.controller.dom.toggle.ontouchend=function(n){t(e,e.elements.controller,n)}:this.elements.controller.dom.toggle.onmouseup=function(n){t(e,e.elements.controller,n)})}},{key:"handleHover",value:function(){var e=this;this.elements.submenuToggles.forEach((function(t){t.dom.parent.addEventListener("mouseenter",(function(){e.isHoverable&&(e.currentEvent="mouse",t.open())})),t.dom.parent.addEventListener("mouseleave",(function(){e.isHoverable&&setTimeout((function(){e.currentEvent="mouse",t.close()}),e.hoverDelay)}))}))}},{key:"handleKeydown",value:function(){var e=this;this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keydown",(function(t){e.currentEvent="keyboard";var n=I(t);"Space"!==n&&"Enter"!==n||A(t)}))}},{key:"handleKeyup",value:function(){var e=this;this.isTopLevel&&this.elements.controller&&this.elements.controller.dom.toggle.addEventListener("keyup",(function(t){e.currentEvent="keyboard";var n=I(t);"Space"!==n&&"Enter"!==n||(A(t),e.elements.controller.open(),e.focusFirstChild())}))}},{key:"focus",value:function(){this.focusState="self","mouse"!==this.currentEvent&&this.dom.menu.focus()}},{key:"blur",value:function(){this.focusState="none","mouse"!==this.currentEvent&&this.dom.menu.blur(),this.isTopLevel&&this.elements.controller&&this.elements.controller.close()}},{key:"focusFirstChild",value:function(){this.blurCurrentChild(),this.currentChild=0,this.focusCurrentChild()}},{key:"focusLastChild",value:function(){this.blurCurrentChild(),this.currentChild=this.elements.menuItems.length-1,this.focusCurrentChild()}},{key:"focusNextChild",value:function(){this.currentChild===this.elements.menuItems.length-1?this.focusFirstChild():(this.blurCurrentChild(),this.currentChild=this.currentChild+1,this.focusCurrentChild())}},{key:"focusPreviousChild",value:function(){0===this.currentChild?this.focusLastChild():(this.blurCurrentChild(),this.currentChild=this.currentChild-1,this.focusCurrentChild())}},{key:"focusCurrentChild",value:function(){-1!==this.currentChild&&this.currentMenuItem.focus()}},{key:"blurCurrentChild",value:function(){-1!==this.currentChild&&this.currentMenuItem.blur()}},{key:"focusNextChildWithCharacter",value:function(e){for(var t=e.toLowerCase(),n=this.currentChild+1,r=!1;!r&&n<this.elements.menuItems.length;){this.elements.menuItems[n].dom.item.innerText.toLowerCase().startsWith(t)&&(r=!0,this.currentChild=n,this.focusCurrentChild()),n++}}},{key:"focusController",value:function(){this.dom.controller&&("mouse"!==this.currentEvent&&this.dom.controller.focus(),this.focusState="none")}},{key:"focusContainer",value:function(){this.dom.container&&("mouse"!==this.currentEvent&&this.dom.container.focus(),this.focusState="none")}},{key:"closeChildren",value:function(){this.elements.submenuToggles.forEach((function(e){return e.close()}))}},{key:"dom",get:function(){return this.domElements}},{key:"selectors",get:function(){return this.domSelectors}},{key:"elements",get:function(){return this.menuElements}},{key:"openClass",get:function(){return this.submenuOpenClass},set:function(e){w({openClass:e}),this.submenuOpenClass=e}},{key:"closeClass",get:function(){return this.submenuCloseClass},set:function(e){w({closeClass:e}),this.submenuCloseClass=e}},{key:"isTopLevel",get:function(){return this.root}},{key:"currentChild",get:function(){return this.focussedChild},set:function(e){b({value:e}),this.focussedChild=e}},{key:"focusState",get:function(){return this.state},set:function(e){!function(e){E(e);var t=["none","self","child"],n="value";try{if("object"!==o(e)){if(t.includes(e))return!0;throw Error}for(var r in e)if(n=r,!t.includes(e[r]))throw Error}catch(e){throw new Error("".concat(n," must be one of the following values: ").concat(t.join(", ")))}}({value:e}),this.state=e}},{key:"currentEvent",get:function(){return this.event},set:function(e){!function(e){E(e);var t=["none","mouse","keyboard"],n="value";try{if("object"!==o(e)){if(t.includes(e))return!0;throw Error}for(var r in e)if(n=r,!t.includes(e[r]))throw Error}catch(e){throw new Error("".concat(n," must be one of the following values: ").concat(t.join(", ")))}}({value:e}),this.event=e}},{key:"currentMenuItem",get:function(){return this.elements.menuItems[this.currentChild]}},{key:"isHoverable",get:function(){return this.hoverable},set:function(e){g({value:e}),this.hoverable=e}},{key:"hoverDelay",get:function(){return this.delay},set:function(e){b({value:e}),this.delay=e}}]),e}(),L=function(e){u(n,e);var t=h(n);function n(e){var r=e.menuElement,o=e.menuItemSelector,i=void 0===o?"li":o,l=e.menuLinkSelector,u=void 0===l?"a":l,c=e.submenuItemSelector,a=void 0===c?"":c,m=e.submenuToggleSelector,h=void 0===m?"a":m,f=e.submenuSelector,d=void 0===f?"ul":f,p=e.controllerElement,v=void 0===p?null:p,y=e.containerElement,g=void 0===y?null:y,b=e.openClass,E=void 0===b?"show":b,C=e.closeClass,M=void 0===C?"hide":C,w=e.isTopLevel,S=void 0===w||w,k=e.parentMenu,I=void 0===k?null:k,A=e.isHoverable,T=void 0!==A&&A,L=e.hoverDelay,O=void 0===L?250:L;return s(this,n),t.call(this,{menuElement:r,menuItemSelector:i,menuLinkSelector:u,submenuItemSelector:a,submenuToggleSelector:h,submenuSelector:d,controllerElement:v,containerElement:g,openClass:E,closeClass:M,isTopLevel:S,parentMenu:I,isHoverable:T,hoverDelay:O})}return l(n,[{key:"initialize",value:function(){f(c(n.prototype),"initialize",this).call(this),this.dom.menu.setAttribute("role","menubar"),this.createChildElements(n),this.handleFocus(),this.handleClick(),this.isHoverable&&this.handleHover(),this.handleKeydown(),this.handleKeyup(),this.elements.menuItems[0].dom.link.tabIndex=0}},{key:"handleKeydown",value:function(){var e=this;f(c(n.prototype),"handleKeydown",this).call(this),this.dom.menu.addEventListener("keydown",(function(t){e.currentEvent="keyboard";var n=I(t);if("Tab"===n&&("none"!==e.elements.rootMenu.focusState?(e.elements.rootMenu.blur(),e.elements.rootMenu.closeChildren()):e.elements.rootMenu.focus()),"Character"===n)A(t);else if(e.isTopLevel){if("self"===e.focusState){(["ArrowRight","ArrowLeft","Home","End"].includes(n)||e.currentMenuItem.isSubmenuItem&&["Space","Enter","ArrowDown","ArrowUp"].includes(n)||e.elements.controller&&["Escape"].includes(n))&&A(t)}}else{(["Escape","ArrowRight","ArrowLeft","ArrowDown","ArrowUp","Home","End"].includes(n)||e.currentMenuItem.isSubmenuItem&&["Space","Enter"].includes(n))&&A(t)}}))}},{key:"handleKeyup",value:function(){var e=this;f(c(n.prototype),"handleKeyup",this).call(this),this.dom.menu.addEventListener("keyup",(function(t){e.currentEvent="keyboard";var n=I(t),r=t.altKey,o=t.crtlKey,s=t.metaKey;if("Character"!==n||(r||o||s))if(e.isTopLevel){if("self"===e.focusState)if("Space"===n||"Enter"===n)e.currentMenuItem.isSubmenuItem&&(A(t),e.currentMenuItem.elements.toggle.open(),e.currentMenuItem.elements.childMenu.focusFirstChild());else if("ArrowRight"===n){A(t);var i=e.currentMenuItem.isSubmenuItem&&e.currentMenuItem.elements.toggle.isOpen;e.focusNextChild(),i&&(e.currentMenuItem.isSubmenuItem?e.currentMenuItem.elements.toggle.preview():e.closeChildren())}else if("ArrowLeft"===n){A(t);var l=e.currentMenuItem.isSubmenuItem&&e.currentMenuItem.elements.toggle.isOpen;e.focusPreviousChild(),l&&(e.currentMenuItem.isSubmenuItem?e.currentMenuItem.elements.toggle.preview():e.closeChildren())}else if("ArrowDown"===n)e.currentMenuItem.isSubmenuItem&&(A(t),e.currentMenuItem.elements.toggle.open(),e.currentMenuItem.elements.childMenu.focusFirstChild());else if("ArrowUp"===n)e.currentMenuItem.isSubmenuItem&&(A(t),e.currentMenuItem.elements.toggle.open(),e.currentMenuItem.elements.childMenu.focusLastChild());else if("Home"===n)A(t),e.focusFirstChild();else if("End"===n)A(t),e.focusLastChild();else if("Escape"===n){e.elements.submenuToggles.some((function(e){return e.isOpen}))?(A(t),e.closeChildren()):e.isTopLevel&&e.elements.controller&&e.elements.controller.isOpen&&(A(t),e.elements.controller.close(),e.focusController())}}else"Space"===n||"Enter"===n?e.currentMenuItem.isSubmenuItem&&(A(t),e.currentMenuItem.elements.toggle.open(),e.currentMenuItem.elements.childMenu.focusFirstChild()):"Escape"===n?(A(t),e.elements.rootMenu.closeChildren(),e.elements.rootMenu.focusCurrentChild()):"ArrowRight"===n?e.currentMenuItem.isSubmenuItem?(A(t),e.currentMenuItem.elements.toggle.open(),e.currentMenuItem.elements.childMenu.focusFirstChild()):(A(t),e.elements.rootMenu.closeChildren(),e.elements.rootMenu.focusNextChild(),e.elements.rootMenu.currentMenuItem.isSubmenuItem&&e.elements.rootMenu.currentMenuItem.elements.toggle.preview()):"ArrowLeft"===n?e.elements.parentMenu.currentMenuItem.isSubmenuItem&&(A(t),e.elements.parentMenu.currentMenuItem.elements.toggle.close(),e.elements.parentMenu.focusCurrentChild(),e.elements.parentMenu===e.elements.rootMenu&&(e.elements.rootMenu.closeChildren(),e.elements.rootMenu.focusPreviousChild(),e.elements.rootMenu.currentMenuItem.isSubmenuItem&&e.elements.rootMenu.currentMenuItem.elements.toggle.preview())):"ArrowDown"===n?(A(t),e.focusNextChild()):"ArrowUp"===n?(A(t),e.focusPreviousChild()):"Home"===n?(A(t),e.focusFirstChild()):"End"===n&&(A(t),e.focusLastChild());else A(t),e.focusNextChildWithCharacter(t.key)}))}}]),n}(T);return{Menubar:L,DisclosureMenu:function(e){u(n,e);var t=h(n);function n(e){var r,o=e.menuElement,i=e.menuItemSelector,l=void 0===i?"li":i,u=e.menuLinkSelector,c=void 0===u?"a":u,a=e.submenuItemSelector,m=void 0===a?"":a,h=e.submenuToggleSelector,f=void 0===h?"a":h,d=e.submenuSelector,p=void 0===d?"ul":d,v=e.controllerElement,y=void 0===v?null:v,g=e.containerElement,b=void 0===g?null:g,E=e.openClass,C=void 0===E?"show":E,M=e.closeClass,w=void 0===M?"hide":M,S=e.isTopLevel,k=void 0===S||S,I=e.parentMenu,A=void 0===I?null:I,T=e.isHoverable,L=void 0!==T&&T,O=e.hoverDelay,j=void 0===O?250:O;return s(this,n),(r=t.call(this,{menuElement:o,menuItemSelector:l,menuLinkSelector:c,submenuItemSelector:m,submenuToggleSelector:f,submenuSelector:p,controllerElement:y,containerElement:b,openClass:C,closeClass:w,isTopLevel:k,parentMenu:A,isHoverable:L,hoverDelay:j})).currentChild=-1,r}return l(n,[{key:"initialize",value:function(){f(c(n.prototype),"initialize",this).call(this),this.createChildElements(n),this.handleFocus(),this.handleClick(),this.isHoverable&&this.handleHover(),this.handleKeydown(),this.handleKeyup()}},{key:"handleKeydown",value:function(){var e=this;f(c(n.prototype),"handleKeydown",this).call(this),this.dom.menu.addEventListener("keydown",(function(t){e.currentEvent="keyboard";var n=I(t);if("self"===e.focusState){(["ArrowUp","ArrowRight","ArrowDown","ArrowLeft","Home","End"].includes(n)||e.currentMenuItem.isSubmenuItem&&["Space","Enter"].includes(n)||e.elements.controller&&["Escape"].includes(n)||e.elements.parentMenu&&["Escape"].includes(n))&&A(t)}}))}},{key:"handleKeyup",value:function(){var e=this;f(c(n.prototype),"handleKeyup",this).call(this),this.dom.menu.addEventListener("keyup",(function(t){e.currentEvent="keyboard";var n=I(t);if("self"===e.focusState)if("Space"===n||"Enter"===n)e.currentMenuItem.isSubmenuItem&&(A(t),e.currentMenuItem.elements.toggle.preview());else if("Escape"===n){e.elements.submenuToggles.some((function(e){return e.isOpen}))?(A(t),e.closeChildren()):e.elements.parentMenu?(A(t),e.elements.parentMenu.closeChildren(),e.elements.parentMenu.focusCurrentChild()):e.isTopLevel&&e.elements.controller&&e.elements.controller.isOpen&&(e.elements.controller.close(),e.focusController())}else"ArrowDown"===n||"ArrowRight"===n?(A(t),e.currentMenuItem.isSubmenuItem&&e.currentMenuItem.elements.toggle.isOpen?e.currentMenuItem.elements.childMenu.focusFirstChild():e.focusNextChild()):"ArrowUp"===n||"ArrowLeft"===n?(A(t),e.focusPreviousChild()):"Home"===n?(A(t),e.focusFirstChild()):"End"===n&&(A(t),e.focusLastChild())}))}},{key:"focusNextChild",value:function(){this.currentChild<this.elements.menuItems.length-1&&(this.blurCurrentChild(),this.currentChild=this.currentChild+1,this.focusCurrentChild())}},{key:"focusPreviousChild",value:function(){this.currentChild>0&&(this.blurCurrentChild(),this.currentChild=this.currentChild-1,this.focusCurrentChild())}}]),n}(T)}}();
