import{__extends}from"tslib";import{k as debounce,r as rIC}from"./helpers-BNj87EbG.js";import{L as ListenerAbstract,a as SingleSubject}from"./listener-CClDIhvK.js";import{b as balBrowser}from"./browser-B1u-Mq75.js";var BalResizeListener=function(i){__extends(e,i);function e(){var e=i.apply(this,arguments)||this;e.debouncedNotify=debounce((function(i){return e.notify(i)}),42);return e}e.prototype.connect=function(e){var t=this;var n;i.prototype.connect.call(this,e);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 e=i[0];if(t.lastWidth===undefined&&t.lastHeight===undefined){t.lastWidth=e.contentRect.width;t.lastHeight=e.contentRect.height}else{var n=t.lastWidth!==e.contentRect.width;var r=t.lastHeight!==e.contentRect.height;if(n||r){t.debouncedNotify({width:n,height:r});t.lastWidth=e.contentRect.width;t.lastHeight=e.contentRect.height}}}))}}));this.resizeObserver.observe(e)};e.prototype.disconnect=function(){var e;i.prototype.disconnect.call(this);(e=this.resizeObserver)===null||e===void 0?void 0:e.disconnect();this.resizeObserver=undefined};return e}(ListenerAbstract);var BalResizeSubject=function(i){__extends(e,i);function e(){var e=i.call(this,(function(i,e){rIC((function(){return i.resizeListener(e)}))}))||this;e.listener=new BalResizeListener;return e}e.prototype.attach=function(e){var t=this;i.prototype.attach.call(this,e);this.listener.connect(e.el);this.listener.add((function(e){return i.prototype.notify.call(t,e)}))};e.prototype.detach=function(){i.prototype.detach.call(this);this.listener.disconnect()};return e}(SingleSubject);function ListenToResize(){return function(i,e,t){var n=i.connectedCallback,r=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 r&&r.call(this)}}}export{ListenToResize as L};