const i=new WeakMap;class t{constructor(t,s){this.startPaused=!1,this.disabled=!1,this.clients=new Set,this.pendingComplete=!1,this.host=t,this.defaultOptions=s.defaultOptions||{},this.startPaused=!!s.startPaused,this.disabled=!!s.disabled,this.onComplete=s.onComplete,i.set(this.host,this)}async add(i){this.clients.add(i),this.startPaused&&i.webAnimation?.pause(),this.pendingComplete=!0,await i.finished,this.pendingComplete&&!this.isAnimating&&(this.pendingComplete=!1,this.onComplete?.())}remove(i){this.clients.delete(i)}pause(){this.clients.forEach((i=>i.webAnimation?.pause()))}play(){this.clients.forEach((i=>i.webAnimation?.play()))}cancel(){this.clients.forEach((i=>i.webAnimation?.cancel())),this.clients.clear()}finish(){this.clients.forEach((i=>i.webAnimation?.finish())),this.clients.clear()}togglePlay(){this.isPlaying?this.pause():this.play()}get isAnimating(){return this.clients.size>0}get isPlaying(){return Array.from(this.clients).some((i=>"running"===i.webAnimation?.playState))}async finished(){await Promise.all(Array.from(this.clients).map((i=>i.finished)))}}export{t as AnimateController,i as controllerMap};
