import{e as t,b as s,h as i}from"./p-4f82c566.js";import{L as h,a as e}from"./p-ab217a42.js";class a extends h{constructor(t){super(),this.tags=[],this.waitAfterFramePrint=!1,this.mutationObserver=void 0,this.mutationObserverInit={childList:!0,subtree:!0,attributes:!0,characterData:!0},this.mutationCallback=t=>t.some((t=>this.tags.includes(t.target.nodeName)))||t.some((t=>Array.from(t.removedNodes).some((t=>this.tags.includes(t.nodeName)))))||t.some((t=>"characterData"===t.type))||0===this.tags.length&&t.length>0?this.notify(void 0):void 0,this.waitAfterFramePrint=t.waitAfterFramePrint||this.waitAfterFramePrint,this.tags=(t.tags||[]).map((t=>t.toUpperCase())),this.mutationObserverInit={childList:!1!==t.childList,subtree:!1!==t.subtree,attributes:!1!==t.attributes,characterData:!1!==t.characterData}}async connect(i){super.connect(i),"undefined"!=typeof MutationObserver&&(this.waitAfterFramePrint&&(await t(i),await s()),this.destroyMutationObserver(),this.mutationObserver=new MutationObserver(this.mutationCallback),this.mutationObserver.observe(i,this.mutationObserverInit))}disconnect(){super.disconnect(),this.destroyMutationObserver()}destroyMutationObserver(){void 0!==this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=void 0)}}class r extends e{constructor(t){super((t=>{t.mutationObserverActive&&t.mutationListener()})),this.options=t,this.debouncedNotify=i((()=>this.notify()),50),this.listener=new a(t)}attach(t){var s,i,h;if(super.attach(t),this.options.closest){const i=t.el.closest(this.options.closest);i&&(null===(s=this.listener)||void 0===s||s.connect(i))}else null===(i=this.listener)||void 0===i||i.connect(t.el);null===(h=this.listener)||void 0===h||h.add((()=>this.debouncedNotify()))}detach(){var t;super.detach(),null===(t=this.listener)||void 0===t||t.disconnect()}}function n(t){return function(s){const{connectedCallback:i,disconnectedCallback:h}=s;s.connectedCallback=function(){return this._balMutationSubject||(this._balMutationSubject=new r(t),this._balMutationSubject.attach(this)),i&&i.call(this)},s.disconnectedCallback=function(){return this._balMutationSubject&&(this._balMutationSubject.detach(),this._balMutationSubject=void 0),h&&h.call(this)}}}export{n as L}