3d-force-graph-ar
Version:
UI component for a 3D force-directed graph in AR
2 lines • 123 kB
JavaScript
// Version 1.10.0 3d-force-graph-ar - https://github.com/vasturiano/3d-force-graph-ar
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("three")):"function"==typeof define&&define.amd?define(["three"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).ForceGraphAR=e(t.THREE)}(this,function(t){"use strict";function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function n(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function r(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function i(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?r(Object(i),!0).forEach(function(e){n(t,e,i[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))})}return t}function o(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,i,o,a,u=[],s=!0,l=!1;try{if(o=(n=n.call(t)).next,0===e);else for(;!(s=(r=o.call(n)).done)&&(u.push(r.value),u.length!==e);s=!0);}catch(t){l=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(l)throw i}}return u}}(t,e)||u(t,e)||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 a(t){return function(t){if(Array.isArray(t))return e(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||u(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 u(t,n){if(t){if("string"==typeof t)return e(t,n);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)?e(t,n):void 0}}function s(t,e,n){var r,i=1;function o(){var o,a,u=r.length,s=0,l=0,c=0;for(o=0;o<u;++o)s+=(a=r[o]).x||0,l+=a.y||0,c+=a.z||0;for(s=(s/u-t)*i,l=(l/u-e)*i,c=(c/u-n)*i,o=0;o<u;++o)a=r[o],s&&(a.x-=s),l&&(a.y-=l),c&&(a.z-=c)}return null==t&&(t=0),null==e&&(e=0),null==n&&(n=0),o.initialize=function(t){r=t},o.x=function(e){return arguments.length?(t=+e,o):t},o.y=function(t){return arguments.length?(e=+t,o):e},o.z=function(t){return arguments.length?(n=+t,o):n},o.strength=function(t){return arguments.length?(i=+t,o):i},o}function l(t,e,n){if(isNaN(e))return t;var r,i,o,a,u,s,l=t._root,c={data:n},f=t._x0,d=t._x1;if(!l)return t._root=c,t;for(;l.length;)if((a=e>=(i=(f+d)/2))?f=i:d=i,r=l,!(l=l[u=+a]))return r[u]=c,t;if(e===(o=+t._x.call(null,l.data)))return c.next=l,r?r[u]=c:t._root=c,t;do{r=r?r[u]=new Array(2):t._root=new Array(2),(a=e>=(i=(f+d)/2))?f=i:d=i}while((u=+a)===(s=+(o>=i)));return r[s]=l,r[u]=c,t}function c(t,e,n){this.node=t,this.x0=e,this.x1=n}function f(t){return t[0]}function d(t,e){var n=new h(null==e?f:e,NaN,NaN);return null==t?n:n.addAll(t)}function h(t,e,n){this._x=t,this._x0=e,this._x1=n,this._root=void 0}function p(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var g=d.prototype=h.prototype;function v(t,e,n,r){if(isNaN(e)||isNaN(n))return t;var i,o,a,u,s,l,c,f,d,h=t._root,p={data:r},g=t._x0,v=t._y0,y=t._x1,b=t._y1;if(!h)return t._root=p,t;for(;h.length;)if((l=e>=(o=(g+y)/2))?g=o:y=o,(c=n>=(a=(v+b)/2))?v=a:b=a,i=h,!(h=h[f=c<<1|l]))return i[f]=p,t;if(u=+t._x.call(null,h.data),s=+t._y.call(null,h.data),e===u&&n===s)return p.next=h,i?i[f]=p:t._root=p,t;do{i=i?i[f]=new Array(4):t._root=new Array(4),(l=e>=(o=(g+y)/2))?g=o:y=o,(c=n>=(a=(v+b)/2))?v=a:b=a}while((f=c<<1|l)==(d=(s>=a)<<1|u>=o));return i[d]=h,i[f]=p,t}function y(t,e,n,r,i){this.node=t,this.x0=e,this.y0=n,this.x1=r,this.y1=i}function b(t){return t[0]}function m(t){return t[1]}function w(t,e,n){var r=new _(null==e?b:e,null==n?m:n,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function _(t,e,n,r,i,o){this._x=t,this._y=e,this._x0=n,this._y0=r,this._x1=i,this._y1=o,this._root=void 0}function x(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}g.copy=function(){var t,e,n=new h(this._x,this._x0,this._x1),r=this._root;if(!r)return n;if(!r.length)return n._root=p(r),n;for(t=[{source:r,target:n._root=new Array(2)}];r=t.pop();)for(var i=0;i<2;++i)(e=r.source[i])&&(e.length?t.push({source:e,target:r.target[i]=new Array(2)}):r.target[i]=p(e));return n},g.add=function(t){const e=+this._x.call(null,t);return l(this.cover(e),e,t)},g.addAll=function(t){Array.isArray(t)||(t=Array.from(t));const e=t.length,n=new Float64Array(e);let r=1/0,i=-1/0;for(let o,a=0;a<e;++a)isNaN(o=+this._x.call(null,t[a]))||(n[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<e;++r)l(this,n[r],t[r]);return this},g.cover=function(t){if(isNaN(t=+t))return this;var e=this._x0,n=this._x1;if(isNaN(e))n=(e=Math.floor(t))+1;else{for(var r,i,o=n-e||1,a=this._root;e>t||t>=n;)switch(i=+(t<e),(r=new Array(2))[i]=a,a=r,o*=2,i){case 0:n=e+o;break;case 1:e=n-o}this._root&&this._root.length&&(this._root=a)}return this._x0=e,this._x1=n,this},g.data=function(){var t=[];return this.visit(function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)}),t},g.extent=function(t){return arguments.length?this.cover(+t[0][0]).cover(+t[1][0]):isNaN(this._x0)?void 0:[[this._x0],[this._x1]]},g.find=function(t,e){var n,r,i,o,a,u=this._x0,s=this._x1,l=[],f=this._root;for(f&&l.push(new c(f,u,s)),null==e?e=1/0:(u=t-e,s=t+e);o=l.pop();)if(!(!(f=o.node)||(r=o.x0)>s||(i=o.x1)<u))if(f.length){var d=(r+i)/2;l.push(new c(f[1],d,i),new c(f[0],r,d)),(a=+(t>=d))&&(o=l[l.length-1],l[l.length-1]=l[l.length-1-a],l[l.length-1-a]=o)}else{var h=Math.abs(t-+this._x.call(null,f.data));h<e&&(e=h,u=t-h,s=t+h,n=f.data)}return n},g.remove=function(t){if(isNaN(o=+this._x.call(null,t)))return this;var e,n,r,i,o,a,u,s,l,c=this._root,f=this._x0,d=this._x1;if(!c)return this;if(c.length)for(;;){if((u=o>=(a=(f+d)/2))?f=a:d=a,e=c,!(c=c[s=+u]))return this;if(!c.length)break;e[s+1&1]&&(n=e,l=s)}for(;c.data!==t;)if(r=c,!(c=c.next))return this;return(i=c.next)&&delete c.next,r?(i?r.next=i:delete r.next,this):e?(i?e[s]=i:delete e[s],(c=e[0]||e[1])&&c===(e[1]||e[0])&&!c.length&&(n?n[l]=c:this._root=c),this):(this._root=i,this)},g.removeAll=function(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this},g.root=function(){return this._root},g.size=function(){var t=0;return this.visit(function(e){if(!e.length)do{++t}while(e=e.next)}),t},g.visit=function(t){var e,n,r,i,o=[],a=this._root;for(a&&o.push(new c(a,this._x0,this._x1));e=o.pop();)if(!t(a=e.node,r=e.x0,i=e.x1)&&a.length){var u=(r+i)/2;(n=a[1])&&o.push(new c(n,u,i)),(n=a[0])&&o.push(new c(n,r,u))}return this},g.visitAfter=function(t){var e,n=[],r=[];for(this._root&&n.push(new c(this._root,this._x0,this._x1));e=n.pop();){var i=e.node;if(i.length){var o,a=e.x0,u=e.x1,s=(a+u)/2;(o=i[0])&&n.push(new c(o,a,s)),(o=i[1])&&n.push(new c(o,s,u))}r.push(e)}for(;e=r.pop();)t(e.node,e.x0,e.x1);return this},g.x=function(t){return arguments.length?(this._x=t,this):this._x};var k=w.prototype=_.prototype;function M(t,e,n,r,i){if(isNaN(e)||isNaN(n)||isNaN(r))return t;var o,a,u,s,l,c,f,d,h,p,g,v,y=t._root,b={data:i},m=t._x0,w=t._y0,_=t._z0,x=t._x1,k=t._y1,M=t._z1;if(!y)return t._root=b,t;for(;y.length;)if((d=e>=(a=(m+x)/2))?m=a:x=a,(h=n>=(u=(w+k)/2))?w=u:k=u,(p=r>=(s=(_+M)/2))?_=s:M=s,o=y,!(y=y[g=p<<2|h<<1|d]))return o[g]=b,t;if(l=+t._x.call(null,y.data),c=+t._y.call(null,y.data),f=+t._z.call(null,y.data),e===l&&n===c&&r===f)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),(d=e>=(a=(m+x)/2))?m=a:x=a,(h=n>=(u=(w+k)/2))?w=u:k=u,(p=r>=(s=(_+M)/2))?_=s:M=s}while((g=p<<2|h<<1|d)==(v=(f>=s)<<2|(c>=u)<<1|l>=a));return o[v]=y,o[g]=b,t}function O(t,e,n,r,i,o,a){this.node=t,this.x0=e,this.y0=n,this.z0=r,this.x1=i,this.y1=o,this.z1=a}k.copy=function(){var t,e,n=new _(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return n;if(!r.length)return n._root=x(r),n;for(t=[{source:r,target:n._root=new Array(4)}];r=t.pop();)for(var i=0;i<4;++i)(e=r.source[i])&&(e.length?t.push({source:e,target:r.target[i]=new Array(4)}):r.target[i]=x(e));return n},k.add=function(t){const e=+this._x.call(null,t),n=+this._y.call(null,t);return v(this.cover(e,n),e,n,t)},k.addAll=function(t){var e,n,r,i,o=t.length,a=new Array(o),u=new Array(o),s=1/0,l=1/0,c=-1/0,f=-1/0;for(n=0;n<o;++n)isNaN(r=+this._x.call(null,e=t[n]))||isNaN(i=+this._y.call(null,e))||(a[n]=r,u[n]=i,r<s&&(s=r),r>c&&(c=r),i<l&&(l=i),i>f&&(f=i));if(s>c||l>f)return this;for(this.cover(s,l).cover(c,f),n=0;n<o;++n)v(this,a[n],u[n],t[n]);return this},k.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,r=this._y0,i=this._x1,o=this._y1;if(isNaN(n))i=(n=Math.floor(t))+1,o=(r=Math.floor(e))+1;else{for(var a,u,s=i-n||1,l=this._root;n>t||t>=i||r>e||e>=o;)switch(u=(e<r)<<1|t<n,(a=new Array(4))[u]=l,l=a,s*=2,u){case 0:i=n+s,o=r+s;break;case 1:n=i-s,o=r+s;break;case 2:i=n+s,r=o-s;break;case 3:n=i-s,r=o-s}this._root&&this._root.length&&(this._root=l)}return this._x0=n,this._y0=r,this._x1=i,this._y1=o,this},k.data=function(){var t=[];return this.visit(function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)}),t},k.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]]},k.find=function(t,e,n){var r,i,o,a,u,s,l,c=this._x0,f=this._y0,d=this._x1,h=this._y1,p=[],g=this._root;for(g&&p.push(new y(g,c,f,d,h)),null==n?n=1/0:(c=t-n,f=e-n,d=t+n,h=e+n,n*=n);s=p.pop();)if(!(!(g=s.node)||(i=s.x0)>d||(o=s.y0)>h||(a=s.x1)<c||(u=s.y1)<f))if(g.length){var v=(i+a)/2,b=(o+u)/2;p.push(new y(g[3],v,b,a,u),new y(g[2],i,b,v,u),new y(g[1],v,o,a,b),new y(g[0],i,o,v,b)),(l=(e>=b)<<1|t>=v)&&(s=p[p.length-1],p[p.length-1]=p[p.length-1-l],p[p.length-1-l]=s)}else{var m=t-+this._x.call(null,g.data),w=e-+this._y.call(null,g.data),_=m*m+w*w;if(_<n){var x=Math.sqrt(n=_);c=t-x,f=e-x,d=t+x,h=e+x,r=g.data}}return r},k.remove=function(t){if(isNaN(o=+this._x.call(null,t))||isNaN(a=+this._y.call(null,t)))return this;var e,n,r,i,o,a,u,s,l,c,f,d,h=this._root,p=this._x0,g=this._y0,v=this._x1,y=this._y1;if(!h)return this;if(h.length)for(;;){if((l=o>=(u=(p+v)/2))?p=u:v=u,(c=a>=(s=(g+y)/2))?g=s:y=s,e=h,!(h=h[f=c<<1|l]))return this;if(!h.length)break;(e[f+1&3]||e[f+2&3]||e[f+3&3])&&(n=e,d=f)}for(;h.data!==t;)if(r=h,!(h=h.next))return this;return(i=h.next)&&delete h.next,r?(i?r.next=i:delete r.next,this):e?(i?e[f]=i:delete e[f],(h=e[0]||e[1]||e[2]||e[3])&&h===(e[3]||e[2]||e[1]||e[0])&&!h.length&&(n?n[d]=h:this._root=h),this):(this._root=i,this)},k.removeAll=function(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this},k.root=function(){return this._root},k.size=function(){var t=0;return this.visit(function(e){if(!e.length)do{++t}while(e=e.next)}),t},k.visit=function(t){var e,n,r,i,o,a,u=[],s=this._root;for(s&&u.push(new y(s,this._x0,this._y0,this._x1,this._y1));e=u.pop();)if(!t(s=e.node,r=e.x0,i=e.y0,o=e.x1,a=e.y1)&&s.length){var l=(r+o)/2,c=(i+a)/2;(n=s[3])&&u.push(new y(n,l,c,o,a)),(n=s[2])&&u.push(new y(n,r,c,l,a)),(n=s[1])&&u.push(new y(n,l,i,o,c)),(n=s[0])&&u.push(new y(n,r,i,l,c))}return this},k.visitAfter=function(t){var e,n=[],r=[];for(this._root&&n.push(new y(this._root,this._x0,this._y0,this._x1,this._y1));e=n.pop();){var i=e.node;if(i.length){var o,a=e.x0,u=e.y0,s=e.x1,l=e.y1,c=(a+s)/2,f=(u+l)/2;(o=i[0])&&n.push(new y(o,a,u,c,f)),(o=i[1])&&n.push(new y(o,c,u,s,f)),(o=i[2])&&n.push(new y(o,a,f,c,l)),(o=i[3])&&n.push(new y(o,c,f,s,l))}r.push(e)}for(;e=r.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},k.x=function(t){return arguments.length?(this._x=t,this):this._x},k.y=function(t){return arguments.length?(this._y=t,this):this._y};const A=(t,e,n,r,i,o)=>Math.sqrt((t-r)**2+(e-i)**2+(n-o)**2);function j(t){return t[0]}function P(t){return t[1]}function D(t){return t[2]}function C(t,e,n,r){var i=new E(null==e?j:e,null==n?P:n,null==r?D:r,NaN,NaN,NaN,NaN,NaN,NaN);return null==t?i:i.addAll(t)}function E(t,e,n,r,i,o,a,u,s){this._x=t,this._y=e,this._z=n,this._x0=r,this._y0=i,this._z0=o,this._x1=a,this._y1=u,this._z1=s,this._root=void 0}function S(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var N=C.prototype=E.prototype;function T(t){return function(){return t}}function z(t){return 1e-6*(t()-.5)}function B(t){return t.index}function R(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function I(t){var e,n,r,i,o,a,u,s=B,l=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},c=T(30),f=1;function d(r){for(var o=0,s=t.length;o<f;++o)for(var l,c,d,h,p,g=0,v=0,y=0,b=0;g<s;++g)c=(l=t[g]).source,v=(d=l.target).x+d.vx-c.x-c.vx||z(u),i>1&&(y=d.y+d.vy-c.y-c.vy||z(u)),i>2&&(b=d.z+d.vz-c.z-c.vz||z(u)),v*=h=((h=Math.sqrt(v*v+y*y+b*b))-n[g])/h*r*e[g],y*=h,b*=h,d.vx-=v*(p=a[g]),i>1&&(d.vy-=y*p),i>2&&(d.vz-=b*p),c.vx+=v*(p=1-p),i>1&&(c.vy+=y*p),i>2&&(c.vz+=b*p)}function h(){if(r){var i,u,l=r.length,c=t.length,f=new Map(r.map((t,e)=>[s(t,e,r),t]));for(i=0,o=new Array(l);i<c;++i)(u=t[i]).index=i,"object"!=typeof u.source&&(u.source=R(f,u.source)),"object"!=typeof u.target&&(u.target=R(f,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(c);i<c;++i)u=t[i],a[i]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);e=new Array(c),p(),n=new Array(c),g()}}function p(){if(r)for(var n=0,i=t.length;n<i;++n)e[n]=+l(t[n],n,t)}function g(){if(r)for(var e=0,i=t.length;e<i;++e)n[e]=+c(t[e],e,t)}return null==t&&(t=[]),d.initialize=function(t,...e){r=t,u=e.find(t=>"function"==typeof t)||Math.random,i=e.find(t=>[1,2,3].includes(t))||2,h()},d.links=function(e){return arguments.length?(t=e,h(),d):t},d.id=function(t){return arguments.length?(s=t,d):s},d.iterations=function(t){return arguments.length?(f=+t,d):f},d.strength=function(t){return arguments.length?(l="function"==typeof t?t:T(+t),p(),d):l},d.distance=function(t){return arguments.length?(c="function"==typeof t?t:T(+t),g(),d):c},d}N.copy=function(){var t,e,n=new E(this._x,this._y,this._z,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1),r=this._root;if(!r)return n;if(!r.length)return n._root=S(r),n;for(t=[{source:r,target:n._root=new Array(8)}];r=t.pop();)for(var i=0;i<8;++i)(e=r.source[i])&&(e.length?t.push({source:e,target:r.target[i]=new Array(8)}):r.target[i]=S(e));return n},N.add=function(t){const e=+this._x.call(null,t),n=+this._y.call(null,t),r=+this._z.call(null,t);return M(this.cover(e,n,r),e,n,r,t)},N.addAll=function(t){Array.isArray(t)||(t=Array.from(t));const e=t.length,n=new Float64Array(e),r=new Float64Array(e),i=new Float64Array(e);let o=1/0,a=1/0,u=1/0,s=-1/0,l=-1/0,c=-1/0;for(let f,d,h,p,g=0;g<e;++g)isNaN(d=+this._x.call(null,f=t[g]))||isNaN(h=+this._y.call(null,f))||isNaN(p=+this._z.call(null,f))||(n[g]=d,r[g]=h,i[g]=p,d<o&&(o=d),d>s&&(s=d),h<a&&(a=h),h>l&&(l=h),p<u&&(u=p),p>c&&(c=p));if(o>s||a>l||u>c)return this;this.cover(o,a,u).cover(s,l,c);for(let o=0;o<e;++o)M(this,n[o],r[o],i[o],t[o]);return this},N.cover=function(t,e,n){if(isNaN(t=+t)||isNaN(e=+e)||isNaN(n=+n))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(e))+1,s=(o=Math.floor(n))+1;else{for(var l,c,f=a-r||1,d=this._root;r>t||t>=a||i>e||e>=u||o>n||n>=s;)switch(c=(n<o)<<2|(e<i)<<1|t<r,(l=new Array(8))[c]=d,d=l,f*=2,c){case 0:a=r+f,u=i+f,s=o+f;break;case 1:r=a-f,u=i+f,s=o+f;break;case 2:a=r+f,i=u-f,s=o+f;break;case 3:r=a-f,i=u-f,s=o+f;break;case 4:a=r+f,u=i+f,o=s-f;break;case 5:r=a-f,u=i+f,o=s-f;break;case 6:a=r+f,i=u-f,o=s-f;break;case 7:r=a-f,i=u-f,o=s-f}this._root&&this._root.length&&(this._root=d)}return this._x0=r,this._y0=i,this._z0=o,this._x1=a,this._y1=u,this._z1=s,this},N.data=function(){var t=[];return this.visit(function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)}),t},N.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]]},N.find=function(t,e,n,r){var i,o,a,u,s,l,c,f,d,h=this._x0,p=this._y0,g=this._z0,v=this._x1,y=this._y1,b=this._z1,m=[],w=this._root;for(w&&m.push(new O(w,h,p,g,v,y,b)),null==r?r=1/0:(h=t-r,p=e-r,g=n-r,v=t+r,y=e+r,b=n+r,r*=r);f=m.pop();)if(!(!(w=f.node)||(o=f.x0)>v||(a=f.y0)>y||(u=f.z0)>b||(s=f.x1)<h||(l=f.y1)<p||(c=f.z1)<g))if(w.length){var _=(o+s)/2,x=(a+l)/2,k=(u+c)/2;m.push(new O(w[7],_,x,k,s,l,c),new O(w[6],o,x,k,_,l,c),new O(w[5],_,a,k,s,x,c),new O(w[4],o,a,k,_,x,c),new O(w[3],_,x,u,s,l,k),new O(w[2],o,x,u,_,l,k),new O(w[1],_,a,u,s,x,k),new O(w[0],o,a,u,_,x,k)),(d=(n>=k)<<2|(e>=x)<<1|t>=_)&&(f=m[m.length-1],m[m.length-1]=m[m.length-1-d],m[m.length-1-d]=f)}else{var M=t-+this._x.call(null,w.data),A=e-+this._y.call(null,w.data),j=n-+this._z.call(null,w.data),P=M*M+A*A+j*j;if(P<r){var D=Math.sqrt(r=P);h=t-D,p=e-D,g=n-D,v=t+D,y=e+D,b=n+D,i=w.data}}return i},N.findAllWithinRadius=function(t,e,n,r){const i=[],o=t-r,a=e-r,u=n-r,s=t+r,l=e+r,c=n+r;return this.visit((f,d,h,p,g,v,y)=>{if(!f.length)do{const o=f.data;A(t,e,n,this._x(o),this._y(o),this._z(o))<=r&&i.push(o)}while(f=f.next);return d>s||h>l||p>c||g<o||v<a||y<u}),i},N.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 e,n,r,i,o,a,u,s,l,c,f,d,h,p,g,v=this._root,y=this._x0,b=this._y0,m=this._z0,w=this._x1,_=this._y1,x=this._z1;if(!v)return this;if(v.length)for(;;){if((f=o>=(s=(y+w)/2))?y=s:w=s,(d=a>=(l=(b+_)/2))?b=l:_=l,(h=u>=(c=(m+x)/2))?m=c:x=c,e=v,!(v=v[p=h<<2|d<<1|f]))return this;if(!v.length)break;(e[p+1&7]||e[p+2&7]||e[p+3&7]||e[p+4&7]||e[p+5&7]||e[p+6&7]||e[p+7&7])&&(n=e,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):e?(i?e[p]=i:delete e[p],(v=e[0]||e[1]||e[2]||e[3]||e[4]||e[5]||e[6]||e[7])&&v===(e[7]||e[6]||e[5]||e[4]||e[3]||e[2]||e[1]||e[0])&&!v.length&&(n?n[g]=v:this._root=v),this):(this._root=i,this)},N.removeAll=function(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this},N.root=function(){return this._root},N.size=function(){var t=0;return this.visit(function(e){if(!e.length)do{++t}while(e=e.next)}),t},N.visit=function(t){var e,n,r,i,o,a,u,s,l=[],c=this._root;for(c&&l.push(new O(c,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));e=l.pop();)if(!t(c=e.node,r=e.x0,i=e.y0,o=e.z0,a=e.x1,u=e.y1,s=e.z1)&&c.length){var f=(r+a)/2,d=(i+u)/2,h=(o+s)/2;(n=c[7])&&l.push(new O(n,f,d,h,a,u,s)),(n=c[6])&&l.push(new O(n,r,d,h,f,u,s)),(n=c[5])&&l.push(new O(n,f,i,h,a,d,s)),(n=c[4])&&l.push(new O(n,r,i,h,f,d,s)),(n=c[3])&&l.push(new O(n,f,d,o,a,u,h)),(n=c[2])&&l.push(new O(n,r,d,o,f,u,h)),(n=c[1])&&l.push(new O(n,f,i,o,a,d,h)),(n=c[0])&&l.push(new O(n,r,i,o,f,d,h))}return this},N.visitAfter=function(t){var e,n=[],r=[];for(this._root&&n.push(new O(this._root,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));e=n.pop();){var i=e.node;if(i.length){var o,a=e.x0,u=e.y0,s=e.z0,l=e.x1,c=e.y1,f=e.z1,d=(a+l)/2,h=(u+c)/2,p=(s+f)/2;(o=i[0])&&n.push(new O(o,a,u,s,d,h,p)),(o=i[1])&&n.push(new O(o,d,u,s,l,h,p)),(o=i[2])&&n.push(new O(o,a,h,s,d,c,p)),(o=i[3])&&n.push(new O(o,d,h,s,l,c,p)),(o=i[4])&&n.push(new O(o,a,u,p,d,h,f)),(o=i[5])&&n.push(new O(o,d,u,p,l,h,f)),(o=i[6])&&n.push(new O(o,a,h,p,d,c,f)),(o=i[7])&&n.push(new O(o,d,h,p,l,c,f))}r.push(e)}for(;e=r.pop();)t(e.node,e.x0,e.y0,e.z0,e.x1,e.y1,e.z1);return this},N.x=function(t){return arguments.length?(this._x=t,this):this._x},N.y=function(t){return arguments.length?(this._y=t,this):this._y},N.z=function(t){return arguments.length?(this._z=t,this):this._z};var L={value:()=>{}};function $(){for(var t,e=0,n=arguments.length,r={};e<n;++e){if(!(t=arguments[e]+"")||t in r||/[\s.]/.test(t))throw new Error("illegal type: "+t);r[t]=[]}return new F(r)}function F(t){this._=t}function q(t,e){for(var n,r=0,i=t.length;r<i;++r)if((n=t[r]).name===e)return n.value}function U(t,e,n){for(var r=0,i=t.length;r<i;++r)if(t[r].name===e){t[r]=L,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=n&&t.push({name:e,value:n}),t}F.prototype=$.prototype={constructor:F,on:function(t,e){var n,r,i=this._,o=(r=i,(t+"").trim().split(/^|\s+/).map(function(t){var e="",n=t.indexOf(".");if(n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),a=-1,u=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++a<u;)if(n=(t=o[a]).type)i[n]=U(i[n],t.name,e);else if(null==e)for(n in i)i[n]=U(i[n],t.name,null);return this}for(;++a<u;)if((n=(t=o[a]).type)&&(n=q(i[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new F(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,r,i=new Array(n),o=0;o<n;++o)i[o]=arguments[o+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(o=0,n=(r=this._[t]).length;o<n;++o)r[o].value.apply(e,i)},apply:function(t,e,n){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(e,n)}};var G,V,H=0,W=0,Q=0,J=0,X=0,Y=0,K="object"==typeof performance&&performance.now?performance:Date,Z="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function tt(){return X||(Z(et),X=K.now()+Y)}function et(){X=0}function nt(){this._call=this._time=this._next=null}function rt(t,e,n){var r=new nt;return r.restart(t,e,n),r}function it(){X=(J=K.now())+Y,H=W=0;try{!function(){tt(),++H;for(var t,e=G;e;)(t=X-e._time)>=0&&e._call.call(void 0,t),e=e._next;--H}()}finally{H=0,function(){var t,e,n=G,r=1/0;for(;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:G=e);V=t,at(r)}(),X=0}}function ot(){var t=K.now(),e=t-J;e>1e3&&(Y-=e,J=t)}function at(t){H||(W&&(W=clearTimeout(W)),t-X>24?(t<1/0&&(W=setTimeout(it,t-K.now()-Y)),Q&&(Q=clearInterval(Q))):(Q||(J=K.now(),Q=setInterval(ot,1e3)),H=1,Z(it)))}nt.prototype=rt.prototype={constructor:nt,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?tt():+n)+(null==e?0:+e),this._next||V===this||(V?V._next=this:G=this,V=this),this._call=t,this._time=n,at()},stop:function(){this._call&&(this._call=null,this._time=1/0,at())}};const ut=4294967296;function st(t){return t.x}function lt(t){return t.y}function ct(t){return t.z}var ft,dt,ht,pt,gt=Math.PI*(3-Math.sqrt(5)),vt=20*Math.PI/(9+Math.sqrt(221));function yt(t,e){e=e||2;var n,r=Math.min(3,Math.max(1,Math.round(e))),i=1,o=.001,a=1-Math.pow(o,1/300),u=0,s=.6,l=new Map,c=rt(h),f=$("tick","end"),d=function(){let t=1;return()=>(t=(1664525*t+1013904223)%ut)/ut}();function h(){p(),f.call("tick",n),i<o&&(c.stop(),f.call("end",n))}function p(e){var o,c,f=t.length;void 0===e&&(e=1);for(var d=0;d<e;++d)for(i+=(u-i)*a,l.forEach(function(t){t(i)}),o=0;o<f;++o)null==(c=t[o]).fx?c.x+=c.vx*=s:(c.x=c.fx,c.vx=0),r>1&&(null==c.fy?c.y+=c.vy*=s:(c.y=c.fy,c.vy=0)),r>2&&(null==c.fz?c.z+=c.vz*=s:(c.z=c.fz,c.vz=0));return n}function g(){for(var e,n=0,i=t.length;n<i;++n){if((e=t[n]).index=n,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),null!=e.fz&&(e.z=e.fz),isNaN(e.x)||r>1&&isNaN(e.y)||r>2&&isNaN(e.z)){var o=10*(r>2?Math.cbrt(.5+n):r>1?Math.sqrt(.5+n):n),a=n*gt,u=n*vt;1===r?e.x=o:2===r?(e.x=o*Math.cos(a),e.y=o*Math.sin(a)):(e.x=o*Math.sin(a)*Math.cos(u),e.y=o*Math.cos(a),e.z=o*Math.sin(a)*Math.sin(u))}(isNaN(e.vx)||r>1&&isNaN(e.vy)||r>2&&isNaN(e.vz))&&(e.vx=0,r>1&&(e.vy=0),r>2&&(e.vz=0))}}function v(e){return e.initialize&&e.initialize(t,d,r),e}return null==t&&(t=[]),g(),n={tick:p,restart:function(){return c.restart(h),n},stop:function(){return c.stop(),n},numDimensions:function(t){return arguments.length?(r=Math.min(3,Math.max(1,Math.round(t))),l.forEach(v),n):r},nodes:function(e){return arguments.length?(t=e,g(),l.forEach(v),n):t},alpha:function(t){return arguments.length?(i=+t,n):i},alphaMin:function(t){return arguments.length?(o=+t,n):o},alphaDecay:function(t){return arguments.length?(a=+t,n):+a},alphaTarget:function(t){return arguments.length?(u=+t,n):u},velocityDecay:function(t){return arguments.length?(s=1-t,n):1-s},randomSource:function(t){return arguments.length?(d=t,l.forEach(v),n):d},force:function(t,e){return arguments.length>1?(null==e?l.delete(t):l.set(t,v(e)),n):l.get(t)},find:function(){var e,n,i,o,a,u,s=Array.prototype.slice.call(arguments),l=s.shift()||0,c=(r>1?s.shift():null)||0,f=(r>2?s.shift():null)||0,d=s.shift()||1/0,h=0,p=t.length;for(d*=d,h=0;h<p;++h)(o=(e=l-(a=t[h]).x)*e+(n=c-(a.y||0))*n+(i=f-(a.z||0))*i)<d&&(u=a,d=o);return u},on:function(t,e){return arguments.length>1?(f.on(t,e),n):f.on(t)}}}function bt(){var t,e,n,r,i,o,a=T(-30),u=1,s=1/0,l=.81;function c(r){var o,a=t.length,u=(1===e?d(t,st):2===e?w(t,st,lt):3===e?C(t,st,lt,ct):null).visitAfter(h);for(i=r,o=0;o<a;++o)n=t[o],u.visit(p)}function f(){if(t){var e,n,r=t.length;for(o=new Array(r),e=0;e<r;++e)n=t[e],o[n.index]=+a(n,e,t)}}function h(t){var n,r,i,a,u,s,l=0,c=0,f=t.length;if(f){for(i=a=u=s=0;s<f;++s)(n=t[s])&&(r=Math.abs(n.value))&&(l+=n.value,c+=r,i+=r*(n.x||0),a+=r*(n.y||0),u+=r*(n.z||0));l*=Math.sqrt(4/f),t.x=i/c,e>1&&(t.y=a/c),e>2&&(t.z=u/c)}else{(n=t).x=n.data.x,e>1&&(n.y=n.data.y),e>2&&(n.z=n.data.z);do{l+=o[n.data.index]}while(n=n.next)}t.value=l}function p(t,a,c,f,d){if(!t.value)return!0;var h=[c,f,d][e-1],p=t.x-n.x,g=e>1?t.y-n.y:0,v=e>2?t.z-n.z:0,y=h-a,b=p*p+g*g+v*v;if(y*y/l<b)return b<s&&(0===p&&(b+=(p=z(r))*p),e>1&&0===g&&(b+=(g=z(r))*g),e>2&&0===v&&(b+=(v=z(r))*v),b<u&&(b=Math.sqrt(u*b)),n.vx+=p*t.value*i/b,e>1&&(n.vy+=g*t.value*i/b),e>2&&(n.vz+=v*t.value*i/b)),!0;if(!(t.length||b>=s)){(t.data!==n||t.next)&&(0===p&&(b+=(p=z(r))*p),e>1&&0===g&&(b+=(g=z(r))*g),e>2&&0===v&&(b+=(v=z(r))*v),b<u&&(b=Math.sqrt(u*b)));do{t.data!==n&&(y=o[t.data.index]*i/b,n.vx+=p*y,e>1&&(n.vy+=g*y),e>2&&(n.vz+=v*y))}while(t=t.next)}}return c.initialize=function(n,...i){t=n,r=i.find(t=>"function"==typeof t)||Math.random,e=i.find(t=>[1,2,3].includes(t))||2,f()},c.strength=function(t){return arguments.length?(a="function"==typeof t?t:T(+t),f(),c):a},c.distanceMin=function(t){return arguments.length?(u=t*t,c):Math.sqrt(u)},c.distanceMax=function(t){return arguments.length?(s=t*t,c):Math.sqrt(s)},c.theta=function(t){return arguments.length?(l=t*t,c):Math.sqrt(l)},c}function mt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function wt(){if(dt)return ft;return dt=1,ft=function(t){!function(t){if(!t)throw new Error("Eventify cannot use falsy object as events subject");for(var e=["on","fire","off"],n=0;n<e.length;++n)if(t.hasOwnProperty(e[n]))throw new Error("Subject cannot be eventified, since it already has property '"+e[n]+"'")}(t);var e=function(t){var e=Object.create(null);return{on:function(n,r,i){if("function"!=typeof r)throw new Error("callback is expected to be a function");var o=e[n];return o||(o=e[n]=[]),o.push({callback:r,ctx:i}),t},off:function(n,r){if(void 0===n)return e=Object.create(null),t;if(e[n])if("function"!=typeof r)delete e[n];else for(var i=e[n],o=0;o<i.length;++o)i[o].callback===r&&i.splice(o,1);return t},fire:function(n){var r,i=e[n];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=e.on,t.off=e.off,t.fire=e.fire,t},ft}var _t,xt,kt,Mt,Ot,At=function(){if(pt)return ht;pt=1,ht=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={},l=0,c=o.multigraph?function(t,e,n){var o=i(t,e),a=s.hasOwnProperty(o);if(a||O(t,e)){a||(s[o]=0);var u="@"+ ++s[o];o=i(t+u,e+u)}return new r(t,e,n,o)}:function(t,e,n){var o=i(t,e),a=u.get(o);if(a)return a.data=n,a;return new r(t,e,n,o)},f=[],d=A,h=A,p=A,g=A,v={version:20,addNode:m,addLink:function(t,e,r){p();var i=w(t)||m(t),o=w(e)||m(e),a=c(t,e,r),s=u.has(a.id);u.set(a.id,a),n(i,a),t!==e&&n(o,a);return d(a,s?"update":"add"),g(),a},removeLink:function(t,e){void 0!==e&&(t=O(t,e));return M(t)},removeNode:_,getNode:w,getNodeCount:x,getLinkCount:k,getEdgeCount:k,getLinksCount:k,getNodesCount:x,getLinks:function(t){var e=w(t);return e?e.links:null},forEachNode:D,forEachLinkedNode:function(t,e,n){var r=w(t);if(r&&r.links&&"function"==typeof e)return n?function(t,e,n){var r=t.values(),i=r.next();for(;!i.done;){var o=i.value;if(o.fromId===e&&n(a.get(o.toId),o))return!0;i=r.next()}}(r.links,t,e):function(t,e,n){var r=t.values(),i=r.next();for(;!i.done;){var o=i.value,u=o.fromId===e?o.toId:o.fromId;if(n(a.get(u),o))return!0;i=r.next()}}(r.links,t,e)},forEachLink:function(t){if("function"==typeof t)for(var e=u.values(),n=e.next();!n.done;){if(t(n.value))return!0;n=e.next()}},beginUpdate:p,endUpdate:g,clear:function(){p(),D(function(t){_(t.id)}),g()},hasLink:O,hasNode:w,getLink:O};return t(v),function(){var t=v.on;function e(){return v.beginUpdate=p=j,v.endUpdate=g=P,d=y,h=b,v.on=t,t.apply(v,arguments)}v.on=e}(),v;function y(t,e){f.push({link:t,changeType:e})}function b(t,e){f.push({node:t,changeType:e})}function m(t,n){if(void 0===t)throw new Error("Invalid node identifier");p();var r=w(t);return r?(r.data=n,h(r,"update")):(r=new e(t,n),h(r,"add")),a.set(t,r),g(),r}function w(t){return a.get(t)}function _(t){var e=w(t);if(!e)return!1;p();var n=e.links;return n&&(n.forEach(M),e.links=null),a.delete(t),h(e,"remove"),g(),!0}function x(){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 e=w(t.fromId),n=w(t.toId);return e&&e.links.delete(t),n&&n.links.delete(t),d(t,"remove"),g(),!0}function O(t,e){if(void 0!==t&&void 0!==e)return u.get(i(t,e))}function A(){}function j(){l+=1}function P(){0===(l-=1)&&f.length>0&&(v.fire("changed",f),f.length=0)}function D(t){if("function"!=typeof t)throw new Error("Function is expected to iterate over graph nodes. You passed "+t);for(var e=a.values(),n=e.next();!n.done;){if(t(n.value))return!0;n=e.next()}}};var t=wt();function e(t,e){this.id=t,this.links=null,this.data=e}function n(t,e){t.links?t.links.add(e):t.links=new Set([e])}function r(t,e,n,r){this.fromId=t,this.toId=e,this.data=n,this.id=r}function i(t,e){return t.toString()+"👉 "+e.toString()}return ht}(),jt=mt(At),Pt={exports:{}},Dt={exports:{}};function Ct(){return xt||(xt=1,_t=function(t){return 0===t?"x":1===t?"y":2===t?"z":"c"+(t+1)}),_t}function Et(){if(Mt)return kt;Mt=1;const t=Ct();return kt=function(e){return function(n,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<e;++r){let e=t(r),i=0===r?"":a;u.push(i+n.replace(/{var}/g,e))}return u.join(o)}}}var St,Nt={exports:{}};var Tt,zt={exports:{}};var Bt,Rt={exports:{}};var It,Lt={exports:{}};var $t,Ft,qt,Ut,Gt,Vt={exports:{}};var Ht,Wt,Qt,Jt,Xt={exports:{}};function Yt(){if(Qt)return Wt;Qt=1,Wt=function(s){var l=qt?Ft:(qt=1,Ft=function(t,e,n,r){this.from=t,this.to=e,this.length=n,this.coefficient=r}),c=(Gt||(Gt=1,Ut=function t(e,n){var r;if(e||(e={}),n)for(r in n)if(n.hasOwnProperty(r)){var i=e.hasOwnProperty(r),o=typeof n[r];i&&typeof e[r]===o?"object"===o&&(e[r]=t(e[r],n[r])):e[r]=n[r]}return e}),Ut),f=wt();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=c(s,{springLength:10,springCoefficient:.8,gravity:-12,theta:.8,dragCoefficient:.9,timeStep:.5,adaptiveTimeStepWeight:0,dimensions:2,debug:!1});var d=a[s.dimensions];if(!d){var h=s.dimensions;d={Body:t(h,s.debug),createQuadTree:e(h),createBounds:n(h),createDragForce:r(h),createSpringForce:i(h),integrate:o(h)},a[h]=d}var p=d.Body,g=d.createQuadTree,v=d.createBounds,y=d.createDragForce,b=d.createSpringForce,m=d.integrate,w=function(){if(Ht)return Xt.exports;function t(t){return new e("number"==typeof t?t:+new Date)}function e(t){this.seed=t}function n(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 Ht=1,Xt.exports=t,Xt.exports.random=t,Xt.exports.randomIterator=function(e,n){var r=n||t();if("function"!=typeof r.next)throw new Error("customRandom does not match expected API: next() function is missing");return{forEach:function(t){var n,i,o;for(n=e.length-1;n>0;--n)i=r.next(n+1),o=e[i],e[i]=e[n],e[n]=o,t(o);e.length&&t(e[0])},shuffle:function(){var t,n,i;for(t=e.length-1;t>0;--t)n=r.next(t+1),i=e[n],e[n]=e[t],e[t]=i;return e}}},e.prototype.next=function(t){return Math.floor(this.nextDouble()*t)},e.prototype.nextDouble=r,e.prototype.uniform=r,e.prototype.gaussian=function(){var t,e,n;do{t=(e=2*this.nextDouble()-1)*e+(n=2*this.nextDouble()-1)*n}while(t>=1||0===t);return e*Math.sqrt(-2*Math.log(t)/t)},e.prototype.random=r,e.prototype.levy=function(){var t=1.5,e=Math.pow(n(2.5)*Math.sin(Math.PI*t/2)/(n(1.25)*t*Math.pow(2,.25)),1/t);return this.gaussian()*e/Math.pow(Math.abs(this.gaussian()),1/t)},Xt.exports}().random(42),_=[],x=[],k=g(s,w),M=v(_,s,w),O=b(s,w),A=y(s),j=[],P=new Map,D=0;S("nbody",function(){if(0===_.length)return;k.insertBodies(_);var t=_.length;for(;t--;){var e=_[t];e.isPinned||(e.reset(),k.updateBodyForce(e),A.update(e))}}),S("spring",function(){var t=x.length;for(;t--;)O.update(x[t])});var C={bodies:_,quadTree:k,springs:x,settings:s,addForce:S,removeForce:function(t){var e=j.indexOf(P.get(t));if(e<0)return;j.splice(e,1),P.delete(t)},getForces:function(){return P},step:function(){for(var t=0;t<j.length;++t)j[t](D);var e=m(_,s.timeStep,s.adaptiveTimeStepWeight);return D+=1,e},addBody:function(t){if(!t)throw new Error("Body is required");return _.push(t),t},addBodyAt:function(t){if(!t)throw new Error("Body position is required");var e=(t=>new p(t))(t);return _.push(e),e},removeBody:function(t){if(t){var e=_.indexOf(t);if(!(e<0))return _.splice(e,1),0===_.length&&M.reset(),!0}},addSpring:function(t,e,n,r){if(!t||!e)throw new Error("Cannot add null spring to force simulator");"number"!=typeof n&&(n=-1);var i=new l(t,e,n,r>=0?r:-1);return x.push(i),i},getTotalMovement:function(){return 0},removeSpring:function(t){if(t){var e=x.indexOf(t);return e>-1?(x.splice(e,1),!0):void 0}},getBestNewBodyPosition:function(t){return M.getBestNewPosition(t)},getBBox:E,getBoundingBox:E,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:w};return function(t,e){for(var n in t)u(t,e,n)}(s,C),f(C),C;function E(){return M.update(),M.box}function S(t,e){if(P.has(t))throw new Error("Force "+t+" is already added");P.set(t,e),j.push(e)}};var t=function(){if(Ot)return Dt.exports;Ot=1;const t=Et();function e(t,e){return`\n${r(t,e)}\n${n(t)}\nreturn {Body: Body, Vector: Vector};\n`}function n(e){let n=t(e),r=n("{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 ${n("this.pos.{var} = {var} || 0;",{indent:2})}\n};`}function r(e,n){let r=t(e),i="";return n&&(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 Dt.exports=function(t,n){let r=e(t,n),{Body:i}=new Function(r)();return i},Dt.exports.generateCreateBodyFunctionBody=e,Dt.exports.getVectorCode=r,Dt.exports.getBodyCode=n,Dt.exports}(),e=function(){if(St)return Nt.exports;St=1;const t=Et(),e=Ct();function n(n){let s=t(n),l=Math.pow(2,n);return`\n${u()}\n${a(n)}\n${r(n)}\n${o(n)}\n${i(n)}\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 e=[];for(let n=0;n<l;++n)e.push(`${t}quad${n} = null;`);return e.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_${e(0)} - node.min_${e(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(" "),e=[];for(let n=0;n<l;++n)e.push(t+`if (node.quad${n}) {`),e.push(t+` queue[pushIdx] = node.quad${n};`),e.push(t+" queueLength += 1;"),e.push(t+" pushIdx += 1;"),e.push(t+"}");return e.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<n;++i)t.push(r+`if (${e(i)} > max_${e(i)}) {`),t.push(r+` quadIdx = quadIdx + ${Math.pow(2,i)};`),t.push(r+` min_${e(i)} = max_${e(i)};`),t.push(r+` max_${e(i)} = node.max_${e(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(e){let n=t(e);return`\n function isSamePosition(point1, point2) {\n ${n("var d{var} = Math.abs(point1.{var} - point2.{var});",{indent:2})}\n \n return ${n("d{var} < 1e-8",{join:" && "})};\n } \n`}function i(t){var e=Math.pow(2,t);return`\nfunction setChild(node, idx, child) {\n ${function(){let t=[];for(let n=0;n<e;++n){let e=0===n?" ":" else ";t.push(`${e}if (idx === ${n}) node.quad${n} = child;`)}return t.join("\n")}()}\n}`}function o(t){return`function getChild(node, idx) {\n${function(){let e=[],n=Math.pow(2,t);for(let t=0;t<n;++t)e.push(` if (idx === ${t}) return node.quad${t};`);return e.join("\n")}()}\n return null;\n}`}function a(e){let n=t(e),r=Math.pow(2,e);return`\nfunction QuadNode() {\n // body stored inside this node. In quad tree only leaf nodes (by construction)\n // contain bodies:\n this.body = null;\n\n // Child nodes are stored in quads. Each quad is presented by number:\n // 0 | 1\n // -----\n // 2 | 3\n${function(t){let e=[];for(let n=0;n<r;++n)e.push(`${t}quad${n} = null;`);return e.join("\n")}(" this.")}\n\n // Total mass of current node\n this.mass = 0;\n\n // Center of mass coordinates\n ${n("this.mass_{var} = 0;",{indent:2})}\n\n // bounding box coordinates\n ${n("this.min_{var} = 0;",{indent:2})}\n ${n("this.max_{var} = 0;",{indent:2})}\n}\n`}function u(){return"\n/**\n * Our implementation of QuadTree is non-recursive to avoid GC hit\n * This data structure represent stack of elements\n * which we are trying to insert into quad tree.\n */\nfunction InsertStack () {\n this.stack = [];\n this.popIdx = 0;\n}\n\nInsertStack.prototype = {\n isEmpty: function() {\n return this.popIdx === 0;\n },\n push: function (node, body) {\n var item = this.stack[this.popIdx];\n if (!item) {\n // we are trying to avoid memory pressure: create new element\n // only when absolutely necessary\n this.stack[this.popIdx] = new InsertStackElement(node, body);\n } else {\n item.node = node;\n item.body = body;\n }\n ++this.popIdx;\n },\n pop: function () {\n if (this.popIdx > 0) {\n return this.stack[--this.popIdx];\n }\n },\n reset: function () {\n this.popIdx = 0;\n }\n};\n\nfunction InsertStackElement(node, body) {\n this.node = node; // QuadTree node\n this.body = body; // physical body which needs to be inserted to node\n}\n"}return Nt.exports=function(t){let e=n(t);return new Function(e)()},Nt.exports.generateQuadTreeFunctionBody=n,Nt.exports.getInsertStackCode=u,Nt.exports.getQuadNodeCode=a,Nt.exports.isSamePosition=r,Nt.exports.getChildBodyCode=o,Nt.exports.setChildBodyCode=i,Nt.exports}(),n=function(){if(Tt)return zt.exports;Tt=1,zt.exports=function(t){let n=e(t);return new Function("bodies","settings","random",n)},zt.exports.generateFunctionBody=e;const t=Et();function