3d-force-graph-ar
Version:
UI component for a 3D force-directed graph in AR
2 lines • 123 kB
JavaScript
// Version 1.9.5 3d-force-graph-ar - https://github.com/vasturiano/3d-force-graph-ar
!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).ForceGraphAR=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){return(n=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+""}(n))in t?Object.defineProperty(t,n,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[n]=e,t}function r(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 i(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?r(Object(i),!0).forEach((function(n){e(t,n,i[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach((function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(i,n))}))}return t}function o(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,l=!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){l=!0,i=t}finally{try{if(!s&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(l)throw i}}return u}}(t,n)||u(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 a(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)||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,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 s(t,n,e){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-n)*i,c=(c/u-e)*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==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 l(t,n,e){if(isNaN(n))return t;var r,i,o,a,u,s,l=t._root,c={data:e},f=t._x0,d=t._x1;if(!l)return t._root=c,t;for(;l.length;)if((a=n>=(i=(f+d)/2))?f=i:d=i,r=l,!(l=l[u=+a]))return r[u]=c,t;if(n===(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=n>=(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,n,e){this.node=t,this.x0=n,this.x1=e}function f(t){return t[0]}function d(t,n){var e=new h(null==n?f:n,NaN,NaN);return null==t?e:e.addAll(t)}function h(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 g=d.prototype=h.prototype;function v(t,n,e,r){if(isNaN(n)||isNaN(e))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=n>=(o=(g+y)/2))?g=o:y=o,(c=e>=(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),n===u&&e===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=n>=(o=(g+y)/2))?g=o:y=o,(c=e>=(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,n,e,r,i){this.node=t,this.x0=n,this.y0=e,this.x1=r,this.y1=i}function b(t){return t[0]}function m(t){return t[1]}function w(t,n,e){var r=new _(null==n?b:n,null==e?m:e,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function _(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 x(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}g.copy=function(){var t,n,e=new h(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},g.add=function(t){const n=+this._x.call(null,t);return l(this.cover(n),n,t)},g.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)l(this,e[r],t[r]);return this},g.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},g.data=function(){var t=[];return this.visit((function(n){if(!n.length)do{t.push(n.data)}while(n=n.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,n){var e,r,i,o,a,u=this._x0,s=this._x1,l=[],f=this._root;for(f&&l.push(new c(f,u,s)),null==n?n=1/0:(u=t-n,s=t+n);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<n&&(n=h,u=t-h,s=t+h,e=f.data)}return e},g.remove=function(t){if(isNaN(o=+this._x.call(null,t)))return this;var n,e,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,n=c,!(c=c[s=+u]))return this;if(!c.length)break;n[s+1&1]&&(e=n,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):n?(i?n[s]=i:delete n[s],(c=n[0]||n[1])&&c===(n[1]||n[0])&&!c.length&&(e?e[l]=c:this._root=c),this):(this._root=i,this)},g.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},g.root=function(){return this._root},g.size=function(){var t=0;return this.visit((function(n){if(!n.length)do{++t}while(n=n.next)})),t},g.visit=function(t){var n,e,r,i,o=[],a=this._root;for(a&&o.push(new c(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 c(e,u,i)),(e=a[0])&&o.push(new c(e,r,u))}return this},g.visitAfter=function(t){var n,e=[],r=[];for(this._root&&e.push(new c(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 c(o,a,s)),(o=i[1])&&e.push(new c(o,s,u))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.x1);return this},g.x=function(t){return arguments.length?(this._x=t,this):this._x};var k=w.prototype=_.prototype;function M(t,n,e,r,i){if(isNaN(n)||isNaN(e)||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=n>=(a=(m+x)/2))?m=a:x=a,(h=e>=(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),n===l&&e===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=n>=(a=(m+x)/2))?m=a:x=a,(h=e>=(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 A(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}k.copy=function(){var t,n,e=new _(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=x(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]=x(n));return e},k.add=function(t){const n=+this._x.call(null,t),e=+this._y.call(null,t);return v(this.cover(n,e),n,e,t)},k.addAll=function(t){var n,e,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(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>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),e=0;e<o;++e)v(this,a[e],u[e],t[e]);return this},k.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,l=this._root;e>t||t>=i||r>n||n>=o;)switch(u=(n<r)<<1|t<e,(a=new Array(4))[u]=l,l=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=l)}return this._x0=e,this._y0=r,this._x1=i,this._y1=o,this},k.data=function(){var t=[];return this.visit((function(n){if(!n.length)do{t.push(n.data)}while(n=n.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,n,e){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==e?e=1/0:(c=t-e,f=n-e,d=t+e,h=n+e,e*=e);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=(n>=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=n-+this._y.call(null,g.data),_=m*m+w*w;if(_<e){var x=Math.sqrt(e=_);c=t-x,f=n-x,d=t+x,h=n+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 n,e,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,n=h,!(h=h[f=c<<1|l]))return this;if(!h.length)break;(n[f+1&3]||n[f+2&3]||n[f+3&3])&&(e=n,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):n?(i?n[f]=i:delete n[f],(h=n[0]||n[1]||n[2]||n[3])&&h===(n[3]||n[2]||n[1]||n[0])&&!h.length&&(e?e[d]=h:this._root=h),this):(this._root=i,this)},k.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},k.root=function(){return this._root},k.size=function(){var t=0;return this.visit((function(n){if(!n.length)do{++t}while(n=n.next)})),t},k.visit=function(t){var n,e,r,i,o,a,u=[],s=this._root;for(s&&u.push(new y(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 l=(r+o)/2,c=(i+a)/2;(e=s[3])&&u.push(new y(e,l,c,o,a)),(e=s[2])&&u.push(new y(e,r,c,l,a)),(e=s[1])&&u.push(new y(e,l,i,o,c)),(e=s[0])&&u.push(new y(e,r,i,l,c))}return this},k.visitAfter=function(t){var n,e=[],r=[];for(this._root&&e.push(new y(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,l=n.y1,c=(a+s)/2,f=(u+l)/2;(o=i[0])&&e.push(new y(o,a,u,c,f)),(o=i[1])&&e.push(new y(o,c,u,s,f)),(o=i[2])&&e.push(new y(o,a,f,c,l)),(o=i[3])&&e.push(new y(o,c,f,s,l))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.y0,n.x1,n.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 O=(t,n,e,r,i,o)=>Math.sqrt((t-r)**2+(n-i)**2+(e-o)**2);function j(t){return t[0]}function P(t){return t[1]}function C(t){return t[2]}function E(t,n,e,r){var i=new S(null==n?j:n,null==e?P:e,null==r?C:r,NaN,NaN,NaN,NaN,NaN,NaN);return null==t?i:i.addAll(t)}function S(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 D(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}var N=E.prototype=S.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,n){var e=t.get(n);if(!e)throw new Error("node not found: "+n);return e}function I(t){var n,e,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))-e[g])/h*r*n[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,n)=>[s(t,n,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]);n=new Array(c),p(),e=new Array(c),g()}}function p(){if(r)for(var e=0,i=t.length;e<i;++e)n[e]=+l(t[e],e,t)}function g(){if(r)for(var n=0,i=t.length;n<i;++n)e[n]=+c(t[n],n,t)}return null==t&&(t=[]),d.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,h()},d.links=function(n){return arguments.length?(t=n,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,n,e=new S(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=D(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]=D(n));return e},N.add=function(t){const n=+this._x.call(null,t),e=+this._y.call(null,t),r=+this._z.call(null,t);return M(this.cover(n,e,r),n,e,r,t)},N.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,l=-1/0,c=-1/0;for(let f,d,h,p,g=0;g<n;++g)isNaN(d=+this._x.call(null,f=t[g]))||isNaN(h=+this._y.call(null,f))||isNaN(p=+this._z.call(null,f))||(e[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<n;++o)M(this,e[o],r[o],i[o],t[o]);return this},N.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 l,c,f=a-r||1,d=this._root;r>t||t>=a||i>n||n>=u||o>e||e>=s;)switch(c=(e<o)<<2|(n<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(n){if(!n.length)do{t.push(n.data)}while(n=n.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,n,e,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 A(w,h,p,g,v,y,b)),null==r?r=1/0:(h=t-r,p=n-r,g=e-r,v=t+r,y=n+r,b=e+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 A(w[7],_,x,k,s,l,c),new A(w[6],o,x,k,_,l,c),new A(w[5],_,a,k,s,x,c),new A(w[4],o,a,k,_,x,c),new A(w[3],_,x,u,s,l,k),new A(w[2],o,x,u,_,l,k),new A(w[1],_,a,u,s,x,k),new A(w[0],o,a,u,_,x,k)),(d=(e>=k)<<2|(n>=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),O=n-+this._y.call(null,w.data),j=e-+this._z.call(null,w.data),P=M*M+O*O+j*j;if(P<r){var C=Math.sqrt(r=P);h=t-C,p=n-C,g=e-C,v=t+C,y=n+C,b=e+C,i=w.data}}return i},N.findAllWithinRadius=function(t,n,e,r){const i=[],o=t-r,a=n-r,u=e-r,s=t+r,l=n+r,c=e+r;return this.visit(((f,d,h,p,g,v,y)=>{if(!f.length)do{const o=f.data;O(t,n,e,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 n,e,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,n=v,!(v=v[p=h<<2|d<<1|f]))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)},N.removeAll=function(t){for(var n=0,e=t.length;n<e;++n)this.remove(t[n]);return this},N.root=function(){return this._root},N.size=function(){var t=0;return this.visit((function(n){if(!n.length)do{++t}while(n=n.next)})),t},N.visit=function(t){var n,e,r,i,o,a,u,s,l=[],c=this._root;for(c&&l.push(new A(c,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));n=l.pop();)if(!t(c=n.node,r=n.x0,i=n.y0,o=n.z0,a=n.x1,u=n.y1,s=n.z1)&&c.length){var f=(r+a)/2,d=(i+u)/2,h=(o+s)/2;(e=c[7])&&l.push(new A(e,f,d,h,a,u,s)),(e=c[6])&&l.push(new A(e,r,d,h,f,u,s)),(e=c[5])&&l.push(new A(e,f,i,h,a,d,s)),(e=c[4])&&l.push(new A(e,r,i,h,f,d,s)),(e=c[3])&&l.push(new A(e,f,d,o,a,u,h)),(e=c[2])&&l.push(new A(e,r,d,o,f,u,h)),(e=c[1])&&l.push(new A(e,f,i,o,a,d,h)),(e=c[0])&&l.push(new A(e,r,i,o,f,d,h))}return this},N.visitAfter=function(t){var n,e=[],r=[];for(this._root&&e.push(new A(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,l=n.x1,c=n.y1,f=n.z1,d=(a+l)/2,h=(u+c)/2,p=(s+f)/2;(o=i[0])&&e.push(new A(o,a,u,s,d,h,p)),(o=i[1])&&e.push(new A(o,d,u,s,l,h,p)),(o=i[2])&&e.push(new A(o,a,h,s,d,c,p)),(o=i[3])&&e.push(new A(o,d,h,s,l,c,p)),(o=i[4])&&e.push(new A(o,a,u,p,d,h,f)),(o=i[5])&&e.push(new A(o,d,u,p,l,h,f)),(o=i[6])&&e.push(new A(o,a,h,p,d,c,f)),(o=i[7])&&e.push(new A(o,d,h,p,l,c,f))}r.push(n)}for(;n=r.pop();)t(n.node,n.x0,n.y0,n.z0,n.x1,n.y1,n.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,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 F(r)}function F(t){this._=t}function q(t,n){for(var e,r=0,i=t.length;r<i;++r)if((e=t[r]).name===n)return e.value}function U(t,n,e){for(var r=0,i=t.length;r<i;++r)if(t[r].name===n){t[r]=L,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=e&&t.push({name:n,value:e}),t}F.prototype=$.prototype={constructor:F,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]=U(i[e],t.name,n);else if(null==n)for(e in i)i[e]=U(i[e],t.name,null);return this}for(;++a<u;)if((e=(t=o[a]).type)&&(e=q(i[e],t.name)))return e},copy:function(){var t={},n=this._;for(var e in n)t[e]=n[e].slice();return new F(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 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(nt),X=K.now()+Y)}function nt(){X=0}function et(){this._call=this._time=this._next=null}function rt(t,n,e){var r=new et;return r.restart(t,n,e),r}function it(){X=(J=K.now())+Y,H=W=0;try{!function(){tt(),++H;for(var t,n=G;n;)(t=X-n._time)>=0&&n._call.call(void 0,t),n=n._next;--H}()}finally{H=0,function(){var t,n,e=G,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:G=n);V=t,at(r)}(),X=0}}function ot(){var t=K.now(),n=t-J;n>1e3&&(Y-=n,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)))}et.prototype=rt.prototype={constructor:et,restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?tt():+e)+(null==n?0:+n),this._next||V===this||(V?V._next=this:G=this,V=this),this._call=t,this._time=e,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,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,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",e),i<o&&(c.stop(),f.call("end",e))}function p(n){var o,c,f=t.length;void 0===n&&(n=1);for(var d=0;d<n;++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 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*gt,u=e*vt;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,d,r),n}return null==t&&(t=[]),g(),e={tick:p,restart:function(){return c.restart(h),e},stop:function(){return c.stop(),e},numDimensions:function(t){return arguments.length?(r=Math.min(3,Math.max(1,Math.round(t))),l.forEach(v),e):r},nodes:function(n){return arguments.length?(t=n,g(),l.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?(d=t,l.forEach(v),e):d},force:function(t,n){return arguments.length>1?(null==n?l.delete(t):l.set(t,v(n)),e):l.get(t)},find:function(){var n,e,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=(n=l-(a=t[h]).x)*n+(e=c-(a.y||0))*e+(i=f-(a.z||0))*i)<d&&(u=a,d=o);return u},on:function(t,n){return arguments.length>1?(f.on(t,n),e):f.on(t)}}}function bt(){var t,n,e,r,i,o,a=T(-30),u=1,s=1/0,l=.81;function c(r){var o,a=t.length,u=(1===n?d(t,st):2===n?w(t,st,lt):3===n?E(t,st,lt,ct):null).visitAfter(h);for(i=r,o=0;o<a;++o)e=t[o],u.visit(p)}function f(){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,l=0,c=0,f=t.length;if(f){for(i=a=u=s=0;s<f;++s)(e=t[s])&&(r=Math.abs(e.value))&&(l+=e.value,c+=r,i+=r*(e.x||0),a+=r*(e.y||0),u+=r*(e.z||0));l*=Math.sqrt(4/f),t.x=i/c,n>1&&(t.y=a/c),n>2&&(t.z=u/c)}else{(e=t).x=e.data.x,n>1&&(e.y=e.data.y),n>2&&(e.z=e.data.z);do{l+=o[e.data.index]}while(e=e.next)}t.value=l}function p(t,a,c,f,d){if(!t.value)return!0;var h=[c,f,d][n-1],p=t.x-e.x,g=n>1?t.y-e.y:0,v=n>2?t.z-e.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),n>1&&0===g&&(b+=(g=z(r))*g),n>2&&0===v&&(b+=(v=z(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=z(r))*p),n>1&&0===g&&(b+=(g=z(r))*g),n>2&&0===v&&(b+=(v=z(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 c.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,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 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},ft}var _t,xt,kt,Mt,At,Ot=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,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)},f=[],d=O,h=O,p=O,g=O,v={version:20,addNode:m,addLink:function(t,n,r){p();var i=w(t)||m(t),o=w(n)||m(n),a=c(t,n,r),s=u.has(a.id);u.set(a.id,a),e(i,a),t!==n&&e(o,a);return d(a,s?"update":"add"),g(),a},removeLink:function(t,n){void 0!==n&&(t=A(t,n));return M(t)},removeNode:_,getNode:w,getNodeCount:x,getLinkCount:k,getEdgeCount:k,getLinksCount:k,getNodesCount:x,getLinks:function(t){var n=w(t);return n?n.links:null},forEachNode:C,forEachLinkedNode:function(t,n,e){var r=w(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(),C((function(t){_(t.id)})),g()},hasLink:A,hasNode:w,getLink:A};return t(v),function(){var t=v.on;function n(){return v.beginUpdate=p=j,v.endUpdate=g=P,d=y,h=b,v.on=t,t.apply(v,arguments)}v.on=n}(),v;function y(t,n){f.push({link:t,changeType:n})}function b(t,n){f.push({node:t,changeType:n})}function m(t,e){if(void 0===t)throw new Error("Invalid node identifier");p();var r=w(t);return r?(r.data=e,h(r,"update")):(r=new n(t,e),h(r,"add")),a.set(t,r),g(),r}function w(t){return a.get(t)}function _(t){var n=w(t);if(!n)return!1;p();var e=n.links;return e&&(e.forEach(M),n.links=null),a.delete(t),h(n,"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 n=w(t.fromId),e=w(t.toId);return n&&n.links.delete(t),e&&e.links.delete(t),d(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(){l+=1}function P(){0===(l-=1)&&f.length>0&&(v.fire("changed",f),f.length=0)}function C(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=wt();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 ht}(),jt=mt(Ot),Pt={exports:{}},Ct={exports:{}};function Et(){return xt||(xt=1,_t=function(t){return 0===t?"x":1===t?"y":2===t?"z":"c"+(t+1)}),_t}function St(){if(Mt)return kt;Mt=1;const t=Et();return kt=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 Dt,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,n,e,r){this.from=t,this.to=n,this.length=e,this.coefficient=r}),c=(Gt||(Gt=1,Ut=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}),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:n(h),createBounds:e(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 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 Ht=1,Xt.exports=t,Xt.exports.random=t,Xt.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.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)},Xt.exports}().random(42),_=[],x=[],k=g(s,w),M=v(_,s,w),A=b(s,w),O=y(s),j=[],P=new Map,C=0;D("nbody",(function(){if(0===_.length)return;k.insertBodies(_);var t=_.length;for(;t--;){var n=_[t];n.isPinned||(n.reset(),k.updateBodyForce(n),O.update(n))}})),D("spring",(function(){var t=x.length;for(;t--;)A.update(x[t])}));var E={bodies:_,quadTree:k,springs:x,settings:s,addForce:D,removeForce:function(t){var n=j.indexOf(P.get(t));if(n<0)return;j.splice(n,1),P.delete(t)},getForces:function(){return P},step:function(){for(var t=0;t<j.length;++t)j[t](C);var n=m(_,s.timeStep,s.adaptiveTimeStepWeight);return C+=1,n},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 n=(t=>new p(t))(t);return _.push(n),n},removeBody:function(t){if(t){var n=_.indexOf(t);if(!(n<0))return _.splice(n,1),0===_.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 l(t,n,e,r>=0?r:-1);return x.push(i),i},getTotalMovement:function(){return 0},removeSpring:function(t){if(t){var n=x.indexOf(t);return n>-1?(x.splice(n,1),!0):void 0}},getBestNewBodyPosition:function(t){return M.getBestNewPosition(t)},getBBox:S,getBoundingBox:S,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,n){for(var e in t)u(t,n,e)}(s,E),f(E),E;function S(){return M.update(),M.box}function D(t,n){if(P.has(t))throw new Error("Force "+t+" is already added");P.set(t,n),j.push(n)}};var t=function(){if(At)return Ct.exports;At=1;const t=St();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 Ct.exports=function(t,e){let r=n(t,e),{Body:i}=new Function(r)();return i},Ct.exports.generateCreateBodyFunctionBody=n,Ct.exports.getVectorCode=r,Ct.exports.getBodyCode=e,Ct.exports}(),n=function(){if(Dt)return Nt.exports;Dt=1;const t=St(),n=Et();function e(e){let s=t(e),l=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<l;++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<l;++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 node.quad${t};`);return n.join("\n")}()}\n return null;\n}`}function a(n){let e=t(n),r=Math.pow(2,n);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 n=[];for(let e=0;e<r;++e)n.push(`${t}quad${e} = null;`);return n.join("\n")}(" this.")}\n\n // Total mass of current node\n this.mass = 0;\n\n // Center of mass coordinates\n ${e("this.mass_{var} = 0;",{indent:2})}\n\n // bounding box coordinates\n ${e("this.min_{var} = 0;",{indent:2})}\n ${e("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 n=e(t);return new Function(n)()},Nt.exports.generateQuadTreeFunctionBody=e,Nt.exports.getInsertStackCode=u,Nt.exports.getQuadNodeCode=a,Nt.exports.isSamePosition=r,Nt.exports.getChildBodyCode=o,Nt.exports.setChildBodyCode=i,Nt.exports}(),e=function(){if(Tt)return zt.exports;Tt=1,zt.exports=function(t){let e=n(t);return new Function("bodies","settings","random",e)},zt.exports.generateFunctionBody=n;cons