tinymce
Version:
Web based JavaScript HTML WYSIWYG editor control.
1,432 lines (1,399 loc) • 1.71 MB
JavaScript
/**
* TinyMCE version 7.9.0 (2025-05-15)
*/
(function () {
'use strict';
var typeOf$1 = function (x) {
if (x === null) {
return 'null';
}
if (x === undefined) {
return 'undefined';
}
var t = typeof x;
if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
return 'array';
}
if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
return 'string';
}
return t;
};
var isEquatableType = function (x) {
return ['undefined', 'boolean', 'number', 'string', 'function', 'xml', 'null'].indexOf(x) !== -1;
};
var sort$1 = function (xs, compareFn) {
var clone = Array.prototype.slice.call(xs);
return clone.sort(compareFn);
};
var contramap = function (eqa, f) {
return eq$2(function (x, y) { return eqa.eq(f(x), f(y)); });
};
var eq$2 = function (f) {
return ({ eq: f });
};
var tripleEq = eq$2(function (x, y) { return x === y; });
var eqString = tripleEq;
var eqArray = function (eqa) { return eq$2(function (x, y) {
if (x.length !== y.length) {
return false;
}
var len = x.length;
for (var i = 0; i < len; i++) {
if (!eqa.eq(x[i], y[i])) {
return false;
}
}
return true;
}); };
// TODO: Make an Ord typeclass
var eqSortedArray = function (eqa, compareFn) {
return contramap(eqArray(eqa), function (xs) { return sort$1(xs, compareFn); });
};
var eqRecord = function (eqa) { return eq$2(function (x, y) {
var kx = Object.keys(x);
var ky = Object.keys(y);
if (!eqSortedArray(eqString).eq(kx, ky)) {
return false;
}
var len = kx.length;
for (var i = 0; i < len; i++) {
var q = kx[i];
if (!eqa.eq(x[q], y[q])) {
return false;
}
}
return true;
}); };
var eqAny = eq$2(function (x, y) {
if (x === y) {
return true;
}
var tx = typeOf$1(x);
var ty = typeOf$1(y);
if (tx !== ty) {
return false;
}
if (isEquatableType(tx)) {
return x === y;
}
else if (tx === 'array') {
return eqArray(eqAny).eq(x, y);
}
else if (tx === 'object') {
return eqRecord(eqAny).eq(x, y);
}
return false;
});
/* eslint-disable @typescript-eslint/no-wrapper-object-types */
const getPrototypeOf$2 = Object.getPrototypeOf;
const hasProto = (v, constructor, predicate) => {
var _a;
if (predicate(v, constructor.prototype)) {
return true;
}
else {
// String-based fallback time
return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name;
}
};
const typeOf = (x) => {
const t = typeof x;
if (x === null) {
return 'null';
}
else if (t === 'object' && Array.isArray(x)) {
return 'array';
}
else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {
return 'string';
}
else {
return t;
}
};
const isType$1 = (type) => (value) => typeOf(value) === type;
const isSimpleType = (type) => (value) => typeof value === type;
const eq$1 = (t) => (a) => t === a;
const is$4 = (value, constructor) => isObject(value) && hasProto(value, constructor, (o, proto) => getPrototypeOf$2(o) === proto);
const isString = isType$1('string');
const isObject = isType$1('object');
const isPlainObject = (value) => is$4(value, Object);
const isArray$1 = isType$1('array');
const isNull = eq$1(null);
const isBoolean = isSimpleType('boolean');
const isUndefined = eq$1(undefined);
const isNullable = (a) => a === null || a === undefined;
const isNonNullable = (a) => !isNullable(a);
const isFunction = isSimpleType('function');
const isNumber = isSimpleType('number');
const isArrayOf = (value, pred) => {
if (isArray$1(value)) {
for (let i = 0, len = value.length; i < len; ++i) {
if (!(pred(value[i]))) {
return false;
}
}
return true;
}
return false;
};
const noop = () => { };
/** Compose a unary function with an n-ary function */
const compose = (fa, fb) => {
return (...args) => {
return fa(fb.apply(null, args));
};
};
/** Compose two unary functions. Similar to compose, but avoids using Function.prototype.apply. */
const compose1 = (fbc, fab) => (a) => fbc(fab(a));
const constant = (value) => {
return () => {
return value;
};
};
const identity = (x) => {
return x;
};
const tripleEquals = (a, b) => {
return a === b;
};
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
function curry(fn, ...initialArgs) {
return (...restArgs) => {
const all = initialArgs.concat(restArgs);
return fn.apply(null, all);
};
}
const not = (f) => (t) => !f(t);
const die = (msg) => {
return () => {
throw new Error(msg);
};
};
const apply$1 = (f) => {
return f();
};
const call = (f) => {
f();
};
const never = constant(false);
const always = constant(true);
/**
* The `Optional` type represents a value (of any type) that potentially does
* not exist. Any `Optional<T>` can either be a `Some<T>` (in which case the
* value does exist) or a `None` (in which case the value does not exist). This
* module defines a whole lot of FP-inspired utility functions for dealing with
* `Optional` objects.
*
* Comparison with null or undefined:
* - We don't get fancy null coalescing operators with `Optional`
* - We do get fancy helper functions with `Optional`
* - `Optional` support nesting, and allow for the type to still be nullable (or
* another `Optional`)
* - There is no option to turn off strict-optional-checks like there is for
* strict-null-checks
*/
class Optional {
// The internal representation has a `tag` and a `value`, but both are
// private: able to be console.logged, but not able to be accessed by code
constructor(tag, value) {
this.tag = tag;
this.value = value;
}
// --- Identities ---
/**
* Creates a new `Optional<T>` that **does** contain a value.
*/
static some(value) {
return new Optional(true, value);
}
/**
* Create a new `Optional<T>` that **does not** contain a value. `T` can be
* any type because we don't actually have a `T`.
*/
static none() {
return Optional.singletonNone;
}
/**
* Perform a transform on an `Optional` type. Regardless of whether this
* `Optional` contains a value or not, `fold` will return a value of type `U`.
* If this `Optional` does not contain a value, the `U` will be created by
* calling `onNone`. If this `Optional` does contain a value, the `U` will be
* created by calling `onSome`.
*
* For the FP enthusiasts in the room, this function:
* 1. Could be used to implement all of the functions below
* 2. Forms a catamorphism
*/
fold(onNone, onSome) {
if (this.tag) {
return onSome(this.value);
}
else {
return onNone();
}
}
/**
* Determine if this `Optional` object contains a value.
*/
isSome() {
return this.tag;
}
/**
* Determine if this `Optional` object **does not** contain a value.
*/
isNone() {
return !this.tag;
}
// --- Functor (name stolen from Haskell / maths) ---
/**
* Perform a transform on an `Optional` object, **if** there is a value. If
* you provide a function to turn a T into a U, this is the function you use
* to turn an `Optional<T>` into an `Optional<U>`. If this **does** contain
* a value then the output will also contain a value (that value being the
* output of `mapper(this.value)`), and if this **does not** contain a value
* then neither will the output.
*/
map(mapper) {
if (this.tag) {
return Optional.some(mapper(this.value));
}
else {
return Optional.none();
}
}
// --- Monad (name stolen from Haskell / maths) ---
/**
* Perform a transform on an `Optional` object, **if** there is a value.
* Unlike `map`, here the transform itself also returns an `Optional`.
*/
bind(binder) {
if (this.tag) {
return binder(this.value);
}
else {
return Optional.none();
}
}
// --- Traversable (name stolen from Haskell / maths) ---
/**
* For a given predicate, this function finds out if there **exists** a value
* inside this `Optional` object that meets the predicate. In practice, this
* means that for `Optional`s that do not contain a value it returns false (as
* no predicate-meeting value exists).
*/
exists(predicate) {
return this.tag && predicate(this.value);
}
/**
* For a given predicate, this function finds out if **all** the values inside
* this `Optional` object meet the predicate. In practice, this means that
* for `Optional`s that do not contain a value it returns true (as all 0
* objects do meet the predicate).
*/
forall(predicate) {
return !this.tag || predicate(this.value);
}
filter(predicate) {
if (!this.tag || predicate(this.value)) {
return this;
}
else {
return Optional.none();
}
}
// --- Getters ---
/**
* Get the value out of the inside of the `Optional` object, using a default
* `replacement` value if the provided `Optional` object does not contain a
* value.
*/
getOr(replacement) {
return this.tag ? this.value : replacement;
}
/**
* Get the value out of the inside of the `Optional` object, using a default
* `replacement` value if the provided `Optional` object does not contain a
* value. Unlike `getOr`, in this method the `replacement` object is also
* `Optional` - meaning that this method will always return an `Optional`.
*/
or(replacement) {
return this.tag ? this : replacement;
}
/**
* Get the value out of the inside of the `Optional` object, using a default
* `replacement` value if the provided `Optional` object does not contain a
* value. Unlike `getOr`, in this method the `replacement` value is
* "thunked" - that is to say that you don't pass a value to `getOrThunk`, you
* pass a function which (if called) will **return** the `value` you want to
* use.
*/
getOrThunk(thunk) {
return this.tag ? this.value : thunk();
}
/**
* Get the value out of the inside of the `Optional` object, using a default
* `replacement` value if the provided Optional object does not contain a
* value.
*
* Unlike `or`, in this method the `replacement` value is "thunked" - that is
* to say that you don't pass a value to `orThunk`, you pass a function which
* (if called) will **return** the `value` you want to use.
*
* Unlike `getOrThunk`, in this method the `replacement` value is also
* `Optional`, meaning that this method will always return an `Optional`.
*/
orThunk(thunk) {
return this.tag ? this : thunk();
}
/**
* Get the value out of the inside of the `Optional` object, throwing an
* exception if the provided `Optional` object does not contain a value.
*
* WARNING:
* You should only be using this function if you know that the `Optional`
* object **is not** empty (otherwise you're throwing exceptions in production
* code, which is bad).
*
* In tests this is more acceptable.
*
* Prefer other methods to this, such as `.each`.
*/
getOrDie(message) {
if (!this.tag) {
throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
}
else {
return this.value;
}
}
// --- Interop with null and undefined ---
/**
* Creates an `Optional` value from a nullable (or undefined-able) input.
* Null, or undefined, is converted to `None`, and anything else is converted
* to `Some`.
*/
static from(value) {
return isNonNullable(value) ? Optional.some(value) : Optional.none();
}
/**
* Converts an `Optional` to a nullable type, by getting the value if it
* exists, or returning `null` if it does not.
*/
getOrNull() {
return this.tag ? this.value : null;
}
/**
* Converts an `Optional` to an undefined-able type, by getting the value if
* it exists, or returning `undefined` if it does not.
*/
getOrUndefined() {
return this.value;
}
// --- Utilities ---
/**
* If the `Optional` contains a value, perform an action on that value.
* Unlike the rest of the methods on this type, `.each` has side-effects. If
* you want to transform an `Optional<T>` **into** something, then this is not
* the method for you. If you want to use an `Optional<T>` to **do**
* something, then this is the method for you - provided you're okay with not
* doing anything in the case where the `Optional` doesn't have a value inside
* it. If you're not sure whether your use-case fits into transforming
* **into** something or **doing** something, check whether it has a return
* value. If it does, you should be performing a transform.
*/
each(worker) {
if (this.tag) {
worker(this.value);
}
}
/**
* Turn the `Optional` object into an array that contains all of the values
* stored inside the `Optional`. In practice, this means the output will have
* either 0 or 1 elements.
*/
toArray() {
return this.tag ? [this.value] : [];
}
/**
* Turn the `Optional` object into a string for debugging or printing. Not
* recommended for production code, but good for debugging. Also note that
* these days an `Optional` object can be logged to the console directly, and
* its inner value (if it exists) will be visible.
*/
toString() {
return this.tag ? `some(${this.value})` : 'none()';
}
}
// Sneaky optimisation: every instance of Optional.none is identical, so just
// reuse the same object
Optional.singletonNone = new Optional(false);
/* eslint-disable @typescript-eslint/unbound-method */
const nativeSlice = Array.prototype.slice;
const nativeIndexOf = Array.prototype.indexOf;
const nativePush = Array.prototype.push;
/* eslint-enable */
const rawIndexOf = (ts, t) => nativeIndexOf.call(ts, t);
const indexOf$1 = (xs, x) => {
// The rawIndexOf method does not wrap up in an option. This is for performance reasons.
const r = rawIndexOf(xs, x);
return r === -1 ? Optional.none() : Optional.some(r);
};
const contains$2 = (xs, x) => rawIndexOf(xs, x) > -1;
const exists = (xs, pred) => {
for (let i = 0, len = xs.length; i < len; i++) {
const x = xs[i];
if (pred(x, i)) {
return true;
}
}
return false;
};
const map$3 = (xs, f) => {
// pre-allocating array size when it's guaranteed to be known
// http://jsperf.com/push-allocated-vs-dynamic/22
const len = xs.length;
const r = new Array(len);
for (let i = 0; i < len; i++) {
const x = xs[i];
r[i] = f(x, i);
}
return r;
};
// Unwound implementing other functions in terms of each.
// The code size is roughly the same, and it should allow for better optimisation.
// const each = function<T, U>(xs: T[], f: (x: T, i?: number, xs?: T[]) => void): void {
const each$e = (xs, f) => {
for (let i = 0, len = xs.length; i < len; i++) {
const x = xs[i];
f(x, i);
}
};
const eachr = (xs, f) => {
for (let i = xs.length - 1; i >= 0; i--) {
const x = xs[i];
f(x, i);
}
};
const partition$2 = (xs, pred) => {
const pass = [];
const fail = [];
for (let i = 0, len = xs.length; i < len; i++) {
const x = xs[i];
const arr = pred(x, i) ? pass : fail;
arr.push(x);
}
return { pass, fail };
};
const filter$5 = (xs, pred) => {
const r = [];
for (let i = 0, len = xs.length; i < len; i++) {
const x = xs[i];
if (pred(x, i)) {
r.push(x);
}
}
return r;
};
const foldr = (xs, f, acc) => {
eachr(xs, (x, i) => {
acc = f(acc, x, i);
});
return acc;
};
const foldl = (xs, f, acc) => {
each$e(xs, (x, i) => {
acc = f(acc, x, i);
});
return acc;
};
const findUntil$1 = (xs, pred, until) => {
for (let i = 0, len = xs.length; i < len; i++) {
const x = xs[i];
if (pred(x, i)) {
return Optional.some(x);
}
else if (until(x, i)) {
break;
}
}
return Optional.none();
};
const find$2 = (xs, pred) => {
return findUntil$1(xs, pred, never);
};
const findIndex$2 = (xs, pred) => {
for (let i = 0, len = xs.length; i < len; i++) {
const x = xs[i];
if (pred(x, i)) {
return Optional.some(i);
}
}
return Optional.none();
};
const flatten = (xs) => {
// Note, this is possible because push supports multiple arguments:
// http://jsperf.com/concat-push/6
// Note that in the past, concat() would silently work (very slowly) for array-like objects.
// With this change it will throw an error.
const r = [];
for (let i = 0, len = xs.length; i < len; ++i) {
// Ensure that each value is an array itself
if (!isArray$1(xs[i])) {
throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
}
nativePush.apply(r, xs[i]);
}
return r;
};
const bind$3 = (xs, f) => flatten(map$3(xs, f));
const forall = (xs, pred) => {
for (let i = 0, len = xs.length; i < len; ++i) {
const x = xs[i];
if (pred(x, i) !== true) {
return false;
}
}
return true;
};
const reverse = (xs) => {
const r = nativeSlice.call(xs, 0);
r.reverse();
return r;
};
const difference = (a1, a2) => filter$5(a1, (x) => !contains$2(a2, x));
const mapToObject = (xs, f) => {
const r = {};
for (let i = 0, len = xs.length; i < len; i++) {
const x = xs[i];
r[String(x)] = f(x, i);
}
return r;
};
const sort = (xs, comparator) => {
const copy = nativeSlice.call(xs, 0);
copy.sort(comparator);
return copy;
};
const get$b = (xs, i) => i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
const head = (xs) => get$b(xs, 0);
const last$2 = (xs) => get$b(xs, xs.length - 1);
const from = isFunction(Array.from) ? Array.from : (x) => nativeSlice.call(x);
const findMap = (arr, f) => {
for (let i = 0; i < arr.length; i++) {
const r = f(arr[i], i);
if (r.isSome()) {
return r;
}
}
return Optional.none();
};
const unique$1 = (xs, comparator) => {
const r = [];
const isDuplicated = isFunction(comparator) ?
(x) => exists(r, (i) => comparator(i, x)) :
(x) => contains$2(r, x);
for (let i = 0, len = xs.length; i < len; i++) {
const x = xs[i];
if (!isDuplicated(x)) {
r.push(x);
}
}
return r;
};
// There are many variations of Object iteration that are faster than the 'for-in' style:
// http://jsperf.com/object-keys-iteration/107
//
// Use the native keys if it is available (IE9+), otherwise fall back to manually filtering
const keys = Object.keys;
// eslint-disable-next-line @typescript-eslint/unbound-method
const hasOwnProperty$1 = Object.hasOwnProperty;
const each$d = (obj, f) => {
const props = keys(obj);
for (let k = 0, len = props.length; k < len; k++) {
const i = props[k];
const x = obj[i];
f(x, i);
}
};
const map$2 = (obj, f) => {
return tupleMap(obj, (x, i) => ({
k: i,
v: f(x, i)
}));
};
const tupleMap = (obj, f) => {
const r = {};
each$d(obj, (x, i) => {
const tuple = f(x, i);
r[tuple.k] = tuple.v;
});
return r;
};
const objAcc = (r) => (x, i) => {
r[i] = x;
};
const internalFilter = (obj, pred, onTrue, onFalse) => {
each$d(obj, (x, i) => {
(pred(x, i) ? onTrue : onFalse)(x, i);
});
};
const bifilter = (obj, pred) => {
const t = {};
const f = {};
internalFilter(obj, pred, objAcc(t), objAcc(f));
return { t, f };
};
const filter$4 = (obj, pred) => {
const t = {};
internalFilter(obj, pred, objAcc(t), noop);
return t;
};
const mapToArray = (obj, f) => {
const r = [];
each$d(obj, (value, name) => {
r.push(f(value, name));
});
return r;
};
const values = (obj) => {
return mapToArray(obj, identity);
};
const get$a = (obj, key) => {
return has$2(obj, key) ? Optional.from(obj[key]) : Optional.none();
};
const has$2 = (obj, key) => hasOwnProperty$1.call(obj, key);
const hasNonNullableKey = (obj, key) => has$2(obj, key) && obj[key] !== undefined && obj[key] !== null;
const equal$1 = (a1, a2, eq = eqAny) => eqRecord(eq).eq(a1, a2);
/*
* Generates a church encoded ADT (https://en.wikipedia.org/wiki/Church_encoding)
* For syntax and use, look at the test code.
*/
const generate$1 = (cases) => {
// validation
if (!isArray$1(cases)) {
throw new Error('cases must be an array');
}
if (cases.length === 0) {
throw new Error('there must be at least one case');
}
const constructors = [];
// adt is mutated to add the individual cases
const adt = {};
each$e(cases, (acase, count) => {
const keys$1 = keys(acase);
// validation
if (keys$1.length !== 1) {
throw new Error('one and only one name per case');
}
const key = keys$1[0];
const value = acase[key];
// validation
if (adt[key] !== undefined) {
throw new Error('duplicate key detected:' + key);
}
else if (key === 'cata') {
throw new Error('cannot have a case named cata (sorry)');
}
else if (!isArray$1(value)) {
// this implicitly checks if acase is an object
throw new Error('case arguments must be an array');
}
constructors.push(key);
//
// constructor for key
//
adt[key] = (...args) => {
const argLength = args.length;
// validation
if (argLength !== value.length) {
throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
}
const match = (branches) => {
const branchKeys = keys(branches);
if (constructors.length !== branchKeys.length) {
throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
}
const allReqd = forall(constructors, (reqKey) => {
return contains$2(branchKeys, reqKey);
});
if (!allReqd) {
throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
}
return branches[key].apply(null, args);
};
//
// the fold function for key
//
return {
fold: (...foldArgs) => {
// runtime validation
if (foldArgs.length !== cases.length) {
throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + foldArgs.length);
}
const target = foldArgs[count];
return target.apply(null, args);
},
match,
// NOTE: Only for debugging.
log: (label) => {
// eslint-disable-next-line no-console
console.log(label, {
constructors,
constructor: key,
params: args
});
}
};
};
});
return adt;
};
const Adt = {
generate: generate$1
};
const Cell = (initial) => {
let value = initial;
const get = () => {
return value;
};
const set = (v) => {
value = v;
};
return {
get,
set
};
};
/**
* Creates a new `Result<T, E>` that **does** contain a value.
*/
const value$3 = (value) => {
const applyHelper = (fn) => fn(value);
const constHelper = constant(value);
const outputHelper = () => output;
const output = {
// Debug info
tag: true,
inner: value,
// Actual Result methods
fold: (_onError, onValue) => onValue(value),
isValue: always,
isError: never,
map: (mapper) => Result.value(mapper(value)),
mapError: outputHelper,
bind: applyHelper,
exists: applyHelper,
forall: applyHelper,
getOr: constHelper,
or: outputHelper,
getOrThunk: constHelper,
orThunk: outputHelper,
getOrDie: constHelper,
each: (fn) => {
// Can't write the function inline because we don't want to return something by mistake
fn(value);
},
toOptional: () => Optional.some(value),
};
return output;
};
/**
* Creates a new `Result<T, E>` that **does not** contain a value, and therefore
* contains an error.
*/
const error = (error) => {
const outputHelper = () => output;
const output = {
// Debug info
tag: false,
inner: error,
// Actual Result methods
fold: (onError, _onValue) => onError(error),
isValue: never,
isError: always,
map: outputHelper,
mapError: (mapper) => Result.error(mapper(error)),
bind: outputHelper,
exists: never,
forall: always,
getOr: identity,
or: identity,
getOrThunk: apply$1,
orThunk: apply$1,
getOrDie: die(String(error)),
each: noop,
toOptional: Optional.none,
};
return output;
};
/**
* Creates a new `Result<T, E>` from an `Optional<T>` and an `E`. If the
* `Optional` contains a value, so will the outputted `Result`. If it does not,
* the outputted `Result` will contain an error (and that error will be the
* error passed in).
*/
const fromOption = (optional, err) => optional.fold(() => error(err), value$3);
const Result = {
value: value$3,
error,
fromOption
};
// Use window object as the global if it's available since CSP will block script evals
// eslint-disable-next-line @typescript-eslint/no-implied-eval
const Global = typeof window !== 'undefined' ? window : Function('return this;')();
/**
* Adds two numbers, and wrap to a range.
* If the result overflows to the right, snap to the left.
* If the result overflows to the left, snap to the right.
*/
// ASSUMPTION: Max will always be larger than min
const clamp$2 = (value, min, max) => Math.min(Math.max(value, min), max);
// the division is meant to get a number between 0 and 1 for more information check this discussion: https://stackoverflow.com/questions/58285941/how-to-replace-math-random-with-crypto-getrandomvalues-and-keep-same-result
const random = () => window.crypto.getRandomValues(new Uint32Array(1))[0] / 4294967295;
/**
* Generate a unique identifier.
*
* The unique portion of the identifier only contains an underscore
* and digits, so that it may safely be used within HTML attributes.
*
* The chance of generating a non-unique identifier has been minimized
* by combining the current time, a random number and a one-up counter.
*
* generate :: String -> String
*/
let unique = 0;
const generate = (prefix) => {
const date = new Date();
const time = date.getTime();
const random$1 = Math.floor(random() * 1000000000);
unique++;
return prefix + '_' + random$1 + unique + String(time);
};
const shallow$1 = (old, nu) => {
return nu;
};
const deep$1 = (old, nu) => {
const bothObjects = isPlainObject(old) && isPlainObject(nu);
return bothObjects ? deepMerge(old, nu) : nu;
};
const baseMerge = (merger) => {
return (...objects) => {
if (objects.length === 0) {
throw new Error(`Can't merge zero objects`);
}
const ret = {};
for (let j = 0; j < objects.length; j++) {
const curObject = objects[j];
for (const key in curObject) {
if (has$2(curObject, key)) {
ret[key] = merger(ret[key], curObject[key]);
}
}
}
return ret;
};
};
const deepMerge = baseMerge(deep$1);
const merge$1 = baseMerge(shallow$1);
/**
* **Is** the value stored inside this Optional object equal to `rhs`?
*/
const is$3 = (lhs, rhs, comparator = tripleEquals) => lhs.exists((left) => comparator(left, rhs));
/**
* Are these two Optional objects equal? Equality here means either they're both
* `Some` (and the values are equal under the comparator) or they're both `None`.
*/
const equals = (lhs, rhs, comparator = tripleEquals) => lift2(lhs, rhs, comparator).getOr(lhs.isNone() && rhs.isNone());
const cat = (arr) => {
const r = [];
const push = (x) => {
r.push(x);
};
for (let i = 0; i < arr.length; i++) {
arr[i].each(push);
}
return r;
};
/*
Notes on the lift functions:
- We used to have a generic liftN, but we were concerned about its type-safety, and the below variants were faster in microbenchmarks.
- The getOrDie calls are partial functions, but are checked beforehand. This is faster and more convenient (but less safe) than folds.
- && is used instead of a loop for simplicity and performance.
*/
const lift2 = (oa, ob, f) => oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none();
const lift3 = (oa, ob, oc, f) => oa.isSome() && ob.isSome() && oc.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie())) : Optional.none();
// This can help with type inference, by specifying the type param on the none case, so the caller doesn't have to.
const someIf = (b, a) => b ? Optional.some(a) : Optional.none();
/** path :: ([String], JsObj?) -> JsObj */
const path = (parts, scope) => {
let o = scope !== undefined && scope !== null ? scope : Global;
for (let i = 0; i < parts.length && o !== undefined && o !== null; ++i) {
o = o[parts[i]];
}
return o;
};
/** resolve :: (String, JsObj?) -> JsObj */
const resolve$3 = (p, scope) => {
const parts = p.split('.');
return path(parts, scope);
};
Adt.generate([
{ bothErrors: ['error1', 'error2'] },
{ firstError: ['error1', 'value2'] },
{ secondError: ['value1', 'error2'] },
{ bothValues: ['value1', 'value2'] }
]);
/** partition :: [Result a] -> { errors: [String], values: [a] } */
const partition$1 = (results) => {
const errors = [];
const values = [];
each$e(results, (result) => {
result.fold((err) => {
errors.push(err);
}, (value) => {
values.push(value);
});
});
return { errors, values };
};
const singleton = (doRevoke) => {
const subject = Cell(Optional.none());
const revoke = () => subject.get().each(doRevoke);
const clear = () => {
revoke();
subject.set(Optional.none());
};
const isSet = () => subject.get().isSome();
const get = () => subject.get();
const set = (s) => {
revoke();
subject.set(Optional.some(s));
};
return {
clear,
isSet,
get,
set
};
};
const repeatable = (delay) => {
const intervalId = Cell(Optional.none());
const revoke = () => intervalId.get().each((id) => clearInterval(id));
const clear = () => {
revoke();
intervalId.set(Optional.none());
};
const isSet = () => intervalId.get().isSome();
const get = () => intervalId.get();
const set = (functionToRepeat) => {
revoke();
intervalId.set(Optional.some(setInterval(functionToRepeat, delay)));
};
return {
clear,
isSet,
get,
set,
};
};
const value$2 = () => {
const subject = singleton(noop);
const on = (f) => subject.get().each(f);
return {
...subject,
on
};
};
const removeFromStart = (str, numChars) => {
return str.substring(numChars);
};
const checkRange = (str, substr, start) => substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
const removeLeading = (str, prefix) => {
return startsWith(str, prefix) ? removeFromStart(str, prefix.length) : str;
};
const contains$1 = (str, substr, start = 0, end) => {
const idx = str.indexOf(substr, start);
if (idx !== -1) {
return isUndefined(end) ? true : idx + substr.length <= end;
}
else {
return false;
}
};
/** Does 'str' start with 'prefix'?
* Note: all strings start with the empty string.
* More formally, for all strings x, startsWith(x, "").
* This is so that for all strings x and y, startsWith(y + x, y)
*/
const startsWith = (str, prefix) => {
return checkRange(str, prefix, 0);
};
/** Does 'str' end with 'suffix'?
* Note: all strings end with the empty string.
* More formally, for all strings x, endsWith(x, "").
* This is so that for all strings x and y, endsWith(x + y, y)
*/
const endsWith = (str, suffix) => {
return checkRange(str, suffix, str.length - suffix.length);
};
const blank = (r) => (s) => s.replace(r, '');
/** removes all leading and trailing spaces */
const trim$4 = blank(/^\s+|\s+$/g);
const lTrim = blank(/^\s+/g);
const rTrim = blank(/\s+$/g);
const isNotEmpty = (s) => s.length > 0;
const isEmpty$3 = (s) => !isNotEmpty(s);
const repeat = (s, count) => count <= 0 ? '' : new Array(count + 1).join(s);
const toInt = (value, radix = 10) => {
const num = parseInt(value, radix);
return isNaN(num) ? Optional.none() : Optional.some(num);
};
// Run a function fn after rate ms. If another invocation occurs
// during the time it is waiting, ignore it completely.
const first$1 = (fn, rate) => {
let timer = null;
const cancel = () => {
if (!isNull(timer)) {
clearTimeout(timer);
timer = null;
}
};
const throttle = (...args) => {
if (isNull(timer)) {
timer = setTimeout(() => {
timer = null;
fn.apply(null, args);
}, rate);
}
};
return {
cancel,
throttle
};
};
// Run a function fn after rate ms. If another invocation occurs
// during the time it is waiting, reschedule the function again
// with the new arguments.
const last$1 = (fn, rate) => {
let timer = null;
const cancel = () => {
if (!isNull(timer)) {
clearTimeout(timer);
timer = null;
}
};
const throttle = (...args) => {
cancel();
timer = setTimeout(() => {
timer = null;
fn.apply(null, args);
}, rate);
};
return {
cancel,
throttle
};
};
const cached = (f) => {
let called = false;
let r;
return (...args) => {
if (!called) {
called = true;
r = f.apply(null, args);
}
return r;
};
};
const zeroWidth = '\uFEFF';
const nbsp = '\u00A0';
const isZwsp$2 = (char) => char === zeroWidth;
const removeZwsp = (s) => s.replace(/\uFEFF/g, '');
const stringArray = (a) => {
const all = {};
each$e(a, (key) => {
all[key] = {};
});
return keys(all);
};
const isArrayLike = (o) => o.length !== undefined;
const isArray = Array.isArray;
const toArray$1 = (obj) => {
if (!isArray(obj)) {
const array = [];
for (let i = 0, l = obj.length; i < l; i++) {
array[i] = obj[i];
}
return array;
}
else {
return obj;
}
};
const each$c = (o, cb, s) => {
if (!o) {
return false;
}
s = s || o;
if (isArrayLike(o)) {
// Indexed arrays, needed for Safari
for (let n = 0, l = o.length; n < l; n++) {
if (cb.call(s, o[n], n, o) === false) {
return false;
}
}
}
else {
// Hashtables
for (const n in o) {
if (has$2(o, n)) {
if (cb.call(s, o[n], n, o) === false) {
return false;
}
}
}
}
return true;
};
const map$1 = (array, callback) => {
const out = [];
each$c(array, (item, index) => {
out.push(callback(item, index, array));
});
return out;
};
const filter$3 = (a, f) => {
const o = [];
each$c(a, (v, index) => {
if (!f || f(v, index, a)) {
o.push(v);
}
});
return o;
};
const indexOf = (a, v) => {
if (a) {
for (let i = 0, l = a.length; i < l; i++) {
if (a[i] === v) {
return i;
}
}
}
return -1;
};
const reduce = (collection, iteratee, accumulator, thisArg) => {
let acc = isUndefined(accumulator) ? collection[0] : accumulator;
for (let i = 0; i < collection.length; i++) {
acc = iteratee.call(thisArg, acc, collection[i], i);
}
return acc;
};
const findIndex$1 = (array, predicate, thisArg) => {
for (let i = 0, l = array.length; i < l; i++) {
if (predicate.call(thisArg, array[i], i, array)) {
return i;
}
}
return -1;
};
const last = (collection) => collection[collection.length - 1];
const DeviceType = (os, browser, userAgent, mediaMatch) => {
const isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
const isiPhone = os.isiOS() && !isiPad;
const isMobile = os.isiOS() || os.isAndroid();
const isTouch = isMobile || mediaMatch('(pointer:coarse)');
const isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
const isPhone = isiPhone || isMobile && !isTablet;
const iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
const isDesktop = !isPhone && !isTablet && !iOSwebview;
return {
isiPad: constant(isiPad),
isiPhone: constant(isiPhone),
isTablet: constant(isTablet),
isPhone: constant(isPhone),
isTouch: constant(isTouch),
isAndroid: os.isAndroid,
isiOS: os.isiOS,
isWebView: constant(iOSwebview),
isDesktop: constant(isDesktop)
};
};
const firstMatch = (regexes, s) => {
for (let i = 0; i < regexes.length; i++) {
const x = regexes[i];
if (x.test(s)) {
return x;
}
}
return undefined;
};
const find$1 = (regexes, agent) => {
const r = firstMatch(regexes, agent);
if (!r) {
return { major: 0, minor: 0 };
}
const group = (i) => {
return Number(agent.replace(r, '$' + i));
};
return nu$3(group(1), group(2));
};
const detect$4 = (versionRegexes, agent) => {
const cleanedAgent = String(agent).toLowerCase();
if (versionRegexes.length === 0) {
return unknown$2();
}
return find$1(versionRegexes, cleanedAgent);
};
const unknown$2 = () => {
return nu$3(0, 0);
};
const nu$3 = (major, minor) => {
return { major, minor };
};
const Version = {
nu: nu$3,
detect: detect$4,
unknown: unknown$2
};
const detectBrowser$1 = (browsers, userAgentData) => {
return findMap(userAgentData.brands, (uaBrand) => {
const lcBrand = uaBrand.brand.toLowerCase();
return find$2(browsers, (browser) => { var _a; return lcBrand === ((_a = browser.brand) === null || _a === void 0 ? void 0 : _a.toLowerCase()); })
.map((info) => ({
current: info.name,
version: Version.nu(parseInt(uaBrand.version, 10), 0)
}));
});
};
const detect$3 = (candidates, userAgent) => {
const agent = String(userAgent).toLowerCase();
return find$2(candidates, (candidate) => {
return candidate.search(agent);
});
};
// They (browser and os) are the same at the moment, but they might
// not stay that way.
const detectBrowser = (browsers, userAgent) => {
return detect$3(browsers, userAgent).map((browser) => {
const version = Version.detect(browser.versionRegexes, userAgent);
return {
current: browser.name,
version
};
});
};
const detectOs = (oses, userAgent) => {
return detect$3(oses, userAgent).map((os) => {
const version = Version.detect(os.versionRegexes, userAgent);
return {
current: os.name,
version
};
});
};
const normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
const checkContains = (target) => {
return (uastring) => {
return contains$1(uastring, target);
};
};
const browsers = [
// This is legacy Edge
{
name: 'Edge',
versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
search: (uastring) => {
return contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');
}
},
// This is Google Chrome and Chromium Edge
{
name: 'Chromium',
brand: 'Chromium',
versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/, normalVersionRegex],
search: (uastring) => {
return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');
}
},
{
name: 'IE',
versionRegexes: [/.*?msie\ ?([0-9]+)\.([0-9]+).*/, /.*?rv:([0-9]+)\.([0-9]+).*/],
search: (uastring) => {
return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');
}
},
// INVESTIGATE: Is this still the Opera user agent?
{
name: 'Opera',
versionRegexes: [normalVersionRegex, /.*?opera\/([0-9]+)\.([0-9]+).*/],
search: checkContains('opera')
},
{
name: 'Firefox',
versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
search: checkContains('firefox')
},
{
name: 'Safari',
versionRegexes: [normalVersionRegex, /.*?cpu os ([0-9]+)_([0-9]+).*/],
search: (uastring) => {
return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');
}
}
];
const oses = [
{
name: 'Windows',
search: checkContains('win'),
versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
},
{
name: 'iOS',
search: (uastring) => {
return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');
},
versionRegexes: [/.*?version\/\ ?([0-9]+)\.([0-9]+).*/, /.*cpu os ([0-9]+)_([0-9]+).*/, /.*cpu iphone os ([0-9]+)_([0-9]+).*/]
},
{
name: 'Android',
search: checkContains('android'),
versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
},
{
name: 'macOS',
search: checkContains('mac os x'),
versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
},
{
name: 'Linux',
search: checkContains('linux'),
versionRegexes: []
},
{ name: 'Solaris',
search: checkContains('sunos'),
versionRegexes: []
},
{
name: 'FreeBSD',
search: checkContains('freebsd'),
versionRegexes: []
},
{
name: 'ChromeOS',
search: checkContains('cros'),
versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
}
];
const PlatformInfo = {
browsers: constant(browsers),
oses: constant(oses)
};
const edge = 'Edge';
const chromium = 'Chromium';
const ie = 'IE';
const opera = 'Opera';
const firefox = 'Firefox';
const safari = 'Safari';
const