import{__extends}from"tslib";import{L as ListenerAbstract,a as SingleSubject}from"./listener-aa4bfae3.js";import{b as balBrowser}from"./browser-a623d3a0.js";import{h as debounce}from"./helpers-2253b115.js";var BalResizeListener=function(i){__extends(t,i);function t(){var t=i.apply(this,arguments)||this;t.debouncedNotify=debounce((function(){return t.notify()}),10);return t}t.prototype.connect=function(t){var e=this;var n;i.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(i){if(balBrowser.hasWindow){window.requestAnimationFrame((function(){if(!Array.isArray(i)||!i.length){return}e.debouncedNotify()}))}}));this.resizeObserver.observe(t)};t.prototype.disconnect=function(){var t;i.prototype.disconnect.call(this);(t=this.resizeObserver)===null||t===void 0?void 0:t.disconnect();this.resizeObserver=undefined};return t}(ListenerAbstract);var BalResizeSubject=function(i){__extends(t,i);function t(){var t=i.call(this,(function(i,t){i.resizeListener({})}))||this;t.listener=new BalResizeListener;return t}t.prototype.attach=function(t){var e=this;i.prototype.attach.call(this,t);this.listener.connect(t.el);this.listener.add((function(t){return i.prototype.notify.call(e,t)}))};t.prototype.detach=function(){i.prototype.detach.call(this);this.listener.disconnect()};return t}(SingleSubject);function ListenToResize(){return function(i,t,e){var n=i.connectedCallback,s=i.disconnectedCallback;i.connectedCallback=function(){if(!this._balResizeSubject){this._balResizeSubject=new BalResizeSubject;this._balResizeSubject.attach(this)}return n&&n.call(this)};i.disconnectedCallback=function(){if(this._balResizeSubject){this._balResizeSubject.detach();this._balResizeSubject=undefined}return s&&s.call(this)}}}export{ListenToResize as L};