import{__extends}from"tslib";import{k as debounce,u as isChildOfEventTarget,o as addEventListener,p as removeEventListener}from"./helpers-BNj87EbG.js";import{L as ListenerAbstract,a as SingleSubject}from"./listener-CClDIhvK.js";var BalAnimationListener=function(t){__extends(n,t);function n(){var n=t.apply(this,arguments)||this;n.debouncedNotify=debounce((function(t){return n.notify({target:t})}),42);n.callbackWillAnimate=function(t){isChildOfEventTarget(t,n.el,(function(t){return n.debouncedNotify(t)}))};n.callbackDidAnimate=function(t){isChildOfEventTarget(t,n.el,(function(t){return n.debouncedNotify(t)}))};return n}n.prototype.connect=function(n){t.prototype.connect.call(this,n);var i=window;if(i){addEventListener(i,"balWillAnimate",this.callbackWillAnimate,{passive:true});addEventListener(i,"balDidAnimate",this.callbackDidAnimate,{passive:true})}};n.prototype.disconnect=function(){t.prototype.disconnect.call(this);var n=window;if(n){removeEventListener(n,"balWillAnimate",this.callbackWillAnimate);removeEventListener(n,"balDidAnimate",this.callbackDidAnimate)}};return n}(ListenerAbstract);var BalAnimationSubject=function(t){__extends(n,t);function n(){var n=t.call(this,(function(t,n){t.animationListener(n)}))||this;n.listener=new BalAnimationListener;return n}n.prototype.attach=function(n){var i=this;t.prototype.attach.call(this,n);this.listener.connect(n.el);this.listener.add((function(n){return t.prototype.notify.call(i,n)}))};n.prototype.detach=function(){t.prototype.detach.call(this);this.listener.disconnect()};return n}(SingleSubject);new BalAnimationSubject;function ListenToAnimation(){return function(t,n,i){var e=t.connectedCallback,r=t.componentDidLoad,s=t.disconnectedCallback;t.connectedCallback=function(){if(!this._balAnimationSubject){this._balAnimationSubject=new BalAnimationSubject}return e&&e.call(this)};t.componentDidLoad=function(){this._balAnimationSubject.attach(this);return r&&r.call(this)};t.disconnectedCallback=function(){if(this._balAnimationSubject){this._balAnimationSubject.detach();this._balAnimationSubject=undefined}return s&&s.call(this)}}}export{ListenToAnimation as L};