!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.most={})}(this,function(t){"use strict";function e(t){this.source=t}function n(t,e){if(t<0)throw new TypeError("n must be >= 0");var n=e.length;return 0===t||0===n?e:t>=n?[]:function(t,e,n){for(var i=new Array(n),r=0;r= 0");for(var i=n.length,r=new Array(i),o=0;o= 0");var n=e.length;return 0===n||t>=n?e:1===n?[]:function(t,e,n){var i,r=new Array(n);for(i=0;i=n?e.push(Z(t.time,[t])):t.time===e[i].time?e[i].events.push(t):e.splice(i,0,Z(t.time,[t]))}else e.push(Z(t.time,[t]))}function X(t,e){e.events=function(t,e){for(var n=e.length,i=new Array(n),r=0,o=void 0,s=0;s=0&&e=0)return this.tasks[e].events.splice(n,1),!0}return!1},K.prototype.removeAll=function(t){for(var e=0,n=this.tasks.length;e=0&&o.active&&(o.time=o.time+o.period,Q(o,n)))}return n}(e,n[o],this.tasks)};var ei=new G(new H,new K);$.prototype.event=function(t,e){this.disposable.disposed||"function"!=typeof this.subscriber.next||this.subscriber.next(e)},$.prototype.end=function(t,e){if(!this.disposable.disposed){var n=this.subscriber,i=this.fatalError;Promise.resolve(this.disposable.dispose()).then(function(){"function"==typeof n.complete&&n.complete(e)}).catch(function(t){et(t,n,i)})}},$.prototype.error=function(t,e){var n=this.subscriber,i=this.fatalError;Promise.resolve(this.disposable.dispose()).then(function(){et(e,n,i)})},tt.prototype.unsubscribe=function(){this.disposable.dispose()},nt.prototype.run=function(t,e){function n(n){S(e.now(),n,t)}return this.source.addEventListener(this.event,n,this.capture),f(it,{target:this,addEvent:n})},rt.prototype.event=function(t,e){this.active&&(0===this.events.length&&O(new ot(this.sink,t,this.events)),this.events.push({time:t,value:e}))},rt.prototype.end=function(t,e){this.active&&this._end(new st(t,e,this.sink))},rt.prototype.error=function(t,e){this._end(new ut(t,e,this.sink))},rt.prototype._end=function(t){this.active=!1,O(t)},ot.prototype.run=function(){for(var t,e=this.events,n=this.sink,i=0,r=e.length;i1){for(var o=new Array(r),s=0;s0&&(this.hasValue[t]||(this.hasValue[t]=!0,this.awaiting-=1)),this.awaiting},ie.prototype.end=function(t,e){c(t,this.disposables[e.index],this.sink),0==--this.activeCount&&this.sink.end(t,e.value)},se.prototype.run=function(t,e){var n=this.transducer(new he(t));return this.source.run(new ue(function(t){return"function"==typeof t["@@transducer/step"]?new pe(t):new ce(t)}(n),t),e)},ue.prototype.event=function(t,e){var n=this.xf.step(t,e);return this.xf.isReduced(n)?this.sink.end(t,this.xf.getResult(n)):n},ue.prototype.end=function(t,e){return this.xf.result(e)},ue.prototype.error=function(t,e){return this.sink.error(t,e)},he.prototype["@@transducer/init"]=he.prototype.init=function(){},he.prototype["@@transducer/step"]=he.prototype.step=function(t,e){return isNaN(t)||(this.time=Math.max(t,this.time)),this.sink.event(this.time,e)},he.prototype["@@transducer/result"]=he.prototype.result=function(t){return this.sink.end(this.time,t)},pe.prototype.step=function(t,e){return this.tx["@@transducer/step"](t,e)},pe.prototype.result=function(t){return this.tx["@@transducer/result"](t)},pe.prototype.isReduced=function(t){return null!=t&&t["@@transducer/reduced"]},pe.prototype.getResult=function(t){return t["@@transducer/value"]},ce.prototype.step=function(t,e){return this.tx.step(t,e)},ce.prototype.result=function(t){return this.tx.result(t)},ce.prototype.isReduced=function(t){return null!=t&&t.__transducers_reduced__},ce.prototype.getResult=function(t){return t.value},fe.prototype.add=function(t){null!==this.head&&(this.head.prev=t,t.next=this.head),this.head=t,++this.length},fe.prototype.remove=function(t){--this.length,t===this.head&&(this.head=this.head.next),null!==t.next&&(t.next.prev=t.prev,t.next=null),null!==t.prev&&(t.prev.next=t.next,t.prev=null)},fe.prototype.isEmpty=function(){return 0===this.length},fe.prototype.dispose=function(){if(this.isEmpty())return Promise.resolve();var t=[],e=this.head;for(this.head=null,this.length=0;null!==e;)t.push(e.dispose()),e=e.next;return Promise.all(t)},le.prototype.run=function(t,e){return new ye(this.f,this.concurrency,this.source,t,e)},ye.prototype.event=function(t,e){this._addInner(t,e)},ye.prototype._addInner=function(t,e){this.current.lengthe&&function(t,e,n,i,r){for(var o=0;o0?this.skip-=1:0!==this.take&&(this.take-=1,this.sink.event(t,e),0===this.take&&(this.disposable.dispose(),this.sink.end(t,e)))},en.prototype.run=function(t,e){var n=v(),i=new nn(this.p,t,n);return n.setDisposable(this.source.run(i,e)),n},nn.prototype.end=dt.prototype.end,nn.prototype.error=dt.prototype.error,nn.prototype.event=function(t,e){if(this.active){var n=this.p;this.active=n(e),this.active?this.sink.event(t,e):(this.disposable.dispose(),this.sink.end(t,e))}},on.prototype.run=function(t,e){return this.source.run(new sn(this.p,t),e)},sn.prototype.end=dt.prototype.end,sn.prototype.error=dt.prototype.error,sn.prototype.event=function(t,e){if(this.skipping){var n=this.p;if(this.skipping=n(e),this.skipping)return}this.sink.event(t,e)},hn.prototype.run=function(t,e){return this.source.run(new pn(this.p,t),e)},pn.prototype.event=function(t,e){if(!this.skipping){var n=this.p;this.skipping=n(e),this.sink.event(t,e),this.skipping&&this.sink.end(t,e)}},pn.prototype.end=dt.prototype.end,pn.prototype.error=dt.prototype.error,dn.prototype.run=function(t,e){var n=new yn(-1/0,t),i=new kn(this.maxSignal,t,e);return d([n,i,this.source.run(new vn(n,i,t),e)])},ln.prototype.run=function(t,e){var n=new wn(this.minSignal,t,e),i=new yn(1/0,t);return d([n,i,this.source.run(new vn(n,i,t),e)])},yn.prototype.error=dt.prototype.error,yn.prototype.event=mn,yn.prototype.end=mn,yn.prototype.dispose=mn,vn.prototype.event=function(t,e){t>=this.min.value&&t=this.time&&(this.time=t+this.period,this.sink.event(t,e))},Rn.prototype.end=dt.prototype.end,Rn.prototype.error=dt.prototype.error,Wn.prototype.run=function(t,e){return new Ln(this.dt,this.source,t,e)},Ln.prototype.event=function(t,e){this._clearTimer(),this.value=e,this.timer=this.scheduler.delay(this.dt,new Cn(this,e))},Ln.prototype._event=function(t,e){this._clearTimer(),this.sink.event(t,e)},Ln.prototype.end=function(t,e){this._clearTimer()&&(this.sink.event(t,this.value),this.value=void 0),this.sink.end(t,e)},Ln.prototype.error=function(t,e){this._clearTimer(),this.sink.error(t,e)},Ln.prototype.dispose=function(){return this._clearTimer(),this.disposable.dispose()},Ln.prototype._clearTimer=function(){return null!==this.timer&&(this.timer.dispose(),this.timer=null,!0)},Cn.prototype.run=function(t){this.debounce._event(t,this.value)},Cn.prototype.error=function(t,e){this.debounce.error(t,e)},Cn.prototype.dispose=function(){},Sn.prototype.run=function(t,e){return new qn(this.source,t,e)},qn.prototype.dispose=function(){return this.active=!1,this.disposable.dispose()},qn.prototype.event=function(t,e){var n=this;this.queue=this.queue.then(function(){return n._event(e)}).catch(this._errorBound)},qn.prototype.end=function(t,e){var n=this;this.queue=this.queue.then(function(){return n._end(e)}).catch(this._errorBound)},qn.prototype.error=function(t,e){var n=this;this.queue=this.queue.then(function(){return n._errorBound(e)}).catch(m)},qn.prototype._event=function(t){return t.then(this._eventBound)},qn.prototype._end=function(t){return Promise.resolve(t).then(this._endBound)},Bn.prototype.event=function(t,e){this.active&&this.sink.event(t,e)},Bn.prototype.end=function(t,e){this.active&&(this.disable(),this.sink.end(t,e))},Bn.prototype.error=function(t,e){this.disable(),this.sink.error(t,e)},Bn.prototype.disable=function(){return this.active=!1,this.sink};var hi=jn;Dn.prototype.run=function(t,e){return e.asap(new _(Vn,this.value,t))},Un.prototype.run=function(t,e){return new zn(this.f,this.source,t,e)},zn.prototype.event=function(t,e){S(t,e,this.sink)},zn.prototype.end=function(t,e){q(t,e,this.sink)},zn.prototype.error=function(t,e){var n=this.sink.disable();c(t,this.disposable,this.sink),this._startNext(t,e,n)},zn.prototype._startNext=function(t,e,n){try{this.disposable=this._continue(this.f,e,n)}catch(e){n.error(t,e)}},zn.prototype._continue=function(t,e,n){return t(e).source.run(n,this.scheduler)},zn.prototype.dispose=function(){return this.disposable.dispose()};var pi=function(t,e){this.source=t,this.sink=e,this.disposed=!1};pi.prototype.dispose=function(){if(!this.disposed){this.disposed=!0;return 0===this.source.remove(this.sink)&&this.source._dispose()}};var ci=function(t){return t.dispose()},fi={dispose:function(){}},ai=function(t){this.source=t,this.sinks=[],this._disposable=fi};ai.prototype.run=function(t,e){return 1===this.add(t)&&(this._disposable=this.source.run(this,e)),new pi(this,t)},ai.prototype._dispose=function(){var t=this._disposable;return this._disposable=fi,Promise.resolve(t).then(ci)},ai.prototype.add=function(t){return this.sinks=function(t,e){for(var n=e.length,i=new Array(n+1),r=0;r=0&&(this.sinks=s(e,this.sinks)),this.sinks.length},ai.prototype.event=function(t,e){var n=this.sinks;if(1===n.length)return n[0].event(t,e);for(var i=0;i