import{__extends}from"tslib";import{L as ListenerAbstract,a as SingleSubject}from"./listener-8c6f024a.js";import{b as balBrowser}from"./browser-216e7b03.js";import{d as debounce}from"./helpers-008ae2b8.js";var BalResizeListener=function(e){__extends(t,e);function t(){var t=e.apply(this,arguments)||this;t.debouncedNotify=debounce((function(){return t.notify()}),10);return t}t.prototype.connect=function(t){var i=this;var n;e.prototype.connect.call(this,t);if(typeof ResizeObserver==="undefined"){return}if(this.resizeObserver!==undefined){(n=this.resizeObserver)===null||n===void 0?void 0:n.disconnect();this.resizeObserver=undefined}this.resizeObserver=new ResizeObserver((function(e){if(balBrowser.hasWindow){window.requestAnimationFrame((function(){if(!Array.isArray(e)||!e.length){return}i.debouncedNotify()}))}}));this.resizeObserver.observe(t)};t.prototype.disconnect=function(){var t;e.prototype.disconnect.call(this);(t=this.resizeObserver)===null||t===void 0?void 0:t.disconnect();this.resizeObserver=undefined};return t}(ListenerAbstract);var BalResizeSubject=function(e){__extends(t,e);function t(){var t=e.call(this,(function(e,t){e.resizeListener({})}))||this;t.listener=new BalResizeListener;return t}t.prototype.attach=function(t){var i=this;e.prototype.attach.call(this,t);this.listener.connect(t.el);this.listener.add((function(t){return e.prototype.notify.call(i,t)}))};t.prototype.detach=function(){e.prototype.detach.call(this);this.listener.disconnect()};return t}(SingleSubject);function ListenToResize(){return function(e,t,i){var n=e.connectedCallback,s=e.disconnectedCallback;e.connectedCallback=function(){this._balResizeSubject=new BalResizeSubject;this._balResizeSubject.attach(this);return n&&n.call(this)};e.disconnectedCallback=function(){this._balResizeSubject.detach();return s&&s.call(this)}}}export{ListenToResize as L};