UNPKG

mapillary-js

Version:

A WebGL interactive street imagery library

1,367 lines (1,307 loc) 2.53 MB
/*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spreadArray(to, from) { for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i]; return to; } function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } } function isFunction(value) { return typeof value === 'function'; } function createErrorClass(createImpl) { var _super = function (instance) { Error.call(instance); instance.stack = new Error().stack; }; var ctorFunc = createImpl(_super); ctorFunc.prototype = Object.create(Error.prototype); ctorFunc.prototype.constructor = ctorFunc; return ctorFunc; } var UnsubscriptionError = createErrorClass(function (_super) { return function UnsubscriptionErrorImpl(errors) { _super(this); this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) { return i + 1 + ") " + err.toString(); }).join('\n ') : ''; this.name = 'UnsubscriptionError'; this.errors = errors; }; }); function arrRemove(arr, item) { if (arr) { var index = arr.indexOf(item); 0 <= index && arr.splice(index, 1); } } var Subscription = (function () { function Subscription(initialTeardown) { this.initialTeardown = initialTeardown; this.closed = false; this._parentage = null; this._teardowns = null; } Subscription.prototype.unsubscribe = function () { var e_1, _a, e_2, _b; var errors; if (!this.closed) { this.closed = true; var _parentage = this._parentage; if (_parentage) { this._parentage = null; if (Array.isArray(_parentage)) { try { for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) { var parent_1 = _parentage_1_1.value; parent_1.remove(this); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1); } finally { if (e_1) throw e_1.error; } } } else { _parentage.remove(this); } } var initialTeardown = this.initialTeardown; if (isFunction(initialTeardown)) { try { initialTeardown(); } catch (e) { errors = e instanceof UnsubscriptionError ? e.errors : [e]; } } var _teardowns = this._teardowns; if (_teardowns) { this._teardowns = null; try { for (var _teardowns_1 = __values(_teardowns), _teardowns_1_1 = _teardowns_1.next(); !_teardowns_1_1.done; _teardowns_1_1 = _teardowns_1.next()) { var teardown_1 = _teardowns_1_1.value; try { execTeardown(teardown_1); } catch (err) { errors = errors !== null && errors !== void 0 ? errors : []; if (err instanceof UnsubscriptionError) { errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors)); } else { errors.push(err); } } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_teardowns_1_1 && !_teardowns_1_1.done && (_b = _teardowns_1.return)) _b.call(_teardowns_1); } finally { if (e_2) throw e_2.error; } } } if (errors) { throw new UnsubscriptionError(errors); } } }; Subscription.prototype.add = function (teardown) { var _a; if (teardown && teardown !== this) { if (this.closed) { execTeardown(teardown); } else { if (teardown instanceof Subscription) { if (teardown.closed || teardown._hasParent(this)) { return; } teardown._addParent(this); } (this._teardowns = (_a = this._teardowns) !== null && _a !== void 0 ? _a : []).push(teardown); } } }; Subscription.prototype._hasParent = function (parent) { var _parentage = this._parentage; return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent)); }; Subscription.prototype._addParent = function (parent) { var _parentage = this._parentage; this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent; }; Subscription.prototype._removeParent = function (parent) { var _parentage = this._parentage; if (_parentage === parent) { this._parentage = null; } else if (Array.isArray(_parentage)) { arrRemove(_parentage, parent); } }; Subscription.prototype.remove = function (teardown) { var _teardowns = this._teardowns; _teardowns && arrRemove(_teardowns, teardown); if (teardown instanceof Subscription) { teardown._removeParent(this); } }; Subscription.EMPTY = (function () { var empty = new Subscription(); empty.closed = true; return empty; })(); return Subscription; }()); var EMPTY_SUBSCRIPTION = Subscription.EMPTY; function isSubscription(value) { return (value instanceof Subscription || (value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe))); } function execTeardown(teardown) { if (isFunction(teardown)) { teardown(); } else { teardown.unsubscribe(); } } var config = { onUnhandledError: null, onStoppedNotification: null, Promise: undefined, useDeprecatedSynchronousErrorHandling: false, useDeprecatedNextContext: false, }; var timeoutProvider = { setTimeout: function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var delegate = timeoutProvider.delegate; return ((delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) || setTimeout).apply(void 0, __spreadArray([], __read(args))); }, clearTimeout: function (handle) { var delegate = timeoutProvider.delegate; return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle); }, delegate: undefined, }; function reportUnhandledError(err) { timeoutProvider.setTimeout(function () { { throw err; } }); } function noop() { } var COMPLETE_NOTIFICATION = (function () { return createNotification('C', undefined, undefined); })(); function errorNotification(error) { return createNotification('E', undefined, error); } function nextNotification(value) { return createNotification('N', value, undefined); } function createNotification(kind, value, error) { return { kind: kind, value: value, error: error, }; } var context = null; function errorContext(cb) { if (config.useDeprecatedSynchronousErrorHandling) { var isRoot = !context; if (isRoot) { context = { errorThrown: false, error: null }; } cb(); if (isRoot) { var _a = context, errorThrown = _a.errorThrown, error = _a.error; context = null; if (errorThrown) { throw error; } } } else { cb(); } } var Subscriber = (function (_super) { __extends(Subscriber, _super); function Subscriber(destination) { var _this = _super.call(this) || this; _this.isStopped = false; if (destination) { _this.destination = destination; if (isSubscription(destination)) { destination.add(_this); } } else { _this.destination = EMPTY_OBSERVER; } return _this; } Subscriber.create = function (next, error, complete) { return new SafeSubscriber(next, error, complete); }; Subscriber.prototype.next = function (value) { if (this.isStopped) { handleStoppedNotification(nextNotification(value), this); } else { this._next(value); } }; Subscriber.prototype.error = function (err) { if (this.isStopped) { handleStoppedNotification(errorNotification(err), this); } else { this.isStopped = true; this._error(err); } }; Subscriber.prototype.complete = function () { if (this.isStopped) { handleStoppedNotification(COMPLETE_NOTIFICATION, this); } else { this.isStopped = true; this._complete(); } }; Subscriber.prototype.unsubscribe = function () { if (!this.closed) { this.isStopped = true; _super.prototype.unsubscribe.call(this); this.destination = null; } }; Subscriber.prototype._next = function (value) { this.destination.next(value); }; Subscriber.prototype._error = function (err) { try { this.destination.error(err); } finally { this.unsubscribe(); } }; Subscriber.prototype._complete = function () { try { this.destination.complete(); } finally { this.unsubscribe(); } }; return Subscriber; }(Subscription)); var SafeSubscriber = (function (_super) { __extends(SafeSubscriber, _super); function SafeSubscriber(observerOrNext, error, complete) { var _this = _super.call(this) || this; var next; if (isFunction(observerOrNext)) { next = observerOrNext; } else if (observerOrNext) { (next = observerOrNext.next, error = observerOrNext.error, complete = observerOrNext.complete); var context_1; if (_this && config.useDeprecatedNextContext) { context_1 = Object.create(observerOrNext); context_1.unsubscribe = function () { return _this.unsubscribe(); }; } else { context_1 = observerOrNext; } next = next === null || next === void 0 ? void 0 : next.bind(context_1); error = error === null || error === void 0 ? void 0 : error.bind(context_1); complete = complete === null || complete === void 0 ? void 0 : complete.bind(context_1); } _this.destination = { next: next ? wrapForErrorHandling(next) : noop, error: wrapForErrorHandling(error !== null && error !== void 0 ? error : defaultErrorHandler), complete: complete ? wrapForErrorHandling(complete) : noop, }; return _this; } return SafeSubscriber; }(Subscriber)); function wrapForErrorHandling(handler, instance) { return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } try { handler.apply(void 0, __spreadArray([], __read(args))); } catch (err) { { reportUnhandledError(err); } } }; } function defaultErrorHandler(err) { throw err; } function handleStoppedNotification(notification, subscriber) { var onStoppedNotification = config.onStoppedNotification; onStoppedNotification && timeoutProvider.setTimeout(function () { return onStoppedNotification(notification, subscriber); }); } var EMPTY_OBSERVER = { closed: true, next: noop, error: defaultErrorHandler, complete: noop, }; var observable = (function () { return (typeof Symbol === 'function' && Symbol.observable) || '@@observable'; })(); function identity(x) { return x; } function pipeFromArray(fns) { if (fns.length === 0) { return identity; } if (fns.length === 1) { return fns[0]; } return function piped(input) { return fns.reduce(function (prev, fn) { return fn(prev); }, input); }; } var Observable = (function () { function Observable(subscribe) { if (subscribe) { this._subscribe = subscribe; } } Observable.prototype.lift = function (operator) { var observable = new Observable(); observable.source = this; observable.operator = operator; return observable; }; Observable.prototype.subscribe = function (observerOrNext, error, complete) { var _this = this; var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete); errorContext(function () { var _a = _this, operator = _a.operator, source = _a.source; subscriber.add(operator ? operator.call(subscriber, source) : source ? _this._subscribe(subscriber) : _this._trySubscribe(subscriber)); }); return subscriber; }; Observable.prototype._trySubscribe = function (sink) { try { return this._subscribe(sink); } catch (err) { sink.error(err); } }; Observable.prototype.forEach = function (next, promiseCtor) { var _this = this; promiseCtor = getPromiseCtor(promiseCtor); return new promiseCtor(function (resolve, reject) { var subscription; subscription = _this.subscribe(function (value) { try { next(value); } catch (err) { reject(err); subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe(); } }, reject, resolve); }); }; Observable.prototype._subscribe = function (subscriber) { var _a; return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber); }; Observable.prototype[observable] = function () { return this; }; Observable.prototype.pipe = function () { var operations = []; for (var _i = 0; _i < arguments.length; _i++) { operations[_i] = arguments[_i]; } return pipeFromArray(operations)(this); }; Observable.prototype.toPromise = function (promiseCtor) { var _this = this; promiseCtor = getPromiseCtor(promiseCtor); return new promiseCtor(function (resolve, reject) { var value; _this.subscribe(function (x) { return (value = x); }, function (err) { return reject(err); }, function () { return resolve(value); }); }); }; Observable.create = function (subscribe) { return new Observable(subscribe); }; return Observable; }()); function getPromiseCtor(promiseCtor) { var _a; return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise; } function isObserver(value) { return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete); } function isSubscriber(value) { return (value && value instanceof Subscriber) || (isObserver(value) && isSubscription(value)); } function hasLift(source) { return isFunction(source === null || source === void 0 ? void 0 : source.lift); } function operate(init) { return function (source) { if (hasLift(source)) { return source.lift(function (liftedSource) { try { return init(liftedSource, this); } catch (err) { this.error(err); } }); } throw new TypeError('Unable to lift unknown Observable type'); }; } var OperatorSubscriber = (function (_super) { __extends(OperatorSubscriber, _super); function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) { var _this = _super.call(this, destination) || this; _this.onFinalize = onFinalize; _this._next = onNext ? function (value) { try { onNext(value); } catch (err) { destination.error(err); } } : _super.prototype._next; _this._error = onError ? function (err) { try { onError(err); } catch (err) { destination.error(err); } finally { this.unsubscribe(); } } : _super.prototype._error; _this._complete = onComplete ? function () { try { onComplete(); } catch (err) { destination.error(err); } finally { this.unsubscribe(); } } : _super.prototype._complete; return _this; } OperatorSubscriber.prototype.unsubscribe = function () { var _a; var closed = this.closed; _super.prototype.unsubscribe.call(this); !closed && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this)); }; return OperatorSubscriber; }(Subscriber)); function refCount() { return operate(function (source, subscriber) { var connection = null; source._refCount++; var refCounter = new OperatorSubscriber(subscriber, undefined, undefined, undefined, function () { if (!source || source._refCount <= 0 || 0 < --source._refCount) { connection = null; return; } var sharedConnection = source._connection; var conn = connection; connection = null; if (sharedConnection && (!conn || sharedConnection === conn)) { sharedConnection.unsubscribe(); } subscriber.unsubscribe(); }); source.subscribe(refCounter); if (!refCounter.closed) { connection = source.connect(); } }); } var ConnectableObservable = (function (_super) { __extends(ConnectableObservable, _super); function ConnectableObservable(source, subjectFactory) { var _this = _super.call(this) || this; _this.source = source; _this.subjectFactory = subjectFactory; _this._subject = null; _this._refCount = 0; _this._connection = null; if (hasLift(source)) { _this.lift = source.lift; } return _this; } ConnectableObservable.prototype._subscribe = function (subscriber) { return this.getSubject().subscribe(subscriber); }; ConnectableObservable.prototype.getSubject = function () { var subject = this._subject; if (!subject || subject.isStopped) { this._subject = this.subjectFactory(); } return this._subject; }; ConnectableObservable.prototype._teardown = function () { this._refCount = 0; var _connection = this._connection; this._subject = this._connection = null; _connection === null || _connection === void 0 ? void 0 : _connection.unsubscribe(); }; ConnectableObservable.prototype.connect = function () { var _this = this; var connection = this._connection; if (!connection) { connection = this._connection = new Subscription(); var subject_1 = this.getSubject(); connection.add(this.source.subscribe(new OperatorSubscriber(subject_1, undefined, function () { _this._teardown(); subject_1.complete(); }, function (err) { _this._teardown(); subject_1.error(err); }, function () { return _this._teardown(); }))); if (connection.closed) { this._connection = null; connection = Subscription.EMPTY; } } return connection; }; ConnectableObservable.prototype.refCount = function () { return refCount()(this); }; return ConnectableObservable; }(Observable)); var ObjectUnsubscribedError = createErrorClass(function (_super) { return function ObjectUnsubscribedErrorImpl() { _super(this); this.name = 'ObjectUnsubscribedError'; this.message = 'object unsubscribed'; }; }); var Subject = (function (_super) { __extends(Subject, _super); function Subject() { var _this = _super.call(this) || this; _this.closed = false; _this.observers = []; _this.isStopped = false; _this.hasError = false; _this.thrownError = null; return _this; } Subject.prototype.lift = function (operator) { var subject = new AnonymousSubject(this, this); subject.operator = operator; return subject; }; Subject.prototype._throwIfClosed = function () { if (this.closed) { throw new ObjectUnsubscribedError(); } }; Subject.prototype.next = function (value) { var _this = this; errorContext(function () { var e_1, _a; _this._throwIfClosed(); if (!_this.isStopped) { var copy = _this.observers.slice(); try { for (var copy_1 = __values(copy), copy_1_1 = copy_1.next(); !copy_1_1.done; copy_1_1 = copy_1.next()) { var observer = copy_1_1.value; observer.next(value); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (copy_1_1 && !copy_1_1.done && (_a = copy_1.return)) _a.call(copy_1); } finally { if (e_1) throw e_1.error; } } } }); }; Subject.prototype.error = function (err) { var _this = this; errorContext(function () { _this._throwIfClosed(); if (!_this.isStopped) { _this.hasError = _this.isStopped = true; _this.thrownError = err; var observers = _this.observers; while (observers.length) { observers.shift().error(err); } } }); }; Subject.prototype.complete = function () { var _this = this; errorContext(function () { _this._throwIfClosed(); if (!_this.isStopped) { _this.isStopped = true; var observers = _this.observers; while (observers.length) { observers.shift().complete(); } } }); }; Subject.prototype.unsubscribe = function () { this.isStopped = this.closed = true; this.observers = null; }; Object.defineProperty(Subject.prototype, "observed", { get: function () { var _a; return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0; }, enumerable: false, configurable: true }); Subject.prototype._trySubscribe = function (subscriber) { this._throwIfClosed(); return _super.prototype._trySubscribe.call(this, subscriber); }; Subject.prototype._subscribe = function (subscriber) { this._throwIfClosed(); this._checkFinalizedStatuses(subscriber); return this._innerSubscribe(subscriber); }; Subject.prototype._innerSubscribe = function (subscriber) { var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers; return hasError || isStopped ? EMPTY_SUBSCRIPTION : (observers.push(subscriber), new Subscription(function () { return arrRemove(observers, subscriber); })); }; Subject.prototype._checkFinalizedStatuses = function (subscriber) { var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped; if (hasError) { subscriber.error(thrownError); } else if (isStopped) { subscriber.complete(); } }; Subject.prototype.asObservable = function () { var observable = new Observable(); observable.source = this; return observable; }; Subject.create = function (destination, source) { return new AnonymousSubject(destination, source); }; return Subject; }(Observable)); var AnonymousSubject = (function (_super) { __extends(AnonymousSubject, _super); function AnonymousSubject(destination, source) { var _this = _super.call(this) || this; _this.destination = destination; _this.source = source; return _this; } AnonymousSubject.prototype.next = function (value) { var _a, _b; (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value); }; AnonymousSubject.prototype.error = function (err) { var _a, _b; (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err); }; AnonymousSubject.prototype.complete = function () { var _a, _b; (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a); }; AnonymousSubject.prototype._subscribe = function (subscriber) { var _a, _b; return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION; }; return AnonymousSubject; }(Subject)); var BehaviorSubject = (function (_super) { __extends(BehaviorSubject, _super); function BehaviorSubject(_value) { var _this = _super.call(this) || this; _this._value = _value; return _this; } Object.defineProperty(BehaviorSubject.prototype, "value", { get: function () { return this.getValue(); }, enumerable: false, configurable: true }); BehaviorSubject.prototype._subscribe = function (subscriber) { var subscription = _super.prototype._subscribe.call(this, subscriber); !subscription.closed && subscriber.next(this._value); return subscription; }; BehaviorSubject.prototype.getValue = function () { var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value; if (hasError) { throw thrownError; } this._throwIfClosed(); return _value; }; BehaviorSubject.prototype.next = function (value) { _super.prototype.next.call(this, (this._value = value)); }; return BehaviorSubject; }(Subject)); var dateTimestampProvider = { now: function () { return (dateTimestampProvider.delegate || Date).now(); }, delegate: undefined, }; var ReplaySubject = (function (_super) { __extends(ReplaySubject, _super); function ReplaySubject(_bufferSize, _windowTime, _timestampProvider) { if (_bufferSize === void 0) { _bufferSize = Infinity; } if (_windowTime === void 0) { _windowTime = Infinity; } if (_timestampProvider === void 0) { _timestampProvider = dateTimestampProvider; } var _this = _super.call(this) || this; _this._bufferSize = _bufferSize; _this._windowTime = _windowTime; _this._timestampProvider = _timestampProvider; _this._buffer = []; _this._infiniteTimeWindow = true; _this._infiniteTimeWindow = _windowTime === Infinity; _this._bufferSize = Math.max(1, _bufferSize); _this._windowTime = Math.max(1, _windowTime); return _this; } ReplaySubject.prototype.next = function (value) { var _a = this, isStopped = _a.isStopped, _buffer = _a._buffer, _infiniteTimeWindow = _a._infiniteTimeWindow, _timestampProvider = _a._timestampProvider, _windowTime = _a._windowTime; if (!isStopped) { _buffer.push(value); !_infiniteTimeWindow && _buffer.push(_timestampProvider.now() + _windowTime); } this._trimBuffer(); _super.prototype.next.call(this, value); }; ReplaySubject.prototype._subscribe = function (subscriber) { this._throwIfClosed(); this._trimBuffer(); var subscription = this._innerSubscribe(subscriber); var _a = this, _infiniteTimeWindow = _a._infiniteTimeWindow, _buffer = _a._buffer; var copy = _buffer.slice(); for (var i = 0; i < copy.length && !subscriber.closed; i += _infiniteTimeWindow ? 1 : 2) { subscriber.next(copy[i]); } this._checkFinalizedStatuses(subscriber); return subscription; }; ReplaySubject.prototype._trimBuffer = function () { var _a = this, _bufferSize = _a._bufferSize, _timestampProvider = _a._timestampProvider, _buffer = _a._buffer, _infiniteTimeWindow = _a._infiniteTimeWindow; var adjustedBufferSize = (_infiniteTimeWindow ? 1 : 2) * _bufferSize; _bufferSize < Infinity && adjustedBufferSize < _buffer.length && _buffer.splice(0, _buffer.length - adjustedBufferSize); if (!_infiniteTimeWindow) { var now = _timestampProvider.now(); var last = 0; for (var i = 1; i < _buffer.length && _buffer[i] <= now; i += 2) { last = i; } last && _buffer.splice(0, last + 1); } }; return ReplaySubject; }(Subject)); var Action = (function (_super) { __extends(Action, _super); function Action(scheduler, work) { return _super.call(this) || this; } Action.prototype.schedule = function (state, delay) { return this; }; return Action; }(Subscription)); var intervalProvider = { setInterval: function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var delegate = intervalProvider.delegate; return ((delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) || setInterval).apply(void 0, __spreadArray([], __read(args))); }, clearInterval: function (handle) { var delegate = intervalProvider.delegate; return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle); }, delegate: undefined, }; var AsyncAction = (function (_super) { __extends(AsyncAction, _super); function AsyncAction(scheduler, work) { var _this = _super.call(this, scheduler, work) || this; _this.scheduler = scheduler; _this.work = work; _this.pending = false; return _this; } AsyncAction.prototype.schedule = function (state, delay) { if (delay === void 0) { delay = 0; } if (this.closed) { return this; } this.state = state; var id = this.id; var scheduler = this.scheduler; if (id != null) { this.id = this.recycleAsyncId(scheduler, id, delay); } this.pending = true; this.delay = delay; this.id = this.id || this.requestAsyncId(scheduler, this.id, delay); return this; }; AsyncAction.prototype.requestAsyncId = function (scheduler, _id, delay) { if (delay === void 0) { delay = 0; } return intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay); }; AsyncAction.prototype.recycleAsyncId = function (_scheduler, id, delay) { if (delay === void 0) { delay = 0; } if (delay != null && this.delay === delay && this.pending === false) { return id; } intervalProvider.clearInterval(id); return undefined; }; AsyncAction.prototype.execute = function (state, delay) { if (this.closed) { return new Error('executing a cancelled action'); } this.pending = false; var error = this._execute(state, delay); if (error) { return error; } else if (this.pending === false && this.id != null) { this.id = this.recycleAsyncId(this.scheduler, this.id, null); } }; AsyncAction.prototype._execute = function (state, _delay) { var errored = false; var errorValue; try { this.work(state); } catch (e) { errored = true; errorValue = (!!e && e) || new Error(e); } if (errored) { this.unsubscribe(); return errorValue; } }; AsyncAction.prototype.unsubscribe = function () { if (!this.closed) { var _a = this, id = _a.id, scheduler = _a.scheduler; var actions = scheduler.actions; this.work = this.state = this.scheduler = null; this.pending = false; arrRemove(actions, this); if (id != null) { this.id = this.recycleAsyncId(scheduler, id, null); } this.delay = null; _super.prototype.unsubscribe.call(this); } }; return AsyncAction; }(Action)); var Scheduler = (function () { function Scheduler(schedulerActionCtor, now) { if (now === void 0) { now = Scheduler.now; } this.schedulerActionCtor = schedulerActionCtor; this.now = now; } Scheduler.prototype.schedule = function (work, delay, state) { if (delay === void 0) { delay = 0; } return new this.schedulerActionCtor(this, work).schedule(state, delay); }; Scheduler.now = dateTimestampProvider.now; return Scheduler; }()); var AsyncScheduler = (function (_super) { __extends(AsyncScheduler, _super); function AsyncScheduler(SchedulerAction, now) { if (now === void 0) { now = Scheduler.now; } var _this = _super.call(this, SchedulerAction, now) || this; _this.actions = []; _this._active = false; _this._scheduled = undefined; return _this; } AsyncScheduler.prototype.flush = function (action) { var actions = this.actions; if (this._active) { actions.push(action); return; } var error; this._active = true; do { if ((error = action.execute(action.state, action.delay))) { break; } } while ((action = actions.shift())); this._active = false; if (error) { while ((action = actions.shift())) { action.unsubscribe(); } throw error; } }; return AsyncScheduler; }(Scheduler)); var asyncScheduler = new AsyncScheduler(AsyncAction); var async = asyncScheduler; var EMPTY$1 = new Observable(function (subscriber) { return subscriber.complete(); }); function empty(scheduler) { return scheduler ? emptyScheduled(scheduler) : EMPTY$1; } function emptyScheduled(scheduler) { return new Observable(function (subscriber) { return scheduler.schedule(function () { return subscriber.complete(); }); }); } function scheduleArray(input, scheduler) { return new Observable(function (subscriber) { var i = 0; return scheduler.schedule(function () { if (i === input.length) { subscriber.complete(); } else { subscriber.next(input[i++]); if (!subscriber.closed) { this.schedule(); } } }); }); } var isArrayLike = (function (x) { return x && typeof x.length === 'number' && typeof x !== 'function'; }); function isPromise(value) { return isFunction(value === null || value === void 0 ? void 0 : value.then); } function scheduleObservable(input, scheduler) { return new Observable(function (subscriber) { var sub = new Subscription(); sub.add(scheduler.schedule(function () { var observable$1 = input[observable](); sub.add(observable$1.subscribe({ next: function (value) { sub.add(scheduler.schedule(function () { return subscriber.next(value); })); }, error: function (err) { sub.add(scheduler.schedule(function () { return subscriber.error(err); })); }, complete: function () { sub.add(scheduler.schedule(function () { return subscriber.complete(); })); }, })); })); return sub; }); } function schedulePromise(input, scheduler) { return new Observable(function (subscriber) { return scheduler.schedule(function () { return input.then(function (value) { subscriber.add(scheduler.schedule(function () { subscriber.next(value); subscriber.add(scheduler.schedule(function () { return subscriber.complete(); })); })); }, function (err) { subscriber.add(scheduler.schedule(function () { return subscriber.error(err); })); }); }); }); } function getSymbolIterator() { if (typeof Symbol !== 'function' || !Symbol.iterator) { return '@@iterator'; } return Symbol.iterator; } var iterator = getSymbolIterator(); function caughtSchedule(subscriber, scheduler, execute, delay) { if (delay === void 0) { delay = 0; } var subscription = scheduler.schedule(function () { try { execute.call(this); } catch (err) { subscriber.error(err); } }, delay); subscriber.add(subscription); return subscription; } function scheduleIterable(input, scheduler) { return new Observable(function (subscriber) { var iterator$1; subscriber.add(scheduler.schedule(function () { iterator$1 = input[iterator](); caughtSchedule(subscriber, scheduler, function () { var _a = iterator$1.next(), value = _a.value, done = _a.done; if (done) { subscriber.complete(); } else { subscriber.next(value); this.schedule(); } }); })); return function () { return isFunction(iterator$1 === null || iterator$1 === void 0 ? void 0 : iterator$1.return) && iterator$1.return(); }; }); } function scheduleAsyncIterable(input, scheduler) { if (!input) { throw new Error('Iterable cannot be null'); } return new Observable(function (subscriber) { var sub = new Subscription(); sub.add(scheduler.schedule(function () { var iterator = input[Symbol.asyncIterator](); sub.add(scheduler.schedule(function () { var _this = this; iterator.next().then(function (result) { if (result.done) { subscriber.complete(); } else { subscriber.next(result.value); _this.schedule(); } }); })); })); return sub; }); } function isInteropObservable(input) { return isFunction(input[observable]); } function isIterable(input) { return isFunction(input === null || input === void 0 ? void 0 : input[iterator]); } function isAsyncIterable(obj) { return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]); } function createInvalidObservableTypeError(input) { return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable."); } function readableStreamLikeToAsyncGenerator(readableStream) { return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() { var reader, _a, value, done; return __generator(this, function (_b) { switch (_b.label) { case 0: reader = readableStream.getReader(); _b.label = 1; case 1: _b.trys.push([1, , 9, 10]); _b.label = 2; case 2: return [4, __await(reader.read())]; case 3: _a = _b.sent(), value = _a.value, done = _a.done; if (!done) return [3, 5]; return [4, __await(void 0)]; case 4: return [2, _b.sent()]; case 5: return [4, __await(value)]; case 6: return [4, _b.sent()]; case 7: _b.sent(); return [3, 2]; case 8: return [3, 10]; case 9: reader.releaseLock(); return [7]; case 10: return [2]; } }); }); } function isReadableStreamLike(obj) { return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader); } function scheduleReadableStreamLike(input, scheduler) { return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler); } function scheduled(input, scheduler) { if (input != null) { if (isInteropObservable(input)) { return scheduleObservable(input, scheduler); } if (isArrayLike(input)) { return scheduleArray(input, scheduler); } if (isPromise(input)) { return schedulePromise(input, scheduler); } if (isAsyncIterable(input)) { return scheduleAsyncIterable(input, scheduler); } if (isIterable(input))