text: "use strict";class Bartender{constructor(t){"function"!=typeof window.CustomEvent&&(window.CustomEvent=function(t,e){e=e||{bubbles:!1,cancelable:!1,detail:null};var s=document.createEvent("CustomEvent");return s.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),s}),this.options=Object.assign({debug:!1,overlay:!0,closeOnOverlayClick:!0,closeOnEsc:!0,trapFocus:!1,scrollTop:!0,mainWrapSelector:".bartender-main",contentWrapSelector:".bartender-content",focusableElementSelector:'[href], button, input, textarea, select, details, [tabindex]:not([tabindex="-1"])',readyClass:"bartender-ready",openClass:"bartender-open"},t),this.overlay=null,this.currentOpenBar=null,this.previousOpenButton=null,this.resizeTimeout=null,this.bars={},this.openButtons=[],this.closeButtons=[],this.toggleButtons=[],this.pushElements=[],this.validBarPositions=["left","right","top","bottom"],this.validModes=["float","push","reveal"],this.contentWrapMutationObserver=null,this.init()}log(t=""){console.log("Bartender: "+t)}logError(t=""){console.error("Bartender: "+t)}debug(t=""){this.options.debug&&console.log("Bartender debug: "+t)}disableFocus(t=[]){const e=performance.now();let s=0;for(let e=0;e<t.length;e++){let i=t[e];"function"==typeof i.matches&&i.matches(this.options.focusableElementSelector)&&!i.getAttribute("data-bartender-prevtabindex")&&(i.setAttribute("data-bartender-prevtabindex",i.getAttribute("tabindex")),i.setAttribute("tabindex","-1"),s++)}const i=performance.now();s>0&&this.debug("Disabled focus of "+s+" elements in "+(i-e))}enableFocus(t=[]){const e=performance.now();let s=0;for(let e=0;e<t.length;e++){let i=t[e];"null"!=i.getAttribute("data-bartender-prevtabindex")?i.setAttribute("tabindex",i.getAttribute("data-bartender-prevtabindex")):i.removeAttribute("tabindex"),i.removeAttribute("data-bartender-prevtabindex"),s++}const i=performance.now();s>0&&this.debug("Enabled focus of "+s+" elements in "+(i-e))}isValidPosition(t=null){return this.validBarPositions.indexOf(t)>=0}init(){try{if(this.mainWrap=document.querySelector(this.options.mainWrapSelector),!this.mainWrap)throw"Main wrap element was not found with selector: "+this.options.mainWrapSelector;if(this.mainWrap.classList.add("bartender-main"),this.contentWrap=this.mainWrap.querySelector(this.options.contentWrapSelector),!this.contentWrap)throw"Content wrap element was not found with selector: "+this.options.contentWrapSelector;this.contentWrap.classList.add("bartender-content"),this.contentWrap.setAttribute("tabindex","-1"),this.openButtons=this.mainWrap.querySelectorAll("[data-bartender-open]"),this.closeButtons=this.mainWrap.querySelectorAll("[data-bartender-close]"),this.toggleButtons=this.mainWrap.querySelectorAll("[data-bartender-toggle]");const t=this.mainWrap.querySelectorAll("[data-bartender-bar]");for(let e=0;e<t.length;e++)this.addBar(t[e]);for(let t=0;t<this.openButtons.length;t++){let e=this.openButtons[t],s=e.getAttribute("data-bartender-open");if(!this.isValidPosition(s))return void this.logError("Open button has invalid bar position '"+s+"' defined. Use one of the following values: "+this.validBarPositions.join(", "));e.setAttribute("aria-expanded","false"),e.addEventListener("click",(()=>{this.open(s,e)}))}for(let t=0;t<this.toggleButtons.length;t++){let e=this.toggleButtons[t],s=e.getAttribute("data-bartender-toggle");if(!this.isValidPosition(s))return void this.logError("Toggle button has invalid bar position '"+s+"' defined. Use one of the following values: "+this.validBarPositions.join(", "));e.setAttribute("aria-expanded","false"),e.addEventListener("click",(()=>{this.toggle(s,e)}))}for(let t=0;t<this.closeButtons.length;t++){this.closeButtons[t].addEventListener("click",(()=>{this.close()}))}this.pushElements=this.mainWrap.querySelectorAll("[data-bartender-push]"),this.pushElements.length&&this.debug("Registered "+this.pushElements.length+" pushable elements."),this.options.overlay&&!this.overlay&&(this.overlay=document.createElement("div"),this.overlay.classList.add("bartender-overlay"),!0===this.options.closeOnOverlayClick&&this.overlay.addEventListener("click",(()=>this.close())),this.contentWrap.appendChild(this.overlay)),this.options.closeOnEsc&&window.addEventListener("keydown",(t=>{let e=t.key||t.keyCode;"Escape"!==e&&"Esc"!==e&&27!==e||this.close()})),window.addEventListener("resize",(()=>{clearTimeout(this.resizeTimeout),this.resizeTimeout=setTimeout((()=>{this.setPush()}),200)})),!0===this.options.trapFocus&&(this.contentWrapMutationObserver=new MutationObserver((t=>{if(this.currentOpenBar)for(let e=0;e<t.length;e++){let s=t[e];"childList"===s.type&&s.addedNodes&&s.addedNodes.length&&this.disableFocus(s.addedNodes)}})),this.contentWrapMutationObserver.observe(this.contentWrap,{attributes:!1,childList:!0,subtree:!0})),this.mainWrap.classList.add(this.options.readyClass)}catch(t){this.logError(t)}return this}addBar(t=null,e={}){try{let s=!1;null===t&&(s=!0,t=document.createElement("div")),t.style.transition="none";let i=e.position||t.getAttribute("data-bartender-bar"),r=e.mode||t.getAttribute("data-bartender-bar-mode");if(r=r||"float",!this.isValidPosition(i))throw"Invalid bar position '"+i+"'. Use one of the following values: "+this.validBarPositions.join(", ");if(this.validModes.indexOf(r)<0)throw"Invalid mode '"+r+"' for bar '"+i+"'. Use one of the following values: "+this.validModes.join(", ");if(this.bars[i])throw"Bar with position '"+i+"' is already defined";t.setAttribute("tabindex","-1"),t.setAttribute("aria-hidden","true"),this.disableFocus(t.querySelectorAll(this.options.focusableElementSelector)),t.setAttribute("data-bartender-bar",i),t.setAttribute("data-bartender-bar-mode",r),!0===s&&this.mainWrap.appendChild(t),setTimeout((()=>{t.style.transition=null}));const n={element:t,position:i,mode:r,mutationObserver:new MutationObserver((t=>{if(!this.currentOpenBar||this.currentOpenBar.position!==i)for(let e=0;e<t.length;e++){let s=t[e];"childList"===s.type&&s.addedNodes&&s.addedNodes.length&&this.disableFocus(s.addedNodes)}}))};return n.mutationObserver.observe(n.element,{attributes:!1,childList:!0,subtree:!0}),this.bars[i]=n,this.debug("Added bar '"+i+"' with mode '"+r+"'"),n}catch(t){return this.logError(t),null}}removeBar(t=null,e=!0){try{if(this.currentOpenBar&&this.currentOpenBar.position===t&&this.close(),!this.isValidPosition(t))throw"Invalid bar position '"+t+"'. Use one of the following values: "+this.validBarPositions.join(", ");if(!this.bars[t])throw"Bar with position '"+t+"' doesn't exist";!0===e&&this.mainWrap.removeChild(this.bars[t].element),delete this.bars[t],this.debug("Removed bar with position '"+t+"'")}catch(t){this.logError(t)}}open(t="",e=null){try{if(!this.isValidPosition(t))throw"Invalid bar position '"+t+"'. Use one of the following values: "+this.validBarPositions.join(", ");const s=this.bars[t];if(!s)throw"Bar with position '"+t+"' is not defined.";return this.currentOpenBar?this.close(!1):!0===this.options.trapFocus&&this.disableFocus(this.contentWrap.querySelectorAll(this.options.focusableElementSelector)),this.contentWrap.setAttribute("aria-hidden","true"),this.debug("Opening bar '"+t+"'"),this.currentOpenBar=s,s.element.classList.add("bartender-bar--open"),this.options.scrollTop&&(s.element.scrollTop=0),s.element.removeAttribute("aria-hidden"),this.enableFocus(s.element.querySelectorAll("[data-bartender-prevtabindex]")),s.element.focus(),this.setPush(),this.previousOpenButton=e,e&&e.setAttribute("aria-expanded",!0),this.showOverlay(),this.mainWrap.classList.add(this.options.openClass),this.mainWrap.dispatchEvent(new CustomEvent("bartender-open",{bubbles:!0,detail:{bar:s,button:e}})),s}catch(t){this.logError(t)}}toggle(t=null,e=null){try{if(!this.isValidPosition(t))throw"Invalid bar position '"+t+"'. Use one of the following values: "+this.validBarPositions.join(", ");return this.currentOpenBar&&this.currentOpenBar.position==t?this.close():(this.close(),this.open(t,e))}catch(t){this.logError(t)}}close(t=!0){try{if(!this.currentOpenBar)return;let e=this.bars[this.currentOpenBar.position];this.debug("Closing bar '"+e.position+"'"),this.mainWrap.dispatchEvent(new CustomEvent("bartender-close",{bubbles:!0,detail:{bar:e}})),this.hideOverlay(),this.contentWrap.style.removeProperty("transform");for(let t=0;t<this.pushElements.length;t++)this.pushElements[t].style.removeProperty("transform");return this.disableFocus(e.element.querySelectorAll(this.options.focusableElementSelector)),e.element.setAttribute("tabindex","-1"),e.element.setAttribute("aria-hidden","true"),this.contentWrap.removeAttribute("aria-hidden"),!0===this.options.trapFocus&&!0===t&&this.enableFocus(this.contentWrap.querySelectorAll("[data-bartender-prevtabindex]")),e.element.classList.remove("bartender-bar--open"),this.currentOpenBar=null,this.mainWrap.style.removeProperty("overflow"),this.mainWrap.classList.remove(this.options.openClass),this.previousOpenButton&&this.previousOpenButton.getAttribute("tabindex")>=0?(this.previousOpenButton.focus(),this.previousOpenButton.setAttribute("aria-expanded","false"),this.previousOpenButton=null):!0===t&&this.contentWrap.focus(),e}catch(t){this.logError(t)}}setPush(){if(!this.currentOpenBar||!this.currentOpenBar.mode)return;let t=null;switch(this.mainWrap.style.overflow="hidden",this.currentOpenBar.position){case"left":t="translateX("+this.currentOpenBar.element.offsetWidth+"px)";break;case"right":t="translateX(-"+this.currentOpenBar.element.offsetWidth+"px)";break;case"top":t="translateY("+this.currentOpenBar.element.offsetHeight+"px)";break;case"bottom":t="translateY(-"+this.currentOpenBar.element.offsetHeight+"px)"}["push","reveal"].indexOf(this.currentOpenBar.mode)>=0&&(this.contentWrap.style.transform=t);for(let e=0;e<this.pushElements.length;e++)this.pushElements[e].style.transform=t}showOverlay(){this.overlay&&(this.overlay.classList.contains("bartender-overlay--visible")||this.overlay.classList.add("bartender-overlay--visible"))}hideOverlay(){this.overlay&&this.overlay.classList.contains("bartender-overlay--visible")&&this.overlay.classList.remove("bartender-overlay--visible")}}
  //# sourceMappingURL=bartender.min.js.map
  