on-screen-keyboard-detector
Version:
Detects presence of the On-Screen-Keyboard in mobile browsers
1,679 lines (1,567 loc) • 73.9 kB
JavaScript
/* @license
On-screen keyboard detector (OSKD) v.2.3.0
(c) 2020-2021 Matthias Seemann
OSKD may be freely distributed under the MIT license.
*/
function _isPlaceholder(a) {
return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true;
}
/**
* Optimized internal one-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
function _curry1(fn) {
return function f1(a) {
if (arguments.length === 0 || _isPlaceholder(a)) {
return f1;
} else {
return fn.apply(this, arguments);
}
};
}
/**
* Optimized internal two-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
function _curry2(fn) {
return function f2(a, b) {
switch (arguments.length) {
case 0:
return f2;
case 1:
return _isPlaceholder(a) ? f2 : _curry1(function (_b) {
return fn(a, _b);
});
default:
return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function (_a) {
return fn(_a, b);
}) : _isPlaceholder(b) ? _curry1(function (_b) {
return fn(a, _b);
}) : fn(a, b);
}
};
}
function _arity(n, fn) {
/* eslint-disable no-unused-vars */
switch (n) {
case 0:
return function () {
return fn.apply(this, arguments);
};
case 1:
return function (a0) {
return fn.apply(this, arguments);
};
case 2:
return function (a0, a1) {
return fn.apply(this, arguments);
};
case 3:
return function (a0, a1, a2) {
return fn.apply(this, arguments);
};
case 4:
return function (a0, a1, a2, a3) {
return fn.apply(this, arguments);
};
case 5:
return function (a0, a1, a2, a3, a4) {
return fn.apply(this, arguments);
};
case 6:
return function (a0, a1, a2, a3, a4, a5) {
return fn.apply(this, arguments);
};
case 7:
return function (a0, a1, a2, a3, a4, a5, a6) {
return fn.apply(this, arguments);
};
case 8:
return function (a0, a1, a2, a3, a4, a5, a6, a7) {
return fn.apply(this, arguments);
};
case 9:
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) {
return fn.apply(this, arguments);
};
case 10:
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
return fn.apply(this, arguments);
};
default:
throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
}
}
/**
* Optimized internal three-arity curry function.
*
* @private
* @category Function
* @param {Function} fn The function to curry.
* @return {Function} The curried function.
*/
function _curry3(fn) {
return function f3(a, b, c) {
switch (arguments.length) {
case 0:
return f3;
case 1:
return _isPlaceholder(a) ? f3 : _curry2(function (_b, _c) {
return fn(a, _b, _c);
});
case 2:
return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function (_a, _c) {
return fn(_a, b, _c);
}) : _isPlaceholder(b) ? _curry2(function (_b, _c) {
return fn(a, _b, _c);
}) : _curry1(function (_c) {
return fn(a, b, _c);
});
default:
return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function (_a, _b) {
return fn(_a, _b, c);
}) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function (_a, _c) {
return fn(_a, b, _c);
}) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function (_b, _c) {
return fn(a, _b, _c);
}) : _isPlaceholder(a) ? _curry1(function (_a) {
return fn(_a, b, c);
}) : _isPlaceholder(b) ? _curry1(function (_b) {
return fn(a, _b, c);
}) : _isPlaceholder(c) ? _curry1(function (_c) {
return fn(a, b, _c);
}) : fn(a, b, c);
}
};
}
/**
* Tests whether or not an object is an array.
*
* @private
* @param {*} val The object to test.
* @return {Boolean} `true` if `val` is an array, `false` otherwise.
* @example
*
* _isArray([]); //=> true
* _isArray(null); //=> false
* _isArray({}); //=> false
*/
const _isArray = Array.isArray || function _isArray(val) {
return val != null && val.length >= 0 && Object.prototype.toString.call(val) === '[object Array]';
};
function _isString(x) {
return Object.prototype.toString.call(x) === '[object String]';
}
/**
* Tests whether or not an object is similar to an array.
*
* @private
* @category Type
* @category List
* @sig * -> Boolean
* @param {*} x The object to test.
* @return {Boolean} `true` if `x` has a numeric length property and extreme indices defined; `false` otherwise.
* @example
*
* _isArrayLike([]); //=> true
* _isArrayLike(true); //=> false
* _isArrayLike({}); //=> false
* _isArrayLike({length: 10}); //=> false
* _isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true
*/
var _isArrayLike =
/*#__PURE__*/
_curry1(function isArrayLike(x) {
if (_isArray(x)) {
return true;
}
if (!x) {
return false;
}
if (typeof x !== 'object') {
return false;
}
if (_isString(x)) {
return false;
}
if (x.nodeType === 1) {
return !!x.length;
}
if (x.length === 0) {
return true;
}
if (x.length > 0) {
return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1);
}
return false;
});
var XWrap =
/*#__PURE__*/
function () {
function XWrap(fn) {
this.f = fn;
}
XWrap.prototype['@@transducer/init'] = function () {
throw new Error('init not implemented on XWrap');
};
XWrap.prototype['@@transducer/result'] = function (acc) {
return acc;
};
XWrap.prototype['@@transducer/step'] = function (acc, x) {
return this.f(acc, x);
};
return XWrap;
}();
function _xwrap(fn) {
return new XWrap(fn);
}
/**
* Creates a function that is bound to a context.
* Note: `R.bind` does not provide the additional argument-binding capabilities of
* [Function.prototype.bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
*
* @func
* @memberOf R
* @since v0.6.0
* @category Function
* @category Object
* @sig (* -> *) -> {*} -> (* -> *)
* @param {Function} fn The function to bind to context
* @param {Object} thisObj The context to bind `fn` to
* @return {Function} A function that will execute in the context of `thisObj`.
* @see R.partial
* @example
*
* const log = R.bind(console.log, console);
* R.pipe(R.assoc('a', 2), R.tap(log), R.assoc('a', 3))({a: 1}); //=> {a: 3}
* // logs {a: 2}
* @symb R.bind(f, o)(a, b) = f.call(o, a, b)
*/
var bind =
/*#__PURE__*/
_curry2(function bind(fn, thisObj) {
return _arity(fn.length, function () {
return fn.apply(thisObj, arguments);
});
});
function _arrayReduce(xf, acc, list) {
var idx = 0;
var len = list.length;
while (idx < len) {
acc = xf['@@transducer/step'](acc, list[idx]);
if (acc && acc['@@transducer/reduced']) {
acc = acc['@@transducer/value'];
break;
}
idx += 1;
}
return xf['@@transducer/result'](acc);
}
function _iterableReduce(xf, acc, iter) {
var step = iter.next();
while (!step.done) {
acc = xf['@@transducer/step'](acc, step.value);
if (acc && acc['@@transducer/reduced']) {
acc = acc['@@transducer/value'];
break;
}
step = iter.next();
}
return xf['@@transducer/result'](acc);
}
function _methodReduce(xf, acc, obj, methodName) {
return xf['@@transducer/result'](obj[methodName](bind(xf['@@transducer/step'], xf), acc));
}
var symIterator = typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator';
function _reduce(fn, acc, list) {
if (typeof fn === 'function') {
fn = _xwrap(fn);
}
if (_isArrayLike(list)) {
return _arrayReduce(fn, acc, list);
}
if (typeof list['fantasy-land/reduce'] === 'function') {
return _methodReduce(fn, acc, list, 'fantasy-land/reduce');
}
if (list[symIterator] != null) {
return _iterableReduce(fn, acc, list[symIterator]());
}
if (typeof list.next === 'function') {
return _iterableReduce(fn, acc, list);
}
if (typeof list.reduce === 'function') {
return _methodReduce(fn, acc, list, 'reduce');
}
throw new TypeError('reduce: list must be array or iterable');
}
/**
* Returns a single item by iterating through the list, successively calling
* the iterator function and passing it an accumulator value and the current
* value from the array, and then passing the result to the next call.
*
* The iterator function receives two values: *(acc, value)*. It may use
* [`R.reduced`](#reduced) to shortcut the iteration.
*
* The arguments' order of [`reduceRight`](#reduceRight)'s iterator function
* is *(value, acc)*.
*
* Note: `R.reduce` does not skip deleted or unassigned indices (sparse
* arrays), unlike the native `Array.prototype.reduce` method. For more details
* on this behavior, see:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description
*
* Dispatches to the `reduce` method of the third argument, if present. When
* doing so, it is up to the user to handle the [`R.reduced`](#reduced)
* shortcuting, as this is not implemented by `reduce`.
*
* @func
* @memberOf R
* @since v0.1.0
* @category List
* @sig ((a, b) -> a) -> a -> [b] -> a
* @param {Function} fn The iterator function. Receives two values, the accumulator and the
* current element from the array.
* @param {*} acc The accumulator value.
* @param {Array} list The list to iterate over.
* @return {*} The final, accumulated value.
* @see R.reduced, R.addIndex, R.reduceRight
* @example
*
* R.reduce(R.subtract, 0, [1, 2, 3, 4]) // => ((((0 - 1) - 2) - 3) - 4) = -10
* // - -10
* // / \ / \
* // - 4 -6 4
* // / \ / \
* // - 3 ==> -3 3
* // / \ / \
* // - 2 -1 2
* // / \ / \
* // 0 1 0 1
*
* @symb R.reduce(f, a, [b, c, d]) = f(f(f(a, b), c), d)
*/
var reduce =
/*#__PURE__*/
_curry3(_reduce);
function _pipe(f, g) {
return function () {
return g.call(this, f.apply(this, arguments));
};
}
/**
* This checks whether a function has a [methodname] function. If it isn't an
* array it will execute that function otherwise it will default to the ramda
* implementation.
*
* @private
* @param {Function} fn ramda implemtation
* @param {String} methodname property to check for a custom implementation
* @return {Object} Whatever the return value of the method is.
*/
function _checkForMethod(methodname, fn) {
return function () {
var length = arguments.length;
if (length === 0) {
return fn();
}
var obj = arguments[length - 1];
return _isArray(obj) || typeof obj[methodname] !== 'function' ? fn.apply(this, arguments) : obj[methodname].apply(obj, Array.prototype.slice.call(arguments, 0, length - 1));
};
}
/**
* Returns the elements of the given list or string (or object with a `slice`
* method) from `fromIndex` (inclusive) to `toIndex` (exclusive).
*
* Dispatches to the `slice` method of the third argument, if present.
*
* @func
* @memberOf R
* @since v0.1.4
* @category List
* @sig Number -> Number -> [a] -> [a]
* @sig Number -> Number -> String -> String
* @param {Number} fromIndex The start index (inclusive).
* @param {Number} toIndex The end index (exclusive).
* @param {*} list
* @return {*}
* @example
*
* R.slice(1, 3, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
* R.slice(1, Infinity, ['a', 'b', 'c', 'd']); //=> ['b', 'c', 'd']
* R.slice(0, -1, ['a', 'b', 'c', 'd']); //=> ['a', 'b', 'c']
* R.slice(-3, -1, ['a', 'b', 'c', 'd']); //=> ['b', 'c']
* R.slice(0, 3, 'ramda'); //=> 'ram'
*/
var slice =
/*#__PURE__*/
_curry3(
/*#__PURE__*/
_checkForMethod('slice', function slice(fromIndex, toIndex, list) {
return Array.prototype.slice.call(list, fromIndex, toIndex);
}));
/**
* Returns all but the first element of the given list or string (or object
* with a `tail` method).
*
* Dispatches to the `slice` method of the first argument, if present.
*
* @func
* @memberOf R
* @since v0.1.0
* @category List
* @sig [a] -> [a]
* @sig String -> String
* @param {*} list
* @return {*}
* @see R.head, R.init, R.last
* @example
*
* R.tail([1, 2, 3]); //=> [2, 3]
* R.tail([1, 2]); //=> [2]
* R.tail([1]); //=> []
* R.tail([]); //=> []
*
* R.tail('abc'); //=> 'bc'
* R.tail('ab'); //=> 'b'
* R.tail('a'); //=> ''
* R.tail(''); //=> ''
*/
var tail =
/*#__PURE__*/
_curry1(
/*#__PURE__*/
_checkForMethod('tail',
/*#__PURE__*/
slice(1, Infinity)));
/**
* Performs left-to-right function composition. The first argument may have
* any arity; the remaining arguments must be unary.
*
* In some libraries this function is named `sequence`.
*
* **Note:** The result of pipe is not automatically curried.
*
* @func
* @memberOf R
* @since v0.1.0
* @category Function
* @sig (((a, b, ..., n) -> o), (o -> p), ..., (x -> y), (y -> z)) -> ((a, b, ..., n) -> z)
* @param {...Function} functions
* @return {Function}
* @see R.compose
* @example
*
* const f = R.pipe(Math.pow, R.negate, R.inc);
*
* f(3, 4); // -(3^4) + 1
* @symb R.pipe(f, g, h)(a, b) = h(g(f(a, b)))
*/
function pipe() {
if (arguments.length === 0) {
throw new Error('pipe requires at least one argument');
}
return _arity(arguments[0].length, reduce(_pipe, arguments[0], tail(arguments)));
}
// Read the current time from the provided Scheduler
var currentTime = function (scheduler) { return scheduler.currentTime(); };
/** @license MIT License (c) copyright 2015-2016 original author or authors */
/** @author Brian Cavalier */
// domEvent :: (EventTarget t, Event e) => String -> t -> boolean=false -> Stream e
var domEvent = function (event, node, capture) {
if ( capture === void 0 ) capture = false;
return new DomEvent(event, node, capture);
};
var resize = function (node, capture) {
if ( capture === void 0 ) capture = false;
return domEvent('resize', node, capture);
};
var scroll = function (node, capture) {
if ( capture === void 0 ) capture = false;
return domEvent('scroll', node, capture);
};
var DomEvent = function DomEvent (event, node, capture) {
this.event = event;
this.node = node;
this.capture = capture;
};
DomEvent.prototype.run = function run (sink, scheduler$$1) {
var this$1 = this;
var send = function (e) { return tryEvent(currentTime(scheduler$$1), e, sink); };
var dispose = function () { return this$1.node.removeEventListener(this$1.event, send, this$1.capture); };
this.node.addEventListener(this.event, send, this.capture);
return { dispose: dispose }
};
function tryEvent (t, x, sink) {
try {
sink.event(t, x);
} catch (e) {
sink.error(t, e);
}
}
/** @license MIT License (c) copyright 2010-2016 original author or authors */
/**
* transform each element with f
*/
function map(f, a) {
var l = a.length;
var b = new Array(l);
for (var i = 0; i < l; ++i) {
b[i] = f(a[i]);
}
return b;
}
/**
* accumulate via left-fold
*/
function reduce$1(f, z, a) {
var r = z;
for (var i = 0, l = a.length; i < l; ++i) {
r = f(r, a[i], i);
}
return r;
}
var compose = function (f, g) { return function (x) { return f(g(x)); }; };
function curry2(f) {
function curried(a, b) {
switch (arguments.length) {
case 0: return curried;
case 1: return function (b) { return f(a, b); };
default: return f(a, b);
}
}
return curried;
}
function curry3(f) {
function curried(a, b, c) {
switch (arguments.length) {
case 0: return curried;
case 1: return curry2(function (b, c) { return f(a, b, c); });
case 2: return function (c) { return f(a, b, c); };
default: return f(a, b, c);
}
}
return curried;
}
var RelativeScheduler = /** @class */ (function () {
function RelativeScheduler(origin, scheduler) {
this.origin = origin;
this.scheduler = scheduler;
}
RelativeScheduler.prototype.currentTime = function () {
return this.scheduler.currentTime() - this.origin;
};
RelativeScheduler.prototype.scheduleTask = function (localOffset, delay, period, task) {
return this.scheduler.scheduleTask(localOffset + this.origin, delay, period, task);
};
RelativeScheduler.prototype.relative = function (origin) {
return new RelativeScheduler(origin + this.origin, this.scheduler);
};
RelativeScheduler.prototype.cancel = function (task) {
return this.scheduler.cancel(task);
};
RelativeScheduler.prototype.cancelAll = function (f) {
return this.scheduler.cancelAll(f);
};
return RelativeScheduler;
}());
/**
* Schedule a task to run as soon as possible, but
* not in the current call stack
*/
var asap = curry2(function (task, scheduler) {
return scheduler.scheduleTask(0, 0, -1, task);
});
/**
* Schedule a task to run after a millisecond delay
*/
var delay = curry3(function (delay, task, scheduler) {
return scheduler.scheduleTask(0, delay, -1, task);
});
/**
* Cancel a scheduledTask
*/
var cancelTask = function (scheduledTask) {
return scheduledTask.dispose();
};
var schedulerRelativeTo = curry2(function (offset, scheduler) {
return new RelativeScheduler(offset, scheduler);
});
/** @license MIT License (c) copyright 2010-2016 original author or authors */
/**
* a with x appended
*/
function append(x, a) {
var l = a.length;
var b = new Array(l + 1);
for (var i = 0; i < l; ++i) {
b[i] = a[i];
}
b[l] = x;
return b;
}
/**
* Concats two `ArrayLike`s
*/
function concat(a, b) {
var al = a.length;
var bl = b.length;
var r = new Array(al + bl);
var i = 0;
for (i = 0; i < al; i++) {
r[i] = a[i];
}
for (var j = 0; j < bl; j++) {
r[i++] = b[j];
}
return r;
}
/**
* accumulate via left-fold
*/
function reduce$2(f, z, a) {
var r = z;
for (var i = 0, l = a.length; i < l; ++i) {
r = f(r, a[i], i);
}
return r;
}
function curry2$1(f) {
function curried(a, b) {
switch (arguments.length) {
case 0: return curried;
case 1: return function (b) { return f(a, b); };
default: return f(a, b);
}
}
return curried;
}
function curry3$1(f) {
function curried(a, b, c) {
switch (arguments.length) {
case 0: return curried;
case 1: return curry2$1(function (b, c) { return f(a, b, c); });
case 2: return function (c) { return f(a, b, c); };
default: return f(a, b, c);
}
}
return curried;
}
var disposeNone = function () { return NONE; };
var NONE = new (/** @class */ (function () {
function DisposeNone() {
}
DisposeNone.prototype.dispose = function () { };
return DisposeNone;
}()))();
var isDisposeNone = function (d) {
return d === NONE;
};
/**
* Wrap an existing disposable (which may not already have been once()d)
* so that it will only dispose its underlying resource at most once.
*/
var disposeOnce = function (disposable) {
return new DisposeOnce(disposable);
};
var DisposeOnce = /** @class */ (function () {
function DisposeOnce(disposable) {
this.disposed = false;
this.disposable = disposable;
}
DisposeOnce.prototype.dispose = function () {
if (!this.disposed) {
this.disposed = true;
if (this.disposable) {
this.disposable.dispose();
this.disposable = undefined;
}
}
};
return DisposeOnce;
}());
/** @license MIT License (c) copyright 2010 original author or authors */
/**
* Aggregate a list of disposables into a DisposeAll
*/
var disposeAll = function (ds) {
var merged = reduce$2(merge, [], ds);
return merged.length === 0 ? disposeNone() : new DisposeAll(merged);
};
/**
* Convenience to aggregate 2 disposables
*/
var disposeBoth = curry2$1(function (d1, d2) {
return disposeAll([d1, d2]);
});
var merge = function (ds, d) {
return isDisposeNone(d) ? ds
: d instanceof DisposeAll ? concat(ds, d.disposables)
: append(d, ds);
};
var DisposeAll = /** @class */ (function () {
function DisposeAll(disposables) {
this.disposables = disposables;
}
DisposeAll.prototype.dispose = function () {
throwIfErrors(disposeCollectErrors(this.disposables));
};
return DisposeAll;
}());
/**
* Dispose all, safely collecting errors into an array
*/
var disposeCollectErrors = function (disposables) {
return reduce$2(appendIfError, [], disposables);
};
/**
* Call dispose and if throws, append thrown error to errors
*/
var appendIfError = function (errors, d) {
try {
d.dispose();
}
catch (e) {
errors.push(e);
}
return errors;
};
/**
* Throw DisposeAllError if errors is non-empty
* @throws
*/
var throwIfErrors = function (errors) {
if (errors.length > 0) {
throw new DisposeAllError(errors.length + " errors", errors);
}
};
var DisposeAllError = /** @class */ (function () {
function DisposeAllError(message, errors) {
this.name = 'DisposeAllError';
this.message = message;
this.errors = errors;
Error.call(this, message);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, DisposeAllError);
}
this.stack = "" + this.stack + formatErrorStacks(this.errors);
}
return DisposeAllError;
}());
DisposeAllError.prototype = Object.create(Error.prototype);
var formatErrorStacks = function (errors) {
return reduce$2(formatErrorStack, '', errors);
};
var formatErrorStack = function (s, e, i) {
return s + ("\n[" + (i + 1) + "] " + e.stack);
};
/** @license MIT License (c) copyright 2010-2017 original author or authors */
// Try to dispose the disposable. If it throws, send
// the error to sink.error with the provided Time value
var tryDispose = curry3$1(function (t, disposable, sink) {
try {
disposable.dispose();
}
catch (e) {
sink.error(t, e);
}
});
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* 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 (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
/** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
function fatalError(e) {
setTimeout(rethrow, 0, e);
}
function rethrow(e) {
throw e;
}
var propagateEventTask = function (value, sink) { return new PropagateEventTask(value, sink); };
var propagateEndTask = function (sink) { return new PropagateEndTask(sink); };
var PropagateTask = /** @class */ (function () {
function PropagateTask(sink) {
this.sink = sink;
this.active = true;
}
PropagateTask.prototype.dispose = function () {
this.active = false;
};
PropagateTask.prototype.run = function (t) {
if (!this.active) {
return;
}
this.runIfActive(t);
};
PropagateTask.prototype.error = function (t, e) {
// TODO: Remove this check and just do this.sink.error(t, e)?
if (!this.active) {
return fatalError(e);
}
this.sink.error(t, e);
};
return PropagateTask;
}());
var PropagateRunEventTask = /** @class */ (function (_super) {
__extends(PropagateRunEventTask, _super);
function PropagateRunEventTask(runEvent, value, sink) {
var _this = _super.call(this, sink) || this;
_this.runEvent = runEvent;
_this.value = value;
return _this;
}
PropagateRunEventTask.prototype.runIfActive = function (t) {
this.runEvent(t, this.value, this.sink);
};
return PropagateRunEventTask;
}(PropagateTask));
var PropagateEventTask = /** @class */ (function (_super) {
__extends(PropagateEventTask, _super);
function PropagateEventTask(value, sink) {
var _this = _super.call(this, sink) || this;
_this.value = value;
return _this;
}
PropagateEventTask.prototype.runIfActive = function (t) {
this.sink.event(t, this.value);
};
return PropagateEventTask;
}(PropagateTask));
var PropagateEndTask = /** @class */ (function (_super) {
__extends(PropagateEndTask, _super);
function PropagateEndTask() {
return _super !== null && _super.apply(this, arguments) || this;
}
PropagateEndTask.prototype.runIfActive = function (t) {
this.sink.end(t);
};
return PropagateEndTask;
}(PropagateTask));
var PropagateErrorTask = /** @class */ (function (_super) {
__extends(PropagateErrorTask, _super);
function PropagateErrorTask(value, sink) {
var _this = _super.call(this, sink) || this;
_this.value = value;
return _this;
}
PropagateErrorTask.prototype.runIfActive = function (t) {
this.sink.error(t, this.value);
};
return PropagateErrorTask;
}(PropagateTask));
/** @license MIT License (c) copyright 2010-2017 original author or authors */
var empty = function () { return EMPTY; };
var isCanonicalEmpty = function (stream) {
return stream === EMPTY;
};
var Empty = /** @class */ (function () {
function Empty() {
}
Empty.prototype.run = function (sink, scheduler) {
return asap(propagateEndTask(sink), scheduler);
};
return Empty;
}());
var EMPTY = new Empty();
var SettableDisposable = /** @class */ (function () {
function SettableDisposable() {
this.disposable = undefined;
this.disposed = false;
}
SettableDisposable.prototype.setDisposable = function (disposable) {
if (this.disposable !== undefined) {
throw new Error('setDisposable called more than once');
}
this.disposable = disposable;
if (this.disposed) {
disposable.dispose();
}
};
SettableDisposable.prototype.dispose = function () {
if (this.disposed) {
return;
}
this.disposed = true;
if (this.disposable !== undefined) {
this.disposable.dispose();
}
};
return SettableDisposable;
}());
/** @license MIT License (c) copyright 2010-2017 original author or authors */
var runEffects = curry2(function (stream, scheduler) {
return new Promise(function (resolve, reject) {
return runStream(stream, scheduler, resolve, reject);
});
});
function runStream(stream, scheduler, resolve, reject) {
var disposable = new SettableDisposable();
var observer = new RunEffectsSink(resolve, reject, disposable);
disposable.setDisposable(stream.run(observer, scheduler));
}
var RunEffectsSink = /** @class */ (function () {
function RunEffectsSink(end, error, disposable) {
this._end = end;
this._error = error;
this._disposable = disposable;
this.active = true;
}
RunEffectsSink.prototype.event = function () { };
RunEffectsSink.prototype.end = function () {
if (!this.active) {
return;
}
this.dispose(this._error, this._end, undefined);
};
RunEffectsSink.prototype.error = function (_t, e) {
this.dispose(this._error, this._error, e);
};
RunEffectsSink.prototype.dispose = function (error, end, x) {
this.active = false;
tryDispose$1(error, end, x, this._disposable);
};
return RunEffectsSink;
}());
function tryDispose$1(error, end, x, disposable) {
try {
disposable.dispose();
}
catch (e) {
error(e);
return;
}
end(x);
}
/**
* Run a Stream, sending all its events to the provided Sink.
*/
var run = function (sink, scheduler, stream) {
return stream.run(sink, scheduler);
};
var RelativeSink = /** @class */ (function () {
function RelativeSink(offset, sink) {
this.sink = sink;
this.offset = offset;
}
RelativeSink.prototype.event = function (t, x) {
this.sink.event(t + this.offset, x);
};
RelativeSink.prototype.error = function (t, e) {
this.sink.error(t + this.offset, e);
};
RelativeSink.prototype.end = function (t) {
this.sink.end(t + this.offset);
};
return RelativeSink;
}());
/**
* Create a stream with its own local clock
* This transforms time from the provided scheduler's clock to a stream-local
* clock (which starts at 0), and then *back* to the scheduler's clock before
* propagating events to sink. In other words, upstream sources will see local times,
* and downstream sinks will see non-local (original) times.
*/
var withLocalTime = function (origin, stream) {
return new WithLocalTime(origin, stream);
};
var WithLocalTime = /** @class */ (function () {
function WithLocalTime(origin, source) {
this.origin = origin;
this.source = source;
}
WithLocalTime.prototype.run = function (sink, scheduler) {
return this.source.run(relativeSink(this.origin, sink), schedulerRelativeTo(this.origin, scheduler));
};
return WithLocalTime;
}());
/**
* Accumulate offsets instead of nesting RelativeSinks, which can happen
* with higher-order stream and combinators like continueWith when they're
* applied recursively.
*/
var relativeSink = function (origin, sink) {
return sink instanceof RelativeSink
? new RelativeSink(origin + sink.offset, sink.sink)
: new RelativeSink(origin, sink);
};
var Pipe = /** @class */ (function () {
function Pipe(sink) {
this.sink = sink;
}
Pipe.prototype.end = function (t) {
return this.sink.end(t);
};
Pipe.prototype.error = function (t, e) {
return this.sink.error(t, e);
};
return Pipe;
}());
var LoopSink = /** @class */ (function (_super) {
__extends(LoopSink, _super);
function LoopSink(stepper, seed, sink) {
var _this = _super.call(this, sink) || this;
_this.step = stepper;
_this.seed = seed;
return _this;
}
LoopSink.prototype.event = function (t, x) {
var result = this.step(this.seed, x);
this.seed = result.seed;
this.sink.event(t, result.value);
};
return LoopSink;
}(Pipe));
var ScanSink = /** @class */ (function (_super) {
__extends(ScanSink, _super);
function ScanSink(f, z, sink) {
var _this = _super.call(this, sink) || this;
_this.f = f;
_this.value = z;
return _this;
}
ScanSink.prototype.event = function (t, x) {
var f = this.f;
this.value = f(this.value, x);
this.sink.event(t, this.value);
};
return ScanSink;
}(Pipe));
var ContinueWithSink = /** @class */ (function (_super) {
__extends(ContinueWithSink, _super);
function ContinueWithSink(f, source, sink, scheduler) {
var _this = _super.call(this, sink) || this;
_this.f = f;
_this.scheduler = scheduler;
_this.active = true;
_this.disposable = disposeOnce(source.run(_this, scheduler));
return _this;
}
ContinueWithSink.prototype.event = function (t, x) {
if (!this.active) {
return;
}
this.sink.event(t, x);
};
ContinueWithSink.prototype.end = function (t) {
if (!this.active) {
return;
}
tryDispose(t, this.disposable, this.sink);
this.startNext(t, this.sink);
};
ContinueWithSink.prototype.startNext = function (t, sink) {
try {
this.disposable = this.continue(this.f, t, sink);
}
catch (e) {
sink.error(t, e);
}
};
ContinueWithSink.prototype.continue = function (f, t, sink) {
return run(sink, this.scheduler, withLocalTime(t, f()));
};
ContinueWithSink.prototype.dispose = function () {
this.active = false;
return this.disposable.dispose();
};
return ContinueWithSink;
}(Pipe));
/** @license MIT License (c) copyright 2010-2016 original author or authors */
var Filter = /** @class */ (function () {
function Filter(p, source) {
this.p = p;
this.source = source;
}
Filter.prototype.run = function (sink, scheduler) {
return this.source.run(new FilterSink(this.p, sink), scheduler);
};
/**
* Create a filtered source, fusing adjacent filter.filter if possible
* @param {function(x:*):boolean} p filtering predicate
* @param {{run:function}} source source to filter
* @returns {Filter} filtered source
*/
Filter.create = function (p, source) {
if (isCanonicalEmpty(source)) {
return source;
}
if (source instanceof Filter) {
return new Filter(and(source.p, p), source.source);
}
return new Filter(p, source);
};
return Filter;
}());
var FilterSink = /** @class */ (function (_super) {
__extends(FilterSink, _super);
function FilterSink(p, sink) {
var _this = _super.call(this, sink) || this;
_this.p = p;
return _this;
}
FilterSink.prototype.event = function (t, x) {
var p = this.p;
p(x) && this.sink.event(t, x);
};
return FilterSink;
}(Pipe));
var and = function (p, q) { return function (x) { return p(x) && q(x); }; };
/** @license MIT License (c) copyright 2010-2016 original author or authors */
var FilterMap = /** @class */ (function () {
function FilterMap(p, f, source) {
this.p = p;
this.f = f;
this.source = source;
}
FilterMap.prototype.run = function (sink, scheduler) {
return this.source.run(new FilterMapSink(this.p, this.f, sink), scheduler);
};
return FilterMap;
}());
var FilterMapSink = /** @class */ (function (_super) {
__extends(FilterMapSink, _super);
function FilterMapSink(p, f, sink) {
var _this = _super.call(this, sink) || this;
_this.p = p;
_this.f = f;
return _this;
}
FilterMapSink.prototype.event = function (t, x) {
var f = this.f;
var p = this.p;
p(x) && this.sink.event(t, f(x));
};
return FilterMapSink;
}(Pipe));
/** @license MIT License (c) copyright 2010-2016 original author or authors */
var Map = /** @class */ (function () {
function Map(f, source) {
this.f = f;
this.source = source;
}
Map.prototype.run = function (sink, scheduler) {
return this.source.run(new MapSink(this.f, sink), scheduler);
};
/**
* Create a mapped source, fusing adjacent map.map, filter.map,
* and filter.map.map if possible
* @param {function(*):*} f mapping function
* @param {{run:function}} source source to map
* @returns {Map|FilterMap} mapped source, possibly fused
*/
Map.create = function (f, source) {
if (isCanonicalEmpty(source)) {
return empty();
}
if (source instanceof Map) {
return new Map(compose(f, source.f), source.source);
}
if (source instanceof Filter) {
return new FilterMap(source.p, f, source.source);
}
return new Map(f, source);
};
return Map;
}());
var MapSink = /** @class */ (function (_super) {
__extends(MapSink, _super);
function MapSink(f, sink) {
var _this = _super.call(this, sink) || this;
_this.f = f;
return _this;
}
MapSink.prototype.event = function (t, x) {
var f = this.f;
this.sink.event(t, f(x));
};
return MapSink;
}(Pipe));
/** @license MIT License (c) copyright 2010-2016 original author or authors */
/**
* Transform each value in the stream by applying f to each
* @param f mapping function
* @param stream stream to map
* @returns stream containing items transformed by f
*/
var map$1 = function (f, stream) {
return Map.create(f, stream);
};
/**
* Perform a side effect for each item in the stream
* @param f side effect to execute for each item. The return value will be discarded.
* @param stream stream to tap
* @returns new stream containing the same items as this stream
*/
var tap = function (f, stream) {
return new Tap(f, stream);
};
var Tap = /** @class */ (function () {
function Tap(f, source) {
this.source = source;
this.f = f;
}
Tap.prototype.run = function (sink, scheduler) {
return this.source.run(new TapSink(this.f, sink), scheduler);
};
return Tap;
}());
var TapSink = /** @class */ (function (_super) {
__extends(TapSink, _super);
function TapSink(f, sink) {
var _this = _super.call(this, sink) || this;
_this.f = f;
return _this;
}
TapSink.prototype.event = function (t, x) {
var f = this.f;
f(x);
this.sink.event(t, x);
};
return TapSink;
}(Pipe));
/** @license MIT License (c) copyright 2010-2016 original author or authors */
var IndexSink = /** @class */ (function (_super) {
__extends(IndexSink, _super);
function IndexSink(i, sink) {
var _this = _super.call(this, sink) || this;
_this.index = i;
_this.active = true;
_this.value = undefined;
return _this;
}
IndexSink.prototype.event = function (t, x) {
if (!this.active) {
return;
}
this.value = x;
this.sink.event(t, this);
};
IndexSink.prototype.end = function (t) {
if (!this.active) {
return;
}
this.active = false;
this.sink.event(t, this);
};
return IndexSink;
}(Pipe));
/** @license MIT License (c) copyright 2010-2016 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
/**
* TODO: find a better way (without `any`)
*/
function invoke(f, args) {
/* eslint complexity: [2,7] */
switch (args.length) {
case 0: return f();
case 1: return f(args[0]);
case 2: return f(args[0], args[1]);
case 3: return f(args[0], args[1], args[2]);
case 4: return f(args[0], args[1], args[2], args[3]);
case 5: return f(args[0], args[1], args[2], args[3], args[4]);
default:
return f.apply(undefined, args);
}
}
var CombineSink = /** @class */ (function (_super) {
__extends(CombineSink, _super);
function CombineSink(disposables, length, sink, f) {
var _this = _super.call(this, sink) || this;
_this.disposables = disposables;
_this.f = f;
_this.awaiting = length;
_this.values = new Array(length);
_this.hasValue = new Array(length).fill(false);
_this.activeCount = length;
return _this;
}
CombineSink.prototype.event = function (t, indexedValue) {
if (!indexedValue.active) {
this.dispose(t, indexedValue.index);
return;
}
var i = indexedValue.index;
var awaiting = this.updateReady(i);
this.values[i] = indexedValue.value;
if (awaiting === 0) {
this.sink.event(t, invoke(this.f, this.values));
}
};
CombineSink.prototype.updateReady = function (index) {
if (this.awaiting > 0) {
if (!this.hasValue[index]) {
this.hasValue[index] = true;
this.awaiting -= 1;
}
}
return this.awaiting;
};
CombineSink.prototype.dispose = function (t, index) {
tryDispose(t, this.disposables[index], this.sink);
if (--this.activeCount === 0) {
this.sink.end(t);
}
};
return CombineSink;
}(Pipe));
/**
* @param streams array of stream to merge
* @returns stream containing events from all input observables
* in time order. If two events are simultaneous they will be merged in
* arbitrary order.
*/
var mergeArray = function (streams) {
return mergeStreams(withoutCanonicalEmpty(streams));
};
/**
* This implements fusion/flattening for merge. It will
* fuse adjacent merge operations. For example:
* - a.merge(b).merge(c) effectively becomes merge(a, b, c)
* - merge(a, merge(b, c)) effectively becomes merge(a, b, c)
* It does this by concatenating the sources arrays of
* any nested Merge sources, in effect "flattening" nested
* merge operations into a single merge.
* TODO: use {@link MergeArray}
*/
var mergeStreams = function (streams) {
return streams.length === 0 ? empty()
: streams.length === 1 ? streams[0]
: new Merge(reduce$1(appendSources, [], streams));
};
var withoutCanonicalEmpty = function (streams) {
return streams.filter(isNotCanonicalEmpty);
};
var isNotCanonicalEmpty = function (stream) {
return !isCanonicalEmpty(stream);
};
var appendSources = function (sources, stream) {
return sources.concat(stream instanceof Merge ? stream.sources : stream);
};
var Merge = /** @class */ (function () {
function Merge(sources) {
this.sources = sources;
}
Merge.prototype.run = function (sink, scheduler) {
var l = this.sources.length;
var disposables = new Array(l);
var sinks = new Array(l);
var mergeSink = new MergeSink(disposables, sinks, sink);
for (var indexSink = void 0, i = 0; i < l; ++i) {
indexSink = sinks[i] = new IndexSink(i, mergeSink);
disposables[i] = this.sources[i].run(indexSink, scheduler);
}
return disposeAll(disposables);
};
return Merge;
}());
var MergeSink = /** @class */ (function (_super) {
__extends(MergeSink, _super);
function MergeSink(disposables, sinks, sink) {
var _this = _super.call(this, sink) || this;
_this.disposables = disposables;
_this.activeCount = sinks.length;
return _this;
}
MergeSink.prototype.event = function (t, indexValue) {
if (!indexValue.active) {
this.dispose(t, indexValue.index);
return;
}
this.sink.event(t, indexValue.value);
};
MergeSink.prototype.dispose = function (t, index) {
tryDispose(t, this.disposables[index], this.sink);
if (--this.activeCount === 0) {
this.sink.end(t);
}
};
return MergeSink;
}(Pipe));
var SnapshotSink = /** @class */ (function (_super) {
__extends(SnapshotSink, _super);
function SnapshotSink(f, sink) {
var _this = _super.call(this, sink) || this;
_this.f = f;
_this.latest = new LatestValueSink(_this);
return _this;
}
SnapshotSink.prototype.event = function (t, x) {
if (this.latest.hasValue) {
var f = this.f;
// TODO: value should be boxed to avoid ! bang
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.sink.event(t, f(this.latest.value, x));
}
};
return SnapshotSink;
}(Pipe));
var LatestValueSink = /** @class */ (function (_super) {
__extends(LatestValueSink, _super);
function LatestValueSink(sink) {
var _this = _super.call(this, sink) || this;
_this.hasValue = false;
return _this;
}
LatestValueSink.prototype.event = function (_t, x) {
this.value = x;
this.hasValue = true;
};
LatestValueSink.prototype.end = function () { };
return LatestValueSink;
}(Pipe));
var SliceSink = /** @class */ (function (_super) {
__extends(SliceSink, _super);
function SliceSink(skip, take, sink, disposable) {
var _this = _super.call(this, sink) || this;
_this.skip = skip;
_this.take = take;
_this.disposable = disposable;
return _this;
}
SliceSink.prototype.event = function (t, x) {
/* eslint complexity: [1, 4] */
if (this.skip > 0) {
this.skip -= 1;
return;
}
if (this.take === 0) {
return;
}
this.take -= 1;
this.sink.event(t, x);
if (this.take === 0) {
this.disposable.dispose();
this.sink.end(t);
}
};
return SliceSink;
}(Pipe));
var TakeWhileSink = /** @class */ (function (_super) {
__extends(TakeWhileSink, _super);
function TakeWhileSink(p, sink, disposable) {
var _this = _super.call(this, sink) || this;
_this.p = p;
_this.active = true;
_this.disposable = disposable;
return _this;
}
TakeWhileSink.prototype.event = function (t, x) {
if (!this.active) {
return;
}
var p = this.p;
this.active = p(x);
if (this.active) {
this.sink.event(t, x);
}
else {
this.disposable.dispose();
this.sink.end(t);
}
};
return TakeWhileSink;
}(Pipe));
var SkipWhileSink = /** @class */ (function (_super) {
__extends(SkipWhileSink, _super);
function SkipWhileSink(p, sink) {
var _this = _super.call(this, sink) || this;
_this.p = p;
_this.skipping = true;
return _this;
}
SkipWhileSink.prototype.event = function (t, x) {
if (this.skipping) {
var p = this.p;
this.skipping = p(x);
if (this.skipping) {
return;
}
}
this.sink.event(t, x);
};
return SkipWhileSink;
}(Pipe));
var SkipAfterSink = /** @class */ (function (_super) {
__extends(SkipAfterSink, _super);
function SkipAfterSink(p, sink) {
var _this = _super.call(this, sink) || this;
_this.p = p;
_this.skipping = false;
return _this;
}
SkipAfterSink.prototype.event = function (t, x) {
if (this.skipping) {
return;
}
var p = this.p;
this.skipping = p(x);
this.sink.event(t, x);
if (this.skipping) {
this.sink.end(t);
}
};
return SkipAfterSink;
}(Pipe));
var ZipItemsSink = /** @class */ (function (_super) {
__extends(ZipItemsSink, _super);
function ZipItemsSink(f, items, sink) {
var _this = _super.call(this, sink) || this;
_this.f = f;
_this.items = items;
_this.index = 0;
return _this;
}
ZipItemsSink.prototype.event = function (t, b) {
var f = this.f;
this.sink.event(t, f(this.items[this.index], b));
this.index += 1;
};
return ZipItemsSink;
}(Pipe));
var ZipSink = /** @class */ (function (_super) {
__extends(ZipSink, _super);
function ZipSink(f, buffers, sinks, sink) {
var _this = _super.call(this, sink) || this;
_this.f = f;
_this.sinks = sinks;
_this.buffers = buffers;
return _this;
}
ZipSink.prototype.event = function (t, indexedValue) {
/* eslint complexity: [1, 5] */
if (!indexedValue.active) {
this.dispose(t, indexedValue.index);
return;
}
var buffers = this.buffers;
var b