import{__extends}from"tslib";import{I as debounce,a as balBrowser,J as rIC}from"./index-DGWPFpP6.js";import{L as ListenerAbstract,a as SingleSubject}from"./listener-Cwtj-tmC.js";var BalResizeListener=function(i){__extends(t,i);function t(){var t=i.apply(this,arguments)||this;t.debouncedNotify=debounce((function(i){return t.notify(i)}),42);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}var t=i[0];if(e.lastWidth===undefined&&e.lastHeight===undefined){e.lastWidth=t.contentRect.width;e.lastHeight=t.contentRect.height}else{var n=e.lastWidth!==t.contentRect.width;var s=e.lastHeight!==t.contentRect.height;if(n||s){e.debouncedNotify({width:n,height:s});e.lastWidth=t.contentRect.width;e.lastHeight=t.contentRect.height}}}))}}));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){rIC((function(){return i.resizeListener(t)}))}))||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};