cytoscape
Version:
Graph theory (a.k.a. network) library for analysis and visualisation
1,780 lines (1,540 loc) • 981 kB
JavaScript
/**
* Copyright (c) 2016-2022, The Cytoscape Consortium.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the “Software”), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.cytoscape = factory());
})(this, (function () { 'use strict';
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty$1(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var window$1 = typeof window === 'undefined' ? null : window; // eslint-disable-line no-undef
var navigator = window$1 ? window$1.navigator : null;
window$1 ? window$1.document : null;
var typeofstr = _typeof('');
var typeofobj = _typeof({});
var typeoffn = _typeof(function () {});
var typeofhtmlele = typeof HTMLElement === "undefined" ? "undefined" : _typeof(HTMLElement);
var instanceStr = function instanceStr(obj) {
return obj && obj.instanceString && fn$6(obj.instanceString) ? obj.instanceString() : null;
};
var string = function string(obj) {
return obj != null && _typeof(obj) == typeofstr;
};
var fn$6 = function fn(obj) {
return obj != null && _typeof(obj) === typeoffn;
};
var array = function array(obj) {
return !elementOrCollection(obj) && (Array.isArray ? Array.isArray(obj) : obj != null && obj instanceof Array);
};
var plainObject = function plainObject(obj) {
return obj != null && _typeof(obj) === typeofobj && !array(obj) && obj.constructor === Object;
};
var object = function object(obj) {
return obj != null && _typeof(obj) === typeofobj;
};
var number$1 = function number(obj) {
return obj != null && _typeof(obj) === _typeof(1) && !isNaN(obj);
};
var integer = function integer(obj) {
return number$1(obj) && Math.floor(obj) === obj;
};
var htmlElement = function htmlElement(obj) {
if ('undefined' === typeofhtmlele) {
return undefined;
} else {
return null != obj && obj instanceof HTMLElement;
}
};
var elementOrCollection = function elementOrCollection(obj) {
return element(obj) || collection(obj);
};
var element = function element(obj) {
return instanceStr(obj) === 'collection' && obj._private.single;
};
var collection = function collection(obj) {
return instanceStr(obj) === 'collection' && !obj._private.single;
};
var core = function core(obj) {
return instanceStr(obj) === 'core';
};
var stylesheet = function stylesheet(obj) {
return instanceStr(obj) === 'stylesheet';
};
var event = function event(obj) {
return instanceStr(obj) === 'event';
};
var emptyString = function emptyString(obj) {
if (obj === undefined || obj === null) {
// null is empty
return true;
} else if (obj === '' || obj.match(/^\s+$/)) {
return true; // empty string is empty
}
return false; // otherwise, we don't know what we've got
};
var domElement = function domElement(obj) {
if (typeof HTMLElement === 'undefined') {
return false; // we're not in a browser so it doesn't matter
} else {
return obj instanceof HTMLElement;
}
};
var boundingBox = function boundingBox(obj) {
return plainObject(obj) && number$1(obj.x1) && number$1(obj.x2) && number$1(obj.y1) && number$1(obj.y2);
};
var promise = function promise(obj) {
return object(obj) && fn$6(obj.then);
};
var ms = function ms() {
return navigator && navigator.userAgent.match(/msie|trident|edge/i);
}; // probably a better way to detect this...
var memoize$1 = function memoize(fn, keyFn) {
if (!keyFn) {
keyFn = function keyFn() {
if (arguments.length === 1) {
return arguments[0];
} else if (arguments.length === 0) {
return 'undefined';
}
var args = [];
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
return args.join('$');
};
}
var memoizedFn = function memoizedFn() {
var self = this;
var args = arguments;
var ret;
var k = keyFn.apply(self, args);
var cache = memoizedFn.cache;
if (!(ret = cache[k])) {
ret = cache[k] = fn.apply(self, args);
}
return ret;
};
memoizedFn.cache = {};
return memoizedFn;
};
var camel2dash = memoize$1(function (str) {
return str.replace(/([A-Z])/g, function (v) {
return '-' + v.toLowerCase();
});
});
var dash2camel = memoize$1(function (str) {
return str.replace(/(-\w)/g, function (v) {
return v[1].toUpperCase();
});
});
var prependCamel = memoize$1(function (prefix, str) {
return prefix + str[0].toUpperCase() + str.substring(1);
}, function (prefix, str) {
return prefix + '$' + str;
});
var capitalize = function capitalize(str) {
if (emptyString(str)) {
return str;
}
return str.charAt(0).toUpperCase() + str.substring(1);
};
var number = '(?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))';
var rgba = 'rgb[a]?\\((' + number + '[%]?)\\s*,\\s*(' + number + '[%]?)\\s*,\\s*(' + number + '[%]?)(?:\\s*,\\s*(' + number + '))?\\)';
var rgbaNoBackRefs = 'rgb[a]?\\((?:' + number + '[%]?)\\s*,\\s*(?:' + number + '[%]?)\\s*,\\s*(?:' + number + '[%]?)(?:\\s*,\\s*(?:' + number + '))?\\)';
var hsla = 'hsl[a]?\\((' + number + ')\\s*,\\s*(' + number + '[%])\\s*,\\s*(' + number + '[%])(?:\\s*,\\s*(' + number + '))?\\)';
var hslaNoBackRefs = 'hsl[a]?\\((?:' + number + ')\\s*,\\s*(?:' + number + '[%])\\s*,\\s*(?:' + number + '[%])(?:\\s*,\\s*(?:' + number + '))?\\)';
var hex3 = '\\#[0-9a-fA-F]{3}';
var hex6 = '\\#[0-9a-fA-F]{6}';
var ascending = function ascending(a, b) {
if (a < b) {
return -1;
} else if (a > b) {
return 1;
} else {
return 0;
}
};
var descending = function descending(a, b) {
return -1 * ascending(a, b);
};
var extend = Object.assign != null ? Object.assign.bind(Object) : function (tgt) {
var args = arguments;
for (var i = 1; i < args.length; i++) {
var obj = args[i];
if (obj == null) {
continue;
}
var keys = Object.keys(obj);
for (var j = 0; j < keys.length; j++) {
var k = keys[j];
tgt[k] = obj[k];
}
}
return tgt;
};
var hex2tuple = function hex2tuple(hex) {
if (!(hex.length === 4 || hex.length === 7) || hex[0] !== '#') {
return;
}
var shortHex = hex.length === 4;
var r, g, b;
var base = 16;
if (shortHex) {
r = parseInt(hex[1] + hex[1], base);
g = parseInt(hex[2] + hex[2], base);
b = parseInt(hex[3] + hex[3], base);
} else {
r = parseInt(hex[1] + hex[2], base);
g = parseInt(hex[3] + hex[4], base);
b = parseInt(hex[5] + hex[6], base);
}
return [r, g, b];
}; // get [r, g, b, a] from hsl(0, 0, 0) or hsla(0, 0, 0, 0)
var hsl2tuple = function hsl2tuple(hsl) {
var ret;
var h, s, l, a, r, g, b;
function hue2rgb(p, q, t) {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1 / 6) return p + (q - p) * 6 * t;
if (t < 1 / 2) return q;
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
return p;
}
var m = new RegExp('^' + hsla + '$').exec(hsl);
if (m) {
// get hue
h = parseInt(m[1]);
if (h < 0) {
h = (360 - -1 * h % 360) % 360;
} else if (h > 360) {
h = h % 360;
}
h /= 360; // normalise on [0, 1]
s = parseFloat(m[2]);
if (s < 0 || s > 100) {
return;
} // saturation is [0, 100]
s = s / 100; // normalise on [0, 1]
l = parseFloat(m[3]);
if (l < 0 || l > 100) {
return;
} // lightness is [0, 100]
l = l / 100; // normalise on [0, 1]
a = m[4];
if (a !== undefined) {
a = parseFloat(a);
if (a < 0 || a > 1) {
return;
} // alpha is [0, 1]
} // now, convert to rgb
// code from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript
if (s === 0) {
r = g = b = Math.round(l * 255); // achromatic
} else {
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
var p = 2 * l - q;
r = Math.round(255 * hue2rgb(p, q, h + 1 / 3));
g = Math.round(255 * hue2rgb(p, q, h));
b = Math.round(255 * hue2rgb(p, q, h - 1 / 3));
}
ret = [r, g, b, a];
}
return ret;
}; // get [r, g, b, a] from rgb(0, 0, 0) or rgba(0, 0, 0, 0)
var rgb2tuple = function rgb2tuple(rgb) {
var ret;
var m = new RegExp('^' + rgba + '$').exec(rgb);
if (m) {
ret = [];
var isPct = [];
for (var i = 1; i <= 3; i++) {
var channel = m[i];
if (channel[channel.length - 1] === '%') {
isPct[i] = true;
}
channel = parseFloat(channel);
if (isPct[i]) {
channel = channel / 100 * 255; // normalise to [0, 255]
}
if (channel < 0 || channel > 255) {
return;
} // invalid channel value
ret.push(Math.floor(channel));
}
var atLeastOneIsPct = isPct[1] || isPct[2] || isPct[3];
var allArePct = isPct[1] && isPct[2] && isPct[3];
if (atLeastOneIsPct && !allArePct) {
return;
} // must all be percent values if one is
var alpha = m[4];
if (alpha !== undefined) {
alpha = parseFloat(alpha);
if (alpha < 0 || alpha > 1) {
return;
} // invalid alpha value
ret.push(alpha);
}
}
return ret;
};
var colorname2tuple = function colorname2tuple(color) {
return colors[color.toLowerCase()];
};
var color2tuple = function color2tuple(color) {
return (array(color) ? color : null) || colorname2tuple(color) || hex2tuple(color) || rgb2tuple(color) || hsl2tuple(color);
};
var colors = {
// special colour names
transparent: [0, 0, 0, 0],
// NB alpha === 0
// regular colours
aliceblue: [240, 248, 255],
antiquewhite: [250, 235, 215],
aqua: [0, 255, 255],
aquamarine: [127, 255, 212],
azure: [240, 255, 255],
beige: [245, 245, 220],
bisque: [255, 228, 196],
black: [0, 0, 0],
blanchedalmond: [255, 235, 205],
blue: [0, 0, 255],
blueviolet: [138, 43, 226],
brown: [165, 42, 42],
burlywood: [222, 184, 135],
cadetblue: [95, 158, 160],
chartreuse: [127, 255, 0],
chocolate: [210, 105, 30],
coral: [255, 127, 80],
cornflowerblue: [100, 149, 237],
cornsilk: [255, 248, 220],
crimson: [220, 20, 60],
cyan: [0, 255, 255],
darkblue: [0, 0, 139],
darkcyan: [0, 139, 139],
darkgoldenrod: [184, 134, 11],
darkgray: [169, 169, 169],
darkgreen: [0, 100, 0],
darkgrey: [169, 169, 169],
darkkhaki: [189, 183, 107],
darkmagenta: [139, 0, 139],
darkolivegreen: [85, 107, 47],
darkorange: [255, 140, 0],
darkorchid: [153, 50, 204],
darkred: [139, 0, 0],
darksalmon: [233, 150, 122],
darkseagreen: [143, 188, 143],
darkslateblue: [72, 61, 139],
darkslategray: [47, 79, 79],
darkslategrey: [47, 79, 79],
darkturquoise: [0, 206, 209],
darkviolet: [148, 0, 211],
deeppink: [255, 20, 147],
deepskyblue: [0, 191, 255],
dimgray: [105, 105, 105],
dimgrey: [105, 105, 105],
dodgerblue: [30, 144, 255],
firebrick: [178, 34, 34],
floralwhite: [255, 250, 240],
forestgreen: [34, 139, 34],
fuchsia: [255, 0, 255],
gainsboro: [220, 220, 220],
ghostwhite: [248, 248, 255],
gold: [255, 215, 0],
goldenrod: [218, 165, 32],
gray: [128, 128, 128],
grey: [128, 128, 128],
green: [0, 128, 0],
greenyellow: [173, 255, 47],
honeydew: [240, 255, 240],
hotpink: [255, 105, 180],
indianred: [205, 92, 92],
indigo: [75, 0, 130],
ivory: [255, 255, 240],
khaki: [240, 230, 140],
lavender: [230, 230, 250],
lavenderblush: [255, 240, 245],
lawngreen: [124, 252, 0],
lemonchiffon: [255, 250, 205],
lightblue: [173, 216, 230],
lightcoral: [240, 128, 128],
lightcyan: [224, 255, 255],
lightgoldenrodyellow: [250, 250, 210],
lightgray: [211, 211, 211],
lightgreen: [144, 238, 144],
lightgrey: [211, 211, 211],
lightpink: [255, 182, 193],
lightsalmon: [255, 160, 122],
lightseagreen: [32, 178, 170],
lightskyblue: [135, 206, 250],
lightslategray: [119, 136, 153],
lightslategrey: [119, 136, 153],
lightsteelblue: [176, 196, 222],
lightyellow: [255, 255, 224],
lime: [0, 255, 0],
limegreen: [50, 205, 50],
linen: [250, 240, 230],
magenta: [255, 0, 255],
maroon: [128, 0, 0],
mediumaquamarine: [102, 205, 170],
mediumblue: [0, 0, 205],
mediumorchid: [186, 85, 211],
mediumpurple: [147, 112, 219],
mediumseagreen: [60, 179, 113],
mediumslateblue: [123, 104, 238],
mediumspringgreen: [0, 250, 154],
mediumturquoise: [72, 209, 204],
mediumvioletred: [199, 21, 133],
midnightblue: [25, 25, 112],
mintcream: [245, 255, 250],
mistyrose: [255, 228, 225],
moccasin: [255, 228, 181],
navajowhite: [255, 222, 173],
navy: [0, 0, 128],
oldlace: [253, 245, 230],
olive: [128, 128, 0],
olivedrab: [107, 142, 35],
orange: [255, 165, 0],
orangered: [255, 69, 0],
orchid: [218, 112, 214],
palegoldenrod: [238, 232, 170],
palegreen: [152, 251, 152],
paleturquoise: [175, 238, 238],
palevioletred: [219, 112, 147],
papayawhip: [255, 239, 213],
peachpuff: [255, 218, 185],
peru: [205, 133, 63],
pink: [255, 192, 203],
plum: [221, 160, 221],
powderblue: [176, 224, 230],
purple: [128, 0, 128],
red: [255, 0, 0],
rosybrown: [188, 143, 143],
royalblue: [65, 105, 225],
saddlebrown: [139, 69, 19],
salmon: [250, 128, 114],
sandybrown: [244, 164, 96],
seagreen: [46, 139, 87],
seashell: [255, 245, 238],
sienna: [160, 82, 45],
silver: [192, 192, 192],
skyblue: [135, 206, 235],
slateblue: [106, 90, 205],
slategray: [112, 128, 144],
slategrey: [112, 128, 144],
snow: [255, 250, 250],
springgreen: [0, 255, 127],
steelblue: [70, 130, 180],
tan: [210, 180, 140],
teal: [0, 128, 128],
thistle: [216, 191, 216],
tomato: [255, 99, 71],
turquoise: [64, 224, 208],
violet: [238, 130, 238],
wheat: [245, 222, 179],
white: [255, 255, 255],
whitesmoke: [245, 245, 245],
yellow: [255, 255, 0],
yellowgreen: [154, 205, 50]
};
var setMap = function setMap(options) {
var obj = options.map;
var keys = options.keys;
var l = keys.length;
for (var i = 0; i < l; i++) {
var key = keys[i];
if (plainObject(key)) {
throw Error('Tried to set map with object key');
}
if (i < keys.length - 1) {
// extend the map if necessary
if (obj[key] == null) {
obj[key] = {};
}
obj = obj[key];
} else {
// set the value
obj[key] = options.value;
}
}
}; // gets the value in a map even if it's not built in places
var getMap = function getMap(options) {
var obj = options.map;
var keys = options.keys;
var l = keys.length;
for (var i = 0; i < l; i++) {
var key = keys[i];
if (plainObject(key)) {
throw Error('Tried to get map with object key');
}
obj = obj[key];
if (obj == null) {
return obj;
}
}
return obj;
}; // deletes the entry in the map
/**
* Checks if `value` is the
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/
function isObject(value) {
var type = typeof value;
return value != null && (type == 'object' || type == 'function');
}
var isObject_1 = isObject;
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
/** Detect free variable `global` from Node.js. */
var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
var _freeGlobal = freeGlobal;
/** Detect free variable `self`. */
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
/** Used as a reference to the global object. */
var root = _freeGlobal || freeSelf || Function('return this')();
var _root = root;
/**
* Gets the timestamp of the number of milliseconds that have elapsed since
* the Unix epoch (1 January 1970 00:00:00 UTC).
*
* @static
* @memberOf _
* @since 2.4.0
* @category Date
* @returns {number} Returns the timestamp.
* @example
*
* _.defer(function(stamp) {
* console.log(_.now() - stamp);
* }, _.now());
* // => Logs the number of milliseconds it took for the deferred invocation.
*/
var now = function() {
return _root.Date.now();
};
var now_1 = now;
/** Used to match a single whitespace character. */
var reWhitespace = /\s/;
/**
* Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
* character of `string`.
*
* @private
* @param {string} string The string to inspect.
* @returns {number} Returns the index of the last non-whitespace character.
*/
function trimmedEndIndex(string) {
var index = string.length;
while (index-- && reWhitespace.test(string.charAt(index))) {}
return index;
}
var _trimmedEndIndex = trimmedEndIndex;
/** Used to match leading whitespace. */
var reTrimStart = /^\s+/;
/**
* The base implementation of `_.trim`.
*
* @private
* @param {string} string The string to trim.
* @returns {string} Returns the trimmed string.
*/
function baseTrim(string) {
return string
? string.slice(0, _trimmedEndIndex(string) + 1).replace(reTrimStart, '')
: string;
}
var _baseTrim = baseTrim;
/** Built-in value references. */
var Symbol$1 = _root.Symbol;
var _Symbol = Symbol$1;
/** Used for built-in method references. */
var objectProto$5 = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty$4 = objectProto$5.hasOwnProperty;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString$1 = objectProto$5.toString;
/** Built-in value references. */
var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined;
/**
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the raw `toStringTag`.
*/
function getRawTag(value) {
var isOwn = hasOwnProperty$4.call(value, symToStringTag$1),
tag = value[symToStringTag$1];
try {
value[symToStringTag$1] = undefined;
var unmasked = true;
} catch (e) {}
var result = nativeObjectToString$1.call(value);
if (unmasked) {
if (isOwn) {
value[symToStringTag$1] = tag;
} else {
delete value[symToStringTag$1];
}
}
return result;
}
var _getRawTag = getRawTag;
/** Used for built-in method references. */
var objectProto$4 = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString = objectProto$4.toString;
/**
* Converts `value` to a string using `Object.prototype.toString`.
*
* @private
* @param {*} value The value to convert.
* @returns {string} Returns the converted string.
*/
function objectToString(value) {
return nativeObjectToString.call(value);
}
var _objectToString = objectToString;
/** `Object#toString` result references. */
var nullTag = '[object Null]',
undefinedTag = '[object Undefined]';
/** Built-in value references. */
var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
/**
* The base implementation of `getTag` without fallbacks for buggy environments.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
function baseGetTag(value) {
if (value == null) {
return value === undefined ? undefinedTag : nullTag;
}
return (symToStringTag && symToStringTag in Object(value))
? _getRawTag(value)
: _objectToString(value);
}
var _baseGetTag = baseGetTag;
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return value != null && typeof value == 'object';
}
var isObjectLike_1 = isObjectLike;
/** `Object#toString` result references. */
var symbolTag = '[object Symbol]';
/**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
* @example
*
* _.isSymbol(Symbol.iterator);
* // => true
*
* _.isSymbol('abc');
* // => false
*/
function isSymbol(value) {
return typeof value == 'symbol' ||
(isObjectLike_1(value) && _baseGetTag(value) == symbolTag);
}
var isSymbol_1 = isSymbol;
/** Used as references for various `Number` constants. */
var NAN = 0 / 0;
/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;
/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;
/** Built-in method references without a dependency on `root`. */
var freeParseInt = parseInt;
/**
* Converts `value` to a number.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to process.
* @returns {number} Returns the number.
* @example
*
* _.toNumber(3.2);
* // => 3.2
*
* _.toNumber(Number.MIN_VALUE);
* // => 5e-324
*
* _.toNumber(Infinity);
* // => Infinity
*
* _.toNumber('3.2');
* // => 3.2
*/
function toNumber(value) {
if (typeof value == 'number') {
return value;
}
if (isSymbol_1(value)) {
return NAN;
}
if (isObject_1(value)) {
var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
value = isObject_1(other) ? (other + '') : other;
}
if (typeof value != 'string') {
return value === 0 ? value : +value;
}
value = _baseTrim(value);
var isBinary = reIsBinary.test(value);
return (isBinary || reIsOctal.test(value))
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
: (reIsBadHex.test(value) ? NAN : +value);
}
var toNumber_1 = toNumber;
/** Error message constants. */
var FUNC_ERROR_TEXT$1 = 'Expected a function';
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max,
nativeMin = Math.min;
/**
* Creates a debounced function that delays invoking `func` until after `wait`
* milliseconds have elapsed since the last time the debounced function was
* invoked. The debounced function comes with a `cancel` method to cancel
* delayed `func` invocations and a `flush` method to immediately invoke them.
* Provide `options` to indicate whether `func` should be invoked on the
* leading and/or trailing edge of the `wait` timeout. The `func` is invoked
* with the last arguments provided to the debounced function. Subsequent
* calls to the debounced function return the result of the last `func`
* invocation.
*
* **Note:** If `leading` and `trailing` options are `true`, `func` is
* invoked on the trailing edge of the timeout only if the debounced function
* is invoked more than once during the `wait` timeout.
*
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
* until to the next tick, similar to `setTimeout` with a timeout of `0`.
*
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
* for details over the differences between `_.debounce` and `_.throttle`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Function
* @param {Function} func The function to debounce.
* @param {number} [wait=0] The number of milliseconds to delay.
* @param {Object} [options={}] The options object.
* @param {boolean} [options.leading=false]
* Specify invoking on the leading edge of the timeout.
* @param {number} [options.maxWait]
* The maximum time `func` is allowed to be delayed before it's invoked.
* @param {boolean} [options.trailing=true]
* Specify invoking on the trailing edge of the timeout.
* @returns {Function} Returns the new debounced function.
* @example
*
* // Avoid costly calculations while the window size is in flux.
* jQuery(window).on('resize', _.debounce(calculateLayout, 150));
*
* // Invoke `sendMail` when clicked, debouncing subsequent calls.
* jQuery(element).on('click', _.debounce(sendMail, 300, {
* 'leading': true,
* 'trailing': false
* }));
*
* // Ensure `batchLog` is invoked once after 1 second of debounced calls.
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
* var source = new EventSource('/stream');
* jQuery(source).on('message', debounced);
*
* // Cancel the trailing debounced invocation.
* jQuery(window).on('popstate', debounced.cancel);
*/
function debounce(func, wait, options) {
var lastArgs,
lastThis,
maxWait,
result,
timerId,
lastCallTime,
lastInvokeTime = 0,
leading = false,
maxing = false,
trailing = true;
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT$1);
}
wait = toNumber_1(wait) || 0;
if (isObject_1(options)) {
leading = !!options.leading;
maxing = 'maxWait' in options;
maxWait = maxing ? nativeMax(toNumber_1(options.maxWait) || 0, wait) : maxWait;
trailing = 'trailing' in options ? !!options.trailing : trailing;
}
function invokeFunc(time) {
var args = lastArgs,
thisArg = lastThis;
lastArgs = lastThis = undefined;
lastInvokeTime = time;
result = func.apply(thisArg, args);
return result;
}
function leadingEdge(time) {
// Reset any `maxWait` timer.
lastInvokeTime = time;
// Start the timer for the trailing edge.
timerId = setTimeout(timerExpired, wait);
// Invoke the leading edge.
return leading ? invokeFunc(time) : result;
}
function remainingWait(time) {
var timeSinceLastCall = time - lastCallTime,
timeSinceLastInvoke = time - lastInvokeTime,
timeWaiting = wait - timeSinceLastCall;
return maxing
? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
: timeWaiting;
}
function shouldInvoke(time) {
var timeSinceLastCall = time - lastCallTime,
timeSinceLastInvoke = time - lastInvokeTime;
// Either this is the first call, activity has stopped and we're at the
// trailing edge, the system time has gone backwards and we're treating
// it as the trailing edge, or we've hit the `maxWait` limit.
return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
(timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
}
function timerExpired() {
var time = now_1();
if (shouldInvoke(time)) {
return trailingEdge(time);
}
// Restart the timer.
timerId = setTimeout(timerExpired, remainingWait(time));
}
function trailingEdge(time) {
timerId = undefined;
// Only invoke if we have `lastArgs` which means `func` has been
// debounced at least once.
if (trailing && lastArgs) {
return invokeFunc(time);
}
lastArgs = lastThis = undefined;
return result;
}
function cancel() {
if (timerId !== undefined) {
clearTimeout(timerId);
}
lastInvokeTime = 0;
lastArgs = lastCallTime = lastThis = timerId = undefined;
}
function flush() {
return timerId === undefined ? result : trailingEdge(now_1());
}
function debounced() {
var time = now_1(),
isInvoking = shouldInvoke(time);
lastArgs = arguments;
lastThis = this;
lastCallTime = time;
if (isInvoking) {
if (timerId === undefined) {
return leadingEdge(lastCallTime);
}
if (maxing) {
// Handle invocations in a tight loop.
clearTimeout(timerId);
timerId = setTimeout(timerExpired, wait);
return invokeFunc(lastCallTime);
}
}
if (timerId === undefined) {
timerId = setTimeout(timerExpired, wait);
}
return result;
}
debounced.cancel = cancel;
debounced.flush = flush;
return debounced;
}
var debounce_1 = debounce;
var performance = window$1 ? window$1.performance : null;
var pnow = performance && performance.now ? function () {
return performance.now();
} : function () {
return Date.now();
};
var raf = function () {
if (window$1) {
if (window$1.requestAnimationFrame) {
return function (fn) {
window$1.requestAnimationFrame(fn);
};
} else if (window$1.mozRequestAnimationFrame) {
return function (fn) {
window$1.mozRequestAnimationFrame(fn);
};
} else if (window$1.webkitRequestAnimationFrame) {
return function (fn) {
window$1.webkitRequestAnimationFrame(fn);
};
} else if (window$1.msRequestAnimationFrame) {
return function (fn) {
window$1.msRequestAnimationFrame(fn);
};
}
}
return function (fn) {
if (fn) {
setTimeout(function () {
fn(pnow());
}, 1000 / 60);
}
};
}();
var requestAnimationFrame = function requestAnimationFrame(fn) {
return raf(fn);
};
var performanceNow = pnow;
var DEFAULT_HASH_SEED = 9261;
var K = 65599; // 37 also works pretty well
var DEFAULT_HASH_SEED_ALT = 5381;
var hashIterableInts = function hashIterableInts(iterator) {
var seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_HASH_SEED;
// sdbm/string-hash
var hash = seed;
var entry;
for (;;) {
entry = iterator.next();
if (entry.done) {
break;
}
hash = hash * K + entry.value | 0;
}
return hash;
};
var hashInt = function hashInt(num) {
var seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_HASH_SEED;
// sdbm/string-hash
return seed * K + num | 0;
};
var hashIntAlt = function hashIntAlt(num) {
var seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_HASH_SEED_ALT;
// djb2/string-hash
return (seed << 5) + seed + num | 0;
};
var combineHashes = function combineHashes(hash1, hash2) {
return hash1 * 0x200000 + hash2;
};
var combineHashesArray = function combineHashesArray(hashes) {
return hashes[0] * 0x200000 + hashes[1];
};
var hashArrays = function hashArrays(hashes1, hashes2) {
return [hashInt(hashes1[0], hashes2[0]), hashIntAlt(hashes1[1], hashes2[1])];
};
var hashIntsArray = function hashIntsArray(ints, seed) {
var entry = {
value: 0,
done: false
};
var i = 0;
var length = ints.length;
var iterator = {
next: function next() {
if (i < length) {
entry.value = ints[i++];
} else {
entry.done = true;
}
return entry;
}
};
return hashIterableInts(iterator, seed);
};
var hashString = function hashString(str, seed) {
var entry = {
value: 0,
done: false
};
var i = 0;
var length = str.length;
var iterator = {
next: function next() {
if (i < length) {
entry.value = str.charCodeAt(i++);
} else {
entry.done = true;
}
return entry;
}
};
return hashIterableInts(iterator, seed);
};
var hashStrings = function hashStrings() {
return hashStringsArray(arguments);
};
var hashStringsArray = function hashStringsArray(strs) {
var hash;
for (var i = 0; i < strs.length; i++) {
var str = strs[i];
if (i === 0) {
hash = hashString(str);
} else {
hash = hashString(str, hash);
}
}
return hash;
};
/*global console */
var warningsEnabled = true;
var warnSupported = console.warn != null; // eslint-disable-line no-console
var traceSupported = console.trace != null; // eslint-disable-line no-console
var MAX_INT$1 = Number.MAX_SAFE_INTEGER || 9007199254740991;
var trueify = function trueify() {
return true;
};
var falsify = function falsify() {
return false;
};
var zeroify = function zeroify() {
return 0;
};
var noop$1 = function noop() {};
var error = function error(msg) {
throw new Error(msg);
};
var warnings = function warnings(enabled) {
if (enabled !== undefined) {
warningsEnabled = !!enabled;
} else {
return warningsEnabled;
}
};
var warn = function warn(msg) {
/* eslint-disable no-console */
if (!warnings()) {
return;
}
if (warnSupported) {
console.warn(msg);
} else {
console.log(msg);
if (traceSupported) {
console.trace();
}
}
};
/* eslint-enable */
var clone = function clone(obj) {
return extend({}, obj);
}; // gets a shallow copy of the argument
var copy = function copy(obj) {
if (obj == null) {
return obj;
}
if (array(obj)) {
return obj.slice();
} else if (plainObject(obj)) {
return clone(obj);
} else {
return obj;
}
};
var copyArray$1 = function copyArray(arr) {
return arr.slice();
};
var uuid = function uuid(a, b
/* placeholders */
) {
for ( // loop :)
b = a = ''; // b - result , a - numeric letiable
a++ < 36; //
b += a * 51 & 52 // if "a" is not 9 or 14 or 19 or 24
? // return a random number or 4
(a ^ 15 // if "a" is not 15
? // generate a random number from 0 to 15
8 ^ Math.random() * (a ^ 20 ? 16 : 4) // unless "a" is 20, in which case a random number from 8 to 11
: 4 // otherwise 4
).toString(16) : '-' // in other cases (if "a" is 9,14,19,24) insert "-"
) {
}
return b;
};
var _staticEmptyObject = {};
var staticEmptyObject = function staticEmptyObject() {
return _staticEmptyObject;
};
var defaults$g = function defaults(_defaults) {
var keys = Object.keys(_defaults);
return function (opts) {
var filledOpts = {};
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var optVal = opts == null ? undefined : opts[key];
filledOpts[key] = optVal === undefined ? _defaults[key] : optVal;
}
return filledOpts;
};
};
var removeFromArray = function removeFromArray(arr, ele, oneCopy) {
for (var i = arr.length - 1; i >= 0; i--) {
if (arr[i] === ele) {
arr.splice(i, 1);
if (oneCopy) {
break;
}
}
}
};
var clearArray = function clearArray(arr) {
arr.splice(0, arr.length);
};
var push = function push(arr, otherArr) {
for (var i = 0; i < otherArr.length; i++) {
var el = otherArr[i];
arr.push(el);
}
};
var getPrefixedProperty = function getPrefixedProperty(obj, propName, prefix) {
if (prefix) {
propName = prependCamel(prefix, propName); // e.g. (labelWidth, source) => sourceLabelWidth
}
return obj[propName];
};
var setPrefixedProperty = function setPrefixedProperty(obj, propName, prefix, value) {
if (prefix) {
propName = prependCamel(prefix, propName); // e.g. (labelWidth, source) => sourceLabelWidth
}
obj[propName] = value;
};
/* global Map */
var ObjectMap = /*#__PURE__*/function () {
function ObjectMap() {
_classCallCheck(this, ObjectMap);
this._obj = {};
}
_createClass(ObjectMap, [{
key: "set",
value: function set(key, val) {
this._obj[key] = val;
return this;
}
}, {
key: "delete",
value: function _delete(key) {
this._obj[key] = undefined;
return this;
}
}, {
key: "clear",
value: function clear() {
this._obj = {};
}
}, {
key: "has",
value: function has(key) {
return this._obj[key] !== undefined;
}
}, {
key: "get",
value: function get(key) {
return this._obj[key];
}
}]);
return ObjectMap;
}();
var Map$2 = typeof Map !== 'undefined' ? Map : ObjectMap;
/* global Set */
var undef = "undefined" ;
var ObjectSet = /*#__PURE__*/function () {
function ObjectSet(arrayOrObjectSet) {
_classCallCheck(this, ObjectSet);
this._obj = Object.create(null);
this.size = 0;
if (arrayOrObjectSet != null) {
var arr;
if (arrayOrObjectSet.instanceString != null && arrayOrObjectSet.instanceString() === this.instanceString()) {
arr = arrayOrObjectSet.toArray();
} else {
arr = arrayOrObjectSet;
}
for (var i = 0; i < arr.length; i++) {
this.add(arr[i]);
}
}
}
_createClass(ObjectSet, [{
key: "instanceString",
value: function instanceString() {
return 'set';
}
}, {
key: "add",
value: function add(val) {
var o = this._obj;
if (o[val] !== 1) {
o[val] = 1;
this.size++;
}
}
}, {
key: "delete",
value: function _delete(val) {
var o = this._obj;
if (o[val] === 1) {
o[val] = 0;
this.size--;
}
}
}, {
key: "clear",
value: function clear() {
this._obj = Object.create(null);
}
}, {
key: "has",
value: function has(val) {
return this._obj[val] === 1;
}
}, {
key: "toArray",
value: function toArray() {
var _this = this;
return Object.keys(this._obj).filter(function (key) {
return _this.has(key);
});
}
}, {
key: "forEach",
value: function forEach(callback, thisArg) {
return this.toArray().forEach(callback, thisArg);
}
}]);
return ObjectSet;
}();
var Set$1 = (typeof Set === "undefined" ? "undefined" : _typeof(Set)) !== undef ? Set : ObjectSet;
var Element = function Element(cy, params) {
var restore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
if (cy === undefined || params === undefined || !core(cy)) {
error('An element must have a core reference and parameters set');
return;
}
var group = params.group; // try to automatically infer the group if unspecified
if (group == null) {
if (params.data && params.data.source != null && params.data.target != null) {
group = 'edges';
} else {
group = 'nodes';
}
} // validate group
if (group !== 'nodes' && group !== 'edges') {
error('An element must be of type `nodes` or `edges`; you specified `' + group + '`');
return;
} // make the element array-like, just like a collection
this.length = 1;
this[0] = this; // NOTE: when something is added here, add also to ele.json()
var _p = this._private = {
cy: cy,
single: true,
// indicates this is an element
data: params.data || {},
// data object
position: params.position || {
x: 0,
y: 0
},
// (x, y) position pair
autoWidth: undefined,
// width and height of nodes calculated by the renderer when set to special 'auto' value
autoHeight: undefined,
autoPadding: undefined,
compoundBoundsClean: false,
// whether the compound dimensions need to be recalculated the next time dimensions are read
listeners: [],
// array of bound listeners
group: group,
// string; 'nodes' or 'edges'
style: {},
// properties as set by the style
rstyle: {},
// properties for style sent from the renderer to the core
styleCxts: [],
// applied style contexts from the styler
styleKeys: {},
// per-group keys of style property values
removed: true,
// whether it's inside the vis; true if removed (set true here since we call restore)
selected: params.selected ? true : false,
// whether it's selected
selectable: params.selectable === undefined ? true : params.selectable ? true : false,
// whether it's selectable
locked: params.locked ? true : false,
// whether the element is locked (cannot be moved)
grabbed: false,
// whether the element is grabbed by the mouse; renderer sets this privately
grabbable: params.grabbable === undefined ? true : params.grabbable ? true : false,
// whether the element can be grabbed
pannable: params.pannable === undefined ? group === 'edges' ? true : false : params.pannable ? true : false,
// whether the element has passthrough panning enabled
active: false,
// whether the element is active from user interaction
classes: new Set$1(),
// map ( className => true )
animation: {
// object for currently-running animations
current: [],
queue: []
},
rscratch: {},
// object in which the renderer can store information
scratch: params.scratch || {},
// scratch objects
edges: [],
// array of connected edges
children: [],
// array of children
parent: params.parent && params.parent.isNode() ? params.parent : null,
// parent ref
traversalCache: {},
// cache of output of traversal functions
backgrounding: false,
// whether background images are loading
bbCache: null,
// cache of the current bounding box
bbCacheShift: {
x: 0,
y: 0
},
// shift applied to cached bb to be applied on next get
bodyBounds: null,
// bounds cache of element body, w/o overlay
overlayBounds: null,
// bounds cache of element body, including overlay
labelBounds: {
// bounds cache of labels
all: null,
source: null,
target: null,
main: null
},
arrowBounds: {
// bounds cache of edge arrows
source: null,
target: null,
'mid-source': null,
'mid-target': null
}
};
if (_p.position.x == null) {
_p.position.x = 0;
}
if (_p.position.y == null) {
_p.position.y = 0;
} // renderedPosition overrides if specified
if (params.renderedPosition) {
var rpos = params.renderedPosition;
var pan = cy.pan();
var zoom = cy.zoom();
_p.position = {
x: (rpos.x - pan.x) / zoom,
y: (rpos.y - pan.y) / zoom
};
}
var classes = [];
if (array(params.classes)) {
classes = params.classes;
} else if (string(params.classes)) {
classes = params.classes.split(/\s+/);
}
for (var i = 0, l = classes.length; i < l; i++) {
var cls = classes[i];
if (!cls || cls === '') {
continue;
}
_p.classes.add(cls);
}
this.createEmitter();
var bypass = params.style || params.css;
if (bypass) {
warn('Setting a `style` bypass at element creation should be done only when absolutely necessary. Try to use the stylesheet instead.');
this.style(bypass);
}
if (restore === undefined || restore) {
this.restore();
}
};
var defineSearch = function defineSearch(params) {
params = {
bfs: params.bfs || !params.dfs,
dfs: params.dfs || !params.bfs
}; // from pseudocode on wikipedia
return function searchF