import{L as s,a as t}from"./p-ab217a42.js";import{b as i}from"./p-e680e7e4.js";import{d as c,i as n,j as o,r as h}from"./p-4f82c566.js";class e extends s{constructor(){super(...arguments),this.onFocusin=s=>{this.notify({ev:s,isFocusIn:!0,isFocusOut:!1})},this.onFocusout=async s=>{if(await c(),i.hasDocument&&this.el){const t=document.activeElement;t&&!n(this.el,t)&&this.notify({ev:s,isFocusIn:!1,isFocusOut:!0})}}}connect(s){super.connect(s),this.el&&(o(this.el,"focusin",this.onFocusin),o(this.el,"focusout",this.onFocusout))}disconnect(){super.disconnect(),this.el&&(h(this.el,"focusin",this.onFocusin),h(this.el,"focusout",this.onFocusout))}}class u extends t{constructor(){super(((s,t)=>{t&&(t.isFocusIn&&(!1===s.hasFocus&&s.focusInListener(t.ev),s.hasFocus=!0),t.isFocusOut&&(s.focusOutListener(t.ev),s.hasFocus=!1))})),this.listener=new e}attach(s){super.attach(s),this.listener.connect(s.el),this.listener.add((s=>super.notify(s)))}detach(){super.detach(),this.listener.disconnect()}}function r(){return function(s){const{connectedCallback:t,disconnectedCallback:i}=s;s.connectedCallback=function(){return this._balFocusSubject||(this._balFocusSubject=new u,this._balFocusSubject.attach(this)),t&&t.call(this)},s.disconnectedCallback=function(){return this._balFocusSubject&&(this._balFocusSubject.detach(),this._balFocusSubject=void 0),i&&i.call(this)}}}export{r as L}