UNPKG

three-forcegraph

Version:
2 lines 110 kB
// Version 1.43.0 three-forcegraph - https://github.com/vasturiano/three-forcegraph !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("three")):"function"==typeof define&&define.amd?define(["three"],n):(t="undefined"!=typeof globalThis?globalThis:t||self).ThreeForceGraph=n(t.THREE)}(this,function(t){"use strict";function n(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=Array(n);e<n;e++)r[e]=t[e];return r}function e(t,n,e){if("function"==typeof t?t===n:t.has(n))return arguments.length<3?n:e;throw new TypeError("Private element is not present on this object")}function r(t,n,e){return n=h(n),function(t,n){if(n&&("object"==typeof n||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,p()?Reflect.construct(n,e||[],h(t).constructor):n.apply(t,e))}function i(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function o(t,n){return t.get(e(t,n))}function a(t,n,e){(function(t,n){if(n.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")})(t,n),n.set(t,e)}function u(t,n,r){return t.set(e(t,n),r),r}function s(t,n,e){if(p())return Reflect.construct.apply(null,arguments);var r=[null];return r.push.apply(r,n),new(t.bind.apply(t,r))}function f(t,n,e){return n&&function(t,n){for(var e=0;e<n.length;e++){var r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,_(r.key),r)}}(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function l(t,n,e){return(n=_(n))in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}function c(){return c="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,n,e){var r=function(t,n){for(;!{}.hasOwnProperty.call(t,n)&&null!==(t=h(t)););return t}(t,n);if(r){var i=Object.getOwnPropertyDescriptor(r,n);return i.get?i.get.call(arguments.length<3?t:e):i.value}},c.apply(null,arguments)}function h(t){return h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},h(t)}function d(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),n&&v(t,n)}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(p=function(){return!!t})()}function g(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),e.push.apply(e,r)}return e}function v(t,n){return v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},v(t,n)}function y(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var r,i,o,a,u=[],s=!0,f=!1;try{if(o=(e=e.call(t)).next,0===n);else for(;!(s=(r=o.call(e)).done)&&(u.push(r.value),u.length!==n);s=!0);}catch(t){f=!0,i=t}finally{try{if(!s&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(f)throw i}}return u}}(t,n)||w(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(t,n,e,r){var i=c(h(t.prototype),n,e);return"function"==typeof i?function(t){return i.apply(e,t)}:i}function m(t){return function(t){if(Array.isArray(t))return n(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||w(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function _(t){var n=function(t,n){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,n);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"==typeof n?n:n+""}function x(t){return x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},x(t)}function w(t,e){if(t){if("string"==typeof t)return n(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}function k(t,n,e){var r,i=1;function o(){var o,a,u=r.length,s=0,f=0,l=0;for(o=0;o<u;++o)s+=(a=r[o]).x||0,f+=a.y||0,l+=a.z||0;for(s=(s/u-t)*i,f=(f/u-n)*i,l=(l/u-e)*i,o=0;o<u;++o)a=r[o],s&&(a.x-=s),f&&(a.y-=f),l&&(a.z-=l)}return null==t&&(t=0),null==n&&(n=0),null==e&&(e=0),o.initialize=function(t){r=t},o.x=function(n){return arguments.length?(t=+n,o):t},o.y=function(t){return arguments.length?(n=+t,o):n},o.z=function(t){return arguments.length?(e=+t,o):e},o.strength=function(t){return arguments.length?(i=+t,o):i},o}function M(t,n,e){if(isNaN(n))return t;var r,i,o,a,u,s,f=t._root,l={data:e},c=t._x0,h=t._x1;if(!f)return t._root=l,t;for(;f.length;)if((a=n>=(i=(c+h)/2))?c=i:h=i,r=f,!(f=f[u=+a]))return r[u]=l,t;if(n===(o=+t._x.call(null,f.data)))return l.next=f,r?r[u]=l:t._root=l,t;do{r=r?r[u]=new Array(2):t._root=new Array(2),(a=n>=(i=(c+h)/2))?c=i:h=i}while((u=+a)===(s=+(o>=i)));return r[s]=f,r[u]=l,t}function A(t,n,e){this.node=t,this.x0=n,this.x1=e}function O(t){return t[0]}function j(t,n){var e=new N(null==n?O:n,NaN,NaN);return null==t?e:e.addAll(t)}function N(t,n,e){this._x=t,this._x0=n,this._x1=e,this._root=void 0}function P(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}var S=j.prototype=N.prototype;function C(t,n,e,r){if(isNaN(n)||isNaN(e))return t;var i,o,a,u,s,f,l,c,h,d=t._root,p={data:r},g=t._x0,v=t._y0,y=t._x1,b=t._y1;if(!d)return t._root=p,t;for(;d.length;)if((f=n>=(o=(g+y)/2))?g=o:y=o,(l=e>=(a=(v+b)/2))?v=a:b=a,i=d,!(d=d[c=l<<1|f]))return i[c]=p,t;if(u=+t._x.call(null,d.data),s=+t._y.call(null,d.data),n===u&&e===s)return p.next=d,i?i[c]=p:t._root=p,t;do{i=i?i[c]=new Array(4):t._root=new Array(4),(f=n>=(o=(g+y)/2))?g=o:y=o,(l=e>=(a=(v+b)/2))?v=a:b=a}while((c=l<<1|f)==(h=(s>=a)<<1|u>=o));return i[h]=d,i[c]=p,t}function z(t,n,e,r,i){this.node=t,this.x0=n,this.y0=e,this.x1=r,this.y1=i}function E(t){return t[0]}function B(t){return t[1]}function T(t,n,e){var r=new D(null==n?E:n,null==e?B:e,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function D(t,n,e,r,i,o){this._x=t,this._y=n,this._x0=e,this._y0=r,this._x1=i,this._y1=o,this._root=void 0}function $(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}S.copy=function(){var t,n,e=new N(this._x,this._x0,this._x1),r=this._root;if(!r)return e;if(!r.length)return e._root=P(r),e;for(t=[{source:r,target:e._root=new Array(2)}];r=t.pop();)for(var i=0;i<2;++i)(n=r.source[i])&&(n.length?t.push({source:n,target:r.target[i]=new Array(2)}):r.target[i]=P(n));return e},S.add=function(t){const n=+this._x.call(null,t);return M(this.cover(n),n,t)},S.addAll=function(t){Array.isArray(t)||(t=Array.from(t));const n=t.length,e=new Float64Array(n);let r=1/0,i=-1/0;for(let o,a=0;a<n;++a)isNaN(o=+this._x.call(null,t[a]))||(e[a]=o,o<r&&(r=o),o>i&&(i=o));if(r>i)return this;this.cover(r).cover(i);for(let r=0;r<n;++r)M(this,e[r],t[r]);return this},S.cover=function(t){if(isNaN(t=+t))return this;var n=this._x0,e=this._x1;if(isNaN(n))e=(n=Math.floor(t))+1;else{for(var r,i,o=e-n||1,a=this._root;n>t||t>=e;)switch(i=+(t<n),(r=new Array(2))[i]=a,a=r,o*=2,i){case 0:e=n+o;break;case 1:n=e-o}this._root&&this._root.length&&(this._root=a)}return this._x0=n,this._x1=e,this},S.data=function(){var t=[];return this.visit(function(n){if(!n.length)do{t.push(n.data)}while(n=n.next)}),t},S.extent=function(t){return arguments.length?this.cover(+t[0][0]).cover(+t[1][0]):isNaN(this._x0)?void 0:[[this._x0],[this._x1]]},S.find=function(t,n){var e,r,i,o,a,u=this._x0,s=this._x1,f=[],l=this._root;for(l&&f.push(new A(l,u,s)),null==n?n=1/0:(u=t-n,s=t+n);o=f.pop();)if(!(!(l=o.node)||(r=o.x0)>s||(i=o.x1)<u))if(l.length){var c=(r+i)/2;f.push(new A(l[1],c,i),new A(l[0],r,c)),(a=+(t>=c))&&(o=f[f.length-1],f[f.length-1]=f[f.length-1-a],f[f.length-1-a]=o)}else{var h=Math.abs(t-+this._x.call(null,l.data));h<n&&(n=h,u=t-h,s=t+h,e=l.data)}return e},S.remove=function(t){if(isNaN(o=+this._x.call(null,t)))return this;var n,e,r,i,o,a,u,s,f,l=this._root,c=this._x0,h=this._x1;if(!l)return this;if(l.length)for(;;){if((u=o>=(a=(c+h)/2))?c=a:h=a,n=l,!(l=l[s=+u]))return this;if(!l.length)break;n[s+1&1]&&(e=n,f=s)}for(;l.data!==t;)if(r=l,!(l=l.next))return this;return(i=l.next)&&delete l.next,r?(i?r.next=i:delete r.next,this):n?(i?n[s]=i:delete n[s],(l=n[0]||n[1])&&l===(n[1]||n[0])&&!l.length&&(e?e[f]=l:this._root=l),this):(this._root=i,this)},S.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},S.root=function(){return this._root},S.size=function(){var t=0;return this.visit(function(n){if(!n.length)do{++t}while(n=n.next)}),t},S.visit=function(t){var n,e,r,i,o=[],a=this._root;for(a&&o.push(new A(a,this._x0,this._x1));n=o.pop();)if(!t(a=n.node,r=n.x0,i=n.x1)&&a.length){var u=(r+i)/2;(e=a[1])&&o.push(new A(e,u,i)),(e=a[0])&&o.push(new A(e,r,u))}return this},S.visitAfter=function(t){var n,e=[],r=[];for(this._root&&e.push(new A(this._root,this._x0,this._x1));n=e.pop();){var i=n.node;if(i.length){var o,a=n.x0,u=n.x1,s=(a+u)/2;(o=i[0])&&e.push(new A(o,a,s)),(o=i[1])&&e.push(new A(o,s,u))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.x1);return this},S.x=function(t){return arguments.length?(this._x=t,this):this._x};var I=T.prototype=D.prototype;function L(t,n,e,r,i){if(isNaN(n)||isNaN(e)||isNaN(r))return t;var o,a,u,s,f,l,c,h,d,p,g,v,y=t._root,b={data:i},m=t._x0,_=t._y0,x=t._z0,w=t._x1,k=t._y1,M=t._z1;if(!y)return t._root=b,t;for(;y.length;)if((h=n>=(a=(m+w)/2))?m=a:w=a,(d=e>=(u=(_+k)/2))?_=u:k=u,(p=r>=(s=(x+M)/2))?x=s:M=s,o=y,!(y=y[g=p<<2|d<<1|h]))return o[g]=b,t;if(f=+t._x.call(null,y.data),l=+t._y.call(null,y.data),c=+t._z.call(null,y.data),n===f&&e===l&&r===c)return b.next=y,o?o[g]=b:t._root=b,t;do{o=o?o[g]=new Array(8):t._root=new Array(8),(h=n>=(a=(m+w)/2))?m=a:w=a,(d=e>=(u=(_+k)/2))?_=u:k=u,(p=r>=(s=(x+M)/2))?x=s:M=s}while((g=p<<2|d<<1|h)==(v=(c>=s)<<2|(l>=u)<<1|f>=a));return o[v]=y,o[g]=b,t}function F(t,n,e,r,i,o,a){this.node=t,this.x0=n,this.y0=e,this.z0=r,this.x1=i,this.y1=o,this.z1=a}I.copy=function(){var t,n,e=new D(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return e;if(!r.length)return e._root=$(r),e;for(t=[{source:r,target:e._root=new Array(4)}];r=t.pop();)for(var i=0;i<4;++i)(n=r.source[i])&&(n.length?t.push({source:n,target:r.target[i]=new Array(4)}):r.target[i]=$(n));return e},I.add=function(t){const n=+this._x.call(null,t),e=+this._y.call(null,t);return C(this.cover(n,e),n,e,t)},I.addAll=function(t){var n,e,r,i,o=t.length,a=new Array(o),u=new Array(o),s=1/0,f=1/0,l=-1/0,c=-1/0;for(e=0;e<o;++e)isNaN(r=+this._x.call(null,n=t[e]))||isNaN(i=+this._y.call(null,n))||(a[e]=r,u[e]=i,r<s&&(s=r),r>l&&(l=r),i<f&&(f=i),i>c&&(c=i));if(s>l||f>c)return this;for(this.cover(s,f).cover(l,c),e=0;e<o;++e)C(this,a[e],u[e],t[e]);return this},I.cover=function(t,n){if(isNaN(t=+t)||isNaN(n=+n))return this;var e=this._x0,r=this._y0,i=this._x1,o=this._y1;if(isNaN(e))i=(e=Math.floor(t))+1,o=(r=Math.floor(n))+1;else{for(var a,u,s=i-e||1,f=this._root;e>t||t>=i||r>n||n>=o;)switch(u=(n<r)<<1|t<e,(a=new Array(4))[u]=f,f=a,s*=2,u){case 0:i=e+s,o=r+s;break;case 1:e=i-s,o=r+s;break;case 2:i=e+s,r=o-s;break;case 3:e=i-s,r=o-s}this._root&&this._root.length&&(this._root=f)}return this._x0=e,this._y0=r,this._x1=i,this._y1=o,this},I.data=function(){var t=[];return this.visit(function(n){if(!n.length)do{t.push(n.data)}while(n=n.next)}),t},I.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},I.find=function(t,n,e){var r,i,o,a,u,s,f,l=this._x0,c=this._y0,h=this._x1,d=this._y1,p=[],g=this._root;for(g&&p.push(new z(g,l,c,h,d)),null==e?e=1/0:(l=t-e,c=n-e,h=t+e,d=n+e,e*=e);s=p.pop();)if(!(!(g=s.node)||(i=s.x0)>h||(o=s.y0)>d||(a=s.x1)<l||(u=s.y1)<c))if(g.length){var v=(i+a)/2,y=(o+u)/2;p.push(new z(g[3],v,y,a,u),new z(g[2],i,y,v,u),new z(g[1],v,o,a,y),new z(g[0],i,o,v,y)),(f=(n>=y)<<1|t>=v)&&(s=p[p.length-1],p[p.length-1]=p[p.length-1-f],p[p.length-1-f]=s)}else{var b=t-+this._x.call(null,g.data),m=n-+this._y.call(null,g.data),_=b*b+m*m;if(_<e){var x=Math.sqrt(e=_);l=t-x,c=n-x,h=t+x,d=n+x,r=g.data}}return r},I.remove=function(t){if(isNaN(o=+this._x.call(null,t))||isNaN(a=+this._y.call(null,t)))return this;var n,e,r,i,o,a,u,s,f,l,c,h,d=this._root,p=this._x0,g=this._y0,v=this._x1,y=this._y1;if(!d)return this;if(d.length)for(;;){if((f=o>=(u=(p+v)/2))?p=u:v=u,(l=a>=(s=(g+y)/2))?g=s:y=s,n=d,!(d=d[c=l<<1|f]))return this;if(!d.length)break;(n[c+1&3]||n[c+2&3]||n[c+3&3])&&(e=n,h=c)}for(;d.data!==t;)if(r=d,!(d=d.next))return this;return(i=d.next)&&delete d.next,r?(i?r.next=i:delete r.next,this):n?(i?n[c]=i:delete n[c],(d=n[0]||n[1]||n[2]||n[3])&&d===(n[3]||n[2]||n[1]||n[0])&&!d.length&&(e?e[h]=d:this._root=d),this):(this._root=i,this)},I.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},I.root=function(){return this._root},I.size=function(){var t=0;return this.visit(function(n){if(!n.length)do{++t}while(n=n.next)}),t},I.visit=function(t){var n,e,r,i,o,a,u=[],s=this._root;for(s&&u.push(new z(s,this._x0,this._y0,this._x1,this._y1));n=u.pop();)if(!t(s=n.node,r=n.x0,i=n.y0,o=n.x1,a=n.y1)&&s.length){var f=(r+o)/2,l=(i+a)/2;(e=s[3])&&u.push(new z(e,f,l,o,a)),(e=s[2])&&u.push(new z(e,r,l,f,a)),(e=s[1])&&u.push(new z(e,f,i,o,l)),(e=s[0])&&u.push(new z(e,r,i,f,l))}return this},I.visitAfter=function(t){var n,e=[],r=[];for(this._root&&e.push(new z(this._root,this._x0,this._y0,this._x1,this._y1));n=e.pop();){var i=n.node;if(i.length){var o,a=n.x0,u=n.y0,s=n.x1,f=n.y1,l=(a+s)/2,c=(u+f)/2;(o=i[0])&&e.push(new z(o,a,u,l,c)),(o=i[1])&&e.push(new z(o,l,u,s,c)),(o=i[2])&&e.push(new z(o,a,c,l,f)),(o=i[3])&&e.push(new z(o,l,c,s,f))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.y0,n.x1,n.y1);return this},I.x=function(t){return arguments.length?(this._x=t,this):this._x},I.y=function(t){return arguments.length?(this._y=t,this):this._y};const R=(t,n,e,r,i,o)=>Math.sqrt((t-r)**2+(n-i)**2+(e-o)**2);function q(t){return t[0]}function U(t){return t[1]}function G(t){return t[2]}function V(t,n,e,r){var i=new H(null==n?q:n,null==e?U:e,null==r?G:r,NaN,NaN,NaN,NaN,NaN,NaN);return null==t?i:i.addAll(t)}function H(t,n,e,r,i,o,a,u,s){this._x=t,this._y=n,this._z=e,this._x0=r,this._y0=i,this._z0=o,this._x1=a,this._y1=u,this._z1=s,this._root=void 0}function W(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}var Q=V.prototype=H.prototype;function X(t){return function(){return t}}function J(t){return 1e-6*(t()-.5)}function Y(t){return t.index}function K(t,n){var e=t.get(n);if(!e)throw new Error("node not found: "+n);return e}function Z(t){var n,e,r,i,o,a,u,s=Y,f=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},l=X(30),c=1;function h(r){for(var o=0,s=t.length;o<c;++o)for(var f,l,h,d,p,g=0,v=0,y=0,b=0;g<s;++g)l=(f=t[g]).source,v=(h=f.target).x+h.vx-l.x-l.vx||J(u),i>1&&(y=h.y+h.vy-l.y-l.vy||J(u)),i>2&&(b=h.z+h.vz-l.z-l.vz||J(u)),v*=d=((d=Math.sqrt(v*v+y*y+b*b))-e[g])/d*r*n[g],y*=d,b*=d,h.vx-=v*(p=a[g]),i>1&&(h.vy-=y*p),i>2&&(h.vz-=b*p),l.vx+=v*(p=1-p),i>1&&(l.vy+=y*p),i>2&&(l.vz+=b*p)}function d(){if(r){var i,u,f=r.length,l=t.length,c=new Map(r.map((t,n)=>[s(t,n,r),t]));for(i=0,o=new Array(f);i<l;++i)(u=t[i]).index=i,"object"!=typeof u.source&&(u.source=K(c,u.source)),"object"!=typeof u.target&&(u.target=K(c,u.target)),o[u.source.index]=(o[u.source.index]||0)+1,o[u.target.index]=(o[u.target.index]||0)+1;for(i=0,a=new Array(l);i<l;++i)u=t[i],a[i]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);n=new Array(l),p(),e=new Array(l),g()}}function p(){if(r)for(var e=0,i=t.length;e<i;++e)n[e]=+f(t[e],e,t)}function g(){if(r)for(var n=0,i=t.length;n<i;++n)e[n]=+l(t[n],n,t)}return null==t&&(t=[]),h.initialize=function(t,...n){r=t,u=n.find(t=>"function"==typeof t)||Math.random,i=n.find(t=>[1,2,3].includes(t))||2,d()},h.links=function(n){return arguments.length?(t=n,d(),h):t},h.id=function(t){return arguments.length?(s=t,h):s},h.iterations=function(t){return arguments.length?(c=+t,h):c},h.strength=function(t){return arguments.length?(f="function"==typeof t?t:X(+t),p(),h):f},h.distance=function(t){return arguments.length?(l="function"==typeof t?t:X(+t),g(),h):l},h}Q.copy=function(){var t,n,e=new H(this._x,this._y,this._z,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1),r=this._root;if(!r)return e;if(!r.length)return e._root=W(r),e;for(t=[{source:r,target:e._root=new Array(8)}];r=t.pop();)for(var i=0;i<8;++i)(n=r.source[i])&&(n.length?t.push({source:n,target:r.target[i]=new Array(8)}):r.target[i]=W(n));return e},Q.add=function(t){const n=+this._x.call(null,t),e=+this._y.call(null,t),r=+this._z.call(null,t);return L(this.cover(n,e,r),n,e,r,t)},Q.addAll=function(t){Array.isArray(t)||(t=Array.from(t));const n=t.length,e=new Float64Array(n),r=new Float64Array(n),i=new Float64Array(n);let o=1/0,a=1/0,u=1/0,s=-1/0,f=-1/0,l=-1/0;for(let c,h,d,p,g=0;g<n;++g)isNaN(h=+this._x.call(null,c=t[g]))||isNaN(d=+this._y.call(null,c))||isNaN(p=+this._z.call(null,c))||(e[g]=h,r[g]=d,i[g]=p,h<o&&(o=h),h>s&&(s=h),d<a&&(a=d),d>f&&(f=d),p<u&&(u=p),p>l&&(l=p));if(o>s||a>f||u>l)return this;this.cover(o,a,u).cover(s,f,l);for(let o=0;o<n;++o)L(this,e[o],r[o],i[o],t[o]);return this},Q.cover=function(t,n,e){if(isNaN(t=+t)||isNaN(n=+n)||isNaN(e=+e))return this;var r=this._x0,i=this._y0,o=this._z0,a=this._x1,u=this._y1,s=this._z1;if(isNaN(r))a=(r=Math.floor(t))+1,u=(i=Math.floor(n))+1,s=(o=Math.floor(e))+1;else{for(var f,l,c=a-r||1,h=this._root;r>t||t>=a||i>n||n>=u||o>e||e>=s;)switch(l=(e<o)<<2|(n<i)<<1|t<r,(f=new Array(8))[l]=h,h=f,c*=2,l){case 0:a=r+c,u=i+c,s=o+c;break;case 1:r=a-c,u=i+c,s=o+c;break;case 2:a=r+c,i=u-c,s=o+c;break;case 3:r=a-c,i=u-c,s=o+c;break;case 4:a=r+c,u=i+c,o=s-c;break;case 5:r=a-c,u=i+c,o=s-c;break;case 6:a=r+c,i=u-c,o=s-c;break;case 7:r=a-c,i=u-c,o=s-c}this._root&&this._root.length&&(this._root=h)}return this._x0=r,this._y0=i,this._z0=o,this._x1=a,this._y1=u,this._z1=s,this},Q.data=function(){var t=[];return this.visit(function(n){if(!n.length)do{t.push(n.data)}while(n=n.next)}),t},Q.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1],+t[0][2]).cover(+t[1][0],+t[1][1],+t[1][2]):isNaN(this._x0)?void 0:[[this._x0,this._y0,this._z0],[this._x1,this._y1,this._z1]]},Q.find=function(t,n,e,r){var i,o,a,u,s,f,l,c,h,d=this._x0,p=this._y0,g=this._z0,v=this._x1,y=this._y1,b=this._z1,m=[],_=this._root;for(_&&m.push(new F(_,d,p,g,v,y,b)),null==r?r=1/0:(d=t-r,p=n-r,g=e-r,v=t+r,y=n+r,b=e+r,r*=r);c=m.pop();)if(!(!(_=c.node)||(o=c.x0)>v||(a=c.y0)>y||(u=c.z0)>b||(s=c.x1)<d||(f=c.y1)<p||(l=c.z1)<g))if(_.length){var x=(o+s)/2,w=(a+f)/2,k=(u+l)/2;m.push(new F(_[7],x,w,k,s,f,l),new F(_[6],o,w,k,x,f,l),new F(_[5],x,a,k,s,w,l),new F(_[4],o,a,k,x,w,l),new F(_[3],x,w,u,s,f,k),new F(_[2],o,w,u,x,f,k),new F(_[1],x,a,u,s,w,k),new F(_[0],o,a,u,x,w,k)),(h=(e>=k)<<2|(n>=w)<<1|t>=x)&&(c=m[m.length-1],m[m.length-1]=m[m.length-1-h],m[m.length-1-h]=c)}else{var M=t-+this._x.call(null,_.data),A=n-+this._y.call(null,_.data),O=e-+this._z.call(null,_.data),j=M*M+A*A+O*O;if(j<r){var N=Math.sqrt(r=j);d=t-N,p=n-N,g=e-N,v=t+N,y=n+N,b=e+N,i=_.data}}return i},Q.findAllWithinRadius=function(t,n,e,r){const i=[],o=t-r,a=n-r,u=e-r,s=t+r,f=n+r,l=e+r;return this.visit((c,h,d,p,g,v,y)=>{if(!c.length)do{const o=c.data;R(t,n,e,this._x(o),this._y(o),this._z(o))<=r&&i.push(o)}while(c=c.next);return h>s||d>f||p>l||g<o||v<a||y<u}),i},Q.remove=function(t){if(isNaN(o=+this._x.call(null,t))||isNaN(a=+this._y.call(null,t))||isNaN(u=+this._z.call(null,t)))return this;var n,e,r,i,o,a,u,s,f,l,c,h,d,p,g,v=this._root,y=this._x0,b=this._y0,m=this._z0,_=this._x1,x=this._y1,w=this._z1;if(!v)return this;if(v.length)for(;;){if((c=o>=(s=(y+_)/2))?y=s:_=s,(h=a>=(f=(b+x)/2))?b=f:x=f,(d=u>=(l=(m+w)/2))?m=l:w=l,n=v,!(v=v[p=d<<2|h<<1|c]))return this;if(!v.length)break;(n[p+1&7]||n[p+2&7]||n[p+3&7]||n[p+4&7]||n[p+5&7]||n[p+6&7]||n[p+7&7])&&(e=n,g=p)}for(;v.data!==t;)if(r=v,!(v=v.next))return this;return(i=v.next)&&delete v.next,r?(i?r.next=i:delete r.next,this):n?(i?n[p]=i:delete n[p],(v=n[0]||n[1]||n[2]||n[3]||n[4]||n[5]||n[6]||n[7])&&v===(n[7]||n[6]||n[5]||n[4]||n[3]||n[2]||n[1]||n[0])&&!v.length&&(e?e[g]=v:this._root=v),this):(this._root=i,this)},Q.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},Q.root=function(){return this._root},Q.size=function(){var t=0;return this.visit(function(n){if(!n.length)do{++t}while(n=n.next)}),t},Q.visit=function(t){var n,e,r,i,o,a,u,s,f=[],l=this._root;for(l&&f.push(new F(l,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));n=f.pop();)if(!t(l=n.node,r=n.x0,i=n.y0,o=n.z0,a=n.x1,u=n.y1,s=n.z1)&&l.length){var c=(r+a)/2,h=(i+u)/2,d=(o+s)/2;(e=l[7])&&f.push(new F(e,c,h,d,a,u,s)),(e=l[6])&&f.push(new F(e,r,h,d,c,u,s)),(e=l[5])&&f.push(new F(e,c,i,d,a,h,s)),(e=l[4])&&f.push(new F(e,r,i,d,c,h,s)),(e=l[3])&&f.push(new F(e,c,h,o,a,u,d)),(e=l[2])&&f.push(new F(e,r,h,o,c,u,d)),(e=l[1])&&f.push(new F(e,c,i,o,a,h,d)),(e=l[0])&&f.push(new F(e,r,i,o,c,h,d))}return this},Q.visitAfter=function(t){var n,e=[],r=[];for(this._root&&e.push(new F(this._root,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));n=e.pop();){var i=n.node;if(i.length){var o,a=n.x0,u=n.y0,s=n.z0,f=n.x1,l=n.y1,c=n.z1,h=(a+f)/2,d=(u+l)/2,p=(s+c)/2;(o=i[0])&&e.push(new F(o,a,u,s,h,d,p)),(o=i[1])&&e.push(new F(o,h,u,s,f,d,p)),(o=i[2])&&e.push(new F(o,a,d,s,h,l,p)),(o=i[3])&&e.push(new F(o,h,d,s,f,l,p)),(o=i[4])&&e.push(new F(o,a,u,p,h,d,c)),(o=i[5])&&e.push(new F(o,h,u,p,f,d,c)),(o=i[6])&&e.push(new F(o,a,d,p,h,l,c)),(o=i[7])&&e.push(new F(o,h,d,p,f,l,c))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.y0,n.z0,n.x1,n.y1,n.z1);return this},Q.x=function(t){return arguments.length?(this._x=t,this):this._x},Q.y=function(t){return arguments.length?(this._y=t,this):this._y},Q.z=function(t){return arguments.length?(this._z=t,this):this._z};var tt={value:()=>{}};function nt(){for(var t,n=0,e=arguments.length,r={};n<e;++n){if(!(t=arguments[n]+"")||t in r||/[\s.]/.test(t))throw new Error("illegal type: "+t);r[t]=[]}return new et(r)}function et(t){this._=t}function rt(t,n){for(var e,r=0,i=t.length;r<i;++r)if((e=t[r]).name===n)return e.value}function it(t,n,e){for(var r=0,i=t.length;r<i;++r)if(t[r].name===n){t[r]=tt,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=e&&t.push({name:n,value:e}),t}et.prototype=nt.prototype={constructor:et,on:function(t,n){var e,r,i=this._,o=(r=i,(t+"").trim().split(/^|\s+/).map(function(t){var n="",e=t.indexOf(".");if(e>=0&&(n=t.slice(e+1),t=t.slice(0,e)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}})),a=-1,u=o.length;if(!(arguments.length<2)){if(null!=n&&"function"!=typeof n)throw new Error("invalid callback: "+n);for(;++a<u;)if(e=(t=o[a]).type)i[e]=it(i[e],t.name,n);else if(null==n)for(e in i)i[e]=it(i[e],t.name,null);return this}for(;++a<u;)if((e=(t=o[a]).type)&&(e=rt(i[e],t.name)))return e},copy:function(){var t={},n=this._;for(var e in n)t[e]=n[e].slice();return new et(t)},call:function(t,n){if((e=arguments.length-2)>0)for(var e,r,i=new Array(e),o=0;o<e;++o)i[o]=arguments[o+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(o=0,e=(r=this._[t]).length;o<e;++o)r[o].value.apply(n,i)},apply:function(t,n,e){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],i=0,o=r.length;i<o;++i)r[i].value.apply(n,e)}};var ot,at,ut=0,st=0,ft=0,lt=0,ct=0,ht=0,dt="object"==typeof performance&&performance.now?performance:Date,pt="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function gt(){return ct||(pt(vt),ct=dt.now()+ht)}function vt(){ct=0}function yt(){this._call=this._time=this._next=null}function bt(t,n,e){var r=new yt;return r.restart(t,n,e),r}function mt(){ct=(lt=dt.now())+ht,ut=st=0;try{!function(){gt(),++ut;for(var t,n=ot;n;)(t=ct-n._time)>=0&&n._call.call(void 0,t),n=n._next;--ut}()}finally{ut=0,function(){var t,n,e=ot,r=1/0;for(;e;)e._call?(r>e._time&&(r=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:ot=n);at=t,xt(r)}(),ct=0}}function _t(){var t=dt.now(),n=t-lt;n>1e3&&(ht-=n,lt=t)}function xt(t){ut||(st&&(st=clearTimeout(st)),t-ct>24?(t<1/0&&(st=setTimeout(mt,t-dt.now()-ht)),ft&&(ft=clearInterval(ft))):(ft||(lt=dt.now(),ft=setInterval(_t,1e3)),ut=1,pt(mt)))}yt.prototype=bt.prototype={constructor:yt,restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?gt():+e)+(null==n?0:+n),this._next||at===this||(at?at._next=this:ot=this,at=this),this._call=t,this._time=e,xt()},stop:function(){this._call&&(this._call=null,this._time=1/0,xt())}};const wt=4294967296;function kt(t){return t.x}function Mt(t){return t.y}function At(t){return t.z}var Ot,jt,Nt,Pt,St=Math.PI*(3-Math.sqrt(5)),Ct=20*Math.PI/(9+Math.sqrt(221));function zt(t,n){n=n||2;var e,r=Math.min(3,Math.max(1,Math.round(n))),i=1,o=.001,a=1-Math.pow(o,1/300),u=0,s=.6,f=new Map,l=bt(d),c=nt("tick","end"),h=function(){let t=1;return()=>(t=(1664525*t+1013904223)%wt)/wt}();function d(){p(),c.call("tick",e),i<o&&(l.stop(),c.call("end",e))}function p(n){var o,l,c=t.length;void 0===n&&(n=1);for(var h=0;h<n;++h)for(i+=(u-i)*a,f.forEach(function(t){t(i)}),o=0;o<c;++o)null==(l=t[o]).fx?l.x+=l.vx*=s:(l.x=l.fx,l.vx=0),r>1&&(null==l.fy?l.y+=l.vy*=s:(l.y=l.fy,l.vy=0)),r>2&&(null==l.fz?l.z+=l.vz*=s:(l.z=l.fz,l.vz=0));return e}function g(){for(var n,e=0,i=t.length;e<i;++e){if((n=t[e]).index=e,null!=n.fx&&(n.x=n.fx),null!=n.fy&&(n.y=n.fy),null!=n.fz&&(n.z=n.fz),isNaN(n.x)||r>1&&isNaN(n.y)||r>2&&isNaN(n.z)){var o=10*(r>2?Math.cbrt(.5+e):r>1?Math.sqrt(.5+e):e),a=e*St,u=e*Ct;1===r?n.x=o:2===r?(n.x=o*Math.cos(a),n.y=o*Math.sin(a)):(n.x=o*Math.sin(a)*Math.cos(u),n.y=o*Math.cos(a),n.z=o*Math.sin(a)*Math.sin(u))}(isNaN(n.vx)||r>1&&isNaN(n.vy)||r>2&&isNaN(n.vz))&&(n.vx=0,r>1&&(n.vy=0),r>2&&(n.vz=0))}}function v(n){return n.initialize&&n.initialize(t,h,r),n}return null==t&&(t=[]),g(),e={tick:p,restart:function(){return l.restart(d),e},stop:function(){return l.stop(),e},numDimensions:function(t){return arguments.length?(r=Math.min(3,Math.max(1,Math.round(t))),f.forEach(v),e):r},nodes:function(n){return arguments.length?(t=n,g(),f.forEach(v),e):t},alpha:function(t){return arguments.length?(i=+t,e):i},alphaMin:function(t){return arguments.length?(o=+t,e):o},alphaDecay:function(t){return arguments.length?(a=+t,e):+a},alphaTarget:function(t){return arguments.length?(u=+t,e):u},velocityDecay:function(t){return arguments.length?(s=1-t,e):1-s},randomSource:function(t){return arguments.length?(h=t,f.forEach(v),e):h},force:function(t,n){return arguments.length>1?(null==n?f.delete(t):f.set(t,v(n)),e):f.get(t)},find:function(){var n,e,i,o,a,u,s=Array.prototype.slice.call(arguments),f=s.shift()||0,l=(r>1?s.shift():null)||0,c=(r>2?s.shift():null)||0,h=s.shift()||1/0,d=0,p=t.length;for(h*=h,d=0;d<p;++d)(o=(n=f-(a=t[d]).x)*n+(e=l-(a.y||0))*e+(i=c-(a.z||0))*i)<h&&(u=a,h=o);return u},on:function(t,n){return arguments.length>1?(c.on(t,n),e):c.on(t)}}}function Et(){var t,n,e,r,i,o,a=X(-30),u=1,s=1/0,f=.81;function l(r){var o,a=t.length,u=(1===n?j(t,kt):2===n?T(t,kt,Mt):3===n?V(t,kt,Mt,At):null).visitAfter(h);for(i=r,o=0;o<a;++o)e=t[o],u.visit(d)}function c(){if(t){var n,e,r=t.length;for(o=new Array(r),n=0;n<r;++n)e=t[n],o[e.index]=+a(e,n,t)}}function h(t){var e,r,i,a,u,s,f=0,l=0,c=t.length;if(c){for(i=a=u=s=0;s<c;++s)(e=t[s])&&(r=Math.abs(e.value))&&(f+=e.value,l+=r,i+=r*(e.x||0),a+=r*(e.y||0),u+=r*(e.z||0));f*=Math.sqrt(4/c),t.x=i/l,n>1&&(t.y=a/l),n>2&&(t.z=u/l)}else{(e=t).x=e.data.x,n>1&&(e.y=e.data.y),n>2&&(e.z=e.data.z);do{f+=o[e.data.index]}while(e=e.next)}t.value=f}function d(t,a,l,c,h){if(!t.value)return!0;var d=[l,c,h][n-1],p=t.x-e.x,g=n>1?t.y-e.y:0,v=n>2?t.z-e.z:0,y=d-a,b=p*p+g*g+v*v;if(y*y/f<b)return b<s&&(0===p&&(b+=(p=J(r))*p),n>1&&0===g&&(b+=(g=J(r))*g),n>2&&0===v&&(b+=(v=J(r))*v),b<u&&(b=Math.sqrt(u*b)),e.vx+=p*t.value*i/b,n>1&&(e.vy+=g*t.value*i/b),n>2&&(e.vz+=v*t.value*i/b)),!0;if(!(t.length||b>=s)){(t.data!==e||t.next)&&(0===p&&(b+=(p=J(r))*p),n>1&&0===g&&(b+=(g=J(r))*g),n>2&&0===v&&(b+=(v=J(r))*v),b<u&&(b=Math.sqrt(u*b)));do{t.data!==e&&(y=o[t.data.index]*i/b,e.vx+=p*y,n>1&&(e.vy+=g*y),n>2&&(e.vz+=v*y))}while(t=t.next)}}return l.initialize=function(e,...i){t=e,r=i.find(t=>"function"==typeof t)||Math.random,n=i.find(t=>[1,2,3].includes(t))||2,c()},l.strength=function(t){return arguments.length?(a="function"==typeof t?t:X(+t),c(),l):a},l.distanceMin=function(t){return arguments.length?(u=t*t,l):Math.sqrt(u)},l.distanceMax=function(t){return arguments.length?(s=t*t,l):Math.sqrt(s)},l.theta=function(t){return arguments.length?(f=t*t,l):Math.sqrt(f)},l}function Bt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Tt(){if(jt)return Ot;return jt=1,Ot=function(t){!function(t){if(!t)throw new Error("Eventify cannot use falsy object as events subject");for(var n=["on","fire","off"],e=0;e<n.length;++e)if(t.hasOwnProperty(n[e]))throw new Error("Subject cannot be eventified, since it already has property '"+n[e]+"'")}(t);var n=function(t){var n=Object.create(null);return{on:function(e,r,i){if("function"!=typeof r)throw new Error("callback is expected to be a function");var o=n[e];return o||(o=n[e]=[]),o.push({callback:r,ctx:i}),t},off:function(e,r){if(void 0===e)return n=Object.create(null),t;if(n[e])if("function"!=typeof r)delete n[e];else for(var i=n[e],o=0;o<i.length;++o)i[o].callback===r&&i.splice(o,1);return t},fire:function(e){var r,i=n[e];if(!i)return t;arguments.length>1&&(r=Array.prototype.splice.call(arguments,1));for(var o=0;o<i.length;++o){var a=i[o];a.callback.apply(a.ctx,r)}return t}}}(t);return t.on=n.on,t.off=n.off,t.fire=n.fire,t},Ot}var Dt,$t,It,Lt,Ft,Rt=function(){if(Pt)return Nt;Pt=1,Nt=function(o){"uniqueLinkId"in(o=o||{})&&(console.warn("ngraph.graph: Starting from version 0.14 `uniqueLinkId` is deprecated.\nUse `multigraph` option instead\n","\n","Note: there is also change in default behavior: From now on each graph\nis considered to be not a multigraph by default (each edge is unique)."),o.multigraph=o.uniqueLinkId);void 0===o.multigraph&&(o.multigraph=!1);if("function"!=typeof Map)throw new Error("ngraph.graph requires `Map` to be defined. Please polyfill it before using ngraph");var a=new Map,u=new Map,s={},f=0,l=o.multigraph?function(t,n,e){var o=i(t,n),a=s.hasOwnProperty(o);if(a||A(t,n)){a||(s[o]=0);var u="@"+ ++s[o];o=i(t+u,n+u)}return new r(t,n,e,o)}:function(t,n,e){var o=i(t,n),a=u.get(o);if(a)return a.data=e,a;return new r(t,n,e,o)},c=[],h=O,d=O,p=O,g=O,v={version:20,addNode:m,addLink:function(t,n,r){p();var i=_(t)||m(t),o=_(n)||m(n),a=l(t,n,r),s=u.has(a.id);u.set(a.id,a),e(i,a),t!==n&&e(o,a);return h(a,s?"update":"add"),g(),a},removeLink:function(t,n){void 0!==n&&(t=A(t,n));return M(t)},removeNode:x,getNode:_,getNodeCount:w,getLinkCount:k,getEdgeCount:k,getLinksCount:k,getNodesCount:w,getLinks:function(t){var n=_(t);return n?n.links:null},forEachNode:P,forEachLinkedNode:function(t,n,e){var r=_(t);if(r&&r.links&&"function"==typeof n)return e?function(t,n,e){var r=t.values(),i=r.next();for(;!i.done;){var o=i.value;if(o.fromId===n&&e(a.get(o.toId),o))return!0;i=r.next()}}(r.links,t,n):function(t,n,e){var r=t.values(),i=r.next();for(;!i.done;){var o=i.value,u=o.fromId===n?o.toId:o.fromId;if(e(a.get(u),o))return!0;i=r.next()}}(r.links,t,n)},forEachLink:function(t){if("function"==typeof t)for(var n=u.values(),e=n.next();!e.done;){if(t(e.value))return!0;e=n.next()}},beginUpdate:p,endUpdate:g,clear:function(){p(),P(function(t){x(t.id)}),g()},hasLink:A,hasNode:_,getLink:A};return t(v),function(){var t=v.on;function n(){return v.beginUpdate=p=j,v.endUpdate=g=N,h=y,d=b,v.on=t,t.apply(v,arguments)}v.on=n}(),v;function y(t,n){c.push({link:t,changeType:n})}function b(t,n){c.push({node:t,changeType:n})}function m(t,e){if(void 0===t)throw new Error("Invalid node identifier");p();var r=_(t);return r?(r.data=e,d(r,"update")):(r=new n(t,e),d(r,"add")),a.set(t,r),g(),r}function _(t){return a.get(t)}function x(t){var n=_(t);if(!n)return!1;p();var e=n.links;return e&&(e.forEach(M),n.links=null),a.delete(t),d(n,"remove"),g(),!0}function w(){return a.size}function k(){return u.size}function M(t){if(!t)return!1;if(!u.get(t.id))return!1;p(),u.delete(t.id);var n=_(t.fromId),e=_(t.toId);return n&&n.links.delete(t),e&&e.links.delete(t),h(t,"remove"),g(),!0}function A(t,n){if(void 0!==t&&void 0!==n)return u.get(i(t,n))}function O(){}function j(){f+=1}function N(){0===(f-=1)&&c.length>0&&(v.fire("changed",c),c.length=0)}function P(t){if("function"!=typeof t)throw new Error("Function is expected to iterate over graph nodes. You passed "+t);for(var n=a.values(),e=n.next();!e.done;){if(t(e.value))return!0;e=n.next()}}};var t=Tt();function n(t,n){this.id=t,this.links=null,this.data=n}function e(t,n){t.links?t.links.add(n):t.links=new Set([n])}function r(t,n,e,r){this.fromId=t,this.toId=n,this.data=e,this.id=r}function i(t,n){return t.toString()+"👉 "+n.toString()}return Nt}(),qt=Bt(Rt),Ut={exports:{}},Gt={exports:{}};function Vt(){return $t||($t=1,Dt=function(t){return 0===t?"x":1===t?"y":2===t?"z":"c"+(t+1)}),Dt}function Ht(){if(Lt)return It;Lt=1;const t=Vt();return It=function(n){return function(e,r){let i=r&&r.indent||0,o=r&&void 0!==r.join?r.join:"\n",a=Array(i+1).join(" "),u=[];for(let r=0;r<n;++r){let n=t(r),i=0===r?"":a;u.push(i+e.replace(/{var}/g,n))}return u.join(o)}}}var Wt,Qt={exports:{}};var Xt,Jt={exports:{}};var Yt,Kt={exports:{}};var Zt,tn={exports:{}};var nn,en,rn,on,an,un={exports:{}};var sn,fn,ln,cn,hn={exports:{}};function dn(){if(ln)return fn;ln=1,fn=function(s){var f=rn?en:(rn=1,en=function(t,n,e,r){this.from=t,this.to=n,this.length=e,this.coefficient=r}),l=(an||(an=1,on=function t(n,e){var r;if(n||(n={}),e)for(r in e)if(e.hasOwnProperty(r)){var i=n.hasOwnProperty(r),o=typeof e[r];i&&typeof n[r]===o?"object"===o&&(n[r]=t(n[r],e[r])):n[r]=e[r]}return n}),on),c=Tt();if(s){if(void 0!==s.springCoeff)throw new Error("springCoeff was renamed to springCoefficient");if(void 0!==s.dragCoeff)throw new Error("dragCoeff was renamed to dragCoefficient")}s=l(s,{springLength:10,springCoefficient:.8,gravity:-12,theta:.8,dragCoefficient:.9,timeStep:.5,adaptiveTimeStepWeight:0,dimensions:2,debug:!1});var h=a[s.dimensions];if(!h){var d=s.dimensions;h={Body:t(d,s.debug),createQuadTree:n(d),createBounds:e(d),createDragForce:r(d),createSpringForce:i(d),integrate:o(d)},a[d]=h}var p=h.Body,g=h.createQuadTree,v=h.createBounds,y=h.createDragForce,b=h.createSpringForce,m=h.integrate,_=function(){if(sn)return hn.exports;function t(t){return new n("number"==typeof t?t:+new Date)}function n(t){this.seed=t}function e(t){return Math.sqrt(2*Math.PI/t)*Math.pow(1/Math.E*(t+1/(12*t-1/(10*t))),t)}function r(){var t=this.seed;return t=4294967295&(3042594569^(t=4251993797+(t=4294967295&(3550635116+(t=374761393+(t=4294967295&(3345072700^(t=t+2127912214+(t<<12)&4294967295)^t>>>19))+(t<<5)&4294967295)^t<<9))+(t<<3)&4294967295)^t>>>16),this.seed=t,(268435455&t)/268435456}return sn=1,hn.exports=t,hn.exports.random=t,hn.exports.randomIterator=function(n,e){var r=e||t();if("function"!=typeof r.next)throw new Error("customRandom does not match expected API: next() function is missing");return{forEach:function(t){var e,i,o;for(e=n.length-1;e>0;--e)i=r.next(e+1),o=n[i],n[i]=n[e],n[e]=o,t(o);n.length&&t(n[0])},shuffle:function(){var t,e,i;for(t=n.length-1;t>0;--t)e=r.next(t+1),i=n[e],n[e]=n[t],n[t]=i;return n}}},n.prototype.next=function(t){return Math.floor(this.nextDouble()*t)},n.prototype.nextDouble=r,n.prototype.uniform=r,n.prototype.gaussian=function(){var t,n,e;do{t=(n=2*this.nextDouble()-1)*n+(e=2*this.nextDouble()-1)*e}while(t>=1||0===t);return n*Math.sqrt(-2*Math.log(t)/t)},n.prototype.random=r,n.prototype.levy=function(){var t=1.5,n=Math.pow(e(2.5)*Math.sin(Math.PI*t/2)/(e(1.25)*t*Math.pow(2,.25)),1/t);return this.gaussian()*n/Math.pow(Math.abs(this.gaussian()),1/t)},hn.exports}().random(42),x=[],w=[],k=g(s,_),M=v(x,s,_),A=b(s,_),O=y(s),j=[],N=new Map,P=0;z("nbody",function(){if(0===x.length)return;k.insertBodies(x);var t=x.length;for(;t--;){var n=x[t];n.isPinned||(n.reset(),k.updateBodyForce(n),O.update(n))}}),z("spring",function(){var t=w.length;for(;t--;)A.update(w[t])});var S={bodies:x,quadTree:k,springs:w,settings:s,addForce:z,removeForce:function(t){var n=j.indexOf(N.get(t));if(n<0)return;j.splice(n,1),N.delete(t)},getForces:function(){return N},step:function(){for(var t=0;t<j.length;++t)j[t](P);var n=m(x,s.timeStep,s.adaptiveTimeStepWeight);return P+=1,n},addBody:function(t){if(!t)throw new Error("Body is required");return x.push(t),t},addBodyAt:function(t){if(!t)throw new Error("Body position is required");var n=(t=>new p(t))(t);return x.push(n),n},removeBody:function(t){if(t){var n=x.indexOf(t);if(!(n<0))return x.splice(n,1),0===x.length&&M.reset(),!0}},addSpring:function(t,n,e,r){if(!t||!n)throw new Error("Cannot add null spring to force simulator");"number"!=typeof e&&(e=-1);var i=new f(t,n,e,r>=0?r:-1);return w.push(i),i},getTotalMovement:function(){return 0},removeSpring:function(t){if(t){var n=w.indexOf(t);return n>-1?(w.splice(n,1),!0):void 0}},getBestNewBodyPosition:function(t){return M.getBestNewPosition(t)},getBBox:C,getBoundingBox:C,invalidateBBox:function(){console.warn("invalidateBBox() is deprecated, bounds always recomputed on `getBBox()` call")},gravity:function(t){return void 0!==t?(s.gravity=t,k.options({gravity:t}),this):s.gravity},theta:function(t){return void 0!==t?(s.theta=t,k.options({theta:t}),this):s.theta},random:_};return function(t,n){for(var e in t)u(t,n,e)}(s,S),c(S),S;function C(){return M.update(),M.box}function z(t,n){if(N.has(t))throw new Error("Force "+t+" is already added");N.set(t,n),j.push(n)}};var t=function(){if(Ft)return Gt.exports;Ft=1;const t=Ht();function n(t,n){return`\n${r(t,n)}\n${e(t)}\nreturn {Body: Body, Vector: Vector};\n`}function e(n){let e=t(n),r=e("{var}",{join:", "});return`\nfunction Body(${r}) {\n this.isPinned = false;\n this.pos = new Vector(${r});\n this.force = new Vector();\n this.velocity = new Vector();\n this.mass = 1;\n\n this.springCount = 0;\n this.springLength = 0;\n}\n\nBody.prototype.reset = function() {\n this.force.reset();\n this.springCount = 0;\n this.springLength = 0;\n}\n\nBody.prototype.setPosition = function (${r}) {\n ${e("this.pos.{var} = {var} || 0;",{indent:2})}\n};`}function r(n,e){let r=t(n),i="";return e&&(i=`${r("\n\t var v{var};\n\tObject.defineProperty(this, '{var}', {\n\t set: function(v) { \n\t if (!Number.isFinite(v)) throw new Error('Cannot set non-numbers to {var}');\n\t v{var} = v; \n\t },\n\t get: function() { return v{var}; }\n\t});")}`),`function Vector(${r("{var}",{join:", "})}) {\n ${i}\n if (typeof arguments[0] === 'object') {\n // could be another vector\n let v = arguments[0];\n ${r('if (!Number.isFinite(v.{var})) throw new Error("Expected value is not a finite number at Vector constructor ({var})");',{indent:4})}\n ${r("this.{var} = v.{var};",{indent:4})}\n } else {\n ${r('this.{var} = typeof {var} === "number" ? {var} : 0;',{indent:4})}\n }\n }\n \n Vector.prototype.reset = function () {\n ${r("this.{var} = ",{join:""})}0;\n };`}return Gt.exports=function(t,e){let r=n(t,e),{Body:i}=new Function(r)();return i},Gt.exports.generateCreateBodyFunctionBody=n,Gt.exports.getVectorCode=r,Gt.exports.getBodyCode=e,Gt.exports}(),n=function(){if(Wt)return Qt.exports;Wt=1;const t=Ht(),n=Vt();function e(e){let s=t(e),f=Math.pow(2,e);return`\n${u()}\n${a(e)}\n${r(e)}\n${o(e)}\n${i(e)}\n\nfunction createQuadTree(options, random) {\n options = options || {};\n options.gravity = typeof options.gravity === 'number' ? options.gravity : -1;\n options.theta = typeof options.theta === 'number' ? options.theta : 0.8;\n\n var gravity = options.gravity;\n var updateQueue = [];\n var insertStack = new InsertStack();\n var theta = options.theta;\n\n var nodesCache = [];\n var currentInCache = 0;\n var root = newNode();\n\n return {\n insertBodies: insertBodies,\n\n /**\n * Gets root node if it is present\n */\n getRoot: function() {\n return root;\n },\n\n updateBodyForce: update,\n\n options: function(newOptions) {\n if (newOptions) {\n if (typeof newOptions.gravity === 'number') {\n gravity = newOptions.gravity;\n }\n if (typeof newOptions.theta === 'number') {\n theta = newOptions.theta;\n }\n\n return this;\n }\n\n return {\n gravity: gravity,\n theta: theta\n };\n }\n };\n\n function newNode() {\n // To avoid pressure on GC we reuse nodes.\n var node = nodesCache[currentInCache];\n if (node) {\n${function(t){let n=[];for(let e=0;e<f;++e)n.push(`${t}quad${e} = null;`);return n.join("\n")}(" node.")}\n node.body = null;\n node.mass = ${s("node.mass_{var} = ",{join:""})}0;\n ${s("node.min_{var} = node.max_{var} = ",{join:""})}0;\n } else {\n node = new QuadNode();\n nodesCache[currentInCache] = node;\n }\n\n ++currentInCache;\n return node;\n }\n\n function update(sourceBody) {\n var queue = updateQueue;\n var v;\n ${s("var d{var};",{indent:4})}\n var r; \n ${s("var f{var} = 0;",{indent:4})}\n var queueLength = 1;\n var shiftIdx = 0;\n var pushIdx = 1;\n\n queue[0] = root;\n\n while (queueLength) {\n var node = queue[shiftIdx];\n var body = node.body;\n\n queueLength -= 1;\n shiftIdx += 1;\n var differentBody = (body !== sourceBody);\n if (body && differentBody) {\n // If the current node is a leaf node (and it is not source body),\n // calculate the force exerted by the current node on body, and add this\n // amount to body's net force.\n ${s("d{var} = body.pos.{var} - sourceBody.pos.{var};",{indent:8})}\n r = Math.sqrt(${s("d{var} * d{var}",{join:" + "})});\n\n if (r === 0) {\n // Poor man's protection against zero distance.\n ${s("d{var} = (random.nextDouble() - 0.5) / 50;",{indent:10})}\n r = Math.sqrt(${s("d{var} * d{var}",{join:" + "})});\n }\n\n // This is standard gravitation force calculation but we divide\n // by r^3 to save two operations when normalizing force vector.\n v = gravity * body.mass * sourceBody.mass / (r * r * r);\n ${s("f{var} += v * d{var};",{indent:8})}\n } else if (differentBody) {\n // Otherwise, calculate the ratio s / r, where s is the width of the region\n // represented by the internal node, and r is the distance between the body\n // and the node's center-of-mass\n ${s("d{var} = node.mass_{var} / node.mass - sourceBody.pos.{var};",{indent:8})}\n r = Math.sqrt(${s("d{var} * d{var}",{join:" + "})});\n\n if (r === 0) {\n // Sorry about code duplication. I don't want to create many functions\n // right away. Just want to see performance first.\n ${s("d{var} = (random.nextDouble() - 0.5) / 50;",{indent:10})}\n r = Math.sqrt(${s("d{var} * d{var}",{join:" + "})});\n }\n // If s / r < θ, treat this internal node as a single body, and calculate the\n // force it exerts on sourceBody, and add this amount to sourceBody's net force.\n if ((node.max_${n(0)} - node.min_${n(0)}) / r < theta) {\n // in the if statement above we consider node's width only\n // because the region was made into square during tree creation.\n // Thus there is no difference between using width or height.\n v = gravity * node.mass * sourceBody.mass / (r * r * r);\n ${s("f{var} += v * d{var};",{indent:10})}\n } else {\n // Otherwise, run the procedure recursively on each of the current node's children.\n\n // I intentionally unfolded this loop, to save several CPU cycles.\n${function(){let t=Array(11).join(" "),n=[];for(let e=0;e<f;++e)n.push(t+`if (node.quad${e}) {`),n.push(t+` queue[pushIdx] = node.quad${e};`),n.push(t+" queueLength += 1;"),n.push(t+" pushIdx += 1;"),n.push(t+"}");return n.join("\n")}()}\n }\n }\n }\n\n ${s("sourceBody.force.{var} += f{var};",{indent:4})}\n }\n\n function insertBodies(bodies) {\n ${s("var {var}min = Number.MAX_VALUE;",{indent:4})}\n ${s("var {var}max = Number.MIN_VALUE;",{indent:4})}\n var i = bodies.length;\n\n // To reduce quad tree depth we are looking for exact bounding box of all particles.\n while (i--) {\n var pos = bodies[i].pos;\n ${s("if (pos.{var} < {var}min) {var}min = pos.{var};",{indent:6})}\n ${s("if (pos.{var} > {var}max) {var}max = pos.{var};",{indent:6})}\n }\n\n // Makes the bounds square.\n var maxSideLength = -Infinity;\n ${s("if ({var}max - {var}min > maxSideLength) maxSideLength = {var}max - {var}min ;",{indent:4})}\n\n currentInCache = 0;\n root = newNode();\n ${s("root.min_{var} = {var}min;",{indent:4})}\n ${s("root.max_{var} = {var}min + maxSideLength;",{indent:4})}\n\n i = bodies.length - 1;\n if (i >= 0) {\n root.body = bodies[i];\n }\n while (i--) {\n insert(bodies[i], root);\n }\n }\n\n function insert(newBody) {\n insertStack.reset();\n insertStack.push(root, newBody);\n\n while (!insertStack.isEmpty()) {\n var stackItem = insertStack.pop();\n var node = stackItem.node;\n var body = stackItem.body;\n\n if (!node.body) {\n // This is internal node. Update the total mass of the node and center-of-mass.\n ${s("var {var} = body.pos.{var};",{indent:8})}\n node.mass += body.mass;\n ${s("node.mass_{var} += body.mass * {var};",{indent:8})}\n\n // Recursively insert the body in the appropriate quadrant.\n // But first find the appropriate quadrant.\n var quadIdx = 0; // Assume we are in the 0's quad.\n ${s("var min_{var} = node.min_{var};",{indent:8})}\n ${s("var max_{var} = (min_{var} + node.max_{var}) / 2;",{indent:8})}\n\n${function(){let t=[],r=Array(8+1).join(" ");for(let i=0;i<e;++i)t.push(r+`if (${n(i)} > max_${n(i)}) {`),t.push(r+` quadIdx = quadIdx + ${Math.pow(2,i)};`),t.push(r+` min_${n(i)} = max_${n(i)};`),t.push(r+` max_${n(i)} = node.max_${n(i)};`),t.push(r+"}");return t.join("\n")}()}\n\n var child = getChild(node, quadIdx);\n\n if (!child) {\n // The node is internal but this quadrant is not taken. Add\n // subnode to it.\n child = newNode();\n ${s("child.min_{var} = min_{var};",{indent:10})}\n ${s("child.max_{var} = max_{var};",{indent:10})}\n child.body = body;\n\n setChild(node, quadIdx, child);\n } else {\n // continue searching in this quadrant.\n insertStack.push(child, body);\n }\n } else {\n // We are trying to add to the leaf node.\n // We have to convert current leaf into internal node\n // and continue adding two nodes.\n var oldBody = node.body;\n node.body = null; // internal nodes do not cary bodies\n\n if (isSamePosition(oldBody.pos, body.pos)) {\n // Prevent infinite subdivision by bumping one node\n // anywhere in this quadrant\n var retriesCount = 3;\n do {\n var offset = random.nextDouble();\n ${s("var d{var} = (node.max_{var} - node.min_{var}) * offset;",{indent:12})}\n\n ${s("oldBody.pos.{var} = node.min_{var} + d{var};",{indent:12})}\n retriesCount -= 1;\n // Make sure we don't bump it out of the box. If we do, next iteration should fix it\n } while (retriesCount > 0 && isSamePosition(oldBody.pos, body.pos));\n\n if (retriesCount === 0 && isSamePosition(oldBody.pos, body.pos)) {\n // This is very bad, we ran out of precision.\n // if we do not return from the method we'll get into\n // infinite loop here. So we sacrifice correctness of layout, and keep the app running\n // Next layout iteration should get larger bounding box in the first step and fix this\n return;\n }\n }\n // Next iteration should subdivide node further.\n insertStack.push(node, oldBody);\n insertStack.push(node, body);\n }\n }\n }\n}\nreturn createQuadTree;\n\n`}function r(n){let e=t(n);return`\n function isSamePosition(point1, point2) {\n ${e("var d{var} = Math.abs(point1.{var} - point2.{var});",{indent:2})}\n \n return ${e("d{var} < 1e-8",{join:" && "})};\n } \n`}function i(t){var n=Math.pow(2,t);return`\nfunction setChild(node, idx, child) {\n ${function(){let t=[];for(let e=0;e<n;++e){let n=0===e?" ":" else ";t.push(`${n}if (idx === ${e}) node.quad${e} = child;`)}return t.join("\n")}()}\n}`}function o(t){return`function getChild(node, idx) {\n${function(){let n=[],e=Math.pow(2,t);for(let t=0;t<e;++t)n.push(` if (idx === ${t}) return n