import{L as s,a as t}from"./p-1d7a7076.js";import{b as i}from"./p-b9dddc6c.js";import{e as c,i as n}from"./p-7c87fba4.js";class o 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&&(this.el.addEventListener("focusin",this.onFocusin),this.el.addEventListener("focusout",this.onFocusout))}disconnect(){super.disconnect(),this.el&&(this.el.removeEventListener("focusin",this.onFocusin),this.el.removeEventListener("focusout",this.onFocusout))}}class h 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 o}attach(s){super.attach(s),this.listener.connect(s.el),this.listener.add((s=>super.notify(s)))}detach(){super.detach(),this.listener.disconnect()}}function u(){return function(s){const{connectedCallback:t,disconnectedCallback:i}=s;s.connectedCallback=function(){return this._balFocusSubject||(this._balFocusSubject=new h,this._balFocusSubject.attach(this)),t&&t.call(this)},s.disconnectedCallback=function(){return this._balFocusSubject&&this._balFocusSubject.detach(),i&&i.call(this)}}}export{u as L}