import{process as e}from"./process.js";import{global as t}from"./global.js";import{queueResizeObserver as r}from"./queueResizeObserver.js";var o=0,n={attributes:!0,characterData:!0,childList:!0,subtree:!0},s=["resize","load","transitionend","animationend","animationstart","animationiteration","keyup","keydown","mouseup","mousedown","mouseover","mouseout","blur","focus"],time=function(e){return void 0===e&&(e=0),Date.now()+e},i=!1,u=new(function(){function Scheduler(){var e=this;this.stopped=!0,this.listener=function(){return e.schedule()}}return Scheduler.prototype.run=function(t){var n=this;if(void 0===t&&(t=250),!i){i=!0;var s=time(t);r((function(){var r=!1;try{r=e()}finally{if(i=!1,t=s-time(),!o)return;r?n.run(1e3):t>0?n.run(t):n.start()}}))}},Scheduler.prototype.schedule=function(){this.stop(),this.run()},Scheduler.prototype.observe=function(){var e=this,cb=function(){return e.observer&&e.observer.observe(document.body,n)};document.body?cb():t.addEventListener("DOMContentLoaded",cb)},Scheduler.prototype.start=function(){var e=this;this.stopped&&(this.stopped=!1,this.observer=new MutationObserver(this.listener),this.observe(),s.forEach((function(r){return t.addEventListener(r,e.listener,!0)})))},Scheduler.prototype.stop=function(){var e=this;this.stopped||(this.observer&&this.observer.disconnect(),s.forEach((function(r){return t.removeEventListener(r,e.listener,!0)})),this.stopped=!0)},Scheduler}()),updateCount=function(e){!o&&e>0&&u.start(),!(o+=e)&&u.stop()};export{u as scheduler,updateCount};