UNPKG

1.15 MBJavaScriptView Raw
1import { d as sanitizeText$1, c as getConfig, l as log, j as select, t as setupGraphViewbox, aA as isDark, aB as lighten, aC as darken } from "./mermaid-4b4b971d.js";
2import { c as createText } from "./createText-b06b2794.js";
3import { c as commonjsGlobal, g as getDefaultExportFromCjs } from "./_commonjsHelpers-7a77ea84.js";
4var parser = function() {
5 var o = function(k, v, o2, l) {
6 for (o2 = o2 || {}, l = k.length; l--; o2[k[l]] = v)
7 ;
8 return o2;
9 }, $V0 = [1, 4], $V1 = [1, 13], $V2 = [1, 12], $V3 = [1, 15], $V4 = [1, 16], $V5 = [1, 20], $V6 = [1, 19], $V7 = [6, 7, 8], $V8 = [1, 26], $V9 = [1, 24], $Va = [1, 25], $Vb = [6, 7, 11], $Vc = [1, 6, 13, 15, 16, 19, 22], $Vd = [1, 33], $Ve = [1, 34], $Vf = [1, 6, 7, 11, 13, 15, 16, 19, 22];
10 var parser2 = {
11 trace: function trace() {
12 },
13 yy: {},
14 symbols_: { "error": 2, "start": 3, "mindMap": 4, "spaceLines": 5, "SPACELINE": 6, "NL": 7, "MINDMAP": 8, "document": 9, "stop": 10, "EOF": 11, "statement": 12, "SPACELIST": 13, "node": 14, "ICON": 15, "CLASS": 16, "nodeWithId": 17, "nodeWithoutId": 18, "NODE_DSTART": 19, "NODE_DESCR": 20, "NODE_DEND": 21, "NODE_ID": 22, "$accept": 0, "$end": 1 },
15 terminals_: { 2: "error", 6: "SPACELINE", 7: "NL", 8: "MINDMAP", 11: "EOF", 13: "SPACELIST", 15: "ICON", 16: "CLASS", 19: "NODE_DSTART", 20: "NODE_DESCR", 21: "NODE_DEND", 22: "NODE_ID" },
16 productions_: [0, [3, 1], [3, 2], [5, 1], [5, 2], [5, 2], [4, 2], [4, 3], [10, 1], [10, 1], [10, 1], [10, 2], [10, 2], [9, 3], [9, 2], [12, 2], [12, 2], [12, 2], [12, 1], [12, 1], [12, 1], [12, 1], [12, 1], [14, 1], [14, 1], [18, 3], [17, 1], [17, 4]],
17 performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$) {
18 var $0 = $$.length - 1;
19 switch (yystate) {
20 case 6:
21 case 7:
22 return yy;
23 case 8:
24 yy.getLogger().trace("Stop NL ");
25 break;
26 case 9:
27 yy.getLogger().trace("Stop EOF ");
28 break;
29 case 11:
30 yy.getLogger().trace("Stop NL2 ");
31 break;
32 case 12:
33 yy.getLogger().trace("Stop EOF2 ");
34 break;
35 case 15:
36 yy.getLogger().info("Node: ", $$[$0].id);
37 yy.addNode($$[$0 - 1].length, $$[$0].id, $$[$0].descr, $$[$0].type);
38 break;
39 case 16:
40 yy.getLogger().trace("Icon: ", $$[$0]);
41 yy.decorateNode({ icon: $$[$0] });
42 break;
43 case 17:
44 case 21:
45 yy.decorateNode({ class: $$[$0] });
46 break;
47 case 18:
48 yy.getLogger().trace("SPACELIST");
49 break;
50 case 19:
51 yy.getLogger().trace("Node: ", $$[$0].id);
52 yy.addNode(0, $$[$0].id, $$[$0].descr, $$[$0].type);
53 break;
54 case 20:
55 yy.decorateNode({ icon: $$[$0] });
56 break;
57 case 25:
58 yy.getLogger().trace("node found ..", $$[$0 - 2]);
59 this.$ = { id: $$[$0 - 1], descr: $$[$0 - 1], type: yy.getType($$[$0 - 2], $$[$0]) };
60 break;
61 case 26:
62 this.$ = { id: $$[$0], descr: $$[$0], type: yy.nodeType.DEFAULT };
63 break;
64 case 27:
65 yy.getLogger().trace("node found ..", $$[$0 - 3]);
66 this.$ = { id: $$[$0 - 3], descr: $$[$0 - 1], type: yy.getType($$[$0 - 2], $$[$0]) };
67 break;
68 }
69 },
70 table: [{ 3: 1, 4: 2, 5: 3, 6: [1, 5], 8: $V0 }, { 1: [3] }, { 1: [2, 1] }, { 4: 6, 6: [1, 7], 7: [1, 8], 8: $V0 }, { 6: $V1, 7: [1, 10], 9: 9, 12: 11, 13: $V2, 14: 14, 15: $V3, 16: $V4, 17: 17, 18: 18, 19: $V5, 22: $V6 }, o($V7, [2, 3]), { 1: [2, 2] }, o($V7, [2, 4]), o($V7, [2, 5]), { 1: [2, 6], 6: $V1, 12: 21, 13: $V2, 14: 14, 15: $V3, 16: $V4, 17: 17, 18: 18, 19: $V5, 22: $V6 }, { 6: $V1, 9: 22, 12: 11, 13: $V2, 14: 14, 15: $V3, 16: $V4, 17: 17, 18: 18, 19: $V5, 22: $V6 }, { 6: $V8, 7: $V9, 10: 23, 11: $Va }, o($Vb, [2, 22], { 17: 17, 18: 18, 14: 27, 15: [1, 28], 16: [1, 29], 19: $V5, 22: $V6 }), o($Vb, [2, 18]), o($Vb, [2, 19]), o($Vb, [2, 20]), o($Vb, [2, 21]), o($Vb, [2, 23]), o($Vb, [2, 24]), o($Vb, [2, 26], { 19: [1, 30] }), { 20: [1, 31] }, { 6: $V8, 7: $V9, 10: 32, 11: $Va }, { 1: [2, 7], 6: $V1, 12: 21, 13: $V2, 14: 14, 15: $V3, 16: $V4, 17: 17, 18: 18, 19: $V5, 22: $V6 }, o($Vc, [2, 14], { 7: $Vd, 11: $Ve }), o($Vf, [2, 8]), o($Vf, [2, 9]), o($Vf, [2, 10]), o($Vb, [2, 15]), o($Vb, [2, 16]), o($Vb, [2, 17]), { 20: [1, 35] }, { 21: [1, 36] }, o($Vc, [2, 13], { 7: $Vd, 11: $Ve }), o($Vf, [2, 11]), o($Vf, [2, 12]), { 21: [1, 37] }, o($Vb, [2, 25]), o($Vb, [2, 27])],
71 defaultActions: { 2: [2, 1], 6: [2, 2] },
72 parseError: function parseError2(str, hash) {
73 if (hash.recoverable) {
74 this.trace(str);
75 } else {
76 var error = new Error(str);
77 error.hash = hash;
78 throw error;
79 }
80 },
81 parse: function parse(input) {
82 var self2 = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, TERROR = 2, EOF = 1;
83 var args = lstack.slice.call(arguments, 1);
84 var lexer2 = Object.create(this.lexer);
85 var sharedState = { yy: {} };
86 for (var k in this.yy) {
87 if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
88 sharedState.yy[k] = this.yy[k];
89 }
90 }
91 lexer2.setInput(input, sharedState.yy);
92 sharedState.yy.lexer = lexer2;
93 sharedState.yy.parser = this;
94 if (typeof lexer2.yylloc == "undefined") {
95 lexer2.yylloc = {};
96 }
97 var yyloc = lexer2.yylloc;
98 lstack.push(yyloc);
99 var ranges = lexer2.options && lexer2.options.ranges;
100 if (typeof sharedState.yy.parseError === "function") {
101 this.parseError = sharedState.yy.parseError;
102 } else {
103 this.parseError = Object.getPrototypeOf(this).parseError;
104 }
105 function lex() {
106 var token;
107 token = tstack.pop() || lexer2.lex() || EOF;
108 if (typeof token !== "number") {
109 if (token instanceof Array) {
110 tstack = token;
111 token = tstack.pop();
112 }
113 token = self2.symbols_[token] || token;
114 }
115 return token;
116 }
117 var symbol, state, action, r, yyval = {}, p, len, newState, expected;
118 while (true) {
119 state = stack[stack.length - 1];
120 if (this.defaultActions[state]) {
121 action = this.defaultActions[state];
122 } else {
123 if (symbol === null || typeof symbol == "undefined") {
124 symbol = lex();
125 }
126 action = table[state] && table[state][symbol];
127 }
128 if (typeof action === "undefined" || !action.length || !action[0]) {
129 var errStr = "";
130 expected = [];
131 for (p in table[state]) {
132 if (this.terminals_[p] && p > TERROR) {
133 expected.push("'" + this.terminals_[p] + "'");
134 }
135 }
136 if (lexer2.showPosition) {
137 errStr = "Parse error on line " + (yylineno + 1) + ":\n" + lexer2.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
138 } else {
139 errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == EOF ? "end of input" : "'" + (this.terminals_[symbol] || symbol) + "'");
140 }
141 this.parseError(errStr, {
142 text: lexer2.match,
143 token: this.terminals_[symbol] || symbol,
144 line: lexer2.yylineno,
145 loc: yyloc,
146 expected
147 });
148 }
149 if (action[0] instanceof Array && action.length > 1) {
150 throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
151 }
152 switch (action[0]) {
153 case 1:
154 stack.push(symbol);
155 vstack.push(lexer2.yytext);
156 lstack.push(lexer2.yylloc);
157 stack.push(action[1]);
158 symbol = null;
159 {
160 yyleng = lexer2.yyleng;
161 yytext = lexer2.yytext;
162 yylineno = lexer2.yylineno;
163 yyloc = lexer2.yylloc;
164 }
165 break;
166 case 2:
167 len = this.productions_[action[1]][1];
168 yyval.$ = vstack[vstack.length - len];
169 yyval._$ = {
170 first_line: lstack[lstack.length - (len || 1)].first_line,
171 last_line: lstack[lstack.length - 1].last_line,
172 first_column: lstack[lstack.length - (len || 1)].first_column,
173 last_column: lstack[lstack.length - 1].last_column
174 };
175 if (ranges) {
176 yyval._$.range = [
177 lstack[lstack.length - (len || 1)].range[0],
178 lstack[lstack.length - 1].range[1]
179 ];
180 }
181 r = this.performAction.apply(yyval, [
182 yytext,
183 yyleng,
184 yylineno,
185 sharedState.yy,
186 action[1],
187 vstack,
188 lstack
189 ].concat(args));
190 if (typeof r !== "undefined") {
191 return r;
192 }
193 if (len) {
194 stack = stack.slice(0, -1 * len * 2);
195 vstack = vstack.slice(0, -1 * len);
196 lstack = lstack.slice(0, -1 * len);
197 }
198 stack.push(this.productions_[action[1]][0]);
199 vstack.push(yyval.$);
200 lstack.push(yyval._$);
201 newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
202 stack.push(newState);
203 break;
204 case 3:
205 return true;
206 }
207 }
208 return true;
209 }
210 };
211 var lexer = function() {
212 var lexer2 = {
213 EOF: 1,
214 parseError: function parseError2(str, hash) {
215 if (this.yy.parser) {
216 this.yy.parser.parseError(str, hash);
217 } else {
218 throw new Error(str);
219 }
220 },
221 // resets the lexer, sets new input
222 setInput: function(input, yy) {
223 this.yy = yy || this.yy || {};
224 this._input = input;
225 this._more = this._backtrack = this.done = false;
226 this.yylineno = this.yyleng = 0;
227 this.yytext = this.matched = this.match = "";
228 this.conditionStack = ["INITIAL"];
229 this.yylloc = {
230 first_line: 1,
231 first_column: 0,
232 last_line: 1,
233 last_column: 0
234 };
235 if (this.options.ranges) {
236 this.yylloc.range = [0, 0];
237 }
238 this.offset = 0;
239 return this;
240 },
241 // consumes and returns one char from the input
242 input: function() {
243 var ch = this._input[0];
244 this.yytext += ch;
245 this.yyleng++;
246 this.offset++;
247 this.match += ch;
248 this.matched += ch;
249 var lines = ch.match(/(?:\r\n?|\n).*/g);
250 if (lines) {
251 this.yylineno++;
252 this.yylloc.last_line++;
253 } else {
254 this.yylloc.last_column++;
255 }
256 if (this.options.ranges) {
257 this.yylloc.range[1]++;
258 }
259 this._input = this._input.slice(1);
260 return ch;
261 },
262 // unshifts one char (or a string) into the input
263 unput: function(ch) {
264 var len = ch.length;
265 var lines = ch.split(/(?:\r\n?|\n)/g);
266 this._input = ch + this._input;
267 this.yytext = this.yytext.substr(0, this.yytext.length - len);
268 this.offset -= len;
269 var oldLines = this.match.split(/(?:\r\n?|\n)/g);
270 this.match = this.match.substr(0, this.match.length - 1);
271 this.matched = this.matched.substr(0, this.matched.length - 1);
272 if (lines.length - 1) {
273 this.yylineno -= lines.length - 1;
274 }
275 var r = this.yylloc.range;
276 this.yylloc = {
277 first_line: this.yylloc.first_line,
278 last_line: this.yylineno + 1,
279 first_column: this.yylloc.first_column,
280 last_column: lines ? (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length : this.yylloc.first_column - len
281 };
282 if (this.options.ranges) {
283 this.yylloc.range = [r[0], r[0] + this.yyleng - len];
284 }
285 this.yyleng = this.yytext.length;
286 return this;
287 },
288 // When called from action, caches matched text and appends it on next action
289 more: function() {
290 this._more = true;
291 return this;
292 },
293 // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead.
294 reject: function() {
295 if (this.options.backtrack_lexer) {
296 this._backtrack = true;
297 } else {
298 return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n" + this.showPosition(), {
299 text: "",
300 token: null,
301 line: this.yylineno
302 });
303 }
304 return this;
305 },
306 // retain first n characters of the match
307 less: function(n) {
308 this.unput(this.match.slice(n));
309 },
310 // displays already matched input, i.e. for error messages
311 pastInput: function() {
312 var past = this.matched.substr(0, this.matched.length - this.match.length);
313 return (past.length > 20 ? "..." : "") + past.substr(-20).replace(/\n/g, "");
314 },
315 // displays upcoming input, i.e. for error messages
316 upcomingInput: function() {
317 var next2 = this.match;
318 if (next2.length < 20) {
319 next2 += this._input.substr(0, 20 - next2.length);
320 }
321 return (next2.substr(0, 20) + (next2.length > 20 ? "..." : "")).replace(/\n/g, "");
322 },
323 // displays the character position where the lexing error occurred, i.e. for error messages
324 showPosition: function() {
325 var pre = this.pastInput();
326 var c = new Array(pre.length + 1).join("-");
327 return pre + this.upcomingInput() + "\n" + c + "^";
328 },
329 // test the lexed token: return FALSE when not a match, otherwise return token
330 test_match: function(match, indexed_rule) {
331 var token, lines, backup;
332 if (this.options.backtrack_lexer) {
333 backup = {
334 yylineno: this.yylineno,
335 yylloc: {
336 first_line: this.yylloc.first_line,
337 last_line: this.last_line,
338 first_column: this.yylloc.first_column,
339 last_column: this.yylloc.last_column
340 },
341 yytext: this.yytext,
342 match: this.match,
343 matches: this.matches,
344 matched: this.matched,
345 yyleng: this.yyleng,
346 offset: this.offset,
347 _more: this._more,
348 _input: this._input,
349 yy: this.yy,
350 conditionStack: this.conditionStack.slice(0),
351 done: this.done
352 };
353 if (this.options.ranges) {
354 backup.yylloc.range = this.yylloc.range.slice(0);
355 }
356 }
357 lines = match[0].match(/(?:\r\n?|\n).*/g);
358 if (lines) {
359 this.yylineno += lines.length;
360 }
361 this.yylloc = {
362 first_line: this.yylloc.last_line,
363 last_line: this.yylineno + 1,
364 first_column: this.yylloc.last_column,
365 last_column: lines ? lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length
366 };
367 this.yytext += match[0];
368 this.match += match[0];
369 this.matches = match;
370 this.yyleng = this.yytext.length;
371 if (this.options.ranges) {
372 this.yylloc.range = [this.offset, this.offset += this.yyleng];
373 }
374 this._more = false;
375 this._backtrack = false;
376 this._input = this._input.slice(match[0].length);
377 this.matched += match[0];
378 token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]);
379 if (this.done && this._input) {
380 this.done = false;
381 }
382 if (token) {
383 return token;
384 } else if (this._backtrack) {
385 for (var k in backup) {
386 this[k] = backup[k];
387 }
388 return false;
389 }
390 return false;
391 },
392 // return next match in input
393 next: function() {
394 if (this.done) {
395 return this.EOF;
396 }
397 if (!this._input) {
398 this.done = true;
399 }
400 var token, match, tempMatch, index;
401 if (!this._more) {
402 this.yytext = "";
403 this.match = "";
404 }
405 var rules = this._currentRules();
406 for (var i = 0; i < rules.length; i++) {
407 tempMatch = this._input.match(this.rules[rules[i]]);
408 if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
409 match = tempMatch;
410 index = i;
411 if (this.options.backtrack_lexer) {
412 token = this.test_match(tempMatch, rules[i]);
413 if (token !== false) {
414 return token;
415 } else if (this._backtrack) {
416 match = false;
417 continue;
418 } else {
419 return false;
420 }
421 } else if (!this.options.flex) {
422 break;
423 }
424 }
425 }
426 if (match) {
427 token = this.test_match(match, rules[index]);
428 if (token !== false) {
429 return token;
430 }
431 return false;
432 }
433 if (this._input === "") {
434 return this.EOF;
435 } else {
436 return this.parseError("Lexical error on line " + (this.yylineno + 1) + ". Unrecognized text.\n" + this.showPosition(), {
437 text: "",
438 token: null,
439 line: this.yylineno
440 });
441 }
442 },
443 // return next match that has a token
444 lex: function lex() {
445 var r = this.next();
446 if (r) {
447 return r;
448 } else {
449 return this.lex();
450 }
451 },
452 // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack)
453 begin: function begin(condition) {
454 this.conditionStack.push(condition);
455 },
456 // pop the previously active lexer condition state off the condition stack
457 popState: function popState() {
458 var n = this.conditionStack.length - 1;
459 if (n > 0) {
460 return this.conditionStack.pop();
461 } else {
462 return this.conditionStack[0];
463 }
464 },
465 // produce the lexer rule set which is active for the currently active lexer condition state
466 _currentRules: function _currentRules() {
467 if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) {
468 return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules;
469 } else {
470 return this.conditions["INITIAL"].rules;
471 }
472 },
473 // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available
474 topState: function topState(n) {
475 n = this.conditionStack.length - 1 - Math.abs(n || 0);
476 if (n >= 0) {
477 return this.conditionStack[n];
478 } else {
479 return "INITIAL";
480 }
481 },
482 // alias for begin(condition)
483 pushState: function pushState(condition) {
484 this.begin(condition);
485 },
486 // return the number of states currently on the stack
487 stateStackSize: function stateStackSize() {
488 return this.conditionStack.length;
489 },
490 options: { "case-insensitive": true },
491 performAction: function anonymous(yy, yy_, $avoiding_name_collisions, YY_START) {
492 switch ($avoiding_name_collisions) {
493 case 0:
494 yy.getLogger().trace("Found comment", yy_.yytext);
495 return 6;
496 case 1:
497 return 8;
498 case 2:
499 this.begin("CLASS");
500 break;
501 case 3:
502 this.popState();
503 return 16;
504 case 4:
505 this.popState();
506 break;
507 case 5:
508 yy.getLogger().trace("Begin icon");
509 this.begin("ICON");
510 break;
511 case 6:
512 yy.getLogger().trace("SPACELINE");
513 return 6;
514 case 7:
515 return 7;
516 case 8:
517 return 15;
518 case 9:
519 yy.getLogger().trace("end icon");
520 this.popState();
521 break;
522 case 10:
523 yy.getLogger().trace("Exploding node");
524 this.begin("NODE");
525 return 19;
526 case 11:
527 yy.getLogger().trace("Cloud");
528 this.begin("NODE");
529 return 19;
530 case 12:
531 yy.getLogger().trace("Explosion Bang");
532 this.begin("NODE");
533 return 19;
534 case 13:
535 yy.getLogger().trace("Cloud Bang");
536 this.begin("NODE");
537 return 19;
538 case 14:
539 this.begin("NODE");
540 return 19;
541 case 15:
542 this.begin("NODE");
543 return 19;
544 case 16:
545 this.begin("NODE");
546 return 19;
547 case 17:
548 this.begin("NODE");
549 return 19;
550 case 18:
551 return 13;
552 case 19:
553 return 22;
554 case 20:
555 return 11;
556 case 21:
557 this.begin("NSTR2");
558 break;
559 case 22:
560 return "NODE_DESCR";
561 case 23:
562 this.popState();
563 break;
564 case 24:
565 yy.getLogger().trace("Starting NSTR");
566 this.begin("NSTR");
567 break;
568 case 25:
569 yy.getLogger().trace("description:", yy_.yytext);
570 return "NODE_DESCR";
571 case 26:
572 this.popState();
573 break;
574 case 27:
575 this.popState();
576 yy.getLogger().trace("node end ))");
577 return "NODE_DEND";
578 case 28:
579 this.popState();
580 yy.getLogger().trace("node end )");
581 return "NODE_DEND";
582 case 29:
583 this.popState();
584 yy.getLogger().trace("node end ...", yy_.yytext);
585 return "NODE_DEND";
586 case 30:
587 this.popState();
588 yy.getLogger().trace("node end ((");
589 return "NODE_DEND";
590 case 31:
591 this.popState();
592 yy.getLogger().trace("node end (-");
593 return "NODE_DEND";
594 case 32:
595 this.popState();
596 yy.getLogger().trace("node end (-");
597 return "NODE_DEND";
598 case 33:
599 this.popState();
600 yy.getLogger().trace("node end ((");
601 return "NODE_DEND";
602 case 34:
603 this.popState();
604 yy.getLogger().trace("node end ((");
605 return "NODE_DEND";
606 case 35:
607 yy.getLogger().trace("Long description:", yy_.yytext);
608 return 20;
609 case 36:
610 yy.getLogger().trace("Long description:", yy_.yytext);
611 return 20;
612 }
613 },
614 rules: [/^(?:\s*%%.*)/i, /^(?:mindmap\b)/i, /^(?::::)/i, /^(?:.+)/i, /^(?:\n)/i, /^(?:::icon\()/i, /^(?:[\s]+[\n])/i, /^(?:[\n]+)/i, /^(?:[^\)]+)/i, /^(?:\))/i, /^(?:-\))/i, /^(?:\(-)/i, /^(?:\)\))/i, /^(?:\))/i, /^(?:\(\()/i, /^(?:\{\{)/i, /^(?:\()/i, /^(?:\[)/i, /^(?:[\s]+)/i, /^(?:[^\(\[\n\-\)\{\}]+)/i, /^(?:$)/i, /^(?:["][`])/i, /^(?:[^`"]+)/i, /^(?:[`]["])/i, /^(?:["])/i, /^(?:[^"]+)/i, /^(?:["])/i, /^(?:[\)]\))/i, /^(?:[\)])/i, /^(?:[\]])/i, /^(?:\}\})/i, /^(?:\(-)/i, /^(?:-\))/i, /^(?:\(\()/i, /^(?:\()/i, /^(?:[^\)\]\(\}]+)/i, /^(?:.+(?!\(\())/i],
615 conditions: { "CLASS": { "rules": [3, 4], "inclusive": false }, "ICON": { "rules": [8, 9], "inclusive": false }, "NSTR2": { "rules": [22, 23], "inclusive": false }, "NSTR": { "rules": [25, 26], "inclusive": false }, "NODE": { "rules": [21, 24, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36], "inclusive": false }, "INITIAL": { "rules": [0, 1, 2, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], "inclusive": true } }
616 };
617 return lexer2;
618 }();
619 parser2.lexer = lexer;
620 function Parser() {
621 this.yy = {};
622 }
623 Parser.prototype = parser2;
624 parser2.Parser = Parser;
625 return new Parser();
626}();
627parser.parser = parser;
628const mindmapParser = parser;
629const sanitizeText = (text) => sanitizeText$1(text, getConfig());
630let nodes = [];
631let cnt = 0;
632let elements = {};
633const clear = () => {
634 nodes = [];
635 cnt = 0;
636 elements = {};
637};
638const getParent = function(level) {
639 for (let i = nodes.length - 1; i >= 0; i--) {
640 if (nodes[i].level < level) {
641 return nodes[i];
642 }
643 }
644 return null;
645};
646const getMindmap = () => {
647 return nodes.length > 0 ? nodes[0] : null;
648};
649const addNode = (level, id, descr, type) => {
650 log.info("addNode", level, id, descr, type);
651 const conf = getConfig();
652 const node = {
653 id: cnt++,
654 nodeId: sanitizeText(id),
655 level,
656 descr: sanitizeText(descr),
657 type,
658 children: [],
659 width: getConfig().mindmap.maxNodeWidth
660 };
661 switch (node.type) {
662 case nodeType.ROUNDED_RECT:
663 node.padding = 2 * conf.mindmap.padding;
664 break;
665 case nodeType.RECT:
666 node.padding = 2 * conf.mindmap.padding;
667 break;
668 case nodeType.HEXAGON:
669 node.padding = 2 * conf.mindmap.padding;
670 break;
671 default:
672 node.padding = conf.mindmap.padding;
673 }
674 const parent = getParent(level);
675 if (parent) {
676 parent.children.push(node);
677 nodes.push(node);
678 } else {
679 if (nodes.length === 0) {
680 nodes.push(node);
681 } else {
682 let error = new Error(
683 'There can be only one root. No parent could be found for ("' + node.descr + '")'
684 );
685 error.hash = {
686 text: "branch " + name,
687 token: "branch " + name,
688 line: "1",
689 loc: { first_line: 1, last_line: 1, first_column: 1, last_column: 1 },
690 expected: ['"checkout ' + name + '"']
691 };
692 throw error;
693 }
694 }
695};
696const nodeType = {
697 DEFAULT: 0,
698 NO_BORDER: 0,
699 ROUNDED_RECT: 1,
700 RECT: 2,
701 CIRCLE: 3,
702 CLOUD: 4,
703 BANG: 5,
704 HEXAGON: 6
705};
706const getType = (startStr, endStr) => {
707 log.debug("In get type", startStr, endStr);
708 switch (startStr) {
709 case "[":
710 return nodeType.RECT;
711 case "(":
712 return endStr === ")" ? nodeType.ROUNDED_RECT : nodeType.CLOUD;
713 case "((":
714 return nodeType.CIRCLE;
715 case ")":
716 return nodeType.CLOUD;
717 case "))":
718 return nodeType.BANG;
719 case "{{":
720 return nodeType.HEXAGON;
721 default:
722 return nodeType.DEFAULT;
723 }
724};
725const setElementForId = (id, element) => {
726 elements[id] = element;
727};
728const decorateNode = (decoration) => {
729 const node = nodes[nodes.length - 1];
730 if (decoration && decoration.icon) {
731 node.icon = sanitizeText(decoration.icon);
732 }
733 if (decoration && decoration.class) {
734 node.class = sanitizeText(decoration.class);
735 }
736};
737const type2Str = (type) => {
738 switch (type) {
739 case nodeType.DEFAULT:
740 return "no-border";
741 case nodeType.RECT:
742 return "rect";
743 case nodeType.ROUNDED_RECT:
744 return "rounded-rect";
745 case nodeType.CIRCLE:
746 return "circle";
747 case nodeType.CLOUD:
748 return "cloud";
749 case nodeType.BANG:
750 return "bang";
751 case nodeType.HEXAGON:
752 return "hexgon";
753 default:
754 return "no-border";
755 }
756};
757let parseError;
758const setErrorHandler = (handler) => {
759 parseError = handler;
760};
761const getLogger = () => log;
762const getNodeById = (id) => nodes[id];
763const getElementById = (id) => elements[id];
764const mindmapDb = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
765 __proto__: null,
766 addNode,
767 clear,
768 decorateNode,
769 getElementById,
770 getLogger,
771 getMindmap,
772 getNodeById,
773 getType,
774 nodeType,
775 get parseError() {
776 return parseError;
777 },
778 sanitizeText,
779 setElementForId,
780 setErrorHandler,
781 type2Str
782}, Symbol.toStringTag, { value: "Module" }));
783const MAX_SECTIONS = 12;
784const defaultBkg = function(elem, node, section) {
785 const rd = 5;
786 elem.append("path").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr(
787 "d",
788 `M0 ${node.height - rd} v${-node.height + 2 * rd} q0,-5 5,-5 h${node.width - 2 * rd} q5,0 5,5 v${node.height - rd} H0 Z`
789 );
790 elem.append("line").attr("class", "node-line-" + section).attr("x1", 0).attr("y1", node.height).attr("x2", node.width).attr("y2", node.height);
791};
792const rectBkg = function(elem, node) {
793 elem.append("rect").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr("height", node.height).attr("width", node.width);
794};
795const cloudBkg = function(elem, node) {
796 const w = node.width;
797 const h = node.height;
798 const r1 = 0.15 * w;
799 const r2 = 0.25 * w;
800 const r3 = 0.35 * w;
801 const r4 = 0.2 * w;
802 elem.append("path").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr(
803 "d",
804 `M0 0 a${r1},${r1} 0 0,1 ${w * 0.25},${-1 * w * 0.1}
805 a${r3},${r3} 1 0,1 ${w * 0.4},${-1 * w * 0.1}
806 a${r2},${r2} 1 0,1 ${w * 0.35},${1 * w * 0.2}
807
808 a${r1},${r1} 1 0,1 ${w * 0.15},${1 * h * 0.35}
809 a${r4},${r4} 1 0,1 ${-1 * w * 0.15},${1 * h * 0.65}
810
811 a${r2},${r1} 1 0,1 ${-1 * w * 0.25},${w * 0.15}
812 a${r3},${r3} 1 0,1 ${-1 * w * 0.5},${0}
813 a${r1},${r1} 1 0,1 ${-1 * w * 0.25},${-1 * w * 0.15}
814
815 a${r1},${r1} 1 0,1 ${-1 * w * 0.1},${-1 * h * 0.35}
816 a${r4},${r4} 1 0,1 ${w * 0.1},${-1 * h * 0.65}
817
818 H0 V0 Z`
819 );
820};
821const bangBkg = function(elem, node) {
822 const w = node.width;
823 const h = node.height;
824 const r = 0.15 * w;
825 elem.append("path").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr(
826 "d",
827 `M0 0 a${r},${r} 1 0,0 ${w * 0.25},${-1 * h * 0.1}
828 a${r},${r} 1 0,0 ${w * 0.25},${0}
829 a${r},${r} 1 0,0 ${w * 0.25},${0}
830 a${r},${r} 1 0,0 ${w * 0.25},${1 * h * 0.1}
831
832 a${r},${r} 1 0,0 ${w * 0.15},${1 * h * 0.33}
833 a${r * 0.8},${r * 0.8} 1 0,0 ${0},${1 * h * 0.34}
834 a${r},${r} 1 0,0 ${-1 * w * 0.15},${1 * h * 0.33}
835
836 a${r},${r} 1 0,0 ${-1 * w * 0.25},${h * 0.15}
837 a${r},${r} 1 0,0 ${-1 * w * 0.25},${0}
838 a${r},${r} 1 0,0 ${-1 * w * 0.25},${0}
839 a${r},${r} 1 0,0 ${-1 * w * 0.25},${-1 * h * 0.15}
840
841 a${r},${r} 1 0,0 ${-1 * w * 0.1},${-1 * h * 0.33}
842 a${r * 0.8},${r * 0.8} 1 0,0 ${0},${-1 * h * 0.34}
843 a${r},${r} 1 0,0 ${w * 0.1},${-1 * h * 0.33}
844
845 H0 V0 Z`
846 );
847};
848const circleBkg = function(elem, node) {
849 elem.append("circle").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr("r", node.width / 2);
850};
851function insertPolygonShape(parent, w, h, points, node) {
852 return parent.insert("polygon", ":first-child").attr(
853 "points",
854 points.map(function(d) {
855 return d.x + "," + d.y;
856 }).join(" ")
857 ).attr("transform", "translate(" + (node.width - w) / 2 + ", " + h + ")");
858}
859const hexagonBkg = function(elem, node) {
860 const h = node.height;
861 const f = 4;
862 const m = h / f;
863 const w = node.width - node.padding + 2 * m;
864 const points = [
865 { x: m, y: 0 },
866 { x: w - m, y: 0 },
867 { x: w, y: -h / 2 },
868 { x: w - m, y: -h },
869 { x: m, y: -h },
870 { x: 0, y: -h / 2 }
871 ];
872 insertPolygonShape(elem, w, h, points, node);
873};
874const roundedRectBkg = function(elem, node) {
875 elem.append("rect").attr("id", "node-" + node.id).attr("class", "node-bkg node-" + type2Str(node.type)).attr("height", node.height).attr("rx", node.padding).attr("ry", node.padding).attr("width", node.width);
876};
877const drawNode = function(elem, node, fullSection, conf) {
878 const htmlLabels = conf.htmlLabels;
879 const section = fullSection % (MAX_SECTIONS - 1);
880 const nodeElem = elem.append("g");
881 node.section = section;
882 let sectionClass = "section-" + section;
883 if (section < 0) {
884 sectionClass += " section-root";
885 }
886 nodeElem.attr("class", (node.class ? node.class + " " : "") + "mindmap-node " + sectionClass);
887 const bkgElem = nodeElem.append("g");
888 const textElem = nodeElem.append("g");
889 const description = node.descr.replace(/(<br\/*>)/g, "\n");
890 createText(textElem, description, {
891 useHtmlLabels: htmlLabels,
892 width: node.width,
893 classes: "mindmap-node-label"
894 });
895 if (!htmlLabels) {
896 textElem.attr("dy", "1em").attr("alignment-baseline", "middle").attr("dominant-baseline", "middle").attr("text-anchor", "middle");
897 }
898 const bbox = textElem.node().getBBox();
899 const fontSize = conf.fontSize.replace ? conf.fontSize.replace("px", "") : conf.fontSize;
900 node.height = bbox.height + fontSize * 1.1 * 0.5 + node.padding;
901 node.width = bbox.width + 2 * node.padding;
902 if (node.icon) {
903 if (node.type === nodeType.CIRCLE) {
904 node.height += 50;
905 node.width += 50;
906 const icon = nodeElem.append("foreignObject").attr("height", "50px").attr("width", node.width).attr("style", "text-align: center;");
907 icon.append("div").attr("class", "icon-container").append("i").attr("class", "node-icon-" + section + " " + node.icon);
908 textElem.attr(
909 "transform",
910 "translate(" + node.width / 2 + ", " + (node.height / 2 - 1.5 * node.padding) + ")"
911 );
912 } else {
913 node.width += 50;
914 const orgHeight = node.height;
915 node.height = Math.max(orgHeight, 60);
916 const heightDiff = Math.abs(node.height - orgHeight);
917 const icon = nodeElem.append("foreignObject").attr("width", "60px").attr("height", node.height).attr("style", "text-align: center;margin-top:" + heightDiff / 2 + "px;");
918 icon.append("div").attr("class", "icon-container").append("i").attr("class", "node-icon-" + section + " " + node.icon);
919 textElem.attr(
920 "transform",
921 "translate(" + (25 + node.width / 2) + ", " + (heightDiff / 2 + node.padding / 2) + ")"
922 );
923 }
924 } else {
925 if (!htmlLabels) {
926 const dx = node.width / 2;
927 const dy = node.padding / 2;
928 textElem.attr("transform", "translate(" + dx + ", " + dy + ")");
929 } else {
930 const dx = (node.width - bbox.width) / 2;
931 const dy = (node.height - bbox.height) / 2;
932 textElem.attr("transform", "translate(" + dx + ", " + dy + ")");
933 }
934 }
935 switch (node.type) {
936 case nodeType.DEFAULT:
937 defaultBkg(bkgElem, node, section);
938 break;
939 case nodeType.ROUNDED_RECT:
940 roundedRectBkg(bkgElem, node);
941 break;
942 case nodeType.RECT:
943 rectBkg(bkgElem, node);
944 break;
945 case nodeType.CIRCLE:
946 bkgElem.attr("transform", "translate(" + node.width / 2 + ", " + +node.height / 2 + ")");
947 circleBkg(bkgElem, node);
948 break;
949 case nodeType.CLOUD:
950 cloudBkg(bkgElem, node);
951 break;
952 case nodeType.BANG:
953 bangBkg(bkgElem, node);
954 break;
955 case nodeType.HEXAGON:
956 hexagonBkg(bkgElem, node);
957 break;
958 }
959 setElementForId(node.id, nodeElem);
960 return node.height;
961};
962const drawEdge = function drawEdge2(edgesElem, mindmap, parent, depth, fullSection) {
963 const section = fullSection % (MAX_SECTIONS - 1);
964 const sx = parent.x + parent.width / 2;
965 const sy = parent.y + parent.height / 2;
966 const ex = mindmap.x + mindmap.width / 2;
967 const ey = mindmap.y + mindmap.height / 2;
968 const mx = ex > sx ? sx + Math.abs(sx - ex) / 2 : sx - Math.abs(sx - ex) / 2;
969 const my = ey > sy ? sy + Math.abs(sy - ey) / 2 : sy - Math.abs(sy - ey) / 2;
970 const qx = ex > sx ? Math.abs(sx - mx) / 2 + sx : -Math.abs(sx - mx) / 2 + sx;
971 const qy = ey > sy ? Math.abs(sy - my) / 2 + sy : -Math.abs(sy - my) / 2 + sy;
972 edgesElem.append("path").attr(
973 "d",
974 parent.direction === "TB" || parent.direction === "BT" ? `M${sx},${sy} Q${sx},${qy} ${mx},${my} T${ex},${ey}` : `M${sx},${sy} Q${qx},${sy} ${mx},${my} T${ex},${ey}`
975 ).attr("class", "edge section-edge-" + section + " edge-depth-" + depth);
976};
977const positionNode = function(node) {
978 const nodeElem = getElementById(node.id);
979 const x = node.x || 0;
980 const y = node.y || 0;
981 nodeElem.attr("transform", "translate(" + x + "," + y + ")");
982};
983const svgDraw = { drawNode, positionNode, drawEdge };
984var cytoscape_umdExports = {};
985var cytoscape_umd = {
986 get exports() {
987 return cytoscape_umdExports;
988 },
989 set exports(v) {
990 cytoscape_umdExports = v;
991 }
992};
993(function(module, exports) {
994 (function(global, factory) {
995 module.exports = factory();
996 })(commonjsGlobal, function() {
997 function _typeof(obj) {
998 "@babel/helpers - typeof";
999 return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
1000 return typeof obj2;
1001 } : function(obj2) {
1002 return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
1003 }, _typeof(obj);
1004 }
1005 function _classCallCheck(instance2, Constructor) {
1006 if (!(instance2 instanceof Constructor)) {
1007 throw new TypeError("Cannot call a class as a function");
1008 }
1009 }
1010 function _defineProperties(target, props) {
1011 for (var i2 = 0; i2 < props.length; i2++) {
1012 var descriptor = props[i2];
1013 descriptor.enumerable = descriptor.enumerable || false;
1014 descriptor.configurable = true;
1015 if ("value" in descriptor)
1016 descriptor.writable = true;
1017 Object.defineProperty(target, descriptor.key, descriptor);
1018 }
1019 }
1020 function _createClass(Constructor, protoProps, staticProps) {
1021 if (protoProps)
1022 _defineProperties(Constructor.prototype, protoProps);
1023 if (staticProps)
1024 _defineProperties(Constructor, staticProps);
1025 Object.defineProperty(Constructor, "prototype", {
1026 writable: false
1027 });
1028 return Constructor;
1029 }
1030 function _defineProperty$1(obj, key, value) {
1031 if (key in obj) {
1032 Object.defineProperty(obj, key, {
1033 value,
1034 enumerable: true,
1035 configurable: true,
1036 writable: true
1037 });
1038 } else {
1039 obj[key] = value;
1040 }
1041 return obj;
1042 }
1043 function _slicedToArray(arr, i2) {
1044 return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i2) || _unsupportedIterableToArray(arr, i2) || _nonIterableRest();
1045 }
1046 function _arrayWithHoles(arr) {
1047 if (Array.isArray(arr))
1048 return arr;
1049 }
1050 function _iterableToArrayLimit(arr, i2) {
1051 var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
1052 if (_i == null)
1053 return;
1054 var _arr = [];
1055 var _n = true;
1056 var _d = false;
1057 var _s, _e;
1058 try {
1059 for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
1060 _arr.push(_s.value);
1061 if (i2 && _arr.length === i2)
1062 break;
1063 }
1064 } catch (err) {
1065 _d = true;
1066 _e = err;
1067 } finally {
1068 try {
1069 if (!_n && _i["return"] != null)
1070 _i["return"]();
1071 } finally {
1072 if (_d)
1073 throw _e;
1074 }
1075 }
1076 return _arr;
1077 }
1078 function _unsupportedIterableToArray(o, minLen) {
1079 if (!o)
1080 return;
1081 if (typeof o === "string")
1082 return _arrayLikeToArray(o, minLen);
1083 var n = Object.prototype.toString.call(o).slice(8, -1);
1084 if (n === "Object" && o.constructor)
1085 n = o.constructor.name;
1086 if (n === "Map" || n === "Set")
1087 return Array.from(o);
1088 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
1089 return _arrayLikeToArray(o, minLen);
1090 }
1091 function _arrayLikeToArray(arr, len) {
1092 if (len == null || len > arr.length)
1093 len = arr.length;
1094 for (var i2 = 0, arr2 = new Array(len); i2 < len; i2++)
1095 arr2[i2] = arr[i2];
1096 return arr2;
1097 }
1098 function _nonIterableRest() {
1099 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1100 }
1101 var window$1 = typeof window === "undefined" ? null : window;
1102 var navigator = window$1 ? window$1.navigator : null;
1103 window$1 ? window$1.document : null;
1104 var typeofstr = _typeof("");
1105 var typeofobj = _typeof({});
1106 var typeoffn = _typeof(function() {
1107 });
1108 var typeofhtmlele = typeof HTMLElement === "undefined" ? "undefined" : _typeof(HTMLElement);
1109 var instanceStr = function instanceStr2(obj) {
1110 return obj && obj.instanceString && fn$6(obj.instanceString) ? obj.instanceString() : null;
1111 };
1112 var string = function string2(obj) {
1113 return obj != null && _typeof(obj) == typeofstr;
1114 };
1115 var fn$6 = function fn2(obj) {
1116 return obj != null && _typeof(obj) === typeoffn;
1117 };
1118 var array = function array2(obj) {
1119 return !elementOrCollection(obj) && (Array.isArray ? Array.isArray(obj) : obj != null && obj instanceof Array);
1120 };
1121 var plainObject = function plainObject2(obj) {
1122 return obj != null && _typeof(obj) === typeofobj && !array(obj) && obj.constructor === Object;
1123 };
1124 var object = function object2(obj) {
1125 return obj != null && _typeof(obj) === typeofobj;
1126 };
1127 var number$1 = function number2(obj) {
1128 return obj != null && _typeof(obj) === _typeof(1) && !isNaN(obj);
1129 };
1130 var integer = function integer2(obj) {
1131 return number$1(obj) && Math.floor(obj) === obj;
1132 };
1133 var htmlElement = function htmlElement2(obj) {
1134 if ("undefined" === typeofhtmlele) {
1135 return void 0;
1136 } else {
1137 return null != obj && obj instanceof HTMLElement;
1138 }
1139 };
1140 var elementOrCollection = function elementOrCollection2(obj) {
1141 return element(obj) || collection(obj);
1142 };
1143 var element = function element2(obj) {
1144 return instanceStr(obj) === "collection" && obj._private.single;
1145 };
1146 var collection = function collection2(obj) {
1147 return instanceStr(obj) === "collection" && !obj._private.single;
1148 };
1149 var core = function core2(obj) {
1150 return instanceStr(obj) === "core";
1151 };
1152 var stylesheet = function stylesheet2(obj) {
1153 return instanceStr(obj) === "stylesheet";
1154 };
1155 var event = function event2(obj) {
1156 return instanceStr(obj) === "event";
1157 };
1158 var emptyString = function emptyString2(obj) {
1159 if (obj === void 0 || obj === null) {
1160 return true;
1161 } else if (obj === "" || obj.match(/^\s+$/)) {
1162 return true;
1163 }
1164 return false;
1165 };
1166 var domElement = function domElement2(obj) {
1167 if (typeof HTMLElement === "undefined") {
1168 return false;
1169 } else {
1170 return obj instanceof HTMLElement;
1171 }
1172 };
1173 var boundingBox = function boundingBox2(obj) {
1174 return plainObject(obj) && number$1(obj.x1) && number$1(obj.x2) && number$1(obj.y1) && number$1(obj.y2);
1175 };
1176 var promise = function promise2(obj) {
1177 return object(obj) && fn$6(obj.then);
1178 };
1179 var ms = function ms2() {
1180 return navigator && navigator.userAgent.match(/msie|trident|edge/i);
1181 };
1182 var memoize$1 = function memoize2(fn2, keyFn) {
1183 if (!keyFn) {
1184 keyFn = function keyFn2() {
1185 if (arguments.length === 1) {
1186 return arguments[0];
1187 } else if (arguments.length === 0) {
1188 return "undefined";
1189 }
1190 var args = [];
1191 for (var i2 = 0; i2 < arguments.length; i2++) {
1192 args.push(arguments[i2]);
1193 }
1194 return args.join("$");
1195 };
1196 }
1197 var memoizedFn = function memoizedFn2() {
1198 var self2 = this;
1199 var args = arguments;
1200 var ret;
1201 var k = keyFn.apply(self2, args);
1202 var cache2 = memoizedFn2.cache;
1203 if (!(ret = cache2[k])) {
1204 ret = cache2[k] = fn2.apply(self2, args);
1205 }
1206 return ret;
1207 };
1208 memoizedFn.cache = {};
1209 return memoizedFn;
1210 };
1211 var camel2dash = memoize$1(function(str) {
1212 return str.replace(/([A-Z])/g, function(v) {
1213 return "-" + v.toLowerCase();
1214 });
1215 });
1216 var dash2camel = memoize$1(function(str) {
1217 return str.replace(/(-\w)/g, function(v) {
1218 return v[1].toUpperCase();
1219 });
1220 });
1221 var prependCamel = memoize$1(function(prefix, str) {
1222 return prefix + str[0].toUpperCase() + str.substring(1);
1223 }, function(prefix, str) {
1224 return prefix + "$" + str;
1225 });
1226 var capitalize = function capitalize2(str) {
1227 if (emptyString(str)) {
1228 return str;
1229 }
1230 return str.charAt(0).toUpperCase() + str.substring(1);
1231 };
1232 var number = "(?:[-+]?(?:(?:\\d+|\\d*\\.\\d+)(?:[Ee][+-]?\\d+)?))";
1233 var rgba = "rgb[a]?\\((" + number + "[%]?)\\s*,\\s*(" + number + "[%]?)\\s*,\\s*(" + number + "[%]?)(?:\\s*,\\s*(" + number + "))?\\)";
1234 var rgbaNoBackRefs = "rgb[a]?\\((?:" + number + "[%]?)\\s*,\\s*(?:" + number + "[%]?)\\s*,\\s*(?:" + number + "[%]?)(?:\\s*,\\s*(?:" + number + "))?\\)";
1235 var hsla = "hsl[a]?\\((" + number + ")\\s*,\\s*(" + number + "[%])\\s*,\\s*(" + number + "[%])(?:\\s*,\\s*(" + number + "))?\\)";
1236 var hslaNoBackRefs = "hsl[a]?\\((?:" + number + ")\\s*,\\s*(?:" + number + "[%])\\s*,\\s*(?:" + number + "[%])(?:\\s*,\\s*(?:" + number + "))?\\)";
1237 var hex3 = "\\#[0-9a-fA-F]{3}";
1238 var hex6 = "\\#[0-9a-fA-F]{6}";
1239 var ascending = function ascending2(a, b) {
1240 if (a < b) {
1241 return -1;
1242 } else if (a > b) {
1243 return 1;
1244 } else {
1245 return 0;
1246 }
1247 };
1248 var descending = function descending2(a, b) {
1249 return -1 * ascending(a, b);
1250 };
1251 var extend = Object.assign != null ? Object.assign.bind(Object) : function(tgt) {
1252 var args = arguments;
1253 for (var i2 = 1; i2 < args.length; i2++) {
1254 var obj = args[i2];
1255 if (obj == null) {
1256 continue;
1257 }
1258 var keys = Object.keys(obj);
1259 for (var j = 0; j < keys.length; j++) {
1260 var k = keys[j];
1261 tgt[k] = obj[k];
1262 }
1263 }
1264 return tgt;
1265 };
1266 var hex2tuple = function hex2tuple2(hex) {
1267 if (!(hex.length === 4 || hex.length === 7) || hex[0] !== "#") {
1268 return;
1269 }
1270 var shortHex = hex.length === 4;
1271 var r, g, b;
1272 var base = 16;
1273 if (shortHex) {
1274 r = parseInt(hex[1] + hex[1], base);
1275 g = parseInt(hex[2] + hex[2], base);
1276 b = parseInt(hex[3] + hex[3], base);
1277 } else {
1278 r = parseInt(hex[1] + hex[2], base);
1279 g = parseInt(hex[3] + hex[4], base);
1280 b = parseInt(hex[5] + hex[6], base);
1281 }
1282 return [r, g, b];
1283 };
1284 var hsl2tuple = function hsl2tuple2(hsl) {
1285 var ret;
1286 var h, s, l, a, r, g, b;
1287 function hue2rgb(p3, q2, t) {
1288 if (t < 0)
1289 t += 1;
1290 if (t > 1)
1291 t -= 1;
1292 if (t < 1 / 6)
1293 return p3 + (q2 - p3) * 6 * t;
1294 if (t < 1 / 2)
1295 return q2;
1296 if (t < 2 / 3)
1297 return p3 + (q2 - p3) * (2 / 3 - t) * 6;
1298 return p3;
1299 }
1300 var m = new RegExp("^" + hsla + "$").exec(hsl);
1301 if (m) {
1302 h = parseInt(m[1]);
1303 if (h < 0) {
1304 h = (360 - -1 * h % 360) % 360;
1305 } else if (h > 360) {
1306 h = h % 360;
1307 }
1308 h /= 360;
1309 s = parseFloat(m[2]);
1310 if (s < 0 || s > 100) {
1311 return;
1312 }
1313 s = s / 100;
1314 l = parseFloat(m[3]);
1315 if (l < 0 || l > 100) {
1316 return;
1317 }
1318 l = l / 100;
1319 a = m[4];
1320 if (a !== void 0) {
1321 a = parseFloat(a);
1322 if (a < 0 || a > 1) {
1323 return;
1324 }
1325 }
1326 if (s === 0) {
1327 r = g = b = Math.round(l * 255);
1328 } else {
1329 var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
1330 var p2 = 2 * l - q;
1331 r = Math.round(255 * hue2rgb(p2, q, h + 1 / 3));
1332 g = Math.round(255 * hue2rgb(p2, q, h));
1333 b = Math.round(255 * hue2rgb(p2, q, h - 1 / 3));
1334 }
1335 ret = [r, g, b, a];
1336 }
1337 return ret;
1338 };
1339 var rgb2tuple = function rgb2tuple2(rgb) {
1340 var ret;
1341 var m = new RegExp("^" + rgba + "$").exec(rgb);
1342 if (m) {
1343 ret = [];
1344 var isPct = [];
1345 for (var i2 = 1; i2 <= 3; i2++) {
1346 var channel = m[i2];
1347 if (channel[channel.length - 1] === "%") {
1348 isPct[i2] = true;
1349 }
1350 channel = parseFloat(channel);
1351 if (isPct[i2]) {
1352 channel = channel / 100 * 255;
1353 }
1354 if (channel < 0 || channel > 255) {
1355 return;
1356 }
1357 ret.push(Math.floor(channel));
1358 }
1359 var atLeastOneIsPct = isPct[1] || isPct[2] || isPct[3];
1360 var allArePct = isPct[1] && isPct[2] && isPct[3];
1361 if (atLeastOneIsPct && !allArePct) {
1362 return;
1363 }
1364 var alpha = m[4];
1365 if (alpha !== void 0) {
1366 alpha = parseFloat(alpha);
1367 if (alpha < 0 || alpha > 1) {
1368 return;
1369 }
1370 ret.push(alpha);
1371 }
1372 }
1373 return ret;
1374 };
1375 var colorname2tuple = function colorname2tuple2(color) {
1376 return colors[color.toLowerCase()];
1377 };
1378 var color2tuple = function color2tuple2(color) {
1379 return (array(color) ? color : null) || colorname2tuple(color) || hex2tuple(color) || rgb2tuple(color) || hsl2tuple(color);
1380 };
1381 var colors = {
1382 // special colour names
1383 transparent: [0, 0, 0, 0],
1384 // NB alpha === 0
1385 // regular colours
1386 aliceblue: [240, 248, 255],
1387 antiquewhite: [250, 235, 215],
1388 aqua: [0, 255, 255],
1389 aquamarine: [127, 255, 212],
1390 azure: [240, 255, 255],
1391 beige: [245, 245, 220],
1392 bisque: [255, 228, 196],
1393 black: [0, 0, 0],
1394 blanchedalmond: [255, 235, 205],
1395 blue: [0, 0, 255],
1396 blueviolet: [138, 43, 226],
1397 brown: [165, 42, 42],
1398 burlywood: [222, 184, 135],
1399 cadetblue: [95, 158, 160],
1400 chartreuse: [127, 255, 0],
1401 chocolate: [210, 105, 30],
1402 coral: [255, 127, 80],
1403 cornflowerblue: [100, 149, 237],
1404 cornsilk: [255, 248, 220],
1405 crimson: [220, 20, 60],
1406 cyan: [0, 255, 255],
1407 darkblue: [0, 0, 139],
1408 darkcyan: [0, 139, 139],
1409 darkgoldenrod: [184, 134, 11],
1410 darkgray: [169, 169, 169],
1411 darkgreen: [0, 100, 0],
1412 darkgrey: [169, 169, 169],
1413 darkkhaki: [189, 183, 107],
1414 darkmagenta: [139, 0, 139],
1415 darkolivegreen: [85, 107, 47],
1416 darkorange: [255, 140, 0],
1417 darkorchid: [153, 50, 204],
1418 darkred: [139, 0, 0],
1419 darksalmon: [233, 150, 122],
1420 darkseagreen: [143, 188, 143],
1421 darkslateblue: [72, 61, 139],
1422 darkslategray: [47, 79, 79],
1423 darkslategrey: [47, 79, 79],
1424 darkturquoise: [0, 206, 209],
1425 darkviolet: [148, 0, 211],
1426 deeppink: [255, 20, 147],
1427 deepskyblue: [0, 191, 255],
1428 dimgray: [105, 105, 105],
1429 dimgrey: [105, 105, 105],
1430 dodgerblue: [30, 144, 255],
1431 firebrick: [178, 34, 34],
1432 floralwhite: [255, 250, 240],
1433 forestgreen: [34, 139, 34],
1434 fuchsia: [255, 0, 255],
1435 gainsboro: [220, 220, 220],
1436 ghostwhite: [248, 248, 255],
1437 gold: [255, 215, 0],
1438 goldenrod: [218, 165, 32],
1439 gray: [128, 128, 128],
1440 grey: [128, 128, 128],
1441 green: [0, 128, 0],
1442 greenyellow: [173, 255, 47],
1443 honeydew: [240, 255, 240],
1444 hotpink: [255, 105, 180],
1445 indianred: [205, 92, 92],
1446 indigo: [75, 0, 130],
1447 ivory: [255, 255, 240],
1448 khaki: [240, 230, 140],
1449 lavender: [230, 230, 250],
1450 lavenderblush: [255, 240, 245],
1451 lawngreen: [124, 252, 0],
1452 lemonchiffon: [255, 250, 205],
1453 lightblue: [173, 216, 230],
1454 lightcoral: [240, 128, 128],
1455 lightcyan: [224, 255, 255],
1456 lightgoldenrodyellow: [250, 250, 210],
1457 lightgray: [211, 211, 211],
1458 lightgreen: [144, 238, 144],
1459 lightgrey: [211, 211, 211],
1460 lightpink: [255, 182, 193],
1461 lightsalmon: [255, 160, 122],
1462 lightseagreen: [32, 178, 170],
1463 lightskyblue: [135, 206, 250],
1464 lightslategray: [119, 136, 153],
1465 lightslategrey: [119, 136, 153],
1466 lightsteelblue: [176, 196, 222],
1467 lightyellow: [255, 255, 224],
1468 lime: [0, 255, 0],
1469 limegreen: [50, 205, 50],
1470 linen: [250, 240, 230],
1471 magenta: [255, 0, 255],
1472 maroon: [128, 0, 0],
1473 mediumaquamarine: [102, 205, 170],
1474 mediumblue: [0, 0, 205],
1475 mediumorchid: [186, 85, 211],
1476 mediumpurple: [147, 112, 219],
1477 mediumseagreen: [60, 179, 113],
1478 mediumslateblue: [123, 104, 238],
1479 mediumspringgreen: [0, 250, 154],
1480 mediumturquoise: [72, 209, 204],
1481 mediumvioletred: [199, 21, 133],
1482 midnightblue: [25, 25, 112],
1483 mintcream: [245, 255, 250],
1484 mistyrose: [255, 228, 225],
1485 moccasin: [255, 228, 181],
1486 navajowhite: [255, 222, 173],
1487 navy: [0, 0, 128],
1488 oldlace: [253, 245, 230],
1489 olive: [128, 128, 0],
1490 olivedrab: [107, 142, 35],
1491 orange: [255, 165, 0],
1492 orangered: [255, 69, 0],
1493 orchid: [218, 112, 214],
1494 palegoldenrod: [238, 232, 170],
1495 palegreen: [152, 251, 152],
1496 paleturquoise: [175, 238, 238],
1497 palevioletred: [219, 112, 147],
1498 papayawhip: [255, 239, 213],
1499 peachpuff: [255, 218, 185],
1500 peru: [205, 133, 63],
1501 pink: [255, 192, 203],
1502 plum: [221, 160, 221],
1503 powderblue: [176, 224, 230],
1504 purple: [128, 0, 128],
1505 red: [255, 0, 0],
1506 rosybrown: [188, 143, 143],
1507 royalblue: [65, 105, 225],
1508 saddlebrown: [139, 69, 19],
1509 salmon: [250, 128, 114],
1510 sandybrown: [244, 164, 96],
1511 seagreen: [46, 139, 87],
1512 seashell: [255, 245, 238],
1513 sienna: [160, 82, 45],
1514 silver: [192, 192, 192],
1515 skyblue: [135, 206, 235],
1516 slateblue: [106, 90, 205],
1517 slategray: [112, 128, 144],
1518 slategrey: [112, 128, 144],
1519 snow: [255, 250, 250],
1520 springgreen: [0, 255, 127],
1521 steelblue: [70, 130, 180],
1522 tan: [210, 180, 140],
1523 teal: [0, 128, 128],
1524 thistle: [216, 191, 216],
1525 tomato: [255, 99, 71],
1526 turquoise: [64, 224, 208],
1527 violet: [238, 130, 238],
1528 wheat: [245, 222, 179],
1529 white: [255, 255, 255],
1530 whitesmoke: [245, 245, 245],
1531 yellow: [255, 255, 0],
1532 yellowgreen: [154, 205, 50]
1533 };
1534 var setMap = function setMap2(options) {
1535 var obj = options.map;
1536 var keys = options.keys;
1537 var l = keys.length;
1538 for (var i2 = 0; i2 < l; i2++) {
1539 var key = keys[i2];
1540 if (plainObject(key)) {
1541 throw Error("Tried to set map with object key");
1542 }
1543 if (i2 < keys.length - 1) {
1544 if (obj[key] == null) {
1545 obj[key] = {};
1546 }
1547 obj = obj[key];
1548 } else {
1549 obj[key] = options.value;
1550 }
1551 }
1552 };
1553 var getMap = function getMap2(options) {
1554 var obj = options.map;
1555 var keys = options.keys;
1556 var l = keys.length;
1557 for (var i2 = 0; i2 < l; i2++) {
1558 var key = keys[i2];
1559 if (plainObject(key)) {
1560 throw Error("Tried to get map with object key");
1561 }
1562 obj = obj[key];
1563 if (obj == null) {
1564 return obj;
1565 }
1566 }
1567 return obj;
1568 };
1569 function isObject(value) {
1570 var type = typeof value;
1571 return value != null && (type == "object" || type == "function");
1572 }
1573 var isObject_1 = isObject;
1574 var commonjsGlobal$1 = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof commonjsGlobal !== "undefined" ? commonjsGlobal : typeof self !== "undefined" ? self : {};
1575 function createCommonjsModule(fn2, module2) {
1576 return module2 = { exports: {} }, fn2(module2, module2.exports), module2.exports;
1577 }
1578 var freeGlobal = typeof commonjsGlobal$1 == "object" && commonjsGlobal$1 && commonjsGlobal$1.Object === Object && commonjsGlobal$1;
1579 var _freeGlobal = freeGlobal;
1580 var freeSelf = typeof self == "object" && self && self.Object === Object && self;
1581 var root = _freeGlobal || freeSelf || Function("return this")();
1582 var _root = root;
1583 var now = function() {
1584 return _root.Date.now();
1585 };
1586 var now_1 = now;
1587 var reWhitespace = /\s/;
1588 function trimmedEndIndex(string2) {
1589 var index = string2.length;
1590 while (index-- && reWhitespace.test(string2.charAt(index))) {
1591 }
1592 return index;
1593 }
1594 var _trimmedEndIndex = trimmedEndIndex;
1595 var reTrimStart = /^\s+/;
1596 function baseTrim(string2) {
1597 return string2 ? string2.slice(0, _trimmedEndIndex(string2) + 1).replace(reTrimStart, "") : string2;
1598 }
1599 var _baseTrim = baseTrim;
1600 var Symbol$1 = _root.Symbol;
1601 var _Symbol = Symbol$1;
1602 var objectProto$5 = Object.prototype;
1603 var hasOwnProperty$4 = objectProto$5.hasOwnProperty;
1604 var nativeObjectToString$1 = objectProto$5.toString;
1605 var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : void 0;
1606 function getRawTag(value) {
1607 var isOwn = hasOwnProperty$4.call(value, symToStringTag$1), tag = value[symToStringTag$1];
1608 try {
1609 value[symToStringTag$1] = void 0;
1610 var unmasked = true;
1611 } catch (e) {
1612 }
1613 var result = nativeObjectToString$1.call(value);
1614 if (unmasked) {
1615 if (isOwn) {
1616 value[symToStringTag$1] = tag;
1617 } else {
1618 delete value[symToStringTag$1];
1619 }
1620 }
1621 return result;
1622 }
1623 var _getRawTag = getRawTag;
1624 var objectProto$4 = Object.prototype;
1625 var nativeObjectToString = objectProto$4.toString;
1626 function objectToString(value) {
1627 return nativeObjectToString.call(value);
1628 }
1629 var _objectToString = objectToString;
1630 var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
1631 var symToStringTag = _Symbol ? _Symbol.toStringTag : void 0;
1632 function baseGetTag(value) {
1633 if (value == null) {
1634 return value === void 0 ? undefinedTag : nullTag;
1635 }
1636 return symToStringTag && symToStringTag in Object(value) ? _getRawTag(value) : _objectToString(value);
1637 }
1638 var _baseGetTag = baseGetTag;
1639 function isObjectLike(value) {
1640 return value != null && typeof value == "object";
1641 }
1642 var isObjectLike_1 = isObjectLike;
1643 var symbolTag = "[object Symbol]";
1644 function isSymbol(value) {
1645 return typeof value == "symbol" || isObjectLike_1(value) && _baseGetTag(value) == symbolTag;
1646 }
1647 var isSymbol_1 = isSymbol;
1648 var NAN = 0 / 0;
1649 var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
1650 var reIsBinary = /^0b[01]+$/i;
1651 var reIsOctal = /^0o[0-7]+$/i;
1652 var freeParseInt = parseInt;
1653 function toNumber(value) {
1654 if (typeof value == "number") {
1655 return value;
1656 }
1657 if (isSymbol_1(value)) {
1658 return NAN;
1659 }
1660 if (isObject_1(value)) {
1661 var other = typeof value.valueOf == "function" ? value.valueOf() : value;
1662 value = isObject_1(other) ? other + "" : other;
1663 }
1664 if (typeof value != "string") {
1665 return value === 0 ? value : +value;
1666 }
1667 value = _baseTrim(value);
1668 var isBinary = reIsBinary.test(value);
1669 return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
1670 }
1671 var toNumber_1 = toNumber;
1672 var FUNC_ERROR_TEXT$1 = "Expected a function";
1673 var nativeMax = Math.max, nativeMin = Math.min;
1674 function debounce(func, wait, options) {
1675 var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
1676 if (typeof func != "function") {
1677 throw new TypeError(FUNC_ERROR_TEXT$1);
1678 }
1679 wait = toNumber_1(wait) || 0;
1680 if (isObject_1(options)) {
1681 leading = !!options.leading;
1682 maxing = "maxWait" in options;
1683 maxWait = maxing ? nativeMax(toNumber_1(options.maxWait) || 0, wait) : maxWait;
1684 trailing = "trailing" in options ? !!options.trailing : trailing;
1685 }
1686 function invokeFunc(time) {
1687 var args = lastArgs, thisArg = lastThis;
1688 lastArgs = lastThis = void 0;
1689 lastInvokeTime = time;
1690 result = func.apply(thisArg, args);
1691 return result;
1692 }
1693 function leadingEdge(time) {
1694 lastInvokeTime = time;
1695 timerId = setTimeout(timerExpired, wait);
1696 return leading ? invokeFunc(time) : result;
1697 }
1698 function remainingWait(time) {
1699 var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
1700 return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
1701 }
1702 function shouldInvoke(time) {
1703 var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
1704 return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
1705 }
1706 function timerExpired() {
1707 var time = now_1();
1708 if (shouldInvoke(time)) {
1709 return trailingEdge(time);
1710 }
1711 timerId = setTimeout(timerExpired, remainingWait(time));
1712 }
1713 function trailingEdge(time) {
1714 timerId = void 0;
1715 if (trailing && lastArgs) {
1716 return invokeFunc(time);
1717 }
1718 lastArgs = lastThis = void 0;
1719 return result;
1720 }
1721 function cancel() {
1722 if (timerId !== void 0) {
1723 clearTimeout(timerId);
1724 }
1725 lastInvokeTime = 0;
1726 lastArgs = lastCallTime = lastThis = timerId = void 0;
1727 }
1728 function flush() {
1729 return timerId === void 0 ? result : trailingEdge(now_1());
1730 }
1731 function debounced() {
1732 var time = now_1(), isInvoking = shouldInvoke(time);
1733 lastArgs = arguments;
1734 lastThis = this;
1735 lastCallTime = time;
1736 if (isInvoking) {
1737 if (timerId === void 0) {
1738 return leadingEdge(lastCallTime);
1739 }
1740 if (maxing) {
1741 clearTimeout(timerId);
1742 timerId = setTimeout(timerExpired, wait);
1743 return invokeFunc(lastCallTime);
1744 }
1745 }
1746 if (timerId === void 0) {
1747 timerId = setTimeout(timerExpired, wait);
1748 }
1749 return result;
1750 }
1751 debounced.cancel = cancel;
1752 debounced.flush = flush;
1753 return debounced;
1754 }
1755 var debounce_1 = debounce;
1756 var performance = window$1 ? window$1.performance : null;
1757 var pnow = performance && performance.now ? function() {
1758 return performance.now();
1759 } : function() {
1760 return Date.now();
1761 };
1762 var raf = function() {
1763 if (window$1) {
1764 if (window$1.requestAnimationFrame) {
1765 return function(fn2) {
1766 window$1.requestAnimationFrame(fn2);
1767 };
1768 } else if (window$1.mozRequestAnimationFrame) {
1769 return function(fn2) {
1770 window$1.mozRequestAnimationFrame(fn2);
1771 };
1772 } else if (window$1.webkitRequestAnimationFrame) {
1773 return function(fn2) {
1774 window$1.webkitRequestAnimationFrame(fn2);
1775 };
1776 } else if (window$1.msRequestAnimationFrame) {
1777 return function(fn2) {
1778 window$1.msRequestAnimationFrame(fn2);
1779 };
1780 }
1781 }
1782 return function(fn2) {
1783 if (fn2) {
1784 setTimeout(function() {
1785 fn2(pnow());
1786 }, 1e3 / 60);
1787 }
1788 };
1789 }();
1790 var requestAnimationFrame2 = function requestAnimationFrame3(fn2) {
1791 return raf(fn2);
1792 };
1793 var performanceNow = pnow;
1794 var DEFAULT_HASH_SEED = 9261;
1795 var K = 65599;
1796 var DEFAULT_HASH_SEED_ALT = 5381;
1797 var hashIterableInts = function hashIterableInts2(iterator) {
1798 var seed = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : DEFAULT_HASH_SEED;
1799 var hash = seed;
1800 var entry;
1801 for (; ; ) {
1802 entry = iterator.next();
1803 if (entry.done) {
1804 break;
1805 }
1806 hash = hash * K + entry.value | 0;
1807 }
1808 return hash;
1809 };
1810 var hashInt = function hashInt2(num) {
1811 var seed = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : DEFAULT_HASH_SEED;
1812 return seed * K + num | 0;
1813 };
1814 var hashIntAlt = function hashIntAlt2(num) {
1815 var seed = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : DEFAULT_HASH_SEED_ALT;
1816 return (seed << 5) + seed + num | 0;
1817 };
1818 var combineHashes = function combineHashes2(hash1, hash2) {
1819 return hash1 * 2097152 + hash2;
1820 };
1821 var combineHashesArray = function combineHashesArray2(hashes) {
1822 return hashes[0] * 2097152 + hashes[1];
1823 };
1824 var hashArrays = function hashArrays2(hashes1, hashes2) {
1825 return [hashInt(hashes1[0], hashes2[0]), hashIntAlt(hashes1[1], hashes2[1])];
1826 };
1827 var hashIntsArray = function hashIntsArray2(ints, seed) {
1828 var entry = {
1829 value: 0,
1830 done: false
1831 };
1832 var i2 = 0;
1833 var length = ints.length;
1834 var iterator = {
1835 next: function next2() {
1836 if (i2 < length) {
1837 entry.value = ints[i2++];
1838 } else {
1839 entry.done = true;
1840 }
1841 return entry;
1842 }
1843 };
1844 return hashIterableInts(iterator, seed);
1845 };
1846 var hashString = function hashString2(str, seed) {
1847 var entry = {
1848 value: 0,
1849 done: false
1850 };
1851 var i2 = 0;
1852 var length = str.length;
1853 var iterator = {
1854 next: function next2() {
1855 if (i2 < length) {
1856 entry.value = str.charCodeAt(i2++);
1857 } else {
1858 entry.done = true;
1859 }
1860 return entry;
1861 }
1862 };
1863 return hashIterableInts(iterator, seed);
1864 };
1865 var hashStrings = function hashStrings2() {
1866 return hashStringsArray(arguments);
1867 };
1868 var hashStringsArray = function hashStringsArray2(strs) {
1869 var hash;
1870 for (var i2 = 0; i2 < strs.length; i2++) {
1871 var str = strs[i2];
1872 if (i2 === 0) {
1873 hash = hashString(str);
1874 } else {
1875 hash = hashString(str, hash);
1876 }
1877 }
1878 return hash;
1879 };
1880 var warningsEnabled = true;
1881 var warnSupported = console.warn != null;
1882 var traceSupported = console.trace != null;
1883 var MAX_INT$1 = Number.MAX_SAFE_INTEGER || 9007199254740991;
1884 var trueify = function trueify2() {
1885 return true;
1886 };
1887 var falsify = function falsify2() {
1888 return false;
1889 };
1890 var zeroify = function zeroify2() {
1891 return 0;
1892 };
1893 var noop$1 = function noop2() {
1894 };
1895 var error = function error2(msg) {
1896 throw new Error(msg);
1897 };
1898 var warnings = function warnings2(enabled) {
1899 if (enabled !== void 0) {
1900 warningsEnabled = !!enabled;
1901 } else {
1902 return warningsEnabled;
1903 }
1904 };
1905 var warn = function warn2(msg) {
1906 if (!warnings()) {
1907 return;
1908 }
1909 if (warnSupported) {
1910 console.warn(msg);
1911 } else {
1912 console.log(msg);
1913 if (traceSupported) {
1914 console.trace();
1915 }
1916 }
1917 };
1918 var clone = function clone2(obj) {
1919 return extend({}, obj);
1920 };
1921 var copy = function copy2(obj) {
1922 if (obj == null) {
1923 return obj;
1924 }
1925 if (array(obj)) {
1926 return obj.slice();
1927 } else if (plainObject(obj)) {
1928 return clone(obj);
1929 } else {
1930 return obj;
1931 }
1932 };
1933 var copyArray$1 = function copyArray2(arr) {
1934 return arr.slice();
1935 };
1936 var uuid = function uuid2(a, b) {
1937 for (
1938 // loop :)
1939 b = a = "";
1940 // b - result , a - numeric letiable
1941 a++ < 36;
1942 //
1943 b += a * 51 & 52 ? (
1944 // return a random number or 4
1945 (a ^ 15 ? (
1946 // generate a random number from 0 to 15
1947 8 ^ Math.random() * (a ^ 20 ? 16 : 4)
1948 ) : 4).toString(16)
1949 ) : "-"
1950 ) {
1951 }
1952 return b;
1953 };
1954 var _staticEmptyObject = {};
1955 var staticEmptyObject = function staticEmptyObject2() {
1956 return _staticEmptyObject;
1957 };
1958 var defaults$g = function defaults2(_defaults) {
1959 var keys = Object.keys(_defaults);
1960 return function(opts) {
1961 var filledOpts = {};
1962 for (var i2 = 0; i2 < keys.length; i2++) {
1963 var key = keys[i2];
1964 var optVal = opts == null ? void 0 : opts[key];
1965 filledOpts[key] = optVal === void 0 ? _defaults[key] : optVal;
1966 }
1967 return filledOpts;
1968 };
1969 };
1970 var removeFromArray = function removeFromArray2(arr, ele, oneCopy) {
1971 for (var i2 = arr.length - 1; i2 >= 0; i2--) {
1972 if (arr[i2] === ele) {
1973 arr.splice(i2, 1);
1974 if (oneCopy) {
1975 break;
1976 }
1977 }
1978 }
1979 };
1980 var clearArray = function clearArray2(arr) {
1981 arr.splice(0, arr.length);
1982 };
1983 var push = function push2(arr, otherArr) {
1984 for (var i2 = 0; i2 < otherArr.length; i2++) {
1985 var el = otherArr[i2];
1986 arr.push(el);
1987 }
1988 };
1989 var getPrefixedProperty = function getPrefixedProperty2(obj, propName, prefix) {
1990 if (prefix) {
1991 propName = prependCamel(prefix, propName);
1992 }
1993 return obj[propName];
1994 };
1995 var setPrefixedProperty = function setPrefixedProperty2(obj, propName, prefix, value) {
1996 if (prefix) {
1997 propName = prependCamel(prefix, propName);
1998 }
1999 obj[propName] = value;
2000 };
2001 var ObjectMap = /* @__PURE__ */ function() {
2002 function ObjectMap2() {
2003 _classCallCheck(this, ObjectMap2);
2004 this._obj = {};
2005 }
2006 _createClass(ObjectMap2, [{
2007 key: "set",
2008 value: function set2(key, val) {
2009 this._obj[key] = val;
2010 return this;
2011 }
2012 }, {
2013 key: "delete",
2014 value: function _delete(key) {
2015 this._obj[key] = void 0;
2016 return this;
2017 }
2018 }, {
2019 key: "clear",
2020 value: function clear2() {
2021 this._obj = {};
2022 }
2023 }, {
2024 key: "has",
2025 value: function has(key) {
2026 return this._obj[key] !== void 0;
2027 }
2028 }, {
2029 key: "get",
2030 value: function get2(key) {
2031 return this._obj[key];
2032 }
2033 }]);
2034 return ObjectMap2;
2035 }();
2036 var Map$2 = typeof Map !== "undefined" ? Map : ObjectMap;
2037 var undef = "undefined";
2038 var ObjectSet = /* @__PURE__ */ function() {
2039 function ObjectSet2(arrayOrObjectSet) {
2040 _classCallCheck(this, ObjectSet2);
2041 this._obj = /* @__PURE__ */ Object.create(null);
2042 this.size = 0;
2043 if (arrayOrObjectSet != null) {
2044 var arr;
2045 if (arrayOrObjectSet.instanceString != null && arrayOrObjectSet.instanceString() === this.instanceString()) {
2046 arr = arrayOrObjectSet.toArray();
2047 } else {
2048 arr = arrayOrObjectSet;
2049 }
2050 for (var i2 = 0; i2 < arr.length; i2++) {
2051 this.add(arr[i2]);
2052 }
2053 }
2054 }
2055 _createClass(ObjectSet2, [{
2056 key: "instanceString",
2057 value: function instanceString() {
2058 return "set";
2059 }
2060 }, {
2061 key: "add",
2062 value: function add(val) {
2063 var o = this._obj;
2064 if (o[val] !== 1) {
2065 o[val] = 1;
2066 this.size++;
2067 }
2068 }
2069 }, {
2070 key: "delete",
2071 value: function _delete(val) {
2072 var o = this._obj;
2073 if (o[val] === 1) {
2074 o[val] = 0;
2075 this.size--;
2076 }
2077 }
2078 }, {
2079 key: "clear",
2080 value: function clear2() {
2081 this._obj = /* @__PURE__ */ Object.create(null);
2082 }
2083 }, {
2084 key: "has",
2085 value: function has(val) {
2086 return this._obj[val] === 1;
2087 }
2088 }, {
2089 key: "toArray",
2090 value: function toArray() {
2091 var _this = this;
2092 return Object.keys(this._obj).filter(function(key) {
2093 return _this.has(key);
2094 });
2095 }
2096 }, {
2097 key: "forEach",
2098 value: function forEach(callback, thisArg) {
2099 return this.toArray().forEach(callback, thisArg);
2100 }
2101 }]);
2102 return ObjectSet2;
2103 }();
2104 var Set$1 = (typeof Set === "undefined" ? "undefined" : _typeof(Set)) !== undef ? Set : ObjectSet;
2105 var Element = function Element2(cy, params) {
2106 var restore = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
2107 if (cy === void 0 || params === void 0 || !core(cy)) {
2108 error("An element must have a core reference and parameters set");
2109 return;
2110 }
2111 var group = params.group;
2112 if (group == null) {
2113 if (params.data && params.data.source != null && params.data.target != null) {
2114 group = "edges";
2115 } else {
2116 group = "nodes";
2117 }
2118 }
2119 if (group !== "nodes" && group !== "edges") {
2120 error("An element must be of type `nodes` or `edges`; you specified `" + group + "`");
2121 return;
2122 }
2123 this.length = 1;
2124 this[0] = this;
2125 var _p = this._private = {
2126 cy,
2127 single: true,
2128 // indicates this is an element
2129 data: params.data || {},
2130 // data object
2131 position: params.position || {
2132 x: 0,
2133 y: 0
2134 },
2135 // (x, y) position pair
2136 autoWidth: void 0,
2137 // width and height of nodes calculated by the renderer when set to special 'auto' value
2138 autoHeight: void 0,
2139 autoPadding: void 0,
2140 compoundBoundsClean: false,
2141 // whether the compound dimensions need to be recalculated the next time dimensions are read
2142 listeners: [],
2143 // array of bound listeners
2144 group,
2145 // string; 'nodes' or 'edges'
2146 style: {},
2147 // properties as set by the style
2148 rstyle: {},
2149 // properties for style sent from the renderer to the core
2150 styleCxts: [],
2151 // applied style contexts from the styler
2152 styleKeys: {},
2153 // per-group keys of style property values
2154 removed: true,
2155 // whether it's inside the vis; true if removed (set true here since we call restore)
2156 selected: params.selected ? true : false,
2157 // whether it's selected
2158 selectable: params.selectable === void 0 ? true : params.selectable ? true : false,
2159 // whether it's selectable
2160 locked: params.locked ? true : false,
2161 // whether the element is locked (cannot be moved)
2162 grabbed: false,
2163 // whether the element is grabbed by the mouse; renderer sets this privately
2164 grabbable: params.grabbable === void 0 ? true : params.grabbable ? true : false,
2165 // whether the element can be grabbed
2166 pannable: params.pannable === void 0 ? group === "edges" ? true : false : params.pannable ? true : false,
2167 // whether the element has passthrough panning enabled
2168 active: false,
2169 // whether the element is active from user interaction
2170 classes: new Set$1(),
2171 // map ( className => true )
2172 animation: {
2173 // object for currently-running animations
2174 current: [],
2175 queue: []
2176 },
2177 rscratch: {},
2178 // object in which the renderer can store information
2179 scratch: params.scratch || {},
2180 // scratch objects
2181 edges: [],
2182 // array of connected edges
2183 children: [],
2184 // array of children
2185 parent: params.parent && params.parent.isNode() ? params.parent : null,
2186 // parent ref
2187 traversalCache: {},
2188 // cache of output of traversal functions
2189 backgrounding: false,
2190 // whether background images are loading
2191 bbCache: null,
2192 // cache of the current bounding box
2193 bbCacheShift: {
2194 x: 0,
2195 y: 0
2196 },
2197 // shift applied to cached bb to be applied on next get
2198 bodyBounds: null,
2199 // bounds cache of element body, w/o overlay
2200 overlayBounds: null,
2201 // bounds cache of element body, including overlay
2202 labelBounds: {
2203 // bounds cache of labels
2204 all: null,
2205 source: null,
2206 target: null,
2207 main: null
2208 },
2209 arrowBounds: {
2210 // bounds cache of edge arrows
2211 source: null,
2212 target: null,
2213 "mid-source": null,
2214 "mid-target": null
2215 }
2216 };
2217 if (_p.position.x == null) {
2218 _p.position.x = 0;
2219 }
2220 if (_p.position.y == null) {
2221 _p.position.y = 0;
2222 }
2223 if (params.renderedPosition) {
2224 var rpos = params.renderedPosition;
2225 var pan = cy.pan();
2226 var zoom = cy.zoom();
2227 _p.position = {
2228 x: (rpos.x - pan.x) / zoom,
2229 y: (rpos.y - pan.y) / zoom
2230 };
2231 }
2232 var classes = [];
2233 if (array(params.classes)) {
2234 classes = params.classes;
2235 } else if (string(params.classes)) {
2236 classes = params.classes.split(/\s+/);
2237 }
2238 for (var i2 = 0, l = classes.length; i2 < l; i2++) {
2239 var cls = classes[i2];
2240 if (!cls || cls === "") {
2241 continue;
2242 }
2243 _p.classes.add(cls);
2244 }
2245 this.createEmitter();
2246 var bypass = params.style || params.css;
2247 if (bypass) {
2248 warn("Setting a `style` bypass at element creation should be done only when absolutely necessary. Try to use the stylesheet instead.");
2249 this.style(bypass);
2250 }
2251 if (restore === void 0 || restore) {
2252 this.restore();
2253 }
2254 };
2255 var defineSearch = function defineSearch2(params) {
2256 params = {
2257 bfs: params.bfs || !params.dfs,
2258 dfs: params.dfs || !params.bfs
2259 };
2260 return function searchFn(roots, fn2, directed) {
2261 var options;
2262 if (plainObject(roots) && !elementOrCollection(roots)) {
2263 options = roots;
2264 roots = options.roots || options.root;
2265 fn2 = options.visit;
2266 directed = options.directed;
2267 }
2268 directed = arguments.length === 2 && !fn$6(fn2) ? fn2 : directed;
2269 fn2 = fn$6(fn2) ? fn2 : function() {
2270 };
2271 var cy = this._private.cy;
2272 var v = roots = string(roots) ? this.filter(roots) : roots;
2273 var Q = [];
2274 var connectedNodes = [];
2275 var connectedBy = {};
2276 var id2depth = {};
2277 var V = {};
2278 var j = 0;
2279 var found;
2280 var _this$byGroup = this.byGroup(), nodes2 = _this$byGroup.nodes, edges = _this$byGroup.edges;
2281 for (var i2 = 0; i2 < v.length; i2++) {
2282 var vi = v[i2];
2283 var viId = vi.id();
2284 if (vi.isNode()) {
2285 Q.unshift(vi);
2286 if (params.bfs) {
2287 V[viId] = true;
2288 connectedNodes.push(vi);
2289 }
2290 id2depth[viId] = 0;
2291 }
2292 }
2293 var _loop = function _loop2() {
2294 var v2 = params.bfs ? Q.shift() : Q.pop();
2295 var vId = v2.id();
2296 if (params.dfs) {
2297 if (V[vId]) {
2298 return "continue";
2299 }
2300 V[vId] = true;
2301 connectedNodes.push(v2);
2302 }
2303 var depth = id2depth[vId];
2304 var prevEdge = connectedBy[vId];
2305 var src = prevEdge != null ? prevEdge.source() : null;
2306 var tgt = prevEdge != null ? prevEdge.target() : null;
2307 var prevNode = prevEdge == null ? void 0 : v2.same(src) ? tgt[0] : src[0];
2308 var ret = void 0;
2309 ret = fn2(v2, prevEdge, prevNode, j++, depth);
2310 if (ret === true) {
2311 found = v2;
2312 return "break";
2313 }
2314 if (ret === false) {
2315 return "break";
2316 }
2317 var vwEdges = v2.connectedEdges().filter(function(e2) {
2318 return (!directed || e2.source().same(v2)) && edges.has(e2);
2319 });
2320 for (var _i2 = 0; _i2 < vwEdges.length; _i2++) {
2321 var e = vwEdges[_i2];
2322 var w = e.connectedNodes().filter(function(n) {
2323 return !n.same(v2) && nodes2.has(n);
2324 });
2325 var wId = w.id();
2326 if (w.length !== 0 && !V[wId]) {
2327 w = w[0];
2328 Q.push(w);
2329 if (params.bfs) {
2330 V[wId] = true;
2331 connectedNodes.push(w);
2332 }
2333 connectedBy[wId] = e;
2334 id2depth[wId] = id2depth[vId] + 1;
2335 }
2336 }
2337 };
2338 while (Q.length !== 0) {
2339 var _ret = _loop();
2340 if (_ret === "continue")
2341 continue;
2342 if (_ret === "break")
2343 break;
2344 }
2345 var connectedEles = cy.collection();
2346 for (var _i = 0; _i < connectedNodes.length; _i++) {
2347 var node = connectedNodes[_i];
2348 var edge = connectedBy[node.id()];
2349 if (edge != null) {
2350 connectedEles.push(edge);
2351 }
2352 connectedEles.push(node);
2353 }
2354 return {
2355 path: cy.collection(connectedEles),
2356 found: cy.collection(found)
2357 };
2358 };
2359 };
2360 var elesfn$v = {
2361 breadthFirstSearch: defineSearch({
2362 bfs: true
2363 }),
2364 depthFirstSearch: defineSearch({
2365 dfs: true
2366 })
2367 };
2368 elesfn$v.bfs = elesfn$v.breadthFirstSearch;
2369 elesfn$v.dfs = elesfn$v.depthFirstSearch;
2370 var heap$1 = createCommonjsModule(function(module2, exports2) {
2371 (function() {
2372 var Heap, defaultCmp, floor, heapify, heappop, heappush, heappushpop, heapreplace, insort, min2, nlargest, nsmallest, updateItem, _siftdown, _siftup;
2373 floor = Math.floor, min2 = Math.min;
2374 defaultCmp = function(x, y) {
2375 if (x < y) {
2376 return -1;
2377 }
2378 if (x > y) {
2379 return 1;
2380 }
2381 return 0;
2382 };
2383 insort = function(a, x, lo, hi, cmp) {
2384 var mid;
2385 if (lo == null) {
2386 lo = 0;
2387 }
2388 if (cmp == null) {
2389 cmp = defaultCmp;
2390 }
2391 if (lo < 0) {
2392 throw new Error("lo must be non-negative");
2393 }
2394 if (hi == null) {
2395 hi = a.length;
2396 }
2397 while (lo < hi) {
2398 mid = floor((lo + hi) / 2);
2399 if (cmp(x, a[mid]) < 0) {
2400 hi = mid;
2401 } else {
2402 lo = mid + 1;
2403 }
2404 }
2405 return [].splice.apply(a, [lo, lo - lo].concat(x)), x;
2406 };
2407 heappush = function(array2, item, cmp) {
2408 if (cmp == null) {
2409 cmp = defaultCmp;
2410 }
2411 array2.push(item);
2412 return _siftdown(array2, 0, array2.length - 1, cmp);
2413 };
2414 heappop = function(array2, cmp) {
2415 var lastelt, returnitem;
2416 if (cmp == null) {
2417 cmp = defaultCmp;
2418 }
2419 lastelt = array2.pop();
2420 if (array2.length) {
2421 returnitem = array2[0];
2422 array2[0] = lastelt;
2423 _siftup(array2, 0, cmp);
2424 } else {
2425 returnitem = lastelt;
2426 }
2427 return returnitem;
2428 };
2429 heapreplace = function(array2, item, cmp) {
2430 var returnitem;
2431 if (cmp == null) {
2432 cmp = defaultCmp;
2433 }
2434 returnitem = array2[0];
2435 array2[0] = item;
2436 _siftup(array2, 0, cmp);
2437 return returnitem;
2438 };
2439 heappushpop = function(array2, item, cmp) {
2440 var _ref;
2441 if (cmp == null) {
2442 cmp = defaultCmp;
2443 }
2444 if (array2.length && cmp(array2[0], item) < 0) {
2445 _ref = [array2[0], item], item = _ref[0], array2[0] = _ref[1];
2446 _siftup(array2, 0, cmp);
2447 }
2448 return item;
2449 };
2450 heapify = function(array2, cmp) {
2451 var i2, _i, _len, _ref1, _results, _results1;
2452 if (cmp == null) {
2453 cmp = defaultCmp;
2454 }
2455 _ref1 = function() {
2456 _results1 = [];
2457 for (var _j = 0, _ref = floor(array2.length / 2); 0 <= _ref ? _j < _ref : _j > _ref; 0 <= _ref ? _j++ : _j--) {
2458 _results1.push(_j);
2459 }
2460 return _results1;
2461 }.apply(this).reverse();
2462 _results = [];
2463 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
2464 i2 = _ref1[_i];
2465 _results.push(_siftup(array2, i2, cmp));
2466 }
2467 return _results;
2468 };
2469 updateItem = function(array2, item, cmp) {
2470 var pos;
2471 if (cmp == null) {
2472 cmp = defaultCmp;
2473 }
2474 pos = array2.indexOf(item);
2475 if (pos === -1) {
2476 return;
2477 }
2478 _siftdown(array2, 0, pos, cmp);
2479 return _siftup(array2, pos, cmp);
2480 };
2481 nlargest = function(array2, n, cmp) {
2482 var elem, result, _i, _len, _ref;
2483 if (cmp == null) {
2484 cmp = defaultCmp;
2485 }
2486 result = array2.slice(0, n);
2487 if (!result.length) {
2488 return result;
2489 }
2490 heapify(result, cmp);
2491 _ref = array2.slice(n);
2492 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2493 elem = _ref[_i];
2494 heappushpop(result, elem, cmp);
2495 }
2496 return result.sort(cmp).reverse();
2497 };
2498 nsmallest = function(array2, n, cmp) {
2499 var elem, los, result, _i, _j, _len, _ref, _ref1, _results;
2500 if (cmp == null) {
2501 cmp = defaultCmp;
2502 }
2503 if (n * 10 <= array2.length) {
2504 result = array2.slice(0, n).sort(cmp);
2505 if (!result.length) {
2506 return result;
2507 }
2508 los = result[result.length - 1];
2509 _ref = array2.slice(n);
2510 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2511 elem = _ref[_i];
2512 if (cmp(elem, los) < 0) {
2513 insort(result, elem, 0, null, cmp);
2514 result.pop();
2515 los = result[result.length - 1];
2516 }
2517 }
2518 return result;
2519 }
2520 heapify(array2, cmp);
2521 _results = [];
2522 for (_j = 0, _ref1 = min2(n, array2.length); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; 0 <= _ref1 ? ++_j : --_j) {
2523 _results.push(heappop(array2, cmp));
2524 }
2525 return _results;
2526 };
2527 _siftdown = function(array2, startpos, pos, cmp) {
2528 var newitem, parent, parentpos;
2529 if (cmp == null) {
2530 cmp = defaultCmp;
2531 }
2532 newitem = array2[pos];
2533 while (pos > startpos) {
2534 parentpos = pos - 1 >> 1;
2535 parent = array2[parentpos];
2536 if (cmp(newitem, parent) < 0) {
2537 array2[pos] = parent;
2538 pos = parentpos;
2539 continue;
2540 }
2541 break;
2542 }
2543 return array2[pos] = newitem;
2544 };
2545 _siftup = function(array2, pos, cmp) {
2546 var childpos, endpos, newitem, rightpos, startpos;
2547 if (cmp == null) {
2548 cmp = defaultCmp;
2549 }
2550 endpos = array2.length;
2551 startpos = pos;
2552 newitem = array2[pos];
2553 childpos = 2 * pos + 1;
2554 while (childpos < endpos) {
2555 rightpos = childpos + 1;
2556 if (rightpos < endpos && !(cmp(array2[childpos], array2[rightpos]) < 0)) {
2557 childpos = rightpos;
2558 }
2559 array2[pos] = array2[childpos];
2560 pos = childpos;
2561 childpos = 2 * pos + 1;
2562 }
2563 array2[pos] = newitem;
2564 return _siftdown(array2, startpos, pos, cmp);
2565 };
2566 Heap = function() {
2567 Heap2.push = heappush;
2568 Heap2.pop = heappop;
2569 Heap2.replace = heapreplace;
2570 Heap2.pushpop = heappushpop;
2571 Heap2.heapify = heapify;
2572 Heap2.updateItem = updateItem;
2573 Heap2.nlargest = nlargest;
2574 Heap2.nsmallest = nsmallest;
2575 function Heap2(cmp) {
2576 this.cmp = cmp != null ? cmp : defaultCmp;
2577 this.nodes = [];
2578 }
2579 Heap2.prototype.push = function(x) {
2580 return heappush(this.nodes, x, this.cmp);
2581 };
2582 Heap2.prototype.pop = function() {
2583 return heappop(this.nodes, this.cmp);
2584 };
2585 Heap2.prototype.peek = function() {
2586 return this.nodes[0];
2587 };
2588 Heap2.prototype.contains = function(x) {
2589 return this.nodes.indexOf(x) !== -1;
2590 };
2591 Heap2.prototype.replace = function(x) {
2592 return heapreplace(this.nodes, x, this.cmp);
2593 };
2594 Heap2.prototype.pushpop = function(x) {
2595 return heappushpop(this.nodes, x, this.cmp);
2596 };
2597 Heap2.prototype.heapify = function() {
2598 return heapify(this.nodes, this.cmp);
2599 };
2600 Heap2.prototype.updateItem = function(x) {
2601 return updateItem(this.nodes, x, this.cmp);
2602 };
2603 Heap2.prototype.clear = function() {
2604 return this.nodes = [];
2605 };
2606 Heap2.prototype.empty = function() {
2607 return this.nodes.length === 0;
2608 };
2609 Heap2.prototype.size = function() {
2610 return this.nodes.length;
2611 };
2612 Heap2.prototype.clone = function() {
2613 var heap2;
2614 heap2 = new Heap2();
2615 heap2.nodes = this.nodes.slice(0);
2616 return heap2;
2617 };
2618 Heap2.prototype.toArray = function() {
2619 return this.nodes.slice(0);
2620 };
2621 Heap2.prototype.insert = Heap2.prototype.push;
2622 Heap2.prototype.top = Heap2.prototype.peek;
2623 Heap2.prototype.front = Heap2.prototype.peek;
2624 Heap2.prototype.has = Heap2.prototype.contains;
2625 Heap2.prototype.copy = Heap2.prototype.clone;
2626 return Heap2;
2627 }();
2628 (function(root2, factory) {
2629 {
2630 return module2.exports = factory();
2631 }
2632 })(this, function() {
2633 return Heap;
2634 });
2635 }).call(commonjsGlobal$1);
2636 });
2637 var heap = heap$1;
2638 var dijkstraDefaults = defaults$g({
2639 root: null,
2640 weight: function weight(edge) {
2641 return 1;
2642 },
2643 directed: false
2644 });
2645 var elesfn$u = {
2646 dijkstra: function dijkstra(options) {
2647 if (!plainObject(options)) {
2648 var args = arguments;
2649 options = {
2650 root: args[0],
2651 weight: args[1],
2652 directed: args[2]
2653 };
2654 }
2655 var _dijkstraDefaults = dijkstraDefaults(options), root2 = _dijkstraDefaults.root, weight = _dijkstraDefaults.weight, directed = _dijkstraDefaults.directed;
2656 var eles = this;
2657 var weightFn = weight;
2658 var source = string(root2) ? this.filter(root2)[0] : root2[0];
2659 var dist2 = {};
2660 var prev = {};
2661 var knownDist = {};
2662 var _this$byGroup = this.byGroup(), nodes2 = _this$byGroup.nodes, edges = _this$byGroup.edges;
2663 edges.unmergeBy(function(ele) {
2664 return ele.isLoop();
2665 });
2666 var getDist2 = function getDist3(node2) {
2667 return dist2[node2.id()];
2668 };
2669 var setDist = function setDist2(node2, d) {
2670 dist2[node2.id()] = d;
2671 Q.updateItem(node2);
2672 };
2673 var Q = new heap(function(a, b) {
2674 return getDist2(a) - getDist2(b);
2675 });
2676 for (var i2 = 0; i2 < nodes2.length; i2++) {
2677 var node = nodes2[i2];
2678 dist2[node.id()] = node.same(source) ? 0 : Infinity;
2679 Q.push(node);
2680 }
2681 var distBetween = function distBetween2(u2, v2) {
2682 var uvs = (directed ? u2.edgesTo(v2) : u2.edgesWith(v2)).intersect(edges);
2683 var smallestDistance = Infinity;
2684 var smallestEdge;
2685 for (var _i = 0; _i < uvs.length; _i++) {
2686 var edge = uvs[_i];
2687 var _weight = weightFn(edge);
2688 if (_weight < smallestDistance || !smallestEdge) {
2689 smallestDistance = _weight;
2690 smallestEdge = edge;
2691 }
2692 }
2693 return {
2694 edge: smallestEdge,
2695 dist: smallestDistance
2696 };
2697 };
2698 while (Q.size() > 0) {
2699 var u = Q.pop();
2700 var smalletsDist = getDist2(u);
2701 var uid = u.id();
2702 knownDist[uid] = smalletsDist;
2703 if (smalletsDist === Infinity) {
2704 continue;
2705 }
2706 var neighbors = u.neighborhood().intersect(nodes2);
2707 for (var _i2 = 0; _i2 < neighbors.length; _i2++) {
2708 var v = neighbors[_i2];
2709 var vid = v.id();
2710 var vDist = distBetween(u, v);
2711 var alt = smalletsDist + vDist.dist;
2712 if (alt < getDist2(v)) {
2713 setDist(v, alt);
2714 prev[vid] = {
2715 node: u,
2716 edge: vDist.edge
2717 };
2718 }
2719 }
2720 }
2721 return {
2722 distanceTo: function distanceTo(node2) {
2723 var target = string(node2) ? nodes2.filter(node2)[0] : node2[0];
2724 return knownDist[target.id()];
2725 },
2726 pathTo: function pathTo(node2) {
2727 var target = string(node2) ? nodes2.filter(node2)[0] : node2[0];
2728 var S = [];
2729 var u2 = target;
2730 var uid2 = u2.id();
2731 if (target.length > 0) {
2732 S.unshift(target);
2733 while (prev[uid2]) {
2734 var p2 = prev[uid2];
2735 S.unshift(p2.edge);
2736 S.unshift(p2.node);
2737 u2 = p2.node;
2738 uid2 = u2.id();
2739 }
2740 }
2741 return eles.spawn(S);
2742 }
2743 };
2744 }
2745 };
2746 var elesfn$t = {
2747 // kruskal's algorithm (finds min spanning tree, assuming undirected graph)
2748 // implemented from pseudocode from wikipedia
2749 kruskal: function kruskal(weightFn) {
2750 weightFn = weightFn || function(edge2) {
2751 return 1;
2752 };
2753 var _this$byGroup = this.byGroup(), nodes2 = _this$byGroup.nodes, edges = _this$byGroup.edges;
2754 var numNodes = nodes2.length;
2755 var forest = new Array(numNodes);
2756 var A = nodes2;
2757 var findSetIndex = function findSetIndex2(ele) {
2758 for (var i3 = 0; i3 < forest.length; i3++) {
2759 var eles = forest[i3];
2760 if (eles.has(ele)) {
2761 return i3;
2762 }
2763 }
2764 };
2765 for (var i2 = 0; i2 < numNodes; i2++) {
2766 forest[i2] = this.spawn(nodes2[i2]);
2767 }
2768 var S = edges.sort(function(a, b) {
2769 return weightFn(a) - weightFn(b);
2770 });
2771 for (var _i = 0; _i < S.length; _i++) {
2772 var edge = S[_i];
2773 var u = edge.source()[0];
2774 var v = edge.target()[0];
2775 var setUIndex = findSetIndex(u);
2776 var setVIndex = findSetIndex(v);
2777 var setU = forest[setUIndex];
2778 var setV = forest[setVIndex];
2779 if (setUIndex !== setVIndex) {
2780 A.merge(edge);
2781 setU.merge(setV);
2782 forest.splice(setVIndex, 1);
2783 }
2784 }
2785 return A;
2786 }
2787 };
2788 var aStarDefaults = defaults$g({
2789 root: null,
2790 goal: null,
2791 weight: function weight(edge) {
2792 return 1;
2793 },
2794 heuristic: function heuristic(edge) {
2795 return 0;
2796 },
2797 directed: false
2798 });
2799 var elesfn$s = {
2800 // Implemented from pseudocode from wikipedia
2801 aStar: function aStar(options) {
2802 var cy = this.cy();
2803 var _aStarDefaults = aStarDefaults(options), root2 = _aStarDefaults.root, goal = _aStarDefaults.goal, heuristic = _aStarDefaults.heuristic, directed = _aStarDefaults.directed, weight = _aStarDefaults.weight;
2804 root2 = cy.collection(root2)[0];
2805 goal = cy.collection(goal)[0];
2806 var sid = root2.id();
2807 var tid = goal.id();
2808 var gScore = {};
2809 var fScore = {};
2810 var closedSetIds = {};
2811 var openSet = new heap(function(a, b) {
2812 return fScore[a.id()] - fScore[b.id()];
2813 });
2814 var openSetIds = new Set$1();
2815 var cameFrom = {};
2816 var cameFromEdge = {};
2817 var addToOpenSet = function addToOpenSet2(ele, id) {
2818 openSet.push(ele);
2819 openSetIds.add(id);
2820 };
2821 var cMin, cMinId;
2822 var popFromOpenSet = function popFromOpenSet2() {
2823 cMin = openSet.pop();
2824 cMinId = cMin.id();
2825 openSetIds["delete"](cMinId);
2826 };
2827 var isInOpenSet = function isInOpenSet2(id) {
2828 return openSetIds.has(id);
2829 };
2830 addToOpenSet(root2, sid);
2831 gScore[sid] = 0;
2832 fScore[sid] = heuristic(root2);
2833 var steps = 0;
2834 while (openSet.size() > 0) {
2835 popFromOpenSet();
2836 steps++;
2837 if (cMinId === tid) {
2838 var path = [];
2839 var pathNode = goal;
2840 var pathNodeId = tid;
2841 var pathEdge = cameFromEdge[pathNodeId];
2842 for (; ; ) {
2843 path.unshift(pathNode);
2844 if (pathEdge != null) {
2845 path.unshift(pathEdge);
2846 }
2847 pathNode = cameFrom[pathNodeId];
2848 if (pathNode == null) {
2849 break;
2850 }
2851 pathNodeId = pathNode.id();
2852 pathEdge = cameFromEdge[pathNodeId];
2853 }
2854 return {
2855 found: true,
2856 distance: gScore[cMinId],
2857 path: this.spawn(path),
2858 steps
2859 };
2860 }
2861 closedSetIds[cMinId] = true;
2862 var vwEdges = cMin._private.edges;
2863 for (var i2 = 0; i2 < vwEdges.length; i2++) {
2864 var e = vwEdges[i2];
2865 if (!this.hasElementWithId(e.id())) {
2866 continue;
2867 }
2868 if (directed && e.data("source") !== cMinId) {
2869 continue;
2870 }
2871 var wSrc = e.source();
2872 var wTgt = e.target();
2873 var w = wSrc.id() !== cMinId ? wSrc : wTgt;
2874 var wid = w.id();
2875 if (!this.hasElementWithId(wid)) {
2876 continue;
2877 }
2878 if (closedSetIds[wid]) {
2879 continue;
2880 }
2881 var tempScore = gScore[cMinId] + weight(e);
2882 if (!isInOpenSet(wid)) {
2883 gScore[wid] = tempScore;
2884 fScore[wid] = tempScore + heuristic(w);
2885 addToOpenSet(w, wid);
2886 cameFrom[wid] = cMin;
2887 cameFromEdge[wid] = e;
2888 continue;
2889 }
2890 if (tempScore < gScore[wid]) {
2891 gScore[wid] = tempScore;
2892 fScore[wid] = tempScore + heuristic(w);
2893 cameFrom[wid] = cMin;
2894 cameFromEdge[wid] = e;
2895 }
2896 }
2897 }
2898 return {
2899 found: false,
2900 distance: void 0,
2901 path: void 0,
2902 steps
2903 };
2904 }
2905 };
2906 var floydWarshallDefaults = defaults$g({
2907 weight: function weight(edge) {
2908 return 1;
2909 },
2910 directed: false
2911 });
2912 var elesfn$r = {
2913 // Implemented from pseudocode from wikipedia
2914 floydWarshall: function floydWarshall(options) {
2915 var cy = this.cy();
2916 var _floydWarshallDefault = floydWarshallDefaults(options), weight = _floydWarshallDefault.weight, directed = _floydWarshallDefault.directed;
2917 var weightFn = weight;
2918 var _this$byGroup = this.byGroup(), nodes2 = _this$byGroup.nodes, edges = _this$byGroup.edges;
2919 var N = nodes2.length;
2920 var Nsq = N * N;
2921 var indexOf = function indexOf2(node) {
2922 return nodes2.indexOf(node);
2923 };
2924 var atIndex = function atIndex2(i3) {
2925 return nodes2[i3];
2926 };
2927 var dist2 = new Array(Nsq);
2928 for (var n = 0; n < Nsq; n++) {
2929 var j = n % N;
2930 var i2 = (n - j) / N;
2931 if (i2 === j) {
2932 dist2[n] = 0;
2933 } else {
2934 dist2[n] = Infinity;
2935 }
2936 }
2937 var next2 = new Array(Nsq);
2938 var edgeNext = new Array(Nsq);
2939 for (var _i = 0; _i < edges.length; _i++) {
2940 var edge = edges[_i];
2941 var src = edge.source()[0];
2942 var tgt = edge.target()[0];
2943 if (src === tgt) {
2944 continue;
2945 }
2946 var s = indexOf(src);
2947 var t = indexOf(tgt);
2948 var st = s * N + t;
2949 var _weight = weightFn(edge);
2950 if (dist2[st] > _weight) {
2951 dist2[st] = _weight;
2952 next2[st] = t;
2953 edgeNext[st] = edge;
2954 }
2955 if (!directed) {
2956 var ts = t * N + s;
2957 if (!directed && dist2[ts] > _weight) {
2958 dist2[ts] = _weight;
2959 next2[ts] = s;
2960 edgeNext[ts] = edge;
2961 }
2962 }
2963 }
2964 for (var k = 0; k < N; k++) {
2965 for (var _i2 = 0; _i2 < N; _i2++) {
2966 var ik = _i2 * N + k;
2967 for (var _j = 0; _j < N; _j++) {
2968 var ij = _i2 * N + _j;
2969 var kj = k * N + _j;
2970 if (dist2[ik] + dist2[kj] < dist2[ij]) {
2971 dist2[ij] = dist2[ik] + dist2[kj];
2972 next2[ij] = next2[ik];
2973 }
2974 }
2975 }
2976 }
2977 var getArgEle = function getArgEle2(ele) {
2978 return (string(ele) ? cy.filter(ele) : ele)[0];
2979 };
2980 var indexOfArgEle = function indexOfArgEle2(ele) {
2981 return indexOf(getArgEle(ele));
2982 };
2983 var res = {
2984 distance: function distance(from, to) {
2985 var i3 = indexOfArgEle(from);
2986 var j2 = indexOfArgEle(to);
2987 return dist2[i3 * N + j2];
2988 },
2989 path: function path(from, to) {
2990 var i3 = indexOfArgEle(from);
2991 var j2 = indexOfArgEle(to);
2992 var fromNode = atIndex(i3);
2993 if (i3 === j2) {
2994 return fromNode.collection();
2995 }
2996 if (next2[i3 * N + j2] == null) {
2997 return cy.collection();
2998 }
2999 var path2 = cy.collection();
3000 var prev = i3;
3001 var edge2;
3002 path2.merge(fromNode);
3003 while (i3 !== j2) {
3004 prev = i3;
3005 i3 = next2[i3 * N + j2];
3006 edge2 = edgeNext[prev * N + i3];
3007 path2.merge(edge2);
3008 path2.merge(atIndex(i3));
3009 }
3010 return path2;
3011 }
3012 };
3013 return res;
3014 }
3015 // floydWarshall
3016 };
3017 var bellmanFordDefaults = defaults$g({
3018 weight: function weight(edge) {
3019 return 1;
3020 },
3021 directed: false,
3022 root: null
3023 });
3024 var elesfn$q = {
3025 // Implemented from pseudocode from wikipedia
3026 bellmanFord: function bellmanFord(options) {
3027 var _this = this;
3028 var _bellmanFordDefaults = bellmanFordDefaults(options), weight = _bellmanFordDefaults.weight, directed = _bellmanFordDefaults.directed, root2 = _bellmanFordDefaults.root;
3029 var weightFn = weight;
3030 var eles = this;
3031 var cy = this.cy();
3032 var _this$byGroup = this.byGroup(), edges = _this$byGroup.edges, nodes2 = _this$byGroup.nodes;
3033 var numNodes = nodes2.length;
3034 var infoMap = new Map$2();
3035 var hasNegativeWeightCycle = false;
3036 var negativeWeightCycles = [];
3037 root2 = cy.collection(root2)[0];
3038 edges.unmergeBy(function(edge2) {
3039 return edge2.isLoop();
3040 });
3041 var numEdges = edges.length;
3042 var getInfo2 = function getInfo3(node2) {
3043 var obj = infoMap.get(node2.id());
3044 if (!obj) {
3045 obj = {};
3046 infoMap.set(node2.id(), obj);
3047 }
3048 return obj;
3049 };
3050 var getNodeFromTo = function getNodeFromTo2(to) {
3051 return (string(to) ? cy.$(to) : to)[0];
3052 };
3053 var distanceTo = function distanceTo2(to) {
3054 return getInfo2(getNodeFromTo(to)).dist;
3055 };
3056 var pathTo = function pathTo2(to) {
3057 var thisStart = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : root2;
3058 var end = getNodeFromTo(to);
3059 var path = [];
3060 var node2 = end;
3061 for (; ; ) {
3062 if (node2 == null) {
3063 return _this.spawn();
3064 }
3065 var _getInfo = getInfo2(node2), edge2 = _getInfo.edge, pred = _getInfo.pred;
3066 path.unshift(node2[0]);
3067 if (node2.same(thisStart) && path.length > 0) {
3068 break;
3069 }
3070 if (edge2 != null) {
3071 path.unshift(edge2);
3072 }
3073 node2 = pred;
3074 }
3075 return eles.spawn(path);
3076 };
3077 for (var i2 = 0; i2 < numNodes; i2++) {
3078 var node = nodes2[i2];
3079 var info = getInfo2(node);
3080 if (node.same(root2)) {
3081 info.dist = 0;
3082 } else {
3083 info.dist = Infinity;
3084 }
3085 info.pred = null;
3086 info.edge = null;
3087 }
3088 var replacedEdge = false;
3089 var checkForEdgeReplacement = function checkForEdgeReplacement2(node1, node2, edge2, info1, info2, weight2) {
3090 var dist2 = info1.dist + weight2;
3091 if (dist2 < info2.dist && !edge2.same(info1.edge)) {
3092 info2.dist = dist2;
3093 info2.pred = node1;
3094 info2.edge = edge2;
3095 replacedEdge = true;
3096 }
3097 };
3098 for (var _i = 1; _i < numNodes; _i++) {
3099 replacedEdge = false;
3100 for (var e = 0; e < numEdges; e++) {
3101 var edge = edges[e];
3102 var src = edge.source();
3103 var tgt = edge.target();
3104 var _weight = weightFn(edge);
3105 var srcInfo = getInfo2(src);
3106 var tgtInfo = getInfo2(tgt);
3107 checkForEdgeReplacement(src, tgt, edge, srcInfo, tgtInfo, _weight);
3108 if (!directed) {
3109 checkForEdgeReplacement(tgt, src, edge, tgtInfo, srcInfo, _weight);
3110 }
3111 }
3112 if (!replacedEdge) {
3113 break;
3114 }
3115 }
3116 if (replacedEdge) {
3117 var negativeWeightCycleIds = [];
3118 for (var _e = 0; _e < numEdges; _e++) {
3119 var _edge = edges[_e];
3120 var _src = _edge.source();
3121 var _tgt = _edge.target();
3122 var _weight2 = weightFn(_edge);
3123 var srcDist = getInfo2(_src).dist;
3124 var tgtDist = getInfo2(_tgt).dist;
3125 if (srcDist + _weight2 < tgtDist || !directed && tgtDist + _weight2 < srcDist) {
3126 if (!hasNegativeWeightCycle) {
3127 warn("Graph contains a negative weight cycle for Bellman-Ford");
3128 hasNegativeWeightCycle = true;
3129 }
3130 if (options.findNegativeWeightCycles !== false) {
3131 var negativeNodes = [];
3132 if (srcDist + _weight2 < tgtDist) {
3133 negativeNodes.push(_src);
3134 }
3135 if (!directed && tgtDist + _weight2 < srcDist) {
3136 negativeNodes.push(_tgt);
3137 }
3138 var numNegativeNodes = negativeNodes.length;
3139 for (var n = 0; n < numNegativeNodes; n++) {
3140 var start = negativeNodes[n];
3141 var cycle = [start];
3142 cycle.push(getInfo2(start).edge);
3143 var _node = getInfo2(start).pred;
3144 while (cycle.indexOf(_node) === -1) {
3145 cycle.push(_node);
3146 cycle.push(getInfo2(_node).edge);
3147 _node = getInfo2(_node).pred;
3148 }
3149 cycle = cycle.slice(cycle.indexOf(_node));
3150 var smallestId = cycle[0].id();
3151 var smallestIndex = 0;
3152 for (var c = 2; c < cycle.length; c += 2) {
3153 if (cycle[c].id() < smallestId) {
3154 smallestId = cycle[c].id();
3155 smallestIndex = c;
3156 }
3157 }
3158 cycle = cycle.slice(smallestIndex).concat(cycle.slice(0, smallestIndex));
3159 cycle.push(cycle[0]);
3160 var cycleId = cycle.map(function(el) {
3161 return el.id();
3162 }).join(",");
3163 if (negativeWeightCycleIds.indexOf(cycleId) === -1) {
3164 negativeWeightCycles.push(eles.spawn(cycle));
3165 negativeWeightCycleIds.push(cycleId);
3166 }
3167 }
3168 } else {
3169 break;
3170 }
3171 }
3172 }
3173 }
3174 return {
3175 distanceTo,
3176 pathTo,
3177 hasNegativeWeightCycle,
3178 negativeWeightCycles
3179 };
3180 }
3181 // bellmanFord
3182 };
3183 var sqrt2 = Math.sqrt(2);
3184 var collapse = function collapse2(edgeIndex, nodeMap, remainingEdges) {
3185 if (remainingEdges.length === 0) {
3186 error("Karger-Stein must be run on a connected (sub)graph");
3187 }
3188 var edgeInfo = remainingEdges[edgeIndex];
3189 var sourceIn = edgeInfo[1];
3190 var targetIn = edgeInfo[2];
3191 var partition1 = nodeMap[sourceIn];
3192 var partition2 = nodeMap[targetIn];
3193 var newEdges = remainingEdges;
3194 for (var i2 = newEdges.length - 1; i2 >= 0; i2--) {
3195 var edge = newEdges[i2];
3196 var src = edge[1];
3197 var tgt = edge[2];
3198 if (nodeMap[src] === partition1 && nodeMap[tgt] === partition2 || nodeMap[src] === partition2 && nodeMap[tgt] === partition1) {
3199 newEdges.splice(i2, 1);
3200 }
3201 }
3202 for (var _i = 0; _i < newEdges.length; _i++) {
3203 var _edge = newEdges[_i];
3204 if (_edge[1] === partition2) {
3205 newEdges[_i] = _edge.slice();
3206 newEdges[_i][1] = partition1;
3207 } else if (_edge[2] === partition2) {
3208 newEdges[_i] = _edge.slice();
3209 newEdges[_i][2] = partition1;
3210 }
3211 }
3212 for (var _i2 = 0; _i2 < nodeMap.length; _i2++) {
3213 if (nodeMap[_i2] === partition2) {
3214 nodeMap[_i2] = partition1;
3215 }
3216 }
3217 return newEdges;
3218 };
3219 var contractUntil = function contractUntil2(metaNodeMap, remainingEdges, size, sizeLimit) {
3220 while (size > sizeLimit) {
3221 var edgeIndex = Math.floor(Math.random() * remainingEdges.length);
3222 remainingEdges = collapse(edgeIndex, metaNodeMap, remainingEdges);
3223 size--;
3224 }
3225 return remainingEdges;
3226 };
3227 var elesfn$p = {
3228 // Computes the minimum cut of an undirected graph
3229 // Returns the correct answer with high probability
3230 kargerStein: function kargerStein() {
3231 var _this = this;
3232 var _this$byGroup = this.byGroup(), nodes2 = _this$byGroup.nodes, edges = _this$byGroup.edges;
3233 edges.unmergeBy(function(edge) {
3234 return edge.isLoop();
3235 });
3236 var numNodes = nodes2.length;
3237 var numEdges = edges.length;
3238 var numIter = Math.ceil(Math.pow(Math.log(numNodes) / Math.LN2, 2));
3239 var stopSize = Math.floor(numNodes / sqrt2);
3240 if (numNodes < 2) {
3241 error("At least 2 nodes are required for Karger-Stein algorithm");
3242 return void 0;
3243 }
3244 var edgeIndexes = [];
3245 for (var i2 = 0; i2 < numEdges; i2++) {
3246 var e = edges[i2];
3247 edgeIndexes.push([i2, nodes2.indexOf(e.source()), nodes2.indexOf(e.target())]);
3248 }
3249 var minCutSize = Infinity;
3250 var minCutEdgeIndexes = [];
3251 var minCutNodeMap = new Array(numNodes);
3252 var metaNodeMap = new Array(numNodes);
3253 var metaNodeMap2 = new Array(numNodes);
3254 var copyNodesMap = function copyNodesMap2(from, to) {
3255 for (var _i3 = 0; _i3 < numNodes; _i3++) {
3256 to[_i3] = from[_i3];
3257 }
3258 };
3259 for (var iter = 0; iter <= numIter; iter++) {
3260 for (var _i4 = 0; _i4 < numNodes; _i4++) {
3261 metaNodeMap[_i4] = _i4;
3262 }
3263 var edgesState = contractUntil(metaNodeMap, edgeIndexes.slice(), numNodes, stopSize);
3264 var edgesState2 = edgesState.slice();
3265 copyNodesMap(metaNodeMap, metaNodeMap2);
3266 var res1 = contractUntil(metaNodeMap, edgesState, stopSize, 2);
3267 var res2 = contractUntil(metaNodeMap2, edgesState2, stopSize, 2);
3268 if (res1.length <= res2.length && res1.length < minCutSize) {
3269 minCutSize = res1.length;
3270 minCutEdgeIndexes = res1;
3271 copyNodesMap(metaNodeMap, minCutNodeMap);
3272 } else if (res2.length <= res1.length && res2.length < minCutSize) {
3273 minCutSize = res2.length;
3274 minCutEdgeIndexes = res2;
3275 copyNodesMap(metaNodeMap2, minCutNodeMap);
3276 }
3277 }
3278 var cut = this.spawn(minCutEdgeIndexes.map(function(e2) {
3279 return edges[e2[0]];
3280 }));
3281 var partition1 = this.spawn();
3282 var partition2 = this.spawn();
3283 var witnessNodePartition = minCutNodeMap[0];
3284 for (var _i5 = 0; _i5 < minCutNodeMap.length; _i5++) {
3285 var partitionId = minCutNodeMap[_i5];
3286 var node = nodes2[_i5];
3287 if (partitionId === witnessNodePartition) {
3288 partition1.merge(node);
3289 } else {
3290 partition2.merge(node);
3291 }
3292 }
3293 var constructComponent = function constructComponent2(subset) {
3294 var component = _this.spawn();
3295 subset.forEach(function(node2) {
3296 component.merge(node2);
3297 node2.connectedEdges().forEach(function(edge) {
3298 if (_this.contains(edge) && !cut.contains(edge)) {
3299 component.merge(edge);
3300 }
3301 });
3302 });
3303 return component;
3304 };
3305 var components = [constructComponent(partition1), constructComponent(partition2)];
3306 var ret = {
3307 cut,
3308 components,
3309 // n.b. partitions are included to be compatible with the old api spec
3310 // (could be removed in a future major version)
3311 partition1,
3312 partition2
3313 };
3314 return ret;
3315 }
3316 };
3317 var copyPosition = function copyPosition2(p2) {
3318 return {
3319 x: p2.x,
3320 y: p2.y
3321 };
3322 };
3323 var modelToRenderedPosition = function modelToRenderedPosition2(p2, zoom, pan) {
3324 return {
3325 x: p2.x * zoom + pan.x,
3326 y: p2.y * zoom + pan.y
3327 };
3328 };
3329 var renderedToModelPosition = function renderedToModelPosition2(p2, zoom, pan) {
3330 return {
3331 x: (p2.x - pan.x) / zoom,
3332 y: (p2.y - pan.y) / zoom
3333 };
3334 };
3335 var array2point = function array2point2(arr) {
3336 return {
3337 x: arr[0],
3338 y: arr[1]
3339 };
3340 };
3341 var min = function min2(arr) {
3342 var begin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
3343 var end = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : arr.length;
3344 var min3 = Infinity;
3345 for (var i2 = begin; i2 < end; i2++) {
3346 var val = arr[i2];
3347 if (isFinite(val)) {
3348 min3 = Math.min(val, min3);
3349 }
3350 }
3351 return min3;
3352 };
3353 var max = function max2(arr) {
3354 var begin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
3355 var end = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : arr.length;
3356 var max3 = -Infinity;
3357 for (var i2 = begin; i2 < end; i2++) {
3358 var val = arr[i2];
3359 if (isFinite(val)) {
3360 max3 = Math.max(val, max3);
3361 }
3362 }
3363 return max3;
3364 };
3365 var mean = function mean2(arr) {
3366 var begin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
3367 var end = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : arr.length;
3368 var total = 0;
3369 var n = 0;
3370 for (var i2 = begin; i2 < end; i2++) {
3371 var val = arr[i2];
3372 if (isFinite(val)) {
3373 total += val;
3374 n++;
3375 }
3376 }
3377 return total / n;
3378 };
3379 var median = function median2(arr) {
3380 var begin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
3381 var end = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : arr.length;
3382 var copy2 = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : true;
3383 var sort = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
3384 var includeHoles = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : true;
3385 if (copy2) {
3386 arr = arr.slice(begin, end);
3387 } else {
3388 if (end < arr.length) {
3389 arr.splice(end, arr.length - end);
3390 }
3391 if (begin > 0) {
3392 arr.splice(0, begin);
3393 }
3394 }
3395 var off = 0;
3396 for (var i2 = arr.length - 1; i2 >= 0; i2--) {
3397 var v = arr[i2];
3398 if (includeHoles) {
3399 if (!isFinite(v)) {
3400 arr[i2] = -Infinity;
3401 off++;
3402 }
3403 } else {
3404 arr.splice(i2, 1);
3405 }
3406 }
3407 if (sort) {
3408 arr.sort(function(a, b) {
3409 return a - b;
3410 });
3411 }
3412 var len = arr.length;
3413 var mid = Math.floor(len / 2);
3414 if (len % 2 !== 0) {
3415 return arr[mid + 1 + off];
3416 } else {
3417 return (arr[mid - 1 + off] + arr[mid + off]) / 2;
3418 }
3419 };
3420 var deg2rad = function deg2rad2(deg) {
3421 return Math.PI * deg / 180;
3422 };
3423 var getAngleFromDisp = function getAngleFromDisp2(dispX, dispY) {
3424 return Math.atan2(dispY, dispX) - Math.PI / 2;
3425 };
3426 var log2 = Math.log2 || function(n) {
3427 return Math.log(n) / Math.log(2);
3428 };
3429 var signum = function signum2(x) {
3430 if (x > 0) {
3431 return 1;
3432 } else if (x < 0) {
3433 return -1;
3434 } else {
3435 return 0;
3436 }
3437 };
3438 var dist = function dist2(p1, p2) {
3439 return Math.sqrt(sqdist(p1, p2));
3440 };
3441 var sqdist = function sqdist2(p1, p2) {
3442 var dx = p2.x - p1.x;
3443 var dy = p2.y - p1.y;
3444 return dx * dx + dy * dy;
3445 };
3446 var inPlaceSumNormalize = function inPlaceSumNormalize2(v) {
3447 var length = v.length;
3448 var total = 0;
3449 for (var i2 = 0; i2 < length; i2++) {
3450 total += v[i2];
3451 }
3452 for (var _i = 0; _i < length; _i++) {
3453 v[_i] = v[_i] / total;
3454 }
3455 return v;
3456 };
3457 var qbezierAt = function qbezierAt2(p0, p1, p2, t) {
3458 return (1 - t) * (1 - t) * p0 + 2 * (1 - t) * t * p1 + t * t * p2;
3459 };
3460 var qbezierPtAt = function qbezierPtAt2(p0, p1, p2, t) {
3461 return {
3462 x: qbezierAt(p0.x, p1.x, p2.x, t),
3463 y: qbezierAt(p0.y, p1.y, p2.y, t)
3464 };
3465 };
3466 var lineAt = function lineAt2(p0, p1, t, d) {
3467 var vec = {
3468 x: p1.x - p0.x,
3469 y: p1.y - p0.y
3470 };
3471 var vecDist = dist(p0, p1);
3472 var normVec = {
3473 x: vec.x / vecDist,
3474 y: vec.y / vecDist
3475 };
3476 t = t == null ? 0 : t;
3477 d = d != null ? d : t * vecDist;
3478 return {
3479 x: p0.x + normVec.x * d,
3480 y: p0.y + normVec.y * d
3481 };
3482 };
3483 var bound = function bound2(min2, val, max2) {
3484 return Math.max(min2, Math.min(max2, val));
3485 };
3486 var makeBoundingBox = function makeBoundingBox2(bb) {
3487 if (bb == null) {
3488 return {
3489 x1: Infinity,
3490 y1: Infinity,
3491 x2: -Infinity,
3492 y2: -Infinity,
3493 w: 0,
3494 h: 0
3495 };
3496 } else if (bb.x1 != null && bb.y1 != null) {
3497 if (bb.x2 != null && bb.y2 != null && bb.x2 >= bb.x1 && bb.y2 >= bb.y1) {
3498 return {
3499 x1: bb.x1,
3500 y1: bb.y1,
3501 x2: bb.x2,
3502 y2: bb.y2,
3503 w: bb.x2 - bb.x1,
3504 h: bb.y2 - bb.y1
3505 };
3506 } else if (bb.w != null && bb.h != null && bb.w >= 0 && bb.h >= 0) {
3507 return {
3508 x1: bb.x1,
3509 y1: bb.y1,
3510 x2: bb.x1 + bb.w,
3511 y2: bb.y1 + bb.h,
3512 w: bb.w,
3513 h: bb.h
3514 };
3515 }
3516 }
3517 };
3518 var copyBoundingBox = function copyBoundingBox2(bb) {
3519 return {
3520 x1: bb.x1,
3521 x2: bb.x2,
3522 w: bb.w,
3523 y1: bb.y1,
3524 y2: bb.y2,
3525 h: bb.h
3526 };
3527 };
3528 var clearBoundingBox = function clearBoundingBox2(bb) {
3529 bb.x1 = Infinity;
3530 bb.y1 = Infinity;
3531 bb.x2 = -Infinity;
3532 bb.y2 = -Infinity;
3533 bb.w = 0;
3534 bb.h = 0;
3535 };
3536 var updateBoundingBox = function updateBoundingBox2(bb1, bb2) {
3537 bb1.x1 = Math.min(bb1.x1, bb2.x1);
3538 bb1.x2 = Math.max(bb1.x2, bb2.x2);
3539 bb1.w = bb1.x2 - bb1.x1;
3540 bb1.y1 = Math.min(bb1.y1, bb2.y1);
3541 bb1.y2 = Math.max(bb1.y2, bb2.y2);
3542 bb1.h = bb1.y2 - bb1.y1;
3543 };
3544 var expandBoundingBoxByPoint = function expandBoundingBoxByPoint2(bb, x, y) {
3545 bb.x1 = Math.min(bb.x1, x);
3546 bb.x2 = Math.max(bb.x2, x);
3547 bb.w = bb.x2 - bb.x1;
3548 bb.y1 = Math.min(bb.y1, y);
3549 bb.y2 = Math.max(bb.y2, y);
3550 bb.h = bb.y2 - bb.y1;
3551 };
3552 var expandBoundingBox = function expandBoundingBox2(bb) {
3553 var padding = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
3554 bb.x1 -= padding;
3555 bb.x2 += padding;
3556 bb.y1 -= padding;
3557 bb.y2 += padding;
3558 bb.w = bb.x2 - bb.x1;
3559 bb.h = bb.y2 - bb.y1;
3560 return bb;
3561 };
3562 var expandBoundingBoxSides = function expandBoundingBoxSides2(bb) {
3563 var padding = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [0];
3564 var top, right, bottom, left;
3565 if (padding.length === 1) {
3566 top = right = bottom = left = padding[0];
3567 } else if (padding.length === 2) {
3568 top = bottom = padding[0];
3569 left = right = padding[1];
3570 } else if (padding.length === 4) {
3571 var _padding = _slicedToArray(padding, 4);
3572 top = _padding[0];
3573 right = _padding[1];
3574 bottom = _padding[2];
3575 left = _padding[3];
3576 }
3577 bb.x1 -= left;
3578 bb.x2 += right;
3579 bb.y1 -= top;
3580 bb.y2 += bottom;
3581 bb.w = bb.x2 - bb.x1;
3582 bb.h = bb.y2 - bb.y1;
3583 return bb;
3584 };
3585 var assignBoundingBox = function assignBoundingBox2(bb1, bb2) {
3586 bb1.x1 = bb2.x1;
3587 bb1.y1 = bb2.y1;
3588 bb1.x2 = bb2.x2;
3589 bb1.y2 = bb2.y2;
3590 bb1.w = bb1.x2 - bb1.x1;
3591 bb1.h = bb1.y2 - bb1.y1;
3592 };
3593 var boundingBoxesIntersect = function boundingBoxesIntersect2(bb1, bb2) {
3594 if (bb1.x1 > bb2.x2) {
3595 return false;
3596 }
3597 if (bb2.x1 > bb1.x2) {
3598 return false;
3599 }
3600 if (bb1.x2 < bb2.x1) {
3601 return false;
3602 }
3603 if (bb2.x2 < bb1.x1) {
3604 return false;
3605 }
3606 if (bb1.y2 < bb2.y1) {
3607 return false;
3608 }
3609 if (bb2.y2 < bb1.y1) {
3610 return false;
3611 }
3612 if (bb1.y1 > bb2.y2) {
3613 return false;
3614 }
3615 if (bb2.y1 > bb1.y2) {
3616 return false;
3617 }
3618 return true;
3619 };
3620 var inBoundingBox = function inBoundingBox2(bb, x, y) {
3621 return bb.x1 <= x && x <= bb.x2 && bb.y1 <= y && y <= bb.y2;
3622 };
3623 var pointInBoundingBox = function pointInBoundingBox2(bb, pt) {
3624 return inBoundingBox(bb, pt.x, pt.y);
3625 };
3626 var boundingBoxInBoundingBox = function boundingBoxInBoundingBox2(bb1, bb2) {
3627 return inBoundingBox(bb1, bb2.x1, bb2.y1) && inBoundingBox(bb1, bb2.x2, bb2.y2);
3628 };
3629 var roundRectangleIntersectLine = function roundRectangleIntersectLine2(x, y, nodeX, nodeY, width, height, padding) {
3630 var cornerRadius = getRoundRectangleRadius(width, height);
3631 var halfWidth = width / 2;
3632 var halfHeight = height / 2;
3633 var straightLineIntersections;
3634 {
3635 var topStartX = nodeX - halfWidth + cornerRadius - padding;
3636 var topStartY = nodeY - halfHeight - padding;
3637 var topEndX = nodeX + halfWidth - cornerRadius + padding;
3638 var topEndY = topStartY;
3639 straightLineIntersections = finiteLinesIntersect(x, y, nodeX, nodeY, topStartX, topStartY, topEndX, topEndY, false);
3640 if (straightLineIntersections.length > 0) {
3641 return straightLineIntersections;
3642 }
3643 }
3644 {
3645 var rightStartX = nodeX + halfWidth + padding;
3646 var rightStartY = nodeY - halfHeight + cornerRadius - padding;
3647 var rightEndX = rightStartX;
3648 var rightEndY = nodeY + halfHeight - cornerRadius + padding;
3649 straightLineIntersections = finiteLinesIntersect(x, y, nodeX, nodeY, rightStartX, rightStartY, rightEndX, rightEndY, false);
3650 if (straightLineIntersections.length > 0) {
3651 return straightLineIntersections;
3652 }
3653 }
3654 {
3655 var bottomStartX = nodeX - halfWidth + cornerRadius - padding;
3656 var bottomStartY = nodeY + halfHeight + padding;
3657 var bottomEndX = nodeX + halfWidth - cornerRadius + padding;
3658 var bottomEndY = bottomStartY;
3659 straightLineIntersections = finiteLinesIntersect(x, y, nodeX, nodeY, bottomStartX, bottomStartY, bottomEndX, bottomEndY, false);
3660 if (straightLineIntersections.length > 0) {
3661 return straightLineIntersections;
3662 }
3663 }
3664 {
3665 var leftStartX = nodeX - halfWidth - padding;
3666 var leftStartY = nodeY - halfHeight + cornerRadius - padding;
3667 var leftEndX = leftStartX;
3668 var leftEndY = nodeY + halfHeight - cornerRadius + padding;
3669 straightLineIntersections = finiteLinesIntersect(x, y, nodeX, nodeY, leftStartX, leftStartY, leftEndX, leftEndY, false);
3670 if (straightLineIntersections.length > 0) {
3671 return straightLineIntersections;
3672 }
3673 }
3674 var arcIntersections;
3675 {
3676 var topLeftCenterX = nodeX - halfWidth + cornerRadius;
3677 var topLeftCenterY = nodeY - halfHeight + cornerRadius;
3678 arcIntersections = intersectLineCircle(x, y, nodeX, nodeY, topLeftCenterX, topLeftCenterY, cornerRadius + padding);
3679 if (arcIntersections.length > 0 && arcIntersections[0] <= topLeftCenterX && arcIntersections[1] <= topLeftCenterY) {
3680 return [arcIntersections[0], arcIntersections[1]];
3681 }
3682 }
3683 {
3684 var topRightCenterX = nodeX + halfWidth - cornerRadius;
3685 var topRightCenterY = nodeY - halfHeight + cornerRadius;
3686 arcIntersections = intersectLineCircle(x, y, nodeX, nodeY, topRightCenterX, topRightCenterY, cornerRadius + padding);
3687 if (arcIntersections.length > 0 && arcIntersections[0] >= topRightCenterX && arcIntersections[1] <= topRightCenterY) {
3688 return [arcIntersections[0], arcIntersections[1]];
3689 }
3690 }
3691 {
3692 var bottomRightCenterX = nodeX + halfWidth - cornerRadius;
3693 var bottomRightCenterY = nodeY + halfHeight - cornerRadius;
3694 arcIntersections = intersectLineCircle(x, y, nodeX, nodeY, bottomRightCenterX, bottomRightCenterY, cornerRadius + padding);
3695 if (arcIntersections.length > 0 && arcIntersections[0] >= bottomRightCenterX && arcIntersections[1] >= bottomRightCenterY) {
3696 return [arcIntersections[0], arcIntersections[1]];
3697 }
3698 }
3699 {
3700 var bottomLeftCenterX = nodeX - halfWidth + cornerRadius;
3701 var bottomLeftCenterY = nodeY + halfHeight - cornerRadius;
3702 arcIntersections = intersectLineCircle(x, y, nodeX, nodeY, bottomLeftCenterX, bottomLeftCenterY, cornerRadius + padding);
3703 if (arcIntersections.length > 0 && arcIntersections[0] <= bottomLeftCenterX && arcIntersections[1] >= bottomLeftCenterY) {
3704 return [arcIntersections[0], arcIntersections[1]];
3705 }
3706 }
3707 return [];
3708 };
3709 var inLineVicinity = function inLineVicinity2(x, y, lx1, ly1, lx2, ly2, tolerance) {
3710 var t = tolerance;
3711 var x1 = Math.min(lx1, lx2);
3712 var x2 = Math.max(lx1, lx2);
3713 var y1 = Math.min(ly1, ly2);
3714 var y2 = Math.max(ly1, ly2);
3715 return x1 - t <= x && x <= x2 + t && y1 - t <= y && y <= y2 + t;
3716 };
3717 var inBezierVicinity = function inBezierVicinity2(x, y, x1, y1, x2, y2, x3, y3, tolerance) {
3718 var bb = {
3719 x1: Math.min(x1, x3, x2) - tolerance,
3720 x2: Math.max(x1, x3, x2) + tolerance,
3721 y1: Math.min(y1, y3, y2) - tolerance,
3722 y2: Math.max(y1, y3, y2) + tolerance
3723 };
3724 if (x < bb.x1 || x > bb.x2 || y < bb.y1 || y > bb.y2) {
3725 return false;
3726 } else {
3727 return true;
3728 }
3729 };
3730 var solveQuadratic = function solveQuadratic2(a, b, c, val) {
3731 c -= val;
3732 var r = b * b - 4 * a * c;
3733 if (r < 0) {
3734 return [];
3735 }
3736 var sqrtR = Math.sqrt(r);
3737 var denom = 2 * a;
3738 var root1 = (-b + sqrtR) / denom;
3739 var root2 = (-b - sqrtR) / denom;
3740 return [root1, root2];
3741 };
3742 var solveCubic = function solveCubic2(a, b, c, d, result) {
3743 var epsilon = 1e-5;
3744 if (a === 0) {
3745 a = epsilon;
3746 }
3747 b /= a;
3748 c /= a;
3749 d /= a;
3750 var discriminant, q, r, dum1, s, t, term1, r13;
3751 q = (3 * c - b * b) / 9;
3752 r = -(27 * d) + b * (9 * c - 2 * (b * b));
3753 r /= 54;
3754 discriminant = q * q * q + r * r;
3755 result[1] = 0;
3756 term1 = b / 3;
3757 if (discriminant > 0) {
3758 s = r + Math.sqrt(discriminant);
3759 s = s < 0 ? -Math.pow(-s, 1 / 3) : Math.pow(s, 1 / 3);
3760 t = r - Math.sqrt(discriminant);
3761 t = t < 0 ? -Math.pow(-t, 1 / 3) : Math.pow(t, 1 / 3);
3762 result[0] = -term1 + s + t;
3763 term1 += (s + t) / 2;
3764 result[4] = result[2] = -term1;
3765 term1 = Math.sqrt(3) * (-t + s) / 2;
3766 result[3] = term1;
3767 result[5] = -term1;
3768 return;
3769 }
3770 result[5] = result[3] = 0;
3771 if (discriminant === 0) {
3772 r13 = r < 0 ? -Math.pow(-r, 1 / 3) : Math.pow(r, 1 / 3);
3773 result[0] = -term1 + 2 * r13;
3774 result[4] = result[2] = -(r13 + term1);
3775 return;
3776 }
3777 q = -q;
3778 dum1 = q * q * q;
3779 dum1 = Math.acos(r / Math.sqrt(dum1));
3780 r13 = 2 * Math.sqrt(q);
3781 result[0] = -term1 + r13 * Math.cos(dum1 / 3);
3782 result[2] = -term1 + r13 * Math.cos((dum1 + 2 * Math.PI) / 3);
3783 result[4] = -term1 + r13 * Math.cos((dum1 + 4 * Math.PI) / 3);
3784 return;
3785 };
3786 var sqdistToQuadraticBezier = function sqdistToQuadraticBezier2(x, y, x1, y1, x2, y2, x3, y3) {
3787 var a = 1 * x1 * x1 - 4 * x1 * x2 + 2 * x1 * x3 + 4 * x2 * x2 - 4 * x2 * x3 + x3 * x3 + y1 * y1 - 4 * y1 * y2 + 2 * y1 * y3 + 4 * y2 * y2 - 4 * y2 * y3 + y3 * y3;
3788 var b = 1 * 9 * x1 * x2 - 3 * x1 * x1 - 3 * x1 * x3 - 6 * x2 * x2 + 3 * x2 * x3 + 9 * y1 * y2 - 3 * y1 * y1 - 3 * y1 * y3 - 6 * y2 * y2 + 3 * y2 * y3;
3789 var c = 1 * 3 * x1 * x1 - 6 * x1 * x2 + x1 * x3 - x1 * x + 2 * x2 * x2 + 2 * x2 * x - x3 * x + 3 * y1 * y1 - 6 * y1 * y2 + y1 * y3 - y1 * y + 2 * y2 * y2 + 2 * y2 * y - y3 * y;
3790 var d = 1 * x1 * x2 - x1 * x1 + x1 * x - x2 * x + y1 * y2 - y1 * y1 + y1 * y - y2 * y;
3791 var roots = [];
3792 solveCubic(a, b, c, d, roots);
3793 var zeroThreshold = 1e-7;
3794 var params = [];
3795 for (var index = 0; index < 6; index += 2) {
3796 if (Math.abs(roots[index + 1]) < zeroThreshold && roots[index] >= 0 && roots[index] <= 1) {
3797 params.push(roots[index]);
3798 }
3799 }
3800 params.push(1);
3801 params.push(0);
3802 var minDistanceSquared = -1;
3803 var curX, curY, distSquared;
3804 for (var i2 = 0; i2 < params.length; i2++) {
3805 curX = Math.pow(1 - params[i2], 2) * x1 + 2 * (1 - params[i2]) * params[i2] * x2 + params[i2] * params[i2] * x3;
3806 curY = Math.pow(1 - params[i2], 2) * y1 + 2 * (1 - params[i2]) * params[i2] * y2 + params[i2] * params[i2] * y3;
3807 distSquared = Math.pow(curX - x, 2) + Math.pow(curY - y, 2);
3808 if (minDistanceSquared >= 0) {
3809 if (distSquared < minDistanceSquared) {
3810 minDistanceSquared = distSquared;
3811 }
3812 } else {
3813 minDistanceSquared = distSquared;
3814 }
3815 }
3816 return minDistanceSquared;
3817 };
3818 var sqdistToFiniteLine = function sqdistToFiniteLine2(x, y, x1, y1, x2, y2) {
3819 var offset = [x - x1, y - y1];
3820 var line = [x2 - x1, y2 - y1];
3821 var lineSq = line[0] * line[0] + line[1] * line[1];
3822 var hypSq = offset[0] * offset[0] + offset[1] * offset[1];
3823 var dotProduct = offset[0] * line[0] + offset[1] * line[1];
3824 var adjSq = dotProduct * dotProduct / lineSq;
3825 if (dotProduct < 0) {
3826 return hypSq;
3827 }
3828 if (adjSq > lineSq) {
3829 return (x - x2) * (x - x2) + (y - y2) * (y - y2);
3830 }
3831 return hypSq - adjSq;
3832 };
3833 var pointInsidePolygonPoints = function pointInsidePolygonPoints2(x, y, points) {
3834 var x1, y1, x2, y2;
3835 var y3;
3836 var up = 0;
3837 for (var i2 = 0; i2 < points.length / 2; i2++) {
3838 x1 = points[i2 * 2];
3839 y1 = points[i2 * 2 + 1];
3840 if (i2 + 1 < points.length / 2) {
3841 x2 = points[(i2 + 1) * 2];
3842 y2 = points[(i2 + 1) * 2 + 1];
3843 } else {
3844 x2 = points[(i2 + 1 - points.length / 2) * 2];
3845 y2 = points[(i2 + 1 - points.length / 2) * 2 + 1];
3846 }
3847 if (x1 == x && x2 == x)
3848 ;
3849 else if (x1 >= x && x >= x2 || x1 <= x && x <= x2) {
3850 y3 = (x - x1) / (x2 - x1) * (y2 - y1) + y1;
3851 if (y3 > y) {
3852 up++;
3853 }
3854 } else {
3855 continue;
3856 }
3857 }
3858 if (up % 2 === 0) {
3859 return false;
3860 } else {
3861 return true;
3862 }
3863 };
3864 var pointInsidePolygon = function pointInsidePolygon2(x, y, basePoints, centerX, centerY, width, height, direction, padding) {
3865 var transformedPoints = new Array(basePoints.length);
3866 var angle;
3867 if (direction[0] != null) {
3868 angle = Math.atan(direction[1] / direction[0]);
3869 if (direction[0] < 0) {
3870 angle = angle + Math.PI / 2;
3871 } else {
3872 angle = -angle - Math.PI / 2;
3873 }
3874 } else {
3875 angle = direction;
3876 }
3877 var cos2 = Math.cos(-angle);
3878 var sin2 = Math.sin(-angle);
3879 for (var i2 = 0; i2 < transformedPoints.length / 2; i2++) {
3880 transformedPoints[i2 * 2] = width / 2 * (basePoints[i2 * 2] * cos2 - basePoints[i2 * 2 + 1] * sin2);
3881 transformedPoints[i2 * 2 + 1] = height / 2 * (basePoints[i2 * 2 + 1] * cos2 + basePoints[i2 * 2] * sin2);
3882 transformedPoints[i2 * 2] += centerX;
3883 transformedPoints[i2 * 2 + 1] += centerY;
3884 }
3885 var points;
3886 if (padding > 0) {
3887 var expandedLineSet = expandPolygon(transformedPoints, -padding);
3888 points = joinLines(expandedLineSet);
3889 } else {
3890 points = transformedPoints;
3891 }
3892 return pointInsidePolygonPoints(x, y, points);
3893 };
3894 var pointInsideRoundPolygon = function pointInsideRoundPolygon2(x, y, basePoints, centerX, centerY, width, height) {
3895 var cutPolygonPoints = new Array(basePoints.length);
3896 var halfW = width / 2;
3897 var halfH = height / 2;
3898 var cornerRadius = getRoundPolygonRadius(width, height);
3899 var squaredCornerRadius = cornerRadius * cornerRadius;
3900 for (var i2 = 0; i2 < basePoints.length / 4; i2++) {
3901 var sourceUv = void 0, destUv = void 0;
3902 if (i2 === 0) {
3903 sourceUv = basePoints.length - 2;
3904 } else {
3905 sourceUv = i2 * 4 - 2;
3906 }
3907 destUv = i2 * 4 + 2;
3908 var px = centerX + halfW * basePoints[i2 * 4];
3909 var py = centerY + halfH * basePoints[i2 * 4 + 1];
3910 var cosTheta = -basePoints[sourceUv] * basePoints[destUv] - basePoints[sourceUv + 1] * basePoints[destUv + 1];
3911 var offset = cornerRadius / Math.tan(Math.acos(cosTheta) / 2);
3912 var cp0x = px - offset * basePoints[sourceUv];
3913 var cp0y = py - offset * basePoints[sourceUv + 1];
3914 var cp1x = px + offset * basePoints[destUv];
3915 var cp1y = py + offset * basePoints[destUv + 1];
3916 cutPolygonPoints[i2 * 4] = cp0x;
3917 cutPolygonPoints[i2 * 4 + 1] = cp0y;
3918 cutPolygonPoints[i2 * 4 + 2] = cp1x;
3919 cutPolygonPoints[i2 * 4 + 3] = cp1y;
3920 var orthx = basePoints[sourceUv + 1];
3921 var orthy = -basePoints[sourceUv];
3922 var cosAlpha = orthx * basePoints[destUv] + orthy * basePoints[destUv + 1];
3923 if (cosAlpha < 0) {
3924 orthx *= -1;
3925 orthy *= -1;
3926 }
3927 var cx = cp0x + orthx * cornerRadius;
3928 var cy = cp0y + orthy * cornerRadius;
3929 var squaredDistance = Math.pow(cx - x, 2) + Math.pow(cy - y, 2);
3930 if (squaredDistance <= squaredCornerRadius) {
3931 return true;
3932 }
3933 }
3934 return pointInsidePolygonPoints(x, y, cutPolygonPoints);
3935 };
3936 var joinLines = function joinLines2(lineSet) {
3937 var vertices = new Array(lineSet.length / 2);
3938 var currentLineStartX, currentLineStartY, currentLineEndX, currentLineEndY;
3939 var nextLineStartX, nextLineStartY, nextLineEndX, nextLineEndY;
3940 for (var i2 = 0; i2 < lineSet.length / 4; i2++) {
3941 currentLineStartX = lineSet[i2 * 4];
3942 currentLineStartY = lineSet[i2 * 4 + 1];
3943 currentLineEndX = lineSet[i2 * 4 + 2];
3944 currentLineEndY = lineSet[i2 * 4 + 3];
3945 if (i2 < lineSet.length / 4 - 1) {
3946 nextLineStartX = lineSet[(i2 + 1) * 4];
3947 nextLineStartY = lineSet[(i2 + 1) * 4 + 1];
3948 nextLineEndX = lineSet[(i2 + 1) * 4 + 2];
3949 nextLineEndY = lineSet[(i2 + 1) * 4 + 3];
3950 } else {
3951 nextLineStartX = lineSet[0];
3952 nextLineStartY = lineSet[1];
3953 nextLineEndX = lineSet[2];
3954 nextLineEndY = lineSet[3];
3955 }
3956 var intersection = finiteLinesIntersect(currentLineStartX, currentLineStartY, currentLineEndX, currentLineEndY, nextLineStartX, nextLineStartY, nextLineEndX, nextLineEndY, true);
3957 vertices[i2 * 2] = intersection[0];
3958 vertices[i2 * 2 + 1] = intersection[1];
3959 }
3960 return vertices;
3961 };
3962 var expandPolygon = function expandPolygon2(points, pad) {
3963 var expandedLineSet = new Array(points.length * 2);
3964 var currentPointX, currentPointY, nextPointX, nextPointY;
3965 for (var i2 = 0; i2 < points.length / 2; i2++) {
3966 currentPointX = points[i2 * 2];
3967 currentPointY = points[i2 * 2 + 1];
3968 if (i2 < points.length / 2 - 1) {
3969 nextPointX = points[(i2 + 1) * 2];
3970 nextPointY = points[(i2 + 1) * 2 + 1];
3971 } else {
3972 nextPointX = points[0];
3973 nextPointY = points[1];
3974 }
3975 var offsetX = nextPointY - currentPointY;
3976 var offsetY = -(nextPointX - currentPointX);
3977 var offsetLength = Math.sqrt(offsetX * offsetX + offsetY * offsetY);
3978 var normalizedOffsetX = offsetX / offsetLength;
3979 var normalizedOffsetY = offsetY / offsetLength;
3980 expandedLineSet[i2 * 4] = currentPointX + normalizedOffsetX * pad;
3981 expandedLineSet[i2 * 4 + 1] = currentPointY + normalizedOffsetY * pad;
3982 expandedLineSet[i2 * 4 + 2] = nextPointX + normalizedOffsetX * pad;
3983 expandedLineSet[i2 * 4 + 3] = nextPointY + normalizedOffsetY * pad;
3984 }
3985 return expandedLineSet;
3986 };
3987 var intersectLineEllipse = function intersectLineEllipse2(x, y, centerX, centerY, ellipseWradius, ellipseHradius) {
3988 var dispX = centerX - x;
3989 var dispY = centerY - y;
3990 dispX /= ellipseWradius;
3991 dispY /= ellipseHradius;
3992 var len = Math.sqrt(dispX * dispX + dispY * dispY);
3993 var newLength = len - 1;
3994 if (newLength < 0) {
3995 return [];
3996 }
3997 var lenProportion = newLength / len;
3998 return [(centerX - x) * lenProportion + x, (centerY - y) * lenProportion + y];
3999 };
4000 var checkInEllipse = function checkInEllipse2(x, y, width, height, centerX, centerY, padding) {
4001 x -= centerX;
4002 y -= centerY;
4003 x /= width / 2 + padding;
4004 y /= height / 2 + padding;
4005 return x * x + y * y <= 1;
4006 };
4007 var intersectLineCircle = function intersectLineCircle2(x1, y1, x2, y2, centerX, centerY, radius) {
4008 var d = [x2 - x1, y2 - y1];
4009 var f = [x1 - centerX, y1 - centerY];
4010 var a = d[0] * d[0] + d[1] * d[1];
4011 var b = 2 * (f[0] * d[0] + f[1] * d[1]);
4012 var c = f[0] * f[0] + f[1] * f[1] - radius * radius;
4013 var discriminant = b * b - 4 * a * c;
4014 if (discriminant < 0) {
4015 return [];
4016 }
4017 var t1 = (-b + Math.sqrt(discriminant)) / (2 * a);
4018 var t2 = (-b - Math.sqrt(discriminant)) / (2 * a);
4019 var tMin = Math.min(t1, t2);
4020 var tMax = Math.max(t1, t2);
4021 var inRangeParams = [];
4022 if (tMin >= 0 && tMin <= 1) {
4023 inRangeParams.push(tMin);
4024 }
4025 if (tMax >= 0 && tMax <= 1) {
4026 inRangeParams.push(tMax);
4027 }
4028 if (inRangeParams.length === 0) {
4029 return [];
4030 }
4031 var nearIntersectionX = inRangeParams[0] * d[0] + x1;
4032 var nearIntersectionY = inRangeParams[0] * d[1] + y1;
4033 if (inRangeParams.length > 1) {
4034 if (inRangeParams[0] == inRangeParams[1]) {
4035 return [nearIntersectionX, nearIntersectionY];
4036 } else {
4037 var farIntersectionX = inRangeParams[1] * d[0] + x1;
4038 var farIntersectionY = inRangeParams[1] * d[1] + y1;
4039 return [nearIntersectionX, nearIntersectionY, farIntersectionX, farIntersectionY];
4040 }
4041 } else {
4042 return [nearIntersectionX, nearIntersectionY];
4043 }
4044 };
4045 var midOfThree = function midOfThree2(a, b, c) {
4046 if (b <= a && a <= c || c <= a && a <= b) {
4047 return a;
4048 } else if (a <= b && b <= c || c <= b && b <= a) {
4049 return b;
4050 } else {
4051 return c;
4052 }
4053 };
4054 var finiteLinesIntersect = function finiteLinesIntersect2(x1, y1, x2, y2, x3, y3, x4, y4, infiniteLines) {
4055 var dx13 = x1 - x3;
4056 var dx21 = x2 - x1;
4057 var dx43 = x4 - x3;
4058 var dy13 = y1 - y3;
4059 var dy21 = y2 - y1;
4060 var dy43 = y4 - y3;
4061 var ua_t = dx43 * dy13 - dy43 * dx13;
4062 var ub_t = dx21 * dy13 - dy21 * dx13;
4063 var u_b = dy43 * dx21 - dx43 * dy21;
4064 if (u_b !== 0) {
4065 var ua = ua_t / u_b;
4066 var ub = ub_t / u_b;
4067 var flptThreshold = 1e-3;
4068 var _min = 0 - flptThreshold;
4069 var _max = 1 + flptThreshold;
4070 if (_min <= ua && ua <= _max && _min <= ub && ub <= _max) {
4071 return [x1 + ua * dx21, y1 + ua * dy21];
4072 } else {
4073 if (!infiniteLines) {
4074 return [];
4075 } else {
4076 return [x1 + ua * dx21, y1 + ua * dy21];
4077 }
4078 }
4079 } else {
4080 if (ua_t === 0 || ub_t === 0) {
4081 if (midOfThree(x1, x2, x4) === x4) {
4082 return [x4, y4];
4083 }
4084 if (midOfThree(x1, x2, x3) === x3) {
4085 return [x3, y3];
4086 }
4087 if (midOfThree(x3, x4, x2) === x2) {
4088 return [x2, y2];
4089 }
4090 return [];
4091 } else {
4092 return [];
4093 }
4094 }
4095 };
4096 var polygonIntersectLine = function polygonIntersectLine2(x, y, basePoints, centerX, centerY, width, height, padding) {
4097 var intersections = [];
4098 var intersection;
4099 var transformedPoints = new Array(basePoints.length);
4100 var doTransform = true;
4101 if (width == null) {
4102 doTransform = false;
4103 }
4104 var points;
4105 if (doTransform) {
4106 for (var i2 = 0; i2 < transformedPoints.length / 2; i2++) {
4107 transformedPoints[i2 * 2] = basePoints[i2 * 2] * width + centerX;
4108 transformedPoints[i2 * 2 + 1] = basePoints[i2 * 2 + 1] * height + centerY;
4109 }
4110 if (padding > 0) {
4111 var expandedLineSet = expandPolygon(transformedPoints, -padding);
4112 points = joinLines(expandedLineSet);
4113 } else {
4114 points = transformedPoints;
4115 }
4116 } else {
4117 points = basePoints;
4118 }
4119 var currentX, currentY, nextX, nextY;
4120 for (var _i2 = 0; _i2 < points.length / 2; _i2++) {
4121 currentX = points[_i2 * 2];
4122 currentY = points[_i2 * 2 + 1];
4123 if (_i2 < points.length / 2 - 1) {
4124 nextX = points[(_i2 + 1) * 2];
4125 nextY = points[(_i2 + 1) * 2 + 1];
4126 } else {
4127 nextX = points[0];
4128 nextY = points[1];
4129 }
4130 intersection = finiteLinesIntersect(x, y, centerX, centerY, currentX, currentY, nextX, nextY);
4131 if (intersection.length !== 0) {
4132 intersections.push(intersection[0], intersection[1]);
4133 }
4134 }
4135 return intersections;
4136 };
4137 var roundPolygonIntersectLine = function roundPolygonIntersectLine2(x, y, basePoints, centerX, centerY, width, height, padding) {
4138 var intersections = [];
4139 var intersection;
4140 var lines = new Array(basePoints.length);
4141 var halfW = width / 2;
4142 var halfH = height / 2;
4143 var cornerRadius = getRoundPolygonRadius(width, height);
4144 for (var i2 = 0; i2 < basePoints.length / 4; i2++) {
4145 var sourceUv = void 0, destUv = void 0;
4146 if (i2 === 0) {
4147 sourceUv = basePoints.length - 2;
4148 } else {
4149 sourceUv = i2 * 4 - 2;
4150 }
4151 destUv = i2 * 4 + 2;
4152 var px = centerX + halfW * basePoints[i2 * 4];
4153 var py = centerY + halfH * basePoints[i2 * 4 + 1];
4154 var cosTheta = -basePoints[sourceUv] * basePoints[destUv] - basePoints[sourceUv + 1] * basePoints[destUv + 1];
4155 var offset = cornerRadius / Math.tan(Math.acos(cosTheta) / 2);
4156 var cp0x = px - offset * basePoints[sourceUv];
4157 var cp0y = py - offset * basePoints[sourceUv + 1];
4158 var cp1x = px + offset * basePoints[destUv];
4159 var cp1y = py + offset * basePoints[destUv + 1];
4160 if (i2 === 0) {
4161 lines[basePoints.length - 2] = cp0x;
4162 lines[basePoints.length - 1] = cp0y;
4163 } else {
4164 lines[i2 * 4 - 2] = cp0x;
4165 lines[i2 * 4 - 1] = cp0y;
4166 }
4167 lines[i2 * 4] = cp1x;
4168 lines[i2 * 4 + 1] = cp1y;
4169 var orthx = basePoints[sourceUv + 1];
4170 var orthy = -basePoints[sourceUv];
4171 var cosAlpha = orthx * basePoints[destUv] + orthy * basePoints[destUv + 1];
4172 if (cosAlpha < 0) {
4173 orthx *= -1;
4174 orthy *= -1;
4175 }
4176 var cx = cp0x + orthx * cornerRadius;
4177 var cy = cp0y + orthy * cornerRadius;
4178 intersection = intersectLineCircle(x, y, centerX, centerY, cx, cy, cornerRadius);
4179 if (intersection.length !== 0) {
4180 intersections.push(intersection[0], intersection[1]);
4181 }
4182 }
4183 for (var _i3 = 0; _i3 < lines.length / 4; _i3++) {
4184 intersection = finiteLinesIntersect(x, y, centerX, centerY, lines[_i3 * 4], lines[_i3 * 4 + 1], lines[_i3 * 4 + 2], lines[_i3 * 4 + 3], false);
4185 if (intersection.length !== 0) {
4186 intersections.push(intersection[0], intersection[1]);
4187 }
4188 }
4189 if (intersections.length > 2) {
4190 var lowestIntersection = [intersections[0], intersections[1]];
4191 var lowestSquaredDistance = Math.pow(lowestIntersection[0] - x, 2) + Math.pow(lowestIntersection[1] - y, 2);
4192 for (var _i4 = 1; _i4 < intersections.length / 2; _i4++) {
4193 var squaredDistance = Math.pow(intersections[_i4 * 2] - x, 2) + Math.pow(intersections[_i4 * 2 + 1] - y, 2);
4194 if (squaredDistance <= lowestSquaredDistance) {
4195 lowestIntersection[0] = intersections[_i4 * 2];
4196 lowestIntersection[1] = intersections[_i4 * 2 + 1];
4197 lowestSquaredDistance = squaredDistance;
4198 }
4199 }
4200 return lowestIntersection;
4201 }
4202 return intersections;
4203 };
4204 var shortenIntersection = function shortenIntersection2(intersection, offset, amount) {
4205 var disp = [intersection[0] - offset[0], intersection[1] - offset[1]];
4206 var length = Math.sqrt(disp[0] * disp[0] + disp[1] * disp[1]);
4207 var lenRatio = (length - amount) / length;
4208 if (lenRatio < 0) {
4209 lenRatio = 1e-5;
4210 }
4211 return [offset[0] + lenRatio * disp[0], offset[1] + lenRatio * disp[1]];
4212 };
4213 var generateUnitNgonPointsFitToSquare = function generateUnitNgonPointsFitToSquare2(sides, rotationRadians) {
4214 var points = generateUnitNgonPoints(sides, rotationRadians);
4215 points = fitPolygonToSquare(points);
4216 return points;
4217 };
4218 var fitPolygonToSquare = function fitPolygonToSquare2(points) {
4219 var x, y;
4220 var sides = points.length / 2;
4221 var minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
4222 for (var i2 = 0; i2 < sides; i2++) {
4223 x = points[2 * i2];
4224 y = points[2 * i2 + 1];
4225 minX = Math.min(minX, x);
4226 maxX = Math.max(maxX, x);
4227 minY = Math.min(minY, y);
4228 maxY = Math.max(maxY, y);
4229 }
4230 var sx = 2 / (maxX - minX);
4231 var sy = 2 / (maxY - minY);
4232 for (var _i5 = 0; _i5 < sides; _i5++) {
4233 x = points[2 * _i5] = points[2 * _i5] * sx;
4234 y = points[2 * _i5 + 1] = points[2 * _i5 + 1] * sy;
4235 minX = Math.min(minX, x);
4236 maxX = Math.max(maxX, x);
4237 minY = Math.min(minY, y);
4238 maxY = Math.max(maxY, y);
4239 }
4240 if (minY < -1) {
4241 for (var _i6 = 0; _i6 < sides; _i6++) {
4242 y = points[2 * _i6 + 1] = points[2 * _i6 + 1] + (-1 - minY);
4243 }
4244 }
4245 return points;
4246 };
4247 var generateUnitNgonPoints = function generateUnitNgonPoints2(sides, rotationRadians) {
4248 var increment = 1 / sides * 2 * Math.PI;
4249 var startAngle = sides % 2 === 0 ? Math.PI / 2 + increment / 2 : Math.PI / 2;
4250 startAngle += rotationRadians;
4251 var points = new Array(sides * 2);
4252 var currentAngle;
4253 for (var i2 = 0; i2 < sides; i2++) {
4254 currentAngle = i2 * increment + startAngle;
4255 points[2 * i2] = Math.cos(currentAngle);
4256 points[2 * i2 + 1] = Math.sin(-currentAngle);
4257 }
4258 return points;
4259 };
4260 var getRoundRectangleRadius = function getRoundRectangleRadius2(width, height) {
4261 return Math.min(width / 4, height / 4, 8);
4262 };
4263 var getRoundPolygonRadius = function getRoundPolygonRadius2(width, height) {
4264 return Math.min(width / 10, height / 10, 8);
4265 };
4266 var getCutRectangleCornerLength = function getCutRectangleCornerLength2() {
4267 return 8;
4268 };
4269 var bezierPtsToQuadCoeff = function bezierPtsToQuadCoeff2(p0, p1, p2) {
4270 return [p0 - 2 * p1 + p2, 2 * (p1 - p0), p0];
4271 };
4272 var getBarrelCurveConstants = function getBarrelCurveConstants2(width, height) {
4273 return {
4274 heightOffset: Math.min(15, 0.05 * height),
4275 widthOffset: Math.min(100, 0.25 * width),
4276 ctrlPtOffsetPct: 0.05
4277 };
4278 };
4279 var pageRankDefaults = defaults$g({
4280 dampingFactor: 0.8,
4281 precision: 1e-6,
4282 iterations: 200,
4283 weight: function weight(edge) {
4284 return 1;
4285 }
4286 });
4287 var elesfn$o = {
4288 pageRank: function pageRank(options) {
4289 var _pageRankDefaults = pageRankDefaults(options), dampingFactor = _pageRankDefaults.dampingFactor, precision = _pageRankDefaults.precision, iterations = _pageRankDefaults.iterations, weight = _pageRankDefaults.weight;
4290 var cy = this._private.cy;
4291 var _this$byGroup = this.byGroup(), nodes2 = _this$byGroup.nodes, edges = _this$byGroup.edges;
4292 var numNodes = nodes2.length;
4293 var numNodesSqd = numNodes * numNodes;
4294 var numEdges = edges.length;
4295 var matrix = new Array(numNodesSqd);
4296 var columnSum = new Array(numNodes);
4297 var additionalProb = (1 - dampingFactor) / numNodes;
4298 for (var i2 = 0; i2 < numNodes; i2++) {
4299 for (var j = 0; j < numNodes; j++) {
4300 var n = i2 * numNodes + j;
4301 matrix[n] = 0;
4302 }
4303 columnSum[i2] = 0;
4304 }
4305 for (var _i = 0; _i < numEdges; _i++) {
4306 var edge = edges[_i];
4307 var srcId = edge.data("source");
4308 var tgtId = edge.data("target");
4309 if (srcId === tgtId) {
4310 continue;
4311 }
4312 var s = nodes2.indexOfId(srcId);
4313 var t = nodes2.indexOfId(tgtId);
4314 var w = weight(edge);
4315 var _n = t * numNodes + s;
4316 matrix[_n] += w;
4317 columnSum[s] += w;
4318 }
4319 var p2 = 1 / numNodes + additionalProb;
4320 for (var _j = 0; _j < numNodes; _j++) {
4321 if (columnSum[_j] === 0) {
4322 for (var _i2 = 0; _i2 < numNodes; _i2++) {
4323 var _n2 = _i2 * numNodes + _j;
4324 matrix[_n2] = p2;
4325 }
4326 } else {
4327 for (var _i3 = 0; _i3 < numNodes; _i3++) {
4328 var _n3 = _i3 * numNodes + _j;
4329 matrix[_n3] = matrix[_n3] / columnSum[_j] + additionalProb;
4330 }
4331 }
4332 }
4333 var eigenvector = new Array(numNodes);
4334 var temp = new Array(numNodes);
4335 var previous;
4336 for (var _i4 = 0; _i4 < numNodes; _i4++) {
4337 eigenvector[_i4] = 1;
4338 }
4339 for (var iter = 0; iter < iterations; iter++) {
4340 for (var _i5 = 0; _i5 < numNodes; _i5++) {
4341 temp[_i5] = 0;
4342 }
4343 for (var _i6 = 0; _i6 < numNodes; _i6++) {
4344 for (var _j2 = 0; _j2 < numNodes; _j2++) {
4345 var _n4 = _i6 * numNodes + _j2;
4346 temp[_i6] += matrix[_n4] * eigenvector[_j2];
4347 }
4348 }
4349 inPlaceSumNormalize(temp);
4350 previous = eigenvector;
4351 eigenvector = temp;
4352 temp = previous;
4353 var diff = 0;
4354 for (var _i7 = 0; _i7 < numNodes; _i7++) {
4355 var delta = previous[_i7] - eigenvector[_i7];
4356 diff += delta * delta;
4357 }
4358 if (diff < precision) {
4359 break;
4360 }
4361 }
4362 var res = {
4363 rank: function rank(node) {
4364 node = cy.collection(node)[0];
4365 return eigenvector[nodes2.indexOf(node)];
4366 }
4367 };
4368 return res;
4369 }
4370 // pageRank
4371 };
4372 var defaults$f = defaults$g({
4373 root: null,
4374 weight: function weight(edge) {
4375 return 1;
4376 },
4377 directed: false,
4378 alpha: 0
4379 });
4380 var elesfn$n = {
4381 degreeCentralityNormalized: function degreeCentralityNormalized(options) {
4382 options = defaults$f(options);
4383 var cy = this.cy();
4384 var nodes2 = this.nodes();
4385 var numNodes = nodes2.length;
4386 if (!options.directed) {
4387 var degrees = {};
4388 var maxDegree = 0;
4389 for (var i2 = 0; i2 < numNodes; i2++) {
4390 var node = nodes2[i2];
4391 options.root = node;
4392 var currDegree = this.degreeCentrality(options);
4393 if (maxDegree < currDegree.degree) {
4394 maxDegree = currDegree.degree;
4395 }
4396 degrees[node.id()] = currDegree.degree;
4397 }
4398 return {
4399 degree: function degree(node2) {
4400 if (maxDegree === 0) {
4401 return 0;
4402 }
4403 if (string(node2)) {
4404 node2 = cy.filter(node2);
4405 }
4406 return degrees[node2.id()] / maxDegree;
4407 }
4408 };
4409 } else {
4410 var indegrees = {};
4411 var outdegrees = {};
4412 var maxIndegree = 0;
4413 var maxOutdegree = 0;
4414 for (var _i = 0; _i < numNodes; _i++) {
4415 var _node = nodes2[_i];
4416 var id = _node.id();
4417 options.root = _node;
4418 var _currDegree = this.degreeCentrality(options);
4419 if (maxIndegree < _currDegree.indegree)
4420 maxIndegree = _currDegree.indegree;
4421 if (maxOutdegree < _currDegree.outdegree)
4422 maxOutdegree = _currDegree.outdegree;
4423 indegrees[id] = _currDegree.indegree;
4424 outdegrees[id] = _currDegree.outdegree;
4425 }
4426 return {
4427 indegree: function indegree(node2) {
4428 if (maxIndegree == 0) {
4429 return 0;
4430 }
4431 if (string(node2)) {
4432 node2 = cy.filter(node2);
4433 }
4434 return indegrees[node2.id()] / maxIndegree;
4435 },
4436 outdegree: function outdegree(node2) {
4437 if (maxOutdegree === 0) {
4438 return 0;
4439 }
4440 if (string(node2)) {
4441 node2 = cy.filter(node2);
4442 }
4443 return outdegrees[node2.id()] / maxOutdegree;
4444 }
4445 };
4446 }
4447 },
4448 // degreeCentralityNormalized
4449 // Implemented from the algorithm in Opsahl's paper
4450 // "Node centrality in weighted networks: Generalizing degree and shortest paths"
4451 // check the heading 2 "Degree"
4452 degreeCentrality: function degreeCentrality(options) {
4453 options = defaults$f(options);
4454 var cy = this.cy();
4455 var callingEles = this;
4456 var _options = options, root2 = _options.root, weight = _options.weight, directed = _options.directed, alpha = _options.alpha;
4457 root2 = cy.collection(root2)[0];
4458 if (!directed) {
4459 var connEdges = root2.connectedEdges().intersection(callingEles);
4460 var k = connEdges.length;
4461 var s = 0;
4462 for (var i2 = 0; i2 < connEdges.length; i2++) {
4463 s += weight(connEdges[i2]);
4464 }
4465 return {
4466 degree: Math.pow(k, 1 - alpha) * Math.pow(s, alpha)
4467 };
4468 } else {
4469 var edges = root2.connectedEdges();
4470 var incoming = edges.filter(function(edge) {
4471 return edge.target().same(root2) && callingEles.has(edge);
4472 });
4473 var outgoing = edges.filter(function(edge) {
4474 return edge.source().same(root2) && callingEles.has(edge);
4475 });
4476 var k_in = incoming.length;
4477 var k_out = outgoing.length;
4478 var s_in = 0;
4479 var s_out = 0;
4480 for (var _i2 = 0; _i2 < incoming.length; _i2++) {
4481 s_in += weight(incoming[_i2]);
4482 }
4483 for (var _i3 = 0; _i3 < outgoing.length; _i3++) {
4484 s_out += weight(outgoing[_i3]);
4485 }
4486 return {
4487 indegree: Math.pow(k_in, 1 - alpha) * Math.pow(s_in, alpha),
4488 outdegree: Math.pow(k_out, 1 - alpha) * Math.pow(s_out, alpha)
4489 };
4490 }
4491 }
4492 // degreeCentrality
4493 };
4494 elesfn$n.dc = elesfn$n.degreeCentrality;
4495 elesfn$n.dcn = elesfn$n.degreeCentralityNormalised = elesfn$n.degreeCentralityNormalized;
4496 var defaults$e = defaults$g({
4497 harmonic: true,
4498 weight: function weight() {
4499 return 1;
4500 },
4501 directed: false,
4502 root: null
4503 });
4504 var elesfn$m = {
4505 closenessCentralityNormalized: function closenessCentralityNormalized(options) {
4506 var _defaults = defaults$e(options), harmonic = _defaults.harmonic, weight = _defaults.weight, directed = _defaults.directed;
4507 var cy = this.cy();
4508 var closenesses = {};
4509 var maxCloseness = 0;
4510 var nodes2 = this.nodes();
4511 var fw = this.floydWarshall({
4512 weight,
4513 directed
4514 });
4515 for (var i2 = 0; i2 < nodes2.length; i2++) {
4516 var currCloseness = 0;
4517 var node_i = nodes2[i2];
4518 for (var j = 0; j < nodes2.length; j++) {
4519 if (i2 !== j) {
4520 var d = fw.distance(node_i, nodes2[j]);
4521 if (harmonic) {
4522 currCloseness += 1 / d;
4523 } else {
4524 currCloseness += d;
4525 }
4526 }
4527 }
4528 if (!harmonic) {
4529 currCloseness = 1 / currCloseness;
4530 }
4531 if (maxCloseness < currCloseness) {
4532 maxCloseness = currCloseness;
4533 }
4534 closenesses[node_i.id()] = currCloseness;
4535 }
4536 return {
4537 closeness: function closeness(node) {
4538 if (maxCloseness == 0) {
4539 return 0;
4540 }
4541 if (string(node)) {
4542 node = cy.filter(node)[0].id();
4543 } else {
4544 node = node.id();
4545 }
4546 return closenesses[node] / maxCloseness;
4547 }
4548 };
4549 },
4550 // Implemented from pseudocode from wikipedia
4551 closenessCentrality: function closenessCentrality(options) {
4552 var _defaults2 = defaults$e(options), root2 = _defaults2.root, weight = _defaults2.weight, directed = _defaults2.directed, harmonic = _defaults2.harmonic;
4553 root2 = this.filter(root2)[0];
4554 var dijkstra = this.dijkstra({
4555 root: root2,
4556 weight,
4557 directed
4558 });
4559 var totalDistance = 0;
4560 var nodes2 = this.nodes();
4561 for (var i2 = 0; i2 < nodes2.length; i2++) {
4562 var n = nodes2[i2];
4563 if (!n.same(root2)) {
4564 var d = dijkstra.distanceTo(n);
4565 if (harmonic) {
4566 totalDistance += 1 / d;
4567 } else {
4568 totalDistance += d;
4569 }
4570 }
4571 }
4572 return harmonic ? totalDistance : 1 / totalDistance;
4573 }
4574 // closenessCentrality
4575 };
4576 elesfn$m.cc = elesfn$m.closenessCentrality;
4577 elesfn$m.ccn = elesfn$m.closenessCentralityNormalised = elesfn$m.closenessCentralityNormalized;
4578 var defaults$d = defaults$g({
4579 weight: null,
4580 directed: false
4581 });
4582 var elesfn$l = {
4583 // Implemented from the algorithm in the paper "On Variants of Shortest-Path Betweenness Centrality and their Generic Computation" by Ulrik Brandes
4584 betweennessCentrality: function betweennessCentrality(options) {
4585 var _defaults = defaults$d(options), directed = _defaults.directed, weight = _defaults.weight;
4586 var weighted = weight != null;
4587 var cy = this.cy();
4588 var V = this.nodes();
4589 var A = {};
4590 var _C = {};
4591 var max2 = 0;
4592 var C = {
4593 set: function set2(key, val) {
4594 _C[key] = val;
4595 if (val > max2) {
4596 max2 = val;
4597 }
4598 },
4599 get: function get2(key) {
4600 return _C[key];
4601 }
4602 };
4603 for (var i2 = 0; i2 < V.length; i2++) {
4604 var v = V[i2];
4605 var vid = v.id();
4606 if (directed) {
4607 A[vid] = v.outgoers().nodes();
4608 } else {
4609 A[vid] = v.openNeighborhood().nodes();
4610 }
4611 C.set(vid, 0);
4612 }
4613 var _loop = function _loop2(s2) {
4614 var sid = V[s2].id();
4615 var S = [];
4616 var P = {};
4617 var g = {};
4618 var d = {};
4619 var Q = new heap(function(a, b) {
4620 return d[a] - d[b];
4621 });
4622 for (var _i = 0; _i < V.length; _i++) {
4623 var _vid = V[_i].id();
4624 P[_vid] = [];
4625 g[_vid] = 0;
4626 d[_vid] = Infinity;
4627 }
4628 g[sid] = 1;
4629 d[sid] = 0;
4630 Q.push(sid);
4631 while (!Q.empty()) {
4632 var _v = Q.pop();
4633 S.push(_v);
4634 if (weighted) {
4635 for (var j = 0; j < A[_v].length; j++) {
4636 var w = A[_v][j];
4637 var vEle = cy.getElementById(_v);
4638 var edge = void 0;
4639 if (vEle.edgesTo(w).length > 0) {
4640 edge = vEle.edgesTo(w)[0];
4641 } else {
4642 edge = w.edgesTo(vEle)[0];
4643 }
4644 var edgeWeight = weight(edge);
4645 w = w.id();
4646 if (d[w] > d[_v] + edgeWeight) {
4647 d[w] = d[_v] + edgeWeight;
4648 if (Q.nodes.indexOf(w) < 0) {
4649 Q.push(w);
4650 } else {
4651 Q.updateItem(w);
4652 }
4653 g[w] = 0;
4654 P[w] = [];
4655 }
4656 if (d[w] == d[_v] + edgeWeight) {
4657 g[w] = g[w] + g[_v];
4658 P[w].push(_v);
4659 }
4660 }
4661 } else {
4662 for (var _j = 0; _j < A[_v].length; _j++) {
4663 var _w = A[_v][_j].id();
4664 if (d[_w] == Infinity) {
4665 Q.push(_w);
4666 d[_w] = d[_v] + 1;
4667 }
4668 if (d[_w] == d[_v] + 1) {
4669 g[_w] = g[_w] + g[_v];
4670 P[_w].push(_v);
4671 }
4672 }
4673 }
4674 }
4675 var e = {};
4676 for (var _i2 = 0; _i2 < V.length; _i2++) {
4677 e[V[_i2].id()] = 0;
4678 }
4679 while (S.length > 0) {
4680 var _w2 = S.pop();
4681 for (var _j2 = 0; _j2 < P[_w2].length; _j2++) {
4682 var _v2 = P[_w2][_j2];
4683 e[_v2] = e[_v2] + g[_v2] / g[_w2] * (1 + e[_w2]);
4684 }
4685 if (_w2 != V[s2].id()) {
4686 C.set(_w2, C.get(_w2) + e[_w2]);
4687 }
4688 }
4689 };
4690 for (var s = 0; s < V.length; s++) {
4691 _loop(s);
4692 }
4693 var ret = {
4694 betweenness: function betweenness(node) {
4695 var id = cy.collection(node).id();
4696 return C.get(id);
4697 },
4698 betweennessNormalized: function betweennessNormalized(node) {
4699 if (max2 == 0) {
4700 return 0;
4701 }
4702 var id = cy.collection(node).id();
4703 return C.get(id) / max2;
4704 }
4705 };
4706 ret.betweennessNormalised = ret.betweennessNormalized;
4707 return ret;
4708 }
4709 // betweennessCentrality
4710 };
4711 elesfn$l.bc = elesfn$l.betweennessCentrality;
4712 var defaults$c = defaults$g({
4713 expandFactor: 2,
4714 // affects time of computation and cluster granularity to some extent: M * M
4715 inflateFactor: 2,
4716 // affects cluster granularity (the greater the value, the more clusters): M(i,j) / E(j)
4717 multFactor: 1,
4718 // optional self loops for each node. Use a neutral value to improve cluster computations.
4719 maxIterations: 20,
4720 // maximum number of iterations of the MCL algorithm in a single run
4721 attributes: [
4722 // attributes/features used to group nodes, ie. similarity values between nodes
4723 function(edge) {
4724 return 1;
4725 }
4726 ]
4727 });
4728 var setOptions$3 = function setOptions2(options) {
4729 return defaults$c(options);
4730 };
4731 var getSimilarity$1 = function getSimilarity2(edge, attributes) {
4732 var total = 0;
4733 for (var i2 = 0; i2 < attributes.length; i2++) {
4734 total += attributes[i2](edge);
4735 }
4736 return total;
4737 };
4738 var addLoops = function addLoops2(M, n, val) {
4739 for (var i2 = 0; i2 < n; i2++) {
4740 M[i2 * n + i2] = val;
4741 }
4742 };
4743 var normalize = function normalize2(M, n) {
4744 var sum;
4745 for (var col = 0; col < n; col++) {
4746 sum = 0;
4747 for (var row = 0; row < n; row++) {
4748 sum += M[row * n + col];
4749 }
4750 for (var _row = 0; _row < n; _row++) {
4751 M[_row * n + col] = M[_row * n + col] / sum;
4752 }
4753 }
4754 };
4755 var mmult = function mmult2(A, B, n) {
4756 var C = new Array(n * n);
4757 for (var i2 = 0; i2 < n; i2++) {
4758 for (var j = 0; j < n; j++) {
4759 C[i2 * n + j] = 0;
4760 }
4761 for (var k = 0; k < n; k++) {
4762 for (var _j = 0; _j < n; _j++) {
4763 C[i2 * n + _j] += A[i2 * n + k] * B[k * n + _j];
4764 }
4765 }
4766 }
4767 return C;
4768 };
4769 var expand = function expand2(M, n, expandFactor) {
4770 var _M = M.slice(0);
4771 for (var p2 = 1; p2 < expandFactor; p2++) {
4772 M = mmult(M, _M, n);
4773 }
4774 return M;
4775 };
4776 var inflate = function inflate2(M, n, inflateFactor) {
4777 var _M = new Array(n * n);
4778 for (var i2 = 0; i2 < n * n; i2++) {
4779 _M[i2] = Math.pow(M[i2], inflateFactor);
4780 }
4781 normalize(_M, n);
4782 return _M;
4783 };
4784 var hasConverged = function hasConverged2(M, _M, n2, roundFactor) {
4785 for (var i2 = 0; i2 < n2; i2++) {
4786 var v1 = Math.round(M[i2] * Math.pow(10, roundFactor)) / Math.pow(10, roundFactor);
4787 var v2 = Math.round(_M[i2] * Math.pow(10, roundFactor)) / Math.pow(10, roundFactor);
4788 if (v1 !== v2) {
4789 return false;
4790 }
4791 }
4792 return true;
4793 };
4794 var assign$2 = function assign2(M, n, nodes2, cy) {
4795 var clusters = [];
4796 for (var i2 = 0; i2 < n; i2++) {
4797 var cluster = [];
4798 for (var j = 0; j < n; j++) {
4799 if (Math.round(M[i2 * n + j] * 1e3) / 1e3 > 0) {
4800 cluster.push(nodes2[j]);
4801 }
4802 }
4803 if (cluster.length !== 0) {
4804 clusters.push(cy.collection(cluster));
4805 }
4806 }
4807 return clusters;
4808 };
4809 var isDuplicate = function isDuplicate2(c1, c2) {
4810 for (var i2 = 0; i2 < c1.length; i2++) {
4811 if (!c2[i2] || c1[i2].id() !== c2[i2].id()) {
4812 return false;
4813 }
4814 }
4815 return true;
4816 };
4817 var removeDuplicates = function removeDuplicates2(clusters) {
4818 for (var i2 = 0; i2 < clusters.length; i2++) {
4819 for (var j = 0; j < clusters.length; j++) {
4820 if (i2 != j && isDuplicate(clusters[i2], clusters[j])) {
4821 clusters.splice(j, 1);
4822 }
4823 }
4824 }
4825 return clusters;
4826 };
4827 var markovClustering = function markovClustering2(options) {
4828 var nodes2 = this.nodes();
4829 var edges = this.edges();
4830 var cy = this.cy();
4831 var opts = setOptions$3(options);
4832 var id2position = {};
4833 for (var i2 = 0; i2 < nodes2.length; i2++) {
4834 id2position[nodes2[i2].id()] = i2;
4835 }
4836 var n = nodes2.length, n2 = n * n;
4837 var M = new Array(n2), _M;
4838 for (var _i = 0; _i < n2; _i++) {
4839 M[_i] = 0;
4840 }
4841 for (var e = 0; e < edges.length; e++) {
4842 var edge = edges[e];
4843 var _i2 = id2position[edge.source().id()];
4844 var j = id2position[edge.target().id()];
4845 var sim = getSimilarity$1(edge, opts.attributes);
4846 M[_i2 * n + j] += sim;
4847 M[j * n + _i2] += sim;
4848 }
4849 addLoops(M, n, opts.multFactor);
4850 normalize(M, n);
4851 var isStillMoving = true;
4852 var iterations = 0;
4853 while (isStillMoving && iterations < opts.maxIterations) {
4854 isStillMoving = false;
4855 _M = expand(M, n, opts.expandFactor);
4856 M = inflate(_M, n, opts.inflateFactor);
4857 if (!hasConverged(M, _M, n2, 4)) {
4858 isStillMoving = true;
4859 }
4860 iterations++;
4861 }
4862 var clusters = assign$2(M, n, nodes2, cy);
4863 clusters = removeDuplicates(clusters);
4864 return clusters;
4865 };
4866 var markovClustering$1 = {
4867 markovClustering,
4868 mcl: markovClustering
4869 };
4870 var identity = function identity2(x) {
4871 return x;
4872 };
4873 var absDiff = function absDiff2(p2, q) {
4874 return Math.abs(q - p2);
4875 };
4876 var addAbsDiff = function addAbsDiff2(total, p2, q) {
4877 return total + absDiff(p2, q);
4878 };
4879 var addSquaredDiff = function addSquaredDiff2(total, p2, q) {
4880 return total + Math.pow(q - p2, 2);
4881 };
4882 var sqrt = function sqrt3(x) {
4883 return Math.sqrt(x);
4884 };
4885 var maxAbsDiff = function maxAbsDiff2(currentMax, p2, q) {
4886 return Math.max(currentMax, absDiff(p2, q));
4887 };
4888 var getDistance = function getDistance2(length, getP, getQ, init, visit) {
4889 var post = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : identity;
4890 var ret = init;
4891 var p2, q;
4892 for (var dim = 0; dim < length; dim++) {
4893 p2 = getP(dim);
4894 q = getQ(dim);
4895 ret = visit(ret, p2, q);
4896 }
4897 return post(ret);
4898 };
4899 var distances = {
4900 euclidean: function euclidean(length, getP, getQ) {
4901 if (length >= 2) {
4902 return getDistance(length, getP, getQ, 0, addSquaredDiff, sqrt);
4903 } else {
4904 return getDistance(length, getP, getQ, 0, addAbsDiff);
4905 }
4906 },
4907 squaredEuclidean: function squaredEuclidean(length, getP, getQ) {
4908 return getDistance(length, getP, getQ, 0, addSquaredDiff);
4909 },
4910 manhattan: function manhattan(length, getP, getQ) {
4911 return getDistance(length, getP, getQ, 0, addAbsDiff);
4912 },
4913 max: function max2(length, getP, getQ) {
4914 return getDistance(length, getP, getQ, -Infinity, maxAbsDiff);
4915 }
4916 };
4917 distances["squared-euclidean"] = distances["squaredEuclidean"];
4918 distances["squaredeuclidean"] = distances["squaredEuclidean"];
4919 function clusteringDistance(method, length, getP, getQ, nodeP, nodeQ) {
4920 var impl2;
4921 if (fn$6(method)) {
4922 impl2 = method;
4923 } else {
4924 impl2 = distances[method] || distances.euclidean;
4925 }
4926 if (length === 0 && fn$6(method)) {
4927 return impl2(nodeP, nodeQ);
4928 } else {
4929 return impl2(length, getP, getQ, nodeP, nodeQ);
4930 }
4931 }
4932 var defaults$b = defaults$g({
4933 k: 2,
4934 m: 2,
4935 sensitivityThreshold: 1e-4,
4936 distance: "euclidean",
4937 maxIterations: 10,
4938 attributes: [],
4939 testMode: false,
4940 testCentroids: null
4941 });
4942 var setOptions$2 = function setOptions2(options) {
4943 return defaults$b(options);
4944 };
4945 var getDist = function getDist2(type, node, centroid, attributes, mode) {
4946 var noNodeP = mode !== "kMedoids";
4947 var getP = noNodeP ? function(i2) {
4948 return centroid[i2];
4949 } : function(i2) {
4950 return attributes[i2](centroid);
4951 };
4952 var getQ = function getQ2(i2) {
4953 return attributes[i2](node);
4954 };
4955 var nodeP = centroid;
4956 var nodeQ = node;
4957 return clusteringDistance(type, attributes.length, getP, getQ, nodeP, nodeQ);
4958 };
4959 var randomCentroids = function randomCentroids2(nodes2, k, attributes) {
4960 var ndim = attributes.length;
4961 var min2 = new Array(ndim);
4962 var max2 = new Array(ndim);
4963 var centroids = new Array(k);
4964 var centroid = null;
4965 for (var i2 = 0; i2 < ndim; i2++) {
4966 min2[i2] = nodes2.min(attributes[i2]).value;
4967 max2[i2] = nodes2.max(attributes[i2]).value;
4968 }
4969 for (var c = 0; c < k; c++) {
4970 centroid = [];
4971 for (var _i = 0; _i < ndim; _i++) {
4972 centroid[_i] = Math.random() * (max2[_i] - min2[_i]) + min2[_i];
4973 }
4974 centroids[c] = centroid;
4975 }
4976 return centroids;
4977 };
4978 var classify = function classify2(node, centroids, distance, attributes, type) {
4979 var min2 = Infinity;
4980 var index = 0;
4981 for (var i2 = 0; i2 < centroids.length; i2++) {
4982 var dist2 = getDist(distance, node, centroids[i2], attributes, type);
4983 if (dist2 < min2) {
4984 min2 = dist2;
4985 index = i2;
4986 }
4987 }
4988 return index;
4989 };
4990 var buildCluster = function buildCluster2(centroid, nodes2, assignment) {
4991 var cluster = [];
4992 var node = null;
4993 for (var n = 0; n < nodes2.length; n++) {
4994 node = nodes2[n];
4995 if (assignment[node.id()] === centroid) {
4996 cluster.push(node);
4997 }
4998 }
4999 return cluster;
5000 };
5001 var haveValuesConverged = function haveValuesConverged2(v1, v2, sensitivityThreshold) {
5002 return Math.abs(v2 - v1) <= sensitivityThreshold;
5003 };
5004 var haveMatricesConverged = function haveMatricesConverged2(v1, v2, sensitivityThreshold) {
5005 for (var i2 = 0; i2 < v1.length; i2++) {
5006 for (var j = 0; j < v1[i2].length; j++) {
5007 var diff = Math.abs(v1[i2][j] - v2[i2][j]);
5008 if (diff > sensitivityThreshold) {
5009 return false;
5010 }
5011 }
5012 }
5013 return true;
5014 };
5015 var seenBefore = function seenBefore2(node, medoids, n) {
5016 for (var i2 = 0; i2 < n; i2++) {
5017 if (node === medoids[i2])
5018 return true;
5019 }
5020 return false;
5021 };
5022 var randomMedoids = function randomMedoids2(nodes2, k) {
5023 var medoids = new Array(k);
5024 if (nodes2.length < 50) {
5025 for (var i2 = 0; i2 < k; i2++) {
5026 var node = nodes2[Math.floor(Math.random() * nodes2.length)];
5027 while (seenBefore(node, medoids, i2)) {
5028 node = nodes2[Math.floor(Math.random() * nodes2.length)];
5029 }
5030 medoids[i2] = node;
5031 }
5032 } else {
5033 for (var _i2 = 0; _i2 < k; _i2++) {
5034 medoids[_i2] = nodes2[Math.floor(Math.random() * nodes2.length)];
5035 }
5036 }
5037 return medoids;
5038 };
5039 var findCost = function findCost2(potentialNewMedoid, cluster, attributes) {
5040 var cost = 0;
5041 for (var n = 0; n < cluster.length; n++) {
5042 cost += getDist("manhattan", cluster[n], potentialNewMedoid, attributes, "kMedoids");
5043 }
5044 return cost;
5045 };
5046 var kMeans = function kMeans2(options) {
5047 var cy = this.cy();
5048 var nodes2 = this.nodes();
5049 var node = null;
5050 var opts = setOptions$2(options);
5051 var clusters = new Array(opts.k);
5052 var assignment = {};
5053 var centroids;
5054 if (opts.testMode) {
5055 if (typeof opts.testCentroids === "number") {
5056 opts.testCentroids;
5057 centroids = randomCentroids(nodes2, opts.k, opts.attributes);
5058 } else if (_typeof(opts.testCentroids) === "object") {
5059 centroids = opts.testCentroids;
5060 } else {
5061 centroids = randomCentroids(nodes2, opts.k, opts.attributes);
5062 }
5063 } else {
5064 centroids = randomCentroids(nodes2, opts.k, opts.attributes);
5065 }
5066 var isStillMoving = true;
5067 var iterations = 0;
5068 while (isStillMoving && iterations < opts.maxIterations) {
5069 for (var n = 0; n < nodes2.length; n++) {
5070 node = nodes2[n];
5071 assignment[node.id()] = classify(node, centroids, opts.distance, opts.attributes, "kMeans");
5072 }
5073 isStillMoving = false;
5074 for (var c = 0; c < opts.k; c++) {
5075 var cluster = buildCluster(c, nodes2, assignment);
5076 if (cluster.length === 0) {
5077 continue;
5078 }
5079 var ndim = opts.attributes.length;
5080 var centroid = centroids[c];
5081 var newCentroid = new Array(ndim);
5082 var sum = new Array(ndim);
5083 for (var d = 0; d < ndim; d++) {
5084 sum[d] = 0;
5085 for (var i2 = 0; i2 < cluster.length; i2++) {
5086 node = cluster[i2];
5087 sum[d] += opts.attributes[d](node);
5088 }
5089 newCentroid[d] = sum[d] / cluster.length;
5090 if (!haveValuesConverged(newCentroid[d], centroid[d], opts.sensitivityThreshold)) {
5091 isStillMoving = true;
5092 }
5093 }
5094 centroids[c] = newCentroid;
5095 clusters[c] = cy.collection(cluster);
5096 }
5097 iterations++;
5098 }
5099 return clusters;
5100 };
5101 var kMedoids = function kMedoids2(options) {
5102 var cy = this.cy();
5103 var nodes2 = this.nodes();
5104 var node = null;
5105 var opts = setOptions$2(options);
5106 var clusters = new Array(opts.k);
5107 var medoids;
5108 var assignment = {};
5109 var curCost;
5110 var minCosts = new Array(opts.k);
5111 if (opts.testMode) {
5112 if (typeof opts.testCentroids === "number")
5113 ;
5114 else if (_typeof(opts.testCentroids) === "object") {
5115 medoids = opts.testCentroids;
5116 } else {
5117 medoids = randomMedoids(nodes2, opts.k);
5118 }
5119 } else {
5120 medoids = randomMedoids(nodes2, opts.k);
5121 }
5122 var isStillMoving = true;
5123 var iterations = 0;
5124 while (isStillMoving && iterations < opts.maxIterations) {
5125 for (var n = 0; n < nodes2.length; n++) {
5126 node = nodes2[n];
5127 assignment[node.id()] = classify(node, medoids, opts.distance, opts.attributes, "kMedoids");
5128 }
5129 isStillMoving = false;
5130 for (var m = 0; m < medoids.length; m++) {
5131 var cluster = buildCluster(m, nodes2, assignment);
5132 if (cluster.length === 0) {
5133 continue;
5134 }
5135 minCosts[m] = findCost(medoids[m], cluster, opts.attributes);
5136 for (var _n = 0; _n < cluster.length; _n++) {
5137 curCost = findCost(cluster[_n], cluster, opts.attributes);
5138 if (curCost < minCosts[m]) {
5139 minCosts[m] = curCost;
5140 medoids[m] = cluster[_n];
5141 isStillMoving = true;
5142 }
5143 }
5144 clusters[m] = cy.collection(cluster);
5145 }
5146 iterations++;
5147 }
5148 return clusters;
5149 };
5150 var updateCentroids = function updateCentroids2(centroids, nodes2, U, weight, opts) {
5151 var numerator, denominator;
5152 for (var n = 0; n < nodes2.length; n++) {
5153 for (var c = 0; c < centroids.length; c++) {
5154 weight[n][c] = Math.pow(U[n][c], opts.m);
5155 }
5156 }
5157 for (var _c = 0; _c < centroids.length; _c++) {
5158 for (var dim = 0; dim < opts.attributes.length; dim++) {
5159 numerator = 0;
5160 denominator = 0;
5161 for (var _n2 = 0; _n2 < nodes2.length; _n2++) {
5162 numerator += weight[_n2][_c] * opts.attributes[dim](nodes2[_n2]);
5163 denominator += weight[_n2][_c];
5164 }
5165 centroids[_c][dim] = numerator / denominator;
5166 }
5167 }
5168 };
5169 var updateMembership = function updateMembership2(U, _U, centroids, nodes2, opts) {
5170 for (var i2 = 0; i2 < U.length; i2++) {
5171 _U[i2] = U[i2].slice();
5172 }
5173 var sum, numerator, denominator;
5174 var pow = 2 / (opts.m - 1);
5175 for (var c = 0; c < centroids.length; c++) {
5176 for (var n = 0; n < nodes2.length; n++) {
5177 sum = 0;
5178 for (var k = 0; k < centroids.length; k++) {
5179 numerator = getDist(opts.distance, nodes2[n], centroids[c], opts.attributes, "cmeans");
5180 denominator = getDist(opts.distance, nodes2[n], centroids[k], opts.attributes, "cmeans");
5181 sum += Math.pow(numerator / denominator, pow);
5182 }
5183 U[n][c] = 1 / sum;
5184 }
5185 }
5186 };
5187 var assign$1 = function assign2(nodes2, U, opts, cy) {
5188 var clusters = new Array(opts.k);
5189 for (var c = 0; c < clusters.length; c++) {
5190 clusters[c] = [];
5191 }
5192 var max2;
5193 var index;
5194 for (var n = 0; n < U.length; n++) {
5195 max2 = -Infinity;
5196 index = -1;
5197 for (var _c2 = 0; _c2 < U[0].length; _c2++) {
5198 if (U[n][_c2] > max2) {
5199 max2 = U[n][_c2];
5200 index = _c2;
5201 }
5202 }
5203 clusters[index].push(nodes2[n]);
5204 }
5205 for (var _c3 = 0; _c3 < clusters.length; _c3++) {
5206 clusters[_c3] = cy.collection(clusters[_c3]);
5207 }
5208 return clusters;
5209 };
5210 var fuzzyCMeans = function fuzzyCMeans2(options) {
5211 var cy = this.cy();
5212 var nodes2 = this.nodes();
5213 var opts = setOptions$2(options);
5214 var clusters;
5215 var centroids;
5216 var U;
5217 var _U;
5218 var weight;
5219 _U = new Array(nodes2.length);
5220 for (var i2 = 0; i2 < nodes2.length; i2++) {
5221 _U[i2] = new Array(opts.k);
5222 }
5223 U = new Array(nodes2.length);
5224 for (var _i3 = 0; _i3 < nodes2.length; _i3++) {
5225 U[_i3] = new Array(opts.k);
5226 }
5227 for (var _i4 = 0; _i4 < nodes2.length; _i4++) {
5228 var total = 0;
5229 for (var j = 0; j < opts.k; j++) {
5230 U[_i4][j] = Math.random();
5231 total += U[_i4][j];
5232 }
5233 for (var _j = 0; _j < opts.k; _j++) {
5234 U[_i4][_j] = U[_i4][_j] / total;
5235 }
5236 }
5237 centroids = new Array(opts.k);
5238 for (var _i5 = 0; _i5 < opts.k; _i5++) {
5239 centroids[_i5] = new Array(opts.attributes.length);
5240 }
5241 weight = new Array(nodes2.length);
5242 for (var _i6 = 0; _i6 < nodes2.length; _i6++) {
5243 weight[_i6] = new Array(opts.k);
5244 }
5245 var isStillMoving = true;
5246 var iterations = 0;
5247 while (isStillMoving && iterations < opts.maxIterations) {
5248 isStillMoving = false;
5249 updateCentroids(centroids, nodes2, U, weight, opts);
5250 updateMembership(U, _U, centroids, nodes2, opts);
5251 if (!haveMatricesConverged(U, _U, opts.sensitivityThreshold)) {
5252 isStillMoving = true;
5253 }
5254 iterations++;
5255 }
5256 clusters = assign$1(nodes2, U, opts, cy);
5257 return {
5258 clusters,
5259 degreeOfMembership: U
5260 };
5261 };
5262 var kClustering = {
5263 kMeans,
5264 kMedoids,
5265 fuzzyCMeans,
5266 fcm: fuzzyCMeans
5267 };
5268 var defaults$a = defaults$g({
5269 distance: "euclidean",
5270 // distance metric to compare nodes
5271 linkage: "min",
5272 // linkage criterion : how to determine the distance between clusters of nodes
5273 mode: "threshold",
5274 // mode:'threshold' => clusters must be threshold distance apart
5275 threshold: Infinity,
5276 // the distance threshold
5277 // mode:'dendrogram' => the nodes are organised as leaves in a tree (siblings are close), merging makes clusters
5278 addDendrogram: false,
5279 // whether to add the dendrogram to the graph for viz
5280 dendrogramDepth: 0,
5281 // depth at which dendrogram branches are merged into the returned clusters
5282 attributes: []
5283 // array of attr functions
5284 });
5285 var linkageAliases = {
5286 "single": "min",
5287 "complete": "max"
5288 };
5289 var setOptions$1 = function setOptions2(options) {
5290 var opts = defaults$a(options);
5291 var preferredAlias = linkageAliases[opts.linkage];
5292 if (preferredAlias != null) {
5293 opts.linkage = preferredAlias;
5294 }
5295 return opts;
5296 };
5297 var mergeClosest = function mergeClosest2(clusters, index, dists, mins, opts) {
5298 var minKey = 0;
5299 var min2 = Infinity;
5300 var dist2;
5301 var attrs = opts.attributes;
5302 var getDist2 = function getDist3(n1, n2) {
5303 return clusteringDistance(opts.distance, attrs.length, function(i3) {
5304 return attrs[i3](n1);
5305 }, function(i3) {
5306 return attrs[i3](n2);
5307 }, n1, n2);
5308 };
5309 for (var i2 = 0; i2 < clusters.length; i2++) {
5310 var key = clusters[i2].key;
5311 var _dist = dists[key][mins[key]];
5312 if (_dist < min2) {
5313 minKey = key;
5314 min2 = _dist;
5315 }
5316 }
5317 if (opts.mode === "threshold" && min2 >= opts.threshold || opts.mode === "dendrogram" && clusters.length === 1) {
5318 return false;
5319 }
5320 var c1 = index[minKey];
5321 var c2 = index[mins[minKey]];
5322 var merged;
5323 if (opts.mode === "dendrogram") {
5324 merged = {
5325 left: c1,
5326 right: c2,
5327 key: c1.key
5328 };
5329 } else {
5330 merged = {
5331 value: c1.value.concat(c2.value),
5332 key: c1.key
5333 };
5334 }
5335 clusters[c1.index] = merged;
5336 clusters.splice(c2.index, 1);
5337 index[c1.key] = merged;
5338 for (var _i = 0; _i < clusters.length; _i++) {
5339 var cur = clusters[_i];
5340 if (c1.key === cur.key) {
5341 dist2 = Infinity;
5342 } else if (opts.linkage === "min") {
5343 dist2 = dists[c1.key][cur.key];
5344 if (dists[c1.key][cur.key] > dists[c2.key][cur.key]) {
5345 dist2 = dists[c2.key][cur.key];
5346 }
5347 } else if (opts.linkage === "max") {
5348 dist2 = dists[c1.key][cur.key];
5349 if (dists[c1.key][cur.key] < dists[c2.key][cur.key]) {
5350 dist2 = dists[c2.key][cur.key];
5351 }
5352 } else if (opts.linkage === "mean") {
5353 dist2 = (dists[c1.key][cur.key] * c1.size + dists[c2.key][cur.key] * c2.size) / (c1.size + c2.size);
5354 } else {
5355 if (opts.mode === "dendrogram")
5356 dist2 = getDist2(cur.value, c1.value);
5357 else
5358 dist2 = getDist2(cur.value[0], c1.value[0]);
5359 }
5360 dists[c1.key][cur.key] = dists[cur.key][c1.key] = dist2;
5361 }
5362 for (var _i2 = 0; _i2 < clusters.length; _i2++) {
5363 var key1 = clusters[_i2].key;
5364 if (mins[key1] === c1.key || mins[key1] === c2.key) {
5365 var _min = key1;
5366 for (var j = 0; j < clusters.length; j++) {
5367 var key2 = clusters[j].key;
5368 if (dists[key1][key2] < dists[key1][_min]) {
5369 _min = key2;
5370 }
5371 }
5372 mins[key1] = _min;
5373 }
5374 clusters[_i2].index = _i2;
5375 }
5376 c1.key = c2.key = c1.index = c2.index = null;
5377 return true;
5378 };
5379 var getAllChildren = function getAllChildren2(root2, arr, cy) {
5380 if (!root2)
5381 return;
5382 if (root2.value) {
5383 arr.push(root2.value);
5384 } else {
5385 if (root2.left)
5386 getAllChildren2(root2.left, arr);
5387 if (root2.right)
5388 getAllChildren2(root2.right, arr);
5389 }
5390 };
5391 var buildDendrogram = function buildDendrogram2(root2, cy) {
5392 if (!root2)
5393 return "";
5394 if (root2.left && root2.right) {
5395 var leftStr = buildDendrogram2(root2.left, cy);
5396 var rightStr = buildDendrogram2(root2.right, cy);
5397 var node = cy.add({
5398 group: "nodes",
5399 data: {
5400 id: leftStr + "," + rightStr
5401 }
5402 });
5403 cy.add({
5404 group: "edges",
5405 data: {
5406 source: leftStr,
5407 target: node.id()
5408 }
5409 });
5410 cy.add({
5411 group: "edges",
5412 data: {
5413 source: rightStr,
5414 target: node.id()
5415 }
5416 });
5417 return node.id();
5418 } else if (root2.value) {
5419 return root2.value.id();
5420 }
5421 };
5422 var buildClustersFromTree = function buildClustersFromTree2(root2, k, cy) {
5423 if (!root2)
5424 return [];
5425 var left = [], right = [], leaves = [];
5426 if (k === 0) {
5427 if (root2.left)
5428 getAllChildren(root2.left, left);
5429 if (root2.right)
5430 getAllChildren(root2.right, right);
5431 leaves = left.concat(right);
5432 return [cy.collection(leaves)];
5433 } else if (k === 1) {
5434 if (root2.value) {
5435 return [cy.collection(root2.value)];
5436 } else {
5437 if (root2.left)
5438 getAllChildren(root2.left, left);
5439 if (root2.right)
5440 getAllChildren(root2.right, right);
5441 return [cy.collection(left), cy.collection(right)];
5442 }
5443 } else {
5444 if (root2.value) {
5445 return [cy.collection(root2.value)];
5446 } else {
5447 if (root2.left)
5448 left = buildClustersFromTree2(root2.left, k - 1, cy);
5449 if (root2.right)
5450 right = buildClustersFromTree2(root2.right, k - 1, cy);
5451 return left.concat(right);
5452 }
5453 }
5454 };
5455 var hierarchicalClustering = function hierarchicalClustering2(options) {
5456 var cy = this.cy();
5457 var nodes2 = this.nodes();
5458 var opts = setOptions$1(options);
5459 var attrs = opts.attributes;
5460 var getDist2 = function getDist3(n1, n2) {
5461 return clusteringDistance(opts.distance, attrs.length, function(i3) {
5462 return attrs[i3](n1);
5463 }, function(i3) {
5464 return attrs[i3](n2);
5465 }, n1, n2);
5466 };
5467 var clusters = [];
5468 var dists = [];
5469 var mins = [];
5470 var index = [];
5471 for (var n = 0; n < nodes2.length; n++) {
5472 var cluster = {
5473 value: opts.mode === "dendrogram" ? nodes2[n] : [nodes2[n]],
5474 key: n,
5475 index: n
5476 };
5477 clusters[n] = cluster;
5478 index[n] = cluster;
5479 dists[n] = [];
5480 mins[n] = 0;
5481 }
5482 for (var i2 = 0; i2 < clusters.length; i2++) {
5483 for (var j = 0; j <= i2; j++) {
5484 var dist2 = void 0;
5485 if (opts.mode === "dendrogram") {
5486 dist2 = i2 === j ? Infinity : getDist2(clusters[i2].value, clusters[j].value);
5487 } else {
5488 dist2 = i2 === j ? Infinity : getDist2(clusters[i2].value[0], clusters[j].value[0]);
5489 }
5490 dists[i2][j] = dist2;
5491 dists[j][i2] = dist2;
5492 if (dist2 < dists[i2][mins[i2]]) {
5493 mins[i2] = j;
5494 }
5495 }
5496 }
5497 var merged = mergeClosest(clusters, index, dists, mins, opts);
5498 while (merged) {
5499 merged = mergeClosest(clusters, index, dists, mins, opts);
5500 }
5501 var retClusters;
5502 if (opts.mode === "dendrogram") {
5503 retClusters = buildClustersFromTree(clusters[0], opts.dendrogramDepth, cy);
5504 if (opts.addDendrogram)
5505 buildDendrogram(clusters[0], cy);
5506 } else {
5507 retClusters = new Array(clusters.length);
5508 clusters.forEach(function(cluster2, i3) {
5509 cluster2.key = cluster2.index = null;
5510 retClusters[i3] = cy.collection(cluster2.value);
5511 });
5512 }
5513 return retClusters;
5514 };
5515 var hierarchicalClustering$1 = {
5516 hierarchicalClustering,
5517 hca: hierarchicalClustering
5518 };
5519 var defaults$9 = defaults$g({
5520 distance: "euclidean",
5521 // distance metric to compare attributes between two nodes
5522 preference: "median",
5523 // suitability of a data point to serve as an exemplar
5524 damping: 0.8,
5525 // damping factor between [0.5, 1)
5526 maxIterations: 1e3,
5527 // max number of iterations to run
5528 minIterations: 100,
5529 // min number of iterations to run in order for clustering to stop
5530 attributes: [
5531 // functions to quantify the similarity between any two points
5532 // e.g. node => node.data('weight')
5533 ]
5534 });
5535 var setOptions = function setOptions2(options) {
5536 var dmp = options.damping;
5537 var pref = options.preference;
5538 if (!(0.5 <= dmp && dmp < 1)) {
5539 error("Damping must range on [0.5, 1). Got: ".concat(dmp));
5540 }
5541 var validPrefs = ["median", "mean", "min", "max"];
5542 if (!(validPrefs.some(function(v) {
5543 return v === pref;
5544 }) || number$1(pref))) {
5545 error("Preference must be one of [".concat(validPrefs.map(function(p2) {
5546 return "'".concat(p2, "'");
5547 }).join(", "), "] or a number. Got: ").concat(pref));
5548 }
5549 return defaults$9(options);
5550 };
5551 var getSimilarity = function getSimilarity2(type, n1, n2, attributes) {
5552 var attr = function attr2(n, i2) {
5553 return attributes[i2](n);
5554 };
5555 return -clusteringDistance(type, attributes.length, function(i2) {
5556 return attr(n1, i2);
5557 }, function(i2) {
5558 return attr(n2, i2);
5559 }, n1, n2);
5560 };
5561 var getPreference = function getPreference2(S, preference) {
5562 var p2 = null;
5563 if (preference === "median") {
5564 p2 = median(S);
5565 } else if (preference === "mean") {
5566 p2 = mean(S);
5567 } else if (preference === "min") {
5568 p2 = min(S);
5569 } else if (preference === "max") {
5570 p2 = max(S);
5571 } else {
5572 p2 = preference;
5573 }
5574 return p2;
5575 };
5576 var findExemplars = function findExemplars2(n, R, A) {
5577 var indices = [];
5578 for (var i2 = 0; i2 < n; i2++) {
5579 if (R[i2 * n + i2] + A[i2 * n + i2] > 0) {
5580 indices.push(i2);
5581 }
5582 }
5583 return indices;
5584 };
5585 var assignClusters = function assignClusters2(n, S, exemplars) {
5586 var clusters = [];
5587 for (var i2 = 0; i2 < n; i2++) {
5588 var index = -1;
5589 var max2 = -Infinity;
5590 for (var ei = 0; ei < exemplars.length; ei++) {
5591 var e = exemplars[ei];
5592 if (S[i2 * n + e] > max2) {
5593 index = e;
5594 max2 = S[i2 * n + e];
5595 }
5596 }
5597 if (index > 0) {
5598 clusters.push(index);
5599 }
5600 }
5601 for (var _ei = 0; _ei < exemplars.length; _ei++) {
5602 clusters[exemplars[_ei]] = exemplars[_ei];
5603 }
5604 return clusters;
5605 };
5606 var assign = function assign2(n, S, exemplars) {
5607 var clusters = assignClusters(n, S, exemplars);
5608 for (var ei = 0; ei < exemplars.length; ei++) {
5609 var ii = [];
5610 for (var c = 0; c < clusters.length; c++) {
5611 if (clusters[c] === exemplars[ei]) {
5612 ii.push(c);
5613 }
5614 }
5615 var maxI = -1;
5616 var maxSum = -Infinity;
5617 for (var i2 = 0; i2 < ii.length; i2++) {
5618 var sum = 0;
5619 for (var j = 0; j < ii.length; j++) {
5620 sum += S[ii[j] * n + ii[i2]];
5621 }
5622 if (sum > maxSum) {
5623 maxI = i2;
5624 maxSum = sum;
5625 }
5626 }
5627 exemplars[ei] = ii[maxI];
5628 }
5629 clusters = assignClusters(n, S, exemplars);
5630 return clusters;
5631 };
5632 var affinityPropagation = function affinityPropagation2(options) {
5633 var cy = this.cy();
5634 var nodes2 = this.nodes();
5635 var opts = setOptions(options);
5636 var id2position = {};
5637 for (var i2 = 0; i2 < nodes2.length; i2++) {
5638 id2position[nodes2[i2].id()] = i2;
5639 }
5640 var n;
5641 var n2;
5642 var S;
5643 var p2;
5644 var R;
5645 var A;
5646 n = nodes2.length;
5647 n2 = n * n;
5648 S = new Array(n2);
5649 for (var _i = 0; _i < n2; _i++) {
5650 S[_i] = -Infinity;
5651 }
5652 for (var _i2 = 0; _i2 < n; _i2++) {
5653 for (var j = 0; j < n; j++) {
5654 if (_i2 !== j) {
5655 S[_i2 * n + j] = getSimilarity(opts.distance, nodes2[_i2], nodes2[j], opts.attributes);
5656 }
5657 }
5658 }
5659 p2 = getPreference(S, opts.preference);
5660 for (var _i3 = 0; _i3 < n; _i3++) {
5661 S[_i3 * n + _i3] = p2;
5662 }
5663 R = new Array(n2);
5664 for (var _i4 = 0; _i4 < n2; _i4++) {
5665 R[_i4] = 0;
5666 }
5667 A = new Array(n2);
5668 for (var _i5 = 0; _i5 < n2; _i5++) {
5669 A[_i5] = 0;
5670 }
5671 var old = new Array(n);
5672 var Rp = new Array(n);
5673 var se = new Array(n);
5674 for (var _i6 = 0; _i6 < n; _i6++) {
5675 old[_i6] = 0;
5676 Rp[_i6] = 0;
5677 se[_i6] = 0;
5678 }
5679 var e = new Array(n * opts.minIterations);
5680 for (var _i7 = 0; _i7 < e.length; _i7++) {
5681 e[_i7] = 0;
5682 }
5683 var iter;
5684 for (iter = 0; iter < opts.maxIterations; iter++) {
5685 for (var _i8 = 0; _i8 < n; _i8++) {
5686 var max2 = -Infinity, max22 = -Infinity, maxI = -1, AS = 0;
5687 for (var _j = 0; _j < n; _j++) {
5688 old[_j] = R[_i8 * n + _j];
5689 AS = A[_i8 * n + _j] + S[_i8 * n + _j];
5690 if (AS >= max2) {
5691 max22 = max2;
5692 max2 = AS;
5693 maxI = _j;
5694 } else if (AS > max22) {
5695 max22 = AS;
5696 }
5697 }
5698 for (var _j2 = 0; _j2 < n; _j2++) {
5699 R[_i8 * n + _j2] = (1 - opts.damping) * (S[_i8 * n + _j2] - max2) + opts.damping * old[_j2];
5700 }
5701 R[_i8 * n + maxI] = (1 - opts.damping) * (S[_i8 * n + maxI] - max22) + opts.damping * old[maxI];
5702 }
5703 for (var _i9 = 0; _i9 < n; _i9++) {
5704 var sum = 0;
5705 for (var _j3 = 0; _j3 < n; _j3++) {
5706 old[_j3] = A[_j3 * n + _i9];
5707 Rp[_j3] = Math.max(0, R[_j3 * n + _i9]);
5708 sum += Rp[_j3];
5709 }
5710 sum -= Rp[_i9];
5711 Rp[_i9] = R[_i9 * n + _i9];
5712 sum += Rp[_i9];
5713 for (var _j4 = 0; _j4 < n; _j4++) {
5714 A[_j4 * n + _i9] = (1 - opts.damping) * Math.min(0, sum - Rp[_j4]) + opts.damping * old[_j4];
5715 }
5716 A[_i9 * n + _i9] = (1 - opts.damping) * (sum - Rp[_i9]) + opts.damping * old[_i9];
5717 }
5718 var K2 = 0;
5719 for (var _i10 = 0; _i10 < n; _i10++) {
5720 var E = A[_i10 * n + _i10] + R[_i10 * n + _i10] > 0 ? 1 : 0;
5721 e[iter % opts.minIterations * n + _i10] = E;
5722 K2 += E;
5723 }
5724 if (K2 > 0 && (iter >= opts.minIterations - 1 || iter == opts.maxIterations - 1)) {
5725 var _sum = 0;
5726 for (var _i11 = 0; _i11 < n; _i11++) {
5727 se[_i11] = 0;
5728 for (var _j5 = 0; _j5 < opts.minIterations; _j5++) {
5729 se[_i11] += e[_j5 * n + _i11];
5730 }
5731 if (se[_i11] === 0 || se[_i11] === opts.minIterations) {
5732 _sum++;
5733 }
5734 }
5735 if (_sum === n) {
5736 break;
5737 }
5738 }
5739 }
5740 var exemplarsIndices = findExemplars(n, R, A);
5741 var clusterIndices = assign(n, S, exemplarsIndices);
5742 var clusters = {};
5743 for (var c = 0; c < exemplarsIndices.length; c++) {
5744 clusters[exemplarsIndices[c]] = [];
5745 }
5746 for (var _i12 = 0; _i12 < nodes2.length; _i12++) {
5747 var pos = id2position[nodes2[_i12].id()];
5748 var clusterIndex = clusterIndices[pos];
5749 if (clusterIndex != null) {
5750 clusters[clusterIndex].push(nodes2[_i12]);
5751 }
5752 }
5753 var retClusters = new Array(exemplarsIndices.length);
5754 for (var _c = 0; _c < exemplarsIndices.length; _c++) {
5755 retClusters[_c] = cy.collection(clusters[exemplarsIndices[_c]]);
5756 }
5757 return retClusters;
5758 };
5759 var affinityPropagation$1 = {
5760 affinityPropagation,
5761 ap: affinityPropagation
5762 };
5763 var hierholzerDefaults = defaults$g({
5764 root: void 0,
5765 directed: false
5766 });
5767 var elesfn$k = {
5768 hierholzer: function hierholzer(options) {
5769 if (!plainObject(options)) {
5770 var args = arguments;
5771 options = {
5772 root: args[0],
5773 directed: args[1]
5774 };
5775 }
5776 var _hierholzerDefaults = hierholzerDefaults(options), root2 = _hierholzerDefaults.root, directed = _hierholzerDefaults.directed;
5777 var eles = this;
5778 var dflag = false;
5779 var oddIn;
5780 var oddOut;
5781 var startVertex;
5782 if (root2)
5783 startVertex = string(root2) ? this.filter(root2)[0].id() : root2[0].id();
5784 var nodes2 = {};
5785 var edges = {};
5786 if (directed) {
5787 eles.forEach(function(ele) {
5788 var id = ele.id();
5789 if (ele.isNode()) {
5790 var ind = ele.indegree(true);
5791 var outd = ele.outdegree(true);
5792 var d1 = ind - outd;
5793 var d2 = outd - ind;
5794 if (d1 == 1) {
5795 if (oddIn)
5796 dflag = true;
5797 else
5798 oddIn = id;
5799 } else if (d2 == 1) {
5800 if (oddOut)
5801 dflag = true;
5802 else
5803 oddOut = id;
5804 } else if (d2 > 1 || d1 > 1) {
5805 dflag = true;
5806 }
5807 nodes2[id] = [];
5808 ele.outgoers().forEach(function(e) {
5809 if (e.isEdge())
5810 nodes2[id].push(e.id());
5811 });
5812 } else {
5813 edges[id] = [void 0, ele.target().id()];
5814 }
5815 });
5816 } else {
5817 eles.forEach(function(ele) {
5818 var id = ele.id();
5819 if (ele.isNode()) {
5820 var d2 = ele.degree(true);
5821 if (d2 % 2) {
5822 if (!oddIn)
5823 oddIn = id;
5824 else if (!oddOut)
5825 oddOut = id;
5826 else
5827 dflag = true;
5828 }
5829 nodes2[id] = [];
5830 ele.connectedEdges().forEach(function(e) {
5831 return nodes2[id].push(e.id());
5832 });
5833 } else {
5834 edges[id] = [ele.source().id(), ele.target().id()];
5835 }
5836 });
5837 }
5838 var result = {
5839 found: false,
5840 trail: void 0
5841 };
5842 if (dflag)
5843 return result;
5844 else if (oddOut && oddIn) {
5845 if (directed) {
5846 if (startVertex && oddOut != startVertex) {
5847 return result;
5848 }
5849 startVertex = oddOut;
5850 } else {
5851 if (startVertex && oddOut != startVertex && oddIn != startVertex) {
5852 return result;
5853 } else if (!startVertex) {
5854 startVertex = oddOut;
5855 }
5856 }
5857 } else {
5858 if (!startVertex)
5859 startVertex = eles[0].id();
5860 }
5861 var walk = function walk2(v) {
5862 var currentNode = v;
5863 var subtour2 = [v];
5864 var adj, adjTail, adjHead;
5865 while (nodes2[currentNode].length) {
5866 adj = nodes2[currentNode].shift();
5867 adjTail = edges[adj][0];
5868 adjHead = edges[adj][1];
5869 if (currentNode != adjHead) {
5870 nodes2[adjHead] = nodes2[adjHead].filter(function(e) {
5871 return e != adj;
5872 });
5873 currentNode = adjHead;
5874 } else if (!directed && currentNode != adjTail) {
5875 nodes2[adjTail] = nodes2[adjTail].filter(function(e) {
5876 return e != adj;
5877 });
5878 currentNode = adjTail;
5879 }
5880 subtour2.unshift(adj);
5881 subtour2.unshift(currentNode);
5882 }
5883 return subtour2;
5884 };
5885 var trail = [];
5886 var subtour = [];
5887 subtour = walk(startVertex);
5888 while (subtour.length != 1) {
5889 if (nodes2[subtour[0]].length == 0) {
5890 trail.unshift(eles.getElementById(subtour.shift()));
5891 trail.unshift(eles.getElementById(subtour.shift()));
5892 } else {
5893 subtour = walk(subtour.shift()).concat(subtour);
5894 }
5895 }
5896 trail.unshift(eles.getElementById(subtour.shift()));
5897 for (var d in nodes2) {
5898 if (nodes2[d].length) {
5899 return result;
5900 }
5901 }
5902 result.found = true;
5903 result.trail = this.spawn(trail, true);
5904 return result;
5905 }
5906 };
5907 var hopcroftTarjanBiconnected = function hopcroftTarjanBiconnected2() {
5908 var eles = this;
5909 var nodes2 = {};
5910 var id = 0;
5911 var edgeCount = 0;
5912 var components = [];
5913 var stack = [];
5914 var visitedEdges = {};
5915 var buildComponent = function buildComponent2(x, y) {
5916 var i2 = stack.length - 1;
5917 var cutset = [];
5918 var component = eles.spawn();
5919 while (stack[i2].x != x || stack[i2].y != y) {
5920 cutset.push(stack.pop().edge);
5921 i2--;
5922 }
5923 cutset.push(stack.pop().edge);
5924 cutset.forEach(function(edge) {
5925 var connectedNodes = edge.connectedNodes().intersection(eles);
5926 component.merge(edge);
5927 connectedNodes.forEach(function(node) {
5928 var nodeId = node.id();
5929 var connectedEdges = node.connectedEdges().intersection(eles);
5930 component.merge(node);
5931 if (!nodes2[nodeId].cutVertex) {
5932 component.merge(connectedEdges);
5933 } else {
5934 component.merge(connectedEdges.filter(function(edge2) {
5935 return edge2.isLoop();
5936 }));
5937 }
5938 });
5939 });
5940 components.push(component);
5941 };
5942 var biconnectedSearch = function biconnectedSearch2(root2, currentNode, parent) {
5943 if (root2 === parent)
5944 edgeCount += 1;
5945 nodes2[currentNode] = {
5946 id,
5947 low: id++,
5948 cutVertex: false
5949 };
5950 var edges = eles.getElementById(currentNode).connectedEdges().intersection(eles);
5951 if (edges.size() === 0) {
5952 components.push(eles.spawn(eles.getElementById(currentNode)));
5953 } else {
5954 var sourceId, targetId, otherNodeId, edgeId;
5955 edges.forEach(function(edge) {
5956 sourceId = edge.source().id();
5957 targetId = edge.target().id();
5958 otherNodeId = sourceId === currentNode ? targetId : sourceId;
5959 if (otherNodeId !== parent) {
5960 edgeId = edge.id();
5961 if (!visitedEdges[edgeId]) {
5962 visitedEdges[edgeId] = true;
5963 stack.push({
5964 x: currentNode,
5965 y: otherNodeId,
5966 edge
5967 });
5968 }
5969 if (!(otherNodeId in nodes2)) {
5970 biconnectedSearch2(root2, otherNodeId, currentNode);
5971 nodes2[currentNode].low = Math.min(nodes2[currentNode].low, nodes2[otherNodeId].low);
5972 if (nodes2[currentNode].id <= nodes2[otherNodeId].low) {
5973 nodes2[currentNode].cutVertex = true;
5974 buildComponent(currentNode, otherNodeId);
5975 }
5976 } else {
5977 nodes2[currentNode].low = Math.min(nodes2[currentNode].low, nodes2[otherNodeId].id);
5978 }
5979 }
5980 });
5981 }
5982 };
5983 eles.forEach(function(ele) {
5984 if (ele.isNode()) {
5985 var nodeId = ele.id();
5986 if (!(nodeId in nodes2)) {
5987 edgeCount = 0;
5988 biconnectedSearch(nodeId, nodeId);
5989 nodes2[nodeId].cutVertex = edgeCount > 1;
5990 }
5991 }
5992 });
5993 var cutVertices = Object.keys(nodes2).filter(function(id2) {
5994 return nodes2[id2].cutVertex;
5995 }).map(function(id2) {
5996 return eles.getElementById(id2);
5997 });
5998 return {
5999 cut: eles.spawn(cutVertices),
6000 components
6001 };
6002 };
6003 var hopcroftTarjanBiconnected$1 = {
6004 hopcroftTarjanBiconnected,
6005 htbc: hopcroftTarjanBiconnected,
6006 htb: hopcroftTarjanBiconnected,
6007 hopcroftTarjanBiconnectedComponents: hopcroftTarjanBiconnected
6008 };
6009 var tarjanStronglyConnected = function tarjanStronglyConnected2() {
6010 var eles = this;
6011 var nodes2 = {};
6012 var index = 0;
6013 var components = [];
6014 var stack = [];
6015 var cut = eles.spawn(eles);
6016 var stronglyConnectedSearch = function stronglyConnectedSearch2(sourceNodeId) {
6017 stack.push(sourceNodeId);
6018 nodes2[sourceNodeId] = {
6019 index,
6020 low: index++,
6021 explored: false
6022 };
6023 var connectedEdges = eles.getElementById(sourceNodeId).connectedEdges().intersection(eles);
6024 connectedEdges.forEach(function(edge) {
6025 var targetNodeId = edge.target().id();
6026 if (targetNodeId !== sourceNodeId) {
6027 if (!(targetNodeId in nodes2)) {
6028 stronglyConnectedSearch2(targetNodeId);
6029 }
6030 if (!nodes2[targetNodeId].explored) {
6031 nodes2[sourceNodeId].low = Math.min(nodes2[sourceNodeId].low, nodes2[targetNodeId].low);
6032 }
6033 }
6034 });
6035 if (nodes2[sourceNodeId].index === nodes2[sourceNodeId].low) {
6036 var componentNodes = eles.spawn();
6037 for (; ; ) {
6038 var nodeId = stack.pop();
6039 componentNodes.merge(eles.getElementById(nodeId));
6040 nodes2[nodeId].low = nodes2[sourceNodeId].index;
6041 nodes2[nodeId].explored = true;
6042 if (nodeId === sourceNodeId) {
6043 break;
6044 }
6045 }
6046 var componentEdges = componentNodes.edgesWith(componentNodes);
6047 var component = componentNodes.merge(componentEdges);
6048 components.push(component);
6049 cut = cut.difference(component);
6050 }
6051 };
6052 eles.forEach(function(ele) {
6053 if (ele.isNode()) {
6054 var nodeId = ele.id();
6055 if (!(nodeId in nodes2)) {
6056 stronglyConnectedSearch(nodeId);
6057 }
6058 }
6059 });
6060 return {
6061 cut,
6062 components
6063 };
6064 };
6065 var tarjanStronglyConnected$1 = {
6066 tarjanStronglyConnected,
6067 tsc: tarjanStronglyConnected,
6068 tscc: tarjanStronglyConnected,
6069 tarjanStronglyConnectedComponents: tarjanStronglyConnected
6070 };
6071 var elesfn$j = {};
6072 [elesfn$v, elesfn$u, elesfn$t, elesfn$s, elesfn$r, elesfn$q, elesfn$p, elesfn$o, elesfn$n, elesfn$m, elesfn$l, markovClustering$1, kClustering, hierarchicalClustering$1, affinityPropagation$1, elesfn$k, hopcroftTarjanBiconnected$1, tarjanStronglyConnected$1].forEach(function(props) {
6073 extend(elesfn$j, props);
6074 });
6075 /*!
6076 Embeddable Minimum Strictly-Compliant Promises/A+ 1.1.1 Thenable
6077 Copyright (c) 2013-2014 Ralf S. Engelschall (http://engelschall.com)
6078 Licensed under The MIT License (http://opensource.org/licenses/MIT)
6079 */
6080 var STATE_PENDING = 0;
6081 var STATE_FULFILLED = 1;
6082 var STATE_REJECTED = 2;
6083 var api = function api2(executor) {
6084 if (!(this instanceof api2))
6085 return new api2(executor);
6086 this.id = "Thenable/1.0.7";
6087 this.state = STATE_PENDING;
6088 this.fulfillValue = void 0;
6089 this.rejectReason = void 0;
6090 this.onFulfilled = [];
6091 this.onRejected = [];
6092 this.proxy = {
6093 then: this.then.bind(this)
6094 };
6095 if (typeof executor === "function")
6096 executor.call(this, this.fulfill.bind(this), this.reject.bind(this));
6097 };
6098 api.prototype = {
6099 /* promise resolving methods */
6100 fulfill: function fulfill(value) {
6101 return deliver(this, STATE_FULFILLED, "fulfillValue", value);
6102 },
6103 reject: function reject(value) {
6104 return deliver(this, STATE_REJECTED, "rejectReason", value);
6105 },
6106 /* "The then Method" [Promises/A+ 1.1, 1.2, 2.2] */
6107 then: function then(onFulfilled, onRejected) {
6108 var curr = this;
6109 var next2 = new api();
6110 curr.onFulfilled.push(resolver(onFulfilled, next2, "fulfill"));
6111 curr.onRejected.push(resolver(onRejected, next2, "reject"));
6112 execute(curr);
6113 return next2.proxy;
6114 }
6115 };
6116 var deliver = function deliver2(curr, state, name2, value) {
6117 if (curr.state === STATE_PENDING) {
6118 curr.state = state;
6119 curr[name2] = value;
6120 execute(curr);
6121 }
6122 return curr;
6123 };
6124 var execute = function execute2(curr) {
6125 if (curr.state === STATE_FULFILLED)
6126 execute_handlers(curr, "onFulfilled", curr.fulfillValue);
6127 else if (curr.state === STATE_REJECTED)
6128 execute_handlers(curr, "onRejected", curr.rejectReason);
6129 };
6130 var execute_handlers = function execute_handlers2(curr, name2, value) {
6131 if (curr[name2].length === 0)
6132 return;
6133 var handlers = curr[name2];
6134 curr[name2] = [];
6135 var func = function func2() {
6136 for (var i2 = 0; i2 < handlers.length; i2++) {
6137 handlers[i2](value);
6138 }
6139 };
6140 if (typeof setImmediate === "function")
6141 setImmediate(func);
6142 else
6143 setTimeout(func, 0);
6144 };
6145 var resolver = function resolver2(cb, next2, method) {
6146 return function(value) {
6147 if (typeof cb !== "function")
6148 next2[method].call(next2, value);
6149 else {
6150 var result;
6151 try {
6152 result = cb(value);
6153 } catch (e) {
6154 next2.reject(e);
6155 return;
6156 }
6157 resolve(next2, result);
6158 }
6159 };
6160 };
6161 var resolve = function resolve2(promise2, x) {
6162 if (promise2 === x || promise2.proxy === x) {
6163 promise2.reject(new TypeError("cannot resolve promise with itself"));
6164 return;
6165 }
6166 var then;
6167 if (_typeof(x) === "object" && x !== null || typeof x === "function") {
6168 try {
6169 then = x.then;
6170 } catch (e) {
6171 promise2.reject(e);
6172 return;
6173 }
6174 }
6175 if (typeof then === "function") {
6176 var resolved = false;
6177 try {
6178 then.call(
6179 x,
6180 /* resolvePromise */
6181 /* [Promises/A+ 2.3.3.3.1] */
6182 function(y) {
6183 if (resolved)
6184 return;
6185 resolved = true;
6186 if (y === x)
6187 promise2.reject(new TypeError("circular thenable chain"));
6188 else
6189 resolve2(promise2, y);
6190 },
6191 /* rejectPromise */
6192 /* [Promises/A+ 2.3.3.3.2] */
6193 function(r) {
6194 if (resolved)
6195 return;
6196 resolved = true;
6197 promise2.reject(r);
6198 }
6199 );
6200 } catch (e) {
6201 if (!resolved)
6202 promise2.reject(e);
6203 }
6204 return;
6205 }
6206 promise2.fulfill(x);
6207 };
6208 api.all = function(ps) {
6209 return new api(function(resolveAll, rejectAll) {
6210 var vals = new Array(ps.length);
6211 var doneCount = 0;
6212 var fulfill = function fulfill2(i3, val) {
6213 vals[i3] = val;
6214 doneCount++;
6215 if (doneCount === ps.length) {
6216 resolveAll(vals);
6217 }
6218 };
6219 for (var i2 = 0; i2 < ps.length; i2++) {
6220 (function(i3) {
6221 var p2 = ps[i3];
6222 var isPromise = p2 != null && p2.then != null;
6223 if (isPromise) {
6224 p2.then(function(val2) {
6225 fulfill(i3, val2);
6226 }, function(err) {
6227 rejectAll(err);
6228 });
6229 } else {
6230 var val = p2;
6231 fulfill(i3, val);
6232 }
6233 })(i2);
6234 }
6235 });
6236 };
6237 api.resolve = function(val) {
6238 return new api(function(resolve2, reject) {
6239 resolve2(val);
6240 });
6241 };
6242 api.reject = function(val) {
6243 return new api(function(resolve2, reject) {
6244 reject(val);
6245 });
6246 };
6247 var Promise$1 = typeof Promise !== "undefined" ? Promise : api;
6248 var Animation = function Animation2(target, opts, opts2) {
6249 var isCore = core(target);
6250 var isEle = !isCore;
6251 var _p = this._private = extend({
6252 duration: 1e3
6253 }, opts, opts2);
6254 _p.target = target;
6255 _p.style = _p.style || _p.css;
6256 _p.started = false;
6257 _p.playing = false;
6258 _p.hooked = false;
6259 _p.applying = false;
6260 _p.progress = 0;
6261 _p.completes = [];
6262 _p.frames = [];
6263 if (_p.complete && fn$6(_p.complete)) {
6264 _p.completes.push(_p.complete);
6265 }
6266 if (isEle) {
6267 var pos = target.position();
6268 _p.startPosition = _p.startPosition || {
6269 x: pos.x,
6270 y: pos.y
6271 };
6272 _p.startStyle = _p.startStyle || target.cy().style().getAnimationStartStyle(target, _p.style);
6273 }
6274 if (isCore) {
6275 var pan = target.pan();
6276 _p.startPan = {
6277 x: pan.x,
6278 y: pan.y
6279 };
6280 _p.startZoom = target.zoom();
6281 }
6282 this.length = 1;
6283 this[0] = this;
6284 };
6285 var anifn = Animation.prototype;
6286 extend(anifn, {
6287 instanceString: function instanceString() {
6288 return "animation";
6289 },
6290 hook: function hook() {
6291 var _p = this._private;
6292 if (!_p.hooked) {
6293 var q;
6294 var tAni = _p.target._private.animation;
6295 if (_p.queue) {
6296 q = tAni.queue;
6297 } else {
6298 q = tAni.current;
6299 }
6300 q.push(this);
6301 if (elementOrCollection(_p.target)) {
6302 _p.target.cy().addToAnimationPool(_p.target);
6303 }
6304 _p.hooked = true;
6305 }
6306 return this;
6307 },
6308 play: function play() {
6309 var _p = this._private;
6310 if (_p.progress === 1) {
6311 _p.progress = 0;
6312 }
6313 _p.playing = true;
6314 _p.started = false;
6315 _p.stopped = false;
6316 this.hook();
6317 return this;
6318 },
6319 playing: function playing() {
6320 return this._private.playing;
6321 },
6322 apply: function apply() {
6323 var _p = this._private;
6324 _p.applying = true;
6325 _p.started = false;
6326 _p.stopped = false;
6327 this.hook();
6328 return this;
6329 },
6330 applying: function applying() {
6331 return this._private.applying;
6332 },
6333 pause: function pause() {
6334 var _p = this._private;
6335 _p.playing = false;
6336 _p.started = false;
6337 return this;
6338 },
6339 stop: function stop() {
6340 var _p = this._private;
6341 _p.playing = false;
6342 _p.started = false;
6343 _p.stopped = true;
6344 return this;
6345 },
6346 rewind: function rewind() {
6347 return this.progress(0);
6348 },
6349 fastforward: function fastforward() {
6350 return this.progress(1);
6351 },
6352 time: function time(t) {
6353 var _p = this._private;
6354 if (t === void 0) {
6355 return _p.progress * _p.duration;
6356 } else {
6357 return this.progress(t / _p.duration);
6358 }
6359 },
6360 progress: function progress(p2) {
6361 var _p = this._private;
6362 var wasPlaying = _p.playing;
6363 if (p2 === void 0) {
6364 return _p.progress;
6365 } else {
6366 if (wasPlaying) {
6367 this.pause();
6368 }
6369 _p.progress = p2;
6370 _p.started = false;
6371 if (wasPlaying) {
6372 this.play();
6373 }
6374 }
6375 return this;
6376 },
6377 completed: function completed() {
6378 return this._private.progress === 1;
6379 },
6380 reverse: function reverse() {
6381 var _p = this._private;
6382 var wasPlaying = _p.playing;
6383 if (wasPlaying) {
6384 this.pause();
6385 }
6386 _p.progress = 1 - _p.progress;
6387 _p.started = false;
6388 var swap = function swap2(a, b) {
6389 var _pa = _p[a];
6390 if (_pa == null) {
6391 return;
6392 }
6393 _p[a] = _p[b];
6394 _p[b] = _pa;
6395 };
6396 swap("zoom", "startZoom");
6397 swap("pan", "startPan");
6398 swap("position", "startPosition");
6399 if (_p.style) {
6400 for (var i2 = 0; i2 < _p.style.length; i2++) {
6401 var prop = _p.style[i2];
6402 var name2 = prop.name;
6403 var startStyleProp = _p.startStyle[name2];
6404 _p.startStyle[name2] = prop;
6405 _p.style[i2] = startStyleProp;
6406 }
6407 }
6408 if (wasPlaying) {
6409 this.play();
6410 }
6411 return this;
6412 },
6413 promise: function promise2(type) {
6414 var _p = this._private;
6415 var arr;
6416 switch (type) {
6417 case "frame":
6418 arr = _p.frames;
6419 break;
6420 default:
6421 case "complete":
6422 case "completed":
6423 arr = _p.completes;
6424 }
6425 return new Promise$1(function(resolve2, reject) {
6426 arr.push(function() {
6427 resolve2();
6428 });
6429 });
6430 }
6431 });
6432 anifn.complete = anifn.completed;
6433 anifn.run = anifn.play;
6434 anifn.running = anifn.playing;
6435 var define$3 = {
6436 animated: function animated() {
6437 return function animatedImpl() {
6438 var self2 = this;
6439 var selfIsArrayLike = self2.length !== void 0;
6440 var all = selfIsArrayLike ? self2 : [self2];
6441 var cy = this._private.cy || this;
6442 if (!cy.styleEnabled()) {
6443 return false;
6444 }
6445 var ele = all[0];
6446 if (ele) {
6447 return ele._private.animation.current.length > 0;
6448 }
6449 };
6450 },
6451 // animated
6452 clearQueue: function clearQueue() {
6453 return function clearQueueImpl() {
6454 var self2 = this;
6455 var selfIsArrayLike = self2.length !== void 0;
6456 var all = selfIsArrayLike ? self2 : [self2];
6457 var cy = this._private.cy || this;
6458 if (!cy.styleEnabled()) {
6459 return this;
6460 }
6461 for (var i2 = 0; i2 < all.length; i2++) {
6462 var ele = all[i2];
6463 ele._private.animation.queue = [];
6464 }
6465 return this;
6466 };
6467 },
6468 // clearQueue
6469 delay: function delay() {
6470 return function delayImpl(time, complete) {
6471 var cy = this._private.cy || this;
6472 if (!cy.styleEnabled()) {
6473 return this;
6474 }
6475 return this.animate({
6476 delay: time,
6477 duration: time,
6478 complete
6479 });
6480 };
6481 },
6482 // delay
6483 delayAnimation: function delayAnimation() {
6484 return function delayAnimationImpl(time, complete) {
6485 var cy = this._private.cy || this;
6486 if (!cy.styleEnabled()) {
6487 return this;
6488 }
6489 return this.animation({
6490 delay: time,
6491 duration: time,
6492 complete
6493 });
6494 };
6495 },
6496 // delay
6497 animation: function animation() {
6498 return function animationImpl(properties, params) {
6499 var self2 = this;
6500 var selfIsArrayLike = self2.length !== void 0;
6501 var all = selfIsArrayLike ? self2 : [self2];
6502 var cy = this._private.cy || this;
6503 var isCore = !selfIsArrayLike;
6504 var isEles = !isCore;
6505 if (!cy.styleEnabled()) {
6506 return this;
6507 }
6508 var style = cy.style();
6509 properties = extend({}, properties, params);
6510 var propertiesEmpty = Object.keys(properties).length === 0;
6511 if (propertiesEmpty) {
6512 return new Animation(all[0], properties);
6513 }
6514 if (properties.duration === void 0) {
6515 properties.duration = 400;
6516 }
6517 switch (properties.duration) {
6518 case "slow":
6519 properties.duration = 600;
6520 break;
6521 case "fast":
6522 properties.duration = 200;
6523 break;
6524 }
6525 if (isEles) {
6526 properties.style = style.getPropsList(properties.style || properties.css);
6527 properties.css = void 0;
6528 }
6529 if (isEles && properties.renderedPosition != null) {
6530 var rpos = properties.renderedPosition;
6531 var pan = cy.pan();
6532 var zoom = cy.zoom();
6533 properties.position = renderedToModelPosition(rpos, zoom, pan);
6534 }
6535 if (isCore && properties.panBy != null) {
6536 var panBy = properties.panBy;
6537 var cyPan = cy.pan();
6538 properties.pan = {
6539 x: cyPan.x + panBy.x,
6540 y: cyPan.y + panBy.y
6541 };
6542 }
6543 var center = properties.center || properties.centre;
6544 if (isCore && center != null) {
6545 var centerPan = cy.getCenterPan(center.eles, properties.zoom);
6546 if (centerPan != null) {
6547 properties.pan = centerPan;
6548 }
6549 }
6550 if (isCore && properties.fit != null) {
6551 var fit = properties.fit;
6552 var fitVp = cy.getFitViewport(fit.eles || fit.boundingBox, fit.padding);
6553 if (fitVp != null) {
6554 properties.pan = fitVp.pan;
6555 properties.zoom = fitVp.zoom;
6556 }
6557 }
6558 if (isCore && plainObject(properties.zoom)) {
6559 var vp = cy.getZoomedViewport(properties.zoom);
6560 if (vp != null) {
6561 if (vp.zoomed) {
6562 properties.zoom = vp.zoom;
6563 }
6564 if (vp.panned) {
6565 properties.pan = vp.pan;
6566 }
6567 } else {
6568 properties.zoom = null;
6569 }
6570 }
6571 return new Animation(all[0], properties);
6572 };
6573 },
6574 // animate
6575 animate: function animate() {
6576 return function animateImpl(properties, params) {
6577 var self2 = this;
6578 var selfIsArrayLike = self2.length !== void 0;
6579 var all = selfIsArrayLike ? self2 : [self2];
6580 var cy = this._private.cy || this;
6581 if (!cy.styleEnabled()) {
6582 return this;
6583 }
6584 if (params) {
6585 properties = extend({}, properties, params);
6586 }
6587 for (var i2 = 0; i2 < all.length; i2++) {
6588 var ele = all[i2];
6589 var queue = ele.animated() && (properties.queue === void 0 || properties.queue);
6590 var ani = ele.animation(properties, queue ? {
6591 queue: true
6592 } : void 0);
6593 ani.play();
6594 }
6595 return this;
6596 };
6597 },
6598 // animate
6599 stop: function stop() {
6600 return function stopImpl(clearQueue, jumpToEnd) {
6601 var self2 = this;
6602 var selfIsArrayLike = self2.length !== void 0;
6603 var all = selfIsArrayLike ? self2 : [self2];
6604 var cy = this._private.cy || this;
6605 if (!cy.styleEnabled()) {
6606 return this;
6607 }
6608 for (var i2 = 0; i2 < all.length; i2++) {
6609 var ele = all[i2];
6610 var _p = ele._private;
6611 var anis = _p.animation.current;
6612 for (var j = 0; j < anis.length; j++) {
6613 var ani = anis[j];
6614 var ani_p = ani._private;
6615 if (jumpToEnd) {
6616 ani_p.duration = 0;
6617 }
6618 }
6619 if (clearQueue) {
6620 _p.animation.queue = [];
6621 }
6622 if (!jumpToEnd) {
6623 _p.animation.current = [];
6624 }
6625 }
6626 cy.notify("draw");
6627 return this;
6628 };
6629 }
6630 // stop
6631 };
6632 var isArray = Array.isArray;
6633 var isArray_1 = isArray;
6634 var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/;
6635 function isKey(value, object2) {
6636 if (isArray_1(value)) {
6637 return false;
6638 }
6639 var type = typeof value;
6640 if (type == "number" || type == "symbol" || type == "boolean" || value == null || isSymbol_1(value)) {
6641 return true;
6642 }
6643 return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object2 != null && value in Object(object2);
6644 }
6645 var _isKey = isKey;
6646 var asyncTag = "[object AsyncFunction]", funcTag = "[object Function]", genTag = "[object GeneratorFunction]", proxyTag = "[object Proxy]";
6647 function isFunction(value) {
6648 if (!isObject_1(value)) {
6649 return false;
6650 }
6651 var tag = _baseGetTag(value);
6652 return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
6653 }
6654 var isFunction_1 = isFunction;
6655 var coreJsData = _root["__core-js_shared__"];
6656 var _coreJsData = coreJsData;
6657 var maskSrcKey = function() {
6658 var uid = /[^.]+$/.exec(_coreJsData && _coreJsData.keys && _coreJsData.keys.IE_PROTO || "");
6659 return uid ? "Symbol(src)_1." + uid : "";
6660 }();
6661 function isMasked(func) {
6662 return !!maskSrcKey && maskSrcKey in func;
6663 }
6664 var _isMasked = isMasked;
6665 var funcProto$1 = Function.prototype;
6666 var funcToString$1 = funcProto$1.toString;
6667 function toSource(func) {
6668 if (func != null) {
6669 try {
6670 return funcToString$1.call(func);
6671 } catch (e) {
6672 }
6673 try {
6674 return func + "";
6675 } catch (e) {
6676 }
6677 }
6678 return "";
6679 }
6680 var _toSource = toSource;
6681 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
6682 var reIsHostCtor = /^\[object .+?Constructor\]$/;
6683 var funcProto = Function.prototype, objectProto$3 = Object.prototype;
6684 var funcToString = funcProto.toString;
6685 var hasOwnProperty$3 = objectProto$3.hasOwnProperty;
6686 var reIsNative = RegExp(
6687 "^" + funcToString.call(hasOwnProperty$3).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
6688 );
6689 function baseIsNative(value) {
6690 if (!isObject_1(value) || _isMasked(value)) {
6691 return false;
6692 }
6693 var pattern = isFunction_1(value) ? reIsNative : reIsHostCtor;
6694 return pattern.test(_toSource(value));
6695 }
6696 var _baseIsNative = baseIsNative;
6697 function getValue$1(object2, key) {
6698 return object2 == null ? void 0 : object2[key];
6699 }
6700 var _getValue = getValue$1;
6701 function getNative(object2, key) {
6702 var value = _getValue(object2, key);
6703 return _baseIsNative(value) ? value : void 0;
6704 }
6705 var _getNative = getNative;
6706 var nativeCreate = _getNative(Object, "create");
6707 var _nativeCreate = nativeCreate;
6708 function hashClear() {
6709 this.__data__ = _nativeCreate ? _nativeCreate(null) : {};
6710 this.size = 0;
6711 }
6712 var _hashClear = hashClear;
6713 function hashDelete(key) {
6714 var result = this.has(key) && delete this.__data__[key];
6715 this.size -= result ? 1 : 0;
6716 return result;
6717 }
6718 var _hashDelete = hashDelete;
6719 var HASH_UNDEFINED$1 = "__lodash_hash_undefined__";
6720 var objectProto$2 = Object.prototype;
6721 var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
6722 function hashGet(key) {
6723 var data2 = this.__data__;
6724 if (_nativeCreate) {
6725 var result = data2[key];
6726 return result === HASH_UNDEFINED$1 ? void 0 : result;
6727 }
6728 return hasOwnProperty$2.call(data2, key) ? data2[key] : void 0;
6729 }
6730 var _hashGet = hashGet;
6731 var objectProto$1 = Object.prototype;
6732 var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
6733 function hashHas(key) {
6734 var data2 = this.__data__;
6735 return _nativeCreate ? data2[key] !== void 0 : hasOwnProperty$1.call(data2, key);
6736 }
6737 var _hashHas = hashHas;
6738 var HASH_UNDEFINED = "__lodash_hash_undefined__";
6739 function hashSet(key, value) {
6740 var data2 = this.__data__;
6741 this.size += this.has(key) ? 0 : 1;
6742 data2[key] = _nativeCreate && value === void 0 ? HASH_UNDEFINED : value;
6743 return this;
6744 }
6745 var _hashSet = hashSet;
6746 function Hash(entries) {
6747 var index = -1, length = entries == null ? 0 : entries.length;
6748 this.clear();
6749 while (++index < length) {
6750 var entry = entries[index];
6751 this.set(entry[0], entry[1]);
6752 }
6753 }
6754 Hash.prototype.clear = _hashClear;
6755 Hash.prototype["delete"] = _hashDelete;
6756 Hash.prototype.get = _hashGet;
6757 Hash.prototype.has = _hashHas;
6758 Hash.prototype.set = _hashSet;
6759 var _Hash = Hash;
6760 function listCacheClear() {
6761 this.__data__ = [];
6762 this.size = 0;
6763 }
6764 var _listCacheClear = listCacheClear;
6765 function eq(value, other) {
6766 return value === other || value !== value && other !== other;
6767 }
6768 var eq_1 = eq;
6769 function assocIndexOf(array2, key) {
6770 var length = array2.length;
6771 while (length--) {
6772 if (eq_1(array2[length][0], key)) {
6773 return length;
6774 }
6775 }
6776 return -1;
6777 }
6778 var _assocIndexOf = assocIndexOf;
6779 var arrayProto = Array.prototype;
6780 var splice = arrayProto.splice;
6781 function listCacheDelete(key) {
6782 var data2 = this.__data__, index = _assocIndexOf(data2, key);
6783 if (index < 0) {
6784 return false;
6785 }
6786 var lastIndex = data2.length - 1;
6787 if (index == lastIndex) {
6788 data2.pop();
6789 } else {
6790 splice.call(data2, index, 1);
6791 }
6792 --this.size;
6793 return true;
6794 }
6795 var _listCacheDelete = listCacheDelete;
6796 function listCacheGet(key) {
6797 var data2 = this.__data__, index = _assocIndexOf(data2, key);
6798 return index < 0 ? void 0 : data2[index][1];
6799 }
6800 var _listCacheGet = listCacheGet;
6801 function listCacheHas(key) {
6802 return _assocIndexOf(this.__data__, key) > -1;
6803 }
6804 var _listCacheHas = listCacheHas;
6805 function listCacheSet(key, value) {
6806 var data2 = this.__data__, index = _assocIndexOf(data2, key);
6807 if (index < 0) {
6808 ++this.size;
6809 data2.push([key, value]);
6810 } else {
6811 data2[index][1] = value;
6812 }
6813 return this;
6814 }
6815 var _listCacheSet = listCacheSet;
6816 function ListCache(entries) {
6817 var index = -1, length = entries == null ? 0 : entries.length;
6818 this.clear();
6819 while (++index < length) {
6820 var entry = entries[index];
6821 this.set(entry[0], entry[1]);
6822 }
6823 }
6824 ListCache.prototype.clear = _listCacheClear;
6825 ListCache.prototype["delete"] = _listCacheDelete;
6826 ListCache.prototype.get = _listCacheGet;
6827 ListCache.prototype.has = _listCacheHas;
6828 ListCache.prototype.set = _listCacheSet;
6829 var _ListCache = ListCache;
6830 var Map$1 = _getNative(_root, "Map");
6831 var _Map = Map$1;
6832 function mapCacheClear() {
6833 this.size = 0;
6834 this.__data__ = {
6835 "hash": new _Hash(),
6836 "map": new (_Map || _ListCache)(),
6837 "string": new _Hash()
6838 };
6839 }
6840 var _mapCacheClear = mapCacheClear;
6841 function isKeyable(value) {
6842 var type = typeof value;
6843 return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value !== "__proto__" : value === null;
6844 }
6845 var _isKeyable = isKeyable;
6846 function getMapData(map, key) {
6847 var data2 = map.__data__;
6848 return _isKeyable(key) ? data2[typeof key == "string" ? "string" : "hash"] : data2.map;
6849 }
6850 var _getMapData = getMapData;
6851 function mapCacheDelete(key) {
6852 var result = _getMapData(this, key)["delete"](key);
6853 this.size -= result ? 1 : 0;
6854 return result;
6855 }
6856 var _mapCacheDelete = mapCacheDelete;
6857 function mapCacheGet(key) {
6858 return _getMapData(this, key).get(key);
6859 }
6860 var _mapCacheGet = mapCacheGet;
6861 function mapCacheHas(key) {
6862 return _getMapData(this, key).has(key);
6863 }
6864 var _mapCacheHas = mapCacheHas;
6865 function mapCacheSet(key, value) {
6866 var data2 = _getMapData(this, key), size = data2.size;
6867 data2.set(key, value);
6868 this.size += data2.size == size ? 0 : 1;
6869 return this;
6870 }
6871 var _mapCacheSet = mapCacheSet;
6872 function MapCache(entries) {
6873 var index = -1, length = entries == null ? 0 : entries.length;
6874 this.clear();
6875 while (++index < length) {
6876 var entry = entries[index];
6877 this.set(entry[0], entry[1]);
6878 }
6879 }
6880 MapCache.prototype.clear = _mapCacheClear;
6881 MapCache.prototype["delete"] = _mapCacheDelete;
6882 MapCache.prototype.get = _mapCacheGet;
6883 MapCache.prototype.has = _mapCacheHas;
6884 MapCache.prototype.set = _mapCacheSet;
6885 var _MapCache = MapCache;
6886 var FUNC_ERROR_TEXT = "Expected a function";
6887 function memoize(func, resolver2) {
6888 if (typeof func != "function" || resolver2 != null && typeof resolver2 != "function") {
6889 throw new TypeError(FUNC_ERROR_TEXT);
6890 }
6891 var memoized = function() {
6892 var args = arguments, key = resolver2 ? resolver2.apply(this, args) : args[0], cache2 = memoized.cache;
6893 if (cache2.has(key)) {
6894 return cache2.get(key);
6895 }
6896 var result = func.apply(this, args);
6897 memoized.cache = cache2.set(key, result) || cache2;
6898 return result;
6899 };
6900 memoized.cache = new (memoize.Cache || _MapCache)();
6901 return memoized;
6902 }
6903 memoize.Cache = _MapCache;
6904 var memoize_1 = memoize;
6905 var MAX_MEMOIZE_SIZE = 500;
6906 function memoizeCapped(func) {
6907 var result = memoize_1(func, function(key) {
6908 if (cache2.size === MAX_MEMOIZE_SIZE) {
6909 cache2.clear();
6910 }
6911 return key;
6912 });
6913 var cache2 = result.cache;
6914 return result;
6915 }
6916 var _memoizeCapped = memoizeCapped;
6917 var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
6918 var reEscapeChar = /\\(\\)?/g;
6919 var stringToPath = _memoizeCapped(function(string2) {
6920 var result = [];
6921 if (string2.charCodeAt(0) === 46) {
6922 result.push("");
6923 }
6924 string2.replace(rePropName, function(match2, number2, quote, subString) {
6925 result.push(quote ? subString.replace(reEscapeChar, "$1") : number2 || match2);
6926 });
6927 return result;
6928 });
6929 var _stringToPath = stringToPath;
6930 function arrayMap(array2, iteratee) {
6931 var index = -1, length = array2 == null ? 0 : array2.length, result = Array(length);
6932 while (++index < length) {
6933 result[index] = iteratee(array2[index], index, array2);
6934 }
6935 return result;
6936 }
6937 var _arrayMap = arrayMap;
6938 var INFINITY$1 = 1 / 0;
6939 var symbolProto = _Symbol ? _Symbol.prototype : void 0, symbolToString = symbolProto ? symbolProto.toString : void 0;
6940 function baseToString(value) {
6941 if (typeof value == "string") {
6942 return value;
6943 }
6944 if (isArray_1(value)) {
6945 return _arrayMap(value, baseToString) + "";
6946 }
6947 if (isSymbol_1(value)) {
6948 return symbolToString ? symbolToString.call(value) : "";
6949 }
6950 var result = value + "";
6951 return result == "0" && 1 / value == -INFINITY$1 ? "-0" : result;
6952 }
6953 var _baseToString = baseToString;
6954 function toString$1(value) {
6955 return value == null ? "" : _baseToString(value);
6956 }
6957 var toString_1 = toString$1;
6958 function castPath(value, object2) {
6959 if (isArray_1(value)) {
6960 return value;
6961 }
6962 return _isKey(value, object2) ? [value] : _stringToPath(toString_1(value));
6963 }
6964 var _castPath = castPath;
6965 var INFINITY = 1 / 0;
6966 function toKey(value) {
6967 if (typeof value == "string" || isSymbol_1(value)) {
6968 return value;
6969 }
6970 var result = value + "";
6971 return result == "0" && 1 / value == -INFINITY ? "-0" : result;
6972 }
6973 var _toKey = toKey;
6974 function baseGet(object2, path) {
6975 path = _castPath(path, object2);
6976 var index = 0, length = path.length;
6977 while (object2 != null && index < length) {
6978 object2 = object2[_toKey(path[index++])];
6979 }
6980 return index && index == length ? object2 : void 0;
6981 }
6982 var _baseGet = baseGet;
6983 function get(object2, path, defaultValue) {
6984 var result = object2 == null ? void 0 : _baseGet(object2, path);
6985 return result === void 0 ? defaultValue : result;
6986 }
6987 var get_1 = get;
6988 var defineProperty = function() {
6989 try {
6990 var func = _getNative(Object, "defineProperty");
6991 func({}, "", {});
6992 return func;
6993 } catch (e) {
6994 }
6995 }();
6996 var _defineProperty = defineProperty;
6997 function baseAssignValue(object2, key, value) {
6998 if (key == "__proto__" && _defineProperty) {
6999 _defineProperty(object2, key, {
7000 "configurable": true,
7001 "enumerable": true,
7002 "value": value,
7003 "writable": true
7004 });
7005 } else {
7006 object2[key] = value;
7007 }
7008 }
7009 var _baseAssignValue = baseAssignValue;
7010 var objectProto = Object.prototype;
7011 var hasOwnProperty = objectProto.hasOwnProperty;
7012 function assignValue(object2, key, value) {
7013 var objValue = object2[key];
7014 if (!(hasOwnProperty.call(object2, key) && eq_1(objValue, value)) || value === void 0 && !(key in object2)) {
7015 _baseAssignValue(object2, key, value);
7016 }
7017 }
7018 var _assignValue = assignValue;
7019 var MAX_SAFE_INTEGER = 9007199254740991;
7020 var reIsUint = /^(?:0|[1-9]\d*)$/;
7021 function isIndex(value, length) {
7022 var type = typeof value;
7023 length = length == null ? MAX_SAFE_INTEGER : length;
7024 return !!length && (type == "number" || type != "symbol" && reIsUint.test(value)) && (value > -1 && value % 1 == 0 && value < length);
7025 }
7026 var _isIndex = isIndex;
7027 function baseSet(object2, path, value, customizer) {
7028 if (!isObject_1(object2)) {
7029 return object2;
7030 }
7031 path = _castPath(path, object2);
7032 var index = -1, length = path.length, lastIndex = length - 1, nested = object2;
7033 while (nested != null && ++index < length) {
7034 var key = _toKey(path[index]), newValue = value;
7035 if (key === "__proto__" || key === "constructor" || key === "prototype") {
7036 return object2;
7037 }
7038 if (index != lastIndex) {
7039 var objValue = nested[key];
7040 newValue = customizer ? customizer(objValue, key, nested) : void 0;
7041 if (newValue === void 0) {
7042 newValue = isObject_1(objValue) ? objValue : _isIndex(path[index + 1]) ? [] : {};
7043 }
7044 }
7045 _assignValue(nested, key, newValue);
7046 nested = nested[key];
7047 }
7048 return object2;
7049 }
7050 var _baseSet = baseSet;
7051 function set(object2, path, value) {
7052 return object2 == null ? object2 : _baseSet(object2, path, value);
7053 }
7054 var set_1 = set;
7055 function copyArray(source, array2) {
7056 var index = -1, length = source.length;
7057 array2 || (array2 = Array(length));
7058 while (++index < length) {
7059 array2[index] = source[index];
7060 }
7061 return array2;
7062 }
7063 var _copyArray = copyArray;
7064 function toPath(value) {
7065 if (isArray_1(value)) {
7066 return _arrayMap(value, _toKey);
7067 }
7068 return isSymbol_1(value) ? [value] : _copyArray(_stringToPath(toString_1(value)));
7069 }
7070 var toPath_1 = toPath;
7071 var define$2 = {
7072 // access data field
7073 data: function data2(params) {
7074 var defaults2 = {
7075 field: "data",
7076 bindingEvent: "data",
7077 allowBinding: false,
7078 allowSetting: false,
7079 allowGetting: false,
7080 settingEvent: "data",
7081 settingTriggersEvent: false,
7082 triggerFnName: "trigger",
7083 immutableKeys: {},
7084 // key => true if immutable
7085 updateStyle: false,
7086 beforeGet: function beforeGet(self2) {
7087 },
7088 beforeSet: function beforeSet(self2, obj) {
7089 },
7090 onSet: function onSet(self2) {
7091 },
7092 canSet: function canSet(self2) {
7093 return true;
7094 }
7095 };
7096 params = extend({}, defaults2, params);
7097 return function dataImpl(name2, value) {
7098 var p2 = params;
7099 var self2 = this;
7100 var selfIsArrayLike = self2.length !== void 0;
7101 var all = selfIsArrayLike ? self2 : [self2];
7102 var single = selfIsArrayLike ? self2[0] : self2;
7103 if (string(name2)) {
7104 var isPathLike = name2.indexOf(".") !== -1;
7105 var path = isPathLike && toPath_1(name2);
7106 if (p2.allowGetting && value === void 0) {
7107 var ret;
7108 if (single) {
7109 p2.beforeGet(single);
7110 if (path && single._private[p2.field][name2] === void 0) {
7111 ret = get_1(single._private[p2.field], path);
7112 } else {
7113 ret = single._private[p2.field][name2];
7114 }
7115 }
7116 return ret;
7117 } else if (p2.allowSetting && value !== void 0) {
7118 var valid2 = !p2.immutableKeys[name2];
7119 if (valid2) {
7120 var change = _defineProperty$1({}, name2, value);
7121 p2.beforeSet(self2, change);
7122 for (var i2 = 0, l = all.length; i2 < l; i2++) {
7123 var ele = all[i2];
7124 if (p2.canSet(ele)) {
7125 if (path && single._private[p2.field][name2] === void 0) {
7126 set_1(ele._private[p2.field], path, value);
7127 } else {
7128 ele._private[p2.field][name2] = value;
7129 }
7130 }
7131 }
7132 if (p2.updateStyle) {
7133 self2.updateStyle();
7134 }
7135 p2.onSet(self2);
7136 if (p2.settingTriggersEvent) {
7137 self2[p2.triggerFnName](p2.settingEvent);
7138 }
7139 }
7140 }
7141 } else if (p2.allowSetting && plainObject(name2)) {
7142 var obj = name2;
7143 var k, v;
7144 var keys = Object.keys(obj);
7145 p2.beforeSet(self2, obj);
7146 for (var _i = 0; _i < keys.length; _i++) {
7147 k = keys[_i];
7148 v = obj[k];
7149 var _valid = !p2.immutableKeys[k];
7150 if (_valid) {
7151 for (var j = 0; j < all.length; j++) {
7152 var _ele = all[j];
7153 if (p2.canSet(_ele)) {
7154 _ele._private[p2.field][k] = v;
7155 }
7156 }
7157 }
7158 }
7159 if (p2.updateStyle) {
7160 self2.updateStyle();
7161 }
7162 p2.onSet(self2);
7163 if (p2.settingTriggersEvent) {
7164 self2[p2.triggerFnName](p2.settingEvent);
7165 }
7166 } else if (p2.allowBinding && fn$6(name2)) {
7167 var fn2 = name2;
7168 self2.on(p2.bindingEvent, fn2);
7169 } else if (p2.allowGetting && name2 === void 0) {
7170 var _ret;
7171 if (single) {
7172 p2.beforeGet(single);
7173 _ret = single._private[p2.field];
7174 }
7175 return _ret;
7176 }
7177 return self2;
7178 };
7179 },
7180 // data
7181 // remove data field
7182 removeData: function removeData(params) {
7183 var defaults2 = {
7184 field: "data",
7185 event: "data",
7186 triggerFnName: "trigger",
7187 triggerEvent: false,
7188 immutableKeys: {}
7189 // key => true if immutable
7190 };
7191 params = extend({}, defaults2, params);
7192 return function removeDataImpl(names) {
7193 var p2 = params;
7194 var self2 = this;
7195 var selfIsArrayLike = self2.length !== void 0;
7196 var all = selfIsArrayLike ? self2 : [self2];
7197 if (string(names)) {
7198 var keys = names.split(/\s+/);
7199 var l = keys.length;
7200 for (var i2 = 0; i2 < l; i2++) {
7201 var key = keys[i2];
7202 if (emptyString(key)) {
7203 continue;
7204 }
7205 var valid2 = !p2.immutableKeys[key];
7206 if (valid2) {
7207 for (var i_a = 0, l_a = all.length; i_a < l_a; i_a++) {
7208 all[i_a]._private[p2.field][key] = void 0;
7209 }
7210 }
7211 }
7212 if (p2.triggerEvent) {
7213 self2[p2.triggerFnName](p2.event);
7214 }
7215 } else if (names === void 0) {
7216 for (var _i_a = 0, _l_a = all.length; _i_a < _l_a; _i_a++) {
7217 var _privateFields = all[_i_a]._private[p2.field];
7218 var _keys = Object.keys(_privateFields);
7219 for (var _i2 = 0; _i2 < _keys.length; _i2++) {
7220 var _key = _keys[_i2];
7221 var validKeyToDelete = !p2.immutableKeys[_key];
7222 if (validKeyToDelete) {
7223 _privateFields[_key] = void 0;
7224 }
7225 }
7226 }
7227 if (p2.triggerEvent) {
7228 self2[p2.triggerFnName](p2.event);
7229 }
7230 }
7231 return self2;
7232 };
7233 }
7234 // removeData
7235 };
7236 var define$1 = {
7237 eventAliasesOn: function eventAliasesOn(proto) {
7238 var p2 = proto;
7239 p2.addListener = p2.listen = p2.bind = p2.on;
7240 p2.unlisten = p2.unbind = p2.off = p2.removeListener;
7241 p2.trigger = p2.emit;
7242 p2.pon = p2.promiseOn = function(events, selector) {
7243 var self2 = this;
7244 var args = Array.prototype.slice.call(arguments, 0);
7245 return new Promise$1(function(resolve2, reject) {
7246 var callback = function callback2(e) {
7247 self2.off.apply(self2, offArgs);
7248 resolve2(e);
7249 };
7250 var onArgs = args.concat([callback]);
7251 var offArgs = onArgs.concat([]);
7252 self2.on.apply(self2, onArgs);
7253 });
7254 };
7255 }
7256 };
7257 var define = {};
7258 [define$3, define$2, define$1].forEach(function(m) {
7259 extend(define, m);
7260 });
7261 var elesfn$i = {
7262 animate: define.animate(),
7263 animation: define.animation(),
7264 animated: define.animated(),
7265 clearQueue: define.clearQueue(),
7266 delay: define.delay(),
7267 delayAnimation: define.delayAnimation(),
7268 stop: define.stop()
7269 };
7270 var elesfn$h = {
7271 classes: function classes(_classes) {
7272 var self2 = this;
7273 if (_classes === void 0) {
7274 var ret = [];
7275 self2[0]._private.classes.forEach(function(cls2) {
7276 return ret.push(cls2);
7277 });
7278 return ret;
7279 } else if (!array(_classes)) {
7280 _classes = (_classes || "").match(/\S+/g) || [];
7281 }
7282 var changed = [];
7283 var classesSet = new Set$1(_classes);
7284 for (var j = 0; j < self2.length; j++) {
7285 var ele = self2[j];
7286 var _p = ele._private;
7287 var eleClasses = _p.classes;
7288 var changedEle = false;
7289 for (var i2 = 0; i2 < _classes.length; i2++) {
7290 var cls = _classes[i2];
7291 var eleHasClass = eleClasses.has(cls);
7292 if (!eleHasClass) {
7293 changedEle = true;
7294 break;
7295 }
7296 }
7297 if (!changedEle) {
7298 changedEle = eleClasses.size !== _classes.length;
7299 }
7300 if (changedEle) {
7301 _p.classes = classesSet;
7302 changed.push(ele);
7303 }
7304 }
7305 if (changed.length > 0) {
7306 this.spawn(changed).updateStyle().emit("class");
7307 }
7308 return self2;
7309 },
7310 addClass: function addClass(classes) {
7311 return this.toggleClass(classes, true);
7312 },
7313 hasClass: function hasClass(className) {
7314 var ele = this[0];
7315 return ele != null && ele._private.classes.has(className);
7316 },
7317 toggleClass: function toggleClass(classes, toggle) {
7318 if (!array(classes)) {
7319 classes = classes.match(/\S+/g) || [];
7320 }
7321 var self2 = this;
7322 var toggleUndefd = toggle === void 0;
7323 var changed = [];
7324 for (var i2 = 0, il = self2.length; i2 < il; i2++) {
7325 var ele = self2[i2];
7326 var eleClasses = ele._private.classes;
7327 var changedEle = false;
7328 for (var j = 0; j < classes.length; j++) {
7329 var cls = classes[j];
7330 var hasClass = eleClasses.has(cls);
7331 var changedNow = false;
7332 if (toggle || toggleUndefd && !hasClass) {
7333 eleClasses.add(cls);
7334 changedNow = true;
7335 } else if (!toggle || toggleUndefd && hasClass) {
7336 eleClasses["delete"](cls);
7337 changedNow = true;
7338 }
7339 if (!changedEle && changedNow) {
7340 changed.push(ele);
7341 changedEle = true;
7342 }
7343 }
7344 }
7345 if (changed.length > 0) {
7346 this.spawn(changed).updateStyle().emit("class");
7347 }
7348 return self2;
7349 },
7350 removeClass: function removeClass(classes) {
7351 return this.toggleClass(classes, false);
7352 },
7353 flashClass: function flashClass(classes, duration) {
7354 var self2 = this;
7355 if (duration == null) {
7356 duration = 250;
7357 } else if (duration === 0) {
7358 return self2;
7359 }
7360 self2.addClass(classes);
7361 setTimeout(function() {
7362 self2.removeClass(classes);
7363 }, duration);
7364 return self2;
7365 }
7366 };
7367 elesfn$h.className = elesfn$h.classNames = elesfn$h.classes;
7368 var tokens = {
7369 metaChar: "[\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\`\\{\\|\\}\\~]",
7370 // chars we need to escape in let names, etc
7371 comparatorOp: "=|\\!=|>|>=|<|<=|\\$=|\\^=|\\*=",
7372 // binary comparison op (used in data selectors)
7373 boolOp: "\\?|\\!|\\^",
7374 // boolean (unary) operators (used in data selectors)
7375 string: `"(?:\\\\"|[^"])*"|'(?:\\\\'|[^'])*'`,
7376 // string literals (used in data selectors) -- doublequotes | singlequotes
7377 number,
7378 // number literal (used in data selectors) --- e.g. 0.1234, 1234, 12e123
7379 meta: "degree|indegree|outdegree",
7380 // allowed metadata fields (i.e. allowed functions to use from Collection)
7381 separator: "\\s*,\\s*",
7382 // queries are separated by commas, e.g. edge[foo = 'bar'], node.someClass
7383 descendant: "\\s+",
7384 child: "\\s+>\\s+",
7385 subject: "\\$",
7386 group: "node|edge|\\*",
7387 directedEdge: "\\s+->\\s+",
7388 undirectedEdge: "\\s+<->\\s+"
7389 };
7390 tokens.variable = "(?:[\\w-.]|(?:\\\\" + tokens.metaChar + "))+";
7391 tokens.className = "(?:[\\w-]|(?:\\\\" + tokens.metaChar + "))+";
7392 tokens.value = tokens.string + "|" + tokens.number;
7393 tokens.id = tokens.variable;
7394 (function() {
7395 var ops, op, i2;
7396 ops = tokens.comparatorOp.split("|");
7397 for (i2 = 0; i2 < ops.length; i2++) {
7398 op = ops[i2];
7399 tokens.comparatorOp += "|@" + op;
7400 }
7401 ops = tokens.comparatorOp.split("|");
7402 for (i2 = 0; i2 < ops.length; i2++) {
7403 op = ops[i2];
7404 if (op.indexOf("!") >= 0) {
7405 continue;
7406 }
7407 if (op === "=") {
7408 continue;
7409 }
7410 tokens.comparatorOp += "|\\!" + op;
7411 }
7412 })();
7413 var newQuery = function newQuery2() {
7414 return {
7415 checks: []
7416 };
7417 };
7418 var Type = {
7419 /** E.g. node */
7420 GROUP: 0,
7421 /** A collection of elements */
7422 COLLECTION: 1,
7423 /** A filter(ele) function */
7424 FILTER: 2,
7425 /** E.g. [foo > 1] */
7426 DATA_COMPARE: 3,
7427 /** E.g. [foo] */
7428 DATA_EXIST: 4,
7429 /** E.g. [?foo] */
7430 DATA_BOOL: 5,
7431 /** E.g. [[degree > 2]] */
7432 META_COMPARE: 6,
7433 /** E.g. :selected */
7434 STATE: 7,
7435 /** E.g. #foo */
7436 ID: 8,
7437 /** E.g. .foo */
7438 CLASS: 9,
7439 /** E.g. #foo <-> #bar */
7440 UNDIRECTED_EDGE: 10,
7441 /** E.g. #foo -> #bar */
7442 DIRECTED_EDGE: 11,
7443 /** E.g. $#foo -> #bar */
7444 NODE_SOURCE: 12,
7445 /** E.g. #foo -> $#bar */
7446 NODE_TARGET: 13,
7447 /** E.g. $#foo <-> #bar */
7448 NODE_NEIGHBOR: 14,
7449 /** E.g. #foo > #bar */
7450 CHILD: 15,
7451 /** E.g. #foo #bar */
7452 DESCENDANT: 16,
7453 /** E.g. $#foo > #bar */
7454 PARENT: 17,
7455 /** E.g. $#foo #bar */
7456 ANCESTOR: 18,
7457 /** E.g. #foo > $bar > #baz */
7458 COMPOUND_SPLIT: 19,
7459 /** Always matches, useful placeholder for subject in `COMPOUND_SPLIT` */
7460 TRUE: 20
7461 };
7462 var stateSelectors = [{
7463 selector: ":selected",
7464 matches: function matches2(ele) {
7465 return ele.selected();
7466 }
7467 }, {
7468 selector: ":unselected",
7469 matches: function matches2(ele) {
7470 return !ele.selected();
7471 }
7472 }, {
7473 selector: ":selectable",
7474 matches: function matches2(ele) {
7475 return ele.selectable();
7476 }
7477 }, {
7478 selector: ":unselectable",
7479 matches: function matches2(ele) {
7480 return !ele.selectable();
7481 }
7482 }, {
7483 selector: ":locked",
7484 matches: function matches2(ele) {
7485 return ele.locked();
7486 }
7487 }, {
7488 selector: ":unlocked",
7489 matches: function matches2(ele) {
7490 return !ele.locked();
7491 }
7492 }, {
7493 selector: ":visible",
7494 matches: function matches2(ele) {
7495 return ele.visible();
7496 }
7497 }, {
7498 selector: ":hidden",
7499 matches: function matches2(ele) {
7500 return !ele.visible();
7501 }
7502 }, {
7503 selector: ":transparent",
7504 matches: function matches2(ele) {
7505 return ele.transparent();
7506 }
7507 }, {
7508 selector: ":grabbed",
7509 matches: function matches2(ele) {
7510 return ele.grabbed();
7511 }
7512 }, {
7513 selector: ":free",
7514 matches: function matches2(ele) {
7515 return !ele.grabbed();
7516 }
7517 }, {
7518 selector: ":removed",
7519 matches: function matches2(ele) {
7520 return ele.removed();
7521 }
7522 }, {
7523 selector: ":inside",
7524 matches: function matches2(ele) {
7525 return !ele.removed();
7526 }
7527 }, {
7528 selector: ":grabbable",
7529 matches: function matches2(ele) {
7530 return ele.grabbable();
7531 }
7532 }, {
7533 selector: ":ungrabbable",
7534 matches: function matches2(ele) {
7535 return !ele.grabbable();
7536 }
7537 }, {
7538 selector: ":animated",
7539 matches: function matches2(ele) {
7540 return ele.animated();
7541 }
7542 }, {
7543 selector: ":unanimated",
7544 matches: function matches2(ele) {
7545 return !ele.animated();
7546 }
7547 }, {
7548 selector: ":parent",
7549 matches: function matches2(ele) {
7550 return ele.isParent();
7551 }
7552 }, {
7553 selector: ":childless",
7554 matches: function matches2(ele) {
7555 return ele.isChildless();
7556 }
7557 }, {
7558 selector: ":child",
7559 matches: function matches2(ele) {
7560 return ele.isChild();
7561 }
7562 }, {
7563 selector: ":orphan",
7564 matches: function matches2(ele) {
7565 return ele.isOrphan();
7566 }
7567 }, {
7568 selector: ":nonorphan",
7569 matches: function matches2(ele) {
7570 return ele.isChild();
7571 }
7572 }, {
7573 selector: ":compound",
7574 matches: function matches2(ele) {
7575 if (ele.isNode()) {
7576 return ele.isParent();
7577 } else {
7578 return ele.source().isParent() || ele.target().isParent();
7579 }
7580 }
7581 }, {
7582 selector: ":loop",
7583 matches: function matches2(ele) {
7584 return ele.isLoop();
7585 }
7586 }, {
7587 selector: ":simple",
7588 matches: function matches2(ele) {
7589 return ele.isSimple();
7590 }
7591 }, {
7592 selector: ":active",
7593 matches: function matches2(ele) {
7594 return ele.active();
7595 }
7596 }, {
7597 selector: ":inactive",
7598 matches: function matches2(ele) {
7599 return !ele.active();
7600 }
7601 }, {
7602 selector: ":backgrounding",
7603 matches: function matches2(ele) {
7604 return ele.backgrounding();
7605 }
7606 }, {
7607 selector: ":nonbackgrounding",
7608 matches: function matches2(ele) {
7609 return !ele.backgrounding();
7610 }
7611 }].sort(function(a, b) {
7612 return descending(a.selector, b.selector);
7613 });
7614 var lookup = function() {
7615 var selToFn = {};
7616 var s;
7617 for (var i2 = 0; i2 < stateSelectors.length; i2++) {
7618 s = stateSelectors[i2];
7619 selToFn[s.selector] = s.matches;
7620 }
7621 return selToFn;
7622 }();
7623 var stateSelectorMatches = function stateSelectorMatches2(sel, ele) {
7624 return lookup[sel](ele);
7625 };
7626 var stateSelectorRegex = "(" + stateSelectors.map(function(s) {
7627 return s.selector;
7628 }).join("|") + ")";
7629 var cleanMetaChars = function cleanMetaChars2(str) {
7630 return str.replace(new RegExp("\\\\(" + tokens.metaChar + ")", "g"), function(match2, $1) {
7631 return $1;
7632 });
7633 };
7634 var replaceLastQuery = function replaceLastQuery2(selector, examiningQuery, replacementQuery) {
7635 selector[selector.length - 1] = replacementQuery;
7636 };
7637 var exprs = [{
7638 name: "group",
7639 // just used for identifying when debugging
7640 query: true,
7641 regex: "(" + tokens.group + ")",
7642 populate: function populate(selector, query, _ref) {
7643 var _ref2 = _slicedToArray(_ref, 1), group = _ref2[0];
7644 query.checks.push({
7645 type: Type.GROUP,
7646 value: group === "*" ? group : group + "s"
7647 });
7648 }
7649 }, {
7650 name: "state",
7651 query: true,
7652 regex: stateSelectorRegex,
7653 populate: function populate(selector, query, _ref3) {
7654 var _ref4 = _slicedToArray(_ref3, 1), state = _ref4[0];
7655 query.checks.push({
7656 type: Type.STATE,
7657 value: state
7658 });
7659 }
7660 }, {
7661 name: "id",
7662 query: true,
7663 regex: "\\#(" + tokens.id + ")",
7664 populate: function populate(selector, query, _ref5) {
7665 var _ref6 = _slicedToArray(_ref5, 1), id = _ref6[0];
7666 query.checks.push({
7667 type: Type.ID,
7668 value: cleanMetaChars(id)
7669 });
7670 }
7671 }, {
7672 name: "className",
7673 query: true,
7674 regex: "\\.(" + tokens.className + ")",
7675 populate: function populate(selector, query, _ref7) {
7676 var _ref8 = _slicedToArray(_ref7, 1), className = _ref8[0];
7677 query.checks.push({
7678 type: Type.CLASS,
7679 value: cleanMetaChars(className)
7680 });
7681 }
7682 }, {
7683 name: "dataExists",
7684 query: true,
7685 regex: "\\[\\s*(" + tokens.variable + ")\\s*\\]",
7686 populate: function populate(selector, query, _ref9) {
7687 var _ref10 = _slicedToArray(_ref9, 1), variable = _ref10[0];
7688 query.checks.push({
7689 type: Type.DATA_EXIST,
7690 field: cleanMetaChars(variable)
7691 });
7692 }
7693 }, {
7694 name: "dataCompare",
7695 query: true,
7696 regex: "\\[\\s*(" + tokens.variable + ")\\s*(" + tokens.comparatorOp + ")\\s*(" + tokens.value + ")\\s*\\]",
7697 populate: function populate(selector, query, _ref11) {
7698 var _ref12 = _slicedToArray(_ref11, 3), variable = _ref12[0], comparatorOp = _ref12[1], value = _ref12[2];
7699 var valueIsString = new RegExp("^" + tokens.string + "$").exec(value) != null;
7700 if (valueIsString) {
7701 value = value.substring(1, value.length - 1);
7702 } else {
7703 value = parseFloat(value);
7704 }
7705 query.checks.push({
7706 type: Type.DATA_COMPARE,
7707 field: cleanMetaChars(variable),
7708 operator: comparatorOp,
7709 value
7710 });
7711 }
7712 }, {
7713 name: "dataBool",
7714 query: true,
7715 regex: "\\[\\s*(" + tokens.boolOp + ")\\s*(" + tokens.variable + ")\\s*\\]",
7716 populate: function populate(selector, query, _ref13) {
7717 var _ref14 = _slicedToArray(_ref13, 2), boolOp = _ref14[0], variable = _ref14[1];
7718 query.checks.push({
7719 type: Type.DATA_BOOL,
7720 field: cleanMetaChars(variable),
7721 operator: boolOp
7722 });
7723 }
7724 }, {
7725 name: "metaCompare",
7726 query: true,
7727 regex: "\\[\\[\\s*(" + tokens.meta + ")\\s*(" + tokens.comparatorOp + ")\\s*(" + tokens.number + ")\\s*\\]\\]",
7728 populate: function populate(selector, query, _ref15) {
7729 var _ref16 = _slicedToArray(_ref15, 3), meta2 = _ref16[0], comparatorOp = _ref16[1], number2 = _ref16[2];
7730 query.checks.push({
7731 type: Type.META_COMPARE,
7732 field: cleanMetaChars(meta2),
7733 operator: comparatorOp,
7734 value: parseFloat(number2)
7735 });
7736 }
7737 }, {
7738 name: "nextQuery",
7739 separator: true,
7740 regex: tokens.separator,
7741 populate: function populate(selector, query) {
7742 var currentSubject = selector.currentSubject;
7743 var edgeCount = selector.edgeCount;
7744 var compoundCount = selector.compoundCount;
7745 var lastQ = selector[selector.length - 1];
7746 if (currentSubject != null) {
7747 lastQ.subject = currentSubject;
7748 selector.currentSubject = null;
7749 }
7750 lastQ.edgeCount = edgeCount;
7751 lastQ.compoundCount = compoundCount;
7752 selector.edgeCount = 0;
7753 selector.compoundCount = 0;
7754 var nextQuery = selector[selector.length++] = newQuery();
7755 return nextQuery;
7756 }
7757 }, {
7758 name: "directedEdge",
7759 separator: true,
7760 regex: tokens.directedEdge,
7761 populate: function populate(selector, query) {
7762 if (selector.currentSubject == null) {
7763 var edgeQuery = newQuery();
7764 var source = query;
7765 var target = newQuery();
7766 edgeQuery.checks.push({
7767 type: Type.DIRECTED_EDGE,
7768 source,
7769 target
7770 });
7771 replaceLastQuery(selector, query, edgeQuery);
7772 selector.edgeCount++;
7773 return target;
7774 } else {
7775 var srcTgtQ = newQuery();
7776 var _source = query;
7777 var _target = newQuery();
7778 srcTgtQ.checks.push({
7779 type: Type.NODE_SOURCE,
7780 source: _source,
7781 target: _target
7782 });
7783 replaceLastQuery(selector, query, srcTgtQ);
7784 selector.edgeCount++;
7785 return _target;
7786 }
7787 }
7788 }, {
7789 name: "undirectedEdge",
7790 separator: true,
7791 regex: tokens.undirectedEdge,
7792 populate: function populate(selector, query) {
7793 if (selector.currentSubject == null) {
7794 var edgeQuery = newQuery();
7795 var source = query;
7796 var target = newQuery();
7797 edgeQuery.checks.push({
7798 type: Type.UNDIRECTED_EDGE,
7799 nodes: [source, target]
7800 });
7801 replaceLastQuery(selector, query, edgeQuery);
7802 selector.edgeCount++;
7803 return target;
7804 } else {
7805 var nhoodQ = newQuery();
7806 var node = query;
7807 var neighbor = newQuery();
7808 nhoodQ.checks.push({
7809 type: Type.NODE_NEIGHBOR,
7810 node,
7811 neighbor
7812 });
7813 replaceLastQuery(selector, query, nhoodQ);
7814 return neighbor;
7815 }
7816 }
7817 }, {
7818 name: "child",
7819 separator: true,
7820 regex: tokens.child,
7821 populate: function populate(selector, query) {
7822 if (selector.currentSubject == null) {
7823 var parentChildQuery = newQuery();
7824 var child = newQuery();
7825 var parent = selector[selector.length - 1];
7826 parentChildQuery.checks.push({
7827 type: Type.CHILD,
7828 parent,
7829 child
7830 });
7831 replaceLastQuery(selector, query, parentChildQuery);
7832 selector.compoundCount++;
7833 return child;
7834 } else if (selector.currentSubject === query) {
7835 var compound = newQuery();
7836 var left = selector[selector.length - 1];
7837 var right = newQuery();
7838 var subject = newQuery();
7839 var _child = newQuery();
7840 var _parent = newQuery();
7841 compound.checks.push({
7842 type: Type.COMPOUND_SPLIT,
7843 left,
7844 right,
7845 subject
7846 });
7847 subject.checks = query.checks;
7848 query.checks = [{
7849 type: Type.TRUE
7850 }];
7851 _parent.checks.push({
7852 type: Type.TRUE
7853 });
7854 right.checks.push({
7855 type: Type.PARENT,
7856 // type is swapped on right side queries
7857 parent: _parent,
7858 child: _child
7859 // empty for now
7860 });
7861 replaceLastQuery(selector, left, compound);
7862 selector.currentSubject = subject;
7863 selector.compoundCount++;
7864 return _child;
7865 } else {
7866 var _parent2 = newQuery();
7867 var _child2 = newQuery();
7868 var pcQChecks = [{
7869 type: Type.PARENT,
7870 parent: _parent2,
7871 child: _child2
7872 }];
7873 _parent2.checks = query.checks;
7874 query.checks = pcQChecks;
7875 selector.compoundCount++;
7876 return _child2;
7877 }
7878 }
7879 }, {
7880 name: "descendant",
7881 separator: true,
7882 regex: tokens.descendant,
7883 populate: function populate(selector, query) {
7884 if (selector.currentSubject == null) {
7885 var ancChQuery = newQuery();
7886 var descendant = newQuery();
7887 var ancestor = selector[selector.length - 1];
7888 ancChQuery.checks.push({
7889 type: Type.DESCENDANT,
7890 ancestor,
7891 descendant
7892 });
7893 replaceLastQuery(selector, query, ancChQuery);
7894 selector.compoundCount++;
7895 return descendant;
7896 } else if (selector.currentSubject === query) {
7897 var compound = newQuery();
7898 var left = selector[selector.length - 1];
7899 var right = newQuery();
7900 var subject = newQuery();
7901 var _descendant = newQuery();
7902 var _ancestor = newQuery();
7903 compound.checks.push({
7904 type: Type.COMPOUND_SPLIT,
7905 left,
7906 right,
7907 subject
7908 });
7909 subject.checks = query.checks;
7910 query.checks = [{
7911 type: Type.TRUE
7912 }];
7913 _ancestor.checks.push({
7914 type: Type.TRUE
7915 });
7916 right.checks.push({
7917 type: Type.ANCESTOR,
7918 // type is swapped on right side queries
7919 ancestor: _ancestor,
7920 descendant: _descendant
7921 // empty for now
7922 });
7923 replaceLastQuery(selector, left, compound);
7924 selector.currentSubject = subject;
7925 selector.compoundCount++;
7926 return _descendant;
7927 } else {
7928 var _ancestor2 = newQuery();
7929 var _descendant2 = newQuery();
7930 var adQChecks = [{
7931 type: Type.ANCESTOR,
7932 ancestor: _ancestor2,
7933 descendant: _descendant2
7934 }];
7935 _ancestor2.checks = query.checks;
7936 query.checks = adQChecks;
7937 selector.compoundCount++;
7938 return _descendant2;
7939 }
7940 }
7941 }, {
7942 name: "subject",
7943 modifier: true,
7944 regex: tokens.subject,
7945 populate: function populate(selector, query) {
7946 if (selector.currentSubject != null && selector.currentSubject !== query) {
7947 warn("Redefinition of subject in selector `" + selector.toString() + "`");
7948 return false;
7949 }
7950 selector.currentSubject = query;
7951 var topQ = selector[selector.length - 1];
7952 var topChk = topQ.checks[0];
7953 var topType = topChk == null ? null : topChk.type;
7954 if (topType === Type.DIRECTED_EDGE) {
7955 topChk.type = Type.NODE_TARGET;
7956 } else if (topType === Type.UNDIRECTED_EDGE) {
7957 topChk.type = Type.NODE_NEIGHBOR;
7958 topChk.node = topChk.nodes[1];
7959 topChk.neighbor = topChk.nodes[0];
7960 topChk.nodes = null;
7961 }
7962 }
7963 }];
7964 exprs.forEach(function(e) {
7965 return e.regexObj = new RegExp("^" + e.regex);
7966 });
7967 var consumeExpr = function consumeExpr2(remaining) {
7968 var expr;
7969 var match2;
7970 var name2;
7971 for (var j = 0; j < exprs.length; j++) {
7972 var e = exprs[j];
7973 var n = e.name;
7974 var m = remaining.match(e.regexObj);
7975 if (m != null) {
7976 match2 = m;
7977 expr = e;
7978 name2 = n;
7979 var consumed = m[0];
7980 remaining = remaining.substring(consumed.length);
7981 break;
7982 }
7983 }
7984 return {
7985 expr,
7986 match: match2,
7987 name: name2,
7988 remaining
7989 };
7990 };
7991 var consumeWhitespace = function consumeWhitespace2(remaining) {
7992 var match2 = remaining.match(/^\s+/);
7993 if (match2) {
7994 var consumed = match2[0];
7995 remaining = remaining.substring(consumed.length);
7996 }
7997 return remaining;
7998 };
7999 var parse = function parse2(selector) {
8000 var self2 = this;
8001 var remaining = self2.inputText = selector;
8002 var currentQuery = self2[0] = newQuery();
8003 self2.length = 1;
8004 remaining = consumeWhitespace(remaining);
8005 for (; ; ) {
8006 var exprInfo = consumeExpr(remaining);
8007 if (exprInfo.expr == null) {
8008 warn("The selector `" + selector + "`is invalid");
8009 return false;
8010 } else {
8011 var args = exprInfo.match.slice(1);
8012 var ret = exprInfo.expr.populate(self2, currentQuery, args);
8013 if (ret === false) {
8014 return false;
8015 } else if (ret != null) {
8016 currentQuery = ret;
8017 }
8018 }
8019 remaining = exprInfo.remaining;
8020 if (remaining.match(/^\s*$/)) {
8021 break;
8022 }
8023 }
8024 var lastQ = self2[self2.length - 1];
8025 if (self2.currentSubject != null) {
8026 lastQ.subject = self2.currentSubject;
8027 }
8028 lastQ.edgeCount = self2.edgeCount;
8029 lastQ.compoundCount = self2.compoundCount;
8030 for (var i2 = 0; i2 < self2.length; i2++) {
8031 var q = self2[i2];
8032 if (q.compoundCount > 0 && q.edgeCount > 0) {
8033 warn("The selector `" + selector + "` is invalid because it uses both a compound selector and an edge selector");
8034 return false;
8035 }
8036 if (q.edgeCount > 1) {
8037 warn("The selector `" + selector + "` is invalid because it uses multiple edge selectors");
8038 return false;
8039 } else if (q.edgeCount === 1) {
8040 warn("The selector `" + selector + "` is deprecated. Edge selectors do not take effect on changes to source and target nodes after an edge is added, for performance reasons. Use a class or data selector on edges instead, updating the class or data of an edge when your app detects a change in source or target nodes.");
8041 }
8042 }
8043 return true;
8044 };
8045 var toString = function toString2() {
8046 if (this.toStringCache != null) {
8047 return this.toStringCache;
8048 }
8049 var clean = function clean2(obj) {
8050 if (obj == null) {
8051 return "";
8052 } else {
8053 return obj;
8054 }
8055 };
8056 var cleanVal = function cleanVal2(val) {
8057 if (string(val)) {
8058 return '"' + val + '"';
8059 } else {
8060 return clean(val);
8061 }
8062 };
8063 var space = function space2(val) {
8064 return " " + val + " ";
8065 };
8066 var checkToString = function checkToString2(check, subject) {
8067 var type = check.type, value = check.value;
8068 switch (type) {
8069 case Type.GROUP: {
8070 var group = clean(value);
8071 return group.substring(0, group.length - 1);
8072 }
8073 case Type.DATA_COMPARE: {
8074 var field = check.field, operator = check.operator;
8075 return "[" + field + space(clean(operator)) + cleanVal(value) + "]";
8076 }
8077 case Type.DATA_BOOL: {
8078 var _operator = check.operator, _field = check.field;
8079 return "[" + clean(_operator) + _field + "]";
8080 }
8081 case Type.DATA_EXIST: {
8082 var _field2 = check.field;
8083 return "[" + _field2 + "]";
8084 }
8085 case Type.META_COMPARE: {
8086 var _operator2 = check.operator, _field3 = check.field;
8087 return "[[" + _field3 + space(clean(_operator2)) + cleanVal(value) + "]]";
8088 }
8089 case Type.STATE: {
8090 return value;
8091 }
8092 case Type.ID: {
8093 return "#" + value;
8094 }
8095 case Type.CLASS: {
8096 return "." + value;
8097 }
8098 case Type.PARENT:
8099 case Type.CHILD: {
8100 return queryToString(check.parent, subject) + space(">") + queryToString(check.child, subject);
8101 }
8102 case Type.ANCESTOR:
8103 case Type.DESCENDANT: {
8104 return queryToString(check.ancestor, subject) + " " + queryToString(check.descendant, subject);
8105 }
8106 case Type.COMPOUND_SPLIT: {
8107 var lhs = queryToString(check.left, subject);
8108 var sub = queryToString(check.subject, subject);
8109 var rhs = queryToString(check.right, subject);
8110 return lhs + (lhs.length > 0 ? " " : "") + sub + rhs;
8111 }
8112 case Type.TRUE: {
8113 return "";
8114 }
8115 }
8116 };
8117 var queryToString = function queryToString2(query2, subject) {
8118 return query2.checks.reduce(function(str2, chk, i3) {
8119 return str2 + (subject === query2 && i3 === 0 ? "$" : "") + checkToString(chk, subject);
8120 }, "");
8121 };
8122 var str = "";
8123 for (var i2 = 0; i2 < this.length; i2++) {
8124 var query = this[i2];
8125 str += queryToString(query, query.subject);
8126 if (this.length > 1 && i2 < this.length - 1) {
8127 str += ", ";
8128 }
8129 }
8130 this.toStringCache = str;
8131 return str;
8132 };
8133 var parse$1 = {
8134 parse,
8135 toString
8136 };
8137 var valCmp = function valCmp2(fieldVal, operator, value) {
8138 var matches2;
8139 var isFieldStr = string(fieldVal);
8140 var isFieldNum = number$1(fieldVal);
8141 var isValStr = string(value);
8142 var fieldStr, valStr;
8143 var caseInsensitive = false;
8144 var notExpr = false;
8145 var isIneqCmp = false;
8146 if (operator.indexOf("!") >= 0) {
8147 operator = operator.replace("!", "");
8148 notExpr = true;
8149 }
8150 if (operator.indexOf("@") >= 0) {
8151 operator = operator.replace("@", "");
8152 caseInsensitive = true;
8153 }
8154 if (isFieldStr || isValStr || caseInsensitive) {
8155 fieldStr = !isFieldStr && !isFieldNum ? "" : "" + fieldVal;
8156 valStr = "" + value;
8157 }
8158 if (caseInsensitive) {
8159 fieldVal = fieldStr = fieldStr.toLowerCase();
8160 value = valStr = valStr.toLowerCase();
8161 }
8162 switch (operator) {
8163 case "*=":
8164 matches2 = fieldStr.indexOf(valStr) >= 0;
8165 break;
8166 case "$=":
8167 matches2 = fieldStr.indexOf(valStr, fieldStr.length - valStr.length) >= 0;
8168 break;
8169 case "^=":
8170 matches2 = fieldStr.indexOf(valStr) === 0;
8171 break;
8172 case "=":
8173 matches2 = fieldVal === value;
8174 break;
8175 case ">":
8176 isIneqCmp = true;
8177 matches2 = fieldVal > value;
8178 break;
8179 case ">=":
8180 isIneqCmp = true;
8181 matches2 = fieldVal >= value;
8182 break;
8183 case "<":
8184 isIneqCmp = true;
8185 matches2 = fieldVal < value;
8186 break;
8187 case "<=":
8188 isIneqCmp = true;
8189 matches2 = fieldVal <= value;
8190 break;
8191 default:
8192 matches2 = false;
8193 break;
8194 }
8195 if (notExpr && (fieldVal != null || !isIneqCmp)) {
8196 matches2 = !matches2;
8197 }
8198 return matches2;
8199 };
8200 var boolCmp = function boolCmp2(fieldVal, operator) {
8201 switch (operator) {
8202 case "?":
8203 return fieldVal ? true : false;
8204 case "!":
8205 return fieldVal ? false : true;
8206 case "^":
8207 return fieldVal === void 0;
8208 }
8209 };
8210 var existCmp = function existCmp2(fieldVal) {
8211 return fieldVal !== void 0;
8212 };
8213 var data$1 = function data2(ele, field) {
8214 return ele.data(field);
8215 };
8216 var meta = function meta2(ele, field) {
8217 return ele[field]();
8218 };
8219 var match = [];
8220 var matches$1 = function matches2(query, ele) {
8221 return query.checks.every(function(chk) {
8222 return match[chk.type](chk, ele);
8223 });
8224 };
8225 match[Type.GROUP] = function(check, ele) {
8226 var group = check.value;
8227 return group === "*" || group === ele.group();
8228 };
8229 match[Type.STATE] = function(check, ele) {
8230 var stateSelector = check.value;
8231 return stateSelectorMatches(stateSelector, ele);
8232 };
8233 match[Type.ID] = function(check, ele) {
8234 var id = check.value;
8235 return ele.id() === id;
8236 };
8237 match[Type.CLASS] = function(check, ele) {
8238 var cls = check.value;
8239 return ele.hasClass(cls);
8240 };
8241 match[Type.META_COMPARE] = function(check, ele) {
8242 var field = check.field, operator = check.operator, value = check.value;
8243 return valCmp(meta(ele, field), operator, value);
8244 };
8245 match[Type.DATA_COMPARE] = function(check, ele) {
8246 var field = check.field, operator = check.operator, value = check.value;
8247 return valCmp(data$1(ele, field), operator, value);
8248 };
8249 match[Type.DATA_BOOL] = function(check, ele) {
8250 var field = check.field, operator = check.operator;
8251 return boolCmp(data$1(ele, field), operator);
8252 };
8253 match[Type.DATA_EXIST] = function(check, ele) {
8254 var field = check.field;
8255 check.operator;
8256 return existCmp(data$1(ele, field));
8257 };
8258 match[Type.UNDIRECTED_EDGE] = function(check, ele) {
8259 var qA = check.nodes[0];
8260 var qB = check.nodes[1];
8261 var src = ele.source();
8262 var tgt = ele.target();
8263 return matches$1(qA, src) && matches$1(qB, tgt) || matches$1(qB, src) && matches$1(qA, tgt);
8264 };
8265 match[Type.NODE_NEIGHBOR] = function(check, ele) {
8266 return matches$1(check.node, ele) && ele.neighborhood().some(function(n) {
8267 return n.isNode() && matches$1(check.neighbor, n);
8268 });
8269 };
8270 match[Type.DIRECTED_EDGE] = function(check, ele) {
8271 return matches$1(check.source, ele.source()) && matches$1(check.target, ele.target());
8272 };
8273 match[Type.NODE_SOURCE] = function(check, ele) {
8274 return matches$1(check.source, ele) && ele.outgoers().some(function(n) {
8275 return n.isNode() && matches$1(check.target, n);
8276 });
8277 };
8278 match[Type.NODE_TARGET] = function(check, ele) {
8279 return matches$1(check.target, ele) && ele.incomers().some(function(n) {
8280 return n.isNode() && matches$1(check.source, n);
8281 });
8282 };
8283 match[Type.CHILD] = function(check, ele) {
8284 return matches$1(check.child, ele) && matches$1(check.parent, ele.parent());
8285 };
8286 match[Type.PARENT] = function(check, ele) {
8287 return matches$1(check.parent, ele) && ele.children().some(function(c) {
8288 return matches$1(check.child, c);
8289 });
8290 };
8291 match[Type.DESCENDANT] = function(check, ele) {
8292 return matches$1(check.descendant, ele) && ele.ancestors().some(function(a) {
8293 return matches$1(check.ancestor, a);
8294 });
8295 };
8296 match[Type.ANCESTOR] = function(check, ele) {
8297 return matches$1(check.ancestor, ele) && ele.descendants().some(function(d) {
8298 return matches$1(check.descendant, d);
8299 });
8300 };
8301 match[Type.COMPOUND_SPLIT] = function(check, ele) {
8302 return matches$1(check.subject, ele) && matches$1(check.left, ele) && matches$1(check.right, ele);
8303 };
8304 match[Type.TRUE] = function() {
8305 return true;
8306 };
8307 match[Type.COLLECTION] = function(check, ele) {
8308 var collection2 = check.value;
8309 return collection2.has(ele);
8310 };
8311 match[Type.FILTER] = function(check, ele) {
8312 var filter2 = check.value;
8313 return filter2(ele);
8314 };
8315 var filter = function filter2(collection2) {
8316 var self2 = this;
8317 if (self2.length === 1 && self2[0].checks.length === 1 && self2[0].checks[0].type === Type.ID) {
8318 return collection2.getElementById(self2[0].checks[0].value).collection();
8319 }
8320 var selectorFunction = function selectorFunction2(element2) {
8321 for (var j = 0; j < self2.length; j++) {
8322 var query = self2[j];
8323 if (matches$1(query, element2)) {
8324 return true;
8325 }
8326 }
8327 return false;
8328 };
8329 if (self2.text() == null) {
8330 selectorFunction = function selectorFunction2() {
8331 return true;
8332 };
8333 }
8334 return collection2.filter(selectorFunction);
8335 };
8336 var matches = function matches2(ele) {
8337 var self2 = this;
8338 for (var j = 0; j < self2.length; j++) {
8339 var query = self2[j];
8340 if (matches$1(query, ele)) {
8341 return true;
8342 }
8343 }
8344 return false;
8345 };
8346 var matching = {
8347 matches,
8348 filter
8349 };
8350 var Selector = function Selector2(selector) {
8351 this.inputText = selector;
8352 this.currentSubject = null;
8353 this.compoundCount = 0;
8354 this.edgeCount = 0;
8355 this.length = 0;
8356 if (selector == null || string(selector) && selector.match(/^\s*$/))
8357 ;
8358 else if (elementOrCollection(selector)) {
8359 this.addQuery({
8360 checks: [{
8361 type: Type.COLLECTION,
8362 value: selector.collection()
8363 }]
8364 });
8365 } else if (fn$6(selector)) {
8366 this.addQuery({
8367 checks: [{
8368 type: Type.FILTER,
8369 value: selector
8370 }]
8371 });
8372 } else if (string(selector)) {
8373 if (!this.parse(selector)) {
8374 this.invalid = true;
8375 }
8376 } else {
8377 error("A selector must be created from a string; found ");
8378 }
8379 };
8380 var selfn = Selector.prototype;
8381 [parse$1, matching].forEach(function(p2) {
8382 return extend(selfn, p2);
8383 });
8384 selfn.text = function() {
8385 return this.inputText;
8386 };
8387 selfn.size = function() {
8388 return this.length;
8389 };
8390 selfn.eq = function(i2) {
8391 return this[i2];
8392 };
8393 selfn.sameText = function(otherSel) {
8394 return !this.invalid && !otherSel.invalid && this.text() === otherSel.text();
8395 };
8396 selfn.addQuery = function(q) {
8397 this[this.length++] = q;
8398 };
8399 selfn.selector = selfn.toString;
8400 var elesfn$g = {
8401 allAre: function allAre(selector) {
8402 var selObj = new Selector(selector);
8403 return this.every(function(ele) {
8404 return selObj.matches(ele);
8405 });
8406 },
8407 is: function is(selector) {
8408 var selObj = new Selector(selector);
8409 return this.some(function(ele) {
8410 return selObj.matches(ele);
8411 });
8412 },
8413 some: function some(fn2, thisArg) {
8414 for (var i2 = 0; i2 < this.length; i2++) {
8415 var ret = !thisArg ? fn2(this[i2], i2, this) : fn2.apply(thisArg, [this[i2], i2, this]);
8416 if (ret) {
8417 return true;
8418 }
8419 }
8420 return false;
8421 },
8422 every: function every(fn2, thisArg) {
8423 for (var i2 = 0; i2 < this.length; i2++) {
8424 var ret = !thisArg ? fn2(this[i2], i2, this) : fn2.apply(thisArg, [this[i2], i2, this]);
8425 if (!ret) {
8426 return false;
8427 }
8428 }
8429 return true;
8430 },
8431 same: function same(collection2) {
8432 if (this === collection2) {
8433 return true;
8434 }
8435 collection2 = this.cy().collection(collection2);
8436 var thisLength = this.length;
8437 var collectionLength = collection2.length;
8438 if (thisLength !== collectionLength) {
8439 return false;
8440 }
8441 if (thisLength === 1) {
8442 return this[0] === collection2[0];
8443 }
8444 return this.every(function(ele) {
8445 return collection2.hasElementWithId(ele.id());
8446 });
8447 },
8448 anySame: function anySame(collection2) {
8449 collection2 = this.cy().collection(collection2);
8450 return this.some(function(ele) {
8451 return collection2.hasElementWithId(ele.id());
8452 });
8453 },
8454 allAreNeighbors: function allAreNeighbors(collection2) {
8455 collection2 = this.cy().collection(collection2);
8456 var nhood = this.neighborhood();
8457 return collection2.every(function(ele) {
8458 return nhood.hasElementWithId(ele.id());
8459 });
8460 },
8461 contains: function contains(collection2) {
8462 collection2 = this.cy().collection(collection2);
8463 var self2 = this;
8464 return collection2.every(function(ele) {
8465 return self2.hasElementWithId(ele.id());
8466 });
8467 }
8468 };
8469 elesfn$g.allAreNeighbours = elesfn$g.allAreNeighbors;
8470 elesfn$g.has = elesfn$g.contains;
8471 elesfn$g.equal = elesfn$g.equals = elesfn$g.same;
8472 var cache = function cache2(fn2, name2) {
8473 return function traversalCache(arg1, arg2, arg3, arg4) {
8474 var selectorOrEles = arg1;
8475 var eles = this;
8476 var key;
8477 if (selectorOrEles == null) {
8478 key = "";
8479 } else if (elementOrCollection(selectorOrEles) && selectorOrEles.length === 1) {
8480 key = selectorOrEles.id();
8481 }
8482 if (eles.length === 1 && key) {
8483 var _p = eles[0]._private;
8484 var tch = _p.traversalCache = _p.traversalCache || {};
8485 var ch = tch[name2] = tch[name2] || [];
8486 var hash = hashString(key);
8487 var cacheHit = ch[hash];
8488 if (cacheHit) {
8489 return cacheHit;
8490 } else {
8491 return ch[hash] = fn2.call(eles, arg1, arg2, arg3, arg4);
8492 }
8493 } else {
8494 return fn2.call(eles, arg1, arg2, arg3, arg4);
8495 }
8496 };
8497 };
8498 var elesfn$f = {
8499 parent: function parent(selector) {
8500 var parents = [];
8501 if (this.length === 1) {
8502 var parent2 = this[0]._private.parent;
8503 if (parent2) {
8504 return parent2;
8505 }
8506 }
8507 for (var i2 = 0; i2 < this.length; i2++) {
8508 var ele = this[i2];
8509 var _parent = ele._private.parent;
8510 if (_parent) {
8511 parents.push(_parent);
8512 }
8513 }
8514 return this.spawn(parents, true).filter(selector);
8515 },
8516 parents: function parents(selector) {
8517 var parents2 = [];
8518 var eles = this.parent();
8519 while (eles.nonempty()) {
8520 for (var i2 = 0; i2 < eles.length; i2++) {
8521 var ele = eles[i2];
8522 parents2.push(ele);
8523 }
8524 eles = eles.parent();
8525 }
8526 return this.spawn(parents2, true).filter(selector);
8527 },
8528 commonAncestors: function commonAncestors(selector) {
8529 var ancestors;
8530 for (var i2 = 0; i2 < this.length; i2++) {
8531 var ele = this[i2];
8532 var parents = ele.parents();
8533 ancestors = ancestors || parents;
8534 ancestors = ancestors.intersect(parents);
8535 }
8536 return ancestors.filter(selector);
8537 },
8538 orphans: function orphans(selector) {
8539 return this.stdFilter(function(ele) {
8540 return ele.isOrphan();
8541 }).filter(selector);
8542 },
8543 nonorphans: function nonorphans(selector) {
8544 return this.stdFilter(function(ele) {
8545 return ele.isChild();
8546 }).filter(selector);
8547 },
8548 children: cache(function(selector) {
8549 var children = [];
8550 for (var i2 = 0; i2 < this.length; i2++) {
8551 var ele = this[i2];
8552 var eleChildren = ele._private.children;
8553 for (var j = 0; j < eleChildren.length; j++) {
8554 children.push(eleChildren[j]);
8555 }
8556 }
8557 return this.spawn(children, true).filter(selector);
8558 }, "children"),
8559 siblings: function siblings(selector) {
8560 return this.parent().children().not(this).filter(selector);
8561 },
8562 isParent: function isParent() {
8563 var ele = this[0];
8564 if (ele) {
8565 return ele.isNode() && ele._private.children.length !== 0;
8566 }
8567 },
8568 isChildless: function isChildless() {
8569 var ele = this[0];
8570 if (ele) {
8571 return ele.isNode() && ele._private.children.length === 0;
8572 }
8573 },
8574 isChild: function isChild() {
8575 var ele = this[0];
8576 if (ele) {
8577 return ele.isNode() && ele._private.parent != null;
8578 }
8579 },
8580 isOrphan: function isOrphan() {
8581 var ele = this[0];
8582 if (ele) {
8583 return ele.isNode() && ele._private.parent == null;
8584 }
8585 },
8586 descendants: function descendants(selector) {
8587 var elements2 = [];
8588 function add(eles) {
8589 for (var i2 = 0; i2 < eles.length; i2++) {
8590 var ele = eles[i2];
8591 elements2.push(ele);
8592 if (ele.children().nonempty()) {
8593 add(ele.children());
8594 }
8595 }
8596 }
8597 add(this.children());
8598 return this.spawn(elements2, true).filter(selector);
8599 }
8600 };
8601 function forEachCompound(eles, fn2, includeSelf, recursiveStep) {
8602 var q = [];
8603 var did = new Set$1();
8604 var cy = eles.cy();
8605 var hasCompounds = cy.hasCompoundNodes();
8606 for (var i2 = 0; i2 < eles.length; i2++) {
8607 var ele = eles[i2];
8608 if (includeSelf) {
8609 q.push(ele);
8610 } else if (hasCompounds) {
8611 recursiveStep(q, did, ele);
8612 }
8613 }
8614 while (q.length > 0) {
8615 var _ele = q.shift();
8616 fn2(_ele);
8617 did.add(_ele.id());
8618 if (hasCompounds) {
8619 recursiveStep(q, did, _ele);
8620 }
8621 }
8622 return eles;
8623 }
8624 function addChildren(q, did, ele) {
8625 if (ele.isParent()) {
8626 var children = ele._private.children;
8627 for (var i2 = 0; i2 < children.length; i2++) {
8628 var child = children[i2];
8629 if (!did.has(child.id())) {
8630 q.push(child);
8631 }
8632 }
8633 }
8634 }
8635 elesfn$f.forEachDown = function(fn2) {
8636 var includeSelf = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
8637 return forEachCompound(this, fn2, includeSelf, addChildren);
8638 };
8639 function addParent(q, did, ele) {
8640 if (ele.isChild()) {
8641 var parent = ele._private.parent;
8642 if (!did.has(parent.id())) {
8643 q.push(parent);
8644 }
8645 }
8646 }
8647 elesfn$f.forEachUp = function(fn2) {
8648 var includeSelf = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
8649 return forEachCompound(this, fn2, includeSelf, addParent);
8650 };
8651 function addParentAndChildren(q, did, ele) {
8652 addParent(q, did, ele);
8653 addChildren(q, did, ele);
8654 }
8655 elesfn$f.forEachUpAndDown = function(fn2) {
8656 var includeSelf = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
8657 return forEachCompound(this, fn2, includeSelf, addParentAndChildren);
8658 };
8659 elesfn$f.ancestors = elesfn$f.parents;
8660 var fn$5, elesfn$e;
8661 fn$5 = elesfn$e = {
8662 data: define.data({
8663 field: "data",
8664 bindingEvent: "data",
8665 allowBinding: true,
8666 allowSetting: true,
8667 settingEvent: "data",
8668 settingTriggersEvent: true,
8669 triggerFnName: "trigger",
8670 allowGetting: true,
8671 immutableKeys: {
8672 "id": true,
8673 "source": true,
8674 "target": true,
8675 "parent": true
8676 },
8677 updateStyle: true
8678 }),
8679 removeData: define.removeData({
8680 field: "data",
8681 event: "data",
8682 triggerFnName: "trigger",
8683 triggerEvent: true,
8684 immutableKeys: {
8685 "id": true,
8686 "source": true,
8687 "target": true,
8688 "parent": true
8689 },
8690 updateStyle: true
8691 }),
8692 scratch: define.data({
8693 field: "scratch",
8694 bindingEvent: "scratch",
8695 allowBinding: true,
8696 allowSetting: true,
8697 settingEvent: "scratch",
8698 settingTriggersEvent: true,
8699 triggerFnName: "trigger",
8700 allowGetting: true,
8701 updateStyle: true
8702 }),
8703 removeScratch: define.removeData({
8704 field: "scratch",
8705 event: "scratch",
8706 triggerFnName: "trigger",
8707 triggerEvent: true,
8708 updateStyle: true
8709 }),
8710 rscratch: define.data({
8711 field: "rscratch",
8712 allowBinding: false,
8713 allowSetting: true,
8714 settingTriggersEvent: false,
8715 allowGetting: true
8716 }),
8717 removeRscratch: define.removeData({
8718 field: "rscratch",
8719 triggerEvent: false
8720 }),
8721 id: function id() {
8722 var ele = this[0];
8723 if (ele) {
8724 return ele._private.data.id;
8725 }
8726 }
8727 };
8728 fn$5.attr = fn$5.data;
8729 fn$5.removeAttr = fn$5.removeData;
8730 var data = elesfn$e;
8731 var elesfn$d = {};
8732 function defineDegreeFunction(callback) {
8733 return function(includeLoops) {
8734 var self2 = this;
8735 if (includeLoops === void 0) {
8736 includeLoops = true;
8737 }
8738 if (self2.length === 0) {
8739 return;
8740 }
8741 if (self2.isNode() && !self2.removed()) {
8742 var degree = 0;
8743 var node = self2[0];
8744 var connectedEdges = node._private.edges;
8745 for (var i2 = 0; i2 < connectedEdges.length; i2++) {
8746 var edge = connectedEdges[i2];
8747 if (!includeLoops && edge.isLoop()) {
8748 continue;
8749 }
8750 degree += callback(node, edge);
8751 }
8752 return degree;
8753 } else {
8754 return;
8755 }
8756 };
8757 }
8758 extend(elesfn$d, {
8759 degree: defineDegreeFunction(function(node, edge) {
8760 if (edge.source().same(edge.target())) {
8761 return 2;
8762 } else {
8763 return 1;
8764 }
8765 }),
8766 indegree: defineDegreeFunction(function(node, edge) {
8767 if (edge.target().same(node)) {
8768 return 1;
8769 } else {
8770 return 0;
8771 }
8772 }),
8773 outdegree: defineDegreeFunction(function(node, edge) {
8774 if (edge.source().same(node)) {
8775 return 1;
8776 } else {
8777 return 0;
8778 }
8779 })
8780 });
8781 function defineDegreeBoundsFunction(degreeFn, callback) {
8782 return function(includeLoops) {
8783 var ret;
8784 var nodes2 = this.nodes();
8785 for (var i2 = 0; i2 < nodes2.length; i2++) {
8786 var ele = nodes2[i2];
8787 var degree = ele[degreeFn](includeLoops);
8788 if (degree !== void 0 && (ret === void 0 || callback(degree, ret))) {
8789 ret = degree;
8790 }
8791 }
8792 return ret;
8793 };
8794 }
8795 extend(elesfn$d, {
8796 minDegree: defineDegreeBoundsFunction("degree", function(degree, min2) {
8797 return degree < min2;
8798 }),
8799 maxDegree: defineDegreeBoundsFunction("degree", function(degree, max2) {
8800 return degree > max2;
8801 }),
8802 minIndegree: defineDegreeBoundsFunction("indegree", function(degree, min2) {
8803 return degree < min2;
8804 }),
8805 maxIndegree: defineDegreeBoundsFunction("indegree", function(degree, max2) {
8806 return degree > max2;
8807 }),
8808 minOutdegree: defineDegreeBoundsFunction("outdegree", function(degree, min2) {
8809 return degree < min2;
8810 }),
8811 maxOutdegree: defineDegreeBoundsFunction("outdegree", function(degree, max2) {
8812 return degree > max2;
8813 })
8814 });
8815 extend(elesfn$d, {
8816 totalDegree: function totalDegree(includeLoops) {
8817 var total = 0;
8818 var nodes2 = this.nodes();
8819 for (var i2 = 0; i2 < nodes2.length; i2++) {
8820 total += nodes2[i2].degree(includeLoops);
8821 }
8822 return total;
8823 }
8824 });
8825 var fn$4, elesfn$c;
8826 var beforePositionSet = function beforePositionSet2(eles, newPos, silent) {
8827 for (var i2 = 0; i2 < eles.length; i2++) {
8828 var ele = eles[i2];
8829 if (!ele.locked()) {
8830 var oldPos = ele._private.position;
8831 var delta = {
8832 x: newPos.x != null ? newPos.x - oldPos.x : 0,
8833 y: newPos.y != null ? newPos.y - oldPos.y : 0
8834 };
8835 if (ele.isParent() && !(delta.x === 0 && delta.y === 0)) {
8836 ele.children().shift(delta, silent);
8837 }
8838 ele.dirtyBoundingBoxCache();
8839 }
8840 }
8841 };
8842 var positionDef = {
8843 field: "position",
8844 bindingEvent: "position",
8845 allowBinding: true,
8846 allowSetting: true,
8847 settingEvent: "position",
8848 settingTriggersEvent: true,
8849 triggerFnName: "emitAndNotify",
8850 allowGetting: true,
8851 validKeys: ["x", "y"],
8852 beforeGet: function beforeGet(ele) {
8853 ele.updateCompoundBounds();
8854 },
8855 beforeSet: function beforeSet(eles, newPos) {
8856 beforePositionSet(eles, newPos, false);
8857 },
8858 onSet: function onSet(eles) {
8859 eles.dirtyCompoundBoundsCache();
8860 },
8861 canSet: function canSet(ele) {
8862 return !ele.locked();
8863 }
8864 };
8865 fn$4 = elesfn$c = {
8866 position: define.data(positionDef),
8867 // position but no notification to renderer
8868 silentPosition: define.data(extend({}, positionDef, {
8869 allowBinding: false,
8870 allowSetting: true,
8871 settingTriggersEvent: false,
8872 allowGetting: false,
8873 beforeSet: function beforeSet(eles, newPos) {
8874 beforePositionSet(eles, newPos, true);
8875 },
8876 onSet: function onSet(eles) {
8877 eles.dirtyCompoundBoundsCache();
8878 }
8879 })),
8880 positions: function positions(pos, silent) {
8881 if (plainObject(pos)) {
8882 if (silent) {
8883 this.silentPosition(pos);
8884 } else {
8885 this.position(pos);
8886 }
8887 } else if (fn$6(pos)) {
8888 var _fn = pos;
8889 var cy = this.cy();
8890 cy.startBatch();
8891 for (var i2 = 0; i2 < this.length; i2++) {
8892 var ele = this[i2];
8893 var _pos = void 0;
8894 if (_pos = _fn(ele, i2)) {
8895 if (silent) {
8896 ele.silentPosition(_pos);
8897 } else {
8898 ele.position(_pos);
8899 }
8900 }
8901 }
8902 cy.endBatch();
8903 }
8904 return this;
8905 },
8906 silentPositions: function silentPositions(pos) {
8907 return this.positions(pos, true);
8908 },
8909 shift: function shift(dim, val, silent) {
8910 var delta;
8911 if (plainObject(dim)) {
8912 delta = {
8913 x: number$1(dim.x) ? dim.x : 0,
8914 y: number$1(dim.y) ? dim.y : 0
8915 };
8916 silent = val;
8917 } else if (string(dim) && number$1(val)) {
8918 delta = {
8919 x: 0,
8920 y: 0
8921 };
8922 delta[dim] = val;
8923 }
8924 if (delta != null) {
8925 var cy = this.cy();
8926 cy.startBatch();
8927 for (var i2 = 0; i2 < this.length; i2++) {
8928 var ele = this[i2];
8929 if (cy.hasCompoundNodes() && ele.isChild() && ele.ancestors().anySame(this)) {
8930 continue;
8931 }
8932 var pos = ele.position();
8933 var newPos = {
8934 x: pos.x + delta.x,
8935 y: pos.y + delta.y
8936 };
8937 if (silent) {
8938 ele.silentPosition(newPos);
8939 } else {
8940 ele.position(newPos);
8941 }
8942 }
8943 cy.endBatch();
8944 }
8945 return this;
8946 },
8947 silentShift: function silentShift(dim, val) {
8948 if (plainObject(dim)) {
8949 this.shift(dim, true);
8950 } else if (string(dim) && number$1(val)) {
8951 this.shift(dim, val, true);
8952 }
8953 return this;
8954 },
8955 // get/set the rendered (i.e. on screen) positon of the element
8956 renderedPosition: function renderedPosition(dim, val) {
8957 var ele = this[0];
8958 var cy = this.cy();
8959 var zoom = cy.zoom();
8960 var pan = cy.pan();
8961 var rpos = plainObject(dim) ? dim : void 0;
8962 var setting = rpos !== void 0 || val !== void 0 && string(dim);
8963 if (ele && ele.isNode()) {
8964 if (setting) {
8965 for (var i2 = 0; i2 < this.length; i2++) {
8966 var _ele = this[i2];
8967 if (val !== void 0) {
8968 _ele.position(dim, (val - pan[dim]) / zoom);
8969 } else if (rpos !== void 0) {
8970 _ele.position(renderedToModelPosition(rpos, zoom, pan));
8971 }
8972 }
8973 } else {
8974 var pos = ele.position();
8975 rpos = modelToRenderedPosition(pos, zoom, pan);
8976 if (dim === void 0) {
8977 return rpos;
8978 } else {
8979 return rpos[dim];
8980 }
8981 }
8982 } else if (!setting) {
8983 return void 0;
8984 }
8985 return this;
8986 },
8987 // get/set the position relative to the parent
8988 relativePosition: function relativePosition(dim, val) {
8989 var ele = this[0];
8990 var cy = this.cy();
8991 var ppos = plainObject(dim) ? dim : void 0;
8992 var setting = ppos !== void 0 || val !== void 0 && string(dim);
8993 var hasCompoundNodes = cy.hasCompoundNodes();
8994 if (ele && ele.isNode()) {
8995 if (setting) {
8996 for (var i2 = 0; i2 < this.length; i2++) {
8997 var _ele2 = this[i2];
8998 var parent = hasCompoundNodes ? _ele2.parent() : null;
8999 var hasParent = parent && parent.length > 0;
9000 var relativeToParent = hasParent;
9001 if (hasParent) {
9002 parent = parent[0];
9003 }
9004 var origin = relativeToParent ? parent.position() : {
9005 x: 0,
9006 y: 0
9007 };
9008 if (val !== void 0) {
9009 _ele2.position(dim, val + origin[dim]);
9010 } else if (ppos !== void 0) {
9011 _ele2.position({
9012 x: ppos.x + origin.x,
9013 y: ppos.y + origin.y
9014 });
9015 }
9016 }
9017 } else {
9018 var pos = ele.position();
9019 var _parent = hasCompoundNodes ? ele.parent() : null;
9020 var _hasParent = _parent && _parent.length > 0;
9021 var _relativeToParent = _hasParent;
9022 if (_hasParent) {
9023 _parent = _parent[0];
9024 }
9025 var _origin = _relativeToParent ? _parent.position() : {
9026 x: 0,
9027 y: 0
9028 };
9029 ppos = {
9030 x: pos.x - _origin.x,
9031 y: pos.y - _origin.y
9032 };
9033 if (dim === void 0) {
9034 return ppos;
9035 } else {
9036 return ppos[dim];
9037 }
9038 }
9039 } else if (!setting) {
9040 return void 0;
9041 }
9042 return this;
9043 }
9044 };
9045 fn$4.modelPosition = fn$4.point = fn$4.position;
9046 fn$4.modelPositions = fn$4.points = fn$4.positions;
9047 fn$4.renderedPoint = fn$4.renderedPosition;
9048 fn$4.relativePoint = fn$4.relativePosition;
9049 var position = elesfn$c;
9050 var fn$3, elesfn$b;
9051 fn$3 = elesfn$b = {};
9052 elesfn$b.renderedBoundingBox = function(options) {
9053 var bb = this.boundingBox(options);
9054 var cy = this.cy();
9055 var zoom = cy.zoom();
9056 var pan = cy.pan();
9057 var x1 = bb.x1 * zoom + pan.x;
9058 var x2 = bb.x2 * zoom + pan.x;
9059 var y1 = bb.y1 * zoom + pan.y;
9060 var y2 = bb.y2 * zoom + pan.y;
9061 return {
9062 x1,
9063 x2,
9064 y1,
9065 y2,
9066 w: x2 - x1,
9067 h: y2 - y1
9068 };
9069 };
9070 elesfn$b.dirtyCompoundBoundsCache = function() {
9071 var silent = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
9072 var cy = this.cy();
9073 if (!cy.styleEnabled() || !cy.hasCompoundNodes()) {
9074 return this;
9075 }
9076 this.forEachUp(function(ele) {
9077 if (ele.isParent()) {
9078 var _p = ele._private;
9079 _p.compoundBoundsClean = false;
9080 _p.bbCache = null;
9081 if (!silent) {
9082 ele.emitAndNotify("bounds");
9083 }
9084 }
9085 });
9086 return this;
9087 };
9088 elesfn$b.updateCompoundBounds = function() {
9089 var force = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
9090 var cy = this.cy();
9091 if (!cy.styleEnabled() || !cy.hasCompoundNodes()) {
9092 return this;
9093 }
9094 if (!force && cy.batching()) {
9095 return this;
9096 }
9097 function update2(parent) {
9098 if (!parent.isParent()) {
9099 return;
9100 }
9101 var _p2 = parent._private;
9102 var children = parent.children();
9103 var includeLabels = parent.pstyle("compound-sizing-wrt-labels").value === "include";
9104 var min2 = {
9105 width: {
9106 val: parent.pstyle("min-width").pfValue,
9107 left: parent.pstyle("min-width-bias-left"),
9108 right: parent.pstyle("min-width-bias-right")
9109 },
9110 height: {
9111 val: parent.pstyle("min-height").pfValue,
9112 top: parent.pstyle("min-height-bias-top"),
9113 bottom: parent.pstyle("min-height-bias-bottom")
9114 }
9115 };
9116 var bb = children.boundingBox({
9117 includeLabels,
9118 includeOverlays: false,
9119 // updating the compound bounds happens outside of the regular
9120 // cache cycle (i.e. before fired events)
9121 useCache: false
9122 });
9123 var pos = _p2.position;
9124 if (bb.w === 0 || bb.h === 0) {
9125 bb = {
9126 w: parent.pstyle("width").pfValue,
9127 h: parent.pstyle("height").pfValue
9128 };
9129 bb.x1 = pos.x - bb.w / 2;
9130 bb.x2 = pos.x + bb.w / 2;
9131 bb.y1 = pos.y - bb.h / 2;
9132 bb.y2 = pos.y + bb.h / 2;
9133 }
9134 function computeBiasValues(propDiff, propBias, propBiasComplement) {
9135 var biasDiff = 0;
9136 var biasComplementDiff = 0;
9137 var biasTotal = propBias + propBiasComplement;
9138 if (propDiff > 0 && biasTotal > 0) {
9139 biasDiff = propBias / biasTotal * propDiff;
9140 biasComplementDiff = propBiasComplement / biasTotal * propDiff;
9141 }
9142 return {
9143 biasDiff,
9144 biasComplementDiff
9145 };
9146 }
9147 function computePaddingValues(width, height, paddingObject, relativeTo) {
9148 if (paddingObject.units === "%") {
9149 switch (relativeTo) {
9150 case "width":
9151 return width > 0 ? paddingObject.pfValue * width : 0;
9152 case "height":
9153 return height > 0 ? paddingObject.pfValue * height : 0;
9154 case "average":
9155 return width > 0 && height > 0 ? paddingObject.pfValue * (width + height) / 2 : 0;
9156 case "min":
9157 return width > 0 && height > 0 ? width > height ? paddingObject.pfValue * height : paddingObject.pfValue * width : 0;
9158 case "max":
9159 return width > 0 && height > 0 ? width > height ? paddingObject.pfValue * width : paddingObject.pfValue * height : 0;
9160 default:
9161 return 0;
9162 }
9163 } else if (paddingObject.units === "px") {
9164 return paddingObject.pfValue;
9165 } else {
9166 return 0;
9167 }
9168 }
9169 var leftVal = min2.width.left.value;
9170 if (min2.width.left.units === "px" && min2.width.val > 0) {
9171 leftVal = leftVal * 100 / min2.width.val;
9172 }
9173 var rightVal = min2.width.right.value;
9174 if (min2.width.right.units === "px" && min2.width.val > 0) {
9175 rightVal = rightVal * 100 / min2.width.val;
9176 }
9177 var topVal = min2.height.top.value;
9178 if (min2.height.top.units === "px" && min2.height.val > 0) {
9179 topVal = topVal * 100 / min2.height.val;
9180 }
9181 var bottomVal = min2.height.bottom.value;
9182 if (min2.height.bottom.units === "px" && min2.height.val > 0) {
9183 bottomVal = bottomVal * 100 / min2.height.val;
9184 }
9185 var widthBiasDiffs = computeBiasValues(min2.width.val - bb.w, leftVal, rightVal);
9186 var diffLeft = widthBiasDiffs.biasDiff;
9187 var diffRight = widthBiasDiffs.biasComplementDiff;
9188 var heightBiasDiffs = computeBiasValues(min2.height.val - bb.h, topVal, bottomVal);
9189 var diffTop = heightBiasDiffs.biasDiff;
9190 var diffBottom = heightBiasDiffs.biasComplementDiff;
9191 _p2.autoPadding = computePaddingValues(bb.w, bb.h, parent.pstyle("padding"), parent.pstyle("padding-relative-to").value);
9192 _p2.autoWidth = Math.max(bb.w, min2.width.val);
9193 pos.x = (-diffLeft + bb.x1 + bb.x2 + diffRight) / 2;
9194 _p2.autoHeight = Math.max(bb.h, min2.height.val);
9195 pos.y = (-diffTop + bb.y1 + bb.y2 + diffBottom) / 2;
9196 }
9197 for (var i2 = 0; i2 < this.length; i2++) {
9198 var ele = this[i2];
9199 var _p = ele._private;
9200 if (!_p.compoundBoundsClean || force) {
9201 update2(ele);
9202 if (!cy.batching()) {
9203 _p.compoundBoundsClean = true;
9204 }
9205 }
9206 }
9207 return this;
9208 };
9209 var noninf = function noninf2(x) {
9210 if (x === Infinity || x === -Infinity) {
9211 return 0;
9212 }
9213 return x;
9214 };
9215 var updateBounds = function updateBounds2(b, x1, y1, x2, y2) {
9216 if (x2 - x1 === 0 || y2 - y1 === 0) {
9217 return;
9218 }
9219 if (x1 == null || y1 == null || x2 == null || y2 == null) {
9220 return;
9221 }
9222 b.x1 = x1 < b.x1 ? x1 : b.x1;
9223 b.x2 = x2 > b.x2 ? x2 : b.x2;
9224 b.y1 = y1 < b.y1 ? y1 : b.y1;
9225 b.y2 = y2 > b.y2 ? y2 : b.y2;
9226 b.w = b.x2 - b.x1;
9227 b.h = b.y2 - b.y1;
9228 };
9229 var updateBoundsFromBox = function updateBoundsFromBox2(b, b2) {
9230 if (b2 == null) {
9231 return b;
9232 }
9233 return updateBounds(b, b2.x1, b2.y1, b2.x2, b2.y2);
9234 };
9235 var prefixedProperty = function prefixedProperty2(obj, field, prefix) {
9236 return getPrefixedProperty(obj, field, prefix);
9237 };
9238 var updateBoundsFromArrow = function updateBoundsFromArrow2(bounds2, ele, prefix) {
9239 if (ele.cy().headless()) {
9240 return;
9241 }
9242 var _p = ele._private;
9243 var rstyle = _p.rstyle;
9244 var halfArW = rstyle.arrowWidth / 2;
9245 var arrowType = ele.pstyle(prefix + "-arrow-shape").value;
9246 var x;
9247 var y;
9248 if (arrowType !== "none") {
9249 if (prefix === "source") {
9250 x = rstyle.srcX;
9251 y = rstyle.srcY;
9252 } else if (prefix === "target") {
9253 x = rstyle.tgtX;
9254 y = rstyle.tgtY;
9255 } else {
9256 x = rstyle.midX;
9257 y = rstyle.midY;
9258 }
9259 var bbs = _p.arrowBounds = _p.arrowBounds || {};
9260 var bb = bbs[prefix] = bbs[prefix] || {};
9261 bb.x1 = x - halfArW;
9262 bb.y1 = y - halfArW;
9263 bb.x2 = x + halfArW;
9264 bb.y2 = y + halfArW;
9265 bb.w = bb.x2 - bb.x1;
9266 bb.h = bb.y2 - bb.y1;
9267 expandBoundingBox(bb, 1);
9268 updateBounds(bounds2, bb.x1, bb.y1, bb.x2, bb.y2);
9269 }
9270 };
9271 var updateBoundsFromLabel = function updateBoundsFromLabel2(bounds2, ele, prefix) {
9272 if (ele.cy().headless()) {
9273 return;
9274 }
9275 var prefixDash;
9276 if (prefix) {
9277 prefixDash = prefix + "-";
9278 } else {
9279 prefixDash = "";
9280 }
9281 var _p = ele._private;
9282 var rstyle = _p.rstyle;
9283 var label = ele.pstyle(prefixDash + "label").strValue;
9284 if (label) {
9285 var halign = ele.pstyle("text-halign");
9286 var valign = ele.pstyle("text-valign");
9287 var labelWidth = prefixedProperty(rstyle, "labelWidth", prefix);
9288 var labelHeight = prefixedProperty(rstyle, "labelHeight", prefix);
9289 var labelX = prefixedProperty(rstyle, "labelX", prefix);
9290 var labelY = prefixedProperty(rstyle, "labelY", prefix);
9291 var marginX = ele.pstyle(prefixDash + "text-margin-x").pfValue;
9292 var marginY = ele.pstyle(prefixDash + "text-margin-y").pfValue;
9293 var isEdge = ele.isEdge();
9294 var rotation = ele.pstyle(prefixDash + "text-rotation");
9295 var outlineWidth = ele.pstyle("text-outline-width").pfValue;
9296 var borderWidth = ele.pstyle("text-border-width").pfValue;
9297 var halfBorderWidth = borderWidth / 2;
9298 var padding = ele.pstyle("text-background-padding").pfValue;
9299 var marginOfError = 2;
9300 var lh = labelHeight;
9301 var lw = labelWidth;
9302 var lw_2 = lw / 2;
9303 var lh_2 = lh / 2;
9304 var lx1, lx2, ly1, ly2;
9305 if (isEdge) {
9306 lx1 = labelX - lw_2;
9307 lx2 = labelX + lw_2;
9308 ly1 = labelY - lh_2;
9309 ly2 = labelY + lh_2;
9310 } else {
9311 switch (halign.value) {
9312 case "left":
9313 lx1 = labelX - lw;
9314 lx2 = labelX;
9315 break;
9316 case "center":
9317 lx1 = labelX - lw_2;
9318 lx2 = labelX + lw_2;
9319 break;
9320 case "right":
9321 lx1 = labelX;
9322 lx2 = labelX + lw;
9323 break;
9324 }
9325 switch (valign.value) {
9326 case "top":
9327 ly1 = labelY - lh;
9328 ly2 = labelY;
9329 break;
9330 case "center":
9331 ly1 = labelY - lh_2;
9332 ly2 = labelY + lh_2;
9333 break;
9334 case "bottom":
9335 ly1 = labelY;
9336 ly2 = labelY + lh;
9337 break;
9338 }
9339 }
9340 lx1 += marginX - Math.max(outlineWidth, halfBorderWidth) - padding - marginOfError;
9341 lx2 += marginX + Math.max(outlineWidth, halfBorderWidth) + padding + marginOfError;
9342 ly1 += marginY - Math.max(outlineWidth, halfBorderWidth) - padding - marginOfError;
9343 ly2 += marginY + Math.max(outlineWidth, halfBorderWidth) + padding + marginOfError;
9344 var bbPrefix = prefix || "main";
9345 var bbs = _p.labelBounds;
9346 var bb = bbs[bbPrefix] = bbs[bbPrefix] || {};
9347 bb.x1 = lx1;
9348 bb.y1 = ly1;
9349 bb.x2 = lx2;
9350 bb.y2 = ly2;
9351 bb.w = lx2 - lx1;
9352 bb.h = ly2 - ly1;
9353 var isAutorotate = isEdge && rotation.strValue === "autorotate";
9354 var isPfValue = rotation.pfValue != null && rotation.pfValue !== 0;
9355 if (isAutorotate || isPfValue) {
9356 var theta = isAutorotate ? prefixedProperty(_p.rstyle, "labelAngle", prefix) : rotation.pfValue;
9357 var cos2 = Math.cos(theta);
9358 var sin2 = Math.sin(theta);
9359 var xo = (lx1 + lx2) / 2;
9360 var yo = (ly1 + ly2) / 2;
9361 if (!isEdge) {
9362 switch (halign.value) {
9363 case "left":
9364 xo = lx2;
9365 break;
9366 case "right":
9367 xo = lx1;
9368 break;
9369 }
9370 switch (valign.value) {
9371 case "top":
9372 yo = ly2;
9373 break;
9374 case "bottom":
9375 yo = ly1;
9376 break;
9377 }
9378 }
9379 var rotate = function rotate2(x, y) {
9380 x = x - xo;
9381 y = y - yo;
9382 return {
9383 x: x * cos2 - y * sin2 + xo,
9384 y: x * sin2 + y * cos2 + yo
9385 };
9386 };
9387 var px1y1 = rotate(lx1, ly1);
9388 var px1y2 = rotate(lx1, ly2);
9389 var px2y1 = rotate(lx2, ly1);
9390 var px2y2 = rotate(lx2, ly2);
9391 lx1 = Math.min(px1y1.x, px1y2.x, px2y1.x, px2y2.x);
9392 lx2 = Math.max(px1y1.x, px1y2.x, px2y1.x, px2y2.x);
9393 ly1 = Math.min(px1y1.y, px1y2.y, px2y1.y, px2y2.y);
9394 ly2 = Math.max(px1y1.y, px1y2.y, px2y1.y, px2y2.y);
9395 }
9396 var bbPrefixRot = bbPrefix + "Rot";
9397 var bbRot = bbs[bbPrefixRot] = bbs[bbPrefixRot] || {};
9398 bbRot.x1 = lx1;
9399 bbRot.y1 = ly1;
9400 bbRot.x2 = lx2;
9401 bbRot.y2 = ly2;
9402 bbRot.w = lx2 - lx1;
9403 bbRot.h = ly2 - ly1;
9404 updateBounds(bounds2, lx1, ly1, lx2, ly2);
9405 updateBounds(_p.labelBounds.all, lx1, ly1, lx2, ly2);
9406 }
9407 return bounds2;
9408 };
9409 var boundingBoxImpl = function boundingBoxImpl2(ele, options) {
9410 var cy = ele._private.cy;
9411 var styleEnabled = cy.styleEnabled();
9412 var headless = cy.headless();
9413 var bounds2 = makeBoundingBox();
9414 var _p = ele._private;
9415 var isNode = ele.isNode();
9416 var isEdge = ele.isEdge();
9417 var ex1, ex2, ey1, ey2;
9418 var x, y;
9419 var rstyle = _p.rstyle;
9420 var manualExpansion = isNode && styleEnabled ? ele.pstyle("bounds-expansion").pfValue : [0];
9421 var isDisplayed = function isDisplayed2(ele2) {
9422 return ele2.pstyle("display").value !== "none";
9423 };
9424 var displayed = !styleEnabled || isDisplayed(ele) && (!isEdge || isDisplayed(ele.source()) && isDisplayed(ele.target()));
9425 if (displayed) {
9426 var overlayOpacity = 0;
9427 var overlayPadding = 0;
9428 if (styleEnabled && options.includeOverlays) {
9429 overlayOpacity = ele.pstyle("overlay-opacity").value;
9430 if (overlayOpacity !== 0) {
9431 overlayPadding = ele.pstyle("overlay-padding").value;
9432 }
9433 }
9434 var underlayOpacity = 0;
9435 var underlayPadding = 0;
9436 if (styleEnabled && options.includeUnderlays) {
9437 underlayOpacity = ele.pstyle("underlay-opacity").value;
9438 if (underlayOpacity !== 0) {
9439 underlayPadding = ele.pstyle("underlay-padding").value;
9440 }
9441 }
9442 var padding = Math.max(overlayPadding, underlayPadding);
9443 var w = 0;
9444 var wHalf = 0;
9445 if (styleEnabled) {
9446 w = ele.pstyle("width").pfValue;
9447 wHalf = w / 2;
9448 }
9449 if (isNode && options.includeNodes) {
9450 var pos = ele.position();
9451 x = pos.x;
9452 y = pos.y;
9453 var _w = ele.outerWidth();
9454 var halfW = _w / 2;
9455 var h = ele.outerHeight();
9456 var halfH = h / 2;
9457 ex1 = x - halfW;
9458 ex2 = x + halfW;
9459 ey1 = y - halfH;
9460 ey2 = y + halfH;
9461 updateBounds(bounds2, ex1, ey1, ex2, ey2);
9462 } else if (isEdge && options.includeEdges) {
9463 if (styleEnabled && !headless) {
9464 var curveStyle = ele.pstyle("curve-style").strValue;
9465 ex1 = Math.min(rstyle.srcX, rstyle.midX, rstyle.tgtX);
9466 ex2 = Math.max(rstyle.srcX, rstyle.midX, rstyle.tgtX);
9467 ey1 = Math.min(rstyle.srcY, rstyle.midY, rstyle.tgtY);
9468 ey2 = Math.max(rstyle.srcY, rstyle.midY, rstyle.tgtY);
9469 ex1 -= wHalf;
9470 ex2 += wHalf;
9471 ey1 -= wHalf;
9472 ey2 += wHalf;
9473 updateBounds(bounds2, ex1, ey1, ex2, ey2);
9474 if (curveStyle === "haystack") {
9475 var hpts = rstyle.haystackPts;
9476 if (hpts && hpts.length === 2) {
9477 ex1 = hpts[0].x;
9478 ey1 = hpts[0].y;
9479 ex2 = hpts[1].x;
9480 ey2 = hpts[1].y;
9481 if (ex1 > ex2) {
9482 var temp = ex1;
9483 ex1 = ex2;
9484 ex2 = temp;
9485 }
9486 if (ey1 > ey2) {
9487 var _temp = ey1;
9488 ey1 = ey2;
9489 ey2 = _temp;
9490 }
9491 updateBounds(bounds2, ex1 - wHalf, ey1 - wHalf, ex2 + wHalf, ey2 + wHalf);
9492 }
9493 } else if (curveStyle === "bezier" || curveStyle === "unbundled-bezier" || curveStyle === "segments" || curveStyle === "taxi") {
9494 var pts2;
9495 switch (curveStyle) {
9496 case "bezier":
9497 case "unbundled-bezier":
9498 pts2 = rstyle.bezierPts;
9499 break;
9500 case "segments":
9501 case "taxi":
9502 pts2 = rstyle.linePts;
9503 break;
9504 }
9505 if (pts2 != null) {
9506 for (var j = 0; j < pts2.length; j++) {
9507 var pt = pts2[j];
9508 ex1 = pt.x - wHalf;
9509 ex2 = pt.x + wHalf;
9510 ey1 = pt.y - wHalf;
9511 ey2 = pt.y + wHalf;
9512 updateBounds(bounds2, ex1, ey1, ex2, ey2);
9513 }
9514 }
9515 }
9516 } else {
9517 var n1 = ele.source();
9518 var n1pos = n1.position();
9519 var n2 = ele.target();
9520 var n2pos = n2.position();
9521 ex1 = n1pos.x;
9522 ex2 = n2pos.x;
9523 ey1 = n1pos.y;
9524 ey2 = n2pos.y;
9525 if (ex1 > ex2) {
9526 var _temp2 = ex1;
9527 ex1 = ex2;
9528 ex2 = _temp2;
9529 }
9530 if (ey1 > ey2) {
9531 var _temp3 = ey1;
9532 ey1 = ey2;
9533 ey2 = _temp3;
9534 }
9535 ex1 -= wHalf;
9536 ex2 += wHalf;
9537 ey1 -= wHalf;
9538 ey2 += wHalf;
9539 updateBounds(bounds2, ex1, ey1, ex2, ey2);
9540 }
9541 }
9542 if (styleEnabled && options.includeEdges && isEdge) {
9543 updateBoundsFromArrow(bounds2, ele, "mid-source");
9544 updateBoundsFromArrow(bounds2, ele, "mid-target");
9545 updateBoundsFromArrow(bounds2, ele, "source");
9546 updateBoundsFromArrow(bounds2, ele, "target");
9547 }
9548 if (styleEnabled) {
9549 var ghost = ele.pstyle("ghost").value === "yes";
9550 if (ghost) {
9551 var gx = ele.pstyle("ghost-offset-x").pfValue;
9552 var gy = ele.pstyle("ghost-offset-y").pfValue;
9553 updateBounds(bounds2, bounds2.x1 + gx, bounds2.y1 + gy, bounds2.x2 + gx, bounds2.y2 + gy);
9554 }
9555 }
9556 var bbBody = _p.bodyBounds = _p.bodyBounds || {};
9557 assignBoundingBox(bbBody, bounds2);
9558 expandBoundingBoxSides(bbBody, manualExpansion);
9559 expandBoundingBox(bbBody, 1);
9560 if (styleEnabled) {
9561 ex1 = bounds2.x1;
9562 ex2 = bounds2.x2;
9563 ey1 = bounds2.y1;
9564 ey2 = bounds2.y2;
9565 updateBounds(bounds2, ex1 - padding, ey1 - padding, ex2 + padding, ey2 + padding);
9566 }
9567 var bbOverlay = _p.overlayBounds = _p.overlayBounds || {};
9568 assignBoundingBox(bbOverlay, bounds2);
9569 expandBoundingBoxSides(bbOverlay, manualExpansion);
9570 expandBoundingBox(bbOverlay, 1);
9571 var bbLabels = _p.labelBounds = _p.labelBounds || {};
9572 if (bbLabels.all != null) {
9573 clearBoundingBox(bbLabels.all);
9574 } else {
9575 bbLabels.all = makeBoundingBox();
9576 }
9577 if (styleEnabled && options.includeLabels) {
9578 if (options.includeMainLabels) {
9579 updateBoundsFromLabel(bounds2, ele, null);
9580 }
9581 if (isEdge) {
9582 if (options.includeSourceLabels) {
9583 updateBoundsFromLabel(bounds2, ele, "source");
9584 }
9585 if (options.includeTargetLabels) {
9586 updateBoundsFromLabel(bounds2, ele, "target");
9587 }
9588 }
9589 }
9590 }
9591 bounds2.x1 = noninf(bounds2.x1);
9592 bounds2.y1 = noninf(bounds2.y1);
9593 bounds2.x2 = noninf(bounds2.x2);
9594 bounds2.y2 = noninf(bounds2.y2);
9595 bounds2.w = noninf(bounds2.x2 - bounds2.x1);
9596 bounds2.h = noninf(bounds2.y2 - bounds2.y1);
9597 if (bounds2.w > 0 && bounds2.h > 0 && displayed) {
9598 expandBoundingBoxSides(bounds2, manualExpansion);
9599 expandBoundingBox(bounds2, 1);
9600 }
9601 return bounds2;
9602 };
9603 var getKey = function getKey2(opts) {
9604 var i2 = 0;
9605 var tf = function tf2(val) {
9606 return (val ? 1 : 0) << i2++;
9607 };
9608 var key = 0;
9609 key += tf(opts.incudeNodes);
9610 key += tf(opts.includeEdges);
9611 key += tf(opts.includeLabels);
9612 key += tf(opts.includeMainLabels);
9613 key += tf(opts.includeSourceLabels);
9614 key += tf(opts.includeTargetLabels);
9615 key += tf(opts.includeOverlays);
9616 return key;
9617 };
9618 var getBoundingBoxPosKey = function getBoundingBoxPosKey2(ele) {
9619 if (ele.isEdge()) {
9620 var p1 = ele.source().position();
9621 var p2 = ele.target().position();
9622 var r = function r2(x) {
9623 return Math.round(x);
9624 };
9625 return hashIntsArray([r(p1.x), r(p1.y), r(p2.x), r(p2.y)]);
9626 } else {
9627 return 0;
9628 }
9629 };
9630 var cachedBoundingBoxImpl = function cachedBoundingBoxImpl2(ele, opts) {
9631 var _p = ele._private;
9632 var bb;
9633 var isEdge = ele.isEdge();
9634 var key = opts == null ? defBbOptsKey : getKey(opts);
9635 var usingDefOpts = key === defBbOptsKey;
9636 var currPosKey = getBoundingBoxPosKey(ele);
9637 var isPosKeySame = _p.bbCachePosKey === currPosKey;
9638 var useCache = opts.useCache && isPosKeySame;
9639 var isDirty = function isDirty2(ele2) {
9640 return ele2._private.bbCache == null || ele2._private.styleDirty;
9641 };
9642 var needRecalc = !useCache || isDirty(ele) || isEdge && isDirty(ele.source()) || isDirty(ele.target());
9643 if (needRecalc) {
9644 if (!isPosKeySame) {
9645 ele.recalculateRenderedStyle(useCache);
9646 }
9647 bb = boundingBoxImpl(ele, defBbOpts);
9648 _p.bbCache = bb;
9649 _p.bbCachePosKey = currPosKey;
9650 } else {
9651 bb = _p.bbCache;
9652 }
9653 if (!usingDefOpts) {
9654 var isNode = ele.isNode();
9655 bb = makeBoundingBox();
9656 if (opts.includeNodes && isNode || opts.includeEdges && !isNode) {
9657 if (opts.includeOverlays) {
9658 updateBoundsFromBox(bb, _p.overlayBounds);
9659 } else {
9660 updateBoundsFromBox(bb, _p.bodyBounds);
9661 }
9662 }
9663 if (opts.includeLabels) {
9664 if (opts.includeMainLabels && (!isEdge || opts.includeSourceLabels && opts.includeTargetLabels)) {
9665 updateBoundsFromBox(bb, _p.labelBounds.all);
9666 } else {
9667 if (opts.includeMainLabels) {
9668 updateBoundsFromBox(bb, _p.labelBounds.mainRot);
9669 }
9670 if (opts.includeSourceLabels) {
9671 updateBoundsFromBox(bb, _p.labelBounds.sourceRot);
9672 }
9673 if (opts.includeTargetLabels) {
9674 updateBoundsFromBox(bb, _p.labelBounds.targetRot);
9675 }
9676 }
9677 }
9678 bb.w = bb.x2 - bb.x1;
9679 bb.h = bb.y2 - bb.y1;
9680 }
9681 return bb;
9682 };
9683 var defBbOpts = {
9684 includeNodes: true,
9685 includeEdges: true,
9686 includeLabels: true,
9687 includeMainLabels: true,
9688 includeSourceLabels: true,
9689 includeTargetLabels: true,
9690 includeOverlays: true,
9691 includeUnderlays: true,
9692 useCache: true
9693 };
9694 var defBbOptsKey = getKey(defBbOpts);
9695 var filledBbOpts = defaults$g(defBbOpts);
9696 elesfn$b.boundingBox = function(options) {
9697 var bounds2;
9698 if (this.length === 1 && this[0]._private.bbCache != null && !this[0]._private.styleDirty && (options === void 0 || options.useCache === void 0 || options.useCache === true)) {
9699 if (options === void 0) {
9700 options = defBbOpts;
9701 } else {
9702 options = filledBbOpts(options);
9703 }
9704 bounds2 = cachedBoundingBoxImpl(this[0], options);
9705 } else {
9706 bounds2 = makeBoundingBox();
9707 options = options || defBbOpts;
9708 var opts = filledBbOpts(options);
9709 var eles = this;
9710 var cy = eles.cy();
9711 var styleEnabled = cy.styleEnabled();
9712 if (styleEnabled) {
9713 for (var i2 = 0; i2 < eles.length; i2++) {
9714 var ele = eles[i2];
9715 var _p = ele._private;
9716 var currPosKey = getBoundingBoxPosKey(ele);
9717 var isPosKeySame = _p.bbCachePosKey === currPosKey;
9718 var useCache = opts.useCache && isPosKeySame && !_p.styleDirty;
9719 ele.recalculateRenderedStyle(useCache);
9720 }
9721 }
9722 this.updateCompoundBounds(!options.useCache);
9723 for (var _i = 0; _i < eles.length; _i++) {
9724 var _ele = eles[_i];
9725 updateBoundsFromBox(bounds2, cachedBoundingBoxImpl(_ele, opts));
9726 }
9727 }
9728 bounds2.x1 = noninf(bounds2.x1);
9729 bounds2.y1 = noninf(bounds2.y1);
9730 bounds2.x2 = noninf(bounds2.x2);
9731 bounds2.y2 = noninf(bounds2.y2);
9732 bounds2.w = noninf(bounds2.x2 - bounds2.x1);
9733 bounds2.h = noninf(bounds2.y2 - bounds2.y1);
9734 return bounds2;
9735 };
9736 elesfn$b.dirtyBoundingBoxCache = function() {
9737 for (var i2 = 0; i2 < this.length; i2++) {
9738 var _p = this[i2]._private;
9739 _p.bbCache = null;
9740 _p.bbCachePosKey = null;
9741 _p.bodyBounds = null;
9742 _p.overlayBounds = null;
9743 _p.labelBounds.all = null;
9744 _p.labelBounds.source = null;
9745 _p.labelBounds.target = null;
9746 _p.labelBounds.main = null;
9747 _p.labelBounds.sourceRot = null;
9748 _p.labelBounds.targetRot = null;
9749 _p.labelBounds.mainRot = null;
9750 _p.arrowBounds.source = null;
9751 _p.arrowBounds.target = null;
9752 _p.arrowBounds["mid-source"] = null;
9753 _p.arrowBounds["mid-target"] = null;
9754 }
9755 this.emitAndNotify("bounds");
9756 return this;
9757 };
9758 elesfn$b.boundingBoxAt = function(fn2) {
9759 var nodes2 = this.nodes();
9760 var cy = this.cy();
9761 var hasCompoundNodes = cy.hasCompoundNodes();
9762 var parents = cy.collection();
9763 if (hasCompoundNodes) {
9764 parents = nodes2.filter(function(node) {
9765 return node.isParent();
9766 });
9767 nodes2 = nodes2.not(parents);
9768 }
9769 if (plainObject(fn2)) {
9770 var obj = fn2;
9771 fn2 = function fn3() {
9772 return obj;
9773 };
9774 }
9775 var storeOldPos = function storeOldPos2(node, i2) {
9776 return node._private.bbAtOldPos = fn2(node, i2);
9777 };
9778 var getOldPos = function getOldPos2(node) {
9779 return node._private.bbAtOldPos;
9780 };
9781 cy.startBatch();
9782 nodes2.forEach(storeOldPos).silentPositions(fn2);
9783 if (hasCompoundNodes) {
9784 parents.dirtyCompoundBoundsCache();
9785 parents.dirtyBoundingBoxCache();
9786 parents.updateCompoundBounds(true);
9787 }
9788 var bb = copyBoundingBox(this.boundingBox({
9789 useCache: false
9790 }));
9791 nodes2.silentPositions(getOldPos);
9792 if (hasCompoundNodes) {
9793 parents.dirtyCompoundBoundsCache();
9794 parents.dirtyBoundingBoxCache();
9795 parents.updateCompoundBounds(true);
9796 }
9797 cy.endBatch();
9798 return bb;
9799 };
9800 fn$3.boundingbox = fn$3.bb = fn$3.boundingBox;
9801 fn$3.renderedBoundingbox = fn$3.renderedBoundingBox;
9802 var bounds = elesfn$b;
9803 var fn$2, elesfn$a;
9804 fn$2 = elesfn$a = {};
9805 var defineDimFns = function defineDimFns2(opts) {
9806 opts.uppercaseName = capitalize(opts.name);
9807 opts.autoName = "auto" + opts.uppercaseName;
9808 opts.labelName = "label" + opts.uppercaseName;
9809 opts.outerName = "outer" + opts.uppercaseName;
9810 opts.uppercaseOuterName = capitalize(opts.outerName);
9811 fn$2[opts.name] = function dimImpl() {
9812 var ele = this[0];
9813 var _p = ele._private;
9814 var cy = _p.cy;
9815 var styleEnabled = cy._private.styleEnabled;
9816 if (ele) {
9817 if (styleEnabled) {
9818 if (ele.isParent()) {
9819 ele.updateCompoundBounds();
9820 return _p[opts.autoName] || 0;
9821 }
9822 var d = ele.pstyle(opts.name);
9823 switch (d.strValue) {
9824 case "label":
9825 ele.recalculateRenderedStyle();
9826 return _p.rstyle[opts.labelName] || 0;
9827 default:
9828 return d.pfValue;
9829 }
9830 } else {
9831 return 1;
9832 }
9833 }
9834 };
9835 fn$2["outer" + opts.uppercaseName] = function outerDimImpl() {
9836 var ele = this[0];
9837 var _p = ele._private;
9838 var cy = _p.cy;
9839 var styleEnabled = cy._private.styleEnabled;
9840 if (ele) {
9841 if (styleEnabled) {
9842 var dim = ele[opts.name]();
9843 var border = ele.pstyle("border-width").pfValue;
9844 var padding = 2 * ele.padding();
9845 return dim + border + padding;
9846 } else {
9847 return 1;
9848 }
9849 }
9850 };
9851 fn$2["rendered" + opts.uppercaseName] = function renderedDimImpl() {
9852 var ele = this[0];
9853 if (ele) {
9854 var d = ele[opts.name]();
9855 return d * this.cy().zoom();
9856 }
9857 };
9858 fn$2["rendered" + opts.uppercaseOuterName] = function renderedOuterDimImpl() {
9859 var ele = this[0];
9860 if (ele) {
9861 var od = ele[opts.outerName]();
9862 return od * this.cy().zoom();
9863 }
9864 };
9865 };
9866 defineDimFns({
9867 name: "width"
9868 });
9869 defineDimFns({
9870 name: "height"
9871 });
9872 elesfn$a.padding = function() {
9873 var ele = this[0];
9874 var _p = ele._private;
9875 if (ele.isParent()) {
9876 ele.updateCompoundBounds();
9877 if (_p.autoPadding !== void 0) {
9878 return _p.autoPadding;
9879 } else {
9880 return ele.pstyle("padding").pfValue;
9881 }
9882 } else {
9883 return ele.pstyle("padding").pfValue;
9884 }
9885 };
9886 elesfn$a.paddedHeight = function() {
9887 var ele = this[0];
9888 return ele.height() + 2 * ele.padding();
9889 };
9890 elesfn$a.paddedWidth = function() {
9891 var ele = this[0];
9892 return ele.width() + 2 * ele.padding();
9893 };
9894 var widthHeight = elesfn$a;
9895 var ifEdge = function ifEdge2(ele, getValue2) {
9896 if (ele.isEdge()) {
9897 return getValue2(ele);
9898 }
9899 };
9900 var ifEdgeRenderedPosition = function ifEdgeRenderedPosition2(ele, getPoint) {
9901 if (ele.isEdge()) {
9902 var cy = ele.cy();
9903 return modelToRenderedPosition(getPoint(ele), cy.zoom(), cy.pan());
9904 }
9905 };
9906 var ifEdgeRenderedPositions = function ifEdgeRenderedPositions2(ele, getPoints) {
9907 if (ele.isEdge()) {
9908 var cy = ele.cy();
9909 var pan = cy.pan();
9910 var zoom = cy.zoom();
9911 return getPoints(ele).map(function(p2) {
9912 return modelToRenderedPosition(p2, zoom, pan);
9913 });
9914 }
9915 };
9916 var controlPoints = function controlPoints2(ele) {
9917 return ele.renderer().getControlPoints(ele);
9918 };
9919 var segmentPoints = function segmentPoints2(ele) {
9920 return ele.renderer().getSegmentPoints(ele);
9921 };
9922 var sourceEndpoint = function sourceEndpoint2(ele) {
9923 return ele.renderer().getSourceEndpoint(ele);
9924 };
9925 var targetEndpoint = function targetEndpoint2(ele) {
9926 return ele.renderer().getTargetEndpoint(ele);
9927 };
9928 var midpoint = function midpoint2(ele) {
9929 return ele.renderer().getEdgeMidpoint(ele);
9930 };
9931 var pts = {
9932 controlPoints: {
9933 get: controlPoints,
9934 mult: true
9935 },
9936 segmentPoints: {
9937 get: segmentPoints,
9938 mult: true
9939 },
9940 sourceEndpoint: {
9941 get: sourceEndpoint
9942 },
9943 targetEndpoint: {
9944 get: targetEndpoint
9945 },
9946 midpoint: {
9947 get: midpoint
9948 }
9949 };
9950 var renderedName = function renderedName2(name2) {
9951 return "rendered" + name2[0].toUpperCase() + name2.substr(1);
9952 };
9953 var edgePoints = Object.keys(pts).reduce(function(obj, name2) {
9954 var spec = pts[name2];
9955 var rName = renderedName(name2);
9956 obj[name2] = function() {
9957 return ifEdge(this, spec.get);
9958 };
9959 if (spec.mult) {
9960 obj[rName] = function() {
9961 return ifEdgeRenderedPositions(this, spec.get);
9962 };
9963 } else {
9964 obj[rName] = function() {
9965 return ifEdgeRenderedPosition(this, spec.get);
9966 };
9967 }
9968 return obj;
9969 }, {});
9970 var dimensions = extend({}, position, bounds, widthHeight, edgePoints);
9971 /*!
9972 Event object based on jQuery events, MIT license
9973
9974 https://jquery.org/license/
9975 https://tldrlegal.com/license/mit-license
9976 https://github.com/jquery/jquery/blob/master/src/event.js
9977 */
9978 var Event = function Event2(src, props) {
9979 this.recycle(src, props);
9980 };
9981 function returnFalse() {
9982 return false;
9983 }
9984 function returnTrue() {
9985 return true;
9986 }
9987 Event.prototype = {
9988 instanceString: function instanceString() {
9989 return "event";
9990 },
9991 recycle: function recycle(src, props) {
9992 this.isImmediatePropagationStopped = this.isPropagationStopped = this.isDefaultPrevented = returnFalse;
9993 if (src != null && src.preventDefault) {
9994 this.type = src.type;
9995 this.isDefaultPrevented = src.defaultPrevented ? returnTrue : returnFalse;
9996 } else if (src != null && src.type) {
9997 props = src;
9998 } else {
9999 this.type = src;
10000 }
10001 if (props != null) {
10002 this.originalEvent = props.originalEvent;
10003 this.type = props.type != null ? props.type : this.type;
10004 this.cy = props.cy;
10005 this.target = props.target;
10006 this.position = props.position;
10007 this.renderedPosition = props.renderedPosition;
10008 this.namespace = props.namespace;
10009 this.layout = props.layout;
10010 }
10011 if (this.cy != null && this.position != null && this.renderedPosition == null) {
10012 var pos = this.position;
10013 var zoom = this.cy.zoom();
10014 var pan = this.cy.pan();
10015 this.renderedPosition = {
10016 x: pos.x * zoom + pan.x,
10017 y: pos.y * zoom + pan.y
10018 };
10019 }
10020 this.timeStamp = src && src.timeStamp || Date.now();
10021 },
10022 preventDefault: function preventDefault() {
10023 this.isDefaultPrevented = returnTrue;
10024 var e = this.originalEvent;
10025 if (!e) {
10026 return;
10027 }
10028 if (e.preventDefault) {
10029 e.preventDefault();
10030 }
10031 },
10032 stopPropagation: function stopPropagation() {
10033 this.isPropagationStopped = returnTrue;
10034 var e = this.originalEvent;
10035 if (!e) {
10036 return;
10037 }
10038 if (e.stopPropagation) {
10039 e.stopPropagation();
10040 }
10041 },
10042 stopImmediatePropagation: function stopImmediatePropagation() {
10043 this.isImmediatePropagationStopped = returnTrue;
10044 this.stopPropagation();
10045 },
10046 isDefaultPrevented: returnFalse,
10047 isPropagationStopped: returnFalse,
10048 isImmediatePropagationStopped: returnFalse
10049 };
10050 var eventRegex = /^([^.]+)(\.(?:[^.]+))?$/;
10051 var universalNamespace = ".*";
10052 var defaults$8 = {
10053 qualifierCompare: function qualifierCompare(q1, q2) {
10054 return q1 === q2;
10055 },
10056 eventMatches: function eventMatches() {
10057 return true;
10058 },
10059 addEventFields: function addEventFields() {
10060 },
10061 callbackContext: function callbackContext(context) {
10062 return context;
10063 },
10064 beforeEmit: function beforeEmit() {
10065 },
10066 afterEmit: function afterEmit() {
10067 },
10068 bubble: function bubble() {
10069 return false;
10070 },
10071 parent: function parent() {
10072 return null;
10073 },
10074 context: null
10075 };
10076 var defaultsKeys = Object.keys(defaults$8);
10077 var emptyOpts = {};
10078 function Emitter() {
10079 var opts = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : emptyOpts;
10080 var context = arguments.length > 1 ? arguments[1] : void 0;
10081 for (var i2 = 0; i2 < defaultsKeys.length; i2++) {
10082 var key = defaultsKeys[i2];
10083 this[key] = opts[key] || defaults$8[key];
10084 }
10085 this.context = context || this.context;
10086 this.listeners = [];
10087 this.emitting = 0;
10088 }
10089 var p = Emitter.prototype;
10090 var forEachEvent = function forEachEvent2(self2, handler, events, qualifier, callback, conf, confOverrides) {
10091 if (fn$6(qualifier)) {
10092 callback = qualifier;
10093 qualifier = null;
10094 }
10095 if (confOverrides) {
10096 if (conf == null) {
10097 conf = confOverrides;
10098 } else {
10099 conf = extend({}, conf, confOverrides);
10100 }
10101 }
10102 var eventList = array(events) ? events : events.split(/\s+/);
10103 for (var i2 = 0; i2 < eventList.length; i2++) {
10104 var evt = eventList[i2];
10105 if (emptyString(evt)) {
10106 continue;
10107 }
10108 var match2 = evt.match(eventRegex);
10109 if (match2) {
10110 var type = match2[1];
10111 var namespace = match2[2] ? match2[2] : null;
10112 var ret = handler(self2, evt, type, namespace, qualifier, callback, conf);
10113 if (ret === false) {
10114 break;
10115 }
10116 }
10117 }
10118 };
10119 var makeEventObj = function makeEventObj2(self2, obj) {
10120 self2.addEventFields(self2.context, obj);
10121 return new Event(obj.type, obj);
10122 };
10123 var forEachEventObj = function forEachEventObj2(self2, handler, events) {
10124 if (event(events)) {
10125 handler(self2, events);
10126 return;
10127 } else if (plainObject(events)) {
10128 handler(self2, makeEventObj(self2, events));
10129 return;
10130 }
10131 var eventList = array(events) ? events : events.split(/\s+/);
10132 for (var i2 = 0; i2 < eventList.length; i2++) {
10133 var evt = eventList[i2];
10134 if (emptyString(evt)) {
10135 continue;
10136 }
10137 var match2 = evt.match(eventRegex);
10138 if (match2) {
10139 var type = match2[1];
10140 var namespace = match2[2] ? match2[2] : null;
10141 var eventObj = makeEventObj(self2, {
10142 type,
10143 namespace,
10144 target: self2.context
10145 });
10146 handler(self2, eventObj);
10147 }
10148 }
10149 };
10150 p.on = p.addListener = function(events, qualifier, callback, conf, confOverrides) {
10151 forEachEvent(this, function(self2, event2, type, namespace, qualifier2, callback2, conf2) {
10152 if (fn$6(callback2)) {
10153 self2.listeners.push({
10154 event: event2,
10155 // full event string
10156 callback: callback2,
10157 // callback to run
10158 type,
10159 // the event type (e.g. 'click')
10160 namespace,
10161 // the event namespace (e.g. ".foo")
10162 qualifier: qualifier2,
10163 // a restriction on whether to match this emitter
10164 conf: conf2
10165 // additional configuration
10166 });
10167 }
10168 }, events, qualifier, callback, conf, confOverrides);
10169 return this;
10170 };
10171 p.one = function(events, qualifier, callback, conf) {
10172 return this.on(events, qualifier, callback, conf, {
10173 one: true
10174 });
10175 };
10176 p.removeListener = p.off = function(events, qualifier, callback, conf) {
10177 var _this = this;
10178 if (this.emitting !== 0) {
10179 this.listeners = copyArray$1(this.listeners);
10180 }
10181 var listeners = this.listeners;
10182 var _loop = function _loop2(i3) {
10183 var listener = listeners[i3];
10184 forEachEvent(_this, function(self2, event2, type, namespace, qualifier2, callback2) {
10185 if ((listener.type === type || events === "*") && (!namespace && listener.namespace !== ".*" || listener.namespace === namespace) && (!qualifier2 || self2.qualifierCompare(listener.qualifier, qualifier2)) && (!callback2 || listener.callback === callback2)) {
10186 listeners.splice(i3, 1);
10187 return false;
10188 }
10189 }, events, qualifier, callback, conf);
10190 };
10191 for (var i2 = listeners.length - 1; i2 >= 0; i2--) {
10192 _loop(i2);
10193 }
10194 return this;
10195 };
10196 p.removeAllListeners = function() {
10197 return this.removeListener("*");
10198 };
10199 p.emit = p.trigger = function(events, extraParams, manualCallback) {
10200 var listeners = this.listeners;
10201 var numListenersBeforeEmit = listeners.length;
10202 this.emitting++;
10203 if (!array(extraParams)) {
10204 extraParams = [extraParams];
10205 }
10206 forEachEventObj(this, function(self2, eventObj) {
10207 if (manualCallback != null) {
10208 listeners = [{
10209 event: eventObj.event,
10210 type: eventObj.type,
10211 namespace: eventObj.namespace,
10212 callback: manualCallback
10213 }];
10214 numListenersBeforeEmit = listeners.length;
10215 }
10216 var _loop2 = function _loop22(i3) {
10217 var listener = listeners[i3];
10218 if (listener.type === eventObj.type && (!listener.namespace || listener.namespace === eventObj.namespace || listener.namespace === universalNamespace) && self2.eventMatches(self2.context, listener, eventObj)) {
10219 var args = [eventObj];
10220 if (extraParams != null) {
10221 push(args, extraParams);
10222 }
10223 self2.beforeEmit(self2.context, listener, eventObj);
10224 if (listener.conf && listener.conf.one) {
10225 self2.listeners = self2.listeners.filter(function(l) {
10226 return l !== listener;
10227 });
10228 }
10229 var context = self2.callbackContext(self2.context, listener, eventObj);
10230 var ret = listener.callback.apply(context, args);
10231 self2.afterEmit(self2.context, listener, eventObj);
10232 if (ret === false) {
10233 eventObj.stopPropagation();
10234 eventObj.preventDefault();
10235 }
10236 }
10237 };
10238 for (var i2 = 0; i2 < numListenersBeforeEmit; i2++) {
10239 _loop2(i2);
10240 }
10241 if (self2.bubble(self2.context) && !eventObj.isPropagationStopped()) {
10242 self2.parent(self2.context).emit(eventObj, extraParams);
10243 }
10244 }, events);
10245 this.emitting--;
10246 return this;
10247 };
10248 var emitterOptions$1 = {
10249 qualifierCompare: function qualifierCompare(selector1, selector2) {
10250 if (selector1 == null || selector2 == null) {
10251 return selector1 == null && selector2 == null;
10252 } else {
10253 return selector1.sameText(selector2);
10254 }
10255 },
10256 eventMatches: function eventMatches(ele, listener, eventObj) {
10257 var selector = listener.qualifier;
10258 if (selector != null) {
10259 return ele !== eventObj.target && element(eventObj.target) && selector.matches(eventObj.target);
10260 }
10261 return true;
10262 },
10263 addEventFields: function addEventFields(ele, evt) {
10264 evt.cy = ele.cy();
10265 evt.target = ele;
10266 },
10267 callbackContext: function callbackContext(ele, listener, eventObj) {
10268 return listener.qualifier != null ? eventObj.target : ele;
10269 },
10270 beforeEmit: function beforeEmit(context, listener) {
10271 if (listener.conf && listener.conf.once) {
10272 listener.conf.onceCollection.removeListener(listener.event, listener.qualifier, listener.callback);
10273 }
10274 },
10275 bubble: function bubble() {
10276 return true;
10277 },
10278 parent: function parent(ele) {
10279 return ele.isChild() ? ele.parent() : ele.cy();
10280 }
10281 };
10282 var argSelector$1 = function argSelector2(arg) {
10283 if (string(arg)) {
10284 return new Selector(arg);
10285 } else {
10286 return arg;
10287 }
10288 };
10289 var elesfn$9 = {
10290 createEmitter: function createEmitter() {
10291 for (var i2 = 0; i2 < this.length; i2++) {
10292 var ele = this[i2];
10293 var _p = ele._private;
10294 if (!_p.emitter) {
10295 _p.emitter = new Emitter(emitterOptions$1, ele);
10296 }
10297 }
10298 return this;
10299 },
10300 emitter: function emitter() {
10301 return this._private.emitter;
10302 },
10303 on: function on(events, selector, callback) {
10304 var argSel = argSelector$1(selector);
10305 for (var i2 = 0; i2 < this.length; i2++) {
10306 var ele = this[i2];
10307 ele.emitter().on(events, argSel, callback);
10308 }
10309 return this;
10310 },
10311 removeListener: function removeListener(events, selector, callback) {
10312 var argSel = argSelector$1(selector);
10313 for (var i2 = 0; i2 < this.length; i2++) {
10314 var ele = this[i2];
10315 ele.emitter().removeListener(events, argSel, callback);
10316 }
10317 return this;
10318 },
10319 removeAllListeners: function removeAllListeners() {
10320 for (var i2 = 0; i2 < this.length; i2++) {
10321 var ele = this[i2];
10322 ele.emitter().removeAllListeners();
10323 }
10324 return this;
10325 },
10326 one: function one(events, selector, callback) {
10327 var argSel = argSelector$1(selector);
10328 for (var i2 = 0; i2 < this.length; i2++) {
10329 var ele = this[i2];
10330 ele.emitter().one(events, argSel, callback);
10331 }
10332 return this;
10333 },
10334 once: function once(events, selector, callback) {
10335 var argSel = argSelector$1(selector);
10336 for (var i2 = 0; i2 < this.length; i2++) {
10337 var ele = this[i2];
10338 ele.emitter().on(events, argSel, callback, {
10339 once: true,
10340 onceCollection: this
10341 });
10342 }
10343 },
10344 emit: function emit(events, extraParams) {
10345 for (var i2 = 0; i2 < this.length; i2++) {
10346 var ele = this[i2];
10347 ele.emitter().emit(events, extraParams);
10348 }
10349 return this;
10350 },
10351 emitAndNotify: function emitAndNotify(event2, extraParams) {
10352 if (this.length === 0) {
10353 return;
10354 }
10355 this.cy().notify(event2, this);
10356 this.emit(event2, extraParams);
10357 return this;
10358 }
10359 };
10360 define.eventAliasesOn(elesfn$9);
10361 var elesfn$8 = {
10362 nodes: function nodes2(selector) {
10363 return this.filter(function(ele) {
10364 return ele.isNode();
10365 }).filter(selector);
10366 },
10367 edges: function edges(selector) {
10368 return this.filter(function(ele) {
10369 return ele.isEdge();
10370 }).filter(selector);
10371 },
10372 // internal helper to get nodes and edges as separate collections with single iteration over elements
10373 byGroup: function byGroup() {
10374 var nodes2 = this.spawn();
10375 var edges = this.spawn();
10376 for (var i2 = 0; i2 < this.length; i2++) {
10377 var ele = this[i2];
10378 if (ele.isNode()) {
10379 nodes2.push(ele);
10380 } else {
10381 edges.push(ele);
10382 }
10383 }
10384 return {
10385 nodes: nodes2,
10386 edges
10387 };
10388 },
10389 filter: function filter2(_filter, thisArg) {
10390 if (_filter === void 0) {
10391 return this;
10392 } else if (string(_filter) || elementOrCollection(_filter)) {
10393 return new Selector(_filter).filter(this);
10394 } else if (fn$6(_filter)) {
10395 var filterEles = this.spawn();
10396 var eles = this;
10397 for (var i2 = 0; i2 < eles.length; i2++) {
10398 var ele = eles[i2];
10399 var include = thisArg ? _filter.apply(thisArg, [ele, i2, eles]) : _filter(ele, i2, eles);
10400 if (include) {
10401 filterEles.push(ele);
10402 }
10403 }
10404 return filterEles;
10405 }
10406 return this.spawn();
10407 },
10408 not: function not(toRemove) {
10409 if (!toRemove) {
10410 return this;
10411 } else {
10412 if (string(toRemove)) {
10413 toRemove = this.filter(toRemove);
10414 }
10415 var elements2 = this.spawn();
10416 for (var i2 = 0; i2 < this.length; i2++) {
10417 var element2 = this[i2];
10418 var remove = toRemove.has(element2);
10419 if (!remove) {
10420 elements2.push(element2);
10421 }
10422 }
10423 return elements2;
10424 }
10425 },
10426 absoluteComplement: function absoluteComplement() {
10427 var cy = this.cy();
10428 return cy.mutableElements().not(this);
10429 },
10430 intersect: function intersect(other) {
10431 if (string(other)) {
10432 var selector = other;
10433 return this.filter(selector);
10434 }
10435 var elements2 = this.spawn();
10436 var col1 = this;
10437 var col2 = other;
10438 var col1Smaller = this.length < other.length;
10439 var colS = col1Smaller ? col1 : col2;
10440 var colL = col1Smaller ? col2 : col1;
10441 for (var i2 = 0; i2 < colS.length; i2++) {
10442 var ele = colS[i2];
10443 if (colL.has(ele)) {
10444 elements2.push(ele);
10445 }
10446 }
10447 return elements2;
10448 },
10449 xor: function xor(other) {
10450 var cy = this._private.cy;
10451 if (string(other)) {
10452 other = cy.$(other);
10453 }
10454 var elements2 = this.spawn();
10455 var col1 = this;
10456 var col2 = other;
10457 var add = function add2(col, other2) {
10458 for (var i2 = 0; i2 < col.length; i2++) {
10459 var ele = col[i2];
10460 var id = ele._private.data.id;
10461 var inOther = other2.hasElementWithId(id);
10462 if (!inOther) {
10463 elements2.push(ele);
10464 }
10465 }
10466 };
10467 add(col1, col2);
10468 add(col2, col1);
10469 return elements2;
10470 },
10471 diff: function diff(other) {
10472 var cy = this._private.cy;
10473 if (string(other)) {
10474 other = cy.$(other);
10475 }
10476 var left = this.spawn();
10477 var right = this.spawn();
10478 var both = this.spawn();
10479 var col1 = this;
10480 var col2 = other;
10481 var add = function add2(col, other2, retEles) {
10482 for (var i2 = 0; i2 < col.length; i2++) {
10483 var ele = col[i2];
10484 var id = ele._private.data.id;
10485 var inOther = other2.hasElementWithId(id);
10486 if (inOther) {
10487 both.merge(ele);
10488 } else {
10489 retEles.push(ele);
10490 }
10491 }
10492 };
10493 add(col1, col2, left);
10494 add(col2, col1, right);
10495 return {
10496 left,
10497 right,
10498 both
10499 };
10500 },
10501 add: function add(toAdd) {
10502 var cy = this._private.cy;
10503 if (!toAdd) {
10504 return this;
10505 }
10506 if (string(toAdd)) {
10507 var selector = toAdd;
10508 toAdd = cy.mutableElements().filter(selector);
10509 }
10510 var elements2 = this.spawnSelf();
10511 for (var i2 = 0; i2 < toAdd.length; i2++) {
10512 var ele = toAdd[i2];
10513 var add2 = !this.has(ele);
10514 if (add2) {
10515 elements2.push(ele);
10516 }
10517 }
10518 return elements2;
10519 },
10520 // in place merge on calling collection
10521 merge: function merge(toAdd) {
10522 var _p = this._private;
10523 var cy = _p.cy;
10524 if (!toAdd) {
10525 return this;
10526 }
10527 if (toAdd && string(toAdd)) {
10528 var selector = toAdd;
10529 toAdd = cy.mutableElements().filter(selector);
10530 }
10531 var map = _p.map;
10532 for (var i2 = 0; i2 < toAdd.length; i2++) {
10533 var toAddEle = toAdd[i2];
10534 var id = toAddEle._private.data.id;
10535 var add = !map.has(id);
10536 if (add) {
10537 var index = this.length++;
10538 this[index] = toAddEle;
10539 map.set(id, {
10540 ele: toAddEle,
10541 index
10542 });
10543 }
10544 }
10545 return this;
10546 },
10547 unmergeAt: function unmergeAt(i2) {
10548 var ele = this[i2];
10549 var id = ele.id();
10550 var _p = this._private;
10551 var map = _p.map;
10552 this[i2] = void 0;
10553 map["delete"](id);
10554 var unmergedLastEle = i2 === this.length - 1;
10555 if (this.length > 1 && !unmergedLastEle) {
10556 var lastEleI = this.length - 1;
10557 var lastEle = this[lastEleI];
10558 var lastEleId = lastEle._private.data.id;
10559 this[lastEleI] = void 0;
10560 this[i2] = lastEle;
10561 map.set(lastEleId, {
10562 ele: lastEle,
10563 index: i2
10564 });
10565 }
10566 this.length--;
10567 return this;
10568 },
10569 // remove single ele in place in calling collection
10570 unmergeOne: function unmergeOne(ele) {
10571 ele = ele[0];
10572 var _p = this._private;
10573 var id = ele._private.data.id;
10574 var map = _p.map;
10575 var entry = map.get(id);
10576 if (!entry) {
10577 return this;
10578 }
10579 var i2 = entry.index;
10580 this.unmergeAt(i2);
10581 return this;
10582 },
10583 // remove eles in place on calling collection
10584 unmerge: function unmerge(toRemove) {
10585 var cy = this._private.cy;
10586 if (!toRemove) {
10587 return this;
10588 }
10589 if (toRemove && string(toRemove)) {
10590 var selector = toRemove;
10591 toRemove = cy.mutableElements().filter(selector);
10592 }
10593 for (var i2 = 0; i2 < toRemove.length; i2++) {
10594 this.unmergeOne(toRemove[i2]);
10595 }
10596 return this;
10597 },
10598 unmergeBy: function unmergeBy(toRmFn) {
10599 for (var i2 = this.length - 1; i2 >= 0; i2--) {
10600 var ele = this[i2];
10601 if (toRmFn(ele)) {
10602 this.unmergeAt(i2);
10603 }
10604 }
10605 return this;
10606 },
10607 map: function map(mapFn, thisArg) {
10608 var arr = [];
10609 var eles = this;
10610 for (var i2 = 0; i2 < eles.length; i2++) {
10611 var ele = eles[i2];
10612 var ret = thisArg ? mapFn.apply(thisArg, [ele, i2, eles]) : mapFn(ele, i2, eles);
10613 arr.push(ret);
10614 }
10615 return arr;
10616 },
10617 reduce: function reduce(fn2, initialValue) {
10618 var val = initialValue;
10619 var eles = this;
10620 for (var i2 = 0; i2 < eles.length; i2++) {
10621 val = fn2(val, eles[i2], i2, eles);
10622 }
10623 return val;
10624 },
10625 max: function max2(valFn, thisArg) {
10626 var max3 = -Infinity;
10627 var maxEle;
10628 var eles = this;
10629 for (var i2 = 0; i2 < eles.length; i2++) {
10630 var ele = eles[i2];
10631 var val = thisArg ? valFn.apply(thisArg, [ele, i2, eles]) : valFn(ele, i2, eles);
10632 if (val > max3) {
10633 max3 = val;
10634 maxEle = ele;
10635 }
10636 }
10637 return {
10638 value: max3,
10639 ele: maxEle
10640 };
10641 },
10642 min: function min2(valFn, thisArg) {
10643 var min3 = Infinity;
10644 var minEle;
10645 var eles = this;
10646 for (var i2 = 0; i2 < eles.length; i2++) {
10647 var ele = eles[i2];
10648 var val = thisArg ? valFn.apply(thisArg, [ele, i2, eles]) : valFn(ele, i2, eles);
10649 if (val < min3) {
10650 min3 = val;
10651 minEle = ele;
10652 }
10653 }
10654 return {
10655 value: min3,
10656 ele: minEle
10657 };
10658 }
10659 };
10660 var fn$1 = elesfn$8;
10661 fn$1["u"] = fn$1["|"] = fn$1["+"] = fn$1.union = fn$1.or = fn$1.add;
10662 fn$1["\\"] = fn$1["!"] = fn$1["-"] = fn$1.difference = fn$1.relativeComplement = fn$1.subtract = fn$1.not;
10663 fn$1["n"] = fn$1["&"] = fn$1["."] = fn$1.and = fn$1.intersection = fn$1.intersect;
10664 fn$1["^"] = fn$1["(+)"] = fn$1["(-)"] = fn$1.symmetricDifference = fn$1.symdiff = fn$1.xor;
10665 fn$1.fnFilter = fn$1.filterFn = fn$1.stdFilter = fn$1.filter;
10666 fn$1.complement = fn$1.abscomp = fn$1.absoluteComplement;
10667 var elesfn$7 = {
10668 isNode: function isNode() {
10669 return this.group() === "nodes";
10670 },
10671 isEdge: function isEdge() {
10672 return this.group() === "edges";
10673 },
10674 isLoop: function isLoop() {
10675 return this.isEdge() && this.source()[0] === this.target()[0];
10676 },
10677 isSimple: function isSimple() {
10678 return this.isEdge() && this.source()[0] !== this.target()[0];
10679 },
10680 group: function group() {
10681 var ele = this[0];
10682 if (ele) {
10683 return ele._private.group;
10684 }
10685 }
10686 };
10687 var zIndexSort = function zIndexSort2(a, b) {
10688 var cy = a.cy();
10689 var hasCompoundNodes = cy.hasCompoundNodes();
10690 function getDepth(ele) {
10691 var style = ele.pstyle("z-compound-depth");
10692 if (style.value === "auto") {
10693 return hasCompoundNodes ? ele.zDepth() : 0;
10694 } else if (style.value === "bottom") {
10695 return -1;
10696 } else if (style.value === "top") {
10697 return MAX_INT$1;
10698 }
10699 return 0;
10700 }
10701 var depthDiff = getDepth(a) - getDepth(b);
10702 if (depthDiff !== 0) {
10703 return depthDiff;
10704 }
10705 function getEleDepth(ele) {
10706 var style = ele.pstyle("z-index-compare");
10707 if (style.value === "auto") {
10708 return ele.isNode() ? 1 : 0;
10709 }
10710 return 0;
10711 }
10712 var eleDiff = getEleDepth(a) - getEleDepth(b);
10713 if (eleDiff !== 0) {
10714 return eleDiff;
10715 }
10716 var zDiff = a.pstyle("z-index").value - b.pstyle("z-index").value;
10717 if (zDiff !== 0) {
10718 return zDiff;
10719 }
10720 return a.poolIndex() - b.poolIndex();
10721 };
10722 var elesfn$6 = {
10723 forEach: function forEach(fn2, thisArg) {
10724 if (fn$6(fn2)) {
10725 var N = this.length;
10726 for (var i2 = 0; i2 < N; i2++) {
10727 var ele = this[i2];
10728 var ret = thisArg ? fn2.apply(thisArg, [ele, i2, this]) : fn2(ele, i2, this);
10729 if (ret === false) {
10730 break;
10731 }
10732 }
10733 }
10734 return this;
10735 },
10736 toArray: function toArray() {
10737 var array2 = [];
10738 for (var i2 = 0; i2 < this.length; i2++) {
10739 array2.push(this[i2]);
10740 }
10741 return array2;
10742 },
10743 slice: function slice(start, end) {
10744 var array2 = [];
10745 var thisSize = this.length;
10746 if (end == null) {
10747 end = thisSize;
10748 }
10749 if (start == null) {
10750 start = 0;
10751 }
10752 if (start < 0) {
10753 start = thisSize + start;
10754 }
10755 if (end < 0) {
10756 end = thisSize + end;
10757 }
10758 for (var i2 = start; i2 >= 0 && i2 < end && i2 < thisSize; i2++) {
10759 array2.push(this[i2]);
10760 }
10761 return this.spawn(array2);
10762 },
10763 size: function size() {
10764 return this.length;
10765 },
10766 eq: function eq2(i2) {
10767 return this[i2] || this.spawn();
10768 },
10769 first: function first() {
10770 return this[0] || this.spawn();
10771 },
10772 last: function last() {
10773 return this[this.length - 1] || this.spawn();
10774 },
10775 empty: function empty() {
10776 return this.length === 0;
10777 },
10778 nonempty: function nonempty() {
10779 return !this.empty();
10780 },
10781 sort: function sort(sortFn) {
10782 if (!fn$6(sortFn)) {
10783 return this;
10784 }
10785 var sorted = this.toArray().sort(sortFn);
10786 return this.spawn(sorted);
10787 },
10788 sortByZIndex: function sortByZIndex() {
10789 return this.sort(zIndexSort);
10790 },
10791 zDepth: function zDepth() {
10792 var ele = this[0];
10793 if (!ele) {
10794 return void 0;
10795 }
10796 var _p = ele._private;
10797 var group = _p.group;
10798 if (group === "nodes") {
10799 var depth = _p.data.parent ? ele.parents().size() : 0;
10800 if (!ele.isParent()) {
10801 return MAX_INT$1 - 1;
10802 }
10803 return depth;
10804 } else {
10805 var src = _p.source;
10806 var tgt = _p.target;
10807 var srcDepth = src.zDepth();
10808 var tgtDepth = tgt.zDepth();
10809 return Math.max(srcDepth, tgtDepth, 0);
10810 }
10811 }
10812 };
10813 elesfn$6.each = elesfn$6.forEach;
10814 var defineSymbolIterator = function defineSymbolIterator2() {
10815 var typeofUndef = "undefined";
10816 var isIteratorSupported = (typeof Symbol === "undefined" ? "undefined" : _typeof(Symbol)) != typeofUndef && _typeof(Symbol.iterator) != typeofUndef;
10817 if (isIteratorSupported) {
10818 elesfn$6[Symbol.iterator] = function() {
10819 var _this = this;
10820 var entry = {
10821 value: void 0,
10822 done: false
10823 };
10824 var i2 = 0;
10825 var length = this.length;
10826 return _defineProperty$1({
10827 next: function next2() {
10828 if (i2 < length) {
10829 entry.value = _this[i2++];
10830 } else {
10831 entry.value = void 0;
10832 entry.done = true;
10833 }
10834 return entry;
10835 }
10836 }, Symbol.iterator, function() {
10837 return this;
10838 });
10839 };
10840 }
10841 };
10842 defineSymbolIterator();
10843 var getLayoutDimensionOptions = defaults$g({
10844 nodeDimensionsIncludeLabels: false
10845 });
10846 var elesfn$5 = {
10847 // Calculates and returns node dimensions { x, y } based on options given
10848 layoutDimensions: function layoutDimensions(options) {
10849 options = getLayoutDimensionOptions(options);
10850 var dims;
10851 if (!this.takesUpSpace()) {
10852 dims = {
10853 w: 0,
10854 h: 0
10855 };
10856 } else if (options.nodeDimensionsIncludeLabels) {
10857 var bbDim = this.boundingBox();
10858 dims = {
10859 w: bbDim.w,
10860 h: bbDim.h
10861 };
10862 } else {
10863 dims = {
10864 w: this.outerWidth(),
10865 h: this.outerHeight()
10866 };
10867 }
10868 if (dims.w === 0 || dims.h === 0) {
10869 dims.w = dims.h = 1;
10870 }
10871 return dims;
10872 },
10873 // using standard layout options, apply position function (w/ or w/o animation)
10874 layoutPositions: function layoutPositions(layout2, options, fn2) {
10875 var nodes2 = this.nodes().filter(function(n) {
10876 return !n.isParent();
10877 });
10878 var cy = this.cy();
10879 var layoutEles = options.eles;
10880 var getMemoizeKey = function getMemoizeKey2(node2) {
10881 return node2.id();
10882 };
10883 var fnMem = memoize$1(fn2, getMemoizeKey);
10884 layout2.emit({
10885 type: "layoutstart",
10886 layout: layout2
10887 });
10888 layout2.animations = [];
10889 var calculateSpacing = function calculateSpacing2(spacing, nodesBb, pos) {
10890 var center = {
10891 x: nodesBb.x1 + nodesBb.w / 2,
10892 y: nodesBb.y1 + nodesBb.h / 2
10893 };
10894 var spacingVector = {
10895 // scale from center of bounding box (not necessarily 0,0)
10896 x: (pos.x - center.x) * spacing,
10897 y: (pos.y - center.y) * spacing
10898 };
10899 return {
10900 x: center.x + spacingVector.x,
10901 y: center.y + spacingVector.y
10902 };
10903 };
10904 var useSpacingFactor = options.spacingFactor && options.spacingFactor !== 1;
10905 var spacingBb = function spacingBb2() {
10906 if (!useSpacingFactor) {
10907 return null;
10908 }
10909 var bb2 = makeBoundingBox();
10910 for (var i3 = 0; i3 < nodes2.length; i3++) {
10911 var node2 = nodes2[i3];
10912 var pos = fnMem(node2, i3);
10913 expandBoundingBoxByPoint(bb2, pos.x, pos.y);
10914 }
10915 return bb2;
10916 };
10917 var bb = spacingBb();
10918 var getFinalPos = memoize$1(function(node2, i3) {
10919 var newPos2 = fnMem(node2, i3);
10920 if (useSpacingFactor) {
10921 var spacing = Math.abs(options.spacingFactor);
10922 newPos2 = calculateSpacing(spacing, bb, newPos2);
10923 }
10924 if (options.transform != null) {
10925 newPos2 = options.transform(node2, newPos2);
10926 }
10927 return newPos2;
10928 }, getMemoizeKey);
10929 if (options.animate) {
10930 for (var i2 = 0; i2 < nodes2.length; i2++) {
10931 var node = nodes2[i2];
10932 var newPos = getFinalPos(node, i2);
10933 var animateNode = options.animateFilter == null || options.animateFilter(node, i2);
10934 if (animateNode) {
10935 var ani = node.animation({
10936 position: newPos,
10937 duration: options.animationDuration,
10938 easing: options.animationEasing
10939 });
10940 layout2.animations.push(ani);
10941 } else {
10942 node.position(newPos);
10943 }
10944 }
10945 if (options.fit) {
10946 var fitAni = cy.animation({
10947 fit: {
10948 boundingBox: layoutEles.boundingBoxAt(getFinalPos),
10949 padding: options.padding
10950 },
10951 duration: options.animationDuration,
10952 easing: options.animationEasing
10953 });
10954 layout2.animations.push(fitAni);
10955 } else if (options.zoom !== void 0 && options.pan !== void 0) {
10956 var zoomPanAni = cy.animation({
10957 zoom: options.zoom,
10958 pan: options.pan,
10959 duration: options.animationDuration,
10960 easing: options.animationEasing
10961 });
10962 layout2.animations.push(zoomPanAni);
10963 }
10964 layout2.animations.forEach(function(ani2) {
10965 return ani2.play();
10966 });
10967 layout2.one("layoutready", options.ready);
10968 layout2.emit({
10969 type: "layoutready",
10970 layout: layout2
10971 });
10972 Promise$1.all(layout2.animations.map(function(ani2) {
10973 return ani2.promise();
10974 })).then(function() {
10975 layout2.one("layoutstop", options.stop);
10976 layout2.emit({
10977 type: "layoutstop",
10978 layout: layout2
10979 });
10980 });
10981 } else {
10982 nodes2.positions(getFinalPos);
10983 if (options.fit) {
10984 cy.fit(options.eles, options.padding);
10985 }
10986 if (options.zoom != null) {
10987 cy.zoom(options.zoom);
10988 }
10989 if (options.pan) {
10990 cy.pan(options.pan);
10991 }
10992 layout2.one("layoutready", options.ready);
10993 layout2.emit({
10994 type: "layoutready",
10995 layout: layout2
10996 });
10997 layout2.one("layoutstop", options.stop);
10998 layout2.emit({
10999 type: "layoutstop",
11000 layout: layout2
11001 });
11002 }
11003 return this;
11004 },
11005 layout: function layout2(options) {
11006 var cy = this.cy();
11007 return cy.makeLayout(extend({}, options, {
11008 eles: this
11009 }));
11010 }
11011 };
11012 elesfn$5.createLayout = elesfn$5.makeLayout = elesfn$5.layout;
11013 function styleCache(key, fn2, ele) {
11014 var _p = ele._private;
11015 var cache2 = _p.styleCache = _p.styleCache || [];
11016 var val;
11017 if ((val = cache2[key]) != null) {
11018 return val;
11019 } else {
11020 val = cache2[key] = fn2(ele);
11021 return val;
11022 }
11023 }
11024 function cacheStyleFunction(key, fn2) {
11025 key = hashString(key);
11026 return function cachedStyleFunction(ele) {
11027 return styleCache(key, fn2, ele);
11028 };
11029 }
11030 function cachePrototypeStyleFunction(key, fn2) {
11031 key = hashString(key);
11032 var selfFn = function selfFn2(ele) {
11033 return fn2.call(ele);
11034 };
11035 return function cachedPrototypeStyleFunction() {
11036 var ele = this[0];
11037 if (ele) {
11038 return styleCache(key, selfFn, ele);
11039 }
11040 };
11041 }
11042 var elesfn$4 = {
11043 recalculateRenderedStyle: function recalculateRenderedStyle(useCache) {
11044 var cy = this.cy();
11045 var renderer2 = cy.renderer();
11046 var styleEnabled = cy.styleEnabled();
11047 if (renderer2 && styleEnabled) {
11048 renderer2.recalculateRenderedStyle(this, useCache);
11049 }
11050 return this;
11051 },
11052 dirtyStyleCache: function dirtyStyleCache() {
11053 var cy = this.cy();
11054 var dirty = function dirty2(ele) {
11055 return ele._private.styleCache = null;
11056 };
11057 if (cy.hasCompoundNodes()) {
11058 var eles;
11059 eles = this.spawnSelf().merge(this.descendants()).merge(this.parents());
11060 eles.merge(eles.connectedEdges());
11061 eles.forEach(dirty);
11062 } else {
11063 this.forEach(function(ele) {
11064 dirty(ele);
11065 ele.connectedEdges().forEach(dirty);
11066 });
11067 }
11068 return this;
11069 },
11070 // fully updates (recalculates) the style for the elements
11071 updateStyle: function updateStyle(notifyRenderer) {
11072 var cy = this._private.cy;
11073 if (!cy.styleEnabled()) {
11074 return this;
11075 }
11076 if (cy.batching()) {
11077 var bEles = cy._private.batchStyleEles;
11078 bEles.merge(this);
11079 return this;
11080 }
11081 var hasCompounds = cy.hasCompoundNodes();
11082 var updatedEles = this;
11083 notifyRenderer = notifyRenderer || notifyRenderer === void 0 ? true : false;
11084 if (hasCompounds) {
11085 updatedEles = this.spawnSelf().merge(this.descendants()).merge(this.parents());
11086 }
11087 var changedEles = updatedEles;
11088 if (notifyRenderer) {
11089 changedEles.emitAndNotify("style");
11090 } else {
11091 changedEles.emit("style");
11092 }
11093 updatedEles.forEach(function(ele) {
11094 return ele._private.styleDirty = true;
11095 });
11096 return this;
11097 },
11098 // private: clears dirty flag and recalculates style
11099 cleanStyle: function cleanStyle() {
11100 var cy = this.cy();
11101 if (!cy.styleEnabled()) {
11102 return;
11103 }
11104 for (var i2 = 0; i2 < this.length; i2++) {
11105 var ele = this[i2];
11106 if (ele._private.styleDirty) {
11107 ele._private.styleDirty = false;
11108 cy.style().apply(ele);
11109 }
11110 }
11111 },
11112 // get the internal parsed style object for the specified property
11113 parsedStyle: function parsedStyle(property) {
11114 var includeNonDefault = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
11115 var ele = this[0];
11116 var cy = ele.cy();
11117 if (!cy.styleEnabled()) {
11118 return;
11119 }
11120 if (ele) {
11121 this.cleanStyle();
11122 var overriddenStyle = ele._private.style[property];
11123 if (overriddenStyle != null) {
11124 return overriddenStyle;
11125 } else if (includeNonDefault) {
11126 return cy.style().getDefaultProperty(property);
11127 } else {
11128 return null;
11129 }
11130 }
11131 },
11132 numericStyle: function numericStyle(property) {
11133 var ele = this[0];
11134 if (!ele.cy().styleEnabled()) {
11135 return;
11136 }
11137 if (ele) {
11138 var pstyle = ele.pstyle(property);
11139 return pstyle.pfValue !== void 0 ? pstyle.pfValue : pstyle.value;
11140 }
11141 },
11142 numericStyleUnits: function numericStyleUnits(property) {
11143 var ele = this[0];
11144 if (!ele.cy().styleEnabled()) {
11145 return;
11146 }
11147 if (ele) {
11148 return ele.pstyle(property).units;
11149 }
11150 },
11151 // get the specified css property as a rendered value (i.e. on-screen value)
11152 // or get the whole rendered style if no property specified (NB doesn't allow setting)
11153 renderedStyle: function renderedStyle(property) {
11154 var cy = this.cy();
11155 if (!cy.styleEnabled()) {
11156 return this;
11157 }
11158 var ele = this[0];
11159 if (ele) {
11160 return cy.style().getRenderedStyle(ele, property);
11161 }
11162 },
11163 // read the calculated css style of the element or override the style (via a bypass)
11164 style: function style(name2, value) {
11165 var cy = this.cy();
11166 if (!cy.styleEnabled()) {
11167 return this;
11168 }
11169 var updateTransitions = false;
11170 var style2 = cy.style();
11171 if (plainObject(name2)) {
11172 var props = name2;
11173 style2.applyBypass(this, props, updateTransitions);
11174 this.emitAndNotify("style");
11175 } else if (string(name2)) {
11176 if (value === void 0) {
11177 var ele = this[0];
11178 if (ele) {
11179 return style2.getStylePropertyValue(ele, name2);
11180 } else {
11181 return;
11182 }
11183 } else {
11184 style2.applyBypass(this, name2, value, updateTransitions);
11185 this.emitAndNotify("style");
11186 }
11187 } else if (name2 === void 0) {
11188 var _ele = this[0];
11189 if (_ele) {
11190 return style2.getRawStyle(_ele);
11191 } else {
11192 return;
11193 }
11194 }
11195 return this;
11196 },
11197 removeStyle: function removeStyle(names) {
11198 var cy = this.cy();
11199 if (!cy.styleEnabled()) {
11200 return this;
11201 }
11202 var updateTransitions = false;
11203 var style = cy.style();
11204 var eles = this;
11205 if (names === void 0) {
11206 for (var i2 = 0; i2 < eles.length; i2++) {
11207 var ele = eles[i2];
11208 style.removeAllBypasses(ele, updateTransitions);
11209 }
11210 } else {
11211 names = names.split(/\s+/);
11212 for (var _i = 0; _i < eles.length; _i++) {
11213 var _ele2 = eles[_i];
11214 style.removeBypasses(_ele2, names, updateTransitions);
11215 }
11216 }
11217 this.emitAndNotify("style");
11218 return this;
11219 },
11220 show: function show() {
11221 this.css("display", "element");
11222 return this;
11223 },
11224 hide: function hide() {
11225 this.css("display", "none");
11226 return this;
11227 },
11228 effectiveOpacity: function effectiveOpacity() {
11229 var cy = this.cy();
11230 if (!cy.styleEnabled()) {
11231 return 1;
11232 }
11233 var hasCompoundNodes = cy.hasCompoundNodes();
11234 var ele = this[0];
11235 if (ele) {
11236 var _p = ele._private;
11237 var parentOpacity = ele.pstyle("opacity").value;
11238 if (!hasCompoundNodes) {
11239 return parentOpacity;
11240 }
11241 var parents = !_p.data.parent ? null : ele.parents();
11242 if (parents) {
11243 for (var i2 = 0; i2 < parents.length; i2++) {
11244 var parent = parents[i2];
11245 var opacity = parent.pstyle("opacity").value;
11246 parentOpacity = opacity * parentOpacity;
11247 }
11248 }
11249 return parentOpacity;
11250 }
11251 },
11252 transparent: function transparent() {
11253 var cy = this.cy();
11254 if (!cy.styleEnabled()) {
11255 return false;
11256 }
11257 var ele = this[0];
11258 var hasCompoundNodes = ele.cy().hasCompoundNodes();
11259 if (ele) {
11260 if (!hasCompoundNodes) {
11261 return ele.pstyle("opacity").value === 0;
11262 } else {
11263 return ele.effectiveOpacity() === 0;
11264 }
11265 }
11266 },
11267 backgrounding: function backgrounding() {
11268 var cy = this.cy();
11269 if (!cy.styleEnabled()) {
11270 return false;
11271 }
11272 var ele = this[0];
11273 return ele._private.backgrounding ? true : false;
11274 }
11275 };
11276 function checkCompound(ele, parentOk) {
11277 var _p = ele._private;
11278 var parents = _p.data.parent ? ele.parents() : null;
11279 if (parents) {
11280 for (var i2 = 0; i2 < parents.length; i2++) {
11281 var parent = parents[i2];
11282 if (!parentOk(parent)) {
11283 return false;
11284 }
11285 }
11286 }
11287 return true;
11288 }
11289 function defineDerivedStateFunction(specs) {
11290 var ok = specs.ok;
11291 var edgeOkViaNode = specs.edgeOkViaNode || specs.ok;
11292 var parentOk = specs.parentOk || specs.ok;
11293 return function() {
11294 var cy = this.cy();
11295 if (!cy.styleEnabled()) {
11296 return true;
11297 }
11298 var ele = this[0];
11299 var hasCompoundNodes = cy.hasCompoundNodes();
11300 if (ele) {
11301 var _p = ele._private;
11302 if (!ok(ele)) {
11303 return false;
11304 }
11305 if (ele.isNode()) {
11306 return !hasCompoundNodes || checkCompound(ele, parentOk);
11307 } else {
11308 var src = _p.source;
11309 var tgt = _p.target;
11310 return edgeOkViaNode(src) && (!hasCompoundNodes || checkCompound(src, edgeOkViaNode)) && (src === tgt || edgeOkViaNode(tgt) && (!hasCompoundNodes || checkCompound(tgt, edgeOkViaNode)));
11311 }
11312 }
11313 };
11314 }
11315 var eleTakesUpSpace = cacheStyleFunction("eleTakesUpSpace", function(ele) {
11316 return ele.pstyle("display").value === "element" && ele.width() !== 0 && (ele.isNode() ? ele.height() !== 0 : true);
11317 });
11318 elesfn$4.takesUpSpace = cachePrototypeStyleFunction("takesUpSpace", defineDerivedStateFunction({
11319 ok: eleTakesUpSpace
11320 }));
11321 var eleInteractive = cacheStyleFunction("eleInteractive", function(ele) {
11322 return ele.pstyle("events").value === "yes" && ele.pstyle("visibility").value === "visible" && eleTakesUpSpace(ele);
11323 });
11324 var parentInteractive = cacheStyleFunction("parentInteractive", function(parent) {
11325 return parent.pstyle("visibility").value === "visible" && eleTakesUpSpace(parent);
11326 });
11327 elesfn$4.interactive = cachePrototypeStyleFunction("interactive", defineDerivedStateFunction({
11328 ok: eleInteractive,
11329 parentOk: parentInteractive,
11330 edgeOkViaNode: eleTakesUpSpace
11331 }));
11332 elesfn$4.noninteractive = function() {
11333 var ele = this[0];
11334 if (ele) {
11335 return !ele.interactive();
11336 }
11337 };
11338 var eleVisible = cacheStyleFunction("eleVisible", function(ele) {
11339 return ele.pstyle("visibility").value === "visible" && ele.pstyle("opacity").pfValue !== 0 && eleTakesUpSpace(ele);
11340 });
11341 var edgeVisibleViaNode = eleTakesUpSpace;
11342 elesfn$4.visible = cachePrototypeStyleFunction("visible", defineDerivedStateFunction({
11343 ok: eleVisible,
11344 edgeOkViaNode: edgeVisibleViaNode
11345 }));
11346 elesfn$4.hidden = function() {
11347 var ele = this[0];
11348 if (ele) {
11349 return !ele.visible();
11350 }
11351 };
11352 elesfn$4.isBundledBezier = cachePrototypeStyleFunction("isBundledBezier", function() {
11353 if (!this.cy().styleEnabled()) {
11354 return false;
11355 }
11356 return !this.removed() && this.pstyle("curve-style").value === "bezier" && this.takesUpSpace();
11357 });
11358 elesfn$4.bypass = elesfn$4.css = elesfn$4.style;
11359 elesfn$4.renderedCss = elesfn$4.renderedStyle;
11360 elesfn$4.removeBypass = elesfn$4.removeCss = elesfn$4.removeStyle;
11361 elesfn$4.pstyle = elesfn$4.parsedStyle;
11362 var elesfn$3 = {};
11363 function defineSwitchFunction(params) {
11364 return function() {
11365 var args = arguments;
11366 var changedEles = [];
11367 if (args.length === 2) {
11368 var data2 = args[0];
11369 var handler = args[1];
11370 this.on(params.event, data2, handler);
11371 } else if (args.length === 1 && fn$6(args[0])) {
11372 var _handler = args[0];
11373 this.on(params.event, _handler);
11374 } else if (args.length === 0 || args.length === 1 && array(args[0])) {
11375 var addlEvents = args.length === 1 ? args[0] : null;
11376 for (var i2 = 0; i2 < this.length; i2++) {
11377 var ele = this[i2];
11378 var able = !params.ableField || ele._private[params.ableField];
11379 var changed = ele._private[params.field] != params.value;
11380 if (params.overrideAble) {
11381 var overrideAble = params.overrideAble(ele);
11382 if (overrideAble !== void 0) {
11383 able = overrideAble;
11384 if (!overrideAble) {
11385 return this;
11386 }
11387 }
11388 }
11389 if (able) {
11390 ele._private[params.field] = params.value;
11391 if (changed) {
11392 changedEles.push(ele);
11393 }
11394 }
11395 }
11396 var changedColl = this.spawn(changedEles);
11397 changedColl.updateStyle();
11398 changedColl.emit(params.event);
11399 if (addlEvents) {
11400 changedColl.emit(addlEvents);
11401 }
11402 }
11403 return this;
11404 };
11405 }
11406 function defineSwitchSet(params) {
11407 elesfn$3[params.field] = function() {
11408 var ele = this[0];
11409 if (ele) {
11410 if (params.overrideField) {
11411 var val = params.overrideField(ele);
11412 if (val !== void 0) {
11413 return val;
11414 }
11415 }
11416 return ele._private[params.field];
11417 }
11418 };
11419 elesfn$3[params.on] = defineSwitchFunction({
11420 event: params.on,
11421 field: params.field,
11422 ableField: params.ableField,
11423 overrideAble: params.overrideAble,
11424 value: true
11425 });
11426 elesfn$3[params.off] = defineSwitchFunction({
11427 event: params.off,
11428 field: params.field,
11429 ableField: params.ableField,
11430 overrideAble: params.overrideAble,
11431 value: false
11432 });
11433 }
11434 defineSwitchSet({
11435 field: "locked",
11436 overrideField: function overrideField(ele) {
11437 return ele.cy().autolock() ? true : void 0;
11438 },
11439 on: "lock",
11440 off: "unlock"
11441 });
11442 defineSwitchSet({
11443 field: "grabbable",
11444 overrideField: function overrideField(ele) {
11445 return ele.cy().autoungrabify() || ele.pannable() ? false : void 0;
11446 },
11447 on: "grabify",
11448 off: "ungrabify"
11449 });
11450 defineSwitchSet({
11451 field: "selected",
11452 ableField: "selectable",
11453 overrideAble: function overrideAble(ele) {
11454 return ele.cy().autounselectify() ? false : void 0;
11455 },
11456 on: "select",
11457 off: "unselect"
11458 });
11459 defineSwitchSet({
11460 field: "selectable",
11461 overrideField: function overrideField(ele) {
11462 return ele.cy().autounselectify() ? false : void 0;
11463 },
11464 on: "selectify",
11465 off: "unselectify"
11466 });
11467 elesfn$3.deselect = elesfn$3.unselect;
11468 elesfn$3.grabbed = function() {
11469 var ele = this[0];
11470 if (ele) {
11471 return ele._private.grabbed;
11472 }
11473 };
11474 defineSwitchSet({
11475 field: "active",
11476 on: "activate",
11477 off: "unactivate"
11478 });
11479 defineSwitchSet({
11480 field: "pannable",
11481 on: "panify",
11482 off: "unpanify"
11483 });
11484 elesfn$3.inactive = function() {
11485 var ele = this[0];
11486 if (ele) {
11487 return !ele._private.active;
11488 }
11489 };
11490 var elesfn$2 = {};
11491 var defineDagExtremity = function defineDagExtremity2(params) {
11492 return function dagExtremityImpl(selector) {
11493 var eles = this;
11494 var ret = [];
11495 for (var i2 = 0; i2 < eles.length; i2++) {
11496 var ele = eles[i2];
11497 if (!ele.isNode()) {
11498 continue;
11499 }
11500 var disqualified = false;
11501 var edges = ele.connectedEdges();
11502 for (var j = 0; j < edges.length; j++) {
11503 var edge = edges[j];
11504 var src = edge.source();
11505 var tgt = edge.target();
11506 if (params.noIncomingEdges && tgt === ele && src !== ele || params.noOutgoingEdges && src === ele && tgt !== ele) {
11507 disqualified = true;
11508 break;
11509 }
11510 }
11511 if (!disqualified) {
11512 ret.push(ele);
11513 }
11514 }
11515 return this.spawn(ret, true).filter(selector);
11516 };
11517 };
11518 var defineDagOneHop = function defineDagOneHop2(params) {
11519 return function(selector) {
11520 var eles = this;
11521 var oEles = [];
11522 for (var i2 = 0; i2 < eles.length; i2++) {
11523 var ele = eles[i2];
11524 if (!ele.isNode()) {
11525 continue;
11526 }
11527 var edges = ele.connectedEdges();
11528 for (var j = 0; j < edges.length; j++) {
11529 var edge = edges[j];
11530 var src = edge.source();
11531 var tgt = edge.target();
11532 if (params.outgoing && src === ele) {
11533 oEles.push(edge);
11534 oEles.push(tgt);
11535 } else if (params.incoming && tgt === ele) {
11536 oEles.push(edge);
11537 oEles.push(src);
11538 }
11539 }
11540 }
11541 return this.spawn(oEles, true).filter(selector);
11542 };
11543 };
11544 var defineDagAllHops = function defineDagAllHops2(params) {
11545 return function(selector) {
11546 var eles = this;
11547 var sEles = [];
11548 var sElesIds = {};
11549 for (; ; ) {
11550 var next2 = params.outgoing ? eles.outgoers() : eles.incomers();
11551 if (next2.length === 0) {
11552 break;
11553 }
11554 var newNext = false;
11555 for (var i2 = 0; i2 < next2.length; i2++) {
11556 var n = next2[i2];
11557 var nid = n.id();
11558 if (!sElesIds[nid]) {
11559 sElesIds[nid] = true;
11560 sEles.push(n);
11561 newNext = true;
11562 }
11563 }
11564 if (!newNext) {
11565 break;
11566 }
11567 eles = next2;
11568 }
11569 return this.spawn(sEles, true).filter(selector);
11570 };
11571 };
11572 elesfn$2.clearTraversalCache = function() {
11573 for (var i2 = 0; i2 < this.length; i2++) {
11574 this[i2]._private.traversalCache = null;
11575 }
11576 };
11577 extend(elesfn$2, {
11578 // get the root nodes in the DAG
11579 roots: defineDagExtremity({
11580 noIncomingEdges: true
11581 }),
11582 // get the leaf nodes in the DAG
11583 leaves: defineDagExtremity({
11584 noOutgoingEdges: true
11585 }),
11586 // normally called children in graph theory
11587 // these nodes =edges=> outgoing nodes
11588 outgoers: cache(defineDagOneHop({
11589 outgoing: true
11590 }), "outgoers"),
11591 // aka DAG descendants
11592 successors: defineDagAllHops({
11593 outgoing: true
11594 }),
11595 // normally called parents in graph theory
11596 // these nodes <=edges= incoming nodes
11597 incomers: cache(defineDagOneHop({
11598 incoming: true
11599 }), "incomers"),
11600 // aka DAG ancestors
11601 predecessors: defineDagAllHops({
11602 incoming: true
11603 })
11604 });
11605 extend(elesfn$2, {
11606 neighborhood: cache(function(selector) {
11607 var elements2 = [];
11608 var nodes2 = this.nodes();
11609 for (var i2 = 0; i2 < nodes2.length; i2++) {
11610 var node = nodes2[i2];
11611 var connectedEdges = node.connectedEdges();
11612 for (var j = 0; j < connectedEdges.length; j++) {
11613 var edge = connectedEdges[j];
11614 var src = edge.source();
11615 var tgt = edge.target();
11616 var otherNode = node === src ? tgt : src;
11617 if (otherNode.length > 0) {
11618 elements2.push(otherNode[0]);
11619 }
11620 elements2.push(edge[0]);
11621 }
11622 }
11623 return this.spawn(elements2, true).filter(selector);
11624 }, "neighborhood"),
11625 closedNeighborhood: function closedNeighborhood(selector) {
11626 return this.neighborhood().add(this).filter(selector);
11627 },
11628 openNeighborhood: function openNeighborhood(selector) {
11629 return this.neighborhood(selector);
11630 }
11631 });
11632 elesfn$2.neighbourhood = elesfn$2.neighborhood;
11633 elesfn$2.closedNeighbourhood = elesfn$2.closedNeighborhood;
11634 elesfn$2.openNeighbourhood = elesfn$2.openNeighborhood;
11635 extend(elesfn$2, {
11636 source: cache(function sourceImpl(selector) {
11637 var ele = this[0];
11638 var src;
11639 if (ele) {
11640 src = ele._private.source || ele.cy().collection();
11641 }
11642 return src && selector ? src.filter(selector) : src;
11643 }, "source"),
11644 target: cache(function targetImpl(selector) {
11645 var ele = this[0];
11646 var tgt;
11647 if (ele) {
11648 tgt = ele._private.target || ele.cy().collection();
11649 }
11650 return tgt && selector ? tgt.filter(selector) : tgt;
11651 }, "target"),
11652 sources: defineSourceFunction({
11653 attr: "source"
11654 }),
11655 targets: defineSourceFunction({
11656 attr: "target"
11657 })
11658 });
11659 function defineSourceFunction(params) {
11660 return function sourceImpl(selector) {
11661 var sources = [];
11662 for (var i2 = 0; i2 < this.length; i2++) {
11663 var ele = this[i2];
11664 var src = ele._private[params.attr];
11665 if (src) {
11666 sources.push(src);
11667 }
11668 }
11669 return this.spawn(sources, true).filter(selector);
11670 };
11671 }
11672 extend(elesfn$2, {
11673 edgesWith: cache(defineEdgesWithFunction(), "edgesWith"),
11674 edgesTo: cache(defineEdgesWithFunction({
11675 thisIsSrc: true
11676 }), "edgesTo")
11677 });
11678 function defineEdgesWithFunction(params) {
11679 return function edgesWithImpl(otherNodes) {
11680 var elements2 = [];
11681 var cy = this._private.cy;
11682 var p2 = params || {};
11683 if (string(otherNodes)) {
11684 otherNodes = cy.$(otherNodes);
11685 }
11686 for (var h = 0; h < otherNodes.length; h++) {
11687 var edges = otherNodes[h]._private.edges;
11688 for (var i2 = 0; i2 < edges.length; i2++) {
11689 var edge = edges[i2];
11690 var edgeData = edge._private.data;
11691 var thisToOther = this.hasElementWithId(edgeData.source) && otherNodes.hasElementWithId(edgeData.target);
11692 var otherToThis = otherNodes.hasElementWithId(edgeData.source) && this.hasElementWithId(edgeData.target);
11693 var edgeConnectsThisAndOther = thisToOther || otherToThis;
11694 if (!edgeConnectsThisAndOther) {
11695 continue;
11696 }
11697 if (p2.thisIsSrc || p2.thisIsTgt) {
11698 if (p2.thisIsSrc && !thisToOther) {
11699 continue;
11700 }
11701 if (p2.thisIsTgt && !otherToThis) {
11702 continue;
11703 }
11704 }
11705 elements2.push(edge);
11706 }
11707 }
11708 return this.spawn(elements2, true);
11709 };
11710 }
11711 extend(elesfn$2, {
11712 connectedEdges: cache(function(selector) {
11713 var retEles = [];
11714 var eles = this;
11715 for (var i2 = 0; i2 < eles.length; i2++) {
11716 var node = eles[i2];
11717 if (!node.isNode()) {
11718 continue;
11719 }
11720 var edges = node._private.edges;
11721 for (var j = 0; j < edges.length; j++) {
11722 var edge = edges[j];
11723 retEles.push(edge);
11724 }
11725 }
11726 return this.spawn(retEles, true).filter(selector);
11727 }, "connectedEdges"),
11728 connectedNodes: cache(function(selector) {
11729 var retEles = [];
11730 var eles = this;
11731 for (var i2 = 0; i2 < eles.length; i2++) {
11732 var edge = eles[i2];
11733 if (!edge.isEdge()) {
11734 continue;
11735 }
11736 retEles.push(edge.source()[0]);
11737 retEles.push(edge.target()[0]);
11738 }
11739 return this.spawn(retEles, true).filter(selector);
11740 }, "connectedNodes"),
11741 parallelEdges: cache(defineParallelEdgesFunction(), "parallelEdges"),
11742 codirectedEdges: cache(defineParallelEdgesFunction({
11743 codirected: true
11744 }), "codirectedEdges")
11745 });
11746 function defineParallelEdgesFunction(params) {
11747 var defaults2 = {
11748 codirected: false
11749 };
11750 params = extend({}, defaults2, params);
11751 return function parallelEdgesImpl(selector) {
11752 var elements2 = [];
11753 var edges = this.edges();
11754 var p2 = params;
11755 for (var i2 = 0; i2 < edges.length; i2++) {
11756 var edge1 = edges[i2];
11757 var edge1_p = edge1._private;
11758 var src1 = edge1_p.source;
11759 var srcid1 = src1._private.data.id;
11760 var tgtid1 = edge1_p.data.target;
11761 var srcEdges1 = src1._private.edges;
11762 for (var j = 0; j < srcEdges1.length; j++) {
11763 var edge2 = srcEdges1[j];
11764 var edge2data = edge2._private.data;
11765 var tgtid2 = edge2data.target;
11766 var srcid2 = edge2data.source;
11767 var codirected = tgtid2 === tgtid1 && srcid2 === srcid1;
11768 var oppdirected = srcid1 === tgtid2 && tgtid1 === srcid2;
11769 if (p2.codirected && codirected || !p2.codirected && (codirected || oppdirected)) {
11770 elements2.push(edge2);
11771 }
11772 }
11773 }
11774 return this.spawn(elements2, true).filter(selector);
11775 };
11776 }
11777 extend(elesfn$2, {
11778 components: function components(root2) {
11779 var self2 = this;
11780 var cy = self2.cy();
11781 var visited = cy.collection();
11782 var unvisited = root2 == null ? self2.nodes() : root2.nodes();
11783 var components2 = [];
11784 if (root2 != null && unvisited.empty()) {
11785 unvisited = root2.sources();
11786 }
11787 var visitInComponent = function visitInComponent2(node, component) {
11788 visited.merge(node);
11789 unvisited.unmerge(node);
11790 component.merge(node);
11791 };
11792 if (unvisited.empty()) {
11793 return self2.spawn();
11794 }
11795 var _loop = function _loop2() {
11796 var cmpt = cy.collection();
11797 components2.push(cmpt);
11798 var root3 = unvisited[0];
11799 visitInComponent(root3, cmpt);
11800 self2.bfs({
11801 directed: false,
11802 roots: root3,
11803 visit: function visit(v) {
11804 return visitInComponent(v, cmpt);
11805 }
11806 });
11807 cmpt.forEach(function(node) {
11808 node.connectedEdges().forEach(function(e) {
11809 if (self2.has(e) && cmpt.has(e.source()) && cmpt.has(e.target())) {
11810 cmpt.merge(e);
11811 }
11812 });
11813 });
11814 };
11815 do {
11816 _loop();
11817 } while (unvisited.length > 0);
11818 return components2;
11819 },
11820 component: function component() {
11821 var ele = this[0];
11822 return ele.cy().mutableElements().components(ele)[0];
11823 }
11824 });
11825 elesfn$2.componentsOf = elesfn$2.components;
11826 var Collection = function Collection2(cy, elements2) {
11827 var unique = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
11828 var removed = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
11829 if (cy === void 0) {
11830 error("A collection must have a reference to the core");
11831 return;
11832 }
11833 var map = new Map$2();
11834 var createdElements = false;
11835 if (!elements2) {
11836 elements2 = [];
11837 } else if (elements2.length > 0 && plainObject(elements2[0]) && !element(elements2[0])) {
11838 createdElements = true;
11839 var eles = [];
11840 var elesIds = new Set$1();
11841 for (var i2 = 0, l = elements2.length; i2 < l; i2++) {
11842 var json = elements2[i2];
11843 if (json.data == null) {
11844 json.data = {};
11845 }
11846 var _data = json.data;
11847 if (_data.id == null) {
11848 _data.id = uuid();
11849 } else if (cy.hasElementWithId(_data.id) || elesIds.has(_data.id)) {
11850 continue;
11851 }
11852 var ele = new Element(cy, json, false);
11853 eles.push(ele);
11854 elesIds.add(_data.id);
11855 }
11856 elements2 = eles;
11857 }
11858 this.length = 0;
11859 for (var _i = 0, _l = elements2.length; _i < _l; _i++) {
11860 var element$1 = elements2[_i][0];
11861 if (element$1 == null) {
11862 continue;
11863 }
11864 var id = element$1._private.data.id;
11865 if (!unique || !map.has(id)) {
11866 if (unique) {
11867 map.set(id, {
11868 index: this.length,
11869 ele: element$1
11870 });
11871 }
11872 this[this.length] = element$1;
11873 this.length++;
11874 }
11875 }
11876 this._private = {
11877 eles: this,
11878 cy,
11879 get map() {
11880 if (this.lazyMap == null) {
11881 this.rebuildMap();
11882 }
11883 return this.lazyMap;
11884 },
11885 set map(m) {
11886 this.lazyMap = m;
11887 },
11888 rebuildMap: function rebuildMap() {
11889 var m = this.lazyMap = new Map$2();
11890 var eles2 = this.eles;
11891 for (var _i2 = 0; _i2 < eles2.length; _i2++) {
11892 var _ele = eles2[_i2];
11893 m.set(_ele.id(), {
11894 index: _i2,
11895 ele: _ele
11896 });
11897 }
11898 }
11899 };
11900 if (unique) {
11901 this._private.map = map;
11902 }
11903 if (createdElements && !removed) {
11904 this.restore();
11905 }
11906 };
11907 var elesfn$1 = Element.prototype = Collection.prototype = Object.create(Array.prototype);
11908 elesfn$1.instanceString = function() {
11909 return "collection";
11910 };
11911 elesfn$1.spawn = function(eles, unique) {
11912 return new Collection(this.cy(), eles, unique);
11913 };
11914 elesfn$1.spawnSelf = function() {
11915 return this.spawn(this);
11916 };
11917 elesfn$1.cy = function() {
11918 return this._private.cy;
11919 };
11920 elesfn$1.renderer = function() {
11921 return this._private.cy.renderer();
11922 };
11923 elesfn$1.element = function() {
11924 return this[0];
11925 };
11926 elesfn$1.collection = function() {
11927 if (collection(this)) {
11928 return this;
11929 } else {
11930 return new Collection(this._private.cy, [this]);
11931 }
11932 };
11933 elesfn$1.unique = function() {
11934 return new Collection(this._private.cy, this, true);
11935 };
11936 elesfn$1.hasElementWithId = function(id) {
11937 id = "" + id;
11938 return this._private.map.has(id);
11939 };
11940 elesfn$1.getElementById = function(id) {
11941 id = "" + id;
11942 var cy = this._private.cy;
11943 var entry = this._private.map.get(id);
11944 return entry ? entry.ele : new Collection(cy);
11945 };
11946 elesfn$1.$id = elesfn$1.getElementById;
11947 elesfn$1.poolIndex = function() {
11948 var cy = this._private.cy;
11949 var eles = cy._private.elements;
11950 var id = this[0]._private.data.id;
11951 return eles._private.map.get(id).index;
11952 };
11953 elesfn$1.indexOf = function(ele) {
11954 var id = ele[0]._private.data.id;
11955 return this._private.map.get(id).index;
11956 };
11957 elesfn$1.indexOfId = function(id) {
11958 id = "" + id;
11959 return this._private.map.get(id).index;
11960 };
11961 elesfn$1.json = function(obj) {
11962 var ele = this.element();
11963 var cy = this.cy();
11964 if (ele == null && obj) {
11965 return this;
11966 }
11967 if (ele == null) {
11968 return void 0;
11969 }
11970 var p2 = ele._private;
11971 if (plainObject(obj)) {
11972 cy.startBatch();
11973 if (obj.data) {
11974 ele.data(obj.data);
11975 var _data2 = p2.data;
11976 if (ele.isEdge()) {
11977 var move = false;
11978 var spec = {};
11979 var src = obj.data.source;
11980 var tgt = obj.data.target;
11981 if (src != null && src != _data2.source) {
11982 spec.source = "" + src;
11983 move = true;
11984 }
11985 if (tgt != null && tgt != _data2.target) {
11986 spec.target = "" + tgt;
11987 move = true;
11988 }
11989 if (move) {
11990 ele = ele.move(spec);
11991 }
11992 } else {
11993 var newParentValSpecd = "parent" in obj.data;
11994 var parent = obj.data.parent;
11995 if (newParentValSpecd && (parent != null || _data2.parent != null) && parent != _data2.parent) {
11996 if (parent === void 0) {
11997 parent = null;
11998 }
11999 if (parent != null) {
12000 parent = "" + parent;
12001 }
12002 ele = ele.move({
12003 parent
12004 });
12005 }
12006 }
12007 }
12008 if (obj.position) {
12009 ele.position(obj.position);
12010 }
12011 var checkSwitch = function checkSwitch2(k, trueFnName, falseFnName) {
12012 var obj_k = obj[k];
12013 if (obj_k != null && obj_k !== p2[k]) {
12014 if (obj_k) {
12015 ele[trueFnName]();
12016 } else {
12017 ele[falseFnName]();
12018 }
12019 }
12020 };
12021 checkSwitch("removed", "remove", "restore");
12022 checkSwitch("selected", "select", "unselect");
12023 checkSwitch("selectable", "selectify", "unselectify");
12024 checkSwitch("locked", "lock", "unlock");
12025 checkSwitch("grabbable", "grabify", "ungrabify");
12026 checkSwitch("pannable", "panify", "unpanify");
12027 if (obj.classes != null) {
12028 ele.classes(obj.classes);
12029 }
12030 cy.endBatch();
12031 return this;
12032 } else if (obj === void 0) {
12033 var json = {
12034 data: copy(p2.data),
12035 position: copy(p2.position),
12036 group: p2.group,
12037 removed: p2.removed,
12038 selected: p2.selected,
12039 selectable: p2.selectable,
12040 locked: p2.locked,
12041 grabbable: p2.grabbable,
12042 pannable: p2.pannable,
12043 classes: null
12044 };
12045 json.classes = "";
12046 var i2 = 0;
12047 p2.classes.forEach(function(cls) {
12048 return json.classes += i2++ === 0 ? cls : " " + cls;
12049 });
12050 return json;
12051 }
12052 };
12053 elesfn$1.jsons = function() {
12054 var jsons = [];
12055 for (var i2 = 0; i2 < this.length; i2++) {
12056 var ele = this[i2];
12057 var json = ele.json();
12058 jsons.push(json);
12059 }
12060 return jsons;
12061 };
12062 elesfn$1.clone = function() {
12063 var cy = this.cy();
12064 var elesArr = [];
12065 for (var i2 = 0; i2 < this.length; i2++) {
12066 var ele = this[i2];
12067 var json = ele.json();
12068 var clone2 = new Element(cy, json, false);
12069 elesArr.push(clone2);
12070 }
12071 return new Collection(cy, elesArr);
12072 };
12073 elesfn$1.copy = elesfn$1.clone;
12074 elesfn$1.restore = function() {
12075 var notifyRenderer = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
12076 var addToPool = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
12077 var self2 = this;
12078 var cy = self2.cy();
12079 var cy_p = cy._private;
12080 var nodes2 = [];
12081 var edges = [];
12082 var elements2;
12083 for (var _i3 = 0, l = self2.length; _i3 < l; _i3++) {
12084 var ele = self2[_i3];
12085 if (addToPool && !ele.removed()) {
12086 continue;
12087 }
12088 if (ele.isNode()) {
12089 nodes2.push(ele);
12090 } else {
12091 edges.push(ele);
12092 }
12093 }
12094 elements2 = nodes2.concat(edges);
12095 var i2;
12096 var removeFromElements = function removeFromElements2() {
12097 elements2.splice(i2, 1);
12098 i2--;
12099 };
12100 for (i2 = 0; i2 < elements2.length; i2++) {
12101 var _ele2 = elements2[i2];
12102 var _private = _ele2._private;
12103 var _data3 = _private.data;
12104 _ele2.clearTraversalCache();
12105 if (!addToPool && !_private.removed)
12106 ;
12107 else if (_data3.id === void 0) {
12108 _data3.id = uuid();
12109 } else if (number$1(_data3.id)) {
12110 _data3.id = "" + _data3.id;
12111 } else if (emptyString(_data3.id) || !string(_data3.id)) {
12112 error("Can not create element with invalid string ID `" + _data3.id + "`");
12113 removeFromElements();
12114 continue;
12115 } else if (cy.hasElementWithId(_data3.id)) {
12116 error("Can not create second element with ID `" + _data3.id + "`");
12117 removeFromElements();
12118 continue;
12119 }
12120 var id = _data3.id;
12121 if (_ele2.isNode()) {
12122 var pos = _private.position;
12123 if (pos.x == null) {
12124 pos.x = 0;
12125 }
12126 if (pos.y == null) {
12127 pos.y = 0;
12128 }
12129 }
12130 if (_ele2.isEdge()) {
12131 var edge = _ele2;
12132 var fields = ["source", "target"];
12133 var fieldsLength = fields.length;
12134 var badSourceOrTarget = false;
12135 for (var j = 0; j < fieldsLength; j++) {
12136 var field = fields[j];
12137 var val = _data3[field];
12138 if (number$1(val)) {
12139 val = _data3[field] = "" + _data3[field];
12140 }
12141 if (val == null || val === "") {
12142 error("Can not create edge `" + id + "` with unspecified " + field);
12143 badSourceOrTarget = true;
12144 } else if (!cy.hasElementWithId(val)) {
12145 error("Can not create edge `" + id + "` with nonexistant " + field + " `" + val + "`");
12146 badSourceOrTarget = true;
12147 }
12148 }
12149 if (badSourceOrTarget) {
12150 removeFromElements();
12151 continue;
12152 }
12153 var src = cy.getElementById(_data3.source);
12154 var tgt = cy.getElementById(_data3.target);
12155 if (src.same(tgt)) {
12156 src._private.edges.push(edge);
12157 } else {
12158 src._private.edges.push(edge);
12159 tgt._private.edges.push(edge);
12160 }
12161 edge._private.source = src;
12162 edge._private.target = tgt;
12163 }
12164 _private.map = new Map$2();
12165 _private.map.set(id, {
12166 ele: _ele2,
12167 index: 0
12168 });
12169 _private.removed = false;
12170 if (addToPool) {
12171 cy.addToPool(_ele2);
12172 }
12173 }
12174 for (var _i4 = 0; _i4 < nodes2.length; _i4++) {
12175 var node = nodes2[_i4];
12176 var _data4 = node._private.data;
12177 if (number$1(_data4.parent)) {
12178 _data4.parent = "" + _data4.parent;
12179 }
12180 var parentId = _data4.parent;
12181 var specifiedParent = parentId != null;
12182 if (specifiedParent || node._private.parent) {
12183 var parent = node._private.parent ? cy.collection().merge(node._private.parent) : cy.getElementById(parentId);
12184 if (parent.empty()) {
12185 _data4.parent = void 0;
12186 } else if (parent[0].removed()) {
12187 warn("Node added with missing parent, reference to parent removed");
12188 _data4.parent = void 0;
12189 node._private.parent = null;
12190 } else {
12191 var selfAsParent = false;
12192 var ancestor = parent;
12193 while (!ancestor.empty()) {
12194 if (node.same(ancestor)) {
12195 selfAsParent = true;
12196 _data4.parent = void 0;
12197 break;
12198 }
12199 ancestor = ancestor.parent();
12200 }
12201 if (!selfAsParent) {
12202 parent[0]._private.children.push(node);
12203 node._private.parent = parent[0];
12204 cy_p.hasCompoundNodes = true;
12205 }
12206 }
12207 }
12208 }
12209 if (elements2.length > 0) {
12210 var restored = elements2.length === self2.length ? self2 : new Collection(cy, elements2);
12211 for (var _i5 = 0; _i5 < restored.length; _i5++) {
12212 var _ele3 = restored[_i5];
12213 if (_ele3.isNode()) {
12214 continue;
12215 }
12216 _ele3.parallelEdges().clearTraversalCache();
12217 _ele3.source().clearTraversalCache();
12218 _ele3.target().clearTraversalCache();
12219 }
12220 var toUpdateStyle;
12221 if (cy_p.hasCompoundNodes) {
12222 toUpdateStyle = cy.collection().merge(restored).merge(restored.connectedNodes()).merge(restored.parent());
12223 } else {
12224 toUpdateStyle = restored;
12225 }
12226 toUpdateStyle.dirtyCompoundBoundsCache().dirtyBoundingBoxCache().updateStyle(notifyRenderer);
12227 if (notifyRenderer) {
12228 restored.emitAndNotify("add");
12229 } else if (addToPool) {
12230 restored.emit("add");
12231 }
12232 }
12233 return self2;
12234 };
12235 elesfn$1.removed = function() {
12236 var ele = this[0];
12237 return ele && ele._private.removed;
12238 };
12239 elesfn$1.inside = function() {
12240 var ele = this[0];
12241 return ele && !ele._private.removed;
12242 };
12243 elesfn$1.remove = function() {
12244 var notifyRenderer = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
12245 var removeFromPool = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
12246 var self2 = this;
12247 var elesToRemove = [];
12248 var elesToRemoveIds = {};
12249 var cy = self2._private.cy;
12250 function addConnectedEdges(node) {
12251 var edges = node._private.edges;
12252 for (var i3 = 0; i3 < edges.length; i3++) {
12253 add(edges[i3]);
12254 }
12255 }
12256 function addChildren2(node) {
12257 var children = node._private.children;
12258 for (var i3 = 0; i3 < children.length; i3++) {
12259 add(children[i3]);
12260 }
12261 }
12262 function add(ele2) {
12263 var alreadyAdded = elesToRemoveIds[ele2.id()];
12264 if (removeFromPool && ele2.removed() || alreadyAdded) {
12265 return;
12266 } else {
12267 elesToRemoveIds[ele2.id()] = true;
12268 }
12269 if (ele2.isNode()) {
12270 elesToRemove.push(ele2);
12271 addConnectedEdges(ele2);
12272 addChildren2(ele2);
12273 } else {
12274 elesToRemove.unshift(ele2);
12275 }
12276 }
12277 for (var i2 = 0, l = self2.length; i2 < l; i2++) {
12278 var ele = self2[i2];
12279 add(ele);
12280 }
12281 function removeEdgeRef(node, edge) {
12282 var connectedEdges = node._private.edges;
12283 removeFromArray(connectedEdges, edge);
12284 node.clearTraversalCache();
12285 }
12286 function removeParallelRef(pllEdge2) {
12287 pllEdge2.clearTraversalCache();
12288 }
12289 var alteredParents = [];
12290 alteredParents.ids = {};
12291 function removeChildRef(parent2, ele2) {
12292 ele2 = ele2[0];
12293 parent2 = parent2[0];
12294 var children = parent2._private.children;
12295 var pid = parent2.id();
12296 removeFromArray(children, ele2);
12297 ele2._private.parent = null;
12298 if (!alteredParents.ids[pid]) {
12299 alteredParents.ids[pid] = true;
12300 alteredParents.push(parent2);
12301 }
12302 }
12303 self2.dirtyCompoundBoundsCache();
12304 if (removeFromPool) {
12305 cy.removeFromPool(elesToRemove);
12306 }
12307 for (var _i6 = 0; _i6 < elesToRemove.length; _i6++) {
12308 var _ele4 = elesToRemove[_i6];
12309 if (_ele4.isEdge()) {
12310 var src = _ele4.source()[0];
12311 var tgt = _ele4.target()[0];
12312 removeEdgeRef(src, _ele4);
12313 removeEdgeRef(tgt, _ele4);
12314 var pllEdges = _ele4.parallelEdges();
12315 for (var j = 0; j < pllEdges.length; j++) {
12316 var pllEdge = pllEdges[j];
12317 removeParallelRef(pllEdge);
12318 if (pllEdge.isBundledBezier()) {
12319 pllEdge.dirtyBoundingBoxCache();
12320 }
12321 }
12322 } else {
12323 var parent = _ele4.parent();
12324 if (parent.length !== 0) {
12325 removeChildRef(parent, _ele4);
12326 }
12327 }
12328 if (removeFromPool) {
12329 _ele4._private.removed = true;
12330 }
12331 }
12332 var elesStillInside = cy._private.elements;
12333 cy._private.hasCompoundNodes = false;
12334 for (var _i7 = 0; _i7 < elesStillInside.length; _i7++) {
12335 var _ele5 = elesStillInside[_i7];
12336 if (_ele5.isParent()) {
12337 cy._private.hasCompoundNodes = true;
12338 break;
12339 }
12340 }
12341 var removedElements = new Collection(this.cy(), elesToRemove);
12342 if (removedElements.size() > 0) {
12343 if (notifyRenderer) {
12344 removedElements.emitAndNotify("remove");
12345 } else if (removeFromPool) {
12346 removedElements.emit("remove");
12347 }
12348 }
12349 for (var _i8 = 0; _i8 < alteredParents.length; _i8++) {
12350 var _ele6 = alteredParents[_i8];
12351 if (!removeFromPool || !_ele6.removed()) {
12352 _ele6.updateStyle();
12353 }
12354 }
12355 return removedElements;
12356 };
12357 elesfn$1.move = function(struct) {
12358 var cy = this._private.cy;
12359 var eles = this;
12360 var notifyRenderer = false;
12361 var modifyPool = false;
12362 var toString2 = function toString3(id) {
12363 return id == null ? id : "" + id;
12364 };
12365 if (struct.source !== void 0 || struct.target !== void 0) {
12366 var srcId = toString2(struct.source);
12367 var tgtId = toString2(struct.target);
12368 var srcExists = srcId != null && cy.hasElementWithId(srcId);
12369 var tgtExists = tgtId != null && cy.hasElementWithId(tgtId);
12370 if (srcExists || tgtExists) {
12371 cy.batch(function() {
12372 eles.remove(notifyRenderer, modifyPool);
12373 eles.emitAndNotify("moveout");
12374 for (var i2 = 0; i2 < eles.length; i2++) {
12375 var ele = eles[i2];
12376 var _data5 = ele._private.data;
12377 if (ele.isEdge()) {
12378 if (srcExists) {
12379 _data5.source = srcId;
12380 }
12381 if (tgtExists) {
12382 _data5.target = tgtId;
12383 }
12384 }
12385 }
12386 eles.restore(notifyRenderer, modifyPool);
12387 });
12388 eles.emitAndNotify("move");
12389 }
12390 } else if (struct.parent !== void 0) {
12391 var parentId = toString2(struct.parent);
12392 var parentExists = parentId === null || cy.hasElementWithId(parentId);
12393 if (parentExists) {
12394 var pidToAssign = parentId === null ? void 0 : parentId;
12395 cy.batch(function() {
12396 var updated = eles.remove(notifyRenderer, modifyPool);
12397 updated.emitAndNotify("moveout");
12398 for (var i2 = 0; i2 < eles.length; i2++) {
12399 var ele = eles[i2];
12400 var _data6 = ele._private.data;
12401 if (ele.isNode()) {
12402 _data6.parent = pidToAssign;
12403 }
12404 }
12405 updated.restore(notifyRenderer, modifyPool);
12406 });
12407 eles.emitAndNotify("move");
12408 }
12409 }
12410 return this;
12411 };
12412 [elesfn$j, elesfn$i, elesfn$h, elesfn$g, elesfn$f, data, elesfn$d, dimensions, elesfn$9, elesfn$8, elesfn$7, elesfn$6, elesfn$5, elesfn$4, elesfn$3, elesfn$2].forEach(function(props) {
12413 extend(elesfn$1, props);
12414 });
12415 var corefn$9 = {
12416 add: function add(opts) {
12417 var elements2;
12418 var cy = this;
12419 if (elementOrCollection(opts)) {
12420 var eles = opts;
12421 if (eles._private.cy === cy) {
12422 elements2 = eles.restore();
12423 } else {
12424 var jsons = [];
12425 for (var i2 = 0; i2 < eles.length; i2++) {
12426 var ele = eles[i2];
12427 jsons.push(ele.json());
12428 }
12429 elements2 = new Collection(cy, jsons);
12430 }
12431 } else if (array(opts)) {
12432 var _jsons = opts;
12433 elements2 = new Collection(cy, _jsons);
12434 } else if (plainObject(opts) && (array(opts.nodes) || array(opts.edges))) {
12435 var elesByGroup = opts;
12436 var _jsons2 = [];
12437 var grs = ["nodes", "edges"];
12438 for (var _i = 0, il = grs.length; _i < il; _i++) {
12439 var group = grs[_i];
12440 var elesArray = elesByGroup[group];
12441 if (array(elesArray)) {
12442 for (var j = 0, jl = elesArray.length; j < jl; j++) {
12443 var json = extend({
12444 group
12445 }, elesArray[j]);
12446 _jsons2.push(json);
12447 }
12448 }
12449 }
12450 elements2 = new Collection(cy, _jsons2);
12451 } else {
12452 var _json = opts;
12453 elements2 = new Element(cy, _json).collection();
12454 }
12455 return elements2;
12456 },
12457 remove: function remove(collection2) {
12458 if (elementOrCollection(collection2))
12459 ;
12460 else if (string(collection2)) {
12461 var selector = collection2;
12462 collection2 = this.$(selector);
12463 }
12464 return collection2.remove();
12465 }
12466 };
12467 /*! Bezier curve function generator. Copyright Gaetan Renaudeau. MIT License: http://en.wikipedia.org/wiki/MIT_License */
12468 function generateCubicBezier(mX1, mY1, mX2, mY2) {
12469 var NEWTON_ITERATIONS = 4, NEWTON_MIN_SLOPE = 1e-3, SUBDIVISION_PRECISION = 1e-7, SUBDIVISION_MAX_ITERATIONS = 10, kSplineTableSize = 11, kSampleStepSize = 1 / (kSplineTableSize - 1), float32ArraySupported = typeof Float32Array !== "undefined";
12470 if (arguments.length !== 4) {
12471 return false;
12472 }
12473 for (var i2 = 0; i2 < 4; ++i2) {
12474 if (typeof arguments[i2] !== "number" || isNaN(arguments[i2]) || !isFinite(arguments[i2])) {
12475 return false;
12476 }
12477 }
12478 mX1 = Math.min(mX1, 1);
12479 mX2 = Math.min(mX2, 1);
12480 mX1 = Math.max(mX1, 0);
12481 mX2 = Math.max(mX2, 0);
12482 var mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
12483 function A(aA1, aA2) {
12484 return 1 - 3 * aA2 + 3 * aA1;
12485 }
12486 function B(aA1, aA2) {
12487 return 3 * aA2 - 6 * aA1;
12488 }
12489 function C(aA1) {
12490 return 3 * aA1;
12491 }
12492 function calcBezier(aT, aA1, aA2) {
12493 return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
12494 }
12495 function getSlope(aT, aA1, aA2) {
12496 return 3 * A(aA1, aA2) * aT * aT + 2 * B(aA1, aA2) * aT + C(aA1);
12497 }
12498 function newtonRaphsonIterate(aX, aGuessT) {
12499 for (var _i = 0; _i < NEWTON_ITERATIONS; ++_i) {
12500 var currentSlope = getSlope(aGuessT, mX1, mX2);
12501 if (currentSlope === 0) {
12502 return aGuessT;
12503 }
12504 var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
12505 aGuessT -= currentX / currentSlope;
12506 }
12507 return aGuessT;
12508 }
12509 function calcSampleValues() {
12510 for (var _i2 = 0; _i2 < kSplineTableSize; ++_i2) {
12511 mSampleValues[_i2] = calcBezier(_i2 * kSampleStepSize, mX1, mX2);
12512 }
12513 }
12514 function binarySubdivide(aX, aA, aB) {
12515 var currentX, currentT, i3 = 0;
12516 do {
12517 currentT = aA + (aB - aA) / 2;
12518 currentX = calcBezier(currentT, mX1, mX2) - aX;
12519 if (currentX > 0) {
12520 aB = currentT;
12521 } else {
12522 aA = currentT;
12523 }
12524 } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i3 < SUBDIVISION_MAX_ITERATIONS);
12525 return currentT;
12526 }
12527 function getTForX(aX) {
12528 var intervalStart = 0, currentSample = 1, lastSample = kSplineTableSize - 1;
12529 for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
12530 intervalStart += kSampleStepSize;
12531 }
12532 --currentSample;
12533 var dist2 = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]), guessForT = intervalStart + dist2 * kSampleStepSize, initialSlope = getSlope(guessForT, mX1, mX2);
12534 if (initialSlope >= NEWTON_MIN_SLOPE) {
12535 return newtonRaphsonIterate(aX, guessForT);
12536 } else if (initialSlope === 0) {
12537 return guessForT;
12538 } else {
12539 return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize);
12540 }
12541 }
12542 var _precomputed = false;
12543 function precompute() {
12544 _precomputed = true;
12545 if (mX1 !== mY1 || mX2 !== mY2) {
12546 calcSampleValues();
12547 }
12548 }
12549 var f = function f2(aX) {
12550 if (!_precomputed) {
12551 precompute();
12552 }
12553 if (mX1 === mY1 && mX2 === mY2) {
12554 return aX;
12555 }
12556 if (aX === 0) {
12557 return 0;
12558 }
12559 if (aX === 1) {
12560 return 1;
12561 }
12562 return calcBezier(getTForX(aX), mY1, mY2);
12563 };
12564 f.getControlPoints = function() {
12565 return [{
12566 x: mX1,
12567 y: mY1
12568 }, {
12569 x: mX2,
12570 y: mY2
12571 }];
12572 };
12573 var str = "generateBezier(" + [mX1, mY1, mX2, mY2] + ")";
12574 f.toString = function() {
12575 return str;
12576 };
12577 return f;
12578 }
12579 /*! Runge-Kutta spring physics function generator. Adapted from Framer.js, copyright Koen Bok. MIT License: http://en.wikipedia.org/wiki/MIT_License */
12580 var generateSpringRK4 = function() {
12581 function springAccelerationForState(state) {
12582 return -state.tension * state.x - state.friction * state.v;
12583 }
12584 function springEvaluateStateWithDerivative(initialState, dt, derivative) {
12585 var state = {
12586 x: initialState.x + derivative.dx * dt,
12587 v: initialState.v + derivative.dv * dt,
12588 tension: initialState.tension,
12589 friction: initialState.friction
12590 };
12591 return {
12592 dx: state.v,
12593 dv: springAccelerationForState(state)
12594 };
12595 }
12596 function springIntegrateState(state, dt) {
12597 var a = {
12598 dx: state.v,
12599 dv: springAccelerationForState(state)
12600 }, b = springEvaluateStateWithDerivative(state, dt * 0.5, a), c = springEvaluateStateWithDerivative(state, dt * 0.5, b), d = springEvaluateStateWithDerivative(state, dt, c), dxdt = 1 / 6 * (a.dx + 2 * (b.dx + c.dx) + d.dx), dvdt = 1 / 6 * (a.dv + 2 * (b.dv + c.dv) + d.dv);
12601 state.x = state.x + dxdt * dt;
12602 state.v = state.v + dvdt * dt;
12603 return state;
12604 }
12605 return function springRK4Factory(tension, friction, duration) {
12606 var initState = {
12607 x: -1,
12608 v: 0,
12609 tension: null,
12610 friction: null
12611 }, path = [0], time_lapsed = 0, tolerance = 1 / 1e4, DT = 16 / 1e3, have_duration, dt, last_state;
12612 tension = parseFloat(tension) || 500;
12613 friction = parseFloat(friction) || 20;
12614 duration = duration || null;
12615 initState.tension = tension;
12616 initState.friction = friction;
12617 have_duration = duration !== null;
12618 if (have_duration) {
12619 time_lapsed = springRK4Factory(tension, friction);
12620 dt = time_lapsed / duration * DT;
12621 } else {
12622 dt = DT;
12623 }
12624 for (; ; ) {
12625 last_state = springIntegrateState(last_state || initState, dt);
12626 path.push(1 + last_state.x);
12627 time_lapsed += 16;
12628 if (!(Math.abs(last_state.x) > tolerance && Math.abs(last_state.v) > tolerance)) {
12629 break;
12630 }
12631 }
12632 return !have_duration ? time_lapsed : function(percentComplete) {
12633 return path[percentComplete * (path.length - 1) | 0];
12634 };
12635 };
12636 }();
12637 var cubicBezier = function cubicBezier2(t1, p1, t2, p2) {
12638 var bezier = generateCubicBezier(t1, p1, t2, p2);
12639 return function(start, end, percent) {
12640 return start + (end - start) * bezier(percent);
12641 };
12642 };
12643 var easings = {
12644 "linear": function linear(start, end, percent) {
12645 return start + (end - start) * percent;
12646 },
12647 // default easings
12648 "ease": cubicBezier(0.25, 0.1, 0.25, 1),
12649 "ease-in": cubicBezier(0.42, 0, 1, 1),
12650 "ease-out": cubicBezier(0, 0, 0.58, 1),
12651 "ease-in-out": cubicBezier(0.42, 0, 0.58, 1),
12652 // sine
12653 "ease-in-sine": cubicBezier(0.47, 0, 0.745, 0.715),
12654 "ease-out-sine": cubicBezier(0.39, 0.575, 0.565, 1),
12655 "ease-in-out-sine": cubicBezier(0.445, 0.05, 0.55, 0.95),
12656 // quad
12657 "ease-in-quad": cubicBezier(0.55, 0.085, 0.68, 0.53),
12658 "ease-out-quad": cubicBezier(0.25, 0.46, 0.45, 0.94),
12659 "ease-in-out-quad": cubicBezier(0.455, 0.03, 0.515, 0.955),
12660 // cubic
12661 "ease-in-cubic": cubicBezier(0.55, 0.055, 0.675, 0.19),
12662 "ease-out-cubic": cubicBezier(0.215, 0.61, 0.355, 1),
12663 "ease-in-out-cubic": cubicBezier(0.645, 0.045, 0.355, 1),
12664 // quart
12665 "ease-in-quart": cubicBezier(0.895, 0.03, 0.685, 0.22),
12666 "ease-out-quart": cubicBezier(0.165, 0.84, 0.44, 1),
12667 "ease-in-out-quart": cubicBezier(0.77, 0, 0.175, 1),
12668 // quint
12669 "ease-in-quint": cubicBezier(0.755, 0.05, 0.855, 0.06),
12670 "ease-out-quint": cubicBezier(0.23, 1, 0.32, 1),
12671 "ease-in-out-quint": cubicBezier(0.86, 0, 0.07, 1),
12672 // expo
12673 "ease-in-expo": cubicBezier(0.95, 0.05, 0.795, 0.035),
12674 "ease-out-expo": cubicBezier(0.19, 1, 0.22, 1),
12675 "ease-in-out-expo": cubicBezier(1, 0, 0, 1),
12676 // circ
12677 "ease-in-circ": cubicBezier(0.6, 0.04, 0.98, 0.335),
12678 "ease-out-circ": cubicBezier(0.075, 0.82, 0.165, 1),
12679 "ease-in-out-circ": cubicBezier(0.785, 0.135, 0.15, 0.86),
12680 // user param easings...
12681 "spring": function spring(tension, friction, duration) {
12682 if (duration === 0) {
12683 return easings.linear;
12684 }
12685 var spring2 = generateSpringRK4(tension, friction, duration);
12686 return function(start, end, percent) {
12687 return start + (end - start) * spring2(percent);
12688 };
12689 },
12690 "cubic-bezier": cubicBezier
12691 };
12692 function getEasedValue(type, start, end, percent, easingFn) {
12693 if (percent === 1) {
12694 return end;
12695 }
12696 if (start === end) {
12697 return end;
12698 }
12699 var val = easingFn(start, end, percent);
12700 if (type == null) {
12701 return val;
12702 }
12703 if (type.roundValue || type.color) {
12704 val = Math.round(val);
12705 }
12706 if (type.min !== void 0) {
12707 val = Math.max(val, type.min);
12708 }
12709 if (type.max !== void 0) {
12710 val = Math.min(val, type.max);
12711 }
12712 return val;
12713 }
12714 function getValue(prop, spec) {
12715 if (prop.pfValue != null || prop.value != null) {
12716 if (prop.pfValue != null && (spec == null || spec.type.units !== "%")) {
12717 return prop.pfValue;
12718 } else {
12719 return prop.value;
12720 }
12721 } else {
12722 return prop;
12723 }
12724 }
12725 function ease(startProp, endProp, percent, easingFn, propSpec) {
12726 var type = propSpec != null ? propSpec.type : null;
12727 if (percent < 0) {
12728 percent = 0;
12729 } else if (percent > 1) {
12730 percent = 1;
12731 }
12732 var start = getValue(startProp, propSpec);
12733 var end = getValue(endProp, propSpec);
12734 if (number$1(start) && number$1(end)) {
12735 return getEasedValue(type, start, end, percent, easingFn);
12736 } else if (array(start) && array(end)) {
12737 var easedArr = [];
12738 for (var i2 = 0; i2 < end.length; i2++) {
12739 var si = start[i2];
12740 var ei = end[i2];
12741 if (si != null && ei != null) {
12742 var val = getEasedValue(type, si, ei, percent, easingFn);
12743 easedArr.push(val);
12744 } else {
12745 easedArr.push(ei);
12746 }
12747 }
12748 return easedArr;
12749 }
12750 return void 0;
12751 }
12752 function step$1(self2, ani, now2, isCore) {
12753 var isEles = !isCore;
12754 var _p = self2._private;
12755 var ani_p = ani._private;
12756 var pEasing = ani_p.easing;
12757 var startTime = ani_p.startTime;
12758 var cy = isCore ? self2 : self2.cy();
12759 var style = cy.style();
12760 if (!ani_p.easingImpl) {
12761 if (pEasing == null) {
12762 ani_p.easingImpl = easings["linear"];
12763 } else {
12764 var easingVals;
12765 if (string(pEasing)) {
12766 var easingProp = style.parse("transition-timing-function", pEasing);
12767 easingVals = easingProp.value;
12768 } else {
12769 easingVals = pEasing;
12770 }
12771 var name2, args;
12772 if (string(easingVals)) {
12773 name2 = easingVals;
12774 args = [];
12775 } else {
12776 name2 = easingVals[1];
12777 args = easingVals.slice(2).map(function(n) {
12778 return +n;
12779 });
12780 }
12781 if (args.length > 0) {
12782 if (name2 === "spring") {
12783 args.push(ani_p.duration);
12784 }
12785 ani_p.easingImpl = easings[name2].apply(null, args);
12786 } else {
12787 ani_p.easingImpl = easings[name2];
12788 }
12789 }
12790 }
12791 var easing = ani_p.easingImpl;
12792 var percent;
12793 if (ani_p.duration === 0) {
12794 percent = 1;
12795 } else {
12796 percent = (now2 - startTime) / ani_p.duration;
12797 }
12798 if (ani_p.applying) {
12799 percent = ani_p.progress;
12800 }
12801 if (percent < 0) {
12802 percent = 0;
12803 } else if (percent > 1) {
12804 percent = 1;
12805 }
12806 if (ani_p.delay == null) {
12807 var startPos = ani_p.startPosition;
12808 var endPos = ani_p.position;
12809 if (endPos && isEles && !self2.locked()) {
12810 var newPos = {};
12811 if (valid(startPos.x, endPos.x)) {
12812 newPos.x = ease(startPos.x, endPos.x, percent, easing);
12813 }
12814 if (valid(startPos.y, endPos.y)) {
12815 newPos.y = ease(startPos.y, endPos.y, percent, easing);
12816 }
12817 self2.position(newPos);
12818 }
12819 var startPan = ani_p.startPan;
12820 var endPan = ani_p.pan;
12821 var pan = _p.pan;
12822 var animatingPan = endPan != null && isCore;
12823 if (animatingPan) {
12824 if (valid(startPan.x, endPan.x)) {
12825 pan.x = ease(startPan.x, endPan.x, percent, easing);
12826 }
12827 if (valid(startPan.y, endPan.y)) {
12828 pan.y = ease(startPan.y, endPan.y, percent, easing);
12829 }
12830 self2.emit("pan");
12831 }
12832 var startZoom = ani_p.startZoom;
12833 var endZoom = ani_p.zoom;
12834 var animatingZoom = endZoom != null && isCore;
12835 if (animatingZoom) {
12836 if (valid(startZoom, endZoom)) {
12837 _p.zoom = bound(_p.minZoom, ease(startZoom, endZoom, percent, easing), _p.maxZoom);
12838 }
12839 self2.emit("zoom");
12840 }
12841 if (animatingPan || animatingZoom) {
12842 self2.emit("viewport");
12843 }
12844 var props = ani_p.style;
12845 if (props && props.length > 0 && isEles) {
12846 for (var i2 = 0; i2 < props.length; i2++) {
12847 var prop = props[i2];
12848 var _name = prop.name;
12849 var end = prop;
12850 var start = ani_p.startStyle[_name];
12851 var propSpec = style.properties[start.name];
12852 var easedVal = ease(start, end, percent, easing, propSpec);
12853 style.overrideBypass(self2, _name, easedVal);
12854 }
12855 self2.emit("style");
12856 }
12857 }
12858 ani_p.progress = percent;
12859 return percent;
12860 }
12861 function valid(start, end) {
12862 if (start == null || end == null) {
12863 return false;
12864 }
12865 if (number$1(start) && number$1(end)) {
12866 return true;
12867 } else if (start && end) {
12868 return true;
12869 }
12870 return false;
12871 }
12872 function startAnimation(self2, ani, now2, isCore) {
12873 var ani_p = ani._private;
12874 ani_p.started = true;
12875 ani_p.startTime = now2 - ani_p.progress * ani_p.duration;
12876 }
12877 function stepAll(now2, cy) {
12878 var eles = cy._private.aniEles;
12879 var doneEles = [];
12880 function stepOne(ele2, isCore) {
12881 var _p = ele2._private;
12882 var current = _p.animation.current;
12883 var queue = _p.animation.queue;
12884 var ranAnis = false;
12885 if (current.length === 0) {
12886 var next2 = queue.shift();
12887 if (next2) {
12888 current.push(next2);
12889 }
12890 }
12891 var callbacks = function callbacks2(_callbacks) {
12892 for (var j = _callbacks.length - 1; j >= 0; j--) {
12893 var cb = _callbacks[j];
12894 cb();
12895 }
12896 _callbacks.splice(0, _callbacks.length);
12897 };
12898 for (var i2 = current.length - 1; i2 >= 0; i2--) {
12899 var ani = current[i2];
12900 var ani_p = ani._private;
12901 if (ani_p.stopped) {
12902 current.splice(i2, 1);
12903 ani_p.hooked = false;
12904 ani_p.playing = false;
12905 ani_p.started = false;
12906 callbacks(ani_p.frames);
12907 continue;
12908 }
12909 if (!ani_p.playing && !ani_p.applying) {
12910 continue;
12911 }
12912 if (ani_p.playing && ani_p.applying) {
12913 ani_p.applying = false;
12914 }
12915 if (!ani_p.started) {
12916 startAnimation(ele2, ani, now2);
12917 }
12918 step$1(ele2, ani, now2, isCore);
12919 if (ani_p.applying) {
12920 ani_p.applying = false;
12921 }
12922 callbacks(ani_p.frames);
12923 if (ani_p.step != null) {
12924 ani_p.step(now2);
12925 }
12926 if (ani.completed()) {
12927 current.splice(i2, 1);
12928 ani_p.hooked = false;
12929 ani_p.playing = false;
12930 ani_p.started = false;
12931 callbacks(ani_p.completes);
12932 }
12933 ranAnis = true;
12934 }
12935 if (!isCore && current.length === 0 && queue.length === 0) {
12936 doneEles.push(ele2);
12937 }
12938 return ranAnis;
12939 }
12940 var ranEleAni = false;
12941 for (var e = 0; e < eles.length; e++) {
12942 var ele = eles[e];
12943 var handledThisEle = stepOne(ele);
12944 ranEleAni = ranEleAni || handledThisEle;
12945 }
12946 var ranCoreAni = stepOne(cy, true);
12947 if (ranEleAni || ranCoreAni) {
12948 if (eles.length > 0) {
12949 cy.notify("draw", eles);
12950 } else {
12951 cy.notify("draw");
12952 }
12953 }
12954 eles.unmerge(doneEles);
12955 cy.emit("step");
12956 }
12957 var corefn$8 = {
12958 // pull in animation functions
12959 animate: define.animate(),
12960 animation: define.animation(),
12961 animated: define.animated(),
12962 clearQueue: define.clearQueue(),
12963 delay: define.delay(),
12964 delayAnimation: define.delayAnimation(),
12965 stop: define.stop(),
12966 addToAnimationPool: function addToAnimationPool(eles) {
12967 var cy = this;
12968 if (!cy.styleEnabled()) {
12969 return;
12970 }
12971 cy._private.aniEles.merge(eles);
12972 },
12973 stopAnimationLoop: function stopAnimationLoop() {
12974 this._private.animationsRunning = false;
12975 },
12976 startAnimationLoop: function startAnimationLoop() {
12977 var cy = this;
12978 cy._private.animationsRunning = true;
12979 if (!cy.styleEnabled()) {
12980 return;
12981 }
12982 function headlessStep() {
12983 if (!cy._private.animationsRunning) {
12984 return;
12985 }
12986 requestAnimationFrame2(function animationStep(now2) {
12987 stepAll(now2, cy);
12988 headlessStep();
12989 });
12990 }
12991 var renderer2 = cy.renderer();
12992 if (renderer2 && renderer2.beforeRender) {
12993 renderer2.beforeRender(function rendererAnimationStep(willDraw, now2) {
12994 stepAll(now2, cy);
12995 }, renderer2.beforeRenderPriorities.animations);
12996 } else {
12997 headlessStep();
12998 }
12999 }
13000 };
13001 var emitterOptions = {
13002 qualifierCompare: function qualifierCompare(selector1, selector2) {
13003 if (selector1 == null || selector2 == null) {
13004 return selector1 == null && selector2 == null;
13005 } else {
13006 return selector1.sameText(selector2);
13007 }
13008 },
13009 eventMatches: function eventMatches(cy, listener, eventObj) {
13010 var selector = listener.qualifier;
13011 if (selector != null) {
13012 return cy !== eventObj.target && element(eventObj.target) && selector.matches(eventObj.target);
13013 }
13014 return true;
13015 },
13016 addEventFields: function addEventFields(cy, evt) {
13017 evt.cy = cy;
13018 evt.target = cy;
13019 },
13020 callbackContext: function callbackContext(cy, listener, eventObj) {
13021 return listener.qualifier != null ? eventObj.target : cy;
13022 }
13023 };
13024 var argSelector = function argSelector2(arg) {
13025 if (string(arg)) {
13026 return new Selector(arg);
13027 } else {
13028 return arg;
13029 }
13030 };
13031 var elesfn = {
13032 createEmitter: function createEmitter() {
13033 var _p = this._private;
13034 if (!_p.emitter) {
13035 _p.emitter = new Emitter(emitterOptions, this);
13036 }
13037 return this;
13038 },
13039 emitter: function emitter() {
13040 return this._private.emitter;
13041 },
13042 on: function on(events, selector, callback) {
13043 this.emitter().on(events, argSelector(selector), callback);
13044 return this;
13045 },
13046 removeListener: function removeListener(events, selector, callback) {
13047 this.emitter().removeListener(events, argSelector(selector), callback);
13048 return this;
13049 },
13050 removeAllListeners: function removeAllListeners() {
13051 this.emitter().removeAllListeners();
13052 return this;
13053 },
13054 one: function one(events, selector, callback) {
13055 this.emitter().one(events, argSelector(selector), callback);
13056 return this;
13057 },
13058 once: function once(events, selector, callback) {
13059 this.emitter().one(events, argSelector(selector), callback);
13060 return this;
13061 },
13062 emit: function emit(events, extraParams) {
13063 this.emitter().emit(events, extraParams);
13064 return this;
13065 },
13066 emitAndNotify: function emitAndNotify(event2, eles) {
13067 this.emit(event2);
13068 this.notify(event2, eles);
13069 return this;
13070 }
13071 };
13072 define.eventAliasesOn(elesfn);
13073 var corefn$7 = {
13074 png: function png(options) {
13075 var renderer2 = this._private.renderer;
13076 options = options || {};
13077 return renderer2.png(options);
13078 },
13079 jpg: function jpg(options) {
13080 var renderer2 = this._private.renderer;
13081 options = options || {};
13082 options.bg = options.bg || "#fff";
13083 return renderer2.jpg(options);
13084 }
13085 };
13086 corefn$7.jpeg = corefn$7.jpg;
13087 var corefn$6 = {
13088 layout: function layout2(options) {
13089 var cy = this;
13090 if (options == null) {
13091 error("Layout options must be specified to make a layout");
13092 return;
13093 }
13094 if (options.name == null) {
13095 error("A `name` must be specified to make a layout");
13096 return;
13097 }
13098 var name2 = options.name;
13099 var Layout2 = cy.extension("layout", name2);
13100 if (Layout2 == null) {
13101 error("No such layout `" + name2 + "` found. Did you forget to import it and `cytoscape.use()` it?");
13102 return;
13103 }
13104 var eles;
13105 if (string(options.eles)) {
13106 eles = cy.$(options.eles);
13107 } else {
13108 eles = options.eles != null ? options.eles : cy.$();
13109 }
13110 var layout3 = new Layout2(extend({}, options, {
13111 cy,
13112 eles
13113 }));
13114 return layout3;
13115 }
13116 };
13117 corefn$6.createLayout = corefn$6.makeLayout = corefn$6.layout;
13118 var corefn$5 = {
13119 notify: function notify(eventName, eventEles) {
13120 var _p = this._private;
13121 if (this.batching()) {
13122 _p.batchNotifications = _p.batchNotifications || {};
13123 var eles = _p.batchNotifications[eventName] = _p.batchNotifications[eventName] || this.collection();
13124 if (eventEles != null) {
13125 eles.merge(eventEles);
13126 }
13127 return;
13128 }
13129 if (!_p.notificationsEnabled) {
13130 return;
13131 }
13132 var renderer2 = this.renderer();
13133 if (this.destroyed() || !renderer2) {
13134 return;
13135 }
13136 renderer2.notify(eventName, eventEles);
13137 },
13138 notifications: function notifications(bool) {
13139 var p2 = this._private;
13140 if (bool === void 0) {
13141 return p2.notificationsEnabled;
13142 } else {
13143 p2.notificationsEnabled = bool ? true : false;
13144 }
13145 return this;
13146 },
13147 noNotifications: function noNotifications(callback) {
13148 this.notifications(false);
13149 callback();
13150 this.notifications(true);
13151 },
13152 batching: function batching() {
13153 return this._private.batchCount > 0;
13154 },
13155 startBatch: function startBatch() {
13156 var _p = this._private;
13157 if (_p.batchCount == null) {
13158 _p.batchCount = 0;
13159 }
13160 if (_p.batchCount === 0) {
13161 _p.batchStyleEles = this.collection();
13162 _p.batchNotifications = {};
13163 }
13164 _p.batchCount++;
13165 return this;
13166 },
13167 endBatch: function endBatch() {
13168 var _p = this._private;
13169 if (_p.batchCount === 0) {
13170 return this;
13171 }
13172 _p.batchCount--;
13173 if (_p.batchCount === 0) {
13174 _p.batchStyleEles.updateStyle();
13175 var renderer2 = this.renderer();
13176 Object.keys(_p.batchNotifications).forEach(function(eventName) {
13177 var eles = _p.batchNotifications[eventName];
13178 if (eles.empty()) {
13179 renderer2.notify(eventName);
13180 } else {
13181 renderer2.notify(eventName, eles);
13182 }
13183 });
13184 }
13185 return this;
13186 },
13187 batch: function batch(callback) {
13188 this.startBatch();
13189 callback();
13190 this.endBatch();
13191 return this;
13192 },
13193 // for backwards compatibility
13194 batchData: function batchData(map) {
13195 var cy = this;
13196 return this.batch(function() {
13197 var ids = Object.keys(map);
13198 for (var i2 = 0; i2 < ids.length; i2++) {
13199 var id = ids[i2];
13200 var data2 = map[id];
13201 var ele = cy.getElementById(id);
13202 ele.data(data2);
13203 }
13204 });
13205 }
13206 };
13207 var rendererDefaults = defaults$g({
13208 hideEdgesOnViewport: false,
13209 textureOnViewport: false,
13210 motionBlur: false,
13211 motionBlurOpacity: 0.05,
13212 pixelRatio: void 0,
13213 desktopTapThreshold: 4,
13214 touchTapThreshold: 8,
13215 wheelSensitivity: 1,
13216 debug: false,
13217 showFps: false
13218 });
13219 var corefn$4 = {
13220 renderTo: function renderTo(context, zoom, pan, pxRatio) {
13221 var r = this._private.renderer;
13222 r.renderTo(context, zoom, pan, pxRatio);
13223 return this;
13224 },
13225 renderer: function renderer2() {
13226 return this._private.renderer;
13227 },
13228 forceRender: function forceRender() {
13229 this.notify("draw");
13230 return this;
13231 },
13232 resize: function resize() {
13233 this.invalidateSize();
13234 this.emitAndNotify("resize");
13235 return this;
13236 },
13237 initRenderer: function initRenderer(options) {
13238 var cy = this;
13239 var RendererProto = cy.extension("renderer", options.name);
13240 if (RendererProto == null) {
13241 error("Can not initialise: No such renderer `".concat(options.name, "` found. Did you forget to import it and `cytoscape.use()` it?"));
13242 return;
13243 }
13244 if (options.wheelSensitivity !== void 0) {
13245 warn("You have set a custom wheel sensitivity. This will make your app zoom unnaturally when using mainstream mice. You should change this value from the default only if you can guarantee that all your users will use the same hardware and OS configuration as your current machine.");
13246 }
13247 var rOpts = rendererDefaults(options);
13248 rOpts.cy = cy;
13249 cy._private.renderer = new RendererProto(rOpts);
13250 this.notify("init");
13251 },
13252 destroyRenderer: function destroyRenderer() {
13253 var cy = this;
13254 cy.notify("destroy");
13255 var domEle = cy.container();
13256 if (domEle) {
13257 domEle._cyreg = null;
13258 while (domEle.childNodes.length > 0) {
13259 domEle.removeChild(domEle.childNodes[0]);
13260 }
13261 }
13262 cy._private.renderer = null;
13263 cy.mutableElements().forEach(function(ele) {
13264 var _p = ele._private;
13265 _p.rscratch = {};
13266 _p.rstyle = {};
13267 _p.animation.current = [];
13268 _p.animation.queue = [];
13269 });
13270 },
13271 onRender: function onRender(fn2) {
13272 return this.on("render", fn2);
13273 },
13274 offRender: function offRender(fn2) {
13275 return this.off("render", fn2);
13276 }
13277 };
13278 corefn$4.invalidateDimensions = corefn$4.resize;
13279 var corefn$3 = {
13280 // get a collection
13281 // - empty collection on no args
13282 // - collection of elements in the graph on selector arg
13283 // - guarantee a returned collection when elements or collection specified
13284 collection: function collection2(eles, opts) {
13285 if (string(eles)) {
13286 return this.$(eles);
13287 } else if (elementOrCollection(eles)) {
13288 return eles.collection();
13289 } else if (array(eles)) {
13290 if (!opts) {
13291 opts = {};
13292 }
13293 return new Collection(this, eles, opts.unique, opts.removed);
13294 }
13295 return new Collection(this);
13296 },
13297 nodes: function nodes2(selector) {
13298 var nodes3 = this.$(function(ele) {
13299 return ele.isNode();
13300 });
13301 if (selector) {
13302 return nodes3.filter(selector);
13303 }
13304 return nodes3;
13305 },
13306 edges: function edges(selector) {
13307 var edges2 = this.$(function(ele) {
13308 return ele.isEdge();
13309 });
13310 if (selector) {
13311 return edges2.filter(selector);
13312 }
13313 return edges2;
13314 },
13315 // search the graph like jQuery
13316 $: function $(selector) {
13317 var eles = this._private.elements;
13318 if (selector) {
13319 return eles.filter(selector);
13320 } else {
13321 return eles.spawnSelf();
13322 }
13323 },
13324 mutableElements: function mutableElements() {
13325 return this._private.elements;
13326 }
13327 };
13328 corefn$3.elements = corefn$3.filter = corefn$3.$;
13329 var styfn$8 = {};
13330 var TRUE = "t";
13331 var FALSE = "f";
13332 styfn$8.apply = function(eles) {
13333 var self2 = this;
13334 var _p = self2._private;
13335 var cy = _p.cy;
13336 var updatedEles = cy.collection();
13337 for (var ie = 0; ie < eles.length; ie++) {
13338 var ele = eles[ie];
13339 var cxtMeta = self2.getContextMeta(ele);
13340 if (cxtMeta.empty) {
13341 continue;
13342 }
13343 var cxtStyle = self2.getContextStyle(cxtMeta);
13344 var app = self2.applyContextStyle(cxtMeta, cxtStyle, ele);
13345 if (ele._private.appliedInitStyle) {
13346 self2.updateTransitions(ele, app.diffProps);
13347 } else {
13348 ele._private.appliedInitStyle = true;
13349 }
13350 var hintsDiff = self2.updateStyleHints(ele);
13351 if (hintsDiff) {
13352 updatedEles.push(ele);
13353 }
13354 }
13355 return updatedEles;
13356 };
13357 styfn$8.getPropertiesDiff = function(oldCxtKey, newCxtKey) {
13358 var self2 = this;
13359 var cache2 = self2._private.propDiffs = self2._private.propDiffs || {};
13360 var dualCxtKey = oldCxtKey + "-" + newCxtKey;
13361 var cachedVal = cache2[dualCxtKey];
13362 if (cachedVal) {
13363 return cachedVal;
13364 }
13365 var diffProps = [];
13366 var addedProp = {};
13367 for (var i2 = 0; i2 < self2.length; i2++) {
13368 var cxt = self2[i2];
13369 var oldHasCxt = oldCxtKey[i2] === TRUE;
13370 var newHasCxt = newCxtKey[i2] === TRUE;
13371 var cxtHasDiffed = oldHasCxt !== newHasCxt;
13372 var cxtHasMappedProps = cxt.mappedProperties.length > 0;
13373 if (cxtHasDiffed || newHasCxt && cxtHasMappedProps) {
13374 var props = void 0;
13375 if (cxtHasDiffed && cxtHasMappedProps) {
13376 props = cxt.properties;
13377 } else if (cxtHasDiffed) {
13378 props = cxt.properties;
13379 } else if (cxtHasMappedProps) {
13380 props = cxt.mappedProperties;
13381 }
13382 for (var j = 0; j < props.length; j++) {
13383 var prop = props[j];
13384 var name2 = prop.name;
13385 var laterCxtOverrides = false;
13386 for (var k = i2 + 1; k < self2.length; k++) {
13387 var laterCxt = self2[k];
13388 var hasLaterCxt = newCxtKey[k] === TRUE;
13389 if (!hasLaterCxt) {
13390 continue;
13391 }
13392 laterCxtOverrides = laterCxt.properties[prop.name] != null;
13393 if (laterCxtOverrides) {
13394 break;
13395 }
13396 }
13397 if (!addedProp[name2] && !laterCxtOverrides) {
13398 addedProp[name2] = true;
13399 diffProps.push(name2);
13400 }
13401 }
13402 }
13403 }
13404 cache2[dualCxtKey] = diffProps;
13405 return diffProps;
13406 };
13407 styfn$8.getContextMeta = function(ele) {
13408 var self2 = this;
13409 var cxtKey = "";
13410 var diffProps;
13411 var prevKey = ele._private.styleCxtKey || "";
13412 for (var i2 = 0; i2 < self2.length; i2++) {
13413 var context = self2[i2];
13414 var contextSelectorMatches = context.selector && context.selector.matches(ele);
13415 if (contextSelectorMatches) {
13416 cxtKey += TRUE;
13417 } else {
13418 cxtKey += FALSE;
13419 }
13420 }
13421 diffProps = self2.getPropertiesDiff(prevKey, cxtKey);
13422 ele._private.styleCxtKey = cxtKey;
13423 return {
13424 key: cxtKey,
13425 diffPropNames: diffProps,
13426 empty: diffProps.length === 0
13427 };
13428 };
13429 styfn$8.getContextStyle = function(cxtMeta) {
13430 var cxtKey = cxtMeta.key;
13431 var self2 = this;
13432 var cxtStyles = this._private.contextStyles = this._private.contextStyles || {};
13433 if (cxtStyles[cxtKey]) {
13434 return cxtStyles[cxtKey];
13435 }
13436 var style = {
13437 _private: {
13438 key: cxtKey
13439 }
13440 };
13441 for (var i2 = 0; i2 < self2.length; i2++) {
13442 var cxt = self2[i2];
13443 var hasCxt = cxtKey[i2] === TRUE;
13444 if (!hasCxt) {
13445 continue;
13446 }
13447 for (var j = 0; j < cxt.properties.length; j++) {
13448 var prop = cxt.properties[j];
13449 style[prop.name] = prop;
13450 }
13451 }
13452 cxtStyles[cxtKey] = style;
13453 return style;
13454 };
13455 styfn$8.applyContextStyle = function(cxtMeta, cxtStyle, ele) {
13456 var self2 = this;
13457 var diffProps = cxtMeta.diffPropNames;
13458 var retDiffProps = {};
13459 var types = self2.types;
13460 for (var i2 = 0; i2 < diffProps.length; i2++) {
13461 var diffPropName = diffProps[i2];
13462 var cxtProp = cxtStyle[diffPropName];
13463 var eleProp = ele.pstyle(diffPropName);
13464 if (!cxtProp) {
13465 if (!eleProp) {
13466 continue;
13467 } else if (eleProp.bypass) {
13468 cxtProp = {
13469 name: diffPropName,
13470 deleteBypassed: true
13471 };
13472 } else {
13473 cxtProp = {
13474 name: diffPropName,
13475 "delete": true
13476 };
13477 }
13478 }
13479 if (eleProp === cxtProp) {
13480 continue;
13481 }
13482 if (cxtProp.mapped === types.fn && eleProp != null && eleProp.mapping != null && eleProp.mapping.value === cxtProp.value) {
13483 var mapping = eleProp.mapping;
13484 var fnValue = mapping.fnValue = cxtProp.value(ele);
13485 if (fnValue === mapping.prevFnValue) {
13486 continue;
13487 }
13488 }
13489 var retDiffProp = retDiffProps[diffPropName] = {
13490 prev: eleProp
13491 };
13492 self2.applyParsedProperty(ele, cxtProp);
13493 retDiffProp.next = ele.pstyle(diffPropName);
13494 if (retDiffProp.next && retDiffProp.next.bypass) {
13495 retDiffProp.next = retDiffProp.next.bypassed;
13496 }
13497 }
13498 return {
13499 diffProps: retDiffProps
13500 };
13501 };
13502 styfn$8.updateStyleHints = function(ele) {
13503 var _p = ele._private;
13504 var self2 = this;
13505 var propNames = self2.propertyGroupNames;
13506 var propGrKeys = self2.propertyGroupKeys;
13507 var propHash = function propHash2(ele2, propNames2, seedKey) {
13508 return self2.getPropertiesHash(ele2, propNames2, seedKey);
13509 };
13510 var oldStyleKey = _p.styleKey;
13511 if (ele.removed()) {
13512 return false;
13513 }
13514 var isNode = _p.group === "nodes";
13515 var overriddenStyles = ele._private.style;
13516 propNames = Object.keys(overriddenStyles);
13517 for (var i2 = 0; i2 < propGrKeys.length; i2++) {
13518 var grKey = propGrKeys[i2];
13519 _p.styleKeys[grKey] = [DEFAULT_HASH_SEED, DEFAULT_HASH_SEED_ALT];
13520 }
13521 var updateGrKey1 = function updateGrKey12(val, grKey2) {
13522 return _p.styleKeys[grKey2][0] = hashInt(val, _p.styleKeys[grKey2][0]);
13523 };
13524 var updateGrKey2 = function updateGrKey22(val, grKey2) {
13525 return _p.styleKeys[grKey2][1] = hashIntAlt(val, _p.styleKeys[grKey2][1]);
13526 };
13527 var updateGrKey = function updateGrKey3(val, grKey2) {
13528 updateGrKey1(val, grKey2);
13529 updateGrKey2(val, grKey2);
13530 };
13531 var updateGrKeyWStr = function updateGrKeyWStr2(strVal, grKey2) {
13532 for (var j = 0; j < strVal.length; j++) {
13533 var ch = strVal.charCodeAt(j);
13534 updateGrKey1(ch, grKey2);
13535 updateGrKey2(ch, grKey2);
13536 }
13537 };
13538 var N = 2e9;
13539 var cleanNum = function cleanNum2(val) {
13540 return -128 < val && val < 128 && Math.floor(val) !== val ? N - (val * 1024 | 0) : val;
13541 };
13542 for (var _i = 0; _i < propNames.length; _i++) {
13543 var name2 = propNames[_i];
13544 var parsedProp = overriddenStyles[name2];
13545 if (parsedProp == null) {
13546 continue;
13547 }
13548 var propInfo = this.properties[name2];
13549 var type = propInfo.type;
13550 var _grKey = propInfo.groupKey;
13551 var normalizedNumberVal = void 0;
13552 if (propInfo.hashOverride != null) {
13553 normalizedNumberVal = propInfo.hashOverride(ele, parsedProp);
13554 } else if (parsedProp.pfValue != null) {
13555 normalizedNumberVal = parsedProp.pfValue;
13556 }
13557 var numberVal = propInfo.enums == null ? parsedProp.value : null;
13558 var haveNormNum = normalizedNumberVal != null;
13559 var haveUnitedNum = numberVal != null;
13560 var haveNum = haveNormNum || haveUnitedNum;
13561 var units = parsedProp.units;
13562 if (type.number && haveNum && !type.multiple) {
13563 var v = haveNormNum ? normalizedNumberVal : numberVal;
13564 updateGrKey(cleanNum(v), _grKey);
13565 if (!haveNormNum && units != null) {
13566 updateGrKeyWStr(units, _grKey);
13567 }
13568 } else {
13569 updateGrKeyWStr(parsedProp.strValue, _grKey);
13570 }
13571 }
13572 var hash = [DEFAULT_HASH_SEED, DEFAULT_HASH_SEED_ALT];
13573 for (var _i2 = 0; _i2 < propGrKeys.length; _i2++) {
13574 var _grKey2 = propGrKeys[_i2];
13575 var grHash = _p.styleKeys[_grKey2];
13576 hash[0] = hashInt(grHash[0], hash[0]);
13577 hash[1] = hashIntAlt(grHash[1], hash[1]);
13578 }
13579 _p.styleKey = combineHashes(hash[0], hash[1]);
13580 var sk = _p.styleKeys;
13581 _p.labelDimsKey = combineHashesArray(sk.labelDimensions);
13582 var labelKeys = propHash(ele, ["label"], sk.labelDimensions);
13583 _p.labelKey = combineHashesArray(labelKeys);
13584 _p.labelStyleKey = combineHashesArray(hashArrays(sk.commonLabel, labelKeys));
13585 if (!isNode) {
13586 var sourceLabelKeys = propHash(ele, ["source-label"], sk.labelDimensions);
13587 _p.sourceLabelKey = combineHashesArray(sourceLabelKeys);
13588 _p.sourceLabelStyleKey = combineHashesArray(hashArrays(sk.commonLabel, sourceLabelKeys));
13589 var targetLabelKeys = propHash(ele, ["target-label"], sk.labelDimensions);
13590 _p.targetLabelKey = combineHashesArray(targetLabelKeys);
13591 _p.targetLabelStyleKey = combineHashesArray(hashArrays(sk.commonLabel, targetLabelKeys));
13592 }
13593 if (isNode) {
13594 var _p$styleKeys = _p.styleKeys, nodeBody = _p$styleKeys.nodeBody, nodeBorder = _p$styleKeys.nodeBorder, backgroundImage = _p$styleKeys.backgroundImage, compound = _p$styleKeys.compound, pie = _p$styleKeys.pie;
13595 var nodeKeys = [nodeBody, nodeBorder, backgroundImage, compound, pie].filter(function(k) {
13596 return k != null;
13597 }).reduce(hashArrays, [DEFAULT_HASH_SEED, DEFAULT_HASH_SEED_ALT]);
13598 _p.nodeKey = combineHashesArray(nodeKeys);
13599 _p.hasPie = pie != null && pie[0] !== DEFAULT_HASH_SEED && pie[1] !== DEFAULT_HASH_SEED_ALT;
13600 }
13601 return oldStyleKey !== _p.styleKey;
13602 };
13603 styfn$8.clearStyleHints = function(ele) {
13604 var _p = ele._private;
13605 _p.styleCxtKey = "";
13606 _p.styleKeys = {};
13607 _p.styleKey = null;
13608 _p.labelKey = null;
13609 _p.labelStyleKey = null;
13610 _p.sourceLabelKey = null;
13611 _p.sourceLabelStyleKey = null;
13612 _p.targetLabelKey = null;
13613 _p.targetLabelStyleKey = null;
13614 _p.nodeKey = null;
13615 _p.hasPie = null;
13616 };
13617 styfn$8.applyParsedProperty = function(ele, parsedProp) {
13618 var self2 = this;
13619 var prop = parsedProp;
13620 var style = ele._private.style;
13621 var flatProp;
13622 var types = self2.types;
13623 var type = self2.properties[prop.name].type;
13624 var propIsBypass = prop.bypass;
13625 var origProp = style[prop.name];
13626 var origPropIsBypass = origProp && origProp.bypass;
13627 var _p = ele._private;
13628 var flatPropMapping = "mapping";
13629 var getVal = function getVal2(p2) {
13630 if (p2 == null) {
13631 return null;
13632 } else if (p2.pfValue != null) {
13633 return p2.pfValue;
13634 } else {
13635 return p2.value;
13636 }
13637 };
13638 var checkTriggers = function checkTriggers2() {
13639 var fromVal = getVal(origProp);
13640 var toVal = getVal(prop);
13641 self2.checkTriggers(ele, prop.name, fromVal, toVal);
13642 };
13643 if (prop && prop.name.substr(0, 3) === "pie") {
13644 warn("The pie style properties are deprecated. Create charts using background images instead.");
13645 }
13646 if (parsedProp.name === "curve-style" && ele.isEdge() && // loops must be bundled beziers
13647 (parsedProp.value !== "bezier" && ele.isLoop() || // edges connected to compound nodes can not be haystacks
13648 parsedProp.value === "haystack" && (ele.source().isParent() || ele.target().isParent()))) {
13649 prop = parsedProp = this.parse(parsedProp.name, "bezier", propIsBypass);
13650 }
13651 if (prop["delete"]) {
13652 style[prop.name] = void 0;
13653 checkTriggers();
13654 return true;
13655 }
13656 if (prop.deleteBypassed) {
13657 if (!origProp) {
13658 checkTriggers();
13659 return true;
13660 } else if (origProp.bypass) {
13661 origProp.bypassed = void 0;
13662 checkTriggers();
13663 return true;
13664 } else {
13665 return false;
13666 }
13667 }
13668 if (prop.deleteBypass) {
13669 if (!origProp) {
13670 checkTriggers();
13671 return true;
13672 } else if (origProp.bypass) {
13673 style[prop.name] = origProp.bypassed;
13674 checkTriggers();
13675 return true;
13676 } else {
13677 return false;
13678 }
13679 }
13680 var printMappingErr = function printMappingErr2() {
13681 warn("Do not assign mappings to elements without corresponding data (i.e. ele `" + ele.id() + "` has no mapping for property `" + prop.name + "` with data field `" + prop.field + "`); try a `[" + prop.field + "]` selector to limit scope to elements with `" + prop.field + "` defined");
13682 };
13683 switch (prop.mapped) {
13684 case types.mapData: {
13685 var fields = prop.field.split(".");
13686 var fieldVal = _p.data;
13687 for (var i2 = 0; i2 < fields.length && fieldVal; i2++) {
13688 var field = fields[i2];
13689 fieldVal = fieldVal[field];
13690 }
13691 if (fieldVal == null) {
13692 printMappingErr();
13693 return false;
13694 }
13695 var percent;
13696 if (!number$1(fieldVal)) {
13697 warn("Do not use continuous mappers without specifying numeric data (i.e. `" + prop.field + ": " + fieldVal + "` for `" + ele.id() + "` is non-numeric)");
13698 return false;
13699 } else {
13700 var fieldWidth = prop.fieldMax - prop.fieldMin;
13701 if (fieldWidth === 0) {
13702 percent = 0;
13703 } else {
13704 percent = (fieldVal - prop.fieldMin) / fieldWidth;
13705 }
13706 }
13707 if (percent < 0) {
13708 percent = 0;
13709 } else if (percent > 1) {
13710 percent = 1;
13711 }
13712 if (type.color) {
13713 var r1 = prop.valueMin[0];
13714 var r2 = prop.valueMax[0];
13715 var g1 = prop.valueMin[1];
13716 var g2 = prop.valueMax[1];
13717 var b1 = prop.valueMin[2];
13718 var b2 = prop.valueMax[2];
13719 var a1 = prop.valueMin[3] == null ? 1 : prop.valueMin[3];
13720 var a2 = prop.valueMax[3] == null ? 1 : prop.valueMax[3];
13721 var clr = [Math.round(r1 + (r2 - r1) * percent), Math.round(g1 + (g2 - g1) * percent), Math.round(b1 + (b2 - b1) * percent), Math.round(a1 + (a2 - a1) * percent)];
13722 flatProp = {
13723 // colours are simple, so just create the flat property instead of expensive string parsing
13724 bypass: prop.bypass,
13725 // we're a bypass if the mapping property is a bypass
13726 name: prop.name,
13727 value: clr,
13728 strValue: "rgb(" + clr[0] + ", " + clr[1] + ", " + clr[2] + ")"
13729 };
13730 } else if (type.number) {
13731 var calcValue = prop.valueMin + (prop.valueMax - prop.valueMin) * percent;
13732 flatProp = this.parse(prop.name, calcValue, prop.bypass, flatPropMapping);
13733 } else {
13734 return false;
13735 }
13736 if (!flatProp) {
13737 printMappingErr();
13738 return false;
13739 }
13740 flatProp.mapping = prop;
13741 prop = flatProp;
13742 break;
13743 }
13744 case types.data: {
13745 var _fields = prop.field.split(".");
13746 var _fieldVal = _p.data;
13747 for (var _i3 = 0; _i3 < _fields.length && _fieldVal; _i3++) {
13748 var _field = _fields[_i3];
13749 _fieldVal = _fieldVal[_field];
13750 }
13751 if (_fieldVal != null) {
13752 flatProp = this.parse(prop.name, _fieldVal, prop.bypass, flatPropMapping);
13753 }
13754 if (!flatProp) {
13755 printMappingErr();
13756 return false;
13757 }
13758 flatProp.mapping = prop;
13759 prop = flatProp;
13760 break;
13761 }
13762 case types.fn: {
13763 var fn2 = prop.value;
13764 var fnRetVal = prop.fnValue != null ? prop.fnValue : fn2(ele);
13765 prop.prevFnValue = fnRetVal;
13766 if (fnRetVal == null) {
13767 warn("Custom function mappers may not return null (i.e. `" + prop.name + "` for ele `" + ele.id() + "` is null)");
13768 return false;
13769 }
13770 flatProp = this.parse(prop.name, fnRetVal, prop.bypass, flatPropMapping);
13771 if (!flatProp) {
13772 warn("Custom function mappers may not return invalid values for the property type (i.e. `" + prop.name + "` for ele `" + ele.id() + "` is invalid)");
13773 return false;
13774 }
13775 flatProp.mapping = copy(prop);
13776 prop = flatProp;
13777 break;
13778 }
13779 case void 0:
13780 break;
13781 default:
13782 return false;
13783 }
13784 if (propIsBypass) {
13785 if (origPropIsBypass) {
13786 prop.bypassed = origProp.bypassed;
13787 } else {
13788 prop.bypassed = origProp;
13789 }
13790 style[prop.name] = prop;
13791 } else {
13792 if (origPropIsBypass) {
13793 origProp.bypassed = prop;
13794 } else {
13795 style[prop.name] = prop;
13796 }
13797 }
13798 checkTriggers();
13799 return true;
13800 };
13801 styfn$8.cleanElements = function(eles, keepBypasses) {
13802 for (var i2 = 0; i2 < eles.length; i2++) {
13803 var ele = eles[i2];
13804 this.clearStyleHints(ele);
13805 ele.dirtyCompoundBoundsCache();
13806 ele.dirtyBoundingBoxCache();
13807 if (!keepBypasses) {
13808 ele._private.style = {};
13809 } else {
13810 var style = ele._private.style;
13811 var propNames = Object.keys(style);
13812 for (var j = 0; j < propNames.length; j++) {
13813 var propName = propNames[j];
13814 var eleProp = style[propName];
13815 if (eleProp != null) {
13816 if (eleProp.bypass) {
13817 eleProp.bypassed = null;
13818 } else {
13819 style[propName] = null;
13820 }
13821 }
13822 }
13823 }
13824 }
13825 };
13826 styfn$8.update = function() {
13827 var cy = this._private.cy;
13828 var eles = cy.mutableElements();
13829 eles.updateStyle();
13830 };
13831 styfn$8.updateTransitions = function(ele, diffProps) {
13832 var self2 = this;
13833 var _p = ele._private;
13834 var props = ele.pstyle("transition-property").value;
13835 var duration = ele.pstyle("transition-duration").pfValue;
13836 var delay = ele.pstyle("transition-delay").pfValue;
13837 if (props.length > 0 && duration > 0) {
13838 var style = {};
13839 var anyPrev = false;
13840 for (var i2 = 0; i2 < props.length; i2++) {
13841 var prop = props[i2];
13842 var styProp = ele.pstyle(prop);
13843 var diffProp = diffProps[prop];
13844 if (!diffProp) {
13845 continue;
13846 }
13847 var prevProp = diffProp.prev;
13848 var fromProp = prevProp;
13849 var toProp = diffProp.next != null ? diffProp.next : styProp;
13850 var diff = false;
13851 var initVal = void 0;
13852 var initDt = 1e-6;
13853 if (!fromProp) {
13854 continue;
13855 }
13856 if (number$1(fromProp.pfValue) && number$1(toProp.pfValue)) {
13857 diff = toProp.pfValue - fromProp.pfValue;
13858 initVal = fromProp.pfValue + initDt * diff;
13859 } else if (number$1(fromProp.value) && number$1(toProp.value)) {
13860 diff = toProp.value - fromProp.value;
13861 initVal = fromProp.value + initDt * diff;
13862 } else if (array(fromProp.value) && array(toProp.value)) {
13863 diff = fromProp.value[0] !== toProp.value[0] || fromProp.value[1] !== toProp.value[1] || fromProp.value[2] !== toProp.value[2];
13864 initVal = fromProp.strValue;
13865 }
13866 if (diff) {
13867 style[prop] = toProp.strValue;
13868 this.applyBypass(ele, prop, initVal);
13869 anyPrev = true;
13870 }
13871 }
13872 if (!anyPrev) {
13873 return;
13874 }
13875 _p.transitioning = true;
13876 new Promise$1(function(resolve2) {
13877 if (delay > 0) {
13878 ele.delayAnimation(delay).play().promise().then(resolve2);
13879 } else {
13880 resolve2();
13881 }
13882 }).then(function() {
13883 return ele.animation({
13884 style,
13885 duration,
13886 easing: ele.pstyle("transition-timing-function").value,
13887 queue: false
13888 }).play().promise();
13889 }).then(function() {
13890 self2.removeBypasses(ele, props);
13891 ele.emitAndNotify("style");
13892 _p.transitioning = false;
13893 });
13894 } else if (_p.transitioning) {
13895 this.removeBypasses(ele, props);
13896 ele.emitAndNotify("style");
13897 _p.transitioning = false;
13898 }
13899 };
13900 styfn$8.checkTrigger = function(ele, name2, fromValue, toValue, getTrigger, onTrigger) {
13901 var prop = this.properties[name2];
13902 var triggerCheck = getTrigger(prop);
13903 if (triggerCheck != null && triggerCheck(fromValue, toValue)) {
13904 onTrigger(prop);
13905 }
13906 };
13907 styfn$8.checkZOrderTrigger = function(ele, name2, fromValue, toValue) {
13908 var _this = this;
13909 this.checkTrigger(ele, name2, fromValue, toValue, function(prop) {
13910 return prop.triggersZOrder;
13911 }, function() {
13912 _this._private.cy.notify("zorder", ele);
13913 });
13914 };
13915 styfn$8.checkBoundsTrigger = function(ele, name2, fromValue, toValue) {
13916 this.checkTrigger(ele, name2, fromValue, toValue, function(prop) {
13917 return prop.triggersBounds;
13918 }, function(prop) {
13919 ele.dirtyCompoundBoundsCache();
13920 ele.dirtyBoundingBoxCache();
13921 if (
13922 // only for beziers -- so performance of other edges isn't affected
13923 prop.triggersBoundsOfParallelBeziers && (name2 === "curve-style" && (fromValue === "bezier" || toValue === "bezier") || name2 === "display" && (fromValue === "none" || toValue === "none"))
13924 ) {
13925 ele.parallelEdges().forEach(function(pllEdge) {
13926 if (pllEdge.isBundledBezier()) {
13927 pllEdge.dirtyBoundingBoxCache();
13928 }
13929 });
13930 }
13931 });
13932 };
13933 styfn$8.checkTriggers = function(ele, name2, fromValue, toValue) {
13934 ele.dirtyStyleCache();
13935 this.checkZOrderTrigger(ele, name2, fromValue, toValue);
13936 this.checkBoundsTrigger(ele, name2, fromValue, toValue);
13937 };
13938 var styfn$7 = {};
13939 styfn$7.applyBypass = function(eles, name2, value, updateTransitions) {
13940 var self2 = this;
13941 var props = [];
13942 var isBypass = true;
13943 if (name2 === "*" || name2 === "**") {
13944 if (value !== void 0) {
13945 for (var i2 = 0; i2 < self2.properties.length; i2++) {
13946 var prop = self2.properties[i2];
13947 var _name = prop.name;
13948 var parsedProp = this.parse(_name, value, true);
13949 if (parsedProp) {
13950 props.push(parsedProp);
13951 }
13952 }
13953 }
13954 } else if (string(name2)) {
13955 var _parsedProp = this.parse(name2, value, true);
13956 if (_parsedProp) {
13957 props.push(_parsedProp);
13958 }
13959 } else if (plainObject(name2)) {
13960 var specifiedProps = name2;
13961 updateTransitions = value;
13962 var names = Object.keys(specifiedProps);
13963 for (var _i = 0; _i < names.length; _i++) {
13964 var _name2 = names[_i];
13965 var _value = specifiedProps[_name2];
13966 if (_value === void 0) {
13967 _value = specifiedProps[dash2camel(_name2)];
13968 }
13969 if (_value !== void 0) {
13970 var _parsedProp2 = this.parse(_name2, _value, true);
13971 if (_parsedProp2) {
13972 props.push(_parsedProp2);
13973 }
13974 }
13975 }
13976 } else {
13977 return false;
13978 }
13979 if (props.length === 0) {
13980 return false;
13981 }
13982 var ret = false;
13983 for (var _i2 = 0; _i2 < eles.length; _i2++) {
13984 var ele = eles[_i2];
13985 var diffProps = {};
13986 var diffProp = void 0;
13987 for (var j = 0; j < props.length; j++) {
13988 var _prop = props[j];
13989 if (updateTransitions) {
13990 var prevProp = ele.pstyle(_prop.name);
13991 diffProp = diffProps[_prop.name] = {
13992 prev: prevProp
13993 };
13994 }
13995 ret = this.applyParsedProperty(ele, copy(_prop)) || ret;
13996 if (updateTransitions) {
13997 diffProp.next = ele.pstyle(_prop.name);
13998 }
13999 }
14000 if (ret) {
14001 this.updateStyleHints(ele);
14002 }
14003 if (updateTransitions) {
14004 this.updateTransitions(ele, diffProps, isBypass);
14005 }
14006 }
14007 return ret;
14008 };
14009 styfn$7.overrideBypass = function(eles, name2, value) {
14010 name2 = camel2dash(name2);
14011 for (var i2 = 0; i2 < eles.length; i2++) {
14012 var ele = eles[i2];
14013 var prop = ele._private.style[name2];
14014 var type = this.properties[name2].type;
14015 var isColor = type.color;
14016 var isMulti = type.mutiple;
14017 var oldValue = !prop ? null : prop.pfValue != null ? prop.pfValue : prop.value;
14018 if (!prop || !prop.bypass) {
14019 this.applyBypass(ele, name2, value);
14020 } else {
14021 prop.value = value;
14022 if (prop.pfValue != null) {
14023 prop.pfValue = value;
14024 }
14025 if (isColor) {
14026 prop.strValue = "rgb(" + value.join(",") + ")";
14027 } else if (isMulti) {
14028 prop.strValue = value.join(" ");
14029 } else {
14030 prop.strValue = "" + value;
14031 }
14032 this.updateStyleHints(ele);
14033 }
14034 this.checkTriggers(ele, name2, oldValue, value);
14035 }
14036 };
14037 styfn$7.removeAllBypasses = function(eles, updateTransitions) {
14038 return this.removeBypasses(eles, this.propertyNames, updateTransitions);
14039 };
14040 styfn$7.removeBypasses = function(eles, props, updateTransitions) {
14041 var isBypass = true;
14042 for (var j = 0; j < eles.length; j++) {
14043 var ele = eles[j];
14044 var diffProps = {};
14045 for (var i2 = 0; i2 < props.length; i2++) {
14046 var name2 = props[i2];
14047 var prop = this.properties[name2];
14048 var prevProp = ele.pstyle(prop.name);
14049 if (!prevProp || !prevProp.bypass) {
14050 continue;
14051 }
14052 var value = "";
14053 var parsedProp = this.parse(name2, value, true);
14054 var diffProp = diffProps[prop.name] = {
14055 prev: prevProp
14056 };
14057 this.applyParsedProperty(ele, parsedProp);
14058 diffProp.next = ele.pstyle(prop.name);
14059 }
14060 this.updateStyleHints(ele);
14061 if (updateTransitions) {
14062 this.updateTransitions(ele, diffProps, isBypass);
14063 }
14064 }
14065 };
14066 var styfn$6 = {};
14067 styfn$6.getEmSizeInPixels = function() {
14068 var px = this.containerCss("font-size");
14069 if (px != null) {
14070 return parseFloat(px);
14071 } else {
14072 return 1;
14073 }
14074 };
14075 styfn$6.containerCss = function(propName) {
14076 var cy = this._private.cy;
14077 var domElement2 = cy.container();
14078 if (window$1 && domElement2 && window$1.getComputedStyle) {
14079 return window$1.getComputedStyle(domElement2).getPropertyValue(propName);
14080 }
14081 };
14082 var styfn$5 = {};
14083 styfn$5.getRenderedStyle = function(ele, prop) {
14084 if (prop) {
14085 return this.getStylePropertyValue(ele, prop, true);
14086 } else {
14087 return this.getRawStyle(ele, true);
14088 }
14089 };
14090 styfn$5.getRawStyle = function(ele, isRenderedVal) {
14091 var self2 = this;
14092 ele = ele[0];
14093 if (ele) {
14094 var rstyle = {};
14095 for (var i2 = 0; i2 < self2.properties.length; i2++) {
14096 var prop = self2.properties[i2];
14097 var val = self2.getStylePropertyValue(ele, prop.name, isRenderedVal);
14098 if (val != null) {
14099 rstyle[prop.name] = val;
14100 rstyle[dash2camel(prop.name)] = val;
14101 }
14102 }
14103 return rstyle;
14104 }
14105 };
14106 styfn$5.getIndexedStyle = function(ele, property, subproperty, index) {
14107 var pstyle = ele.pstyle(property)[subproperty][index];
14108 return pstyle != null ? pstyle : ele.cy().style().getDefaultProperty(property)[subproperty][0];
14109 };
14110 styfn$5.getStylePropertyValue = function(ele, propName, isRenderedVal) {
14111 var self2 = this;
14112 ele = ele[0];
14113 if (ele) {
14114 var prop = self2.properties[propName];
14115 if (prop.alias) {
14116 prop = prop.pointsTo;
14117 }
14118 var type = prop.type;
14119 var styleProp = ele.pstyle(prop.name);
14120 if (styleProp) {
14121 var value = styleProp.value, units = styleProp.units, strValue = styleProp.strValue;
14122 if (isRenderedVal && type.number && value != null && number$1(value)) {
14123 var zoom = ele.cy().zoom();
14124 var getRenderedValue = function getRenderedValue2(val) {
14125 return val * zoom;
14126 };
14127 var getValueStringWithUnits = function getValueStringWithUnits2(val, units2) {
14128 return getRenderedValue(val) + units2;
14129 };
14130 var isArrayValue = array(value);
14131 var haveUnits = isArrayValue ? units.every(function(u) {
14132 return u != null;
14133 }) : units != null;
14134 if (haveUnits) {
14135 if (isArrayValue) {
14136 return value.map(function(v, i2) {
14137 return getValueStringWithUnits(v, units[i2]);
14138 }).join(" ");
14139 } else {
14140 return getValueStringWithUnits(value, units);
14141 }
14142 } else {
14143 if (isArrayValue) {
14144 return value.map(function(v) {
14145 return string(v) ? v : "" + getRenderedValue(v);
14146 }).join(" ");
14147 } else {
14148 return "" + getRenderedValue(value);
14149 }
14150 }
14151 } else if (strValue != null) {
14152 return strValue;
14153 }
14154 }
14155 return null;
14156 }
14157 };
14158 styfn$5.getAnimationStartStyle = function(ele, aniProps) {
14159 var rstyle = {};
14160 for (var i2 = 0; i2 < aniProps.length; i2++) {
14161 var aniProp = aniProps[i2];
14162 var name2 = aniProp.name;
14163 var styleProp = ele.pstyle(name2);
14164 if (styleProp !== void 0) {
14165 if (plainObject(styleProp)) {
14166 styleProp = this.parse(name2, styleProp.strValue);
14167 } else {
14168 styleProp = this.parse(name2, styleProp);
14169 }
14170 }
14171 if (styleProp) {
14172 rstyle[name2] = styleProp;
14173 }
14174 }
14175 return rstyle;
14176 };
14177 styfn$5.getPropsList = function(propsObj) {
14178 var self2 = this;
14179 var rstyle = [];
14180 var style = propsObj;
14181 var props = self2.properties;
14182 if (style) {
14183 var names = Object.keys(style);
14184 for (var i2 = 0; i2 < names.length; i2++) {
14185 var name2 = names[i2];
14186 var val = style[name2];
14187 var prop = props[name2] || props[camel2dash(name2)];
14188 var styleProp = this.parse(prop.name, val);
14189 if (styleProp) {
14190 rstyle.push(styleProp);
14191 }
14192 }
14193 }
14194 return rstyle;
14195 };
14196 styfn$5.getNonDefaultPropertiesHash = function(ele, propNames, seed) {
14197 var hash = seed.slice();
14198 var name2, val, strVal, chVal;
14199 var i2, j;
14200 for (i2 = 0; i2 < propNames.length; i2++) {
14201 name2 = propNames[i2];
14202 val = ele.pstyle(name2, false);
14203 if (val == null) {
14204 continue;
14205 } else if (val.pfValue != null) {
14206 hash[0] = hashInt(chVal, hash[0]);
14207 hash[1] = hashIntAlt(chVal, hash[1]);
14208 } else {
14209 strVal = val.strValue;
14210 for (j = 0; j < strVal.length; j++) {
14211 chVal = strVal.charCodeAt(j);
14212 hash[0] = hashInt(chVal, hash[0]);
14213 hash[1] = hashIntAlt(chVal, hash[1]);
14214 }
14215 }
14216 }
14217 return hash;
14218 };
14219 styfn$5.getPropertiesHash = styfn$5.getNonDefaultPropertiesHash;
14220 var styfn$4 = {};
14221 styfn$4.appendFromJson = function(json) {
14222 var style = this;
14223 for (var i2 = 0; i2 < json.length; i2++) {
14224 var context = json[i2];
14225 var selector = context.selector;
14226 var props = context.style || context.css;
14227 var names = Object.keys(props);
14228 style.selector(selector);
14229 for (var j = 0; j < names.length; j++) {
14230 var name2 = names[j];
14231 var value = props[name2];
14232 style.css(name2, value);
14233 }
14234 }
14235 return style;
14236 };
14237 styfn$4.fromJson = function(json) {
14238 var style = this;
14239 style.resetToDefault();
14240 style.appendFromJson(json);
14241 return style;
14242 };
14243 styfn$4.json = function() {
14244 var json = [];
14245 for (var i2 = this.defaultLength; i2 < this.length; i2++) {
14246 var cxt = this[i2];
14247 var selector = cxt.selector;
14248 var props = cxt.properties;
14249 var css = {};
14250 for (var j = 0; j < props.length; j++) {
14251 var prop = props[j];
14252 css[prop.name] = prop.strValue;
14253 }
14254 json.push({
14255 selector: !selector ? "core" : selector.toString(),
14256 style: css
14257 });
14258 }
14259 return json;
14260 };
14261 var styfn$3 = {};
14262 styfn$3.appendFromString = function(string2) {
14263 var self2 = this;
14264 var style = this;
14265 var remaining = "" + string2;
14266 var selAndBlockStr;
14267 var blockRem;
14268 var propAndValStr;
14269 remaining = remaining.replace(/[/][*](\s|.)+?[*][/]/g, "");
14270 function removeSelAndBlockFromRemaining() {
14271 if (remaining.length > selAndBlockStr.length) {
14272 remaining = remaining.substr(selAndBlockStr.length);
14273 } else {
14274 remaining = "";
14275 }
14276 }
14277 function removePropAndValFromRem() {
14278 if (blockRem.length > propAndValStr.length) {
14279 blockRem = blockRem.substr(propAndValStr.length);
14280 } else {
14281 blockRem = "";
14282 }
14283 }
14284 for (; ; ) {
14285 var nothingLeftToParse = remaining.match(/^\s*$/);
14286 if (nothingLeftToParse) {
14287 break;
14288 }
14289 var selAndBlock = remaining.match(/^\s*((?:.|\s)+?)\s*\{((?:.|\s)+?)\}/);
14290 if (!selAndBlock) {
14291 warn("Halting stylesheet parsing: String stylesheet contains more to parse but no selector and block found in: " + remaining);
14292 break;
14293 }
14294 selAndBlockStr = selAndBlock[0];
14295 var selectorStr = selAndBlock[1];
14296 if (selectorStr !== "core") {
14297 var selector = new Selector(selectorStr);
14298 if (selector.invalid) {
14299 warn("Skipping parsing of block: Invalid selector found in string stylesheet: " + selectorStr);
14300 removeSelAndBlockFromRemaining();
14301 continue;
14302 }
14303 }
14304 var blockStr = selAndBlock[2];
14305 var invalidBlock = false;
14306 blockRem = blockStr;
14307 var props = [];
14308 for (; ; ) {
14309 var _nothingLeftToParse = blockRem.match(/^\s*$/);
14310 if (_nothingLeftToParse) {
14311 break;
14312 }
14313 var propAndVal = blockRem.match(/^\s*(.+?)\s*:\s*(.+?)(?:\s*;|\s*$)/);
14314 if (!propAndVal) {
14315 warn("Skipping parsing of block: Invalid formatting of style property and value definitions found in:" + blockStr);
14316 invalidBlock = true;
14317 break;
14318 }
14319 propAndValStr = propAndVal[0];
14320 var propStr = propAndVal[1];
14321 var valStr = propAndVal[2];
14322 var prop = self2.properties[propStr];
14323 if (!prop) {
14324 warn("Skipping property: Invalid property name in: " + propAndValStr);
14325 removePropAndValFromRem();
14326 continue;
14327 }
14328 var parsedProp = style.parse(propStr, valStr);
14329 if (!parsedProp) {
14330 warn("Skipping property: Invalid property definition in: " + propAndValStr);
14331 removePropAndValFromRem();
14332 continue;
14333 }
14334 props.push({
14335 name: propStr,
14336 val: valStr
14337 });
14338 removePropAndValFromRem();
14339 }
14340 if (invalidBlock) {
14341 removeSelAndBlockFromRemaining();
14342 break;
14343 }
14344 style.selector(selectorStr);
14345 for (var i2 = 0; i2 < props.length; i2++) {
14346 var _prop = props[i2];
14347 style.css(_prop.name, _prop.val);
14348 }
14349 removeSelAndBlockFromRemaining();
14350 }
14351 return style;
14352 };
14353 styfn$3.fromString = function(string2) {
14354 var style = this;
14355 style.resetToDefault();
14356 style.appendFromString(string2);
14357 return style;
14358 };
14359 var styfn$2 = {};
14360 (function() {
14361 var number$12 = number;
14362 var rgba2 = rgbaNoBackRefs;
14363 var hsla2 = hslaNoBackRefs;
14364 var hex3$1 = hex3;
14365 var hex6$1 = hex6;
14366 var data2 = function data3(prefix) {
14367 return "^" + prefix + "\\s*\\(\\s*([\\w\\.]+)\\s*\\)$";
14368 };
14369 var mapData = function mapData2(prefix) {
14370 var mapArg = number$12 + "|\\w+|" + rgba2 + "|" + hsla2 + "|" + hex3$1 + "|" + hex6$1;
14371 return "^" + prefix + "\\s*\\(([\\w\\.]+)\\s*\\,\\s*(" + number$12 + ")\\s*\\,\\s*(" + number$12 + ")\\s*,\\s*(" + mapArg + ")\\s*\\,\\s*(" + mapArg + ")\\)$";
14372 };
14373 var urlRegexes = [`^url\\s*\\(\\s*['"]?(.+?)['"]?\\s*\\)$`, "^(none)$", "^(.+)$"];
14374 styfn$2.types = {
14375 time: {
14376 number: true,
14377 min: 0,
14378 units: "s|ms",
14379 implicitUnits: "ms"
14380 },
14381 percent: {
14382 number: true,
14383 min: 0,
14384 max: 100,
14385 units: "%",
14386 implicitUnits: "%"
14387 },
14388 percentages: {
14389 number: true,
14390 min: 0,
14391 max: 100,
14392 units: "%",
14393 implicitUnits: "%",
14394 multiple: true
14395 },
14396 zeroOneNumber: {
14397 number: true,
14398 min: 0,
14399 max: 1,
14400 unitless: true
14401 },
14402 zeroOneNumbers: {
14403 number: true,
14404 min: 0,
14405 max: 1,
14406 unitless: true,
14407 multiple: true
14408 },
14409 nOneOneNumber: {
14410 number: true,
14411 min: -1,
14412 max: 1,
14413 unitless: true
14414 },
14415 nonNegativeInt: {
14416 number: true,
14417 min: 0,
14418 integer: true,
14419 unitless: true
14420 },
14421 position: {
14422 enums: ["parent", "origin"]
14423 },
14424 nodeSize: {
14425 number: true,
14426 min: 0,
14427 enums: ["label"]
14428 },
14429 number: {
14430 number: true,
14431 unitless: true
14432 },
14433 numbers: {
14434 number: true,
14435 unitless: true,
14436 multiple: true
14437 },
14438 positiveNumber: {
14439 number: true,
14440 unitless: true,
14441 min: 0,
14442 strictMin: true
14443 },
14444 size: {
14445 number: true,
14446 min: 0
14447 },
14448 bidirectionalSize: {
14449 number: true
14450 },
14451 // allows negative
14452 bidirectionalSizeMaybePercent: {
14453 number: true,
14454 allowPercent: true
14455 },
14456 // allows negative
14457 bidirectionalSizes: {
14458 number: true,
14459 multiple: true
14460 },
14461 // allows negative
14462 sizeMaybePercent: {
14463 number: true,
14464 min: 0,
14465 allowPercent: true
14466 },
14467 axisDirection: {
14468 enums: ["horizontal", "leftward", "rightward", "vertical", "upward", "downward", "auto"]
14469 },
14470 paddingRelativeTo: {
14471 enums: ["width", "height", "average", "min", "max"]
14472 },
14473 bgWH: {
14474 number: true,
14475 min: 0,
14476 allowPercent: true,
14477 enums: ["auto"],
14478 multiple: true
14479 },
14480 bgPos: {
14481 number: true,
14482 allowPercent: true,
14483 multiple: true
14484 },
14485 bgRelativeTo: {
14486 enums: ["inner", "include-padding"],
14487 multiple: true
14488 },
14489 bgRepeat: {
14490 enums: ["repeat", "repeat-x", "repeat-y", "no-repeat"],
14491 multiple: true
14492 },
14493 bgFit: {
14494 enums: ["none", "contain", "cover"],
14495 multiple: true
14496 },
14497 bgCrossOrigin: {
14498 enums: ["anonymous", "use-credentials"],
14499 multiple: true
14500 },
14501 bgClip: {
14502 enums: ["none", "node"],
14503 multiple: true
14504 },
14505 bgContainment: {
14506 enums: ["inside", "over"],
14507 multiple: true
14508 },
14509 color: {
14510 color: true
14511 },
14512 colors: {
14513 color: true,
14514 multiple: true
14515 },
14516 fill: {
14517 enums: ["solid", "linear-gradient", "radial-gradient"]
14518 },
14519 bool: {
14520 enums: ["yes", "no"]
14521 },
14522 bools: {
14523 enums: ["yes", "no"],
14524 multiple: true
14525 },
14526 lineStyle: {
14527 enums: ["solid", "dotted", "dashed"]
14528 },
14529 lineCap: {
14530 enums: ["butt", "round", "square"]
14531 },
14532 borderStyle: {
14533 enums: ["solid", "dotted", "dashed", "double"]
14534 },
14535 curveStyle: {
14536 enums: ["bezier", "unbundled-bezier", "haystack", "segments", "straight", "straight-triangle", "taxi"]
14537 },
14538 fontFamily: {
14539 regex: '^([\\w- \\"]+(?:\\s*,\\s*[\\w- \\"]+)*)$'
14540 },
14541 fontStyle: {
14542 enums: ["italic", "normal", "oblique"]
14543 },
14544 fontWeight: {
14545 enums: ["normal", "bold", "bolder", "lighter", "100", "200", "300", "400", "500", "600", "800", "900", 100, 200, 300, 400, 500, 600, 700, 800, 900]
14546 },
14547 textDecoration: {
14548 enums: ["none", "underline", "overline", "line-through"]
14549 },
14550 textTransform: {
14551 enums: ["none", "uppercase", "lowercase"]
14552 },
14553 textWrap: {
14554 enums: ["none", "wrap", "ellipsis"]
14555 },
14556 textOverflowWrap: {
14557 enums: ["whitespace", "anywhere"]
14558 },
14559 textBackgroundShape: {
14560 enums: ["rectangle", "roundrectangle", "round-rectangle"]
14561 },
14562 nodeShape: {
14563 enums: ["rectangle", "roundrectangle", "round-rectangle", "cutrectangle", "cut-rectangle", "bottomroundrectangle", "bottom-round-rectangle", "barrel", "ellipse", "triangle", "round-triangle", "square", "pentagon", "round-pentagon", "hexagon", "round-hexagon", "concavehexagon", "concave-hexagon", "heptagon", "round-heptagon", "octagon", "round-octagon", "tag", "round-tag", "star", "diamond", "round-diamond", "vee", "rhomboid", "polygon"]
14564 },
14565 overlayShape: {
14566 enums: ["roundrectangle", "round-rectangle", "ellipse"]
14567 },
14568 compoundIncludeLabels: {
14569 enums: ["include", "exclude"]
14570 },
14571 arrowShape: {
14572 enums: ["tee", "triangle", "triangle-tee", "circle-triangle", "triangle-cross", "triangle-backcurve", "vee", "square", "circle", "diamond", "chevron", "none"]
14573 },
14574 arrowFill: {
14575 enums: ["filled", "hollow"]
14576 },
14577 display: {
14578 enums: ["element", "none"]
14579 },
14580 visibility: {
14581 enums: ["hidden", "visible"]
14582 },
14583 zCompoundDepth: {
14584 enums: ["bottom", "orphan", "auto", "top"]
14585 },
14586 zIndexCompare: {
14587 enums: ["auto", "manual"]
14588 },
14589 valign: {
14590 enums: ["top", "center", "bottom"]
14591 },
14592 halign: {
14593 enums: ["left", "center", "right"]
14594 },
14595 justification: {
14596 enums: ["left", "center", "right", "auto"]
14597 },
14598 text: {
14599 string: true
14600 },
14601 data: {
14602 mapping: true,
14603 regex: data2("data")
14604 },
14605 layoutData: {
14606 mapping: true,
14607 regex: data2("layoutData")
14608 },
14609 scratch: {
14610 mapping: true,
14611 regex: data2("scratch")
14612 },
14613 mapData: {
14614 mapping: true,
14615 regex: mapData("mapData")
14616 },
14617 mapLayoutData: {
14618 mapping: true,
14619 regex: mapData("mapLayoutData")
14620 },
14621 mapScratch: {
14622 mapping: true,
14623 regex: mapData("mapScratch")
14624 },
14625 fn: {
14626 mapping: true,
14627 fn: true
14628 },
14629 url: {
14630 regexes: urlRegexes,
14631 singleRegexMatchValue: true
14632 },
14633 urls: {
14634 regexes: urlRegexes,
14635 singleRegexMatchValue: true,
14636 multiple: true
14637 },
14638 propList: {
14639 propList: true
14640 },
14641 angle: {
14642 number: true,
14643 units: "deg|rad",
14644 implicitUnits: "rad"
14645 },
14646 textRotation: {
14647 number: true,
14648 units: "deg|rad",
14649 implicitUnits: "rad",
14650 enums: ["none", "autorotate"]
14651 },
14652 polygonPointList: {
14653 number: true,
14654 multiple: true,
14655 evenMultiple: true,
14656 min: -1,
14657 max: 1,
14658 unitless: true
14659 },
14660 edgeDistances: {
14661 enums: ["intersection", "node-position"]
14662 },
14663 edgeEndpoint: {
14664 number: true,
14665 multiple: true,
14666 units: "%|px|em|deg|rad",
14667 implicitUnits: "px",
14668 enums: ["inside-to-node", "outside-to-node", "outside-to-node-or-label", "outside-to-line", "outside-to-line-or-label"],
14669 singleEnum: true,
14670 validate: function validate(valArr, unitsArr) {
14671 switch (valArr.length) {
14672 case 2:
14673 return unitsArr[0] !== "deg" && unitsArr[0] !== "rad" && unitsArr[1] !== "deg" && unitsArr[1] !== "rad";
14674 case 1:
14675 return string(valArr[0]) || unitsArr[0] === "deg" || unitsArr[0] === "rad";
14676 default:
14677 return false;
14678 }
14679 }
14680 },
14681 easing: {
14682 regexes: ["^(spring)\\s*\\(\\s*(" + number$12 + ")\\s*,\\s*(" + number$12 + ")\\s*\\)$", "^(cubic-bezier)\\s*\\(\\s*(" + number$12 + ")\\s*,\\s*(" + number$12 + ")\\s*,\\s*(" + number$12 + ")\\s*,\\s*(" + number$12 + ")\\s*\\)$"],
14683 enums: ["linear", "ease", "ease-in", "ease-out", "ease-in-out", "ease-in-sine", "ease-out-sine", "ease-in-out-sine", "ease-in-quad", "ease-out-quad", "ease-in-out-quad", "ease-in-cubic", "ease-out-cubic", "ease-in-out-cubic", "ease-in-quart", "ease-out-quart", "ease-in-out-quart", "ease-in-quint", "ease-out-quint", "ease-in-out-quint", "ease-in-expo", "ease-out-expo", "ease-in-out-expo", "ease-in-circ", "ease-out-circ", "ease-in-out-circ"]
14684 },
14685 gradientDirection: {
14686 enums: [
14687 "to-bottom",
14688 "to-top",
14689 "to-left",
14690 "to-right",
14691 "to-bottom-right",
14692 "to-bottom-left",
14693 "to-top-right",
14694 "to-top-left",
14695 "to-right-bottom",
14696 "to-left-bottom",
14697 "to-right-top",
14698 "to-left-top"
14699 // different order
14700 ]
14701 },
14702 boundsExpansion: {
14703 number: true,
14704 multiple: true,
14705 min: 0,
14706 validate: function validate(valArr) {
14707 var length = valArr.length;
14708 return length === 1 || length === 2 || length === 4;
14709 }
14710 }
14711 };
14712 var diff = {
14713 zeroNonZero: function zeroNonZero(val1, val2) {
14714 if ((val1 == null || val2 == null) && val1 !== val2) {
14715 return true;
14716 }
14717 if (val1 == 0 && val2 != 0) {
14718 return true;
14719 } else if (val1 != 0 && val2 == 0) {
14720 return true;
14721 } else {
14722 return false;
14723 }
14724 },
14725 any: function any(val1, val2) {
14726 return val1 != val2;
14727 },
14728 emptyNonEmpty: function emptyNonEmpty(str1, str2) {
14729 var empty1 = emptyString(str1);
14730 var empty2 = emptyString(str2);
14731 return empty1 && !empty2 || !empty1 && empty2;
14732 }
14733 };
14734 var t = styfn$2.types;
14735 var mainLabel = [{
14736 name: "label",
14737 type: t.text,
14738 triggersBounds: diff.any,
14739 triggersZOrder: diff.emptyNonEmpty
14740 }, {
14741 name: "text-rotation",
14742 type: t.textRotation,
14743 triggersBounds: diff.any
14744 }, {
14745 name: "text-margin-x",
14746 type: t.bidirectionalSize,
14747 triggersBounds: diff.any
14748 }, {
14749 name: "text-margin-y",
14750 type: t.bidirectionalSize,
14751 triggersBounds: diff.any
14752 }];
14753 var sourceLabel = [{
14754 name: "source-label",
14755 type: t.text,
14756 triggersBounds: diff.any
14757 }, {
14758 name: "source-text-rotation",
14759 type: t.textRotation,
14760 triggersBounds: diff.any
14761 }, {
14762 name: "source-text-margin-x",
14763 type: t.bidirectionalSize,
14764 triggersBounds: diff.any
14765 }, {
14766 name: "source-text-margin-y",
14767 type: t.bidirectionalSize,
14768 triggersBounds: diff.any
14769 }, {
14770 name: "source-text-offset",
14771 type: t.size,
14772 triggersBounds: diff.any
14773 }];
14774 var targetLabel = [{
14775 name: "target-label",
14776 type: t.text,
14777 triggersBounds: diff.any
14778 }, {
14779 name: "target-text-rotation",
14780 type: t.textRotation,
14781 triggersBounds: diff.any
14782 }, {
14783 name: "target-text-margin-x",
14784 type: t.bidirectionalSize,
14785 triggersBounds: diff.any
14786 }, {
14787 name: "target-text-margin-y",
14788 type: t.bidirectionalSize,
14789 triggersBounds: diff.any
14790 }, {
14791 name: "target-text-offset",
14792 type: t.size,
14793 triggersBounds: diff.any
14794 }];
14795 var labelDimensions = [{
14796 name: "font-family",
14797 type: t.fontFamily,
14798 triggersBounds: diff.any
14799 }, {
14800 name: "font-style",
14801 type: t.fontStyle,
14802 triggersBounds: diff.any
14803 }, {
14804 name: "font-weight",
14805 type: t.fontWeight,
14806 triggersBounds: diff.any
14807 }, {
14808 name: "font-size",
14809 type: t.size,
14810 triggersBounds: diff.any
14811 }, {
14812 name: "text-transform",
14813 type: t.textTransform,
14814 triggersBounds: diff.any
14815 }, {
14816 name: "text-wrap",
14817 type: t.textWrap,
14818 triggersBounds: diff.any
14819 }, {
14820 name: "text-overflow-wrap",
14821 type: t.textOverflowWrap,
14822 triggersBounds: diff.any
14823 }, {
14824 name: "text-max-width",
14825 type: t.size,
14826 triggersBounds: diff.any
14827 }, {
14828 name: "text-outline-width",
14829 type: t.size,
14830 triggersBounds: diff.any
14831 }, {
14832 name: "line-height",
14833 type: t.positiveNumber,
14834 triggersBounds: diff.any
14835 }];
14836 var commonLabel = [{
14837 name: "text-valign",
14838 type: t.valign,
14839 triggersBounds: diff.any
14840 }, {
14841 name: "text-halign",
14842 type: t.halign,
14843 triggersBounds: diff.any
14844 }, {
14845 name: "color",
14846 type: t.color
14847 }, {
14848 name: "text-outline-color",
14849 type: t.color
14850 }, {
14851 name: "text-outline-opacity",
14852 type: t.zeroOneNumber
14853 }, {
14854 name: "text-background-color",
14855 type: t.color
14856 }, {
14857 name: "text-background-opacity",
14858 type: t.zeroOneNumber
14859 }, {
14860 name: "text-background-padding",
14861 type: t.size,
14862 triggersBounds: diff.any
14863 }, {
14864 name: "text-border-opacity",
14865 type: t.zeroOneNumber
14866 }, {
14867 name: "text-border-color",
14868 type: t.color
14869 }, {
14870 name: "text-border-width",
14871 type: t.size,
14872 triggersBounds: diff.any
14873 }, {
14874 name: "text-border-style",
14875 type: t.borderStyle,
14876 triggersBounds: diff.any
14877 }, {
14878 name: "text-background-shape",
14879 type: t.textBackgroundShape,
14880 triggersBounds: diff.any
14881 }, {
14882 name: "text-justification",
14883 type: t.justification
14884 }];
14885 var behavior = [{
14886 name: "events",
14887 type: t.bool
14888 }, {
14889 name: "text-events",
14890 type: t.bool
14891 }];
14892 var visibility = [{
14893 name: "display",
14894 type: t.display,
14895 triggersZOrder: diff.any,
14896 triggersBounds: diff.any,
14897 triggersBoundsOfParallelBeziers: true
14898 }, {
14899 name: "visibility",
14900 type: t.visibility,
14901 triggersZOrder: diff.any
14902 }, {
14903 name: "opacity",
14904 type: t.zeroOneNumber,
14905 triggersZOrder: diff.zeroNonZero
14906 }, {
14907 name: "text-opacity",
14908 type: t.zeroOneNumber
14909 }, {
14910 name: "min-zoomed-font-size",
14911 type: t.size
14912 }, {
14913 name: "z-compound-depth",
14914 type: t.zCompoundDepth,
14915 triggersZOrder: diff.any
14916 }, {
14917 name: "z-index-compare",
14918 type: t.zIndexCompare,
14919 triggersZOrder: diff.any
14920 }, {
14921 name: "z-index",
14922 type: t.nonNegativeInt,
14923 triggersZOrder: diff.any
14924 }];
14925 var overlay = [{
14926 name: "overlay-padding",
14927 type: t.size,
14928 triggersBounds: diff.any
14929 }, {
14930 name: "overlay-color",
14931 type: t.color
14932 }, {
14933 name: "overlay-opacity",
14934 type: t.zeroOneNumber,
14935 triggersBounds: diff.zeroNonZero
14936 }, {
14937 name: "overlay-shape",
14938 type: t.overlayShape,
14939 triggersBounds: diff.any
14940 }];
14941 var underlay = [{
14942 name: "underlay-padding",
14943 type: t.size,
14944 triggersBounds: diff.any
14945 }, {
14946 name: "underlay-color",
14947 type: t.color
14948 }, {
14949 name: "underlay-opacity",
14950 type: t.zeroOneNumber,
14951 triggersBounds: diff.zeroNonZero
14952 }, {
14953 name: "underlay-shape",
14954 type: t.overlayShape,
14955 triggersBounds: diff.any
14956 }];
14957 var transition = [{
14958 name: "transition-property",
14959 type: t.propList
14960 }, {
14961 name: "transition-duration",
14962 type: t.time
14963 }, {
14964 name: "transition-delay",
14965 type: t.time
14966 }, {
14967 name: "transition-timing-function",
14968 type: t.easing
14969 }];
14970 var nodeSizeHashOverride = function nodeSizeHashOverride2(ele, parsedProp) {
14971 if (parsedProp.value === "label") {
14972 return -ele.poolIndex();
14973 } else {
14974 return parsedProp.pfValue;
14975 }
14976 };
14977 var nodeBody = [{
14978 name: "height",
14979 type: t.nodeSize,
14980 triggersBounds: diff.any,
14981 hashOverride: nodeSizeHashOverride
14982 }, {
14983 name: "width",
14984 type: t.nodeSize,
14985 triggersBounds: diff.any,
14986 hashOverride: nodeSizeHashOverride
14987 }, {
14988 name: "shape",
14989 type: t.nodeShape,
14990 triggersBounds: diff.any
14991 }, {
14992 name: "shape-polygon-points",
14993 type: t.polygonPointList,
14994 triggersBounds: diff.any
14995 }, {
14996 name: "background-color",
14997 type: t.color
14998 }, {
14999 name: "background-fill",
15000 type: t.fill
15001 }, {
15002 name: "background-opacity",
15003 type: t.zeroOneNumber
15004 }, {
15005 name: "background-blacken",
15006 type: t.nOneOneNumber
15007 }, {
15008 name: "background-gradient-stop-colors",
15009 type: t.colors
15010 }, {
15011 name: "background-gradient-stop-positions",
15012 type: t.percentages
15013 }, {
15014 name: "background-gradient-direction",
15015 type: t.gradientDirection
15016 }, {
15017 name: "padding",
15018 type: t.sizeMaybePercent,
15019 triggersBounds: diff.any
15020 }, {
15021 name: "padding-relative-to",
15022 type: t.paddingRelativeTo,
15023 triggersBounds: diff.any
15024 }, {
15025 name: "bounds-expansion",
15026 type: t.boundsExpansion,
15027 triggersBounds: diff.any
15028 }];
15029 var nodeBorder = [{
15030 name: "border-color",
15031 type: t.color
15032 }, {
15033 name: "border-opacity",
15034 type: t.zeroOneNumber
15035 }, {
15036 name: "border-width",
15037 type: t.size,
15038 triggersBounds: diff.any
15039 }, {
15040 name: "border-style",
15041 type: t.borderStyle
15042 }];
15043 var backgroundImage = [{
15044 name: "background-image",
15045 type: t.urls
15046 }, {
15047 name: "background-image-crossorigin",
15048 type: t.bgCrossOrigin
15049 }, {
15050 name: "background-image-opacity",
15051 type: t.zeroOneNumbers
15052 }, {
15053 name: "background-image-containment",
15054 type: t.bgContainment
15055 }, {
15056 name: "background-image-smoothing",
15057 type: t.bools
15058 }, {
15059 name: "background-position-x",
15060 type: t.bgPos
15061 }, {
15062 name: "background-position-y",
15063 type: t.bgPos
15064 }, {
15065 name: "background-width-relative-to",
15066 type: t.bgRelativeTo
15067 }, {
15068 name: "background-height-relative-to",
15069 type: t.bgRelativeTo
15070 }, {
15071 name: "background-repeat",
15072 type: t.bgRepeat
15073 }, {
15074 name: "background-fit",
15075 type: t.bgFit
15076 }, {
15077 name: "background-clip",
15078 type: t.bgClip
15079 }, {
15080 name: "background-width",
15081 type: t.bgWH
15082 }, {
15083 name: "background-height",
15084 type: t.bgWH
15085 }, {
15086 name: "background-offset-x",
15087 type: t.bgPos
15088 }, {
15089 name: "background-offset-y",
15090 type: t.bgPos
15091 }];
15092 var compound = [{
15093 name: "position",
15094 type: t.position,
15095 triggersBounds: diff.any
15096 }, {
15097 name: "compound-sizing-wrt-labels",
15098 type: t.compoundIncludeLabels,
15099 triggersBounds: diff.any
15100 }, {
15101 name: "min-width",
15102 type: t.size,
15103 triggersBounds: diff.any
15104 }, {
15105 name: "min-width-bias-left",
15106 type: t.sizeMaybePercent,
15107 triggersBounds: diff.any
15108 }, {
15109 name: "min-width-bias-right",
15110 type: t.sizeMaybePercent,
15111 triggersBounds: diff.any
15112 }, {
15113 name: "min-height",
15114 type: t.size,
15115 triggersBounds: diff.any
15116 }, {
15117 name: "min-height-bias-top",
15118 type: t.sizeMaybePercent,
15119 triggersBounds: diff.any
15120 }, {
15121 name: "min-height-bias-bottom",
15122 type: t.sizeMaybePercent,
15123 triggersBounds: diff.any
15124 }];
15125 var edgeLine = [{
15126 name: "line-style",
15127 type: t.lineStyle
15128 }, {
15129 name: "line-color",
15130 type: t.color
15131 }, {
15132 name: "line-fill",
15133 type: t.fill
15134 }, {
15135 name: "line-cap",
15136 type: t.lineCap
15137 }, {
15138 name: "line-opacity",
15139 type: t.zeroOneNumber
15140 }, {
15141 name: "line-dash-pattern",
15142 type: t.numbers
15143 }, {
15144 name: "line-dash-offset",
15145 type: t.number
15146 }, {
15147 name: "line-gradient-stop-colors",
15148 type: t.colors
15149 }, {
15150 name: "line-gradient-stop-positions",
15151 type: t.percentages
15152 }, {
15153 name: "curve-style",
15154 type: t.curveStyle,
15155 triggersBounds: diff.any,
15156 triggersBoundsOfParallelBeziers: true
15157 }, {
15158 name: "haystack-radius",
15159 type: t.zeroOneNumber,
15160 triggersBounds: diff.any
15161 }, {
15162 name: "source-endpoint",
15163 type: t.edgeEndpoint,
15164 triggersBounds: diff.any
15165 }, {
15166 name: "target-endpoint",
15167 type: t.edgeEndpoint,
15168 triggersBounds: diff.any
15169 }, {
15170 name: "control-point-step-size",
15171 type: t.size,
15172 triggersBounds: diff.any
15173 }, {
15174 name: "control-point-distances",
15175 type: t.bidirectionalSizes,
15176 triggersBounds: diff.any
15177 }, {
15178 name: "control-point-weights",
15179 type: t.numbers,
15180 triggersBounds: diff.any
15181 }, {
15182 name: "segment-distances",
15183 type: t.bidirectionalSizes,
15184 triggersBounds: diff.any
15185 }, {
15186 name: "segment-weights",
15187 type: t.numbers,
15188 triggersBounds: diff.any
15189 }, {
15190 name: "taxi-turn",
15191 type: t.bidirectionalSizeMaybePercent,
15192 triggersBounds: diff.any
15193 }, {
15194 name: "taxi-turn-min-distance",
15195 type: t.size,
15196 triggersBounds: diff.any
15197 }, {
15198 name: "taxi-direction",
15199 type: t.axisDirection,
15200 triggersBounds: diff.any
15201 }, {
15202 name: "edge-distances",
15203 type: t.edgeDistances,
15204 triggersBounds: diff.any
15205 }, {
15206 name: "arrow-scale",
15207 type: t.positiveNumber,
15208 triggersBounds: diff.any
15209 }, {
15210 name: "loop-direction",
15211 type: t.angle,
15212 triggersBounds: diff.any
15213 }, {
15214 name: "loop-sweep",
15215 type: t.angle,
15216 triggersBounds: diff.any
15217 }, {
15218 name: "source-distance-from-node",
15219 type: t.size,
15220 triggersBounds: diff.any
15221 }, {
15222 name: "target-distance-from-node",
15223 type: t.size,
15224 triggersBounds: diff.any
15225 }];
15226 var ghost = [{
15227 name: "ghost",
15228 type: t.bool,
15229 triggersBounds: diff.any
15230 }, {
15231 name: "ghost-offset-x",
15232 type: t.bidirectionalSize,
15233 triggersBounds: diff.any
15234 }, {
15235 name: "ghost-offset-y",
15236 type: t.bidirectionalSize,
15237 triggersBounds: diff.any
15238 }, {
15239 name: "ghost-opacity",
15240 type: t.zeroOneNumber
15241 }];
15242 var core2 = [{
15243 name: "selection-box-color",
15244 type: t.color
15245 }, {
15246 name: "selection-box-opacity",
15247 type: t.zeroOneNumber
15248 }, {
15249 name: "selection-box-border-color",
15250 type: t.color
15251 }, {
15252 name: "selection-box-border-width",
15253 type: t.size
15254 }, {
15255 name: "active-bg-color",
15256 type: t.color
15257 }, {
15258 name: "active-bg-opacity",
15259 type: t.zeroOneNumber
15260 }, {
15261 name: "active-bg-size",
15262 type: t.size
15263 }, {
15264 name: "outside-texture-bg-color",
15265 type: t.color
15266 }, {
15267 name: "outside-texture-bg-opacity",
15268 type: t.zeroOneNumber
15269 }];
15270 var pie = [];
15271 styfn$2.pieBackgroundN = 16;
15272 pie.push({
15273 name: "pie-size",
15274 type: t.sizeMaybePercent
15275 });
15276 for (var i2 = 1; i2 <= styfn$2.pieBackgroundN; i2++) {
15277 pie.push({
15278 name: "pie-" + i2 + "-background-color",
15279 type: t.color
15280 });
15281 pie.push({
15282 name: "pie-" + i2 + "-background-size",
15283 type: t.percent
15284 });
15285 pie.push({
15286 name: "pie-" + i2 + "-background-opacity",
15287 type: t.zeroOneNumber
15288 });
15289 }
15290 var edgeArrow = [];
15291 var arrowPrefixes = styfn$2.arrowPrefixes = ["source", "mid-source", "target", "mid-target"];
15292 [{
15293 name: "arrow-shape",
15294 type: t.arrowShape,
15295 triggersBounds: diff.any
15296 }, {
15297 name: "arrow-color",
15298 type: t.color
15299 }, {
15300 name: "arrow-fill",
15301 type: t.arrowFill
15302 }].forEach(function(prop2) {
15303 arrowPrefixes.forEach(function(prefix) {
15304 var name2 = prefix + "-" + prop2.name;
15305 var type = prop2.type, triggersBounds = prop2.triggersBounds;
15306 edgeArrow.push({
15307 name: name2,
15308 type,
15309 triggersBounds
15310 });
15311 });
15312 }, {});
15313 var props = styfn$2.properties = [].concat(behavior, transition, visibility, overlay, underlay, ghost, commonLabel, labelDimensions, mainLabel, sourceLabel, targetLabel, nodeBody, nodeBorder, backgroundImage, pie, compound, edgeLine, edgeArrow, core2);
15314 var propGroups = styfn$2.propertyGroups = {
15315 // common to all eles
15316 behavior,
15317 transition,
15318 visibility,
15319 overlay,
15320 underlay,
15321 ghost,
15322 // labels
15323 commonLabel,
15324 labelDimensions,
15325 mainLabel,
15326 sourceLabel,
15327 targetLabel,
15328 // node props
15329 nodeBody,
15330 nodeBorder,
15331 backgroundImage,
15332 pie,
15333 compound,
15334 // edge props
15335 edgeLine,
15336 edgeArrow,
15337 core: core2
15338 };
15339 var propGroupNames = styfn$2.propertyGroupNames = {};
15340 var propGroupKeys = styfn$2.propertyGroupKeys = Object.keys(propGroups);
15341 propGroupKeys.forEach(function(key) {
15342 propGroupNames[key] = propGroups[key].map(function(prop2) {
15343 return prop2.name;
15344 });
15345 propGroups[key].forEach(function(prop2) {
15346 return prop2.groupKey = key;
15347 });
15348 });
15349 var aliases = styfn$2.aliases = [{
15350 name: "content",
15351 pointsTo: "label"
15352 }, {
15353 name: "control-point-distance",
15354 pointsTo: "control-point-distances"
15355 }, {
15356 name: "control-point-weight",
15357 pointsTo: "control-point-weights"
15358 }, {
15359 name: "edge-text-rotation",
15360 pointsTo: "text-rotation"
15361 }, {
15362 name: "padding-left",
15363 pointsTo: "padding"
15364 }, {
15365 name: "padding-right",
15366 pointsTo: "padding"
15367 }, {
15368 name: "padding-top",
15369 pointsTo: "padding"
15370 }, {
15371 name: "padding-bottom",
15372 pointsTo: "padding"
15373 }];
15374 styfn$2.propertyNames = props.map(function(p2) {
15375 return p2.name;
15376 });
15377 for (var _i = 0; _i < props.length; _i++) {
15378 var prop = props[_i];
15379 props[prop.name] = prop;
15380 }
15381 for (var _i2 = 0; _i2 < aliases.length; _i2++) {
15382 var alias = aliases[_i2];
15383 var pointsToProp = props[alias.pointsTo];
15384 var aliasProp = {
15385 name: alias.name,
15386 alias: true,
15387 pointsTo: pointsToProp
15388 };
15389 props.push(aliasProp);
15390 props[alias.name] = aliasProp;
15391 }
15392 })();
15393 styfn$2.getDefaultProperty = function(name2) {
15394 return this.getDefaultProperties()[name2];
15395 };
15396 styfn$2.getDefaultProperties = function() {
15397 var _p = this._private;
15398 if (_p.defaultProperties != null) {
15399 return _p.defaultProperties;
15400 }
15401 var rawProps = extend({
15402 // core props
15403 "selection-box-color": "#ddd",
15404 "selection-box-opacity": 0.65,
15405 "selection-box-border-color": "#aaa",
15406 "selection-box-border-width": 1,
15407 "active-bg-color": "black",
15408 "active-bg-opacity": 0.15,
15409 "active-bg-size": 30,
15410 "outside-texture-bg-color": "#000",
15411 "outside-texture-bg-opacity": 0.125,
15412 // common node/edge props
15413 "events": "yes",
15414 "text-events": "no",
15415 "text-valign": "top",
15416 "text-halign": "center",
15417 "text-justification": "auto",
15418 "line-height": 1,
15419 "color": "#000",
15420 "text-outline-color": "#000",
15421 "text-outline-width": 0,
15422 "text-outline-opacity": 1,
15423 "text-opacity": 1,
15424 "text-decoration": "none",
15425 "text-transform": "none",
15426 "text-wrap": "none",
15427 "text-overflow-wrap": "whitespace",
15428 "text-max-width": 9999,
15429 "text-background-color": "#000",
15430 "text-background-opacity": 0,
15431 "text-background-shape": "rectangle",
15432 "text-background-padding": 0,
15433 "text-border-opacity": 0,
15434 "text-border-width": 0,
15435 "text-border-style": "solid",
15436 "text-border-color": "#000",
15437 "font-family": "Helvetica Neue, Helvetica, sans-serif",
15438 "font-style": "normal",
15439 "font-weight": "normal",
15440 "font-size": 16,
15441 "min-zoomed-font-size": 0,
15442 "text-rotation": "none",
15443 "source-text-rotation": "none",
15444 "target-text-rotation": "none",
15445 "visibility": "visible",
15446 "display": "element",
15447 "opacity": 1,
15448 "z-compound-depth": "auto",
15449 "z-index-compare": "auto",
15450 "z-index": 0,
15451 "label": "",
15452 "text-margin-x": 0,
15453 "text-margin-y": 0,
15454 "source-label": "",
15455 "source-text-offset": 0,
15456 "source-text-margin-x": 0,
15457 "source-text-margin-y": 0,
15458 "target-label": "",
15459 "target-text-offset": 0,
15460 "target-text-margin-x": 0,
15461 "target-text-margin-y": 0,
15462 "overlay-opacity": 0,
15463 "overlay-color": "#000",
15464 "overlay-padding": 10,
15465 "overlay-shape": "round-rectangle",
15466 "underlay-opacity": 0,
15467 "underlay-color": "#000",
15468 "underlay-padding": 10,
15469 "underlay-shape": "round-rectangle",
15470 "transition-property": "none",
15471 "transition-duration": 0,
15472 "transition-delay": 0,
15473 "transition-timing-function": "linear",
15474 // node props
15475 "background-blacken": 0,
15476 "background-color": "#999",
15477 "background-fill": "solid",
15478 "background-opacity": 1,
15479 "background-image": "none",
15480 "background-image-crossorigin": "anonymous",
15481 "background-image-opacity": 1,
15482 "background-image-containment": "inside",
15483 "background-image-smoothing": "yes",
15484 "background-position-x": "50%",
15485 "background-position-y": "50%",
15486 "background-offset-x": 0,
15487 "background-offset-y": 0,
15488 "background-width-relative-to": "include-padding",
15489 "background-height-relative-to": "include-padding",
15490 "background-repeat": "no-repeat",
15491 "background-fit": "none",
15492 "background-clip": "node",
15493 "background-width": "auto",
15494 "background-height": "auto",
15495 "border-color": "#000",
15496 "border-opacity": 1,
15497 "border-width": 0,
15498 "border-style": "solid",
15499 "height": 30,
15500 "width": 30,
15501 "shape": "ellipse",
15502 "shape-polygon-points": "-1, -1, 1, -1, 1, 1, -1, 1",
15503 "bounds-expansion": 0,
15504 // node gradient
15505 "background-gradient-direction": "to-bottom",
15506 "background-gradient-stop-colors": "#999",
15507 "background-gradient-stop-positions": "0%",
15508 // ghost props
15509 "ghost": "no",
15510 "ghost-offset-y": 0,
15511 "ghost-offset-x": 0,
15512 "ghost-opacity": 0,
15513 // compound props
15514 "padding": 0,
15515 "padding-relative-to": "width",
15516 "position": "origin",
15517 "compound-sizing-wrt-labels": "include",
15518 "min-width": 0,
15519 "min-width-bias-left": 0,
15520 "min-width-bias-right": 0,
15521 "min-height": 0,
15522 "min-height-bias-top": 0,
15523 "min-height-bias-bottom": 0
15524 }, {
15525 // node pie bg
15526 "pie-size": "100%"
15527 }, [{
15528 name: "pie-{{i}}-background-color",
15529 value: "black"
15530 }, {
15531 name: "pie-{{i}}-background-size",
15532 value: "0%"
15533 }, {
15534 name: "pie-{{i}}-background-opacity",
15535 value: 1
15536 }].reduce(function(css, prop2) {
15537 for (var i3 = 1; i3 <= styfn$2.pieBackgroundN; i3++) {
15538 var name3 = prop2.name.replace("{{i}}", i3);
15539 var val2 = prop2.value;
15540 css[name3] = val2;
15541 }
15542 return css;
15543 }, {}), {
15544 // edge props
15545 "line-style": "solid",
15546 "line-color": "#999",
15547 "line-fill": "solid",
15548 "line-cap": "butt",
15549 "line-opacity": 1,
15550 "line-gradient-stop-colors": "#999",
15551 "line-gradient-stop-positions": "0%",
15552 "control-point-step-size": 40,
15553 "control-point-weights": 0.5,
15554 "segment-weights": 0.5,
15555 "segment-distances": 20,
15556 "taxi-turn": "50%",
15557 "taxi-turn-min-distance": 10,
15558 "taxi-direction": "auto",
15559 "edge-distances": "intersection",
15560 "curve-style": "haystack",
15561 "haystack-radius": 0,
15562 "arrow-scale": 1,
15563 "loop-direction": "-45deg",
15564 "loop-sweep": "-90deg",
15565 "source-distance-from-node": 0,
15566 "target-distance-from-node": 0,
15567 "source-endpoint": "outside-to-node",
15568 "target-endpoint": "outside-to-node",
15569 "line-dash-pattern": [6, 3],
15570 "line-dash-offset": 0
15571 }, [{
15572 name: "arrow-shape",
15573 value: "none"
15574 }, {
15575 name: "arrow-color",
15576 value: "#999"
15577 }, {
15578 name: "arrow-fill",
15579 value: "filled"
15580 }].reduce(function(css, prop2) {
15581 styfn$2.arrowPrefixes.forEach(function(prefix) {
15582 var name3 = prefix + "-" + prop2.name;
15583 var val2 = prop2.value;
15584 css[name3] = val2;
15585 });
15586 return css;
15587 }, {}));
15588 var parsedProps = {};
15589 for (var i2 = 0; i2 < this.properties.length; i2++) {
15590 var prop = this.properties[i2];
15591 if (prop.pointsTo) {
15592 continue;
15593 }
15594 var name2 = prop.name;
15595 var val = rawProps[name2];
15596 var parsedProp = this.parse(name2, val);
15597 parsedProps[name2] = parsedProp;
15598 }
15599 _p.defaultProperties = parsedProps;
15600 return _p.defaultProperties;
15601 };
15602 styfn$2.addDefaultStylesheet = function() {
15603 this.selector(":parent").css({
15604 "shape": "rectangle",
15605 "padding": 10,
15606 "background-color": "#eee",
15607 "border-color": "#ccc",
15608 "border-width": 1
15609 }).selector("edge").css({
15610 "width": 3
15611 }).selector(":loop").css({
15612 "curve-style": "bezier"
15613 }).selector("edge:compound").css({
15614 "curve-style": "bezier",
15615 "source-endpoint": "outside-to-line",
15616 "target-endpoint": "outside-to-line"
15617 }).selector(":selected").css({
15618 "background-color": "#0169D9",
15619 "line-color": "#0169D9",
15620 "source-arrow-color": "#0169D9",
15621 "target-arrow-color": "#0169D9",
15622 "mid-source-arrow-color": "#0169D9",
15623 "mid-target-arrow-color": "#0169D9"
15624 }).selector(":parent:selected").css({
15625 "background-color": "#CCE1F9",
15626 "border-color": "#aec8e5"
15627 }).selector(":active").css({
15628 "overlay-color": "black",
15629 "overlay-padding": 10,
15630 "overlay-opacity": 0.25
15631 });
15632 this.defaultLength = this.length;
15633 };
15634 var styfn$1 = {};
15635 styfn$1.parse = function(name2, value, propIsBypass, propIsFlat) {
15636 var self2 = this;
15637 if (fn$6(value)) {
15638 return self2.parseImplWarn(name2, value, propIsBypass, propIsFlat);
15639 }
15640 var flatKey = propIsFlat === "mapping" || propIsFlat === true || propIsFlat === false || propIsFlat == null ? "dontcare" : propIsFlat;
15641 var bypassKey = propIsBypass ? "t" : "f";
15642 var valueKey = "" + value;
15643 var argHash = hashStrings(name2, valueKey, bypassKey, flatKey);
15644 var propCache = self2.propCache = self2.propCache || [];
15645 var ret;
15646 if (!(ret = propCache[argHash])) {
15647 ret = propCache[argHash] = self2.parseImplWarn(name2, value, propIsBypass, propIsFlat);
15648 }
15649 if (propIsBypass || propIsFlat === "mapping") {
15650 ret = copy(ret);
15651 if (ret) {
15652 ret.value = copy(ret.value);
15653 }
15654 }
15655 return ret;
15656 };
15657 styfn$1.parseImplWarn = function(name2, value, propIsBypass, propIsFlat) {
15658 var prop = this.parseImpl(name2, value, propIsBypass, propIsFlat);
15659 if (!prop && value != null) {
15660 warn("The style property `".concat(name2, ": ").concat(value, "` is invalid"));
15661 }
15662 if (prop && (prop.name === "width" || prop.name === "height") && value === "label") {
15663 warn("The style value of `label` is deprecated for `" + prop.name + "`");
15664 }
15665 return prop;
15666 };
15667 styfn$1.parseImpl = function(name2, value, propIsBypass, propIsFlat) {
15668 var self2 = this;
15669 name2 = camel2dash(name2);
15670 var property = self2.properties[name2];
15671 var passedValue = value;
15672 var types = self2.types;
15673 if (!property) {
15674 return null;
15675 }
15676 if (value === void 0) {
15677 return null;
15678 }
15679 if (property.alias) {
15680 property = property.pointsTo;
15681 name2 = property.name;
15682 }
15683 var valueIsString = string(value);
15684 if (valueIsString) {
15685 value = value.trim();
15686 }
15687 var type = property.type;
15688 if (!type) {
15689 return null;
15690 }
15691 if (propIsBypass && (value === "" || value === null)) {
15692 return {
15693 name: name2,
15694 value,
15695 bypass: true,
15696 deleteBypass: true
15697 };
15698 }
15699 if (fn$6(value)) {
15700 return {
15701 name: name2,
15702 value,
15703 strValue: "fn",
15704 mapped: types.fn,
15705 bypass: propIsBypass
15706 };
15707 }
15708 var data2, mapData;
15709 if (!valueIsString || propIsFlat || value.length < 7 || value[1] !== "a")
15710 ;
15711 else if (value.length >= 7 && value[0] === "d" && (data2 = new RegExp(types.data.regex).exec(value))) {
15712 if (propIsBypass) {
15713 return false;
15714 }
15715 var mapped = types.data;
15716 return {
15717 name: name2,
15718 value: data2,
15719 strValue: "" + value,
15720 mapped,
15721 field: data2[1],
15722 bypass: propIsBypass
15723 };
15724 } else if (value.length >= 10 && value[0] === "m" && (mapData = new RegExp(types.mapData.regex).exec(value))) {
15725 if (propIsBypass) {
15726 return false;
15727 }
15728 if (type.multiple) {
15729 return false;
15730 }
15731 var _mapped = types.mapData;
15732 if (!(type.color || type.number)) {
15733 return false;
15734 }
15735 var valueMin = this.parse(name2, mapData[4]);
15736 if (!valueMin || valueMin.mapped) {
15737 return false;
15738 }
15739 var valueMax = this.parse(name2, mapData[5]);
15740 if (!valueMax || valueMax.mapped) {
15741 return false;
15742 }
15743 if (valueMin.pfValue === valueMax.pfValue || valueMin.strValue === valueMax.strValue) {
15744 warn("`" + name2 + ": " + value + "` is not a valid mapper because the output range is zero; converting to `" + name2 + ": " + valueMin.strValue + "`");
15745 return this.parse(name2, valueMin.strValue);
15746 } else if (type.color) {
15747 var c1 = valueMin.value;
15748 var c2 = valueMax.value;
15749 var same = c1[0] === c2[0] && c1[1] === c2[1] && c1[2] === c2[2] && // optional alpha
15750 (c1[3] === c2[3] || (c1[3] == null || c1[3] === 1) && (c2[3] == null || c2[3] === 1));
15751 if (same) {
15752 return false;
15753 }
15754 }
15755 return {
15756 name: name2,
15757 value: mapData,
15758 strValue: "" + value,
15759 mapped: _mapped,
15760 field: mapData[1],
15761 fieldMin: parseFloat(mapData[2]),
15762 // min & max are numeric
15763 fieldMax: parseFloat(mapData[3]),
15764 valueMin: valueMin.value,
15765 valueMax: valueMax.value,
15766 bypass: propIsBypass
15767 };
15768 }
15769 if (type.multiple && propIsFlat !== "multiple") {
15770 var vals;
15771 if (valueIsString) {
15772 vals = value.split(/\s+/);
15773 } else if (array(value)) {
15774 vals = value;
15775 } else {
15776 vals = [value];
15777 }
15778 if (type.evenMultiple && vals.length % 2 !== 0) {
15779 return null;
15780 }
15781 var valArr = [];
15782 var unitsArr = [];
15783 var pfValArr = [];
15784 var strVal = "";
15785 var hasEnum = false;
15786 for (var i2 = 0; i2 < vals.length; i2++) {
15787 var p2 = self2.parse(name2, vals[i2], propIsBypass, "multiple");
15788 hasEnum = hasEnum || string(p2.value);
15789 valArr.push(p2.value);
15790 pfValArr.push(p2.pfValue != null ? p2.pfValue : p2.value);
15791 unitsArr.push(p2.units);
15792 strVal += (i2 > 0 ? " " : "") + p2.strValue;
15793 }
15794 if (type.validate && !type.validate(valArr, unitsArr)) {
15795 return null;
15796 }
15797 if (type.singleEnum && hasEnum) {
15798 if (valArr.length === 1 && string(valArr[0])) {
15799 return {
15800 name: name2,
15801 value: valArr[0],
15802 strValue: valArr[0],
15803 bypass: propIsBypass
15804 };
15805 } else {
15806 return null;
15807 }
15808 }
15809 return {
15810 name: name2,
15811 value: valArr,
15812 pfValue: pfValArr,
15813 strValue: strVal,
15814 bypass: propIsBypass,
15815 units: unitsArr
15816 };
15817 }
15818 var checkEnums = function checkEnums2() {
15819 for (var _i = 0; _i < type.enums.length; _i++) {
15820 var en = type.enums[_i];
15821 if (en === value) {
15822 return {
15823 name: name2,
15824 value,
15825 strValue: "" + value,
15826 bypass: propIsBypass
15827 };
15828 }
15829 }
15830 return null;
15831 };
15832 if (type.number) {
15833 var units;
15834 var implicitUnits = "px";
15835 if (type.units) {
15836 units = type.units;
15837 }
15838 if (type.implicitUnits) {
15839 implicitUnits = type.implicitUnits;
15840 }
15841 if (!type.unitless) {
15842 if (valueIsString) {
15843 var unitsRegex = "px|em" + (type.allowPercent ? "|\\%" : "");
15844 if (units) {
15845 unitsRegex = units;
15846 }
15847 var match2 = value.match("^(" + number + ")(" + unitsRegex + ")?$");
15848 if (match2) {
15849 value = match2[1];
15850 units = match2[2] || implicitUnits;
15851 }
15852 } else if (!units || type.implicitUnits) {
15853 units = implicitUnits;
15854 }
15855 }
15856 value = parseFloat(value);
15857 if (isNaN(value) && type.enums === void 0) {
15858 return null;
15859 }
15860 if (isNaN(value) && type.enums !== void 0) {
15861 value = passedValue;
15862 return checkEnums();
15863 }
15864 if (type.integer && !integer(value)) {
15865 return null;
15866 }
15867 if (type.min !== void 0 && (value < type.min || type.strictMin && value === type.min) || type.max !== void 0 && (value > type.max || type.strictMax && value === type.max)) {
15868 return null;
15869 }
15870 var ret = {
15871 name: name2,
15872 value,
15873 strValue: "" + value + (units ? units : ""),
15874 units,
15875 bypass: propIsBypass
15876 };
15877 if (type.unitless || units !== "px" && units !== "em") {
15878 ret.pfValue = value;
15879 } else {
15880 ret.pfValue = units === "px" || !units ? value : this.getEmSizeInPixels() * value;
15881 }
15882 if (units === "ms" || units === "s") {
15883 ret.pfValue = units === "ms" ? value : 1e3 * value;
15884 }
15885 if (units === "deg" || units === "rad") {
15886 ret.pfValue = units === "rad" ? value : deg2rad(value);
15887 }
15888 if (units === "%") {
15889 ret.pfValue = value / 100;
15890 }
15891 return ret;
15892 } else if (type.propList) {
15893 var props = [];
15894 var propsStr = "" + value;
15895 if (propsStr === "none")
15896 ;
15897 else {
15898 var propsSplit = propsStr.split(/\s*,\s*|\s+/);
15899 for (var _i2 = 0; _i2 < propsSplit.length; _i2++) {
15900 var propName = propsSplit[_i2].trim();
15901 if (self2.properties[propName]) {
15902 props.push(propName);
15903 } else {
15904 warn("`" + propName + "` is not a valid property name");
15905 }
15906 }
15907 if (props.length === 0) {
15908 return null;
15909 }
15910 }
15911 return {
15912 name: name2,
15913 value: props,
15914 strValue: props.length === 0 ? "none" : props.join(" "),
15915 bypass: propIsBypass
15916 };
15917 } else if (type.color) {
15918 var tuple = color2tuple(value);
15919 if (!tuple) {
15920 return null;
15921 }
15922 return {
15923 name: name2,
15924 value: tuple,
15925 pfValue: tuple,
15926 strValue: "rgb(" + tuple[0] + "," + tuple[1] + "," + tuple[2] + ")",
15927 // n.b. no spaces b/c of multiple support
15928 bypass: propIsBypass
15929 };
15930 } else if (type.regex || type.regexes) {
15931 if (type.enums) {
15932 var enumProp = checkEnums();
15933 if (enumProp) {
15934 return enumProp;
15935 }
15936 }
15937 var regexes = type.regexes ? type.regexes : [type.regex];
15938 for (var _i3 = 0; _i3 < regexes.length; _i3++) {
15939 var regex = new RegExp(regexes[_i3]);
15940 var m = regex.exec(value);
15941 if (m) {
15942 return {
15943 name: name2,
15944 value: type.singleRegexMatchValue ? m[1] : m,
15945 strValue: "" + value,
15946 bypass: propIsBypass
15947 };
15948 }
15949 }
15950 return null;
15951 } else if (type.string) {
15952 return {
15953 name: name2,
15954 value: "" + value,
15955 strValue: "" + value,
15956 bypass: propIsBypass
15957 };
15958 } else if (type.enums) {
15959 return checkEnums();
15960 } else {
15961 return null;
15962 }
15963 };
15964 var Style = function Style2(cy) {
15965 if (!(this instanceof Style2)) {
15966 return new Style2(cy);
15967 }
15968 if (!core(cy)) {
15969 error("A style must have a core reference");
15970 return;
15971 }
15972 this._private = {
15973 cy,
15974 coreStyle: {}
15975 };
15976 this.length = 0;
15977 this.resetToDefault();
15978 };
15979 var styfn = Style.prototype;
15980 styfn.instanceString = function() {
15981 return "style";
15982 };
15983 styfn.clear = function() {
15984 var _p = this._private;
15985 var cy = _p.cy;
15986 var eles = cy.elements();
15987 for (var i2 = 0; i2 < this.length; i2++) {
15988 this[i2] = void 0;
15989 }
15990 this.length = 0;
15991 _p.contextStyles = {};
15992 _p.propDiffs = {};
15993 this.cleanElements(eles, true);
15994 eles.forEach(function(ele) {
15995 var ele_p = ele[0]._private;
15996 ele_p.styleDirty = true;
15997 ele_p.appliedInitStyle = false;
15998 });
15999 return this;
16000 };
16001 styfn.resetToDefault = function() {
16002 this.clear();
16003 this.addDefaultStylesheet();
16004 return this;
16005 };
16006 styfn.core = function(propName) {
16007 return this._private.coreStyle[propName] || this.getDefaultProperty(propName);
16008 };
16009 styfn.selector = function(selectorStr) {
16010 var selector = selectorStr === "core" ? null : new Selector(selectorStr);
16011 var i2 = this.length++;
16012 this[i2] = {
16013 selector,
16014 properties: [],
16015 mappedProperties: [],
16016 index: i2
16017 };
16018 return this;
16019 };
16020 styfn.css = function() {
16021 var self2 = this;
16022 var args = arguments;
16023 if (args.length === 1) {
16024 var map = args[0];
16025 for (var i2 = 0; i2 < self2.properties.length; i2++) {
16026 var prop = self2.properties[i2];
16027 var mapVal = map[prop.name];
16028 if (mapVal === void 0) {
16029 mapVal = map[dash2camel(prop.name)];
16030 }
16031 if (mapVal !== void 0) {
16032 this.cssRule(prop.name, mapVal);
16033 }
16034 }
16035 } else if (args.length === 2) {
16036 this.cssRule(args[0], args[1]);
16037 }
16038 return this;
16039 };
16040 styfn.style = styfn.css;
16041 styfn.cssRule = function(name2, value) {
16042 var property = this.parse(name2, value);
16043 if (property) {
16044 var i2 = this.length - 1;
16045 this[i2].properties.push(property);
16046 this[i2].properties[property.name] = property;
16047 if (property.name.match(/pie-(\d+)-background-size/) && property.value) {
16048 this._private.hasPie = true;
16049 }
16050 if (property.mapped) {
16051 this[i2].mappedProperties.push(property);
16052 }
16053 var currentSelectorIsCore = !this[i2].selector;
16054 if (currentSelectorIsCore) {
16055 this._private.coreStyle[property.name] = property;
16056 }
16057 }
16058 return this;
16059 };
16060 styfn.append = function(style) {
16061 if (stylesheet(style)) {
16062 style.appendToStyle(this);
16063 } else if (array(style)) {
16064 this.appendFromJson(style);
16065 } else if (string(style)) {
16066 this.appendFromString(style);
16067 }
16068 return this;
16069 };
16070 Style.fromJson = function(cy, json) {
16071 var style = new Style(cy);
16072 style.fromJson(json);
16073 return style;
16074 };
16075 Style.fromString = function(cy, string2) {
16076 return new Style(cy).fromString(string2);
16077 };
16078 [styfn$8, styfn$7, styfn$6, styfn$5, styfn$4, styfn$3, styfn$2, styfn$1].forEach(function(props) {
16079 extend(styfn, props);
16080 });
16081 Style.types = styfn.types;
16082 Style.properties = styfn.properties;
16083 Style.propertyGroups = styfn.propertyGroups;
16084 Style.propertyGroupNames = styfn.propertyGroupNames;
16085 Style.propertyGroupKeys = styfn.propertyGroupKeys;
16086 var corefn$2 = {
16087 style: function style(newStyle) {
16088 if (newStyle) {
16089 var s = this.setStyle(newStyle);
16090 s.update();
16091 }
16092 return this._private.style;
16093 },
16094 setStyle: function setStyle(style) {
16095 var _p = this._private;
16096 if (stylesheet(style)) {
16097 _p.style = style.generateStyle(this);
16098 } else if (array(style)) {
16099 _p.style = Style.fromJson(this, style);
16100 } else if (string(style)) {
16101 _p.style = Style.fromString(this, style);
16102 } else {
16103 _p.style = Style(this);
16104 }
16105 return _p.style;
16106 },
16107 // e.g. cy.data() changed => recalc ele mappers
16108 updateStyle: function updateStyle() {
16109 this.mutableElements().updateStyle();
16110 }
16111 };
16112 var defaultSelectionType = "single";
16113 var corefn$1 = {
16114 autolock: function autolock(bool) {
16115 if (bool !== void 0) {
16116 this._private.autolock = bool ? true : false;
16117 } else {
16118 return this._private.autolock;
16119 }
16120 return this;
16121 },
16122 autoungrabify: function autoungrabify(bool) {
16123 if (bool !== void 0) {
16124 this._private.autoungrabify = bool ? true : false;
16125 } else {
16126 return this._private.autoungrabify;
16127 }
16128 return this;
16129 },
16130 autounselectify: function autounselectify(bool) {
16131 if (bool !== void 0) {
16132 this._private.autounselectify = bool ? true : false;
16133 } else {
16134 return this._private.autounselectify;
16135 }
16136 return this;
16137 },
16138 selectionType: function selectionType(selType) {
16139 var _p = this._private;
16140 if (_p.selectionType == null) {
16141 _p.selectionType = defaultSelectionType;
16142 }
16143 if (selType !== void 0) {
16144 if (selType === "additive" || selType === "single") {
16145 _p.selectionType = selType;
16146 }
16147 } else {
16148 return _p.selectionType;
16149 }
16150 return this;
16151 },
16152 panningEnabled: function panningEnabled(bool) {
16153 if (bool !== void 0) {
16154 this._private.panningEnabled = bool ? true : false;
16155 } else {
16156 return this._private.panningEnabled;
16157 }
16158 return this;
16159 },
16160 userPanningEnabled: function userPanningEnabled(bool) {
16161 if (bool !== void 0) {
16162 this._private.userPanningEnabled = bool ? true : false;
16163 } else {
16164 return this._private.userPanningEnabled;
16165 }
16166 return this;
16167 },
16168 zoomingEnabled: function zoomingEnabled(bool) {
16169 if (bool !== void 0) {
16170 this._private.zoomingEnabled = bool ? true : false;
16171 } else {
16172 return this._private.zoomingEnabled;
16173 }
16174 return this;
16175 },
16176 userZoomingEnabled: function userZoomingEnabled(bool) {
16177 if (bool !== void 0) {
16178 this._private.userZoomingEnabled = bool ? true : false;
16179 } else {
16180 return this._private.userZoomingEnabled;
16181 }
16182 return this;
16183 },
16184 boxSelectionEnabled: function boxSelectionEnabled(bool) {
16185 if (bool !== void 0) {
16186 this._private.boxSelectionEnabled = bool ? true : false;
16187 } else {
16188 return this._private.boxSelectionEnabled;
16189 }
16190 return this;
16191 },
16192 pan: function pan() {
16193 var args = arguments;
16194 var pan2 = this._private.pan;
16195 var dim, val, dims, x, y;
16196 switch (args.length) {
16197 case 0:
16198 return pan2;
16199 case 1:
16200 if (string(args[0])) {
16201 dim = args[0];
16202 return pan2[dim];
16203 } else if (plainObject(args[0])) {
16204 if (!this._private.panningEnabled) {
16205 return this;
16206 }
16207 dims = args[0];
16208 x = dims.x;
16209 y = dims.y;
16210 if (number$1(x)) {
16211 pan2.x = x;
16212 }
16213 if (number$1(y)) {
16214 pan2.y = y;
16215 }
16216 this.emit("pan viewport");
16217 }
16218 break;
16219 case 2:
16220 if (!this._private.panningEnabled) {
16221 return this;
16222 }
16223 dim = args[0];
16224 val = args[1];
16225 if ((dim === "x" || dim === "y") && number$1(val)) {
16226 pan2[dim] = val;
16227 }
16228 this.emit("pan viewport");
16229 break;
16230 }
16231 this.notify("viewport");
16232 return this;
16233 },
16234 panBy: function panBy(arg0, arg1) {
16235 var args = arguments;
16236 var pan = this._private.pan;
16237 var dim, val, dims, x, y;
16238 if (!this._private.panningEnabled) {
16239 return this;
16240 }
16241 switch (args.length) {
16242 case 1:
16243 if (plainObject(arg0)) {
16244 dims = args[0];
16245 x = dims.x;
16246 y = dims.y;
16247 if (number$1(x)) {
16248 pan.x += x;
16249 }
16250 if (number$1(y)) {
16251 pan.y += y;
16252 }
16253 this.emit("pan viewport");
16254 }
16255 break;
16256 case 2:
16257 dim = arg0;
16258 val = arg1;
16259 if ((dim === "x" || dim === "y") && number$1(val)) {
16260 pan[dim] += val;
16261 }
16262 this.emit("pan viewport");
16263 break;
16264 }
16265 this.notify("viewport");
16266 return this;
16267 },
16268 fit: function fit(elements2, padding) {
16269 var viewportState = this.getFitViewport(elements2, padding);
16270 if (viewportState) {
16271 var _p = this._private;
16272 _p.zoom = viewportState.zoom;
16273 _p.pan = viewportState.pan;
16274 this.emit("pan zoom viewport");
16275 this.notify("viewport");
16276 }
16277 return this;
16278 },
16279 getFitViewport: function getFitViewport(elements2, padding) {
16280 if (number$1(elements2) && padding === void 0) {
16281 padding = elements2;
16282 elements2 = void 0;
16283 }
16284 if (!this._private.panningEnabled || !this._private.zoomingEnabled) {
16285 return;
16286 }
16287 var bb;
16288 if (string(elements2)) {
16289 var sel = elements2;
16290 elements2 = this.$(sel);
16291 } else if (boundingBox(elements2)) {
16292 var bbe = elements2;
16293 bb = {
16294 x1: bbe.x1,
16295 y1: bbe.y1,
16296 x2: bbe.x2,
16297 y2: bbe.y2
16298 };
16299 bb.w = bb.x2 - bb.x1;
16300 bb.h = bb.y2 - bb.y1;
16301 } else if (!elementOrCollection(elements2)) {
16302 elements2 = this.mutableElements();
16303 }
16304 if (elementOrCollection(elements2) && elements2.empty()) {
16305 return;
16306 }
16307 bb = bb || elements2.boundingBox();
16308 var w = this.width();
16309 var h = this.height();
16310 var zoom;
16311 padding = number$1(padding) ? padding : 0;
16312 if (!isNaN(w) && !isNaN(h) && w > 0 && h > 0 && !isNaN(bb.w) && !isNaN(bb.h) && bb.w > 0 && bb.h > 0) {
16313 zoom = Math.min((w - 2 * padding) / bb.w, (h - 2 * padding) / bb.h);
16314 zoom = zoom > this._private.maxZoom ? this._private.maxZoom : zoom;
16315 zoom = zoom < this._private.minZoom ? this._private.minZoom : zoom;
16316 var pan = {
16317 // now pan to middle
16318 x: (w - zoom * (bb.x1 + bb.x2)) / 2,
16319 y: (h - zoom * (bb.y1 + bb.y2)) / 2
16320 };
16321 return {
16322 zoom,
16323 pan
16324 };
16325 }
16326 return;
16327 },
16328 zoomRange: function zoomRange(min2, max2) {
16329 var _p = this._private;
16330 if (max2 == null) {
16331 var opts = min2;
16332 min2 = opts.min;
16333 max2 = opts.max;
16334 }
16335 if (number$1(min2) && number$1(max2) && min2 <= max2) {
16336 _p.minZoom = min2;
16337 _p.maxZoom = max2;
16338 } else if (number$1(min2) && max2 === void 0 && min2 <= _p.maxZoom) {
16339 _p.minZoom = min2;
16340 } else if (number$1(max2) && min2 === void 0 && max2 >= _p.minZoom) {
16341 _p.maxZoom = max2;
16342 }
16343 return this;
16344 },
16345 minZoom: function minZoom(zoom) {
16346 if (zoom === void 0) {
16347 return this._private.minZoom;
16348 } else {
16349 return this.zoomRange({
16350 min: zoom
16351 });
16352 }
16353 },
16354 maxZoom: function maxZoom2(zoom) {
16355 if (zoom === void 0) {
16356 return this._private.maxZoom;
16357 } else {
16358 return this.zoomRange({
16359 max: zoom
16360 });
16361 }
16362 },
16363 getZoomedViewport: function getZoomedViewport(params) {
16364 var _p = this._private;
16365 var currentPan = _p.pan;
16366 var currentZoom = _p.zoom;
16367 var pos;
16368 var zoom;
16369 var bail = false;
16370 if (!_p.zoomingEnabled) {
16371 bail = true;
16372 }
16373 if (number$1(params)) {
16374 zoom = params;
16375 } else if (plainObject(params)) {
16376 zoom = params.level;
16377 if (params.position != null) {
16378 pos = modelToRenderedPosition(params.position, currentZoom, currentPan);
16379 } else if (params.renderedPosition != null) {
16380 pos = params.renderedPosition;
16381 }
16382 if (pos != null && !_p.panningEnabled) {
16383 bail = true;
16384 }
16385 }
16386 zoom = zoom > _p.maxZoom ? _p.maxZoom : zoom;
16387 zoom = zoom < _p.minZoom ? _p.minZoom : zoom;
16388 if (bail || !number$1(zoom) || zoom === currentZoom || pos != null && (!number$1(pos.x) || !number$1(pos.y))) {
16389 return null;
16390 }
16391 if (pos != null) {
16392 var pan1 = currentPan;
16393 var zoom1 = currentZoom;
16394 var zoom2 = zoom;
16395 var pan2 = {
16396 x: -zoom2 / zoom1 * (pos.x - pan1.x) + pos.x,
16397 y: -zoom2 / zoom1 * (pos.y - pan1.y) + pos.y
16398 };
16399 return {
16400 zoomed: true,
16401 panned: true,
16402 zoom: zoom2,
16403 pan: pan2
16404 };
16405 } else {
16406 return {
16407 zoomed: true,
16408 panned: false,
16409 zoom,
16410 pan: currentPan
16411 };
16412 }
16413 },
16414 zoom: function zoom(params) {
16415 if (params === void 0) {
16416 return this._private.zoom;
16417 } else {
16418 var vp = this.getZoomedViewport(params);
16419 var _p = this._private;
16420 if (vp == null || !vp.zoomed) {
16421 return this;
16422 }
16423 _p.zoom = vp.zoom;
16424 if (vp.panned) {
16425 _p.pan.x = vp.pan.x;
16426 _p.pan.y = vp.pan.y;
16427 }
16428 this.emit("zoom" + (vp.panned ? " pan" : "") + " viewport");
16429 this.notify("viewport");
16430 return this;
16431 }
16432 },
16433 viewport: function viewport(opts) {
16434 var _p = this._private;
16435 var zoomDefd = true;
16436 var panDefd = true;
16437 var events = [];
16438 var zoomFailed = false;
16439 var panFailed = false;
16440 if (!opts) {
16441 return this;
16442 }
16443 if (!number$1(opts.zoom)) {
16444 zoomDefd = false;
16445 }
16446 if (!plainObject(opts.pan)) {
16447 panDefd = false;
16448 }
16449 if (!zoomDefd && !panDefd) {
16450 return this;
16451 }
16452 if (zoomDefd) {
16453 var z = opts.zoom;
16454 if (z < _p.minZoom || z > _p.maxZoom || !_p.zoomingEnabled) {
16455 zoomFailed = true;
16456 } else {
16457 _p.zoom = z;
16458 events.push("zoom");
16459 }
16460 }
16461 if (panDefd && (!zoomFailed || !opts.cancelOnFailedZoom) && _p.panningEnabled) {
16462 var p2 = opts.pan;
16463 if (number$1(p2.x)) {
16464 _p.pan.x = p2.x;
16465 panFailed = false;
16466 }
16467 if (number$1(p2.y)) {
16468 _p.pan.y = p2.y;
16469 panFailed = false;
16470 }
16471 if (!panFailed) {
16472 events.push("pan");
16473 }
16474 }
16475 if (events.length > 0) {
16476 events.push("viewport");
16477 this.emit(events.join(" "));
16478 this.notify("viewport");
16479 }
16480 return this;
16481 },
16482 center: function center(elements2) {
16483 var pan = this.getCenterPan(elements2);
16484 if (pan) {
16485 this._private.pan = pan;
16486 this.emit("pan viewport");
16487 this.notify("viewport");
16488 }
16489 return this;
16490 },
16491 getCenterPan: function getCenterPan(elements2, zoom) {
16492 if (!this._private.panningEnabled) {
16493 return;
16494 }
16495 if (string(elements2)) {
16496 var selector = elements2;
16497 elements2 = this.mutableElements().filter(selector);
16498 } else if (!elementOrCollection(elements2)) {
16499 elements2 = this.mutableElements();
16500 }
16501 if (elements2.length === 0) {
16502 return;
16503 }
16504 var bb = elements2.boundingBox();
16505 var w = this.width();
16506 var h = this.height();
16507 zoom = zoom === void 0 ? this._private.zoom : zoom;
16508 var pan = {
16509 // middle
16510 x: (w - zoom * (bb.x1 + bb.x2)) / 2,
16511 y: (h - zoom * (bb.y1 + bb.y2)) / 2
16512 };
16513 return pan;
16514 },
16515 reset: function reset() {
16516 if (!this._private.panningEnabled || !this._private.zoomingEnabled) {
16517 return this;
16518 }
16519 this.viewport({
16520 pan: {
16521 x: 0,
16522 y: 0
16523 },
16524 zoom: 1
16525 });
16526 return this;
16527 },
16528 invalidateSize: function invalidateSize() {
16529 this._private.sizeCache = null;
16530 },
16531 size: function size() {
16532 var _p = this._private;
16533 var container = _p.container;
16534 return _p.sizeCache = _p.sizeCache || (container ? function() {
16535 var style = window$1.getComputedStyle(container);
16536 var val = function val2(name2) {
16537 return parseFloat(style.getPropertyValue(name2));
16538 };
16539 return {
16540 width: container.clientWidth - val("padding-left") - val("padding-right"),
16541 height: container.clientHeight - val("padding-top") - val("padding-bottom")
16542 };
16543 }() : {
16544 // fallback if no container (not 0 b/c can be used for dividing etc)
16545 width: 1,
16546 height: 1
16547 });
16548 },
16549 width: function width() {
16550 return this.size().width;
16551 },
16552 height: function height() {
16553 return this.size().height;
16554 },
16555 extent: function extent() {
16556 var pan = this._private.pan;
16557 var zoom = this._private.zoom;
16558 var rb = this.renderedExtent();
16559 var b = {
16560 x1: (rb.x1 - pan.x) / zoom,
16561 x2: (rb.x2 - pan.x) / zoom,
16562 y1: (rb.y1 - pan.y) / zoom,
16563 y2: (rb.y2 - pan.y) / zoom
16564 };
16565 b.w = b.x2 - b.x1;
16566 b.h = b.y2 - b.y1;
16567 return b;
16568 },
16569 renderedExtent: function renderedExtent() {
16570 var width = this.width();
16571 var height = this.height();
16572 return {
16573 x1: 0,
16574 y1: 0,
16575 x2: width,
16576 y2: height,
16577 w: width,
16578 h: height
16579 };
16580 },
16581 multiClickDebounceTime: function multiClickDebounceTime(_int) {
16582 if (_int)
16583 this._private.multiClickDebounceTime = _int;
16584 else
16585 return this._private.multiClickDebounceTime;
16586 return this;
16587 }
16588 };
16589 corefn$1.centre = corefn$1.center;
16590 corefn$1.autolockNodes = corefn$1.autolock;
16591 corefn$1.autoungrabifyNodes = corefn$1.autoungrabify;
16592 var fn = {
16593 data: define.data({
16594 field: "data",
16595 bindingEvent: "data",
16596 allowBinding: true,
16597 allowSetting: true,
16598 settingEvent: "data",
16599 settingTriggersEvent: true,
16600 triggerFnName: "trigger",
16601 allowGetting: true,
16602 updateStyle: true
16603 }),
16604 removeData: define.removeData({
16605 field: "data",
16606 event: "data",
16607 triggerFnName: "trigger",
16608 triggerEvent: true,
16609 updateStyle: true
16610 }),
16611 scratch: define.data({
16612 field: "scratch",
16613 bindingEvent: "scratch",
16614 allowBinding: true,
16615 allowSetting: true,
16616 settingEvent: "scratch",
16617 settingTriggersEvent: true,
16618 triggerFnName: "trigger",
16619 allowGetting: true,
16620 updateStyle: true
16621 }),
16622 removeScratch: define.removeData({
16623 field: "scratch",
16624 event: "scratch",
16625 triggerFnName: "trigger",
16626 triggerEvent: true,
16627 updateStyle: true
16628 })
16629 };
16630 fn.attr = fn.data;
16631 fn.removeAttr = fn.removeData;
16632 var Core = function Core2(opts) {
16633 var cy = this;
16634 opts = extend({}, opts);
16635 var container = opts.container;
16636 if (container && !htmlElement(container) && htmlElement(container[0])) {
16637 container = container[0];
16638 }
16639 var reg = container ? container._cyreg : null;
16640 reg = reg || {};
16641 if (reg && reg.cy) {
16642 reg.cy.destroy();
16643 reg = {};
16644 }
16645 var readies = reg.readies = reg.readies || [];
16646 if (container) {
16647 container._cyreg = reg;
16648 }
16649 reg.cy = cy;
16650 var head = window$1 !== void 0 && container !== void 0 && !opts.headless;
16651 var options = opts;
16652 options.layout = extend({
16653 name: head ? "grid" : "null"
16654 }, options.layout);
16655 options.renderer = extend({
16656 name: head ? "canvas" : "null"
16657 }, options.renderer);
16658 var defVal = function defVal2(def, val, altVal) {
16659 if (val !== void 0) {
16660 return val;
16661 } else if (altVal !== void 0) {
16662 return altVal;
16663 } else {
16664 return def;
16665 }
16666 };
16667 var _p = this._private = {
16668 container,
16669 // html dom ele container
16670 ready: false,
16671 // whether ready has been triggered
16672 options,
16673 // cached options
16674 elements: new Collection(this),
16675 // elements in the graph
16676 listeners: [],
16677 // list of listeners
16678 aniEles: new Collection(this),
16679 // elements being animated
16680 data: options.data || {},
16681 // data for the core
16682 scratch: {},
16683 // scratch object for core
16684 layout: null,
16685 renderer: null,
16686 destroyed: false,
16687 // whether destroy was called
16688 notificationsEnabled: true,
16689 // whether notifications are sent to the renderer
16690 minZoom: 1e-50,
16691 maxZoom: 1e50,
16692 zoomingEnabled: defVal(true, options.zoomingEnabled),
16693 userZoomingEnabled: defVal(true, options.userZoomingEnabled),
16694 panningEnabled: defVal(true, options.panningEnabled),
16695 userPanningEnabled: defVal(true, options.userPanningEnabled),
16696 boxSelectionEnabled: defVal(true, options.boxSelectionEnabled),
16697 autolock: defVal(false, options.autolock, options.autolockNodes),
16698 autoungrabify: defVal(false, options.autoungrabify, options.autoungrabifyNodes),
16699 autounselectify: defVal(false, options.autounselectify),
16700 styleEnabled: options.styleEnabled === void 0 ? head : options.styleEnabled,
16701 zoom: number$1(options.zoom) ? options.zoom : 1,
16702 pan: {
16703 x: plainObject(options.pan) && number$1(options.pan.x) ? options.pan.x : 0,
16704 y: plainObject(options.pan) && number$1(options.pan.y) ? options.pan.y : 0
16705 },
16706 animation: {
16707 // object for currently-running animations
16708 current: [],
16709 queue: []
16710 },
16711 hasCompoundNodes: false,
16712 multiClickDebounceTime: defVal(250, options.multiClickDebounceTime)
16713 };
16714 this.createEmitter();
16715 this.selectionType(options.selectionType);
16716 this.zoomRange({
16717 min: options.minZoom,
16718 max: options.maxZoom
16719 });
16720 var loadExtData = function loadExtData2(extData, next2) {
16721 var anyIsPromise = extData.some(promise);
16722 if (anyIsPromise) {
16723 return Promise$1.all(extData).then(next2);
16724 } else {
16725 next2(extData);
16726 }
16727 };
16728 if (_p.styleEnabled) {
16729 cy.setStyle([]);
16730 }
16731 var rendererOptions = extend({}, options, options.renderer);
16732 cy.initRenderer(rendererOptions);
16733 var setElesAndLayout = function setElesAndLayout2(elements2, onload, ondone) {
16734 cy.notifications(false);
16735 var oldEles = cy.mutableElements();
16736 if (oldEles.length > 0) {
16737 oldEles.remove();
16738 }
16739 if (elements2 != null) {
16740 if (plainObject(elements2) || array(elements2)) {
16741 cy.add(elements2);
16742 }
16743 }
16744 cy.one("layoutready", function(e) {
16745 cy.notifications(true);
16746 cy.emit(e);
16747 cy.one("load", onload);
16748 cy.emitAndNotify("load");
16749 }).one("layoutstop", function() {
16750 cy.one("done", ondone);
16751 cy.emit("done");
16752 });
16753 var layoutOpts = extend({}, cy._private.options.layout);
16754 layoutOpts.eles = cy.elements();
16755 cy.layout(layoutOpts).run();
16756 };
16757 loadExtData([options.style, options.elements], function(thens) {
16758 var initStyle = thens[0];
16759 var initEles = thens[1];
16760 if (_p.styleEnabled) {
16761 cy.style().append(initStyle);
16762 }
16763 setElesAndLayout(initEles, function() {
16764 cy.startAnimationLoop();
16765 _p.ready = true;
16766 if (fn$6(options.ready)) {
16767 cy.on("ready", options.ready);
16768 }
16769 for (var i2 = 0; i2 < readies.length; i2++) {
16770 var fn2 = readies[i2];
16771 cy.on("ready", fn2);
16772 }
16773 if (reg) {
16774 reg.readies = [];
16775 }
16776 cy.emit("ready");
16777 }, options.done);
16778 });
16779 };
16780 var corefn = Core.prototype;
16781 extend(corefn, {
16782 instanceString: function instanceString() {
16783 return "core";
16784 },
16785 isReady: function isReady() {
16786 return this._private.ready;
16787 },
16788 destroyed: function destroyed() {
16789 return this._private.destroyed;
16790 },
16791 ready: function ready(fn2) {
16792 if (this.isReady()) {
16793 this.emitter().emit("ready", [], fn2);
16794 } else {
16795 this.on("ready", fn2);
16796 }
16797 return this;
16798 },
16799 destroy: function destroy() {
16800 var cy = this;
16801 if (cy.destroyed())
16802 return;
16803 cy.stopAnimationLoop();
16804 cy.destroyRenderer();
16805 this.emit("destroy");
16806 cy._private.destroyed = true;
16807 return cy;
16808 },
16809 hasElementWithId: function hasElementWithId(id) {
16810 return this._private.elements.hasElementWithId(id);
16811 },
16812 getElementById: function getElementById2(id) {
16813 return this._private.elements.getElementById(id);
16814 },
16815 hasCompoundNodes: function hasCompoundNodes() {
16816 return this._private.hasCompoundNodes;
16817 },
16818 headless: function headless() {
16819 return this._private.renderer.isHeadless();
16820 },
16821 styleEnabled: function styleEnabled() {
16822 return this._private.styleEnabled;
16823 },
16824 addToPool: function addToPool(eles) {
16825 this._private.elements.merge(eles);
16826 return this;
16827 },
16828 removeFromPool: function removeFromPool(eles) {
16829 this._private.elements.unmerge(eles);
16830 return this;
16831 },
16832 container: function container() {
16833 return this._private.container || null;
16834 },
16835 mount: function mount(container) {
16836 if (container == null) {
16837 return;
16838 }
16839 var cy = this;
16840 var _p = cy._private;
16841 var options = _p.options;
16842 if (!htmlElement(container) && htmlElement(container[0])) {
16843 container = container[0];
16844 }
16845 cy.stopAnimationLoop();
16846 cy.destroyRenderer();
16847 _p.container = container;
16848 _p.styleEnabled = true;
16849 cy.invalidateSize();
16850 cy.initRenderer(extend({}, options, options.renderer, {
16851 // allow custom renderer name to be re-used, otherwise use canvas
16852 name: options.renderer.name === "null" ? "canvas" : options.renderer.name
16853 }));
16854 cy.startAnimationLoop();
16855 cy.style(options.style);
16856 cy.emit("mount");
16857 return cy;
16858 },
16859 unmount: function unmount() {
16860 var cy = this;
16861 cy.stopAnimationLoop();
16862 cy.destroyRenderer();
16863 cy.initRenderer({
16864 name: "null"
16865 });
16866 cy.emit("unmount");
16867 return cy;
16868 },
16869 options: function options() {
16870 return copy(this._private.options);
16871 },
16872 json: function json(obj) {
16873 var cy = this;
16874 var _p = cy._private;
16875 var eles = cy.mutableElements();
16876 var getFreshRef = function getFreshRef2(ele) {
16877 return cy.getElementById(ele.id());
16878 };
16879 if (plainObject(obj)) {
16880 cy.startBatch();
16881 if (obj.elements) {
16882 var idInJson = {};
16883 var updateEles = function updateEles2(jsons, gr2) {
16884 var toAdd = [];
16885 var toMod = [];
16886 for (var i3 = 0; i3 < jsons.length; i3++) {
16887 var json3 = jsons[i3];
16888 if (!json3.data.id) {
16889 warn("cy.json() cannot handle elements without an ID attribute");
16890 continue;
16891 }
16892 var id = "" + json3.data.id;
16893 var ele = cy.getElementById(id);
16894 idInJson[id] = true;
16895 if (ele.length !== 0) {
16896 toMod.push({
16897 ele,
16898 json: json3
16899 });
16900 } else {
16901 if (gr2) {
16902 json3.group = gr2;
16903 toAdd.push(json3);
16904 } else {
16905 toAdd.push(json3);
16906 }
16907 }
16908 }
16909 cy.add(toAdd);
16910 for (var _i = 0; _i < toMod.length; _i++) {
16911 var _toMod$_i = toMod[_i], _ele = _toMod$_i.ele, _json = _toMod$_i.json;
16912 _ele.json(_json);
16913 }
16914 };
16915 if (array(obj.elements)) {
16916 updateEles(obj.elements);
16917 } else {
16918 var grs = ["nodes", "edges"];
16919 for (var i2 = 0; i2 < grs.length; i2++) {
16920 var gr = grs[i2];
16921 var elements2 = obj.elements[gr];
16922 if (array(elements2)) {
16923 updateEles(elements2, gr);
16924 }
16925 }
16926 }
16927 var parentsToRemove = cy.collection();
16928 eles.filter(function(ele) {
16929 return !idInJson[ele.id()];
16930 }).forEach(function(ele) {
16931 if (ele.isParent()) {
16932 parentsToRemove.merge(ele);
16933 } else {
16934 ele.remove();
16935 }
16936 });
16937 parentsToRemove.forEach(function(ele) {
16938 return ele.children().move({
16939 parent: null
16940 });
16941 });
16942 parentsToRemove.forEach(function(ele) {
16943 return getFreshRef(ele).remove();
16944 });
16945 }
16946 if (obj.style) {
16947 cy.style(obj.style);
16948 }
16949 if (obj.zoom != null && obj.zoom !== _p.zoom) {
16950 cy.zoom(obj.zoom);
16951 }
16952 if (obj.pan) {
16953 if (obj.pan.x !== _p.pan.x || obj.pan.y !== _p.pan.y) {
16954 cy.pan(obj.pan);
16955 }
16956 }
16957 if (obj.data) {
16958 cy.data(obj.data);
16959 }
16960 var fields = ["minZoom", "maxZoom", "zoomingEnabled", "userZoomingEnabled", "panningEnabled", "userPanningEnabled", "boxSelectionEnabled", "autolock", "autoungrabify", "autounselectify", "multiClickDebounceTime"];
16961 for (var _i2 = 0; _i2 < fields.length; _i2++) {
16962 var f = fields[_i2];
16963 if (obj[f] != null) {
16964 cy[f](obj[f]);
16965 }
16966 }
16967 cy.endBatch();
16968 return this;
16969 } else {
16970 var flat = !!obj;
16971 var json2 = {};
16972 if (flat) {
16973 json2.elements = this.elements().map(function(ele) {
16974 return ele.json();
16975 });
16976 } else {
16977 json2.elements = {};
16978 eles.forEach(function(ele) {
16979 var group = ele.group();
16980 if (!json2.elements[group]) {
16981 json2.elements[group] = [];
16982 }
16983 json2.elements[group].push(ele.json());
16984 });
16985 }
16986 if (this._private.styleEnabled) {
16987 json2.style = cy.style().json();
16988 }
16989 json2.data = copy(cy.data());
16990 var options = _p.options;
16991 json2.zoomingEnabled = _p.zoomingEnabled;
16992 json2.userZoomingEnabled = _p.userZoomingEnabled;
16993 json2.zoom = _p.zoom;
16994 json2.minZoom = _p.minZoom;
16995 json2.maxZoom = _p.maxZoom;
16996 json2.panningEnabled = _p.panningEnabled;
16997 json2.userPanningEnabled = _p.userPanningEnabled;
16998 json2.pan = copy(_p.pan);
16999 json2.boxSelectionEnabled = _p.boxSelectionEnabled;
17000 json2.renderer = copy(options.renderer);
17001 json2.hideEdgesOnViewport = options.hideEdgesOnViewport;
17002 json2.textureOnViewport = options.textureOnViewport;
17003 json2.wheelSensitivity = options.wheelSensitivity;
17004 json2.motionBlur = options.motionBlur;
17005 json2.multiClickDebounceTime = options.multiClickDebounceTime;
17006 return json2;
17007 }
17008 }
17009 });
17010 corefn.$id = corefn.getElementById;
17011 [corefn$9, corefn$8, elesfn, corefn$7, corefn$6, corefn$5, corefn$4, corefn$3, corefn$2, corefn$1, fn].forEach(function(props) {
17012 extend(corefn, props);
17013 });
17014 var defaults$7 = {
17015 fit: true,
17016 // whether to fit the viewport to the graph
17017 directed: false,
17018 // whether the tree is directed downwards (or edges can point in any direction if false)
17019 padding: 30,
17020 // padding on fit
17021 circle: false,
17022 // put depths in concentric circles if true, put depths top down if false
17023 grid: false,
17024 // whether to create an even grid into which the DAG is placed (circle:false only)
17025 spacingFactor: 1.75,
17026 // positive spacing factor, larger => more space between nodes (N.B. n/a if causes overlap)
17027 boundingBox: void 0,
17028 // constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
17029 avoidOverlap: true,
17030 // prevents node overlap, may overflow boundingBox if not enough space
17031 nodeDimensionsIncludeLabels: false,
17032 // Excludes the label when calculating node bounding boxes for the layout algorithm
17033 roots: void 0,
17034 // the roots of the trees
17035 maximal: false,
17036 // whether to shift nodes down their natural BFS depths in order to avoid upwards edges (DAGS only)
17037 depthSort: void 0,
17038 // a sorting function to order nodes at equal depth. e.g. function(a, b){ return a.data('weight') - b.data('weight') }
17039 animate: false,
17040 // whether to transition the node positions
17041 animationDuration: 500,
17042 // duration of animation in ms if enabled
17043 animationEasing: void 0,
17044 // easing of animation if enabled,
17045 animateFilter: function animateFilter(node, i2) {
17046 return true;
17047 },
17048 // a function that determines whether the node should be animated. All nodes animated by default on animate enabled. Non-animated nodes are positioned immediately when the layout starts
17049 ready: void 0,
17050 // callback on layoutready
17051 stop: void 0,
17052 // callback on layoutstop
17053 transform: function transform(node, position2) {
17054 return position2;
17055 }
17056 // transform a given node position. Useful for changing flow direction in discrete layouts
17057 };
17058 var getInfo = function getInfo2(ele) {
17059 return ele.scratch("breadthfirst");
17060 };
17061 var setInfo = function setInfo2(ele, obj) {
17062 return ele.scratch("breadthfirst", obj);
17063 };
17064 function BreadthFirstLayout(options) {
17065 this.options = extend({}, defaults$7, options);
17066 }
17067 BreadthFirstLayout.prototype.run = function() {
17068 var params = this.options;
17069 var options = params;
17070 var cy = params.cy;
17071 var eles = options.eles;
17072 var nodes2 = eles.nodes().filter(function(n2) {
17073 return !n2.isParent();
17074 });
17075 var graph = eles;
17076 var directed = options.directed;
17077 var maximal = options.maximal || options.maximalAdjustments > 0;
17078 var bb = makeBoundingBox(options.boundingBox ? options.boundingBox : {
17079 x1: 0,
17080 y1: 0,
17081 w: cy.width(),
17082 h: cy.height()
17083 });
17084 var roots;
17085 if (elementOrCollection(options.roots)) {
17086 roots = options.roots;
17087 } else if (array(options.roots)) {
17088 var rootsArray = [];
17089 for (var i2 = 0; i2 < options.roots.length; i2++) {
17090 var id = options.roots[i2];
17091 var ele = cy.getElementById(id);
17092 rootsArray.push(ele);
17093 }
17094 roots = cy.collection(rootsArray);
17095 } else if (string(options.roots)) {
17096 roots = cy.$(options.roots);
17097 } else {
17098 if (directed) {
17099 roots = nodes2.roots();
17100 } else {
17101 var components = eles.components();
17102 roots = cy.collection();
17103 var _loop = function _loop2(_i3) {
17104 var comp = components[_i3];
17105 var maxDegree = comp.maxDegree(false);
17106 var compRoots = comp.filter(function(ele2) {
17107 return ele2.degree(false) === maxDegree;
17108 });
17109 roots = roots.add(compRoots);
17110 };
17111 for (var _i = 0; _i < components.length; _i++) {
17112 _loop(_i);
17113 }
17114 }
17115 }
17116 var depths = [];
17117 var foundByBfs = {};
17118 var addToDepth = function addToDepth2(ele2, d) {
17119 if (depths[d] == null) {
17120 depths[d] = [];
17121 }
17122 var i3 = depths[d].length;
17123 depths[d].push(ele2);
17124 setInfo(ele2, {
17125 index: i3,
17126 depth: d
17127 });
17128 };
17129 var changeDepth = function changeDepth2(ele2, newDepth) {
17130 var _getInfo = getInfo(ele2), depth = _getInfo.depth, index = _getInfo.index;
17131 depths[depth][index] = null;
17132 addToDepth(ele2, newDepth);
17133 };
17134 graph.bfs({
17135 roots,
17136 directed: options.directed,
17137 visit: function visit(node, edge, pNode, i3, depth) {
17138 var ele2 = node[0];
17139 var id2 = ele2.id();
17140 addToDepth(ele2, depth);
17141 foundByBfs[id2] = true;
17142 }
17143 });
17144 var orphanNodes = [];
17145 for (var _i2 = 0; _i2 < nodes2.length; _i2++) {
17146 var _ele = nodes2[_i2];
17147 if (foundByBfs[_ele.id()]) {
17148 continue;
17149 } else {
17150 orphanNodes.push(_ele);
17151 }
17152 }
17153 var assignDepthsAt = function assignDepthsAt2(i3) {
17154 var eles2 = depths[i3];
17155 for (var j = 0; j < eles2.length; j++) {
17156 var _ele2 = eles2[j];
17157 if (_ele2 == null) {
17158 eles2.splice(j, 1);
17159 j--;
17160 continue;
17161 }
17162 setInfo(_ele2, {
17163 depth: i3,
17164 index: j
17165 });
17166 }
17167 };
17168 var assignDepths = function assignDepths2() {
17169 for (var _i3 = 0; _i3 < depths.length; _i3++) {
17170 assignDepthsAt(_i3);
17171 }
17172 };
17173 var adjustMaximally = function adjustMaximally2(ele2, shifted2) {
17174 var eInfo = getInfo(ele2);
17175 var incomers = ele2.incomers().filter(function(el) {
17176 return el.isNode() && eles.has(el);
17177 });
17178 var maxDepth = -1;
17179 var id2 = ele2.id();
17180 for (var k = 0; k < incomers.length; k++) {
17181 var incmr = incomers[k];
17182 var iInfo = getInfo(incmr);
17183 maxDepth = Math.max(maxDepth, iInfo.depth);
17184 }
17185 if (eInfo.depth <= maxDepth) {
17186 if (shifted2[id2]) {
17187 return null;
17188 }
17189 changeDepth(ele2, maxDepth + 1);
17190 shifted2[id2] = true;
17191 return true;
17192 }
17193 return false;
17194 };
17195 if (directed && maximal) {
17196 var Q = [];
17197 var shifted = {};
17198 var enqueue = function enqueue2(n2) {
17199 return Q.push(n2);
17200 };
17201 var dequeue = function dequeue2() {
17202 return Q.shift();
17203 };
17204 nodes2.forEach(function(n2) {
17205 return Q.push(n2);
17206 });
17207 while (Q.length > 0) {
17208 var _ele3 = dequeue();
17209 var didShift = adjustMaximally(_ele3, shifted);
17210 if (didShift) {
17211 _ele3.outgoers().filter(function(el) {
17212 return el.isNode() && eles.has(el);
17213 }).forEach(enqueue);
17214 } else if (didShift === null) {
17215 warn("Detected double maximal shift for node `" + _ele3.id() + "`. Bailing maximal adjustment due to cycle. Use `options.maximal: true` only on DAGs.");
17216 break;
17217 }
17218 }
17219 }
17220 assignDepths();
17221 var minDistance = 0;
17222 if (options.avoidOverlap) {
17223 for (var _i4 = 0; _i4 < nodes2.length; _i4++) {
17224 var n = nodes2[_i4];
17225 var nbb = n.layoutDimensions(options);
17226 var w = nbb.w;
17227 var h = nbb.h;
17228 minDistance = Math.max(minDistance, w, h);
17229 }
17230 }
17231 var cachedWeightedPercent = {};
17232 var getWeightedPercent = function getWeightedPercent2(ele2) {
17233 if (cachedWeightedPercent[ele2.id()]) {
17234 return cachedWeightedPercent[ele2.id()];
17235 }
17236 var eleDepth = getInfo(ele2).depth;
17237 var neighbors = ele2.neighborhood();
17238 var percent = 0;
17239 var samples = 0;
17240 for (var _i5 = 0; _i5 < neighbors.length; _i5++) {
17241 var neighbor = neighbors[_i5];
17242 if (neighbor.isEdge() || neighbor.isParent() || !nodes2.has(neighbor)) {
17243 continue;
17244 }
17245 var bf = getInfo(neighbor);
17246 if (bf == null) {
17247 continue;
17248 }
17249 var index = bf.index;
17250 var depth = bf.depth;
17251 if (index == null || depth == null) {
17252 continue;
17253 }
17254 var nDepth = depths[depth].length;
17255 if (depth < eleDepth) {
17256 percent += index / nDepth;
17257 samples++;
17258 }
17259 }
17260 samples = Math.max(1, samples);
17261 percent = percent / samples;
17262 if (samples === 0) {
17263 percent = 0;
17264 }
17265 cachedWeightedPercent[ele2.id()] = percent;
17266 return percent;
17267 };
17268 var sortFn = function sortFn2(a, b) {
17269 var apct = getWeightedPercent(a);
17270 var bpct = getWeightedPercent(b);
17271 var diff = apct - bpct;
17272 if (diff === 0) {
17273 return ascending(a.id(), b.id());
17274 } else {
17275 return diff;
17276 }
17277 };
17278 if (options.depthSort !== void 0) {
17279 sortFn = options.depthSort;
17280 }
17281 for (var _i6 = 0; _i6 < depths.length; _i6++) {
17282 depths[_i6].sort(sortFn);
17283 assignDepthsAt(_i6);
17284 }
17285 var orphanDepth = [];
17286 for (var _i7 = 0; _i7 < orphanNodes.length; _i7++) {
17287 orphanDepth.push(orphanNodes[_i7]);
17288 }
17289 depths.unshift(orphanDepth);
17290 assignDepths();
17291 var biggestDepthSize = 0;
17292 for (var _i8 = 0; _i8 < depths.length; _i8++) {
17293 biggestDepthSize = Math.max(depths[_i8].length, biggestDepthSize);
17294 }
17295 var center = {
17296 x: bb.x1 + bb.w / 2,
17297 y: bb.x1 + bb.h / 2
17298 };
17299 var maxDepthSize = depths.reduce(function(max2, eles2) {
17300 return Math.max(max2, eles2.length);
17301 }, 0);
17302 var getPosition = function getPosition2(ele2) {
17303 var _getInfo2 = getInfo(ele2), depth = _getInfo2.depth, index = _getInfo2.index;
17304 var depthSize = depths[depth].length;
17305 var distanceX = Math.max(bb.w / ((options.grid ? maxDepthSize : depthSize) + 1), minDistance);
17306 var distanceY = Math.max(bb.h / (depths.length + 1), minDistance);
17307 var radiusStepSize = Math.min(bb.w / 2 / depths.length, bb.h / 2 / depths.length);
17308 radiusStepSize = Math.max(radiusStepSize, minDistance);
17309 if (!options.circle) {
17310 var epos = {
17311 x: center.x + (index + 1 - (depthSize + 1) / 2) * distanceX,
17312 y: (depth + 1) * distanceY
17313 };
17314 return epos;
17315 } else {
17316 var radius = radiusStepSize * depth + radiusStepSize - (depths.length > 0 && depths[0].length <= 3 ? radiusStepSize / 2 : 0);
17317 var theta = 2 * Math.PI / depths[depth].length * index;
17318 if (depth === 0 && depths[0].length === 1) {
17319 radius = 1;
17320 }
17321 return {
17322 x: center.x + radius * Math.cos(theta),
17323 y: center.y + radius * Math.sin(theta)
17324 };
17325 }
17326 };
17327 eles.nodes().layoutPositions(this, options, getPosition);
17328 return this;
17329 };
17330 var defaults$6 = {
17331 fit: true,
17332 // whether to fit the viewport to the graph
17333 padding: 30,
17334 // the padding on fit
17335 boundingBox: void 0,
17336 // constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
17337 avoidOverlap: true,
17338 // prevents node overlap, may overflow boundingBox and radius if not enough space
17339 nodeDimensionsIncludeLabels: false,
17340 // Excludes the label when calculating node bounding boxes for the layout algorithm
17341 spacingFactor: void 0,
17342 // Applies a multiplicative factor (>0) to expand or compress the overall area that the nodes take up
17343 radius: void 0,
17344 // the radius of the circle
17345 startAngle: 3 / 2 * Math.PI,
17346 // where nodes start in radians
17347 sweep: void 0,
17348 // how many radians should be between the first and last node (defaults to full circle)
17349 clockwise: true,
17350 // whether the layout should go clockwise (true) or counterclockwise/anticlockwise (false)
17351 sort: void 0,
17352 // a sorting function to order the nodes; e.g. function(a, b){ return a.data('weight') - b.data('weight') }
17353 animate: false,
17354 // whether to transition the node positions
17355 animationDuration: 500,
17356 // duration of animation in ms if enabled
17357 animationEasing: void 0,
17358 // easing of animation if enabled
17359 animateFilter: function animateFilter(node, i2) {
17360 return true;
17361 },
17362 // a function that determines whether the node should be animated. All nodes animated by default on animate enabled. Non-animated nodes are positioned immediately when the layout starts
17363 ready: void 0,
17364 // callback on layoutready
17365 stop: void 0,
17366 // callback on layoutstop
17367 transform: function transform(node, position2) {
17368 return position2;
17369 }
17370 // transform a given node position. Useful for changing flow direction in discrete layouts
17371 };
17372 function CircleLayout(options) {
17373 this.options = extend({}, defaults$6, options);
17374 }
17375 CircleLayout.prototype.run = function() {
17376 var params = this.options;
17377 var options = params;
17378 var cy = params.cy;
17379 var eles = options.eles;
17380 var clockwise = options.counterclockwise !== void 0 ? !options.counterclockwise : options.clockwise;
17381 var nodes2 = eles.nodes().not(":parent");
17382 if (options.sort) {
17383 nodes2 = nodes2.sort(options.sort);
17384 }
17385 var bb = makeBoundingBox(options.boundingBox ? options.boundingBox : {
17386 x1: 0,
17387 y1: 0,
17388 w: cy.width(),
17389 h: cy.height()
17390 });
17391 var center = {
17392 x: bb.x1 + bb.w / 2,
17393 y: bb.y1 + bb.h / 2
17394 };
17395 var sweep = options.sweep === void 0 ? 2 * Math.PI - 2 * Math.PI / nodes2.length : options.sweep;
17396 var dTheta = sweep / Math.max(1, nodes2.length - 1);
17397 var r;
17398 var minDistance = 0;
17399 for (var i2 = 0; i2 < nodes2.length; i2++) {
17400 var n = nodes2[i2];
17401 var nbb = n.layoutDimensions(options);
17402 var w = nbb.w;
17403 var h = nbb.h;
17404 minDistance = Math.max(minDistance, w, h);
17405 }
17406 if (number$1(options.radius)) {
17407 r = options.radius;
17408 } else if (nodes2.length <= 1) {
17409 r = 0;
17410 } else {
17411 r = Math.min(bb.h, bb.w) / 2 - minDistance;
17412 }
17413 if (nodes2.length > 1 && options.avoidOverlap) {
17414 minDistance *= 1.75;
17415 var dcos = Math.cos(dTheta) - Math.cos(0);
17416 var dsin = Math.sin(dTheta) - Math.sin(0);
17417 var rMin = Math.sqrt(minDistance * minDistance / (dcos * dcos + dsin * dsin));
17418 r = Math.max(rMin, r);
17419 }
17420 var getPos = function getPos2(ele, i3) {
17421 var theta = options.startAngle + i3 * dTheta * (clockwise ? 1 : -1);
17422 var rx = r * Math.cos(theta);
17423 var ry = r * Math.sin(theta);
17424 var pos = {
17425 x: center.x + rx,
17426 y: center.y + ry
17427 };
17428 return pos;
17429 };
17430 eles.nodes().layoutPositions(this, options, getPos);
17431 return this;
17432 };
17433 var defaults$5 = {
17434 fit: true,
17435 // whether to fit the viewport to the graph
17436 padding: 30,
17437 // the padding on fit
17438 startAngle: 3 / 2 * Math.PI,
17439 // where nodes start in radians
17440 sweep: void 0,
17441 // how many radians should be between the first and last node (defaults to full circle)
17442 clockwise: true,
17443 // whether the layout should go clockwise (true) or counterclockwise/anticlockwise (false)
17444 equidistant: false,
17445 // whether levels have an equal radial distance betwen them, may cause bounding box overflow
17446 minNodeSpacing: 10,
17447 // min spacing between outside of nodes (used for radius adjustment)
17448 boundingBox: void 0,
17449 // constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
17450 avoidOverlap: true,
17451 // prevents node overlap, may overflow boundingBox if not enough space
17452 nodeDimensionsIncludeLabels: false,
17453 // Excludes the label when calculating node bounding boxes for the layout algorithm
17454 height: void 0,
17455 // height of layout area (overrides container height)
17456 width: void 0,
17457 // width of layout area (overrides container width)
17458 spacingFactor: void 0,
17459 // Applies a multiplicative factor (>0) to expand or compress the overall area that the nodes take up
17460 concentric: function concentric(node) {
17461 return node.degree();
17462 },
17463 levelWidth: function levelWidth(nodes2) {
17464 return nodes2.maxDegree() / 4;
17465 },
17466 animate: false,
17467 // whether to transition the node positions
17468 animationDuration: 500,
17469 // duration of animation in ms if enabled
17470 animationEasing: void 0,
17471 // easing of animation if enabled
17472 animateFilter: function animateFilter(node, i2) {
17473 return true;
17474 },
17475 // a function that determines whether the node should be animated. All nodes animated by default on animate enabled. Non-animated nodes are positioned immediately when the layout starts
17476 ready: void 0,
17477 // callback on layoutready
17478 stop: void 0,
17479 // callback on layoutstop
17480 transform: function transform(node, position2) {
17481 return position2;
17482 }
17483 // transform a given node position. Useful for changing flow direction in discrete layouts
17484 };
17485 function ConcentricLayout(options) {
17486 this.options = extend({}, defaults$5, options);
17487 }
17488 ConcentricLayout.prototype.run = function() {
17489 var params = this.options;
17490 var options = params;
17491 var clockwise = options.counterclockwise !== void 0 ? !options.counterclockwise : options.clockwise;
17492 var cy = params.cy;
17493 var eles = options.eles;
17494 var nodes2 = eles.nodes().not(":parent");
17495 var bb = makeBoundingBox(options.boundingBox ? options.boundingBox : {
17496 x1: 0,
17497 y1: 0,
17498 w: cy.width(),
17499 h: cy.height()
17500 });
17501 var center = {
17502 x: bb.x1 + bb.w / 2,
17503 y: bb.y1 + bb.h / 2
17504 };
17505 var nodeValues = [];
17506 var maxNodeSize = 0;
17507 for (var i2 = 0; i2 < nodes2.length; i2++) {
17508 var node = nodes2[i2];
17509 var value = void 0;
17510 value = options.concentric(node);
17511 nodeValues.push({
17512 value,
17513 node
17514 });
17515 node._private.scratch.concentric = value;
17516 }
17517 nodes2.updateStyle();
17518 for (var _i = 0; _i < nodes2.length; _i++) {
17519 var _node = nodes2[_i];
17520 var nbb = _node.layoutDimensions(options);
17521 maxNodeSize = Math.max(maxNodeSize, nbb.w, nbb.h);
17522 }
17523 nodeValues.sort(function(a, b) {
17524 return b.value - a.value;
17525 });
17526 var levelWidth = options.levelWidth(nodes2);
17527 var levels = [[]];
17528 var currentLevel = levels[0];
17529 for (var _i2 = 0; _i2 < nodeValues.length; _i2++) {
17530 var val = nodeValues[_i2];
17531 if (currentLevel.length > 0) {
17532 var diff = Math.abs(currentLevel[0].value - val.value);
17533 if (diff >= levelWidth) {
17534 currentLevel = [];
17535 levels.push(currentLevel);
17536 }
17537 }
17538 currentLevel.push(val);
17539 }
17540 var minDist = maxNodeSize + options.minNodeSpacing;
17541 if (!options.avoidOverlap) {
17542 var firstLvlHasMulti = levels.length > 0 && levels[0].length > 1;
17543 var maxR = Math.min(bb.w, bb.h) / 2 - minDist;
17544 var rStep = maxR / (levels.length + firstLvlHasMulti ? 1 : 0);
17545 minDist = Math.min(minDist, rStep);
17546 }
17547 var r = 0;
17548 for (var _i3 = 0; _i3 < levels.length; _i3++) {
17549 var level = levels[_i3];
17550 var sweep = options.sweep === void 0 ? 2 * Math.PI - 2 * Math.PI / level.length : options.sweep;
17551 var dTheta = level.dTheta = sweep / Math.max(1, level.length - 1);
17552 if (level.length > 1 && options.avoidOverlap) {
17553 var dcos = Math.cos(dTheta) - Math.cos(0);
17554 var dsin = Math.sin(dTheta) - Math.sin(0);
17555 var rMin = Math.sqrt(minDist * minDist / (dcos * dcos + dsin * dsin));
17556 r = Math.max(rMin, r);
17557 }
17558 level.r = r;
17559 r += minDist;
17560 }
17561 if (options.equidistant) {
17562 var rDeltaMax = 0;
17563 var _r = 0;
17564 for (var _i4 = 0; _i4 < levels.length; _i4++) {
17565 var _level = levels[_i4];
17566 var rDelta = _level.r - _r;
17567 rDeltaMax = Math.max(rDeltaMax, rDelta);
17568 }
17569 _r = 0;
17570 for (var _i5 = 0; _i5 < levels.length; _i5++) {
17571 var _level2 = levels[_i5];
17572 if (_i5 === 0) {
17573 _r = _level2.r;
17574 }
17575 _level2.r = _r;
17576 _r += rDeltaMax;
17577 }
17578 }
17579 var pos = {};
17580 for (var _i6 = 0; _i6 < levels.length; _i6++) {
17581 var _level3 = levels[_i6];
17582 var _dTheta = _level3.dTheta;
17583 var _r2 = _level3.r;
17584 for (var j = 0; j < _level3.length; j++) {
17585 var _val = _level3[j];
17586 var theta = options.startAngle + (clockwise ? 1 : -1) * _dTheta * j;
17587 var p2 = {
17588 x: center.x + _r2 * Math.cos(theta),
17589 y: center.y + _r2 * Math.sin(theta)
17590 };
17591 pos[_val.node.id()] = p2;
17592 }
17593 }
17594 eles.nodes().layoutPositions(this, options, function(ele) {
17595 var id = ele.id();
17596 return pos[id];
17597 });
17598 return this;
17599 };
17600 var DEBUG;
17601 var defaults$4 = {
17602 // Called on `layoutready`
17603 ready: function ready() {
17604 },
17605 // Called on `layoutstop`
17606 stop: function stop() {
17607 },
17608 // Whether to animate while running the layout
17609 // true : Animate continuously as the layout is running
17610 // false : Just show the end result
17611 // 'end' : Animate with the end result, from the initial positions to the end positions
17612 animate: true,
17613 // Easing of the animation for animate:'end'
17614 animationEasing: void 0,
17615 // The duration of the animation for animate:'end'
17616 animationDuration: void 0,
17617 // A function that determines whether the node should be animated
17618 // All nodes animated by default on animate enabled
17619 // Non-animated nodes are positioned immediately when the layout starts
17620 animateFilter: function animateFilter(node, i2) {
17621 return true;
17622 },
17623 // The layout animates only after this many milliseconds for animate:true
17624 // (prevents flashing on fast runs)
17625 animationThreshold: 250,
17626 // Number of iterations between consecutive screen positions update
17627 refresh: 20,
17628 // Whether to fit the network view after when done
17629 fit: true,
17630 // Padding on fit
17631 padding: 30,
17632 // Constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
17633 boundingBox: void 0,
17634 // Excludes the label when calculating node bounding boxes for the layout algorithm
17635 nodeDimensionsIncludeLabels: false,
17636 // Randomize the initial positions of the nodes (true) or use existing positions (false)
17637 randomize: false,
17638 // Extra spacing between components in non-compound graphs
17639 componentSpacing: 40,
17640 // Node repulsion (non overlapping) multiplier
17641 nodeRepulsion: function nodeRepulsion2(node) {
17642 return 2048;
17643 },
17644 // Node repulsion (overlapping) multiplier
17645 nodeOverlap: 4,
17646 // Ideal edge (non nested) length
17647 idealEdgeLength: function idealEdgeLength(edge) {
17648 return 32;
17649 },
17650 // Divisor to compute edge forces
17651 edgeElasticity: function edgeElasticity(edge) {
17652 return 32;
17653 },
17654 // Nesting factor (multiplier) to compute ideal edge length for nested edges
17655 nestingFactor: 1.2,
17656 // Gravity force (constant)
17657 gravity: 1,
17658 // Maximum number of iterations to perform
17659 numIter: 1e3,
17660 // Initial temperature (maximum node displacement)
17661 initialTemp: 1e3,
17662 // Cooling factor (how the temperature is reduced between consecutive iterations
17663 coolingFactor: 0.99,
17664 // Lower temperature threshold (below this point the layout will end)
17665 minTemp: 1
17666 };
17667 function CoseLayout(options) {
17668 this.options = extend({}, defaults$4, options);
17669 this.options.layout = this;
17670 }
17671 CoseLayout.prototype.run = function() {
17672 var options = this.options;
17673 var cy = options.cy;
17674 var layout2 = this;
17675 layout2.stopped = false;
17676 if (options.animate === true || options.animate === false) {
17677 layout2.emit({
17678 type: "layoutstart",
17679 layout: layout2
17680 });
17681 }
17682 if (true === options.debug) {
17683 DEBUG = true;
17684 } else {
17685 DEBUG = false;
17686 }
17687 var layoutInfo = createLayoutInfo(cy, layout2, options);
17688 if (DEBUG) {
17689 printLayoutInfo(layoutInfo);
17690 }
17691 if (options.randomize) {
17692 randomizePositions(layoutInfo);
17693 }
17694 var startTime = performanceNow();
17695 var refresh = function refresh2() {
17696 refreshPositions(layoutInfo, cy, options);
17697 if (true === options.fit) {
17698 cy.fit(options.padding);
17699 }
17700 };
17701 var mainLoop = function mainLoop2(i3) {
17702 if (layout2.stopped || i3 >= options.numIter) {
17703 return false;
17704 }
17705 step(layoutInfo, options);
17706 layoutInfo.temperature = layoutInfo.temperature * options.coolingFactor;
17707 if (layoutInfo.temperature < options.minTemp) {
17708 return false;
17709 }
17710 return true;
17711 };
17712 var done = function done2() {
17713 if (options.animate === true || options.animate === false) {
17714 refresh();
17715 layout2.one("layoutstop", options.stop);
17716 layout2.emit({
17717 type: "layoutstop",
17718 layout: layout2
17719 });
17720 } else {
17721 var nodes2 = options.eles.nodes();
17722 var getScaledPos = getScaleInBoundsFn(layoutInfo, options, nodes2);
17723 nodes2.layoutPositions(layout2, options, getScaledPos);
17724 }
17725 };
17726 var i2 = 0;
17727 var loopRet = true;
17728 if (options.animate === true) {
17729 var frame = function frame2() {
17730 var f = 0;
17731 while (loopRet && f < options.refresh) {
17732 loopRet = mainLoop(i2);
17733 i2++;
17734 f++;
17735 }
17736 if (!loopRet) {
17737 separateComponents(layoutInfo, options);
17738 done();
17739 } else {
17740 var now2 = performanceNow();
17741 if (now2 - startTime >= options.animationThreshold) {
17742 refresh();
17743 }
17744 requestAnimationFrame2(frame2);
17745 }
17746 };
17747 frame();
17748 } else {
17749 while (loopRet) {
17750 loopRet = mainLoop(i2);
17751 i2++;
17752 }
17753 separateComponents(layoutInfo, options);
17754 done();
17755 }
17756 return this;
17757 };
17758 CoseLayout.prototype.stop = function() {
17759 this.stopped = true;
17760 if (this.thread) {
17761 this.thread.stop();
17762 }
17763 this.emit("layoutstop");
17764 return this;
17765 };
17766 CoseLayout.prototype.destroy = function() {
17767 if (this.thread) {
17768 this.thread.stop();
17769 }
17770 return this;
17771 };
17772 var createLayoutInfo = function createLayoutInfo2(cy, layout2, options) {
17773 var edges = options.eles.edges();
17774 var nodes2 = options.eles.nodes();
17775 var layoutInfo = {
17776 isCompound: cy.hasCompoundNodes(),
17777 layoutNodes: [],
17778 idToIndex: {},
17779 nodeSize: nodes2.size(),
17780 graphSet: [],
17781 indexToGraph: [],
17782 layoutEdges: [],
17783 edgeSize: edges.size(),
17784 temperature: options.initialTemp,
17785 clientWidth: cy.width(),
17786 clientHeight: cy.width(),
17787 boundingBox: makeBoundingBox(options.boundingBox ? options.boundingBox : {
17788 x1: 0,
17789 y1: 0,
17790 w: cy.width(),
17791 h: cy.height()
17792 })
17793 };
17794 var components = options.eles.components();
17795 var id2cmptId = {};
17796 for (var i2 = 0; i2 < components.length; i2++) {
17797 var component = components[i2];
17798 for (var j = 0; j < component.length; j++) {
17799 var node = component[j];
17800 id2cmptId[node.id()] = i2;
17801 }
17802 }
17803 for (var i2 = 0; i2 < layoutInfo.nodeSize; i2++) {
17804 var n = nodes2[i2];
17805 var nbb = n.layoutDimensions(options);
17806 var tempNode = {};
17807 tempNode.isLocked = n.locked();
17808 tempNode.id = n.data("id");
17809 tempNode.parentId = n.data("parent");
17810 tempNode.cmptId = id2cmptId[n.id()];
17811 tempNode.children = [];
17812 tempNode.positionX = n.position("x");
17813 tempNode.positionY = n.position("y");
17814 tempNode.offsetX = 0;
17815 tempNode.offsetY = 0;
17816 tempNode.height = nbb.w;
17817 tempNode.width = nbb.h;
17818 tempNode.maxX = tempNode.positionX + tempNode.width / 2;
17819 tempNode.minX = tempNode.positionX - tempNode.width / 2;
17820 tempNode.maxY = tempNode.positionY + tempNode.height / 2;
17821 tempNode.minY = tempNode.positionY - tempNode.height / 2;
17822 tempNode.padLeft = parseFloat(n.style("padding"));
17823 tempNode.padRight = parseFloat(n.style("padding"));
17824 tempNode.padTop = parseFloat(n.style("padding"));
17825 tempNode.padBottom = parseFloat(n.style("padding"));
17826 tempNode.nodeRepulsion = fn$6(options.nodeRepulsion) ? options.nodeRepulsion(n) : options.nodeRepulsion;
17827 layoutInfo.layoutNodes.push(tempNode);
17828 layoutInfo.idToIndex[tempNode.id] = i2;
17829 }
17830 var queue = [];
17831 var start = 0;
17832 var end = -1;
17833 var tempGraph = [];
17834 for (var i2 = 0; i2 < layoutInfo.nodeSize; i2++) {
17835 var n = layoutInfo.layoutNodes[i2];
17836 var p_id = n.parentId;
17837 if (null != p_id) {
17838 layoutInfo.layoutNodes[layoutInfo.idToIndex[p_id]].children.push(n.id);
17839 } else {
17840 queue[++end] = n.id;
17841 tempGraph.push(n.id);
17842 }
17843 }
17844 layoutInfo.graphSet.push(tempGraph);
17845 while (start <= end) {
17846 var node_id = queue[start++];
17847 var node_ix = layoutInfo.idToIndex[node_id];
17848 var node = layoutInfo.layoutNodes[node_ix];
17849 var children = node.children;
17850 if (children.length > 0) {
17851 layoutInfo.graphSet.push(children);
17852 for (var i2 = 0; i2 < children.length; i2++) {
17853 queue[++end] = children[i2];
17854 }
17855 }
17856 }
17857 for (var i2 = 0; i2 < layoutInfo.graphSet.length; i2++) {
17858 var graph = layoutInfo.graphSet[i2];
17859 for (var j = 0; j < graph.length; j++) {
17860 var index = layoutInfo.idToIndex[graph[j]];
17861 layoutInfo.indexToGraph[index] = i2;
17862 }
17863 }
17864 for (var i2 = 0; i2 < layoutInfo.edgeSize; i2++) {
17865 var e = edges[i2];
17866 var tempEdge = {};
17867 tempEdge.id = e.data("id");
17868 tempEdge.sourceId = e.data("source");
17869 tempEdge.targetId = e.data("target");
17870 var idealLength = fn$6(options.idealEdgeLength) ? options.idealEdgeLength(e) : options.idealEdgeLength;
17871 var elasticity = fn$6(options.edgeElasticity) ? options.edgeElasticity(e) : options.edgeElasticity;
17872 var sourceIx = layoutInfo.idToIndex[tempEdge.sourceId];
17873 var targetIx = layoutInfo.idToIndex[tempEdge.targetId];
17874 var sourceGraph = layoutInfo.indexToGraph[sourceIx];
17875 var targetGraph = layoutInfo.indexToGraph[targetIx];
17876 if (sourceGraph != targetGraph) {
17877 var lca = findLCA(tempEdge.sourceId, tempEdge.targetId, layoutInfo);
17878 var lcaGraph = layoutInfo.graphSet[lca];
17879 var depth = 0;
17880 var tempNode = layoutInfo.layoutNodes[sourceIx];
17881 while (-1 === lcaGraph.indexOf(tempNode.id)) {
17882 tempNode = layoutInfo.layoutNodes[layoutInfo.idToIndex[tempNode.parentId]];
17883 depth++;
17884 }
17885 tempNode = layoutInfo.layoutNodes[targetIx];
17886 while (-1 === lcaGraph.indexOf(tempNode.id)) {
17887 tempNode = layoutInfo.layoutNodes[layoutInfo.idToIndex[tempNode.parentId]];
17888 depth++;
17889 }
17890 idealLength *= depth * options.nestingFactor;
17891 }
17892 tempEdge.idealLength = idealLength;
17893 tempEdge.elasticity = elasticity;
17894 layoutInfo.layoutEdges.push(tempEdge);
17895 }
17896 return layoutInfo;
17897 };
17898 var findLCA = function findLCA2(node1, node2, layoutInfo) {
17899 var res = findLCA_aux(node1, node2, 0, layoutInfo);
17900 if (2 > res.count) {
17901 return 0;
17902 } else {
17903 return res.graph;
17904 }
17905 };
17906 var findLCA_aux = function findLCA_aux2(node1, node2, graphIx, layoutInfo) {
17907 var graph = layoutInfo.graphSet[graphIx];
17908 if (-1 < graph.indexOf(node1) && -1 < graph.indexOf(node2)) {
17909 return {
17910 count: 2,
17911 graph: graphIx
17912 };
17913 }
17914 var c = 0;
17915 for (var i2 = 0; i2 < graph.length; i2++) {
17916 var nodeId = graph[i2];
17917 var nodeIx = layoutInfo.idToIndex[nodeId];
17918 var children = layoutInfo.layoutNodes[nodeIx].children;
17919 if (0 === children.length) {
17920 continue;
17921 }
17922 var childGraphIx = layoutInfo.indexToGraph[layoutInfo.idToIndex[children[0]]];
17923 var result = findLCA_aux2(node1, node2, childGraphIx, layoutInfo);
17924 if (0 === result.count) {
17925 continue;
17926 } else if (1 === result.count) {
17927 c++;
17928 if (2 === c) {
17929 break;
17930 }
17931 } else {
17932 return result;
17933 }
17934 }
17935 return {
17936 count: c,
17937 graph: graphIx
17938 };
17939 };
17940 var printLayoutInfo;
17941 var randomizePositions = function randomizePositions2(layoutInfo, cy) {
17942 var width = layoutInfo.clientWidth;
17943 var height = layoutInfo.clientHeight;
17944 for (var i2 = 0; i2 < layoutInfo.nodeSize; i2++) {
17945 var n = layoutInfo.layoutNodes[i2];
17946 if (0 === n.children.length && !n.isLocked) {
17947 n.positionX = Math.random() * width;
17948 n.positionY = Math.random() * height;
17949 }
17950 }
17951 };
17952 var getScaleInBoundsFn = function getScaleInBoundsFn2(layoutInfo, options, nodes2) {
17953 var bb = layoutInfo.boundingBox;
17954 var coseBB = {
17955 x1: Infinity,
17956 x2: -Infinity,
17957 y1: Infinity,
17958 y2: -Infinity
17959 };
17960 if (options.boundingBox) {
17961 nodes2.forEach(function(node) {
17962 var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[node.data("id")]];
17963 coseBB.x1 = Math.min(coseBB.x1, lnode.positionX);
17964 coseBB.x2 = Math.max(coseBB.x2, lnode.positionX);
17965 coseBB.y1 = Math.min(coseBB.y1, lnode.positionY);
17966 coseBB.y2 = Math.max(coseBB.y2, lnode.positionY);
17967 });
17968 coseBB.w = coseBB.x2 - coseBB.x1;
17969 coseBB.h = coseBB.y2 - coseBB.y1;
17970 }
17971 return function(ele, i2) {
17972 var lnode = layoutInfo.layoutNodes[layoutInfo.idToIndex[ele.data("id")]];
17973 if (options.boundingBox) {
17974 var pctX = (lnode.positionX - coseBB.x1) / coseBB.w;
17975 var pctY = (lnode.positionY - coseBB.y1) / coseBB.h;
17976 return {
17977 x: bb.x1 + pctX * bb.w,
17978 y: bb.y1 + pctY * bb.h
17979 };
17980 } else {
17981 return {
17982 x: lnode.positionX,
17983 y: lnode.positionY
17984 };
17985 }
17986 };
17987 };
17988 var refreshPositions = function refreshPositions2(layoutInfo, cy, options) {
17989 var layout2 = options.layout;
17990 var nodes2 = options.eles.nodes();
17991 var getScaledPos = getScaleInBoundsFn(layoutInfo, options, nodes2);
17992 nodes2.positions(getScaledPos);
17993 if (true !== layoutInfo.ready) {
17994 layoutInfo.ready = true;
17995 layout2.one("layoutready", options.ready);
17996 layout2.emit({
17997 type: "layoutready",
17998 layout: this
17999 });
18000 }
18001 };
18002 var step = function step2(layoutInfo, options, _step) {
18003 calculateNodeForces(layoutInfo, options);
18004 calculateEdgeForces(layoutInfo);
18005 calculateGravityForces(layoutInfo, options);
18006 propagateForces(layoutInfo);
18007 updatePositions(layoutInfo);
18008 };
18009 var calculateNodeForces = function calculateNodeForces2(layoutInfo, options) {
18010 for (var i2 = 0; i2 < layoutInfo.graphSet.length; i2++) {
18011 var graph = layoutInfo.graphSet[i2];
18012 var numNodes = graph.length;
18013 for (var j = 0; j < numNodes; j++) {
18014 var node1 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]];
18015 for (var k = j + 1; k < numNodes; k++) {
18016 var node2 = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[k]]];
18017 nodeRepulsion(node1, node2, layoutInfo, options);
18018 }
18019 }
18020 }
18021 };
18022 var randomDistance = function randomDistance2(max2) {
18023 return -max2 + 2 * max2 * Math.random();
18024 };
18025 var nodeRepulsion = function nodeRepulsion2(node1, node2, layoutInfo, options) {
18026 var cmptId1 = node1.cmptId;
18027 var cmptId2 = node2.cmptId;
18028 if (cmptId1 !== cmptId2 && !layoutInfo.isCompound) {
18029 return;
18030 }
18031 var directionX = node2.positionX - node1.positionX;
18032 var directionY = node2.positionY - node1.positionY;
18033 var maxRandDist = 1;
18034 if (0 === directionX && 0 === directionY) {
18035 directionX = randomDistance(maxRandDist);
18036 directionY = randomDistance(maxRandDist);
18037 }
18038 var overlap = nodesOverlap(node1, node2, directionX, directionY);
18039 if (overlap > 0) {
18040 var force = options.nodeOverlap * overlap;
18041 var distance = Math.sqrt(directionX * directionX + directionY * directionY);
18042 var forceX = force * directionX / distance;
18043 var forceY = force * directionY / distance;
18044 } else {
18045 var point1 = findClippingPoint(node1, directionX, directionY);
18046 var point2 = findClippingPoint(node2, -1 * directionX, -1 * directionY);
18047 var distanceX = point2.x - point1.x;
18048 var distanceY = point2.y - point1.y;
18049 var distanceSqr = distanceX * distanceX + distanceY * distanceY;
18050 var distance = Math.sqrt(distanceSqr);
18051 var force = (node1.nodeRepulsion + node2.nodeRepulsion) / distanceSqr;
18052 var forceX = force * distanceX / distance;
18053 var forceY = force * distanceY / distance;
18054 }
18055 if (!node1.isLocked) {
18056 node1.offsetX -= forceX;
18057 node1.offsetY -= forceY;
18058 }
18059 if (!node2.isLocked) {
18060 node2.offsetX += forceX;
18061 node2.offsetY += forceY;
18062 }
18063 return;
18064 };
18065 var nodesOverlap = function nodesOverlap2(node1, node2, dX, dY) {
18066 if (dX > 0) {
18067 var overlapX = node1.maxX - node2.minX;
18068 } else {
18069 var overlapX = node2.maxX - node1.minX;
18070 }
18071 if (dY > 0) {
18072 var overlapY = node1.maxY - node2.minY;
18073 } else {
18074 var overlapY = node2.maxY - node1.minY;
18075 }
18076 if (overlapX >= 0 && overlapY >= 0) {
18077 return Math.sqrt(overlapX * overlapX + overlapY * overlapY);
18078 } else {
18079 return 0;
18080 }
18081 };
18082 var findClippingPoint = function findClippingPoint2(node, dX, dY) {
18083 var X = node.positionX;
18084 var Y = node.positionY;
18085 var H = node.height || 1;
18086 var W = node.width || 1;
18087 var dirSlope = dY / dX;
18088 var nodeSlope = H / W;
18089 var res = {};
18090 if (0 === dX && 0 < dY) {
18091 res.x = X;
18092 res.y = Y + H / 2;
18093 return res;
18094 }
18095 if (0 === dX && 0 > dY) {
18096 res.x = X;
18097 res.y = Y + H / 2;
18098 return res;
18099 }
18100 if (0 < dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) {
18101 res.x = X + W / 2;
18102 res.y = Y + W * dY / 2 / dX;
18103 return res;
18104 }
18105 if (0 > dX && -1 * nodeSlope <= dirSlope && dirSlope <= nodeSlope) {
18106 res.x = X - W / 2;
18107 res.y = Y - W * dY / 2 / dX;
18108 return res;
18109 }
18110 if (0 < dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) {
18111 res.x = X + H * dX / 2 / dY;
18112 res.y = Y + H / 2;
18113 return res;
18114 }
18115 if (0 > dY && (dirSlope <= -1 * nodeSlope || dirSlope >= nodeSlope)) {
18116 res.x = X - H * dX / 2 / dY;
18117 res.y = Y - H / 2;
18118 return res;
18119 }
18120 return res;
18121 };
18122 var calculateEdgeForces = function calculateEdgeForces2(layoutInfo, options) {
18123 for (var i2 = 0; i2 < layoutInfo.edgeSize; i2++) {
18124 var edge = layoutInfo.layoutEdges[i2];
18125 var sourceIx = layoutInfo.idToIndex[edge.sourceId];
18126 var source = layoutInfo.layoutNodes[sourceIx];
18127 var targetIx = layoutInfo.idToIndex[edge.targetId];
18128 var target = layoutInfo.layoutNodes[targetIx];
18129 var directionX = target.positionX - source.positionX;
18130 var directionY = target.positionY - source.positionY;
18131 if (0 === directionX && 0 === directionY) {
18132 continue;
18133 }
18134 var point1 = findClippingPoint(source, directionX, directionY);
18135 var point2 = findClippingPoint(target, -1 * directionX, -1 * directionY);
18136 var lx = point2.x - point1.x;
18137 var ly = point2.y - point1.y;
18138 var l = Math.sqrt(lx * lx + ly * ly);
18139 var force = Math.pow(edge.idealLength - l, 2) / edge.elasticity;
18140 if (0 !== l) {
18141 var forceX = force * lx / l;
18142 var forceY = force * ly / l;
18143 } else {
18144 var forceX = 0;
18145 var forceY = 0;
18146 }
18147 if (!source.isLocked) {
18148 source.offsetX += forceX;
18149 source.offsetY += forceY;
18150 }
18151 if (!target.isLocked) {
18152 target.offsetX -= forceX;
18153 target.offsetY -= forceY;
18154 }
18155 }
18156 };
18157 var calculateGravityForces = function calculateGravityForces2(layoutInfo, options) {
18158 if (options.gravity === 0) {
18159 return;
18160 }
18161 var distThreshold = 1;
18162 for (var i2 = 0; i2 < layoutInfo.graphSet.length; i2++) {
18163 var graph = layoutInfo.graphSet[i2];
18164 var numNodes = graph.length;
18165 if (0 === i2) {
18166 var centerX = layoutInfo.clientHeight / 2;
18167 var centerY = layoutInfo.clientWidth / 2;
18168 } else {
18169 var temp = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[0]]];
18170 var parent = layoutInfo.layoutNodes[layoutInfo.idToIndex[temp.parentId]];
18171 var centerX = parent.positionX;
18172 var centerY = parent.positionY;
18173 }
18174 for (var j = 0; j < numNodes; j++) {
18175 var node = layoutInfo.layoutNodes[layoutInfo.idToIndex[graph[j]]];
18176 if (node.isLocked) {
18177 continue;
18178 }
18179 var dx = centerX - node.positionX;
18180 var dy = centerY - node.positionY;
18181 var d = Math.sqrt(dx * dx + dy * dy);
18182 if (d > distThreshold) {
18183 var fx = options.gravity * dx / d;
18184 var fy = options.gravity * dy / d;
18185 node.offsetX += fx;
18186 node.offsetY += fy;
18187 }
18188 }
18189 }
18190 };
18191 var propagateForces = function propagateForces2(layoutInfo, options) {
18192 var queue = [];
18193 var start = 0;
18194 var end = -1;
18195 queue.push.apply(queue, layoutInfo.graphSet[0]);
18196 end += layoutInfo.graphSet[0].length;
18197 while (start <= end) {
18198 var nodeId = queue[start++];
18199 var nodeIndex = layoutInfo.idToIndex[nodeId];
18200 var node = layoutInfo.layoutNodes[nodeIndex];
18201 var children = node.children;
18202 if (0 < children.length && !node.isLocked) {
18203 var offX = node.offsetX;
18204 var offY = node.offsetY;
18205 for (var i2 = 0; i2 < children.length; i2++) {
18206 var childNode = layoutInfo.layoutNodes[layoutInfo.idToIndex[children[i2]]];
18207 childNode.offsetX += offX;
18208 childNode.offsetY += offY;
18209 queue[++end] = children[i2];
18210 }
18211 node.offsetX = 0;
18212 node.offsetY = 0;
18213 }
18214 }
18215 };
18216 var updatePositions = function updatePositions2(layoutInfo, options) {
18217 for (var i2 = 0; i2 < layoutInfo.nodeSize; i2++) {
18218 var n = layoutInfo.layoutNodes[i2];
18219 if (0 < n.children.length) {
18220 n.maxX = void 0;
18221 n.minX = void 0;
18222 n.maxY = void 0;
18223 n.minY = void 0;
18224 }
18225 }
18226 for (var i2 = 0; i2 < layoutInfo.nodeSize; i2++) {
18227 var n = layoutInfo.layoutNodes[i2];
18228 if (0 < n.children.length || n.isLocked) {
18229 continue;
18230 }
18231 var tempForce = limitForce(n.offsetX, n.offsetY, layoutInfo.temperature);
18232 n.positionX += tempForce.x;
18233 n.positionY += tempForce.y;
18234 n.offsetX = 0;
18235 n.offsetY = 0;
18236 n.minX = n.positionX - n.width;
18237 n.maxX = n.positionX + n.width;
18238 n.minY = n.positionY - n.height;
18239 n.maxY = n.positionY + n.height;
18240 updateAncestryBoundaries(n, layoutInfo);
18241 }
18242 for (var i2 = 0; i2 < layoutInfo.nodeSize; i2++) {
18243 var n = layoutInfo.layoutNodes[i2];
18244 if (0 < n.children.length && !n.isLocked) {
18245 n.positionX = (n.maxX + n.minX) / 2;
18246 n.positionY = (n.maxY + n.minY) / 2;
18247 n.width = n.maxX - n.minX;
18248 n.height = n.maxY - n.minY;
18249 }
18250 }
18251 };
18252 var limitForce = function limitForce2(forceX, forceY, max2) {
18253 var force = Math.sqrt(forceX * forceX + forceY * forceY);
18254 if (force > max2) {
18255 var res = {
18256 x: max2 * forceX / force,
18257 y: max2 * forceY / force
18258 };
18259 } else {
18260 var res = {
18261 x: forceX,
18262 y: forceY
18263 };
18264 }
18265 return res;
18266 };
18267 var updateAncestryBoundaries = function updateAncestryBoundaries2(node, layoutInfo) {
18268 var parentId = node.parentId;
18269 if (null == parentId) {
18270 return;
18271 }
18272 var p2 = layoutInfo.layoutNodes[layoutInfo.idToIndex[parentId]];
18273 var flag = false;
18274 if (null == p2.maxX || node.maxX + p2.padRight > p2.maxX) {
18275 p2.maxX = node.maxX + p2.padRight;
18276 flag = true;
18277 }
18278 if (null == p2.minX || node.minX - p2.padLeft < p2.minX) {
18279 p2.minX = node.minX - p2.padLeft;
18280 flag = true;
18281 }
18282 if (null == p2.maxY || node.maxY + p2.padBottom > p2.maxY) {
18283 p2.maxY = node.maxY + p2.padBottom;
18284 flag = true;
18285 }
18286 if (null == p2.minY || node.minY - p2.padTop < p2.minY) {
18287 p2.minY = node.minY - p2.padTop;
18288 flag = true;
18289 }
18290 if (flag) {
18291 return updateAncestryBoundaries2(p2, layoutInfo);
18292 }
18293 return;
18294 };
18295 var separateComponents = function separateComponents2(layoutInfo, options) {
18296 var nodes2 = layoutInfo.layoutNodes;
18297 var components = [];
18298 for (var i2 = 0; i2 < nodes2.length; i2++) {
18299 var node = nodes2[i2];
18300 var cid = node.cmptId;
18301 var component = components[cid] = components[cid] || [];
18302 component.push(node);
18303 }
18304 var totalA = 0;
18305 for (var i2 = 0; i2 < components.length; i2++) {
18306 var c = components[i2];
18307 if (!c) {
18308 continue;
18309 }
18310 c.x1 = Infinity;
18311 c.x2 = -Infinity;
18312 c.y1 = Infinity;
18313 c.y2 = -Infinity;
18314 for (var j = 0; j < c.length; j++) {
18315 var n = c[j];
18316 c.x1 = Math.min(c.x1, n.positionX - n.width / 2);
18317 c.x2 = Math.max(c.x2, n.positionX + n.width / 2);
18318 c.y1 = Math.min(c.y1, n.positionY - n.height / 2);
18319 c.y2 = Math.max(c.y2, n.positionY + n.height / 2);
18320 }
18321 c.w = c.x2 - c.x1;
18322 c.h = c.y2 - c.y1;
18323 totalA += c.w * c.h;
18324 }
18325 components.sort(function(c1, c2) {
18326 return c2.w * c2.h - c1.w * c1.h;
18327 });
18328 var x = 0;
18329 var y = 0;
18330 var usedW = 0;
18331 var rowH = 0;
18332 var maxRowW = Math.sqrt(totalA) * layoutInfo.clientWidth / layoutInfo.clientHeight;
18333 for (var i2 = 0; i2 < components.length; i2++) {
18334 var c = components[i2];
18335 if (!c) {
18336 continue;
18337 }
18338 for (var j = 0; j < c.length; j++) {
18339 var n = c[j];
18340 if (!n.isLocked) {
18341 n.positionX += x - c.x1;
18342 n.positionY += y - c.y1;
18343 }
18344 }
18345 x += c.w + options.componentSpacing;
18346 usedW += c.w + options.componentSpacing;
18347 rowH = Math.max(rowH, c.h);
18348 if (usedW > maxRowW) {
18349 y += rowH + options.componentSpacing;
18350 x = 0;
18351 usedW = 0;
18352 rowH = 0;
18353 }
18354 }
18355 };
18356 var defaults$3 = {
18357 fit: true,
18358 // whether to fit the viewport to the graph
18359 padding: 30,
18360 // padding used on fit
18361 boundingBox: void 0,
18362 // constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
18363 avoidOverlap: true,
18364 // prevents node overlap, may overflow boundingBox if not enough space
18365 avoidOverlapPadding: 10,
18366 // extra spacing around nodes when avoidOverlap: true
18367 nodeDimensionsIncludeLabels: false,
18368 // Excludes the label when calculating node bounding boxes for the layout algorithm
18369 spacingFactor: void 0,
18370 // Applies a multiplicative factor (>0) to expand or compress the overall area that the nodes take up
18371 condense: false,
18372 // uses all available space on false, uses minimal space on true
18373 rows: void 0,
18374 // force num of rows in the grid
18375 cols: void 0,
18376 // force num of columns in the grid
18377 position: function position2(node) {
18378 },
18379 // returns { row, col } for element
18380 sort: void 0,
18381 // a sorting function to order the nodes; e.g. function(a, b){ return a.data('weight') - b.data('weight') }
18382 animate: false,
18383 // whether to transition the node positions
18384 animationDuration: 500,
18385 // duration of animation in ms if enabled
18386 animationEasing: void 0,
18387 // easing of animation if enabled
18388 animateFilter: function animateFilter(node, i2) {
18389 return true;
18390 },
18391 // a function that determines whether the node should be animated. All nodes animated by default on animate enabled. Non-animated nodes are positioned immediately when the layout starts
18392 ready: void 0,
18393 // callback on layoutready
18394 stop: void 0,
18395 // callback on layoutstop
18396 transform: function transform(node, position2) {
18397 return position2;
18398 }
18399 // transform a given node position. Useful for changing flow direction in discrete layouts
18400 };
18401 function GridLayout(options) {
18402 this.options = extend({}, defaults$3, options);
18403 }
18404 GridLayout.prototype.run = function() {
18405 var params = this.options;
18406 var options = params;
18407 var cy = params.cy;
18408 var eles = options.eles;
18409 var nodes2 = eles.nodes().not(":parent");
18410 if (options.sort) {
18411 nodes2 = nodes2.sort(options.sort);
18412 }
18413 var bb = makeBoundingBox(options.boundingBox ? options.boundingBox : {
18414 x1: 0,
18415 y1: 0,
18416 w: cy.width(),
18417 h: cy.height()
18418 });
18419 if (bb.h === 0 || bb.w === 0) {
18420 eles.nodes().layoutPositions(this, options, function(ele) {
18421 return {
18422 x: bb.x1,
18423 y: bb.y1
18424 };
18425 });
18426 } else {
18427 var cells = nodes2.size();
18428 var splits = Math.sqrt(cells * bb.h / bb.w);
18429 var rows = Math.round(splits);
18430 var cols = Math.round(bb.w / bb.h * splits);
18431 var small = function small2(val) {
18432 if (val == null) {
18433 return Math.min(rows, cols);
18434 } else {
18435 var min2 = Math.min(rows, cols);
18436 if (min2 == rows) {
18437 rows = val;
18438 } else {
18439 cols = val;
18440 }
18441 }
18442 };
18443 var large = function large2(val) {
18444 if (val == null) {
18445 return Math.max(rows, cols);
18446 } else {
18447 var max2 = Math.max(rows, cols);
18448 if (max2 == rows) {
18449 rows = val;
18450 } else {
18451 cols = val;
18452 }
18453 }
18454 };
18455 var oRows = options.rows;
18456 var oCols = options.cols != null ? options.cols : options.columns;
18457 if (oRows != null && oCols != null) {
18458 rows = oRows;
18459 cols = oCols;
18460 } else if (oRows != null && oCols == null) {
18461 rows = oRows;
18462 cols = Math.ceil(cells / rows);
18463 } else if (oRows == null && oCols != null) {
18464 cols = oCols;
18465 rows = Math.ceil(cells / cols);
18466 } else if (cols * rows > cells) {
18467 var sm = small();
18468 var lg = large();
18469 if ((sm - 1) * lg >= cells) {
18470 small(sm - 1);
18471 } else if ((lg - 1) * sm >= cells) {
18472 large(lg - 1);
18473 }
18474 } else {
18475 while (cols * rows < cells) {
18476 var _sm = small();
18477 var _lg = large();
18478 if ((_lg + 1) * _sm >= cells) {
18479 large(_lg + 1);
18480 } else {
18481 small(_sm + 1);
18482 }
18483 }
18484 }
18485 var cellWidth = bb.w / cols;
18486 var cellHeight = bb.h / rows;
18487 if (options.condense) {
18488 cellWidth = 0;
18489 cellHeight = 0;
18490 }
18491 if (options.avoidOverlap) {
18492 for (var i2 = 0; i2 < nodes2.length; i2++) {
18493 var node = nodes2[i2];
18494 var pos = node._private.position;
18495 if (pos.x == null || pos.y == null) {
18496 pos.x = 0;
18497 pos.y = 0;
18498 }
18499 var nbb = node.layoutDimensions(options);
18500 var p2 = options.avoidOverlapPadding;
18501 var w = nbb.w + p2;
18502 var h = nbb.h + p2;
18503 cellWidth = Math.max(cellWidth, w);
18504 cellHeight = Math.max(cellHeight, h);
18505 }
18506 }
18507 var cellUsed = {};
18508 var used = function used2(row2, col2) {
18509 return cellUsed["c-" + row2 + "-" + col2] ? true : false;
18510 };
18511 var use = function use2(row2, col2) {
18512 cellUsed["c-" + row2 + "-" + col2] = true;
18513 };
18514 var row = 0;
18515 var col = 0;
18516 var moveToNextCell = function moveToNextCell2() {
18517 col++;
18518 if (col >= cols) {
18519 col = 0;
18520 row++;
18521 }
18522 };
18523 var id2manPos = {};
18524 for (var _i = 0; _i < nodes2.length; _i++) {
18525 var _node = nodes2[_i];
18526 var rcPos = options.position(_node);
18527 if (rcPos && (rcPos.row !== void 0 || rcPos.col !== void 0)) {
18528 var _pos = {
18529 row: rcPos.row,
18530 col: rcPos.col
18531 };
18532 if (_pos.col === void 0) {
18533 _pos.col = 0;
18534 while (used(_pos.row, _pos.col)) {
18535 _pos.col++;
18536 }
18537 } else if (_pos.row === void 0) {
18538 _pos.row = 0;
18539 while (used(_pos.row, _pos.col)) {
18540 _pos.row++;
18541 }
18542 }
18543 id2manPos[_node.id()] = _pos;
18544 use(_pos.row, _pos.col);
18545 }
18546 }
18547 var getPos = function getPos2(element2, i3) {
18548 var x, y;
18549 if (element2.locked() || element2.isParent()) {
18550 return false;
18551 }
18552 var rcPos2 = id2manPos[element2.id()];
18553 if (rcPos2) {
18554 x = rcPos2.col * cellWidth + cellWidth / 2 + bb.x1;
18555 y = rcPos2.row * cellHeight + cellHeight / 2 + bb.y1;
18556 } else {
18557 while (used(row, col)) {
18558 moveToNextCell();
18559 }
18560 x = col * cellWidth + cellWidth / 2 + bb.x1;
18561 y = row * cellHeight + cellHeight / 2 + bb.y1;
18562 use(row, col);
18563 moveToNextCell();
18564 }
18565 return {
18566 x,
18567 y
18568 };
18569 };
18570 nodes2.layoutPositions(this, options, getPos);
18571 }
18572 return this;
18573 };
18574 var defaults$2 = {
18575 ready: function ready() {
18576 },
18577 // on layoutready
18578 stop: function stop() {
18579 }
18580 // on layoutstop
18581 };
18582 function NullLayout(options) {
18583 this.options = extend({}, defaults$2, options);
18584 }
18585 NullLayout.prototype.run = function() {
18586 var options = this.options;
18587 var eles = options.eles;
18588 var layout2 = this;
18589 options.cy;
18590 layout2.emit("layoutstart");
18591 eles.nodes().positions(function() {
18592 return {
18593 x: 0,
18594 y: 0
18595 };
18596 });
18597 layout2.one("layoutready", options.ready);
18598 layout2.emit("layoutready");
18599 layout2.one("layoutstop", options.stop);
18600 layout2.emit("layoutstop");
18601 return this;
18602 };
18603 NullLayout.prototype.stop = function() {
18604 return this;
18605 };
18606 var defaults$1 = {
18607 positions: void 0,
18608 // map of (node id) => (position obj); or function(node){ return somPos; }
18609 zoom: void 0,
18610 // the zoom level to set (prob want fit = false if set)
18611 pan: void 0,
18612 // the pan level to set (prob want fit = false if set)
18613 fit: true,
18614 // whether to fit to viewport
18615 padding: 30,
18616 // padding on fit
18617 animate: false,
18618 // whether to transition the node positions
18619 animationDuration: 500,
18620 // duration of animation in ms if enabled
18621 animationEasing: void 0,
18622 // easing of animation if enabled
18623 animateFilter: function animateFilter(node, i2) {
18624 return true;
18625 },
18626 // a function that determines whether the node should be animated. All nodes animated by default on animate enabled. Non-animated nodes are positioned immediately when the layout starts
18627 ready: void 0,
18628 // callback on layoutready
18629 stop: void 0,
18630 // callback on layoutstop
18631 transform: function transform(node, position2) {
18632 return position2;
18633 }
18634 // transform a given node position. Useful for changing flow direction in discrete layouts
18635 };
18636 function PresetLayout(options) {
18637 this.options = extend({}, defaults$1, options);
18638 }
18639 PresetLayout.prototype.run = function() {
18640 var options = this.options;
18641 var eles = options.eles;
18642 var nodes2 = eles.nodes();
18643 var posIsFn = fn$6(options.positions);
18644 function getPosition(node) {
18645 if (options.positions == null) {
18646 return copyPosition(node.position());
18647 }
18648 if (posIsFn) {
18649 return options.positions(node);
18650 }
18651 var pos = options.positions[node._private.data.id];
18652 if (pos == null) {
18653 return null;
18654 }
18655 return pos;
18656 }
18657 nodes2.layoutPositions(this, options, function(node, i2) {
18658 var position2 = getPosition(node);
18659 if (node.locked() || position2 == null) {
18660 return false;
18661 }
18662 return position2;
18663 });
18664 return this;
18665 };
18666 var defaults = {
18667 fit: true,
18668 // whether to fit to viewport
18669 padding: 30,
18670 // fit padding
18671 boundingBox: void 0,
18672 // constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
18673 animate: false,
18674 // whether to transition the node positions
18675 animationDuration: 500,
18676 // duration of animation in ms if enabled
18677 animationEasing: void 0,
18678 // easing of animation if enabled
18679 animateFilter: function animateFilter(node, i2) {
18680 return true;
18681 },
18682 // a function that determines whether the node should be animated. All nodes animated by default on animate enabled. Non-animated nodes are positioned immediately when the layout starts
18683 ready: void 0,
18684 // callback on layoutready
18685 stop: void 0,
18686 // callback on layoutstop
18687 transform: function transform(node, position2) {
18688 return position2;
18689 }
18690 // transform a given node position. Useful for changing flow direction in discrete layouts
18691 };
18692 function RandomLayout(options) {
18693 this.options = extend({}, defaults, options);
18694 }
18695 RandomLayout.prototype.run = function() {
18696 var options = this.options;
18697 var cy = options.cy;
18698 var eles = options.eles;
18699 var bb = makeBoundingBox(options.boundingBox ? options.boundingBox : {
18700 x1: 0,
18701 y1: 0,
18702 w: cy.width(),
18703 h: cy.height()
18704 });
18705 var getPos = function getPos2(node, i2) {
18706 return {
18707 x: bb.x1 + Math.round(Math.random() * bb.w),
18708 y: bb.y1 + Math.round(Math.random() * bb.h)
18709 };
18710 };
18711 eles.nodes().layoutPositions(this, options, getPos);
18712 return this;
18713 };
18714 var layout = [{
18715 name: "breadthfirst",
18716 impl: BreadthFirstLayout
18717 }, {
18718 name: "circle",
18719 impl: CircleLayout
18720 }, {
18721 name: "concentric",
18722 impl: ConcentricLayout
18723 }, {
18724 name: "cose",
18725 impl: CoseLayout
18726 }, {
18727 name: "grid",
18728 impl: GridLayout
18729 }, {
18730 name: "null",
18731 impl: NullLayout
18732 }, {
18733 name: "preset",
18734 impl: PresetLayout
18735 }, {
18736 name: "random",
18737 impl: RandomLayout
18738 }];
18739 function NullRenderer(options) {
18740 this.options = options;
18741 this.notifications = 0;
18742 }
18743 var noop = function noop2() {
18744 };
18745 var throwImgErr = function throwImgErr2() {
18746 throw new Error("A headless instance can not render images");
18747 };
18748 NullRenderer.prototype = {
18749 recalculateRenderedStyle: noop,
18750 notify: function notify() {
18751 this.notifications++;
18752 },
18753 init: noop,
18754 isHeadless: function isHeadless() {
18755 return true;
18756 },
18757 png: throwImgErr,
18758 jpg: throwImgErr
18759 };
18760 var BRp$f = {};
18761 BRp$f.arrowShapeWidth = 0.3;
18762 BRp$f.registerArrowShapes = function() {
18763 var arrowShapes = this.arrowShapes = {};
18764 var renderer2 = this;
18765 var bbCollide = function bbCollide2(x, y, size, angle, translation, edgeWidth, padding) {
18766 var x1 = translation.x - size / 2 - padding;
18767 var x2 = translation.x + size / 2 + padding;
18768 var y1 = translation.y - size / 2 - padding;
18769 var y2 = translation.y + size / 2 + padding;
18770 var inside = x1 <= x && x <= x2 && y1 <= y && y <= y2;
18771 return inside;
18772 };
18773 var transform = function transform2(x, y, size, angle, translation) {
18774 var xRotated = x * Math.cos(angle) - y * Math.sin(angle);
18775 var yRotated = x * Math.sin(angle) + y * Math.cos(angle);
18776 var xScaled = xRotated * size;
18777 var yScaled = yRotated * size;
18778 var xTranslated = xScaled + translation.x;
18779 var yTranslated = yScaled + translation.y;
18780 return {
18781 x: xTranslated,
18782 y: yTranslated
18783 };
18784 };
18785 var transformPoints = function transformPoints2(pts2, size, angle, translation) {
18786 var retPts = [];
18787 for (var i2 = 0; i2 < pts2.length; i2 += 2) {
18788 var x = pts2[i2];
18789 var y = pts2[i2 + 1];
18790 retPts.push(transform(x, y, size, angle, translation));
18791 }
18792 return retPts;
18793 };
18794 var pointsToArr = function pointsToArr2(pts2) {
18795 var ret = [];
18796 for (var i2 = 0; i2 < pts2.length; i2++) {
18797 var p2 = pts2[i2];
18798 ret.push(p2.x, p2.y);
18799 }
18800 return ret;
18801 };
18802 var standardGap = function standardGap2(edge) {
18803 return edge.pstyle("width").pfValue * edge.pstyle("arrow-scale").pfValue * 2;
18804 };
18805 var defineArrowShape = function defineArrowShape2(name2, defn) {
18806 if (string(defn)) {
18807 defn = arrowShapes[defn];
18808 }
18809 arrowShapes[name2] = extend({
18810 name: name2,
18811 points: [-0.15, -0.3, 0.15, -0.3, 0.15, 0.3, -0.15, 0.3],
18812 collide: function collide(x, y, size, angle, translation, padding) {
18813 var points = pointsToArr(transformPoints(this.points, size + 2 * padding, angle, translation));
18814 var inside = pointInsidePolygonPoints(x, y, points);
18815 return inside;
18816 },
18817 roughCollide: bbCollide,
18818 draw: function draw2(context, size, angle, translation) {
18819 var points = transformPoints(this.points, size, angle, translation);
18820 renderer2.arrowShapeImpl("polygon")(context, points);
18821 },
18822 spacing: function spacing(edge) {
18823 return 0;
18824 },
18825 gap: standardGap
18826 }, defn);
18827 };
18828 defineArrowShape("none", {
18829 collide: falsify,
18830 roughCollide: falsify,
18831 draw: noop$1,
18832 spacing: zeroify,
18833 gap: zeroify
18834 });
18835 defineArrowShape("triangle", {
18836 points: [-0.15, -0.3, 0, 0, 0.15, -0.3]
18837 });
18838 defineArrowShape("arrow", "triangle");
18839 defineArrowShape("triangle-backcurve", {
18840 points: arrowShapes["triangle"].points,
18841 controlPoint: [0, -0.15],
18842 roughCollide: bbCollide,
18843 draw: function draw2(context, size, angle, translation, edgeWidth) {
18844 var ptsTrans = transformPoints(this.points, size, angle, translation);
18845 var ctrlPt = this.controlPoint;
18846 var ctrlPtTrans = transform(ctrlPt[0], ctrlPt[1], size, angle, translation);
18847 renderer2.arrowShapeImpl(this.name)(context, ptsTrans, ctrlPtTrans);
18848 },
18849 gap: function gap(edge) {
18850 return standardGap(edge) * 0.8;
18851 }
18852 });
18853 defineArrowShape("triangle-tee", {
18854 points: [0, 0, 0.15, -0.3, -0.15, -0.3, 0, 0],
18855 pointsTee: [-0.15, -0.4, -0.15, -0.5, 0.15, -0.5, 0.15, -0.4],
18856 collide: function collide(x, y, size, angle, translation, edgeWidth, padding) {
18857 var triPts = pointsToArr(transformPoints(this.points, size + 2 * padding, angle, translation));
18858 var teePts = pointsToArr(transformPoints(this.pointsTee, size + 2 * padding, angle, translation));
18859 var inside = pointInsidePolygonPoints(x, y, triPts) || pointInsidePolygonPoints(x, y, teePts);
18860 return inside;
18861 },
18862 draw: function draw2(context, size, angle, translation, edgeWidth) {
18863 var triPts = transformPoints(this.points, size, angle, translation);
18864 var teePts = transformPoints(this.pointsTee, size, angle, translation);
18865 renderer2.arrowShapeImpl(this.name)(context, triPts, teePts);
18866 }
18867 });
18868 defineArrowShape("circle-triangle", {
18869 radius: 0.15,
18870 pointsTr: [0, -0.15, 0.15, -0.45, -0.15, -0.45, 0, -0.15],
18871 collide: function collide(x, y, size, angle, translation, edgeWidth, padding) {
18872 var t = translation;
18873 var circleInside = Math.pow(t.x - x, 2) + Math.pow(t.y - y, 2) <= Math.pow((size + 2 * padding) * this.radius, 2);
18874 var triPts = pointsToArr(transformPoints(this.points, size + 2 * padding, angle, translation));
18875 return pointInsidePolygonPoints(x, y, triPts) || circleInside;
18876 },
18877 draw: function draw2(context, size, angle, translation, edgeWidth) {
18878 var triPts = transformPoints(this.pointsTr, size, angle, translation);
18879 renderer2.arrowShapeImpl(this.name)(context, triPts, translation.x, translation.y, this.radius * size);
18880 },
18881 spacing: function spacing(edge) {
18882 return renderer2.getArrowWidth(edge.pstyle("width").pfValue, edge.pstyle("arrow-scale").value) * this.radius;
18883 }
18884 });
18885 defineArrowShape("triangle-cross", {
18886 points: [0, 0, 0.15, -0.3, -0.15, -0.3, 0, 0],
18887 baseCrossLinePts: [
18888 -0.15,
18889 -0.4,
18890 // first half of the rectangle
18891 -0.15,
18892 -0.4,
18893 0.15,
18894 -0.4,
18895 // second half of the rectangle
18896 0.15,
18897 -0.4
18898 ],
18899 crossLinePts: function crossLinePts(size, edgeWidth) {
18900 var p2 = this.baseCrossLinePts.slice();
18901 var shiftFactor = edgeWidth / size;
18902 var y0 = 3;
18903 var y1 = 5;
18904 p2[y0] = p2[y0] - shiftFactor;
18905 p2[y1] = p2[y1] - shiftFactor;
18906 return p2;
18907 },
18908 collide: function collide(x, y, size, angle, translation, edgeWidth, padding) {
18909 var triPts = pointsToArr(transformPoints(this.points, size + 2 * padding, angle, translation));
18910 var teePts = pointsToArr(transformPoints(this.crossLinePts(size, edgeWidth), size + 2 * padding, angle, translation));
18911 var inside = pointInsidePolygonPoints(x, y, triPts) || pointInsidePolygonPoints(x, y, teePts);
18912 return inside;
18913 },
18914 draw: function draw2(context, size, angle, translation, edgeWidth) {
18915 var triPts = transformPoints(this.points, size, angle, translation);
18916 var crossLinePts = transformPoints(this.crossLinePts(size, edgeWidth), size, angle, translation);
18917 renderer2.arrowShapeImpl(this.name)(context, triPts, crossLinePts);
18918 }
18919 });
18920 defineArrowShape("vee", {
18921 points: [-0.15, -0.3, 0, 0, 0.15, -0.3, 0, -0.15],
18922 gap: function gap(edge) {
18923 return standardGap(edge) * 0.525;
18924 }
18925 });
18926 defineArrowShape("circle", {
18927 radius: 0.15,
18928 collide: function collide(x, y, size, angle, translation, edgeWidth, padding) {
18929 var t = translation;
18930 var inside = Math.pow(t.x - x, 2) + Math.pow(t.y - y, 2) <= Math.pow((size + 2 * padding) * this.radius, 2);
18931 return inside;
18932 },
18933 draw: function draw2(context, size, angle, translation, edgeWidth) {
18934 renderer2.arrowShapeImpl(this.name)(context, translation.x, translation.y, this.radius * size);
18935 },
18936 spacing: function spacing(edge) {
18937 return renderer2.getArrowWidth(edge.pstyle("width").pfValue, edge.pstyle("arrow-scale").value) * this.radius;
18938 }
18939 });
18940 defineArrowShape("tee", {
18941 points: [-0.15, 0, -0.15, -0.1, 0.15, -0.1, 0.15, 0],
18942 spacing: function spacing(edge) {
18943 return 1;
18944 },
18945 gap: function gap(edge) {
18946 return 1;
18947 }
18948 });
18949 defineArrowShape("square", {
18950 points: [-0.15, 0, 0.15, 0, 0.15, -0.3, -0.15, -0.3]
18951 });
18952 defineArrowShape("diamond", {
18953 points: [-0.15, -0.15, 0, -0.3, 0.15, -0.15, 0, 0],
18954 gap: function gap(edge) {
18955 return edge.pstyle("width").pfValue * edge.pstyle("arrow-scale").value;
18956 }
18957 });
18958 defineArrowShape("chevron", {
18959 points: [0, 0, -0.15, -0.15, -0.1, -0.2, 0, -0.1, 0.1, -0.2, 0.15, -0.15],
18960 gap: function gap(edge) {
18961 return 0.95 * edge.pstyle("width").pfValue * edge.pstyle("arrow-scale").value;
18962 }
18963 });
18964 };
18965 var BRp$e = {};
18966 BRp$e.projectIntoViewport = function(clientX, clientY) {
18967 var cy = this.cy;
18968 var offsets = this.findContainerClientCoords();
18969 var offsetLeft = offsets[0];
18970 var offsetTop = offsets[1];
18971 var scale = offsets[4];
18972 var pan = cy.pan();
18973 var zoom = cy.zoom();
18974 var x = ((clientX - offsetLeft) / scale - pan.x) / zoom;
18975 var y = ((clientY - offsetTop) / scale - pan.y) / zoom;
18976 return [x, y];
18977 };
18978 BRp$e.findContainerClientCoords = function() {
18979 if (this.containerBB) {
18980 return this.containerBB;
18981 }
18982 var container = this.container;
18983 var rect = container.getBoundingClientRect();
18984 var style = window$1.getComputedStyle(container);
18985 var styleValue = function styleValue2(name2) {
18986 return parseFloat(style.getPropertyValue(name2));
18987 };
18988 var padding = {
18989 left: styleValue("padding-left"),
18990 right: styleValue("padding-right"),
18991 top: styleValue("padding-top"),
18992 bottom: styleValue("padding-bottom")
18993 };
18994 var border = {
18995 left: styleValue("border-left-width"),
18996 right: styleValue("border-right-width"),
18997 top: styleValue("border-top-width"),
18998 bottom: styleValue("border-bottom-width")
18999 };
19000 var clientWidth = container.clientWidth;
19001 var clientHeight = container.clientHeight;
19002 var paddingHor = padding.left + padding.right;
19003 var paddingVer = padding.top + padding.bottom;
19004 var borderHor = border.left + border.right;
19005 var scale = rect.width / (clientWidth + borderHor);
19006 var unscaledW = clientWidth - paddingHor;
19007 var unscaledH = clientHeight - paddingVer;
19008 var left = rect.left + padding.left + border.left;
19009 var top = rect.top + padding.top + border.top;
19010 return this.containerBB = [left, top, unscaledW, unscaledH, scale];
19011 };
19012 BRp$e.invalidateContainerClientCoordsCache = function() {
19013 this.containerBB = null;
19014 };
19015 BRp$e.findNearestElement = function(x, y, interactiveElementsOnly, isTouch) {
19016 return this.findNearestElements(x, y, interactiveElementsOnly, isTouch)[0];
19017 };
19018 BRp$e.findNearestElements = function(x, y, interactiveElementsOnly, isTouch) {
19019 var self2 = this;
19020 var r = this;
19021 var eles = r.getCachedZSortedEles();
19022 var near = [];
19023 var zoom = r.cy.zoom();
19024 var hasCompounds = r.cy.hasCompoundNodes();
19025 var edgeThreshold = (isTouch ? 24 : 8) / zoom;
19026 var nodeThreshold = (isTouch ? 8 : 2) / zoom;
19027 var labelThreshold = (isTouch ? 8 : 2) / zoom;
19028 var minSqDist = Infinity;
19029 var nearEdge;
19030 var nearNode;
19031 if (interactiveElementsOnly) {
19032 eles = eles.interactive;
19033 }
19034 function addEle(ele2, sqDist) {
19035 if (ele2.isNode()) {
19036 if (nearNode) {
19037 return;
19038 } else {
19039 nearNode = ele2;
19040 near.push(ele2);
19041 }
19042 }
19043 if (ele2.isEdge() && (sqDist == null || sqDist < minSqDist)) {
19044 if (nearEdge) {
19045 if (nearEdge.pstyle("z-compound-depth").value === ele2.pstyle("z-compound-depth").value && nearEdge.pstyle("z-compound-depth").value === ele2.pstyle("z-compound-depth").value) {
19046 for (var i3 = 0; i3 < near.length; i3++) {
19047 if (near[i3].isEdge()) {
19048 near[i3] = ele2;
19049 nearEdge = ele2;
19050 minSqDist = sqDist != null ? sqDist : minSqDist;
19051 break;
19052 }
19053 }
19054 }
19055 } else {
19056 near.push(ele2);
19057 nearEdge = ele2;
19058 minSqDist = sqDist != null ? sqDist : minSqDist;
19059 }
19060 }
19061 }
19062 function checkNode(node) {
19063 var width = node.outerWidth() + 2 * nodeThreshold;
19064 var height = node.outerHeight() + 2 * nodeThreshold;
19065 var hw = width / 2;
19066 var hh = height / 2;
19067 var pos = node.position();
19068 if (pos.x - hw <= x && x <= pos.x + hw && pos.y - hh <= y && y <= pos.y + hh) {
19069 var shape = r.nodeShapes[self2.getNodeShape(node)];
19070 if (shape.checkPoint(x, y, 0, width, height, pos.x, pos.y)) {
19071 addEle(node, 0);
19072 return true;
19073 }
19074 }
19075 }
19076 function checkEdge(edge) {
19077 var _p = edge._private;
19078 var rs = _p.rscratch;
19079 var styleWidth = edge.pstyle("width").pfValue;
19080 var scale = edge.pstyle("arrow-scale").value;
19081 var width = styleWidth / 2 + edgeThreshold;
19082 var widthSq = width * width;
19083 var width2 = width * 2;
19084 var src = _p.source;
19085 var tgt = _p.target;
19086 var sqDist;
19087 if (rs.edgeType === "segments" || rs.edgeType === "straight" || rs.edgeType === "haystack") {
19088 var pts2 = rs.allpts;
19089 for (var i3 = 0; i3 + 3 < pts2.length; i3 += 2) {
19090 if (inLineVicinity(x, y, pts2[i3], pts2[i3 + 1], pts2[i3 + 2], pts2[i3 + 3], width2) && widthSq > (sqDist = sqdistToFiniteLine(x, y, pts2[i3], pts2[i3 + 1], pts2[i3 + 2], pts2[i3 + 3]))) {
19091 addEle(edge, sqDist);
19092 return true;
19093 }
19094 }
19095 } else if (rs.edgeType === "bezier" || rs.edgeType === "multibezier" || rs.edgeType === "self" || rs.edgeType === "compound") {
19096 var pts2 = rs.allpts;
19097 for (var i3 = 0; i3 + 5 < rs.allpts.length; i3 += 4) {
19098 if (inBezierVicinity(x, y, pts2[i3], pts2[i3 + 1], pts2[i3 + 2], pts2[i3 + 3], pts2[i3 + 4], pts2[i3 + 5], width2) && widthSq > (sqDist = sqdistToQuadraticBezier(x, y, pts2[i3], pts2[i3 + 1], pts2[i3 + 2], pts2[i3 + 3], pts2[i3 + 4], pts2[i3 + 5]))) {
19099 addEle(edge, sqDist);
19100 return true;
19101 }
19102 }
19103 }
19104 var src = src || _p.source;
19105 var tgt = tgt || _p.target;
19106 var arSize = self2.getArrowWidth(styleWidth, scale);
19107 var arrows = [{
19108 name: "source",
19109 x: rs.arrowStartX,
19110 y: rs.arrowStartY,
19111 angle: rs.srcArrowAngle
19112 }, {
19113 name: "target",
19114 x: rs.arrowEndX,
19115 y: rs.arrowEndY,
19116 angle: rs.tgtArrowAngle
19117 }, {
19118 name: "mid-source",
19119 x: rs.midX,
19120 y: rs.midY,
19121 angle: rs.midsrcArrowAngle
19122 }, {
19123 name: "mid-target",
19124 x: rs.midX,
19125 y: rs.midY,
19126 angle: rs.midtgtArrowAngle
19127 }];
19128 for (var i3 = 0; i3 < arrows.length; i3++) {
19129 var ar = arrows[i3];
19130 var shape = r.arrowShapes[edge.pstyle(ar.name + "-arrow-shape").value];
19131 var edgeWidth = edge.pstyle("width").pfValue;
19132 if (shape.roughCollide(x, y, arSize, ar.angle, {
19133 x: ar.x,
19134 y: ar.y
19135 }, edgeWidth, edgeThreshold) && shape.collide(x, y, arSize, ar.angle, {
19136 x: ar.x,
19137 y: ar.y
19138 }, edgeWidth, edgeThreshold)) {
19139 addEle(edge);
19140 return true;
19141 }
19142 }
19143 if (hasCompounds && near.length > 0) {
19144 checkNode(src);
19145 checkNode(tgt);
19146 }
19147 }
19148 function preprop(obj, name2, pre) {
19149 return getPrefixedProperty(obj, name2, pre);
19150 }
19151 function checkLabel(ele2, prefix) {
19152 var _p = ele2._private;
19153 var th = labelThreshold;
19154 var prefixDash;
19155 if (prefix) {
19156 prefixDash = prefix + "-";
19157 } else {
19158 prefixDash = "";
19159 }
19160 ele2.boundingBox();
19161 var bb = _p.labelBounds[prefix || "main"];
19162 var text = ele2.pstyle(prefixDash + "label").value;
19163 var eventsEnabled = ele2.pstyle("text-events").strValue === "yes";
19164 if (!eventsEnabled || !text) {
19165 return;
19166 }
19167 var lx = preprop(_p.rscratch, "labelX", prefix);
19168 var ly = preprop(_p.rscratch, "labelY", prefix);
19169 var theta = preprop(_p.rscratch, "labelAngle", prefix);
19170 var ox = ele2.pstyle(prefixDash + "text-margin-x").pfValue;
19171 var oy = ele2.pstyle(prefixDash + "text-margin-y").pfValue;
19172 var lx1 = bb.x1 - th - ox;
19173 var lx2 = bb.x2 + th - ox;
19174 var ly1 = bb.y1 - th - oy;
19175 var ly2 = bb.y2 + th - oy;
19176 if (theta) {
19177 var cos2 = Math.cos(theta);
19178 var sin2 = Math.sin(theta);
19179 var rotate = function rotate2(x2, y2) {
19180 x2 = x2 - lx;
19181 y2 = y2 - ly;
19182 return {
19183 x: x2 * cos2 - y2 * sin2 + lx,
19184 y: x2 * sin2 + y2 * cos2 + ly
19185 };
19186 };
19187 var px1y1 = rotate(lx1, ly1);
19188 var px1y2 = rotate(lx1, ly2);
19189 var px2y1 = rotate(lx2, ly1);
19190 var px2y2 = rotate(lx2, ly2);
19191 var points = [
19192 // with the margin added after the rotation is applied
19193 px1y1.x + ox,
19194 px1y1.y + oy,
19195 px2y1.x + ox,
19196 px2y1.y + oy,
19197 px2y2.x + ox,
19198 px2y2.y + oy,
19199 px1y2.x + ox,
19200 px1y2.y + oy
19201 ];
19202 if (pointInsidePolygonPoints(x, y, points)) {
19203 addEle(ele2);
19204 return true;
19205 }
19206 } else {
19207 if (inBoundingBox(bb, x, y)) {
19208 addEle(ele2);
19209 return true;
19210 }
19211 }
19212 }
19213 for (var i2 = eles.length - 1; i2 >= 0; i2--) {
19214 var ele = eles[i2];
19215 if (ele.isNode()) {
19216 checkNode(ele) || checkLabel(ele);
19217 } else {
19218 checkEdge(ele) || checkLabel(ele) || checkLabel(ele, "source") || checkLabel(ele, "target");
19219 }
19220 }
19221 return near;
19222 };
19223 BRp$e.getAllInBox = function(x1, y1, x2, y2) {
19224 var eles = this.getCachedZSortedEles().interactive;
19225 var box = [];
19226 var x1c = Math.min(x1, x2);
19227 var x2c = Math.max(x1, x2);
19228 var y1c = Math.min(y1, y2);
19229 var y2c = Math.max(y1, y2);
19230 x1 = x1c;
19231 x2 = x2c;
19232 y1 = y1c;
19233 y2 = y2c;
19234 var boxBb = makeBoundingBox({
19235 x1,
19236 y1,
19237 x2,
19238 y2
19239 });
19240 for (var e = 0; e < eles.length; e++) {
19241 var ele = eles[e];
19242 if (ele.isNode()) {
19243 var node = ele;
19244 var nodeBb = node.boundingBox({
19245 includeNodes: true,
19246 includeEdges: false,
19247 includeLabels: false
19248 });
19249 if (boundingBoxesIntersect(boxBb, nodeBb) && !boundingBoxInBoundingBox(nodeBb, boxBb)) {
19250 box.push(node);
19251 }
19252 } else {
19253 var edge = ele;
19254 var _p = edge._private;
19255 var rs = _p.rscratch;
19256 if (rs.startX != null && rs.startY != null && !inBoundingBox(boxBb, rs.startX, rs.startY)) {
19257 continue;
19258 }
19259 if (rs.endX != null && rs.endY != null && !inBoundingBox(boxBb, rs.endX, rs.endY)) {
19260 continue;
19261 }
19262 if (rs.edgeType === "bezier" || rs.edgeType === "multibezier" || rs.edgeType === "self" || rs.edgeType === "compound" || rs.edgeType === "segments" || rs.edgeType === "haystack") {
19263 var pts2 = _p.rstyle.bezierPts || _p.rstyle.linePts || _p.rstyle.haystackPts;
19264 var allInside = true;
19265 for (var i2 = 0; i2 < pts2.length; i2++) {
19266 if (!pointInBoundingBox(boxBb, pts2[i2])) {
19267 allInside = false;
19268 break;
19269 }
19270 }
19271 if (allInside) {
19272 box.push(edge);
19273 }
19274 } else if (rs.edgeType === "haystack" || rs.edgeType === "straight") {
19275 box.push(edge);
19276 }
19277 }
19278 }
19279 return box;
19280 };
19281 var BRp$d = {};
19282 BRp$d.calculateArrowAngles = function(edge) {
19283 var rs = edge._private.rscratch;
19284 var isHaystack = rs.edgeType === "haystack";
19285 var isBezier = rs.edgeType === "bezier";
19286 var isMultibezier = rs.edgeType === "multibezier";
19287 var isSegments = rs.edgeType === "segments";
19288 var isCompound = rs.edgeType === "compound";
19289 var isSelf = rs.edgeType === "self";
19290 var dispX, dispY;
19291 var startX, startY, endX, endY, midX, midY;
19292 if (isHaystack) {
19293 startX = rs.haystackPts[0];
19294 startY = rs.haystackPts[1];
19295 endX = rs.haystackPts[2];
19296 endY = rs.haystackPts[3];
19297 } else {
19298 startX = rs.arrowStartX;
19299 startY = rs.arrowStartY;
19300 endX = rs.arrowEndX;
19301 endY = rs.arrowEndY;
19302 }
19303 midX = rs.midX;
19304 midY = rs.midY;
19305 if (isSegments) {
19306 dispX = startX - rs.segpts[0];
19307 dispY = startY - rs.segpts[1];
19308 } else if (isMultibezier || isCompound || isSelf || isBezier) {
19309 var pts2 = rs.allpts;
19310 var bX = qbezierAt(pts2[0], pts2[2], pts2[4], 0.1);
19311 var bY = qbezierAt(pts2[1], pts2[3], pts2[5], 0.1);
19312 dispX = startX - bX;
19313 dispY = startY - bY;
19314 } else {
19315 dispX = startX - midX;
19316 dispY = startY - midY;
19317 }
19318 rs.srcArrowAngle = getAngleFromDisp(dispX, dispY);
19319 var midX = rs.midX;
19320 var midY = rs.midY;
19321 if (isHaystack) {
19322 midX = (startX + endX) / 2;
19323 midY = (startY + endY) / 2;
19324 }
19325 dispX = endX - startX;
19326 dispY = endY - startY;
19327 if (isSegments) {
19328 var pts2 = rs.allpts;
19329 if (pts2.length / 2 % 2 === 0) {
19330 var i2 = pts2.length / 2;
19331 var i1 = i2 - 2;
19332 dispX = pts2[i2] - pts2[i1];
19333 dispY = pts2[i2 + 1] - pts2[i1 + 1];
19334 } else {
19335 var i2 = pts2.length / 2 - 1;
19336 var i1 = i2 - 2;
19337 var i3 = i2 + 2;
19338 dispX = pts2[i2] - pts2[i1];
19339 dispY = pts2[i2 + 1] - pts2[i1 + 1];
19340 }
19341 } else if (isMultibezier || isCompound || isSelf) {
19342 var pts2 = rs.allpts;
19343 var cpts = rs.ctrlpts;
19344 var bp0x, bp0y;
19345 var bp1x, bp1y;
19346 if (cpts.length / 2 % 2 === 0) {
19347 var p0 = pts2.length / 2 - 1;
19348 var ic = p0 + 2;
19349 var p1 = ic + 2;
19350 bp0x = qbezierAt(pts2[p0], pts2[ic], pts2[p1], 0);
19351 bp0y = qbezierAt(pts2[p0 + 1], pts2[ic + 1], pts2[p1 + 1], 0);
19352 bp1x = qbezierAt(pts2[p0], pts2[ic], pts2[p1], 1e-4);
19353 bp1y = qbezierAt(pts2[p0 + 1], pts2[ic + 1], pts2[p1 + 1], 1e-4);
19354 } else {
19355 var ic = pts2.length / 2 - 1;
19356 var p0 = ic - 2;
19357 var p1 = ic + 2;
19358 bp0x = qbezierAt(pts2[p0], pts2[ic], pts2[p1], 0.4999);
19359 bp0y = qbezierAt(pts2[p0 + 1], pts2[ic + 1], pts2[p1 + 1], 0.4999);
19360 bp1x = qbezierAt(pts2[p0], pts2[ic], pts2[p1], 0.5);
19361 bp1y = qbezierAt(pts2[p0 + 1], pts2[ic + 1], pts2[p1 + 1], 0.5);
19362 }
19363 dispX = bp1x - bp0x;
19364 dispY = bp1y - bp0y;
19365 }
19366 rs.midtgtArrowAngle = getAngleFromDisp(dispX, dispY);
19367 rs.midDispX = dispX;
19368 rs.midDispY = dispY;
19369 dispX *= -1;
19370 dispY *= -1;
19371 if (isSegments) {
19372 var pts2 = rs.allpts;
19373 if (pts2.length / 2 % 2 === 0)
19374 ;
19375 else {
19376 var i2 = pts2.length / 2 - 1;
19377 var i3 = i2 + 2;
19378 dispX = -(pts2[i3] - pts2[i2]);
19379 dispY = -(pts2[i3 + 1] - pts2[i2 + 1]);
19380 }
19381 }
19382 rs.midsrcArrowAngle = getAngleFromDisp(dispX, dispY);
19383 if (isSegments) {
19384 dispX = endX - rs.segpts[rs.segpts.length - 2];
19385 dispY = endY - rs.segpts[rs.segpts.length - 1];
19386 } else if (isMultibezier || isCompound || isSelf || isBezier) {
19387 var pts2 = rs.allpts;
19388 var l = pts2.length;
19389 var bX = qbezierAt(pts2[l - 6], pts2[l - 4], pts2[l - 2], 0.9);
19390 var bY = qbezierAt(pts2[l - 5], pts2[l - 3], pts2[l - 1], 0.9);
19391 dispX = endX - bX;
19392 dispY = endY - bY;
19393 } else {
19394 dispX = endX - midX;
19395 dispY = endY - midY;
19396 }
19397 rs.tgtArrowAngle = getAngleFromDisp(dispX, dispY);
19398 };
19399 BRp$d.getArrowWidth = BRp$d.getArrowHeight = function(edgeWidth, scale) {
19400 var cache2 = this.arrowWidthCache = this.arrowWidthCache || {};
19401 var cachedVal = cache2[edgeWidth + ", " + scale];
19402 if (cachedVal) {
19403 return cachedVal;
19404 }
19405 cachedVal = Math.max(Math.pow(edgeWidth * 13.37, 0.9), 29) * scale;
19406 cache2[edgeWidth + ", " + scale] = cachedVal;
19407 return cachedVal;
19408 };
19409 var BRp$c = {};
19410 BRp$c.findHaystackPoints = function(edges) {
19411 for (var i2 = 0; i2 < edges.length; i2++) {
19412 var edge = edges[i2];
19413 var _p = edge._private;
19414 var rs = _p.rscratch;
19415 if (!rs.haystack) {
19416 var angle = Math.random() * 2 * Math.PI;
19417 rs.source = {
19418 x: Math.cos(angle),
19419 y: Math.sin(angle)
19420 };
19421 angle = Math.random() * 2 * Math.PI;
19422 rs.target = {
19423 x: Math.cos(angle),
19424 y: Math.sin(angle)
19425 };
19426 }
19427 var src = _p.source;
19428 var tgt = _p.target;
19429 var srcPos = src.position();
19430 var tgtPos = tgt.position();
19431 var srcW = src.width();
19432 var tgtW = tgt.width();
19433 var srcH = src.height();
19434 var tgtH = tgt.height();
19435 var radius = edge.pstyle("haystack-radius").value;
19436 var halfRadius = radius / 2;
19437 rs.haystackPts = rs.allpts = [rs.source.x * srcW * halfRadius + srcPos.x, rs.source.y * srcH * halfRadius + srcPos.y, rs.target.x * tgtW * halfRadius + tgtPos.x, rs.target.y * tgtH * halfRadius + tgtPos.y];
19438 rs.midX = (rs.allpts[0] + rs.allpts[2]) / 2;
19439 rs.midY = (rs.allpts[1] + rs.allpts[3]) / 2;
19440 rs.edgeType = "haystack";
19441 rs.haystack = true;
19442 this.storeEdgeProjections(edge);
19443 this.calculateArrowAngles(edge);
19444 this.recalculateEdgeLabelProjections(edge);
19445 this.calculateLabelAngles(edge);
19446 }
19447 };
19448 BRp$c.findSegmentsPoints = function(edge, pairInfo) {
19449 var rs = edge._private.rscratch;
19450 var posPts = pairInfo.posPts, intersectionPts = pairInfo.intersectionPts, vectorNormInverse = pairInfo.vectorNormInverse;
19451 var edgeDistances = edge.pstyle("edge-distances").value;
19452 var segmentWs = edge.pstyle("segment-weights");
19453 var segmentDs = edge.pstyle("segment-distances");
19454 var segmentsN = Math.min(segmentWs.pfValue.length, segmentDs.pfValue.length);
19455 rs.edgeType = "segments";
19456 rs.segpts = [];
19457 for (var s = 0; s < segmentsN; s++) {
19458 var w = segmentWs.pfValue[s];
19459 var d = segmentDs.pfValue[s];
19460 var w1 = 1 - w;
19461 var w2 = w;
19462 var midptPts = edgeDistances === "node-position" ? posPts : intersectionPts;
19463 var adjustedMidpt = {
19464 x: midptPts.x1 * w1 + midptPts.x2 * w2,
19465 y: midptPts.y1 * w1 + midptPts.y2 * w2
19466 };
19467 rs.segpts.push(adjustedMidpt.x + vectorNormInverse.x * d, adjustedMidpt.y + vectorNormInverse.y * d);
19468 }
19469 };
19470 BRp$c.findLoopPoints = function(edge, pairInfo, i2, edgeIsUnbundled) {
19471 var rs = edge._private.rscratch;
19472 var dirCounts = pairInfo.dirCounts, srcPos = pairInfo.srcPos;
19473 var ctrlptDists = edge.pstyle("control-point-distances");
19474 var ctrlptDist = ctrlptDists ? ctrlptDists.pfValue[0] : void 0;
19475 var loopDir = edge.pstyle("loop-direction").pfValue;
19476 var loopSwp = edge.pstyle("loop-sweep").pfValue;
19477 var stepSize = edge.pstyle("control-point-step-size").pfValue;
19478 rs.edgeType = "self";
19479 var j = i2;
19480 var loopDist = stepSize;
19481 if (edgeIsUnbundled) {
19482 j = 0;
19483 loopDist = ctrlptDist;
19484 }
19485 var loopAngle = loopDir - Math.PI / 2;
19486 var outAngle = loopAngle - loopSwp / 2;
19487 var inAngle = loopAngle + loopSwp / 2;
19488 var dc = String(loopDir + "_" + loopSwp);
19489 j = dirCounts[dc] === void 0 ? dirCounts[dc] = 0 : ++dirCounts[dc];
19490 rs.ctrlpts = [srcPos.x + Math.cos(outAngle) * 1.4 * loopDist * (j / 3 + 1), srcPos.y + Math.sin(outAngle) * 1.4 * loopDist * (j / 3 + 1), srcPos.x + Math.cos(inAngle) * 1.4 * loopDist * (j / 3 + 1), srcPos.y + Math.sin(inAngle) * 1.4 * loopDist * (j / 3 + 1)];
19491 };
19492 BRp$c.findCompoundLoopPoints = function(edge, pairInfo, i2, edgeIsUnbundled) {
19493 var rs = edge._private.rscratch;
19494 rs.edgeType = "compound";
19495 var srcPos = pairInfo.srcPos, tgtPos = pairInfo.tgtPos, srcW = pairInfo.srcW, srcH = pairInfo.srcH, tgtW = pairInfo.tgtW, tgtH = pairInfo.tgtH;
19496 var stepSize = edge.pstyle("control-point-step-size").pfValue;
19497 var ctrlptDists = edge.pstyle("control-point-distances");
19498 var ctrlptDist = ctrlptDists ? ctrlptDists.pfValue[0] : void 0;
19499 var j = i2;
19500 var loopDist = stepSize;
19501 if (edgeIsUnbundled) {
19502 j = 0;
19503 loopDist = ctrlptDist;
19504 }
19505 var loopW = 50;
19506 var loopaPos = {
19507 x: srcPos.x - srcW / 2,
19508 y: srcPos.y - srcH / 2
19509 };
19510 var loopbPos = {
19511 x: tgtPos.x - tgtW / 2,
19512 y: tgtPos.y - tgtH / 2
19513 };
19514 var loopPos = {
19515 x: Math.min(loopaPos.x, loopbPos.x),
19516 y: Math.min(loopaPos.y, loopbPos.y)
19517 };
19518 var minCompoundStretch = 0.5;
19519 var compoundStretchA = Math.max(minCompoundStretch, Math.log(srcW * 0.01));
19520 var compoundStretchB = Math.max(minCompoundStretch, Math.log(tgtW * 0.01));
19521 rs.ctrlpts = [loopPos.x, loopPos.y - (1 + Math.pow(loopW, 1.12) / 100) * loopDist * (j / 3 + 1) * compoundStretchA, loopPos.x - (1 + Math.pow(loopW, 1.12) / 100) * loopDist * (j / 3 + 1) * compoundStretchB, loopPos.y];
19522 };
19523 BRp$c.findStraightEdgePoints = function(edge) {
19524 edge._private.rscratch.edgeType = "straight";
19525 };
19526 BRp$c.findBezierPoints = function(edge, pairInfo, i2, edgeIsUnbundled, edgeIsSwapped) {
19527 var rs = edge._private.rscratch;
19528 var vectorNormInverse = pairInfo.vectorNormInverse, posPts = pairInfo.posPts, intersectionPts = pairInfo.intersectionPts;
19529 var edgeDistances = edge.pstyle("edge-distances").value;
19530 var stepSize = edge.pstyle("control-point-step-size").pfValue;
19531 var ctrlptDists = edge.pstyle("control-point-distances");
19532 var ctrlptWs = edge.pstyle("control-point-weights");
19533 var bezierN = ctrlptDists && ctrlptWs ? Math.min(ctrlptDists.value.length, ctrlptWs.value.length) : 1;
19534 var ctrlptDist = ctrlptDists ? ctrlptDists.pfValue[0] : void 0;
19535 var ctrlptWeight = ctrlptWs.value[0];
19536 var multi = edgeIsUnbundled;
19537 rs.edgeType = multi ? "multibezier" : "bezier";
19538 rs.ctrlpts = [];
19539 for (var b = 0; b < bezierN; b++) {
19540 var normctrlptDist = (0.5 - pairInfo.eles.length / 2 + i2) * stepSize * (edgeIsSwapped ? -1 : 1);
19541 var manctrlptDist = void 0;
19542 var sign = signum(normctrlptDist);
19543 if (multi) {
19544 ctrlptDist = ctrlptDists ? ctrlptDists.pfValue[b] : stepSize;
19545 ctrlptWeight = ctrlptWs.value[b];
19546 }
19547 if (edgeIsUnbundled) {
19548 manctrlptDist = ctrlptDist;
19549 } else {
19550 manctrlptDist = ctrlptDist !== void 0 ? sign * ctrlptDist : void 0;
19551 }
19552 var distanceFromMidpoint = manctrlptDist !== void 0 ? manctrlptDist : normctrlptDist;
19553 var w1 = 1 - ctrlptWeight;
19554 var w2 = ctrlptWeight;
19555 var midptPts = edgeDistances === "node-position" ? posPts : intersectionPts;
19556 var adjustedMidpt = {
19557 x: midptPts.x1 * w1 + midptPts.x2 * w2,
19558 y: midptPts.y1 * w1 + midptPts.y2 * w2
19559 };
19560 rs.ctrlpts.push(adjustedMidpt.x + vectorNormInverse.x * distanceFromMidpoint, adjustedMidpt.y + vectorNormInverse.y * distanceFromMidpoint);
19561 }
19562 };
19563 BRp$c.findTaxiPoints = function(edge, pairInfo) {
19564 var rs = edge._private.rscratch;
19565 rs.edgeType = "segments";
19566 var VERTICAL = "vertical";
19567 var HORIZONTAL = "horizontal";
19568 var LEFTWARD = "leftward";
19569 var RIGHTWARD = "rightward";
19570 var DOWNWARD = "downward";
19571 var UPWARD = "upward";
19572 var AUTO = "auto";
19573 var posPts = pairInfo.posPts, srcW = pairInfo.srcW, srcH = pairInfo.srcH, tgtW = pairInfo.tgtW, tgtH = pairInfo.tgtH;
19574 var edgeDistances = edge.pstyle("edge-distances").value;
19575 var dIncludesNodeBody = edgeDistances !== "node-position";
19576 var taxiDir = edge.pstyle("taxi-direction").value;
19577 var rawTaxiDir = taxiDir;
19578 var taxiTurn = edge.pstyle("taxi-turn");
19579 var turnIsPercent = taxiTurn.units === "%";
19580 var taxiTurnPfVal = taxiTurn.pfValue;
19581 var turnIsNegative = taxiTurnPfVal < 0;
19582 var minD = edge.pstyle("taxi-turn-min-distance").pfValue;
19583 var dw = dIncludesNodeBody ? (srcW + tgtW) / 2 : 0;
19584 var dh = dIncludesNodeBody ? (srcH + tgtH) / 2 : 0;
19585 var pdx = posPts.x2 - posPts.x1;
19586 var pdy = posPts.y2 - posPts.y1;
19587 var subDWH = function subDWH2(dxy, dwh) {
19588 if (dxy > 0) {
19589 return Math.max(dxy - dwh, 0);
19590 } else {
19591 return Math.min(dxy + dwh, 0);
19592 }
19593 };
19594 var dx = subDWH(pdx, dw);
19595 var dy = subDWH(pdy, dh);
19596 var isExplicitDir = false;
19597 if (rawTaxiDir === AUTO) {
19598 taxiDir = Math.abs(dx) > Math.abs(dy) ? HORIZONTAL : VERTICAL;
19599 } else if (rawTaxiDir === UPWARD || rawTaxiDir === DOWNWARD) {
19600 taxiDir = VERTICAL;
19601 isExplicitDir = true;
19602 } else if (rawTaxiDir === LEFTWARD || rawTaxiDir === RIGHTWARD) {
19603 taxiDir = HORIZONTAL;
19604 isExplicitDir = true;
19605 }
19606 var isVert = taxiDir === VERTICAL;
19607 var l = isVert ? dy : dx;
19608 var pl = isVert ? pdy : pdx;
19609 var sgnL = signum(pl);
19610 var forcedDir = false;
19611 if (!(isExplicitDir && (turnIsPercent || turnIsNegative)) && (rawTaxiDir === DOWNWARD && pl < 0 || rawTaxiDir === UPWARD && pl > 0 || rawTaxiDir === LEFTWARD && pl > 0 || rawTaxiDir === RIGHTWARD && pl < 0)) {
19612 sgnL *= -1;
19613 l = sgnL * Math.abs(l);
19614 forcedDir = true;
19615 }
19616 var d;
19617 if (turnIsPercent) {
19618 var p2 = taxiTurnPfVal < 0 ? 1 + taxiTurnPfVal : taxiTurnPfVal;
19619 d = p2 * l;
19620 } else {
19621 var k = taxiTurnPfVal < 0 ? l : 0;
19622 d = k + taxiTurnPfVal * sgnL;
19623 }
19624 var getIsTooClose = function getIsTooClose2(d2) {
19625 return Math.abs(d2) < minD || Math.abs(d2) >= Math.abs(l);
19626 };
19627 var isTooCloseSrc = getIsTooClose(d);
19628 var isTooCloseTgt = getIsTooClose(Math.abs(l) - Math.abs(d));
19629 var isTooClose = isTooCloseSrc || isTooCloseTgt;
19630 if (isTooClose && !forcedDir) {
19631 if (isVert) {
19632 var lShapeInsideSrc = Math.abs(pl) <= srcH / 2;
19633 var lShapeInsideTgt = Math.abs(pdx) <= tgtW / 2;
19634 if (lShapeInsideSrc) {
19635 var x = (posPts.x1 + posPts.x2) / 2;
19636 var y1 = posPts.y1, y2 = posPts.y2;
19637 rs.segpts = [x, y1, x, y2];
19638 } else if (lShapeInsideTgt) {
19639 var y = (posPts.y1 + posPts.y2) / 2;
19640 var x1 = posPts.x1, x2 = posPts.x2;
19641 rs.segpts = [x1, y, x2, y];
19642 } else {
19643 rs.segpts = [posPts.x1, posPts.y2];
19644 }
19645 } else {
19646 var _lShapeInsideSrc = Math.abs(pl) <= srcW / 2;
19647 var _lShapeInsideTgt = Math.abs(pdy) <= tgtH / 2;
19648 if (_lShapeInsideSrc) {
19649 var _y = (posPts.y1 + posPts.y2) / 2;
19650 var _x = posPts.x1, _x2 = posPts.x2;
19651 rs.segpts = [_x, _y, _x2, _y];
19652 } else if (_lShapeInsideTgt) {
19653 var _x3 = (posPts.x1 + posPts.x2) / 2;
19654 var _y2 = posPts.y1, _y3 = posPts.y2;
19655 rs.segpts = [_x3, _y2, _x3, _y3];
19656 } else {
19657 rs.segpts = [posPts.x2, posPts.y1];
19658 }
19659 }
19660 } else {
19661 if (isVert) {
19662 var _y4 = posPts.y1 + d + (dIncludesNodeBody ? srcH / 2 * sgnL : 0);
19663 var _x4 = posPts.x1, _x5 = posPts.x2;
19664 rs.segpts = [_x4, _y4, _x5, _y4];
19665 } else {
19666 var _x6 = posPts.x1 + d + (dIncludesNodeBody ? srcW / 2 * sgnL : 0);
19667 var _y5 = posPts.y1, _y6 = posPts.y2;
19668 rs.segpts = [_x6, _y5, _x6, _y6];
19669 }
19670 }
19671 };
19672 BRp$c.tryToCorrectInvalidPoints = function(edge, pairInfo) {
19673 var rs = edge._private.rscratch;
19674 if (rs.edgeType === "bezier") {
19675 var srcPos = pairInfo.srcPos, tgtPos = pairInfo.tgtPos, srcW = pairInfo.srcW, srcH = pairInfo.srcH, tgtW = pairInfo.tgtW, tgtH = pairInfo.tgtH, srcShape = pairInfo.srcShape, tgtShape = pairInfo.tgtShape;
19676 var badStart = !number$1(rs.startX) || !number$1(rs.startY);
19677 var badAStart = !number$1(rs.arrowStartX) || !number$1(rs.arrowStartY);
19678 var badEnd = !number$1(rs.endX) || !number$1(rs.endY);
19679 var badAEnd = !number$1(rs.arrowEndX) || !number$1(rs.arrowEndY);
19680 var minCpADistFactor = 3;
19681 var arrowW = this.getArrowWidth(edge.pstyle("width").pfValue, edge.pstyle("arrow-scale").value) * this.arrowShapeWidth;
19682 var minCpADist = minCpADistFactor * arrowW;
19683 var startACpDist = dist({
19684 x: rs.ctrlpts[0],
19685 y: rs.ctrlpts[1]
19686 }, {
19687 x: rs.startX,
19688 y: rs.startY
19689 });
19690 var closeStartACp = startACpDist < minCpADist;
19691 var endACpDist = dist({
19692 x: rs.ctrlpts[0],
19693 y: rs.ctrlpts[1]
19694 }, {
19695 x: rs.endX,
19696 y: rs.endY
19697 });
19698 var closeEndACp = endACpDist < minCpADist;
19699 var overlapping = false;
19700 if (badStart || badAStart || closeStartACp) {
19701 overlapping = true;
19702 var cpD = {
19703 // delta
19704 x: rs.ctrlpts[0] - srcPos.x,
19705 y: rs.ctrlpts[1] - srcPos.y
19706 };
19707 var cpL = Math.sqrt(cpD.x * cpD.x + cpD.y * cpD.y);
19708 var cpM = {
19709 // normalised delta
19710 x: cpD.x / cpL,
19711 y: cpD.y / cpL
19712 };
19713 var radius = Math.max(srcW, srcH);
19714 var cpProj = {
19715 // *2 radius guarantees outside shape
19716 x: rs.ctrlpts[0] + cpM.x * 2 * radius,
19717 y: rs.ctrlpts[1] + cpM.y * 2 * radius
19718 };
19719 var srcCtrlPtIntn = srcShape.intersectLine(srcPos.x, srcPos.y, srcW, srcH, cpProj.x, cpProj.y, 0);
19720 if (closeStartACp) {
19721 rs.ctrlpts[0] = rs.ctrlpts[0] + cpM.x * (minCpADist - startACpDist);
19722 rs.ctrlpts[1] = rs.ctrlpts[1] + cpM.y * (minCpADist - startACpDist);
19723 } else {
19724 rs.ctrlpts[0] = srcCtrlPtIntn[0] + cpM.x * minCpADist;
19725 rs.ctrlpts[1] = srcCtrlPtIntn[1] + cpM.y * minCpADist;
19726 }
19727 }
19728 if (badEnd || badAEnd || closeEndACp) {
19729 overlapping = true;
19730 var _cpD = {
19731 // delta
19732 x: rs.ctrlpts[0] - tgtPos.x,
19733 y: rs.ctrlpts[1] - tgtPos.y
19734 };
19735 var _cpL = Math.sqrt(_cpD.x * _cpD.x + _cpD.y * _cpD.y);
19736 var _cpM = {
19737 // normalised delta
19738 x: _cpD.x / _cpL,
19739 y: _cpD.y / _cpL
19740 };
19741 var _radius = Math.max(srcW, srcH);
19742 var _cpProj = {
19743 // *2 radius guarantees outside shape
19744 x: rs.ctrlpts[0] + _cpM.x * 2 * _radius,
19745 y: rs.ctrlpts[1] + _cpM.y * 2 * _radius
19746 };
19747 var tgtCtrlPtIntn = tgtShape.intersectLine(tgtPos.x, tgtPos.y, tgtW, tgtH, _cpProj.x, _cpProj.y, 0);
19748 if (closeEndACp) {
19749 rs.ctrlpts[0] = rs.ctrlpts[0] + _cpM.x * (minCpADist - endACpDist);
19750 rs.ctrlpts[1] = rs.ctrlpts[1] + _cpM.y * (minCpADist - endACpDist);
19751 } else {
19752 rs.ctrlpts[0] = tgtCtrlPtIntn[0] + _cpM.x * minCpADist;
19753 rs.ctrlpts[1] = tgtCtrlPtIntn[1] + _cpM.y * minCpADist;
19754 }
19755 }
19756 if (overlapping) {
19757 this.findEndpoints(edge);
19758 }
19759 }
19760 };
19761 BRp$c.storeAllpts = function(edge) {
19762 var rs = edge._private.rscratch;
19763 if (rs.edgeType === "multibezier" || rs.edgeType === "bezier" || rs.edgeType === "self" || rs.edgeType === "compound") {
19764 rs.allpts = [];
19765 rs.allpts.push(rs.startX, rs.startY);
19766 for (var b = 0; b + 1 < rs.ctrlpts.length; b += 2) {
19767 rs.allpts.push(rs.ctrlpts[b], rs.ctrlpts[b + 1]);
19768 if (b + 3 < rs.ctrlpts.length) {
19769 rs.allpts.push((rs.ctrlpts[b] + rs.ctrlpts[b + 2]) / 2, (rs.ctrlpts[b + 1] + rs.ctrlpts[b + 3]) / 2);
19770 }
19771 }
19772 rs.allpts.push(rs.endX, rs.endY);
19773 var m, mt;
19774 if (rs.ctrlpts.length / 2 % 2 === 0) {
19775 m = rs.allpts.length / 2 - 1;
19776 rs.midX = rs.allpts[m];
19777 rs.midY = rs.allpts[m + 1];
19778 } else {
19779 m = rs.allpts.length / 2 - 3;
19780 mt = 0.5;
19781 rs.midX = qbezierAt(rs.allpts[m], rs.allpts[m + 2], rs.allpts[m + 4], mt);
19782 rs.midY = qbezierAt(rs.allpts[m + 1], rs.allpts[m + 3], rs.allpts[m + 5], mt);
19783 }
19784 } else if (rs.edgeType === "straight") {
19785 rs.allpts = [rs.startX, rs.startY, rs.endX, rs.endY];
19786 rs.midX = (rs.startX + rs.endX + rs.arrowStartX + rs.arrowEndX) / 4;
19787 rs.midY = (rs.startY + rs.endY + rs.arrowStartY + rs.arrowEndY) / 4;
19788 } else if (rs.edgeType === "segments") {
19789 rs.allpts = [];
19790 rs.allpts.push(rs.startX, rs.startY);
19791 rs.allpts.push.apply(rs.allpts, rs.segpts);
19792 rs.allpts.push(rs.endX, rs.endY);
19793 if (rs.segpts.length % 4 === 0) {
19794 var i2 = rs.segpts.length / 2;
19795 var i1 = i2 - 2;
19796 rs.midX = (rs.segpts[i1] + rs.segpts[i2]) / 2;
19797 rs.midY = (rs.segpts[i1 + 1] + rs.segpts[i2 + 1]) / 2;
19798 } else {
19799 var _i = rs.segpts.length / 2 - 1;
19800 rs.midX = rs.segpts[_i];
19801 rs.midY = rs.segpts[_i + 1];
19802 }
19803 }
19804 };
19805 BRp$c.checkForInvalidEdgeWarning = function(edge) {
19806 var rs = edge[0]._private.rscratch;
19807 if (rs.nodesOverlap || number$1(rs.startX) && number$1(rs.startY) && number$1(rs.endX) && number$1(rs.endY)) {
19808 rs.loggedErr = false;
19809 } else {
19810 if (!rs.loggedErr) {
19811 rs.loggedErr = true;
19812 warn("Edge `" + edge.id() + "` has invalid endpoints and so it is impossible to draw. Adjust your edge style (e.g. control points) accordingly or use an alternative edge type. This is expected behaviour when the source node and the target node overlap.");
19813 }
19814 }
19815 };
19816 BRp$c.findEdgeControlPoints = function(edges) {
19817 var _this = this;
19818 if (!edges || edges.length === 0) {
19819 return;
19820 }
19821 var r = this;
19822 var cy = r.cy;
19823 var hasCompounds = cy.hasCompoundNodes();
19824 var hashTable = {
19825 map: new Map$2(),
19826 get: function get2(pairId2) {
19827 var map2 = this.map.get(pairId2[0]);
19828 if (map2 != null) {
19829 return map2.get(pairId2[1]);
19830 } else {
19831 return null;
19832 }
19833 },
19834 set: function set2(pairId2, val) {
19835 var map2 = this.map.get(pairId2[0]);
19836 if (map2 == null) {
19837 map2 = new Map$2();
19838 this.map.set(pairId2[0], map2);
19839 }
19840 map2.set(pairId2[1], val);
19841 }
19842 };
19843 var pairIds = [];
19844 var haystackEdges = [];
19845 for (var i2 = 0; i2 < edges.length; i2++) {
19846 var edge = edges[i2];
19847 var _p = edge._private;
19848 var curveStyle = edge.pstyle("curve-style").value;
19849 if (edge.removed() || !edge.takesUpSpace()) {
19850 continue;
19851 }
19852 if (curveStyle === "haystack") {
19853 haystackEdges.push(edge);
19854 continue;
19855 }
19856 var edgeIsUnbundled = curveStyle === "unbundled-bezier" || curveStyle === "segments" || curveStyle === "straight" || curveStyle === "straight-triangle" || curveStyle === "taxi";
19857 var edgeIsBezier = curveStyle === "unbundled-bezier" || curveStyle === "bezier";
19858 var src = _p.source;
19859 var tgt = _p.target;
19860 var srcIndex = src.poolIndex();
19861 var tgtIndex = tgt.poolIndex();
19862 var pairId = [srcIndex, tgtIndex].sort();
19863 var tableEntry = hashTable.get(pairId);
19864 if (tableEntry == null) {
19865 tableEntry = {
19866 eles: []
19867 };
19868 hashTable.set(pairId, tableEntry);
19869 pairIds.push(pairId);
19870 }
19871 tableEntry.eles.push(edge);
19872 if (edgeIsUnbundled) {
19873 tableEntry.hasUnbundled = true;
19874 }
19875 if (edgeIsBezier) {
19876 tableEntry.hasBezier = true;
19877 }
19878 }
19879 var _loop = function _loop2(p3) {
19880 var pairId2 = pairIds[p3];
19881 var pairInfo = hashTable.get(pairId2);
19882 var swappedpairInfo = void 0;
19883 if (!pairInfo.hasUnbundled) {
19884 var pllEdges = pairInfo.eles[0].parallelEdges().filter(function(e) {
19885 return e.isBundledBezier();
19886 });
19887 clearArray(pairInfo.eles);
19888 pllEdges.forEach(function(edge2) {
19889 return pairInfo.eles.push(edge2);
19890 });
19891 pairInfo.eles.sort(function(edge1, edge2) {
19892 return edge1.poolIndex() - edge2.poolIndex();
19893 });
19894 }
19895 var firstEdge = pairInfo.eles[0];
19896 var src2 = firstEdge.source();
19897 var tgt2 = firstEdge.target();
19898 if (src2.poolIndex() > tgt2.poolIndex()) {
19899 var temp = src2;
19900 src2 = tgt2;
19901 tgt2 = temp;
19902 }
19903 var srcPos = pairInfo.srcPos = src2.position();
19904 var tgtPos = pairInfo.tgtPos = tgt2.position();
19905 var srcW = pairInfo.srcW = src2.outerWidth();
19906 var srcH = pairInfo.srcH = src2.outerHeight();
19907 var tgtW = pairInfo.tgtW = tgt2.outerWidth();
19908 var tgtH = pairInfo.tgtH = tgt2.outerHeight();
19909 var srcShape = pairInfo.srcShape = r.nodeShapes[_this.getNodeShape(src2)];
19910 var tgtShape = pairInfo.tgtShape = r.nodeShapes[_this.getNodeShape(tgt2)];
19911 pairInfo.dirCounts = {
19912 "north": 0,
19913 "west": 0,
19914 "south": 0,
19915 "east": 0,
19916 "northwest": 0,
19917 "southwest": 0,
19918 "northeast": 0,
19919 "southeast": 0
19920 };
19921 for (var _i2 = 0; _i2 < pairInfo.eles.length; _i2++) {
19922 var _edge = pairInfo.eles[_i2];
19923 var rs = _edge[0]._private.rscratch;
19924 var _curveStyle = _edge.pstyle("curve-style").value;
19925 var _edgeIsUnbundled = _curveStyle === "unbundled-bezier" || _curveStyle === "segments" || _curveStyle === "taxi";
19926 var edgeIsSwapped = !src2.same(_edge.source());
19927 if (!pairInfo.calculatedIntersection && src2 !== tgt2 && (pairInfo.hasBezier || pairInfo.hasUnbundled)) {
19928 pairInfo.calculatedIntersection = true;
19929 var srcOutside = srcShape.intersectLine(srcPos.x, srcPos.y, srcW, srcH, tgtPos.x, tgtPos.y, 0);
19930 var srcIntn = pairInfo.srcIntn = srcOutside;
19931 var tgtOutside = tgtShape.intersectLine(tgtPos.x, tgtPos.y, tgtW, tgtH, srcPos.x, srcPos.y, 0);
19932 var tgtIntn = pairInfo.tgtIntn = tgtOutside;
19933 var intersectionPts = pairInfo.intersectionPts = {
19934 x1: srcOutside[0],
19935 x2: tgtOutside[0],
19936 y1: srcOutside[1],
19937 y2: tgtOutside[1]
19938 };
19939 var posPts = pairInfo.posPts = {
19940 x1: srcPos.x,
19941 x2: tgtPos.x,
19942 y1: srcPos.y,
19943 y2: tgtPos.y
19944 };
19945 var dy = tgtOutside[1] - srcOutside[1];
19946 var dx = tgtOutside[0] - srcOutside[0];
19947 var l = Math.sqrt(dx * dx + dy * dy);
19948 var vector = pairInfo.vector = {
19949 x: dx,
19950 y: dy
19951 };
19952 var vectorNorm = pairInfo.vectorNorm = {
19953 x: vector.x / l,
19954 y: vector.y / l
19955 };
19956 var vectorNormInverse = {
19957 x: -vectorNorm.y,
19958 y: vectorNorm.x
19959 };
19960 pairInfo.nodesOverlap = !number$1(l) || tgtShape.checkPoint(srcOutside[0], srcOutside[1], 0, tgtW, tgtH, tgtPos.x, tgtPos.y) || srcShape.checkPoint(tgtOutside[0], tgtOutside[1], 0, srcW, srcH, srcPos.x, srcPos.y);
19961 pairInfo.vectorNormInverse = vectorNormInverse;
19962 swappedpairInfo = {
19963 nodesOverlap: pairInfo.nodesOverlap,
19964 dirCounts: pairInfo.dirCounts,
19965 calculatedIntersection: true,
19966 hasBezier: pairInfo.hasBezier,
19967 hasUnbundled: pairInfo.hasUnbundled,
19968 eles: pairInfo.eles,
19969 srcPos: tgtPos,
19970 tgtPos: srcPos,
19971 srcW: tgtW,
19972 srcH: tgtH,
19973 tgtW: srcW,
19974 tgtH: srcH,
19975 srcIntn: tgtIntn,
19976 tgtIntn: srcIntn,
19977 srcShape: tgtShape,
19978 tgtShape: srcShape,
19979 posPts: {
19980 x1: posPts.x2,
19981 y1: posPts.y2,
19982 x2: posPts.x1,
19983 y2: posPts.y1
19984 },
19985 intersectionPts: {
19986 x1: intersectionPts.x2,
19987 y1: intersectionPts.y2,
19988 x2: intersectionPts.x1,
19989 y2: intersectionPts.y1
19990 },
19991 vector: {
19992 x: -vector.x,
19993 y: -vector.y
19994 },
19995 vectorNorm: {
19996 x: -vectorNorm.x,
19997 y: -vectorNorm.y
19998 },
19999 vectorNormInverse: {
20000 x: -vectorNormInverse.x,
20001 y: -vectorNormInverse.y
20002 }
20003 };
20004 }
20005 var passedPairInfo = edgeIsSwapped ? swappedpairInfo : pairInfo;
20006 rs.nodesOverlap = passedPairInfo.nodesOverlap;
20007 rs.srcIntn = passedPairInfo.srcIntn;
20008 rs.tgtIntn = passedPairInfo.tgtIntn;
20009 if (hasCompounds && (src2.isParent() || src2.isChild() || tgt2.isParent() || tgt2.isChild()) && (src2.parents().anySame(tgt2) || tgt2.parents().anySame(src2) || src2.same(tgt2) && src2.isParent())) {
20010 _this.findCompoundLoopPoints(_edge, passedPairInfo, _i2, _edgeIsUnbundled);
20011 } else if (src2 === tgt2) {
20012 _this.findLoopPoints(_edge, passedPairInfo, _i2, _edgeIsUnbundled);
20013 } else if (_curveStyle === "segments") {
20014 _this.findSegmentsPoints(_edge, passedPairInfo);
20015 } else if (_curveStyle === "taxi") {
20016 _this.findTaxiPoints(_edge, passedPairInfo);
20017 } else if (_curveStyle === "straight" || !_edgeIsUnbundled && pairInfo.eles.length % 2 === 1 && _i2 === Math.floor(pairInfo.eles.length / 2)) {
20018 _this.findStraightEdgePoints(_edge);
20019 } else {
20020 _this.findBezierPoints(_edge, passedPairInfo, _i2, _edgeIsUnbundled, edgeIsSwapped);
20021 }
20022 _this.findEndpoints(_edge);
20023 _this.tryToCorrectInvalidPoints(_edge, passedPairInfo);
20024 _this.checkForInvalidEdgeWarning(_edge);
20025 _this.storeAllpts(_edge);
20026 _this.storeEdgeProjections(_edge);
20027 _this.calculateArrowAngles(_edge);
20028 _this.recalculateEdgeLabelProjections(_edge);
20029 _this.calculateLabelAngles(_edge);
20030 }
20031 };
20032 for (var p2 = 0; p2 < pairIds.length; p2++) {
20033 _loop(p2);
20034 }
20035 this.findHaystackPoints(haystackEdges);
20036 };
20037 function getPts(pts2) {
20038 var retPts = [];
20039 if (pts2 == null) {
20040 return;
20041 }
20042 for (var i2 = 0; i2 < pts2.length; i2 += 2) {
20043 var x = pts2[i2];
20044 var y = pts2[i2 + 1];
20045 retPts.push({
20046 x,
20047 y
20048 });
20049 }
20050 return retPts;
20051 }
20052 BRp$c.getSegmentPoints = function(edge) {
20053 var rs = edge[0]._private.rscratch;
20054 var type = rs.edgeType;
20055 if (type === "segments") {
20056 this.recalculateRenderedStyle(edge);
20057 return getPts(rs.segpts);
20058 }
20059 };
20060 BRp$c.getControlPoints = function(edge) {
20061 var rs = edge[0]._private.rscratch;
20062 var type = rs.edgeType;
20063 if (type === "bezier" || type === "multibezier" || type === "self" || type === "compound") {
20064 this.recalculateRenderedStyle(edge);
20065 return getPts(rs.ctrlpts);
20066 }
20067 };
20068 BRp$c.getEdgeMidpoint = function(edge) {
20069 var rs = edge[0]._private.rscratch;
20070 this.recalculateRenderedStyle(edge);
20071 return {
20072 x: rs.midX,
20073 y: rs.midY
20074 };
20075 };
20076 var BRp$b = {};
20077 BRp$b.manualEndptToPx = function(node, prop) {
20078 var r = this;
20079 var npos = node.position();
20080 var w = node.outerWidth();
20081 var h = node.outerHeight();
20082 if (prop.value.length === 2) {
20083 var p2 = [prop.pfValue[0], prop.pfValue[1]];
20084 if (prop.units[0] === "%") {
20085 p2[0] = p2[0] * w;
20086 }
20087 if (prop.units[1] === "%") {
20088 p2[1] = p2[1] * h;
20089 }
20090 p2[0] += npos.x;
20091 p2[1] += npos.y;
20092 return p2;
20093 } else {
20094 var angle = prop.pfValue[0];
20095 angle = -Math.PI / 2 + angle;
20096 var l = 2 * Math.max(w, h);
20097 var _p = [npos.x + Math.cos(angle) * l, npos.y + Math.sin(angle) * l];
20098 return r.nodeShapes[this.getNodeShape(node)].intersectLine(npos.x, npos.y, w, h, _p[0], _p[1], 0);
20099 }
20100 };
20101 BRp$b.findEndpoints = function(edge) {
20102 var r = this;
20103 var intersect;
20104 var source = edge.source()[0];
20105 var target = edge.target()[0];
20106 var srcPos = source.position();
20107 var tgtPos = target.position();
20108 var tgtArShape = edge.pstyle("target-arrow-shape").value;
20109 var srcArShape = edge.pstyle("source-arrow-shape").value;
20110 var tgtDist = edge.pstyle("target-distance-from-node").pfValue;
20111 var srcDist = edge.pstyle("source-distance-from-node").pfValue;
20112 var curveStyle = edge.pstyle("curve-style").value;
20113 var rs = edge._private.rscratch;
20114 var et = rs.edgeType;
20115 var taxi = curveStyle === "taxi";
20116 var self2 = et === "self" || et === "compound";
20117 var bezier = et === "bezier" || et === "multibezier" || self2;
20118 var multi = et !== "bezier";
20119 var lines = et === "straight" || et === "segments";
20120 var segments = et === "segments";
20121 var hasEndpts = bezier || multi || lines;
20122 var overrideEndpts = self2 || taxi;
20123 var srcManEndpt = edge.pstyle("source-endpoint");
20124 var srcManEndptVal = overrideEndpts ? "outside-to-node" : srcManEndpt.value;
20125 var tgtManEndpt = edge.pstyle("target-endpoint");
20126 var tgtManEndptVal = overrideEndpts ? "outside-to-node" : tgtManEndpt.value;
20127 rs.srcManEndpt = srcManEndpt;
20128 rs.tgtManEndpt = tgtManEndpt;
20129 var p1;
20130 var p2;
20131 var p1_i;
20132 var p2_i;
20133 if (bezier) {
20134 var cpStart = [rs.ctrlpts[0], rs.ctrlpts[1]];
20135 var cpEnd = multi ? [rs.ctrlpts[rs.ctrlpts.length - 2], rs.ctrlpts[rs.ctrlpts.length - 1]] : cpStart;
20136 p1 = cpEnd;
20137 p2 = cpStart;
20138 } else if (lines) {
20139 var srcArrowFromPt = !segments ? [tgtPos.x, tgtPos.y] : rs.segpts.slice(0, 2);
20140 var tgtArrowFromPt = !segments ? [srcPos.x, srcPos.y] : rs.segpts.slice(rs.segpts.length - 2);
20141 p1 = tgtArrowFromPt;
20142 p2 = srcArrowFromPt;
20143 }
20144 if (tgtManEndptVal === "inside-to-node") {
20145 intersect = [tgtPos.x, tgtPos.y];
20146 } else if (tgtManEndpt.units) {
20147 intersect = this.manualEndptToPx(target, tgtManEndpt);
20148 } else if (tgtManEndptVal === "outside-to-line") {
20149 intersect = rs.tgtIntn;
20150 } else {
20151 if (tgtManEndptVal === "outside-to-node" || tgtManEndptVal === "outside-to-node-or-label") {
20152 p1_i = p1;
20153 } else if (tgtManEndptVal === "outside-to-line" || tgtManEndptVal === "outside-to-line-or-label") {
20154 p1_i = [srcPos.x, srcPos.y];
20155 }
20156 intersect = r.nodeShapes[this.getNodeShape(target)].intersectLine(tgtPos.x, tgtPos.y, target.outerWidth(), target.outerHeight(), p1_i[0], p1_i[1], 0);
20157 if (tgtManEndptVal === "outside-to-node-or-label" || tgtManEndptVal === "outside-to-line-or-label") {
20158 var trs = target._private.rscratch;
20159 var lw = trs.labelWidth;
20160 var lh = trs.labelHeight;
20161 var lx = trs.labelX;
20162 var ly = trs.labelY;
20163 var lw2 = lw / 2;
20164 var lh2 = lh / 2;
20165 var va = target.pstyle("text-valign").value;
20166 if (va === "top") {
20167 ly -= lh2;
20168 } else if (va === "bottom") {
20169 ly += lh2;
20170 }
20171 var ha = target.pstyle("text-halign").value;
20172 if (ha === "left") {
20173 lx -= lw2;
20174 } else if (ha === "right") {
20175 lx += lw2;
20176 }
20177 var labelIntersect = polygonIntersectLine(p1_i[0], p1_i[1], [lx - lw2, ly - lh2, lx + lw2, ly - lh2, lx + lw2, ly + lh2, lx - lw2, ly + lh2], tgtPos.x, tgtPos.y);
20178 if (labelIntersect.length > 0) {
20179 var refPt = srcPos;
20180 var intSqdist = sqdist(refPt, array2point(intersect));
20181 var labIntSqdist = sqdist(refPt, array2point(labelIntersect));
20182 var minSqDist = intSqdist;
20183 if (labIntSqdist < intSqdist) {
20184 intersect = labelIntersect;
20185 minSqDist = labIntSqdist;
20186 }
20187 if (labelIntersect.length > 2) {
20188 var labInt2SqDist = sqdist(refPt, {
20189 x: labelIntersect[2],
20190 y: labelIntersect[3]
20191 });
20192 if (labInt2SqDist < minSqDist) {
20193 intersect = [labelIntersect[2], labelIntersect[3]];
20194 }
20195 }
20196 }
20197 }
20198 }
20199 var arrowEnd = shortenIntersection(intersect, p1, r.arrowShapes[tgtArShape].spacing(edge) + tgtDist);
20200 var edgeEnd = shortenIntersection(intersect, p1, r.arrowShapes[tgtArShape].gap(edge) + tgtDist);
20201 rs.endX = edgeEnd[0];
20202 rs.endY = edgeEnd[1];
20203 rs.arrowEndX = arrowEnd[0];
20204 rs.arrowEndY = arrowEnd[1];
20205 if (srcManEndptVal === "inside-to-node") {
20206 intersect = [srcPos.x, srcPos.y];
20207 } else if (srcManEndpt.units) {
20208 intersect = this.manualEndptToPx(source, srcManEndpt);
20209 } else if (srcManEndptVal === "outside-to-line") {
20210 intersect = rs.srcIntn;
20211 } else {
20212 if (srcManEndptVal === "outside-to-node" || srcManEndptVal === "outside-to-node-or-label") {
20213 p2_i = p2;
20214 } else if (srcManEndptVal === "outside-to-line" || srcManEndptVal === "outside-to-line-or-label") {
20215 p2_i = [tgtPos.x, tgtPos.y];
20216 }
20217 intersect = r.nodeShapes[this.getNodeShape(source)].intersectLine(srcPos.x, srcPos.y, source.outerWidth(), source.outerHeight(), p2_i[0], p2_i[1], 0);
20218 if (srcManEndptVal === "outside-to-node-or-label" || srcManEndptVal === "outside-to-line-or-label") {
20219 var srs = source._private.rscratch;
20220 var _lw = srs.labelWidth;
20221 var _lh = srs.labelHeight;
20222 var _lx = srs.labelX;
20223 var _ly = srs.labelY;
20224 var _lw2 = _lw / 2;
20225 var _lh2 = _lh / 2;
20226 var _va = source.pstyle("text-valign").value;
20227 if (_va === "top") {
20228 _ly -= _lh2;
20229 } else if (_va === "bottom") {
20230 _ly += _lh2;
20231 }
20232 var _ha = source.pstyle("text-halign").value;
20233 if (_ha === "left") {
20234 _lx -= _lw2;
20235 } else if (_ha === "right") {
20236 _lx += _lw2;
20237 }
20238 var _labelIntersect = polygonIntersectLine(p2_i[0], p2_i[1], [_lx - _lw2, _ly - _lh2, _lx + _lw2, _ly - _lh2, _lx + _lw2, _ly + _lh2, _lx - _lw2, _ly + _lh2], srcPos.x, srcPos.y);
20239 if (_labelIntersect.length > 0) {
20240 var _refPt = tgtPos;
20241 var _intSqdist = sqdist(_refPt, array2point(intersect));
20242 var _labIntSqdist = sqdist(_refPt, array2point(_labelIntersect));
20243 var _minSqDist = _intSqdist;
20244 if (_labIntSqdist < _intSqdist) {
20245 intersect = [_labelIntersect[0], _labelIntersect[1]];
20246 _minSqDist = _labIntSqdist;
20247 }
20248 if (_labelIntersect.length > 2) {
20249 var _labInt2SqDist = sqdist(_refPt, {
20250 x: _labelIntersect[2],
20251 y: _labelIntersect[3]
20252 });
20253 if (_labInt2SqDist < _minSqDist) {
20254 intersect = [_labelIntersect[2], _labelIntersect[3]];
20255 }
20256 }
20257 }
20258 }
20259 }
20260 var arrowStart = shortenIntersection(intersect, p2, r.arrowShapes[srcArShape].spacing(edge) + srcDist);
20261 var edgeStart = shortenIntersection(intersect, p2, r.arrowShapes[srcArShape].gap(edge) + srcDist);
20262 rs.startX = edgeStart[0];
20263 rs.startY = edgeStart[1];
20264 rs.arrowStartX = arrowStart[0];
20265 rs.arrowStartY = arrowStart[1];
20266 if (hasEndpts) {
20267 if (!number$1(rs.startX) || !number$1(rs.startY) || !number$1(rs.endX) || !number$1(rs.endY)) {
20268 rs.badLine = true;
20269 } else {
20270 rs.badLine = false;
20271 }
20272 }
20273 };
20274 BRp$b.getSourceEndpoint = function(edge) {
20275 var rs = edge[0]._private.rscratch;
20276 this.recalculateRenderedStyle(edge);
20277 switch (rs.edgeType) {
20278 case "haystack":
20279 return {
20280 x: rs.haystackPts[0],
20281 y: rs.haystackPts[1]
20282 };
20283 default:
20284 return {
20285 x: rs.arrowStartX,
20286 y: rs.arrowStartY
20287 };
20288 }
20289 };
20290 BRp$b.getTargetEndpoint = function(edge) {
20291 var rs = edge[0]._private.rscratch;
20292 this.recalculateRenderedStyle(edge);
20293 switch (rs.edgeType) {
20294 case "haystack":
20295 return {
20296 x: rs.haystackPts[2],
20297 y: rs.haystackPts[3]
20298 };
20299 default:
20300 return {
20301 x: rs.arrowEndX,
20302 y: rs.arrowEndY
20303 };
20304 }
20305 };
20306 var BRp$a = {};
20307 function pushBezierPts(r, edge, pts2) {
20308 var qbezierAt$1 = function qbezierAt$12(p1, p22, p3, t) {
20309 return qbezierAt(p1, p22, p3, t);
20310 };
20311 var _p = edge._private;
20312 var bpts = _p.rstyle.bezierPts;
20313 for (var i2 = 0; i2 < r.bezierProjPcts.length; i2++) {
20314 var p2 = r.bezierProjPcts[i2];
20315 bpts.push({
20316 x: qbezierAt$1(pts2[0], pts2[2], pts2[4], p2),
20317 y: qbezierAt$1(pts2[1], pts2[3], pts2[5], p2)
20318 });
20319 }
20320 }
20321 BRp$a.storeEdgeProjections = function(edge) {
20322 var _p = edge._private;
20323 var rs = _p.rscratch;
20324 var et = rs.edgeType;
20325 _p.rstyle.bezierPts = null;
20326 _p.rstyle.linePts = null;
20327 _p.rstyle.haystackPts = null;
20328 if (et === "multibezier" || et === "bezier" || et === "self" || et === "compound") {
20329 _p.rstyle.bezierPts = [];
20330 for (var i2 = 0; i2 + 5 < rs.allpts.length; i2 += 4) {
20331 pushBezierPts(this, edge, rs.allpts.slice(i2, i2 + 6));
20332 }
20333 } else if (et === "segments") {
20334 var lpts = _p.rstyle.linePts = [];
20335 for (var i2 = 0; i2 + 1 < rs.allpts.length; i2 += 2) {
20336 lpts.push({
20337 x: rs.allpts[i2],
20338 y: rs.allpts[i2 + 1]
20339 });
20340 }
20341 } else if (et === "haystack") {
20342 var hpts = rs.haystackPts;
20343 _p.rstyle.haystackPts = [{
20344 x: hpts[0],
20345 y: hpts[1]
20346 }, {
20347 x: hpts[2],
20348 y: hpts[3]
20349 }];
20350 }
20351 _p.rstyle.arrowWidth = this.getArrowWidth(edge.pstyle("width").pfValue, edge.pstyle("arrow-scale").value) * this.arrowShapeWidth;
20352 };
20353 BRp$a.recalculateEdgeProjections = function(edges) {
20354 this.findEdgeControlPoints(edges);
20355 };
20356 var BRp$9 = {};
20357 BRp$9.recalculateNodeLabelProjection = function(node) {
20358 var content = node.pstyle("label").strValue;
20359 if (emptyString(content)) {
20360 return;
20361 }
20362 var textX, textY;
20363 var _p = node._private;
20364 var nodeWidth = node.width();
20365 var nodeHeight = node.height();
20366 var padding = node.padding();
20367 var nodePos = node.position();
20368 var textHalign = node.pstyle("text-halign").strValue;
20369 var textValign = node.pstyle("text-valign").strValue;
20370 var rs = _p.rscratch;
20371 var rstyle = _p.rstyle;
20372 switch (textHalign) {
20373 case "left":
20374 textX = nodePos.x - nodeWidth / 2 - padding;
20375 break;
20376 case "right":
20377 textX = nodePos.x + nodeWidth / 2 + padding;
20378 break;
20379 default:
20380 textX = nodePos.x;
20381 }
20382 switch (textValign) {
20383 case "top":
20384 textY = nodePos.y - nodeHeight / 2 - padding;
20385 break;
20386 case "bottom":
20387 textY = nodePos.y + nodeHeight / 2 + padding;
20388 break;
20389 default:
20390 textY = nodePos.y;
20391 }
20392 rs.labelX = textX;
20393 rs.labelY = textY;
20394 rstyle.labelX = textX;
20395 rstyle.labelY = textY;
20396 this.calculateLabelAngles(node);
20397 this.applyLabelDimensions(node);
20398 };
20399 var lineAngleFromDelta = function lineAngleFromDelta2(dx, dy) {
20400 var angle = Math.atan(dy / dx);
20401 if (dx === 0 && angle < 0) {
20402 angle = angle * -1;
20403 }
20404 return angle;
20405 };
20406 var lineAngle = function lineAngle2(p0, p1) {
20407 var dx = p1.x - p0.x;
20408 var dy = p1.y - p0.y;
20409 return lineAngleFromDelta(dx, dy);
20410 };
20411 var bezierAngle = function bezierAngle2(p0, p1, p2, t) {
20412 var t0 = bound(0, t - 1e-3, 1);
20413 var t1 = bound(0, t + 1e-3, 1);
20414 var lp0 = qbezierPtAt(p0, p1, p2, t0);
20415 var lp1 = qbezierPtAt(p0, p1, p2, t1);
20416 return lineAngle(lp0, lp1);
20417 };
20418 BRp$9.recalculateEdgeLabelProjections = function(edge) {
20419 var p2;
20420 var _p = edge._private;
20421 var rs = _p.rscratch;
20422 var r = this;
20423 var content = {
20424 mid: edge.pstyle("label").strValue,
20425 source: edge.pstyle("source-label").strValue,
20426 target: edge.pstyle("target-label").strValue
20427 };
20428 if (content.mid || content.source || content.target)
20429 ;
20430 else {
20431 return;
20432 }
20433 p2 = {
20434 x: rs.midX,
20435 y: rs.midY
20436 };
20437 var setRs = function setRs2(propName, prefix, value) {
20438 setPrefixedProperty(_p.rscratch, propName, prefix, value);
20439 setPrefixedProperty(_p.rstyle, propName, prefix, value);
20440 };
20441 setRs("labelX", null, p2.x);
20442 setRs("labelY", null, p2.y);
20443 var midAngle = lineAngleFromDelta(rs.midDispX, rs.midDispY);
20444 setRs("labelAutoAngle", null, midAngle);
20445 var createControlPointInfo = function createControlPointInfo2() {
20446 if (createControlPointInfo2.cache) {
20447 return createControlPointInfo2.cache;
20448 }
20449 var ctrlpts = [];
20450 for (var i2 = 0; i2 + 5 < rs.allpts.length; i2 += 4) {
20451 var p0 = {
20452 x: rs.allpts[i2],
20453 y: rs.allpts[i2 + 1]
20454 };
20455 var p1 = {
20456 x: rs.allpts[i2 + 2],
20457 y: rs.allpts[i2 + 3]
20458 };
20459 var p22 = {
20460 x: rs.allpts[i2 + 4],
20461 y: rs.allpts[i2 + 5]
20462 };
20463 ctrlpts.push({
20464 p0,
20465 p1,
20466 p2: p22,
20467 startDist: 0,
20468 length: 0,
20469 segments: []
20470 });
20471 }
20472 var bpts = _p.rstyle.bezierPts;
20473 var nProjs = r.bezierProjPcts.length;
20474 function addSegment(cp2, p02, p12, t0, t1) {
20475 var length = dist(p02, p12);
20476 var prevSegment = cp2.segments[cp2.segments.length - 1];
20477 var segment = {
20478 p0: p02,
20479 p1: p12,
20480 t0,
20481 t1,
20482 startDist: prevSegment ? prevSegment.startDist + prevSegment.length : 0,
20483 length
20484 };
20485 cp2.segments.push(segment);
20486 cp2.length += length;
20487 }
20488 for (var _i = 0; _i < ctrlpts.length; _i++) {
20489 var cp = ctrlpts[_i];
20490 var prevCp = ctrlpts[_i - 1];
20491 if (prevCp) {
20492 cp.startDist = prevCp.startDist + prevCp.length;
20493 }
20494 addSegment(cp, cp.p0, bpts[_i * nProjs], 0, r.bezierProjPcts[0]);
20495 for (var j = 0; j < nProjs - 1; j++) {
20496 addSegment(cp, bpts[_i * nProjs + j], bpts[_i * nProjs + j + 1], r.bezierProjPcts[j], r.bezierProjPcts[j + 1]);
20497 }
20498 addSegment(cp, bpts[_i * nProjs + nProjs - 1], cp.p2, r.bezierProjPcts[nProjs - 1], 1);
20499 }
20500 return createControlPointInfo2.cache = ctrlpts;
20501 };
20502 var calculateEndProjection = function calculateEndProjection2(prefix) {
20503 var angle;
20504 var isSrc = prefix === "source";
20505 if (!content[prefix]) {
20506 return;
20507 }
20508 var offset = edge.pstyle(prefix + "-text-offset").pfValue;
20509 switch (rs.edgeType) {
20510 case "self":
20511 case "compound":
20512 case "bezier":
20513 case "multibezier": {
20514 var cps = createControlPointInfo();
20515 var selected;
20516 var startDist = 0;
20517 var totalDist = 0;
20518 for (var i2 = 0; i2 < cps.length; i2++) {
20519 var _cp = cps[isSrc ? i2 : cps.length - 1 - i2];
20520 for (var j = 0; j < _cp.segments.length; j++) {
20521 var _seg = _cp.segments[isSrc ? j : _cp.segments.length - 1 - j];
20522 var lastSeg = i2 === cps.length - 1 && j === _cp.segments.length - 1;
20523 startDist = totalDist;
20524 totalDist += _seg.length;
20525 if (totalDist >= offset || lastSeg) {
20526 selected = {
20527 cp: _cp,
20528 segment: _seg
20529 };
20530 break;
20531 }
20532 }
20533 if (selected) {
20534 break;
20535 }
20536 }
20537 var cp = selected.cp;
20538 var seg = selected.segment;
20539 var tSegment = (offset - startDist) / seg.length;
20540 var segDt = seg.t1 - seg.t0;
20541 var t = isSrc ? seg.t0 + segDt * tSegment : seg.t1 - segDt * tSegment;
20542 t = bound(0, t, 1);
20543 p2 = qbezierPtAt(cp.p0, cp.p1, cp.p2, t);
20544 angle = bezierAngle(cp.p0, cp.p1, cp.p2, t);
20545 break;
20546 }
20547 case "straight":
20548 case "segments":
20549 case "haystack": {
20550 var d = 0, di, d0;
20551 var p0, p1;
20552 var l = rs.allpts.length;
20553 for (var _i2 = 0; _i2 + 3 < l; _i2 += 2) {
20554 if (isSrc) {
20555 p0 = {
20556 x: rs.allpts[_i2],
20557 y: rs.allpts[_i2 + 1]
20558 };
20559 p1 = {
20560 x: rs.allpts[_i2 + 2],
20561 y: rs.allpts[_i2 + 3]
20562 };
20563 } else {
20564 p0 = {
20565 x: rs.allpts[l - 2 - _i2],
20566 y: rs.allpts[l - 1 - _i2]
20567 };
20568 p1 = {
20569 x: rs.allpts[l - 4 - _i2],
20570 y: rs.allpts[l - 3 - _i2]
20571 };
20572 }
20573 di = dist(p0, p1);
20574 d0 = d;
20575 d += di;
20576 if (d >= offset) {
20577 break;
20578 }
20579 }
20580 var pD = offset - d0;
20581 var _t = pD / di;
20582 _t = bound(0, _t, 1);
20583 p2 = lineAt(p0, p1, _t);
20584 angle = lineAngle(p0, p1);
20585 break;
20586 }
20587 }
20588 setRs("labelX", prefix, p2.x);
20589 setRs("labelY", prefix, p2.y);
20590 setRs("labelAutoAngle", prefix, angle);
20591 };
20592 calculateEndProjection("source");
20593 calculateEndProjection("target");
20594 this.applyLabelDimensions(edge);
20595 };
20596 BRp$9.applyLabelDimensions = function(ele) {
20597 this.applyPrefixedLabelDimensions(ele);
20598 if (ele.isEdge()) {
20599 this.applyPrefixedLabelDimensions(ele, "source");
20600 this.applyPrefixedLabelDimensions(ele, "target");
20601 }
20602 };
20603 BRp$9.applyPrefixedLabelDimensions = function(ele, prefix) {
20604 var _p = ele._private;
20605 var text = this.getLabelText(ele, prefix);
20606 var labelDims = this.calculateLabelDimensions(ele, text);
20607 var lineHeight = ele.pstyle("line-height").pfValue;
20608 var textWrap = ele.pstyle("text-wrap").strValue;
20609 var lines = getPrefixedProperty(_p.rscratch, "labelWrapCachedLines", prefix) || [];
20610 var numLines = textWrap !== "wrap" ? 1 : Math.max(lines.length, 1);
20611 var normPerLineHeight = labelDims.height / numLines;
20612 var labelLineHeight = normPerLineHeight * lineHeight;
20613 var width = labelDims.width;
20614 var height = labelDims.height + (numLines - 1) * (lineHeight - 1) * normPerLineHeight;
20615 setPrefixedProperty(_p.rstyle, "labelWidth", prefix, width);
20616 setPrefixedProperty(_p.rscratch, "labelWidth", prefix, width);
20617 setPrefixedProperty(_p.rstyle, "labelHeight", prefix, height);
20618 setPrefixedProperty(_p.rscratch, "labelHeight", prefix, height);
20619 setPrefixedProperty(_p.rscratch, "labelLineHeight", prefix, labelLineHeight);
20620 };
20621 BRp$9.getLabelText = function(ele, prefix) {
20622 var _p = ele._private;
20623 var pfd = prefix ? prefix + "-" : "";
20624 var text = ele.pstyle(pfd + "label").strValue;
20625 var textTransform = ele.pstyle("text-transform").value;
20626 var rscratch = function rscratch2(propName, value) {
20627 if (value) {
20628 setPrefixedProperty(_p.rscratch, propName, prefix, value);
20629 return value;
20630 } else {
20631 return getPrefixedProperty(_p.rscratch, propName, prefix);
20632 }
20633 };
20634 if (!text) {
20635 return "";
20636 }
20637 if (textTransform == "none")
20638 ;
20639 else if (textTransform == "uppercase") {
20640 text = text.toUpperCase();
20641 } else if (textTransform == "lowercase") {
20642 text = text.toLowerCase();
20643 }
20644 var wrapStyle = ele.pstyle("text-wrap").value;
20645 if (wrapStyle === "wrap") {
20646 var labelKey = rscratch("labelKey");
20647 if (labelKey != null && rscratch("labelWrapKey") === labelKey) {
20648 return rscratch("labelWrapCachedText");
20649 }
20650 var zwsp = "​";
20651 var lines = text.split("\n");
20652 var maxW = ele.pstyle("text-max-width").pfValue;
20653 var overflow = ele.pstyle("text-overflow-wrap").value;
20654 var overflowAny = overflow === "anywhere";
20655 var wrappedLines = [];
20656 var wordsRegex = /[\s\u200b]+/;
20657 var wordSeparator = overflowAny ? "" : " ";
20658 for (var l = 0; l < lines.length; l++) {
20659 var line = lines[l];
20660 var lineDims = this.calculateLabelDimensions(ele, line);
20661 var lineW = lineDims.width;
20662 if (overflowAny) {
20663 var processedLine = line.split("").join(zwsp);
20664 line = processedLine;
20665 }
20666 if (lineW > maxW) {
20667 var words = line.split(wordsRegex);
20668 var subline = "";
20669 for (var w = 0; w < words.length; w++) {
20670 var word = words[w];
20671 var testLine = subline.length === 0 ? word : subline + wordSeparator + word;
20672 var testDims = this.calculateLabelDimensions(ele, testLine);
20673 var testW = testDims.width;
20674 if (testW <= maxW) {
20675 subline += word + wordSeparator;
20676 } else {
20677 if (subline) {
20678 wrappedLines.push(subline);
20679 }
20680 subline = word + wordSeparator;
20681 }
20682 }
20683 if (!subline.match(/^[\s\u200b]+$/)) {
20684 wrappedLines.push(subline);
20685 }
20686 } else {
20687 wrappedLines.push(line);
20688 }
20689 }
20690 rscratch("labelWrapCachedLines", wrappedLines);
20691 text = rscratch("labelWrapCachedText", wrappedLines.join("\n"));
20692 rscratch("labelWrapKey", labelKey);
20693 } else if (wrapStyle === "ellipsis") {
20694 var _maxW = ele.pstyle("text-max-width").pfValue;
20695 var ellipsized = "";
20696 var ellipsis = "…";
20697 var incLastCh = false;
20698 if (this.calculateLabelDimensions(ele, text).width < _maxW) {
20699 return text;
20700 }
20701 for (var i2 = 0; i2 < text.length; i2++) {
20702 var widthWithNextCh = this.calculateLabelDimensions(ele, ellipsized + text[i2] + ellipsis).width;
20703 if (widthWithNextCh > _maxW) {
20704 break;
20705 }
20706 ellipsized += text[i2];
20707 if (i2 === text.length - 1) {
20708 incLastCh = true;
20709 }
20710 }
20711 if (!incLastCh) {
20712 ellipsized += ellipsis;
20713 }
20714 return ellipsized;
20715 }
20716 return text;
20717 };
20718 BRp$9.getLabelJustification = function(ele) {
20719 var justification = ele.pstyle("text-justification").strValue;
20720 var textHalign = ele.pstyle("text-halign").strValue;
20721 if (justification === "auto") {
20722 if (ele.isNode()) {
20723 switch (textHalign) {
20724 case "left":
20725 return "right";
20726 case "right":
20727 return "left";
20728 default:
20729 return "center";
20730 }
20731 } else {
20732 return "center";
20733 }
20734 } else {
20735 return justification;
20736 }
20737 };
20738 BRp$9.calculateLabelDimensions = function(ele, text) {
20739 var r = this;
20740 var cacheKey = hashString(text, ele._private.labelDimsKey);
20741 var cache2 = r.labelDimCache || (r.labelDimCache = []);
20742 var existingVal = cache2[cacheKey];
20743 if (existingVal != null) {
20744 return existingVal;
20745 }
20746 var padding = 0;
20747 var fStyle = ele.pstyle("font-style").strValue;
20748 var size = ele.pstyle("font-size").pfValue;
20749 var family = ele.pstyle("font-family").strValue;
20750 var weight = ele.pstyle("font-weight").strValue;
20751 var canvas = this.labelCalcCanvas;
20752 var c2d = this.labelCalcCanvasContext;
20753 if (!canvas) {
20754 canvas = this.labelCalcCanvas = document.createElement("canvas");
20755 c2d = this.labelCalcCanvasContext = canvas.getContext("2d");
20756 var ds = canvas.style;
20757 ds.position = "absolute";
20758 ds.left = "-9999px";
20759 ds.top = "-9999px";
20760 ds.zIndex = "-1";
20761 ds.visibility = "hidden";
20762 ds.pointerEvents = "none";
20763 }
20764 c2d.font = "".concat(fStyle, " ").concat(weight, " ").concat(size, "px ").concat(family);
20765 var width = 0;
20766 var height = 0;
20767 var lines = text.split("\n");
20768 for (var i2 = 0; i2 < lines.length; i2++) {
20769 var line = lines[i2];
20770 var metrics = c2d.measureText(line);
20771 var w = Math.ceil(metrics.width);
20772 var h = size;
20773 width = Math.max(w, width);
20774 height += h;
20775 }
20776 width += padding;
20777 height += padding;
20778 return cache2[cacheKey] = {
20779 width,
20780 height
20781 };
20782 };
20783 BRp$9.calculateLabelAngle = function(ele, prefix) {
20784 var _p = ele._private;
20785 var rs = _p.rscratch;
20786 var isEdge = ele.isEdge();
20787 var prefixDash = prefix ? prefix + "-" : "";
20788 var rot = ele.pstyle(prefixDash + "text-rotation");
20789 var rotStr = rot.strValue;
20790 if (rotStr === "none") {
20791 return 0;
20792 } else if (isEdge && rotStr === "autorotate") {
20793 return rs.labelAutoAngle;
20794 } else if (rotStr === "autorotate") {
20795 return 0;
20796 } else {
20797 return rot.pfValue;
20798 }
20799 };
20800 BRp$9.calculateLabelAngles = function(ele) {
20801 var r = this;
20802 var isEdge = ele.isEdge();
20803 var _p = ele._private;
20804 var rs = _p.rscratch;
20805 rs.labelAngle = r.calculateLabelAngle(ele);
20806 if (isEdge) {
20807 rs.sourceLabelAngle = r.calculateLabelAngle(ele, "source");
20808 rs.targetLabelAngle = r.calculateLabelAngle(ele, "target");
20809 }
20810 };
20811 var BRp$8 = {};
20812 var TOO_SMALL_CUT_RECT = 28;
20813 var warnedCutRect = false;
20814 BRp$8.getNodeShape = function(node) {
20815 var r = this;
20816 var shape = node.pstyle("shape").value;
20817 if (shape === "cutrectangle" && (node.width() < TOO_SMALL_CUT_RECT || node.height() < TOO_SMALL_CUT_RECT)) {
20818 if (!warnedCutRect) {
20819 warn("The `cutrectangle` node shape can not be used at small sizes so `rectangle` is used instead");
20820 warnedCutRect = true;
20821 }
20822 return "rectangle";
20823 }
20824 if (node.isParent()) {
20825 if (shape === "rectangle" || shape === "roundrectangle" || shape === "round-rectangle" || shape === "cutrectangle" || shape === "cut-rectangle" || shape === "barrel") {
20826 return shape;
20827 } else {
20828 return "rectangle";
20829 }
20830 }
20831 if (shape === "polygon") {
20832 var points = node.pstyle("shape-polygon-points").value;
20833 return r.nodeShapes.makePolygon(points).name;
20834 }
20835 return shape;
20836 };
20837 var BRp$7 = {};
20838 BRp$7.registerCalculationListeners = function() {
20839 var cy = this.cy;
20840 var elesToUpdate = cy.collection();
20841 var r = this;
20842 var enqueue = function enqueue2(eles) {
20843 var dirtyStyleCaches = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
20844 elesToUpdate.merge(eles);
20845 if (dirtyStyleCaches) {
20846 for (var i2 = 0; i2 < eles.length; i2++) {
20847 var ele = eles[i2];
20848 var _p = ele._private;
20849 var rstyle = _p.rstyle;
20850 rstyle.clean = false;
20851 rstyle.cleanConnected = false;
20852 }
20853 }
20854 };
20855 r.binder(cy).on("bounds.* dirty.*", function onDirtyBounds(e) {
20856 var ele = e.target;
20857 enqueue(ele);
20858 }).on("style.* background.*", function onDirtyStyle(e) {
20859 var ele = e.target;
20860 enqueue(ele, false);
20861 });
20862 var updateEleCalcs = function updateEleCalcs2(willDraw) {
20863 if (willDraw) {
20864 var fns = r.onUpdateEleCalcsFns;
20865 elesToUpdate.cleanStyle();
20866 for (var i2 = 0; i2 < elesToUpdate.length; i2++) {
20867 var ele = elesToUpdate[i2];
20868 var rstyle = ele._private.rstyle;
20869 if (ele.isNode() && !rstyle.cleanConnected) {
20870 enqueue(ele.connectedEdges());
20871 rstyle.cleanConnected = true;
20872 }
20873 }
20874 if (fns) {
20875 for (var _i = 0; _i < fns.length; _i++) {
20876 var fn2 = fns[_i];
20877 fn2(willDraw, elesToUpdate);
20878 }
20879 }
20880 r.recalculateRenderedStyle(elesToUpdate);
20881 elesToUpdate = cy.collection();
20882 }
20883 };
20884 r.flushRenderedStyleQueue = function() {
20885 updateEleCalcs(true);
20886 };
20887 r.beforeRender(updateEleCalcs, r.beforeRenderPriorities.eleCalcs);
20888 };
20889 BRp$7.onUpdateEleCalcs = function(fn2) {
20890 var fns = this.onUpdateEleCalcsFns = this.onUpdateEleCalcsFns || [];
20891 fns.push(fn2);
20892 };
20893 BRp$7.recalculateRenderedStyle = function(eles, useCache) {
20894 var isCleanConnected = function isCleanConnected2(ele2) {
20895 return ele2._private.rstyle.cleanConnected;
20896 };
20897 var edges = [];
20898 var nodes2 = [];
20899 if (this.destroyed) {
20900 return;
20901 }
20902 if (useCache === void 0) {
20903 useCache = true;
20904 }
20905 for (var i2 = 0; i2 < eles.length; i2++) {
20906 var ele = eles[i2];
20907 var _p = ele._private;
20908 var rstyle = _p.rstyle;
20909 if (ele.isEdge() && (!isCleanConnected(ele.source()) || !isCleanConnected(ele.target()))) {
20910 rstyle.clean = false;
20911 }
20912 if (useCache && rstyle.clean || ele.removed()) {
20913 continue;
20914 }
20915 if (ele.pstyle("display").value === "none") {
20916 continue;
20917 }
20918 if (_p.group === "nodes") {
20919 nodes2.push(ele);
20920 } else {
20921 edges.push(ele);
20922 }
20923 rstyle.clean = true;
20924 }
20925 for (var _i2 = 0; _i2 < nodes2.length; _i2++) {
20926 var _ele = nodes2[_i2];
20927 var _p2 = _ele._private;
20928 var _rstyle = _p2.rstyle;
20929 var pos = _ele.position();
20930 this.recalculateNodeLabelProjection(_ele);
20931 _rstyle.nodeX = pos.x;
20932 _rstyle.nodeY = pos.y;
20933 _rstyle.nodeW = _ele.pstyle("width").pfValue;
20934 _rstyle.nodeH = _ele.pstyle("height").pfValue;
20935 }
20936 this.recalculateEdgeProjections(edges);
20937 for (var _i3 = 0; _i3 < edges.length; _i3++) {
20938 var _ele2 = edges[_i3];
20939 var _p3 = _ele2._private;
20940 var _rstyle2 = _p3.rstyle;
20941 var rs = _p3.rscratch;
20942 _rstyle2.srcX = rs.arrowStartX;
20943 _rstyle2.srcY = rs.arrowStartY;
20944 _rstyle2.tgtX = rs.arrowEndX;
20945 _rstyle2.tgtY = rs.arrowEndY;
20946 _rstyle2.midX = rs.midX;
20947 _rstyle2.midY = rs.midY;
20948 _rstyle2.labelAngle = rs.labelAngle;
20949 _rstyle2.sourceLabelAngle = rs.sourceLabelAngle;
20950 _rstyle2.targetLabelAngle = rs.targetLabelAngle;
20951 }
20952 };
20953 var BRp$6 = {};
20954 BRp$6.updateCachedGrabbedEles = function() {
20955 var eles = this.cachedZSortedEles;
20956 if (!eles) {
20957 return;
20958 }
20959 eles.drag = [];
20960 eles.nondrag = [];
20961 var grabTargets = [];
20962 for (var i2 = 0; i2 < eles.length; i2++) {
20963 var ele = eles[i2];
20964 var rs = ele._private.rscratch;
20965 if (ele.grabbed() && !ele.isParent()) {
20966 grabTargets.push(ele);
20967 } else if (rs.inDragLayer) {
20968 eles.drag.push(ele);
20969 } else {
20970 eles.nondrag.push(ele);
20971 }
20972 }
20973 for (var i2 = 0; i2 < grabTargets.length; i2++) {
20974 var ele = grabTargets[i2];
20975 eles.drag.push(ele);
20976 }
20977 };
20978 BRp$6.invalidateCachedZSortedEles = function() {
20979 this.cachedZSortedEles = null;
20980 };
20981 BRp$6.getCachedZSortedEles = function(forceRecalc) {
20982 if (forceRecalc || !this.cachedZSortedEles) {
20983 var eles = this.cy.mutableElements().toArray();
20984 eles.sort(zIndexSort);
20985 eles.interactive = eles.filter(function(ele) {
20986 return ele.interactive();
20987 });
20988 this.cachedZSortedEles = eles;
20989 this.updateCachedGrabbedEles();
20990 } else {
20991 eles = this.cachedZSortedEles;
20992 }
20993 return eles;
20994 };
20995 var BRp$5 = {};
20996 [BRp$e, BRp$d, BRp$c, BRp$b, BRp$a, BRp$9, BRp$8, BRp$7, BRp$6].forEach(function(props) {
20997 extend(BRp$5, props);
20998 });
20999 var BRp$4 = {};
21000 BRp$4.getCachedImage = function(url, crossOrigin, onLoad) {
21001 var r = this;
21002 var imageCache = r.imageCache = r.imageCache || {};
21003 var cache2 = imageCache[url];
21004 if (cache2) {
21005 if (!cache2.image.complete) {
21006 cache2.image.addEventListener("load", onLoad);
21007 }
21008 return cache2.image;
21009 } else {
21010 cache2 = imageCache[url] = imageCache[url] || {};
21011 var image = cache2.image = new Image();
21012 image.addEventListener("load", onLoad);
21013 image.addEventListener("error", function() {
21014 image.error = true;
21015 });
21016 var dataUriPrefix = "data:";
21017 var isDataUri = url.substring(0, dataUriPrefix.length).toLowerCase() === dataUriPrefix;
21018 if (!isDataUri) {
21019 image.crossOrigin = crossOrigin;
21020 }
21021 image.src = url;
21022 return image;
21023 }
21024 };
21025 var BRp$3 = {};
21026 BRp$3.registerBinding = function(target, event2, handler, useCapture) {
21027 var args = Array.prototype.slice.apply(arguments, [1]);
21028 var b = this.binder(target);
21029 return b.on.apply(b, args);
21030 };
21031 BRp$3.binder = function(tgt) {
21032 var r = this;
21033 var tgtIsDom = tgt === window || tgt === document || tgt === document.body || domElement(tgt);
21034 if (r.supportsPassiveEvents == null) {
21035 var supportsPassive = false;
21036 try {
21037 var opts = Object.defineProperty({}, "passive", {
21038 get: function get2() {
21039 supportsPassive = true;
21040 return true;
21041 }
21042 });
21043 window.addEventListener("test", null, opts);
21044 } catch (err) {
21045 }
21046 r.supportsPassiveEvents = supportsPassive;
21047 }
21048 var on = function on2(event2, handler, useCapture) {
21049 var args = Array.prototype.slice.call(arguments);
21050 if (tgtIsDom && r.supportsPassiveEvents) {
21051 args[2] = {
21052 capture: useCapture != null ? useCapture : false,
21053 passive: false,
21054 once: false
21055 };
21056 }
21057 r.bindings.push({
21058 target: tgt,
21059 args
21060 });
21061 (tgt.addEventListener || tgt.on).apply(tgt, args);
21062 return this;
21063 };
21064 return {
21065 on,
21066 addEventListener: on,
21067 addListener: on,
21068 bind: on
21069 };
21070 };
21071 BRp$3.nodeIsDraggable = function(node) {
21072 return node && node.isNode() && !node.locked() && node.grabbable();
21073 };
21074 BRp$3.nodeIsGrabbable = function(node) {
21075 return this.nodeIsDraggable(node) && node.interactive();
21076 };
21077 BRp$3.load = function() {
21078 var r = this;
21079 var isSelected = function isSelected2(ele) {
21080 return ele.selected();
21081 };
21082 var triggerEvents = function triggerEvents2(target, names, e, position2) {
21083 if (target == null) {
21084 target = r.cy;
21085 }
21086 for (var i2 = 0; i2 < names.length; i2++) {
21087 var name2 = names[i2];
21088 target.emit({
21089 originalEvent: e,
21090 type: name2,
21091 position: position2
21092 });
21093 }
21094 };
21095 var isMultSelKeyDown = function isMultSelKeyDown2(e) {
21096 return e.shiftKey || e.metaKey || e.ctrlKey;
21097 };
21098 var allowPanningPassthrough = function allowPanningPassthrough2(down, downs) {
21099 var allowPassthrough = true;
21100 if (r.cy.hasCompoundNodes() && down && down.pannable()) {
21101 for (var i2 = 0; downs && i2 < downs.length; i2++) {
21102 var down = downs[i2];
21103 if (down.isNode() && down.isParent() && !down.pannable()) {
21104 allowPassthrough = false;
21105 break;
21106 }
21107 }
21108 } else {
21109 allowPassthrough = true;
21110 }
21111 return allowPassthrough;
21112 };
21113 var setGrabbed = function setGrabbed2(ele) {
21114 ele[0]._private.grabbed = true;
21115 };
21116 var setFreed = function setFreed2(ele) {
21117 ele[0]._private.grabbed = false;
21118 };
21119 var setInDragLayer = function setInDragLayer2(ele) {
21120 ele[0]._private.rscratch.inDragLayer = true;
21121 };
21122 var setOutDragLayer = function setOutDragLayer2(ele) {
21123 ele[0]._private.rscratch.inDragLayer = false;
21124 };
21125 var setGrabTarget = function setGrabTarget2(ele) {
21126 ele[0]._private.rscratch.isGrabTarget = true;
21127 };
21128 var removeGrabTarget = function removeGrabTarget2(ele) {
21129 ele[0]._private.rscratch.isGrabTarget = false;
21130 };
21131 var addToDragList = function addToDragList2(ele, opts) {
21132 var list = opts.addToList;
21133 var listHasEle = list.has(ele);
21134 if (!listHasEle && ele.grabbable() && !ele.locked()) {
21135 list.merge(ele);
21136 setGrabbed(ele);
21137 }
21138 };
21139 var addDescendantsToDrag = function addDescendantsToDrag2(node, opts) {
21140 if (!node.cy().hasCompoundNodes()) {
21141 return;
21142 }
21143 if (opts.inDragLayer == null && opts.addToList == null) {
21144 return;
21145 }
21146 var innerNodes = node.descendants();
21147 if (opts.inDragLayer) {
21148 innerNodes.forEach(setInDragLayer);
21149 innerNodes.connectedEdges().forEach(setInDragLayer);
21150 }
21151 if (opts.addToList) {
21152 addToDragList(innerNodes, opts);
21153 }
21154 };
21155 var addNodesToDrag = function addNodesToDrag2(nodes2, opts) {
21156 opts = opts || {};
21157 var hasCompoundNodes = nodes2.cy().hasCompoundNodes();
21158 if (opts.inDragLayer) {
21159 nodes2.forEach(setInDragLayer);
21160 nodes2.neighborhood().stdFilter(function(ele) {
21161 return !hasCompoundNodes || ele.isEdge();
21162 }).forEach(setInDragLayer);
21163 }
21164 if (opts.addToList) {
21165 nodes2.forEach(function(ele) {
21166 addToDragList(ele, opts);
21167 });
21168 }
21169 addDescendantsToDrag(nodes2, opts);
21170 updateAncestorsInDragLayer(nodes2, {
21171 inDragLayer: opts.inDragLayer
21172 });
21173 r.updateCachedGrabbedEles();
21174 };
21175 var addNodeToDrag = addNodesToDrag;
21176 var freeDraggedElements = function freeDraggedElements2(grabbedEles) {
21177 if (!grabbedEles) {
21178 return;
21179 }
21180 r.getCachedZSortedEles().forEach(function(ele) {
21181 setFreed(ele);
21182 setOutDragLayer(ele);
21183 removeGrabTarget(ele);
21184 });
21185 r.updateCachedGrabbedEles();
21186 };
21187 var updateAncestorsInDragLayer = function updateAncestorsInDragLayer2(node, opts) {
21188 if (opts.inDragLayer == null && opts.addToList == null) {
21189 return;
21190 }
21191 if (!node.cy().hasCompoundNodes()) {
21192 return;
21193 }
21194 var parent = node.ancestors().orphans();
21195 if (parent.same(node)) {
21196 return;
21197 }
21198 var nodes2 = parent.descendants().spawnSelf().merge(parent).unmerge(node).unmerge(node.descendants());
21199 var edges = nodes2.connectedEdges();
21200 if (opts.inDragLayer) {
21201 edges.forEach(setInDragLayer);
21202 nodes2.forEach(setInDragLayer);
21203 }
21204 if (opts.addToList) {
21205 nodes2.forEach(function(ele) {
21206 addToDragList(ele, opts);
21207 });
21208 }
21209 };
21210 var blurActiveDomElement = function blurActiveDomElement2() {
21211 if (document.activeElement != null && document.activeElement.blur != null) {
21212 document.activeElement.blur();
21213 }
21214 };
21215 var haveMutationsApi = typeof MutationObserver !== "undefined";
21216 var haveResizeObserverApi = typeof ResizeObserver !== "undefined";
21217 if (haveMutationsApi) {
21218 r.removeObserver = new MutationObserver(function(mutns) {
21219 for (var i2 = 0; i2 < mutns.length; i2++) {
21220 var mutn = mutns[i2];
21221 var rNodes = mutn.removedNodes;
21222 if (rNodes) {
21223 for (var j = 0; j < rNodes.length; j++) {
21224 var rNode = rNodes[j];
21225 if (rNode === r.container) {
21226 r.destroy();
21227 break;
21228 }
21229 }
21230 }
21231 }
21232 });
21233 if (r.container.parentNode) {
21234 r.removeObserver.observe(r.container.parentNode, {
21235 childList: true
21236 });
21237 }
21238 } else {
21239 r.registerBinding(r.container, "DOMNodeRemoved", function(e) {
21240 r.destroy();
21241 });
21242 }
21243 var onResize = debounce_1(function() {
21244 r.cy.resize();
21245 }, 100);
21246 if (haveMutationsApi) {
21247 r.styleObserver = new MutationObserver(onResize);
21248 r.styleObserver.observe(r.container, {
21249 attributes: true
21250 });
21251 }
21252 r.registerBinding(window, "resize", onResize);
21253 if (haveResizeObserverApi) {
21254 r.resizeObserver = new ResizeObserver(onResize);
21255 r.resizeObserver.observe(r.container);
21256 }
21257 var forEachUp = function forEachUp2(domEle, fn2) {
21258 while (domEle != null) {
21259 fn2(domEle);
21260 domEle = domEle.parentNode;
21261 }
21262 };
21263 var invalidateCoords = function invalidateCoords2() {
21264 r.invalidateContainerClientCoordsCache();
21265 };
21266 forEachUp(r.container, function(domEle) {
21267 r.registerBinding(domEle, "transitionend", invalidateCoords);
21268 r.registerBinding(domEle, "animationend", invalidateCoords);
21269 r.registerBinding(domEle, "scroll", invalidateCoords);
21270 });
21271 r.registerBinding(r.container, "contextmenu", function(e) {
21272 e.preventDefault();
21273 });
21274 var inBoxSelection = function inBoxSelection2() {
21275 return r.selection[4] !== 0;
21276 };
21277 var eventInContainer = function eventInContainer2(e) {
21278 var containerPageCoords = r.findContainerClientCoords();
21279 var x = containerPageCoords[0];
21280 var y = containerPageCoords[1];
21281 var width = containerPageCoords[2];
21282 var height = containerPageCoords[3];
21283 var positions = e.touches ? e.touches : [e];
21284 var atLeastOnePosInside = false;
21285 for (var i2 = 0; i2 < positions.length; i2++) {
21286 var p2 = positions[i2];
21287 if (x <= p2.clientX && p2.clientX <= x + width && y <= p2.clientY && p2.clientY <= y + height) {
21288 atLeastOnePosInside = true;
21289 break;
21290 }
21291 }
21292 if (!atLeastOnePosInside) {
21293 return false;
21294 }
21295 var container = r.container;
21296 var target = e.target;
21297 var tParent = target.parentNode;
21298 var containerIsTarget = false;
21299 while (tParent) {
21300 if (tParent === container) {
21301 containerIsTarget = true;
21302 break;
21303 }
21304 tParent = tParent.parentNode;
21305 }
21306 if (!containerIsTarget) {
21307 return false;
21308 }
21309 return true;
21310 };
21311 r.registerBinding(r.container, "mousedown", function mousedownHandler(e) {
21312 if (!eventInContainer(e)) {
21313 return;
21314 }
21315 e.preventDefault();
21316 blurActiveDomElement();
21317 r.hoverData.capture = true;
21318 r.hoverData.which = e.which;
21319 var cy = r.cy;
21320 var gpos = [e.clientX, e.clientY];
21321 var pos = r.projectIntoViewport(gpos[0], gpos[1]);
21322 var select2 = r.selection;
21323 var nears = r.findNearestElements(pos[0], pos[1], true, false);
21324 var near = nears[0];
21325 var draggedElements = r.dragData.possibleDragElements;
21326 r.hoverData.mdownPos = pos;
21327 r.hoverData.mdownGPos = gpos;
21328 var checkForTaphold = function checkForTaphold2() {
21329 r.hoverData.tapholdCancelled = false;
21330 clearTimeout(r.hoverData.tapholdTimeout);
21331 r.hoverData.tapholdTimeout = setTimeout(function() {
21332 if (r.hoverData.tapholdCancelled) {
21333 return;
21334 } else {
21335 var ele = r.hoverData.down;
21336 if (ele) {
21337 ele.emit({
21338 originalEvent: e,
21339 type: "taphold",
21340 position: {
21341 x: pos[0],
21342 y: pos[1]
21343 }
21344 });
21345 } else {
21346 cy.emit({
21347 originalEvent: e,
21348 type: "taphold",
21349 position: {
21350 x: pos[0],
21351 y: pos[1]
21352 }
21353 });
21354 }
21355 }
21356 }, r.tapholdDuration);
21357 };
21358 if (e.which == 3) {
21359 r.hoverData.cxtStarted = true;
21360 var cxtEvt = {
21361 originalEvent: e,
21362 type: "cxttapstart",
21363 position: {
21364 x: pos[0],
21365 y: pos[1]
21366 }
21367 };
21368 if (near) {
21369 near.activate();
21370 near.emit(cxtEvt);
21371 r.hoverData.down = near;
21372 } else {
21373 cy.emit(cxtEvt);
21374 }
21375 r.hoverData.downTime = (/* @__PURE__ */ new Date()).getTime();
21376 r.hoverData.cxtDragged = false;
21377 } else if (e.which == 1) {
21378 if (near) {
21379 near.activate();
21380 }
21381 {
21382 if (near != null) {
21383 if (r.nodeIsGrabbable(near)) {
21384 var makeEvent = function makeEvent2(type) {
21385 return {
21386 originalEvent: e,
21387 type,
21388 position: {
21389 x: pos[0],
21390 y: pos[1]
21391 }
21392 };
21393 };
21394 var triggerGrab = function triggerGrab2(ele) {
21395 ele.emit(makeEvent("grab"));
21396 };
21397 setGrabTarget(near);
21398 if (!near.selected()) {
21399 draggedElements = r.dragData.possibleDragElements = cy.collection();
21400 addNodeToDrag(near, {
21401 addToList: draggedElements
21402 });
21403 near.emit(makeEvent("grabon")).emit(makeEvent("grab"));
21404 } else {
21405 draggedElements = r.dragData.possibleDragElements = cy.collection();
21406 var selectedNodes = cy.$(function(ele) {
21407 return ele.isNode() && ele.selected() && r.nodeIsGrabbable(ele);
21408 });
21409 addNodesToDrag(selectedNodes, {
21410 addToList: draggedElements
21411 });
21412 near.emit(makeEvent("grabon"));
21413 selectedNodes.forEach(triggerGrab);
21414 }
21415 r.redrawHint("eles", true);
21416 r.redrawHint("drag", true);
21417 }
21418 }
21419 r.hoverData.down = near;
21420 r.hoverData.downs = nears;
21421 r.hoverData.downTime = (/* @__PURE__ */ new Date()).getTime();
21422 }
21423 triggerEvents(near, ["mousedown", "tapstart", "vmousedown"], e, {
21424 x: pos[0],
21425 y: pos[1]
21426 });
21427 if (near == null) {
21428 select2[4] = 1;
21429 r.data.bgActivePosistion = {
21430 x: pos[0],
21431 y: pos[1]
21432 };
21433 r.redrawHint("select", true);
21434 r.redraw();
21435 } else if (near.pannable()) {
21436 select2[4] = 1;
21437 }
21438 checkForTaphold();
21439 }
21440 select2[0] = select2[2] = pos[0];
21441 select2[1] = select2[3] = pos[1];
21442 }, false);
21443 r.registerBinding(window, "mousemove", function mousemoveHandler(e) {
21444 var capture = r.hoverData.capture;
21445 if (!capture && !eventInContainer(e)) {
21446 return;
21447 }
21448 var preventDefault = false;
21449 var cy = r.cy;
21450 var zoom = cy.zoom();
21451 var gpos = [e.clientX, e.clientY];
21452 var pos = r.projectIntoViewport(gpos[0], gpos[1]);
21453 var mdownPos = r.hoverData.mdownPos;
21454 var mdownGPos = r.hoverData.mdownGPos;
21455 var select2 = r.selection;
21456 var near = null;
21457 if (!r.hoverData.draggingEles && !r.hoverData.dragging && !r.hoverData.selecting) {
21458 near = r.findNearestElement(pos[0], pos[1], true, false);
21459 }
21460 var last = r.hoverData.last;
21461 var down = r.hoverData.down;
21462 var disp = [pos[0] - select2[2], pos[1] - select2[3]];
21463 var draggedElements = r.dragData.possibleDragElements;
21464 var isOverThresholdDrag;
21465 if (mdownGPos) {
21466 var dx = gpos[0] - mdownGPos[0];
21467 var dx2 = dx * dx;
21468 var dy = gpos[1] - mdownGPos[1];
21469 var dy2 = dy * dy;
21470 var dist2 = dx2 + dy2;
21471 r.hoverData.isOverThresholdDrag = isOverThresholdDrag = dist2 >= r.desktopTapThreshold2;
21472 }
21473 var multSelKeyDown = isMultSelKeyDown(e);
21474 if (isOverThresholdDrag) {
21475 r.hoverData.tapholdCancelled = true;
21476 }
21477 var updateDragDelta = function updateDragDelta2() {
21478 var dragDelta2 = r.hoverData.dragDelta = r.hoverData.dragDelta || [];
21479 if (dragDelta2.length === 0) {
21480 dragDelta2.push(disp[0]);
21481 dragDelta2.push(disp[1]);
21482 } else {
21483 dragDelta2[0] += disp[0];
21484 dragDelta2[1] += disp[1];
21485 }
21486 };
21487 preventDefault = true;
21488 triggerEvents(near, ["mousemove", "vmousemove", "tapdrag"], e, {
21489 x: pos[0],
21490 y: pos[1]
21491 });
21492 var goIntoBoxMode = function goIntoBoxMode2() {
21493 r.data.bgActivePosistion = void 0;
21494 if (!r.hoverData.selecting) {
21495 cy.emit({
21496 originalEvent: e,
21497 type: "boxstart",
21498 position: {
21499 x: pos[0],
21500 y: pos[1]
21501 }
21502 });
21503 }
21504 select2[4] = 1;
21505 r.hoverData.selecting = true;
21506 r.redrawHint("select", true);
21507 r.redraw();
21508 };
21509 if (r.hoverData.which === 3) {
21510 if (isOverThresholdDrag) {
21511 var cxtEvt = {
21512 originalEvent: e,
21513 type: "cxtdrag",
21514 position: {
21515 x: pos[0],
21516 y: pos[1]
21517 }
21518 };
21519 if (down) {
21520 down.emit(cxtEvt);
21521 } else {
21522 cy.emit(cxtEvt);
21523 }
21524 r.hoverData.cxtDragged = true;
21525 if (!r.hoverData.cxtOver || near !== r.hoverData.cxtOver) {
21526 if (r.hoverData.cxtOver) {
21527 r.hoverData.cxtOver.emit({
21528 originalEvent: e,
21529 type: "cxtdragout",
21530 position: {
21531 x: pos[0],
21532 y: pos[1]
21533 }
21534 });
21535 }
21536 r.hoverData.cxtOver = near;
21537 if (near) {
21538 near.emit({
21539 originalEvent: e,
21540 type: "cxtdragover",
21541 position: {
21542 x: pos[0],
21543 y: pos[1]
21544 }
21545 });
21546 }
21547 }
21548 }
21549 } else if (r.hoverData.dragging) {
21550 preventDefault = true;
21551 if (cy.panningEnabled() && cy.userPanningEnabled()) {
21552 var deltaP;
21553 if (r.hoverData.justStartedPan) {
21554 var mdPos = r.hoverData.mdownPos;
21555 deltaP = {
21556 x: (pos[0] - mdPos[0]) * zoom,
21557 y: (pos[1] - mdPos[1]) * zoom
21558 };
21559 r.hoverData.justStartedPan = false;
21560 } else {
21561 deltaP = {
21562 x: disp[0] * zoom,
21563 y: disp[1] * zoom
21564 };
21565 }
21566 cy.panBy(deltaP);
21567 cy.emit("dragpan");
21568 r.hoverData.dragged = true;
21569 }
21570 pos = r.projectIntoViewport(e.clientX, e.clientY);
21571 } else if (select2[4] == 1 && (down == null || down.pannable())) {
21572 if (isOverThresholdDrag) {
21573 if (!r.hoverData.dragging && cy.boxSelectionEnabled() && (multSelKeyDown || !cy.panningEnabled() || !cy.userPanningEnabled())) {
21574 goIntoBoxMode();
21575 } else if (!r.hoverData.selecting && cy.panningEnabled() && cy.userPanningEnabled()) {
21576 var allowPassthrough = allowPanningPassthrough(down, r.hoverData.downs);
21577 if (allowPassthrough) {
21578 r.hoverData.dragging = true;
21579 r.hoverData.justStartedPan = true;
21580 select2[4] = 0;
21581 r.data.bgActivePosistion = array2point(mdownPos);
21582 r.redrawHint("select", true);
21583 r.redraw();
21584 }
21585 }
21586 if (down && down.pannable() && down.active()) {
21587 down.unactivate();
21588 }
21589 }
21590 } else {
21591 if (down && down.pannable() && down.active()) {
21592 down.unactivate();
21593 }
21594 if ((!down || !down.grabbed()) && near != last) {
21595 if (last) {
21596 triggerEvents(last, ["mouseout", "tapdragout"], e, {
21597 x: pos[0],
21598 y: pos[1]
21599 });
21600 }
21601 if (near) {
21602 triggerEvents(near, ["mouseover", "tapdragover"], e, {
21603 x: pos[0],
21604 y: pos[1]
21605 });
21606 }
21607 r.hoverData.last = near;
21608 }
21609 if (down) {
21610 if (isOverThresholdDrag) {
21611 if (cy.boxSelectionEnabled() && multSelKeyDown) {
21612 if (down && down.grabbed()) {
21613 freeDraggedElements(draggedElements);
21614 down.emit("freeon");
21615 draggedElements.emit("free");
21616 if (r.dragData.didDrag) {
21617 down.emit("dragfreeon");
21618 draggedElements.emit("dragfree");
21619 }
21620 }
21621 goIntoBoxMode();
21622 } else if (down && down.grabbed() && r.nodeIsDraggable(down)) {
21623 var justStartedDrag = !r.dragData.didDrag;
21624 if (justStartedDrag) {
21625 r.redrawHint("eles", true);
21626 }
21627 r.dragData.didDrag = true;
21628 if (!r.hoverData.draggingEles) {
21629 addNodesToDrag(draggedElements, {
21630 inDragLayer: true
21631 });
21632 }
21633 var totalShift = {
21634 x: 0,
21635 y: 0
21636 };
21637 if (number$1(disp[0]) && number$1(disp[1])) {
21638 totalShift.x += disp[0];
21639 totalShift.y += disp[1];
21640 if (justStartedDrag) {
21641 var dragDelta = r.hoverData.dragDelta;
21642 if (dragDelta && number$1(dragDelta[0]) && number$1(dragDelta[1])) {
21643 totalShift.x += dragDelta[0];
21644 totalShift.y += dragDelta[1];
21645 }
21646 }
21647 }
21648 r.hoverData.draggingEles = true;
21649 draggedElements.silentShift(totalShift).emit("position drag");
21650 r.redrawHint("drag", true);
21651 r.redraw();
21652 }
21653 } else {
21654 updateDragDelta();
21655 }
21656 }
21657 preventDefault = true;
21658 }
21659 select2[2] = pos[0];
21660 select2[3] = pos[1];
21661 if (preventDefault) {
21662 if (e.stopPropagation)
21663 e.stopPropagation();
21664 if (e.preventDefault)
21665 e.preventDefault();
21666 return false;
21667 }
21668 }, false);
21669 var clickTimeout, didDoubleClick, prevClickTimeStamp;
21670 r.registerBinding(window, "mouseup", function mouseupHandler(e) {
21671 var capture = r.hoverData.capture;
21672 if (!capture) {
21673 return;
21674 }
21675 r.hoverData.capture = false;
21676 var cy = r.cy;
21677 var pos = r.projectIntoViewport(e.clientX, e.clientY);
21678 var select2 = r.selection;
21679 var near = r.findNearestElement(pos[0], pos[1], true, false);
21680 var draggedElements = r.dragData.possibleDragElements;
21681 var down = r.hoverData.down;
21682 var multSelKeyDown = isMultSelKeyDown(e);
21683 if (r.data.bgActivePosistion) {
21684 r.redrawHint("select", true);
21685 r.redraw();
21686 }
21687 r.hoverData.tapholdCancelled = true;
21688 r.data.bgActivePosistion = void 0;
21689 if (down) {
21690 down.unactivate();
21691 }
21692 if (r.hoverData.which === 3) {
21693 var cxtEvt = {
21694 originalEvent: e,
21695 type: "cxttapend",
21696 position: {
21697 x: pos[0],
21698 y: pos[1]
21699 }
21700 };
21701 if (down) {
21702 down.emit(cxtEvt);
21703 } else {
21704 cy.emit(cxtEvt);
21705 }
21706 if (!r.hoverData.cxtDragged) {
21707 var cxtTap = {
21708 originalEvent: e,
21709 type: "cxttap",
21710 position: {
21711 x: pos[0],
21712 y: pos[1]
21713 }
21714 };
21715 if (down) {
21716 down.emit(cxtTap);
21717 } else {
21718 cy.emit(cxtTap);
21719 }
21720 }
21721 r.hoverData.cxtDragged = false;
21722 r.hoverData.which = null;
21723 } else if (r.hoverData.which === 1) {
21724 triggerEvents(near, ["mouseup", "tapend", "vmouseup"], e, {
21725 x: pos[0],
21726 y: pos[1]
21727 });
21728 if (!r.dragData.didDrag && // didn't move a node around
21729 !r.hoverData.dragged && // didn't pan
21730 !r.hoverData.selecting && // not box selection
21731 !r.hoverData.isOverThresholdDrag) {
21732 triggerEvents(down, ["click", "tap", "vclick"], e, {
21733 x: pos[0],
21734 y: pos[1]
21735 });
21736 didDoubleClick = false;
21737 if (e.timeStamp - prevClickTimeStamp <= cy.multiClickDebounceTime()) {
21738 clickTimeout && clearTimeout(clickTimeout);
21739 didDoubleClick = true;
21740 prevClickTimeStamp = null;
21741 triggerEvents(down, ["dblclick", "dbltap", "vdblclick"], e, {
21742 x: pos[0],
21743 y: pos[1]
21744 });
21745 } else {
21746 clickTimeout = setTimeout(function() {
21747 if (didDoubleClick)
21748 return;
21749 triggerEvents(down, ["oneclick", "onetap", "voneclick"], e, {
21750 x: pos[0],
21751 y: pos[1]
21752 });
21753 }, cy.multiClickDebounceTime());
21754 prevClickTimeStamp = e.timeStamp;
21755 }
21756 }
21757 if (down == null && !r.dragData.didDrag && !r.hoverData.selecting && !r.hoverData.dragged && !isMultSelKeyDown(e)) {
21758 cy.$(isSelected).unselect(["tapunselect"]);
21759 if (draggedElements.length > 0) {
21760 r.redrawHint("eles", true);
21761 }
21762 r.dragData.possibleDragElements = draggedElements = cy.collection();
21763 }
21764 if (near == down && !r.dragData.didDrag && !r.hoverData.selecting) {
21765 if (near != null && near._private.selectable) {
21766 if (r.hoverData.dragging)
21767 ;
21768 else if (cy.selectionType() === "additive" || multSelKeyDown) {
21769 if (near.selected()) {
21770 near.unselect(["tapunselect"]);
21771 } else {
21772 near.select(["tapselect"]);
21773 }
21774 } else {
21775 if (!multSelKeyDown) {
21776 cy.$(isSelected).unmerge(near).unselect(["tapunselect"]);
21777 near.select(["tapselect"]);
21778 }
21779 }
21780 r.redrawHint("eles", true);
21781 }
21782 }
21783 if (r.hoverData.selecting) {
21784 var box = cy.collection(r.getAllInBox(select2[0], select2[1], select2[2], select2[3]));
21785 r.redrawHint("select", true);
21786 if (box.length > 0) {
21787 r.redrawHint("eles", true);
21788 }
21789 cy.emit({
21790 type: "boxend",
21791 originalEvent: e,
21792 position: {
21793 x: pos[0],
21794 y: pos[1]
21795 }
21796 });
21797 var eleWouldBeSelected = function eleWouldBeSelected2(ele) {
21798 return ele.selectable() && !ele.selected();
21799 };
21800 if (cy.selectionType() === "additive") {
21801 box.emit("box").stdFilter(eleWouldBeSelected).select().emit("boxselect");
21802 } else {
21803 if (!multSelKeyDown) {
21804 cy.$(isSelected).unmerge(box).unselect();
21805 }
21806 box.emit("box").stdFilter(eleWouldBeSelected).select().emit("boxselect");
21807 }
21808 r.redraw();
21809 }
21810 if (r.hoverData.dragging) {
21811 r.hoverData.dragging = false;
21812 r.redrawHint("select", true);
21813 r.redrawHint("eles", true);
21814 r.redraw();
21815 }
21816 if (!select2[4]) {
21817 r.redrawHint("drag", true);
21818 r.redrawHint("eles", true);
21819 var downWasGrabbed = down && down.grabbed();
21820 freeDraggedElements(draggedElements);
21821 if (downWasGrabbed) {
21822 down.emit("freeon");
21823 draggedElements.emit("free");
21824 if (r.dragData.didDrag) {
21825 down.emit("dragfreeon");
21826 draggedElements.emit("dragfree");
21827 }
21828 }
21829 }
21830 }
21831 select2[4] = 0;
21832 r.hoverData.down = null;
21833 r.hoverData.cxtStarted = false;
21834 r.hoverData.draggingEles = false;
21835 r.hoverData.selecting = false;
21836 r.hoverData.isOverThresholdDrag = false;
21837 r.dragData.didDrag = false;
21838 r.hoverData.dragged = false;
21839 r.hoverData.dragDelta = [];
21840 r.hoverData.mdownPos = null;
21841 r.hoverData.mdownGPos = null;
21842 }, false);
21843 var wheelHandler = function wheelHandler2(e) {
21844 if (r.scrollingPage) {
21845 return;
21846 }
21847 var cy = r.cy;
21848 var zoom = cy.zoom();
21849 var pan = cy.pan();
21850 var pos = r.projectIntoViewport(e.clientX, e.clientY);
21851 var rpos = [pos[0] * zoom + pan.x, pos[1] * zoom + pan.y];
21852 if (r.hoverData.draggingEles || r.hoverData.dragging || r.hoverData.cxtStarted || inBoxSelection()) {
21853 e.preventDefault();
21854 return;
21855 }
21856 if (cy.panningEnabled() && cy.userPanningEnabled() && cy.zoomingEnabled() && cy.userZoomingEnabled()) {
21857 e.preventDefault();
21858 r.data.wheelZooming = true;
21859 clearTimeout(r.data.wheelTimeout);
21860 r.data.wheelTimeout = setTimeout(function() {
21861 r.data.wheelZooming = false;
21862 r.redrawHint("eles", true);
21863 r.redraw();
21864 }, 150);
21865 var diff;
21866 if (e.deltaY != null) {
21867 diff = e.deltaY / -250;
21868 } else if (e.wheelDeltaY != null) {
21869 diff = e.wheelDeltaY / 1e3;
21870 } else {
21871 diff = e.wheelDelta / 1e3;
21872 }
21873 diff = diff * r.wheelSensitivity;
21874 var needsWheelFix = e.deltaMode === 1;
21875 if (needsWheelFix) {
21876 diff *= 33;
21877 }
21878 var newZoom = cy.zoom() * Math.pow(10, diff);
21879 if (e.type === "gesturechange") {
21880 newZoom = r.gestureStartZoom * e.scale;
21881 }
21882 cy.zoom({
21883 level: newZoom,
21884 renderedPosition: {
21885 x: rpos[0],
21886 y: rpos[1]
21887 }
21888 });
21889 cy.emit(e.type === "gesturechange" ? "pinchzoom" : "scrollzoom");
21890 }
21891 };
21892 r.registerBinding(r.container, "wheel", wheelHandler, true);
21893 r.registerBinding(window, "scroll", function scrollHandler(e) {
21894 r.scrollingPage = true;
21895 clearTimeout(r.scrollingPageTimeout);
21896 r.scrollingPageTimeout = setTimeout(function() {
21897 r.scrollingPage = false;
21898 }, 250);
21899 }, true);
21900 r.registerBinding(r.container, "gesturestart", function gestureStartHandler(e) {
21901 r.gestureStartZoom = r.cy.zoom();
21902 if (!r.hasTouchStarted) {
21903 e.preventDefault();
21904 }
21905 }, true);
21906 r.registerBinding(r.container, "gesturechange", function(e) {
21907 if (!r.hasTouchStarted) {
21908 wheelHandler(e);
21909 }
21910 }, true);
21911 r.registerBinding(r.container, "mouseout", function mouseOutHandler(e) {
21912 var pos = r.projectIntoViewport(e.clientX, e.clientY);
21913 r.cy.emit({
21914 originalEvent: e,
21915 type: "mouseout",
21916 position: {
21917 x: pos[0],
21918 y: pos[1]
21919 }
21920 });
21921 }, false);
21922 r.registerBinding(r.container, "mouseover", function mouseOverHandler(e) {
21923 var pos = r.projectIntoViewport(e.clientX, e.clientY);
21924 r.cy.emit({
21925 originalEvent: e,
21926 type: "mouseover",
21927 position: {
21928 x: pos[0],
21929 y: pos[1]
21930 }
21931 });
21932 }, false);
21933 var f1x1, f1y1, f2x1, f2y1;
21934 var distance1, distance1Sq;
21935 var center1, modelCenter1;
21936 var offsetLeft, offsetTop;
21937 var containerWidth, containerHeight;
21938 var twoFingersStartInside;
21939 var distance = function distance2(x1, y1, x2, y2) {
21940 return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
21941 };
21942 var distanceSq = function distanceSq2(x1, y1, x2, y2) {
21943 return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
21944 };
21945 var touchstartHandler;
21946 r.registerBinding(r.container, "touchstart", touchstartHandler = function touchstartHandler2(e) {
21947 r.hasTouchStarted = true;
21948 if (!eventInContainer(e)) {
21949 return;
21950 }
21951 blurActiveDomElement();
21952 r.touchData.capture = true;
21953 r.data.bgActivePosistion = void 0;
21954 var cy = r.cy;
21955 var now2 = r.touchData.now;
21956 var earlier = r.touchData.earlier;
21957 if (e.touches[0]) {
21958 var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY);
21959 now2[0] = pos[0];
21960 now2[1] = pos[1];
21961 }
21962 if (e.touches[1]) {
21963 var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY);
21964 now2[2] = pos[0];
21965 now2[3] = pos[1];
21966 }
21967 if (e.touches[2]) {
21968 var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY);
21969 now2[4] = pos[0];
21970 now2[5] = pos[1];
21971 }
21972 if (e.touches[1]) {
21973 r.touchData.singleTouchMoved = true;
21974 freeDraggedElements(r.dragData.touchDragEles);
21975 var offsets = r.findContainerClientCoords();
21976 offsetLeft = offsets[0];
21977 offsetTop = offsets[1];
21978 containerWidth = offsets[2];
21979 containerHeight = offsets[3];
21980 f1x1 = e.touches[0].clientX - offsetLeft;
21981 f1y1 = e.touches[0].clientY - offsetTop;
21982 f2x1 = e.touches[1].clientX - offsetLeft;
21983 f2y1 = e.touches[1].clientY - offsetTop;
21984 twoFingersStartInside = 0 <= f1x1 && f1x1 <= containerWidth && 0 <= f2x1 && f2x1 <= containerWidth && 0 <= f1y1 && f1y1 <= containerHeight && 0 <= f2y1 && f2y1 <= containerHeight;
21985 var pan = cy.pan();
21986 var zoom = cy.zoom();
21987 distance1 = distance(f1x1, f1y1, f2x1, f2y1);
21988 distance1Sq = distanceSq(f1x1, f1y1, f2x1, f2y1);
21989 center1 = [(f1x1 + f2x1) / 2, (f1y1 + f2y1) / 2];
21990 modelCenter1 = [(center1[0] - pan.x) / zoom, (center1[1] - pan.y) / zoom];
21991 var cxtDistThreshold = 200;
21992 var cxtDistThresholdSq = cxtDistThreshold * cxtDistThreshold;
21993 if (distance1Sq < cxtDistThresholdSq && !e.touches[2]) {
21994 var near1 = r.findNearestElement(now2[0], now2[1], true, true);
21995 var near2 = r.findNearestElement(now2[2], now2[3], true, true);
21996 if (near1 && near1.isNode()) {
21997 near1.activate().emit({
21998 originalEvent: e,
21999 type: "cxttapstart",
22000 position: {
22001 x: now2[0],
22002 y: now2[1]
22003 }
22004 });
22005 r.touchData.start = near1;
22006 } else if (near2 && near2.isNode()) {
22007 near2.activate().emit({
22008 originalEvent: e,
22009 type: "cxttapstart",
22010 position: {
22011 x: now2[0],
22012 y: now2[1]
22013 }
22014 });
22015 r.touchData.start = near2;
22016 } else {
22017 cy.emit({
22018 originalEvent: e,
22019 type: "cxttapstart",
22020 position: {
22021 x: now2[0],
22022 y: now2[1]
22023 }
22024 });
22025 }
22026 if (r.touchData.start) {
22027 r.touchData.start._private.grabbed = false;
22028 }
22029 r.touchData.cxt = true;
22030 r.touchData.cxtDragged = false;
22031 r.data.bgActivePosistion = void 0;
22032 r.redraw();
22033 return;
22034 }
22035 }
22036 if (e.touches[2]) {
22037 if (cy.boxSelectionEnabled()) {
22038 e.preventDefault();
22039 }
22040 } else if (e.touches[1])
22041 ;
22042 else if (e.touches[0]) {
22043 var nears = r.findNearestElements(now2[0], now2[1], true, true);
22044 var near = nears[0];
22045 if (near != null) {
22046 near.activate();
22047 r.touchData.start = near;
22048 r.touchData.starts = nears;
22049 if (r.nodeIsGrabbable(near)) {
22050 var draggedEles = r.dragData.touchDragEles = cy.collection();
22051 var selectedNodes = null;
22052 r.redrawHint("eles", true);
22053 r.redrawHint("drag", true);
22054 if (near.selected()) {
22055 selectedNodes = cy.$(function(ele) {
22056 return ele.selected() && r.nodeIsGrabbable(ele);
22057 });
22058 addNodesToDrag(selectedNodes, {
22059 addToList: draggedEles
22060 });
22061 } else {
22062 addNodeToDrag(near, {
22063 addToList: draggedEles
22064 });
22065 }
22066 setGrabTarget(near);
22067 var makeEvent = function makeEvent2(type) {
22068 return {
22069 originalEvent: e,
22070 type,
22071 position: {
22072 x: now2[0],
22073 y: now2[1]
22074 }
22075 };
22076 };
22077 near.emit(makeEvent("grabon"));
22078 if (selectedNodes) {
22079 selectedNodes.forEach(function(n) {
22080 n.emit(makeEvent("grab"));
22081 });
22082 } else {
22083 near.emit(makeEvent("grab"));
22084 }
22085 }
22086 }
22087 triggerEvents(near, ["touchstart", "tapstart", "vmousedown"], e, {
22088 x: now2[0],
22089 y: now2[1]
22090 });
22091 if (near == null) {
22092 r.data.bgActivePosistion = {
22093 x: pos[0],
22094 y: pos[1]
22095 };
22096 r.redrawHint("select", true);
22097 r.redraw();
22098 }
22099 r.touchData.singleTouchMoved = false;
22100 r.touchData.singleTouchStartTime = +/* @__PURE__ */ new Date();
22101 clearTimeout(r.touchData.tapholdTimeout);
22102 r.touchData.tapholdTimeout = setTimeout(function() {
22103 if (r.touchData.singleTouchMoved === false && !r.pinching && !r.touchData.selecting) {
22104 triggerEvents(r.touchData.start, ["taphold"], e, {
22105 x: now2[0],
22106 y: now2[1]
22107 });
22108 }
22109 }, r.tapholdDuration);
22110 }
22111 if (e.touches.length >= 1) {
22112 var sPos = r.touchData.startPosition = [];
22113 for (var i2 = 0; i2 < now2.length; i2++) {
22114 sPos[i2] = earlier[i2] = now2[i2];
22115 }
22116 var touch0 = e.touches[0];
22117 r.touchData.startGPosition = [touch0.clientX, touch0.clientY];
22118 }
22119 }, false);
22120 var touchmoveHandler;
22121 r.registerBinding(window, "touchmove", touchmoveHandler = function touchmoveHandler2(e) {
22122 var capture = r.touchData.capture;
22123 if (!capture && !eventInContainer(e)) {
22124 return;
22125 }
22126 var select2 = r.selection;
22127 var cy = r.cy;
22128 var now2 = r.touchData.now;
22129 var earlier = r.touchData.earlier;
22130 var zoom = cy.zoom();
22131 if (e.touches[0]) {
22132 var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY);
22133 now2[0] = pos[0];
22134 now2[1] = pos[1];
22135 }
22136 if (e.touches[1]) {
22137 var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY);
22138 now2[2] = pos[0];
22139 now2[3] = pos[1];
22140 }
22141 if (e.touches[2]) {
22142 var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY);
22143 now2[4] = pos[0];
22144 now2[5] = pos[1];
22145 }
22146 var startGPos = r.touchData.startGPosition;
22147 var isOverThresholdDrag;
22148 if (capture && e.touches[0] && startGPos) {
22149 var disp = [];
22150 for (var j = 0; j < now2.length; j++) {
22151 disp[j] = now2[j] - earlier[j];
22152 }
22153 var dx = e.touches[0].clientX - startGPos[0];
22154 var dx2 = dx * dx;
22155 var dy = e.touches[0].clientY - startGPos[1];
22156 var dy2 = dy * dy;
22157 var dist2 = dx2 + dy2;
22158 isOverThresholdDrag = dist2 >= r.touchTapThreshold2;
22159 }
22160 if (capture && r.touchData.cxt) {
22161 e.preventDefault();
22162 var f1x2 = e.touches[0].clientX - offsetLeft, f1y2 = e.touches[0].clientY - offsetTop;
22163 var f2x2 = e.touches[1].clientX - offsetLeft, f2y2 = e.touches[1].clientY - offsetTop;
22164 var distance2Sq = distanceSq(f1x2, f1y2, f2x2, f2y2);
22165 var factorSq = distance2Sq / distance1Sq;
22166 var distThreshold = 150;
22167 var distThresholdSq = distThreshold * distThreshold;
22168 var factorThreshold = 1.5;
22169 var factorThresholdSq = factorThreshold * factorThreshold;
22170 if (factorSq >= factorThresholdSq || distance2Sq >= distThresholdSq) {
22171 r.touchData.cxt = false;
22172 r.data.bgActivePosistion = void 0;
22173 r.redrawHint("select", true);
22174 var cxtEvt = {
22175 originalEvent: e,
22176 type: "cxttapend",
22177 position: {
22178 x: now2[0],
22179 y: now2[1]
22180 }
22181 };
22182 if (r.touchData.start) {
22183 r.touchData.start.unactivate().emit(cxtEvt);
22184 r.touchData.start = null;
22185 } else {
22186 cy.emit(cxtEvt);
22187 }
22188 }
22189 }
22190 if (capture && r.touchData.cxt) {
22191 var cxtEvt = {
22192 originalEvent: e,
22193 type: "cxtdrag",
22194 position: {
22195 x: now2[0],
22196 y: now2[1]
22197 }
22198 };
22199 r.data.bgActivePosistion = void 0;
22200 r.redrawHint("select", true);
22201 if (r.touchData.start) {
22202 r.touchData.start.emit(cxtEvt);
22203 } else {
22204 cy.emit(cxtEvt);
22205 }
22206 if (r.touchData.start) {
22207 r.touchData.start._private.grabbed = false;
22208 }
22209 r.touchData.cxtDragged = true;
22210 var near = r.findNearestElement(now2[0], now2[1], true, true);
22211 if (!r.touchData.cxtOver || near !== r.touchData.cxtOver) {
22212 if (r.touchData.cxtOver) {
22213 r.touchData.cxtOver.emit({
22214 originalEvent: e,
22215 type: "cxtdragout",
22216 position: {
22217 x: now2[0],
22218 y: now2[1]
22219 }
22220 });
22221 }
22222 r.touchData.cxtOver = near;
22223 if (near) {
22224 near.emit({
22225 originalEvent: e,
22226 type: "cxtdragover",
22227 position: {
22228 x: now2[0],
22229 y: now2[1]
22230 }
22231 });
22232 }
22233 }
22234 } else if (capture && e.touches[2] && cy.boxSelectionEnabled()) {
22235 e.preventDefault();
22236 r.data.bgActivePosistion = void 0;
22237 this.lastThreeTouch = +/* @__PURE__ */ new Date();
22238 if (!r.touchData.selecting) {
22239 cy.emit({
22240 originalEvent: e,
22241 type: "boxstart",
22242 position: {
22243 x: now2[0],
22244 y: now2[1]
22245 }
22246 });
22247 }
22248 r.touchData.selecting = true;
22249 r.touchData.didSelect = true;
22250 select2[4] = 1;
22251 if (!select2 || select2.length === 0 || select2[0] === void 0) {
22252 select2[0] = (now2[0] + now2[2] + now2[4]) / 3;
22253 select2[1] = (now2[1] + now2[3] + now2[5]) / 3;
22254 select2[2] = (now2[0] + now2[2] + now2[4]) / 3 + 1;
22255 select2[3] = (now2[1] + now2[3] + now2[5]) / 3 + 1;
22256 } else {
22257 select2[2] = (now2[0] + now2[2] + now2[4]) / 3;
22258 select2[3] = (now2[1] + now2[3] + now2[5]) / 3;
22259 }
22260 r.redrawHint("select", true);
22261 r.redraw();
22262 } else if (capture && e.touches[1] && !r.touchData.didSelect && cy.zoomingEnabled() && cy.panningEnabled() && cy.userZoomingEnabled() && cy.userPanningEnabled()) {
22263 e.preventDefault();
22264 r.data.bgActivePosistion = void 0;
22265 r.redrawHint("select", true);
22266 var draggedEles = r.dragData.touchDragEles;
22267 if (draggedEles) {
22268 r.redrawHint("drag", true);
22269 for (var i2 = 0; i2 < draggedEles.length; i2++) {
22270 var de_p = draggedEles[i2]._private;
22271 de_p.grabbed = false;
22272 de_p.rscratch.inDragLayer = false;
22273 }
22274 }
22275 var _start = r.touchData.start;
22276 var f1x2 = e.touches[0].clientX - offsetLeft, f1y2 = e.touches[0].clientY - offsetTop;
22277 var f2x2 = e.touches[1].clientX - offsetLeft, f2y2 = e.touches[1].clientY - offsetTop;
22278 var distance2 = distance(f1x2, f1y2, f2x2, f2y2);
22279 var factor = distance2 / distance1;
22280 if (twoFingersStartInside) {
22281 var df1x = f1x2 - f1x1;
22282 var df1y = f1y2 - f1y1;
22283 var df2x = f2x2 - f2x1;
22284 var df2y = f2y2 - f2y1;
22285 var tx = (df1x + df2x) / 2;
22286 var ty = (df1y + df2y) / 2;
22287 var zoom1 = cy.zoom();
22288 var zoom2 = zoom1 * factor;
22289 var pan1 = cy.pan();
22290 var ctrx = modelCenter1[0] * zoom1 + pan1.x;
22291 var ctry = modelCenter1[1] * zoom1 + pan1.y;
22292 var pan2 = {
22293 x: -zoom2 / zoom1 * (ctrx - pan1.x - tx) + ctrx,
22294 y: -zoom2 / zoom1 * (ctry - pan1.y - ty) + ctry
22295 };
22296 if (_start && _start.active()) {
22297 var draggedEles = r.dragData.touchDragEles;
22298 freeDraggedElements(draggedEles);
22299 r.redrawHint("drag", true);
22300 r.redrawHint("eles", true);
22301 _start.unactivate().emit("freeon");
22302 draggedEles.emit("free");
22303 if (r.dragData.didDrag) {
22304 _start.emit("dragfreeon");
22305 draggedEles.emit("dragfree");
22306 }
22307 }
22308 cy.viewport({
22309 zoom: zoom2,
22310 pan: pan2,
22311 cancelOnFailedZoom: true
22312 });
22313 cy.emit("pinchzoom");
22314 distance1 = distance2;
22315 f1x1 = f1x2;
22316 f1y1 = f1y2;
22317 f2x1 = f2x2;
22318 f2y1 = f2y2;
22319 r.pinching = true;
22320 }
22321 if (e.touches[0]) {
22322 var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY);
22323 now2[0] = pos[0];
22324 now2[1] = pos[1];
22325 }
22326 if (e.touches[1]) {
22327 var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY);
22328 now2[2] = pos[0];
22329 now2[3] = pos[1];
22330 }
22331 if (e.touches[2]) {
22332 var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY);
22333 now2[4] = pos[0];
22334 now2[5] = pos[1];
22335 }
22336 } else if (e.touches[0] && !r.touchData.didSelect) {
22337 var start = r.touchData.start;
22338 var last = r.touchData.last;
22339 var near;
22340 if (!r.hoverData.draggingEles && !r.swipePanning) {
22341 near = r.findNearestElement(now2[0], now2[1], true, true);
22342 }
22343 if (capture && start != null) {
22344 e.preventDefault();
22345 }
22346 if (capture && start != null && r.nodeIsDraggable(start)) {
22347 if (isOverThresholdDrag) {
22348 var draggedEles = r.dragData.touchDragEles;
22349 var justStartedDrag = !r.dragData.didDrag;
22350 if (justStartedDrag) {
22351 addNodesToDrag(draggedEles, {
22352 inDragLayer: true
22353 });
22354 }
22355 r.dragData.didDrag = true;
22356 var totalShift = {
22357 x: 0,
22358 y: 0
22359 };
22360 if (number$1(disp[0]) && number$1(disp[1])) {
22361 totalShift.x += disp[0];
22362 totalShift.y += disp[1];
22363 if (justStartedDrag) {
22364 r.redrawHint("eles", true);
22365 var dragDelta = r.touchData.dragDelta;
22366 if (dragDelta && number$1(dragDelta[0]) && number$1(dragDelta[1])) {
22367 totalShift.x += dragDelta[0];
22368 totalShift.y += dragDelta[1];
22369 }
22370 }
22371 }
22372 r.hoverData.draggingEles = true;
22373 draggedEles.silentShift(totalShift).emit("position drag");
22374 r.redrawHint("drag", true);
22375 if (r.touchData.startPosition[0] == earlier[0] && r.touchData.startPosition[1] == earlier[1]) {
22376 r.redrawHint("eles", true);
22377 }
22378 r.redraw();
22379 } else {
22380 var dragDelta = r.touchData.dragDelta = r.touchData.dragDelta || [];
22381 if (dragDelta.length === 0) {
22382 dragDelta.push(disp[0]);
22383 dragDelta.push(disp[1]);
22384 } else {
22385 dragDelta[0] += disp[0];
22386 dragDelta[1] += disp[1];
22387 }
22388 }
22389 }
22390 {
22391 triggerEvents(start || near, ["touchmove", "tapdrag", "vmousemove"], e, {
22392 x: now2[0],
22393 y: now2[1]
22394 });
22395 if ((!start || !start.grabbed()) && near != last) {
22396 if (last) {
22397 last.emit({
22398 originalEvent: e,
22399 type: "tapdragout",
22400 position: {
22401 x: now2[0],
22402 y: now2[1]
22403 }
22404 });
22405 }
22406 if (near) {
22407 near.emit({
22408 originalEvent: e,
22409 type: "tapdragover",
22410 position: {
22411 x: now2[0],
22412 y: now2[1]
22413 }
22414 });
22415 }
22416 }
22417 r.touchData.last = near;
22418 }
22419 if (capture) {
22420 for (var i2 = 0; i2 < now2.length; i2++) {
22421 if (now2[i2] && r.touchData.startPosition[i2] && isOverThresholdDrag) {
22422 r.touchData.singleTouchMoved = true;
22423 }
22424 }
22425 }
22426 if (capture && (start == null || start.pannable()) && cy.panningEnabled() && cy.userPanningEnabled()) {
22427 var allowPassthrough = allowPanningPassthrough(start, r.touchData.starts);
22428 if (allowPassthrough) {
22429 e.preventDefault();
22430 if (!r.data.bgActivePosistion) {
22431 r.data.bgActivePosistion = array2point(r.touchData.startPosition);
22432 }
22433 if (r.swipePanning) {
22434 cy.panBy({
22435 x: disp[0] * zoom,
22436 y: disp[1] * zoom
22437 });
22438 cy.emit("dragpan");
22439 } else if (isOverThresholdDrag) {
22440 r.swipePanning = true;
22441 cy.panBy({
22442 x: dx * zoom,
22443 y: dy * zoom
22444 });
22445 cy.emit("dragpan");
22446 if (start) {
22447 start.unactivate();
22448 r.redrawHint("select", true);
22449 r.touchData.start = null;
22450 }
22451 }
22452 }
22453 var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY);
22454 now2[0] = pos[0];
22455 now2[1] = pos[1];
22456 }
22457 }
22458 for (var j = 0; j < now2.length; j++) {
22459 earlier[j] = now2[j];
22460 }
22461 if (capture && e.touches.length > 0 && !r.hoverData.draggingEles && !r.swipePanning && r.data.bgActivePosistion != null) {
22462 r.data.bgActivePosistion = void 0;
22463 r.redrawHint("select", true);
22464 r.redraw();
22465 }
22466 }, false);
22467 var touchcancelHandler;
22468 r.registerBinding(window, "touchcancel", touchcancelHandler = function touchcancelHandler2(e) {
22469 var start = r.touchData.start;
22470 r.touchData.capture = false;
22471 if (start) {
22472 start.unactivate();
22473 }
22474 });
22475 var touchendHandler, didDoubleTouch, touchTimeout, prevTouchTimeStamp;
22476 r.registerBinding(window, "touchend", touchendHandler = function touchendHandler2(e) {
22477 var start = r.touchData.start;
22478 var capture = r.touchData.capture;
22479 if (capture) {
22480 if (e.touches.length === 0) {
22481 r.touchData.capture = false;
22482 }
22483 e.preventDefault();
22484 } else {
22485 return;
22486 }
22487 var select2 = r.selection;
22488 r.swipePanning = false;
22489 r.hoverData.draggingEles = false;
22490 var cy = r.cy;
22491 var zoom = cy.zoom();
22492 var now2 = r.touchData.now;
22493 var earlier = r.touchData.earlier;
22494 if (e.touches[0]) {
22495 var pos = r.projectIntoViewport(e.touches[0].clientX, e.touches[0].clientY);
22496 now2[0] = pos[0];
22497 now2[1] = pos[1];
22498 }
22499 if (e.touches[1]) {
22500 var pos = r.projectIntoViewport(e.touches[1].clientX, e.touches[1].clientY);
22501 now2[2] = pos[0];
22502 now2[3] = pos[1];
22503 }
22504 if (e.touches[2]) {
22505 var pos = r.projectIntoViewport(e.touches[2].clientX, e.touches[2].clientY);
22506 now2[4] = pos[0];
22507 now2[5] = pos[1];
22508 }
22509 if (start) {
22510 start.unactivate();
22511 }
22512 var ctxTapend;
22513 if (r.touchData.cxt) {
22514 ctxTapend = {
22515 originalEvent: e,
22516 type: "cxttapend",
22517 position: {
22518 x: now2[0],
22519 y: now2[1]
22520 }
22521 };
22522 if (start) {
22523 start.emit(ctxTapend);
22524 } else {
22525 cy.emit(ctxTapend);
22526 }
22527 if (!r.touchData.cxtDragged) {
22528 var ctxTap = {
22529 originalEvent: e,
22530 type: "cxttap",
22531 position: {
22532 x: now2[0],
22533 y: now2[1]
22534 }
22535 };
22536 if (start) {
22537 start.emit(ctxTap);
22538 } else {
22539 cy.emit(ctxTap);
22540 }
22541 }
22542 if (r.touchData.start) {
22543 r.touchData.start._private.grabbed = false;
22544 }
22545 r.touchData.cxt = false;
22546 r.touchData.start = null;
22547 r.redraw();
22548 return;
22549 }
22550 if (!e.touches[2] && cy.boxSelectionEnabled() && r.touchData.selecting) {
22551 r.touchData.selecting = false;
22552 var box = cy.collection(r.getAllInBox(select2[0], select2[1], select2[2], select2[3]));
22553 select2[0] = void 0;
22554 select2[1] = void 0;
22555 select2[2] = void 0;
22556 select2[3] = void 0;
22557 select2[4] = 0;
22558 r.redrawHint("select", true);
22559 cy.emit({
22560 type: "boxend",
22561 originalEvent: e,
22562 position: {
22563 x: now2[0],
22564 y: now2[1]
22565 }
22566 });
22567 var eleWouldBeSelected = function eleWouldBeSelected2(ele) {
22568 return ele.selectable() && !ele.selected();
22569 };
22570 box.emit("box").stdFilter(eleWouldBeSelected).select().emit("boxselect");
22571 if (box.nonempty()) {
22572 r.redrawHint("eles", true);
22573 }
22574 r.redraw();
22575 }
22576 if (start != null) {
22577 start.unactivate();
22578 }
22579 if (e.touches[2]) {
22580 r.data.bgActivePosistion = void 0;
22581 r.redrawHint("select", true);
22582 } else if (e.touches[1])
22583 ;
22584 else if (e.touches[0])
22585 ;
22586 else if (!e.touches[0]) {
22587 r.data.bgActivePosistion = void 0;
22588 r.redrawHint("select", true);
22589 var draggedEles = r.dragData.touchDragEles;
22590 if (start != null) {
22591 var startWasGrabbed = start._private.grabbed;
22592 freeDraggedElements(draggedEles);
22593 r.redrawHint("drag", true);
22594 r.redrawHint("eles", true);
22595 if (startWasGrabbed) {
22596 start.emit("freeon");
22597 draggedEles.emit("free");
22598 if (r.dragData.didDrag) {
22599 start.emit("dragfreeon");
22600 draggedEles.emit("dragfree");
22601 }
22602 }
22603 triggerEvents(start, ["touchend", "tapend", "vmouseup", "tapdragout"], e, {
22604 x: now2[0],
22605 y: now2[1]
22606 });
22607 start.unactivate();
22608 r.touchData.start = null;
22609 } else {
22610 var near = r.findNearestElement(now2[0], now2[1], true, true);
22611 triggerEvents(near, ["touchend", "tapend", "vmouseup", "tapdragout"], e, {
22612 x: now2[0],
22613 y: now2[1]
22614 });
22615 }
22616 var dx = r.touchData.startPosition[0] - now2[0];
22617 var dx2 = dx * dx;
22618 var dy = r.touchData.startPosition[1] - now2[1];
22619 var dy2 = dy * dy;
22620 var dist2 = dx2 + dy2;
22621 var rdist2 = dist2 * zoom * zoom;
22622 if (!r.touchData.singleTouchMoved) {
22623 if (!start) {
22624 cy.$(":selected").unselect(["tapunselect"]);
22625 }
22626 triggerEvents(start, ["tap", "vclick"], e, {
22627 x: now2[0],
22628 y: now2[1]
22629 });
22630 didDoubleTouch = false;
22631 if (e.timeStamp - prevTouchTimeStamp <= cy.multiClickDebounceTime()) {
22632 touchTimeout && clearTimeout(touchTimeout);
22633 didDoubleTouch = true;
22634 prevTouchTimeStamp = null;
22635 triggerEvents(start, ["dbltap", "vdblclick"], e, {
22636 x: now2[0],
22637 y: now2[1]
22638 });
22639 } else {
22640 touchTimeout = setTimeout(function() {
22641 if (didDoubleTouch)
22642 return;
22643 triggerEvents(start, ["onetap", "voneclick"], e, {
22644 x: now2[0],
22645 y: now2[1]
22646 });
22647 }, cy.multiClickDebounceTime());
22648 prevTouchTimeStamp = e.timeStamp;
22649 }
22650 }
22651 if (start != null && !r.dragData.didDrag && start._private.selectable && rdist2 < r.touchTapThreshold2 && !r.pinching) {
22652 if (cy.selectionType() === "single") {
22653 cy.$(isSelected).unmerge(start).unselect(["tapunselect"]);
22654 start.select(["tapselect"]);
22655 } else {
22656 if (start.selected()) {
22657 start.unselect(["tapunselect"]);
22658 } else {
22659 start.select(["tapselect"]);
22660 }
22661 }
22662 r.redrawHint("eles", true);
22663 }
22664 r.touchData.singleTouchMoved = true;
22665 }
22666 for (var j = 0; j < now2.length; j++) {
22667 earlier[j] = now2[j];
22668 }
22669 r.dragData.didDrag = false;
22670 if (e.touches.length === 0) {
22671 r.touchData.dragDelta = [];
22672 r.touchData.startPosition = null;
22673 r.touchData.startGPosition = null;
22674 r.touchData.didSelect = false;
22675 }
22676 if (e.touches.length < 2) {
22677 if (e.touches.length === 1) {
22678 r.touchData.startGPosition = [e.touches[0].clientX, e.touches[0].clientY];
22679 }
22680 r.pinching = false;
22681 r.redrawHint("eles", true);
22682 r.redraw();
22683 }
22684 }, false);
22685 if (typeof TouchEvent === "undefined") {
22686 var pointers = [];
22687 var makeTouch = function makeTouch2(e) {
22688 return {
22689 clientX: e.clientX,
22690 clientY: e.clientY,
22691 force: 1,
22692 identifier: e.pointerId,
22693 pageX: e.pageX,
22694 pageY: e.pageY,
22695 radiusX: e.width / 2,
22696 radiusY: e.height / 2,
22697 screenX: e.screenX,
22698 screenY: e.screenY,
22699 target: e.target
22700 };
22701 };
22702 var makePointer = function makePointer2(e) {
22703 return {
22704 event: e,
22705 touch: makeTouch(e)
22706 };
22707 };
22708 var addPointer = function addPointer2(e) {
22709 pointers.push(makePointer(e));
22710 };
22711 var removePointer = function removePointer2(e) {
22712 for (var i2 = 0; i2 < pointers.length; i2++) {
22713 var p2 = pointers[i2];
22714 if (p2.event.pointerId === e.pointerId) {
22715 pointers.splice(i2, 1);
22716 return;
22717 }
22718 }
22719 };
22720 var updatePointer = function updatePointer2(e) {
22721 var p2 = pointers.filter(function(p3) {
22722 return p3.event.pointerId === e.pointerId;
22723 })[0];
22724 p2.event = e;
22725 p2.touch = makeTouch(e);
22726 };
22727 var addTouchesToEvent = function addTouchesToEvent2(e) {
22728 e.touches = pointers.map(function(p2) {
22729 return p2.touch;
22730 });
22731 };
22732 var pointerIsMouse = function pointerIsMouse2(e) {
22733 return e.pointerType === "mouse" || e.pointerType === 4;
22734 };
22735 r.registerBinding(r.container, "pointerdown", function(e) {
22736 if (pointerIsMouse(e)) {
22737 return;
22738 }
22739 e.preventDefault();
22740 addPointer(e);
22741 addTouchesToEvent(e);
22742 touchstartHandler(e);
22743 });
22744 r.registerBinding(r.container, "pointerup", function(e) {
22745 if (pointerIsMouse(e)) {
22746 return;
22747 }
22748 removePointer(e);
22749 addTouchesToEvent(e);
22750 touchendHandler(e);
22751 });
22752 r.registerBinding(r.container, "pointercancel", function(e) {
22753 if (pointerIsMouse(e)) {
22754 return;
22755 }
22756 removePointer(e);
22757 addTouchesToEvent(e);
22758 touchcancelHandler(e);
22759 });
22760 r.registerBinding(r.container, "pointermove", function(e) {
22761 if (pointerIsMouse(e)) {
22762 return;
22763 }
22764 e.preventDefault();
22765 updatePointer(e);
22766 addTouchesToEvent(e);
22767 touchmoveHandler(e);
22768 });
22769 }
22770 };
22771 var BRp$2 = {};
22772 BRp$2.generatePolygon = function(name2, points) {
22773 return this.nodeShapes[name2] = {
22774 renderer: this,
22775 name: name2,
22776 points,
22777 draw: function draw2(context, centerX, centerY, width, height) {
22778 this.renderer.nodeShapeImpl("polygon", context, centerX, centerY, width, height, this.points);
22779 },
22780 intersectLine: function intersectLine(nodeX, nodeY, width, height, x, y, padding) {
22781 return polygonIntersectLine(x, y, this.points, nodeX, nodeY, width / 2, height / 2, padding);
22782 },
22783 checkPoint: function checkPoint(x, y, padding, width, height, centerX, centerY) {
22784 return pointInsidePolygon(x, y, this.points, centerX, centerY, width, height, [0, -1], padding);
22785 }
22786 };
22787 };
22788 BRp$2.generateEllipse = function() {
22789 return this.nodeShapes["ellipse"] = {
22790 renderer: this,
22791 name: "ellipse",
22792 draw: function draw2(context, centerX, centerY, width, height) {
22793 this.renderer.nodeShapeImpl(this.name, context, centerX, centerY, width, height);
22794 },
22795 intersectLine: function intersectLine(nodeX, nodeY, width, height, x, y, padding) {
22796 return intersectLineEllipse(x, y, nodeX, nodeY, width / 2 + padding, height / 2 + padding);
22797 },
22798 checkPoint: function checkPoint(x, y, padding, width, height, centerX, centerY) {
22799 return checkInEllipse(x, y, width, height, centerX, centerY, padding);
22800 }
22801 };
22802 };
22803 BRp$2.generateRoundPolygon = function(name2, points) {
22804 var allPoints = new Array(points.length * 2);
22805 for (var i2 = 0; i2 < points.length / 2; i2++) {
22806 var sourceIndex = i2 * 2;
22807 var destIndex = void 0;
22808 if (i2 < points.length / 2 - 1) {
22809 destIndex = (i2 + 1) * 2;
22810 } else {
22811 destIndex = 0;
22812 }
22813 allPoints[i2 * 4] = points[sourceIndex];
22814 allPoints[i2 * 4 + 1] = points[sourceIndex + 1];
22815 var xDest = points[destIndex] - points[sourceIndex];
22816 var yDest = points[destIndex + 1] - points[sourceIndex + 1];
22817 var norm = Math.sqrt(xDest * xDest + yDest * yDest);
22818 allPoints[i2 * 4 + 2] = xDest / norm;
22819 allPoints[i2 * 4 + 3] = yDest / norm;
22820 }
22821 return this.nodeShapes[name2] = {
22822 renderer: this,
22823 name: name2,
22824 points: allPoints,
22825 draw: function draw2(context, centerX, centerY, width, height) {
22826 this.renderer.nodeShapeImpl("round-polygon", context, centerX, centerY, width, height, this.points);
22827 },
22828 intersectLine: function intersectLine(nodeX, nodeY, width, height, x, y, padding) {
22829 return roundPolygonIntersectLine(x, y, this.points, nodeX, nodeY, width, height);
22830 },
22831 checkPoint: function checkPoint(x, y, padding, width, height, centerX, centerY) {
22832 return pointInsideRoundPolygon(x, y, this.points, centerX, centerY, width, height);
22833 }
22834 };
22835 };
22836 BRp$2.generateRoundRectangle = function() {
22837 return this.nodeShapes["round-rectangle"] = this.nodeShapes["roundrectangle"] = {
22838 renderer: this,
22839 name: "round-rectangle",
22840 points: generateUnitNgonPointsFitToSquare(4, 0),
22841 draw: function draw2(context, centerX, centerY, width, height) {
22842 this.renderer.nodeShapeImpl(this.name, context, centerX, centerY, width, height);
22843 },
22844 intersectLine: function intersectLine(nodeX, nodeY, width, height, x, y, padding) {
22845 return roundRectangleIntersectLine(x, y, nodeX, nodeY, width, height, padding);
22846 },
22847 checkPoint: function checkPoint(x, y, padding, width, height, centerX, centerY) {
22848 var cornerRadius = getRoundRectangleRadius(width, height);
22849 var diam = cornerRadius * 2;
22850 if (pointInsidePolygon(x, y, this.points, centerX, centerY, width, height - diam, [0, -1], padding)) {
22851 return true;
22852 }
22853 if (pointInsidePolygon(x, y, this.points, centerX, centerY, width - diam, height, [0, -1], padding)) {
22854 return true;
22855 }
22856 if (checkInEllipse(x, y, diam, diam, centerX - width / 2 + cornerRadius, centerY - height / 2 + cornerRadius, padding)) {
22857 return true;
22858 }
22859 if (checkInEllipse(x, y, diam, diam, centerX + width / 2 - cornerRadius, centerY - height / 2 + cornerRadius, padding)) {
22860 return true;
22861 }
22862 if (checkInEllipse(x, y, diam, diam, centerX + width / 2 - cornerRadius, centerY + height / 2 - cornerRadius, padding)) {
22863 return true;
22864 }
22865 if (checkInEllipse(x, y, diam, diam, centerX - width / 2 + cornerRadius, centerY + height / 2 - cornerRadius, padding)) {
22866 return true;
22867 }
22868 return false;
22869 }
22870 };
22871 };
22872 BRp$2.generateCutRectangle = function() {
22873 return this.nodeShapes["cut-rectangle"] = this.nodeShapes["cutrectangle"] = {
22874 renderer: this,
22875 name: "cut-rectangle",
22876 cornerLength: getCutRectangleCornerLength(),
22877 points: generateUnitNgonPointsFitToSquare(4, 0),
22878 draw: function draw2(context, centerX, centerY, width, height) {
22879 this.renderer.nodeShapeImpl(this.name, context, centerX, centerY, width, height);
22880 },
22881 generateCutTrianglePts: function generateCutTrianglePts(width, height, centerX, centerY) {
22882 var cl = this.cornerLength;
22883 var hh = height / 2;
22884 var hw = width / 2;
22885 var xBegin = centerX - hw;
22886 var xEnd = centerX + hw;
22887 var yBegin = centerY - hh;
22888 var yEnd = centerY + hh;
22889 return {
22890 topLeft: [xBegin, yBegin + cl, xBegin + cl, yBegin, xBegin + cl, yBegin + cl],
22891 topRight: [xEnd - cl, yBegin, xEnd, yBegin + cl, xEnd - cl, yBegin + cl],
22892 bottomRight: [xEnd, yEnd - cl, xEnd - cl, yEnd, xEnd - cl, yEnd - cl],
22893 bottomLeft: [xBegin + cl, yEnd, xBegin, yEnd - cl, xBegin + cl, yEnd - cl]
22894 };
22895 },
22896 intersectLine: function intersectLine(nodeX, nodeY, width, height, x, y, padding) {
22897 var cPts = this.generateCutTrianglePts(width + 2 * padding, height + 2 * padding, nodeX, nodeY);
22898 var pts2 = [].concat.apply([], [cPts.topLeft.splice(0, 4), cPts.topRight.splice(0, 4), cPts.bottomRight.splice(0, 4), cPts.bottomLeft.splice(0, 4)]);
22899 return polygonIntersectLine(x, y, pts2, nodeX, nodeY);
22900 },
22901 checkPoint: function checkPoint(x, y, padding, width, height, centerX, centerY) {
22902 if (pointInsidePolygon(x, y, this.points, centerX, centerY, width, height - 2 * this.cornerLength, [0, -1], padding)) {
22903 return true;
22904 }
22905 if (pointInsidePolygon(x, y, this.points, centerX, centerY, width - 2 * this.cornerLength, height, [0, -1], padding)) {
22906 return true;
22907 }
22908 var cutTrianglePts = this.generateCutTrianglePts(width, height, centerX, centerY);
22909 return pointInsidePolygonPoints(x, y, cutTrianglePts.topLeft) || pointInsidePolygonPoints(x, y, cutTrianglePts.topRight) || pointInsidePolygonPoints(x, y, cutTrianglePts.bottomRight) || pointInsidePolygonPoints(x, y, cutTrianglePts.bottomLeft);
22910 }
22911 };
22912 };
22913 BRp$2.generateBarrel = function() {
22914 return this.nodeShapes["barrel"] = {
22915 renderer: this,
22916 name: "barrel",
22917 points: generateUnitNgonPointsFitToSquare(4, 0),
22918 draw: function draw2(context, centerX, centerY, width, height) {
22919 this.renderer.nodeShapeImpl(this.name, context, centerX, centerY, width, height);
22920 },
22921 intersectLine: function intersectLine(nodeX, nodeY, width, height, x, y, padding) {
22922 var t0 = 0.15;
22923 var t1 = 0.5;
22924 var t2 = 0.85;
22925 var bPts = this.generateBarrelBezierPts(width + 2 * padding, height + 2 * padding, nodeX, nodeY);
22926 var approximateBarrelCurvePts = function approximateBarrelCurvePts2(pts3) {
22927 var m0 = qbezierPtAt({
22928 x: pts3[0],
22929 y: pts3[1]
22930 }, {
22931 x: pts3[2],
22932 y: pts3[3]
22933 }, {
22934 x: pts3[4],
22935 y: pts3[5]
22936 }, t0);
22937 var m1 = qbezierPtAt({
22938 x: pts3[0],
22939 y: pts3[1]
22940 }, {
22941 x: pts3[2],
22942 y: pts3[3]
22943 }, {
22944 x: pts3[4],
22945 y: pts3[5]
22946 }, t1);
22947 var m2 = qbezierPtAt({
22948 x: pts3[0],
22949 y: pts3[1]
22950 }, {
22951 x: pts3[2],
22952 y: pts3[3]
22953 }, {
22954 x: pts3[4],
22955 y: pts3[5]
22956 }, t2);
22957 return [pts3[0], pts3[1], m0.x, m0.y, m1.x, m1.y, m2.x, m2.y, pts3[4], pts3[5]];
22958 };
22959 var pts2 = [].concat(approximateBarrelCurvePts(bPts.topLeft), approximateBarrelCurvePts(bPts.topRight), approximateBarrelCurvePts(bPts.bottomRight), approximateBarrelCurvePts(bPts.bottomLeft));
22960 return polygonIntersectLine(x, y, pts2, nodeX, nodeY);
22961 },
22962 generateBarrelBezierPts: function generateBarrelBezierPts(width, height, centerX, centerY) {
22963 var hh = height / 2;
22964 var hw = width / 2;
22965 var xBegin = centerX - hw;
22966 var xEnd = centerX + hw;
22967 var yBegin = centerY - hh;
22968 var yEnd = centerY + hh;
22969 var curveConstants = getBarrelCurveConstants(width, height);
22970 var hOffset = curveConstants.heightOffset;
22971 var wOffset = curveConstants.widthOffset;
22972 var ctrlPtXOffset = curveConstants.ctrlPtOffsetPct * width;
22973 var pts2 = {
22974 topLeft: [xBegin, yBegin + hOffset, xBegin + ctrlPtXOffset, yBegin, xBegin + wOffset, yBegin],
22975 topRight: [xEnd - wOffset, yBegin, xEnd - ctrlPtXOffset, yBegin, xEnd, yBegin + hOffset],
22976 bottomRight: [xEnd, yEnd - hOffset, xEnd - ctrlPtXOffset, yEnd, xEnd - wOffset, yEnd],
22977 bottomLeft: [xBegin + wOffset, yEnd, xBegin + ctrlPtXOffset, yEnd, xBegin, yEnd - hOffset]
22978 };
22979 pts2.topLeft.isTop = true;
22980 pts2.topRight.isTop = true;
22981 pts2.bottomLeft.isBottom = true;
22982 pts2.bottomRight.isBottom = true;
22983 return pts2;
22984 },
22985 checkPoint: function checkPoint(x, y, padding, width, height, centerX, centerY) {
22986 var curveConstants = getBarrelCurveConstants(width, height);
22987 var hOffset = curveConstants.heightOffset;
22988 var wOffset = curveConstants.widthOffset;
22989 if (pointInsidePolygon(x, y, this.points, centerX, centerY, width, height - 2 * hOffset, [0, -1], padding)) {
22990 return true;
22991 }
22992 if (pointInsidePolygon(x, y, this.points, centerX, centerY, width - 2 * wOffset, height, [0, -1], padding)) {
22993 return true;
22994 }
22995 var barrelCurvePts = this.generateBarrelBezierPts(width, height, centerX, centerY);
22996 var getCurveT = function getCurveT2(x2, y3, curvePts) {
22997 var x0 = curvePts[4];
22998 var x1 = curvePts[2];
22999 var x22 = curvePts[0];
23000 var y02 = curvePts[5];
23001 var y22 = curvePts[1];
23002 var xMin = Math.min(x0, x22);
23003 var xMax = Math.max(x0, x22);
23004 var yMin = Math.min(y02, y22);
23005 var yMax = Math.max(y02, y22);
23006 if (xMin <= x2 && x2 <= xMax && yMin <= y3 && y3 <= yMax) {
23007 var coeff = bezierPtsToQuadCoeff(x0, x1, x22);
23008 var roots = solveQuadratic(coeff[0], coeff[1], coeff[2], x2);
23009 var validRoots = roots.filter(function(r) {
23010 return 0 <= r && r <= 1;
23011 });
23012 if (validRoots.length > 0) {
23013 return validRoots[0];
23014 }
23015 }
23016 return null;
23017 };
23018 var curveRegions = Object.keys(barrelCurvePts);
23019 for (var i2 = 0; i2 < curveRegions.length; i2++) {
23020 var corner = curveRegions[i2];
23021 var cornerPts = barrelCurvePts[corner];
23022 var t = getCurveT(x, y, cornerPts);
23023 if (t == null) {
23024 continue;
23025 }
23026 var y0 = cornerPts[5];
23027 var y1 = cornerPts[3];
23028 var y2 = cornerPts[1];
23029 var bezY = qbezierAt(y0, y1, y2, t);
23030 if (cornerPts.isTop && bezY <= y) {
23031 return true;
23032 }
23033 if (cornerPts.isBottom && y <= bezY) {
23034 return true;
23035 }
23036 }
23037 return false;
23038 }
23039 };
23040 };
23041 BRp$2.generateBottomRoundrectangle = function() {
23042 return this.nodeShapes["bottom-round-rectangle"] = this.nodeShapes["bottomroundrectangle"] = {
23043 renderer: this,
23044 name: "bottom-round-rectangle",
23045 points: generateUnitNgonPointsFitToSquare(4, 0),
23046 draw: function draw2(context, centerX, centerY, width, height) {
23047 this.renderer.nodeShapeImpl(this.name, context, centerX, centerY, width, height);
23048 },
23049 intersectLine: function intersectLine(nodeX, nodeY, width, height, x, y, padding) {
23050 var topStartX = nodeX - (width / 2 + padding);
23051 var topStartY = nodeY - (height / 2 + padding);
23052 var topEndY = topStartY;
23053 var topEndX = nodeX + (width / 2 + padding);
23054 var topIntersections = finiteLinesIntersect(x, y, nodeX, nodeY, topStartX, topStartY, topEndX, topEndY, false);
23055 if (topIntersections.length > 0) {
23056 return topIntersections;
23057 }
23058 return roundRectangleIntersectLine(x, y, nodeX, nodeY, width, height, padding);
23059 },
23060 checkPoint: function checkPoint(x, y, padding, width, height, centerX, centerY) {
23061 var cornerRadius = getRoundRectangleRadius(width, height);
23062 var diam = 2 * cornerRadius;
23063 if (pointInsidePolygon(x, y, this.points, centerX, centerY, width, height - diam, [0, -1], padding)) {
23064 return true;
23065 }
23066 if (pointInsidePolygon(x, y, this.points, centerX, centerY, width - diam, height, [0, -1], padding)) {
23067 return true;
23068 }
23069 var outerWidth = width / 2 + 2 * padding;
23070 var outerHeight = height / 2 + 2 * padding;
23071 var points = [centerX - outerWidth, centerY - outerHeight, centerX - outerWidth, centerY, centerX + outerWidth, centerY, centerX + outerWidth, centerY - outerHeight];
23072 if (pointInsidePolygonPoints(x, y, points)) {
23073 return true;
23074 }
23075 if (checkInEllipse(x, y, diam, diam, centerX + width / 2 - cornerRadius, centerY + height / 2 - cornerRadius, padding)) {
23076 return true;
23077 }
23078 if (checkInEllipse(x, y, diam, diam, centerX - width / 2 + cornerRadius, centerY + height / 2 - cornerRadius, padding)) {
23079 return true;
23080 }
23081 return false;
23082 }
23083 };
23084 };
23085 BRp$2.registerNodeShapes = function() {
23086 var nodeShapes = this.nodeShapes = {};
23087 var renderer2 = this;
23088 this.generateEllipse();
23089 this.generatePolygon("triangle", generateUnitNgonPointsFitToSquare(3, 0));
23090 this.generateRoundPolygon("round-triangle", generateUnitNgonPointsFitToSquare(3, 0));
23091 this.generatePolygon("rectangle", generateUnitNgonPointsFitToSquare(4, 0));
23092 nodeShapes["square"] = nodeShapes["rectangle"];
23093 this.generateRoundRectangle();
23094 this.generateCutRectangle();
23095 this.generateBarrel();
23096 this.generateBottomRoundrectangle();
23097 {
23098 var diamondPoints = [0, 1, 1, 0, 0, -1, -1, 0];
23099 this.generatePolygon("diamond", diamondPoints);
23100 this.generateRoundPolygon("round-diamond", diamondPoints);
23101 }
23102 this.generatePolygon("pentagon", generateUnitNgonPointsFitToSquare(5, 0));
23103 this.generateRoundPolygon("round-pentagon", generateUnitNgonPointsFitToSquare(5, 0));
23104 this.generatePolygon("hexagon", generateUnitNgonPointsFitToSquare(6, 0));
23105 this.generateRoundPolygon("round-hexagon", generateUnitNgonPointsFitToSquare(6, 0));
23106 this.generatePolygon("heptagon", generateUnitNgonPointsFitToSquare(7, 0));
23107 this.generateRoundPolygon("round-heptagon", generateUnitNgonPointsFitToSquare(7, 0));
23108 this.generatePolygon("octagon", generateUnitNgonPointsFitToSquare(8, 0));
23109 this.generateRoundPolygon("round-octagon", generateUnitNgonPointsFitToSquare(8, 0));
23110 var star5Points = new Array(20);
23111 {
23112 var outerPoints = generateUnitNgonPoints(5, 0);
23113 var innerPoints = generateUnitNgonPoints(5, Math.PI / 5);
23114 var innerRadius = 0.5 * (3 - Math.sqrt(5));
23115 innerRadius *= 1.57;
23116 for (var i2 = 0; i2 < innerPoints.length / 2; i2++) {
23117 innerPoints[i2 * 2] *= innerRadius;
23118 innerPoints[i2 * 2 + 1] *= innerRadius;
23119 }
23120 for (var i2 = 0; i2 < 20 / 4; i2++) {
23121 star5Points[i2 * 4] = outerPoints[i2 * 2];
23122 star5Points[i2 * 4 + 1] = outerPoints[i2 * 2 + 1];
23123 star5Points[i2 * 4 + 2] = innerPoints[i2 * 2];
23124 star5Points[i2 * 4 + 3] = innerPoints[i2 * 2 + 1];
23125 }
23126 }
23127 star5Points = fitPolygonToSquare(star5Points);
23128 this.generatePolygon("star", star5Points);
23129 this.generatePolygon("vee", [-1, -1, 0, -0.333, 1, -1, 0, 1]);
23130 this.generatePolygon("rhomboid", [-1, -1, 0.333, -1, 1, 1, -0.333, 1]);
23131 this.nodeShapes["concavehexagon"] = this.generatePolygon("concave-hexagon", [-1, -0.95, -0.75, 0, -1, 0.95, 1, 0.95, 0.75, 0, 1, -0.95]);
23132 {
23133 var tagPoints = [-1, -1, 0.25, -1, 1, 0, 0.25, 1, -1, 1];
23134 this.generatePolygon("tag", tagPoints);
23135 this.generateRoundPolygon("round-tag", tagPoints);
23136 }
23137 nodeShapes.makePolygon = function(points) {
23138 var key = points.join("$");
23139 var name2 = "polygon-" + key;
23140 var shape;
23141 if (shape = this[name2]) {
23142 return shape;
23143 }
23144 return renderer2.generatePolygon(name2, points);
23145 };
23146 };
23147 var BRp$1 = {};
23148 BRp$1.timeToRender = function() {
23149 return this.redrawTotalTime / this.redrawCount;
23150 };
23151 BRp$1.redraw = function(options) {
23152 options = options || staticEmptyObject();
23153 var r = this;
23154 if (r.averageRedrawTime === void 0) {
23155 r.averageRedrawTime = 0;
23156 }
23157 if (r.lastRedrawTime === void 0) {
23158 r.lastRedrawTime = 0;
23159 }
23160 if (r.lastDrawTime === void 0) {
23161 r.lastDrawTime = 0;
23162 }
23163 r.requestedFrame = true;
23164 r.renderOptions = options;
23165 };
23166 BRp$1.beforeRender = function(fn2, priority) {
23167 if (this.destroyed) {
23168 return;
23169 }
23170 if (priority == null) {
23171 error("Priority is not optional for beforeRender");
23172 }
23173 var cbs = this.beforeRenderCallbacks;
23174 cbs.push({
23175 fn: fn2,
23176 priority
23177 });
23178 cbs.sort(function(a, b) {
23179 return b.priority - a.priority;
23180 });
23181 };
23182 var beforeRenderCallbacks = function beforeRenderCallbacks2(r, willDraw, startTime) {
23183 var cbs = r.beforeRenderCallbacks;
23184 for (var i2 = 0; i2 < cbs.length; i2++) {
23185 cbs[i2].fn(willDraw, startTime);
23186 }
23187 };
23188 BRp$1.startRenderLoop = function() {
23189 var r = this;
23190 var cy = r.cy;
23191 if (r.renderLoopStarted) {
23192 return;
23193 } else {
23194 r.renderLoopStarted = true;
23195 }
23196 var renderFn = function renderFn2(requestTime) {
23197 if (r.destroyed) {
23198 return;
23199 }
23200 if (cy.batching())
23201 ;
23202 else if (r.requestedFrame && !r.skipFrame) {
23203 beforeRenderCallbacks(r, true, requestTime);
23204 var startTime = performanceNow();
23205 r.render(r.renderOptions);
23206 var endTime = r.lastDrawTime = performanceNow();
23207 if (r.averageRedrawTime === void 0) {
23208 r.averageRedrawTime = endTime - startTime;
23209 }
23210 if (r.redrawCount === void 0) {
23211 r.redrawCount = 0;
23212 }
23213 r.redrawCount++;
23214 if (r.redrawTotalTime === void 0) {
23215 r.redrawTotalTime = 0;
23216 }
23217 var duration = endTime - startTime;
23218 r.redrawTotalTime += duration;
23219 r.lastRedrawTime = duration;
23220 r.averageRedrawTime = r.averageRedrawTime / 2 + duration / 2;
23221 r.requestedFrame = false;
23222 } else {
23223 beforeRenderCallbacks(r, false, requestTime);
23224 }
23225 r.skipFrame = false;
23226 requestAnimationFrame2(renderFn2);
23227 };
23228 requestAnimationFrame2(renderFn);
23229 };
23230 var BaseRenderer = function BaseRenderer2(options) {
23231 this.init(options);
23232 };
23233 var BR = BaseRenderer;
23234 var BRp = BR.prototype;
23235 BRp.clientFunctions = ["redrawHint", "render", "renderTo", "matchCanvasSize", "nodeShapeImpl", "arrowShapeImpl"];
23236 BRp.init = function(options) {
23237 var r = this;
23238 r.options = options;
23239 r.cy = options.cy;
23240 var ctr = r.container = options.cy.container();
23241 if (window$1) {
23242 var document2 = window$1.document;
23243 var head = document2.head;
23244 var stylesheetId = "__________cytoscape_stylesheet";
23245 var className = "__________cytoscape_container";
23246 var stylesheetAlreadyExists = document2.getElementById(stylesheetId) != null;
23247 if (ctr.className.indexOf(className) < 0) {
23248 ctr.className = (ctr.className || "") + " " + className;
23249 }
23250 if (!stylesheetAlreadyExists) {
23251 var stylesheet2 = document2.createElement("style");
23252 stylesheet2.id = stylesheetId;
23253 stylesheet2.innerHTML = "." + className + " { position: relative; }";
23254 head.insertBefore(stylesheet2, head.children[0]);
23255 }
23256 var computedStyle = window$1.getComputedStyle(ctr);
23257 var position2 = computedStyle.getPropertyValue("position");
23258 if (position2 === "static") {
23259 warn("A Cytoscape container has style position:static and so can not use UI extensions properly");
23260 }
23261 }
23262 r.selection = [void 0, void 0, void 0, void 0, 0];
23263 r.bezierProjPcts = [0.05, 0.225, 0.4, 0.5, 0.6, 0.775, 0.95];
23264 r.hoverData = {
23265 down: null,
23266 last: null,
23267 downTime: null,
23268 triggerMode: null,
23269 dragging: false,
23270 initialPan: [null, null],
23271 capture: false
23272 };
23273 r.dragData = {
23274 possibleDragElements: []
23275 };
23276 r.touchData = {
23277 start: null,
23278 capture: false,
23279 // These 3 fields related to tap, taphold events
23280 startPosition: [null, null, null, null, null, null],
23281 singleTouchStartTime: null,
23282 singleTouchMoved: true,
23283 now: [null, null, null, null, null, null],
23284 earlier: [null, null, null, null, null, null]
23285 };
23286 r.redraws = 0;
23287 r.showFps = options.showFps;
23288 r.debug = options.debug;
23289 r.hideEdgesOnViewport = options.hideEdgesOnViewport;
23290 r.textureOnViewport = options.textureOnViewport;
23291 r.wheelSensitivity = options.wheelSensitivity;
23292 r.motionBlurEnabled = options.motionBlur;
23293 r.forcedPixelRatio = number$1(options.pixelRatio) ? options.pixelRatio : null;
23294 r.motionBlur = options.motionBlur;
23295 r.motionBlurOpacity = options.motionBlurOpacity;
23296 r.motionBlurTransparency = 1 - r.motionBlurOpacity;
23297 r.motionBlurPxRatio = 1;
23298 r.mbPxRBlurry = 1;
23299 r.minMbLowQualFrames = 4;
23300 r.fullQualityMb = false;
23301 r.clearedForMotionBlur = [];
23302 r.desktopTapThreshold = options.desktopTapThreshold;
23303 r.desktopTapThreshold2 = options.desktopTapThreshold * options.desktopTapThreshold;
23304 r.touchTapThreshold = options.touchTapThreshold;
23305 r.touchTapThreshold2 = options.touchTapThreshold * options.touchTapThreshold;
23306 r.tapholdDuration = 500;
23307 r.bindings = [];
23308 r.beforeRenderCallbacks = [];
23309 r.beforeRenderPriorities = {
23310 // higher priority execs before lower one
23311 animations: 400,
23312 eleCalcs: 300,
23313 eleTxrDeq: 200,
23314 lyrTxrDeq: 150,
23315 lyrTxrSkip: 100
23316 };
23317 r.registerNodeShapes();
23318 r.registerArrowShapes();
23319 r.registerCalculationListeners();
23320 };
23321 BRp.notify = function(eventName, eles) {
23322 var r = this;
23323 var cy = r.cy;
23324 if (this.destroyed) {
23325 return;
23326 }
23327 if (eventName === "init") {
23328 r.load();
23329 return;
23330 }
23331 if (eventName === "destroy") {
23332 r.destroy();
23333 return;
23334 }
23335 if (eventName === "add" || eventName === "remove" || eventName === "move" && cy.hasCompoundNodes() || eventName === "load" || eventName === "zorder" || eventName === "mount") {
23336 r.invalidateCachedZSortedEles();
23337 }
23338 if (eventName === "viewport") {
23339 r.redrawHint("select", true);
23340 }
23341 if (eventName === "load" || eventName === "resize" || eventName === "mount") {
23342 r.invalidateContainerClientCoordsCache();
23343 r.matchCanvasSize(r.container);
23344 }
23345 r.redrawHint("eles", true);
23346 r.redrawHint("drag", true);
23347 this.startRenderLoop();
23348 this.redraw();
23349 };
23350 BRp.destroy = function() {
23351 var r = this;
23352 r.destroyed = true;
23353 r.cy.stopAnimationLoop();
23354 for (var i2 = 0; i2 < r.bindings.length; i2++) {
23355 var binding = r.bindings[i2];
23356 var b = binding;
23357 var tgt = b.target;
23358 (tgt.off || tgt.removeEventListener).apply(tgt, b.args);
23359 }
23360 r.bindings = [];
23361 r.beforeRenderCallbacks = [];
23362 r.onUpdateEleCalcsFns = [];
23363 if (r.removeObserver) {
23364 r.removeObserver.disconnect();
23365 }
23366 if (r.styleObserver) {
23367 r.styleObserver.disconnect();
23368 }
23369 if (r.resizeObserver) {
23370 r.resizeObserver.disconnect();
23371 }
23372 if (r.labelCalcDiv) {
23373 try {
23374 document.body.removeChild(r.labelCalcDiv);
23375 } catch (e) {
23376 }
23377 }
23378 };
23379 BRp.isHeadless = function() {
23380 return false;
23381 };
23382 [BRp$f, BRp$5, BRp$4, BRp$3, BRp$2, BRp$1].forEach(function(props) {
23383 extend(BRp, props);
23384 });
23385 var fullFpsTime = 1e3 / 60;
23386 var defs = {
23387 setupDequeueing: function setupDequeueing(opts) {
23388 return function setupDequeueingImpl() {
23389 var self2 = this;
23390 var r = this.renderer;
23391 if (self2.dequeueingSetup) {
23392 return;
23393 } else {
23394 self2.dequeueingSetup = true;
23395 }
23396 var queueRedraw = debounce_1(function() {
23397 r.redrawHint("eles", true);
23398 r.redrawHint("drag", true);
23399 r.redraw();
23400 }, opts.deqRedrawThreshold);
23401 var dequeue = function dequeue2(willDraw, frameStartTime) {
23402 var startTime = performanceNow();
23403 var avgRenderTime = r.averageRedrawTime;
23404 var renderTime = r.lastRedrawTime;
23405 var deqd = [];
23406 var extent = r.cy.extent();
23407 var pixelRatio = r.getPixelRatio();
23408 if (!willDraw) {
23409 r.flushRenderedStyleQueue();
23410 }
23411 while (true) {
23412 var now2 = performanceNow();
23413 var duration = now2 - startTime;
23414 var frameDuration = now2 - frameStartTime;
23415 if (renderTime < fullFpsTime) {
23416 var timeAvailable = fullFpsTime - (willDraw ? avgRenderTime : 0);
23417 if (frameDuration >= opts.deqFastCost * timeAvailable) {
23418 break;
23419 }
23420 } else {
23421 if (willDraw) {
23422 if (duration >= opts.deqCost * renderTime || duration >= opts.deqAvgCost * avgRenderTime) {
23423 break;
23424 }
23425 } else if (frameDuration >= opts.deqNoDrawCost * fullFpsTime) {
23426 break;
23427 }
23428 }
23429 var thisDeqd = opts.deq(self2, pixelRatio, extent);
23430 if (thisDeqd.length > 0) {
23431 for (var i2 = 0; i2 < thisDeqd.length; i2++) {
23432 deqd.push(thisDeqd[i2]);
23433 }
23434 } else {
23435 break;
23436 }
23437 }
23438 if (deqd.length > 0) {
23439 opts.onDeqd(self2, deqd);
23440 if (!willDraw && opts.shouldRedraw(self2, deqd, pixelRatio, extent)) {
23441 queueRedraw();
23442 }
23443 }
23444 };
23445 var priority = opts.priority || noop$1;
23446 r.beforeRender(dequeue, priority(self2));
23447 };
23448 }
23449 };
23450 var ElementTextureCacheLookup = /* @__PURE__ */ function() {
23451 function ElementTextureCacheLookup2(getKey2) {
23452 var doesEleInvalidateKey = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : falsify;
23453 _classCallCheck(this, ElementTextureCacheLookup2);
23454 this.idsByKey = new Map$2();
23455 this.keyForId = new Map$2();
23456 this.cachesByLvl = new Map$2();
23457 this.lvls = [];
23458 this.getKey = getKey2;
23459 this.doesEleInvalidateKey = doesEleInvalidateKey;
23460 }
23461 _createClass(ElementTextureCacheLookup2, [{
23462 key: "getIdsFor",
23463 value: function getIdsFor(key) {
23464 if (key == null) {
23465 error("Can not get id list for null key");
23466 }
23467 var idsByKey = this.idsByKey;
23468 var ids = this.idsByKey.get(key);
23469 if (!ids) {
23470 ids = new Set$1();
23471 idsByKey.set(key, ids);
23472 }
23473 return ids;
23474 }
23475 }, {
23476 key: "addIdForKey",
23477 value: function addIdForKey(key, id) {
23478 if (key != null) {
23479 this.getIdsFor(key).add(id);
23480 }
23481 }
23482 }, {
23483 key: "deleteIdForKey",
23484 value: function deleteIdForKey(key, id) {
23485 if (key != null) {
23486 this.getIdsFor(key)["delete"](id);
23487 }
23488 }
23489 }, {
23490 key: "getNumberOfIdsForKey",
23491 value: function getNumberOfIdsForKey(key) {
23492 if (key == null) {
23493 return 0;
23494 } else {
23495 return this.getIdsFor(key).size;
23496 }
23497 }
23498 }, {
23499 key: "updateKeyMappingFor",
23500 value: function updateKeyMappingFor(ele) {
23501 var id = ele.id();
23502 var prevKey = this.keyForId.get(id);
23503 var currKey = this.getKey(ele);
23504 this.deleteIdForKey(prevKey, id);
23505 this.addIdForKey(currKey, id);
23506 this.keyForId.set(id, currKey);
23507 }
23508 }, {
23509 key: "deleteKeyMappingFor",
23510 value: function deleteKeyMappingFor(ele) {
23511 var id = ele.id();
23512 var prevKey = this.keyForId.get(id);
23513 this.deleteIdForKey(prevKey, id);
23514 this.keyForId["delete"](id);
23515 }
23516 }, {
23517 key: "keyHasChangedFor",
23518 value: function keyHasChangedFor(ele) {
23519 var id = ele.id();
23520 var prevKey = this.keyForId.get(id);
23521 var newKey = this.getKey(ele);
23522 return prevKey !== newKey;
23523 }
23524 }, {
23525 key: "isInvalid",
23526 value: function isInvalid(ele) {
23527 return this.keyHasChangedFor(ele) || this.doesEleInvalidateKey(ele);
23528 }
23529 }, {
23530 key: "getCachesAt",
23531 value: function getCachesAt(lvl) {
23532 var cachesByLvl = this.cachesByLvl, lvls = this.lvls;
23533 var caches = cachesByLvl.get(lvl);
23534 if (!caches) {
23535 caches = new Map$2();
23536 cachesByLvl.set(lvl, caches);
23537 lvls.push(lvl);
23538 }
23539 return caches;
23540 }
23541 }, {
23542 key: "getCache",
23543 value: function getCache(key, lvl) {
23544 return this.getCachesAt(lvl).get(key);
23545 }
23546 }, {
23547 key: "get",
23548 value: function get2(ele, lvl) {
23549 var key = this.getKey(ele);
23550 var cache2 = this.getCache(key, lvl);
23551 if (cache2 != null) {
23552 this.updateKeyMappingFor(ele);
23553 }
23554 return cache2;
23555 }
23556 }, {
23557 key: "getForCachedKey",
23558 value: function getForCachedKey(ele, lvl) {
23559 var key = this.keyForId.get(ele.id());
23560 var cache2 = this.getCache(key, lvl);
23561 return cache2;
23562 }
23563 }, {
23564 key: "hasCache",
23565 value: function hasCache(key, lvl) {
23566 return this.getCachesAt(lvl).has(key);
23567 }
23568 }, {
23569 key: "has",
23570 value: function has(ele, lvl) {
23571 var key = this.getKey(ele);
23572 return this.hasCache(key, lvl);
23573 }
23574 }, {
23575 key: "setCache",
23576 value: function setCache(key, lvl, cache2) {
23577 cache2.key = key;
23578 this.getCachesAt(lvl).set(key, cache2);
23579 }
23580 }, {
23581 key: "set",
23582 value: function set2(ele, lvl, cache2) {
23583 var key = this.getKey(ele);
23584 this.setCache(key, lvl, cache2);
23585 this.updateKeyMappingFor(ele);
23586 }
23587 }, {
23588 key: "deleteCache",
23589 value: function deleteCache(key, lvl) {
23590 this.getCachesAt(lvl)["delete"](key);
23591 }
23592 }, {
23593 key: "delete",
23594 value: function _delete(ele, lvl) {
23595 var key = this.getKey(ele);
23596 this.deleteCache(key, lvl);
23597 }
23598 }, {
23599 key: "invalidateKey",
23600 value: function invalidateKey(key) {
23601 var _this = this;
23602 this.lvls.forEach(function(lvl) {
23603 return _this.deleteCache(key, lvl);
23604 });
23605 }
23606 // returns true if no other eles reference the invalidated cache (n.b. other eles may need the cache with the same key)
23607 }, {
23608 key: "invalidate",
23609 value: function invalidate(ele) {
23610 var id = ele.id();
23611 var key = this.keyForId.get(id);
23612 this.deleteKeyMappingFor(ele);
23613 var entireKeyInvalidated = this.doesEleInvalidateKey(ele);
23614 if (entireKeyInvalidated) {
23615 this.invalidateKey(key);
23616 }
23617 return entireKeyInvalidated || this.getNumberOfIdsForKey(key) === 0;
23618 }
23619 }]);
23620 return ElementTextureCacheLookup2;
23621 }();
23622 var minTxrH = 25;
23623 var txrStepH = 50;
23624 var minLvl$1 = -4;
23625 var maxLvl$1 = 3;
23626 var maxZoom$1 = 7.99;
23627 var eleTxrSpacing = 8;
23628 var defTxrWidth = 1024;
23629 var maxTxrW = 1024;
23630 var maxTxrH = 1024;
23631 var minUtility = 0.2;
23632 var maxFullness = 0.8;
23633 var maxFullnessChecks = 10;
23634 var deqCost$1 = 0.15;
23635 var deqAvgCost$1 = 0.1;
23636 var deqNoDrawCost$1 = 0.9;
23637 var deqFastCost$1 = 0.9;
23638 var deqRedrawThreshold$1 = 100;
23639 var maxDeqSize$1 = 1;
23640 var getTxrReasons = {
23641 dequeue: "dequeue",
23642 downscale: "downscale",
23643 highQuality: "highQuality"
23644 };
23645 var initDefaults = defaults$g({
23646 getKey: null,
23647 doesEleInvalidateKey: falsify,
23648 drawElement: null,
23649 getBoundingBox: null,
23650 getRotationPoint: null,
23651 getRotationOffset: null,
23652 isVisible: trueify,
23653 allowEdgeTxrCaching: true,
23654 allowParentTxrCaching: true
23655 });
23656 var ElementTextureCache = function ElementTextureCache2(renderer2, initOptions) {
23657 var self2 = this;
23658 self2.renderer = renderer2;
23659 self2.onDequeues = [];
23660 var opts = initDefaults(initOptions);
23661 extend(self2, opts);
23662 self2.lookup = new ElementTextureCacheLookup(opts.getKey, opts.doesEleInvalidateKey);
23663 self2.setupDequeueing();
23664 };
23665 var ETCp = ElementTextureCache.prototype;
23666 ETCp.reasons = getTxrReasons;
23667 ETCp.getTextureQueue = function(txrH) {
23668 var self2 = this;
23669 self2.eleImgCaches = self2.eleImgCaches || {};
23670 return self2.eleImgCaches[txrH] = self2.eleImgCaches[txrH] || [];
23671 };
23672 ETCp.getRetiredTextureQueue = function(txrH) {
23673 var self2 = this;
23674 var rtxtrQs = self2.eleImgCaches.retired = self2.eleImgCaches.retired || {};
23675 var rtxtrQ = rtxtrQs[txrH] = rtxtrQs[txrH] || [];
23676 return rtxtrQ;
23677 };
23678 ETCp.getElementQueue = function() {
23679 var self2 = this;
23680 var q = self2.eleCacheQueue = self2.eleCacheQueue || new heap(function(a, b) {
23681 return b.reqs - a.reqs;
23682 });
23683 return q;
23684 };
23685 ETCp.getElementKeyToQueue = function() {
23686 var self2 = this;
23687 var k2q = self2.eleKeyToCacheQueue = self2.eleKeyToCacheQueue || {};
23688 return k2q;
23689 };
23690 ETCp.getElement = function(ele, bb, pxRatio, lvl, reason) {
23691 var self2 = this;
23692 var r = this.renderer;
23693 var zoom = r.cy.zoom();
23694 var lookup2 = this.lookup;
23695 if (!bb || bb.w === 0 || bb.h === 0 || isNaN(bb.w) || isNaN(bb.h) || !ele.visible() || ele.removed()) {
23696 return null;
23697 }
23698 if (!self2.allowEdgeTxrCaching && ele.isEdge() || !self2.allowParentTxrCaching && ele.isParent()) {
23699 return null;
23700 }
23701 if (lvl == null) {
23702 lvl = Math.ceil(log2(zoom * pxRatio));
23703 }
23704 if (lvl < minLvl$1) {
23705 lvl = minLvl$1;
23706 } else if (zoom >= maxZoom$1 || lvl > maxLvl$1) {
23707 return null;
23708 }
23709 var scale = Math.pow(2, lvl);
23710 var eleScaledH = bb.h * scale;
23711 var eleScaledW = bb.w * scale;
23712 var scaledLabelShown = r.eleTextBiggerThanMin(ele, scale);
23713 if (!this.isVisible(ele, scaledLabelShown)) {
23714 return null;
23715 }
23716 var eleCache = lookup2.get(ele, lvl);
23717 if (eleCache && eleCache.invalidated) {
23718 eleCache.invalidated = false;
23719 eleCache.texture.invalidatedWidth -= eleCache.width;
23720 }
23721 if (eleCache) {
23722 return eleCache;
23723 }
23724 var txrH;
23725 if (eleScaledH <= minTxrH) {
23726 txrH = minTxrH;
23727 } else if (eleScaledH <= txrStepH) {
23728 txrH = txrStepH;
23729 } else {
23730 txrH = Math.ceil(eleScaledH / txrStepH) * txrStepH;
23731 }
23732 if (eleScaledH > maxTxrH || eleScaledW > maxTxrW) {
23733 return null;
23734 }
23735 var txrQ = self2.getTextureQueue(txrH);
23736 var txr = txrQ[txrQ.length - 2];
23737 var addNewTxr = function addNewTxr2() {
23738 return self2.recycleTexture(txrH, eleScaledW) || self2.addTexture(txrH, eleScaledW);
23739 };
23740 if (!txr) {
23741 txr = txrQ[txrQ.length - 1];
23742 }
23743 if (!txr) {
23744 txr = addNewTxr();
23745 }
23746 if (txr.width - txr.usedWidth < eleScaledW) {
23747 txr = addNewTxr();
23748 }
23749 var scalableFrom = function scalableFrom2(otherCache) {
23750 return otherCache && otherCache.scaledLabelShown === scaledLabelShown;
23751 };
23752 var deqing = reason && reason === getTxrReasons.dequeue;
23753 var highQualityReq = reason && reason === getTxrReasons.highQuality;
23754 var downscaleReq = reason && reason === getTxrReasons.downscale;
23755 var higherCache;
23756 for (var l = lvl + 1; l <= maxLvl$1; l++) {
23757 var c = lookup2.get(ele, l);
23758 if (c) {
23759 higherCache = c;
23760 break;
23761 }
23762 }
23763 var oneUpCache = higherCache && higherCache.level === lvl + 1 ? higherCache : null;
23764 var downscale = function downscale2() {
23765 txr.context.drawImage(oneUpCache.texture.canvas, oneUpCache.x, 0, oneUpCache.width, oneUpCache.height, txr.usedWidth, 0, eleScaledW, eleScaledH);
23766 };
23767 txr.context.setTransform(1, 0, 0, 1, 0, 0);
23768 txr.context.clearRect(txr.usedWidth, 0, eleScaledW, txrH);
23769 if (scalableFrom(oneUpCache)) {
23770 downscale();
23771 } else if (scalableFrom(higherCache)) {
23772 if (highQualityReq) {
23773 for (var _l = higherCache.level; _l > lvl; _l--) {
23774 oneUpCache = self2.getElement(ele, bb, pxRatio, _l, getTxrReasons.downscale);
23775 }
23776 downscale();
23777 } else {
23778 self2.queueElement(ele, higherCache.level - 1);
23779 return higherCache;
23780 }
23781 } else {
23782 var lowerCache;
23783 if (!deqing && !highQualityReq && !downscaleReq) {
23784 for (var _l2 = lvl - 1; _l2 >= minLvl$1; _l2--) {
23785 var _c = lookup2.get(ele, _l2);
23786 if (_c) {
23787 lowerCache = _c;
23788 break;
23789 }
23790 }
23791 }
23792 if (scalableFrom(lowerCache)) {
23793 self2.queueElement(ele, lvl);
23794 return lowerCache;
23795 }
23796 txr.context.translate(txr.usedWidth, 0);
23797 txr.context.scale(scale, scale);
23798 this.drawElement(txr.context, ele, bb, scaledLabelShown, false);
23799 txr.context.scale(1 / scale, 1 / scale);
23800 txr.context.translate(-txr.usedWidth, 0);
23801 }
23802 eleCache = {
23803 x: txr.usedWidth,
23804 texture: txr,
23805 level: lvl,
23806 scale,
23807 width: eleScaledW,
23808 height: eleScaledH,
23809 scaledLabelShown
23810 };
23811 txr.usedWidth += Math.ceil(eleScaledW + eleTxrSpacing);
23812 txr.eleCaches.push(eleCache);
23813 lookup2.set(ele, lvl, eleCache);
23814 self2.checkTextureFullness(txr);
23815 return eleCache;
23816 };
23817 ETCp.invalidateElements = function(eles) {
23818 for (var i2 = 0; i2 < eles.length; i2++) {
23819 this.invalidateElement(eles[i2]);
23820 }
23821 };
23822 ETCp.invalidateElement = function(ele) {
23823 var self2 = this;
23824 var lookup2 = self2.lookup;
23825 var caches = [];
23826 var invalid = lookup2.isInvalid(ele);
23827 if (!invalid) {
23828 return;
23829 }
23830 for (var lvl = minLvl$1; lvl <= maxLvl$1; lvl++) {
23831 var cache2 = lookup2.getForCachedKey(ele, lvl);
23832 if (cache2) {
23833 caches.push(cache2);
23834 }
23835 }
23836 var noOtherElesUseCache = lookup2.invalidate(ele);
23837 if (noOtherElesUseCache) {
23838 for (var i2 = 0; i2 < caches.length; i2++) {
23839 var _cache = caches[i2];
23840 var txr = _cache.texture;
23841 txr.invalidatedWidth += _cache.width;
23842 _cache.invalidated = true;
23843 self2.checkTextureUtility(txr);
23844 }
23845 }
23846 self2.removeFromQueue(ele);
23847 };
23848 ETCp.checkTextureUtility = function(txr) {
23849 if (txr.invalidatedWidth >= minUtility * txr.width) {
23850 this.retireTexture(txr);
23851 }
23852 };
23853 ETCp.checkTextureFullness = function(txr) {
23854 var self2 = this;
23855 var txrQ = self2.getTextureQueue(txr.height);
23856 if (txr.usedWidth / txr.width > maxFullness && txr.fullnessChecks >= maxFullnessChecks) {
23857 removeFromArray(txrQ, txr);
23858 } else {
23859 txr.fullnessChecks++;
23860 }
23861 };
23862 ETCp.retireTexture = function(txr) {
23863 var self2 = this;
23864 var txrH = txr.height;
23865 var txrQ = self2.getTextureQueue(txrH);
23866 var lookup2 = this.lookup;
23867 removeFromArray(txrQ, txr);
23868 txr.retired = true;
23869 var eleCaches = txr.eleCaches;
23870 for (var i2 = 0; i2 < eleCaches.length; i2++) {
23871 var eleCache = eleCaches[i2];
23872 lookup2.deleteCache(eleCache.key, eleCache.level);
23873 }
23874 clearArray(eleCaches);
23875 var rtxtrQ = self2.getRetiredTextureQueue(txrH);
23876 rtxtrQ.push(txr);
23877 };
23878 ETCp.addTexture = function(txrH, minW) {
23879 var self2 = this;
23880 var txrQ = self2.getTextureQueue(txrH);
23881 var txr = {};
23882 txrQ.push(txr);
23883 txr.eleCaches = [];
23884 txr.height = txrH;
23885 txr.width = Math.max(defTxrWidth, minW);
23886 txr.usedWidth = 0;
23887 txr.invalidatedWidth = 0;
23888 txr.fullnessChecks = 0;
23889 txr.canvas = self2.renderer.makeOffscreenCanvas(txr.width, txr.height);
23890 txr.context = txr.canvas.getContext("2d");
23891 return txr;
23892 };
23893 ETCp.recycleTexture = function(txrH, minW) {
23894 var self2 = this;
23895 var txrQ = self2.getTextureQueue(txrH);
23896 var rtxtrQ = self2.getRetiredTextureQueue(txrH);
23897 for (var i2 = 0; i2 < rtxtrQ.length; i2++) {
23898 var txr = rtxtrQ[i2];
23899 if (txr.width >= minW) {
23900 txr.retired = false;
23901 txr.usedWidth = 0;
23902 txr.invalidatedWidth = 0;
23903 txr.fullnessChecks = 0;
23904 clearArray(txr.eleCaches);
23905 txr.context.setTransform(1, 0, 0, 1, 0, 0);
23906 txr.context.clearRect(0, 0, txr.width, txr.height);
23907 removeFromArray(rtxtrQ, txr);
23908 txrQ.push(txr);
23909 return txr;
23910 }
23911 }
23912 };
23913 ETCp.queueElement = function(ele, lvl) {
23914 var self2 = this;
23915 var q = self2.getElementQueue();
23916 var k2q = self2.getElementKeyToQueue();
23917 var key = this.getKey(ele);
23918 var existingReq = k2q[key];
23919 if (existingReq) {
23920 existingReq.level = Math.max(existingReq.level, lvl);
23921 existingReq.eles.merge(ele);
23922 existingReq.reqs++;
23923 q.updateItem(existingReq);
23924 } else {
23925 var req = {
23926 eles: ele.spawn().merge(ele),
23927 level: lvl,
23928 reqs: 1,
23929 key
23930 };
23931 q.push(req);
23932 k2q[key] = req;
23933 }
23934 };
23935 ETCp.dequeue = function(pxRatio) {
23936 var self2 = this;
23937 var q = self2.getElementQueue();
23938 var k2q = self2.getElementKeyToQueue();
23939 var dequeued = [];
23940 var lookup2 = self2.lookup;
23941 for (var i2 = 0; i2 < maxDeqSize$1; i2++) {
23942 if (q.size() > 0) {
23943 var req = q.pop();
23944 var key = req.key;
23945 var ele = req.eles[0];
23946 var cacheExists = lookup2.hasCache(ele, req.level);
23947 k2q[key] = null;
23948 if (cacheExists) {
23949 continue;
23950 }
23951 dequeued.push(req);
23952 var bb = self2.getBoundingBox(ele);
23953 self2.getElement(ele, bb, pxRatio, req.level, getTxrReasons.dequeue);
23954 } else {
23955 break;
23956 }
23957 }
23958 return dequeued;
23959 };
23960 ETCp.removeFromQueue = function(ele) {
23961 var self2 = this;
23962 var q = self2.getElementQueue();
23963 var k2q = self2.getElementKeyToQueue();
23964 var key = this.getKey(ele);
23965 var req = k2q[key];
23966 if (req != null) {
23967 if (req.eles.length === 1) {
23968 req.reqs = MAX_INT$1;
23969 q.updateItem(req);
23970 q.pop();
23971 k2q[key] = null;
23972 } else {
23973 req.eles.unmerge(ele);
23974 }
23975 }
23976 };
23977 ETCp.onDequeue = function(fn2) {
23978 this.onDequeues.push(fn2);
23979 };
23980 ETCp.offDequeue = function(fn2) {
23981 removeFromArray(this.onDequeues, fn2);
23982 };
23983 ETCp.setupDequeueing = defs.setupDequeueing({
23984 deqRedrawThreshold: deqRedrawThreshold$1,
23985 deqCost: deqCost$1,
23986 deqAvgCost: deqAvgCost$1,
23987 deqNoDrawCost: deqNoDrawCost$1,
23988 deqFastCost: deqFastCost$1,
23989 deq: function deq(self2, pxRatio, extent) {
23990 return self2.dequeue(pxRatio, extent);
23991 },
23992 onDeqd: function onDeqd(self2, deqd) {
23993 for (var i2 = 0; i2 < self2.onDequeues.length; i2++) {
23994 var fn2 = self2.onDequeues[i2];
23995 fn2(deqd);
23996 }
23997 },
23998 shouldRedraw: function shouldRedraw(self2, deqd, pxRatio, extent) {
23999 for (var i2 = 0; i2 < deqd.length; i2++) {
24000 var eles = deqd[i2].eles;
24001 for (var j = 0; j < eles.length; j++) {
24002 var bb = eles[j].boundingBox();
24003 if (boundingBoxesIntersect(bb, extent)) {
24004 return true;
24005 }
24006 }
24007 }
24008 return false;
24009 },
24010 priority: function priority(self2) {
24011 return self2.renderer.beforeRenderPriorities.eleTxrDeq;
24012 }
24013 });
24014 var defNumLayers = 1;
24015 var minLvl = -4;
24016 var maxLvl = 2;
24017 var maxZoom = 3.99;
24018 var deqRedrawThreshold = 50;
24019 var refineEleDebounceTime = 50;
24020 var deqCost = 0.15;
24021 var deqAvgCost = 0.1;
24022 var deqNoDrawCost = 0.9;
24023 var deqFastCost = 0.9;
24024 var maxDeqSize = 1;
24025 var invalidThreshold = 250;
24026 var maxLayerArea = 4e3 * 4e3;
24027 var useHighQualityEleTxrReqs = true;
24028 var LayeredTextureCache = function LayeredTextureCache2(renderer2) {
24029 var self2 = this;
24030 var r = self2.renderer = renderer2;
24031 var cy = r.cy;
24032 self2.layersByLevel = {};
24033 self2.firstGet = true;
24034 self2.lastInvalidationTime = performanceNow() - 2 * invalidThreshold;
24035 self2.skipping = false;
24036 self2.eleTxrDeqs = cy.collection();
24037 self2.scheduleElementRefinement = debounce_1(function() {
24038 self2.refineElementTextures(self2.eleTxrDeqs);
24039 self2.eleTxrDeqs.unmerge(self2.eleTxrDeqs);
24040 }, refineEleDebounceTime);
24041 r.beforeRender(function(willDraw, now2) {
24042 if (now2 - self2.lastInvalidationTime <= invalidThreshold) {
24043 self2.skipping = true;
24044 } else {
24045 self2.skipping = false;
24046 }
24047 }, r.beforeRenderPriorities.lyrTxrSkip);
24048 var qSort = function qSort2(a, b) {
24049 return b.reqs - a.reqs;
24050 };
24051 self2.layersQueue = new heap(qSort);
24052 self2.setupDequeueing();
24053 };
24054 var LTCp = LayeredTextureCache.prototype;
24055 var layerIdPool = 0;
24056 var MAX_INT = Math.pow(2, 53) - 1;
24057 LTCp.makeLayer = function(bb, lvl) {
24058 var scale = Math.pow(2, lvl);
24059 var w = Math.ceil(bb.w * scale);
24060 var h = Math.ceil(bb.h * scale);
24061 var canvas = this.renderer.makeOffscreenCanvas(w, h);
24062 var layer = {
24063 id: layerIdPool = ++layerIdPool % MAX_INT,
24064 bb,
24065 level: lvl,
24066 width: w,
24067 height: h,
24068 canvas,
24069 context: canvas.getContext("2d"),
24070 eles: [],
24071 elesQueue: [],
24072 reqs: 0
24073 };
24074 var cxt = layer.context;
24075 var dx = -layer.bb.x1;
24076 var dy = -layer.bb.y1;
24077 cxt.scale(scale, scale);
24078 cxt.translate(dx, dy);
24079 return layer;
24080 };
24081 LTCp.getLayers = function(eles, pxRatio, lvl) {
24082 var self2 = this;
24083 var r = self2.renderer;
24084 var cy = r.cy;
24085 var zoom = cy.zoom();
24086 var firstGet = self2.firstGet;
24087 self2.firstGet = false;
24088 if (lvl == null) {
24089 lvl = Math.ceil(log2(zoom * pxRatio));
24090 if (lvl < minLvl) {
24091 lvl = minLvl;
24092 } else if (zoom >= maxZoom || lvl > maxLvl) {
24093 return null;
24094 }
24095 }
24096 self2.validateLayersElesOrdering(lvl, eles);
24097 var layersByLvl = self2.layersByLevel;
24098 var scale = Math.pow(2, lvl);
24099 var layers = layersByLvl[lvl] = layersByLvl[lvl] || [];
24100 var bb;
24101 var lvlComplete = self2.levelIsComplete(lvl, eles);
24102 var tmpLayers;
24103 var checkTempLevels = function checkTempLevels2() {
24104 var canUseAsTmpLvl = function canUseAsTmpLvl2(l) {
24105 self2.validateLayersElesOrdering(l, eles);
24106 if (self2.levelIsComplete(l, eles)) {
24107 tmpLayers = layersByLvl[l];
24108 return true;
24109 }
24110 };
24111 var checkLvls = function checkLvls2(dir) {
24112 if (tmpLayers) {
24113 return;
24114 }
24115 for (var l = lvl + dir; minLvl <= l && l <= maxLvl; l += dir) {
24116 if (canUseAsTmpLvl(l)) {
24117 break;
24118 }
24119 }
24120 };
24121 checkLvls(1);
24122 checkLvls(-1);
24123 for (var i3 = layers.length - 1; i3 >= 0; i3--) {
24124 var layer2 = layers[i3];
24125 if (layer2.invalid) {
24126 removeFromArray(layers, layer2);
24127 }
24128 }
24129 };
24130 if (!lvlComplete) {
24131 checkTempLevels();
24132 } else {
24133 return layers;
24134 }
24135 var getBb = function getBb2() {
24136 if (!bb) {
24137 bb = makeBoundingBox();
24138 for (var i3 = 0; i3 < eles.length; i3++) {
24139 updateBoundingBox(bb, eles[i3].boundingBox());
24140 }
24141 }
24142 return bb;
24143 };
24144 var makeLayer = function makeLayer2(opts) {
24145 opts = opts || {};
24146 var after = opts.after;
24147 getBb();
24148 var area = bb.w * scale * (bb.h * scale);
24149 if (area > maxLayerArea) {
24150 return null;
24151 }
24152 var layer2 = self2.makeLayer(bb, lvl);
24153 if (after != null) {
24154 var index = layers.indexOf(after) + 1;
24155 layers.splice(index, 0, layer2);
24156 } else if (opts.insert === void 0 || opts.insert) {
24157 layers.unshift(layer2);
24158 }
24159 return layer2;
24160 };
24161 if (self2.skipping && !firstGet) {
24162 return null;
24163 }
24164 var layer = null;
24165 var maxElesPerLayer = eles.length / defNumLayers;
24166 var allowLazyQueueing = !firstGet;
24167 for (var i2 = 0; i2 < eles.length; i2++) {
24168 var ele = eles[i2];
24169 var rs = ele._private.rscratch;
24170 var caches = rs.imgLayerCaches = rs.imgLayerCaches || {};
24171 var existingLayer = caches[lvl];
24172 if (existingLayer) {
24173 layer = existingLayer;
24174 continue;
24175 }
24176 if (!layer || layer.eles.length >= maxElesPerLayer || !boundingBoxInBoundingBox(layer.bb, ele.boundingBox())) {
24177 layer = makeLayer({
24178 insert: true,
24179 after: layer
24180 });
24181 if (!layer) {
24182 return null;
24183 }
24184 }
24185 if (tmpLayers || allowLazyQueueing) {
24186 self2.queueLayer(layer, ele);
24187 } else {
24188 self2.drawEleInLayer(layer, ele, lvl, pxRatio);
24189 }
24190 layer.eles.push(ele);
24191 caches[lvl] = layer;
24192 }
24193 if (tmpLayers) {
24194 return tmpLayers;
24195 }
24196 if (allowLazyQueueing) {
24197 return null;
24198 }
24199 return layers;
24200 };
24201 LTCp.getEleLevelForLayerLevel = function(lvl, pxRatio) {
24202 return lvl;
24203 };
24204 LTCp.drawEleInLayer = function(layer, ele, lvl, pxRatio) {
24205 var self2 = this;
24206 var r = this.renderer;
24207 var context = layer.context;
24208 var bb = ele.boundingBox();
24209 if (bb.w === 0 || bb.h === 0 || !ele.visible()) {
24210 return;
24211 }
24212 lvl = self2.getEleLevelForLayerLevel(lvl, pxRatio);
24213 {
24214 r.setImgSmoothing(context, false);
24215 }
24216 {
24217 r.drawCachedElement(context, ele, null, null, lvl, useHighQualityEleTxrReqs);
24218 }
24219 {
24220 r.setImgSmoothing(context, true);
24221 }
24222 };
24223 LTCp.levelIsComplete = function(lvl, eles) {
24224 var self2 = this;
24225 var layers = self2.layersByLevel[lvl];
24226 if (!layers || layers.length === 0) {
24227 return false;
24228 }
24229 var numElesInLayers = 0;
24230 for (var i2 = 0; i2 < layers.length; i2++) {
24231 var layer = layers[i2];
24232 if (layer.reqs > 0) {
24233 return false;
24234 }
24235 if (layer.invalid) {
24236 return false;
24237 }
24238 numElesInLayers += layer.eles.length;
24239 }
24240 if (numElesInLayers !== eles.length) {
24241 return false;
24242 }
24243 return true;
24244 };
24245 LTCp.validateLayersElesOrdering = function(lvl, eles) {
24246 var layers = this.layersByLevel[lvl];
24247 if (!layers) {
24248 return;
24249 }
24250 for (var i2 = 0; i2 < layers.length; i2++) {
24251 var layer = layers[i2];
24252 var offset = -1;
24253 for (var j = 0; j < eles.length; j++) {
24254 if (layer.eles[0] === eles[j]) {
24255 offset = j;
24256 break;
24257 }
24258 }
24259 if (offset < 0) {
24260 this.invalidateLayer(layer);
24261 continue;
24262 }
24263 var o = offset;
24264 for (var j = 0; j < layer.eles.length; j++) {
24265 if (layer.eles[j] !== eles[o + j]) {
24266 this.invalidateLayer(layer);
24267 break;
24268 }
24269 }
24270 }
24271 };
24272 LTCp.updateElementsInLayers = function(eles, update2) {
24273 var self2 = this;
24274 var isEles = element(eles[0]);
24275 for (var i2 = 0; i2 < eles.length; i2++) {
24276 var req = isEles ? null : eles[i2];
24277 var ele = isEles ? eles[i2] : eles[i2].ele;
24278 var rs = ele._private.rscratch;
24279 var caches = rs.imgLayerCaches = rs.imgLayerCaches || {};
24280 for (var l = minLvl; l <= maxLvl; l++) {
24281 var layer = caches[l];
24282 if (!layer) {
24283 continue;
24284 }
24285 if (req && self2.getEleLevelForLayerLevel(layer.level) !== req.level) {
24286 continue;
24287 }
24288 update2(layer, ele, req);
24289 }
24290 }
24291 };
24292 LTCp.haveLayers = function() {
24293 var self2 = this;
24294 var haveLayers = false;
24295 for (var l = minLvl; l <= maxLvl; l++) {
24296 var layers = self2.layersByLevel[l];
24297 if (layers && layers.length > 0) {
24298 haveLayers = true;
24299 break;
24300 }
24301 }
24302 return haveLayers;
24303 };
24304 LTCp.invalidateElements = function(eles) {
24305 var self2 = this;
24306 if (eles.length === 0) {
24307 return;
24308 }
24309 self2.lastInvalidationTime = performanceNow();
24310 if (eles.length === 0 || !self2.haveLayers()) {
24311 return;
24312 }
24313 self2.updateElementsInLayers(eles, function invalAssocLayers(layer, ele, req) {
24314 self2.invalidateLayer(layer);
24315 });
24316 };
24317 LTCp.invalidateLayer = function(layer) {
24318 this.lastInvalidationTime = performanceNow();
24319 if (layer.invalid) {
24320 return;
24321 }
24322 var lvl = layer.level;
24323 var eles = layer.eles;
24324 var layers = this.layersByLevel[lvl];
24325 removeFromArray(layers, layer);
24326 layer.elesQueue = [];
24327 layer.invalid = true;
24328 if (layer.replacement) {
24329 layer.replacement.invalid = true;
24330 }
24331 for (var i2 = 0; i2 < eles.length; i2++) {
24332 var caches = eles[i2]._private.rscratch.imgLayerCaches;
24333 if (caches) {
24334 caches[lvl] = null;
24335 }
24336 }
24337 };
24338 LTCp.refineElementTextures = function(eles) {
24339 var self2 = this;
24340 self2.updateElementsInLayers(eles, function refineEachEle(layer, ele, req) {
24341 var rLyr = layer.replacement;
24342 if (!rLyr) {
24343 rLyr = layer.replacement = self2.makeLayer(layer.bb, layer.level);
24344 rLyr.replaces = layer;
24345 rLyr.eles = layer.eles;
24346 }
24347 if (!rLyr.reqs) {
24348 for (var i2 = 0; i2 < rLyr.eles.length; i2++) {
24349 self2.queueLayer(rLyr, rLyr.eles[i2]);
24350 }
24351 }
24352 });
24353 };
24354 LTCp.enqueueElementRefinement = function(ele) {
24355 this.eleTxrDeqs.merge(ele);
24356 this.scheduleElementRefinement();
24357 };
24358 LTCp.queueLayer = function(layer, ele) {
24359 var self2 = this;
24360 var q = self2.layersQueue;
24361 var elesQ = layer.elesQueue;
24362 var hasId = elesQ.hasId = elesQ.hasId || {};
24363 if (layer.replacement) {
24364 return;
24365 }
24366 if (ele) {
24367 if (hasId[ele.id()]) {
24368 return;
24369 }
24370 elesQ.push(ele);
24371 hasId[ele.id()] = true;
24372 }
24373 if (layer.reqs) {
24374 layer.reqs++;
24375 q.updateItem(layer);
24376 } else {
24377 layer.reqs = 1;
24378 q.push(layer);
24379 }
24380 };
24381 LTCp.dequeue = function(pxRatio) {
24382 var self2 = this;
24383 var q = self2.layersQueue;
24384 var deqd = [];
24385 var eleDeqs = 0;
24386 while (eleDeqs < maxDeqSize) {
24387 if (q.size() === 0) {
24388 break;
24389 }
24390 var layer = q.peek();
24391 if (layer.replacement) {
24392 q.pop();
24393 continue;
24394 }
24395 if (layer.replaces && layer !== layer.replaces.replacement) {
24396 q.pop();
24397 continue;
24398 }
24399 if (layer.invalid) {
24400 q.pop();
24401 continue;
24402 }
24403 var ele = layer.elesQueue.shift();
24404 if (ele) {
24405 self2.drawEleInLayer(layer, ele, layer.level, pxRatio);
24406 eleDeqs++;
24407 }
24408 if (deqd.length === 0) {
24409 deqd.push(true);
24410 }
24411 if (layer.elesQueue.length === 0) {
24412 q.pop();
24413 layer.reqs = 0;
24414 if (layer.replaces) {
24415 self2.applyLayerReplacement(layer);
24416 }
24417 self2.requestRedraw();
24418 }
24419 }
24420 return deqd;
24421 };
24422 LTCp.applyLayerReplacement = function(layer) {
24423 var self2 = this;
24424 var layersInLevel = self2.layersByLevel[layer.level];
24425 var replaced = layer.replaces;
24426 var index = layersInLevel.indexOf(replaced);
24427 if (index < 0 || replaced.invalid) {
24428 return;
24429 }
24430 layersInLevel[index] = layer;
24431 for (var i2 = 0; i2 < layer.eles.length; i2++) {
24432 var _p = layer.eles[i2]._private;
24433 var cache2 = _p.imgLayerCaches = _p.imgLayerCaches || {};
24434 if (cache2) {
24435 cache2[layer.level] = layer;
24436 }
24437 }
24438 self2.requestRedraw();
24439 };
24440 LTCp.requestRedraw = debounce_1(function() {
24441 var r = this.renderer;
24442 r.redrawHint("eles", true);
24443 r.redrawHint("drag", true);
24444 r.redraw();
24445 }, 100);
24446 LTCp.setupDequeueing = defs.setupDequeueing({
24447 deqRedrawThreshold,
24448 deqCost,
24449 deqAvgCost,
24450 deqNoDrawCost,
24451 deqFastCost,
24452 deq: function deq(self2, pxRatio) {
24453 return self2.dequeue(pxRatio);
24454 },
24455 onDeqd: noop$1,
24456 shouldRedraw: trueify,
24457 priority: function priority(self2) {
24458 return self2.renderer.beforeRenderPriorities.lyrTxrDeq;
24459 }
24460 });
24461 var CRp$a = {};
24462 var impl;
24463 function polygon(context, points) {
24464 for (var i2 = 0; i2 < points.length; i2++) {
24465 var pt = points[i2];
24466 context.lineTo(pt.x, pt.y);
24467 }
24468 }
24469 function triangleBackcurve(context, points, controlPoint) {
24470 var firstPt;
24471 for (var i2 = 0; i2 < points.length; i2++) {
24472 var pt = points[i2];
24473 if (i2 === 0) {
24474 firstPt = pt;
24475 }
24476 context.lineTo(pt.x, pt.y);
24477 }
24478 context.quadraticCurveTo(controlPoint.x, controlPoint.y, firstPt.x, firstPt.y);
24479 }
24480 function triangleTee(context, trianglePoints, teePoints) {
24481 if (context.beginPath) {
24482 context.beginPath();
24483 }
24484 var triPts = trianglePoints;
24485 for (var i2 = 0; i2 < triPts.length; i2++) {
24486 var pt = triPts[i2];
24487 context.lineTo(pt.x, pt.y);
24488 }
24489 var teePts = teePoints;
24490 var firstTeePt = teePoints[0];
24491 context.moveTo(firstTeePt.x, firstTeePt.y);
24492 for (var i2 = 1; i2 < teePts.length; i2++) {
24493 var pt = teePts[i2];
24494 context.lineTo(pt.x, pt.y);
24495 }
24496 if (context.closePath) {
24497 context.closePath();
24498 }
24499 }
24500 function circleTriangle(context, trianglePoints, rx, ry, r) {
24501 if (context.beginPath) {
24502 context.beginPath();
24503 }
24504 context.arc(rx, ry, r, 0, Math.PI * 2, false);
24505 var triPts = trianglePoints;
24506 var firstTrPt = triPts[0];
24507 context.moveTo(firstTrPt.x, firstTrPt.y);
24508 for (var i2 = 0; i2 < triPts.length; i2++) {
24509 var pt = triPts[i2];
24510 context.lineTo(pt.x, pt.y);
24511 }
24512 if (context.closePath) {
24513 context.closePath();
24514 }
24515 }
24516 function circle(context, rx, ry, r) {
24517 context.arc(rx, ry, r, 0, Math.PI * 2, false);
24518 }
24519 CRp$a.arrowShapeImpl = function(name2) {
24520 return (impl || (impl = {
24521 "polygon": polygon,
24522 "triangle-backcurve": triangleBackcurve,
24523 "triangle-tee": triangleTee,
24524 "circle-triangle": circleTriangle,
24525 "triangle-cross": triangleTee,
24526 "circle": circle
24527 }))[name2];
24528 };
24529 var CRp$9 = {};
24530 CRp$9.drawElement = function(context, ele, shiftToOriginWithBb, showLabel, showOverlay, showOpacity) {
24531 var r = this;
24532 if (ele.isNode()) {
24533 r.drawNode(context, ele, shiftToOriginWithBb, showLabel, showOverlay, showOpacity);
24534 } else {
24535 r.drawEdge(context, ele, shiftToOriginWithBb, showLabel, showOverlay, showOpacity);
24536 }
24537 };
24538 CRp$9.drawElementOverlay = function(context, ele) {
24539 var r = this;
24540 if (ele.isNode()) {
24541 r.drawNodeOverlay(context, ele);
24542 } else {
24543 r.drawEdgeOverlay(context, ele);
24544 }
24545 };
24546 CRp$9.drawElementUnderlay = function(context, ele) {
24547 var r = this;
24548 if (ele.isNode()) {
24549 r.drawNodeUnderlay(context, ele);
24550 } else {
24551 r.drawEdgeUnderlay(context, ele);
24552 }
24553 };
24554 CRp$9.drawCachedElementPortion = function(context, ele, eleTxrCache, pxRatio, lvl, reason, getRotation, getOpacity2) {
24555 var r = this;
24556 var bb = eleTxrCache.getBoundingBox(ele);
24557 if (bb.w === 0 || bb.h === 0) {
24558 return;
24559 }
24560 var eleCache = eleTxrCache.getElement(ele, bb, pxRatio, lvl, reason);
24561 if (eleCache != null) {
24562 var opacity = getOpacity2(r, ele);
24563 if (opacity === 0) {
24564 return;
24565 }
24566 var theta = getRotation(r, ele);
24567 var x1 = bb.x1, y1 = bb.y1, w = bb.w, h = bb.h;
24568 var x, y, sx, sy, smooth;
24569 if (theta !== 0) {
24570 var rotPt = eleTxrCache.getRotationPoint(ele);
24571 sx = rotPt.x;
24572 sy = rotPt.y;
24573 context.translate(sx, sy);
24574 context.rotate(theta);
24575 smooth = r.getImgSmoothing(context);
24576 if (!smooth) {
24577 r.setImgSmoothing(context, true);
24578 }
24579 var off = eleTxrCache.getRotationOffset(ele);
24580 x = off.x;
24581 y = off.y;
24582 } else {
24583 x = x1;
24584 y = y1;
24585 }
24586 var oldGlobalAlpha;
24587 if (opacity !== 1) {
24588 oldGlobalAlpha = context.globalAlpha;
24589 context.globalAlpha = oldGlobalAlpha * opacity;
24590 }
24591 context.drawImage(eleCache.texture.canvas, eleCache.x, 0, eleCache.width, eleCache.height, x, y, w, h);
24592 if (opacity !== 1) {
24593 context.globalAlpha = oldGlobalAlpha;
24594 }
24595 if (theta !== 0) {
24596 context.rotate(-theta);
24597 context.translate(-sx, -sy);
24598 if (!smooth) {
24599 r.setImgSmoothing(context, false);
24600 }
24601 }
24602 } else {
24603 eleTxrCache.drawElement(context, ele);
24604 }
24605 };
24606 var getZeroRotation = function getZeroRotation2() {
24607 return 0;
24608 };
24609 var getLabelRotation = function getLabelRotation2(r, ele) {
24610 return r.getTextAngle(ele, null);
24611 };
24612 var getSourceLabelRotation = function getSourceLabelRotation2(r, ele) {
24613 return r.getTextAngle(ele, "source");
24614 };
24615 var getTargetLabelRotation = function getTargetLabelRotation2(r, ele) {
24616 return r.getTextAngle(ele, "target");
24617 };
24618 var getOpacity = function getOpacity2(r, ele) {
24619 return ele.effectiveOpacity();
24620 };
24621 var getTextOpacity = function getTextOpacity2(e, ele) {
24622 return ele.pstyle("text-opacity").pfValue * ele.effectiveOpacity();
24623 };
24624 CRp$9.drawCachedElement = function(context, ele, pxRatio, extent, lvl, requestHighQuality) {
24625 var r = this;
24626 var _r$data = r.data, eleTxrCache = _r$data.eleTxrCache, lblTxrCache = _r$data.lblTxrCache, slbTxrCache = _r$data.slbTxrCache, tlbTxrCache = _r$data.tlbTxrCache;
24627 var bb = ele.boundingBox();
24628 var reason = requestHighQuality === true ? eleTxrCache.reasons.highQuality : null;
24629 if (bb.w === 0 || bb.h === 0 || !ele.visible()) {
24630 return;
24631 }
24632 if (!extent || boundingBoxesIntersect(bb, extent)) {
24633 var isEdge = ele.isEdge();
24634 var badLine = ele.element()._private.rscratch.badLine;
24635 r.drawElementUnderlay(context, ele);
24636 r.drawCachedElementPortion(context, ele, eleTxrCache, pxRatio, lvl, reason, getZeroRotation, getOpacity);
24637 if (!isEdge || !badLine) {
24638 r.drawCachedElementPortion(context, ele, lblTxrCache, pxRatio, lvl, reason, getLabelRotation, getTextOpacity);
24639 }
24640 if (isEdge && !badLine) {
24641 r.drawCachedElementPortion(context, ele, slbTxrCache, pxRatio, lvl, reason, getSourceLabelRotation, getTextOpacity);
24642 r.drawCachedElementPortion(context, ele, tlbTxrCache, pxRatio, lvl, reason, getTargetLabelRotation, getTextOpacity);
24643 }
24644 r.drawElementOverlay(context, ele);
24645 }
24646 };
24647 CRp$9.drawElements = function(context, eles) {
24648 var r = this;
24649 for (var i2 = 0; i2 < eles.length; i2++) {
24650 var ele = eles[i2];
24651 r.drawElement(context, ele);
24652 }
24653 };
24654 CRp$9.drawCachedElements = function(context, eles, pxRatio, extent) {
24655 var r = this;
24656 for (var i2 = 0; i2 < eles.length; i2++) {
24657 var ele = eles[i2];
24658 r.drawCachedElement(context, ele, pxRatio, extent);
24659 }
24660 };
24661 CRp$9.drawCachedNodes = function(context, eles, pxRatio, extent) {
24662 var r = this;
24663 for (var i2 = 0; i2 < eles.length; i2++) {
24664 var ele = eles[i2];
24665 if (!ele.isNode()) {
24666 continue;
24667 }
24668 r.drawCachedElement(context, ele, pxRatio, extent);
24669 }
24670 };
24671 CRp$9.drawLayeredElements = function(context, eles, pxRatio, extent) {
24672 var r = this;
24673 var layers = r.data.lyrTxrCache.getLayers(eles, pxRatio);
24674 if (layers) {
24675 for (var i2 = 0; i2 < layers.length; i2++) {
24676 var layer = layers[i2];
24677 var bb = layer.bb;
24678 if (bb.w === 0 || bb.h === 0) {
24679 continue;
24680 }
24681 context.drawImage(layer.canvas, bb.x1, bb.y1, bb.w, bb.h);
24682 }
24683 } else {
24684 r.drawCachedElements(context, eles, pxRatio, extent);
24685 }
24686 };
24687 var CRp$8 = {};
24688 CRp$8.drawEdge = function(context, edge, shiftToOriginWithBb) {
24689 var drawLabel = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : true;
24690 var shouldDrawOverlay = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
24691 var shouldDrawOpacity = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : true;
24692 var r = this;
24693 var rs = edge._private.rscratch;
24694 if (shouldDrawOpacity && !edge.visible()) {
24695 return;
24696 }
24697 if (rs.badLine || rs.allpts == null || isNaN(rs.allpts[0])) {
24698 return;
24699 }
24700 var bb;
24701 if (shiftToOriginWithBb) {
24702 bb = shiftToOriginWithBb;
24703 context.translate(-bb.x1, -bb.y1);
24704 }
24705 var opacity = shouldDrawOpacity ? edge.pstyle("opacity").value : 1;
24706 var lineOpacity = shouldDrawOpacity ? edge.pstyle("line-opacity").value : 1;
24707 var curveStyle = edge.pstyle("curve-style").value;
24708 var lineStyle = edge.pstyle("line-style").value;
24709 var edgeWidth = edge.pstyle("width").pfValue;
24710 var lineCap = edge.pstyle("line-cap").value;
24711 var effectiveLineOpacity = opacity * lineOpacity;
24712 var effectiveArrowOpacity = opacity * lineOpacity;
24713 var drawLine = function drawLine2() {
24714 var strokeOpacity = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : effectiveLineOpacity;
24715 if (curveStyle === "straight-triangle") {
24716 r.eleStrokeStyle(context, edge, strokeOpacity);
24717 r.drawEdgeTrianglePath(edge, context, rs.allpts);
24718 } else {
24719 context.lineWidth = edgeWidth;
24720 context.lineCap = lineCap;
24721 r.eleStrokeStyle(context, edge, strokeOpacity);
24722 r.drawEdgePath(edge, context, rs.allpts, lineStyle);
24723 context.lineCap = "butt";
24724 }
24725 };
24726 var drawOverlay = function drawOverlay2() {
24727 if (!shouldDrawOverlay) {
24728 return;
24729 }
24730 r.drawEdgeOverlay(context, edge);
24731 };
24732 var drawUnderlay = function drawUnderlay2() {
24733 if (!shouldDrawOverlay) {
24734 return;
24735 }
24736 r.drawEdgeUnderlay(context, edge);
24737 };
24738 var drawArrows = function drawArrows2() {
24739 var arrowOpacity = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : effectiveArrowOpacity;
24740 r.drawArrowheads(context, edge, arrowOpacity);
24741 };
24742 var drawText = function drawText2() {
24743 r.drawElementText(context, edge, null, drawLabel);
24744 };
24745 context.lineJoin = "round";
24746 var ghost = edge.pstyle("ghost").value === "yes";
24747 if (ghost) {
24748 var gx = edge.pstyle("ghost-offset-x").pfValue;
24749 var gy = edge.pstyle("ghost-offset-y").pfValue;
24750 var ghostOpacity = edge.pstyle("ghost-opacity").value;
24751 var effectiveGhostOpacity = effectiveLineOpacity * ghostOpacity;
24752 context.translate(gx, gy);
24753 drawLine(effectiveGhostOpacity);
24754 drawArrows(effectiveGhostOpacity);
24755 context.translate(-gx, -gy);
24756 }
24757 drawUnderlay();
24758 drawLine();
24759 drawArrows();
24760 drawOverlay();
24761 drawText();
24762 if (shiftToOriginWithBb) {
24763 context.translate(bb.x1, bb.y1);
24764 }
24765 };
24766 var drawEdgeOverlayUnderlay = function drawEdgeOverlayUnderlay2(overlayOrUnderlay) {
24767 if (!["overlay", "underlay"].includes(overlayOrUnderlay)) {
24768 throw new Error("Invalid state");
24769 }
24770 return function(context, edge) {
24771 if (!edge.visible()) {
24772 return;
24773 }
24774 var opacity = edge.pstyle("".concat(overlayOrUnderlay, "-opacity")).value;
24775 if (opacity === 0) {
24776 return;
24777 }
24778 var r = this;
24779 var usePaths = r.usePaths();
24780 var rs = edge._private.rscratch;
24781 var padding = edge.pstyle("".concat(overlayOrUnderlay, "-padding")).pfValue;
24782 var width = 2 * padding;
24783 var color = edge.pstyle("".concat(overlayOrUnderlay, "-color")).value;
24784 context.lineWidth = width;
24785 if (rs.edgeType === "self" && !usePaths) {
24786 context.lineCap = "butt";
24787 } else {
24788 context.lineCap = "round";
24789 }
24790 r.colorStrokeStyle(context, color[0], color[1], color[2], opacity);
24791 r.drawEdgePath(edge, context, rs.allpts, "solid");
24792 };
24793 };
24794 CRp$8.drawEdgeOverlay = drawEdgeOverlayUnderlay("overlay");
24795 CRp$8.drawEdgeUnderlay = drawEdgeOverlayUnderlay("underlay");
24796 CRp$8.drawEdgePath = function(edge, context, pts2, type) {
24797 var rs = edge._private.rscratch;
24798 var canvasCxt = context;
24799 var path;
24800 var pathCacheHit = false;
24801 var usePaths = this.usePaths();
24802 var lineDashPattern = edge.pstyle("line-dash-pattern").pfValue;
24803 var lineDashOffset = edge.pstyle("line-dash-offset").pfValue;
24804 if (usePaths) {
24805 var pathCacheKey = pts2.join("$");
24806 var keyMatches = rs.pathCacheKey && rs.pathCacheKey === pathCacheKey;
24807 if (keyMatches) {
24808 path = context = rs.pathCache;
24809 pathCacheHit = true;
24810 } else {
24811 path = context = new Path2D();
24812 rs.pathCacheKey = pathCacheKey;
24813 rs.pathCache = path;
24814 }
24815 }
24816 if (canvasCxt.setLineDash) {
24817 switch (type) {
24818 case "dotted":
24819 canvasCxt.setLineDash([1, 1]);
24820 break;
24821 case "dashed":
24822 canvasCxt.setLineDash(lineDashPattern);
24823 canvasCxt.lineDashOffset = lineDashOffset;
24824 break;
24825 case "solid":
24826 canvasCxt.setLineDash([]);
24827 break;
24828 }
24829 }
24830 if (!pathCacheHit && !rs.badLine) {
24831 if (context.beginPath) {
24832 context.beginPath();
24833 }
24834 context.moveTo(pts2[0], pts2[1]);
24835 switch (rs.edgeType) {
24836 case "bezier":
24837 case "self":
24838 case "compound":
24839 case "multibezier":
24840 for (var i2 = 2; i2 + 3 < pts2.length; i2 += 4) {
24841 context.quadraticCurveTo(pts2[i2], pts2[i2 + 1], pts2[i2 + 2], pts2[i2 + 3]);
24842 }
24843 break;
24844 case "straight":
24845 case "segments":
24846 case "haystack":
24847 for (var _i = 2; _i + 1 < pts2.length; _i += 2) {
24848 context.lineTo(pts2[_i], pts2[_i + 1]);
24849 }
24850 break;
24851 }
24852 }
24853 context = canvasCxt;
24854 if (usePaths) {
24855 context.stroke(path);
24856 } else {
24857 context.stroke();
24858 }
24859 if (context.setLineDash) {
24860 context.setLineDash([]);
24861 }
24862 };
24863 CRp$8.drawEdgeTrianglePath = function(edge, context, pts2) {
24864 context.fillStyle = context.strokeStyle;
24865 var edgeWidth = edge.pstyle("width").pfValue;
24866 for (var i2 = 0; i2 + 1 < pts2.length; i2 += 2) {
24867 var vector = [pts2[i2 + 2] - pts2[i2], pts2[i2 + 3] - pts2[i2 + 1]];
24868 var length = Math.sqrt(vector[0] * vector[0] + vector[1] * vector[1]);
24869 var normal = [vector[1] / length, -vector[0] / length];
24870 var triangleHead = [normal[0] * edgeWidth / 2, normal[1] * edgeWidth / 2];
24871 context.beginPath();
24872 context.moveTo(pts2[i2] - triangleHead[0], pts2[i2 + 1] - triangleHead[1]);
24873 context.lineTo(pts2[i2] + triangleHead[0], pts2[i2 + 1] + triangleHead[1]);
24874 context.lineTo(pts2[i2 + 2], pts2[i2 + 3]);
24875 context.closePath();
24876 context.fill();
24877 }
24878 };
24879 CRp$8.drawArrowheads = function(context, edge, opacity) {
24880 var rs = edge._private.rscratch;
24881 var isHaystack = rs.edgeType === "haystack";
24882 if (!isHaystack) {
24883 this.drawArrowhead(context, edge, "source", rs.arrowStartX, rs.arrowStartY, rs.srcArrowAngle, opacity);
24884 }
24885 this.drawArrowhead(context, edge, "mid-target", rs.midX, rs.midY, rs.midtgtArrowAngle, opacity);
24886 this.drawArrowhead(context, edge, "mid-source", rs.midX, rs.midY, rs.midsrcArrowAngle, opacity);
24887 if (!isHaystack) {
24888 this.drawArrowhead(context, edge, "target", rs.arrowEndX, rs.arrowEndY, rs.tgtArrowAngle, opacity);
24889 }
24890 };
24891 CRp$8.drawArrowhead = function(context, edge, prefix, x, y, angle, opacity) {
24892 if (isNaN(x) || x == null || isNaN(y) || y == null || isNaN(angle) || angle == null) {
24893 return;
24894 }
24895 var self2 = this;
24896 var arrowShape = edge.pstyle(prefix + "-arrow-shape").value;
24897 if (arrowShape === "none") {
24898 return;
24899 }
24900 var arrowClearFill = edge.pstyle(prefix + "-arrow-fill").value === "hollow" ? "both" : "filled";
24901 var arrowFill = edge.pstyle(prefix + "-arrow-fill").value;
24902 var edgeWidth = edge.pstyle("width").pfValue;
24903 var edgeOpacity = edge.pstyle("opacity").value;
24904 if (opacity === void 0) {
24905 opacity = edgeOpacity;
24906 }
24907 var gco = context.globalCompositeOperation;
24908 if (opacity !== 1 || arrowFill === "hollow") {
24909 context.globalCompositeOperation = "destination-out";
24910 self2.colorFillStyle(context, 255, 255, 255, 1);
24911 self2.colorStrokeStyle(context, 255, 255, 255, 1);
24912 self2.drawArrowShape(edge, context, arrowClearFill, edgeWidth, arrowShape, x, y, angle);
24913 context.globalCompositeOperation = gco;
24914 }
24915 var color = edge.pstyle(prefix + "-arrow-color").value;
24916 self2.colorFillStyle(context, color[0], color[1], color[2], opacity);
24917 self2.colorStrokeStyle(context, color[0], color[1], color[2], opacity);
24918 self2.drawArrowShape(edge, context, arrowFill, edgeWidth, arrowShape, x, y, angle);
24919 };
24920 CRp$8.drawArrowShape = function(edge, context, fill, edgeWidth, shape, x, y, angle) {
24921 var r = this;
24922 var usePaths = this.usePaths() && shape !== "triangle-cross";
24923 var pathCacheHit = false;
24924 var path;
24925 var canvasContext = context;
24926 var translation = {
24927 x,
24928 y
24929 };
24930 var scale = edge.pstyle("arrow-scale").value;
24931 var size = this.getArrowWidth(edgeWidth, scale);
24932 var shapeImpl = r.arrowShapes[shape];
24933 if (usePaths) {
24934 var cache2 = r.arrowPathCache = r.arrowPathCache || [];
24935 var key = hashString(shape);
24936 var cachedPath = cache2[key];
24937 if (cachedPath != null) {
24938 path = context = cachedPath;
24939 pathCacheHit = true;
24940 } else {
24941 path = context = new Path2D();
24942 cache2[key] = path;
24943 }
24944 }
24945 if (!pathCacheHit) {
24946 if (context.beginPath) {
24947 context.beginPath();
24948 }
24949 if (usePaths) {
24950 shapeImpl.draw(context, 1, 0, {
24951 x: 0,
24952 y: 0
24953 }, 1);
24954 } else {
24955 shapeImpl.draw(context, size, angle, translation, edgeWidth);
24956 }
24957 if (context.closePath) {
24958 context.closePath();
24959 }
24960 }
24961 context = canvasContext;
24962 if (usePaths) {
24963 context.translate(x, y);
24964 context.rotate(angle);
24965 context.scale(size, size);
24966 }
24967 if (fill === "filled" || fill === "both") {
24968 if (usePaths) {
24969 context.fill(path);
24970 } else {
24971 context.fill();
24972 }
24973 }
24974 if (fill === "hollow" || fill === "both") {
24975 context.lineWidth = (shapeImpl.matchEdgeWidth ? edgeWidth : 1) / (usePaths ? size : 1);
24976 context.lineJoin = "miter";
24977 if (usePaths) {
24978 context.stroke(path);
24979 } else {
24980 context.stroke();
24981 }
24982 }
24983 if (usePaths) {
24984 context.scale(1 / size, 1 / size);
24985 context.rotate(-angle);
24986 context.translate(-x, -y);
24987 }
24988 };
24989 var CRp$7 = {};
24990 CRp$7.safeDrawImage = function(context, img, ix, iy, iw, ih, x, y, w, h) {
24991 if (iw <= 0 || ih <= 0 || w <= 0 || h <= 0) {
24992 return;
24993 }
24994 try {
24995 context.drawImage(img, ix, iy, iw, ih, x, y, w, h);
24996 } catch (e) {
24997 warn(e);
24998 }
24999 };
25000 CRp$7.drawInscribedImage = function(context, img, node, index, nodeOpacity) {
25001 var r = this;
25002 var pos = node.position();
25003 var nodeX = pos.x;
25004 var nodeY = pos.y;
25005 var styleObj = node.cy().style();
25006 var getIndexedStyle = styleObj.getIndexedStyle.bind(styleObj);
25007 var fit = getIndexedStyle(node, "background-fit", "value", index);
25008 var repeat = getIndexedStyle(node, "background-repeat", "value", index);
25009 var nodeW = node.width();
25010 var nodeH = node.height();
25011 var paddingX2 = node.padding() * 2;
25012 var nodeTW = nodeW + (getIndexedStyle(node, "background-width-relative-to", "value", index) === "inner" ? 0 : paddingX2);
25013 var nodeTH = nodeH + (getIndexedStyle(node, "background-height-relative-to", "value", index) === "inner" ? 0 : paddingX2);
25014 var rs = node._private.rscratch;
25015 var clip = getIndexedStyle(node, "background-clip", "value", index);
25016 var shouldClip = clip === "node";
25017 var imgOpacity = getIndexedStyle(node, "background-image-opacity", "value", index) * nodeOpacity;
25018 var smooth = getIndexedStyle(node, "background-image-smoothing", "value", index);
25019 var imgW = img.width || img.cachedW;
25020 var imgH = img.height || img.cachedH;
25021 if (null == imgW || null == imgH) {
25022 document.body.appendChild(img);
25023 imgW = img.cachedW = img.width || img.offsetWidth;
25024 imgH = img.cachedH = img.height || img.offsetHeight;
25025 document.body.removeChild(img);
25026 }
25027 var w = imgW;
25028 var h = imgH;
25029 if (getIndexedStyle(node, "background-width", "value", index) !== "auto") {
25030 if (getIndexedStyle(node, "background-width", "units", index) === "%") {
25031 w = getIndexedStyle(node, "background-width", "pfValue", index) * nodeTW;
25032 } else {
25033 w = getIndexedStyle(node, "background-width", "pfValue", index);
25034 }
25035 }
25036 if (getIndexedStyle(node, "background-height", "value", index) !== "auto") {
25037 if (getIndexedStyle(node, "background-height", "units", index) === "%") {
25038 h = getIndexedStyle(node, "background-height", "pfValue", index) * nodeTH;
25039 } else {
25040 h = getIndexedStyle(node, "background-height", "pfValue", index);
25041 }
25042 }
25043 if (w === 0 || h === 0) {
25044 return;
25045 }
25046 if (fit === "contain") {
25047 var scale = Math.min(nodeTW / w, nodeTH / h);
25048 w *= scale;
25049 h *= scale;
25050 } else if (fit === "cover") {
25051 var scale = Math.max(nodeTW / w, nodeTH / h);
25052 w *= scale;
25053 h *= scale;
25054 }
25055 var x = nodeX - nodeTW / 2;
25056 var posXUnits = getIndexedStyle(node, "background-position-x", "units", index);
25057 var posXPfVal = getIndexedStyle(node, "background-position-x", "pfValue", index);
25058 if (posXUnits === "%") {
25059 x += (nodeTW - w) * posXPfVal;
25060 } else {
25061 x += posXPfVal;
25062 }
25063 var offXUnits = getIndexedStyle(node, "background-offset-x", "units", index);
25064 var offXPfVal = getIndexedStyle(node, "background-offset-x", "pfValue", index);
25065 if (offXUnits === "%") {
25066 x += (nodeTW - w) * offXPfVal;
25067 } else {
25068 x += offXPfVal;
25069 }
25070 var y = nodeY - nodeTH / 2;
25071 var posYUnits = getIndexedStyle(node, "background-position-y", "units", index);
25072 var posYPfVal = getIndexedStyle(node, "background-position-y", "pfValue", index);
25073 if (posYUnits === "%") {
25074 y += (nodeTH - h) * posYPfVal;
25075 } else {
25076 y += posYPfVal;
25077 }
25078 var offYUnits = getIndexedStyle(node, "background-offset-y", "units", index);
25079 var offYPfVal = getIndexedStyle(node, "background-offset-y", "pfValue", index);
25080 if (offYUnits === "%") {
25081 y += (nodeTH - h) * offYPfVal;
25082 } else {
25083 y += offYPfVal;
25084 }
25085 if (rs.pathCache) {
25086 x -= nodeX;
25087 y -= nodeY;
25088 nodeX = 0;
25089 nodeY = 0;
25090 }
25091 var gAlpha = context.globalAlpha;
25092 context.globalAlpha = imgOpacity;
25093 var smoothingEnabled = r.getImgSmoothing(context);
25094 var isSmoothingSwitched = false;
25095 if (smooth === "no" && smoothingEnabled) {
25096 r.setImgSmoothing(context, false);
25097 isSmoothingSwitched = true;
25098 } else if (smooth === "yes" && !smoothingEnabled) {
25099 r.setImgSmoothing(context, true);
25100 isSmoothingSwitched = true;
25101 }
25102 if (repeat === "no-repeat") {
25103 if (shouldClip) {
25104 context.save();
25105 if (rs.pathCache) {
25106 context.clip(rs.pathCache);
25107 } else {
25108 r.nodeShapes[r.getNodeShape(node)].draw(context, nodeX, nodeY, nodeTW, nodeTH);
25109 context.clip();
25110 }
25111 }
25112 r.safeDrawImage(context, img, 0, 0, imgW, imgH, x, y, w, h);
25113 if (shouldClip) {
25114 context.restore();
25115 }
25116 } else {
25117 var pattern = context.createPattern(img, repeat);
25118 context.fillStyle = pattern;
25119 r.nodeShapes[r.getNodeShape(node)].draw(context, nodeX, nodeY, nodeTW, nodeTH);
25120 context.translate(x, y);
25121 context.fill();
25122 context.translate(-x, -y);
25123 }
25124 context.globalAlpha = gAlpha;
25125 if (isSmoothingSwitched) {
25126 r.setImgSmoothing(context, smoothingEnabled);
25127 }
25128 };
25129 var CRp$6 = {};
25130 CRp$6.eleTextBiggerThanMin = function(ele, scale) {
25131 if (!scale) {
25132 var zoom = ele.cy().zoom();
25133 var pxRatio = this.getPixelRatio();
25134 var lvl = Math.ceil(log2(zoom * pxRatio));
25135 scale = Math.pow(2, lvl);
25136 }
25137 var computedSize = ele.pstyle("font-size").pfValue * scale;
25138 var minSize = ele.pstyle("min-zoomed-font-size").pfValue;
25139 if (computedSize < minSize) {
25140 return false;
25141 }
25142 return true;
25143 };
25144 CRp$6.drawElementText = function(context, ele, shiftToOriginWithBb, force, prefix) {
25145 var useEleOpacity = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : true;
25146 var r = this;
25147 if (force == null) {
25148 if (useEleOpacity && !r.eleTextBiggerThanMin(ele)) {
25149 return;
25150 }
25151 } else if (force === false) {
25152 return;
25153 }
25154 if (ele.isNode()) {
25155 var label = ele.pstyle("label");
25156 if (!label || !label.value) {
25157 return;
25158 }
25159 var justification = r.getLabelJustification(ele);
25160 context.textAlign = justification;
25161 context.textBaseline = "bottom";
25162 } else {
25163 var badLine = ele.element()._private.rscratch.badLine;
25164 var _label = ele.pstyle("label");
25165 var srcLabel = ele.pstyle("source-label");
25166 var tgtLabel = ele.pstyle("target-label");
25167 if (badLine || (!_label || !_label.value) && (!srcLabel || !srcLabel.value) && (!tgtLabel || !tgtLabel.value)) {
25168 return;
25169 }
25170 context.textAlign = "center";
25171 context.textBaseline = "bottom";
25172 }
25173 var applyRotation = !shiftToOriginWithBb;
25174 var bb;
25175 if (shiftToOriginWithBb) {
25176 bb = shiftToOriginWithBb;
25177 context.translate(-bb.x1, -bb.y1);
25178 }
25179 if (prefix == null) {
25180 r.drawText(context, ele, null, applyRotation, useEleOpacity);
25181 if (ele.isEdge()) {
25182 r.drawText(context, ele, "source", applyRotation, useEleOpacity);
25183 r.drawText(context, ele, "target", applyRotation, useEleOpacity);
25184 }
25185 } else {
25186 r.drawText(context, ele, prefix, applyRotation, useEleOpacity);
25187 }
25188 if (shiftToOriginWithBb) {
25189 context.translate(bb.x1, bb.y1);
25190 }
25191 };
25192 CRp$6.getFontCache = function(context) {
25193 var cache2;
25194 this.fontCaches = this.fontCaches || [];
25195 for (var i2 = 0; i2 < this.fontCaches.length; i2++) {
25196 cache2 = this.fontCaches[i2];
25197 if (cache2.context === context) {
25198 return cache2;
25199 }
25200 }
25201 cache2 = {
25202 context
25203 };
25204 this.fontCaches.push(cache2);
25205 return cache2;
25206 };
25207 CRp$6.setupTextStyle = function(context, ele) {
25208 var useEleOpacity = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
25209 var labelStyle = ele.pstyle("font-style").strValue;
25210 var labelSize = ele.pstyle("font-size").pfValue + "px";
25211 var labelFamily = ele.pstyle("font-family").strValue;
25212 var labelWeight = ele.pstyle("font-weight").strValue;
25213 var opacity = useEleOpacity ? ele.effectiveOpacity() * ele.pstyle("text-opacity").value : 1;
25214 var outlineOpacity = ele.pstyle("text-outline-opacity").value * opacity;
25215 var color = ele.pstyle("color").value;
25216 var outlineColor = ele.pstyle("text-outline-color").value;
25217 context.font = labelStyle + " " + labelWeight + " " + labelSize + " " + labelFamily;
25218 context.lineJoin = "round";
25219 this.colorFillStyle(context, color[0], color[1], color[2], opacity);
25220 this.colorStrokeStyle(context, outlineColor[0], outlineColor[1], outlineColor[2], outlineOpacity);
25221 };
25222 function roundRect(ctx, x, y, width, height) {
25223 var radius = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : 5;
25224 ctx.beginPath();
25225 ctx.moveTo(x + radius, y);
25226 ctx.lineTo(x + width - radius, y);
25227 ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
25228 ctx.lineTo(x + width, y + height - radius);
25229 ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
25230 ctx.lineTo(x + radius, y + height);
25231 ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
25232 ctx.lineTo(x, y + radius);
25233 ctx.quadraticCurveTo(x, y, x + radius, y);
25234 ctx.closePath();
25235 ctx.fill();
25236 }
25237 CRp$6.getTextAngle = function(ele, prefix) {
25238 var theta;
25239 var _p = ele._private;
25240 var rscratch = _p.rscratch;
25241 var pdash = prefix ? prefix + "-" : "";
25242 var rotation = ele.pstyle(pdash + "text-rotation");
25243 var textAngle = getPrefixedProperty(rscratch, "labelAngle", prefix);
25244 if (rotation.strValue === "autorotate") {
25245 theta = ele.isEdge() ? textAngle : 0;
25246 } else if (rotation.strValue === "none") {
25247 theta = 0;
25248 } else {
25249 theta = rotation.pfValue;
25250 }
25251 return theta;
25252 };
25253 CRp$6.drawText = function(context, ele, prefix) {
25254 var applyRotation = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : true;
25255 var useEleOpacity = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
25256 var _p = ele._private;
25257 var rscratch = _p.rscratch;
25258 var parentOpacity = useEleOpacity ? ele.effectiveOpacity() : 1;
25259 if (useEleOpacity && (parentOpacity === 0 || ele.pstyle("text-opacity").value === 0)) {
25260 return;
25261 }
25262 if (prefix === "main") {
25263 prefix = null;
25264 }
25265 var textX = getPrefixedProperty(rscratch, "labelX", prefix);
25266 var textY = getPrefixedProperty(rscratch, "labelY", prefix);
25267 var orgTextX, orgTextY;
25268 var text = this.getLabelText(ele, prefix);
25269 if (text != null && text !== "" && !isNaN(textX) && !isNaN(textY)) {
25270 this.setupTextStyle(context, ele, useEleOpacity);
25271 var pdash = prefix ? prefix + "-" : "";
25272 var textW = getPrefixedProperty(rscratch, "labelWidth", prefix);
25273 var textH = getPrefixedProperty(rscratch, "labelHeight", prefix);
25274 var marginX = ele.pstyle(pdash + "text-margin-x").pfValue;
25275 var marginY = ele.pstyle(pdash + "text-margin-y").pfValue;
25276 var isEdge = ele.isEdge();
25277 var halign = ele.pstyle("text-halign").value;
25278 var valign = ele.pstyle("text-valign").value;
25279 if (isEdge) {
25280 halign = "center";
25281 valign = "center";
25282 }
25283 textX += marginX;
25284 textY += marginY;
25285 var theta;
25286 if (!applyRotation) {
25287 theta = 0;
25288 } else {
25289 theta = this.getTextAngle(ele, prefix);
25290 }
25291 if (theta !== 0) {
25292 orgTextX = textX;
25293 orgTextY = textY;
25294 context.translate(orgTextX, orgTextY);
25295 context.rotate(theta);
25296 textX = 0;
25297 textY = 0;
25298 }
25299 switch (valign) {
25300 case "top":
25301 break;
25302 case "center":
25303 textY += textH / 2;
25304 break;
25305 case "bottom":
25306 textY += textH;
25307 break;
25308 }
25309 var backgroundOpacity = ele.pstyle("text-background-opacity").value;
25310 var borderOpacity = ele.pstyle("text-border-opacity").value;
25311 var textBorderWidth = ele.pstyle("text-border-width").pfValue;
25312 var backgroundPadding = ele.pstyle("text-background-padding").pfValue;
25313 if (backgroundOpacity > 0 || textBorderWidth > 0 && borderOpacity > 0) {
25314 var bgX = textX - backgroundPadding;
25315 switch (halign) {
25316 case "left":
25317 bgX -= textW;
25318 break;
25319 case "center":
25320 bgX -= textW / 2;
25321 break;
25322 }
25323 var bgY = textY - textH - backgroundPadding;
25324 var bgW = textW + 2 * backgroundPadding;
25325 var bgH = textH + 2 * backgroundPadding;
25326 if (backgroundOpacity > 0) {
25327 var textFill = context.fillStyle;
25328 var textBackgroundColor = ele.pstyle("text-background-color").value;
25329 context.fillStyle = "rgba(" + textBackgroundColor[0] + "," + textBackgroundColor[1] + "," + textBackgroundColor[2] + "," + backgroundOpacity * parentOpacity + ")";
25330 var styleShape = ele.pstyle("text-background-shape").strValue;
25331 if (styleShape.indexOf("round") === 0) {
25332 roundRect(context, bgX, bgY, bgW, bgH, 2);
25333 } else {
25334 context.fillRect(bgX, bgY, bgW, bgH);
25335 }
25336 context.fillStyle = textFill;
25337 }
25338 if (textBorderWidth > 0 && borderOpacity > 0) {
25339 var textStroke = context.strokeStyle;
25340 var textLineWidth = context.lineWidth;
25341 var textBorderColor = ele.pstyle("text-border-color").value;
25342 var textBorderStyle = ele.pstyle("text-border-style").value;
25343 context.strokeStyle = "rgba(" + textBorderColor[0] + "," + textBorderColor[1] + "," + textBorderColor[2] + "," + borderOpacity * parentOpacity + ")";
25344 context.lineWidth = textBorderWidth;
25345 if (context.setLineDash) {
25346 switch (textBorderStyle) {
25347 case "dotted":
25348 context.setLineDash([1, 1]);
25349 break;
25350 case "dashed":
25351 context.setLineDash([4, 2]);
25352 break;
25353 case "double":
25354 context.lineWidth = textBorderWidth / 4;
25355 context.setLineDash([]);
25356 break;
25357 case "solid":
25358 context.setLineDash([]);
25359 break;
25360 }
25361 }
25362 context.strokeRect(bgX, bgY, bgW, bgH);
25363 if (textBorderStyle === "double") {
25364 var whiteWidth = textBorderWidth / 2;
25365 context.strokeRect(bgX + whiteWidth, bgY + whiteWidth, bgW - whiteWidth * 2, bgH - whiteWidth * 2);
25366 }
25367 if (context.setLineDash) {
25368 context.setLineDash([]);
25369 }
25370 context.lineWidth = textLineWidth;
25371 context.strokeStyle = textStroke;
25372 }
25373 }
25374 var lineWidth = 2 * ele.pstyle("text-outline-width").pfValue;
25375 if (lineWidth > 0) {
25376 context.lineWidth = lineWidth;
25377 }
25378 if (ele.pstyle("text-wrap").value === "wrap") {
25379 var lines = getPrefixedProperty(rscratch, "labelWrapCachedLines", prefix);
25380 var lineHeight = getPrefixedProperty(rscratch, "labelLineHeight", prefix);
25381 var halfTextW = textW / 2;
25382 var justification = this.getLabelJustification(ele);
25383 if (justification === "auto")
25384 ;
25385 else if (halign === "left") {
25386 if (justification === "left") {
25387 textX += -textW;
25388 } else if (justification === "center") {
25389 textX += -halfTextW;
25390 }
25391 } else if (halign === "center") {
25392 if (justification === "left") {
25393 textX += -halfTextW;
25394 } else if (justification === "right") {
25395 textX += halfTextW;
25396 }
25397 } else if (halign === "right") {
25398 if (justification === "center") {
25399 textX += halfTextW;
25400 } else if (justification === "right") {
25401 textX += textW;
25402 }
25403 }
25404 switch (valign) {
25405 case "top":
25406 textY -= (lines.length - 1) * lineHeight;
25407 break;
25408 case "center":
25409 case "bottom":
25410 textY -= (lines.length - 1) * lineHeight;
25411 break;
25412 }
25413 for (var l = 0; l < lines.length; l++) {
25414 if (lineWidth > 0) {
25415 context.strokeText(lines[l], textX, textY);
25416 }
25417 context.fillText(lines[l], textX, textY);
25418 textY += lineHeight;
25419 }
25420 } else {
25421 if (lineWidth > 0) {
25422 context.strokeText(text, textX, textY);
25423 }
25424 context.fillText(text, textX, textY);
25425 }
25426 if (theta !== 0) {
25427 context.rotate(-theta);
25428 context.translate(-orgTextX, -orgTextY);
25429 }
25430 }
25431 };
25432 var CRp$5 = {};
25433 CRp$5.drawNode = function(context, node, shiftToOriginWithBb) {
25434 var drawLabel = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : true;
25435 var shouldDrawOverlay = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
25436 var shouldDrawOpacity = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : true;
25437 var r = this;
25438 var nodeWidth, nodeHeight;
25439 var _p = node._private;
25440 var rs = _p.rscratch;
25441 var pos = node.position();
25442 if (!number$1(pos.x) || !number$1(pos.y)) {
25443 return;
25444 }
25445 if (shouldDrawOpacity && !node.visible()) {
25446 return;
25447 }
25448 var eleOpacity = shouldDrawOpacity ? node.effectiveOpacity() : 1;
25449 var usePaths = r.usePaths();
25450 var path;
25451 var pathCacheHit = false;
25452 var padding = node.padding();
25453 nodeWidth = node.width() + 2 * padding;
25454 nodeHeight = node.height() + 2 * padding;
25455 var bb;
25456 if (shiftToOriginWithBb) {
25457 bb = shiftToOriginWithBb;
25458 context.translate(-bb.x1, -bb.y1);
25459 }
25460 var bgImgProp = node.pstyle("background-image");
25461 var urls = bgImgProp.value;
25462 var urlDefined = new Array(urls.length);
25463 var image = new Array(urls.length);
25464 var numImages = 0;
25465 for (var i2 = 0; i2 < urls.length; i2++) {
25466 var url = urls[i2];
25467 var defd = urlDefined[i2] = url != null && url !== "none";
25468 if (defd) {
25469 var bgImgCrossOrigin = node.cy().style().getIndexedStyle(node, "background-image-crossorigin", "value", i2);
25470 numImages++;
25471 image[i2] = r.getCachedImage(url, bgImgCrossOrigin, function() {
25472 _p.backgroundTimestamp = Date.now();
25473 node.emitAndNotify("background");
25474 });
25475 }
25476 }
25477 var darkness = node.pstyle("background-blacken").value;
25478 var borderWidth = node.pstyle("border-width").pfValue;
25479 var bgOpacity = node.pstyle("background-opacity").value * eleOpacity;
25480 var borderColor = node.pstyle("border-color").value;
25481 var borderStyle = node.pstyle("border-style").value;
25482 var borderOpacity = node.pstyle("border-opacity").value * eleOpacity;
25483 context.lineJoin = "miter";
25484 var setupShapeColor = function setupShapeColor2() {
25485 var bgOpy = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : bgOpacity;
25486 r.eleFillStyle(context, node, bgOpy);
25487 };
25488 var setupBorderColor = function setupBorderColor2() {
25489 var bdrOpy = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : borderOpacity;
25490 r.colorStrokeStyle(context, borderColor[0], borderColor[1], borderColor[2], bdrOpy);
25491 };
25492 var styleShape = node.pstyle("shape").strValue;
25493 var shapePts = node.pstyle("shape-polygon-points").pfValue;
25494 if (usePaths) {
25495 context.translate(pos.x, pos.y);
25496 var pathCache = r.nodePathCache = r.nodePathCache || [];
25497 var key = hashStrings(styleShape === "polygon" ? styleShape + "," + shapePts.join(",") : styleShape, "" + nodeHeight, "" + nodeWidth);
25498 var cachedPath = pathCache[key];
25499 if (cachedPath != null) {
25500 path = cachedPath;
25501 pathCacheHit = true;
25502 rs.pathCache = path;
25503 } else {
25504 path = new Path2D();
25505 pathCache[key] = rs.pathCache = path;
25506 }
25507 }
25508 var drawShape = function drawShape2() {
25509 if (!pathCacheHit) {
25510 var npos = pos;
25511 if (usePaths) {
25512 npos = {
25513 x: 0,
25514 y: 0
25515 };
25516 }
25517 r.nodeShapes[r.getNodeShape(node)].draw(path || context, npos.x, npos.y, nodeWidth, nodeHeight);
25518 }
25519 if (usePaths) {
25520 context.fill(path);
25521 } else {
25522 context.fill();
25523 }
25524 };
25525 var drawImages = function drawImages2() {
25526 var nodeOpacity = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : eleOpacity;
25527 var inside = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
25528 var prevBging = _p.backgrounding;
25529 var totalCompleted = 0;
25530 for (var _i = 0; _i < image.length; _i++) {
25531 var bgContainment = node.cy().style().getIndexedStyle(node, "background-image-containment", "value", _i);
25532 if (inside && bgContainment === "over" || !inside && bgContainment === "inside") {
25533 totalCompleted++;
25534 continue;
25535 }
25536 if (urlDefined[_i] && image[_i].complete && !image[_i].error) {
25537 totalCompleted++;
25538 r.drawInscribedImage(context, image[_i], node, _i, nodeOpacity);
25539 }
25540 }
25541 _p.backgrounding = !(totalCompleted === numImages);
25542 if (prevBging !== _p.backgrounding) {
25543 node.updateStyle(false);
25544 }
25545 };
25546 var drawPie = function drawPie2() {
25547 var redrawShape = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
25548 var pieOpacity = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : eleOpacity;
25549 if (r.hasPie(node)) {
25550 r.drawPie(context, node, pieOpacity);
25551 if (redrawShape) {
25552 if (!usePaths) {
25553 r.nodeShapes[r.getNodeShape(node)].draw(context, pos.x, pos.y, nodeWidth, nodeHeight);
25554 }
25555 }
25556 }
25557 };
25558 var darken2 = function darken3() {
25559 var darkenOpacity = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : eleOpacity;
25560 var opacity = (darkness > 0 ? darkness : -darkness) * darkenOpacity;
25561 var c = darkness > 0 ? 0 : 255;
25562 if (darkness !== 0) {
25563 r.colorFillStyle(context, c, c, c, opacity);
25564 if (usePaths) {
25565 context.fill(path);
25566 } else {
25567 context.fill();
25568 }
25569 }
25570 };
25571 var drawBorder = function drawBorder2() {
25572 if (borderWidth > 0) {
25573 context.lineWidth = borderWidth;
25574 context.lineCap = "butt";
25575 if (context.setLineDash) {
25576 switch (borderStyle) {
25577 case "dotted":
25578 context.setLineDash([1, 1]);
25579 break;
25580 case "dashed":
25581 context.setLineDash([4, 2]);
25582 break;
25583 case "solid":
25584 case "double":
25585 context.setLineDash([]);
25586 break;
25587 }
25588 }
25589 if (usePaths) {
25590 context.stroke(path);
25591 } else {
25592 context.stroke();
25593 }
25594 if (borderStyle === "double") {
25595 context.lineWidth = borderWidth / 3;
25596 var gco = context.globalCompositeOperation;
25597 context.globalCompositeOperation = "destination-out";
25598 if (usePaths) {
25599 context.stroke(path);
25600 } else {
25601 context.stroke();
25602 }
25603 context.globalCompositeOperation = gco;
25604 }
25605 if (context.setLineDash) {
25606 context.setLineDash([]);
25607 }
25608 }
25609 };
25610 var drawOverlay = function drawOverlay2() {
25611 if (shouldDrawOverlay) {
25612 r.drawNodeOverlay(context, node, pos, nodeWidth, nodeHeight);
25613 }
25614 };
25615 var drawUnderlay = function drawUnderlay2() {
25616 if (shouldDrawOverlay) {
25617 r.drawNodeUnderlay(context, node, pos, nodeWidth, nodeHeight);
25618 }
25619 };
25620 var drawText = function drawText2() {
25621 r.drawElementText(context, node, null, drawLabel);
25622 };
25623 var ghost = node.pstyle("ghost").value === "yes";
25624 if (ghost) {
25625 var gx = node.pstyle("ghost-offset-x").pfValue;
25626 var gy = node.pstyle("ghost-offset-y").pfValue;
25627 var ghostOpacity = node.pstyle("ghost-opacity").value;
25628 var effGhostOpacity = ghostOpacity * eleOpacity;
25629 context.translate(gx, gy);
25630 setupShapeColor(ghostOpacity * bgOpacity);
25631 drawShape();
25632 drawImages(effGhostOpacity, true);
25633 setupBorderColor(ghostOpacity * borderOpacity);
25634 drawBorder();
25635 drawPie(darkness !== 0 || borderWidth !== 0);
25636 drawImages(effGhostOpacity, false);
25637 darken2(effGhostOpacity);
25638 context.translate(-gx, -gy);
25639 }
25640 if (usePaths) {
25641 context.translate(-pos.x, -pos.y);
25642 }
25643 drawUnderlay();
25644 if (usePaths) {
25645 context.translate(pos.x, pos.y);
25646 }
25647 setupShapeColor();
25648 drawShape();
25649 drawImages(eleOpacity, true);
25650 setupBorderColor();
25651 drawBorder();
25652 drawPie(darkness !== 0 || borderWidth !== 0);
25653 drawImages(eleOpacity, false);
25654 darken2();
25655 if (usePaths) {
25656 context.translate(-pos.x, -pos.y);
25657 }
25658 drawText();
25659 drawOverlay();
25660 if (shiftToOriginWithBb) {
25661 context.translate(bb.x1, bb.y1);
25662 }
25663 };
25664 var drawNodeOverlayUnderlay = function drawNodeOverlayUnderlay2(overlayOrUnderlay) {
25665 if (!["overlay", "underlay"].includes(overlayOrUnderlay)) {
25666 throw new Error("Invalid state");
25667 }
25668 return function(context, node, pos, nodeWidth, nodeHeight) {
25669 var r = this;
25670 if (!node.visible()) {
25671 return;
25672 }
25673 var padding = node.pstyle("".concat(overlayOrUnderlay, "-padding")).pfValue;
25674 var opacity = node.pstyle("".concat(overlayOrUnderlay, "-opacity")).value;
25675 var color = node.pstyle("".concat(overlayOrUnderlay, "-color")).value;
25676 var shape = node.pstyle("".concat(overlayOrUnderlay, "-shape")).value;
25677 if (opacity > 0) {
25678 pos = pos || node.position();
25679 if (nodeWidth == null || nodeHeight == null) {
25680 var _padding = node.padding();
25681 nodeWidth = node.width() + 2 * _padding;
25682 nodeHeight = node.height() + 2 * _padding;
25683 }
25684 r.colorFillStyle(context, color[0], color[1], color[2], opacity);
25685 r.nodeShapes[shape].draw(context, pos.x, pos.y, nodeWidth + padding * 2, nodeHeight + padding * 2);
25686 context.fill();
25687 }
25688 };
25689 };
25690 CRp$5.drawNodeOverlay = drawNodeOverlayUnderlay("overlay");
25691 CRp$5.drawNodeUnderlay = drawNodeOverlayUnderlay("underlay");
25692 CRp$5.hasPie = function(node) {
25693 node = node[0];
25694 return node._private.hasPie;
25695 };
25696 CRp$5.drawPie = function(context, node, nodeOpacity, pos) {
25697 node = node[0];
25698 pos = pos || node.position();
25699 var cyStyle = node.cy().style();
25700 var pieSize = node.pstyle("pie-size");
25701 var x = pos.x;
25702 var y = pos.y;
25703 var nodeW = node.width();
25704 var nodeH = node.height();
25705 var radius = Math.min(nodeW, nodeH) / 2;
25706 var lastPercent = 0;
25707 var usePaths = this.usePaths();
25708 if (usePaths) {
25709 x = 0;
25710 y = 0;
25711 }
25712 if (pieSize.units === "%") {
25713 radius = radius * pieSize.pfValue;
25714 } else if (pieSize.pfValue !== void 0) {
25715 radius = pieSize.pfValue / 2;
25716 }
25717 for (var i2 = 1; i2 <= cyStyle.pieBackgroundN; i2++) {
25718 var size = node.pstyle("pie-" + i2 + "-background-size").value;
25719 var color = node.pstyle("pie-" + i2 + "-background-color").value;
25720 var opacity = node.pstyle("pie-" + i2 + "-background-opacity").value * nodeOpacity;
25721 var percent = size / 100;
25722 if (percent + lastPercent > 1) {
25723 percent = 1 - lastPercent;
25724 }
25725 var angleStart = 1.5 * Math.PI + 2 * Math.PI * lastPercent;
25726 var angleDelta = 2 * Math.PI * percent;
25727 var angleEnd = angleStart + angleDelta;
25728 if (size === 0 || lastPercent >= 1 || lastPercent + percent > 1) {
25729 continue;
25730 }
25731 context.beginPath();
25732 context.moveTo(x, y);
25733 context.arc(x, y, radius, angleStart, angleEnd);
25734 context.closePath();
25735 this.colorFillStyle(context, color[0], color[1], color[2], opacity);
25736 context.fill();
25737 lastPercent += percent;
25738 }
25739 };
25740 var CRp$4 = {};
25741 var motionBlurDelay = 100;
25742 CRp$4.getPixelRatio = function() {
25743 var context = this.data.contexts[0];
25744 if (this.forcedPixelRatio != null) {
25745 return this.forcedPixelRatio;
25746 }
25747 var backingStore = context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1;
25748 return (window.devicePixelRatio || 1) / backingStore;
25749 };
25750 CRp$4.paintCache = function(context) {
25751 var caches = this.paintCaches = this.paintCaches || [];
25752 var needToCreateCache = true;
25753 var cache2;
25754 for (var i2 = 0; i2 < caches.length; i2++) {
25755 cache2 = caches[i2];
25756 if (cache2.context === context) {
25757 needToCreateCache = false;
25758 break;
25759 }
25760 }
25761 if (needToCreateCache) {
25762 cache2 = {
25763 context
25764 };
25765 caches.push(cache2);
25766 }
25767 return cache2;
25768 };
25769 CRp$4.createGradientStyleFor = function(context, shapeStyleName, ele, fill, opacity) {
25770 var gradientStyle;
25771 var usePaths = this.usePaths();
25772 var colors2 = ele.pstyle(shapeStyleName + "-gradient-stop-colors").value, positions = ele.pstyle(shapeStyleName + "-gradient-stop-positions").pfValue;
25773 if (fill === "radial-gradient") {
25774 if (ele.isEdge()) {
25775 var start = ele.sourceEndpoint(), end = ele.targetEndpoint(), mid = ele.midpoint();
25776 var d1 = dist(start, mid);
25777 var d2 = dist(end, mid);
25778 gradientStyle = context.createRadialGradient(mid.x, mid.y, 0, mid.x, mid.y, Math.max(d1, d2));
25779 } else {
25780 var pos = usePaths ? {
25781 x: 0,
25782 y: 0
25783 } : ele.position(), width = ele.paddedWidth(), height = ele.paddedHeight();
25784 gradientStyle = context.createRadialGradient(pos.x, pos.y, 0, pos.x, pos.y, Math.max(width, height));
25785 }
25786 } else {
25787 if (ele.isEdge()) {
25788 var _start = ele.sourceEndpoint(), _end = ele.targetEndpoint();
25789 gradientStyle = context.createLinearGradient(_start.x, _start.y, _end.x, _end.y);
25790 } else {
25791 var _pos = usePaths ? {
25792 x: 0,
25793 y: 0
25794 } : ele.position(), _width = ele.paddedWidth(), _height = ele.paddedHeight(), halfWidth = _width / 2, halfHeight = _height / 2;
25795 var direction = ele.pstyle("background-gradient-direction").value;
25796 switch (direction) {
25797 case "to-bottom":
25798 gradientStyle = context.createLinearGradient(_pos.x, _pos.y - halfHeight, _pos.x, _pos.y + halfHeight);
25799 break;
25800 case "to-top":
25801 gradientStyle = context.createLinearGradient(_pos.x, _pos.y + halfHeight, _pos.x, _pos.y - halfHeight);
25802 break;
25803 case "to-left":
25804 gradientStyle = context.createLinearGradient(_pos.x + halfWidth, _pos.y, _pos.x - halfWidth, _pos.y);
25805 break;
25806 case "to-right":
25807 gradientStyle = context.createLinearGradient(_pos.x - halfWidth, _pos.y, _pos.x + halfWidth, _pos.y);
25808 break;
25809 case "to-bottom-right":
25810 case "to-right-bottom":
25811 gradientStyle = context.createLinearGradient(_pos.x - halfWidth, _pos.y - halfHeight, _pos.x + halfWidth, _pos.y + halfHeight);
25812 break;
25813 case "to-top-right":
25814 case "to-right-top":
25815 gradientStyle = context.createLinearGradient(_pos.x - halfWidth, _pos.y + halfHeight, _pos.x + halfWidth, _pos.y - halfHeight);
25816 break;
25817 case "to-bottom-left":
25818 case "to-left-bottom":
25819 gradientStyle = context.createLinearGradient(_pos.x + halfWidth, _pos.y - halfHeight, _pos.x - halfWidth, _pos.y + halfHeight);
25820 break;
25821 case "to-top-left":
25822 case "to-left-top":
25823 gradientStyle = context.createLinearGradient(_pos.x + halfWidth, _pos.y + halfHeight, _pos.x - halfWidth, _pos.y - halfHeight);
25824 break;
25825 }
25826 }
25827 }
25828 if (!gradientStyle)
25829 return null;
25830 var hasPositions = positions.length === colors2.length;
25831 var length = colors2.length;
25832 for (var i2 = 0; i2 < length; i2++) {
25833 gradientStyle.addColorStop(hasPositions ? positions[i2] : i2 / (length - 1), "rgba(" + colors2[i2][0] + "," + colors2[i2][1] + "," + colors2[i2][2] + "," + opacity + ")");
25834 }
25835 return gradientStyle;
25836 };
25837 CRp$4.gradientFillStyle = function(context, ele, fill, opacity) {
25838 var gradientStyle = this.createGradientStyleFor(context, "background", ele, fill, opacity);
25839 if (!gradientStyle)
25840 return null;
25841 context.fillStyle = gradientStyle;
25842 };
25843 CRp$4.colorFillStyle = function(context, r, g, b, a) {
25844 context.fillStyle = "rgba(" + r + "," + g + "," + b + "," + a + ")";
25845 };
25846 CRp$4.eleFillStyle = function(context, ele, opacity) {
25847 var backgroundFill = ele.pstyle("background-fill").value;
25848 if (backgroundFill === "linear-gradient" || backgroundFill === "radial-gradient") {
25849 this.gradientFillStyle(context, ele, backgroundFill, opacity);
25850 } else {
25851 var backgroundColor = ele.pstyle("background-color").value;
25852 this.colorFillStyle(context, backgroundColor[0], backgroundColor[1], backgroundColor[2], opacity);
25853 }
25854 };
25855 CRp$4.gradientStrokeStyle = function(context, ele, fill, opacity) {
25856 var gradientStyle = this.createGradientStyleFor(context, "line", ele, fill, opacity);
25857 if (!gradientStyle)
25858 return null;
25859 context.strokeStyle = gradientStyle;
25860 };
25861 CRp$4.colorStrokeStyle = function(context, r, g, b, a) {
25862 context.strokeStyle = "rgba(" + r + "," + g + "," + b + "," + a + ")";
25863 };
25864 CRp$4.eleStrokeStyle = function(context, ele, opacity) {
25865 var lineFill = ele.pstyle("line-fill").value;
25866 if (lineFill === "linear-gradient" || lineFill === "radial-gradient") {
25867 this.gradientStrokeStyle(context, ele, lineFill, opacity);
25868 } else {
25869 var lineColor = ele.pstyle("line-color").value;
25870 this.colorStrokeStyle(context, lineColor[0], lineColor[1], lineColor[2], opacity);
25871 }
25872 };
25873 CRp$4.matchCanvasSize = function(container) {
25874 var r = this;
25875 var data2 = r.data;
25876 var bb = r.findContainerClientCoords();
25877 var width = bb[2];
25878 var height = bb[3];
25879 var pixelRatio = r.getPixelRatio();
25880 var mbPxRatio = r.motionBlurPxRatio;
25881 if (container === r.data.bufferCanvases[r.MOTIONBLUR_BUFFER_NODE] || container === r.data.bufferCanvases[r.MOTIONBLUR_BUFFER_DRAG]) {
25882 pixelRatio = mbPxRatio;
25883 }
25884 var canvasWidth = width * pixelRatio;
25885 var canvasHeight = height * pixelRatio;
25886 var canvas;
25887 if (canvasWidth === r.canvasWidth && canvasHeight === r.canvasHeight) {
25888 return;
25889 }
25890 r.fontCaches = null;
25891 var canvasContainer = data2.canvasContainer;
25892 canvasContainer.style.width = width + "px";
25893 canvasContainer.style.height = height + "px";
25894 for (var i2 = 0; i2 < r.CANVAS_LAYERS; i2++) {
25895 canvas = data2.canvases[i2];
25896 canvas.width = canvasWidth;
25897 canvas.height = canvasHeight;
25898 canvas.style.width = width + "px";
25899 canvas.style.height = height + "px";
25900 }
25901 for (var i2 = 0; i2 < r.BUFFER_COUNT; i2++) {
25902 canvas = data2.bufferCanvases[i2];
25903 canvas.width = canvasWidth;
25904 canvas.height = canvasHeight;
25905 canvas.style.width = width + "px";
25906 canvas.style.height = height + "px";
25907 }
25908 r.textureMult = 1;
25909 if (pixelRatio <= 1) {
25910 canvas = data2.bufferCanvases[r.TEXTURE_BUFFER];
25911 r.textureMult = 2;
25912 canvas.width = canvasWidth * r.textureMult;
25913 canvas.height = canvasHeight * r.textureMult;
25914 }
25915 r.canvasWidth = canvasWidth;
25916 r.canvasHeight = canvasHeight;
25917 };
25918 CRp$4.renderTo = function(cxt, zoom, pan, pxRatio) {
25919 this.render({
25920 forcedContext: cxt,
25921 forcedZoom: zoom,
25922 forcedPan: pan,
25923 drawAllLayers: true,
25924 forcedPxRatio: pxRatio
25925 });
25926 };
25927 CRp$4.render = function(options) {
25928 options = options || staticEmptyObject();
25929 var forcedContext = options.forcedContext;
25930 var drawAllLayers = options.drawAllLayers;
25931 var drawOnlyNodeLayer = options.drawOnlyNodeLayer;
25932 var forcedZoom = options.forcedZoom;
25933 var forcedPan = options.forcedPan;
25934 var r = this;
25935 var pixelRatio = options.forcedPxRatio === void 0 ? this.getPixelRatio() : options.forcedPxRatio;
25936 var cy = r.cy;
25937 var data2 = r.data;
25938 var needDraw = data2.canvasNeedsRedraw;
25939 var textureDraw = r.textureOnViewport && !forcedContext && (r.pinching || r.hoverData.dragging || r.swipePanning || r.data.wheelZooming);
25940 var motionBlur = options.motionBlur !== void 0 ? options.motionBlur : r.motionBlur;
25941 var mbPxRatio = r.motionBlurPxRatio;
25942 var hasCompoundNodes = cy.hasCompoundNodes();
25943 var inNodeDragGesture = r.hoverData.draggingEles;
25944 var inBoxSelection = r.hoverData.selecting || r.touchData.selecting ? true : false;
25945 motionBlur = motionBlur && !forcedContext && r.motionBlurEnabled && !inBoxSelection;
25946 var motionBlurFadeEffect = motionBlur;
25947 if (!forcedContext) {
25948 if (r.prevPxRatio !== pixelRatio) {
25949 r.invalidateContainerClientCoordsCache();
25950 r.matchCanvasSize(r.container);
25951 r.redrawHint("eles", true);
25952 r.redrawHint("drag", true);
25953 }
25954 r.prevPxRatio = pixelRatio;
25955 }
25956 if (!forcedContext && r.motionBlurTimeout) {
25957 clearTimeout(r.motionBlurTimeout);
25958 }
25959 if (motionBlur) {
25960 if (r.mbFrames == null) {
25961 r.mbFrames = 0;
25962 }
25963 r.mbFrames++;
25964 if (r.mbFrames < 3) {
25965 motionBlurFadeEffect = false;
25966 }
25967 if (r.mbFrames > r.minMbLowQualFrames) {
25968 r.motionBlurPxRatio = r.mbPxRBlurry;
25969 }
25970 }
25971 if (r.clearingMotionBlur) {
25972 r.motionBlurPxRatio = 1;
25973 }
25974 if (r.textureDrawLastFrame && !textureDraw) {
25975 needDraw[r.NODE] = true;
25976 needDraw[r.SELECT_BOX] = true;
25977 }
25978 var style = cy.style();
25979 var zoom = cy.zoom();
25980 var effectiveZoom = forcedZoom !== void 0 ? forcedZoom : zoom;
25981 var pan = cy.pan();
25982 var effectivePan = {
25983 x: pan.x,
25984 y: pan.y
25985 };
25986 var vp = {
25987 zoom,
25988 pan: {
25989 x: pan.x,
25990 y: pan.y
25991 }
25992 };
25993 var prevVp = r.prevViewport;
25994 var viewportIsDiff = prevVp === void 0 || vp.zoom !== prevVp.zoom || vp.pan.x !== prevVp.pan.x || vp.pan.y !== prevVp.pan.y;
25995 if (!viewportIsDiff && !(inNodeDragGesture && !hasCompoundNodes)) {
25996 r.motionBlurPxRatio = 1;
25997 }
25998 if (forcedPan) {
25999 effectivePan = forcedPan;
26000 }
26001 effectiveZoom *= pixelRatio;
26002 effectivePan.x *= pixelRatio;
26003 effectivePan.y *= pixelRatio;
26004 var eles = r.getCachedZSortedEles();
26005 function mbclear(context2, x, y, w, h) {
26006 var gco = context2.globalCompositeOperation;
26007 context2.globalCompositeOperation = "destination-out";
26008 r.colorFillStyle(context2, 255, 255, 255, r.motionBlurTransparency);
26009 context2.fillRect(x, y, w, h);
26010 context2.globalCompositeOperation = gco;
26011 }
26012 function setContextTransform(context2, clear3) {
26013 var ePan, eZoom, w, h;
26014 if (!r.clearingMotionBlur && (context2 === data2.bufferContexts[r.MOTIONBLUR_BUFFER_NODE] || context2 === data2.bufferContexts[r.MOTIONBLUR_BUFFER_DRAG])) {
26015 ePan = {
26016 x: pan.x * mbPxRatio,
26017 y: pan.y * mbPxRatio
26018 };
26019 eZoom = zoom * mbPxRatio;
26020 w = r.canvasWidth * mbPxRatio;
26021 h = r.canvasHeight * mbPxRatio;
26022 } else {
26023 ePan = effectivePan;
26024 eZoom = effectiveZoom;
26025 w = r.canvasWidth;
26026 h = r.canvasHeight;
26027 }
26028 context2.setTransform(1, 0, 0, 1, 0, 0);
26029 if (clear3 === "motionBlur") {
26030 mbclear(context2, 0, 0, w, h);
26031 } else if (!forcedContext && (clear3 === void 0 || clear3)) {
26032 context2.clearRect(0, 0, w, h);
26033 }
26034 if (!drawAllLayers) {
26035 context2.translate(ePan.x, ePan.y);
26036 context2.scale(eZoom, eZoom);
26037 }
26038 if (forcedPan) {
26039 context2.translate(forcedPan.x, forcedPan.y);
26040 }
26041 if (forcedZoom) {
26042 context2.scale(forcedZoom, forcedZoom);
26043 }
26044 }
26045 if (!textureDraw) {
26046 r.textureDrawLastFrame = false;
26047 }
26048 if (textureDraw) {
26049 r.textureDrawLastFrame = true;
26050 if (!r.textureCache) {
26051 r.textureCache = {};
26052 r.textureCache.bb = cy.mutableElements().boundingBox();
26053 r.textureCache.texture = r.data.bufferCanvases[r.TEXTURE_BUFFER];
26054 var cxt = r.data.bufferContexts[r.TEXTURE_BUFFER];
26055 cxt.setTransform(1, 0, 0, 1, 0, 0);
26056 cxt.clearRect(0, 0, r.canvasWidth * r.textureMult, r.canvasHeight * r.textureMult);
26057 r.render({
26058 forcedContext: cxt,
26059 drawOnlyNodeLayer: true,
26060 forcedPxRatio: pixelRatio * r.textureMult
26061 });
26062 var vp = r.textureCache.viewport = {
26063 zoom: cy.zoom(),
26064 pan: cy.pan(),
26065 width: r.canvasWidth,
26066 height: r.canvasHeight
26067 };
26068 vp.mpan = {
26069 x: (0 - vp.pan.x) / vp.zoom,
26070 y: (0 - vp.pan.y) / vp.zoom
26071 };
26072 }
26073 needDraw[r.DRAG] = false;
26074 needDraw[r.NODE] = false;
26075 var context = data2.contexts[r.NODE];
26076 var texture = r.textureCache.texture;
26077 var vp = r.textureCache.viewport;
26078 context.setTransform(1, 0, 0, 1, 0, 0);
26079 if (motionBlur) {
26080 mbclear(context, 0, 0, vp.width, vp.height);
26081 } else {
26082 context.clearRect(0, 0, vp.width, vp.height);
26083 }
26084 var outsideBgColor = style.core("outside-texture-bg-color").value;
26085 var outsideBgOpacity = style.core("outside-texture-bg-opacity").value;
26086 r.colorFillStyle(context, outsideBgColor[0], outsideBgColor[1], outsideBgColor[2], outsideBgOpacity);
26087 context.fillRect(0, 0, vp.width, vp.height);
26088 var zoom = cy.zoom();
26089 setContextTransform(context, false);
26090 context.clearRect(vp.mpan.x, vp.mpan.y, vp.width / vp.zoom / pixelRatio, vp.height / vp.zoom / pixelRatio);
26091 context.drawImage(texture, vp.mpan.x, vp.mpan.y, vp.width / vp.zoom / pixelRatio, vp.height / vp.zoom / pixelRatio);
26092 } else if (r.textureOnViewport && !forcedContext) {
26093 r.textureCache = null;
26094 }
26095 var extent = cy.extent();
26096 var vpManip = r.pinching || r.hoverData.dragging || r.swipePanning || r.data.wheelZooming || r.hoverData.draggingEles || r.cy.animated();
26097 var hideEdges = r.hideEdgesOnViewport && vpManip;
26098 var needMbClear = [];
26099 needMbClear[r.NODE] = !needDraw[r.NODE] && motionBlur && !r.clearedForMotionBlur[r.NODE] || r.clearingMotionBlur;
26100 if (needMbClear[r.NODE]) {
26101 r.clearedForMotionBlur[r.NODE] = true;
26102 }
26103 needMbClear[r.DRAG] = !needDraw[r.DRAG] && motionBlur && !r.clearedForMotionBlur[r.DRAG] || r.clearingMotionBlur;
26104 if (needMbClear[r.DRAG]) {
26105 r.clearedForMotionBlur[r.DRAG] = true;
26106 }
26107 if (needDraw[r.NODE] || drawAllLayers || drawOnlyNodeLayer || needMbClear[r.NODE]) {
26108 var useBuffer = motionBlur && !needMbClear[r.NODE] && mbPxRatio !== 1;
26109 var context = forcedContext || (useBuffer ? r.data.bufferContexts[r.MOTIONBLUR_BUFFER_NODE] : data2.contexts[r.NODE]);
26110 var clear2 = motionBlur && !useBuffer ? "motionBlur" : void 0;
26111 setContextTransform(context, clear2);
26112 if (hideEdges) {
26113 r.drawCachedNodes(context, eles.nondrag, pixelRatio, extent);
26114 } else {
26115 r.drawLayeredElements(context, eles.nondrag, pixelRatio, extent);
26116 }
26117 if (r.debug) {
26118 r.drawDebugPoints(context, eles.nondrag);
26119 }
26120 if (!drawAllLayers && !motionBlur) {
26121 needDraw[r.NODE] = false;
26122 }
26123 }
26124 if (!drawOnlyNodeLayer && (needDraw[r.DRAG] || drawAllLayers || needMbClear[r.DRAG])) {
26125 var useBuffer = motionBlur && !needMbClear[r.DRAG] && mbPxRatio !== 1;
26126 var context = forcedContext || (useBuffer ? r.data.bufferContexts[r.MOTIONBLUR_BUFFER_DRAG] : data2.contexts[r.DRAG]);
26127 setContextTransform(context, motionBlur && !useBuffer ? "motionBlur" : void 0);
26128 if (hideEdges) {
26129 r.drawCachedNodes(context, eles.drag, pixelRatio, extent);
26130 } else {
26131 r.drawCachedElements(context, eles.drag, pixelRatio, extent);
26132 }
26133 if (r.debug) {
26134 r.drawDebugPoints(context, eles.drag);
26135 }
26136 if (!drawAllLayers && !motionBlur) {
26137 needDraw[r.DRAG] = false;
26138 }
26139 }
26140 if (r.showFps || !drawOnlyNodeLayer && needDraw[r.SELECT_BOX] && !drawAllLayers) {
26141 var context = forcedContext || data2.contexts[r.SELECT_BOX];
26142 setContextTransform(context);
26143 if (r.selection[4] == 1 && (r.hoverData.selecting || r.touchData.selecting)) {
26144 var zoom = r.cy.zoom();
26145 var borderWidth = style.core("selection-box-border-width").value / zoom;
26146 context.lineWidth = borderWidth;
26147 context.fillStyle = "rgba(" + style.core("selection-box-color").value[0] + "," + style.core("selection-box-color").value[1] + "," + style.core("selection-box-color").value[2] + "," + style.core("selection-box-opacity").value + ")";
26148 context.fillRect(r.selection[0], r.selection[1], r.selection[2] - r.selection[0], r.selection[3] - r.selection[1]);
26149 if (borderWidth > 0) {
26150 context.strokeStyle = "rgba(" + style.core("selection-box-border-color").value[0] + "," + style.core("selection-box-border-color").value[1] + "," + style.core("selection-box-border-color").value[2] + "," + style.core("selection-box-opacity").value + ")";
26151 context.strokeRect(r.selection[0], r.selection[1], r.selection[2] - r.selection[0], r.selection[3] - r.selection[1]);
26152 }
26153 }
26154 if (data2.bgActivePosistion && !r.hoverData.selecting) {
26155 var zoom = r.cy.zoom();
26156 var pos = data2.bgActivePosistion;
26157 context.fillStyle = "rgba(" + style.core("active-bg-color").value[0] + "," + style.core("active-bg-color").value[1] + "," + style.core("active-bg-color").value[2] + "," + style.core("active-bg-opacity").value + ")";
26158 context.beginPath();
26159 context.arc(pos.x, pos.y, style.core("active-bg-size").pfValue / zoom, 0, 2 * Math.PI);
26160 context.fill();
26161 }
26162 var timeToRender = r.lastRedrawTime;
26163 if (r.showFps && timeToRender) {
26164 timeToRender = Math.round(timeToRender);
26165 var fps = Math.round(1e3 / timeToRender);
26166 context.setTransform(1, 0, 0, 1, 0, 0);
26167 context.fillStyle = "rgba(255, 0, 0, 0.75)";
26168 context.strokeStyle = "rgba(255, 0, 0, 0.75)";
26169 context.lineWidth = 1;
26170 context.fillText("1 frame = " + timeToRender + " ms = " + fps + " fps", 0, 20);
26171 var maxFps = 60;
26172 context.strokeRect(0, 30, 250, 20);
26173 context.fillRect(0, 30, 250 * Math.min(fps / maxFps, 1), 20);
26174 }
26175 if (!drawAllLayers) {
26176 needDraw[r.SELECT_BOX] = false;
26177 }
26178 }
26179 if (motionBlur && mbPxRatio !== 1) {
26180 var cxtNode = data2.contexts[r.NODE];
26181 var txtNode = r.data.bufferCanvases[r.MOTIONBLUR_BUFFER_NODE];
26182 var cxtDrag = data2.contexts[r.DRAG];
26183 var txtDrag = r.data.bufferCanvases[r.MOTIONBLUR_BUFFER_DRAG];
26184 var drawMotionBlur = function drawMotionBlur2(cxt2, txt, needClear) {
26185 cxt2.setTransform(1, 0, 0, 1, 0, 0);
26186 if (needClear || !motionBlurFadeEffect) {
26187 cxt2.clearRect(0, 0, r.canvasWidth, r.canvasHeight);
26188 } else {
26189 mbclear(cxt2, 0, 0, r.canvasWidth, r.canvasHeight);
26190 }
26191 var pxr = mbPxRatio;
26192 cxt2.drawImage(
26193 txt,
26194 // img
26195 0,
26196 0,
26197 // sx, sy
26198 r.canvasWidth * pxr,
26199 r.canvasHeight * pxr,
26200 // sw, sh
26201 0,
26202 0,
26203 // x, y
26204 r.canvasWidth,
26205 r.canvasHeight
26206 // w, h
26207 );
26208 };
26209 if (needDraw[r.NODE] || needMbClear[r.NODE]) {
26210 drawMotionBlur(cxtNode, txtNode, needMbClear[r.NODE]);
26211 needDraw[r.NODE] = false;
26212 }
26213 if (needDraw[r.DRAG] || needMbClear[r.DRAG]) {
26214 drawMotionBlur(cxtDrag, txtDrag, needMbClear[r.DRAG]);
26215 needDraw[r.DRAG] = false;
26216 }
26217 }
26218 r.prevViewport = vp;
26219 if (r.clearingMotionBlur) {
26220 r.clearingMotionBlur = false;
26221 r.motionBlurCleared = true;
26222 r.motionBlur = true;
26223 }
26224 if (motionBlur) {
26225 r.motionBlurTimeout = setTimeout(function() {
26226 r.motionBlurTimeout = null;
26227 r.clearedForMotionBlur[r.NODE] = false;
26228 r.clearedForMotionBlur[r.DRAG] = false;
26229 r.motionBlur = false;
26230 r.clearingMotionBlur = !textureDraw;
26231 r.mbFrames = 0;
26232 needDraw[r.NODE] = true;
26233 needDraw[r.DRAG] = true;
26234 r.redraw();
26235 }, motionBlurDelay);
26236 }
26237 if (!forcedContext) {
26238 cy.emit("render");
26239 }
26240 };
26241 var CRp$3 = {};
26242 CRp$3.drawPolygonPath = function(context, x, y, width, height, points) {
26243 var halfW = width / 2;
26244 var halfH = height / 2;
26245 if (context.beginPath) {
26246 context.beginPath();
26247 }
26248 context.moveTo(x + halfW * points[0], y + halfH * points[1]);
26249 for (var i2 = 1; i2 < points.length / 2; i2++) {
26250 context.lineTo(x + halfW * points[i2 * 2], y + halfH * points[i2 * 2 + 1]);
26251 }
26252 context.closePath();
26253 };
26254 CRp$3.drawRoundPolygonPath = function(context, x, y, width, height, points) {
26255 var halfW = width / 2;
26256 var halfH = height / 2;
26257 var cornerRadius = getRoundPolygonRadius(width, height);
26258 if (context.beginPath) {
26259 context.beginPath();
26260 }
26261 for (var _i = 0; _i < points.length / 4; _i++) {
26262 var sourceUv = void 0, destUv = void 0;
26263 if (_i === 0) {
26264 sourceUv = points.length - 2;
26265 } else {
26266 sourceUv = _i * 4 - 2;
26267 }
26268 destUv = _i * 4 + 2;
26269 var px = x + halfW * points[_i * 4];
26270 var py = y + halfH * points[_i * 4 + 1];
26271 var cosTheta = -points[sourceUv] * points[destUv] - points[sourceUv + 1] * points[destUv + 1];
26272 var offset = cornerRadius / Math.tan(Math.acos(cosTheta) / 2);
26273 var cp0x = px - offset * points[sourceUv];
26274 var cp0y = py - offset * points[sourceUv + 1];
26275 var cp1x = px + offset * points[destUv];
26276 var cp1y = py + offset * points[destUv + 1];
26277 if (_i === 0) {
26278 context.moveTo(cp0x, cp0y);
26279 } else {
26280 context.lineTo(cp0x, cp0y);
26281 }
26282 context.arcTo(px, py, cp1x, cp1y, cornerRadius);
26283 }
26284 context.closePath();
26285 };
26286 CRp$3.drawRoundRectanglePath = function(context, x, y, width, height) {
26287 var halfWidth = width / 2;
26288 var halfHeight = height / 2;
26289 var cornerRadius = getRoundRectangleRadius(width, height);
26290 if (context.beginPath) {
26291 context.beginPath();
26292 }
26293 context.moveTo(x, y - halfHeight);
26294 context.arcTo(x + halfWidth, y - halfHeight, x + halfWidth, y, cornerRadius);
26295 context.arcTo(x + halfWidth, y + halfHeight, x, y + halfHeight, cornerRadius);
26296 context.arcTo(x - halfWidth, y + halfHeight, x - halfWidth, y, cornerRadius);
26297 context.arcTo(x - halfWidth, y - halfHeight, x, y - halfHeight, cornerRadius);
26298 context.lineTo(x, y - halfHeight);
26299 context.closePath();
26300 };
26301 CRp$3.drawBottomRoundRectanglePath = function(context, x, y, width, height) {
26302 var halfWidth = width / 2;
26303 var halfHeight = height / 2;
26304 var cornerRadius = getRoundRectangleRadius(width, height);
26305 if (context.beginPath) {
26306 context.beginPath();
26307 }
26308 context.moveTo(x, y - halfHeight);
26309 context.lineTo(x + halfWidth, y - halfHeight);
26310 context.lineTo(x + halfWidth, y);
26311 context.arcTo(x + halfWidth, y + halfHeight, x, y + halfHeight, cornerRadius);
26312 context.arcTo(x - halfWidth, y + halfHeight, x - halfWidth, y, cornerRadius);
26313 context.lineTo(x - halfWidth, y - halfHeight);
26314 context.lineTo(x, y - halfHeight);
26315 context.closePath();
26316 };
26317 CRp$3.drawCutRectanglePath = function(context, x, y, width, height) {
26318 var halfWidth = width / 2;
26319 var halfHeight = height / 2;
26320 var cornerLength = getCutRectangleCornerLength();
26321 if (context.beginPath) {
26322 context.beginPath();
26323 }
26324 context.moveTo(x - halfWidth + cornerLength, y - halfHeight);
26325 context.lineTo(x + halfWidth - cornerLength, y - halfHeight);
26326 context.lineTo(x + halfWidth, y - halfHeight + cornerLength);
26327 context.lineTo(x + halfWidth, y + halfHeight - cornerLength);
26328 context.lineTo(x + halfWidth - cornerLength, y + halfHeight);
26329 context.lineTo(x - halfWidth + cornerLength, y + halfHeight);
26330 context.lineTo(x - halfWidth, y + halfHeight - cornerLength);
26331 context.lineTo(x - halfWidth, y - halfHeight + cornerLength);
26332 context.closePath();
26333 };
26334 CRp$3.drawBarrelPath = function(context, x, y, width, height) {
26335 var halfWidth = width / 2;
26336 var halfHeight = height / 2;
26337 var xBegin = x - halfWidth;
26338 var xEnd = x + halfWidth;
26339 var yBegin = y - halfHeight;
26340 var yEnd = y + halfHeight;
26341 var barrelCurveConstants = getBarrelCurveConstants(width, height);
26342 var wOffset = barrelCurveConstants.widthOffset;
26343 var hOffset = barrelCurveConstants.heightOffset;
26344 var ctrlPtXOffset = barrelCurveConstants.ctrlPtOffsetPct * wOffset;
26345 if (context.beginPath) {
26346 context.beginPath();
26347 }
26348 context.moveTo(xBegin, yBegin + hOffset);
26349 context.lineTo(xBegin, yEnd - hOffset);
26350 context.quadraticCurveTo(xBegin + ctrlPtXOffset, yEnd, xBegin + wOffset, yEnd);
26351 context.lineTo(xEnd - wOffset, yEnd);
26352 context.quadraticCurveTo(xEnd - ctrlPtXOffset, yEnd, xEnd, yEnd - hOffset);
26353 context.lineTo(xEnd, yBegin + hOffset);
26354 context.quadraticCurveTo(xEnd - ctrlPtXOffset, yBegin, xEnd - wOffset, yBegin);
26355 context.lineTo(xBegin + wOffset, yBegin);
26356 context.quadraticCurveTo(xBegin + ctrlPtXOffset, yBegin, xBegin, yBegin + hOffset);
26357 context.closePath();
26358 };
26359 var sin0 = Math.sin(0);
26360 var cos0 = Math.cos(0);
26361 var sin = {};
26362 var cos = {};
26363 var ellipseStepSize = Math.PI / 40;
26364 for (var i = 0 * Math.PI; i < 2 * Math.PI; i += ellipseStepSize) {
26365 sin[i] = Math.sin(i);
26366 cos[i] = Math.cos(i);
26367 }
26368 CRp$3.drawEllipsePath = function(context, centerX, centerY, width, height) {
26369 if (context.beginPath) {
26370 context.beginPath();
26371 }
26372 if (context.ellipse) {
26373 context.ellipse(centerX, centerY, width / 2, height / 2, 0, 0, 2 * Math.PI);
26374 } else {
26375 var xPos, yPos;
26376 var rw = width / 2;
26377 var rh = height / 2;
26378 for (var i2 = 0 * Math.PI; i2 < 2 * Math.PI; i2 += ellipseStepSize) {
26379 xPos = centerX - rw * sin[i2] * sin0 + rw * cos[i2] * cos0;
26380 yPos = centerY + rh * cos[i2] * sin0 + rh * sin[i2] * cos0;
26381 if (i2 === 0) {
26382 context.moveTo(xPos, yPos);
26383 } else {
26384 context.lineTo(xPos, yPos);
26385 }
26386 }
26387 }
26388 context.closePath();
26389 };
26390 var CRp$2 = {};
26391 CRp$2.createBuffer = function(w, h) {
26392 var buffer = document.createElement("canvas");
26393 buffer.width = w;
26394 buffer.height = h;
26395 return [buffer, buffer.getContext("2d")];
26396 };
26397 CRp$2.bufferCanvasImage = function(options) {
26398 var cy = this.cy;
26399 var eles = cy.mutableElements();
26400 var bb = eles.boundingBox();
26401 var ctrRect = this.findContainerClientCoords();
26402 var width = options.full ? Math.ceil(bb.w) : ctrRect[2];
26403 var height = options.full ? Math.ceil(bb.h) : ctrRect[3];
26404 var specdMaxDims = number$1(options.maxWidth) || number$1(options.maxHeight);
26405 var pxRatio = this.getPixelRatio();
26406 var scale = 1;
26407 if (options.scale !== void 0) {
26408 width *= options.scale;
26409 height *= options.scale;
26410 scale = options.scale;
26411 } else if (specdMaxDims) {
26412 var maxScaleW = Infinity;
26413 var maxScaleH = Infinity;
26414 if (number$1(options.maxWidth)) {
26415 maxScaleW = scale * options.maxWidth / width;
26416 }
26417 if (number$1(options.maxHeight)) {
26418 maxScaleH = scale * options.maxHeight / height;
26419 }
26420 scale = Math.min(maxScaleW, maxScaleH);
26421 width *= scale;
26422 height *= scale;
26423 }
26424 if (!specdMaxDims) {
26425 width *= pxRatio;
26426 height *= pxRatio;
26427 scale *= pxRatio;
26428 }
26429 var buffCanvas = document.createElement("canvas");
26430 buffCanvas.width = width;
26431 buffCanvas.height = height;
26432 buffCanvas.style.width = width + "px";
26433 buffCanvas.style.height = height + "px";
26434 var buffCxt = buffCanvas.getContext("2d");
26435 if (width > 0 && height > 0) {
26436 buffCxt.clearRect(0, 0, width, height);
26437 buffCxt.globalCompositeOperation = "source-over";
26438 var zsortedEles = this.getCachedZSortedEles();
26439 if (options.full) {
26440 buffCxt.translate(-bb.x1 * scale, -bb.y1 * scale);
26441 buffCxt.scale(scale, scale);
26442 this.drawElements(buffCxt, zsortedEles);
26443 buffCxt.scale(1 / scale, 1 / scale);
26444 buffCxt.translate(bb.x1 * scale, bb.y1 * scale);
26445 } else {
26446 var pan = cy.pan();
26447 var translation = {
26448 x: pan.x * scale,
26449 y: pan.y * scale
26450 };
26451 scale *= cy.zoom();
26452 buffCxt.translate(translation.x, translation.y);
26453 buffCxt.scale(scale, scale);
26454 this.drawElements(buffCxt, zsortedEles);
26455 buffCxt.scale(1 / scale, 1 / scale);
26456 buffCxt.translate(-translation.x, -translation.y);
26457 }
26458 if (options.bg) {
26459 buffCxt.globalCompositeOperation = "destination-over";
26460 buffCxt.fillStyle = options.bg;
26461 buffCxt.rect(0, 0, width, height);
26462 buffCxt.fill();
26463 }
26464 }
26465 return buffCanvas;
26466 };
26467 function b64ToBlob(b64, mimeType) {
26468 var bytes = atob(b64);
26469 var buff = new ArrayBuffer(bytes.length);
26470 var buffUint8 = new Uint8Array(buff);
26471 for (var i2 = 0; i2 < bytes.length; i2++) {
26472 buffUint8[i2] = bytes.charCodeAt(i2);
26473 }
26474 return new Blob([buff], {
26475 type: mimeType
26476 });
26477 }
26478 function b64UriToB64(b64uri) {
26479 var i2 = b64uri.indexOf(",");
26480 return b64uri.substr(i2 + 1);
26481 }
26482 function output(options, canvas, mimeType) {
26483 var getB64Uri = function getB64Uri2() {
26484 return canvas.toDataURL(mimeType, options.quality);
26485 };
26486 switch (options.output) {
26487 case "blob-promise":
26488 return new Promise$1(function(resolve2, reject) {
26489 try {
26490 canvas.toBlob(function(blob) {
26491 if (blob != null) {
26492 resolve2(blob);
26493 } else {
26494 reject(new Error("`canvas.toBlob()` sent a null value in its callback"));
26495 }
26496 }, mimeType, options.quality);
26497 } catch (err) {
26498 reject(err);
26499 }
26500 });
26501 case "blob":
26502 return b64ToBlob(b64UriToB64(getB64Uri()), mimeType);
26503 case "base64":
26504 return b64UriToB64(getB64Uri());
26505 case "base64uri":
26506 default:
26507 return getB64Uri();
26508 }
26509 }
26510 CRp$2.png = function(options) {
26511 return output(options, this.bufferCanvasImage(options), "image/png");
26512 };
26513 CRp$2.jpg = function(options) {
26514 return output(options, this.bufferCanvasImage(options), "image/jpeg");
26515 };
26516 var CRp$1 = {};
26517 CRp$1.nodeShapeImpl = function(name2, context, centerX, centerY, width, height, points) {
26518 switch (name2) {
26519 case "ellipse":
26520 return this.drawEllipsePath(context, centerX, centerY, width, height);
26521 case "polygon":
26522 return this.drawPolygonPath(context, centerX, centerY, width, height, points);
26523 case "round-polygon":
26524 return this.drawRoundPolygonPath(context, centerX, centerY, width, height, points);
26525 case "roundrectangle":
26526 case "round-rectangle":
26527 return this.drawRoundRectanglePath(context, centerX, centerY, width, height);
26528 case "cutrectangle":
26529 case "cut-rectangle":
26530 return this.drawCutRectanglePath(context, centerX, centerY, width, height);
26531 case "bottomroundrectangle":
26532 case "bottom-round-rectangle":
26533 return this.drawBottomRoundRectanglePath(context, centerX, centerY, width, height);
26534 case "barrel":
26535 return this.drawBarrelPath(context, centerX, centerY, width, height);
26536 }
26537 };
26538 var CR = CanvasRenderer;
26539 var CRp = CanvasRenderer.prototype;
26540 CRp.CANVAS_LAYERS = 3;
26541 CRp.SELECT_BOX = 0;
26542 CRp.DRAG = 1;
26543 CRp.NODE = 2;
26544 CRp.BUFFER_COUNT = 3;
26545 CRp.TEXTURE_BUFFER = 0;
26546 CRp.MOTIONBLUR_BUFFER_NODE = 1;
26547 CRp.MOTIONBLUR_BUFFER_DRAG = 2;
26548 function CanvasRenderer(options) {
26549 var r = this;
26550 r.data = {
26551 canvases: new Array(CRp.CANVAS_LAYERS),
26552 contexts: new Array(CRp.CANVAS_LAYERS),
26553 canvasNeedsRedraw: new Array(CRp.CANVAS_LAYERS),
26554 bufferCanvases: new Array(CRp.BUFFER_COUNT),
26555 bufferContexts: new Array(CRp.CANVAS_LAYERS)
26556 };
26557 var tapHlOffAttr = "-webkit-tap-highlight-color";
26558 var tapHlOffStyle = "rgba(0,0,0,0)";
26559 r.data.canvasContainer = document.createElement("div");
26560 var containerStyle = r.data.canvasContainer.style;
26561 r.data.canvasContainer.style[tapHlOffAttr] = tapHlOffStyle;
26562 containerStyle.position = "relative";
26563 containerStyle.zIndex = "0";
26564 containerStyle.overflow = "hidden";
26565 var container = options.cy.container();
26566 container.appendChild(r.data.canvasContainer);
26567 container.style[tapHlOffAttr] = tapHlOffStyle;
26568 var styleMap = {
26569 "-webkit-user-select": "none",
26570 "-moz-user-select": "-moz-none",
26571 "user-select": "none",
26572 "-webkit-tap-highlight-color": "rgba(0,0,0,0)",
26573 "outline-style": "none"
26574 };
26575 if (ms()) {
26576 styleMap["-ms-touch-action"] = "none";
26577 styleMap["touch-action"] = "none";
26578 }
26579 for (var i2 = 0; i2 < CRp.CANVAS_LAYERS; i2++) {
26580 var canvas = r.data.canvases[i2] = document.createElement("canvas");
26581 r.data.contexts[i2] = canvas.getContext("2d");
26582 Object.keys(styleMap).forEach(function(k) {
26583 canvas.style[k] = styleMap[k];
26584 });
26585 canvas.style.position = "absolute";
26586 canvas.setAttribute("data-id", "layer" + i2);
26587 canvas.style.zIndex = String(CRp.CANVAS_LAYERS - i2);
26588 r.data.canvasContainer.appendChild(canvas);
26589 r.data.canvasNeedsRedraw[i2] = false;
26590 }
26591 r.data.topCanvas = r.data.canvases[0];
26592 r.data.canvases[CRp.NODE].setAttribute("data-id", "layer" + CRp.NODE + "-node");
26593 r.data.canvases[CRp.SELECT_BOX].setAttribute("data-id", "layer" + CRp.SELECT_BOX + "-selectbox");
26594 r.data.canvases[CRp.DRAG].setAttribute("data-id", "layer" + CRp.DRAG + "-drag");
26595 for (var i2 = 0; i2 < CRp.BUFFER_COUNT; i2++) {
26596 r.data.bufferCanvases[i2] = document.createElement("canvas");
26597 r.data.bufferContexts[i2] = r.data.bufferCanvases[i2].getContext("2d");
26598 r.data.bufferCanvases[i2].style.position = "absolute";
26599 r.data.bufferCanvases[i2].setAttribute("data-id", "buffer" + i2);
26600 r.data.bufferCanvases[i2].style.zIndex = String(-i2 - 1);
26601 r.data.bufferCanvases[i2].style.visibility = "hidden";
26602 }
26603 r.pathsEnabled = true;
26604 var emptyBb = makeBoundingBox();
26605 var getBoxCenter = function getBoxCenter2(bb) {
26606 return {
26607 x: (bb.x1 + bb.x2) / 2,
26608 y: (bb.y1 + bb.y2) / 2
26609 };
26610 };
26611 var getCenterOffset = function getCenterOffset2(bb) {
26612 return {
26613 x: -bb.w / 2,
26614 y: -bb.h / 2
26615 };
26616 };
26617 var backgroundTimestampHasChanged = function backgroundTimestampHasChanged2(ele) {
26618 var _p = ele[0]._private;
26619 var same = _p.oldBackgroundTimestamp === _p.backgroundTimestamp;
26620 return !same;
26621 };
26622 var getStyleKey = function getStyleKey2(ele) {
26623 return ele[0]._private.nodeKey;
26624 };
26625 var getLabelKey = function getLabelKey2(ele) {
26626 return ele[0]._private.labelStyleKey;
26627 };
26628 var getSourceLabelKey = function getSourceLabelKey2(ele) {
26629 return ele[0]._private.sourceLabelStyleKey;
26630 };
26631 var getTargetLabelKey = function getTargetLabelKey2(ele) {
26632 return ele[0]._private.targetLabelStyleKey;
26633 };
26634 var drawElement = function drawElement2(context, ele, bb, scaledLabelShown, useEleOpacity) {
26635 return r.drawElement(context, ele, bb, false, false, useEleOpacity);
26636 };
26637 var drawLabel = function drawLabel2(context, ele, bb, scaledLabelShown, useEleOpacity) {
26638 return r.drawElementText(context, ele, bb, scaledLabelShown, "main", useEleOpacity);
26639 };
26640 var drawSourceLabel = function drawSourceLabel2(context, ele, bb, scaledLabelShown, useEleOpacity) {
26641 return r.drawElementText(context, ele, bb, scaledLabelShown, "source", useEleOpacity);
26642 };
26643 var drawTargetLabel = function drawTargetLabel2(context, ele, bb, scaledLabelShown, useEleOpacity) {
26644 return r.drawElementText(context, ele, bb, scaledLabelShown, "target", useEleOpacity);
26645 };
26646 var getElementBox = function getElementBox2(ele) {
26647 ele.boundingBox();
26648 return ele[0]._private.bodyBounds;
26649 };
26650 var getLabelBox = function getLabelBox2(ele) {
26651 ele.boundingBox();
26652 return ele[0]._private.labelBounds.main || emptyBb;
26653 };
26654 var getSourceLabelBox = function getSourceLabelBox2(ele) {
26655 ele.boundingBox();
26656 return ele[0]._private.labelBounds.source || emptyBb;
26657 };
26658 var getTargetLabelBox = function getTargetLabelBox2(ele) {
26659 ele.boundingBox();
26660 return ele[0]._private.labelBounds.target || emptyBb;
26661 };
26662 var isLabelVisibleAtScale = function isLabelVisibleAtScale2(ele, scaledLabelShown) {
26663 return scaledLabelShown;
26664 };
26665 var getElementRotationPoint = function getElementRotationPoint2(ele) {
26666 return getBoxCenter(getElementBox(ele));
26667 };
26668 var addTextMargin = function addTextMargin2(prefix, pt, ele) {
26669 var pre = prefix ? prefix + "-" : "";
26670 return {
26671 x: pt.x + ele.pstyle(pre + "text-margin-x").pfValue,
26672 y: pt.y + ele.pstyle(pre + "text-margin-y").pfValue
26673 };
26674 };
26675 var getRsPt = function getRsPt2(ele, x, y) {
26676 var rs = ele[0]._private.rscratch;
26677 return {
26678 x: rs[x],
26679 y: rs[y]
26680 };
26681 };
26682 var getLabelRotationPoint = function getLabelRotationPoint2(ele) {
26683 return addTextMargin("", getRsPt(ele, "labelX", "labelY"), ele);
26684 };
26685 var getSourceLabelRotationPoint = function getSourceLabelRotationPoint2(ele) {
26686 return addTextMargin("source", getRsPt(ele, "sourceLabelX", "sourceLabelY"), ele);
26687 };
26688 var getTargetLabelRotationPoint = function getTargetLabelRotationPoint2(ele) {
26689 return addTextMargin("target", getRsPt(ele, "targetLabelX", "targetLabelY"), ele);
26690 };
26691 var getElementRotationOffset = function getElementRotationOffset2(ele) {
26692 return getCenterOffset(getElementBox(ele));
26693 };
26694 var getSourceLabelRotationOffset = function getSourceLabelRotationOffset2(ele) {
26695 return getCenterOffset(getSourceLabelBox(ele));
26696 };
26697 var getTargetLabelRotationOffset = function getTargetLabelRotationOffset2(ele) {
26698 return getCenterOffset(getTargetLabelBox(ele));
26699 };
26700 var getLabelRotationOffset = function getLabelRotationOffset2(ele) {
26701 var bb = getLabelBox(ele);
26702 var p2 = getCenterOffset(getLabelBox(ele));
26703 if (ele.isNode()) {
26704 switch (ele.pstyle("text-halign").value) {
26705 case "left":
26706 p2.x = -bb.w;
26707 break;
26708 case "right":
26709 p2.x = 0;
26710 break;
26711 }
26712 switch (ele.pstyle("text-valign").value) {
26713 case "top":
26714 p2.y = -bb.h;
26715 break;
26716 case "bottom":
26717 p2.y = 0;
26718 break;
26719 }
26720 }
26721 return p2;
26722 };
26723 var eleTxrCache = r.data.eleTxrCache = new ElementTextureCache(r, {
26724 getKey: getStyleKey,
26725 doesEleInvalidateKey: backgroundTimestampHasChanged,
26726 drawElement,
26727 getBoundingBox: getElementBox,
26728 getRotationPoint: getElementRotationPoint,
26729 getRotationOffset: getElementRotationOffset,
26730 allowEdgeTxrCaching: false,
26731 allowParentTxrCaching: false
26732 });
26733 var lblTxrCache = r.data.lblTxrCache = new ElementTextureCache(r, {
26734 getKey: getLabelKey,
26735 drawElement: drawLabel,
26736 getBoundingBox: getLabelBox,
26737 getRotationPoint: getLabelRotationPoint,
26738 getRotationOffset: getLabelRotationOffset,
26739 isVisible: isLabelVisibleAtScale
26740 });
26741 var slbTxrCache = r.data.slbTxrCache = new ElementTextureCache(r, {
26742 getKey: getSourceLabelKey,
26743 drawElement: drawSourceLabel,
26744 getBoundingBox: getSourceLabelBox,
26745 getRotationPoint: getSourceLabelRotationPoint,
26746 getRotationOffset: getSourceLabelRotationOffset,
26747 isVisible: isLabelVisibleAtScale
26748 });
26749 var tlbTxrCache = r.data.tlbTxrCache = new ElementTextureCache(r, {
26750 getKey: getTargetLabelKey,
26751 drawElement: drawTargetLabel,
26752 getBoundingBox: getTargetLabelBox,
26753 getRotationPoint: getTargetLabelRotationPoint,
26754 getRotationOffset: getTargetLabelRotationOffset,
26755 isVisible: isLabelVisibleAtScale
26756 });
26757 var lyrTxrCache = r.data.lyrTxrCache = new LayeredTextureCache(r);
26758 r.onUpdateEleCalcs(function invalidateTextureCaches(willDraw, eles) {
26759 eleTxrCache.invalidateElements(eles);
26760 lblTxrCache.invalidateElements(eles);
26761 slbTxrCache.invalidateElements(eles);
26762 tlbTxrCache.invalidateElements(eles);
26763 lyrTxrCache.invalidateElements(eles);
26764 for (var _i = 0; _i < eles.length; _i++) {
26765 var _p = eles[_i]._private;
26766 _p.oldBackgroundTimestamp = _p.backgroundTimestamp;
26767 }
26768 });
26769 var refineInLayers = function refineInLayers2(reqs) {
26770 for (var i3 = 0; i3 < reqs.length; i3++) {
26771 lyrTxrCache.enqueueElementRefinement(reqs[i3].ele);
26772 }
26773 };
26774 eleTxrCache.onDequeue(refineInLayers);
26775 lblTxrCache.onDequeue(refineInLayers);
26776 slbTxrCache.onDequeue(refineInLayers);
26777 tlbTxrCache.onDequeue(refineInLayers);
26778 }
26779 CRp.redrawHint = function(group, bool) {
26780 var r = this;
26781 switch (group) {
26782 case "eles":
26783 r.data.canvasNeedsRedraw[CRp.NODE] = bool;
26784 break;
26785 case "drag":
26786 r.data.canvasNeedsRedraw[CRp.DRAG] = bool;
26787 break;
26788 case "select":
26789 r.data.canvasNeedsRedraw[CRp.SELECT_BOX] = bool;
26790 break;
26791 }
26792 };
26793 var pathsImpld = typeof Path2D !== "undefined";
26794 CRp.path2dEnabled = function(on) {
26795 if (on === void 0) {
26796 return this.pathsEnabled;
26797 }
26798 this.pathsEnabled = on ? true : false;
26799 };
26800 CRp.usePaths = function() {
26801 return pathsImpld && this.pathsEnabled;
26802 };
26803 CRp.setImgSmoothing = function(context, bool) {
26804 if (context.imageSmoothingEnabled != null) {
26805 context.imageSmoothingEnabled = bool;
26806 } else {
26807 context.webkitImageSmoothingEnabled = bool;
26808 context.mozImageSmoothingEnabled = bool;
26809 context.msImageSmoothingEnabled = bool;
26810 }
26811 };
26812 CRp.getImgSmoothing = function(context) {
26813 if (context.imageSmoothingEnabled != null) {
26814 return context.imageSmoothingEnabled;
26815 } else {
26816 return context.webkitImageSmoothingEnabled || context.mozImageSmoothingEnabled || context.msImageSmoothingEnabled;
26817 }
26818 };
26819 CRp.makeOffscreenCanvas = function(width, height) {
26820 var canvas;
26821 if ((typeof OffscreenCanvas === "undefined" ? "undefined" : _typeof(OffscreenCanvas)) !== "undefined") {
26822 canvas = new OffscreenCanvas(width, height);
26823 } else {
26824 canvas = document.createElement("canvas");
26825 canvas.width = width;
26826 canvas.height = height;
26827 }
26828 return canvas;
26829 };
26830 [CRp$a, CRp$9, CRp$8, CRp$7, CRp$6, CRp$5, CRp$4, CRp$3, CRp$2, CRp$1].forEach(function(props) {
26831 extend(CRp, props);
26832 });
26833 var renderer = [{
26834 name: "null",
26835 impl: NullRenderer
26836 }, {
26837 name: "base",
26838 impl: BR
26839 }, {
26840 name: "canvas",
26841 impl: CR
26842 }];
26843 var incExts = [{
26844 type: "layout",
26845 extensions: layout
26846 }, {
26847 type: "renderer",
26848 extensions: renderer
26849 }];
26850 var extensions = {};
26851 var modules = {};
26852 function setExtension(type, name2, registrant) {
26853 var ext = registrant;
26854 var overrideErr = function overrideErr2(field) {
26855 warn("Can not register `" + name2 + "` for `" + type + "` since `" + field + "` already exists in the prototype and can not be overridden");
26856 };
26857 if (type === "core") {
26858 if (Core.prototype[name2]) {
26859 return overrideErr(name2);
26860 } else {
26861 Core.prototype[name2] = registrant;
26862 }
26863 } else if (type === "collection") {
26864 if (Collection.prototype[name2]) {
26865 return overrideErr(name2);
26866 } else {
26867 Collection.prototype[name2] = registrant;
26868 }
26869 } else if (type === "layout") {
26870 var Layout2 = function Layout3(options) {
26871 this.options = options;
26872 registrant.call(this, options);
26873 if (!plainObject(this._private)) {
26874 this._private = {};
26875 }
26876 this._private.cy = options.cy;
26877 this._private.listeners = [];
26878 this.createEmitter();
26879 };
26880 var layoutProto = Layout2.prototype = Object.create(registrant.prototype);
26881 var optLayoutFns = [];
26882 for (var i2 = 0; i2 < optLayoutFns.length; i2++) {
26883 var fnName = optLayoutFns[i2];
26884 layoutProto[fnName] = layoutProto[fnName] || function() {
26885 return this;
26886 };
26887 }
26888 if (layoutProto.start && !layoutProto.run) {
26889 layoutProto.run = function() {
26890 this.start();
26891 return this;
26892 };
26893 } else if (!layoutProto.start && layoutProto.run) {
26894 layoutProto.start = function() {
26895 this.run();
26896 return this;
26897 };
26898 }
26899 var regStop = registrant.prototype.stop;
26900 layoutProto.stop = function() {
26901 var opts = this.options;
26902 if (opts && opts.animate) {
26903 var anis = this.animations;
26904 if (anis) {
26905 for (var _i = 0; _i < anis.length; _i++) {
26906 anis[_i].stop();
26907 }
26908 }
26909 }
26910 if (regStop) {
26911 regStop.call(this);
26912 } else {
26913 this.emit("layoutstop");
26914 }
26915 return this;
26916 };
26917 if (!layoutProto.destroy) {
26918 layoutProto.destroy = function() {
26919 return this;
26920 };
26921 }
26922 layoutProto.cy = function() {
26923 return this._private.cy;
26924 };
26925 var getCy = function getCy2(layout2) {
26926 return layout2._private.cy;
26927 };
26928 var emitterOpts = {
26929 addEventFields: function addEventFields(layout2, evt) {
26930 evt.layout = layout2;
26931 evt.cy = getCy(layout2);
26932 evt.target = layout2;
26933 },
26934 bubble: function bubble() {
26935 return true;
26936 },
26937 parent: function parent(layout2) {
26938 return getCy(layout2);
26939 }
26940 };
26941 extend(layoutProto, {
26942 createEmitter: function createEmitter() {
26943 this._private.emitter = new Emitter(emitterOpts, this);
26944 return this;
26945 },
26946 emitter: function emitter() {
26947 return this._private.emitter;
26948 },
26949 on: function on(evt, cb) {
26950 this.emitter().on(evt, cb);
26951 return this;
26952 },
26953 one: function one(evt, cb) {
26954 this.emitter().one(evt, cb);
26955 return this;
26956 },
26957 once: function once(evt, cb) {
26958 this.emitter().one(evt, cb);
26959 return this;
26960 },
26961 removeListener: function removeListener(evt, cb) {
26962 this.emitter().removeListener(evt, cb);
26963 return this;
26964 },
26965 removeAllListeners: function removeAllListeners() {
26966 this.emitter().removeAllListeners();
26967 return this;
26968 },
26969 emit: function emit(evt, params) {
26970 this.emitter().emit(evt, params);
26971 return this;
26972 }
26973 });
26974 define.eventAliasesOn(layoutProto);
26975 ext = Layout2;
26976 } else if (type === "renderer" && name2 !== "null" && name2 !== "base") {
26977 var BaseRenderer2 = getExtension("renderer", "base");
26978 var bProto = BaseRenderer2.prototype;
26979 var RegistrantRenderer = registrant;
26980 var rProto = registrant.prototype;
26981 var Renderer = function Renderer2() {
26982 BaseRenderer2.apply(this, arguments);
26983 RegistrantRenderer.apply(this, arguments);
26984 };
26985 var proto = Renderer.prototype;
26986 for (var pName in bProto) {
26987 var pVal = bProto[pName];
26988 var existsInR = rProto[pName] != null;
26989 if (existsInR) {
26990 return overrideErr(pName);
26991 }
26992 proto[pName] = pVal;
26993 }
26994 for (var _pName in rProto) {
26995 proto[_pName] = rProto[_pName];
26996 }
26997 bProto.clientFunctions.forEach(function(name3) {
26998 proto[name3] = proto[name3] || function() {
26999 error("Renderer does not implement `renderer." + name3 + "()` on its prototype");
27000 };
27001 });
27002 ext = Renderer;
27003 } else if (type === "__proto__" || type === "constructor" || type === "prototype") {
27004 return error(type + " is an illegal type to be registered, possibly lead to prototype pollutions");
27005 }
27006 return setMap({
27007 map: extensions,
27008 keys: [type, name2],
27009 value: ext
27010 });
27011 }
27012 function getExtension(type, name2) {
27013 return getMap({
27014 map: extensions,
27015 keys: [type, name2]
27016 });
27017 }
27018 function setModule(type, name2, moduleType, moduleName, registrant) {
27019 return setMap({
27020 map: modules,
27021 keys: [type, name2, moduleType, moduleName],
27022 value: registrant
27023 });
27024 }
27025 function getModule(type, name2, moduleType, moduleName) {
27026 return getMap({
27027 map: modules,
27028 keys: [type, name2, moduleType, moduleName]
27029 });
27030 }
27031 var extension = function extension2() {
27032 if (arguments.length === 2) {
27033 return getExtension.apply(null, arguments);
27034 } else if (arguments.length === 3) {
27035 return setExtension.apply(null, arguments);
27036 } else if (arguments.length === 4) {
27037 return getModule.apply(null, arguments);
27038 } else if (arguments.length === 5) {
27039 return setModule.apply(null, arguments);
27040 } else {
27041 error("Invalid extension access syntax");
27042 }
27043 };
27044 Core.prototype.extension = extension;
27045 incExts.forEach(function(group) {
27046 group.extensions.forEach(function(ext) {
27047 setExtension(group.type, ext.name, ext.impl);
27048 });
27049 });
27050 var Stylesheet = function Stylesheet2() {
27051 if (!(this instanceof Stylesheet2)) {
27052 return new Stylesheet2();
27053 }
27054 this.length = 0;
27055 };
27056 var sheetfn = Stylesheet.prototype;
27057 sheetfn.instanceString = function() {
27058 return "stylesheet";
27059 };
27060 sheetfn.selector = function(selector) {
27061 var i2 = this.length++;
27062 this[i2] = {
27063 selector,
27064 properties: []
27065 };
27066 return this;
27067 };
27068 sheetfn.css = function(name2, value) {
27069 var i2 = this.length - 1;
27070 if (string(name2)) {
27071 this[i2].properties.push({
27072 name: name2,
27073 value
27074 });
27075 } else if (plainObject(name2)) {
27076 var map = name2;
27077 var propNames = Object.keys(map);
27078 for (var j = 0; j < propNames.length; j++) {
27079 var key = propNames[j];
27080 var mapVal = map[key];
27081 if (mapVal == null) {
27082 continue;
27083 }
27084 var prop = Style.properties[key] || Style.properties[dash2camel(key)];
27085 if (prop == null) {
27086 continue;
27087 }
27088 var _name = prop.name;
27089 var _value = mapVal;
27090 this[i2].properties.push({
27091 name: _name,
27092 value: _value
27093 });
27094 }
27095 }
27096 return this;
27097 };
27098 sheetfn.style = sheetfn.css;
27099 sheetfn.generateStyle = function(cy) {
27100 var style = new Style(cy);
27101 return this.appendToStyle(style);
27102 };
27103 sheetfn.appendToStyle = function(style) {
27104 for (var i2 = 0; i2 < this.length; i2++) {
27105 var context = this[i2];
27106 var selector = context.selector;
27107 var props = context.properties;
27108 style.selector(selector);
27109 for (var j = 0; j < props.length; j++) {
27110 var prop = props[j];
27111 style.css(prop.name, prop.value);
27112 }
27113 }
27114 return style;
27115 };
27116 var version = "3.23.0";
27117 var cytoscape2 = function cytoscape3(options) {
27118 if (options === void 0) {
27119 options = {};
27120 }
27121 if (plainObject(options)) {
27122 return new Core(options);
27123 } else if (string(options)) {
27124 return extension.apply(extension, arguments);
27125 }
27126 };
27127 cytoscape2.use = function(ext) {
27128 var args = Array.prototype.slice.call(arguments, 1);
27129 args.unshift(cytoscape2);
27130 ext.apply(null, args);
27131 return this;
27132 };
27133 cytoscape2.warnings = function(bool) {
27134 return warnings(bool);
27135 };
27136 cytoscape2.version = version;
27137 cytoscape2.stylesheet = cytoscape2.Stylesheet = Stylesheet;
27138 return cytoscape2;
27139 });
27140})(cytoscape_umd);
27141const cytoscape$1 = cytoscape_umdExports;
27142var cytoscapeCoseBilkentExports = {};
27143var cytoscapeCoseBilkent = {
27144 get exports() {
27145 return cytoscapeCoseBilkentExports;
27146 },
27147 set exports(v) {
27148 cytoscapeCoseBilkentExports = v;
27149 }
27150};
27151var coseBaseExports = {};
27152var coseBase = {
27153 get exports() {
27154 return coseBaseExports;
27155 },
27156 set exports(v) {
27157 coseBaseExports = v;
27158 }
27159};
27160var layoutBaseExports = {};
27161var layoutBase = {
27162 get exports() {
27163 return layoutBaseExports;
27164 },
27165 set exports(v) {
27166 layoutBaseExports = v;
27167 }
27168};
27169var hasRequiredLayoutBase;
27170function requireLayoutBase() {
27171 if (hasRequiredLayoutBase)
27172 return layoutBaseExports;
27173 hasRequiredLayoutBase = 1;
27174 (function(module, exports) {
27175 (function webpackUniversalModuleDefinition(root, factory) {
27176 module.exports = factory();
27177 })(commonjsGlobal, function() {
27178 return (
27179 /******/
27180 function(modules) {
27181 var installedModules = {};
27182 function __webpack_require__(moduleId) {
27183 if (installedModules[moduleId]) {
27184 return installedModules[moduleId].exports;
27185 }
27186 var module2 = installedModules[moduleId] = {
27187 /******/
27188 i: moduleId,
27189 /******/
27190 l: false,
27191 /******/
27192 exports: {}
27193 /******/
27194 };
27195 modules[moduleId].call(module2.exports, module2, module2.exports, __webpack_require__);
27196 module2.l = true;
27197 return module2.exports;
27198 }
27199 __webpack_require__.m = modules;
27200 __webpack_require__.c = installedModules;
27201 __webpack_require__.i = function(value) {
27202 return value;
27203 };
27204 __webpack_require__.d = function(exports2, name2, getter) {
27205 if (!__webpack_require__.o(exports2, name2)) {
27206 Object.defineProperty(exports2, name2, {
27207 /******/
27208 configurable: false,
27209 /******/
27210 enumerable: true,
27211 /******/
27212 get: getter
27213 /******/
27214 });
27215 }
27216 };
27217 __webpack_require__.n = function(module2) {
27218 var getter = module2 && module2.__esModule ? (
27219 /******/
27220 function getDefault() {
27221 return module2["default"];
27222 }
27223 ) : (
27224 /******/
27225 function getModuleExports() {
27226 return module2;
27227 }
27228 );
27229 __webpack_require__.d(getter, "a", getter);
27230 return getter;
27231 };
27232 __webpack_require__.o = function(object, property) {
27233 return Object.prototype.hasOwnProperty.call(object, property);
27234 };
27235 __webpack_require__.p = "";
27236 return __webpack_require__(__webpack_require__.s = 26);
27237 }([
27238 /* 0 */
27239 /***/
27240 function(module2, exports2, __webpack_require__) {
27241 function LayoutConstants() {
27242 }
27243 LayoutConstants.QUALITY = 1;
27244 LayoutConstants.DEFAULT_CREATE_BENDS_AS_NEEDED = false;
27245 LayoutConstants.DEFAULT_INCREMENTAL = false;
27246 LayoutConstants.DEFAULT_ANIMATION_ON_LAYOUT = true;
27247 LayoutConstants.DEFAULT_ANIMATION_DURING_LAYOUT = false;
27248 LayoutConstants.DEFAULT_ANIMATION_PERIOD = 50;
27249 LayoutConstants.DEFAULT_UNIFORM_LEAF_NODE_SIZES = false;
27250 LayoutConstants.DEFAULT_GRAPH_MARGIN = 15;
27251 LayoutConstants.NODE_DIMENSIONS_INCLUDE_LABELS = false;
27252 LayoutConstants.SIMPLE_NODE_SIZE = 40;
27253 LayoutConstants.SIMPLE_NODE_HALF_SIZE = LayoutConstants.SIMPLE_NODE_SIZE / 2;
27254 LayoutConstants.EMPTY_COMPOUND_NODE_SIZE = 40;
27255 LayoutConstants.MIN_EDGE_LENGTH = 1;
27256 LayoutConstants.WORLD_BOUNDARY = 1e6;
27257 LayoutConstants.INITIAL_WORLD_BOUNDARY = LayoutConstants.WORLD_BOUNDARY / 1e3;
27258 LayoutConstants.WORLD_CENTER_X = 1200;
27259 LayoutConstants.WORLD_CENTER_Y = 900;
27260 module2.exports = LayoutConstants;
27261 },
27262 /* 1 */
27263 /***/
27264 function(module2, exports2, __webpack_require__) {
27265 var LGraphObject = __webpack_require__(2);
27266 var IGeometry = __webpack_require__(8);
27267 var IMath = __webpack_require__(9);
27268 function LEdge(source, target, vEdge) {
27269 LGraphObject.call(this, vEdge);
27270 this.isOverlapingSourceAndTarget = false;
27271 this.vGraphObject = vEdge;
27272 this.bendpoints = [];
27273 this.source = source;
27274 this.target = target;
27275 }
27276 LEdge.prototype = Object.create(LGraphObject.prototype);
27277 for (var prop in LGraphObject) {
27278 LEdge[prop] = LGraphObject[prop];
27279 }
27280 LEdge.prototype.getSource = function() {
27281 return this.source;
27282 };
27283 LEdge.prototype.getTarget = function() {
27284 return this.target;
27285 };
27286 LEdge.prototype.isInterGraph = function() {
27287 return this.isInterGraph;
27288 };
27289 LEdge.prototype.getLength = function() {
27290 return this.length;
27291 };
27292 LEdge.prototype.isOverlapingSourceAndTarget = function() {
27293 return this.isOverlapingSourceAndTarget;
27294 };
27295 LEdge.prototype.getBendpoints = function() {
27296 return this.bendpoints;
27297 };
27298 LEdge.prototype.getLca = function() {
27299 return this.lca;
27300 };
27301 LEdge.prototype.getSourceInLca = function() {
27302 return this.sourceInLca;
27303 };
27304 LEdge.prototype.getTargetInLca = function() {
27305 return this.targetInLca;
27306 };
27307 LEdge.prototype.getOtherEnd = function(node) {
27308 if (this.source === node) {
27309 return this.target;
27310 } else if (this.target === node) {
27311 return this.source;
27312 } else {
27313 throw "Node is not incident with this edge";
27314 }
27315 };
27316 LEdge.prototype.getOtherEndInGraph = function(node, graph) {
27317 var otherEnd = this.getOtherEnd(node);
27318 var root = graph.getGraphManager().getRoot();
27319 while (true) {
27320 if (otherEnd.getOwner() == graph) {
27321 return otherEnd;
27322 }
27323 if (otherEnd.getOwner() == root) {
27324 break;
27325 }
27326 otherEnd = otherEnd.getOwner().getParent();
27327 }
27328 return null;
27329 };
27330 LEdge.prototype.updateLength = function() {
27331 var clipPointCoordinates = new Array(4);
27332 this.isOverlapingSourceAndTarget = IGeometry.getIntersection(this.target.getRect(), this.source.getRect(), clipPointCoordinates);
27333 if (!this.isOverlapingSourceAndTarget) {
27334 this.lengthX = clipPointCoordinates[0] - clipPointCoordinates[2];
27335 this.lengthY = clipPointCoordinates[1] - clipPointCoordinates[3];
27336 if (Math.abs(this.lengthX) < 1) {
27337 this.lengthX = IMath.sign(this.lengthX);
27338 }
27339 if (Math.abs(this.lengthY) < 1) {
27340 this.lengthY = IMath.sign(this.lengthY);
27341 }
27342 this.length = Math.sqrt(this.lengthX * this.lengthX + this.lengthY * this.lengthY);
27343 }
27344 };
27345 LEdge.prototype.updateLengthSimple = function() {
27346 this.lengthX = this.target.getCenterX() - this.source.getCenterX();
27347 this.lengthY = this.target.getCenterY() - this.source.getCenterY();
27348 if (Math.abs(this.lengthX) < 1) {
27349 this.lengthX = IMath.sign(this.lengthX);
27350 }
27351 if (Math.abs(this.lengthY) < 1) {
27352 this.lengthY = IMath.sign(this.lengthY);
27353 }
27354 this.length = Math.sqrt(this.lengthX * this.lengthX + this.lengthY * this.lengthY);
27355 };
27356 module2.exports = LEdge;
27357 },
27358 /* 2 */
27359 /***/
27360 function(module2, exports2, __webpack_require__) {
27361 function LGraphObject(vGraphObject) {
27362 this.vGraphObject = vGraphObject;
27363 }
27364 module2.exports = LGraphObject;
27365 },
27366 /* 3 */
27367 /***/
27368 function(module2, exports2, __webpack_require__) {
27369 var LGraphObject = __webpack_require__(2);
27370 var Integer = __webpack_require__(10);
27371 var RectangleD = __webpack_require__(13);
27372 var LayoutConstants = __webpack_require__(0);
27373 var RandomSeed = __webpack_require__(16);
27374 var PointD = __webpack_require__(4);
27375 function LNode(gm, loc, size, vNode) {
27376 if (size == null && vNode == null) {
27377 vNode = loc;
27378 }
27379 LGraphObject.call(this, vNode);
27380 if (gm.graphManager != null)
27381 gm = gm.graphManager;
27382 this.estimatedSize = Integer.MIN_VALUE;
27383 this.inclusionTreeDepth = Integer.MAX_VALUE;
27384 this.vGraphObject = vNode;
27385 this.edges = [];
27386 this.graphManager = gm;
27387 if (size != null && loc != null)
27388 this.rect = new RectangleD(loc.x, loc.y, size.width, size.height);
27389 else
27390 this.rect = new RectangleD();
27391 }
27392 LNode.prototype = Object.create(LGraphObject.prototype);
27393 for (var prop in LGraphObject) {
27394 LNode[prop] = LGraphObject[prop];
27395 }
27396 LNode.prototype.getEdges = function() {
27397 return this.edges;
27398 };
27399 LNode.prototype.getChild = function() {
27400 return this.child;
27401 };
27402 LNode.prototype.getOwner = function() {
27403 return this.owner;
27404 };
27405 LNode.prototype.getWidth = function() {
27406 return this.rect.width;
27407 };
27408 LNode.prototype.setWidth = function(width) {
27409 this.rect.width = width;
27410 };
27411 LNode.prototype.getHeight = function() {
27412 return this.rect.height;
27413 };
27414 LNode.prototype.setHeight = function(height) {
27415 this.rect.height = height;
27416 };
27417 LNode.prototype.getCenterX = function() {
27418 return this.rect.x + this.rect.width / 2;
27419 };
27420 LNode.prototype.getCenterY = function() {
27421 return this.rect.y + this.rect.height / 2;
27422 };
27423 LNode.prototype.getCenter = function() {
27424 return new PointD(this.rect.x + this.rect.width / 2, this.rect.y + this.rect.height / 2);
27425 };
27426 LNode.prototype.getLocation = function() {
27427 return new PointD(this.rect.x, this.rect.y);
27428 };
27429 LNode.prototype.getRect = function() {
27430 return this.rect;
27431 };
27432 LNode.prototype.getDiagonal = function() {
27433 return Math.sqrt(this.rect.width * this.rect.width + this.rect.height * this.rect.height);
27434 };
27435 LNode.prototype.getHalfTheDiagonal = function() {
27436 return Math.sqrt(this.rect.height * this.rect.height + this.rect.width * this.rect.width) / 2;
27437 };
27438 LNode.prototype.setRect = function(upperLeft, dimension) {
27439 this.rect.x = upperLeft.x;
27440 this.rect.y = upperLeft.y;
27441 this.rect.width = dimension.width;
27442 this.rect.height = dimension.height;
27443 };
27444 LNode.prototype.setCenter = function(cx, cy) {
27445 this.rect.x = cx - this.rect.width / 2;
27446 this.rect.y = cy - this.rect.height / 2;
27447 };
27448 LNode.prototype.setLocation = function(x, y) {
27449 this.rect.x = x;
27450 this.rect.y = y;
27451 };
27452 LNode.prototype.moveBy = function(dx, dy) {
27453 this.rect.x += dx;
27454 this.rect.y += dy;
27455 };
27456 LNode.prototype.getEdgeListToNode = function(to) {
27457 var edgeList = [];
27458 var self2 = this;
27459 self2.edges.forEach(function(edge) {
27460 if (edge.target == to) {
27461 if (edge.source != self2)
27462 throw "Incorrect edge source!";
27463 edgeList.push(edge);
27464 }
27465 });
27466 return edgeList;
27467 };
27468 LNode.prototype.getEdgesBetween = function(other) {
27469 var edgeList = [];
27470 var self2 = this;
27471 self2.edges.forEach(function(edge) {
27472 if (!(edge.source == self2 || edge.target == self2))
27473 throw "Incorrect edge source and/or target";
27474 if (edge.target == other || edge.source == other) {
27475 edgeList.push(edge);
27476 }
27477 });
27478 return edgeList;
27479 };
27480 LNode.prototype.getNeighborsList = function() {
27481 var neighbors = /* @__PURE__ */ new Set();
27482 var self2 = this;
27483 self2.edges.forEach(function(edge) {
27484 if (edge.source == self2) {
27485 neighbors.add(edge.target);
27486 } else {
27487 if (edge.target != self2) {
27488 throw "Incorrect incidency!";
27489 }
27490 neighbors.add(edge.source);
27491 }
27492 });
27493 return neighbors;
27494 };
27495 LNode.prototype.withChildren = function() {
27496 var withNeighborsList = /* @__PURE__ */ new Set();
27497 var childNode;
27498 var children;
27499 withNeighborsList.add(this);
27500 if (this.child != null) {
27501 var nodes2 = this.child.getNodes();
27502 for (var i = 0; i < nodes2.length; i++) {
27503 childNode = nodes2[i];
27504 children = childNode.withChildren();
27505 children.forEach(function(node) {
27506 withNeighborsList.add(node);
27507 });
27508 }
27509 }
27510 return withNeighborsList;
27511 };
27512 LNode.prototype.getNoOfChildren = function() {
27513 var noOfChildren = 0;
27514 var childNode;
27515 if (this.child == null) {
27516 noOfChildren = 1;
27517 } else {
27518 var nodes2 = this.child.getNodes();
27519 for (var i = 0; i < nodes2.length; i++) {
27520 childNode = nodes2[i];
27521 noOfChildren += childNode.getNoOfChildren();
27522 }
27523 }
27524 if (noOfChildren == 0) {
27525 noOfChildren = 1;
27526 }
27527 return noOfChildren;
27528 };
27529 LNode.prototype.getEstimatedSize = function() {
27530 if (this.estimatedSize == Integer.MIN_VALUE) {
27531 throw "assert failed";
27532 }
27533 return this.estimatedSize;
27534 };
27535 LNode.prototype.calcEstimatedSize = function() {
27536 if (this.child == null) {
27537 return this.estimatedSize = (this.rect.width + this.rect.height) / 2;
27538 } else {
27539 this.estimatedSize = this.child.calcEstimatedSize();
27540 this.rect.width = this.estimatedSize;
27541 this.rect.height = this.estimatedSize;
27542 return this.estimatedSize;
27543 }
27544 };
27545 LNode.prototype.scatter = function() {
27546 var randomCenterX;
27547 var randomCenterY;
27548 var minX = -LayoutConstants.INITIAL_WORLD_BOUNDARY;
27549 var maxX = LayoutConstants.INITIAL_WORLD_BOUNDARY;
27550 randomCenterX = LayoutConstants.WORLD_CENTER_X + RandomSeed.nextDouble() * (maxX - minX) + minX;
27551 var minY = -LayoutConstants.INITIAL_WORLD_BOUNDARY;
27552 var maxY = LayoutConstants.INITIAL_WORLD_BOUNDARY;
27553 randomCenterY = LayoutConstants.WORLD_CENTER_Y + RandomSeed.nextDouble() * (maxY - minY) + minY;
27554 this.rect.x = randomCenterX;
27555 this.rect.y = randomCenterY;
27556 };
27557 LNode.prototype.updateBounds = function() {
27558 if (this.getChild() == null) {
27559 throw "assert failed";
27560 }
27561 if (this.getChild().getNodes().length != 0) {
27562 var childGraph = this.getChild();
27563 childGraph.updateBounds(true);
27564 this.rect.x = childGraph.getLeft();
27565 this.rect.y = childGraph.getTop();
27566 this.setWidth(childGraph.getRight() - childGraph.getLeft());
27567 this.setHeight(childGraph.getBottom() - childGraph.getTop());
27568 if (LayoutConstants.NODE_DIMENSIONS_INCLUDE_LABELS) {
27569 var width = childGraph.getRight() - childGraph.getLeft();
27570 var height = childGraph.getBottom() - childGraph.getTop();
27571 if (this.labelWidth > width) {
27572 this.rect.x -= (this.labelWidth - width) / 2;
27573 this.setWidth(this.labelWidth);
27574 }
27575 if (this.labelHeight > height) {
27576 if (this.labelPos == "center") {
27577 this.rect.y -= (this.labelHeight - height) / 2;
27578 } else if (this.labelPos == "top") {
27579 this.rect.y -= this.labelHeight - height;
27580 }
27581 this.setHeight(this.labelHeight);
27582 }
27583 }
27584 }
27585 };
27586 LNode.prototype.getInclusionTreeDepth = function() {
27587 if (this.inclusionTreeDepth == Integer.MAX_VALUE) {
27588 throw "assert failed";
27589 }
27590 return this.inclusionTreeDepth;
27591 };
27592 LNode.prototype.transform = function(trans) {
27593 var left = this.rect.x;
27594 if (left > LayoutConstants.WORLD_BOUNDARY) {
27595 left = LayoutConstants.WORLD_BOUNDARY;
27596 } else if (left < -LayoutConstants.WORLD_BOUNDARY) {
27597 left = -LayoutConstants.WORLD_BOUNDARY;
27598 }
27599 var top = this.rect.y;
27600 if (top > LayoutConstants.WORLD_BOUNDARY) {
27601 top = LayoutConstants.WORLD_BOUNDARY;
27602 } else if (top < -LayoutConstants.WORLD_BOUNDARY) {
27603 top = -LayoutConstants.WORLD_BOUNDARY;
27604 }
27605 var leftTop = new PointD(left, top);
27606 var vLeftTop = trans.inverseTransformPoint(leftTop);
27607 this.setLocation(vLeftTop.x, vLeftTop.y);
27608 };
27609 LNode.prototype.getLeft = function() {
27610 return this.rect.x;
27611 };
27612 LNode.prototype.getRight = function() {
27613 return this.rect.x + this.rect.width;
27614 };
27615 LNode.prototype.getTop = function() {
27616 return this.rect.y;
27617 };
27618 LNode.prototype.getBottom = function() {
27619 return this.rect.y + this.rect.height;
27620 };
27621 LNode.prototype.getParent = function() {
27622 if (this.owner == null) {
27623 return null;
27624 }
27625 return this.owner.getParent();
27626 };
27627 module2.exports = LNode;
27628 },
27629 /* 4 */
27630 /***/
27631 function(module2, exports2, __webpack_require__) {
27632 function PointD(x, y) {
27633 if (x == null && y == null) {
27634 this.x = 0;
27635 this.y = 0;
27636 } else {
27637 this.x = x;
27638 this.y = y;
27639 }
27640 }
27641 PointD.prototype.getX = function() {
27642 return this.x;
27643 };
27644 PointD.prototype.getY = function() {
27645 return this.y;
27646 };
27647 PointD.prototype.setX = function(x) {
27648 this.x = x;
27649 };
27650 PointD.prototype.setY = function(y) {
27651 this.y = y;
27652 };
27653 PointD.prototype.getDifference = function(pt) {
27654 return new DimensionD(this.x - pt.x, this.y - pt.y);
27655 };
27656 PointD.prototype.getCopy = function() {
27657 return new PointD(this.x, this.y);
27658 };
27659 PointD.prototype.translate = function(dim) {
27660 this.x += dim.width;
27661 this.y += dim.height;
27662 return this;
27663 };
27664 module2.exports = PointD;
27665 },
27666 /* 5 */
27667 /***/
27668 function(module2, exports2, __webpack_require__) {
27669 var LGraphObject = __webpack_require__(2);
27670 var Integer = __webpack_require__(10);
27671 var LayoutConstants = __webpack_require__(0);
27672 var LGraphManager = __webpack_require__(6);
27673 var LNode = __webpack_require__(3);
27674 var LEdge = __webpack_require__(1);
27675 var RectangleD = __webpack_require__(13);
27676 var Point2 = __webpack_require__(12);
27677 var LinkedList = __webpack_require__(11);
27678 function LGraph(parent, obj2, vGraph) {
27679 LGraphObject.call(this, vGraph);
27680 this.estimatedSize = Integer.MIN_VALUE;
27681 this.margin = LayoutConstants.DEFAULT_GRAPH_MARGIN;
27682 this.edges = [];
27683 this.nodes = [];
27684 this.isConnected = false;
27685 this.parent = parent;
27686 if (obj2 != null && obj2 instanceof LGraphManager) {
27687 this.graphManager = obj2;
27688 } else if (obj2 != null && obj2 instanceof Layout) {
27689 this.graphManager = obj2.graphManager;
27690 }
27691 }
27692 LGraph.prototype = Object.create(LGraphObject.prototype);
27693 for (var prop in LGraphObject) {
27694 LGraph[prop] = LGraphObject[prop];
27695 }
27696 LGraph.prototype.getNodes = function() {
27697 return this.nodes;
27698 };
27699 LGraph.prototype.getEdges = function() {
27700 return this.edges;
27701 };
27702 LGraph.prototype.getGraphManager = function() {
27703 return this.graphManager;
27704 };
27705 LGraph.prototype.getParent = function() {
27706 return this.parent;
27707 };
27708 LGraph.prototype.getLeft = function() {
27709 return this.left;
27710 };
27711 LGraph.prototype.getRight = function() {
27712 return this.right;
27713 };
27714 LGraph.prototype.getTop = function() {
27715 return this.top;
27716 };
27717 LGraph.prototype.getBottom = function() {
27718 return this.bottom;
27719 };
27720 LGraph.prototype.isConnected = function() {
27721 return this.isConnected;
27722 };
27723 LGraph.prototype.add = function(obj1, sourceNode, targetNode) {
27724 if (sourceNode == null && targetNode == null) {
27725 var newNode = obj1;
27726 if (this.graphManager == null) {
27727 throw "Graph has no graph mgr!";
27728 }
27729 if (this.getNodes().indexOf(newNode) > -1) {
27730 throw "Node already in graph!";
27731 }
27732 newNode.owner = this;
27733 this.getNodes().push(newNode);
27734 return newNode;
27735 } else {
27736 var newEdge = obj1;
27737 if (!(this.getNodes().indexOf(sourceNode) > -1 && this.getNodes().indexOf(targetNode) > -1)) {
27738 throw "Source or target not in graph!";
27739 }
27740 if (!(sourceNode.owner == targetNode.owner && sourceNode.owner == this)) {
27741 throw "Both owners must be this graph!";
27742 }
27743 if (sourceNode.owner != targetNode.owner) {
27744 return null;
27745 }
27746 newEdge.source = sourceNode;
27747 newEdge.target = targetNode;
27748 newEdge.isInterGraph = false;
27749 this.getEdges().push(newEdge);
27750 sourceNode.edges.push(newEdge);
27751 if (targetNode != sourceNode) {
27752 targetNode.edges.push(newEdge);
27753 }
27754 return newEdge;
27755 }
27756 };
27757 LGraph.prototype.remove = function(obj) {
27758 var node = obj;
27759 if (obj instanceof LNode) {
27760 if (node == null) {
27761 throw "Node is null!";
27762 }
27763 if (!(node.owner != null && node.owner == this)) {
27764 throw "Owner graph is invalid!";
27765 }
27766 if (this.graphManager == null) {
27767 throw "Owner graph manager is invalid!";
27768 }
27769 var edgesToBeRemoved = node.edges.slice();
27770 var edge;
27771 var s = edgesToBeRemoved.length;
27772 for (var i = 0; i < s; i++) {
27773 edge = edgesToBeRemoved[i];
27774 if (edge.isInterGraph) {
27775 this.graphManager.remove(edge);
27776 } else {
27777 edge.source.owner.remove(edge);
27778 }
27779 }
27780 var index = this.nodes.indexOf(node);
27781 if (index == -1) {
27782 throw "Node not in owner node list!";
27783 }
27784 this.nodes.splice(index, 1);
27785 } else if (obj instanceof LEdge) {
27786 var edge = obj;
27787 if (edge == null) {
27788 throw "Edge is null!";
27789 }
27790 if (!(edge.source != null && edge.target != null)) {
27791 throw "Source and/or target is null!";
27792 }
27793 if (!(edge.source.owner != null && edge.target.owner != null && edge.source.owner == this && edge.target.owner == this)) {
27794 throw "Source and/or target owner is invalid!";
27795 }
27796 var sourceIndex = edge.source.edges.indexOf(edge);
27797 var targetIndex = edge.target.edges.indexOf(edge);
27798 if (!(sourceIndex > -1 && targetIndex > -1)) {
27799 throw "Source and/or target doesn't know this edge!";
27800 }
27801 edge.source.edges.splice(sourceIndex, 1);
27802 if (edge.target != edge.source) {
27803 edge.target.edges.splice(targetIndex, 1);
27804 }
27805 var index = edge.source.owner.getEdges().indexOf(edge);
27806 if (index == -1) {
27807 throw "Not in owner's edge list!";
27808 }
27809 edge.source.owner.getEdges().splice(index, 1);
27810 }
27811 };
27812 LGraph.prototype.updateLeftTop = function() {
27813 var top = Integer.MAX_VALUE;
27814 var left = Integer.MAX_VALUE;
27815 var nodeTop;
27816 var nodeLeft;
27817 var margin;
27818 var nodes2 = this.getNodes();
27819 var s = nodes2.length;
27820 for (var i = 0; i < s; i++) {
27821 var lNode = nodes2[i];
27822 nodeTop = lNode.getTop();
27823 nodeLeft = lNode.getLeft();
27824 if (top > nodeTop) {
27825 top = nodeTop;
27826 }
27827 if (left > nodeLeft) {
27828 left = nodeLeft;
27829 }
27830 }
27831 if (top == Integer.MAX_VALUE) {
27832 return null;
27833 }
27834 if (nodes2[0].getParent().paddingLeft != void 0) {
27835 margin = nodes2[0].getParent().paddingLeft;
27836 } else {
27837 margin = this.margin;
27838 }
27839 this.left = left - margin;
27840 this.top = top - margin;
27841 return new Point2(this.left, this.top);
27842 };
27843 LGraph.prototype.updateBounds = function(recursive) {
27844 var left = Integer.MAX_VALUE;
27845 var right = -Integer.MAX_VALUE;
27846 var top = Integer.MAX_VALUE;
27847 var bottom = -Integer.MAX_VALUE;
27848 var nodeLeft;
27849 var nodeRight;
27850 var nodeTop;
27851 var nodeBottom;
27852 var margin;
27853 var nodes2 = this.nodes;
27854 var s = nodes2.length;
27855 for (var i = 0; i < s; i++) {
27856 var lNode = nodes2[i];
27857 if (recursive && lNode.child != null) {
27858 lNode.updateBounds();
27859 }
27860 nodeLeft = lNode.getLeft();
27861 nodeRight = lNode.getRight();
27862 nodeTop = lNode.getTop();
27863 nodeBottom = lNode.getBottom();
27864 if (left > nodeLeft) {
27865 left = nodeLeft;
27866 }
27867 if (right < nodeRight) {
27868 right = nodeRight;
27869 }
27870 if (top > nodeTop) {
27871 top = nodeTop;
27872 }
27873 if (bottom < nodeBottom) {
27874 bottom = nodeBottom;
27875 }
27876 }
27877 var boundingRect = new RectangleD(left, top, right - left, bottom - top);
27878 if (left == Integer.MAX_VALUE) {
27879 this.left = this.parent.getLeft();
27880 this.right = this.parent.getRight();
27881 this.top = this.parent.getTop();
27882 this.bottom = this.parent.getBottom();
27883 }
27884 if (nodes2[0].getParent().paddingLeft != void 0) {
27885 margin = nodes2[0].getParent().paddingLeft;
27886 } else {
27887 margin = this.margin;
27888 }
27889 this.left = boundingRect.x - margin;
27890 this.right = boundingRect.x + boundingRect.width + margin;
27891 this.top = boundingRect.y - margin;
27892 this.bottom = boundingRect.y + boundingRect.height + margin;
27893 };
27894 LGraph.calculateBounds = function(nodes2) {
27895 var left = Integer.MAX_VALUE;
27896 var right = -Integer.MAX_VALUE;
27897 var top = Integer.MAX_VALUE;
27898 var bottom = -Integer.MAX_VALUE;
27899 var nodeLeft;
27900 var nodeRight;
27901 var nodeTop;
27902 var nodeBottom;
27903 var s = nodes2.length;
27904 for (var i = 0; i < s; i++) {
27905 var lNode = nodes2[i];
27906 nodeLeft = lNode.getLeft();
27907 nodeRight = lNode.getRight();
27908 nodeTop = lNode.getTop();
27909 nodeBottom = lNode.getBottom();
27910 if (left > nodeLeft) {
27911 left = nodeLeft;
27912 }
27913 if (right < nodeRight) {
27914 right = nodeRight;
27915 }
27916 if (top > nodeTop) {
27917 top = nodeTop;
27918 }
27919 if (bottom < nodeBottom) {
27920 bottom = nodeBottom;
27921 }
27922 }
27923 var boundingRect = new RectangleD(left, top, right - left, bottom - top);
27924 return boundingRect;
27925 };
27926 LGraph.prototype.getInclusionTreeDepth = function() {
27927 if (this == this.graphManager.getRoot()) {
27928 return 1;
27929 } else {
27930 return this.parent.getInclusionTreeDepth();
27931 }
27932 };
27933 LGraph.prototype.getEstimatedSize = function() {
27934 if (this.estimatedSize == Integer.MIN_VALUE) {
27935 throw "assert failed";
27936 }
27937 return this.estimatedSize;
27938 };
27939 LGraph.prototype.calcEstimatedSize = function() {
27940 var size = 0;
27941 var nodes2 = this.nodes;
27942 var s = nodes2.length;
27943 for (var i = 0; i < s; i++) {
27944 var lNode = nodes2[i];
27945 size += lNode.calcEstimatedSize();
27946 }
27947 if (size == 0) {
27948 this.estimatedSize = LayoutConstants.EMPTY_COMPOUND_NODE_SIZE;
27949 } else {
27950 this.estimatedSize = size / Math.sqrt(this.nodes.length);
27951 }
27952 return this.estimatedSize;
27953 };
27954 LGraph.prototype.updateConnected = function() {
27955 var self2 = this;
27956 if (this.nodes.length == 0) {
27957 this.isConnected = true;
27958 return;
27959 }
27960 var queue = new LinkedList();
27961 var visited = /* @__PURE__ */ new Set();
27962 var currentNode = this.nodes[0];
27963 var neighborEdges;
27964 var currentNeighbor;
27965 var childrenOfNode = currentNode.withChildren();
27966 childrenOfNode.forEach(function(node) {
27967 queue.push(node);
27968 visited.add(node);
27969 });
27970 while (queue.length !== 0) {
27971 currentNode = queue.shift();
27972 neighborEdges = currentNode.getEdges();
27973 var size = neighborEdges.length;
27974 for (var i = 0; i < size; i++) {
27975 var neighborEdge = neighborEdges[i];
27976 currentNeighbor = neighborEdge.getOtherEndInGraph(currentNode, this);
27977 if (currentNeighbor != null && !visited.has(currentNeighbor)) {
27978 var childrenOfNeighbor = currentNeighbor.withChildren();
27979 childrenOfNeighbor.forEach(function(node) {
27980 queue.push(node);
27981 visited.add(node);
27982 });
27983 }
27984 }
27985 }
27986 this.isConnected = false;
27987 if (visited.size >= this.nodes.length) {
27988 var noOfVisitedInThisGraph = 0;
27989 visited.forEach(function(visitedNode) {
27990 if (visitedNode.owner == self2) {
27991 noOfVisitedInThisGraph++;
27992 }
27993 });
27994 if (noOfVisitedInThisGraph == this.nodes.length) {
27995 this.isConnected = true;
27996 }
27997 }
27998 };
27999 module2.exports = LGraph;
28000 },
28001 /* 6 */
28002 /***/
28003 function(module2, exports2, __webpack_require__) {
28004 var LGraph;
28005 var LEdge = __webpack_require__(1);
28006 function LGraphManager(layout) {
28007 LGraph = __webpack_require__(5);
28008 this.layout = layout;
28009 this.graphs = [];
28010 this.edges = [];
28011 }
28012 LGraphManager.prototype.addRoot = function() {
28013 var ngraph = this.layout.newGraph();
28014 var nnode = this.layout.newNode(null);
28015 var root = this.add(ngraph, nnode);
28016 this.setRootGraph(root);
28017 return this.rootGraph;
28018 };
28019 LGraphManager.prototype.add = function(newGraph, parentNode, newEdge, sourceNode, targetNode) {
28020 if (newEdge == null && sourceNode == null && targetNode == null) {
28021 if (newGraph == null) {
28022 throw "Graph is null!";
28023 }
28024 if (parentNode == null) {
28025 throw "Parent node is null!";
28026 }
28027 if (this.graphs.indexOf(newGraph) > -1) {
28028 throw "Graph already in this graph mgr!";
28029 }
28030 this.graphs.push(newGraph);
28031 if (newGraph.parent != null) {
28032 throw "Already has a parent!";
28033 }
28034 if (parentNode.child != null) {
28035 throw "Already has a child!";
28036 }
28037 newGraph.parent = parentNode;
28038 parentNode.child = newGraph;
28039 return newGraph;
28040 } else {
28041 targetNode = newEdge;
28042 sourceNode = parentNode;
28043 newEdge = newGraph;
28044 var sourceGraph = sourceNode.getOwner();
28045 var targetGraph = targetNode.getOwner();
28046 if (!(sourceGraph != null && sourceGraph.getGraphManager() == this)) {
28047 throw "Source not in this graph mgr!";
28048 }
28049 if (!(targetGraph != null && targetGraph.getGraphManager() == this)) {
28050 throw "Target not in this graph mgr!";
28051 }
28052 if (sourceGraph == targetGraph) {
28053 newEdge.isInterGraph = false;
28054 return sourceGraph.add(newEdge, sourceNode, targetNode);
28055 } else {
28056 newEdge.isInterGraph = true;
28057 newEdge.source = sourceNode;
28058 newEdge.target = targetNode;
28059 if (this.edges.indexOf(newEdge) > -1) {
28060 throw "Edge already in inter-graph edge list!";
28061 }
28062 this.edges.push(newEdge);
28063 if (!(newEdge.source != null && newEdge.target != null)) {
28064 throw "Edge source and/or target is null!";
28065 }
28066 if (!(newEdge.source.edges.indexOf(newEdge) == -1 && newEdge.target.edges.indexOf(newEdge) == -1)) {
28067 throw "Edge already in source and/or target incidency list!";
28068 }
28069 newEdge.source.edges.push(newEdge);
28070 newEdge.target.edges.push(newEdge);
28071 return newEdge;
28072 }
28073 }
28074 };
28075 LGraphManager.prototype.remove = function(lObj) {
28076 if (lObj instanceof LGraph) {
28077 var graph = lObj;
28078 if (graph.getGraphManager() != this) {
28079 throw "Graph not in this graph mgr";
28080 }
28081 if (!(graph == this.rootGraph || graph.parent != null && graph.parent.graphManager == this)) {
28082 throw "Invalid parent node!";
28083 }
28084 var edgesToBeRemoved = [];
28085 edgesToBeRemoved = edgesToBeRemoved.concat(graph.getEdges());
28086 var edge;
28087 var s = edgesToBeRemoved.length;
28088 for (var i = 0; i < s; i++) {
28089 edge = edgesToBeRemoved[i];
28090 graph.remove(edge);
28091 }
28092 var nodesToBeRemoved = [];
28093 nodesToBeRemoved = nodesToBeRemoved.concat(graph.getNodes());
28094 var node;
28095 s = nodesToBeRemoved.length;
28096 for (var i = 0; i < s; i++) {
28097 node = nodesToBeRemoved[i];
28098 graph.remove(node);
28099 }
28100 if (graph == this.rootGraph) {
28101 this.setRootGraph(null);
28102 }
28103 var index = this.graphs.indexOf(graph);
28104 this.graphs.splice(index, 1);
28105 graph.parent = null;
28106 } else if (lObj instanceof LEdge) {
28107 edge = lObj;
28108 if (edge == null) {
28109 throw "Edge is null!";
28110 }
28111 if (!edge.isInterGraph) {
28112 throw "Not an inter-graph edge!";
28113 }
28114 if (!(edge.source != null && edge.target != null)) {
28115 throw "Source and/or target is null!";
28116 }
28117 if (!(edge.source.edges.indexOf(edge) != -1 && edge.target.edges.indexOf(edge) != -1)) {
28118 throw "Source and/or target doesn't know this edge!";
28119 }
28120 var index = edge.source.edges.indexOf(edge);
28121 edge.source.edges.splice(index, 1);
28122 index = edge.target.edges.indexOf(edge);
28123 edge.target.edges.splice(index, 1);
28124 if (!(edge.source.owner != null && edge.source.owner.getGraphManager() != null)) {
28125 throw "Edge owner graph or owner graph manager is null!";
28126 }
28127 if (edge.source.owner.getGraphManager().edges.indexOf(edge) == -1) {
28128 throw "Not in owner graph manager's edge list!";
28129 }
28130 var index = edge.source.owner.getGraphManager().edges.indexOf(edge);
28131 edge.source.owner.getGraphManager().edges.splice(index, 1);
28132 }
28133 };
28134 LGraphManager.prototype.updateBounds = function() {
28135 this.rootGraph.updateBounds(true);
28136 };
28137 LGraphManager.prototype.getGraphs = function() {
28138 return this.graphs;
28139 };
28140 LGraphManager.prototype.getAllNodes = function() {
28141 if (this.allNodes == null) {
28142 var nodeList = [];
28143 var graphs = this.getGraphs();
28144 var s = graphs.length;
28145 for (var i = 0; i < s; i++) {
28146 nodeList = nodeList.concat(graphs[i].getNodes());
28147 }
28148 this.allNodes = nodeList;
28149 }
28150 return this.allNodes;
28151 };
28152 LGraphManager.prototype.resetAllNodes = function() {
28153 this.allNodes = null;
28154 };
28155 LGraphManager.prototype.resetAllEdges = function() {
28156 this.allEdges = null;
28157 };
28158 LGraphManager.prototype.resetAllNodesToApplyGravitation = function() {
28159 this.allNodesToApplyGravitation = null;
28160 };
28161 LGraphManager.prototype.getAllEdges = function() {
28162 if (this.allEdges == null) {
28163 var edgeList = [];
28164 var graphs = this.getGraphs();
28165 graphs.length;
28166 for (var i = 0; i < graphs.length; i++) {
28167 edgeList = edgeList.concat(graphs[i].getEdges());
28168 }
28169 edgeList = edgeList.concat(this.edges);
28170 this.allEdges = edgeList;
28171 }
28172 return this.allEdges;
28173 };
28174 LGraphManager.prototype.getAllNodesToApplyGravitation = function() {
28175 return this.allNodesToApplyGravitation;
28176 };
28177 LGraphManager.prototype.setAllNodesToApplyGravitation = function(nodeList) {
28178 if (this.allNodesToApplyGravitation != null) {
28179 throw "assert failed";
28180 }
28181 this.allNodesToApplyGravitation = nodeList;
28182 };
28183 LGraphManager.prototype.getRoot = function() {
28184 return this.rootGraph;
28185 };
28186 LGraphManager.prototype.setRootGraph = function(graph) {
28187 if (graph.getGraphManager() != this) {
28188 throw "Root not in this graph mgr!";
28189 }
28190 this.rootGraph = graph;
28191 if (graph.parent == null) {
28192 graph.parent = this.layout.newNode("Root node");
28193 }
28194 };
28195 LGraphManager.prototype.getLayout = function() {
28196 return this.layout;
28197 };
28198 LGraphManager.prototype.isOneAncestorOfOther = function(firstNode, secondNode) {
28199 if (!(firstNode != null && secondNode != null)) {
28200 throw "assert failed";
28201 }
28202 if (firstNode == secondNode) {
28203 return true;
28204 }
28205 var ownerGraph = firstNode.getOwner();
28206 var parentNode;
28207 do {
28208 parentNode = ownerGraph.getParent();
28209 if (parentNode == null) {
28210 break;
28211 }
28212 if (parentNode == secondNode) {
28213 return true;
28214 }
28215 ownerGraph = parentNode.getOwner();
28216 if (ownerGraph == null) {
28217 break;
28218 }
28219 } while (true);
28220 ownerGraph = secondNode.getOwner();
28221 do {
28222 parentNode = ownerGraph.getParent();
28223 if (parentNode == null) {
28224 break;
28225 }
28226 if (parentNode == firstNode) {
28227 return true;
28228 }
28229 ownerGraph = parentNode.getOwner();
28230 if (ownerGraph == null) {
28231 break;
28232 }
28233 } while (true);
28234 return false;
28235 };
28236 LGraphManager.prototype.calcLowestCommonAncestors = function() {
28237 var edge;
28238 var sourceNode;
28239 var targetNode;
28240 var sourceAncestorGraph;
28241 var targetAncestorGraph;
28242 var edges = this.getAllEdges();
28243 var s = edges.length;
28244 for (var i = 0; i < s; i++) {
28245 edge = edges[i];
28246 sourceNode = edge.source;
28247 targetNode = edge.target;
28248 edge.lca = null;
28249 edge.sourceInLca = sourceNode;
28250 edge.targetInLca = targetNode;
28251 if (sourceNode == targetNode) {
28252 edge.lca = sourceNode.getOwner();
28253 continue;
28254 }
28255 sourceAncestorGraph = sourceNode.getOwner();
28256 while (edge.lca == null) {
28257 edge.targetInLca = targetNode;
28258 targetAncestorGraph = targetNode.getOwner();
28259 while (edge.lca == null) {
28260 if (targetAncestorGraph == sourceAncestorGraph) {
28261 edge.lca = targetAncestorGraph;
28262 break;
28263 }
28264 if (targetAncestorGraph == this.rootGraph) {
28265 break;
28266 }
28267 if (edge.lca != null) {
28268 throw "assert failed";
28269 }
28270 edge.targetInLca = targetAncestorGraph.getParent();
28271 targetAncestorGraph = edge.targetInLca.getOwner();
28272 }
28273 if (sourceAncestorGraph == this.rootGraph) {
28274 break;
28275 }
28276 if (edge.lca == null) {
28277 edge.sourceInLca = sourceAncestorGraph.getParent();
28278 sourceAncestorGraph = edge.sourceInLca.getOwner();
28279 }
28280 }
28281 if (edge.lca == null) {
28282 throw "assert failed";
28283 }
28284 }
28285 };
28286 LGraphManager.prototype.calcLowestCommonAncestor = function(firstNode, secondNode) {
28287 if (firstNode == secondNode) {
28288 return firstNode.getOwner();
28289 }
28290 var firstOwnerGraph = firstNode.getOwner();
28291 do {
28292 if (firstOwnerGraph == null) {
28293 break;
28294 }
28295 var secondOwnerGraph = secondNode.getOwner();
28296 do {
28297 if (secondOwnerGraph == null) {
28298 break;
28299 }
28300 if (secondOwnerGraph == firstOwnerGraph) {
28301 return secondOwnerGraph;
28302 }
28303 secondOwnerGraph = secondOwnerGraph.getParent().getOwner();
28304 } while (true);
28305 firstOwnerGraph = firstOwnerGraph.getParent().getOwner();
28306 } while (true);
28307 return firstOwnerGraph;
28308 };
28309 LGraphManager.prototype.calcInclusionTreeDepths = function(graph, depth) {
28310 if (graph == null && depth == null) {
28311 graph = this.rootGraph;
28312 depth = 1;
28313 }
28314 var node;
28315 var nodes2 = graph.getNodes();
28316 var s = nodes2.length;
28317 for (var i = 0; i < s; i++) {
28318 node = nodes2[i];
28319 node.inclusionTreeDepth = depth;
28320 if (node.child != null) {
28321 this.calcInclusionTreeDepths(node.child, depth + 1);
28322 }
28323 }
28324 };
28325 LGraphManager.prototype.includesInvalidEdge = function() {
28326 var edge;
28327 var s = this.edges.length;
28328 for (var i = 0; i < s; i++) {
28329 edge = this.edges[i];
28330 if (this.isOneAncestorOfOther(edge.source, edge.target)) {
28331 return true;
28332 }
28333 }
28334 return false;
28335 };
28336 module2.exports = LGraphManager;
28337 },
28338 /* 7 */
28339 /***/
28340 function(module2, exports2, __webpack_require__) {
28341 var LayoutConstants = __webpack_require__(0);
28342 function FDLayoutConstants() {
28343 }
28344 for (var prop in LayoutConstants) {
28345 FDLayoutConstants[prop] = LayoutConstants[prop];
28346 }
28347 FDLayoutConstants.MAX_ITERATIONS = 2500;
28348 FDLayoutConstants.DEFAULT_EDGE_LENGTH = 50;
28349 FDLayoutConstants.DEFAULT_SPRING_STRENGTH = 0.45;
28350 FDLayoutConstants.DEFAULT_REPULSION_STRENGTH = 4500;
28351 FDLayoutConstants.DEFAULT_GRAVITY_STRENGTH = 0.4;
28352 FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_STRENGTH = 1;
28353 FDLayoutConstants.DEFAULT_GRAVITY_RANGE_FACTOR = 3.8;
28354 FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR = 1.5;
28355 FDLayoutConstants.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION = true;
28356 FDLayoutConstants.DEFAULT_USE_SMART_REPULSION_RANGE_CALCULATION = true;
28357 FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL = 0.3;
28358 FDLayoutConstants.COOLING_ADAPTATION_FACTOR = 0.33;
28359 FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT = 1e3;
28360 FDLayoutConstants.ADAPTATION_UPPER_NODE_LIMIT = 5e3;
28361 FDLayoutConstants.MAX_NODE_DISPLACEMENT_INCREMENTAL = 100;
28362 FDLayoutConstants.MAX_NODE_DISPLACEMENT = FDLayoutConstants.MAX_NODE_DISPLACEMENT_INCREMENTAL * 3;
28363 FDLayoutConstants.MIN_REPULSION_DIST = FDLayoutConstants.DEFAULT_EDGE_LENGTH / 10;
28364 FDLayoutConstants.CONVERGENCE_CHECK_PERIOD = 100;
28365 FDLayoutConstants.PER_LEVEL_IDEAL_EDGE_LENGTH_FACTOR = 0.1;
28366 FDLayoutConstants.MIN_EDGE_LENGTH = 1;
28367 FDLayoutConstants.GRID_CALCULATION_CHECK_PERIOD = 10;
28368 module2.exports = FDLayoutConstants;
28369 },
28370 /* 8 */
28371 /***/
28372 function(module2, exports2, __webpack_require__) {
28373 var Point2 = __webpack_require__(12);
28374 function IGeometry() {
28375 }
28376 IGeometry.calcSeparationAmount = function(rectA, rectB, overlapAmount, separationBuffer) {
28377 if (!rectA.intersects(rectB)) {
28378 throw "assert failed";
28379 }
28380 var directions = new Array(2);
28381 this.decideDirectionsForOverlappingNodes(rectA, rectB, directions);
28382 overlapAmount[0] = Math.min(rectA.getRight(), rectB.getRight()) - Math.max(rectA.x, rectB.x);
28383 overlapAmount[1] = Math.min(rectA.getBottom(), rectB.getBottom()) - Math.max(rectA.y, rectB.y);
28384 if (rectA.getX() <= rectB.getX() && rectA.getRight() >= rectB.getRight()) {
28385 overlapAmount[0] += Math.min(rectB.getX() - rectA.getX(), rectA.getRight() - rectB.getRight());
28386 } else if (rectB.getX() <= rectA.getX() && rectB.getRight() >= rectA.getRight()) {
28387 overlapAmount[0] += Math.min(rectA.getX() - rectB.getX(), rectB.getRight() - rectA.getRight());
28388 }
28389 if (rectA.getY() <= rectB.getY() && rectA.getBottom() >= rectB.getBottom()) {
28390 overlapAmount[1] += Math.min(rectB.getY() - rectA.getY(), rectA.getBottom() - rectB.getBottom());
28391 } else if (rectB.getY() <= rectA.getY() && rectB.getBottom() >= rectA.getBottom()) {
28392 overlapAmount[1] += Math.min(rectA.getY() - rectB.getY(), rectB.getBottom() - rectA.getBottom());
28393 }
28394 var slope = Math.abs((rectB.getCenterY() - rectA.getCenterY()) / (rectB.getCenterX() - rectA.getCenterX()));
28395 if (rectB.getCenterY() === rectA.getCenterY() && rectB.getCenterX() === rectA.getCenterX()) {
28396 slope = 1;
28397 }
28398 var moveByY = slope * overlapAmount[0];
28399 var moveByX = overlapAmount[1] / slope;
28400 if (overlapAmount[0] < moveByX) {
28401 moveByX = overlapAmount[0];
28402 } else {
28403 moveByY = overlapAmount[1];
28404 }
28405 overlapAmount[0] = -1 * directions[0] * (moveByX / 2 + separationBuffer);
28406 overlapAmount[1] = -1 * directions[1] * (moveByY / 2 + separationBuffer);
28407 };
28408 IGeometry.decideDirectionsForOverlappingNodes = function(rectA, rectB, directions) {
28409 if (rectA.getCenterX() < rectB.getCenterX()) {
28410 directions[0] = -1;
28411 } else {
28412 directions[0] = 1;
28413 }
28414 if (rectA.getCenterY() < rectB.getCenterY()) {
28415 directions[1] = -1;
28416 } else {
28417 directions[1] = 1;
28418 }
28419 };
28420 IGeometry.getIntersection2 = function(rectA, rectB, result) {
28421 var p1x = rectA.getCenterX();
28422 var p1y = rectA.getCenterY();
28423 var p2x = rectB.getCenterX();
28424 var p2y = rectB.getCenterY();
28425 if (rectA.intersects(rectB)) {
28426 result[0] = p1x;
28427 result[1] = p1y;
28428 result[2] = p2x;
28429 result[3] = p2y;
28430 return true;
28431 }
28432 var topLeftAx = rectA.getX();
28433 var topLeftAy = rectA.getY();
28434 var topRightAx = rectA.getRight();
28435 var bottomLeftAx = rectA.getX();
28436 var bottomLeftAy = rectA.getBottom();
28437 var bottomRightAx = rectA.getRight();
28438 var halfWidthA = rectA.getWidthHalf();
28439 var halfHeightA = rectA.getHeightHalf();
28440 var topLeftBx = rectB.getX();
28441 var topLeftBy = rectB.getY();
28442 var topRightBx = rectB.getRight();
28443 var bottomLeftBx = rectB.getX();
28444 var bottomLeftBy = rectB.getBottom();
28445 var bottomRightBx = rectB.getRight();
28446 var halfWidthB = rectB.getWidthHalf();
28447 var halfHeightB = rectB.getHeightHalf();
28448 var clipPointAFound = false;
28449 var clipPointBFound = false;
28450 if (p1x === p2x) {
28451 if (p1y > p2y) {
28452 result[0] = p1x;
28453 result[1] = topLeftAy;
28454 result[2] = p2x;
28455 result[3] = bottomLeftBy;
28456 return false;
28457 } else if (p1y < p2y) {
28458 result[0] = p1x;
28459 result[1] = bottomLeftAy;
28460 result[2] = p2x;
28461 result[3] = topLeftBy;
28462 return false;
28463 } else
28464 ;
28465 } else if (p1y === p2y) {
28466 if (p1x > p2x) {
28467 result[0] = topLeftAx;
28468 result[1] = p1y;
28469 result[2] = topRightBx;
28470 result[3] = p2y;
28471 return false;
28472 } else if (p1x < p2x) {
28473 result[0] = topRightAx;
28474 result[1] = p1y;
28475 result[2] = topLeftBx;
28476 result[3] = p2y;
28477 return false;
28478 } else
28479 ;
28480 } else {
28481 var slopeA = rectA.height / rectA.width;
28482 var slopeB = rectB.height / rectB.width;
28483 var slopePrime = (p2y - p1y) / (p2x - p1x);
28484 var cardinalDirectionA = void 0;
28485 var cardinalDirectionB = void 0;
28486 var tempPointAx = void 0;
28487 var tempPointAy = void 0;
28488 var tempPointBx = void 0;
28489 var tempPointBy = void 0;
28490 if (-slopeA === slopePrime) {
28491 if (p1x > p2x) {
28492 result[0] = bottomLeftAx;
28493 result[1] = bottomLeftAy;
28494 clipPointAFound = true;
28495 } else {
28496 result[0] = topRightAx;
28497 result[1] = topLeftAy;
28498 clipPointAFound = true;
28499 }
28500 } else if (slopeA === slopePrime) {
28501 if (p1x > p2x) {
28502 result[0] = topLeftAx;
28503 result[1] = topLeftAy;
28504 clipPointAFound = true;
28505 } else {
28506 result[0] = bottomRightAx;
28507 result[1] = bottomLeftAy;
28508 clipPointAFound = true;
28509 }
28510 }
28511 if (-slopeB === slopePrime) {
28512 if (p2x > p1x) {
28513 result[2] = bottomLeftBx;
28514 result[3] = bottomLeftBy;
28515 clipPointBFound = true;
28516 } else {
28517 result[2] = topRightBx;
28518 result[3] = topLeftBy;
28519 clipPointBFound = true;
28520 }
28521 } else if (slopeB === slopePrime) {
28522 if (p2x > p1x) {
28523 result[2] = topLeftBx;
28524 result[3] = topLeftBy;
28525 clipPointBFound = true;
28526 } else {
28527 result[2] = bottomRightBx;
28528 result[3] = bottomLeftBy;
28529 clipPointBFound = true;
28530 }
28531 }
28532 if (clipPointAFound && clipPointBFound) {
28533 return false;
28534 }
28535 if (p1x > p2x) {
28536 if (p1y > p2y) {
28537 cardinalDirectionA = this.getCardinalDirection(slopeA, slopePrime, 4);
28538 cardinalDirectionB = this.getCardinalDirection(slopeB, slopePrime, 2);
28539 } else {
28540 cardinalDirectionA = this.getCardinalDirection(-slopeA, slopePrime, 3);
28541 cardinalDirectionB = this.getCardinalDirection(-slopeB, slopePrime, 1);
28542 }
28543 } else {
28544 if (p1y > p2y) {
28545 cardinalDirectionA = this.getCardinalDirection(-slopeA, slopePrime, 1);
28546 cardinalDirectionB = this.getCardinalDirection(-slopeB, slopePrime, 3);
28547 } else {
28548 cardinalDirectionA = this.getCardinalDirection(slopeA, slopePrime, 2);
28549 cardinalDirectionB = this.getCardinalDirection(slopeB, slopePrime, 4);
28550 }
28551 }
28552 if (!clipPointAFound) {
28553 switch (cardinalDirectionA) {
28554 case 1:
28555 tempPointAy = topLeftAy;
28556 tempPointAx = p1x + -halfHeightA / slopePrime;
28557 result[0] = tempPointAx;
28558 result[1] = tempPointAy;
28559 break;
28560 case 2:
28561 tempPointAx = bottomRightAx;
28562 tempPointAy = p1y + halfWidthA * slopePrime;
28563 result[0] = tempPointAx;
28564 result[1] = tempPointAy;
28565 break;
28566 case 3:
28567 tempPointAy = bottomLeftAy;
28568 tempPointAx = p1x + halfHeightA / slopePrime;
28569 result[0] = tempPointAx;
28570 result[1] = tempPointAy;
28571 break;
28572 case 4:
28573 tempPointAx = bottomLeftAx;
28574 tempPointAy = p1y + -halfWidthA * slopePrime;
28575 result[0] = tempPointAx;
28576 result[1] = tempPointAy;
28577 break;
28578 }
28579 }
28580 if (!clipPointBFound) {
28581 switch (cardinalDirectionB) {
28582 case 1:
28583 tempPointBy = topLeftBy;
28584 tempPointBx = p2x + -halfHeightB / slopePrime;
28585 result[2] = tempPointBx;
28586 result[3] = tempPointBy;
28587 break;
28588 case 2:
28589 tempPointBx = bottomRightBx;
28590 tempPointBy = p2y + halfWidthB * slopePrime;
28591 result[2] = tempPointBx;
28592 result[3] = tempPointBy;
28593 break;
28594 case 3:
28595 tempPointBy = bottomLeftBy;
28596 tempPointBx = p2x + halfHeightB / slopePrime;
28597 result[2] = tempPointBx;
28598 result[3] = tempPointBy;
28599 break;
28600 case 4:
28601 tempPointBx = bottomLeftBx;
28602 tempPointBy = p2y + -halfWidthB * slopePrime;
28603 result[2] = tempPointBx;
28604 result[3] = tempPointBy;
28605 break;
28606 }
28607 }
28608 }
28609 return false;
28610 };
28611 IGeometry.getCardinalDirection = function(slope, slopePrime, line) {
28612 if (slope > slopePrime) {
28613 return line;
28614 } else {
28615 return 1 + line % 4;
28616 }
28617 };
28618 IGeometry.getIntersection = function(s1, s2, f1, f2) {
28619 if (f2 == null) {
28620 return this.getIntersection2(s1, s2, f1);
28621 }
28622 var x1 = s1.x;
28623 var y1 = s1.y;
28624 var x2 = s2.x;
28625 var y2 = s2.y;
28626 var x3 = f1.x;
28627 var y3 = f1.y;
28628 var x4 = f2.x;
28629 var y4 = f2.y;
28630 var x = void 0, y = void 0;
28631 var a1 = void 0, a2 = void 0, b1 = void 0, b2 = void 0, c1 = void 0, c2 = void 0;
28632 var denom = void 0;
28633 a1 = y2 - y1;
28634 b1 = x1 - x2;
28635 c1 = x2 * y1 - x1 * y2;
28636 a2 = y4 - y3;
28637 b2 = x3 - x4;
28638 c2 = x4 * y3 - x3 * y4;
28639 denom = a1 * b2 - a2 * b1;
28640 if (denom === 0) {
28641 return null;
28642 }
28643 x = (b1 * c2 - b2 * c1) / denom;
28644 y = (a2 * c1 - a1 * c2) / denom;
28645 return new Point2(x, y);
28646 };
28647 IGeometry.angleOfVector = function(Cx, Cy, Nx, Ny) {
28648 var C_angle = void 0;
28649 if (Cx !== Nx) {
28650 C_angle = Math.atan((Ny - Cy) / (Nx - Cx));
28651 if (Nx < Cx) {
28652 C_angle += Math.PI;
28653 } else if (Ny < Cy) {
28654 C_angle += this.TWO_PI;
28655 }
28656 } else if (Ny < Cy) {
28657 C_angle = this.ONE_AND_HALF_PI;
28658 } else {
28659 C_angle = this.HALF_PI;
28660 }
28661 return C_angle;
28662 };
28663 IGeometry.doIntersect = function(p1, p2, p3, p4) {
28664 var a = p1.x;
28665 var b = p1.y;
28666 var c = p2.x;
28667 var d = p2.y;
28668 var p = p3.x;
28669 var q = p3.y;
28670 var r = p4.x;
28671 var s = p4.y;
28672 var det = (c - a) * (s - q) - (r - p) * (d - b);
28673 if (det === 0) {
28674 return false;
28675 } else {
28676 var lambda = ((s - q) * (r - a) + (p - r) * (s - b)) / det;
28677 var gamma = ((b - d) * (r - a) + (c - a) * (s - b)) / det;
28678 return 0 < lambda && lambda < 1 && 0 < gamma && gamma < 1;
28679 }
28680 };
28681 IGeometry.HALF_PI = 0.5 * Math.PI;
28682 IGeometry.ONE_AND_HALF_PI = 1.5 * Math.PI;
28683 IGeometry.TWO_PI = 2 * Math.PI;
28684 IGeometry.THREE_PI = 3 * Math.PI;
28685 module2.exports = IGeometry;
28686 },
28687 /* 9 */
28688 /***/
28689 function(module2, exports2, __webpack_require__) {
28690 function IMath() {
28691 }
28692 IMath.sign = function(value) {
28693 if (value > 0) {
28694 return 1;
28695 } else if (value < 0) {
28696 return -1;
28697 } else {
28698 return 0;
28699 }
28700 };
28701 IMath.floor = function(value) {
28702 return value < 0 ? Math.ceil(value) : Math.floor(value);
28703 };
28704 IMath.ceil = function(value) {
28705 return value < 0 ? Math.floor(value) : Math.ceil(value);
28706 };
28707 module2.exports = IMath;
28708 },
28709 /* 10 */
28710 /***/
28711 function(module2, exports2, __webpack_require__) {
28712 function Integer() {
28713 }
28714 Integer.MAX_VALUE = 2147483647;
28715 Integer.MIN_VALUE = -2147483648;
28716 module2.exports = Integer;
28717 },
28718 /* 11 */
28719 /***/
28720 function(module2, exports2, __webpack_require__) {
28721 var _createClass = function() {
28722 function defineProperties(target, props) {
28723 for (var i = 0; i < props.length; i++) {
28724 var descriptor = props[i];
28725 descriptor.enumerable = descriptor.enumerable || false;
28726 descriptor.configurable = true;
28727 if ("value" in descriptor)
28728 descriptor.writable = true;
28729 Object.defineProperty(target, descriptor.key, descriptor);
28730 }
28731 }
28732 return function(Constructor, protoProps, staticProps) {
28733 if (protoProps)
28734 defineProperties(Constructor.prototype, protoProps);
28735 if (staticProps)
28736 defineProperties(Constructor, staticProps);
28737 return Constructor;
28738 };
28739 }();
28740 function _classCallCheck(instance2, Constructor) {
28741 if (!(instance2 instanceof Constructor)) {
28742 throw new TypeError("Cannot call a class as a function");
28743 }
28744 }
28745 var nodeFrom = function nodeFrom2(value) {
28746 return { value, next: null, prev: null };
28747 };
28748 var add = function add2(prev, node, next2, list) {
28749 if (prev !== null) {
28750 prev.next = node;
28751 } else {
28752 list.head = node;
28753 }
28754 if (next2 !== null) {
28755 next2.prev = node;
28756 } else {
28757 list.tail = node;
28758 }
28759 node.prev = prev;
28760 node.next = next2;
28761 list.length++;
28762 return node;
28763 };
28764 var _remove = function _remove2(node, list) {
28765 var prev = node.prev, next2 = node.next;
28766 if (prev !== null) {
28767 prev.next = next2;
28768 } else {
28769 list.head = next2;
28770 }
28771 if (next2 !== null) {
28772 next2.prev = prev;
28773 } else {
28774 list.tail = prev;
28775 }
28776 node.prev = node.next = null;
28777 list.length--;
28778 return node;
28779 };
28780 var LinkedList = function() {
28781 function LinkedList2(vals) {
28782 var _this = this;
28783 _classCallCheck(this, LinkedList2);
28784 this.length = 0;
28785 this.head = null;
28786 this.tail = null;
28787 if (vals != null) {
28788 vals.forEach(function(v) {
28789 return _this.push(v);
28790 });
28791 }
28792 }
28793 _createClass(LinkedList2, [{
28794 key: "size",
28795 value: function size() {
28796 return this.length;
28797 }
28798 }, {
28799 key: "insertBefore",
28800 value: function insertBefore(val, otherNode) {
28801 return add(otherNode.prev, nodeFrom(val), otherNode, this);
28802 }
28803 }, {
28804 key: "insertAfter",
28805 value: function insertAfter(val, otherNode) {
28806 return add(otherNode, nodeFrom(val), otherNode.next, this);
28807 }
28808 }, {
28809 key: "insertNodeBefore",
28810 value: function insertNodeBefore(newNode, otherNode) {
28811 return add(otherNode.prev, newNode, otherNode, this);
28812 }
28813 }, {
28814 key: "insertNodeAfter",
28815 value: function insertNodeAfter(newNode, otherNode) {
28816 return add(otherNode, newNode, otherNode.next, this);
28817 }
28818 }, {
28819 key: "push",
28820 value: function push(val) {
28821 return add(this.tail, nodeFrom(val), null, this);
28822 }
28823 }, {
28824 key: "unshift",
28825 value: function unshift(val) {
28826 return add(null, nodeFrom(val), this.head, this);
28827 }
28828 }, {
28829 key: "remove",
28830 value: function remove(node) {
28831 return _remove(node, this);
28832 }
28833 }, {
28834 key: "pop",
28835 value: function pop() {
28836 return _remove(this.tail, this).value;
28837 }
28838 }, {
28839 key: "popNode",
28840 value: function popNode() {
28841 return _remove(this.tail, this);
28842 }
28843 }, {
28844 key: "shift",
28845 value: function shift() {
28846 return _remove(this.head, this).value;
28847 }
28848 }, {
28849 key: "shiftNode",
28850 value: function shiftNode() {
28851 return _remove(this.head, this);
28852 }
28853 }, {
28854 key: "get_object_at",
28855 value: function get_object_at(index) {
28856 if (index <= this.length()) {
28857 var i = 1;
28858 var current = this.head;
28859 while (i < index) {
28860 current = current.next;
28861 i++;
28862 }
28863 return current.value;
28864 }
28865 }
28866 }, {
28867 key: "set_object_at",
28868 value: function set_object_at(index, value) {
28869 if (index <= this.length()) {
28870 var i = 1;
28871 var current = this.head;
28872 while (i < index) {
28873 current = current.next;
28874 i++;
28875 }
28876 current.value = value;
28877 }
28878 }
28879 }]);
28880 return LinkedList2;
28881 }();
28882 module2.exports = LinkedList;
28883 },
28884 /* 12 */
28885 /***/
28886 function(module2, exports2, __webpack_require__) {
28887 function Point2(x, y, p) {
28888 this.x = null;
28889 this.y = null;
28890 if (x == null && y == null && p == null) {
28891 this.x = 0;
28892 this.y = 0;
28893 } else if (typeof x == "number" && typeof y == "number" && p == null) {
28894 this.x = x;
28895 this.y = y;
28896 } else if (x.constructor.name == "Point" && y == null && p == null) {
28897 p = x;
28898 this.x = p.x;
28899 this.y = p.y;
28900 }
28901 }
28902 Point2.prototype.getX = function() {
28903 return this.x;
28904 };
28905 Point2.prototype.getY = function() {
28906 return this.y;
28907 };
28908 Point2.prototype.getLocation = function() {
28909 return new Point2(this.x, this.y);
28910 };
28911 Point2.prototype.setLocation = function(x, y, p) {
28912 if (x.constructor.name == "Point" && y == null && p == null) {
28913 p = x;
28914 this.setLocation(p.x, p.y);
28915 } else if (typeof x == "number" && typeof y == "number" && p == null) {
28916 if (parseInt(x) == x && parseInt(y) == y) {
28917 this.move(x, y);
28918 } else {
28919 this.x = Math.floor(x + 0.5);
28920 this.y = Math.floor(y + 0.5);
28921 }
28922 }
28923 };
28924 Point2.prototype.move = function(x, y) {
28925 this.x = x;
28926 this.y = y;
28927 };
28928 Point2.prototype.translate = function(dx, dy) {
28929 this.x += dx;
28930 this.y += dy;
28931 };
28932 Point2.prototype.equals = function(obj) {
28933 if (obj.constructor.name == "Point") {
28934 var pt = obj;
28935 return this.x == pt.x && this.y == pt.y;
28936 }
28937 return this == obj;
28938 };
28939 Point2.prototype.toString = function() {
28940 return new Point2().constructor.name + "[x=" + this.x + ",y=" + this.y + "]";
28941 };
28942 module2.exports = Point2;
28943 },
28944 /* 13 */
28945 /***/
28946 function(module2, exports2, __webpack_require__) {
28947 function RectangleD(x, y, width, height) {
28948 this.x = 0;
28949 this.y = 0;
28950 this.width = 0;
28951 this.height = 0;
28952 if (x != null && y != null && width != null && height != null) {
28953 this.x = x;
28954 this.y = y;
28955 this.width = width;
28956 this.height = height;
28957 }
28958 }
28959 RectangleD.prototype.getX = function() {
28960 return this.x;
28961 };
28962 RectangleD.prototype.setX = function(x) {
28963 this.x = x;
28964 };
28965 RectangleD.prototype.getY = function() {
28966 return this.y;
28967 };
28968 RectangleD.prototype.setY = function(y) {
28969 this.y = y;
28970 };
28971 RectangleD.prototype.getWidth = function() {
28972 return this.width;
28973 };
28974 RectangleD.prototype.setWidth = function(width) {
28975 this.width = width;
28976 };
28977 RectangleD.prototype.getHeight = function() {
28978 return this.height;
28979 };
28980 RectangleD.prototype.setHeight = function(height) {
28981 this.height = height;
28982 };
28983 RectangleD.prototype.getRight = function() {
28984 return this.x + this.width;
28985 };
28986 RectangleD.prototype.getBottom = function() {
28987 return this.y + this.height;
28988 };
28989 RectangleD.prototype.intersects = function(a) {
28990 if (this.getRight() < a.x) {
28991 return false;
28992 }
28993 if (this.getBottom() < a.y) {
28994 return false;
28995 }
28996 if (a.getRight() < this.x) {
28997 return false;
28998 }
28999 if (a.getBottom() < this.y) {
29000 return false;
29001 }
29002 return true;
29003 };
29004 RectangleD.prototype.getCenterX = function() {
29005 return this.x + this.width / 2;
29006 };
29007 RectangleD.prototype.getMinX = function() {
29008 return this.getX();
29009 };
29010 RectangleD.prototype.getMaxX = function() {
29011 return this.getX() + this.width;
29012 };
29013 RectangleD.prototype.getCenterY = function() {
29014 return this.y + this.height / 2;
29015 };
29016 RectangleD.prototype.getMinY = function() {
29017 return this.getY();
29018 };
29019 RectangleD.prototype.getMaxY = function() {
29020 return this.getY() + this.height;
29021 };
29022 RectangleD.prototype.getWidthHalf = function() {
29023 return this.width / 2;
29024 };
29025 RectangleD.prototype.getHeightHalf = function() {
29026 return this.height / 2;
29027 };
29028 module2.exports = RectangleD;
29029 },
29030 /* 14 */
29031 /***/
29032 function(module2, exports2, __webpack_require__) {
29033 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
29034 return typeof obj;
29035 } : function(obj) {
29036 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
29037 };
29038 function UniqueIDGeneretor() {
29039 }
29040 UniqueIDGeneretor.lastID = 0;
29041 UniqueIDGeneretor.createID = function(obj) {
29042 if (UniqueIDGeneretor.isPrimitive(obj)) {
29043 return obj;
29044 }
29045 if (obj.uniqueID != null) {
29046 return obj.uniqueID;
29047 }
29048 obj.uniqueID = UniqueIDGeneretor.getString();
29049 UniqueIDGeneretor.lastID++;
29050 return obj.uniqueID;
29051 };
29052 UniqueIDGeneretor.getString = function(id) {
29053 if (id == null)
29054 id = UniqueIDGeneretor.lastID;
29055 return "Object#" + id;
29056 };
29057 UniqueIDGeneretor.isPrimitive = function(arg) {
29058 var type = typeof arg === "undefined" ? "undefined" : _typeof(arg);
29059 return arg == null || type != "object" && type != "function";
29060 };
29061 module2.exports = UniqueIDGeneretor;
29062 },
29063 /* 15 */
29064 /***/
29065 function(module2, exports2, __webpack_require__) {
29066 function _toConsumableArray(arr) {
29067 if (Array.isArray(arr)) {
29068 for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
29069 arr2[i] = arr[i];
29070 }
29071 return arr2;
29072 } else {
29073 return Array.from(arr);
29074 }
29075 }
29076 var LayoutConstants = __webpack_require__(0);
29077 var LGraphManager = __webpack_require__(6);
29078 var LNode = __webpack_require__(3);
29079 var LEdge = __webpack_require__(1);
29080 var LGraph = __webpack_require__(5);
29081 var PointD = __webpack_require__(4);
29082 var Transform = __webpack_require__(17);
29083 var Emitter = __webpack_require__(27);
29084 function Layout2(isRemoteUse) {
29085 Emitter.call(this);
29086 this.layoutQuality = LayoutConstants.QUALITY;
29087 this.createBendsAsNeeded = LayoutConstants.DEFAULT_CREATE_BENDS_AS_NEEDED;
29088 this.incremental = LayoutConstants.DEFAULT_INCREMENTAL;
29089 this.animationOnLayout = LayoutConstants.DEFAULT_ANIMATION_ON_LAYOUT;
29090 this.animationDuringLayout = LayoutConstants.DEFAULT_ANIMATION_DURING_LAYOUT;
29091 this.animationPeriod = LayoutConstants.DEFAULT_ANIMATION_PERIOD;
29092 this.uniformLeafNodeSizes = LayoutConstants.DEFAULT_UNIFORM_LEAF_NODE_SIZES;
29093 this.edgeToDummyNodes = /* @__PURE__ */ new Map();
29094 this.graphManager = new LGraphManager(this);
29095 this.isLayoutFinished = false;
29096 this.isSubLayout = false;
29097 this.isRemoteUse = false;
29098 if (isRemoteUse != null) {
29099 this.isRemoteUse = isRemoteUse;
29100 }
29101 }
29102 Layout2.RANDOM_SEED = 1;
29103 Layout2.prototype = Object.create(Emitter.prototype);
29104 Layout2.prototype.getGraphManager = function() {
29105 return this.graphManager;
29106 };
29107 Layout2.prototype.getAllNodes = function() {
29108 return this.graphManager.getAllNodes();
29109 };
29110 Layout2.prototype.getAllEdges = function() {
29111 return this.graphManager.getAllEdges();
29112 };
29113 Layout2.prototype.getAllNodesToApplyGravitation = function() {
29114 return this.graphManager.getAllNodesToApplyGravitation();
29115 };
29116 Layout2.prototype.newGraphManager = function() {
29117 var gm = new LGraphManager(this);
29118 this.graphManager = gm;
29119 return gm;
29120 };
29121 Layout2.prototype.newGraph = function(vGraph) {
29122 return new LGraph(null, this.graphManager, vGraph);
29123 };
29124 Layout2.prototype.newNode = function(vNode) {
29125 return new LNode(this.graphManager, vNode);
29126 };
29127 Layout2.prototype.newEdge = function(vEdge) {
29128 return new LEdge(null, null, vEdge);
29129 };
29130 Layout2.prototype.checkLayoutSuccess = function() {
29131 return this.graphManager.getRoot() == null || this.graphManager.getRoot().getNodes().length == 0 || this.graphManager.includesInvalidEdge();
29132 };
29133 Layout2.prototype.runLayout = function() {
29134 this.isLayoutFinished = false;
29135 if (this.tilingPreLayout) {
29136 this.tilingPreLayout();
29137 }
29138 this.initParameters();
29139 var isLayoutSuccessfull;
29140 if (this.checkLayoutSuccess()) {
29141 isLayoutSuccessfull = false;
29142 } else {
29143 isLayoutSuccessfull = this.layout();
29144 }
29145 if (LayoutConstants.ANIMATE === "during") {
29146 return false;
29147 }
29148 if (isLayoutSuccessfull) {
29149 if (!this.isSubLayout) {
29150 this.doPostLayout();
29151 }
29152 }
29153 if (this.tilingPostLayout) {
29154 this.tilingPostLayout();
29155 }
29156 this.isLayoutFinished = true;
29157 return isLayoutSuccessfull;
29158 };
29159 Layout2.prototype.doPostLayout = function() {
29160 if (!this.incremental) {
29161 this.transform();
29162 }
29163 this.update();
29164 };
29165 Layout2.prototype.update2 = function() {
29166 if (this.createBendsAsNeeded) {
29167 this.createBendpointsFromDummyNodes();
29168 this.graphManager.resetAllEdges();
29169 }
29170 if (!this.isRemoteUse) {
29171 var allEdges = this.graphManager.getAllEdges();
29172 for (var i = 0; i < allEdges.length; i++) {
29173 allEdges[i];
29174 }
29175 var nodes2 = this.graphManager.getRoot().getNodes();
29176 for (var i = 0; i < nodes2.length; i++) {
29177 nodes2[i];
29178 }
29179 this.update(this.graphManager.getRoot());
29180 }
29181 };
29182 Layout2.prototype.update = function(obj) {
29183 if (obj == null) {
29184 this.update2();
29185 } else if (obj instanceof LNode) {
29186 var node = obj;
29187 if (node.getChild() != null) {
29188 var nodes2 = node.getChild().getNodes();
29189 for (var i = 0; i < nodes2.length; i++) {
29190 update(nodes2[i]);
29191 }
29192 }
29193 if (node.vGraphObject != null) {
29194 var vNode = node.vGraphObject;
29195 vNode.update(node);
29196 }
29197 } else if (obj instanceof LEdge) {
29198 var edge = obj;
29199 if (edge.vGraphObject != null) {
29200 var vEdge = edge.vGraphObject;
29201 vEdge.update(edge);
29202 }
29203 } else if (obj instanceof LGraph) {
29204 var graph = obj;
29205 if (graph.vGraphObject != null) {
29206 var vGraph = graph.vGraphObject;
29207 vGraph.update(graph);
29208 }
29209 }
29210 };
29211 Layout2.prototype.initParameters = function() {
29212 if (!this.isSubLayout) {
29213 this.layoutQuality = LayoutConstants.QUALITY;
29214 this.animationDuringLayout = LayoutConstants.DEFAULT_ANIMATION_DURING_LAYOUT;
29215 this.animationPeriod = LayoutConstants.DEFAULT_ANIMATION_PERIOD;
29216 this.animationOnLayout = LayoutConstants.DEFAULT_ANIMATION_ON_LAYOUT;
29217 this.incremental = LayoutConstants.DEFAULT_INCREMENTAL;
29218 this.createBendsAsNeeded = LayoutConstants.DEFAULT_CREATE_BENDS_AS_NEEDED;
29219 this.uniformLeafNodeSizes = LayoutConstants.DEFAULT_UNIFORM_LEAF_NODE_SIZES;
29220 }
29221 if (this.animationDuringLayout) {
29222 this.animationOnLayout = false;
29223 }
29224 };
29225 Layout2.prototype.transform = function(newLeftTop) {
29226 if (newLeftTop == void 0) {
29227 this.transform(new PointD(0, 0));
29228 } else {
29229 var trans = new Transform();
29230 var leftTop = this.graphManager.getRoot().updateLeftTop();
29231 if (leftTop != null) {
29232 trans.setWorldOrgX(newLeftTop.x);
29233 trans.setWorldOrgY(newLeftTop.y);
29234 trans.setDeviceOrgX(leftTop.x);
29235 trans.setDeviceOrgY(leftTop.y);
29236 var nodes2 = this.getAllNodes();
29237 var node;
29238 for (var i = 0; i < nodes2.length; i++) {
29239 node = nodes2[i];
29240 node.transform(trans);
29241 }
29242 }
29243 }
29244 };
29245 Layout2.prototype.positionNodesRandomly = function(graph) {
29246 if (graph == void 0) {
29247 this.positionNodesRandomly(this.getGraphManager().getRoot());
29248 this.getGraphManager().getRoot().updateBounds(true);
29249 } else {
29250 var lNode;
29251 var childGraph;
29252 var nodes2 = graph.getNodes();
29253 for (var i = 0; i < nodes2.length; i++) {
29254 lNode = nodes2[i];
29255 childGraph = lNode.getChild();
29256 if (childGraph == null) {
29257 lNode.scatter();
29258 } else if (childGraph.getNodes().length == 0) {
29259 lNode.scatter();
29260 } else {
29261 this.positionNodesRandomly(childGraph);
29262 lNode.updateBounds();
29263 }
29264 }
29265 }
29266 };
29267 Layout2.prototype.getFlatForest = function() {
29268 var flatForest = [];
29269 var isForest = true;
29270 var allNodes = this.graphManager.getRoot().getNodes();
29271 var isFlat = true;
29272 for (var i = 0; i < allNodes.length; i++) {
29273 if (allNodes[i].getChild() != null) {
29274 isFlat = false;
29275 }
29276 }
29277 if (!isFlat) {
29278 return flatForest;
29279 }
29280 var visited = /* @__PURE__ */ new Set();
29281 var toBeVisited = [];
29282 var parents = /* @__PURE__ */ new Map();
29283 var unProcessedNodes = [];
29284 unProcessedNodes = unProcessedNodes.concat(allNodes);
29285 while (unProcessedNodes.length > 0 && isForest) {
29286 toBeVisited.push(unProcessedNodes[0]);
29287 while (toBeVisited.length > 0 && isForest) {
29288 var currentNode = toBeVisited[0];
29289 toBeVisited.splice(0, 1);
29290 visited.add(currentNode);
29291 var neighborEdges = currentNode.getEdges();
29292 for (var i = 0; i < neighborEdges.length; i++) {
29293 var currentNeighbor = neighborEdges[i].getOtherEnd(currentNode);
29294 if (parents.get(currentNode) != currentNeighbor) {
29295 if (!visited.has(currentNeighbor)) {
29296 toBeVisited.push(currentNeighbor);
29297 parents.set(currentNeighbor, currentNode);
29298 } else {
29299 isForest = false;
29300 break;
29301 }
29302 }
29303 }
29304 }
29305 if (!isForest) {
29306 flatForest = [];
29307 } else {
29308 var temp = [].concat(_toConsumableArray(visited));
29309 flatForest.push(temp);
29310 for (var i = 0; i < temp.length; i++) {
29311 var value = temp[i];
29312 var index = unProcessedNodes.indexOf(value);
29313 if (index > -1) {
29314 unProcessedNodes.splice(index, 1);
29315 }
29316 }
29317 visited = /* @__PURE__ */ new Set();
29318 parents = /* @__PURE__ */ new Map();
29319 }
29320 }
29321 return flatForest;
29322 };
29323 Layout2.prototype.createDummyNodesForBendpoints = function(edge) {
29324 var dummyNodes = [];
29325 var prev = edge.source;
29326 var graph = this.graphManager.calcLowestCommonAncestor(edge.source, edge.target);
29327 for (var i = 0; i < edge.bendpoints.length; i++) {
29328 var dummyNode = this.newNode(null);
29329 dummyNode.setRect(new Point(0, 0), new Dimension(1, 1));
29330 graph.add(dummyNode);
29331 var dummyEdge = this.newEdge(null);
29332 this.graphManager.add(dummyEdge, prev, dummyNode);
29333 dummyNodes.add(dummyNode);
29334 prev = dummyNode;
29335 }
29336 var dummyEdge = this.newEdge(null);
29337 this.graphManager.add(dummyEdge, prev, edge.target);
29338 this.edgeToDummyNodes.set(edge, dummyNodes);
29339 if (edge.isInterGraph()) {
29340 this.graphManager.remove(edge);
29341 } else {
29342 graph.remove(edge);
29343 }
29344 return dummyNodes;
29345 };
29346 Layout2.prototype.createBendpointsFromDummyNodes = function() {
29347 var edges = [];
29348 edges = edges.concat(this.graphManager.getAllEdges());
29349 edges = [].concat(_toConsumableArray(this.edgeToDummyNodes.keys())).concat(edges);
29350 for (var k = 0; k < edges.length; k++) {
29351 var lEdge = edges[k];
29352 if (lEdge.bendpoints.length > 0) {
29353 var path = this.edgeToDummyNodes.get(lEdge);
29354 for (var i = 0; i < path.length; i++) {
29355 var dummyNode = path[i];
29356 var p = new PointD(dummyNode.getCenterX(), dummyNode.getCenterY());
29357 var ebp = lEdge.bendpoints.get(i);
29358 ebp.x = p.x;
29359 ebp.y = p.y;
29360 dummyNode.getOwner().remove(dummyNode);
29361 }
29362 this.graphManager.add(lEdge, lEdge.source, lEdge.target);
29363 }
29364 }
29365 };
29366 Layout2.transform = function(sliderValue, defaultValue, minDiv, maxMul) {
29367 if (minDiv != void 0 && maxMul != void 0) {
29368 var value = defaultValue;
29369 if (sliderValue <= 50) {
29370 var minValue = defaultValue / minDiv;
29371 value -= (defaultValue - minValue) / 50 * (50 - sliderValue);
29372 } else {
29373 var maxValue = defaultValue * maxMul;
29374 value += (maxValue - defaultValue) / 50 * (sliderValue - 50);
29375 }
29376 return value;
29377 } else {
29378 var a, b;
29379 if (sliderValue <= 50) {
29380 a = 9 * defaultValue / 500;
29381 b = defaultValue / 10;
29382 } else {
29383 a = 9 * defaultValue / 50;
29384 b = -8 * defaultValue;
29385 }
29386 return a * sliderValue + b;
29387 }
29388 };
29389 Layout2.findCenterOfTree = function(nodes2) {
29390 var list = [];
29391 list = list.concat(nodes2);
29392 var removedNodes = [];
29393 var remainingDegrees = /* @__PURE__ */ new Map();
29394 var foundCenter = false;
29395 var centerNode = null;
29396 if (list.length == 1 || list.length == 2) {
29397 foundCenter = true;
29398 centerNode = list[0];
29399 }
29400 for (var i = 0; i < list.length; i++) {
29401 var node = list[i];
29402 var degree = node.getNeighborsList().size;
29403 remainingDegrees.set(node, node.getNeighborsList().size);
29404 if (degree == 1) {
29405 removedNodes.push(node);
29406 }
29407 }
29408 var tempList = [];
29409 tempList = tempList.concat(removedNodes);
29410 while (!foundCenter) {
29411 var tempList2 = [];
29412 tempList2 = tempList2.concat(tempList);
29413 tempList = [];
29414 for (var i = 0; i < list.length; i++) {
29415 var node = list[i];
29416 var index = list.indexOf(node);
29417 if (index >= 0) {
29418 list.splice(index, 1);
29419 }
29420 var neighbours = node.getNeighborsList();
29421 neighbours.forEach(function(neighbour) {
29422 if (removedNodes.indexOf(neighbour) < 0) {
29423 var otherDegree = remainingDegrees.get(neighbour);
29424 var newDegree = otherDegree - 1;
29425 if (newDegree == 1) {
29426 tempList.push(neighbour);
29427 }
29428 remainingDegrees.set(neighbour, newDegree);
29429 }
29430 });
29431 }
29432 removedNodes = removedNodes.concat(tempList);
29433 if (list.length == 1 || list.length == 2) {
29434 foundCenter = true;
29435 centerNode = list[0];
29436 }
29437 }
29438 return centerNode;
29439 };
29440 Layout2.prototype.setGraphManager = function(gm) {
29441 this.graphManager = gm;
29442 };
29443 module2.exports = Layout2;
29444 },
29445 /* 16 */
29446 /***/
29447 function(module2, exports2, __webpack_require__) {
29448 function RandomSeed() {
29449 }
29450 RandomSeed.seed = 1;
29451 RandomSeed.x = 0;
29452 RandomSeed.nextDouble = function() {
29453 RandomSeed.x = Math.sin(RandomSeed.seed++) * 1e4;
29454 return RandomSeed.x - Math.floor(RandomSeed.x);
29455 };
29456 module2.exports = RandomSeed;
29457 },
29458 /* 17 */
29459 /***/
29460 function(module2, exports2, __webpack_require__) {
29461 var PointD = __webpack_require__(4);
29462 function Transform(x, y) {
29463 this.lworldOrgX = 0;
29464 this.lworldOrgY = 0;
29465 this.ldeviceOrgX = 0;
29466 this.ldeviceOrgY = 0;
29467 this.lworldExtX = 1;
29468 this.lworldExtY = 1;
29469 this.ldeviceExtX = 1;
29470 this.ldeviceExtY = 1;
29471 }
29472 Transform.prototype.getWorldOrgX = function() {
29473 return this.lworldOrgX;
29474 };
29475 Transform.prototype.setWorldOrgX = function(wox) {
29476 this.lworldOrgX = wox;
29477 };
29478 Transform.prototype.getWorldOrgY = function() {
29479 return this.lworldOrgY;
29480 };
29481 Transform.prototype.setWorldOrgY = function(woy) {
29482 this.lworldOrgY = woy;
29483 };
29484 Transform.prototype.getWorldExtX = function() {
29485 return this.lworldExtX;
29486 };
29487 Transform.prototype.setWorldExtX = function(wex) {
29488 this.lworldExtX = wex;
29489 };
29490 Transform.prototype.getWorldExtY = function() {
29491 return this.lworldExtY;
29492 };
29493 Transform.prototype.setWorldExtY = function(wey) {
29494 this.lworldExtY = wey;
29495 };
29496 Transform.prototype.getDeviceOrgX = function() {
29497 return this.ldeviceOrgX;
29498 };
29499 Transform.prototype.setDeviceOrgX = function(dox) {
29500 this.ldeviceOrgX = dox;
29501 };
29502 Transform.prototype.getDeviceOrgY = function() {
29503 return this.ldeviceOrgY;
29504 };
29505 Transform.prototype.setDeviceOrgY = function(doy) {
29506 this.ldeviceOrgY = doy;
29507 };
29508 Transform.prototype.getDeviceExtX = function() {
29509 return this.ldeviceExtX;
29510 };
29511 Transform.prototype.setDeviceExtX = function(dex) {
29512 this.ldeviceExtX = dex;
29513 };
29514 Transform.prototype.getDeviceExtY = function() {
29515 return this.ldeviceExtY;
29516 };
29517 Transform.prototype.setDeviceExtY = function(dey) {
29518 this.ldeviceExtY = dey;
29519 };
29520 Transform.prototype.transformX = function(x) {
29521 var xDevice = 0;
29522 var worldExtX = this.lworldExtX;
29523 if (worldExtX != 0) {
29524 xDevice = this.ldeviceOrgX + (x - this.lworldOrgX) * this.ldeviceExtX / worldExtX;
29525 }
29526 return xDevice;
29527 };
29528 Transform.prototype.transformY = function(y) {
29529 var yDevice = 0;
29530 var worldExtY = this.lworldExtY;
29531 if (worldExtY != 0) {
29532 yDevice = this.ldeviceOrgY + (y - this.lworldOrgY) * this.ldeviceExtY / worldExtY;
29533 }
29534 return yDevice;
29535 };
29536 Transform.prototype.inverseTransformX = function(x) {
29537 var xWorld = 0;
29538 var deviceExtX = this.ldeviceExtX;
29539 if (deviceExtX != 0) {
29540 xWorld = this.lworldOrgX + (x - this.ldeviceOrgX) * this.lworldExtX / deviceExtX;
29541 }
29542 return xWorld;
29543 };
29544 Transform.prototype.inverseTransformY = function(y) {
29545 var yWorld = 0;
29546 var deviceExtY = this.ldeviceExtY;
29547 if (deviceExtY != 0) {
29548 yWorld = this.lworldOrgY + (y - this.ldeviceOrgY) * this.lworldExtY / deviceExtY;
29549 }
29550 return yWorld;
29551 };
29552 Transform.prototype.inverseTransformPoint = function(inPoint) {
29553 var outPoint = new PointD(this.inverseTransformX(inPoint.x), this.inverseTransformY(inPoint.y));
29554 return outPoint;
29555 };
29556 module2.exports = Transform;
29557 },
29558 /* 18 */
29559 /***/
29560 function(module2, exports2, __webpack_require__) {
29561 function _toConsumableArray(arr) {
29562 if (Array.isArray(arr)) {
29563 for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
29564 arr2[i] = arr[i];
29565 }
29566 return arr2;
29567 } else {
29568 return Array.from(arr);
29569 }
29570 }
29571 var Layout2 = __webpack_require__(15);
29572 var FDLayoutConstants = __webpack_require__(7);
29573 var LayoutConstants = __webpack_require__(0);
29574 var IGeometry = __webpack_require__(8);
29575 var IMath = __webpack_require__(9);
29576 function FDLayout() {
29577 Layout2.call(this);
29578 this.useSmartIdealEdgeLengthCalculation = FDLayoutConstants.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION;
29579 this.idealEdgeLength = FDLayoutConstants.DEFAULT_EDGE_LENGTH;
29580 this.springConstant = FDLayoutConstants.DEFAULT_SPRING_STRENGTH;
29581 this.repulsionConstant = FDLayoutConstants.DEFAULT_REPULSION_STRENGTH;
29582 this.gravityConstant = FDLayoutConstants.DEFAULT_GRAVITY_STRENGTH;
29583 this.compoundGravityConstant = FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_STRENGTH;
29584 this.gravityRangeFactor = FDLayoutConstants.DEFAULT_GRAVITY_RANGE_FACTOR;
29585 this.compoundGravityRangeFactor = FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR;
29586 this.displacementThresholdPerNode = 3 * FDLayoutConstants.DEFAULT_EDGE_LENGTH / 100;
29587 this.coolingFactor = FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL;
29588 this.initialCoolingFactor = FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL;
29589 this.totalDisplacement = 0;
29590 this.oldTotalDisplacement = 0;
29591 this.maxIterations = FDLayoutConstants.MAX_ITERATIONS;
29592 }
29593 FDLayout.prototype = Object.create(Layout2.prototype);
29594 for (var prop in Layout2) {
29595 FDLayout[prop] = Layout2[prop];
29596 }
29597 FDLayout.prototype.initParameters = function() {
29598 Layout2.prototype.initParameters.call(this, arguments);
29599 this.totalIterations = 0;
29600 this.notAnimatedIterations = 0;
29601 this.useFRGridVariant = FDLayoutConstants.DEFAULT_USE_SMART_REPULSION_RANGE_CALCULATION;
29602 this.grid = [];
29603 };
29604 FDLayout.prototype.calcIdealEdgeLengths = function() {
29605 var edge;
29606 var lcaDepth;
29607 var source;
29608 var target;
29609 var sizeOfSourceInLca;
29610 var sizeOfTargetInLca;
29611 var allEdges = this.getGraphManager().getAllEdges();
29612 for (var i = 0; i < allEdges.length; i++) {
29613 edge = allEdges[i];
29614 edge.idealLength = this.idealEdgeLength;
29615 if (edge.isInterGraph) {
29616 source = edge.getSource();
29617 target = edge.getTarget();
29618 sizeOfSourceInLca = edge.getSourceInLca().getEstimatedSize();
29619 sizeOfTargetInLca = edge.getTargetInLca().getEstimatedSize();
29620 if (this.useSmartIdealEdgeLengthCalculation) {
29621 edge.idealLength += sizeOfSourceInLca + sizeOfTargetInLca - 2 * LayoutConstants.SIMPLE_NODE_SIZE;
29622 }
29623 lcaDepth = edge.getLca().getInclusionTreeDepth();
29624 edge.idealLength += FDLayoutConstants.DEFAULT_EDGE_LENGTH * FDLayoutConstants.PER_LEVEL_IDEAL_EDGE_LENGTH_FACTOR * (source.getInclusionTreeDepth() + target.getInclusionTreeDepth() - 2 * lcaDepth);
29625 }
29626 }
29627 };
29628 FDLayout.prototype.initSpringEmbedder = function() {
29629 var s = this.getAllNodes().length;
29630 if (this.incremental) {
29631 if (s > FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) {
29632 this.coolingFactor = Math.max(this.coolingFactor * FDLayoutConstants.COOLING_ADAPTATION_FACTOR, this.coolingFactor - (s - FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) / (FDLayoutConstants.ADAPTATION_UPPER_NODE_LIMIT - FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) * this.coolingFactor * (1 - FDLayoutConstants.COOLING_ADAPTATION_FACTOR));
29633 }
29634 this.maxNodeDisplacement = FDLayoutConstants.MAX_NODE_DISPLACEMENT_INCREMENTAL;
29635 } else {
29636 if (s > FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) {
29637 this.coolingFactor = Math.max(FDLayoutConstants.COOLING_ADAPTATION_FACTOR, 1 - (s - FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) / (FDLayoutConstants.ADAPTATION_UPPER_NODE_LIMIT - FDLayoutConstants.ADAPTATION_LOWER_NODE_LIMIT) * (1 - FDLayoutConstants.COOLING_ADAPTATION_FACTOR));
29638 } else {
29639 this.coolingFactor = 1;
29640 }
29641 this.initialCoolingFactor = this.coolingFactor;
29642 this.maxNodeDisplacement = FDLayoutConstants.MAX_NODE_DISPLACEMENT;
29643 }
29644 this.maxIterations = Math.max(this.getAllNodes().length * 5, this.maxIterations);
29645 this.totalDisplacementThreshold = this.displacementThresholdPerNode * this.getAllNodes().length;
29646 this.repulsionRange = this.calcRepulsionRange();
29647 };
29648 FDLayout.prototype.calcSpringForces = function() {
29649 var lEdges = this.getAllEdges();
29650 var edge;
29651 for (var i = 0; i < lEdges.length; i++) {
29652 edge = lEdges[i];
29653 this.calcSpringForce(edge, edge.idealLength);
29654 }
29655 };
29656 FDLayout.prototype.calcRepulsionForces = function() {
29657 var gridUpdateAllowed = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
29658 var forceToNodeSurroundingUpdate = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
29659 var i, j;
29660 var nodeA, nodeB;
29661 var lNodes = this.getAllNodes();
29662 var processedNodeSet;
29663 if (this.useFRGridVariant) {
29664 if (this.totalIterations % FDLayoutConstants.GRID_CALCULATION_CHECK_PERIOD == 1 && gridUpdateAllowed) {
29665 this.updateGrid();
29666 }
29667 processedNodeSet = /* @__PURE__ */ new Set();
29668 for (i = 0; i < lNodes.length; i++) {
29669 nodeA = lNodes[i];
29670 this.calculateRepulsionForceOfANode(nodeA, processedNodeSet, gridUpdateAllowed, forceToNodeSurroundingUpdate);
29671 processedNodeSet.add(nodeA);
29672 }
29673 } else {
29674 for (i = 0; i < lNodes.length; i++) {
29675 nodeA = lNodes[i];
29676 for (j = i + 1; j < lNodes.length; j++) {
29677 nodeB = lNodes[j];
29678 if (nodeA.getOwner() != nodeB.getOwner()) {
29679 continue;
29680 }
29681 this.calcRepulsionForce(nodeA, nodeB);
29682 }
29683 }
29684 }
29685 };
29686 FDLayout.prototype.calcGravitationalForces = function() {
29687 var node;
29688 var lNodes = this.getAllNodesToApplyGravitation();
29689 for (var i = 0; i < lNodes.length; i++) {
29690 node = lNodes[i];
29691 this.calcGravitationalForce(node);
29692 }
29693 };
29694 FDLayout.prototype.moveNodes = function() {
29695 var lNodes = this.getAllNodes();
29696 var node;
29697 for (var i = 0; i < lNodes.length; i++) {
29698 node = lNodes[i];
29699 node.move();
29700 }
29701 };
29702 FDLayout.prototype.calcSpringForce = function(edge, idealLength) {
29703 var sourceNode = edge.getSource();
29704 var targetNode = edge.getTarget();
29705 var length;
29706 var springForce;
29707 var springForceX;
29708 var springForceY;
29709 if (this.uniformLeafNodeSizes && sourceNode.getChild() == null && targetNode.getChild() == null) {
29710 edge.updateLengthSimple();
29711 } else {
29712 edge.updateLength();
29713 if (edge.isOverlapingSourceAndTarget) {
29714 return;
29715 }
29716 }
29717 length = edge.getLength();
29718 if (length == 0)
29719 return;
29720 springForce = this.springConstant * (length - idealLength);
29721 springForceX = springForce * (edge.lengthX / length);
29722 springForceY = springForce * (edge.lengthY / length);
29723 sourceNode.springForceX += springForceX;
29724 sourceNode.springForceY += springForceY;
29725 targetNode.springForceX -= springForceX;
29726 targetNode.springForceY -= springForceY;
29727 };
29728 FDLayout.prototype.calcRepulsionForce = function(nodeA, nodeB) {
29729 var rectA = nodeA.getRect();
29730 var rectB = nodeB.getRect();
29731 var overlapAmount = new Array(2);
29732 var clipPoints = new Array(4);
29733 var distanceX;
29734 var distanceY;
29735 var distanceSquared;
29736 var distance;
29737 var repulsionForce;
29738 var repulsionForceX;
29739 var repulsionForceY;
29740 if (rectA.intersects(rectB)) {
29741 IGeometry.calcSeparationAmount(rectA, rectB, overlapAmount, FDLayoutConstants.DEFAULT_EDGE_LENGTH / 2);
29742 repulsionForceX = 2 * overlapAmount[0];
29743 repulsionForceY = 2 * overlapAmount[1];
29744 var childrenConstant = nodeA.noOfChildren * nodeB.noOfChildren / (nodeA.noOfChildren + nodeB.noOfChildren);
29745 nodeA.repulsionForceX -= childrenConstant * repulsionForceX;
29746 nodeA.repulsionForceY -= childrenConstant * repulsionForceY;
29747 nodeB.repulsionForceX += childrenConstant * repulsionForceX;
29748 nodeB.repulsionForceY += childrenConstant * repulsionForceY;
29749 } else {
29750 if (this.uniformLeafNodeSizes && nodeA.getChild() == null && nodeB.getChild() == null) {
29751 distanceX = rectB.getCenterX() - rectA.getCenterX();
29752 distanceY = rectB.getCenterY() - rectA.getCenterY();
29753 } else {
29754 IGeometry.getIntersection(rectA, rectB, clipPoints);
29755 distanceX = clipPoints[2] - clipPoints[0];
29756 distanceY = clipPoints[3] - clipPoints[1];
29757 }
29758 if (Math.abs(distanceX) < FDLayoutConstants.MIN_REPULSION_DIST) {
29759 distanceX = IMath.sign(distanceX) * FDLayoutConstants.MIN_REPULSION_DIST;
29760 }
29761 if (Math.abs(distanceY) < FDLayoutConstants.MIN_REPULSION_DIST) {
29762 distanceY = IMath.sign(distanceY) * FDLayoutConstants.MIN_REPULSION_DIST;
29763 }
29764 distanceSquared = distanceX * distanceX + distanceY * distanceY;
29765 distance = Math.sqrt(distanceSquared);
29766 repulsionForce = this.repulsionConstant * nodeA.noOfChildren * nodeB.noOfChildren / distanceSquared;
29767 repulsionForceX = repulsionForce * distanceX / distance;
29768 repulsionForceY = repulsionForce * distanceY / distance;
29769 nodeA.repulsionForceX -= repulsionForceX;
29770 nodeA.repulsionForceY -= repulsionForceY;
29771 nodeB.repulsionForceX += repulsionForceX;
29772 nodeB.repulsionForceY += repulsionForceY;
29773 }
29774 };
29775 FDLayout.prototype.calcGravitationalForce = function(node) {
29776 var ownerGraph;
29777 var ownerCenterX;
29778 var ownerCenterY;
29779 var distanceX;
29780 var distanceY;
29781 var absDistanceX;
29782 var absDistanceY;
29783 var estimatedSize;
29784 ownerGraph = node.getOwner();
29785 ownerCenterX = (ownerGraph.getRight() + ownerGraph.getLeft()) / 2;
29786 ownerCenterY = (ownerGraph.getTop() + ownerGraph.getBottom()) / 2;
29787 distanceX = node.getCenterX() - ownerCenterX;
29788 distanceY = node.getCenterY() - ownerCenterY;
29789 absDistanceX = Math.abs(distanceX) + node.getWidth() / 2;
29790 absDistanceY = Math.abs(distanceY) + node.getHeight() / 2;
29791 if (node.getOwner() == this.graphManager.getRoot()) {
29792 estimatedSize = ownerGraph.getEstimatedSize() * this.gravityRangeFactor;
29793 if (absDistanceX > estimatedSize || absDistanceY > estimatedSize) {
29794 node.gravitationForceX = -this.gravityConstant * distanceX;
29795 node.gravitationForceY = -this.gravityConstant * distanceY;
29796 }
29797 } else {
29798 estimatedSize = ownerGraph.getEstimatedSize() * this.compoundGravityRangeFactor;
29799 if (absDistanceX > estimatedSize || absDistanceY > estimatedSize) {
29800 node.gravitationForceX = -this.gravityConstant * distanceX * this.compoundGravityConstant;
29801 node.gravitationForceY = -this.gravityConstant * distanceY * this.compoundGravityConstant;
29802 }
29803 }
29804 };
29805 FDLayout.prototype.isConverged = function() {
29806 var converged;
29807 var oscilating = false;
29808 if (this.totalIterations > this.maxIterations / 3) {
29809 oscilating = Math.abs(this.totalDisplacement - this.oldTotalDisplacement) < 2;
29810 }
29811 converged = this.totalDisplacement < this.totalDisplacementThreshold;
29812 this.oldTotalDisplacement = this.totalDisplacement;
29813 return converged || oscilating;
29814 };
29815 FDLayout.prototype.animate = function() {
29816 if (this.animationDuringLayout && !this.isSubLayout) {
29817 if (this.notAnimatedIterations == this.animationPeriod) {
29818 this.update();
29819 this.notAnimatedIterations = 0;
29820 } else {
29821 this.notAnimatedIterations++;
29822 }
29823 }
29824 };
29825 FDLayout.prototype.calcNoOfChildrenForAllNodes = function() {
29826 var node;
29827 var allNodes = this.graphManager.getAllNodes();
29828 for (var i = 0; i < allNodes.length; i++) {
29829 node = allNodes[i];
29830 node.noOfChildren = node.getNoOfChildren();
29831 }
29832 };
29833 FDLayout.prototype.calcGrid = function(graph) {
29834 var sizeX = 0;
29835 var sizeY = 0;
29836 sizeX = parseInt(Math.ceil((graph.getRight() - graph.getLeft()) / this.repulsionRange));
29837 sizeY = parseInt(Math.ceil((graph.getBottom() - graph.getTop()) / this.repulsionRange));
29838 var grid = new Array(sizeX);
29839 for (var i = 0; i < sizeX; i++) {
29840 grid[i] = new Array(sizeY);
29841 }
29842 for (var i = 0; i < sizeX; i++) {
29843 for (var j = 0; j < sizeY; j++) {
29844 grid[i][j] = new Array();
29845 }
29846 }
29847 return grid;
29848 };
29849 FDLayout.prototype.addNodeToGrid = function(v, left, top) {
29850 var startX = 0;
29851 var finishX = 0;
29852 var startY = 0;
29853 var finishY = 0;
29854 startX = parseInt(Math.floor((v.getRect().x - left) / this.repulsionRange));
29855 finishX = parseInt(Math.floor((v.getRect().width + v.getRect().x - left) / this.repulsionRange));
29856 startY = parseInt(Math.floor((v.getRect().y - top) / this.repulsionRange));
29857 finishY = parseInt(Math.floor((v.getRect().height + v.getRect().y - top) / this.repulsionRange));
29858 for (var i = startX; i <= finishX; i++) {
29859 for (var j = startY; j <= finishY; j++) {
29860 this.grid[i][j].push(v);
29861 v.setGridCoordinates(startX, finishX, startY, finishY);
29862 }
29863 }
29864 };
29865 FDLayout.prototype.updateGrid = function() {
29866 var i;
29867 var nodeA;
29868 var lNodes = this.getAllNodes();
29869 this.grid = this.calcGrid(this.graphManager.getRoot());
29870 for (i = 0; i < lNodes.length; i++) {
29871 nodeA = lNodes[i];
29872 this.addNodeToGrid(nodeA, this.graphManager.getRoot().getLeft(), this.graphManager.getRoot().getTop());
29873 }
29874 };
29875 FDLayout.prototype.calculateRepulsionForceOfANode = function(nodeA, processedNodeSet, gridUpdateAllowed, forceToNodeSurroundingUpdate) {
29876 if (this.totalIterations % FDLayoutConstants.GRID_CALCULATION_CHECK_PERIOD == 1 && gridUpdateAllowed || forceToNodeSurroundingUpdate) {
29877 var surrounding = /* @__PURE__ */ new Set();
29878 nodeA.surrounding = new Array();
29879 var nodeB;
29880 var grid = this.grid;
29881 for (var i = nodeA.startX - 1; i < nodeA.finishX + 2; i++) {
29882 for (var j = nodeA.startY - 1; j < nodeA.finishY + 2; j++) {
29883 if (!(i < 0 || j < 0 || i >= grid.length || j >= grid[0].length)) {
29884 for (var k = 0; k < grid[i][j].length; k++) {
29885 nodeB = grid[i][j][k];
29886 if (nodeA.getOwner() != nodeB.getOwner() || nodeA == nodeB) {
29887 continue;
29888 }
29889 if (!processedNodeSet.has(nodeB) && !surrounding.has(nodeB)) {
29890 var distanceX = Math.abs(nodeA.getCenterX() - nodeB.getCenterX()) - (nodeA.getWidth() / 2 + nodeB.getWidth() / 2);
29891 var distanceY = Math.abs(nodeA.getCenterY() - nodeB.getCenterY()) - (nodeA.getHeight() / 2 + nodeB.getHeight() / 2);
29892 if (distanceX <= this.repulsionRange && distanceY <= this.repulsionRange) {
29893 surrounding.add(nodeB);
29894 }
29895 }
29896 }
29897 }
29898 }
29899 }
29900 nodeA.surrounding = [].concat(_toConsumableArray(surrounding));
29901 }
29902 for (i = 0; i < nodeA.surrounding.length; i++) {
29903 this.calcRepulsionForce(nodeA, nodeA.surrounding[i]);
29904 }
29905 };
29906 FDLayout.prototype.calcRepulsionRange = function() {
29907 return 0;
29908 };
29909 module2.exports = FDLayout;
29910 },
29911 /* 19 */
29912 /***/
29913 function(module2, exports2, __webpack_require__) {
29914 var LEdge = __webpack_require__(1);
29915 var FDLayoutConstants = __webpack_require__(7);
29916 function FDLayoutEdge(source, target, vEdge) {
29917 LEdge.call(this, source, target, vEdge);
29918 this.idealLength = FDLayoutConstants.DEFAULT_EDGE_LENGTH;
29919 }
29920 FDLayoutEdge.prototype = Object.create(LEdge.prototype);
29921 for (var prop in LEdge) {
29922 FDLayoutEdge[prop] = LEdge[prop];
29923 }
29924 module2.exports = FDLayoutEdge;
29925 },
29926 /* 20 */
29927 /***/
29928 function(module2, exports2, __webpack_require__) {
29929 var LNode = __webpack_require__(3);
29930 function FDLayoutNode(gm, loc, size, vNode) {
29931 LNode.call(this, gm, loc, size, vNode);
29932 this.springForceX = 0;
29933 this.springForceY = 0;
29934 this.repulsionForceX = 0;
29935 this.repulsionForceY = 0;
29936 this.gravitationForceX = 0;
29937 this.gravitationForceY = 0;
29938 this.displacementX = 0;
29939 this.displacementY = 0;
29940 this.startX = 0;
29941 this.finishX = 0;
29942 this.startY = 0;
29943 this.finishY = 0;
29944 this.surrounding = [];
29945 }
29946 FDLayoutNode.prototype = Object.create(LNode.prototype);
29947 for (var prop in LNode) {
29948 FDLayoutNode[prop] = LNode[prop];
29949 }
29950 FDLayoutNode.prototype.setGridCoordinates = function(_startX, _finishX, _startY, _finishY) {
29951 this.startX = _startX;
29952 this.finishX = _finishX;
29953 this.startY = _startY;
29954 this.finishY = _finishY;
29955 };
29956 module2.exports = FDLayoutNode;
29957 },
29958 /* 21 */
29959 /***/
29960 function(module2, exports2, __webpack_require__) {
29961 function DimensionD2(width, height) {
29962 this.width = 0;
29963 this.height = 0;
29964 if (width !== null && height !== null) {
29965 this.height = height;
29966 this.width = width;
29967 }
29968 }
29969 DimensionD2.prototype.getWidth = function() {
29970 return this.width;
29971 };
29972 DimensionD2.prototype.setWidth = function(width) {
29973 this.width = width;
29974 };
29975 DimensionD2.prototype.getHeight = function() {
29976 return this.height;
29977 };
29978 DimensionD2.prototype.setHeight = function(height) {
29979 this.height = height;
29980 };
29981 module2.exports = DimensionD2;
29982 },
29983 /* 22 */
29984 /***/
29985 function(module2, exports2, __webpack_require__) {
29986 var UniqueIDGeneretor = __webpack_require__(14);
29987 function HashMap() {
29988 this.map = {};
29989 this.keys = [];
29990 }
29991 HashMap.prototype.put = function(key, value) {
29992 var theId = UniqueIDGeneretor.createID(key);
29993 if (!this.contains(theId)) {
29994 this.map[theId] = value;
29995 this.keys.push(key);
29996 }
29997 };
29998 HashMap.prototype.contains = function(key) {
29999 UniqueIDGeneretor.createID(key);
30000 return this.map[key] != null;
30001 };
30002 HashMap.prototype.get = function(key) {
30003 var theId = UniqueIDGeneretor.createID(key);
30004 return this.map[theId];
30005 };
30006 HashMap.prototype.keySet = function() {
30007 return this.keys;
30008 };
30009 module2.exports = HashMap;
30010 },
30011 /* 23 */
30012 /***/
30013 function(module2, exports2, __webpack_require__) {
30014 var UniqueIDGeneretor = __webpack_require__(14);
30015 function HashSet() {
30016 this.set = {};
30017 }
30018 HashSet.prototype.add = function(obj) {
30019 var theId = UniqueIDGeneretor.createID(obj);
30020 if (!this.contains(theId))
30021 this.set[theId] = obj;
30022 };
30023 HashSet.prototype.remove = function(obj) {
30024 delete this.set[UniqueIDGeneretor.createID(obj)];
30025 };
30026 HashSet.prototype.clear = function() {
30027 this.set = {};
30028 };
30029 HashSet.prototype.contains = function(obj) {
30030 return this.set[UniqueIDGeneretor.createID(obj)] == obj;
30031 };
30032 HashSet.prototype.isEmpty = function() {
30033 return this.size() === 0;
30034 };
30035 HashSet.prototype.size = function() {
30036 return Object.keys(this.set).length;
30037 };
30038 HashSet.prototype.addAllTo = function(list) {
30039 var keys = Object.keys(this.set);
30040 var length = keys.length;
30041 for (var i = 0; i < length; i++) {
30042 list.push(this.set[keys[i]]);
30043 }
30044 };
30045 HashSet.prototype.size = function() {
30046 return Object.keys(this.set).length;
30047 };
30048 HashSet.prototype.addAll = function(list) {
30049 var s = list.length;
30050 for (var i = 0; i < s; i++) {
30051 var v = list[i];
30052 this.add(v);
30053 }
30054 };
30055 module2.exports = HashSet;
30056 },
30057 /* 24 */
30058 /***/
30059 function(module2, exports2, __webpack_require__) {
30060 var _createClass = function() {
30061 function defineProperties(target, props) {
30062 for (var i = 0; i < props.length; i++) {
30063 var descriptor = props[i];
30064 descriptor.enumerable = descriptor.enumerable || false;
30065 descriptor.configurable = true;
30066 if ("value" in descriptor)
30067 descriptor.writable = true;
30068 Object.defineProperty(target, descriptor.key, descriptor);
30069 }
30070 }
30071 return function(Constructor, protoProps, staticProps) {
30072 if (protoProps)
30073 defineProperties(Constructor.prototype, protoProps);
30074 if (staticProps)
30075 defineProperties(Constructor, staticProps);
30076 return Constructor;
30077 };
30078 }();
30079 function _classCallCheck(instance2, Constructor) {
30080 if (!(instance2 instanceof Constructor)) {
30081 throw new TypeError("Cannot call a class as a function");
30082 }
30083 }
30084 var LinkedList = __webpack_require__(11);
30085 var Quicksort = function() {
30086 function Quicksort2(A, compareFunction) {
30087 _classCallCheck(this, Quicksort2);
30088 if (compareFunction !== null || compareFunction !== void 0)
30089 this.compareFunction = this._defaultCompareFunction;
30090 var length = void 0;
30091 if (A instanceof LinkedList)
30092 length = A.size();
30093 else
30094 length = A.length;
30095 this._quicksort(A, 0, length - 1);
30096 }
30097 _createClass(Quicksort2, [{
30098 key: "_quicksort",
30099 value: function _quicksort(A, p, r) {
30100 if (p < r) {
30101 var q = this._partition(A, p, r);
30102 this._quicksort(A, p, q);
30103 this._quicksort(A, q + 1, r);
30104 }
30105 }
30106 }, {
30107 key: "_partition",
30108 value: function _partition(A, p, r) {
30109 var x = this._get(A, p);
30110 var i = p;
30111 var j = r;
30112 while (true) {
30113 while (this.compareFunction(x, this._get(A, j))) {
30114 j--;
30115 }
30116 while (this.compareFunction(this._get(A, i), x)) {
30117 i++;
30118 }
30119 if (i < j) {
30120 this._swap(A, i, j);
30121 i++;
30122 j--;
30123 } else
30124 return j;
30125 }
30126 }
30127 }, {
30128 key: "_get",
30129 value: function _get(object, index) {
30130 if (object instanceof LinkedList)
30131 return object.get_object_at(index);
30132 else
30133 return object[index];
30134 }
30135 }, {
30136 key: "_set",
30137 value: function _set(object, index, value) {
30138 if (object instanceof LinkedList)
30139 object.set_object_at(index, value);
30140 else
30141 object[index] = value;
30142 }
30143 }, {
30144 key: "_swap",
30145 value: function _swap(A, i, j) {
30146 var temp = this._get(A, i);
30147 this._set(A, i, this._get(A, j));
30148 this._set(A, j, temp);
30149 }
30150 }, {
30151 key: "_defaultCompareFunction",
30152 value: function _defaultCompareFunction(a, b) {
30153 return b > a;
30154 }
30155 }]);
30156 return Quicksort2;
30157 }();
30158 module2.exports = Quicksort;
30159 },
30160 /* 25 */
30161 /***/
30162 function(module2, exports2, __webpack_require__) {
30163 var _createClass = function() {
30164 function defineProperties(target, props) {
30165 for (var i = 0; i < props.length; i++) {
30166 var descriptor = props[i];
30167 descriptor.enumerable = descriptor.enumerable || false;
30168 descriptor.configurable = true;
30169 if ("value" in descriptor)
30170 descriptor.writable = true;
30171 Object.defineProperty(target, descriptor.key, descriptor);
30172 }
30173 }
30174 return function(Constructor, protoProps, staticProps) {
30175 if (protoProps)
30176 defineProperties(Constructor.prototype, protoProps);
30177 if (staticProps)
30178 defineProperties(Constructor, staticProps);
30179 return Constructor;
30180 };
30181 }();
30182 function _classCallCheck(instance2, Constructor) {
30183 if (!(instance2 instanceof Constructor)) {
30184 throw new TypeError("Cannot call a class as a function");
30185 }
30186 }
30187 var NeedlemanWunsch = function() {
30188 function NeedlemanWunsch2(sequence1, sequence2) {
30189 var match_score = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1;
30190 var mismatch_penalty = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : -1;
30191 var gap_penalty = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : -1;
30192 _classCallCheck(this, NeedlemanWunsch2);
30193 this.sequence1 = sequence1;
30194 this.sequence2 = sequence2;
30195 this.match_score = match_score;
30196 this.mismatch_penalty = mismatch_penalty;
30197 this.gap_penalty = gap_penalty;
30198 this.iMax = sequence1.length + 1;
30199 this.jMax = sequence2.length + 1;
30200 this.grid = new Array(this.iMax);
30201 for (var i = 0; i < this.iMax; i++) {
30202 this.grid[i] = new Array(this.jMax);
30203 for (var j = 0; j < this.jMax; j++) {
30204 this.grid[i][j] = 0;
30205 }
30206 }
30207 this.tracebackGrid = new Array(this.iMax);
30208 for (var _i = 0; _i < this.iMax; _i++) {
30209 this.tracebackGrid[_i] = new Array(this.jMax);
30210 for (var _j = 0; _j < this.jMax; _j++) {
30211 this.tracebackGrid[_i][_j] = [null, null, null];
30212 }
30213 }
30214 this.alignments = [];
30215 this.score = -1;
30216 this.computeGrids();
30217 }
30218 _createClass(NeedlemanWunsch2, [{
30219 key: "getScore",
30220 value: function getScore() {
30221 return this.score;
30222 }
30223 }, {
30224 key: "getAlignments",
30225 value: function getAlignments() {
30226 return this.alignments;
30227 }
30228 // Main dynamic programming procedure
30229 }, {
30230 key: "computeGrids",
30231 value: function computeGrids() {
30232 for (var j = 1; j < this.jMax; j++) {
30233 this.grid[0][j] = this.grid[0][j - 1] + this.gap_penalty;
30234 this.tracebackGrid[0][j] = [false, false, true];
30235 }
30236 for (var i = 1; i < this.iMax; i++) {
30237 this.grid[i][0] = this.grid[i - 1][0] + this.gap_penalty;
30238 this.tracebackGrid[i][0] = [false, true, false];
30239 }
30240 for (var _i2 = 1; _i2 < this.iMax; _i2++) {
30241 for (var _j2 = 1; _j2 < this.jMax; _j2++) {
30242 var diag = void 0;
30243 if (this.sequence1[_i2 - 1] === this.sequence2[_j2 - 1])
30244 diag = this.grid[_i2 - 1][_j2 - 1] + this.match_score;
30245 else
30246 diag = this.grid[_i2 - 1][_j2 - 1] + this.mismatch_penalty;
30247 var up = this.grid[_i2 - 1][_j2] + this.gap_penalty;
30248 var left = this.grid[_i2][_j2 - 1] + this.gap_penalty;
30249 var maxOf = [diag, up, left];
30250 var indices = this.arrayAllMaxIndexes(maxOf);
30251 this.grid[_i2][_j2] = maxOf[indices[0]];
30252 this.tracebackGrid[_i2][_j2] = [indices.includes(0), indices.includes(1), indices.includes(2)];
30253 }
30254 }
30255 this.score = this.grid[this.iMax - 1][this.jMax - 1];
30256 }
30257 // Gets all possible valid sequence combinations
30258 }, {
30259 key: "alignmentTraceback",
30260 value: function alignmentTraceback() {
30261 var inProcessAlignments = [];
30262 inProcessAlignments.push({
30263 pos: [this.sequence1.length, this.sequence2.length],
30264 seq1: "",
30265 seq2: ""
30266 });
30267 while (inProcessAlignments[0]) {
30268 var current = inProcessAlignments[0];
30269 var directions = this.tracebackGrid[current.pos[0]][current.pos[1]];
30270 if (directions[0]) {
30271 inProcessAlignments.push({
30272 pos: [current.pos[0] - 1, current.pos[1] - 1],
30273 seq1: this.sequence1[current.pos[0] - 1] + current.seq1,
30274 seq2: this.sequence2[current.pos[1] - 1] + current.seq2
30275 });
30276 }
30277 if (directions[1]) {
30278 inProcessAlignments.push({
30279 pos: [current.pos[0] - 1, current.pos[1]],
30280 seq1: this.sequence1[current.pos[0] - 1] + current.seq1,
30281 seq2: "-" + current.seq2
30282 });
30283 }
30284 if (directions[2]) {
30285 inProcessAlignments.push({
30286 pos: [current.pos[0], current.pos[1] - 1],
30287 seq1: "-" + current.seq1,
30288 seq2: this.sequence2[current.pos[1] - 1] + current.seq2
30289 });
30290 }
30291 if (current.pos[0] === 0 && current.pos[1] === 0)
30292 this.alignments.push({
30293 sequence1: current.seq1,
30294 sequence2: current.seq2
30295 });
30296 inProcessAlignments.shift();
30297 }
30298 return this.alignments;
30299 }
30300 // Helper Functions
30301 }, {
30302 key: "getAllIndexes",
30303 value: function getAllIndexes(arr, val) {
30304 var indexes = [], i = -1;
30305 while ((i = arr.indexOf(val, i + 1)) !== -1) {
30306 indexes.push(i);
30307 }
30308 return indexes;
30309 }
30310 }, {
30311 key: "arrayAllMaxIndexes",
30312 value: function arrayAllMaxIndexes(array) {
30313 return this.getAllIndexes(array, Math.max.apply(null, array));
30314 }
30315 }]);
30316 return NeedlemanWunsch2;
30317 }();
30318 module2.exports = NeedlemanWunsch;
30319 },
30320 /* 26 */
30321 /***/
30322 function(module2, exports2, __webpack_require__) {
30323 var layoutBase2 = function layoutBase3() {
30324 return;
30325 };
30326 layoutBase2.FDLayout = __webpack_require__(18);
30327 layoutBase2.FDLayoutConstants = __webpack_require__(7);
30328 layoutBase2.FDLayoutEdge = __webpack_require__(19);
30329 layoutBase2.FDLayoutNode = __webpack_require__(20);
30330 layoutBase2.DimensionD = __webpack_require__(21);
30331 layoutBase2.HashMap = __webpack_require__(22);
30332 layoutBase2.HashSet = __webpack_require__(23);
30333 layoutBase2.IGeometry = __webpack_require__(8);
30334 layoutBase2.IMath = __webpack_require__(9);
30335 layoutBase2.Integer = __webpack_require__(10);
30336 layoutBase2.Point = __webpack_require__(12);
30337 layoutBase2.PointD = __webpack_require__(4);
30338 layoutBase2.RandomSeed = __webpack_require__(16);
30339 layoutBase2.RectangleD = __webpack_require__(13);
30340 layoutBase2.Transform = __webpack_require__(17);
30341 layoutBase2.UniqueIDGeneretor = __webpack_require__(14);
30342 layoutBase2.Quicksort = __webpack_require__(24);
30343 layoutBase2.LinkedList = __webpack_require__(11);
30344 layoutBase2.LGraphObject = __webpack_require__(2);
30345 layoutBase2.LGraph = __webpack_require__(5);
30346 layoutBase2.LEdge = __webpack_require__(1);
30347 layoutBase2.LGraphManager = __webpack_require__(6);
30348 layoutBase2.LNode = __webpack_require__(3);
30349 layoutBase2.Layout = __webpack_require__(15);
30350 layoutBase2.LayoutConstants = __webpack_require__(0);
30351 layoutBase2.NeedlemanWunsch = __webpack_require__(25);
30352 module2.exports = layoutBase2;
30353 },
30354 /* 27 */
30355 /***/
30356 function(module2, exports2, __webpack_require__) {
30357 function Emitter() {
30358 this.listeners = [];
30359 }
30360 var p = Emitter.prototype;
30361 p.addListener = function(event, callback) {
30362 this.listeners.push({
30363 event,
30364 callback
30365 });
30366 };
30367 p.removeListener = function(event, callback) {
30368 for (var i = this.listeners.length; i >= 0; i--) {
30369 var l = this.listeners[i];
30370 if (l.event === event && l.callback === callback) {
30371 this.listeners.splice(i, 1);
30372 }
30373 }
30374 };
30375 p.emit = function(event, data) {
30376 for (var i = 0; i < this.listeners.length; i++) {
30377 var l = this.listeners[i];
30378 if (event === l.event) {
30379 l.callback(data);
30380 }
30381 }
30382 };
30383 module2.exports = Emitter;
30384 }
30385 /******/
30386 ])
30387 );
30388 });
30389 })(layoutBase);
30390 return layoutBaseExports;
30391}
30392var hasRequiredCoseBase;
30393function requireCoseBase() {
30394 if (hasRequiredCoseBase)
30395 return coseBaseExports;
30396 hasRequiredCoseBase = 1;
30397 (function(module, exports) {
30398 (function webpackUniversalModuleDefinition(root, factory) {
30399 module.exports = factory(requireLayoutBase());
30400 })(commonjsGlobal, function(__WEBPACK_EXTERNAL_MODULE_0__) {
30401 return (
30402 /******/
30403 function(modules) {
30404 var installedModules = {};
30405 function __webpack_require__(moduleId) {
30406 if (installedModules[moduleId]) {
30407 return installedModules[moduleId].exports;
30408 }
30409 var module2 = installedModules[moduleId] = {
30410 /******/
30411 i: moduleId,
30412 /******/
30413 l: false,
30414 /******/
30415 exports: {}
30416 /******/
30417 };
30418 modules[moduleId].call(module2.exports, module2, module2.exports, __webpack_require__);
30419 module2.l = true;
30420 return module2.exports;
30421 }
30422 __webpack_require__.m = modules;
30423 __webpack_require__.c = installedModules;
30424 __webpack_require__.i = function(value) {
30425 return value;
30426 };
30427 __webpack_require__.d = function(exports2, name2, getter) {
30428 if (!__webpack_require__.o(exports2, name2)) {
30429 Object.defineProperty(exports2, name2, {
30430 /******/
30431 configurable: false,
30432 /******/
30433 enumerable: true,
30434 /******/
30435 get: getter
30436 /******/
30437 });
30438 }
30439 };
30440 __webpack_require__.n = function(module2) {
30441 var getter = module2 && module2.__esModule ? (
30442 /******/
30443 function getDefault() {
30444 return module2["default"];
30445 }
30446 ) : (
30447 /******/
30448 function getModuleExports() {
30449 return module2;
30450 }
30451 );
30452 __webpack_require__.d(getter, "a", getter);
30453 return getter;
30454 };
30455 __webpack_require__.o = function(object, property) {
30456 return Object.prototype.hasOwnProperty.call(object, property);
30457 };
30458 __webpack_require__.p = "";
30459 return __webpack_require__(__webpack_require__.s = 7);
30460 }([
30461 /* 0 */
30462 /***/
30463 function(module2, exports2) {
30464 module2.exports = __WEBPACK_EXTERNAL_MODULE_0__;
30465 },
30466 /* 1 */
30467 /***/
30468 function(module2, exports2, __webpack_require__) {
30469 var FDLayoutConstants = __webpack_require__(0).FDLayoutConstants;
30470 function CoSEConstants() {
30471 }
30472 for (var prop in FDLayoutConstants) {
30473 CoSEConstants[prop] = FDLayoutConstants[prop];
30474 }
30475 CoSEConstants.DEFAULT_USE_MULTI_LEVEL_SCALING = false;
30476 CoSEConstants.DEFAULT_RADIAL_SEPARATION = FDLayoutConstants.DEFAULT_EDGE_LENGTH;
30477 CoSEConstants.DEFAULT_COMPONENT_SEPERATION = 60;
30478 CoSEConstants.TILE = true;
30479 CoSEConstants.TILING_PADDING_VERTICAL = 10;
30480 CoSEConstants.TILING_PADDING_HORIZONTAL = 10;
30481 CoSEConstants.TREE_REDUCTION_ON_INCREMENTAL = false;
30482 module2.exports = CoSEConstants;
30483 },
30484 /* 2 */
30485 /***/
30486 function(module2, exports2, __webpack_require__) {
30487 var FDLayoutEdge = __webpack_require__(0).FDLayoutEdge;
30488 function CoSEEdge(source, target, vEdge) {
30489 FDLayoutEdge.call(this, source, target, vEdge);
30490 }
30491 CoSEEdge.prototype = Object.create(FDLayoutEdge.prototype);
30492 for (var prop in FDLayoutEdge) {
30493 CoSEEdge[prop] = FDLayoutEdge[prop];
30494 }
30495 module2.exports = CoSEEdge;
30496 },
30497 /* 3 */
30498 /***/
30499 function(module2, exports2, __webpack_require__) {
30500 var LGraph = __webpack_require__(0).LGraph;
30501 function CoSEGraph(parent, graphMgr, vGraph) {
30502 LGraph.call(this, parent, graphMgr, vGraph);
30503 }
30504 CoSEGraph.prototype = Object.create(LGraph.prototype);
30505 for (var prop in LGraph) {
30506 CoSEGraph[prop] = LGraph[prop];
30507 }
30508 module2.exports = CoSEGraph;
30509 },
30510 /* 4 */
30511 /***/
30512 function(module2, exports2, __webpack_require__) {
30513 var LGraphManager = __webpack_require__(0).LGraphManager;
30514 function CoSEGraphManager(layout) {
30515 LGraphManager.call(this, layout);
30516 }
30517 CoSEGraphManager.prototype = Object.create(LGraphManager.prototype);
30518 for (var prop in LGraphManager) {
30519 CoSEGraphManager[prop] = LGraphManager[prop];
30520 }
30521 module2.exports = CoSEGraphManager;
30522 },
30523 /* 5 */
30524 /***/
30525 function(module2, exports2, __webpack_require__) {
30526 var FDLayoutNode = __webpack_require__(0).FDLayoutNode;
30527 var IMath = __webpack_require__(0).IMath;
30528 function CoSENode(gm, loc, size, vNode) {
30529 FDLayoutNode.call(this, gm, loc, size, vNode);
30530 }
30531 CoSENode.prototype = Object.create(FDLayoutNode.prototype);
30532 for (var prop in FDLayoutNode) {
30533 CoSENode[prop] = FDLayoutNode[prop];
30534 }
30535 CoSENode.prototype.move = function() {
30536 var layout = this.graphManager.getLayout();
30537 this.displacementX = layout.coolingFactor * (this.springForceX + this.repulsionForceX + this.gravitationForceX) / this.noOfChildren;
30538 this.displacementY = layout.coolingFactor * (this.springForceY + this.repulsionForceY + this.gravitationForceY) / this.noOfChildren;
30539 if (Math.abs(this.displacementX) > layout.coolingFactor * layout.maxNodeDisplacement) {
30540 this.displacementX = layout.coolingFactor * layout.maxNodeDisplacement * IMath.sign(this.displacementX);
30541 }
30542 if (Math.abs(this.displacementY) > layout.coolingFactor * layout.maxNodeDisplacement) {
30543 this.displacementY = layout.coolingFactor * layout.maxNodeDisplacement * IMath.sign(this.displacementY);
30544 }
30545 if (this.child == null) {
30546 this.moveBy(this.displacementX, this.displacementY);
30547 } else if (this.child.getNodes().length == 0) {
30548 this.moveBy(this.displacementX, this.displacementY);
30549 } else {
30550 this.propogateDisplacementToChildren(this.displacementX, this.displacementY);
30551 }
30552 layout.totalDisplacement += Math.abs(this.displacementX) + Math.abs(this.displacementY);
30553 this.springForceX = 0;
30554 this.springForceY = 0;
30555 this.repulsionForceX = 0;
30556 this.repulsionForceY = 0;
30557 this.gravitationForceX = 0;
30558 this.gravitationForceY = 0;
30559 this.displacementX = 0;
30560 this.displacementY = 0;
30561 };
30562 CoSENode.prototype.propogateDisplacementToChildren = function(dX, dY) {
30563 var nodes2 = this.getChild().getNodes();
30564 var node;
30565 for (var i = 0; i < nodes2.length; i++) {
30566 node = nodes2[i];
30567 if (node.getChild() == null) {
30568 node.moveBy(dX, dY);
30569 node.displacementX += dX;
30570 node.displacementY += dY;
30571 } else {
30572 node.propogateDisplacementToChildren(dX, dY);
30573 }
30574 }
30575 };
30576 CoSENode.prototype.setPred1 = function(pred12) {
30577 this.pred1 = pred12;
30578 };
30579 CoSENode.prototype.getPred1 = function() {
30580 return pred1;
30581 };
30582 CoSENode.prototype.getPred2 = function() {
30583 return pred2;
30584 };
30585 CoSENode.prototype.setNext = function(next2) {
30586 this.next = next2;
30587 };
30588 CoSENode.prototype.getNext = function() {
30589 return next;
30590 };
30591 CoSENode.prototype.setProcessed = function(processed2) {
30592 this.processed = processed2;
30593 };
30594 CoSENode.prototype.isProcessed = function() {
30595 return processed;
30596 };
30597 module2.exports = CoSENode;
30598 },
30599 /* 6 */
30600 /***/
30601 function(module2, exports2, __webpack_require__) {
30602 var FDLayout = __webpack_require__(0).FDLayout;
30603 var CoSEGraphManager = __webpack_require__(4);
30604 var CoSEGraph = __webpack_require__(3);
30605 var CoSENode = __webpack_require__(5);
30606 var CoSEEdge = __webpack_require__(2);
30607 var CoSEConstants = __webpack_require__(1);
30608 var FDLayoutConstants = __webpack_require__(0).FDLayoutConstants;
30609 var LayoutConstants = __webpack_require__(0).LayoutConstants;
30610 var Point2 = __webpack_require__(0).Point;
30611 var PointD = __webpack_require__(0).PointD;
30612 var Layout2 = __webpack_require__(0).Layout;
30613 var Integer = __webpack_require__(0).Integer;
30614 var IGeometry = __webpack_require__(0).IGeometry;
30615 var LGraph = __webpack_require__(0).LGraph;
30616 var Transform = __webpack_require__(0).Transform;
30617 function CoSELayout() {
30618 FDLayout.call(this);
30619 this.toBeTiled = {};
30620 }
30621 CoSELayout.prototype = Object.create(FDLayout.prototype);
30622 for (var prop in FDLayout) {
30623 CoSELayout[prop] = FDLayout[prop];
30624 }
30625 CoSELayout.prototype.newGraphManager = function() {
30626 var gm = new CoSEGraphManager(this);
30627 this.graphManager = gm;
30628 return gm;
30629 };
30630 CoSELayout.prototype.newGraph = function(vGraph) {
30631 return new CoSEGraph(null, this.graphManager, vGraph);
30632 };
30633 CoSELayout.prototype.newNode = function(vNode) {
30634 return new CoSENode(this.graphManager, vNode);
30635 };
30636 CoSELayout.prototype.newEdge = function(vEdge) {
30637 return new CoSEEdge(null, null, vEdge);
30638 };
30639 CoSELayout.prototype.initParameters = function() {
30640 FDLayout.prototype.initParameters.call(this, arguments);
30641 if (!this.isSubLayout) {
30642 if (CoSEConstants.DEFAULT_EDGE_LENGTH < 10) {
30643 this.idealEdgeLength = 10;
30644 } else {
30645 this.idealEdgeLength = CoSEConstants.DEFAULT_EDGE_LENGTH;
30646 }
30647 this.useSmartIdealEdgeLengthCalculation = CoSEConstants.DEFAULT_USE_SMART_IDEAL_EDGE_LENGTH_CALCULATION;
30648 this.springConstant = FDLayoutConstants.DEFAULT_SPRING_STRENGTH;
30649 this.repulsionConstant = FDLayoutConstants.DEFAULT_REPULSION_STRENGTH;
30650 this.gravityConstant = FDLayoutConstants.DEFAULT_GRAVITY_STRENGTH;
30651 this.compoundGravityConstant = FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_STRENGTH;
30652 this.gravityRangeFactor = FDLayoutConstants.DEFAULT_GRAVITY_RANGE_FACTOR;
30653 this.compoundGravityRangeFactor = FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR;
30654 this.prunedNodesAll = [];
30655 this.growTreeIterations = 0;
30656 this.afterGrowthIterations = 0;
30657 this.isTreeGrowing = false;
30658 this.isGrowthFinished = false;
30659 this.coolingCycle = 0;
30660 this.maxCoolingCycle = this.maxIterations / FDLayoutConstants.CONVERGENCE_CHECK_PERIOD;
30661 this.finalTemperature = FDLayoutConstants.CONVERGENCE_CHECK_PERIOD / this.maxIterations;
30662 this.coolingAdjuster = 1;
30663 }
30664 };
30665 CoSELayout.prototype.layout = function() {
30666 var createBendsAsNeeded = LayoutConstants.DEFAULT_CREATE_BENDS_AS_NEEDED;
30667 if (createBendsAsNeeded) {
30668 this.createBendpoints();
30669 this.graphManager.resetAllEdges();
30670 }
30671 this.level = 0;
30672 return this.classicLayout();
30673 };
30674 CoSELayout.prototype.classicLayout = function() {
30675 this.nodesWithGravity = this.calculateNodesToApplyGravitationTo();
30676 this.graphManager.setAllNodesToApplyGravitation(this.nodesWithGravity);
30677 this.calcNoOfChildrenForAllNodes();
30678 this.graphManager.calcLowestCommonAncestors();
30679 this.graphManager.calcInclusionTreeDepths();
30680 this.graphManager.getRoot().calcEstimatedSize();
30681 this.calcIdealEdgeLengths();
30682 if (!this.incremental) {
30683 var forest = this.getFlatForest();
30684 if (forest.length > 0) {
30685 this.positionNodesRadially(forest);
30686 } else {
30687 this.reduceTrees();
30688 this.graphManager.resetAllNodesToApplyGravitation();
30689 var allNodes = new Set(this.getAllNodes());
30690 var intersection = this.nodesWithGravity.filter(function(x) {
30691 return allNodes.has(x);
30692 });
30693 this.graphManager.setAllNodesToApplyGravitation(intersection);
30694 this.positionNodesRandomly();
30695 }
30696 } else {
30697 if (CoSEConstants.TREE_REDUCTION_ON_INCREMENTAL) {
30698 this.reduceTrees();
30699 this.graphManager.resetAllNodesToApplyGravitation();
30700 var allNodes = new Set(this.getAllNodes());
30701 var intersection = this.nodesWithGravity.filter(function(x) {
30702 return allNodes.has(x);
30703 });
30704 this.graphManager.setAllNodesToApplyGravitation(intersection);
30705 }
30706 }
30707 this.initSpringEmbedder();
30708 this.runSpringEmbedder();
30709 return true;
30710 };
30711 CoSELayout.prototype.tick = function() {
30712 this.totalIterations++;
30713 if (this.totalIterations === this.maxIterations && !this.isTreeGrowing && !this.isGrowthFinished) {
30714 if (this.prunedNodesAll.length > 0) {
30715 this.isTreeGrowing = true;
30716 } else {
30717 return true;
30718 }
30719 }
30720 if (this.totalIterations % FDLayoutConstants.CONVERGENCE_CHECK_PERIOD == 0 && !this.isTreeGrowing && !this.isGrowthFinished) {
30721 if (this.isConverged()) {
30722 if (this.prunedNodesAll.length > 0) {
30723 this.isTreeGrowing = true;
30724 } else {
30725 return true;
30726 }
30727 }
30728 this.coolingCycle++;
30729 if (this.layoutQuality == 0) {
30730 this.coolingAdjuster = this.coolingCycle;
30731 } else if (this.layoutQuality == 1) {
30732 this.coolingAdjuster = this.coolingCycle / 3;
30733 }
30734 this.coolingFactor = Math.max(this.initialCoolingFactor - Math.pow(this.coolingCycle, Math.log(100 * (this.initialCoolingFactor - this.finalTemperature)) / Math.log(this.maxCoolingCycle)) / 100 * this.coolingAdjuster, this.finalTemperature);
30735 this.animationPeriod = Math.ceil(this.initialAnimationPeriod * Math.sqrt(this.coolingFactor));
30736 }
30737 if (this.isTreeGrowing) {
30738 if (this.growTreeIterations % 10 == 0) {
30739 if (this.prunedNodesAll.length > 0) {
30740 this.graphManager.updateBounds();
30741 this.updateGrid();
30742 this.growTree(this.prunedNodesAll);
30743 this.graphManager.resetAllNodesToApplyGravitation();
30744 var allNodes = new Set(this.getAllNodes());
30745 var intersection = this.nodesWithGravity.filter(function(x) {
30746 return allNodes.has(x);
30747 });
30748 this.graphManager.setAllNodesToApplyGravitation(intersection);
30749 this.graphManager.updateBounds();
30750 this.updateGrid();
30751 this.coolingFactor = FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL;
30752 } else {
30753 this.isTreeGrowing = false;
30754 this.isGrowthFinished = true;
30755 }
30756 }
30757 this.growTreeIterations++;
30758 }
30759 if (this.isGrowthFinished) {
30760 if (this.isConverged()) {
30761 return true;
30762 }
30763 if (this.afterGrowthIterations % 10 == 0) {
30764 this.graphManager.updateBounds();
30765 this.updateGrid();
30766 }
30767 this.coolingFactor = FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL * ((100 - this.afterGrowthIterations) / 100);
30768 this.afterGrowthIterations++;
30769 }
30770 var gridUpdateAllowed = !this.isTreeGrowing && !this.isGrowthFinished;
30771 var forceToNodeSurroundingUpdate = this.growTreeIterations % 10 == 1 && this.isTreeGrowing || this.afterGrowthIterations % 10 == 1 && this.isGrowthFinished;
30772 this.totalDisplacement = 0;
30773 this.graphManager.updateBounds();
30774 this.calcSpringForces();
30775 this.calcRepulsionForces(gridUpdateAllowed, forceToNodeSurroundingUpdate);
30776 this.calcGravitationalForces();
30777 this.moveNodes();
30778 this.animate();
30779 return false;
30780 };
30781 CoSELayout.prototype.getPositionsData = function() {
30782 var allNodes = this.graphManager.getAllNodes();
30783 var pData = {};
30784 for (var i = 0; i < allNodes.length; i++) {
30785 var rect = allNodes[i].rect;
30786 var id = allNodes[i].id;
30787 pData[id] = {
30788 id,
30789 x: rect.getCenterX(),
30790 y: rect.getCenterY(),
30791 w: rect.width,
30792 h: rect.height
30793 };
30794 }
30795 return pData;
30796 };
30797 CoSELayout.prototype.runSpringEmbedder = function() {
30798 this.initialAnimationPeriod = 25;
30799 this.animationPeriod = this.initialAnimationPeriod;
30800 var layoutEnded = false;
30801 if (FDLayoutConstants.ANIMATE === "during") {
30802 this.emit("layoutstarted");
30803 } else {
30804 while (!layoutEnded) {
30805 layoutEnded = this.tick();
30806 }
30807 this.graphManager.updateBounds();
30808 }
30809 };
30810 CoSELayout.prototype.calculateNodesToApplyGravitationTo = function() {
30811 var nodeList = [];
30812 var graph;
30813 var graphs = this.graphManager.getGraphs();
30814 var size = graphs.length;
30815 var i;
30816 for (i = 0; i < size; i++) {
30817 graph = graphs[i];
30818 graph.updateConnected();
30819 if (!graph.isConnected) {
30820 nodeList = nodeList.concat(graph.getNodes());
30821 }
30822 }
30823 return nodeList;
30824 };
30825 CoSELayout.prototype.createBendpoints = function() {
30826 var edges = [];
30827 edges = edges.concat(this.graphManager.getAllEdges());
30828 var visited = /* @__PURE__ */ new Set();
30829 var i;
30830 for (i = 0; i < edges.length; i++) {
30831 var edge = edges[i];
30832 if (!visited.has(edge)) {
30833 var source = edge.getSource();
30834 var target = edge.getTarget();
30835 if (source == target) {
30836 edge.getBendpoints().push(new PointD());
30837 edge.getBendpoints().push(new PointD());
30838 this.createDummyNodesForBendpoints(edge);
30839 visited.add(edge);
30840 } else {
30841 var edgeList = [];
30842 edgeList = edgeList.concat(source.getEdgeListToNode(target));
30843 edgeList = edgeList.concat(target.getEdgeListToNode(source));
30844 if (!visited.has(edgeList[0])) {
30845 if (edgeList.length > 1) {
30846 var k;
30847 for (k = 0; k < edgeList.length; k++) {
30848 var multiEdge = edgeList[k];
30849 multiEdge.getBendpoints().push(new PointD());
30850 this.createDummyNodesForBendpoints(multiEdge);
30851 }
30852 }
30853 edgeList.forEach(function(edge2) {
30854 visited.add(edge2);
30855 });
30856 }
30857 }
30858 }
30859 if (visited.size == edges.length) {
30860 break;
30861 }
30862 }
30863 };
30864 CoSELayout.prototype.positionNodesRadially = function(forest) {
30865 var currentStartingPoint = new Point2(0, 0);
30866 var numberOfColumns = Math.ceil(Math.sqrt(forest.length));
30867 var height = 0;
30868 var currentY = 0;
30869 var currentX = 0;
30870 var point = new PointD(0, 0);
30871 for (var i = 0; i < forest.length; i++) {
30872 if (i % numberOfColumns == 0) {
30873 currentX = 0;
30874 currentY = height;
30875 if (i != 0) {
30876 currentY += CoSEConstants.DEFAULT_COMPONENT_SEPERATION;
30877 }
30878 height = 0;
30879 }
30880 var tree = forest[i];
30881 var centerNode = Layout2.findCenterOfTree(tree);
30882 currentStartingPoint.x = currentX;
30883 currentStartingPoint.y = currentY;
30884 point = CoSELayout.radialLayout(tree, centerNode, currentStartingPoint);
30885 if (point.y > height) {
30886 height = Math.floor(point.y);
30887 }
30888 currentX = Math.floor(point.x + CoSEConstants.DEFAULT_COMPONENT_SEPERATION);
30889 }
30890 this.transform(new PointD(LayoutConstants.WORLD_CENTER_X - point.x / 2, LayoutConstants.WORLD_CENTER_Y - point.y / 2));
30891 };
30892 CoSELayout.radialLayout = function(tree, centerNode, startingPoint) {
30893 var radialSep = Math.max(this.maxDiagonalInTree(tree), CoSEConstants.DEFAULT_RADIAL_SEPARATION);
30894 CoSELayout.branchRadialLayout(centerNode, null, 0, 359, 0, radialSep);
30895 var bounds = LGraph.calculateBounds(tree);
30896 var transform = new Transform();
30897 transform.setDeviceOrgX(bounds.getMinX());
30898 transform.setDeviceOrgY(bounds.getMinY());
30899 transform.setWorldOrgX(startingPoint.x);
30900 transform.setWorldOrgY(startingPoint.y);
30901 for (var i = 0; i < tree.length; i++) {
30902 var node = tree[i];
30903 node.transform(transform);
30904 }
30905 var bottomRight = new PointD(bounds.getMaxX(), bounds.getMaxY());
30906 return transform.inverseTransformPoint(bottomRight);
30907 };
30908 CoSELayout.branchRadialLayout = function(node, parentOfNode, startAngle, endAngle, distance, radialSeparation) {
30909 var halfInterval = (endAngle - startAngle + 1) / 2;
30910 if (halfInterval < 0) {
30911 halfInterval += 180;
30912 }
30913 var nodeAngle = (halfInterval + startAngle) % 360;
30914 var teta = nodeAngle * IGeometry.TWO_PI / 360;
30915 var x_ = distance * Math.cos(teta);
30916 var y_ = distance * Math.sin(teta);
30917 node.setCenter(x_, y_);
30918 var neighborEdges = [];
30919 neighborEdges = neighborEdges.concat(node.getEdges());
30920 var childCount = neighborEdges.length;
30921 if (parentOfNode != null) {
30922 childCount--;
30923 }
30924 var branchCount = 0;
30925 var incEdgesCount = neighborEdges.length;
30926 var startIndex;
30927 var edges = node.getEdgesBetween(parentOfNode);
30928 while (edges.length > 1) {
30929 var temp = edges[0];
30930 edges.splice(0, 1);
30931 var index = neighborEdges.indexOf(temp);
30932 if (index >= 0) {
30933 neighborEdges.splice(index, 1);
30934 }
30935 incEdgesCount--;
30936 childCount--;
30937 }
30938 if (parentOfNode != null) {
30939 startIndex = (neighborEdges.indexOf(edges[0]) + 1) % incEdgesCount;
30940 } else {
30941 startIndex = 0;
30942 }
30943 var stepAngle = Math.abs(endAngle - startAngle) / childCount;
30944 for (var i = startIndex; branchCount != childCount; i = ++i % incEdgesCount) {
30945 var currentNeighbor = neighborEdges[i].getOtherEnd(node);
30946 if (currentNeighbor == parentOfNode) {
30947 continue;
30948 }
30949 var childStartAngle = (startAngle + branchCount * stepAngle) % 360;
30950 var childEndAngle = (childStartAngle + stepAngle) % 360;
30951 CoSELayout.branchRadialLayout(currentNeighbor, node, childStartAngle, childEndAngle, distance + radialSeparation, radialSeparation);
30952 branchCount++;
30953 }
30954 };
30955 CoSELayout.maxDiagonalInTree = function(tree) {
30956 var maxDiagonal = Integer.MIN_VALUE;
30957 for (var i = 0; i < tree.length; i++) {
30958 var node = tree[i];
30959 var diagonal = node.getDiagonal();
30960 if (diagonal > maxDiagonal) {
30961 maxDiagonal = diagonal;
30962 }
30963 }
30964 return maxDiagonal;
30965 };
30966 CoSELayout.prototype.calcRepulsionRange = function() {
30967 return 2 * (this.level + 1) * this.idealEdgeLength;
30968 };
30969 CoSELayout.prototype.groupZeroDegreeMembers = function() {
30970 var self2 = this;
30971 var tempMemberGroups = {};
30972 this.memberGroups = {};
30973 this.idToDummyNode = {};
30974 var zeroDegree = [];
30975 var allNodes = this.graphManager.getAllNodes();
30976 for (var i = 0; i < allNodes.length; i++) {
30977 var node = allNodes[i];
30978 var parent = node.getParent();
30979 if (this.getNodeDegreeWithChildren(node) === 0 && (parent.id == void 0 || !this.getToBeTiled(parent))) {
30980 zeroDegree.push(node);
30981 }
30982 }
30983 for (var i = 0; i < zeroDegree.length; i++) {
30984 var node = zeroDegree[i];
30985 var p_id = node.getParent().id;
30986 if (typeof tempMemberGroups[p_id] === "undefined")
30987 tempMemberGroups[p_id] = [];
30988 tempMemberGroups[p_id] = tempMemberGroups[p_id].concat(node);
30989 }
30990 Object.keys(tempMemberGroups).forEach(function(p_id2) {
30991 if (tempMemberGroups[p_id2].length > 1) {
30992 var dummyCompoundId = "DummyCompound_" + p_id2;
30993 self2.memberGroups[dummyCompoundId] = tempMemberGroups[p_id2];
30994 var parent2 = tempMemberGroups[p_id2][0].getParent();
30995 var dummyCompound = new CoSENode(self2.graphManager);
30996 dummyCompound.id = dummyCompoundId;
30997 dummyCompound.paddingLeft = parent2.paddingLeft || 0;
30998 dummyCompound.paddingRight = parent2.paddingRight || 0;
30999 dummyCompound.paddingBottom = parent2.paddingBottom || 0;
31000 dummyCompound.paddingTop = parent2.paddingTop || 0;
31001 self2.idToDummyNode[dummyCompoundId] = dummyCompound;
31002 var dummyParentGraph = self2.getGraphManager().add(self2.newGraph(), dummyCompound);
31003 var parentGraph = parent2.getChild();
31004 parentGraph.add(dummyCompound);
31005 for (var i2 = 0; i2 < tempMemberGroups[p_id2].length; i2++) {
31006 var node2 = tempMemberGroups[p_id2][i2];
31007 parentGraph.remove(node2);
31008 dummyParentGraph.add(node2);
31009 }
31010 }
31011 });
31012 };
31013 CoSELayout.prototype.clearCompounds = function() {
31014 var childGraphMap = {};
31015 var idToNode = {};
31016 this.performDFSOnCompounds();
31017 for (var i = 0; i < this.compoundOrder.length; i++) {
31018 idToNode[this.compoundOrder[i].id] = this.compoundOrder[i];
31019 childGraphMap[this.compoundOrder[i].id] = [].concat(this.compoundOrder[i].getChild().getNodes());
31020 this.graphManager.remove(this.compoundOrder[i].getChild());
31021 this.compoundOrder[i].child = null;
31022 }
31023 this.graphManager.resetAllNodes();
31024 this.tileCompoundMembers(childGraphMap, idToNode);
31025 };
31026 CoSELayout.prototype.clearZeroDegreeMembers = function() {
31027 var self2 = this;
31028 var tiledZeroDegreePack = this.tiledZeroDegreePack = [];
31029 Object.keys(this.memberGroups).forEach(function(id) {
31030 var compoundNode = self2.idToDummyNode[id];
31031 tiledZeroDegreePack[id] = self2.tileNodes(self2.memberGroups[id], compoundNode.paddingLeft + compoundNode.paddingRight);
31032 compoundNode.rect.width = tiledZeroDegreePack[id].width;
31033 compoundNode.rect.height = tiledZeroDegreePack[id].height;
31034 });
31035 };
31036 CoSELayout.prototype.repopulateCompounds = function() {
31037 for (var i = this.compoundOrder.length - 1; i >= 0; i--) {
31038 var lCompoundNode = this.compoundOrder[i];
31039 var id = lCompoundNode.id;
31040 var horizontalMargin = lCompoundNode.paddingLeft;
31041 var verticalMargin = lCompoundNode.paddingTop;
31042 this.adjustLocations(this.tiledMemberPack[id], lCompoundNode.rect.x, lCompoundNode.rect.y, horizontalMargin, verticalMargin);
31043 }
31044 };
31045 CoSELayout.prototype.repopulateZeroDegreeMembers = function() {
31046 var self2 = this;
31047 var tiledPack = this.tiledZeroDegreePack;
31048 Object.keys(tiledPack).forEach(function(id) {
31049 var compoundNode = self2.idToDummyNode[id];
31050 var horizontalMargin = compoundNode.paddingLeft;
31051 var verticalMargin = compoundNode.paddingTop;
31052 self2.adjustLocations(tiledPack[id], compoundNode.rect.x, compoundNode.rect.y, horizontalMargin, verticalMargin);
31053 });
31054 };
31055 CoSELayout.prototype.getToBeTiled = function(node) {
31056 var id = node.id;
31057 if (this.toBeTiled[id] != null) {
31058 return this.toBeTiled[id];
31059 }
31060 var childGraph = node.getChild();
31061 if (childGraph == null) {
31062 this.toBeTiled[id] = false;
31063 return false;
31064 }
31065 var children = childGraph.getNodes();
31066 for (var i = 0; i < children.length; i++) {
31067 var theChild = children[i];
31068 if (this.getNodeDegree(theChild) > 0) {
31069 this.toBeTiled[id] = false;
31070 return false;
31071 }
31072 if (theChild.getChild() == null) {
31073 this.toBeTiled[theChild.id] = false;
31074 continue;
31075 }
31076 if (!this.getToBeTiled(theChild)) {
31077 this.toBeTiled[id] = false;
31078 return false;
31079 }
31080 }
31081 this.toBeTiled[id] = true;
31082 return true;
31083 };
31084 CoSELayout.prototype.getNodeDegree = function(node) {
31085 node.id;
31086 var edges = node.getEdges();
31087 var degree = 0;
31088 for (var i = 0; i < edges.length; i++) {
31089 var edge = edges[i];
31090 if (edge.getSource().id !== edge.getTarget().id) {
31091 degree = degree + 1;
31092 }
31093 }
31094 return degree;
31095 };
31096 CoSELayout.prototype.getNodeDegreeWithChildren = function(node) {
31097 var degree = this.getNodeDegree(node);
31098 if (node.getChild() == null) {
31099 return degree;
31100 }
31101 var children = node.getChild().getNodes();
31102 for (var i = 0; i < children.length; i++) {
31103 var child = children[i];
31104 degree += this.getNodeDegreeWithChildren(child);
31105 }
31106 return degree;
31107 };
31108 CoSELayout.prototype.performDFSOnCompounds = function() {
31109 this.compoundOrder = [];
31110 this.fillCompexOrderByDFS(this.graphManager.getRoot().getNodes());
31111 };
31112 CoSELayout.prototype.fillCompexOrderByDFS = function(children) {
31113 for (var i = 0; i < children.length; i++) {
31114 var child = children[i];
31115 if (child.getChild() != null) {
31116 this.fillCompexOrderByDFS(child.getChild().getNodes());
31117 }
31118 if (this.getToBeTiled(child)) {
31119 this.compoundOrder.push(child);
31120 }
31121 }
31122 };
31123 CoSELayout.prototype.adjustLocations = function(organization, x, y, compoundHorizontalMargin, compoundVerticalMargin) {
31124 x += compoundHorizontalMargin;
31125 y += compoundVerticalMargin;
31126 var left = x;
31127 for (var i = 0; i < organization.rows.length; i++) {
31128 var row = organization.rows[i];
31129 x = left;
31130 var maxHeight = 0;
31131 for (var j = 0; j < row.length; j++) {
31132 var lnode = row[j];
31133 lnode.rect.x = x;
31134 lnode.rect.y = y;
31135 x += lnode.rect.width + organization.horizontalPadding;
31136 if (lnode.rect.height > maxHeight)
31137 maxHeight = lnode.rect.height;
31138 }
31139 y += maxHeight + organization.verticalPadding;
31140 }
31141 };
31142 CoSELayout.prototype.tileCompoundMembers = function(childGraphMap, idToNode) {
31143 var self2 = this;
31144 this.tiledMemberPack = [];
31145 Object.keys(childGraphMap).forEach(function(id) {
31146 var compoundNode = idToNode[id];
31147 self2.tiledMemberPack[id] = self2.tileNodes(childGraphMap[id], compoundNode.paddingLeft + compoundNode.paddingRight);
31148 compoundNode.rect.width = self2.tiledMemberPack[id].width;
31149 compoundNode.rect.height = self2.tiledMemberPack[id].height;
31150 });
31151 };
31152 CoSELayout.prototype.tileNodes = function(nodes2, minWidth) {
31153 var verticalPadding = CoSEConstants.TILING_PADDING_VERTICAL;
31154 var horizontalPadding = CoSEConstants.TILING_PADDING_HORIZONTAL;
31155 var organization = {
31156 rows: [],
31157 rowWidth: [],
31158 rowHeight: [],
31159 width: 0,
31160 height: minWidth,
31161 // assume minHeight equals to minWidth
31162 verticalPadding,
31163 horizontalPadding
31164 };
31165 nodes2.sort(function(n1, n2) {
31166 if (n1.rect.width * n1.rect.height > n2.rect.width * n2.rect.height)
31167 return -1;
31168 if (n1.rect.width * n1.rect.height < n2.rect.width * n2.rect.height)
31169 return 1;
31170 return 0;
31171 });
31172 for (var i = 0; i < nodes2.length; i++) {
31173 var lNode = nodes2[i];
31174 if (organization.rows.length == 0) {
31175 this.insertNodeToRow(organization, lNode, 0, minWidth);
31176 } else if (this.canAddHorizontal(organization, lNode.rect.width, lNode.rect.height)) {
31177 this.insertNodeToRow(organization, lNode, this.getShortestRowIndex(organization), minWidth);
31178 } else {
31179 this.insertNodeToRow(organization, lNode, organization.rows.length, minWidth);
31180 }
31181 this.shiftToLastRow(organization);
31182 }
31183 return organization;
31184 };
31185 CoSELayout.prototype.insertNodeToRow = function(organization, node, rowIndex, minWidth) {
31186 var minCompoundSize = minWidth;
31187 if (rowIndex == organization.rows.length) {
31188 var secondDimension = [];
31189 organization.rows.push(secondDimension);
31190 organization.rowWidth.push(minCompoundSize);
31191 organization.rowHeight.push(0);
31192 }
31193 var w = organization.rowWidth[rowIndex] + node.rect.width;
31194 if (organization.rows[rowIndex].length > 0) {
31195 w += organization.horizontalPadding;
31196 }
31197 organization.rowWidth[rowIndex] = w;
31198 if (organization.width < w) {
31199 organization.width = w;
31200 }
31201 var h = node.rect.height;
31202 if (rowIndex > 0)
31203 h += organization.verticalPadding;
31204 var extraHeight = 0;
31205 if (h > organization.rowHeight[rowIndex]) {
31206 extraHeight = organization.rowHeight[rowIndex];
31207 organization.rowHeight[rowIndex] = h;
31208 extraHeight = organization.rowHeight[rowIndex] - extraHeight;
31209 }
31210 organization.height += extraHeight;
31211 organization.rows[rowIndex].push(node);
31212 };
31213 CoSELayout.prototype.getShortestRowIndex = function(organization) {
31214 var r = -1;
31215 var min = Number.MAX_VALUE;
31216 for (var i = 0; i < organization.rows.length; i++) {
31217 if (organization.rowWidth[i] < min) {
31218 r = i;
31219 min = organization.rowWidth[i];
31220 }
31221 }
31222 return r;
31223 };
31224 CoSELayout.prototype.getLongestRowIndex = function(organization) {
31225 var r = -1;
31226 var max = Number.MIN_VALUE;
31227 for (var i = 0; i < organization.rows.length; i++) {
31228 if (organization.rowWidth[i] > max) {
31229 r = i;
31230 max = organization.rowWidth[i];
31231 }
31232 }
31233 return r;
31234 };
31235 CoSELayout.prototype.canAddHorizontal = function(organization, extraWidth, extraHeight) {
31236 var sri = this.getShortestRowIndex(organization);
31237 if (sri < 0) {
31238 return true;
31239 }
31240 var min = organization.rowWidth[sri];
31241 if (min + organization.horizontalPadding + extraWidth <= organization.width)
31242 return true;
31243 var hDiff = 0;
31244 if (organization.rowHeight[sri] < extraHeight) {
31245 if (sri > 0)
31246 hDiff = extraHeight + organization.verticalPadding - organization.rowHeight[sri];
31247 }
31248 var add_to_row_ratio;
31249 if (organization.width - min >= extraWidth + organization.horizontalPadding) {
31250 add_to_row_ratio = (organization.height + hDiff) / (min + extraWidth + organization.horizontalPadding);
31251 } else {
31252 add_to_row_ratio = (organization.height + hDiff) / organization.width;
31253 }
31254 hDiff = extraHeight + organization.verticalPadding;
31255 var add_new_row_ratio;
31256 if (organization.width < extraWidth) {
31257 add_new_row_ratio = (organization.height + hDiff) / extraWidth;
31258 } else {
31259 add_new_row_ratio = (organization.height + hDiff) / organization.width;
31260 }
31261 if (add_new_row_ratio < 1)
31262 add_new_row_ratio = 1 / add_new_row_ratio;
31263 if (add_to_row_ratio < 1)
31264 add_to_row_ratio = 1 / add_to_row_ratio;
31265 return add_to_row_ratio < add_new_row_ratio;
31266 };
31267 CoSELayout.prototype.shiftToLastRow = function(organization) {
31268 var longest = this.getLongestRowIndex(organization);
31269 var last = organization.rowWidth.length - 1;
31270 var row = organization.rows[longest];
31271 var node = row[row.length - 1];
31272 var diff = node.width + organization.horizontalPadding;
31273 if (organization.width - organization.rowWidth[last] > diff && longest != last) {
31274 row.splice(-1, 1);
31275 organization.rows[last].push(node);
31276 organization.rowWidth[longest] = organization.rowWidth[longest] - diff;
31277 organization.rowWidth[last] = organization.rowWidth[last] + diff;
31278 organization.width = organization.rowWidth[instance.getLongestRowIndex(organization)];
31279 var maxHeight = Number.MIN_VALUE;
31280 for (var i = 0; i < row.length; i++) {
31281 if (row[i].height > maxHeight)
31282 maxHeight = row[i].height;
31283 }
31284 if (longest > 0)
31285 maxHeight += organization.verticalPadding;
31286 var prevTotal = organization.rowHeight[longest] + organization.rowHeight[last];
31287 organization.rowHeight[longest] = maxHeight;
31288 if (organization.rowHeight[last] < node.height + organization.verticalPadding)
31289 organization.rowHeight[last] = node.height + organization.verticalPadding;
31290 var finalTotal = organization.rowHeight[longest] + organization.rowHeight[last];
31291 organization.height += finalTotal - prevTotal;
31292 this.shiftToLastRow(organization);
31293 }
31294 };
31295 CoSELayout.prototype.tilingPreLayout = function() {
31296 if (CoSEConstants.TILE) {
31297 this.groupZeroDegreeMembers();
31298 this.clearCompounds();
31299 this.clearZeroDegreeMembers();
31300 }
31301 };
31302 CoSELayout.prototype.tilingPostLayout = function() {
31303 if (CoSEConstants.TILE) {
31304 this.repopulateZeroDegreeMembers();
31305 this.repopulateCompounds();
31306 }
31307 };
31308 CoSELayout.prototype.reduceTrees = function() {
31309 var prunedNodesAll = [];
31310 var containsLeaf = true;
31311 var node;
31312 while (containsLeaf) {
31313 var allNodes = this.graphManager.getAllNodes();
31314 var prunedNodesInStepTemp = [];
31315 containsLeaf = false;
31316 for (var i = 0; i < allNodes.length; i++) {
31317 node = allNodes[i];
31318 if (node.getEdges().length == 1 && !node.getEdges()[0].isInterGraph && node.getChild() == null) {
31319 prunedNodesInStepTemp.push([node, node.getEdges()[0], node.getOwner()]);
31320 containsLeaf = true;
31321 }
31322 }
31323 if (containsLeaf == true) {
31324 var prunedNodesInStep = [];
31325 for (var j = 0; j < prunedNodesInStepTemp.length; j++) {
31326 if (prunedNodesInStepTemp[j][0].getEdges().length == 1) {
31327 prunedNodesInStep.push(prunedNodesInStepTemp[j]);
31328 prunedNodesInStepTemp[j][0].getOwner().remove(prunedNodesInStepTemp[j][0]);
31329 }
31330 }
31331 prunedNodesAll.push(prunedNodesInStep);
31332 this.graphManager.resetAllNodes();
31333 this.graphManager.resetAllEdges();
31334 }
31335 }
31336 this.prunedNodesAll = prunedNodesAll;
31337 };
31338 CoSELayout.prototype.growTree = function(prunedNodesAll) {
31339 var lengthOfPrunedNodesInStep = prunedNodesAll.length;
31340 var prunedNodesInStep = prunedNodesAll[lengthOfPrunedNodesInStep - 1];
31341 var nodeData;
31342 for (var i = 0; i < prunedNodesInStep.length; i++) {
31343 nodeData = prunedNodesInStep[i];
31344 this.findPlaceforPrunedNode(nodeData);
31345 nodeData[2].add(nodeData[0]);
31346 nodeData[2].add(nodeData[1], nodeData[1].source, nodeData[1].target);
31347 }
31348 prunedNodesAll.splice(prunedNodesAll.length - 1, 1);
31349 this.graphManager.resetAllNodes();
31350 this.graphManager.resetAllEdges();
31351 };
31352 CoSELayout.prototype.findPlaceforPrunedNode = function(nodeData) {
31353 var gridForPrunedNode;
31354 var nodeToConnect;
31355 var prunedNode = nodeData[0];
31356 if (prunedNode == nodeData[1].source) {
31357 nodeToConnect = nodeData[1].target;
31358 } else {
31359 nodeToConnect = nodeData[1].source;
31360 }
31361 var startGridX = nodeToConnect.startX;
31362 var finishGridX = nodeToConnect.finishX;
31363 var startGridY = nodeToConnect.startY;
31364 var finishGridY = nodeToConnect.finishY;
31365 var upNodeCount = 0;
31366 var downNodeCount = 0;
31367 var rightNodeCount = 0;
31368 var leftNodeCount = 0;
31369 var controlRegions = [upNodeCount, rightNodeCount, downNodeCount, leftNodeCount];
31370 if (startGridY > 0) {
31371 for (var i = startGridX; i <= finishGridX; i++) {
31372 controlRegions[0] += this.grid[i][startGridY - 1].length + this.grid[i][startGridY].length - 1;
31373 }
31374 }
31375 if (finishGridX < this.grid.length - 1) {
31376 for (var i = startGridY; i <= finishGridY; i++) {
31377 controlRegions[1] += this.grid[finishGridX + 1][i].length + this.grid[finishGridX][i].length - 1;
31378 }
31379 }
31380 if (finishGridY < this.grid[0].length - 1) {
31381 for (var i = startGridX; i <= finishGridX; i++) {
31382 controlRegions[2] += this.grid[i][finishGridY + 1].length + this.grid[i][finishGridY].length - 1;
31383 }
31384 }
31385 if (startGridX > 0) {
31386 for (var i = startGridY; i <= finishGridY; i++) {
31387 controlRegions[3] += this.grid[startGridX - 1][i].length + this.grid[startGridX][i].length - 1;
31388 }
31389 }
31390 var min = Integer.MAX_VALUE;
31391 var minCount;
31392 var minIndex;
31393 for (var j = 0; j < controlRegions.length; j++) {
31394 if (controlRegions[j] < min) {
31395 min = controlRegions[j];
31396 minCount = 1;
31397 minIndex = j;
31398 } else if (controlRegions[j] == min) {
31399 minCount++;
31400 }
31401 }
31402 if (minCount == 3 && min == 0) {
31403 if (controlRegions[0] == 0 && controlRegions[1] == 0 && controlRegions[2] == 0) {
31404 gridForPrunedNode = 1;
31405 } else if (controlRegions[0] == 0 && controlRegions[1] == 0 && controlRegions[3] == 0) {
31406 gridForPrunedNode = 0;
31407 } else if (controlRegions[0] == 0 && controlRegions[2] == 0 && controlRegions[3] == 0) {
31408 gridForPrunedNode = 3;
31409 } else if (controlRegions[1] == 0 && controlRegions[2] == 0 && controlRegions[3] == 0) {
31410 gridForPrunedNode = 2;
31411 }
31412 } else if (minCount == 2 && min == 0) {
31413 var random = Math.floor(Math.random() * 2);
31414 if (controlRegions[0] == 0 && controlRegions[1] == 0) {
31415 if (random == 0) {
31416 gridForPrunedNode = 0;
31417 } else {
31418 gridForPrunedNode = 1;
31419 }
31420 } else if (controlRegions[0] == 0 && controlRegions[2] == 0) {
31421 if (random == 0) {
31422 gridForPrunedNode = 0;
31423 } else {
31424 gridForPrunedNode = 2;
31425 }
31426 } else if (controlRegions[0] == 0 && controlRegions[3] == 0) {
31427 if (random == 0) {
31428 gridForPrunedNode = 0;
31429 } else {
31430 gridForPrunedNode = 3;
31431 }
31432 } else if (controlRegions[1] == 0 && controlRegions[2] == 0) {
31433 if (random == 0) {
31434 gridForPrunedNode = 1;
31435 } else {
31436 gridForPrunedNode = 2;
31437 }
31438 } else if (controlRegions[1] == 0 && controlRegions[3] == 0) {
31439 if (random == 0) {
31440 gridForPrunedNode = 1;
31441 } else {
31442 gridForPrunedNode = 3;
31443 }
31444 } else {
31445 if (random == 0) {
31446 gridForPrunedNode = 2;
31447 } else {
31448 gridForPrunedNode = 3;
31449 }
31450 }
31451 } else if (minCount == 4 && min == 0) {
31452 var random = Math.floor(Math.random() * 4);
31453 gridForPrunedNode = random;
31454 } else {
31455 gridForPrunedNode = minIndex;
31456 }
31457 if (gridForPrunedNode == 0) {
31458 prunedNode.setCenter(nodeToConnect.getCenterX(), nodeToConnect.getCenterY() - nodeToConnect.getHeight() / 2 - FDLayoutConstants.DEFAULT_EDGE_LENGTH - prunedNode.getHeight() / 2);
31459 } else if (gridForPrunedNode == 1) {
31460 prunedNode.setCenter(nodeToConnect.getCenterX() + nodeToConnect.getWidth() / 2 + FDLayoutConstants.DEFAULT_EDGE_LENGTH + prunedNode.getWidth() / 2, nodeToConnect.getCenterY());
31461 } else if (gridForPrunedNode == 2) {
31462 prunedNode.setCenter(nodeToConnect.getCenterX(), nodeToConnect.getCenterY() + nodeToConnect.getHeight() / 2 + FDLayoutConstants.DEFAULT_EDGE_LENGTH + prunedNode.getHeight() / 2);
31463 } else {
31464 prunedNode.setCenter(nodeToConnect.getCenterX() - nodeToConnect.getWidth() / 2 - FDLayoutConstants.DEFAULT_EDGE_LENGTH - prunedNode.getWidth() / 2, nodeToConnect.getCenterY());
31465 }
31466 };
31467 module2.exports = CoSELayout;
31468 },
31469 /* 7 */
31470 /***/
31471 function(module2, exports2, __webpack_require__) {
31472 var coseBase2 = {};
31473 coseBase2.layoutBase = __webpack_require__(0);
31474 coseBase2.CoSEConstants = __webpack_require__(1);
31475 coseBase2.CoSEEdge = __webpack_require__(2);
31476 coseBase2.CoSEGraph = __webpack_require__(3);
31477 coseBase2.CoSEGraphManager = __webpack_require__(4);
31478 coseBase2.CoSELayout = __webpack_require__(6);
31479 coseBase2.CoSENode = __webpack_require__(5);
31480 module2.exports = coseBase2;
31481 }
31482 /******/
31483 ])
31484 );
31485 });
31486 })(coseBase);
31487 return coseBaseExports;
31488}
31489(function(module, exports) {
31490 (function webpackUniversalModuleDefinition(root, factory) {
31491 module.exports = factory(requireCoseBase());
31492 })(commonjsGlobal, function(__WEBPACK_EXTERNAL_MODULE_0__) {
31493 return (
31494 /******/
31495 function(modules) {
31496 var installedModules = {};
31497 function __webpack_require__(moduleId) {
31498 if (installedModules[moduleId]) {
31499 return installedModules[moduleId].exports;
31500 }
31501 var module2 = installedModules[moduleId] = {
31502 /******/
31503 i: moduleId,
31504 /******/
31505 l: false,
31506 /******/
31507 exports: {}
31508 /******/
31509 };
31510 modules[moduleId].call(module2.exports, module2, module2.exports, __webpack_require__);
31511 module2.l = true;
31512 return module2.exports;
31513 }
31514 __webpack_require__.m = modules;
31515 __webpack_require__.c = installedModules;
31516 __webpack_require__.i = function(value) {
31517 return value;
31518 };
31519 __webpack_require__.d = function(exports2, name2, getter) {
31520 if (!__webpack_require__.o(exports2, name2)) {
31521 Object.defineProperty(exports2, name2, {
31522 /******/
31523 configurable: false,
31524 /******/
31525 enumerable: true,
31526 /******/
31527 get: getter
31528 /******/
31529 });
31530 }
31531 };
31532 __webpack_require__.n = function(module2) {
31533 var getter = module2 && module2.__esModule ? (
31534 /******/
31535 function getDefault() {
31536 return module2["default"];
31537 }
31538 ) : (
31539 /******/
31540 function getModuleExports() {
31541 return module2;
31542 }
31543 );
31544 __webpack_require__.d(getter, "a", getter);
31545 return getter;
31546 };
31547 __webpack_require__.o = function(object, property) {
31548 return Object.prototype.hasOwnProperty.call(object, property);
31549 };
31550 __webpack_require__.p = "";
31551 return __webpack_require__(__webpack_require__.s = 1);
31552 }([
31553 /* 0 */
31554 /***/
31555 function(module2, exports2) {
31556 module2.exports = __WEBPACK_EXTERNAL_MODULE_0__;
31557 },
31558 /* 1 */
31559 /***/
31560 function(module2, exports2, __webpack_require__) {
31561 var LayoutConstants = __webpack_require__(0).layoutBase.LayoutConstants;
31562 var FDLayoutConstants = __webpack_require__(0).layoutBase.FDLayoutConstants;
31563 var CoSEConstants = __webpack_require__(0).CoSEConstants;
31564 var CoSELayout = __webpack_require__(0).CoSELayout;
31565 var CoSENode = __webpack_require__(0).CoSENode;
31566 var PointD = __webpack_require__(0).layoutBase.PointD;
31567 var DimensionD2 = __webpack_require__(0).layoutBase.DimensionD;
31568 var defaults = {
31569 // Called on `layoutready`
31570 ready: function ready() {
31571 },
31572 // Called on `layoutstop`
31573 stop: function stop() {
31574 },
31575 // 'draft', 'default' or 'proof"
31576 // - 'draft' fast cooling rate
31577 // - 'default' moderate cooling rate
31578 // - "proof" slow cooling rate
31579 quality: "default",
31580 // include labels in node dimensions
31581 nodeDimensionsIncludeLabels: false,
31582 // number of ticks per frame; higher is faster but more jerky
31583 refresh: 30,
31584 // Whether to fit the network view after when done
31585 fit: true,
31586 // Padding on fit
31587 padding: 10,
31588 // Whether to enable incremental mode
31589 randomize: true,
31590 // Node repulsion (non overlapping) multiplier
31591 nodeRepulsion: 4500,
31592 // Ideal edge (non nested) length
31593 idealEdgeLength: 50,
31594 // Divisor to compute edge forces
31595 edgeElasticity: 0.45,
31596 // Nesting factor (multiplier) to compute ideal edge length for nested edges
31597 nestingFactor: 0.1,
31598 // Gravity force (constant)
31599 gravity: 0.25,
31600 // Maximum number of iterations to perform
31601 numIter: 2500,
31602 // For enabling tiling
31603 tile: true,
31604 // Type of layout animation. The option set is {'during', 'end', false}
31605 animate: "end",
31606 // Duration for animate:end
31607 animationDuration: 500,
31608 // Represents the amount of the vertical space to put between the zero degree members during the tiling operation(can also be a function)
31609 tilingPaddingVertical: 10,
31610 // Represents the amount of the horizontal space to put between the zero degree members during the tiling operation(can also be a function)
31611 tilingPaddingHorizontal: 10,
31612 // Gravity range (constant) for compounds
31613 gravityRangeCompound: 1.5,
31614 // Gravity force (constant) for compounds
31615 gravityCompound: 1,
31616 // Gravity range (constant)
31617 gravityRange: 3.8,
31618 // Initial cooling factor for incremental layout
31619 initialEnergyOnIncremental: 0.5
31620 };
31621 function extend(defaults2, options) {
31622 var obj = {};
31623 for (var i in defaults2) {
31624 obj[i] = defaults2[i];
31625 }
31626 for (var i in options) {
31627 obj[i] = options[i];
31628 }
31629 return obj;
31630 }
31631 function _CoSELayout(_options) {
31632 this.options = extend(defaults, _options);
31633 getUserOptions(this.options);
31634 }
31635 var getUserOptions = function getUserOptions2(options) {
31636 if (options.nodeRepulsion != null)
31637 CoSEConstants.DEFAULT_REPULSION_STRENGTH = FDLayoutConstants.DEFAULT_REPULSION_STRENGTH = options.nodeRepulsion;
31638 if (options.idealEdgeLength != null)
31639 CoSEConstants.DEFAULT_EDGE_LENGTH = FDLayoutConstants.DEFAULT_EDGE_LENGTH = options.idealEdgeLength;
31640 if (options.edgeElasticity != null)
31641 CoSEConstants.DEFAULT_SPRING_STRENGTH = FDLayoutConstants.DEFAULT_SPRING_STRENGTH = options.edgeElasticity;
31642 if (options.nestingFactor != null)
31643 CoSEConstants.PER_LEVEL_IDEAL_EDGE_LENGTH_FACTOR = FDLayoutConstants.PER_LEVEL_IDEAL_EDGE_LENGTH_FACTOR = options.nestingFactor;
31644 if (options.gravity != null)
31645 CoSEConstants.DEFAULT_GRAVITY_STRENGTH = FDLayoutConstants.DEFAULT_GRAVITY_STRENGTH = options.gravity;
31646 if (options.numIter != null)
31647 CoSEConstants.MAX_ITERATIONS = FDLayoutConstants.MAX_ITERATIONS = options.numIter;
31648 if (options.gravityRange != null)
31649 CoSEConstants.DEFAULT_GRAVITY_RANGE_FACTOR = FDLayoutConstants.DEFAULT_GRAVITY_RANGE_FACTOR = options.gravityRange;
31650 if (options.gravityCompound != null)
31651 CoSEConstants.DEFAULT_COMPOUND_GRAVITY_STRENGTH = FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_STRENGTH = options.gravityCompound;
31652 if (options.gravityRangeCompound != null)
31653 CoSEConstants.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR = FDLayoutConstants.DEFAULT_COMPOUND_GRAVITY_RANGE_FACTOR = options.gravityRangeCompound;
31654 if (options.initialEnergyOnIncremental != null)
31655 CoSEConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL = FDLayoutConstants.DEFAULT_COOLING_FACTOR_INCREMENTAL = options.initialEnergyOnIncremental;
31656 if (options.quality == "draft")
31657 LayoutConstants.QUALITY = 0;
31658 else if (options.quality == "proof")
31659 LayoutConstants.QUALITY = 2;
31660 else
31661 LayoutConstants.QUALITY = 1;
31662 CoSEConstants.NODE_DIMENSIONS_INCLUDE_LABELS = FDLayoutConstants.NODE_DIMENSIONS_INCLUDE_LABELS = LayoutConstants.NODE_DIMENSIONS_INCLUDE_LABELS = options.nodeDimensionsIncludeLabels;
31663 CoSEConstants.DEFAULT_INCREMENTAL = FDLayoutConstants.DEFAULT_INCREMENTAL = LayoutConstants.DEFAULT_INCREMENTAL = !options.randomize;
31664 CoSEConstants.ANIMATE = FDLayoutConstants.ANIMATE = LayoutConstants.ANIMATE = options.animate;
31665 CoSEConstants.TILE = options.tile;
31666 CoSEConstants.TILING_PADDING_VERTICAL = typeof options.tilingPaddingVertical === "function" ? options.tilingPaddingVertical.call() : options.tilingPaddingVertical;
31667 CoSEConstants.TILING_PADDING_HORIZONTAL = typeof options.tilingPaddingHorizontal === "function" ? options.tilingPaddingHorizontal.call() : options.tilingPaddingHorizontal;
31668 };
31669 _CoSELayout.prototype.run = function() {
31670 var ready;
31671 var frameId;
31672 var options = this.options;
31673 this.idToLNode = {};
31674 var layout = this.layout = new CoSELayout();
31675 var self2 = this;
31676 self2.stopped = false;
31677 this.cy = this.options.cy;
31678 this.cy.trigger({ type: "layoutstart", layout: this });
31679 var gm = layout.newGraphManager();
31680 this.gm = gm;
31681 var nodes2 = this.options.eles.nodes();
31682 var edges = this.options.eles.edges();
31683 this.root = gm.addRoot();
31684 this.processChildrenList(this.root, this.getTopMostNodes(nodes2), layout);
31685 for (var i = 0; i < edges.length; i++) {
31686 var edge = edges[i];
31687 var sourceNode = this.idToLNode[edge.data("source")];
31688 var targetNode = this.idToLNode[edge.data("target")];
31689 if (sourceNode !== targetNode && sourceNode.getEdgesBetween(targetNode).length == 0) {
31690 var e1 = gm.add(layout.newEdge(), sourceNode, targetNode);
31691 e1.id = edge.id();
31692 }
31693 }
31694 var getPositions = function getPositions2(ele, i2) {
31695 if (typeof ele === "number") {
31696 ele = i2;
31697 }
31698 var theId = ele.data("id");
31699 var lNode = self2.idToLNode[theId];
31700 return {
31701 x: lNode.getRect().getCenterX(),
31702 y: lNode.getRect().getCenterY()
31703 };
31704 };
31705 var iterateAnimated = function iterateAnimated2() {
31706 var afterReposition = function afterReposition2() {
31707 if (options.fit) {
31708 options.cy.fit(options.eles, options.padding);
31709 }
31710 if (!ready) {
31711 ready = true;
31712 self2.cy.one("layoutready", options.ready);
31713 self2.cy.trigger({ type: "layoutready", layout: self2 });
31714 }
31715 };
31716 var ticksPerFrame = self2.options.refresh;
31717 var isDone;
31718 for (var i2 = 0; i2 < ticksPerFrame && !isDone; i2++) {
31719 isDone = self2.stopped || self2.layout.tick();
31720 }
31721 if (isDone) {
31722 if (layout.checkLayoutSuccess() && !layout.isSubLayout) {
31723 layout.doPostLayout();
31724 }
31725 if (layout.tilingPostLayout) {
31726 layout.tilingPostLayout();
31727 }
31728 layout.isLayoutFinished = true;
31729 self2.options.eles.nodes().positions(getPositions);
31730 afterReposition();
31731 self2.cy.one("layoutstop", self2.options.stop);
31732 self2.cy.trigger({ type: "layoutstop", layout: self2 });
31733 if (frameId) {
31734 cancelAnimationFrame(frameId);
31735 }
31736 ready = false;
31737 return;
31738 }
31739 var animationData = self2.layout.getPositionsData();
31740 options.eles.nodes().positions(function(ele, i3) {
31741 if (typeof ele === "number") {
31742 ele = i3;
31743 }
31744 if (!ele.isParent()) {
31745 var theId = ele.id();
31746 var pNode = animationData[theId];
31747 var temp = ele;
31748 while (pNode == null) {
31749 pNode = animationData[temp.data("parent")] || animationData["DummyCompound_" + temp.data("parent")];
31750 animationData[theId] = pNode;
31751 temp = temp.parent()[0];
31752 if (temp == void 0) {
31753 break;
31754 }
31755 }
31756 if (pNode != null) {
31757 return {
31758 x: pNode.x,
31759 y: pNode.y
31760 };
31761 } else {
31762 return {
31763 x: ele.position("x"),
31764 y: ele.position("y")
31765 };
31766 }
31767 }
31768 });
31769 afterReposition();
31770 frameId = requestAnimationFrame(iterateAnimated2);
31771 };
31772 layout.addListener("layoutstarted", function() {
31773 if (self2.options.animate === "during") {
31774 frameId = requestAnimationFrame(iterateAnimated);
31775 }
31776 });
31777 layout.runLayout();
31778 if (this.options.animate !== "during") {
31779 self2.options.eles.nodes().not(":parent").layoutPositions(self2, self2.options, getPositions);
31780 ready = false;
31781 }
31782 return this;
31783 };
31784 _CoSELayout.prototype.getTopMostNodes = function(nodes2) {
31785 var nodesMap = {};
31786 for (var i = 0; i < nodes2.length; i++) {
31787 nodesMap[nodes2[i].id()] = true;
31788 }
31789 var roots = nodes2.filter(function(ele, i2) {
31790 if (typeof ele === "number") {
31791 ele = i2;
31792 }
31793 var parent = ele.parent()[0];
31794 while (parent != null) {
31795 if (nodesMap[parent.id()]) {
31796 return false;
31797 }
31798 parent = parent.parent()[0];
31799 }
31800 return true;
31801 });
31802 return roots;
31803 };
31804 _CoSELayout.prototype.processChildrenList = function(parent, children, layout) {
31805 var size = children.length;
31806 for (var i = 0; i < size; i++) {
31807 var theChild = children[i];
31808 var children_of_children = theChild.children();
31809 var theNode;
31810 var dimensions = theChild.layoutDimensions({
31811 nodeDimensionsIncludeLabels: this.options.nodeDimensionsIncludeLabels
31812 });
31813 if (theChild.outerWidth() != null && theChild.outerHeight() != null) {
31814 theNode = parent.add(new CoSENode(layout.graphManager, new PointD(theChild.position("x") - dimensions.w / 2, theChild.position("y") - dimensions.h / 2), new DimensionD2(parseFloat(dimensions.w), parseFloat(dimensions.h))));
31815 } else {
31816 theNode = parent.add(new CoSENode(this.graphManager));
31817 }
31818 theNode.id = theChild.data("id");
31819 theNode.paddingLeft = parseInt(theChild.css("padding"));
31820 theNode.paddingTop = parseInt(theChild.css("padding"));
31821 theNode.paddingRight = parseInt(theChild.css("padding"));
31822 theNode.paddingBottom = parseInt(theChild.css("padding"));
31823 if (this.options.nodeDimensionsIncludeLabels) {
31824 if (theChild.isParent()) {
31825 var labelWidth = theChild.boundingBox({ includeLabels: true, includeNodes: false }).w;
31826 var labelHeight = theChild.boundingBox({ includeLabels: true, includeNodes: false }).h;
31827 var labelPos = theChild.css("text-halign");
31828 theNode.labelWidth = labelWidth;
31829 theNode.labelHeight = labelHeight;
31830 theNode.labelPos = labelPos;
31831 }
31832 }
31833 this.idToLNode[theChild.data("id")] = theNode;
31834 if (isNaN(theNode.rect.x)) {
31835 theNode.rect.x = 0;
31836 }
31837 if (isNaN(theNode.rect.y)) {
31838 theNode.rect.y = 0;
31839 }
31840 if (children_of_children != null && children_of_children.length > 0) {
31841 var theNewGraph;
31842 theNewGraph = layout.getGraphManager().add(layout.newGraph(), theNode);
31843 this.processChildrenList(theNewGraph, children_of_children, layout);
31844 }
31845 }
31846 };
31847 _CoSELayout.prototype.stop = function() {
31848 this.stopped = true;
31849 return this;
31850 };
31851 var register = function register2(cytoscape2) {
31852 cytoscape2("layout", "cose-bilkent", _CoSELayout);
31853 };
31854 if (typeof cytoscape !== "undefined") {
31855 register(cytoscape);
31856 }
31857 module2.exports = register;
31858 }
31859 /******/
31860 ])
31861 );
31862 });
31863})(cytoscapeCoseBilkent);
31864const coseBilkent = /* @__PURE__ */ getDefaultExportFromCjs(cytoscapeCoseBilkentExports);
31865cytoscape$1.use(coseBilkent);
31866function drawNodes(svg, mindmap, section, conf) {
31867 svgDraw.drawNode(svg, mindmap, section, conf);
31868 if (mindmap.children) {
31869 mindmap.children.forEach((child, index) => {
31870 drawNodes(svg, child, section < 0 ? index : section, conf);
31871 });
31872 }
31873}
31874function drawEdges(edgesEl, cy) {
31875 cy.edges().map((edge, id) => {
31876 const data = edge.data();
31877 if (edge[0]._private.bodyBounds) {
31878 const bounds = edge[0]._private.rscratch;
31879 log.trace("Edge: ", id, data);
31880 edgesEl.insert("path").attr(
31881 "d",
31882 `M ${bounds.startX},${bounds.startY} L ${bounds.midX},${bounds.midY} L${bounds.endX},${bounds.endY} `
31883 ).attr("class", "edge section-edge-" + data.section + " edge-depth-" + data.depth);
31884 }
31885 });
31886}
31887function addNodes(mindmap, cy, conf, level) {
31888 cy.add({
31889 group: "nodes",
31890 data: {
31891 id: mindmap.id,
31892 labelText: mindmap.descr,
31893 height: mindmap.height,
31894 width: mindmap.width,
31895 level,
31896 nodeId: mindmap.id,
31897 padding: mindmap.padding,
31898 type: mindmap.type
31899 },
31900 position: {
31901 x: mindmap.x,
31902 y: mindmap.y
31903 }
31904 });
31905 if (mindmap.children) {
31906 mindmap.children.forEach((child) => {
31907 addNodes(child, cy, conf, level + 1);
31908 cy.add({
31909 group: "edges",
31910 data: {
31911 id: `${mindmap.id}_${child.id}`,
31912 source: mindmap.id,
31913 target: child.id,
31914 depth: level,
31915 section: child.section
31916 }
31917 });
31918 });
31919 }
31920}
31921function layoutMindmap(node, conf) {
31922 return new Promise((resolve) => {
31923 const renderEl = select("body").append("div").attr("id", "cy").attr("style", "display:none");
31924 const cy = cytoscape$1({
31925 container: document.getElementById("cy"),
31926 // container to render in
31927 style: [
31928 {
31929 selector: "edge",
31930 style: {
31931 "curve-style": "bezier"
31932 }
31933 }
31934 ]
31935 });
31936 renderEl.remove();
31937 addNodes(node, cy, conf, 0);
31938 cy.nodes().forEach(function(n) {
31939 n.layoutDimensions = () => {
31940 const data = n.data();
31941 return { w: data.width, h: data.height };
31942 };
31943 });
31944 cy.layout({
31945 name: "cose-bilkent",
31946 quality: "proof",
31947 // headless: true,
31948 styleEnabled: false,
31949 animate: false
31950 }).run();
31951 cy.ready((e) => {
31952 log.info("Ready", e);
31953 resolve(cy);
31954 });
31955 });
31956}
31957function positionNodes(cy) {
31958 cy.nodes().map((node, id) => {
31959 const data = node.data();
31960 data.x = node.position().x;
31961 data.y = node.position().y;
31962 svgDraw.positionNode(data);
31963 const el = getElementById(data.nodeId);
31964 log.info("Id:", id, "Position: (", node.position().x, ", ", node.position().y, ")", data);
31965 el.attr(
31966 "transform",
31967 `translate(${node.position().x - data.width / 2}, ${node.position().y - data.height / 2})`
31968 );
31969 el.attr("attr", `apa-${id})`);
31970 });
31971}
31972const draw = async (text, id, version, diagObj) => {
31973 const conf = getConfig();
31974 conf.htmlLabels = false;
31975 diagObj.db.clear();
31976 diagObj.parser.parse(text);
31977 log.debug("Rendering mindmap diagram\n" + text, diagObj.parser);
31978 const securityLevel = getConfig().securityLevel;
31979 let sandboxElement;
31980 if (securityLevel === "sandbox") {
31981 sandboxElement = select("#i" + id);
31982 }
31983 const root = securityLevel === "sandbox" ? select(sandboxElement.nodes()[0].contentDocument.body) : select("body");
31984 const svg = root.select("#" + id);
31985 svg.append("g");
31986 const mm = diagObj.db.getMindmap();
31987 const edgesElem = svg.append("g");
31988 edgesElem.attr("class", "mindmap-edges");
31989 const nodesElem = svg.append("g");
31990 nodesElem.attr("class", "mindmap-nodes");
31991 drawNodes(nodesElem, mm, -1, conf);
31992 const cy = await layoutMindmap(mm, conf);
31993 drawEdges(edgesElem, cy);
31994 positionNodes(cy);
31995 setupGraphViewbox(void 0, svg, conf.mindmap.padding, conf.mindmap.useMaxWidth);
31996};
31997const mindmapRenderer = {
31998 draw
31999};
32000const genSections = (options) => {
32001 let sections = "";
32002 for (let i = 0; i < options.THEME_COLOR_LIMIT; i++) {
32003 options["lineColor" + i] = options["lineColor" + i] || options["cScaleInv" + i];
32004 if (isDark(options["lineColor" + i])) {
32005 options["lineColor" + i] = lighten(options["lineColor" + i], 20);
32006 } else {
32007 options["lineColor" + i] = darken(options["lineColor" + i], 20);
32008 }
32009 }
32010 for (let i = 0; i < options.THEME_COLOR_LIMIT; i++) {
32011 const sw = "" + (17 - 3 * i);
32012 sections += `
32013 .section-${i - 1} rect, .section-${i - 1} path, .section-${i - 1} circle, .section-${i - 1} polygon, .section-${i - 1} path {
32014 fill: ${options["cScale" + i]};
32015 }
32016 .section-${i - 1} text {
32017 fill: ${options["cScaleLabel" + i]};
32018 }
32019 .node-icon-${i - 1} {
32020 font-size: 40px;
32021 color: ${options["cScaleLabel" + i]};
32022 }
32023 .section-edge-${i - 1}{
32024 stroke: ${options["cScale" + i]};
32025 }
32026 .edge-depth-${i - 1}{
32027 stroke-width: ${sw};
32028 }
32029 .section-${i - 1} line {
32030 stroke: ${options["cScaleInv" + i]} ;
32031 stroke-width: 3;
32032 }
32033
32034 .disabled, .disabled circle, .disabled text {
32035 fill: lightgray;
32036 }
32037 .disabled text {
32038 fill: #efefef;
32039 }
32040 `;
32041 }
32042 return sections;
32043};
32044const getStyles = (options) => `
32045 .edge {
32046 stroke-width: 3;
32047 }
32048 ${genSections(options)}
32049 .section-root rect, .section-root path, .section-root circle, .section-root polygon {
32050 fill: ${options.git0};
32051 }
32052 .section-root text {
32053 fill: ${options.gitBranchLabel0};
32054 }
32055 .icon-container {
32056 height:100%;
32057 display: flex;
32058 justify-content: center;
32059 align-items: center;
32060 }
32061 .edge {
32062 fill: none;
32063 }
32064 .mindmap-node-label {
32065 dy: 1em;
32066 alignment-baseline: middle;
32067 text-anchor: middle;
32068 dominant-baseline: middle;
32069 text-align: center;
32070 }
32071`;
32072const mindmapStyles = getStyles;
32073const diagram = {
32074 db: mindmapDb,
32075 renderer: mindmapRenderer,
32076 parser: mindmapParser,
32077 styles: mindmapStyles
32078};
32079export {
32080 diagram
32081};