vis-network
Version:
A dynamic, browser-based visualization library.
1,537 lines (1,307 loc) • 1.25 MB
JavaScript
/**
* vis-network
* https://visjs.github.io/vis-network/
*
* A dynamic, browser-based visualization library.
*
* @version 9.1.9
* @date 2023-11-03T01:42:27.418Z
*
* @copyright (c) 2011-2017 Almende B.V, http://almende.com
* @copyright (c) 2017-2019 visjs contributors, https://github.com/visjs
*
* @license
* vis.js is dual licensed under both
*
* 1. The Apache 2.0 License
* http://www.apache.org/licenses/LICENSE-2.0
*
* and
*
* 2. The MIT License
* http://opensource.org/licenses/MIT
*
* vis.js may be distributed under either license.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vis-data/peer/umd/vis-data.js')) :
typeof define === 'function' && define.amd ? define(['exports', 'vis-data/peer/umd/vis-data.js'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vis = global.vis || {}, global.vis));
})(this, (function (exports, esnext) {
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
var check = function (it) {
return it && it.Math === Math && it;
};
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
var global$n =
// eslint-disable-next-line es/no-global-this -- safe
check(typeof globalThis == 'object' && globalThis) ||
check(typeof window == 'object' && window) ||
// eslint-disable-next-line no-restricted-globals -- safe
check(typeof self == 'object' && self) ||
check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
// eslint-disable-next-line no-new-func -- fallback
(function () { return this; })() || commonjsGlobal || Function('return this')();
var fails$w = function (exec) {
try {
return !!exec();
} catch (error) {
return true;
}
};
var fails$v = fails$w;
var functionBindNative = !fails$v(function () {
// eslint-disable-next-line es/no-function-prototype-bind -- safe
var test = (function () { /* empty */ }).bind();
// eslint-disable-next-line no-prototype-builtins -- safe
return typeof test != 'function' || test.hasOwnProperty('prototype');
});
var NATIVE_BIND$4 = functionBindNative;
var FunctionPrototype$4 = Function.prototype;
var apply$5 = FunctionPrototype$4.apply;
var call$f = FunctionPrototype$4.call;
// eslint-disable-next-line es/no-reflect -- safe
var functionApply = typeof Reflect == 'object' && Reflect.apply || (NATIVE_BIND$4 ? call$f.bind(apply$5) : function () {
return call$f.apply(apply$5, arguments);
});
var NATIVE_BIND$3 = functionBindNative;
var FunctionPrototype$3 = Function.prototype;
var call$e = FunctionPrototype$3.call;
var uncurryThisWithBind = NATIVE_BIND$3 && FunctionPrototype$3.bind.bind(call$e, call$e);
var functionUncurryThis = NATIVE_BIND$3 ? uncurryThisWithBind : function (fn) {
return function () {
return call$e.apply(fn, arguments);
};
};
var uncurryThis$x = functionUncurryThis;
var toString$c = uncurryThis$x({}.toString);
var stringSlice$1 = uncurryThis$x(''.slice);
var classofRaw$2 = function (it) {
return stringSlice$1(toString$c(it), 8, -1);
};
var classofRaw$1 = classofRaw$2;
var uncurryThis$w = functionUncurryThis;
var functionUncurryThisClause = function (fn) {
// Nashorn bug:
// https://github.com/zloirock/core-js/issues/1128
// https://github.com/zloirock/core-js/issues/1130
if (classofRaw$1(fn) === 'Function') return uncurryThis$w(fn);
};
var documentAll$2 = typeof document == 'object' && document.all;
// https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
// eslint-disable-next-line unicorn/no-typeof-undefined -- required for testing
var IS_HTMLDDA = typeof documentAll$2 == 'undefined' && documentAll$2 !== undefined;
var documentAll_1 = {
all: documentAll$2,
IS_HTMLDDA: IS_HTMLDDA
};
var $documentAll$1 = documentAll_1;
var documentAll$1 = $documentAll$1.all;
// `IsCallable` abstract operation
// https://tc39.es/ecma262/#sec-iscallable
var isCallable$i = $documentAll$1.IS_HTMLDDA ? function (argument) {
return typeof argument == 'function' || argument === documentAll$1;
} : function (argument) {
return typeof argument == 'function';
};
var objectGetOwnPropertyDescriptor = {};
var fails$u = fails$w;
// Detect IE8's incomplete defineProperty implementation
var descriptors = !fails$u(function () {
// eslint-disable-next-line es/no-object-defineproperty -- required for testing
return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] !== 7;
});
var NATIVE_BIND$2 = functionBindNative;
var call$d = Function.prototype.call;
var functionCall = NATIVE_BIND$2 ? call$d.bind(call$d) : function () {
return call$d.apply(call$d, arguments);
};
var objectPropertyIsEnumerable = {};
var $propertyIsEnumerable$1 = {}.propertyIsEnumerable;
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
var getOwnPropertyDescriptor$9 = Object.getOwnPropertyDescriptor;
// Nashorn ~ JDK8 bug
var NASHORN_BUG = getOwnPropertyDescriptor$9 && !$propertyIsEnumerable$1.call({ 1: 2 }, 1);
// `Object.prototype.propertyIsEnumerable` method implementation
// https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
objectPropertyIsEnumerable.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
var descriptor = getOwnPropertyDescriptor$9(this, V);
return !!descriptor && descriptor.enumerable;
} : $propertyIsEnumerable$1;
var createPropertyDescriptor$5 = function (bitmap, value) {
return {
enumerable: !(bitmap & 1),
configurable: !(bitmap & 2),
writable: !(bitmap & 4),
value: value
};
};
var uncurryThis$v = functionUncurryThis;
var fails$t = fails$w;
var classof$e = classofRaw$2;
var $Object$5 = Object;
var split = uncurryThis$v(''.split);
// fallback for non-array-like ES3 and non-enumerable old V8 strings
var indexedObject = fails$t(function () {
// throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
// eslint-disable-next-line no-prototype-builtins -- safe
return !$Object$5('z').propertyIsEnumerable(0);
}) ? function (it) {
return classof$e(it) === 'String' ? split(it, '') : $Object$5(it);
} : $Object$5;
// we can't use just `it == null` since of `document.all` special case
// https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-aec
var isNullOrUndefined$6 = function (it) {
return it === null || it === undefined;
};
var isNullOrUndefined$5 = isNullOrUndefined$6;
var $TypeError$g = TypeError;
// `RequireObjectCoercible` abstract operation
// https://tc39.es/ecma262/#sec-requireobjectcoercible
var requireObjectCoercible$5 = function (it) {
if (isNullOrUndefined$5(it)) throw new $TypeError$g("Can't call method on " + it);
return it;
};
// toObject with fallback for non-array-like ES3 strings
var IndexedObject$3 = indexedObject;
var requireObjectCoercible$4 = requireObjectCoercible$5;
var toIndexedObject$a = function (it) {
return IndexedObject$3(requireObjectCoercible$4(it));
};
var isCallable$h = isCallable$i;
var $documentAll = documentAll_1;
var documentAll = $documentAll.all;
var isObject$j = $documentAll.IS_HTMLDDA ? function (it) {
return typeof it == 'object' ? it !== null : isCallable$h(it) || it === documentAll;
} : function (it) {
return typeof it == 'object' ? it !== null : isCallable$h(it);
};
var path$w = {};
var path$v = path$w;
var global$m = global$n;
var isCallable$g = isCallable$i;
var aFunction = function (variable) {
return isCallable$g(variable) ? variable : undefined;
};
var getBuiltIn$c = function (namespace, method) {
return arguments.length < 2 ? aFunction(path$v[namespace]) || aFunction(global$m[namespace])
: path$v[namespace] && path$v[namespace][method] || global$m[namespace] && global$m[namespace][method];
};
var uncurryThis$u = functionUncurryThis;
var objectIsPrototypeOf = uncurryThis$u({}.isPrototypeOf);
var engineUserAgent = typeof navigator != 'undefined' && String(navigator.userAgent) || '';
var global$l = global$n;
var userAgent$2 = engineUserAgent;
var process = global$l.process;
var Deno = global$l.Deno;
var versions = process && process.versions || Deno && Deno.version;
var v8 = versions && versions.v8;
var match, version;
if (v8) {
match = v8.split('.');
// in old Chrome, versions of V8 isn't V8 = Chrome / 10
// but their correct versions are not interesting for us
version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]);
}
// BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0`
// so check `userAgent` even if `.v8` exists, but 0
if (!version && userAgent$2) {
match = userAgent$2.match(/Edge\/(\d+)/);
if (!match || match[1] >= 74) {
match = userAgent$2.match(/Chrome\/(\d+)/);
if (match) version = +match[1];
}
}
var engineV8Version = version;
/* eslint-disable es/no-symbol -- required for testing */
var V8_VERSION$2 = engineV8Version;
var fails$s = fails$w;
var global$k = global$n;
var $String$5 = global$k.String;
// eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
var symbolConstructorDetection = !!Object.getOwnPropertySymbols && !fails$s(function () {
var symbol = Symbol('symbol detection');
// Chrome 38 Symbol has incorrect toString conversion
// `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
// nb: Do not call `String` directly to avoid this being optimized out to `symbol+''` which will,
// of course, fail.
return !$String$5(symbol) || !(Object(symbol) instanceof Symbol) ||
// Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
!Symbol.sham && V8_VERSION$2 && V8_VERSION$2 < 41;
});
/* eslint-disable es/no-symbol -- required for testing */
var NATIVE_SYMBOL$5 = symbolConstructorDetection;
var useSymbolAsUid = NATIVE_SYMBOL$5
&& !Symbol.sham
&& typeof Symbol.iterator == 'symbol';
var getBuiltIn$b = getBuiltIn$c;
var isCallable$f = isCallable$i;
var isPrototypeOf$k = objectIsPrototypeOf;
var USE_SYMBOL_AS_UID$1 = useSymbolAsUid;
var $Object$4 = Object;
var isSymbol$5 = USE_SYMBOL_AS_UID$1 ? function (it) {
return typeof it == 'symbol';
} : function (it) {
var $Symbol = getBuiltIn$b('Symbol');
return isCallable$f($Symbol) && isPrototypeOf$k($Symbol.prototype, $Object$4(it));
};
var $String$4 = String;
var tryToString$6 = function (argument) {
try {
return $String$4(argument);
} catch (error) {
return 'Object';
}
};
var isCallable$e = isCallable$i;
var tryToString$5 = tryToString$6;
var $TypeError$f = TypeError;
// `Assert: IsCallable(argument) is true`
var aCallable$7 = function (argument) {
if (isCallable$e(argument)) return argument;
throw new $TypeError$f(tryToString$5(argument) + ' is not a function');
};
var aCallable$6 = aCallable$7;
var isNullOrUndefined$4 = isNullOrUndefined$6;
// `GetMethod` abstract operation
// https://tc39.es/ecma262/#sec-getmethod
var getMethod$3 = function (V, P) {
var func = V[P];
return isNullOrUndefined$4(func) ? undefined : aCallable$6(func);
};
var call$c = functionCall;
var isCallable$d = isCallable$i;
var isObject$i = isObject$j;
var $TypeError$e = TypeError;
// `OrdinaryToPrimitive` abstract operation
// https://tc39.es/ecma262/#sec-ordinarytoprimitive
var ordinaryToPrimitive$1 = function (input, pref) {
var fn, val;
if (pref === 'string' && isCallable$d(fn = input.toString) && !isObject$i(val = call$c(fn, input))) return val;
if (isCallable$d(fn = input.valueOf) && !isObject$i(val = call$c(fn, input))) return val;
if (pref !== 'string' && isCallable$d(fn = input.toString) && !isObject$i(val = call$c(fn, input))) return val;
throw new $TypeError$e("Can't convert object to primitive value");
};
var shared$7 = {exports: {}};
var global$j = global$n;
// eslint-disable-next-line es/no-object-defineproperty -- safe
var defineProperty$f = Object.defineProperty;
var defineGlobalProperty$1 = function (key, value) {
try {
defineProperty$f(global$j, key, { value: value, configurable: true, writable: true });
} catch (error) {
global$j[key] = value;
} return value;
};
var global$i = global$n;
var defineGlobalProperty = defineGlobalProperty$1;
var SHARED = '__core-js_shared__';
var store$3 = global$i[SHARED] || defineGlobalProperty(SHARED, {});
var sharedStore = store$3;
var store$2 = sharedStore;
(shared$7.exports = function (key, value) {
return store$2[key] || (store$2[key] = value !== undefined ? value : {});
})('versions', []).push({
version: '3.33.0',
mode: 'pure' ,
copyright: '© 2014-2023 Denis Pushkarev (zloirock.ru)',
license: 'https://github.com/zloirock/core-js/blob/v3.33.0/LICENSE',
source: 'https://github.com/zloirock/core-js'
});
var sharedExports = shared$7.exports;
var requireObjectCoercible$3 = requireObjectCoercible$5;
var $Object$3 = Object;
// `ToObject` abstract operation
// https://tc39.es/ecma262/#sec-toobject
var toObject$e = function (argument) {
return $Object$3(requireObjectCoercible$3(argument));
};
var uncurryThis$t = functionUncurryThis;
var toObject$d = toObject$e;
var hasOwnProperty = uncurryThis$t({}.hasOwnProperty);
// `HasOwnProperty` abstract operation
// https://tc39.es/ecma262/#sec-hasownproperty
// eslint-disable-next-line es/no-object-hasown -- safe
var hasOwnProperty_1 = Object.hasOwn || function hasOwn(it, key) {
return hasOwnProperty(toObject$d(it), key);
};
var uncurryThis$s = functionUncurryThis;
var id$2 = 0;
var postfix = Math.random();
var toString$b = uncurryThis$s(1.0.toString);
var uid$4 = function (key) {
return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString$b(++id$2 + postfix, 36);
};
var global$h = global$n;
var shared$6 = sharedExports;
var hasOwn$h = hasOwnProperty_1;
var uid$3 = uid$4;
var NATIVE_SYMBOL$4 = symbolConstructorDetection;
var USE_SYMBOL_AS_UID = useSymbolAsUid;
var Symbol$5 = global$h.Symbol;
var WellKnownSymbolsStore$2 = shared$6('wks');
var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol$5['for'] || Symbol$5 : Symbol$5 && Symbol$5.withoutSetter || uid$3;
var wellKnownSymbol$m = function (name) {
if (!hasOwn$h(WellKnownSymbolsStore$2, name)) {
WellKnownSymbolsStore$2[name] = NATIVE_SYMBOL$4 && hasOwn$h(Symbol$5, name)
? Symbol$5[name]
: createWellKnownSymbol('Symbol.' + name);
} return WellKnownSymbolsStore$2[name];
};
var call$b = functionCall;
var isObject$h = isObject$j;
var isSymbol$4 = isSymbol$5;
var getMethod$2 = getMethod$3;
var ordinaryToPrimitive = ordinaryToPrimitive$1;
var wellKnownSymbol$l = wellKnownSymbol$m;
var $TypeError$d = TypeError;
var TO_PRIMITIVE = wellKnownSymbol$l('toPrimitive');
// `ToPrimitive` abstract operation
// https://tc39.es/ecma262/#sec-toprimitive
var toPrimitive$6 = function (input, pref) {
if (!isObject$h(input) || isSymbol$4(input)) return input;
var exoticToPrim = getMethod$2(input, TO_PRIMITIVE);
var result;
if (exoticToPrim) {
if (pref === undefined) pref = 'default';
result = call$b(exoticToPrim, input, pref);
if (!isObject$h(result) || isSymbol$4(result)) return result;
throw new $TypeError$d("Can't convert object to primitive value");
}
if (pref === undefined) pref = 'number';
return ordinaryToPrimitive(input, pref);
};
var toPrimitive$5 = toPrimitive$6;
var isSymbol$3 = isSymbol$5;
// `ToPropertyKey` abstract operation
// https://tc39.es/ecma262/#sec-topropertykey
var toPropertyKey$4 = function (argument) {
var key = toPrimitive$5(argument, 'string');
return isSymbol$3(key) ? key : key + '';
};
var global$g = global$n;
var isObject$g = isObject$j;
var document$1 = global$g.document;
// typeof document.createElement is 'object' in old IE
var EXISTS$1 = isObject$g(document$1) && isObject$g(document$1.createElement);
var documentCreateElement$1 = function (it) {
return EXISTS$1 ? document$1.createElement(it) : {};
};
var DESCRIPTORS$h = descriptors;
var fails$r = fails$w;
var createElement = documentCreateElement$1;
// Thanks to IE8 for its funny defineProperty
var ie8DomDefine = !DESCRIPTORS$h && !fails$r(function () {
// eslint-disable-next-line es/no-object-defineproperty -- required for testing
return Object.defineProperty(createElement('div'), 'a', {
get: function () { return 7; }
}).a !== 7;
});
var DESCRIPTORS$g = descriptors;
var call$a = functionCall;
var propertyIsEnumerableModule$2 = objectPropertyIsEnumerable;
var createPropertyDescriptor$4 = createPropertyDescriptor$5;
var toIndexedObject$9 = toIndexedObject$a;
var toPropertyKey$3 = toPropertyKey$4;
var hasOwn$g = hasOwnProperty_1;
var IE8_DOM_DEFINE$1 = ie8DomDefine;
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
var $getOwnPropertyDescriptor$2 = Object.getOwnPropertyDescriptor;
// `Object.getOwnPropertyDescriptor` method
// https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
objectGetOwnPropertyDescriptor.f = DESCRIPTORS$g ? $getOwnPropertyDescriptor$2 : function getOwnPropertyDescriptor(O, P) {
O = toIndexedObject$9(O);
P = toPropertyKey$3(P);
if (IE8_DOM_DEFINE$1) try {
return $getOwnPropertyDescriptor$2(O, P);
} catch (error) { /* empty */ }
if (hasOwn$g(O, P)) return createPropertyDescriptor$4(!call$a(propertyIsEnumerableModule$2.f, O, P), O[P]);
};
var fails$q = fails$w;
var isCallable$c = isCallable$i;
var replacement = /#|\.prototype\./;
var isForced$1 = function (feature, detection) {
var value = data[normalize(feature)];
return value === POLYFILL ? true
: value === NATIVE ? false
: isCallable$c(detection) ? fails$q(detection)
: !!detection;
};
var normalize = isForced$1.normalize = function (string) {
return String(string).replace(replacement, '.').toLowerCase();
};
var data = isForced$1.data = {};
var NATIVE = isForced$1.NATIVE = 'N';
var POLYFILL = isForced$1.POLYFILL = 'P';
var isForced_1 = isForced$1;
var uncurryThis$r = functionUncurryThisClause;
var aCallable$5 = aCallable$7;
var NATIVE_BIND$1 = functionBindNative;
var bind$e = uncurryThis$r(uncurryThis$r.bind);
// optional / simple context binding
var functionBindContext = function (fn, that) {
aCallable$5(fn);
return that === undefined ? fn : NATIVE_BIND$1 ? bind$e(fn, that) : function (/* ...args */) {
return fn.apply(that, arguments);
};
};
var objectDefineProperty = {};
var DESCRIPTORS$f = descriptors;
var fails$p = fails$w;
// V8 ~ Chrome 36-
// https://bugs.chromium.org/p/v8/issues/detail?id=3334
var v8PrototypeDefineBug = DESCRIPTORS$f && fails$p(function () {
// eslint-disable-next-line es/no-object-defineproperty -- required for testing
return Object.defineProperty(function () { /* empty */ }, 'prototype', {
value: 42,
writable: false
}).prototype !== 42;
});
var isObject$f = isObject$j;
var $String$3 = String;
var $TypeError$c = TypeError;
// `Assert: Type(argument) is Object`
var anObject$d = function (argument) {
if (isObject$f(argument)) return argument;
throw new $TypeError$c($String$3(argument) + ' is not an object');
};
var DESCRIPTORS$e = descriptors;
var IE8_DOM_DEFINE = ie8DomDefine;
var V8_PROTOTYPE_DEFINE_BUG$1 = v8PrototypeDefineBug;
var anObject$c = anObject$d;
var toPropertyKey$2 = toPropertyKey$4;
var $TypeError$b = TypeError;
// eslint-disable-next-line es/no-object-defineproperty -- safe
var $defineProperty$1 = Object.defineProperty;
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
var $getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
var ENUMERABLE = 'enumerable';
var CONFIGURABLE$1 = 'configurable';
var WRITABLE = 'writable';
// `Object.defineProperty` method
// https://tc39.es/ecma262/#sec-object.defineproperty
objectDefineProperty.f = DESCRIPTORS$e ? V8_PROTOTYPE_DEFINE_BUG$1 ? function defineProperty(O, P, Attributes) {
anObject$c(O);
P = toPropertyKey$2(P);
anObject$c(Attributes);
if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) {
var current = $getOwnPropertyDescriptor$1(O, P);
if (current && current[WRITABLE]) {
O[P] = Attributes.value;
Attributes = {
configurable: CONFIGURABLE$1 in Attributes ? Attributes[CONFIGURABLE$1] : current[CONFIGURABLE$1],
enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE],
writable: false
};
}
} return $defineProperty$1(O, P, Attributes);
} : $defineProperty$1 : function defineProperty(O, P, Attributes) {
anObject$c(O);
P = toPropertyKey$2(P);
anObject$c(Attributes);
if (IE8_DOM_DEFINE) try {
return $defineProperty$1(O, P, Attributes);
} catch (error) { /* empty */ }
if ('get' in Attributes || 'set' in Attributes) throw new $TypeError$b('Accessors not supported');
if ('value' in Attributes) O[P] = Attributes.value;
return O;
};
var DESCRIPTORS$d = descriptors;
var definePropertyModule$3 = objectDefineProperty;
var createPropertyDescriptor$3 = createPropertyDescriptor$5;
var createNonEnumerableProperty$6 = DESCRIPTORS$d ? function (object, key, value) {
return definePropertyModule$3.f(object, key, createPropertyDescriptor$3(1, value));
} : function (object, key, value) {
object[key] = value;
return object;
};
var global$f = global$n;
var apply$4 = functionApply;
var uncurryThis$q = functionUncurryThisClause;
var isCallable$b = isCallable$i;
var getOwnPropertyDescriptor$8 = objectGetOwnPropertyDescriptor.f;
var isForced = isForced_1;
var path$u = path$w;
var bind$d = functionBindContext;
var createNonEnumerableProperty$5 = createNonEnumerableProperty$6;
var hasOwn$f = hasOwnProperty_1;
var wrapConstructor = function (NativeConstructor) {
var Wrapper = function (a, b, c) {
if (this instanceof Wrapper) {
switch (arguments.length) {
case 0: return new NativeConstructor();
case 1: return new NativeConstructor(a);
case 2: return new NativeConstructor(a, b);
} return new NativeConstructor(a, b, c);
} return apply$4(NativeConstructor, this, arguments);
};
Wrapper.prototype = NativeConstructor.prototype;
return Wrapper;
};
/*
options.target - name of the target object
options.global - target is the global object
options.stat - export as static methods of target
options.proto - export as prototype methods of target
options.real - real prototype method for the `pure` version
options.forced - export even if the native feature is available
options.bind - bind methods to the target, required for the `pure` version
options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
options.unsafe - use the simple assignment of property instead of delete + defineProperty
options.sham - add a flag to not completely full polyfills
options.enumerable - export as enumerable property
options.dontCallGetSet - prevent calling a getter on target
options.name - the .name of the function if it does not match the key
*/
var _export = function (options, source) {
var TARGET = options.target;
var GLOBAL = options.global;
var STATIC = options.stat;
var PROTO = options.proto;
var nativeSource = GLOBAL ? global$f : STATIC ? global$f[TARGET] : (global$f[TARGET] || {}).prototype;
var target = GLOBAL ? path$u : path$u[TARGET] || createNonEnumerableProperty$5(path$u, TARGET, {})[TARGET];
var targetPrototype = target.prototype;
var FORCED, USE_NATIVE, VIRTUAL_PROTOTYPE;
var key, sourceProperty, targetProperty, nativeProperty, resultProperty, descriptor;
for (key in source) {
FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
// contains in native
USE_NATIVE = !FORCED && nativeSource && hasOwn$f(nativeSource, key);
targetProperty = target[key];
if (USE_NATIVE) if (options.dontCallGetSet) {
descriptor = getOwnPropertyDescriptor$8(nativeSource, key);
nativeProperty = descriptor && descriptor.value;
} else nativeProperty = nativeSource[key];
// export native or implementation
sourceProperty = (USE_NATIVE && nativeProperty) ? nativeProperty : source[key];
if (USE_NATIVE && typeof targetProperty == typeof sourceProperty) continue;
// bind methods to global for calling from export context
if (options.bind && USE_NATIVE) resultProperty = bind$d(sourceProperty, global$f);
// wrap global constructors for prevent changes in this version
else if (options.wrap && USE_NATIVE) resultProperty = wrapConstructor(sourceProperty);
// make static versions for prototype methods
else if (PROTO && isCallable$b(sourceProperty)) resultProperty = uncurryThis$q(sourceProperty);
// default case
else resultProperty = sourceProperty;
// add a flag to not completely full polyfills
if (options.sham || (sourceProperty && sourceProperty.sham) || (targetProperty && targetProperty.sham)) {
createNonEnumerableProperty$5(resultProperty, 'sham', true);
}
createNonEnumerableProperty$5(target, key, resultProperty);
if (PROTO) {
VIRTUAL_PROTOTYPE = TARGET + 'Prototype';
if (!hasOwn$f(path$u, VIRTUAL_PROTOTYPE)) {
createNonEnumerableProperty$5(path$u, VIRTUAL_PROTOTYPE, {});
}
// export virtual prototype methods
createNonEnumerableProperty$5(path$u[VIRTUAL_PROTOTYPE], key, sourceProperty);
// export real prototype methods
if (options.real && targetPrototype && (FORCED || !targetPrototype[key])) {
createNonEnumerableProperty$5(targetPrototype, key, sourceProperty);
}
}
}
};
var ceil = Math.ceil;
var floor$1 = Math.floor;
// `Math.trunc` method
// https://tc39.es/ecma262/#sec-math.trunc
// eslint-disable-next-line es/no-math-trunc -- safe
var mathTrunc = Math.trunc || function trunc(x) {
var n = +x;
return (n > 0 ? floor$1 : ceil)(n);
};
var trunc = mathTrunc;
// `ToIntegerOrInfinity` abstract operation
// https://tc39.es/ecma262/#sec-tointegerorinfinity
var toIntegerOrInfinity$4 = function (argument) {
var number = +argument;
// eslint-disable-next-line no-self-compare -- NaN check
return number !== number || number === 0 ? 0 : trunc(number);
};
var toIntegerOrInfinity$3 = toIntegerOrInfinity$4;
var max$3 = Math.max;
var min$2 = Math.min;
// Helper for a popular repeating case of the spec:
// Let integer be ? ToInteger(index).
// If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
var toAbsoluteIndex$5 = function (index, length) {
var integer = toIntegerOrInfinity$3(index);
return integer < 0 ? max$3(integer + length, 0) : min$2(integer, length);
};
var toIntegerOrInfinity$2 = toIntegerOrInfinity$4;
var min$1 = Math.min;
// `ToLength` abstract operation
// https://tc39.es/ecma262/#sec-tolength
var toLength$1 = function (argument) {
return argument > 0 ? min$1(toIntegerOrInfinity$2(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
};
var toLength = toLength$1;
// `LengthOfArrayLike` abstract operation
// https://tc39.es/ecma262/#sec-lengthofarraylike
var lengthOfArrayLike$c = function (obj) {
return toLength(obj.length);
};
var toIndexedObject$8 = toIndexedObject$a;
var toAbsoluteIndex$4 = toAbsoluteIndex$5;
var lengthOfArrayLike$b = lengthOfArrayLike$c;
// `Array.prototype.{ indexOf, includes }` methods implementation
var createMethod$4 = function (IS_INCLUDES) {
return function ($this, el, fromIndex) {
var O = toIndexedObject$8($this);
var length = lengthOfArrayLike$b(O);
var index = toAbsoluteIndex$4(fromIndex, length);
var value;
// Array#includes uses SameValueZero equality algorithm
// eslint-disable-next-line no-self-compare -- NaN check
if (IS_INCLUDES && el !== el) while (length > index) {
value = O[index++];
// eslint-disable-next-line no-self-compare -- NaN check
if (value !== value) return true;
// Array#indexOf ignores holes, Array#includes - not
} else for (;length > index; index++) {
if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
} return !IS_INCLUDES && -1;
};
};
var arrayIncludes = {
// `Array.prototype.includes` method
// https://tc39.es/ecma262/#sec-array.prototype.includes
includes: createMethod$4(true),
// `Array.prototype.indexOf` method
// https://tc39.es/ecma262/#sec-array.prototype.indexof
indexOf: createMethod$4(false)
};
var hiddenKeys$6 = {};
var uncurryThis$p = functionUncurryThis;
var hasOwn$e = hasOwnProperty_1;
var toIndexedObject$7 = toIndexedObject$a;
var indexOf$4 = arrayIncludes.indexOf;
var hiddenKeys$5 = hiddenKeys$6;
var push$b = uncurryThis$p([].push);
var objectKeysInternal = function (object, names) {
var O = toIndexedObject$7(object);
var i = 0;
var result = [];
var key;
for (key in O) !hasOwn$e(hiddenKeys$5, key) && hasOwn$e(O, key) && push$b(result, key);
// Don't enum bug & hidden keys
while (names.length > i) if (hasOwn$e(O, key = names[i++])) {
~indexOf$4(result, key) || push$b(result, key);
}
return result;
};
// IE8- don't enum bug keys
var enumBugKeys$3 = [
'constructor',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'toLocaleString',
'toString',
'valueOf'
];
var internalObjectKeys$1 = objectKeysInternal;
var enumBugKeys$2 = enumBugKeys$3;
// `Object.keys` method
// https://tc39.es/ecma262/#sec-object.keys
// eslint-disable-next-line es/no-object-keys -- safe
var objectKeys$3 = Object.keys || function keys(O) {
return internalObjectKeys$1(O, enumBugKeys$2);
};
var objectGetOwnPropertySymbols = {};
// eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
objectGetOwnPropertySymbols.f = Object.getOwnPropertySymbols;
var DESCRIPTORS$c = descriptors;
var uncurryThis$o = functionUncurryThis;
var call$9 = functionCall;
var fails$o = fails$w;
var objectKeys$2 = objectKeys$3;
var getOwnPropertySymbolsModule$3 = objectGetOwnPropertySymbols;
var propertyIsEnumerableModule$1 = objectPropertyIsEnumerable;
var toObject$c = toObject$e;
var IndexedObject$2 = indexedObject;
// eslint-disable-next-line es/no-object-assign -- safe
var $assign = Object.assign;
// eslint-disable-next-line es/no-object-defineproperty -- required for testing
var defineProperty$e = Object.defineProperty;
var concat$6 = uncurryThis$o([].concat);
// `Object.assign` method
// https://tc39.es/ecma262/#sec-object.assign
var objectAssign = !$assign || fails$o(function () {
// should have correct order of operations (Edge bug)
if (DESCRIPTORS$c && $assign({ b: 1 }, $assign(defineProperty$e({}, 'a', {
enumerable: true,
get: function () {
defineProperty$e(this, 'b', {
value: 3,
enumerable: false
});
}
}), { b: 2 })).b !== 1) return true;
// should work with symbols and should have deterministic property order (V8 bug)
var A = {};
var B = {};
// eslint-disable-next-line es/no-symbol -- safe
var symbol = Symbol('assign detection');
var alphabet = 'abcdefghijklmnopqrst';
A[symbol] = 7;
alphabet.split('').forEach(function (chr) { B[chr] = chr; });
return $assign({}, A)[symbol] !== 7 || objectKeys$2($assign({}, B)).join('') !== alphabet;
}) ? function assign(target, source) { // eslint-disable-line no-unused-vars -- required for `.length`
var T = toObject$c(target);
var argumentsLength = arguments.length;
var index = 1;
var getOwnPropertySymbols = getOwnPropertySymbolsModule$3.f;
var propertyIsEnumerable = propertyIsEnumerableModule$1.f;
while (argumentsLength > index) {
var S = IndexedObject$2(arguments[index++]);
var keys = getOwnPropertySymbols ? concat$6(objectKeys$2(S), getOwnPropertySymbols(S)) : objectKeys$2(S);
var length = keys.length;
var j = 0;
var key;
while (length > j) {
key = keys[j++];
if (!DESCRIPTORS$c || call$9(propertyIsEnumerable, S, key)) T[key] = S[key];
}
} return T;
} : $assign;
var $$O = _export;
var assign$5 = objectAssign;
// `Object.assign` method
// https://tc39.es/ecma262/#sec-object.assign
// eslint-disable-next-line es/no-object-assign -- required for testing
$$O({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign$5 }, {
assign: assign$5
});
var path$t = path$w;
var assign$4 = path$t.Object.assign;
var parent$1b = assign$4;
var assign$3 = parent$1b;
var assign$2 = assign$3;
var _Object$assign = /*@__PURE__*/getDefaultExportFromCjs(assign$2);
var uncurryThis$n = functionUncurryThis;
var arraySlice$5 = uncurryThis$n([].slice);
var uncurryThis$m = functionUncurryThis;
var aCallable$4 = aCallable$7;
var isObject$e = isObject$j;
var hasOwn$d = hasOwnProperty_1;
var arraySlice$4 = arraySlice$5;
var NATIVE_BIND = functionBindNative;
var $Function = Function;
var concat$5 = uncurryThis$m([].concat);
var join = uncurryThis$m([].join);
var factories = {};
var construct$4 = function (C, argsLength, args) {
if (!hasOwn$d(factories, argsLength)) {
var list = [];
var i = 0;
for (; i < argsLength; i++) list[i] = 'a[' + i + ']';
factories[argsLength] = $Function('C,a', 'return new C(' + join(list, ',') + ')');
} return factories[argsLength](C, args);
};
// `Function.prototype.bind` method implementation
// https://tc39.es/ecma262/#sec-function.prototype.bind
// eslint-disable-next-line es/no-function-prototype-bind -- detection
var functionBind = NATIVE_BIND ? $Function.bind : function bind(that /* , ...args */) {
var F = aCallable$4(this);
var Prototype = F.prototype;
var partArgs = arraySlice$4(arguments, 1);
var boundFunction = function bound(/* args... */) {
var args = concat$5(partArgs, arraySlice$4(arguments));
return this instanceof boundFunction ? construct$4(F, args.length, args) : F.apply(that, args);
};
if (isObject$e(Prototype)) boundFunction.prototype = Prototype;
return boundFunction;
};
// TODO: Remove from `core-js@4`
var $$N = _export;
var bind$c = functionBind;
// `Function.prototype.bind` method
// https://tc39.es/ecma262/#sec-function.prototype.bind
// eslint-disable-next-line es/no-function-prototype-bind -- detection
$$N({ target: 'Function', proto: true, forced: Function.bind !== bind$c }, {
bind: bind$c
});
var path$s = path$w;
var entryVirtual$i = function (CONSTRUCTOR) {
return path$s[CONSTRUCTOR + 'Prototype'];
};
var entryVirtual$h = entryVirtual$i;
var bind$b = entryVirtual$h('Function').bind;
var isPrototypeOf$j = objectIsPrototypeOf;
var method$f = bind$b;
var FunctionPrototype$2 = Function.prototype;
var bind$a = function (it) {
var own = it.bind;
return it === FunctionPrototype$2 || (isPrototypeOf$j(FunctionPrototype$2, it) && own === FunctionPrototype$2.bind) ? method$f : own;
};
var parent$1a = bind$a;
var bind$9 = parent$1a;
var bind$8 = bind$9;
var _bindInstanceProperty$1 = /*@__PURE__*/getDefaultExportFromCjs(bind$8);
/**
* Draw a circle.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The position of the center on the x axis.
* @param y - The position of the center on the y axis.
* @param r - The radius of the circle.
*/
function drawCircle(ctx, x, y, r) {
ctx.beginPath();
ctx.arc(x, y, r, 0, 2 * Math.PI, false);
ctx.closePath();
}
/**
* Draw a square.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The position of the center on the x axis.
* @param y - The position of the center on the y axis.
* @param r - Half of the width and height of the square.
*/
function drawSquare(ctx, x, y, r) {
ctx.beginPath();
ctx.rect(x - r, y - r, r * 2, r * 2);
ctx.closePath();
}
/**
* Draw an equilateral triangle standing on a side.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The position of the center on the x axis.
* @param y - The position of the center on the y axis.
* @param r - Half of the length of the sides.
* @remarks
* http://en.wikipedia.org/wiki/Equilateral_triangle
*/
function drawTriangle(ctx, x, y, r) {
ctx.beginPath();
// the change in radius and the offset is here to center the shape
r *= 1.15;
y += 0.275 * r;
var s = r * 2;
var s2 = s / 2;
var ir = Math.sqrt(3) / 6 * s; // radius of inner circle
var h = Math.sqrt(s * s - s2 * s2); // height
ctx.moveTo(x, y - (h - ir));
ctx.lineTo(x + s2, y + ir);
ctx.lineTo(x - s2, y + ir);
ctx.lineTo(x, y - (h - ir));
ctx.closePath();
}
/**
* Draw an equilateral triangle standing on a vertex.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The position of the center on the x axis.
* @param y - The position of the center on the y axis.
* @param r - Half of the length of the sides.
* @remarks
* http://en.wikipedia.org/wiki/Equilateral_triangle
*/
function drawTriangleDown(ctx, x, y, r) {
ctx.beginPath();
// the change in radius and the offset is here to center the shape
r *= 1.15;
y -= 0.275 * r;
var s = r * 2;
var s2 = s / 2;
var ir = Math.sqrt(3) / 6 * s; // radius of inner circle
var h = Math.sqrt(s * s - s2 * s2); // height
ctx.moveTo(x, y + (h - ir));
ctx.lineTo(x + s2, y - ir);
ctx.lineTo(x - s2, y - ir);
ctx.lineTo(x, y + (h - ir));
ctx.closePath();
}
/**
* Draw a star.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The position of the center on the x axis.
* @param y - The position of the center on the y axis.
* @param r - The outer radius of the star.
*/
function drawStar(ctx, x, y, r) {
// http://www.html5canvastutorials.com/labs/html5-canvas-star-spinner/
ctx.beginPath();
// the change in radius and the offset is here to center the shape
r *= 0.82;
y += 0.1 * r;
for (var n = 0; n < 10; n++) {
var radius = n % 2 === 0 ? r * 1.3 : r * 0.5;
ctx.lineTo(x + radius * Math.sin(n * 2 * Math.PI / 10), y - radius * Math.cos(n * 2 * Math.PI / 10));
}
ctx.closePath();
}
/**
* Draw a diamond.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The position of the center on the x axis.
* @param y - The position of the center on the y axis.
* @param r - Half of the width and height of the diamond.
* @remarks
* http://www.html5canvastutorials.com/labs/html5-canvas-star-spinner/
*/
function drawDiamond(ctx, x, y, r) {
ctx.beginPath();
ctx.lineTo(x, y + r);
ctx.lineTo(x + r, y);
ctx.lineTo(x, y - r);
ctx.lineTo(x - r, y);
ctx.closePath();
}
/**
* Draw a rectangle with rounded corners.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The position of the center on the x axis.
* @param y - The position of the center on the y axis.
* @param w - The width of the rectangle.
* @param h - The height of the rectangle.
* @param r - The radius of the corners.
* @remarks
* http://stackoverflow.com/questions/1255512/how-to-draw-a-rounded-rectangle-on-html-canvas
*/
function drawRoundRect(ctx, x, y, w, h, r) {
var r2d = Math.PI / 180;
if (w - 2 * r < 0) {
r = w / 2;
} //ensure that the radius isn't too large for x
if (h - 2 * r < 0) {
r = h / 2;
} //ensure that the radius isn't too large for y
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.arc(x + w - r, y + r, r, r2d * 270, r2d * 360, false);
ctx.lineTo(x + w, y + h - r);
ctx.arc(x + w - r, y + h - r, r, 0, r2d * 90, false);
ctx.lineTo(x + r, y + h);
ctx.arc(x + r, y + h - r, r, r2d * 90, r2d * 180, false);
ctx.lineTo(x, y + r);
ctx.arc(x + r, y + r, r, r2d * 180, r2d * 270, false);
ctx.closePath();
}
/**
* Draw an ellipse.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The position of the center on the x axis.
* @param y - The position of the center on the y axis.
* @param w - The width of the ellipse.
* @param h - The height of the ellipse.
* @remarks
* http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
*
* Postfix '_vis' added to discern it from standard method ellipse().
*/
function drawEllipse(ctx, x, y, w, h) {
var kappa = 0.5522848,
ox = w / 2 * kappa,
// control point offset horizontal
oy = h / 2 * kappa,
// control point offset vertical
xe = x + w,
// x-end
ye = y + h,
// y-end
xm = x + w / 2,
// x-middle
ym = y + h / 2; // y-middle
ctx.beginPath();
ctx.moveTo(x, ym);
ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
ctx.closePath();
}
/**
* Draw an isometric cylinder.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The position of the center on the x axis.
* @param y - The position of the center on the y axis.
* @param w - The width of the database.
* @param h - The height of the database.
* @remarks
* http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
*/
function drawDatabase(ctx, x, y, w, h) {
var f = 1 / 3;
var wEllipse = w;
var hEllipse = h * f;
var kappa = 0.5522848,
ox = wEllipse / 2 * kappa,
// control point offset horizontal
oy = hEllipse / 2 * kappa,
// control point offset vertical
xe = x + wEllipse,
// x-end
ye = y + hEllipse,
// y-end
xm = x + wEllipse / 2,
// x-middle
ym = y + hEllipse / 2,
// y-middle
ymb = y + (h - hEllipse / 2),
// y-midlle, bottom ellipse
yeb = y + h; // y-end, bottom ellipse
ctx.beginPath();
ctx.moveTo(xe, ym);
ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
ctx.lineTo(xe, ymb);
ctx.bezierCurveTo(xe, ymb + oy, xm + ox, yeb, xm, yeb);
ctx.bezierCurveTo(xm - ox, yeb, x, ymb + oy, x, ymb);
ctx.lineTo(x, ym);
}
/**
* Draw a dashed line.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The start position on the x axis.
* @param y - The start position on the y axis.
* @param x2 - The end position on the x axis.
* @param y2 - The end position on the y axis.
* @param pattern - List of lengths starting with line and then alternating between space and line.
* @author David Jordan
* @remarks
* date 2012-08-08
* http://stackoverflow.com/questions/4576724/dotted-stroke-in-canvas
*/
function drawDashedLine(ctx, x, y, x2, y2, pattern) {
ctx.beginPath();
ctx.moveTo(x, y);
var patternLength = pattern.length;
var dx = x2 - x;
var dy = y2 - y;
var slope = dy / dx;
var distRemaining = Math.sqrt(dx * dx + dy * dy);
var patternIndex = 0;
var draw = true;
var xStep = 0;
var dashLength = +pattern[0];
while (distRemaining >= 0.1) {
dashLength = +pattern[patternIndex++ % patternLength];
if (dashLength > distRemaining) {
dashLength = distRemaining;
}
xStep = Math.sqrt(dashLength * dashLength / (1 + slope * slope));
xStep = dx < 0 ? -xStep : xStep;
x += xStep;
y += slope * xStep;
if (draw === true) {
ctx.lineTo(x, y);
} else {
ctx.moveTo(x, y);
}
distRemaining -= dashLength;
draw = !draw;
}
}
/**
* Draw a hexagon.
*
* @param ctx - The context this shape will be rendered to.
* @param x - The position of the center on the x axis.
* @param y - The position of the center on the y axis.
* @param r - The radius of the hexagon.
*/
function drawHexagon(ctx, x, y, r) {
ctx.beginPath();
var sides = 6;
var a = Math.PI * 2 / sides;
ctx.moveTo(x + r, y);
for (var i = 1; i < sides; i++) {
ctx.lineTo(x + r * Math.cos(a * i), y + r * Math.sin(a * i));
}
ctx.closePath();
}
var shapeMap = {
circle: drawCircle,
dashedLine: drawDashedLine,
database: drawDatabase,
diamond: drawDiamond,
ellipse: drawEllipse,
ellipse_vis: drawEllipse,
hexagon: drawHexagon,
roundRect: drawRoundRect,
square: drawSquare,
star: drawStar,
triangle: drawTriangle,
triangleDown: drawTriangleDown
};
/**
* Returns either custom or native drawing function base on supplied name.
*
* @param name - The name of the function. Either the name of a
* CanvasRenderingContext2D property or an export from shapes.ts without the
* draw prefix.
* @returns The function that can be used for rendering. In case of native
* CanvasRenderingContext2D function the API is normalized to
* `(ctx: CanvasRenderingContext2D, ...originalArgs) => void`.
*/
function getShape(name) {
if (Object.prototype.hasOwnProperty.call(shapeMap, name)) {
return shapeMap[name];
} else {
return function (ctx) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
CanvasRenderingContext2D.prototype[name].call(ctx, args);
};
}
}
var componentEmitter = {exports: {}};
(function (module) {
/**
* Expose `Emitter`.
*/
{
module.exports = Emitter;
}
/**
* Initialize a new `Emitter`.
*
* @api public
*/
function Emitter(obj) {
if (obj) return mixin(obj);
}
/**
* Mixin the emitter properties.
*
* @param {Object} obj
* @return {Object}
* @api private
*/
function mixin(obj) {
for (var key in Emitter.prototype) {
obj[key] = Emitter.prototype[key];
}
return obj;
}
/**
* Listen on the given `event` with `fn`.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.on =
Emitter.prototype.addEventListener = function(event, fn){
this._callbacks = this._callbacks || {};
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
.push(fn);
return this;
};
/**
* Adds an `event` listener that will be invoked a single
* time then automatically removed.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.once = function(event, fn){
function on() {
this.off(event, on);
fn.apply(this, arguments);
}
on.fn = fn;
this.on(event, on);
return this;
};
/**
* Remove the given callback for `event` or all
* registered callbacks.
*
* @param {String} event
* @param {Function} fn
* @return {Emitter}
* @api public
*/
Emitter.prototype.off =
Emitter.prototype.removeListener =
Emitter.prototype.removeAllListeners =
Emitter.prototype.removeEventListener = function(event, fn){
this._callbacks = this._callbacks || {};
// all
if (0 == arguments.length) {
this._callbacks = {};
return this;
}
// specific event
var callbacks = this._callbacks['$' + event];
if (!callbacks) return this;
// remove all handlers
if (1 == arguments.length) {
delete this._callbacks['$' + event];
return this;
}
// remove specific handler
var cb;
for (var i = 0; i < callbacks.length; i++) {
cb = callbacks[i];
if (cb === fn || cb.fn === fn) {
callbacks.splice(i, 1);
break;
}
}
// Remove event specific arrays for event types that no
// one is subscribed for to avoid memory leak.
if (callbacks.length === 0) {
delete this._callbacks['$' + event];
}
return this;
};
/**
* Emit `event` with the given args.
*
* @param {String} event
* @param {Mixed} ...
* @return {Emitter}
*/
Emitter.prototype.emit = function(event){
this._callbacks = this._callbacks || {};
var args = new Array(arguments.length - 1)
, callbacks = this._callbacks['$' + event];
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
if (callbacks) {
callbacks = callbacks.slice(0);
for (var i = 0, len = callbacks.length; i < len; ++i) {
callbacks[i].apply(this, args);
}
}
return this;
};
/**
* Return array of callbacks for `event`.
*
* @param {String} event
* @return {Array}
* @api public
*/
Emitter.prototype.listeners = function(event){
this._callbacks = this._callbacks || {};
return this._callbacks['$' + event] || [];
};
/**
* Check if this emitter has `event` handlers.
*
* @param {String} e