!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).AriaModalElement=e()}(this,(function(){"use strict";const t=["dialog","alertdialog"];class e extends HTMLElement{constructor(){var e,o;super(),this.moveFocusToFirst=t=>{const e=t.target;this.focusFirstElement(e,this.props.node)},this.moveFocusToLast=t=>{const e=t.target;this.focusLastElement(e,this.props.node)},this.handleOnKeyup=t=>{27===t.keyCode&&this.props.open&&(this.setAttribute("open","false"),t.stopPropagation())},this.focusAfterClose=null,this.props={open:"true"===this.getAttribute("open"),node:this.getElementByAttribute("node"),firstFocus:this.getElementByAttribute("first-focus"),active:this.getAttribute("active")||"",animation:"true"===this.getAttribute("animation"),duration:Number(this.getAttribute("duration"))||300},this.validateAriaAttrs(["aria-label","aria-labelledby"]),this.validateAriaAttrs(["aria-describedby"]);const i=this.getAttribute("role")||"dialog";if(!t.includes(i))throw new Error(`role attribution is assigned invalid value. assignable value are ${t.join(" or ")}.`);this.getAttribute("aria-modal")||this.setAttribute("aria-modal","true");const n=this.attachShadow({mode:"open"});n.appendChild(this.template().content.cloneNode(!0)),document.addEventListener("keyup",this.handleOnKeyup),null===(e=n.getElementById("first-descendant"))||void 0===e||e.addEventListener("focus",this.moveFocusToLast,!0),null===(o=n.getElementById("last-descendant"))||void 0===o||o.addEventListener("focus",this.moveFocusToFirst,!0)}static get observedAttributes(){return["open"]}attributeChangedCallback(t,e,o){"open"===t&&(this.props.open="true"===o,this.changeStyle(),this.setTabIndex(),this.trapFocus())}disconnectedCallback(){var t,e,o,i;null===(e=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("first-descendant"))||void 0===e||e.addEventListener("focus",this.moveFocusToLast,!0),null===(i=null===(o=this.shadowRoot)||void 0===o?void 0:o.getElementById("last-descendant"))||void 0===i||i.addEventListener("focus",this.moveFocusToFirst,!0)}adoptedCallback(){var t,e,o,i;null===(e=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("first-descendant"))||void 0===e||e.addEventListener("focus",this.moveFocusToLast,!0),null===(i=null===(o=this.shadowRoot)||void 0===o?void 0:o.getElementById("last-descendant"))||void 0===i||i.addEventListener("focus",this.moveFocusToFirst,!0)}trapFocus(){var t;this.props.open?(this.focusAfterClose=document.activeElement,this.props.firstFocus.focus()):null===(t=this.focusAfterClose)||void 0===t||t.focus()}setTabIndex(){var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("slot"),o=null==e?void 0:e.previousElementSibling,i=null==e?void 0:e.nextElementSibling;o&&o.setAttribute("tabindex","0"),i&&i.setAttribute("tabindex","0")}setHideStyle(t){const{node:e,animation:o,duration:i,active:n}=this.props;o?(t.classList.add("hide"),setTimeout(()=>{t.classList.remove("active"),t.classList.remove("hide"),e.classList.remove(n)},i)):(t.classList.remove("active"),e.classList.remove(n))}changeStyle(){var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.getElementById("aria-modal-backdrop");if(!e)throw new Error("Could not find aria-modal-backdrop id");this.props.open?(e.classList.add("active"),this.props.node.classList.add(this.props.active)):this.setHideStyle(e)}template(){const t=document.createElement("template");return document.body.appendChild(t),t.innerHTML=`\n \n