1import { b as __extends } from './tslib.es6-c4a4947b.js';
2import { b as Subscriber, d as isScheduler, l as subscribeToResult, n as OuterSubscriber, o as noop, p as isFunction } from './mergeMap-64c6f393.js';
3import { a as concat } from './concat-981db672.js';
4import { N as Notification } from './Notification-9e07e457.js';
5import { a as async } from './timer-a781bf0e.js';
6
7/** PURE_IMPORTS_START  PURE_IMPORTS_END */
8function isDate(value) {
9    return value instanceof Date && !isNaN(+value);
10}
11
12/** PURE_IMPORTS_START tslib,_scheduler_async,_util_isDate,_Subscriber,_Notification PURE_IMPORTS_END */
13function delay(delay, scheduler) {
14    if (scheduler === void 0) {
15        scheduler = async;
16    }
17    var absoluteDelay = isDate(delay);
18    var delayFor = absoluteDelay ? (+delay - scheduler.now()) : Math.abs(delay);
19    return function (source) { return source.lift(new DelayOperator(delayFor, scheduler)); };
20}
21var DelayOperator = /*@__PURE__*/ (function () {
22    function DelayOperator(delay, scheduler) {
23        this.delay = delay;
24        this.scheduler = scheduler;
25    }
26    DelayOperator.prototype.call = function (subscriber, source) {
27        return source.subscribe(new DelaySubscriber(subscriber, this.delay, this.scheduler));
28    };
29    return DelayOperator;
30}());
31var DelaySubscriber = /*@__PURE__*/ (function (_super) {
32    __extends(DelaySubscriber, _super);
33    function DelaySubscriber(destination, delay, scheduler) {
34        var _this = _super.call(this, destination) || this;
35        _this.delay = delay;
36        _this.scheduler = scheduler;
37        _this.queue = [];
38        _this.active = false;
39        _this.errored = false;
40        return _this;
41    }
42    DelaySubscriber.dispatch = function (state) {
43        var source = state.source;
44        var queue = source.queue;
45        var scheduler = state.scheduler;
46        var destination = state.destination;
47        while (queue.length > 0 && (queue[0].time - scheduler.now()) <= 0) {
48            queue.shift().notification.observe(destination);
49        }
50        if (queue.length > 0) {
51            var delay_1 = Math.max(0, queue[0].time - scheduler.now());
52            this.schedule(state, delay_1);
53        }
54        else {
55            this.unsubscribe();
56            source.active = false;
57        }
58    };
59    DelaySubscriber.prototype._schedule = function (scheduler) {
60        this.active = true;
61        var destination = this.destination;
62        destination.add(scheduler.schedule(DelaySubscriber.dispatch, this.delay, {
63            source: this, destination: this.destination, scheduler: scheduler
64        }));
65    };
66    DelaySubscriber.prototype.scheduleNotification = function (notification) {
67        if (this.errored === true) {
68            return;
69        }
70        var scheduler = this.scheduler;
71        var message = new DelayMessage(scheduler.now() + this.delay, notification);
72        this.queue.push(message);
73        if (this.active === false) {
74            this._schedule(scheduler);
75        }
76    };
77    DelaySubscriber.prototype._next = function (value) {
78        this.scheduleNotification(Notification.createNext(value));
79    };
80    DelaySubscriber.prototype._error = function (err) {
81        this.errored = true;
82        this.queue = [];
83        this.destination.error(err);
84        this.unsubscribe();
85    };
86    DelaySubscriber.prototype._complete = function () {
87        this.scheduleNotification(Notification.createComplete());
88        this.unsubscribe();
89    };
90    return DelaySubscriber;
91}(Subscriber));
92var DelayMessage = /*@__PURE__*/ (function () {
93    function DelayMessage(time, notification) {
94        this.time = time;
95        this.notification = notification;
96    }
97    return DelayMessage;
98}());
99
100/** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */
101function distinctUntilChanged(compare, keySelector) {
102    return function (source) { return source.lift(new DistinctUntilChangedOperator(compare, keySelector)); };
103}
104var DistinctUntilChangedOperator = /*@__PURE__*/ (function () {
105    function DistinctUntilChangedOperator(compare, keySelector) {
106        this.compare = compare;
107        this.keySelector = keySelector;
108    }
109    DistinctUntilChangedOperator.prototype.call = function (subscriber, source) {
110        return source.subscribe(new DistinctUntilChangedSubscriber(subscriber, this.compare, this.keySelector));
111    };
112    return DistinctUntilChangedOperator;
113}());
114var DistinctUntilChangedSubscriber = /*@__PURE__*/ (function (_super) {
115    __extends(DistinctUntilChangedSubscriber, _super);
116    function DistinctUntilChangedSubscriber(destination, compare, keySelector) {
117        var _this = _super.call(this, destination) || this;
118        _this.keySelector = keySelector;
119        _this.hasKey = false;
120        if (typeof compare === 'function') {
121            _this.compare = compare;
122        }
123        return _this;
124    }
125    DistinctUntilChangedSubscriber.prototype.compare = function (x, y) {
126        return x === y;
127    };
128    DistinctUntilChangedSubscriber.prototype._next = function (value) {
129        var key;
130        try {
131            var keySelector = this.keySelector;
132            key = keySelector ? keySelector(value) : value;
133        }
134        catch (err) {
135            return this.destination.error(err);
136        }
137        var result = false;
138        if (this.hasKey) {
139            try {
140                var compare = this.compare;
141                result = compare(this.key, key);
142            }
143            catch (err) {
144                return this.destination.error(err);
145            }
146        }
147        else {
148            this.hasKey = true;
149        }
150        if (!result) {
151            this.key = key;
152            this.destination.next(value);
153        }
154    };
155    return DistinctUntilChangedSubscriber;
156}(Subscriber));
157
158/** PURE_IMPORTS_START _observable_concat,_util_isScheduler PURE_IMPORTS_END */
159function startWith() {
160    var array = [];
161    for (var _i = 0; _i < arguments.length; _i++) {
162        array[_i] = arguments[_i];
163    }
164    var scheduler = array[array.length - 1];
165    if (isScheduler(scheduler)) {
166        array.pop();
167        return function (source) { return concat(array, source, scheduler); };
168    }
169    else {
170        return function (source) { return concat(array, source); };
171    }
172}
173
174/** PURE_IMPORTS_START tslib,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
175function takeUntil(notifier) {
176    return function (source) { return source.lift(new TakeUntilOperator(notifier)); };
177}
178var TakeUntilOperator = /*@__PURE__*/ (function () {
179    function TakeUntilOperator(notifier) {
180        this.notifier = notifier;
181    }
182    TakeUntilOperator.prototype.call = function (subscriber, source) {
183        var takeUntilSubscriber = new TakeUntilSubscriber(subscriber);
184        var notifierSubscription = subscribeToResult(takeUntilSubscriber, this.notifier);
185        if (notifierSubscription && !takeUntilSubscriber.seenValue) {
186            takeUntilSubscriber.add(notifierSubscription);
187            return source.subscribe(takeUntilSubscriber);
188        }
189        return takeUntilSubscriber;
190    };
191    return TakeUntilOperator;
192}());
193var TakeUntilSubscriber = /*@__PURE__*/ (function (_super) {
194    __extends(TakeUntilSubscriber, _super);
195    function TakeUntilSubscriber(destination) {
196        var _this = _super.call(this, destination) || this;
197        _this.seenValue = false;
198        return _this;
199    }
200    TakeUntilSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
201        this.seenValue = true;
202        this.complete();
203    };
204    TakeUntilSubscriber.prototype.notifyComplete = function () {
205    };
206    return TakeUntilSubscriber;
207}(OuterSubscriber));
208
209/** PURE_IMPORTS_START tslib,_Subscriber,_util_noop,_util_isFunction PURE_IMPORTS_END */
210function tap(nextOrObserver, error, complete) {
211    return function tapOperatorFunction(source) {
212        return source.lift(new DoOperator(nextOrObserver, error, complete));
213    };
214}
215var DoOperator = /*@__PURE__*/ (function () {
216    function DoOperator(nextOrObserver, error, complete) {
217        this.nextOrObserver = nextOrObserver;
218        this.error = error;
219        this.complete = complete;
220    }
221    DoOperator.prototype.call = function (subscriber, source) {
222        return source.subscribe(new TapSubscriber(subscriber, this.nextOrObserver, this.error, this.complete));
223    };
224    return DoOperator;
225}());
226var TapSubscriber = /*@__PURE__*/ (function (_super) {
227    __extends(TapSubscriber, _super);
228    function TapSubscriber(destination, observerOrNext, error, complete) {
229        var _this = _super.call(this, destination) || this;
230        _this._tapNext = noop;
231        _this._tapError = noop;
232        _this._tapComplete = noop;
233        _this._tapError = error || noop;
234        _this._tapComplete = complete || noop;
235        if (isFunction(observerOrNext)) {
236            _this._context = _this;
237            _this._tapNext = observerOrNext;
238        }
239        else if (observerOrNext) {
240            _this._context = observerOrNext;
241            _this._tapNext = observerOrNext.next || noop;
242            _this._tapError = observerOrNext.error || noop;
243            _this._tapComplete = observerOrNext.complete || noop;
244        }
245        return _this;
246    }
247    TapSubscriber.prototype._next = function (value) {
248        try {
249            this._tapNext.call(this._context, value);
250        }
251        catch (err) {
252            this.destination.error(err);
253            return;
254        }
255        this.destination.next(value);
256    };
257    TapSubscriber.prototype._error = function (err) {
258        try {
259            this._tapError.call(this._context, err);
260        }
261        catch (err) {
262            this.destination.error(err);
263            return;
264        }
265        this.destination.error(err);
266    };
267    TapSubscriber.prototype._complete = function () {
268        try {
269            this._tapComplete.call(this._context);
270        }
271        catch (err) {
272            this.destination.error(err);
273            return;
274        }
275        return this.destination.complete();
276    };
277    return TapSubscriber;
278}(Subscriber));
279
280/** PURE_IMPORTS_START tslib,_OuterSubscriber,_util_subscribeToResult PURE_IMPORTS_END */
281function withLatestFrom() {
282    var args = [];
283    for (var _i = 0; _i < arguments.length; _i++) {
284        args[_i] = arguments[_i];
285    }
286    return function (source) {
287        var project;
288        if (typeof args[args.length - 1] === 'function') {
289            project = args.pop();
290        }
291        var observables = args;
292        return source.lift(new WithLatestFromOperator(observables, project));
293    };
294}
295var WithLatestFromOperator = /*@__PURE__*/ (function () {
296    function WithLatestFromOperator(observables, project) {
297        this.observables = observables;
298        this.project = project;
299    }
300    WithLatestFromOperator.prototype.call = function (subscriber, source) {
301        return source.subscribe(new WithLatestFromSubscriber(subscriber, this.observables, this.project));
302    };
303    return WithLatestFromOperator;
304}());
305var WithLatestFromSubscriber = /*@__PURE__*/ (function (_super) {
306    __extends(WithLatestFromSubscriber, _super);
307    function WithLatestFromSubscriber(destination, observables, project) {
308        var _this = _super.call(this, destination) || this;
309        _this.observables = observables;
310        _this.project = project;
311        _this.toRespond = [];
312        var len = observables.length;
313        _this.values = new Array(len);
314        for (var i = 0; i < len; i++) {
315            _this.toRespond.push(i);
316        }
317        for (var i = 0; i < len; i++) {
318            var observable = observables[i];
319            _this.add(subscribeToResult(_this, observable, observable, i));
320        }
321        return _this;
322    }
323    WithLatestFromSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
324        this.values[outerIndex] = innerValue;
325        var toRespond = this.toRespond;
326        if (toRespond.length > 0) {
327            var found = toRespond.indexOf(outerIndex);
328            if (found !== -1) {
329                toRespond.splice(found, 1);
330            }
331        }
332    };
333    WithLatestFromSubscriber.prototype.notifyComplete = function () {
334    };
335    WithLatestFromSubscriber.prototype._next = function (value) {
336        if (this.toRespond.length === 0) {
337            var args = [value].concat(this.values);
338            if (this.project) {
339                this._tryProject(args);
340            }
341            else {
342                this.destination.next(args);
343            }
344        }
345    };
346    WithLatestFromSubscriber.prototype._tryProject = function (args) {
347        var result;
348        try {
349            result = this.project.apply(this, args);
350        }
351        catch (err) {
352            this.destination.error(err);
353            return;
354        }
355        this.destination.next(result);
356    };
357    return WithLatestFromSubscriber;
358}(OuterSubscriber));
359
360export { tap as a, delay as b, distinctUntilChanged as d, isDate as i, startWith as s, takeUntil as t, withLatestFrom as w };
361