import{r as t,i as s,h as i,H as a,e}from"./p-ee1e0eb4.js";const r=class{constructor(i){t(this,i),this.shown=s(this,"shown",7),this.hidden=s(this,"hidden",7),this.theme="dark",this.preventClose=!1,this.focusIndex=0,this.isShowing=!1}async show(){this.$focusedElBeforeOpen=document.activeElement,this.$focusedElBeforeOpen&&this.$focusedElBeforeOpen.setAttribute("aria-expanded","true"),this.isShowing=!0,this.$focusableEls.length>0?setTimeout((()=>this.$focusableEls[0].focus()),100):setTimeout((()=>this.$content.focus()),100),this.shown.emit()}async hide(){this.isShowing=!1,this.focusIndex=0,this.$focusedElBeforeOpen&&(this.$focusedElBeforeOpen.setAttribute("aria-expanded","false"),this.$focusedElBeforeOpen.focus()),this.hidden.emit()}handleKeyDown(t){switch(t.keyCode){case 9:this.handleTab(t);break;case 27:this.handleEsc()}}handleEsc(){this.preventClose||this.hide()}handleTab(t){t.preventDefault(),t.shiftKey?this.handleBackwardTab():this.handleForwardTab()}handleBackwardTab(){this.focusIndex=0===this.focusIndex?this.$focusableEls.length-1:--this.focusIndex,this.$focusableEls[this.focusIndex].focus()}handleForwardTab(){this.focusIndex=this.$focusableEls.length-1===this.focusIndex?0:++this.focusIndex,this.$focusableEls[this.focusIndex].focus()}handleScrimClick(){this.preventClose||this.hide()}componentDidLoad(){this.$focusableEls=Array.from(this.$el.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]'))}render(){return i(a,{class:{"sparkle-overlay":!0,[this.theme]:!0,absolute:this.absolute,opened:this.isShowing}},i("div",{class:"scrim",onClick:()=>this.handleScrimClick()}),i("div",{class:"content",role:"dialog","aria-labelledby":this.titleId,tabindex:"-1",ref:t=>this.$content=t},i("slot",null)))}get $el(){return e(this)}};r.style="sparkle-overlay{--sparkle-z-index-xl:500;--sparkle-transition-fast:0.3s;--sparkle-color-light-base:197, 209, 218;--sparkle-shadow-xl:0 20px 40px rgba(0, 0, 0, 0.2)}.sparkle-overlay{-ms-flex-align:center;align-items:center;display:flex;visibility:hidden;-ms-flex-pack:center;justify-content:center;position:fixed;top:0;left:0;right:0;bottom:0;pointer-events:auto;-ms-touch-action:none;touch-action:none;opacity:0;z-index:var(--sparkle-z-index-xl)}.sparkle-overlay,.sparkle-overlay.opened{-webkit-transition:all var(--sparkle-transition-fast) ease-in-out;transition:all var(--sparkle-transition-fast) ease-in-out}.sparkle-overlay.opened{visibility:visible;opacity:1}.sparkle-overlay.opened .content{-webkit-transition:all var(--sparkle-transition-fast) ease-in-out;transition:all var(--sparkle-transition-fast) ease-in-out}.sparkle-overlay.light{background-color:rgba(var(--sparkle-color-light-base), 0.6)}.sparkle-overlay.dark{background-color:rgba(var(--sparkle-color-dark-base), 0.6)}.sparkle-overlay.absolute{position:absolute}.sparkle-overlay .scrim{border-radius:inherit;height:100%;position:absolute;top:0;bottom:0;left:0;right:0;-webkit-transition:inherit;transition:inherit;width:100%;will-change:opacity}.sparkle-overlay .content{position:relative;outline:none;-webkit-box-shadow:var(--sparkle-shadow-xl);box-shadow:var(--sparkle-shadow-xl);-webkit-transition:all var(--sparkle-transition-fast) ease-in-out;transition:all var(--sparkle-transition-fast) ease-in-out}";export{r as sparkle_overlay}