@myrialabs/clopen 0.4.49 → 0.4.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/backend/chat/background-wait.test.ts +28 -0
  2. package/backend/chat/message-pages.test.ts +17 -0
  3. package/backend/chat/message-pages.ts +6 -2
  4. package/backend/chat/stream-manager.ts +73 -14
  5. package/backend/database/migrations/088_create_messages_fts_map.ts +52 -0
  6. package/backend/database/migrations/089_add_memory_layout_tiles.ts +58 -0
  7. package/backend/database/migrations/index.ts +14 -0
  8. package/backend/database/queries/graph-queries.ts +392 -135
  9. package/backend/database/queries/message-fts.test.ts +120 -0
  10. package/backend/database/queries/message-queries.ts +45 -9
  11. package/backend/database/queries/session-queries.ts +3 -2
  12. package/backend/database/queries/utils-queries.ts +3 -0
  13. package/backend/engine/adapters/claude/environment.ts +4 -0
  14. package/backend/engine/adapters/claude/input-gate.test.ts +59 -0
  15. package/backend/engine/adapters/claude/input-gate.ts +74 -0
  16. package/backend/engine/adapters/claude/message-converter.test.ts +16 -0
  17. package/backend/engine/adapters/claude/message-converter.ts +8 -0
  18. package/backend/engine/adapters/claude/stream.ts +15 -0
  19. package/backend/git/identity/scope-config.test.ts +7 -4
  20. package/backend/index.ts +35 -8
  21. package/backend/memory/README.md +7 -4
  22. package/backend/memory/layout.test.ts +377 -0
  23. package/backend/memory/layout.ts +1029 -265
  24. package/backend/memory/view.ts +257 -386
  25. package/backend/project/status-manager.ts +4 -2
  26. package/backend/ws/chat/stream.ts +19 -10
  27. package/backend/ws/memory/crud.ts +118 -81
  28. package/backend/ws/messages/crud.ts +3 -1
  29. package/bin/clopen.ts +3 -2
  30. package/dist/assets/{index-DD0-3EWg.js → index-By6KdSLT.js} +1 -1
  31. package/dist/assets/index-By6KdSLT.js.br +0 -0
  32. package/dist/assets/index-By6KdSLT.js.gz +0 -0
  33. package/dist/assets/{index-CrVWZH_D.js → index-DV4TiDn1.js} +1 -1
  34. package/dist/assets/index-DV4TiDn1.js.br +0 -0
  35. package/dist/assets/index-DV4TiDn1.js.gz +0 -0
  36. package/dist/assets/main-DIESTGTD.css +1 -0
  37. package/dist/assets/main-DIESTGTD.css.br +0 -0
  38. package/dist/assets/main-DIESTGTD.css.gz +0 -0
  39. package/dist/assets/{main-D2_TmcwQ.js → main-Da3JKoua.js} +612 -612
  40. package/dist/assets/main-Da3JKoua.js.br +0 -0
  41. package/dist/assets/main-Da3JKoua.js.gz +0 -0
  42. package/dist/index.html +2 -2
  43. package/dist/index.html.br +0 -0
  44. package/dist/index.html.gz +0 -0
  45. package/package.json +3 -3
  46. package/shared/types/memory.ts +96 -73
  47. package/shared/types/unified/index.ts +1 -0
  48. package/shared/types/unified/stream.ts +22 -1
  49. package/shared/utils/process-supervisor.test.ts +71 -1
  50. package/shared/utils/process-supervisor.ts +134 -29
  51. package/shared/utils/process-tree.ts +99 -0
  52. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js +0 -1
  53. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
  54. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
  55. package/dist/assets/index-CrVWZH_D.js.br +0 -0
  56. package/dist/assets/index-CrVWZH_D.js.gz +0 -0
  57. package/dist/assets/index-DD0-3EWg.js.br +0 -0
  58. package/dist/assets/index-DD0-3EWg.js.gz +0 -0
  59. package/dist/assets/main-D2_TmcwQ.js.br +0 -0
  60. package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
  61. package/dist/assets/main-Yucigcmf.css +0 -1
  62. package/dist/assets/main-Yucigcmf.css.br +0 -0
  63. package/dist/assets/main-Yucigcmf.css.gz +0 -0
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The processes below a pid, and waiting for them to be gone.
3
+ *
4
+ * A supervised child (the server, the dev frontend) starts processes of its
5
+ * own — engine CLIs, the preview's Chrome, cloudflared — and some of those sit
6
+ * in other process groups, so a signal to the child's group does not reach
7
+ * them. Collected BEFORE anything is signalled: once their parent exits they
8
+ * are re-parented and can no longer be found by parent id.
9
+ *
10
+ * POSIX only (`ps`); on Windows the lists are empty and callers fall back to
11
+ * the single pid.
12
+ */
13
+
14
+ const IS_WINDOWS = process.platform === 'win32';
15
+
16
+ /** Every descendant of `rootPid` (not `rootPid` itself). */
17
+ export function collectDescendants(rootPid: number): number[] {
18
+ if (IS_WINDOWS || !Number.isInteger(rootPid) || rootPid <= 0) return [];
19
+ let output: string;
20
+ try {
21
+ output = new TextDecoder().decode(Bun.spawnSync(['ps', '-A', '-o', 'pid=,ppid='], { stdout: 'pipe', stderr: 'ignore' }).stdout);
22
+ } catch {
23
+ return [];
24
+ }
25
+ const children = new Map<number, number[]>();
26
+ for (const line of output.split('\n')) {
27
+ const [pid, ppid] = line.trim().split(/\s+/).map(Number);
28
+ if (!pid || ppid === undefined || Number.isNaN(ppid)) continue;
29
+ const list = children.get(ppid);
30
+ if (list) list.push(pid);
31
+ else children.set(ppid, [pid]);
32
+ }
33
+ const found = new Set<number>();
34
+ const queue = [rootPid];
35
+ while (queue.length > 0) {
36
+ const pid = queue.pop()!;
37
+ for (const child of children.get(pid) ?? []) {
38
+ if (found.has(child) || child === rootPid || child === process.pid) continue;
39
+ found.add(child);
40
+ queue.push(child);
41
+ }
42
+ }
43
+ return [...found];
44
+ }
45
+
46
+ /** Whether `pid` still exists (one we may not signal counts as existing). */
47
+ export function isAlive(pid: number): boolean {
48
+ try {
49
+ process.kill(pid, 0);
50
+ return true;
51
+ } catch (err) {
52
+ return (err as NodeJS.ErrnoException).code === 'EPERM';
53
+ }
54
+ }
55
+
56
+ /** Send `signal` to every pid still there. */
57
+ export function signalAll(pids: number[], signal: NodeJS.Signals): void {
58
+ for (const pid of pids) {
59
+ try {
60
+ process.kill(pid, signal);
61
+ } catch {
62
+ // Already gone.
63
+ }
64
+ }
65
+ }
66
+
67
+ /** Resolves once none of `pids` exists, or after `timeoutMs`; returns the survivors. */
68
+ export async function waitForExit(pids: number[], timeoutMs: number, pollMs = 50): Promise<number[]> {
69
+ const deadline = Date.now() + timeoutMs;
70
+ let alive = pids.filter(isAlive);
71
+ while (alive.length > 0 && Date.now() < deadline) {
72
+ await new Promise((resolve) => setTimeout(resolve, pollMs));
73
+ alive = alive.filter(isAlive);
74
+ }
75
+ return alive;
76
+ }
77
+
78
+ /**
79
+ * Whether this process's parent forwards terminal signals to it: a script
80
+ * runner (`bun run`, `bun x`) in the same process group. A Ctrl+C reaches the
81
+ * whole foreground group — runner and child — and the runner then forwards its
82
+ * copy, so the child receives the FIRST Ctrl+C twice (measured: 1 ms apart;
83
+ * later presses arrive once). A plain shell does not forward.
84
+ */
85
+ export function parentForwardsSignals(): boolean {
86
+ if (IS_WINDOWS) return false;
87
+ try {
88
+ const read = (pid: number, field: string) =>
89
+ new TextDecoder().decode(Bun.spawnSync(['ps', '-o', `${field}=`, '-p', String(pid)], { stdout: 'pipe', stderr: 'ignore' }).stdout).trim();
90
+ const ownGroup = read(process.pid, 'pgid');
91
+ const parentGroup = read(process.ppid, 'pgid');
92
+ if (!ownGroup || ownGroup !== parentGroup) return false;
93
+ const command = read(process.ppid, 'command');
94
+ const program = command.split(/\s+/)[0]?.split('/').pop() ?? '';
95
+ return program === 'bun' || program === 'bunx' || program === 'bun.exe';
96
+ } catch {
97
+ return false;
98
+ }
99
+ }
@@ -1 +0,0 @@
1
- (function(){"use strict";function yt(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Ee={exports:{}},qe;function wt(){if(qe)return Ee.exports;qe=1;var i=typeof Reflect=="object"?Reflect:null,e=i&&typeof i.apply=="function"?i.apply:function(g,E,_){return Function.prototype.apply.call(g,E,_)},t;i&&typeof i.ownKeys=="function"?t=i.ownKeys:Object.getOwnPropertySymbols?t=function(g){return Object.getOwnPropertyNames(g).concat(Object.getOwnPropertySymbols(g))}:t=function(g){return Object.getOwnPropertyNames(g)};function n(w){console&&console.warn&&console.warn(w)}var r=Number.isNaN||function(g){return g!==g};function o(){o.init.call(this)}Ee.exports=o,Ee.exports.once=j,o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var s=10;function u(w){if(typeof w!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof w)}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(w){if(typeof w!="number"||w<0||r(w))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+w+".");s=w}}),o.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(g){if(typeof g!="number"||g<0||r(g))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+g+".");return this._maxListeners=g,this};function h(w){return w._maxListeners===void 0?o.defaultMaxListeners:w._maxListeners}o.prototype.getMaxListeners=function(){return h(this)},o.prototype.emit=function(g){for(var E=[],_=1;_<arguments.length;_++)E.push(arguments[_]);var L=g==="error",S=this._events;if(S!==void 0)L=L&&S.error===void 0;else if(!L)return!1;if(L){var I;if(E.length>0&&(I=E[0]),I instanceof Error)throw I;var Z=new Error("Unhandled error."+(I?" ("+I.message+")":""));throw Z.context=I,Z}var z=S[g];if(z===void 0)return!1;if(typeof z=="function")e(z,this,E);else for(var d=z.length,ce=U(z,d),_=0;_<d;++_)e(ce[_],this,E);return!0};function a(w,g,E,_){var L,S,I;if(u(E),S=w._events,S===void 0?(S=w._events=Object.create(null),w._eventsCount=0):(S.newListener!==void 0&&(w.emit("newListener",g,E.listener?E.listener:E),S=w._events),I=S[g]),I===void 0)I=S[g]=E,++w._eventsCount;else if(typeof I=="function"?I=S[g]=_?[E,I]:[I,E]:_?I.unshift(E):I.push(E),L=h(w),L>0&&I.length>L&&!I.warned){I.warned=!0;var Z=new Error("Possible EventEmitter memory leak detected. "+I.length+" "+String(g)+" listeners added. Use emitter.setMaxListeners() to increase limit");Z.name="MaxListenersExceededWarning",Z.emitter=w,Z.type=g,Z.count=I.length,n(Z)}return w}o.prototype.addListener=function(g,E){return a(this,g,E,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(g,E){return a(this,g,E,!0)};function c(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function l(w,g,E){var _={fired:!1,wrapFn:void 0,target:w,type:g,listener:E},L=c.bind(_);return L.listener=E,_.wrapFn=L,L}o.prototype.once=function(g,E){return u(E),this.on(g,l(this,g,E)),this},o.prototype.prependOnceListener=function(g,E){return u(E),this.prependListener(g,l(this,g,E)),this},o.prototype.removeListener=function(g,E){var _,L,S,I,Z;if(u(E),L=this._events,L===void 0)return this;if(_=L[g],_===void 0)return this;if(_===E||_.listener===E)--this._eventsCount===0?this._events=Object.create(null):(delete L[g],L.removeListener&&this.emit("removeListener",g,_.listener||E));else if(typeof _!="function"){for(S=-1,I=_.length-1;I>=0;I--)if(_[I]===E||_[I].listener===E){Z=_[I].listener,S=I;break}if(S<0)return this;S===0?_.shift():O(_,S),_.length===1&&(L[g]=_[0]),L.removeListener!==void 0&&this.emit("removeListener",g,Z||E)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(g){var E,_,L;if(_=this._events,_===void 0)return this;if(_.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):_[g]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete _[g]),this;if(arguments.length===0){var S=Object.keys(_),I;for(L=0;L<S.length;++L)I=S[L],I!=="removeListener"&&this.removeAllListeners(I);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(E=_[g],typeof E=="function")this.removeListener(g,E);else if(E!==void 0)for(L=E.length-1;L>=0;L--)this.removeListener(g,E[L]);return this};function y(w,g,E){var _=w._events;if(_===void 0)return[];var L=_[g];return L===void 0?[]:typeof L=="function"?E?[L.listener||L]:[L]:E?R(L):U(L,L.length)}o.prototype.listeners=function(g){return y(this,g,!0)},o.prototype.rawListeners=function(g){return y(this,g,!1)},o.listenerCount=function(w,g){return typeof w.listenerCount=="function"?w.listenerCount(g):v.call(w,g)},o.prototype.listenerCount=v;function v(w){var g=this._events;if(g!==void 0){var E=g[w];if(typeof E=="function")return 1;if(E!==void 0)return E.length}return 0}o.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]};function U(w,g){for(var E=new Array(g),_=0;_<g;++_)E[_]=w[_];return E}function O(w,g){for(;g+1<w.length;g++)w[g]=w[g+1];w.pop()}function R(w){for(var g=new Array(w.length),E=0;E<g.length;++E)g[E]=w[E].listener||w[E];return g}function j(w,g){return new Promise(function(E,_){function L(I){w.removeListener(g,S),_(I)}function S(){typeof w.removeListener=="function"&&w.removeListener("error",L),E([].slice.call(arguments))}x(w,g,S,{once:!0}),g!=="error"&&C(w,L,{once:!0})})}function C(w,g,E){typeof w.on=="function"&&x(w,"error",g,E)}function x(w,g,E,_){if(typeof w.on=="function")_.once?w.once(g,E):w.on(g,E);else if(typeof w.addEventListener=="function")w.addEventListener(g,function L(S){_.once&&w.removeEventListener(g,L),E(S)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof w)}return Ee.exports}var bt=wt();function mt(){const i=arguments[0];for(let e=1,t=arguments.length;e<t;e++)if(arguments[e])for(const n in arguments[e])i[n]=arguments[e][n];return i}let B=mt;typeof Object.assign=="function"&&(B=Object.assign);function V(i,e,t,n){const r=i._nodes.get(e);let o=null;return r&&(n==="mixed"?o=r.out&&r.out[t]||r.undirected&&r.undirected[t]:n==="directed"?o=r.out&&r.out[t]:o=r.undirected&&r.undirected[t]),o}function q(i){return typeof i=="object"&&i!==null}function Ne(i){let e;for(e in i)return!1;return!0}function Y(i,e,t){Object.defineProperty(i,e,{enumerable:!1,configurable:!1,writable:!0,value:t})}function Q(i,e,t){const n={enumerable:!0,configurable:!0};typeof t=="function"?n.get=t:(n.value=t,n.writable=!1),Object.defineProperty(i,e,n)}function Ve(i){return!(!q(i)||i.attributes&&!Array.isArray(i.attributes))}function vt(){let i=Math.floor(Math.random()*256)&255;return()=>i++}function M(){const i=arguments;let e=null,t=-1;return{[Symbol.iterator](){return this},next(){let n=null;do{if(e===null){if(t++,t>=i.length)return{done:!0};e=i[t][Symbol.iterator]()}if(n=e.next(),n.done){e=null;continue}break}while(!0);return n}}}function ue(){return{[Symbol.iterator](){return this},next(){return{done:!0}}}}class Oe extends Error{constructor(e){super(),this.name="GraphError",this.message=e}}class G extends Oe{constructor(e){super(e),this.name="InvalidArgumentsGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,G.prototype.constructor)}}class b extends Oe{constructor(e){super(e),this.name="NotFoundGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,b.prototype.constructor)}}class $ extends Oe{constructor(e){super(e),this.name="UsageGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,$.prototype.constructor)}}function Ye(i,e){this.key=i,this.attributes=e,this.clear()}Ye.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={}};function Ze(i,e){this.key=i,this.attributes=e,this.clear()}Ze.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.directedLoops=0,this.in={},this.out={}};function Je(i,e){this.key=i,this.attributes=e,this.clear()}Je.prototype.clear=function(){this.undirectedDegree=0,this.undirectedLoops=0,this.undirected={}};function ae(i,e,t,n,r){this.key=e,this.attributes=r,this.undirected=i,this.source=t,this.target=n}ae.prototype.attach=function(){let i="out",e="in";this.undirected&&(i=e="undirected");const t=this.source.key,n=this.target.key;this.source[i][n]=this,!(this.undirected&&t===n)&&(this.target[e][t]=this)},ae.prototype.attachMulti=function(){let i="out",e="in";const t=this.source.key,n=this.target.key;this.undirected&&(i=e="undirected");const r=this.source[i],o=r[n];if(typeof o>"u"){r[n]=this,this.undirected&&t===n||(this.target[e][t]=this);return}o.previous=this,this.next=o,r[n]=this,this.target[e][t]=this},ae.prototype.detach=function(){const i=this.source.key,e=this.target.key;let t="out",n="in";this.undirected&&(t=n="undirected"),delete this.source[t][e],delete this.target[n][i]},ae.prototype.detachMulti=function(){const i=this.source.key,e=this.target.key;let t="out",n="in";this.undirected&&(t=n="undirected"),this.previous===void 0?this.next===void 0?(delete this.source[t][e],delete this.target[n][i]):(this.next.previous=void 0,this.source[t][e]=this.next,this.target[n][i]=this.next):(this.previous.next=this.next,this.next!==void 0&&(this.next.previous=this.previous))};const Qe=0,Xe=1,Et=2,Me=3;function ee(i,e,t,n,r,o,s){let u,h,a,c;if(n=""+n,t===Qe){if(u=i._nodes.get(n),!u)throw new b(`Graph.${e}: could not find the "${n}" node in the graph.`);a=r,c=o}else if(t===Me){if(r=""+r,h=i._edges.get(r),!h)throw new b(`Graph.${e}: could not find the "${r}" edge in the graph.`);const l=h.source.key,y=h.target.key;if(n===l)u=h.target;else if(n===y)u=h.source;else throw new b(`Graph.${e}: the "${n}" node is not attached to the "${r}" edge (${l}, ${y}).`);a=o,c=s}else{if(h=i._edges.get(n),!h)throw new b(`Graph.${e}: could not find the "${n}" edge in the graph.`);t===Xe?u=h.source:u=h.target,a=r,c=o}return[u,a,c]}function Gt(i,e,t){i.prototype[e]=function(n,r,o){const[s,u]=ee(this,e,t,n,r,o);return s.attributes[u]}}function _t(i,e,t){i.prototype[e]=function(n,r){const[o]=ee(this,e,t,n,r);return o.attributes}}function $t(i,e,t){i.prototype[e]=function(n,r,o){const[s,u]=ee(this,e,t,n,r,o);return s.attributes.hasOwnProperty(u)}}function Dt(i,e,t){i.prototype[e]=function(n,r,o,s){const[u,h,a]=ee(this,e,t,n,r,o,s);return u.attributes[h]=a,this.emit("nodeAttributesUpdated",{key:u.key,type:"set",attributes:u.attributes,name:h}),this}}function kt(i,e,t){i.prototype[e]=function(n,r,o,s){const[u,h,a]=ee(this,e,t,n,r,o,s);if(typeof a!="function")throw new G(`Graph.${e}: updater should be a function.`);const c=u.attributes,l=a(c[h]);return c[h]=l,this.emit("nodeAttributesUpdated",{key:u.key,type:"set",attributes:u.attributes,name:h}),this}}function At(i,e,t){i.prototype[e]=function(n,r,o){const[s,u]=ee(this,e,t,n,r,o);return delete s.attributes[u],this.emit("nodeAttributesUpdated",{key:s.key,type:"remove",attributes:s.attributes,name:u}),this}}function Lt(i,e,t){i.prototype[e]=function(n,r,o){const[s,u]=ee(this,e,t,n,r,o);if(!q(u))throw new G(`Graph.${e}: provided attributes are not a plain object.`);return s.attributes=u,this.emit("nodeAttributesUpdated",{key:s.key,type:"replace",attributes:s.attributes}),this}}function St(i,e,t){i.prototype[e]=function(n,r,o){const[s,u]=ee(this,e,t,n,r,o);if(!q(u))throw new G(`Graph.${e}: provided attributes are not a plain object.`);return B(s.attributes,u),this.emit("nodeAttributesUpdated",{key:s.key,type:"merge",attributes:s.attributes,data:u}),this}}function Ut(i,e,t){i.prototype[e]=function(n,r,o){const[s,u]=ee(this,e,t,n,r,o);if(typeof u!="function")throw new G(`Graph.${e}: provided updater is not a function.`);return s.attributes=u(s.attributes),this.emit("nodeAttributesUpdated",{key:s.key,type:"update",attributes:s.attributes}),this}}const Ot=[{name:i=>`get${i}Attribute`,attacher:Gt},{name:i=>`get${i}Attributes`,attacher:_t},{name:i=>`has${i}Attribute`,attacher:$t},{name:i=>`set${i}Attribute`,attacher:Dt},{name:i=>`update${i}Attribute`,attacher:kt},{name:i=>`remove${i}Attribute`,attacher:At},{name:i=>`replace${i}Attributes`,attacher:Lt},{name:i=>`merge${i}Attributes`,attacher:St},{name:i=>`update${i}Attributes`,attacher:Ut}];function It(i){Ot.forEach(function({name:e,attacher:t}){t(i,e("Node"),Qe),t(i,e("Source"),Xe),t(i,e("Target"),Et),t(i,e("Opposite"),Me)})}function Ct(i,e,t){i.prototype[e]=function(n,r){let o;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new $(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new $(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);const s=""+n,u=""+r;if(r=arguments[2],o=V(this,s,u,t),!o)throw new b(`Graph.${e}: could not find an edge for the given path ("${s}" - "${u}").`)}else{if(t!=="mixed")throw new $(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(n=""+n,o=this._edges.get(n),!o)throw new b(`Graph.${e}: could not find the "${n}" edge in the graph.`)}return o.attributes[r]}}function Rt(i,e,t){i.prototype[e]=function(n){let r;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new $(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>1){if(this.multi)throw new $(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);const o=""+n,s=""+arguments[1];if(r=V(this,o,s,t),!r)throw new b(`Graph.${e}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(t!=="mixed")throw new $(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(n=""+n,r=this._edges.get(n),!r)throw new b(`Graph.${e}: could not find the "${n}" edge in the graph.`)}return r.attributes}}function jt(i,e,t){i.prototype[e]=function(n,r){let o;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new $(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new $(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);const s=""+n,u=""+r;if(r=arguments[2],o=V(this,s,u,t),!o)throw new b(`Graph.${e}: could not find an edge for the given path ("${s}" - "${u}").`)}else{if(t!=="mixed")throw new $(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(n=""+n,o=this._edges.get(n),!o)throw new b(`Graph.${e}: could not find the "${n}" edge in the graph.`)}return o.attributes.hasOwnProperty(r)}}function zt(i,e,t){i.prototype[e]=function(n,r,o){let s;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new $(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new $(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);const u=""+n,h=""+r;if(r=arguments[2],o=arguments[3],s=V(this,u,h,t),!s)throw new b(`Graph.${e}: could not find an edge for the given path ("${u}" - "${h}").`)}else{if(t!=="mixed")throw new $(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(n=""+n,s=this._edges.get(n),!s)throw new b(`Graph.${e}: could not find the "${n}" edge in the graph.`)}return s.attributes[r]=o,this.emit("edgeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:r}),this}}function Tt(i,e,t){i.prototype[e]=function(n,r,o){let s;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new $(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new $(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);const u=""+n,h=""+r;if(r=arguments[2],o=arguments[3],s=V(this,u,h,t),!s)throw new b(`Graph.${e}: could not find an edge for the given path ("${u}" - "${h}").`)}else{if(t!=="mixed")throw new $(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(n=""+n,s=this._edges.get(n),!s)throw new b(`Graph.${e}: could not find the "${n}" edge in the graph.`)}if(typeof o!="function")throw new G(`Graph.${e}: updater should be a function.`);return s.attributes[r]=o(s.attributes[r]),this.emit("edgeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:r}),this}}function Wt(i,e,t){i.prototype[e]=function(n,r){let o;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new $(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new $(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);const s=""+n,u=""+r;if(r=arguments[2],o=V(this,s,u,t),!o)throw new b(`Graph.${e}: could not find an edge for the given path ("${s}" - "${u}").`)}else{if(t!=="mixed")throw new $(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(n=""+n,o=this._edges.get(n),!o)throw new b(`Graph.${e}: could not find the "${n}" edge in the graph.`)}return delete o.attributes[r],this.emit("edgeAttributesUpdated",{key:o.key,type:"remove",attributes:o.attributes,name:r}),this}}function Pt(i,e,t){i.prototype[e]=function(n,r){let o;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new $(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new $(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);const s=""+n,u=""+r;if(r=arguments[2],o=V(this,s,u,t),!o)throw new b(`Graph.${e}: could not find an edge for the given path ("${s}" - "${u}").`)}else{if(t!=="mixed")throw new $(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(n=""+n,o=this._edges.get(n),!o)throw new b(`Graph.${e}: could not find the "${n}" edge in the graph.`)}if(!q(r))throw new G(`Graph.${e}: provided attributes are not a plain object.`);return o.attributes=r,this.emit("edgeAttributesUpdated",{key:o.key,type:"replace",attributes:o.attributes}),this}}function xt(i,e,t){i.prototype[e]=function(n,r){let o;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new $(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new $(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);const s=""+n,u=""+r;if(r=arguments[2],o=V(this,s,u,t),!o)throw new b(`Graph.${e}: could not find an edge for the given path ("${s}" - "${u}").`)}else{if(t!=="mixed")throw new $(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(n=""+n,o=this._edges.get(n),!o)throw new b(`Graph.${e}: could not find the "${n}" edge in the graph.`)}if(!q(r))throw new G(`Graph.${e}: provided attributes are not a plain object.`);return B(o.attributes,r),this.emit("edgeAttributesUpdated",{key:o.key,type:"merge",attributes:o.attributes,data:r}),this}}function Kt(i,e,t){i.prototype[e]=function(n,r){let o;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new $(`Graph.${e}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new $(`Graph.${e}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);const s=""+n,u=""+r;if(r=arguments[2],o=V(this,s,u,t),!o)throw new b(`Graph.${e}: could not find an edge for the given path ("${s}" - "${u}").`)}else{if(t!=="mixed")throw new $(`Graph.${e}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(n=""+n,o=this._edges.get(n),!o)throw new b(`Graph.${e}: could not find the "${n}" edge in the graph.`)}if(typeof r!="function")throw new G(`Graph.${e}: provided updater is not a function.`);return o.attributes=r(o.attributes),this.emit("edgeAttributesUpdated",{key:o.key,type:"update",attributes:o.attributes}),this}}const Ft=[{name:i=>`get${i}Attribute`,attacher:Ct},{name:i=>`get${i}Attributes`,attacher:Rt},{name:i=>`has${i}Attribute`,attacher:jt},{name:i=>`set${i}Attribute`,attacher:zt},{name:i=>`update${i}Attribute`,attacher:Tt},{name:i=>`remove${i}Attribute`,attacher:Wt},{name:i=>`replace${i}Attributes`,attacher:Pt},{name:i=>`merge${i}Attributes`,attacher:xt},{name:i=>`update${i}Attributes`,attacher:Kt}];function Ht(i){Ft.forEach(function({name:e,attacher:t}){t(i,e("Edge"),"mixed"),t(i,e("DirectedEdge"),"directed"),t(i,e("UndirectedEdge"),"undirected")})}const Bt=[{name:"edges",type:"mixed"},{name:"inEdges",type:"directed",direction:"in"},{name:"outEdges",type:"directed",direction:"out"},{name:"inboundEdges",type:"mixed",direction:"in"},{name:"outboundEdges",type:"mixed",direction:"out"},{name:"directedEdges",type:"directed"},{name:"undirectedEdges",type:"undirected"}];function qt(i,e,t,n){let r=!1;for(const o in e){if(o===n)continue;const s=e[o];if(r=t(s.key,s.attributes,s.source.key,s.target.key,s.source.attributes,s.target.attributes,s.undirected),i&&r)return s.key}}function Nt(i,e,t,n){let r,o,s,u=!1;for(const h in e)if(h!==n){r=e[h];do{if(o=r.source,s=r.target,u=t(r.key,r.attributes,o.key,s.key,o.attributes,s.attributes,r.undirected),i&&u)return r.key;r=r.next}while(r!==void 0)}}function Ie(i,e){const t=Object.keys(i),n=t.length;let r,o=0;return{[Symbol.iterator](){return this},next(){do if(r)r=r.next;else{if(o>=n)return{done:!0};const s=t[o++];if(s===e){r=void 0;continue}r=i[s]}while(!r);return{done:!1,value:{edge:r.key,attributes:r.attributes,source:r.source.key,target:r.target.key,sourceAttributes:r.source.attributes,targetAttributes:r.target.attributes,undirected:r.undirected}}}}}function Vt(i,e,t,n){const r=e[t];if(!r)return;const o=r.source,s=r.target;if(n(r.key,r.attributes,o.key,s.key,o.attributes,s.attributes,r.undirected)&&i)return r.key}function Yt(i,e,t,n){let r=e[t];if(!r)return;let o=!1;do{if(o=n(r.key,r.attributes,r.source.key,r.target.key,r.source.attributes,r.target.attributes,r.undirected),i&&o)return r.key;r=r.next}while(r!==void 0)}function Ce(i,e){let t=i[e];if(t.next!==void 0)return{[Symbol.iterator](){return this},next(){if(!t)return{done:!0};const r={edge:t.key,attributes:t.attributes,source:t.source.key,target:t.target.key,sourceAttributes:t.source.attributes,targetAttributes:t.target.attributes,undirected:t.undirected};return t=t.next,{done:!1,value:r}}};let n=!1;return{[Symbol.iterator](){return this},next(){return n===!0?{done:!0}:(n=!0,{done:!1,value:{edge:t.key,attributes:t.attributes,source:t.source.key,target:t.target.key,sourceAttributes:t.source.attributes,targetAttributes:t.target.attributes,undirected:t.undirected}})}}}function Zt(i,e){if(i.size===0)return[];if(e==="mixed"||e===i.type)return Array.from(i._edges.keys());const t=e==="undirected"?i.undirectedSize:i.directedSize,n=new Array(t),r=e==="undirected",o=i._edges.values();let s=0,u,h;for(;u=o.next(),u.done!==!0;)h=u.value,h.undirected===r&&(n[s++]=h.key);return n}function et(i,e,t,n){if(e.size===0)return;const r=t!=="mixed"&&t!==e.type,o=t==="undirected";let s,u,h=!1;const a=e._edges.values();for(;s=a.next(),s.done!==!0;){if(u=s.value,r&&u.undirected!==o)continue;const{key:c,attributes:l,source:y,target:v}=u;if(h=n(c,l,y.key,v.key,y.attributes,v.attributes,u.undirected),i&&h)return c}}function Jt(i,e){if(i.size===0)return ue();const t=e!=="mixed"&&e!==i.type,n=e==="undirected",r=i._edges.values();return{[Symbol.iterator](){return this},next(){let o,s;for(;;){if(o=r.next(),o.done)return o;if(s=o.value,!(t&&s.undirected!==n))break}return{value:{edge:s.key,attributes:s.attributes,source:s.source.key,target:s.target.key,sourceAttributes:s.source.attributes,targetAttributes:s.target.attributes,undirected:s.undirected},done:!1}}}}function Re(i,e,t,n,r,o){const s=e?Nt:qt;let u;if(t!=="undirected"&&(n!=="out"&&(u=s(i,r.in,o),i&&u)||n!=="in"&&(u=s(i,r.out,o,n?void 0:r.key),i&&u))||t!=="directed"&&(u=s(i,r.undirected,o),i&&u))return u}function Qt(i,e,t,n){const r=[];return Re(!1,i,e,t,n,function(o){r.push(o)}),r}function Xt(i,e,t){let n=ue();return i!=="undirected"&&(e!=="out"&&typeof t.in<"u"&&(n=M(n,Ie(t.in))),e!=="in"&&typeof t.out<"u"&&(n=M(n,Ie(t.out,e?void 0:t.key)))),i!=="directed"&&typeof t.undirected<"u"&&(n=M(n,Ie(t.undirected))),n}function je(i,e,t,n,r,o,s){const u=t?Yt:Vt;let h;if(e!=="undirected"&&(typeof r.in<"u"&&n!=="out"&&(h=u(i,r.in,o,s),i&&h)||typeof r.out<"u"&&n!=="in"&&(n||r.key!==o)&&(h=u(i,r.out,o,s),i&&h))||e!=="directed"&&typeof r.undirected<"u"&&(h=u(i,r.undirected,o,s),i&&h))return h}function Mt(i,e,t,n,r){const o=[];return je(!1,i,e,t,n,r,function(s){o.push(s)}),o}function en(i,e,t,n){let r=ue();return i!=="undirected"&&(typeof t.in<"u"&&e!=="out"&&n in t.in&&(r=M(r,Ce(t.in,n))),typeof t.out<"u"&&e!=="in"&&n in t.out&&(e||t.key!==n)&&(r=M(r,Ce(t.out,n)))),i!=="directed"&&typeof t.undirected<"u"&&n in t.undirected&&(r=M(r,Ce(t.undirected,n))),r}function tn(i,e){const{name:t,type:n,direction:r}=e;i.prototype[t]=function(o,s){if(n!=="mixed"&&this.type!=="mixed"&&n!==this.type)return[];if(!arguments.length)return Zt(this,n);if(arguments.length===1){o=""+o;const u=this._nodes.get(o);if(typeof u>"u")throw new b(`Graph.${t}: could not find the "${o}" node in the graph.`);return Qt(this.multi,n==="mixed"?this.type:n,r,u)}if(arguments.length===2){o=""+o,s=""+s;const u=this._nodes.get(o);if(!u)throw new b(`Graph.${t}: could not find the "${o}" source node in the graph.`);if(!this._nodes.has(s))throw new b(`Graph.${t}: could not find the "${s}" target node in the graph.`);return Mt(n,this.multi,r,u,s)}throw new G(`Graph.${t}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function nn(i,e){const{name:t,type:n,direction:r}=e,o="forEach"+t[0].toUpperCase()+t.slice(1,-1);i.prototype[o]=function(a,c,l){if(!(n!=="mixed"&&this.type!=="mixed"&&n!==this.type)){if(arguments.length===1)return l=a,et(!1,this,n,l);if(arguments.length===2){a=""+a,l=c;const y=this._nodes.get(a);if(typeof y>"u")throw new b(`Graph.${o}: could not find the "${a}" node in the graph.`);return Re(!1,this.multi,n==="mixed"?this.type:n,r,y,l)}if(arguments.length===3){a=""+a,c=""+c;const y=this._nodes.get(a);if(!y)throw new b(`Graph.${o}: could not find the "${a}" source node in the graph.`);if(!this._nodes.has(c))throw new b(`Graph.${o}: could not find the "${c}" target node in the graph.`);return je(!1,n,this.multi,r,y,c,l)}throw new G(`Graph.${o}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)}};const s="map"+t[0].toUpperCase()+t.slice(1);i.prototype[s]=function(){const a=Array.prototype.slice.call(arguments),c=a.pop();let l;if(a.length===0){let y=0;n!=="directed"&&(y+=this.undirectedSize),n!=="undirected"&&(y+=this.directedSize),l=new Array(y);let v=0;a.push((U,O,R,j,C,x,w)=>{l[v++]=c(U,O,R,j,C,x,w)})}else l=[],a.push((y,v,U,O,R,j,C)=>{l.push(c(y,v,U,O,R,j,C))});return this[o].apply(this,a),l};const u="filter"+t[0].toUpperCase()+t.slice(1);i.prototype[u]=function(){const a=Array.prototype.slice.call(arguments),c=a.pop(),l=[];return a.push((y,v,U,O,R,j,C)=>{c(y,v,U,O,R,j,C)&&l.push(y)}),this[o].apply(this,a),l};const h="reduce"+t[0].toUpperCase()+t.slice(1);i.prototype[h]=function(){let a=Array.prototype.slice.call(arguments);if(a.length<2||a.length>4)throw new G(`Graph.${h}: invalid number of arguments (expecting 2, 3 or 4 and got ${a.length}).`);if(typeof a[a.length-1]=="function"&&typeof a[a.length-2]!="function")throw new G(`Graph.${h}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let c,l;a.length===2?(c=a[0],l=a[1],a=[]):a.length===3?(c=a[1],l=a[2],a=[a[0]]):a.length===4&&(c=a[2],l=a[3],a=[a[0],a[1]]);let y=l;return a.push((v,U,O,R,j,C,x)=>{y=c(y,v,U,O,R,j,C,x)}),this[o].apply(this,a),y}}function rn(i,e){const{name:t,type:n,direction:r}=e,o="find"+t[0].toUpperCase()+t.slice(1,-1);i.prototype[o]=function(h,a,c){if(n!=="mixed"&&this.type!=="mixed"&&n!==this.type)return!1;if(arguments.length===1)return c=h,et(!0,this,n,c);if(arguments.length===2){h=""+h,c=a;const l=this._nodes.get(h);if(typeof l>"u")throw new b(`Graph.${o}: could not find the "${h}" node in the graph.`);return Re(!0,this.multi,n==="mixed"?this.type:n,r,l,c)}if(arguments.length===3){h=""+h,a=""+a;const l=this._nodes.get(h);if(!l)throw new b(`Graph.${o}: could not find the "${h}" source node in the graph.`);if(!this._nodes.has(a))throw new b(`Graph.${o}: could not find the "${a}" target node in the graph.`);return je(!0,n,this.multi,r,l,a,c)}throw new G(`Graph.${o}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)};const s="some"+t[0].toUpperCase()+t.slice(1,-1);i.prototype[s]=function(){const h=Array.prototype.slice.call(arguments),a=h.pop();return h.push((l,y,v,U,O,R,j)=>a(l,y,v,U,O,R,j)),!!this[o].apply(this,h)};const u="every"+t[0].toUpperCase()+t.slice(1,-1);i.prototype[u]=function(){const h=Array.prototype.slice.call(arguments),a=h.pop();return h.push((l,y,v,U,O,R,j)=>!a(l,y,v,U,O,R,j)),!this[o].apply(this,h)}}function on(i,e){const{name:t,type:n,direction:r}=e,o=t.slice(0,-1)+"Entries";i.prototype[o]=function(s,u){if(n!=="mixed"&&this.type!=="mixed"&&n!==this.type)return ue();if(!arguments.length)return Jt(this,n);if(arguments.length===1){s=""+s;const h=this._nodes.get(s);if(!h)throw new b(`Graph.${o}: could not find the "${s}" node in the graph.`);return Xt(n,r,h)}if(arguments.length===2){s=""+s,u=""+u;const h=this._nodes.get(s);if(!h)throw new b(`Graph.${o}: could not find the "${s}" source node in the graph.`);if(!this._nodes.has(u))throw new b(`Graph.${o}: could not find the "${u}" target node in the graph.`);return en(n,r,h,u)}throw new G(`Graph.${o}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function sn(i){Bt.forEach(e=>{tn(i,e),nn(i,e),rn(i,e),on(i,e)})}const un=[{name:"neighbors",type:"mixed"},{name:"inNeighbors",type:"directed",direction:"in"},{name:"outNeighbors",type:"directed",direction:"out"},{name:"inboundNeighbors",type:"mixed",direction:"in"},{name:"outboundNeighbors",type:"mixed",direction:"out"},{name:"directedNeighbors",type:"directed"},{name:"undirectedNeighbors",type:"undirected"}];function Ge(){this.A=null,this.B=null}Ge.prototype.wrap=function(i){this.A===null?this.A=i:this.B===null&&(this.B=i)},Ge.prototype.has=function(i){return this.A!==null&&i in this.A||this.B!==null&&i in this.B};function ye(i,e,t,n,r){for(const o in n){const s=n[o],u=s.source,h=s.target,a=u===t?h:u;if(e&&e.has(a.key))continue;const c=r(a.key,a.attributes);if(i&&c)return a.key}}function ze(i,e,t,n,r){if(e!=="mixed"){if(e==="undirected")return ye(i,null,n,n.undirected,r);if(typeof t=="string")return ye(i,null,n,n[t],r)}const o=new Ge;let s;if(e!=="undirected"){if(t!=="out"){if(s=ye(i,null,n,n.in,r),i&&s)return s;o.wrap(n.in)}if(t!=="in"){if(s=ye(i,o,n,n.out,r),i&&s)return s;o.wrap(n.out)}}if(e!=="directed"&&(s=ye(i,o,n,n.undirected,r),i&&s))return s}function an(i,e,t){if(i!=="mixed"){if(i==="undirected")return Object.keys(t.undirected);if(typeof e=="string")return Object.keys(t[e])}const n=[];return ze(!1,i,e,t,function(r){n.push(r)}),n}function we(i,e,t){const n=Object.keys(t),r=n.length;let o=0;return{[Symbol.iterator](){return this},next(){let s=null;do{if(o>=r)return i&&i.wrap(t),{done:!0};const u=t[n[o++]],h=u.source,a=u.target;if(s=h===e?a:h,i&&i.has(s.key)){s=null;continue}}while(s===null);return{done:!1,value:{neighbor:s.key,attributes:s.attributes}}}}}function hn(i,e,t){if(i!=="mixed"){if(i==="undirected")return we(null,t,t.undirected);if(typeof e=="string")return we(null,t,t[e])}let n=ue();const r=new Ge;return i!=="undirected"&&(e!=="out"&&(n=M(n,we(r,t,t.in))),e!=="in"&&(n=M(n,we(r,t,t.out)))),i!=="directed"&&(n=M(n,we(r,t,t.undirected))),n}function dn(i,e){const{name:t,type:n,direction:r}=e;i.prototype[t]=function(o){if(n!=="mixed"&&this.type!=="mixed"&&n!==this.type)return[];o=""+o;const s=this._nodes.get(o);if(typeof s>"u")throw new b(`Graph.${t}: could not find the "${o}" node in the graph.`);return an(n==="mixed"?this.type:n,r,s)}}function cn(i,e){const{name:t,type:n,direction:r}=e,o="forEach"+t[0].toUpperCase()+t.slice(1,-1);i.prototype[o]=function(a,c){if(n!=="mixed"&&this.type!=="mixed"&&n!==this.type)return;a=""+a;const l=this._nodes.get(a);if(typeof l>"u")throw new b(`Graph.${o}: could not find the "${a}" node in the graph.`);ze(!1,n==="mixed"?this.type:n,r,l,c)};const s="map"+t[0].toUpperCase()+t.slice(1);i.prototype[s]=function(a,c){const l=[];return this[o](a,(y,v)=>{l.push(c(y,v))}),l};const u="filter"+t[0].toUpperCase()+t.slice(1);i.prototype[u]=function(a,c){const l=[];return this[o](a,(y,v)=>{c(y,v)&&l.push(y)}),l};const h="reduce"+t[0].toUpperCase()+t.slice(1);i.prototype[h]=function(a,c,l){if(arguments.length<3)throw new G(`Graph.${h}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let y=l;return this[o](a,(v,U)=>{y=c(y,v,U)}),y}}function fn(i,e){const{name:t,type:n,direction:r}=e,o=t[0].toUpperCase()+t.slice(1,-1),s="find"+o;i.prototype[s]=function(a,c){if(n!=="mixed"&&this.type!=="mixed"&&n!==this.type)return;a=""+a;const l=this._nodes.get(a);if(typeof l>"u")throw new b(`Graph.${s}: could not find the "${a}" node in the graph.`);return ze(!0,n==="mixed"?this.type:n,r,l,c)};const u="some"+o;i.prototype[u]=function(a,c){return!!this[s](a,c)};const h="every"+o;i.prototype[h]=function(a,c){return!this[s](a,(y,v)=>!c(y,v))}}function ln(i,e){const{name:t,type:n,direction:r}=e,o=t.slice(0,-1)+"Entries";i.prototype[o]=function(s){if(n!=="mixed"&&this.type!=="mixed"&&n!==this.type)return ue();s=""+s;const u=this._nodes.get(s);if(typeof u>"u")throw new b(`Graph.${o}: could not find the "${s}" node in the graph.`);return hn(n==="mixed"?this.type:n,r,u)}}function pn(i){un.forEach(e=>{dn(i,e),cn(i,e),fn(i,e),ln(i,e)})}function _e(i,e,t,n,r){const o=n._nodes.values(),s=n.type;let u,h,a,c,l,y;for(;u=o.next(),u.done!==!0;){let v=!1;if(h=u.value,s!=="undirected"){c=h.out;for(a in c){l=c[a];do y=l.target,v=!0,r(h.key,y.key,h.attributes,y.attributes,l.key,l.attributes,l.undirected),l=l.next;while(l)}}if(s!=="directed"){c=h.undirected;for(a in c)if(!(e&&h.key>a)){l=c[a];do y=l.target,y.key!==a&&(y=l.source),v=!0,r(h.key,y.key,h.attributes,y.attributes,l.key,l.attributes,l.undirected),l=l.next;while(l)}}t&&!v&&r(h.key,null,h.attributes,null,null,null,null)}}function gn(i,e){const t={key:i};return Ne(e.attributes)||(t.attributes=B({},e.attributes)),t}function yn(i,e,t){const n={key:e,source:t.source.key,target:t.target.key};return Ne(t.attributes)||(n.attributes=B({},t.attributes)),i==="mixed"&&t.undirected&&(n.undirected=!0),n}function wn(i){if(!q(i))throw new G('Graph.import: invalid serialized node. A serialized node should be a plain object with at least a "key" property.');if(!("key"in i))throw new G("Graph.import: serialized node is missing its key.");if("attributes"in i&&(!q(i.attributes)||i.attributes===null))throw new G("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.")}function bn(i){if(!q(i))throw new G('Graph.import: invalid serialized edge. A serialized edge should be a plain object with at least a "source" & "target" property.');if(!("source"in i))throw new G("Graph.import: serialized edge is missing its source.");if(!("target"in i))throw new G("Graph.import: serialized edge is missing its target.");if("attributes"in i&&(!q(i.attributes)||i.attributes===null))throw new G("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.");if("undirected"in i&&typeof i.undirected!="boolean")throw new G("Graph.import: invalid undirectedness information. Undirected should be boolean or omitted.")}const mn=vt(),vn=new Set(["directed","undirected","mixed"]),tt=new Set(["domain","_events","_eventsCount","_maxListeners"]),En=[{name:i=>`${i}Edge`,generateKey:!0},{name:i=>`${i}DirectedEdge`,generateKey:!0,type:"directed"},{name:i=>`${i}UndirectedEdge`,generateKey:!0,type:"undirected"},{name:i=>`${i}EdgeWithKey`},{name:i=>`${i}DirectedEdgeWithKey`,type:"directed"},{name:i=>`${i}UndirectedEdgeWithKey`,type:"undirected"}],Gn={allowSelfLoops:!0,multi:!1,type:"mixed"};function _n(i,e,t){if(t&&!q(t))throw new G(`Graph.addNode: invalid attributes. Expecting an object but got "${t}"`);if(e=""+e,t=t||{},i._nodes.has(e))throw new $(`Graph.addNode: the "${e}" node already exist in the graph.`);const n=new i.NodeDataClass(e,t);return i._nodes.set(e,n),i.emit("nodeAdded",{key:e,attributes:t}),n}function nt(i,e,t){const n=new i.NodeDataClass(e,t);return i._nodes.set(e,n),i.emit("nodeAdded",{key:e,attributes:t}),n}function it(i,e,t,n,r,o,s,u){if(!n&&i.type==="undirected")throw new $(`Graph.${e}: you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead.`);if(n&&i.type==="directed")throw new $(`Graph.${e}: you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead.`);if(u&&!q(u))throw new G(`Graph.${e}: invalid attributes. Expecting an object but got "${u}"`);if(o=""+o,s=""+s,u=u||{},!i.allowSelfLoops&&o===s)throw new $(`Graph.${e}: source & target are the same ("${o}"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.`);const h=i._nodes.get(o),a=i._nodes.get(s);if(!h)throw new b(`Graph.${e}: source node "${o}" not found.`);if(!a)throw new b(`Graph.${e}: target node "${s}" not found.`);const c={key:null,undirected:n,source:o,target:s,attributes:u};if(t)r=i._edgeKeyGenerator();else if(r=""+r,i._edges.has(r))throw new $(`Graph.${e}: the "${r}" edge already exists in the graph.`);if(!i.multi&&(n?typeof h.undirected[s]<"u":typeof h.out[s]<"u"))throw new $(`Graph.${e}: an edge linking "${o}" to "${s}" already exists. If you really want to add multiple edges linking those nodes, you should create a multi graph by using the 'multi' option.`);const l=new ae(n,r,h,a,u);i._edges.set(r,l);const y=o===s;return n?(h.undirectedDegree++,a.undirectedDegree++,y&&(h.undirectedLoops++,i._undirectedSelfLoopCount++)):(h.outDegree++,a.inDegree++,y&&(h.directedLoops++,i._directedSelfLoopCount++)),i.multi?l.attachMulti():l.attach(),n?i._undirectedSize++:i._directedSize++,c.key=r,i.emit("edgeAdded",c),r}function $n(i,e,t,n,r,o,s,u,h){if(!n&&i.type==="undirected")throw new $(`Graph.${e}: you cannot merge/update a directed edge to an undirected graph. Use the #.mergeEdge/#.updateEdge or #.addUndirectedEdge instead.`);if(n&&i.type==="directed")throw new $(`Graph.${e}: you cannot merge/update an undirected edge to a directed graph. Use the #.mergeEdge/#.updateEdge or #.addDirectedEdge instead.`);if(u){if(h){if(typeof u!="function")throw new G(`Graph.${e}: invalid updater function. Expecting a function but got "${u}"`)}else if(!q(u))throw new G(`Graph.${e}: invalid attributes. Expecting an object but got "${u}"`)}o=""+o,s=""+s;let a;if(h&&(a=u,u=void 0),!i.allowSelfLoops&&o===s)throw new $(`Graph.${e}: source & target are the same ("${o}"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.`);let c=i._nodes.get(o),l=i._nodes.get(s),y,v;if(!t&&(y=i._edges.get(r),y)){if((y.source.key!==o||y.target.key!==s)&&(!n||y.source.key!==s||y.target.key!==o))throw new $(`Graph.${e}: inconsistency detected when attempting to merge the "${r}" edge with "${o}" source & "${s}" target vs. ("${y.source.key}", "${y.target.key}").`);v=y}if(!v&&!i.multi&&c&&(v=n?c.undirected[s]:c.out[s]),v){const C=[v.key,!1,!1,!1];if(h?!a:!u)return C;if(h){const x=v.attributes;v.attributes=a(x),i.emit("edgeAttributesUpdated",{type:"replace",key:v.key,attributes:v.attributes})}else B(v.attributes,u),i.emit("edgeAttributesUpdated",{type:"merge",key:v.key,attributes:v.attributes,data:u});return C}u=u||{},h&&a&&(u=a(u));const U={key:null,undirected:n,source:o,target:s,attributes:u};if(t)r=i._edgeKeyGenerator();else if(r=""+r,i._edges.has(r))throw new $(`Graph.${e}: the "${r}" edge already exists in the graph.`);let O=!1,R=!1;c||(c=nt(i,o,{}),O=!0,o===s&&(l=c,R=!0)),l||(l=nt(i,s,{}),R=!0),y=new ae(n,r,c,l,u),i._edges.set(r,y);const j=o===s;return n?(c.undirectedDegree++,l.undirectedDegree++,j&&(c.undirectedLoops++,i._undirectedSelfLoopCount++)):(c.outDegree++,l.inDegree++,j&&(c.directedLoops++,i._directedSelfLoopCount++)),i.multi?y.attachMulti():y.attach(),n?i._undirectedSize++:i._directedSize++,U.key=r,i.emit("edgeAdded",U),[r,!0,O,R]}function he(i,e){i._edges.delete(e.key);const{source:t,target:n,attributes:r}=e,o=e.undirected,s=t===n;o?(t.undirectedDegree--,n.undirectedDegree--,s&&(t.undirectedLoops--,i._undirectedSelfLoopCount--)):(t.outDegree--,n.inDegree--,s&&(t.directedLoops--,i._directedSelfLoopCount--)),i.multi?e.detachMulti():e.detach(),o?i._undirectedSize--:i._directedSize--,i.emit("edgeDropped",{key:e.key,attributes:r,source:t.key,target:n.key,undirected:o})}class P extends bt.EventEmitter{constructor(e){if(super(),e=B({},Gn,e),typeof e.multi!="boolean")throw new G(`Graph.constructor: invalid 'multi' option. Expecting a boolean but got "${e.multi}".`);if(!vn.has(e.type))throw new G(`Graph.constructor: invalid 'type' option. Should be one of "mixed", "directed" or "undirected" but got "${e.type}".`);if(typeof e.allowSelfLoops!="boolean")throw new G(`Graph.constructor: invalid 'allowSelfLoops' option. Expecting a boolean but got "${e.allowSelfLoops}".`);const t=e.type==="mixed"?Ye:e.type==="directed"?Ze:Je;Y(this,"NodeDataClass",t);const n="geid_"+mn()+"_";let r=0;const o=()=>{let s;do s=n+r++;while(this._edges.has(s));return s};Y(this,"_attributes",{}),Y(this,"_nodes",new Map),Y(this,"_edges",new Map),Y(this,"_directedSize",0),Y(this,"_undirectedSize",0),Y(this,"_directedSelfLoopCount",0),Y(this,"_undirectedSelfLoopCount",0),Y(this,"_edgeKeyGenerator",o),Y(this,"_options",e),tt.forEach(s=>Y(this,s,this[s])),Q(this,"order",()=>this._nodes.size),Q(this,"size",()=>this._edges.size),Q(this,"directedSize",()=>this._directedSize),Q(this,"undirectedSize",()=>this._undirectedSize),Q(this,"selfLoopCount",()=>this._directedSelfLoopCount+this._undirectedSelfLoopCount),Q(this,"directedSelfLoopCount",()=>this._directedSelfLoopCount),Q(this,"undirectedSelfLoopCount",()=>this._undirectedSelfLoopCount),Q(this,"multi",this._options.multi),Q(this,"type",this._options.type),Q(this,"allowSelfLoops",this._options.allowSelfLoops),Q(this,"implementation",()=>"graphology")}_resetInstanceCounters(){this._directedSize=0,this._undirectedSize=0,this._directedSelfLoopCount=0,this._undirectedSelfLoopCount=0}hasNode(e){return this._nodes.has(""+e)}hasDirectedEdge(e,t){if(this.type==="undirected")return!1;if(arguments.length===1){const n=""+e,r=this._edges.get(n);return!!r&&!r.undirected}else if(arguments.length===2){e=""+e,t=""+t;const n=this._nodes.get(e);return n?n.out.hasOwnProperty(t):!1}throw new G(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasUndirectedEdge(e,t){if(this.type==="directed")return!1;if(arguments.length===1){const n=""+e,r=this._edges.get(n);return!!r&&r.undirected}else if(arguments.length===2){e=""+e,t=""+t;const n=this._nodes.get(e);return n?n.undirected.hasOwnProperty(t):!1}throw new G(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasEdge(e,t){if(arguments.length===1){const n=""+e;return this._edges.has(n)}else if(arguments.length===2){e=""+e,t=""+t;const n=this._nodes.get(e);return n?typeof n.out<"u"&&n.out.hasOwnProperty(t)||typeof n.undirected<"u"&&n.undirected.hasOwnProperty(t):!1}throw new G(`Graph.hasEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}directedEdge(e,t){if(this.type==="undirected")return;if(e=""+e,t=""+t,this.multi)throw new $("Graph.directedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.directedEdges instead.");const n=this._nodes.get(e);if(!n)throw new b(`Graph.directedEdge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(t))throw new b(`Graph.directedEdge: could not find the "${t}" target node in the graph.`);const r=n.out&&n.out[t]||void 0;if(r)return r.key}undirectedEdge(e,t){if(this.type==="directed")return;if(e=""+e,t=""+t,this.multi)throw new $("Graph.undirectedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.undirectedEdges instead.");const n=this._nodes.get(e);if(!n)throw new b(`Graph.undirectedEdge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(t))throw new b(`Graph.undirectedEdge: could not find the "${t}" target node in the graph.`);const r=n.undirected&&n.undirected[t]||void 0;if(r)return r.key}edge(e,t){if(this.multi)throw new $("Graph.edge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.edges instead.");e=""+e,t=""+t;const n=this._nodes.get(e);if(!n)throw new b(`Graph.edge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(t))throw new b(`Graph.edge: could not find the "${t}" target node in the graph.`);const r=n.out&&n.out[t]||n.undirected&&n.undirected[t]||void 0;if(r)return r.key}areDirectedNeighbors(e,t){e=""+e,t=""+t;const n=this._nodes.get(e);if(!n)throw new b(`Graph.areDirectedNeighbors: could not find the "${e}" node in the graph.`);return this.type==="undirected"?!1:t in n.in||t in n.out}areOutNeighbors(e,t){e=""+e,t=""+t;const n=this._nodes.get(e);if(!n)throw new b(`Graph.areOutNeighbors: could not find the "${e}" node in the graph.`);return this.type==="undirected"?!1:t in n.out}areInNeighbors(e,t){e=""+e,t=""+t;const n=this._nodes.get(e);if(!n)throw new b(`Graph.areInNeighbors: could not find the "${e}" node in the graph.`);return this.type==="undirected"?!1:t in n.in}areUndirectedNeighbors(e,t){e=""+e,t=""+t;const n=this._nodes.get(e);if(!n)throw new b(`Graph.areUndirectedNeighbors: could not find the "${e}" node in the graph.`);return this.type==="directed"?!1:t in n.undirected}areNeighbors(e,t){e=""+e,t=""+t;const n=this._nodes.get(e);if(!n)throw new b(`Graph.areNeighbors: could not find the "${e}" node in the graph.`);return this.type!=="undirected"&&(t in n.in||t in n.out)||this.type!=="directed"&&t in n.undirected}areInboundNeighbors(e,t){e=""+e,t=""+t;const n=this._nodes.get(e);if(!n)throw new b(`Graph.areInboundNeighbors: could not find the "${e}" node in the graph.`);return this.type!=="undirected"&&t in n.in||this.type!=="directed"&&t in n.undirected}areOutboundNeighbors(e,t){e=""+e,t=""+t;const n=this._nodes.get(e);if(!n)throw new b(`Graph.areOutboundNeighbors: could not find the "${e}" node in the graph.`);return this.type!=="undirected"&&t in n.out||this.type!=="directed"&&t in n.undirected}inDegree(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.inDegree: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:t.inDegree}outDegree(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.outDegree: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:t.outDegree}directedDegree(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.directedDegree: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:t.inDegree+t.outDegree}undirectedDegree(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.undirectedDegree: could not find the "${e}" node in the graph.`);return this.type==="directed"?0:t.undirectedDegree}inboundDegree(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.inboundDegree: could not find the "${e}" node in the graph.`);let n=0;return this.type!=="directed"&&(n+=t.undirectedDegree),this.type!=="undirected"&&(n+=t.inDegree),n}outboundDegree(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.outboundDegree: could not find the "${e}" node in the graph.`);let n=0;return this.type!=="directed"&&(n+=t.undirectedDegree),this.type!=="undirected"&&(n+=t.outDegree),n}degree(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.degree: could not find the "${e}" node in the graph.`);let n=0;return this.type!=="directed"&&(n+=t.undirectedDegree),this.type!=="undirected"&&(n+=t.inDegree+t.outDegree),n}inDegreeWithoutSelfLoops(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.inDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:t.inDegree-t.directedLoops}outDegreeWithoutSelfLoops(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.outDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:t.outDegree-t.directedLoops}directedDegreeWithoutSelfLoops(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.directedDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="undirected"?0:t.inDegree+t.outDegree-t.directedLoops*2}undirectedDegreeWithoutSelfLoops(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.undirectedDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type==="directed"?0:t.undirectedDegree-t.undirectedLoops*2}inboundDegreeWithoutSelfLoops(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.inboundDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let n=0,r=0;return this.type!=="directed"&&(n+=t.undirectedDegree,r+=t.undirectedLoops*2),this.type!=="undirected"&&(n+=t.inDegree,r+=t.directedLoops),n-r}outboundDegreeWithoutSelfLoops(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.outboundDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let n=0,r=0;return this.type!=="directed"&&(n+=t.undirectedDegree,r+=t.undirectedLoops*2),this.type!=="undirected"&&(n+=t.outDegree,r+=t.directedLoops),n-r}degreeWithoutSelfLoops(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.degreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let n=0,r=0;return this.type!=="directed"&&(n+=t.undirectedDegree,r+=t.undirectedLoops*2),this.type!=="undirected"&&(n+=t.inDegree+t.outDegree,r+=t.directedLoops*2),n-r}source(e){e=""+e;const t=this._edges.get(e);if(!t)throw new b(`Graph.source: could not find the "${e}" edge in the graph.`);return t.source.key}target(e){e=""+e;const t=this._edges.get(e);if(!t)throw new b(`Graph.target: could not find the "${e}" edge in the graph.`);return t.target.key}extremities(e){e=""+e;const t=this._edges.get(e);if(!t)throw new b(`Graph.extremities: could not find the "${e}" edge in the graph.`);return[t.source.key,t.target.key]}opposite(e,t){e=""+e,t=""+t;const n=this._edges.get(t);if(!n)throw new b(`Graph.opposite: could not find the "${t}" edge in the graph.`);const r=n.source.key,o=n.target.key;if(e===r)return o;if(e===o)return r;throw new b(`Graph.opposite: the "${e}" node is not attached to the "${t}" edge (${r}, ${o}).`)}hasExtremity(e,t){e=""+e,t=""+t;const n=this._edges.get(e);if(!n)throw new b(`Graph.hasExtremity: could not find the "${e}" edge in the graph.`);return n.source.key===t||n.target.key===t}isUndirected(e){e=""+e;const t=this._edges.get(e);if(!t)throw new b(`Graph.isUndirected: could not find the "${e}" edge in the graph.`);return t.undirected}isDirected(e){e=""+e;const t=this._edges.get(e);if(!t)throw new b(`Graph.isDirected: could not find the "${e}" edge in the graph.`);return!t.undirected}isSelfLoop(e){e=""+e;const t=this._edges.get(e);if(!t)throw new b(`Graph.isSelfLoop: could not find the "${e}" edge in the graph.`);return t.source===t.target}addNode(e,t){return _n(this,e,t).key}mergeNode(e,t){if(t&&!q(t))throw new G(`Graph.mergeNode: invalid attributes. Expecting an object but got "${t}"`);e=""+e,t=t||{};let n=this._nodes.get(e);return n?(t&&(B(n.attributes,t),this.emit("nodeAttributesUpdated",{type:"merge",key:e,attributes:n.attributes,data:t})),[e,!1]):(n=new this.NodeDataClass(e,t),this._nodes.set(e,n),this.emit("nodeAdded",{key:e,attributes:t}),[e,!0])}updateNode(e,t){if(t&&typeof t!="function")throw new G(`Graph.updateNode: invalid updater function. Expecting a function but got "${t}"`);e=""+e;let n=this._nodes.get(e);if(n){if(t){const o=n.attributes;n.attributes=t(o),this.emit("nodeAttributesUpdated",{type:"replace",key:e,attributes:n.attributes})}return[e,!1]}const r=t?t({}):{};return n=new this.NodeDataClass(e,r),this._nodes.set(e,n),this.emit("nodeAdded",{key:e,attributes:r}),[e,!0]}dropNode(e){e=""+e;const t=this._nodes.get(e);if(!t)throw new b(`Graph.dropNode: could not find the "${e}" node in the graph.`);let n;if(this.type!=="undirected"){for(const r in t.out){n=t.out[r];do he(this,n),n=n.next;while(n)}for(const r in t.in){n=t.in[r];do he(this,n),n=n.next;while(n)}}if(this.type!=="directed")for(const r in t.undirected){n=t.undirected[r];do he(this,n),n=n.next;while(n)}this._nodes.delete(e),this.emit("nodeDropped",{key:e,attributes:t.attributes})}dropEdge(e){let t;if(arguments.length>1){const n=""+arguments[0],r=""+arguments[1];if(t=V(this,n,r,this.type),!t)throw new b(`Graph.dropEdge: could not find the "${n}" -> "${r}" edge in the graph.`)}else if(e=""+e,t=this._edges.get(e),!t)throw new b(`Graph.dropEdge: could not find the "${e}" edge in the graph.`);return he(this,t),this}dropDirectedEdge(e,t){if(arguments.length<2)throw new $("Graph.dropDirectedEdge: it does not make sense to try and drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new $("Graph.dropDirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");e=""+e,t=""+t;const n=V(this,e,t,"directed");if(!n)throw new b(`Graph.dropDirectedEdge: could not find a "${e}" -> "${t}" edge in the graph.`);return he(this,n),this}dropUndirectedEdge(e,t){if(arguments.length<2)throw new $("Graph.dropUndirectedEdge: it does not make sense to drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new $("Graph.dropUndirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");const n=V(this,e,t,"undirected");if(!n)throw new b(`Graph.dropUndirectedEdge: could not find a "${e}" -> "${t}" edge in the graph.`);return he(this,n),this}clear(){this._edges.clear(),this._nodes.clear(),this._resetInstanceCounters(),this.emit("cleared")}clearEdges(){const e=this._nodes.values();let t;for(;t=e.next(),t.done!==!0;)t.value.clear();this._edges.clear(),this._resetInstanceCounters(),this.emit("edgesCleared")}getAttribute(e){return this._attributes[e]}getAttributes(){return this._attributes}hasAttribute(e){return this._attributes.hasOwnProperty(e)}setAttribute(e,t){return this._attributes[e]=t,this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:e}),this}updateAttribute(e,t){if(typeof t!="function")throw new G("Graph.updateAttribute: updater should be a function.");const n=this._attributes[e];return this._attributes[e]=t(n),this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:e}),this}removeAttribute(e){return delete this._attributes[e],this.emit("attributesUpdated",{type:"remove",attributes:this._attributes,name:e}),this}replaceAttributes(e){if(!q(e))throw new G("Graph.replaceAttributes: provided attributes are not a plain object.");return this._attributes=e,this.emit("attributesUpdated",{type:"replace",attributes:this._attributes}),this}mergeAttributes(e){if(!q(e))throw new G("Graph.mergeAttributes: provided attributes are not a plain object.");return B(this._attributes,e),this.emit("attributesUpdated",{type:"merge",attributes:this._attributes,data:e}),this}updateAttributes(e){if(typeof e!="function")throw new G("Graph.updateAttributes: provided updater is not a function.");return this._attributes=e(this._attributes),this.emit("attributesUpdated",{type:"update",attributes:this._attributes}),this}updateEachNodeAttributes(e,t){if(typeof e!="function")throw new G("Graph.updateEachNodeAttributes: expecting an updater function.");if(t&&!Ve(t))throw new G("Graph.updateEachNodeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");const n=this._nodes.values();let r,o;for(;r=n.next(),r.done!==!0;)o=r.value,o.attributes=e(o.key,o.attributes);this.emit("eachNodeAttributesUpdated",{hints:t||null})}updateEachEdgeAttributes(e,t){if(typeof e!="function")throw new G("Graph.updateEachEdgeAttributes: expecting an updater function.");if(t&&!Ve(t))throw new G("Graph.updateEachEdgeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");const n=this._edges.values();let r,o,s,u;for(;r=n.next(),r.done!==!0;)o=r.value,s=o.source,u=o.target,o.attributes=e(o.key,o.attributes,s.key,u.key,s.attributes,u.attributes,o.undirected);this.emit("eachEdgeAttributesUpdated",{hints:t||null})}forEachAdjacencyEntry(e){if(typeof e!="function")throw new G("Graph.forEachAdjacencyEntry: expecting a callback.");_e(!1,!1,!1,this,e)}forEachAdjacencyEntryWithOrphans(e){if(typeof e!="function")throw new G("Graph.forEachAdjacencyEntryWithOrphans: expecting a callback.");_e(!1,!1,!0,this,e)}forEachAssymetricAdjacencyEntry(e){if(typeof e!="function")throw new G("Graph.forEachAssymetricAdjacencyEntry: expecting a callback.");_e(!1,!0,!1,this,e)}forEachAssymetricAdjacencyEntryWithOrphans(e){if(typeof e!="function")throw new G("Graph.forEachAssymetricAdjacencyEntryWithOrphans: expecting a callback.");_e(!1,!0,!0,this,e)}nodes(){return Array.from(this._nodes.keys())}forEachNode(e){if(typeof e!="function")throw new G("Graph.forEachNode: expecting a callback.");const t=this._nodes.values();let n,r;for(;n=t.next(),n.done!==!0;)r=n.value,e(r.key,r.attributes)}findNode(e){if(typeof e!="function")throw new G("Graph.findNode: expecting a callback.");const t=this._nodes.values();let n,r;for(;n=t.next(),n.done!==!0;)if(r=n.value,e(r.key,r.attributes))return r.key}mapNodes(e){if(typeof e!="function")throw new G("Graph.mapNode: expecting a callback.");const t=this._nodes.values();let n,r;const o=new Array(this.order);let s=0;for(;n=t.next(),n.done!==!0;)r=n.value,o[s++]=e(r.key,r.attributes);return o}someNode(e){if(typeof e!="function")throw new G("Graph.someNode: expecting a callback.");const t=this._nodes.values();let n,r;for(;n=t.next(),n.done!==!0;)if(r=n.value,e(r.key,r.attributes))return!0;return!1}everyNode(e){if(typeof e!="function")throw new G("Graph.everyNode: expecting a callback.");const t=this._nodes.values();let n,r;for(;n=t.next(),n.done!==!0;)if(r=n.value,!e(r.key,r.attributes))return!1;return!0}filterNodes(e){if(typeof e!="function")throw new G("Graph.filterNodes: expecting a callback.");const t=this._nodes.values();let n,r;const o=[];for(;n=t.next(),n.done!==!0;)r=n.value,e(r.key,r.attributes)&&o.push(r.key);return o}reduceNodes(e,t){if(typeof e!="function")throw new G("Graph.reduceNodes: expecting a callback.");if(arguments.length<2)throw new G("Graph.reduceNodes: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.");let n=t;const r=this._nodes.values();let o,s;for(;o=r.next(),o.done!==!0;)s=o.value,n=e(n,s.key,s.attributes);return n}nodeEntries(){const e=this._nodes.values();return{[Symbol.iterator](){return this},next(){const t=e.next();if(t.done)return t;const n=t.value;return{value:{node:n.key,attributes:n.attributes},done:!1}}}}export(){const e=new Array(this._nodes.size);let t=0;this._nodes.forEach((r,o)=>{e[t++]=gn(o,r)});const n=new Array(this._edges.size);return t=0,this._edges.forEach((r,o)=>{n[t++]=yn(this.type,o,r)}),{options:{type:this.type,multi:this.multi,allowSelfLoops:this.allowSelfLoops},attributes:this.getAttributes(),nodes:e,edges:n}}import(e,t=!1){if(e instanceof P)return e.forEachNode((h,a)=>{t?this.mergeNode(h,a):this.addNode(h,a)}),e.forEachEdge((h,a,c,l,y,v,U)=>{t?U?this.mergeUndirectedEdgeWithKey(h,c,l,a):this.mergeDirectedEdgeWithKey(h,c,l,a):U?this.addUndirectedEdgeWithKey(h,c,l,a):this.addDirectedEdgeWithKey(h,c,l,a)}),this;if(!q(e))throw new G("Graph.import: invalid argument. Expecting a serialized graph or, alternatively, a Graph instance.");if(e.attributes){if(!q(e.attributes))throw new G("Graph.import: invalid attributes. Expecting a plain object.");t?this.mergeAttributes(e.attributes):this.replaceAttributes(e.attributes)}let n,r,o,s,u;if(e.nodes){if(o=e.nodes,!Array.isArray(o))throw new G("Graph.import: invalid nodes. Expecting an array.");for(n=0,r=o.length;n<r;n++){s=o[n],wn(s);const{key:h,attributes:a}=s;t?this.mergeNode(h,a):this.addNode(h,a)}}if(e.edges){let h=!1;if(this.type==="undirected"&&(h=!0),o=e.edges,!Array.isArray(o))throw new G("Graph.import: invalid edges. Expecting an array.");for(n=0,r=o.length;n<r;n++){u=o[n],bn(u);const{source:a,target:c,attributes:l,undirected:y=h}=u;let v;"key"in u?(v=t?y?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:y?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey,v.call(this,u.key,a,c,l)):(v=t?y?this.mergeUndirectedEdge:this.mergeDirectedEdge:y?this.addUndirectedEdge:this.addDirectedEdge,v.call(this,a,c,l))}}return this}nullCopy(e){const t=new P(B({},this._options,e));return t.replaceAttributes(B({},this.getAttributes())),t}emptyCopy(e){const t=this.nullCopy(e);return this._nodes.forEach((n,r)=>{const o=B({},n.attributes);n=new t.NodeDataClass(r,o),t._nodes.set(r,n)}),t}copy(e){if(e=e||{},typeof e.type=="string"&&e.type!==this.type&&e.type!=="mixed")throw new $(`Graph.copy: cannot create an incompatible copy from "${this.type}" type to "${e.type}" because this would mean losing information about the current graph.`);if(typeof e.multi=="boolean"&&e.multi!==this.multi&&e.multi!==!0)throw new $("Graph.copy: cannot create an incompatible copy by downgrading a multi graph to a simple one because this would mean losing information about the current graph.");if(typeof e.allowSelfLoops=="boolean"&&e.allowSelfLoops!==this.allowSelfLoops&&e.allowSelfLoops!==!0)throw new $("Graph.copy: cannot create an incompatible copy from a graph allowing self loops to one that does not because this would mean losing information about the current graph.");const t=this.emptyCopy(e),n=this._edges.values();let r,o;for(;r=n.next(),r.done!==!0;)o=r.value,it(t,"copy",!1,o.undirected,o.key,o.source.key,o.target.key,B({},o.attributes));return t}toJSON(){return this.export()}toString(){return"[object Graph]"}inspect(){const e={};this._nodes.forEach((o,s)=>{e[s]=o.attributes});const t={},n={};this._edges.forEach((o,s)=>{const u=o.undirected?"--":"->";let h="",a=o.source.key,c=o.target.key,l;o.undirected&&a>c&&(l=a,a=c,c=l);const y=`(${a})${u}(${c})`;s.startsWith("geid_")?this.multi&&(typeof n[y]>"u"?n[y]=0:n[y]++,h+=`${n[y]}. `):h+=`[${s}]: `,h+=y,t[h]=o.attributes});const r={};for(const o in this)this.hasOwnProperty(o)&&!tt.has(o)&&typeof this[o]!="function"&&typeof o!="symbol"&&(r[o]=this[o]);return r.attributes=this._attributes,r.nodes=e,r.edges=t,Y(r,"constructor",this.constructor),r}}typeof Symbol<"u"&&(P.prototype[Symbol.for("nodejs.util.inspect.custom")]=P.prototype.inspect),En.forEach(i=>{["add","merge","update"].forEach(e=>{const t=i.name(e),n=e==="add"?it:$n;i.generateKey?P.prototype[t]=function(r,o,s){return n(this,t,!0,(i.type||this.type)==="undirected",null,r,o,s,e==="update")}:P.prototype[t]=function(r,o,s,u){return n(this,t,!1,(i.type||this.type)==="undirected",r,o,s,u,e==="update")}})}),It(P),Ht(P),sn(P),pn(P);class rt extends P{constructor(e){const t=B({type:"directed"},e);if("multi"in t&&t.multi!==!1)throw new G("DirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if(t.type!=="directed")throw new G('DirectedGraph.from: inconsistent "'+t.type+'" type in given options!');super(t)}}class ot extends P{constructor(e){const t=B({type:"undirected"},e);if("multi"in t&&t.multi!==!1)throw new G("UndirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if(t.type!=="undirected")throw new G('UndirectedGraph.from: inconsistent "'+t.type+'" type in given options!');super(t)}}class st extends P{constructor(e){const t=B({multi:!0},e);if("multi"in t&&t.multi!==!0)throw new G("MultiGraph.from: inconsistent indication that the graph should be simple in given options!");super(t)}}class ut extends P{constructor(e){const t=B({type:"directed",multi:!0},e);if("multi"in t&&t.multi!==!0)throw new G("MultiDirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if(t.type!=="directed")throw new G('MultiDirectedGraph.from: inconsistent "'+t.type+'" type in given options!');super(t)}}class at extends P{constructor(e){const t=B({type:"undirected",multi:!0},e);if("multi"in t&&t.multi!==!0)throw new G("MultiUndirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if(t.type!=="undirected")throw new G('MultiUndirectedGraph.from: inconsistent "'+t.type+'" type in given options!');super(t)}}function de(i){i.from=function(e,t){const n=B({},e.options,t),r=new i(n);return r.import(e),r}}de(P),de(rt),de(ot),de(st),de(ut),de(at),P.Graph=P,P.DirectedGraph=rt,P.UndirectedGraph=ot,P.MultiGraph=st,P.MultiDirectedGraph=ut,P.MultiUndirectedGraph=at,P.InvalidArgumentsGraphError=G,P.NotFoundGraphError=b,P.UsageGraphError=$;var Te,ht;function Dn(){return ht||(ht=1,Te=function(e){return e!==null&&typeof e=="object"&&typeof e.addUndirectedEdgeWithKey=="function"&&typeof e.dropNode=="function"&&typeof e.multi=="boolean"}),Te}var be={},dt;function kn(){if(dt)return be;dt=1;function i(n){return typeof n!="number"||isNaN(n)?1:n}function e(n,r){var o={},s=function(a){return typeof a>"u"?r:a};typeof r=="function"&&(s=r);var u=function(a){return s(a[n])},h=function(){return s(void 0)};return typeof n=="string"?(o.fromAttributes=u,o.fromGraph=function(a,c){return u(a.getNodeAttributes(c))},o.fromEntry=function(a,c){return u(c)}):typeof n=="function"?(o.fromAttributes=function(){throw new Error("graphology-utils/getters/createNodeValueGetter: irrelevant usage.")},o.fromGraph=function(a,c){return s(n(c,a.getNodeAttributes(c)))},o.fromEntry=function(a,c){return s(n(a,c))}):(o.fromAttributes=h,o.fromGraph=h,o.fromEntry=h),o}function t(n,r){var o={},s=function(a){return typeof a>"u"?r:a};typeof r=="function"&&(s=r);var u=function(a){return s(a[n])},h=function(){return s(void 0)};return typeof n=="string"?(o.fromAttributes=u,o.fromGraph=function(a,c){return u(a.getEdgeAttributes(c))},o.fromEntry=function(a,c){return u(c)},o.fromPartialEntry=o.fromEntry,o.fromMinimalEntry=o.fromEntry):typeof n=="function"?(o.fromAttributes=function(){throw new Error("graphology-utils/getters/createEdgeValueGetter: irrelevant usage.")},o.fromGraph=function(a,c){var l=a.extremities(c);return s(n(c,a.getEdgeAttributes(c),l[0],l[1],a.getNodeAttributes(l[0]),a.getNodeAttributes(l[1]),a.isUndirected(c)))},o.fromEntry=function(a,c,l,y,v,U,O){return s(n(a,c,l,y,v,U,O))},o.fromPartialEntry=function(a,c,l,y){return s(n(a,c,l,y))},o.fromMinimalEntry=function(a,c){return s(n(a,c))}):(o.fromAttributes=h,o.fromGraph=h,o.fromEntry=h,o.fromMinimalEntry=h),o}return be.createNodeValueGetter=e,be.createEdgeValueGetter=t,be.createEdgeWeightGetter=function(n){return t(n,i)},be}var We,ct;function An(){if(ct)return We;ct=1;var i=0,e=1,t=2,n=3,r=4,o=5,s=6,u=7,h=8,a=9,c=0,l=1,y=2,v=0,U=1,O=2,R=3,j=4,C=5,x=6,w=7,g=8,E=3,_=10,L=3,S=9,I=10;return We=function(z,d,ce){var Fe,m,f,K,H,ie,fe,N,A,He,X=d.length,Rn=ce.length,me=z.adjustSizes,jn=z.barnesHutTheta*z.barnesHutTheta,$e,F,T,W,ne,k,D,p=[];for(f=0;f<X;f+=_)d[f+r]=d[f+t],d[f+o]=d[f+n],d[f+t]=0,d[f+n]=0;if(z.outboundAttractionDistribution){for($e=0,f=0;f<X;f+=_)$e+=d[f+s];$e/=X/_}if(z.barnesHutOptimize){var re=1/0,le=-1/0,oe=1/0,pe=-1/0,J,ge,Be;for(f=0;f<X;f+=_)re=Math.min(re,d[f+i]),le=Math.max(le,d[f+i]),oe=Math.min(oe,d[f+e]),pe=Math.max(pe,d[f+e]);var De=le-re,ke=pe-oe;for(De>ke?(oe-=(De-ke)/2,pe=oe+De):(re-=(ke-De)/2,le=re+ke),p[0+v]=-1,p[0+U]=(re+le)/2,p[0+O]=(oe+pe)/2,p[0+R]=Math.max(le-re,pe-oe),p[0+j]=-1,p[0+C]=-1,p[0+x]=0,p[0+w]=0,p[0+g]=0,Fe=1,f=0;f<X;f+=_)for(m=0,Be=E;;)if(p[m+C]>=0){d[f+i]<p[m+U]?d[f+e]<p[m+O]?J=p[m+C]:J=p[m+C]+S:d[f+e]<p[m+O]?J=p[m+C]+S*2:J=p[m+C]+S*3,p[m+w]=(p[m+w]*p[m+x]+d[f+i]*d[f+s])/(p[m+x]+d[f+s]),p[m+g]=(p[m+g]*p[m+x]+d[f+e]*d[f+s])/(p[m+x]+d[f+s]),p[m+x]+=d[f+s],m=J;continue}else if(p[m+v]<0){p[m+v]=f;break}else{if(p[m+C]=Fe*S,N=p[m+R]/2,A=p[m+C],p[A+v]=-1,p[A+U]=p[m+U]-N,p[A+O]=p[m+O]-N,p[A+R]=N,p[A+j]=A+S,p[A+C]=-1,p[A+x]=0,p[A+w]=0,p[A+g]=0,A+=S,p[A+v]=-1,p[A+U]=p[m+U]-N,p[A+O]=p[m+O]+N,p[A+R]=N,p[A+j]=A+S,p[A+C]=-1,p[A+x]=0,p[A+w]=0,p[A+g]=0,A+=S,p[A+v]=-1,p[A+U]=p[m+U]+N,p[A+O]=p[m+O]-N,p[A+R]=N,p[A+j]=A+S,p[A+C]=-1,p[A+x]=0,p[A+w]=0,p[A+g]=0,A+=S,p[A+v]=-1,p[A+U]=p[m+U]+N,p[A+O]=p[m+O]+N,p[A+R]=N,p[A+j]=p[m+j],p[A+C]=-1,p[A+x]=0,p[A+w]=0,p[A+g]=0,Fe+=4,d[p[m+v]+i]<p[m+U]?d[p[m+v]+e]<p[m+O]?J=p[m+C]:J=p[m+C]+S:d[p[m+v]+e]<p[m+O]?J=p[m+C]+S*2:J=p[m+C]+S*3,p[m+x]=d[p[m+v]+s],p[m+w]=d[p[m+v]+i],p[m+g]=d[p[m+v]+e],p[J+v]=p[m+v],p[m+v]=-1,d[f+i]<p[m+U]?d[f+e]<p[m+O]?ge=p[m+C]:ge=p[m+C]+S:d[f+e]<p[m+O]?ge=p[m+C]+S*2:ge=p[m+C]+S*3,J===ge)if(Be--){m=J;continue}else{Be=E;break}p[ge+v]=f;break}}if(z.barnesHutOptimize)for(F=z.scalingRatio,f=0;f<X;f+=_)for(m=0;;)if(p[m+C]>=0)if(k=Math.pow(d[f+i]-p[m+w],2)+Math.pow(d[f+e]-p[m+g],2),He=p[m+R],4*He*He/k<jn){if(T=d[f+i]-p[m+w],W=d[f+e]-p[m+g],me===!0?k>0?(D=F*d[f+s]*p[m+x]/k,d[f+t]+=T*D,d[f+n]+=W*D):k<0&&(D=-F*d[f+s]*p[m+x]/Math.sqrt(k),d[f+t]+=T*D,d[f+n]+=W*D):k>0&&(D=F*d[f+s]*p[m+x]/k,d[f+t]+=T*D,d[f+n]+=W*D),m=p[m+j],m<0)break;continue}else{m=p[m+C];continue}else{if(ie=p[m+v],ie>=0&&ie!==f&&(T=d[f+i]-d[ie+i],W=d[f+e]-d[ie+e],k=T*T+W*W,me===!0?k>0?(D=F*d[f+s]*d[ie+s]/k,d[f+t]+=T*D,d[f+n]+=W*D):k<0&&(D=-F*d[f+s]*d[ie+s]/Math.sqrt(k),d[f+t]+=T*D,d[f+n]+=W*D):k>0&&(D=F*d[f+s]*d[ie+s]/k,d[f+t]+=T*D,d[f+n]+=W*D)),m=p[m+j],m<0)break;continue}else for(F=z.scalingRatio,K=0;K<X;K+=_)for(H=0;H<K;H+=_)T=d[K+i]-d[H+i],W=d[K+e]-d[H+e],me===!0?(k=Math.sqrt(T*T+W*W)-d[K+h]-d[H+h],k>0?(D=F*d[K+s]*d[H+s]/k/k,d[K+t]+=T*D,d[K+n]+=W*D,d[H+t]-=T*D,d[H+n]-=W*D):k<0&&(D=100*F*d[K+s]*d[H+s],d[K+t]+=T*D,d[K+n]+=W*D,d[H+t]-=T*D,d[H+n]-=W*D)):(k=Math.sqrt(T*T+W*W),k>0&&(D=F*d[K+s]*d[H+s]/k/k,d[K+t]+=T*D,d[K+n]+=W*D,d[H+t]-=T*D,d[H+n]-=W*D));for(A=z.gravity/z.scalingRatio,F=z.scalingRatio,f=0;f<X;f+=_)D=0,T=d[f+i],W=d[f+e],k=Math.sqrt(Math.pow(T,2)+Math.pow(W,2)),z.strongGravityMode?k>0&&(D=F*d[f+s]*A):k>0&&(D=F*d[f+s]*A/k),d[f+t]-=T*D,d[f+n]-=W*D;for(F=1*(z.outboundAttractionDistribution?$e:1),fe=0;fe<Rn;fe+=L)K=ce[fe+c],H=ce[fe+l],N=ce[fe+y],ne=Math.pow(N,z.edgeWeightInfluence),T=d[K+i]-d[H+i],W=d[K+e]-d[H+e],me===!0?(k=Math.sqrt(T*T+W*W)-d[K+h]-d[H+h],z.linLogMode?z.outboundAttractionDistribution?k>0&&(D=-F*ne*Math.log(1+k)/k/d[K+s]):k>0&&(D=-F*ne*Math.log(1+k)/k):z.outboundAttractionDistribution?k>0&&(D=-F*ne/d[K+s]):k>0&&(D=-F*ne)):(k=Math.sqrt(Math.pow(T,2)+Math.pow(W,2)),z.linLogMode?z.outboundAttractionDistribution?k>0&&(D=-F*ne*Math.log(1+k)/k/d[K+s]):k>0&&(D=-F*ne*Math.log(1+k)/k):z.outboundAttractionDistribution?(k=1,D=-F*ne/d[K+s]):(k=1,D=-F*ne)),k>0&&(d[K+t]+=T*D,d[K+n]+=W*D,d[H+t]-=T*D,d[H+n]-=W*D);var Ae,ve,Le,se,Se,Ue;if(me===!0)for(f=0;f<X;f+=_)d[f+a]!==1&&(Ae=Math.sqrt(Math.pow(d[f+t],2)+Math.pow(d[f+n],2)),Ae>I&&(d[f+t]=d[f+t]*I/Ae,d[f+n]=d[f+n]*I/Ae),ve=d[f+s]*Math.sqrt((d[f+r]-d[f+t])*(d[f+r]-d[f+t])+(d[f+o]-d[f+n])*(d[f+o]-d[f+n])),Le=Math.sqrt((d[f+r]+d[f+t])*(d[f+r]+d[f+t])+(d[f+o]+d[f+n])*(d[f+o]+d[f+n]))/2,se=.1*Math.log(1+Le)/(1+Math.sqrt(ve)),Se=d[f+i]+d[f+t]*(se/z.slowDown),d[f+i]=Se,Ue=d[f+e]+d[f+n]*(se/z.slowDown),d[f+e]=Ue);else for(f=0;f<X;f+=_)d[f+a]!==1&&(ve=d[f+s]*Math.sqrt((d[f+r]-d[f+t])*(d[f+r]-d[f+t])+(d[f+o]-d[f+n])*(d[f+o]-d[f+n])),Le=Math.sqrt((d[f+r]+d[f+t])*(d[f+r]+d[f+t])+(d[f+o]+d[f+n])*(d[f+o]+d[f+n]))/2,se=d[f+u]*Math.log(1+Le)/(1+Math.sqrt(ve)),d[f+u]=Math.min(1,Math.sqrt(se*(Math.pow(d[f+t],2)+Math.pow(d[f+n],2))/(1+Math.sqrt(ve)))),Se=d[f+i]+d[f+t]*(se/z.slowDown),d[f+i]=Se,Ue=d[f+e]+d[f+n]*(se/z.slowDown),d[f+e]=Ue);return{}},We}var te={},ft;function Ln(){if(ft)return te;ft=1;var i=10,e=3;return te.assign=function(t){t=t||{};var n=Array.prototype.slice.call(arguments).slice(1),r,o,s;for(r=0,s=n.length;r<s;r++)if(n[r])for(o in n[r])t[o]=n[r][o];return t},te.validateSettings=function(t){return"linLogMode"in t&&typeof t.linLogMode!="boolean"?{message:"the `linLogMode` setting should be a boolean."}:"outboundAttractionDistribution"in t&&typeof t.outboundAttractionDistribution!="boolean"?{message:"the `outboundAttractionDistribution` setting should be a boolean."}:"adjustSizes"in t&&typeof t.adjustSizes!="boolean"?{message:"the `adjustSizes` setting should be a boolean."}:"edgeWeightInfluence"in t&&typeof t.edgeWeightInfluence!="number"?{message:"the `edgeWeightInfluence` setting should be a number."}:"scalingRatio"in t&&!(typeof t.scalingRatio=="number"&&t.scalingRatio>=0)?{message:"the `scalingRatio` setting should be a number >= 0."}:"strongGravityMode"in t&&typeof t.strongGravityMode!="boolean"?{message:"the `strongGravityMode` setting should be a boolean."}:"gravity"in t&&!(typeof t.gravity=="number"&&t.gravity>=0)?{message:"the `gravity` setting should be a number >= 0."}:"slowDown"in t&&!(typeof t.slowDown=="number"||t.slowDown>=0)?{message:"the `slowDown` setting should be a number >= 0."}:"barnesHutOptimize"in t&&typeof t.barnesHutOptimize!="boolean"?{message:"the `barnesHutOptimize` setting should be a boolean."}:"barnesHutTheta"in t&&!(typeof t.barnesHutTheta=="number"&&t.barnesHutTheta>=0)?{message:"the `barnesHutTheta` setting should be a number >= 0."}:null},te.graphToByteArrays=function(t,n){var r=t.order,o=t.size,s={},u,h=new Float32Array(r*i),a=new Float32Array(o*e);return u=0,t.forEachNode(function(c,l){s[c]=u,h[u]=l.x,h[u+1]=l.y,h[u+2]=0,h[u+3]=0,h[u+4]=0,h[u+5]=0,h[u+6]=1,h[u+7]=1,h[u+8]=l.size||1,h[u+9]=l.fixed?1:0,u+=i}),u=0,t.forEachEdge(function(c,l,y,v,U,O,R){var j=s[y],C=s[v],x=n(c,l,y,v,U,O,R);h[j+6]+=x,h[C+6]+=x,a[u]=j,a[u+1]=C,a[u+2]=x,u+=e}),{nodes:h,edges:a}},te.assignLayoutChanges=function(t,n,r){var o=0;t.updateEachNodeAttributes(function(s,u){return u.x=n[o],u.y=n[o+1],o+=i,r?r(s,u):u})},te.readGraphPositions=function(t,n){var r=0;t.forEachNode(function(o,s){n[r]=s.x,n[r+1]=s.y,r+=i})},te.collectLayoutChanges=function(t,n,r){for(var o=t.nodes(),s={},u=0,h=0,a=n.length;u<a;u+=i){if(r){var c=Object.assign({},t.getNodeAttributes(o[h]));c.x=n[u],c.y=n[u+1],c=r(o[h],c),s[o[h]]={x:c.x,y:c.y}}else s[o[h]]={x:n[u],y:n[u+1]};h++}return s},te.createWorker=function(n){var r=window.URL||window.webkitURL,o=n.toString(),s=r.createObjectURL(new Blob(["("+o+").call(this);"],{type:"text/javascript"})),u=new Worker(s);return r.revokeObjectURL(s),u},te}var Pe,lt;function Sn(){return lt||(lt=1,Pe={linLogMode:!1,outboundAttractionDistribution:!1,adjustSizes:!1,edgeWeightInfluence:1,scalingRatio:1,strongGravityMode:!1,gravity:1,slowDown:1,barnesHutOptimize:!1,barnesHutTheta:.5}),Pe}var xe,pt;function Un(){if(pt)return xe;pt=1;var i=Dn(),e=kn().createEdgeWeightGetter,t=An(),n=Ln(),r=Sn();function o(h,a,c){if(!i(a))throw new Error("graphology-layout-forceatlas2: the given graph is not a valid graphology instance.");typeof c=="number"&&(c={iterations:c});var l=c.iterations;if(typeof l!="number")throw new Error("graphology-layout-forceatlas2: invalid number of iterations.");if(l<=0)throw new Error("graphology-layout-forceatlas2: you should provide a positive number of iterations.");var y=e("getEdgeWeight"in c?c.getEdgeWeight:"weight").fromEntry,v=typeof c.outputReducer=="function"?c.outputReducer:null,U=n.assign({},r,c.settings),O=n.validateSettings(U);if(O)throw new Error("graphology-layout-forceatlas2: "+O.message);var R=n.graphToByteArrays(a,y),j;for(j=0;j<l;j++)t(U,R.nodes,R.edges);if(h){n.assignLayoutChanges(a,R.nodes,v);return}return n.collectLayoutChanges(a,R.nodes)}function s(h){var a=typeof h=="number"?h:h.order;return{barnesHutOptimize:a>2e3,strongGravityMode:!0,gravity:.05,scalingRatio:10,slowDown:1+Math.log(a)}}var u=o.bind(null,!1);return u.assign=o.bind(null,!0),u.inferSettings=s,xe=u,xe}var On=Un(),gt=yt(On);const In=12;let Ke=!1;self.onmessage=i=>{const e=i.data;if(e.type==="stop"){Ke=!0;return}e.type==="start"&&(Ke=!1,Cn(e))};function Cn(i){const e=new P({type:"undirected",multi:!1});for(const h of i.nodes)e.addNode(h.id,{x:h.x,y:h.y,size:1+Math.sqrt(h.degree)});for(const h of i.edges)!e.hasNode(h.source)||!e.hasNode(h.target)||h.source!==h.target&&(e.hasEdge(h.source,h.target)||e.addUndirectedEdge(h.source,h.target,{weight:h.weight}));const t=e.order;if(t===0){self.postMessage({type:"done"});return}const r={...gt.inferSettings(e),outboundAttractionDistribution:!0,gravity:.12,scalingRatio:50,adjustSizes:!1,edgeWeightInfluence:1,barnesHutOptimize:t>500},o=e.nodes();self.postMessage({type:"order",ids:o});let s=0;const u=()=>{if(Ke)return;const h=Math.min(In,i.iterations-s);gt.assign(e,{iterations:h,settings:r}),s+=h;const a=new Float32Array(o.length*2);for(let c=0;c<o.length;c++){const l=e.getNodeAttributes(o[c]);a[c*2]=l.x,a[c*2+1]=l.y}if(self.postMessage({type:"positions",coords:a},[a.buffer]),s>=i.iterations){self.postMessage({type:"done"});return}setTimeout(u,0)};u()}})();
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file