import{r as t,x as s,I as i}from"./p-CklISCW5.js";import{L as r,a as h}from"./p-DttRmuGk.js";class e extends r{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=>{if(0===this.tags.length&&t.length>0)return this.notify(void 0);const s=t.filter((t=>this.tags.includes(t.target.nodeName.toLowerCase()))),i=s.some((t=>Array.from(t.addedNodes).some((t=>this.tags.includes(t.nodeName))))),r=s.some((t=>Array.from(t.removedNodes).some((t=>this.tags.includes(t.nodeName))))),h=s.some((t=>{return"attributes"===t.type&&"styles"!==(s=t.attributeName)&&"class"!==s&&!s.startsWith("data-")&&!s.startsWith("aria-");var s}));return i||h||r?this.notify(void 0):void 0},this.waitAfterFramePrint=t.waitAfterFramePrint||this.waitAfterFramePrint,this.tags=(t.tags||[]).map((t=>t.toLowerCase())),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 a extends h{constructor(t){super((t=>{t.mutationObserverActive&&t.mutationListener()})),this.options=t,this.debouncedNotify=i((()=>this.notify()),50),this.listener=new e(t)}attach(t){var s,i,r;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===(r=this.listener)||void 0===r||r.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:r}=s;s.connectedCallback=function(){return this._balMutationSubject||(this._balMutationSubject=new a(t),this._balMutationSubject.attach(this)),i&&i.call(this)},s.disconnectedCallback=function(){return this._balMutationSubject&&(this._balMutationSubject.detach(),this._balMutationSubject=void 0),r&&r.call(this)}}}export{n as L}