UNPKG

cytoscape

Version:

Graph theory (a.k.a. network) library for analysis and visualisation

1,795 lines (1,662 loc) 1.06 MB
/** * Copyright (c) 2016-2025, 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. */ 'use strict'; function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", { writable: false }), e; } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var n = 0, F = function () {}; return { s: F, n: function () { return n >= r.length ? { done: true } : { done: false, value: r[n++] }; }, e: function (r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function () { t = t.call(r); }, n: function () { var r = t.next(); return a = r.done, r; }, e: function (r) { u = true, o = r; }, f: function () { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; } function _defineProperty$1(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = true, o = false; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = true, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } 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."); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (undefined !== e) { var i = e.call(t, r); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return (String )(t); } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : undefined; } } var _window = typeof window === 'undefined' ? null : window; // eslint-disable-line no-undef var navigator = _window ? _window.navigator : null; _window ? _window.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 = 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(function (str) { return str.replace(/([A-Z])/g, function (v) { return '-' + v.toLowerCase(); }); }); var dash2camel = memoize(function (str) { return str.replace(/(-\w)/g, function (v) { return v[1].toUpperCase(); }); }); var prependCamel = memoize(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; }; // get [r, g, b] from #abc or #aabbcc 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] }; // sets the value in a map (map may not be built) 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; }; 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; } /** * 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 */ var isObject_1; var hasRequiredIsObject; function requireIsObject () { if (hasRequiredIsObject) return isObject_1; hasRequiredIsObject = 1; function isObject(value) { var type = typeof value; return value != null && (type == 'object' || type == 'function'); } isObject_1 = isObject; return isObject_1; } /** Detect free variable `global` from Node.js. */ var _freeGlobal; var hasRequired_freeGlobal; function require_freeGlobal () { if (hasRequired_freeGlobal) return _freeGlobal; hasRequired_freeGlobal = 1; var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; _freeGlobal = freeGlobal; return _freeGlobal; } var _root; var hasRequired_root; function require_root () { if (hasRequired_root) return _root; hasRequired_root = 1; var freeGlobal = require_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')(); _root = root; return _root; } var now_1; var hasRequiredNow; function requireNow () { if (hasRequiredNow) return now_1; hasRequiredNow = 1; var root = require_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(); }; now_1 = now; return now_1; } /** Used to match a single whitespace character. */ var _trimmedEndIndex; var hasRequired_trimmedEndIndex; function require_trimmedEndIndex () { if (hasRequired_trimmedEndIndex) return _trimmedEndIndex; hasRequired_trimmedEndIndex = 1; 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; } _trimmedEndIndex = trimmedEndIndex; return _trimmedEndIndex; } var _baseTrim; var hasRequired_baseTrim; function require_baseTrim () { if (hasRequired_baseTrim) return _baseTrim; hasRequired_baseTrim = 1; var trimmedEndIndex = require_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; } _baseTrim = baseTrim; return _baseTrim; } var _Symbol; var hasRequired_Symbol; function require_Symbol () { if (hasRequired_Symbol) return _Symbol; hasRequired_Symbol = 1; var root = require_root(); /** Built-in value references. */ var Symbol = root.Symbol; _Symbol = Symbol; return _Symbol; } var _getRawTag; var hasRequired_getRawTag; function require_getRawTag () { if (hasRequired_getRawTag) return _getRawTag; hasRequired_getRawTag = 1; var Symbol = require_Symbol(); /** Used for built-in method references. */ var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString = objectProto.toString; /** Built-in value references. */ var symToStringTag = 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.call(value, symToStringTag), tag = value[symToStringTag]; try { value[symToStringTag] = undefined; var unmasked = true; } catch (e) {} var result = nativeObjectToString.call(value); if (unmasked) { if (isOwn) { value[symToStringTag] = tag; } else { delete value[symToStringTag]; } } return result; } _getRawTag = getRawTag; return _getRawTag; } /** Used for built-in method references. */ var _objectToString; var hasRequired_objectToString; function require_objectToString () { if (hasRequired_objectToString) return _objectToString; hasRequired_objectToString = 1; var objectProto = Object.prototype; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ var nativeObjectToString = objectProto.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); } _objectToString = objectToString; return _objectToString; } var _baseGetTag; var hasRequired_baseGetTag; function require_baseGetTag () { if (hasRequired_baseGetTag) return _baseGetTag; hasRequired_baseGetTag = 1; var Symbol = require_Symbol(), getRawTag = require_getRawTag(), objectToString = require_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); } _baseGetTag = baseGetTag; return _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 */ var isObjectLike_1; var hasRequiredIsObjectLike; function requireIsObjectLike () { if (hasRequiredIsObjectLike) return isObjectLike_1; hasRequiredIsObjectLike = 1; function isObjectLike(value) { return value != null && typeof value == 'object'; } isObjectLike_1 = isObjectLike; return isObjectLike_1; } var isSymbol_1; var hasRequiredIsSymbol; function requireIsSymbol () { if (hasRequiredIsSymbol) return isSymbol_1; hasRequiredIsSymbol = 1; var baseGetTag = require_baseGetTag(), isObjectLike = requireIsObjectLike(); /** `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(value) && baseGetTag(value) == symbolTag); } isSymbol_1 = isSymbol; return isSymbol_1; } var toNumber_1; var hasRequiredToNumber; function requireToNumber () { if (hasRequiredToNumber) return toNumber_1; hasRequiredToNumber = 1; var baseTrim = require_baseTrim(), isObject = requireIsObject(), isSymbol = requireIsSymbol(); /** 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(value)) { return NAN; } if (isObject(value)) { var other = typeof value.valueOf == 'function' ? value.valueOf() : value; value = isObject(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); } toNumber_1 = toNumber; return toNumber_1; } var debounce_1; var hasRequiredDebounce; function requireDebounce () { if (hasRequiredDebounce) return debounce_1; hasRequiredDebounce = 1; var isObject = requireIsObject(), now = requireNow(), toNumber = requireToNumber(); /** Error message constants. */ var FUNC_ERROR_TEXT = '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); } wait = toNumber(wait) || 0; if (isObject(options)) { leading = !!options.leading; maxing = 'maxWait' in options; maxWait = maxing ? nativeMax(toNumber(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(); 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()); } function debounced() { var time = now(), 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; } debounce_1 = debounce; return debounce_1; } var debounceExports = requireDebounce(); var debounce = /*@__PURE__*/getDefaultExportFromCjs(debounceExports); var performance$1 = _window ? _window.performance : null; var pnow = performance$1 && performance$1.now ? function () { return performance$1.now(); } : function () { return Date.now(); }; var raf = function () { if (_window) { if (_window.requestAnimationFrame) { return function (fn) { _window.requestAnimationFrame(fn); }; } else if (_window.mozRequestAnimationFrame) { return function (fn) { _window.mozRequestAnimationFrame(fn); }; } else if (_window.webkitRequestAnimationFrame) { return function (fn) { _window.webkitRequestAnimationFrame(fn); }; } else if (_window.msRequestAnimationFrame) { return function (fn) { _window.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; }; var warningsEnabled = true; var warnSupported = console.warn != null; var traceSupported = console.trace != null; 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) { if (!warnings()) { return; } if (warnSupported) { console.warn(msg); } else { console.log(msg); if (traceSupported) { console.trace(); } } }; 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 = 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); } } }; 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 = {}; } return _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]; } }]); }(); var Map$1 = 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]); } } } return _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); } }]); }(); var Set$1 = (typeof Set === "undefined" ? "undefined" : _typeof(Set)) !== undef ? Set : ObjectSet; // represents a node or an edge 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, incl