class a{constructor(e,s={}){if(this.target=null,this.drawer=null,this.toggle=null,this.transition=500,this.dismisses=null,this.options={keyboard:!0,backdrop:!0,...s},this.documentOnKeydown=t=>this.hideOnKeydown({e:t,drawer:this}),typeof e=="string")this.target=document.querySelector(e);else if(e instanceof HTMLElement)this.target=e;else throw new Error("No target element found");this.target.classList.contains("drawer")?this.drawer=this.target:(this.toggle=this.target,this.drawer=document.querySelector(this.toggle.dataset.target),this.toggle.addEventListener("click",()=>{const t=document.querySelectorAll(".drawer.show");t.length?[...t].forEach(i=>this.hide(i)):this.show()})),this.dismisses=this.drawer.querySelectorAll('[data-dismiss="drawer"]'),this.dismisses.length&&[...this.dismisses].forEach(t=>{t.addEventListener("click",()=>this.hide())})}show(e=null){const s=e||this.drawer;s.classList.contains("showing")||(s.classList.add("showing"),this.options.backdrop&&document.body.appendChild(this.createBackdrop()),setTimeout(()=>{const t=document.querySelector(".drawer-backdrop");s.classList.replace("showing","show"),t&&(t.classList.add("show"),t.addEventListener("click",()=>{this.options.backdrop!=="static"&&this.hide()})),this.options.keyboard&&document.addEventListener("keydown",this.documentOnKeydown)},15))}hide(e=null){const s=e||this.drawer;if(s.classList.contains("show")&&!s.classList.contains("hiding")){const t=document.querySelector(".drawer-backdrop");s.classList.add("hiding"),t&&t.classList.remove("show"),setTimeout(()=>{s.classList.remove("show"),s.classList.remove("hiding"),t&&t.remove(),this.options.keyboard&&document.removeEventListener("keydown",this.documentOnKeydown)},this.transition)}}hideOnKeydown(e){const{e:s,drawer:t}=e;s.key==="Escape"&&t.options.keyboard&&t.hide()}createBackdrop(){document.querySelector(".drawer-backdrop")&&document.querySelector(".drawer-backdrop").remove();const e=document.createElement("div");return e.setAttribute("class","drawer-backdrop"),e}}const d={init(){const r=this.querySelectors('[data-toggle="drawer"]');r.length&&r.forEach(e=>{const s=e.dataset.target;if(s){const t=document.querySelector(s),i={keyboard:t.dataset.keyboard!=="false",backdrop:(()=>{let o=!0;return t.dataset.backdrop==="static"&&(o="static"),t.dataset.backdrop==="false"&&(o=!1),o})()};new a(e,i)}})},querySelectors(r){let e=[];return r&&(e=[...document.querySelectorAll(r)].filter(s=>!s.parentElement.classList.contains("code-viewer-source"))),e},of(r,e={}){return new a(r,e)}};export{d};
